~ubuntu-branches/ubuntu/trusty/monodevelop/trusty-proposed

« back to all changes in this revision

Viewing changes to external/xwt/Samples/Samples/Boxes.cs

  • Committer: Package Import Robot
  • Author(s): Jo Shields
  • Date: 2013-05-12 09:46:03 UTC
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20130512094603-mad323bzcxvmcam0
Tags: upstream-4.0.5+dfsg
ImportĀ upstreamĀ versionĀ 4.0.5+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
using System;
 
2
using Xwt;
 
3
using Xwt.Drawing;
 
4
 
 
5
namespace Samples
 
6
{
 
7
        public class Boxes: VBox
 
8
        {
 
9
                public Boxes ()
 
10
                {
 
11
                        HBox box1 = new HBox ();
 
12
                        
 
13
                        VBox box2 = new VBox ();
 
14
                        box2.PackStart (new SimpleBox (30), BoxMode.None);
 
15
                        box2.PackStart (new SimpleBox (30), BoxMode.None);
 
16
                        box2.PackStart (new SimpleBox (30), BoxMode.FillAndExpand);
 
17
                        
 
18
                        box1.PackStart (box2, BoxMode.FillAndExpand);
 
19
                        box1.PackStart (new SimpleBox (30), BoxMode.None);
 
20
                        box1.PackStart (new SimpleBox (30), BoxMode.Expand);
 
21
                        PackStart (box1, BoxMode.None);
 
22
                        
 
23
                        HBox box3 = new HBox ();
 
24
                        box3.PackEnd (new SimpleBox (30));
 
25
                        box3.PackStart (new SimpleBox (20) {Color = new Color (1, 0.5, 0.5)});
 
26
                        box3.PackEnd (new SimpleBox (40));
 
27
                        box3.PackStart (new SimpleBox (10) {Color = new Color (1, 0.5, 0.5)});
 
28
                        box3.PackEnd (new SimpleBox (30));
 
29
                        box3.PackStart (new SimpleBox (10) {Color = new Color (1, 0.5, 0.5)}, BoxMode.FillAndExpand);
 
30
                        PackStart (box3);
 
31
                        
 
32
                        HBox box4 = new HBox ();
 
33
                        Button b = new Button ("Click me");
 
34
                        b.Clicked += delegate {
 
35
                                b.Label = "Button has grown";
 
36
                        };
 
37
                        box4.PackStart (new SimpleBox (30), BoxMode.FillAndExpand);
 
38
                        box4.PackStart (b);
 
39
                        box4.PackStart (new SimpleBox (30), BoxMode.FillAndExpand);
 
40
                        PackStart (box4);
 
41
                        
 
42
                        HBox box5 = new HBox ();
 
43
                        Button b2 = new Button ("Hide / Show");
 
44
                        box5.PackStart (new SimpleBox (30), BoxMode.FillAndExpand);
 
45
                        var hsb = new SimpleBox (20);
 
46
                        box5.PackStart (hsb, BoxMode.None);
 
47
                        box5.PackStart (b2);
 
48
                        box5.PackStart (new SimpleBox (30), BoxMode.FillAndExpand);
 
49
                        b2.Clicked += delegate {
 
50
                                hsb.Visible = !hsb.Visible;
 
51
                        };
 
52
                        PackStart (box5);
 
53
                        
 
54
                        HBox box6 = new HBox ();
 
55
                        for (int n=0; n<15; n++) {
 
56
                                var w = new Label ("TestLabel" + n);
 
57
                                w.MinWidth = 10;
 
58
                                box6.PackStart (w);
 
59
                        }
 
60
                        PackStart (box6);
 
61
                }
 
62
        }
 
63
        
 
64
        class SimpleBox: Canvas
 
65
        {
 
66
                Size coreSize;
 
67
                double margin = 1;
 
68
                bool highlight;
 
69
                
 
70
                public Color Color { get; set; }
 
71
                
 
72
                public SimpleBox (double coreSize)
 
73
                {
 
74
                        Color = new Color (0.5, 0.5, 1);
 
75
                        this.coreSize = new Size (coreSize, coreSize);
 
76
                        MinWidth = MinHeight = coreSize + margin * 2;
 
77
                }
 
78
                
 
79
                public SimpleBox (double coreWidth, double coreHeight)
 
80
                {
 
81
                        Color = new Color (0.5, 0.5, 1);
 
82
                        this.coreSize = new Size (coreWidth, coreHeight);
 
83
                        MinWidth = coreSize.Width + margin * 2;
 
84
                        MinHeight = coreSize.Height + margin * 2;
 
85
                }
 
86
                
 
87
                protected override void OnMouseEntered (EventArgs args)
 
88
                {
 
89
                        base.OnMouseEntered (args);
 
90
                        highlight = true;
 
91
                        QueueDraw ();
 
92
                }
 
93
                
 
94
                protected override void OnMouseExited (EventArgs args)
 
95
                {
 
96
                        base.OnMouseExited (args);
 
97
                        QueueDraw ();
 
98
                        highlight = false;
 
99
                }
 
100
                
 
101
                protected override void OnDraw (Context ctx, Rectangle dirtyRect)
 
102
                {
 
103
                        ctx.SetColor (new Color (0.5, 0.5, 0.5));
 
104
                        ctx.Rectangle (Bounds);
 
105
                        ctx.Fill ();
 
106
                        ctx.SetColor (new Color (0.8, 0.8, 0.8));
 
107
                        ctx.Rectangle (Bounds.Inflate (-margin, -margin)); 
 
108
                        ctx.Fill ();
 
109
                        ctx.SetColor (highlight ? Color.BlendWith (Xwt.Drawing.Colors.White, 0.5) : Color);
 
110
                        ctx.Rectangle (Bounds.Width / 2 - coreSize.Width / 2, Bounds.Height / 2 - coreSize.Height / 2, coreSize.Width, coreSize.Height);
 
111
                        ctx.Fill ();
 
112
                }
 
113
        }
 
114
}
 
115