Merge lp:~unity-team/unity/unity.fix-608124-2 into lp:unity

Proposed by Mirco Müller
Status: Merged
Merged at revision: 474
Proposed branch: lp:~unity-team/unity/unity.fix-608124-2
Merge into: lp:unity
Diff against target: 210 lines (+140/-7)
1 file modified
unity-private/places/places-default-renderer.vala (+140/-7)
To merge this branch: bzr merge lp:~unity-team/unity/unity.fix-608124-2
Reviewer Review Type Date Requested Status
Mikkel Kamstrup Erlandsen (community) Approve
Review via email: mp+34053@code.launchpad.net

Description of the change

Better (following the mockups more) scrollbar visuals.

To post a comment you must log in.
Revision history for this message
Mikkel Kamstrup Erlandsen (kamstrup) wrote :

The if-statements starting on line 93 of the diff could use some 'else if's for code clarity. Same for the ifs starting on line 131.

Otherwise - works well. Code looks good. Diff is nice and tidy. Good work!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'unity-private/places/places-default-renderer.vala'
2--- unity-private/places/places-default-renderer.vala 2010-08-26 17:04:48 +0000
3+++ unity-private/places/places-default-renderer.vala 2010-08-30 08:40:58 +0000
4@@ -24,13 +24,19 @@
5 static const float TOP_PADDING = 22.0f;
6 static const float PADDING = 12.0f;
7 static const int SPACING = 0;
8-
9+ static const int SLIDER_STATE_NORMAL = 0;
10+ static const int SLIDER_STATE_PRELIGHT = 1;
11+ static const int SLIDER_STATE_ACTIVE = 2;
12+
13 private EmptySearchGroup search_empty;
14 private EmptySectionGroup section_empty;
15
16 private Ctk.ScrollView scroll;
17 private Unity.CairoCanvas trough;
18 private Unity.CairoCanvas slider;
19+ private int slider_state;
20+ private bool button_pressed;
21+ private Ctk.EffectGlow slider_glow;
22 private Ctk.VBox box;
23 private Dee.Model groups_model;
24 private Dee.Model results_model;
25@@ -58,7 +64,12 @@
26 int width,
27 int height)
28 {
29- double radius = (double) width / 2.0f;
30+ Cairo.Surface dots = new Cairo.ImageSurface (Cairo.Format.ARGB32,
31+ 4,
32+ 4);
33+ Cairo.Context cr_dots = new Cairo.Context (dots);
34+ Cairo.Pattern dot_pattern;
35+ double radius = (double) width / 2.0f;
36
37 cr.set_operator (Cairo.Operator.CLEAR);
38 cr.paint ();
39@@ -79,6 +90,30 @@
40 180.0f * GLib.Math.PI / 180.0f);
41 cr.close_path ();
42 cr.set_source_rgba (1.0f, 1.0f, 1.0f, 0.1f);
43+
44+ // draw dotted pattern
45+ cr_dots.set_operator (Cairo.Operator.CLEAR);
46+ cr_dots.paint ();
47+ cr_dots.scale (1.0f, 1.0f);
48+ cr_dots.set_operator (Cairo.Operator.OVER);
49+ cr_dots.set_source_rgba (1.0f, 1.0f, 1.0f, 0.025f);
50+ cr_dots.rectangle (0.0f, 0.0f, 1.0f, 1.0f);
51+ cr_dots.fill ();
52+ cr_dots.rectangle (1.0f, 1.0f, 1.0f, 1.0f);
53+ cr_dots.fill ();
54+ cr_dots.rectangle (2.0f, 0.0f, 1.0f, 1.0f);
55+ cr_dots.fill ();
56+ cr_dots.rectangle (0.0f, 2.0f, 1.0f, 1.0f);
57+ cr_dots.fill ();
58+ cr_dots.rectangle (2.0f, 2.0f, 1.0f, 1.0f);
59+ cr_dots.fill ();
60+ cr_dots.rectangle (3.0f, 3.0f, 1.0f, 1.0f);
61+ cr_dots.fill ();
62+
63+ dot_pattern = new Cairo.Pattern.for_surface (dots);
64+ cr.set_operator (Cairo.Operator.OVER);
65+ cr.set_source (dot_pattern);
66+ dot_pattern.set_extend (Cairo.Extend.REPEAT);
67 cr.fill_preserve ();
68 cr.set_source_rgba (1.0f, 1.0f, 1.0f, 0.35f);
69 cr.stroke ();
70@@ -89,9 +124,14 @@
71 int width,
72 int height)
73 {
74- double radius = (double) width / 2.0f;
75- double half = (double) width / 2.0f;
76- double half_height = (double) height / 2.0f;
77+ Cairo.Surface stripes = new Cairo.ImageSurface (Cairo.Format.ARGB32,
78+ 4,
79+ 4);
80+ Cairo.Context cr_stripes = new Cairo.Context (stripes);
81+ Cairo.Pattern stripe_pattern;
82+ double radius = (double) width / 2.0f;
83+ double half = (double) width / 2.0f;
84+ double half_height = (double) height / 2.0f;
85
86 cr.set_operator (Cairo.Operator.CLEAR);
87 cr.paint ();
88@@ -111,7 +151,37 @@
89 0.0f * GLib.Math.PI / 180.0f,
90 180.0f * GLib.Math.PI / 180.0f);
91 cr.close_path ();
92- cr.set_source_rgba (0.0f, 0.0f, 0.0f, 0.15f);
93+
94+ if (slider_state == SLIDER_STATE_NORMAL)
95+ {
96+ cr.set_source_rgba (0.0f, 0.0f, 0.0f, 0.15f);
97+ }
98+ if (slider_state == SLIDER_STATE_PRELIGHT)
99+ {
100+ cr_stripes.set_operator (Cairo.Operator.CLEAR);
101+ cr_stripes.paint ();
102+ cr_stripes.scale (1.0f, 1.0f);
103+ cr_stripes.set_operator (Cairo.Operator.OVER);
104+ cr_stripes.set_source_rgba (1.0f, 1.0f, 1.0f, 0.25f);
105+ cr_stripes.rectangle (0.0f, 0.0f, 1.0f, 1.0f);
106+ cr_stripes.fill ();
107+ cr_stripes.rectangle (1.0f, 1.0f, 1.0f, 1.0f);
108+ cr_stripes.fill ();
109+ cr_stripes.rectangle (2.0f, 2.0f, 1.0f, 1.0f);
110+ cr_stripes.fill ();
111+ cr_stripes.rectangle (3.0f, 3.0f, 1.0f, 1.0f);
112+ cr_stripes.fill ();
113+
114+ stripe_pattern = new Cairo.Pattern.for_surface (stripes);
115+ cr.set_operator (Cairo.Operator.OVER);
116+ cr.set_source (stripe_pattern);
117+ stripe_pattern.set_extend (Cairo.Extend.REPEAT);
118+ }
119+ if (slider_state == SLIDER_STATE_ACTIVE)
120+ {
121+ cr.set_source_rgba (1.0f, 1.0f, 1.0f, 1.0f);
122+ }
123+
124 cr.fill_preserve ();
125 cr.set_source_rgba (1.0f, 1.0f, 1.0f, 0.5f);
126 cr.stroke ();
127@@ -123,19 +193,82 @@
128 cr.line_to (_align ((double) width - 2.0f), _align (half_height));
129 cr.move_to (_align (1.0f), _align (half_height + 2.0f));
130 cr.line_to (_align ((double) width - 2.0f), _align (half_height + 2.0f));
131+
132+ if (slider_state == SLIDER_STATE_NORMAL ||
133+ slider_state == SLIDER_STATE_PRELIGHT)
134+ {
135+ cr.set_operator (Cairo.Operator.OVER);
136+ }
137+ if (slider_state == SLIDER_STATE_ACTIVE)
138+ {
139+ cr.set_operator (Cairo.Operator.CLEAR);
140+ }
141+
142 cr.stroke ();
143 }
144
145+ private bool
146+ on_slider_enter (Clutter.Event event)
147+ {
148+ slider_state = SLIDER_STATE_PRELIGHT;
149+ slider.update ();
150+ slider_glow.set_invalidate_effect_cache (true);
151+ return false;
152+ }
153+
154+ private bool
155+ on_slider_leave (Clutter.Event event)
156+ {
157+ if (!button_pressed)
158+ {
159+ slider_state = SLIDER_STATE_NORMAL;
160+ slider.update ();
161+ slider_glow.set_invalidate_effect_cache (true);
162+ }
163+ return false;
164+ }
165+
166+ private bool
167+ on_slider_button_press (Clutter.Event event)
168+ {
169+ button_pressed = true;
170+ slider_state = SLIDER_STATE_ACTIVE;
171+ slider.update ();
172+ slider_glow.set_invalidate_effect_cache (true);
173+ return false;
174+ }
175+
176+ private bool
177+ on_slider_button_release (Clutter.Event event)
178+ {
179+ button_pressed = false;
180+ slider_state = SLIDER_STATE_PRELIGHT;
181+ slider.update ();
182+ slider_glow.set_invalidate_effect_cache (true);
183+ return false;
184+ }
185+
186 construct
187 {
188 padding = { PADDING, 0.0f, 0.0f, 0.0f };
189
190+ slider_glow = new Ctk.EffectGlow ();
191+ slider_glow.set_color ({ 255, 255, 255, 255 });
192+ slider_glow.set_factor (1.0f);
193+ slider_glow.set_margin (5);
194+
195 trough = new Unity.CairoCanvas (trough_paint);
196 slider = new Unity.CairoCanvas (slider_paint);
197+ slider.enter_event.connect (on_slider_enter);
198+ slider.leave_event.connect (on_slider_leave);
199+ slider.button_press_event.connect (on_slider_button_press);
200+ slider.button_release_event.connect (on_slider_button_release);
201+ slider_state = SLIDER_STATE_NORMAL;
202+ button_pressed = false;
203+ slider.add_effect (slider_glow);
204
205 scroll = new Ctk.ScrollView ();
206 scroll.set_scroll_bar (trough, slider);
207- //slider.reactive = true;
208 add_actor (scroll);
209 scroll.show ();
210 trough.show ();