Skip to content

Instantly share code, notes, and snippets.

@andreldm
Created December 27, 2014 15:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andreldm/b78d519f0e856d091d50 to your computer and use it in GitHub Desktop.
Save andreldm/b78d519f0e856d091d50 to your computer and use it in GitHub Desktop.
FLTK callback with classes
/*
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