Commit: f4ddb89ae12be93334b5f238c5549e17658c24d6
Author: Antony Riakiotakis
Date:   Wed Jul 16 00:24:33 2014 +0300
https://developer.blender.org/rBf4ddb89ae12be93334b5f238c5549e17658c24d6

Palettes:

Functionality review:

Include "active palette color" concept, marked by triangular widget.
This is set when adding and selecting a palette color.
Add explicit delete operator that removes the active palette color.

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

M       source/blender/blenkernel/BKE_paint.h
M       source/blender/blenkernel/intern/paint.c
M       source/blender/editors/include/UI_interface.h
M       source/blender/editors/interface/interface_handlers.c
M       source/blender/editors/interface/interface_intern.h
M       source/blender/editors/interface/interface_templates.c
M       source/blender/editors/interface/interface_widgets.c
M       source/blender/editors/sculpt_paint/paint_ops.c
M       source/blender/makesdna/DNA_brush_types.h

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

diff --git a/source/blender/blenkernel/BKE_paint.h 
b/source/blender/blenkernel/BKE_paint.h
index 66f4dac..0bdac68 100644
--- a/source/blender/blenkernel/BKE_paint.h
+++ b/source/blender/blenkernel/BKE_paint.h
@@ -100,9 +100,9 @@ void BKE_paint_set_overlay_override(enum OverlayFlags flag);
 void                 BKE_palette_free(struct Palette *palette);
 struct Palette      *BKE_palette_add(struct Main *bmain, const char *name);
 struct PaletteColor *BKE_palette_color_add(struct Palette *palette);
-struct PaletteColor *BKE_palette_color_get_last(struct Palette *palette);
+void                 BKE_palette_color_delete(struct Palette *palette);
 bool                 BKE_palette_is_empty(const struct Palette *palette);
-void                 BKE_palette_color_remove(struct Palette *palette, struct 
PaletteColor *colour);
+void                 BKE_palette_color_remove(struct Palette *palette, struct 
PaletteColor *color);
 void                 BKE_palette_cleanup(struct Palette *palette);
 
 /* paint curves */
diff --git a/source/blender/blenkernel/intern/paint.c 
b/source/blender/blenkernel/intern/paint.c
index 1d5bb14..48211f2 100644
--- a/source/blender/blenkernel/intern/paint.c
+++ b/source/blender/blenkernel/intern/paint.c
@@ -312,11 +312,11 @@ void BKE_paint_curve_set(Brush *br, PaintCurve *pc)
        }
 }
 
-/* remove colour from palette. Must be certain colour is inside the palette! */
-void BKE_palette_color_remove(Palette *palette, PaletteColor *colour)
+/* remove colour from palette. Must be certain color is inside the palette! */
+void BKE_palette_color_remove(Palette *palette, PaletteColor *color)
 {
-       BLI_remlink(&palette->colors, colour);
-       BLI_addhead(&palette->deleted, colour);
+       BLI_remlink(&palette->colors, color);
+       BLI_addhead(&palette->deleted, color);
 }
 
 void BKE_palette_cleanup(Palette *palette)
@@ -346,14 +346,24 @@ PaletteColor *BKE_palette_color_add(Palette *palette)
 {
        PaletteColor *color = MEM_callocN(sizeof(*color), "Pallete Color");
        BLI_addtail(&palette->colors, color);
+       palette->active_color = BLI_countlist(&palette->colors) - 1;
        return color;
 }
 
-struct PaletteColor *BKE_palette_color_get_last(struct Palette *palette)
+void BKE_palette_color_delete(struct Palette *palette)
 {
-       return palette->colors.last;
+       PaletteColor *color = BLI_findlink(&palette->colors, 
palette->active_color);
+
+       if(color) {
+               if ((color == palette->colors.last) && (palette->colors.last != 
palette->colors.first))
+                       palette->active_color--;
+
+               BLI_remlink(&palette->colors, color);
+               BLI_addhead(&palette->deleted, color);
+       }
 }
 
+
 bool BKE_palette_is_empty(const struct Palette *palette)
 {
        return BLI_listbase_is_empty(&palette->colors);
diff --git a/source/blender/editors/include/UI_interface.h 
b/source/blender/editors/include/UI_interface.h
index ad17ef4..c73efa1 100644
--- a/source/blender/editors/include/UI_interface.h
+++ b/source/blender/editors/include/UI_interface.h
@@ -291,7 +291,8 @@ typedef enum {
 #define UI_GRAD_V_ALT   9
 #define UI_GRAD_L_ALT   10
 
-#define UI_COLOR_PALETTE 20
+#define UI_PALETTE_COLOR 20
+#define UI_PALETTE_COLOR_ACTIVE 1
 
 /* Drawing
  *
diff --git a/source/blender/editors/interface/interface_handlers.c 
b/source/blender/editors/interface/interface_handlers.c
index 93c820c..57aba5e 100644
--- a/source/blender/editors/interface/interface_handlers.c
+++ b/source/blender/editors/interface/interface_handlers.c
@@ -4286,7 +4286,7 @@ static int ui_do_but_COLOR(bContext *C, uiBut *but, 
uiHandleButtonData *data, co
                        ui_apply_button(C, but->block, but, data, true);
                        return WM_UI_HANDLER_BREAK;
                }
-               else if ((int)(but->a1) == UI_COLOR_PALETTE &&
+               else if ((int)(but->a1) == UI_PALETTE_COLOR &&
                         event->type == DELKEY && event->val == KM_PRESS)
                {
                        Scene *scene = CTX_data_scene(C);
@@ -4315,36 +4315,45 @@ static int ui_do_but_COLOR(bContext *C, uiBut *but, 
uiHandleButtonData *data, co
                }
 
                if (event->type == LEFTMOUSE && event->val == KM_RELEASE) {
-                       if ((int)(but->a1) == UI_COLOR_PALETTE && !event->ctrl) 
{
-                               float color[3];
-                               Scene *scene = CTX_data_scene(C);
-                               Paint *paint = BKE_paint_get_active(scene);
-                               Brush *brush = BKE_paint_brush(paint);
-
-                               if (brush->flag & BRUSH_USE_GRADIENT) {
-                                       float *target = 
&brush->gradient->data[brush->gradient->cur].r;
-
-                                       if (but->rnaprop && 
RNA_property_subtype(but->rnaprop) == PROP_COLOR_GAMMA) {
-                                               
RNA_property_float_get_array(&but->rnapoin, but->rnaprop, target);
-                                               
ui_block_to_scene_linear_v3(but->block, target);
+                       if ((int)(but->a1) == UI_PALETTE_COLOR) {
+                               Palette *palette = but->rnapoin.id.data;
+                               PaletteColor *color = but->rnapoin.data;
+                               palette->active_color = 
BLI_findindex(&palette->colors, color);
+
+                               if( !event->ctrl) {
+                                       float color[3];
+                                       Scene *scene = CTX_data_scene(C);
+                                       Paint *paint = 
BKE_paint_get_active(scene);
+                                       Brush *brush = BKE_paint_brush(paint);
+
+                                       if (brush->flag & BRUSH_USE_GRADIENT) {
+                                               float *target = 
&brush->gradient->data[brush->gradient->cur].r;
+
+                                               if (but->rnaprop && 
RNA_property_subtype(but->rnaprop) == PROP_COLOR_GAMMA) {
+                                                       
RNA_property_float_get_array(&but->rnapoin, but->rnaprop, target);
+                                                       
ui_block_to_scene_linear_v3(but->block, target);
+                                               }
+                                               else if (but->rnaprop && 
RNA_property_subtype(but->rnaprop) == PROP_COLOR) {
+                                                       
RNA_property_float_get_array(&but->rnapoin, but->rnaprop, target);
+                                               }
                                        }
-                                       else if (but->rnaprop && 
RNA_property_subtype(but->rnaprop) == PROP_COLOR) {
-                                               
RNA_property_float_get_array(&but->rnapoin, but->rnaprop, target);
+                                       else {
+                                               if (but->rnaprop && 
RNA_property_subtype(but->rnaprop) == PROP_COLOR_GAMMA) {
+                                                       
RNA_property_float_get_array(&but->rnapoin, but->rnaprop, color);
+                                                       
BKE_brush_color_set(scene, brush, color);
+                                               }
+                                               else if (but->rnaprop && 
RNA_property_subtype(but->rnaprop) == PROP_COLOR) {
+                                                       
RNA_property_float_get_array(&but->rnapoin, but->rnaprop, color);
+                                                       
ui_block_to_display_space_v3(but->block, color);
+                                                       
BKE_brush_color_set(scene, brush, color);
+                                               }
                                        }
+
+                                       button_activate_state(C, but, 
BUTTON_STATE_EXIT);
                                }
                                else {
-                                       if (but->rnaprop && 
RNA_property_subtype(but->rnaprop) == PROP_COLOR_GAMMA) {
-                                               
RNA_property_float_get_array(&but->rnapoin, but->rnaprop, color);
-                                               BKE_brush_color_set(scene, 
brush, color);
-                                       }
-                                       else if (but->rnaprop && 
RNA_property_subtype(but->rnaprop) == PROP_COLOR) {
-                                               
RNA_property_float_get_array(&but->rnapoin, but->rnaprop, color);
-                                               
ui_block_to_display_space_v3(but->block, color);
-                                               BKE_brush_color_set(scene, 
brush, color);
-                                       }
+                                       button_activate_state(C, but, 
BUTTON_STATE_MENU_OPEN);
                                }
-
-                               button_activate_state(C, but, 
BUTTON_STATE_EXIT);
                        }
                        else {
                                button_activate_state(C, but, 
BUTTON_STATE_MENU_OPEN);
diff --git a/source/blender/editors/interface/interface_intern.h 
b/source/blender/editors/interface/interface_intern.h
index cfb2ac1..830bca3 100644
--- a/source/blender/editors/interface/interface_intern.h
+++ b/source/blender/editors/interface/interface_intern.h
@@ -186,6 +186,7 @@ struct uiBut {
         * (type == LABEL),      Use (a1 == 1.0f) to use a2 as a blending 
factor (wow, this is imaginative!).
         * (type == SCROLL)      Use as scroll size.
         * (type == SEARCH_MENU) Use as number or rows.
+        * (type == COLOR)       Use as indication of color palette
         */
        float a1;
 
@@ -193,6 +194,7 @@ struct uiBut {
         * (type == NUM),        Use to store RNA 'precision' value, for 
dragging and click-step.
         * (type == LABEL),      If (a1 == 1.0f) use a2 as a blending factor.
         * (type == SEARCH_MENU) Use as number or columns.
+        * (type == COLOR)       Use as indication of active palette color
         */
        float a2;
 
diff --git a/source/blender/editors/interface/interface_templates.c 
b/source/blender/editors/interface/interface_templates.c
index 5a9b1e9..5e25c8f 100644
--- a/source/blender/editors/interface/interface_templates.c
+++ b/source/blender/editors/interface/interface_templates.c
@@ -2375,7 +2375,7 @@ void uiTemplatePalette(uiLayout *layout, PointerRNA *ptr, 
const char *propname,
        PaletteColor *color;
        uiBlock *block;
        uiLayout *col;
-       int row_cols = 0;
+       int row_cols = 0, col_id = 0;
        int cols_per_row = MAX2(uiLayoutGetWidth(layout) / UI_UNIT_X, 1);
 
        if (!prop) {
@@ -2398,7 +2398,8 @@ void uiTemplatePalette(uiLayout *layout, PointerRNA *ptr, 
const char *propname,
 
        col = uiLayoutColumn(layout, true);
        uiLayoutRow(col, true);
-       uiDefIconButO(block, BUT, "PALETTE_OT_color_add", WM_OP_INVOKE_DEFAULT, 
ICON_PLUS, 0, 0, UI_UNIT_X, UI_UNIT_Y, NULL);
+       uiDefIconButO(block, BUT, "PALETTE_OT_color_add", WM_OP_INVOKE_DEFAULT, 
ICON_ZOOMIN, 0, 0, UI_UNIT_X, UI_UNIT_Y, NULL);
+       uiDefIconButO(block, BUT, "PALETTE_OT_color_delete", 
WM_OP_INVOKE_DEFAULT, ICON_ZOOMOUT, 0, 0, UI_UNIT_X, UI_UNIT_Y, NULL);
 
        col = uiLayoutColumn(layout, true);
        uiLayoutRow(col, true);
@@ -2412,10 +2413,11 @@ void uiTemplatePalette(uiLayout *layout, PointerRNA 
*ptr, const char *propname,
                }
 
                RNA_pointer_create(&palette->id, &RNA_PaletteColor, color, 
&ptr);
-               uiDefButR(block, COLOR, 0, "", 0, 0, UI_UNIT_X, UI_UNIT_Y, 
&ptr, "color",
-                         -1, 0.0, 1.0, UI_COLOR_PALETTE, 0.0, "");
+               uiDefButR(block, COLOR, 0, "", 0, 0, UI_UNIT_X, UI_UNIT_Y, 
&ptr, "color", -1, 0.0, 1.0,
+                         UI_PALETTE_COLOR, (col_id == palette->active_color) ? 
UI_PALETTE_COLOR_ACTIVE : 0.0, "");
 
                row_cols++;
+               col_id++;
        }
 }
 
diff --git a/source/blender/editors/interface/interface_widgets.c 
b/source/blender/editors/interface/interface_widgets.c
index 6ea0a55..522e834 100644
--- a/source/blender/editors/interface/interface_widgets.c
+++ b/source/blender/editors/interface/interface_widgets.c
@@ -33,6 +33,7 @@
 #include <string.h>
 #include <assert.h>
 
+#include "DNA_brush_types.h"
 #include "DNA_screen_types.h"
 #include "DNA_userdef_types.h"
 
@@ -2825,6 +2826,17 @@ static void widget_swatch(uiBut *but, uiWidgetColors 
*wcol, rcti *rect, int stat
 
        widgetbase_draw(&wtb, wcol);
        
+       if (but->a1 == UI_PALETTE_COLOR && but->a2 == UI_PALETTE_COLOR_ACTIVE) {
+               float width = rect->xmax - rect->xmin;
+               float height = rect->ymax -

@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to