summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorilotterytea <iltsu@alright.party>2025-02-01 14:54:55 +0500
committerilotterytea <iltsu@alright.party>2025-02-01 14:55:37 +0500
commit98bb51185eb053d56052ad9feb3420c258dbb601 (patch)
tree81562188ef0015a6c903bb985ab864014b80f4b4
parentf1ab4e564ea83540e513e1266c87e31c0eedf073 (diff)
upd: we migrated to sfml/imgui/c++ stack (project rewrite)
-rw-r--r--CMakeLists.txt56
-rw-r--r--README.md4
-rw-r--r--src/editor.c366
-rw-r--r--src/editor.h38
-rw-r--r--src/floor.c195
-rw-r--r--src/floor.h38
-rw-r--r--src/level.c38
-rw-r--r--src/level.h21
-rw-r--r--src/logger.c38
-rw-r--r--src/logger.h13
-rw-r--r--src/main.c87
-rw-r--r--src/main.cpp37
-rw-r--r--src/tileset.c38
-rw-r--r--src/tileset.h28
14 files changed, 68 insertions, 929 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 4840d9c..e39e28e 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -4,11 +4,11 @@ include(FetchContent)
project(
sillyeditor
VERSION 1.0
- DESCRIPTION "a simple doom-inspired level editor"
+ DESCRIPTION "a simple level editor"
)
-set(CMAKE_C_STANDARD 99)
-set(CMAKE_C_STANDARD_REQUIRED True)
+set(CMAKE_CXX_STANDARD 17)
+set(CMAKE_CXX_STANDARD_REQUIRED True)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
@@ -20,37 +20,39 @@ set_target_properties(
OUTPUT_NAME "editor"
)
-file(GLOB_RECURSE SRC_FILES "src/*.c" "src/*.h")
+file(GLOB_RECURSE SRC_FILES "src/*.cpp" "src/*.hpp")
target_sources(sillyeditor PRIVATE ${SRC_FILES})
-# raylib
-find_package(raylib QUIET)
-if (NOT raylib_FOUND)
- include(FetchContent)
- FetchContent_Declare(
- raylib
- URL https://github.com/raysan5/raylib/archive/refs/tags/5.5.tar.gz
- )
- FetchContent_MakeAvailable(raylib)
-endif()
-
-# raygui
+# sfml
+FetchContent_Declare(sfml
+ GIT_REPOSITORY https://github.com/SFML/SFML.git
+ GIT_TAG 3.0.0
+ GIT_SHALLOW ON
+ EXCLUDE_FROM_ALL
+ SYSTEM)
+FetchContent_MakeAvailable(sfml)
+
+# imgui
FetchContent_Declare(
- raygui
- GIT_REPOSITORY https://github.com/raysan5/raygui.git
- GIT_TAG 4.0
+ imgui
+ GIT_REPOSITORY https://github.com/ocornut/imgui.git
+ GIT_TAG v1.91.8
)
-FetchContent_MakeAvailable(raygui)
+FetchContent_MakeAvailable(imgui)
-# nativefiledialog
+# imgui-sfml
FetchContent_Declare(
- nfd
- GIT_REPOSITORY https://github.com/btzy/nativefiledialog-extended.git
- GIT_TAG master
+ imgui-sfml
+ GIT_REPOSITORY https://github.com/SFML/imgui-sfml.git
+ GIT_TAG v3.0
)
-FetchContent_MakeAvailable(nfd)
-target_include_directories(sillyeditor PRIVATE ${raygui_SOURCE_DIR}/src)
+set(SFML_DIR "${sfml_SOURCE_DIR}/cmake")
+set(IMGUI_DIR ${imgui_SOURCE_DIR})
+set(IMGUI_SFML_FIND_SFML OFF)
+FetchContent_MakeAvailable(imgui-sfml)
+
+target_include_directories(sillyeditor PRIVATE ${imgui_SOURCE_DIR})
-target_link_libraries(sillyeditor PRIVATE raylib m nfd)
+target_link_libraries(sillyeditor PRIVATE sfml-graphics ImGui-SFML::ImGui-SFML)
diff --git a/README.md b/README.md
index d9a5b15..b748742 100644
--- a/README.md
+++ b/README.md
@@ -1,7 +1,7 @@
# sillyeditor
-A simple 3D level editor.
-Made with [Raylib](https://raylib.com) and the C programming language.
+A simple level editor.
+Made with [SFML](https://www.sfml-dev.org/), [Dear ImGui](https://github.com/ocornut/imgui) and the C++ programming language. [It was previously written in C/Raylib!](https://github.com/ilotterytea/sillyeditor/tree/4334fb4bdca40ef75f81ec16e01a85e9e06ad26c)
## Compile from sources
diff --git a/src/editor.c b/src/editor.c
deleted file mode 100644
index c1d9463..0000000
--- a/src/editor.c
+++ /dev/null
@@ -1,366 +0,0 @@
-#include "editor.h"
-
-#include <stdbool.h>
-#include <stddef.h>
-#include <stdio.h>
-#include <stdlib.h>
-
-#include "logger.h"
-#include "nfd.h"
-#include "raylib.h"
-
-#define RAYGUI_IMPLEMENTATION
-#include "raygui.h"
-
-const char *EDITOR_MAIN_TABS[] = {"Build"};
-const int EDITOR_MAIN_TABS_SIZE =
- sizeof(EDITOR_MAIN_TABS) / sizeof(EDITOR_MAIN_TABS[0]);
-
-void SE_UpdateEditor(Editor *editor) {
- EditorState *state = &editor->state;
-
- // update selected layer
- if (state->activeTilesetTile != NULL &&
- state->activeTilesetTile->type != state->activeTileLayerId) {
- state->activeTileLayerId = state->activeTilesetTile->type;
- SE_LOG_INFO("Changed selected layer");
- }
-
- // update tile rotation
- if (IsKeyPressed(KEY_R)) {
- state->tileRotation += 90.0f;
- if (state->tileRotation >= 360.0f) {
- state->tileRotation = 0.0f;
- }
- }
-}
-
-void drawBuildTab(Editor *editor, Tileset *tileset, int x, int y, int width,
- int height, int padding) {
- GuiPanel((Rectangle){x, y + 24.0f, width, height}, NULL);
-
- // Displaying what tile is selected right now
- TilesetTile *activeTilesetTile = editor->state.activeTilesetTile;
-
- const char *selectedTileLabel;
-
- if (activeTilesetTile != NULL) {
- int type = activeTilesetTile->type;
- if (type == TILE_FLOOR) {
- selectedTileLabel = "FLOOR";
- } else if (type == TILE_WALL) {
- selectedTileLabel = "WALL";
- } else {
- selectedTileLabel = "SMTH";
- }
-
- DrawTextureEx(activeTilesetTile->texture,
- (Vector2){x + padding, y + padding * 3.0f}, 0.0f, 6.0f,
- WHITE);
-
- } else {
- selectedTileLabel = "???";
- DrawRectangle(x + padding, y + padding * 3.0f, TILE_WIDTH * 6.0f,
- TILE_HEIGHT * 6.0f, LIGHTGRAY);
- }
-
- GuiLabel((Rectangle){x + padding, y + padding * 2.0f, width - padding * 2.0f,
- 24.0f},
- selectedTileLabel);
-
- // Drawing rotation
- GuiLabel((Rectangle){x + padding * 7.0f, y + padding * 2.0f,
- width - padding * 2.0f, 24.0f},
- "Rotation");
-
- DrawCircle(x + padding * 7.0f + 10.0f, y + padding * 3.0f + 10.0f, 10.0f,
- LIGHTGRAY);
-
- DrawCircleSector(
- (Vector2){x + padding * 7.0f + 10.0f, y + padding * 3.0f + 10.0f}, 10.0f,
- 0.0f, editor->state.tileRotation, 4, GRAY);
-
- int rotationTextLength =
- snprintf(NULL, 0, "%.0f", editor->state.tileRotation);
- char *rotationText = malloc(rotationTextLength + 1);
- snprintf(rotationText, rotationTextLength + 1, "%.0f",
- editor->state.tileRotation);
-
- GuiLabel((Rectangle){x + padding * 7.0f + 25.0f, y + padding * 3.0f,
- width - padding * 2.0f, 24.0f},
- rotationText);
-
- free(rotationText);
-
- // Rendering
- Rectangle controlBounds = {x + padding, y + padding + 20.0f * 8.0f,
- width - padding * 2.0f, 200.0f};
- controlBounds.height = height - controlBounds.y - padding * 4.0f;
- Rectangle contentSize = {x + padding, y + padding, 10 * TILE_WIDTH, 1000};
-
- GuiScrollPanel(controlBounds, NULL, contentSize, &editor->state.panelScroll,
- &editor->state.panelView);
-
- BeginScissorMode(editor->state.panelView.x, editor->state.panelView.y,
- editor->state.panelView.width,
- editor->state.panelView.height);
-
- Vector2 mousePos = GetMousePosition();
-
- // rendering floor tiles in grid
- int row = 0, column = 0, texturesPerRow = 10;
- float scale = 3.0f;
- for (int i = 0; i < tileset->tileCount; i++) {
- TilesetTile *tile = tileset->tiles[i];
- if (tile == NULL) continue;
-
- row = i / texturesPerRow;
- column = i % texturesPerRow;
-
- int x = controlBounds.x + 5 + TILE_WIDTH * column * scale;
- int y = controlBounds.y + editor->state.panelScroll.y +
- TILE_HEIGHT * row * scale;
-
- DrawTextureEx(tile->texture, (Vector2){x, y}, 0.0f, scale, WHITE);
-
- bool isHovered =
- (x <= mousePos.x && mousePos.x <= x + TILE_WIDTH * scale) &&
- (y <= mousePos.y && mousePos.y <= y + TILE_HEIGHT * scale);
-
- bool sameTile =
- activeTilesetTile != NULL && activeTilesetTile->id == tile->id;
-
- // hover event
- if (isHovered || sameTile) {
- DrawRectangleLines(x, y, TILE_WIDTH * scale, TILE_HEIGHT * scale, YELLOW);
- }
-
- // select tile
- if (isHovered && IsMouseButtonDown(MOUSE_BUTTON_LEFT)) {
- editor->state.activeTilesetTile = tile;
- }
- }
-
- EndScissorMode();
-
- // create tile button
- if (GuiButton(
- (Rectangle){x + padding, height - padding - 12.0f, 24.0f, 24.0f},
- "#08#") &&
- editor->state.createBlockState == NULL) {
- SE_LOG_INFO("Creating a new block");
- EditorCreateBlockState *state = malloc(sizeof(EditorCreateBlockState));
- state->isFloor = true;
- state->isWall = false;
- state->upFilePath = NULL;
- editor->state.createBlockState = state;
- }
-}
-
-void drawTextures(EditorCreateBlockState *state, int wx, int wy, int ww, int wh,
- int pad) {
- if (state->isFloor) {
- GuiLabel((Rectangle){wx + pad, wy + pad + 24.0f * 2.0f, ww, 24.0f}, "UP");
- DrawTexture(state->upTexture, wx + pad, wy + pad + 24.0f * 3.0f, WHITE);
- } else {
- GuiLabel((Rectangle){wx + pad, wy + pad + 24.0f * 2.0f, ww, 24.0f},
- "UP (2D)");
- DrawTexture(state->upTexture, wx + pad, wy + pad + 24.0f * 3.0f, WHITE);
-
- GuiLabel((Rectangle){wx + pad + 24.0f * 3.0f, wy + pad + 24.0f * 2.0f, ww,
- 24.0f},
- "CORNER (2D)");
- DrawTexture(state->cornerTexture, wx + pad + 24.0f * 3.0f,
- wy + pad + 24.0f * 3.0f, WHITE);
-
- GuiLabel((Rectangle){wx + pad + 24.0f * 7.0f, wy + pad + 24.0f * 2.0f, ww,
- 24.0f},
- "SIDE (3D)");
- DrawTexture(state->sideTexture, wx + pad + 24.0f * 7.0f,
- wy + pad + 24.0f * 3.0f, WHITE);
- }
-}
-
-void drawPreview(EditorCreateBlockState *state, int wx, int wy, int ww, int wh,
- int pad) {
- GuiLabel((Rectangle){wx + pad, wy + pad + 24.0f * 4.0f, ww, 24.0f},
- "2D PREVIEW");
- for (int x = 0; x < 10; x++) {
- for (int y = 0; y < 5; y++) {
- if (state->isFloor) {
- DrawTexture(state->upTexture, wx + pad + x * TILE_WIDTH,
- wy + pad + 24.0f * 5.0f + y * TILE_HEIGHT, WHITE);
- } else {
- Vector2 position = {x * TILE_WIDTH, y * TILE_HEIGHT};
- position.x += wx + pad;
- position.y += wy + pad + 24.0f * 5.0f;
-
- // --- CORNERS ---
- // top left
- if (x == 0 && y == 0) {
- DrawTextureEx(state->cornerTexture, position, 0.0f, 1.0f, WHITE);
- }
- // top right
- else if (x == 9 && y == 0) {
- DrawTextureEx(state->cornerTexture, position, 90.0f, 1.0f, WHITE);
- }
- // bottom left
- else if (x == 0 && y == 4) {
- DrawTextureEx(state->cornerTexture, position, 270.0f, 1.0f, WHITE);
- }
- // bottom right
- else if (x == 9 && y == 4) {
- DrawTextureEx(state->cornerTexture, position, 180.0f, 1.0f, WHITE);
- }
-
- // --- SIDES ---
- // top
- else if (y == 0) {
- DrawTextureEx(state->upTexture, position, 0.0f, 1.0f, WHITE);
- }
- // left
- else if (x == 0 && y > 1) {
- DrawTextureEx(state->upTexture, position, 270.0f, 1.0f, WHITE);
- }
- // right
- else if (x == 9) {
- DrawTextureEx(state->upTexture, position, 90.0f, 1.0f, WHITE);
- }
- // bottom
- else if (y == 4 && x > 1) {
- DrawTextureEx(state->upTexture, position, 180.0f, 1.0f, WHITE);
- }
- }
- }
- }
-}
-
-void loadTexture(EditorCreateBlockState *state) {
- nfdu8char_t *outPath;
- nfdu8filteritem_t filters[1] = {{"Images", "png"}};
- nfdopendialogu8args_t args = {0};
- args.filterList = filters;
- args.filterCount = 1;
- nfdresult_t result = NFD_OpenDialogU8_With(&outPath, &args);
-
- if (result == NFD_OKAY) {
- if (!IsFileExtension(outPath, ".png")) {
- SE_LOG_WARN("The editor only supports .png files");
- return;
- }
-
- // unloading old texture
- if (state->upFilePath != NULL) {
- UnloadTexture(state->upTexture);
- free(state->upFilePath);
- }
-
- state->upFilePath = outPath;
- Image image = LoadImage(state->upFilePath);
-
- if (image.width != TILE_WIDTH || image.height != TILE_HEIGHT) {
- ImageResizeNN(&image, TILE_WIDTH, TILE_HEIGHT);
- }
-
- state->upTexture = LoadTextureFromImage(image);
-
- UnloadImage(image);
- }
-}
-
-void drawCreatingNewBlock(Editor *editor, Tileset *tileset) {
- EditorCreateBlockState *state = editor->state.createBlockState;
-
- int ww = 300;
- int wh = 280;
-
- int wx = GetScreenWidth() / 2.0f - ww / 2.0f;
- int wy = GetScreenHeight() / 2.0f - wh / 2.0f;
- int pad = 20;
-
- int close = GuiWindowBox((Rectangle){wx, wy, ww, wh}, "Creating a new block");
-
- // --- Block type ---
- GuiLabel((Rectangle){wx + pad, wy + pad, ww - pad * 2, 24.0f}, "Select type");
-
- GuiCheckBox((Rectangle){wx + pad, wy + pad + 24.0f, 24.0f, 24.0f}, "Floor",
- &state->isFloor);
- if (state->isFloor) state->isWall = false;
-
- GuiCheckBox(
- (Rectangle){wx + pad * 4.0f + 24.0f, wy + pad + 24.0f, 24.0f, 24.0f},
- "Wall", &state->isWall);
- if (state->isWall) state->isFloor = false;
- if (!state->isWall && !state->isFloor) state->isFloor = true;
-
- // --- Texture loading ---
- // Loading UP texture
- if (state->upFilePath == NULL) {
- if (GuiButton((Rectangle){wx + pad, wy + pad + 24.0f * 3.0f, 64.0f, 24.0f},
- "Load")) {
- loadTexture(state);
- }
- }
- // Changing the texture
- else {
- if (GuiButton((Rectangle){wx + pad * 1.5f + TILE_WIDTH,
- wy + pad + 24.0f * 3.0f - TILE_WIDTH / 2.0f,
- 24.0f, 24.0f},
- "#211#")) {
- loadTexture(state);
- }
- }
-
- // --- Texture preview ---
- // Up texture
- drawTextures(state, wx, wy, ww, wh, pad);
-
- drawPreview(state, wx, wy, ww, wh, pad);
-
- int createButton = GuiButton(
- (Rectangle){wx + pad, wy + wh - pad * 2.0f, ww - pad * 2.0f, 32.0f},
- "Create");
-
- if (createButton) {
- close = true;
-
- TilesetTileType type = state->isFloor ? TILE_FLOOR : TILE_WALL;
-
- SE_AddTilesetTile(tileset, state->upTexture, type);
- }
-
- if (close) {
- if (state->upFilePath != NULL) {
- free(state->upFilePath);
- state->upFilePath = NULL;
-
- if (!createButton) {
- UnloadTexture(state->upTexture);
- }
- }
-
- free(state);
- editor->state.createBlockState = NULL;
- }
-}
-
-void SE_DrawEditor(Editor *editor, Tileset *tileset) {
- switch (editor->state.activeMainTab) {
- case 0: {
- drawBuildTab(editor, tileset, EDITOR_TOOLKIT_X, EDITOR_TOOLKIT_Y,
- EDITOR_TOOLKIT_WIDTH, EDITOR_TOOLKIT_HEIGHT, 20);
- break;
- }
- default:
- break;
- }
-
- GuiTabBar((Rectangle){EDITOR_TOOLKIT_X, EDITOR_TOOLKIT_Y, 100.0, 24.0f},
- EDITOR_MAIN_TABS, EDITOR_MAIN_TABS_SIZE,
- &editor->state.activeMainTab);
-
- // Creating new block
- if (editor->state.createBlockState != NULL) {
- drawCreatingNewBlock(editor, tileset);
- }
-} \ No newline at end of file
diff --git a/src/editor.h b/src/editor.h
deleted file mode 100644
index 9b2cda5..0000000
--- a/src/editor.h
+++ /dev/null
@@ -1,38 +0,0 @@
-#ifndef __EDITOR_H__
-#define __EDITOR_H__
-#include <raylib.h>
-#include <stdbool.h>
-
-#include "tileset.h"
-
-#define EDITOR_TOOLKIT_WIDTH 400.0f
-#define EDITOR_TOOLKIT_HEIGHT GetScreenHeight()
-#define EDITOR_TOOLKIT_X GetScreenWidth() - EDITOR_TOOLKIT_WIDTH
-#define EDITOR_TOOLKIT_Y 0.0f
-
-typedef struct {
- bool isFloor, isWall;
- char *upFilePath, *sideFilePath, *cornerFilePath;
- Texture2D upTexture, sideTexture, cornerTexture;
-} EditorCreateBlockState;
-
-typedef struct {
- int activeMainTab;
- int activeTileLayerId;
-
- float tileRotation;
-
- TilesetTile *activeTilesetTile;
- EditorCreateBlockState *createBlockState;
- Rectangle panelView;
- Vector2 panelScroll;
-} EditorState;
-
-typedef struct {
- EditorState state;
-} Editor;
-
-void SE_UpdateEditor(Editor *editor);
-void SE_DrawEditor(Editor *editor, Tileset *tileset);
-
-#endif
diff --git a/src/floor.c b/src/floor.c
deleted file mode 100644
index 91dcf86..0000000
--- a/src/floor.c
+++ /dev/null
@@ -1,195 +0,0 @@
-#include "floor.h"
-
-#include "logger.h"
-#include "stdlib.h"
-
-Tile *SE_CreateTile(TileLayer *layer, TilesetTile *tilesetTile) {
- Tile *tile = malloc(sizeof(Tile));
-
- tile->id = layer->tileCount;
- tile->tilesetTile = tilesetTile;
- tile->position = (Vector2){0.0f, 0.0f};
- tile->rotation = 0.0f;
-
- layer->tiles[layer->tileCount] = tile;
- layer->tileCount++;
-
- return tile;
-}
-
-void SE_RemoveTile(TileLayer *layer, Tile *tile) {
- int index = -1;
-
- for (int i = 0; i < layer->tileCount; i++) {
- Tile *t = layer->tiles[i];
- if (t->id == tile->id) {
- index = i;
- break;
- }
- }
-
- if (index == -1) {
- SE_LOG_WARN("Tile doesn't belong to the layer");
- return;
- }
-
- free(tile);
- layer->tiles[index] = NULL;
-
- // clearing layer from null values
- int i, j = 0;
- Tile **tiles = layer->tiles;
- int *count = &layer->tileCount;
-
- for (i = 0; i < *count; i++) {
- if (tiles[i] != NULL) {
- tiles[j++] = tiles[i];
- }
- }
-
- *count = j;
-
- for (i = j; i < *count; i++) {
- tiles[i] = NULL;
- }
-}
-
-Tile *SE_FindTileAtPosition(TileLayer *layer, Vector2 position) {
- Tile *tile = NULL;
-
- for (int i = 0; i < layer->tileCount; i++) {
- Tile *t = layer->tiles[i];
- if (t->position.x == position.x && t->position.y == position.y) {
- tile = t;
- break;
- }
- }
-
- return tile;
-}
-
-TileFloor *SE_CreateTileFloor(int width, int height) {
- TileFloor *floor = malloc(sizeof(TileFloor));
-
- floor->width = width;
- floor->height = height;
- floor->layerCount = 0;
-
- return floor;
-}
-
-TileLayer *SE_CreateTileLayer(TileFloor *floor) {
- TileLayer *layer = malloc(sizeof(TileLayer));
-
- layer->tileCount = 0;
- layer->index = floor->layerCount;
-
- floor->layers[floor->layerCount] = layer;
- floor->layerCount++;
-
- return layer;
-}
-
-void SE_UpdateTileFloor(EditorState *state, TileFloor *floor,
- Camera2D *camera) {
- // creating a new layer if it does not exists
- TileLayer *layer;
- if (floor->layerCount <= state->activeTileLayerId) {
- layer = SE_CreateTileLayer(floor);
- } else {
- layer = floor->layers[state->activeTileLayerId];
- }
-
- // tile manipulation
- Vector2 mousePos = GetScreenToWorld2D(GetMousePosition(), *camera);
-
- for (int x = 0; x < floor->width; x++) {
- for (int y = 0; y < floor->height; y++) {
- Vector2 pos = (Vector2){x, y};
-
- if (CheckCollisionPointRec(
- mousePos, (Rectangle){pos.x * camera->zoom, pos.y * camera->zoom,
- camera->zoom, camera->zoom})) {
- // placing tiles
- if (IsMouseButtonDown(MOUSE_BUTTON_LEFT) &&
- state->activeTilesetTile != NULL) {
- Tile *tile = SE_FindTileAtPosition(layer, pos);
-
- if (tile == NULL) {
- tile = SE_CreateTile(layer, state->activeTilesetTile);
- tile->position = pos;
- }
-
- tile->rotation = state->tileRotation;
- tile->tilesetTile = state->activeTilesetTile;
- }
-
- // removing tiles
- if (IsMouseButtonDown(MOUSE_BUTTON_RIGHT)) {
- Tile *tile = SE_FindTileAtPosition(layer, pos);
- if (tile != NULL) {
- SE_RemoveTile(layer, tile);
- }
- }
- }
- }
- }
-}
-
-void SE_DrawTileFloor(TileFloor *floor, EditorState *state, Camera2D *camera) {
- // draw placed tiles
- for (int layerIndex = 0; layerIndex < floor->layerCount; layerIndex++) {
- TileLayer *layer = floor->layers[layerIndex];
-
- for (int tileIndex = 0; tileIndex < layer->tileCount; tileIndex++) {
- Tile *tile = layer->tiles[tileIndex];
-
- Rectangle s = {0, 0, TILE_WIDTH, TILE_HEIGHT};
- Rectangle d = {tile->position.x * camera->zoom,
- tile->position.y * camera->zoom, camera->zoom,
- camera->zoom};
-
- Vector2 o = {0, 0};
-
- if (tile->rotation == 90.0f) {
- o.y = d.height;
- } else if (tile->rotation == 180.0f) {
- o.x = d.width;
- o.y = d.height;
- } else if (tile->rotation == 270.0f) {
- o.x = d.width;
- }
-
- DrawTexturePro(tile->tilesetTile->texture, s, d, o, tile->rotation,
- WHITE);
- }
- }
-
- // draw active tile
- if (state->activeTilesetTile != NULL) {
- Vector2 mousePos = GetScreenToWorld2D(GetMousePosition(), *camera);
- Rectangle s = {0, 0, TILE_WIDTH, TILE_HEIGHT};
- Rectangle d = {mousePos.x, mousePos.y, camera->zoom / 2.0f,
- camera->zoom / 2.0f};
-
- Vector2 o = {d.width / 2.0f, d.height / 2.0f};
-
- DrawTexturePro(state->activeTilesetTile->texture, s, d, o,
- state->tileRotation, WHITE);
- }
-}
-
-void SE_UnloadTileFloor(TileFloor *floor) {
- for (int layerIndex = 0; layerIndex < floor->layerCount; layerIndex++) {
- TileLayer *layer = floor->layers[layerIndex];
-
- for (int tileIndex = 0; tileIndex < layer->tileCount; tileIndex++) {
- Tile *tile = layer->tiles[tileIndex];
- free(tile);
- }
-
- free(layer);
- }
-
- free(floor);
-} \ No newline at end of file
diff --git a/src/floor.h b/src/floor.h
deleted file mode 100644
index ad3b2da..0000000
--- a/src/floor.h
+++ /dev/null
@@ -1,38 +0,0 @@
-#ifndef __FLOOR_H_
-#define __FLOOR_H_
-
-#include "editor.h"
-#include "raylib.h"
-#include "tileset.h"
-
-typedef struct {
- int id;
- Vector2 position;
- float rotation;
- TilesetTile *tilesetTile;
-} Tile;
-
-typedef struct {
- int index;
- int tileCount;
- Tile *tiles[];
-} TileLayer;
-
-typedef struct {
- int width, height;
- int layerCount;
- TileLayer *layers[];
-} TileFloor;
-
-Tile *SE_CreateTile(TileLayer *layer, TilesetTile *tilesetTile);
-void SE_RemoveTile(TileLayer *layer, Tile *tile);
-Tile *SE_FindTileAtPosition(TileLayer *layer, Vector2 position);
-
-TileLayer *SE_CreateTileLayer(TileFloor *floor);
-
-TileFloor *SE_CreateTileFloor(int width, int height);
-void SE_UpdateTileFloor(EditorState *state, TileFloor *floor, Camera2D *camera);
-void SE_DrawTileFloor(TileFloor *floor, EditorState *state, Camera2D *camera);
-void SE_UnloadTileFloor(TileFloor *floor);
-
-#endif \ No newline at end of file
diff --git a/src/level.c b/src/level.c
deleted file mode 100644
index cda6594..0000000
--- a/src/level.c
+++ /dev/null
@@ -1,38 +0,0 @@
-#include "level.h"
-
-#include <stdio.h>
-#include <stdlib.h>
-
-#include "raylib.h"
-
-Level *SE_CreateLevel(int width, int height) {
- Level *level = malloc(sizeof(Level) + sizeof(Vector3) * width * height);
-
- for (int i = 0; i < width * height; i++) {
- level->sides[i] = NULL;
- }
-
- level->width = width;
- level->height = height;
-
- return level;
-}
-
-void SE_RenderLevel(Level *level, int zoomScale) {
- for (int i = 0; i < level->width * level->height; i++) {
- Side *side = level->sides[i];
- if (side == NULL) continue;
-
- DrawLine(side->a.x * zoomScale, side->a.y * zoomScale,
- side->b.x * zoomScale, side->b.y * zoomScale, RED);
- }
-}
-
-void SE_FreeLevel(Level *level) {
- for (int i = 0; i < level->width * level->height; i++) {
- Side *side = level->sides[i];
- if (side == NULL) continue;
- free(side);
- }
- free(level);
-}
diff --git a/src/level.h b/src/level.h
deleted file mode 100644
index 35e8cb8..0000000
--- a/src/level.h
+++ /dev/null
@@ -1,21 +0,0 @@
-#ifndef __LEVEL_H__
-#define __LEVEL_H__
-
-typedef struct {
- int x, y;
-} Point;
-
-typedef struct {
- Point a, b;
-} Side;
-
-typedef struct {
- int width, height;
- Side *sides[];
-} Level;
-
-Level *SE_CreateLevel(int width, int height);
-void SE_RenderLevel(Level *level, int zoomScale);
-void SE_FreeLevel(Level *level);
-
-#endif
diff --git a/src/logger.c b/src/logger.c
deleted file mode 100644
index 3b7820a..0000000
--- a/src/logger.c
+++ /dev/null
@@ -1,38 +0,0 @@
-#include "logger.h"
-
-#include <stdio.h>
-#include <time.h>
-
-#include "raylib.h"
-
-// cv pasted from
-// https://www.raylib.com/examples/core/loader.html?name=core_custom_logging
-// :tf:
-void SE_Logger(int type, const char *text, va_list args) {
- char timeStr[64] = {0};
- time_t now = time(NULL);
- struct tm *tm_info = localtime(&now);
-
- strftime(timeStr, sizeof(timeStr), "%Y-%m-%d %H:%M:%S", tm_info);
- printf("[%s] ", timeStr);
-
- switch (type) {
- case LOG_INFO:
- printf("[INFO] : ");
- break;
- case LOG_ERROR:
- printf("[ERROR]: ");
- break;
- case LOG_WARNING:
- printf("[WARN] : ");
- break;
- case LOG_DEBUG:
- printf("[DEBUG]: ");
- break;
- default:
- break;
- }
-
- vprintf(text, args);
- printf("\n");
-} \ No newline at end of file
diff --git a/src/logger.h b/src/logger.h
deleted file mode 100644
index f42b441..0000000
--- a/src/logger.h
+++ /dev/null
@@ -1,13 +0,0 @@
-#ifndef __LOGGER_H__
-#define __LOGGER_H__
-
-#define SE_LOG_INFO(x) SE_Logger(LOG_INFO, x, NULL)
-#define SE_LOG_WARN(x) SE_Logger(LOG_WARNING, x, NULL)
-#define SE_LOG_DEBUG(x) SE_Logger(LOG_DEBUG, x, NULL)
-#define SE_LOG_ERROR(x) SE_Logger(LOG_ERROR, x, NULL)
-
-#include <stdarg.h>
-
-void SE_Logger(int type, const char *text, va_list args);
-
-#endif \ No newline at end of file
diff --git a/src/main.c b/src/main.c
deleted file mode 100644
index 5ba9463..0000000
--- a/src/main.c
+++ /dev/null
@@ -1,87 +0,0 @@
-#include <stddef.h>
-#include <stdio.h>
-#include <stdlib.h>
-
-#include "editor.h"
-#include "floor.h"
-#include "logger.h"
-#include "nfd.h"
-#include "raylib.h"
-#include "tileset.h"
-
-int main() {
- NFD_Init();
- SetTraceLogCallback(SE_Logger);
-
- SetConfigFlags(FLAG_WINDOW_RESIZABLE);
- InitWindow(800, 600, "sillyeditor");
- SetTargetFPS(60);
- SetWindowMinSize(800, 600);
-
- Editor editor = {0};
- editor.state.activeTileLayerId = 0;
-
- Tileset* tileset = SE_CreateTileset();
- TileFloor* floor = SE_CreateTileFloor(30, 30);
-
- Camera2D camera = {0};
- camera.target = (Vector2){0.0f, 0.0f};
- camera.offset = (Vector2){0.0f, 0.0f};
- camera.rotation = 0.0f;
- camera.zoom = 4.0f;
-
- while (!WindowShouldClose()) {
- SE_UpdateEditor(&editor);
-
- bool isEditorFocused =
- CheckCollisionPointRec(
- GetMousePosition(),
- (Rectangle){0.0f, 0.0f, EDITOR_TOOLKIT_X, GetScreenHeight()}) &&
- editor.state.createBlockState == NULL;
-
- if (isEditorFocused) {
- SE_UpdateTileFloor(&editor.state, floor, &camera);
-
- if (GetMouseWheelMove() != 0.0) {
- camera.zoom += (int)GetMouseWheelMove();
-
- if (camera.zoom > 6.0f)
- camera.zoom = 6.0f;
- else if (camera.zoom < 4.0f)
- camera.zoom = 4.0f;
- }
-
- if (IsMouseButtonDown(MOUSE_BUTTON_MIDDLE)) {
- Vector2 mousePos = GetMouseDelta();
- camera.target.x -= mousePos.x / 5.0f;
- camera.target.y -= mousePos.y / 5.0f;
- }
- }
-
- BeginDrawing();
- ClearBackground(RAYWHITE);
-
- BeginMode2D(camera);
- SE_DrawTileFloor(floor, &editor.state, &camera);
-
- // rendering grid
- for (int x = 0; x < floor->width; x++) {
- for (int y = 0; y < floor->height; y++) {
- DrawRectangleLines(x * camera.zoom, y * camera.zoom, camera.zoom,
- camera.zoom, BLACK);
- }
- }
-
- EndMode2D();
-
- SE_DrawEditor(&editor, tileset);
-
- EndDrawing();
- }
-
- SE_UnloadTileFloor(floor);
- SE_UnloadTileset(tileset);
- CloseWindow();
-
- return 0;
-}
diff --git a/src/main.cpp b/src/main.cpp
new file mode 100644
index 0000000..5bb7884
--- /dev/null
+++ b/src/main.cpp
@@ -0,0 +1,37 @@
+#include <imgui-SFML.h>
+#include <imgui.h>
+
+#include <SFML/Graphics/RenderWindow.hpp>
+#include <SFML/System/Clock.hpp>
+#include <SFML/Window/Event.hpp>
+#include <SFML/Window/VideoMode.hpp>
+#include <optional>
+
+int main() {
+ sf::RenderWindow window(sf::VideoMode({800, 600}), "sillyeditor");
+ window.setFramerateLimit(60);
+ ImGui::SFML::Init(window);
+
+ sf::Clock deltaClock;
+ while (window.isOpen()) {
+ while (const std::optional<sf::Event> event = window.pollEvent()) {
+ if (event.has_value()) {
+ sf::Event e = event.value();
+ ImGui::SFML::ProcessEvent(window, e);
+ }
+
+ if (event->is<sf::Event::Closed>()) {
+ window.close();
+ }
+ }
+
+ ImGui::SFML::Update(window, deltaClock.restart());
+
+ window.clear();
+
+ ImGui::SFML::Render(window);
+ window.display();
+ }
+
+ return 0;
+} \ No newline at end of file
diff --git a/src/tileset.c b/src/tileset.c
deleted file mode 100644
index d3cd9c8..0000000
--- a/src/tileset.c
+++ /dev/null
@@ -1,38 +0,0 @@
-#include "tileset.h"
-
-#include "stdlib.h"
-
-Tileset *SE_CreateTileset() {
- Tileset *set = malloc(sizeof(Tileset) * 100);
- set->tileCount = 0;
- return set;
-}
-
-TilesetTile *SE_AddTilesetTile(Tileset *set, Texture2D texture,
- TilesetTileType type) {
- TilesetTile *tile =
- malloc(sizeof(TilesetTile) + texture.width * texture.height);
-
- tile->id = set->tileCount;
- tile->texture = texture;
- tile->type = type;
-
- set->tileCount++;
- set->tiles[tile->id] = tile;
-
- return tile;
-}
-
-void SE_UnloadTilesetTile(TilesetTile *tile) {
- UnloadTexture(tile->texture);
- free(tile);
-}
-
-void SE_UnloadTileset(Tileset *set) {
- for (int i = 0; i < set->tileCount; i++) {
- TilesetTile *tile = set->tiles[i];
- SE_UnloadTilesetTile(tile);
- }
-
- free(set);
-} \ No newline at end of file
diff --git a/src/tileset.h b/src/tileset.h
deleted file mode 100644
index 3f74808..0000000
--- a/src/tileset.h
+++ /dev/null
@@ -1,28 +0,0 @@
-#ifndef __TEXTURE_H__
-#define __TEXTURE_H__
-
-#include "raylib.h"
-
-#define TILE_WIDTH 16
-#define TILE_HEIGHT 16
-
-typedef enum { TILE_FLOOR = 0, TILE_WALL } TilesetTileType;
-
-typedef struct {
- int id;
- Texture2D texture;
- TilesetTileType type;
-} TilesetTile;
-
-typedef struct {
- int tileCount;
- TilesetTile *tiles[];
-} Tileset;
-
-Tileset *SE_CreateTileset();
-TilesetTile *SE_AddTilesetTile(Tileset *set, Texture2D texture,
- TilesetTileType type);
-void SE_UnloadTilesetTile(TilesetTile *tile);
-void SE_UnloadTileset(Tileset *set);
-
-#endif \ No newline at end of file