Skip to content

Commit

Permalink
Merge pull request #5772 from Web-eWorks/editor-frontend
Browse files Browse the repository at this point in the history
Editor Welcome Screen
  • Loading branch information
Web-eWorks authored Feb 22, 2024
2 parents d84a731 + 6b30f90 commit 3d4553f
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 0 deletions.
83 changes: 83 additions & 0 deletions src/editor/EditorApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include "EditorApp.h"

#include "EditorDraw.h"
#include "EditorIcons.h"
#include "MathUtil.h"
#include "Modal.h"

#include "FileSystem.h"
Expand All @@ -17,6 +19,7 @@
#include "core/IniConfig.h"
#include "core/OS.h"
#include "graphics/Graphics.h"
#include "imgui/imgui.h"
#include "lua/Lua.h"
#include "graphics/opengl/RendererGL.h"

Expand Down Expand Up @@ -71,6 +74,8 @@ void EditorApp::Initialize(argh::parser &cmdline)
SetAppName("SystemEditor");
return;
}

QueueLifecycle(RefCountedPtr<Application::Lifecycle>(new EditorWelcomeScreen(this)));
}

void EditorApp::AddLoadingTask(TaskSet::Handle handle)
Expand Down Expand Up @@ -232,3 +237,81 @@ void LoadingPhase::Update(float dt)
RequestEndLifecycle();
}
}

// ============================================================================
// Welcome Screen
// ============================================================================

static inline ImVec4 operator*(const ImVec4& lhs, const float& rhs) { return ImVec4(lhs.x * rhs, lhs.y * rhs, lhs.z * rhs, lhs.w * rhs); }

ImVec2 CalcEditorModeButtonSize(const char *label, float iconSize)
{
ImVec2 textSize = ImGui::CalcTextSize(label, nullptr, false, iconSize);
return ImVec2(iconSize, iconSize + ImGui::GetStyle().ItemSpacing.y + textSize.y) + ImGui::GetStyle().FramePadding * 2.f;
}

bool DrawEditorModeButton(const char *label, const char *icon, float iconSize, PiGui::Instance *pigui)
{
ImGuiStyle &style = ImGui::GetStyle();

ImVec2 size = CalcEditorModeButtonSize(label, iconSize);
ImVec2 pos = ImGui::GetCursorScreenPos();
ImVec2 padding = style.FramePadding;

bool clicked = ImGui::InvisibleButton(label, size);
bool hovered = ImGui::IsItemHovered();
float timer = ImGui::GetCurrentContext()->HoveredIdTimer;

ImColor regular = style.Colors[ImGuiCol_Text];
ImColor active = style.Colors[ImGuiCol_ButtonHovered];
ImColor col = hovered ? ImColor(ImLerp<ImVec4>(regular, active, std::min(1.f, timer * 8.f))) : regular;

ImDrawList *dl = ImGui::GetWindowDrawList();

dl->AddRect(pos, pos + size, ImColor(style.Colors[ImGuiCol_FrameBg]), style.FrameRounding, 0, 2.f);

ImGui::PushFont(pigui->GetFont("icons", iconSize));
dl->AddText(pos + padding, col, icon);
ImGui::PopFont();

ImVec2 textSize = ImGui::CalcTextSize(label, nullptr, false, iconSize);
ImVec2 textOffset = ImVec2(
(iconSize - textSize.x) / 2.f,
iconSize + style.ItemSpacing.y);

dl->AddText(nullptr, 0, pos + padding + textOffset, regular, label, nullptr, textSize.x);

return clicked;
}

void EditorWelcomeScreen::Update(float dt)
{
Draw::BeginHostWindow("##fullscreen");

PiGui::Instance *pigui = m_app->GetPiGui();

float iconSize = 128;
int numButtons = 2;
ImVec2 size = CalcEditorModeButtonSize("Model Viewer", iconSize);

ImGui::SetCursorPos((ImGui::GetWindowSize() - ImVec2(size.x * numButtons + ImGui::GetStyle().ItemSpacing.x, size.y)) / 2.f);
ImGui::BeginGroup();

if (DrawEditorModeButton("Model Viewer", EICON_SURFACE_STATION, iconSize, pigui)) {
m_app->QueueLifecycle(RefCountedPtr<ModelViewer>(new ModelViewer(m_app, Lua::manager)));
m_app->SetAppName("Model Viewer");
RequestEndLifecycle();
}

ImGui::SameLine();

if (DrawEditorModeButton("System Editor", EICON_SYSTEM_EDITOR, iconSize, pigui)) {
m_app->QueueLifecycle(RefCountedPtr<SystemEditor>(new SystemEditor(m_app)));
m_app->SetAppName("System Editor");
RequestEndLifecycle();
}

ImGui::EndGroup();

ImGui::End();
}
14 changes: 14 additions & 0 deletions src/editor/EditorApp.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,18 @@ namespace Editor {
float minRuntime = 1.f;
};

class EditorWelcomeScreen : public Application::Lifecycle {
public:
EditorWelcomeScreen(EditorApp *app) :
Application::Lifecycle(),
m_app(app)
{}

protected:
void Update(float dt) override;

private:
EditorApp *m_app;
};

} // namespace Editor
2 changes: 2 additions & 0 deletions src/editor/EditorIcons.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
#define EICON_SPACE_STATION u8"\uF063"
#define EICON_SURFACE_STATION u8"\uF073"

#define EICON_SYSTEM_EDITOR u8"\uF08E"

#define EICON_STOP u8"\uF054"
#define EICON_PAUSE u8"\uF055"
#define EICON_PLAY u8"\uF056"
Expand Down
2 changes: 2 additions & 0 deletions src/editor/system/SystemEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,8 @@ void SystemEditor::RegisterMenuActions()
if (HasUnsavedChanges()) {
m_unsavedFileModal = m_app->PushModal<UnsavedFileModal>();
m_pendingFileReq = FileRequest_Quit;
} else {
RequestEndLifecycle();
}
}
});
Expand Down

0 comments on commit 3d4553f

Please sign in to comment.