99#include " imgui_internal.h"
1010#include " material_symbols.cpp"
1111
12-
1312extern LRESULT CALLBACK wnd_proc (HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam);
1413
1514void App::applyAviutl2Style ()
1615{
1716 auto aulColor2imVec4 = [this ](const std::string& name) -> ImVec4 {
18- if (!config_handle ) return {};
19- auto rgb = config_handle ->get_color_code (config_handle , name.c_str ());
17+ if (!m_config_handle ) return {};
18+ auto rgb = m_config_handle ->get_color_code (m_config_handle , name.c_str ());
2019 float inv_255 = 1 .0f / 255 .0f ;
2120 float r = static_cast <float >((rgb >> 16 ) & 0xFF ) * inv_255;
2221 float g = static_cast <float >((rgb >> 8 ) & 0xFF ) * inv_255;
@@ -96,20 +95,20 @@ void App::run(std::promise<HWND>&& hwnd_promise)
9695 float main_scale = ImGui_ImplWin32_GetDpiScaleForMonitor (::MonitorFromPoint (POINT {0 , 0 }, MONITOR_DEFAULTTOPRIMARY ));
9796
9897 // ウィンドウの作成
99- if (!g_app. window_manager .createPluginWindow (WINDOW_NAME , main_scale, wnd_proc)) {
98+ if (!m_window_manager .createPluginWindow (WINDOW_NAME , main_scale, wnd_proc)) {
10099 hwnd_promise.set_exception (std::make_exception_ptr (std::runtime_error (" Failed to create window" )));
101100 return ;
102101 }
103102
104- HWND hwnd = g_app. window_manager .getWindowHandle ();
103+ HWND hwnd = m_window_manager .getWindowHandle ();
105104 hwnd_promise.set_value (hwnd);
106105
107106 //
108107 // D3D の初期化
109108 //
110- if (!g_app. d3d_manager .initialize (hwnd)) {
111- g_app. d3d_manager .cleanup ();
112- g_app. window_manager .unregisterClass ();
109+ if (!m_d3d_manager .initialize (hwnd)) {
110+ m_d3d_manager .cleanup ();
111+ m_window_manager .unregisterClass ();
113112 return ;
114113 }
115114
@@ -122,15 +121,7 @@ void App::run(std::promise<HWND>&& hwnd_promise)
122121 io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard | ImGuiConfigFlags_DockingEnable | ImGuiConfigFlags_ViewportsEnable;
123122
124123 ImGui::StyleColorsDark ();
125- ImGuiStyle& style = ImGui::GetStyle ();
126- style.FrameRounding = Scale::Absolute::FRAME_ROUNDING ;
127- style.GrabMinSize = Scale::Absolute::GRAB_MIN_SIZE ;
128- style.FrameBorderSize = Scale::Absolute::FRAME_BORDER_SIZE ;
129- style.TabRounding = Scale::Absolute::TAB_ROUNDING ;
130- style.DockingSeparatorSize = Scale::Absolute::DOCKING_SEPARATOR_SIZE ;
131- style.ItemSpacing = ImVec2 (Scale::Absolute::ITEM_SPACING_X , Scale::Absolute::ITEM_SPACING_Y );
132- style.ItemInnerSpacing = ImVec2 (Scale::Absolute::ITEM_INNER_SPACING_X , style.ItemInnerSpacing .y );
133- style.ScrollbarRounding = Scale::Absolute::SCROLLBAR_ROUNDING ;
124+ ImGuiStyle& style = ImGui::GetStyle ();
134125
135126 style.ScaleAllSizes (main_scale);
136127 style.FontScaleDpi = main_scale;
@@ -145,10 +136,10 @@ void App::run(std::promise<HWND>&& hwnd_promise)
145136 // imgui.ini を自動生成しないようにする
146137 io.IniFilename = nullptr ;
147138 readSettings (); // 設定を読み込む
148- style.FontScaleMain = g_app. settings .ui_scale / 100 .0f ;
139+ style.FontScaleMain = m_settings .ui_scale / 100 .0f ;
149140
150141 ImGui_ImplWin32_Init (hwnd);
151- ImGui_ImplDX11_Init (g_app. d3d_manager . getDevice ().Get (), g_app. d3d_manager .getDeviceContext ().Get ());
142+ ImGui_ImplDX11_Init (m_d3d_manager. getDevice ().Get (), m_d3d_manager .getDeviceContext ().Get ());
152143
153144 //
154145 // フォントの設定
@@ -158,7 +149,7 @@ void App::run(std::promise<HWND>&& hwnd_promise)
158149 config1.GlyphExcludeRanges = exclude_ranges;
159150
160151 // sytle.conf からフォント名を取得
161- FONT_INFO * font_info = g_app. config_handle ->get_font_info (g_app. config_handle , " DefaultFamily" );
152+ FONT_INFO * font_info = m_config_handle ->get_font_info (m_config_handle , " DefaultFamily" );
162153 // フォント名からフォントデータを取得
163154 auto font_data = getFontDataByName (font_info->name );
164155
@@ -195,24 +186,31 @@ void App::run(std::promise<HWND>&& hwnd_promise)
195186 //
196187 applyAviutl2Style ();
197188
189+ style.FrameRounding = Scale::Absolute::FRAME_ROUNDING ;
190+ style.GrabMinSize = Scale::Absolute::GRAB_MIN_SIZE ;
191+ style.FrameBorderSize = Scale::Absolute::FRAME_BORDER_SIZE ;
192+ style.TabRounding = Scale::Absolute::TAB_ROUNDING ;
193+ style.DockingSeparatorSize = Scale::Absolute::DOCKING_SEPARATOR_SIZE ;
194+ style.ScrollbarRounding = Scale::Absolute::SCROLLBAR_ROUNDING ;
195+
198196 //
199197 // グラデーションエディター用の D3D を初期化
200198 //
201- custom_ui::initDX11 (g_app. d3d_manager . getDevice (), g_app. d3d_manager .getDeviceContext ());
199+ custom_ui::initDX11 (m_d3d_manager. getDevice (), m_d3d_manager .getDeviceContext ());
202200
203201 ::ShowWindow (hwnd, SW_SHOWDEFAULT );
204202 ::UpdateWindow (hwnd);
205203
206204 // メインビューの初期化
207205 m_main_view = std::make_unique<MainView>(
208- get_logger_wrapper_interface (g_app. log_handle ),
209- get_config_wrapper_interface (g_app. config_handle ));
206+ get_logger_wrapper_interface (m_log_handle ),
207+ get_config_wrapper_interface (m_config_handle ));
210208
211- m_main_view->setWindowVisible ({static_cast <bool >(g_app. settings .preset_tab ),
212- static_cast <bool >(g_app. settings .history_tab )});
209+ m_main_view->setWindowVisible ({static_cast <bool >(m_settings .preset_tab ),
210+ static_cast <bool >(m_settings .history_tab )});
213211
214212 // WM_SIZE で ImGui のレンダリング処理を呼び出すために保存する
215- g_app. render = [this ]() {
213+ m_render = [this ]() {
216214 renderFrame ();
217215 };
218216
@@ -228,7 +226,7 @@ void App::run(std::promise<HWND>&& hwnd_promise)
228226 if (done) break ;
229227
230228 // ウィンドウの表示状態を取得する
231- g_app. is_window_visible = (::IsWindowVisible (g_app. window_manager .getWindowHandle ()) != 0 );
229+ m_is_window_visible = (::IsWindowVisible (m_window_manager .getWindowHandle ()) != 0 );
232230
233231 renderFrame ();
234232 }
@@ -237,18 +235,18 @@ void App::run(std::promise<HWND>&& hwnd_promise)
237235void App::renderFrame ()
238236{
239237 static bool was_visible = true ;
240- bool is_visible = g_app. is_window_visible ;
238+ bool is_visible = m_is_window_visible ;
241239 bool just_hidden = (was_visible && !is_visible);
242240 was_visible = is_visible;
243241
244242 // 非表示になった瞬間だけはオクルージョン判定を無視
245- if (!just_hidden && g_app. d3d_manager . isSwapChainOccluded () && g_app. d3d_manager .getSwapChain ()->Present (0 , DXGI_PRESENT_TEST ) == DXGI_STATUS_OCCLUDED ) {
243+ if (!just_hidden && m_d3d_manager. isSwapChainOccluded () && m_d3d_manager .getSwapChain ()->Present (0 , DXGI_PRESENT_TEST ) == DXGI_STATUS_OCCLUDED ) {
246244 ::Sleep (10 );
247245 return ;
248246 }
249247
250- g_app. d3d_manager .setSwapChainOccluded (false );
251- g_app. d3d_manager .handleWindowResize ();
248+ m_d3d_manager .setSwapChainOccluded (false );
249+ m_d3d_manager .handleWindowResize ();
252250
253251 // 再入を防ぐ(WM_SIZE 等で renderFrame が再帰的に呼ばれる可能性がある)
254252 static thread_local bool s_in_render = false ;
@@ -282,18 +280,23 @@ void App::renderFrame()
282280 ImGui::ClosePopupsOverWindow (nullptr , false );
283281 }
284282
283+ // 相対スケールを適用
284+ ImGuiStyle& style = ImGui::GetStyle ();
285+ style.ItemSpacing = ImVec2 (ImGui::GetFrameHeight () * Scale::Relative::ITEM_SPACING_X , ImGui::GetFrameHeight () * Scale::Relative::ITEM_SPACING_Y );
286+ style.ItemInnerSpacing = ImVec2 (ImGui::GetFrameHeight () * Scale::Relative::ITEM_INNER_SPACING_X , style.ItemInnerSpacing .y );
287+
285288 // 非表示の時でもウィンドウ等の状態を維持するために描画処理を呼び出す
286289 m_main_view->render ();
287290
288291 ImGui::Render ();
289292
290- ImVec4 clear_color = color_conv::u32Rgb2Vec4Rgba<ImVec4>(g_app. config_handle ->get_color_code (g_app. config_handle , " Background" ));
293+ ImVec4 clear_color = color_conv::u32Rgb2Vec4Rgba<ImVec4>(m_config_handle ->get_color_code (m_config_handle , " Background" ));
291294 const float clear_color_with_alpha[4 ] = {clear_color.x * clear_color.w , clear_color.y * clear_color.w , clear_color.z * clear_color.w , clear_color.w };
292295
293- auto rtv = g_app. d3d_manager .getRenderTargetView ();
296+ auto rtv = m_d3d_manager .getRenderTargetView ();
294297 if (rtv) {
295- g_app. d3d_manager .getDeviceContext ()->OMSetRenderTargets (1 , rtv.GetAddressOf (), nullptr );
296- g_app. d3d_manager .getDeviceContext ()->ClearRenderTargetView (rtv.Get (), clear_color_with_alpha);
298+ m_d3d_manager .getDeviceContext ()->OMSetRenderTargets (1 , rtv.GetAddressOf (), nullptr );
299+ m_d3d_manager .getDeviceContext ()->ClearRenderTargetView (rtv.Get (), clear_color_with_alpha);
297300 }
298301
299302 ImGui_ImplDX11_RenderDrawData (ImGui::GetDrawData ());
@@ -303,8 +306,8 @@ void App::renderFrame()
303306 ImGui::RenderPlatformWindowsDefault ();
304307 }
305308
306- HRESULT hr = g_app. d3d_manager .getSwapChain ()->Present (1 , 0 );
307- g_app. d3d_manager .setSwapChainOccluded (hr == DXGI_STATUS_OCCLUDED );
309+ HRESULT hr = m_d3d_manager .getSwapChain ()->Present (1 , 0 );
310+ m_d3d_manager .setSwapChainOccluded (hr == DXGI_STATUS_OCCLUDED );
308311
309312 // 再入フラグを解除
310313 s_in_render = false ;
@@ -314,14 +317,14 @@ void App::cleanup()
314317{
315318 // タブの表示状態を保存
316319 auto visible = m_main_view->getWindowVisible ();
317- g_app. settings .preset_tab = static_cast <uint32_t >(visible.preset_window );
318- g_app. settings .history_tab = static_cast <uint32_t >(visible.history_window );
320+ m_settings .preset_tab = static_cast <uint32_t >(visible.preset_window );
321+ m_settings .history_tab = static_cast <uint32_t >(visible.history_window );
319322
320323 writeSettings (); // ウィンドウのレイアウト等の設定をファイルに書き込む
321324 m_main_view.get ()->writeHistories (); // グラデーションの履歴をファイルに書き込む
322325
323326 // ビューを解放
324- g_app. render = nullptr ;
327+ m_render = nullptr ;
325328 m_main_view.reset ();
326329 custom_ui::cleanup ();
327330
@@ -331,17 +334,17 @@ void App::cleanup()
331334 ImGui::DestroyContext ();
332335
333336 // グラデーション描画用の D3D を解放
334- g_app. d3d_manager .cleanup ();
337+ m_d3d_manager .cleanup ();
335338
336339 // WM_QUIT を App::run() 内のメッセージループに通知
337- HWND hwnd = window_manager .getWindowHandle ();
340+ HWND hwnd = m_window_manager .getWindowHandle ();
338341 if (hwnd) {
339342 ::PostMessage (hwnd, WM_QUIT , 0 , 0 );
340343 }
341344
342345 // GUI スレッドを停止
343- if (gui_thread .joinable ()) {
344- gui_thread .join ();
346+ if (m_gui_thread .joinable ()) {
347+ m_gui_thread .join ();
345348 }
346349}
347350
@@ -362,15 +365,15 @@ void App::readSettings()
362365 };
363366
364367 // 設定ファイル全体を読み込む
365- std::ifstream ifs (g_app. settings_file_path );
368+ std::ifstream ifs (m_settings_file_path );
366369 std::string settings_content ((std::istreambuf_iterator<char >(ifs)), std::istreambuf_iterator<char >());
367370
368- auto ui_scale = getConfigInt (g_app. settings_file_path , " settings" , " ui_scale" , 100 );
369- g_app. settings .ui_scale = std::clamp (ui_scale, 50u , 400u );
370- auto preset_tab = getConfigInt (g_app. settings_file_path , " settings" , " preset_tab" , 0 );
371- g_app. settings .preset_tab = std::clamp (preset_tab, 0u , 1u );
372- auto history_tab = getConfigInt (g_app. settings_file_path , " settings" , " history_tab" , 0 );
373- g_app. settings .history_tab = std::clamp (history_tab, 0u , 1u );
371+ auto ui_scale = getConfigInt (m_settings_file_path , " settings" , " ui_scale" , 100 );
372+ m_settings .ui_scale = std::clamp (ui_scale, 50u , 400u );
373+ auto preset_tab = getConfigInt (m_settings_file_path , " settings" , " preset_tab" , 0 );
374+ m_settings .preset_tab = std::clamp (preset_tab, 0u , 1u );
375+ auto history_tab = getConfigInt (m_settings_file_path , " settings" , " history_tab" , 0 );
376+ m_settings .history_tab = std::clamp (history_tab, 0u , 1u );
374377
375378 // [imgui] セクション以下全体を抽出
376379 size_t imgui_start = settings_content.find (" [imgui]" );
@@ -393,7 +396,7 @@ void App::readSettings()
393396void App::writeSettings ()
394397{
395398 {
396- std::ofstream ofs (g_app. settings_file_path );
399+ std::ofstream ofs (m_settings_file_path );
397400 ofs.clear ();
398401 }
399402
@@ -405,15 +408,15 @@ void App::writeSettings()
405408 // 再書き込み
406409 std::string settings_data_str{};
407410 settings_data_str += " [settings]\n " ;
408- settings_data_str += std::format (" ui_scale={}\n " , g_app. settings .ui_scale );
409- settings_data_str += std::format (" preset_tab={}\n " , g_app. settings .preset_tab );
410- settings_data_str += std::format (" history_tab={}\n " , g_app. settings .history_tab );
411+ settings_data_str += std::format (" ui_scale={}\n " , m_settings .ui_scale );
412+ settings_data_str += std::format (" preset_tab={}\n " , m_settings .preset_tab );
413+ settings_data_str += std::format (" history_tab={}\n " , m_settings .history_tab );
411414
412415 settings_data_str += " \n " ;
413416
414417 settings_data_str += " [imgui]\n " ;
415418 settings_data_str += imgui_data_str;
416- std::ofstream ofs (g_app. settings_file_path );
419+ std::ofstream ofs (m_settings_file_path );
417420 ofs << settings_data_str;
418421}
419422
0 commit comments