|
Post by bigbass on Nov 26, 2017 17:24:53 GMT 1
Hey vovchik
Great news!
Next as you suggested before we need to remove USEC but to do this we will have to reinvent some c++ code syntax for bacon use like what was done with PROTO struct
or we may be able to make our own events handler without the c++ way of doing class we both have got at the events in a more direct approach we just need to see if there is a simple way of doing it and keep trying
Joe
|
|
|
Post by bigbass on Nov 26, 2017 21:31:43 GMT 1
Hey vovchik
I was trying to understand your excellent shortcut way of reducing /baconizing the syntax to follow what it would look like if it were in HUG
and even from inside the USEC the DEF FN work!
so if we have to make an include file to simplify the syntax its no big deal I recycled your DEF FN here not as a widget demo but as a test bed to see what could be done
we need only to rework the CALLBACK DEF FN thats where where the problem is but I got around it another way to show that it will work once the DEF FN is adjusted
enough talking here's the code it explains better
Joe
PRAGMA INCLUDE <FL/x.H> PRAGMA INCLUDE <FL/names.h> PRAGMA INCLUDE <FL/Fl.H> PRAGMA INCLUDE <FL/Fl_Double_Window.H> PRAGMA INCLUDE <FL/Fl_Button.H> PRAGMA INCLUDE <FL/Fl_Dial.H> PRAGMA INCLUDE <FL/Fl_Box.H> PRAGMA INCLUDE <FL/Fl_Widget.H> PRAGMA INCLUDE <iostream> PRAGMA LDFLAGS -lfltk -lfltk_images -L. PRAGMA COMPILER g++ PRAGMA OPTIONS -Wno-write-strings -Wno-pointer-arith OPTION PARSE FALSE
ALIAS Fl::get_mouse TO GET_MOUSE ALIAS Fl::run TO DISPLAY DEF FN GET(arg1,arg2) = arg1->arg2() DECLARE roller_y TYPE Fl_Dial* DEF FN SETPROPERTY(arg1,arg2,arg3) = arg1->arg2(arg3) DEF FN DIAL(t, x, y) = new Fl_Dial(0, 0, x, y, t) DEF FN SHOW(w) = w->show() DEF FN ATTACH(w, x, y) = w->position(x, y) DEF FN CALLBACK(arg1,arg2) = arg1->callback(arg2,NULL) DEF FN WINDOW(t, x, y) = new Fl_Double_Window(x, y, t)
' ------------------ SUB WHEEL_CB(Fl_Widget* widget, void* but) ' ------------------ PRINT "Wheel: ", GET(roller_y, value) END SUB
USEH #define USECPLUS extern "C" { #define ENDCPLUS }
USECPLUS
// scroll wheel code struct MyDial : Fl_Dial { MyDial(int x,int y,int w,int h,const char*l=0) :Fl_Dial(x,y,w,h,l) {} int handle(int e) { int ret = Fl_Dial::handle(e); switch(e) {
case FL_MOUSEWHEEL: std::cout<<" mousewheel: \n"<<ret; Fl_Dial *roller_y;
{ Fl::flush(); roller_y->value( roller_y->value() + Fl::e_dy * roller_y->step() ); std::cout<< GET(roller_y, value); return 1; } return 0;
break;
} return(ret); } };
ENDCPLUS END USEH
DECLARE win TYPE Fl_Window* 'DECLARE roller_y TYPE Fl_Dial*
win = new Fl_Window(120,150) win->begin()
roller_y = new MyDial(30, 50, 50, 45, "mouse scroll") SETPROPERTY(roller_y, box, FL_ROUND_UP_BOX) SETPROPERTY(roller_y, selection_color, FL_BACKGROUND_COLOR) SETPROPERTY(roller_y, labelsize, 9) SETPROPERTY(roller_y, step, 0.1) roller_y->callback((Fl_Callback*)WHEEL_CB) SETPROPERTY(roller_y, align, FL_ALIGN_TOP_LEFT)
win->end() SHOW(win) DISPLAY
|
|
|
Post by bigbass on Nov 26, 2017 22:44:33 GMT 1
I got the syntax for the roller DEF FN callback working
its a special callback because it mirrors the movement of the wheel visually the rest will fall nicely in place as we go
DEF FN ROLLERCALLBACK(arg1,arg2) = arg1->callback((Fl_Callback*)arg2) ROLLERCALLBACK(roller_y ,WHEEL_CB)
|
|
|
Post by vovchik on Nov 26, 2017 23:48:21 GMT 1
Dear Joe, Yes, very close to nailing it. I still get a segfault, but I get "mousewheel" printing out before it crashes, and flush is there, as in the c++ code, so I am at a loss to explain it. But at least the type was recognized and we are in the callback. With kind regards, vovchik
|
|
|
Post by bigbass on Nov 27, 2017 15:58:48 GMT 1
Hey vovchik I think we should start clean without c++ classes I did it in fluid from the example code its an all included cxx // generated by Fast Light User Interface Designer (fluid) version 1.0304
#include <FL/Fl.H> #include <FL/Fl_Double_Window.H> #include <stdio.h> #include <FL/Fl_Box.H> #include <FL/Fl_Dial.H> #include <FL/Fl_Roller.H> #include <FL/Fl_Double_Window.H>
// in set build commands : compile command geany //g++ -Wall -c "%f" -lfltk -lXext -lX11 -lm
// build command for geany //g++ -Wall -o "%e" "%f" -lfltk -lXext -lX11 -lm
static void callback(Fl_Widget* o, void*) { printf("%g \r", ((Fl_Valuator*)o)->value()); printf("in callback "); fflush(stdout); }
int main(int argc, char **argv) { Fl_Double_Window* w; { Fl_Double_Window* o = new Fl_Double_Window(295, 135, "Valuator no classes, showing values "); w = o; o->color((Fl_Color)FL_WHITE); o->selection_color((Fl_Color)43); { Fl_Box* o = new Fl_Box(5, 10, 270, 105, "Fl_Dial"); o->box(FL_ENGRAVED_BOX); o->labelfont(1); o->align(Fl_Align(FL_ALIGN_TOP|FL_ALIGN_INSIDE)); } // Fl_Box* o { Fl_Dial* o = new Fl_Dial(25, 35, 65, 65, "0"); o->tooltip("Standard Dial"); o->color((Fl_Color)FL_YELLOW); o->selection_color((Fl_Color)FL_BLUE); o->labelsize(8); o->value(1.0); o->callback((Fl_Callback*)callback); o->angles(0,315); } // Fl_Dial* o { Fl_Dial* o = new Fl_Dial(105, 35, 65, 65, "FL_LINE_DIAL"); o->tooltip("Line Dial"); o->type(1); o->color((Fl_Color)FL_YELLOW); o->selection_color((Fl_Color)1); o->labelsize(8); o->value(0.5); o->callback((Fl_Callback*)callback); } // Fl_Dial* o { Fl_Dial* o = new Fl_Dial(190, 35, 65, 65, "FL_FILL_DIAL"); o->tooltip("Fill Dial"); o->type(2); o->color((Fl_Color)FL_BLUE); o->selection_color((Fl_Color)FL_YELLOW); o->labelsize(8); o->value(1); o->callback((Fl_Callback*)callback); o->angles(0,360); } // Fl_Dial* o o->end(); } // Fl_Double_Window* o w->show(argc, argv); return Fl::run(); }
|
|
|
Post by bigbass on Nov 27, 2017 16:51:02 GMT 1
Hey vovchik super easy to port to bacon just a few minutes now we can see whats going on better with less code oh and I forgot no USEC and printf and fflush work porting fluid generated GUI's in this way will be easy PRAGMA INCLUDE <FL/x.H> PRAGMA INCLUDE <FL/names.h> PRAGMA INCLUDE <FL/Fl.H> PRAGMA INCLUDE <FL/Fl_Double_Window.H> PRAGMA INCLUDE <FL/Fl_Button.H> PRAGMA INCLUDE <FL/Fl_Dial.H> PRAGMA INCLUDE <FL/Fl_Box.H> PRAGMA INCLUDE <FL/Fl_Widget.H> PRAGMA INCLUDE <FL/Fl_Roller.H> PRAGMA INCLUDE <stdio.h> PRAGMA INCLUDE <iostream> PRAGMA LDFLAGS -lfltk -lfltk_images -L. PRAGMA COMPILER g++ PRAGMA OPTIONS -Wno-write-strings -Wno-pointer-arith OPTION PARSE FALSE
SUB callback(Fl_Widget* o, void*)
printf("%g \r", ((Fl_Valuator*)o)->value()) printf("in callback ") fflush(stdout) END SUB
DECLARE win TYPE Fl_Double_Window* DECLARE BOX TYPE Fl_Box* DECLARE DIAL TYPE Fl_Dial*
win = new Fl_Double_Window(295, 135, "Valuator no classes, showing values ") win->color((Fl_Color)FL_WHITE) win->selection_color((Fl_Color)43) BOX = new Fl_Box(5, 10, 270, 105, "Fl_Dial") BOX->box(FL_ENGRAVED_BOX) BOX->labelfont(1) BOX->align(Fl_Align(FL_ALIGN_TOP|FL_ALIGN_INSIDE)) DIAL = new Fl_Dial(25, 35, 65, 65, "0") DIAL->tooltip("Standard Dial") DIAL->color((Fl_Color)FL_YELLOW) DIAL->selection_color((Fl_Color)FL_BLUE) DIAL->labelsize(8) DIAL->value(1.0) DIAL->callback((Fl_Callback*)callback) DIAL->angles(0,315) DIAL = new Fl_Dial(105, 35, 65, 65, "FL_LINE_DIAL") DIAL->tooltip("Line Dial") DIAL->type(1) DIAL->color((Fl_Color)FL_YELLOW) DIAL->selection_color((Fl_Color)1) DIAL->labelsize(8) DIAL->value(0.5) DIAL->callback((Fl_Callback*)callback) DIAL = new Fl_Dial(190, 35, 65, 65, "FL_FILL_DIAL") DIAL->tooltip("Fill Dial") DIAL->type(2) DIAL->color((Fl_Color)FL_BLUE) DIAL->selection_color((Fl_Color)FL_YELLOW) DIAL->labelsize(8) DIAL->value(1) DIAL->callback((Fl_Callback*)callback) DIAL->angles(0,360) win->end() win->show(argc, argv) Fl::run()
|
|
|
Post by bigbass on Nov 27, 2017 18:28:23 GMT 1
Lets give it a better look The color reverts without updating will fix it but it still looks better PRAGMA INCLUDE <FL/x.H> PRAGMA INCLUDE <FL/names.h> PRAGMA INCLUDE <FL/Fl.H> PRAGMA INCLUDE <FL/Fl_Double_Window.H> PRAGMA INCLUDE <FL/Fl_Button.H> PRAGMA INCLUDE <FL/Fl_Dial.H> PRAGMA INCLUDE <FL/Fl_Box.H> PRAGMA INCLUDE <FL/Fl_Widget.H> PRAGMA INCLUDE <FL/Fl_Roller.H> PRAGMA INCLUDE <stdio.h> PRAGMA INCLUDE <iostream> PRAGMA LDFLAGS -lfltk -lfltk_images -L. PRAGMA COMPILER g++ PRAGMA OPTIONS -Wno-write-strings -Wno-pointer-arith OPTION PARSE FALSE
SUB callback(Fl_Widget* o, void*)
printf("%g \r", ((Fl_Valuator*)o)->value()) printf("in callback ") fflush(stdout) Fl::flush() END SUB
DECLARE WIN TYPE Fl_Double_Window* DECLARE BOX TYPE Fl_Box* DECLARE DIAL TYPE Fl_Dial*
WIN = new Fl_Double_Window(305, 130, "Valuator no classes, showing values ") WIN->box(FL_GLEAM_UP_BOX) WIN->color((Fl_Color)43) WIN->selection_color((Fl_Color)43) BOX = new Fl_Box(15, 10, 270, 105, "Fl_Dial") BOX->box(FL_GLEAM_ROUND_UP_BOX) BOX->labelfont(1) BOX->align(Fl_Align(FL_ALIGN_TOP|FL_ALIGN_INSIDE)) DIAL = new Fl_Dial(30, 30, 65, 65, "0") DIAL->tooltip("Standard Dial") DIAL->box(FL_PLASTIC_ROUND_UP_BOX) DIAL->color((Fl_Color)236) DIAL->selection_color(FL_FOREGROUND_COLOR) DIAL->labelsize(8) DIAL->value(0.5) DIAL->callback((Fl_Callback*)callback) DIAL->angles(0,315) DIAL = new Fl_Dial(106, 30, 65, 65, "FL_LINE_DIAL") DIAL->tooltip("Line Dial") DIAL->type(1) DIAL->box(FL_PLASTIC_ROUND_UP_BOX) DIAL->color((Fl_Color)236) DIAL->selection_color(FL_FOREGROUND_COLOR) DIAL->labelsize(8) DIAL->value(0.5) DIAL->callback((Fl_Callback*)callback) DIAL = new Fl_Dial(185, 30, 65, 65, "FL_FILL_DIAL") DIAL->tooltip("Fill Dial") DIAL->type(2) DIAL->box(FL_PLASTIC_ROUND_UP_BOX) DIAL->color((Fl_Color)245) DIAL->selection_color(FL_DARK2) DIAL->labelsize(8) DIAL->value(1) DIAL->callback((Fl_Callback*)callback) DIAL->angles(0,360) WIN->end() WIN->show(argc, argv) Fl::run()
|
|
|
Post by bigbass on Dec 21, 2017 1:20:14 GMT 1
Hey Guys For a long time I wanted a tree demo for bacon and finally we got one with fltk ok cleaned up the callback. Check terminal for output P.S Peter The SIZEOF doesn't get syntax highlighting in bacongui
PRAGMA INCLUDE <FL/Fl.H> PRAGMA INCLUDE <FL/names.h> PRAGMA INCLUDE <FL/Fl_Double_Window.H> PRAGMA INCLUDE <FL/Fl_Tree.H> PRAGMA INCLUDE <stdio.h> PRAGMA LDFLAGS -lfltk -lfltk_images -L. PRAGMA COMPILER g++ PRAGMA OPTIONS -Wno-write-strings -Wno-pointer-arith OPTION PARSE FALSE
DECLARE item TYPE Fl_Tree_Item* DECLARE win TYPE Fl_Double_Window* DECLARE tree TYPE Fl_Tree*
SUB TreeCallback(Fl_Widget *w , void* data)
LOCAL pathname[256] TYPE char item = tree->callback_item() tree->item_pathname(pathname, SIZEOF(pathname), item) ITEM$ = (char*)item->label() PNAME$ = (char*) pathname PRINT "TreeCallback: Item selected= ",ITEM$, " Full pathname= ", PNAME$ END SUB
Fl::scheme("gleam") win = new Fl_Double_Window(250, 400, "Simple Tree") win->begin()
'--- Create the tree tree = new Fl_Tree(10, 10, win->w()-20, win->h()-20) '--- don't show root of tree tree->showroot(0) '--- setup a callback for the tree tree->callback(TreeCallback)
'--- Add some items tree->add("Flintstones/Fred") tree->add("Flintstones/Wilma") tree->add("Flintstones/Pebbles") tree->add("Simpsons/Homer") tree->add("Simpsons/Marge") tree->add("Simpsons/Bart") tree->add("Simpsons/Lisa") '--- front slashes tree->add("Pathnames/\\/bin") tree->add("Pathnames/\\/usr\\/sbin") '--- backslashes tree->add("Pathnames/C:\\\\Program Files") tree->add("Pathnames/C:\\\\Documents and Settings")
'---Start with some items closed tree->close("Simpsons") tree->close("Pathnames")
win->end() win->resizable(win) win->show(argc, argv) Fl::run()
|
|
|
Post by vovchik on Dec 21, 2017 9:11:26 GMT 1
Dear Joe, Thanks. Nice and simple coding, and it works. It's a very good example. I added a few bells and whistles below. With kind regards, vovchik PRAGMA INCLUDE <FL/Fl.H> PRAGMA INCLUDE <FL/names.h> PRAGMA INCLUDE <FL/Fl_Double_Window.H> PRAGMA INCLUDE <FL/Fl_Tree.H> PRAGMA INCLUDE <stdio.h> PRAGMA LDFLAGS -lfltk -lfltk_images -L. PRAGMA COMPILER g++ PRAGMA OPTIONS -Wno-write-strings -Wno-pointer-arith OPTION PARSE FALSE
DECLARE item TYPE Fl_Tree_Item* DECLARE win TYPE Fl_Double_Window* DECLARE tree TYPE Fl_Tree* DECLARE myfiles$ TYPE STRING LOCAL i$ TYPE STRING myfiles$ = EXEC$("find -L $PWD -name \\*.* -print") ' myfiles$ = EXEC$("ls -1rtR -d -1 $PWD/*")
' ------------------ SUB TreeCallback(Fl_Widget *w , void* data) ' ------------------ LOCAL pathname[256] TYPE char LOCAL ITEM$, PNAME$ TYPE STRING item = tree->callback_item() tree->item_pathname(pathname, SIZEOF(pathname), item) ITEM$ = (char*)item->label() PNAME$ = (char*) pathname PRINT "TreeCallback:", NL$, "Item selected = ", ITEM$, NL$, "Full pathname = /", PNAME$ END SUB
Fl::scheme("gleam")
win = new Fl_Double_Window(450, 500, "Simple Tree") win->resizable(win) win->color(FL_DARK_RED) win->box(FL_GLEAM_UP_BOX) win->begin()
'--- Create the tree tree = new Fl_Tree(10, 10, win->w()-20, win->h()-20) '--- don't show root of tree tree->showroot(0) ' bg color tree->color(DEC("FFFFF500")) ' text size tree->item_labelsize(15) ' font tree->item_labelfont(FL_BOLD) ' color of text tree->item_labelfgcolor(FL_DARK_RED) ' selection color = dark red tree->selection_color(FL_DARK_RED)
'--- setup a callback for the tree tree->callback(TreeCallback)
'--- Add some items tree->add("Flintstones/Fred") tree->add("Flintstones/Wilma") tree->add("Flintstones/Pebbles") tree->add("Simpsons/Homer") tree->add("Simpsons/Marge") tree->add("Simpsons/Bart") tree->add("Simpsons/Lisa")
' chaange color of subsequent items tree->item_labelfgcolor(FL_BLUE) FOR i$ IN myfiles$ STEP NL$ tree->add(i$) NEXT i$ ' color of text tree->item_labelfgcolor(FL_DARK_RED) tree->add("Mozart/Leopold") tree->add("Mozart/Leopold/Wolfgang Amadeus") tree->add("Mozart/Leopold/Wolfgang Amadeus/Franz Xaver") tree->add("Mozart/Leopold/Nannerl")
'---Start with some items closed 'tree->close("Simpsons") tree->close("home") tree->close("Mozart")
win->end()
win->show(argc, argv) Fl::run()
|
|
|
Post by bigbass on Dec 24, 2017 0:10:02 GMT 1
Hey vovchik I don't know how you air brushed the the box border but I really like the artistic touch you gave it all looks much better and runs fine I'll get the simple classic widgets going then send them off to the vovchik custom widget shop for a hotrod with custom air brushed paint and upholstery and audio Joe
|
|
|
Post by Pjot on Dec 25, 2017 20:18:56 GMT 1
P.S Peter The SIZEOF doesn't get syntax highlighting in bacongui Hi bigbass, For me it works in both GUI's (see screenshots). Can you show in which code this is happening? Do you have a screenshot? Thanks, Peter Attachments:
|
|
|
Post by bigbass on Dec 25, 2017 20:43:21 GMT 1
Hello Peter After looking again and enlarging the text I now see what happened I have a And I confused the color with the comment color I have really bad with light colors when there isn't a big contrast (same problem I have matching my socks) I am sorry problem it is my poor color perception all is ok with the syntax highlighting Joe
|
|
|
Post by bigbass on Dec 31, 2017 23:03:20 GMT 1
Hey Guys
Got all the events going with a simple demo
If doing a game with images as buttons this may come in handy
mouse ,keys ,wheel ,drag ,enter,all other events
Joe
PRAGMA INCLUDE <FL/Fl.H> <FL/Fl_Window.H> <FL/Fl_Button.H> <FL/names.h> <FL/Enumerations.H> <iostream> PRAGMA LDFLAGS -lfltk -lfltk_images -L. 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 w->color(FL_RED) w->label("LEFT BUT") PRINT " The LEFT mouse button "
ELIF Fl::event_button( ) == 2 THEN w->color(FL_GREEN) w->label("MID BUT") PRINT " The MIDDLE mouse button"
ELIF Fl::event_button( ) == 3 THEN w->color(FL_YELLOW) w->label("RIGHT BUT") PRINT " The RIGHT mouse button"
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: label("Key Pressed"); 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_ENTER: color(FL_BLUE); std::cout<<"enter"<<" event and returns :\n"<<ret; redraw(); break; case FL_LEAVE: color(FL_BACKGROUND_COLOR); std::cout<<"leave"<<" event and returns :\n"<<ret; redraw(); break; case FL_DRAG: label("Drag"); std::cout<<"drag"<<" event and returns :\n"<<ret; break; case FL_FOCUS: std::cout<<"focus"<<" event and returns :\n"<<ret; break; case FL_UNFOCUS: std::cout<<"unfocus"<<" event and returns :\n"<<ret; break; case FL_CLOSE: std::cout<<"close"<<" event and returns :\n"<<ret; break; case FL_MOVE: std::cout<<"move"<<" event and returns :\n"<<ret; break; case FL_DEACTIVATE: std::cout<<"deactivate"<<" event and returns :\n"<<ret; break; case FL_ACTIVATE: std::cout<<"activate"<<" event and returns :\n"<<ret; break; case FL_HIDE: std::cout<<"hide"<<" event and returns :\n"<<ret; break; case FL_SHOW: std::cout<<"show"<<" event and returns :\n"<<ret; break; case FL_PASTE: std::cout<<"paste"<<" event and returns :\n"<<ret; break; case FL_SELECTIONCLEAR: std::cout<<"selectionclear"<<" event and returns :\n"<<ret; break; case FL_MOUSEWHEEL: color(FL_WHITE); label("wheel"); std::cout<<"mousewheel"<<" event and returns :\n"<<ret; std::cout<< Fl::event_dx(); std::cout<< Fl::event_dy(); break; case FL_NO_EVENT: std::cout<<"no 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,125,"A") but_a.callback(but_a_cb) win->end() win->show() Fl::run()
|
|
|
Post by vovchik on Jan 1, 2018 1:41:51 GMT 1
Dear Joe, Thanks for the demo. Everything works - I just had to add the -.L to the LDFLAGS. Will now have to see what games we can come up with. Happy New Year! With kind regards, vovchik
|
|
|
Post by bigbass on Jan 1, 2018 2:01:07 GMT 1
Hey vovchik
Thanks updated the code added special keys too Have a Happy New Year and enjoy the end of this year!
Joe
|
|