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
|
// Copyright (c) 2013-2021 Bruyère Jean-Philippe <jp_bruyere@hotmail.com>
//
// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
using System;
using Crow;
using System.IO;
using System.Text;
using Crow.IML;
using System.Runtime.CompilerServices;
using Glfw;
using System.Diagnostics;
using Crow.Text;
using System.Collections.Generic;
using Encoding = System.Text.Encoding;
using Samples;
namespace ShowCase
{
class Showcase : SampleBaseForEditor
{
DbgEvtType[] logEvts = {
DbgEvtType.MouseEnter,
DbgEvtType.MouseLeave,
DbgEvtType.WidgetMouseDown,
DbgEvtType.WidgetMouseUp,
DbgEvtType.WidgetMouseClick,
};
static void Main ()
{
initDebugLog ();
Environment.SetEnvironmentVariable ("FONTCONFIG_PATH", @"C:\Users\Jean-Philippe\source\vcpkg\installed\x64-windows\tools\fontconfig\fonts");
using (Showcase app = new Showcase ()) {
app.WindowTitle = "C.R.O.W Showcase";
app.SetWindowIcon ("#Crow.Icons.crow.png");
//app.Theme = @"C:\Users\Jean-Philippe\source\Crow\Themes\TestTheme";
CurrentProgramInstance = app;
app.Run ();
}
}
public Container crowContainer;
Stopwatch reloadChrono = new Stopwatch ();
public override string Source {
get => source;
set {
if (source == value)
return;
source = value;
CMDSave.CanExecute = IsDirty;
if (!reloadChrono.IsRunning)
reloadChrono.Restart ();
NotifyValueChanged (source);
NotifyValueChanged ("IsDirty", IsDirty);
}
}
void reloadFromSource () {
hideError ();
Widget g = null;
try {
lock (UpdateMutex) {
Instantiator inst = null;
using (MemoryStream ms = new MemoryStream (Encoding.UTF8.GetBytes (source)))
inst = new Instantiator (this, ms);
g = inst.CreateInstance ();
crowContainer.SetChild (g);
g.DataSource = this;
}
} catch (InstantiatorException itorex) {
showError (itorex);
} catch (Exception ex) {
showError (ex);
}
}
void showError (Exception ex) {
Console.WriteLine (ex);
NotifyValueChanged ("ErrorMessage", ex);
NotifyValueChanged ("ShowError", true);
}
void hideError () {
NotifyValueChanged ("ShowError", false);
}
protected override void OnInitialized () {
base.OnInitialized ();
Load ("#ShowCase.showcase.crow").DataSource = this;
crowContainer = FindByName ("CrowContainer") as Container;
editor = FindByName ("tb") as TextBox;
if (!File.Exists (CurrentFile))
newFile ();
//I set an empty object as datasource at this level to force update when new
//widgets are added to the interface
crowContainer.DataSource = new object ();
hideError ();
reloadFromFile ();
}
public override void UpdateFrame () {
base.UpdateFrame ();
if (reloadChrono.ElapsedMilliseconds < 200)
return;
reloadFromSource ();
reloadChrono.Reset ();
}
public override bool OnKeyDown (KeyEventArgs e) {
switch (e.Key) {
case Key.F5:
Load ("#ShowCase.DebugLog.crow").DataSource = this;
return true;
case Key.F6:
if (DebugLogRecording) {
DbgLogger.IncludedEvents.Clear();
if (DebugLogToFile && !string.IsNullOrEmpty(DebugLogFilePath))
DbgLogger.Save (this, DebugLogFilePath);
DebugLogRecording = false;
} else {
DbgLogger.Reset ();
DbgLogger.IncludedEvents = new List<DbgEvtType> (logEvts);
DebugLogRecording = true;
}
return true;
}
return base.OnKeyDown (e);
}
}
}
|