5 #include "MEM_guardedalloc.h"
7 #include "DNA_screen_types.h"
8 #include "DNA_view2d_types.h"
9 #include "DNA_windowmanager_types.h"
11 #include "BLI_arithb.h"
12 #include "BLI_blenlib.h"
14 #include "BKE_global.h"
15 #include "BKE_screen.h"
16 #include "BKE_utildefines.h"
20 #include "wm_subwindow.h"
21 #include "wm_window.h"
25 #include "UI_interface.h"
27 #include "UI_view2d.h"
29 #include "ED_screen.h"
31 #include "interface.h"
33 #define MENU_BUTTON_HEIGHT 20
35 #define MENU_SHADOW_LEFT -1
36 #define MENU_SHADOW_BOTTOM -10
37 #define MENU_SHADOW_RIGHT 10
38 #define MENU_SHADOW_TOP 1
40 /*********************** Menu Data Parsing ********************* */
54 int nitems, itemssize;
57 static MenuData *menudata_new(char *instr)
59 MenuData *md= MEM_mallocN(sizeof(*md), "MenuData");
65 md->nitems= md->itemssize= 0;
70 static void menudata_set_title(MenuData *md, char *title, int titleicon)
75 md->titleicon= titleicon;
78 static void menudata_add_item(MenuData *md, char *str, int retval, int icon)
80 if (md->nitems==md->itemssize) {
81 int nsize= md->itemssize?(md->itemssize<<1):1;
82 MenuEntry *oitems= md->items;
84 md->items= MEM_mallocN(nsize*sizeof(*md->items), "md->items");
86 memcpy(md->items, oitems, md->nitems*sizeof(*md->items));
93 md->items[md->nitems].str= str;
94 md->items[md->nitems].retval= retval;
95 md->items[md->nitems].icon= icon;
99 void menudata_free(MenuData *md)
101 MEM_freeN(md->instr);
103 MEM_freeN(md->items);
108 * Parse menu description strings, string is of the
109 * form "[sss%t|]{(sss[%xNN]|), (%l|)}", ssss%t indicates the
110 * menu title, sss or sss%xNN indicates an option,
111 * if %xNN is given then NN is the return value if
112 * that option is selected otherwise the return value
113 * is the index of the option (starting with 1). %l
114 * indicates a seperator.
116 * @param str String to be parsed.
117 * @retval new menudata structure, free with menudata_free()
119 MenuData *decompose_menu_string(char *str)
121 char *instr= BLI_strdup(str);
122 MenuData *md= menudata_new(instr);
123 char *nitem= NULL, *s= instr;
124 int nicon=0, nretval= 1, nitem_is_title= 0;
135 } else if (s[1]=='t') {
140 } else if (s[1]=='l') {
143 } else if (s[1]=='i') {
149 } else if (c=='|' || c=='\0') {
153 if (nitem_is_title) {
154 menudata_set_title(md, nitem, nicon);
157 /* prevent separator to get a value */
158 if(nitem[0]=='%' && nitem[1]=='l')
159 menudata_add_item(md, nitem, -1, nicon);
161 menudata_add_item(md, nitem, nretval, nicon);
162 nretval= md->nitems+1;
180 void ui_set_name_menu(uiBut *but, int value)
185 md= decompose_menu_string(but->str);
186 for (i=0; i<md->nitems; i++)
187 if (md->items[i].retval==value)
188 strcpy(but->drawstr, md->items[i].str);
193 /******************** Creating Temporary regions ******************/
195 ARegion *ui_add_temporary_region(bScreen *sc)
199 ar= MEM_callocN(sizeof(ARegion), "area region");
200 BLI_addtail(&sc->regionbase, ar);
202 ar->regiontype= RGN_TYPE_TEMPORARY;
203 ar->alignment= RGN_ALIGN_FLOAT;
208 void ui_remove_temporary_region(bContext *C, bScreen *sc, ARegion *ar)
210 ED_region_exit(C, ar);
211 BKE_area_region_free(ar);
212 BLI_freelinkN(&sc->regionbase, ar);
215 /************************* Creating Tooltips **********************/
217 typedef struct uiTooltipData {
219 struct BMF_Font *font;
224 static void ui_tooltip_region_draw(const bContext *C, ARegion *ar)
229 data= ar->regiondata;
236 /* draw drop shadow */
237 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
240 glColor4ub(0, 0, 0, 20);
242 gl_round_box(GL_POLYGON, 3, 3, x2-x1-3, y2-y1-2, 2.0);
243 gl_round_box(GL_POLYGON, 3, 2, x2-x1-2, y2-y1-2, 3.0);
245 glColor4ub(0, 0, 0, 8);
247 gl_round_box(GL_POLYGON, 3, 1, x2-x1-1, y2-y1-3, 4.0);
248 gl_round_box(GL_POLYGON, 3, 0, x2-x1-0, y2-y1-3, 5.0);
252 /* draw background */
253 glColor3f(1.0f, 1.0f, 0.8666f);
254 glRectf(0, 4, x2-x1+4, y2-y1);
259 /* set the position for drawing text +4 in from the left edge, and leaving
260 * an equal gap between the top of the background box and the top of the
261 * string's bbox, and the bottom of the background box, and the bottom of
262 * the string's bbox */
263 ui_rasterpos_safe(4, ((y2-data->bbox.ymax)+(y1+data->bbox.ymin))/2 - data->bbox.ymin - y1, data->aspect);
266 UI_DrawString(data->font, data->tip, ui_translate_tooltips());
269 static void ui_tooltip_region_free(ARegion *ar)
273 data= ar->regiondata;
274 MEM_freeN(data->tip);
278 ARegion *ui_tooltip_create(bContext *C, ARegion *butregion, uiBut *but)
280 static ARegionType type;
283 int x1, x2, y1, y2, winx, winy;
285 if(!but->tip || strlen(but->tip)==0)
288 /* create area region */
289 ar= ui_add_temporary_region(C->window->screen);
291 memset(&type, 0, sizeof(ARegionType));
292 type.draw= ui_tooltip_region_draw;
293 type.free= ui_tooltip_region_free;
296 /* create tooltip data */
297 data= MEM_callocN(sizeof(uiTooltipData), "uiTooltipData");
298 data->tip= BLI_strdup(but->tip);
299 data->font= but->font;
300 data->aspect= but->aspect;
301 UI_GetBoundingBox(data->font, data->tip, ui_translate_tooltips(), &data->bbox);
303 ar->regiondata= data;
305 /* compute position */
306 x1= (but->x1+but->x2)/2;
307 x2= x1+but->aspect*((data->bbox.xmax-data->bbox.xmin) + 8);
309 y1= y2-but->aspect*((data->bbox.ymax+(data->bbox.ymax-data->bbox.ymin)));
315 /* XXX temp, region v2ds can be empty still */
316 if(butregion->v2d.cur.xmin != butregion->v2d.cur.xmax) {
318 UI_view2d_to_region_no_clip(&butregion->v2d, x1, y1, &tx, &ty);
319 x1= (int)tx; y1= (int)ty;
320 UI_view2d_to_region_no_clip(&butregion->v2d, x2, y2, &tx, &ty);
321 x2= (int)tx; y2= (int)ty;
324 x1 += butregion->winrct.xmin;
325 x2 += butregion->winrct.xmin;
326 y1 += butregion->winrct.ymin;
327 y2 += butregion->winrct.ymin;
330 wm_window_get_size(C->window, &winx, &winy);
354 ED_region_init(C, ar);
356 /* notify change and redraw */
357 WM_event_add_notifier(C, WM_NOTE_SCREEN_CHANGED, 0, NULL);
358 WM_event_add_notifier(C, WM_NOTE_WINDOW_REDRAW, 0, NULL);
363 void ui_tooltip_free(bContext *C, ARegion *ar)
365 ui_remove_temporary_region(C, C->window->screen, ar);
367 WM_event_add_notifier(C, WM_NOTE_SCREEN_CHANGED, 0, NULL);
368 WM_event_add_notifier(C, WM_NOTE_WINDOW_REDRAW, 0, NULL);
371 /************************* Creating Menu Blocks **********************/
373 /* position block relative to but, result is in window space */
374 static void ui_block_position(wmWindow *window, ARegion *butregion, uiBut *but, uiBlock *block)
377 uiSafetyRct *saferct;
380 int xsize, ysize, xof=0, yof=0, center;
381 short dir1= 0, dir2=0;
383 /* transform to window coordinates, using the source button region/block */
384 butrct.xmin= but->x1; butrct.xmax= but->x2;
385 butrct.ymin= but->y1; butrct.ymax= but->y2;
387 ui_block_to_window_fl(butregion, but->block, &butrct.xmin, &butrct.ymin);
388 ui_block_to_window_fl(butregion, but->block, &butrct.xmax, &butrct.ymax);
390 /* calc block rect */
391 if(block->minx == 0.0f && block->maxx == 0.0f) {
392 if(block->buttons.first) {
393 block->minx= block->miny= 10000;
394 block->maxx= block->maxy= -10000;
396 bt= block->buttons.first;
398 if(bt->x1 < block->minx) block->minx= bt->x1;
399 if(bt->y1 < block->miny) block->miny= bt->y1;
401 if(bt->x2 > block->maxx) block->maxx= bt->x2;
402 if(bt->y2 > block->maxy) block->maxy= bt->y2;
408 /* we're nice and allow empty blocks too */
409 block->minx= block->miny= 0;
410 block->maxx= block->maxy= 20;
414 aspect= (float)(block->maxx - block->minx + 4);
415 ui_block_to_window_fl(butregion, but->block, &block->minx, &block->miny);
416 ui_block_to_window_fl(butregion, but->block, &block->maxx, &block->maxy);
418 //block->minx-= 2.0; block->miny-= 2.0;
419 //block->maxx+= 2.0; block->maxy+= 2.0;
421 xsize= block->maxx - block->minx+4; // 4 for shadow
422 ysize= block->maxy - block->miny+4;
423 aspect/= (float)xsize;
426 int left=0, right=0, top=0, down=0;
429 wm_window_get_size(window, &winx, &winy);
431 if(block->direction & UI_CENTER) center= ysize/2;
434 if( butrct.xmin-xsize > 0.0) left= 1;
435 if( butrct.xmax+xsize < winx) right= 1;
436 if( butrct.ymin-ysize+center > 0.0) down= 1;
437 if( butrct.ymax+ysize-center < winy) top= 1;
439 dir1= block->direction & UI_DIRECTION;
441 /* secundary directions */
442 if(dir1 & (UI_TOP|UI_DOWN)) {
443 if(dir1 & UI_LEFT) dir2= UI_LEFT;
444 else if(dir1 & UI_RIGHT) dir2= UI_RIGHT;
445 dir1 &= (UI_TOP|UI_DOWN);
448 if(dir2==0) if(dir1==UI_LEFT || dir1==UI_RIGHT) dir2= UI_DOWN;
449 if(dir2==0) if(dir1==UI_TOP || dir1==UI_DOWN) dir2= UI_LEFT;
451 /* no space at all? dont change */
453 if(dir1==UI_LEFT && left==0) dir1= UI_RIGHT;
454 if(dir1==UI_RIGHT && right==0) dir1= UI_LEFT;
455 /* this is aligning, not append! */
456 if(dir2==UI_LEFT && right==0) dir2= UI_RIGHT;
457 if(dir2==UI_RIGHT && left==0) dir2= UI_LEFT;
460 if(dir1==UI_TOP && top==0) dir1= UI_DOWN;
461 if(dir1==UI_DOWN && down==0) dir1= UI_TOP;
462 if(dir2==UI_TOP && top==0) dir2= UI_DOWN;
463 if(dir2==UI_DOWN && down==0) dir2= UI_TOP;
467 xof= butrct.xmin - block->maxx;
468 if(dir2==UI_TOP) yof= butrct.ymin - block->miny-center;
469 else yof= butrct.ymax - block->maxy+center;
471 else if(dir1==UI_RIGHT) {
472 xof= butrct.xmax - block->minx;
473 if(dir2==UI_TOP) yof= butrct.ymin - block->miny-center;
474 else yof= butrct.ymax - block->maxy+center;
476 else if(dir1==UI_TOP) {
477 yof= butrct.ymax - block->miny;
478 if(dir2==UI_RIGHT) xof= butrct.xmax - block->maxx;
479 else xof= butrct.xmin - block->minx;
480 // changed direction?
481 if((dir1 & block->direction)==0) {
482 if(block->direction & UI_SHIFT_FLIPPED)
483 xof+= dir2==UI_LEFT?25:-25;
484 uiBlockFlipOrder(block);
487 else if(dir1==UI_DOWN) {
488 yof= butrct.ymin - block->maxy;
489 if(dir2==UI_RIGHT) xof= butrct.xmax - block->maxx;
490 else xof= butrct.xmin - block->minx;
491 // changed direction?
492 if((dir1 & block->direction)==0) {
493 if(block->direction & UI_SHIFT_FLIPPED)
494 xof+= dir2==UI_LEFT?25:-25;
495 uiBlockFlipOrder(block);
499 /* and now we handle the exception; no space below or to top */
500 if(top==0 && down==0) {
501 if(dir1==UI_LEFT || dir1==UI_RIGHT) {
502 // align with bottom of screen
507 /* or no space left or right */
508 if(left==0 && right==0) {
509 if(dir1==UI_TOP || dir1==UI_DOWN) {
510 // align with left size of screen
515 // apply requested offset in the block
516 xof += block->xofs/block->aspect;
517 yof += block->yofs/block->aspect;
522 for(bt= block->buttons.first; bt; bt= bt->next) {
523 ui_block_to_window_fl(butregion, but->block, &bt->x1, &bt->y1);
524 ui_block_to_window_fl(butregion, but->block, &bt->x2, &bt->y2);
532 // ui_check_but recalculates drawstring size in pixels
541 /* safety calculus */
543 float midx= (butrct.xmin+butrct.xmax)/2.0;
544 float midy= (butrct.ymin+butrct.ymax)/2.0;
546 /* when you are outside parent button, safety there should be smaller */
548 // parent button to left
549 if( midx < block->minx ) block->safety.xmin= block->minx-3;
550 else block->safety.xmin= block->minx-40;
551 // parent button to right
552 if( midx > block->maxx ) block->safety.xmax= block->maxx+3;
553 else block->safety.xmax= block->maxx+40;
555 // parent button on bottom
556 if( midy < block->miny ) block->safety.ymin= block->miny-3;
557 else block->safety.ymin= block->miny-40;
558 // parent button on top
559 if( midy > block->maxy ) block->safety.ymax= block->maxy+3;
560 else block->safety.ymax= block->maxy+40;
562 // exception for switched pulldowns...
563 if(dir1 && (dir1 & block->direction)==0) {
564 if(dir2==UI_RIGHT) block->safety.xmax= block->maxx+3;
565 if(dir2==UI_LEFT) block->safety.xmin= block->minx-3;
567 block->direction= dir1;
570 block->safety.xmin= block->minx-40;
571 block->safety.ymin= block->miny-40;
572 block->safety.xmax= block->maxx+40;
573 block->safety.ymax= block->maxy+40;
576 /* keep a list of these, needed for pulldown menus */
577 saferct= MEM_callocN(sizeof(uiSafetyRct), "uiSafetyRct");
578 saferct->parent= butrct;
579 saferct->safety= block->safety;
580 BLI_freelistN(&block->saferct);
582 BLI_duplicatelist(&block->saferct, &but->block->saferct);
583 BLI_addhead(&block->saferct, saferct);
586 static void ui_block_region_draw(const bContext *C, ARegion *ar)
590 for(block=ar->uiblocks.first; block; block=block->next) {
591 wm_subwindow_getmatrix(C->window, ar->swinid, block->winmat);
596 uiMenuBlockHandle *ui_menu_block_create(bContext *C, ARegion *butregion, uiBut *but, uiBlockFuncFP block_func, void *arg)
598 static ARegionType type;
602 uiMenuBlockHandle *handle;
603 uiSafetyRct *saferct;
606 handle= MEM_callocN(sizeof(uiMenuBlockHandle), "uiMenuBlockHandle");
608 /* create area region */
609 ar= ui_add_temporary_region(C->window->screen);
611 memset(&type, 0, sizeof(ARegionType));
612 type.draw= ui_block_region_draw;
615 UI_add_region_handlers(&ar->handlers);
618 ar->regiondata= handle;
620 /* create ui block */
621 block= block_func(C, handle, arg);
622 block->handle= handle;
624 /* if this is being created from a button */
626 if(ELEM(but->type, BLOCK, PULLDOWN))
627 block->xofs = -2; /* for proper alignment */
629 /* only used for automatic toolbox, so can set the shift flag */
630 if(but->flag & UI_MAKE_TOP) {
631 block->direction= UI_TOP|UI_SHIFT_FLIPPED;
632 uiBlockFlipOrder(block);
634 if(but->flag & UI_MAKE_DOWN) block->direction= UI_DOWN|UI_SHIFT_FLIPPED;
635 if(but->flag & UI_MAKE_LEFT) block->direction |= UI_LEFT;
636 if(but->flag & UI_MAKE_RIGHT) block->direction |= UI_RIGHT;
638 ui_block_position(C->window, butregion, but, block);
641 /* keep a list of these, needed for pulldown menus */
642 saferct= MEM_callocN(sizeof(uiSafetyRct), "uiSafetyRct");
643 saferct->safety= block->safety;
644 BLI_addhead(&block->saferct, saferct);
647 /* the block and buttons were positioned in window space as in 2.4x, now
648 * these menu blocks are regions so we bring it back to region space.
649 * additionally we add some padding for the menu shadow */
650 ar->winrct.xmin= block->minx + MENU_SHADOW_LEFT;
651 ar->winrct.xmax= block->maxx + MENU_SHADOW_RIGHT;
652 ar->winrct.ymin= block->miny + MENU_SHADOW_BOTTOM;
653 ar->winrct.ymax= block->maxy + MENU_SHADOW_TOP;
655 block->minx -= ar->winrct.xmin;
656 block->maxx -= ar->winrct.xmin;
657 block->miny -= ar->winrct.ymin;
658 block->maxy -= ar->winrct.ymin;
660 for(bt= block->buttons.first; bt; bt= bt->next) {
661 bt->x1 -= ar->winrct.xmin;
662 bt->x2 -= ar->winrct.xmin;
663 bt->y1 -= ar->winrct.ymin;
664 bt->y2 -= ar->winrct.ymin;
667 block->flag |= UI_BLOCK_LOOP|UI_BLOCK_MOVEMOUSE_QUIT;
670 ED_region_init(C, ar);
672 /* notify change and redraw */
673 WM_event_add_notifier(C, WM_NOTE_SCREEN_CHANGED, 0, NULL);
674 WM_event_add_notifier(C, WM_NOTE_WINDOW_REDRAW, 0, NULL);
679 void ui_menu_block_free(bContext *C, uiMenuBlockHandle *handle)
681 ui_remove_temporary_region(C, C->window->screen, handle->region);
684 WM_event_add_notifier(C, WM_NOTE_SCREEN_CHANGED, 0, NULL);
685 WM_event_add_notifier(C, WM_NOTE_WINDOW_REDRAW, 0, NULL);
688 /***************************** Menu Button ***************************/
690 uiBlock *ui_block_func_MENU(bContext *C, uiMenuBlockHandle *handle, void *arg_but)
698 int width, height, boxh, columns, rows, startx, starty, x1, y1, xmax, a;
700 /* create the block */
701 block= uiBeginBlock(C, handle->region, "menu", UI_EMBOSSP, UI_HELV);
702 block->dt= UI_EMBOSSP;
703 block->flag= UI_BLOCK_LOOP|UI_BLOCK_REDRAW|UI_BLOCK_NUMSELECT;
704 block->themecol= TH_MENU_ITEM;
706 /* compute menu data */
707 md= decompose_menu_string(but->str);
709 /* columns and row calculation */
710 columns= (md->nitems+20)/20;
714 columns= (md->nitems+25)/25;
716 rows= md->nitems/columns;
719 while(rows*columns<md->nitems)
722 /* prevent scaling up of pupmenu */
727 /* size and location */
729 width= 1.5*aspect*strlen(md->title)+UI_GetStringWidth(block->curfont, md->title, ui_translate_menus());
733 for(a=0; a<md->nitems; a++) {
734 xmax= aspect*UI_GetStringWidth(block->curfont, md->items[a].str, ui_translate_menus());
735 if(md->items[a].icon)
742 if(width < (but->x2 - but->x1))
743 width = (but->x2 - but->x1);
747 boxh= MENU_BUTTON_HEIGHT;
759 uiSetCurFont(block, block->font+1);
761 bt= uiDefIconTextBut(block, LABEL, 0, md->titleicon, md->title, startx, (short)(starty+rows*boxh), (short)width, (short)boxh, NULL, 0.0, 0.0, 0, 0, "");
763 bt= uiDefBut(block, LABEL, 0, md->title, startx, (short)(starty+rows*boxh), (short)width, (short)boxh, NULL, 0.0, 0.0, 0, 0, "");
764 bt->flag= UI_TEXT_LEFT;
766 uiSetCurFont(block, block->font);
769 for(a=0; a<md->nitems; a++) {
771 x1= startx + width*((int)(md->nitems-a-1)/rows);
772 y1= starty - boxh*(rows - ((md->nitems - a - 1)%rows)) + (rows*boxh);
774 if (strcmp(md->items[md->nitems-a-1].str, "%l")==0) {
775 bt= uiDefBut(block, SEPR, B_NOP, "", x1, y1,(short)(width-(rows>1)), (short)(boxh-1), NULL, 0.0, 0.0, 0, 0, "");
777 else if(md->items[md->nitems-a-1].icon) {
778 bt= uiDefIconTextButF(block, BUTM|FLO, B_NOP, md->items[md->nitems-a-1].icon ,md->items[md->nitems-a-1].str, x1, y1,(short)(width-(rows>1)), (short)(boxh-1), &handle->retvalue, (float) md->items[md->nitems-a-1].retval, 0.0, 0, 0, "");
781 bt= uiDefButF(block, BUTM|FLO, B_NOP, md->items[md->nitems-a-1].str, x1, y1,(short)(width-(rows>1)), (short)(boxh-1), &handle->retvalue, (float) md->items[md->nitems-a-1].retval, 0.0, 0, 0, "");
787 /* the code up here has flipped locations, because of change of preferred order */
788 /* thats why we have to switch list order too, to make arrowkeys work */
790 lb.first= lb.last= NULL;
791 bt= block->buttons.first;
793 uiBut *next= bt->next;
794 BLI_remlink(&block->buttons, bt);
795 BLI_addhead(&lb, bt);
800 block->direction= UI_TOP;
801 uiEndBlock(C, block);
806 uiBlock *ui_block_func_ICONROW(bContext *C, uiMenuBlockHandle *handle, void *arg_but)
812 block= uiBeginBlock(C, handle->region, "menu", UI_EMBOSSP, UI_HELV);
813 block->flag= UI_BLOCK_LOOP|UI_BLOCK_REDRAW|UI_BLOCK_NUMSELECT;
814 block->themecol= TH_MENU_ITEM;
816 for(a=(int)but->min; a<=(int)but->max; a++) {
817 uiDefIconButF(block, BUTM|FLO, B_NOP, but->icon+(a-but->min), 0, (short)(18*a), (short)(but->x2-but->x1-4), 18, &handle->retvalue, (float)a, 0.0, 0, 0, "");
820 block->direction= UI_TOP;
822 uiEndBlock(C, block);
827 uiBlock *ui_block_func_ICONTEXTROW(bContext *C, uiMenuBlockHandle *handle, void *arg_but)
832 int width, xmax, ypos, a;
834 block= uiBeginBlock(C, handle->region, "menu", UI_EMBOSSP, UI_HELV);
835 block->flag= UI_BLOCK_LOOP|UI_BLOCK_REDRAW|UI_BLOCK_NUMSELECT;
836 block->themecol= TH_MENU_ITEM;
838 md= decompose_menu_string(but->str);
840 /* size and location */
841 /* expand menu width to fit labels */
843 width= 2*strlen(md->title)+UI_GetStringWidth(block->curfont, md->title, ui_translate_menus());
847 for(a=0; a<md->nitems; a++) {
848 xmax= UI_GetStringWidth(block->curfont, md->items[a].str, ui_translate_menus());
849 if(xmax>width) width= xmax;
853 if (width<50) width=50;
857 /* loop through the menu options and draw them out with icons & text labels */
858 for(a=0; a<md->nitems; a++) {
860 /* add a space if there's a separator (%l) */
861 if (strcmp(md->items[a].str, "%l")==0) {
865 uiDefIconTextButF(block, BUTM|FLO, B_NOP, (short)((but->icon)+(md->items[a].retval-but->min)), md->items[a].str, 0, ypos,(short)width, 19, &handle->retvalue, (float) md->items[a].retval, 0.0, 0, 0, "");
872 uiSetCurFont(block, block->font+1);
873 bt= uiDefBut(block, LABEL, 0, md->title, 0, ypos, (short)width, 19, NULL, 0.0, 0.0, 0, 0, "");
874 uiSetCurFont(block, block->font);
875 bt->flag= UI_TEXT_LEFT;
880 block->direction= UI_TOP;
882 uiBoundsBlock(block, 3);
883 uiEndBlock(C, block);
888 static void ui_warp_pointer(short x, short y)
890 /* XXX 2.50 which function to use for this? */
892 /* OSX has very poor mousewarp support, it sends events;
893 this causes a menu being pressed immediately ... */
900 /********************* Color Button ****************/
902 /* picker sizes S hsize, F full size, D spacer, B button/pallette height */
908 #define UI_PALETTE_TOT 16
909 /* note; in tot+1 the old color is stored */
910 static float palette[UI_PALETTE_TOT+1][3]= {
911 {0.93, 0.83, 0.81}, {0.88, 0.89, 0.73}, {0.69, 0.81, 0.57}, {0.51, 0.76, 0.64},
912 {0.37, 0.56, 0.61}, {0.33, 0.29, 0.55}, {0.46, 0.21, 0.51}, {0.40, 0.12, 0.18},
913 {1.0, 1.0, 1.0}, {0.85, 0.85, 0.85}, {0.7, 0.7, 0.7}, {0.56, 0.56, 0.56},
914 {0.42, 0.42, 0.42}, {0.28, 0.28, 0.28}, {0.14, 0.14, 0.14}, {0.0, 0.0, 0.0}
917 /* for picker, while editing hsv */
918 void ui_set_but_hsv(uiBut *but)
922 hsv_to_rgb(but->hsv[0], but->hsv[1], but->hsv[2], col, col+1, col+2);
923 ui_set_but_vectorf(but, col);
926 static void update_picker_hex(uiBlock *block, float *rgb)
931 sprintf(col, "%02X%02X%02X", (unsigned int)(rgb[0]*255.0), (unsigned int)(rgb[1]*255.0), (unsigned int)(rgb[2]*255.0));
933 // this updates button strings, is hackish... but button pointers are on stack of caller function
935 for(bt= block->buttons.first; bt; bt= bt->next) {
936 if(strcmp(bt->str, "Hex: ")==0) {
937 strcpy(bt->poin, col);
944 void ui_update_block_buts_hsv(uiBlock *block, float *hsv)
950 // this updates button strings, is hackish... but button pointers are on stack of caller function
951 hsv_to_rgb(hsv[0], hsv[1], hsv[2], &r, &g, &b);
953 rgb[0] = r; rgb[1] = g; rgb[2] = b;
954 update_picker_hex(block, rgb);
956 for(bt= block->buttons.first; bt; bt= bt->next) {
957 if(bt->type==HSVCUBE) {
958 VECCOPY(bt->hsv, hsv);
961 else if(bt->str[1]==' ') {
962 if(bt->str[0]=='R') {
963 ui_set_but_val(bt, r);
965 else if(bt->str[0]=='G') {
966 ui_set_but_val(bt, g);
968 else if(bt->str[0]=='B') {
969 ui_set_but_val(bt, b);
971 else if(bt->str[0]=='H') {
972 ui_set_but_val(bt, hsv[0]);
974 else if(bt->str[0]=='S') {
975 ui_set_but_val(bt, hsv[1]);
977 else if(bt->str[0]=='V') {
978 ui_set_but_val(bt, hsv[2]);
984 static void ui_update_block_buts_hex(uiBlock *block, char *hexcol)
991 // this updates button strings, is hackish... but button pointers are on stack of caller function
992 hex_to_rgb(hexcol, &r, &g, &b);
993 rgb_to_hsv(r, g, b, &h, &s, &v);
995 for(bt= block->buttons.first; bt; bt= bt->next) {
996 if(bt->type==HSVCUBE) {
1002 else if(bt->str[1]==' ') {
1003 if(bt->str[0]=='R') {
1004 ui_set_but_val(bt, r);
1006 else if(bt->str[0]=='G') {
1007 ui_set_but_val(bt, g);
1009 else if(bt->str[0]=='B') {
1010 ui_set_but_val(bt, b);
1012 else if(bt->str[0]=='H') {
1013 ui_set_but_val(bt, h);
1015 else if(bt->str[0]=='S') {
1016 ui_set_but_val(bt, s);
1018 else if(bt->str[0]=='V') {
1019 ui_set_but_val(bt, v);
1025 /* bt1 is palette but, col1 is original color */
1026 /* callback to copy from/to palette */
1027 static void do_palette_cb(bContext *C, void *bt1, void *col1)
1029 uiBut *but1= (uiBut *)bt1;
1030 float *col= (float *)col1;
1033 fp= (float *)but1->poin;
1035 /* XXX 2.50 bad access, how to solve?
1037 if( (get_qual() & LR_CTRLKEY) ) {
1044 rgb_to_hsv(col[0], col[1], col[2], hsv, hsv+1, hsv+2);
1045 ui_update_block_buts_hsv(but1->block, hsv);
1046 update_picker_hex(but1->block, col);
1049 /* bt1 is num but, hsv1 is pointer to original color in hsv space*/
1050 /* callback to handle changes in num-buts in picker */
1051 static void do_palette1_cb(bContext *C, void *bt1, void *hsv1)
1053 uiBut *but1= (uiBut *)bt1;
1054 float *hsv= (float *)hsv1;
1057 if(but1->str[1]==' ') {
1058 if(but1->str[0]=='R') fp= (float *)but1->poin;
1059 else if(but1->str[0]=='G') fp= ((float *)but1->poin)-1;
1060 else if(but1->str[0]=='B') fp= ((float *)but1->poin)-2;
1063 rgb_to_hsv(fp[0], fp[1], fp[2], hsv, hsv+1, hsv+2);
1065 ui_update_block_buts_hsv(but1->block, hsv);
1068 /* bt1 is num but, col1 is pointer to original color */
1069 /* callback to handle changes in num-buts in picker */
1070 static void do_palette2_cb(bContext *C, void *bt1, void *col1)
1072 uiBut *but1= (uiBut *)bt1;
1073 float *rgb= (float *)col1;
1076 if(but1->str[1]==' ') {
1077 if(but1->str[0]=='H') fp= (float *)but1->poin;
1078 else if(but1->str[0]=='S') fp= ((float *)but1->poin)-1;
1079 else if(but1->str[0]=='V') fp= ((float *)but1->poin)-2;
1082 hsv_to_rgb(fp[0], fp[1], fp[2], rgb, rgb+1, rgb+2);
1084 ui_update_block_buts_hsv(but1->block, fp);
1087 static void do_palette_hex_cb(bContext *C, void *bt1, void *hexcl)
1089 uiBut *but1= (uiBut *)bt1;
1090 char *hexcol= (char *)hexcl;
1092 ui_update_block_buts_hex(but1->block, hexcol);
1095 /* used for both 3d view and image window */
1096 static void do_palette_sample_cb(bContext *C, void *bt1, void *col1) /* frontbuf */
1098 /* XXX 2.50 this should become an operator? */
1100 uiBut *but1= (uiBut *)bt1;
1111 oldcursor=get_cursor();
1112 win=winlay_get_active_window();
1114 while (get_mbut() & L_MOUSE) UI_wait_for_statechange();
1116 SetBlenderCursor(BC_EYEDROPPER_CURSOR);
1118 /* loop and wait for a mouse click */
1124 dev = extern_qread_ext(&val, &ascii);
1126 if(dev==INPUTCHANGE) break;
1127 if(get_mbut() & R_MOUSE) break;
1128 else if(get_mbut() & L_MOUSE) {
1129 uiGetMouse(mywinget(), mval);
1130 x= mval[0]; y= mval[1];
1135 else if(dev==ESCKEY) break;
1137 window_set_cursor(win, oldcursor);
1139 if(capturing) return;
1141 if(x<0 || y<0) return;
1143 /* if we've got a glick, use OpenGL to sample the color under the mouse pointer */
1144 glReadBuffer(GL_FRONT);
1145 glReadPixels(x, y, 1, 1, GL_RGBA, GL_FLOAT, tempcol);
1146 glReadBuffer(GL_BACK);
1148 /* and send that color back to the picker */
1149 rgb_to_hsv(tempcol[0], tempcol[1], tempcol[2], hsv, hsv+1, hsv+2);
1150 ui_update_block_buts_hsv(but1->block, hsv);
1151 update_picker_hex(but1->block, tempcol);
1153 for (but= but1->block->buttons.first; but; but= but->next) {
1158 but= but1->block->buttons.first;
1159 ui_block_flush_back(but->block);
1163 /* color picker, Gimp version. mode: 'f' = floating panel, 'p' = popup */
1164 /* col = read/write to, hsv/old/hexcol = memory for temporal use */
1165 void uiBlockPickerButtons(uiBlock *block, float *col, float *hsv, float *old, char *hexcol, char mode, short retval)
1171 VECCOPY(old, col); // old color stored there, for palette_cb to work
1173 // the cube intersection
1174 bt= uiDefButF(block, HSVCUBE, retval, "", 0,DPICK+BPICK,FPICK,FPICK, col, 0.0, 0.0, 2, 0, "");
1175 uiButSetFlag(bt, UI_NO_HILITE);
1177 bt= uiDefButF(block, HSVCUBE, retval, "", 0,0,FPICK,BPICK, col, 0.0, 0.0, 3, 0, "");
1178 uiButSetFlag(bt, UI_NO_HILITE);
1182 uiBlockSetEmboss(block, UI_EMBOSSP);
1184 bt=uiDefButF(block, COL, retval, "", FPICK+DPICK, 0, BPICK,BPICK, old, 0.0, 0.0, -1, 0, "Old color, click to restore");
1185 uiButSetFunc(bt, do_palette_cb, bt, col);
1186 uiDefButF(block, COL, retval, "", FPICK+DPICK, BPICK+DPICK, BPICK,60-BPICK-DPICK, col, 0.0, 0.0, -1, 0, "Active color");
1188 h= (DPICK+BPICK+FPICK-64)/(UI_PALETTE_TOT/2.0);
1189 uiBlockBeginAlign(block);
1190 for(a= -1+UI_PALETTE_TOT/2; a>=0; a--) {
1191 bt= uiDefButF(block, COL, retval, "", FPICK+DPICK, 65.0+(float)a*h, BPICK/2, h, palette[a+UI_PALETTE_TOT/2], 0.0, 0.0, -1, 0, "Click to choose, hold CTRL to store in palette");
1192 uiButSetFunc(bt, do_palette_cb, bt, col);
1193 bt= uiDefButF(block, COL, retval, "", FPICK+DPICK+BPICK/2, 65.0+(float)a*h, BPICK/2, h, palette[a], 0.0, 0.0, -1, 0, "Click to choose, hold CTRL to store in palette");
1194 uiButSetFunc(bt, do_palette_cb, bt, col);
1196 uiBlockEndAlign(block);
1198 uiBlockSetEmboss(block, UI_EMBOSS);
1201 rgb_to_hsv(col[0], col[1], col[2], hsv, hsv+1, hsv+2);
1202 sprintf(hexcol, "%02X%02X%02X", (unsigned int)(col[0]*255.0), (unsigned int)(col[1]*255.0), (unsigned int)(col[2]*255.0));
1204 offs= FPICK+2*DPICK+BPICK;
1206 /* note; made this a TOG now, with NULL pointer. Is because BUT now gets handled with a afterfunc */
1207 bt= uiDefIconTextBut(block, TOG, UI_RETURN_OK, ICON_EYEDROPPER, "Sample", offs+55, 170, 85, 20, NULL, 0, 0, 0, 0, "Sample the color underneath the following mouse click (ESC or RMB to cancel)");
1208 uiButSetFunc(bt, do_palette_sample_cb, bt, col);
1209 uiButSetFlag(bt, UI_TEXT_LEFT);
1211 bt= uiDefBut(block, TEX, retval, "Hex: ", offs, 140, 140, 20, hexcol, 0, 8, 0, 0, "Hex triplet for color (#RRGGBB)");
1212 uiButSetFunc(bt, do_palette_hex_cb, bt, hexcol);
1214 uiBlockBeginAlign(block);
1215 bt= uiDefButF(block, NUMSLI, retval, "R ", offs, 110, 140,20, col, 0.0, 1.0, 10, 3, "");
1216 uiButSetFunc(bt, do_palette1_cb, bt, hsv);
1217 bt= uiDefButF(block, NUMSLI, retval, "G ", offs, 90, 140,20, col+1, 0.0, 1.0, 10, 3, "");
1218 uiButSetFunc(bt, do_palette1_cb, bt, hsv);
1219 bt= uiDefButF(block, NUMSLI, retval, "B ", offs, 70, 140,20, col+2, 0.0, 1.0, 10, 3, "");
1220 uiButSetFunc(bt, do_palette1_cb, bt, hsv);
1222 uiBlockBeginAlign(block);
1223 bt= uiDefButF(block, NUMSLI, retval, "H ", offs, 40, 140,20, hsv, 0.0, 1.0, 10, 3, "");
1224 uiButSetFunc(bt, do_palette2_cb, bt, col);
1225 bt= uiDefButF(block, NUMSLI, retval, "S ", offs, 20, 140,20, hsv+1, 0.0, 1.0, 10, 3, "");
1226 uiButSetFunc(bt, do_palette2_cb, bt, col);
1227 bt= uiDefButF(block, NUMSLI, retval, "V ", offs, 0, 140,20, hsv+2, 0.0, 1.0, 10, 3, "");
1228 uiButSetFunc(bt, do_palette2_cb, bt, col);
1229 uiBlockEndAlign(block);
1232 uiBlock *ui_block_func_COL(bContext *C, uiMenuBlockHandle *handle, void *arg_but)
1234 uiBut *but= arg_but;
1236 static float hsvcol[3], oldcol[3];
1237 static char hexcol[128];
1239 block= uiBeginBlock(C, handle->region, "colorpicker", UI_EMBOSS, UI_HELV);
1240 block->flag= UI_BLOCK_LOOP|UI_BLOCK_REDRAW|UI_BLOCK_KEEP_OPEN;
1241 block->themecol= TH_BUT_NUM;
1243 VECCOPY(handle->retvec, but->editvec);
1244 uiBlockPickerButtons(block, handle->retvec, hsvcol, oldcol, hexcol, 'p', 0);
1247 block->direction= UI_TOP;
1248 uiBoundsBlock(block, 3);
1253 /* ******************** PUPmenu ****************** */
1255 static int pupmenu_set= 0;
1257 void pupmenu_set_active(int val)
1262 /* value== -1 read, otherwise set */
1263 static int pupmenu_memory(char *str, int value)
1265 static char mem[256], first=1;
1269 memset(mem, 0, 256);
1277 if(value >= 0) mem[ val & 255 ]= value;
1278 else return mem[ val & 255 ];
1283 #define PUP_LABELH 6
1285 typedef struct uiPupMenuInfo {
1292 uiBlock *ui_block_func_PUPMENU(bContext *C, uiMenuBlockHandle *handle, void *arg_info)
1295 uiPupMenuInfo *info;
1296 int columns, rows, mousemove[2]= {0, 0}, mousewarp= 0;
1297 int width, height, xmax, ymax, maxrow;
1298 int a, startx, starty, endx, endy, x1, y1;
1303 maxrow= info->maxrow;
1306 /* block stuff first, need to know the font */
1307 block= uiBeginBlock(C, handle->region, "menu", UI_EMBOSSP, UI_HELV);
1308 uiBlockSetFlag(block, UI_BLOCK_LOOP|UI_BLOCK_REDRAW|UI_BLOCK_RET_1|UI_BLOCK_NUMSELECT);
1309 block->themecol= TH_MENU_ITEM;
1311 md= decompose_menu_string(info->instr);
1316 /* size and location, title slightly bigger for bold */
1318 width= 2*strlen(md->title)+UI_GetStringWidth(uiBlockGetCurFont(block), md->title, ui_translate_buttons());
1323 for(a=0; a<md->nitems; a++) {
1324 xmax= UI_GetStringWidth(uiBlockGetCurFont(block), md->items[a].str, ui_translate_buttons());
1325 if(xmax>width) width= xmax;
1327 if(strcmp(md->items[a].str, "%l")==0) height+= PUP_LABELH;
1328 else height+= MENU_BUTTON_HEIGHT;
1332 if (width<50) width=50;
1334 wm_window_get_size(C->window, &xmax, &ymax);
1336 /* set first item */
1339 lastselected= pupmenu_set-1;
1342 else if(md->nitems>1) {
1343 lastselected= pupmenu_memory(info->instr, -1);
1346 startx= info->mx-(0.8*(width));
1347 starty= info->my-height+MENU_BUTTON_HEIGHT/2;
1348 if(lastselected>=0 && lastselected<md->nitems) {
1349 for(a=0; a<md->nitems; a++) {
1350 if(a==lastselected) break;
1351 if( strcmp(md->items[a].str, "%l")==0) starty+= PUP_LABELH;
1352 else starty+=MENU_BUTTON_HEIGHT;
1355 //starty= info->my-height+MENU_BUTTON_HEIGHT/2+lastselected*MENU_BUTTON_HEIGHT;
1362 mousemove[1]= 10-starty;
1366 endx= startx+width*columns;
1367 endy= starty+height;
1371 startx= endx-width*columns;
1374 mousemove[1]= ymax-endy-20;
1376 starty= endy-height;
1379 if(mousemove[0] || mousemove[1]) {
1380 ui_warp_pointer(info->mx+mousemove[0], info->my+mousemove[1]);
1381 mousemove[0]= info->mx;
1382 mousemove[1]= info->my;
1390 uiSetCurFont(block, UI_HELVB);
1394 sprintf(titlestr, " %s", md->title);
1395 uiDefIconTextBut(block, LABEL, 0, md->titleicon, titlestr, startx, (short)(starty+height), width, MENU_BUTTON_HEIGHT, NULL, 0.0, 0.0, 0, 0, "");
1398 bt= uiDefBut(block, LABEL, 0, md->title, startx, (short)(starty+height), columns*width, MENU_BUTTON_HEIGHT, NULL, 0.0, 0.0, 0, 0, "");
1399 bt->flag= UI_TEXT_LEFT;
1401 uiSetCurFont(block, UI_HELV);
1404 x1= startx + width*((int)a/rows);
1405 y1= starty + height - MENU_BUTTON_HEIGHT;
1407 for(a=0; a<md->nitems; a++) {
1408 char *name= md->items[a].str;
1409 int icon = md->items[a].icon;
1411 if(strcmp(name, "%l")==0) {
1412 uiDefBut(block, SEPR, B_NOP, "", x1, y1, width, PUP_LABELH, NULL, 0, 0.0, 0, 0, "");
1416 uiDefIconButF(block, BUTM, B_NOP, icon, x1, y1, width+16, MENU_BUTTON_HEIGHT-1, &handle->retvalue, (float) md->items[a].retval, 0.0, 0, 0, "");
1417 y1 -= MENU_BUTTON_HEIGHT;
1420 uiDefButF(block, BUTM, B_NOP, name, x1, y1, width, MENU_BUTTON_HEIGHT-1, &handle->retvalue, (float) md->items[a].retval, 0.0, 0, 0, "");
1421 y1 -= MENU_BUTTON_HEIGHT;
1425 uiBoundsBlock(block, 1);
1426 uiEndBlock(C, block);
1430 /* XXX 2.5 need to store last selected */
1432 /* calculate last selected */
1433 if(event & ui_return_ok) {
1435 for(a=0; a<md->nitems; a++) {
1436 if(val==md->items[a].retval) lastselected= a;
1439 pupmenu_memory(info->instr, lastselected);
1443 /* XXX 2.5 need to warp back */
1445 if(mousemove[1] && (event & ui_return_out)==0)
1446 ui_warp_pointer(mousemove[0], mousemove[1]);
1453 uiBlock *ui_block_func_PUPMENUCOL(bContext *C, uiMenuBlockHandle *handle, void *arg_info)
1456 uiPupMenuInfo *info;
1457 int columns, rows, mousemove[2]= {0, 0}, mousewarp;
1458 int width, height, xmax, ymax, maxrow;
1459 int a, startx, starty, endx, endy, x1, y1;
1464 maxrow= info->maxrow;
1467 /* block stuff first, need to know the font */
1468 block= uiBeginBlock(C, handle->region, "menu", UI_EMBOSSP, UI_HELV);
1469 uiBlockSetFlag(block, UI_BLOCK_LOOP|UI_BLOCK_REDRAW|UI_BLOCK_RET_1|UI_BLOCK_NUMSELECT);
1470 block->themecol= TH_MENU_ITEM;
1472 md= decompose_menu_string(info->instr);
1474 /* columns and row calculation */
1475 columns= (md->nitems+maxrow)/maxrow;
1476 if (columns<1) columns= 1;
1480 columns= (md->nitems+maxrow)/maxrow;
1483 rows= (int) md->nitems/columns;
1484 if (rows<1) rows= 1;
1486 while (rows*columns<(md->nitems+columns) ) rows++;
1488 /* size and location, title slightly bigger for bold */
1490 width= 2*strlen(md->title)+UI_GetStringWidth(uiBlockGetCurFont(block), md->title, ui_translate_buttons());
1495 for(a=0; a<md->nitems; a++) {
1496 xmax= UI_GetStringWidth(uiBlockGetCurFont(block), md->items[a].str, ui_translate_buttons());
1497 if(xmax>width) width= xmax;
1501 if (width<50) width=50;
1503 height= rows*MENU_BUTTON_HEIGHT;
1504 if (md->title) height+= MENU_BUTTON_HEIGHT;
1506 wm_window_get_size(C->window, &xmax, &ymax);
1508 /* find active item */
1509 fvalue= handle->retvalue;
1510 for(a=0; a<md->nitems; a++) {
1511 if( md->items[a].retval== (int)fvalue ) break;
1514 /* no active item? */
1516 if(md->title) a= -1;
1521 startx = info->mx-width/2 - ((int)(a)/rows)*width;
1523 startx= info->mx-width/2;
1524 starty = info->my-height + MENU_BUTTON_HEIGHT/2 + ((a)%rows)*MENU_BUTTON_HEIGHT;
1526 if (md->title) starty+= MENU_BUTTON_HEIGHT;
1529 mousemove[0]= 10-startx;
1533 mousemove[1]= 10-starty;
1537 endx= startx+width*columns;
1538 endy= starty+height;
1541 mousemove[0]= xmax-endx-10;
1543 startx= endx-width*columns;
1546 mousemove[1]= ymax-endy-10;
1548 starty= endy-height;
1551 if(mousemove[0] || mousemove[1]) {
1552 ui_warp_pointer(info->mx+mousemove[0], info->my+mousemove[1]);
1553 mousemove[0]= info->mx;
1554 mousemove[1]= info->my;
1561 uiSetCurFont(block, UI_HELVB);
1566 bt= uiDefBut(block, LABEL, 0, md->title, startx, (short)(starty+rows*MENU_BUTTON_HEIGHT), columns*width, MENU_BUTTON_HEIGHT, NULL, 0.0, 0.0, 0, 0, "");
1567 bt->flag= UI_TEXT_LEFT;
1569 uiSetCurFont(block, UI_HELV);
1572 for(a=0; a<md->nitems; a++) {
1573 char *name= md->items[a].str;
1574 int icon = md->items[a].icon;
1576 x1= startx + width*((int)a/rows);
1577 y1= starty - MENU_BUTTON_HEIGHT*(a%rows) + (rows-1)*MENU_BUTTON_HEIGHT;
1579 if(strcmp(name, "%l")==0) {
1580 uiDefBut(block, SEPR, B_NOP, "", x1, y1, width, PUP_LABELH, NULL, 0, 0.0, 0, 0, "");
1584 uiDefIconButF(block, BUTM, B_NOP, icon, x1, y1, width+16, MENU_BUTTON_HEIGHT-1, &handle->retvalue, (float) md->items[a].retval, 0.0, 0, 0, "");
1585 y1 -= MENU_BUTTON_HEIGHT;
1588 uiDefButF(block, BUTM, B_NOP, name, x1, y1, width, MENU_BUTTON_HEIGHT-1, &handle->retvalue, (float) md->items[a].retval, 0.0, 0, 0, "");
1589 y1 -= MENU_BUTTON_HEIGHT;
1593 uiBoundsBlock(block, 1);
1594 uiEndBlock(C, block);
1597 event= uiDoBlocks(&listb, 0, 1);
1602 /* XXX 2.5 need to warp back */
1604 if((event & UI_RETURN_OUT)==0)
1605 ui_warp_pointer(mousemove[0], mousemove[1]);
1611 uiMenuBlockHandle *pupmenu_col(bContext *C, char *instr, int mx, int my, int maxrow)
1615 memset(&info, 0, sizeof(info));
1619 info.maxrow= maxrow;
1621 return ui_menu_block_create(C, NULL, NULL, ui_block_func_PUPMENUCOL, &info);
1624 uiMenuBlockHandle *pupmenu(bContext *C, char *instr, int mx, int my)
1628 memset(&info, 0, sizeof(info));
1633 return ui_menu_block_create(C, NULL, NULL, ui_block_func_PUPMENU, &info);
1637 void pupmenu_free(bContext *C, uiMenuBlockHandle *handle)
1639 ui_menu_block_free(C, handle);
1642 /*************** Temporary Buttons Tests **********************/
1644 static uiBlock *test_submenu(bContext *C, uiMenuBlockHandle *handle, void *arg)
1646 ARegion *ar= handle->region;
1648 short yco= 0, menuwidth=120;
1650 block= uiBeginBlock(C, ar, "test_viewmenu", UI_EMBOSSP, UI_HELV);
1651 //uiBlockSetButmFunc(block, do_test_viewmenu, NULL);
1653 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Play Back Animation", 0, yco-=20,
1654 menuwidth, 19, NULL, 0.0, 0.0, 1, 2, "");
1656 uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
1658 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Show Seconds|T", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 5, "");
1660 uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_HLT,
1661 "Only Selected Data Keys|", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 12, "");
1663 uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
1665 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Jump To Next Marker|PageUp", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 6, "");
1666 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Jump To Prev Marker|PageDown", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 7, "");
1667 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Jump To Next Key|Ctrl PageUp", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 8, "");
1668 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Jump To Prev Key|Ctrl PageDown", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 9, "");
1670 uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
1672 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Center View|C", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 10, "");
1673 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "View All|Home", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 3, "");
1674 uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_HLT,
1675 "Lock Time to Other Windows|", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 11, "");
1677 uiBlockSetDirection(block, UI_RIGHT);
1679 uiTextBoundsBlock(block, 50);
1680 uiEndBlock(C, block);
1685 static uiBlock *test_viewmenu(bContext *C, uiMenuBlockHandle *handle, void *arg_area)
1687 ScrArea *area= arg_area;
1688 ARegion *ar= handle->region;
1690 short yco= 0, menuwidth=120;
1692 block= uiBeginBlock(C, ar, "test_viewmenu", UI_EMBOSSP, UI_HELV);
1693 //uiBlockSetButmFunc(block, do_test_viewmenu, NULL);
1695 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Play Back Animation", 0, yco-=20,
1696 menuwidth, 19, NULL, 0.0, 0.0, 1, 2, "");
1698 uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
1700 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Show Seconds|T", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 5, "");
1702 uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_HLT,
1703 "Only Selected Data Keys|", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 12, "");
1705 uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
1707 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Jump To Next Marker|PageUp", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 6, "");
1708 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Jump To Prev Marker|PageDown", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 7, "");
1709 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Jump To Next Key|Ctrl PageUp", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 8, "");
1710 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Jump To Prev Key|Ctrl PageDown", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 9, "");
1712 uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
1714 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Center View|C", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 10, "");
1715 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "View All|Home", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 3, "");
1716 uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_HLT,
1717 "Lock Time to Other Windows|", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 11, "");
1719 uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
1720 uiDefIconTextBlockBut(block, test_submenu, NULL, ICON_RIGHTARROW_THIN, "Sub Menu", 0, yco-=20, 120, 19, "");
1721 uiDefIconTextBlockBut(block, test_submenu, NULL, ICON_RIGHTARROW_THIN, "Sub Menu", 0, yco-=20, 120, 19, "");
1722 uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
1724 if(area->headertype==HEADERTOP) {
1725 uiBlockSetDirection(block, UI_DOWN);
1728 uiBlockSetDirection(block, UI_TOP);
1729 uiBlockFlipOrder(block);
1732 uiTextBoundsBlock(block, 50);
1733 uiEndBlock(C, block);
1738 void uiTestRegion(const bContext *C)
1743 static float testcol[3];
1744 static char testtext[64];
1745 static float testnumf=5.0f;
1746 static short testchoice= 0, testtog= 0, testicontog= 0;
1749 static CurveMapping *cumap= NULL;
1750 static ColorBand *coba= NULL;
1753 block= uiBeginBlock(C, C->region, "header buttons", UI_EMBOSS, UI_HELV);
1755 uiDefPulldownBut(block, test_viewmenu, C->area, "View",
1758 uiDefBut(block, BUT, 31415, "Type BUT",
1759 13+50+5, 3, 80, 20, NULL, 0, 0, 0, 0, "A tooltip.");
1760 uiDefButS(block, MENU, 31416, "Gather Method%t|Raytrace %x0|Approximate %x1",
1761 13+50+5+80+5, 3, 100, 20, &testchoice, 0, 0, 0, 0, "Method for occlusion gathering");
1762 uiDefButBitS(block, TOG, 1, 31417, "Pixel Cache",
1763 13+50+5+80+5+100+5, 3, 100, 20, &testtog, 0, 0, 0, 0, "Cache AO results in pixels and interpolate over neighbouring pixels for speedup.");
1765 uiDefBut(block, TEX, 31418, "Text: ",
1766 13+50+5+80+5+100+5+100+5, 3, 200, 20, testtext, 0, sizeof(testtext), 0, 0, "User defined text");
1768 uiDefButF(block, NUMSLI, 31419, "Slider: ",
1769 13+50+5+80+5+100+5+100+5+200+5, 3, 150, 20, &testnumf, 0.0, 10.0, 0, 0, "Some tooltip.");
1770 uiDefButF(block, NUM, 31419, "N: ",
1771 13+50+5+80+5+100+5+100+5+200+5+150+5, 3, 100, 20, &testnumf, 0.0, 10.0, 0, 0, "Some tooltip.");
1773 uiDefButF(block, COL, 3142, "",
1774 13+50+5+80+5+100+5+100+5+200+5+150+5+100+5, 3, 100, 20, testcol, 0, 0, 0, 0 /*B_BANDCOL*/, "");
1776 xco = 13+50+5+80+5+100+5+100+5+200+5+150+5+100+5+100+5;
1777 uiDefIconButBitS(block, ICONTOG, 1 /*AUTOKEY_ON*/, REDRAWINFO, ICON_PYTHON,
1778 xco, 3, 20, 20, &testicontog, 0, 0, 0, 0, "Automatic keyframe insertion for Objects and Bones");
1783 cumap= curvemapping_add(4, 0.0f, 0.0f, 1.0f, 1.0f);
1784 cumap->flag &= ~CUMA_DO_CLIP;
1787 coba= add_colorband(0);
1789 uiDefBut(block, BUT_CURVE, 3143, "",
1790 13+400, 33, 100, 100, cumap, 0.0f, 1.0f, 0, 0, "");
1791 uiDefBut(block, BUT_COLORBAND, 3143, "",
1792 13+400+100+10, 33, 150, 30, coba, 0.0f, 1.0f, 0, 0, "");
1795 uiEndBlock(C, block);