FLTK学习笔记二

Making Your Own Boxtypes

You can define your own boxtypes by making a small function that draws the box and adding it to the table of boxtypes.

Adding Your Box Type

#define XYZ_BOX FL_FREE_BOXTYPE
Fl::set_boxtype(XYZ_BOX, xyz_draw, 1, 1, 2, 2);

The Drawing Function

void xyz_draw(int x, int y, int w, int h, Fl_Color c) {
fl_color(c);
fl_rectf(x, y, w, h);
fl_color(FL_BLACK);
fl_rect(x, y, w, h);
}


Making Your Own Label Types

Adding Your Label Type

#define XYZ_LABEL FL_FREE_LABELTYPE
Fl::set_labeltype(XYZ_LABEL, xyz_draw, xyz_measure);

The label type number n can be any integer value starting at the constant FL_FREE_LABELTYPE. Once
you have added the label type you can use the labeltype() method to select your label type.

Label Type Functions

void xyz_draw(const Fl_Label *label, int x, int y, int w, int h, Fl_Align align
) {
...
}

void xyz_measure(const Fl_Label *label, int &w, int &h) {
...
}


Making your own symbols

int fl_add_symbol(const char *name, void (*drawit)(Fl_Color), int scalable)

name is the name of the symbol without the "@"; scalable must be set to 1 if the symbol is generated using scalable vector drawing functions.To create a new symbol, you implement a drawing function void drawit(Fl_Color c) which typically uses the functions described in Drawing Complex Shapes to generate a vector shape inside a two-bytwo units sized box around the origin.

int fl_draw_symbol(const char *name,int x,int y,int w,int h,Fl_Color col)
This function draws a named symbol fitting the given rectangle.


A widgets can only have one callback at a time, even though you can change the trigger condition at any time.

If you want set multi callback, you must override the parent widget's handle() method. This method is called when event happened, then it decide what to do. Detail see: int Fl_Button::handle(int event)

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值