From e587d0ebee6f3c0e2b9a6eb76583929587e2496a Mon Sep 17 00:00:00 2001 From: Jonathan Westhues Date: Sun, 11 May 2014 15:43:03 -0700 Subject: [PATCH] Fix GUI bugs in FLTK port, per Xavier Thomas's forum post: "There was some small but annoying bugs with the FLTK port: -cursor disappear sometimes -not all the area of the windows (graphic and text windows) is accessible by the mouse after a re-size -input widget for editing constraints value are not correctly placed" --- src/fltk/fltkmain.cpp | 106 +++++++++++++++++++------------ src/fltk/xFl_Gl_Window_Group.H | 3 + src/fltk/xFl_Gl_Window_Group.cxx | 6 ++ 3 files changed, 76 insertions(+), 39 deletions(-) diff --git a/src/fltk/fltkmain.cpp b/src/fltk/fltkmain.cpp index 37bf02c6..ad0e81a5 100644 --- a/src/fltk/fltkmain.cpp +++ b/src/fltk/fltkmain.cpp @@ -359,45 +359,6 @@ int64_t GetUnixTime(void) return (int64_t)ret; } -void ShowTextEditControl(int x, int y, char *s) -{ - if(GraphicsEditControlIsVisible()) return; - - // Note: TextEditControl->position() does NOT set (x,y) position! - TextEditControl->resize(x, y, TextEditControl->w(), TextEditControl->h()); - if(s) TextEditControl->value(s); - TextEditControl->show(); -} - -void HideTextEditControl(void) -{ - TextEditControl->hide(); -} - -bool TextEditControlIsVisible(void) -{ - return TextEditControl->visible(); -} - -void ShowGraphicsEditControl(int x, int y, char *s) -{ - if(GraphicsEditControlIsVisible()) return; - - GraphicsEditControl->position(x, y); - GraphicsEditControl->value(s); - GraphicsEditControl->show(); -} - -void HideGraphicsEditControl(void) -{ - GraphicsEditControl->hide(); -} - -bool GraphicsEditControlIsVisible(void) -{ - return GraphicsEditControl->visible(); -} - class Graphics_Gl_Window : public Fl_Gl_Window_Group { public: @@ -713,6 +674,73 @@ void Text_Gl_Window::dummy(void) // sop to Clang++'s -Wweak-vtables warning } +void ShowTextEditControl(int x, int y, char *s) +{ + if(GraphicsEditControlIsVisible()) return; + + // Note: TextEditControl->position() does NOT set (x,y) position! + // It changes the cursor postion in the input widget + // Use the :: operator to avoid confusion + TextEditControl->Fl_Widget::position(x, y); + if(s) TextEditControl->value(s); + TextEditControl->show(); + + // Grab focus and select all to ease editing + TextEditControl->take_focus(); + TextEditControl->Fl_Input::position(TextEditControl->size()); + TextEditControl->mark(0); + +} + +void HideTextEditControl(void) +{ + // return focus to the GL window before hiding the widget + // this avoid the disapparition of the mouse pointer if it was over the widget + TextGlWnd->take_focus(); + + TextEditControl->hide(); +} + +bool TextEditControlIsVisible(void) +{ + return TextEditControl->visible(); +} + +void ShowGraphicsEditControl(int x, int y, char *s) +{ + if(GraphicsEditControlIsVisible()) return; + + // Convert to ij (vs. xy) style coordinates, + // and compensate for the input widget height due to inverse coord + x = x + GraphicsGlWnd->w()/2; + y = -y + GraphicsGlWnd->h()/2 - GraphicsEditControl->h(); + + // Use of the :: 0perator to avoid confusion with the Fl_input positon metod. + GraphicsEditControl->Fl_Widget::position(x, y); + GraphicsEditControl->value(s); + GraphicsEditControl->show(); + + // Grab focus and select all to ease editing + GraphicsEditControl->take_focus(); + GraphicsEditControl->Fl_Input::position(GraphicsEditControl->size()); + GraphicsEditControl->mark(0); + +} + +void HideGraphicsEditControl(void) +{ + // return focus to the GL window before hiding the widget + // this avoid the disapparition of the mouse pointer if it was over the widget + GraphicsGlWnd->take_focus(); + + GraphicsEditControl->hide(); +} + +bool GraphicsEditControlIsVisible(void) +{ + return GraphicsEditControl->visible(); +} + void InvalidateText(void) { TextGlWnd->redraw(); diff --git a/src/fltk/xFl_Gl_Window_Group.H b/src/fltk/xFl_Gl_Window_Group.H index 05d2abde..01c71825 100644 --- a/src/fltk/xFl_Gl_Window_Group.H +++ b/src/fltk/xFl_Gl_Window_Group.H @@ -82,6 +82,9 @@ public: */ virtual int handle_gl(int event); + // override resize + virtual void resize(int x, int y,int w, int h); + protected: void draw(void); diff --git a/src/fltk/xFl_Gl_Window_Group.cxx b/src/fltk/xFl_Gl_Window_Group.cxx index 8b62a682..0483af5f 100644 --- a/src/fltk/xFl_Gl_Window_Group.cxx +++ b/src/fltk/xFl_Gl_Window_Group.cxx @@ -169,6 +169,12 @@ int Fl_Gl_Window_Group::handle_gl(int event) { return 0; } +void Fl_Gl_Window_Group::resize(int x, int y,int w, int h) +{ + glstandin->resize(x,y,w,h); + Fl_Window::resize(x,y,w,h); +} + void Fl_Gl_Window_Group::flush(void) { // Fl_Window::make_current() does this, but not // Fl_Gl_Window::make_current(), and we can't override make_current()