forked from covscript/covscript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
picasso.csp
207 lines (207 loc) · 5.52 KB
/
picasso.csp
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
package picasso
import regex
import imgui
using imgui
struct event
var listeners=new array
function add_listener(func)
listeners.push_front(func)
end
function activate(obj)
foreach func:listeners
if func(obj)
return true
end
end
return false
end
end
struct base_window
var win_opened=false
var win_flags={flags.no_collapse,flags.always_auto_resize}
var title="Picasso Base Window"
function initialize()
end
var on_show=new event
var on_close=new event
function show()
win_opened=true
on_show.activate(this)
end
function is_opened()
return win_opened
end
function on_layout()
end
function on_draw()
end
function render()
begin_window(title,win_opened,win_flags)
if !win_opened
on_close.activate(win_opened)
end
on_layout()
on_draw()
end_window()
end
end
struct base_activity
var title="Picasso Base Activity"
var window_list=new array
var geometry={640,400}
var enable_menu=false
var imgui_app=null
function initialize()
end
var on_start=new event
var on_present=new event
function on_menu_present()
end
function on_close()
end
function add_window(win)
if typeid win!=typeid pointer
throw runtime.exception("Only receive pointer to window.")
end
window_list.push_back(win)
end
function start()
imgui_app=window_application(geometry.at(0),geometry.at(1),title)
on_start.activate(this)
loop
if imgui_app.is_closed()
on_close()
return
end
imgui_app.prepare()
if enable_menu
if begin_main_menu_bar()
on_menu_present()
end_main_menu_bar()
end
end
on_present.activate(this)
foreach it:window_list
if it->is_opened()
it->render()
end
end
imgui_app.render()
end
end
end
struct message_box extends base_window
var message=new string
function on_layout() override
text(message)
end
function on_draw() override
set_window_focus()
spacing()
if button("OK") || is_key_pressed(get_key_index(keys.enter))
this.on_close.activate(null)
this.win_opened=false
end
end
end
struct question_box extends base_window
var question=new string
function on_layout() override
text(question)
end
function on_draw() override
set_window_focus()
spacing()
if button("Yes") || is_key_pressed(to_integer('Y'))
this.on_close.activate(true)
this.win_opened=false
end
same_line()
if button("No") || is_key_pressed(to_integer('N'))
this.on_close.activate(false)
this.win_opened=false
end
end
end
struct file_explorer extends base_window
var path="."
var message=new string
var filters={}
var path_info=null
var path_name=null
var selected=0
function read_path()
if path[path.size()-1]!=system.path.separator
path+=system.path.separator
end
path_info=new array
path_name=new array
var info=system.path.scan(path)
var regs=new array
var files=new array
foreach it:filters
regs.push_back(regex.build(it))
end
foreach it:info
if it.type()==system.path.type.dir
path_info.push_back(it)
else
foreach reg:regs
if !reg.match(it.name()).empty()
files.push_back(it)
end
end
end
end
foreach it:files
path_info.push_back(it)
end
foreach it:path_info
if it.type()==system.path.type.dir
path_name.push_back(to_string(system.path.separator)+it.name())
else
path_name.push_back(it.name())
end
end
end
function on_layout() override
text(message)
separator()
list_box("##dir_list",selected,path_name)
end
function on_draw() override
var info=path_info.at(selected)
if begin_popup_item("dir_list")
if menu_item("Enter","",info.type()==system.path.type.dir)
path+=info.name()
read_path()
selected=0
end
if menu_item("Select","",info.type()!=system.path.type.dir)
this.on_close.activate(path+info.name())
this.win_opened=false
end
end_popup()
end
if is_item_hovered()&&is_mouse_double_clicked(0)
if info.type()==system.path.type.dir
path+=info.name()
read_path()
selected=0
else
this.on_close.activate(path+info.name())
this.win_opened=false
end
end
separator()
if menu_item("Select","",info.type()!=system.path.type.dir)
this.on_close.activate(path+info.name())
this.win_opened=false
end
separator()
if menu_item("Cancel","",true)
this.on_close.activate(null)
this.win_opened=false
end
end
end