[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [20592] branches/blender2.5/blender/source /blender/editors: UI:
Brecht Van Lommel
brecht at blender.org
Wed Jun 3 02:14:14 CEST 2009
Revision: 20592
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=20592
Author: blendix
Date: 2009-06-03 02:14:12 +0200 (Wed, 03 Jun 2009)
Log Message:
-----------
UI:
* Added initial color ramp and curve mapping templates.
Modified Paths:
--------------
branches/blender2.5/blender/source/blender/editors/include/UI_interface.h
branches/blender2.5/blender/source/blender/editors/interface/interface_api.c
branches/blender2.5/blender/source/blender/editors/interface/interface_templates.c
branches/blender2.5/blender/source/blender/editors/interface/interface_utils.c
Modified: branches/blender2.5/blender/source/blender/editors/include/UI_interface.h
===================================================================
--- branches/blender2.5/blender/source/blender/editors/include/UI_interface.h 2009-06-03 00:09:30 UTC (rev 20591)
+++ branches/blender2.5/blender/source/blender/editors/include/UI_interface.h 2009-06-03 00:14:12 UTC (rev 20592)
@@ -52,6 +52,7 @@
struct uiStyle;
struct uiFontStyle;
struct ColorBand;
+struct CurveMapping;
typedef struct uiBut uiBut;
typedef struct uiBlock uiBlock;
@@ -514,9 +515,9 @@
void autocomplete_bone(struct bContext *C, char *str, void *arg_v);
void autocomplete_vgroup(struct bContext *C, char *str, void *arg_v);
-struct CurveMapping;
struct rctf;
void curvemap_buttons(uiBlock *block, struct CurveMapping *cumap, char labeltype, short event, short redraw, struct rctf *rect);
+void colorband_buttons(uiBlock *block, struct ColorBand *coba, struct rctf *rect, int small);
/* Module
@@ -604,6 +605,8 @@
uiLayout *uiTemplateModifier(uiLayout *layout, struct PointerRNA *ptr);
uiLayout *uiTemplateConstraint(uiLayout *layout, struct PointerRNA *ptr);
void uiTemplatePreview(uiLayout *layout, struct ID *id);
+void uiTemplateColorRamp(uiLayout *layout, struct ColorBand *coba, int expand);
+void uiTemplateCurveMapping(uiLayout *layout, struct CurveMapping *cumap, int type);
/* items */
void uiItemO(uiLayout *layout, char *name, int icon, char *opname);
Modified: branches/blender2.5/blender/source/blender/editors/interface/interface_api.c
===================================================================
--- branches/blender2.5/blender/source/blender/editors/interface/interface_api.c 2009-06-03 00:09:30 UTC (rev 20591)
+++ branches/blender2.5/blender/source/blender/editors/interface/interface_api.c 2009-06-03 00:14:12 UTC (rev 20592)
@@ -54,6 +54,12 @@
FunctionRNA *func;
PropertyRNA *parm;
+ static EnumPropertyItem curve_type_items[] = {
+ {0, "NONE", "None", ""},
+ {'v', "VECTOR", "Vector", ""},
+ {'c', "COLOR", "Color", ""},
+ {0, NULL, NULL, NULL}};
+
/* simple layout specifiers */
func= RNA_def_function(srna, "row", "uiLayoutRow");
parm= RNA_def_pointer(func, "layout", "UILayout", "", "Sub-layout to put items in.");
@@ -214,5 +220,14 @@
parm= RNA_def_pointer(func, "id", "ID", "", "ID datablock.");
RNA_def_property_flag(parm, PROP_REQUIRED);
+ func= RNA_def_function(srna, "template_curve_mapping", "uiTemplateCurveMapping");
+ parm= RNA_def_pointer(func, "curvemap", "CurveMapping", "", "Curve mapping pointer.");
+ RNA_def_property_flag(parm, PROP_REQUIRED);
+ RNA_def_enum(func, "type", curve_type_items, 0, "Type", "Type of curves to display.");
+
+ func= RNA_def_function(srna, "template_color_ramp", "uiTemplateColorRamp");
+ parm= RNA_def_pointer(func, "ramp", "ColorRamp", "", "Color ramp pointer.");
+ RNA_def_property_flag(parm, PROP_REQUIRED);
+ RNA_def_boolean(func, "expand", 0, "", "Expand button to show more detail.");
}
Modified: branches/blender2.5/blender/source/blender/editors/interface/interface_templates.c
===================================================================
--- branches/blender2.5/blender/source/blender/editors/interface/interface_templates.c 2009-06-03 00:09:30 UTC (rev 20591)
+++ branches/blender2.5/blender/source/blender/editors/interface/interface_templates.c 2009-06-03 00:14:12 UTC (rev 20592)
@@ -1311,3 +1311,37 @@
}
+/********************** ColorRamp Template **************************/
+
+void uiTemplateColorRamp(uiLayout *layout, ColorBand *coba, int expand)
+{
+ uiBlock *block;
+ rctf rect;
+
+ if(coba) {
+ rect.xmin= 0; rect.xmax= 200;
+ rect.ymin= 0; rect.ymax= 190;
+
+ block= uiLayoutFreeBlock(layout);
+ colorband_buttons(block, coba, &rect, !expand);
+ }
+}
+
+/********************* CurveMapping Template ************************/
+
+#include "DNA_color_types.h"
+
+void uiTemplateCurveMapping(uiLayout *layout, CurveMapping *cumap, int type)
+{
+ uiBlock *block;
+ rctf rect;
+
+ if(cumap) {
+ rect.xmin= 0; rect.xmax= 200;
+ rect.ymin= 0; rect.ymax= 190;
+
+ block= uiLayoutFreeBlock(layout);
+ curvemap_buttons(block, cumap, type, 0, 0, &rect);
+ }
+}
+
Modified: branches/blender2.5/blender/source/blender/editors/interface/interface_utils.c
===================================================================
--- branches/blender2.5/blender/source/blender/editors/interface/interface_utils.c 2009-06-03 00:09:30 UTC (rev 20591)
+++ branches/blender2.5/blender/source/blender/editors/interface/interface_utils.c 2009-06-03 00:14:12 UTC (rev 20592)
@@ -35,6 +35,7 @@
#include "DNA_material_types.h"
#include "DNA_object_types.h"
#include "DNA_screen_types.h"
+#include "DNA_texture_types.h"
#include "DNA_windowmanager_types.h"
#include "BKE_colortools.h"
@@ -42,6 +43,7 @@
#include "BKE_idprop.h"
#include "BKE_library.h"
#include "BKE_main.h"
+#include "BKE_texture.h"
#include "BKE_utildefines.h"
#include "RNA_access.h"
@@ -1098,3 +1100,128 @@
cumap, 0.0f, 1.0f, 0, 0, "");
}
+#define B_BANDCOL 1
+
+static int vergcband(const void *a1, const void *a2)
+{
+ const CBData *x1=a1, *x2=a2;
+
+ if( x1->pos > x2->pos ) return 1;
+ else if( x1->pos < x2->pos) return -1;
+ return 0;
+}
+
+static void colorband_pos_cb(bContext *C, void *coba_v, void *unused_v)
+{
+ ColorBand *coba= coba_v;
+ int a;
+
+ if(coba->tot<2) return;
+
+ for(a=0; a<coba->tot; a++) coba->data[a].cur= a;
+ qsort(coba->data, coba->tot, sizeof(CBData), vergcband);
+ for(a=0; a<coba->tot; a++) {
+ if(coba->data[a].cur==coba->cur) {
+ // XXX if(coba->cur!=a) addqueue(curarea->win, REDRAW, 0); /* button cur */
+ coba->cur= a;
+ break;
+ }
+ }
+}
+
+static void colorband_add_cb(bContext *C, void *coba_v, void *unused_v)
+{
+ ColorBand *coba= coba_v;
+
+ if(coba->tot < MAXCOLORBAND-1) coba->tot++;
+ coba->cur= coba->tot-1;
+
+ colorband_pos_cb(C, coba, NULL);
+ ED_undo_push(C, "Add colorband");
+}
+
+static void colorband_del_cb(bContext *C, void *coba_v, void *unused_v)
+{
+ ColorBand *coba= coba_v;
+ int a;
+
+ if(coba->tot<2) return;
+
+ for(a=coba->cur; a<coba->tot; a++) {
+ coba->data[a]= coba->data[a+1];
+ }
+ if(coba->cur) coba->cur--;
+ coba->tot--;
+
+ ED_undo_push(C, "Delete colorband");
+ // XXX BIF_preview_changed(ID_TE);
+}
+
+
+/* offset aligns from bottom, standard width 300, height 115 */
+static void colorband_buttons_large(uiBlock *block, ColorBand *coba, int xoffs, int yoffs, int redraw)
+{
+ CBData *cbd;
+ uiBut *bt;
+
+ if(coba==NULL) return;
+
+ 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");
+ uiButSetFunc(bt, colorband_add_cb, coba, NULL);
+ 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");
+ bt= uiDefBut(block, BUT, redraw, "Del", 199+xoffs,95+yoffs,37,20, 0, 0, 0, 0, 0, "Deletes the active position");
+ uiButSetFunc(bt, colorband_del_cb, coba, NULL);
+
+ uiDefButS(block, MENU, redraw, "Interpolation %t|Ease %x1|Cardinal %x3|Linear %x0|B-Spline %x2|Constant %x4",
+ 236+xoffs, 95+yoffs, 64, 20, &coba->ipotype, 0.0, 0.0, 0, 0, "Sets interpolation type");
+
+ uiDefBut(block, BUT_COLORBAND, redraw, "", xoffs,65+yoffs,300,30, coba, 0, 0, 0, 0, "");
+
+ cbd= coba->data + coba->cur;
+
+ uiBlockBeginAlign(block);
+ 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");
+ uiButSetFunc(bt, colorband_pos_cb, coba, NULL);
+ uiDefButF(block, COL, redraw, "", xoffs,20+yoffs,110,20, &(cbd->r), 0, 0, 0, B_BANDCOL, "");
+ uiDefButF(block, NUMSLI, redraw, "A ", xoffs,yoffs,110,20, &cbd->a, 0.0, 1.0, 10, 0, "Sets the alpha value for this position");
+
+ uiBlockBeginAlign(block);
+ 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");
+ 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");
+ 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");
+ uiBlockEndAlign(block);
+}
+
+static void colorband_buttons_small(uiBlock *block, ColorBand *coba, rctf *butr, int event)
+{
+ CBData *cbd;
+ uiBut *bt;
+ float unit= (butr->xmax-butr->xmin)/14.0f;
+ float xs= butr->xmin;
+
+ cbd= coba->data + coba->cur;
+
+ uiBlockBeginAlign(block);
+ uiDefButF(block, COL, event, "", xs,butr->ymin+20.0f,2.0f*unit,20, &(cbd->r), 0, 0, 0, B_BANDCOL, "");
+ 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, "");
+ 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");
+ uiButSetFunc(bt, colorband_add_cb, coba, NULL);
+ 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");
+ uiButSetFunc(bt, colorband_del_cb, coba, NULL);
+
+ uiDefButS(block, MENU, event, "Interpolation %t|Ease %x1|Cardinal %x3|Linear %x0|B-Spline %x2|Constant %x4",
+ xs+10.0f*unit, butr->ymin+20.0f, unit*4, 20, &coba->ipotype, 0.0, 0.0, 0, 0, "Sets interpolation type");
+
+ uiDefBut(block, BUT_COLORBAND, event, "", xs,butr->ymin,butr->xmax-butr->xmin,20.0f, coba, 0, 0, 0, 0, "");
+ uiBlockEndAlign(block);
+
+}
+
+void colorband_buttons(uiBlock *block, ColorBand *coba, rctf *butr, int small)
+{
+ if(small)
+ colorband_buttons_small(block, coba, butr, 0);
+ else
+ colorband_buttons_large(block, coba, 0, 0, 0);
+}
+
More information about the Bf-blender-cvs
mailing list