Presentation is loading. Please wait.

Presentation is loading. Please wait.

FLTK Help Session By Richard Yu Gu CS 638 -Graphics Fall, 1999.

Similar presentations


Presentation on theme: "FLTK Help Session By Richard Yu Gu CS 638 -Graphics Fall, 1999."— 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 Widgets in FLTK 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

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(, ). Define callback function as void funcname(Fl_Widget *but, )

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 Drawing Using FLTK #include color(x) to change color 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)

9 Drawing Images 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); 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. Parameter e tells the type of event, common types are –FL_PUSH –FL_DRAG –FL_RELEASE –FL_MOVE –FL_KEYBOARD 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();

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


Download ppt "FLTK Help Session By Richard Yu Gu CS 638 -Graphics Fall, 1999."

Similar presentations


Ads by Google