Merge lp:~cimi/overlay-scrollbar/fitt-law into lp:overlay-scrollbar

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
Reviewer Review Type Date Requested Status
Ted Gould (community) Approve
Review via email: mp+60301@code.launchpad.net
To post a comment you must log in.
lp:~cimi/overlay-scrollbar/fitt-law updated
231. By Andrea Cimitan

Don't check for detached state on drag. Indentation fixes

Revision history for this message
Ted Gould (ted) wrote :

Love the video!

  review approve

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'os/os-private.h'
--- os/os-private.h 2011-04-05 16:21:15 +0000
+++ os/os-private.h 2011-05-08 14:08:31 +0000
@@ -31,8 +31,8 @@
31#endif /* __GNUC__ */31#endif /* __GNUC__ */
3232
33/* Default size of the thumb in pixels. */33/* Default size of the thumb in pixels. */
34#define DEFAULT_THUMB_WIDTH 1534#define DEFAULT_THUMB_WIDTH 17
35#define DEFAULT_THUMB_HEIGHT 6735#define DEFAULT_THUMB_HEIGHT 69
3636
37G_BEGIN_DECLS37G_BEGIN_DECLS
3838
@@ -167,9 +167,12 @@
167 GtkWindowClass parent_class;167 GtkWindowClass parent_class;
168};168};
169169
170GType os_thumb_get_type (void) G_GNUC_CONST;170GType os_thumb_get_type (void) G_GNUC_CONST;
171171
172GtkWidget* os_thumb_new (GtkOrientation orientation);172GtkWidget* os_thumb_new (GtkOrientation orientation);
173
174void os_thumb_set_detached (OsThumb *thumb,
175 gboolean detached);
173176
174/* os-pager.c */177/* os-pager.c */
175178
176179
=== modified file 'os/os-scrollbar.c'
--- os/os-scrollbar.c 2011-04-26 22:33:59 +0000
+++ os/os-scrollbar.c 2011-05-08 14:08:31 +0000
@@ -32,6 +32,9 @@
32/* Default size of the pager in pixels. */32/* Default size of the pager in pixels. */
33#define DEFAULT_PAGER_WIDTH 333#define DEFAULT_PAGER_WIDTH 3
3434
35/* Default thumb allocation shift in pixels. */
36#define THUMB_ALLOCATION_SHIFT -3
37
35/* Width of the proximity effect in pixels. */38/* Width of the proximity effect in pixels. */
36#define PROXIMITY_WIDTH 3039#define PROXIMITY_WIDTH 30
3740
@@ -539,7 +542,7 @@
539 (x - 1 + priv->slider.width) >= screen_width))542 (x - 1 + priv->slider.width) >= screen_width))
540 {543 {
541 priv->internal = TRUE;544 priv->internal = TRUE;
542 return x - DEFAULT_PAGER_WIDTH - priv->slider.width;545 return MAX (x - priv->slider.width, screen_width - priv->slider.width);
543 }546 }
544547
545 if (priv->orientation == GTK_ORIENTATION_VERTICAL)548 if (priv->orientation == GTK_ORIENTATION_VERTICAL)
@@ -573,7 +576,7 @@
573 (y - 1 + priv->slider.height) >= screen_height))576 (y - 1 + priv->slider.height) >= screen_height))
574 {577 {
575 priv->internal = TRUE;578 priv->internal = TRUE;
576 return y - DEFAULT_PAGER_WIDTH - priv->slider.height;579 return MAX (y - priv->slider.height, screen_height - priv->slider.height);
577 }580 }
578581
579 if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)582 if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
@@ -1162,6 +1165,35 @@
1162 if (!priv->motion_notify_event && !priv->enter_notify_event)1165 if (!priv->motion_notify_event && !priv->enter_notify_event)
1163 gtk_widget_hide (GTK_WIDGET (priv->thumb));1166 gtk_widget_hide (GTK_WIDGET (priv->thumb));
11641167
1168 if (gtk_widget_get_mapped (GTK_WIDGET (priv->thumb)))
1169 {
1170 /* if we're dragging the thumb, it can't be detached. */
1171 if (priv->motion_notify_event)
1172 os_thumb_set_detached (OS_THUMB (priv->thumb), FALSE);
1173 else
1174 {
1175 gint x_pos, y_pos;
1176 gdk_window_get_origin (gtk_widget_get_window (GTK_WIDGET (priv->thumb)), &x_pos, &y_pos);
1177
1178 if (priv->orientation == GTK_ORIENTATION_VERTICAL)
1179 {
1180 if ((priv->win_y + priv->overlay.y > y_pos + priv->slider.height) ||
1181 (priv->win_y + priv->overlay.y + priv->overlay.height < y_pos))
1182 os_thumb_set_detached (OS_THUMB (priv->thumb), TRUE);
1183 else
1184 os_thumb_set_detached (OS_THUMB (priv->thumb), FALSE);
1185 }
1186 else
1187 {
1188 if ((priv->win_x + priv->overlay.x > x_pos + priv->slider.width) ||
1189 (priv->win_x + priv->overlay.x + priv->overlay.width < x_pos))
1190 os_thumb_set_detached (OS_THUMB (priv->thumb), TRUE);
1191 else
1192 os_thumb_set_detached (OS_THUMB (priv->thumb), FALSE);
1193 }
1194 }
1195 }
1196
1165 pager_move (scrollbar);1197 pager_move (scrollbar);
1166}1198}
11671199
@@ -1399,6 +1431,7 @@
1399 os_scrollbar_move_thumb (scrollbar, priv->win_x, priv->win_y + priv->slider.y);1431 os_scrollbar_move_thumb (scrollbar, priv->win_x, priv->win_y + priv->slider.y);
1400 }1432 }
14011433
1434 os_thumb_set_detached (OS_THUMB (priv->thumb), FALSE);
1402 gtk_widget_show (GTK_WIDGET (priv->thumb));1435 gtk_widget_show (GTK_WIDGET (priv->thumb));
1403 }1436 }
1404 else1437 else
@@ -1438,6 +1471,7 @@
1438 os_scrollbar_move_thumb (scrollbar, priv->win_x + priv->slider.x, priv->win_y);1471 os_scrollbar_move_thumb (scrollbar, priv->win_x + priv->slider.x, priv->win_y);
1439 }1472 }
14401473
1474 os_thumb_set_detached (OS_THUMB (priv->thumb), FALSE);
1441 gtk_widget_show (GTK_WIDGET (priv->thumb));1475 gtk_widget_show (GTK_WIDGET (priv->thumb));
1442 }1476 }
1443 else1477 else
@@ -1771,7 +1805,7 @@
1771 priv->slider.width = DEFAULT_THUMB_WIDTH;1805 priv->slider.width = DEFAULT_THUMB_WIDTH;
1772 priv->slider.height = DEFAULT_THUMB_HEIGHT;1806 priv->slider.height = DEFAULT_THUMB_HEIGHT;
1773 priv->overlay_all.x = allocation->x - DEFAULT_PAGER_WIDTH;1807 priv->overlay_all.x = allocation->x - DEFAULT_PAGER_WIDTH;
1774 priv->thumb_all.x = allocation->x;1808 priv->thumb_all.x = allocation->x + THUMB_ALLOCATION_SHIFT;
17751809
1776 rect.x = priv->overlay_all.x;1810 rect.x = priv->overlay_all.x;
1777 rect.y = priv->overlay_all.y;1811 rect.y = priv->overlay_all.y;
@@ -1785,7 +1819,7 @@
1785 priv->slider.width = DEFAULT_THUMB_HEIGHT;1819 priv->slider.width = DEFAULT_THUMB_HEIGHT;
1786 priv->slider.height = DEFAULT_THUMB_WIDTH;1820 priv->slider.height = DEFAULT_THUMB_WIDTH;
1787 priv->overlay_all.y = allocation->y - DEFAULT_PAGER_WIDTH ;1821 priv->overlay_all.y = allocation->y - DEFAULT_PAGER_WIDTH ;
1788 priv->thumb_all.y = allocation->y;1822 priv->thumb_all.y = allocation->y + THUMB_ALLOCATION_SHIFT;
17891823
1790 rect.x = priv->overlay_all.x;1824 rect.x = priv->overlay_all.x;
1791 rect.y = priv->overlay_all.y;1825 rect.y = priv->overlay_all.y;
17921826
=== modified file 'os/os-thumb.c'
--- os/os-thumb.c 2011-04-20 14:51:48 +0000
+++ os/os-thumb.c 2011-05-08 14:08:31 +0000
@@ -40,6 +40,9 @@
40/* Number of tolerance pixels. */40/* Number of tolerance pixels. */
41#define TOLERANCE_PIXELS 341#define TOLERANCE_PIXELS 3
4242
43/* Thumb radius in pixels (higher values are automatically clamped). */
44#define THUMB_RADIUS 9
45
43struct _OsThumbPrivate {46struct _OsThumbPrivate {
44 GtkOrientation orientation;47 GtkOrientation orientation;
45 GtkWidget *grabbed_widget;48 GtkWidget *grabbed_widget;
@@ -48,6 +51,7 @@
48 gboolean motion_notify_event;51 gboolean motion_notify_event;
49 gboolean can_rgba;52 gboolean can_rgba;
50 gboolean use_tolerance;53 gboolean use_tolerance;
54 gboolean detached;
51 gint pointer_x;55 gint pointer_x;
52 gint pointer_y;56 gint pointer_y;
53 guint32 source_id;57 guint32 source_id;
@@ -79,6 +83,31 @@
7983
80/* Private functions. */84/* Private functions. */
8185
86/* Draw an arror. */
87static void
88os_cairo_draw_arrow (cairo_t *cr,
89 gdouble x,
90 gdouble y,
91 gdouble width,
92 gdouble height)
93{
94 cairo_save (cr);
95
96 cairo_translate (cr, x, y);
97 cairo_move_to (cr, -width / 2, -height / 2);
98 cairo_line_to (cr, 0, height / 2);
99 cairo_line_to (cr, width / 2, -height / 2);
100 cairo_close_path (cr);
101
102 cairo_set_source_rgba (cr, 0.3, 0.3, 0.3, 0.75);
103 cairo_fill_preserve (cr);
104
105 cairo_set_source_rgba (cr, 0.3, 0.3, 0.3, 1.0);
106 cairo_stroke (cr);
107
108 cairo_restore (cr);
109}
110
82/* Draw a rounded rectangle. */111/* Draw a rounded rectangle. */
83static void112static void
84os_cairo_draw_rounded_rect (cairo_t *cr,113os_cairo_draw_rounded_rect (cairo_t *cr,
@@ -189,6 +218,7 @@
189 priv = thumb->priv;218 priv = thumb->priv;
190219
191 priv->can_rgba = FALSE;220 priv->can_rgba = FALSE;
221 priv->detached = FALSE;
192222
193 priv->source_id = 0;223 priv->source_id = 0;
194 priv->animation = os_animation_new (RATE_FADE_OUT, DURATION_FADE_OUT,224 priv->animation = os_animation_new (RATE_FADE_OUT, DURATION_FADE_OUT,
@@ -350,6 +380,7 @@
350{380{
351 GtkAllocation allocation;381 GtkAllocation allocation;
352 GtkStateType state_type_down, state_type_up;382 GtkStateType state_type_down, state_type_up;
383 GtkStyle *style;
353 OsThumb *thumb;384 OsThumb *thumb;
354 OsThumbPrivate *priv;385 OsThumbPrivate *priv;
355 cairo_pattern_t *pat;386 cairo_pattern_t *pat;
@@ -357,6 +388,8 @@
357 gint x, y, width, height;388 gint x, y, width, height;
358 gint radius;389 gint radius;
359390
391 style = gtk_widget_get_style (widget);
392
360 thumb = OS_THUMB (widget);393 thumb = OS_THUMB (widget);
361 priv = thumb->priv;394 priv = thumb->priv;
362395
@@ -369,10 +402,12 @@
369 y = 0;402 y = 0;
370 width = allocation.width;403 width = allocation.width;
371 height = allocation.height;404 height = allocation.height;
372 radius = priv->can_rgba ? 18 : 0;405 radius = priv->can_rgba ? THUMB_RADIUS : 0;
373406
374 cr = gdk_cairo_create (gtk_widget_get_window (widget));407 cr = gdk_cairo_create (gtk_widget_get_window (widget));
375408
409 cairo_save (cr);
410
376 cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);411 cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
377 cairo_set_source_rgba (cr, 0, 0, 0, 0);412 cairo_set_source_rgba (cr, 0, 0, 0, 0);
378 cairo_paint (cr);413 cairo_paint (cr);
@@ -434,117 +469,101 @@
434 }469 }
435 cairo_set_source (cr, pat);470 cairo_set_source (cr, pat);
436 cairo_pattern_destroy (pat);471 cairo_pattern_destroy (pat);
437 cairo_fill_preserve (cr);
438472
439 cairo_set_source_rgba (cr, 0.6, 0.6, 0.6, 1.0);
440473
441 if (priv->motion_notify_event)474 if (priv->motion_notify_event)
442 {475 {
476 cairo_fill_preserve (cr);
443 cairo_set_source_rgba (cr, 0.5, 0.5, 0.5, 0.2);477 cairo_set_source_rgba (cr, 0.5, 0.5, 0.5, 0.2);
444 cairo_fill_preserve (cr);478 cairo_fill (cr);
445 cairo_set_source_rgba (cr, 0.5, 0.5, 0.5, 1.0);479 }
446 cairo_stroke (cr);480 else
447481 cairo_fill (cr);
448 os_cairo_draw_rounded_rect (cr, x + 1, y + 1, width - 2, height - 2, radius + 1);482
449 cairo_set_source_rgba (cr, 1, 1, 1, 0.5);483 cairo_set_line_width (cr, 2.0);
450 cairo_stroke (cr);484 os_cairo_draw_rounded_rect (cr, x + 0.5, y + 0.5, width - 1, height - 1, radius - 1);
451 }485 if (!priv->detached)
452 else486 cairo_set_source_rgba (cr, style->bg[GTK_STATE_SELECTED].red/65535.0,
453 {487 style->bg[GTK_STATE_SELECTED].green/65535.0,
454 cairo_stroke (cr);488 style->bg[GTK_STATE_SELECTED].blue/65535.0, 1.0f);
455489 else
456 os_cairo_draw_rounded_rect (cr, x + 1, y + 1, width - 2, height - 2, radius + 1);490 cairo_set_source_rgba (cr, 0.6, 0.6, 0.6, 1.0f);
457 cairo_set_source_rgba (cr, 1, 1, 1, 0.5);491 cairo_stroke (cr);
458 cairo_stroke (cr);492
459 }493 cairo_set_line_width (cr, 1.0);
460494 os_cairo_draw_rounded_rect (cr, x + 1, y + 1, width - 2, height - 2, radius - 1);
461 if (priv->orientation == GTK_ORIENTATION_VERTICAL)495 cairo_set_source_rgba (cr, 0.1, 0.1, 0.1, 0.1);
462 {496 cairo_stroke (cr);
463 cairo_move_to (cr, x + 0.5, y - 1 + height / 2);497
464 cairo_line_to (cr, width - 0.5, y - 1 + height / 2);498 os_cairo_draw_rounded_rect (cr, x + 2, y + 2, width - 4, height - 4, radius - 3);
465 cairo_set_source_rgba (cr, 0.6, 0.6, 0.6, 0.4);499 cairo_set_source_rgba (cr, 0.6, 0.6, 0.6, 0.5);
466 cairo_stroke (cr);500 cairo_stroke (cr);
467501
468 cairo_move_to (cr, x + 0.5, y + height / 2);502 os_cairo_draw_rounded_rect (cr, x + 3, y + 3, width - 6, height - 6, radius - 4);
469 cairo_line_to (cr, width - 0.5, y + height / 2);503 cairo_set_source_rgba (cr, 1, 1, 1, 0.2);
470 cairo_set_source_rgba (cr, 1, 1, 1, 0.5);504 cairo_stroke (cr);
471 cairo_stroke (cr);505
472 }506 if (priv->orientation == GTK_ORIENTATION_VERTICAL)
473 else507 {
474 {508 cairo_move_to (cr, x + 2.5, y - 1 + height / 2);
475 cairo_move_to (cr, x - 1 + width / 2, y + 0.5);509 cairo_line_to (cr, width - 2.5, y - 1 + height / 2);
476 cairo_line_to (cr, x - 1 + width / 2, height - 0.5);510 cairo_set_source_rgba (cr, 0.6, 0.6, 0.6, 0.4);
477 cairo_set_source_rgba (cr, 0.6, 0.6, 0.6, 0.4);511 cairo_stroke (cr);
478 cairo_stroke (cr);512
479513 cairo_move_to (cr, x + 2.5, y + height / 2);
480 cairo_move_to (cr, x + width / 2, y + 0.5);514 cairo_line_to (cr, width - 2.5, y + height / 2);
481 cairo_line_to (cr, x + width / 2, height - 0.5);515 cairo_set_source_rgba (cr, 1, 1, 1, 0.5);
482 cairo_set_source_rgba (cr, 1, 1, 1, 0.5);516 cairo_stroke (cr);
483 cairo_stroke (cr);517 }
484 }518 else
485519 {
486 cairo_restore (cr);520 cairo_move_to (cr, x - 1 + width / 2, y + 2.5);
487521 cairo_line_to (cr, x - 1 + width / 2, height - 2.5);
488 if (priv->orientation == GTK_ORIENTATION_VERTICAL)522 cairo_set_source_rgba (cr, 0.6, 0.6, 0.6, 0.4);
489 {523 cairo_stroke (cr);
490 gtk_paint_arrow (gtk_widget_get_style (widget),524
491 gtk_widget_get_window (widget),525 cairo_move_to (cr, x + width / 2, y + 2.5);
492 state_type_up,526 cairo_line_to (cr, x + width / 2, height - 2.5);
493 GTK_SHADOW_IN,527 cairo_set_source_rgba (cr, 1, 1, 1, 0.5);
494 NULL,528 cairo_stroke (cr);
495 widget,529 }
496 "arrow",530
497 GTK_ARROW_UP,531 if (priv->orientation == GTK_ORIENTATION_VERTICAL)
498 FALSE,532 {
499 4,533 /* direction UP. */
500 4,534 cairo_save (cr);
501 width - 8,535 cairo_translate (cr, 8.5, 8.5);
502 width - 8);536 cairo_rotate (cr, G_PI);
503537 os_cairo_draw_arrow (cr, 0.5, 0, 4, 3);
504 gtk_paint_arrow (gtk_widget_get_style (widget),538 cairo_restore (cr);
505 gtk_widget_get_window (widget),539
506 state_type_down,540 /* direction DOWN. */
507 GTK_SHADOW_NONE,541 cairo_save (cr);
508 NULL,542 cairo_translate (cr, 8.5, height - 8.5);
509 widget,543 cairo_rotate (cr, 0);
510 "arrow",544 os_cairo_draw_arrow (cr, -0.5, 0, 4, 3);
511 GTK_ARROW_DOWN,545 cairo_restore (cr);
512 FALSE,546 }
513 4,547 else
514 height - (width - 8) - 4,548 {
515 width - 8,549 /* direction LEFT. */
516 width - 8);550 cairo_save (cr);
517 }551 cairo_translate (cr, 8.5, 8.5);
518 else552 cairo_rotate (cr, G_PI * 0.5);
519 {553 os_cairo_draw_arrow (cr, -0.5, 0, 4, 3);
520 gtk_paint_arrow (gtk_widget_get_style (widget),554 cairo_restore (cr);
521 gtk_widget_get_window (widget),555
522 state_type_up,556 /* direction RIGHT. */
523 GTK_SHADOW_IN,557 cairo_save (cr);
524 NULL,558 cairo_translate (cr, width - 8.5, 8.5);
525 widget,559 cairo_rotate (cr, G_PI * 1.5);
526 "arrow",560 os_cairo_draw_arrow (cr, 0.5, 0, 4, 3);
527 GTK_ARROW_LEFT,561 cairo_restore (cr);
528 FALSE,562 }
529 4,563
530 4,564 cairo_restore (cr);
531 height - 8,565
532 height - 8);566 cairo_restore (cr);
533
534 gtk_paint_arrow (gtk_widget_get_style (widget),
535 gtk_widget_get_window (widget),
536 state_type_down,
537 GTK_SHADOW_NONE,
538 NULL,
539 widget,
540 "arrow",
541 GTK_ARROW_RIGHT,
542 FALSE,
543 width - (height - 8) - 4,
544 4,
545 height - 8,
546 height - 8);
547 }
548567
549 cairo_destroy (cr);568 cairo_destroy (cr);
550569
@@ -802,3 +821,27 @@
802{821{
803 return g_object_new (OS_TYPE_THUMB, "orientation", orientation, NULL);822 return g_object_new (OS_TYPE_THUMB, "orientation", orientation, NULL);
804}823}
824
825/**
826 * os_thumb_set_detached:
827 * @thumb: a #OsThumb
828 * @detached: a gboolean
829 *
830 * Sets the thumb to be detached.
831 **/
832void
833os_thumb_set_detached (OsThumb *thumb,
834 gboolean detached)
835{
836 OsThumbPrivate *priv;
837
838 g_return_if_fail (OS_THUMB (thumb));
839
840 priv = thumb->priv;
841
842 if (priv->detached != detached)
843 {
844 priv->detached = detached;
845 gtk_widget_queue_draw (GTK_WIDGET (thumb));
846 }
847}

Subscribers

People subscribed via source and target branches