1 / 12

FLTK Help Session

FLTK Help Session. By Richard Yu Gu CS 638 -Graphics Fall, 1999. Component of FLTK to Discuss. Widget Basics Sub-classing Widgets Basic Drawing Event Handling Questions. Building blocks Several widgets can behave independently or interrelated

sef
Download Presentation

FLTK Help Session

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 Help Session By Richard Yu Gu CS 638 -Graphics Fall, 1999

  2. Component of FLTK to Discuss • Widget Basics • Sub-classing Widgets • Basic Drawing • Event Handling • Questions

  3. Building blocks Several widgets can behave independently or interrelated Many different “build-in” types come with FLTK Window Button Box Input Field File Chooser Menu Slider Group Widgets in FLTK

  4. Window by Example • Creating a new Window with its size as parameters • Subsequent Widget creation are to this window until end() occur. • show() member method displays the window • damage(1) member method triggers refreshing of the window

  5. Box by Example • Add Box to a window with its position in the window and its size. • redraw() method refreshes and update the display of the box, which is triggered by damage(1). • label() method allow drawing of text or image to the box.

  6. Buttons and Callback Functions • Button respond to click on them by calling the pre-registered function- “callback” function • Register a callback function by using the member function callback(<func name>, <(list of) parameters to the CB func>). • Define callback function as void funcname(Fl_Widget *but, <parameters>)

  7. Sidetrack on Callback Functions • Callback functions can be used and is meaningful for most of the widgets in FLTK library • When the default event of the widget occurred, the registered callback function if invoked automatically.

  8. #include <FL/fl_draw.h> color(x) to change color <FL/Enumerations.H> to see pre-defined colors Override draw() func of the widget to make the drawing persistent fl_rectf fl_rect fl_line fl_loop fl_polygon fl_arc fl_pie fl_draw(char *, int x, inty) Drawing Using FLTK

  9. Image Stored as char array, image, of length width*height*3. (Ordered in RGB) fl_draw_image(image, X, Y, imgW, imgH) With in a widget such as box do the following (new Fl_Image((unsigned char *)(image), imgW, imgH))->label(this); Drawing Images To make the drawing persistent programmer should subclass the widget that which to be drawn to and override the private: void draw() function.

  10. Event Handling • User Interaction • Mouse and Keyboard • Actions • Subclass the widget that need to deal with some specific events • Override the public: int handle(int e) method in the new class. • If, in the handle() function an event is dealt with, function should return 1, otherwise return 0.

  11. Event Handling Cont. • To find out where the mouse is use • Fl::event_x(); • Fl::event_y(); • To find out which button is pressed • Fl::event_button(); • To find which key is pressed • Fl::event_key(); • Parameter e tells the type of event, common types are • FL_PUSH • FL_DRAG • FL_RELEASE • FL_RELEASE • FL_MOVE • FL_KEYBOARD

  12. Questions? • More example of widgets? • More details at S:\fltk\documentation • Questions?

More Related