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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 *****
34 #include "MEM_guardedalloc.h"
36 #include "DNA_scene_types.h"
37 #include "DNA_screen_types.h"
38 #include "DNA_userdef_types.h"
41 #include "BLI_blenlib.h"
42 #include "BLI_dynstr.h"
43 #include "BLI_utildefines.h"
45 #include "BKE_context.h"
46 #include "BKE_library.h"
48 #include "BKE_utildefines.h" /* FILE_MAX */
54 #include "UI_interface.h"
59 #include "wm_subwindow.h"
60 #include "wm_window.h"
62 #include "RNA_access.h"
64 #include "BPY_extern.h"
66 #include "interface_intern.h"
68 #define MENU_WIDTH 120
69 #define MENU_ITEM_HEIGHT 20
70 #define MENU_SEP_HEIGHT 6
73 * a full doc with API notes can be found in bf-blender/trunk/blender/doc/guides/interface_API.txt
75 * uiBlahBlah() external function
76 * ui_blah_blah() internal function
79 static void ui_free_but(const bContext *C, uiBut *but);
81 /* ************* translation ************** */
83 int ui_translate_buttons()
85 return (U.transopts & USER_TR_BUTTONS);
88 int ui_translate_menus()
90 return (U.transopts & USER_TR_MENUS);
93 int ui_translate_tooltips()
95 return (U.transopts & USER_TR_TOOLTIPS);
98 /* ************* window matrix ************** */
100 void ui_block_to_window_fl(const ARegion *ar, uiBlock *block, float *x, float *y)
103 int sx, sy, getsizex, getsizey;
105 getsizex= ar->winrct.xmax-ar->winrct.xmin+1;
106 getsizey= ar->winrct.ymax-ar->winrct.ymin+1;
114 gx += block->panel->ofsx;
115 gy += block->panel->ofsy;
118 *x= ((float)sx) + ((float)getsizex)*(0.5+ 0.5*(gx*block->winmat[0][0]+ gy*block->winmat[1][0]+ block->winmat[3][0]));
119 *y= ((float)sy) + ((float)getsizey)*(0.5+ 0.5*(gx*block->winmat[0][1]+ gy*block->winmat[1][1]+ block->winmat[3][1]));
122 void ui_block_to_window(const ARegion *ar, uiBlock *block, int *x, int *y)
129 ui_block_to_window_fl(ar, block, &fx, &fy);
135 void ui_block_to_window_rct(const ARegion *ar, uiBlock *block, rctf *graph, rcti *winr)
140 ui_block_to_window_fl(ar, block, &tmpr.xmin, &tmpr.ymin);
141 ui_block_to_window_fl(ar, block, &tmpr.xmax, &tmpr.ymax);
143 winr->xmin= tmpr.xmin;
144 winr->ymin= tmpr.ymin;
145 winr->xmax= tmpr.xmax;
146 winr->ymax= tmpr.ymax;
149 void ui_window_to_block_fl(const ARegion *ar, uiBlock *block, float *x, float *y) /* for mouse cursor */
151 float a, b, c, d, e, f, px, py;
152 int sx, sy, getsizex, getsizey;
154 getsizex= ar->winrct.xmax-ar->winrct.xmin+1;
155 getsizey= ar->winrct.ymax-ar->winrct.ymin+1;
159 a= .5*((float)getsizex)*block->winmat[0][0];
160 b= .5*((float)getsizex)*block->winmat[1][0];
161 c= .5*((float)getsizex)*(1.0+block->winmat[3][0]);
163 d= .5*((float)getsizey)*block->winmat[0][1];
164 e= .5*((float)getsizey)*block->winmat[1][1];
165 f= .5*((float)getsizey)*(1.0+block->winmat[3][1]);
170 *y= (a*(py-f) + d*(c-px))/(a*e-d*b);
171 *x= (px- b*(*y)- c)/a;
174 *x -= block->panel->ofsx;
175 *y -= block->panel->ofsy;
179 void ui_window_to_block(const ARegion *ar, uiBlock *block, int *x, int *y)
186 ui_window_to_block_fl(ar, block, &fx, &fy);
192 void ui_window_to_region(const ARegion *ar, int *x, int *y)
194 *x-= ar->winrct.xmin;
195 *y-= ar->winrct.ymin;
198 /* ******************* block calc ************************* */
200 void ui_block_translate(uiBlock *block, int x, int y)
204 for(bt= block->buttons.first; bt; bt=bt->next) {
217 static void ui_text_bounds_block(uiBlock *block, float offset)
219 uiStyle *style= U.uistyles.first; // XXX pass on as arg
221 int i = 0, j, x1addval= offset, nextcol;
222 int lastcol= 0, col= 0;
224 uiStyleFontSet(&style->widget);
226 for(bt= block->buttons.first; bt; bt= bt->next) {
228 //int transopts= ui_translate_buttons();
229 //if(bt->type==TEX || bt->type==IDPOIN) transopts= 0;
231 j= BLF_width(style->widget.uifont_id, bt->drawstr);
236 if(bt->next && bt->x1 < bt->next->x1)
240 /* cope with multi collumns */
241 bt= block->buttons.first;
243 if(bt->next && bt->x1 < bt->next->x1) {
250 bt->x2 = bt->x1 + i + block->bounds;
253 bt->x2= MAX2(bt->x2, offset + block->minbounds);
255 ui_check_but(bt); // clips text again
258 x1addval+= i + block->bounds;
264 void ui_bounds_block(uiBlock *block)
269 if(block->buttons.first==NULL) {
271 block->minx= 0.0; block->maxx= block->panel->sizex;
272 block->miny= 0.0; block->maxy= block->panel->sizey;
277 block->minx= block->miny= 10000;
278 block->maxx= block->maxy= -10000;
280 bt= block->buttons.first;
282 if(bt->x1 < block->minx) block->minx= bt->x1;
283 if(bt->y1 < block->miny) block->miny= bt->y1;
285 if(bt->x2 > block->maxx) block->maxx= bt->x2;
286 if(bt->y2 > block->maxy) block->maxy= bt->y2;
291 block->minx -= block->bounds;
292 block->miny -= block->bounds;
293 block->maxx += block->bounds;
294 block->maxy += block->bounds;
297 block->maxx= block->minx + MAX2(block->maxx - block->minx, block->minbounds);
299 /* hardcoded exception... but that one is annoying with larger safety */
300 bt= block->buttons.first;
301 if(bt && strncmp(bt->str, "ERROR", 5)==0) xof= 10;
304 block->safety.xmin= block->minx-xof;
305 block->safety.ymin= block->miny-xof;
306 block->safety.xmax= block->maxx+xof;
307 block->safety.ymax= block->maxy+xof;
310 static void ui_centered_bounds_block(const bContext *C, uiBlock *block)
312 wmWindow *window= CTX_wm_window(C);
317 /* note: this is used for the splash where window bounds event has not been
318 * updated by ghost, get the window bounds from ghost directly */
320 // wm_window_get_size(window, &xmax, &ymax);
321 wm_window_get_size_ghost(window, &xmax, &ymax);
323 ui_bounds_block(block);
325 width= block->maxx - block->minx;
326 height= block->maxy - block->miny;
328 startx = (xmax * 0.5f) - (width * 0.5f);
329 starty = (ymax * 0.5f) - (height * 0.5f);
331 ui_block_translate(block, startx - block->minx, starty - block->miny);
333 /* now recompute bounds and safety */
334 ui_bounds_block(block);
337 static void ui_popup_bounds_block(const bContext *C, uiBlock *block, int bounds_calc)
339 wmWindow *window= CTX_wm_window(C);
340 int startx, starty, endx, endy, width, height, oldwidth, oldheight;
341 int oldbounds, xmax, ymax;
343 oldbounds= block->bounds;
345 /* compute mouse position with user defined offset */
346 ui_bounds_block(block);
348 wm_window_get_size(window, &xmax, &ymax);
350 oldwidth= block->maxx - block->minx;
351 oldheight= block->maxy - block->miny;
353 /* first we ensure wide enough text bounds */
354 if(bounds_calc==UI_BLOCK_BOUNDS_POPUP_MENU) {
355 if(block->flag & UI_BLOCK_LOOP) {
357 ui_text_bounds_block(block, block->minx);
361 /* next we recompute bounds */
362 block->bounds= oldbounds;
363 ui_bounds_block(block);
365 /* and we adjust the position to fit within window */
366 width= block->maxx - block->minx;
367 height= block->maxy - block->miny;
369 /* avoid divide by zero below, caused by calling with no UI, but better not crash */
370 oldwidth= oldwidth > 0 ? oldwidth : MAX2(1, width);
371 oldheight= oldheight > 0 ? oldheight : MAX2(1, height);
373 /* offset block based on mouse position, user offset is scaled
374 along in case we resized the block in ui_text_bounds_block */
375 startx= window->eventstate->x + block->minx + (block->mx*width)/oldwidth;
376 starty= window->eventstate->y + block->miny + (block->my*height)/oldheight;
395 ui_block_translate(block, startx - block->minx, starty - block->miny);
397 /* now recompute bounds and safety */
398 ui_bounds_block(block);
401 /* used for various cases */
402 void uiBoundsBlock(uiBlock *block, int addval)
407 block->bounds= addval;
408 block->dobounds= UI_BLOCK_BOUNDS;
411 /* used for pulldowns */
412 void uiTextBoundsBlock(uiBlock *block, int addval)
414 block->bounds= addval;
415 block->dobounds= UI_BLOCK_BOUNDS_TEXT;
418 /* used for block popups */
419 void uiPopupBoundsBlock(uiBlock *block, int addval, int mx, int my)
421 block->bounds= addval;
422 block->dobounds= UI_BLOCK_BOUNDS_POPUP_MOUSE;
427 /* used for menu popups */
428 void uiMenuPopupBoundsBlock(uiBlock *block, int addval, int mx, int my)
430 block->bounds= addval;
431 block->dobounds= UI_BLOCK_BOUNDS_POPUP_MENU;
436 /* used for centered popups, i.e. splash */
437 void uiCenteredBoundsBlock(uiBlock *block, int addval)
439 block->bounds= addval;
440 block->dobounds= UI_BLOCK_BOUNDS_POPUP_CENTER;
443 /* ************** LINK LINE DRAWING ************* */
445 /* link line drawing is not part of buttons or theme.. so we stick with it here */
447 static void ui_draw_linkline(uiLinkLine *line)
451 if(line->from==NULL || line->to==NULL) return;
453 rect.xmin= (line->from->x1+line->from->x2)/2.0;
454 rect.ymin= (line->from->y1+line->from->y2)/2.0;
455 rect.xmax= (line->to->x1+line->to->x2)/2.0;
456 rect.ymax= (line->to->y1+line->to->y2)/2.0;
458 if(line->flag & UI_SELECT)
459 glColor3ub(100,100,100);
463 ui_draw_link_bezier(&rect);
466 static void ui_draw_links(uiBlock *block)
471 but= block->buttons.first;
473 if(but->type==LINK && but->link) {
474 line= but->link->lines.first;
476 ui_draw_linkline(line);
484 /* ************** BLOCK ENDING FUNCTION ************* */
486 /* NOTE: if but->poin is allocated memory for every defbut, things fail... */
487 static int ui_but_equals_old(uiBut *but, uiBut *oldbut)
489 /* various properties are being compared here, hopfully sufficient
490 * to catch all cases, but it is simple to add more checks later */
491 if(but->retval != oldbut->retval) return 0;
492 if(but->rnapoin.data != oldbut->rnapoin.data) return 0;
493 if(but->rnaprop != oldbut->rnaprop)
494 if(but->rnaindex != oldbut->rnaindex) return 0;
495 if(but->func != oldbut->func) return 0;
496 if(but->funcN != oldbut->funcN) return 0;
497 if(oldbut->func_arg1 != oldbut && but->func_arg1 != oldbut->func_arg1) return 0;
498 if(oldbut->func_arg2 != oldbut && but->func_arg2 != oldbut->func_arg2) return 0;
499 if(!but->funcN && ((but->poin != oldbut->poin && (uiBut*)oldbut->poin != oldbut) || but->pointype != oldbut->pointype)) return 0;
504 static int ui_but_update_from_old_block(const bContext *C, uiBlock *block, uiBut *but)
510 oldblock= block->oldblock;
514 for(oldbut=oldblock->buttons.first; oldbut; oldbut=oldbut->next) {
515 if(ui_but_equals_old(oldbut, but)) {
518 but->flag= oldbut->flag;
520 /* exception! redalert flag can't be update from old button.
521 * perhaps it should only copy spesific flags rather then all. */
522 but->flag= (oldbut->flag & ~UI_BUT_REDALERT) | (but->flag & UI_BUT_REDALERT);
524 but->active= oldbut->active;
525 but->pos= oldbut->pos;
526 but->editstr= oldbut->editstr;
527 but->editval= oldbut->editval;
528 but->editvec= oldbut->editvec;
529 but->editcoba= oldbut->editcoba;
530 but->editcumap= oldbut->editcumap;
531 but->selsta= oldbut->selsta;
532 but->selend= oldbut->selend;
533 but->softmin= oldbut->softmin;
534 but->softmax= oldbut->softmax;
535 but->linkto[0]= oldbut->linkto[0];
536 but->linkto[1]= oldbut->linkto[1];
539 oldbut->active= NULL;
542 /* ensures one button can get activated, and in case the buttons
543 * draw are the same this gives O(1) lookup for each button */
544 BLI_remlink(&oldblock->buttons, oldbut);
545 ui_free_but(C, oldbut);
554 /* needed for temporarily rename buttons, such as in outliner or fileselect,
555 they should keep calling uiDefButs to keep them alive */
556 /* returns 0 when button removed */
557 int uiButActiveOnly(const bContext *C, uiBlock *block, uiBut *but)
561 int activate= 0, found= 0, isactive= 0;
563 oldblock= block->oldblock;
567 for(oldbut=oldblock->buttons.first; oldbut; oldbut=oldbut->next) {
568 if(ui_but_equals_old(oldbut, but)) {
578 if(activate || found==0) {
579 ui_button_activate_do( (bContext *)C, CTX_wm_region(C), but);
581 else if(found && isactive==0) {
583 BLI_remlink(&block->buttons, but);
591 /* assigns automatic keybindings to menu items for fast access
592 * (underline key in menu) */
593 static void ui_menu_block_set_keyaccels(uiBlock *block)
597 unsigned int meny_key_mask= 0;
598 unsigned char menu_key;
603 /* only do it before bounding */
604 if(block->minx != block->maxx)
607 for(pass=0; pass<2; pass++) {
608 /* 2 Passes, on for first letter only, second for any letter if first fails
609 * fun first pass on all buttons so first word chars always get first priority */
611 for(but=block->buttons.first; but; but=but->next) {
612 if(!ELEM4(but->type, BUT, MENU, BLOCK, PULLDOWN) || (but->flag & UI_HIDDEN)) {
615 else if(but->menu_key=='\0') {
617 for(str_pt= but->str; *str_pt; ) {
618 menu_key= tolower(*str_pt);
619 if((menu_key >= 'a' && menu_key <= 'z') && !(meny_key_mask & 1<<(menu_key-'a'))) {
620 meny_key_mask |= 1<<(menu_key-'a');
625 /* Skip to next delimeter on first pass (be picky) */
626 while(isalpha(*str_pt))
633 /* just step over every char second pass and find first usable key */
639 but->menu_key= menu_key;
642 /* run second pass */
646 /* if all keys have been used just exit, unlikely */
647 if(meny_key_mask == (1<<26)-1) {
654 /* check if second pass is needed */
662 void ui_menu_block_set_keymaps(const bContext *C, uiBlock *block)
666 char buf[512], *butstr;
668 /* only do it before bounding */
669 if(block->minx != block->maxx)
672 for(but=block->buttons.first; but; but=but->next) {
674 prop= (but->opptr)? but->opptr->data: NULL;
676 if(WM_key_event_operator_string(C, but->optype->idname, but->opcontext, prop, buf, sizeof(buf))) {
677 butstr= MEM_mallocN(strlen(but->str)+strlen(buf)+2, "menu_block_set_keymaps");
678 strcpy(butstr, but->str);
682 but->str= but->strdata;
683 BLI_strncpy(but->str, butstr, sizeof(but->strdata));
692 void uiEndBlock(const bContext *C, uiBlock *block)
695 Scene *scene= CTX_data_scene(C);
697 /* inherit flags from 'old' buttons that was drawn here previous, based
698 * on matching buttons, we need this to make button event handling non
699 * blocking, while still alowing buttons to be remade each redraw as it
700 * is expected by blender code */
701 for(but=block->buttons.first; but; but=but->next) {
702 if(ui_but_update_from_old_block(C, block, but))
705 /* temp? Proper check for greying out */
707 wmOperatorType *ot= but->optype;
710 CTX_store_set((bContext*)C, but->context);
712 if(ot == NULL || WM_operator_poll_context((bContext*)C, ot, but->opcontext)==0) {
713 but->flag |= UI_BUT_DISABLED;
718 CTX_store_set((bContext*)C, NULL);
721 ui_but_anim_flag(but, (scene)? scene->r.cfra: 0.0f);
724 if(block->oldblock) {
725 block->auto_open= block->oldblock->auto_open;
726 block->auto_open_last= block->oldblock->auto_open_last;
727 block->tooltipdisabled= block->oldblock->tooltipdisabled;
729 block->oldblock= NULL;
732 /* handle pending stuff */
733 if(block->layouts.first) uiBlockLayoutResolve(block, NULL, NULL);
734 ui_block_do_align(block);
735 if((block->flag & UI_BLOCK_LOOP) && (block->flag & UI_BLOCK_NUMSELECT)) ui_menu_block_set_keyaccels(block); /* could use a different flag to check */
736 if(block->flag & UI_BLOCK_LOOP) ui_menu_block_set_keymaps(C, block);
739 if(block->dobounds == UI_BLOCK_BOUNDS) ui_bounds_block(block);
740 else if(block->dobounds == UI_BLOCK_BOUNDS_TEXT) ui_text_bounds_block(block, 0.0f);
741 else if(block->dobounds == UI_BLOCK_BOUNDS_POPUP_CENTER) ui_centered_bounds_block(C, block);
742 else if(block->dobounds) ui_popup_bounds_block(C, block, block->dobounds);
744 if(block->minx==0.0 && block->maxx==0.0) uiBoundsBlock(block, 0);
745 if(block->flag & UI_BUT_ALIGN) uiBlockEndAlign(block);
750 /* ************** BLOCK DRAWING FUNCTION ************* */
752 void ui_fontscale(short *points, float aspect)
754 if(aspect < 0.9f || aspect > 1.1f) {
755 float pointsf= *points;
757 /* for some reason scaling fonts goes too fast compared to widget size */
758 aspect= sqrt(aspect);
762 *points= ceil(pointsf);
764 *points= floor(pointsf);
768 /* project button or block (but==NULL) to pixels in regionspace */
769 static void ui_but_to_pixelrect(rcti *rect, const ARegion *ar, uiBlock *block, uiBut *but)
772 float getsizex, getsizey;
777 gx= (but?but->x1:block->minx) + (block->panel?block->panel->ofsx:0.0f);
778 gy= (but?but->y1:block->miny) + (block->panel?block->panel->ofsy:0.0f);
780 rect->xmin= floor(getsizex*(0.5+ 0.5*(gx*block->winmat[0][0]+ gy*block->winmat[1][0]+ block->winmat[3][0])));
781 rect->ymin= floor(getsizey*(0.5+ 0.5*(gx*block->winmat[0][1]+ gy*block->winmat[1][1]+ block->winmat[3][1])));
783 gx= (but?but->x2:block->maxx) + (block->panel?block->panel->ofsx:0.0f);
784 gy= (but?but->y2:block->maxy) + (block->panel?block->panel->ofsy:0.0f);
786 rect->xmax= floor(getsizex*(0.5+ 0.5*(gx*block->winmat[0][0]+ gy*block->winmat[1][0]+ block->winmat[3][0])));
787 rect->ymax= floor(getsizey*(0.5+ 0.5*(gx*block->winmat[0][1]+ gy*block->winmat[1][1]+ block->winmat[3][1])));
791 /* uses local copy of style, to scale things down, and allow widgets to change stuff */
792 void uiDrawBlock(const bContext *C, uiBlock *block)
794 uiStyle style= *((uiStyle *)U.uistyles.first); // XXX pass on as arg
799 /* get menu region or area region */
802 ar= CTX_wm_region(C);
805 uiEndBlock(C, block);
807 /* we set this only once */
808 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
811 ui_fontscale(&style.paneltitle.points, block->aspect);
812 ui_fontscale(&style.grouplabel.points, block->aspect);
813 ui_fontscale(&style.widgetlabel.points, block->aspect);
814 ui_fontscale(&style.widget.points, block->aspect);
816 /* scale block min/max to rect */
817 ui_but_to_pixelrect(&rect, ar, block, NULL);
819 /* pixel space for AA widgets */
820 glMatrixMode(GL_PROJECTION);
822 glMatrixMode(GL_MODELVIEW);
826 wmOrtho2(-0.01f, ar->winx-0.01f, -0.01f, ar->winy-0.01f);
829 if(block->flag & UI_BLOCK_LOOP)
830 ui_draw_menu_back(&style, block, &rect);
831 else if(block->panel)
832 ui_draw_aligned_panel(&style, block, &rect);
835 for(but= block->buttons.first; but; but= but->next) {
836 ui_but_to_pixelrect(&rect, ar, block, but);
838 if(!(but->flag & UI_HIDDEN) &&
839 /* XXX: figure out why invalid coordinates happen when closing render window */
840 /* and material preview is redrawn in main window (temp fix for bug #23848) */
841 rect.xmin < rect.xmax && rect.ymin < rect.ymax)
842 ui_draw_but(C, ar, &style, but, &rect);
846 glMatrixMode(GL_PROJECTION);
848 glMatrixMode(GL_MODELVIEW);
851 ui_draw_links(block);
854 /* ************* EVENTS ************* */
856 static void ui_is_but_sel(uiBut *but)
860 short push=0, true=1;
862 value= ui_get_but_val(but);
864 if(ELEM3(but->type, TOGN, ICONTOGN, OPTIONN)) true= 0;
868 if( BTST(lvalue, (but->bitnr)) ) push= true;
887 if(value!=but->hardmin) push= 1;
892 if(value==0.0) push= 1;
896 /* support for rna enum buts */
897 if(but->rnaprop && (RNA_property_flag(but->rnaprop) & PROP_ENUM_FLAG)) {
898 if((int)value & (int)but->hardmax) push= 1;
901 if(value == but->hardmax) push= 1;
914 else if(push==1) but->flag |= UI_SELECT;
915 else but->flag &= ~UI_SELECT;
918 /* XXX 2.50 no links supported yet */
920 static int uibut_contains_pt(uiBut *UNUSED(but), short *UNUSED(mval))
926 uiBut *ui_get_valid_link_button(uiBlock *block, uiBut *but, short *mval)
930 /* find button to link to */
931 for (bt= block->buttons.first; bt; bt= bt->next)
932 if(bt!=but && uibut_contains_pt(bt, mval))
936 if (but->type==LINK && bt->type==INLINK) {
937 if( but->link->tocode == (int)bt->hardmin ) {
941 else if(but->type==INLINK && bt->type==LINK) {
942 if( bt->link->tocode == (int)but->hardmin ) {
952 static uiBut *ui_find_inlink(uiBlock *block, void *poin)
956 but= block->buttons.first;
958 if(but->type==INLINK) {
959 if(but->poin == poin) return but;
966 static void ui_add_link_line(ListBase *listb, uiBut *but, uiBut *bt)
970 line= MEM_callocN(sizeof(uiLinkLine), "linkline");
971 BLI_addtail(listb, line);
976 uiBut *uiFindInlink(uiBlock *block, void *poin)
978 return ui_find_inlink(block, poin);
981 void uiComposeLinks(uiBlock *block)
988 but= block->buttons.first;
990 if(but->type==LINK) {
993 /* for all pointers in the array */
997 for(a=0; a < *(link->totlink); a++) {
998 bt= ui_find_inlink(block, (*ppoin)[a] );
1000 ui_add_link_line(&link->lines, but, bt);
1004 else if(link->poin) {
1005 bt= ui_find_inlink(block, *(link->poin) );
1007 ui_add_link_line(&link->lines, but, bt);
1017 /* ************************************************ */
1019 void uiBlockSetButLock(uiBlock *block, int val, const char *lockstr)
1022 block->lock= val ? 1:0;
1023 block->lockstr= lockstr;
1027 void uiBlockClearButLock(uiBlock *block)
1030 block->lockstr= NULL;
1033 /* *************************************************************** */
1035 void ui_delete_linkline(uiLinkLine *line, uiBut *but)
1040 BLI_remlink(&but->link->lines, line);
1042 link= line->from->link;
1044 /* are there more pointers allowed? */
1047 if(*(link->totlink)==1) {
1048 *(link->totlink)= 0;
1049 MEM_freeN(*(link->ppoin));
1050 *(link->ppoin)= NULL;
1054 for(a=0; a< (*(link->totlink)); a++) {
1056 if( (*(link->ppoin))[a] != line->to->poin ) {
1057 (*(link->ppoin))[b]= (*(link->ppoin))[a];
1061 (*(link->totlink))--;
1065 *(link->poin)= NULL;
1071 /* XXX 2.50 no links supported yet */
1073 static void ui_delete_active_linkline(uiBlock *block)
1077 uiLinkLine *line, *nline;
1080 but= block->buttons.first;
1082 if(but->type==LINK && but->link) {
1083 line= but->link->lines.first;
1088 if(line->flag & UI_SELECT) {
1089 BLI_remlink(&but->link->lines, line);
1091 link= line->from->link;
1093 /* are there more pointers allowed? */
1096 if(*(link->totlink)==1) {
1097 *(link->totlink)= 0;
1098 MEM_freeN(*(link->ppoin));
1099 *(link->ppoin)= NULL;
1103 for(a=0; a< (*(link->totlink)); a++) {
1105 if( (*(link->ppoin))[a] != line->to->poin ) {
1106 (*(link->ppoin))[b]= (*(link->ppoin))[a];
1110 (*(link->totlink))--;
1114 *(link->poin)= NULL;
1125 /* temporal! these buttons can be everywhere... */
1126 allqueue(REDRAWBUTSLOGIC, 0);
1129 static void ui_do_active_linklines(uiBlock *block, short *mval)
1132 uiLinkLine *line, *act= NULL;
1133 float mindist= 12.0, fac, v1[2], v2[2], v3[3];
1140 /* find a line close to the mouse */
1141 but= block->buttons.first;
1143 if(but->type==LINK && but->link) {
1145 line= but->link->lines.first;
1147 v2[0]= line->from->x2;
1148 v2[1]= (line->from->y1+line->from->y2)/2.0;
1149 v3[0]= line->to->x1;
1150 v3[1]= (line->to->y1+line->to->y2)/2.0;
1152 fac= dist_to_line_segment_v2(v1, v2, v3);
1164 /* check for a 'found one' to prevent going to 'frontbuffer' mode.
1165 this slows done gfx quite some, and at OSX the 'finish' forces a swapbuffer */
1167 glDrawBuffer(GL_FRONT);
1170 but= block->buttons.first;
1172 if(but->type==LINK && but->link) {
1173 line= but->link->lines.first;
1176 if((line->flag & UI_SELECT)==0) {
1177 line->flag |= UI_SELECT;
1178 ui_draw_linkline(line);
1181 else if(line->flag & UI_SELECT) {
1182 line->flag &= ~UI_SELECT;
1183 ui_draw_linkline(line);
1191 glDrawBuffer(GL_BACK);
1196 /* ******************************************************* */
1198 /* XXX 2.50 no screendump supported yet */
1201 /* nasty but safe way to store screendump rect */
1202 static int scr_x=0, scr_y=0, scr_sizex=0, scr_sizey=0;
1204 static void ui_set_screendump_bbox(uiBlock *block)
1209 scr_sizex= block->maxx - block->minx;
1210 scr_sizey= block->maxy - block->miny;
1213 scr_sizex= scr_sizey= 0;
1217 /* used for making screenshots for menus, called in screendump.c */
1218 int uiIsMenu(int *x, int *y, int *sizex, int *sizey)
1220 if(scr_sizex!=0 && scr_sizey!=0) {
1232 /* *********************** data get/set ***********************
1233 * this either works with the pointed to data, or can work with
1234 * an edit override pointer while dragging for example */
1236 /* for buttons pointing to color for example */
1237 void ui_get_but_vectorf(uiBut *but, float *vec)
1243 VECCOPY(vec, but->editvec);
1249 vec[0]= vec[1]= vec[2]= 0.0f;
1251 if(RNA_property_type(prop) == PROP_FLOAT) {
1252 tot= RNA_property_array_length(&but->rnapoin, prop);
1255 for(a=0; a<tot; a++)
1256 vec[a]= RNA_property_float_get_index(&but->rnapoin, prop, a);
1259 else if(but->pointype == CHA) {
1260 char *cp= (char *)but->poin;
1261 vec[0]= ((float)cp[0])/255.0;
1262 vec[1]= ((float)cp[1])/255.0;
1263 vec[2]= ((float)cp[2])/255.0;
1265 else if(but->pointype == FLO) {
1266 float *fp= (float *)but->poin;
1270 if (but->editvec==NULL) {
1271 fprintf(stderr, "ui_get_but_vectorf: can't get color, should never happen\n");
1272 vec[0]= vec[1]= vec[2]= 0.0f;
1277 /* for buttons pointing to color for example */
1278 void ui_set_but_vectorf(uiBut *but, float *vec)
1284 VECCOPY(but->editvec, vec);
1290 if(RNA_property_type(prop) == PROP_FLOAT) {
1291 tot= RNA_property_array_length(&but->rnapoin, prop);
1294 for(a=0; a<tot; a++)
1295 RNA_property_float_set_index(&but->rnapoin, prop, a, vec[a]);
1298 else if(but->pointype == CHA) {
1299 char *cp= (char *)but->poin;
1300 cp[0]= (char)(0.5 +vec[0]*255.0);
1301 cp[1]= (char)(0.5 +vec[1]*255.0);
1302 cp[2]= (char)(0.5 +vec[2]*255.0);
1304 else if(but->pointype == FLO) {
1305 float *fp= (float *)but->poin;
1310 int ui_is_but_float(uiBut *but)
1312 if(but->pointype==FLO && but->poin)
1315 if(but->rnaprop && RNA_property_type(but->rnaprop) == PROP_FLOAT)
1321 int ui_is_but_unit(uiBut *but)
1323 Scene *scene= CTX_data_scene((bContext *)but->block->evil_C);
1324 int unit_type= uiButGetUnitType(but);
1326 if(unit_type == PROP_UNIT_NONE)
1329 #if 1 // removed so angle buttons get correct snapping
1330 if (scene->unit.system_rotation == USER_UNIT_ROT_RADIANS && unit_type == PROP_UNIT_ROTATION)
1334 /* for now disable time unit conversion */
1335 if (unit_type == PROP_UNIT_TIME)
1338 if (scene->unit.system == USER_UNIT_NONE) {
1339 if (unit_type != PROP_UNIT_ROTATION) {
1347 double ui_get_but_val(uiBut *but)
1352 if(but->editval) { return *(but->editval); }
1353 if(but->poin==NULL && but->rnapoin.data==NULL) return 0.0;
1358 switch(RNA_property_type(prop)) {
1360 if(RNA_property_array_length(&but->rnapoin, prop))
1361 value= RNA_property_boolean_get_index(&but->rnapoin, prop, but->rnaindex);
1363 value= RNA_property_boolean_get(&but->rnapoin, prop);
1366 if(RNA_property_array_length(&but->rnapoin, prop))
1367 value= RNA_property_int_get_index(&but->rnapoin, prop, but->rnaindex);
1369 value= RNA_property_int_get(&but->rnapoin, prop);
1372 if(RNA_property_array_length(&but->rnapoin, prop))
1373 value= RNA_property_float_get_index(&but->rnapoin, prop, but->rnaindex);
1375 value= RNA_property_float_get(&but->rnapoin, prop);
1378 value= RNA_property_enum_get(&but->rnapoin, prop);
1385 else if(but->type== HSVSLI) {
1388 fp= (but->editvec)? but->editvec: (float *)but->poin;
1389 rgb_to_hsv(fp[0], fp[1], fp[2], &h, &s, &v);
1391 switch(but->str[0]) {
1392 case 'H': value= h; break;
1393 case 'S': value= s; break;
1394 case 'V': value= v; break;
1397 else if( but->pointype == CHA ) {
1398 value= *(char *)but->poin;
1400 else if( but->pointype == SHO ) {
1401 value= *(short *)but->poin;
1403 else if( but->pointype == INT ) {
1404 value= *(int *)but->poin;
1406 else if( but->pointype == FLO ) {
1407 value= *(float *)but->poin;
1413 void ui_set_but_val(uiBut *but, double value)
1417 /* value is a hsv value: convert to rgb */
1421 if(RNA_property_editable(&but->rnapoin, prop)) {
1422 switch(RNA_property_type(prop)) {
1424 if(RNA_property_array_length(&but->rnapoin, prop))
1425 RNA_property_boolean_set_index(&but->rnapoin, prop, but->rnaindex, value);
1427 RNA_property_boolean_set(&but->rnapoin, prop, value);
1430 if(RNA_property_array_length(&but->rnapoin, prop))
1431 RNA_property_int_set_index(&but->rnapoin, prop, but->rnaindex, (int)value);
1433 RNA_property_int_set(&but->rnapoin, prop, (int)value);
1436 if(RNA_property_array_length(&but->rnapoin, prop))
1437 RNA_property_float_set_index(&but->rnapoin, prop, but->rnaindex, value);
1439 RNA_property_float_set(&but->rnapoin, prop, value);
1442 if(RNA_property_flag(prop) & PROP_ENUM_FLAG) {
1443 int ivalue= (int)value;
1444 ivalue ^= RNA_property_enum_get(&but->rnapoin, prop); /* toggle for enum/flag buttons */
1445 RNA_property_enum_set(&but->rnapoin, prop, ivalue);
1448 RNA_property_enum_set(&but->rnapoin, prop, value);
1456 else if(but->pointype==0);
1457 else if(but->type==HSVSLI ) {
1460 fp= (but->editvec)? but->editvec: (float *)but->poin;
1461 rgb_to_hsv(fp[0], fp[1], fp[2], &h, &s, &v);
1463 switch(but->str[0]) {
1464 case 'H': h= value; break;
1465 case 'S': s= value; break;
1466 case 'V': v= value; break;
1469 hsv_to_rgb(h, s, v, fp, fp+1, fp+2);
1473 /* first do rounding */
1474 if(but->pointype==CHA)
1475 value= (char)floor(value+0.5);
1476 else if(but->pointype==SHO ) {
1477 /* gcc 3.2.1 seems to have problems
1478 * casting a double like 32772.0 to
1479 * a short so we cast to an int, then
1482 gcckludge = (int) floor(value+0.5);
1483 value= (short)gcckludge;
1485 else if(but->pointype==INT )
1486 value= (int)floor(value+0.5);
1487 else if(but->pointype==FLO ) {
1488 float fval= (float)value;
1489 if(fval>= -0.00001f && fval<= 0.00001f) fval= 0.0f; /* prevent negative zero */
1493 /* then set value with possible edit override */
1495 *but->editval= value;
1496 else if(but->pointype==CHA)
1497 *((char *)but->poin)= (char)value;
1498 else if(but->pointype==SHO)
1499 *((short *)but->poin)= (short)value;
1500 else if(but->pointype==INT)
1501 *((int *)but->poin)= (int)value;
1502 else if(but->pointype==FLO)
1503 *((float *)but->poin)= (float)value;
1506 /* update select flag */
1510 int ui_get_but_string_max_length(uiBut *but)
1512 if(ELEM(but->type, TEX, SEARCH_MENU))
1513 return but->hardmax;
1514 else if(but->type == IDPOIN)
1515 return sizeof(((ID*)NULL)->name)-2;
1517 return UI_MAX_DRAW_STR;
1520 static double ui_get_but_scale_unit(uiBut *but, double value)
1522 Scene *scene= CTX_data_scene((bContext *)but->block->evil_C);
1523 int unit_type= uiButGetUnitType(but);
1525 if(unit_type == PROP_UNIT_LENGTH) {
1526 return value * scene->unit.scale_length;
1528 else if(unit_type == PROP_UNIT_AREA) {
1529 return value * pow(scene->unit.scale_length, 2);
1531 else if(unit_type == PROP_UNIT_VOLUME) {
1532 return value * pow(scene->unit.scale_length, 3);
1534 else if(unit_type == PROP_UNIT_TIME) { /* WARNING - using evil_C :| */
1535 return FRA2TIME(value);
1542 /* str will be overwritten */
1543 void ui_convert_to_unit_alt_name(uiBut *but, char *str, int maxlen)
1545 if(ui_is_but_unit(but)) {
1546 int unit_type= uiButGetUnitType(but);
1548 Scene *scene= CTX_data_scene((bContext *)but->block->evil_C);
1550 orig_str= MEM_callocN(sizeof(char)*maxlen + 1, "textedit sub str");
1551 memcpy(orig_str, str, maxlen);
1553 bUnit_ToUnitAltName(str, maxlen, orig_str, scene->unit.system, unit_type>>16);
1555 MEM_freeN(orig_str);
1559 static void ui_get_but_string_unit(uiBut *but, char *str, int len_max, double value, int pad)
1561 Scene *scene= CTX_data_scene((bContext *)but->block->evil_C);
1562 int do_split= scene->unit.flag & USER_UNIT_OPT_SPLIT;
1563 int unit_type= uiButGetUnitType(but);
1564 int precision= but->a2;
1566 if(scene->unit.scale_length<0.0001) scene->unit.scale_length= 1.0; // XXX do_versions
1569 if(precision>4) precision= 4;
1570 else if(precision==0) precision= 2;
1572 bUnit_AsString(str, len_max, ui_get_but_scale_unit(but, value), precision, scene->unit.system, unit_type>>16, do_split, pad);
1575 static float ui_get_but_step_unit(uiBut *but, float step_default)
1577 Scene *scene= CTX_data_scene((bContext *)but->block->evil_C);
1578 int unit_type= uiButGetUnitType(but)>>16;
1581 step = bUnit_ClosestScalar(ui_get_but_scale_unit(but, step_default), scene->unit.system, unit_type);
1583 if(step > 0.0) { /* -1 is an error value */
1584 return (step/ui_get_but_scale_unit(but, 1.0))*100;
1587 return step_default;
1592 void ui_get_but_string(uiBut *but, char *str, int maxlen)
1594 if(but->rnaprop && ELEM3(but->type, TEX, IDPOIN, SEARCH_MENU)) {
1598 type= RNA_property_type(but->rnaprop);
1600 if(type == PROP_STRING) {
1602 buf= RNA_property_string_get_alloc(&but->rnapoin, but->rnaprop, str, maxlen);
1604 else if(type == PROP_POINTER) {
1606 PointerRNA ptr= RNA_property_pointer_get(&but->rnapoin, but->rnaprop);
1607 buf= RNA_struct_name_get_alloc(&ptr, str, maxlen);
1613 else if(buf && buf != str) {
1614 /* string was too long, we have to truncate */
1615 BLI_strncpy(str, buf, maxlen);
1619 else if(but->type == IDPOIN) {
1621 if(but->idpoin_idpp) { /* Can be NULL for ID properties by python */
1622 ID *id= *(but->idpoin_idpp);
1624 BLI_strncpy(str, id->name+2, maxlen);
1631 else if(but->type == TEX) {
1633 BLI_strncpy(str, but->poin, maxlen);
1636 else if(but->type == SEARCH_MENU) {
1638 BLI_strncpy(str, but->poin, maxlen);
1641 else if(ui_but_anim_expression_get(but, str, maxlen))
1642 ; /* driver expression */
1644 /* number editing */
1647 value= ui_get_but_val(but);
1649 if(ui_is_but_float(but)) {
1650 if(ui_is_but_unit(but)) {
1651 ui_get_but_string_unit(but, str, maxlen, value, 0);
1653 else if(but->a2) { /* amount of digits defined */
1654 if(but->a2==1) BLI_snprintf(str, maxlen, "%.1f", value);
1655 else if(but->a2==2) BLI_snprintf(str, maxlen, "%.2f", value);
1656 else if(but->a2==3) BLI_snprintf(str, maxlen, "%.3f", value);
1657 else BLI_snprintf(str, maxlen, "%.4f", value);
1660 BLI_snprintf(str, maxlen, "%.3f", value);
1663 BLI_snprintf(str, maxlen, "%d", (int)value);
1667 int ui_set_but_string(bContext *C, uiBut *but, const char *str)
1669 if(but->rnaprop && ELEM3(but->type, TEX, IDPOIN, SEARCH_MENU)) {
1670 if(RNA_property_editable(&but->rnapoin, but->rnaprop)) {
1673 type= RNA_property_type(but->rnaprop);
1675 if(type == PROP_STRING) {
1677 RNA_property_string_set(&but->rnapoin, but->rnaprop, str);
1680 else if(type == PROP_POINTER) {
1682 PointerRNA ptr, rptr;
1685 if(str == NULL || str[0] == '\0') {
1686 RNA_property_pointer_set(&but->rnapoin, but->rnaprop, PointerRNA_NULL);
1690 ptr= but->rnasearchpoin;
1691 prop= but->rnasearchprop;
1693 if(prop && RNA_property_collection_lookup_string(&ptr, prop, str, &rptr))
1694 RNA_property_pointer_set(&but->rnapoin, but->rnaprop, rptr);
1703 else if(but->type == IDPOIN) {
1705 but->idpoin_func(C, (char*)str, but->idpoin_idpp);
1708 else if(but->type == TEX) {
1710 BLI_strncpy(but->poin, str, but->hardmax);
1713 else if(but->type == SEARCH_MENU) {
1715 BLI_strncpy(but->poin, str, but->hardmax);
1718 else if(ui_but_anim_expression_set(but, str)) {
1719 /* driver expression */
1723 /* number editing */
1728 char str_unit_convert[256];
1729 int unit_type= uiButGetUnitType(but);
1730 Scene *scene= CTX_data_scene((bContext *)but->block->evil_C);
1732 BLI_strncpy(str_unit_convert, str, sizeof(str_unit_convert));
1734 if(ui_is_but_unit(but)) {
1735 /* ugly, use the draw string to get the value, this could cause problems if it includes some text which resolves to a unit */
1736 bUnit_ReplaceString(str_unit_convert, sizeof(str_unit_convert), but->drawstr, ui_get_but_scale_unit(but, 1.0), scene->unit.system, unit_type>>16);
1739 if(BPY_button_exec(C, str_unit_convert, &value)) {
1740 value = ui_get_but_val(but); /* use its original value */
1748 #endif // WITH_PYTHON
1750 if(!ui_is_but_float(but)) value= (int)floor(value + 0.5);
1751 if(but->type==NUMABS) value= fabs(value);
1753 /* not that we use hard limits here */
1754 if(value<but->hardmin) value= but->hardmin;
1755 if(value>but->hardmax) value= but->hardmax;
1757 ui_set_but_val(but, value);
1764 void ui_set_but_default(bContext *C, uiBut *but)
1766 /* if there is a valid property that is editable... */
1767 if (but->rnapoin.data && but->rnaprop && RNA_property_editable(&but->rnapoin, but->rnaprop)) {
1768 if(RNA_property_reset(&but->rnapoin, but->rnaprop, -1)) {
1769 /* perform updates required for this property */
1770 RNA_property_update(C, &but->rnapoin, but->rnaprop);
1775 static double soft_range_round_up(double value, double max)
1777 /* round up to .., 0.1, 0.2, 0.5, 1, 2, 5, 10, 20, 50, .. */
1778 double newmax= pow(10.0, ceil(log(value)/log(10.0)));
1780 if(newmax*0.2 >= max && newmax*0.2 >= value)
1782 else if(newmax*0.5 >= max && newmax*0.5 >= value)
1788 static double soft_range_round_down(double value, double max)
1790 /* round down to .., 0.1, 0.2, 0.5, 1, 2, 5, 10, 20, 50, .. */
1791 double newmax= pow(10.0, floor(log(value)/log(10.0)));
1793 if(newmax*5.0 <= max && newmax*5.0 <= value)
1795 else if(newmax*2.0 <= max && newmax*2.0 <= value)
1801 void ui_set_but_soft_range(uiBut *but, double value)
1804 double softmin, softmax, step, precision;
1807 type= RNA_property_type(but->rnaprop);
1809 /* clamp button range to something reasonable in case
1810 * we get -inf/inf from RNA properties */
1811 if(type == PROP_INT) {
1812 int imin, imax, istep;
1814 RNA_property_int_ui_range(&but->rnapoin, but->rnaprop, &imin, &imax, &istep);
1815 softmin= (imin == INT_MIN)? -1e4: imin;
1816 softmax= (imin == INT_MAX)? 1e4: imax;
1820 else if(type == PROP_FLOAT) {
1821 float fmin, fmax, fstep, fprecision;
1823 RNA_property_float_ui_range(&but->rnapoin, but->rnaprop, &fmin, &fmax, &fstep, &fprecision);
1824 softmin= (fmin == -FLT_MAX)? -1e4: fmin;
1825 softmax= (fmax == FLT_MAX)? 1e4: fmax;
1827 precision= fprecision;
1832 /* if the value goes out of the soft/max range, adapt the range */
1833 if(value+1e-10 < softmin) {
1835 softmin= -soft_range_round_up(-value, -softmin);
1837 softmin= soft_range_round_down(value, softmin);
1839 if(softmin < but->hardmin)
1840 softmin= but->hardmin;
1842 else if(value-1e-10 > softmax) {
1844 softmax= -soft_range_round_down(-value, -softmax);
1846 softmax= soft_range_round_up(value, softmax);
1848 if(softmax > but->hardmax)
1849 softmax= but->hardmax;
1852 but->softmin= softmin;
1853 but->softmax= softmax;
1857 /* ******************* Free ********************/
1859 static void ui_free_link(uiLink *link)
1862 BLI_freelistN(&link->lines);
1867 /* can be called with C==NULL */
1868 static void ui_free_but(const bContext *C, uiBut *but)
1871 WM_operator_properties_free(but->opptr);
1872 MEM_freeN(but->opptr);
1874 if(but->func_argN) MEM_freeN(but->func_argN);
1876 /* XXX solve later, buttons should be free-able without context ideally,
1877 however they may have open tooltips or popup windows, which need to
1878 be closed using a context pointer */
1880 ui_button_active_free(C, but);
1883 MEM_freeN(but->active);
1885 if(but->str && but->str != but->strdata) MEM_freeN(but->str);
1886 ui_free_link(but->link);
1891 /* can be called with C==NULL */
1892 void uiFreeBlock(const bContext *C, uiBlock *block)
1896 while( (but= block->buttons.first) ) {
1897 BLI_remlink(&block->buttons, but);
1898 ui_free_but(C, but);
1901 if(block->func_argN)
1902 MEM_freeN(block->func_argN);
1904 CTX_store_free_list(&block->contexts);
1906 BLI_freelistN(&block->saferct);
1911 /* can be called with C==NULL */
1912 void uiFreeBlocks(const bContext *C, ListBase *lb)
1916 while( (block= lb->first) ) {
1917 BLI_remlink(lb, block);
1918 uiFreeBlock(C, block);
1922 void uiFreeInactiveBlocks(const bContext *C, ListBase *lb)
1924 uiBlock *block, *nextblock;
1926 for(block=lb->first; block; block=nextblock) {
1927 nextblock= block->next;
1929 if(!block->handle) {
1930 if(!block->active) {
1931 BLI_remlink(lb, block);
1932 uiFreeBlock(C, block);
1940 void uiBlockSetRegion(uiBlock *block, ARegion *region)
1943 uiBlock *oldblock= NULL;
1945 lb= ®ion->uiblocks;
1947 /* each listbase only has one block with this name, free block
1948 * if is already there so it can be rebuilt from scratch */
1950 for (oldblock= lb->first; oldblock; oldblock= oldblock->next)
1951 if (BLI_streq(oldblock->name, block->name))
1955 oldblock->active= 0;
1956 oldblock->panel= NULL;
1960 block->oldblock= oldblock;
1962 /* at the beginning of the list! for dynamical menus/blocks */
1964 BLI_addhead(lb, block);
1967 uiBlock *uiBeginBlock(const bContext *C, ARegion *region, const char *name, short dt)
1972 int getsizex, getsizey;
1974 window= CTX_wm_window(C);
1975 scn = CTX_data_scene(C);
1977 block= MEM_callocN(sizeof(uiBlock), "uiBlock");
1980 block->evil_C= (void*)C; // XXX
1981 if (scn) block->color_profile= (scn->r.color_mgt_flag & R_COLOR_MANAGEMENT);
1982 BLI_strncpy(block->name, name, sizeof(block->name));
1985 uiBlockSetRegion(block, region);
1987 /* window matrix and aspect */
1988 if(region && region->swinid) {
1989 wm_subwindow_getmatrix(window, region->swinid, block->winmat);
1990 wm_subwindow_getsize(window, region->swinid, &getsizex, &getsizey);
1992 /* TODO - investigate why block->winmat[0][0] is negative
1993 * in the image view when viewRedrawForce is called */
1994 block->aspect= 2.0/fabs( (getsizex)*block->winmat[0][0]);
1997 /* no subwindow created yet, for menus for example, so we
1998 * use the main window instead, since buttons are created
2000 wm_subwindow_getmatrix(window, window->screen->mainwin, block->winmat);
2001 wm_subwindow_getsize(window, window->screen->mainwin, &getsizex, &getsizey);
2003 block->aspect= 2.0/fabs(getsizex*block->winmat[0][0]);
2004 block->auto_open= 2;
2005 block->flag |= UI_BLOCK_LOOP; /* tag as menu */
2011 uiBlock *uiGetBlock(const char *name, ARegion *ar)
2013 uiBlock *block= ar->uiblocks.first;
2016 if( strcmp(name, block->name)==0 ) return block;
2023 void uiBlockSetEmboss(uiBlock *block, char dt)
2028 void ui_check_but(uiBut *but)
2030 /* if something changed in the button */
2033 // int transopts= ui_translate_buttons();
2037 // if(but->type==TEX || but->type==IDPOIN) transopts= 0;
2039 /* only update soft range while not editing */
2040 if(but->rnaprop && !(but->editval || but->editstr || but->editvec))
2041 ui_set_but_soft_range(but, ui_get_but_val(but));
2043 /* test for min and max, icon sliders, etc */
2044 switch( but->type ) {
2050 value= ui_get_but_val(but);
2051 if(value < but->hardmin) ui_set_but_val(but, but->hardmin);
2052 else if(value > but->hardmax) ui_set_but_val(but, but->hardmax);
2056 value= fabs( ui_get_but_val(but) );
2057 if(value < but->hardmin) ui_set_but_val(but, but->hardmin);
2058 else if(value > but->hardmax) ui_set_but_val(but, but->hardmax);
2063 if(!but->rnaprop || (RNA_property_flag(but->rnaprop) & PROP_ICONS_CONSECUTIVE)) {
2064 if(but->flag & UI_SELECT) but->iconadd= 1;
2065 else but->iconadd= 0;
2070 if(!but->rnaprop || (RNA_property_flag(but->rnaprop) & PROP_ICONS_CONSECUTIVE)) {
2071 value= ui_get_but_val(but);
2072 but->iconadd= (int)value- (int)(but->hardmin);
2077 if(!but->rnaprop || (RNA_property_flag(but->rnaprop) & PROP_ICONS_CONSECUTIVE)) {
2078 value= ui_get_but_val(but);
2079 but->iconadd= (int)value- (int)(but->hardmin);
2085 /* safety is 4 to enable small number buttons (like 'users') */
2086 okwidth= -4 + (but->x2 - but->x1);
2089 switch( but->type ) {
2094 if(but->x2 - but->x1 > 24) {
2095 value= ui_get_but_val(but);
2096 ui_set_name_menu(but, (int)value);
2105 value= ui_get_but_val(but);
2107 if(ui_is_but_float(but)) {
2108 if(value == FLT_MAX) sprintf(but->drawstr, "%sinf", but->str);
2109 else if(value == -FLT_MAX) sprintf(but->drawstr, "%s-inf", but->str);
2110 /* support length type buttons */
2111 else if(ui_is_but_unit(but)) {
2112 char new_str[sizeof(but->drawstr)];
2113 ui_get_but_string_unit(but, new_str, sizeof(new_str), value, TRUE);
2114 BLI_snprintf(but->drawstr, sizeof(but->drawstr), "%s%s", but->str, new_str);
2116 else if(but->a2) { /* amount of digits defined */
2117 if(but->a2==1) sprintf(but->drawstr, "%s%.1f", but->str, value);
2118 else if(but->a2==2) sprintf(but->drawstr, "%s%.2f", but->str, value);
2119 else if(but->a2==3) sprintf(but->drawstr, "%s%.3f", but->str, value);
2120 else sprintf(but->drawstr, "%s%.4f", but->str, value);
2123 if(but->hardmax<10.001) sprintf(but->drawstr, "%s%.3f", but->str, value);
2124 else sprintf(but->drawstr, "%s%.2f", but->str, value);
2128 sprintf(but->drawstr, "%s%d", but->str, (int)value);
2132 PropertySubType pstype = RNA_property_subtype(but->rnaprop);
2134 if (pstype == PROP_PERCENTAGE)
2135 strcat(but->drawstr, "%");
2140 if(ui_is_but_float(but)) {
2141 value= ui_get_but_val(but);
2142 if(but->a2) { /* amount of digits defined */
2143 if(but->a2==1) sprintf(but->drawstr, "%s%.1f", but->str, value);
2144 else if(but->a2==2) sprintf(but->drawstr, "%s%.2f", but->str, value);
2145 else if(but->a2==3) sprintf(but->drawstr, "%s%.3f", but->str, value);
2146 else sprintf(but->drawstr, "%s%.4f", but->str, value);
2149 sprintf(but->drawstr, "%s%.2f", but->str, value);
2152 else strncpy(but->drawstr, but->str, UI_MAX_DRAW_STR);
2160 char str[UI_MAX_DRAW_STR];
2162 ui_get_but_string(but, str, UI_MAX_DRAW_STR-strlen(but->str));
2164 strcpy(but->drawstr, but->str);
2165 strcat(but->drawstr, str);
2170 strncpy(but->drawstr, but->str, UI_MAX_DRAW_STR);
2171 if (but->flag & UI_SELECT) {
2172 strcat(but->drawstr, "Press a key");
2174 strcat(but->drawstr, WM_key_event_string((short) ui_get_but_val(but)));
2179 if (but->flag & UI_SELECT) {
2180 but->drawstr[0]= '\0';
2182 if(but->modifier_key) {
2183 char *str= but->drawstr;
2185 if(but->modifier_key & KM_SHIFT)
2186 str= strcat(str, "Shift ");
2187 if(but->modifier_key & KM_CTRL)
2188 str= strcat(str, "Ctrl ");
2189 if(but->modifier_key & KM_ALT)
2190 str= strcat(str, "Alt ");
2191 if(but->modifier_key & KM_OSKEY)
2192 str= strcat(str, "Cmd ");
2195 strcat(but->drawstr, "Press a key ");
2198 strncpy(but->drawstr, but->str, UI_MAX_DRAW_STR);
2203 /* trying to get the dual-icon to left of text... not very nice */
2205 strncpy(but->drawstr, " ", UI_MAX_DRAW_STR);
2206 strncpy(but->drawstr+2, but->str, UI_MAX_DRAW_STR-2);
2214 strncpy(but->drawstr, but->str, UI_MAX_DRAW_STR);
2218 /* if we are doing text editing, this will override the drawstr */
2220 strncpy(but->drawstr, but->editstr, UI_MAX_DRAW_STR);
2222 /* text clipping moved to widget drawing code itself */
2226 void uiBlockBeginAlign(uiBlock *block)
2228 /* if other align was active, end it */
2229 if(block->flag & UI_BUT_ALIGN) uiBlockEndAlign(block);
2231 block->flag |= UI_BUT_ALIGN_DOWN;
2234 /* buttons declared after this call will get this align nr */ // XXX flag?
2237 static int buts_are_horiz(uiBut *but1, uiBut *but2)
2241 dx= fabs( but1->x2 - but2->x1);
2242 dy= fabs( but1->y1 - but2->y2);
2244 if(dx > dy) return 0;
2248 void uiBlockEndAlign(uiBlock *block)
2250 block->flag &= ~UI_BUT_ALIGN; // all 4 flags
2253 int ui_but_can_align(uiBut *but)
2255 return !ELEM3(but->type, LABEL, OPTION, OPTIONN);
2258 static void ui_block_do_align_but(uiBut *first, int nr)
2260 uiBut *prev, *but=NULL, *next;
2261 int flag= 0, cols=0, rows=0;
2265 for(but=first; but && but->alignnr == nr; but=but->next) {
2266 if(but->next && but->next->alignnr == nr) {
2267 if(buts_are_horiz(but, but->next)) cols++;
2272 /* rows==0: 1 row, cols==0: 1 collumn */
2274 /* note; how it uses 'flag' in loop below (either set it, or OR it) is confusing */
2275 for(but=first, prev=NULL; but && but->alignnr == nr; prev=but, but=but->next) {
2277 if(next && next->alignnr != nr)
2280 /* clear old flag */
2281 but->flag &= ~UI_BUT_ALIGN;
2283 if(flag==0) { /* first case */
2285 if(buts_are_horiz(but, next)) {
2287 flag= UI_BUT_ALIGN_RIGHT;
2289 flag= UI_BUT_ALIGN_DOWN|UI_BUT_ALIGN_RIGHT;
2292 flag= UI_BUT_ALIGN_DOWN;
2296 else if(next==NULL) { /* last case */
2298 if(buts_are_horiz(prev, but)) {
2300 flag= UI_BUT_ALIGN_LEFT;
2302 flag= UI_BUT_ALIGN_TOP|UI_BUT_ALIGN_LEFT;
2304 else flag= UI_BUT_ALIGN_TOP;
2307 else if(buts_are_horiz(but, next)) {
2308 /* check if this is already second row */
2309 if( prev && buts_are_horiz(prev, but)==0) {
2310 flag &= ~UI_BUT_ALIGN_LEFT;
2311 flag |= UI_BUT_ALIGN_TOP;
2312 /* exception case: bottom row */
2315 while(bt && bt->alignnr == nr) {
2316 if(bt->next && bt->next->alignnr == nr && buts_are_horiz(bt, bt->next)==0 ) break;
2319 if(bt==0 || bt->alignnr != nr) flag= UI_BUT_ALIGN_TOP|UI_BUT_ALIGN_RIGHT;
2322 else flag |= UI_BUT_ALIGN_LEFT;
2326 flag |= UI_BUT_ALIGN_TOP;
2328 else { /* next button switches to new row */
2330 if(prev && buts_are_horiz(prev, but))
2331 flag |= UI_BUT_ALIGN_LEFT;
2333 flag &= ~UI_BUT_ALIGN_LEFT;
2334 flag |= UI_BUT_ALIGN_TOP;
2337 if( (flag & UI_BUT_ALIGN_TOP)==0) { /* stil top row */
2339 if(next && buts_are_horiz(but, next))
2340 flag = UI_BUT_ALIGN_DOWN|UI_BUT_ALIGN_LEFT|UI_BUT_ALIGN_RIGHT;
2342 /* last button in top row */
2343 flag = UI_BUT_ALIGN_DOWN|UI_BUT_ALIGN_LEFT;
2347 flag |= UI_BUT_ALIGN_DOWN;
2350 flag |= UI_BUT_ALIGN_TOP;
2356 /* merge coordinates */
2360 but->x1= (prev->x2+but->x1)/2.0;
2364 but->y2= (prev->y1+but->y2)/2.0;
2368 if(buts_are_horiz(prev, but)) {
2369 but->x1= (prev->x2+but->x1)/2.0;
2371 /* copy height too */
2374 else if(prev->prev && buts_are_horiz(prev->prev, prev)==0) {
2375 /* the previous button is a single one in its row */
2376 but->y2= (prev->y1+but->y2)/2.0;
2380 if(next && buts_are_horiz(but, next)==0)
2384 /* the previous button is not a single one in its row */
2392 void ui_block_do_align(uiBlock *block)
2397 /* align buttons with same align nr */
2398 for(but=block->buttons.first; but;) {
2401 ui_block_do_align_but(but, nr);
2403 /* skip with same number */
2404 for(; but && but->alignnr == nr; but=but->next);
2415 ui_def_but is the function that draws many button types
2418 "a1" Click Step (how much to change the value each click)
2419 "a2" Number of decimal point values to display. 0 defaults to 3 (0.000) 1,2,3, and a maximum of 4,
2420 all greater values will be clamped to 4.
2423 static uiBut *ui_def_but(uiBlock *block, int type, int retval, const char *str, int x1, int y1, short x2, short y2, void *poin, float min, float max, float a1, float a2, const char *tip)
2428 if(type & BUTPOIN) { /* a pointer is required */
2433 but= MEM_callocN(sizeof(uiBut), "uiBut");
2435 but->type= type & BUTTYPE;
2436 but->pointype= type & BUTPOIN;
2437 but->bit= type & BIT;
2438 but->bitnr= type & 31;
2442 but->retval= retval;
2445 if(slen >= UI_MAX_NAME_STR-1) {
2446 but->str= MEM_mallocN(slen+2, "ui_def_but str"); /* why +2 ? */
2449 but->str= but->strdata;
2451 memcpy(but->str, str, slen+1);
2459 but->hardmin= but->softmin= min;
2460 but->hardmax= but->softmax= max;
2465 but->lock= block->lock;
2466 but->lockstr= block->lockstr;
2469 but->aspect= 1.0f; //XXX block->aspect;
2470 but->block= block; // pointer back, used for frontbuffer status, and picker
2472 if((block->flag & UI_BUT_ALIGN) && ui_but_can_align(but))
2473 but->alignnr= block->alignnr;
2475 but->func= block->func;
2476 but->func_arg1= block->func_arg1;
2477 but->func_arg2= block->func_arg2;
2479 but->funcN= block->funcN;
2480 if(block->func_argN)
2481 but->func_argN= MEM_dupallocN(block->func_argN);
2483 but->pos= -1; /* cursor invisible */
2485 if(ELEM4(but->type, NUM, NUMABS, NUMSLI, HSVSLI)) { /* add a space to name */
2486 slen= strlen(but->str);
2487 if(slen>0 && slen<UI_MAX_NAME_STR-2) {
2488 if(but->str[slen-1]!=' ') {
2489 but->str[slen]= ' ';
2490 but->str[slen+1]= 0;
2495 if((block->flag & UI_BLOCK_LOOP) || ELEM8(but->type, MENU, TEX, LABEL, IDPOIN, BLOCK, BUTM, SEARCH_MENU, PROGRESSBAR))
2496 but->flag |= (UI_TEXT_LEFT|UI_ICON_LEFT);
2497 else if(but->type==BUT_TOGDUAL)
2498 but->flag |= UI_ICON_LEFT;
2500 but->flag |= (block->flag & UI_BUT_ALIGN);
2504 but->flag |= UI_BUT_DISABLED;
2508 if(ELEM8(but->type, BLOCK, BUT, LABEL, PULLDOWN, ROUNDBOX, LISTBOX, SEARCH_MENU, BUTM));
2509 else if(ELEM5(but->type, SCROLL, SEPR, LINK, INLINK, FTPREVIEW));
2510 else but->flag |= UI_BUT_UNDO;
2512 BLI_addtail(&block->buttons, but);
2514 if(block->curlayout)
2515 ui_layout_add_but(block->curlayout, but);
2520 static uiBut *ui_def_but_rna(uiBlock *block, int type, int retval, const char *str, int x1, int y1, short x2, short y2, PointerRNA *ptr, const char *propname, int index, float min, float max, float a1, float a2, const char *tip)
2524 PropertyType proptype;
2525 int freestr= 0, icon= 0;
2527 prop= RNA_struct_find_property(ptr, propname);
2530 proptype= RNA_property_type(prop);
2532 /* use rna values if parameters are not specified */
2534 if(type == MENU && proptype == PROP_ENUM) {
2535 EnumPropertyItem *item;
2537 int i, totitem, value, free;
2539 RNA_property_enum_items(block->evil_C, ptr, prop, &item, &totitem, &free);
2540 value= RNA_property_enum_get(ptr, prop);
2542 dynstr= BLI_dynstr_new();
2543 BLI_dynstr_appendf(dynstr, "%s%%t", RNA_property_ui_name(prop));
2544 for(i=0; i<totitem; i++) {
2545 if(!item[i].identifier[0]) {
2547 BLI_dynstr_appendf(dynstr, "|%s%%l", item[i].name);
2549 BLI_dynstr_append(dynstr, "|%l");
2551 else if(item[i].icon)
2552 BLI_dynstr_appendf(dynstr, "|%s %%i%d %%x%d", item[i].name, item[i].icon, item[i].value);
2554 BLI_dynstr_appendf(dynstr, "|%s %%x%d", item[i].name, item[i].value);
2556 if(value == item[i].value)
2559 str= BLI_dynstr_get_cstring(dynstr);
2560 BLI_dynstr_free(dynstr);
2567 else if(ELEM(type, ROW, LISTROW) && proptype == PROP_ENUM) {
2568 EnumPropertyItem *item;
2569 int i, totitem, free;
2571 RNA_property_enum_items(block->evil_C, ptr, prop, &item, &totitem, &free);
2572 for(i=0; i<totitem; i++) {
2573 if(item[i].identifier[0] && item[i].value == (int)max) {
2574 str= (char*)item[i].name;
2580 str= (char*)RNA_property_ui_name(prop);
2585 str= (char*)RNA_property_ui_name(prop);
2586 icon= RNA_property_ui_icon(prop);
2591 if(type == ROW && proptype == PROP_ENUM) {
2592 EnumPropertyItem *item;
2593 int i, totitem, free;
2595 RNA_property_enum_items(block->evil_C, ptr, prop, &item, &totitem, &free);
2597 for(i=0; i<totitem; i++) {
2598 if(item[i].identifier[0] && item[i].value == (int)max) {
2599 if(item[i].description[0])
2600 tip= (char*)item[i].description;
2611 tip= (char*)RNA_property_ui_description(prop);
2613 if(min == max || a1 == -1 || a2 == -1) {
2614 if(proptype == PROP_INT) {
2615 int hardmin, hardmax, softmin, softmax, step;
2617 RNA_property_int_range(ptr, prop, &hardmin, &hardmax);
2618 RNA_property_int_ui_range(ptr, prop, &softmin, &softmax, &step);
2620 if(!ELEM(type, ROW, LISTROW) && min == max) {
2629 else if(proptype == PROP_FLOAT) {
2630 float hardmin, hardmax, softmin, softmax, step, precision;
2632 RNA_property_float_range(ptr, prop, &hardmin, &hardmax);
2633 RNA_property_float_ui_range(ptr, prop, &softmin, &softmax, &step, &precision);
2635 if(!ELEM(type, ROW, LISTROW) && min == max) {
2644 else if(proptype == PROP_STRING) {
2646 max= RNA_property_string_maxlength(prop);
2647 if(max == 0) /* interface code should ideally support unlimited length */
2648 max= UI_MAX_DRAW_STR;
2653 printf("ui_def_but_rna: property not found: %s.%s\n", RNA_struct_identifier(ptr->type), propname);
2654 str= (char*)propname;
2657 /* now create button */
2658 but= ui_def_but(block, type, retval, str, x1, y1, x2, y2, NULL, min, max, a1, a2, tip);
2664 if(RNA_property_array_length(&but->rnapoin, but->rnaprop))
2665 but->rnaindex= index;
2671 but->icon= (BIFIconID)icon;
2672 but->flag |= UI_HAS_ICON;
2673 but->flag|= UI_ICON_LEFT;
2676 if (!prop || !RNA_property_editable(&but->rnapoin, prop)) {
2677 but->flag |= UI_BUT_DISABLED;
2682 /* If this button uses units, calculate the step from this */
2683 if(ui_is_but_unit(but))
2684 but->a1= ui_get_but_step_unit(but, but->a1);
2687 MEM_freeN((void *)str);
2692 static uiBut *ui_def_but_operator(uiBlock *block, int type, const char *opname, int opcontext, const char *str, int x1, int y1, short x2, short y2, const char *tip)
2697 ot= WM_operatortype_find(opname, 0);
2700 if(ot) str= ot->name;
2704 if ((!tip || tip[0]=='\0') && ot && ot->description) {
2705 tip= ot->description;
2708 but= ui_def_but(block, type, -1, str, x1, y1, x2, y2, NULL, 0, 0, 0, 0, tip);
2710 but->opcontext= opcontext;
2713 but->flag |= UI_BUT_DISABLED;
2721 static uiBut *ui_def_but_operator_text(uiBlock *block, int type, const char *opname, int opcontext, const char *str, int x1, int y1, short x2, short y2, void *poin, float min, float max, float a1, float a2, const char *tip)
2726 ot= WM_operatortype_find(opname, 0);
2729 if(ot) str= ot->name;
2733 if ((!tip || tip[0]=='\0') && ot && ot->description) {
2734 tip= ot->description;
2737 but= ui_def_but(block, type, -1, str, x1, y1, x2, y2, poin, min, max, a1, a2, tip);
2739 but->opcontext= opcontext;
2742 but->flag |= UI_BUT_DISABLED;
2750 uiBut *uiDefBut(uiBlock *block, int type, int retval, const char *str, int x1, int y1, short x2, short y2, void *poin, float min, float max, float a1, float a2, const char *tip)
2752 uiBut *but= ui_def_but(block, type, retval, str, x1, y1, x2, y2, poin, min, max, a1, a2, tip);
2759 /* if _x_ is a power of two (only one bit) return the power,
2760 * otherwise return -1.
2761 * (1<<findBitIndex(x))==x for powers of two.
2763 static int findBitIndex(unsigned int x) {
2764 if (!x || (x&(x-1))!=0) { /* x&(x-1) strips lowest bit */
2769 if (x&0xFFFF0000) idx+=16, x>>=16;
2770 if (x&0xFF00) idx+=8, x>>=8;
2771 if (x&0xF0) idx+=4, x>>=4;
2772 if (x&0xC) idx+=2, x>>=2;
2779 /* autocomplete helper functions */
2780 struct AutoComplete {
2783 const char *startname;
2786 AutoComplete *autocomplete_begin(const char *startname, int maxlen)
2788 AutoComplete *autocpl;
2790 autocpl= MEM_callocN(sizeof(AutoComplete), "AutoComplete");
2791 autocpl->maxlen= maxlen;
2792 autocpl->truncate= MEM_callocN(sizeof(char)*maxlen, "AutoCompleteTruncate");
2793 autocpl->startname= startname;
2798 void autocomplete_do_name(AutoComplete *autocpl, const char *name)
2800 char *truncate= autocpl->truncate;
2801 const char *startname= autocpl->startname;
2804 for(a=0; a<autocpl->maxlen-1; a++) {
2805 if(startname[a]==0 || startname[a]!=name[a])
2809 if(startname[a]==0) {
2812 BLI_strncpy(truncate, name, autocpl->maxlen);
2814 /* remove from truncate what is not in bone->name */
2815 for(a=0; a<autocpl->maxlen-1; a++) {
2820 else if(truncate[a]!=name[a])
2827 void autocomplete_end(AutoComplete *autocpl, char *autoname)
2829 if(autocpl->truncate[0])
2830 BLI_strncpy(autoname, autocpl->truncate, autocpl->maxlen);
2832 if (autoname != autocpl->startname) /* dont copy a string over its self */
2833 BLI_strncpy(autoname, autocpl->startname, autocpl->maxlen);
2835 MEM_freeN(autocpl->truncate);
2839 /* autocomplete callback for ID buttons */
2840 static void autocomplete_id(bContext *C, char *str, void *arg_v)
2842 int blocktype= (intptr_t)arg_v;
2843 ListBase *listb= which_libbase(CTX_data_main(C), blocktype);
2845 if(listb==NULL) return;
2847 /* search if str matches the beginning of an ID struct */
2849 AutoComplete *autocpl= autocomplete_begin(str, 22);
2852 for(id= listb->first; id; id= id->next)
2853 autocomplete_do_name(autocpl, id->name+2);
2855 autocomplete_end(autocpl, str);
2859 static uiBut *uiDefButBit(uiBlock *block, int type, int bit, int retval, const char *str, int x1, int y1, short x2, short y2, void *poin, float min, float max, float a1, float a2, const char *tip)
2861 int bitIdx= findBitIndex(bit);
2865 return uiDefBut(block, type|BIT|bitIdx, retval, str, x1, y1, x2, y2, poin, min, max, a1, a2, tip);
2868 uiBut *uiDefButF(uiBlock *block, int type, int retval, const char *str, int x1, int y1, short x2, short y2, float *poin, float min, float max, float a1, float a2, const char *tip)
2870 return uiDefBut(block, type|FLO, retval, str, x1, y1, x2, y2, (void*) poin, min, max, a1, a2, tip);
2872 uiBut *uiDefButBitF(uiBlock *block, int type, int bit, int retval, const char *str, int x1, int y1, short x2, short y2, float *poin, float min, float max, float a1, float a2, const char *tip)
2874 return uiDefButBit(block, type|FLO, bit, retval, str, x1, y1, x2, y2, (void*) poin, min, max, a1, a2, tip);
2876 uiBut *uiDefButI(uiBlock *block, int type, int retval, const char *str, int x1, int y1, short x2, short y2, int *poin, float min, float max, float a1, float a2, const char *tip)
2878 return uiDefBut(block, type|INT, retval, str, x1, y1, x2, y2, (void*) poin, min, max, a1, a2, tip);
2880 uiBut *uiDefButBitI(uiBlock *block, int type, int bit, int retval, const char *str, int x1, int y1, short x2, short y2, int *poin, float min, float max, float a1, float a2, const char *tip)
2882 return uiDefButBit(block, type|INT, bit, retval, str, x1, y1, x2, y2, (void*) poin, min, max, a1, a2, tip);
2884 uiBut *uiDefButS(uiBlock *block, int type, int retval, const char *str, int x1, int y1, short x2, short y2, short *poin, float min, float max, float a1, float a2, const char *tip)
2886 return uiDefBut(block, type|SHO, retval, str, x1, y1, x2, y2, (void*) poin, min, max, a1, a2, tip);
2888 uiBut *uiDefButBitS(uiBlock *block, int type, int bit, int retval, const char *str, int x1, int y1, short x2, short y2, short *poin, float min, float max, float a1, float a2, const char *tip)
2890 return uiDefButBit(block, type|SHO, bit, retval, str, x1, y1, x2, y2, (void*) poin, min, max, a1, a2, tip);
2892 uiBut *uiDefButC(uiBlock *block, int type, int retval, const char *str, int x1, int y1, short x2, short y2, char *poin, float min, float max, float a1, float a2, const char *tip)
2894 return uiDefBut(block, type|CHA, retval, str, x1, y1, x2, y2, (void*) poin, min, max, a1, a2, tip);
2896 uiBut *uiDefButBitC(uiBlock *block, int type, int bit, int retval, const char *str, int x1, int y1, short x2, short y2, char *poin, float min, float max, float a1, float a2, const char *tip)
2898 return uiDefButBit(block, type|CHA, bit, retval, str, x1, y1, x2, y2, (void*) poin, min, max, a1, a2, tip);
2900 uiBut *uiDefButR(uiBlock *block, int type, int retval, const char *str, int x1, int y1, short x2, short y2, PointerRNA *ptr, const char *propname, int index, float min, float max, float a1, float a2, const char *tip)
2904 but= ui_def_but_rna(block, type, retval, str, x1, y1, x2, y2, ptr, propname, index, min, max, a1, a2, tip);
2910 uiBut *uiDefButO(uiBlock *block, int type, const char *opname, int opcontext, const char *str, int x1, int y1, short x2, short y2, const char *tip)
2914 but= ui_def_but_operator(block, type, opname, opcontext, str, x1, y1, x2, y2, tip);
2921 uiBut *uiDefButTextO(uiBlock *block, int type, const char *opname, int opcontext, const char *str, int x1, int y1, short x2, short y2, void *poin, float min, float max, float a1, float a2, const char *tip)
2923 uiBut *but= ui_def_but_operator_text(block, type, opname, opcontext, str, x1, y1, x2, y2, poin, min, max, a1, a2, tip);
2931 /* if a1==1.0 then a2 is an extra icon blending factor (alpha 0.0 - 1.0) */
2932 uiBut *uiDefIconBut(uiBlock *block, int type, int retval, int icon, int x1, int y1, short x2, short y2, void *poin, float min, float max, float a1, float a2, const char *tip)
2934 uiBut *but= ui_def_but(block, type, retval, "", x1, y1, x2, y2, poin, min, max, a1, a2, tip);
2936 but->icon= (BIFIconID) icon;
2937 but->flag|= UI_HAS_ICON;
2943 static uiBut *uiDefIconButBit(uiBlock *block, int type, int bit, int retval, int icon, int x1, int y1, short x2, short y2, void *poin, float min, float max, float a1, float a2, const char *tip)
2945 int bitIdx= findBitIndex(bit);
2949 return uiDefIconBut(block, type|BIT|bitIdx, retval, icon, x1, y1, x2, y2, poin, min, max, a1, a2, tip);
2953 uiBut *uiDefIconButF(uiBlock *block, int type, int retval, int icon, int x1, int y1, short x2, short y2, float *poin, float min, float max, float a1, float a2, const char *tip)
2955 return uiDefIconBut(block, type|FLO, retval, icon, x1, y1, x2, y2, (void*) poin, min, max, a1, a2, tip);
2957 uiBut *uiDefIconButBitF(uiBlock *block, int type, int bit, int retval, int icon, int x1, int y1, short x2, short y2, float *poin, float min, float max, float a1, float a2, const char *tip)
2959 return uiDefIconButBit(block, type|FLO, bit, retval, icon, x1, y1, x2, y2, (void*) poin, min, max, a1, a2, tip);
2961 uiBut *uiDefIconButI(uiBlock *block, int type, int retval, int icon, int x1, int y1, short x2, short y2, int *poin, float min, float max, float a1, float a2, const char *tip)
2963 return uiDefIconBut(block, type|INT, retval, icon, x1, y1, x2, y2, (void*) poin, min, max, a1, a2, tip);
2965 uiBut *uiDefIconButBitI(uiBlock *block, int type, int bit, int retval, int icon, int x1, int y1, short x2, short y2, int *poin, float min, float max, float a1, float a2, const char *tip)
2967 return uiDefIconButBit(block, type|INT, bit, retval, icon, x1, y1, x2, y2, (void*) poin, min, max, a1, a2, tip);
2969 uiBut *uiDefIconButS(uiBlock *block, int type, int retval, int icon, int x1, int y1, short x2, short y2, short *poin, float min, float max, float a1, float a2, const char *tip)
2971 return uiDefIconBut(block, type|SHO, retval, icon, x1, y1, x2, y2, (void*) poin, min, max, a1, a2, tip);
2973 uiBut *uiDefIconButBitS(uiBlock *block, int type, int bit, int retval, int icon, int x1, int y1, short x2, short y2, short *poin, float min, float max, float a1, float a2, const char *tip)
2975 return uiDefIconButBit(block, type|SHO, bit, retval, icon, x1, y1, x2, y2, (void*) poin, min, max, a1, a2, tip);
2977 uiBut *uiDefIconButC(uiBlock *block, int type, int retval, int icon, int x1, int y1, short x2, short y2, char *poin, float min, float max, float a1, float a2, const char *tip)
2979 return uiDefIconBut(block, type|CHA, retval, icon, x1, y1, x2, y2, (void*) poin, min, max, a1, a2, tip);
2981 uiBut *uiDefIconButBitC(uiBlock *block, int type, int bit, int retval, int icon, int x1, int y1, short x2, short y2, char *poin, float min, float max, float a1, float a2, const char *tip)
2983 return uiDefIconButBit(block, type|CHA, bit, retval, icon, x1, y1, x2, y2, (void*) poin, min, max, a1, a2, tip);
2985 uiBut *uiDefIconButR(uiBlock *block, int type, int retval, int icon, int x1, int y1, short x2, short y2, PointerRNA *ptr, const char *propname, int index, float min, float max, float a1, float a2, const char *tip)
2989 but= ui_def_but_rna(block, type, retval, "", x1, y1, x2, y2, ptr, propname, index, min, max, a1, a2, tip);
2992 but->icon= (BIFIconID) icon;
2993 but->flag|= UI_HAS_ICON;
3000 uiBut *uiDefIconButO(uiBlock *block, int type, const char *opname, int opcontext, int icon, int x1, int y1, short x2, short y2, const char *tip)
3004 but= ui_def_but_operator(block, type, opname, opcontext, "", x1, y1, x2, y2, tip);
3006 but->icon= (BIFIconID) icon;
3007 but->flag|= UI_HAS_ICON;
3014 /* Button containing both string label and icon */
3015 uiBut *uiDefIconTextBut(uiBlock *block, int type, int retval, int icon, const char *str, int x1, int y1, short x2, short y2, void *poin, float min, float max, float a1, float a2, const char *tip)
3017 uiBut *but= ui_def_but(block, type, retval, str, x1, y1, x2, y2, poin, min, max, a1, a2, tip);
3019 but->icon= (BIFIconID) icon;
3020 but->flag|= UI_HAS_ICON;
3022 but->flag|= UI_ICON_LEFT;
3028 static uiBut *uiDefIconTextButBit(uiBlock *block, int type, int bit, int retval, int icon, const char *str, int x1, int y1, short x2, short y2, void *poin, float min, float max, float a1, float a2, const char *tip)