blob: 61b6e0593b90394e3c346f67bc9c00deecf26c97 (
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
112
113
114
115
|
using System;
using Cairo;
using System.Xml.Serialization;
using System.ComponentModel;
using System.Diagnostics;
namespace Crow
{
public class Image : GraphicObject
{
Picture _pic;
string _svgSub;
bool scaled;
[XmlAttributeAttribute()][DefaultValue(true)]
public virtual bool Scaled {
get { return scaled; }
set {
if (scaled == value)
return;
scaled = value;
NotifyValueChanged ("Scaled", scaled);
if (_pic == null)
return;
_pic.Scaled = scaled;
RegisterForGraphicUpdate ();
}
}
bool keepProps;
[XmlAttributeAttribute()][DefaultValue(true)]
public virtual bool KeepProportions {
get { return keepProps; }
set {
if (keepProps == value)
return;
keepProps = value;
NotifyValueChanged ("KeepProportions", keepProps);
if (_pic == null)
return;
_pic.KeepProportions = keepProps;
RegisterForGraphicUpdate ();
}
}
[XmlAttributeAttribute("Path")]
public string Path {
get { return _pic == null ? null : _pic.Path; }
set {
try {
if (string.IsNullOrEmpty(value)){
_pic = null;
return;
}
LoadImage (value);
_pic.Scaled = scaled;
_pic.KeepProportions = keepProps;
} catch (Exception ex) {
Debug.WriteLine (ex.Message);
_pic = null;
}
}
}
[XmlAttributeAttribute()][DefaultValue(null)]
public string SvgSub {
get { return _svgSub; }
set {
_svgSub = value;
RegisterForGraphicUpdate ();
}
}
#region CTOR
public Image () : base()
{
}
#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);
RegisterForGraphicUpdate ();
RegisterForLayouting (LayoutingType.Sizing);
}
#endregion
#region GraphicObject overrides
protected override int measureRawSize (LayoutingType lt)
{
if (_pic == null)
_pic = "#Crow.Images.Icons.IconAlerte.svg";
//TODO:take scalling in account
if (lt == LayoutingType.Width)
return _pic.Dimensions.Width + 2 * Margin;
else
return _pic.Dimensions.Height + 2 * Margin;
}
protected override void onDraw (Context gr)
{
base.onDraw (gr);
if (_pic == null)
return;
_pic.Paint (gr, ClientRectangle, _svgSub);
}
#endregion
}
}
|