Merge lp:~3v1n0/unity-greeter/shutdown-fade into lp:unity-greeter

Proposed by Marco Trevisan (Treviño)
Status: Merged
Approved by: Marco Trevisan (Treviño)
Approved revision: 1052
Merged at revision: 1024
Proposed branch: lp:~3v1n0/unity-greeter/shutdown-fade
Merge into: lp:unity-greeter
Prerequisite: lp:~3v1n0/unity-greeter/shutdown-blurred-bg
Diff against target: 164 lines (+57/-12)
3 files modified
src/animate-timer.vala (+13/-7)
src/main-window.vala (+2/-2)
src/shutdown-dialog.vala (+42/-3)
To merge this branch: bzr merge lp:~3v1n0/unity-greeter/shutdown-fade
Reviewer Review Type Date Requested Status
Robert Ancell Approve
Review via email: mp+194972@code.launchpad.net

Commit message

ShutdownDialog: fade-in/out the dialog when opening/closing it

The old "close" signal is now a method, while the view actually closes
on "closed" signal callback in main window.

Description of the change

Fade the shutdown dialog in/out when showing/hiding it.

Changed the behavior of the AnimateTimer so that it won't stop if the easing curve value reaches the 1.0f progress (it might be only a peek, depending on the easing curve we use); always care about time progress only instead.

To post a comment you must log in.
Revision history for this message
Robert Ancell (robert-ancell) wrote :

Incorrect indentatin
121 + if (p >= 1.0f)
122 + {
123 + animation.stop ();
124 + closed ();
125 + }

Otherwise works great!

review: Approve
Revision history for this message
Robert Ancell (robert-ancell) wrote :

