4 * ***** BEGIN GPL LICENSE BLOCK *****
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
21 * All rights reserved.
23 * Contributor(s): Blender Foundation 2002-2008, full recode.
25 * ***** END GPL LICENSE BLOCK *****
32 #include "MEM_guardedalloc.h"
35 #include "DNA_listBase.h"
36 #include "DNA_scene_types.h"
37 #include "DNA_screen_types.h"
38 #include "DNA_texture_types.h"
39 #include "DNA_userdef_types.h"
41 #include "BLI_arithb.h"
42 #include "BLI_blenlib.h"
43 #include "BLI_dynstr.h"
45 #include "BKE_context.h"
46 #include "BKE_idprop.h"
47 #include "BKE_library.h"
48 #include "BKE_screen.h"
49 #include "BKE_texture.h"
50 #include "BKE_utildefines.h"
53 #include "BIF_glutil.h"
57 #include "UI_interface.h"
59 #include "ED_screen.h"
63 #include "wm_subwindow.h"
64 #include "wm_window.h"
66 #include "RNA_access.h"
67 #include "RNA_types.h"
69 #include "interface_intern.h"
71 #define MENU_WIDTH 120
72 #define MENU_ITEM_HEIGHT 20
73 #define MENU_SEP_HEIGHT 6
76 * a full doc with API notes can be found in bf-blender/blender/doc/interface_API.txt
78 * uiBlahBlah() external function
79 * ui_blah_blah() internal function
82 static void ui_free_but(const bContext *C, uiBut *but);
84 /* ************* translation ************** */
86 int ui_translate_buttons()
88 return (U.transopts & USER_TR_BUTTONS);
91 int ui_translate_menus()
93 return (U.transopts & USER_TR_MENUS);
96 int ui_translate_tooltips()
98 return (U.transopts & USER_TR_TOOLTIPS);
101 /* ************* window matrix ************** */
103 void ui_block_to_window_fl(const ARegion *ar, uiBlock *block, float *x, float *y)
106 int sx, sy, getsizex, getsizey;
108 getsizex= ar->winrct.xmax-ar->winrct.xmin+1;
109 getsizey= ar->winrct.ymax-ar->winrct.ymin+1;
117 gx += block->panel->ofsx;
118 gy += block->panel->ofsy;
121 *x= ((float)sx) + ((float)getsizex)*(0.5+ 0.5*(gx*block->winmat[0][0]+ gy*block->winmat[1][0]+ block->winmat[3][0]));
122 *y= ((float)sy) + ((float)getsizey)*(0.5+ 0.5*(gx*block->winmat[0][1]+ gy*block->winmat[1][1]+ block->winmat[3][1]));
125 void ui_block_to_window(const ARegion *ar, uiBlock *block, int *x, int *y)
132 ui_block_to_window_fl(ar, block, &fx, &fy);
138 void ui_block_to_window_rct(const ARegion *ar, uiBlock *block, rctf *graph, rcti *winr)
143 ui_block_to_window_fl(ar, block, &tmpr.xmin, &tmpr.ymin);
144 ui_block_to_window_fl(ar, block, &tmpr.xmax, &tmpr.ymax);
146 winr->xmin= tmpr.xmin;
147 winr->ymin= tmpr.ymin;
148 winr->xmax= tmpr.xmax;
149 winr->ymax= tmpr.ymax;
152 void ui_window_to_block_fl(const ARegion *ar, uiBlock *block, float *x, float *y) /* for mouse cursor */
154 float a, b, c, d, e, f, px, py;
155 int sx, sy, getsizex, getsizey;
157 getsizex= ar->winrct.xmax-ar->winrct.xmin+1;
158 getsizey= ar->winrct.ymax-ar->winrct.ymin+1;
162 a= .5*((float)getsizex)*block->winmat[0][0];
163 b= .5*((float)getsizex)*block->winmat[1][0];
164 c= .5*((float)getsizex)*(1.0+block->winmat[3][0]);
166 d= .5*((float)getsizey)*block->winmat[0][1];
167 e= .5*((float)getsizey)*block->winmat[1][1];
168 f= .5*((float)getsizey)*(1.0+block->winmat[3][1]);
173 *y= (a*(py-f) + d*(c-px))/(a*e-d*b);
174 *x= (px- b*(*y)- c)/a;
177 *x -= block->panel->ofsx;
178 *y -= block->panel->ofsy;
182 void ui_window_to_block(const ARegion *ar, uiBlock *block, int *x, int *y)
189 ui_window_to_block_fl(ar, block, &fx, &fy);
195 void ui_window_to_region(const ARegion *ar, int *x, int *y)
197 *x-= ar->winrct.xmin;
198 *y-= ar->winrct.ymin;
201 /* ******************* block calc ************************* */
203 void ui_block_translate(uiBlock *block, int x, int y)
207 for(bt= block->buttons.first; bt; bt=bt->next) {
220 static void ui_text_bounds_block(uiBlock *block, float offset)
222 uiStyle *style= U.uistyles.first; // XXX pass on as arg
224 int i = 0, j, x1addval= offset, nextcol;
226 uiStyleFontSet(&style->widget);
228 for(bt= block->buttons.first; bt; bt= bt->next) {
230 //int transopts= ui_translate_buttons();
231 //if(bt->type==TEX || bt->type==IDPOIN) transopts= 0;
233 j= BLF_width(bt->drawstr);
239 /* cope with multi collumns */
240 bt= block->buttons.first;
242 if(bt->next && bt->x1 < bt->next->x1)
247 bt->x2 = bt->x1 + i + block->bounds;
249 ui_check_but(bt); // clips text again
252 x1addval+= i + block->bounds;
258 void ui_bounds_block(uiBlock *block)
263 if(block->buttons.first==NULL) {
265 block->minx= 0.0; block->maxx= block->panel->sizex;
266 block->miny= 0.0; block->maxy= block->panel->sizey;
271 block->minx= block->miny= 10000;
272 block->maxx= block->maxy= -10000;
274 bt= block->buttons.first;
276 if(bt->x1 < block->minx) block->minx= bt->x1;
277 if(bt->y1 < block->miny) block->miny= bt->y1;
279 if(bt->x2 > block->maxx) block->maxx= bt->x2;
280 if(bt->y2 > block->maxy) block->maxy= bt->y2;
285 block->minx -= block->bounds;
286 block->miny -= block->bounds;
287 block->maxx += block->bounds;
288 block->maxy += block->bounds;
291 /* hardcoded exception... but that one is annoying with larger safety */
292 bt= block->buttons.first;
293 if(bt && strncmp(bt->str, "ERROR", 5)==0) xof= 10;
296 block->safety.xmin= block->minx-xof;
297 block->safety.ymin= block->miny-xof;
298 block->safety.xmax= block->maxx+xof;
299 block->safety.ymax= block->maxy+xof;
302 static void ui_popup_bounds_block(const bContext *C, uiBlock *block, int menu)
304 wmWindow *window= CTX_wm_window(C);
305 int startx, starty, endx, endy, width, height;
306 int oldbounds, mx, my, xmax, ymax;
308 oldbounds= block->bounds;
310 /* compute mouse position with user defined offset */
311 ui_bounds_block(block);
312 mx= window->eventstate->x + block->minx + block->mx;
313 my= window->eventstate->y + block->miny + block->my;
315 wm_window_get_size(window, &xmax, &ymax);
317 /* first we ensure wide enough text bounds */
319 if(block->flag & UI_BLOCK_LOOP) {
321 ui_text_bounds_block(block, block->minx);
325 /* next we recompute bounds */
326 block->bounds= oldbounds;
327 ui_bounds_block(block);
329 /* and we adjust the position to fit within window */
330 width= block->maxx - block->minx;
331 height= block->maxy - block->miny;
333 startx= mx-(0.8*(width));
353 ui_block_translate(block, startx - block->minx, starty - block->miny);
355 /* now recompute bounds and safety */
356 ui_bounds_block(block);
359 /* used for various cases */
360 void uiBoundsBlock(uiBlock *block, int addval)
365 block->bounds= addval;
369 /* used for pulldowns */
370 void uiTextBoundsBlock(uiBlock *block, int addval)
372 block->bounds= addval;
376 /* used for block popups */
377 void uiPopupBoundsBlock(uiBlock *block, int addval, int mx, int my)
379 block->bounds= addval;
385 /* used for menu popups */
386 void uiMenuPopupBoundsBlock(uiBlock *block, int addval, int mx, int my)
388 block->bounds= addval;
394 /* ************** LINK LINE DRAWING ************* */
396 /* link line drawing is not part of buttons or theme.. so we stick with it here */
398 static void ui_draw_linkline(uiBut *but, uiLinkLine *line)
402 if(line->from==NULL || line->to==NULL) return;
404 rect.xmin= (line->from->x1+line->from->x2)/2.0;
405 rect.ymin= (line->from->y1+line->from->y2)/2.0;
406 rect.xmax= (line->to->x1+line->to->x2)/2.0;
407 rect.ymax= (line->to->y1+line->to->y2)/2.0;
409 if(line->flag & UI_SELECT)
410 glColor3ub(100,100,100);
414 ui_draw_link_bezier(&rect);
417 static void ui_draw_links(uiBlock *block)
422 but= block->buttons.first;
424 if(but->type==LINK && but->link) {
425 line= but->link->lines.first;
427 ui_draw_linkline(but, line);
435 /* ************** BLOCK ENDING FUNCTION ************* */
437 /* NOTE: if but->poin is allocated memory for every defbut, things fail... */
438 static int ui_but_equals_old(uiBut *but, uiBut *oldbut)
440 /* various properties are being compared here, hopfully sufficient
441 * to catch all cases, but it is simple to add more checks later */
442 if(but->retval != oldbut->retval) return 0;
443 if(but->rnapoin.data != oldbut->rnapoin.data) return 0;
444 if(but->rnaprop != oldbut->rnaprop)
445 if(but->rnaindex != oldbut->rnaindex) return 0;
446 if(but->func != oldbut->func) return 0;
447 if(but->funcN != oldbut->funcN) return 0;
448 if(oldbut->func_arg1 != oldbut && but->func_arg1 != oldbut->func_arg1) return 0;
449 if(oldbut->func_arg2 != oldbut && but->func_arg2 != oldbut->func_arg2) return 0;
450 if(!but->funcN && ((but->poin != oldbut->poin && (uiBut*)oldbut->poin != oldbut) || but->pointype != oldbut->pointype)) return 0;
455 static int ui_but_update_from_old_block(const bContext *C, uiBlock *block, uiBut *but)
461 oldblock= block->oldblock;
465 for(oldbut=oldblock->buttons.first; oldbut; oldbut=oldbut->next) {
466 if(ui_but_equals_old(oldbut, but)) {
468 but->flag= oldbut->flag;
469 but->active= oldbut->active;
470 but->pos= oldbut->pos;
471 but->editstr= oldbut->editstr;
472 but->editval= oldbut->editval;
473 but->editvec= oldbut->editvec;
474 but->editcoba= oldbut->editcoba;
475 but->editcumap= oldbut->editcumap;
476 but->selsta= oldbut->selsta;
477 but->selend= oldbut->selend;
478 but->softmin= oldbut->softmin;
479 but->softmax= oldbut->softmax;
480 but->linkto[0]= oldbut->linkto[0];
481 but->linkto[1]= oldbut->linkto[1];
484 oldbut->active= NULL;
487 /* ensures one button can get activated, and in case the buttons
488 * draw are the same this gives O(1) lookup for each button */
489 BLI_remlink(&oldblock->buttons, oldbut);
490 ui_free_but(C, oldbut);
499 void ui_menu_block_set_keymaps(const bContext *C, uiBlock *block)
503 char buf[512], *butstr;
505 /* only do it before bounding */
506 if(block->minx != block->maxx)
509 for(but=block->buttons.first; but; but=but->next) {
511 prop= (but->opptr)? but->opptr->data: NULL;
513 if(WM_key_event_operator_string(C, but->optype->idname, but->opcontext, prop, buf, sizeof(buf))) {
514 butstr= MEM_mallocN(strlen(but->str)+strlen(buf)+2, "menu_block_set_keymaps");
515 strcpy(butstr, but->str);
519 but->str= but->strdata;
520 BLI_strncpy(but->str, butstr, sizeof(but->strdata));
529 void uiEndBlock(const bContext *C, uiBlock *block)
532 Scene *scene= CTX_data_scene(C);
534 /* inherit flags from 'old' buttons that was drawn here previous, based
535 * on matching buttons, we need this to make button event handling non
536 * blocking, while still alowing buttons to be remade each redraw as it
537 * is expected by blender code */
538 for(but=block->buttons.first; but; but=but->next) {
539 if(ui_but_update_from_old_block(C, block, but))
542 /* temp? Proper check for greying out */
544 wmOperatorType *ot= but->optype;
547 CTX_store_set((bContext*)C, but->context);
549 if(ot==NULL || (ot->poll && ot->poll((bContext *)C)==0)) {
550 but->flag |= UI_BUT_DISABLED;
555 CTX_store_set((bContext*)C, NULL);
558 /* only update soft range while not editing */
559 if(but->rnaprop && !(but->editval || but->editstr || but->editvec))
560 ui_set_but_soft_range(but, ui_get_but_val(but));
562 ui_but_anim_flag(but, (scene)? scene->r.cfra: 0.0f);
565 if(block->oldblock) {
566 block->auto_open= block->oldblock->auto_open;
567 block->auto_open_last= block->oldblock->auto_open_last;
568 block->tooltipdisabled= block->oldblock->tooltipdisabled;
570 block->oldblock= NULL;
573 /* handle pending stuff */
574 if(block->layouts.first) uiBlockLayoutResolve(C, block, NULL, NULL);
575 ui_block_do_align(block);
576 if(block->flag & UI_BLOCK_LOOP) ui_menu_block_set_keymaps(C, block);
579 if(block->dobounds == 1) ui_bounds_block(block);
580 else if(block->dobounds == 2) ui_text_bounds_block(block, 0.0f);
581 else if(block->dobounds) ui_popup_bounds_block(C, block, (block->dobounds == 4));
583 if(block->minx==0.0 && block->maxx==0.0) uiBoundsBlock(block, 0);
584 if(block->flag & UI_BUT_ALIGN) uiBlockEndAlign(block);
589 /* ************** BLOCK DRAWING FUNCTION ************* */
591 void ui_fontscale(short *points, float aspect)
593 if(aspect < 0.9f || aspect > 1.1f) {
594 float pointsf= *points;
596 /* for some reason scaling fonts goes too fast compared to widget size */
597 aspect= sqrt(aspect);
601 *points= ceil(pointsf);
603 *points= floor(pointsf);
607 /* project button or block (but==NULL) to pixels in regionspace */
608 static void ui_but_to_pixelrect(rcti *rect, const ARegion *ar, uiBlock *block, uiBut *but)
611 float getsizex, getsizey;
616 gx= (but?but->x1:block->minx) + (block->panel?block->panel->ofsx:0.0f);
617 gy= (but?but->y1:block->miny) + (block->panel?block->panel->ofsy:0.0f);
619 rect->xmin= floor(getsizex*(0.5+ 0.5*(gx*block->winmat[0][0]+ gy*block->winmat[1][0]+ block->winmat[3][0])));
620 rect->ymin= floor(getsizey*(0.5+ 0.5*(gx*block->winmat[0][1]+ gy*block->winmat[1][1]+ block->winmat[3][1])));
622 gx= (but?but->x2:block->maxx) + (block->panel?block->panel->ofsx:0.0f);
623 gy= (but?but->y2:block->maxy) + (block->panel?block->panel->ofsy:0.0f);
625 rect->xmax= floor(getsizex*(0.5+ 0.5*(gx*block->winmat[0][0]+ gy*block->winmat[1][0]+ block->winmat[3][0])));
626 rect->ymax= floor(getsizey*(0.5+ 0.5*(gx*block->winmat[0][1]+ gy*block->winmat[1][1]+ block->winmat[3][1])));
630 /* uses local copy of style, to scale things down, and allow widgets to change stuff */
631 void uiDrawBlock(const bContext *C, uiBlock *block)
633 uiStyle style= *((uiStyle *)U.uistyles.first); // XXX pass on as arg
638 /* get menu region or area region */
641 ar= CTX_wm_region(C);
644 uiEndBlock(C, block);
646 /* we set this only once */
647 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
650 ui_fontscale(&style.paneltitle.points, block->aspect);
651 ui_fontscale(&style.grouplabel.points, block->aspect);
652 ui_fontscale(&style.widgetlabel.points, block->aspect);
653 ui_fontscale(&style.widget.points, block->aspect);
655 /* scale block min/max to rect */
656 ui_but_to_pixelrect(&rect, ar, block, NULL);
658 /* pixel space for AA widgets */
662 wmOrtho2(-0.01f, ar->winx-0.01f, -0.01f, ar->winy-0.01f);
665 if(block->flag & UI_BLOCK_LOOP)
666 ui_draw_menu_back(&style, block, &rect);
667 else if(block->panel)
668 ui_draw_aligned_panel(ar, &style, block, &rect);
671 for(but= block->buttons.first; but; but= but->next) {
672 ui_but_to_pixelrect(&rect, ar, block, but);
673 if(!(but->flag & UI_HIDDEN))
674 ui_draw_but(C, ar, &style, but, &rect);
680 ui_draw_links(block);
683 /* ************* EVENTS ************* */
685 static void ui_is_but_sel(uiBut *but)
689 short push=0, true=1;
691 value= ui_get_but_val(but);
693 if(ELEM3(but->type, TOGN, ICONTOGN, OPTIONN)) true= 0;
697 if( BTST(lvalue, (but->bitnr)) ) push= true;
706 if (value==-1) push= 1;
715 if(value!=but->hardmin) push= 1;
720 if(value==0.0) push= 1;
723 if(value == but->hardmax) push= 1;
735 else if(push==1) but->flag |= UI_SELECT;
736 else but->flag &= ~UI_SELECT;
739 /* XXX 2.50 no links supported yet */
741 static int uibut_contains_pt(uiBut *but, short *mval)
747 uiBut *ui_get_valid_link_button(uiBlock *block, uiBut *but, short *mval)
751 /* find button to link to */
752 for (bt= block->buttons.first; bt; bt= bt->next)
753 if(bt!=but && uibut_contains_pt(bt, mval))
757 if (but->type==LINK && bt->type==INLINK) {
758 if( but->link->tocode == (int)bt->hardmin ) {
762 else if(but->type==INLINK && bt->type==LINK) {
763 if( bt->link->tocode == (int)but->hardmin ) {
773 static uiBut *ui_find_inlink(uiBlock *block, void *poin)
777 but= block->buttons.first;
779 if(but->type==INLINK) {
780 if(but->poin == poin) return but;
787 static void ui_add_link_line(ListBase *listb, uiBut *but, uiBut *bt)
791 line= MEM_callocN(sizeof(uiLinkLine), "linkline");
792 BLI_addtail(listb, line);
797 uiBut *uiFindInlink(uiBlock *block, void *poin)
799 return ui_find_inlink(block, poin);
802 void uiComposeLinks(uiBlock *block)
809 but= block->buttons.first;
811 if(but->type==LINK) {
814 /* for all pointers in the array */
818 for(a=0; a < *(link->totlink); a++) {
819 bt= ui_find_inlink(block, (*ppoin)[a] );
821 ui_add_link_line(&link->lines, but, bt);
825 else if(link->poin) {
826 bt= ui_find_inlink(block, *(link->poin) );
828 ui_add_link_line(&link->lines, but, bt);
838 /* ************************************************ */
840 void uiBlockSetButLock(uiBlock *block, int val, char *lockstr)
844 block->lockstr= lockstr;
848 void uiBlockClearButLock(uiBlock *block)
851 block->lockstr= NULL;
854 /* *************************************************************** */
857 /* XXX 2.50 no links supported yet */
859 static void ui_delete_active_linkline(uiBlock *block)
863 uiLinkLine *line, *nline;
866 but= block->buttons.first;
868 if(but->type==LINK && but->link) {
869 line= but->link->lines.first;
874 if(line->flag & UI_SELECT) {
875 BLI_remlink(&but->link->lines, line);
877 link= line->from->link;
879 /* are there more pointers allowed? */
882 if(*(link->totlink)==1) {
884 MEM_freeN(*(link->ppoin));
885 *(link->ppoin)= NULL;
889 for(a=0; a< (*(link->totlink)); a++) {
891 if( (*(link->ppoin))[a] != line->to->poin ) {
892 (*(link->ppoin))[b]= (*(link->ppoin))[a];
896 (*(link->totlink))--;
911 /* temporal! these buttons can be everywhere... */
912 allqueue(REDRAWBUTSLOGIC, 0);
915 static void ui_do_active_linklines(uiBlock *block, short *mval)
918 uiLinkLine *line, *act= NULL;
919 float mindist= 12.0, fac, v1[2], v2[2], v3[3];
926 /* find a line close to the mouse */
927 but= block->buttons.first;
929 if(but->type==LINK && but->link) {
931 line= but->link->lines.first;
933 v2[0]= line->from->x2;
934 v2[1]= (line->from->y1+line->from->y2)/2.0;
936 v3[1]= (line->to->y1+line->to->y2)/2.0;
938 fac= PdistVL2Dfl(v1, v2, v3);
950 /* check for a 'found one' to prevent going to 'frontbuffer' mode.
951 this slows done gfx quite some, and at OSX the 'finish' forces a swapbuffer */
953 glDrawBuffer(GL_FRONT);
956 but= block->buttons.first;
958 if(but->type==LINK && but->link) {
959 line= but->link->lines.first;
962 if((line->flag & UI_SELECT)==0) {
963 line->flag |= UI_SELECT;
964 ui_draw_linkline(but, line);
967 else if(line->flag & UI_SELECT) {
968 line->flag &= ~UI_SELECT;
969 ui_draw_linkline(but, line);
977 glDrawBuffer(GL_BACK);
982 /* ******************************************************* */
984 /* XXX 2.50 no screendump supported yet */
987 /* nasty but safe way to store screendump rect */
988 static int scr_x=0, scr_y=0, scr_sizex=0, scr_sizey=0;
990 static void ui_set_screendump_bbox(uiBlock *block)
995 scr_sizex= block->maxx - block->minx;
996 scr_sizey= block->maxy - block->miny;
999 scr_sizex= scr_sizey= 0;
1003 /* used for making screenshots for menus, called in screendump.c */
1004 int uiIsMenu(int *x, int *y, int *sizex, int *sizey)
1006 if(scr_sizex!=0 && scr_sizey!=0) {
1018 /* *********************** data get/set ***********************
1019 * this either works with the pointed to data, or can work with
1020 * an edit override pointer while dragging for example */
1022 /* for buttons pointing to color for example */
1023 void ui_get_but_vectorf(uiBut *but, float *vec)
1029 VECCOPY(vec, but->editvec);
1036 vec[0]= vec[1]= vec[2]= 0.0f;
1038 if(RNA_property_type(prop) == PROP_FLOAT) {
1039 tot= RNA_property_array_length(prop);
1042 for(a=0; a<tot; a++)
1043 vec[a]= RNA_property_float_get_index(&but->rnapoin, prop, a);
1046 else if(but->pointype == CHA) {
1047 char *cp= (char *)but->poin;
1048 vec[0]= ((float)cp[0])/255.0;
1049 vec[1]= ((float)cp[1])/255.0;
1050 vec[2]= ((float)cp[2])/255.0;
1052 else if(but->pointype == FLO) {
1053 float *fp= (float *)but->poin;
1058 /* for buttons pointing to color for example */
1059 void ui_set_but_vectorf(uiBut *but, float *vec)
1065 VECCOPY(but->editvec, vec);
1072 if(RNA_property_type(prop) == PROP_FLOAT) {
1073 tot= RNA_property_array_length(prop);
1076 for(a=0; a<tot; a++)
1077 RNA_property_float_set_index(&but->rnapoin, prop, a, vec[a]);
1080 else if(but->pointype == CHA) {
1081 char *cp= (char *)but->poin;
1082 cp[0]= (char)(0.5 +vec[0]*255.0);
1083 cp[1]= (char)(0.5 +vec[1]*255.0);
1084 cp[2]= (char)(0.5 +vec[2]*255.0);
1086 else if(but->pointype == FLO) {
1087 float *fp= (float *)but->poin;
1092 int ui_is_but_float(uiBut *but)
1094 if(but->pointype==FLO && but->poin)
1097 if(but->rnaprop && RNA_property_type(but->rnaprop) == PROP_FLOAT)
1103 double ui_get_but_val(uiBut *but)
1108 if(but->editval) { return *(but->editval); }
1109 if(but->poin==NULL && but->rnapoin.data==NULL) return 0.0;
1114 switch(RNA_property_type(prop)) {
1116 if(RNA_property_array_length(prop))
1117 value= RNA_property_boolean_get_index(&but->rnapoin, prop, but->rnaindex);
1119 value= RNA_property_boolean_get(&but->rnapoin, prop);
1122 if(RNA_property_array_length(prop))
1123 value= RNA_property_int_get_index(&but->rnapoin, prop, but->rnaindex);
1125 value= RNA_property_int_get(&but->rnapoin, prop);
1128 if(RNA_property_array_length(prop))
1129 value= RNA_property_float_get_index(&but->rnapoin, prop, but->rnaindex);
1131 value= RNA_property_float_get(&but->rnapoin, prop);
1134 value= RNA_property_enum_get(&but->rnapoin, prop);
1141 else if(but->type== HSVSLI) {
1144 fp= (but->editvec)? but->editvec: (float *)but->poin;
1145 rgb_to_hsv(fp[0], fp[1], fp[2], &h, &s, &v);
1147 switch(but->str[0]) {
1148 case 'H': value= h; break;
1149 case 'S': value= s; break;
1150 case 'V': value= v; break;
1153 else if( but->pointype == CHA ) {
1154 value= *(char *)but->poin;
1156 else if( but->pointype == SHO ) {
1157 value= *(short *)but->poin;
1159 else if( but->pointype == INT ) {
1160 value= *(int *)but->poin;
1162 else if( but->pointype == FLO ) {
1163 value= *(float *)but->poin;
1169 void ui_set_but_val(uiBut *but, double value)
1173 /* value is a hsv value: convert to rgb */
1177 if(RNA_property_editable(&but->rnapoin, prop)) {
1178 switch(RNA_property_type(prop)) {
1180 if(RNA_property_array_length(prop))
1181 RNA_property_boolean_set_index(&but->rnapoin, prop, but->rnaindex, value);
1183 RNA_property_boolean_set(&but->rnapoin, prop, value);
1186 if(RNA_property_array_length(prop))
1187 RNA_property_int_set_index(&but->rnapoin, prop, but->rnaindex, value);
1189 RNA_property_int_set(&but->rnapoin, prop, value);
1192 if(RNA_property_array_length(prop))
1193 RNA_property_float_set_index(&but->rnapoin, prop, but->rnaindex, value);
1195 RNA_property_float_set(&but->rnapoin, prop, value);
1198 RNA_property_enum_set(&but->rnapoin, prop, value);
1205 else if(but->pointype==0);
1206 else if(but->type==HSVSLI ) {
1209 fp= (but->editvec)? but->editvec: (float *)but->poin;
1210 rgb_to_hsv(fp[0], fp[1], fp[2], &h, &s, &v);
1212 switch(but->str[0]) {
1213 case 'H': h= value; break;
1214 case 'S': s= value; break;
1215 case 'V': v= value; break;
1218 hsv_to_rgb(h, s, v, fp, fp+1, fp+2);
1222 /* first do rounding */
1223 if(but->pointype==CHA)
1224 value= (char)floor(value+0.5);
1225 else if(but->pointype==SHO ) {
1226 /* gcc 3.2.1 seems to have problems
1227 * casting a double like 32772.0 to
1228 * a short so we cast to an int, then
1231 gcckludge = (int) floor(value+0.5);
1232 value= (short)gcckludge;
1234 else if(but->pointype==INT )
1235 value= (int)floor(value+0.5);
1236 else if(but->pointype==FLO ) {
1237 float fval= (float)value;
1238 if(fval>= -0.00001f && fval<= 0.00001f) fval= 0.0f; /* prevent negative zero */
1242 /* then set value with possible edit override */
1244 *but->editval= value;
1245 else if(but->pointype==CHA)
1246 *((char *)but->poin)= (char)value;
1247 else if(but->pointype==SHO)
1248 *((short *)but->poin)= (short)value;
1249 else if(but->pointype==INT)
1250 *((int *)but->poin)= (int)value;
1251 else if(but->pointype==FLO)
1252 *((float *)but->poin)= (float)value;
1255 /* update select flag */
1259 int ui_get_but_string_max_length(uiBut *but)
1261 if(but->type == TEX)
1262 return but->hardmax;
1263 else if(but->type == IDPOIN)
1264 return sizeof(((ID*)NULL)->name)-2;
1266 return UI_MAX_DRAW_STR;
1269 void ui_get_but_string(uiBut *but, char *str, int maxlen)
1271 if(but->rnaprop && ELEM3(but->type, TEX, IDPOIN, SEARCH_MENU)) {
1275 type= RNA_property_type(but->rnaprop);
1277 if(type == PROP_STRING) {
1279 buf= RNA_property_string_get_alloc(&but->rnapoin, but->rnaprop, str, maxlen);
1281 else if(type == PROP_POINTER) {
1283 PointerRNA ptr= RNA_property_pointer_get(&but->rnapoin, but->rnaprop);
1284 buf= RNA_struct_name_get_alloc(&ptr, str, maxlen);
1288 BLI_strncpy(str, "", maxlen);
1290 else if(buf && buf != str) {
1291 /* string was too long, we have to truncate */
1292 BLI_strncpy(str, buf, maxlen);
1296 else if(but->type == IDPOIN) {
1298 ID *id= *(but->idpoin_idpp);
1300 if(id) BLI_strncpy(str, id->name+2, maxlen);
1301 else BLI_strncpy(str, "", maxlen);
1305 else if(but->type == TEX) {
1307 BLI_strncpy(str, but->poin, maxlen);
1310 else if(but->type == SEARCH_MENU) {
1312 BLI_strncpy(str, but->poin, maxlen);
1319 value= ui_get_but_val(but);
1321 if(ui_is_but_float(but)) {
1322 if(but->a2) { /* amount of digits defined */
1323 if(but->a2==1) BLI_snprintf(str, maxlen, "%.1f", value);
1324 else if(but->a2==2) BLI_snprintf(str, maxlen, "%.2f", value);
1325 else if(but->a2==3) BLI_snprintf(str, maxlen, "%.3f", value);
1326 else BLI_snprintf(str, maxlen, "%.4f", value);
1329 BLI_snprintf(str, maxlen, "%.3f", value);
1332 BLI_snprintf(str, maxlen, "%d", (int)value);
1336 int ui_set_but_string(bContext *C, uiBut *but, const char *str)
1338 if(but->rnaprop && ELEM3(but->type, TEX, IDPOIN, SEARCH_MENU)) {
1339 if(RNA_property_editable(&but->rnapoin, but->rnaprop)) {
1342 type= RNA_property_type(but->rnaprop);
1344 if(type == PROP_STRING) {
1346 RNA_property_string_set(&but->rnapoin, but->rnaprop, str);
1349 else if(type == PROP_POINTER) {
1351 PointerRNA ptr, rptr;
1354 if(str == NULL || str[0] == '\0') {
1355 RNA_property_pointer_set(&but->rnapoin, but->rnaprop, PointerRNA_NULL);
1359 ptr= but->rnasearchpoin;
1360 prop= but->rnasearchprop;
1362 if(prop && RNA_property_collection_lookup_string(&ptr, prop, str, &rptr))
1363 RNA_property_pointer_set(&but->rnapoin, but->rnaprop, rptr);
1372 else if(but->type == IDPOIN) {
1374 but->idpoin_func(C, (char*)str, but->idpoin_idpp);
1377 else if(but->type == TEX) {
1379 BLI_strncpy(but->poin, str, but->hardmax);
1382 else if(but->type == SEARCH_MENU) {
1384 BLI_strncpy(but->poin, str, but->hardmax);
1390 /* XXX 2.50 missing python api */
1392 if(BPY_button_eval(str, &value)) {
1393 BKE_report(CTX_reports(C), RPT_WARNING, "Invalid Python expression, check console");
1394 value = 0.0f; /* Zero out value on error */
1403 if(!ui_is_but_float(but)) value= (int)value;
1404 if(but->type==NUMABS) value= fabs(value);
1406 /* not that we use hard limits here */
1407 if(value<but->hardmin) value= but->hardmin;
1408 if(value>but->hardmax) value= but->hardmax;
1410 ui_set_but_val(but, value);
1417 static double soft_range_round_up(double value, double max)
1419 /* round up to .., 0.1, 0.2, 0.5, 1, 2, 5, 10, 20, 50, .. */
1420 double newmax= pow(10.0, ceil(log(value)/log(10.0)));
1422 if(newmax*0.2 >= max && newmax*0.2 >= value)
1424 else if(newmax*0.5 >= max && newmax*0.5 >= value)
1430 static double soft_range_round_down(double value, double max)
1432 /* round down to .., 0.1, 0.2, 0.5, 1, 2, 5, 10, 20, 50, .. */
1433 double newmax= pow(10.0, floor(log(value)/log(10.0)));
1435 if(newmax*5.0 <= max && newmax*5.0 <= value)
1437 else if(newmax*2.0 <= max && newmax*2.0 <= value)
1443 void ui_set_but_soft_range(uiBut *but, double value)
1446 double softmin, softmax, step, precision;
1449 type= RNA_property_type(but->rnaprop);
1451 if(type == PROP_INT) {
1452 int imin, imax, istep;
1454 RNA_property_int_ui_range(&but->rnapoin, but->rnaprop, &imin, &imax, &istep);
1460 else if(type == PROP_FLOAT) {
1461 float fmin, fmax, fstep, fprecision;
1463 RNA_property_float_ui_range(&but->rnapoin, but->rnaprop, &fmin, &fmax, &fstep, &fprecision);
1467 precision= fprecision;
1472 /* clamp button range to something reasonable in case
1473 * we get -inf/inf from RNA properties */
1474 softmin= MAX2(softmin, -1e4);
1475 softmax= MIN2(softmax, 1e4);
1477 /* if the value goes out of the soft/max range, adapt the range */
1478 if(value+1e-10 < softmin) {
1480 softmin= -soft_range_round_up(-value, -softmin);
1482 softmin= soft_range_round_down(value, softmin);
1484 if(softmin < but->hardmin)
1485 softmin= but->hardmin;
1487 else if(value-1e-10 > softmax) {
1489 softmax= -soft_range_round_down(-value, -softmax);
1491 softmax= soft_range_round_up(value, softmax);
1493 if(softmax > but->hardmax)
1494 softmax= but->hardmax;
1497 but->softmin= softmin;
1498 but->softmax= softmax;
1502 /* ******************* Free ********************/
1504 static void ui_free_link(uiLink *link)
1507 BLI_freelistN(&link->lines);
1512 /* can be called with C==NULL */
1513 static void ui_free_but(const bContext *C, uiBut *but)
1516 WM_operator_properties_free(but->opptr);
1517 MEM_freeN(but->opptr);
1519 if(but->func_argN) MEM_freeN(but->func_argN);
1521 /* XXX solve later, buttons should be free-able without context? */
1523 ui_button_active_cancel(C, but);
1526 MEM_freeN(but->active);
1528 if(but->str && but->str != but->strdata) MEM_freeN(but->str);
1529 ui_free_link(but->link);
1534 /* can be called with C==NULL */
1535 void uiFreeBlock(const bContext *C, uiBlock *block)
1539 while( (but= block->buttons.first) ) {
1540 BLI_remlink(&block->buttons, but);
1541 ui_free_but(C, but);
1544 CTX_store_free_list(&block->contexts);
1546 BLI_freelistN(&block->saferct);
1551 /* can be called with C==NULL */
1552 void uiFreeBlocks(const bContext *C, ListBase *lb)
1556 while( (block= lb->first) ) {
1557 BLI_remlink(lb, block);
1558 uiFreeBlock(C, block);
1562 void uiFreeInactiveBlocks(const bContext *C, ListBase *lb)
1564 uiBlock *block, *nextblock;
1566 for(block=lb->first; block; block=nextblock) {
1567 nextblock= block->next;
1569 if(!block->handle) {
1570 if(!block->active) {
1571 BLI_remlink(lb, block);
1572 uiFreeBlock(C, block);
1580 void uiBlockSetRegion(uiBlock *block, ARegion *region)
1583 uiBlock *oldblock= NULL;
1585 lb= ®ion->uiblocks;
1587 /* each listbase only has one block with this name, free block
1588 * if is already there so it can be rebuilt from scratch */
1590 for (oldblock= lb->first; oldblock; oldblock= oldblock->next)
1591 if (BLI_streq(oldblock->name, block->name))
1595 oldblock->active= 0;
1596 oldblock->panel= NULL;
1600 block->oldblock= oldblock;
1602 /* at the beginning of the list! for dynamical menus/blocks */
1604 BLI_addhead(lb, block);
1607 uiBlock *uiBeginBlock(const bContext *C, ARegion *region, const char *name, short dt)
1611 int getsizex, getsizey;
1613 window= CTX_wm_window(C);
1615 block= MEM_callocN(sizeof(uiBlock), "uiBlock");
1618 BLI_strncpy(block->name, name, sizeof(block->name));
1621 uiBlockSetRegion(block, region);
1623 /* window matrix and aspect */
1624 if(region && region->swinid) {
1625 wm_subwindow_getmatrix(window, region->swinid, block->winmat);
1626 wm_subwindow_getsize(window, region->swinid, &getsizex, &getsizey);
1628 /* TODO - investigate why block->winmat[0][0] is negative
1629 * in the image view when viewRedrawForce is called */
1630 block->aspect= 2.0/fabs( (getsizex)*block->winmat[0][0]);
1633 /* no subwindow created yet, for menus for example, so we
1634 * use the main window instead, since buttons are created
1636 wm_subwindow_getmatrix(window, window->screen->mainwin, block->winmat);
1637 wm_subwindow_getsize(window, window->screen->mainwin, &getsizex, &getsizey);
1639 block->aspect= 2.0/fabs(getsizex*block->winmat[0][0]);
1640 block->auto_open= 2;
1641 block->flag |= UI_BLOCK_LOOP; /* tag as menu */
1647 uiBlock *uiGetBlock(char *name, ARegion *ar)
1649 uiBlock *block= ar->uiblocks.first;
1652 if( strcmp(name, block->name)==0 ) return block;
1659 void uiBlockSetEmboss(uiBlock *block, short dt)
1664 void ui_check_but(uiBut *but)
1666 /* if something changed in the button */
1669 // int transopts= ui_translate_buttons();
1673 // if(but->type==TEX || but->type==IDPOIN) transopts= 0;
1675 /* test for min and max, icon sliders, etc */
1676 switch( but->type ) {
1682 value= ui_get_but_val(but);
1683 if(value < but->hardmin) ui_set_but_val(but, but->hardmin);
1684 else if(value > but->hardmax) ui_set_but_val(but, but->hardmax);
1688 value= fabs( ui_get_but_val(but) );
1689 if(value < but->hardmin) ui_set_but_val(but, but->hardmin);
1690 else if(value > but->hardmax) ui_set_but_val(but, but->hardmax);
1695 if(!but->rnaprop || (RNA_property_flag(but->rnaprop) & PROP_ICONS_CONSECUTIVE)) {
1696 if(but->flag & UI_SELECT) but->iconadd= 1;
1697 else but->iconadd= 0;
1702 if(!but->rnaprop || (RNA_property_flag(but->rnaprop) & PROP_ICONS_CONSECUTIVE)) {
1703 value= ui_get_but_val(but);
1704 but->iconadd= (int)value- (int)(but->hardmin);
1709 if(!but->rnaprop || (RNA_property_flag(but->rnaprop) & PROP_ICONS_CONSECUTIVE)) {
1710 value= ui_get_but_val(but);
1711 but->iconadd= (int)value- (int)(but->hardmin);
1717 /* safety is 4 to enable small number buttons (like 'users') */
1718 okwidth= -4 + (but->x2 - but->x1);
1721 switch( but->type ) {
1726 if(but->x2 - but->x1 > 24) {
1727 value= ui_get_but_val(but);
1728 ui_set_name_menu(but, (int)value);
1737 value= ui_get_but_val(but);
1739 if(ui_is_but_float(but)) {
1740 if(value == FLT_MAX) sprintf(but->drawstr, "%sinf", but->str);
1741 else if(value == -FLT_MAX) sprintf(but->drawstr, "%s-inf", but->str);
1742 else if(but->a2) { /* amount of digits defined */
1743 if(but->a2==1) sprintf(but->drawstr, "%s%.1f", but->str, value);
1744 else if(but->a2==2) sprintf(but->drawstr, "%s%.2f", but->str, value);
1745 else if(but->a2==3) sprintf(but->drawstr, "%s%.3f", but->str, value);
1746 else sprintf(but->drawstr, "%s%.4f", but->str, value);
1749 if(but->hardmax<10.001) sprintf(but->drawstr, "%s%.3f", but->str, value);
1750 else sprintf(but->drawstr, "%s%.2f", but->str, value);
1754 sprintf(but->drawstr, "%s%d", but->str, (int)value);
1758 PropertySubType pstype = RNA_property_subtype(but->rnaprop);
1760 if (pstype == PROP_PERCENTAGE)
1761 strcat(but->drawstr, "%");
1766 if(ui_is_but_float(but)) {
1767 value= ui_get_but_val(but);
1768 if(but->a2) { /* amount of digits defined */
1769 if(but->a2==1) sprintf(but->drawstr, "%s%.1f", but->str, value);
1770 else if(but->a2==2) sprintf(but->drawstr, "%s%.2f", but->str, value);
1771 else if(but->a2==3) sprintf(but->drawstr, "%s%.3f", but->str, value);
1772 else sprintf(but->drawstr, "%s%.4f", but->str, value);
1775 sprintf(but->drawstr, "%s%.2f", but->str, value);
1778 else strcpy(but->drawstr, but->str);
1786 char str[UI_MAX_DRAW_STR];
1788 ui_get_but_string(but, str, UI_MAX_DRAW_STR-strlen(but->str));
1790 strcpy(but->drawstr, but->str);
1791 strcat(but->drawstr, str);
1796 strcpy(but->drawstr, but->str);
1797 if (but->flag & UI_SELECT) {
1798 strcat(but->drawstr, "Press a key");
1800 strcat(but->drawstr, WM_key_event_string((short) ui_get_but_val(but)));
1805 /* trying to get the dual-icon to left of text... not very nice */
1807 strcpy(but->drawstr, " ");
1808 strcpy(but->drawstr+2, but->str);
1812 strcpy(but->drawstr, but->str);
1816 /* if we are doing text editing, this will override the drawstr */
1818 strcpy(but->drawstr, but->str);
1819 strcat(but->drawstr, but->editstr);
1822 /* text clipping moved to widget drawing code itself */
1826 void uiBlockBeginAlign(uiBlock *block)
1828 /* if other align was active, end it */
1829 if(block->flag & UI_BUT_ALIGN) uiBlockEndAlign(block);
1831 block->flag |= UI_BUT_ALIGN_DOWN;
1834 /* buttons declared after this call will get this align nr */ // XXX flag?
1837 static int buts_are_horiz(uiBut *but1, uiBut *but2)
1841 dx= fabs( but1->x2 - but2->x1);
1842 dy= fabs( but1->y1 - but2->y2);
1844 if(dx > dy) return 0;
1848 void uiBlockEndAlign(uiBlock *block)
1850 block->flag &= ~UI_BUT_ALIGN; // all 4 flags
1853 int ui_but_can_align(uiBut *but)
1855 return !ELEM3(but->type, LABEL, OPTION, OPTIONN);
1858 static void ui_block_do_align_but(uiBlock *block, uiBut *first, int nr)
1860 uiBut *prev, *but=NULL, *next;
1861 int flag= 0, cols=0, rows=0;
1865 for(but=first; but && but->alignnr == nr; but=but->next) {
1866 if(but->next && but->next->alignnr == nr) {
1867 if(buts_are_horiz(but, but->next)) cols++;
1872 /* rows==0: 1 row, cols==0: 1 collumn */
1874 /* note; how it uses 'flag' in loop below (either set it, or OR it) is confusing */
1875 for(but=first, prev=NULL; but && but->alignnr == nr; prev=but, but=but->next) {
1877 if(next && next->alignnr != nr)
1880 /* clear old flag */
1881 but->flag &= ~UI_BUT_ALIGN;
1883 if(flag==0) { /* first case */
1885 if(buts_are_horiz(but, next)) {
1887 flag= UI_BUT_ALIGN_RIGHT;
1889 flag= UI_BUT_ALIGN_DOWN|UI_BUT_ALIGN_RIGHT;
1892 flag= UI_BUT_ALIGN_DOWN;
1896 else if(next==NULL) { /* last case */
1898 if(buts_are_horiz(prev, but)) {
1900 flag= UI_BUT_ALIGN_LEFT;
1902 flag= UI_BUT_ALIGN_TOP|UI_BUT_ALIGN_LEFT;
1904 else flag= UI_BUT_ALIGN_TOP;
1907 else if(buts_are_horiz(but, next)) {
1908 /* check if this is already second row */
1909 if( prev && buts_are_horiz(prev, but)==0) {
1910 flag &= ~UI_BUT_ALIGN_LEFT;
1911 flag |= UI_BUT_ALIGN_TOP;
1912 /* exception case: bottom row */
1915 while(bt && bt->alignnr == nr) {
1916 if(bt->next && bt->next->alignnr == nr && buts_are_horiz(bt, bt->next)==0 ) break;
1919 if(bt==0 || bt->alignnr != nr) flag= UI_BUT_ALIGN_TOP|UI_BUT_ALIGN_RIGHT;
1922 else flag |= UI_BUT_ALIGN_LEFT;
1926 flag |= UI_BUT_ALIGN_TOP;
1928 else { /* next button switches to new row */
1930 if(prev && buts_are_horiz(prev, but))
1931 flag |= UI_BUT_ALIGN_LEFT;
1933 if( (flag & UI_BUT_ALIGN_TOP)==0) { /* stil top row */
1935 flag= UI_BUT_ALIGN_DOWN|UI_BUT_ALIGN_LEFT;
1937 flag |= UI_BUT_ALIGN_DOWN;
1940 flag |= UI_BUT_ALIGN_TOP;
1946 /* merge coordinates */
1950 but->x1= (prev->x2+but->x1)/2.0;
1954 but->y2= (prev->y1+but->y2)/2.0;
1958 if(buts_are_horiz(prev, but)) {
1959 but->x1= (prev->x2+but->x1)/2.0;
1961 /* copy height too */
1964 else if(prev->prev && buts_are_horiz(prev->prev, prev)==0) {
1965 /* the previous button is a single one in its row */
1966 but->y2= (prev->y1+but->y2)/2.0;
1970 /* the previous button is not a single one in its row */
1978 void ui_block_do_align(uiBlock *block)
1983 /* align buttons with same align nr */
1984 for(but=block->buttons.first; but;) {
1987 ui_block_do_align_but(block, but, nr);
1989 /* skip with same number */
1990 for(; but && but->alignnr == nr; but=but->next);
2001 ui_def_but is the function that draws many button types
2004 "a1" Click Step (how much to change the value each click)
2005 "a2" Number of decimal point values to display. 0 defaults to 3 (0.000) 1,2,3, and a maximum of 4,
2006 all greater values will be clamped to 4.
2009 static uiBut *ui_def_but(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)
2014 if(type & BUTPOIN) { /* a pointer is required */
2019 but= MEM_callocN(sizeof(uiBut), "uiBut");
2021 but->type= type & BUTTYPE;
2022 but->pointype= type & BUTPOIN;
2023 but->bit= type & BIT;
2024 but->bitnr= type & 31;
2027 but->retval= retval;
2028 if( strlen(str)>=UI_MAX_NAME_STR-1 ) {
2029 but->str= MEM_callocN( strlen(str)+2, "uiDefBut");
2030 strcpy(but->str, str);
2033 but->str= but->strdata;
2034 strcpy(but->str, str);
2042 but->hardmin= but->softmin= min;
2043 but->hardmax= but->softmax= max;
2048 but->lock= block->lock;
2049 but->lockstr= block->lockstr;
2052 but->aspect= 1.0f; //XXX block->aspect;
2053 but->block= block; // pointer back, used for frontbuffer status, and picker
2055 if((block->flag & UI_BUT_ALIGN) && ui_but_can_align(but))
2056 but->alignnr= block->alignnr;
2058 but->func= block->func;
2059 but->func_arg1= block->func_arg1;
2060 but->func_arg2= block->func_arg2;
2062 but->pos= -1; /* cursor invisible */
2064 if(ELEM(but->type, NUM, NUMABS)) { /* add a space to name */
2065 slen= strlen(but->str);
2066 if(slen>0 && slen<UI_MAX_NAME_STR-2) {
2067 if(but->str[slen-1]!=' ') {
2068 but->str[slen]= ' ';
2069 but->str[slen+1]= 0;
2074 if(ELEM(but->type, HSVCUBE, HSVCIRCLE)) { /* hsv buttons temp storage */
2076 ui_get_but_vectorf(but, rgb);
2077 rgb_to_hsv(rgb[0], rgb[1], rgb[2], but->hsv, but->hsv+1, but->hsv+2);
2080 if((block->flag & UI_BLOCK_LOOP) || ELEM7(but->type, MENU, TEX, LABEL, IDPOIN, BLOCK, BUTM, SEARCH_MENU))
2081 but->flag |= (UI_TEXT_LEFT|UI_ICON_LEFT);
2082 else if(but->type==BUT_TOGDUAL)
2083 but->flag |= UI_ICON_LEFT;
2085 but->flag |= (block->flag & UI_BUT_ALIGN);
2089 but->flag |= UI_BUT_DISABLED;
2093 BLI_addtail(&block->buttons, but);
2095 if(block->curlayout)
2096 ui_layout_add_but(block->curlayout, but);
2101 uiBut *ui_def_but_rna(uiBlock *block, int type, int retval, char *str, short x1, short y1, short x2, short y2, PointerRNA *ptr, const char *propname, int index, float min, float max, float a1, float a2, char *tip)
2105 PropertyType proptype;
2106 int freestr= 0, icon= 0;
2108 prop= RNA_struct_find_property(ptr, propname);
2111 proptype= RNA_property_type(prop);
2113 /* use rna values if parameters are not specified */
2115 if(type == MENU && proptype == PROP_ENUM) {
2116 const EnumPropertyItem *item;
2118 int i, totitem, value;
2120 RNA_property_enum_items(ptr, prop, &item, &totitem);
2121 value= RNA_property_enum_get(ptr, prop);
2123 dynstr= BLI_dynstr_new();
2124 BLI_dynstr_appendf(dynstr, "%s%%t", RNA_property_ui_name(prop));
2125 for(i=0; i<totitem; i++) {
2127 BLI_dynstr_appendf(dynstr, "|%s %%i%d %%x%d", item[i].name, item[i].icon, item[i].value);
2129 BLI_dynstr_appendf(dynstr, "|%s %%x%d", item[i].name, item[i].value);
2131 if(value == item[i].value)
2134 str= BLI_dynstr_get_cstring(dynstr);
2135 BLI_dynstr_free(dynstr);
2139 else if(type == ROW && proptype == PROP_ENUM) {
2140 const EnumPropertyItem *item;
2143 RNA_property_enum_items(ptr, prop, &item, &totitem);
2144 for(i=0; i<totitem; i++) {
2145 if(item[i].value == (int)max) {
2146 str= (char*)item[i].name;
2152 str= (char*)RNA_property_ui_name(prop);
2155 str= (char*)RNA_property_ui_name(prop);
2156 icon= RNA_property_ui_icon(prop);
2161 if(type == ROW && proptype == PROP_ENUM) {
2162 const EnumPropertyItem *item;
2165 RNA_property_enum_items(ptr, prop, &item, &totitem);
2167 for(i=0; i<totitem; i++) {
2168 if(item[i].value == (int)max) {
2169 if(item[i].description[0])
2170 tip= (char*)item[i].description;
2178 tip= (char*)RNA_property_ui_description(prop);
2180 if(min == max || a1 == -1 || a2 == -1) {
2181 if(proptype == PROP_INT) {
2182 int hardmin, hardmax, softmin, softmax, step;
2184 RNA_property_int_range(ptr, prop, &hardmin, &hardmax);
2185 RNA_property_int_ui_range(ptr, prop, &softmin, &softmax, &step);
2187 if(type != ROW && min == max) {
2196 else if(proptype == PROP_FLOAT) {
2197 float hardmin, hardmax, softmin, softmax, step, precision;
2199 RNA_property_float_range(ptr, prop, &hardmin, &hardmax);
2200 RNA_property_float_ui_range(ptr, prop, &softmin, &softmax, &step, &precision);
2202 if(type != ROW && min == max) {
2211 else if(proptype == PROP_STRING) {
2213 max= RNA_property_string_maxlength(prop);
2214 if(max == 0) /* interface code should ideally support unlimited length */
2215 max= UI_MAX_DRAW_STR;
2220 str= (char*)propname;
2222 /* now create button */
2223 but= ui_def_but(block, type, retval, str, x1, y1, x2, y2, NULL, min, max, a1, a2, tip);
2229 if(RNA_property_array_length(but->rnaprop))
2230 but->rnaindex= index;
2236 but->icon= (BIFIconID)icon;
2237 but->flag |= UI_HAS_ICON;
2238 but->flag|= UI_ICON_LEFT;
2241 if (!prop || !RNA_property_editable(&but->rnapoin, prop)) {
2242 but->flag |= UI_BUT_DISABLED;
2253 uiBut *ui_def_but_operator(uiBlock *block, int type, char *opname, int opcontext, char *str, short x1, short y1, short x2, short y2, char *tip)
2258 ot= WM_operatortype_find(opname);
2261 if(ot) str= ot->name;
2265 if ((!tip || tip[0]=='\0') && ot && ot->description) {
2266 tip= ot->description;
2269 but= ui_def_but(block, type, -1, str, x1, y1, x2, y2, NULL, 0, 0, 0, 0, tip);
2271 but->opcontext= opcontext;
2274 but->flag |= UI_BUT_DISABLED;
2282 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)
2284 uiBut *but= ui_def_but(block, type, retval, str, x1, y1, x2, y2, poin, min, max, a1, a2, tip);
2291 /* if _x_ is a power of two (only one bit) return the power,
2292 * otherwise return -1.
2293 * (1<<findBitIndex(x))==x for powers of two.
2295 static int findBitIndex(unsigned int x) {
2296 if (!x || (x&(x-1))!=0) { /* x&(x-1) strips lowest bit */
2301 if (x&0xFFFF0000) idx+=16, x>>=16;
2302 if (x&0xFF00) idx+=8, x>>=8;
2303 if (x&0xF0) idx+=4, x>>=4;
2304 if (x&0xC) idx+=2, x>>=2;
2311 /* autocomplete helper functions */
2312 struct AutoComplete {
2318 AutoComplete *autocomplete_begin(char *startname, int maxlen)
2320 AutoComplete *autocpl;
2322 autocpl= MEM_callocN(sizeof(AutoComplete), "AutoComplete");
2323 autocpl->maxlen= maxlen;
2324 autocpl->truncate= MEM_callocN(sizeof(char)*maxlen, "AutoCompleteTruncate");
2325 autocpl->startname= startname;
2330 void autocomplete_do_name(AutoComplete *autocpl, const char *name)
2332 char *truncate= autocpl->truncate;
2333 char *startname= autocpl->startname;
2336 for(a=0; a<autocpl->maxlen-1; a++) {
2337 if(startname[a]==0 || startname[a]!=name[a])
2341 if(startname[a]==0) {
2344 BLI_strncpy(truncate, name, autocpl->maxlen);
2346 /* remove from truncate what is not in bone->name */
2347 for(a=0; a<autocpl->maxlen-1; a++) {
2352 else if(truncate[a]!=name[a])
2359 void autocomplete_end(AutoComplete *autocpl, char *autoname)
2361 if(autocpl->truncate[0])
2362 BLI_strncpy(autoname, autocpl->truncate, autocpl->maxlen);
2364 if (autoname != autocpl->startname) /* dont copy a string over its self */
2365 BLI_strncpy(autoname, autocpl->startname, autocpl->maxlen);
2367 MEM_freeN(autocpl->truncate);
2371 /* autocomplete callback for ID buttons */
2372 static void autocomplete_id(bContext *C, char *str, void *arg_v)
2374 int blocktype= (intptr_t)arg_v;
2375 ListBase *listb= wich_libbase(CTX_data_main(C), blocktype);
2377 if(listb==NULL) return;
2379 /* search if str matches the beginning of an ID struct */
2381 AutoComplete *autocpl= autocomplete_begin(str, 22);
2384 for(id= listb->first; id; id= id->next)
2385 autocomplete_do_name(autocpl, id->name+2);
2387 autocomplete_end(autocpl, str);
2391 static uiBut *uiDefButBit(uiBlock *block, int type, int bit, int retval, char *str, short x1, short y1, short x2, short y2, void *poin, float min, float max, float a1, float a2, char *tip)
2393 int bitIdx= findBitIndex(bit);
2397 return uiDefBut(block, type|BIT|bitIdx, retval, str, x1, y1, x2, y2, poin, min, max, a1, a2, tip);
2400 uiBut *uiDefButF(uiBlock *block, int type, int retval, char *str, short x1, short y1, short x2, short y2, float *poin, float min, float max, float a1, float a2, char *tip)
2402 return uiDefBut(block, type|FLO, retval, str, x1, y1, x2, y2, (void*) poin, min, max, a1, a2, tip);
2404 uiBut *uiDefButBitF(uiBlock *block, int type, int bit, int retval, char *str, short x1, short y1, short x2, short y2, float *poin, float min, float max, float a1, float a2, char *tip)
2406 return uiDefButBit(block, type|FLO, bit, retval, str, x1, y1, x2, y2, (void*) poin, min, max, a1, a2, tip);
2408 uiBut *uiDefButI(uiBlock *block, int type, int retval, char *str, short x1, short y1, short x2, short y2, int *poin, float min, float max, float a1, float a2, char *tip)
2410 return uiDefBut(block, type|INT, retval, str, x1, y1, x2, y2, (void*) poin, min, max, a1, a2, tip);
2412 uiBut *uiDefButBitI(uiBlock *block, int type, int bit, int retval, char *str, short x1, short y1, short x2, short y2, int *poin, float min, float max, float a1, float a2, char *tip)
2414 return uiDefButBit(block, type|INT, bit, retval, str, x1, y1, x2, y2, (void*) poin, min, max, a1, a2, tip);
2416 uiBut *uiDefButS(uiBlock *block, int type, int retval, char *str, short x1, short y1, short x2, short y2, short *poin, float min, float max, float a1, float a2, char *tip)
2418 return uiDefBut(block, type|SHO, retval, str, x1, y1, x2, y2, (void*) poin, min, max, a1, a2, tip);
2420 uiBut *uiDefButBitS(uiBlock *block, int type, int bit, int retval, char *str, short x1, short y1, short x2, short y2, short *poin, float min, float max, float a1, float a2, char *tip)
2422 return uiDefButBit(block, type|SHO, bit, retval, str, x1, y1, x2, y2, (void*) poin, min, max, a1, a2, tip);
2424 uiBut *uiDefButC(uiBlock *block, int type, int retval, char *str, short x1, short y1, short x2, short y2, char *poin, float min, float max, float a1, float a2, char *tip)
2426 return uiDefBut(block, type|CHA, retval, str, x1, y1, x2, y2, (void*) poin, min, max, a1, a2, tip);
2428 uiBut *uiDefButBitC(uiBlock *block, int type, int bit, int retval, char *str, short x1, short y1, short x2, short y2, char *poin, float min, float max, float a1, float a2, char *tip)
2430 return uiDefButBit(block, type|CHA, bit, retval, str, x1, y1, x2, y2, (void*) poin, min, max, a1, a2, tip);
2432 uiBut *uiDefButR(uiBlock *block, int type, int retval, char *str, short x1, short y1, short x2, short y2, PointerRNA *ptr, const char *propname, int index, float min, float max, float a1, float a2, char *tip)
2436 but= ui_def_but_rna(block, type, retval, str, x1, y1, x2, y2, ptr, propname, index, min, max, a1, a2, tip);
2442 uiBut *uiDefButO(uiBlock *block, int type, char *opname, int opcontext, char *str, short x1, short y1, short x2, short y2, char *tip)
2446 but= ui_def_but_operator(block, type, opname, opcontext, str, x1, y1, x2, y2, tip);
2453 uiBut *uiDefIconBut(uiBlock *block, int type, int retval, int icon, short x1, short y1, short x2, short y2, void *poin, float min, float max, float a1, float a2, char *tip)
2455 uiBut *but= ui_def_but(block, type, retval, "", x1, y1, x2, y2, poin, min, max, a1, a2, tip);
2457 but->icon= (BIFIconID) icon;
2458 but->flag|= UI_HAS_ICON;
2464 static uiBut *uiDefIconButBit(uiBlock *block, int type, int bit, int retval, int icon, short x1, short y1, short x2, short y2, void *poin, float min, float max, float a1, float a2, char *tip)
2466 int bitIdx= findBitIndex(bit);
2470 return uiDefIconBut(block, type|BIT|bitIdx, retval, icon, x1, y1, x2, y2, poin, min, max, a1, a2, tip);
2474 uiBut *uiDefIconButF(uiBlock *block, int type, int retval, int icon, short x1, short y1, short x2, short y2, float *poin, float min, float max, float a1, float a2, char *tip)
2476 return uiDefIconBut(block, type|FLO, retval, icon, x1, y1, x2, y2, (void*) poin, min, max, a1, a2, tip);
2478 uiBut *uiDefIconButBitF(uiBlock *block, int type, int bit, int retval, int icon, short x1, short y1, short x2, short y2, float *poin, float min, float max, float a1, float a2, char *tip)
2480 return uiDefIconButBit(block, type|FLO, bit, retval, icon, x1, y1, x2, y2, (void*) poin, min, max, a1, a2, tip);
2482 uiBut *uiDefIconButI(uiBlock *block, int type, int retval, int icon, short x1, short y1, short x2, short y2, int *poin, float min, float max, float a1, float a2, char *tip)
2484 return uiDefIconBut(block, type|INT, retval, icon, x1, y1, x2, y2, (void*) poin, min, max, a1, a2, tip);
2486 uiBut *uiDefIconButBitI(uiBlock *block, int type, int bit, int retval, int icon, short x1, short y1, short x2, short y2, int *poin, float min, float max, float a1, float a2, char *tip)
2488 return uiDefIconButBit(block, type|INT, bit, retval, icon, x1, y1, x2, y2, (void*) poin, min, max, a1, a2, tip);
2490 uiBut *uiDefIconButS(uiBlock *block, int type, int retval, int icon, short x1, short y1, short x2, short y2, short *poin, float min, float max, float a1, float a2, char *tip)
2492 return uiDefIconBut(block, type|SHO, retval, icon, x1, y1, x2, y2, (void*) poin, min, max, a1, a2, tip);
2494 uiBut *uiDefIconButBitS(uiBlock *block, int type, int bit, int retval, int icon, short x1, short y1, short x2, short y2, short *poin, float min, float max, float a1, float a2, char *tip)
2496 return uiDefIconButBit(block, type|SHO, bit, retval, icon, x1, y1, x2, y2, (void*) poin, min, max, a1, a2, tip);
2498 uiBut *uiDefIconButC(uiBlock *block, int type, int retval, int icon, short x1, short y1, short x2, short y2, char *poin, float min, float max, float a1, float a2, char *tip)
2500 return uiDefIconBut(block, type|CHA, retval, icon, x1, y1, x2, y2, (void*) poin, min, max, a1, a2, tip);
2502 uiBut *uiDefIconButBitC(uiBlock *block, int type, int bit, int retval, int icon, short x1, short y1, short x2, short y2, char *poin, float min, float max, float a1, float a2, char *tip)
2504 return uiDefIconButBit(block, type|CHA, bit, retval, icon, x1, y1, x2, y2, (void*) poin, min, max, a1, a2, tip);
2506 uiBut *uiDefIconButR(uiBlock *block, int type, int retval, int icon, short x1, short y1, short x2, short y2, PointerRNA *ptr, const char *propname, int index, float min, float max, float a1, float a2, char *tip)
2510 but= ui_def_but_rna(block, type, retval, "", x1, y1, x2, y2, ptr, propname, index, min, max, a1, a2, tip);
2513 but->icon= (BIFIconID) icon;
2514 but->flag|= UI_HAS_ICON;
2521 uiBut *uiDefIconButO(uiBlock *block, int type, char *opname, int opcontext, int icon, short x1, short y1, short x2, short y2, char *tip)
2525 but= ui_def_but_operator(block, type, opname, opcontext, "", x1, y1, x2, y2, tip);
2527 but->icon= (BIFIconID) icon;
2528 but->flag|= UI_HAS_ICON;
2535 /* Button containing both string label and icon */
2536 uiBut *uiDefIconTextBut(uiBlock *block, int type, int retval, int icon, char *str, short x1, short y1, short x2, short y2, void *poin, float min, float max, float a1, float a2, char *tip)
2538 uiBut *but= ui_def_but(block, type, retval, str, x1, y1, x2, y2, poin, min, max, a1, a2, tip);
2540 but->icon= (BIFIconID) icon;
2541 but->flag|= UI_HAS_ICON;
2543 but->flag|= UI_ICON_LEFT;
2549 static uiBut *uiDefIconTextButBit(uiBlock *block, int type, int bit, int retval, int icon, char *str, short x1, short y1, short x2, short y2, void *poin, float min, float max, float a1, float a2, char *tip)
2551 int bitIdx= findBitIndex(bit);
2555 return uiDefIconTextBut(block, type|BIT|bitIdx, retval, icon, str, x1, y1, x2, y2, poin, min, max, a1, a2, tip);
2559 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)
2561 return uiDefIconTextBut(block, type|FLO, retval, icon, str, x1, y1, x2, y2, (void*) poin, min, max, a1, a2, tip);
2563 uiBut *uiDefIconTextButBitF(uiBlock *block, int type, int bit, 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)
2565 return uiDefIconTextButBit(block, type|FLO, bit, retval, icon, str, x1, y1, x2, y2, (void*) poin, min, max, a1, a2, tip);
2567 uiBut *uiDefIconTextButI(uiBlock *block, int type, int retval, int icon, char *str, short x1, short y1, short x2, short y2, int *poin, float min, float max, float a1, float a2, char *tip)
2569 return uiDefIconTextBut(block, type|INT, retval, icon, str, x1, y1, x2, y2, (void*) poin, min, max, a1, a2, tip);
2571 uiBut *uiDefIconTextButBitI(uiBlock *block, int type, int bit, int retval, int icon, char *str, short x1, short y1, short x2, short y2, int *poin, float min, float max, float a1, float a2, char *tip)
2573 return uiDefIconTextButBit(block, type|INT, bit, retval, icon, str, x1, y1, x2, y2, (void*) poin, min, max, a1, a2, tip);
2575 uiBut *uiDefIconTextButS(uiBlock *block, int type, int retval, int icon, char *str, short x1, short y1, short x2, short y2, short *poin, float min, float max, float a1, float a2, char *tip)
2577 return uiDefIconTextBut(block, type|SHO, retval, icon, str, x1, y1, x2, y2, (void*) poin, min, max, a1, a2, tip);
2579 uiBut *uiDefIconTextButBitS(uiBlock *block, int type, int bit, int retval, int icon, char *str, short x1, short y1, short x2, short y2, short *poin, float min, float max, float a1, float a2, char *tip)
2581 return uiDefIconTextButBit(block, type|SHO, bit, retval, icon, str, x1, y1, x2, y2, (void*) poin, min, max, a1, a2, tip);
2583 uiBut *uiDefIconTextButC(uiBlock *block, int type, int retval, int icon, char *str, short x1, short y1, short x2, short y2, char *poin, float min, float max, float a1, float a2, char *tip)
2585 return uiDefIconTextBut(block, type|CHA, retval, icon, str, x1, y1, x2, y2, (void*) poin, min, max, a1, a2, tip);
2587 uiBut *uiDefIconTextButBitC(uiBlock *block, int type, int bit, int retval, int icon, char *str, short x1, short y1, short x2, short y2, char *poin, float min, float max, float a1, float a2, char *tip)
2589 return uiDefIconTextButBit(block, type|CHA, bit, retval, icon, str, x1, y1, x2, y2, (void*) poin, min, max, a1, a2, tip);
2591 uiBut *uiDefIconTextButR(uiBlock *block, int type, int retval, int icon, char *str, short x1, short y1, short x2, short y2, PointerRNA *ptr, const char *propname, int index, float min, float max, float a1, float a2, char *tip)
2595 but= ui_def_but_rna(block, type, retval, str, x1, y1, x2, y2, ptr, propname, index, min, max, a1, a2, tip);
2598 but->icon= (BIFIconID) icon;
2599 but->flag|= UI_HAS_ICON;
2601 but->flag|= UI_ICON_LEFT;
2607 uiBut *uiDefIconTextButO(uiBlock *block, int type, char *opname, int opcontext, int icon, char *str, short x1, short y1, short x2, short y2, char *tip)
2611 but= ui_def_but_operator(block, type, opname, opcontext, str, x1, y1, x2, y2, tip);
2613 but->icon= (BIFIconID) icon;
2614 but->flag|= UI_HAS_ICON;
2615 but->flag|= UI_ICON_LEFT;
2622 static int ui_menu_y(uiBlock *block)
2624 uiBut *but= block->buttons.last;
2626 if(but) return but->y1;
2630 uiBut *uiDefMenuButO(uiBlock *block, char *opname, char *name)
2632 int y= ui_menu_y(block) - MENU_ITEM_HEIGHT;
2633 return uiDefIconTextButO(block, BUT, opname, WM_OP_INVOKE_REGION_WIN, ICON_BLANK1, name, 0, y, MENU_WIDTH, MENU_ITEM_HEIGHT-1, NULL);
2636 uiBut *uiDefMenuSep(uiBlock *block)
2638 int y= ui_menu_y(block) - MENU_SEP_HEIGHT;
2639 return uiDefBut(block, SEPR, 0, "", 0, y, MENU_WIDTH, MENU_SEP_HEIGHT, NULL, 0.0, 0.0, 0, 0, "");
2642 /* END Button containing both string label and icon */
2644 void uiSetButLink(uiBut *but, void **poin, void ***ppoin, short *tot, int from, int to)
2648 link= but->link= MEM_callocN(sizeof(uiLink), "new uilink");
2653 link->fromcode= from;
2657 /* cruft to make uiBlock and uiBut private */
2659 int uiBlocksGetYMin(ListBase *lb)
2664 for (block= lb->first; block; block= block->next)
2665 if (block==lb->first || block->miny<min)
2671 void uiBlockSetDirection(uiBlock *block, int direction)
2673 block->direction= direction;
2676 /* this call escapes if there's alignment flags */
2677 void uiBlockFlipOrder(uiBlock *block)
2681 float centy, miny=10000, maxy= -10000;
2683 if(U.uiflag & USER_MENUFIXEDORDER)
2686 for(but= block->buttons.first; but; but= but->next) {
2687 if(but->flag & UI_BUT_ALIGN) return;
2688 if(but->y1 < miny) miny= but->y1;
2689 if(but->y2 > maxy) maxy= but->y2;
2692 centy= (miny+maxy)/2.0;
2693 for(but= block->buttons.first; but; but= but->next) {
2694 but->y1 = centy-(but->y1-centy);
2695 but->y2 = centy-(but->y2-centy);
2696 SWAP(float, but->y1, but->y2);
2699 /* also flip order in block itself, for example for arrowkey */
2700 lb.first= lb.last= NULL;
2701 but= block->buttons.first;
2704 BLI_remlink(&block->buttons, but);
2705 BLI_addtail(&lb, but);
2712 void uiBlockSetFlag(uiBlock *block, int flag)
2717 void uiBlockClearFlag(uiBlock *block, int flag)
2719 block->flag&= ~flag;
2722 void uiBlockSetXOfs(uiBlock *block, int xofs)
2727 void uiButSetFlag(uiBut *but, int flag)
2732 void uiButClearFlag(uiBut *but, int flag)
2737 int uiButGetRetVal(uiBut *but)
2742 PointerRNA *uiButGetOperatorPtrRNA(uiBut *but)
2744 if(but->optype && !but->opptr) {
2745 but->opptr= MEM_callocN(sizeof(PointerRNA), "uiButOpPtr");
2746 WM_operator_properties_create(but->opptr, but->optype->idname);
2752 void uiBlockSetHandleFunc(uiBlock *block, uiBlockHandleFunc func, void *arg)
2754 block->handle_func= func;
2755 block->handle_func_arg= arg;
2758 void uiBlockSetButmFunc(uiBlock *block, uiMenuHandleFunc func, void *arg)
2760 block->butm_func= func;
2761 block->butm_func_arg= arg;
2764 void uiBlockSetFunc(uiBlock *block, uiButHandleFunc func, void *arg1, void *arg2)
2767 block->func_arg1= arg1;
2768 block->func_arg2= arg2;
2771 void uiBlockSetRenameFunc(uiBlock *block, uiButHandleRenameFunc func, void *arg1)
2776 void uiBlockSetDrawExtraFunc(uiBlock *block, void (*func)(const bContext *C, void *idv, rcti *rect))
2778 block->drawextra= func;
2781 void uiButSetFunc(uiBut *but, uiButHandleFunc func, void *arg1, void *arg2)
2784 but->func_arg1= arg1;
2785 but->func_arg2= arg2;
2788 void uiButSetNFunc(uiBut *but, uiButHandleNFunc funcN, void *argN, void *arg2)
2791 but->func_argN= argN;
2792 but->func_arg2= arg2;
2795 void uiButSetCompleteFunc(uiBut *but, uiButCompleteFunc func, void *arg)
2797 but->autocomplete_func= func;
2798 but->autofunc_arg= arg;
2801 uiBut *uiDefIDPoinBut(uiBlock *block, uiIDPoinFuncFP func, short blocktype, int retval, char *str, short x1, short y1, short x2, short y2, void *idpp, char *tip)
2803 uiBut *but= ui_def_but(block, IDPOIN, retval, str, x1, y1, x2, y2, NULL, 0.0, 0.0, 0.0, 0.0, tip);
2804 but->idpoin_func= func;
2805 but->idpoin_idpp= (ID**) idpp;
2809 uiButSetCompleteFunc(but, autocomplete_id, (void *)(intptr_t)blocktype);
2814 uiBut *uiDefBlockBut(uiBlock *block, uiBlockCreateFunc func, void *arg, char *str, short x1, short y1, short x2, short y2, char *tip)
2816 uiBut *but= ui_def_but(block, BLOCK, 0, str, x1, y1, x2, y2, arg, 0.0, 0.0, 0.0, 0.0, tip);
2817 but->block_create_func= func;
2822 uiBut *uiDefBlockButN(uiBlock *block, uiBlockCreateFunc func, void *argN, char *str, short x1, short y1, short x2, short y2, char *tip)
2824 uiBut *but= ui_def_but(block, BLOCK, 0, str, x1, y1, x2, y2, NULL, 0.0, 0.0, 0.0, 0.0, tip);
2825 but->block_create_func= func;
2826 but->func_argN= argN;
2832 uiBut *uiDefPulldownBut(uiBlock *block, uiBlockCreateFunc func, void *arg, char *str, short x1, short y1, short x2, short y2, char *tip)
2834 uiBut *but= ui_def_but(block, PULLDOWN, 0, str, x1, y1, x2, y2, arg, 0.0, 0.0, 0.0, 0.0, tip);
2835 but->block_create_func= func;
2840 uiBut *uiDefMenuBut(uiBlock *block, uiMenuCreateFunc func, void *arg, char *str, short x1, short y1, short x2, short y2, char *tip)
2842 uiBut *but= ui_def_but(block, PULLDOWN, 0, str, x1, y1, x2, y2, arg, 0.0, 0.0, 0.0, 0.0, tip);
2843 but->menu_create_func= func;
2848 uiBut *uiDefIconTextMenuBut(uiBlock *block, uiMenuCreateFunc func, void *arg, int icon, char *str, short x1, short y1, short x2, short y2, char *tip)
2850 uiBut *but= ui_def_but(block, PULLDOWN, 0, str, x1, y1, x2, y2, arg, 0.0, 0.0, 0.0, 0.0, tip);
2852 but->icon= (BIFIconID) icon;
2853 but->flag|= UI_HAS_ICON;
2855 but->flag|= UI_ICON_LEFT;
2856 but->flag|= UI_ICON_SUBMENU;
2858 but->menu_create_func= func;
2864 /* Block button containing both string label and icon */
2865 uiBut *uiDefIconTextBlockBut(uiBlock *block, uiBlockCreateFunc func, void *arg, int icon, char *str, short x1, short y1, short x2, short y2, char *tip)
2867 uiBut *but= ui_def_but(block, BLOCK, 0, str, x1, y1, x2, y2, arg, 0.0, 0.0, 0.0, 0.0, tip);
2869 /* XXX temp, old menu calls pass on icon arrow, which is now UI_ICON_SUBMENU flag */
2870 if(icon!=ICON_RIGHTARROW_THIN) {
2871 but->icon= (BIFIconID) icon;
2872 but->flag|= UI_ICON_LEFT;
2874 but->flag|= UI_HAS_ICON;
2875 but->flag|= UI_ICON_SUBMENU;
2877 but->block_create_func= func;
2883 /* Block button containing icon */
2884 uiBut *uiDefIconBlockBut(uiBlock *block, uiBlockCreateFunc func, void *arg, int retval, int icon, short x1, short y1, short x2, short y2, char *tip)
2886 uiBut *but= ui_def_but(block, BLOCK, retval, "", x1, y1, x2, y2, arg, 0.0, 0.0, 0.0, 0.0, tip);
2888 but->icon= (BIFIconID) icon;
2889 but->flag|= UI_HAS_ICON;
2891 but->flag|= UI_ICON_LEFT;
2892 but->flag|= UI_ICON_SUBMENU;
2894 but->block_create_func= func;
2900 void uiDefKeyevtButS(uiBlock *block, int retval, char *str, short x1, short y1, short x2, short y2, short *spoin, char *tip)
2902 uiBut *but= ui_def_but(block, KEYEVT|SHO, retval, str, x1, y1, x2, y2, spoin, 0.0, 0.0, 0.0, 0.0, tip);
2906 /* arg is pointer to string/name, use uiButSetSearchFunc() below to make this work */
2907 uiBut *uiDefSearchBut(uiBlock *block, void *arg, int retval, int icon, int maxlen, short x1, short y1, short x2, short y2, char *tip)
2909 uiBut *but= ui_def_but(block, SEARCH_MENU, retval, "", x1, y1, x2, y2, arg, 0.0, maxlen, 0.0, 0.0, tip);
2911 but->icon= (BIFIconID) icon;
2912 but->flag|= UI_HAS_ICON;
2914 but->flag|= UI_ICON_LEFT|UI_TEXT_LEFT;
2921 /* arg is user value, searchfunc and handlefunc both get it as arg */
2922 /* if active set, button opens with this item visible and selected */
2923 void uiButSetSearchFunc(uiBut *but, uiButSearchFunc sfunc, void *arg, uiButHandleFunc bfunc, void *active)
2925 but->search_func= sfunc;
2926 but->search_arg= arg;
2928 uiButSetFunc(but, bfunc, arg, active);
2931 /* Program Init/Exit */
2935 ui_resources_init();
2938 /* after reading userdef file */
2939 void UI_init_userdef(void)
2941 /* fix saved themes */
2942 init_userdef_do_versions();
2943 /* set default colors in default theme */
2944 ui_theme_init_userdef();
2951 ui_resources_free();