FLTK学习笔记三

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 = -g
CXXFLAGS = $(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 = hello
OBJS = hello.o
SRCS = hello.cxx
.SUFFIXES: .o .cxx
%.o: %.cxx
	$(CXX) $(CXXFLAGS) $(DEBUG) -c $<
all: $(OBJS)
	$(LINK) -o $(TARGET) $(OBJS) $(LDSTATIC)
$(TARGET): $(OBJS)
hello.o: hello.cxx
clean:
	rm -f hello.o 2> /dev/null
	rm -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();
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值