Merge lp:~cimi/overlay-scrollbar/fitt-law into lp:overlay-scrollbar
- fitt-law
- Merge into trunk
Proposed by
Andrea Cimitan
Status: | Merged |
---|---|
Merged at revision: | 230 |
Proposed branch: | lp:~cimi/overlay-scrollbar/fitt-law |
Merge into: | lp:overlay-scrollbar |
Diff against target: |
461 lines (+196/-116) 3 files modified
os/os-private.h (+8/-5) os/os-scrollbar.c (+38/-4) os/os-thumb.c (+150/-107) |
To merge this branch: | bzr merge lp:~cimi/overlay-scrollbar/fitt-law |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Ted Gould (community) | Approve | ||
Review via email: mp+60301@code.launchpad.net |
Commit message
Description of the change
To post a comment you must log in.
- 231. By Andrea Cimitan
-
Don't check for detached state on drag. Indentation fixes
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'os/os-private.h' |
2 | --- os/os-private.h 2011-04-05 16:21:15 +0000 |
3 | +++ os/os-private.h 2011-05-08 14:08:31 +0000 |
4 | @@ -31,8 +31,8 @@ |
5 | #endif /* __GNUC__ */ |
6 | |
7 | /* Default size of the thumb in pixels. */ |
8 | -#define DEFAULT_THUMB_WIDTH 15 |
9 | -#define DEFAULT_THUMB_HEIGHT 67 |
10 | +#define DEFAULT_THUMB_WIDTH 17 |
11 | +#define DEFAULT_THUMB_HEIGHT 69 |
12 | |
13 | G_BEGIN_DECLS |
14 | |
15 | @@ -167,9 +167,12 @@ |
16 | GtkWindowClass parent_class; |
17 | }; |
18 | |
19 | -GType os_thumb_get_type (void) G_GNUC_CONST; |
20 | - |
21 | -GtkWidget* os_thumb_new (GtkOrientation orientation); |
22 | +GType os_thumb_get_type (void) G_GNUC_CONST; |
23 | + |
24 | +GtkWidget* os_thumb_new (GtkOrientation orientation); |
25 | + |
26 | +void os_thumb_set_detached (OsThumb *thumb, |
27 | + gboolean detached); |
28 | |
29 | /* os-pager.c */ |
30 | |
31 | |
32 | === modified file 'os/os-scrollbar.c' |
33 | --- os/os-scrollbar.c 2011-04-26 22:33:59 +0000 |
34 | +++ os/os-scrollbar.c 2011-05-08 14:08:31 +0000 |
35 | @@ -32,6 +32,9 @@ |
36 | /* Default size of the pager in pixels. */ |
37 | #define DEFAULT_PAGER_WIDTH 3 |
38 | |
39 | +/* Default thumb allocation shift in pixels. */ |
40 | +#define THUMB_ALLOCATION_SHIFT -3 |
41 | + |
42 | /* Width of the proximity effect in pixels. */ |
43 | #define PROXIMITY_WIDTH 30 |
44 | |
45 | @@ -539,7 +542,7 @@ |
46 | (x - 1 + priv->slider.width) >= screen_width)) |
47 | { |
48 | priv->internal = TRUE; |
49 | - return x - DEFAULT_PAGER_WIDTH - priv->slider.width; |
50 | + return MAX (x - priv->slider.width, screen_width - priv->slider.width); |
51 | } |
52 | |
53 | if (priv->orientation == GTK_ORIENTATION_VERTICAL) |
54 | @@ -573,7 +576,7 @@ |
55 | (y - 1 + priv->slider.height) >= screen_height)) |
56 | { |
57 | priv->internal = TRUE; |
58 | - return y - DEFAULT_PAGER_WIDTH - priv->slider.height; |
59 | + return MAX (y - priv->slider.height, screen_height - priv->slider.height); |
60 | } |
61 | |
62 | if (priv->orientation == GTK_ORIENTATION_HORIZONTAL) |
63 | @@ -1162,6 +1165,35 @@ |
64 | if (!priv->motion_notify_event && !priv->enter_notify_event) |
65 | gtk_widget_hide (GTK_WIDGET (priv->thumb)); |
66 | |
67 | + if (gtk_widget_get_mapped (GTK_WIDGET (priv->thumb))) |
68 | + { |
69 | + /* if we're dragging the thumb, it can't be detached. */ |
70 | + if (priv->motion_notify_event) |
71 | + os_thumb_set_detached (OS_THUMB (priv->thumb), FALSE); |
72 | + else |
73 | + { |
74 | + gint x_pos, y_pos; |
75 | + gdk_window_get_origin (gtk_widget_get_window (GTK_WIDGET (priv->thumb)), &x_pos, &y_pos); |
76 | + |
77 | + if (priv->orientation == GTK_ORIENTATION_VERTICAL) |
78 | + { |
79 | + if ((priv->win_y + priv->overlay.y > y_pos + priv->slider.height) || |
80 | + (priv->win_y + priv->overlay.y + priv->overlay.height < y_pos)) |
81 | + os_thumb_set_detached (OS_THUMB (priv->thumb), TRUE); |
82 | + else |
83 | + os_thumb_set_detached (OS_THUMB (priv->thumb), FALSE); |
84 | + } |
85 | + else |
86 | + { |
87 | + if ((priv->win_x + priv->overlay.x > x_pos + priv->slider.width) || |
88 | + (priv->win_x + priv->overlay.x + priv->overlay.width < x_pos)) |
89 | + os_thumb_set_detached (OS_THUMB (priv->thumb), TRUE); |
90 | + else |
91 | + os_thumb_set_detached (OS_THUMB (priv->thumb), FALSE); |
92 | + } |
93 | + } |
94 | + } |
95 | + |
96 | pager_move (scrollbar); |
97 | } |
98 | |
99 | @@ -1399,6 +1431,7 @@ |
100 | os_scrollbar_move_thumb (scrollbar, priv->win_x, priv->win_y + priv->slider.y); |
101 | } |
102 | |
103 | + os_thumb_set_detached (OS_THUMB (priv->thumb), FALSE); |
104 | gtk_widget_show (GTK_WIDGET (priv->thumb)); |
105 | } |
106 | else |
107 | @@ -1438,6 +1471,7 @@ |
108 | os_scrollbar_move_thumb (scrollbar, priv->win_x + priv->slider.x, priv->win_y); |
109 | } |
110 | |
111 | + os_thumb_set_detached (OS_THUMB (priv->thumb), FALSE); |
112 | gtk_widget_show (GTK_WIDGET (priv->thumb)); |
113 | } |
114 | else |
115 | @@ -1771,7 +1805,7 @@ |
116 | priv->slider.width = DEFAULT_THUMB_WIDTH; |
117 | priv->slider.height = DEFAULT_THUMB_HEIGHT; |
118 | priv->overlay_all.x = allocation->x - DEFAULT_PAGER_WIDTH; |
119 | - priv->thumb_all.x = allocation->x; |
120 | + priv->thumb_all.x = allocation->x + THUMB_ALLOCATION_SHIFT; |
121 | |
122 | rect.x = priv->overlay_all.x; |
123 | rect.y = priv->overlay_all.y; |
124 | @@ -1785,7 +1819,7 @@ |
125 | priv->slider.width = DEFAULT_THUMB_HEIGHT; |
126 | priv->slider.height = DEFAULT_THUMB_WIDTH; |
127 | priv->overlay_all.y = allocation->y - DEFAULT_PAGER_WIDTH ; |
128 | - priv->thumb_all.y = allocation->y; |
129 | + priv->thumb_all.y = allocation->y + THUMB_ALLOCATION_SHIFT; |
130 | |
131 | rect.x = priv->overlay_all.x; |
132 | rect.y = priv->overlay_all.y; |
133 | |
134 | === modified file 'os/os-thumb.c' |
135 | --- os/os-thumb.c 2011-04-20 14:51:48 +0000 |
136 | +++ os/os-thumb.c 2011-05-08 14:08:31 +0000 |
137 | @@ -40,6 +40,9 @@ |
138 | /* Number of tolerance pixels. */ |
139 | #define TOLERANCE_PIXELS 3 |
140 | |
141 | +/* Thumb radius in pixels (higher values are automatically clamped). */ |
142 | +#define THUMB_RADIUS 9 |
143 | + |
144 | struct _OsThumbPrivate { |
145 | GtkOrientation orientation; |
146 | GtkWidget *grabbed_widget; |
147 | @@ -48,6 +51,7 @@ |
148 | gboolean motion_notify_event; |
149 | gboolean can_rgba; |
150 | gboolean use_tolerance; |
151 | + gboolean detached; |
152 | gint pointer_x; |
153 | gint pointer_y; |
154 | guint32 source_id; |
155 | @@ -79,6 +83,31 @@ |
156 | |
157 | /* Private functions. */ |
158 | |
159 | +/* Draw an arror. */ |
160 | +static void |
161 | +os_cairo_draw_arrow (cairo_t *cr, |
162 | + gdouble x, |
163 | + gdouble y, |
164 | + gdouble width, |
165 | + gdouble height) |
166 | +{ |
167 | + cairo_save (cr); |
168 | + |
169 | + cairo_translate (cr, x, y); |
170 | + cairo_move_to (cr, -width / 2, -height / 2); |
171 | + cairo_line_to (cr, 0, height / 2); |
172 | + cairo_line_to (cr, width / 2, -height / 2); |
173 | + cairo_close_path (cr); |
174 | + |
175 | + cairo_set_source_rgba (cr, 0.3, 0.3, 0.3, 0.75); |
176 | + cairo_fill_preserve (cr); |
177 | + |
178 | + cairo_set_source_rgba (cr, 0.3, 0.3, 0.3, 1.0); |
179 | + cairo_stroke (cr); |
180 | + |
181 | + cairo_restore (cr); |
182 | +} |
183 | + |
184 | /* Draw a rounded rectangle. */ |
185 | static void |
186 | os_cairo_draw_rounded_rect (cairo_t *cr, |
187 | @@ -189,6 +218,7 @@ |
188 | priv = thumb->priv; |
189 | |
190 | priv->can_rgba = FALSE; |
191 | + priv->detached = FALSE; |
192 | |
193 | priv->source_id = 0; |
194 | priv->animation = os_animation_new (RATE_FADE_OUT, DURATION_FADE_OUT, |
195 | @@ -350,6 +380,7 @@ |
196 | { |
197 | GtkAllocation allocation; |
198 | GtkStateType state_type_down, state_type_up; |
199 | + GtkStyle *style; |
200 | OsThumb *thumb; |
201 | OsThumbPrivate *priv; |
202 | cairo_pattern_t *pat; |
203 | @@ -357,6 +388,8 @@ |
204 | gint x, y, width, height; |
205 | gint radius; |
206 | |
207 | + style = gtk_widget_get_style (widget); |
208 | + |
209 | thumb = OS_THUMB (widget); |
210 | priv = thumb->priv; |
211 | |
212 | @@ -369,10 +402,12 @@ |
213 | y = 0; |
214 | width = allocation.width; |
215 | height = allocation.height; |
216 | - radius = priv->can_rgba ? 18 : 0; |
217 | + radius = priv->can_rgba ? THUMB_RADIUS : 0; |
218 | |
219 | cr = gdk_cairo_create (gtk_widget_get_window (widget)); |
220 | |
221 | + cairo_save (cr); |
222 | + |
223 | cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE); |
224 | cairo_set_source_rgba (cr, 0, 0, 0, 0); |
225 | cairo_paint (cr); |
226 | @@ -434,117 +469,101 @@ |
227 | } |
228 | cairo_set_source (cr, pat); |
229 | cairo_pattern_destroy (pat); |
230 | - cairo_fill_preserve (cr); |
231 | |
232 | - cairo_set_source_rgba (cr, 0.6, 0.6, 0.6, 1.0); |
233 | |
234 | if (priv->motion_notify_event) |
235 | { |
236 | + cairo_fill_preserve (cr); |
237 | cairo_set_source_rgba (cr, 0.5, 0.5, 0.5, 0.2); |
238 | - cairo_fill_preserve (cr); |
239 | - cairo_set_source_rgba (cr, 0.5, 0.5, 0.5, 1.0); |
240 | - cairo_stroke (cr); |
241 | - |
242 | - os_cairo_draw_rounded_rect (cr, x + 1, y + 1, width - 2, height - 2, radius + 1); |
243 | - cairo_set_source_rgba (cr, 1, 1, 1, 0.5); |
244 | - cairo_stroke (cr); |
245 | - } |
246 | - else |
247 | - { |
248 | - cairo_stroke (cr); |
249 | - |
250 | - os_cairo_draw_rounded_rect (cr, x + 1, y + 1, width - 2, height - 2, radius + 1); |
251 | - cairo_set_source_rgba (cr, 1, 1, 1, 0.5); |
252 | - cairo_stroke (cr); |
253 | - } |
254 | - |
255 | - if (priv->orientation == GTK_ORIENTATION_VERTICAL) |
256 | - { |
257 | - cairo_move_to (cr, x + 0.5, y - 1 + height / 2); |
258 | - cairo_line_to (cr, width - 0.5, y - 1 + height / 2); |
259 | - cairo_set_source_rgba (cr, 0.6, 0.6, 0.6, 0.4); |
260 | - cairo_stroke (cr); |
261 | - |
262 | - cairo_move_to (cr, x + 0.5, y + height / 2); |
263 | - cairo_line_to (cr, width - 0.5, y + height / 2); |
264 | - cairo_set_source_rgba (cr, 1, 1, 1, 0.5); |
265 | - cairo_stroke (cr); |
266 | - } |
267 | - else |
268 | - { |
269 | - cairo_move_to (cr, x - 1 + width / 2, y + 0.5); |
270 | - cairo_line_to (cr, x - 1 + width / 2, height - 0.5); |
271 | - cairo_set_source_rgba (cr, 0.6, 0.6, 0.6, 0.4); |
272 | - cairo_stroke (cr); |
273 | - |
274 | - cairo_move_to (cr, x + width / 2, y + 0.5); |
275 | - cairo_line_to (cr, x + width / 2, height - 0.5); |
276 | - cairo_set_source_rgba (cr, 1, 1, 1, 0.5); |
277 | - cairo_stroke (cr); |
278 | - } |
279 | - |
280 | - cairo_restore (cr); |
281 | - |
282 | - if (priv->orientation == GTK_ORIENTATION_VERTICAL) |
283 | - { |
284 | - gtk_paint_arrow (gtk_widget_get_style (widget), |
285 | - gtk_widget_get_window (widget), |
286 | - state_type_up, |
287 | - GTK_SHADOW_IN, |
288 | - NULL, |
289 | - widget, |
290 | - "arrow", |
291 | - GTK_ARROW_UP, |
292 | - FALSE, |
293 | - 4, |
294 | - 4, |
295 | - width - 8, |
296 | - width - 8); |
297 | - |
298 | - gtk_paint_arrow (gtk_widget_get_style (widget), |
299 | - gtk_widget_get_window (widget), |
300 | - state_type_down, |
301 | - GTK_SHADOW_NONE, |
302 | - NULL, |
303 | - widget, |
304 | - "arrow", |
305 | - GTK_ARROW_DOWN, |
306 | - FALSE, |
307 | - 4, |
308 | - height - (width - 8) - 4, |
309 | - width - 8, |
310 | - width - 8); |
311 | - } |
312 | - else |
313 | - { |
314 | - gtk_paint_arrow (gtk_widget_get_style (widget), |
315 | - gtk_widget_get_window (widget), |
316 | - state_type_up, |
317 | - GTK_SHADOW_IN, |
318 | - NULL, |
319 | - widget, |
320 | - "arrow", |
321 | - GTK_ARROW_LEFT, |
322 | - FALSE, |
323 | - 4, |
324 | - 4, |
325 | - height - 8, |
326 | - height - 8); |
327 | - |
328 | - gtk_paint_arrow (gtk_widget_get_style (widget), |
329 | - gtk_widget_get_window (widget), |
330 | - state_type_down, |
331 | - GTK_SHADOW_NONE, |
332 | - NULL, |
333 | - widget, |
334 | - "arrow", |
335 | - GTK_ARROW_RIGHT, |
336 | - FALSE, |
337 | - width - (height - 8) - 4, |
338 | - 4, |
339 | - height - 8, |
340 | - height - 8); |
341 | - } |
342 | + cairo_fill (cr); |
343 | + } |
344 | + else |
345 | + cairo_fill (cr); |
346 | + |
347 | + cairo_set_line_width (cr, 2.0); |
348 | + os_cairo_draw_rounded_rect (cr, x + 0.5, y + 0.5, width - 1, height - 1, radius - 1); |
349 | + if (!priv->detached) |
350 | + cairo_set_source_rgba (cr, style->bg[GTK_STATE_SELECTED].red/65535.0, |
351 | + style->bg[GTK_STATE_SELECTED].green/65535.0, |
352 | + style->bg[GTK_STATE_SELECTED].blue/65535.0, 1.0f); |
353 | + else |
354 | + cairo_set_source_rgba (cr, 0.6, 0.6, 0.6, 1.0f); |
355 | + cairo_stroke (cr); |
356 | + |
357 | + cairo_set_line_width (cr, 1.0); |
358 | + os_cairo_draw_rounded_rect (cr, x + 1, y + 1, width - 2, height - 2, radius - 1); |
359 | + cairo_set_source_rgba (cr, 0.1, 0.1, 0.1, 0.1); |
360 | + cairo_stroke (cr); |
361 | + |
362 | + os_cairo_draw_rounded_rect (cr, x + 2, y + 2, width - 4, height - 4, radius - 3); |
363 | + cairo_set_source_rgba (cr, 0.6, 0.6, 0.6, 0.5); |
364 | + cairo_stroke (cr); |
365 | + |
366 | + os_cairo_draw_rounded_rect (cr, x + 3, y + 3, width - 6, height - 6, radius - 4); |
367 | + cairo_set_source_rgba (cr, 1, 1, 1, 0.2); |
368 | + cairo_stroke (cr); |
369 | + |
370 | + if (priv->orientation == GTK_ORIENTATION_VERTICAL) |
371 | + { |
372 | + cairo_move_to (cr, x + 2.5, y - 1 + height / 2); |
373 | + cairo_line_to (cr, width - 2.5, y - 1 + height / 2); |
374 | + cairo_set_source_rgba (cr, 0.6, 0.6, 0.6, 0.4); |
375 | + cairo_stroke (cr); |
376 | + |
377 | + cairo_move_to (cr, x + 2.5, y + height / 2); |
378 | + cairo_line_to (cr, width - 2.5, y + height / 2); |
379 | + cairo_set_source_rgba (cr, 1, 1, 1, 0.5); |
380 | + cairo_stroke (cr); |
381 | + } |
382 | + else |
383 | + { |
384 | + cairo_move_to (cr, x - 1 + width / 2, y + 2.5); |
385 | + cairo_line_to (cr, x - 1 + width / 2, height - 2.5); |
386 | + cairo_set_source_rgba (cr, 0.6, 0.6, 0.6, 0.4); |
387 | + cairo_stroke (cr); |
388 | + |
389 | + cairo_move_to (cr, x + width / 2, y + 2.5); |
390 | + cairo_line_to (cr, x + width / 2, height - 2.5); |
391 | + cairo_set_source_rgba (cr, 1, 1, 1, 0.5); |
392 | + cairo_stroke (cr); |
393 | + } |
394 | + |
395 | + if (priv->orientation == GTK_ORIENTATION_VERTICAL) |
396 | + { |
397 | + /* direction UP. */ |
398 | + cairo_save (cr); |
399 | + cairo_translate (cr, 8.5, 8.5); |
400 | + cairo_rotate (cr, G_PI); |
401 | + os_cairo_draw_arrow (cr, 0.5, 0, 4, 3); |
402 | + cairo_restore (cr); |
403 | + |
404 | + /* direction DOWN. */ |
405 | + cairo_save (cr); |
406 | + cairo_translate (cr, 8.5, height - 8.5); |
407 | + cairo_rotate (cr, 0); |
408 | + os_cairo_draw_arrow (cr, -0.5, 0, 4, 3); |
409 | + cairo_restore (cr); |
410 | + } |
411 | + else |
412 | + { |
413 | + /* direction LEFT. */ |
414 | + cairo_save (cr); |
415 | + cairo_translate (cr, 8.5, 8.5); |
416 | + cairo_rotate (cr, G_PI * 0.5); |
417 | + os_cairo_draw_arrow (cr, -0.5, 0, 4, 3); |
418 | + cairo_restore (cr); |
419 | + |
420 | + /* direction RIGHT. */ |
421 | + cairo_save (cr); |
422 | + cairo_translate (cr, width - 8.5, 8.5); |
423 | + cairo_rotate (cr, G_PI * 1.5); |
424 | + os_cairo_draw_arrow (cr, 0.5, 0, 4, 3); |
425 | + cairo_restore (cr); |
426 | + } |
427 | + |
428 | + cairo_restore (cr); |
429 | + |
430 | + cairo_restore (cr); |
431 | |
432 | cairo_destroy (cr); |
433 | |
434 | @@ -802,3 +821,27 @@ |
435 | { |
436 | return g_object_new (OS_TYPE_THUMB, "orientation", orientation, NULL); |
437 | } |
438 | + |
439 | +/** |
440 | + * os_thumb_set_detached: |
441 | + * @thumb: a #OsThumb |
442 | + * @detached: a gboolean |
443 | + * |
444 | + * Sets the thumb to be detached. |
445 | + **/ |
446 | +void |
447 | +os_thumb_set_detached (OsThumb *thumb, |
448 | + gboolean detached) |
449 | +{ |
450 | + OsThumbPrivate *priv; |
451 | + |
452 | + g_return_if_fail (OS_THUMB (thumb)); |
453 | + |
454 | + priv = thumb->priv; |
455 | + |
456 | + if (priv->detached != detached) |
457 | + { |
458 | + priv->detached = detached; |
459 | + gtk_widget_queue_draw (GTK_WIDGET (thumb)); |
460 | + } |
461 | +} |
Love the video!
review approve