Hello,
I am trying to draw a rectangle from the point, where the user starts to drag
the mouse to the actual mouse position. I tried to make the code like this, it
draws the rectangle but only when the mouse is moving. When I stop moving the
mouse, the rectangle disapears till I move again.
Can you please help me to make the rectangle visible until I release the mouse
button?
//header file
struct Point{
double x;
double y;
double z;
};
class My_OpenGL_View : public Fl_Gl_Window
{
public:
My_OpenGL_View(int x, int y, int w, int h, const char *label = 0);
~My_OpenGL_View();
int handle(int event);
void draw(void);
public:
bool selectionRectangle;
Point mouseClick;
Point mousePosition;
}
//cpp file
My_OpenGL_View::My_OpenGL_View(int x, int y, int w, int h, const char
*label):Fl_Gl_Window(x,y,w,h,label)
{
selectionRectangle = false;
}
My_OpenGL_View::~My_OpenGL_View(void)
{
}
int My_OpenGL_View::handle( int event )
{
switch(event) //switch events
{
case FL_MOVE:
mouseClick.x = Fl::event_x();
mouseClick.y = Fl::event_y();
return 1;
case FL_PUSH:
if (Fl::event_button() == 1)
{
selectionRectangle = true;
}
case FL_DRAG:
mousePosition.x = Fl::event_x();
mousePosition.y = Fl::event_y();
this->redraw();
case FL_RELEASE:
if(Fl::event_button()==1) //on right button release
{
scene.PickObjects(x, y, sizeX, sizeY);
selectionRectangle = false;
}
case FL_FOCUS:
case FL_UNFOCUS:
this->redraw();
return 1;
default:
return Fl_Window::handle(event);
}
}
void My_OpenGL_View::draw( void )
{
//some opengl rendering
if (selectionRectangle)
{
fl_line_style(FL_SOLID,2);
fl_color(FL_RED);
fl_loop(mouseClick.x, mouseClick.y, mousePosition.x,
mouseClick.y, mousePosition.x, mousePosition.y, mouseClick.x, mousePosition.y);
}
}
_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk