~ubuntu-branches/ubuntu/vivid/birdfont/vivid

« back to all changes in this revision

Viewing changes to libbirdfont/TabBar.vala

  • Committer: Package Import Robot
  • Author(s): Hideki Yamane
  • Date: 2014-04-15 20:35:28 UTC
  • mto: This revision was merged to the branch mainline in revision 4.
  • Revision ID: package-import@ubuntu.com-20140415203528-evwq2mnksme9fv0t
Tags: upstream-0.37
ImportĀ upstreamĀ versionĀ 0.37

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
    Copyright (C) 2012 Johan Mattsson
 
2
    Copyright (C) 2012, 2014 Johan Mattsson
3
3
 
4
4
    This library is free software; you can redistribute it and/or modify 
5
5
    it under the terms of the GNU Lesser General Public License as 
26
26
        static const int NO_TAB = -1;
27
27
        static const int NEXT_TAB = -2;
28
28
        static const int PREVIOUS_TAB = -3;
 
29
        static const int PROGRESS_WHEEL = -3;
29
30
 
30
31
        int first_tab = 0;
31
32
        int selected = 0;
32
33
        int over = NO_TAB;
33
 
        int over_close = NO_TAB;
 
34
        int over_close_tab = NO_TAB;
34
35
        
35
36
        public signal void signal_tab_selected (Tab selected_tab);
 
37
        public signal void redraw (int x, int y, int w, int h);
36
38
 
37
39
        Tab? previous_tab = null;
38
40
        Tab? current_tab = null;
46
48
        ImageSurface? tab3_left = null;
47
49
        ImageSurface? tab3_right = null;
48
50
        
49
 
        ImageSurface? bar_background = null;
50
 
        ImageSurface next_tab;
51
 
        ImageSurface to_previous_tab;
52
 
                        
 
51
        ImageSurface? progress = null;
 
52
 
 
53
        ImageSurface? next_tab;
 
54
        ImageSurface? to_previous_tab;
 
55
        
 
56
        ImageSurface? tab_bar_background = null;
 
57
        
 
58
        double scale = 1; // scale images in 320 dpi
 
59
        
 
60
        bool processing = false;
 
61
        double wheel_rotation = 0;
 
62
        
53
63
        public TabBar () {
54
64
                tabs = new List<Tab> ();
55
65
                
62
72
                tab3_left = Icons.get_icon ("tab3_left.png");
63
73
                tab3_right = Icons.get_icon ("tab3_right.png");
64
74
                
65
 
                bar_background = Icons.get_icon ("tabbar_background.png");
66
 
                
67
 
                next_tab = (!) Icons.get_icon ("next_tab.png");
68
 
                to_previous_tab = (!) Icons.get_icon ("previous_tab.png");
69
 
                
70
 
                if (is_null (next_tab)) {
71
 
                        warning ("Tab icon is null");
72
 
                }
 
75
                next_tab = Icons.get_icon ("next_tab.png");
 
76
                to_previous_tab = Icons.get_icon ("previous_tab.png");
 
77
                
 
78
                progress = Icons.get_icon ("progress_wheel.png");
 
79
                tab_bar_background = Icons.get_icon ("tab_bar_background.png");
73
80
        }
74
81
        
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);
77
84
        }
78
85
 
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) {
80
87
                int i = 0;
81
88
                double offset = 19;
 
89
                double edge;
 
90
                
 
91
                return_if_fail (tab3_right != null);
 
92
                
 
93
                edge = ((!)tab3_right).get_width () * scale;
82
94
                
83
95
                if (x < 19 && has_scroll ()) {
84
 
                        over_close = NO_TAB;
 
96
                        over_close_tab = NO_TAB;
85
97
                        over = PREVIOUS_TAB;
86
98
                        return;
87
99
                }
 
100
 
 
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;
 
107
                                over = NEXT_TAB;
 
108
                        }
 
