FLTK logo

Re: event_x() To Get FL_Gl_Window Coordinates

FLTK matrix user chat room
(using Element browser app)   FLTK gitter user chat room   GitHub FLTK Project   FLTK News RSS Feed  
  FLTK Apps      FLTK Library      Forums      Links     Login 
 All Forums  |  Back to fltk.opengl  ]
 
Previous Message ]New Message | Reply ]Next Message ]

Re: event_x() To Get FL_Gl_Window Coordinates Albrecht Schlosser Apr 05, 2013  
 
On 03.04.2013 22:54, Mike Werner wrote:
> I want to be able to left click in an OpenGL window and have the mouse coordinates in that window returned (i.e. relative to the upper left corner of the window). Seems like I should be able to do this using Fl::event_x.  However it's turning out to be difficult. First of all the only way I can get event_x to return anything is to put it in the draw function of my Fl_Gl_Window with the syntax Fl::event_x(). But this doesn't return anything when I click in the OpenGL window. It ONLY returns coordinates when I click on a button outside the OGL window. And the X value returned is relative to main FLTK window. Not what I need.

First of all: Fl::event_x() is only valid in the event handling code
or in a callback called from this code. Putting Fl::event_x() in a
draw() method can only give you _undefined_ values, i.e. it _can_
sometimes be what you expect. This is because Fl::event_x() uses
a static variable that is updated only on some events like mouse
clicks, but also on FL_MOVE and maybe others.

I saw your follow-up: using a button underneath the OGL window
might do what you need, since you get the button callback when
the click event is handled. There is no way other than to do
the coordinate translation yourself, since the OGL window has
its own coordinate system, but the button coordinates are
relative to the button's window().

> Was hoping to be able to put event_x() in the draw function

never put it in the draw() method, see above.

> or in the callback to Fl_Gl_Window and get OGL window relative coordinates.
>
> The only idea I have now is to put a large button underneath the OGL window. When I click inside the OGL window, this button will be activated and I'll get an x cord. relative to the main FLTK window and have to subtract off the upper left corner coordinates of the OGL window.
>
> Anyone have a more elegant solution?

I'd try to put an invisible box or button in the OGL window that
serves the same purpose as your button in the main window. The
invisible box could be an own derived class, so that you can
use the handle() method, but a simple callback would also do
the job. However, event handling in GL Windows might differ
from normal windows, so I don't know if this would work.


Albrecht
Direct Link to Message ]
 
     
Previous Message ]New Message | Reply ]Next Message ]
 
 

Comments are owned by the poster. All other content is copyright 1998-2024 by Bill Spitzak and others. This project is hosted by The FLTK Team. Please report site problems to 'erco@seriss.com'.