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

« back to all changes in this revision

Viewing changes to external/xwt/Samples/Samples/CanvasWithWidget.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
// 
 
2
// CanvasWithWidget.cs
 
3
//  
 
4
// Author:
 
5
//       Lluis Sanchez <lluis@xamarin.com>
 
6
// 
 
7
// Copyright (c) 2011 Xamarin Inc
 
8
// 
 
9
// Permission is hereby granted, free of charge, to any person obtaining a copy
 
10
// of this software and associated documentation files (the "Software"), to deal
 
11
// in the Software without restriction, including without limitation the rights
 
12
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 
13
// copies of the Software, and to permit persons to whom the Software is
 
14
// furnished to do so, subject to the following conditions:
 
15
// 
 
16
// The above copyright notice and this permission notice shall be included in
 
17
// all copies or substantial portions of the Software.
 
18
// 
 
19
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 
20
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 
21
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 
22
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 
23
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 
24
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 
25
// THE SOFTWARE.
 
26
using System;
 
27
using Xwt;
 
28
using Xwt.Drawing;
 
29
 
 
30
namespace Samples
 
31
{
 
32
        public class CanvasWithWidget_Linear: VBox
 
33
        {
 
34
                public CanvasWithWidget_Linear ()
 
35
                {
 
36
                        MyCanvas c = new MyCanvas (true);
 
37
                        PackStart (c, BoxMode.FillAndExpand);
 
38
                }
 
39
        }
 
40
 
 
41
        public class CanvasWithWidget_Radial : VBox
 
42
        {
 
43
                public CanvasWithWidget_Radial ()
 
44
                {
 
45
                        MyCanvas c = new MyCanvas (false);
 
46
                        PackStart (c, BoxMode.FillAndExpand);
 
47
                }
 
48
        }
 
49
        
 
50
        class MyCanvas: Canvas
 
51
        {
 
52
                Rectangle rect = new Rectangle (30, 30, 100, 30);
 
53
                bool Linear {
 
54
                        get; set;
 
55
                }
 
56
 
 
57
                public MyCanvas (bool linear)
 
58
                {
 
59
                        var entry = new TextEntry () { ShowFrame = false };
 
60
                        AddChild (entry, rect);
 
61
                        
 
62
                        var box = new HBox ();
 
63
                        box.PackStart (new Button ("..."));
 
64
                        box.PackStart (new TextEntry (), BoxMode.FillAndExpand);
 
65
                        AddChild (box, new Rectangle (30, 70, 100, 30));
 
66
                        Linear = linear;
 
67
                }
 
68
                
 
69
                protected override void OnDraw (Xwt.Drawing.Context ctx, Rectangle dirtyRect)
 
70
                {
 
71
                        if (Bounds.IsEmpty)
 
72
                                return;
 
73
 
 
74
                        ctx.Rectangle (0, 0, Bounds.Width, Bounds.Height);
 
75
                        Gradient g = null;
 
76
                        if (Linear)
 
77
                                g = new LinearGradient (0, 0, Bounds.Width, Bounds.Height);
 
78
                        else
 
79
                                g = new RadialGradient (Bounds.Width / 2, Bounds.Height / 2, Bounds.Width / 2, Bounds.Width / 2, Bounds.Height / 2, Bounds.Width / 4); 
 
80
                        g.AddColorStop (0, new Color (1, 0, 0));
 
81
                        g.AddColorStop (1, new Color (0, 1, 0));
 
82
                        ctx.Pattern = g;
 
83
                        ctx.Fill ();
 
84
                        
 
85
                        Rectangle r = rect.Inflate (5, 5);
 
86
                        ctx.Rectangle (r);
 
87
                        ctx.SetColor (new Color (0,0,1));
 
88
                        ctx.SetLineWidth (1);
 
89
                        ctx.Stroke ();
 
90
                }
 
91
        }
 
92
}
 
93