mirror of
https://github.com/DarkStore-3DS/Universal-Core.git
synced 2026-07-03 00:39:23 +00:00
Minor improvements and make functions const
This commit is contained in:
+15
-27
@@ -42,18 +42,6 @@ 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 UNIVCORE_TEXT_BUFFERED
|
||||
@@ -67,9 +55,9 @@ private:
|
||||
std::vector<u8> fontWidths;
|
||||
std::vector<u16> fontMap;
|
||||
|
||||
u16 charIndex(char16_t c);
|
||||
u16 charIndex(char16_t c) const;
|
||||
|
||||
void print(std::u16string_view text, int x, int y, Alignment align, Palette palette, int maxWidth, float scaleX, float scaleY, bool rtl, Sprite *sprite);
|
||||
void print(std::u16string_view text, int x, int y, Alignment align, u8 color, int maxWidth, float scaleX, float scaleY, bool rtl, Sprite *sprite) const;
|
||||
|
||||
public:
|
||||
/**
|
||||
@@ -97,15 +85,15 @@ public:
|
||||
* @brief The height of the font
|
||||
* @return The font height
|
||||
*/
|
||||
u8 height(void) { return tileHeight; }
|
||||
u8 height(void) const { return tileHeight; }
|
||||
|
||||
/**
|
||||
* @brief Calculates the width of a given string of text
|
||||
* @param text The text to calculate the width of
|
||||
* @return The width of the given string
|
||||
*/
|
||||
int calcWidth(std::string_view text) { return calcWidth(utf8to16(text)); }
|
||||
int calcWidth(std::u16string_view text);
|
||||
int calcWidth(std::string_view text) const { return calcWidth(utf8to16(text)); }
|
||||
int calcWidth(std::u16string_view text) const;
|
||||
|
||||
/**
|
||||
* @brief Prints an integer value to a background layer
|
||||
@@ -113,12 +101,12 @@ public:
|
||||
* @param y The Y position to print at
|
||||
* @param value The value to print
|
||||
* @param align (Optional) The alignment to use
|
||||
* @param palette (Optional) The palette to use
|
||||
* @param color (Optional) The color 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
|
||||
*/
|
||||
void print(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) { print(utf8to16(std::to_string(value)), x, y, align, palette, maxWidth, scaleX, scaleY, false, nullptr); }
|
||||
void print(int x, int y, int value, Alignment align = Alignment::left, u8 color = 0, int maxWidth = 0, float scaleX = 1.0f, float scaleY = 1.0f) const { print(utf8to16(std::to_string(value)), x, y, align, color, maxWidth, scaleX, scaleY, false, nullptr); }
|
||||
|
||||
/**
|
||||
* @brief Prints a string to a background layer
|
||||
@@ -126,13 +114,13 @@ public:
|
||||
* @param y The Y position to print at
|
||||
* @param text The string to print
|
||||
* @param align (Optional) The alignment to use
|
||||
* @param palette (Optional) The palette to use
|
||||
* @param color (Optional) The color 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
|
||||
*/
|
||||
void print(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) { print(utf8to16(text), x, y, align, palette, maxWidth, scaleX, scaleY, false, nullptr); }
|
||||
void print(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) { print(text, x, y, align, palette, maxWidth, scaleX, scaleY, false, nullptr); }
|
||||
void print(int x, int y, std::string_view text, Alignment align = Alignment::left, u8 color = 0, int maxWidth = 0, float scaleX = 1.0f, float scaleY = 1.0f) const { print(utf8to16(text), x, y, align, color, maxWidth, scaleX, scaleY, false, nullptr); }
|
||||
void print(int x, int y, std::u16string_view text, Alignment align = Alignment::left, u8 color = 0, int maxWidth = 0, float scaleX = 1.0f, float scaleY = 1.0f) const { print(text, x, y, align, color, maxWidth, scaleX, scaleY, false, nullptr); }
|
||||
|
||||
/**
|
||||
* @brief Prints an integer value to a sprite
|
||||
@@ -141,12 +129,12 @@ public:
|
||||
* @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 color (Optional) The color 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
|
||||
*/
|
||||
void print(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) { print(utf8to16(std::to_string(value)), x, y, align, palette, maxWidth, scaleX, scaleY, false, nullptr); }
|
||||
void print(int x, int y, int value, Sprite &sprite, Alignment align = Alignment::left, u8 color = 0, int maxWidth = 0, float scaleX = 1.0f, float scaleY = 1.0f) const { print(utf8to16(std::to_string(value)), x, y, align, color, maxWidth, scaleX, scaleY, false, nullptr); }
|
||||
|
||||
/**
|
||||
* @brief Prints a string to a sprite
|
||||
@@ -155,13 +143,13 @@ public:
|
||||
* @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 color (Optional) The color 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
|
||||
*/
|
||||
void print(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) { print(utf8to16(text), x, y, align, palette, maxWidth, scaleX, scaleY, false, &sprite); }
|
||||
void print(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) { print(text, x, y, align, palette, maxWidth, scaleX, scaleY, false, &sprite); }
|
||||
void print(int x, int y, std::string_view text, Sprite &sprite, Alignment align = Alignment::left, u8 color = 0, int maxWidth = 0, float scaleX = 1.0f, float scaleY = 1.0f) const { print(utf8to16(text), x, y, align, color, maxWidth, scaleX, scaleY, false, &sprite); }
|
||||
void print(int x, int y, std::u16string_view text, Sprite &sprite, Alignment align = Alignment::left, u8 color = 0, int maxWidth = 0, float scaleX = 1.0f, float scaleY = 1.0f) const { print(text, x, y, align, color, maxWidth, scaleX, scaleY, false, &sprite); }
|
||||
|
||||
#ifdef UNIVCORE_TEXT_BUFFERED
|
||||
/**
|
||||
|
||||
+4
-4
@@ -113,14 +113,14 @@ namespace Gui {
|
||||
x: The X Offset from center. (Center: 200 px on top, 160 px on Bottom.)
|
||||
y: The Y Position of the Text.
|
||||
size: The size of the Text.
|
||||
palette: The palette of the Text.
|
||||
color: The color of the Text.
|
||||
Text: The Text which should be displayed.
|
||||
maxWidth: The maxWidth for the Text. (Optional!)
|
||||
maxHeight: The maxHeight of the Text. (Optional!)
|
||||
fnt: The Font which should be used. Uses default font by default. (Optional!)
|
||||
int flags: C2D text flags to use. (Optional!)
|
||||
*/
|
||||
void DrawStringCentered(int x, int y, float size, Palette palette, const std::string &Text, int maxWidth = 0, int maxHeight = 0, Font *fnt = nullptr, int flags = 0);
|
||||
void DrawStringCentered(int x, int y, float size, u8 color, const std::string &Text, int maxWidth = 0, int maxHeight = 0, Font *fnt = nullptr, int flags = 0);
|
||||
|
||||
/*
|
||||
Draws a String.
|
||||
@@ -128,14 +128,14 @@ namespace Gui {
|
||||
x: The X Position where the Text should be drawn.
|
||||
y: The Y Position where the Text should be drawn.
|
||||
size: The size of the Text.
|
||||
palette: The palette of the Text.
|
||||
color: The color of the Text.
|
||||
Text: The Text which should be displayed.
|
||||
maxWidth: The maxWidth for the Text. (Optional!)
|
||||
maxHeight: The maxHeight of the Text. (Optional!)
|
||||
fnt: The Font which should be used. Uses default font by default. (Optional!)
|
||||
flags: C2D text flags to use.
|
||||
*/
|
||||
void DrawString(int x, int y, float size, Palette palette, const std::string &Text, int maxWidth = 0, int maxHeight = 0, Font *fnt = nullptr, int flags = 0);
|
||||
void DrawString(int x, int y, float size, u8 color, const std::string &Text, int maxWidth = 0, int maxHeight = 0, Font *fnt = nullptr, int flags = 0);
|
||||
|
||||
/*
|
||||
Get the width of a String.
|
||||
|
||||
+8
-3
@@ -77,7 +77,7 @@ public:
|
||||
/**
|
||||
* @brief Copies the palette into VRAM
|
||||
*/
|
||||
void copyPalette(void);
|
||||
void copyPalette(void) const;
|
||||
|
||||
/**
|
||||
* @brief Draws the image to a background layer, slower but can skip alpha, scale, and offset the palette
|
||||
@@ -87,7 +87,7 @@ public:
|
||||
* @param scaleY (Optional) The scale for the Y axis
|
||||
* @param skipAlpha (Optional) Whether to skip transparent pixels, draws faster when disabled at 1.0 scale
|
||||
*/
|
||||
void draw(int x, int y, float scaleX = 1.0f, float scaleY = 1.0f, bool skipAlpha = true);
|
||||
void draw(int x, int y, float scaleX = 1.0f, float scaleY = 1.0f, bool skipAlpha = true) const;
|
||||
|
||||
/**
|
||||
* @brief Draws a segment of an image to a background layer, slower but can skip alpha, scale, and offset the palette
|
||||
@@ -101,8 +101,13 @@ public:
|
||||
* @param scaleY (Optional) The scale for the Y axis
|
||||
* @param skipAlpha (Optional) Whether to skip transparent pixels, draws faster when disabled at 1.0 scale
|
||||
*/
|
||||
void drawSegment(int x, int y, int imageX, int imageY, int w, int h, float scaleX = 1.0f, float scaleY = 1.0f, bool skipAlpha = true);
|
||||
void drawSegment(int x, int y, int imageX, int imageY, int w, int h, float scaleX = 1.0f, float scaleY = 1.0f, bool skipAlpha = true) const;
|
||||
|
||||
/**
|
||||
* @brief Returns the pixel at index
|
||||
* @param index The index of the pixel to get
|
||||
*/
|
||||
u16 operator[](int index) const;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
+6
-26
@@ -112,23 +112,13 @@ public:
|
||||
/**
|
||||
* @brief Clears the sprite
|
||||
*/
|
||||
void clear(void);
|
||||
void clear(void) const;
|
||||
|
||||
/**
|
||||
* @brief Fills the sprite with a solid color
|
||||
* @param color The color to fill with
|
||||
*/
|
||||
void fillColor(u16 color);
|
||||
|
||||
/**
|
||||
* @brief Draws a rectangle outline to the sprite
|
||||
* @param x The X position
|
||||
* @param y The Y position
|
||||
* @param w The Width
|
||||
* @param h The Height
|
||||
* @param color The color to use
|
||||
*/
|
||||
void drawOutline(int x, int y, int w, int h, u16 color);
|
||||
void fillColor(u16 color) const;
|
||||
|
||||
/**
|
||||
* @brief Draws a solid color rectangle to the sprite
|
||||
@@ -138,17 +128,7 @@ public:
|
||||
* @param h The height of the rectangle
|
||||
* @param color The color of the rectangle
|
||||
*/
|
||||
void drawRectangle(int x, int y, int w, int h, u16 color) { drawRectangle(x, y, w, h, color, color); }
|
||||
/**
|
||||
* @brief Draws a solid color rectangle to the sprite
|
||||
* @param x The X position to draw at
|
||||
* @param y The Y position to draw at
|
||||
* @param w The width of the rectangle
|
||||
* @param h The height of the rectangle
|
||||
* @param color The color of even rows
|
||||
* @param color The color of odd rows
|
||||
*/
|
||||
void drawRectangle(int x, int y, int w, int h, u16 color1, u16 color2);
|
||||
void drawRectangle(int x, int y, int w, int h, u16 color) const;
|
||||
|
||||
/**
|
||||
* @brief Draws the image to a sprite, can skip alpha and scale the image
|
||||
@@ -158,7 +138,7 @@ public:
|
||||
* @param scaleX (Optional) The scale for the X axis
|
||||
* @param scaleY (Optional) The scale for the Y axis
|
||||
*/
|
||||
void drawImage(int x, int y, const Image &image, float scaleX = 1.0f, float scaleY = 1.0f);
|
||||
void drawImage(int x, int y, const Image &image, float scaleX = 1.0f, float scaleY = 1.0f) const;
|
||||
|
||||
/**
|
||||
* @brief Draws a segment of an image to a sprite, faster but overwrites alpha and no scaling
|
||||
@@ -172,12 +152,12 @@ public:
|
||||
* @param scaleX (Optional) The scale for the X axis
|
||||
* @param scaleY (Optional) The scale for the Y axis
|
||||
*/
|
||||
void drawImageSegment(int x, int y, int imageX, int imageY, int w, int h, const Image &image, float scaleX = 1.0f, float scaleY = 1.0f);
|
||||
void drawImageSegment(int x, int y, int imageX, int imageY, int w, int h, const Image &image, float scaleX = 1.0f, float scaleY = 1.0f) const;
|
||||
|
||||
/**
|
||||
* @brief Updates the OAM that this sprite is on, also updates all other sprites on that screen. Avoid calling this excessively, if changing a lot of sprites call it once when they're all done.
|
||||
*/
|
||||
void update(void) { oamUpdate(_oam); }
|
||||
void update(void) const { oamUpdate(_oam); }
|
||||
/**
|
||||
* @brief Updates all sprites on the given screen. Avoid calling this excessively, if changing a lot of sprites call it once when they're all done.
|
||||
* @param top Whether to update the top or bottom screen
|
||||
|
||||
@@ -54,13 +54,13 @@ public:
|
||||
/**
|
||||
* @brief Returns the number of images in the spritesheet
|
||||
*/
|
||||
size_t size(void) { return _images.size(); }
|
||||
size_t size(void) const { return _images.size(); }
|
||||
|
||||
/**
|
||||
* @brief Returns the Image at index
|
||||
* @param index The Image to get
|
||||
*/
|
||||
Image &operator[](size_t index);
|
||||
Image &operator[](size_t index) const;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user