[Bf-blender-cvs] [bd46a92] temp-ui-widget-refactor: New widget type for colorband

Julian Eisel noreply at git.blender.org
Mon Jul 20 12:07:50 CEST 2015


Commit: bd46a92deb787fbdcfc43fe9b85be6b75065ecdf
Author: Julian Eisel
Date:   Mon Jul 20 12:07:09 2015 +0200
Branches: temp-ui-widget-refactor
https://developer.blender.org/rBbd46a92deb787fbdcfc43fe9b85be6b75065ecdf

New widget type for colorband

===================================================================

M	source/blender/editors/interface/interface_widgets.c
M	source/blender/editors/interface/widgets/widgets.c
M	source/blender/editors/interface/widgets/widgets.h
M	source/blender/editors/interface/widgets/widgets_draw/drawstyle_classic.c
M	source/blender/editors/interface/widgets/widgets_draw/widgets_draw.c
M	source/blender/editors/interface/widgets/widgets_draw/widgets_draw_intern.h

===================================================================

diff --git a/source/blender/editors/interface/interface_widgets.c b/source/blender/editors/interface/interface_widgets.c
index 1f4075f..7872e44 100644
--- a/source/blender/editors/interface/interface_widgets.c
+++ b/source/blender/editors/interface/interface_widgets.c
@@ -1142,7 +1142,7 @@ void ui_draw_but(const bContext *C, ARegion *ar, uiStyle *style, uiBut *but, rct
 				break;
 				
 			case UI_BTYPE_COLORBAND:
-				ui_draw_but_COLORBAND(but, &tui->wcol_regular, rect);
+				wt = WidgetTypeInit(UI_WTYPE_COLORBAND);
 				break;
 				
 			case UI_BTYPE_UNITVEC:
diff --git a/source/blender/editors/interface/widgets/widgets.c b/source/blender/editors/interface/widgets/widgets.c
index 589dbbc..6d7f649 100644
--- a/source/blender/editors/interface/widgets/widgets.c
+++ b/source/blender/editors/interface/widgets/widgets.c
@@ -80,6 +80,10 @@ uiWidgetType *WidgetTypeInit(const uiWidgetTypeEnum type)
 			wt.draw_type = draw_style->checkbox;
 			break;
 
+		case UI_WTYPE_COLORBAND:
+			wt.draw_type = draw_style->colorband;
+			break;
+
 		case UI_WTYPE_EXEC:
 			wt.wcol_theme = &btheme->tui.wcol_tool;
 			wt.draw_type = draw_style->exec;
diff --git a/source/blender/editors/interface/widgets/widgets.h b/source/blender/editors/interface/widgets/widgets.h
index 819a696..bea38b7 100644
--- a/source/blender/editors/interface/widgets/widgets.h
+++ b/source/blender/editors/interface/widgets/widgets.h
@@ -77,6 +77,7 @@ typedef enum {
 	UI_WTYPE_SWATCH,
 	UI_WTYPE_RGB_PICKER,
 	UI_WTYPE_UNITVEC,
+	UI_WTYPE_COLORBAND,
 	UI_WTYPE_HSV_CIRCLE,
 	UI_WTYPE_HSV_CUBE,
 	UI_WTYPE_HSV_VERT,
@@ -116,6 +117,7 @@ typedef struct uiWidgetDrawStyle {
 	/* let's keep this in a nice alphabetical order! */
 	uiWidgetDrawType *box,
 	                 *checkbox,
+	                 *colorband,
 	                 *exec,
 	                 *filename,
 	                 *hsv_circle,
diff --git a/source/blender/editors/interface/widgets/widgets_draw/drawstyle_classic.c b/source/blender/editors/interface/widgets/widgets_draw/drawstyle_classic.c
index 684d21a..8b42333 100644
--- a/source/blender/editors/interface/widgets/widgets_draw/drawstyle_classic.c
+++ b/source/blender/editors/interface/widgets/widgets_draw/drawstyle_classic.c
@@ -38,6 +38,10 @@
 #include "DNA_userdef_types.h"
 #include "DNA_brush_types.h"
 
+#include "BKE_texture.h"
+
+#include "IMB_colormanagement.h"
+
 #include "RNA_access.h"
 
 #include "UI_interface.h"
@@ -129,6 +133,113 @@ static void widget_checkbox(uiWidgetColors *wcol, rcti *rect, int state, int UNU
 	rect->xmin += BLI_rcti_size_y(rect) * 0.7 + delta;
 }
 
+
+static void widget_colorband(
+        uiBut *but, uiWidgetColors *wcol, rcti *rect,
+        int UNUSED(state), int UNUSED(roundboxalign))
+{
+	ColorBand *coba;
+	CBData *cbd;
+	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;
+
+	coba = (ColorBand *)(but->editcoba ? but->editcoba : but->poin);
+	if (coba == NULL) return;
+
+	if (but->block->color_profile)
+		display = ui_block_cm_display_get(but->block);
+
+	x1 = rect->xmin;
+	sizex = rect->xmax - x1;
+	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, 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, rect->ymax);
+	glDisable(GL_POLYGON_STIPPLE);
+
+	/* layer: color ramp */
+	glShadeModel(GL_FLAT);
+	glEnable(GL_BLEND);
+
+	cbd = coba->data;
+
+	v1[1] = y1 + sizey_solid;
+	v2[1] = rect->ymax;
+
+	glBegin(GL_TRIANGLE_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;
+
+		glColor4fv(colf);
+		glVertex2fv(v1);
+		glVertex2fv(v2);
+	}
+	glEnd();
+
+	/* layer: color ramp without alpha for reference when manipulating ramp properties */
+	v1[1] = y1;
+	v2[1] = y1 + sizey_solid;
+
+	glBegin(GL_TRIANGLE_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);
+	glShadeModel(GL_SMOOTH);
+
+	/* layer: box outline */
+	glColor4f(0.0, 0.0, 0.0, 1.0);
+	fdrawbox(x1, y1, x1 + sizex, rect->ymax);
+
+	/* 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);
+
+	/* layer: draw handles */
+	for (a = 0; a < coba->tot; a++, cbd++) {
+		if (a != coba->cur) {
+			pos = x1 + cbd->pos * (sizex - 1) + 1;
+			ui_draw_colorband_handle(rect, pos, &cbd->r, display, false);
+		}
+	}
+
+	/* layer: active handle */
+	if (coba->tot != 0) {
+		cbd = &coba->data[coba->cur];
+		pos = x1 + cbd->pos * (sizex - 1) + 1;
+		ui_draw_colorband_handle(rect, pos, &cbd->r, display, true);
+	}
+}
+
 static void widget_roundbut(uiWidgetColors *wcol, rcti *rect, int UNUSED(state), int roundboxalign)
 {
 	uiWidgetDrawBase wtb;
@@ -1145,6 +1256,13 @@ uiWidgetDrawType drawtype_classic_checkbox = {
 	/* text */   widget_draw_text_icon,
 };
 
+uiWidgetDrawType drawtype_classic_colorband = {
+	/* state */  NULL,
+	/* draw */   NULL,
+	/* custom */ widget_colorband,
+	/* text */   NULL,
+};
+
 uiWidgetDrawType drawtype_classic_exec = {
 	/* state */  widget_state,
 	/* draw */   widget_roundbut,
@@ -1366,6 +1484,7 @@ uiWidgetDrawType drawtype_classic_unitvec = {
 uiWidgetDrawStyle WidgetStyle_Classic = {
 	/* box */               &drawtype_classic_box,
 	/* checkbox */          &drawtype_classic_checkbox,
+	/* colorband */         &drawtype_classic_colorband,
 	/* exec */              &drawtype_classic_exec,
 	/* filename */          NULL, /* not used (yet?) */
 	/* hsv_circle */        &drawtype_classic_hsv_circle,
diff --git a/source/blender/editors/interface/widgets/widgets_draw/widgets_draw.c b/source/blender/editors/interface/widgets/widgets_draw/widgets_draw.c
index b73c5be..8d484e8 100644
--- a/source/blender/editors/interface/widgets/widgets_draw/widgets_draw.c
+++ b/source/blender/editors/interface/widgets/widgets_draw/widgets_draw.c
@@ -32,6 +32,8 @@
 #include "BLI_math.h"
 #include "BLI_rect.h"
 
+#include "IMB_colormanagement.h"
+
 #include "DNA_userdef_types.h"
 #include "DNA_screen_types.h"
 
@@ -725,3 +727,158 @@ void ui_hsv_cursor(float x, float y)
 
 	glPopMatrix();
 }
+
+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);
+	}
+}
+
+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(96, 96, 96);
+	ui_draw_colorband_handle_tri(x, y1 + height, half_width, half_width, true);
+
+	if (active)
+		glColor3ub(255, 255, 255);
+	else
+		glColor3ub(128, 128, 128);
+	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_wid

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list