aboutsummaryrefslogtreecommitdiffstatsci
path: root/src/GraphicObjects/Image.cs
blob: 9806c9928563f5f3e590f921186ba0e2baff578a (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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Cairo;
using System.IO;
using System.Runtime.InteropServices;
using System.Xml.Serialization;
using System.ComponentModel;

namespace go
{
	public class Image : GraphicObject
	{
		Picture _pic;
		string _svgSub;

        [XmlAttributeAttribute("Path")]        
		public string ImagePath {
			get { return _pic == null ? null : _pic.Path; }
			set {				
				LoadImage (value);
				_pic.KeepProportions = true;
			}
		}

		[XmlAttributeAttribute()][DefaultValue(null)]
		public string SvgSub {
			get { return _svgSub; }
			set {
				_svgSub = value;
				registerForGraphicUpdate ();
			}
		}
			
		#region CTOR
		public Image () : base()
		{
		}
		public Image (string _imgPath, Rectangle _bounds)
            : base(_bounds)
		{			
            LoadImage(_imgPath);
        }
		public Image (string _imgPath)
            : base()
		{			
            LoadImage(_imgPath);
		}
//		public Image (System.Drawing.Bitmap _bitmap)
//            : base()
//		{
//			_pic = new BmpPicture ();
//
//			LoadImage (_bitmap);
//		}
		#endregion

		#region Image Loading
		public void LoadImage (string path)
		{

			if (path.EndsWith (".svg", true, System.Globalization.CultureInfo.InvariantCulture)) 
				_pic = new SvgPicture ();
			else 
				_pic = new BmpPicture ();

			_pic.LoadImage (path);
		}
		#endregion

		#region GraphicObject overrides
		protected override Size measureRawSize ()
		{
//			if (_pic == null)
//				_pic = "#go.Images.Icons.IconAlerte.svg";

			return _pic.Dimensions + Margin * 2;
		}
		protected override void onDraw (Context gr)
		{
			base.onDraw (gr);

			if (_pic == null)
				return;

			_pic.Paint (gr, ClientRectangle, _svgSub);
		}
		#endregion
	}
}