|
Post by bigbass on Nov 30, 2017 8:24:30 GMT 1
Hey guys getting started with fluid and setting up the callbacks can take some time and having a demo of some code before its ported to bacon can help bridge a gap by default fluid just points everything to "o" making it tricky to port but the way I set this up it generates easier to read code fluid-keys.tar.gz (2.13 KB) by the way I have a hard time to read these small symbols at night and made a small tool and demo at the same time when you generate the header you have to adjust it to look like I have below to make correctly
|
|
|
Post by bigbass on Nov 30, 2017 17:38:49 GMT 1
Hello This is a better simplified demo because this is what you will see when working with fluid all the steps are transparent nothing missing *The reason steps were missing before was I was still doing manual edits making an all in one to get it to compile and build now all is working correctly with the headers I fixed the redraw part of the dial widget 1.) install fluid 2.) fluid mouse4.fl (or set the file to open with fluid) 3.) notice the needed headers were manually added inside the mouse4.fl if you click on WIN then the TAB C++ there is a box called Extra Code: this step saves you a big headache it is not automatically done 4.) if you use this as a guide it will be easy to port code to bacon it took be some time to get this all sorted out to produce code that will compile cleanly for both fluid and bacon included is mouse4.fl = is the fluid GUI file to make the GUI and is able to regenerate the *.cxx and *.h files mouse5.bac = is the bacon port of the mouse4.cxx if you compile using geany you wont need a make file fluidmouse.tar.gz (2.19 KB) compile option g++ -Wall -c "%f" -lfltk -lXext -lX11 -lm build option g++ -Wall -o "%e" "%f" -lfltk -lXext -lX11 -lm Attachments:
|
|
|
Post by vovchik on Nov 30, 2017 19:33:02 GMT 1
Dear Joe,
Thanks. And we can shorten it somewhat like this:
PRAGMA INCLUDE <FL/Fl.H> PRAGMA INCLUDE <FL/names.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_Light_Button.H> PRAGMA LDFLAGS -lfltk -lfltk_images -L. PRAGMA COMPILER g++ PRAGMA OPTIONS -Wno-write-strings -Wno-pointer-arith OPTION PARSE FALSE
SUB BUTTON_CB3(Fl_Widget* o, void*) PRINT "B3" END SUB
SUB BUTTON_CB2(Fl_Widget* o, void*) PRINT "B2" END SUB
SUB BUTTON_CB1(Fl_Widget* o, void*) PRINT "B1" END SUB
SUB DIAL_CB(Fl_Widget* o, void*) LOCAL val TYPE float val = ((Fl_Valuator*)o)->value() PRINT val END SUB
DECLARE WIN TYPE Fl_Double_Window* DECLARE BOX TYPE Fl_Box* DECLARE DIAL TYPE Fl_Dial* DECLARE B1 TYPE Fl_Light_Button* DECLARE B2 TYPE Fl_Light_Button* DECLARE B3 TYPE Fl_Light_Button*
WIN = new Fl_Double_Window(305, 330, "Valuator no classes, showing values ") WIN->box(FL_GLEAM_UP_BOX) WIN->color(43) WIN->selection_color(43) BOX = new Fl_Box(45, 5, 230, 230, "Scroll") BOX->box(FL_GLEAM_ROUND_UP_BOX) BOX->labelfont(1) BOX->align(Fl_Align(FL_ALIGN_TOP|FL_ALIGN_INSIDE)) DIAL = new Fl_Dial(125, 25, 65, 65, "DIAL") DIAL->tooltip("Standard Dial") DIAL->box(FL_PLASTIC_ROUND_UP_BOX) DIAL->color(44) DIAL->selection_color(FL_FOREGROUND_COLOR) DIAL->labelsize(8) DIAL->value(0.5) DIAL->callback(DIAL_CB) DIAL->window()->hotspot(DIAL) DIAL->angles(0,315)
B1 = new Fl_Light_Button(65, 115, 50, 100, "b1") B1->tooltip("b1") B1->box(FL_GLEAM_UP_BOX) B1->callback(BUTTON_CB1)
B2 = new Fl_Light_Button(130, 115, 50, 100, "b2") B2->tooltip("b2") B2->box(FL_GLEAM_ROUND_UP_BOX) B2->callback(BUTTON_CB2) B3 = new Fl_Light_Button(195, 115, 50, 100, "b3") B3->tooltip("b3") B3->box(FL_GLEAM_ROUND_UP_BOX) B3->callback(BUTTON_CB3)
WIN->end() WIN->show(argc, argv)
Fl::run()
It works fine on my machine.
With kind regards, vovchik
|
|
|
Post by bigbass on Nov 30, 2017 20:47:49 GMT 1
Hey vovchik Yes both parts of the callback look better shortened without the cast what a strange cast to get the value by the default way((Fl_Valuator*)o)->value())
but dont forget to put back the DIAL->redraw() it is needed in the callback to update the visual of the scroll
Joe
|
|
|
Post by vovchik on Nov 30, 2017 21:30:14 GMT 1
Dear Joe, And we can then do a HUG job on it. PRAGMA INCLUDE <FL/Fl.H> PRAGMA INCLUDE <FL/names.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_Light_Button.H> PRAGMA LDFLAGS -lfltk -lfltk_images -L. PRAGMA COMPILER g++ PRAGMA OPTIONS -Wno-write-strings -Wno-pointer-arith OPTION PARSE FALSE
' FLTK aliases ALIAS Fl::scheme TO STYLE ALIAS Fl::run TO DISPLAY ALIAS Fl::visual TO VISUAL ALIAS Fl::flush TO SYNC ALIAS Fl_Color TO FL_COLOR ALIAS fl_color TO SETCOLOR ' FLTK functions DEF FN CH2$(x) = (char*)x DEF FN WINDOW(t, x, y) = new Fl_Double_Window(x, y, t) DEF FN LIGHT_BUTTON(t, x, y) = new Fl_Light_Button(0, 0, x, y, t) DEF FN BUTTON(t, x, y) = new Fl_Button(0, 0, x, y, t) DEF FN DIAL(t, x, y) = new Fl_Dial(0, 0, x, y, t) DEF FN BOX(t, x, y) = new Fl_Box(0, 0, x, y, t) DEF FN MARK(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 HIDE(w) = w->hide() DEF FN SETANGLES(a, b, c) = a->angles(b,c) DEF FN SETHOTSPOT(a) = a->window()->hotspot(a) DEF FN SETPROPERTY(arg1,arg2,arg3) = arg1->arg2(arg3) DEF FN GET(arg1,arg2) = arg1->arg2() DEF FN SET(w,x) = w->value(x) DEF FN GRAB$(arg1,arg2) = arg1->arg2() DEF FN TEXT(w,x) = w->label(x) DEF FN ATTACH(w, x, y) = w->position(x, y) DEF FN RESIZABLE(w, x) = w->resizable(x) DEF FN REDRAW(w) = w->redraw() DEF FN IMAGE_RGB(x, y, z, d) = new Fl_RGB_Image(x, y, z, d) DEF FN IMG_RGB_SCALE(w, x, y) = w->copy(x, y) DEF FN IMAGE_RGB_FREE(x) = x->~Fl_RGB_Image()
DECLARE win TYPE Fl_Double_Window* DECLARE box TYPE Fl_Box* DECLARE dial TYPE Fl_Dial* DECLARE b[3] TYPE Fl_Light_Button*
SUB BUTTON_CB3(Fl_Widget* o, void*) PRINT "b[2]" END SUB
SUB BUTTON_CB2(Fl_Widget* o, void*) PRINT "b[1]" END SUB
SUB BUTTON_CB1(Fl_Widget* o, void*) PRINT "b[0]" END SUB
SUB DIAL_CB(Fl_Widget* o, void*) LOCAL val TYPE float val = ((Fl_Valuator*)o)->value() PRINT val REDRAW(o) SYNC END SUB
' global FLTK settings VISUAL(FL_RGB8) STYLE("plastic") win = WINDOW("Valuator no classes, showing values", 305, 330) SETPROPERTY(win, box, FL_GLEAM_UP_BOX) SETPROPERTY(win, color, 43) SETPROPERTY(win, selection_color, 43)
box = BOX("Scroll", 230, 230) SETPROPERTY(box, box, FL_GLEAM_ROUND_UP_BOX) SETPROPERTY(box, labelfont, 1) SETPROPERTY(box, align, FL_ALIGN_TOP|FL_ALIGN_INSIDE) ATTACH(box, 45, 5)
dial = DIAL("DIAL", 65, 65) SETPROPERTY(dial, tooltip,"Standard Dial") SETPROPERTY(dial, box, FL_PLASTIC_ROUND_UP_BOX) SETPROPERTY(dial, color, 44) SETPROPERTY(dial, selection_color, FL_FOREGROUND_COLOR) SETPROPERTY(dial, labelsize, 8) SETPROPERTY(dial, value, 0.5) CALLBACK(dial, DIAL_CB) SETHOTSPOT(dial) SETANGLES(dial, 0, 315) ATTACH(dial, 125, 25)
b[0] = LIGHT_BUTTON("b[0]", 50, 100) SETPROPERTY(b[0], tooltip, "b1") SETPROPERTY(b[0], box, FL_GLEAM_UP_BOX) CALLBACK(b[0], BUTTON_CB1) ATTACH(b[0], 65, 115)
b[1] = LIGHT_BUTTON("b[1]", 50, 100) SETPROPERTY(b[1], tooltip, "b[1]") SETPROPERTY(b[1], box, FL_GLEAM_ROUND_UP_BOX) CALLBACK(b[1], BUTTON_CB2) ATTACH(b[1], 130, 115) b[2] = LIGHT_BUTTON("b[2]", 50, 100) SETPROPERTY(b[2], tooltip, "b[2]") SETPROPERTY(b[2], box, FL_GLEAM_ROUND_UP_BOX) CALLBACK(b[2], BUTTON_CB3) ATTACH(b[2], 195, 115)
SHOW(win)
DISPLAY()
With kind regards, vovchik
|
|
|
Post by bigbass on Dec 1, 2017 5:47:44 GMT 1
Thanks vovchik For the HUG syntax version A lot of work and cleverness to do the macros
|
|
|
Post by bigbass on Dec 1, 2017 18:40:03 GMT 1
Hey Guys I am trying to do this transparently showing all the steps Here is the reference code www.c-jump.com/bcc/common/Talk2/Cxx/FltkFluid/FltkFluid.htmlThis is a nice demo / tutorial and a good place to begin porting code to so that the fluid output syntax is more readable if you notice everything in fluid points to "o" and uses a make_window and then a main that we don't need so I removed it to simplify the reading 1.)we can add basic looking Names to make it easier to port to bacon using the fluid GUI as a first step 2.)then we can port it to bacon syntax add the PRAGMA... 3.)and finally give it HUG syntax DEF FN and much more all of these are important steps to get more code for bacon I do see that it would be possible to have a HUG version of fltk but it will be a work in progress and if we test the code well a widget at a time it would come together and we have fluid to speed up the grunt work of going from idea to widget/app I really like using fluid we need something like this Joe here is my modified version of the source code with the fluid file GUI cxx and the *.h fluid-demo2.tar.gz (2.02 KB) dont forget the geany compile
|
|
|
Post by bigbass on Dec 2, 2017 8:08:07 GMT 1
here is the bacon code for the above widget still could use PRINT but cout also works for both this is getting easy but tedious we should make a fluid2 bacon code converter It would be tricky to automate the MENUBAR[] part of the code though
PRAGMA INCLUDE <FL/Fl.H> PRAGMA INCLUDE <FL/Fl_Window.H> PRAGMA INCLUDE <FL/Fl_Input.H> PRAGMA INCLUDE <FL/Fl_Menu_Bar.H> PRAGMA INCLUDE <FL/Fl_Button.H> PRAGMA INCLUDE <FL/Fl_Output.H> PRAGMA INCLUDE <FL/Fl_Group.H> PRAGMA INCLUDE <FL/Fl_Round_Button.H> PRAGMA INCLUDE <FL/names.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_Light_Button.H> PRAGMA INCLUDE <iostream> PRAGMA LDFLAGS -lfltk -lfltk_images -L. PRAGMA COMPILER g++ PRAGMA OPTIONS -Wno-write-strings -Wno-pointer-arith OPTION PARSE FALSE
DECLARE WIN TYPE Fl_Window* DECLARE INPUT1 TYPE Fl_Input* DECLARE BUTTON0 TYPE Fl_Button* DECLARE OUTCODE TYPE Fl_Output* DECLARE MENUBAR TYPE Fl_Menu_Bar* DECLARE GROUP1 TYPE Fl_Group* DECLARE BUTTON1 TYPE Fl_Round_Button* DECLARE BUTTON2 TYPE Fl_Round_Button* DECLARE BUTTON3 TYPE Fl_Round_Button*
'--- cant use a closed array forced a size of 100 DECLARE Fl_Menu_Item menu_MENUBAR[100]
SUB WIN_CB(Fl_Widget* inp_, void* userdata_) PRINT "X button clicked -- exiting the program" exit( 0 ) END SUB
SUB RADIO_CB(Fl_Widget* btn, void* userdata) std::cout << "radio " << (long)userdata << '\n' END SUB
SUB GET_CB(Fl_Widget* inp_, void* userdata_) LOCAL text TYPE char* LOCAL outcode TYPE char* text = INPUT1->value() OUTCODE->value( text ) std::cout << " get input " << INPUT1->value() << '\n' END SUB
SUB INPUT_CB(Fl_Widget* inp_, void* userdata) std::cout << "INPUT_CB\n " << (char*)userdata END SUB
TEN = 10 TWENTY = 20 THIRTY = 30
Fl_Menu_Item menu_MENUBAR[] = { \ {"File", 0, WIN_CB, 0, 64, (uchar)FL_NORMAL_LABEL, 0, 14, 0}, \ {"Quit", 0, WIN_CB, 0, 0, (uchar)FL_NORMAL_LABEL, 0, 14, 0}, \ {0,0,0,0,0,0,0,0,0}, \ {0,0,0,0,0,0,0,0,0}}
WIN = new Fl_Window(320, 240, "MY WINDOW") WIN->box(FL_GLEAM_ROUND_DOWN_BOX) WIN->callback(WIN_CB) INPUT1 = new Fl_Input(60, 36, 75, 24, "Data:") INPUT1->callback(INPUT_CB, (void*)("input"))
BUTTON0 = new Fl_Button(15, 70, 70, 25, "Get data") BUTTON0->box(FL_GLEAM_ROUND_DOWN_BOX) BUTTON0->callback(GET_CB)
OUTCODE = new Fl_Output(210, 70, 75, 25, "Read-only data") MENUBAR = new Fl_Menu_Bar(0, 0, 320, 20) MENUBAR->box(FL_GLEAM_ROUND_DOWN_BOX) MENUBAR->menu(menu_MENUBAR)
GROUP1 = new Fl_Group(50, 117, 155, 68) BUTTON1 = new Fl_Round_Button(50, 117, 155, 18, "ten") BUTTON1->tooltip("button 1") BUTTON1->type(102) BUTTON1->down_box(FL_ROUND_DOWN_BOX) BUTTON1->callback(RADIO_CB, (void*)(10)) BUTTON2 = new Fl_Round_Button(50, 140, 155, 20, "twenty") BUTTON2->tooltip("button 2") BUTTON2->type(102) BUTTON2->down_box(FL_ROUND_DOWN_BOX) BUTTON2->callback(RADIO_CB, (void*)(20))
BUTTON3 = new Fl_Round_Button(50, 165, 155, 20, "thirty") BUTTON3->tooltip("button 3") BUTTON3->type(102) BUTTON3->down_box(FL_ROUND_DOWN_BOX) BUTTON3->callback(RADIO_CB, (void*)(30)) GROUP1-> end() WIN->end() WIN->resizable(WIN) WIN->show(argc, argv) Fl::run()
|
|
|
Post by vovchik on Dec 2, 2017 10:45:12 GMT 1
Dear Joe,
Menus in fltk are actually easy. I would do them this way, for example (using add):
PRAGMA INCLUDE <FL/Fl.H> PRAGMA INCLUDE <FL/Fl_Window.H> PRAGMA INCLUDE <FL/Fl_Input.H> PRAGMA INCLUDE <FL/Fl_Menu_Bar.H> PRAGMA INCLUDE <FL/Fl_Button.H> PRAGMA INCLUDE <FL/Fl_Output.H> PRAGMA INCLUDE <FL/Fl_Group.H> PRAGMA INCLUDE <FL/Fl_Round_Button.H> PRAGMA INCLUDE <FL/names.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_Light_Button.H> PRAGMA INCLUDE <iostream> PRAGMA LDFLAGS -lfltk -lfltk_images -L. PRAGMA COMPILER g++ PRAGMA OPTIONS -Wno-write-strings -Wno-pointer-arith OPTION PARSE FALSE
DECLARE WIN TYPE Fl_Window* DECLARE INPUT1 TYPE Fl_Input* DECLARE BUTTON0 TYPE Fl_Button* DECLARE OUTCODE TYPE Fl_Output* DECLARE MENUBAR TYPE Fl_Menu_Bar* DECLARE GROUP1 TYPE Fl_Group* DECLARE BUTTON1 TYPE Fl_Round_Button* DECLARE BUTTON2 TYPE Fl_Round_Button* DECLARE BUTTON3 TYPE Fl_Round_Button*
'--- cant use a closed array forced a size of 100 'DECLARE Fl_Menu_Item menu_MENUBAR[100]
SUB WIN_CB(Fl_Widget* inp_, void* userdata_) PRINT "X button clicked -- exiting the program" exit( 0 ) END SUB
SUB FILE_CB(Fl_Widget* inp_, void* userdata_) PRINT "File button clicked" PRINT EXEC$("ls -l") END SUB
SUB RADIO_CB(Fl_Widget* btn, void* userdata) std::cout << "radio " << (long)userdata << '\n' END SUB
SUB GET_CB(Fl_Widget* inp_, void* userdata_) LOCAL text TYPE char* LOCAL outcode TYPE char* text = INPUT1->value() OUTCODE->value( text ) std::cout << " get input " << INPUT1->value() << '\n' END SUB
SUB INPUT_CB(Fl_Widget* inp_, void* userdata) std::cout << "INPUT_CB\n " << (char*)userdata END SUB
SUB MENU_CB(Fl_Widget* inp_, void* userdata_) PRINT MENUBAR->value() END SUB
TEN = 10 TWENTY = 20 THIRTY = 30
WIN = new Fl_Window(320, 240, "MY WINDOW") WIN->box(FL_GLEAM_ROUND_DOWN_BOX) WIN->callback(WIN_CB) INPUT1 = new Fl_Input(60, 36, 75, 24, "Data:") INPUT1->callback(INPUT_CB, (void*)("input"))
BUTTON0 = new Fl_Button(15, 70, 70, 25, "Get data") BUTTON0->box(FL_GLEAM_ROUND_DOWN_BOX) BUTTON0->callback(GET_CB)
OUTCODE = new Fl_Output(210, 70, 75, 25, "Read-only data")
MENUBAR = new Fl_Menu_Bar(0, 0, 320, 20) MENUBAR->box(FL_GLEAM_ROUND_DOWN_BOX) MENUBAR->selection_color(FL_BLUE) MENUBAR->add("File/Quit", FL_CTRL+'q', WIN_CB) MENUBAR->add("Edit/List files (ls)", FL_CTRL+'l', FILE_CB) MENUBAR->add("Edit/Other items/Item 1", 0, MENU_CB) MENUBAR->add("Edit/Other items/Item 2", 0, MENU_CB)
GROUP1 = new Fl_Group(50, 117, 155, 68) BUTTON1 = new Fl_Round_Button(50, 117, 155, 18, "ten") BUTTON1->tooltip("button 1") BUTTON1->type(102) BUTTON1->down_box(FL_ROUND_DOWN_BOX) BUTTON1->callback(RADIO_CB, (void*)(10))
BUTTON2 = new Fl_Round_Button(50, 140, 155, 20, "twenty") BUTTON2->tooltip("button 2") BUTTON2->type(102) BUTTON2->down_box(FL_ROUND_DOWN_BOX) BUTTON2->callback(RADIO_CB, (void*)(20))
BUTTON3 = new Fl_Round_Button(50, 165, 155, 20, "thirty") BUTTON3->tooltip("button 3") BUTTON3->type(102) BUTTON3->down_box(FL_ROUND_DOWN_BOX) BUTTON3->callback(RADIO_CB, (void*)(30)) GROUP1-> end() WIN->end() WIN->resizable(WIN) WIN->show(argc, argv) Fl::run()
With kind regards, vovchik
|
|
|
Post by bigbass on Dec 2, 2017 15:52:10 GMT 1
Hey vovchik Thats the best way to do the menu easy to read easy to apply and much simpler and a big thanks from me sometimes just code isn't enough you need to see the improvements visually to get the full impact Joe
|
|
|
Post by bigbass on Dec 3, 2017 17:42:52 GMT 1
Hey vovchik
This is a menu using fluid to explain better what happens when you write code in fluid the out put code is generated like this
would be nice if we can do it a better way to generate menu->add I hope we dont need to hack a the source code to do it if we could find a way to convert the fluid file code to save the manually adding the code using menu->add
I wrote a little demo code for a menu
call it menu.fl then you can run it in fluid and generate the *.cxx *.h
# data file for the Fltk User Interface Designer (fluid) version 1.0304 header_name {.h} code_name {.cxx} Function {FILE_CB(Fl_Widget* inp_, void* userdata_)} {open return_type void } { code {printf("file callback\\n");} {} }
Function {NEW_CB(Fl_Widget* inp_, void* userdata_)} {open return_type void } { code {printf("new callback\\n");} {} }
Function {OPEN_CB(Fl_Widget* inp_, void* userdata_)} {open return_type void } { code {printf("open callback\\n");} {} }
Function {SAVE_CB(Fl_Widget* inp_, void* userdata_)} {open return_type void } { code {printf("save callback\\n");} {} }
Function {SAVEAS_CB(Fl_Widget* inp_, void* userdata_)} {open return_type void } { code {printf("saveas callback\\n");} {} }
Function {EXIT_CB(Fl_Widget* inp_, void* userdata_)} {open return_type void } { code {printf("exit callback\\n");} {} }
Function {BOLD_CB(Fl_Widget* inp_, void* userdata_)} {open return_type void } { code {printf("bold callback\\n");} {} }
Function {ENDLIST_CB(Fl_Widget* inp_, void* userdata_)} {open return_type void } { code {printf("endlist callback\\n");} {} }
Function {TEXT_CB(Fl_Widget* inp_, void* userdata_)} {open return_type void } { code {printf("text callback\\n");} {} }
Function {} {open } { Fl_Window WIN { label { Editor} open xywh {294 274 640 455} type Double hide resizable } { Fl_Menu_Bar MENUBAR {open xywh {0 0 640 25} box PLASTIC_UP_BOX color 227 selection_color 221 } { Submenu SUBMENU_FILE { label File open xywh {0 0 100 20} } { MenuItem MENU_NEW { label New callback NEW_CB xywh {5 5 100 20} } MenuItem MENU_OPEN { label Open callback OPEN_CB xywh {0 0 100 20} } MenuItem MENU_SAVE { label Save callback SAVE_CB xywh {0 0 100 20} } MenuItem MENU_SAVEAS { label {Save as} callback SAVEAS_CB xywh {0 0 100 20} } MenuItem MENU_EXIT { label Exit callback EXIT_CB xywh {0 0 100 20} } } Submenu SUBMENU_EDIT { label Edit open xywh {0 0 100 20} } { MenuItem MENU_BOLD { label Bold callback BOLD_CB xywh {0 0 100 20} } } Submenu SUBMENU_VIEW { label View open xywh {0 0 100 20} } { MenuItem MENU_TEXT { label Text callback TEXT_CB xywh {0 0 100 20} } } Submenu SUBMENU_OPTIONS { label Options open xywh {0 0 100 20} } { Submenu SUBMENU_LIST { label List open xywh {0 0 100 20} } { MenuItem MENU_ENDLIST { label {End List} callback ENDLIST_CB xywh {5 5 100 20} } } } Submenu SUBMENU_HELP { label Help open xywh {0 0 100 20} } {} } Fl_Scroll SCROLL {open xywh {0 30 640 450} } { Fl_Text_Editor TEXTEDITOR {selected xywh {0 30 640 450} box DOWN_BOX code0 {Fl_Text_Buffer* BUFF;} code1 {BUFF = new Fl_Text_Buffer();} code2 {TEXTEDITOR->buffer(BUFF);} } } } }
|
|
|
Post by vovchik on Dec 3, 2017 21:54:37 GMT 1
Dear Joe, Thanks. It produces a very nice-looking menu without much code. And if that code could be parsed easily into HUG-like BaCon, it would be very convenient for quick and dirty gui design. With kind regards, vovchik
|
|
|
Post by bigbass on Dec 4, 2017 3:10:32 GMT 1
Hey vovchik updated the code in the above post so the editor part works (has a buffer ) and is part of the fluid code so you don't have to add it manually trying to do the same for the menu add but havent figured out the syntax for it to compile P.S I went back and looked at the excellent editor Peter posted and this is a different idea trying to code in fluid in a way we can generate bacon code easily later and have a GUI tool to keep the code organized and easy to edit for example we can add parts of the ed.cxx.tar.gz into fluid then port it the parts we want to get a better idea how to add code to fluid when you don't have an original *.fl to start with www.straub.as/cpp/fltk/fltkdoc-1.1.9/doc/editor.html#editorJoe
|
|
|
Post by bigbass on Dec 4, 2017 20:51:31 GMT 1
This follows the documentation in the above link I made a fluid file for the editor (there isn't one in the examples just cxx code)
here I added all the dummy callbacks but have to add the code later to do the work
but great demo for fluid because you can add what you want later takes a little time to get started but worth the effort and is fun
# data file for the Fltk User Interface Designer (fluid) version 1.0304 header_name {.h} code_name {.cxx} Function {open_cb(Fl_Widget* inp_, void* userdata_)} {open return_type void } { code {printf("open_cb callback\\n");} {} }
Function {save_cb(Fl_Widget* inp_, void* userdata_)} {open return_type void } { code {printf("save_cb callback\\n");} {} }
Function {saveas_cb(Fl_Widget* inp_, void* userdata_)} {open return_type void } { code {printf("saveas callback\\n");} {} }
Function {close_cb(Fl_Widget* inp_, void* userdata_)} {open return_type void } { code {printf("close_cb callback\\n");} {} }
Function {insert_cb(Fl_Widget* inp_, void* userdata_)} {open return_type void } { code {printf("insert_cb callback\\n");} {} }
Function {view_cb(Fl_Widget* inp_, void* userdata_)} {open return_type void } { code {printf("view_cb callback\\n");} {} }
Function {quit_cb(Fl_Widget* inp_, void* userdata_)} {open return_type void } { code {printf("quit_cb callback\\n");} {} }
Function {new_cb(Fl_Widget* inp_, void* userdata_)} {open return_type void } { code {printf("new_cb callback\\n");} {} }
Function {undo_cb(Fl_Widget* inp_, void* userdata_)} {open return_type void } { code {printf("undo callback\\n");} {} }
Function {cut_cb(Fl_Widget* inp_, void* userdata_)} {open return_type void } { code {printf("cut callback\\n");} {} }
Function {copy_cb(Fl_Widget* inp_, void* userdata_)} {open return_type void } { code {printf("copy callback\\n");} {} }
Function {paste_cb(Fl_Widget* inp_, void* userdata_)} {open return_type void } { code {printf("paste callback\\n");} {} }
Function {delete_cb(Fl_Widget* inp_, void* userdata_)} {open return_type void } { code {printf("delete callback\\n");} {} }
Function {find_cb(Fl_Widget* inp_, void* userdata_)} {open return_type void } { code {printf("find callback\\n");} {} }
Function {find2_cb(Fl_Widget* inp_, void* userdata_)} {open return_type void } { code {printf("find2 callback\\n");} {} }
Function {replace_cb(Fl_Widget* inp_, void* userdata_)} {open return_type void } { code {printf("replace callback\\n");} {} }
Function {replace2_cb(Fl_Widget* inp_, void* userdata_)} {open selected return_type void } { code {printf("replace2 callback\\n");} {} }
Function {} {open } { Fl_Window WIN { label { Editor} comment {
Fl_Text_Buffer *textbuf; Fl_Window *replace_dlg; Fl_Input *replace_find; Fl_Input *replace_with; Fl_Button *replace_all; Fl_Return_Button *replace_next; Fl_Button *replace_cancel;
char search[256];} open xywh {688 125 640 455} type Double hide resizable code0 {\#include <stdio.h> \#include <stdlib.h> \#include <string.h> \#include <ctype.h> \#include <errno.h>} code1 {\#include <FL/Fl.H> \#include <FL/Fl_Group.H> \#include <FL/Fl_Double_Window.H> \#include <FL/fl_ask.H> \#include <FL/Fl_Native_File_Chooser.H> \#include <FL/Fl_Menu_Bar.H> \#include <FL/Fl_Input.H> \#include <FL/Fl_Button.H> \#include <FL/Fl_Return_Button.H> \#include <FL/Fl_Text_Buffer.H> \#include <FL/Fl_Text_Editor.H> \#include <FL/filename.H>} } { Fl_Menu_Bar menuitems {open xywh {0 0 640 25} box PLASTIC_UP_BOX color 227 selection_color 221 } { Submenu SUBMENU_FILE { label File open xywh {0 0 100 20} } { MenuItem MENU_NEW { label New callback new_cb xywh {5 5 100 20} } MenuItem MENU_OPEN { label Open callback open_cb xywh {0 0 100 20} } MenuItem MENU_SAVE { label Save callback save_cb xywh {0 0 100 20} } MenuItem MENU_SAVEAS { label {Save as} callback save_cb xywh {0 0 100 20} } MenuItem MENU_QUIT { label Quit callback quit_cb xywh {0 0 100 20} } MenuItem MENU_INSERT { label Insert callback insert_cb xywh {10 10 100 20} } MenuItem MENU_VIEW { label View callback view_cb xywh {20 20 100 20} } } Submenu SUBMENU_EDIT { label Edit open xywh {0 0 100 20} } { MenuItem MENU_UNDO { label Undo callback undo_cb xywh {10 10 100 20} } MenuItem MENU_CUT { label Cut callback cut_cb xywh {20 20 100 20} } MenuItem MENU_COPY { label Copy callback copy_cb xywh {30 30 100 20} } MenuItem MENU_PASTE { label Paste callback paste_cb xywh {40 40 100 20} } MenuItem MENU_DELETE { label Delete callback delete_cb xywh {50 50 100 20} } } Submenu SUBMENU_SEARCH { label Search open xywh {0 0 100 20} } { MenuItem MENU_FIND { label Find callback find_cb xywh {60 60 100 20} } MenuItem MENU_FIND_AGAIN { label {Find Again} callback find2_cb xywh {70 70 100 20} } MenuItem MENU_REPLACE { label Replace callback replace_cb xywh {80 80 100 20} } MenuItem MENU_REPLACE_AGAIN { label {Replace Again} callback replace2_cb xywh {90 90 100 20} } } } Fl_Scroll SCROLL {open xywh {0 30 640 450} } { Fl_Text_Editor TEXTEDITOR { comment {
Fl_Text_Buffer *textbuf;
Fl_Text_Buffer *textbuf; Fl_Window *replace_dlg; Fl_Input *replace_find; Fl_Input *replace_with; Fl_Button *replace_all; Fl_Return_Button *replace_next; Fl_Button *replace_cancel;
Fl_Text_Editor *editor; char search[256];} xywh {0 30 640 450} box DOWN_BOX code0 {Fl_Text_Buffer* BUFF;} code1 {BUFF = new Fl_Text_Buffer();} code2 {TEXTEDITOR->buffer(BUFF);} } } } }
|
|
|
Post by vovchik on Dec 4, 2017 22:01:52 GMT 1
Dear Joe, Thanks. This is a kind of barebones version modded from Peter's code. Don't worry - it will not write anything to any file - just display the buffer in a terminal. With kind regards, vovchik PRAGMA INCLUDE <FL/Fl.H> PRAGMA INCLUDE <FL/Fl_Double_Window.H> PRAGMA INCLUDE <FL/Fl_Text_Editor.H> PRAGMA INCLUDE <FL/Fl_Menu_Bar.H> PRAGMA INCLUDE <FL/Fl_Button.H> PRAGMA INCLUDE <FL/Fl_Scroll.H> PRAGMA LDFLAGS -lfltk -L. PRAGMA COMPILER g++ PRAGMA OPTIONS -Wno-write-strings -Wno-pointer-arith
OPTION PARSE FALSE
DECLARE win TYPE Fl_Double_Window*
DECLARE buff TYPE Fl_Text_Buffer* DECLARE edit TYPE Fl_Text_Editor* 'DECLARE menu TYPE Fl_Menu_Bar* DECLARE slc TYPE Fl_Scroll* DECLARE ebut0, ebut1 TYPE Fl_Button* DECLARE ww, wh TYPE int DECLARE src TYPE char* ww = 500 wh = 480
' ------------------ FUNCTION HEX2RGB(STRING hex$) ' ------------------ ' returns unsigned int for html hex colour LOCAL rgb TYPE unsigned int IF ISFALSE(REGEX(hex$, "^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$")) THEN ' if hex$ is bad, convert to white PRINT "Invalid hex number: ", hex$ hex$ = "#FFFFFF" END IF hex$ = hex$ & "00" rgb = DEC(MID$(hex$, 2)) RETURN rgb END FUNCTION
' ------------------ SUB SAVE_EDIT_CB(Fl_Widget *w, void *data) ' ------------------ LOCAL newbuf$ TYPE STRING PRINT "Button clicked..." newbuf$ = (char*)buff->text() PRINT newbuf$ END SUB
' ------------------ SUB CLOSE_EDIT_CB(Fl_Widget *w, void* data) ' ------------------ END END SUB
' set scheme Fl::scheme("gleam") ' prevent dithering Fl::visual(FL_RGB) ' window win = new Fl_Double_Window(ww, wh, "Edit /etc/passwd") win->box(FL_GLEAM_UP_BOX) win->color(FL_DARK_RED)
ebut0 = new Fl_Button(10, wh - 40, 60, 30, "Save") ebut0->callback(SAVE_EDIT_CB) ebut1 = new Fl_Button(ww - 70, wh - 40, 60, 30, "Close") ebut1->callback(CLOSE_EDIT_CB)
scl = new Fl_Scroll(10, 10, ww - 20, wh - 60, "")
buff = new Fl_Text_Buffer() edit = new Fl_Text_Editor(10, 10, ww - 20, wh - 60) edit->color(HEX2RGB("#F6F2E5")) edit->selection_color(FL_BLUE) edit->buffer(buff) win->show() src = (char*)LOAD$("/etc/passwd") buff->text(src)
return(Fl::run())
|
|