BlenderDev/interface API
Wikipedia,自由的百科全书
interface API介绍
本文的写作得益于Blender maillist 给我发的一份邮件,告诉我Blender的user interface方面的文档都在/doc/interface.txt中,我看了这个文档,决定把我了解得内容写出来。
1. 窗口(window)和模块(block)
所有的Blender的GUI元素都被存放在uiBlock结构中,而所有的uiBlock构成一个链表,最终显示在一个窗口中。
uiBlock通过以下函数生成:
uiBlock *block= uiNewBlock(&curarea->uiblocks, "stuff", UI_EMBOSSX, UI_HELV, curarea->win);
下面的代码生成一个新的模块,然后将模块放入一个窗口区域的uiBlock链表中:
uiDoBlocks(&curarea->uiblocks, event);
1.1内存分配
在这个工具箱中,创建新的uiBlock和在界面上画出uiBlock没有任何区别,在任何一个窗口中,重画所有的uiBlock就是重新创建了所有的uiBlock。
内存分配主要处理以下事件:
- 如果在同一个窗口中有同名的uiBlock,他们将被释放
- 当你关闭一个窗口时,这个窗口中的所有uiBlock将会被释放
- 当你复制一个窗口时,这个窗口中所有的uiBlock将会被复制
1.2内部工作机制
当调用uiDoBlock函数时,当前活动窗口中的所有模块将被重新评价,这时在链表中将进行一系列复杂的过程:
代码:
- while(looping)
/* the normal buttons handling */
- for each block
- call uiDoBlock (handles buttons for single block)
- (end for)
/* at this moment, a new block can be created, for a menu */
/* so we create a 2nd loop for it */
- while first block is a menu
- if block is a menu and not initialized:
- initalize 'saveunder'
- draw it
- get event from queue
- call uiDoBlock (handles buttons for single block)
/* here, a new block again can be created, for a sub menu */
- if return "end" from uiDoBlock
restore 'saveunder's
free all menu blocks
exit from loop
- do tooltip if nothing has happened
- (end while)
- if there was menu, it does this loop once more
(when you click outside a menu, at another button)
- (end while)
- do tooltip if nothing has happened
interface API详解
创建一个新的按钮模块,并把他放到窗口的模块链表中:
uiBlock *uiNewBlock(ListBase *lb, char *name, short dt, short font, short win)
ListBase *lb 指向窗口的链表地址,新的uiBlock将被放在这个链表中
char *name 标志uiBlock的唯一名字,如果这个名字在链表中已经存在,原先取这个名字的uiBlock将会被释放
short dt drawtype. 下面有说明
short font font id 号
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 coloured button (like blender sensors) */
font:
UI_HELV 0 /* 正常 */
UI_HELVB 1 /* 粗体 */
当一个uiBlock被创建出来后,所有的uiButton都会有uiBlock的属性
?? uiBlock的控制函数
?? void uiDrawBlock(block) 画出uiBlock
?? void uiBlockSetCol(uiBlock *block, int col)
设置uiBlock的颜色:
col:
BUTGREY,
BUTGREEN,
BUTBLUE,
BUTSALMON,
MIDGREY,
BUTPURPLE,
?? void uiBlockSetEmboss(uiBlock *block, int emboss)
改变uiBlock的drawtype,关于drawtype的定义,前面有
?? void uiBlockSetDirection(uiBlock *block, int direction)
用于pop-up和pulldown按钮
direction:
UI_TOP
UI_DOWN
UI_LEFT
UI_RIGHT
?? void uiBlockSetXOfs(uiBlock *block, int xofs)
for menus, offset from parent
设置uiBlock在菜单中的位置
?? void uiBlockSetButmFunc(uiBlock *block, void (*menufunc)(void *arg, int event), void *arg)
设置uiBlock的响应函数
?? void uiAutoBlock(uiBlock *block, float minx, float miny, float sizex, float sizey, UI_BLOCK_ROWS)
让block中的按钮自动对齐
