[gimp/gimp-2-10] app: draw border around FG/BG-editor color areas



commit 38a9e808211f0a80a7f6966df52b89fb1280d405
Author: Ell <ell_se yahoo com>
Date:   Sat Feb 22 15:32:54 2020 +0200

    app: draw border around FG/BG-editor color areas
    
    In GimpFgBgEditor, we currently use gtk_render_frame() in master,
    and gtk_paint_shadow() in gimp-2-10, to draw a border around the
    color FG/BG color areas.  However, the former is relatively
    subtle, especially with dark themes, and the latter is a NOP with
    the pixmap engine, which is what our built-in themes use.
    
    Instead, draw the border ourselves as a pair of black and white
    rectangles, similarly to Photoshop.
    
    Move the entire color-frame drawing functionality to a separate
    function, to avoid code duplication between the FG and BG frames.
    
    (cherry picked from commit fb1c0860974fa7b3734e162afb193040d11f9678)

 app/widgets/gimpfgbgeditor.c | 248 ++++++++++++++++++++-----------------------
 1 file changed, 116 insertions(+), 132 deletions(-)
---
diff --git a/app/widgets/gimpfgbgeditor.c b/app/widgets/gimpfgbgeditor.c
index 982c3e1066..96d2156e3a 100644
--- a/app/widgets/gimpfgbgeditor.c
+++ b/app/widgets/gimpfgbgeditor.c
@@ -105,6 +105,16 @@ static void     gimp_fg_bg_editor_destroy_transform (GimpFgBgEditor   *editor);
 static void     gimp_fg_bg_editor_image_changed     (GimpFgBgEditor   *editor,
                                                      GimpImage        *image);
 
+static void     gimp_fg_bg_editor_draw_color_frame  (GimpFgBgEditor   *editor,
+                                                     cairo_t          *cr,
+                                                     const GimpRGB    *color,
+                                                     gint              x,
+                                                     gint              y,
+                                                     gint              width,
+                                                     gint              height,
+                                                     gint              corner_dx,
+                                                     gint              corner_dy);
+
 G_DEFINE_TYPE (GimpFgBgEditor, gimp_fg_bg_editor, GTK_TYPE_EVENT_BOX)
 
 #define parent_class gimp_fg_bg_editor_parent_class
