|
Post by bigbass on Nov 20, 2017 20:41:18 GMT 1
Hey vovchik First you got mail I see now how to get all the fluid code into one file and compile it in geany (this gets around the make file) I just took from the *.h and manually add it to the *cxx and use the geany compile options I posted in the first post of this thread now we could design in fluid and test if it compiles correctly then port it to bacon and add in bacon code this now is clear and easy using this demo P.S Thanks for inspiring me with fltk this will let us make some really cool things without the big headache c++ can give and thanks Peter for getting all this g++ code to compile Joe note this is all generated from fluid execept the manually adding the header code into the *cxx we could generate include files for anything and edit them easily now we lose readability for fast design but this is a great tool // generated by Fast Light User Interface Designer (fluid) version 1.0304
#include <FL/Fl.H> extern "C" { void butCB(Fl_Widget *w, void *ud); } extern "C" { void quitButCB(Fl_Widget *w, void *ud); } #include <FL/Fl_Double_Window.H> #include <FL/Fl_Button.H> #include <FL/Fl_Return_Button.H> #include <FL/Fl_Box.H> #include <stdio.h> #include <stdlib.h>
void butCB(Fl_Widget *w, void *ud) { printf("Hello, World!\n"); }
void quitButCB(Fl_Widget *w, void *ud) { printf("Exit!\n"); exit(1); }
int main(int argc, char **argv) { Fl_Double_Window* w; { Fl_Double_Window* o = new Fl_Double_Window(275, 160, "hello non-oo version"); w = o; if (w) {/* empty */} { Fl_Button* o = new Fl_Button(5, 10, 100, 25, "a button"); o->callback((Fl_Callback*)butCB); } // Fl_Button* o { Fl_Return_Button* o = new Fl_Return_Button(175, 120, 90, 35, "Quit"); o->tooltip("the quit button"); o->callback((Fl_Callback*)quitButCB); } // Fl_Return_Button* o { new Fl_Box(5, 45, 265, 65, "box"); } // Fl_Box* o o->end(); } // Fl_Double_Window* o w->show(argc, argv); return Fl::run(); }
here is the fluid file *.fl we could easily add to or modify code here then compile and port to save a lot time with the visual aspect # data file for the Fltk User Interface Designer (fluid) version 1.0304 header_name {.h} code_name {.cxx} decl {\#include <stdio.h>} {private local }
decl {\#include <stdlib.h>} {private local }
Function {butCB(Fl_Widget *w, void *ud)} {C return_type void } { code {printf("Hello, World!\\n");} {} }
Function {quitButCB(Fl_Widget *w, void *ud)} {open C return_type void } { code {printf("Exit!\\n"); exit(1);} {} }
Function {} {open } { Fl_Window {} { label {hello non-oo version} open xywh {427 139 275 160} type Double hide } { Fl_Button {} { label {a button} callback butCB xywh {5 10 100 25} } Fl_Return_Button {} { label Quit callback quitButCB selected tooltip {the quit button} xywh {175 120 90 35} } Fl_Box {} { label box xywh {5 45 265 65} } } }
|
|
|
Post by bigbass on Nov 21, 2017 7:02:19 GMT 1
Hey guys I know we want bacon code but first I have to get working source code. I built the simple GUI in fluid making sense using fluid I manually added in the event code but will later make it a fluid file tomorrow I added the class MyButton to get the events working this is the cpp code compile in geany Joe // generated by Fast Light User Interface Designer (fluid) version 1.0304
#include <stdio.h> #include <stdlib.h> #include <FL/Fl.H> #include <FL/Fl_Double_Window.H> #include <FL/Fl_Return_Button.H> #include <FL/Fl_Dial.H> #include <FL/Fl_Light_Button.H> #include <FL/names.h> #include <iostream>
extern "C" { void LEFT_CB(Fl_Widget *w, void *ud); } extern "C" { void MIDDLE_CB(Fl_Widget *w, void *ud); } extern "C" { void RIGHT_CB(Fl_Widget *w, void *ud); } extern "C" { void SCROLL_CB(Fl_Widget *w, void *ud); } extern "C" { void quitButCB(Fl_Widget *w, void *ud); }
void LEFT_CB(Fl_Widget *w, void *ud) { if (Fl::event_button( ) == 1) printf(" The LEFT mouse button \n"); if (Fl::event_button( ) == 2) printf(" The MIDDLE mouse button \n"); if (Fl::event_button( ) == 3) printf(" The RIGHT mouse button\n"); }
void MIDDLE_CB(Fl_Widget *w, void *ud) { if (Fl::event_button( ) == 1) printf(" The LEFT mouse button \n"); if (Fl::event_button( ) == 2) printf(" The MIDDLE mouse button \n"); if (Fl::event_button( ) == 3) printf(" The RIGHT mouse button\n"); }
void RIGHT_CB(Fl_Widget *w, void *ud) { if (Fl::event_button( ) == 1) printf(" The LEFT mouse button \n"); if (Fl::event_button( ) == 2) printf(" The MIDDLE mouse button \n"); if (Fl::event_button( ) == 3) printf(" The RIGHT mouse button\n"); }
void SCROLL_CB(Fl_Widget *w, void *ud) { printf("Scroll\n"); //std::cout<< Fl::event_dx(); //std::cout<< Fl::event_dy(); }
void quitButCB(Fl_Widget *w, void *ud) { printf("Exit!\n"); exit(1); }
struct MyButton : Fl_Light_Button {
MyButton(int x,int y,int w,int h,const char*l=0) :Fl_Light_Button(x,y,w,h,l) {}
int handle(int e) { int ret = Fl_Light_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 "; std::cout<< Fl::event_key() << " special key pressed \n "; break;
case FL_MOUSEWHEEL: std::cout<<"mousewheel"<<" event and returns: \n"<<ret; std::cout<< Fl::event_dx(); std::cout<< Fl::event_dy(); break; } return(ret); } };
int main(int argc, char **argv) { Fl_Double_Window* w; { Fl_Double_Window* o = new Fl_Double_Window(240, 160, "Mouse test"); w = o; if (w) {/* empty */} { Fl_Return_Button* o = new Fl_Return_Button(175, 115, 60, 40, "Quit"); o->tooltip("the quit button"); o->callback((Fl_Callback*)quitButCB); } // Fl_Return_Button* o { Fl_Dial* o = new Fl_Dial(90, 80, 65, 55, "scroll"); o->tooltip("scroll mouse"); o->callback((Fl_Callback*)SCROLL_CB, (void*)("scroll wheel")); } // Fl_Dial* o { MyButton* o = new MyButton(15, 20, 60, 50, "Left"); o->tooltip("left mouse"); o->callback((Fl_Callback*)LEFT_CB, (void*)("You pressed Left")); } // Fl_Light_Button* o { MyButton* o = new MyButton(85, 20, 70, 50, "Middle"); o->tooltip("middle mouse"); o->callback((Fl_Callback*)MIDDLE_CB, (void*)("you pressed Middle")); } // Fl_Light_Button* o { MyButton* o = new MyButton(165, 20, 70, 50, "Right"); o->tooltip("right mouse"); o->callback((Fl_Callback*)RIGHT_CB, (void*)("You pressed Right")); } // Fl_Light_Button* o o->end(); } // Fl_Double_Window* o w->show(argc, argv); return Fl::run(); }
|
|
|
Post by bigbass on Nov 22, 2017 6:58:31 GMT 1
Hey guys what I wanted was this type of demo widget when you press the mouse button the widget lights all the button and now the scroll follows the movement of the mouse wheel Trying to keep things transparent so you could run fluid and rebuild or edit easily adding all the needed files Note place or copy the official fluid binary in the fluid folder this is a minimum build before I hack at the files make an all in one file just run make in the test folder Joe mini-build.tar.gz (1005.27 KB)
|
|
|
Post by vovchik on Nov 22, 2017 17:07:57 GMT 1
Dear Joe, This old thing, which I posted in August (I think) and revised slightly today, does much of the event scavenging that the fltk example does, but in BaCon style. With kind regards, vovchik
|
|
|
Post by bigbass on Nov 22, 2017 18:04:48 GMT 1
Hey vovchik Thanks again for a good looking decent demo baconized I should hope I am not on a rabbit trail of trying to modify demos from the official fluid demos to bacon (and understand them) but they are overly complex to port I am able /and you are able to get at the events directly in a simplified way and glue it all together in bacon code I guess its easier to build the GUI in fluid and glue it all together in a baconized way I was hoping for some type of conversion tool I broke rule number 1 keep it simple its not too hard if there is only one cxx and no linking to port quickly but sorting out all the pointers when there is linking is a mess P.S thanks again for steering back to the bacon way of doing business Joe
|
|
|
Post by bigbass on Nov 23, 2017 16:02:42 GMT 1
Hey guys
persistence paid off this time I really fought with this much more than I expected to make an all in one file joining two cxx files and two headers and get it to compile cleanly and work correctly using fluid to design with
debugged modified and made an all in one mouse button test from original keyboard.cxx and keyboard_ui.cxx ,keyboard.h ,keyboard_ui.h,keyboard_ui.fl
well we now have some code to baconize make it more readable later but having working source code is also important without the complex linking and dependencies when using the official demos
in geany compile with these build options g++ -Wall -c "%f" -lfltk -lXext -lX11 -lm g++ -Wall -o "%e" "%f" -lfltk -lXext -lX11 -lm
some tips to remember when an all in one only callbacks are extern or it wont build
// // "$Id: keyboard.cxx 9303 2012-03-26 16:54:54Z manolo $" //
// // Copyright 1998-2010 by Bill Spitzak and others. // // This library is free software. Distribution and use rights are outlined in // the file "COPYING" which should have been included with this file. If this // file is missing or damaged, see the license at: // // http://www.fltk.org/COPYING.php // // Please report all bugs and problems on the following page: // // http://www.fltk.org/str.php //
// // Keyboard/event test program for the Fast Light Tool Kit (FLTK). // // Continuously display FLTK's event state. // // Known bugs: // // X insists on reporting the state *before* the shift key was // pressed, rather than after, on shift key events. I fixed this for // the mouse buttons, but it did not seem worth it for shift. // // X servers do not agree about any shift flags after except shift, ctrl, // lock, and alt. They may also not agree about the symbols for the extra // keys Micro$oft put on the keyboard. // // On IRIX the backslash key does not work. A bug in XKeysymToKeycode? //
// bigbass debugged modified and made an all in one mouse button test // from original keyboard.cxx and keyboard_ui.cxx ,keyboard.h ,keyboard_ui.h,keyboard_ui.fl
#include <stdio.h> #include <FL/Fl.H> #include <FL/Fl_Window.H>
class MyWindow : public Fl_Window { int handle(int); public: MyWindow(int w, int h, const char *t=0L) : Fl_Window( w, h, t ) { } };
#include <FL/Fl.H> MyWindow *my_window; #include <FL/Fl_Button.H> extern void shift_cb(Fl_Button*, void*); #include <FL/Fl_Dial.H> extern void wheel_cb(Fl_Dial*, void*); Fl_Dial *roller_y; MyWindow* make_window();
#include <string.h> // these are used to identify which buttons are which: void key_cb(Fl_Button*, void*) {} void shift_cb(Fl_Button*, void*) {} void wheel_cb(Fl_Dial*, void*) {}
// this is used to stop Esc from exiting the program: int handle(int e) { return (e == FL_SHORTCUT); // eat all keystrokes }
int MyWindow::handle(int msg) { if (msg==FL_MOUSEWHEEL) { roller_y->value( roller_y->value() + Fl::e_dy * roller_y->step() ); return 1; } return 0; }
int main(int argc, char** argv) { Fl::add_handler(handle); MyWindow *window = make_window(); window->show(argc,argv); while (Fl::wait()) { // update all the buttons with the current key and shift state: for (int i = 0; i < window->children(); i++) { Fl_Widget* b = window->child(i); if (b->callback() == (Fl_Callback*)key_cb) { int i = b->argument(); if (!i) i = b->label()[0]; Fl_Button *btn = ((Fl_Button*)b); int state = Fl::event_key(i); if (btn->value()!=state) btn->value(state); } else if (b->callback() == (Fl_Callback*)shift_cb) { int i = b->argument(); Fl_Button *btn = ((Fl_Button*)b); int state = Fl::event_state(i); if (btn->value()!=state) btn->value(state); } } } }
// GUI PART OF CODE
MyWindow* make_window() { { my_window = new MyWindow(235, 215); my_window->box(FL_FLAT_BOX); my_window->color(FL_BACKGROUND_COLOR); my_window->selection_color(FL_BACKGROUND_COLOR); my_window->labeltype(FL_NO_LABEL); my_window->labelfont(0); my_window->labelsize(14); my_window->labelcolor(FL_FOREGROUND_COLOR); my_window->align(Fl_Align(FL_ALIGN_TOP)); my_window->when(FL_WHEN_RELEASE); { Fl_Button* o = new Fl_Button(30, 40, 45, 80, "b1"); o->box(FL_THIN_UP_BOX); o->selection_color((Fl_Color)3); o->labelsize(8); o->callback((Fl_Callback*)shift_cb, (void*)(FL_BUTTON1)); } // Fl_Button* o { Fl_Button* o = new Fl_Button(95, 40, 45, 80, "b2"); o->box(FL_THIN_UP_BOX); o->selection_color((Fl_Color)3); o->labelsize(8); o->callback((Fl_Callback*)shift_cb, (void*)(FL_BUTTON2)); } // Fl_Button* o { Fl_Button* o = new Fl_Button(155, 40, 45, 80, "b3"); o->box(FL_THIN_UP_BOX); o->selection_color((Fl_Color)3); o->labelsize(8); o->callback((Fl_Callback*)shift_cb, (void*)(FL_BUTTON3)); } // Fl_Button* o { roller_y = new Fl_Dial(95, 145, 50, 45, "mouse scroll"); roller_y->box(FL_ROUND_UP_BOX); roller_y->selection_color(FL_BACKGROUND_COLOR); roller_y->labelsize(9); roller_y->step(0.1); roller_y->callback((Fl_Callback*)wheel_cb); roller_y->align(Fl_Align(FL_ALIGN_TOP_LEFT)); } // Fl_Dial* roller_y my_window->end(); } // MyWindow* my_window return my_window; }
If you want to use fluid here is the GUI part of the code
# data file for the Fltk User Interface Designer (fluid) version 1.0304 header_name {.h} code_name {.cxx} Function {make_window()} {open } { Fl_Window my_window {open selected xywh {456 296 235 215} type Double code0 {\#include "keyboard.h"} class MyWindow visible } { Fl_Button {} { label b1 user_data FL_BUTTON1 user_data_type {void*} callback shift_cb xywh {30 40 45 80} box THIN_UP_BOX selection_color 3 labelsize 8 } Fl_Button {} { label b2 user_data FL_BUTTON2 user_data_type {void*} callback shift_cb xywh {95 40 45 80} box THIN_UP_BOX selection_color 3 labelsize 8 } Fl_Button {} { label b3 user_data FL_BUTTON3 user_data_type {void*} callback shift_cb xywh {155 40 45 80} box THIN_UP_BOX selection_color 3 labelsize 8 } Fl_Dial roller_y { label {mouse scroll} callback wheel_cb xywh {95 145 50 45} box ROUND_UP_BOX selection_color 49 labelsize 9 align 5 step 0.1 } } }
|
|
|
Post by vovchik on Nov 23, 2017 16:29:19 GMT 1
Dear Joe, Thanks. All working as advertised - mouse buttons and scrollwheel, and ESC is dead. With kind regards, vovchik
|
|
|
Post by bigbass on Nov 23, 2017 17:28:52 GMT 1
Hey vovchik
I'm glad it compiled for you I know you will build many more wonderful things using fltk and these events will come in handy for everyone
of course we will simplify the code when it gets ported but having a way to use fluid to design with is fun and interesting
Joe
|
|
|
Post by vovchik on Nov 23, 2017 22:24:33 GMT 1
Dear Joe, Here is a mock-up of your events prog in BaCon. We just need the handle() bit and a flush-out of the callbacks, and we might well be in business. That, of course, is the tricky part and my brain is only semi-functional today. Too little coffee. With kind regards, vovchik UPDATED: Added a tiny bit to the callbacks, but they still need proper event processing and scrollwheel detection.
|
|
|
Post by bigbass on Nov 24, 2017 19:38:18 GMT 1
Hey vovchik
Thanks for your work looking good
almost there but still no with the wheel
Dont want to post the code until I get the mouse to move the scroll widget
Joe
|
|
|
Post by bigbass on Nov 25, 2017 6:58:54 GMT 1
Hey vovchik
sometimes less is more when dealing with a pesky problem area in g++
here is the less just to show how its done for the scroll move shown on the widget when you scroll now working yippie !
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
SUB wheel_cb(Fl_Dial* d, void* v)
PRINT "mouse callback "
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() ); 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") roller_y->box(FL_ROUND_UP_BOX) roller_y->selection_color(FL_BACKGROUND_COLOR) roller_y->labelsize(9) roller_y->step(0.1) roller_y->callback((Fl_Callback*)wheel_cb) roller_y->align(Fl_Align(FL_ALIGN_TOP_LEFT))
win->end() win->show() Fl::run()
|
|
|
Post by vovchik on Nov 25, 2017 11:31:22 GMT 1
Dear Joe, Thanks. It is a lot "less" and I like it. When I move the scrollweel when inside the dial, though, I get a segfault on 32-bit Mint. Wonder why...and have to investigate.
With kind regards, vovchik
|
|
|
Post by bigbass on Nov 25, 2017 14:12:20 GMT 1
Hey vovchik I had the same problem with segfault before and had to make a new MyDial class to get at the signal I think Peter explained the cause in detail in another post link on page 17 of the fltk thread fltk has a few callback options and we can get unexpected results when we compile 32 bit or 64 bit code with that tip I would focus on the callback Try this it compiles and works for me but if I just stuff a long in there I get a segfault too SUB wheel_cb(Fl_Dial* roller_y, long p) looks like on this one you will have to get the correct combo so it works for both machines good luck on the mission *going to take a look now at the button part of the code to see if we can get the mouse button press to cause the button to light when outside of the button widget but still in the window Joe
|
|
|
Post by bigbass on Nov 26, 2017 16:25:38 GMT 1
Hey vovchik Now it works for me I hope for you too the buffer overflow segfault we need to add Fl::flush();Fl::flush(); roller_y->value( roller_y->value() + Fl::e_dy * roller_y->step() ); return 1; I can't tell how much I fought with this one and how many combinations I tried but I think this was a good test of fltk events how they work "because of" this difficult segfault error Joe www.fltk.org/documentation.php/doc-1.1/osissues.htmlint fl_handle(const XEvent &) This call allows you to supply the X events to FLTK, which may allow FLTK to cooperate with another toolkit or library. The return value is non-zero if FLTK understood the event. If the window does not belong to FLTK and the add_handler() functions all return 0, this function will return false. Besides feeding events your code should call Fl::flush() periodically so that FLTK redraws its windows. This function will call the callback functions. It will not return until they complete. In particular, if a callback pops up a modal window by calling fl_ask(), for instance, it will not return until the modal function returns.
|
|
|
Post by vovchik on Nov 26, 2017 16:44:22 GMT 1
Dear Joe,
Thanks - works perfectly!!!! Great that you tried Fl::flush().
Incidentally, for routine compiling of fltk c__, I use the following, because I'm usually lazy:
fltk-config --compile events-joe3.cxx
and it does everything, producing and getting rid of temporary objects and leaving you with the binary.
With kind regards, vovchik
|
|