FLTK学习笔记三

来源:互联网 发布:主流的数据分析工具 编辑:程序博客网 时间:2024/05/22 15:24
Drawing Things in FLTK

There are only certain places you can execute drawing code in FLTK. Calling these functions at other places will result in undefined behavior!
The most common place is inside the virtual Fl_Widget::draw() method. To write code here, you must subclass one of the existing Fl_Widget classes and implement your own version of draw().
• You can also create custom boxtypes and labeltypes. These involve writing small procedures that can be called by existing Fl_Widget::draw() methods. These "types" are identified by an 8-bit index that is stored in the widget’s box(), labeltype(), and possibly other properties.
• You can call Fl_Window::make_current() to do incremental update of a widget. Use Fl_Widget::window() to find the window.


Handling Events

Events are identified by the integer argument passed to a handle() method that overrides the Fl_Widget::handle() virtual method. Other information about the most recent event is stored in static locations and acquired by calling the Fl::event_*() methods.


Example:

CXX = $(shell /cygdrive/d/bin/fltk/bin/fltk-config --cxx)DEBUG = -gCXXFLAGS = $(shell /cygdrive/d/bin/fltk/bin/fltk-config --cxxflags ) -I.LDFLAGS = $(shell /cygdrive/d/bin/fltk/bin/fltk-config --ldflags )LDSTATIC = $(shell /cygdrive/d/bin/fltk/bin/fltk-config --ldstaticflags)FLTKPREFIX = $(shell /cygdrive/d/bin/fltk/bin/fltk-config --prefix)LINK = $(CXX)TARGET = helloOBJS = hello.oSRCS = hello.cxx.SUFFIXES: .o .cxx%.o: %.cxx$(CXX) $(CXXFLAGS) $(DEBUG) -c $<all: $(OBJS)$(LINK) -o $(TARGET) $(OBJS) $(LDSTATIC)$(TARGET): $(OBJS)hello.o: hello.cxxclean:rm -f hello.o 2> /dev/nullrm -f $(TARGET) 2> /dev/null


 

#include <FL/Fl.H>#include <FL/Fl_Window.H>#include <FL/Fl_Box.H>#include <FL/fl_draw.H>class MyDraw: public Fl_Widget{    void draw(){    fl_color(FL_RED);    fl_rectf(x(),y(),w(),h());    }public:    MyDraw(int X, int Y, int W, int H): Fl_Widget(X,Y,W,H){}};int main(int argc, char **argv) {    Fl_Window *window = new Fl_Window(340,180);    Fl_Box *box = new Fl_Box(20,40,300,100,"Hello, World!");    box->box(FL_UP_BOX);    box->labelfont(FL_BOLD+FL_ITALIC);    box->labelsize(36);    box->labeltype(FL_SHADOW_LABEL);    MyDraw *draw = new MyDraw(10,10,20,30);    window->end();    window->show(argc, argv);    return Fl::run();}

 

原创粉丝点击