5 #include "MEM_guardedalloc.h"
7 #include "DNA_screen_types.h"
8 #include "DNA_windowmanager_types.h"
10 #include "BLI_arithb.h"
11 #include "BLI_blenlib.h"
13 #include "BKE_global.h"
14 #include "BKE_screen.h"
15 #include "BKE_utildefines.h"
19 #include "wm_subwindow.h"
20 #include "wm_window.h"
25 #include "UI_interface.h"
27 #include "ED_screen.h"
29 #include "interface.h"
31 #define MENU_BUTTON_HEIGHT 20
33 #define MENU_SHADOW_LEFT -1
34 #define MENU_SHADOW_BOTTOM -10
35 #define MENU_SHADOW_RIGHT 10
36 #define MENU_SHADOW_TOP 1
38 /*********************** Menu Data Parsing ********************* */
52 int nitems, itemssize;
55 static MenuData *menudata_new(char *instr)
57 MenuData *md= MEM_mallocN(sizeof(*md), "MenuData");
63 md->nitems= md->itemssize= 0;
68 static void menudata_set_title(MenuData *md, char *title, int titleicon)
73 md->titleicon= titleicon;
76 static void menudata_add_item(MenuData *md, char *str, int retval, int icon)
78 if (md->nitems==md->itemssize) {
79 int nsize= md->itemssize?(md->itemssize<<1):1;
80 MenuEntry *oitems= md->items;
82 md->items= MEM_mallocN(nsize*sizeof(*md->items), "md->items");
84 memcpy(md->items, oitems, md->nitems*sizeof(*md->items));
91 md->items[md->nitems].str= str;
92 md->items[md->nitems].retval= retval;
93 md->items[md->nitems].icon= icon;
97 void menudata_free(MenuData *md)
101 MEM_freeN(md->items);
106 * Parse menu description strings, string is of the
107 * form "[sss%t|]{(sss[%xNN]|), (%l|)}", ssss%t indicates the
108 * menu title, sss or sss%xNN indicates an option,
109 * if %xNN is given then NN is the return value if
110 * that option is selected otherwise the return value
111 * is the index of the option (starting with 1). %l
112 * indicates a seperator.
114 * @param str String to be parsed.
115 * @retval new menudata structure, free with menudata_free()
117 MenuData *decompose_menu_string(char *str)
119 char *instr= BLI_strdup(str);
120 MenuData *md= menudata_new(instr);
121 char *nitem= NULL, *s= instr;
122 int nicon=0, nretval= 1, nitem_is_title= 0;
133 } else if (s[1]=='t') {
138 } else if (s[1]=='l') {
141 } else if (s[1]=='i') {
147 } else if (c=='|' || c=='\0') {
151 if (nitem_is_title) {
152 menudata_set_title(md, nitem, nicon);
155 /* prevent separator to get a value */
156 if(nitem[0]=='%' && nitem[1]=='l')
157 menudata_add_item(md, nitem, -1, nicon);
159 menudata_add_item(md, nitem, nretval, nicon);
160 nretval= md->nitems+1;
178 void ui_set_name_menu(uiBut *but, int value)
183 md= decompose_menu_string(but->str);
184 for (i=0; i<md->nitems; i++)
185 if (md->items[i].retval==value)
186 strcpy(but->drawstr, md->items[i].str);
191 /******************** Creating Temporary regions ******************/
193 ARegion *ui_add_temporary_region(bScreen *sc)
197 ar= MEM_callocN(sizeof(ARegion), "area region");
198 BLI_addtail(&sc->regionbase, ar);
200 ar->regiontype= RGN_TYPE_TEMPORARY;
201 ar->alignment= RGN_ALIGN_FLOAT;
206 void ui_remove_temporary_region(bContext *C, bScreen *sc, ARegion *ar)
208 ED_region_exit(C, ar);
209 BKE_area_region_free(ar);
210 BLI_freelinkN(&sc->regionbase, ar);
213 /************************* Creating Tooltips **********************/
215 typedef struct uiTooltipData {
217 struct BMF_Font *font;
222 static void ui_tooltip_region_draw(const bContext *C, ARegion *ar)
227 data= ar->regiondata;
234 /* draw drop shadow */
235 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
238 glColor4ub(0, 0, 0, 20);
240 gl_round_box(GL_POLYGON, 3, 3, x2-x1-3, y2-y1-2, 2.0);
241 gl_round_box(GL_POLYGON, 3, 2, x2-x1-2, y2-y1-2, 3.0);
243 glColor4ub(0, 0, 0, 8);
245 gl_round_box(GL_POLYGON, 3, 1, x2-x1-1, y2-y1-3, 4.0);
246 gl_round_box(GL_POLYGON, 3, 0, x2-x1-0, y2-y1-3, 5.0);
250 /* draw background */
251 glColor3f(1.0f, 1.0f, 0.8666f);
252 glRectf(0, 4, x2-x1-4, y2-y1);
257 /* set the position for drawing text +4 in from the left edge, and leaving
258 * an equal gap between the top of the background box and the top of the
259 * string's bbox, and the bottom of the background box, and the bottom of
260 * the string's bbox */
261 ui_rasterpos_safe(4, ((y2-data->bbox.ymax)+(y1+data->bbox.ymin))/2 - data->bbox.ymin - y1, data->aspect);
264 UI_DrawString(data->font, data->tip, ui_translate_tooltips());
267 static void ui_tooltip_region_free(ARegion *ar)
271 data= ar->regiondata;
272 MEM_freeN(data->tip);
276 ARegion *ui_tooltip_create(bContext *C, ARegion *butregion, uiBut *but)
278 static ARegionType type={NULL, NULL, NULL, NULL, NULL};
281 int x1, x2, y1, y2, winx, winy;
283 if(!but->tip || strlen(but->tip)==0)
286 /* create area region */
287 ar= ui_add_temporary_region(C->window->screen);
289 type.draw= ui_tooltip_region_draw;
290 type.free= ui_tooltip_region_free;
293 /* create tooltip data */
294 data= MEM_callocN(sizeof(uiTooltipData), "uiTooltipData");
295 data->tip= BLI_strdup(but->tip);
296 data->font= but->font;
297 data->aspect= but->aspect;
298 UI_GetBoundingBox(data->font, data->tip, ui_translate_tooltips(), &data->bbox);
300 ar->regiondata= data;
302 /* compute position */
303 x1= (but->x1+but->x2)/2;
304 x2= x1+but->aspect*((data->bbox.xmax-data->bbox.xmin) + 8);
306 y1= y2-but->aspect*((data->bbox.ymax+(data->bbox.ymax-data->bbox.ymin)));
312 x1 += butregion->winrct.xmin;
313 x2 += butregion->winrct.xmin;
314 y1 += butregion->winrct.ymin;
315 y2 += butregion->winrct.ymin;
318 wm_window_get_size(C->window, &winx, &winy);
334 /* notify change and redraw */
335 WM_event_add_notifier(C->wm, C->window, 0, WM_NOTE_SCREEN_CHANGED, 0, NULL);
336 WM_event_add_notifier(C->wm, C->window, 0, WM_NOTE_WINDOW_REDRAW, 0, NULL);
341 void ui_tooltip_free(bContext *C, ARegion *ar)
343 ui_remove_temporary_region(C, C->window->screen, ar);
345 WM_event_add_notifier(C->wm, C->window, 0, WM_NOTE_SCREEN_CHANGED, 0, NULL);
346 WM_event_add_notifier(C->wm, C->window, 0, WM_NOTE_WINDOW_REDRAW, 0, NULL);
349 /************************* Creating Menu Blocks **********************/
351 /* position block relative to but, result is in window space */
352 static void ui_block_position(wmWindow *window, ARegion *butregion, uiBut *but, uiBlock *block)
355 uiSafetyRct *saferct;
358 int xsize, ysize, xof=0, yof=0, center;
359 short dir1= 0, dir2=0;
361 /* transform to window coordinates, using the source button region/block */
362 butrct.xmin= but->x1; butrct.xmax= but->x2;
363 butrct.ymin= but->y1; butrct.ymax= but->y2;
365 ui_block_to_window_fl(butregion, but->block, &butrct.xmin, &butrct.ymin);
366 ui_block_to_window_fl(butregion, but->block, &butrct.xmax, &butrct.ymax);
368 /* calc block rect */
369 if(block->minx == 0.0f && block->maxx == 0.0f) {
370 if(block->buttons.first) {
371 block->minx= block->miny= 10000;
372 block->maxx= block->maxy= -10000;
374 bt= block->buttons.first;
376 if(bt->x1 < block->minx) block->minx= bt->x1;
377 if(bt->y1 < block->miny) block->miny= bt->y1;
379 if(bt->x2 > block->maxx) block->maxx= bt->x2;
380 if(bt->y2 > block->maxy) block->maxy= bt->y2;
386 /* we're nice and allow empty blocks too */
387 block->minx= block->miny= 0;
388 block->maxx= block->maxy= 20;
392 aspect= (float)(block->maxx - block->minx + 4);
393 ui_block_to_window_fl(butregion, but->block, &block->minx, &block->miny);
394 ui_block_to_window_fl(butregion, but->block, &block->maxx, &block->maxy);
396 //block->minx-= 2.0; block->miny-= 2.0;
397 //block->maxx+= 2.0; block->maxy+= 2.0;
399 xsize= block->maxx - block->minx+4; // 4 for shadow
400 ysize= block->maxy - block->miny+4;
401 aspect/= (float)xsize;
404 int left=0, right=0, top=0, down=0;
407 wm_window_get_size(window, &winx, &winy);
409 if(block->direction & UI_CENTER) center= ysize/2;
412 if( butrct.xmin-xsize > 0.0) left= 1;
413 if( butrct.xmax+xsize < winx) right= 1;
414 if( butrct.ymin-ysize+center > 0.0) down= 1;
415 if( butrct.ymax+ysize-center < winy) top= 1;
417 dir1= block->direction & UI_DIRECTION;
419 /* secundary directions */
420 if(dir1 & (UI_TOP|UI_DOWN)) {
421 if(dir1 & UI_LEFT) dir2= UI_LEFT;
422 else if(dir1 & UI_RIGHT) dir2= UI_RIGHT;
423 dir1 &= (UI_TOP|UI_DOWN);
426 if(dir2==0) if(dir1==UI_LEFT || dir1==UI_RIGHT) dir2= UI_DOWN;
427 if(dir2==0) if(dir1==UI_TOP || dir1==UI_DOWN) dir2= UI_LEFT;
429 /* no space at all? dont change */
431 if(dir1==UI_LEFT && left==0) dir1= UI_RIGHT;
432 if(dir1==UI_RIGHT && right==0) dir1= UI_LEFT;
433 /* this is aligning, not append! */
434 if(dir2==UI_LEFT && right==0) dir2= UI_RIGHT;
435 if(dir2==UI_RIGHT && left==0) dir2= UI_LEFT;
438 if(dir1==UI_TOP && top==0) dir1= UI_DOWN;
439 if(dir1==UI_DOWN && down==0) dir1= UI_TOP;
440 if(dir2==UI_TOP && top==0) dir2= UI_DOWN;
441 if(dir2==UI_DOWN && down==0) dir2= UI_TOP;
445 xof= butrct.xmin - block->maxx;
446 if(dir2==UI_TOP) yof= butrct.ymin - block->miny-center;
447 else yof= butrct.ymax - block->maxy+center;
449 else if(dir1==UI_RIGHT) {
450 xof= butrct.xmax - block->minx;
451 if(dir2==UI_TOP) yof= butrct.ymin - block->miny-center;
452 else yof= butrct.ymax - block->maxy+center;
454 else if(dir1==UI_TOP) {
455 yof= butrct.ymax - block->miny;
456 if(dir2==UI_RIGHT) xof= butrct.xmax - block->maxx;
457 else xof= butrct.xmin - block->minx;
458 // changed direction?
459 if((dir1 & block->direction)==0) {
460 if(block->direction & UI_SHIFT_FLIPPED)
461 xof+= dir2==UI_LEFT?25:-25;
462 uiBlockFlipOrder(block);
465 else if(dir1==UI_DOWN) {
466 yof= butrct.ymin - block->maxy;
467 if(dir2==UI_RIGHT) xof= butrct.xmax - block->maxx;
468 else xof= butrct.xmin - block->minx;
469 // changed direction?
470 if((dir1 & block->direction)==0) {
471 if(block->direction & UI_SHIFT_FLIPPED)
472 xof+= dir2==UI_LEFT?25:-25;
473 uiBlockFlipOrder(block);
477 /* and now we handle the exception; no space below or to top */
478 if(top==0 && down==0) {
479 if(dir1==UI_LEFT || dir1==UI_RIGHT) {
480 // align with bottom of screen
485 /* or no space left or right */
486 if(left==0 && right==0) {
487 if(dir1==UI_TOP || dir1==UI_DOWN) {
488 // align with left size of screen
493 // apply requested offset in the block
494 xof += block->xofs/block->aspect;
495 yof += block->yofs/block->aspect;
500 for(bt= block->buttons.first; bt; bt= bt->next) {
501 ui_block_to_window_fl(butregion, but->block, &bt->x1, &bt->y1);
502 ui_block_to_window_fl(butregion, but->block, &bt->x2, &bt->y2);
510 // ui_check_but recalculates drawstring size in pixels
519 /* safety calculus */
521 float midx= (butrct.xmin+butrct.xmax)/2.0;
522 float midy= (butrct.ymin+butrct.ymax)/2.0;
524 /* when you are outside parent button, safety there should be smaller */
526 // parent button to left
527 if( midx < block->minx ) block->safety.xmin= block->minx-3;
528 else block->safety.xmin= block->minx-40;
529 // parent button to right
530 if( midx > block->maxx ) block->safety.xmax= block->maxx+3;
531 else block->safety.xmax= block->maxx+40;
533 // parent button on bottom
534 if( midy < block->miny ) block->safety.ymin= block->miny-3;
535 else block->safety.ymin= block->miny-40;
536 // parent button on top
537 if( midy > block->maxy ) block->safety.ymax= block->maxy+3;
538 else block->safety.ymax= block->maxy+40;
540 // exception for switched pulldowns...
541 if(dir1 && (dir1 & block->direction)==0) {
542 if(dir2==UI_RIGHT) block->safety.xmax= block->maxx+3;
543 if(dir2==UI_LEFT) block->safety.xmin= block->minx-3;
545 block->direction= dir1;
548 block->safety.xmin= block->minx-40;
549 block->safety.ymin= block->miny-40;
550 block->safety.xmax= block->maxx+40;
551 block->safety.ymax= block->maxy+40;
554 /* keep a list of these, needed for pulldown menus */
555 saferct= MEM_callocN(sizeof(uiSafetyRct), "uiSafetyRct");
556 saferct->parent= butrct;
557 saferct->safety= block->safety;
558 BLI_freelistN(&block->saferct);
560 BLI_duplicatelist(&block->saferct, &but->block->saferct);
561 BLI_addhead(&block->saferct, saferct);
564 static void ui_block_region_draw(const bContext *C, ARegion *ar)
568 for(block=ar->uiblocks.first; block; block=block->next) {
569 wm_subwindow_getmatrix(C->window, ar->swinid, block->winmat);
574 static void ui_block_region_free(ARegion *ar)
576 uiFreeBlocks(&ar->uiblocks);
579 uiMenuBlockHandle *ui_menu_block_create(bContext *C, ARegion *butregion, uiBut *but, uiBlockFuncFP block_func, void *arg)
581 static ARegionType type={NULL, NULL, NULL, NULL, NULL};
585 uiMenuBlockHandle *handle;
586 uiSafetyRct *saferct;
589 handle= MEM_callocN(sizeof(uiMenuBlockHandle), "uiMenuBlockHandle");
591 /* create area region */
592 ar= ui_add_temporary_region(C->window->screen);
594 type.draw= ui_block_region_draw;
595 type.free= ui_block_region_free;
598 WM_event_add_keymap_handler(&ar->handlers, &C->wm->uikeymap);
601 ar->regiondata= handle;
603 /* create ui block */
604 block= block_func(C->window, handle, arg);
605 block->handle= handle;
607 /* if this is being created from a button */
609 if(ELEM(but->type, BLOCK, PULLDOWN))
610 block->xofs = -2; /* for proper alignment */
612 /* only used for automatic toolbox, so can set the shift flag */
613 if(but->flag & UI_MAKE_TOP) {
614 block->direction= UI_TOP|UI_SHIFT_FLIPPED;
615 uiBlockFlipOrder(block);
617 if(but->flag & UI_MAKE_DOWN) block->direction= UI_DOWN|UI_SHIFT_FLIPPED;
618 if(but->flag & UI_MAKE_LEFT) block->direction |= UI_LEFT;
619 if(but->flag & UI_MAKE_RIGHT) block->direction |= UI_RIGHT;
621 ui_block_position(C->window, butregion, but, block);
624 /* keep a list of these, needed for pulldown menus */
625 saferct= MEM_callocN(sizeof(uiSafetyRct), "uiSafetyRct");
626 saferct->safety= block->safety;
627 BLI_addhead(&block->saferct, saferct);
630 /* the block and buttons were positioned in window space as in 2.4x, now
631 * these menu blocks are regions so we bring it back to region space.
632 * additionally we add some padding for the menu shadow */
633 ar->winrct.xmin= block->minx + MENU_SHADOW_LEFT;
634 ar->winrct.xmax= block->maxx + MENU_SHADOW_RIGHT;
635 ar->winrct.ymin= block->miny + MENU_SHADOW_BOTTOM;
636 ar->winrct.ymax= block->maxy + MENU_SHADOW_TOP;
638 block->minx -= ar->winrct.xmin;
639 block->maxx -= ar->winrct.xmin;
640 block->miny -= ar->winrct.ymin;
641 block->maxy -= ar->winrct.ymin;
643 for(bt= block->buttons.first; bt; bt= bt->next) {
644 bt->x1 -= ar->winrct.xmin;
645 bt->x2 -= ar->winrct.xmin;
646 bt->y1 -= ar->winrct.ymin;
647 bt->y2 -= ar->winrct.ymin;
650 block->flag |= UI_BLOCK_LOOP|UI_BLOCK_MOVEMOUSE_QUIT;
652 /* notify change and redraw */
653 WM_event_add_notifier(C->wm, C->window, 0, WM_NOTE_SCREEN_CHANGED, 0, NULL);
654 WM_event_add_notifier(C->wm, C->window, 0, WM_NOTE_WINDOW_REDRAW, 0, NULL);
656 SWAP(ARegion*, C->region, ar); /* XXX 2.50 bad context swapping */
657 WM_operator_invoke(C, WM_operatortype_find("ED_UI_OT_menu_block_handle"), NULL);
658 SWAP(ARegion*, C->region, ar);
663 void ui_menu_block_free(bContext *C, uiMenuBlockHandle *handle)
665 ui_remove_temporary_region(C, C->window->screen, handle->region);
668 WM_event_add_notifier(C->wm, C->window, 0, WM_NOTE_SCREEN_CHANGED, 0, NULL);
669 WM_event_add_notifier(C->wm, C->window, 0, WM_NOTE_WINDOW_REDRAW, 0, NULL);
672 /***************************** Menu Button ***************************/
674 uiBlock *ui_block_func_MENU(wmWindow *window, uiMenuBlockHandle *handle, void *arg_but)
682 int width, height, boxh, columns, rows, startx, starty, x1, y1, xmax, a;
684 /* create the block */
685 block= uiBeginBlock(window, handle->region, "menu", UI_EMBOSSP, UI_HELV);
686 block->dt= UI_EMBOSSP;
687 block->flag= UI_BLOCK_LOOP|UI_BLOCK_REDRAW|UI_BLOCK_NUMSELECT;
688 block->themecol= TH_MENU_ITEM;
690 /* compute menu data */
691 md= decompose_menu_string(but->str);
693 /* columns and row calculation */
694 columns= (md->nitems+20)/20;
698 columns= (md->nitems+25)/25;
700 rows= md->nitems/columns;
703 while(rows*columns<md->nitems)
706 /* prevent scaling up of pupmenu */
711 /* size and location */
713 width= 1.5*aspect*strlen(md->title)+UI_GetStringWidth(block->curfont, md->title, ui_translate_menus());
717 for(a=0; a<md->nitems; a++) {
718 xmax= aspect*UI_GetStringWidth(block->curfont, md->items[a].str, ui_translate_menus());
719 if(md->items[a].icon)
726 if(width < (but->x2 - but->x1))
727 width = (but->x2 - but->x1);
731 boxh= MENU_BUTTON_HEIGHT;
743 uiSetCurFont(block, block->font+1);
745 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, "");
747 bt= uiDefBut(block, LABEL, 0, md->title, startx, (short)(starty+rows*boxh), (short)width, (short)boxh, NULL, 0.0, 0.0, 0, 0, "");
748 bt->flag= UI_TEXT_LEFT;
750 uiSetCurFont(block, block->font);
753 for(a=0; a<md->nitems; a++) {
755 x1= startx + width*((int)(md->nitems-a-1)/rows);
756 y1= starty - boxh*(rows - ((md->nitems - a - 1)%rows)) + (rows*boxh);
758 if (strcmp(md->items[md->nitems-a-1].str, "%l")==0) {
759 bt= uiDefBut(block, SEPR, B_NOP, "", x1, y1,(short)(width-(rows>1)), (short)(boxh-1), NULL, 0.0, 0.0, 0, 0, "");
761 else if(md->items[md->nitems-a-1].icon) {
762 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, "");
765 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, "");
771 /* the code up here has flipped locations, because of change of preferred order */
772 /* thats why we have to switch list order too, to make arrowkeys work */
774 lb.first= lb.last= NULL;
775 bt= block->buttons.first;
777 uiBut *next= bt->next;
778 BLI_remlink(&block->buttons, bt);
779 BLI_addhead(&lb, bt);
784 block->direction= UI_TOP;
790 uiBlock *ui_block_func_ICONROW(wmWindow *window, uiMenuBlockHandle *handle, void *arg_but)
796 block= uiBeginBlock(window, handle->region, "menu", UI_EMBOSSP, UI_HELV);
797 block->flag= UI_BLOCK_LOOP|UI_BLOCK_REDRAW|UI_BLOCK_NUMSELECT;
798 block->themecol= TH_MENU_ITEM;
800 for(a=(int)but->min; a<=(int)but->max; a++) {
801 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, "");
804 block->direction= UI_TOP;
811 uiBlock *ui_block_func_ICONTEXTROW(wmWindow *window, uiMenuBlockHandle *handle, void *arg_but)
816 int width, xmax, ypos, a;
818 block= uiBeginBlock(window, handle->region, "menu", UI_EMBOSSP, UI_HELV);
819 block->flag= UI_BLOCK_LOOP|UI_BLOCK_REDRAW|UI_BLOCK_NUMSELECT;
820 block->themecol= TH_MENU_ITEM;
822 md= decompose_menu_string(but->str);
824 /* size and location */
825 /* expand menu width to fit labels */
827 width= 2*strlen(md->title)+UI_GetStringWidth(block->curfont, md->title, ui_translate_menus());
831 for(a=0; a<md->nitems; a++) {
832 xmax= UI_GetStringWidth(block->curfont, md->items[a].str, ui_translate_menus());
833 if(xmax>width) width= xmax;
837 if (width<50) width=50;
841 /* loop through the menu options and draw them out with icons & text labels */
842 for(a=0; a<md->nitems; a++) {
844 /* add a space if there's a separator (%l) */
845 if (strcmp(md->items[a].str, "%l")==0) {
849 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, "");
856 uiSetCurFont(block, block->font+1);
857 bt= uiDefBut(block, LABEL, 0, md->title, 0, ypos, (short)width, 19, NULL, 0.0, 0.0, 0, 0, "");
858 uiSetCurFont(block, block->font);
859 bt->flag= UI_TEXT_LEFT;
864 block->direction= UI_TOP;
866 uiBoundsBlock(block, 3);
872 static void ui_warp_pointer(short x, short y)
874 /* XXX 2.50 which function to use for this? */
876 /* OSX has very poor mousewarp support, it sends events;
877 this causes a menu being pressed immediately ... */
884 /********************* Color Button ****************/
886 /* picker sizes S hsize, F full size, D spacer, B button/pallette height */
892 #define UI_PALETTE_TOT 16
893 /* note; in tot+1 the old color is stored */
894 static float palette[UI_PALETTE_TOT+1][3]= {
895 {0.93, 0.83, 0.81}, {0.88, 0.89, 0.73}, {0.69, 0.81, 0.57}, {0.51, 0.76, 0.64},
896 {0.37, 0.56, 0.61}, {0.33, 0.29, 0.55}, {0.46, 0.21, 0.51}, {0.40, 0.12, 0.18},
897 {1.0, 1.0, 1.0}, {0.85, 0.85, 0.85}, {0.7, 0.7, 0.7}, {0.56, 0.56, 0.56},
898 {0.42, 0.42, 0.42}, {0.28, 0.28, 0.28}, {0.14, 0.14, 0.14}, {0.0, 0.0, 0.0}
901 /* for picker, while editing hsv */
902 void ui_set_but_hsv(uiBut *but)
906 hsv_to_rgb(but->hsv[0], but->hsv[1], but->hsv[2], col, col+1, col+2);
907 ui_set_but_vectorf(but, col);
910 static void update_picker_hex(uiBlock *block, float *rgb)
915 sprintf(col, "%02X%02X%02X", (unsigned int)(rgb[0]*255.0), (unsigned int)(rgb[1]*255.0), (unsigned int)(rgb[2]*255.0));
917 // this updates button strings, is hackish... but button pointers are on stack of caller function
919 for(bt= block->buttons.first; bt; bt= bt->next) {
920 if(strcmp(bt->str, "Hex: ")==0) {
921 strcpy(bt->poin, col);
928 void ui_update_block_buts_hsv(uiBlock *block, float *hsv)
934 // this updates button strings, is hackish... but button pointers are on stack of caller function
935 hsv_to_rgb(hsv[0], hsv[1], hsv[2], &r, &g, &b);
937 rgb[0] = r; rgb[1] = g; rgb[2] = b;
938 update_picker_hex(block, rgb);
940 for(bt= block->buttons.first; bt; bt= bt->next) {
941 if(bt->type==HSVCUBE) {
942 VECCOPY(bt->hsv, hsv);
945 else if(bt->str[1]==' ') {
946 if(bt->str[0]=='R') {
947 ui_set_but_val(bt, r);
949 else if(bt->str[0]=='G') {
950 ui_set_but_val(bt, g);
952 else if(bt->str[0]=='B') {
953 ui_set_but_val(bt, b);
955 else if(bt->str[0]=='H') {
956 ui_set_but_val(bt, hsv[0]);
958 else if(bt->str[0]=='S') {
959 ui_set_but_val(bt, hsv[1]);
961 else if(bt->str[0]=='V') {
962 ui_set_but_val(bt, hsv[2]);
968 static void ui_update_block_buts_hex(uiBlock *block, char *hexcol)
975 // this updates button strings, is hackish... but button pointers are on stack of caller function
976 hex_to_rgb(hexcol, &r, &g, &b);
977 rgb_to_hsv(r, g, b, &h, &s, &v);
979 for(bt= block->buttons.first; bt; bt= bt->next) {
980 if(bt->type==HSVCUBE) {
986 else if(bt->str[1]==' ') {
987 if(bt->str[0]=='R') {
988 ui_set_but_val(bt, r);
990 else if(bt->str[0]=='G') {
991 ui_set_but_val(bt, g);
993 else if(bt->str[0]=='B') {
994 ui_set_but_val(bt, b);
996 else if(bt->str[0]=='H') {
997 ui_set_but_val(bt, h);
999 else if(bt->str[0]=='S') {
1000 ui_set_but_val(bt, s);
1002 else if(bt->str[0]=='V') {
1003 ui_set_but_val(bt, v);
1009 /* bt1 is palette but, col1 is original color */
1010 /* callback to copy from/to palette */
1011 static void do_palette_cb(void *bt1, void *col1)
1013 uiBut *but1= (uiBut *)bt1;
1014 float *col= (float *)col1;
1017 fp= (float *)but1->poin;
1019 /* XXX 2.50 bad access, how to solve?
1021 if( (get_qual() & LR_CTRLKEY) ) {
1028 rgb_to_hsv(col[0], col[1], col[2], hsv, hsv+1, hsv+2);
1029 ui_update_block_buts_hsv(but1->block, hsv);
1030 update_picker_hex(but1->block, col);
1033 /* bt1 is num but, hsv1 is pointer to original color in hsv space*/
1034 /* callback to handle changes in num-buts in picker */
1035 static void do_palette1_cb(void *bt1, void *hsv1)
1037 uiBut *but1= (uiBut *)bt1;
1038 float *hsv= (float *)hsv1;
1041 if(but1->str[1]==' ') {
1042 if(but1->str[0]=='R') fp= (float *)but1->poin;
1043 else if(but1->str[0]=='G') fp= ((float *)but1->poin)-1;
1044 else if(but1->str[0]=='B') fp= ((float *)but1->poin)-2;
1047 rgb_to_hsv(fp[0], fp[1], fp[2], hsv, hsv+1, hsv+2);
1049 ui_update_block_buts_hsv(but1->block, hsv);
1052 /* bt1 is num but, col1 is pointer to original color */
1053 /* callback to handle changes in num-buts in picker */
1054 static void do_palette2_cb(void *bt1, void *col1)
1056 uiBut *but1= (uiBut *)bt1;
1057 float *rgb= (float *)col1;
1060 if(but1->str[1]==' ') {
1061 if(but1->str[0]=='H') fp= (float *)but1->poin;
1062 else if(but1->str[0]=='S') fp= ((float *)but1->poin)-1;
1063 else if(but1->str[0]=='V') fp= ((float *)but1->poin)-2;
1066 hsv_to_rgb(fp[0], fp[1], fp[2], rgb, rgb+1, rgb+2);
1068 ui_update_block_buts_hsv(but1->block, fp);
1071 static void do_palette_hex_cb(void *bt1, void *hexcl)
1073 uiBut *but1= (uiBut *)bt1;
1074 char *hexcol= (char *)hexcl;
1076 ui_update_block_buts_hex(but1->block, hexcol);
1079 /* used for both 3d view and image window */
1080 static void do_palette_sample_cb(void *bt1, void *col1) /* frontbuf */
1082 /* XXX 2.50 this should become an operator? */
1084 uiBut *but1= (uiBut *)bt1;
1095 oldcursor=get_cursor();
1096 win=winlay_get_active_window();
1098 while (get_mbut() & L_MOUSE) UI_wait_for_statechange();
1100 SetBlenderCursor(BC_EYEDROPPER_CURSOR);
1102 /* loop and wait for a mouse click */
1108 dev = extern_qread_ext(&val, &ascii);
1110 if(dev==INPUTCHANGE) break;
1111 if(get_mbut() & R_MOUSE) break;
1112 else if(get_mbut() & L_MOUSE) {
1113 uiGetMouse(mywinget(), mval);
1114 x= mval[0]; y= mval[1];
1119 else if(dev==ESCKEY) break;
1121 window_set_cursor(win, oldcursor);
1123 if(capturing) return;
1125 if(x<0 || y<0) return;
1127 /* if we've got a glick, use OpenGL to sample the color under the mouse pointer */
1128 glReadBuffer(GL_FRONT);
1129 glReadPixels(x, y, 1, 1, GL_RGBA, GL_FLOAT, tempcol);
1130 glReadBuffer(GL_BACK);
1132 /* and send that color back to the picker */
1133 rgb_to_hsv(tempcol[0], tempcol[1], tempcol[2], hsv, hsv+1, hsv+2);
1134 ui_update_block_buts_hsv(but1->block, hsv);
1135 update_picker_hex(but1->block, tempcol);
1137 for (but= but1->block->buttons.first; but; but= but->next) {
1142 but= but1->block->buttons.first;
1143 ui_block_flush_back(but->block);
1147 /* color picker, Gimp version. mode: 'f' = floating panel, 'p' = popup */
1148 /* col = read/write to, hsv/old/hexcol = memory for temporal use */
1149 void uiBlockPickerButtons(uiBlock *block, float *col, float *hsv, float *old, char *hexcol, char mode, short retval)
1155 VECCOPY(old, col); // old color stored there, for palette_cb to work
1157 // the cube intersection
1158 bt= uiDefButF(block, HSVCUBE, retval, "", 0,DPICK+BPICK,FPICK,FPICK, col, 0.0, 0.0, 2, 0, "");
1159 uiButSetFlag(bt, UI_NO_HILITE);
1161 bt= uiDefButF(block, HSVCUBE, retval, "", 0,0,FPICK,BPICK, col, 0.0, 0.0, 3, 0, "");
1162 uiButSetFlag(bt, UI_NO_HILITE);
1166 uiBlockSetEmboss(block, UI_EMBOSSP);
1168 bt=uiDefButF(block, COL, retval, "", FPICK+DPICK, 0, BPICK,BPICK, old, 0.0, 0.0, -1, 0, "Old color, click to restore");
1169 uiButSetFunc(bt, do_palette_cb, bt, col);
1170 uiDefButF(block, COL, retval, "", FPICK+DPICK, BPICK+DPICK, BPICK,60-BPICK-DPICK, col, 0.0, 0.0, -1, 0, "Active color");
1172 h= (DPICK+BPICK+FPICK-64)/(UI_PALETTE_TOT/2.0);
1173 uiBlockBeginAlign(block);
1174 for(a= -1+UI_PALETTE_TOT/2; a>=0; a--) {
1175 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");
1176 uiButSetFunc(bt, do_palette_cb, bt, col);
1177 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");
1178 uiButSetFunc(bt, do_palette_cb, bt, col);
1180 uiBlockEndAlign(block);
1182 uiBlockSetEmboss(block, UI_EMBOSS);
1185 rgb_to_hsv(col[0], col[1], col[2], hsv, hsv+1, hsv+2);
1186 sprintf(hexcol, "%02X%02X%02X", (unsigned int)(col[0]*255.0), (unsigned int)(col[1]*255.0), (unsigned int)(col[2]*255.0));
1188 offs= FPICK+2*DPICK+BPICK;
1190 /* note; made this a TOG now, with NULL pointer. Is because BUT now gets handled with a afterfunc */
1191 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)");
1192 uiButSetFunc(bt, do_palette_sample_cb, bt, col);
1193 uiButSetFlag(bt, UI_TEXT_LEFT);
1195 bt= uiDefBut(block, TEX, retval, "Hex: ", offs, 140, 140, 20, hexcol, 0, 8, 0, 0, "Hex triplet for color (#RRGGBB)");
1196 uiButSetFunc(bt, do_palette_hex_cb, bt, hexcol);
1198 uiBlockBeginAlign(block);
1199 bt= uiDefButF(block, NUMSLI, retval, "R ", offs, 110, 140,20, col, 0.0, 1.0, 10, 3, "");
1200 uiButSetFunc(bt, do_palette1_cb, bt, hsv);
1201 bt= uiDefButF(block, NUMSLI, retval, "G ", offs, 90, 140,20, col+1, 0.0, 1.0, 10, 3, "");
1202 uiButSetFunc(bt, do_palette1_cb, bt, hsv);
1203 bt= uiDefButF(block, NUMSLI, retval, "B ", offs, 70, 140,20, col+2, 0.0, 1.0, 10, 3, "");
1204 uiButSetFunc(bt, do_palette1_cb, bt, hsv);
1206 uiBlockBeginAlign(block);
1207 bt= uiDefButF(block, NUMSLI, retval, "H ", offs, 40, 140,20, hsv, 0.0, 1.0, 10, 3, "");
1208 uiButSetFunc(bt, do_palette2_cb, bt, col);
1209 bt= uiDefButF(block, NUMSLI, retval, "S ", offs, 20, 140,20, hsv+1, 0.0, 1.0, 10, 3, "");
1210 uiButSetFunc(bt, do_palette2_cb, bt, col);
1211 bt= uiDefButF(block, NUMSLI, retval, "V ", offs, 0, 140,20, hsv+2, 0.0, 1.0, 10, 3, "");
1212 uiButSetFunc(bt, do_palette2_cb, bt, col);
1213 uiBlockEndAlign(block);
1216 uiBlock *ui_block_func_COL(wmWindow *window, uiMenuBlockHandle *handle, void *arg_but)
1218 uiBut *but= arg_but;
1220 static float hsvcol[3], oldcol[3];
1221 static char hexcol[128];
1223 block= uiBeginBlock(window, handle->region, "colorpicker", UI_EMBOSS, UI_HELV);
1224 block->flag= UI_BLOCK_LOOP|UI_BLOCK_REDRAW|UI_BLOCK_KEEP_OPEN;
1225 block->themecol= TH_BUT_NUM;
1227 VECCOPY(handle->retvec, but->editvec);
1228 uiBlockPickerButtons(block, handle->retvec, hsvcol, oldcol, hexcol, 'p', 0);
1231 block->direction= UI_TOP;
1232 uiBoundsBlock(block, 3);
1237 /* ******************** PUPmenu ****************** */
1239 static int pupmenu_set= 0;
1241 void pupmenu_set_active(int val)
1246 /* value== -1 read, otherwise set */
1247 static int pupmenu_memory(char *str, int value)
1249 static char mem[256], first=1;
1253 memset(mem, 0, 256);
1261 if(value >= 0) mem[ val & 255 ]= value;
1262 else return mem[ val & 255 ];
1267 #define PUP_LABELH 6
1269 typedef struct uiPupMenuInfo {
1276 uiBlock *ui_block_func_PUPMENU(wmWindow *window, uiMenuBlockHandle *handle, void *arg_info)
1279 uiPupMenuInfo *info;
1280 int columns, rows, mousemove[2]= {0, 0}, mousewarp= 0;
1281 int width, height, xmax, ymax, maxrow;
1282 int a, startx, starty, endx, endy, x1, y1;
1287 maxrow= info->maxrow;
1290 /* block stuff first, need to know the font */
1291 block= uiBeginBlock(window, handle->region, "menu", UI_EMBOSSP, UI_HELV);
1292 uiBlockSetFlag(block, UI_BLOCK_LOOP|UI_BLOCK_REDRAW|UI_BLOCK_RET_1|UI_BLOCK_NUMSELECT);
1293 block->themecol= TH_MENU_ITEM;
1295 md= decompose_menu_string(info->instr);
1300 /* size and location, title slightly bigger for bold */
1302 width= 2*strlen(md->title)+UI_GetStringWidth(uiBlockGetCurFont(block), md->title, ui_translate_buttons());
1307 for(a=0; a<md->nitems; a++) {
1308 xmax= UI_GetStringWidth(uiBlockGetCurFont(block), md->items[a].str, ui_translate_buttons());
1309 if(xmax>width) width= xmax;
1311 if(strcmp(md->items[a].str, "%l")==0) height+= PUP_LABELH;
1312 else height+= MENU_BUTTON_HEIGHT;
1316 if (width<50) width=50;
1318 wm_window_get_size(window, &xmax, &ymax);
1320 /* set first item */
1323 lastselected= pupmenu_set-1;
1326 else if(md->nitems>1) {
1327 lastselected= pupmenu_memory(info->instr, -1);
1330 startx= info->mx-(0.8*(width));
1331 starty= info->my-height+MENU_BUTTON_HEIGHT/2;
1332 if(lastselected>=0 && lastselected<md->nitems) {
1333 for(a=0; a<md->nitems; a++) {
1334 if(a==lastselected) break;
1335 if( strcmp(md->items[a].str, "%l")==0) starty+= PUP_LABELH;
1336 else starty+=MENU_BUTTON_HEIGHT;
1339 //starty= info->my-height+MENU_BUTTON_HEIGHT/2+lastselected*MENU_BUTTON_HEIGHT;
1346 mousemove[1]= 10-starty;
1350 endx= startx+width*columns;
1351 endy= starty+height;
1355 startx= endx-width*columns;
1358 mousemove[1]= ymax-endy-20;
1360 starty= endy-height;
1363 if(mousemove[0] || mousemove[1]) {
1364 ui_warp_pointer(info->mx+mousemove[0], info->my+mousemove[1]);
1365 mousemove[0]= info->mx;
1366 mousemove[1]= info->my;
1374 uiSetCurFont(block, UI_HELVB);
1378 sprintf(titlestr, " %s", md->title);
1379 uiDefIconTextBut(block, LABEL, 0, md->titleicon, titlestr, startx, (short)(starty+height), width, MENU_BUTTON_HEIGHT, NULL, 0.0, 0.0, 0, 0, "");
1382 bt= uiDefBut(block, LABEL, 0, md->title, startx, (short)(starty+height), columns*width, MENU_BUTTON_HEIGHT, NULL, 0.0, 0.0, 0, 0, "");
1383 bt->flag= UI_TEXT_LEFT;
1385 uiSetCurFont(block, UI_HELV);
1388 x1= startx + width*((int)a/rows);
1389 y1= starty + height - MENU_BUTTON_HEIGHT;
1391 for(a=0; a<md->nitems; a++) {
1392 char *name= md->items[a].str;
1393 int icon = md->items[a].icon;
1395 if(strcmp(name, "%l")==0) {
1396 uiDefBut(block, SEPR, B_NOP, "", x1, y1, width, PUP_LABELH, NULL, 0, 0.0, 0, 0, "");
1400 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, "");
1401 y1 -= MENU_BUTTON_HEIGHT;
1404 uiDefButF(block, BUTM, B_NOP, name, x1, y1, width, MENU_BUTTON_HEIGHT-1, &handle->retvalue, (float) md->items[a].retval, 0.0, 0, 0, "");
1405 y1 -= MENU_BUTTON_HEIGHT;
1409 uiBoundsBlock(block, 1);
1414 /* XXX 2.5 need to store last selected */
1416 /* calculate last selected */
1417 if(event & ui_return_ok) {
1419 for(a=0; a<md->nitems; a++) {
1420 if(val==md->items[a].retval) lastselected= a;
1423 pupmenu_memory(info->instr, lastselected);
1427 /* XXX 2.5 need to warp back */
1429 if(mousemove[1] && (event & ui_return_out)==0)
1430 ui_warp_pointer(mousemove[0], mousemove[1]);
1437 uiBlock *ui_block_func_PUPMENUCOL(wmWindow *window, uiMenuBlockHandle *handle, void *arg_info)
1440 uiPupMenuInfo *info;
1441 int columns, rows, mousemove[2]= {0, 0}, mousewarp;
1442 int width, height, xmax, ymax, maxrow;
1443 int a, startx, starty, endx, endy, x1, y1;
1448 maxrow= info->maxrow;
1451 /* block stuff first, need to know the font */
1452 block= uiBeginBlock(window, handle->region, "menu", UI_EMBOSSP, UI_HELV);
1453 uiBlockSetFlag(block, UI_BLOCK_LOOP|UI_BLOCK_REDRAW|UI_BLOCK_RET_1|UI_BLOCK_NUMSELECT);
1454 block->themecol= TH_MENU_ITEM;
1456 md= decompose_menu_string(info->instr);
1458 /* columns and row calculation */
1459 columns= (md->nitems+maxrow)/maxrow;
1460 if (columns<1) columns= 1;
1464 columns= (md->nitems+maxrow)/maxrow;
1467 rows= (int) md->nitems/columns;
1468 if (rows<1) rows= 1;
1470 while (rows*columns<(md->nitems+columns) ) rows++;
1472 /* size and location, title slightly bigger for bold */
1474 width= 2*strlen(md->title)+UI_GetStringWidth(uiBlockGetCurFont(block), md->title, ui_translate_buttons());
1479 for(a=0; a<md->nitems; a++) {
1480 xmax= UI_GetStringWidth(uiBlockGetCurFont(block), md->items[a].str, ui_translate_buttons());
1481 if(xmax>width) width= xmax;
1485 if (width<50) width=50;
1487 height= rows*MENU_BUTTON_HEIGHT;
1488 if (md->title) height+= MENU_BUTTON_HEIGHT;
1490 wm_window_get_size(window, &xmax, &ymax);
1492 /* find active item */
1493 fvalue= handle->retvalue;
1494 for(a=0; a<md->nitems; a++) {
1495 if( md->items[a].retval== (int)fvalue ) break;
1498 /* no active item? */
1500 if(md->title) a= -1;
1505 startx = info->mx-width/2 - ((int)(a)/rows)*width;
1507 startx= info->mx-width/2;
1508 starty = info->my-height + MENU_BUTTON_HEIGHT/2 + ((a)%rows)*MENU_BUTTON_HEIGHT;
1510 if (md->title) starty+= MENU_BUTTON_HEIGHT;
1513 mousemove[0]= 10-startx;
1517 mousemove[1]= 10-starty;
1521 endx= startx+width*columns;
1522 endy= starty+height;
1525 mousemove[0]= xmax-endx-10;
1527 startx= endx-width*columns;
1530 mousemove[1]= ymax-endy-10;
1532 starty= endy-height;
1535 if(mousemove[0] || mousemove[1]) {
1536 ui_warp_pointer(info->mx+mousemove[0], info->my+mousemove[1]);
1537 mousemove[0]= info->mx;
1538 mousemove[1]= info->my;
1545 uiSetCurFont(block, UI_HELVB);
1550 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, "");
1551 bt->flag= UI_TEXT_LEFT;
1553 uiSetCurFont(block, UI_HELV);
1556 for(a=0; a<md->nitems; a++) {
1557 char *name= md->items[a].str;
1558 int icon = md->items[a].icon;
1560 x1= startx + width*((int)a/rows);
1561 y1= starty - MENU_BUTTON_HEIGHT*(a%rows) + (rows-1)*MENU_BUTTON_HEIGHT;
1563 if(strcmp(name, "%l")==0) {
1564 uiDefBut(block, SEPR, B_NOP, "", x1, y1, width, PUP_LABELH, NULL, 0, 0.0, 0, 0, "");
1568 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, "");
1569 y1 -= MENU_BUTTON_HEIGHT;
1572 uiDefButF(block, BUTM, B_NOP, name, x1, y1, width, MENU_BUTTON_HEIGHT-1, &handle->retvalue, (float) md->items[a].retval, 0.0, 0, 0, "");
1573 y1 -= MENU_BUTTON_HEIGHT;
1577 uiBoundsBlock(block, 1);
1581 event= uiDoBlocks(&listb, 0, 1);
1586 /* XXX 2.5 need to warp back */
1588 if((event & UI_RETURN_OUT)==0)
1589 ui_warp_pointer(mousemove[0], mousemove[1]);
1595 uiMenuBlockHandle *pupmenu_col(bContext *C, char *instr, int mx, int my, int maxrow)
1599 memset(&info, 0, sizeof(info));
1603 info.maxrow= maxrow;
1605 return ui_menu_block_create(C, NULL, NULL, ui_block_func_PUPMENUCOL, &info);
1608 uiMenuBlockHandle *pupmenu(bContext *C, char *instr, int mx, int my)
1612 memset(&info, 0, sizeof(info));
1617 return ui_menu_block_create(C, NULL, NULL, ui_block_func_PUPMENU, &info);
1621 void pupmenu_free(bContext *C, uiMenuBlockHandle *handle)
1623 ui_menu_block_free(C, handle);
1626 /*************** Temporary Buttons Tests **********************/
1628 static uiBlock *test_submenu(wmWindow *window, uiMenuBlockHandle *handle, void *arg)
1630 ARegion *ar= handle->region;
1632 short yco= 0, menuwidth=120;
1634 block= uiBeginBlock(window, ar, "test_viewmenu", UI_EMBOSSP, UI_HELV);
1635 //uiBlockSetButmFunc(block, do_test_viewmenu, NULL);
1637 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Play Back Animation", 0, yco-=20,
1638 menuwidth, 19, NULL, 0.0, 0.0, 1, 2, "");
1640 uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
1642 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Show Seconds|T", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 5, "");
1644 uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_HLT,
1645 "Only Selected Data Keys|", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 12, "");
1647 uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
1649 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Jump To Next Marker|PageUp", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 6, "");
1650 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Jump To Prev Marker|PageDown", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 7, "");
1651 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Jump To Next Key|Ctrl PageUp", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 8, "");
1652 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Jump To Prev Key|Ctrl PageDown", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 9, "");
1654 uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
1656 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Center View|C", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 10, "");
1657 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "View All|Home", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 3, "");
1658 uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_HLT,
1659 "Lock Time to Other Windows|", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 11, "");
1661 uiBlockSetDirection(block, UI_RIGHT);
1663 uiTextBoundsBlock(block, 50);
1669 static uiBlock *test_viewmenu(wmWindow *window, uiMenuBlockHandle *handle, void *arg_area)
1671 ScrArea *area= arg_area;
1672 ARegion *ar= handle->region;
1674 short yco= 0, menuwidth=120;
1676 block= uiBeginBlock(window, ar, "test_viewmenu", UI_EMBOSSP, UI_HELV);
1677 //uiBlockSetButmFunc(block, do_test_viewmenu, NULL);
1679 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Play Back Animation", 0, yco-=20,
1680 menuwidth, 19, NULL, 0.0, 0.0, 1, 2, "");
1682 uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
1684 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Show Seconds|T", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 5, "");
1686 uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_HLT,
1687 "Only Selected Data Keys|", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 12, "");
1689 uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
1691 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Jump To Next Marker|PageUp", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 6, "");
1692 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Jump To Prev Marker|PageDown", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 7, "");
1693 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Jump To Next Key|Ctrl PageUp", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 8, "");
1694 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Jump To Prev Key|Ctrl PageDown", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 9, "");
1696 uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
1698 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Center View|C", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 10, "");
1699 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "View All|Home", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 3, "");
1700 uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_HLT,
1701 "Lock Time to Other Windows|", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 11, "");
1703 uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
1704 uiDefIconTextBlockBut(block, test_submenu, NULL, ICON_RIGHTARROW_THIN, "Sub Menu", 0, yco-=20, 120, 19, "");
1705 uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
1707 if(area->headertype==HEADERTOP) {
1708 uiBlockSetDirection(block, UI_DOWN);
1711 uiBlockSetDirection(block, UI_TOP);
1712 uiBlockFlipOrder(block);
1715 uiTextBoundsBlock(block, 50);
1721 void uiTestRegion(const bContext *C)
1724 static float testcol[3];
1725 static char testtext[64];
1726 static float testnumf=5.0f;
1727 static short testchoice= 0, testtog= 0;
1729 static CurveMapping *cumap= NULL;
1730 static ColorBand *coba= NULL;
1733 block= uiBeginBlock(C->window, C->region, "header buttons", UI_EMBOSS, UI_HELV);
1735 uiDefPulldownBut(block, test_viewmenu, C->area, "View",
1738 uiDefBut(block, BUT, 31415, "Type BUT",
1739 13+50+5, 3, 80, 20, NULL, 0, 0, 0, 0, "A tooltip.");
1740 uiDefButS(block, MENU, 31416, "Gather Method%t|Raytrace %x0|Approximate %x1",
1741 13+50+5+80+5, 3, 100, 20, &testchoice, 0, 0, 0, 0, "Method for occlusion gathering");
1742 uiDefButBitS(block, TOG, 1, 31417, "Pixel Cache",
1743 13+50+5+80+5+100+5, 3, 80, 20, &testtog, 0, 0, 0, 0, "Cache AO results in pixels and interpolate over neighbouring pixels for speedup.");
1745 uiDefBut(block, TEX, 31418, "Text: ",
1746 13+50+5+80+5+100+5+80+5, 3, 200, 20, testtext, 0, sizeof(testtext), 0, 0, "User defined text");
1748 uiDefButF(block, NUMSLI, 31419, "Slider: ",
1749 13+50+5+80+5+100+5+80+5+200+5, 3, 150, 20, &testnumf, 0.0, 10.0, 0, 0, "Some tooltip.");
1750 uiDefButF(block, NUM, 31419, "N: ",
1751 13+50+5+80+5+100+5+80+5+200+5+150+5, 3, 100, 20, &testnumf, 0.0, 10.0, 0, 0, "Some tooltip.");
1753 uiDefButF(block, COL, 3142, "",
1754 13+50+5+80+5+100+5+80+5+200+5+150+5+100+5, 3, 100, 20, testcol, 0, 0, 0, 0 /*B_BANDCOL*/, "");
1758 cumap= curvemapping_add(4, 0.0f, 0.0f, 1.0f, 1.0f);
1759 cumap->flag &= ~CUMA_DO_CLIP;
1762 coba= add_colorband(0);
1764 uiDefBut(block, BUT_CURVE, 3143, "",
1765 13+400, 33, 100, 100, cumap, 0.0f, 1.0f, 0, 0, "");
1766 uiDefBut(block, BUT_COLORBAND, 3143, "",
1767 13+400+100+10, 33, 150, 30, coba, 0.0f, 1.0f, 0, 0, "");