@@ -259,19 +269,14 @@ static gboolean
 gimp_fg_bg_editor_expose (GtkWidget      *widget,
                           GdkEventExpose *eevent)
 {
-  GimpFgBgEditor    *editor = GIMP_FG_BG_EDITOR (widget);
-  GtkStyle          *style  = gtk_widget_get_style (widget);
-  GdkWindow         *window = gtk_widget_get_window (widget);
-  cairo_t           *cr;
-  GimpPalette       *colormap_palette = NULL;
-  GtkAllocation      allocation;
-  gint               width, height;
-  gint               default_w, default_h;
-  gint               swap_w, swap_h;
-  gint               rect_w, rect_h;
-  GimpRGB            color;
-  GimpRGB            transformed_color;
-  GimpImageBaseType  base_type = GIMP_RGB;
+  GimpFgBgEditor *editor = GIMP_FG_BG_EDITOR (widget);
+  cairo_t        *cr;
+  GtkAllocation   allocation;
+  gint            width, height;
+  gint            default_w, default_h;
+  gint            swap_w, swap_h;
+  gint            rect_w, rect_h;
+  GimpRGB         color;
 
   if (! gtk_widget_is_drawable (widget))
     return FALSE;
@@ -335,136 +340,27 @@ gimp_fg_bg_editor_expose (GtkWidget      *widget,
   editor->rect_width  = rect_w;
   editor->rect_height = rect_h;
 
-
   if (! editor->transform)
     gimp_fg_bg_editor_create_transform (editor);
 
-  if (editor->active_image)
-    {
-      base_type = gimp_image_get_base_type (editor->active_image);
-
-      if (base_type == GIMP_INDEXED)
-        colormap_palette = gimp_image_get_colormap_palette (editor->active_image);
-    }
-
-  /*  draw the background area  */
-
   if (editor->context)
     {
+      /*  draw the background frame  */
       gimp_context_get_background (editor->context, &color);
-
-      if (editor->transform)
-        gimp_color_transform_process_pixels (editor->transform,
-                                             babl_format ("R'G'B'A double"),
-                                             &color,
-                                             babl_format ("R'G'B'A double"),
-                                             &transformed_color,
-                                             1);
-      else
-        transformed_color = color;
-
-      gimp_cairo_set_source_rgb (cr, &transformed_color);
-
-      cairo_rectangle (cr,
-                       width - rect_w,
-                       height - rect_h,
-                       rect_w,
-                       rect_h);
-      cairo_fill (cr);
-
-
-      if (editor->color_config &&
-          /* Common out-of-gamut case */
-          ((color.r < 0.0 || color.r > 1.0 ||
-            color.g < 0.0 || color.g > 1.0 ||
-            color.b < 0.0 || color.b > 1.0) ||
-           /* Indexed images */
-           (colormap_palette && ! gimp_palette_find_entry (colormap_palette, &color, NULL)) ||
-           /* Grayscale images */
-           (base_type == GIMP_GRAY &&
-            (ABS (color.r - color.g) > CHANNEL_EPSILON ||
-             ABS (color.r - color.b) > CHANNEL_EPSILON ||
-             ABS (color.g - color.b) > CHANNEL_EPSILON))))
-        {
-          gint side = MIN (rect_w, rect_h) * 2 / 3;
-
-          cairo_move_to (cr, width, height);
-          cairo_line_to (cr, width - side, height);
-          cairo_line_to (cr, width, height - side);
-          cairo_line_to (cr, width, height);
-
-          gimp_cairo_set_source_rgb (cr,
-                                     &editor->color_config->out_of_gamut_color);
-          cairo_fill (cr);
-        }
-    }
-
-  gtk_paint_shadow (style, window, GTK_STATE_NORMAL,
-                    editor->active_color == GIMP_ACTIVE_COLOR_FOREGROUND ?
-                    GTK_SHADOW_OUT : GTK_SHADOW_IN,
-                    NULL, widget, NULL,
-                    allocation.x + (width - rect_w),
-                    allocation.y + (height - rect_h),
-                    rect_w, rect_h);
+      gimp_fg_bg_editor_draw_color_frame (editor, cr, &color,
+                                          width - rect_w, height - rect_h,
+                                          rect_w,         rect_h,
+                                          +1,             +1);
 
 
-  /*  draw the foreground area  */
-
-  if (editor->context)
-    {
+      /*  draw the foreground frame  */
       gimp_context_get_foreground (editor->context, &color);
-
-      if (editor->transform)
-        gimp_color_transform_process_pixels (editor->transform,
-                                             babl_format ("R'G'B'A double"),
-                                             &color,
-                                             babl_format ("R'G'B'A double"),
-                                             &transformed_color,
-                                             1);
-      else
-        transformed_color = color;
-
-      gimp_cairo_set_source_rgb (cr, &transformed_color);
-
-      cairo_rectangle (cr,
-                       0, 0,
-                       rect_w, rect_h);
-      cairo_fill (cr);
-
-      if (editor->color_config &&
-          /* Common out-of-gamut case */
-          ((color.r < 0.0 || color.r > 1.0 ||
-            color.g < 0.0 || color.g > 1.0 ||
-            color.b < 0.0 || color.b > 1.0) ||
-           /* Indexed images */
-           (colormap_palette && ! gimp_palette_find_entry (colormap_palette, &color, NULL)) ||
-           /* Grayscale images */
-           (base_type == GIMP_GRAY &&
-            (ABS (color.r - color.g) > CHANNEL_EPSILON ||
-             ABS (color.r - color.b) > CHANNEL_EPSILON ||
-             ABS (color.g - color.b) > CHANNEL_EPSILON))))
-        {
-          gint side = MIN (rect_w, rect_h) * 2 / 3;
-
-          cairo_move_to (cr, 0, 0);
-          cairo_line_to (cr, 0, side);
-          cairo_line_to (cr, side, 0);
-          cairo_line_to (cr, 0, 0);
-
-          gimp_cairo_set_source_rgb (cr,
-                                     &editor->color_config->out_of_gamut_color);
-          cairo_fill (cr);
-        }
+      gimp_fg_bg_editor_draw_color_frame (editor, cr, &color,
+                                          0,              0,
+                                          rect_w,         rect_h,
+                                          -1,             -1);
     }
 
-  gtk_paint_shadow (style, window, GTK_STATE_NORMAL,
-                    editor->active_color == GIMP_ACTIVE_COLOR_BACKGROUND ?
-                    GTK_SHADOW_OUT : GTK_SHADOW_IN,
-                    NULL, widget, NULL,
-                    allocation.x,
-                    allocation.y,
-                    rect_w, rect_h);
-
   cairo_destroy (cr);
 
   return TRUE;
@@ -838,3 +734,91 @@ gimp_fg_bg_editor_image_changed (GimpFgBgEditor *editor,
         }
     }
 }
