[Bf-blender-cvs] [c9c2e888e28] greasepencil-object: GP Color Picker: Highlight the color under the mouse

Joshua Leung noreply at git.blender.org
Tue Feb 6 15:05:47 CET 2018


Commit: c9c2e888e28cc8f592bc24b97fb8c3ac9e93fa24
Author: Joshua Leung
Date:   Wed Feb 7 02:36:24 2018 +1300
Branches: greasepencil-object
https://developer.blender.org/rBc9c2e888e28cc8f592bc24b97fb8c3ac9e93fa24

GP Color Picker: Highlight the color under the mouse

Previously, the color picker provided no feedback on which
color under the mouse would get applied when clicking.
It also wasn't that clear what the current active color
was.

This commit fixes this, making the UI feel more like a
standard Blender menu/popup, and less like a glitchy
non-interactive graphic, by drawing a highlight rect
behind the item currently under the mouse. By default,
the current/active color will be highlighted before
the mouse enters the panel.

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

M	source/blender/editors/gpencil/gpencil_colorpick.c
M	source/blender/editors/gpencil/gpencil_intern.h

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

diff --git a/source/blender/editors/gpencil/gpencil_colorpick.c b/source/blender/editors/gpencil/gpencil_colorpick.c
index 813b66b5903..26908695ef6 100644
--- a/source/blender/editors/gpencil/gpencil_colorpick.c
+++ b/source/blender/editors/gpencil/gpencil_colorpick.c
@@ -129,10 +129,11 @@ static void gpencil_draw_color_table(const bContext *UNUSED(C), tGPDpick *tgpk)
 		return;
 	}
 	const uiFontStyle *fstyle = UI_FSTYLE_WIDGET;
-	float ink[4];
+	float background[4];
 	float line[4];
+	float selcolor[4];
+	float wcolor[4] = { 0.9f, 0.9f, 0.9f, 0.8f };  // <--- XXX, why?
 	float radius = (0.2f * U.widget_unit);
-	float wcolor[4] = { 0.9f, 0.9f, 0.9f, 0.8f };
 
 	/* boxes for stroke and fill color */
 	rcti sbox;
@@ -140,16 +141,19 @@ static void gpencil_draw_color_table(const bContext *UNUSED(C), tGPDpick *tgpk)
 
 	bTheme *btheme = UI_GetTheme();
 	uiWidgetColors menuBack = btheme->tui.wcol_menu_back;
+	uiWidgetColors menuItem = btheme->tui.wcol_menu_item;
 
 	rgba_uchar_to_float(line, menuBack.outline);
-	rgba_uchar_to_float(ink, menuBack.inner);
+	rgba_uchar_to_float(background, menuBack.inner);
+	rgba_uchar_to_float(selcolor, menuItem.inner_sel);
 
 	/* draw panel background */
+	/* TODO: Draw soft drop shadow behind this (like standard menus)? */
 	glEnable(GL_BLEND);
 	UI_draw_roundbox_corner_set(UI_CNR_ALL);
 	UI_draw_roundbox_4fv(true, tgpk->panel.xmin, tgpk->panel.ymin,
 						tgpk->panel.xmax, tgpk->panel.ymax,
-						radius, ink);
+						radius, background);
 	glDisable(GL_BLEND);
 
 	/* draw color boxes */
@@ -172,10 +176,16 @@ static void gpencil_draw_color_table(const bContext *UNUSED(C), tGPDpick *tgpk)
 		fbox.xmax = col->rect.xmax;
 		fbox.ymax = col->rect.ymax - scaley;
 
