selecting rectangle region as in gimp



Hi,

I am new to gtk. Looking at the examples of
scribble-simple and wheelbarrow, I could get to
display my own image and paint a 5 * 5 (or n * n)
black rectangle onto my image. But I would like to
have something like what gimp is providing.
Essentially dragging, that could paint a black
rectangle (or elliptical region) onto my image.

Could anyone guide me how I can acheive this? I
actually need the coordinates as well, of the entire
painted rectangle.

Once I have the image drawn, using 

void on_darea_expose (GtkWidget* widget,
                      GdkEventExpose* event,
                      gpointer user_data)
{
    gdk_draw_gray_image(widget->window,
widget->style->fg_gc[GTK_STATE_NORMAL],
                        0, 0, IMAGE_WIDTH,
IMAGE_HEIGHT,
                        GDK_RGB_DITHER_MAX, rgbbuf,
IMAGE_WIDTH*IMAGE_DEPTH);
} //where rgbbuf is the image buffer

I am using the following functions to acheive my
functionality

static gint button_press_event( GtkWidget     
*widget,
                                GdkEventButton *event
)
{
  if (event->button == 1 && widget->window != NULL &&
value == 1)
    draw_brush (widget, event->x, event->y);
  
  
  return TRUE;
}

static void draw_brush( GtkWidget *widget,
                        gdouble    dx,
                        gdouble    dy)
{
  GdkRectangle update_rect;
  int num;int i, j;
  gtk_signal_connect (GTK_OBJECT (darea),
"motion_notify_event",
		      (GtkSignalFunc) motion_notify_event, NULL);
 for(i = 1; i < 6; i++)
 {
 	for(j = 0; j < 5; j++)
 {
 	num = dy * IMAGE_WIDTH + dx + j;
 	
 	rgbbuf[num]=0;//buffer of my image
 	
 }
 dy += 1;
 }
 	
  
  update_rect.x = dx - 5;
  update_rect.y = dy - 5;
  update_rect.width = 10;
  update_rect.height = 10;
  gdk_draw_rectangle (widget->window,
		      widget->style->black_gc,
		      TRUE,
		      update_rect.x, update_rect.y,
		      update_rect.width, update_rect.height);
  gtk_widget_draw (widget, &update_rect);
  
}

As I said, this only blackens a n * n rectangle, but I
would like to have something like in gimp (dragging
such that entire dragged area is blackened out and
also I could get all the blackened coordinates). Which
functions could I use? Is there some plugin or sample
code that I could use?

Thanks in advance for any help.

Srinivas



__________________________________
Do you Yahoo!?
The New Yahoo! Shopping - with improved product search
http://shopping.yahoo.com



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