-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
UIImage.cs
82 lines (61 loc) · 2.49 KB
/
UIImage.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
using System;
using System.Drawing;
using System.Windows.Forms;
namespace WinForMono {
public class UIImage : UIElement {
// Needed so UIBuilders don't crash on this thing
public UIImage() : this(null) {}
public UIImage(Image i = null) {
if (i == null) {
System.IO.Stream image_stream = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("WinForMono.no_img.png");
i = Image.FromStream(image_stream);
image_stream.Close();
}
derived_underlying = new PictureBox();
derived_underlying.Image = i;
derived_underlying.SizeMode = PictureBoxSizeMode.StretchImage;
image_clicked += () => {};
underlying.Click += (object o, EventArgs e) => { image_clicked.Invoke(); };
CALL_THIS_AFTER_CONSTRUCTION_PLEASE();
}
public void clear_click_events() {
image_clicked = null;
image_clicked += () => {};
}
protected override void on_hover_start(object sender, EventArgs _e) {
base.on_hover_start(sender, _e);
derived_underlying.BackColor = hover_background_colour;
}
protected override void on_hover_end(object sender, EventArgs _e) {
base.on_hover_end(sender, _e);
derived_underlying.BackColor = background_colour;
}
public override Control underlying {
get => (Control)derived_underlying;
set => derived_underlying = (PictureBox)value;
}
private PictureBox derived_underlying;
public Image image {
get => derived_underlying.Image;
set => derived_underlying.Image = value;
}
public Color background_colour {
get => _background_colour;
set {
_background_colour = value;
if (_hover_background_colour == null) _hover_background_colour = value;
if (!hovering) derived_underlying.BackColor = _background_colour;
}
}
private Color _background_colour;
public Color hover_background_colour {
get => _hover_background_colour;
set {
_hover_background_colour = value;
if (hovering) derived_underlying.BackColor = _hover_background_colour;
}
}
private Color _hover_background_colour;
public event Action image_clicked;
}
}