Skip to content

Commit

Permalink
Use more Helium
Browse files Browse the repository at this point in the history
  • Loading branch information
lainsce committed Jan 29, 2024
1 parent 190200a commit 4305edc
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/colorbutton.vala
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
public class Colorway.PaletteButton : Gtk.Button {
public class Colorway.PaletteButton : He.FillButton {
private Gtk.CssProvider provider = new Gtk.CssProvider();
private string _hex = "";
private Gtk.Stack image_stack = new Gtk.Stack();
Expand Down
17 changes: 9 additions & 8 deletions src/hue_slider.vala
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,27 @@
* Co-Authored by: Arvianto Dwi Wicaksono <arvianto.dwi@gmail.com>
*/

public class Colorway.HueSlider : Gtk.Scale {
public class Colorway.HueSlider : He.Slider {

// Signals
public signal void on_value_changed (double hue);

public HueSlider (double hue) {
this.adjustment = new Gtk.Adjustment (hue, 0, 360, 1, 360, 0);
scale.adjustment = new Gtk.Adjustment (hue, 0, 360, 1, 360, 0);
}

construct {
// Initialize parent's properties
this.orientation = Gtk.Orientation.HORIZONTAL;
this.draw_value = false;
this.digits = 0;
this.has_origin = false;
scale.orientation = Gtk.Orientation.HORIZONTAL;
scale.draw_value = false;
scale.digits = 0;
scale.has_origin = false;

this.add_css_class ("clr-hue");
this.stop_indicator_visibility = true;

this.value_changed.connect (() => {
double hue = this.adjustment.get_value () / 360;
scale.value_changed.connect (() => {
double hue = scale.adjustment.get_value () / 360;
on_value_changed (hue);
});
}
Expand Down
22 changes: 11 additions & 11 deletions src/window.vala
Original file line number Diff line number Diff line change
Expand Up @@ -149,13 +149,13 @@ namespace Colorway {
(float)Utils.make_srgb(g),
(float)Utils.make_srgb(b));

hue_slider.set_value(ch*360);
hue_slider.scale.set_value(ch*360);

color_box.append(da);
color_box.append(hue_slider);

da.on_sv_move.connect ((s, v) => {
double hue = hue_slider.get_value () / 360;
double hue = hue_slider.scale.get_value () / 360;
Gtk.hsv_to_rgb ((float)hue, (float)s, (float)v, out active_color.red, out active_color.green, out active_color.blue);

var pcda = Utils.make_hex((float)Utils.make_srgb(active_color.red),
Expand Down Expand Up @@ -202,7 +202,7 @@ namespace Colorway {
setup_color_rules.begin (color, contrast, hue, s, v, color_rule_dropdown, sbox, tbox);
});

double hue = hue_slider.get_value () / 360;
double hue = hue_slider.scale.get_value () / 360;
double s, v;
da.pos_to_sv (out s, out v);
setup_color_rules.begin (color, contrast, hue, s, v, color_rule_dropdown, sbox, tbox);
Expand Down Expand Up @@ -246,7 +246,7 @@ namespace Colorway {
da.sv_to_pos (csl, cvl);
da.queue_draw();

hue_slider.set_value(chl*360);
hue_slider.scale.set_value(chl*360);

color = pcl.up();
color_label.get_entry ().set_text (pcl.up());
Expand Down Expand Up @@ -298,7 +298,7 @@ namespace Colorway {
tbox.set_visible (false);
break;
case 1:
var h = (hue_shift (hue_slider.get_value (), 180.0)) / 360;
var h = (hue_shift (hue_slider.scale.get_value (), 180.0)) / 360;
double cs, cv;
da.pos_to_sv (out cs, out cv);
Gtk.hsv_to_rgb ((float)h, (float)cs, (float)cv, out active_color.red, out active_color.green, out active_color.blue);
Expand All @@ -312,15 +312,15 @@ namespace Colorway {

break;
case 2:
var ch1 = (hue_shift (hue_slider.get_value (), 120.0)) / 360;
var ch1 = (hue_shift (hue_slider.scale.get_value (), 120.0)) / 360;
double cs1, cv1;
da.pos_to_sv (out cs1, out cv1);
Gtk.hsv_to_rgb ((float)ch1, (float)cs1, (float)cv1, out active_color.red, out active_color.green, out active_color.blue);
var c1 = Utils.make_hex((float)Utils.make_srgb(active_color.red),
(float)Utils.make_srgb(active_color.green),
(float)Utils.make_srgb(active_color.blue));

var ch2 = (hue_shift (hue_slider.get_value (), 240.0)) / 360;
var ch2 = (hue_shift (hue_slider.scale.get_value (), 240.0)) / 360;
double cs2, cv2;
da.pos_to_sv (out cs2, out cv2);
Gtk.hsv_to_rgb ((float)ch2, (float)cs2, (float)cv2, out active_color.red, out active_color.green, out active_color.blue);
Expand All @@ -334,23 +334,23 @@ namespace Colorway {

break;
case 3:
var ch1 = (hue_shift (hue_slider.get_value (), 90.0)) / 360;
var ch1 = (hue_shift (hue_slider.scale.get_value (), 90.0)) / 360;
double cs1, cv1;
da.pos_to_sv (out cs1, out cv1);
Gtk.hsv_to_rgb ((float)ch1, (float)cs1, (float)cv1, out active_color.red, out active_color.green, out active_color.blue);
var c1 = Utils.make_hex((float)Utils.make_srgb(active_color.red),
(float)Utils.make_srgb(active_color.green),
(float)Utils.make_srgb(active_color.blue));

var ch2 = (hue_shift (hue_slider.get_value (), 180.0)) / 360;
var ch2 = (hue_shift (hue_slider.scale.get_value (), 180.0)) / 360;
double cs2, cv2;
da.pos_to_sv (out cs2, out cv2);
Gtk.hsv_to_rgb ((float)ch2, (float)cs2, (float)cv2, out active_color.red, out active_color.green, out active_color.blue);
var c2 = Utils.make_hex((float)Utils.make_srgb(active_color.red),
(float)Utils.make_srgb(active_color.green),
(float)Utils.make_srgb(active_color.blue));

var ch3 = (hue_shift (hue_slider.get_value (), 270.0)) / 360;
var ch3 = (hue_shift (hue_slider.scale.get_value (), 270.0)) / 360;
double cs3, cv3;
da.pos_to_sv (out cs3, out cv3);
Gtk.hsv_to_rgb ((float)ch3, (float)cs3, (float)cv3, out active_color.red, out active_color.green, out active_color.blue);
Expand Down Expand Up @@ -427,7 +427,7 @@ namespace Colorway {
active_color = color_portal;
da.active_color = color_portal;

hue_slider.set_value(h*360);
hue_slider.scale.set_value(h*360);

if (Utils.contrast_ratio(active_color, {0,0,0,1}) > Utils.contrast_ratio(active_color, {1,1,1,1}) + 3) {
contrast = "#000000";
Expand Down

0 comments on commit 4305edc

Please sign in to comment.