~ubuntu-branches/ubuntu/saucy/f-spot/saucy

« back to all changes in this revision

Viewing changes to lib/Hyena/src/Hyena.Gui/Hyena.Widgets/SegmentedBar.cs

  • Committer: Bazaar Package Importer
  • Author(s): Iain Lane
  • Date: 2010-05-24 10:35:57 UTC
  • mfrom: (2.4.7 experimental)
  • Revision ID: james.westby@ubuntu.com-20100524103557-1j0i8f66caybci2n
Tags: 0.7.0-1
* New upstream release 0.7.0
 + First release of the unstable 0.7 development series. Massive changes.
 + Reparenting and detaching support (Anton Keks) (Closes: #559745)
 + A new Mallard-based documentation (Harold Schreckengost)
 + No longer embeds flickrnet, uses distribution copy (Iain Lane)
 + Adoption of a large amount of Hyena functionality (Paul Lange, Peter
   Goetz)
 + No longer embeds gnome-keyring-sharp
 + Completely rewritten import, much faster and less memory hungry (Ruben
   Vermeersch) (Closes: #559080, #492658, #341790, #357811, #426017) (LP:
   #412091)
 + No longer use gphoto2-sharp, now uses gvfs which is less crash-pron
   (Ruben Vermeersch)
 + Fix Facebook support (Ruben Vermeersch)
 + Modernized unit tests
 + Revamped build (Mike Gemünde)
 + Much improved duplicate detection (much faster too) (Ruben Vermeersch)
 + Mouse selection in Iconview (Vincent Pomey)
 + Image panning support using middle mouse button (Wojciech Dzierżanowski)
 + Timeline slider now restricted to the size of the window (Iain Churcher)
 + Over 100 bugs closed (http://bit.ly/cyVjnD)
   - No more warnings about schema defaults (Closes: #584215) (LP: #586132)
* debian/control: Clean up build deps to match configure checks
* debian/rules: Don't run dh_makeshilbs as we don't ship any shared
  libraries. There are some private ones though, which get picked up and
  result in a useless postinst/postrm call to ldconfig. Thanks, lintian.
* debian/patches/debian_fix-distclean.patch,
  debian/patches/debian_fix_f-spot.exe.config.patch,
  debian/patches/debian_link-system-flickrnet.patch,
  debian/patches/debian_link-system-gnome-keyring.patch,
  debian/patches/debian_disable-unit-tests,
  debian/patches/git_transition_duration.patch,
  debian/patches/ubuntu_fix_folder_export_hang.patch:
  Clean up obsolete patches which are no longer necessary 
* debian/patches/*: Temporarily disable patches which originated from Ubuntu
  and no longer apply cleanly. We will get these back in a future upstream
  development release.
* debian/patches/*: Refresh to apply cleanly 
* debian/rules: Add new include dir to autoreconf call to pick up f-spot
  macros 

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//
 
2
// SegmentedBar.cs
 
3
//
 
4
// Author:
 
5
//   Aaron Bockover <abockover@novell.com>
 
6
//
 
7
// Copyright (C) 2008 Novell, Inc.
 
8
//
 
9
// Permission is hereby granted, free of charge, to any person obtaining
 
10
// a copy of this software and associated documentation files (the
 
11
// "Software"), to deal in the Software without restriction, including
 
12
// without limitation the rights to use, copy, modify, merge, publish,
 
13
// distribute, sublicense, and/or sell copies of the Software, and to
 
14
// permit persons to whom the Software is furnished to do so, subject to
 
15
// the following conditions:
 
16
//
 
17
// The above copyright notice and this permission notice shall be
 
18
// included in all copies or substantial portions of the Software.
 
19
//
 
20
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 
21
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 
22
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 
23
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
 
24
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
 
25
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 
26
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
27
//
 
28
 
 
29
using System;
 
30
using System.Collections.Generic;
 
31
 
 
32
using Gtk;
 
33
using Cairo;
 
34
 
 
35
using Hyena.Gui;
 
36
 
 
37
namespace Hyena.Widgets
 
38
{
 
39
    public class SegmentedBar : Widget
 
40
    {
 
41
        public delegate string BarValueFormatHandler (Segment segment);
 
42
 
 
43
        public class Segment
 
44
        {
 
45
            private string title;
 
46
            private double percent;
 
47
            private Cairo.Color color;
 
48
            private bool show_in_bar;
 
49
 
 
50
            public Segment (string title, double percent, Cairo.Color color)
 
51
                : this (title, percent, color, true)
 
52
            {
 
53
            }
 
54
 
 
55
            public Segment (string title, double percent, Cairo.Color color, bool showInBar)
 
56
            {
 
57
                this.title = title;
 
58
                this.percent = percent;
 
59
                this.color = color;
 
60
                this.show_in_bar = showInBar;
 
61
            }
 
62
 
 
63
            public string Title {
 
64
                get { return title; }
 
65
                set { title = value; }
 
66
            }
 
67
 
 
68
            public double Percent {
 
69
                get { return percent; }
 
70
                set { percent = value; }
 
71
            }
 
72
 
 
73
            public Cairo.Color Color {
 
74
                get { return color; }
 
75
                set { color = value; }
 
76
            }
 
77
 
 
78
            public bool ShowInBar {
 
79
                get { return show_in_bar; }
 
80
                set { show_in_bar = value; }
 
81
            }
 
82
 
 
83
            internal int LayoutWidth;
 
84
            internal int LayoutHeight;
 
85
        }
 
86
 
 
87
        // State
 
88
        private List<Segment> segments = new List<Segment> ();
 
89
        private int layout_width;
 
90
        private int layout_height;
 
91
 
 
92
        // Properties
 
93
        private int bar_height = 26;
 
94
        private int bar_label_spacing = 8;
 
95
        private int segment_label_spacing = 16;
 
96
        private int segment_box_size = 12;
 
97
        private int segment_box_spacing = 6;
 
98
        private int h_padding = 0;
 
99
 
 
100
        private bool show_labels = true;
 
101
        private bool reflect = true;
 
102
 
 
103
        private Color remainder_color = CairoExtensions.RgbToColor (0xeeeeee);
 
104
 
 
105
        private BarValueFormatHandler format_handler;
 
106
 
 
107
        public SegmentedBar ()
 
108
        {
 
109
            WidgetFlags |= WidgetFlags.NoWindow;
 
110
        }
 
111
 
 
112
        protected override void OnRealized ()
 
113
        {
 
114
            GdkWindow = Parent.GdkWindow;
 
115
            base.OnRealized ();
 
116
        }
 
117
 
 
118
#region Size Calculations
 
119
 
 
120
        protected override void OnSizeRequested (ref Requisition requisition)
 
121
        {
 
122
            requisition.Width = 200;
 
123
            requisition.Height = 0;
 
124
        }
 
125
 
 
126
        protected override void OnSizeAllocated (Gdk.Rectangle allocation)
 
127
        {
 
128
            int _bar_height = reflect ? (int)Math.Ceiling (bar_height * 1.75) : bar_height;
 
129
 
 
130
            if (show_labels) {
 
131
                ComputeLayoutSize ();
 
132
                HeightRequest = Math.Max (bar_height + bar_label_spacing + layout_height, _bar_height);
 
133
                WidthRequest = layout_width + (2 * h_padding);
 
134
            } else {
 
135
                HeightRequest = _bar_height;
 
136
                WidthRequest = bar_height + (2 * h_padding);
 
137
            }
 
138
 
 
139
            base.OnSizeAllocated (allocation);
 
140
        }
 
141
 
 
142
        private void ComputeLayoutSize ()
 
143
        {
 
144
            if (segments.Count == 0) {
 
145
                return;
 
146
            }
 
147
 
 
148
            Pango.Layout layout = null;
 
149
 
 
150
            layout_width = layout_height = 0;
 
151
 
 
152
            for (int i = 0, n = segments.Count; i < n; i++) {
 
153
                int aw, ah, bw, bh;
 
154
 
 
155
                layout = CreateAdaptLayout (layout, false, true);
 
156
                layout.SetText (FormatSegmentText (segments[i]));
 
157
                layout.GetPixelSize (out aw, out ah);
 
158
 
 
159
                layout = CreateAdaptLayout (layout, true, false);
 
160
                layout.SetText (FormatSegmentValue (segments[i]));
 
161
                layout.GetPixelSize (out bw, out bh);
 
162
 
 
163
                int w = Math.Max (aw, bw);
 
164
                int h = ah + bh;
 
165
 
 
166
                segments[i].LayoutWidth = w;
 
167
                segments[i].LayoutHeight = Math.Max (h, segment_box_size * 2);
 
168
 
 
169
                layout_width += segments[i].LayoutWidth + segment_box_size + segment_box_spacing
 
170
                    + (i < n - 1 ? segment_label_spacing : 0);
 
171
                layout_height = Math.Max (layout_height, segments[i].LayoutHeight);
 
172
            }
 
173
 
 
174
            layout.Dispose ();
 
175
        }
 
176
 
 
177
#endregion
 
178
 
 
179
#region Public Methods
 
180
 
 
181
        public void AddSegmentRgba (string title, double percent, uint rgbaColor)
 
182
        {
 
183
            AddSegment (title, percent, CairoExtensions.RgbaToColor (rgbaColor));
 
184
        }
 
185
 
 
186
        public void AddSegmentRgb (string title, double percent, uint rgbColor)
 
187
        {
 
188
            AddSegment (title, percent, CairoExtensions.RgbToColor (rgbColor));
 
189
        }
 
190
 
 
191
        public void AddSegment (string title, double percent, Color color)
 
192
        {
 
193
            AddSegment (new Segment (title, percent, color, true));
 
194
        }
 
195
 
 
196
        public void AddSegment (string title, double percent, Color color, bool showInBar)
 
197
        {
 
198
            AddSegment (new Segment (title, percent, color, showInBar));
 
199
        }
 
200
 
 
201
        public void AddSegment (Segment segment)
 
202
        {
 
203
            lock (segments) {
 
204
                segments.Add (segment);
 
205
                QueueDraw ();
 
206
            }
 
207
        }
 
208
 
 
209
        public void UpdateSegment (int index, double percent)
 
210
        {
 
211
            segments[index].Percent = percent;
 
212
            QueueDraw ();
 
213
        }
 
214
 
 
215
#endregion
 
216
 
 
217
#region Public Properties
 
218
 
 
219
        public BarValueFormatHandler ValueFormatter {
 
220
            get { return format_handler; }
 
221
            set { format_handler = value; }
 
222
        }
 
223
 
 
224
        public Color RemainderColor {
 
225
            get { return remainder_color; }
 
226
            set {
 
227
                remainder_color = value;
 
228
                QueueDraw ();
 
229
            }
 
230
        }
 
231
 
 
232
        public int BarHeight {
 
233
            get { return bar_height; }
 
234
            set {
 
235
                if (bar_height != value) {
 
236
                    bar_height = value;
 
237
                    QueueResize ();
 
238
                }
 
239
            }
 
240
        }
 
241
 
 
242
        public bool ShowReflection {
 
243
            get { return reflect; }
 
244
            set {
 
245
                if (reflect != value) {
 
246
                    reflect = value;
 
247
                    QueueResize ();
 
248
                }
 
249
            }
 
250
        }
 
251
 
 
252
        public bool ShowLabels {
 
253
            get { return show_labels; }
 
254
            set {
 
255
                if (show_labels != value) {
 
256
                    show_labels = value;
 
257
                    QueueResize ();
 
258
                }
 
259
            }
 
260
        }
 
261
 
 
262
        public int SegmentLabelSpacing {
 
263
            get { return segment_label_spacing; }
 
264
            set {
 
265
                if (segment_label_spacing != value) {
 
266
                    segment_label_spacing = value;
 
267
                    QueueResize ();
 
268
                }
 
269
            }
 
270
        }
 
271
        public int SegmentBoxSize {
 
272
            get { return segment_box_size; }
 
273
            set {
 
274
                if (segment_box_size != value) {
 
275
                    segment_box_size = value;
 
276
                    QueueResize ();
 
277
                }
 
278
            }
 
279
        }
 
280
 
 
281
        public int SegmentBoxSpacing {
 
282
            get { return segment_box_spacing; }
 
283
            set {
 
284
                if (segment_box_spacing != value) {
 
285
                    segment_box_spacing = value;
 
286
                    QueueResize ();
 
287
                }
 
288
            }
 
289
        }
 
290
 
 
291
        public int BarLabelSpacing {
 
292
            get { return bar_label_spacing; }
 
293
            set {
 
294
                if (bar_label_spacing != value) {
 
295
                    bar_label_spacing = value;
 
296
                    QueueResize ();
 
297
                }
 
298
            }
 
299
        }
 
300
 
 
301
        public int HorizontalPadding {
 
302
            get { return h_padding; }
 
303
            set {
 
304
                if (h_padding != value) {
 
305
                    h_padding = value;
 
306
                    QueueResize ();
 
307
                }
 
308
            }
 
309
        }
 
310
 
 
311
#endregion
 
312
 
 
313
#region Rendering
 
314
 
 
315
        protected override bool OnExposeEvent (Gdk.EventExpose evnt)
 
316
        {
 
317
            if (evnt.Window != GdkWindow) {
 
318
                return base.OnExposeEvent (evnt);
 
319
            }
 
320
 
 
321
            Cairo.Context cr = Gdk.CairoHelper.Create (evnt.Window);
 
322
 
 
323
            if (reflect) {
 
324
                CairoExtensions.PushGroup (cr);
 
325
            }
 
326
 
 
327
            cr.Operator = Operator.Over;
 
328
            cr.Translate (Allocation.X + h_padding, Allocation.Y);
 
329
            cr.Rectangle (0, 0, Allocation.Width - h_padding, Math.Max (2 * bar_height,
 
330
                bar_height + bar_label_spacing + layout_height));
 
331
            cr.Clip ();
 
332
 
 
333
            Pattern bar = RenderBar (Allocation.Width - 2 * h_padding, bar_height);
 
334
 
 
335
            cr.Save ();
 
336
            cr.Source = bar;
 
337
            cr.Paint ();
 
338
            cr.Restore ();
 
339
 
 
340
            if (reflect) {
 
341
                cr.Save ();
 
342
 
 
343
                cr.Rectangle (0, bar_height, Allocation.Width - h_padding, bar_height);
 
344
                cr.Clip ();
 
345
 
 
346
                Matrix matrix = new Matrix ();
 
347
                matrix.InitScale (1, -1);
 
348
                matrix.Translate (0, -(2 * bar_height) + 1);
 
349
                cr.Transform (matrix);
 
350
 
 
351
                cr.Pattern = bar;
 
352
 
 
353
                LinearGradient mask = new LinearGradient (0, 0, 0, bar_height);
 
354
 
 
355
                mask.AddColorStop (0.25, new Color (0, 0, 0, 0));
 
356
                mask.AddColorStop (0.5, new Color (0, 0, 0, 0.125));
 
357
                mask.AddColorStop (0.75, new Color (0, 0, 0, 0.4));
 
358
                mask.AddColorStop (1.0, new Color (0, 0, 0, 0.7));
 
359
 
 
360
                cr.Mask (mask);
 
361
                mask.Destroy ();
 
362
 
 
363
                cr.Restore ();
 
364
 
 
365
                CairoExtensions.PopGroupToSource (cr);
 
366
                cr.Paint ();
 
367
            }
 
368
 
 
369
            if (show_labels) {
 
370
                cr.Translate ((reflect ? Allocation.X : -h_padding) + (Allocation.Width - layout_width) / 2,
 
371
                     (reflect ? Allocation.Y : 0) + bar_height + bar_label_spacing);
 
372
 
 
373
                RenderLabels (cr);
 
374
            }
 
375
 
 
376
            bar.Destroy ();
 
377
            CairoExtensions.DisposeContext (cr);
 
378
 
 
379
            return true;
 
380
        }
 
381
 
 
382
        private Pattern RenderBar (int w, int h)
 
383
        {
 
384
            ImageSurface s = new ImageSurface (Format.Argb32, w, h);
 
385
            Context cr = new Context (s);
 
386
            RenderBar (cr, w, h, h / 2);
 
387
// TODO Implement the new ctor - see http://bugzilla.gnome.org/show_bug.cgi?id=561394
 
388
#pragma warning disable 0618
 
389
            Pattern pattern = new Pattern (s);
 
390
#pragma warning restore 0618
 
391
            s.Destroy ();
 
392
            ((IDisposable)cr).Dispose ();
 
393
            return pattern;
 
394
        }
 
395
 
 
396
        private void RenderBar (Context cr, int w, int h, int r)
 
397
        {
 
398
            RenderBarSegments (cr, w, h, r);
 
399
            RenderBarStrokes (cr, w, h, r);
 
400
        }
 
401
 
 
402
        private void RenderBarSegments (Context cr, int w, int h, int r)
 
403
        {
 
404
            LinearGradient grad = new LinearGradient (0, 0, w, 0);
 
405
            double last = 0.0;
 
406
 
 
407
            foreach (Segment segment in segments) {
 
408
                if (segment.Percent > 0) {
 
409
                    grad.AddColorStop (last, segment.Color);
 
410
                    grad.AddColorStop (last += segment.Percent, segment.Color);
 
411
                }
 
412
            }
 
413
 
 
414
            CairoExtensions.RoundedRectangle (cr, 0, 0, w, h, r);
 
415
            cr.Pattern = grad;
 
416
            cr.FillPreserve ();
 
417
            cr.Pattern.Destroy ();
 
418
 
 
419
            grad = new LinearGradient (0, 0, 0, h);
 
420
            grad.AddColorStop (0.0, new Color (1, 1, 1, 0.125));
 
421
            grad.AddColorStop (0.35, new Color (1, 1, 1, 0.255));
 
422
            grad.AddColorStop (1, new Color (0, 0, 0, 0.4));
 
423
 
 
424
            cr.Pattern = grad;
 
425
            cr.Fill ();
 
426
            cr.Pattern.Destroy ();
 
427
        }
 
428
 
 
429
        private void RenderBarStrokes (Context cr, int w, int h, int r)
 
430
        {
 
431
            LinearGradient stroke = MakeSegmentGradient (h, CairoExtensions.RgbaToColor (0x00000040));
 
432
            LinearGradient seg_sep_light = MakeSegmentGradient (h, CairoExtensions.RgbaToColor (0xffffff20));
 
433
            LinearGradient seg_sep_dark = MakeSegmentGradient (h, CairoExtensions.RgbaToColor (0x00000020));
 
434
 
 
435
            cr.LineWidth = 1;
 
436
 
 
437
            double seg_w = 20;
 
438
            double x = seg_w > r ? seg_w : r;
 
439
 
 
440
            while (x <= w - r) {
 
441
                cr.MoveTo (x - 0.5, 1);
 
442
                cr.LineTo (x - 0.5, h - 1);
 
443
                cr.Pattern = seg_sep_light;
 
444
                cr.Stroke ();
 
445
 
 
446
                cr.MoveTo (x + 0.5, 1);
 
447
                cr.LineTo (x + 0.5, h - 1);
 
448
                cr.Pattern = seg_sep_dark;
 
449
                cr.Stroke ();
 
450
 
 
451
                x += seg_w;
 
452
            }
 
453
 
 
454
            CairoExtensions.RoundedRectangle (cr, 0.5, 0.5, w - 1, h - 1, r);
 
455
            cr.Pattern = stroke;
 
456
            cr.Stroke ();
 
457
 
 
458
            stroke.Destroy ();
 
459
            seg_sep_light.Destroy ();
 
460
            seg_sep_dark.Destroy ();
 
461
        }
 
462
 
 
463
        private LinearGradient MakeSegmentGradient (int h, Color color)
 
464
        {
 
465
            return MakeSegmentGradient (h, color, false);
 
466
        }
 
467
 
 
468
        private LinearGradient MakeSegmentGradient (int h, Color color, bool diag)
 
469
        {
 
470
            LinearGradient grad = new LinearGradient (0, 0, 0, h);
 
471
            grad.AddColorStop (0, CairoExtensions.ColorShade (color, 1.1));
 
472
            grad.AddColorStop (0.35, CairoExtensions.ColorShade (color, 1.2));
 
473
            grad.AddColorStop (1, CairoExtensions.ColorShade (color, 0.8));
 
474
            return grad;
 
475
        }
 
476
 
 
477
        private void RenderLabels (Context cr)
 
478
        {
 
479
            if (segments.Count == 0) {
 
480
                return;
 
481
            }
 
482
 
 
483
            Pango.Layout layout = null;
 
484
            Color text_color = CairoExtensions.GdkColorToCairoColor (Style.Foreground (State));
 
485
            Color box_stroke_color = new Color (0, 0, 0, 0.6);
 
486
 
 
487
            int x = 0;
 
488
 
 
489
            foreach (Segment segment in segments) {
 
490
                cr.LineWidth = 1;
 
491
                cr.Rectangle (x + 0.5, 2 + 0.5, segment_box_size - 1, segment_box_size - 1);
 
492
                LinearGradient grad = MakeSegmentGradient (segment_box_size, segment.Color, true);
 
493
                cr.Pattern = grad;
 
494
                cr.FillPreserve ();
 
495
                cr.Color = box_stroke_color;
 
496
                cr.Stroke ();
 
497
                grad.Destroy ();
 
498
 
 
499
                x += segment_box_size + segment_box_spacing;
 
500
 
 
501
                int lw, lh;
 
502
                layout = CreateAdaptLayout (layout, false, true);
 
503
                layout.SetText (FormatSegmentText (segment));
 
504
                layout.GetPixelSize (out lw, out lh);
 
505
 
 
506
                cr.MoveTo (x, 0);
 
507
                text_color.A = 0.9;
 
508
                cr.Color = text_color;
 
509
                PangoCairoHelper.ShowLayout (cr, layout);
 
510
                cr.Fill ();
 
511
 
 
512
                layout = CreateAdaptLayout (layout, true, false);
 
513
                layout.SetText (FormatSegmentValue (segment));
 
514
 
 
515
                cr.MoveTo (x, lh);
 
516
                text_color.A = 0.75;
 
517
                cr.Color = text_color;
 
518
                PangoCairoHelper.ShowLayout (cr, layout);
 
519
                cr.Fill ();
 
520
 
 
521
                x += segment.LayoutWidth + segment_label_spacing;
 
522
            }
 
523
 
 
524
            layout.Dispose ();
 
525
        }
 
526
 
 
527
#endregion
 
528
 
 
529
#region Utilities
 
530
 
 
531
        private int pango_size_normal;
 
532
 
 
533
        private Pango.Layout CreateAdaptLayout (Pango.Layout layout, bool small, bool bold)
 
534
        {
 
535
            if (layout == null) {
 
536
                Pango.Context context = CreatePangoContext ();
 
537
                layout = new Pango.Layout (context);
 
538
                layout.FontDescription = context.FontDescription;
 
539
                pango_size_normal = layout.FontDescription.Size;
 
540
            }
 
541
 
 
542
            layout.FontDescription.Size = small
 
543
                ? (int)(layout.FontDescription.Size * Pango.Scale.Small)
 
544
                : pango_size_normal;
 
545
 
 
546
            layout.FontDescription.Weight = bold
 
547
                ? Pango.Weight.Bold
 
548
                : Pango.Weight.Normal;
 
549
 
 
550
            return layout;
 
551
        }
 
552
 
 
553
 
 
554
        private string FormatSegmentText (Segment segment)
 
555
        {
 
556
            return segment.Title;
 
557
        }
 
558
 
 
559
        private string FormatSegmentValue (Segment segment)
 
560
        {
 
561
            return format_handler == null
 
562
                ? String.Format ("{0}%", segment.Percent * 100.0)
 
563
                : format_handler (segment);
 
564
        }
 
565
 
 
566
#endregion
 
567
 
 
568
    }
 
569
 
 
570
#region Test Module
 
571
 
 
572
    [TestModule ("Segmented Bar")]
 
573
    internal class SegmentedBarTestModule : Window
 
574
    {
 
575
        private SegmentedBar bar;
 
576
        private VBox box;
 
577
        public SegmentedBarTestModule () : base ("Segmented Bar")
 
578
        {
 
579
            BorderWidth = 10;
 
580
            AppPaintable = true;
 
581
 
 
582
            box = new VBox ();
 
583
            box.Spacing = 10;
 
584
            Add (box);
 
585
 
 
586
            int space = 55;
 
587
            bar = new SegmentedBar ();
 
588
            bar.HorizontalPadding = bar.BarHeight / 2;
 
589
            bar.AddSegmentRgb ("Audio", 0.00187992456702332, 0x3465a4);
 
590
            bar.AddSegmentRgb ("Other", 0.0788718162651326, 0xf57900);
 
591
            bar.AddSegmentRgb ("Video", 0.0516869922033282, 0x73d216);
 
592
            bar.AddSegment ("Free Space", 0.867561266964516, bar.RemainderColor, false);
 
593
 
 
594
            bar.ValueFormatter = delegate (SegmentedBar.Segment segment) {
 
595
                return String.Format ("{0} GB", space * segment.Percent);
 
596
            };
 
597
 
 
598
            HBox controls = new HBox ();
 
599
            controls.Spacing = 5;
 
600
 
 
601
            Label label = new Label ("Height:");
 
602
            controls.PackStart (label, false, false, 0);
 
603
 
 
604
            SpinButton height = new SpinButton (new Adjustment (bar.BarHeight, 5, 100, 1, 1, 1), 1, 0);
 
605
            height.Activated += delegate { bar.BarHeight = height.ValueAsInt; };
 
606
            height.Changed += delegate { bar.BarHeight = height.ValueAsInt; bar.HorizontalPadding = bar.BarHeight / 2; };
 
607
            controls.PackStart (height, false, false, 0);
 
608
 
 
609
            CheckButton reflect = new CheckButton ("Reflection");
 
610
            reflect.Active = bar.ShowReflection;
 
611
            reflect.Toggled += delegate { bar.ShowReflection = reflect.Active; };
 
612
            controls.PackStart (reflect, false, false, 0);
 
613
 
 
614
            CheckButton labels = new CheckButton ("Labels");
 
615
            labels.Active = bar.ShowLabels;
 
616
            labels.Toggled += delegate { bar.ShowLabels = labels.Active; };
 
617
            controls.PackStart (labels, false, false, 0);
 
618
 
 
619
            box.PackStart (controls, false, false, 0);
 
620
            box.PackStart (new HSeparator (), false, false, 0);
 
621
            box.PackStart (bar, false, false, 0);
 
622
            box.ShowAll ();
 
623
 
 
624
            SetSizeRequest (350, -1);
 
625
 
 
626
            Gdk.Geometry limits = new Gdk.Geometry ();
 
627
            limits.MinWidth = SizeRequest ().Width;
 
628
            limits.MaxWidth = Gdk.Screen.Default.Width;
 
629
            limits.MinHeight = -1;
 
630
            limits.MaxHeight = -1;
 
631
            SetGeometryHints (this, limits, Gdk.WindowHints.MaxSize | Gdk.WindowHints.MinSize);
 
632
        }
 
633
    }
 
634
 
 
635
#endregion
 
636
 
 
637
}