Re: Get position of cursor in widget?

2007-07-17 Thread Cédric Lucantis
Le lundi 16 juillet 2007 12:50, charlesvpacker a écrit :
 I'm a GTK newbie who has successfully taken the very first
 steps toward building a custom image processing application.
 I've figured out how to read and display an image using
 a GtkImage and GtkPixbuf. I've also modified a block of pixels
 in the existing pixbuf and updated the displayed image
 via gtk_image_set_from_pixbuf. Now I want to get the pixel
 position of the mouse cursor resting on the image. I don't recall
 seeing a GTK tutorial on capturing pointer position or motion.
 Could somebody, um, point me to one?


If you want this from within a mouse event handler, you can use the 
(x,y) and (x_root,y_root) members provided by all the mouse event 
types. The first pair gives the position of the mouse relative to the 
event window and the second the position relative to the screen origin. 

If you're not in a handler, you still have gdk_window_get_pointer() and 
gdk_display_get_pointer(). See the Gdk reference manual for more infos 
(sections 'Event structures', 'Windows' and 'Display').

-- 
Cédric Lucantis
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: Image process in gdk

2007-05-20 Thread Cédric Lucantis
Le dimanche 20 mai 2007 17:45, Luis Ramirez a écrit :
 Hello

 I am just a beginner in gtk and after working with the excellent samples
 available I wanted to begin with a simple program that loads an image and
 applies different processes on it (brightness, BW, rotate, ...).
 If I load and process the image before gtk_main() everything goes right but
 if I link the call_back of a Button to a function, the image does not
 change.
 I have tried to use the widget expose_event but it works with a widget
 created with gtk_drawing_area_new(), but not with a widget created with
 gdk_pixbuf_new_from_file().

