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

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

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

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

FLTK Help Session

By Richard Yu Gu

CS 638 -Graphics

Fall, 1999

Page 2: 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

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

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

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

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

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

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.

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

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 asvoid funcname(Fl_Widget *but, <parameters>)

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

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.

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

Drawing Using FLTK

• #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)

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

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 shouldsubclass the widget that which to be drawn to and

override the private: void draw() function.

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

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.

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

Event Handling Cont.

• Parameter e tells the type of event, common types are– FL_PUSH

– FL_DRAG

– FL_RELEASE

– 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();

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

Questions?

• More example of widgets?

• More details at S:\fltk\documentation

• Questions?