|
Post by bigbass on Nov 12, 2017 17:24:22 GMT 1
I understand how to get events in gtk/gdk
but I am missing something using fltk
I spent a few hours and got this far with working code minus the event part
we really need to get this working to have full control of the low level signals
PRAGMA INCLUDE <FL/Fl.H> <FL/Fl_Window.H> <FL/Fl_Button.H> <iostream> PRAGMA LDFLAGS -lfltk PRAGMA COMPILER g++ PRAGMA OPTIONS -Wno-write-strings -Wno-pointer-arith
OPTION PARSE FALSE
SUB but_a_cb(Fl_Widget* w, void* v) printf("The button was pressed\n") std::cout << " Button A clicked a callback reached!\n";
END SUB
DECLARE win TYPE Fl_Window* DECLARE but_a TYPE Fl_Button* DECLARE MyButton TYPE Fl_Button*
win = new Fl_Window(120,150) win->begin() but_a = new Fl_Button(10,10,100,25,"A") but_a->shortcut('a') but_a->callback(but_a_cb) 'win->end() win->show() Fl::run()
I reduced this code down to the minimum that works correctly and got rid of the namespace too just need to add the struct, handle ,case ,switch part for bacon
sorry the formatting got lost when I pasted into the forum
TIP if you use geany compile with this build option to save time
g++ -Wall -c "%f" -lfltk -lXext -lX11 -lm
g++ -Wall -o "%e" "%f" -lfltk -lXext -lX11 -lm
#include <FL/Fl.H> #include <FL/Fl_Window.H> #include <FL/Fl_Button.H> #include <iostream>
struct MyButton : Fl_Button {
MyButton(int x,int y,int w,int h,const char*l=0) :Fl_Button(x,y,w,h,l) {} int handle(int e) { int ret = Fl_Button::handle(e); switch(e) { case FL_PUSH: std::cout<<" push\n"<<" event and returns:\n"<<ret; break; case FL_RELEASE: std:: cout<<" release"<<" event and returns:\n"<<ret; break; } return(ret); } };
void but_a_cb(Fl_Widget* w, void* v){ std::cout << " Button A clicked a callback reached!\n"; }
int main() { Fl_Window win(120,150); win.begin();
MyButton but_a(10,10,100,25,"A"); but_a.shortcut('a'); but_a.callback(but_a_cb); win.end(); win.show(); return(Fl::run()); }
|
|
|
Post by vovchik on Nov 12, 2017 19:37:14 GMT 1
Dear Joe, I remember doing something with event handling, and one of the FLKT includes (.H) lists all the events and keyboard codes. Can't remember which, though, but your idea of organizing all that so that it is easy to use is excellent. With kind regards, vovchik PS. Something useful here: events and here: more events. And check out "/usr/include/FL/names.h", too. I once did a demo with fltkc: ' *********************** ' COMPILER DIRECTIVES ' ***********************
PRAGMA LDFLAGS fltkc
' *********************** ' END COMPILER DIRECTIVES ' ***********************
' *********************** ' EXTERNAL FUNCTIONS ' ***********************
PROTO Fl_WindowExNew ALIAS WINDOW PROTO Fl_BoxNew ALIAS BOX PROTO Fl_WindowShow ALIAS SHOW PROTO Fl_Run ALIAS DISPLAY PROTO Fl_BoxNew ALIAS BOX PROTO Fl_SetScheme ALIAS SCHEME_SET PROTO Fl_WidgetSetColor ALIAS SET_COLOR PROTO Fl_WindowExSetHandleCB ALIAS CALLBACK PROTO Fl_EventText ALIAS GET_EVENT_TEXT
' *********************** ' END EXTERNAL FUNCTIONS ' ***********************
' *********************** ' INITIALIZATION ' ***********************
DECLARE win, box TYPE long ' event constants CONST FL_NO_EVENT = 0 CONST FL_PUSH = 1 CONST FL_RELEASE = 2 CONST FL_ENTER = 3 CONST FL_LEAVE = 4 CONST FL_DRAG = 5 CONST FL_FOCUS = 6 CONST FL_UNFOCUS = 7 CONST FL_KEYDOWN = 8 CONST FL_KEYBOARD = 8 CONST FL_KEYUP = 9 CONST FL_CLOSE = 10 CONST FL_MOVE = 11 CONST FL_SHORTCUT = 12 CONST FL_DEACTIVATE = 13 CONST FL_ACTIVATE = 14 CONST FL_HIDE = 15 CONST FL_SHOW = 16 CONST FL_PASTE = 17 CONST FL_SELECTIONCLEAR = 18 CONST FL_MOUSEWHEEL = 19 CONST FL_DND_ENTER = 20 CONST FL_DND_DRAG = 21 CONST FL_DND_LEAVE = 22 CONST FL_DND_RELEASE = 23 CONST FL_SCREEN_CONFIGURATION_CHANGED = 24 CONST FL_FULLSCREEN = 25
/*
DESCRIPTION OF EVENTS
FL_NO_EVENT 0. No event.
FL_PUSH 1. A mouse button has gone down with the mouse pointing at this widget. You can find out what button by calling Fl::event_button(). You find out the mouse position by calling Fl::event_x() and Fl::event_y(). A widget indicates that it "wants" the mouse click by returning non-zero from its Fl_Widget::handle() method. It will then become the Fl::pushed() widget and will get FL_DRAG and the matching FL_RELEASE events. If Fl_Widget::handle() returns zero then FLTK will try sending the FL_PUSH to another widget.
FL_RELEASE 2. A mouse button has been released. You can find out what button by calling Fl::event_button(). In order to receive the FL_RELEASE event, the widget must return non-zero when handling FL_PUSH.
FL_ENTER 3. The mouse has been moved to point at this widget. This can be used for highlighting feedback. If a widget wants to highlight or otherwise track the mouse, it indicates this by returning non-zero from its handle() method. It then becomes the Fl::belowmouse() widget and will receive FL_MOVE and FL_LEAVE events.
FL_LEAVE 4. The mouse has moved out of the widget. In order to receive the FL_LEAVE event, the widget must return non-zero when handling FL_ENTER.
FL_DRAG 5. The mouse has moved with a button held down. The current button state is in Fl::event_state(). The mouse position is in Fl::event_x() and Fl::event_y(). In order to receive FL_DRAG events, the widget must return non-zero when handling FL_PUSH.
FL_FOCUS 6. This indicates an attempt to give a widget the keyboard focus. If a widget wants the focus, it should change itself to display the fact that it has the focus, and return non-zero from its handle() method. It then becomes the Fl::focus() widget and gets FL_KEYDOWN, FL_KEYUP, and FL_UNFOCUS events. The focus will change either because the window manager changed which window gets the focus, or because the user tried to navigate using tab, arrows, or other keys. You can check Fl::event_key() to figure out why it moved. For navigation it will be the key pressed and for interaction with the window manager it will be zero.
FL_UNFOCUS 7. This event is sent to the previous Fl::focus() widget when another widget gets the focus or the window loses focus.
FL_KEYDOWN 8. A key was pressed (FL_KEYDOWN) or released (FL_KEYUP). Fl_KEYBOARD is a synonym for FL_KEYDOWN. The key can be found in Fl::event_key(). The text that the key should insert can be found with Fl::event_text() and its length is in Fl::event_length(). If you use the key handle() should return 1. If you return zero then FLTK assumes you ignored the key and will then attempt to send it to a parent widget. If none of them want it, it will change the event into a FL_SHORTCUT event. To receive FL_KEYBOARD events you must also respond to the FL_FOCUS and FL_UNFOCUS events. If you are writing a text-editing widget you may also want to call the Fl::compose() function to translate individual keystrokes into non-ASCII characters. FL_KEYUP events are sent to the widget that currently has focus. This is not necessarily the same widget that received the corresponding FL_KEYDOWN event because focus may have changed between events.
FL_KEYBOARD 8. Equivalent to FL_KEYDOWN.
FL_KEYUP 9. Key release event.
FL_CLOSE 10. The user clicked the close button of a window. This event is used internally only to trigger the callback of Fl_Window derived classed. The default callback closes the window calling Fl_Window::hide().
FL_MOVE 11. The mouse has moved without any mouse buttons held down. This event is sent to the Fl::belowmouse() widget. In order to receive FL_MOVE events, the widget must return non-zero when handling FL_ENTER.
FL_SHORTCUT 12. If the Fl::focus() widget is zero or ignores an FL_KEYBOARD event then FLTK tries sending this event to every widget it can, until one of them returns non-zero. FL_SHORTCUT is first sent to the Fl::belowmouse() widget, then its parents and siblings, and eventually to every widget in the window, trying to find an object that returns non-zero. FLTK tries really hard to not to ignore any keystrokes! You can also make "global" shortcut by using Fl::add_handler(). A global shortcut will work no matter what windows are displayed or which one has the focus.
FL_DEACTIVATE 13. This widget is no longer active, due to Fl_Widget::deactivate() being called on it or one of its parents. Fl_Widget::active() may still be true after this, the widget is only active if Fl_Widget::active() is true on it and all its parents (use Fl_Widget::active_r() to check this).
FL_ACTIVATE 14. This widget is now active, due to Fl_Widget::activate() being called on it or one of its parents.
FL_HIDE 15 This widget is no longer visible, due to Fl_Widget::hide() being called on it or one of its parents, or due to a parent window being minimized. Fl_Widget::visible() may still be true after this, but the widget is visible only if visible() is true for it and all its parents (use Fl_Widget::visible_r() to check this).
FL_SHOW 16. This widget is visible again, due to Fl_Widget::show() being called on it or one of its parents, or due to a parent window being restored. Child Fl_Windows respond to this by actually creating the window if not done already, so if you subclass a window, be sure to pass FL_SHOW to the base class Fl_Widget::handle() method!
FL_PASTE 17. You should get this event some time after you call Fl::paste(). The contents of Fl::event_text() is the text to insert and the number of characters is in Fl::event_length().
FL_SELECTIONCLEAR 18. The Fl::selection_owner() will get this event before the selection is moved to another widget. This indicates that some other widget or program has claimed the selection. Motif programs used this to clear the selection indication. Most modern programs ignore this.
FL_MOUSEWHEEL 19. The user has moved the mouse wheel. The Fl::event_dx() and Fl::event_dy() methods can be used to find the amount to scroll horizontally and vertically.
FL_DND_ENTER 20. The mouse has been moved to point at this widget. A widget that is interested in receiving drag'n'drop data must return 1 to receive FL_DND_DRAG, FL_DND_LEAVE and FL_DND_RELEASE events.
FL_DND_DRAG 21. The mouse has been moved inside a widget while dragging data. A widget that is interested in receiving drag'n'drop data should indicate the possible drop position.
FL_DND_LEAVE 22. The mouse has moved out of the widget.
FL_DND_RELEASE 23. The user has released the mouse button dropping data into the widget. If the widget returns 1, it will receive the data in the immediately following FL_PASTE event.
FL_SCREEN_CONFIGURATION_CHANGED
24. The screen configuration (number, positions) was changed. Use Fl::add_handler() to be notified of this event.
FL_FULLSCREEN 25. The fullscreen state of the window has changed.
*/
' *********************** ' END INITIALIZATION ' ***********************
' *********************** ' SUBS & FUNCTIONS ' ***********************
' ------------------ FUNCTION HANDLE_CB(long widget, int event) ' ------------------ LOCAL active_dnd TYPE int LOCAL event_txt$ TYPE STRING PRINT "Event received: ", event active_dnd = 0 event_txt$ = (char*)GET_EVENT_TEXT(win) SELECT event CASE FL_DND_ENTER PRINT "Event Enter" active_dnd = 1 PRINT event_txt$ RETURN 1 CASE FL_DND_LEAVE PRINT "EVent Leave" active_dnd = 0 PRINT event_txt$ RETURN 1 CASE FL_DND_DRAG; CASE FL_DND_RELEASE PRINT "Event Drag or Release" PRINT event_txt$ RETURN 1 CASE FL_PASTE IF active_dnd THEN PRINT "Paste" PRINT event_txt$ active_dnd = 0 RETURN 1 END IF DEFAULT IF LEN(event_txt$) > 0 THEN PRINT "Text: ", event_txt$ END IF END SELECT RETURN 0 END FUNCTION
' ------------------ SUB MK_GUI() ' ------------------ SCHEME_SET("plastic") win = WINDOW(320, 200, "BaCon FLTK Events" & NULL) SET_COLOR(win, 222) box = BOX(10, 40, 300, 90, "Try dragging a file into\nan area below this window." & NULL) CALLBACK(win, HANDLE_CB) SHOW(win) END SUB
' *********************** ' END SUBS & FUNCTIONS ' ***********************
' *********************** ' MAIN ' ***********************
MK_GUI() DISPLAY
' *********************** ' END MAIN ' ***********************
|
|
|
Post by bigbass on Nov 13, 2017 1:41:09 GMT 1
Hey vovchik
Thanks for the code and links
by trial and error I figured out an easier way to get to the signal without all the long talk of the official docs and no simple code to port
code is the best way to explain something after reading through the docs this way is simple and right to the point
PRAGMA INCLUDE <FL/Fl.H> <FL/Fl_Window.H> <FL/Fl_Button.H> <iostream> <FL/names.h> PRAGMA LDFLAGS -lfltk PRAGMA COMPILER g++ PRAGMA OPTIONS -Wno-write-strings -Wno-pointer-arith
OPTION PARSE FALSE
SUB but_a_cb(Fl_Widget* w, void* p)
IF Fl::event_button( ) == 1 THEN
printf(" The LEFT mouse button \n")
ELIF Fl::event_button( ) == 2 THEN
printf(" The MIDDLE mouse button \n")
ELIF Fl::event_button( ) == 3 THEN
printf(" The RIGHT mouse button\n")
ENDIF END SUB
DECLARE win TYPE Fl_Window* DECLARE but_a TYPE Fl_Button* DECLARE MyButton TYPE Fl_Button*
win = new Fl_Window(120,150) win->begin() but_a = new Fl_Button(10,10,100,25,"A") but_a->shortcut('a') but_a->callback(but_a_cb) win->end() win->show() Fl::run()
|
|
|
Post by vovchik on Nov 13, 2017 8:46:23 GMT 1
Dear Joe, Thanks. That was easy. And it is pretty straightforward. Here is another way of doing the same, but more like HUG: ' *********************** ' COMPILER DIRECTIVES ' ***********************
PRAGMA INCLUDE <FL/Fl_Double_Window.H> PRAGMA INCLUDE <FL/Fl_Box.H> PRAGMA INCLUDE <FL/Fl_Tooltip.H> PRAGMA INCLUDE <FL/Fl_Button.H> PRAGMA OPTIONS -Wno-deprecated PRAGMA LDFLAGS -lfltk -L. PRAGMA COMPILER g++ PRAGMA OPTIONS -Wno-write-strings -Wno-pointer-arith -fno-strict-aliasing -fpermissive OPTION PARSE FALSE
' *********************** ' END COMPILER DIRECTIVES ' ***********************
' *********************** ' INITIALIZATION ' ***********************
' FLTK aliases ALIAS Fl::scheme TO STYLE ALIAS Fl::run TO DISPLAY ALIAS Fl::visual TO VISUAL ALIAS Fl::event_button TO EVENT_BUTTON ' FLTK functions DEF FN WINDOW(t, x, y) = new Fl_Double_Window(x, y, t) DEF FN BUTTON(t, x, y) = new Fl_Button(0, 0, x, y, t) DEF FN BOX(t, x, y) = new Fl_Box(0, 0, x, y, t) DEF FN CALLBACK(arg1,arg2) = arg1->callback(arg2,NULL) DEF FN SHOW(w) = w->show() DEF FN SETPROPERTY(arg1,arg2,arg3) = arg1->arg2(arg3) DEF FN TEXT(w,x) = w->copy_label(x) DEF FN ATTACH(w, x, y) = w->position(x, y) DEF FN SETFONT(x, y) = Fl::set_font(x, y) DEF FN INITFONTS() = Fl::set_fonts("*") ' widget declarations DECLARE win TYPE Fl_Double_Window* DECLARE but_a TYPE Fl_Button* DECLARE msg TYPE Fl_Box*
' *********************** ' END INITIALIZATION ' ***********************
' *********************** ' SUBS & FUNCTIONS ' ***********************
' ----------------- SUB BUT_A_CB(Fl_Widget* w, void* p) ' ----------------- LOCAL but TYPE int but = EVENT_BUTTON() SELECT but CASE 1 PRINT "Left mouse button pressed." TEXT(msg, "Mouse left") CASE 2 PRINT "Middle mouse button pressed." TEXT(msg, "Mouse middle") CASE 3 PRINT "Right mouse button pressed." TEXT(msg, "Mouse right") CASE -65159 PRINT "Shortcut key pressed." TEXT(msg, "Shortcut") END SELECT END SUB
' ----------------- SUB MK_GUI() ' ----------------- ' global FLTK settings VISUAL(FL_RGB8) STYLE("plastic") ' fonts INITFONTS() SETFONT(FL_HELVETICA, "DejaVu Sans") ' window win = WINDOW("Events", 120, 150) ' button but_a = BUTTON("A", 100, 25) ATTACH(but_a, 10, 10) SETPROPERTY(but_a, shortcut, 'a') SETPROPERTY(but_a, tooltip, \ "Click any mouse key or\npress shortcut key ('a')") CALLBACK(but_a, BUT_A_CB) ' message box msg = BOX("", 100, 25) TEXT(msg, "Event") SETPROPERTY(msg, box, FL_RSHADOW_BOX) SETPROPERTY(msg, tooltip, \ "Display event.") SETPROPERTY(msg, color, FL_RED) SETPROPERTY(msg, labelcolor, FL_WHITE) SETPROPERTY(msg, labelfont, FL_BOLD) SETPROPERTY(msg, labelsize, 11) SETPROPERTY(msg, align, \ FL_ALIGN_CENTER|FL_ALIGN_CLIP|FL_ALIGN_INSIDE) ATTACH(msg, 10, 60) ' display main window SHOW(win) END SUB
' *********************** ' END SUBS & FUNCTIONS ' ***********************
' *********************** ' MAIN ' ***********************
MK_GUI() DISPLAY()
' *********************** ' END MAIN ' *********************** With kind regards, vovchik
|
|
|
Post by bigbass on Nov 13, 2017 16:21:05 GMT 1
Hey vovchik
Thanks I like the way you did it and that you have a lot of time with fltk the blending of bringing c++ source code to bacon and make it work and look like what we are used to for this a big thanks
I however am still getting my feet wet actually testing in c++ first removing namespaces and trying to bridge the gap to simplify the source code to make it easier to port later
we do need a lot of small and complete demos there are some things in c++ that are difficult to port into bacon directly without having a bit of creativity
Joe
|
|
|
Post by vovchik on Nov 13, 2017 19:47:54 GMT 1
Dear Joe, I am getting my feet wet, too. I improved that little demo by adding a message box that shows mouse coordinates in the button box. With kind regards, vovchik ' *********************** ' COMPILER DIRECTIVES ' ***********************
PRAGMA INCLUDE <FL/Fl.H> PRAGMA INCLUDE <FL/x.H> PRAGMA INCLUDE <FL/Fl_Double_Window.H> PRAGMA INCLUDE <FL/Fl_Box.H> PRAGMA INCLUDE <FL/Fl_Tooltip.H> PRAGMA INCLUDE <FL/Fl_Button.H> PRAGMA OPTIONS -Wno-deprecated PRAGMA LDFLAGS -lfltk -L. PRAGMA COMPILER g++ PRAGMA OPTIONS -Wno-write-strings -Wno-pointer-arith -fno-strict-aliasing -fpermissive OPTION PARSE FALSE
' *********************** ' END COMPILER DIRECTIVES ' ***********************
' *********************** ' INITIALIZATION ' ***********************
' FLTK aliases ALIAS Fl::scheme TO STYLE ALIAS Fl::run TO DISPLAY ALIAS Fl::visual TO VISUAL ALIAS Fl::event_button TO EVENT_BUTTON ' FLTK functions DEF FN WINDOW(t, x, y) = new Fl_Double_Window(x, y, t) DEF FN BUTTON(t, x, y) = new Fl_Button(0, 0, x, y, t) DEF FN BOX(t, x, y) = new Fl_Box(0, 0, x, y, t) DEF FN CALLBACK(arg1,arg2) = arg1->callback(arg2,NULL) DEF FN SHOW(w) = w->show() DEF FN SETPROPERTY(arg1,arg2,arg3) = arg1->arg2(arg3) DEF FN TEXT(w,x) = w->copy_label(x) DEF FN ATTACH(w, x, y) = w->position(x, y) DEF FN GET(arg1,arg2) = arg1->arg2() DEF FN SETFONT(x, y) = Fl::set_font(x, y) DEF FN INITFONTS() = Fl::set_fonts("*") ' widget declarations DECLARE win TYPE Fl_Double_Window* DECLARE but_a TYPE Fl_Button* DECLARE msg, mouse TYPE Fl_Box*
' *********************** ' END INITIALIZATION ' ***********************
' *********************** ' SUBS & FUNCTIONS ' ***********************
' ----------------- FUNCTION MOUSE(int mode) TYPE int ' ----------------- LOCAL e, x, y TYPE int e = Fl::event() x = Fl::event_x_root() y = Fl::event_y_root() SELECT mode CASE 0 RETURN x CASE 1 RETURN y END SELECT END FUNCTION
' ----------------- SUB BUT_A_CB(Fl_Widget* wid, void* p) ' ----------------- LOCAL but, x, y TYPE int but = EVENT_BUTTON() x = MOUSE(0) - GET(win, x) - GET(wid, x) y = MOUSE(1) - GET(win, y) - GET(wid, y) SELECT but CASE 1 PRINT "Left mouse button pressed." TEXT(msg, "Mouse left") CASE 2 PRINT "Middle mouse button pressed." TEXT(msg, "Mouse middle") CASE 3 PRINT "Right mouse button pressed." TEXT(msg, "Mouse right") CASE -65159 PRINT "Shortcut key pressed." TEXT(msg, "Shortcut") END SELECT PRINT "Mouse at ", x, ":", y TEXT(mouse, STR$(x) & ":" & STR$(y)) END SUB
' ----------------- SUB MK_GUI() ' ----------------- ' global FLTK settings VISUAL(FL_RGB8) STYLE("plastic") ' fonts INITFONTS() SETFONT(FL_HELVETICA, "DejaVu Sans") ' window win = WINDOW("Events", 120, 150) ' button but_a = BUTTON("Click me", 100, 60) ATTACH(but_a, 10, 10) SETPROPERTY(but_a, shortcut, 'a') SETPROPERTY(but_a, tooltip, \ "Click any mouse key or\npress shortcut key ('a')") CALLBACK(but_a, BUT_A_CB) ' message box msg = BOX("", 100, 25) TEXT(msg, "Event") SETPROPERTY(msg, box, FL_RSHADOW_BOX) SETPROPERTY(msg, tooltip, \ "Display event.") SETPROPERTY(msg, color, FL_RED) SETPROPERTY(msg, labelcolor, FL_WHITE) SETPROPERTY(msg, labelfont, FL_BOLD) SETPROPERTY(msg, labelsize, 11) SETPROPERTY(msg, align, \ FL_ALIGN_CENTER|FL_ALIGN_CLIP|FL_ALIGN_INSIDE) ATTACH(msg, 10, 80) mouse = BOX("", 100, 25) TEXT(mouse, "Mouse") SETPROPERTY(mouse, box, FL_RSHADOW_BOX) SETPROPERTY(mouse, tooltip, \ "Display event.") SETPROPERTY(mouse, color, FL_GRAY) SETPROPERTY(mouse, labelcolor, FL_BLACK) SETPROPERTY(mouse, labelfont, FL_BOLD) SETPROPERTY(mouse, labelsize, 11) SETPROPERTY(mouse, align, \ FL_ALIGN_CENTER|FL_ALIGN_CLIP|FL_ALIGN_INSIDE) ATTACH(mouse, 10, 115) SHOW(win) END SUB
' *********************** ' END SUBS & FUNCTIONS ' ***********************
' *********************** ' MAIN ' ***********************
MK_GUI() DISPLAY()
' *********************** ' END MAIN ' ***********************
|
|
|
Post by bigbass on Nov 14, 2017 15:59:27 GMT 1
Hey vovchik I like how this event widget has improved in steps so that it will be much easier to grasp all the changes from source code to final product (hand crafted code) and thats where you can see the creativity come in I really like how we will be able to take c++ code and port it to bacon and remove the "::uglification::" Joe a good link to look up whats going on behind the scenes www.fltk.org/doc-2.0/html/namespacefltk.html
|
|
|
Post by bigbass on Nov 19, 2017 0:27:59 GMT 1
Hey vovchik
porting code with namespace and classes is undocumented but I found a way to do it to get at the low level events a lot of testing to find out how we can get it to compile in bacon t
bacon understands structs but it doesnt understand class private/public so I used struct look at the bacon part it can see the class MyButton at the bottom using struct MyButton
Now we can see the key press name and any other events such as PUSH ,RELEASE,MOUSEWHEEL ect...
PRAGMA INCLUDE <FL/Fl.H> <FL/Fl_Window.H> <FL/Fl_Button.H> <FL/names.h> <iostream> PRAGMA LDFLAGS -lfltk PRAGMA COMPILER g++ PRAGMA OPTIONS -Wno-write-strings -Wno-pointer-arith
OPTION PARSE FALSE
SUB but_a_cb(Fl_Widget* w, void* p)
IF Fl::event_button( ) == 1 THEN
printf(" The LEFT mouse button \n")
ELIF Fl::event_button( ) == 2 THEN
printf(" The MIDDLE mouse button \n")
ELIF Fl::event_button( ) == 3 THEN
printf(" The RIGHT mouse button\n")
ENDIF END SUB
USEH #define USECPLUS extern "C" { #define ENDCPLUS }
USECPLUS
struct MyButton : Fl_Button {
MyButton(int x,int y,int w,int h,const char*l=0) :Fl_Button(x,y,w,h,l) {}
int handle(int e) { int ret = Fl_Button::handle(e); switch(e) { case FL_PUSH: std::cout<<" push\n"<<" event and returns: \n"<<ret; break; case FL_RELEASE: std:: cout<<" release"<<" event and returns: \n"<<ret; break; case FL_KEYDOWN: std::cout<< Fl::event_text() << " key pressed \n "; break;
case FL_MOUSEWHEEL: std::cout<<"mousewheel"<<" event and returns: \n"<<ret; break; } return(ret); } };
ENDCPLUS END USEH
DECLARE win TYPE Fl_Window* DECLARE MyButton TYPE Fl_Button*
win = new Fl_Window(120,150) win->begin() struct MyButton but_a(10,10,100,25,"A") but_a.callback(but_a_cb) win->end() win->show() Fl::run()
here is the original c++ source code I ported modified and added to -- see what got changed
#include <FL/Fl.H> #include <FL/Fl_Window.H> #include <FL/Fl_Button.H> #include <iostream> #include <FL/names.h>
using namespace std;
class MyButton : public Fl_Button { static int count; public: MyButton(int x,int y,int w,int h,const char*l=0) :Fl_Button(x,y,w,h,l) {} int handle(int e) { int ret = Fl_Button::handle(e); cout<<endl<<count++<<" ******** button "<<label()<<" receives "; switch(e) { case FL_PUSH: cout<<"push"<<" event and returns:"<<ret<<endl; break; case FL_RELEASE: cout<<"release"<<" event and returns:"<<ret<<endl; break; case FL_ENTER: color(FL_CYAN); cout<<"enter"<<" event and returns:"<<ret<<endl; redraw(); break; case FL_LEAVE: color(FL_BACKGROUND_COLOR); cout<<"leave"<<" event and returns:"<<ret<<endl; redraw(); break; case FL_DRAG: cout<<"drag"<<" event and returns:"<<ret<<endl; break; case FL_FOCUS: cout<<"focus"<<" event and returns:"<<ret<<endl; break; case FL_UNFOCUS: cout<<"unfocus"<<" event and returns:"<<ret<<endl; break; case FL_KEYDOWN: cout<<"keydown"<<" event and returns:"<<ret<<endl; break;
case FL_KEYUP: if ( Fl::event_key() == shortcut() ){ box(FL_UP_BOX); redraw(); ret=1; //return handled so keyup event stops } //being sent to ALL other buttons unecessarily cout<<"keyup"<<" event and returns:"<<ret<<endl; break; case FL_CLOSE: cout<<"close"<<" event and returns:"<<ret<<endl; break; case FL_MOVE: cout<<"move"<<" event and returns:"<<ret<<endl; break; case FL_SHORTCUT: if ( Fl::event_key() == shortcut() ){ box(FL_DOWN_BOX); redraw(); } cout<<"shortcut"<<" event and returns:"<<ret<<endl; break; case FL_DEACTIVATE: cout<<"deactivate"<<" event and returns:"<<ret<<endl; break; case FL_ACTIVATE: cout<<"activate"<<" event and returns:"<<ret<<endl; break; case FL_HIDE: cout<<"hide"<<" event and returns:"<<ret<<endl; break; case FL_SHOW: cout<<"show"<<" event and returns:"<<ret<<endl; break; case FL_PASTE: cout<<"paste"<<" event and returns:"<<ret<<endl; break; case FL_SELECTIONCLEAR: cout<<"selectionclear"<<" event and returns:"<<ret<<endl; break; case FL_MOUSEWHEEL: cout<<"mousewheel"<<" event and returns:"<<ret<<endl; break; case FL_NO_EVENT: cout<<"no event"<<" and returns:"<<ret<<endl; break; } return(ret); } };
int MyButton::count=0;
void but_a_cb(Fl_Widget* w, void* v){ cout <<endl<< "Button A callback!"<<endl; }
void but_b_cb(Fl_Widget* w, void* v){ cout <<endl<< "Button B callback!"<<endl; }
void but_c_cb(Fl_Widget* w, void* v){ cout <<endl<< "Button C callback!"<<endl; }
int main() { Fl_Window win(120,150); win.begin();
MyButton but_a(10,10,100,25,"A"); but_a.shortcut('a'); but_a.callback(but_a_cb);
MyButton but_b(10,50,100,25,"B"); but_b.shortcut('b'); but_b.callback(but_b_cb);
MyButton but_c(10,90,100,25,"C"); but_c.shortcut('c'); but_c.callback(but_c_cb);
win.end(); win.show(); return(Fl::run()); }
|
|
|
Post by vovchik on Nov 19, 2017 0:58:32 GMT 1
Dear Joe, Excellent work, and I see where you are headed. The only thing really missing is "special keys", but they are in the fltk EVENT enum and have to be caught in the switch bit. I did something with events before but can't find the code. This could be made into a very useful "include". Thanks. With kind regards, vovchik
|
|
|
Post by bigbass on Nov 19, 2017 5:23:40 GMT 1
Hey vovchik www.fltk.org/doc-1.3/Enumerations_8H_source.htmlwe just add <FL/Enumerations.H> then case FL_KEYDOWN: std::cout<< Fl::event_text() << " key pressed \n "; std::cout<< Fl::event_key() << " special key pressed \n "; if (Fl::event_key() == FL_BackSpace) printf("FL_BackSpace \n"); if (Fl::event_key() == FL_Shift_L) printf("FL_Shift_L \n"); break; case FL_MOUSEWHEEL: std::cout<< "mousewheel"<<" event and returns: \n"<<ret; std::cout<< Fl::event_dx(); std::cout<< Fl::event_dy(); break; this will work for all the special keys this shows just FL_BackSpace,FL_Shift_L but from here we can get any event Joe
|
|
|
Post by vovchik on Nov 19, 2017 10:20:13 GMT 1
Dear Joe, And, if we add <FL/Enumerations.H> to the includes and insert this just before the switch statement, we get all sorts of useful event info easily: printf("Event was %s (%d)\n", fl_eventnames[e], e); With kind regards, vovchik
|
|
|
Post by bigbass on Nov 19, 2017 21:30:11 GMT 1
Hey vovchik if you download the fltk source code in the folder test there is this keyboard if you modify the make file so it doesnt delete the keyboard headers you can edit the code and run make again #include <stdio.h> #include <FL/Fl.H> #include <FL/Fl_Window.H> #include <FL/Fl_Button.H> #include <FL/names.h> #include <FL/Enumerations.H> #include <iostream> keyboard.cxx I just added the cout part and the headers above to get the info into the terminal this could be fun to port later // this is used to stop Esc from exiting the program: int handle(int e) { std::cout<< Fl::event_text() << " key pressed \n "; return (e == FL_SHORTCUT); // eat all keystrokes } Joe
|
|
|
Post by bigbass on Nov 19, 2017 21:35:13 GMT 1
keyboard-code.tar.gz (5.88 KB) here are the files in case they get deleted running make I havent tried this outside the sources yet but testing first in c++ and we could edit also in fluid the fluid part I have no idea how to port to bacon yet Joe
|
|
|
Post by bigbass on Nov 20, 2017 4:42:59 GMT 1
Hey vovchik I should have started with an easier demo but I couldn't help myself it was perfect for testing all the events to see all what is going on so here is the easiest demo for fluid I could find I see now how to edit or build another make file and how fluid is compiling the files this seems like a nice way to generate some widgets simpleFluid.tar.gz (2.93 KB) I am posting just as a reference because later I want to get the keyboard code and app all together standalone Joe
|
|
|
Post by vovchik on Nov 20, 2017 16:16:16 GMT 1
Dear Joe, It is interesting how that "o" type is changed within the outer {}, in order to get child widgets within a parent widget. Have to think about that...unless you already have. With kind regards, vovchik
|
|