Getting around to cleaning drawing code finally.
This commit is contained in:
@ -4,6 +4,7 @@
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
# Subdirs
|
||||
add_subdirectory(draw)
|
||||
|
||||
# Sources
|
||||
target_sources(${DAWN_TARGET_NAME}
|
||||
|
15
src/dawn/display/draw/CMakeLists.txt
Normal file
15
src/dawn/display/draw/CMakeLists.txt
Normal file
@ -0,0 +1,15 @@
|
||||
# Copyright (c) 2024 Dominic Masters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
# Subdirs
|
||||
|
||||
# Sources
|
||||
target_sources(${DAWN_TARGET_NAME}
|
||||
PRIVATE
|
||||
drawmap.c
|
||||
drawtext.c
|
||||
drawshape.c
|
||||
drawui.c
|
||||
)
|
91
src/dawn/display/draw/drawmap.c
Normal file
91
src/dawn/display/draw/drawmap.c
Normal file
@ -0,0 +1,91 @@
|
||||
/**
|
||||
* Copyright (c) 2024 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "drawmap.h"
|
||||
#include "assert/assert.h"
|
||||
#include "display/symbol.h"
|
||||
|
||||
void drawMap(
|
||||
const map_t *map,
|
||||
const uint16_t cameraX,
|
||||
const uint16_t cameraY,
|
||||
const uint16_t drawX,
|
||||
const uint16_t drawY,
|
||||
const uint16_t drawWidth,
|
||||
const uint16_t drawHeight
|
||||
) {
|
||||
assertNotNull(map, "Map cannot be NULL.");
|
||||
assertTrue(drawX < FRAME_WIDTH, "Map is too far right.");
|
||||
assertTrue(drawY < FRAME_HEIGHT, "Map is too far down.");
|
||||
assertTrue(drawWidth > 0, "Map is too narrow.");
|
||||
assertTrue(drawHeight > 0, "Map is too short.");
|
||||
assertTrue(drawX + drawWidth <= FRAME_WIDTH, "Map is too wide.");
|
||||
assertTrue(drawY + drawHeight <= FRAME_HEIGHT, "Map is too tall.");
|
||||
|
||||
entity_t *ent;
|
||||
tile_t tile;
|
||||
uint32_t i;
|
||||
char_t *bufferDest;
|
||||
uint8_t *colorDest;
|
||||
|
||||
// If the size of the map's smaller than the frame, center it, otherwise use
|
||||
// the cameraPosition as the center point.
|
||||
int16_t offsetX = 0, offsetY = 0;
|
||||
if(map->width < drawWidth) {
|
||||
offsetX = (drawWidth - map->width) / 2;
|
||||
} else {
|
||||
// Clamp to map bounds
|
||||
if(cameraX < drawWidth / 2) {
|
||||
offsetX = 0;
|
||||
} else if(cameraX >= map->width - (drawWidth / 2)) {
|
||||
offsetX = -(map->width - drawWidth);
|
||||
} else {
|
||||
offsetX = -(cameraX - (drawWidth / 2));
|
||||
}
|
||||
}
|
||||
|
||||
if(map->height < drawHeight) {
|
||||
offsetY = (drawHeight - map->height) / 2;
|
||||
} else {
|
||||
// Clamp to map bounds
|
||||
if(cameraY < drawHeight / 2) {
|
||||
offsetY = 0;
|
||||
} else if(cameraY >= map->height - (drawHeight / 2)) {
|
||||
offsetY = -(map->height - drawHeight);
|
||||
} else {
|
||||
offsetY = -(cameraY - (drawHeight / 2));
|
||||
}
|
||||
}
|
||||
|
||||
// Draw the map
|
||||
i = 0;
|
||||
for(uint16_t y = 0; y < drawHeight; y++) {
|
||||
bufferDest = &FRAME_BUFFER[(drawY + y) * FRAME_WIDTH + drawX];
|
||||
colorDest = &FRAME_COLOR[(drawY + y) * FRAME_WIDTH + drawX];
|
||||
|
||||
for(uint16_t x = 0; x < drawWidth; x++) {
|
||||
if(x < offsetX || y < offsetY || x >= map->width + offsetX || y >= map->height + offsetY) {
|
||||
colorDest[x] = COLOR_BLACK;
|
||||
bufferDest[x] = ' ';
|
||||
continue;
|
||||
}
|
||||
|
||||
// Entity?
|
||||
ent = mapEntityGetByPosition(map, x - offsetX, y - offsetY);
|
||||
if(ent != NULL) {
|
||||
colorDest[x] = symbolGetColorByEntity(ent);
|
||||
bufferDest[x] = symbolGetCharByEntity(ent);
|
||||
continue;
|
||||
}
|
||||
|
||||
// Tile?
|
||||
tile = mapTileGetByPosition(map, x - offsetX, y - offsetY, 0);
|
||||
colorDest[x] = symbolGetColorByTile(tile);
|
||||
bufferDest[x] = symbolGetCharByTile(tile);
|
||||
}
|
||||
}
|
||||
}
|
31
src/dawn/display/draw/drawmap.h
Normal file
31
src/dawn/display/draw/drawmap.h
Normal file
@ -0,0 +1,31 @@
|
||||
/**
|
||||
* Copyright (c) 2024 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "display/frame.h"
|
||||
#include "rpg/world/map.h"
|
||||
|
||||
/**
|
||||
* Draws a map to a region of the screen.
|
||||
*
|
||||
* @param map Map to draw.
|
||||
* @param cameraX X position of the camera.
|
||||
* @param cameraY Y position of the camera.
|
||||
* @param drawX X position to draw the map.
|
||||
* @param drawY Y position to draw the map.
|
||||
* @param drawWidth Width of the map to draw.
|
||||
* @param drawHeight Height of the map to draw.
|
||||
*/
|
||||
void drawMap(
|
||||
const map_t *map,
|
||||
const uint16_t cameraX,
|
||||
const uint16_t cameraY,
|
||||
const uint16_t drawX,
|
||||
const uint16_t drawY,
|
||||
const uint16_t drawWidth,
|
||||
const uint16_t drawHeight
|
||||
);
|
43
src/dawn/display/draw/drawshape.c
Normal file
43
src/dawn/display/draw/drawshape.c
Normal file
@ -0,0 +1,43 @@
|
||||
/**
|
||||
* Copyright (c) 2024 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "drawshape.h"
|
||||
#include "assert/assert.h"
|
||||
|
||||
void drawClear(
|
||||
const char_t c,
|
||||
const uint8_t color
|
||||
) {
|
||||
memset(FRAME_BUFFER, c, FRAME_HEIGHT * FRAME_WIDTH);
|
||||
memset(FRAME_COLOR, color, FRAME_HEIGHT * FRAME_WIDTH);
|
||||
}
|
||||
|
||||
void drawBox(
|
||||
const uint16_t x,
|
||||
const uint16_t y,
|
||||
const uint16_t width,
|
||||
const uint16_t height,
|
||||
const char_t c,
|
||||
const uint8_t color
|
||||
) {
|
||||
assertTrue(x < FRAME_WIDTH, "Box is too far right.");
|
||||
assertTrue(y < FRAME_HEIGHT, "Box is too far down.");
|
||||
if(width == 0 || height == 0) return;
|
||||
assertTrue(x + width <= FRAME_WIDTH, "Box is too wide.");
|
||||
assertTrue(y + height <= FRAME_HEIGHT, "Box is too tall.");
|
||||
|
||||
if(width == FRAME_WIDTH) {
|
||||
memset(&FRAME_BUFFER[y * FRAME_WIDTH + x], c, height * width);
|
||||
memset(&FRAME_COLOR[y * FRAME_WIDTH + x], color, height * width);
|
||||
return;
|
||||
}
|
||||
|
||||
for(uint16_t iy = 0; iy < height; iy++) {
|
||||
memset(&FRAME_BUFFER[(y + iy) * FRAME_WIDTH + x], c, width);
|
||||
memset(&FRAME_COLOR[(y + iy) * FRAME_WIDTH + x], color, width);
|
||||
}
|
||||
}
|
39
src/dawn/display/draw/drawshape.h
Normal file
39
src/dawn/display/draw/drawshape.h
Normal file
@ -0,0 +1,39 @@
|
||||
/**
|
||||
* Copyright (c) 2024 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "display/frame.h"
|
||||
|
||||
/**
|
||||
* Clears the frame buffer with a character and color.
|
||||
*
|
||||
* @param c Character to clear the frame buffer with.
|
||||
* @param color Color to clear the frame buffer with.
|
||||
*/
|
||||
void drawClear(
|
||||
const char_t c,
|
||||
const uint8_t color
|
||||
);
|
||||
|
||||
/**
|
||||
* Draws a box to the frame buffer.
|
||||
*
|
||||
* @param x The x position to draw the box.
|
||||
* @param y The y position to draw the box.
|
||||
* @param width The width of the box.
|
||||
* @param height The height of the box.
|
||||
* @param c The character to draw the box with.
|
||||
* @param color The color to draw the box.
|
||||
*/
|
||||
void drawBox(
|
||||
const uint16_t x,
|
||||
const uint16_t y,
|
||||
const uint16_t width,
|
||||
const uint16_t height,
|
||||
const char_t c,
|
||||
const uint8_t color
|
||||
);
|
26
src/dawn/display/draw/drawtext.c
Normal file
26
src/dawn/display/draw/drawtext.c
Normal file
@ -0,0 +1,26 @@
|
||||
/**
|
||||
* Copyright (c) 2024 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "drawtext.h"
|
||||
#include "assert/assert.h"
|
||||
|
||||
void drawText(
|
||||
const char_t *text,
|
||||
const uint16_t x,
|
||||
const uint16_t y,
|
||||
const uint8_t color
|
||||
) {
|
||||
size_t len = strlen(text);
|
||||
if(len == 0) return;
|
||||
|
||||
assertTrue(x + len <= FRAME_WIDTH, "Text is too long.");
|
||||
assertTrue(y < FRAME_HEIGHT, "Text is too low.");
|
||||
|
||||
uint16_t i = y * FRAME_WIDTH + x;
|
||||
memcpy(&FRAME_BUFFER[i], text, len);
|
||||
memset(&FRAME_COLOR[i], color, len);
|
||||
}
|
24
src/dawn/display/draw/drawtext.h
Normal file
24
src/dawn/display/draw/drawtext.h
Normal file
@ -0,0 +1,24 @@
|
||||
/**
|
||||
* Copyright (c) 2024 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "display/frame.h"
|
||||
|
||||
/**
|
||||
* Draws some text to the frame buffer.
|
||||
*
|
||||
* @param text The text to draw.
|
||||
* @param x The x position to draw the text.
|
||||
* @param y The y position to draw the text.
|
||||
* @param color The color to draw the text.
|
||||
*/
|
||||
void drawText(
|
||||
const char_t *text,
|
||||
const uint16_t x,
|
||||
const uint16_t y,
|
||||
const uint8_t color
|
||||
);
|
56
src/dawn/display/draw/drawui.c
Normal file
56
src/dawn/display/draw/drawui.c
Normal file
@ -0,0 +1,56 @@
|
||||
/**
|
||||
* Copyright (c) 2024 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "drawui.h"
|
||||
#include "drawshape.h"
|
||||
#include "assert/assert.h"
|
||||
|
||||
void drawUIBox(
|
||||
const uint16_t x,
|
||||
const uint16_t y,
|
||||
const uint16_t width,
|
||||
const uint16_t height,
|
||||
const uint8_t color,
|
||||
const bool_t fill
|
||||
) {
|
||||
assertTrue(x < FRAME_WIDTH, "Box is too far right.");
|
||||
assertTrue(y < FRAME_HEIGHT, "Box is too far down.");
|
||||
assertTrue(width > 2, "Box is too narrow.");
|
||||
assertTrue(height > 2, "Box is too short.");
|
||||
assertTrue(x + width <= FRAME_WIDTH, "Box is too wide.");
|
||||
assertTrue(y + height <= FRAME_HEIGHT, "Box is too tall.");
|
||||
|
||||
// Draw the top and bottom borders
|
||||
for(uint16_t i = 0; i < width; i++) {
|
||||
FRAME_BUFFER[y * FRAME_WIDTH + x + i] = '-';
|
||||
FRAME_BUFFER[(y + height - 1) * FRAME_WIDTH + x + i] = '-';
|
||||
FRAME_COLOR[y * FRAME_WIDTH + x + i] = color;
|
||||
FRAME_COLOR[(y + height - 1) * FRAME_WIDTH + x + i] = color;
|
||||
}
|
||||
|
||||
// Draw the left and right borders
|
||||
for(uint16_t i = 0; i < height; i++) {
|
||||
FRAME_BUFFER[(y + i) * FRAME_WIDTH + x] = '|';
|
||||
FRAME_BUFFER[(y + i) * FRAME_WIDTH + x + width - 1] = '|';
|
||||
FRAME_COLOR[(y + i) * FRAME_WIDTH + x] = color;
|
||||
FRAME_COLOR[(y + i) * FRAME_WIDTH + x + width - 1] = color;
|
||||
}
|
||||
|
||||
// Draw the corners
|
||||
FRAME_BUFFER[y * FRAME_WIDTH + x] = '+';
|
||||
FRAME_BUFFER[y * FRAME_WIDTH + x + width - 1] = '+';
|
||||
FRAME_BUFFER[(y + height - 1) * FRAME_WIDTH + x] = '+';
|
||||
FRAME_BUFFER[(y + height - 1) * FRAME_WIDTH + x + width - 1] = '+';
|
||||
FRAME_COLOR[y * FRAME_WIDTH + x] = color;
|
||||
FRAME_COLOR[y * FRAME_WIDTH + x + width - 1] = color;
|
||||
FRAME_COLOR[(y + height - 1) * FRAME_WIDTH + x] = color;
|
||||
FRAME_COLOR[(y + height - 1) * FRAME_WIDTH + x + width - 1] = color;
|
||||
|
||||
// Fill the inside
|
||||
if(!fill) return;
|
||||
drawBox(x + 1, y + 1, width - 2, height - 2, ' ', COLOR_BLACK);
|
||||
}
|
28
src/dawn/display/draw/drawui.h
Normal file
28
src/dawn/display/draw/drawui.h
Normal file
@ -0,0 +1,28 @@
|
||||
/**
|
||||
* Copyright (c) 2024 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "display/frame.h"
|
||||
|
||||
/**
|
||||
* Draws a UI box to the frame buffer.
|
||||
*
|
||||
* @param x The x position to draw the border.
|
||||
* @param y The y position to draw the border.
|
||||
* @param width The width of the border.
|
||||
* @param height The height of the border.
|
||||
* @param color The color to draw the border.
|
||||
* @param fill Whether or not to fill the inside of the border.
|
||||
*/
|
||||
void drawUIBox(
|
||||
const uint16_t x,
|
||||
const uint16_t y,
|
||||
const uint16_t width,
|
||||
const uint16_t height,
|
||||
const uint8_t color,
|
||||
const bool_t fill
|
||||
);
|
@ -9,86 +9,27 @@
|
||||
#include "display/symbol.h"
|
||||
#include "rpg/world/map.h"
|
||||
#include "game.h"
|
||||
|
||||
#include "ui/textbox.h"
|
||||
|
||||
#include "display/draw/drawshape.h"
|
||||
#include "display/draw/drawui.h"
|
||||
#include "display/draw/drawtext.h"
|
||||
#include "display/draw/drawmap.h"
|
||||
|
||||
char_t FRAME_BUFFER[FRAME_HEIGHT * FRAME_WIDTH];
|
||||
uint8_t FRAME_COLOR[FRAME_HEIGHT * FRAME_WIDTH];
|
||||
|
||||
void frameInit() {
|
||||
memset(FRAME_BUFFER, ' ', FRAME_HEIGHT * FRAME_WIDTH);
|
||||
frameUIReset();
|
||||
drawClear(' ', COLOR_BLACK);
|
||||
// drawBox(5, 5, 5, 5, '+', COLOR_YELLOW);
|
||||
// drawUIBox(5, 5, 15, 10, COLOR_YELLOW, true);
|
||||
// drawText("Hello, World!", 6, 6, COLOR_WHITE);
|
||||
}
|
||||
|
||||
void frameUpdate() {
|
||||
map_t *map = GAME.currentMap;
|
||||
if(map == NULL) return;
|
||||
|
||||
// Draw the map area.
|
||||
if(GAME.state == GAME_STATE_PAUSED) {
|
||||
framePausedDraw();
|
||||
} else {
|
||||
frameMapDraw();
|
||||
}
|
||||
}
|
||||
|
||||
void framePausedDraw() {
|
||||
char_t *test = "Paused";
|
||||
uint16_t x = (FRAME_WIDTH - strlen(test)) / 2;
|
||||
uint16_t y = (FRAME_HEIGHT - FRAME_BOTTOM_UI_HEIGHT) / 2;
|
||||
uint16_t j;
|
||||
for(uint16_t i = 0; i < strlen(test); i++) {
|
||||
j = (y * FRAME_WIDTH) + x + i;
|
||||
FRAME_BUFFER[j] = test[i];
|
||||
FRAME_COLOR[j] = COLOR_WHITE;
|
||||
}
|
||||
}
|
||||
|
||||
void frameUIReset() {
|
||||
memset(
|
||||
FRAME_BUFFER + (FRAME_HEIGHT - FRAME_BOTTOM_UI_HEIGHT) * FRAME_WIDTH,
|
||||
' ',
|
||||
FRAME_WIDTH * FRAME_BOTTOM_UI_HEIGHT
|
||||
);
|
||||
|
||||
memset(
|
||||
FRAME_COLOR + (FRAME_HEIGHT - FRAME_BOTTOM_UI_HEIGHT) * FRAME_WIDTH,
|
||||
COLOR_WHITE,
|
||||
FRAME_WIDTH * FRAME_BOTTOM_UI_HEIGHT
|
||||
);
|
||||
|
||||
// Draw UI top and bottom borders
|
||||
for(uint16_t x = 0; x < FRAME_WIDTH; x++) {
|
||||
char_t c = x == 0 || x == FRAME_WIDTH-1 ? '+' : '-';
|
||||
int32_t i = (FRAME_HEIGHT - 1) * FRAME_WIDTH + x;
|
||||
FRAME_BUFFER[i] = c;
|
||||
|
||||
i = (FRAME_HEIGHT - FRAME_BOTTOM_UI_HEIGHT) * FRAME_WIDTH + x;
|
||||
FRAME_BUFFER[i] = c;
|
||||
}
|
||||
|
||||
// Draw UI left and right borders
|
||||
for(
|
||||
uint16_t y = FRAME_HEIGHT - FRAME_BOTTOM_UI_HEIGHT + 1;
|
||||
y < FRAME_HEIGHT - 1;
|
||||
y++
|
||||
) {
|
||||
int32_t i = y * FRAME_WIDTH;
|
||||
FRAME_BUFFER[i] = '|';
|
||||
|
||||
i = y * FRAME_WIDTH + FRAME_WIDTH - 1;
|
||||
FRAME_BUFFER[i] = '|';
|
||||
}
|
||||
}
|
||||
|
||||
void frameMapDraw() {
|
||||
// Draw the map area.
|
||||
entity_t *ent;
|
||||
tile_t tile;
|
||||
uint32_t i;
|
||||
|
||||
map_t *map = GAME.currentMap;
|
||||
if(map == NULL) return;
|
||||
|
||||
// Try get player
|
||||
entity_t *player = mapEntityGetByType(map, ENTITY_TYPE_PLAYER);
|
||||
@ -101,82 +42,19 @@ void frameMapDraw() {
|
||||
cameraPositionY = player->y;
|
||||
}
|
||||
|
||||
// If the size of the map's smaller than the frame, center it, otherwise use
|
||||
// the cameraPosition as the center point.
|
||||
int16_t offsetX = 0, offsetY = 0;
|
||||
if(map->width < FRAME_MAP_WIDTH) {
|
||||
offsetX = (FRAME_MAP_WIDTH - map->width) / 2;
|
||||
} else {
|
||||
// Clamp to map bounds
|
||||
if(cameraPositionX < FRAME_MAP_WIDTH / 2) {
|
||||
offsetX = 0;
|
||||
} else if(cameraPositionX >= map->width - (FRAME_MAP_WIDTH / 2)) {
|
||||
offsetX = -(map->width - FRAME_MAP_WIDTH);
|
||||
} else {
|
||||
offsetX = -(cameraPositionX - (FRAME_MAP_WIDTH / 2));
|
||||
}
|
||||
}
|
||||
drawMap(
|
||||
GAME.currentMap,
|
||||
cameraPositionX, cameraPositionY,
|
||||
0, 0,
|
||||
FRAME_WIDTH, FRAME_HEIGHT
|
||||
);
|
||||
}
|
||||
|
||||
if(map->height < FRAME_MAP_HEIGHT) {
|
||||
offsetY = (FRAME_MAP_HEIGHT - map->height) / 2;
|
||||
} else {
|
||||
// Clamp to map bounds
|
||||
if(cameraPositionY < FRAME_MAP_HEIGHT / 2) {
|
||||
offsetY = 0;
|
||||
} else if(cameraPositionY >= map->height - (FRAME_MAP_HEIGHT / 2)) {
|
||||
offsetY = -(map->height - FRAME_MAP_HEIGHT);
|
||||
} else {
|
||||
offsetY = -(cameraPositionY - (FRAME_MAP_HEIGHT / 2));
|
||||
}
|
||||
}
|
||||
void framePausedDraw() {
|
||||
return;
|
||||
|
||||
// Draw the map
|
||||
i = 0;
|
||||
for(uint16_t y = 0; y < FRAME_MAP_HEIGHT; y++) {
|
||||
for(uint16_t x = 0; x < FRAME_MAP_WIDTH; x++) {
|
||||
if(x < offsetX || y < offsetY || x >= map->width + offsetX || y >= map->height + offsetY) {
|
||||
FRAME_COLOR[i] = COLOR_BLACK;
|
||||
FRAME_BUFFER[i++] = ' ';
|
||||
continue;
|
||||
}
|
||||
|
||||
// Entity?
|
||||
ent = mapEntityGetByPosition(map, x - offsetX, y - offsetY);
|
||||
if(ent != NULL) {
|
||||
FRAME_COLOR[i] = symbolGetColorByEntity(ent);
|
||||
FRAME_BUFFER[i++] = symbolGetCharByEntity(ent);
|
||||
continue;
|
||||
}
|
||||
|
||||
// Tile?
|
||||
tile = mapTileGetByPosition(map, x - offsetX, y - offsetY, 0);
|
||||
FRAME_COLOR[i] = symbolGetColorByTile(tile);
|
||||
FRAME_BUFFER[i++] = symbolGetCharByTile(tile);
|
||||
}
|
||||
}
|
||||
|
||||
// Old code:
|
||||
// i = 0;
|
||||
// for(uint16_t y = 0; y < FRAME_HEIGHT - FRAME_BOTTOM_UI_HEIGHT; y++) {
|
||||
// for(uint16_t x = 0; x < FRAME_WIDTH; x++) {
|
||||
// if(x >= map->width || y >= map->height) {
|
||||
// FRAME_COLOR[i] = COLOR_BLACK;
|
||||
// FRAME_BUFFER[i++] = ' ';
|
||||
// continue;
|
||||
// }
|
||||
|
||||
// // Entity?
|
||||
// ent = mapEntityGetByPosition(map, x, y);
|
||||
// if(ent != NULL) {
|
||||
// FRAME_COLOR[i] = symbolGetColorByEntity(ent);
|
||||
// FRAME_BUFFER[i++] = symbolGetCharByEntity(ent);
|
||||
// continue;
|
||||
// }
|
||||
|
||||
// // Tile?
|
||||
// tile = mapTileGetByPosition(map, x, y, 0);
|
||||
// FRAME_COLOR[i] = symbolGetColorByTile(tile);
|
||||
// FRAME_BUFFER[i++] = symbolGetCharByTile(tile);
|
||||
// }
|
||||
// }
|
||||
char_t *test = "Paused";
|
||||
uint16_t x = (FRAME_WIDTH - strlen(test)) / 2;
|
||||
uint16_t y = (FRAME_HEIGHT - FRAME_BOTTOM_UI_HEIGHT) / 2;
|
||||
// frameTextDraw(test, x, y, COLOR_RED);
|
||||
}
|
@ -16,9 +16,6 @@
|
||||
|
||||
#define FRAME_BOTTOM_UI_HEIGHT 8
|
||||
|
||||
#define FRAME_MAP_WIDTH FRAME_WIDTH
|
||||
#define FRAME_MAP_HEIGHT (FRAME_HEIGHT - FRAME_BOTTOM_UI_HEIGHT)
|
||||
|
||||
extern char_t FRAME_BUFFER[FRAME_HEIGHT * FRAME_WIDTH];
|
||||
extern uint8_t FRAME_COLOR[FRAME_HEIGHT * FRAME_WIDTH];
|
||||
|
||||
@ -32,16 +29,37 @@ void frameInit();
|
||||
*/
|
||||
void frameUpdate();
|
||||
|
||||
/**
|
||||
* Clears the frame buffer.
|
||||
*/
|
||||
void frameClear();
|
||||
|
||||
/**
|
||||
* Draws a UI frame.
|
||||
*
|
||||
* @param x The x position to draw the border.
|
||||
* @param y The y position to draw the border.
|
||||
* @param width The width of the border.
|
||||
* @param height The height of the border.
|
||||
* @param color The color to draw the border.
|
||||
*/
|
||||
void frameBoxDraw(
|
||||
const uint16_t x,
|
||||
const uint16_t y,
|
||||
const uint16_t width,
|
||||
const uint16_t height,
|
||||
const uint8_t color
|
||||
);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Draws the paused screen.
|
||||
*/
|
||||
void framePausedDraw();
|
||||
|
||||
/**
|
||||
* Resets the UI area of the frame.
|
||||
*/
|
||||
void frameUIReset();
|
||||
|
||||
/**
|
||||
* Redraws the entire map area of the frame.
|
||||
*/
|
||||
|
@ -46,6 +46,7 @@ uint8_t gameUpdate(const float_t delta) {
|
||||
assertUnreachable("Invalid game state.");
|
||||
}
|
||||
|
||||
// Perform render.
|
||||
displayUpdate();
|
||||
|
||||
if(GAME.shouldExit) return GAME_UPDATE_RESULT_EXIT;
|
||||
|
@ -20,6 +20,8 @@ void textboxSetText(
|
||||
const char_t *title,
|
||||
const char_t *text
|
||||
) {
|
||||
return;
|
||||
|
||||
assertNotNull(text, "Text cannot be NULL.");
|
||||
|
||||
// Setup text copies
|
||||
@ -37,9 +39,6 @@ void textboxSetText(
|
||||
TEXTBOX.title[0] = '\0';
|
||||
}
|
||||
|
||||
// Reset UI.
|
||||
frameUIReset();
|
||||
|
||||
// Add > indicator
|
||||
FRAME_BUFFER[(FRAME_HEIGHT * FRAME_WIDTH) - 4] = ' ';
|
||||
FRAME_BUFFER[(FRAME_HEIGHT * FRAME_WIDTH) - 3] = '>';
|
||||
@ -64,6 +63,7 @@ bool_t textboxIsOpen() {
|
||||
}
|
||||
|
||||
void textboxUpdate() {
|
||||
return;
|
||||
if(!textboxIsOpen()) return;
|
||||
|
||||
int32_t j;
|
||||
@ -73,7 +73,6 @@ void textboxUpdate() {
|
||||
// Wait for input
|
||||
if(inputWasPressed(INPUT_BIND_ACCEPT)) {
|
||||
TEXTBOX.open = false;
|
||||
frameUIReset();
|
||||
return;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user