Interface API
Interface API
Contents
1 General notes
1.1 C and H files
- The API is built with Blender in mind, with some buttons acting on lists of
Blender data.
It was not meant to be available as a separate SDK, nor to be used for other
applications.
- It works with only OpenGL calls, for the full 100%. This means that it has some
quirks
built-in to work with all OS's and OpenGL versions. Especially frontbuffer
drawing is
a continuous point of attention. Buttons can be drawn with any window matrix.
However,
errors can still occur when buttons are created in windows with non-standard
glViewports.
- The code was written to replace the old 1.8 button system, but under high
pressure. Quite
some button methods from the old system were copied for that reason.
- I tried to design a unified GUI system, which equally works for pulldown menus,
pop up menus,
and normal button layouts. Although it gives nice features and freedom in design,
the code
looks quite hard to understand for that reason. Not all 'normal' pulldown menu
features
could be hacked in easily, they just differ too much from other UI elements.
Could be
looked at once...
- During the past period of NaN (beginning of 2002) someone tried to make a more
'high' level
API for it, with less low level defines and structure info needed in calling
code. I am not
really sure if this was done well... or even finished. In the bottom of
interface.c you can
see the 'new' API which is now used in Blender code. It used to be so much more
simple!
Nevertheless, I will use that convention in this doc.
- Unfinished stuff: the code was scheduled to be expanded with 'floating blocks'
which can
serve as permanent little button-fields in Blender windows. Think for example of
having
an (optional) extra field in the 3d window displaying object loc/rot/size.
After that, the existing button windows can be reorganized in such blocks as
well, allowing
a user to configure the genereal buttons layout (make vertical for example).
(the previous 2 include files have not been separated fully yet)
Color and icons stuff has been put in: (unfinished code, under development)
blender/source/blender/src/resources.c
blender/source/blender/include/BIF_resources.h
Related code:
blender/source/blender/src/toolbox.c (extra GUI elements built on top of this API)
All GUI elements are collected in uiBlocks, which in turn are linked together in a
list that's
part of a Blender Area-window.
The next code example makes a new block, and puts it in the list of blocks of the
current active
Area:
uiDoBlocks(&curarea->uiblocks, event);
This code is usually available in each area-window event queue handler. You give
uiDoBlocks
an event code, and the uiDoBlocks handles whatever is to be handled. Blocks can be
standard buttons or pull down menus. Can return immediately, or jump to an internal
handling
loop.
With a call to uiDoblocks, all blocks in the current active window are evaluated.
It walks through the lists in a rather complex manner:
- while(looping)
- (end while)
uiBlock *uiNewBlock(ListBase *lb, char *name, short dt, short font, short win)
ListBase *lb pointer to list basis, where the block will be appended to
(blenlib)
char *name unique name to identify the block. When the name exists in
the list,
the old uiBlock gets freed.
short dt drawtype. See below
short font font id number
short win blender area-window id
drawtype:
UI_EMBOSSX 0 /* Rounded embossed button (standard in Blender) */
UI_EMBOSSW 1 /* Simpler embossed button */
UI_EMBOSSN 2 /* Button with no border */
UI_EMBOSSF 3 /* Square embossed button (file select) */
UI_EMBOSSM 4 /* Colored, for pulldown menus */
UI_EMBOSSP 5 /* Simple borderless colored button (like blender
sensors) */
font:
UI_HELV 0 /* normal font */
UI_HELVB 1 /* bold font */
With the new truetype option in Blender, this is used for all font families
When a uiBlock is created, each uiButton that is defined gets the uiBlock
properties.
Changing Block properties in between will effect uiButtons defined thereafter.
void uiDrawBlock(block)
draws the block
col:
BUTGREY,
BUTGREEN,
BUTBLUE,
BUTSALMON,
MIDGREY,
BUTPURPLE,
direction:
UI_TOP
UI_DOWN
UI_LEFT
UI_RIGHT
void uiAutoBlock(uiBlock *block, float minx, float miny, float sizex, float sizey,
UI_BLOCK_ROWS)
Sets the buttons in this block to automatically align, and fit within
boundaries.
Internally it allows multiple columns or rows as well. Only 'row order' has
been implemented.
The uiDefBut definitions don't need coordinates as input here, but instead:
- first value (x1) to indicate row number
- width and height values (if filled in) will be used to define a relative
width/height.
A call to uiDrawBlock will invoke the calculus to fit in all buttons.
(these values are being set within the interface.c and toolbox.c code.)
Internally, each button or menu item is a 'uiButton', with a generic API and
handling:
ui_def_but(block, type, retval, str, x1, y1, x2, y2, poin, min, max, a1, a2, tip);
Because a lot of obscure generic (re-use) happens here, translation calls have been
made
for each most button types individually.
-----------4.1 UiDefBut
uiBut *UiDefBut[CSIF]( uiBlock *block, int type, int retval, char *str,
short x1, short y1, short x2, short y2, xxxx *poin,
float min, float max, float a1, float a2, char *tip)
type:
1. BUT
Activation button. (like "Render")
Passing on a pointer is not needed
2. TOG or TOGN
Toggle button (like "Lock")
The pointer value is set either at 0 or 1
If pressed, it calls the optional function with arguments provided.
Type TOGN: works negative, when pressed it sets at 0
"|BIT|<nr>"
When added to type, it works on a single bit <nr> (lowest order bit: nr =
'0')
3. ROW
Button that's part of a row.
in "min" you set a row-id number, in "max" the value you want *poin to be
assigned when you press the button. Always pass on these values as floats.
When this button is pressed, it sets the "max" value to *poin, and redraws
all buttons with the same row-id number.
4. NUMSLI or HSVSLI
Number-slider or hsv-slider button.
"min" and "max" are to clamp the value to.
If you want a button type "Col" to be updated, make 'a1' equal to 'retval'
from the COL button.
5. NUM
Number button
Set the clamping values 'min' and 'max' always as float.
For UiDefButF, set a 'step' in 'a1', in 1/100's. The step value is the
increment or
decrement when you click once on the right or left side of a button.
The optional button function is additionally called for each change of the
*poin value.
6. TEX
Text string button.
Pointertype is standard a char. Value 'max' is length of string (pass as
float).
When button is left with ESC, it doesn't put the 'retval' at the queue.
7. LABEL
Label button.
Only displays text.
If 'min' is set at 1.0, the text is printed in white.
8 SEPR
A separator line, typically used within pulldown menus.
9. MENU
Menu button.
The syntax of the string in *name defines the menu items:
- %t means the previous text becomes the title
- item separator is '|'
- return values are indicated with %x[nr] (i.e: %x12).
without returnvalues, the first item gets value 0 (incl. title!)
Example: "Do something %t| turn left %2| turn right %1| nothing %0"
10. COLOR
A special button that only visualizes a RGB value
In 'retval' you can put a code, which is used to identify for sliders if it
needs
redraws while using the sliders. Check button '5'.
As *poin you input the pointer to the 'r' value, 'g' and 'b' are supposed to
be
next to that.
Instead of a 'name', all buttons as described for uiDefBut also can have an icon:
Same syntax and types available as previous uiDefBut, but now with an icon
code
instead of a name. The icons are numbered in resources.c
uiBut *uiDefIconTextButF(uiBlock *block, int type, int retval, int icon, char *str,
short x1, short y1, short x2, short y2, float *poin,
float min, float max, float a1, float a2, char *tip)
Same again, but now with an icon and string as button name.
14. BLOCK
void uiDefBlockBut(uiBlock *block, uiBlockFuncFP func, void *arg, char *str,
short x1, short y1, short x2, short y2, char *tip)
This button creates a new block when pressed. The function argument 'func' is
called
to take care of this. An example func:
uiBlockSetDirection(block, UI_RIGHT);
uiTextBoundsBlock(block, 50); /* checks for fontsize */
return block;
}
The uiDef coordinates here are only relative. When this function is called,
the interface
code automatically makes sure the buttons fit in the menu nicely.
-----------4.4 specials
15. KEYEVT
INLINK, the 'linking to' part activates creating a link, when a user releases
the mouse
cursor over it, while dragging a line from the LINK button.
uiSetButLink(but, void **pt, void ***ppt, short *totlink, short fromcode, short
tocode);
**pt: pointer to pointer (only one link allowed)
***ppt: pointer to pointerpointer (an array of pointers)
(Either one of these values should be NULL)
void uiButSetFunc(uiBut *but, void (*func)(void *arg1, void *arg2), void *arg1,
void *arg2)
When the button is pressed and released, it calls this function, with the 2
arguments.
</body>
<br><br><br>