Very WIP: Make more like 3DS Universal-Core

This commit is contained in:
Pk11
2021-08-22 23:36:48 -05:00
parent 4c6a15c5c7
commit 90c730f35d
7 changed files with 140 additions and 129 deletions
+29 -21
View File
@@ -42,9 +42,21 @@ enum class Alignment {
right,
};
enum class Palette : u8 {
#ifdef UNIVCORE_TEXT_PALETTES
UNIVCORE_TEXT_PALETTES
#else
white
#endif
};
#ifndef UNIVCORE_TEXT_DEFAULT_PALETTE
#define UNIVCORE_TEXT_DEFAULT_PALETTE white
#endif
class Font {
private:
#ifdef TEXT_BUFFERED
#ifdef UNIVCORE_TEXT_BUFFERED
static u8 textBuf[2][256 * 192];
#endif
@@ -57,7 +69,7 @@ private:
u16 charIndex(char16_t c);
void print(std::u16string_view text, int x, int y, bool top, int layer, Alignment align, int maxWidth, int color, float scaleX, float scaleY, bool rtl, Sprite *sprite);
void DrawString(std::u16string_view text, int x, int y, Alignment align, Palette palette, int maxWidth, float scaleX, float scaleY, bool rtl, Sprite *sprite);
public:
/**
@@ -97,65 +109,61 @@ public:
/**
* @brief Prints an integer value to a background layer
* @param value The value to print
* @param x The X position to print at
* @param y The Y position to print at
* @param top Whether to print on the top or bottom screen
* @param layer (Optional) The layer to print on
* @param value The value to print
* @param align (Optional) The alignment to use
* @param palette (Optional) The palette to use
* @param maxWidth (Optional) The maximum width of the string, set to 0 for no max width
* @param color (Optional) The color to print in
* @param scaleX (Optional) The scale on the X axis
* @param scaleY (Optional) The scale on the Y axis
*/
void print(int value, int x, int y, bool top, int layer = 2, Alignment align = Alignment::left, int maxWidth = 0, int color = 0, float scaleX = 1.0f, float scaleY = 1.0f) { print(utf8to16(std::to_string(value)), x, y, top, layer, align, maxWidth, scaleX, scaleY, color, false, nullptr); }
void DrawString(int x, int y, int value, Alignment align = Alignment::left, Palette palette = Palette::UNIVCORE_TEXT_DEFAULT_PALETTE, int maxWidth = 0, float scaleX = 1.0f, float scaleY = 1.0f) { DrawString(utf8to16(std::to_string(value)), x, y, align, palette, maxWidth, scaleX, scaleY, false, nullptr); }
/**
* @brief Prints a string to a background layer
* @param text The string to print
* @param x The X position to print at
* @param y The Y position to print at
* @param top Whether to print on the top or bottom screen
* @param layer (Optional) The layer to print on
* @param text The string to print
* @param align (Optional) The alignment to use
* @param palette (Optional) The palette to use
* @param maxWidth (Optional) The maximum width of the string, set to 0 for no max width
* @param scaleX (Optional) The scale on the X axis
* @param scaleY (Optional) The scale on the Y axis
* @param color (Optional) The color to print in
*/
void print(std::string_view text, int x, int y, bool top, int layer = 2, Alignment align = Alignment::left, int maxWidth = 0, int color = 0, float scaleX = 1.0f, float scaleY = 1.0f) { print(utf8to16(text), x, y, top, layer, align, maxWidth, color, scaleX, scaleY, false, nullptr); }
void print(std::u16string_view text, int x, int y, bool top, int layer = 2, Alignment align = Alignment::left, int maxWidth = 0, int color = 0, float scaleX = 1.0f, float scaleY = 1.0f) { print(text, x, y, top, layer, align, maxWidth, color, scaleX, scaleY, false, nullptr); }
void DrawString(int x, int y, std::string_view text, Alignment align = Alignment::left, Palette palette = Palette::UNIVCORE_TEXT_DEFAULT_PALETTE, int maxWidth = 0, float scaleX = 1.0f, float scaleY = 1.0f) { DrawString(utf8to16(text), x, y, align, palette, maxWidth, scaleX, scaleY, false, nullptr); }
void DrawString(int x, int y, std::u16string_view text, Alignment align = Alignment::left, Palette palette = Palette::UNIVCORE_TEXT_DEFAULT_PALETTE, int maxWidth = 0, float scaleX = 1.0f, float scaleY = 1.0f) { DrawString(text, x, y, align, palette, maxWidth, scaleX, scaleY, false, nullptr); }
/**
* @brief Prints an integer value to a sprite
* @param value The value to print
* @param x The X position to print at
* @param y The Y position to print at
* @param value The value to print
* @param sprite The sprite to print to
* @param align (Optional) The alignment to use
* @param palette (Optional) The palette to use
* @param maxWidth (Optional) The maximum width of the string, set to 0 for no max width
* @param color (Optional) The color to print in
* @param scaleX (Optional) The scale on the X axis
* @param scaleY (Optional) The scale on the Y axis
*/
void print(int value, int x, int y, Sprite &sprite, Alignment align = Alignment::left, int maxWidth = 0, int color = 0, float scaleX = 1.0f, float scaleY = 1.0f) { print(utf8to16(std::to_string(value)), x, y, false, 0, align, maxWidth, color, scaleX, scaleY, false, nullptr); }
void DrawString(int x, int y, int value, Sprite &sprite, Alignment align = Alignment::left, Palette palette = Palette::UNIVCORE_TEXT_DEFAULT_PALETTE, int maxWidth = 0, float scaleX = 1.0f, float scaleY = 1.0f) { DrawString(utf8to16(std::to_string(value)), x, y, align, palette, maxWidth, scaleX, scaleY, false, nullptr); }
/**
* @brief Prints a string to a sprite
* @param text The string to print
* @param x The X position to print at
* @param y The Y position to print at
* @param text The string to print
* @param sprite The sprite to print to
* @param align (Optional) The alignment to use
* @param palette (Optional) The palette to use
* @param maxWidth (Optional) The maximum width of the string, set to 0 for no max width
* @param color (Optional) The color to print in
* @param scaleX (Optional) The scale on the X axis
* @param scaleY (Optional) The scale on the Y axis
*/
void print(std::string_view text, int x, int y, Sprite &sprite, Alignment align = Alignment::left, int maxWidth = 0, int color = 0, float scaleX = 1.0f, float scaleY = 1.0f) { print(utf8to16(text), x, y, false, 0, align, maxWidth, color, scaleX, scaleY, false, &sprite); }
void print(std::u16string_view text, int x, int y, Sprite &sprite, Alignment align = Alignment::left, int maxWidth = 0, int color = 0, float scaleX = 1.0f, float scaleY = 1.0f) { print(text, x, y, false, 0, align, maxWidth, color, scaleX, scaleY, false, &sprite); }
void DrawString(int x, int y, std::string_view text, Sprite &sprite, Alignment align = Alignment::left, Palette palette = Palette::UNIVCORE_TEXT_DEFAULT_PALETTE, int maxWidth = 0, float scaleX = 1.0f, float scaleY = 1.0f) { DrawString(utf8to16(text), x, y, align, palette, maxWidth, scaleX, scaleY, false, &sprite); }
void DrawString(int x, int y, std::u16string_view text, Sprite &sprite, Alignment align = Alignment::left, Palette palette = Palette::UNIVCORE_TEXT_DEFAULT_PALETTE, int maxWidth = 0, float scaleX = 1.0f, float scaleY = 1.0f) { DrawString(text, x, y, align, palette, maxWidth, scaleX, scaleY, false, &sprite); }
#ifdef TEXT_BUFFERED
#ifdef UNIVCORE_TEXT_BUFFERED
/**
* @brief Clears all text from both screens
*/
+19 -32
View File
@@ -24,8 +24,8 @@
* reasonable ways as different from the original version.
*/
#ifndef _UNIVERSAL_CORE_GRAPHICS_HPP
#define _UNIVERSAL_CORE_GRAPHICS_HPP
#ifndef _UNIVERSAL_CORE_GUI_HPP
#define _UNIVERSAL_CORE_GUI_HPP
#include "font.hpp"
#include "image.hpp"
@@ -34,9 +34,16 @@
#include <nds/ndstypes.h>
namespace Graphics {
#ifdef UNIVCORE_3DS_SIZE
#define SCALE_3DS(Pos) Pos = (Pos * 4 / 5)
#else
#define SCALE_3DS(Pos)
#endif
namespace Gui {
extern int bg3Main, bg2Main, bg3Sub, bg2Sub;
extern bool wideScreen;
extern bool widescreen;
extern bool top;
/**
* @brief Initializes the screens for drawing
@@ -44,21 +51,16 @@ namespace Graphics {
void init(void);
/**
* @brief Clears the given layer
* @brief Clears the given screen
* @param top The screen to clear
*/
void clear(bool top, int layer);
void clear(bool top);
/**
* @brief Draws a rectangle outline of a given size at a given position
* @param x The X position
* @param y The Y position
* @param w The Width
* @param h The Height
* @param color The index of the color to use
* @param top Whether to draw to the top or bottom screen
* @param layer The layer to draw to
*/
void drawOutline(int x, int y, int w, int h, u8 color, bool top, int layer);
* @brief Changes which screen to draw to
* @param top The screen to draw to
*/
void ScreenDraw(bool top);
/**
* @brief Draws a rectangle of a given size at a given position
@@ -67,23 +69,8 @@ namespace Graphics {
* @param w The Width
* @param h The Height
* @param color The index of the color to use
* @param top Whether to draw on the top or bottom screen
* @param layer The layer to draw to
*/
void drawRectangle(int x, int y, int w, int h, u8 color, bool top, bool layer);
/**
* @brief Draws a rectangle of a given size at a given position
* @param x The X position
* @param y The Y position
* @param w The Width
* @param h The Height
* @param color1 The index of the color to use for even rows
* @param color2 The index of the color to use for odd rows
* @param top Whether to draw on the top or bottom screen
* @param layer The layer to draw to
*/
void drawRectangle(int x, int y, int w, int h, u8 color1, u8 color2, bool top, bool layer);
void Draw_Rect(int x, int y, int w, int h, u8 color);
}
#endif
+8 -16
View File
@@ -42,18 +42,18 @@ private:
public:
/**
* Image drawing class
* @param path The path to load the image from
* @param paths The paths to try load the image from, from highest to lowest priority
*/
Image(const std::vector<std::string> &paths);
/**
* @brief Text printing class
* @param paths The paths to try load the image from, from highest to lowest priority
* @param path The path to load the image from
*/
Image(const std::string &path) : Image(std::vector<std::string>({path})) {};
/**
* @brief Text printing class
* @param file The file to load the image from, seeked to the image magic
* @brief Image drawing class
* @param file The file to load the image from, seeked to the '.GFX' magic
*/
Image(FILE *file);
@@ -70,24 +70,20 @@ public:
* @brief Draws the image to a background layer, faster but without alpha, scaling, or palette offsetting
* @param x The X position to draw at
* @param y The Y position to draw at
* @param top Whether to draw on teh top or bottom screen, not used for sprites
* @param layer (Optional) The layer to draw on, not used for sprites
* @param copyPal (Optional) Whether to copy the image's palette into palette VRAM
*/
void draw(int x, int y, bool top, int layer = 3, bool copyPal = true);
void draw(int x, int y, bool copyPal = true);
/**
* @brief Draws the image to a background layer, slower but can skip alpha, scale, and offset the palette
* @param x The X position to draw at
* @param y The Y position to draw at
* @param top Whether to draw on the top or bottom screen
* @param layer (Optional) Which background layer to draw on
* @param scaleX (Optional) The scale for the X axis
* @param scaleY (Optional) The scale for the Y axis
* @param paletteOffset (Optional) How much to offset the palette by
* @param copyPal (Optional) Whether to copy the image's palette into palette VRAM
*/
void drawSpecial(int x, int y, bool top, int layer = 3, float scaleX = 1.0f, float scaleY = 1.0f, int paletteOffset = 0, bool copyPal = true);
void drawSpecial(int x, int y, float scaleX = 1.0f, float scaleY = 1.0f, int paletteOffset = 0, bool copyPal = true);
/**
* @brief Draws a segment of an image to a background layer, faster but overwrites alpha and no scaling or palette offsetting
@@ -97,11 +93,9 @@ public:
* @param imageY The Y position in the image to draw from
* @param w The width to draw
* @param h The height to draw
* @param top Whether to draw on the top or bottom screen
* @param layer (Optional) Which background layer to draw on
* @param copyPal (Optional) Whether to copy the image's palette into palette VRAM
*/
void drawSegment(int x, int y, int imageX, int imageY, int w, int h, bool top, int layer = 3, bool copyPal = true);
void drawSegment(int x, int y, int imageX, int imageY, int w, int h, bool copyPal = true);
/**
* @brief Draws a segment of an image to a background layer, slower but can skip alpha, scale, and offset the palette
@@ -111,14 +105,12 @@ public:
* @param imageY The Y position in the image to draw from
* @param w The width to draw
* @param h The height to draw
* @param top Whether to draw on the top or bottom screen
* @param layer (Optional) Which background layer to draw on
* @param scaleX (Optional) The scale for the X axis
* @param scaleY (Optional) The scale for the Y axis
* @param paletteOffset (Optional) How much to offset the palette by
* @param copyPal (Optional) Whether to copy the image's palette into palette VRAM
*/
void drawSegmentSpecial(int x, int y, int imageX, int imageY, int w, int h, bool top, int layer = 3, float scaleX = 1.0f, float scaleY = 1.0f, int paletteOffset = 0, bool copyPal = true);
void drawSegmentSpecial(int x, int y, int imageX, int imageY, int w, int h, float scaleX = 1.0f, float scaleY = 1.0f, int paletteOffset = 0, bool copyPal = true);
};