-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSampleImageBox.cs
More file actions
282 lines (244 loc) · 9.19 KB
/
SampleImageBox.cs
File metadata and controls
282 lines (244 loc) · 9.19 KB
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
using FishUI;
using FishUI.Controls;
using System;
using System.Numerics;
namespace FishUIDemos
{
/// <summary>
/// Demonstrates ImageBox and AnimatedImageBox controls with various
/// scaling modes, filter modes, and animation features.
/// </summary>
public class SampleImageBox : ISample
{
FishUI.FishUI FUI;
public string Name => "ImageBox";
public TakeScreenshotFunc TakeScreenshot { get; set; }
public FishUI.FishUI CreateUI(FishUISettings UISettings, IFishUIGfx Gfx, IFishUIInput Input, IFishUIEvents Events)
{
FUI = new FishUI.FishUI(UISettings, Gfx, Input, Events);
FUI.Init();
FishUITheme theme = UISettings.LoadTheme(ThemePreferences.LoadThemePath(), applyImmediately: true);
return FUI;
}
public void Init()
{
// === Title ===
Label titleLabel = new Label("ImageBox Demo");
titleLabel.Position = new Vector2(20, 20);
titleLabel.Size = new Vector2(300, 30);
titleLabel.Alignment = Align.Left;
FUI.AddControl(titleLabel);
// Screenshot button
ImageRef iconCamera = FUI.Graphics.LoadImage("data/silk_icons/camera.png");
Button screenshotBtn = new Button();
screenshotBtn.Icon = iconCamera;
screenshotBtn.Position = new Vector2(330, 20);
screenshotBtn.Size = new Vector2(30, 30);
screenshotBtn.IsImageButton = true;
screenshotBtn.TooltipText = "Take a screenshot";
screenshotBtn.OnButtonPressed += (btn, mbtn, pos) => TakeScreenshot?.Invoke(Name);
FUI.AddControl(screenshotBtn);
// ============ ROW 1: ImageBox Scaling/Filter Modes ============
Label imageBoxLabel = new Label("ImageBox Scaling & Filter Modes");
imageBoxLabel.Position = new Vector2(20, 60);
imageBoxLabel.Size = new Vector2(250, 20);
imageBoxLabel.Alignment = Align.Left;
FUI.AddControl(imageBoxLabel);
// Load pixel art image for better filter mode demonstration
ImageRef pixelImage = FUI.Graphics.LoadImage("data/images/win95_pixel.png");
// None - original size, centered
Label noneLabel = new Label("None (Original)");
noneLabel.Position = new Vector2(20, 85);
noneLabel.Size = new Vector2(100, 16);
noneLabel.Alignment = Align.Left;
FUI.AddControl(noneLabel);
ImageBox imgNone = new ImageBox(pixelImage);
imgNone.Position = new Vector2(20, 105);
imgNone.Size = new Vector2(100, 100);
imgNone.ScaleMode = ImageScaleMode.None;
imgNone.TooltipText = "ScaleMode.None - Original size, centered";
FUI.AddControl(imgNone);
// Stretch - fills bounds
Label stretchLabel = new Label("Stretch");
stretchLabel.Position = new Vector2(130, 85);
stretchLabel.Size = new Vector2(100, 16);
stretchLabel.Alignment = Align.Left;
FUI.AddControl(stretchLabel);
ImageBox imgStretch = new ImageBox(pixelImage);
imgStretch.Position = new Vector2(130, 105);
imgStretch.Size = new Vector2(100, 100);
imgStretch.ScaleMode = ImageScaleMode.Stretch;
imgStretch.TooltipText = "ScaleMode.Stretch - Fills bounds";
FUI.AddControl(imgStretch);
// Smooth filter mode
Label smoothLabel = new Label("Smooth Filter");
smoothLabel.Position = new Vector2(240, 85);
smoothLabel.Size = new Vector2(100, 16);
smoothLabel.Alignment = Align.Left;
FUI.AddControl(smoothLabel);
ImageBox imgSmooth = new ImageBox(pixelImage);
imgSmooth.Position = new Vector2(240, 105);
imgSmooth.Size = new Vector2(100, 100);
imgSmooth.ScaleMode = ImageScaleMode.Stretch;
imgSmooth.FilterMode = ImageFilterMode.Smooth;
imgSmooth.TooltipText = "FilterMode.Smooth - Bilinear filtering";
FUI.AddControl(imgSmooth);
// Pixelated filter mode (best for pixel art)
Label pixelLabel = new Label("Pixelated Filter");
pixelLabel.Position = new Vector2(350, 85);
pixelLabel.Size = new Vector2(100, 16);
pixelLabel.Alignment = Align.Left;
FUI.AddControl(pixelLabel);
ImageBox imgPixelated = new ImageBox(pixelImage);
imgPixelated.Position = new Vector2(350, 105);
imgPixelated.Size = new Vector2(100, 100);
imgPixelated.ScaleMode = ImageScaleMode.Stretch;
imgPixelated.FilterMode = ImageFilterMode.Pixelated;
imgPixelated.TooltipText = "FilterMode.Pixelated - Nearest-neighbor (pixel art)";
FUI.AddControl(imgPixelated);
// Clickable ImageBox
Label clickLabel = new Label("Clickable");
clickLabel.Position = new Vector2(460, 85);
clickLabel.Size = new Vector2(100, 16);
clickLabel.Alignment = Align.Left;
FUI.AddControl(clickLabel);
Label clickCountLabel = new Label("Clicks: 0");
clickCountLabel.Position = new Vector2(570, 130);
clickCountLabel.Size = new Vector2(80, 20);
clickCountLabel.Alignment = Align.Left;
FUI.AddControl(clickCountLabel);
int clickCount = 0;
ImageBox imgClickable = new ImageBox(pixelImage);
imgClickable.Position = new Vector2(460, 105);
imgClickable.Size = new Vector2(100, 100);
imgClickable.ScaleMode = ImageScaleMode.Stretch;
imgClickable.FilterMode = ImageFilterMode.Pixelated;
imgClickable.TooltipText = "Click me!";
imgClickable.OnClick += (sender, btn, pos) =>
{
clickCount++;
clickCountLabel.Text = $"Clicks: {clickCount}";
};
FUI.AddControl(imgClickable);
// ============ ROW 2: AnimatedImageBox ============
Label animLabel = new Label("AnimatedImageBox");
animLabel.Position = new Vector2(20, 220);
animLabel.Size = new Vector2(150, 20);
animLabel.Alignment = Align.Left;
FUI.AddControl(animLabel);
// Load stargate animation frames
AnimatedImageBox stargateAnim = new AnimatedImageBox();
stargateAnim.Position = new Vector2(20, 245);
stargateAnim.Size = new Vector2(120, 120);
stargateAnim.ScaleMode = ImageScaleMode.Fit;
stargateAnim.FrameRate = 10f;
stargateAnim.Loop = true;
stargateAnim.TooltipText = "Stargate animation (10 FPS, looping)";
for (int i = 0; i <= 27; i++)
{
string framePath = $"data/anim_images/stargate/frame_{i:D2}_delay-0.1s.png";
ImageRef frame = FUI.Graphics.LoadImage(framePath);
if (frame != null)
stargateAnim.AddFrame(frame);
}
FUI.AddControl(stargateAnim);
// Animation controls
Button animPlayPause = new Button();
animPlayPause.Text = "Pause";
animPlayPause.Position = new Vector2(150, 245);
animPlayPause.Size = new Vector2(70, 25);
animPlayPause.OnButtonPressed += (btn, mbtn, pos) =>
{
if (stargateAnim.IsPlaying)
{
stargateAnim.Pause();
animPlayPause.Text = "Play";
}
else
{
stargateAnim.Play();
animPlayPause.Text = "Pause";
}
};
FUI.AddControl(animPlayPause);
Button animStop = new Button();
animStop.Text = "Stop";
animStop.Position = new Vector2(150, 275);
animStop.Size = new Vector2(70, 25);
animStop.OnButtonPressed += (btn, mbtn, pos) =>
{
stargateAnim.Stop();
animPlayPause.Text = "Play";
};
FUI.AddControl(animStop);
Label fpsLabel = new Label("FPS:");
fpsLabel.Position = new Vector2(150, 310);
fpsLabel.Size = new Vector2(30, 16);
fpsLabel.Alignment = Align.Left;
FUI.AddControl(fpsLabel);
Slider fpsSlider = new Slider();
fpsSlider.Position = new Vector2(180, 310);
fpsSlider.Size = new Vector2(80, 20);
fpsSlider.MinValue = 1;
fpsSlider.MaxValue = 30;
fpsSlider.Value = 10;
fpsSlider.Step = 1;
fpsSlider.ShowValueLabel = true;
fpsSlider.TooltipText = "Adjust animation frame rate";
fpsSlider.OnValueChanged += (slider, val) =>
{
stargateAnim.FrameRate = val;
};
FUI.AddControl(fpsSlider);
CheckBox pingPongCheck = new CheckBox("Ping-Pong");
pingPongCheck.Position = new Vector2(150, 340);
pingPongCheck.Size = new Vector2(15, 15);
pingPongCheck.IsChecked = false;
FUI.AddControl(pingPongCheck);
Button pingPongBtn = new Button();
pingPongBtn.Text = "Toggle";
pingPongBtn.Position = new Vector2(240, 338);
pingPongBtn.Size = new Vector2(50, 20);
pingPongBtn.OnButtonPressed += (btn, mbtn, pos) =>
{
stargateAnim.PingPong = !stargateAnim.PingPong;
pingPongCheck.IsChecked = stargateAnim.PingPong;
};
FUI.AddControl(pingPongBtn);
// ============ Animation Viewer Window ============
Window videoWindow = new Window();
videoWindow.Title = "Animation Viewer";
videoWindow.Position = new Vector2(350, 220);
videoWindow.Size = new Vector2(280, 180);
videoWindow.ShowCloseButton = true;
videoWindow.OnClosed += (wnd) => { wnd.Visible = false; };
FUI.AddControl(videoWindow);
AnimatedImageBox videoAnim = new AnimatedImageBox();
videoAnim.Position = new Vector2(5, 5);
videoAnim.Size = new Vector2(270, 145);
videoAnim.Anchor = FishUIAnchor.All;
videoAnim.ScaleMode = ImageScaleMode.Fit;
videoAnim.FrameRate = 10f;
videoAnim.Loop = true;
for (int j = 0; j <= 27; j++)
{
string vframePath = $"data/anim_images/stargate/frame_{j:D2}_delay-0.1s.png";
ImageRef vframe = FUI.Graphics.LoadImage(vframePath);
if (vframe != null)
videoAnim.AddFrame(vframe);
}
videoWindow.AddChild(videoAnim);
Button showVideoBtn = new Button();
showVideoBtn.Text = "Show Viewer";
showVideoBtn.Position = new Vector2(20, 375);
showVideoBtn.Size = new Vector2(100, 25);
showVideoBtn.TooltipText = "Show resizable animation viewer window";
showVideoBtn.OnButtonPressed += (btn, mbtn, pos) =>
{
videoWindow.Visible = true;
videoWindow.BringToFront();
};
FUI.AddControl(showVideoBtn);
}
}
}