[Bf-blender-cvs] [08b3e9a] temp-ui-widget-refactor: New widget types for HSV circle and cube
Julian Eisel
noreply at git.blender.org
Mon Jul 20 11:11:46 CEST 2015
Commit: 08b3e9a49c69b1ca1a34f3b15eef51ebb7e28b66
Author: Julian Eisel
Date: Mon Jul 20 11:09:46 2015 +0200
Branches: temp-ui-widget-refactor
https://developer.blender.org/rB08b3e9a49c69b1ca1a34f3b15eef51ebb7e28b66
New widget types for HSV circle and cube
===================================================================
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
===================================================================
diff --git a/source/blender/editors/interface/interface_widgets.c b/source/blender/editors/interface/interface_widgets.c
index 870ce40..1f4075f 100644
--- a/source/blender/editors/interface/interface_widgets.c
+++ b/source/blender/editors/interface/interface_widgets.c
@@ -618,88 +618,6 @@ void ui_hsvcircle_pos_from_vals(uiBut *but, const rcti *rect, float *hsv, float
*ypos = centy + sinf(-ang) * radius;
}
-static void ui_draw_but_HSVCIRCLE(uiBut *but, uiWidgetColors *wcol, const rcti *rect)
-{
- const int tot = 64;
- const float radstep = 2.0f * (float)M_PI / (float)tot;
- const float centx = BLI_rcti_cent_x_fl(rect);
- const float centy = BLI_rcti_cent_y_fl(rect);
- float radius = (float)min_ii(BLI_rcti_size_x(rect), BLI_rcti_size_y(rect)) / 2.0f;
-
- /* gouraud triangle fan */
- ColorPicker *cpicker = but->custom_data;
- const float *hsv_ptr = cpicker->color_data;
- float xpos, ypos, ang = 0.0f;
- float rgb[3], hsvo[3], hsv[3], col[3], colcent[3];
- int a;
- bool color_profile = ui_but_is_colorpicker_display_space(but);
-
- /* color */
- ui_but_v3_get(but, rgb);
-
- /* since we use compat functions on both 'hsv' and 'hsvo', they need to be initialized */
- hsvo[0] = hsv[0] = hsv_ptr[0];
- hsvo[1] = hsv[1] = hsv_ptr[1];
- hsvo[2] = hsv[2] = hsv_ptr[2];
-
- if (color_profile)
- ui_block_cm_to_display_space_v3(but->block, rgb);
-
- ui_rgb_to_color_picker_compat_v(rgb, hsv);
- copy_v3_v3(hsvo, hsv);
-
- CLAMP(hsv[2], 0.0f, 1.0f); /* for display only */
-
- /* exception: if 'lock' is set
- * lock the value of the color wheel to 1.
- * Useful for color correction tools where you're only interested in hue. */
- if (but->flag & UI_BUT_COLOR_LOCK) {
- if (U.color_picker_type == USER_CP_CIRCLE_HSV)
- hsv[2] = 1.0f;
- else
- hsv[2] = 0.5f;
- }
-
- ui_color_picker_to_rgb(0.0f, 0.0f, hsv[2], colcent, colcent + 1, colcent + 2);
-
- glShadeModel(GL_SMOOTH);
-
- glBegin(GL_TRIANGLE_FAN);
- glColor3fv(colcent);
- glVertex2f(centx, centy);
-
- for (a = 0; a <= tot; a++, ang += radstep) {
- float si = sinf(ang);
- float co = cosf(ang);
-
- ui_hsvcircle_vals_from_pos(hsv, hsv + 1, rect, centx + co * radius, centy + si * radius);
-
- ui_color_picker_to_rgb_v(hsv, col);
-
- glColor3fv(col);
- glVertex2f(centx + co * radius, centy + si * radius);
- }
- glEnd();
-
- glShadeModel(GL_FLAT);
-
- /* fully rounded outline */
- glPushMatrix();
- glTranslatef(centx, centy, 0.0f);
- glEnable(GL_BLEND);
- glEnable(GL_LINE_SMOOTH);
- glColor3ubv((unsigned char *)wcol->outline);
- glutil_draw_lined_arc(0.0f, M_PI * 2.0, radius, tot + 1);
- glDisable(GL_BLEND);
- glDisable(GL_LINE_SMOOTH);
- glPopMatrix();
-
- /* cursor */
- ui_hsvcircle_pos_from_vals(but, rect, hsvo, &xpos, &ypos);
-
- ui_hsv_cursor(xpos, ypos);
-}
-
/* ************ custom buttons, old stuff ************** */
/* draws in resolution of 48x4 colors */
@@ -887,37 +805,6 @@ void ui_hsvcube_pos_from_vals(uiBut *but, const rcti *rect, float *hsv, float *x
*yp = rect->ymin + y * BLI_rcti_size_y(rect);
}
-static void ui_draw_but_HSVCUBE(uiBut *but, const rcti *rect)
-{
- float rgb[3];
- float x = 0.0f, y = 0.0f;
- ColorPicker *cpicker = but->custom_data;
- float *hsv = cpicker->color_data;
- float hsv_n[3];
- bool use_display_colorspace = ui_but_is_colorpicker_display_space(but);
-
- copy_v3_v3(hsv_n, hsv);
-
- ui_but_v3_get(but, rgb);
-
- if (use_display_colorspace)
- ui_block_cm_to_display_space_v3(but->block, rgb);
-
- rgb_to_hsv_compat_v(rgb, hsv_n);
-
- ui_draw_gradient(rect, hsv_n, but->a1, 1.0f);
-
- ui_hsvcube_pos_from_vals(but, rect, hsv_n, &x, &y);
- CLAMP(x, rect->xmin + 3.0f, rect->xmax - 3.0f);
- CLAMP(y, rect->ymin + 3.0f, rect->ymax - 3.0f);
-
- ui_hsv_cursor(x, y);
-
- /* outline */
- glColor3ub(0, 0, 0);
- fdrawbox((rect->xmin), (rect->ymin), (rect->xmax), (rect->ymax));
-}
-
/* ************ separator, for menus etc ***************** */
static void ui_draw_separator(const rcti *rect, uiWidgetColors *wcol)
@@ -1246,12 +1133,12 @@ void ui_draw_but(const bContext *C, ARegion *ar, uiStyle *style, uiBut *but, rct
}
/* other HSV pickers */
else {
- ui_draw_but_HSVCUBE(but, rect);
+ wt = WidgetTypeInit(UI_WTYPE_HSV_CUBE);
}
break;
case UI_BTYPE_HSVCIRCLE:
- ui_draw_but_HSVCIRCLE(but, &tui->wcol_regular, rect);
+ wt = WidgetTypeInit(UI_WTYPE_HSV_CIRCLE);
break;
case UI_BTYPE_COLORBAND:
diff --git a/source/blender/editors/interface/widgets/widgets.c b/source/blender/editors/interface/widgets/widgets.c
index 58da37f..589dbbc 100644
--- a/source/blender/editors/interface/widgets/widgets.c
+++ b/source/blender/editors/interface/widgets/widgets.c
@@ -88,6 +88,14 @@ uiWidgetType *WidgetTypeInit(const uiWidgetTypeEnum type)
case UI_WTYPE_FILENAME:
break;
+ case UI_WTYPE_HSV_CIRCLE:
+ wt.draw_type = draw_style->hsv_circle;
+ break;
+
+ case UI_WTYPE_HSV_CUBE:
+ wt.draw_type = draw_style->hsv_cube;
+ break;
+
case UI_WTYPE_HSV_VERT:
wt.draw_type = draw_style->hsv_vert;
break;
diff --git a/source/blender/editors/interface/widgets/widgets.h b/source/blender/editors/interface/widgets/widgets.h
index 5a9e368..819a696 100644
--- a/source/blender/editors/interface/widgets/widgets.h
+++ b/source/blender/editors/interface/widgets/widgets.h
@@ -77,6 +77,8 @@ typedef enum {
UI_WTYPE_SWATCH,
UI_WTYPE_RGB_PICKER,
UI_WTYPE_UNITVEC,
+ UI_WTYPE_HSV_CIRCLE,
+ UI_WTYPE_HSV_CUBE,
UI_WTYPE_HSV_VERT,
UI_WTYPE_BOX,
UI_WTYPE_SCROLL_BACK,
@@ -116,6 +118,8 @@ typedef struct uiWidgetDrawStyle {
*checkbox,
*exec,
*filename,
+ *hsv_circle,
+ *hsv_cube,
*hsv_vert,
*icon,
*label,
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 8f80662..684d21a 100644
--- a/source/blender/editors/interface/widgets/widgets_draw/drawstyle_classic.c
+++ b/source/blender/editors/interface/widgets/widgets_draw/drawstyle_classic.c
@@ -25,6 +25,7 @@
*/
#include "BIF_gl.h"
+#include "BIF_glutil.h"
#include "BLF_api.h"
@@ -141,6 +142,124 @@ static void widget_roundbut(uiWidgetColors *wcol, rcti *rect, int UNUSED(state),
widget_drawbase_draw(&wtb, wcol);
}
+static void widget_hsv_circle(
+ uiBut *but, uiWidgetColors *wcol, rcti *rect,
+ int UNUSED(state), int UNUSED(roundboxalign))
+{
+ const int tot = 64;
+ const float radstep = 2.0f * (float)M_PI / (float)tot;
+ const float centx = BLI_rcti_cent_x_fl(rect);
+ const float centy = BLI_rcti_cent_y_fl(rect);
+ float radius = (float)min_ii(BLI_rcti_size_x(rect), BLI_rcti_size_y(rect)) / 2.0f;
+
+ /* gouraud triangle fan */
+ ColorPicker *cpicker = but->custom_data;
+ const float *hsv_ptr = cpicker->color_data;
+ float xpos, ypos, ang = 0.0f;
+ float rgb[3], hsvo[3], hsv[3], col[3], colcent[3];
+ int a;
+ bool color_profile = ui_but_is_colorpicker_display_space(but);
+
+ /* color */
+ ui_but_v3_get(but, rgb);
+
+ /* since we use compat functions on both 'hsv' and 'hsvo', they need to be initialized */
+ hsvo[0] = hsv[0] = hsv_ptr[0];
+ hsvo[1] = hsv[1] = hsv_ptr[1];
+ hsvo[2] = hsv[2] = hsv_ptr[2];
+
+ if (color_profile)
+ ui_block_cm_to_display_space_v3(but->block, rgb);
+
+ ui_rgb_to_color_picker_compat_v(rgb, hsv);
+ copy_v3_v3(hsvo, hsv);
+
+ CLAMP(hsv[2], 0.0f, 1.0f); /* for display only */
+
+ /* exception: if 'lock' is set
+ * lock the value of the color wheel to 1.
+ * Useful for color correction tools where you're only interested in hue. */
+ if (but->flag & UI_BUT_COLOR_LOCK) {
+ if (U.color_picker_type == USER_CP_CIRCLE_HSV)
+ hsv[2] = 1.0f;
+ else
+ hsv[2] = 0.5f;
+ }
+
+ ui_color_picker_to_rgb(0.0f, 0.0f, hsv[2], colcent, colcent + 1, colcent + 2);
+
+ glShadeModel(GL_SMOOTH);
+
+ glBegin(GL_TRIANGLE_FAN);
+ glColor3fv(colcent);
+ glVertex2f(centx, centy);
+
+ for (a = 0; a <= tot; a++, ang += radstep) {
+ float si = sinf(ang);
+ float co = cosf(ang);
+
+ ui_hsvcircle_vals_from_pos(hsv, hsv + 1, rect, centx + co * radius, centy + si * radius);
+
+ ui_color_picker_to_rgb_v(hsv, col);
+
+ glColor3fv(col);
+ glVertex2f(centx + co * radius, centy + si * radius);
+ }
+ glEnd();
+
+ glShadeModel(GL_FLAT);
+
+ /* fully rounded outline */
+ glPushMatrix();
+ glTranslatef(centx, centy, 0.0f);
+ glEnable(GL_BLEND);
+ glEnable(GL_LINE_SMOOTH);
+ glColor3ubv((unsigned char *)wcol->outline);
+ glutil_draw_lined_arc(0.0f, M_PI * 2.0, radius, tot + 1);
+ glDisable(GL_BLEND);
+ glDisable(GL_LINE_SMOOTH);
+ glPopMatrix();
+
+ /* cursor */
+ ui_hsvcircle_pos_from_vals(but, rect, hsvo, &xpos, &ypos);
+
+ ui_hsv_cursor(xpos, ypos);
+}
+
+static void widget_hsv_cube(
+ uiBut *but, uiWidgetColors *UNUSED(wcol), rcti *rect,
+ int UNUSED(state), int UNUSED(roundboxalign))
+{
+ float rgb[3];
+ float x = 0.0f, y = 0.0f;
+ ColorPicker *cpicker = but->custom_data;
+ float *hsv = cpicker->color_data;
+ float hsv_n[3];
+ bool use_display_colorspace = ui_but_is_colorpicker_display_space(but);
+
+ copy_v3_v3(hsv_n, hsv);
+
+ ui_but_v3_get(but, rgb);
+
+ if (use_display_colorspace)
+ ui_block_cm_to_display_space_v3(but->block, rgb);
+
+ rgb_to_hsv_compat_v(rgb, hsv_n);
+
+ ui_draw_gradient(rect, hsv_n, but->a1, 1.0f);
+
+ ui_hsvcube_pos_from_vals(but, rect, hsv_n, &x, &y);
+ CLAMP(x, rect->xmin + 3.0f, rect->xmax - 3.0f);
+ CLAMP(y, rect->ymin + 3.0f, rect->ymax - 3.0f);
+
+ ui_hsv_cursor(x, y);
+
+ /* outline */
+ glColor3ub(0, 0, 0);
+ fdrawbox((rect->xmin), (rect->ymin), (rect->xmax), (rect->ymax));
+}
+
+
static void widget_hsv_vert(
uiBut *but, uiWidgetColors *UNUSED(wcol), rcti *rect,
int UNUSED(state), int UNUSED(roundboxalign))
@@ -1033,6 +1152,20 @@ uiWidgetDrawType drawtype_classic_exec = {
/* text */ widget_draw_text_icon,
};
+uiWidgetDrawType drawtype_classic_hsv_circle = {
+ /* state */ NULL,
+ /* draw */ NULL,
+ /* custom */ widget_hsv_circle,
+ /* text */ NULL,
+};
+
+uiWidgetDrawType drawtype_classic_hsv_cube = {
+ /* state */ NULL,
+ /* draw */ NULL,
+ /* custom */ widget_hsv_cube,
+ /* text */ NULL,
+};
+
uiWidgetDra
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list