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 *****
28 /** \file blender/editors/interface/interface.c
29 * \ingroup edinterface
39 #include "MEM_guardedalloc.h"
41 #include "DNA_scene_types.h"
42 #include "DNA_screen_types.h"
43 #include "DNA_userdef_types.h"
46 #include "BLI_blenlib.h"
47 #include "BLI_dynstr.h"
48 #include "BLI_utildefines.h"
50 #include "BKE_context.h"
51 #include "BKE_library.h"
53 #include "BKE_utildefines.h" /* FILE_MAX */
59 #include "UI_interface.h"
64 #include "wm_subwindow.h"
65 #include "wm_window.h"
67 #include "RNA_access.h"
69 #include "BPY_extern.h"
71 #include "interface_intern.h"
73 #define MENU_WIDTH 120
74 #define MENU_ITEM_HEIGHT 20
75 #define MENU_SEP_HEIGHT 6
78 * a full doc with API notes can be found in bf-blender/trunk/blender/doc/guides/interface_API.txt
80 * uiBlahBlah() external function
81 * ui_blah_blah() internal function
84 static void ui_free_but(const bContext *C, uiBut *but);
86 /* ************* translation ************** */
88 int ui_translate_buttons(void)
90 return (U.transopts & USER_TR_BUTTONS);
93 int ui_translate_menus(void)
95 return (U.transopts & USER_TR_MENUS);
98 int ui_translate_tooltips(void)
100 return (U.transopts & USER_TR_TOOLTIPS);
103 /* ************* window matrix ************** */
105 void ui_block_to_window_fl(const ARegion *ar, uiBlock *block, float *x, float *y)
108 int sx, sy, getsizex, getsizey;
110 getsizex= ar->winrct.xmax-ar->winrct.xmin+1;
111 getsizey= ar->winrct.ymax-ar->winrct.ymin+1;
119 gx += block->panel->ofsx;
120 gy += block->panel->ofsy;
123 *x= ((float)sx) + ((float)getsizex)*(0.5f+ 0.5f*(gx*block->winmat[0][0]+ gy*block->winmat[1][0]+ block->winmat[3][0]));
124 *y= ((float)sy) + ((float)getsizey)*(0.5f+ 0.5f*(gx*block->winmat[0][1]+ gy*block->winmat[1][1]+ block->winmat[3][1]));
127 void ui_block_to_window(const ARegion *ar, uiBlock *block, int *x, int *y)
134 ui_block_to_window_fl(ar, block, &fx, &fy);
140 void ui_block_to_window_rct(const ARegion *ar, uiBlock *block, rctf *graph, rcti *winr)
145 ui_block_to_window_fl(ar, block, &tmpr.xmin, &tmpr.ymin);
146 ui_block_to_window_fl(ar, block, &tmpr.xmax, &tmpr.ymax);
148 winr->xmin= tmpr.xmin;
149 winr->ymin= tmpr.ymin;
150 winr->xmax= tmpr.xmax;
151 winr->ymax= tmpr.ymax;
154 void ui_window_to_block_fl(const ARegion *ar, uiBlock *block, float *x, float *y) /* for mouse cursor */
156 float a, b, c, d, e, f, px, py;
157 int sx, sy, getsizex, getsizey;
159 getsizex= ar->winrct.xmax-ar->winrct.xmin+1;
160 getsizey= ar->winrct.ymax-ar->winrct.ymin+1;
164 a= 0.5f*((float)getsizex)*block->winmat[0][0];
165 b= 0.5f*((float)getsizex)*block->winmat[1][0];
166 c= 0.5f*((float)getsizex)*(1.0f+block->winmat[3][0]);
168 d= 0.5f*((float)getsizey)*block->winmat[0][1];
169 e= 0.5f*((float)getsizey)*block->winmat[1][1];
170 f= 0.5f*((float)getsizey)*(1.0f+block->winmat[3][1]);
175 *y= (a*(py-f) + d*(c-px))/(a*e-d*b);
176 *x= (px- b*(*y)- c)/a;
179 *x -= block->panel->ofsx;
180 *y -= block->panel->ofsy;
184 void ui_window_to_block(const ARegion *ar, uiBlock *block, int *x, int *y)
191 ui_window_to_block_fl(ar, block, &fx, &fy);
197 void ui_window_to_region(const ARegion *ar, int *x, int *y)
199 *x-= ar->winrct.xmin;
200 *y-= ar->winrct.ymin;
203 /* ******************* block calc ************************* */
205 void ui_block_translate(uiBlock *block, int x, int y)
209 for(bt= block->buttons.first; bt; bt=bt->next) {
222 static void ui_text_bounds_block(uiBlock *block, float offset)
224 uiStyle *style= U.uistyles.first; // XXX pass on as arg
226 int i = 0, j, x1addval= offset, nextcol;
227 int lastcol= 0, col= 0;
229 uiStyleFontSet(&style->widget);
231 for(bt= block->buttons.first; bt; bt= bt->next) {
233 //int transopts= ui_translate_buttons();
234 //if(bt->type==TEX || bt->type==IDPOIN) transopts= 0;
236 j= BLF_width(style->widget.uifont_id, bt->drawstr);
241 if(bt->next && bt->x1 < bt->next->x1)
245 /* cope with multi collumns */
246 bt= block->buttons.first;
248 if(bt->next && bt->x1 < bt->next->x1) {
255 bt->x2 = bt->x1 + i + block->bounds;
258 bt->x2= MAX2(bt->x2, offset + block->minbounds);
260 ui_check_but(bt); // clips text again
263 x1addval+= i + block->bounds;
269 void ui_bounds_block(uiBlock *block)
274 if(block->buttons.first==NULL) {
276 block->minx= 0.0; block->maxx= block->panel->sizex;
277 block->miny= 0.0; block->maxy= block->panel->sizey;
282 block->minx= block->miny= 10000;
283 block->maxx= block->maxy= -10000;
285 bt= block->buttons.first;
287 if(bt->x1 < block->minx) block->minx= bt->x1;
288 if(bt->y1 < block->miny) block->miny= bt->y1;
290 if(bt->x2 > block->maxx) block->maxx= bt->x2;
291 if(bt->y2 > block->maxy) block->maxy= bt->y2;
296 block->minx -= block->bounds;
297 block->miny -= block->bounds;
298 block->maxx += block->bounds;
299 block->maxy += block->bounds;
302 block->maxx= block->minx + MAX2(block->maxx - block->minx, block->minbounds);
304 /* hardcoded exception... but that one is annoying with larger safety */
305 bt= block->buttons.first;
306 if(bt && strncmp(bt->str, "ERROR", 5)==0) xof= 10;
309 block->safety.xmin= block->minx-xof;
310 block->safety.ymin= block->miny-xof;
311 block->safety.xmax= block->maxx+xof;
312 block->safety.ymax= block->maxy+xof;
315 static void ui_centered_bounds_block(const bContext *C, uiBlock *block)
317 wmWindow *window= CTX_wm_window(C);
322 /* note: this is used for the splash where window bounds event has not been
323 * updated by ghost, get the window bounds from ghost directly */
325 // wm_window_get_size(window, &xmax, &ymax);
326 wm_window_get_size_ghost(window, &xmax, &ymax);
328 ui_bounds_block(block);
330 width= block->maxx - block->minx;
331 height= block->maxy - block->miny;
333 startx = (xmax * 0.5f) - (width * 0.5f);
334 starty = (ymax * 0.5f) - (height * 0.5f);
336 ui_block_translate(block, startx - block->minx, starty - block->miny);
338 /* now recompute bounds and safety */
339 ui_bounds_block(block);
342 static void ui_popup_bounds_block(const bContext *C, uiBlock *block, int bounds_calc)
344 wmWindow *window= CTX_wm_window(C);
345 int startx, starty, endx, endy, width, height, oldwidth, oldheight;
346 int oldbounds, xmax, ymax;
348 oldbounds= block->bounds;
350 /* compute mouse position with user defined offset */
351 ui_bounds_block(block);
353 wm_window_get_size(window, &xmax, &ymax);
355 oldwidth= block->maxx - block->minx;
356 oldheight= block->maxy - block->miny;
358 /* first we ensure wide enough text bounds */
359 if(bounds_calc==UI_BLOCK_BOUNDS_POPUP_MENU) {
360 if(block->flag & UI_BLOCK_LOOP) {
362 ui_text_bounds_block(block, block->minx);
366 /* next we recompute bounds */
367 block->bounds= oldbounds;
368 ui_bounds_block(block);
370 /* and we adjust the position to fit within window */
371 width= block->maxx - block->minx;
372 height= block->maxy - block->miny;
374 /* avoid divide by zero below, caused by calling with no UI, but better not crash */
375 oldwidth= oldwidth > 0 ? oldwidth : MAX2(1, width);
376 oldheight= oldheight > 0 ? oldheight : MAX2(1, height);
378 /* offset block based on mouse position, user offset is scaled
379 along in case we resized the block in ui_text_bounds_block */
380 startx= window->eventstate->x + block->minx + (block->mx*width)/oldwidth;
381 starty= window->eventstate->y + block->miny + (block->my*height)/oldheight;
400 ui_block_translate(block, startx - block->minx, starty - block->miny);
402 /* now recompute bounds and safety */
403 ui_bounds_block(block);
406 /* used for various cases */
407 void uiBoundsBlock(uiBlock *block, int addval)
412 block->bounds= addval;
413 block->dobounds= UI_BLOCK_BOUNDS;
416 /* used for pulldowns */
417 void uiTextBoundsBlock(uiBlock *block, int addval)
419 block->bounds= addval;
420 block->dobounds= UI_BLOCK_BOUNDS_TEXT;
423 /* used for block popups */
424 void uiPopupBoundsBlock(uiBlock *block, int addval, int mx, int my)
426 block->bounds= addval;
427 block->dobounds= UI_BLOCK_BOUNDS_POPUP_MOUSE;
432 /* used for menu popups */
433 void uiMenuPopupBoundsBlock(uiBlock *block, int addval, int mx, int my)
435 block->bounds= addval;
436 block->dobounds= UI_BLOCK_BOUNDS_POPUP_MENU;
441 /* used for centered popups, i.e. splash */
442 void uiCenteredBoundsBlock(uiBlock *block, int addval)
444 block->bounds= addval;
445 block->dobounds= UI_BLOCK_BOUNDS_POPUP_CENTER;
448 /* ************** LINK LINE DRAWING ************* */
450 /* link line drawing is not part of buttons or theme.. so we stick with it here */
452 static void ui_draw_linkline(uiLinkLine *line)
456 if(line->from==NULL || line->to==NULL) return;
458 rect.xmin= (line->from->x1+line->from->x2)/2.0f;
459 rect.ymin= (line->from->y1+line->from->y2)/2.0f;
460 rect.xmax= (line->to->x1+line->to->x2)/2.0f;
461 rect.ymax= (line->to->y1+line->to->y2)/2.0f;
463 if(line->flag & UI_SELECT)
464 glColor3ub(100,100,100);
468 ui_draw_link_bezier(&rect);
471 static void ui_draw_links(uiBlock *block)
476 but= block->buttons.first;
478 if(but->type==LINK && but->link) {
479 line= but->link->lines.first;
481 ui_draw_linkline(line);
489 /* ************** BLOCK ENDING FUNCTION ************* */
491 /* NOTE: if but->poin is allocated memory for every defbut, things fail... */
492 static int ui_but_equals_old(uiBut *but, uiBut *oldbut)
494 /* various properties are being compared here, hopfully sufficient
495 * to catch all cases, but it is simple to add more checks later */
496 if(but->retval != oldbut->retval) return 0;
497 if(but->rnapoin.data != oldbut->rnapoin.data) return 0;
498 if(but->rnaprop != oldbut->rnaprop)
499 if(but->rnaindex != oldbut->rnaindex) return 0;
500 if(but->func != oldbut->func) return 0;
501 if(but->funcN != oldbut->funcN) return 0;
502 if(oldbut->func_arg1 != oldbut && but->func_arg1 != oldbut->func_arg1) return 0;
503 if(oldbut->func_arg2 != oldbut && but->func_arg2 != oldbut->func_arg2) return 0;
504 if(!but->funcN && ((but->poin != oldbut->poin && (uiBut*)oldbut->poin != oldbut) || but->pointype != oldbut->pointype)) return 0;
505 if(but->optype != oldbut->optype) return 0;
510 /* oldbut is being inserted in new block, so we use the lines from new button, and replace button pointers */
511 static void ui_but_update_linklines(uiBlock *block, uiBut *oldbut, uiBut *newbut)
516 /* if active button is LINK */
517 if(newbut->type==LINK && newbut->link) {
519 SWAP(uiLink *, oldbut->link, newbut->link);
521 for(line= oldbut->link->lines.first; line; line= line->next) {
524 if(line->from==newbut)
529 /* check all other button links */
530 for(but= block->buttons.first; but; but= but->next) {
531 if(but!=newbut && but->type==LINK && but->link) {
532 for(line= but->link->lines.first; line; line= line->next) {
535 if(line->from==newbut)
542 static int ui_but_update_from_old_block(const bContext *C, uiBlock *block, uiBut **butpp)
545 uiBut *oldbut, *but= *butpp;
548 oldblock= block->oldblock;
552 for(oldbut=oldblock->buttons.first; oldbut; oldbut=oldbut->next) {
553 if(ui_but_equals_old(oldbut, but)) {
556 // but->flag= oldbut->flag;
558 /* exception! redalert flag can't be update from old button.
559 * perhaps it should only copy spesific flags rather then all. */
560 // but->flag= (oldbut->flag & ~UI_BUT_REDALERT) | (but->flag & UI_BUT_REDALERT);
562 // but->active= oldbut->active;
563 // but->pos= oldbut->pos;
564 // but->ofs= oldbut->ofs;
565 // but->editstr= oldbut->editstr;
566 // but->editval= oldbut->editval;
567 // but->editvec= oldbut->editvec;
568 // but->editcoba= oldbut->editcoba;
569 // but->editcumap= oldbut->editcumap;
570 // but->selsta= oldbut->selsta;
571 // but->selend= oldbut->selend;
572 // but->softmin= oldbut->softmin;
573 // but->softmax= oldbut->softmax;
574 // but->linkto[0]= oldbut->linkto[0];
575 // but->linkto[1]= oldbut->linkto[1];
577 // oldbut->active= NULL;
579 /* move button over from oldblock to new block */
580 BLI_remlink(&oldblock->buttons, oldbut);
581 BLI_insertlink(&block->buttons, but, oldbut);
582 oldbut->block= block;
585 /* still stuff needs to be copied */
586 oldbut->x1= but->x1; oldbut->y1= but->y1;
587 oldbut->x2= but->x2; oldbut->y2= but->y2;
588 oldbut->context= but->context; /* set by Layout */
590 /* typically the same pointers, but not on undo/redo */
591 /* XXX some menu buttons store button itself in but->poin. Ugly */
592 if(oldbut->poin != (char *)oldbut) {
593 SWAP(char *, oldbut->poin, but->poin)
594 SWAP(void *, oldbut->func_argN, but->func_argN)
597 ui_but_update_linklines(block, oldbut, but);
599 BLI_remlink(&block->buttons, but);
602 /* note: if layout hasn't been applied yet, it uses old button pointers... */
605 /* ensures one button can get activated, and in case the buttons
606 * draw are the same this gives O(1) lookup for each button */
607 BLI_remlink(&oldblock->buttons, oldbut);
608 ui_free_but(C, oldbut);
618 /* needed for temporarily rename buttons, such as in outliner or fileselect,
619 they should keep calling uiDefButs to keep them alive */
620 /* returns 0 when button removed */
621 int uiButActiveOnly(const bContext *C, uiBlock *block, uiBut *but)
625 int activate= 0, found= 0, isactive= 0;
627 oldblock= block->oldblock;
631 for(oldbut=oldblock->buttons.first; oldbut; oldbut=oldbut->next) {
632 if(ui_but_equals_old(oldbut, but)) {
642 if(activate || found==0) {
643 ui_button_activate_do( (bContext *)C, CTX_wm_region(C), but);
645 else if(found && isactive==0) {
647 BLI_remlink(&block->buttons, but);
655 /* assigns automatic keybindings to menu items for fast access
656 * (underline key in menu) */
657 static void ui_menu_block_set_keyaccels(uiBlock *block)
661 unsigned int meny_key_mask= 0;
662 unsigned char menu_key;
667 /* only do it before bounding */
668 if(block->minx != block->maxx)
671 for(pass=0; pass<2; pass++) {
672 /* 2 Passes, on for first letter only, second for any letter if first fails
673 * fun first pass on all buttons so first word chars always get first priority */
675 for(but=block->buttons.first; but; but=but->next) {
676 if(!ELEM4(but->type, BUT, MENU, BLOCK, PULLDOWN) || (but->flag & UI_HIDDEN)) {
679 else if(but->menu_key=='\0') {
681 for(str_pt= but->str; *str_pt; ) {
682 menu_key= tolower(*str_pt);
683 if((menu_key >= 'a' && menu_key <= 'z') && !(meny_key_mask & 1<<(menu_key-'a'))) {
684 meny_key_mask |= 1<<(menu_key-'a');
689 /* Skip to next delimeter on first pass (be picky) */
690 while(isalpha(*str_pt))
697 /* just step over every char second pass and find first usable key */
703 but->menu_key= menu_key;
706 /* run second pass */
710 /* if all keys have been used just exit, unlikely */
711 if(meny_key_mask == (1<<26)-1) {
718 /* check if second pass is needed */
726 static void ui_menu_block_set_keymaps(const bContext *C, uiBlock *block)
732 /* only do it before bounding */
733 if(block->minx != block->maxx)
736 for(but=block->buttons.first; but; but=but->next) {
738 prop= (but->opptr)? but->opptr->data: NULL;
740 if(WM_key_event_operator_string(C, but->optype->idname, but->opcontext, prop, buf, sizeof(buf))) {
741 char *butstr_orig= BLI_strdup(but->str);
742 BLI_snprintf(but->strdata, sizeof(but->strdata), "%s|%s", butstr_orig, buf);
743 MEM_freeN(butstr_orig);
744 but->str= but->strdata;
751 void uiEndBlock(const bContext *C, uiBlock *block)
754 Scene *scene= CTX_data_scene(C);
756 /* inherit flags from 'old' buttons that was drawn here previous, based
757 * on matching buttons, we need this to make button event handling non
758 * blocking, while still alowing buttons to be remade each redraw as it
759 * is expected by blender code */
760 for(but=block->buttons.first; but; but=but->next) {
761 if(ui_but_update_from_old_block(C, block, &but))
764 /* temp? Proper check for greying out */
766 wmOperatorType *ot= but->optype;
769 CTX_store_set((bContext*)C, but->context);
771 if(ot == NULL || WM_operator_poll_context((bContext*)C, ot, but->opcontext)==0) {
772 but->flag |= UI_BUT_DISABLED;
777 CTX_store_set((bContext*)C, NULL);
780 ui_but_anim_flag(but, (scene)? scene->r.cfra: 0.0f);
783 if(block->oldblock) {
784 block->auto_open= block->oldblock->auto_open;
785 block->auto_open_last= block->oldblock->auto_open_last;
786 block->tooltipdisabled= block->oldblock->tooltipdisabled;
788 block->oldblock= NULL;
791 /* handle pending stuff */
792 if(block->layouts.first) uiBlockLayoutResolve(block, NULL, NULL);
793 ui_block_do_align(block);
794 if((block->flag & UI_BLOCK_LOOP) && (block->flag & UI_BLOCK_NUMSELECT)) ui_menu_block_set_keyaccels(block); /* could use a different flag to check */
795 if(block->flag & UI_BLOCK_LOOP) ui_menu_block_set_keymaps(C, block);
798 if(block->dobounds == UI_BLOCK_BOUNDS) ui_bounds_block(block);
799 else if(block->dobounds == UI_BLOCK_BOUNDS_TEXT) ui_text_bounds_block(block, 0.0f);
800 else if(block->dobounds == UI_BLOCK_BOUNDS_POPUP_CENTER) ui_centered_bounds_block(C, block);
801 else if(block->dobounds) ui_popup_bounds_block(C, block, block->dobounds);
803 if(block->minx==0.0f && block->maxx==0.0f) uiBoundsBlock(block, 0);
804 if(block->flag & UI_BUT_ALIGN) uiBlockEndAlign(block);
809 /* ************** BLOCK DRAWING FUNCTION ************* */
811 void ui_fontscale(short *points, float aspect)
813 if(aspect < 0.9f || aspect > 1.1f) {
814 float pointsf= *points;
816 /* for some reason scaling fonts goes too fast compared to widget size */
817 aspect= sqrt(aspect);
821 *points= ceilf(pointsf);
823 *points= floorf(pointsf);
827 /* project button or block (but==NULL) to pixels in regionspace */
828 static void ui_but_to_pixelrect(rcti *rect, const ARegion *ar, uiBlock *block, uiBut *but)
831 float getsizex, getsizey;
836 gx= (but?but->x1:block->minx) + (block->panel?block->panel->ofsx:0.0f);
837 gy= (but?but->y1:block->miny) + (block->panel?block->panel->ofsy:0.0f);
839 rect->xmin= floorf(getsizex*(0.5f+ 0.5f*(gx*block->winmat[0][0]+ gy*block->winmat[1][0]+ block->winmat[3][0])));
840 rect->ymin= floorf(getsizey*(0.5f+ 0.5f*(gx*block->winmat[0][1]+ gy*block->winmat[1][1]+ block->winmat[3][1])));
842 gx= (but?but->x2:block->maxx) + (block->panel?block->panel->ofsx:0.0f);
843 gy= (but?but->y2:block->maxy) + (block->panel?block->panel->ofsy:0.0f);
845 rect->xmax= floorf(getsizex*(0.5f+ 0.5f*(gx*block->winmat[0][0]+ gy*block->winmat[1][0]+ block->winmat[3][0])));
846 rect->ymax= floorf(getsizey*(0.5f+ 0.5f*(gx*block->winmat[0][1]+ gy*block->winmat[1][1]+ block->winmat[3][1])));
850 /* uses local copy of style, to scale things down, and allow widgets to change stuff */
851 void uiDrawBlock(const bContext *C, uiBlock *block)
853 uiStyle style= *((uiStyle *)U.uistyles.first); // XXX pass on as arg
858 /* get menu region or area region */
861 ar= CTX_wm_region(C);
864 uiEndBlock(C, block);
866 /* we set this only once */
867 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
870 ui_fontscale(&style.paneltitle.points, block->aspect);
871 ui_fontscale(&style.grouplabel.points, block->aspect);
872 ui_fontscale(&style.widgetlabel.points, block->aspect);
873 ui_fontscale(&style.widget.points, block->aspect);
875 /* scale block min/max to rect */
876 ui_but_to_pixelrect(&rect, ar, block, NULL);
878 /* pixel space for AA widgets */
879 glMatrixMode(GL_PROJECTION);
881 glMatrixMode(GL_MODELVIEW);
885 wmOrtho2(-0.01f, ar->winx-0.01f, -0.01f, ar->winy-0.01f);
888 if(block->flag & UI_BLOCK_LOOP)
889 ui_draw_menu_back(&style, block, &rect);
890 else if(block->panel)
891 ui_draw_aligned_panel(&style, block, &rect);
894 for(but= block->buttons.first; but; but= but->next) {
895 ui_but_to_pixelrect(&rect, ar, block, but);
897 if(!(but->flag & UI_HIDDEN) &&
898 /* XXX: figure out why invalid coordinates happen when closing render window */
899 /* and material preview is redrawn in main window (temp fix for bug #23848) */
900 rect.xmin < rect.xmax && rect.ymin < rect.ymax)
901 ui_draw_but(C, ar, &style, but, &rect);
905 glMatrixMode(GL_PROJECTION);
907 glMatrixMode(GL_MODELVIEW);
910 ui_draw_links(block);
913 /* ************* EVENTS ************* */
915 static void ui_is_but_sel(uiBut *but)
917 double value; /* only initialized when needed, to avoid calling when not used */
918 short push=0, true=1;
920 if(ELEM3(but->type, TOGN, ICONTOGN, OPTIONN)) true= 0;
924 value= ui_get_but_val(but);
926 if( BTST(lvalue, (but->bitnr)) ) push= true;
945 value= ui_get_but_val(but);
946 if(value != (double)but->hardmin) push= 1;
951 value= ui_get_but_val(but);
952 if(value==0.0) push= 1;
956 value= ui_get_but_val(but);
957 /* support for rna enum buts */
958 if(but->rnaprop && (RNA_property_flag(but->rnaprop) & PROP_ENUM_FLAG)) {
959 if((int)value & (int)but->hardmax) push= 1;
962 if(value == (double)but->hardmax) push= 1;
975 else if(push==1) but->flag |= UI_SELECT;
976 else but->flag &= ~UI_SELECT;
979 static uiBut *ui_find_inlink(uiBlock *block, void *poin)
983 but= block->buttons.first;
985 if(but->type==INLINK) {
986 if(but->poin == poin) return but;
993 static void ui_add_link_line(ListBase *listb, uiBut *but, uiBut *bt)
997 line= MEM_callocN(sizeof(uiLinkLine), "linkline");
998 BLI_addtail(listb, line);
1003 uiBut *uiFindInlink(uiBlock *block, void *poin)
1005 return ui_find_inlink(block, poin);
1008 void uiComposeLinks(uiBlock *block)
1015 but= block->buttons.first;
1017 if(but->type==LINK) {
1020 /* for all pointers in the array */
1024 for(a=0; a < *(link->totlink); a++) {
1025 bt= ui_find_inlink(block, (*ppoin)[a] );
1027 ui_add_link_line(&link->lines, but, bt);
1031 else if(link->poin) {
1032 bt= ui_find_inlink(block, *(link->poin) );
1034 ui_add_link_line(&link->lines, but, bt);
1044 /* ************************************************ */
1046 void uiBlockSetButLock(uiBlock *block, int val, const char *lockstr)
1049 block->lock= val ? 1:0;
1050 block->lockstr= lockstr;
1054 void uiBlockClearButLock(uiBlock *block)
1057 block->lockstr= NULL;
1060 /* *************************************************************** */
1062 void ui_delete_linkline(uiLinkLine *line, uiBut *but)
1067 BLI_remlink(&but->link->lines, line);
1069 link= line->from->link;
1071 /* are there more pointers allowed? */
1074 if(*(link->totlink)==1) {
1075 *(link->totlink)= 0;
1076 MEM_freeN(*(link->ppoin));
1077 *(link->ppoin)= NULL;
1081 for(a=0; a< (*(link->totlink)); a++) {
1083 if( (*(link->ppoin))[a] != line->to->poin ) {
1084 (*(link->ppoin))[b]= (*(link->ppoin))[a];
1088 (*(link->totlink))--;
1092 *(link->poin)= NULL;
1099 /* *********************** data get/set ***********************
1100 * this either works with the pointed to data, or can work with
1101 * an edit override pointer while dragging for example */
1103 /* for buttons pointing to color for example */
1104 void ui_get_but_vectorf(uiBut *but, float *vec)
1110 VECCOPY(vec, but->editvec);
1116 vec[0]= vec[1]= vec[2]= 0.0f;
1118 if(RNA_property_type(prop) == PROP_FLOAT) {
1119 tot= RNA_property_array_length(&but->rnapoin, prop);
1122 for(a=0; a<tot; a++)
1123 vec[a]= RNA_property_float_get_index(&but->rnapoin, prop, a);
1126 else if(but->pointype == CHA) {
1127 char *cp= (char *)but->poin;
1128 vec[0]= ((float)cp[0])/255.0f;
1129 vec[1]= ((float)cp[1])/255.0f;
1130 vec[2]= ((float)cp[2])/255.0f;
1132 else if(but->pointype == FLO) {
1133 float *fp= (float *)but->poin;
1137 if (but->editvec==NULL) {
1138 fprintf(stderr, "ui_get_but_vectorf: can't get color, should never happen\n");
1139 vec[0]= vec[1]= vec[2]= 0.0f;
1144 /* for buttons pointing to color for example */
1145 void ui_set_but_vectorf(uiBut *but, float *vec)
1151 VECCOPY(but->editvec, vec);
1157 if(RNA_property_type(prop) == PROP_FLOAT) {
1158 tot= RNA_property_array_length(&but->rnapoin, prop);
1161 for(a=0; a<tot; a++)
1162 RNA_property_float_set_index(&but->rnapoin, prop, a, vec[a]);
1165 else if(but->pointype == CHA) {
1166 char *cp= (char *)but->poin;
1167 cp[0]= (char)(0.5f + vec[0]*255.0f);
1168 cp[1]= (char)(0.5f + vec[1]*255.0f);
1169 cp[2]= (char)(0.5f + vec[2]*255.0f);
1171 else if(but->pointype == FLO) {
1172 float *fp= (float *)but->poin;
1177 int ui_is_but_float(uiBut *but)
1179 if(but->pointype==FLO && but->poin)
1182 if(but->rnaprop && RNA_property_type(but->rnaprop) == PROP_FLOAT)
1188 int ui_is_but_unit(uiBut *but)
1190 Scene *scene= CTX_data_scene((bContext *)but->block->evil_C);
1191 int unit_type= uiButGetUnitType(but);
1193 if(unit_type == PROP_UNIT_NONE)
1196 #if 1 // removed so angle buttons get correct snapping
1197 if (scene->unit.system_rotation == USER_UNIT_ROT_RADIANS && unit_type == PROP_UNIT_ROTATION)
1201 /* for now disable time unit conversion */
1202 if (unit_type == PROP_UNIT_TIME)
1205 if (scene->unit.system == USER_UNIT_NONE) {
1206 if (unit_type != PROP_UNIT_ROTATION) {
1214 int ui_is_but_rna_valid(uiBut *but)
1216 if (but->rnaprop==NULL || RNA_struct_contains_property(&but->rnapoin, but->rnaprop)) {
1220 printf("property removed %s: %p\n", but->drawstr, but->rnaprop);
1225 double ui_get_but_val(uiBut *but)
1230 if(but->editval) { return *(but->editval); }
1231 if(but->poin==NULL && but->rnapoin.data==NULL) return 0.0;
1236 switch(RNA_property_type(prop)) {
1238 if(RNA_property_array_length(&but->rnapoin, prop))
1239 value= RNA_property_boolean_get_index(&but->rnapoin, prop, but->rnaindex);
1241 value= RNA_property_boolean_get(&but->rnapoin, prop);
1244 if(RNA_property_array_length(&but->rnapoin, prop))
1245 value= RNA_property_int_get_index(&but->rnapoin, prop, but->rnaindex);
1247 value= RNA_property_int_get(&but->rnapoin, prop);
1250 if(RNA_property_array_length(&but->rnapoin, prop))
1251 value= RNA_property_float_get_index(&but->rnapoin, prop, but->rnaindex);
1253 value= RNA_property_float_get(&but->rnapoin, prop);
1256 value= RNA_property_enum_get(&but->rnapoin, prop);
1263 else if(but->type== HSVSLI) {
1266 fp= (but->editvec)? but->editvec: (float *)but->poin;
1267 rgb_to_hsv(fp[0], fp[1], fp[2], &h, &s, &v);
1269 switch(but->str[0]) {
1270 case 'H': value= h; break;
1271 case 'S': value= s; break;
1272 case 'V': value= v; break;
1275 else if( but->pointype == CHA ) {
1276 value= *(char *)but->poin;
1278 else if( but->pointype == SHO ) {
1279 value= *(short *)but->poin;
1281 else if( but->pointype == INT ) {
1282 value= *(int *)but->poin;
1284 else if( but->pointype == FLO ) {
1285 value= *(float *)but->poin;
1291 void ui_set_but_val(uiBut *but, double value)
1295 /* value is a hsv value: convert to rgb */
1299 if(RNA_property_editable(&but->rnapoin, prop)) {
1300 switch(RNA_property_type(prop)) {
1302 if(RNA_property_array_length(&but->rnapoin, prop))
1303 RNA_property_boolean_set_index(&but->rnapoin, prop, but->rnaindex, value);
1305 RNA_property_boolean_set(&but->rnapoin, prop, value);
1308 if(RNA_property_array_length(&but->rnapoin, prop))
1309 RNA_property_int_set_index(&but->rnapoin, prop, but->rnaindex, (int)value);
1311 RNA_property_int_set(&but->rnapoin, prop, (int)value);
1314 if(RNA_property_array_length(&but->rnapoin, prop))
1315 RNA_property_float_set_index(&but->rnapoin, prop, but->rnaindex, value);
1317 RNA_property_float_set(&but->rnapoin, prop, value);
1320 if(RNA_property_flag(prop) & PROP_ENUM_FLAG) {
1321 int ivalue= (int)value;
1322 ivalue ^= RNA_property_enum_get(&but->rnapoin, prop); /* toggle for enum/flag buttons */
1323 RNA_property_enum_set(&but->rnapoin, prop, ivalue);
1326 RNA_property_enum_set(&but->rnapoin, prop, value);
1334 else if(but->pointype==0);
1335 else if(but->type==HSVSLI ) {
1338 fp= (but->editvec)? but->editvec: (float *)but->poin;
1339 rgb_to_hsv(fp[0], fp[1], fp[2], &h, &s, &v);
1341 switch(but->str[0]) {
1342 case 'H': h= value; break;
1343 case 'S': s= value; break;
1344 case 'V': v= value; break;
1347 hsv_to_rgb(h, s, v, fp, fp+1, fp+2);
1351 /* first do rounding */
1352 if(but->pointype==CHA)
1353 value= (char)floor(value+0.5);
1354 else if(but->pointype==SHO ) {
1355 /* gcc 3.2.1 seems to have problems
1356 * casting a double like 32772.0 to
1357 * a short so we cast to an int, then
1360 gcckludge = (int) floor(value+0.5);
1361 value= (short)gcckludge;
1363 else if(but->pointype==INT )
1364 value= (int)floor(value+0.5);
1365 else if(but->pointype==FLO ) {
1366 float fval= (float)value;
1367 if(fval>= -0.00001f && fval<= 0.00001f) fval= 0.0f; /* prevent negative zero */
1371 /* then set value with possible edit override */
1373 *but->editval= value;
1374 else if(but->pointype==CHA)
1375 *((char *)but->poin)= (char)value;
1376 else if(but->pointype==SHO)
1377 *((short *)but->poin)= (short)value;
1378 else if(but->pointype==INT)
1379 *((int *)but->poin)= (int)value;
1380 else if(but->pointype==FLO)
1381 *((float *)but->poin)= (float)value;
1384 /* update select flag */
1388 int ui_get_but_string_max_length(uiBut *but)
1390 if(ELEM(but->type, TEX, SEARCH_MENU))
1391 return but->hardmax;
1392 else if(but->type == IDPOIN)
1393 return MAX_ID_NAME-2;
1395 return UI_MAX_DRAW_STR;
1398 static double ui_get_but_scale_unit(uiBut *but, double value)
1400 Scene *scene= CTX_data_scene((bContext *)but->block->evil_C);
1401 int unit_type= uiButGetUnitType(but);
1403 if(unit_type == PROP_UNIT_LENGTH) {
1404 return value * (double)scene->unit.scale_length;
1406 else if(unit_type == PROP_UNIT_AREA) {
1407 return value * pow(scene->unit.scale_length, 2);
1409 else if(unit_type == PROP_UNIT_VOLUME) {
1410 return value * pow(scene->unit.scale_length, 3);
1412 else if(unit_type == PROP_UNIT_TIME) { /* WARNING - using evil_C :| */
1413 return FRA2TIME(value);
1420 /* str will be overwritten */
1421 void ui_convert_to_unit_alt_name(uiBut *but, char *str, int maxlen)
1423 if(ui_is_but_unit(but)) {
1424 int unit_type= uiButGetUnitType(but);
1426 Scene *scene= CTX_data_scene((bContext *)but->block->evil_C);
1428 orig_str= MEM_callocN(sizeof(char)*maxlen + 1, "textedit sub str");
1429 memcpy(orig_str, str, maxlen);
1431 bUnit_ToUnitAltName(str, maxlen, orig_str, scene->unit.system, unit_type>>16);
1433 MEM_freeN(orig_str);
1437 static void ui_get_but_string_unit(uiBut *but, char *str, int len_max, double value, int pad)
1439 Scene *scene= CTX_data_scene((bContext *)but->block->evil_C);
1440 int do_split= scene->unit.flag & USER_UNIT_OPT_SPLIT;
1441 int unit_type= uiButGetUnitType(but);
1442 int precision= but->a2;
1444 if(scene->unit.scale_length<0.0001f) scene->unit.scale_length= 1.0f; // XXX do_versions
1447 if(precision>7) precision= 7;
1448 else if(precision==0) precision= 2;
1450 bUnit_AsString(str, len_max, ui_get_but_scale_unit(but, value), precision, scene->unit.system, unit_type>>16, do_split, pad);
1453 static float ui_get_but_step_unit(uiBut *but, float step_default)
1455 Scene *scene= CTX_data_scene((bContext *)but->block->evil_C);
1456 int unit_type= uiButGetUnitType(but)>>16;
1459 step = bUnit_ClosestScalar(ui_get_but_scale_unit(but, step_default), scene->unit.system, unit_type);
1461 if(step > 0.0f) { /* -1 is an error value */
1462 return (float)((double)step/ui_get_but_scale_unit(but, 1.0))*100.0f;
1465 return step_default;
1470 void ui_get_but_string(uiBut *but, char *str, int maxlen)
1472 if(but->rnaprop && ELEM3(but->type, TEX, IDPOIN, SEARCH_MENU)) {
1476 type= RNA_property_type(but->rnaprop);
1478 if(type == PROP_STRING) {
1480 buf= RNA_property_string_get_alloc(&but->rnapoin, but->rnaprop, str, maxlen);
1482 else if(type == PROP_POINTER) {
1484 PointerRNA ptr= RNA_property_pointer_get(&but->rnapoin, but->rnaprop);
1485 buf= RNA_struct_name_get_alloc(&ptr, str, maxlen);
1491 else if(buf && buf != str) {
1492 /* string was too long, we have to truncate */
1493 BLI_strncpy(str, buf, maxlen);
1497 else if(but->type == IDPOIN) {
1499 if(but->idpoin_idpp) { /* Can be NULL for ID properties by python */
1500 ID *id= *(but->idpoin_idpp);
1502 BLI_strncpy(str, id->name+2, maxlen);
1509 else if(but->type == TEX) {
1511 BLI_strncpy(str, but->poin, maxlen);
1514 else if(but->type == SEARCH_MENU) {
1516 BLI_strncpy(str, but->poin, maxlen);
1519 else if(ui_but_anim_expression_get(but, str, maxlen))
1520 ; /* driver expression */
1522 /* number editing */
1525 value= ui_get_but_val(but);
1527 if(ui_is_but_float(but)) {
1528 if(ui_is_but_unit(but)) {
1529 ui_get_but_string_unit(but, str, maxlen, value, 0);
1532 int prec= (int)but->a2;
1533 if(prec==0) prec= 3;
1534 else CLAMP(prec, 1, 7);
1536 BLI_snprintf(str, maxlen, "%.*f", prec, value);
1540 BLI_snprintf(str, maxlen, "%d", (int)value);
1546 static int ui_set_but_string_eval_num_unit(bContext *C, uiBut *but, const char *str, double *value)
1548 char str_unit_convert[256];
1549 const int unit_type= uiButGetUnitType(but);
1550 Scene *scene= CTX_data_scene((bContext *)but->block->evil_C);
1552 BLI_strncpy(str_unit_convert, str, sizeof(str_unit_convert));
1554 /* ugly, use the draw string to get the value, this could cause problems if it includes some text which resolves to a unit */
1555 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);
1557 return (BPY_button_exec(C, str_unit_convert, value, TRUE) != -1);
1560 static int ui_set_but_string_eval_num(bContext *C, uiBut *but, const char *str, double *value)
1564 if(str[0] != '\0') {
1565 int is_unit_but= ui_is_but_unit(but);
1566 /* only enable verbose if we won't run again with units */
1567 if(BPY_button_exec(C, str, value, is_unit_but==FALSE) != -1) {
1568 /* if the value parsed ok without unit conversion this button may still need a unit multiplier */
1572 BLI_snprintf(str_new, sizeof(str_new), "%f", *value);
1573 ok= ui_set_but_string_eval_num_unit(C, but, str_new, value);
1576 ok= TRUE; /* parse normal string via py (no unit conversion needed) */
1579 else if(is_unit_but) {
1580 /* parse failed, this is a unit but so run replacements and parse again */
1581 ok= ui_set_but_string_eval_num_unit(C, but, str, value);
1588 #endif // WITH_PYTHON
1590 int ui_set_but_string(bContext *C, uiBut *but, const char *str)
1592 if(but->rnaprop && ELEM3(but->type, TEX, IDPOIN, SEARCH_MENU)) {
1593 if(RNA_property_editable(&but->rnapoin, but->rnaprop)) {
1596 type= RNA_property_type(but->rnaprop);
1598 if(type == PROP_STRING) {
1600 RNA_property_string_set(&but->rnapoin, but->rnaprop, str);
1603 else if(type == PROP_POINTER) {
1605 PointerRNA ptr, rptr;
1608 if(str == NULL || str[0] == '\0') {
1609 RNA_property_pointer_set(&but->rnapoin, but->rnaprop, PointerRNA_NULL);
1613 ptr= but->rnasearchpoin;
1614 prop= but->rnasearchprop;
1616 if(prop && RNA_property_collection_lookup_string(&ptr, prop, str, &rptr))
1617 RNA_property_pointer_set(&but->rnapoin, but->rnaprop, rptr);
1626 else if(but->type == IDPOIN) {
1628 but->idpoin_func(C, str, but->idpoin_idpp);
1631 else if(but->type == TEX) {
1633 BLI_strncpy(but->poin, str, but->hardmax);
1636 else if(but->type == SEARCH_MENU) {
1638 BLI_strncpy(but->poin, str, but->hardmax);
1641 else if(ui_but_anim_expression_set(but, str)) {
1642 /* driver expression */
1646 /* number editing */
1650 if(ui_set_but_string_eval_num(C, but, str, &value) == FALSE) {
1655 #endif // WITH_PYTHON
1657 if(!ui_is_but_float(but)) value= (int)floor(value + 0.5);
1658 if(but->type==NUMABS) value= fabs(value);
1660 /* not that we use hard limits here */
1661 if(value < (double)but->hardmin) value= but->hardmin;
1662 if(value > (double)but->hardmax) value= but->hardmax;
1664 ui_set_but_val(but, value);
1671 void ui_set_but_default(bContext *C, uiBut *but, short all)
1673 /* if there is a valid property that is editable... */
1674 if (but->rnapoin.data && but->rnaprop && RNA_property_editable(&but->rnapoin, but->rnaprop)) {
1675 int index = (all)? -1 : but->rnaindex;
1677 if(RNA_property_reset(&but->rnapoin, but->rnaprop, index)) {
1678 /* perform updates required for this property */
1679 RNA_property_update(C, &but->rnapoin, but->rnaprop);
1684 static double soft_range_round_up(double value, double max)
1686 /* round up to .., 0.1, 0.2, 0.5, 1, 2, 5, 10, 20, 50, .. */
1687 double newmax= pow(10.0, ceil(log(value)/log(10.0)));
1689 if(newmax*0.2 >= max && newmax*0.2 >= value)
1691 else if(newmax*0.5 >= max && newmax*0.5 >= value)
1697 static double soft_range_round_down(double value, double max)
1699 /* round down to .., 0.1, 0.2, 0.5, 1, 2, 5, 10, 20, 50, .. */
1700 double newmax= pow(10.0, floor(log(value)/log(10.0)));
1702 if(newmax*5.0 <= max && newmax*5.0 <= value)
1704 else if(newmax*2.0 <= max && newmax*2.0 <= value)
1710 void ui_set_but_soft_range(uiBut *but, double value)
1713 double softmin, softmax /*, step, precision*/;
1716 type= RNA_property_type(but->rnaprop);
1718 /* clamp button range to something reasonable in case
1719 * we get -inf/inf from RNA properties */
1720 if(type == PROP_INT) {
1721 int imin, imax, istep;
1723 RNA_property_int_ui_range(&but->rnapoin, but->rnaprop, &imin, &imax, &istep);
1724 softmin= (imin == INT_MIN)? -1e4: imin;
1725 softmax= (imin == INT_MAX)? 1e4: imax;
1726 /*step= istep;*/ /*UNUSED*/
1727 /*precision= 1;*/ /*UNUSED*/
1729 else if(type == PROP_FLOAT) {
1730 float fmin, fmax, fstep, fprecision;
1732 RNA_property_float_ui_range(&but->rnapoin, but->rnaprop, &fmin, &fmax, &fstep, &fprecision);
1733 softmin= (fmin == -FLT_MAX)? (float)-1e4: fmin;
1734 softmax= (fmax == FLT_MAX)? (float)1e4: fmax;
1735 /*step= fstep;*/ /*UNUSED*/
1736 /*precision= fprecision;*/ /*UNUSED*/
1741 /* if the value goes out of the soft/max range, adapt the range */
1742 if(value+1e-10 < softmin) {
1744 softmin= -soft_range_round_up(-value, -softmin);
1746 softmin= soft_range_round_down(value, softmin);
1748 if(softmin < (double)but->hardmin)
1749 softmin= (double)but->hardmin;
1751 else if(value-1e-10 > softmax) {
1753 softmax= -soft_range_round_down(-value, -softmax);
1755 softmax= soft_range_round_up(value, softmax);
1757 if(softmax > (double)but->hardmax)
1758 softmax= but->hardmax;
1761 but->softmin= softmin;
1762 but->softmax= softmax;
1766 /* ******************* Free ********************/
1768 static void ui_free_link(uiLink *link)
1771 BLI_freelistN(&link->lines);
1776 /* can be called with C==NULL */
1777 static void ui_free_but(const bContext *C, uiBut *but)
1780 WM_operator_properties_free(but->opptr);
1781 MEM_freeN(but->opptr);
1783 if(but->func_argN) MEM_freeN(but->func_argN);
1785 /* XXX solve later, buttons should be free-able without context ideally,
1786 however they may have open tooltips or popup windows, which need to
1787 be closed using a context pointer */
1789 ui_button_active_free(C, but);
1792 MEM_freeN(but->active);
1794 if(but->str && but->str != but->strdata) MEM_freeN(but->str);
1795 ui_free_link(but->link);
1800 /* can be called with C==NULL */
1801 void uiFreeBlock(const bContext *C, uiBlock *block)
1805 while( (but= block->buttons.first) ) {
1806 BLI_remlink(&block->buttons, but);
1807 ui_free_but(C, but);
1810 if(block->func_argN)
1811 MEM_freeN(block->func_argN);
1813 CTX_store_free_list(&block->contexts);
1815 BLI_freelistN(&block->saferct);
1820 /* can be called with C==NULL */
1821 void uiFreeBlocks(const bContext *C, ListBase *lb)
1825 while( (block= lb->first) ) {
1826 BLI_remlink(lb, block);
1827 uiFreeBlock(C, block);
1831 void uiFreeInactiveBlocks(const bContext *C, ListBase *lb)
1833 uiBlock *block, *nextblock;
1835 for(block=lb->first; block; block=nextblock) {
1836 nextblock= block->next;
1838 if(!block->handle) {
1839 if(!block->active) {
1840 BLI_remlink(lb, block);
1841 uiFreeBlock(C, block);
1849 void uiBlockSetRegion(uiBlock *block, ARegion *region)
1852 uiBlock *oldblock= NULL;
1854 lb= ®ion->uiblocks;
1856 /* each listbase only has one block with this name, free block
1857 * if is already there so it can be rebuilt from scratch */
1859 for (oldblock= lb->first; oldblock; oldblock= oldblock->next)
1860 if (BLI_streq(oldblock->name, block->name))
1864 oldblock->active= 0;
1865 oldblock->panel= NULL;
1869 block->oldblock= oldblock;
1871 /* at the beginning of the list! for dynamical menus/blocks */
1873 BLI_addhead(lb, block);
1876 uiBlock *uiBeginBlock(const bContext *C, ARegion *region, const char *name, short dt)
1881 int getsizex, getsizey;
1883 window= CTX_wm_window(C);
1884 scn = CTX_data_scene(C);
1886 block= MEM_callocN(sizeof(uiBlock), "uiBlock");
1889 block->evil_C= (void*)C; // XXX
1890 if (scn) block->color_profile= (scn->r.color_mgt_flag & R_COLOR_MANAGEMENT);
1891 BLI_strncpy(block->name, name, sizeof(block->name));
1894 uiBlockSetRegion(block, region);
1896 /* window matrix and aspect */
1897 if(region && region->swinid) {
1898 wm_subwindow_getmatrix(window, region->swinid, block->winmat);
1899 wm_subwindow_getsize(window, region->swinid, &getsizex, &getsizey);
1901 /* TODO - investigate why block->winmat[0][0] is negative
1902 * in the image view when viewRedrawForce is called */
1903 block->aspect= 2.0/fabs( (getsizex)*block->winmat[0][0]);
1906 /* no subwindow created yet, for menus for example, so we
1907 * use the main window instead, since buttons are created
1909 wm_subwindow_getmatrix(window, window->screen->mainwin, block->winmat);
1910 wm_subwindow_getsize(window, window->screen->mainwin, &getsizex, &getsizey);
1912 block->aspect= 2.0/fabs(getsizex*block->winmat[0][0]);
1913 block->auto_open= 2;
1914 block->flag |= UI_BLOCK_LOOP; /* tag as menu */
1920 uiBlock *uiGetBlock(const char *name, ARegion *ar)
1922 return BLI_findstring(&ar->uiblocks, name, offsetof(uiBlock, name));
1925 void uiBlockSetEmboss(uiBlock *block, char dt)
1930 void ui_check_but(uiBut *but)
1932 /* if something changed in the button */
1934 // float okwidth; // UNUSED
1935 // int transopts= ui_translate_buttons();
1939 // if(but->type==TEX || but->type==IDPOIN) transopts= 0;
1941 /* only update soft range while not editing */
1942 if(but->rnaprop && !(but->editval || but->editstr || but->editvec))
1943 ui_set_but_soft_range(but, ui_get_but_val(but));
1945 /* test for min and max, icon sliders, etc */
1946 switch( but->type ) {
1952 value= ui_get_but_val(but);
1953 if(value < (double)but->hardmin) ui_set_but_val(but, but->hardmin);
1954 else if(value > (double)but->hardmax) ui_set_but_val(but, but->hardmax);
1958 value= fabs( ui_get_but_val(but) );
1959 if(value < (double)but->hardmin) ui_set_but_val(but, but->hardmin);
1960 else if(value > (double)but->hardmax) ui_set_but_val(but, but->hardmax);
1965 if(!but->rnaprop || (RNA_property_flag(but->rnaprop) & PROP_ICONS_CONSECUTIVE)) {
1966 if(but->flag & UI_SELECT) but->iconadd= 1;
1967 else but->iconadd= 0;
1972 if(!but->rnaprop || (RNA_property_flag(but->rnaprop) & PROP_ICONS_CONSECUTIVE)) {
1973 value= ui_get_but_val(but);
1974 but->iconadd= (int)value- (int)(but->hardmin);
1979 if(!but->rnaprop || (RNA_property_flag(but->rnaprop) & PROP_ICONS_CONSECUTIVE)) {
1980 value= ui_get_but_val(but);
1981 but->iconadd= (int)value- (int)(but->hardmin);
1987 /* safety is 4 to enable small number buttons (like 'users') */
1988 // okwidth= -4 + (but->x2 - but->x1); // UNUSED
1991 switch( but->type ) {
1996 if(but->x2 - but->x1 > 24) {
1997 value= ui_get_but_val(but);
1998 ui_set_name_menu(but, (int)value);
2007 value= ui_get_but_val(but);
2009 if(ui_is_but_float(but)) {
2010 if(value == (double) FLT_MAX) sprintf(but->drawstr, "%sinf", but->str);
2011 else if(value == (double) -FLT_MAX) sprintf(but->drawstr, "%s-inf", but->str);
2012 /* support length type buttons */
2013 else if(ui_is_but_unit(but)) {
2014 char new_str[sizeof(but->drawstr)];
2015 ui_get_but_string_unit(but, new_str, sizeof(new_str), value, TRUE);
2016 BLI_snprintf(but->drawstr, sizeof(but->drawstr), "%s%s", but->str, new_str);
2019 int prec= (int)but->a2;
2020 if(prec==0) prec= (but->hardmax < 10.001f) ? 3 : 2;
2021 else CLAMP(prec, 1, 7);
2023 BLI_snprintf(but->drawstr, sizeof(but->drawstr), "%s%.*f", but->str, prec, value);
2027 sprintf(but->drawstr, "%s%d", but->str, (int)value);
2031 PropertySubType pstype = RNA_property_subtype(but->rnaprop);
2033 if (pstype == PROP_PERCENTAGE)
2034 strcat(but->drawstr, "%");
2039 if(ui_is_but_float(but)) {
2040 int prec= (int)but->a2;
2041 value= ui_get_but_val(but);
2042 if(prec==0) prec= 3;
2043 else CLAMP(prec, 1, 7);
2045 BLI_snprintf(but->drawstr, sizeof(but->drawstr), "%s%.*f", but->str, prec, value);
2048 strncpy(but->drawstr, but->str, UI_MAX_DRAW_STR);
2057 char str[UI_MAX_DRAW_STR];
2059 ui_get_but_string(but, str, UI_MAX_DRAW_STR-strlen(but->str));
2061 BLI_snprintf(but->drawstr, sizeof(but->drawstr), "%s%s", but->str, str);
2066 strncpy(but->drawstr, but->str, UI_MAX_DRAW_STR);
2067 if (but->flag & UI_SELECT) {
2068 strcat(but->drawstr, "Press a key");
2070 strcat(but->drawstr, WM_key_event_string((short) ui_get_but_val(but)));
2075 if (but->flag & UI_SELECT) {
2076 but->drawstr[0]= '\0';
2078 if(but->modifier_key) {
2079 char *str= but->drawstr;
2081 if(but->modifier_key & KM_SHIFT)
2082 str= strcat(str, "Shift ");
2083 if(but->modifier_key & KM_CTRL)
2084 str= strcat(str, "Ctrl ");
2085 if(but->modifier_key & KM_ALT)
2086 str= strcat(str, "Alt ");
2087 if(but->modifier_key & KM_OSKEY)
2088 str= strcat(str, "Cmd ");
2090 (void)str; /* UNUSED */
2093 strcat(but->drawstr, "Press a key ");
2096 strncpy(but->drawstr, but->str, UI_MAX_DRAW_STR);
2101 /* trying to get the dual-icon to left of text... not very nice */
2103 strncpy(but->drawstr, " ", UI_MAX_DRAW_STR);
2104 strncpy(but->drawstr+2, but->str, UI_MAX_DRAW_STR-2);
2112 strncpy(but->drawstr, but->str, UI_MAX_DRAW_STR);
2116 /* if we are doing text editing, this will override the drawstr */
2118 strncpy(but->drawstr, but->editstr, UI_MAX_DRAW_STR);
2120 /* text clipping moved to widget drawing code itself */
2124 void uiBlockBeginAlign(uiBlock *block)
2126 /* if other align was active, end it */
2127 if(block->flag & UI_BUT_ALIGN) uiBlockEndAlign(block);
2129 block->flag |= UI_BUT_ALIGN_DOWN;
2132 /* buttons declared after this call will get this align nr */ // XXX flag?
2135 static int buts_are_horiz(uiBut *but1, uiBut *but2)
2139 dx= fabs( but1->x2 - but2->x1);
2140 dy= fabs( but1->y1 - but2->y2);
2142 if(dx > dy) return 0;
2146 void uiBlockEndAlign(uiBlock *block)
2148 block->flag &= ~UI_BUT_ALIGN; // all 4 flags
2151 int ui_but_can_align(uiBut *but)
2153 return !ELEM3(but->type, LABEL, OPTION, OPTIONN);
2156 static void ui_block_do_align_but(uiBut *first, int nr)
2158 uiBut *prev, *but=NULL, *next;
2159 int flag= 0, cols=0, rows=0;
2163 for(but=first; but && but->alignnr == nr; but=but->next) {
2164 if(but->next && but->next->alignnr == nr) {
2165 if(buts_are_horiz(but, but->next)) cols++;
2170 /* rows==0: 1 row, cols==0: 1 collumn */
2172 /* note; how it uses 'flag' in loop below (either set it, or OR it) is confusing */
2173 for(but=first, prev=NULL; but && but->alignnr == nr; prev=but, but=but->next) {
2175 if(next && next->alignnr != nr)
2178 /* clear old flag */
2179 but->flag &= ~UI_BUT_ALIGN;
2181 if(flag==0) { /* first case */
2183 if(buts_are_horiz(but, next)) {
2185 flag= UI_BUT_ALIGN_RIGHT;
2187 flag= UI_BUT_ALIGN_DOWN|UI_BUT_ALIGN_RIGHT;
2190 flag= UI_BUT_ALIGN_DOWN;
2194 else if(next==NULL) { /* last case */
2196 if(buts_are_horiz(prev, but)) {
2198 flag= UI_BUT_ALIGN_LEFT;
2200 flag= UI_BUT_ALIGN_TOP|UI_BUT_ALIGN_LEFT;
2202 else flag= UI_BUT_ALIGN_TOP;
2205 else if(buts_are_horiz(but, next)) {
2206 /* check if this is already second row */
2207 if( prev && buts_are_horiz(prev, but)==0) {
2208 flag &= ~UI_BUT_ALIGN_LEFT;
2209 flag |= UI_BUT_ALIGN_TOP;
2210 /* exception case: bottom row */
2213 while(bt && bt->alignnr == nr) {
2214 if(bt->next && bt->next->alignnr == nr && buts_are_horiz(bt, bt->next)==0 ) break;
2217 if(bt==NULL || bt->alignnr != nr) flag= UI_BUT_ALIGN_TOP|UI_BUT_ALIGN_RIGHT;
2220 else flag |= UI_BUT_ALIGN_LEFT;
2224 flag |= UI_BUT_ALIGN_TOP;
2226 else { /* next button switches to new row */
2228 if(prev && buts_are_horiz(prev, but))
2229 flag |= UI_BUT_ALIGN_LEFT;
2231 flag &= ~UI_BUT_ALIGN_LEFT;
2232 flag |= UI_BUT_ALIGN_TOP;
2235 if( (flag & UI_BUT_ALIGN_TOP)==0) { /* stil top row */
2237 if(next && buts_are_horiz(but, next))
2238 flag = UI_BUT_ALIGN_DOWN|UI_BUT_ALIGN_LEFT|UI_BUT_ALIGN_RIGHT;
2240 /* last button in top row */
2241 flag = UI_BUT_ALIGN_DOWN|UI_BUT_ALIGN_LEFT;
2245 flag |= UI_BUT_ALIGN_DOWN;
2248 flag |= UI_BUT_ALIGN_TOP;
2254 /* merge coordinates */
2258 but->x1= (prev->x2+but->x1)/2.0f;
2262 but->y2= (prev->y1+but->y2)/2.0f;
2266 if(buts_are_horiz(prev, but)) {
2267 but->x1= (prev->x2+but->x1)/2.0f;
2269 /* copy height too */
2272 else if(prev->prev && buts_are_horiz(prev->prev, prev)==0) {
2273 /* the previous button is a single one in its row */
2274 but->y2= (prev->y1+but->y2)/2.0f;
2278 if(next && buts_are_horiz(but, next)==0)
2282 /* the previous button is not a single one in its row */
2290 void ui_block_do_align(uiBlock *block)
2295 /* align buttons with same align nr */
2296 for(but=block->buttons.first; but;) {
2299 ui_block_do_align_but(but, nr);
2301 /* skip with same number */
2302 for(; but && but->alignnr == nr; but=but->next);
2313 ui_def_but is the function that draws many button types
2316 "a1" Click Step (how much to change the value each click)
2317 "a2" Number of decimal point values to display. 0 defaults to 3 (0.000) 1,2,3, and a maximum of 4,
2318 all greater values will be clamped to 4.
2321 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)
2326 if(type & BUTPOIN) { /* a pointer is required */
2331 but= MEM_callocN(sizeof(uiBut), "uiBut");
2333 but->type= type & BUTTYPE;
2334 but->pointype= type & BUTPOIN;
2335 but->bit= type & BIT;
2336 but->bitnr= type & 31;
2340 but->retval= retval;
2343 if(slen >= UI_MAX_NAME_STR-1) {
2344 but->str= MEM_mallocN(slen+2, "ui_def_but str"); /* why +2 ? */
2347 but->str= but->strdata;
2349 memcpy(but->str, str, slen+1);
2357 but->hardmin= but->softmin= min;
2358 but->hardmax= but->softmax= max;
2363 but->lock= block->lock;
2364 but->lockstr= block->lockstr;
2367 but->aspect= 1.0f; //XXX block->aspect;
2368 but->block= block; // pointer back, used for frontbuffer status, and picker
2370 if((block->flag & UI_BUT_ALIGN) && ui_but_can_align(but))
2371 but->alignnr= block->alignnr;
2373 but->func= block->func;
2374 but->func_arg1= block->func_arg1;
2375 but->func_arg2= block->func_arg2;
2377 but->funcN= block->funcN;
2378 if(block->func_argN)
2379 but->func_argN= MEM_dupallocN(block->func_argN);
2381 but->pos= -1; /* cursor invisible */
2383 if(ELEM4(but->type, NUM, NUMABS, NUMSLI, HSVSLI)) { /* add a space to name */
2384 slen= strlen(but->str);
2385 if(slen>0 && slen<UI_MAX_NAME_STR-2) {
2386 if(but->str[slen-1]!=' ') {
2387 but->str[slen]= ' ';
2388 but->str[slen+1]= 0;
2393 if((block->flag & UI_BLOCK_LOOP) || ELEM8(but->type, MENU, TEX, LABEL, IDPOIN, BLOCK, BUTM, SEARCH_MENU, PROGRESSBAR))
2394 but->flag |= (UI_TEXT_LEFT|UI_ICON_LEFT);
2395 else if(but->type==BUT_TOGDUAL)
2396 but->flag |= UI_ICON_LEFT;
2398 but->flag |= (block->flag & UI_BUT_ALIGN);
2402 but->flag |= UI_BUT_DISABLED;
2406 /* keep track of UI_interface.h */
2407 if(ELEM7(but->type, BLOCK, BUT, LABEL, PULLDOWN, ROUNDBOX, LISTBOX, BUTM));
2408 else if(ELEM3(but->type, SCROLL, SEPR, FTPREVIEW));
2409 else if(but->type >= SEARCH_MENU);
2410 else but->flag |= UI_BUT_UNDO;
2412 BLI_addtail(&block->buttons, but);
2414 if(block->curlayout)
2415 ui_layout_add_but(block->curlayout, but);
2420 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)
2424 PropertyType proptype;
2425 int freestr= 0, icon= 0;
2427 prop= RNA_struct_find_property(ptr, propname);
2430 proptype= RNA_property_type(prop);
2432 /* use rna values if parameters are not specified */
2434 if(type == MENU && proptype == PROP_ENUM) {
2435 EnumPropertyItem *item;
2437 int i, totitem, value, free;
2439 RNA_property_enum_items(block->evil_C, ptr, prop, &item, &totitem, &free);
2440 value= RNA_property_enum_get(ptr, prop);
2442 dynstr= BLI_dynstr_new();
2443 BLI_dynstr_appendf(dynstr, "%s%%t", RNA_property_ui_name(prop));
2444 for(i=0; i<totitem; i++) {
2445 if(!item[i].identifier[0]) {
2447 BLI_dynstr_appendf(dynstr, "|%s%%l", item[i].name);
2449 BLI_dynstr_append(dynstr, "|%l");
2451 else if(item[i].icon)
2452 BLI_dynstr_appendf(dynstr, "|%s %%i%d %%x%d", item[i].name, item[i].icon, item[i].value);
2454 BLI_dynstr_appendf(dynstr, "|%s %%x%d", item[i].name, item[i].value);
2456 if(value == item[i].value) {
2459 tip= item[i].description;
2462 str= BLI_dynstr_get_cstring(dynstr);
2463 BLI_dynstr_free(dynstr);
2470 else if(ELEM(type, ROW, LISTROW) && proptype == PROP_ENUM) {
2471 EnumPropertyItem *item;
2472 int i, totitem, free;
2474 RNA_property_enum_items(block->evil_C, ptr, prop, &item, &totitem, &free);
2475 for(i=0; i<totitem; i++) {
2476 if(item[i].identifier[0] && item[i].value == (int)max) {
2483 str= RNA_property_ui_name(prop);
2488 str= RNA_property_ui_name(prop);
2489 icon= RNA_property_ui_icon(prop);
2494 if(type == ROW && proptype == PROP_ENUM) {
2495 EnumPropertyItem *item;
2496 int i, totitem, free;
2498 RNA_property_enum_items(block->evil_C, ptr, prop, &item, &totitem, &free);
2500 for(i=0; i<totitem; i++) {
2501 if(item[i].identifier[0] && item[i].value == (int)max) {
2502 if(item[i].description[0])
2503 tip= item[i].description;
2514 tip= RNA_property_ui_description(prop);
2516 if(min == max || a1 == -1 || a2 == -1) {
2517 if(proptype == PROP_INT) {
2518 int hardmin, hardmax, softmin, softmax, step;
2520 RNA_property_int_range(ptr, prop, &hardmin, &hardmax);
2521 RNA_property_int_ui_range(ptr, prop, &softmin, &softmax, &step);
2523 if(!ELEM(type, ROW, LISTROW) && min == max) {
2532 else if(proptype == PROP_FLOAT) {
2533 float hardmin, hardmax, softmin, softmax, step, precision;
2535 RNA_property_float_range(ptr, prop, &hardmin, &hardmax);
2536 RNA_property_float_ui_range(ptr, prop, &softmin, &softmax, &step, &precision);
2538 if(!ELEM(type, ROW, LISTROW) && min == max) {
2547 else if(proptype == PROP_STRING) {
2549 max= RNA_property_string_maxlength(prop);
2550 if(max == 0) /* interface code should ideally support unlimited length */
2551 max= UI_MAX_DRAW_STR;
2556 RNA_warning("ui_def_but_rna: property not found: %s.%s\n", RNA_struct_identifier(ptr->type), propname);
2560 /* now create button */
2561 but= ui_def_but(block, type, retval, str, x1, y1, x2, y2, NULL, min, max, a1, a2, tip);
2567 if(RNA_property_array_length(&but->rnapoin, but->rnaprop))
2568 but->rnaindex= index;
2574 but->icon= (BIFIconID)icon;
2575 but->flag |= UI_HAS_ICON;
2576 but->flag|= UI_ICON_LEFT;
2579 if (!prop || !RNA_property_editable(&but->rnapoin, prop)) {
2580 but->flag |= UI_BUT_DISABLED;
2585 /* If this button uses units, calculate the step from this */
2586 if(ui_is_but_unit(but))
2587 but->a1= ui_get_but_step_unit(but, but->a1);
2590 MEM_freeN((void *)str);
2595 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)
2600 ot= WM_operatortype_find(opname, 0);
2603 if(ot) str= ot->name;
2607 if ((!tip || tip[0]=='\0') && ot && ot->description) {
2608 tip= ot->description;
2611 but= ui_def_but(block, type, -1, str, x1, y1, x2, y2, NULL, 0, 0, 0, 0, tip);
2613 but->opcontext= opcontext;
2616 but->flag |= UI_BUT_DISABLED;
2624 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)
2629 ot= WM_operatortype_find(opname, 0);
2632 if(ot) str= ot->name;
2636 if ((!tip || tip[0]=='\0') && ot && ot->description) {
2637 tip= ot->description;
2640 but= ui_def_but(block, type, -1, str, x1, y1, x2, y2, poin, min, max, a1, a2, tip);
2642 but->opcontext= opcontext;
2645 but->flag |= UI_BUT_DISABLED;
2653 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)
2655 uiBut *but= ui_def_but(block, type, retval, str, x1, y1, x2, y2, poin, min, max, a1, a2, tip);
2662 /* if _x_ is a power of two (only one bit) return the power,
2663 * otherwise return -1.
2664 * (1<<findBitIndex(x))==x for powers of two.
2666 static int findBitIndex(unsigned int x) {
2667 if (!x || (x&(x-1))!=0) { /* x&(x-1) strips lowest bit */
2672 if (x&0xFFFF0000) idx+=16, x>>=16;
2673 if (x&0xFF00) idx+=8, x>>=8;
2674 if (x&0xF0) idx+=4, x>>=4;
2675 if (x&0xC) idx+=2, x>>=2;
2682 /* autocomplete helper functions */
2683 struct AutoComplete {
2686 const char *startname;
2689 AutoComplete *autocomplete_begin(const char *startname, int maxlen)
2691 AutoComplete *autocpl;
2693 autocpl= MEM_callocN(sizeof(AutoComplete), "AutoComplete");
2694 autocpl->maxlen= maxlen;
2695 autocpl->truncate= MEM_callocN(sizeof(char)*maxlen, "AutoCompleteTruncate");
2696 autocpl->startname= startname;
2701 void autocomplete_do_name(AutoComplete *autocpl, const char *name)
2703 char *truncate= autocpl->truncate;
2704 const char *startname= autocpl->startname;
2707 for(a=0; a<autocpl->maxlen-1; a++) {
2708 if(startname[a]==0 || startname[a]!=name[a])
2712 if(startname[a]==0) {
2715 BLI_strncpy(truncate, name, autocpl->maxlen);
2717 /* remove from truncate what is not in bone->name */
2718 for(a=0; a<autocpl->maxlen-1; a++) {
2723 else if(truncate[a]!=name[a])
2730 void autocomplete_end(AutoComplete *autocpl, char *autoname)
2732 if(autocpl->truncate[0])
2733 BLI_strncpy(autoname, autocpl->truncate, autocpl->maxlen);
2735 if (autoname != autocpl->startname) /* dont copy a string over its self */
2736 BLI_strncpy(autoname, autocpl->startname, autocpl->maxlen);
2738 MEM_freeN(autocpl->truncate);
2742 /* autocomplete callback for ID buttons */
2743 static void autocomplete_id(bContext *C, char *str, void *arg_v)
2745 int blocktype= (intptr_t)arg_v;
2746 ListBase *listb= which_libbase(CTX_data_main(C), blocktype);
2748 if(listb==NULL) return;
2750 /* search if str matches the beginning of an ID struct */
2752 AutoComplete *autocpl= autocomplete_begin(str, 22);
2755 for(id= listb->first; id; id= id->next)
2756 autocomplete_do_name(autocpl, id->name+2);
2758 autocomplete_end(autocpl, str);
2762 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)
2764 int bitIdx= findBitIndex(bit);
2768 return uiDefBut(block, type|BIT|bitIdx, retval, str, x1, y1, x2, y2, poin, min, max, a1, a2, tip);
2771 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)
2773 return uiDefBut(block, type|FLO, retval, str, x1, y1, x2, y2, (void*) poin, min, max, a1, a2, tip);
2775 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)
2777 return uiDefButBit(block, type|FLO, bit, retval, str, x1, y1, x2, y2, (void*) poin, min, max, a1, a2, tip);
2779 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)
2781 return uiDefBut(block, type|INT, retval, str, x1, y1, x2, y2, (void*) poin, min, max, a1, a2, tip);
2783 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)
2785 return uiDefButBit(block, type|INT, bit, retval, str, x1, y1, x2, y2, (void*) poin, min, max, a1, a2, tip);
2787 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)
2789 return uiDefBut(block, type|SHO, retval, str, x1, y1, x2, y2, (void*) poin, min, max, a1, a2, tip);
2791 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)
2793 return uiDefButBit(block, type|SHO, bit, retval, str, x1, y1, x2, y2, (void*) poin, min, max, a1, a2, tip);
2795 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)
2797 return uiDefBut(block, type|CHA, retval, str, x1, y1, x2, y2, (void*) poin, min, max, a1, a2, tip);
2799 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)
2801 return uiDefButBit(block, type|CHA, bit, retval, str, x1, y1, x2, y2, (void*) poin, min, max, a1, a2, tip);
2803 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)
2807 but= ui_def_but_rna(block, type, retval, str, x1, y1, x2, y2, ptr, propname, index, min, max, a1, a2, tip);
2813 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)
2817 but= ui_def_but_operator(block, type, opname, opcontext, str, x1, y1, x2, y2, tip);
2824 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)
2826 uiBut *but= ui_def_but_operator_text(block, type, opname, opcontext, str, x1, y1, x2, y2, poin, min, max, a1, a2, tip);
2834 /* if a1==1.0 then a2 is an extra icon blending factor (alpha 0.0 - 1.0) */
2835 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)
2837 uiBut *but= ui_def_but(block, type, retval, "", x1, y1, x2, y2, poin, min, max, a1, a2, tip);
2839 but->icon= (BIFIconID) icon;
2840 but->flag|= UI_HAS_ICON;
2846 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)
2848 int bitIdx= findBitIndex(bit);
2852 return uiDefIconBut(block, type|BIT|bitIdx, retval, icon, x1, y1, x2, y2, poin, min, max, a1, a2, tip);
2856 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)
2858 return uiDefIconBut(block, type|FLO, retval, icon, x1, y1, x2, y2, (void*) poin, min, max, a1, a2, tip);
2860 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)
2862 return uiDefIconButBit(block, type|FLO, bit, retval, icon, x1, y1, x2, y2, (void*) poin, min, max, a1, a2, tip);
2864 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)
2866 return uiDefIconBut(block, type|INT, retval, icon, x1, y1, x2, y2, (void*) poin, min, max, a1, a2, tip);
2868 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)
2870 return uiDefIconButBit(block, type|INT, bit, retval, icon, x1, y1, x2, y2, (void*) poin, min, max, a1, a2, tip);
2872 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)
2874 return uiDefIconBut(block, type|SHO, retval, icon, x1, y1, x2, y2, (void*) poin, min, max, a1, a2, tip);
2876 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)
2878 return uiDefIconButBit(block, type|SHO, bit, retval, icon, x1, y1, x2, y2, (void*) poin, min, max, a1, a2, tip);
2880 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)
2882 return uiDefIconBut(block, type|CHA, retval, icon, x1, y1, x2, y2, (void*) poin, min, max, a1, a2, tip);
2884 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)
2886 return uiDefIconButBit(block, type|CHA, bit, retval, icon, x1, y1, x2, y2, (void*) poin, min, max, a1, a2, tip);
2888 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)
2892 but= ui_def_but_rna(block, type, retval, "", x1, y1, x2, y2, ptr, propname, index, min, max, a1, a2, tip);
2895 but->icon= (BIFIconID) icon;
2896 but->flag|= UI_HAS_ICON;
2903 uiBut *uiDefIconButO(uiBlock *block, int type, const char *opname, int opcontext, int icon, int x1, int y1, short x2, short y2, const char *tip)
2907 but= ui_def_but_operator(block, type, opname, opcontext, "", x1, y1, x2, y2, tip);
2909 but->icon= (BIFIconID) icon;
2910 but->flag|= UI_HAS_ICON;
2917 /* Button containing both string label and icon */
2918 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)
2920 uiBut *but= ui_def_but(block, type, retval, str, x1, y1, x2, y2, poin, min, max, a1, a2, tip);
2922 but->icon= (BIFIconID) icon;
2923 but->flag|= UI_HAS_ICON;
2925 but->flag|= UI_ICON_LEFT;
2931 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)
2933 int bitIdx= findBitIndex(bit);
2937 return uiDefIconTextBut(block, type|BIT|bitIdx, retval, icon, str, x1, y1, x2, y2, poin, min, max, a1, a2, tip);
2941 uiBut *uiDefIconTextButF(uiBlock *block, int type, int retval, int icon, const char *str, int x1, int y1, short x2, short y2, float *poin, float min, float max, float a1, float a2, const char *tip)
2943 return uiDefIconTextBut(block, type|FLO, retval, icon, str, x1, y1, x2, y2, (void*) poin, min, max, a1, a2, tip);
2945 uiBut *uiDefIconTextButBitF(uiBlock *block, int type, int bit, int retval, int icon, const char *str, int x1, int y1, short x2, short y2, float *poin, float min, float max, float a1, float a2, const char *tip)
2947 return uiDefIconTextButBit(block, type|FLO, bit, retval, icon, str, x1, y1, x2, y2, (void*) poin, min, max, a1, a2, tip);
2949 uiBut *uiDefIconTextButI(uiBlock *block, int type, int retval, int icon, const char *str, int x1, int y1, short x2, short y2, int *poin, float min, float max, float a1, float a2, const char *tip)
2951 return uiDefIconTextBut(block, type|INT, retval, icon, str, x1, y1, x2, y2, (void*) poin, min, max, a1, a2, tip);
2953 uiBut *uiDefIconTextButBitI(uiBlock *block, int type, int bit, int retval, int icon, const char *str, int x1, int y1, short x2, short y2, int *poin, float min, float max, float a1, float a2, const char *tip)
2955 return uiDefIconTextButBit(block, type|INT, bit, retval, icon, str, x1, y1, x2, y2, (void*) poin, min, max, a1, a2, tip);
2957 uiBut *uiDefIconTextButS(uiBlock *block, int type, int retval, int icon, const char *str, int x1, int y1, short x2, short y2, short *poin, float min, float max, float a1, float a2, const char *tip)
2959 return uiDefIconTextBut(block, type|SHO, retval, icon, str, x1, y1, x2, y2, (void*) poin, min, max, a1, a2, tip);
2961 uiBut *uiDefIconTextButBitS(uiBlock *block, int type, int bit, int retval, int icon, const char *str, int x1, int y1, short x2, short y2, short *poin, float min, float max, float a1, float a2, const char *tip)
2963 return uiDefIconTextButBit(block, type|SHO, bit, retval, icon, str, x1, y1, x2, y2, (void*) poin, min, max, a1, a2, tip);
2965 uiBut *uiDefIconTextButC(uiBlock *block, int type, int retval, int icon, const char *str, int x1, int y1, short x2, short y2, char *poin, float min, float max, float a1, float a2, const char *tip)
2967 return uiDefIconTextBut(block, type|CHA, retval, icon, str, x1, y1, x2, y2, (void*) poin, min, max, a1, a2, tip);
2969 uiBut *uiDefIconTextButBitC(uiBlock *block, int type, int bit, int retval, int icon, const char *str, int x1, int y1, short x2, short y2, char *poin, float min, float max, float a1, float a2, const char *tip)
2971 return uiDefIconTextButBit(block, type|CHA, bit, retval, icon, str, x1, y1, x2, y2, (void*) poin, min, max, a1, a2, tip);
2973 uiBut *uiDefIconTextButR(uiBlock *block, int type, int retval, int icon, 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)
2977 but= ui_def_but_rna(block, type, retval, str, x1, y1, x2, y2, ptr, propname, index, min, max, a1, a2, tip);
2980 but->icon= (BIFIconID) icon;
2981 but->flag|= UI_HAS_ICON;
2983 but->flag|= UI_ICON_LEFT;
2989 uiBut *uiDefIconTextButO(uiBlock *block, int type, const char *opname, int opcontext, int icon, const char *str, int x1, int y1, short x2, short y2, const char *tip)
2993 but= ui_def_but_operator(block, type, opname, opcontext, str, x1, y1, x2, y2, tip);
2995 but->icon= (BIFIconID) icon;
2996 but->flag|= UI_HAS_ICON;
2997 but->flag|= UI_ICON_LEFT;
3004 /* END Button containing both string label and icon */
3006 void uiSetButLink(uiBut *but, void **poin, void ***ppoin, short *tot, int from, int to)
3010 link= but->link= MEM_callocN(sizeof(uiLink), "new uilink");
3015 link->fromcode= from;
3019 /* cruft to make uiBlock and uiBut private */
3021 int uiBlocksGetYMin(ListBase *lb)
3026 for (block= lb->first; block; block= block->next)
3027 if (block==lb->first || block->miny<min)
3033 void uiBlockSetDirection(uiBlock *block, int direction)
3035 block->direction= direction;
3038 /* this call escapes if there's alignment flags */
3039 void uiBlockFlipOrder(uiBlock *block)
3043 float centy, miny=10000, maxy= -10000;
3045 if(U.uiflag & USER_MENUFIXEDORDER)
3047 else if(block->flag & UI_BLOCK_NO_FLIP)