changeset 35:a2898079d6fe

Clean up drawing code a bit.
author Matti Hamalainen <ccr@tnsp.org>
date Sat, 24 Sep 2011 17:14:47 +0300
parents fc416dd81a39
children 50df08fdfb2c
files src/flats.cc src/objinfo.cc
diffstat 2 files changed, 86 insertions(+), 117 deletions(-) [+]
line wrap: on
line diff
--- a/src/flats.cc	Sat Sep 24 16:25:18 2011 +0300
+++ b/src/flats.cc	Sat Sep 24 17:14:47 2011 +0300
@@ -141,13 +141,18 @@
  */
 void display_flat_depressed(hookfunc_comm_t * c)
 {
-    draw_box_border(c->x0, c->y0, c->x1 - c->x0 + 1, c->y1 - c->y0 + 1,
+    draw_box_border(c->x0, c->y0,
+                    c->x1 - c->x0 + 1,
+                    c->y1 - c->y0 + 1,
                     HOLLOW_BORDER, 0);
+
     c->x0 += HOLLOW_BORDER;
     c->y0 += HOLLOW_BORDER;
     c->x1 -= HOLLOW_BORDER;
     c->y1 -= HOLLOW_BORDER;
+
     DisplayFloorTexture(c);
+
     c->x0 -= HOLLOW_BORDER;
     c->y0 -= HOLLOW_BORDER;
     c->x1 += HOLLOW_BORDER;
--- a/src/objinfo.cc	Sat Sep 24 16:25:18 2011 +0300
+++ b/src/objinfo.cc	Sat Sep 24 17:14:47 2011 +0300
@@ -92,6 +92,82 @@
     out_y1 = 0;
 }
 
+static int is_notexture(const char *name)
+{
+    return (name[0] == '-' && name[1] == 0);
+}
+
+static void draw_sidedef_info(int sidedef, int sd, int sd2, int obj_no, int x0, int y0, int ix0, int iy0, int s1, int s2, int width, int height)
+{
+        DrawScreenBox3D(x0, y0, x0 + width - 1, y0 + height - 1);
+
+        if (obj_no >= 0 && sd >= 0)
+        {
+            set_colour(WINTITLE);
+            DrawScreenText(ix0, iy0, "Sidedef%d #%d", sidedef, sd);
+
+            if (s1 >= 0 && s2 >= 0 &&
+                Sectors[s1].ceilh > Sectors[s2].ceilh &&
+                !(is_sky(Sectors[s1].ceilt) && is_sky(Sectors[s2].ceilt)))
+            {
+                set_colour(is_notexture(SideDefs[sd].tex1) ? CLR_ERROR : WINFG);
+            }
+            else
+                set_colour(WINFG_DIM);
+ 
+            DrawScreenText(-1, iy0 + (int) (1.5 * FONTH),
+                "\1Upper:\2  %.*s",
+                WAD_TEX_NAME, SideDefs[sd].tex1);
+
+            set_colour(sd2 < 0 && is_notexture(SideDefs[sd].tex3) ? CLR_ERROR : WINFG);
+
+            DrawScreenText(-1, -1,
+                "\1Middle:\2 %.*s",
+                WAD_TEX_NAME, SideDefs[sd].tex3);
+
+            if (s1 >= 0 && s2 >= 0 &&
+                Sectors[s1].floorh < Sectors[s2].floorh &&
+                !(is_sky(Sectors[s1].floort) && is_sky(Sectors[s2].floort)))
+            {
+                set_colour(is_notexture(SideDefs[sd].tex2) ? CLR_ERROR : WINFG);
+            }
+            else
+                set_colour(WINFG_DIM);
+
+            DrawScreenText(-1, -1,
+                "\1Lower:\2  %.*s",
+                WAD_TEX_NAME, SideDefs[sd].tex2);
+
+            set_colour(WINFG);
+            DrawScreenText(-1, -1, "\1X-ofs:\2  %d", SideDefs[sd].xoff);
+            DrawScreenText(-1, -1, "\1Y-ofs:\2  %d", SideDefs[sd].yoff);
+            DrawScreenText(-1, -1, "\1Sector:\2 #%d", s1);
+        }
+        else
+        {
+            char message[64];
+            const char *str = NULL;
+            switch (sidedef) {
+                case 1: str = "1st"; break;
+                case 2: str = "2nd"; break;
+                case 3: str = "3rd"; break;
+            }
+            if (str != NULL)
+                y_snprintf(message, sizeof(message), "(no %s sidedef)", str);
+            else
+                y_snprintf(message, sizeof(message), "(no %dth sidedef)", sidedef);
+
+            // If the "2" flag is set, there must be a second sidedef
+            if (sidedef == 1 || (sidedef == 2 && (LineDefs[obj_no].flags & 0x04)))
+                set_colour(CLR_ERROR);
+            else
+                set_colour(WINFG_DIM);
+
+            DrawScreenText(x0 + (width - FONTW * strlen(message)) / 2,
+                           y0 + (height - FONTH) / 2, message);
+        }
+}
+
 
 void objinfo_c::draw()
 {
@@ -106,7 +182,7 @@
     int height;
 
     // Am I already drawn ?
-    if (!is_obj(obj_no) || obj_no == obj_no_disp && obj_type == obj_type_disp)
+    if (!is_obj(obj_no) || (obj_no == obj_no_disp && obj_type == obj_type_disp))
         return;
 
     // Does the box need to be redrawn ?
@@ -243,6 +319,7 @@
         y0 = out_y1 - height + 1;
         ix0 = x0 + BOX_BORDER + WIDE_HSPACING;
         iy0 = y0 + BOX_BORDER + WIDE_VSPACING;
+
         // Ignore box_disp -- always redraw the whole box
         DrawScreenBox3D(x0, y0, x0 + width - 1, y0 + height - 1);
         if (obj_no >= 0)
@@ -315,128 +392,15 @@
         width = 2 * BOX_BORDER + 2 * WIDE_HSPACING + 16 * FONTW;
         ix0 = x0 + BOX_BORDER + WIDE_HSPACING;
         y0 = out_y1 - height + 1;
-        // Ignore box_disp -- always redraw the whole box
-        DrawScreenBox3D(x0, y0, x0 + width - 1, y0 + height - 1);
-        if (obj_no >= 0 && sd1 >= 0)
-        {
-            set_colour(WINTITLE);
-            DrawScreenText(ix0, iy0, "Sidedef1 #%d", sd1);
 
-            if (s1 >= 0 && s2 >= 0 && Sectors[s1].ceilh > Sectors[s2].ceilh
-                && !(is_sky(Sectors[s1].ceilt) && is_sky(Sectors[s2].ceilt)))
-            {
-                if (SideDefs[sd1].tex1[0] == '-'
-                    && SideDefs[sd1].tex1[1] == '\0')
-                    set_colour(CLR_ERROR);
-                else
-                    set_colour(WINFG);
-            }
-            else
-                set_colour(WINFG_DIM);
-            DrawScreenText(-1, iy0 + (int) (1.5 * FONTH), "\1Upper:\2  %.*s",
-                           WAD_TEX_NAME, SideDefs[sd1].tex1);
-
-            if (sd2 < 0
-                && SideDefs[sd1].tex3[0] == '-'
-                && SideDefs[sd1].tex3[1] == '\0')
-                set_colour(CLR_ERROR);
-            else
-                set_colour(WINFG);
-            DrawScreenText(-1, -1,
-                           "\1Middle:\2 %.*s", WAD_TEX_NAME,
-                           SideDefs[sd1].tex3);
-
-            if (s1 >= 0 && s2 >= 0 && Sectors[s1].floorh < Sectors[s2].floorh
-                && !(is_sky(Sectors[s1].floort)
-                     && is_sky(Sectors[s2].floort)))
-            {
-                if (SideDefs[sd1].tex2[0] == '-'
-                    && SideDefs[sd1].tex2[1] == '\0')
-                    set_colour(CLR_ERROR);
-                else
-                    set_colour(WINFG);
-            }
-            else
-                set_colour(WINFG_DIM);
-            DrawScreenText(-1, -1, "\1Lower:\2  %.*s",
-                           WAD_TEX_NAME, SideDefs[sd1].tex2);
-
-            set_colour(WINFG);
-            DrawScreenText(-1, -1, "\1X-ofs:\2  %d", SideDefs[sd1].xoff);
-            DrawScreenText(-1, -1, "\1Y-ofs:\2  %d", SideDefs[sd1].yoff);
-            DrawScreenText(-1, -1, "\1Sector:\2 #%d", s1);
-        }
-        else
-        {
-            const char *message = "(no 1st sidedef)";
-            set_colour(CLR_ERROR);
-            DrawScreenText(x0 + (width - FONTW * strlen(message)) / 2,
-                           y0 + (height - FONTH) / 2, message);
-        }
+        draw_sidedef_info(1, sd1, sd2, obj_no, x0, y0, ix0, iy0, s1, s2, width, height);
 
         // 2nd sidedef
         x0 += width;
         ix0 = x0 + BOX_BORDER + WIDE_HSPACING;
         y0 = out_y1 - height + 1;
-        // Ignore box_disp -- always redraw the whole box
-        DrawScreenBox3D(x0, y0, x0 + width - 1, y0 + height - 1);
-        if (obj_no >= 0 && sd2 >= 0)
-        {
-            set_colour(WINTITLE);
-            DrawScreenText(ix0, iy0, "Sidedef2 #%d", sd2);
-            set_colour(WINFG);
-            const char *tex_name;
 
-            tex_name = SideDefs[sd2].tex1;        // Upper texture
-            if (s1 >= 0 && s2 >= 0 && Sectors[s2].ceilh > Sectors[s1].ceilh
-                && !(is_sky(Sectors[s1].ceilt) && is_sky(Sectors[s2].ceilt)))
-            {
-                if (tex_name[0] == '-' && tex_name[1] == '\0')
-                    set_colour(CLR_ERROR);
-                else
-                    set_colour(WINFG);
-            }
-            else
-                set_colour(WINFG_DIM);
-            DrawScreenText(-1, iy0 + (int) (1.5 * FONTH),
-                           "\1Upper:\2  %.*s", WAD_TEX_NAME, tex_name);
-
-            tex_name = SideDefs[sd2].tex3;        // Middle texture
-            set_colour(WINFG);
-            DrawScreenText(-1, -1,
-                           "\1Middle:\2 %.*s", WAD_TEX_NAME, tex_name);
-
-            tex_name = SideDefs[sd2].tex2;        // Lower texture
-            if (s1 >= 0 && s2 >= 0 && Sectors[s2].floorh < Sectors[s1].floorh
-                && !(is_sky(Sectors[s1].floort)
-                     && is_sky(Sectors[s2].floort)))
-            {
-                if (tex_name[0] == '-' && tex_name[1] == '\0')
-                    set_colour(CLR_ERROR);
-                else
-                    set_colour(WINFG);
-            }
-            else
-                set_colour(WINFG_DIM);
-            DrawScreenText(-1, -1, "\1Lower:\2  %.*s", WAD_TEX_NAME,
-                           tex_name);
-
-            set_colour(WINFG);
-            DrawScreenText(-1, -1, "\1X-ofs:\2  %d", SideDefs[sd2].xoff);
-            DrawScreenText(-1, -1, "\1Y-ofs:\2  %d", SideDefs[sd2].yoff);
-            DrawScreenText(-1, -1, "\1Sector:\2 #%d", s2);
-        }
-        else
-        {
-            const char *message = "(no 2nd sidedef)";
-            // If the "2" flag is set, there must be a second sidedef
-            if (LineDefs[obj_no].flags & 0x04)        // FIXME hard-coded
-                set_colour(CLR_ERROR);
-            else
-                set_colour(WINFG_DIM);
-            DrawScreenText(x0 + (width - FONTW * strlen(message)) / 2,
-                           y0 + (height - FONTH) / 2, message);
-        }
+        draw_sidedef_info(2, sd2, sd1, obj_no, x0, y0, ix0, iy0, s2, s1, width, height);
 
         // Superimposed linedefs
         {