Re: [fltk.general] Open a menu with Mouse hover
You can inherit Fl_Menu_Bar and catch FL_ENTER events. Here is the working sample: #include FL/Fl.H #include FL/Fl_Double_Window.H #include FL/Fl_Menu_Bar.H #include FL/Fl_Menu_Item.H class MyBar : public Fl_Menu_Bar { public: MyBar(int X, int Y, int W, int H, const char *l=0) : Fl_Menu_Bar(X, Y, W, H, l) { } int handle(int e) { if(e == FL_ENTER) { const Fl_Menu_Item *v; v = menu()-pulldown(x(), y(), w(), h(), v, this, 0, 1); picked(v); return 1; } return Fl_Menu_Bar::handle(e); } }; int main(int argc, char **argv) { Fl_Double_Window *win = new Fl_Double_Window(300,100); MyBar *menubar = new MyBar(0,0,300,25); menubar-add(File/Open); menubar-add(File/Save); menubar-add(Edit/Cut); menubar-add(Edit/Copy); menubar-add(Edit/Paste); win-end(); win-show(); return(Fl::run()); } pulldown() function will use mouse position and according to coordinates, select appropriate menu item. The same strategy is used for getting ordinary 'click-ed' menu event, except it is handled when FLTK receives FL_PUSH event. Sanel On 01/21/2013 06:38 PM, Howard Rubin wrote: How can I get a menu item to drop down by hovering the mouse? In this program, clicking on the File menu will drop it down, and then I can just move the mouse over the Edit menu to drop it down. I need the File menu to drop down when I move the mouse over it without the mouse click. #include FL/Fl.H #include FL/Fl_Double_Window.H #include FL/Fl_Menu_Bar.H int main(int argc, char **argv) { Fl_Double_Window *win = new Fl_Double_Window(300,100); Fl_Menu_Bar *menubar = new Fl_Menu_Bar(0,0,300,25); menubar-add(File/Open); menubar-add(File/Save); menubar-add(Edit/Cut); menubar-add(Edit/Copy); menubar-add(Edit/Paste); win-end(); win-show(); return(Fl::run()); } ___ fltk mailing list fltk@easysw.com http://lists.easysw.com/mailman/listinfo/fltk
[fltk.general] Open a menu with Mouse hover
How can I get a menu item to drop down by hovering the mouse? In this program, clicking on the File menu will drop it down, and then I can just move the mouse over the Edit menu to drop it down. I need the File menu to drop down when I move the mouse over it without the mouse click. #include FL/Fl.H #include FL/Fl_Double_Window.H #include FL/Fl_Menu_Bar.H int main(int argc, char **argv) { Fl_Double_Window *win = new Fl_Double_Window(300,100); Fl_Menu_Bar *menubar = new Fl_Menu_Bar(0,0,300,25); menubar-add(File/Open); menubar-add(File/Save); menubar-add(Edit/Cut); menubar-add(Edit/Copy); menubar-add(Edit/Paste); win-end(); win-show(); return(Fl::run()); } ___ fltk mailing list fltk@easysw.com http://lists.easysw.com/mailman/listinfo/fltk
Re: [fltk.general] Open a menu with Mouse hover
On 21 Jan 2013, at 17:39, Howard Rubin wrote: How can I get a menu item to drop down by hovering the mouse? In this program, clicking on the File menu will drop it down, and then I can just move the mouse over the Edit menu to drop it down. I need the File menu to drop down when I move the mouse over it without the mouse click. #include FL/Fl.H #include FL/Fl_Double_Window.H #include FL/Fl_Menu_Bar.H int main(int argc, char **argv) { Fl_Double_Window *win = new Fl_Double_Window(300,100); Fl_Menu_Bar *menubar = new Fl_Menu_Bar(0,0,300,25); menubar-add(File/Open); menubar-add(File/Save); menubar-add(Edit/Cut); menubar-add(Edit/Copy); menubar-add(Edit/Paste); win-end(); win-show(); return(Fl::run()); } There's no built-in support for that in fltk, so you'll need to roll your own widget to do this. For most widgets, the normal thing to do would be just derive from the widget you want to tweak, then override the handle() method to catch the enter/leave events and use those to trigger your drop down. But... for historical reasons (possibly to be resolved in fltk3!) the Fl_Menu_Item widget is not a true class, and you can't really derive your own modified version as a result... Instead, what you can do is replace the Fl_Menu_Bar with a simple box, populated with your own widgets derived from Fl_Menu_Button - this can easily be made to appear like a conventional menu bar, but the derived Fl_Menu_Button widgets can have a modified handle() method that catches the FL_ENTER / FL_LEAVE events and uses those events to trigger to popping up (or down) of the menu associated with the Fl_Menu_Button. Any use...? ___ fltk mailing list fltk@easysw.com http://lists.easysw.com/mailman/listinfo/fltk