109
                } else if (!has_scroll () && has_progress_wheel ()) {
 
110
                        if (x > width - 19) {
 
111
                                over_close_tab = NO_TAB;
 
112
                                over = PROGRESS_WHEEL;
 
113
                        }
 
114
                } else if (has_scroll () && !has_progress_wheel ()) {
 
115
                        if (x > width - 19) {
 
116
                                over_close_tab = NO_TAB;
 
117
                                over = NEXT_TAB;
 
118
                        }
 
119
                }
88
120
                
89
121
                foreach (Tab t in tabs) {
90
 
                        
91
122
                        if (i < first_tab) {
92
123
                                i++;
93
124
                                continue;
94
125
                        }
95
 
                        
96
 
                        if (offset + t.get_width () + 3 > width && has_scroll ()) {
97
 
                                over_close = NO_TAB;
98
 
                                over = NEXT_TAB;
99
 
                                return;
100
 
                        }
101
 
                                
102
 
                        if (offset < x < offset + t.get_width ()) {
 
126
 
 
127
                        if (offset < x < offset + t.get_width () + edge) {
103
128
                                over = i;
104
129
                                
105
 
                                if (height - 18 < y < height - 5 && x > offset + t.get_width () - 16) {
106
 
                                        over_close =  i;
 
130
                                if (height - 18 < y < height - 5 && x > offset + t.get_width () - 19) {
 
131
                                        over_close_tab =  i;
107
132
                                } else {
108
 
                                        over_close =  NO_TAB;
 
133
                                        over_close_tab =  NO_TAB;
109
134
                                }
110
135
                                
111
136
                                return;
112
137
                        }
113
138
                        
114
 
                        offset += t.get_width () + 3;
 
139
                        offset += t.get_width () + ((!)tab1_right).get_width () * scale;
115
140
                        i++;
116
141
                }
117
142
 
118
 
                over_close = NO_TAB;            
 
143
                over_close_tab = NO_TAB;                
119
144
                over = NO_TAB;
120
145
        }       
121
146
        
125
150
         */
126
151
        public bool select_char (string s) {
127
152
                int i = 0;
 
153
                
 
154
                if (MenuTab.suppress_event) {
 
155
                        warn_if_test ("Event supressed");
 
156
                        return false;
 
157
                }
 
158
                
128
159
                foreach (Tab t in tabs) {
129
160
                        if (t.get_display ().get_name () == s) {
130
161
                                select_tab (i);
137
168
        }
138
169
 
139
170
        public bool select_tab_name (string s) {
 
171
                if (MenuTab.suppress_event) {
 
172
                        warn_if_test ("Event supressed");
 
173
                        return false;
 
174
                }
 
175
                
140
176
                return select_char (s);
141
177
        }
142
178
 
143
179
        public void select_overview () {
 
180
                if (MenuTab.suppress_event) {
 
181
                        warn_if_test ("Event supressed");
 
182
                        return;
 
183
                }
 
184
                
144
185
                select_tab_name ("Overview");
145
186
        }
146
187
 
148
189
                Tab t;
149
190
                bool open;
150
191
                
 
192
                if (MenuTab.suppress_event) {
 
193
                        warn_if_test ("Event supressed");
 
194
                        return;
 
195
                }
 
196
                
151
197
                if (previous_tab == null) {
152
198
                        return;
153
199
                }
163
209
        public void close_display (FontDisplay f) {
164
210
                int i = -1;
165
211
                
 
212
                if (MenuTab.suppress_event) {
 
213
                        warn_if_test ("Event supressed");
 
214
                        return;
 
215
                }
 
216
                
166
217
                if (tabs.length () > 1) {
167
218
                        foreach (var t in tabs) {
168
219
                                ++i;
178
229
        } 
179
230
 
180
231
        public void close_all_tabs () {
 
232
                if (MenuTab.suppress_event) {
 
233
                        warn_if_test ("Event supressed");
 
234
                        return;
 
235
                }
 
236
                
181
237
                for (int i = 0; i < get_length (); i++) {
182
238
                        if (close_tab (i, false, true)) {
183
239
                                close_all_tabs ();
190
246
                Tab t;
191
247
                EmptyTab empty_tab_canvas;
192
248
                Tab empty_tab;
193
 
                
 
249
        
 
250
                if (MenuTab.suppress_event) {
 
251
                        warn_if_test ("Event supressed");
 
252
                        return false;
 
253
                }
 
254
                                
194
255
                if (!(0 <= index < tabs.length ())) {
195
256
                        return false;
196
257
                }
233
294
        
234
295
        public bool close_by_name (string name, bool background_tab = false) {
235
296
                int i = 0;
236
 
                
 
297
 
 
298
                if (MenuTab.suppress_event) {
 
299
                        warn_if_test ("Event supressed");
 
300
                        return false;
 
301
                }
 
302
                                
237
303
                foreach (var t in tabs) {
238
304
                        if (t.get_display ().get_name () == name) {
239
305
                                return close_tab (i, background_tab);
246
312
        }
247
313
        
248
314
        public void close_background_tab_by_name (string name) {
 
315
                if (MenuTab.suppress_event) {
 
316
                        warn_if_test ("Event supressed");
 
317
                        return;
 
318
                }
 
319
                
249
320
                close_by_name (name, true);
250
321
        }
251
322
        
252
323
        /** Select a tab and return true if it is open. */
253
324
        public bool selected_open_tab (Tab t) {
254
325
                int i = 0;
 
326
 
 
327
                if (MenuTab.suppress_event) {
 
328
                        warn_if_test ("Event supressed");
 
329
                        return false;
 
330
                }
 
331
                
255
332
                foreach (var n in tabs) {
256
333
                        if (n == t) {
257
334
                                select_tab (i);
284
361
 
285
362
        public bool selected_open_tab_by_name (string t) {
286
363
                int i = 0;
 
364
        
 
365
                if (MenuTab.suppress_event) {
 
366
                        warn_if_test ("Event supressed");
 
367
                        return false;
 
368
                }
 
369
                
287
370
                foreach (var n in tabs) {
288
371
                        if (n.get_display ().get_name () == t) {
289
372
                                select_tab (i);
297
380
        }
298
381
        
299
382
        public Tab get_selected_tab () {
300
 
                return tabs.nth (get_selected ()).data;
 
383
                int s = get_selected ();
 
384
                if (0 <= s < tabs.length ()) {
 
385
                        return tabs.nth (get_selected ()).data;
 
386
                }
 
387
                
 
388
                warning ("No tab selected.");
 
389
                return new Tab (new EmptyTab ("Error", "Error"), 30, false);
301
390
        }
302
391
        
303
392
        public uint get_length () {
308
397
                return selected;
309
398
        }
310
399
        
311
 
        public void select_tab (int index) {
 
400
        public void select_tab (int index, bool signal_selected = true) {
312
401
                Tab t;
313
 
        
 
402
 
 
403
                if (MenuTab.suppress_event) {
 
404
                        warn_if_test ("Event supressed");
 
405
                        return;
 
406
                }
 
407
                        
314
408
                // always close any pending text input if the user switches tab
315
409
                MainWindow.native_window.hide_text_input ();
316
410
 
349
443
                previous_tab = current_tab;
350
444
                current_tab = t;
351
445
 
352
 
                scroll_to_tab (selected);
 
446
                scroll_to_tab (selected, signal_selected);
353
447
        }
354
448
        
355
449
        private bool has_scroll () {
356
450
                int i = 0;
357
451
                double offset = 19;
 
452
                double end = (has_progress_wheel ()) ? width - 28 : width - 19;
 
453
                
 
454
                return_if_fail (tab1_right != null);
358
455
                
359
456
                if (first_tab > 0) {
360
457
                        return true;
366
463
                                continue;
367
464
                        }
368
465
                        
369
 
                        if (offset + t.get_width () + 3 > width - 19) {
 
466
                        if (offset + t.get_width () + 3 > end) {
370
467
                                return true;
371
468
                        }
372
469
 
373
 
                        offset += t.get_width () + 3;
 
470
                        offset += t.get_width () + ((!)tab1_right).get_width () * scale;
374
471
                        i++;
375
472
                }
376
473
                
381
478
                unowned List<Tab?>? lt;
382
479
                Tab t;
383
480
                
384
 
                lt = tabs.nth(index);
385
 
                return_if_fail(lt != null);             
 
481
                lt = tabs.nth (index);
 
482
                return_if_fail (lt != null);            
386
483
                t = (!) ((!) lt).data;
387
484
                
388
485
                signal_tab_selected (t);                
389
486
        }
390
487
        
391
 
        private void scroll_to_tab (int index) {
 
488
        private void scroll_to_tab (int index, bool send_signal_selected = true) {
392
489
                double offset = 19;
393
490
                int i = 0;
 
491
                double end = (has_progress_wheel ()) ? width - 28 : width - 19;
 
492
                
 
493
                return_if_fail (tab1_right != null);
394
494
                
395
495
                if (index < first_tab) {
396
496
                        first_tab = index;
397
 
                        signal_selected (index);
 
497
                        
 
498
                        if (send_signal_selected) {
 
499
                                signal_selected (index);
 
500
                        }
398
501
                        return;
399
502
                }
400
503
                
406
509
                        }
407
510
                        
408
511
                        // out of view
409
 
                        if (offset + t.get_width () + 3 > width - 19) {
 
512
                        if (offset + t.get_width () + 3 > end) {
410
513
                                first_tab++;
411
514
                                scroll_to_tab (index);
412
515
                                return;
414
517
 
415
518
                        // in view
416
519
                        if (i == index) {
417
 
                                signal_selected (index);
 
520
                                
 
521
                                if (send_signal_selected) {                             
 
522
                                        signal_selected (index);
 
523
                                }
 
524
                                
418
525
                                return;
419
526
                        }
420
527
 
421
 
                        offset += t.get_width () + 3;
 
528
                        offset += t.get_width () + ((!)tab1_right).get_width () * scale;
422
529
                        i++;
423
530
                }
424
531
                
429
536
                int over, close;
430
537
                
431
538
                if (MenuTab.suppress_event) {
 
539
                        warn_if_test ("Event supressed");
432
540
                        return;
433
541
                }
434
542
                
435
543
                this.width = width;
436
544
                this.height = height;
 
545
                this.scale = height / 117.0;
437
546
                
438
 
                is_over_close (x, y, out over, out close);
 
547
                over_close (x, y, out over, out close);
439
548
 
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);
442
551
                } else {
443
552
                        select_tab (over);
444
553
                }
445
554
        }
446
555
        
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;
449
 
                
 
560
 
 
561
                if (MenuTab.suppress_event) {
 
562
                        warn_if_test ("Event supressed");
 
563
                        return;
 
564
                }
 
565
                                
450
566
                if (tab_width < 0) {
451
567
                        tab_width = 9 * display_item.get_label ().char_count ();
452
568
                        tab_width += 36;
453
569
                }
454
570
                                
455
571
                tabs.insert (new Tab (display_item, tab_width, always_open), s);
456
 
                select_tab (s);
 
572
                select_tab (s, signal_selected);
457
573
        }
458
574
        
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) {
 
577
                bool i;
 
578
                
 
579
                if (MenuTab.suppress_event) {
 
580
                        warn_if_test ("Event supressed");
 
581
                        return false;
 
582
                }
 
583
                                
 
584
                i = select_tab_name (display_item.get_name ());
462
585
 
463
586
                if (!i) {
464
 
                        add_tab (display_item, tab_width, always_open);
 
587
                        add_tab (display_item, signal_selected);
465
588
                        return true;
466
589
                }
467
590
                
469
592
        }
470
593
        
471
594
        public void draw (Context cr, int width, int height) {
 
595
                double next_tab_x;
 
596
                double w, h;
 
597
                double progress_y;
 
598
                
472
599
                this.width = width;
473
600
                this.height = height;
 
601
                this.scale = height / 117.0;
 
602
                                
 
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);
474
607
                
475
608
                cr.save ();
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 ();
480
 
                cr.stroke ();
481
613
                cr.restore ();
482
614
 
483
 
                for (int j = 0; j < width; j++) {
484
 
                        cr.set_source_surface ((!) bar_background, j, height - ((!) bar_background).get_height ());
 
615
                cr.save ();
 
616
                cr.scale (scale, scale);
 
617
                
 
618
                w = width / scale;
 
619
                h = height / scale;
 
620
 
 
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 ());
485
623
                        cr.paint ();
486
624
                }
487
625
 
488
626
                if (has_scroll ()) {
489
627
                        // left arrow
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);
491
629
                        cr.paint ();
492
630
 
493
631
                        // right arrow
494
 
                        cr.set_source_surface (next_tab, width - 19, height - next_tab.get_height () - 5);
495
 
                        cr.paint ();
 
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);
 
634
                        cr.paint ();
 
635
                }
 
636
                
 
637
                // progress wheel
 
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);
 
642
                        
 
643
                        c.save ();
 
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);
 
647
                        c.fill_preserve ();     
 
648
                        
 
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);
 
652
                        
 
653
                        c.set_source_surface ((!) progress, 0 ,0);
 
654
                        
 
655
                        c.translate (p.get_width () / 2.0, p.get_height () / 2.0);
 
656
                        c.paint ();
 
657
                        c.restore ();
 
658
 
 
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);
 
661
                        cr.paint ();
 
662
                        
496
663
                }
497
664
                
498
665
                draw_tabs (cr);
499
 
                
 
666
                cr.restore ();
500
667
        }
501
668
        
502
669
        private void draw_tabs (Context cr) {
503
670
                double close_opacity;
504
 
                double offset = 19;
 
671
                double offset = 19 / scale;
 
672
                double tab_width;
505
673
                int i = 0;
 
674
                double tabs_end = width / scale;
 
675
                double h = height / scale;
 
676
                double tab_height;
 
677
                double tab_y;
 
678
                
 
679
                if (has_progress_wheel ()) {
 
680
                        tabs_end -= 19 / scale;
 
681
                }
 
682
                
 
683
                if (has_scroll ()) {
 
684
                        tabs_end -= 19 / scale;
 
685
                }               
506
686
                
507
687
                return_if_fail (tab3_right != null);
508
688
                return_if_fail (tab2_right != null);
512
692
                return_if_fail (tab2_left != null);
513
693
                return_if_fail (tab1_left != null);
514
694
                return_if_fail (tab1_right != null);
 
695
                return_if_fail (next_tab != null);
 
696
                
 
697
                tab_height = ((!)tab3_right).get_height ();
 
698
                tab_y = h - tab_height;
515
699
                
516
700
                foreach (Tab t in tabs) {
517
701
                        
522
706
 
523
707
                        cr.save ();
524
708
                        cr.translate (offset, 0);
525
 
                                                
526
 
                        if (offset + t.get_width () + next_tab.get_width () + 3 > width) {
 
709
                        
 
710
                        tab_width = t.get_width () / scale;
 
711
                        
 
712
                        if (offset + tab_width + ((!)next_tab).get_width () + 3 / scale > tabs_end) {
 
713
                                cr.restore ();
527
714
                                break;
528
715
                        }
529
716
                
530
717
                        // background
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);
534
721
                                        cr.paint ();
535
722
                                }                                                       
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);
539
726
                                        cr.paint ();
540
727
                                }                               
541
728
                        } else {
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);
544
731
                                        cr.paint ();
545
732
                                }
546
733
                        }
