Re: How to create a label that moves along with the mouse cursor?



On 28/04/2007 12:27, Chris Dams mi infn it wrote:
> I am new to GTK but already succeeded into drawing a graph with real
> values on the plane that are color encoded (i.e., in mathematical
> language: a function RxR -> R, where RxR is represented by a DrawingArea
> and the outcome of the function by a colored pixel at the right position.)
> Now I would like to also display the value at the point where the mouse
> cursor happens to be inside the drawing area and I would like to do this
> by displaying a label next to the mouse cursor on which the value at the
> cursor position is shown. It should move along with the cursor and adjust
> the value shown depending on the current cursor position. I figured out
> that I can respond to pointer motion events and read their co-ordinates,
> but I do not know how to create the label to show the appropriate value.
> Could someone on this list tell me? Is this possible in GTK?
>   

You could just do this:
On the mouse move event of your drawing area you store the position of
the mouse pointer in a member variable of your (window-?) class. Then
you queue_draw() on your drawing area. In the function where you draw
the (buffered?) graph to the drawing area you add a couple of lines to
draw text at the stored location.

Niko Demmel



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