Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTon Roosendaal <ton@blender.org>2006-01-08 14:41:06 +0300
committerTon Roosendaal <ton@blender.org>2006-01-08 14:41:06 +0300
commit104ab9b103ab30ca87ccb9e739a58863fc29d3bf (patch)
tree4f26f35a13cc5f92d485f72f2c9116d202f2f9cd /source/blender/src/butspace.c
parent32e21f4524cd3c428b5b8492089530471a7f0867 (diff)
Orange:
- New UI element: the "Curve Button". For mapping ranges (like 0 - 1) to another range, the curve button can be used for proportional falloff, bone influences, painting density, etc. Most evident use is of course to map RGB color with curves. To be able to use it, you have to allocate a CurveMapping struct and pass this on to the button. The CurveMapping API is in the new C file blenkernel/intern/colortools.c It's as simple as calling: curvemap= curvemapping_add(3, 0, 0, 1, 1) Which will create 3 curves, and sets a default 0-1 range. The current code only supports up to 4 curves maximum per mapping struct. The CurveMap button in Blender than handles allmost all editing. Evaluating a single channel: float newvalue= curvemapping_evaluateF(curvemap, 0, oldval); Where the second argument is the channel index, here 0-1-2 are possible. Or mapping a vector: curvemapping_evaluate3F(curvemap, newvec, oldvec); Optimized versions for byte or short mapping is possible too, not done yet. In butspace.c I've added a template wrapper for buttons around the curve, to reveil settings or show tools; check this screenie: http://www.blender.org/bf/curves.jpg - Buttons R, G, B: select channel - icons + and -: zoom in, out - icon 'wrench': menu with tools, like clear curve, set handle type - icon 'clipping': menu with clip values, and to dis/enable clipping - icon 'x': delete selection In the curve button itself, only LMB clicks are handled (like all UI elements in Blender). - click on point: select - shift+click on point: swap select - click on point + drag: select point (if not selected) and move it - click outside point + drag: translate view - CTRL+click: add new point - hold SHIFT while dragging to snap to grid (Yes I know... either one of these can be Blender compliant, not both!) - if you drag a point exactly on top of another, it merges them Other fixes: - Icons now draw using "Safe RasterPos", so they align with pixel boundary. the old code made ints from the raster pos coordinate, which doesn't work well for zoom in/out situations - bug in Node editing: buttons could not get freed, causing in memory error prints at end of a Blender session. That one was a very simple, but nasty error causing me all evening last night to find! (Hint; check diff of editnode.c, where uiDoButtons is called) Last note: this adds 3 new files in our tree, I did scons, but not MSVC!
Diffstat (limited to 'source/blender/src/butspace.c')
-rw-r--r--source/blender/src/butspace.c191
1 files changed, 191 insertions, 0 deletions
diff --git a/source/blender/src/butspace.c b/source/blender/src/butspace.c
index a068ec8c71e..a702f294d47 100644
--- a/source/blender/src/butspace.c
+++ b/source/blender/src/butspace.c
@@ -41,6 +41,7 @@
#include "MEM_guardedalloc.h"
+#include "DNA_color_types.h"
#include "DNA_object_types.h"
#include "DNA_scene_types.h"
#include "DNA_screen_types.h"
@@ -48,6 +49,7 @@
#include "DNA_space_types.h"
#include "DNA_texture_types.h"
+#include "BKE_colortools.h"
#include "BKE_global.h"
#include "BKE_main.h"
#include "BKE_library.h"
@@ -239,6 +241,195 @@ void test_texpoin_but(char *name, ID **idpp)
*idpp= NULL;
}
+/* ----------- custom button group ---------------------- */
+
+static void curvemap_buttons_zoom_in(void *cumap_v, void *unused)
+{
+ CurveMapping *cumap = cumap_v;
+ float d;
+
+ /* we allow 5 times zoom */
+ if( (cumap->curr.xmax - cumap->curr.xmin) > 0.2f*(cumap->clipr.xmax - cumap->clipr.xmin) ) {
+ d= 0.1154f*(cumap->curr.xmax - cumap->curr.xmin);
+ cumap->curr.xmin+= d;
+ cumap->curr.xmax-= d;
+ d= 0.1154f*(cumap->curr.ymax - cumap->curr.ymin);
+ cumap->curr.ymin+= d;
+ cumap->curr.ymax-= d;
+ }
+}
+
+static void curvemap_buttons_zoom_out(void *cumap_v, void *unused)
+{
+ CurveMapping *cumap = cumap_v;
+ float d;
+
+ /* we allow 5 times zoom */
+ if( (cumap->curr.xmax - cumap->curr.xmin) < 5.0f*(cumap->clipr.xmax - cumap->clipr.xmin) ) {
+ d= 0.15f*(cumap->curr.xmax - cumap->curr.xmin);
+ cumap->curr.xmin-= d;
+ cumap->curr.xmax+= d;
+ d= 0.15f*(cumap->curr.ymax - cumap->curr.ymin);
+ cumap->curr.ymin-= d;
+ cumap->curr.ymax+= d;
+ }
+}
+
+static void curvemap_buttons_setclip(void *cumap_v, void *unused)
+{
+ CurveMapping *cumap = cumap_v;
+
+ curvemapping_changed(cumap, 0);
+}
+
+static void curvemap_buttons_delete(void *cumap_v, void *unused)
+{
+ CurveMapping *cumap = cumap_v;
+
+ curvemap_remove(cumap->cm+cumap->cur, SELECT);
+ curvemapping_changed(cumap, 0);
+}
+
+/* NOTE: this is a block-menu, needs 0 events, otherwise the menu closes */
+static uiBlock *curvemap_clipping_func(void *cumap_v)
+{
+ CurveMapping *cumap = cumap_v;
+ uiBlock *block;
+ uiBut *bt;
+
+ block= uiNewBlock(&curarea->uiblocks, "curvemap_clipping_func", UI_EMBOSS, UI_HELV, curarea->win);
+
+ /* use this for a fake extra empy space around the buttons */
+ uiDefBut(block, LABEL, 0, "", -4, 16, 128, 106, NULL, 0, 0, 0, 0, "");
+
+ bt= uiDefButBitI(block, TOG, CUMA_DO_CLIP, 1, "Use Clipping",
+ 0,100,120,18, &cumap->flag, 0.0, 0.0, 10, 0, "");
+ uiButSetFunc(bt, curvemap_buttons_setclip, cumap, NULL);
+
+ uiBlockBeginAlign(block);
+ uiDefButF(block, NUM, 0, "Min X ", 0,74,120,18, &cumap->clipr.xmin, -10.0, cumap->clipr.xmax, 10, 0, "");
+ uiDefButF(block, NUM, 0, "Min Y ", 0,56,120,18, &cumap->clipr.ymin, -10.0, cumap->clipr.ymax, 10, 0, "");
+ uiDefButF(block, NUM, 0, "Max X ", 0,38,120,18, &cumap->clipr.xmax, cumap->clipr.xmin, 10.0, 10, 0, "");
+ uiDefButF(block, NUM, 0, "Max Y ", 0,20,120,18, &cumap->clipr.ymax, cumap->clipr.ymin, 10.0, 10, 0, "");
+
+ uiBlockSetDirection(block, UI_RIGHT);
+
+ return block;
+}
+
+
+static void curvemap_tools_dofunc(void *cumap_v, int event)
+{
+ CurveMapping *cumap = cumap_v;
+ CurveMap *cuma= cumap->cm+cumap->cur;
+
+ switch(event) {
+ case 0:
+ curvemap_reset(cuma, &cumap->clipr);
+ curvemapping_changed(cumap, 0);
+ break;
+ case 1:
+ cumap->curr= cumap->clipr;
+ break;
+ case 2: /* set vector */
+ curvemap_sethandle(cuma, 1);
+ curvemapping_changed(cumap, 0);
+ break;
+ case 3: /* set auto */
+ curvemap_sethandle(cuma, 0);
+ curvemapping_changed(cumap, 0);
+ break;
+ }
+ addqueue(curarea->win, REDRAW, 1);
+}
+
+static uiBlock *curvemap_tools_func(void *cumap_v)
+{
+ uiBlock *block;
+ short yco= 0, menuwidth=120;
+
+ block= uiNewBlock(&curarea->uiblocks, "curvemap_tools_func", UI_EMBOSSP, UI_HELV, curarea->win);
+ uiBlockSetButmFunc(block, curvemap_tools_dofunc, cumap_v);
+
+ uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Reset View", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 1, "");
+ uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Vector Handle", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 2, "");
+ uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Auto Handle", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 3, "");
+ uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Reset Curve", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 0, "");
+
+ uiBlockSetDirection(block, UI_RIGHT);
+ uiTextBoundsBlock(block, 50);
+ return block;
+}
+
+/* still unsure how this call evolves... we use labeltype for defining what curve-channels to show */
+void curvemap_buttons(uiBlock *block, CurveMapping *cumap, char labeltype, short event, short redraw, rctf *rect)
+{
+ uiBut *bt;
+ float dx, fy= rect->ymax-18.0f;
+ int icon;
+ short xco, yco;
+
+ yco= (short)(rect->ymax-18.0f);
+
+ /* curve choice options + tools/settings, 8 icons */
+ dx= (rect->xmax-rect->xmin)/(8.0f);
+
+ uiBlockBeginAlign(block);
+ if(labeltype=='v') { /* vector */
+ xco= (short)rect->xmin;
+ if(cumap->cm[0].curve)
+ uiDefButI(block, ROW, redraw, "X", xco, yco+2, dx, 16, &cumap->cur, 0.0, 0.0, 0.0, 0.0, "");
+ xco= (short)(rect->xmin+1.0f*dx);
+ if(cumap->cm[1].curve)
+ uiDefButI(block, ROW, redraw, "Y", xco, yco+2, dx, 16, &cumap->cur, 0.0, 1.0, 0.0, 0.0, "");
+ xco= (short)(rect->xmin+2.0f*dx);
+ if(cumap->cm[2].curve)
+ uiDefButI(block, ROW, redraw, "Z", xco, yco+2, dx, 16, &cumap->cur, 0.0, 2.0, 0.0, 0.0, "");
+ }
+ else if(labeltype=='c') { /* color */
+ xco= (short)rect->xmin;
+ if(cumap->cm[0].curve)
+ uiDefButI(block, ROW, redraw, "R", xco, yco+2, dx, 16, &cumap->cur, 0.0, 0.0, 0.0, 0.0, "");
+ xco= (short)(rect->xmin+1.0f*dx);
+ if(cumap->cm[1].curve)
+ uiDefButI(block, ROW, redraw, "G", xco, yco+2, dx, 16, &cumap->cur, 0.0, 1.0, 0.0, 0.0, "");
+ xco= (short)(rect->xmin+2.0f*dx);
+ if(cumap->cm[2].curve)
+ uiDefButI(block, ROW, redraw, "B", xco, yco+2, dx, 16, &cumap->cur, 0.0, 2.0, 0.0, 0.0, "");
+ }
+ /* else no channels ! */
+ uiBlockEndAlign(block);
+
+ xco= (short)(rect->xmin+3.5f*dx);
+ uiBlockSetEmboss(block, UI_EMBOSSN);
+ bt= uiDefIconBut(block, BUT, redraw, ICON_ZOOMIN, xco, yco, dx, 14, NULL, 0.0, 0.0, 0.0, 0.0, "Zoom in");
+ uiButSetFunc(bt, curvemap_buttons_zoom_in, cumap, NULL);
+
+ xco= (short)(rect->xmin+4.25f*dx);
+ bt= uiDefIconBut(block, BUT, redraw, ICON_ZOOMOUT, xco, yco, dx, 14, NULL, 0.0, 0.0, 0.0, 0.0, "Zoom out");
+ uiButSetFunc(bt, curvemap_buttons_zoom_out, cumap, NULL);
+
+ xco= (short)(rect->xmin+5.0f*dx);
+ bt= uiDefIconBlockBut(block, curvemap_tools_func, cumap, event, ICON_MODIFIER, xco, yco, dx, 18, "Tools");
+
+ xco= (short)(rect->xmin+6.0f*dx);
+ if(cumap->flag & CUMA_DO_CLIP) icon= ICON_CLIPUV_HLT; else icon= ICON_CLIPUV_DEHLT;
+ bt= uiDefIconBlockBut(block, curvemap_clipping_func, cumap, event, icon, xco, yco, dx, 18, "Clipping Options");
+
+ xco= (short)(rect->xmin+7.0f*dx);
+ bt= uiDefIconBut(block, BUT, redraw, ICON_X, xco, yco, dx, 18, NULL, 0.0, 0.0, 0.0, 0.0, "Delete points");
+ uiButSetFunc(bt, curvemap_buttons_delete, cumap, NULL);
+
+ uiBlockSetEmboss(block, UI_EMBOSS);
+
+ uiDefBut(block, BUT_CURVE, event, "",
+ rect->xmin, rect->ymin, rect->xmax-rect->xmin, fy-rect->ymin,
+ cumap, 0.0f, 1.0f, 0, 0, "");
+
+
+}
+
+
/* --------------------------------- */