summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/editor.c16
-rw-r--r--src/editor.h43
-rw-r--r--src/main.c29
3 files changed, 47 insertions, 41 deletions
diff --git a/src/editor.c b/src/editor.c
index 8728564..7d7c04f 100644
--- a/src/editor.c
+++ b/src/editor.c
@@ -49,7 +49,8 @@ void SE_DrawEditor(Editor *editor, Camera2D *camera) {
DrawTexturePro(t->texture, s, d, (Vector2){0, 0}, 0.0f, WHITE);
// placing tiles
- if (IsMouseButtonDown(MOUSE_BUTTON_LEFT)) {
+ if (IsMouseButtonDown(MOUSE_BUTTON_LEFT) &&
+ GetMousePosition().x < EDITOR_TOOLKIT_X) {
EditorTile *t = NULL;
// checking for existing tiles on the position
for (int i = 0; i < editor->state.cache.tilesCount; i++) {
@@ -368,22 +369,19 @@ void drawCreatingNewBlock(Editor *editor) {
}
void SE_DrawEditorToolkit(Editor *editor) {
- float width = 400.0f;
- float height = GetScreenHeight();
- float x = GetScreenWidth() - width;
- float y = 0;
-
switch (editor->state.activeMainTab) {
case 0: {
- drawBuildTab(editor, x, y, width, height);
+ drawBuildTab(editor, EDITOR_TOOLKIT_X, EDITOR_TOOLKIT_Y,
+ EDITOR_TOOLKIT_WIDTH, EDITOR_TOOLKIT_HEIGHT);
break;
}
default:
break;
}
- GuiTabBar((Rectangle){x, y, 100.0, 24.0f}, EDITOR_MAIN_TABS,
- EDITOR_MAIN_TABS_SIZE, &editor->state.activeMainTab);
+ 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) {
diff --git a/src/editor.h b/src/editor.h
index 5e51682..0c32cdf 100644
--- a/src/editor.h
+++ b/src/editor.h
@@ -5,44 +5,49 @@
#include "xd.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
+
#define TEXTURE_WIDTH 16.0f
#define TEXTURE_HEIGHT 16.0f
typedef struct {
- bool isFloor, isWall;
- char *upFilePath, *sideFilePath, *cornerFilePath;
- Texture2D upTexture, sideTexture, cornerTexture;
+ bool isFloor, isWall;
+ char *upFilePath, *sideFilePath, *cornerFilePath;
+ Texture2D upTexture, sideTexture, cornerTexture;
} EditorCreateBlockState;
typedef struct {
- XdTileData data;
- Texture2D texture;
+ XdTileData data;
+ Texture2D texture;
} EditorTileData;
typedef struct {
- EditorTileData *tile;
- Vector2 position;
+ EditorTileData *tile;
+ Vector2 position;
} EditorTile;
typedef struct {
- int tileDataSize;
- int tilesCount;
- EditorTileData *tileData[200];
- EditorTile *tiles[];
+ int tileDataSize;
+ int tilesCount;
+ EditorTileData *tileData[200];
+ EditorTile *tiles[];
} EditorCache;
typedef struct {
- int currentLevel, currentLayer, activeMainTab;
- EditorCreateBlockState *createBlockState;
- Rectangle panelView;
- Vector2 panelScroll;
- EditorTileData *selectedTile;
- EditorCache cache;
+ int currentLevel, currentLayer, activeMainTab;
+ EditorCreateBlockState *createBlockState;
+ Rectangle panelView;
+ Vector2 panelScroll;
+ EditorTileData *selectedTile;
+ EditorCache cache;
} EditorState;
typedef struct {
- XdData *data;
- EditorState state;
+ XdData *data;
+ EditorState state;
} Editor;
void SE_DrawEditor(Editor *editor, Camera2D *camera);
diff --git a/src/main.c b/src/main.c
index cc9c25e..271ce40 100644
--- a/src/main.c
+++ b/src/main.c
@@ -42,19 +42,22 @@ int main() {
camera.zoom = 4.0f;
while (!WindowShouldClose()) {
- 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;
+ // interact with the map if the mouse is outside build tab
+ if (GetMousePosition().x < EDITOR_TOOLKIT_X) {
+ 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();