3 Commits
Author SHA1 Message Date
Ronny Dobra 3de7a3746f update release notes 2017-07-13 01:43:14 +02:00
Ronny Dobra 53268107d5 improvements to avoid issue #19 2017-07-13 01:39:35 +02:00
Ronny Dobra d2d04ade5b remove dead code 2017-07-12 23:15:27 +02:00
3 changed files with 60 additions and 36 deletions

No files matched your search

@@ -22,6 +22,13 @@
<category>Development</category>
</categories>
<releases>
​<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>
+7 -1
View File
@@ -1,4 +1,10 @@
om.github.ronnydo.colorpicker (1.0.0) xenial; urgency=medium
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)
+46 -35
View File
@@ -34,12 +34,21 @@ namespace ColorPicker.Widgets {
const string bright_border_color_string = "#FFFFFF";
private Gdk.RGBA bright_border_color = Gdk.RGBA();
int snapsize = 35; // must be odd to have a 1px magnifier center
// 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;
}
@@ -51,7 +60,8 @@ namespace ColorPicker.Widgets {
set_deletable (false);
set_skip_taskbar_hint (true);
set_skip_pager_hint (true);
set_keep_above (true);
set_keep_above (true);
dark_border_color.parse (dark_border_color_string);
bright_border_color.parse (bright_border_color_string);
@@ -78,13 +88,12 @@ namespace ColorPicker.Widgets {
}
public override bool draw (Cairo.Context cr) {
public override bool draw (Cairo.Context cr) {
return false;
}
public override bool motion_notify_event (Gdk.EventMotion e) {
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);
@@ -121,20 +130,21 @@ namespace ColorPicker.Widgets {
int px, py;
get_pointer (out px, out py);
int shadow_width = 15;
var radius = snapsize * zoomlevel / 2;
// take screenshot
var latest_pb = snap (px - snapsize / 2, py - snapsize / 2,
snapsize, snapsize);
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);
@@ -146,9 +156,9 @@ namespace ColorPicker.Widgets {
base_context.clip_preserve ();
base_context.paint ();
base_context.restore ();
// Draw a shadow as outside magnifier border
// Draw a shadow as outside magnifier border
double shadow_alpha = 0.6;
base_context.set_line_width (1);
@@ -159,7 +169,8 @@ namespace ColorPicker.Widgets {
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);
@@ -189,37 +200,38 @@ namespace ColorPicker.Widgets {
// 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());
var zoom_pb = drawn_pb.scale_simple(
snapsize * zoomlevel, snapsize * zoomlevel, Gdk.InterpType.TILES);
var magnifier = new Gdk.Cursor.from_pixbuf(
magnifier = new Gdk.Cursor.from_pixbuf(
get_screen ().get_display (),
zoom_pb,
zoom_pb.get_width() / 2,
zoom_pb.get_height () / 2);
// Set the cursor
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(
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);
Gdk.CURRENT_TIME);
}
public Gdk.Pixbuf? snap (int x, int y, int w, int h) {
Gdk.Screen screen;
int t_x, t_y;
Gdk.ModifierType mask;
var display=Gdk.Display.get_default();
display.get_pointer (out screen, out t_x, out t_y, out mask);
var root = Gdk.get_default_root_window ();
var screenshot = Gdk.pixbuf_get_from_window (root, x, y, w, h);
var screenshot = Gdk.pixbuf_get_from_window (root, x, y, w, h);
return screenshot;
}
@@ -233,8 +245,8 @@ namespace ColorPicker.Widgets {
}
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);
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
@@ -258,8 +270,7 @@ namespace ColorPicker.Widgets {
public override void show_all () {
base.show_all ();
base.show_all ();
var manager = Gdk.Display.get_default ().get_device_manager ();
var pointer = manager.get_client_pointer ();