Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3a9d2e4d13 | ||
|
|
63ffa15123 | ||
|
|
3de7a3746f | ||
|
|
53268107d5 | ||
|
|
d2d04ade5b | ||
|
|
083dbaded6 | ||
|
|
6927c4cf08 | ||
|
|
2c1626da05 | ||
|
|
ea611827ea | ||
|
|
8231e746c2 | ||
|
|
917bdb9f90 | ||
|
|
8ac5abbd8c | ||
|
|
624fd7bb67 | ||
|
|
33765cdef1 |
No files matched your search
@@ -3,7 +3,7 @@
|
||||
One Color Picker to rule them all! No overhelming menus or settings. An easy tool with the features you need.
|
||||
|
||||
Features:
|
||||
* Pick a color
|
||||
* Pick a color with the zoomable Magnifier
|
||||
* Choose between multiple Color Formats
|
||||
* Let the Color History remember your last colors
|
||||
|
||||
|
||||
@@ -1,33 +1,143 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!-- Copyright 2017 Ronny Dobra <ronnydobra at arcor dot de> -->
|
||||
<component type="desktop">
|
||||
<id>com.github.ronnydo.colorpicker.desktop</id>
|
||||
<metadata_license>CC0-1.0</metadata_license>
|
||||
<project_license>GPL-3.0+</project_license>
|
||||
<name>Color Picker</name>
|
||||
<summary>The most intuitive Color Picker to speed up your workflow.</summary>
|
||||
<description>
|
||||
<p>One Color Picker to rule them all! No overhelming menus or settings. An easy tool with the features you need.</p>
|
||||
<p>Features:</p>
|
||||
<ul>
|
||||
<li>Pick a color</li>
|
||||
<li>Choose between multiple Color Formats</li>
|
||||
<li>Let the Color History remember your last colors</li>
|
||||
</ul>
|
||||
</description>
|
||||
<provides>
|
||||
<binary>com.github.ronnydo.colorpicker</binary>
|
||||
</provides>
|
||||
<screenshots>
|
||||
<screenshot type="default">
|
||||
<image>https://raw.githubusercontent.com/ronnydo/colorpicker/master/data/screenshot.png</image>
|
||||
</screenshot>
|
||||
</screenshots>
|
||||
<developer_name>Ronny Dobra</developer_name>
|
||||
<url type="homepage">https://github.com/RonnyDo/ColorPicker</url>
|
||||
<url type="bugtracker">https://github.com/RonnyDo/ColorPicker/issues</url>
|
||||
<custom>
|
||||
<value key="x-appcenter-color-primary">#A3FF91</value>
|
||||
<value key="x-appcenter-color-primary-text">#333333</value>
|
||||
</custom>
|
||||
</component>
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!-- Copyright 2017 Ronny Dobra <ronnydobra at arcor dot de> -->
|
||||
<component type="desktop">
|
||||
<id>com.github.ronnydo.colorpicker.desktop</id>
|
||||
<metadata_license>CC0-1.0</metadata_license>
|
||||
<project_license>GPL-3.0+</project_license>
|
||||
<name>Color Picker</name>
|
||||
<summary>The most intuitive Color Picker to speed up your workflow</summary>
|
||||
<description>
|
||||
<p>One Color Picker to rule them all! No overhelming menus or settings. An easy tool with the features you need.</p>
|
||||
<p>Features:</p>
|
||||
<ul>
|
||||
<li>Pick a color with the zoomable Magnifier</li>
|
||||
<li>Choose between multiple Color Formats</li>
|
||||
<li>Let the Color History remember your last colors</li>
|
||||
</ul>
|
||||
</description>
|
||||
<categories>
|
||||
<category>GTK</category>
|
||||
<category>Utility</category>
|
||||
<category>Graphics</category>
|
||||
<category>Development</category>
|
||||
</categories>
|
||||
<releases>
|
||||
<release version="1.0.2" date="2017-08-20" urgency="medium">
|
||||
<description>
|
||||
<ul>
|
||||
<li>Implement "Don't add the same color to color history twice" (issue #24)</li>
|
||||
</ul>
|
||||
</description>
|
||||
</release>
|
||||
<release version="1.0.1" date="2017-07-13" urgency="medium">
|
||||
<description>
|
||||
<ul>
|
||||
<li>Improvements to avoid issue #19</li>
|
||||
</ul>
|
||||
</description>
|
||||
</release>
|
||||
<release version="1.0.0" date="2017-07-07" urgency="medium">
|
||||
<description>
|
||||
<ul>
|
||||
<li>Main Release!</li>
|
||||
<li>Implement magnifier (issue #12)</li>
|
||||
<li>Use your mousewheel to zoom the magnifier in and out.</li>
|
||||
<li>Invalid AppData file (issue #17)</li>
|
||||
<li>Code cleanup</li>
|
||||
</ul>
|
||||
</description>
|
||||
</release>
|
||||
<release version="0.9.5" date="2017-06-27" urgency="medium">
|
||||
<description>
|
||||
<ul>
|
||||
<li>Fix dark color scheme bug (issue #13)</li>
|
||||
<li>Enhance project description</li>
|
||||
</ul>
|
||||
</description>
|
||||
</release>
|
||||
<release version="0.9.4" date="2017-06-26" urgency="medium">
|
||||
<description>
|
||||
<ul>
|
||||
<li>Fix build bug (issue #16)</li>
|
||||
</ul>
|
||||
</description>
|
||||
</release>
|
||||
<release version="0.9.3" date="2017-06-26" urgency="medium">
|
||||
<description>
|
||||
<ul>
|
||||
<li>Color Picker now restores your recent window position, color format and color history! (issue #10, issue #11 and issue #15)</li>
|
||||
<li>Minor icon changes</li>
|
||||
</ul>
|
||||
</description>
|
||||
</release>
|
||||
<release version="0.9.2" date="2017-06-23" urgency="low">
|
||||
<description>
|
||||
<ul>
|
||||
<li>Fix issue #8</li>
|
||||
</ul>
|
||||
</description>
|
||||
</release>
|
||||
<release version="0.9.1" date="2017-06-23" urgency="low">
|
||||
<description>
|
||||
<ul>
|
||||
<li>Fix issue #8</li>
|
||||
</ul>
|
||||
</description>
|
||||
</release>
|
||||
<release version="0.9.0" date="2017-06-22" urgency="medium">
|
||||
<description>
|
||||
<ul>
|
||||
<li>Beta release</li>
|
||||
<li>Fix issue #4</li>
|
||||
<li>Fix issue #5</li>
|
||||
<li>Fix issue #6</li>
|
||||
<li>Fix issue #7</li>
|
||||
<li>Update icons</li>
|
||||
<li>Add German translation</li>
|
||||
</ul>
|
||||
</description>
|
||||
</release>
|
||||
<release version="0.1.2" date="2017-06-21" urgency="low">
|
||||
<description>
|
||||
<ul>
|
||||
<li>Fix build information</li>
|
||||
</ul>
|
||||
</description>
|
||||
</release>
|
||||
<release version="0.1.1" date="2017-06-19" urgency="low">
|
||||
<description>
|
||||
<ul>
|
||||
<li>Added debian files and logo files</li>
|
||||
</ul>
|
||||
</description>
|
||||
</release>
|
||||
<release version="0.1.0" date="2017-06-15" urgency="low">
|
||||
<description>
|
||||
<ul>
|
||||
<li>First official release</li>
|
||||
</ul>
|
||||
</description>
|
||||
</release>
|
||||
<release version="1.0" date="2012-08-26"/>
|
||||
</releases>
|
||||
<provides>
|
||||
<binary>com.github.ronnydo.colorpicker</binary>
|
||||
</provides>
|
||||
<screenshots>
|
||||
<screenshot type="default">
|
||||
<caption>Normal variant</caption>
|
||||
<image>https://raw.githubusercontent.com/ronnydo/colorpicker/master/data/screenshot.png</image>
|
||||
</screenshot>
|
||||
<screenshot>
|
||||
<caption>Dark variant</caption>
|
||||
<image>https://raw.githubusercontent.com/ronnydo/colorpicker/master/data/screenshot_dark.png</image>
|
||||
</screenshot>
|
||||
</screenshots>
|
||||
<developer_name>Ronny Dobra</developer_name>
|
||||
<url type="homepage">https://github.com/RonnyDo/ColorPicker</url>
|
||||
<url type="bugtracker">https://github.com/RonnyDo/ColorPicker/issues</url>
|
||||
<custom>
|
||||
<value key="x-appcenter-color-primary">#A3FF91</value>
|
||||
<value key="x-appcenter-color-primary-text">#333333</value>
|
||||
</custom>
|
||||
</component>
|
||||
@@ -3,7 +3,7 @@ Name=Color Picker
|
||||
Comment=An intuitive Color Picker
|
||||
Exec=com.github.ronnydo.colorpicker
|
||||
Icon=com.github.ronnydo.colorpicker
|
||||
Keywords=color;picker;selector;pipette;
|
||||
Keywords=colorpicker;color;picker;selector;pipette;
|
||||
Terminal=false
|
||||
Type=Application
|
||||
Categories=GTK;Utility;Graphics;Development;
|
||||
@@ -23,5 +23,10 @@
|
||||
<summary>Color History</summary>
|
||||
<description>Color History</description>
|
||||
</key>
|
||||
<key name="zoomlevel" type="i">
|
||||
<default>3</default>
|
||||
<summary>Most recent zoomlevel of the picker's magnifier.</summary>
|
||||
<description>Most recent zoomlevel of the picker's magnifier.</description>
|
||||
</key>
|
||||
</schema>
|
||||
</schemalist>
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 24 KiB After Width: | Height: | Size: 25 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 26 KiB |
Vendored
+35
-1
@@ -1,6 +1,40 @@
|
||||
com.github.ronnydo.colorpicker (1.0.1) xenial; urgency=medium
|
||||
|
||||
* Implement "Don't add the same color to color history twice" (issue #24)
|
||||
|
||||
-- Ronny Dobra <ronnydobra at arcor dot de> Thu, 20 Aug 2017 13:30:00 +0100
|
||||
|
||||
com.github.ronnydo.colorpicker (1.0.1) xenial; urgency=medium
|
||||
|
||||
* Improvements to avoid issue #19
|
||||
|
||||
-- Ronny Dobra <ronnydobra at arcor dot de> Thu, 13 Jul 2017 01:45:00 +0100
|
||||
|
||||
com.github.ronnydo.colorpicker (1.0.0) xenial; urgency=medium
|
||||
|
||||
* Main Release!
|
||||
* Implement magnifier (issue #12)
|
||||
* Use your mousewheel to zoom the magnifier in and out.
|
||||
* Invalid AppData file (issue #17)
|
||||
* Code cleanup
|
||||
|
||||
-- Ronny Dobra <ronnydobra at arcor dot de> Thu, 07 Jul 2017 12:00:00 +0100
|
||||
|
||||
com.github.ronnydo.colorpicker (0.9.5) xenial; urgency=medium
|
||||
|
||||
* Fix issue #13
|
||||
|
||||
-- Ronny Dobra <ronnydobra at arcor dot de> Thu, 27 Jun 2017 23:20:00 +0100
|
||||
|
||||
com.github.ronnydo.colorpicker (0.9.4) xenial; urgency=medium
|
||||
|
||||
* Fix issue #16
|
||||
|
||||
-- Ronny Dobra <ronnydobra at arcor dot de> Thu, 26 Jun 2017 23:10:00 +0100
|
||||
|
||||
com.github.ronnydo.colorpicker (0.9.3) xenial; urgency=medium
|
||||
|
||||
* Color Picker now restores your recent window position, color format color history! (issue #10, issue #11 and issue #15)
|
||||
* Color Picker now restores your recent window position, color format and color history! (issue #10, issue #11 and issue #15)
|
||||
* Minor icon changes
|
||||
|
||||
-- Ronny Dobra <ronnydobra at arcor dot de> Thu, 26 Jun 2017 22:45:00 +0100
|
||||
|
||||
Vendored
+1
-1
@@ -13,4 +13,4 @@ Package: com.github.ronnydo.colorpicker
|
||||
Architecture: any
|
||||
Depends: ${misc:Depends}, ${shlibs:Depends}
|
||||
Description: An intuitive Color Picker
|
||||
The most intuitive Color Picker to speed up your workflow.
|
||||
The most intuitive Color Picker to speed up your workflow
|
||||
Executable
+7
@@ -0,0 +1,7 @@
|
||||
sudo rm -r build
|
||||
meson build
|
||||
cd build
|
||||
mesonconf -Dprefix=/usr
|
||||
ninja
|
||||
./com.github.ronnydo.colorpicker
|
||||
cd ..
|
||||
+1
-1
@@ -23,7 +23,7 @@ executable(
|
||||
'src/ExtRGBA.vala',
|
||||
'src/Widgets/ColorArea.vala',
|
||||
'src/Widgets/ColorHistory.vala',
|
||||
'src/Widgets/MousePosition.vala',
|
||||
'src/Widgets/Picker.vala',
|
||||
'src/Services/Settings.vala',
|
||||
c_args: c_args,
|
||||
dependencies: [
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import os
|
||||
import subprocess
|
||||
|
||||
schemadir = os.path.join(os.environ['MESON_INSTALL_PREFIX'], 'share', 'glib-2.0', 'schemas')
|
||||
|
||||
if not os.environ.get('DESTDIR'):
|
||||
print('Compiling gsettings schemas...')
|
||||
subprocess.call(['glib-compile-schemas', schemadir])
|
||||
@@ -30,7 +30,6 @@ namespace ColorPicker {
|
||||
icon_name: "com.github.ronnydo.colorpicker",
|
||||
title: _("Color Picker"),
|
||||
resizable: false,
|
||||
//height_request: 500,
|
||||
width_request: 500
|
||||
);
|
||||
}
|
||||
@@ -38,7 +37,7 @@ namespace ColorPicker {
|
||||
construct {
|
||||
// main box
|
||||
ext_active_color.parse ("#FFFFFF");
|
||||
|
||||
|
||||
var color_area = new ColorPicker.Widgets.ColorArea ();
|
||||
color_area.set_color (ext_active_color);
|
||||
|
||||
@@ -153,7 +152,7 @@ namespace ColorPicker {
|
||||
|
||||
// activate color picker
|
||||
pick_color_button.clicked.connect (() => {
|
||||
var mouse_position = new ColorPicker.Widgets.MousePosition ();
|
||||
var mouse_position = new ColorPicker.Widgets.Picker ();
|
||||
mouse_position.show_all ();
|
||||
|
||||
mouse_position.moved.connect ((t, color) => {
|
||||
@@ -228,10 +227,14 @@ namespace ColorPicker {
|
||||
|
||||
this.present ();
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
// trigger picker on startup
|
||||
pick_color_button.clicked ();
|
||||
this.show.connect(() => {
|
||||
pick_color_button.clicked ();
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void update_color_format_combobox_text (Gtk.Entry format_entry, int id) {
|
||||
|
||||
@@ -29,6 +29,7 @@ namespace ColorPicker.Services {
|
||||
public int window_y { get; set; }
|
||||
public int color_format_index { get; set; }
|
||||
public string[] color_history { get; set; }
|
||||
public int zoomlevel { get; set; }
|
||||
|
||||
public static Settings get_instance () {
|
||||
if (instance == null) {
|
||||
|
||||
@@ -29,12 +29,11 @@ namespace ColorPicker.Widgets {
|
||||
Gee.ArrayList<Gdk.RGBA?> color_list;
|
||||
|
||||
const int border_width = 1;
|
||||
const string border_color_string = "rgba(50, 50, 50, 0.4)";
|
||||
|
||||
// hardcoded from /usr/share/themes/elementary/gtk-3.0/[gtk.css|gtk-dark.css]
|
||||
const string border_color_string = "rgba(0, 0, 0, 0.25)";
|
||||
private Gdk.RGBA border_color = Gdk.RGBA();
|
||||
|
||||
const string triangle_color_string = "#F5F5F5";
|
||||
private Gdk.RGBA triangle_color = Gdk.RGBA();
|
||||
|
||||
|
||||
const int shadow_width = 16;
|
||||
const string shadow_color_string = "#000000";
|
||||
//const string shadow_color_string = "#A9A9A9";
|
||||
@@ -43,13 +42,12 @@ namespace ColorPicker.Widgets {
|
||||
int selected_color = 0;
|
||||
|
||||
|
||||
public ColorHistory () {
|
||||
public ColorHistory () {
|
||||
set_size_request (100, 28);
|
||||
add_events(Gdk.EventMask.BUTTON_PRESS_MASK | Gdk.EventMask.BUTTON_RELEASE_MASK | Gdk.EventMask.ENTER_NOTIFY_MASK);
|
||||
color_list = new Gee.ArrayList<Gdk.RGBA?> ();
|
||||
restore_colors ();
|
||||
restore_colors ();
|
||||
border_color.parse (border_color_string);
|
||||
triangle_color.parse (triangle_color_string);
|
||||
}
|
||||
|
||||
construct {
|
||||
@@ -60,7 +58,7 @@ namespace ColorPicker.Widgets {
|
||||
var color_array = settings.color_history;
|
||||
|
||||
if (color_array != null) {
|
||||
// if more colors should be saved as allowed, drop the oldest ones.
|
||||
// drop oldest colors, if more colors are stored as allowed
|
||||
if (max_colors < color_array.length) {
|
||||
int offset = color_array.length - max_colors;
|
||||
var sliced_array = color_array [offset:color_array.length];
|
||||
@@ -89,30 +87,44 @@ namespace ColorPicker.Widgets {
|
||||
}
|
||||
|
||||
public void add_color (Gdk.RGBA color) {
|
||||
if (color_list.size >= max_colors) {
|
||||
remove_oldest_color ();
|
||||
}
|
||||
int c_index = get_index_of (color);
|
||||
|
||||
if (c_index < 0) {
|
||||
if (color_list.size >= max_colors) {
|
||||
color_list.remove_at (0);
|
||||
}
|
||||
} else {
|
||||
color_list.remove_at (c_index);
|
||||
}
|
||||
|
||||
color_list.add (color);
|
||||
store_colors ();
|
||||
|
||||
selected_color = get_color_list ().size - 1;
|
||||
}
|
||||
|
||||
public void remove_oldest_color () {
|
||||
color_list.remove_at (0);
|
||||
store_colors ();
|
||||
}
|
||||
public int get_index_of (Gdk.RGBA color) {
|
||||
for (int i = 0; i < color_list.size; i++) {
|
||||
if (color_list[i] == color) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public Gee.ArrayList<Gdk.RGBA?> get_color_list () {
|
||||
return color_list;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* Widget is asked to draw itself */
|
||||
public override bool draw (Cairo.Context ctx) {
|
||||
|
||||
int width = get_allocated_width (); // better element_width / amount
|
||||
if (color_list == null && color_list.size <= 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
int width = get_allocated_width ();
|
||||
int height = get_allocated_height ();
|
||||
|
||||
var style_context = get_toplevel ().get_style_context ();
|
||||
|
||||
// colorboxes
|
||||
for (int i = 0; i < color_list.size; i++) {
|
||||
@@ -127,8 +139,7 @@ namespace ColorPicker.Widgets {
|
||||
Gdk.cairo_set_source_rgba (ctx, color_list.get (i));
|
||||
|
||||
ctx.fill ();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// simple shade
|
||||
ctx.new_path ();
|
||||
@@ -140,8 +151,7 @@ namespace ColorPicker.Widgets {
|
||||
Gdk.cairo_set_source_rgba (ctx, s);
|
||||
|
||||
ctx.set_line_width (border_width);
|
||||
ctx.stroke ();
|
||||
|
||||
ctx.stroke ();
|
||||
|
||||
/*
|
||||
// real faded shade
|
||||
@@ -159,53 +169,40 @@ namespace ColorPicker.Widgets {
|
||||
Gdk.cairo_set_source_rgba (ctx, shadow_color);
|
||||
ctx.stroke ();
|
||||
}
|
||||
*/
|
||||
|
||||
// colorboxes border
|
||||
*/
|
||||
|
||||
// triangle fill
|
||||
ctx.new_path ();
|
||||
ctx.move_to (0, 0);
|
||||
ctx.rel_line_to (width, 0);
|
||||
ctx.rel_line_to (0, height);
|
||||
ctx.rel_line_to (-1 * width, 0);
|
||||
ctx.close_path ();
|
||||
|
||||
Gdk.cairo_set_source_rgba (ctx, border_color);
|
||||
// fix: stright lines must be + 1 to appear same as diagonales
|
||||
ctx.set_line_width (border_width + 1);
|
||||
|
||||
int triangle_height = 10;
|
||||
int triangle_width = 20;
|
||||
// fix: "+1" against rounding error
|
||||
ctx.move_to ((width / color_list.size * selected_color + 1) + (width / color_list.size / 2 + 1) - triangle_width / 2, height);
|
||||
ctx.rel_line_to (triangle_width / 2, -1 * triangle_height);
|
||||
ctx.rel_line_to (triangle_width / 2, triangle_height);
|
||||
ctx.close_path ();
|
||||
Gdk.cairo_set_source_rgba (ctx, style_context.get_background_color(Gtk.StateFlags.NORMAL));
|
||||
ctx.fill ();
|
||||
|
||||
|
||||
// triangle border (left tip -> tip -> right tip)
|
||||
ctx.new_path ();
|
||||
Gdk.cairo_set_source_rgba (ctx, border_color);
|
||||
ctx.set_line_width (border_width);
|
||||
ctx.move_to ((width / color_list.size * selected_color + 1) + (width / color_list.size / 2 + 1) - triangle_width / 2, height);
|
||||
ctx.rel_line_to (triangle_width / 2, -1 * triangle_height);
|
||||
ctx.rel_line_to (triangle_width / 2, triangle_height);
|
||||
ctx.stroke ();
|
||||
|
||||
|
||||
|
||||
// triangle (Is used to indicate the selected color, which isn't implemented yet)
|
||||
if (color_list.size > 0) {
|
||||
ctx.new_path ();
|
||||
int triangle_height = 10;
|
||||
int triangle_width = 20;
|
||||
|
||||
// fix: "+1" against rounding error
|
||||
ctx.move_to ((width / color_list.size * selected_color + 1) + (width / color_list.size / 2 + 1), height - triangle_height);
|
||||
ctx.rel_line_to (triangle_width / 2, triangle_height);
|
||||
ctx.rel_line_to (-1 * triangle_width, 0);
|
||||
ctx.close_path ();
|
||||
|
||||
Gdk.cairo_set_source_rgba (ctx, triangle_color);
|
||||
|
||||
ctx.fill ();
|
||||
|
||||
// triangle border
|
||||
ctx.new_path ();
|
||||
// fix: "+1" against rounding error
|
||||
ctx.move_to ((width / color_list.size * selected_color + 1) + (width / color_list.size / 2 + 1) - triangle_width / 2, height);
|
||||
ctx.rel_line_to (triangle_width / 2, -1 * triangle_height);
|
||||
ctx.rel_line_to (triangle_width / 2, triangle_height);
|
||||
Gdk.cairo_set_source_rgba (ctx, border_color);
|
||||
|
||||
ctx.set_line_width (border_width);
|
||||
|
||||
ctx.stroke ();
|
||||
}
|
||||
|
||||
// continue from right triangle tip to draw around the ColorHistory border
|
||||
ctx.set_line_width (border_width +1);
|
||||
ctx.move_to ((width / color_list.size * selected_color + 1) + (width / color_list.size / 2 + 1) + triangle_width / 2, height);
|
||||
ctx.line_to (width, height);
|
||||
ctx.line_to (width, 0);
|
||||
ctx.line_to (0, 0);
|
||||
ctx.line_to (0, height);
|
||||
ctx.line_to ((width / color_list.size * selected_color + 1) + (width / color_list.size / 2 + 1) - triangle_width / 2, height);
|
||||
ctx.stroke ();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,163 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2017 Ronny Dobra (https://github.com/RonnyDo/ColorPicker)
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public
|
||||
* License along with this program; if not, write to the
|
||||
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
* Boston, MA 02110-1301 USA
|
||||
*
|
||||
* Authored by: Ronny Dobra <ronnydobra at arcor dot de>
|
||||
*/
|
||||
|
||||
namespace ColorPicker.Widgets {
|
||||
|
||||
public class MousePosition : Granite.Widgets.CompositedWindow {
|
||||
|
||||
public signal void picked (Gdk.RGBA color);
|
||||
public signal void cancelled ();
|
||||
public signal void moved (Gdk.RGBA color);
|
||||
|
||||
construct {
|
||||
type = Gtk.WindowType.POPUP;
|
||||
}
|
||||
|
||||
public MousePosition () {
|
||||
stick ();
|
||||
set_resizable (true);
|
||||
set_deletable (false);
|
||||
set_skip_taskbar_hint (true);
|
||||
set_skip_pager_hint (true);
|
||||
set_keep_above (true);
|
||||
|
||||
var screen = get_screen ();
|
||||
set_default_size (screen.get_width (), screen.get_height ());
|
||||
}
|
||||
|
||||
|
||||
public override bool button_release_event (Gdk.EventButton e) {
|
||||
if (e.button != 1) {
|
||||
return true;
|
||||
}
|
||||
|
||||
Gdk.RGBA color = get_color_at ((int) e.x_root, (int) e.y_root);
|
||||
picked (color);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public override bool motion_notify_event (Gdk.EventMotion e) {
|
||||
Gdk.RGBA color = get_color_at ((int) e.x_root, (int) e.y_root);
|
||||
moved (color);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public override bool key_press_event (Gdk.EventKey e) {
|
||||
if (e.keyval == Gdk.Key.Escape) {
|
||||
cancelled ();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public Gdk.RGBA get_color_at (int x, int y) {
|
||||
Gdk.Window win = Gdk.get_default_root_window ();
|
||||
Gdk.Pixbuf? pixbuf = Gdk.pixbuf_get_from_window (win, x, y, 1, 1);
|
||||
|
||||
if (pixbuf != null) {
|
||||
// see https://hackage.haskell.org/package/gtk3-0.14.6/docs/Graphics-UI-Gtk-Gdk-Pixbuf.html
|
||||
uint8 red = pixbuf.get_pixels()[0];
|
||||
uint8 green = pixbuf.get_pixels()[1];
|
||||
uint8 blue = pixbuf.get_pixels()[2];
|
||||
|
||||
Gdk.RGBA color = Gdk.RGBA();
|
||||
string spec = "rgb(" + red.to_string() + "," + green.to_string() + "," + blue.to_string() + ")";
|
||||
if (color.parse (spec)) {
|
||||
return color;
|
||||
} else {
|
||||
stdout.printf("ERROR: Parse pixel rgb values failed.");
|
||||
}
|
||||
}
|
||||
|
||||
// fallback: default RGBA color
|
||||
stdout.printf("ERROR: Gdk.pixbuf_get_from_window failed");
|
||||
return Gdk.RGBA ();
|
||||
}
|
||||
|
||||
|
||||
public override void show_all () {
|
||||
base.show_all ();
|
||||
var manager = Gdk.Display.get_default ().get_device_manager ();
|
||||
var pointer = manager.get_client_pointer ();
|
||||
var keyboard = pointer.get_associated_device ();
|
||||
var window = get_window ();
|
||||
|
||||
var status = pointer.grab (window,
|
||||
Gdk.GrabOwnership.NONE,
|
||||
false,
|
||||
Gdk.EventMask.BUTTON_PRESS_MASK | Gdk.EventMask.BUTTON_RELEASE_MASK | Gdk.EventMask.POINTER_MOTION_MASK,
|
||||
new Gdk.Cursor.for_display (window.get_display (), Gdk.CursorType.CROSSHAIR),
|
||||
Gtk.get_current_event_time ());
|
||||
|
||||
if (status != Gdk.GrabStatus.SUCCESS) {
|
||||
pointer.ungrab (Gtk.get_current_event_time ());
|
||||
}
|
||||
|
||||
if (keyboard != null) {
|
||||
status = keyboard.grab (window,
|
||||
Gdk.GrabOwnership.NONE,
|
||||
false,
|
||||
Gdk.EventMask.KEY_PRESS_MASK,
|
||||
null,
|
||||
Gtk.get_current_event_time ());
|
||||
|
||||
if (status != Gdk.GrabStatus.SUCCESS) {
|
||||
keyboard.ungrab (Gtk.get_current_event_time ());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public new void close () {
|
||||
get_window ().set_cursor (null);
|
||||
base.close ();
|
||||
}
|
||||
|
||||
/*
|
||||
public override bool draw (Cairo.Context ctx) {
|
||||
if (!dragging) {
|
||||
return true;
|
||||
}
|
||||
|
||||
int w = get_allocated_width ();
|
||||
int h = get_allocated_height ();
|
||||
|
||||
ctx.rectangle (0, 0, w, h);
|
||||
ctx.set_source_rgba (0.1, 0.1, 0.1, 0.2);
|
||||
ctx.fill ();
|
||||
|
||||
ctx.rectangle (0, 0, w, h);
|
||||
ctx.set_source_rgb (0.7, 0.7, 0.7);
|
||||
ctx.set_line_width (1.0);
|
||||
ctx.stroke ();
|
||||
|
||||
return base.draw (ctx);
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,318 @@
|
||||
/*
|
||||
* Copyright (c) 2017 Ronny Dobra (https://github.com/RonnyDo/ColorPicker)
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public
|
||||
* License along with this program; if not, write to the
|
||||
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
* Boston, MA 02110-1301 USA
|
||||
*
|
||||
* Authored by: Ronny Dobra <ronnydobra at arcor dot de>
|
||||
* Inspired by: https://github.com/stuartlangridge/ColourPicker/
|
||||
*/
|
||||
|
||||
namespace ColorPicker.Widgets {
|
||||
|
||||
public class Picker : Granite.Widgets.CompositedWindow {
|
||||
|
||||
public signal void picked (Gdk.RGBA color);
|
||||
public signal void cancelled ();
|
||||
public signal void moved (Gdk.RGBA color);
|
||||
|
||||
const string dark_border_color_string = "#333333";
|
||||
private Gdk.RGBA dark_border_color = Gdk.RGBA();
|
||||
|
||||
const string bright_border_color_string = "#FFFFFF";
|
||||
private Gdk.RGBA bright_border_color = Gdk.RGBA();
|
||||
|
||||
// 1. Snapsize is the amount of pixel going to be magnified by the zoomlevel.
|
||||
// 2. The snapsize must be odd to have a 1px magnifier center.
|
||||
// 3. Asure that snapsize*max_zoomlevel+shadow_width*2 is smaller than 2 * get_screen ().get_display ().get_maximal_cursor_size()
|
||||
// Valid: snapsize = 31, max_zoomlevel = 7, shadow_width = 15 --> 247px
|
||||
// get_maximal_cursor_size = 128 --> 256px
|
||||
// Otherwise the cursor starts to flicker. See https://github.com/stuartlangridge/ColourPicker/issues/6#issuecomment-277972290
|
||||
// and https://github.com/RonnyDo/ColorPicker/issues/19
|
||||
int snapsize = 31;
|
||||
int min_zoomlevel = 2;
|
||||
int max_zoomlevel = 7;
|
||||
int zoomlevel = 3;
|
||||
int shadow_width = 15;
|
||||
|
||||
private Gdk.Cursor magnifier = null;
|
||||
|
||||
construct {
|
||||
type = Gtk.WindowType.POPUP;
|
||||
}
|
||||
|
||||
|
||||
public Picker () {
|
||||
stick ();
|
||||
set_resizable (true);
|
||||
set_deletable (false);
|
||||
set_skip_taskbar_hint (true);
|
||||
set_skip_pager_hint (true);
|
||||
set_keep_above (true);
|
||||
|
||||
|
||||
dark_border_color.parse (dark_border_color_string);
|
||||
bright_border_color.parse (bright_border_color_string);
|
||||
|
||||
// restore zoomlevel
|
||||
if (settings.zoomlevel >= min_zoomlevel && settings.zoomlevel <= max_zoomlevel) {
|
||||
zoomlevel = settings.zoomlevel;
|
||||
}
|
||||
|
||||
var screen = get_screen ();
|
||||
set_default_size (screen.get_width (), screen.get_height ());
|
||||
}
|
||||
|
||||
|
||||
public override bool button_release_event (Gdk.EventButton e) {
|
||||
if (e.button != 1) {
|
||||
return true;
|
||||
}
|
||||
|
||||
Gdk.RGBA color = get_color_at ((int) e.x_root, (int) e.y_root);
|
||||
picked (color);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public override bool draw (Cairo.Context cr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public override bool motion_notify_event (Gdk.EventMotion e) {
|
||||
Gdk.RGBA color = get_color_at ((int) e.x_root, (int) e.y_root);
|
||||
moved (color);
|
||||
|
||||
set_magnifier_cursor ();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public override bool scroll_event (Gdk.EventScroll e) {
|
||||
switch (e.direction) {
|
||||
case Gdk.ScrollDirection.UP:
|
||||
if (zoomlevel < max_zoomlevel) {
|
||||
zoomlevel++;
|
||||
}
|
||||
set_magnifier_cursor ();
|
||||
break;
|
||||
case Gdk.ScrollDirection.DOWN:
|
||||
if (zoomlevel > min_zoomlevel) {
|
||||
zoomlevel--;
|
||||
}
|
||||
set_magnifier_cursor ();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public void set_magnifier_cursor () {
|
||||
// draw cursor
|
||||
int px, py;
|
||||
get_pointer (out px, out py);
|
||||
|
||||
var radius = snapsize * zoomlevel / 2;
|
||||
|
||||
// take screenshot
|
||||
|
||||
var latest_pb = snap (px - snapsize / 2, py - snapsize / 2, snapsize, snapsize);
|
||||
|
||||
// Zoom that screenshot up, and grab a snapsize-sized piece from the middle
|
||||
var scaled_pb = latest_pb.scale_simple (snapsize * zoomlevel + shadow_width * 2 , snapsize * zoomlevel + shadow_width * 2 , Gdk.InterpType.NEAREST);
|
||||
|
||||
|
||||
// Create the base surface for our cursor
|
||||
var base_surface = new Cairo.ImageSurface (Cairo.Format.ARGB32, snapsize * zoomlevel + shadow_width * 2 , snapsize * zoomlevel + shadow_width * 2);
|
||||
var base_context = new Cairo.Context (base_surface);
|
||||
|
||||
|
||||
// Create the circular path on our base surface
|
||||
base_context.arc (radius + shadow_width, radius + shadow_width, radius, 0, 2 * Math.PI);
|
||||
|
||||
// Paste in the screenshot
|
||||
Gdk.cairo_set_source_pixbuf (base_context, scaled_pb, 0, 0);
|
||||
|
||||
// Clip to that circular path, keeping the path around for later, and paint the pasted screenshot
|
||||
base_context.save ();
|
||||
base_context.clip_preserve ();
|
||||
base_context.paint ();
|
||||
base_context.restore ();
|
||||
|
||||
|
||||
// Draw a shadow as outside magnifier border
|
||||
double shadow_alpha = 0.6;
|
||||
base_context.set_line_width (1);
|
||||
|
||||
for (int i = 0; i <= shadow_width; i++) {
|
||||
base_context.arc (radius + shadow_width, radius + shadow_width, radius + shadow_width- i, 0, 2 * Math.PI);
|
||||
Gdk.RGBA shadow_color = Gdk.RGBA();
|
||||
shadow_color.parse(dark_border_color_string);
|
||||
shadow_color.alpha = shadow_alpha / ((shadow_width - i + 1)*(shadow_width - i + 1));
|
||||
Gdk.cairo_set_source_rgba (base_context, shadow_color);
|
||||
base_context.stroke ();
|
||||
}
|
||||
|
||||
|
||||
// Draw an outside bright magnifier border
|
||||
Gdk.cairo_set_source_rgba (base_context, bright_border_color);
|
||||
base_context.arc (radius + shadow_width, radius + shadow_width, radius - 1, 0, 2 * Math.PI);
|
||||
base_context.stroke();
|
||||
|
||||
|
||||
// Draw inside square
|
||||
base_context.set_line_width (1);
|
||||
|
||||
Gdk.cairo_set_source_rgba (base_context, dark_border_color);
|
||||
base_context.move_to (radius + shadow_width - zoomlevel, radius + shadow_width - zoomlevel);
|
||||
base_context.line_to (radius + shadow_width + zoomlevel, radius + shadow_width - zoomlevel);
|
||||
base_context.line_to (radius + shadow_width + zoomlevel, radius + shadow_width + zoomlevel);
|
||||
base_context.line_to (radius + shadow_width - zoomlevel, radius + shadow_width + zoomlevel);
|
||||
base_context.close_path ();
|
||||
base_context.stroke ();
|
||||
|
||||
Gdk.cairo_set_source_rgba (base_context, bright_border_color);
|
||||
base_context.move_to (radius + shadow_width - zoomlevel + 1, radius + shadow_width - zoomlevel + 1);
|
||||
base_context.line_to (radius + shadow_width + zoomlevel - 1, radius + shadow_width - zoomlevel + 1);
|
||||
base_context.line_to (radius + shadow_width + zoomlevel - 1, radius + shadow_width + zoomlevel - 1);
|
||||
base_context.line_to (radius + shadow_width - zoomlevel + 1, radius + shadow_width + zoomlevel - 1);
|
||||
base_context.close_path ();
|
||||
base_context.stroke ();
|
||||
|
||||
|
||||
// turn the base surface into a pixbuf and thence a cursor
|
||||
var drawn_pb = Gdk.pixbuf_get_from_surface(base_surface, 0, 0, base_surface.get_width(), base_surface.get_height());
|
||||
|
||||
magnifier = new Gdk.Cursor.from_pixbuf(
|
||||
get_screen ().get_display (),
|
||||
drawn_pb,
|
||||
drawn_pb.get_width () / 2,
|
||||
drawn_pb.get_height () / 2);
|
||||
|
||||
/*
|
||||
uint max_cursor_width, max_cursor_height, default_cursor_width, default_cursor_height;;
|
||||
get_screen ().get_display ().get_maximal_cursor_size (out max_cursor_width, out max_cursor_height);
|
||||
print ("\n\nCursor size is " + drawn_pb.get_width().to_string () + "x" + drawn_pb.get_height().to_string ());
|
||||
print ("\nAllowed size is " + max_cursor_width.to_string () + "x" + max_cursor_height.to_string ());
|
||||
print ("\nDefault size is " + get_screen ().get_display ().get_default_cursor_size ().to_string ());
|
||||
*/
|
||||
|
||||
// Set the cursor
|
||||
var manager = Gdk.Display.get_default ().get_device_manager ();
|
||||
manager.get_client_pointer ().grab (
|
||||
get_window (),
|
||||
Gdk.GrabOwnership.APPLICATION,
|
||||
true,
|
||||
Gdk.EventMask.BUTTON_PRESS_MASK | Gdk.EventMask.POINTER_MOTION_MASK | Gdk.EventMask.SCROLL_MASK,
|
||||
magnifier,
|
||||
Gdk.CURRENT_TIME);
|
||||
|
||||
}
|
||||
|
||||
|
||||
public Gdk.Pixbuf? snap (int x, int y, int w, int h) {
|
||||
var root = Gdk.get_default_root_window ();
|
||||
|
||||
var screenshot = Gdk.pixbuf_get_from_window (root, x, y, w, h);
|
||||
return screenshot;
|
||||
}
|
||||
|
||||
|
||||
public override bool key_press_event (Gdk.EventKey e) {
|
||||
if (e.keyval == Gdk.Key.Escape) {
|
||||
cancelled ();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public Gdk.RGBA get_color_at (int x, int y) {
|
||||
var root = Gdk.get_default_root_window ();
|
||||
Gdk.Pixbuf? pixbuf = Gdk.pixbuf_get_from_window (root, x, y, 1, 1);
|
||||
|
||||
if (pixbuf != null) {
|
||||
// see https://hackage.haskell.org/package/gtk3-0.14.6/docs/Graphics-UI-Gtk-Gdk-Pixbuf.html
|
||||
uint8 red = pixbuf.get_pixels()[0];
|
||||
uint8 green = pixbuf.get_pixels()[1];
|
||||
uint8 blue = pixbuf.get_pixels()[2];
|
||||
|
||||
Gdk.RGBA color = Gdk.RGBA();
|
||||
string spec = "rgb(" + red.to_string() + "," + green.to_string() + "," + blue.to_string() + ")";
|
||||
if (color.parse (spec)) {
|
||||
return color;
|
||||
} else {
|
||||
stdout.printf("ERROR: Parse pixel rgb values failed.");
|
||||
}
|
||||
}
|
||||
|
||||
// fallback: default RGBA color
|
||||
stdout.printf("ERROR: Gdk.pixbuf_get_from_window failed");
|
||||
return Gdk.RGBA ();
|
||||
}
|
||||
|
||||
|
||||
public override void show_all () {
|
||||
base.show_all ();
|
||||
|
||||
var manager = Gdk.Display.get_default ().get_device_manager ();
|
||||
var pointer = manager.get_client_pointer ();
|
||||
var keyboard = pointer.get_associated_device ();
|
||||
var window = get_window ();
|
||||
|
||||
var status = pointer.grab (window,
|
||||
Gdk.GrabOwnership.NONE,
|
||||
false,
|
||||
Gdk.EventMask.BUTTON_PRESS_MASK | Gdk.EventMask.BUTTON_RELEASE_MASK | Gdk.EventMask.POINTER_MOTION_MASK,
|
||||
new Gdk.Cursor.for_display (window.get_display (), Gdk.CursorType.CROSSHAIR),
|
||||
Gtk.get_current_event_time ());
|
||||
|
||||
if (status != Gdk.GrabStatus.SUCCESS) {
|
||||
pointer.ungrab (Gtk.get_current_event_time ());
|
||||
}
|
||||
|
||||
// show magnifier
|
||||
set_magnifier_cursor ();
|
||||
|
||||
if (keyboard != null) {
|
||||
status = keyboard.grab (window,
|
||||
Gdk.GrabOwnership.NONE,
|
||||
false,
|
||||
Gdk.EventMask.KEY_PRESS_MASK,
|
||||
null,
|
||||
Gtk.get_current_event_time ());
|
||||
|
||||
if (status != Gdk.GrabStatus.SUCCESS) {
|
||||
keyboard.ungrab (Gtk.get_current_event_time ());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public new void close () {
|
||||
// save zoomlevel
|
||||
settings.zoomlevel = zoomlevel;
|
||||
|
||||
get_window ().set_cursor (null);
|
||||
base.close ();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user