From c15931f2315f43d884d542cf757c4e08ce04ffaf Mon Sep 17 00:00:00 2001 From: dawsh Date: Mon, 12 May 2025 21:26:34 -0500 Subject: [PATCH] Initial Commit --- CMakeLists.txt | 76 +++++++++++++++++++++ cmake/CPM.cmake | 24 +++++++ include/Editor.hpp | 9 +++ include/EditorApp.hpp | 150 ++++++++++++++++++++++++++++++++++++++++++ include/Entity.hpp | 8 +++ include/Layer.hpp | 8 +++ include/Level.hpp | 8 +++ include/TileLayer.hpp | 16 +++++ include/Tileset.hpp | 8 +++ main.cpp | 27 ++++++++ src/EditorApp.cpp | 1 + 11 files changed, 335 insertions(+) create mode 100644 CMakeLists.txt create mode 100644 cmake/CPM.cmake create mode 100644 include/Editor.hpp create mode 100644 include/EditorApp.hpp create mode 100644 include/Entity.hpp create mode 100644 include/Layer.hpp create mode 100644 include/Level.hpp create mode 100644 include/TileLayer.hpp create mode 100644 include/Tileset.hpp create mode 100644 main.cpp create mode 100644 src/EditorApp.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..70bd583 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,76 @@ +cmake_minimum_required(VERSION 3.18..3.27) + +project(Editor2D + VERSION 1.0 + LANGUAGES CXX) + +if (PROJECT_SOURCE_DIR STREQUAL PROJECT_BINARY_DIR) + message(FATAL_ERROR "In-source builds are not allowed!") +endif() + +set(CMAKE_CXX_STANDARD 20) + +set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake") + +# Enable package managers +include(cmake/CPM.cmake) + +file(GLOB_RECURSE EDITOR_HEADERS "include/*.hpp") +file(GLOB_RECURSE EDITOR_SRC "src/*.cpp") + +include_directories("include") + + + + + +CPMAddPackage(NAME jlog + URL https://git.redacted.cc/josh/jlog/archive/Prerelease-18.zip) + +CPMAddPackage(NAME mcolor + URL https://git.redacted.cc/maxine/mcolor/archive/Prerelease-7.2.zip) + +CPMAddPackage(NAME Event + URL https://git.redacted.cc/josh/Event/archive/Release-12.zip) + +CPMAddPackage(NAME jjx + URL https://git.redacted.cc/josh/jjx/archive/Release-1.1.zip) + +CPMAddPackage(NAME J3ML + URL https://git.redacted.cc/josh/j3ml/archive/3.4.5.zip) + +CPMAddPackage(NAME ReWindow + URL https://git.redacted.cc/Redacted/ReWindow/archive/Prerelease-32.zip) + +CPMAddPackage(NAME JGL + URL https://git.redacted.cc/josh/JGL/archive/Prerelease-55.zip) + +CPMAddPackage(NAME JUI + URL https://git.redacted.cc/josh/ReJUI/archive/Prerelease-6.zip) + + +if (UNIX) + add_library(Editor2D SHARED ${EDITOR_SRC}) +endif() + +if (WIN32) + ADD_LIBRARY(Editor2D STATIC ${EDITOR_SRC}) +endif() + +set_target_properties(Editor2D PROPERTIES LINKER_LANGUAGE CXX) + +target_include_directories(Editor2D PUBLIC + ${Event_SOURCE_DIR}/include + ${J3ML_SOURCE_DIR}/include + ${jlog_SOURCE_DIR}/include + ${JGL_SOURCE_DIR}/include + ${ReWindow_SOURCE_DIR}/include + ${JUI_SOURCE_DIR}/include + ${mcolor_SOURCE_DIR}/include +) + +target_link_libraries(Editor2D PUBLIC Event J3ML jlog ReWindow JGL JUI mcolor) + + +add_executable(Editor2DApp main.cpp) +target_link_libraries(Editor2DApp PUBLIC Editor2D) \ No newline at end of file diff --git a/cmake/CPM.cmake b/cmake/CPM.cmake new file mode 100644 index 0000000..d866ad7 --- /dev/null +++ b/cmake/CPM.cmake @@ -0,0 +1,24 @@ +# SPDX-License-Identifier: MIT +# +# SPDX-FileCopyrightText: Copyright (c) 2019-2023 Lars Melchior and contributors + +set(CPM_DOWNLOAD_VERSION 0.38.7) +set(CPM_HASH_SUM "83e5eb71b2bbb8b1f2ad38f1950287a057624e385c238f6087f94cdfc44af9c5") + +if(CPM_SOURCE_CACHE) + set(CPM_DOWNLOAD_LOCATION "${CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake") +elseif(DEFINED ENV{CPM_SOURCE_CACHE}) + set(CPM_DOWNLOAD_LOCATION "$ENV{CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake") +else() + set(CPM_DOWNLOAD_LOCATION "${CMAKE_BINARY_DIR}/cmake/CPM_${CPM_DOWNLOAD_VERSION}.cmake") +endif() + +# Expand relative path. This is important if the provided path contains a tilde (~) +get_filename_component(CPM_DOWNLOAD_LOCATION ${CPM_DOWNLOAD_LOCATION} ABSOLUTE) + +file(DOWNLOAD + https://github.com/cpm-cmake/CPM.cmake/releases/download/v${CPM_DOWNLOAD_VERSION}/CPM.cmake + ${CPM_DOWNLOAD_LOCATION} EXPECTED_HASH SHA256=${CPM_HASH_SUM} +) + +include(${CPM_DOWNLOAD_LOCATION}) \ No newline at end of file diff --git a/include/Editor.hpp b/include/Editor.hpp new file mode 100644 index 0000000..92bd7de --- /dev/null +++ b/include/Editor.hpp @@ -0,0 +1,9 @@ +#pragma once + +class Editor { +public: +protected: +private: + + +} \ No newline at end of file diff --git a/include/EditorApp.hpp b/include/EditorApp.hpp new file mode 100644 index 0000000..9ddfd32 --- /dev/null +++ b/include/EditorApp.hpp @@ -0,0 +1,150 @@ +#pragma once +#include + +#include "JGL/JGL.h" +#include "JUI/Widgets/Scene.hpp" +#include "JUI/Widgets/UtilityBar.hpp" + +#define GL_VER_MAJOR 2 +#define GL_VER_MINOR 1 + +using namespace ReWindow; +using namespace JUI::UDimLiterals; + +class EditorApp : public OpenGLWindow { +public: + JUI::Scene* scene; + + EditorApp() : OpenGLWindow("Editor App", 1080, 768, GL_VER_MAJOR, GL_VER_MINOR) { + + } + + void CreateWidgets() { + scene = new JUI::Scene(); + + + auto* topbar = new JUI::UtilityBar(scene); + + + auto* file = topbar->AddSubmenu("File"); + file->SetFont(JGL::Fonts::Jupiteroid); + file->AddButton("New"); + file->AddButton("Open"); + file->AddButton("Save"); + file->AddButton("Save As"); + file->AddSeparator(2_px); + file->AddButton("About"); + file->AddButton("Preferences"); + + auto* edit = topbar->AddSubmenu("Edit"); + edit->AddButton("Undo"); + edit->AddButton("Redo"); + edit->AddButton("Copy"); + edit->AddSeparator(2_px); + edit->AddButton("Paste"); + edit->AddButton("Cut Selection"); + + auto* view = topbar->AddSubmenu("View"); + view->AddButton("Zoom In"); + view->AddButton("Zoom Out"); + view->AddSeparator(2_px); + view->AddButton("Toggle Grid"); + + auto* level = topbar->AddSubmenu("Level"); + auto* layer = topbar->AddSubmenu("Layer"); + layer->AddButton("New"); + layer->AddButton("Open from File"); + layer->AddButton("Duplicate Selected"); + layer->AddButton("Delete Selected"); + layer->AddButton("Edit Selected"); + layer->AddButton("Export Layer"); + + + + + } + + bool Open() override { + if (!OpenGLWindow::Open()) return false; + + auto size = GetSize(); + auto vec_size = Vector2i(size.x, size.y); + if (!JGL::Init(vec_size, 0.f, 1.f)) + return false; + JGL::Update(vec_size); + + glClearColor(0.f, 0.f, 0.f, 0.f); + + glEnable(GL_DEPTH_TEST); + glDepthFunc(GL_LESS); + glDepthMask(GL_TRUE); + // TODO: Delete when we update to the next release of JGL + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); // NOTE: This MUST be called for text rendering to work properly!!! + + CreateWidgets(); + + return true; + } + + void Update(float elapsed) { + auto size = GetSize(); + Vector2i vSize = Vector2i(size.x, size.y); + + + JGL::Update(vSize); + scene->SetViewportSize(Vector2(vSize)); + scene->Update(elapsed); + } + + void Draw() { + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + //glMatrixMode(GL_MODELVIEW); + //glLoadIdentity(); + + + J2D::Begin(); + + J2D::End(); + + scene->Draw(); + } + + void OnRefresh(float elapsed) override { + Update(elapsed); + Draw(); + SwapBuffers(); + } + + enum JUI::MouseButton ToJUIEnum(const MouseButton& btn) { + if (btn == MouseButtons::Left) return JUI::MouseButton::Left; + if (btn == MouseButtons::Middle) return JUI::MouseButton::Middle; + if (btn == MouseButtons::Right) return JUI::MouseButton::Right; + + // Default condition. + return JUI::MouseButton::Left; + } + + void OnMouseButtonDown(const MouseButtonDownEvent &e) override { + auto btn = ToJUIEnum(e.Button); + + if (scene->ObserveMouseInput(btn, true)) return; + } + + void OnMouseButtonUp(const MouseButtonUpEvent &e) override { + auto btn = ToJUIEnum(e.Button); + if (scene->ObserveMouseInput(btn, false)) return; + } + + void OnMouseMove(const MouseMoveEvent &e) override { + Vector2 mposv2(e.Position.x, e.Position.y); + if (scene->ObserveMouseMovement(mposv2)) return; + } + + void OnKeyDown(const KeyDownEvent &e) override { + if (scene->ObserveKeyInput(e.key, true)) return; + } + + void OnKeyUp(const KeyUpEvent &e) override { + if (scene->ObserveKeyInput(e.key, false)) return; + } +}; \ No newline at end of file diff --git a/include/Entity.hpp b/include/Entity.hpp new file mode 100644 index 0000000..f1dc142 --- /dev/null +++ b/include/Entity.hpp @@ -0,0 +1,8 @@ +// +// Created by dawsh on 5/12/25. +// + +#ifndef ENTITY_HPP +#define ENTITY_HPP + +#endif //ENTITY_HPP diff --git a/include/Layer.hpp b/include/Layer.hpp new file mode 100644 index 0000000..c161efc --- /dev/null +++ b/include/Layer.hpp @@ -0,0 +1,8 @@ +// +// Created by dawsh on 5/12/25. +// + +#ifndef LAYER_HPP +#define LAYER_HPP + +#endif //LAYER_HPP diff --git a/include/Level.hpp b/include/Level.hpp new file mode 100644 index 0000000..c5dca1d --- /dev/null +++ b/include/Level.hpp @@ -0,0 +1,8 @@ +// +// Created by dawsh on 5/12/25. +// + +#ifndef LEVEL_HPP +#define LEVEL_HPP + +#endif //LEVEL_HPP diff --git a/include/TileLayer.hpp b/include/TileLayer.hpp new file mode 100644 index 0000000..23943cd --- /dev/null +++ b/include/TileLayer.hpp @@ -0,0 +1,16 @@ +#pragma once + +struct TileCell { + +}; + +class TileLayer { +public: + int rows; + int cols; + int cell_width; + int cell_height; + TileCell cells[][]; +protected: +private: +}; \ No newline at end of file diff --git a/include/Tileset.hpp b/include/Tileset.hpp new file mode 100644 index 0000000..afe34f1 --- /dev/null +++ b/include/Tileset.hpp @@ -0,0 +1,8 @@ +// +// Created by dawsh on 5/12/25. +// + +#ifndef TILESET_HPP +#define TILESET_HPP + +#endif //TILESET_HPP diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..3d70ace --- /dev/null +++ b/main.cpp @@ -0,0 +1,27 @@ +// +// Created by dawsh on 5/12/25. +// + +#include + +#include "ReWindow/Logger.h" + +int main() { + + ReWindow::Logger::Debug.EnableConsole(false); + + auto* standalone_app = new EditorApp(); + + bool success = standalone_app->Open(); + + if (!success) { + // TODO: FUCK + return -1; + } + + while (standalone_app->IsOpen()) { + standalone_app->ManagedRefresh(); + } + + return 0; +} diff --git a/src/EditorApp.cpp b/src/EditorApp.cpp new file mode 100644 index 0000000..1c72fc8 --- /dev/null +++ b/src/EditorApp.cpp @@ -0,0 +1 @@ +#include \ No newline at end of file