forked from britzl/extension-imgui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.script
374 lines (314 loc) · 11.2 KB
/
example.script
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
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
local JEDI = { "Luke", "Obi-Wan", "Yoda" }
local SITH = { "Maul", "Vader", "Palpatine" }
local function set_style()
imgui.set_style_window_rounding(6)
imgui.set_style_frame_rounding(3)
imgui.set_style_scrollbar_rounding(10)
imgui.set_style_color(imgui.ImGuiCol_Text, 0.90, 0.90, 0.90, 0.90)
imgui.set_style_color(imgui.ImGuiCol_TextDisabled, 0.60, 0.60, 0.60, 1.00)
imgui.set_style_color(imgui.ImGuiCol_WindowBg, 0.09, 0.09, 0.15, 1.00)
imgui.set_style_color(imgui.ImGuiCol_PopupBg, 0.05, 0.05, 0.10, 0.85)
imgui.set_style_color(imgui.ImGuiCol_Border, 0.70, 0.70, 0.70, 0.65)
imgui.set_style_color(imgui.ImGuiCol_BorderShadow, 0.00, 0.00, 0.00, 0.00)
imgui.set_style_color(imgui.ImGuiCol_FrameBg, 0.00, 0.00, 0.01, 1.00)
imgui.set_style_color(imgui.ImGuiCol_FrameBgHovered, 0.90, 0.80, 0.80, 0.40)
imgui.set_style_color(imgui.ImGuiCol_FrameBgActive, 0.90, 0.65, 0.65, 0.45)
imgui.set_style_color(imgui.ImGuiCol_TitleBg, 0.00, 0.00, 0.00, 0.83)
imgui.set_style_color(imgui.ImGuiCol_TitleBgCollapsed, 0.40, 0.40, 0.80, 0.20)
imgui.set_style_color(imgui.ImGuiCol_TitleBgActive, 0.00, 0.00, 0.00, 0.87)
imgui.set_style_color(imgui.ImGuiCol_MenuBarBg, 0.01, 0.01, 0.02, 0.80)
imgui.set_style_color(imgui.ImGuiCol_ScrollbarBg, 0.20, 0.25, 0.30, 0.60)
imgui.set_style_color(imgui.ImGuiCol_ScrollbarGrab, 0.55, 0.53, 0.55, 0.51)
imgui.set_style_color(imgui.ImGuiCol_ScrollbarGrabHovered, 0.56, 0.56, 0.56, 1.00)
imgui.set_style_color(imgui.ImGuiCol_ScrollbarGrabActive, 0.56, 0.56, 0.56, 0.91)
imgui.set_style_color(imgui.ImGuiCol_CheckMark, 0.90, 0.90, 0.90, 0.83)
imgui.set_style_color(imgui.ImGuiCol_SliderGrab, 0.70, 0.70, 0.70, 0.62)
imgui.set_style_color(imgui.ImGuiCol_SliderGrabActive, 0.30, 0.30, 0.30, 0.84)
imgui.set_style_color(imgui.ImGuiCol_Button, 0.48, 0.72, 0.89, 0.49)
imgui.set_style_color(imgui.ImGuiCol_ButtonHovered, 0.50, 0.69, 0.99, 0.68)
imgui.set_style_color(imgui.ImGuiCol_ButtonActive, 0.80, 0.50, 0.50, 1.00)
imgui.set_style_color(imgui.ImGuiCol_Header, 0.30, 0.69, 1.00, 0.53)
imgui.set_style_color(imgui.ImGuiCol_HeaderHovered, 0.44, 0.61, 0.86, 1.00)
imgui.set_style_color(imgui.ImGuiCol_HeaderActive, 0.38, 0.62, 0.83, 1.00)
imgui.set_style_color(imgui.ImGuiCol_ResizeGrip, 1.00, 1.00, 1.00, 0.85)
imgui.set_style_color(imgui.ImGuiCol_ResizeGripHovered, 1.00, 1.00, 1.00, 0.60)
imgui.set_style_color(imgui.ImGuiCol_ResizeGripActive, 1.00, 1.00, 1.00, 0.90)
imgui.set_style_color(imgui.ImGuiCol_PlotLines, 1.00, 1.00, 1.00, 1.00)
imgui.set_style_color(imgui.ImGuiCol_PlotLinesHovered, 0.90, 0.70, 0.00, 1.00)
imgui.set_style_color(imgui.ImGuiCol_PlotHistogram, 0.90, 0.70, 0.00, 1.00)
imgui.set_style_color(imgui.ImGuiCol_PlotHistogramHovered, 1.00, 0.60, 0.00, 1.00)
imgui.set_style_color(imgui.ImGuiCol_TextSelectedBg, 0.00, 0.00, 1.00, 0.35)
end
local function makeData(self)
self.values_line = {}
self.values_hist = {}
for i=1, 60 do
local data = math.random(1, 30)
self.values_hist[data] = (self.values_hist[data] or 0) + 1
table.insert(self.values_line, data)
end
end
function init(self)
self.counter = 0
self.show_demo_window = false
self.show_close_window = false
self.show_live_data = false
imgui.set_ini_filename()
set_style()
local scale = 2
imgui.scale_all_sizes(scale)
self.values_line = {}
self.values_hist = {}
makeData(self)
local fontsize = 12.0 * scale
local fontsizebase = 12.0 * scale
self.fonts = {}
local regular_data, error = sys.load_resource("/example/bundle/fonts/Montserrat-Regular.ttf")
self.fonts["Regular"] = imgui.font_add_ttf_data(regular_data, #regular_data, fontsize, fontsizebase)
local bold_data, error = sys.load_resource("/example/bundle/fonts/Montserrat-Bold.ttf")
self.fonts["Bold"] = imgui.font_add_ttf_data(bold_data, #bold_data, fontsize, fontsizebase)
local italic_data, error = sys.load_resource("/example/bundle/fonts/Montserrat-Italic.ttf")
self.fonts["Italic"] = imgui.font_add_ttf_data(italic_data, #italic_data, fontsize, fontsizebase)
local bolditalic_data, error = sys.load_resource("/example/bundle/fonts/Montserrat-BoldItalic.ttf")
self.fonts["BoldItalic"] = imgui.font_add_ttf_data(bolditalic_data, #bolditalic_data, fontsize, fontsizebase)
-- Resource based Image
local img1_data, error = sys.load_resource("/example/bundle/images/image1.png")
self.image1 = imgui.image_load_data("image1", img1_data, #img1_data)
-- File based Image can be used on desktop platforms
-- self.image1 = imgui.image_load("example/images/image1.png")
local img2_data, error = sys.load_resource("/example/bundle/images/image2.png")
self.image2 = imgui.image_load_data("image2", img2_data, #img2_data)
end
local function close_window(self)
local flags = imgui.WINDOWFLAGS_NOMOVE
local full, open = imgui.begin_window("Close window", true, flags)
if full then
imgui.text("You can close this window, but cannot move")
end
imgui.end_window()
if not open then
self.show_close_window = false
end
end
local function update_tab1(self)
imgui.text("This is some useful text.")
local changed, checked = imgui.checkbox("Demo window", self.show_demo_window)
if changed then
self.show_demo_window = checked
end
imgui.separator()
if imgui.button("Button") then
self.counter = self.counter + 1
end
imgui.same_line()
imgui.text(("counter = %d"):format(self.counter))
imgui.separator()
local pos = go.get_position("object")
local changed, x, y, z = imgui.input_float3("pos", pos.x, pos.y, pos.z)
if changed then
pos.x = x
pos.y = y
pos.z = z
go.set_position(pos, "object")
end
local changed, x, y, z = imgui.input_int4("posi", pos.x, pos.y, pos.z, 0)
if changed then
pos.x = x
pos.y = y
pos.z = z
go.set_position(pos, "object")
end
local changed, int = imgui.input_int("test int", self.int or 0)
if changed then
self.int = int
end
if imgui.button("open window with close button") then
self.show_close_window = true;
end
imgui.begin_table("table_example", 3)
imgui.table_setup_column("FIRST NAME")
imgui.table_setup_column("LAST NAME")
imgui.table_setup_column("AGE")
imgui.table_headers_row()
imgui.table_next_row()
imgui.table_next_column()
imgui.text("Bilbo")
imgui.table_next_column()
imgui.text("Baggins")
imgui.table_next_column()
imgui.text("129")
imgui.table_next_row()
imgui.table_next_column()
imgui.text("Frodo")
imgui.table_next_column()
imgui.text("Baggins")
imgui.table_next_column()
imgui.text("51")
imgui.end_table()
end
local function update_tab2(self)
local selected = imgui.tree_node("root")
if selected then
imgui.bullet()
self.foo_selected = imgui.selectable("foo", self.foo_selected)
imgui.bullet()
self.bar_selected = imgui.selectable("bar", self.bar_selected)
imgui.tree_pop()
end
-- this is the old way of creating combo boxes
-- it still exists in the ImGUI API since it's a quick way ti create a combo box
local changed, jedi = imgui.combo("Jedi##array", self.selected_jedi or 1, JEDI)
if changed then
self.selected_jedi = jedi
end
-- new way of creating combo boxes with a begin and end function
if imgui.begin_combo("Jedi##selectable", "Select a Jedi") then
for i=1,#JEDI do
if imgui.selectable(JEDI[i], i == (self.selected_jedi or 1)) then
self.selected_jedi = i
end
end
imgui.end_combo()
end
imgui.separator()
local testdbl = self.testdbl or 0
local changed, value = imgui.input_double("test double", testdbl, 0.0001, 0.01, 5)
if changed then
self.testdbl = value
end
local progress = self.progress or 0
local changed, p = imgui.input_float("progress float", progress, 0.01, 1.0, 3)
if changed then
self.progress = p
progress = p
end
imgui.separator()
imgui.draw_progress(progress, -1, 0.0)
imgui.push_id("first")
if imgui.button("Same name") then
pprint("first same button")
end
imgui.pop_id()
imgui.push_id("second")
if imgui.button("Same name") then
pprint("second same button")
end
imgui.pop_id()
end
local function update_tab3(self)
local changed, checked = imgui.checkbox("Live Data", self.show_live_data)
if changed then
self.show_live_data = checked
end
if(self.show_live_data == true) then
makeData(self)
end
imgui.separator()
imgui.text_colored(" Data Plot ", 1, 0, 0, 1 )
imgui.plot_lines( "Data", 0, 150, 40, self.values_line )
imgui.separator()
imgui.text_colored(" Data Histogram ", 0, 1, 0, 1 )
imgui.plot_histogram( "Histogram", 0, 150, 40, self.values_hist )
imgui.separator()
end
-- Example images and font styles
local function update_tab4(self)
imgui.font_push(self.fonts["Regular"])
imgui.text_colored("Example Text Regular", 1, 1, 1, 1 )
imgui.font_pop()
imgui.separator()
imgui.font_push(self.fonts["Bold"])
imgui.text_colored("Example Text Bold", 1, 1, 1, 1 )
imgui.font_pop()
imgui.separator()
imgui.font_push(self.fonts["Italic"])
imgui.text_colored("Example Text Italic", 1, 1, 1, 1 )
imgui.font_pop()
imgui.separator()
imgui.font_push(self.fonts["BoldItalic"])
imgui.text_colored("Example Text Bold Italic", 1, 1, 1, 1 )
imgui.font_pop()
imgui.separator()
imgui.font_push(self.fonts["Regular"])
imgui.text_colored("image stretched", 1, 1, 1, 1 )
imgui.image_add(self.image1, 150,20)
imgui.text_colored("image original aspect", 1, 1, 1, 1 )
imgui.image_add(self.image2, 150,150)
imgui.font_pop()
end
local function update_tab5(self)
if imgui.tree_node("Jedi vs Sith") then
imgui.text("Right click for some info")
for i=1,#JEDI do
imgui.tree_node(JEDI[i], imgui.TREENODE_LEAF + imgui.TREENODE_NO_TREE_PUSH_ON_OPEN)
if imgui.begin_dragdrop_source(imgui.DROPFLAGS_SOURCEALLOWNULLID) then
imgui.set_dragdrop_payload("jedi", JEDI[i])
imgui.end_dragdrop_source()
end
if imgui.begin_popup_context_item("jedipop" .. i) then
imgui.text("This is a Jedi")
imgui.end_popup()
end
end
for i=1,#SITH do
imgui.tree_node(SITH[i], imgui.TREENODE_LEAF + imgui.TREENODE_NO_TREE_PUSH_ON_OPEN)
if imgui.begin_dragdrop_source(imgui.DROPFLAGS_SOURCEALLOWNULLID) then
imgui.set_dragdrop_payload("sith", SITH[i])
imgui.end_dragdrop_source()
end
if imgui.begin_popup_context_item("sithpop" .. i) then
imgui.text("This is a Sith")
imgui.end_popup()
end
end
imgui.tree_pop()
end
imgui.separator()
imgui.text("Drop Jedi and Sith here")
if imgui.begin_dragdrop_target() then
if imgui.accept_dragdrop_payload("jedi") then
self.counter = self.counter + 1
elseif imgui.accept_dragdrop_payload("sith") then
self.counter = self.counter - 1
end
imgui.end_dragdrop_target()
end
imgui.text("Counter " .. self.counter)
end
function update(self, dt)
if self.show_demo_window then
imgui.demo()
end
if self.show_close_window then
close_window(self)
end
imgui.begin_window("Hello, world!")
imgui.begin_tab_bar("tabs")
local tab1_open = imgui.begin_tab_item("Tab1")
if tab1_open then
update_tab1(self)
imgui.end_tab_item()
end
local tab2_open = imgui.begin_tab_item("Tab2")
if tab2_open then
update_tab2(self)
imgui.end_tab_item()
end
local tab3_open = imgui.begin_tab_item("Tab3")
if tab3_open then
update_tab3(self)
imgui.end_tab_item()
end
local tab4_open = imgui.begin_tab_item("Tab4")
if tab4_open then
update_tab4(self)
imgui.end_tab_item()
end
local tab5_open = imgui.begin_tab_item("Tab5")
if tab5_open then
update_tab5(self)
imgui.end_tab_item()
end
imgui.end_tab_bar()
imgui.end_window()
end