-
Notifications
You must be signed in to change notification settings - Fork 17
/
Program.cs
126 lines (106 loc) · 4.43 KB
/
Program.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
using StereoKit;
using StereoKit.Framework;
class Program
{
static Painting activePainting = new Painting();
static PaletteMenu paletteMenu;
static Pose menuPose = new Pose(0.4f, 0, -0.4f, Quat.LookDir(-1,0,1));
static Sprite appLogo;
static void Main(string[] args)
{
// Initialize StereoKit! During initialization, we can prepare a few
// settings, like the assetsFolder and appName. assetsFolder the
// folder that StereoKit will look for assets in when provided a
// relative folder name. Settings can also be told to make a
// flatscreen app, or how to behave if the preferred initialization
// mode fails.
SKSettings settings = new SKSettings
{
appName = "StereoKit Ink",
assetsFolder = "Assets",
};
if (!SK.Initialize(settings))
return;
// This is a simple radial hand menu where we'll store some quick
// actions! It's activated by a grip motion, and is great for fast,
// gesture-like activation of menu items. It also can be used with
// multiple HandRadialLayers to nest commands in sub-menus.
//
// Steppers are classes that implement the IStepper interface, and
// once added to StereoKit's stepper list, will have their Step
// method called each frame! This is a great way to add fire-and-
// forget objects or systems that need to update each frame.
SK.AddStepper(new HandMenuRadial(
new HandRadialLayer("Root", -90,
new HandMenuItem("Undo", null, ()=>activePainting?.Undo()),
new HandMenuItem("Redo", null, ()=>activePainting?.Redo()))));
// Initialize the palette menu, see PaletteMenu.cs! This class
// manages the palette UI object for manipulating our brush stroke
// size and color.
paletteMenu = new PaletteMenu();
// Load in the app logo as a sprite! We'll draw this at the top of
// the application menu later in this file.
appLogo = Sprite.FromFile("StereoKitInkLight.png");
// Run StereoKit until it receives some sort of reason to quit! This
// callback code will get called every single frame, so you can kinda
// think of this like a while loop.
SK.Run(() =>
{
// Send input information to the painting, it will handle this
// info to create brush strokes. This will also draw the painting
// too!
activePainting.Step(Handed.Right, paletteMenu.PaintColor, paletteMenu.PaintSize);
// Step our palette UI!
paletteMenu.Step();
// Step our application's menu! This includes Save/Load Clear and
// Quit commands.
StepMenuWindow();
});
}
static void StepMenuWindow()
{
// Begin the application's menu window, we'll draw this without a
// head bar (Body only) since we have a nice application image we can
// add instead!
UI.WindowBegin("Menu", ref menuPose, UIWin.Body);
// Just draw the application logo across the top of the Menu window!
// Vec2.Zero here tells StereoKit to auto-size both axes, so this
// will automatically expand to the width of the window.
UI.Image(appLogo, V.XY(UI.LayoutRemaining.x, 0));
// Add undo and redo to the main menu, these are both available on
// the radial menu, but these are easier to discover, and it never
// hurts to have multiple options!
if (UI.Button("Undo")) activePainting?.Undo();
UI.SameLine();
if (UI.Button("Redo")) activePainting?.Redo();
// When the user presses the save button, lets show a save file
// dialog! When a file name and folder have been selected, it'll make
// a call to SavePainting with the file's path name with the .skp
// extension.
if (UI.Button("Save"))
Platform.FilePicker(PickerMode.Save, SavePainting, null, ".skp");
// And on that same line, we'll have a load button! This'll let the
// user pick out any .skp files, and will call LoadPainting with the
// selected file.
UI.SameLine();
if (UI.Button("Load"))
Platform.FilePicker(PickerMode.Open, LoadPainting, null, ".skp");
// Some visual separation
UI.HSeparator();
// Clear is easy! Just create a new Painting object!
if (UI.Button("Clear"))
activePainting = new Painting();
// And if they want to quit? Just tell StereoKit! This will let
// StereoKit finish the the frame properly, and then break out of the
// Step loop above.
UI.SameLine();
if (UI.Button("Quit"))
SK.Quit();
// And end the window!
UI.WindowEnd();
}
static void LoadPainting(string file)
=> activePainting = Painting.FromFile(Platform.ReadFileText(file)??"");
static void SavePainting(string file)
=> Platform.WriteFile(file, activePainting.ToFileData());
}