547
734
                        
548
735
                        // close (x)
549
736
                        if (t.has_close_button ()) {
550
 
                                cr.set_line_width (1);
 
737
                                cr.save ();
 
738
                                cr.new_path ();
 
739
                                cr.set_line_width (1 / scale);
551
740
                                
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);
554
743
                                
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);
557
746
 
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);
560
749
                                
561
750
                                cr.stroke ();
 
751
                                cr.restore ();
562
752
                        }
563
753
 
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 ());
568
758
                        cr.stroke ();
569
759
                        
570
760
                        // edges
571
 
                        if (tab1_left != null  && tab1_right != null && tab2_left != null  && tab2_right != null && tab3_left != null  && tab3_right != null) {
572
 
                                if (i == selected) {
573
 
                                        cr.set_source_surface ((!) tab3_left, 0, (height - ((!)tab1_left).get_height ()) + 1);
574
 
                                        cr.paint ();
575
 
                                        
576
 
                                        cr.set_source_surface ((!) tab3_right, t.get_width () - 2, (height - ((!)tab1_left).get_height ()) + 1);
577
 
                                        cr.paint ();
578
 
                                } else if (i == over) {
579
 
                                        cr.set_source_surface ((!) tab2_left, 0, (height - ((!)tab1_left).get_height ()) + 1);
580
 
                                        cr.paint ();
581
 
 
582
 
                                        cr.set_source_surface ((!) tab2_right, t.get_width () - 2, (height - ((!)tab1_left).get_height ()) + 1);
583
 
                                        cr.paint ();
584
 
                                } else {
585
 
                                        cr.set_source_surface ((!) tab1_left, 0, (height - ((!)tab1_left).get_height ()) + 1);
586
 
                                        cr.paint ();
587
 
 
588
 
                                        cr.set_source_surface ((!) tab1_right, t.get_width () - 2, (height - ((!)tab1_left).get_height ()) + 1);
589
 
                                        cr.paint ();
590
 
                                }
 
761
                        if (i == selected) {
 
762
                                cr.set_source_surface ((!) tab3_left, 0, tab_y);
 
763
                                cr.paint ();
 
764
                                
 
765
                                cr.set_source_surface ((!) tab3_right, tab_width, tab_y);
 
766
                                cr.paint ();
 
767
                        } else if (i == over) {
 
768
                                cr.set_source_surface ((!) tab2_left, 0, tab_y);
 
769
                                cr.paint ();
 
770
 
 
771
                                cr.set_source_surface ((!) tab2_right, tab_width, tab_y);
 
772
                                cr.paint ();
 
773
                        } else {
 
774
                                cr.set_source_surface ((!) tab1_left, 0, tab_y);
 
775
                                cr.paint ();
 
776
 
 
777
                                cr.set_source_surface ((!) tab1_right, tab_width, tab_y);
 
778
                                cr.paint ();
591
779
                        }
592
780
 
593
781
                        cr.restore ();
594
782
                        
595
 
                        offset += t.get_width () + 3;
 
783
                        offset += tab_width + ((!)tab1_right).get_width ();
596
784
                        i++;
597
785
                }
