mirror of
https://github.com/DarkStore-3DS/Universal-Core.git
synced 2026-07-02 16:59:05 +00:00
Minor improvements and make functions const
This commit is contained in:
@@ -4,8 +4,6 @@ This contains the GUI & Core part for our DS(i) Applications.
|
||||
## Config Defines
|
||||
#define the following in `UNIVCORE_CONFIG.h` to alter specific things.
|
||||
- `UNIVCORE_TEXT_BUFFERED` to have the text be first rendered to a buffer before drawing to the screen with Font::update()
|
||||
- `UNIVCORE_TEXT_PALETTES` to set custom text palette names (comma separated)
|
||||
- `UNIVCORE_TEXT_DEFAULT_PALETTE` to set the default text palette name
|
||||
- `UNIVCORE_3DS_SIZE` to make all X and Y positions use the 3DS resolution
|
||||
|
||||
Logo created by: [TotallyNotGuy](https://github.com/TotallyNotGuy).
|
||||
|
||||
+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
|
||||
|
||||
+41
-67
@@ -130,7 +130,7 @@ Font::Font(const std::vector<std::string> &paths) {
|
||||
}
|
||||
}
|
||||
|
||||
u16 Font::charIndex(char16_t c) {
|
||||
u16 Font::charIndex(char16_t c) const {
|
||||
// Try a binary search
|
||||
int left = 0;
|
||||
int right = fontMap.size();
|
||||
@@ -173,7 +173,7 @@ std::u16string Font::utf8to16(std::string_view text) {
|
||||
return out;
|
||||
}
|
||||
|
||||
int Font::calcWidth(std::u16string_view text) {
|
||||
int Font::calcWidth(std::u16string_view text) const {
|
||||
uint x = 0;
|
||||
|
||||
for(auto c : text) {
|
||||
@@ -184,8 +184,8 @@ int Font::calcWidth(std::u16string_view text) {
|
||||
return x;
|
||||
}
|
||||
|
||||
ITCM_CODE void Font::print(std::u16string_view text, int x, int y, Alignment align, Palette palette,
|
||||
int maxWidth, float scaleX, float scaleY, bool rtl, Sprite *sprite) {
|
||||
ITCM_CODE void Font::print(std::u16string_view text, int x, int y, Alignment align, u8 color,
|
||||
int maxWidth, float scaleX, float scaleY, bool rtl, Sprite *sprite) const {
|
||||
// If RTL isn't forced, check for RTL text
|
||||
for(const auto c : text) {
|
||||
if(c >= 0x0590 && c <= 0x05FF) {
|
||||
@@ -203,7 +203,7 @@ ITCM_CODE void Font::print(std::u16string_view text, int x, int y, Alignment ali
|
||||
case Alignment::center: {
|
||||
size_t newline = text.find('\n');
|
||||
while(newline != text.npos) {
|
||||
print(text.substr(0, newline), x, y, align, palette, maxWidth, scaleX, scaleY, rtl, sprite);
|
||||
print(text.substr(0, newline), x, y, align, color, maxWidth, scaleX, scaleY, rtl, sprite);
|
||||
text = text.substr(newline + 1);
|
||||
newline = text.find('\n');
|
||||
y += tileHeight;
|
||||
@@ -216,7 +216,7 @@ ITCM_CODE void Font::print(std::u16string_view text, int x, int y, Alignment ali
|
||||
size_t newline = text.find('\n');
|
||||
while(newline != text.npos) {
|
||||
print(text.substr(0, newline), x - (calcWidth(text.substr(0, newline)) * scaleX), y,
|
||||
Alignment::left, palette, maxWidth, scaleX, scaleY, rtl, sprite);
|
||||
Alignment::left, color, maxWidth, scaleX, scaleY, rtl, sprite);
|
||||
text = text.substr(newline + 1);
|
||||
newline = text.find('\n');
|
||||
y += tileHeight;
|
||||
@@ -320,70 +320,44 @@ ITCM_CODE void Font::print(std::u16string_view text, int x, int y, Alignment ali
|
||||
}
|
||||
}
|
||||
|
||||
u8 *dstBegin;
|
||||
int width, height;
|
||||
if(sprite) {
|
||||
// Don't draw off sprite chars
|
||||
if(x >= 0 && x < sprite->width() && y >= 0 && y + tileHeight < sprite->height()) {
|
||||
u16 *dst = sprite->gfx() + x + fontWidths[(index * 3)];
|
||||
// Use faster integer math if scale is 1
|
||||
if(scaleX == 1.0f && scaleY == 1.0f) {
|
||||
for(int i = 0; i < tileHeight; i++) {
|
||||
for(int j = 0; j < tileWidth; j++) {
|
||||
u8 px = fontTiles[(index * tileSize) + (i * tileWidth + j) / 4] >>
|
||||
((3 - ((i * tileWidth + j) % 4)) * 2) &
|
||||
3;
|
||||
if(px)
|
||||
dst[(y + i) * sprite->width() + j] = px + (u8(palette) * 4);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for(float i = 0.0f; i < tileHeight; i += 1 / scaleY) {
|
||||
for(float j = 0.0f; j < tileWidth; j += 1 / scaleY) {
|
||||
u8 px = fontTiles[(index * tileSize) + (i * tileWidth + j) / 4] >>
|
||||
((3 - (int(i * tileWidth + j) % 4)) * 2) &
|
||||
3;
|
||||
if(px)
|
||||
dst[int((y + i) * sprite->width() + j)] = px + (u8(palette) * 4);
|
||||
}
|
||||
width = sprite->width();
|
||||
height = sprite->height();
|
||||
dstBegin = (u8 *)sprite->gfx();
|
||||
} else {
|
||||
width = 256;
|
||||
height = 192;
|
||||
#ifdef UNIVCORE_TEXT_BUFFERED
|
||||
dstBegin = textBuf[currentScreen];
|
||||
#else
|
||||
dstBegin = (u8 *)bgGetGfxPtr(Gui::top ? 2 : 6);
|
||||
#endif
|
||||
}
|
||||
dstBegin += y * width + x + fontWidths[(index * 3)];
|
||||
|
||||
// Don't draw off screen chars
|
||||
if(x >= 0 && x + fontWidths[(index * 3) + 2] < width && y >= 0 && y + tileHeight < height) {
|
||||
// Use faster integer math if scale is 1
|
||||
if(scaleX == 1.0f && scaleY == 1.0f) {
|
||||
for(int i = 0; i < tileHeight; i++) {
|
||||
u8 *dst = dstBegin + i * width;
|
||||
for(int j = 0; j < tileWidth; j++) {
|
||||
u8 px = fontTiles[(index * tileSize) + (i * tileWidth + j) / 4] >>
|
||||
((3 - ((i * tileWidth + j) % 4)) * 2) & 3;
|
||||
if(px)
|
||||
toncset(dst + j, px + color, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Don't draw off screen chars
|
||||
if(x >= 0 && x + fontWidths[(index * 3) + 2] < 256 && y >= 0 && y + tileHeight < 192) {
|
||||
#ifdef UNIVCORE_TEXT_BUFFERED
|
||||
u8 *dst = textBuf[currentScreen] + y * 256 + x + fontWidths[(index * 3)];
|
||||
#else
|
||||
u8 *dst = (u8 *)bgGetGfxPtr(Gui::top ? 2 : 6) + y * 256 + x + fontWidths[(index * 3)];
|
||||
#endif
|
||||
// Use faster integer math if scale is 1
|
||||
if(scaleX == 1.0f && scaleY == 1.0f) {
|
||||
for(int i = 0; i < tileHeight; i++) {
|
||||
for(int j = 0; j < tileWidth; j++) {
|
||||
u8 px = fontTiles[(index * tileSize) + (i * tileWidth + j) / 4] >>
|
||||
((3 - ((i * tileWidth + j) % 4)) * 2) &
|
||||
3;
|
||||
if(px) {
|
||||
#ifdef UNIVCORE_TEXT_BUFFERED
|
||||
dst[i * 256 + j] = px + (u8(palette) * 4);
|
||||
#else
|
||||
toncset(dst + i * 256 + j, px + (u8(palette) * 4), 1);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for(int i = 0; i < tileHeight * scaleY; i++) {
|
||||
for(int j = 0; j < tileWidth * scaleX; j++) {
|
||||
u8 loc = int(i / scaleY) * tileWidth + int(j / scaleX);
|
||||
u8 px = fontTiles[index * tileSize + loc / 4] >> ((3 - (loc % 4)) * 2) & 3;
|
||||
if(px) {
|
||||
#ifdef UNIVCORE_TEXT_BUFFERED
|
||||
dst[i * 256 + j] = px + (u8(palette) * 4);
|
||||
#else
|
||||
toncset(dst + i * 256 + j, px + (u8(palette) * 4), 1);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for(int i = 0; i < tileHeight * scaleY; i++) {
|
||||
u8 *dst = dstBegin + i * width;
|
||||
for(int j = 0; j < tileWidth * scaleX; j++) {
|
||||
u8 loc = int(i / scaleY) * tileWidth + int(j / scaleX);
|
||||
u8 px = fontTiles[index * tileSize + loc / 4] >> ((3 - (loc % 4)) * 2) & 3;
|
||||
if(px)
|
||||
toncset(dst + j, px + color, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+6
-6
@@ -109,23 +109,23 @@ bool Gui::reinit(const char *FontPath) {
|
||||
return Gui::init(FontPath);
|
||||
}
|
||||
|
||||
void Gui::DrawStringCentered(int x, int y, float size, Palette palette, const std::string &Text, int maxWidth, int maxHeight, Font *fnt, int flags) {
|
||||
void Gui::DrawStringCentered(int x, int y, float size, u8 color, const std::string &Text, int maxWidth, int maxHeight, Font *fnt, int flags) {
|
||||
#ifdef UNIVCORE_3DS_SIZE
|
||||
Gui::DrawString(x, y, size, palette, Text, maxWidth, maxHeight, fnt, flags | C2D_AlignCenter);
|
||||
Gui::DrawString(x, y, size, color, Text, maxWidth, maxHeight, fnt, flags | C2D_AlignCenter);
|
||||
#else
|
||||
Gui::DrawString(x, y, size, palette, Text, maxWidth, maxHeight, fnt, flags | C2D_AlignCenter);
|
||||
Gui::DrawString(x, y, size, color, Text, maxWidth, maxHeight, fnt, flags | C2D_AlignCenter);
|
||||
#endif
|
||||
}
|
||||
|
||||
void Gui::DrawString(int x, int y, float size, Palette palette, const std::string &Text, int maxWidth, int maxHeight, Font *fnt, int flags) {
|
||||
void Gui::DrawString(int x, int y, float size, u8 color, const std::string &Text, int maxWidth, int maxHeight, Font *fnt, int flags) {
|
||||
float heightScale = maxHeight == 0 ? size : std::min(size, size * (maxHeight / Gui::GetStringHeight(size, Text, fnt)));
|
||||
float widthScale = maxWidth == 0 ? size : std::min(size, size * (maxWidth / Gui::GetStringWidth(size, Text, fnt)));
|
||||
|
||||
// TODO: Wrapping and such
|
||||
if(fnt)
|
||||
fnt->print(x, y, Text, flags & C2D_AlignCenter ? Alignment::center : (flags & C2D_AlignRight ? Alignment::right : Alignment::left), palette, maxWidth, widthScale, heightScale);
|
||||
fnt->print(x, y, Text, flags & C2D_AlignCenter ? Alignment::center : (flags & C2D_AlignRight ? Alignment::right : Alignment::left), color, maxWidth, widthScale, heightScale);
|
||||
else
|
||||
DefaultFont->print(x, y, Text, flags & C2D_AlignCenter ? Alignment::center : (flags & C2D_AlignRight ? Alignment::right : Alignment::left), palette, maxWidth, widthScale, heightScale);
|
||||
DefaultFont->print(x, y, Text, flags & C2D_AlignCenter ? Alignment::center : (flags & C2D_AlignRight ? Alignment::right : Alignment::left), color, maxWidth, widthScale, heightScale);
|
||||
}
|
||||
|
||||
int Gui::GetStringWidth(float size, const std::string &Text, Font *fnt) {
|
||||
|
||||
+9
-8
@@ -138,22 +138,19 @@ void Image::paletteStart(u8 paletteStart) {
|
||||
}
|
||||
}
|
||||
|
||||
void Image::copyPalette(void) {
|
||||
void Image::copyPalette(void) const {
|
||||
tonccpy((currentScreen ? BG_PALETTE : BG_PALETTE_SUB) + _paletteStart, _palette.data(), _palette.size() * 2);
|
||||
}
|
||||
|
||||
void Image::draw(int x, int y, float scaleX, float scaleY, bool skipAlpha) {
|
||||
void Image::draw(int x, int y, float scaleX, float scaleY, bool skipAlpha) const {
|
||||
SCALE_3DS(x);
|
||||
SCALE_3DS(y);
|
||||
char s[64];
|
||||
// _bitmap[0] = 39;
|
||||
snprintf(s, sizeof(s), "%lu, %lu, %u, %u, 0x%X", _width, _height, _bitmap.size(), _bitmap[0], 0);
|
||||
|
||||
// If the scale is 1 use faster integer math
|
||||
if(scaleX == 1.0f && scaleY == 1.0f) {
|
||||
if(skipAlpha) {
|
||||
for(u32 i = 0; i < _height; i++) {
|
||||
u8 *src = _bitmap.data() + i * _width;
|
||||
const u8 *src = _bitmap.data() + i * _width;
|
||||
u8 *dst = (u8 *)bgGetGfxPtr(currentScreen ? 3 : 7) + (y + i) * 256 + x;
|
||||
for(u32 j = 0; j < _width; j++) {
|
||||
if(_palette[src[j] - _paletteStart] & 0x8000)
|
||||
@@ -178,7 +175,7 @@ void Image::draw(int x, int y, float scaleX, float scaleY, bool skipAlpha) {
|
||||
}
|
||||
}
|
||||
|
||||
void Image::drawSegment(int x, int y, int imageX, int imageY, int w, int h, float scaleX, float scaleY, bool skipAlpha) {
|
||||
void Image::drawSegment(int x, int y, int imageX, int imageY, int w, int h, float scaleX, float scaleY, bool skipAlpha) const {
|
||||
SCALE_3DS(x);
|
||||
SCALE_3DS(y);
|
||||
|
||||
@@ -186,7 +183,7 @@ void Image::drawSegment(int x, int y, int imageX, int imageY, int w, int h, floa
|
||||
if(scaleX == 1.0f && scaleY == 1.0f) {
|
||||
if(skipAlpha) {
|
||||
for(int i = 0; i < h; i++) {
|
||||
u8 *src = _bitmap.data() + i * _width;
|
||||
const u8 *src = _bitmap.data() + i * _width;
|
||||
u8 *dst = (u8 *)bgGetGfxPtr(currentScreen ? 3 : 7) + (y + i) * 256 + x;
|
||||
for(int j = 0; j < w; j++) {
|
||||
if(_palette[src[j] - _paletteStart] & 0x8000)
|
||||
@@ -210,3 +207,7 @@ void Image::drawSegment(int x, int y, int imageX, int imageY, int w, int h, floa
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
u16 Image::operator[](int index) const {
|
||||
return _palette[_bitmap[index] - _paletteStart];
|
||||
}
|
||||
|
||||
+10
-27
@@ -180,36 +180,22 @@ void Sprite::visibility(bool show) {
|
||||
}
|
||||
}
|
||||
|
||||
void Sprite::clear(void) { toncset16(_gfx, 0, (_size & 0xFF) << 5); }
|
||||
void Sprite::clear(void) const { toncset16(_gfx, 0, (_size & 0xFF) << 5); }
|
||||
|
||||
void Sprite::fillColor(u16 color) { toncset16(_gfx, color, (_size & 0xFF) << 5); }
|
||||
void Sprite::fillColor(u16 color) const { toncset16(_gfx, color, (_size & 0xFF) << 5); }
|
||||
|
||||
void Sprite::drawOutline(int x, int y, int w, int h, u16 color) {
|
||||
h += y;
|
||||
if(y >= 0 && y <= _height)
|
||||
toncset16(_gfx + y * _width + std::max(x, 0), color, std::min(w, _width - x));
|
||||
for(y++; y < (h - 1); y++) {
|
||||
if(y >= 0 && y <= _height && x >= 0)
|
||||
_gfx[y * _width + x] = color;
|
||||
if(y >= 0 && y <= _height && x + w <= _width)
|
||||
_gfx[y * _width + x + w - 1] = color;
|
||||
}
|
||||
if(y >= 0 && y <= _height)
|
||||
toncset16(_gfx + y * _width + std::max(x, 0), color, std::min(w, _width - x));
|
||||
}
|
||||
|
||||
void Sprite::drawRectangle(int x, int y, int w, int h, u16 color1, u16 color2) {
|
||||
void Sprite::drawRectangle(int x, int y, int w, int h, u16 color) const {
|
||||
for(int i = 0; i < h; i++) {
|
||||
toncset16(_gfx + ((y + i) * _width + x), ((i % 2) ? color1 : color2), w);
|
||||
toncset16(_gfx + ((y + i) * _width + x), color, w);
|
||||
}
|
||||
}
|
||||
|
||||
void Sprite::drawImage(int x, int y, const Image &image, float scaleX, float scaleY) {
|
||||
void Sprite::drawImage(int x, int y, const Image &image, float scaleX, float scaleY) const {
|
||||
// If the scale is 1 use faster integer math
|
||||
if(scaleX == 1.0f && scaleY == 1.0f) {
|
||||
for(int i = 0; i < image.height(); i++) {
|
||||
for(int j = 0; j < image.width(); j++) {
|
||||
u16 px = image.palette()[image.bitmap()[i * image.width() + j] - image.paletteStart()];
|
||||
u16 px = image[i * image.width() + j];
|
||||
if(px & 0x8000)
|
||||
_gfx[(y + i) * _height + x + j] = px;
|
||||
}
|
||||
@@ -217,8 +203,7 @@ void Sprite::drawImage(int x, int y, const Image &image, float scaleX, float sca
|
||||
} else {
|
||||
for(int i = 0; i < image.height() * scaleY; i++) {
|
||||
for(int j = 0; j < image.width() * scaleX; j++) {
|
||||
u16 px =
|
||||
image.palette()[image.bitmap()[int(i / scaleY) * image.width() + int(j / scaleX)] - image.paletteStart()];
|
||||
u16 px = image[int(i / scaleY) * image.width() + int(j / scaleX)];
|
||||
if(px & 0x8000)
|
||||
_gfx[(y + i) * _height + j + x] = px;
|
||||
}
|
||||
@@ -227,12 +212,12 @@ void Sprite::drawImage(int x, int y, const Image &image, float scaleX, float sca
|
||||
}
|
||||
|
||||
void Sprite::drawImageSegment(int x, int y, int imageX, int imageY, int w, int h, const Image &image, float scaleX,
|
||||
float scaleY) {
|
||||
float scaleY) const {
|
||||
// If the scale is 1 use faster integer math
|
||||
if(scaleX == 1.0f && scaleY == 1.0f) {
|
||||
for(int i = 0; i < h; i++) {
|
||||
for(int j = 0; j < w; j++) {
|
||||
u16 px = image.palette()[image.bitmap()[(imageY + i) * image.width() + imageX + j] - image.paletteStart()];
|
||||
u16 px = image[(imageY + i) * image.width() + imageX + j];
|
||||
if(px & 0x8000)
|
||||
_gfx[(y + i) * _height + x + j] = px;
|
||||
}
|
||||
@@ -240,9 +225,7 @@ void Sprite::drawImageSegment(int x, int y, int imageX, int imageY, int w, int h
|
||||
} else {
|
||||
for(int i = 0; i < h * scaleY; i++) {
|
||||
for(int j = 0; j < w * scaleX; j++) {
|
||||
u16 px = image.palette()[image.bitmap()[(imageY + int(i / scaleY)) * image.width() + imageX +
|
||||
int(j / scaleX)] -
|
||||
image.paletteStart()];
|
||||
u16 px = image[imageY + int(i / scaleY) * image.width() + imageX + int(j / scaleX)];
|
||||
if(px & 0x8000)
|
||||
_gfx[(y + i) * _height + x + j] = px;
|
||||
}
|
||||
|
||||
@@ -83,7 +83,7 @@ Spritesheet::~Spritesheet(void) {
|
||||
}
|
||||
}
|
||||
|
||||
Image &Spritesheet::operator[](size_t index) {
|
||||
Image &Spritesheet::operator[](size_t index) const {
|
||||
if(_images[index] && index < _images.size())
|
||||
return *_images[index];
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user