Undo revision 23130 which was a merge with 2.5, a messy one because I did something...
[blender.git] / source / blender / editors / interface / interface_utils.c
1 /**
2  * ***** BEGIN GPL LICENSE BLOCK *****
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version. 
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software Foundation,
16  * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
17  *
18  * The Original Code is Copyright (C) 2009 Blender Foundation.
19  * All rights reserved.
20  * 
21  * Contributor(s): Blender Foundation
22  *
23  * ***** END GPL LICENSE BLOCK *****
24  */
25
26 #include <math.h>
27 #include <stdlib.h>
28 #include <string.h>
29
30 #include "MEM_guardedalloc.h"
31
32 #include "DNA_action_types.h"
33 #include "DNA_color_types.h"
34 #include "DNA_listBase.h"
35 #include "DNA_material_types.h"
36 #include "DNA_object_types.h"
37 #include "DNA_screen_types.h"
38 #include "DNA_texture_types.h"
39 #include "DNA_windowmanager_types.h"
40
41 #include "BLI_blenlib.h"
42
43 #include "BKE_colortools.h"
44 #include "BKE_context.h"
45 #include "BKE_idprop.h"
46 #include "BKE_icons.h"
47 #include "BKE_library.h"
48 #include "BKE_main.h"
49 #include "BKE_texture.h"
50 #include "BKE_utildefines.h"
51
52 #include "RNA_access.h"
53
54 #include "UI_interface.h"
55 #include "UI_resources.h"
56
57 #include "ED_screen.h"
58 #include "ED_util.h"
59
60 #include "WM_api.h"
61 #include "WM_types.h"
62
63 #include "interface_intern.h"
64
65 #define DEF_BUT_WIDTH           150
66 #define DEF_ICON_BUT_WIDTH      20
67 #define DEF_BUT_HEIGHT          20
68
69 /*************************** RNA Utilities ******************************/
70
71 uiBut *uiDefAutoButR(uiBlock *block, PointerRNA *ptr, PropertyRNA *prop, int index, char *name, int icon, int x1, int y1, int x2, int y2)
72 {
73         uiBut *but=NULL;
74         const char *propname= RNA_property_identifier(prop);
75         int arraylen= RNA_property_array_length(prop);
76
77         switch(RNA_property_type(prop)) {
78                 case PROP_BOOLEAN: {
79                         int value, length;
80
81                         if(arraylen && index == -1)
82                                 return NULL;
83
84                         length= RNA_property_array_length(prop);
85
86                         if(length)
87                                 value= RNA_property_boolean_get_index(ptr, prop, index);
88                         else
89                                 value= RNA_property_boolean_get(ptr, prop);
90
91                         if(icon && name && strcmp(name, "") == 0)
92                                 but= uiDefIconButR(block, ICONTOG, 0, icon, x1, y1, x2, y2, ptr, propname, index, 0, 0, -1, -1, NULL);
93                         else if(icon)
94                                 but= uiDefIconTextButR(block, ICONTOG, 0, icon, name, x1, y1, x2, y2, ptr, propname, index, 0, 0, -1, -1, NULL);
95                         else
96                                 but= uiDefButR(block, OPTION, 0, name, x1, y1, x2, y2, ptr, propname, index, 0, 0, -1, -1, NULL);
97                         break;
98                 }
99                 case PROP_INT:
100                 case PROP_FLOAT:
101                         if(arraylen && index == -1) {
102                                 if(RNA_property_subtype(prop) == PROP_COLOR)
103                                         but= uiDefButR(block, COL, 0, name, x1, y1, x2, y2, ptr, propname, 0, 0, 0, -1, -1, NULL);
104                         }
105                         else if(RNA_property_subtype(prop) == PROP_PERCENTAGE)
106                                 but= uiDefButR(block, NUMSLI, 0, name, x1, y1, x2, y2, ptr, propname, index, 0, 0, -1, -1, NULL);
107                         else
108                                 but= uiDefButR(block, NUM, 0, name, x1, y1, x2, y2, ptr, propname, index, 0, 0, -1, -1, NULL);
109                         break;
110                 case PROP_ENUM:
111                         but= uiDefButR(block, MENU, 0, NULL, x1, y1, x2, y2, ptr, propname, index, 0, 0, -1, -1, NULL);
112                         break;
113                 case PROP_STRING:
114                         if(icon && name && strcmp(name, "") == 0)
115                                 but= uiDefIconButR(block, TEX, 0, icon, x1, y1, x2, y2, ptr, propname, index, 0, 0, -1, -1, NULL);
116                         else if(icon)
117                                 but= uiDefIconTextButR(block, TEX, 0, icon, name, x1, y1, x2, y2, ptr, propname, index, 0, 0, -1, -1, NULL);
118                         else
119                                 but= uiDefButR(block, TEX, 0, name, x1, y1, x2, y2, ptr, propname, index, 0, 0, -1, -1, NULL);
120                         break;
121                 case PROP_POINTER: {
122                         PointerRNA pptr;
123                         int icon;
124
125                         pptr= RNA_property_pointer_get(ptr, prop);
126                         if(!pptr.type)
127                                 pptr.type= RNA_property_pointer_type(ptr, prop);
128                         icon= RNA_struct_ui_icon(pptr.type);
129                         if(icon == ICON_DOT)
130                                 icon= 0;
131
132                         but= uiDefIconTextButR(block, IDPOIN, 0, icon, name, x1, y1, x2, y2, ptr, propname, index, 0, 0, -1, -1, NULL);
133                         break;
134                 }
135                 case PROP_COLLECTION: {
136                         char text[256];
137                         sprintf(text, "%d items", RNA_property_collection_length(ptr, prop));
138                         but= uiDefBut(block, LABEL, 0, text, x1, y1, x2, y2, NULL, 0, 0, 0, 0, NULL);
139                         uiButSetFlag(but, UI_BUT_DISABLED);
140                         break;
141                 }
142                 default:
143                         but= NULL;
144                         break;
145         }
146
147         return but;
148 }
149
150 void uiDefAutoButsRNA(const bContext *C, uiLayout *layout, PointerRNA *ptr, int columns)
151 {
152         uiLayout *split, *col;
153         char *name;
154
155         RNA_STRUCT_BEGIN(ptr, prop) {
156                 if(strcmp(RNA_property_identifier(prop), "rna_type") == 0)
157                         continue;
158
159                 name= (char*)RNA_property_ui_name(prop);
160
161                 if(columns == 1) {
162                         col= uiLayoutColumn(layout, 1);
163                         uiItemL(col, name, 0);
164                 }
165                 else if(columns == 2) {
166                         split = uiLayoutSplit(layout, 0.5f);
167
168                         uiItemL(uiLayoutColumn(split, 0), name, 0);
169                         col= uiLayoutColumn(split, 0);
170                 }
171                 else
172                         col= NULL;
173
174                 /* temp hack to show normal button for spin/screw */
175                 if(strcmp(name, "Axis")==0) {
176                         uiDefButR(uiLayoutGetBlock(col), BUT_NORMAL, 0, name, 0, 0, 100, 100, ptr, "axis", -1, 0, 0, -1, -1, NULL);
177                 }
178                 else uiItemFullR(col, "", 0, ptr, prop, -1, 0, 0, 0, 0);
179         }
180         RNA_STRUCT_END;
181 }
182
183 /***************************** ID Utilities *******************************/
184 /* note, C code version, will be replaced with version in interface_templates.c */
185
186 typedef struct uiIDPoinParams {
187         uiIDPoinFunc func;
188         ListBase *lb;
189         ID *id;
190         short id_code;
191         short browsenr;
192 } uiIDPoinParams;
193
194 static void idpoin_cb(bContext *C, void *arg_params, void *arg_event)
195 {
196         uiIDPoinParams *params= (uiIDPoinParams*)arg_params;
197         ListBase *lb= params->lb;
198         uiIDPoinFunc func= params->func;
199         ID *id= params->id, *idtest;
200         int nr, event= GET_INT_FROM_POINTER(arg_event);
201
202         if(event == UI_ID_BROWSE && params->browsenr == 32767)
203                 event= UI_ID_ADD_NEW;
204         else if(event == UI_ID_BROWSE && params->browsenr == 32766)
205                 event= UI_ID_OPEN;
206
207         switch(event) {
208                 case UI_ID_RENAME:
209                         if(id) test_idbutton(id->name+2);
210                         else return;
211                         break;
212                 case UI_ID_BROWSE: {
213                         /* ID can be NULL, if nothing was assigned yet */
214                         if(lb->first==NULL) return;
215
216                         if(params->browsenr== -2) {
217                                 /* XXX implement or find a replacement (ID can be NULL!)
218                                  * activate_databrowse((ID *)G.buts->lockpoin, GS(id->name), 0, B_MESHBROWSE, &params->browsenr, do_global_buttons); */
219                                 return;
220                         }
221                         if(params->browsenr < 0)
222                                 return;
223
224                         for(idtest=lb->first, nr=1; idtest; idtest=idtest->next, nr++) {
225                                 if(nr==params->browsenr) {
226                                         if(id == idtest)
227                                                 return;
228
229                                         id= idtest;
230
231                                         break;
232                                 }
233                         }
234                         break;
235                 }
236                 case UI_ID_DELETE:
237                         id= NULL;
238                         break;
239                 case UI_ID_FAKE_USER:
240                         if(id) {
241                                 if(id->flag & LIB_FAKEUSER) id->us++;
242                                 else id->us--;
243                         }
244                         else return;
245                         break;
246                 case UI_ID_PIN:
247                         break;
248                 case UI_ID_ADD_NEW:
249                         break;
250                 case UI_ID_OPEN:
251                         break;
252                 case UI_ID_ALONE:
253                         if(!id || id->us < 1)
254                                 return;
255                         break;
256                 case UI_ID_LOCAL:
257                         if(!id || id->us < 1)
258                                 return;
259                         break;
260                 case UI_ID_AUTO_NAME:
261                         break;
262         }
263
264         if(func)
265                 func(C, id, event);
266 }
267
268 /* ***************************** ID Search browse menu ********************** */
269
270 static void id_search_call_cb(struct bContext *C, void *arg_params, void *item)
271 {
272         uiIDPoinParams *params= (uiIDPoinParams*)arg_params;
273
274         if(item && params->func)
275                 params->func(C, item, UI_ID_BROWSE);
276
277 }
278
279 static void id_search_cb(const struct bContext *C, void *arg_params, char *str, uiSearchItems *items)
280 {
281         uiIDPoinParams *params= (uiIDPoinParams*)arg_params;
282         ID *id;
283         
284         for(id= params->lb->first; id; id= id->next) {
285                 int iconid= 0;
286                 
287                 
288                 /* icon */
289                 switch(GS(id->name))
290                 {
291                         case ID_MA: /* fall through */
292                         case ID_TE: /* fall through */
293                         case ID_IM: /* fall through */
294                         case ID_WO: /* fall through */
295                         case ID_LA: /* fall through */
296                                 iconid= BKE_icon_getid(id);
297                                 break;
298                         default:
299                                 break;
300                 }
301                 
302                 if(BLI_strcasestr(id->name+2, str)) {
303                         if(0==uiSearchItemAdd(items, id->name+2, id, iconid))
304                                 break;
305                 }
306         }
307 }
308
309 static uiBlock *id_search_menu(bContext *C, ARegion *ar, void *arg_params)
310 {
311         static char search[256];
312         static uiIDPoinParams params;
313         wmEvent event;
314         wmWindow *win= CTX_wm_window(C);
315         uiBlock *block;
316         uiBut *but;
317         
318         /* clear initial search string, then all items show */
319         search[0]= 0;
320         /* params is malloced, can be freed by parent button */
321         params= *((uiIDPoinParams*)arg_params);
322         
323         block= uiBeginBlock(C, ar, "_popup", UI_EMBOSS);
324         uiBlockSetFlag(block, UI_BLOCK_LOOP|UI_BLOCK_REDRAW|UI_BLOCK_RET_1);
325         
326         /* fake button, it holds space for search items */
327         uiDefBut(block, LABEL, 0, "", 10, 15, 150, uiSearchBoxhHeight(), NULL, 0, 0, 0, 0, NULL);
328         
329         but= uiDefSearchBut(block, search, 0, ICON_VIEWZOOM, 256, 10, 0, 150, 19, "");
330         uiButSetSearchFunc(but, id_search_cb, &params, id_search_call_cb, NULL);
331         
332         uiBoundsBlock(block, 6);
333         uiBlockSetDirection(block, UI_DOWN);    
334         uiEndBlock(C, block);
335         
336         event= *(win->eventstate);      /* XXX huh huh? make api call */
337         event.type= EVT_BUT_OPEN;
338         event.val= KM_PRESS;
339         event.customdata= but;
340         event.customdatafree= FALSE;
341         wm_event_add(win, &event);
342         
343         return block;
344 }
345
346 /* ****************** */
347
348 int uiDefIDPoinButs(uiBlock *block, Main *bmain, ID *parid, ID *id, int id_code, short *pin_p, int x, int y, uiIDPoinFunc func, int events)
349 {
350         uiBut *but;
351         uiIDPoinParams *params, *dup_params;
352         char str1[10];
353         int len, add_addbutton=0;
354
355         /* setup struct that we will pass on with the buttons */
356         params= MEM_callocN(sizeof(uiIDPoinParams), "uiIDPoinParams");
357         params->lb= wich_libbase(bmain, id_code);
358         params->id= id;
359         params->id_code= id_code;
360         params->func= func;
361
362         /* create buttons */
363         uiBlockBeginAlign(block);
364
365         /* XXX solve?
366         if(id && id->us>1)
367                 uiBlockSetCol(block, TH_BUT_SETTING1);
368
369         if((events & UI_ID_PIN) && *pin_p)
370                 uiBlockSetCol(block, TH_BUT_SETTING2);
371         */
372         
373         /* pin button */
374         if(id && (events & UI_ID_PIN)) {
375                 but= uiDefIconButS(block, ICONTOG, (events & UI_ID_PIN), ICON_KEY_DEHLT, x, y ,DEF_ICON_BUT_WIDTH,DEF_BUT_HEIGHT, pin_p, 0, 0, 0, 0, "Keeps this view displaying the current data regardless of what object is selected");
376                 uiButSetNFunc(but, idpoin_cb, MEM_dupallocN(params), SET_INT_IN_POINTER(UI_ID_PIN));
377                 x+= DEF_ICON_BUT_WIDTH;
378         }
379
380         /* browse menu */
381         if(events & UI_ID_BROWSE) {
382                 uiDefBlockButN(block, id_search_menu, MEM_dupallocN(params), "", x, y, DEF_ICON_BUT_WIDTH, DEF_BUT_HEIGHT, "Browse ID data");
383                 x+= DEF_ICON_BUT_WIDTH;
384         }
385         
386         
387
388         /* text button with name */
389         if(id) {
390                 /* XXX solve?
391                 if(id->us > 1)
392                         uiBlockSetCol(block, TH_BUT_SETTING1);
393                 */
394                 /* pinned data? 
395                 if((events & UI_ID_PIN) && *pin_p)
396                         uiBlockSetCol(block, TH_BUT_SETTING2);
397                 */
398                 /* redalert overrides pin color 
399                 if(id->us<=0)
400                         uiBlockSetCol(block, TH_REDALERT);
401                 */
402                 uiBlockSetButLock(block, id->lib!=0, "Can't edit external libdata");
403                 
404                 /* name button */
405                 text_idbutton(id, str1);
406                 
407                 if(GS(id->name)==ID_IP) len= 110;
408                 else if((y) && (GS(id->name)==ID_AC)) len= 100; // comes from button panel (poselib)
409                 else if(y) len= 140;    // comes from button panel
410                 else len= 120;
411                 
412                 but= uiDefBut(block, TEX, 0, str1,x, y, (short)len, DEF_BUT_HEIGHT, id->name+2, 0.0, 21.0, 0, 0, "Displays current Datablock name. Click to change.");
413                 uiButSetNFunc(but, idpoin_cb, MEM_dupallocN(params), SET_INT_IN_POINTER(UI_ID_RENAME));
414
415                 x+= len;
416
417                 uiBlockClearButLock(block);
418                 
419                 /* lib make local button */
420                 if(id->lib) {
421                         if(id->flag & LIB_INDIRECT) uiDefIconBut(block, BUT, 0, 0 /* XXX ICON_DATALIB */,x,y,DEF_ICON_BUT_WIDTH,DEF_BUT_HEIGHT, 0, 0, 0, 0, 0, "Indirect Library Datablock. Cannot change.");
422                         else {
423                                 but= uiDefIconBut(block, BUT, 0, 0 /* XXX ICON_PARLIB */, x,y,DEF_ICON_BUT_WIDTH,DEF_BUT_HEIGHT, 0, 0, 0, 0, 0, 
424                                                           (events & UI_ID_LOCAL)? "Direct linked Library Datablock. Click to make local.": "Direct linked Library Datablock, cannot make local.");
425                                 uiButSetNFunc(but, idpoin_cb, MEM_dupallocN(params), SET_INT_IN_POINTER(UI_ID_ALONE));
426                         }
427                         
428                         x+= DEF_ICON_BUT_WIDTH;
429                 }
430                 
431                 /* number of users / make local button */
432                 if((events & UI_ID_ALONE) && id->us>1) {
433                         int butwidth;
434
435                         uiBlockSetButLock(block, (events & UI_ID_PIN) && *pin_p, "Can't make pinned data single-user");
436                         
437                         sprintf(str1, "%d", id->us);
438                         butwidth= (id->us<10)? DEF_ICON_BUT_WIDTH: DEF_ICON_BUT_WIDTH+10;
439
440                         but= uiDefBut(block, BUT, 0, str1, x, y, butwidth, DEF_BUT_HEIGHT, 0, 0, 0, 0, 0, "Displays number of users of this data. Click to make a single-user copy.");
441                         uiButSetNFunc(but, idpoin_cb, MEM_dupallocN(params), SET_INT_IN_POINTER(UI_ID_ALONE));
442                         x+= butwidth;
443                         
444                         uiBlockClearButLock(block);
445                 }
446                 
447                 /* delete button */
448                 if(events & UI_ID_DELETE) {
449                         uiBlockSetButLock(block, (events & UI_ID_PIN) && *pin_p, "Can't unlink pinned data");
450                         if(parid && parid->lib);
451                         else {
452                                 but= uiDefIconBut(block, BUT, 0, ICON_X, x,y,DEF_ICON_BUT_WIDTH,DEF_BUT_HEIGHT, 0, 0, 0, 0, 0, "Deletes link to this Datablock");
453                                 uiButSetNFunc(but, idpoin_cb, MEM_dupallocN(params), SET_INT_IN_POINTER(UI_ID_DELETE));
454                                 x+= DEF_ICON_BUT_WIDTH;
455                         }
456                         
457                         uiBlockClearButLock(block);
458                 }
459
460                 /* auto name button */
461                 if(events & UI_ID_AUTO_NAME) {
462                         if(parid && parid->lib);
463                         else {
464                                 but= uiDefIconBut(block, BUT, 0, ICON_AUTO,x,y,DEF_ICON_BUT_WIDTH,DEF_BUT_HEIGHT, 0, 0, 0, 0, 0, "Generates an automatic name");
465                                 uiButSetNFunc(but, idpoin_cb, MEM_dupallocN(params), SET_INT_IN_POINTER(UI_ID_AUTO_NAME));
466                                 x+= DEF_ICON_BUT_WIDTH;
467                         }
468                 }
469
470                 /* fake user button */
471                 if(events & UI_ID_FAKE_USER) {
472                         but= uiDefButBitS(block, TOG, LIB_FAKEUSER, 0, "F", x,y,DEF_ICON_BUT_WIDTH,DEF_BUT_HEIGHT, &id->flag, 0, 0, 0, 0, "Saves this datablock even if it has no users");
473                         uiButSetNFunc(but, idpoin_cb, MEM_dupallocN(params), SET_INT_IN_POINTER(UI_ID_FAKE_USER));
474                         x+= DEF_ICON_BUT_WIDTH;
475                 }
476         }
477         /* add new button */
478         else if(add_addbutton) {
479                 if(parid) uiBlockSetButLock(block, parid->lib!=0, "Can't edit external libdata");
480                 dup_params= MEM_dupallocN(params);
481                 but= uiDefButS(block, TOG, 0, "Add New", x, y, 110, DEF_BUT_HEIGHT, &dup_params->browsenr, params->browsenr, 32767.0, 0, 0, "Add new data block");
482                 uiButSetNFunc(but, idpoin_cb, dup_params, SET_INT_IN_POINTER(UI_ID_ADD_NEW));
483                 x+= 110;
484         }
485         
486         uiBlockEndAlign(block);
487
488         MEM_freeN(params);
489
490         return x;
491 }
492
493 /* ****************************** default button callbacks ******************* */
494 /* ************ LEGACY WARNING, only to get things work with 2.48 code! ****** */
495
496 void test_idbutton_cb(struct bContext *C, void *namev, void *arg2)
497 {
498         char *name= namev;
499         
500         test_idbutton(name+2);
501 }
502
503
504 void test_scriptpoin_but(struct bContext *C, char *name, ID **idpp)
505 {
506         ID *id;
507         
508         id= CTX_data_main(C)->text.first;
509         while(id) {
510                 if( strcmp(name, id->name+2)==0 ) {
511                         *idpp= id;
512                         return;
513                 }
514                 id= id->next;
515         }
516         *idpp= NULL;
517 }
518
519 void test_actionpoin_but(struct bContext *C, char *name, ID **idpp)
520 {
521         ID *id;
522         
523         id= CTX_data_main(C)->action.first;
524         while(id) {
525                 if( strcmp(name, id->name+2)==0 ) {
526                         id_us_plus(id);
527                         *idpp= id;
528                         return;
529                 }
530                 id= id->next;
531         }
532         *idpp= NULL;
533 }
534
535
536 void test_obpoin_but(struct bContext *C, char *name, ID **idpp)
537 {
538         ID *id;
539         
540 // XXX  if(idpp == (ID **)&(emptytex.object)) {
541 //              error("You must add a texture first");
542 //              *idpp= 0;
543 //              return;
544 //      }
545         
546         id= CTX_data_main(C)->object.first;
547         while(id) {
548                 if( strcmp(name, id->name+2)==0 ) {
549                         *idpp= id;
550                         id_lib_extern(id);      /* checks lib data, sets correct flag for saving then */
551                         return;
552                 }
553                 id= id->next;
554         }
555         *idpp= NULL;
556 }
557
558 /* tests for an object of type OB_MESH */
559 void test_meshobpoin_but(struct bContext *C, char *name, ID **idpp)
560 {
561         ID *id;
562
563         id = CTX_data_main(C)->object.first;
564         while(id) {
565                 Object *ob = (Object *)id;
566                 if(ob->type == OB_MESH && strcmp(name, id->name + 2) == 0) {
567                         *idpp = id;
568                         /* checks lib data, sets correct flag for saving then */
569                         id_lib_extern(id);
570                         return;
571                 }
572                 id = id->next;
573         }
574         *idpp = NULL;
575 }
576
577 void test_meshpoin_but(struct bContext *C, char *name, ID **idpp)
578 {
579         ID *id;
580
581         if( *idpp ) (*idpp)->us--;
582         
583         id= CTX_data_main(C)->mesh.first;
584         while(id) {
585                 if( strcmp(name, id->name+2)==0 ) {
586                         *idpp= id;
587                         id_us_plus(id);
588                         return;
589                 }
590                 id= id->next;
591         }
592         *idpp= NULL;
593 }
594
595 void test_matpoin_but(struct bContext *C, char *name, ID **idpp)
596 {
597         ID *id;
598
599         if( *idpp ) (*idpp)->us--;
600         
601         id= CTX_data_main(C)->mat.first;
602         while(id) {
603                 if( strcmp(name, id->name+2)==0 ) {
604                         *idpp= id;
605                         id_us_plus(id);
606                         return;
607                 }
608                 id= id->next;
609         }
610         *idpp= NULL;
611 }
612
613 void test_scenepoin_but(struct bContext *C, char *name, ID **idpp)
614 {
615         ID *id;
616         
617         if( *idpp ) (*idpp)->us--;
618         
619         id= CTX_data_main(C)->scene.first;
620         while(id) {
621                 if( strcmp(name, id->name+2)==0 ) {
622                         *idpp= id;
623                         id_us_plus(id);
624                         return;
625                 }
626                 id= id->next;
627         }
628         *idpp= NULL;
629 }
630
631 void test_grouppoin_but(struct bContext *C, char *name, ID **idpp)
632 {
633         ID *id;
634         
635         if( *idpp ) (*idpp)->us--;
636         
637         id= CTX_data_main(C)->group.first;
638         while(id) {
639                 if( strcmp(name, id->name+2)==0 ) {
640                         *idpp= id;
641                         id_us_plus(id);
642                         return;
643                 }
644                 id= id->next;
645         }
646         *idpp= NULL;
647 }
648
649 void test_texpoin_but(struct bContext *C, char *name, ID **idpp)
650 {
651         ID *id;
652         
653         if( *idpp ) (*idpp)->us--;
654         
655         id= CTX_data_main(C)->tex.first;
656         while(id) {
657                 if( strcmp(name, id->name+2)==0 ) {
658                         *idpp= id;
659                         id_us_plus(id);
660                         return;
661                 }
662                 id= id->next;
663         }
664         *idpp= NULL;
665 }
666
667 void test_imapoin_but(struct bContext *C, char *name, ID **idpp)
668 {
669         ID *id;
670         
671         if( *idpp ) (*idpp)->us--;
672         
673         id= CTX_data_main(C)->image.first;
674         while(id) {
675                 if( strcmp(name, id->name+2)==0 ) {
676                         *idpp= id;
677                         id_us_plus(id);
678                         return;
679                 }
680                 id= id->next;
681         }
682         *idpp= NULL;
683 }
684
685 /* autocomplete callback for  buttons */
686 void autocomplete_bone(struct bContext *C, char *str, void *arg_v)
687 {
688         Object *ob= (Object *)arg_v;
689         
690         if(ob==NULL || ob->pose==NULL) return;
691         
692         /* search if str matches the beginning of name */
693         if(str[0]) {
694                 AutoComplete *autocpl= autocomplete_begin(str, 32);
695                 bPoseChannel *pchan;
696                 
697                 for(pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next)
698                         autocomplete_do_name(autocpl, pchan->name);
699                 
700                 autocomplete_end(autocpl, str);
701         }
702 }
703
704 /* autocomplete callback for buttons */
705 void autocomplete_vgroup(struct bContext *C, char *str, void *arg_v)
706 {
707         Object *ob= (Object *)arg_v;
708         
709         if(ob==NULL) return;
710         
711         /* search if str matches the beginning of a name */
712         if(str[0]) {
713                 AutoComplete *autocpl= autocomplete_begin(str, 32);
714                 bDeformGroup *dg;
715                 
716                 for(dg= ob->defbase.first; dg; dg= dg->next)
717                         if(dg->name!=str)
718                                 autocomplete_do_name(autocpl, dg->name);
719                 
720                 autocomplete_end(autocpl, str);
721         }
722 }
723
724
725 /* ----------- custom button group ---------------------- */
726
727 static void curvemap_buttons_zoom_in(bContext *C, void *cumap_v, void *unused)
728 {
729         CurveMapping *cumap = cumap_v;
730         float d;
731         
732         /* we allow 20 times zoom */
733         if( (cumap->curr.xmax - cumap->curr.xmin) > 0.04f*(cumap->clipr.xmax - cumap->clipr.xmin) ) {
734                 d= 0.1154f*(cumap->curr.xmax - cumap->curr.xmin);
735                 cumap->curr.xmin+= d;
736                 cumap->curr.xmax-= d;
737                 d= 0.1154f*(cumap->curr.ymax - cumap->curr.ymin);
738                 cumap->curr.ymin+= d;
739                 cumap->curr.ymax-= d;
740         }
741 }
742
743 static void curvemap_buttons_zoom_out(bContext *C, void *cumap_v, void *unused)
744 {
745         CurveMapping *cumap = cumap_v;
746         float d, d1;
747         
748         /* we allow 20 times zoom, but dont view outside clip */
749         if( (cumap->curr.xmax - cumap->curr.xmin) < 20.0f*(cumap->clipr.xmax - cumap->clipr.xmin) ) {
750                 d= d1= 0.15f*(cumap->curr.xmax - cumap->curr.xmin);
751                 
752                 if(cumap->flag & CUMA_DO_CLIP) 
753                         if(cumap->curr.xmin-d < cumap->clipr.xmin)
754                                 d1= cumap->curr.xmin - cumap->clipr.xmin;
755                 cumap->curr.xmin-= d1;
756                 
757                 d1= d;
758                 if(cumap->flag & CUMA_DO_CLIP) 
759                         if(cumap->curr.xmax+d > cumap->clipr.xmax)
760                                 d1= -cumap->curr.xmax + cumap->clipr.xmax;
761                 cumap->curr.xmax+= d1;
762                 
763                 d= d1= 0.15f*(cumap->curr.ymax - cumap->curr.ymin);
764                 
765                 if(cumap->flag & CUMA_DO_CLIP) 
766                         if(cumap->curr.ymin-d < cumap->clipr.ymin)
767                                 d1= cumap->curr.ymin - cumap->clipr.ymin;
768                 cumap->curr.ymin-= d1;
769                 
770                 d1= d;
771                 if(cumap->flag & CUMA_DO_CLIP) 
772                         if(cumap->curr.ymax+d > cumap->clipr.ymax)
773                                 d1= -cumap->curr.ymax + cumap->clipr.ymax;
774                 cumap->curr.ymax+= d1;
775         }
776 }
777
778 static void curvemap_buttons_setclip(bContext *C, void *cumap_v, void *unused)
779 {
780         CurveMapping *cumap = cumap_v;
781         
782         curvemapping_changed(cumap, 0);
783 }       
784
785 static void curvemap_buttons_delete(bContext *C, void *cumap_v, void *unused)
786 {
787         CurveMapping *cumap = cumap_v;
788         
789         curvemap_remove(cumap->cm+cumap->cur, SELECT);
790         curvemapping_changed(cumap, 0);
791 }
792
793 /* NOTE: this is a block-menu, needs 0 events, otherwise the menu closes */
794 static uiBlock *curvemap_clipping_func(struct bContext *C, struct ARegion *ar, void *cumap_v)
795 {
796         CurveMapping *cumap = cumap_v;
797         uiBlock *block;
798         uiBut *bt;
799         
800         block= uiBeginBlock(C, ar, "curvemap_clipping_func", UI_EMBOSS);
801         
802         /* use this for a fake extra empy space around the buttons */
803         uiDefBut(block, LABEL, 0, "",                   -4, 16, 128, 106, NULL, 0, 0, 0, 0, "");
804         
805         bt= uiDefButBitI(block, TOG, CUMA_DO_CLIP, 1, "Use Clipping",    
806                                                                                 0,100,120,18, &cumap->flag, 0.0, 0.0, 10, 0, "");
807         uiButSetFunc(bt, curvemap_buttons_setclip, cumap, NULL);
808
809         uiBlockBeginAlign(block);
810         uiDefButF(block, NUM, 0, "Min X ",       0,74,120,18, &cumap->clipr.xmin, -100.0, cumap->clipr.xmax, 10, 0, "");
811         uiDefButF(block, NUM, 0, "Min Y ",       0,56,120,18, &cumap->clipr.ymin, -100.0, cumap->clipr.ymax, 10, 0, "");
812         uiDefButF(block, NUM, 0, "Max X ",       0,38,120,18, &cumap->clipr.xmax, cumap->clipr.xmin, 100.0, 10, 0, "");
813         uiDefButF(block, NUM, 0, "Max Y ",       0,20,120,18, &cumap->clipr.ymax, cumap->clipr.ymin, 100.0, 10, 0, "");
814         
815         uiBlockSetDirection(block, UI_RIGHT);
816         
817         uiEndBlock(C, block);
818         return block;
819 }
820
821
822 static void curvemap_tools_dofunc(bContext *C, void *cumap_v, int event)
823 {
824         CurveMapping *cumap = cumap_v;
825         CurveMap *cuma= cumap->cm+cumap->cur;
826         
827         switch(event) {
828                 case 0:
829                         curvemap_reset(cuma, &cumap->clipr);
830                         curvemapping_changed(cumap, 0);
831                         break;
832                 case 1:
833                         cumap->curr= cumap->clipr;
834                         break;
835                 case 2: /* set vector */
836                         curvemap_sethandle(cuma, 1);
837                         curvemapping_changed(cumap, 0);
838                         break;
839                 case 3: /* set auto */
840                         curvemap_sethandle(cuma, 0);
841                         curvemapping_changed(cumap, 0);
842                         break;
843                 case 4: /* extend horiz */
844                         cuma->flag &= ~CUMA_EXTEND_EXTRAPOLATE;
845                         curvemapping_changed(cumap, 0);
846                         break;
847                 case 5: /* extend extrapolate */
848                         cuma->flag |= CUMA_EXTEND_EXTRAPOLATE;
849                         curvemapping_changed(cumap, 0);
850                         break;
851         }
852         ED_region_tag_redraw(CTX_wm_region(C));
853 }
854
855 static uiBlock *curvemap_tools_func(struct bContext *C, struct ARegion *ar, void *cumap_v)
856 {
857         uiBlock *block;
858         short yco= 0, menuwidth=120;
859         
860         block= uiBeginBlock(C, ar, "curvemap_tools_func", UI_EMBOSS);
861         uiBlockSetButmFunc(block, curvemap_tools_dofunc, cumap_v);
862         
863         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Reset View",                             0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 1, "");
864         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Vector Handle",                  0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 2, "");
865         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Auto Handle",                    0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 3, "");
866         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Extend Horizontal",              0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 4, "");
867         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Extend Extrapolated",    0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 5, "");
868         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Reset Curve",                    0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 0, "");
869         
870         uiBlockSetDirection(block, UI_RIGHT);
871         uiTextBoundsBlock(block, 50);
872         
873         uiEndBlock(C, block);
874         return block;
875 }
876
877 /* still unsure how this call evolves... we use labeltype for defining what curve-channels to show */
878 void curvemap_buttons(uiBlock *block, CurveMapping *cumap, char labeltype, short event, short redraw, rctf *rect)
879 {
880         uiBut *bt;
881         float dx, fy= rect->ymax-18.0f;
882         int icon;
883         short xco, yco;
884         
885         yco= (short)(rect->ymax-18.0f);
886         
887         /* curve choice options + tools/settings, 8 icons + spacer */
888         dx= (rect->xmax-rect->xmin)/(9.0f);
889         
890         uiBlockBeginAlign(block);
891         if(labeltype=='v') {    /* vector */
892                 xco= (short)rect->xmin;
893                 if(cumap->cm[0].curve)
894                         uiDefButI(block, ROW, redraw, "X", xco, yco+2, dx, 16, &cumap->cur, 0.0, 0.0, 0.0, 0.0, "");
895                 xco= (short)(rect->xmin+1.0f*dx);
896                 if(cumap->cm[1].curve)
897                         uiDefButI(block, ROW, redraw, "Y", xco, yco+2, dx, 16, &cumap->cur, 0.0, 1.0, 0.0, 0.0, "");
898                 xco= (short)(rect->xmin+2.0f*dx);
899                 if(cumap->cm[2].curve)
900                         uiDefButI(block, ROW, redraw, "Z", xco, yco+2, dx, 16, &cumap->cur, 0.0, 2.0, 0.0, 0.0, "");
901         }
902         else if(labeltype=='c') { /* color */
903                 xco= (short)rect->xmin;
904                 if(cumap->cm[3].curve)
905                         uiDefButI(block, ROW, redraw, "C", xco, yco+2, dx, 16, &cumap->cur, 0.0, 3.0, 0.0, 0.0, "");
906                 xco= (short)(rect->xmin+1.0f*dx);
907                 if(cumap->cm[0].curve)
908                         uiDefButI(block, ROW, redraw, "R", xco, yco+2, dx, 16, &cumap->cur, 0.0, 0.0, 0.0, 0.0, "");
909                 xco= (short)(rect->xmin+2.0f*dx);
910                 if(cumap->cm[1].curve)
911                         uiDefButI(block, ROW, redraw, "G", xco, yco+2, dx, 16, &cumap->cur, 0.0, 1.0, 0.0, 0.0, "");
912                 xco= (short)(rect->xmin+3.0f*dx);
913                 if(cumap->cm[2].curve)
914                         uiDefButI(block, ROW, redraw, "B", xco, yco+2, dx, 16, &cumap->cur, 0.0, 2.0, 0.0, 0.0, "");
915         }
916         /* else no channels ! */
917         uiBlockEndAlign(block);
918
919         xco= (short)(rect->xmin+4.5f*dx);
920         uiBlockSetEmboss(block, UI_EMBOSSN);
921         bt= uiDefIconBut(block, BUT, redraw, ICON_ZOOMIN, xco, yco, dx, 14, NULL, 0.0, 0.0, 0.0, 0.0, "Zoom in");
922         uiButSetFunc(bt, curvemap_buttons_zoom_in, cumap, NULL);
923         
924         xco= (short)(rect->xmin+5.25f*dx);
925         bt= uiDefIconBut(block, BUT, redraw, ICON_ZOOMOUT, xco, yco, dx, 14, NULL, 0.0, 0.0, 0.0, 0.0, "Zoom out");
926         uiButSetFunc(bt, curvemap_buttons_zoom_out, cumap, NULL);
927         
928         xco= (short)(rect->xmin+6.0f*dx);
929         bt= uiDefIconBlockBut(block, curvemap_tools_func, cumap, event, ICON_MODIFIER, xco, yco, dx, 18, "Tools");
930         
931         xco= (short)(rect->xmin+7.0f*dx);
932         if(cumap->flag & CUMA_DO_CLIP) icon= ICON_CLIPUV_HLT; else icon= ICON_CLIPUV_DEHLT;
933         bt= uiDefIconBlockBut(block, curvemap_clipping_func, cumap, event, icon, xco, yco, dx, 18, "Clipping Options");
934         
935         xco= (short)(rect->xmin+8.0f*dx);
936         bt= uiDefIconBut(block, BUT, event, ICON_X, xco, yco, dx, 18, NULL, 0.0, 0.0, 0.0, 0.0, "Delete points");
937         uiButSetFunc(bt, curvemap_buttons_delete, cumap, NULL);
938         
939         uiBlockSetEmboss(block, UI_EMBOSS);
940         
941         uiDefBut(block, BUT_CURVE, event, "", 
942                           rect->xmin, rect->ymin, rect->xmax-rect->xmin, fy-rect->ymin, 
943                           cumap, 0.0f, 1.0f, 0, 0, "");
944 }
945
946 /* still unsure how this call evolves... we use labeltype for defining what curve-channels to show */
947 void curvemap_layout(uiLayout *layout, CurveMapping *cumap, char labeltype, short event, short redraw, rctf *rect)
948 {
949         uiLayout *row;
950         uiBlock *block;
951         uiBut *bt;
952         float dx, fy= rect->ymax-18.0f;
953         int icon;
954         
955         block= uiLayoutGetBlock(layout);
956         
957         /* curve choice options + tools/settings, 8 icons + spacer */
958         dx= UI_UNIT_X;
959         
960         row= uiLayoutRow(layout, 0);
961         uiLayoutSetAlignment(row, UI_LAYOUT_ALIGN_RIGHT);
962
963         if(labeltype=='v') {    /* vector */
964                 row= uiLayoutRow(layout, 1);
965
966                 if(cumap->cm[0].curve)
967                         uiDefButI(block, ROW, redraw, "X", 0, 0, dx, 16, &cumap->cur, 0.0, 0.0, 0.0, 0.0, "");
968                 if(cumap->cm[1].curve)
969                         uiDefButI(block, ROW, redraw, "Y", 0, 0, dx, 16, &cumap->cur, 0.0, 1.0, 0.0, 0.0, "");
970                 if(cumap->cm[2].curve)
971                         uiDefButI(block, ROW, redraw, "Z", 0, 0, dx, 16, &cumap->cur, 0.0, 2.0, 0.0, 0.0, "");
972         }
973         else if(labeltype=='c') { /* color */
974                 row= uiLayoutRow(layout, 1);
975
976                 if(cumap->cm[3].curve)
977                         uiDefButI(block, ROW, redraw, "C", 0, 0, dx, 16, &cumap->cur, 0.0, 3.0, 0.0, 0.0, "");
978                 if(cumap->cm[0].curve)
979                         uiDefButI(block, ROW, redraw, "R", 0, 0, dx, 16, &cumap->cur, 0.0, 0.0, 0.0, 0.0, "");
980                 if(cumap->cm[1].curve)
981                         uiDefButI(block, ROW, redraw, "G", 0, 0, dx, 16, &cumap->cur, 0.0, 1.0, 0.0, 0.0, "");
982                 if(cumap->cm[2].curve)
983                         uiDefButI(block, ROW, redraw, "B", 0, 0, dx, 16, &cumap->cur, 0.0, 2.0, 0.0, 0.0, "");
984         }
985
986         row= uiLayoutRow(row, 1);
987
988         uiBlockSetEmboss(block, UI_EMBOSSN);
989         bt= uiDefIconBut(block, BUT, redraw, ICON_ZOOMIN, 0, 0, dx, 14, NULL, 0.0, 0.0, 0.0, 0.0, "Zoom in");
990         uiButSetFunc(bt, curvemap_buttons_zoom_in, cumap, NULL);
991         
992         bt= uiDefIconBut(block, BUT, redraw, ICON_ZOOMOUT, 0, 0, dx, 14, NULL, 0.0, 0.0, 0.0, 0.0, "Zoom out");
993         uiButSetFunc(bt, curvemap_buttons_zoom_out, cumap, NULL);
994         
995         bt= uiDefIconBlockBut(block, curvemap_tools_func, cumap, event, ICON_MODIFIER, 0, 0, dx, 18, "Tools");
996         
997         if(cumap->flag & CUMA_DO_CLIP) icon= ICON_CLIPUV_HLT; else icon= ICON_CLIPUV_DEHLT;
998         bt= uiDefIconBlockBut(block, curvemap_clipping_func, cumap, event, icon, 0, 0, dx, 18, "Clipping Options");
999         
1000         bt= uiDefIconBut(block, BUT, event, ICON_X, 0, 0, dx, 18, NULL, 0.0, 0.0, 0.0, 0.0, "Delete points");
1001         uiButSetFunc(bt, curvemap_buttons_delete, cumap, NULL);
1002         
1003         uiBlockSetEmboss(block, UI_EMBOSS);
1004         
1005         row= uiLayoutRow(layout, 0);
1006         uiDefBut(block, BUT_CURVE, event, "", 
1007                           rect->xmin, rect->ymin, rect->xmax-rect->xmin, fy-rect->ymin, 
1008                           cumap, 0.0f, 1.0f, 0, 0, "");
1009 }
1010
1011
1012 #define B_BANDCOL 1
1013
1014 static int vergcband(const void *a1, const void *a2)
1015 {
1016         const CBData *x1=a1, *x2=a2;
1017
1018         if( x1->pos > x2->pos ) return 1;
1019         else if( x1->pos < x2->pos) return -1;
1020         return 0;
1021 }
1022
1023 static void colorband_pos_cb(bContext *C, void *coba_v, void *unused_v)
1024 {
1025         ColorBand *coba= coba_v;
1026         int a;
1027         
1028         if(coba->tot<2) return;
1029         
1030         for(a=0; a<coba->tot; a++) coba->data[a].cur= a;
1031         qsort(coba->data, coba->tot, sizeof(CBData), vergcband);
1032         for(a=0; a<coba->tot; a++) {
1033                 if(coba->data[a].cur==coba->cur) {
1034                         // XXX if(coba->cur!=a) addqueue(curarea->win, REDRAW, 0);      /* button cur */
1035                         coba->cur= a;
1036                         break;
1037                 }
1038         }
1039
1040         WM_event_add_notifier(C, NC_TEXTURE, NULL);
1041 }
1042
1043 static void colorband_cb(bContext *C, void *coba_v, void *unused_v)
1044 {
1045         WM_event_add_notifier(C, NC_TEXTURE, NULL);
1046 }
1047
1048 static void colorband_add_cb(bContext *C, void *coba_v, void *unused_v)
1049 {
1050         ColorBand *coba= coba_v;
1051         
1052         if(coba->tot < MAXCOLORBAND-1) coba->tot++;
1053         coba->cur= coba->tot-1;
1054         
1055         colorband_pos_cb(C, coba, NULL);
1056         ED_undo_push(C, "Add colorband");
1057         WM_event_add_notifier(C, NC_TEXTURE, NULL);
1058 }
1059
1060 static void colorband_del_cb(bContext *C, void *coba_v, void *unused_v)
1061 {
1062         ColorBand *coba= coba_v;
1063         int a;
1064         
1065         if(coba->tot<2) return;
1066         
1067         for(a=coba->cur; a<coba->tot; a++) {
1068                 coba->data[a]= coba->data[a+1];
1069         }
1070         if(coba->cur) coba->cur--;
1071         coba->tot--;
1072         
1073         ED_undo_push(C, "Delete colorband");
1074         // XXX BIF_preview_changed(ID_TE);
1075         WM_event_add_notifier(C, NC_TEXTURE, NULL);
1076 }
1077
1078
1079 /* offset aligns from bottom, standard width 300, height 115 */
1080 static void colorband_buttons_large(uiBlock *block, ColorBand *coba, int xoffs, int yoffs, int redraw)
1081 {
1082         CBData *cbd;
1083         uiBut *bt;
1084         
1085         if(coba==NULL) return;
1086         
1087         bt= uiDefBut(block, BUT, redraw,        "Add",                  0+xoffs,100+yoffs,50,20, 0, 0, 0, 0, 0, "Add a new color stop to the colorband");
1088         uiButSetFunc(bt, colorband_add_cb, coba, NULL);
1089         bt= uiDefBut(block, BUT, redraw,        "Delete",               60+xoffs,100+yoffs,50,20, 0, 0, 0, 0, 0, "Delete the active position");
1090         uiDefButS(block, NUM, redraw,           "",                             120+xoffs,100+yoffs,80, 20, &coba->cur, 0.0, (float)(coba->tot-1), 0, 0, "Choose active color stop");
1091         
1092         uiButSetFunc(bt, colorband_del_cb, coba, NULL);
1093         
1094         bt= uiDefButS(block, MENU, redraw,              "Interpolation %t|Ease %x1|Cardinal %x3|Linear %x0|B-Spline %x2|Constant %x4",
1095                 210+xoffs, 100+yoffs, 90, 20,           &coba->ipotype, 0.0, 0.0, 0, 0, "Set interpolation between color stops");
1096         uiButSetFunc(bt, colorband_cb, coba, NULL);
1097         uiBlockEndAlign(block);
1098
1099         bt= uiDefBut(block, BUT_COLORBAND, redraw, "",  xoffs,65+yoffs,300,30, coba, 0, 0, 0, 0, "");
1100         uiButSetFunc(bt, colorband_cb, coba, NULL);
1101         
1102         cbd= coba->data + coba->cur;
1103         
1104         bt= uiDefButF(block, NUM, redraw, "Pos:",                       0+xoffs,40+yoffs,100, 20, &cbd->pos, 0.0, 1.0, 10, 0, "The position of the active color stop");
1105         uiButSetFunc(bt, colorband_pos_cb, coba, NULL);
1106         bt= uiDefButF(block, COL, redraw,               "",                             110+xoffs,40+yoffs,80,20, &(cbd->r), 0, 0, 0, B_BANDCOL, "The color value for the active color stop");
1107         uiButSetFunc(bt, colorband_cb, coba, NULL);
1108         bt= uiDefButF(block, NUMSLI, redraw,    "A ",                   200+xoffs,40+yoffs,100,20, &cbd->a, 0.0, 1.0, 10, 0, "The alpha value of the active color stop");
1109         uiButSetFunc(bt, colorband_cb, coba, NULL);
1110
1111 }
1112
1113 static void colorband_buttons_small(uiBlock *block, ColorBand *coba, rctf *butr, int event)
1114 {
1115         CBData *cbd;
1116         uiBut *bt;
1117         float unit= (butr->xmax-butr->xmin)/14.0f;
1118         float xs= butr->xmin;
1119         
1120         cbd= coba->data + coba->cur;
1121         
1122         
1123         bt= uiDefBut(block, BUT, event, "Add",                  xs,butr->ymin+20.0f,2.0f*unit,20,       NULL, 0, 0, 0, 0, "Add a new color stop to the colorband");
1124         uiButSetFunc(bt, colorband_add_cb, coba, NULL);
1125         bt= uiDefBut(block, BUT, event, "Delete",               xs+2.0f*unit,butr->ymin+20.0f,2.0f*unit,20,     NULL, 0, 0, 0, 0, "Delete the active position");
1126         uiButSetFunc(bt, colorband_del_cb, coba, NULL);
1127         
1128         uiDefButF(block, COL, event,            "",                     xs+4.0f*unit,butr->ymin+20.0f,2.0f*unit,20,                             &(cbd->r), 0, 0, 0, B_BANDCOL, "The color value for the active color stop");
1129         uiDefButF(block, NUMSLI, event,         "A:",           xs+6.0f*unit,butr->ymin+20.0f,4.0f*unit,20,     &(cbd->a), 0.0f, 1.0f, 10, 2, "The alpha value of the active color stop");
1130         
1131         uiDefButS(block, MENU, event,           "Interpolation %t|Ease %x1|Cardinal %x3|Linear %x0|B-Spline %x2|Constant %x4",
1132                 xs+10.0f*unit, butr->ymin+20.0f, unit*4, 20,            &coba->ipotype, 0.0, 0.0, 0, 0, "Set interpolation between color stops");
1133
1134         uiDefBut(block, BUT_COLORBAND, event, "",               xs,butr->ymin,butr->xmax-butr->xmin,20.0f, coba, 0, 0, 0, 0, "");
1135         uiBlockEndAlign(block);
1136 }
1137
1138 void colorband_buttons(uiBlock *block, ColorBand *coba, rctf *butr, int small)
1139 {
1140         if(small)
1141                 colorband_buttons_small(block, coba, butr, 0);
1142         else
1143                 colorband_buttons_large(block, coba, 0, 0, 0);
1144 }
1145