summaryrefslogtreecommitdiff
path: root/src/renderers
diff options
context:
space:
mode:
authorJörg Frings-Fürst <debian@jff-webhosting.net>2015-01-15 18:59:03 +0100
committerJörg Frings-Fürst <debian@jff-webhosting.net>2015-01-15 18:59:03 +0100
commit484946ba512d2f441471e3d7e1b839b4f71c54a7 (patch)
treecfe32a46fee52ab246d2258d7fcec862eb1af9ad /src/renderers
parent45fa2e053bf7f7d51f3e0583abe3d53de4ebdcfd (diff)
Merge Upstream Release
Diffstat (limited to 'src/renderers')
-rw-r--r--src/renderers/pieWindow.vala124
-rw-r--r--src/renderers/sliceRenderer.vala148
2 files changed, 136 insertions, 136 deletions
diff --git a/src/renderers/pieWindow.vala b/src/renderers/pieWindow.vala
index 66ed863..a95b3e3 100644
--- a/src/renderers/pieWindow.vala
+++ b/src/renderers/pieWindow.vala
@@ -1,4 +1,4 @@
-/*
+/*
Copyright (c) 2011 by Simon Schneegans
This program is free software: you can redistribute it and/or modify it
@@ -12,14 +12,14 @@ 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, see <http://www.gnu.org/licenses/>.
-*/
+this program. If not, see <http://www.gnu.org/licenses/>.
+*/
using GLib.Math;
namespace GnomePie {
-/////////////////////////////////////////////////////////////////////////
+/////////////////////////////////////////////////////////////////////////
/// An invisible window. Used to draw Pies onto.
/////////////////////////////////////////////////////////////////////////
@@ -28,54 +28,54 @@ public class PieWindow : Gtk.Window {
/////////////////////////////////////////////////////////////////////
/// Signal which gets emitted when the PieWindow is about to close.
/////////////////////////////////////////////////////////////////////
-
+
public signal void on_closing();
-
+
/////////////////////////////////////////////////////////////////////
/// Signal which gets emitted when the PieWindow is closed.
/////////////////////////////////////////////////////////////////////
-
+
public signal void on_closed();
-
+
/////////////////////////////////////////////////////////////////////
/// The background image used for fake transparency if
/// has_compositing is false.
/////////////////////////////////////////////////////////////////////
-
+
public Image background { get; private set; default=null; }
-
+
/////////////////////////////////////////////////////////////////////
/// The owned renderer.
/////////////////////////////////////////////////////////////////////
private PieRenderer renderer;
-
+
/////////////////////////////////////////////////////////////////////
/// True, if the Pie is currently fading out.
/////////////////////////////////////////////////////////////////////
-
+
private bool closing = false;
private bool closed = false;
-
+
/////////////////////////////////////////////////////////////////////
/// A timer used for calculating the frame time.
/////////////////////////////////////////////////////////////////////
-
+
private GLib.Timer timer;
-
+
/////////////////////////////////////////////////////////////////////
/// True, if the screen supports compositing.
/////////////////////////////////////////////////////////////////////
-
+
private bool has_compositing = false;
-
+
/////////////////////////////////////////////////////////////////////
/// C'tor, sets up the window.
/////////////////////////////////////////////////////////////////////
public PieWindow() {
this.renderer = new PieRenderer();
-
+
this.set_title("Gnome-Pie");
this.set_skip_taskbar_hint(true);
this.set_skip_pager_hint(true);
@@ -85,7 +85,8 @@ public class PieWindow : Gtk.Window {
this.set_resizable(false);
this.icon_name = "gnome-pie";
this.set_accept_focus(false);
-
+ this.app_paintable = true;
+
// check for compositing
if (this.screen.is_composited()) {
#if HAVE_GTK_3
@@ -95,7 +96,7 @@ public class PieWindow : Gtk.Window {
#endif
this.has_compositing = true;
}
-
+
// set up event filter
this.add_events(Gdk.EventMask.BUTTON_RELEASE_MASK |
Gdk.EventMask.KEY_RELEASE_MASK |
@@ -107,13 +108,13 @@ public class PieWindow : Gtk.Window {
if (e.button == 1 || this.renderer.turbo_mode) this.activate_slice();
return true;
});
-
+
// cancel on right click
this.button_press_event.connect ((e) => {
if (e.button == 3) this.cancel();
return true;
});
-
+
// remember last pressed key in order to disable key repeat
uint last_key = 0;
this.key_press_event.connect((e) => {
@@ -123,7 +124,7 @@ public class PieWindow : Gtk.Window {
}
return true;
});
-
+
// activate on key release if turbo_mode is enabled
this.key_release_event.connect((e) => {
last_key = 0;
@@ -133,13 +134,13 @@ public class PieWindow : Gtk.Window {
this.handle_key_release(e.keyval);
return true;
});
-
+
// notify the renderer of mouse move events
this.motion_notify_event.connect((e) => {
this.renderer.on_mouse_move();
return true;
});
-
+
this.show.connect_after(() => {
Gtk.grab_add(this);
FocusGrabber.grab(this.get_window(), true, true, false);
@@ -152,7 +153,7 @@ public class PieWindow : Gtk.Window {
this.expose_event.connect(this.draw_window);
#endif
}
-
+
/////////////////////////////////////////////////////////////////////
/// Loads a Pie to be rendered.
/////////////////////////////////////////////////////////////////////
@@ -162,14 +163,14 @@ public class PieWindow : Gtk.Window {
this.set_window_position(pie);
this.set_size_request(renderer.size, renderer.size);
}
-
+
/////////////////////////////////////////////////////////////////////
/// Opens the window. load_pie should have been called before.
/////////////////////////////////////////////////////////////////////
-
+
public void open() {
this.realize();
-
+
// capture the background image if there is no compositing
if (!this.has_compositing) {
int x, y, width, height;
@@ -177,7 +178,7 @@ public class PieWindow : Gtk.Window {
this.get_size(out width, out height);
this.background = new Image.capture_screen(x, y, width+1, height+1);
}
-
+
// capture the input focus
this.show();
@@ -185,38 +186,38 @@ public class PieWindow : Gtk.Window {
this.timer = new GLib.Timer();
this.timer.start();
this.queue_draw();
-
+
// the main draw loop
- GLib.Timeout.add((uint)(1000.0/Config.global.refresh_rate), () => {
+ GLib.Timeout.add((uint)(1000.0/Config.global.refresh_rate), () => {
if (this.closed)
return false;
-
+
this.queue_draw();
return this.visible;
- });
+ });
}
-
+
/////////////////////////////////////////////////////////////////////
/// Gets the center position of the window.
/////////////////////////////////////////////////////////////////////
-
+
public void get_center_pos(out int out_x, out int out_y) {
int x=0, y=0, width=0, height=0;
this.get_position(out x, out y);
this.get_size(out width, out height);
-
+
out_x = x + width/2;
out_y = y + height/2;
}
-
+
/////////////////////////////////////////////////////////////////////
/// Draw the Pie.
/////////////////////////////////////////////////////////////////////
#if HAVE_GTK_3
- private bool draw_window(Cairo.Context ctx) {
+ private bool draw_window(Cairo.Context ctx) {
#else
- private bool draw_window(Gtk.Widget da, Gdk.EventExpose event) {
+ private bool draw_window(Gtk.Widget da, Gdk.EventExpose event) {
// clear the window
var ctx = Gdk.cairo_create(this.get_window());
#endif
@@ -230,29 +231,29 @@ public class PieWindow : Gtk.Window {
ctx.set_source_surface(background.surface, -1, -1);
ctx.paint();
}
-
+
// align the context to the center of the PieWindow
ctx.translate(this.width_request*0.5, this.height_request*0.5);
-
+
// get the mouse position
double mouse_x = 0.0, mouse_y = 0.0;
this.get_pointer(out mouse_x, out mouse_y);
-
+
// store the frame time
double frame_time = this.timer.elapsed();
this.timer.reset();
-
+
// render the Pie
this.renderer.draw(frame_time, ctx, (int)(mouse_x - this.width_request*0.5),
(int)(mouse_y - this.height_request*0.5));
-
+
return true;
}
-
+
/////////////////////////////////////////////////////////////////////
/// Activates the currently activate slice.
/////////////////////////////////////////////////////////////////////
-
+
private void activate_slice() {
if (!this.closing) {
this.closing = true;
@@ -260,7 +261,7 @@ public class PieWindow : Gtk.Window {
Gtk.grab_remove(this);
FocusGrabber.ungrab();
this.renderer.activate();
-
+
GLib.Timeout.add((uint)(Config.global.theme.fade_out_time*1000), () => {
this.closed = true;
this.on_closed();
@@ -269,11 +270,11 @@ public class PieWindow : Gtk.Window {
});
}
}
-
+
/////////////////////////////////////////////////////////////////////
/// Activates no slice and closes the PieWindow.
/////////////////////////////////////////////////////////////////////
-
+
private void cancel() {
if (!this.closing) {
this.closing = true;
@@ -281,7 +282,7 @@ public class PieWindow : Gtk.Window {
Gtk.grab_remove(this);
FocusGrabber.ungrab();
this.renderer.cancel();
-
+
GLib.Timeout.add((uint)(Config.global.theme.fade_out_time*1000), () => {
this.closed = true;
this.on_closed();
@@ -290,21 +291,21 @@ public class PieWindow : Gtk.Window {
});
}
}
-
+
/////////////////////////////////////////////////////////////////////
/// Sets the position of the window to the center of the screen or to
/// the mouse.
/////////////////////////////////////////////////////////////////////
-
+
private void set_window_position(Pie pie) {
if(PieManager.get_is_centered(pie.id)) this.set_position(Gtk.WindowPosition.CENTER);
else this.set_position(Gtk.WindowPosition.MOUSE);
}
-
+
/////////////////////////////////////////////////////////////////////
/// Do some useful stuff when keys are pressed.
/////////////////////////////////////////////////////////////////////
-
+
private void handle_key_press(uint key) {
if (Gdk.keyval_name(key) == "Escape") this.cancel();
else if (Gdk.keyval_name(key) == "Return") this.activate_slice();
@@ -316,31 +317,30 @@ public class PieWindow : Gtk.Window {
else if (Gdk.keyval_name(key) == "Alt_L") this.renderer.show_hotkeys = true;
else {
int index = -1;
-
- if (key >= 48 && key <= 57) index = (int)key - 48;
+
+ if (key >= 48 && key <= 57) index = ((int)key - 39)%10;
else if (key >= 97 && key <= 122) index = (int)key - 87;
else if (key >= 65 && key <= 90) index = (int)key - 55;
-
+
if (index >= 0 && index < this.renderer.slice_count()) {
this.renderer.key_board_control = true;
this.renderer.set_highlighted_slice(index);
-
+
if (this.renderer.active_slice == index) {
GLib.Timeout.add((uint)(Config.global.theme.transition_time*1000.0), ()=> {
this.activate_slice();
return false;
});
}
-
}
}
}
}
-
+
/////////////////////////////////////////////////////////////////////
/// Do some useful stuff when keys are released.
/////////////////////////////////////////////////////////////////////
-
+
private void handle_key_release(uint key) {
if (!this.renderer.turbo_mode) {
if (Gdk.keyval_name(key) == "Alt_L") this.renderer.show_hotkeys = false;
diff --git a/src/renderers/sliceRenderer.vala b/src/renderers/sliceRenderer.vala
index 743f13e..2ecf7c4 100644
--- a/src/renderers/sliceRenderer.vala
+++ b/src/renderers/sliceRenderer.vala
@@ -1,4 +1,4 @@
-/*
+/*
Copyright (c) 2011 by Simon Schneegans
This program is free software: you can redistribute it and/or modify it
@@ -12,14 +12,14 @@ 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, see <http://www.gnu.org/licenses/>.
+this program. If not, see <http://www.gnu.org/licenses/>.
*/
using GLib.Math;
namespace GnomePie {
-/////////////////////////////////////////////////////////////////////////
+/////////////////////////////////////////////////////////////////////////
/// Renders a Slice of a Pie. According to the current theme.
/////////////////////////////////////////////////////////////////////////
@@ -30,57 +30,57 @@ public class SliceRenderer : GLib.Object {
/////////////////////////////////////////////////////////////////////
public bool active {get; private set; default = false;}
-
+
/////////////////////////////////////////////////////////////////////
/// The Image which should be displayed as center caption when this
/// slice is active.
/////////////////////////////////////////////////////////////////////
-
+
public Image caption {get; private set;}
-
+
/////////////////////////////////////////////////////////////////////
/// The color which should be used for colorizing center layers when
/// this slice is active.
/////////////////////////////////////////////////////////////////////
-
+
public Color color {get; private set;}
-
+
/////////////////////////////////////////////////////////////////////
/// The two Images used, when this slice is active or not.
/////////////////////////////////////////////////////////////////////
-
+
private Image active_icon;
private Image inactive_icon;
-
+
/////////////////////////////////////////////////////////////////////
/// The Image displaying the associated hot key of this slice.
/////////////////////////////////////////////////////////////////////
-
+
private Image hotkey;
-
+
/////////////////////////////////////////////////////////////////////
/// The Action which is rendered by this SliceRenderer.
/////////////////////////////////////////////////////////////////////
-
+
private Action action;
-
+
/////////////////////////////////////////////////////////////////////
/// The PieRenderer which owns this SliceRenderer.
/////////////////////////////////////////////////////////////////////
- private unowned PieRenderer parent;
-
+ private unowned PieRenderer parent;
+
/////////////////////////////////////////////////////////////////////
/// The index of this slice in a pie. Clockwise assigned, starting
/// from the right-most slice.
/////////////////////////////////////////////////////////////////////
-
+
private int position;
-
+
/////////////////////////////////////////////////////////////////////
/// AnimatedValues needed for a slice.
/////////////////////////////////////////////////////////////////////
-
+
private AnimatedValue fade; // for transitions from active to inactive
private AnimatedValue scale; // for zoom effect
private AnimatedValue alpha; // for fading in/out
@@ -94,24 +94,24 @@ public class SliceRenderer : GLib.Object {
public SliceRenderer(PieRenderer parent) {
this.parent = parent;
-
+
this.fade = new AnimatedValue.linear(0.0, 0.0, Config.global.theme.transition_time);
this.wobble = new AnimatedValue.linear(0.0, 0.0, Config.global.theme.transition_time);
this.alpha = new AnimatedValue.linear(0.0, 1.0, Config.global.theme.fade_in_time);
- this.scale = new AnimatedValue.cubic(AnimatedValue.Direction.OUT,
- 1.0/Config.global.theme.max_zoom,
- 1.0/Config.global.theme.max_zoom,
- Config.global.theme.transition_time,
+ this.scale = new AnimatedValue.cubic(AnimatedValue.Direction.OUT,
+ 1.0/Config.global.theme.max_zoom,
+ 1.0/Config.global.theme.max_zoom,
+ Config.global.theme.transition_time,
Config.global.theme.springiness);
- this.fade_scale = new AnimatedValue.cubic(AnimatedValue.Direction.OUT,
- Config.global.theme.fade_in_zoom, 1.0,
- Config.global.theme.fade_in_time,
+ this.fade_scale = new AnimatedValue.cubic(AnimatedValue.Direction.OUT,
+ Config.global.theme.fade_in_zoom, 1.0,
+ Config.global.theme.fade_in_time,
Config.global.theme.springiness);
- this.fade_rotation = new AnimatedValue.cubic(AnimatedValue.Direction.OUT,
- Config.global.theme.fade_in_rotation, 0.0,
+ this.fade_rotation = new AnimatedValue.cubic(AnimatedValue.Direction.OUT,
+ Config.global.theme.fade_in_rotation, 0.0,
Config.global.theme.fade_in_time);
}
-
+
/////////////////////////////////////////////////////////////////////
/// Loads an Action. All members are initialized accordingly.
/////////////////////////////////////////////////////////////////////
@@ -119,64 +119,64 @@ public class SliceRenderer : GLib.Object {
public void load(Action action, int position) {
this.position = position;
this.action = action;
-
-
+
+
if (Config.global.theme.caption)
- this.caption = new RenderedText(action.name,
+ this.caption = new RenderedText(action.name,
Config.global.theme.caption_width,
Config.global.theme.caption_height,
Config.global.theme.caption_font,
Config.global.theme.caption_color,
Config.global.global_scale);
-
+
this.active_icon = new ThemedIcon(action.name, action.icon, true);
this.inactive_icon = new ThemedIcon(action.name, action.icon, false);
-
+
this.color = new Color.from_icon(this.active_icon);
-
+
string hotkey_label = "";
if (position < 10) {
- hotkey_label = "%u".printf(position);
+ hotkey_label = "%u".printf((position+1)%10);
} else if (position < 36) {
hotkey_label = "%c".printf((char)(55 + position));
}
-
+
this.hotkey = new RenderedText(hotkey_label, (int)Config.global.theme.slice_radius*2,
(int)Config.global.theme.slice_radius*2, "sans 20",
Config.global.theme.caption_color, Config.global.global_scale);
}
-
+
/////////////////////////////////////////////////////////////////////
/// Activaes the Action of this slice.
/////////////////////////////////////////////////////////////////////
-
+
public void activate() {
action.activate();
}
-
+
/////////////////////////////////////////////////////////////////////
/// Initiates the fade-out animation by resetting the targets of the
/// AnimatedValues to 0.0.
/////////////////////////////////////////////////////////////////////
-
+
public void fade_out() {
this.alpha.reset_target(0.0, Config.global.theme.fade_out_time);
- this.fade_scale = new AnimatedValue.cubic(AnimatedValue.Direction.IN,
- this.fade_scale.val,
- Config.global.theme.fade_out_zoom,
- Config.global.theme.fade_out_time,
+ this.fade_scale = new AnimatedValue.cubic(AnimatedValue.Direction.IN,
+ this.fade_scale.val,
+ Config.global.theme.fade_out_zoom,
+ Config.global.theme.fade_out_time,
Config.global.theme.springiness);
- this.fade_rotation = new AnimatedValue.cubic(AnimatedValue.Direction.IN,
- this.fade_rotation.val,
- Config.global.theme.fade_out_rotation,
+ this.fade_rotation = new AnimatedValue.cubic(AnimatedValue.Direction.IN,
+ this.fade_rotation.val,
+ Config.global.theme.fade_out_rotation,
Config.global.theme.fade_out_time);
}
-
+
/////////////////////////////////////////////////////////////////////
/// Should be called if the active slice of the PieRenderer changes.
/// The members activity, caption and color are set accordingly.
/////////////////////////////////////////////////////////////////////
-
+
public void set_active_slice(SliceRenderer? active_slice) {
if (active_slice == this) {
this.fade.reset_target(1.0, Config.global.theme.transition_time);
@@ -184,13 +184,13 @@ public class SliceRenderer : GLib.Object {
this.fade.reset_target(0.0, Config.global.theme.transition_time);
}
}
-
+
/////////////////////////////////////////////////////////////////////
/// Draws all layers of the slice.
/////////////////////////////////////////////////////////////////////
public void draw(double frame_time, Cairo.Context ctx, double angle, double distance) {
-
+
// update the AnimatedValues
this.scale.update(frame_time);
this.alpha.update(frame_time);
@@ -198,16 +198,16 @@ public class SliceRenderer : GLib.Object {
this.fade_scale.update(frame_time);
this.fade_rotation.update(frame_time);
this.wobble.update(frame_time);
-
+
double direction = 2.0 * PI * position/parent.slice_count() + this.fade_rotation.val;
double max_scale = 1.0/Config.global.theme.max_zoom;
double diff = fabs(angle-direction);
if (diff > PI)
diff = 2 * PI - diff;
-
+
active = ((parent.active_slice >= 0) && (diff < PI/parent.slice_count()));
-
+
if (parent.active_slice >= 0) {
double wobble = Config.global.theme.wobble*diff/PI*(1-diff/PI);
if ((direction < angle && direction > angle - PI) || direction > PI+angle) {
@@ -218,61 +218,61 @@ public class SliceRenderer : GLib.Object {
} else {
this.wobble.reset_target(0, Config.global.theme.transition_time*0.5);
}
-
+
direction += this.wobble.val;
if (diff < 2 * PI * Config.global.theme.zoom_range)
max_scale = (Config.global.theme.max_zoom/(diff * (Config.global.theme.max_zoom - 1)
/(2 * PI * Config.global.theme.zoom_range) + 1))
/Config.global.theme.max_zoom;
-
-
-
+
+
+
max_scale = (parent.active_slice >= 0 ? max_scale : 1.0/Config.global.theme.max_zoom);
-
+
if (fabs(this.scale.end - max_scale) > Config.global.theme.max_zoom*0.005)
this.scale.reset_target(max_scale, Config.global.theme.transition_time);
-
+
ctx.save();
-
+
// distance from the center
double radius = Config.global.theme.radius;
-
+
// increase radius if there are many slices in a pie
if (atan((Config.global.theme.slice_radius+Config.global.theme.slice_gap)
/(radius/Config.global.theme.max_zoom)) > PI/parent.slice_count()) {
radius = (Config.global.theme.slice_radius+Config.global.theme.slice_gap)
/tan(PI/parent.slice_count())*Config.global.theme.max_zoom;
}
-
+
// transform the context
ctx.scale(scale.val*fade_scale.val, scale.val*fade_scale.val);
ctx.translate(cos(direction)*radius, sin(direction)*radius);
-
+
ctx.push_group();
-
+
ctx.set_operator(Cairo.Operator.ADD);
-
+
// paint the images
if (fade.val > 0.0) active_icon.paint_on(ctx, this.alpha.val*this.fade.val);
if (fade.val < 1.0) inactive_icon.paint_on(ctx, this.alpha.val*(1.0 - fade.val));
-
+
if (this.parent.show_hotkeys) {
ctx.set_operator(Cairo.Operator.ATOP);
ctx.set_source_rgba(0, 0, 0, 0.5);
ctx.paint();
}
-
+
ctx.set_operator(Cairo.Operator.OVER);
-
-
+
+
ctx.pop_group_to_source();
ctx.paint();
-
+
// draw hotkeys if necassary
if (this.parent.show_hotkeys)
this.hotkey.paint_on(ctx, 1.0);
-
+
ctx.restore();
}
}