Re: method to erase a drawing area



Hello Frederico,

What you are doing is basically hit detection. What I wonder is why you are
doing it the "hard" way. Why don't you use one of the canvas widgets, e.g.
goocanvas? It allows you to tie events to specific geometric objects.

If you want to do it on your own I first of all suggest that you use cairo,
using gdk_draw_* is considered obsolete. Second you can use the idea of
keeping a second non-visible image as a "label" image. I've described this
multiple times on the net:

   - http://www.mail-archive.com/gtk-perl-list gnome org/msg01428.html
   - http://www.mail-archive.com/gtk-list gnome org/msg27934.html

Regarding your approach you can still salvage it by instead of checking for

 if((GPOINTER_TO_INT(desenho->parray->pdata[x1]) == x) &&
(GPOINTER_TO_INT(desenho->parray->pdata[x1+1]) == y))

you check for

          int xp = GPOINTER_TO_INT(desenho->parray->pdata[x1]);
          int yp = GPOINTER_TO_INT(desenho->parray->pdata[x1+1]);
          int posH = GPOINTER_TO_INT(desenho->parray->pdata[x1+2]);
          int posV = GPOINTER_TO_INT(desenho->parray->pdata[x1+3]);

if (abs(xp-x)<posH && abs(yp-y)<posV) ...

Regards,
Dov


2009/4/17 frederico schardong <frede sch gmail com>

Hi,

I have a drawing area, and a window with 2 gtk_range, and them
variable form 1 to 10, and this values go to posH and posV. I'm doing
this to can draw a rectangular with my specification.. max width: 10,
min: 1, max henght:10, min: 1.

This event is called when drawing area is clicked:

static gboolean button_pressed (GtkWidget *a, GdkEventButton *event)
{
   gint x = event->x, y = event->y, x1, y1;

       for(x1 = (0-posH); x1 < posH; x1++)
       {
           for(y1 = (0-posV); y1 < posV; y1++)
           {
               gdk_draw_point(desenho->drawingArea->window,
desenho->drawingArea->style->fg_gc[GTK_WIDGET_STATE(desenho->drawingArea)],
x+x1, y+y1);
           }
       }

       g_print("\ndrawing x: %d y: %d tamH: %d tamV: %d", x, y, posH,
posV);

       g_ptr_array_add(desenho->parray, GINT_TO_POINTER(x));
       g_ptr_array_add(desenho->parray, GINT_TO_POINTER(y));
       g_ptr_array_add(desenho->parray, GINT_TO_POINTER(posH));
       g_ptr_array_add(desenho->parray, GINT_TO_POINTER(posV));
}

But now I must do a eraser function... I do a simple for:
gint x1, x = event->x, y = event->y;

for (x1 = 0; x1 < desenho->parray->len; x1 = x1 + 4)
       {
           if((GPOINTER_TO_INT(desenho->parray->pdata[x1]) == x) &&
(GPOINTER_TO_INT(desenho->parray->pdata[x1+1]) == y))
           {   g_print("\nta no lugar certo mano!");
               g_ptr_array_remove_index(desenho->parray, x1);
               g_ptr_array_remove_index(desenho->parray, x1);
               g_ptr_array_remove_index(desenho->parray, x1);
               g_ptr_array_remove_index(desenho->parray, x1);
           }


 it's work, but not fine... it's only work when i click exactly where
I clicked before to draw this point... but I need to delete from
GPtrArray when I click on somewhere of this rectangle area... not only
center... Can help me list?
_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]