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

« back to all changes in this revision

Viewing changes to external/xwt/Samples/Samples/ScrollWindowSample.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
// ScrollWindowSample.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 ScrollWindowSample: VBox
 
33
        {
 
34
                public ScrollWindowSample ()
 
35
                {
 
36
                        ScrollView v1 = new ScrollView ();
 
37
                        VBox b1 = new VBox ();
 
38
                        for (int n=0; n<30; n++)
 
39
                                b1.PackStart (new Label ("Line " + n), BoxMode.None);
 
40
                        Button u = new Button ("Click to remove");
 
41
                        u.Clicked += delegate {
 
42
                                b1.Remove (u);
 
43
                        };
 
44
                        b1.PackStart (u);
 
45
                        
 
46
                        v1.Content = b1;
 
47
                        v1.VerticalScrollPolicy = ScrollPolicy.Always;
 
48
                        v1.BorderVisible = false;
 
49
                        PackStart (v1, BoxMode.FillAndExpand);
 
50
                        
 
51
                        ScrollView v2 = new ScrollView ();
 
52
                        VBox b2 = new VBox ();
 
53
                        for (int n=0; n<10; n++)
 
54
                                b2.PackStart (new Label ("Line " + n), BoxMode.None);
 
55
                        v2.Content = b2;
 
56
                        v2.VerticalScrollPolicy = ScrollPolicy.Never;
 
57
                        PackStart (v2, BoxMode.FillAndExpand);
 
58
                        
 
59
                        ScrollView v3 = new ScrollView ();
 
60
                        VBox b3 = new VBox ();
 
61
                        Button b = new Button ("Click to add items");
 
62
                        b.Clicked += delegate {
 
63
                                for (int n=0; n<10; n++)
 
64
                                        b3.PackStart (new Label ("Line " + n), BoxMode.None);
 
65
                        };
 
66
                        b3.PackStart (b);
 
67
                        v3.Content = b3;
 
68
                        v3.VerticalScrollPolicy = ScrollPolicy.Automatic;
 
69
                        PackStart (v3, BoxMode.FillAndExpand);
 
70
                        
 
71
                        ScrollView v4 = new ScrollView ();
 
72
                        PackStart (v4, BoxMode.FillAndExpand);
 
73
                        var sb = new ScrollableCanvas ();
 
74
                        v4.Content = sb;
 
75
                        v4.VerticalScrollPolicy = ScrollPolicy.Always;
 
76
                }
 
77
        }
 
78
        
 
79
        class ScrollableCanvas: Canvas
 
80
        {
 
81
                ScrollAdjustment hscroll;
 
82
                ScrollAdjustment vscroll;
 
83
                int imageSize = 500;
 
84
                
 
85
                public ScrollableCanvas ()
 
86
                {
 
87
                        MinWidth = 100;
 
88
                        MinHeight = 100;
 
89
                }
 
90
                
 
91
                protected override void OnDraw (Context ctx, Rectangle dirtyRect)
 
92
                {
 
93
                        ctx.Save ();
 
94
                        ctx.Translate (-hscroll.Value, -vscroll.Value);
 
95
                        ctx.Rectangle (new Rectangle (0, 0, imageSize, imageSize));
 
96
                        ctx.SetColor (Xwt.Drawing.Colors.White);
 
97
                        ctx.Fill ();
 
98
                        ctx.Arc (imageSize / 2, imageSize / 2, imageSize / 2 - 20, 0, 360);
 
99
                        ctx.SetColor (new Color (0,0,1));
 
100
                        ctx.Fill ();
 
101
                        ctx.Restore ();
 
102
 
 
103
                        ctx.Rectangle (0, 0, Bounds.Width, 30);
 
104
                        ctx.SetColor (new Color (1, 0, 0, 0.5));
 
105
                        ctx.Fill ();
 
106
                }
 
107
                
 
108
                protected override bool SupportsCustomScrolling {
 
109
                        get {
 
110
                                return true;
 
111
                        }
 
112
                }
 
113
                
 
114
                protected override void SetScrollAdjustments (ScrollAdjustment horizontal, ScrollAdjustment vertical)
 
115
                {
 
116
                        hscroll = horizontal;
 
117
                        vscroll = vertical;
 
118
                        
 
119
                        hscroll.UpperValue = imageSize;
 
120
                        hscroll.PageIncrement = Bounds.Width;
 
121
                        hscroll.PageSize = Bounds.Width;
 
122
                        hscroll.ValueChanged += delegate {
 
123
                                QueueDraw ();
 
124
                        };
 
125
                        
 
126
                        vscroll.UpperValue = imageSize;
 
127
                        vscroll.PageIncrement = Bounds.Height;
 
128
                        vscroll.PageSize = Bounds.Height;
 
129
                        vscroll.ValueChanged += delegate {
 
130
                                QueueDraw ();
 
131
                        };
 
132
                }
 
133
                
 
134
                protected override void OnBoundsChanged ()
 
135
                {
 
136
                        vscroll.PageSize = vscroll.PageIncrement = Bounds.Height;
 
137
                        hscroll.PageSize = hscroll.PageIncrement = Bounds.Width;
 
138
                }
 
139
        }
 
140
}
 
141