[simple-scan/wip/exalm/dark: 6/7] page-icon: Refresh colors, support dark and hc
- From: Bartosz <bkosiorek src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [simple-scan/wip/exalm/dark: 6/7] page-icon: Refresh colors, support dark and hc
- Date: Wed, 5 Jan 2022 20:39:48 +0000 (UTC)
commit feb4be5eb887c548f94afbae10d2c9468ed5fc4c
Author: Alexander Mikhaylenko <alexm gnome org>
Date: Sat Dec 25 22:35:33 2021 +0500
page-icon: Refresh colors, support dark and hc
src/app-window.vala | 34 +--------------------------
src/page-icon.vala | 68 +++++++++++++++++++++++++++++++++++++++++++----------
2 files changed, 56 insertions(+), 46 deletions(-)
---
diff --git a/src/app-window.vala b/src/app-window.vala
index f7a45bd2..59d421cb 100644
--- a/src/app-window.vala
+++ b/src/app-window.vala
@@ -1399,39 +1399,7 @@ public class AppWindow : Hdy.ApplicationWindow
box.add (page_box);
}
- /* Get colours for each page (from Tango palette) */
- var r = 1.0;
- var g = 1.0;
- var b = 1.0;
- switch (side)
- {
- case 'F':
- /* Plum */
- r = 0x75 / 255.0;
- g = 0x50 / 255.0;
- b = 0x7B / 255.0;
- break;
- case 'B':
- /* Orange */
- r = 0xF5 / 255.0;
- g = 0x79 / 255.0;
- b = 0.0;
- break;
- case 'C':
- /* Butter to Scarlet Red */
- var p = (items[i] - '1') / 5.0;
- r = (0xED / 255.0) * (1 - p) + 0xCC * p;
- g = (0xD4 / 255.0) * (1 - p);
- b = 0;
- break;
- }
-
- /* Mix with white to look more paper like */
- r = r + (1.0 - r) * 0.7;
- g = g + (1.0 - g) * 0.7;
- b = b + (1.0 - b) * 0.7;
-
- var icon = new PageIcon ("%c".printf (items[i]), r, g, b);
+ var icon = new PageIcon (side, items[i] - '1');
icon.visible = true;
page_box.add (icon);
}
diff --git a/src/page-icon.vala b/src/page-icon.vala
index 793ca5bb..f1a25ead 100644
--- a/src/page-icon.vala
+++ b/src/page-icon.vala
@@ -12,18 +12,14 @@
public class PageIcon : Gtk.DrawingArea
{
- private string text;
- private double r;
- private double g;
- private double b;
+ private char side;
+ private int position;
private const int MINIMUM_WIDTH = 20;
- public PageIcon (string text, double r = 1.0, double g = 1.0, double b = 1.0)
+ public PageIcon (char side, int position)
{
- this.text = text;
- this.r = r;
- this.g = g;
- this.b = b;
+ this.side = side;
+ this.position = position;
}
public override void get_preferred_width (out int minimum_width, out int natural_width)
@@ -57,15 +53,61 @@ public class PageIcon : Gtk.DrawingArea
c.translate ((get_allocated_width () - w) / 2, (get_allocated_height () - h) / 2);
- c.rectangle (0.5, 0.5, w - 1, h - 1);
+ bool dark = Hdy.StyleManager.get_default ().dark;
+ bool hc = Hdy.StyleManager.get_default ().high_contrast;
+
+ if (dark && !hc)
+ c.rectangle (1, 1, w - 2, h - 2);
+ else
+ c.rectangle (0, 0, w, h);
+
+ Gdk.RGBA rgba = {};
+
+ switch (side)
+ {
+ case 'F':
+ /* Purple 2 */
+ rgba.parse ("#c061cb");
+ break;
+ case 'B':
+ /* Orange 3 */
+ rgba.parse ("#ff7800");
+ break;
+ default:
+ /* Yellow 3 to Red 2 */
+ Gdk.RGBA start = {}, end = {};
+ start.parse ("#f6d32d");
+ end.parse ("#ed333b");
+
+ double progress = position / 5.0;
+ rgba.red = start.red + (end.red - start.red) * progress;
+ rgba.green = start.green + (end.green - start.green) * progress;
+ rgba.blue = start.blue + (end.blue - start.blue) * progress;
+ break;
+ }
- c.set_source_rgb (r, g, b);
- c.fill_preserve ();
+ rgba.alpha = 0.3;
+
+ Gdk.cairo_set_source_rgba (c, rgba);
+ c.fill ();
c.set_line_width (1.0);
- c.set_source_rgb (0.0, 0.0, 0.0);
+ if (hc && dark)
+ c.set_source_rgba (1, 1, 1, 0.5);
+ else if (hc)
+ c.set_source_rgba (0, 0, 0, 0.5);
+ else
+ c.set_source_rgba (0, 0, 0, 0.15);
+
+ c.rectangle (0.5, 0.5, w - 1, h - 1);
c.stroke ();
+ if (dark)
+ c.set_source_rgb (1, 1, 1);
+ else
+ c.set_source_rgb (0, 0, 0);
+
+ var text = @"$(position + 1)";
Cairo.TextExtents extents;
c.text_extents (text, out extents);
c.translate ((w - extents.width) * 0.5 - 0.5, (h + extents.height) * 0.5 - 0.5);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]