1+ import os
2+
3+ # core
4+ import pilotlight .pilotlight as pl
5+ from pilotlight .pilotlight import *
6+ from pilotlight .imgui import *
7+ from pilotlight .enums import *
8+ from pilotlight .types import *
9+
10+ def show_example_menu_file ():
11+ static = show_example_menu_file
12+
13+ ImGui_MenuItem ("(demo menu)" , "" , False , False )
14+ if ImGui_MenuItem ("New" ):
15+ pass
16+ if ImGui_MenuItem ("Open" , "Ctrl+O" ):
17+ pass
18+ if ImGui_BeginMenu ("Open Recent" ):
19+ ImGui_MenuItem ("Hello" )
20+ ImGui_MenuItem ("Sailor" )
21+ if ImGui_BeginMenu ("Recurse.." ):
22+ show_example_menu_file ()
23+ ImGui_EndMenu ()
24+ ImGui_EndMenu ()
25+ if ImGui_MenuItem ("Save" , "Ctrl+S" ):
26+ pass
27+ if ImGui_MenuItem ("Save As.." ):
28+ pass
29+ ImGui_Separator ()
30+ if ImGui_BeginMenu ("Options" ):
31+ if not hasattr (static , "enabled" ):
32+ static .enabled = True
33+ _ , static .enabled = ImGui_MenuItem ("Enabled" , "" , static .enabled )
34+ ImGui_BeginChild ("child" , (0 , 60 ), ImGuiChildFlags .Borders )
35+ for i in range (0 , 10 ):
36+ ImGui_Text ("Scrolling Text %d" % i )
37+ ImGui_EndChild ()
38+ if not hasattr (static , "f" ):
39+ static .f = pl_create_float_pointer ()
40+ static .n = pl_create_int_pointer ()
41+ ImGui_SliderFloat ("Value" , static .f , 0.0 , 1.0 )
42+ ImGui_InputFloat ("Input" , static .f , 0.1 )
43+ items = ["Yes" , "No" , "Maybe" ]
44+ ImGui_Combo ("Combo" , static .n , items )
45+ ImGui_EndMenu ()
46+
47+ class App :
48+
49+ def __init__ (self ):
50+ self .ptWindow = None
51+ self .show_imgui_demo = None
52+ self .show_implot_demo = None
53+ self .some_string_array = bytearray ("pizza" , 'utf-8' )
54+ self .some_string_array .resize (256 )
55+
56+ def pl_app_load (self ):
57+
58+ self .show_imgui_demo = pl_create_bool_pointer ()
59+ self .show_implot_demo = pl_create_bool_pointer ()
60+
61+ pl_vfs_mount_directory ("/cache" , "cache" )
62+ pl_vfs_mount_directory ("/shaders" , os .path .dirname (os .path .abspath (pl .__file__ )) + "/shaders" )
63+ pl_vfs_mount_directory ("/shader-temp" , "shader-temp" )
64+
65+ self .ptWindow = pl_window_create ("Demo" , 200 , 200 , 500 , 500 , 0 )
66+ pl_window_show (self .ptWindow )
67+
68+ starter_flags = plStarterFlag .PL_STARTER_FLAGS_ALL_EXTENSIONS
69+ starter_flags |= plStarterFlag .PL_STARTER_FLAGS_MSAA
70+ starter_flags &= ~ plStarterFlag .PL_STARTER_FLAGS_SHADER_EXT
71+ pl_starter_initialize (self .ptWindow , starter_flags )
72+
73+ shader_options = plShaderOptions ()
74+ shader_options .pcCacheOutputDirectory = "/shader-temp/"
75+ shader_options .apcDirectories = ["/shaders/" ]
76+ shader_options .apcIncludeDirectories = ["/shaders/" ]
77+ shader_options .tFlags = plShaderFlags .PL_SHADER_FLAGS_AUTO_OUTPUT | plShaderFlags .PL_SHADER_FLAGS_INCLUDE_DEBUG | plShaderFlags .PL_SHADER_FLAGS_ALWAYS_COMPILE
78+ pl_shader_initialize (shader_options )
79+
80+ pl_starter_finalize ()
81+ pl_dear_imgui_initialize (pl_starter_get_device (), pl_starter_get_swapchain (), pl_starter_get_render_pass ())
82+ pl_shader_variant_initialize (pl_starter_get_device ())
83+
84+ ImGui_StyleColorsDark ()
85+
86+
87+ def pl_app_shutdown (self ):
88+ pl_graphics_flush_device (pl_starter_get_device ())
89+ pl_dear_imgui_cleanup ()
90+ pl_starter_cleanup ()
91+ pl_window_destroy (self .ptWindow )
92+
93+ def pl_app_resize (self ):
94+ pl_starter_resize ()
95+
96+ def pl_app_update (self ):
97+
98+
99+ if not pl_starter_begin_frame ():
100+ return
101+
102+ pl_dear_imgui_new_frame (pl_starter_get_device (), pl_starter_get_render_pass ())
103+
104+ if pl_get_pointer_value (self .show_imgui_demo ):
105+ ImGui_ShowDemoWindow (self .show_imgui_demo )
106+
107+ if pl_get_pointer_value (self .show_implot_demo ):
108+ ImPlot_ShowDemoWindow (self .show_implot_demo )
109+
110+ # dear imgui API
111+ if ImGui_BeginMainMenuBar ():
112+ if ImGui_BeginMenu ("File" ):
113+ ImGui_EndMenu ()
114+ if ImGui_BeginMenu ("Edit" , False ):
115+ ImGui_EndMenu ()
116+ if ImGui_BeginMenu ("Tools" ):
117+ ImGui_MenuItem ("Show ImGui Demo" , selected_pointer = self .show_imgui_demo )
118+ ImGui_MenuItem ("Show ImPlot Demo" , selected_pointer = self .show_implot_demo )
119+ ImGui_EndMenu ()
120+ if ImGui_BeginMenu ("Help" ):
121+ ImGui_MenuItem ("Check For Update" )
122+ ImGui_MenuItem ("About" , "-a" )
123+ ImGui_EndMenu ()
124+ ImGui_EndMainMenuBar ()
125+
126+
127+ if ImGui_Begin ("Dear ImGui Demo" , None , ImGuiWindowFlags .MenuBar ):
128+ if ImGui_BeginMenuBar ():
129+ if ImGui_BeginMenu ("Menu" ):
130+ show_example_menu_file ()
131+ ImGui_EndMenu ()
132+ ImGui_EndMenuBar ()
133+ ImGui_End ()
134+
135+
136+ render_encoder = pl_starter_begin_main_pass ()
137+
138+ pl_dear_imgui_render (render_encoder )
139+
140+ pl_starter_end_main_pass ()
141+
142+ pl_starter_end_frame ()
143+
144+ # run app
145+ pl_run (App ())
0 commit comments