[Bf-blender-cvs] [e53e6013229] greasepencil-object: GPencil: Add new buttons to move Up/Down colors in Palette
Antonio Vazquez
noreply at git.blender.org
Mon Nov 18 10:21:18 CET 2019
Commit: e53e6013229f46ea4f277718874c5379d785ea39
Author: Antonio Vazquez
Date: Mon Nov 18 10:19:31 2019 +0100
Branches: greasepencil-object
https://developer.blender.org/rBe53e6013229f46ea4f277718874c5379d785ea39
GPencil: Add new buttons to move Up/Down colors in Palette
===================================================================
M source/blender/editors/interface/interface_templates.c
M source/blender/editors/sculpt_paint/paint_ops.c
===================================================================
diff --git a/source/blender/editors/interface/interface_templates.c b/source/blender/editors/interface/interface_templates.c
index 021d7733fae..5f47ad8d4ec 100644
--- a/source/blender/editors/interface/interface_templates.c
+++ b/source/blender/editors/interface/interface_templates.c
@@ -4745,6 +4745,8 @@ void uiTemplatePalette(uiLayout *layout,
PaletteColor *color;
uiBlock *block;
uiLayout *col;
+ uiBut *but = NULL;
+
int row_cols = 0, col_id = 0;
int cols_per_row = MAX2(uiLayoutGetWidth(layout) / UI_UNIT_X, 1);
@@ -4786,6 +4788,33 @@ void uiTemplatePalette(uiLayout *layout,
UI_UNIT_X,
UI_UNIT_Y,
NULL);
+ if (color) {
+ but = uiDefIconButO(block,
+ UI_BTYPE_BUT,
+ "PALETTE_OT_color_move",
+ WM_OP_INVOKE_DEFAULT,
+ ICON_TRIA_UP,
+ 0,
+ 0,
+ UI_UNIT_X,
+ UI_UNIT_Y,
+ NULL);
+ UI_but_operator_ptr_get(but);
+ RNA_enum_set(but->opptr, "type", -1);
+
+ but = uiDefIconButO(block,
+ UI_BTYPE_BUT,
+ "PALETTE_OT_color_move",
+ WM_OP_INVOKE_DEFAULT,
+ ICON_TRIA_DOWN,
+ 0,
+ 0,
+ UI_UNIT_X,
+ UI_UNIT_Y,
+ NULL);
+ UI_but_operator_ptr_get(but);
+ RNA_enum_set(but->opptr, "type", 1);
+ }
col = uiLayoutColumn(layout, true);
uiLayoutRow(col, true);
diff --git a/source/blender/editors/sculpt_paint/paint_ops.c b/source/blender/editors/sculpt_paint/paint_ops.c
index 4423719b2fb..7da81ecf2ba 100644
--- a/source/blender/editors/sculpt_paint/paint_ops.c
+++ b/source/blender/editors/sculpt_paint/paint_ops.c
@@ -481,6 +481,51 @@ void PALETTE_OT_sort(wmOperatorType *ot)
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
}
+/* Move colors in palette. */
+static int palette_color_move_exec(bContext *C, wmOperator *op)
+{
+ Paint *paint = BKE_paint_get_active_from_context(C);
+ Palette *palette = paint->palette;
+ PaletteColor *palcolor = BLI_findlink(&palette->colors, palette->active_color);
+
+ if (palcolor == NULL) {
+ return OPERATOR_CANCELLED;
+ }
+
+ const int direction = RNA_enum_get(op->ptr, "type");
+
+ BLI_assert(ELEM(direction, -1, 0, 1)); /* we use value below */
+ if (BLI_listbase_link_move(&palette->colors, palcolor, direction)) {
+ palette->active_color += direction;
+ WM_event_add_notifier(C, NC_BRUSH | NA_EDITED, NULL);
+ }
+
+ return OPERATOR_FINISHED;
+}
+
+void PALETTE_OT_color_move(wmOperatorType *ot)
+{
+ static const EnumPropertyItem slot_move[] = {
+ {-1, "UP", 0, "Up", ""},
+ {1, "DOWN", 0, "Down", ""},
+ {0, NULL, 0, NULL, NULL},
+ };
+
+ /* identifiers */
+ ot->name = "Move Palette Color";
+ ot->idname = "PALETTE_OT_color_move";
+ ot->description = "Move the active Color up/down in the list";
+
+ /* api callbacks */
+ ot->exec = palette_color_move_exec;
+ ot->poll = palette_sort_poll;
+
+ /* flags */
+ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+
+ ot->prop = RNA_def_enum(ot->srna, "type", slot_move, 0, "Type", "");
+}
+
/* Join Palette swatches. */
static bool palette_join_poll(bContext *C)
{
@@ -1230,6 +1275,7 @@ void ED_operatortypes_paint(void)
WM_operatortype_append(PALETTE_OT_extract_from_image);
WM_operatortype_append(PALETTE_OT_sort);
+ WM_operatortype_append(PALETTE_OT_color_move);
WM_operatortype_append(PALETTE_OT_join);
/* paint curve */
More information about the Bf-blender-cvs
mailing list