]> git.draconx.ca Git - rrace.git/commitdiff
Factor out common parts of icon generation.
authorNick Bowler <nbowler@draconx.ca>
Wed, 9 Mar 2022 02:08:46 +0000 (21:08 -0500)
committerNick Bowler <nbowler@draconx.ca>
Wed, 9 Mar 2022 06:32:44 +0000 (01:32 -0500)
The row formatting in the four different icon files is basically
the same, and can be adapted into a common function.

src/ewmhicon.c

index 32392a802df6af414a2bafbae25b937d7ef7f30f..087dc46858bfdd19ad011cd5fb0f395f3f97c13e 100644 (file)
@@ -40,13 +40,27 @@ static unsigned long wm_pixel(const XColor *c)
             | scale16to8(c->blue);
 }
 
+static void format_row(unsigned long *row, const XColor *c,
+                       unsigned s, unsigned y, unsigned w, unsigned h)
+{
+       unsigned x;
+
+       for (x = 0; x < w; x++) {
+               row[x] = wm_pixel(&c[COLOUR_PRIMARY]);
+               if (x < s || y < s)
+                       row[x] = wm_pixel(&c[COLOUR_LIGHT]);
+               if ((x+s >= w && x+y >= w) || (y+s >= h && x+y >= h))
+                       row[x] = wm_pixel(&c[COLOUR_DARK]);
+       }
+}
+
 /*
  * The 16x16 icon is drawn with 1px shadow, 6x6 tiles, with 1 pixel cropped off
  * all the edge tiles
  */
 void ewmh_tile16(unsigned long *icon, const XColor *c, int tile_x, int tile_y)
 {
-       int out_x, out_y, out_w, x, y;
+       int out_x, out_y, out_w, y;
        unsigned long row[6];
 
        out_x = tile_x * 11 / 2;
@@ -54,14 +68,7 @@ void ewmh_tile16(unsigned long *icon, const XColor *c, int tile_x, int tile_y)
        out_w = (5 + (tile_x == 1)) * sizeof row[0];
 
        for (y = 0+(tile_y == 0); y < 6-(tile_y == 2); y++) {
-               for (x = 0+(tile_x == 0); x < 6-(tile_x==2); x++) {
-                       if (x == 0 || y == 0)
-                               row[x] = wm_pixel(&c[COLOUR_LIGHT]);
-                       else if (x == 5 || y == 5)
-                               row[x] = wm_pixel(&c[COLOUR_DARK]);
-                       else
-                               row[x] = wm_pixel(&c[COLOUR_PRIMARY]);
-               }
+               format_row(row, c, 1, y, 6, 6);
                memcpy(&icon[16 * out_y++ + out_x], &row[tile_x == 0], out_w);
        }
 }
@@ -71,21 +78,14 @@ void ewmh_tile16(unsigned long *icon, const XColor *c, int tile_x, int tile_y)
  */
 void ewmh_tile24(unsigned long *icon, const XColor *c, int tile_x, int tile_y)
 {
-       int out_x, out_y, x, y;
+       int out_x, out_y, y;
        unsigned long row[8];
 
        out_x = tile_x * 8;
        out_y = tile_y * 8;
 
        for (y = 0; y < 8; y++) {
-               for (x = 0; x < 8; x++) {
-                       if (x == 0 || y == 0)
-                               row[x] = wm_pixel(&c[COLOUR_LIGHT]);
-                       else if (x == 7 || y == 7)
-                               row[x] = wm_pixel(&c[COLOUR_DARK]);
-                       else
-                               row[x] = wm_pixel(&c[COLOUR_PRIMARY]);
-               }
+               format_row(row, c, 1, y, 8, 8);
                memcpy(&icon[24 * out_y++ + out_x], row, sizeof row);
        }
 }
@@ -96,7 +96,7 @@ void ewmh_tile24(unsigned long *icon, const XColor *c, int tile_x, int tile_y)
  */
 void ewmh_tile32(unsigned long *icon, const XColor *c, int tile_x, int tile_y)
 {
-       int out_x, out_y, out_w, out_h, x, y;
+       int out_x, out_y, out_w, out_h, y;
        unsigned long row[11];
 
        out_x = 10*tile_x + (tile_x > 0);
@@ -105,14 +105,7 @@ void ewmh_tile32(unsigned long *icon, const XColor *c, int tile_x, int tile_y)
        out_h = 10 + (tile_y != 1);
 
        for (y = 0; y < out_h; y++) {
-               for (x = 0; x < out_w; x++) {
-                       if (x == 0 || y == 0)
-                               row[x] = wm_pixel(&c[COLOUR_LIGHT]);
-                       else if (x == out_w-1 || y == out_h-1)
-                               row[x] = wm_pixel(&c[COLOUR_DARK]);
-                       else
-                               row[x] = wm_pixel(&c[COLOUR_PRIMARY]);
-               }
+               format_row(row, c, 1, y, out_w, out_h);
                memcpy(&icon[32 * out_y++ + out_x], row, out_w * sizeof row[0]);
        }
 }
@@ -122,25 +115,14 @@ void ewmh_tile32(unsigned long *icon, const XColor *c, int tile_x, int tile_y)
  */
 void ewmh_tile48(unsigned long *icon, const XColor *c, int tile_x, int tile_y)
 {
-       int out_x, out_y, x, y;
+       int out_x, out_y, y;
        unsigned long row[16];
 
        out_x = tile_x * 16;
        out_y = tile_y * 16;
 
        for (y = 0; y < 16; y++) {
-               for (x = 0; x < 16; x++) {
-                       if (x == 0 || y == 0)
-                               row[x] = wm_pixel(&c[COLOUR_LIGHT]);
-                       else if (x == 15 || y == 15)
-                               row[x] = wm_pixel(&c[COLOUR_DARK]);
-                       else if (x == 1 || y == 1)
-                               row[x] = wm_pixel(&c[COLOUR_LIGHT]);
-                       else if (x == 14 || y == 14)
-                               row[x] = wm_pixel(&c[COLOUR_DARK]);
-                       else
-                               row[x] = wm_pixel(&c[COLOUR_PRIMARY]);
-               }
+               format_row(row, c, 2, y, 16, 16);
                memcpy(&icon[48 * out_y++ + out_x], row, sizeof row);
        }
 }