MCPcopy Create free account
hub / github.com/SakuraEngine/SakuraEngine / InitializeImgui

Function InitializeImgui

samples/application/chat/main.cpp:163–255  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

161}
162
163int InitializeImgui(Renderer& renderer, skr_vfs_t* vfs)
164{
165 auto renderModule = SkrRendererModule::Get();
166 const auto device = renderer.renderGraph->get_backend_device();
167 const auto backend = device->adapter->instance->backend;
168 const auto gfx_queue = renderer.renderGraph->get_gfx_queue();
169 ImGui::CreateContext();
170 ImGuiIO& io = ImGui::GetIO();
171 io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls
172 io.ConfigFlags |= ImGuiConfigFlags_DockingEnable; // Enable Docking
173 io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable; // Enable Multi-Viewport / Platform Windows
174 ImGui::StyleColorsDark();
175 {
176 auto& style = ImGui::GetStyle();
177 if (ImGui::GetIO().ConfigFlags & ImGuiConfigFlags_ViewportsEnable)
178 {
179 style.WindowRounding = 0.0f;
180 style.Colors[ImGuiCol_WindowBg].w = 1.0f;
181 }
182 const char* font_path = "./../resources/font/SourceSansPro-Regular.ttf";
183 uint8_t* font_bytes;
184 uint32_t font_length;
185 read_bytes(vfs, font_path, &font_bytes, &font_length);
186 float dpi_scaling = 1.f;
187 if (!skr_runtime_is_dpi_aware())
188 {
189 float ddpi;
190 SDL_GetDisplayDPI(0, &ddpi, NULL, NULL);
191 dpi_scaling = ddpi / OS_DPI;
192 // scale back
193 style.ScaleAllSizes(1.f / dpi_scaling);
194 ImGui::GetIO().FontGlobalScale = 1.f / dpi_scaling;
195 }
196 else
197 {
198 float ddpi;
199 SDL_GetDisplayDPI(0, &ddpi, NULL, NULL);
200 dpi_scaling = ddpi / OS_DPI;
201 // scale back
202 style.ScaleAllSizes(dpi_scaling);
203 }
204 ImFontConfig cfg = {};
205 cfg.SizePixels = 16.f * dpi_scaling;
206 cfg.OversampleH = cfg.OversampleV = 1;
207 cfg.PixelSnapH = true;
208 ImGui::GetIO().Fonts->AddFontFromMemoryTTF(font_bytes,
209 font_length, cfg.SizePixels, &cfg);
210 ImGui::GetIO().Fonts->Build();
211 sakura_free(font_bytes);
212 }
213 skr::String vsname = u8"shaders/imgui_vertex";
214 skr::String fsname = u8"shaders/imgui_fragment";
215 vsname.append(backend == ::CGPU_BACKEND_D3D12 ? ".dxil" : ".spv");
216 fsname.append(backend == ::CGPU_BACKEND_D3D12 ? ".dxil" : ".spv");
217
218 uint32_t im_vs_length;
219 uint8_t* im_vs_bytes;
220 read_bytes(vfs, vsname.c_str(), &im_vs_bytes, &im_vs_length);

Callers 2

initializeFunction · 0.85
InitializeMethod · 0.85

Calls 14

GetStyleFunction · 0.85
skr_runtime_is_dpi_awareFunction · 0.85
cgpu_free_shader_libraryFunction · 0.85
get_backend_deviceMethod · 0.80
ScaleAllSizesMethod · 0.80
AddFontFromMemoryTTFMethod · 0.80
read_bytesFunction · 0.70
GetClass · 0.50
BuildMethod · 0.45

Tested by

no test coverage detected