Skip to content

Commit

Permalink
feat: icons in editor
Browse files Browse the repository at this point in the history
  • Loading branch information
BenMcAvoy committed Oct 13, 2024
1 parent deafeac commit 0f68920
Show file tree
Hide file tree
Showing 11 changed files with 86 additions and 21 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ cmake_minimum_required(VERSION 3.5)
set (CMAKE_EXPORT_COMPILE_COMMANDS ON)

# C++
set (CMAKE_CXX_STANDARD 23)
set (CMAKE_CXX_STANDARD 20)
set (CMAKE_CXX_STANDARD_REQUIRED ON)

# Project declaration
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Come back later, sorry! Jenjin is not ready for real usage.
- [x] Texture loading
- [x] Scripting (Lua)
- [x] Transparency on sprites
- [ ] Icons everywhere
- [x] Icons everywhere
- [ ] Code editor in the editor
- [ ] Dynamic data attached to game objects at runtime
- [ ] Hierarchy and `.Parent` in Lua along with `workspace` (e.g. `Workspace.MyGameObject.Parent` == `Workspace`)
Expand Down
1 change: 1 addition & 0 deletions engine/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ target_include_directories(JenjinEngine
${CMAKE_SOURCE_DIR}/megasource/libs/stb/
${CMAKE_SOURCE_DIR}/megasource/libs/lua/include/
${CMAKE_SOURCE_DIR}/megasource/libs/sol2/include/
${CMAKE_SOURCE_DIR}/megasource/libs/IconFontCppHeaders/
${CMAKE_SOURCE_DIR}/megasource/libs/
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/src
Expand Down
61 changes: 47 additions & 14 deletions engine/src/editor/editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,28 @@
#include <imgui.h>
#include <imgui_internal.h>

#include <IconsFontAwesome6.h>

#include <filesystem>
#include <fstream>
#include <memory>
#include <string>
#include <vector>

#define EDITOR_WELCOME_TITLE ICON_FA_DOOR_OPEN " Welcome";
#define EDITOR_VIEWPORT_TITLE ICON_FA_VIDEO " Viewport";
#define EDITOR_HIERARCHY_TITLE ICON_FA_SITEMAP " Hierarchy";
#define EDITOR_INSPECTOR_TITLE ICON_FA_EYE " Inspector";
#define EDITOR_EXPLORER_TITLE ICON_FA_FOLDER " Explorer";
#define EDITOR_CODE_TITLE ICON_FA_CODE " Code";
#define EDITOR_CONSOLE_TITLE ICON_FA_TERMINAL " Console";

#define TRANSFORM_WIDGET_TITLE ICON_FA_ARROWS_UP_DOWN_LEFT_RIGHT " Transform";
#define APPEARANCE_WIDGET_TITLE ICON_FA_PALETTE " Appearance";
#define TEXTURES_WIDGET_TITLE ICON_FA_IMAGES " Textures";

#define MANAGE_WIDGET_TITLE ICON_FA_JAR " Manage";

using namespace Jenjin::Editor;

Manager::Manager() {}
Expand Down Expand Up @@ -138,7 +154,8 @@ void Manager::dockspace() {
ImGui::DockBuilderSetNodeSize(dockspace_id, viewport->Size);

// Dock the welcome window in the center
ImGui::DockBuilderDockWindow("Welcome", dockspace_id);
static auto title = EDITOR_WELCOME_TITLE;
ImGui::DockBuilderDockWindow(title, dockspace_id);

auto dock_left = ImGui::DockBuilderSplitNode(dockspace_id, ImGuiDir_Left,
0.25f, nullptr, &dockspace_id);
Expand All @@ -148,10 +165,17 @@ void Manager::dockspace() {
0.6f, nullptr, &dockspace_id);
auto middle = dockspace_id;

ImGui::DockBuilderDockWindow("Hierarchy", dock_left_up);
ImGui::DockBuilderDockWindow("Explorer", dock_left);
ImGui::DockBuilderDockWindow("Inspector", dock_right);
ImGui::DockBuilderDockWindow("Viewport", middle);
static auto hierarchy_title = EDITOR_HIERARCHY_TITLE;
ImGui::DockBuilderDockWindow(hierarchy_title, dock_left_up);

static auto explorer_title = EDITOR_EXPLORER_TITLE;
ImGui::DockBuilderDockWindow(explorer_title, dock_left);

static auto inspector_title = EDITOR_INSPECTOR_TITLE;
ImGui::DockBuilderDockWindow(inspector_title, dock_right);

static auto viewport_title = EDITOR_VIEWPORT_TITLE;
ImGui::DockBuilderDockWindow(viewport_title, middle);

ImGui::DockBuilderFinish(dockspace_id);
}
Expand All @@ -168,7 +192,8 @@ void Manager::hierarchy(Jenjin::Scene *scene) {
std::vector<std::shared_ptr<Jenjin::GameObject>> *gameObjects =
Jenjin::EngineRef->GetCurrentScene()->GetGameObjects();

ImGui::Begin("Hierarchy");
static auto title = EDITOR_HIERARCHY_TITLE;
ImGui::Begin(title);

static char name[128] = {0};
// Press or Ctrl + Shift + A
Expand Down Expand Up @@ -246,7 +271,8 @@ void Manager::inspector(Jenjin::Scene *scene) {
return;
}

ImGui::Begin("Inspector");
static auto title = EDITOR_INSPECTOR_TITLE;
ImGui::Begin(title);

if (selectedCamera) {
ImGui::Text("Camera");
Expand Down Expand Up @@ -274,7 +300,8 @@ void Manager::inspector(Jenjin::Scene *scene) {

ImGui::Unindent();

ImGui::Text("Appearance");
static auto appearance_title = APPEARANCE_WIDGET_TITLE;
ImGui::Text("%s", appearance_title);
ImGui::Separator();
ImGui::Indent();

Expand All @@ -294,23 +321,26 @@ void Manager::inspector(Jenjin::Scene *scene) {
return;
}

if (ImGui::CollapsingHeader("Transform", ImGuiTreeNodeFlags_DefaultOpen)) {
static auto transform_title = TRANSFORM_WIDGET_TITLE;
if (ImGui::CollapsingHeader(transform_title, ImGuiTreeNodeFlags_DefaultOpen)) {
ImGui::Indent();
Jenjin::Editor::Widgets::transformWidget(&selectedObject->transform);
ImGui::Unindent();
}

ImGui::ItemSize(ImVec2(0, 10));

if (ImGui::CollapsingHeader("Appearance", ImGuiTreeNodeFlags_DefaultOpen)) {
static auto appearance_title = APPEARANCE_WIDGET_TITLE;
if (ImGui::CollapsingHeader(appearance_title)) {
ImGui::Indent();
ImGui::ColorPicker3("Color", glm::value_ptr(selectedObject->color));
ImGui::Unindent();
}

ImGui::ItemSize(ImVec2(0, 10));

if (ImGui::CollapsingHeader("Textures", ImGuiTreeNodeFlags_DefaultOpen)) {
static auto textures_title = TEXTURES_WIDGET_TITLE;
if (ImGui::CollapsingHeader(textures_title)) {
ImGui::Indent();
auto diriter = std::filesystem::directory_iterator(this->paths.projectPath +
"/textures/");
Expand Down Expand Up @@ -346,7 +376,8 @@ void Manager::inspector(Jenjin::Scene *scene) {

ImGui::ItemSize(ImVec2(0, 10));

if (ImGui::CollapsingHeader("Manage", ImGuiTreeNodeFlags_DefaultOpen)) {
static auto manage_title = MANAGE_WIDGET_TITLE;
if (ImGui::CollapsingHeader(manage_title, ImGuiTreeNodeFlags_DefaultOpen)) {
ImGui::Indent();
ImGui::InputText("##RenameInput", renameGameObjectBuffer,
sizeof(renameGameObjectBuffer));
Expand All @@ -367,7 +398,8 @@ void Manager::inspector(Jenjin::Scene *scene) {
}

void Manager::explorer(Jenjin::Scene *scene) {
ImGui::Begin("Explorer");
static auto title = EDITOR_EXPLORER_TITLE;
ImGui::Begin(title);

for (auto file :
std::filesystem::directory_iterator(this->paths.projectPath)) {
Expand Down Expand Up @@ -464,7 +496,8 @@ void Manager::show_all(Jenjin::Scene *scene) {
}

void Manager::welcome() {
ImGui::Begin("Welcome", nullptr,
static auto title = EDITOR_WELCOME_TITLE;
ImGui::Begin(title, nullptr,
ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove |
ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoScrollbar);

Expand Down
17 changes: 14 additions & 3 deletions engine/src/editor/widgets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@
#include <imgui.h>
#include <imgui_internal.h>

#include <IconsFontAwesome6.h>

#define LEFT_RIGHT ICON_FA_ARROWS_LEFT_RIGHT
#define UP_DOWN ICON_FA_ARROWS_UP_DOWN

#define ROTATE ICON_FA_ARROWS_SPIN

using namespace Jenjin::Editor;

static void drawButtonWithDrag(const std::string &buttonLabel,
Expand Down Expand Up @@ -59,6 +66,9 @@ bool Widgets::transformWidget(Jenjin::GameObject::Transform *transform) {
GImGui->Font->FontSize + GImGui->Style.FramePadding.y * 2.0f;
ImVec2 buttonSize = {lineHeight + 3.0f, lineHeight};

static auto left_right_title = LEFT_RIGHT;
static auto up_down_title = UP_DOWN;

start_widget("Position");
drawButtonWithDrag("X", "##X", transform->position.x,
ImVec4{0.6f, 0.2f, 0.2f, 1.0f},
Expand All @@ -72,19 +82,20 @@ bool Widgets::transformWidget(Jenjin::GameObject::Transform *transform) {
end_widget();

start_widget("Scale");
drawButtonWithDrag("W", "##ScaleW", transform->scale.x,
drawButtonWithDrag(left_right_title, "##ScaleW", transform->scale.x,
ImVec4{0.6f, 0.2f, 0.2f, 1.0f},
ImVec4{0.7f, 0.3f, 0.3f, 1.0f},
ImVec4{0.6f, 0.2f, 0.2f, 1.0f}, buttonSize, 1);

drawButtonWithDrag("H", "##ScaleH", transform->scale.y,
drawButtonWithDrag(up_down_title, "##ScaleH", transform->scale.y,
ImVec4{0.3f, 0.6f, 0.3f, 1.0f},
ImVec4{0.4f, 0.7f, 0.4f, 1.0f},
ImVec4{0.3f, 0.6f, 0.3f, 1.0f}, buttonSize, 1);
end_widget();

static auto rotation_title = ROTATE;
start_widget("Rotation", 1);
drawButtonWithDrag("Z", "##Rotation", transform->rotation,
drawButtonWithDrag(rotation_title, "##Rotation", transform->rotation,
ImVec4{0.3f, 0.4f, 0.7f, 1.0f},
ImVec4{0.4f, 0.5f, 0.8f, 1.0f},
ImVec4{0.3f, 0.4f, 0.7f, 1.0f}, buttonSize);
Expand Down
14 changes: 14 additions & 0 deletions engine/src/helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#include <imgui_impl_glfw.h>
#include <imgui_impl_opengl3.h>

#include <IconsFontAwesome6.h>

#include <spdlog/spdlog.h>

namespace Jenjin::Helpers {
Expand Down Expand Up @@ -37,12 +39,24 @@ void CheckWindow(GLFWwindow *window) {
void InitiateImGui(GLFWwindow *window) {
IMGUI_CHECKVERSION();
ImGui::CreateContext();

ImGuiIO &io = ImGui::GetIO();
io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard;
io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad;
io.ConfigFlags |= ImGuiConfigFlags_DockingEnable;

io.Fonts->AddFontFromFileTTF("resources/fonts/Roboto-Medium.ttf", 16.0f);

float base = 16.0f;
float icon = base * 2.0f / 3.0f;

static const ImWchar icon_ranges[] = { ICON_MIN_FA, ICON_MAX_16_FA, 0 };
ImFontConfig config;
config.MergeMode = true;
config.PixelSnapH = true;
config.GlyphMinAdvanceX = icon;
io.Fonts->AddFontFromFileTTF("./resources/fonts/fa-solid-900.ttf", base, &config, icon_ranges);

ImGui::StyleColorsDark();

// Photoshop style by Derydoca from ImThemes
Expand Down
7 changes: 6 additions & 1 deletion engine/src/targets/editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@
#include <imgui_impl_opengl3.h>

#include <glm/gtc/type_ptr.hpp>
#include <IconsFontAwesome6.h>

#include <GLFW/glfw3.h>

#define VIEWPORT_TITLE ICON_FA_VIDEO " Viewport";

using namespace Jenjin::Targets;

EditorTarget::EditorTarget() {}
Expand Down Expand Up @@ -51,7 +54,9 @@ void EditorTarget::Render() {
return;
}

ImGui::Begin("Viewport");
static auto title = VIEWPORT_TITLE;
ImGui::Begin(title, nullptr,
ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse);

ImVec2 size = ImGui::GetContentRegionAvail();
this->width = size.x;
Expand Down
Binary file removed jenjin/game
Binary file not shown.
2 changes: 1 addition & 1 deletion megasource
1 change: 1 addition & 0 deletions resources/fonts/fa-solid-900-LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://fontawesome.com/license/free
Binary file added resources/fonts/fa-solid-900.ttf
Binary file not shown.

0 comments on commit 0f68920

Please sign in to comment.