-		/* focus to current color */
-		if (tgpk->palette->active_color == col->index) {
-			focus = true;
+		/* highlight background of item under mouse */
+		if (i == tgpk->curindex) {
+			/* TODO: How to get the menu gradient shading? */
+			rcti *cbox = &col->full_rect;
+			UI_draw_roundbox_4fv(true,
+			                     cbox->xmin, cbox->ymin,
+			                     cbox->xmax, cbox->ymax,
+			                     0, selcolor);
 		}
+
 		/* fill box */
 		UI_draw_roundbox_4fv(true, fbox.xmin, fbox.ymin, fbox.xmax, fbox.ymax, radius, wcolor);
 		gp_draw_pattern_box(fbox.xmin + 2, fbox.ymin + 2, fbox.xmax - 2, fbox.ymax - 2);
@@ -280,6 +290,7 @@ static tGPDpick *gp_session_init_colorpick(bContext *C, wmOperator *op, const wm
 
 	/* allocate color table */
 	tgpk->totcolor = get_tot_colors(tgpk);
+	tgpk->curindex = tgpk->palette->active_color;
 	if (tgpk->totcolor > 0) {
 		tgpk->colors = MEM_callocN(sizeof(tGPDpickColor) * tgpk->totcolor, "gp_colorpicker");
 	}
@@ -371,6 +382,13 @@ static tGPDpick *gp_session_init_colorpick(bContext *C, wmOperator *op, const wm
 		tcolor->rect.ymax = tgpk->panel.ymax - (tgpk->boxsize[1] * row) - (GP_BOX_GAP * row) - (GP_BOX_GAP / 2);
 		tcolor->rect.ymin = tcolor->rect.ymax - tgpk->boxsize[0];
 
+		/* "full" hit region  (used for UI highlight and event testing) */
+		// XXX: It would be nice to have these larger, to allow for a less laggy feel (due the hit-region misses)
+		tcolor->full_rect.xmin = tcolor->rect.xmin - (GP_BOX_GAP / 4);
+		tcolor->full_rect.xmax = tcolor->rect.xmax + (GP_BOX_GAP / 4);
+		tcolor->full_rect.ymin = tcolor->rect.ymin - (GP_BOX_GAP / 4);
+		tcolor->full_rect.ymax = tcolor->rect.ymax + (GP_BOX_GAP / 4);
+
 		idx++;
 		row++;
 		tcolor++;
@@ -469,23 +487,19 @@ static int gpencil_colorpick_invoke(bContext *C, wmOperator *op, const wmEvent *
 	return OPERATOR_RUNNING_MODAL;
 }
 
-/* set active color when user select one box of the toolbar */
-static bool set_color(const wmEvent *event, tGPDpick *tgpk)
+/* get active color under the cursor */
+/* FIXME: Can we do this without looping? */
+static int gpencil_colorpick_index_from_mouse(const tGPDpick *tgpk, const wmEvent *event)
 {
 	tGPDpickColor *tcol = tgpk->colors;
-	/* if click out of panel, end */
-	if (!BLI_rcti_isect_pt_v(&tgpk->panel, event->mval)) {
-		return true;
-	}
 
 	for (int i = 0; i < tgpk->totcolor; i++, tcol++) {
-		if (BLI_rcti_isect_pt_v(&tcol->rect, event->mval)) {
-			tgpk->palette->active_color = tcol->index;
-			return true;
+		if (BLI_rcti_isect_pt_v(&tcol->full_rect, event->mval)) {
+			return tcol->index;
 		}
 	}
 
-	return false;
+	return -1;
 }
 
 /* events handling during interactive part of operator */
@@ -502,9 +516,29 @@ static int gpencil_colorpick_modal(bContext *C, wmOperator *op, const wmEvent *e
 		case RIGHTMOUSE:
 			estate = OPERATOR_CANCELLED;
 			break;
+
 		case LEFTMOUSE:
-			if (set_color(event, tgpk) == true) {
-				estate = OPERATOR_FINISHED;
+			if (!BLI_rcti_isect_pt_v(&tgpk->panel, event->mval)) {
+				/* if click out of panel, end */
+				estate = OPERATOR_CANCELLED;
+			}
+			else {
+				int index = gpencil_colorpick_index_from_mouse(tgpk, event);
+				if (index != -1) {
+					tgpk->palette->active_color = index;
+					estate = OPERATOR_FINISHED;
+				}
+			}
+			break;
+
+		case MOUSEMOVE:
+			if (BLI_rcti_isect_pt_v(&tgpk->panel, event->mval)) {
+				int index = gpencil_colorpick_index_from_mouse(tgpk, event);
+				if (index != -1) {
+					/* don't update active color if we move outside the grid */
+					tgpk->curindex = index;
+					ED_region_tag_redraw(CTX_wm_region(C));
+				}
 			}
 			break;
 	}
diff --git a/source/blender/editors/gpencil/gpencil_intern.h b/source/blender/editors/gpencil/gpencil_intern.h
index 47dd7d6e411..02a279d5670 100644
--- a/source/blender/editors/gpencil/gpencil_intern.h
+++ b/source/blender/editors/gpencil/gpencil_intern.h
@@ -201,6 +201,7 @@ typedef struct tGPDfill {
 /* Temporary color picker operation data */
 typedef struct tGPDpickColor {
 	char name[64];   /* color name. Must be unique. */
+	rcti full_rect;  /* full size of region occupied by color box (for event/highlight handling) */
 	rcti rect;       /* box position */
 	int index;       /* index of color in palette */
 	float rgba[4];   /* color */
@@ -226,6 +227,7 @@ typedef struct tGPDpick {
 	int boxsize[2];                     /* size of each box color */
 
 	int totcolor;                       /* number of colors */
+	int curindex;                       /* index of color under cursor */
 	tGPDpickColor *colors;              /* colors of palette */
 
 	void *draw_handle_3d;               /* handle for drawing strokes while operator is running */



More information about the Bf-blender-cvs mailing list