aboutsummaryrefslogtreecommitdiffstatsci
path: root/src/GraphicObjects/Popper.cs
blob: 0bbe3a527c4deaa8656271f2e33cb3ebbeb4556b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
using System;


using System.Collections.Generic;
using System.Linq;
using System.Text;
//using OpenTK.Graphics.OpenGL;

using Cairo;

using winColors = System.Drawing.Color;
using System.Diagnostics;
using System.Xml.Serialization;
using OpenTK.Input;
using System.ComponentModel;
using System.Xml;
using System.IO;

namespace go
{
	[DefaultTemplate("#go.Templates.Popper.goml")]
    public class Popper : TemplatedContainer
    {		
		bool _isPopped;
		Label _caption;
		Image _image;
		GraphicObject _content;

		public event EventHandler Pop;
		public event EventHandler Unpop;

		public override GraphicObject Content {
			get { return _content; }
			set { _content = value; }
		}
		public Popper() : base()
		{
		}	

		protected override void loadTemplate(GraphicObject template = null)
		{
			base.loadTemplate (template);

			_caption = this.child.FindByName ("Caption") as Label;
			_image = this.child.FindByName ("Image") as Image;

			if (_image == null)
				return;
			_image.SvgSub = "collapsed";

			this.Pop += (object sender, EventArgs e) => {_image.SvgSub = "expanded";};
			this.Unpop += (object sender, EventArgs e) => {_image.SvgSub = "collapsed";};

		}
			

		[XmlAttributeAttribute()][DefaultValue("Popper")]
		public string Title {
			get { return _caption.Text; } 
			set {
				if (_caption == null)
					return;
				_caption.Text = value; 
			}
		}        
      
		[XmlAttributeAttribute()][DefaultValue(false)]
        public bool IsPopped
        {
			get { return _isPopped; }
            set
            {
                if (value == _isPopped)
                    return;

				_isPopped = value;

				if (_isPopped)
					onPop (this, null);
				else
					onUnpop (this, null);

                registerForGraphicUpdate();
            }
        }

		public virtual void onPop(object sender, EventArgs e)
		{
			if (Content != null) {
				Rectangle r = this.ScreenCoordinates (this.Slot);
				Content.Visible = true;
				Content.Left = r.Left;
				Content.Top = r.Bottom;
				TopContainer.AddWidget (Content);
			}
			Pop.Raise (this, e);
		}
		public virtual void onUnpop(object sender, EventArgs e)
		{
			TopContainer.DeleteWidget (Content);
			Unpop.Raise (this, e);
		}
			
		public override void onMouseClick (object sender, MouseButtonEventArgs e)
		{
			IsPopped = !IsPopped;
			base.onMouseClick (sender, e);
		}

	}
}