diff options
| author | ilotterytea <iltsu@alright.party> | 2025-01-26 20:37:46 +0500 |
|---|---|---|
| committer | ilotterytea <iltsu@alright.party> | 2025-01-26 20:37:46 +0500 |
| commit | 22d120fbfbe65a14478f16d6d25b215031753e06 (patch) | |
| tree | 88e62de2634ef1483dd4794387d207d9c1ede8d8 | |
| parent | 49051c9b98b2d19ed5b61a874394904e0ba086ab (diff) | |
feat: render selected tile
| -rw-r--r-- | src/editor.c | 61 |
1 files changed, 30 insertions, 31 deletions
diff --git a/src/editor.c b/src/editor.c index 78c3d60..ce5c5ae 100644 --- a/src/editor.c +++ b/src/editor.c @@ -9,7 +9,6 @@ #define RAYGUI_IMPLEMENTATION #include "raygui.h" - #include "xd.h" const char *EDITOR_MAIN_TABS[] = {"Build"}; @@ -26,44 +25,44 @@ void SE_DrawEditor(Editor *editor, Camera2D *camera) { for (int x = 0; x < floor->width; x++) { for (int y = 0; y < floor->height; y++) { float rx = x * zoom, ry = y * zoom; - Color innerColor = RAYWHITE; - Color borderColor = LIGHTGRAY; + DrawRectangleLines(rx, ry, zoom, zoom, LIGHTGRAY); - // recolor the tile if the cursor above the tile if ((rx < mousePos.x && mousePos.x < rx + zoom) && (ry < mousePos.y && mousePos.y < ry + zoom)) { - innerColor = SKYBLUE; - borderColor = BLUE; - - // placing tiles - if (IsMouseButtonDown(MOUSE_BUTTON_LEFT) && - editor->state.selectedTile != NULL) { - EditorTile *t = NULL; - // checking for existing tiles on the position - for (int i = 0; i < editor->state.cache.tilesCount; i++) { - EditorTile *tt = editor->state.cache.tiles[i]; - - if (tt == NULL) continue; - - if (tt->position.x == x && tt->position.y == y) { - t = tt; - break; + // rendering selected tile + if (editor->state.selectedTile != NULL) { + EditorTileData *t = editor->state.selectedTile; + Rectangle s = {0, 0, 16, 16}; + Rectangle d = {rx, ry, zoom, zoom}; + + DrawTexturePro(t->texture, s, d, (Vector2){0, 0}, 0.0f, WHITE); + + // placing tiles + if (IsMouseButtonDown(MOUSE_BUTTON_LEFT)) { + EditorTile *t = NULL; + // checking for existing tiles on the position + for (int i = 0; i < editor->state.cache.tilesCount; i++) { + EditorTile *tt = editor->state.cache.tiles[i]; + + if (tt == NULL) continue; + + if (tt->position.x == x && tt->position.y == y) { + t = tt; + break; + } } - } - if (t == NULL) { - t = malloc(sizeof(EditorTile)); - t->position = (Vector2){x, y}; - editor->state.cache.tiles[editor->state.cache.tilesCount] = t; - editor->state.cache.tilesCount++; - } + if (t == NULL) { + t = malloc(sizeof(EditorTile)); + t->position = (Vector2){x, y}; + editor->state.cache.tiles[editor->state.cache.tilesCount] = t; + editor->state.cache.tilesCount++; + } - t->tile = editor->state.selectedTile; + t->tile = editor->state.selectedTile; + } } } - - DrawRectangle(rx, ry, zoom, zoom, innerColor); - DrawRectangleLines(rx, ry, zoom, zoom, borderColor); } } |
