summaryrefslogtreecommitdiff
path: root/src/renderers
diff options
context:
space:
mode:
authorAlessandro Ghedini <al3xbio@gmail.com>2011-11-20 15:50:38 +0100
committerAlessandro Ghedini <al3xbio@gmail.com>2011-11-20 15:51:50 +0100
commit3997b71e281a5f43cc8c1892e85de30728df7b2d (patch)
tree96f2be7c48af03b7c540eba9dd6680eb270f23b8 /src/renderers
parent902829c62f552f35517783570025b479745de3c5 (diff)
Imported Upstream version 0.3.1
Diffstat (limited to 'src/renderers')
-rw-r--r--src/renderers/centerRenderer.vala55
-rw-r--r--src/renderers/pieRenderer.vala99
-rw-r--r--src/renderers/pieWindow.vala153
-rw-r--r--src/renderers/sliceRenderer.vala89
4 files changed, 328 insertions, 68 deletions
diff --git a/src/renderers/centerRenderer.vala b/src/renderers/centerRenderer.vala
index c30e9ce..fab633e 100644
--- a/src/renderers/centerRenderer.vala
+++ b/src/renderers/centerRenderer.vala
@@ -19,17 +19,44 @@ using GLib.Math;
namespace GnomePie {
-// Renders the center of a Pie.
+/////////////////////////////////////////////////////////////////////////
+/// Renders the center of a Pie.
+/////////////////////////////////////////////////////////////////////////
public class CenterRenderer : GLib.Object {
+ /////////////////////////////////////////////////////////////////////
+ /// The PieRenderer which owns this CenterRenderer.
+ /////////////////////////////////////////////////////////////////////
+
private unowned PieRenderer parent;
+
+ /////////////////////////////////////////////////////////////////////
+ /// The caption drawn in the center. Changes when the active slice
+ /// changes.
+ /////////////////////////////////////////////////////////////////////
+
private unowned Image? caption;
+
+ /////////////////////////////////////////////////////////////////////
+ /// The color of the currently active slice. Used to colorize layers.
+ /////////////////////////////////////////////////////////////////////
+
private Color color;
+ /////////////////////////////////////////////////////////////////////
+ /// Two AnimatedValues: alpha is for global transparency (when
+ /// fading in/out), activity is 1.0 if there is an active slice and
+ /// 0.0 if there is no active slice.
+ /////////////////////////////////////////////////////////////////////
+
private AnimatedValue activity;
private AnimatedValue alpha;
+ /////////////////////////////////////////////////////////////////////
+ /// C'tor, initializes all members.
+ /////////////////////////////////////////////////////////////////////
+
public CenterRenderer(PieRenderer parent) {
this.parent = parent;
this.activity = new AnimatedValue.linear(0.0, 0.0, Config.global.theme.transition_time);
@@ -38,11 +65,21 @@ public class CenterRenderer : GLib.Object {
this.caption = null;
}
+ /////////////////////////////////////////////////////////////////////
+ /// Initiates the fade-out animation by resetting the targets of the
+ /// AnimatedValues to 0.0.
+ /////////////////////////////////////////////////////////////////////
+
public void fade_out() {
this.activity.reset_target(0.0, Config.global.theme.fade_out_time);
this.alpha.reset_target(0.0, 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 == null) {
this.activity.reset_target(0.0, Config.global.theme.transition_time);
@@ -53,17 +90,23 @@ public class CenterRenderer : GLib.Object {
}
}
+ /////////////////////////////////////////////////////////////////////
+ /// Draws all center layers and the caption.
+ /////////////////////////////////////////////////////////////////////
+
public void draw(double frame_time, Cairo.Context ctx, double angle, double distance) {
-
+ // get all center_layers
var layers = Config.global.theme.center_layers;
+ // update the AnimatedValues
this.activity.update(frame_time);
this.alpha.update(frame_time);
+ // draw each layer
foreach (var layer in layers) {
-
ctx.save();
+ // calculate all values needed for animation/drawing
double active_speed = (layer.active_rotation_mode == CenterLayer.RotationMode.TO_MOUSE) ?
0.0 : layer.active_rotation_speed;
double inactive_speed = (layer.inactive_rotation_mode == CenterLayer.RotationMode.TO_MOUSE) ?
@@ -114,10 +157,14 @@ public class CenterRenderer : GLib.Object {
if (colorize > 0.0) ctx.push_group();
+ // transform the context
ctx.rotate(layer.rotation);
ctx.scale(max_scale, max_scale);
+
+ // paint the layer
layer.image.paint_on(ctx, this.alpha.val*max_alpha);
+ // colorize it, if necessary
if (colorize > 0.0) {
ctx.set_operator(Cairo.Operator.ATOP);
ctx.set_source_rgb(this.color.r, this.color.g, this.color.b);
@@ -135,7 +182,7 @@ public class CenterRenderer : GLib.Object {
if (Config.global.theme.caption && caption != null && this.activity.val > 0) {
ctx.save();
ctx.identity_matrix();
- int pos = this.parent.get_size()/2;
+ int pos = this.parent.size/2;
ctx.translate(pos, (int)(Config.global.theme.caption_position) + pos);
caption.paint_on(ctx, this.activity.val*this.alpha.val);
ctx.restore();
diff --git a/src/renderers/pieRenderer.vala b/src/renderers/pieRenderer.vala
index 5b706f4..ffaf776 100644
--- a/src/renderers/pieRenderer.vala
+++ b/src/renderers/pieRenderer.vala
@@ -26,15 +26,60 @@ namespace GnomePie {
public class PieRenderer : GLib.Object {
+ /////////////////////////////////////////////////////////////////////
+ /// The index of the slice used for quick action. (The action which
+ /// gets executed when the user clicks on the middle of the pie)
+ /////////////////////////////////////////////////////////////////////
+
public int quick_action { get; private set; }
+
+ /////////////////////////////////////////////////////////////////////
+ /// The index of the currently active slice.
+ /////////////////////////////////////////////////////////////////////
+
public int active_slice { get; private set; }
+
+ /////////////////////////////////////////////////////////////////////
+ /// True, if the hot keys are currently displayed.
+ /////////////////////////////////////////////////////////////////////
+
public bool show_hotkeys { get; set; }
- private int size;
+ /////////////////////////////////////////////////////////////////////
+ /// The width and height of the Pie in pixels.
+ /////////////////////////////////////////////////////////////////////
+
+ public int size { get; private set; }
+
+ /////////////////////////////////////////////////////////////////////
+ /// True if the pie should close when it's trigger is released.
+ /////////////////////////////////////////////////////////////////////
+
+ public bool turbo_mode { get; private set; default=false; }
+
+ /////////////////////////////////////////////////////////////////////
+ /// All SliceRenderers used to draw this Pie.
+ /////////////////////////////////////////////////////////////////////
+
private Gee.ArrayList<SliceRenderer?> slices;
+
+ /////////////////////////////////////////////////////////////////////
+ /// The renderer for the center of this pie.
+ /////////////////////////////////////////////////////////////////////
+
private CenterRenderer center;
+
+ /////////////////////////////////////////////////////////////////////
+ /// True if the pie is currently navigated with the keyboard. This is
+ /// set to false as soon as the mouse moves.
+ /////////////////////////////////////////////////////////////////////
+
private bool key_board_control = false;
+ /////////////////////////////////////////////////////////////////////
+ /// C'tor, initializes members.
+ /////////////////////////////////////////////////////////////////////
+
public PieRenderer() {
this.slices = new Gee.ArrayList<SliceRenderer?>();
this.center = new CenterRenderer(this);
@@ -43,6 +88,10 @@ public class PieRenderer : GLib.Object {
this.size = 0;
}
+ /////////////////////////////////////////////////////////////////////
+ /// Loads an Pie. All members are initialized accordingly.
+ /////////////////////////////////////////////////////////////////////
+
public void load_pie(Pie pie) {
this.slices.clear();
@@ -61,6 +110,8 @@ public class PieRenderer : GLib.Object {
}
}
+ this.turbo_mode = PieManager.get_is_turbo(pie.id);
+
this.set_highlighted_slice(this.quick_action);
this.size = (int)fmax(2*Config.global.theme.radius + 2*Config.global.theme.slice_radius*Config.global.theme.max_zoom,
@@ -74,12 +125,20 @@ public class PieRenderer : GLib.Object {
}
}
+ /////////////////////////////////////////////////////////////////////
+ /// Activates the currently active slice.
+ /////////////////////////////////////////////////////////////////////
+
public void activate() {
if (this.active_slice >= 0 && this.active_slice < this.slices.size)
slices[active_slice].activate();
this.cancel();
}
+ /////////////////////////////////////////////////////////////////////
+ /// Asks all renders to fade out.
+ /////////////////////////////////////////////////////////////////////
+
public void cancel() {
foreach (var slice in this.slices)
slice.fade_out();
@@ -87,6 +146,11 @@ public class PieRenderer : GLib.Object {
center.fade_out();
}
+ /////////////////////////////////////////////////////////////////////
+ /// Called when the up-key is pressed. Selects the next slice towards
+ /// the top.
+ /////////////////////////////////////////////////////////////////////
+
public void select_up() {
int bottom = this.slice_count()/4;
int top = this.slice_count()*3/4;
@@ -99,6 +163,11 @@ public class PieRenderer : GLib.Object {
this.set_highlighted_slice((this.active_slice-1+this.slice_count())%this.slice_count());
}
+ /////////////////////////////////////////////////////////////////////
+ /// Called when the down-key is pressed. Selects the next slice
+ /// towards the bottom.
+ /////////////////////////////////////////////////////////////////////
+
public void select_down() {
int bottom = this.slice_count()/4;
int top = this.slice_count()*3/4;
@@ -111,6 +180,11 @@ public class PieRenderer : GLib.Object {
this.set_highlighted_slice((this.active_slice+1)%this.slice_count());
}
+ /////////////////////////////////////////////////////////////////////
+ /// Called when the left-key is pressed. Selects the next slice
+ /// towards the left.
+ /////////////////////////////////////////////////////////////////////
+
public void select_left() {
int left = this.slice_count()/2;
int right = 0;
@@ -123,6 +197,11 @@ public class PieRenderer : GLib.Object {
this.set_highlighted_slice(this.active_slice+1);
}
+ /////////////////////////////////////////////////////////////////////
+ /// Called when the right-key is pressed. Selects the next slice
+ /// towards the right.
+ /////////////////////////////////////////////////////////////////////
+
public void select_right() {
int left = this.slice_count()/2;
int right = 0;
@@ -135,13 +214,17 @@ public class PieRenderer : GLib.Object {
this.set_highlighted_slice((this.active_slice-1+this.slice_count())%this.slice_count());
}
+ /////////////////////////////////////////////////////////////////////
+ /// Returns the amount of slices in this pie.
+ /////////////////////////////////////////////////////////////////////
+
public int slice_count() {
return slices.size;
}
- public int get_size() {
- return size;
- }
+ /////////////////////////////////////////////////////////////////////
+ /// Draws the entire pie.
+ /////////////////////////////////////////////////////////////////////
public void draw(double frame_time, Cairo.Context ctx, int mouse_x, int mouse_y) {
double distance = sqrt(mouse_x*mouse_x + mouse_y*mouse_y);
@@ -179,10 +262,18 @@ public class PieRenderer : GLib.Object {
slice.draw(frame_time, ctx, angle, distance);
}
+ /////////////////////////////////////////////////////////////////////
+ /// Called when the user moves the mouse.
+ /////////////////////////////////////////////////////////////////////
+
public void on_mouse_move() {
this.key_board_control = false;
}
+ /////////////////////////////////////////////////////////////////////
+ /// Called when the currently active slice changes.
+ /////////////////////////////////////////////////////////////////////
+
public void set_highlighted_slice(int index) {
if (index != this.active_slice) {
if (index >= 0 && index < this.slice_count())
diff --git a/src/renderers/pieWindow.vala b/src/renderers/pieWindow.vala
index c4ac2ec..59117df 100644
--- a/src/renderers/pieWindow.vala
+++ b/src/renderers/pieWindow.vala
@@ -19,19 +19,52 @@ using GLib.Math;
namespace GnomePie {
-// An invisible window. Used to draw Pies onto.
+/////////////////////////////////////////////////////////////////////////
+/// An invisible window. Used to draw Pies onto.
+/////////////////////////////////////////////////////////////////////////
public class PieWindow : Gtk.Window {
+
+ /////////////////////////////////////////////////////////////////////
+ /// Signal which gets emitted when the PieWindow is about to close.
+ /////////////////////////////////////////////////////////////////////
public signal void on_closing();
+
+ /////////////////////////////////////////////////////////////////////
+ /// The owned renderer.
+ /////////////////////////////////////////////////////////////////////
private PieRenderer renderer;
+
+ /////////////////////////////////////////////////////////////////////
+ /// True, if the Pie is currently fading out.
+ /////////////////////////////////////////////////////////////////////
+
private bool closing = false;
+
+ /////////////////////////////////////////////////////////////////////
+ /// A timer used for calculating the frame time.
+ /////////////////////////////////////////////////////////////////////
+
private GLib.Timer timer;
+ /////////////////////////////////////////////////////////////////////
+ /// True, if the screen supports compositing.
+ /////////////////////////////////////////////////////////////////////
+
private bool has_compositing = false;
+ /////////////////////////////////////////////////////////////////////
+ /// The background image used for fake transparency if
+ /// has_compositing is false.
+ /////////////////////////////////////////////////////////////////////
+
private Image background = null;
+
+ /////////////////////////////////////////////////////////////////////
+ /// C'tor, sets up the window.
+ /////////////////////////////////////////////////////////////////////
public PieWindow() {
this.renderer = new PieRenderer();
@@ -46,19 +79,27 @@ public class PieWindow : Gtk.Window {
this.icon_name = "gnome-pie";
this.set_accept_focus(false);
+ // check for compositing
if (this.screen.is_composited()) {
this.set_colormap(this.screen.get_rgba_colormap());
this.has_compositing = true;
}
+ // set up event filter
this.add_events(Gdk.EventMask.BUTTON_RELEASE_MASK |
Gdk.EventMask.KEY_RELEASE_MASK |
Gdk.EventMask.KEY_PRESS_MASK |
Gdk.EventMask.POINTER_MOTION_MASK);
+ // activate on left click
this.button_release_event.connect ((e) => {
- if (e.button == 1) this.activate_slice();
- else this.cancel();
+ 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;
});
@@ -72,32 +113,44 @@ 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;
- if (Config.global.turbo_mode)
+ if (this.renderer.turbo_mode)
this.activate_slice();
else
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;
});
+ // draw the pie on expose
this.expose_event.connect(this.draw);
}
+
+ /////////////////////////////////////////////////////////////////////
+ /// Loads a Pie to be rendered.
+ /////////////////////////////////////////////////////////////////////
public void load_pie(Pie pie) {
this.renderer.load_pie(pie);
this.set_window_position();
- this.set_size_request(renderer.get_size(), renderer.get_size());
+ 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;
this.get_position(out x, out y);
@@ -105,23 +158,31 @@ public class PieWindow : Gtk.Window {
this.background = new Image.capture_screen(x, y, width+1, height+1);
}
+ // capture the input focus
this.show();
- this.fix_focus();
+ FocusGrabber.grab(this);
+ // start the timer
this.timer = new GLib.Timer();
this.timer.start();
this.queue_draw();
+ // the main draw loop
Timeout.add((uint)(1000.0/Config.global.refresh_rate), () => {
this.queue_draw();
return this.visible;
});
}
+
+ /////////////////////////////////////////////////////////////////////
+ /// Draw the Pie.
+ /////////////////////////////////////////////////////////////////////
private bool draw(Gtk.Widget da, Gdk.EventExpose event) {
// clear the window
var ctx = Gdk.cairo_create(this.window);
+ // paint the background image if there is no compositing
if (this.has_compositing) {
ctx.set_operator (Cairo.Operator.CLEAR);
ctx.paint();
@@ -132,59 +193,80 @@ public class PieWindow : Gtk.Window {
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;
this.on_closing();
- this.unfix_focus();
+ FocusGrabber.ungrab(this);
this.renderer.activate();
Timeout.add((uint)(Config.global.theme.fade_out_time*1000), () => {
this.destroy();
- //ThemedIcon.clear_cache();
+ ThemedIcon.clear_cache();
return false;
});
}
}
+ /////////////////////////////////////////////////////////////////////
+ /// Activates no slice and closes the PieWindow.
+ /////////////////////////////////////////////////////////////////////
+
private void cancel() {
if (!this.closing) {
this.closing = true;
this.on_closing();
- this.unfix_focus();
+ FocusGrabber.ungrab(this);
this.renderer.cancel();
Timeout.add((uint)(Config.global.theme.fade_out_time*1000), () => {
this.destroy();
- //ThemedIcon.clear_cache();
+ ThemedIcon.clear_cache();
return false;
});
}
}
+ /////////////////////////////////////////////////////////////////////
+ /// Sets the position of the window to the center of the screen or to
+ /// the mouse.
+ /////////////////////////////////////////////////////////////////////
+
private void set_window_position() {
if(Config.global.open_at_mouse) this.set_position(Gtk.WindowPosition.MOUSE);
else this.set_position(Gtk.WindowPosition.CENTER);
}
+ /////////////////////////////////////////////////////////////////////
+ /// 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();
- else if (!Config.global.turbo_mode) {
+ else if (!this.renderer.turbo_mode) {
if (Gdk.keyval_name(key) == "Up") this.renderer.select_up();
else if (Gdk.keyval_name(key) == "Down") this.renderer.select_down();
else if (Gdk.keyval_name(key) == "Left") this.renderer.select_left();
@@ -212,52 +294,15 @@ public class PieWindow : Gtk.Window {
}
}
+ /////////////////////////////////////////////////////////////////////
+ /// Do some useful stuff when keys are released.
+ /////////////////////////////////////////////////////////////////////
+
private void handle_key_release(uint key) {
- if (!Config.global.turbo_mode) {
+ if (!this.renderer.turbo_mode) {
if (Gdk.keyval_name(key) == "Alt_L") this.renderer.show_hotkeys = false;
}
}
-
- // utilities for grabbing focus
- // Code from Gnome-Do/Synapse
- private void fix_focus() {
- uint32 timestamp = Gtk.get_current_event_time();
- this.present_with_time(timestamp);
- this.get_window().raise();
- this.get_window().focus(timestamp);
-
- int i = 0;
- Timeout.add(100, () => {
- if (++i >= 100) return false;
- return !try_grab_window();
- });
- }
-
- // Code from Gnome-Do/Synapse
- private void unfix_focus() {
- uint32 time = Gtk.get_current_event_time();
- Gdk.pointer_ungrab(time);
- Gdk.keyboard_ungrab(time);
- Gtk.grab_remove(this);
- }
-
- // Code from Gnome-Do/Synapse
- private bool try_grab_window() {
- uint time = Gtk.get_current_event_time();
- if (Gdk.pointer_grab(this.get_window(), true, Gdk.EventMask.BUTTON_PRESS_MASK |
- Gdk.EventMask.BUTTON_RELEASE_MASK | Gdk.EventMask.POINTER_MOTION_MASK,
- null, null, time) == Gdk.GrabStatus.SUCCESS) {
-
- if (Gdk.keyboard_grab(this.get_window(), true, time) == Gdk.GrabStatus.SUCCESS) {
- Gtk.grab_add(this);
- return true;
- } else {
- Gdk.pointer_ungrab(time);
- return false;
- }
- }
- return false;
- }
}
}
diff --git a/src/renderers/sliceRenderer.vala b/src/renderers/sliceRenderer.vala
index 08c880f..61c50b1 100644
--- a/src/renderers/sliceRenderer.vala
+++ b/src/renderers/sliceRenderer.vala
@@ -19,28 +19,77 @@ using GLib.Math;
namespace GnomePie {
-// Renders a Slice of a Pie. According to the current theme.
+/////////////////////////////////////////////////////////////////////////
+/// Renders a Slice of a Pie. According to the current theme.
+/////////////////////////////////////////////////////////////////////////
public class SliceRenderer : GLib.Object {
+ /////////////////////////////////////////////////////////////////////
+ /// Whether this slice is active (hovered) or not.
+ /////////////////////////////////////////////////////////////////////
+
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;
+
+ /////////////////////////////////////////////////////////////////////
+ /// The index of this slice in a pie. Clockwise assigned, starting
+ /// from the right-most slice.
+ /////////////////////////////////////////////////////////////////////
+
private int position;
- private AnimatedValue fade;
- private AnimatedValue scale;
- private AnimatedValue alpha;
- private AnimatedValue fade_rotation;
- private AnimatedValue fade_scale;
+ /////////////////////////////////////////////////////////////////////
+ /// 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
+ private AnimatedValue fade_rotation; // for fading in/out
+ private AnimatedValue fade_scale; // for fading in/out
+
+ /////////////////////////////////////////////////////////////////////
+ /// C'tor, initializes all AnimatedValues.
+ /////////////////////////////////////////////////////////////////////
public SliceRenderer(PieRenderer parent) {
this.parent = parent;
@@ -60,6 +109,10 @@ public class SliceRenderer : GLib.Object {
Config.global.theme.fade_in_rotation, 0.0,
Config.global.theme.fade_in_time);
}
+
+ /////////////////////////////////////////////////////////////////////
+ /// Loads an Action. All members are initialized accordingly.
+ /////////////////////////////////////////////////////////////////////
public void load(Action action, int position) {
this.position = position;
@@ -88,10 +141,19 @@ public class SliceRenderer : GLib.Object {
(int)Config.global.theme.slice_radius*2, "sans 20");
}
+ /////////////////////////////////////////////////////////////////////
+ /// 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,
@@ -105,6 +167,11 @@ public class SliceRenderer : GLib.Object {
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);
@@ -112,6 +179,10 @@ 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) {
@@ -134,6 +205,7 @@ public class SliceRenderer : GLib.Object {
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);
+ // update the AnimatedValues
this.scale.update(frame_time);
this.alpha.update(frame_time);
this.fade.update(frame_time);
@@ -142,14 +214,17 @@ public class SliceRenderer : GLib.Object {
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);
@@ -157,6 +232,7 @@ public class SliceRenderer : GLib.Object {
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));
@@ -172,6 +248,7 @@ public class SliceRenderer : GLib.Object {
ctx.pop_group_to_source();
ctx.paint();
+ // draw hotkeys if necassary
if (this.parent.show_hotkeys)
this.hotkey.paint_on(ctx, 1.0);