2 * ***** BEGIN GPL LICENSE BLOCK *****
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.
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.
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.
18 * The Original Code is Copyright (C) 2009 Blender Foundation.
19 * All rights reserved.
21 * Contributor(s): Blender Foundation
23 * ***** END GPL LICENSE BLOCK *****
30 #include "MEM_guardedalloc.h"
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"
41 #include "BLI_blenlib.h"
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"
49 #include "BKE_texture.h"
50 #include "BKE_utildefines.h"
52 #include "RNA_access.h"
54 #include "UI_interface.h"
55 #include "UI_resources.h"
57 #include "ED_screen.h"
63 #include "interface_intern.h"
65 #define DEF_BUT_WIDTH 150
66 #define DEF_ICON_BUT_WIDTH 20
67 #define DEF_BUT_HEIGHT 20
69 /*************************** RNA Utilities ******************************/
71 uiBut *uiDefAutoButR(uiBlock *block, PointerRNA *ptr, PropertyRNA *prop, int index, char *name, int icon, int x1, int y1, int x2, int y2)
74 const char *propname= RNA_property_identifier(prop);
75 int arraylen= RNA_property_array_length(prop);
77 switch(RNA_property_type(prop)) {
81 if(arraylen && index == -1)
84 length= RNA_property_array_length(prop);
87 value= RNA_property_boolean_get_index(ptr, prop, index);
89 value= RNA_property_boolean_get(ptr, prop);
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);
94 but= uiDefIconTextButR(block, ICONTOG, 0, icon, name, x1, y1, x2, y2, ptr, propname, index, 0, 0, -1, -1, NULL);
96 but= uiDefButR(block, OPTION, 0, name, x1, y1, x2, y2, ptr, propname, index, 0, 0, -1, -1, NULL);
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);
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);
108 but= uiDefButR(block, NUM, 0, name, x1, y1, x2, y2, ptr, propname, index, 0, 0, -1, -1, NULL);
111 but= uiDefButR(block, MENU, 0, NULL, x1, y1, x2, y2, ptr, propname, index, 0, 0, -1, -1, NULL);
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);
117 but= uiDefIconTextButR(block, TEX, 0, icon, name, x1, y1, x2, y2, ptr, propname, index, 0, 0, -1, -1, NULL);
119 but= uiDefButR(block, TEX, 0, name, x1, y1, x2, y2, ptr, propname, index, 0, 0, -1, -1, NULL);
125 pptr= RNA_property_pointer_get(ptr, prop);
127 pptr.type= RNA_property_pointer_type(ptr, prop);
128 icon= RNA_struct_ui_icon(pptr.type);
132 but= uiDefIconTextButR(block, IDPOIN, 0, icon, name, x1, y1, x2, y2, ptr, propname, index, 0, 0, -1, -1, NULL);
135 case PROP_COLLECTION: {
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);
150 void uiDefAutoButsRNA(const bContext *C, uiLayout *layout, PointerRNA *ptr, int columns)
152 uiLayout *split, *col;
155 uiItemL(layout, (char*)RNA_struct_ui_name(ptr->type), 0);
157 RNA_STRUCT_BEGIN(ptr, prop) {
158 if(strcmp(RNA_property_identifier(prop), "rna_type") == 0)
161 name= (char*)RNA_property_ui_name(prop);
164 col= uiLayoutColumn(layout, 1);
165 uiItemL(col, name, 0);
167 else if(columns == 2) {
168 split = uiLayoutSplit(layout, 0.5f);
170 uiItemL(uiLayoutColumn(split, 0), name, 0);
171 col= uiLayoutColumn(split, 0);
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);
178 else uiItemFullR(col, "", 0, ptr, prop, -1, 0, 0, 0, 0);
183 /***************************** ID Utilities *******************************/
184 /* note, C code version, will be replaced with version in interface_templates.c */
186 typedef struct uiIDPoinParams {
194 static void idpoin_cb(bContext *C, void *arg_params, void *arg_event)
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);
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)
209 if(id) test_idbutton(id->name+2);
213 /* ID can be NULL, if nothing was assigned yet */
214 if(lb->first==NULL) return;
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, ¶ms->browsenr, do_global_buttons); */
221 if(params->browsenr < 0)
224 for(idtest=lb->first, nr=1; idtest; idtest=idtest->next, nr++) {
225 if(nr==params->browsenr) {
239 case UI_ID_FAKE_USER:
241 if(id->flag & LIB_FAKEUSER) id->us++;
253 if(!id || id->us < 1)
257 if(!id || id->us < 1)
260 case UI_ID_AUTO_NAME:
268 /* ***************************** ID Search browse menu ********************** */
270 static void id_search_call_cb(struct bContext *C, void *arg_params, void *item)
272 uiIDPoinParams *params= (uiIDPoinParams*)arg_params;
274 if(item && params->func)
275 params->func(C, item, UI_ID_BROWSE);
279 static void id_search_cb(const struct bContext *C, void *arg_params, char *str, uiSearchItems *items)
281 uiIDPoinParams *params= (uiIDPoinParams*)arg_params;
284 for(id= params->lb->first; id; id= id->next) {
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);
302 if(BLI_strcasestr(id->name+2, str)) {
303 if(0==uiSearchItemAdd(items, id->name+2, id, iconid))
309 static uiBlock *id_search_menu(bContext *C, ARegion *ar, void *arg_params)
311 static char search[256];
312 static uiIDPoinParams params;
314 wmWindow *win= CTX_wm_window(C);
318 /* clear initial search string, then all items show */
320 /* params is malloced, can be freed by parent button */
321 params= *((uiIDPoinParams*)arg_params);
323 block= uiBeginBlock(C, ar, "_popup", UI_EMBOSS);
324 uiBlockSetFlag(block, UI_BLOCK_LOOP|UI_BLOCK_REDRAW|UI_BLOCK_RET_1);
326 /* fake button, it holds space for search items */
327 uiDefBut(block, LABEL, 0, "", 10, 15, 150, uiSearchBoxhHeight(), NULL, 0, 0, 0, 0, NULL);
329 but= uiDefSearchBut(block, search, 0, ICON_VIEWZOOM, 256, 10, 0, 150, 19, "");
330 uiButSetSearchFunc(but, id_search_cb, ¶ms, id_search_call_cb, NULL);
332 uiBoundsBlock(block, 6);
333 uiBlockSetDirection(block, UI_DOWN);
334 uiEndBlock(C, block);
336 event= *(win->eventstate); /* XXX huh huh? make api call */
337 event.type= EVT_BUT_OPEN;
339 event.customdata= but;
340 event.customdatafree= FALSE;
341 wm_event_add(win, &event);
346 /* ****************** */
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)
351 uiIDPoinParams *params, *dup_params;
353 int len, add_addbutton=0;
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);
359 params->id_code= id_code;
363 uiBlockBeginAlign(block);
367 uiBlockSetCol(block, TH_BUT_SETTING1);
369 if((events & UI_ID_PIN) && *pin_p)
370 uiBlockSetCol(block, TH_BUT_SETTING2);
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;
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;
388 /* text button with name */
392 uiBlockSetCol(block, TH_BUT_SETTING1);
395 if((events & UI_ID_PIN) && *pin_p)
396 uiBlockSetCol(block, TH_BUT_SETTING2);
398 /* redalert overrides pin color
400 uiBlockSetCol(block, TH_REDALERT);
402 uiBlockSetButLock(block, id->lib!=0, "Can't edit external libdata");
405 text_idbutton(id, str1);
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
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));
417 uiBlockClearButLock(block);
419 /* lib make local button */
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.");
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));
428 x+= DEF_ICON_BUT_WIDTH;
431 /* number of users / make local button */
432 if((events & UI_ID_ALONE) && id->us>1) {
435 uiBlockSetButLock(block, (events & UI_ID_PIN) && *pin_p, "Can't make pinned data single-user");
437 sprintf(str1, "%d", id->us);
438 butwidth= (id->us<10)? DEF_ICON_BUT_WIDTH: DEF_ICON_BUT_WIDTH+10;
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));
444 uiBlockClearButLock(block);
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);
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;
457 uiBlockClearButLock(block);
460 /* auto name button */
461 if(events & UI_ID_AUTO_NAME) {
462 if(parid && parid->lib);
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;
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;
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));
486 uiBlockEndAlign(block);
493 /* ****************************** default button callbacks ******************* */
494 /* ************ LEGACY WARNING, only to get things work with 2.48 code! ****** */
496 void test_idbutton_cb(struct bContext *C, void *namev, void *arg2)
500 test_idbutton(name+2);
504 void test_scriptpoin_but(struct bContext *C, char *name, ID **idpp)
508 id= CTX_data_main(C)->text.first;
510 if( strcmp(name, id->name+2)==0 ) {
519 void test_actionpoin_but(struct bContext *C, char *name, ID **idpp)
523 id= CTX_data_main(C)->action.first;
525 if( strcmp(name, id->name+2)==0 ) {
536 void test_obpoin_but(struct bContext *C, char *name, ID **idpp)
540 // XXX if(idpp == (ID **)&(emptytex.object)) {
541 // error("You must add a texture first");
546 id= CTX_data_main(C)->object.first;
548 if( strcmp(name, id->name+2)==0 ) {
550 id_lib_extern(id); /* checks lib data, sets correct flag for saving then */
558 /* tests for an object of type OB_MESH */
559 void test_meshobpoin_but(struct bContext *C, char *name, ID **idpp)
563 id = CTX_data_main(C)->object.first;
565 Object *ob = (Object *)id;
566 if(ob->type == OB_MESH && strcmp(name, id->name + 2) == 0) {
568 /* checks lib data, sets correct flag for saving then */
577 void test_meshpoin_but(struct bContext *C, char *name, ID **idpp)
581 if( *idpp ) (*idpp)->us--;
583 id= CTX_data_main(C)->mesh.first;
585 if( strcmp(name, id->name+2)==0 ) {
595 void test_matpoin_but(struct bContext *C, char *name, ID **idpp)
599 if( *idpp ) (*idpp)->us--;
601 id= CTX_data_main(C)->mat.first;
603 if( strcmp(name, id->name+2)==0 ) {
613 void test_scenepoin_but(struct bContext *C, char *name, ID **idpp)
617 if( *idpp ) (*idpp)->us--;
619 id= CTX_data_main(C)->scene.first;
621 if( strcmp(name, id->name+2)==0 ) {
631 void test_grouppoin_but(struct bContext *C, char *name, ID **idpp)
635 if( *idpp ) (*idpp)->us--;
637 id= CTX_data_main(C)->group.first;
639 if( strcmp(name, id->name+2)==0 ) {
649 void test_texpoin_but(struct bContext *C, char *name, ID **idpp)
653 if( *idpp ) (*idpp)->us--;
655 id= CTX_data_main(C)->tex.first;
657 if( strcmp(name, id->name+2)==0 ) {
667 void test_imapoin_but(struct bContext *C, char *name, ID **idpp)
671 if( *idpp ) (*idpp)->us--;
673 id= CTX_data_main(C)->image.first;
675 if( strcmp(name, id->name+2)==0 ) {
685 /* autocomplete callback for buttons */
686 void autocomplete_bone(struct bContext *C, char *str, void *arg_v)
688 Object *ob= (Object *)arg_v;
690 if(ob==NULL || ob->pose==NULL) return;
692 /* search if str matches the beginning of name */
694 AutoComplete *autocpl= autocomplete_begin(str, 32);
697 for(pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next)
698 autocomplete_do_name(autocpl, pchan->name);
700 autocomplete_end(autocpl, str);
704 /* autocomplete callback for buttons */
705 void autocomplete_vgroup(struct bContext *C, char *str, void *arg_v)
707 Object *ob= (Object *)arg_v;
711 /* search if str matches the beginning of a name */
713 AutoComplete *autocpl= autocomplete_begin(str, 32);
716 for(dg= ob->defbase.first; dg; dg= dg->next)
718 autocomplete_do_name(autocpl, dg->name);
720 autocomplete_end(autocpl, str);
725 /* ----------- custom button group ---------------------- */
727 static void curvemap_buttons_zoom_in(bContext *C, void *cumap_v, void *unused)
729 CurveMapping *cumap = cumap_v;
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;
743 static void curvemap_buttons_zoom_out(bContext *C, void *cumap_v, void *unused)
745 CurveMapping *cumap = cumap_v;
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);
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;
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;
763 d= d1= 0.15f*(cumap->curr.ymax - cumap->curr.ymin);
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;
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;
778 static void curvemap_buttons_setclip(bContext *C, void *cumap_v, void *unused)
780 CurveMapping *cumap = cumap_v;
782 curvemapping_changed(cumap, 0);
785 static void curvemap_buttons_delete(bContext *C, void *cumap_v, void *unused)
787 CurveMapping *cumap = cumap_v;
789 curvemap_remove(cumap->cm+cumap->cur, SELECT);
790 curvemapping_changed(cumap, 0);
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)
796 CurveMapping *cumap = cumap_v;
800 block= uiBeginBlock(C, ar, "curvemap_clipping_func", UI_EMBOSS);
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, "");
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);
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, "");
815 uiBlockSetDirection(block, UI_RIGHT);
817 uiEndBlock(C, block);
822 static void curvemap_tools_dofunc(bContext *C, void *cumap_v, int event)
824 CurveMapping *cumap = cumap_v;
825 CurveMap *cuma= cumap->cm+cumap->cur;
829 curvemap_reset(cuma, &cumap->clipr);
830 curvemapping_changed(cumap, 0);
833 cumap->curr= cumap->clipr;
835 case 2: /* set vector */
836 curvemap_sethandle(cuma, 1);
837 curvemapping_changed(cumap, 0);
839 case 3: /* set auto */
840 curvemap_sethandle(cuma, 0);
841 curvemapping_changed(cumap, 0);
843 case 4: /* extend horiz */
844 cuma->flag &= ~CUMA_EXTEND_EXTRAPOLATE;
845 curvemapping_changed(cumap, 0);
847 case 5: /* extend extrapolate */
848 cuma->flag |= CUMA_EXTEND_EXTRAPOLATE;
849 curvemapping_changed(cumap, 0);
852 ED_region_tag_redraw(CTX_wm_region(C));
855 static uiBlock *curvemap_tools_func(struct bContext *C, struct ARegion *ar, void *cumap_v)
858 short yco= 0, menuwidth=120;
860 block= uiBeginBlock(C, ar, "curvemap_tools_func", UI_EMBOSS);
861 uiBlockSetButmFunc(block, curvemap_tools_dofunc, cumap_v);
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, "");
870 uiBlockSetDirection(block, UI_RIGHT);
871 uiTextBoundsBlock(block, 50);
873 uiEndBlock(C, block);
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)
881 float dx, fy= rect->ymax-18.0f;
885 yco= (short)(rect->ymax-18.0f);
887 /* curve choice options + tools/settings, 8 icons + spacer */
888 dx= (rect->xmax-rect->xmin)/(9.0f);
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, "");
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, "");
916 /* else no channels ! */
917 uiBlockEndAlign(block);
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);
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);
928 xco= (short)(rect->xmin+6.0f*dx);
929 bt= uiDefIconBlockBut(block, curvemap_tools_func, cumap, event, ICON_MODIFIER, xco, yco, dx, 18, "Tools");
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");
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);
939 uiBlockSetEmboss(block, UI_EMBOSS);
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, "");
948 static int vergcband(const void *a1, const void *a2)
950 const CBData *x1=a1, *x2=a2;
952 if( x1->pos > x2->pos ) return 1;
953 else if( x1->pos < x2->pos) return -1;
957 static void colorband_pos_cb(bContext *C, void *coba_v, void *unused_v)
959 ColorBand *coba= coba_v;
962 if(coba->tot<2) return;
964 for(a=0; a<coba->tot; a++) coba->data[a].cur= a;
965 qsort(coba->data, coba->tot, sizeof(CBData), vergcband);
966 for(a=0; a<coba->tot; a++) {
967 if(coba->data[a].cur==coba->cur) {
968 // XXX if(coba->cur!=a) addqueue(curarea->win, REDRAW, 0); /* button cur */
975 static void colorband_add_cb(bContext *C, void *coba_v, void *unused_v)
977 ColorBand *coba= coba_v;
979 if(coba->tot < MAXCOLORBAND-1) coba->tot++;
980 coba->cur= coba->tot-1;
982 colorband_pos_cb(C, coba, NULL);
983 ED_undo_push(C, "Add colorband");
986 static void colorband_del_cb(bContext *C, void *coba_v, void *unused_v)
988 ColorBand *coba= coba_v;
991 if(coba->tot<2) return;
993 for(a=coba->cur; a<coba->tot; a++) {
994 coba->data[a]= coba->data[a+1];
996 if(coba->cur) coba->cur--;
999 ED_undo_push(C, "Delete colorband");
1000 // XXX BIF_preview_changed(ID_TE);
1004 /* offset aligns from bottom, standard width 300, height 115 */
1005 static void colorband_buttons_large(uiBlock *block, ColorBand *coba, int xoffs, int yoffs, int redraw)
1010 if(coba==NULL) return;
1012 bt= uiDefBut(block, BUT, redraw, "Add", 80+xoffs,95+yoffs,37,20, 0, 0, 0, 0, 0, "Adds a new color position to the colorband");
1013 uiButSetFunc(bt, colorband_add_cb, coba, NULL);
1014 uiDefButS(block, NUM, redraw, "Cur:", 117+xoffs,95+yoffs,81,20, &coba->cur, 0.0, (float)(coba->tot-1), 0, 0, "Displays the active color from the colorband");
1015 bt= uiDefBut(block, BUT, redraw, "Del", 199+xoffs,95+yoffs,37,20, 0, 0, 0, 0, 0, "Deletes the active position");
1016 uiButSetFunc(bt, colorband_del_cb, coba, NULL);
1018 uiDefButS(block, MENU, redraw, "Interpolation %t|Ease %x1|Cardinal %x3|Linear %x0|B-Spline %x2|Constant %x4",
1019 236+xoffs, 95+yoffs, 64, 20, &coba->ipotype, 0.0, 0.0, 0, 0, "Sets interpolation type");
1021 uiDefBut(block, BUT_COLORBAND, redraw, "", xoffs,65+yoffs,300,30, coba, 0, 0, 0, 0, "");
1023 cbd= coba->data + coba->cur;
1025 uiBlockBeginAlign(block);
1026 bt= uiDefButF(block, NUM, redraw, "Pos", xoffs,40+yoffs,110,20, &cbd->pos, 0.0, 1.0, 10, 0, "Sets the position of the active color");
1027 uiButSetFunc(bt, colorband_pos_cb, coba, NULL);
1028 uiDefButF(block, COL, redraw, "", xoffs,20+yoffs,110,20, &(cbd->r), 0, 0, 0, B_BANDCOL, "");
1029 uiDefButF(block, NUMSLI, redraw, "A ", xoffs,yoffs,110,20, &cbd->a, 0.0, 1.0, 10, 0, "Sets the alpha value for this position");
1031 uiBlockBeginAlign(block);
1032 uiDefButF(block, NUMSLI, redraw, "R ", 115+xoffs,40+yoffs,185,20, &cbd->r, 0.0, 1.0, B_BANDCOL, 0, "Sets the red value for the active color");
1033 uiDefButF(block, NUMSLI, redraw, "G ", 115+xoffs,20+yoffs,185,20, &cbd->g, 0.0, 1.0, B_BANDCOL, 0, "Sets the green value for the active color");
1034 uiDefButF(block, NUMSLI, redraw, "B ", 115+xoffs,yoffs,185,20, &cbd->b, 0.0, 1.0, B_BANDCOL, 0, "Sets the blue value for the active color");
1035 uiBlockEndAlign(block);
1038 static void colorband_buttons_small(uiBlock *block, ColorBand *coba, rctf *butr, int event)
1042 float unit= (butr->xmax-butr->xmin)/14.0f;
1043 float xs= butr->xmin;
1045 cbd= coba->data + coba->cur;
1047 uiBlockBeginAlign(block);
1048 uiDefButF(block, COL, event, "", xs,butr->ymin+20.0f,2.0f*unit,20, &(cbd->r), 0, 0, 0, B_BANDCOL, "");
1049 uiDefButF(block, NUM, event, "A:", xs+2.0f*unit,butr->ymin+20.0f,4.0f*unit,20, &(cbd->a), 0.0f, 1.0f, 10, 2, "");
1050 bt= uiDefBut(block, BUT, event, "Add", xs+6.0f*unit,butr->ymin+20.0f,2.0f*unit,20, NULL, 0, 0, 0, 0, "Adds a new color position to the colorband");
1051 uiButSetFunc(bt, colorband_add_cb, coba, NULL);
1052 bt= uiDefBut(block, BUT, event, "Del", xs+8.0f*unit,butr->ymin+20.0f,2.0f*unit,20, NULL, 0, 0, 0, 0, "Deletes the active position");
1053 uiButSetFunc(bt, colorband_del_cb, coba, NULL);
1055 uiDefButS(block, MENU, event, "Interpolation %t|Ease %x1|Cardinal %x3|Linear %x0|B-Spline %x2|Constant %x4",
1056 xs+10.0f*unit, butr->ymin+20.0f, unit*4, 20, &coba->ipotype, 0.0, 0.0, 0, 0, "Sets interpolation type");
1058 uiDefBut(block, BUT_COLORBAND, event, "", xs,butr->ymin,butr->xmax-butr->xmin,20.0f, coba, 0, 0, 0, 0, "");
1059 uiBlockEndAlign(block);
1063 void colorband_buttons(uiBlock *block, ColorBand *coba, rctf *butr, int small)
1066 colorband_buttons_small(block, coba, butr, 0);
1068 colorband_buttons_large(block, coba, 0, 0, 0);