Something went wrong. Try again.
art software for the rest of us
drawing paint image sdl art
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173#include "ToolbarLayer.h"#include "MaterialIcons.h"#include "../Tools/BrushTool.h"#include "../Tools/EraserTool.h"#include "../Tools/MoveTool.h"#include "../Tools/DemoTool.h"#include "../ImGui.h"#include "../ManagementContext/StyleManagmentContext.h"#include "../ManagementContext/PanelManagementContext.h"//#include "BrushPickerLayer.h"//#include "ColorPickerLayer.h"//#include "LayerManagerLayer.h"//#include "SettingsLayer.h"#include "../App.h"
enum class MenuAction { Settings, Exit };
void ToolbarAppLayer::OnActivate(){ tools.push_back(new EraserTool()); tools.push_back(new BrushTool()); Tool::SetActive(tools.back()); tools.push_back(new MoveTool()); tools.push_back(new DemoTool()); if (menu) { return; } std::vector<PopupOption> options; PopupOption option; option.label = "Settings"; option.icon = ICON_MS_SETTINGS; option.id = (unsigned int)MenuAction::Settings; options.push_back(option); option.label = "Back to My Gallery"; option.icon = ICON_MS_ARROW_BACK; option.id = (unsigned int)MenuAction::Exit; options.push_back(option); menu = new Popup(options); isActive = true;}
void ToolbarAppLayer::OnDeactivate(){ Tool::SetActive(nullptr); for (auto tool : tools) { delete tool; } tools.clear(); delete menu; menu = nullptr; isActive = false;}
void ToolbarAppLayer::renderTools(){ ImGui::Begin("Tools Selector", (bool*)NULL, ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoMove); for (auto it = tools.begin(); it != tools.end(); ++it) { bool sameTool = *it == Tool::GetActive(); if (sameTool) { StyleManagmentContext::Push(SELECTED); } if (ImGui::Button((*it)->GetIcon().c_str())) { Tool::SetActive(*it); } if (sameTool) { StyleManagmentContext::Pop(); } ImGui::SameLine(); } ImGui::End();}
void ToolbarAppLayer::renderActions(){ ImGui::Begin("Tool Actions", (bool*)NULL, ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoMove);
ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled); if (ImGui::Button(ICON_MS_CYCLE)) { Tool::SetActive(Tool::GetActive() == tools[0] ? tools[1] : tools[0]); } ImGui::SameLine(); // Cycle Eraser/Brush if (ImGui::Button(ICON_MS_STYLUS_BRUSH) && !PanelManagementContext::IsOpen(Panels::BRUSHES)) { PanelManagementContext::Open(Panels::BRUSHES); } ImGui::SameLine(); if (ImGui::Button(ICON_MS_COLORS) && !PanelManagementContext::IsOpen(Panels::COLORS)) { PanelManagementContext::Open(Panels::COLORS); } ImGui::SameLine(); // Show Color Picker //ImGui::ColorEdit3("##ColorPicker", Tool::Color, ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_NoLabel | ImGuiColorEditFlags_AlphaPreviewHalf); ImGui::SameLine();
ImGui::BeginDisabled(!history->CanUndo()); if (ImGui::Button(ICON_MS_UNDO)) { history->Undo(); } ImGui::SameLine(); ImGui::EndDisabled();
ImGui::BeginDisabled(!history->CanRedo()); if (ImGui::Button(ICON_MS_REDO)) { history->Redo(); } ImGui::SameLine(); ImGui::EndDisabled();
if (ImGui::Button(ICON_MS_LAYERS) && !PanelManagementContext::IsOpen(Panels::LAYERS)) {
//LayerManagerAppLayer::Toggle(); PanelManagementContext::Open(Panels::LAYERS); } ImGui::SameLine(); // Show Layer Panel if (ImGui::Button(ICON_MS_MORE_HORIZ)) { //ImGui::OpenPopup("##ToolsMenu"); menu->Toggle(); } ImGui::End();}void ToolbarAppLayer::renderPopup(){}void ToolbarAppLayer::OnRender(){ StyleManagmentContext::Push(TOOLBAR); StyleManagmentContext::Push(ICONSLIST); ImGui::PushFont(DearImGuiApp::MaterialIcons, 24.0f);
const ImGuiViewport* viewport = ImGui::GetMainViewport(); ImVec2 work_pos = viewport->WorkPos; ImVec2 work_size = viewport->WorkSize; ImVec2 window_pos;
float toolsWidth = (8 + 40 * tools.size()); float actionsWidth = (8 + 40 * 7);
window_pos.x = work_pos.x + (work_size.x / 2) - ((toolsWidth + actionsWidth + 8) / 2); window_pos.y = work_pos.y + work_size.y - 8; ImGui::SetNextWindowPos((window_pos), 0, ImVec2(0.0f, 1.0f));
renderTools();
window_pos.x = work_pos.x + (work_size.x / 2) + ((toolsWidth + actionsWidth + 8) / 2); window_pos.y = work_pos.y + work_size.y - 8; ImGui::SetNextWindowPos((window_pos), 0, ImVec2(1.0f, 1.0f));
renderActions();
ImGui::PopFont(); StyleManagmentContext::Pop(); StyleManagmentContext::Pop();
menu->SetPosition(ImVec2(work_pos.x + (work_size.x / 2) + 196, work_pos.y + work_size.y - 64), ImVec2(0.5f, 1.0f)); menu->OnRender();
int selected = menu->CheckSelected(); // here we should compare against a key instead of string switch ((MenuAction)selected) { case MenuAction::Settings: //SettingsAppLayer::Toggle(); break; case MenuAction::Exit: std::printf("Exit\n"); { //SDL_Event* event = (SDL_Event*)malloc(sizeof(SDL_Event)); event->type = SDL_EVENT_QUIT; //SDL_PushEvent(event); App::CurrentArtwork->SaveProject(); delete App::CurrentArtwork; App::CurrentArtwork = nullptr; } break; default: break; }}