5bbc5923c7d0a72fa3fdf23b33259ccc0c079736
[blender.git] / source / blender / editors / interface / interface_regions.c
1
2 #include <stdlib.h>
3 #include <string.h>
4
5 #include "MEM_guardedalloc.h"
6
7 #include "DNA_screen_types.h"
8 #include "DNA_windowmanager_types.h"
9
10 #include "BLI_arithb.h"
11 #include "BLI_blenlib.h"
12
13 #include "BKE_global.h"
14 #include "BKE_screen.h"
15 #include "BKE_utildefines.h"
16
17 #include "WM_api.h"
18 #include "WM_types.h"
19 #include "wm_subwindow.h"
20 #include "wm_window.h"
21
22 #include "BIF_gl.h"
23
24 #include "UI_text.h"
25 #include "UI_interface.h"
26
27 #include "ED_screen.h"
28
29 #include "interface.h"
30
31 #define MENU_BUTTON_HEIGHT      20
32 #define B_NOP                   -1
33 #define MENU_SHADOW_LEFT        -1
34 #define MENU_SHADOW_BOTTOM      -10
35 #define MENU_SHADOW_RIGHT       10
36 #define MENU_SHADOW_TOP         1
37
38 /*********************** Menu Data Parsing ********************* */
39
40 typedef struct {
41         char *str;
42         int retval;
43         int icon;
44 } MenuEntry;
45
46 typedef struct {
47         char *instr;
48         char *title;
49         int titleicon;
50         
51         MenuEntry *items;
52         int nitems, itemssize;
53 } MenuData;
54
55 static MenuData *menudata_new(char *instr)
56 {
57         MenuData *md= MEM_mallocN(sizeof(*md), "MenuData");
58
59         md->instr= instr;
60         md->title= NULL;
61         md->titleicon= 0;
62         md->items= NULL;
63         md->nitems= md->itemssize= 0;
64         
65         return md;
66 }
67
68 static void menudata_set_title(MenuData *md, char *title, int titleicon)
69 {
70         if (!md->title)
71                 md->title= title;
72         if (!md->titleicon)
73                 md->titleicon= titleicon;
74 }
75
76 static void menudata_add_item(MenuData *md, char *str, int retval, int icon)
77 {
78         if (md->nitems==md->itemssize) {
79                 int nsize= md->itemssize?(md->itemssize<<1):1;
80                 MenuEntry *oitems= md->items;
81                 
82                 md->items= MEM_mallocN(nsize*sizeof(*md->items), "md->items");
83                 if (oitems) {
84                         memcpy(md->items, oitems, md->nitems*sizeof(*md->items));
85                         MEM_freeN(oitems);
86                 }
87                 
88                 md->itemssize= nsize;
89         }
90         
91         md->items[md->nitems].str= str;
92         md->items[md->nitems].retval= retval;
93         md->items[md->nitems].icon= icon;
94         md->nitems++;
95 }
96
97 void menudata_free(MenuData *md)
98 {
99         MEM_freeN(md->instr);
100         if (md->items)
101                 MEM_freeN(md->items);
102         MEM_freeN(md);
103 }
104
105         /**
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.
113          * 
114          * @param str String to be parsed.
115          * @retval new menudata structure, free with menudata_free()
116          */
117 MenuData *decompose_menu_string(char *str) 
118 {
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;
123         
124         while (1) {
125                 char c= *s;
126
127                 if (c=='%') {
128                         if (s[1]=='x') {
129                                 nretval= atoi(s+2);
130
131                                 *s= '\0';
132                                 s++;
133                         } else if (s[1]=='t') {
134                                 nitem_is_title= 1;
135
136                                 *s= '\0';
137                                 s++;
138                         } else if (s[1]=='l') {
139                                 nitem= "%l";
140                                 s++;
141                         } else if (s[1]=='i') {
142                                 nicon= atoi(s+2);
143                                 
144                                 *s= '\0';
145                                 s++;
146                         }
147                 } else if (c=='|' || c=='\0') {
148                         if (nitem) {
149                                 *s= '\0';
150
151                                 if (nitem_is_title) {
152                                         menudata_set_title(md, nitem, nicon);
153                                         nitem_is_title= 0;
154                                 } else {
155                                         /* prevent separator to get a value */
156                                         if(nitem[0]=='%' && nitem[1]=='l')
157                                                 menudata_add_item(md, nitem, -1, nicon);
158                                         else
159                                                 menudata_add_item(md, nitem, nretval, nicon);
160                                         nretval= md->nitems+1;
161                                 } 
162                                 
163                                 nitem= NULL;
164                                 nicon= 0;
165                         }
166                         
167                         if (c=='\0')
168                                 break;
169                 } else if (!nitem)
170                         nitem= s;
171                 
172                 s++;
173         }
174         
175         return md;
176 }
177
178 void ui_set_name_menu(uiBut *but, int value)
179 {
180         MenuData *md;
181         int i;
182         
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);
187         
188         menudata_free(md);
189 }
190
191 /******************** Creating Temporary regions ******************/
192
193 ARegion *ui_add_temporary_region(bScreen *sc)
194 {
195         ARegion *ar;
196
197         ar= MEM_callocN(sizeof(ARegion), "area region");
198         BLI_addtail(&sc->regionbase, ar);
199
200         ar->regiontype= RGN_TYPE_TEMPORARY;
201         ar->alignment= RGN_ALIGN_FLOAT;
202
203         return ar;
204 }
205
206 void ui_remove_temporary_region(bContext *C, bScreen *sc, ARegion *ar)
207 {
208         ED_region_exit(C, ar);
209         BKE_area_region_free(ar);
210         BLI_freelinkN(&sc->regionbase, ar);
211 }
212
213 /************************* Creating Tooltips **********************/
214
215 typedef struct uiTooltipData {
216         rctf bbox;
217         struct BMF_Font *font;
218         char *tip;
219         float aspect;
220 } uiTooltipData;
221
222 static void ui_tooltip_region_draw(const bContext *C, ARegion *ar)
223 {
224         uiTooltipData *data;
225         int x1, y1, x2, y2;
226
227         data= ar->regiondata;
228
229         x1= ar->winrct.xmin;
230         y1= ar->winrct.ymin;
231         x2= ar->winrct.xmax;
232         y2= ar->winrct.ymax;
233
234         /* draw drop shadow */
235         glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
236         glEnable(GL_BLEND);
237
238         glColor4ub(0, 0, 0, 20);
239         
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);
242         
243         glColor4ub(0, 0, 0, 8);
244         
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);
247
248         glDisable(GL_BLEND);
249         
250         /* draw background */
251         glColor3f(1.0f, 1.0f, 0.8666f);
252         glRectf(0, 4, x2-x1-4, y2-y1);
253         
254         /* draw text */
255         glColor3ub(0,0,0);
256
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);
262         UI_SetScale(1.0);
263
264         UI_DrawString(data->font, data->tip, ui_translate_tooltips());
265 }
266
267 static void ui_tooltip_region_free(ARegion *ar)
268 {
269         uiTooltipData *data;
270
271         data= ar->regiondata;
272         MEM_freeN(data->tip);
273         MEM_freeN(data);
274 }
275
276 ARegion *ui_tooltip_create(bContext *C, ARegion *butregion, uiBut *but)
277 {
278         static ARegionType type={NULL, NULL, NULL, NULL, NULL};
279         ARegion *ar;
280         uiTooltipData *data;
281         int x1, x2, y1, y2, winx, winy;
282
283         if(!but->tip || strlen(but->tip)==0)
284                 return NULL;
285
286         /* create area region */
287         ar= ui_add_temporary_region(C->window->screen);
288
289         type.draw= ui_tooltip_region_draw;
290         type.free= ui_tooltip_region_free;
291         ar->type= &type;
292
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);
299
300         ar->regiondata= data;
301
302         /* compute position */
303         x1= (but->x1+but->x2)/2;
304         x2= x1+but->aspect*((data->bbox.xmax-data->bbox.xmin) + 8);
305         y2= but->y1-10;
306         y1= y2-but->aspect*((data->bbox.ymax+(data->bbox.ymax-data->bbox.ymin)));
307
308         y2 += 4;
309         x2 += 4;
310
311         if(butregion) {
312                 x1 += butregion->winrct.xmin;
313                 x2 += butregion->winrct.xmin;
314                 y1 += butregion->winrct.ymin;
315                 y2 += butregion->winrct.ymin;
316         }
317
318         wm_window_get_size(C->window, &winx, &winy);
319
320         if(x2 > winx) {
321                 x1 -= x2-winx;
322                 x2= winx;
323         }
324         if(y1 < 0) {
325                 y1 += 36;
326                 y2 += 36;
327         }
328
329         ar->winrct.xmin= x1;
330         ar->winrct.ymin= y1;
331         ar->winrct.xmax= x2;
332         ar->winrct.ymax= y2;
333
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);
337
338         return ar;
339 }
340
341 void ui_tooltip_free(bContext *C, ARegion *ar)
342 {
343         ui_remove_temporary_region(C, C->window->screen, ar);
344
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);
347 }
348
349 /************************* Creating Menu Blocks **********************/
350
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)
353 {
354         uiBut *bt;
355         uiSafetyRct *saferct;
356         rctf butrct;
357         float aspect;
358         int xsize, ysize, xof=0, yof=0, center;
359         short dir1= 0, dir2=0;
360         
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;
364
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);
367
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;
373                         
374                         bt= block->buttons.first;
375                         while(bt) {
376                                 if(bt->x1 < block->minx) block->minx= bt->x1;
377                                 if(bt->y1 < block->miny) block->miny= bt->y1;
378
379                                 if(bt->x2 > block->maxx) block->maxx= bt->x2;
380                                 if(bt->y2 > block->maxy) block->maxy= bt->y2;
381                                 
382                                 bt= bt->next;
383                         }
384                 }
385                 else {
386                         /* we're nice and allow empty blocks too */
387                         block->minx= block->miny= 0;
388                         block->maxx= block->maxy= 20;
389                 }
390         }
391         
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);
395
396         //block->minx-= 2.0; block->miny-= 2.0;
397         //block->maxx+= 2.0; block->maxy+= 2.0;
398         
399         xsize= block->maxx - block->minx+4; // 4 for shadow
400         ysize= block->maxy - block->miny+4;
401         aspect/= (float)xsize;
402
403         if(but) {
404                 int left=0, right=0, top=0, down=0;
405                 int winx, winy;
406
407                 wm_window_get_size(window, &winx, &winy);
408
409                 if(block->direction & UI_CENTER) center= ysize/2;
410                 else center= 0;
411
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;
416                 
417                 dir1= block->direction & UI_DIRECTION;
418
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);
424                 }
425
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;
428                 
429                 /* no space at all? dont change */
430                 if(left || right) {
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;
436                 }
437                 if(down || top) {
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;
442                 }
443                 
444                 if(dir1==UI_LEFT) {
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;
448                 }
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;
453                 }
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);
463                         }
464                 }
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);
474                         }
475                 }
476
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 
481                                 yof= ysize;
482                         }
483                 }
484                 
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 
489                                 xof= -block->minx+5;
490                         }
491                 }
492                 
493                 // apply requested offset in the block
494                 xof += block->xofs/block->aspect;
495                 yof += block->yofs/block->aspect;
496         }
497         
498         /* apply */
499         
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);
503
504                 bt->x1 += xof;
505                 bt->x2 += xof;
506                 bt->y1 += yof;
507                 bt->y2 += yof;
508
509                 bt->aspect= 1.0;
510                 // ui_check_but recalculates drawstring size in pixels
511                 ui_check_but(bt);
512         }
513         
514         block->minx += xof;
515         block->miny += yof;
516         block->maxx += xof;
517         block->maxy += yof;
518
519         /* safety calculus */
520         if(but) {
521                 float midx= (butrct.xmin+butrct.xmax)/2.0;
522                 float midy= (butrct.ymin+butrct.ymax)/2.0;
523                 
524                 /* when you are outside parent button, safety there should be smaller */
525                 
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;
532                 
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;
539                 
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; 
544                 }
545                 block->direction= dir1;
546         }
547         else {
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;
552         }
553
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);
559         if(but)
560                 BLI_duplicatelist(&block->saferct, &but->block->saferct);
561         BLI_addhead(&block->saferct, saferct);
562 }
563
564 static void ui_block_region_draw(const bContext *C, ARegion *ar)
565 {
566         uiBlock *block;
567
568         for(block=ar->uiblocks.first; block; block=block->next) {
569                 wm_subwindow_getmatrix(C->window, ar->swinid, block->winmat);
570                 uiDrawBlock(block);
571         }
572 }
573
574 static void ui_block_region_free(ARegion *ar)
575 {
576         uiFreeBlocks(&ar->uiblocks);
577 }
578
579 uiMenuBlockHandle *ui_menu_block_create(bContext *C, ARegion *butregion, uiBut *but, uiBlockFuncFP block_func, void *arg)
580 {
581         static ARegionType type={NULL, NULL, NULL, NULL, NULL};
582         ARegion *ar;
583         uiBlock *block;
584         uiBut *bt;
585         uiMenuBlockHandle *handle;
586         uiSafetyRct *saferct;
587
588         /* create handle */
589         handle= MEM_callocN(sizeof(uiMenuBlockHandle), "uiMenuBlockHandle");
590
591         /* create area region */
592         ar= ui_add_temporary_region(C->window->screen);
593
594         type.draw= ui_block_region_draw;
595         type.free= ui_block_region_free;
596         ar->type= &type;
597
598         WM_event_add_keymap_handler(&ar->handlers, &C->wm->uikeymap);
599
600         handle->region= ar;
601         ar->regiondata= handle;
602
603         /* create ui block */
604         block= block_func(C->window, handle, arg);
605         block->handle= handle;
606
607         /* if this is being created from a button */
608         if(but) {
609                 if(ELEM(but->type, BLOCK, PULLDOWN))
610                         block->xofs = -2;       /* for proper alignment */
611
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);
616                 }
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;
620
621                 ui_block_position(C->window, butregion, but, block);
622         }
623         else {
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);
628         }
629
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;
637
638         block->minx -= ar->winrct.xmin;
639         block->maxx -= ar->winrct.xmin;
640         block->miny -= ar->winrct.ymin;
641         block->maxy -= ar->winrct.ymin;
642
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;
648         }
649
650         block->flag |= UI_BLOCK_LOOP|UI_BLOCK_MOVEMOUSE_QUIT;
651
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);
655
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);
659
660         return handle;
661 }
662
663 void ui_menu_block_free(bContext *C, uiMenuBlockHandle *handle)
664 {
665         ui_remove_temporary_region(C, C->window->screen, handle->region);
666         MEM_freeN(handle);
667
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);
670 }
671
672 /***************************** Menu Button ***************************/
673
674 uiBlock *ui_block_func_MENU(wmWindow *window, uiMenuBlockHandle *handle, void *arg_but)
675 {
676         uiBut *but= arg_but;
677         uiBlock *block;
678         uiBut *bt;
679         MenuData *md;
680         ListBase lb;
681         float aspect;
682         int width, height, boxh, columns, rows, startx, starty, x1, y1, xmax, a;
683
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;
689
690         /* compute menu data */
691         md= decompose_menu_string(but->str);
692
693         /* columns and row calculation */
694         columns= (md->nitems+20)/20;
695         if(columns<1)
696                 columns= 1;
697         if(columns>8)
698                 columns= (md->nitems+25)/25;
699         
700         rows= md->nitems/columns;
701         if(rows<1)
702                 rows= 1;
703         while(rows*columns<md->nitems)
704                 rows++;
705                 
706         /* prevent scaling up of pupmenu */
707         aspect= but->aspect;
708         if(aspect < 1.0f)
709                 aspect = 1.0f;
710
711         /* size and location */
712         if(md->title)
713                 width= 1.5*aspect*strlen(md->title)+UI_GetStringWidth(block->curfont, md->title, ui_translate_menus());
714         else
715                 width= 0;
716
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)
720                         xmax += 20*aspect;
721                 if(xmax>width)
722                         width= xmax;
723         }
724
725         width+= 10;
726         if(width < (but->x2 - but->x1))
727                 width = (but->x2 - but->x1);
728         if(width<50)
729                 width=50;
730
731         boxh= MENU_BUTTON_HEIGHT;
732         
733         height= rows*boxh;
734         if(md->title)
735                 height+= boxh;
736
737         /* here we go! */
738         startx= but->x1;
739         starty= but->y1;
740         
741         if(md->title) {
742                 uiBut *bt;
743                 uiSetCurFont(block, block->font+1);
744                 if (md->titleicon) {
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, "");
746                 } else {
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;
749                 }
750                 uiSetCurFont(block, block->font);
751         }
752
753         for(a=0; a<md->nitems; a++) {
754                 
755                 x1= startx + width*((int)(md->nitems-a-1)/rows);
756                 y1= starty - boxh*(rows - ((md->nitems - a - 1)%rows)) + (rows*boxh);
757
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, "");
760                 }
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, "");
763                 }
764                 else {
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, "");
766                 }
767         }
768         
769         menudata_free(md);
770
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 */
773         
774         lb.first= lb.last= NULL;
775         bt= block->buttons.first;
776         while(bt) {
777                 uiBut *next= bt->next;
778                 BLI_remlink(&block->buttons, bt);
779                 BLI_addhead(&lb, bt);
780                 bt= next;
781         }
782         block->buttons= lb;
783
784         block->direction= UI_TOP;
785         uiEndBlock(block);
786
787         return block;
788 }
789
790 uiBlock *ui_block_func_ICONROW(wmWindow *window, uiMenuBlockHandle *handle, void *arg_but)
791 {
792         uiBut *but= arg_but;
793         uiBlock *block;
794         int a;
795         
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;
799         
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, "");
802         }
803
804         block->direction= UI_TOP;       
805
806         uiEndBlock(block);
807
808         return block;
809 }
810
811 uiBlock *ui_block_func_ICONTEXTROW(wmWindow *window, uiMenuBlockHandle *handle, void *arg_but)
812 {
813         uiBut *but= arg_but;
814         uiBlock *block;
815         MenuData *md;
816         int width, xmax, ypos, a;
817
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;
821
822         md= decompose_menu_string(but->str);
823
824         /* size and location */
825         /* expand menu width to fit labels */
826         if(md->title)
827                 width= 2*strlen(md->title)+UI_GetStringWidth(block->curfont, md->title, ui_translate_menus());
828         else
829                 width= 0;
830
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;
834         }
835
836         width+= 30;
837         if (width<50) width=50;
838
839         ypos = 1;
840
841         /* loop through the menu options and draw them out with icons & text labels */
842         for(a=0; a<md->nitems; a++) {
843
844                 /* add a space if there's a separator (%l) */
845                 if (strcmp(md->items[a].str, "%l")==0) {
846                         ypos +=3;
847                 }
848                 else {
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, "");
850                         ypos += 20;
851                 }
852         }
853         
854         if(md->title) {
855                 uiBut *bt;
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;
860         }
861         
862         menudata_free(md);
863
864         block->direction= UI_TOP;
865
866         uiBoundsBlock(block, 3);
867         uiEndBlock(block);
868
869         return block;
870 }
871
872 static void ui_warp_pointer(short x, short y)
873 {
874         /* XXX 2.50 which function to use for this? */
875 #if 0
876         /* OSX has very poor mousewarp support, it sends events;
877            this causes a menu being pressed immediately ... */
878         #ifndef __APPLE__
879         warp_pointer(x, y);
880         #endif
881 #endif
882 }
883
884 /********************* Color Button ****************/
885
886 /* picker sizes S hsize, F full size, D spacer, B button/pallette height  */
887 #define SPICK   110.0
888 #define FPICK   180.0
889 #define DPICK   6.0
890 #define BPICK   24.0
891
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}
899 };  
900
901 /* for picker, while editing hsv */
902 void ui_set_but_hsv(uiBut *but)
903 {
904         float col[3];
905         
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);
908 }
909
910 static void update_picker_hex(uiBlock *block, float *rgb)
911 {
912         uiBut *bt;
913         char col[16];
914         
915         sprintf(col, "%02X%02X%02X", (unsigned int)(rgb[0]*255.0), (unsigned int)(rgb[1]*255.0), (unsigned int)(rgb[2]*255.0));
916         
917         // this updates button strings, is hackish... but button pointers are on stack of caller function
918
919         for(bt= block->buttons.first; bt; bt= bt->next) {
920                 if(strcmp(bt->str, "Hex: ")==0) {
921                         strcpy(bt->poin, col);
922                         ui_check_but(bt);
923                         break;
924                 }
925         }
926 }
927
928 void ui_update_block_buts_hsv(uiBlock *block, float *hsv)
929 {
930         uiBut *bt;
931         float r, g, b;
932         float rgb[3];
933         
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);
936         
937         rgb[0] = r; rgb[1] = g; rgb[2] = b;
938         update_picker_hex(block, rgb);
939
940         for(bt= block->buttons.first; bt; bt= bt->next) {
941                 if(bt->type==HSVCUBE) {
942                         VECCOPY(bt->hsv, hsv);
943                         ui_set_but_hsv(bt);
944                 }
945                 else if(bt->str[1]==' ') {
946                         if(bt->str[0]=='R') {
947                                 ui_set_but_val(bt, r);
948                         }
949                         else if(bt->str[0]=='G') {
950                                 ui_set_but_val(bt, g);
951                         }
952                         else if(bt->str[0]=='B') {
953                                 ui_set_but_val(bt, b);
954                         }
955                         else if(bt->str[0]=='H') {
956                                 ui_set_but_val(bt, hsv[0]);
957                         }
958                         else if(bt->str[0]=='S') {
959                                 ui_set_but_val(bt, hsv[1]);
960                         }
961                         else if(bt->str[0]=='V') {
962                                 ui_set_but_val(bt, hsv[2]);
963                         }
964                 }               
965         }
966 }
967
968 static void ui_update_block_buts_hex(uiBlock *block, char *hexcol)
969 {
970         uiBut *bt;
971         float r=0, g=0, b=0;
972         float h, s, v;
973         
974         
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);
978
979         for(bt= block->buttons.first; bt; bt= bt->next) {
980                 if(bt->type==HSVCUBE) {
981                         bt->hsv[0] = h;
982                         bt->hsv[1] = s;                 
983                         bt->hsv[2] = v;
984                         ui_set_but_hsv(bt);
985                 }
986                 else if(bt->str[1]==' ') {
987                         if(bt->str[0]=='R') {
988                                 ui_set_but_val(bt, r);
989                         }
990                         else if(bt->str[0]=='G') {
991                                 ui_set_but_val(bt, g);
992                         }
993                         else if(bt->str[0]=='B') {
994                                 ui_set_but_val(bt, b);
995                         }
996                         else if(bt->str[0]=='H') {
997                                 ui_set_but_val(bt, h);
998                         }
999                         else if(bt->str[0]=='S') {
1000                                 ui_set_but_val(bt, s);
1001                         }
1002                         else if(bt->str[0]=='V') {
1003                                 ui_set_but_val(bt, v);
1004                         }
1005                 }
1006         }
1007 }
1008
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)
1012 {
1013         uiBut *but1= (uiBut *)bt1;
1014         float *col= (float *)col1;
1015         float *fp, hsv[3];
1016         
1017         fp= (float *)but1->poin;
1018         
1019         /* XXX 2.50 bad access, how to solve?
1020          *
1021         if( (get_qual() & LR_CTRLKEY) ) {
1022                 VECCOPY(fp, col);
1023         }
1024         else*/ {
1025                 VECCOPY(col, fp);
1026         }
1027         
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);
1031 }
1032
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)
1036 {
1037         uiBut *but1= (uiBut *)bt1;
1038         float *hsv= (float *)hsv1;
1039         float *fp= NULL;
1040         
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;
1045         }
1046         if(fp) {
1047                 rgb_to_hsv(fp[0], fp[1], fp[2], hsv, hsv+1, hsv+2);
1048         } 
1049         ui_update_block_buts_hsv(but1->block, hsv);
1050 }
1051
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)
1055 {
1056         uiBut *but1= (uiBut *)bt1;
1057         float *rgb= (float *)col1;
1058         float *fp= NULL;
1059         
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;
1064         }
1065         if(fp) {
1066                 hsv_to_rgb(fp[0], fp[1], fp[2], rgb, rgb+1, rgb+2);
1067         } 
1068         ui_update_block_buts_hsv(but1->block, fp);
1069 }
1070
1071 static void do_palette_hex_cb(void *bt1, void *hexcl)
1072 {
1073         uiBut *but1= (uiBut *)bt1;
1074         char *hexcol= (char *)hexcl;
1075         
1076         ui_update_block_buts_hex(but1->block, hexcol);  
1077 }
1078
1079 /* used for both 3d view and image window */
1080 static void do_palette_sample_cb(void *bt1, void *col1) /* frontbuf */
1081 {
1082         /* XXX 2.50 this should become an operator? */
1083 #if 0
1084         uiBut *but1= (uiBut *)bt1;
1085         uiBut *but;
1086         float tempcol[4];
1087         int x=0, y=0;
1088         short mval[2];
1089         float hsv[3];
1090         short capturing;
1091         int oldcursor;
1092         Window *win;
1093         unsigned short dev;
1094         
1095         oldcursor=get_cursor();
1096         win=winlay_get_active_window();
1097         
1098         while (get_mbut() & L_MOUSE) UI_wait_for_statechange();
1099         
1100         SetBlenderCursor(BC_EYEDROPPER_CURSOR);
1101         
1102         /* loop and wait for a mouse click */
1103         capturing = TRUE;
1104         while(capturing) {
1105                 char ascii;
1106                 short val;
1107                 
1108                 dev = extern_qread_ext(&val, &ascii);
1109                 
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];
1115                         
1116                         capturing = FALSE;
1117                         break;
1118                 }
1119                 else if(dev==ESCKEY) break;
1120         }
1121         window_set_cursor(win, oldcursor);
1122         
1123         if(capturing) return;
1124         
1125         if(x<0 || y<0) return;
1126         
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);
1131         
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);
1136         
1137         for (but= but1->block->buttons.first; but; but= but->next) {
1138                 ui_check_but(but);
1139                 ui_draw_but(but);
1140         }
1141         
1142         but= but1->block->buttons.first;
1143         ui_block_flush_back(but->block);
1144 #endif
1145 }
1146
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)
1150 {
1151         uiBut *bt;
1152         float h, offs;
1153         int a;
1154
1155         VECCOPY(old, col);      // old color stored there, for palette_cb to work
1156         
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);
1160
1161         bt= uiDefButF(block, HSVCUBE, retval, "",       0,0,FPICK,BPICK, col, 0.0, 0.0, 3, 0, "");
1162         uiButSetFlag(bt, UI_NO_HILITE);
1163
1164         // palette
1165         
1166         uiBlockSetEmboss(block, UI_EMBOSSP);
1167         
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");
1171
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);
1179         }
1180         uiBlockEndAlign(block);
1181         
1182         uiBlockSetEmboss(block, UI_EMBOSS);
1183
1184         // buttons
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));      
1187
1188         offs= FPICK+2*DPICK+BPICK;
1189
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);
1194         
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);
1197
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);
1205         
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);
1214 }
1215
1216 uiBlock *ui_block_func_COL(wmWindow *window, uiMenuBlockHandle *handle, void *arg_but)
1217 {
1218         uiBut *but= arg_but;
1219         uiBlock *block;
1220         static float hsvcol[3], oldcol[3];
1221         static char hexcol[128];
1222         
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;
1226         
1227         VECCOPY(handle->retvec, but->editvec);
1228         uiBlockPickerButtons(block, handle->retvec, hsvcol, oldcol, hexcol, 'p', 0);
1229
1230         /* and lets go */
1231         block->direction= UI_TOP;
1232         uiBoundsBlock(block, 3);
1233         
1234         return block;
1235 }
1236
1237 /* ******************** PUPmenu ****************** */
1238
1239 static int pupmenu_set= 0;
1240
1241 void pupmenu_set_active(int val)
1242 {
1243         pupmenu_set= val;
1244 }
1245
1246 /* value== -1 read, otherwise set */
1247 static int pupmenu_memory(char *str, int value)
1248 {
1249         static char mem[256], first=1;
1250         int val=0, nr=0;
1251         
1252         if(first) {
1253                 memset(mem, 0, 256);
1254                 first= 0;
1255         }
1256         while(str[nr]) {
1257                 val+= str[nr];
1258                 nr++;
1259         }
1260
1261         if(value >= 0) mem[ val & 255 ]= value;
1262         else return mem[ val & 255 ];
1263         
1264         return 0;
1265 }
1266
1267 #define PUP_LABELH      6
1268
1269 typedef struct uiPupMenuInfo {
1270         char *instr;
1271         int mx, my;
1272         int startx, starty;
1273         int maxrow;
1274 } uiPupMenuInfo;
1275
1276 uiBlock *ui_block_func_PUPMENU(wmWindow *window, uiMenuBlockHandle *handle, void *arg_info)
1277 {
1278         uiBlock *block;
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;
1283         int lastselected;
1284         MenuData *md;
1285
1286         info= arg_info;
1287         maxrow= info->maxrow;
1288         height= 0;
1289
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;
1294         
1295         md= decompose_menu_string(info->instr);
1296
1297         rows= md->nitems;
1298         columns= 1;
1299
1300         /* size and location, title slightly bigger for bold */
1301         if(md->title) {
1302                 width= 2*strlen(md->title)+UI_GetStringWidth(uiBlockGetCurFont(block), md->title, ui_translate_buttons());
1303                 width /= columns;
1304         }
1305         else width= 0;
1306
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;
1310
1311                 if(strcmp(md->items[a].str, "%l")==0) height+= PUP_LABELH;
1312                 else height+= MENU_BUTTON_HEIGHT;
1313         }
1314
1315         width+= 10;
1316         if (width<50) width=50;
1317         
1318         wm_window_get_size(window, &xmax, &ymax);
1319
1320         /* set first item */
1321         lastselected= 0;
1322         if(pupmenu_set) {
1323                 lastselected= pupmenu_set-1;
1324                 pupmenu_set= 0;
1325         }
1326         else if(md->nitems>1) {
1327                 lastselected= pupmenu_memory(info->instr, -1);
1328         }
1329
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;
1337                 }
1338                 
1339                 //starty= info->my-height+MENU_BUTTON_HEIGHT/2+lastselected*MENU_BUTTON_HEIGHT;
1340         }
1341         
1342         if(startx<10) {
1343                 startx= 10;
1344         }
1345         if(starty<10) {
1346                 mousemove[1]= 10-starty;
1347                 starty= 10;
1348         }
1349         
1350         endx= startx+width*columns;
1351         endy= starty+height;
1352
1353         if(endx>xmax) {
1354                 endx= xmax-10;
1355                 startx= endx-width*columns;
1356         }
1357         if(endy>ymax-20) {
1358                 mousemove[1]= ymax-endy-20;
1359                 endy= ymax-20;
1360                 starty= endy-height;
1361         }
1362
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;
1367                 mousewarp= 1;
1368         }
1369
1370         /* here we go! */
1371         if(md->title) {
1372                 uiBut *bt;
1373                 char titlestr[256];
1374                 uiSetCurFont(block, UI_HELVB);
1375
1376                 if(md->titleicon) {
1377                         width+= 20;
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, "");
1380                 }
1381                 else {
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;
1384                 }
1385                 uiSetCurFont(block, UI_HELV);
1386         }
1387
1388         x1= startx + width*((int)a/rows);
1389         y1= starty + height - MENU_BUTTON_HEIGHT;
1390                 
1391         for(a=0; a<md->nitems; a++) {
1392                 char *name= md->items[a].str;
1393                 int icon = md->items[a].icon;
1394
1395                 if(strcmp(name, "%l")==0) {
1396                         uiDefBut(block, SEPR, B_NOP, "", x1, y1, width, PUP_LABELH, NULL, 0, 0.0, 0, 0, "");
1397                         y1 -= PUP_LABELH;
1398                 }
1399                 else if (icon) {
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;
1402                 }
1403                 else {
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;
1406                 }
1407         }
1408         
1409         uiBoundsBlock(block, 1);
1410         uiEndBlock(block);
1411
1412         menudata_free(md);
1413
1414         /* XXX 2.5 need to store last selected */
1415 #if 0
1416         /* calculate last selected */
1417         if(event & ui_return_ok) {
1418                 lastselected= 0;
1419                 for(a=0; a<md->nitems; a++) {
1420                         if(val==md->items[a].retval) lastselected= a;
1421                 }
1422                 
1423                 pupmenu_memory(info->instr, lastselected);
1424         }
1425 #endif
1426         
1427         /* XXX 2.5 need to warp back */
1428 #if 0
1429         if(mousemove[1] && (event & ui_return_out)==0)
1430                 ui_warp_pointer(mousemove[0], mousemove[1]);
1431         return val;
1432 #endif
1433
1434         return block;
1435 }
1436
1437 uiBlock *ui_block_func_PUPMENUCOL(wmWindow *window, uiMenuBlockHandle *handle, void *arg_info)
1438 {
1439         uiBlock *block;
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;
1444         float fvalue;
1445         MenuData *md;
1446
1447         info= arg_info;
1448         maxrow= info->maxrow;
1449         height= 0;
1450
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;
1455         
1456         md= decompose_menu_string(info->instr);
1457
1458         /* columns and row calculation */
1459         columns= (md->nitems+maxrow)/maxrow;
1460         if (columns<1) columns= 1;
1461         
1462         if(columns > 8) {
1463                 maxrow += 5;
1464                 columns= (md->nitems+maxrow)/maxrow;
1465         }
1466         
1467         rows= (int) md->nitems/columns;
1468         if (rows<1) rows= 1;
1469         
1470         while (rows*columns<(md->nitems+columns) ) rows++;
1471
1472         /* size and location, title slightly bigger for bold */
1473         if(md->title) {
1474                 width= 2*strlen(md->title)+UI_GetStringWidth(uiBlockGetCurFont(block), md->title, ui_translate_buttons());
1475                 width /= columns;
1476         }
1477         else width= 0;
1478
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;
1482         }
1483
1484         width+= 10;
1485         if (width<50) width=50;
1486         
1487         height= rows*MENU_BUTTON_HEIGHT;
1488         if (md->title) height+= MENU_BUTTON_HEIGHT;
1489         
1490         wm_window_get_size(window, &xmax, &ymax);
1491
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;
1496         }
1497
1498         /* no active item? */
1499         if(a==md->nitems) {
1500                 if(md->title) a= -1;
1501                 else a= 0;
1502         }
1503
1504         if(a>0)
1505                 startx = info->mx-width/2 - ((int)(a)/rows)*width;
1506         else
1507                 startx= info->mx-width/2;
1508         starty = info->my-height + MENU_BUTTON_HEIGHT/2 + ((a)%rows)*MENU_BUTTON_HEIGHT;
1509
1510         if (md->title) starty+= MENU_BUTTON_HEIGHT;
1511         
1512         if(startx<10) {
1513                 mousemove[0]= 10-startx;
1514                 startx= 10;
1515         }
1516         if(starty<10) {
1517                 mousemove[1]= 10-starty;
1518                 starty= 10;
1519         }
1520         
1521         endx= startx+width*columns;
1522         endy= starty+height;
1523
1524         if(endx>xmax) {
1525                 mousemove[0]= xmax-endx-10;
1526                 endx= xmax-10;
1527                 startx= endx-width*columns;
1528         }
1529         if(endy>ymax) {
1530                 mousemove[1]= ymax-endy-10;
1531                 endy= ymax-10;
1532                 starty= endy-height;
1533         }
1534
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;
1539                 mousewarp= 1;
1540         }
1541
1542         /* here we go! */
1543         if(md->title) {
1544                 uiBut *bt;
1545                 uiSetCurFont(block, UI_HELVB);
1546
1547                 if(md->titleicon) {
1548                 }
1549                 else {
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;
1552                 }
1553                 uiSetCurFont(block, UI_HELV);
1554         }
1555
1556         for(a=0; a<md->nitems; a++) {
1557                 char *name= md->items[a].str;
1558                 int icon = md->items[a].icon;
1559
1560                 x1= startx + width*((int)a/rows);
1561                 y1= starty - MENU_BUTTON_HEIGHT*(a%rows) + (rows-1)*MENU_BUTTON_HEIGHT; 
1562                 
1563                 if(strcmp(name, "%l")==0) {
1564                         uiDefBut(block, SEPR, B_NOP, "", x1, y1, width, PUP_LABELH, NULL, 0, 0.0, 0, 0, "");
1565                         y1 -= PUP_LABELH;
1566                 }
1567                 else if (icon) {
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;
1570                 }
1571                 else {
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;
1574                 }
1575         }
1576         
1577         uiBoundsBlock(block, 1);
1578         uiEndBlock(block);
1579
1580 #if 0
1581         event= uiDoBlocks(&listb, 0, 1);
1582 #endif
1583         
1584         menudata_free(md);
1585         
1586         /* XXX 2.5 need to warp back */
1587 #if 0
1588         if((event & UI_RETURN_OUT)==0)
1589                 ui_warp_pointer(mousemove[0], mousemove[1]);
1590 #endif
1591
1592         return block;
1593 }
1594
1595 uiMenuBlockHandle *pupmenu_col(bContext *C, char *instr, int mx, int my, int maxrow)
1596 {
1597         uiPupMenuInfo info;
1598
1599         memset(&info, 0, sizeof(info));
1600         info.instr= instr;
1601         info.mx= mx;
1602         info.my= my;
1603         info.maxrow= maxrow;
1604
1605         return ui_menu_block_create(C, NULL, NULL, ui_block_func_PUPMENUCOL, &info);
1606 }
1607
1608 uiMenuBlockHandle *pupmenu(bContext *C, char *instr, int mx, int my)
1609 {
1610         uiPupMenuInfo info;
1611
1612         memset(&info, 0, sizeof(info));
1613         info.instr= instr;
1614         info.mx= mx;
1615         info.my= my;
1616
1617         return ui_menu_block_create(C, NULL, NULL, ui_block_func_PUPMENU, &info);
1618 }
1619
1620
1621 void pupmenu_free(bContext *C, uiMenuBlockHandle *handle)
1622 {
1623         ui_menu_block_free(C, handle);
1624 }
1625
1626 /*************** Temporary Buttons Tests **********************/
1627
1628 static uiBlock *test_submenu(wmWindow *window, uiMenuBlockHandle *handle, void *arg)
1629 {
1630         ARegion *ar= handle->region;
1631         uiBlock *block;
1632         short yco= 0, menuwidth=120;
1633         
1634         block= uiBeginBlock(window, ar, "test_viewmenu", UI_EMBOSSP, UI_HELV);
1635         //uiBlockSetButmFunc(block, do_test_viewmenu, NULL);
1636         
1637         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Play Back Animation", 0, yco-=20,
1638                                          menuwidth, 19, NULL, 0.0, 0.0, 1, 2, "");
1639
1640         uiDefBut(block, SEPR, 0, "",        0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
1641         
1642         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Show Seconds|T", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 5, "");
1643         
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, "");
1646         
1647         uiDefBut(block, SEPR, 0, "",        0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
1648         
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, "");
1653         
1654         uiDefBut(block, SEPR, 0, "",        0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
1655         
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, "");
1660         
1661         uiBlockSetDirection(block, UI_RIGHT);
1662
1663         uiTextBoundsBlock(block, 50);
1664         uiEndBlock(block);
1665         
1666         return block;
1667 }
1668
1669 static uiBlock *test_viewmenu(wmWindow *window, uiMenuBlockHandle *handle, void *arg_area)
1670 {
1671         ScrArea *area= arg_area;
1672         ARegion *ar= handle->region;
1673         uiBlock *block;
1674         short yco= 0, menuwidth=120;
1675         
1676         block= uiBeginBlock(window, ar, "test_viewmenu", UI_EMBOSSP, UI_HELV);
1677         //uiBlockSetButmFunc(block, do_test_viewmenu, NULL);
1678         
1679         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Play Back Animation", 0, yco-=20,
1680                                          menuwidth, 19, NULL, 0.0, 0.0, 1, 2, "");
1681
1682         uiDefBut(block, SEPR, 0, "",        0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
1683         
1684         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Show Seconds|T", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 5, "");
1685         
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, "");
1688         
1689         uiDefBut(block, SEPR, 0, "",        0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
1690         
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, "");
1695         
1696         uiDefBut(block, SEPR, 0, "",        0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
1697         
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, "");
1702
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, "");
1706
1707         if(area->headertype==HEADERTOP) {
1708                 uiBlockSetDirection(block, UI_DOWN);
1709         }
1710         else {
1711                 uiBlockSetDirection(block, UI_TOP);
1712                 uiBlockFlipOrder(block);
1713         }
1714
1715         uiTextBoundsBlock(block, 50);
1716         uiEndBlock(block);
1717         
1718         return block;
1719 }
1720
1721 void uiTestRegion(const bContext *C)
1722 {
1723         uiBlock *block;
1724         static float testcol[3];
1725         static char testtext[64];
1726         static float testnumf=5.0f;
1727         static short testchoice= 0, testtog= 0;
1728 #if 0
1729         static CurveMapping *cumap= NULL;
1730         static ColorBand *coba= NULL;
1731 #endif
1732
1733         block= uiBeginBlock(C->window, C->region, "header buttons", UI_EMBOSS, UI_HELV);
1734
1735         uiDefPulldownBut(block, test_viewmenu, C->area,  "View",
1736                 13, 1, 50, 24, "");
1737
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.");
1744
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");
1747
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.");
1752
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*/, "");
1755
1756 #if 0
1757         if(!cumap) {
1758                 cumap= curvemapping_add(4, 0.0f, 0.0f, 1.0f, 1.0f);  
1759                 cumap->flag &= ~CUMA_DO_CLIP;
1760         }
1761         if(!coba)
1762                 coba= add_colorband(0);
1763
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, "");
1768 #endif
1769
1770         uiEndBlock(block);
1771         uiDrawBlock(block);
1772 }
1773