598
786
        }
600
788
        public void add_empty_tab (string name, string label) {
601
789
                add_tab (new EmptyTab (name, label));
602
790
        }
 
791
        
 
792
        bool has_progress_wheel () {
 
793
                return processing;
 
794
        }
 
795
 
 
796
        public void set_progress (bool running) {
 
797
                TimeoutSource timer;
 
798
                
 
799
                if (unlikely (processing == running)) {
 
800
                        warning (@"Progress is already set to $running");
 
801
                        return;
 
802
                }
 
803
                
 
804
                processing = running;
 
805
                
 
806
                if (processing) {
 
807
                        timer = new TimeoutSource (50);
 
808
                        timer.set_callback (() => {
 
809
                                wheel_rotation += 0.008 * 2 * Math.PI;
 
810
                                
 
811
                                if (wheel_rotation > 2 * Math.PI) {
 
812
                                        wheel_rotation -= 2 * Math.PI;
 
813
                                }
 
814
                                redraw (width - 19, 0, 19, height);
 
815
                                return processing;
 
816
                        });
 
817
                        timer.attach (null);
 
818
                }
 
819
        }
 
820
        
 
821
        public static void start_wheel () {
 
822
                if (!is_null (MainWindow.get_tab_bar ())) {
 
823
                        MainWindow.get_tab_bar ().set_progress (true);
 
824
                        Tool.yield ();
 
825
                }
 
826
        }
 
827
 
 
828
        public static void stop_wheel () {
 
829
                if (!is_null (MainWindow.get_tab_bar ())) {
 
830
                        MainWindow.get_tab_bar ().set_progress (false);
 
831
                        Tool.yield ();
 
832
                }
 
833
        }
603
834
}
604
835
 
605
836
}