Mid menu coding
This commit is contained in:
@ -36,4 +36,5 @@ void drawStateOverworld() {
|
||||
|
||||
// Draw UI
|
||||
drawUITextbox();
|
||||
drawUITestMenu();
|
||||
}
|
@ -8,9 +8,10 @@
|
||||
#include "drawui.h"
|
||||
#include "drawshape.h"
|
||||
#include "assert/assert.h"
|
||||
#include "ui/textbox.h"
|
||||
#include "game/time.h"
|
||||
#include "display/draw/drawtext.h"
|
||||
#include "ui/textbox.h"
|
||||
#include "ui/testmenu.h"
|
||||
|
||||
void drawUIBox(
|
||||
const uint16_t x,
|
||||
@ -58,6 +59,69 @@ void drawUIBox(
|
||||
drawBox(x + 1, y + 1, width - 2, height - 2, ' ', COLOR_BLACK);
|
||||
}
|
||||
|
||||
void drawUIMenu(
|
||||
const menu_t *menu,
|
||||
const uint16_t x,
|
||||
const uint16_t y,
|
||||
const uint16_t width,
|
||||
const char_t* strings[],
|
||||
const int16_t stringCount,
|
||||
const uint8_t cursorColor,
|
||||
const uint8_t textColor
|
||||
) {
|
||||
assertTrue(menu, "Menu cannot be NULL.");
|
||||
assertTrue(strings, "Strings cannot be NULL.");
|
||||
assertTrue(stringCount > 0, "String count must be greater than 0.");
|
||||
assertTrue(menu->rows > 0, "Rows must be greater than 0.");
|
||||
assertTrue(menu->columns > 0, "Columns must be greater than 0.");
|
||||
assertTrue(width*2 > menu->columns, "Width must be greater than columns.");
|
||||
|
||||
uint16_t stringWidth = (width / menu->columns) + 1;// +1 for cursor and padding
|
||||
|
||||
// Draw the menu
|
||||
for(uint16_t row = 0; row < menu->rows; row++) {
|
||||
for(uint16_t col = 0; col < menu->columns; col++) {
|
||||
uint16_t index = (row * menu->columns) + col;
|
||||
if(index >= stringCount) break;
|
||||
|
||||
drawText(
|
||||
strings[index],
|
||||
-1,
|
||||
x + (col * stringWidth) + 1,
|
||||
y + row,
|
||||
textColor
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Draw the cursor
|
||||
size_t i = (x + (menu->x * stringWidth)) + ((y + menu->y) * FRAME_WIDTH);
|
||||
FRAME_BUFFER[i] = '>';
|
||||
FRAME_COLOR[i] = cursorColor;
|
||||
}
|
||||
|
||||
void drawUIMenuBox(
|
||||
const menu_t *menu,
|
||||
const uint16_t x,
|
||||
const uint16_t y,
|
||||
const uint16_t width,
|
||||
const uint16_t height,
|
||||
const char_t* strings[],
|
||||
const int16_t stringCount,
|
||||
const uint8_t cursorColor,
|
||||
const uint8_t textColor,
|
||||
const uint8_t boxColor
|
||||
) {
|
||||
drawUIBox(x, y, width, height, boxColor, true);
|
||||
|
||||
// drawUIMenu(
|
||||
// menu,
|
||||
// x + 1, y + 1, width - 2,
|
||||
// strings, stringCount,
|
||||
// cursorColor, textColor
|
||||
// );
|
||||
}
|
||||
|
||||
void drawUITextbox() {
|
||||
if(!textboxIsOpen()) return;
|
||||
|
||||
@ -92,4 +156,47 @@ void drawUITextbox() {
|
||||
int32_t blink = (int32_t)(TIME.time * DRAW_UI_TEXTBOX_BLINKS_PER_SECOND) % 2;
|
||||
FRAME_BUFFER[DRAW_UI_TEXTBOX_CURSOR_POS + 1] = blink ? '>' : ' ';
|
||||
FRAME_BUFFER[DRAW_UI_TEXTBOX_CURSOR_POS + 2] = blink ? ' ' : '>';
|
||||
}
|
||||
|
||||
void drawUITestMenu() {
|
||||
const char_t* strings[] = {
|
||||
"Option 1",
|
||||
"Option 2",
|
||||
"Option 3",
|
||||
"Option 4",
|
||||
"Option 5",
|
||||
"Option 6",
|
||||
"Option 7",
|
||||
"Option 8",
|
||||
"Option 9",
|
||||
"Option 10",
|
||||
"Option 11",
|
||||
"Option 12",
|
||||
"Option 13",
|
||||
"Option 14",
|
||||
"Option 15",
|
||||
"Option 16",
|
||||
"Option 17",
|
||||
"Option 18",
|
||||
"Option 19",
|
||||
"Option 20",
|
||||
"Option 21",
|
||||
"Option 22",
|
||||
"Option 23",
|
||||
"Option 24",
|
||||
"Option 25",
|
||||
"Option 26",
|
||||
"Option 27",
|
||||
"Option 28",
|
||||
"Option 29",
|
||||
"Option 30"
|
||||
};
|
||||
|
||||
drawUIMenuBox(
|
||||
&TEST_MENU.menu,
|
||||
0, 0,
|
||||
FRAME_WIDTH, 5,
|
||||
strings, sizeof(strings) / sizeof(char_t*),
|
||||
COLOR_CYAN, COLOR_WHITE, COLOR_MAGENTA
|
||||
);
|
||||
}
|
@ -7,6 +7,7 @@
|
||||
|
||||
#pragma once
|
||||
#include "display/frame.h"
|
||||
#include "ui/menu.h"
|
||||
|
||||
#define DRAW_UI_TEXTBOX_WIDTH FRAME_WIDTH
|
||||
#define DRAW_UI_TEXTBOX_HEIGHT 8
|
||||
@ -32,7 +33,63 @@ void drawUIBox(
|
||||
const bool_t fill
|
||||
);
|
||||
|
||||
/**
|
||||
* Draws a UI menu to the frame buffer.
|
||||
*
|
||||
* @param menu The menu to draw.
|
||||
* @param x The x position to draw the menu.
|
||||
* @param y The y position to draw the menu.
|
||||
* @param width The width of the menu.
|
||||
* @param strings The strings to draw in the menu.
|
||||
* @param stringCount The number of strings in the menu.
|
||||
* @param cursorColor The color of the cursor.
|
||||
* @param textColor The color of the text.
|
||||
*/
|
||||
void drawUIMenu(
|
||||
const menu_t *menu,
|
||||
const uint16_t x,
|
||||
const uint16_t y,
|
||||
const uint16_t width,
|
||||
|
||||
const char_t* strings[],
|
||||
const int16_t stringCount,
|
||||
const uint8_t cursorColor,
|
||||
const uint8_t textColor
|
||||
);
|
||||
|
||||
/**
|
||||
* Draws a UI menu box to the frame buffer.
|
||||
*
|
||||
* @param menu The menu to draw.
|
||||
* @param x The x position to draw the menu.
|
||||
* @param y The y position to draw the menu.
|
||||
* @param width The width of the menu.
|
||||
* @param height The height of the menu.
|
||||
* @param strings The strings to draw in the menu.
|
||||
* @param stringCount The number of strings in the menu.
|
||||
* @param cursorColor The color of the cursor.
|
||||
* @param textColor The color of the text.
|
||||
* @param boxColor The color of the box.
|
||||
*/
|
||||
void drawUIMenuBox(
|
||||
const menu_t *menu,
|
||||
const uint16_t x,
|
||||
const uint16_t y,
|
||||
const uint16_t width,
|
||||
const uint16_t height,
|
||||
const char_t* strings[],
|
||||
const int16_t stringCount,
|
||||
const uint8_t cursorColor,
|
||||
const uint8_t textColor,
|
||||
const uint8_t boxColor
|
||||
);
|
||||
|
||||
/**
|
||||
* Draws the UI textbox to the frame buffer.
|
||||
*/
|
||||
void drawUITextbox();
|
||||
void drawUITextbox();
|
||||
|
||||
/**
|
||||
* Draws the UI test menu to the frame buffer.
|
||||
*/
|
||||
void drawUITestMenu();
|
Reference in New Issue
Block a user