|
|
|
|
|
|
|
|
|
|
|
|
button |
|
|
|
|
The button widget is very important in Blender. A majority of interface elements are buttons. Buttons can be (and frequently are) stored in ui blocks which are containers for buttons.
Buttons are used to implement widget functionality of many different widgets commonly found in GUI toolkits. For example Blender buttons are used as traditional push buttons, radio buttons, popup menus, check boxes, text/integer edit fields, etc. The problem with this is that it makes it difficult for a user to imagine what kind of functionality is implemented with a particular button. For example, the buttons in the picture below have quite different functionality but they look the same:
push button | integer edit field | popup menu | radio buttons |
Their function must be inferred from subtle hints such as
The definition of a Blender button structure can be found in the file interface.h
.
There is one button structure for all button types.
typedef struct uiBut
{
struct uiBut *next, *prev;
short type, pointype, bit, bitnr, retval, flag, strwidth;
short ofs, pos, pad;
uint paper;
char *str;
char strdata[UI_MAX_NAME_STR];
char drawstr[UI_MAX_DRAW_STR];
float x1, y1, x2, y2;
char *poin;
float min, max;
float a1, a2, rt[4];
float aspect;
void (*func)();
void (*butfunc)(struct uiBut *);
struct uiBlock *(*blockfunc)();
void (*embossfunc)(uiCol *, float, float, float, float, float, int);
uiLink *link;
char *tip, *lockstr;
uiCol *col;
void *font;
uiIconImage *icon;
short lock, win;
short iconxadd, iconx, icony;
} uiBut ;
From the structure definition, you can see that the button can be part of a linked list of buttons.
The button structure contains four function pointers:
func
: This routine is usedbutfunc
: This routine is usedblockfunc
: This routine is used ??? The routine is initialized
at creation time to be the block's flock func.embossfunc
: This routine is used when drawing the outline/edges
of buttons and determines its visual appearance. There are a number of emboss
routines and the button's emboss routine is initialized at creation time to
be the block's emboss type.The function pointers are set at button creation.
The button is created with the uiDefBut
routine declared in the
file interface.h
and defined in the file interface.c
:
uiBut *uiDefBut(uiBlock *block, int type, int retval, char *str, short
x1, short y1, short x2, short y2, void *poin, float min, float max, float a1,
float a2, char *tip);
This routine creates a new uiBut
structure and fills in a number
of the structure fields.
Some of the parameters are somewhat cryptic. Here is a short description for each of them:
block
: the button block this button belongs to.type
: the type of button, the logical OR of of a button type
and a pointer type defined in interface.h
:
retval
: is the value returned when ???str
: ???x1, y1, x2, y2
: bounding box of the buttonpoin
min, max
: ???tip
: a tooltip that explains the function of the button