From d6b2677825cbb423e2099563c16321c3e23d7899 Mon Sep 17 00:00:00 2001 From: Alessandro Ghedini Date: Sun, 20 Nov 2011 15:50:38 +0100 Subject: Imported Upstream version 0.3.1 --- src/renderers/sliceRenderer.vala | 89 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 83 insertions(+), 6 deletions(-) (limited to 'src/renderers/sliceRenderer.vala') 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); -- cgit v1.2.3 From 60560a030fda3c539ff9dc1563b9926414a193da Mon Sep 17 00:00:00 2001 From: Alessandro Ghedini Date: Sat, 21 Jan 2012 19:07:09 +0100 Subject: Imported Upstream version 0.4.0 --- src/renderers/sliceRenderer.vala | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) (limited to 'src/renderers/sliceRenderer.vala') diff --git a/src/renderers/sliceRenderer.vala b/src/renderers/sliceRenderer.vala index 61c50b1..4803070 100644 --- a/src/renderers/sliceRenderer.vala +++ b/src/renderers/sliceRenderer.vala @@ -20,7 +20,7 @@ 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 { @@ -123,7 +123,9 @@ public class SliceRenderer : GLib.Object { 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_font, + Config.global.theme.caption_color, + Config.global.global_scale); this.active_icon = new ThemedIcon(action.icon, true); this.inactive_icon = new ThemedIcon(action.icon, false); @@ -138,7 +140,8 @@ public class SliceRenderer : GLib.Object { } this.hotkey = new RenderedText(hotkey_label, (int)Config.global.theme.slice_radius*2, - (int)Config.global.theme.slice_radius*2, "sans 20"); + (int)Config.global.theme.slice_radius*2, "sans 20", + Config.global.theme.caption_color, Config.global.global_scale); } ///////////////////////////////////////////////////////////////////// @@ -185,6 +188,13 @@ public class SliceRenderer : GLib.Object { ///////////////////////////////////////////////////////////////////// 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); + this.fade.update(frame_time); + this.fade_scale.update(frame_time); + this.fade_rotation.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; @@ -205,13 +215,6 @@ 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); - this.fade_scale.update(frame_time); - this.fade_rotation.update(frame_time); - ctx.save(); // distance from the center -- cgit v1.2.3