Created
December 27, 2014 15:52
-
-
Save andreldm/b78d519f0e856d091d50 to your computer and use it in GitHub Desktop.
FLTK callback with classes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Compiling | |
Windows: | |
g++ test.cpp -o test -std=gnu++11 -lfltk -lfltk_images -lole32 -luuid -lcomctl32 -lwsock32 -lgdi32 -lcomdlg32 | |
*/ | |
#include <FL/Fl.H> | |
#include <FL/Fl_Window.H> | |
#include <FL/Fl_Button.H> | |
#include <iostream> | |
class MyClass | |
{ | |
private: | |
Fl_Window *win; | |
int i; | |
public: | |
MyClass() | |
{ | |
i = 1; | |
win = new Fl_Window(90, 100); | |
Fl_Button *button = new Fl_Button(10, 10, 70, 20, "Button 1"); | |
button->callback([] (Fl_Widget*, void* data) { | |
(static_cast<MyClass*> (data))->handleButtonClick("Button 1"); }, this); | |
button = new Fl_Button(10, 40, 70, 20, "Button 2"); | |
button->callback([] (Fl_Widget*, void* data) { | |
(static_cast<MyClass*> (data))->handleButtonClick("Button 2"); }, this); | |
} | |
void show() | |
{ | |
win->show(); | |
} | |
void handleButtonClick(const char *msg) | |
{ | |
std::cout << msg << " - " << i++ << std::endl; | |
} | |
}; | |
int main() { | |
MyClass myClass; | |
myClass.show(); | |
return(Fl::run()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment