@@ -310,9 +310,10 @@ namespace
310310 namespace buttons_toolbar
311311 {
312312 float button_size = 19 .0f ;
313- unordered_map<spartan::RHI_Texture*, Widget*> widgets;
313+ // keyed by icon type, every icon shares one atlas texture pointer now so a pointer key would collide
314+ vector<pair<spartan::IconType, Widget*>> widgets;
314315
315- void toolbar_button (spartan::RHI_Texture* icon_type, const char * tooltip_text, bool (*get_visibility)(Widget*), void (*on_press)(Widget*), Widget* widget = nullptr, float cursor_pos_x = -1.0f)
316+ void toolbar_button (spartan::IconType icon_type, const char * tooltip_text, bool (*get_visibility)(Widget*), void (*on_press)(Widget*), Widget* widget = nullptr, float cursor_pos_x = -1.0f)
316317 {
317318 ImGui::SameLine ();
318319
@@ -495,7 +496,7 @@ namespace
495496 ImGui::SetCursorPosX (cursor_pos_x);
496497 ImGui::SetCursorPosY (offset_y);
497498
498- if (ImGuiSp::image_button (spartan::ResourceCache::GetIcon (spartan:: IconType::Play) , button_size * dpi, false ))
499+ if (ImGuiSp::image_button (spartan::IconType::Play, button_size * dpi, false ))
499500 {
500501 toggle_playing ();
501502 }
@@ -530,7 +531,7 @@ namespace
530531 {
531532 static auto screenshot_visible = [](Widget*) { return false ; };
532533 static auto screenshot_press = [](Widget*) { spartan::Renderer::Screenshot (); };
533- toolbar_button (spartan::ResourceCache::GetIcon (spartan:: IconType::Screenshot) , " Screenshot" ,
534+ toolbar_button (spartan::IconType::Screenshot, " Screenshot" ,
534535 screenshot_visible, screenshot_press, nullptr , cursor_pos_x);
535536
536537 static auto renderdoc_visible = [](Widget*) { return false ; };
@@ -545,7 +546,7 @@ namespace
545546 SP_LOG_WARNING (" RenderDoc integration is disabled. To enable, go to \" Debugging.h\" , and set \" is_renderdoc_enabled\" to \" true\" " );
546547 }
547548 };
548- toolbar_button (spartan::ResourceCache::GetIcon (spartan:: IconType::RenderDoc) , " RenderDoc capture" ,
549+ toolbar_button (spartan::IconType::RenderDoc, " RenderDoc capture" ,
549550 renderdoc_visible, renderdoc_press, nullptr );
550551 }
551552
@@ -556,16 +557,16 @@ namespace
556557 {
557558 static auto world_visible = [](Widget*) { return GeneralWindows::GetVisibilityWorlds (); };
558559 static auto world_press = [](Widget*) { GeneralWindows::SetVisibilityWorlds (!GeneralWindows::GetVisibilityWorlds ()); };
559- toolbar_button (spartan::ResourceCache::GetIcon (spartan:: IconType::Terrain) , " Worlds" ,
560+ toolbar_button (spartan::IconType::Terrain, " Worlds" ,
560561 world_visible, world_press, nullptr );
561562
562563 for (auto & widget_it : widgets)
563564 {
564565 Widget* widget_ptr = widget_it.second ;
565- spartan::RHI_Texture* icon_tex = widget_it.first ;
566+ spartan::IconType icon = widget_it.first ;
566567 static auto is_widget_visible = [](Widget* w) { return w->GetVisible (); };
567568 static auto set_widget_visible = [](Widget* w) { w->SetVisible (true ); };
568- toolbar_button (icon_tex , widget_ptr->GetTitle (), is_widget_visible, set_widget_visible, widget_ptr);
569+ toolbar_button (icon , widget_ptr->GetTitle (), is_widget_visible, set_widget_visible, widget_ptr);
569570 }
570571 }
571572
@@ -617,7 +618,7 @@ namespace
617618 ImGui::PushStyleColor (ImGuiCol_ButtonActive, ImVec4 (1 , 1 , 1 , 0 .2f ));
618619 ImGui::PushStyleVar (ImGuiStyleVar_FramePadding, ImVec2 (button_padding_x * dpi, button_padding_y * dpi));
619620
620- if (ImGuiSp::image_button (spartan::ResourceCache::GetIcon (spartan:: IconType::Minimize) , icon_size, false ))
621+ if (ImGuiSp::image_button (spartan::IconType::Minimize, icon_size, false ))
621622 {
622623 spartan::Window::Minimize ();
623624 }
@@ -626,7 +627,7 @@ namespace
626627 ImGui::SetCursorPosY (offset_y);
627628
628629 // maximize/restore button
629- if (ImGuiSp::image_button (spartan::ResourceCache::GetIcon (spartan:: IconType::Maximize) , icon_size, false ))
630+ if (ImGuiSp::image_button (spartan::IconType::Maximize, icon_size, false ))
630631 {
631632 spartan::Window::Maximize ();
632633 }
@@ -641,7 +642,7 @@ namespace
641642 ImGui::PushStyleColor (ImGuiCol_ButtonHovered, ImVec4 (0 .9f , 0 .2f , 0 .2f , 1 .0f ));
642643 ImGui::PushStyleColor (ImGuiCol_ButtonActive, ImVec4 (0 .7f , 0 .1f , 0 .1f , 1 .0f ));
643644
644- if (ImGuiSp::image_button (spartan::ResourceCache::GetIcon (spartan:: IconType::X) , icon_size, false ))
645+ if (ImGuiSp::image_button (spartan::IconType::X, icon_size, false ))
645646 {
646647 spartan::Window::Close ();
647648 }
@@ -657,11 +658,11 @@ void MenuBar::Initialize(Editor* _editor)
657658 editor = _editor;
658659 file_dialog = make_unique<FileDialog>(true , FileDialog_Type_FileSelection, FileDialog_Op_Open, FileDialog_Filter_World);
659660
660- buttons_toolbar::widgets[ spartan::ResourceCache::GetIcon ( spartan::IconType::Profiler)] = editor->GetWidget <Profiler>();
661- buttons_toolbar::widgets[ spartan::ResourceCache::GetIcon ( spartan::IconType::ResourceCache)] = editor->GetWidget <ResourceViewer>();
662- buttons_toolbar::widgets[ spartan::ResourceCache::GetIcon ( spartan::IconType::Shader)] = editor->GetWidget <ShaderEditor>();
663- buttons_toolbar::widgets[ spartan::ResourceCache::GetIcon ( spartan::IconType::Gear)] = editor->GetWidget <RenderOptions>();
664- buttons_toolbar::widgets[ spartan::ResourceCache::GetIcon ( spartan::IconType::Texture)] = editor->GetWidget <TextureViewer>();
661+ buttons_toolbar::widgets. push_back ({ spartan::IconType::Profiler, editor->GetWidget <Profiler>() } );
662+ buttons_toolbar::widgets. push_back ({ spartan::IconType::ResourceCache, editor->GetWidget <ResourceViewer>() } );
663+ buttons_toolbar::widgets. push_back ({ spartan::IconType::Shader, editor->GetWidget <ShaderEditor>() } );
664+ buttons_toolbar::widgets. push_back ({ spartan::IconType::Gear, editor->GetWidget <RenderOptions>() } );
665+ buttons_toolbar::widgets. push_back ({ spartan::IconType::Texture, editor->GetWidget <TextureViewer>() } );
665666
666667 spartan::Engine::SetFlag (spartan::EngineMode::Playing, false );
667668}
@@ -725,10 +726,10 @@ void MenuBar::Tick()
725726 // logo
726727 ImGui::SetCursorPosX (padding_x);
727728 ImGui::SetCursorPosY (icon_y);
728- spartan::RHI_Texture* logo = spartan::ResourceCache::GetIcon (spartan::IconType::Logo);
729- if (logo)
729+ const spartan::Icon& logo = spartan::ResourceCache::GetIcon (spartan::IconType::Logo);
730+ if (logo. texture )
730731 {
731- ImGui::Image ( reinterpret_cast <ImTextureID>( logo) , ImVec2 (icon_size, icon_size));
732+ ImGuiSp::image ( logo. texture , ImVec2 (icon_size, icon_size), logo. uv_min , logo. uv_max );
732733 }
733734 ImGui::SameLine (0 , padding_x * 0 .5f );
734735
0 commit comments