2.5
[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_view2d_types.h"
9 #include "DNA_windowmanager_types.h"
10
11 #include "BLI_arithb.h"
12 #include "BLI_blenlib.h"
13
14 #include "BKE_global.h"
15 #include "BKE_screen.h"
16 #include "BKE_utildefines.h"
17
18 #include "WM_api.h"
19 #include "WM_types.h"
20 #include "wm_subwindow.h"
21 #include "wm_window.h"
22
23 #include "BIF_gl.h"
24
25 #include "UI_interface.h"
26 #include "UI_text.h"
27 #include "UI_view2d.h"
28
29 #include "ED_screen.h"
30
31 #include "interface.h"
32
33 #define MENU_BUTTON_HEIGHT      20
34 #define B_NOP                   -1
35 #define MENU_SHADOW_LEFT        -1
36 #define MENU_SHADOW_BOTTOM      -10
37 #define MENU_SHADOW_RIGHT       10
38 #define MENU_SHADOW_TOP         1
39
40 /*********************** Menu Data Parsing ********************* */
41
42 typedef struct {
43         char *str;
44         int retval;
45         int icon;
46 } MenuEntry;
47
48 typedef struct {
49         char *instr;
50         char *title;
51         int titleicon;
52         
53         MenuEntry *items;
54         int nitems, itemssize;
55 } MenuData;
56
57 static MenuData *menudata_new(char *instr)
58 {
59         MenuData *md= MEM_mallocN(sizeof(*md), "MenuData");
60
61         md->instr= instr;
62         md->title= NULL;
63         md->titleicon= 0;
64         md->items= NULL;
65         md->nitems= md->itemssize= 0;
66         
67         return md;
68 }
69
70 static void menudata_set_title(MenuData *md, char *title, int titleicon)
71 {
72         if (!md->title)
73                 md->title= title;
74         if (!md->titleicon)
75                 md->titleicon= titleicon;
76 }
77
78 static void menudata_add_item(MenuData *md, char *str, int retval, int icon)
79 {
80         if (md->nitems==md->itemssize) {
81                 int nsize= md->itemssize?(md->itemssize<<1):1;
82                 MenuEntry *oitems= md->items;
83                 
84                 md->items= MEM_mallocN(nsize*sizeof(*md->items), "md->items");
85                 if (oitems) {
86                         memcpy(md->items, oitems, md->nitems*sizeof(*md->items));
87                         MEM_freeN(oitems);
88                 }
89                 
90                 md->itemssize= nsize;
91         }
92         
93         md->items[md->nitems].str= str;
94         md->items[md->nitems].retval= retval;
95         md->items[md->nitems].icon= icon;
96         md->nitems++;
97 }
98
99 void menudata_free(MenuData *md)
100 {
101         MEM_freeN(md->instr);
102         if (md->items)
103                 MEM_freeN(md->items);
104         MEM_freeN(md);
105 }
106
107         /**
108          * Parse menu description strings, string is of the
109          * form "[sss%t|]{(sss[%xNN]|), (%l|)}", ssss%t indicates the
110          * menu title, sss or sss%xNN indicates an option, 
111          * if %xNN is given then NN is the return value if
112          * that option is selected otherwise the return value
113          * is the index of the option (starting with 1). %l
114          * indicates a seperator.
115          * 
116          * @param str String to be parsed.
117          * @retval new menudata structure, free with menudata_free()
118          */
119 MenuData *decompose_menu_string(char *str) 
120 {
121         char *instr= BLI_strdup(str);
122         MenuData *md= menudata_new(instr);
123         char *nitem= NULL, *s= instr;
124         int nicon=0, nretval= 1, nitem_is_title= 0;
125         
126         while (1) {
127                 char c= *s;
128
129                 if (c=='%') {
130                         if (s[1]=='x') {
131                                 nretval= atoi(s+2);
132
133                                 *s= '\0';
134                                 s++;
135                         } else if (s[1]=='t') {
136                                 nitem_is_title= 1;
137
138                                 *s= '\0';
139                                 s++;
140                         } else if (s[1]=='l') {
141                                 nitem= "%l";
142                                 s++;
143                         } else if (s[1]=='i') {
144                                 nicon= atoi(s+2);
145                                 
146                                 *s= '\0';
147                                 s++;
148                         }
149                 } else if (c=='|' || c=='\0') {
150                         if (nitem) {
151                                 *s= '\0';
152
153                                 if (nitem_is_title) {
154                                         menudata_set_title(md, nitem, nicon);
155                                         nitem_is_title= 0;
156                                 } else {
157                                         /* prevent separator to get a value */
158                                         if(nitem[0]=='%' && nitem[1]=='l')
159                                                 menudata_add_item(md, nitem, -1, nicon);
160                                         else
161                                                 menudata_add_item(md, nitem, nretval, nicon);
162                                         nretval= md->nitems+1;
163                                 } 
164                                 
165                                 nitem= NULL;
166                                 nicon= 0;
167                         }
168                         
169                         if (c=='\0')
170                                 break;
171                 } else if (!nitem)
172                         nitem= s;
173                 
174                 s++;
175         }
176         
177         return md;
178 }
179
180 void ui_set_name_menu(uiBut *but, int value)
181 {
182         MenuData *md;
183         int i;
184         
185         md= decompose_menu_string(but->str);
186         for (i=0; i<md->nitems; i++)
187                 if (md->items[i].retval==value)
188                         strcpy(but->drawstr, md->items[i].str);
189         
190         menudata_free(md);
191 }
192
193 /******************** Creating Temporary regions ******************/
194
195 ARegion *ui_add_temporary_region(bScreen *sc)
196 {
197         ARegion *ar;
198
199         ar= MEM_callocN(sizeof(ARegion), "area region");
200         BLI_addtail(&sc->regionbase, ar);
201
202         ar->regiontype= RGN_TYPE_TEMPORARY;
203         ar->alignment= RGN_ALIGN_FLOAT;
204
205         return ar;
206 }
207
208 void ui_remove_temporary_region(bContext *C, bScreen *sc, ARegion *ar)
209 {
210         ED_region_exit(C, ar);
211         BKE_area_region_free(ar);
212         BLI_freelinkN(&sc->regionbase, ar);
213 }
214
215 /************************* Creating Tooltips **********************/
216
217 typedef struct uiTooltipData {
218         rctf bbox;
219         struct BMF_Font *font;
220         char *tip;
221         float aspect;
222 } uiTooltipData;
223
224 static void ui_tooltip_region_draw(const bContext *C, ARegion *ar)
225 {
226         uiTooltipData *data;
227         int x1, y1, x2, y2;
228
229         data= ar->regiondata;
230
231         x1= ar->winrct.xmin;
232         y1= ar->winrct.ymin;
233         x2= ar->winrct.xmax;
234         y2= ar->winrct.ymax;
235
236         /* draw drop shadow */
237         glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
238         glEnable(GL_BLEND);
239
240         glColor4ub(0, 0, 0, 20);
241         
242         gl_round_box(GL_POLYGON, 3, 3, x2-x1-3, y2-y1-2, 2.0);
243         gl_round_box(GL_POLYGON, 3, 2, x2-x1-2, y2-y1-2, 3.0);
244         
245         glColor4ub(0, 0, 0, 8);
246         
247         gl_round_box(GL_POLYGON, 3, 1, x2-x1-1, y2-y1-3, 4.0);
248         gl_round_box(GL_POLYGON, 3, 0, x2-x1-0, y2-y1-3, 5.0);
249
250         glDisable(GL_BLEND);
251         
252         /* draw background */
253         glColor3f(1.0f, 1.0f, 0.8666f);
254         glRectf(0, 4, x2-x1+4, y2-y1);
255         
256         /* draw text */
257         glColor3ub(0,0,0);
258
259         /* set the position for drawing text +4 in from the left edge, and leaving
260          * an equal gap between the top of the background box and the top of the
261          * string's bbox, and the bottom of the background box, and the bottom of
262          * the string's bbox */
263         ui_rasterpos_safe(4, ((y2-data->bbox.ymax)+(y1+data->bbox.ymin))/2 - data->bbox.ymin - y1, data->aspect);
264         UI_SetScale(1.0);
265
266         UI_DrawString(data->font, data->tip, ui_translate_tooltips());
267 }
268
269 static void ui_tooltip_region_free(ARegion *ar)
270 {
271         uiTooltipData *data;
272
273         data= ar->regiondata;
274         MEM_freeN(data->tip);
275         MEM_freeN(data);
276 }
277
278 ARegion *ui_tooltip_create(bContext *C, ARegion *butregion, uiBut *but)
279 {
280         static ARegionType type;
281         ARegion *ar;
282         uiTooltipData *data;
283         int x1, x2, y1, y2, winx, winy;
284
285         if(!but->tip || strlen(but->tip)==0)
286                 return NULL;
287
288         /* create area region */
289         ar= ui_add_temporary_region(C->window->screen);
290
291         memset(&type, 0, sizeof(ARegionType));
292         type.draw= ui_tooltip_region_draw;
293         type.free= ui_tooltip_region_free;
294         ar->type= &type;
295
296         /* create tooltip data */
297         data= MEM_callocN(sizeof(uiTooltipData), "uiTooltipData");
298         data->tip= BLI_strdup(but->tip);
299         data->font= but->font;
300         data->aspect= but->aspect;
301         UI_GetBoundingBox(data->font, data->tip, ui_translate_tooltips(), &data->bbox);
302
303         ar->regiondata= data;
304
305         /* compute position */
306         x1= (but->x1+but->x2)/2;
307         x2= x1+but->aspect*((data->bbox.xmax-data->bbox.xmin) + 8);
308         y2= but->y1-10;
309         y1= y2-but->aspect*((data->bbox.ymax+(data->bbox.ymax-data->bbox.ymin)));
310
311         y2 += 8;
312         x2 += 8;
313
314         if(butregion) {
315                 /* XXX temp, region v2ds can be empty still */
316                 if(butregion->v2d.cur.xmin != butregion->v2d.cur.xmax) {
317                         short tx, ty;
318                         UI_view2d_to_region_no_clip(&butregion->v2d, x1, y1, &tx, &ty);
319                         x1= (int)tx; y1= (int)ty;
320                         UI_view2d_to_region_no_clip(&butregion->v2d, x2, y2, &tx, &ty);
321                         x2= (int)tx; y2= (int)ty;
322                 }
323
324                 x1 += butregion->winrct.xmin;
325                 x2 += butregion->winrct.xmin;
326                 y1 += butregion->winrct.ymin;
327                 y2 += butregion->winrct.ymin;
328         }
329
330         wm_window_get_size(C->window, &winx, &winy);
331
332         if(x2 > winx) {
333                 /* super size */
334                 if(x2 > winx + x1) {
335                         x2= winx;
336                         x1= 0;
337                 }
338                 else {
339                         x1 -= x2-winx;
340                         x2= winx;
341                 }
342         }
343         if(y1 < 0) {
344                 y1 += 36;
345                 y2 += 36;
346         }
347         
348         ar->winrct.xmin= x1;
349         ar->winrct.ymin= y1;
350         ar->winrct.xmax= x2;
351         ar->winrct.ymax= y2;
352
353         /* adds subwindow */
354         ED_region_init(C, ar);
355         
356         /* notify change and redraw */
357         WM_event_add_notifier(C, WM_NOTE_SCREEN_CHANGED, 0, NULL);
358         WM_event_add_notifier(C, WM_NOTE_WINDOW_REDRAW, 0, NULL);
359
360         return ar;
361 }
362
363 void ui_tooltip_free(bContext *C, ARegion *ar)
364 {
365         ui_remove_temporary_region(C, C->window->screen, ar);
366
367         WM_event_add_notifier(C, WM_NOTE_SCREEN_CHANGED, 0, NULL);
368         WM_event_add_notifier(C, WM_NOTE_WINDOW_REDRAW, 0, NULL);
369 }
370
371 /************************* Creating Menu Blocks **********************/
372
373 /* position block relative to but, result is in window space */
374 static void ui_block_position(wmWindow *window, ARegion *butregion, uiBut *but, uiBlock *block)
375 {
376         uiBut *bt;
377         uiSafetyRct *saferct;
378         rctf butrct;
379         float aspect;
380         int xsize, ysize, xof=0, yof=0, center;
381         short dir1= 0, dir2=0;
382         
383         /* transform to window coordinates, using the source button region/block */
384         butrct.xmin= but->x1; butrct.xmax= but->x2;
385         butrct.ymin= but->y1; butrct.ymax= but->y2;
386
387         ui_block_to_window_fl(butregion, but->block, &butrct.xmin, &butrct.ymin);
388         ui_block_to_window_fl(butregion, but->block, &butrct.xmax, &butrct.ymax);
389
390         /* calc block rect */
391         if(block->minx == 0.0f && block->maxx == 0.0f) {
392                 if(block->buttons.first) {
393                         block->minx= block->miny= 10000;
394                         block->maxx= block->maxy= -10000;
395                         
396                         bt= block->buttons.first;
397                         while(bt) {
398                                 if(bt->x1 < block->minx) block->minx= bt->x1;
399                                 if(bt->y1 < block->miny) block->miny= bt->y1;
400
401                                 if(bt->x2 > block->maxx) block->maxx= bt->x2;
402                                 if(bt->y2 > block->maxy) block->maxy= bt->y2;
403                                 
404                                 bt= bt->next;
405                         }
406                 }
407                 else {
408                         /* we're nice and allow empty blocks too */
409                         block->minx= block->miny= 0;
410                         block->maxx= block->maxy= 20;
411                 }
412         }
413         
414         aspect= (float)(block->maxx - block->minx + 4);
415         ui_block_to_window_fl(butregion, but->block, &block->minx, &block->miny);
416         ui_block_to_window_fl(butregion, but->block, &block->maxx, &block->maxy);
417
418         //block->minx-= 2.0; block->miny-= 2.0;
419         //block->maxx+= 2.0; block->maxy+= 2.0;
420         
421         xsize= block->maxx - block->minx+4; // 4 for shadow
422         ysize= block->maxy - block->miny+4;
423         aspect/= (float)xsize;
424
425         if(but) {
426                 int left=0, right=0, top=0, down=0;
427                 int winx, winy;
428
429                 wm_window_get_size(window, &winx, &winy);
430
431                 if(block->direction & UI_CENTER) center= ysize/2;
432                 else center= 0;
433
434                 if( butrct.xmin-xsize > 0.0) left= 1;
435                 if( butrct.xmax+xsize < winx) right= 1;
436                 if( butrct.ymin-ysize+center > 0.0) down= 1;
437                 if( butrct.ymax+ysize-center < winy) top= 1;
438                 
439                 dir1= block->direction & UI_DIRECTION;
440
441                 /* secundary directions */
442                 if(dir1 & (UI_TOP|UI_DOWN)) {
443                         if(dir1 & UI_LEFT) dir2= UI_LEFT;
444                         else if(dir1 & UI_RIGHT) dir2= UI_RIGHT;
445                         dir1 &= (UI_TOP|UI_DOWN);
446                 }
447
448                 if(dir2==0) if(dir1==UI_LEFT || dir1==UI_RIGHT) dir2= UI_DOWN;
449                 if(dir2==0) if(dir1==UI_TOP || dir1==UI_DOWN) dir2= UI_LEFT;
450                 
451                 /* no space at all? dont change */
452                 if(left || right) {
453                         if(dir1==UI_LEFT && left==0) dir1= UI_RIGHT;
454                         if(dir1==UI_RIGHT && right==0) dir1= UI_LEFT;
455                         /* this is aligning, not append! */
456                         if(dir2==UI_LEFT && right==0) dir2= UI_RIGHT;
457                         if(dir2==UI_RIGHT && left==0) dir2= UI_LEFT;
458                 }
459                 if(down || top) {
460                         if(dir1==UI_TOP && top==0) dir1= UI_DOWN;
461                         if(dir1==UI_DOWN && down==0) dir1= UI_TOP;
462                         if(dir2==UI_TOP && top==0) dir2= UI_DOWN;
463                         if(dir2==UI_DOWN && down==0) dir2= UI_TOP;
464                 }
465                 
466                 if(dir1==UI_LEFT) {
467                         xof= butrct.xmin - block->maxx;
468                         if(dir2==UI_TOP) yof= butrct.ymin - block->miny-center;
469                         else yof= butrct.ymax - block->maxy+center;
470                 }
471                 else if(dir1==UI_RIGHT) {
472                         xof= butrct.xmax - block->minx;
473                         if(dir2==UI_TOP) yof= butrct.ymin - block->miny-center;
474                         else yof= butrct.ymax - block->maxy+center;
475                 }
476                 else if(dir1==UI_TOP) {
477                         yof= butrct.ymax - block->miny;
478                         if(dir2==UI_RIGHT) xof= butrct.xmax - block->maxx;
479                         else xof= butrct.xmin - block->minx;
480                         // changed direction? 
481                         if((dir1 & block->direction)==0) {
482                                 if(block->direction & UI_SHIFT_FLIPPED)
483                                         xof+= dir2==UI_LEFT?25:-25;
484                                 uiBlockFlipOrder(block);
485                         }
486                 }
487                 else if(dir1==UI_DOWN) {
488                         yof= butrct.ymin - block->maxy;
489                         if(dir2==UI_RIGHT) xof= butrct.xmax - block->maxx;
490                         else xof= butrct.xmin - block->minx;
491                         // changed direction?
492                         if((dir1 & block->direction)==0) {
493                                 if(block->direction & UI_SHIFT_FLIPPED)
494                                         xof+= dir2==UI_LEFT?25:-25;
495                                 uiBlockFlipOrder(block);
496                         }
497                 }
498
499                 /* and now we handle the exception; no space below or to top */
500                 if(top==0 && down==0) {
501                         if(dir1==UI_LEFT || dir1==UI_RIGHT) {
502                                 // align with bottom of screen 
503                                 yof= ysize;
504                         }
505                 }
506                 
507                 /* or no space left or right */
508                 if(left==0 && right==0) {
509                         if(dir1==UI_TOP || dir1==UI_DOWN) {
510                                 // align with left size of screen 
511                                 xof= -block->minx+5;
512                         }
513                 }
514                 
515                 // apply requested offset in the block
516                 xof += block->xofs/block->aspect;
517                 yof += block->yofs/block->aspect;
518         }
519         
520         /* apply */
521         
522         for(bt= block->buttons.first; bt; bt= bt->next) {
523                 ui_block_to_window_fl(butregion, but->block, &bt->x1, &bt->y1);
524                 ui_block_to_window_fl(butregion, but->block, &bt->x2, &bt->y2);
525
526                 bt->x1 += xof;
527                 bt->x2 += xof;
528                 bt->y1 += yof;
529                 bt->y2 += yof;
530
531                 bt->aspect= 1.0;
532                 // ui_check_but recalculates drawstring size in pixels
533                 ui_check_but(bt);
534         }
535         
536         block->minx += xof;
537         block->miny += yof;
538         block->maxx += xof;
539         block->maxy += yof;
540
541         /* safety calculus */
542         if(but) {
543                 float midx= (butrct.xmin+butrct.xmax)/2.0;
544                 float midy= (butrct.ymin+butrct.ymax)/2.0;
545                 
546                 /* when you are outside parent button, safety there should be smaller */
547                 
548                 // parent button to left
549                 if( midx < block->minx ) block->safety.xmin= block->minx-3; 
550                 else block->safety.xmin= block->minx-40;
551                 // parent button to right
552                 if( midx > block->maxx ) block->safety.xmax= block->maxx+3; 
553                 else block->safety.xmax= block->maxx+40;
554                 
555                 // parent button on bottom
556                 if( midy < block->miny ) block->safety.ymin= block->miny-3; 
557                 else block->safety.ymin= block->miny-40;
558                 // parent button on top
559                 if( midy > block->maxy ) block->safety.ymax= block->maxy+3; 
560                 else block->safety.ymax= block->maxy+40;
561                 
562                 // exception for switched pulldowns...
563                 if(dir1 && (dir1 & block->direction)==0) {
564                         if(dir2==UI_RIGHT) block->safety.xmax= block->maxx+3; 
565                         if(dir2==UI_LEFT) block->safety.xmin= block->minx-3; 
566                 }
567                 block->direction= dir1;
568         }
569         else {
570                 block->safety.xmin= block->minx-40;
571                 block->safety.ymin= block->miny-40;
572                 block->safety.xmax= block->maxx+40;
573                 block->safety.ymax= block->maxy+40;
574         }
575
576         /* keep a list of these, needed for pulldown menus */
577         saferct= MEM_callocN(sizeof(uiSafetyRct), "uiSafetyRct");
578         saferct->parent= butrct;
579         saferct->safety= block->safety;
580         BLI_freelistN(&block->saferct);
581         if(but)
582                 BLI_duplicatelist(&block->saferct, &but->block->saferct);
583         BLI_addhead(&block->saferct, saferct);
584 }
585
586 static void ui_block_region_draw(const bContext *C, ARegion *ar)
587 {
588         uiBlock *block;
589
590         for(block=ar->uiblocks.first; block; block=block->next) {
591                 wm_subwindow_getmatrix(C->window, ar->swinid, block->winmat);
592                 uiDrawBlock(block);
593         }
594 }
595
596 uiMenuBlockHandle *ui_menu_block_create(bContext *C, ARegion *butregion, uiBut *but, uiBlockFuncFP block_func, void *arg)
597 {
598         static ARegionType type;
599         ARegion *ar;
600         uiBlock *block;
601         uiBut *bt;
602         uiMenuBlockHandle *handle;
603         uiSafetyRct *saferct;
604
605         /* create handle */
606         handle= MEM_callocN(sizeof(uiMenuBlockHandle), "uiMenuBlockHandle");
607
608         /* create area region */
609         ar= ui_add_temporary_region(C->window->screen);
610
611         memset(&type, 0, sizeof(ARegionType));
612         type.draw= ui_block_region_draw;
613         ar->type= &type;
614
615         UI_add_region_handlers(&ar->handlers);
616
617         handle->region= ar;
618         ar->regiondata= handle;
619
620         /* create ui block */
621         block= block_func(C, handle, arg);
622         block->handle= handle;
623
624         /* if this is being created from a button */
625         if(but) {
626                 if(ELEM(but->type, BLOCK, PULLDOWN))
627                         block->xofs = -2;       /* for proper alignment */
628
629                 /* only used for automatic toolbox, so can set the shift flag */
630                 if(but->flag & UI_MAKE_TOP) {
631                         block->direction= UI_TOP|UI_SHIFT_FLIPPED;
632                         uiBlockFlipOrder(block);
633                 }
634                 if(but->flag & UI_MAKE_DOWN) block->direction= UI_DOWN|UI_SHIFT_FLIPPED;
635                 if(but->flag & UI_MAKE_LEFT) block->direction |= UI_LEFT;
636                 if(but->flag & UI_MAKE_RIGHT) block->direction |= UI_RIGHT;
637
638                 ui_block_position(C->window, butregion, but, block);
639         }
640         else {
641                 /* keep a list of these, needed for pulldown menus */
642                 saferct= MEM_callocN(sizeof(uiSafetyRct), "uiSafetyRct");
643                 saferct->safety= block->safety;
644                 BLI_addhead(&block->saferct, saferct);
645         }
646
647         /* the block and buttons were positioned in window space as in 2.4x, now
648          * these menu blocks are regions so we bring it back to region space.
649          * additionally we add some padding for the menu shadow */
650         ar->winrct.xmin= block->minx + MENU_SHADOW_LEFT;
651         ar->winrct.xmax= block->maxx + MENU_SHADOW_RIGHT;
652         ar->winrct.ymin= block->miny + MENU_SHADOW_BOTTOM;
653         ar->winrct.ymax= block->maxy + MENU_SHADOW_TOP;
654
655         block->minx -= ar->winrct.xmin;
656         block->maxx -= ar->winrct.xmin;
657         block->miny -= ar->winrct.ymin;
658         block->maxy -= ar->winrct.ymin;
659
660         for(bt= block->buttons.first; bt; bt= bt->next) {
661                 bt->x1 -= ar->winrct.xmin;
662                 bt->x2 -= ar->winrct.xmin;
663                 bt->y1 -= ar->winrct.ymin;
664                 bt->y2 -= ar->winrct.ymin;
665         }
666
667         block->flag |= UI_BLOCK_LOOP|UI_BLOCK_MOVEMOUSE_QUIT;
668
669         /* adds subwindow */
670         ED_region_init(C, ar);
671         
672         /* notify change and redraw */
673         WM_event_add_notifier(C, WM_NOTE_SCREEN_CHANGED, 0, NULL);
674         WM_event_add_notifier(C, WM_NOTE_WINDOW_REDRAW, 0, NULL);
675
676         return handle;
677 }
678
679 void ui_menu_block_free(bContext *C, uiMenuBlockHandle *handle)
680 {
681         ui_remove_temporary_region(C, C->window->screen, handle->region);
682         MEM_freeN(handle);
683
684         WM_event_add_notifier(C, WM_NOTE_SCREEN_CHANGED, 0, NULL);
685         WM_event_add_notifier(C, WM_NOTE_WINDOW_REDRAW, 0, NULL);
686 }
687
688 /***************************** Menu Button ***************************/
689
690 uiBlock *ui_block_func_MENU(bContext *C, uiMenuBlockHandle *handle, void *arg_but)
691 {
692         uiBut *but= arg_but;
693         uiBlock *block;
694         uiBut *bt;
695         MenuData *md;
696         ListBase lb;
697         float aspect;
698         int width, height, boxh, columns, rows, startx, starty, x1, y1, xmax, a;
699
700         /* create the block */
701         block= uiBeginBlock(C, handle->region, "menu", UI_EMBOSSP, UI_HELV);
702         block->dt= UI_EMBOSSP;
703         block->flag= UI_BLOCK_LOOP|UI_BLOCK_REDRAW|UI_BLOCK_NUMSELECT;
704         block->themecol= TH_MENU_ITEM;
705
706         /* compute menu data */
707         md= decompose_menu_string(but->str);
708
709         /* columns and row calculation */
710         columns= (md->nitems+20)/20;
711         if(columns<1)
712                 columns= 1;
713         if(columns>8)
714                 columns= (md->nitems+25)/25;
715         
716         rows= md->nitems/columns;
717         if(rows<1)
718                 rows= 1;
719         while(rows*columns<md->nitems)
720                 rows++;
721                 
722         /* prevent scaling up of pupmenu */
723         aspect= but->aspect;
724         if(aspect < 1.0f)
725                 aspect = 1.0f;
726
727         /* size and location */
728         if(md->title)
729                 width= 1.5*aspect*strlen(md->title)+UI_GetStringWidth(block->curfont, md->title, ui_translate_menus());
730         else
731                 width= 0;
732
733         for(a=0; a<md->nitems; a++) {
734                 xmax= aspect*UI_GetStringWidth(block->curfont, md->items[a].str, ui_translate_menus());
735                 if(md->items[a].icon)
736                         xmax += 20*aspect;
737                 if(xmax>width)
738                         width= xmax;
739         }
740
741         width+= 10;
742         if(width < (but->x2 - but->x1))
743                 width = (but->x2 - but->x1);
744         if(width<50)
745                 width=50;
746
747         boxh= MENU_BUTTON_HEIGHT;
748         
749         height= rows*boxh;
750         if(md->title)
751                 height+= boxh;
752
753         /* here we go! */
754         startx= but->x1;
755         starty= but->y1;
756         
757         if(md->title) {
758                 uiBut *bt;
759                 uiSetCurFont(block, block->font+1);
760                 if (md->titleicon) {
761                         bt= uiDefIconTextBut(block, LABEL, 0, md->titleicon, md->title, startx, (short)(starty+rows*boxh), (short)width, (short)boxh, NULL, 0.0, 0.0, 0, 0, "");
762                 } else {
763                         bt= uiDefBut(block, LABEL, 0, md->title, startx, (short)(starty+rows*boxh), (short)width, (short)boxh, NULL, 0.0, 0.0, 0, 0, "");
764                         bt->flag= UI_TEXT_LEFT;
765                 }
766                 uiSetCurFont(block, block->font);
767         }
768
769         for(a=0; a<md->nitems; a++) {
770                 
771                 x1= startx + width*((int)(md->nitems-a-1)/rows);
772                 y1= starty - boxh*(rows - ((md->nitems - a - 1)%rows)) + (rows*boxh);
773
774                 if (strcmp(md->items[md->nitems-a-1].str, "%l")==0) {
775                         bt= uiDefBut(block, SEPR, B_NOP, "", x1, y1,(short)(width-(rows>1)), (short)(boxh-1), NULL, 0.0, 0.0, 0, 0, "");
776                 }
777                 else if(md->items[md->nitems-a-1].icon) {
778                         bt= uiDefIconTextButF(block, BUTM|FLO, B_NOP, md->items[md->nitems-a-1].icon ,md->items[md->nitems-a-1].str, x1, y1,(short)(width-(rows>1)), (short)(boxh-1), &handle->retvalue, (float) md->items[md->nitems-a-1].retval, 0.0, 0, 0, "");
779                 }
780                 else {
781                         bt= uiDefButF(block, BUTM|FLO, B_NOP, md->items[md->nitems-a-1].str, x1, y1,(short)(width-(rows>1)), (short)(boxh-1), &handle->retvalue, (float) md->items[md->nitems-a-1].retval, 0.0, 0, 0, "");
782                 }
783         }
784         
785         menudata_free(md);
786
787         /* the code up here has flipped locations, because of change of preferred order */
788         /* thats why we have to switch list order too, to make arrowkeys work */
789         
790         lb.first= lb.last= NULL;
791         bt= block->buttons.first;
792         while(bt) {
793                 uiBut *next= bt->next;
794                 BLI_remlink(&block->buttons, bt);
795                 BLI_addhead(&lb, bt);
796                 bt= next;
797         }
798         block->buttons= lb;
799
800         block->direction= UI_TOP;
801         uiEndBlock(C, block);
802
803         return block;
804 }
805
806 uiBlock *ui_block_func_ICONROW(bContext *C, uiMenuBlockHandle *handle, void *arg_but)
807 {
808         uiBut *but= arg_but;
809         uiBlock *block;
810         int a;
811         
812         block= uiBeginBlock(C, handle->region, "menu", UI_EMBOSSP, UI_HELV);
813         block->flag= UI_BLOCK_LOOP|UI_BLOCK_REDRAW|UI_BLOCK_NUMSELECT;
814         block->themecol= TH_MENU_ITEM;
815         
816         for(a=(int)but->min; a<=(int)but->max; a++) {
817                 uiDefIconButF(block, BUTM|FLO, B_NOP, but->icon+(a-but->min), 0, (short)(18*a), (short)(but->x2-but->x1-4), 18, &handle->retvalue, (float)a, 0.0, 0, 0, "");
818         }
819
820         block->direction= UI_TOP;       
821
822         uiEndBlock(C, block);
823
824         return block;
825 }
826
827 uiBlock *ui_block_func_ICONTEXTROW(bContext *C, uiMenuBlockHandle *handle, void *arg_but)
828 {
829         uiBut *but= arg_but;
830         uiBlock *block;
831         MenuData *md;
832         int width, xmax, ypos, a;
833
834         block= uiBeginBlock(C, handle->region, "menu", UI_EMBOSSP, UI_HELV);
835         block->flag= UI_BLOCK_LOOP|UI_BLOCK_REDRAW|UI_BLOCK_NUMSELECT;
836         block->themecol= TH_MENU_ITEM;
837
838         md= decompose_menu_string(but->str);
839
840         /* size and location */
841         /* expand menu width to fit labels */
842         if(md->title)
843                 width= 2*strlen(md->title)+UI_GetStringWidth(block->curfont, md->title, ui_translate_menus());
844         else
845                 width= 0;
846
847         for(a=0; a<md->nitems; a++) {
848                 xmax= UI_GetStringWidth(block->curfont, md->items[a].str, ui_translate_menus());
849                 if(xmax>width) width= xmax;
850         }
851
852         width+= 30;
853         if (width<50) width=50;
854
855         ypos = 1;
856
857         /* loop through the menu options and draw them out with icons & text labels */
858         for(a=0; a<md->nitems; a++) {
859
860                 /* add a space if there's a separator (%l) */
861                 if (strcmp(md->items[a].str, "%l")==0) {
862                         ypos +=3;
863                 }
864                 else {
865                         uiDefIconTextButF(block, BUTM|FLO, B_NOP, (short)((but->icon)+(md->items[a].retval-but->min)), md->items[a].str, 0, ypos,(short)width, 19, &handle->retvalue, (float) md->items[a].retval, 0.0, 0, 0, "");
866                         ypos += 20;
867                 }
868         }
869         
870         if(md->title) {
871                 uiBut *bt;
872                 uiSetCurFont(block, block->font+1);
873                 bt= uiDefBut(block, LABEL, 0, md->title, 0, ypos, (short)width, 19, NULL, 0.0, 0.0, 0, 0, "");
874                 uiSetCurFont(block, block->font);
875                 bt->flag= UI_TEXT_LEFT;
876         }
877         
878         menudata_free(md);
879
880         block->direction= UI_TOP;
881
882         uiBoundsBlock(block, 3);
883         uiEndBlock(C, block);
884
885         return block;
886 }
887
888 static void ui_warp_pointer(short x, short y)
889 {
890         /* XXX 2.50 which function to use for this? */
891 #if 0
892         /* OSX has very poor mousewarp support, it sends events;
893            this causes a menu being pressed immediately ... */
894         #ifndef __APPLE__
895         warp_pointer(x, y);
896         #endif
897 #endif
898 }
899
900 /********************* Color Button ****************/
901
902 /* picker sizes S hsize, F full size, D spacer, B button/pallette height  */
903 #define SPICK   110.0
904 #define FPICK   180.0
905 #define DPICK   6.0
906 #define BPICK   24.0
907
908 #define UI_PALETTE_TOT 16
909 /* note; in tot+1 the old color is stored */
910 static float palette[UI_PALETTE_TOT+1][3]= {
911 {0.93, 0.83, 0.81}, {0.88, 0.89, 0.73}, {0.69, 0.81, 0.57}, {0.51, 0.76, 0.64}, 
912 {0.37, 0.56, 0.61}, {0.33, 0.29, 0.55}, {0.46, 0.21, 0.51}, {0.40, 0.12, 0.18}, 
913 {1.0, 1.0, 1.0}, {0.85, 0.85, 0.85}, {0.7, 0.7, 0.7}, {0.56, 0.56, 0.56}, 
914 {0.42, 0.42, 0.42}, {0.28, 0.28, 0.28}, {0.14, 0.14, 0.14}, {0.0, 0.0, 0.0}
915 };  
916
917 /* for picker, while editing hsv */
918 void ui_set_but_hsv(uiBut *but)
919 {
920         float col[3];
921         
922         hsv_to_rgb(but->hsv[0], but->hsv[1], but->hsv[2], col, col+1, col+2);
923         ui_set_but_vectorf(but, col);
924 }
925
926 static void update_picker_hex(uiBlock *block, float *rgb)
927 {
928         uiBut *bt;
929         char col[16];
930         
931         sprintf(col, "%02X%02X%02X", (unsigned int)(rgb[0]*255.0), (unsigned int)(rgb[1]*255.0), (unsigned int)(rgb[2]*255.0));
932         
933         // this updates button strings, is hackish... but button pointers are on stack of caller function
934
935         for(bt= block->buttons.first; bt; bt= bt->next) {
936                 if(strcmp(bt->str, "Hex: ")==0) {
937                         strcpy(bt->poin, col);
938                         ui_check_but(bt);
939                         break;
940                 }
941         }
942 }
943
944 void ui_update_block_buts_hsv(uiBlock *block, float *hsv)
945 {
946         uiBut *bt;
947         float r, g, b;
948         float rgb[3];
949         
950         // this updates button strings, is hackish... but button pointers are on stack of caller function
951         hsv_to_rgb(hsv[0], hsv[1], hsv[2], &r, &g, &b);
952         
953         rgb[0] = r; rgb[1] = g; rgb[2] = b;
954         update_picker_hex(block, rgb);
955
956         for(bt= block->buttons.first; bt; bt= bt->next) {
957                 if(bt->type==HSVCUBE) {
958                         VECCOPY(bt->hsv, hsv);
959                         ui_set_but_hsv(bt);
960                 }
961                 else if(bt->str[1]==' ') {
962                         if(bt->str[0]=='R') {
963                                 ui_set_but_val(bt, r);
964                         }
965                         else if(bt->str[0]=='G') {
966                                 ui_set_but_val(bt, g);
967                         }
968                         else if(bt->str[0]=='B') {
969                                 ui_set_but_val(bt, b);
970                         }
971                         else if(bt->str[0]=='H') {
972                                 ui_set_but_val(bt, hsv[0]);
973                         }
974                         else if(bt->str[0]=='S') {
975                                 ui_set_but_val(bt, hsv[1]);
976                         }
977                         else if(bt->str[0]=='V') {
978                                 ui_set_but_val(bt, hsv[2]);
979                         }
980                 }               
981         }
982 }
983
984 static void ui_update_block_buts_hex(uiBlock *block, char *hexcol)
985 {
986         uiBut *bt;
987         float r=0, g=0, b=0;
988         float h, s, v;
989         
990         
991         // this updates button strings, is hackish... but button pointers are on stack of caller function
992         hex_to_rgb(hexcol, &r, &g, &b);
993         rgb_to_hsv(r, g, b, &h, &s, &v);
994
995         for(bt= block->buttons.first; bt; bt= bt->next) {
996                 if(bt->type==HSVCUBE) {
997                         bt->hsv[0] = h;
998                         bt->hsv[1] = s;                 
999                         bt->hsv[2] = v;
1000                         ui_set_but_hsv(bt);
1001                 }
1002                 else if(bt->str[1]==' ') {
1003                         if(bt->str[0]=='R') {
1004                                 ui_set_but_val(bt, r);
1005                         }
1006                         else if(bt->str[0]=='G') {
1007                                 ui_set_but_val(bt, g);
1008                         }
1009                         else if(bt->str[0]=='B') {
1010                                 ui_set_but_val(bt, b);
1011                         }
1012                         else if(bt->str[0]=='H') {
1013                                 ui_set_but_val(bt, h);
1014                         }
1015                         else if(bt->str[0]=='S') {
1016                                 ui_set_but_val(bt, s);
1017                         }
1018                         else if(bt->str[0]=='V') {
1019                                 ui_set_but_val(bt, v);
1020                         }
1021                 }
1022         }
1023 }
1024
1025 /* bt1 is palette but, col1 is original color */
1026 /* callback to copy from/to palette */
1027 static void do_palette_cb(void *bt1, void *col1)
1028 {
1029         uiBut *but1= (uiBut *)bt1;
1030         float *col= (float *)col1;
1031         float *fp, hsv[3];
1032         
1033         fp= (float *)but1->poin;
1034         
1035         /* XXX 2.50 bad access, how to solve?
1036          *
1037         if( (get_qual() & LR_CTRLKEY) ) {
1038                 VECCOPY(fp, col);
1039         }
1040         else*/ {
1041                 VECCOPY(col, fp);
1042         }
1043         
1044         rgb_to_hsv(col[0], col[1], col[2], hsv, hsv+1, hsv+2);
1045         ui_update_block_buts_hsv(but1->block, hsv);
1046         update_picker_hex(but1->block, col);
1047 }
1048
1049 /* bt1 is num but, hsv1 is pointer to original color in hsv space*/
1050 /* callback to handle changes in num-buts in picker */
1051 static void do_palette1_cb(void *bt1, void *hsv1)
1052 {
1053         uiBut *but1= (uiBut *)bt1;
1054         float *hsv= (float *)hsv1;
1055         float *fp= NULL;
1056         
1057         if(but1->str[1]==' ') {
1058                 if(but1->str[0]=='R') fp= (float *)but1->poin;
1059                 else if(but1->str[0]=='G') fp= ((float *)but1->poin)-1;
1060                 else if(but1->str[0]=='B') fp= ((float *)but1->poin)-2;
1061         }
1062         if(fp) {
1063                 rgb_to_hsv(fp[0], fp[1], fp[2], hsv, hsv+1, hsv+2);
1064         } 
1065         ui_update_block_buts_hsv(but1->block, hsv);
1066 }
1067
1068 /* bt1 is num but, col1 is pointer to original color */
1069 /* callback to handle changes in num-buts in picker */
1070 static void do_palette2_cb(void *bt1, void *col1)
1071 {
1072         uiBut *but1= (uiBut *)bt1;
1073         float *rgb= (float *)col1;
1074         float *fp= NULL;
1075         
1076         if(but1->str[1]==' ') {
1077                 if(but1->str[0]=='H') fp= (float *)but1->poin;
1078                 else if(but1->str[0]=='S') fp= ((float *)but1->poin)-1;
1079                 else if(but1->str[0]=='V') fp= ((float *)but1->poin)-2;
1080         }
1081         if(fp) {
1082                 hsv_to_rgb(fp[0], fp[1], fp[2], rgb, rgb+1, rgb+2);
1083         } 
1084         ui_update_block_buts_hsv(but1->block, fp);
1085 }
1086
1087 static void do_palette_hex_cb(void *bt1, void *hexcl)
1088 {
1089         uiBut *but1= (uiBut *)bt1;
1090         char *hexcol= (char *)hexcl;
1091         
1092         ui_update_block_buts_hex(but1->block, hexcol);  
1093 }
1094
1095 /* used for both 3d view and image window */
1096 static void do_palette_sample_cb(void *bt1, void *col1) /* frontbuf */
1097 {
1098         /* XXX 2.50 this should become an operator? */
1099 #if 0
1100         uiBut *but1= (uiBut *)bt1;
1101         uiBut *but;
1102         float tempcol[4];
1103         int x=0, y=0;
1104         short mval[2];
1105         float hsv[3];
1106         short capturing;
1107         int oldcursor;
1108         Window *win;
1109         unsigned short dev;
1110         
1111         oldcursor=get_cursor();
1112         win=winlay_get_active_window();
1113         
1114         while (get_mbut() & L_MOUSE) UI_wait_for_statechange();
1115         
1116         SetBlenderCursor(BC_EYEDROPPER_CURSOR);
1117         
1118         /* loop and wait for a mouse click */
1119         capturing = TRUE;
1120         while(capturing) {
1121                 char ascii;
1122                 short val;
1123                 
1124                 dev = extern_qread_ext(&val, &ascii);
1125                 
1126                 if(dev==INPUTCHANGE) break;
1127                 if(get_mbut() & R_MOUSE) break;
1128                 else if(get_mbut() & L_MOUSE) {
1129                         uiGetMouse(mywinget(), mval);
1130                         x= mval[0]; y= mval[1];
1131                         
1132                         capturing = FALSE;
1133                         break;
1134                 }
1135                 else if(dev==ESCKEY) break;
1136         }
1137         window_set_cursor(win, oldcursor);
1138         
1139         if(capturing) return;
1140         
1141         if(x<0 || y<0) return;
1142         
1143         /* if we've got a glick, use OpenGL to sample the color under the mouse pointer */
1144         glReadBuffer(GL_FRONT);
1145         glReadPixels(x, y, 1, 1, GL_RGBA, GL_FLOAT, tempcol);
1146         glReadBuffer(GL_BACK);
1147         
1148         /* and send that color back to the picker */
1149         rgb_to_hsv(tempcol[0], tempcol[1], tempcol[2], hsv, hsv+1, hsv+2);
1150         ui_update_block_buts_hsv(but1->block, hsv);
1151         update_picker_hex(but1->block, tempcol);
1152         
1153         for (but= but1->block->buttons.first; but; but= but->next) {
1154                 ui_check_but(but);
1155                 ui_draw_but(but);
1156         }
1157         
1158         but= but1->block->buttons.first;
1159         ui_block_flush_back(but->block);
1160 #endif
1161 }
1162
1163 /* color picker, Gimp version. mode: 'f' = floating panel, 'p' =  popup */
1164 /* col = read/write to, hsv/old/hexcol = memory for temporal use */
1165 void uiBlockPickerButtons(uiBlock *block, float *col, float *hsv, float *old, char *hexcol, char mode, short retval)
1166 {
1167         uiBut *bt;
1168         float h, offs;
1169         int a;
1170
1171         VECCOPY(old, col);      // old color stored there, for palette_cb to work
1172         
1173         // the cube intersection
1174         bt= uiDefButF(block, HSVCUBE, retval, "",       0,DPICK+BPICK,FPICK,FPICK, col, 0.0, 0.0, 2, 0, "");
1175         uiButSetFlag(bt, UI_NO_HILITE);
1176
1177         bt= uiDefButF(block, HSVCUBE, retval, "",       0,0,FPICK,BPICK, col, 0.0, 0.0, 3, 0, "");
1178         uiButSetFlag(bt, UI_NO_HILITE);
1179
1180         // palette
1181         
1182         uiBlockSetEmboss(block, UI_EMBOSSP);
1183         
1184         bt=uiDefButF(block, COL, retval, "",            FPICK+DPICK, 0, BPICK,BPICK, old, 0.0, 0.0, -1, 0, "Old color, click to restore");
1185         uiButSetFunc(bt, do_palette_cb, bt, col);
1186         uiDefButF(block, COL, retval, "",               FPICK+DPICK, BPICK+DPICK, BPICK,60-BPICK-DPICK, col, 0.0, 0.0, -1, 0, "Active color");
1187
1188         h= (DPICK+BPICK+FPICK-64)/(UI_PALETTE_TOT/2.0);
1189         uiBlockBeginAlign(block);
1190         for(a= -1+UI_PALETTE_TOT/2; a>=0; a--) {
1191                 bt= uiDefButF(block, COL, retval, "",   FPICK+DPICK, 65.0+(float)a*h, BPICK/2, h, palette[a+UI_PALETTE_TOT/2], 0.0, 0.0, -1, 0, "Click to choose, hold CTRL to store in palette");
1192                 uiButSetFunc(bt, do_palette_cb, bt, col);
1193                 bt= uiDefButF(block, COL, retval, "",   FPICK+DPICK+BPICK/2, 65.0+(float)a*h, BPICK/2, h, palette[a], 0.0, 0.0, -1, 0, "Click to choose, hold CTRL to store in palette");               
1194                 uiButSetFunc(bt, do_palette_cb, bt, col);
1195         }
1196         uiBlockEndAlign(block);
1197         
1198         uiBlockSetEmboss(block, UI_EMBOSS);
1199
1200         // buttons
1201         rgb_to_hsv(col[0], col[1], col[2], hsv, hsv+1, hsv+2);
1202         sprintf(hexcol, "%02X%02X%02X", (unsigned int)(col[0]*255.0), (unsigned int)(col[1]*255.0), (unsigned int)(col[2]*255.0));      
1203
1204         offs= FPICK+2*DPICK+BPICK;
1205
1206         /* note; made this a TOG now, with NULL pointer. Is because BUT now gets handled with a afterfunc */
1207         bt= uiDefIconTextBut(block, TOG, UI_RETURN_OK, ICON_EYEDROPPER, "Sample", offs+55, 170, 85, 20, NULL, 0, 0, 0, 0, "Sample the color underneath the following mouse click (ESC or RMB to cancel)");
1208         uiButSetFunc(bt, do_palette_sample_cb, bt, col);
1209         uiButSetFlag(bt, UI_TEXT_LEFT);
1210         
1211         bt= uiDefBut(block, TEX, retval, "Hex: ", offs, 140, 140, 20, hexcol, 0, 8, 0, 0, "Hex triplet for color (#RRGGBB)");
1212         uiButSetFunc(bt, do_palette_hex_cb, bt, hexcol);
1213
1214         uiBlockBeginAlign(block);
1215         bt= uiDefButF(block, NUMSLI, retval, "R ",      offs, 110, 140,20, col, 0.0, 1.0, 10, 3, "");
1216         uiButSetFunc(bt, do_palette1_cb, bt, hsv);
1217         bt= uiDefButF(block, NUMSLI, retval, "G ",      offs, 90, 140,20, col+1, 0.0, 1.0, 10, 3, "");
1218         uiButSetFunc(bt, do_palette1_cb, bt, hsv);
1219         bt= uiDefButF(block, NUMSLI, retval, "B ",      offs, 70, 140,20, col+2, 0.0, 1.0, 10, 3, "");
1220         uiButSetFunc(bt, do_palette1_cb, bt, hsv);
1221         
1222         uiBlockBeginAlign(block);
1223         bt= uiDefButF(block, NUMSLI, retval, "H ",      offs, 40, 140,20, hsv, 0.0, 1.0, 10, 3, "");
1224         uiButSetFunc(bt, do_palette2_cb, bt, col);
1225         bt= uiDefButF(block, NUMSLI, retval, "S ",      offs, 20, 140,20, hsv+1, 0.0, 1.0, 10, 3, "");
1226         uiButSetFunc(bt, do_palette2_cb, bt, col);
1227         bt= uiDefButF(block, NUMSLI, retval, "V ",      offs, 0, 140,20, hsv+2, 0.0, 1.0, 10, 3, "");
1228         uiButSetFunc(bt, do_palette2_cb, bt, col);
1229         uiBlockEndAlign(block);
1230 }
1231
1232 uiBlock *ui_block_func_COL(bContext *C, uiMenuBlockHandle *handle, void *arg_but)
1233 {
1234         uiBut *but= arg_but;
1235         uiBlock *block;
1236         static float hsvcol[3], oldcol[3];
1237         static char hexcol[128];
1238         
1239         block= uiBeginBlock(C, handle->region, "colorpicker", UI_EMBOSS, UI_HELV);
1240         block->flag= UI_BLOCK_LOOP|UI_BLOCK_REDRAW|UI_BLOCK_KEEP_OPEN;
1241         block->themecol= TH_BUT_NUM;
1242         
1243         VECCOPY(handle->retvec, but->editvec);
1244         uiBlockPickerButtons(block, handle->retvec, hsvcol, oldcol, hexcol, 'p', 0);
1245
1246         /* and lets go */
1247         block->direction= UI_TOP;
1248         uiBoundsBlock(block, 3);
1249         
1250         return block;
1251 }
1252
1253 /* ******************** PUPmenu ****************** */
1254
1255 static int pupmenu_set= 0;
1256
1257 void pupmenu_set_active(int val)
1258 {
1259         pupmenu_set= val;
1260 }
1261
1262 /* value== -1 read, otherwise set */
1263 static int pupmenu_memory(char *str, int value)
1264 {
1265         static char mem[256], first=1;
1266         int val=0, nr=0;
1267         
1268         if(first) {
1269                 memset(mem, 0, 256);
1270                 first= 0;
1271         }
1272         while(str[nr]) {
1273                 val+= str[nr];
1274                 nr++;
1275         }
1276
1277         if(value >= 0) mem[ val & 255 ]= value;
1278         else return mem[ val & 255 ];
1279         
1280         return 0;
1281 }
1282
1283 #define PUP_LABELH      6
1284
1285 typedef struct uiPupMenuInfo {
1286         char *instr;
1287         int mx, my;
1288         int startx, starty;
1289         int maxrow;
1290 } uiPupMenuInfo;
1291
1292 uiBlock *ui_block_func_PUPMENU(bContext *C, uiMenuBlockHandle *handle, void *arg_info)
1293 {
1294         uiBlock *block;
1295         uiPupMenuInfo *info;
1296         int columns, rows, mousemove[2]= {0, 0}, mousewarp= 0;
1297         int width, height, xmax, ymax, maxrow;
1298         int a, startx, starty, endx, endy, x1, y1;
1299         int lastselected;
1300         MenuData *md;
1301
1302         info= arg_info;
1303         maxrow= info->maxrow;
1304         height= 0;
1305
1306         /* block stuff first, need to know the font */
1307         block= uiBeginBlock(C, handle->region, "menu", UI_EMBOSSP, UI_HELV);
1308         uiBlockSetFlag(block, UI_BLOCK_LOOP|UI_BLOCK_REDRAW|UI_BLOCK_RET_1|UI_BLOCK_NUMSELECT);
1309         block->themecol= TH_MENU_ITEM;
1310         
1311         md= decompose_menu_string(info->instr);
1312
1313         rows= md->nitems;
1314         columns= 1;
1315
1316         /* size and location, title slightly bigger for bold */
1317         if(md->title) {
1318                 width= 2*strlen(md->title)+UI_GetStringWidth(uiBlockGetCurFont(block), md->title, ui_translate_buttons());
1319                 width /= columns;
1320         }
1321         else width= 0;
1322
1323         for(a=0; a<md->nitems; a++) {
1324                 xmax= UI_GetStringWidth(uiBlockGetCurFont(block), md->items[a].str, ui_translate_buttons());
1325                 if(xmax>width) width= xmax;
1326
1327                 if(strcmp(md->items[a].str, "%l")==0) height+= PUP_LABELH;
1328                 else height+= MENU_BUTTON_HEIGHT;
1329         }
1330
1331         width+= 10;
1332         if (width<50) width=50;
1333         
1334         wm_window_get_size(C->window, &xmax, &ymax);
1335
1336         /* set first item */
1337         lastselected= 0;
1338         if(pupmenu_set) {
1339                 lastselected= pupmenu_set-1;
1340                 pupmenu_set= 0;
1341         }
1342         else if(md->nitems>1) {
1343                 lastselected= pupmenu_memory(info->instr, -1);
1344         }
1345
1346         startx= info->mx-(0.8*(width));
1347         starty= info->my-height+MENU_BUTTON_HEIGHT/2;
1348         if(lastselected>=0 && lastselected<md->nitems) {
1349                 for(a=0; a<md->nitems; a++) {
1350                         if(a==lastselected) break;
1351                         if( strcmp(md->items[a].str, "%l")==0) starty+= PUP_LABELH;
1352                         else starty+=MENU_BUTTON_HEIGHT;
1353                 }
1354                 
1355                 //starty= info->my-height+MENU_BUTTON_HEIGHT/2+lastselected*MENU_BUTTON_HEIGHT;
1356         }
1357         
1358         if(startx<10) {
1359                 startx= 10;
1360         }
1361         if(starty<10) {
1362                 mousemove[1]= 10-starty;
1363                 starty= 10;
1364         }
1365         
1366         endx= startx+width*columns;
1367         endy= starty+height;
1368
1369         if(endx>xmax) {
1370                 endx= xmax-10;
1371                 startx= endx-width*columns;
1372         }
1373         if(endy>ymax-20) {
1374                 mousemove[1]= ymax-endy-20;
1375                 endy= ymax-20;
1376                 starty= endy-height;
1377         }
1378
1379         if(mousemove[0] || mousemove[1]) {
1380                 ui_warp_pointer(info->mx+mousemove[0], info->my+mousemove[1]);
1381                 mousemove[0]= info->mx;
1382                 mousemove[1]= info->my;
1383                 mousewarp= 1;
1384         }
1385
1386         /* here we go! */
1387         if(md->title) {
1388                 uiBut *bt;
1389                 char titlestr[256];
1390                 uiSetCurFont(block, UI_HELVB);
1391
1392                 if(md->titleicon) {
1393                         width+= 20;
1394                         sprintf(titlestr, " %s", md->title);
1395                         uiDefIconTextBut(block, LABEL, 0, md->titleicon, titlestr, startx, (short)(starty+height), width, MENU_BUTTON_HEIGHT, NULL, 0.0, 0.0, 0, 0, "");
1396                 }
1397                 else {
1398                         bt= uiDefBut(block, LABEL, 0, md->title, startx, (short)(starty+height), columns*width, MENU_BUTTON_HEIGHT, NULL, 0.0, 0.0, 0, 0, "");
1399                         bt->flag= UI_TEXT_LEFT;
1400                 }
1401                 uiSetCurFont(block, UI_HELV);
1402         }
1403
1404         x1= startx + width*((int)a/rows);
1405         y1= starty + height - MENU_BUTTON_HEIGHT;
1406                 
1407         for(a=0; a<md->nitems; a++) {
1408                 char *name= md->items[a].str;
1409                 int icon = md->items[a].icon;
1410
1411                 if(strcmp(name, "%l")==0) {
1412                         uiDefBut(block, SEPR, B_NOP, "", x1, y1, width, PUP_LABELH, NULL, 0, 0.0, 0, 0, "");
1413                         y1 -= PUP_LABELH;
1414                 }
1415                 else if (icon) {
1416                         uiDefIconButF(block, BUTM, B_NOP, icon, x1, y1, width+16, MENU_BUTTON_HEIGHT-1, &handle->retvalue, (float) md->items[a].retval, 0.0, 0, 0, "");
1417                         y1 -= MENU_BUTTON_HEIGHT;
1418                 }
1419                 else {
1420                         uiDefButF(block, BUTM, B_NOP, name, x1, y1, width, MENU_BUTTON_HEIGHT-1, &handle->retvalue, (float) md->items[a].retval, 0.0, 0, 0, "");
1421                         y1 -= MENU_BUTTON_HEIGHT;
1422                 }
1423         }
1424         
1425         uiBoundsBlock(block, 1);
1426         uiEndBlock(C, block);
1427
1428         menudata_free(md);
1429
1430         /* XXX 2.5 need to store last selected */
1431 #if 0
1432         /* calculate last selected */
1433         if(event & ui_return_ok) {
1434                 lastselected= 0;
1435                 for(a=0; a<md->nitems; a++) {
1436                         if(val==md->items[a].retval) lastselected= a;
1437                 }
1438                 
1439                 pupmenu_memory(info->instr, lastselected);
1440         }
1441 #endif
1442         
1443         /* XXX 2.5 need to warp back */
1444 #if 0
1445         if(mousemove[1] && (event & ui_return_out)==0)
1446                 ui_warp_pointer(mousemove[0], mousemove[1]);
1447         return val;
1448 #endif
1449
1450         return block;
1451 }
1452
1453 uiBlock *ui_block_func_PUPMENUCOL(bContext *C, uiMenuBlockHandle *handle, void *arg_info)
1454 {
1455         uiBlock *block;
1456         uiPupMenuInfo *info;
1457         int columns, rows, mousemove[2]= {0, 0}, mousewarp;
1458         int width, height, xmax, ymax, maxrow;
1459         int a, startx, starty, endx, endy, x1, y1;
1460         float fvalue;
1461         MenuData *md;
1462
1463         info= arg_info;
1464         maxrow= info->maxrow;
1465         height= 0;
1466
1467         /* block stuff first, need to know the font */
1468         block= uiBeginBlock(C, handle->region, "menu", UI_EMBOSSP, UI_HELV);
1469         uiBlockSetFlag(block, UI_BLOCK_LOOP|UI_BLOCK_REDRAW|UI_BLOCK_RET_1|UI_BLOCK_NUMSELECT);
1470         block->themecol= TH_MENU_ITEM;
1471         
1472         md= decompose_menu_string(info->instr);
1473
1474         /* columns and row calculation */
1475         columns= (md->nitems+maxrow)/maxrow;
1476         if (columns<1) columns= 1;
1477         
1478         if(columns > 8) {
1479                 maxrow += 5;
1480                 columns= (md->nitems+maxrow)/maxrow;
1481         }
1482         
1483         rows= (int) md->nitems/columns;
1484         if (rows<1) rows= 1;
1485         
1486         while (rows*columns<(md->nitems+columns) ) rows++;
1487
1488         /* size and location, title slightly bigger for bold */
1489         if(md->title) {
1490                 width= 2*strlen(md->title)+UI_GetStringWidth(uiBlockGetCurFont(block), md->title, ui_translate_buttons());
1491                 width /= columns;
1492         }
1493         else width= 0;
1494
1495         for(a=0; a<md->nitems; a++) {
1496                 xmax= UI_GetStringWidth(uiBlockGetCurFont(block), md->items[a].str, ui_translate_buttons());
1497                 if(xmax>width) width= xmax;
1498         }
1499
1500         width+= 10;
1501         if (width<50) width=50;
1502         
1503         height= rows*MENU_BUTTON_HEIGHT;
1504         if (md->title) height+= MENU_BUTTON_HEIGHT;
1505         
1506         wm_window_get_size(C->window, &xmax, &ymax);
1507
1508         /* find active item */
1509         fvalue= handle->retvalue;
1510         for(a=0; a<md->nitems; a++) {
1511                 if( md->items[a].retval== (int)fvalue ) break;
1512         }
1513
1514         /* no active item? */
1515         if(a==md->nitems) {
1516                 if(md->title) a= -1;
1517                 else a= 0;
1518         }
1519
1520         if(a>0)
1521                 startx = info->mx-width/2 - ((int)(a)/rows)*width;
1522         else
1523                 startx= info->mx-width/2;
1524         starty = info->my-height + MENU_BUTTON_HEIGHT/2 + ((a)%rows)*MENU_BUTTON_HEIGHT;
1525
1526         if (md->title) starty+= MENU_BUTTON_HEIGHT;
1527         
1528         if(startx<10) {
1529                 mousemove[0]= 10-startx;
1530                 startx= 10;
1531         }
1532         if(starty<10) {
1533                 mousemove[1]= 10-starty;
1534                 starty= 10;
1535         }
1536         
1537         endx= startx+width*columns;
1538         endy= starty+height;
1539
1540         if(endx>xmax) {
1541                 mousemove[0]= xmax-endx-10;
1542                 endx= xmax-10;
1543                 startx= endx-width*columns;
1544         }
1545         if(endy>ymax) {
1546                 mousemove[1]= ymax-endy-10;
1547                 endy= ymax-10;
1548                 starty= endy-height;
1549         }
1550
1551         if(mousemove[0] || mousemove[1]) {
1552                 ui_warp_pointer(info->mx+mousemove[0], info->my+mousemove[1]);
1553                 mousemove[0]= info->mx;
1554                 mousemove[1]= info->my;
1555                 mousewarp= 1;
1556         }
1557
1558         /* here we go! */
1559         if(md->title) {
1560                 uiBut *bt;
1561                 uiSetCurFont(block, UI_HELVB);
1562
1563                 if(md->titleicon) {
1564                 }
1565                 else {
1566                         bt= uiDefBut(block, LABEL, 0, md->title, startx, (short)(starty+rows*MENU_BUTTON_HEIGHT), columns*width, MENU_BUTTON_HEIGHT, NULL, 0.0, 0.0, 0, 0, "");
1567                         bt->flag= UI_TEXT_LEFT;
1568                 }
1569                 uiSetCurFont(block, UI_HELV);
1570         }
1571
1572         for(a=0; a<md->nitems; a++) {
1573                 char *name= md->items[a].str;
1574                 int icon = md->items[a].icon;
1575
1576                 x1= startx + width*((int)a/rows);
1577                 y1= starty - MENU_BUTTON_HEIGHT*(a%rows) + (rows-1)*MENU_BUTTON_HEIGHT; 
1578                 
1579                 if(strcmp(name, "%l")==0) {
1580                         uiDefBut(block, SEPR, B_NOP, "", x1, y1, width, PUP_LABELH, NULL, 0, 0.0, 0, 0, "");
1581                         y1 -= PUP_LABELH;
1582                 }
1583                 else if (icon) {
1584                         uiDefIconButF(block, BUTM, B_NOP, icon, x1, y1, width+16, MENU_BUTTON_HEIGHT-1, &handle->retvalue, (float) md->items[a].retval, 0.0, 0, 0, "");
1585                         y1 -= MENU_BUTTON_HEIGHT;
1586                 }
1587                 else {
1588                         uiDefButF(block, BUTM, B_NOP, name, x1, y1, width, MENU_BUTTON_HEIGHT-1, &handle->retvalue, (float) md->items[a].retval, 0.0, 0, 0, "");
1589                         y1 -= MENU_BUTTON_HEIGHT;
1590                 }
1591         }
1592         
1593         uiBoundsBlock(block, 1);
1594         uiEndBlock(C, block);
1595
1596 #if 0
1597         event= uiDoBlocks(&listb, 0, 1);
1598 #endif
1599         
1600         menudata_free(md);
1601         
1602         /* XXX 2.5 need to warp back */
1603 #if 0
1604         if((event & UI_RETURN_OUT)==0)
1605                 ui_warp_pointer(mousemove[0], mousemove[1]);
1606 #endif
1607
1608         return block;
1609 }
1610
1611 uiMenuBlockHandle *pupmenu_col(bContext *C, char *instr, int mx, int my, int maxrow)
1612 {
1613         uiPupMenuInfo info;
1614
1615         memset(&info, 0, sizeof(info));
1616         info.instr= instr;
1617         info.mx= mx;
1618         info.my= my;
1619         info.maxrow= maxrow;
1620
1621         return ui_menu_block_create(C, NULL, NULL, ui_block_func_PUPMENUCOL, &info);
1622 }
1623
1624 uiMenuBlockHandle *pupmenu(bContext *C, char *instr, int mx, int my)
1625 {
1626         uiPupMenuInfo info;
1627
1628         memset(&info, 0, sizeof(info));
1629         info.instr= instr;
1630         info.mx= mx;
1631         info.my= my;
1632
1633         return ui_menu_block_create(C, NULL, NULL, ui_block_func_PUPMENU, &info);
1634 }
1635
1636
1637 void pupmenu_free(bContext *C, uiMenuBlockHandle *handle)
1638 {
1639         ui_menu_block_free(C, handle);
1640 }
1641
1642 /*************** Temporary Buttons Tests **********************/
1643
1644 static uiBlock *test_submenu(bContext *C, uiMenuBlockHandle *handle, void *arg)
1645 {
1646         ARegion *ar= handle->region;
1647         uiBlock *block;
1648         short yco= 0, menuwidth=120;
1649         
1650         block= uiBeginBlock(C, ar, "test_viewmenu", UI_EMBOSSP, UI_HELV);
1651         //uiBlockSetButmFunc(block, do_test_viewmenu, NULL);
1652         
1653         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Play Back Animation", 0, yco-=20,
1654                                          menuwidth, 19, NULL, 0.0, 0.0, 1, 2, "");
1655
1656         uiDefBut(block, SEPR, 0, "",        0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
1657         
1658         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Show Seconds|T", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 5, "");
1659         
1660         uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_HLT,
1661                                          "Only Selected Data Keys|", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 12, "");
1662         
1663         uiDefBut(block, SEPR, 0, "",        0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
1664         
1665         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Jump To Next Marker|PageUp", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 6, "");
1666         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Jump To Prev Marker|PageDown", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 7, "");
1667         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Jump To Next Key|Ctrl PageUp", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 8, "");
1668         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Jump To Prev Key|Ctrl PageDown", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 9, "");
1669         
1670         uiDefBut(block, SEPR, 0, "",        0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
1671         
1672         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Center View|C", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 10, "");
1673         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "View All|Home", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 3, "");
1674         uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_HLT,
1675                                          "Lock Time to Other Windows|", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 11, "");
1676         
1677         uiBlockSetDirection(block, UI_RIGHT);
1678
1679         uiTextBoundsBlock(block, 50);
1680         uiEndBlock(C, block);
1681         
1682         return block;
1683 }
1684
1685 static uiBlock *test_viewmenu(bContext *C, uiMenuBlockHandle *handle, void *arg_area)
1686 {
1687         ScrArea *area= arg_area;
1688         ARegion *ar= handle->region;
1689         uiBlock *block;
1690         short yco= 0, menuwidth=120;
1691         
1692         block= uiBeginBlock(C, ar, "test_viewmenu", UI_EMBOSSP, UI_HELV);
1693         //uiBlockSetButmFunc(block, do_test_viewmenu, NULL);
1694         
1695         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Play Back Animation", 0, yco-=20,
1696                                          menuwidth, 19, NULL, 0.0, 0.0, 1, 2, "");
1697
1698         uiDefBut(block, SEPR, 0, "",        0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
1699         
1700         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Show Seconds|T", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 5, "");
1701         
1702         uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_HLT,
1703                                          "Only Selected Data Keys|", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 12, "");
1704         
1705         uiDefBut(block, SEPR, 0, "",        0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
1706         
1707         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Jump To Next Marker|PageUp", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 6, "");
1708         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Jump To Prev Marker|PageDown", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 7, "");
1709         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Jump To Next Key|Ctrl PageUp", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 8, "");
1710         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Jump To Prev Key|Ctrl PageDown", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 9, "");
1711         
1712         uiDefBut(block, SEPR, 0, "",        0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
1713         
1714         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Center View|C", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 10, "");
1715         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "View All|Home", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 3, "");
1716         uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_HLT, 
1717                                          "Lock Time to Other Windows|", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 11, "");
1718
1719         uiDefBut(block, SEPR, 0, "",        0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
1720     uiDefIconTextBlockBut(block, test_submenu, NULL, ICON_RIGHTARROW_THIN, "Sub Menu", 0, yco-=20, 120, 19, "");
1721     uiDefIconTextBlockBut(block, test_submenu, NULL, ICON_RIGHTARROW_THIN, "Sub Menu", 0, yco-=20, 120, 19, "");
1722         uiDefBut(block, SEPR, 0, "",        0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
1723
1724         if(area->headertype==HEADERTOP) {
1725                 uiBlockSetDirection(block, UI_DOWN);
1726         }
1727         else {
1728                 uiBlockSetDirection(block, UI_TOP);
1729                 uiBlockFlipOrder(block);
1730         }
1731
1732         uiTextBoundsBlock(block, 50);
1733         uiEndBlock(C, block);
1734         
1735         return block;
1736 }
1737
1738 void uiTestRegion(const bContext *C)
1739 {
1740         uiBlock *block;
1741         short xco;
1742         
1743         static float testcol[3];
1744         static char testtext[64];
1745         static float testnumf=5.0f;
1746         static short testchoice= 0, testtog= 0, testicontog= 0;
1747
1748 #if 0
1749         static CurveMapping *cumap= NULL;
1750         static ColorBand *coba= NULL;
1751 #endif
1752
1753         block= uiBeginBlock(C, C->region, "header buttons", UI_EMBOSS, UI_HELV);
1754
1755         uiDefPulldownBut(block, test_viewmenu, C->area,  "View",
1756                 13, 1, 50, 24, "");
1757
1758         uiDefBut(block, BUT, 31415, "Type BUT",
1759                 13+50+5, 3, 80, 20, NULL, 0, 0, 0, 0, "A tooltip.");
1760         uiDefButS(block, MENU, 31416, "Gather Method%t|Raytrace %x0|Approximate %x1",
1761                 13+50+5+80+5, 3, 100, 20, &testchoice, 0, 0, 0, 0, "Method for occlusion gathering");
1762         uiDefButBitS(block, TOG, 1, 31417, "Pixel Cache",
1763                 13+50+5+80+5+100+5, 3, 100, 20, &testtog, 0, 0, 0, 0, "Cache AO results in pixels and interpolate over neighbouring pixels for speedup.");
1764
1765         uiDefBut(block, TEX, 31418, "Text: ",
1766                 13+50+5+80+5+100+5+100+5, 3, 200, 20, testtext, 0, sizeof(testtext), 0, 0, "User defined text");
1767
1768         uiDefButF(block, NUMSLI, 31419, "Slider: ",
1769                 13+50+5+80+5+100+5+100+5+200+5, 3, 150, 20, &testnumf, 0.0, 10.0, 0, 0, "Some tooltip.");
1770         uiDefButF(block, NUM, 31419, "N: ",
1771                 13+50+5+80+5+100+5+100+5+200+5+150+5, 3, 100, 20, &testnumf, 0.0, 10.0, 0, 0, "Some tooltip.");
1772
1773     uiDefButF(block, COL, 3142, "",
1774                 13+50+5+80+5+100+5+100+5+200+5+150+5+100+5, 3, 100, 20, testcol, 0, 0, 0, 0 /*B_BANDCOL*/, "");
1775
1776         xco = 13+50+5+80+5+100+5+100+5+200+5+150+5+100+5+100+5;
1777         uiDefIconButBitS(block, ICONTOG, 1 /*AUTOKEY_ON*/, REDRAWINFO, ICON_PYTHON,
1778                         xco, 3, 20, 20, &testicontog, 0, 0, 0, 0, "Automatic keyframe insertion for Objects and Bones");
1779         xco += 5;
1780
1781 #if 0
1782         if(!cumap) {
1783                 cumap= curvemapping_add(4, 0.0f, 0.0f, 1.0f, 1.0f);  
1784                 cumap->flag &= ~CUMA_DO_CLIP;
1785         }
1786         if(!coba)
1787                 coba= add_colorband(0);
1788
1789     uiDefBut(block, BUT_CURVE, 3143, "",
1790                 13+400, 33, 100, 100, cumap, 0.0f, 1.0f, 0, 0, "");
1791     uiDefBut(block, BUT_COLORBAND, 3143, "",
1792                 13+400+100+10, 33, 150, 30, coba, 0.0f, 1.0f, 0, 0, "");
1793 #endif
1794
1795         uiEndBlock(C, block);
1796         uiDrawBlock(block);
1797 }
1798