Initial Commit

This commit is contained in:
2025-05-12 21:26:34 -05:00
commit c15931f231
11 changed files with 335 additions and 0 deletions

76
CMakeLists.txt Normal file
View File

@@ -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)

24
cmake/CPM.cmake Normal file
View File

@@ -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})

9
include/Editor.hpp Normal file
View File

@@ -0,0 +1,9 @@
#pragma once
class Editor {
public:
protected:
private:
}

150
include/EditorApp.hpp Normal file
View File

@@ -0,0 +1,150 @@
#pragma once
#include <ReWindow/types/Window.h>
#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;
}
};

8
include/Entity.hpp Normal file
View File

@@ -0,0 +1,8 @@
//
// Created by dawsh on 5/12/25.
//
#ifndef ENTITY_HPP
#define ENTITY_HPP
#endif //ENTITY_HPP

8
include/Layer.hpp Normal file
View File

@@ -0,0 +1,8 @@
//
// Created by dawsh on 5/12/25.
//
#ifndef LAYER_HPP
#define LAYER_HPP
#endif //LAYER_HPP

8
include/Level.hpp Normal file
View File

@@ -0,0 +1,8 @@
//
// Created by dawsh on 5/12/25.
//
#ifndef LEVEL_HPP
#define LEVEL_HPP
#endif //LEVEL_HPP

16
include/TileLayer.hpp Normal file
View File

@@ -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:
};

8
include/Tileset.hpp Normal file
View File

@@ -0,0 +1,8 @@
//
// Created by dawsh on 5/12/25.
//
#ifndef TILESET_HPP
#define TILESET_HPP
#endif //TILESET_HPP

27
main.cpp Normal file
View File

@@ -0,0 +1,27 @@
//
// Created by dawsh on 5/12/25.
//
#include <EditorApp.hpp>
#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;
}

1
src/EditorApp.cpp Normal file
View File

@@ -0,0 +1 @@
#include <EditorApp.hpp>