Update of /cvsroot/tuxpaint/tuxpaint/src
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29336/src

Modified Files:
        magic.h tuxpaint.c 
Log Message:
new smudge tool

Index: magic.h
===================================================================
RCS file: /cvsroot/tuxpaint/tuxpaint/src/magic.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- magic.h     23 Nov 2004 01:28:45 -0000      1.3
+++ magic.h     6 Dec 2004 23:56:43 -0000       1.4
@@ -37,6 +37,7 @@
   MAGIC_THIN,
 
   MAGIC_FILL,
+  MAGIC_SMUDGE,
   
   NUM_MAGICS
 };
@@ -63,7 +64,8 @@
   gettext_noop("Thick"),
   gettext_noop("Thin"),
 
-  gettext_noop("Fill")
+  gettext_noop("Fill"),
+  gettext_noop("Smudge"),
 };
 
 
@@ -88,7 +90,8 @@
   gettext_noop("Click and move the mouse to thicken the picture."),
   gettext_noop("Click and move the mouse to thin the picture."),
 
-  gettext_noop("Click in the picture to fill that area with color.")
+  gettext_noop("Click in the picture to fill that area with color."),
+  gettext_noop("Click and move the mouse around to smudge the picture."),
 };
 
 
@@ -113,7 +116,8 @@
   DATA_PREFIX "images/magic/thick.png",
   DATA_PREFIX "images/magic/thin.png",
 
-  DATA_PREFIX "images/magic/fill.png"
+  DATA_PREFIX "images/magic/fill.png",
+  DATA_PREFIX "images/magic/blur.png",  // FIXME: this is the smudge tool
 };
 
 

Index: tuxpaint.c
===================================================================
RCS file: /cvsroot/tuxpaint/tuxpaint/src/tuxpaint.c,v
retrieving revision 1.191
retrieving revision 1.192
diff -u -d -r1.191 -r1.192
--- tuxpaint.c  6 Dec 2004 20:03:29 -0000       1.191
+++ tuxpaint.c  6 Dec 2004 23:56:43 -0000       1.192
@@ -727,8 +727,8 @@
 static void mainloop(void);
 static void brush_draw(int x1, int y1, int x2, int y2, int update);
 static void blit_brush(int x, int y);
-static void magic_draw(int x1, int y1, int x2, int y2);
-static void blit_magic(int x, int y);
+static void magic_draw(int x1, int y1, int x2, int y2, int button_down);
+static void blit_magic(int x, int y, int button_down);
 static void stamp_draw(int x, int y);
 static void rec_undo_buffer(void);
 static void update_canvas(int x1, int y1, int x2, int y2);
@@ -2104,8 +2104,6 @@
                {
                  /* Draw something! */
                  
-                 button_down = 1;
-                 
                  old_x = event.button.x - 96;
                  old_y = event.button.y;
                  
@@ -2232,7 +2230,7 @@
                     
                      if (cur_magic != MAGIC_FILL)
                        {
-                         magic_draw(old_x, old_y, old_x, old_y);
+                         magic_draw(old_x, old_y, old_x, old_y, button_down);
                        }
                      else
                        {
@@ -2284,7 +2282,8 @@
                      do_render_cur_text(0);
                    }
                  
-                 
+                 button_down = 1;
+
                  /* Make sure these commands are available now: */
                  
                  if (tool_avail[TOOL_NEW] == 0)
@@ -2818,7 +2817,7 @@
                          cur_magic != MAGIC_MIRROR &&
                          cur_magic != MAGIC_FILL)
                        {
-                         magic_draw(old_x, old_y, new_x, new_y);
+                         magic_draw(old_x, old_y, new_x, new_y, button_down);
                        }
                    }
                  else if (cur_tool == TOOL_ERASER)
@@ -3914,7 +3913,7 @@
 
 /* Draw using the current brush: */
 
-static void magic_draw(int x1, int y1, int x2, int y2)
+static void magic_draw(int x1, int y1, int x2, int y2, int button_down)
 {
   int dx, dy, y;
   int orig_x1, orig_y1, orig_x2, orig_y2, tmp;
@@ -3952,12 +3951,12 @@
           if (y1 > y2)
            {
              for (y = y1; y >= y2; y--)
-               blit_magic(x1, y);
+               blit_magic(x1, y, button_down);
            }
           else
            {
              for (y = y1; y <= y2; y++)
-               blit_magic(x1, y);
+               blit_magic(x1, y, button_down);
            }
        
          x1 = x1 + dx;
@@ -3968,12 +3967,12 @@
       if (y1 > y2)
        {
          for (y = y1; y >= y2; y--)
-           blit_magic(x1, y);
+           blit_magic(x1, y, button_down);
        }
       else
        {
          for (y = y1; y <= y2; y++)
-           blit_magic(x1, y);
+           blit_magic(x1, y, button_down);
        }
     }
 
@@ -4029,7 +4028,7 @@
 
 /* Draw the current brush in the current color: */
 
-static void blit_magic(int x, int y)
+static void blit_magic(int x, int y, int button_down)
 {
   int xx, yy, w, h;
   Uint32 colr;
@@ -4162,6 +4161,36 @@
          SDL_UnlockSurface(canvas);
          SDL_UnlockSurface(last);
        }
+      else if (cur_magic == MAGIC_SMUDGE)
+       {
+         static double state[32][32][3];
+         unsigned i = 32*32;
+         double rate = button_down ? 0.5 : 0.0;
+
+         SDL_LockSurface(last);
+         SDL_LockSurface(canvas);
+
+         while (i--)
+           {
+             int iy = i>>5;
+             int ix = i&0x1f;
+             // is it not on the circle of radius sqrt(120) at location 16,16?
+             if ( (ix-16)*(ix-16) + (iy-16)*(iy-16) > 120)
+               continue;
+             // it is on the circle, so grab it
+
+             //SDL_GetRGB(getpixel(last, x+ix-16, y+iy-16), last->format, &r, 
&g, &b);
+             SDL_GetRGB(getpixel(canvas, x+ix-16, y+iy-16), last->format, &r, 
&g, &b);
+             state[ix][iy][0] = rate*state[ix][iy][0] + 
(1.0-rate)*sRGB_to_linear_table[r];
+             state[ix][iy][1] = rate*state[ix][iy][1] + 
(1.0-rate)*sRGB_to_linear_table[g];
+             state[ix][iy][2] = rate*state[ix][iy][2] + 
(1.0-rate)*sRGB_to_linear_table[b];
+
+             // opacity 100% --> new data not blended w/ existing data
+             putpixel(canvas, x+ix-16, y+iy-16, SDL_MapRGB(canvas->format, 
linear_to_sRGB(state[ix][iy][0]), linear_to_sRGB(state[ix][iy][1]), 
linear_to_sRGB(state[ix][iy][2])));
+           }
+         SDL_UnlockSurface(canvas);
+         SDL_UnlockSurface(last);
+       }
       else if (cur_magic == MAGIC_NEGATIVE)
        {
          SDL_LockSurface(last);
@@ -4171,8 +4200,6 @@
            {
              for (xx = x - 16; xx < x + 16; xx++)
                {
-                 /* Get average color around here: */
-               
                  SDL_GetRGB(getpixel(last, xx, yy), last->format,
                             &r, &g, &b);
        

_______________________________________________
Tuxpaint-commits mailing list
[EMAIL PROTECTED]
http://tux4kids.net/mailman/listinfo/tuxpaint-commits

Reply via email to