Something went wrong. Try again.
art software for the rest of us
drawing paint image sdl art
Something went wrong. Try again.
3.5 kB · 111 lines
C++
at master
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112#include "Popup.h"#include "../ManagementContext/StyleManagmentContext.h"#include "../ImGui.h"
int Popup::count = 0;
bool Popup::setActive(bool active){ if (active != this->active) { count += active ? 1 : -1; } return this->active = active;}
Popup::Popup(std::vector<PopupOption> options){ this->options = options;}
Popup::~Popup(){}
void Popup::OnRender(){ if (!active) { return; } ImGui::SetNextWindowPos(this->position, 0, this->pivot); StyleManagmentContext::Push(POPUP); static int callDelay = 2; if (ImGui::Begin(("Popup##Popup" + std::to_string((long int)this)).c_str(), (bool*)NULL, ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_AlwaysAutoResize)) { callDelay++; if (callDelay == 2) { ImGui::SetWindowFocus(("Popup##Popup" + std::to_string((long int)this)).c_str()); } if (ImGui::IsWindowAppearing()) { callDelay = 0; } StyleManagmentContext::Push(POPUPINNER); if (ImGui::BeginChild("##MenuContent", ImVec2(200.0f, 0.0f), ImGuiChildFlags_AutoResizeY | ImGuiChildFlags_AutoResizeX | ImGuiChildFlags_Borders)) { for (size_t i = 0; i < options.size(); i++) { if (options[i] != options.front()) { ImGui::Separator(); } auto cursor = ImGui::GetCursorScreenPos(); ImGui::Selectable(("##" + options[i].label).c_str(), &options[i].selected, 0, ImVec2(200.0f, 32.0f)); cursor.x += 8.0f; cursor.y += 6.0f; ImGui::SetCursorScreenPos(cursor); if (options[i].icon.empty()) { ImGui::Text(options[i].label.c_str(), nullptr); } else { cursor.y -= 2.0f; ImGui::SetCursorScreenPos(cursor); ImGui::PushFont(DearImGuiApp::MaterialIcons, 24.0f); ImGui::Text(options[i].icon.c_str(), nullptr); ImGui::PopFont(); cursor.x += 28.0f; cursor.y += 2.0f; ImGui::SetCursorScreenPos(cursor); ImGui::Text(options[i].label.c_str(), nullptr); } cursor = ImGui::GetCursorScreenPos(); cursor.x += 0.0f; cursor.y += 6.0f; // ghetto ImGui::SetCursorScreenPos(cursor); /*if (selected) { //options[i].onSelect(); (void)selected; }*/ } ImGui::Dummy(ImVec2(0.0f, 0.0f)); ImGui::EndChild(); } StyleManagmentContext::Pop();
if (ImGui::IsMouseReleased(ImGuiMouseButton_Left) && !ImGui::IsWindowFocused(ImGuiFocusedFlags_RootAndChildWindows)) { setActive(false); } } ImGui::End(); StyleManagmentContext::Pop();}
void Popup::SetPosition(ImVec2 position, ImVec2 pivot){ this->position = position; this->pivot = pivot;}
int Popup::CheckSelected(){ for (size_t i = 0; i < options.size(); i++) { if (options[i].selected) { options[i].selected = false; setActive(false); return options[i].id; } } return -1;}
int Popup::GetCount(){ return count;}
void Popup::Toggle(){ setActive(!active);}