It looks like you are confusing GdkPixbuf and GtkPixbuf. A GdkPixbuf is not a 
widget but only an object storing a bitmap, while a GtkPixbuf is a widget 
displaying a GdkPixbuf. Anyway, GtkPixbuf is deprecated so you should use 
GtkImage instead.
If it's not enough for your needs, you'll have to create your own widget 
extending GtkDrawingArea, see the Gtk tutorial (section 'Writing your own 
widgets') for more infos about that.

 Do you have any simple example about it?. It is simpler to show images with
 cairo?

There's also a complete example in the tutorial (scribble).

Cairo is a vector graphics lib, which is very different from bitmap graphics. 
I never used it, so I don't know if it's easier, it's just another world and 
the choice depends on what you want to do.

-- 
Cédric Lucantis
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: Gtk+ and multithreating

2007-05-14 Thread Cédric Lucantis
Le lundi 14 mai 2007 20:20, Michael Ekstrand a écrit :
 On Mon, 2007-05-14 at 19:53 +0200, Michelle Konzack wrote:
  So, can anyone provide me with a Tutorial HOW TO MULTITHREAD those
  functions some_code_to_update_the_dialog ?
 
  And maybe some other tips...

 Can you do everything asynchronously?  Initiate your connections, and
 set up some GIOChannels to watch for data availability?  That will let
 you set up callbacks so the GLib main loop will notify your program as
 bits of data are available from each server.  You don't block on
 communication, your GUI stays responsive, and you don't have to worry
 about the complexities of multithreading.

 - Michael

Michael is probably right, but to answer your question there's a good 
documentation about that in the GLib manual. See the 
sections 'Threads', 'Thread Pools' and 'Asynchronous Queues' under 'Glib Core 
Application Support'. If you want to know more, there's a tutorial here 
(about pthread but with a general introduction) :

http://www.llnl.gov/computing/tutorials/pthreads

-- 
Cédric Lucantis
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: Simple draw question

2007-05-06 Thread Cédric Lucantis
 
  You should never draw anything in an enter/leave callback, but only in an
  expose event. Also note that creating/destroying a GC each time you draw
  it is very slow, so you should do something like this instead:

 Ok, I have questions here and they are because I really want to know why
 and not start anything.

 1. Why is drawing in the enter in leave callback not something you
 should do? Is it because if you do to much it can cause a backlog of
 events?

Merely a 'good design' question, but also because some prepare/release stuff 
is required before and after drawing on a GdkWindow (basicaly to set the 
clipping region and to setup the double buffer and copy its contents after 
the drawing operations). This is done by gdk_window_begin_paint_rect() and 
gdk_window_end_paint() which are automatically called by gtk when an expose 
event is processed. I think you can also call these yourself if you really 
want to keep your drawing within the leave/enter events, but a 
more 'conventional' way is to invalidate the window and then call 
gdk_window_process_updates() to process the expose event immediately.
You'll find a lot of interesting things about that in the GdkWindow doc.


 2. Actually while creating and destroying a GC may be slow (and I don't
 think it is actually that slow) it seems that in this case I should have
 just looked them up off the widget (which I didn't know there were
 several GCs off of the widget style).

Not sure it is that slow, but using an existing one is obviously faster than 
creating it. It's also better (but of course not mandatory) to use the ones 
provided by the widget style, first because that's why they are here, and 
because it'll keep your app consistent if the user modify some style/resource 
settings (but I don't know much about that).
For info, manys GCs are created by the style, see gtkstyle.h for a list of 
them.


 3. I did try what you recommended and basically I found this. The expose
 event was not fired enough. I _think_ what happens is that GTK optimizes
 calls to event handlers and so if you send it 5 requests to expose on
 the same object and they stack up in the dispatcher, you only get one
 expose event called (this is actually the right thing to do) and so when
 I was testing this, I would get only one call to expose and so the box
 would never be drawn. (my guess could be totally wrong here).

I don't understand what you mean here. It's true that gtk optimizes the 
invalidate calls, not by stacking them but by keeping an 'update_area' for 
each window and thus only redrawing the dirty part of it when nothing else 
has to be done (this is managed by an idle event). But even if you get only 
one call to expose, shouldn't it be enough to redraw it ?

Finally, note that I'm definitely not a gtk wizard, so maybe am I only saying 
stupid things here ;)

-- 
Cédric Lucantis
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: Simple draw question

2007-05-05 Thread Cédric Lucantis
Le samedi 5 mai 2007 00:48, Kevin DeKorte a écrit :
 Hi,

 I have a situation where I need to highlight an eventbox when a user
 enters it and unhighlight it when the users leaves. I'm using this code
 but the color I'm drawing in the leave_button_callback is always wrong
 and varies from run to run with the program. Any ideas what I am doing
 wrong. I was looking for a XOR option or something but I don't see it.

 gboolean enter_button_callback (GtkWidget *widget, GdkEventCrossing
 *event, gpointer data)
 {
   GdkGC *gc;
   gc = gdk_gc_new(widget-window);
 gdk_draw_rectangle(widget-window, gc, FALSE, 0, 0,
 widget-allocation.width-1,
widget-allocation.height-1);
 gdk_gc_unref(gc);

   return FALSE;
 }

 gboolean leave_button_callback (GtkWidget *widget, GdkEventCrossing
 *event, gpointer data)
 {
   GdkGC *gc;
   GdkGCValues v;
   GdkColor color;
   GdkColormap *map;

   gc = gdk_gc_new(widget-window);
   map = gdk_gc_get_colormap(gc);
   gdk_gc_get_values(gc,v);
   gdk_colormap_query_color(map,v.background.pixel,color);

   gdk_gc_set_foreground(gc,color);

 gdk_draw_rectangle(widget-window, gc, FALSE, 0, 0,
 widget-allocation.width-1,
widget-allocation.height-1);
 gdk_gc_unref(gc);
   return FALSE;
 }

You should never draw anything in an enter/leave callback, but only in an 
expose event. Also note that creating/destroying a GC each time you draw it 
is very slow, so you should do something like this instead:

enter_button_callback()
{
gtk_widget_set_state(widget, GTK_STATE_PRELIGHT);

/* not sure this is required, as it's maybe called by set_state? */
/* you may use gdk_window_invalidate_* instead for better performances,
 * see the docs for more infos */
gtk_widget_queue_draw(widget);
}

leave_button_callback()
{
/* same with GTK_STATE_NORMAL */
}

expose_button_callback()
{
gdk_draw_rectangle(widget-window, widget-state-fg_gc[widget-state], 
...)
}

-- 
Cédric Lucantis
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: Radio button

2007-03-15 Thread Cédric Lucantis
 My application has a number of radio buttons stored in a horizontal button
 box.

 The radio buttons were created with gtk_radio_button_new_with_label and
 gtk_radio_button_new_with_label_from_widget.

 Each button and its label is left-justified (aligned?) within its
 allocation rectangle.

 I want the button and the label to be centered in the allocation rectangle.

 The machines on which my application will be deployed are running Gtk
 version 2.0.

 Thanks in advance for any help.

You need a GtkAlignment widget, documented in the manual.

-- 
Cédric Lucantis
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: Cross compilation for windows

2007-03-02 Thread Cédric Lucantis
Hi,

 I thought of running my application on windows, so i searched in google
 and i got the script to setup cross compilation environment for
 window.And I succeded in setting up the environment for
 cross-compilation using the sources

 binutils-2.11.2.tar.bz2
 gcc-2.95.3.tar.gz
 mingw-runtime-1.0.1-20010726-src.tar.gz
 w32api-1.0.1-20010726-src.tar.gz

 Now my problem is how to cross compile?
 I dont have any idea to cross compile,


There's a 'cross compiling the glib package' in glib user's manual. It worked 
fine for me, but I'm only using glib, not gtk so I can't help for it. Anyway 
you'll probably prefer to use the prebuild packages available on gtk.org 
(follow the Projects/GTK+ for Win32 link)

-- 
Cédric Lucantis
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: Need your help on the widget's width and height

2006-03-17 Thread Cédric Lucantis
Le Vendredi 17 Mars 2006 13:17, yeajchao a écrit :
 Hello everyone
 I am writing my own gtk widget
 and i want my own widget's height and width ratio is 0.8, like this:

widget-allocation.height / widget-allocation.width == 0.8

 and my gtk_mywidget_size_allocate() function like this:

  Start of my code
 ---
 static void
 gtk_mywidget_size_allocate(GtkWidget *widget,
GtkAllocation *allocation)
 {
  ??

 if (allocation-height = allocation-width * 0.8)
 allocation-height = allocation-width;
 else
 allocation-width = allocation-height/0.8;

 widget-allocation = *allocation;

 ??
 }
  End of my code -

But ,i found ,in my test application,my own widget's size didn't change
Who can tell my what's wrroy ?
And who can tell my how to maintain my widget's height, width ratio to a
 constant value ?

Any help would be much appreciated !

The GtkAspectFrame widget seems to be what you are looking for. You
can probably use it or at least have a look at its source code. It
looks like you already read it, but just in case there is a chapter
'Creating your own widget' in the Gtk tutorial which explains the size
negotiation process.

Bye,
--
Cédric Lucantis

___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list