Skip to content

Commit f7489e6

Browse files
author
Lains
committed
1.0.2 - Fix the button icon contrast, re-add picker button bg
1 parent e407f64 commit f7489e6

File tree

2 files changed

+88
-6
lines changed

2 files changed

+88
-6
lines changed

src/chooser.vala

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public class Colorway.Chooser : Gtk.DrawingArea {
3131
public static unowned Chooser instance;
3232
private static Cairo.Surface surface;
3333
private static Gtk.GestureClick gesture;
34+
private static Gtk.GestureDrag drag;
3435
public Gdk.RGBA active_color;
3536
public double h;
3637
public double s;
@@ -66,6 +67,11 @@ public class Colorway.Chooser : Gtk.DrawingArea {
6667
this.add_controller (gesture);
6768
GLib.Signal.connect (gesture, "released", (GLib.Callback) gesture_press_release, null);
6869

70+
drag = new Gtk.GestureDrag ();
71+
GLib.Signal.connect (drag, "drag-begin", (GLib.Callback) gesture_drag_begin, null);
72+
GLib.Signal.connect (drag, "drag-update", (GLib.Callback) gesture_drag_update, null);
73+
this.add_controller (drag);
74+
6975
surface = new Cairo.ImageSurface (Cairo.Format.ARGB32, WIDTH, HEIGHT);
7076

7177
this.set_draw_func (draw_func);
@@ -155,4 +161,39 @@ public class Colorway.Chooser : Gtk.DrawingArea {
155161
instance.queue_draw ();
156162
}
157163

164+
private static void gesture_drag_begin (double start_x, double start_y) {
165+
xpos = start_x;
166+
ypos = start_y;
167+
168+
double new_s, new_v;
169+
xy_to_sv (xpos, ypos, out new_s, out new_v);
170+
instance.on_sv_move (new_s, new_v);
171+
instance.queue_draw ();
172+
}
173+
174+
private static void gesture_drag_update (double offset_x, double offset_y) {
175+
double _xpos, _ypos;
176+
drag.get_start_point (out _xpos, out _ypos);
177+
178+
if (_xpos + offset_x > WIDTH) {
179+
xpos = WIDTH;
180+
} else if (_xpos + offset_x < 0) {
181+
xpos = 0;
182+
} else {
183+
xpos = _xpos + offset_x;
184+
}
185+
186+
if (_ypos + offset_y > HEIGHT) {
187+
ypos = HEIGHT;
188+
} else if (_ypos + offset_y < 0) {
189+
ypos = 0;
190+
} else {
191+
ypos = _ypos + offset_y;
192+
}
193+
194+
double new_s, new_v;
195+
xy_to_sv (xpos, ypos, out new_s, out new_v);
196+
instance.on_sv_move (new_s, new_v);
197+
instance.queue_draw ();
198+
}
158199
}

src/window.vala

Lines changed: 47 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -469,17 +469,58 @@ namespace Colorway {
469469
tbox.hex = rule_color2;
470470
ubox.hex = rule_color;
471471

472-
if (contrast == "#FFFFFF") {
473-
box.light = false;
474-
sbox.light = false;
475-
tbox.light = false;
476-
ubox.light = false;
477-
} else {
472+
Gdk.RGBA gcolor = {};
473+
gcolor.parse(color);
474+
Gdk.RGBA grcolor = {};
475+
grcolor.parse(rule_color);
476+
Gdk.RGBA grcolor1 = {};
477+
grcolor1.parse(rule_color1);
478+
Gdk.RGBA grcolor2 = {};
479+
grcolor2.parse(rule_color2);
480+
481+
if (Utils.contrast_ratio(gcolor, {0,0,0,1}) > Utils.contrast_ratio(gcolor, {1,1,1,1}) + 3) {
478482
box.light = true;
483+
} else {
484+
box.light = false;
485+
}
486+
487+
if (Utils.contrast_ratio(grcolor1, {0,0,0,1}) > Utils.contrast_ratio(grcolor1, {1,1,1,1}) + 3) {
479488
sbox.light = true;
489+
} else {
490+
sbox.light = false;
491+
}
492+
493+
if (Utils.contrast_ratio(grcolor2, {0,0,0,1}) > Utils.contrast_ratio(grcolor2, {1,1,1,1}) + 3) {
480494
tbox.light = true;
495+
} else {
496+
tbox.light = false;
497+
}
498+
499+
if (Utils.contrast_ratio(grcolor, {0,0,0,1}) > Utils.contrast_ratio(grcolor, {1,1,1,1}) + 3) {
481500
ubox.light = true;
501+
} else {
502+
ubox.light = false;
503+
}
504+
505+
var css_provider = new Gtk.CssProvider();
506+
string style = null;
507+
style = """
508+
.clr-preview {
509+
background: %s;
510+
color: %s;
511+
border: 1px solid @borders;
512+
border-radius: 9999px;
482513
}
514+
""".printf(color,
515+
contrast);
516+
517+
css_provider.load_from_data(style.data);
518+
519+
Gtk.StyleContext.add_provider_for_display (
520+
Gdk.Display.get_default (),
521+
css_provider,
522+
Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION
523+
);
483524
}
484525

485526
public void action_export () {

0 commit comments

Comments
 (0)