summaryrefslogtreecommitdiff
path: root/src/gui/piePreviewDeleteSign.vala
diff options
context:
space:
mode:
authorAlessandro Ghedini <al3xbio@gmail.com>2012-01-21 19:14:06 +0100
committerAlessandro Ghedini <al3xbio@gmail.com>2012-01-21 19:19:46 +0100
commitc05883f47c498be4e11893e5178c5bc37ffd9f4a (patch)
treedbd3cd7ad3d7771405ad63af2f1e9d14d4ae5a35 /src/gui/piePreviewDeleteSign.vala
parent31539042f11bc210a29e923f45586779c3ad46b2 (diff)
parent60560a030fda3c539ff9dc1563b9926414a193da (diff)
Merge commit 'upstream/0.4.0'
Diffstat (limited to 'src/gui/piePreviewDeleteSign.vala')
-rw-r--r--src/gui/piePreviewDeleteSign.vala195
1 files changed, 195 insertions, 0 deletions
diff --git a/src/gui/piePreviewDeleteSign.vala b/src/gui/piePreviewDeleteSign.vala
new file mode 100644
index 0000000..2ff3321
--- /dev/null
+++ b/src/gui/piePreviewDeleteSign.vala
@@ -0,0 +1,195 @@
+/*
+Copyright (c) 2011 by Simon Schneegans
+
+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 3 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, see <http://www.gnu.org/licenses/>.
+*/
+
+using GLib.Math;
+
+namespace GnomePie {
+
+/////////////////////////////////////////////////////////////////////////
+/// The delete sign, displayed in the upper right corner of each
+/// Slice.
+/////////////////////////////////////////////////////////////////////////
+
+public class PiePreviewDeleteSign : GLib.Object {
+
+ /////////////////////////////////////////////////////////////////////
+ /// Called when the user clicked on this sign.
+ /////////////////////////////////////////////////////////////////////
+
+ public signal void on_clicked();
+
+ /////////////////////////////////////////////////////////////////////
+ /// The image used to display this oject.
+ /////////////////////////////////////////////////////////////////////
+
+ public Image icon { get; private set; }
+
+ /////////////////////////////////////////////////////////////////////
+ /// Some constants determining the look and behaviour of this Slice.
+ /////////////////////////////////////////////////////////////////////
+
+ private const int radius = 18;
+ private const double globale_scale = 0.8;
+ private const double click_cancel_treshold = 5;
+
+ /////////////////////////////////////////////////////////////////////
+ /// True, when the add sign is currently visible.
+ /////////////////////////////////////////////////////////////////////
+
+ private bool visible = false;
+
+ /////////////////////////////////////////////////////////////////////
+ /// Some AnimatedValues for smooth transitions.
+ /////////////////////////////////////////////////////////////////////
+
+ private AnimatedValue size;
+ private AnimatedValue alpha;
+ private AnimatedValue activity;
+ private AnimatedValue clicked;
+
+ /////////////////////////////////////////////////////////////////////
+ /// Storing the position where a mouse click was executed. Useful for
+ /// canceling the click when the mouse moves some pixels.
+ /////////////////////////////////////////////////////////////////////
+
+ private double clicked_x = 0.0;
+ private double clicked_y = 0.0;
+
+ /////////////////////////////////////////////////////////////////////
+ /// C'tor, sets everything up.
+ /////////////////////////////////////////////////////////////////////
+
+ public PiePreviewDeleteSign() {
+ this.size = new AnimatedValue.cubic(AnimatedValue.Direction.OUT, 0, 0, 0, 2.0);
+ this.alpha = new AnimatedValue.cubic(AnimatedValue.Direction.OUT, 0, 0, 0, 0.0);
+ this.activity = new AnimatedValue.cubic(AnimatedValue.Direction.OUT, -3, -3, 0, 0.0);
+ this.clicked = new AnimatedValue.cubic(AnimatedValue.Direction.OUT, 1, 1, 0, 0.0);
+ }
+
+ /////////////////////////////////////////////////////////////////////
+ /// Loads an Action. All members are initialized accordingly.
+ /////////////////////////////////////////////////////////////////////
+
+ public void load() {
+ this.icon = new Icon("stock_delete", radius*2);
+ }
+
+ /////////////////////////////////////////////////////////////////////
+ /// Makes this object visible.
+ /////////////////////////////////////////////////////////////////////
+
+ public void show() {
+ if (!this.visible) {
+ this.visible = true;
+ this.alpha.reset_target(1.0, 0.3);
+ }
+ }
+
+ /////////////////////////////////////////////////////////////////////
+ /// Makes this object invisible.
+ /////////////////////////////////////////////////////////////////////
+
+ public void hide() {
+ if (this.visible) {
+ this.visible = false;
+ this.alpha.reset_target(0.0, 0.3);
+ }
+ }
+
+ /////////////////////////////////////////////////////////////////////
+ /// Updates the size of this object. All transitions will be smooth.
+ /////////////////////////////////////////////////////////////////////
+
+ public void set_size(double size) {
+ this.size.reset_target(size, 0.2);
+ }
+
+ /////////////////////////////////////////////////////////////////////
+ /// Draws the sign to the given context.
+ /////////////////////////////////////////////////////////////////////
+
+ public void draw(double frame_time, Cairo.Context ctx) {
+ this.size.update(frame_time);
+ this.alpha.update(frame_time);
+ this.activity.update(frame_time);
+ this.clicked.update(frame_time);
+
+ if (this.alpha.val > 0) {
+ ctx.save();
+
+ // transform the context
+ double scale = (this.size.val*this.clicked.val
+ + this.activity.val*0.2 - 0.2)*globale_scale;
+ ctx.scale(scale, scale);
+
+ // paint the image
+ icon.paint_on(ctx, this.alpha.val);
+
+ ctx.restore();
+ }
+ }
+
+ /////////////////////////////////////////////////////////////////////
+ /// Called when the mouse moves to another position.
+ /////////////////////////////////////////////////////////////////////
+
+ public bool on_mouse_move(double x, double y) {
+ if (this.clicked.end == 0.9) {
+ double dist = GLib.Math.pow(x-this.clicked_x, 2) + GLib.Math.pow(y-this.clicked_y, 2);
+ if (dist > this.click_cancel_treshold*this.click_cancel_treshold)
+ this.clicked.reset_target(1.0, 0.1);
+ }
+
+ if (GLib.Math.fabs(x) <= radius*globale_scale && GLib.Math.fabs(y) <= radius*globale_scale) {
+ this.activity.reset_target(1.0, 0.2);
+ return true;
+ }
+
+ this.activity.reset_target(0.0, 0.2);
+ return false;
+ }
+
+ /////////////////////////////////////////////////////////////////////
+ /// Called when a button of the mouse is pressed.
+ /////////////////////////////////////////////////////////////////////
+
+ public bool on_button_press(double x, double y) {
+ if (this.activity.end == 1.0) {
+ this.clicked.reset_target(0.9, 0.1);
+ this.clicked_x = x;
+ this.clicked_y = y;
+ return true;
+ }
+ return false;
+ }
+
+ /////////////////////////////////////////////////////////////////////
+ /// Called when a button of the mouse is released.
+ /////////////////////////////////////////////////////////////////////
+
+ public bool on_button_release(double x, double y) {
+ if (this.clicked.end == 0.9) {
+ this.clicked.reset_target(1.0, 0.1);
+ this.on_clicked();
+
+ return true;
+ }
+ return false;
+ }
+}
+
+}