summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSimon Robertshaw <simon@hardwired.org.uk>2011-08-14 17:31:48 (GMT)
committer Simon Robertshaw <simon@hardwired.org.uk>2011-08-14 17:31:48 (GMT)
commitd3153aae85f2e3cd1ba8ff0520e5ebe51e08d7d5 (patch)
tree87ee489d32b7515e4d026767dbea152cc892b432 /src
parent2749285134c92cae393b9e113e32983b105d700c (diff)
downloadpowder-d3153aae85f2e3cd1ba8ff0520e5ebe51e08d7d5.zip
powder-d3153aae85f2e3cd1ba8ff0520e5ebe51e08d7d5.tar.gz
Extended info for line drawing
Diffstat (limited to 'src')
-rw-r--r--src/graphics.c86
-rw-r--r--src/main.c2
2 files changed, 85 insertions, 3 deletions
diff --git a/src/graphics.c b/src/graphics.c
index 8508288..033d219 100644
--- a/src/graphics.c
+++ b/src/graphics.c
@@ -1044,6 +1044,18 @@ int drawtext(pixel *vid, int x, int y, const char *s, int r, int g, int b, int a
#endif
return x;
}
+
+//Draw text with an outline
+int drawtext_outline(pixel *vid, int x, int y, const char *s, int r, int g, int b, int a, int or, int og, int ob, int oa)
+{
+ drawtext(vid, x-1, y-1, s, or, og, ob, oa);
+ drawtext(vid, x+1, y+1, s, or, og, ob, oa);
+
+ drawtext(vid, x-1, y+1, s, or, og, ob, oa);
+ drawtext(vid, x+1, y-1, s, or, og, ob, oa);
+
+ return drawtext(vid, x, y, s, r, g, b, a);
+}
int drawtextwrap(pixel *vid, int x, int y, int w, const char *s, int r, int g, int b, int a)
{
#ifdef OpenGL
@@ -1618,6 +1630,53 @@ void xor_line(int x1, int y1, int x2, int y2, pixel *vid)
}
}
+//same as blend_pixel, but draws a line of it
+void blend_line(pixel *vid, int x1, int y1, int x2, int y2, int r, int g, int b, int a)
+{
+ int cp=abs(y2-y1)>abs(x2-x1), x, y, dx, dy, sy;
+ float e, de;
+ if (cp)
+ {
+ y = x1;
+ x1 = y1;
+ y1 = y;
+ y = x2;
+ x2 = y2;
+ y2 = y;
+ }
+ if (x1 > x2)
+ {
+ y = x1;
+ x1 = x2;
+ x2 = y;
+ y = y1;
+ y1 = y2;
+ y2 = y;
+ }
+ dx = x2 - x1;
+ dy = abs(y2 - y1);
+ e = 0.0f;
+ if (dx)
+ de = dy/(float)dx;
+ else
+ de = 0.0f;
+ y = y1;
+ sy = (y1<y2) ? 1 : -1;
+ for (x=x1; x<=x2; x++)
+ {
+ if (cp)
+ blendpixel(vid, y, x, r, g, b, a);
+ else
+ blendpixel(vid, x, y, r, g, b, a);
+ e += de;
+ if (e >= 0.5f)
+ {
+ y += sy;
+ e -= 1.0f;
+ }
+ }
+}
+
//same as xor_pixel, but draws a rectangle
void xor_rect(pixel *vid, int x, int y, int w, int h)
{
@@ -4524,11 +4583,34 @@ int sdl_open(void)
return 1;
}
-int draw_debug_info(pixel* vid)
+int draw_debug_info(pixel* vid, int lm, int lx, int ly, int cx, int cy)
{
+ char infobuf[256];
+ if(debug_flags & DEBUG_DRAWTOOL)
+ {
+ if(lm == 1) //Line tool
+ {
+ blend_line(vid, 0, cy, XRES, cy, 255, 255, 255, 120);
+ blend_line(vid, cx, 0, cx, YRES, 255, 255, 255, 120);
+
+ blend_line(vid, 0, ly, XRES, ly, 255, 255, 255, 120);
+ blend_line(vid, lx, 0, lx, YRES, 255, 255, 255, 120);
+
+ sprintf(infobuf, "%d x %d", lx, ly);
+ drawtext_outline(vid, lx+(lx>cx?3:-textwidth(infobuf)-3), ly+(ly<cy?-10:3), infobuf, 255, 255, 255, 200, 0, 0, 0, 120);
+
+ sprintf(infobuf, "%d x %d", cx, cy);
+ drawtext_outline(vid, cx+(lx<cx?3:-textwidth(infobuf)-2), cy+(ly>cy?-10:3), infobuf, 255, 255, 255, 200, 0, 0, 0, 120);
+
+ sprintf(infobuf, "%d", abs(cx-lx));
+ drawtext_outline(vid, cx+(lx<cx?-(cx-lx)/2:(lx-cx)/2)-textwidth(infobuf)/2, cy+(ly>cy?-10:3), infobuf, 255, 255, 255, 200, 0, 0, 0, 120);
+
+ sprintf(infobuf, "%d", abs(cy-ly));
+ drawtext_outline(vid, cx+(lx<cx?3:-textwidth(infobuf)-2), cy+(ly>cy?-(cy-ly)/2:(ly-cy)/2)-3, infobuf, 255, 255, 255, 200, 0, 0, 0, 120);
+ }
+ }
if(debug_flags & DEBUG_PARTS)
{
- char infobuf[256];
int i = 0, x = 0, y = 0, lpx = 0, lpy = 0;
sprintf(infobuf, "%d/%d (%.2f%%)", parts_lastActiveIndex, NPART, (((float)parts_lastActiveIndex)/((float)NPART))*100.0f);
for(i = 0; i < NPART; i++){
diff --git a/src/main.c b/src/main.c
index e403b3d..458123a 100644
--- a/src/main.c
+++ b/src/main.c
@@ -1964,7 +1964,7 @@ int main(int argc, char *argv[])
if(debug_flags)
{
- draw_debug_info(vid_buf);
+ draw_debug_info(vid_buf, lm, lx, ly, x, y);
}
if (http_ver_check)