+
+static void
+gimp_fg_bg_editor_draw_color_frame (GimpFgBgEditor *editor,
+                                    cairo_t        *cr,
+                                    const GimpRGB  *color,
+                                    gint            x,
+                                    gint            y,
+                                    gint            width,
+                                    gint            height,
+                                    gint            corner_dx,
+                                    gint            corner_dy)
+{
+  GimpPalette       *colormap_palette = NULL;
+  GimpImageBaseType  base_type        = GIMP_RGB;
+  GimpRGB            transformed_color;
+
+  if (editor->active_image)
+    {
+      base_type = gimp_image_get_base_type (editor->active_image);
+
+      if (base_type == GIMP_INDEXED)
+        {
+          colormap_palette = gimp_image_get_colormap_palette (
+            editor->active_image);
+        }
+    }
+
+  if (editor->transform)
+    {
+      gimp_color_transform_process_pixels (editor->transform,
+                                           babl_format ("R'G'B'A double"),
+                                           color,
+                                           babl_format ("R'G'B'A double"),
+                                           &transformed_color,
+                                           1);
+    }
+  else
+    {
+      transformed_color = *color;
+    }
+
+  cairo_save (cr);
+
+  gimp_cairo_set_source_rgb (cr, &transformed_color);
+
+  cairo_rectangle (cr, x, y, width, height);
+  cairo_fill (cr);
+
+  if (editor->color_config &&
+      /* Common out-of-gamut case */
+      ((color->r < 0.0 || color->r > 1.0 ||
+        color->g < 0.0 || color->g > 1.0 ||
+        color->b < 0.0 || color->b > 1.0) ||
+       /* Indexed images */
+       (colormap_palette &&
+        ! gimp_palette_find_entry (colormap_palette, color, NULL)) ||
+       /* Grayscale images */
+       (base_type == GIMP_GRAY &&
+        (ABS (color->r - color->g) > CHANNEL_EPSILON ||
+         ABS (color->r - color->b) > CHANNEL_EPSILON ||
+         ABS (color->g - color->b) > CHANNEL_EPSILON))))
+    {
+      gint corner_x = x + 0.5 * (1.0 + corner_dx) * width;
+      gint corner_y = y + 0.5 * (1.0 + corner_dy) * height;
+      gint side     = MIN (width, height) * 2 / 3;
+
+      cairo_move_to (cr, corner_x, corner_y);
+      cairo_line_to (cr, corner_x + side * corner_dx, corner_y);
+      cairo_line_to (cr, corner_x, corner_y + side * corner_dy);
+      cairo_close_path (cr);
+
+      gimp_cairo_set_source_rgb (cr,
+                                 &editor->color_config->out_of_gamut_color);
+      cairo_fill (cr);
+    }
+
+  cairo_set_line_width (cr, 1.0);
+
+  cairo_set_source_rgb (cr, 0.0, 0.0, 0.0);
+  cairo_rectangle (cr, x + 0.5, y + 0.5, width - 1.0, height - 1.0);
+  cairo_stroke (cr);
+
+  cairo_set_source_rgb (cr, 1.0, 1.0, 1.0);
+  cairo_rectangle (cr, x + 1.5, y + 1.5, width - 3.0, height - 3.0);
+  cairo_stroke (cr);
+
+  cairo_restore (cr);
+}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]