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:
authorCampbell Barton <ideasman42@gmail.com>2014-03-29 08:26:29 +0400
committerCampbell Barton <ideasman42@gmail.com>2014-03-29 08:36:50 +0400
commiteaaacfc7b8b6fc7819289ede03065e83ed4f6f9e (patch)
tree6aaf44116dde502a316ed141de4c697144d47232
parentb64bdb2c1bee4afffad29a763ab76156cf7730c8 (diff)
UI: Color-Ramp handles
- display handles with solid color. - active handle is highlighted. - 1/4 of the colorband draws solid. - use old-style handles when zoomed out. D289 by Charlie Jolly with own modifications.
-rw-r--r--source/blender/editors/interface/interface_draw.c286
1 files changed, 210 insertions, 76 deletions
diff --git a/source/blender/editors/interface/interface_draw.c b/source/blender/editors/interface/interface_draw.c
index 1e2a8baf141..13551d9df42 100644
--- a/source/blender/editors/interface/interface_draw.c
+++ b/source/blender/editors/interface/interface_draw.c
@@ -912,12 +912,167 @@ void ui_draw_but_VECTORSCOPE(ARegion *ar, uiBut *but, uiWidgetColors *UNUSED(wco
glDisable(GL_BLEND);
}
+static void ui_draw_colorband_handle_tri_hlight(float x1, float y1, float halfwidth, float height)
+{
+ float v[2];
+
+ glEnable(GL_LINE_SMOOTH);
+
+ glBegin(GL_LINE_STRIP);
+ copy_v2_fl2(v, x1 + halfwidth, y1);
+ glVertex2fv(v);
+ copy_v2_fl2(v, x1, y1 + height);
+ glVertex2fv(v);
+ copy_v2_fl2(v, x1 - halfwidth, y1);
+ glVertex2fv(v);
+ glEnd();
+
+ glDisable(GL_LINE_SMOOTH);
+}
+
+static void ui_draw_colorband_handle_tri(float x1, float y1, float halfwidth, float height, bool fill)
+{
+ float v[2];
+
+ if (fill) {
+ glPolygonMode(GL_FRONT, GL_FILL);
+ glEnable(GL_POLYGON_SMOOTH);
+ }
+ else {
+ glPolygonMode(GL_FRONT, GL_LINE);
+ glEnable(GL_LINE_SMOOTH);
+ }
+
+ glBegin(GL_TRIANGLES);
+ copy_v2_fl2(v, x1 + halfwidth, y1);
+ glVertex2fv(v);
+ copy_v2_fl2(v, x1, y1 + height);
+ glVertex2fv(v);
+ copy_v2_fl2(v, x1 - halfwidth, y1);
+ glVertex2fv(v);
+ glEnd();
+
+ if (fill) {
+ glDisable(GL_POLYGON_SMOOTH);
+ }
+ else {
+ glDisable(GL_LINE_SMOOTH);
+ glPolygonMode(GL_FRONT, GL_FILL);
+ }
+}
+
+static void ui_draw_colorband_handle_box(float x1, float y1, float x2, float y2, bool fill)
+{
+ float v[2];
+
+ if (fill) {
+ glPolygonMode(GL_FRONT, GL_FILL);
+ }
+ else {
+ glPolygonMode(GL_FRONT, GL_LINE);
+ }
+
+ glBegin(GL_QUADS);
+ copy_v2_fl2(v, x1, y1);
+ glVertex2fv(v);
+ copy_v2_fl2(v, x1, y2);
+ glVertex2fv(v);
+ copy_v2_fl2(v, x2, y2);
+ glVertex2fv(v);
+ copy_v2_fl2(v, x2, y1);
+ glVertex2fv(v);
+ glEnd();
+
+ if (!fill) {
+ glPolygonMode(GL_FRONT, GL_FILL);
+ }
+}
+
+static void ui_draw_colorband_handle(
+ const rcti *rect, float x,
+ const float rgb[3], struct ColorManagedDisplay *display,
+ bool active)
+{
+ const float sizey = BLI_rcti_size_y(rect);
+ const float min_width = 3.0f;
+ float half_width, height, y1, y2;
+ float colf[3] = {UNPACK3(rgb)};
+
+ half_width = floorf(sizey / 3.5f);
+ height = half_width * 1.4f;
+
+ y1 = rect->ymin + (sizey * 0.16f);
+ y2 = rect->ymax;
+
+ /* align to pixels */
+ x = floorf(x + 0.5f);
+ y1 = floorf(y1 + 0.5f);
+
+ if (active || half_width < min_width) {
+ glBegin(GL_LINES);
+ glColor3ub(0, 0, 0);
+ glVertex2f(x, y1);
+ glVertex2f(x, y2);
+ glEnd();
+ setlinestyle(active ? 2 : 1);
+ glBegin(GL_LINES);
+ glColor3ub(200, 200, 200);
+ glVertex2f(x, y1);
+ glVertex2f(x, y2);
+ glEnd();
+ setlinestyle(0);
+
+ /* hide handles when zoomed out too far */
+ if (half_width < min_width) {
+ return;
+ }
+ }
+
+ /* shift handle down */
+ y1 = y1 - half_width;
+
+ glColor3ub(0, 0, 0);
+ ui_draw_colorband_handle_box(x - half_width, y1 - 1, x + half_width, y1 + height, false);
+
+ /* draw all triangles blended */
+ glEnable(GL_BLEND);
+
+ ui_draw_colorband_handle_tri(x, y1 + height, half_width, half_width, true);
+
+ if (active)
+ glColor3ub(196, 196, 196);
+ else
+ glColor3ub(128, 128, 128);
+ ui_draw_colorband_handle_tri(x, y1 + height, half_width, half_width, true);
+
+ if (active)
+ glColor3ub(255, 255, 255);
+ else
+ glColor3ub(196, 196, 196);
+ ui_draw_colorband_handle_tri_hlight(x, y1 + height - 1, (half_width - 1), (half_width - 1));
+
+ glColor3ub(0, 0, 0);
+ ui_draw_colorband_handle_tri_hlight(x, y1 + height, half_width, half_width);
+
+ glDisable(GL_BLEND);
+
+ glColor3ub(128, 128, 128);
+ ui_draw_colorband_handle_box(x - (half_width - 1), y1, x + (half_width - 1), y1 + height, true);
+
+ if (display) {
+ IMB_colormanagement_scene_linear_to_display_v3(colf, display);
+ }
+
+ glColor3fv(colf);
+ ui_draw_colorband_handle_box(x - (half_width - 2), y1 + 1, x + (half_width - 2), y1 + height - 2, true);
+}
+
void ui_draw_but_COLORBAND(uiBut *but, uiWidgetColors *UNUSED(wcol), const rcti *rect)
{
ColorBand *coba;
CBData *cbd;
- float x1, y1, sizex, sizey;
- float v3[2], v1[2], v2[2], v1a[2], v2a[2];
+ float x1, y1, sizex, sizey, sizey_solid;
+ float v1[2], v2[2];
int a;
float pos, colf[4] = {0, 0, 0, 0}; /* initialize in case the colorband isn't valid */
struct ColorManagedDisplay *display = NULL;
@@ -929,37 +1084,32 @@ void ui_draw_but_COLORBAND(uiBut *but, uiWidgetColors *UNUSED(wcol), const rcti
display = ui_block_display_get(but->block);
x1 = rect->xmin;
- y1 = rect->ymin;
sizex = rect->xmax - x1;
- sizey = rect->ymax - y1;
-
- /* first background, to show tranparency */
+ sizey = BLI_rcti_size_y(rect);
+ sizey_solid = sizey / 4;
+ y1 = rect->ymin;
+ /* layer: background, to show tranparency */
glColor4ub(UI_ALPHA_CHECKER_DARK, UI_ALPHA_CHECKER_DARK, UI_ALPHA_CHECKER_DARK, 255);
- glRectf(x1, y1, x1 + sizex, y1 + sizey);
+ glRectf(x1, y1, x1 + sizex, rect->ymax);
glEnable(GL_POLYGON_STIPPLE);
glColor4ub(UI_ALPHA_CHECKER_LIGHT, UI_ALPHA_CHECKER_LIGHT, UI_ALPHA_CHECKER_LIGHT, 255);
glPolygonStipple(stipple_checker_8px);
- glRectf(x1, y1, x1 + sizex, y1 + sizey);
+ glRectf(x1, y1, x1 + sizex, rect->ymax);
glDisable(GL_POLYGON_STIPPLE);
+ /* layer: color ramp */
glShadeModel(GL_FLAT);
glEnable(GL_BLEND);
-
+
cbd = coba->data;
-
- v1[0] = v2[0] = x1;
- v1[1] = y1;
- v2[1] = y1 + sizey;
+
+ v1[1] = y1 + sizey_solid;
+ v2[1] = rect->ymax;
glBegin(GL_QUAD_STRIP);
-
- glColor4fv(&cbd->r);
- glVertex2fv(v1);
- glVertex2fv(v2);
-
- for (a = 1; a <= sizex; a++) {
- pos = ((float)a) / (sizex - 1);
+ for (a = 0; a <= sizex; a++) {
+ pos = ((float)a) / sizex;
do_colorband(coba, pos, colf);
if (display)
IMB_colormanagement_scene_linear_to_display_v3(colf, display);
@@ -970,71 +1120,55 @@ void ui_draw_but_COLORBAND(uiBut *but, uiWidgetColors *UNUSED(wcol), const rcti
glVertex2fv(v1);
glVertex2fv(v2);
}
-
glEnd();
- glShadeModel(GL_FLAT);
+
+ /* layer: color ramp without alpha for reference when manipulating ramp properties */
+ v1[1] = y1;
+ v2[1] = y1 + sizey_solid;
+
+ glBegin(GL_QUAD_STRIP);
+ for (a = 0; a <= sizex; a++) {
+ pos = ((float)a) / sizex;
+ do_colorband(coba, pos, colf);
+ if (display)
+ IMB_colormanagement_scene_linear_to_display_v3(colf, display);
+
+ v1[0] = v2[0] = x1 + a;
+
+ glColor4f(colf[0], colf[1], colf[2], 1.0f);
+ glVertex2fv(v1);
+ glVertex2fv(v2);
+ }
+ glEnd();
+
glDisable(GL_BLEND);
-
- /* outline */
+ glShadeModel(GL_SMOOTH);
+
+ /* layer: box outline */
glColor4f(0.0, 0.0, 0.0, 1.0);
- fdrawbox(x1, y1, x1 + sizex, y1 + sizey);
-
- /* help lines */
- v1[0] = v2[0] = v3[0] = x1;
- v1[1] = y1;
- v1a[1] = y1 + 0.25f * sizey;
- v2[1] = y1 + 0.5f * sizey;
- v2a[1] = y1 + 0.75f * sizey;
- v3[1] = y1 + sizey;
+ fdrawbox(x1, y1, x1 + sizex, rect->ymax);
+ glEnd();
+ /* layer: box outline */
+ glEnable(GL_BLEND);
+ glColor4f(0.0f, 0.0f, 0.0f, 0.5f);
+ fdrawline(x1, y1, x1 + sizex, y1);
+ glColor4f(1.0f, 1.0f, 1.0f, 0.25f);
+ fdrawline(x1, y1 - 1, x1 + sizex, y1 - 1);
+ glDisable(GL_BLEND);
- cbd = coba->data;
- glBegin(GL_LINES);
+ /* layer: draw handles */
for (a = 0; a < coba->tot; a++, cbd++) {
- v1[0] = v2[0] = v3[0] = v1a[0] = v2a[0] = x1 + cbd->pos * sizex;
-
- if (a == coba->cur) {
- glColor3ub(0, 0, 0);
- glVertex2fv(v1);
- glVertex2fv(v3);
- glEnd();
-
- setlinestyle(2);
- glBegin(GL_LINES);
- glColor3ub(255, 255, 255);
- glVertex2fv(v1);
- glVertex2fv(v3);
- glEnd();
- setlinestyle(0);
- glBegin(GL_LINES);
-
-#if 0
- glColor3ub(0, 0, 0);
- glVertex2fv(v1);
- glVertex2fv(v1a);
- glColor3ub(255, 255, 255);
- glVertex2fv(v1a);
- glVertex2fv(v2);
- glColor3ub(0, 0, 0);
- glVertex2fv(v2);
- glVertex2fv(v2a);
- glColor3ub(255, 255, 255);
- glVertex2fv(v2a);
- glVertex2fv(v3);
-#endif
- }
- else {
- glColor3ub(0, 0, 0);
- glVertex2fv(v1);
- glVertex2fv(v2);
-
- glColor3ub(255, 255, 255);
- glVertex2fv(v2);
- glVertex2fv(v3);
+ if (a != coba->cur) {
+ pos = x1 + cbd->pos * (sizex - 1) + 1;
+ ui_draw_colorband_handle(rect, pos, &cbd->r, display, false);
}
}
- glEnd();
+ /* layer: active handle */
+ cbd = &coba->data[coba->cur];
+ pos = x1 + cbd->pos * (sizex - 1) + 1;
+ ui_draw_colorband_handle(rect, pos, &cbd->r, display, true);
}
void ui_draw_but_NORMAL(uiBut *but, uiWidgetColors *wcol, const rcti *rect)