1 / 28

FLTK

FLTK. Install and Use FLTK Widgets Callbacks Handling event System events Mouse events Keyboard events. Objectives. Linux Package manager Mac < 10.5 Mac Ports *nix ./configure && make && make install Visual Studio Open fltk-source/visualc/fltk.dsw and build

lan
Download Presentation

FLTK

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. FLTK

  2. Install and Use FLTK • Widgets • Callbacks • Handling event • System events • Mouse events • Keyboard events Objectives

  3. Linux • Package manager • Mac < 10.5 • Mac Ports • *nix • ./configure && make && make install • Visual Studio • Open fltk-source/visualc/fltk.dsw and build • In fltk-source copy FL folder to vc/include • In fltk-source/lib copy all files to vc/lib Installing FLTK 1.1

  4. Visual Studio • Add fltk.lib, wsock32.lib, comctl32.lib,fltkgl.lib, fltkforms.lib, and fltkimages.lib (or fltkd.lib, etc.) to linker input • *nix • `fltk-config --use-gl --use-images --use-forms --cxxflags –ldflags` Linking

  5. Basic visual building blocks which are combined intoan applications GUI Widgets

  6. Buttons • Includes radio buttons and check boxes • Text • Display and receive strings • Valuators • Display and receive numbers • Groups • Containers such as tabs and group boxes • Also includes windows and OpenGL windows Common FLTK Widgets

  7. Parent Child relationship • Created widgets are added to current group • Created group widgets start their own group • Stopped by calling widget->end(); • Can manually add widgets to groups • Get / Set Methods • Change style, properties, values etc. • Get: int minimum() • Set: void minimum(int) Hierarchies and Properties

  8. #include <FL/Fl.H> #include <FL/Fl_Window.H> #include <FL/Fl_Box.H> intmain(intargc, char **argv) { Fl_Window *window = new Fl_Window(300, 180); Fl_Box *box = new Fl_Box(20, 40, 260, 100, "Hello World"); box->box(FL_UP_BOX); window->end(); window->show(argc, argv); return Fl::run(); } FLTK Hello World

  9. Sets a functions to called when the value of a widget changes • void functionName(Fl_Widget*, void*) • Called function is passed pointer to the widget that changed and optional pointer to data • Can be activated by keyboard shortcut FLTK Callbacks

  10. void button_cb(Fl_Widget *widget, void *data) { Fl_Button*button = (Fl_Button*)widget; button->label("Thank you"); } intmain(intargc, char **argv) { ... Fl_Button *button = new Fl_Button(50, 70, 200, 40, "Click Me"); button->callback(button_cb); ... } Callback Demo

  11. Subclass an existing widget • Control widget to get/receive a value • Composite widget to hold a list of child widgets and handle them together • Can also subclass existing widget and change Custom Widgets

  12. Composite widget • Slider and text box • When the value of one changes the other is updated • Will use slider internally to store data • Easier because already has min, max, etc. • Improvements • Validate text box input Custom Widget

  13. Widget is a composition so we will inherit Fl_Group Class CustomWidget : Fl_Group { • Constructor with default FLTK parameters public: CustomWidget(intx, inty, intw, inth, char *l =0) : Fl_Group(x, y, w, h, l); Custom Widget

  14. Our two widgets private: Fl_Int_Input*input; Fl_Slider*slider; • Slider will store our data • Current value • Bounds • Step size Custom Widget

  15. Common slider properties public: int value(); void value(intv); int minimum(); void minimum(int min); int maximum(); void maximum(int max); void bounds(int min, int max); Custom Widget

  16. Internal callbacks static void input_cb(Fl_Widget *w, void *d); static void slider_cb(Fl_Widget *w, void *d); void input_cb2(); void slider_cb2(); Custom Widget

  17. Constructor: Layout intconst in_w = 40; input = new Fl_Int_Input(x, y, in_w, h); slider = new Fl_Slider(x + in_w, y, w- in_w, h); slider->type(FL_HOR_SLIDER); Custom Widget

  18. Constructor: Data bounds(1, 100); value(1); • Constructor: Callbacks input->when(FL_WHEN_CHANGED); input->callback(input_cb, this); slider->callback(slider_cb, this); Custom Widget

  19. Static callbacks void CustomWidget::input_cb(Fl_Widget *w, void *d) { ((CustomWidget*)d)->input_cb2(); } void CustomWidget::slider_cb(Fl_Widget *w, void *d) { ((CustomWidget*)d)->slider_cb2(); } Custom Widget

  20. Callbacks: Update the other widget void CustomWidget::input_cb2() { intval; sscanf(input->value(), "%d", &val); slider->value(val); } void CustomWidget::slider_cb2() { char val[16]; sprintf(val, "%d", (int)(slider->value() + 0.5)); input->value(val); } Custom Widget

  21. Properties intCustomWidget::value() { return (int)(slider->value() + 0.5); } void CustomWidget::value(intv) { slider->value(v); slider_cb2(); } Custom Widget

  22. Focus events • Mouse enters/leaves program • Program gains/loses focus • Clipboard events • Widget events • Activation/deactivation • Show/hide System Events

  23. Button pushed down • Mouse moved while button pressed (drag) • Button release • Mouse moved • Mouse wheel Mouse Events

  24. Propagate through widgets until handled • Key Up/Down • Event trigger on both key press and release • Sent to widget with focus, then parents, then becomes a shortcut • Shortcuts • Sent to widget under mouse, then parents, then every widget Keyboard Events

  25. Override inthandle(int event) • Return 0 if event unused • Event will continue to be passed around • Return 1 if event used • Event is consumed • Slider responds to left/right keys • Expand to include up/down keys Custom Widget Events

  26. intCustomWidget::handle(int event) { if ( event == FL_KEYDOWN ) { if ( Fl::event_key() == FL_Up ) { value(value() + 1); return 1; } else if ( Fl::event_key() == FL_Down ) { value(value() - 1); return 1; } } return Fl_Group::handle(event); } Custom Widget Events

  27. GUI to produce FLTK source code • Creates C++ code • Compile .fl file into .cxx and .h • Can create your entire program FLUID

  28. Premade dialog boxes • File chooser • Input • Color • Alerts • Images • 2D drawing functions • Threads • Timers Other FLTK Parts

More Related