62
72
tab3_left = Icons.get_icon ("tab3_left.png");
63
73
tab3_right = Icons.get_icon ("tab3_right.png");
65
bar_background = Icons.get_icon ("tabbar_background.png");
67
next_tab = (!) Icons.get_icon ("next_tab.png");
68
to_previous_tab = (!) Icons.get_icon ("previous_tab.png");
70
if (is_null (next_tab)) {
71
warning ("Tab icon is null");
75
next_tab = Icons.get_icon ("next_tab.png");
76
to_previous_tab = Icons.get_icon ("previous_tab.png");
78
progress = Icons.get_icon ("progress_wheel.png");
79
tab_bar_background = Icons.get_icon ("tab_bar_background.png");
75
82
public void motion (double x, double y) {
76
is_over_close (x, y, out over, out over_close);
83
over_close (x, y, out over, out over_close_tab);
79
private void is_over_close (double x, double y, out int over, out int over_close) {
86
private void over_close (double x, double y, out int over, out int over_close_tab) {
81
88
double offset = 19;
91
return_if_fail (tab3_right != null);
93
edge = ((!)tab3_right).get_width () * scale;
83
95
if (x < 19 && has_scroll ()) {
96
over_close_tab = NO_TAB;
85
97
over = PREVIOUS_TAB;
101
if (has_scroll () && has_progress_wheel ()) {
102
if (x > width - 19) {
103
over_close_tab = NO_TAB;
104
over = PROGRESS_WHEEL;
105
} else if (x > width - 2 * 19) {
106
over_close_tab = NO_TAB;
109
} else if (!has_scroll () && has_progress_wheel ()) {
110
if (x > width - 19) {
111
over_close_tab = NO_TAB;
112
over = PROGRESS_WHEEL;
114
} else if (has_scroll () && !has_progress_wheel ()) {
115
if (x > width - 19) {
116
over_close_tab = NO_TAB;
89
121
foreach (Tab t in tabs) {
91
122
if (i < first_tab) {
96
if (offset + t.get_width () + 3 > width && has_scroll ()) {
102
if (offset < x < offset + t.get_width ()) {
127
if (offset < x < offset + t.get_width () + edge) {
105
if (height - 18 < y < height - 5 && x > offset + t.get_width () - 16) {
130
if (height - 18 < y < height - 5 && x > offset + t.get_width () - 19) {
133
over_close_tab = NO_TAB;
114
offset += t.get_width () + 3;
139
offset += t.get_width () + ((!)tab1_right).get_width () * scale;
143
over_close_tab = NO_TAB;
431
538
if (MenuTab.suppress_event) {
539
warn_if_test ("Event supressed");
435
543
this.width = width;
436
544
this.height = height;
545
this.scale = height / 117.0;
438
is_over_close (x, y, out over, out close);
547
over_close (x, y, out over, out close);
440
if (over_close >= 0 && over == selected) {
441
close_tab (over_close);
549
if (over_close_tab >= 0 && over == selected) {
550
close_tab (over_close_tab);
443
552
select_tab (over);
447
public void add_tab (FontDisplay display_item, double tab_width = -1, bool always_open = false) {
556
public void add_tab (FontDisplay display_item, bool signal_selected = true) {
557
double tab_width = -1;
558
bool always_open = false;
448
559
int s = (tabs.length () == 0) ? 0 : selected + 1;
561
if (MenuTab.suppress_event) {
562
warn_if_test ("Event supressed");
450
566
if (tab_width < 0) {
451
567
tab_width = 9 * display_item.get_label ().char_count ();
455
571
tabs.insert (new Tab (display_item, tab_width, always_open), s);
572
select_tab (s, signal_selected);
459
575
/** Returns true if the new item was added to the bar. */
460
public bool add_unique_tab (FontDisplay display_item, double tab_width = -1, bool always_open = false) {
461
bool i = select_tab_name (display_item.get_name ());
576
public bool add_unique_tab (FontDisplay display_item, bool signal_selected = true) {
579
if (MenuTab.suppress_event) {
580
warn_if_test ("Event supressed");
584
i = select_tab_name (display_item.get_name ());
464
add_tab (display_item, tab_width, always_open);
587
add_tab (display_item, signal_selected);
471
594
public void draw (Context cr, int width, int height) {
472
599
this.width = width;
473
600
this.height = height;
601
this.scale = height / 117.0;
603
return_if_fail (to_previous_tab != null);
604
return_if_fail (next_tab != null);
605
return_if_fail (progress != null);
606
return_if_fail (tab_bar_background != null);
476
609
cr.rectangle (0, 0, width, height);
477
610
cr.set_line_width (0);
478
611
cr.set_source_rgba (230/255.0, 229/255.0, 228/255.0, 1);
479
612
cr.fill_preserve ();
483
for (int j = 0; j < width; j++) {
484
cr.set_source_surface ((!) bar_background, j, height - ((!) bar_background).get_height ());
616
cr.scale (scale, scale);
621
for (double i = 0; i < w; i += ((!)tab_bar_background).get_width ()) {
622
cr.set_source_surface ((!) tab_bar_background, i, h - ((!) tab_bar_background).get_height ());
488
626
if (has_scroll ()) {
490
cr.set_source_surface (to_previous_tab, 3, height - to_previous_tab.get_height () - 5);
628
cr.set_source_surface ((!) to_previous_tab, 2 / scale, h - ((!) to_previous_tab).get_height () - 5 / scale);
494
cr.set_source_surface (next_tab, width - 19, height - next_tab.get_height () - 5);
632
next_tab_x = (has_progress_wheel ()) ? w - (2 * 19 + 3) / scale : w - 19 / scale;
633
cr.set_source_surface ((!) next_tab, next_tab_x, h - ((!) next_tab).get_height () - 5 / scale);
638
if (has_progress_wheel ()) {
639
ImageSurface p = (!) progress;
640
Surface s = new Surface.similar (p, p.get_content (), p.get_width (), p.get_height ());
641
Context c = new Context (s);
644
c.rectangle (0, 0, p.get_width (), p.get_height ());
645
c.set_line_width (0);
646
c.set_source_rgba (230/255.0, 229/255.0, 228/255.0, 1);
649
c.translate (p.get_width () / 2.0, p.get_height () / 2.0);
650
c.rotate (wheel_rotation);
651
c.translate (-p.get_width () / 2.0, -p.get_height () / 2.0);
653
c.set_source_surface ((!) progress, 0 ,0);
655
c.translate (p.get_width () / 2.0, p.get_height () / 2.0);
659
progress_y = (has_scroll ()) ? h - ((!) progress).get_height () - 5 / scale : (h - ((!) progress).get_height ()) / 2;
660
cr.set_source_surface (c.get_target (), w - 19 / scale, progress_y);
502
669
private void draw_tabs (Context cr) {
503
670
double close_opacity;
671
double offset = 19 / scale;
674
double tabs_end = width / scale;
675
double h = height / scale;
679
if (has_progress_wheel ()) {
680
tabs_end -= 19 / scale;
684
tabs_end -= 19 / scale;
507
687
return_if_fail (tab3_right != null);
508
688
return_if_fail (tab2_right != null);
524
708
cr.translate (offset, 0);
526
if (offset + t.get_width () + next_tab.get_width () + 3 > width) {
710
tab_width = t.get_width () / scale;
712
if (offset + tab_width + ((!)next_tab).get_width () + 3 / scale > tabs_end) {
531
718
if (i == selected) {
532
for (int j = 0; j < t.get_width (); j++) {
533
cr.set_source_surface ((!) tab3_right, j, (height - ((!)tab1_left).get_height ()) + 1);
719
for (int j = ((!)tab3_left).get_width (); j < tab_width; j++) {
720
cr.set_source_surface ((!) tab3_right, j, tab_y);
536
723
} else if (i == over) {
537
for (int j = 0; j < t.get_width (); j++) {
538
cr.set_source_surface ((!) tab2_right, j, (height - ((!)tab1_left).get_height ()) + 1);
724
for (int j = ((!)tab2_left).get_width (); j < tab_width; j++) {
725
cr.set_source_surface ((!) tab2_right, j, tab_y);
542
for (int j = 0; j < t.get_width (); j++) {
543
cr.set_source_surface ((!) tab1_right, j, (height - ((!)tab1_left).get_height ()) + 1);
729
for (int j = ((!)tab1_left).get_width (); j < tab_width; j++) {
730
cr.set_source_surface ((!) tab1_right, j, tab_y);
549
736
if (t.has_close_button ()) {
550
cr.set_line_width (1);
739
cr.set_line_width (1 / scale);
552
close_opacity = (over_close == i) ? 1 : 0.2;
741
close_opacity = (over_close_tab == i) ? 1 : 0.2;
553
742
cr.set_source_rgba (0, 0, 0, close_opacity);
555
cr.move_to (t.get_width () - 5, height - 14);
556
cr.line_to (t.get_width () - 10, height - 9);
744
cr.move_to (tab_width - 5 / scale, h - 14 / scale);
745
cr.line_to (tab_width - 10 / scale, h - 9 / scale);
558
cr.move_to (t.get_width () - 10, height - 14);
559
cr.line_to (t.get_width () - 5, height - 9);
747
cr.move_to (tab_width - 10 / scale, h - 14 / scale);
748
cr.line_to (tab_width - 5 / scale, h - 9 / scale);
564
754
cr.set_source_rgba (0, 0, 0, 1);
565
cr.set_font_size (14);
566
cr.move_to (8, height - 6);
755
cr.set_font_size (14 / scale);
756
cr.move_to (8 / scale, h - 6 / scale);
567
757
cr.show_text (t.get_display ().get_label ());
571
if (tab1_left != null && tab1_right != null && tab2_left != null && tab2_right != null && tab3_left != null && tab3_right != null) {
573
cr.set_source_surface ((!) tab3_left, 0, (height - ((!)tab1_left).get_height ()) + 1);
576
cr.set_source_surface ((!) tab3_right, t.get_width () - 2, (height - ((!)tab1_left).get_height ()) + 1);
578
} else if (i == over) {
579
cr.set_source_surface ((!) tab2_left, 0, (height - ((!)tab1_left).get_height ()) + 1);
582
cr.set_source_surface ((!) tab2_right, t.get_width () - 2, (height - ((!)tab1_left).get_height ()) + 1);
585
cr.set_source_surface ((!) tab1_left, 0, (height - ((!)tab1_left).get_height ()) + 1);
588
cr.set_source_surface ((!) tab1_right, t.get_width () - 2, (height - ((!)tab1_left).get_height ()) + 1);
762
cr.set_source_surface ((!) tab3_left, 0, tab_y);
765
cr.set_source_surface ((!) tab3_right, tab_width, tab_y);
767
} else if (i == over) {
768
cr.set_source_surface ((!) tab2_left, 0, tab_y);
771
cr.set_source_surface ((!) tab2_right, tab_width, tab_y);
774
cr.set_source_surface ((!) tab1_left, 0, tab_y);
777
cr.set_source_surface ((!) tab1_right, tab_width, tab_y);
595
offset += t.get_width () + 3;
783
offset += tab_width + ((!)tab1_right).get_width ();
600
788
public void add_empty_tab (string name, string label) {
601
789
add_tab (new EmptyTab (name, label));
792
bool has_progress_wheel () {
796
public void set_progress (bool running) {
799
if (unlikely (processing == running)) {
800
warning (@"Progress is already set to $running");
804
processing = running;
807
timer = new TimeoutSource (50);
808
timer.set_callback (() => {
809
wheel_rotation += 0.008 * 2 * Math.PI;
811
if (wheel_rotation > 2 * Math.PI) {
812
wheel_rotation -= 2 * Math.PI;
814
redraw (width - 19, 0, 19, height);
821
public static void start_wheel () {
822
if (!is_null (MainWindow.get_tab_bar ())) {
823
MainWindow.get_tab_bar ().set_progress (true);
828
public static void stop_wheel () {
829
if (!is_null (MainWindow.get_tab_bar ())) {
830
MainWindow.get_tab_bar ().set_progress (false);