(Doesn't need a re-review once indentation fixed)

review: Needs Fixing
Revision history for this message
Marco Trevisan (Treviño) (3v1n0) wrote :

Ups, pushed the fix.

Revision history for this message
Robert Ancell (robert-ancell) :
review: Approve
Revision history for this message
Marco Trevisan (Treviño) (3v1n0) wrote :

Merged with parent branch to fix conflicts... Reapproving myself.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/animate-timer.vala'
2--- src/animate-timer.vala 2013-06-19 20:08:25 +0000
3+++ src/animate-timer.vala 2013-11-13 04:28:56 +0000
4@@ -58,6 +58,11 @@
5 this.easing_func = func;
6 }
7
8+ ~AnimateTimer ()
9+ {
10+ stop ();
11+ }
12+
13 /* temp_speed is in milliseconds */
14 public void reset (int temp_speed = -1)
15 {
16@@ -93,10 +98,11 @@
17 if (start_time == 0)
18 start_time = GLib.get_monotonic_time ();
19
20- progress = calculate_progress (GLib.get_monotonic_time ());
21+ var time_progress = normalize_time (GLib.get_monotonic_time ());
22+ progress = calculate_progress (time_progress);
23 animate (progress);
24
25- if (progress >= 1.0)
26+ if (time_progress >= 1.0)
27 {
28 timeout = 0;
29 return false;
30@@ -108,17 +114,17 @@
31 /* Returns 0.0 to 1.0 where 1.0 is at or past end_time */
32 private double normalize_time (TimeSpan now)
33 {
34+ if (length == 0)
35+ return 1.0f;
36+
37 return (((double)(now - start_time)) / length).clamp (0.0, 1.0);
38 }
39
40 /* Returns 0.0 to 1.0 where 1.0 is done.
41 time is not normalized yet! */
42- private double calculate_progress (TimeSpan time)
43+ private double calculate_progress (double time_progress)
44 {
45- if (length == 0)
46- return 1.0;
47- var x = normalize_time (time);
48- var y = easing_func (x);
49+ var y = easing_func (time_progress);
50 return y.clamp (0.0, 1.0);
51 }
52
53
54=== modified file 'src/main-window.vala'
55--- src/main-window.vala 2013-11-13 04:28:56 +0000
56+++ src/main-window.vala 2013-11-13 04:28:56 +0000
57@@ -343,10 +343,10 @@
58 login_box.sensitive = false;
59
60 shutdown_dialog = new ShutdownDialog (type, background);
61- shutdown_dialog.visible = true;
62- shutdown_dialog.close.connect (close_shutdown_dialog);
63+ shutdown_dialog.closed.connect (close_shutdown_dialog);
64 background.add (shutdown_dialog);
65 move_to_monitor (active_monitor);
66+ shutdown_dialog.visible = true;
67 }
68
69 public void close_shutdown_dialog ()
70
71=== modified file 'src/shutdown-dialog.vala'
72--- src/shutdown-dialog.vala 2013-11-13 04:28:56 +0000
73+++ src/shutdown-dialog.vala 2013-11-13 04:28:56 +0000
74@@ -27,7 +27,7 @@
75
76 public class ShutdownDialog : Gtk.Fixed
77 {
78- public signal void close ();
79+ public signal void closed ();
80
81 private Cairo.ImageSurface? bg_surface = null;
82 private Cairo.ImageSurface? corner_surface = null;
83@@ -53,6 +53,8 @@
84 private Gtk.EventBox monitor_events;
85 private Gtk.EventBox vbox_events;
86
87+ private AnimateTimer animation;
88+ private bool closing = false;
89
90 public ShutdownDialog (ShutdownDialogType type, Background bg)
91 {
92@@ -188,6 +190,9 @@
93 warning ("Failed to shutdown: %s", e.message);
94 }
95 });
96+
97+ if (type != ShutdownDialogType.SHUTDOWN)
98+ show.connect(() => { button.grab_focus (); });
99 }
100
101 close_button = new DialogButton (Path.build_filename (Config.PKGDATADIR, "dialog_close.png"), Path.build_filename (Config.PKGDATADIR, "dialog_close_highlight.png"), Path.build_filename (Config.PKGDATADIR, "dialog_close_press.png"));
102@@ -195,6 +200,29 @@
103 close_button.clicked.connect (() => { close (); });
104 close_button.visible = true;
105 add (close_button);
106+
107+ animation = new AnimateTimer ((x) => { return x; }, AnimateTimer.INSTANT);
108+ animation.animate.connect (() => { queue_draw (); });
109+ show.connect (() => { animation.reset(); });
110+ }
111+
112+ public void close ()
113+ {
114+ var start_value = 1.0f - animation.progress;
115+ animation = new AnimateTimer ((x) => { return start_value + x; }, AnimateTimer.INSTANT);
116+ animation.animate.connect ((p) =>
117+ {
118+ queue_draw ();
119+
120+ if (p >= 1.0f)
121+ {
122+ animation.stop ();
123+ closed ();
124+ }
125+ });
126+
127+ closing = true;
128+ animation.reset();
129 }
130
131 private void rebuild_background ()
132@@ -276,11 +304,14 @@
133 int x = (get_allocated_width () - width) / 2;
134 int y = (get_allocated_height () - height) / 2;
135
136+ if (animation.is_running)
137+ c.push_group ();
138+
139 /* Darken background */
140 c.set_source_rgba (0, 0, 0, 0.25);
141 c.paint ();
142
143- if (bg_surface == null)
144+ if (bg_surface == null || animation.is_running)
145 {
146 /* Create a new blurred surface of the current surface */
147 bg_surface = new Cairo.ImageSurface (Cairo.Format.ARGB32, width, height);
148@@ -385,7 +416,15 @@
149
150 c.restore ();
151
152- return base.draw (c);
153+ var ret = base.draw (c);
154+
155+ if (animation.is_running)
156+ {
157+ c.pop_group_to_source ();
158+ c.paint_with_alpha (closing ? 1.0f - animation.progress : animation.progress);
159+ }
160+
161+ return ret;
162 }
163
164 private DialogButton add_button (string text, string inactive_filename, string active_filename)

Subscribers

People subscribed via source and target branches