-
Notifications
You must be signed in to change notification settings - Fork 0
/
UK.cs
133 lines (119 loc) · 3.3 KB
/
UK.cs
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
namespace MVC_CountryFlags
{
[Serializable()]
class UK : AnyCountry
{
// constructor
public UK(string countryName, int x_at, int y_at, int flag_width, int flag_height)
: base(countryName, x_at, y_at, flag_width, flag_height)
{
}
// override method to display flag as text
public override string ToString()
{
return "UK: " +
flag_width.ToString() + " cm width, " +
flag_height.ToString() + " cm height at " +
this.Position();
}
// override method to display flag as graphics
public override void Display(Graphics g)
{
if (g != null)
{
Bitmap bitImage = new Bitmap(Properties.Resources.UK);
g.DrawImage(bitImage, x, y, flag_width, flag_height);
}
if (Highlight)
{
// add in border if flag selected
// to define point and size
Point pt = new Point(x + 1, y + 1); // to avoid shadow
int borderSide = flag_width - 2; // make slightly smaller than flag to avoid shadow
int borderTop = flag_height - 2;
Size size = new Size(borderSide, borderTop);
// draw border
Pen p = new Pen(Color.Black, 2);
p.DashStyle = DashStyle.Solid;
g.DrawRectangle(p, new Rectangle(pt, size));
p.Dispose();
}
}
//x_pos of the flag
public override int x_pos //non abstract property
{
get
{
return x;
}
set
{
x = value;
}
}
//y_pos of the flag
public override int y_pos //non abstract property
{
get
{
return y;
}
set
{
y = value;
}
}
//width of the flag
public override int flag_width //non abstract property
{
get
{
return width;
}
set
{
width = value;
}
}
//height of the flag
public override int flag_height //non abstract property
{
get
{
return height;
}
set
{
height = value;
}
}
//name of the flag
public override string name
{
get
{
return countryName;
}
set
{
countryName = value;
}
}
/// <summary> method: HitTest
/// used to create rectangle the same size as the flag if selected
/// </summary>
/// <param name="p"></param>
/// <returns></returns>
public override bool HitTest(Point p)
{
GraphicsPath pth = new GraphicsPath();
pth.AddRectangle(new Rectangle(x, y, width, height));
bool retval = pth.IsVisible(p);
pth.Dispose();
return retval;
}
}
}