mirror of
https://github.com/DarkStore-3DS/Universal-Core.git
synced 2026-07-03 00:39:23 +00:00
Very WIP: Make more like 3DS Universal-Core
This commit is contained in:
@@ -1,8 +1,12 @@
|
||||
# Universal-Core (NDS) by Universal-Team
|
||||
This contains the GUI & Core part for our DS(i) Applications.
|
||||
|
||||
## Config
|
||||
Define `BUFFERED_FONT` in `UNIVCORE_CONFIG.h` to have the text be first rendered to a buffer before drawing to the screen with Font::update().
|
||||
## 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).
|
||||
|
||||
|
||||
+29
-21
@@ -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
|
||||
*/
|
||||
|
||||
@@ -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
@@ -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);
|
||||
|
||||
};
|
||||
|
||||
|
||||
+26
-19
@@ -26,9 +26,10 @@
|
||||
|
||||
#include "font.hpp"
|
||||
|
||||
#include "gui.hpp"
|
||||
#include "tonccpy.h"
|
||||
|
||||
#ifdef TEXT_BUFFERED
|
||||
#ifdef UNIVCORE_TEXT_BUFFERED
|
||||
u8 Font::textBuf[2][256 * 192];
|
||||
#endif
|
||||
|
||||
@@ -182,8 +183,8 @@ int Font::calcWidth(std::u16string_view text) {
|
||||
return x;
|
||||
}
|
||||
|
||||
ITCM_CODE void Font::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) {
|
||||
ITCM_CODE void Font::DrawString(std::u16string_view text, int x, int y, Alignment align, Palette palette,
|
||||
int maxWidth, float scaleX, float scaleY, bool rtl, Sprite *sprite) {
|
||||
// If RTL isn't forced, check for RTL text
|
||||
for(const auto c : text) {
|
||||
if(c >= 0x0590 && c <= 0x05FF) {
|
||||
@@ -201,7 +202,7 @@ ITCM_CODE void Font::print(std::u16string_view text, int x, int y, bool top, int
|
||||
case Alignment::center: {
|
||||
size_t newline = text.find('\n');
|
||||
while(newline != text.npos) {
|
||||
print(text.substr(0, newline), x, y, top, layer, align, maxWidth, color, scaleX, scaleY, rtl, sprite);
|
||||
DrawString(text.substr(0, newline), x, y, align, palette, maxWidth, scaleX, scaleY, rtl, sprite);
|
||||
text = text.substr(newline + 1);
|
||||
newline = text.find('\n');
|
||||
y += tileHeight;
|
||||
@@ -213,8 +214,8 @@ ITCM_CODE void Font::print(std::u16string_view text, int x, int y, bool top, int
|
||||
case Alignment::right: {
|
||||
size_t newline = text.find('\n');
|
||||
while(newline != text.npos) {
|
||||
print(text.substr(0, newline), x - (calcWidth(text.substr(0, newline)) * scaleX), y, top, layer,
|
||||
Alignment::left, maxWidth, color, scaleX, scaleY, rtl, sprite);
|
||||
DrawString(text.substr(0, newline), x - (calcWidth(text.substr(0, newline)) * scaleX), y,
|
||||
Alignment::left, palette, maxWidth, scaleX, scaleY, rtl, sprite);
|
||||
text = text.substr(newline + 1);
|
||||
newline = text.find('\n');
|
||||
y += tileHeight;
|
||||
@@ -223,8 +224,14 @@ ITCM_CODE void Font::print(std::u16string_view text, int x, int y, bool top, int
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(align != Alignment::center)
|
||||
SCALE_3DS(x);
|
||||
SCALE_3DS(y);
|
||||
|
||||
const int xStart = x;
|
||||
|
||||
|
||||
if(maxWidth != 0)
|
||||
scaleX = std::min(scaleX, (float)maxWidth / (calcWidth(text) * scaleX));
|
||||
|
||||
@@ -324,7 +331,7 @@ ITCM_CODE void Font::print(std::u16string_view text, int x, int y, bool top, int
|
||||
((3 - ((i * tileWidth + j) % 4)) * 2) &
|
||||
3;
|
||||
if(px)
|
||||
dst[(y + i) * sprite->width() + j] = px + (color * 4);
|
||||
dst[(y + i) * sprite->width() + j] = px + (u8(palette) * 4);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@@ -334,7 +341,7 @@ ITCM_CODE void Font::print(std::u16string_view text, int x, int y, bool top, int
|
||||
((3 - (int(i * tileWidth + j) % 4)) * 2) &
|
||||
3;
|
||||
if(px)
|
||||
dst[int((y + i) * sprite->width() + j)] = px + (color * 4);
|
||||
dst[int((y + i) * sprite->width() + j)] = px + (u8(palette) * 4);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -342,10 +349,10 @@ ITCM_CODE void Font::print(std::u16string_view text, int x, int y, bool top, int
|
||||
} else {
|
||||
// Don't draw off screen chars
|
||||
if(x >= 0 && x + fontWidths[(index * 3) + 2] < 256 && y >= 0 && y + tileHeight < 192) {
|
||||
#ifdef TEXT_BUFFERED
|
||||
u8 *dst = textBuf[top] + y * 256 + x + fontWidths[(index * 3)];
|
||||
#ifdef UNIVCORE_TEXT_BUFFERED
|
||||
u8 *dst = textBuf[Gui::top] + y * 256 + x + fontWidths[(index * 3)];
|
||||
#else
|
||||
u8 *dst = (u8 *)bgGetGfxPtr(top ? layer : layer + 4) + y * 256 + x + fontWidths[(index * 3)];
|
||||
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) {
|
||||
@@ -355,10 +362,10 @@ ITCM_CODE void Font::print(std::u16string_view text, int x, int y, bool top, int
|
||||
((3 - ((i * tileWidth + j) % 4)) * 2) &
|
||||
3;
|
||||
if(px) {
|
||||
#ifdef TEXT_BUFFERED
|
||||
dst[i * 256 + j] = px + (color * 4);
|
||||
#ifdef UNIVCORE_TEXT_BUFFERED
|
||||
dst[i * 256 + j] = px + (u8(palette) * 4);
|
||||
#else
|
||||
toncset(dst + i * 256 + j, px + (color * 4), 1);
|
||||
toncset(dst + i * 256 + j, px + (u8(palette) * 4), 1);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -369,10 +376,10 @@ ITCM_CODE void Font::print(std::u16string_view text, int x, int y, bool top, int
|
||||
u8 loc = int(i / scaleY) * tileWidth + int(j / scaleX);
|
||||
u8 px = fontTiles[index * tileSize + loc / 4] >> ((3 - (loc % 4)) * 2) & 3;
|
||||
if(px) {
|
||||
#ifdef TEXT_BUFFERED
|
||||
dst[i * 256 + j] = px + (color * 4);
|
||||
#ifdef UNIVCORE_TEXT_BUFFERED
|
||||
dst[i * 256 + j] = px + (u8(palette) * 4);
|
||||
#else
|
||||
toncset(dst + i * 256 + j, px + (color * 4), 1);
|
||||
toncset(dst + i * 256 + j, px + (u8(palette) * 4), 1);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -385,10 +392,10 @@ ITCM_CODE void Font::print(std::u16string_view text, int x, int y, bool top, int
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef TEXT_BUFFERED
|
||||
#ifdef UNIVCORE_TEXT_BUFFERED
|
||||
void Font::clear(bool top) { dmaFillWords(0, Font::textBuf[top], 256 * 192); }
|
||||
|
||||
void Font::update(bool top) {
|
||||
tonccpy(bgGetGfxPtr(top ? TEXT_TOP_LAYER : TEXT_BOTTOM_LAYER + 4), Font::textBuf[top], 256 * 192);
|
||||
tonccpy(bgGetGfxPtr(top ? 2 : 6), Font::textBuf[top], 256 * 192);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -24,16 +24,18 @@
|
||||
* reasonable ways as different from the original version.
|
||||
*/
|
||||
|
||||
#include "graphics.hpp"
|
||||
#include "gui.hpp"
|
||||
#include "gui.hpp"
|
||||
|
||||
#include "tonccpy.h"
|
||||
|
||||
#include <nds.h>
|
||||
|
||||
int Graphics::bg3Main, Graphics::bg2Main, Graphics::bg3Sub, Graphics::bg2Sub;
|
||||
bool Graphics::wideScreen = false;
|
||||
int Gui::bg3Main, Gui::bg2Main, Gui::bg3Sub, Gui::bg2Sub;
|
||||
bool Gui::widescreen = false;
|
||||
bool Gui::top = false;
|
||||
|
||||
void Graphics::init(void) {
|
||||
void Gui::init(void) {
|
||||
// Initialize video mode
|
||||
videoSetMode(MODE_5_2D);
|
||||
videoSetModeSub(MODE_5_2D);
|
||||
@@ -63,29 +65,22 @@ void Graphics::init(void) {
|
||||
REG_BLDCNT_SUB = 1 << 11;
|
||||
}
|
||||
|
||||
void Graphics::clear(bool top, int layer) { toncset(bgGetGfxPtr(top ? layer : layer + 4), 0, 256 * 192); }
|
||||
|
||||
void Graphics::drawOutline(int x, int y, int w, int h, u8 color, bool top, int layer) {
|
||||
u8 *dst = (u8 *)bgGetGfxPtr(top ? layer : layer + 4);
|
||||
h += y;
|
||||
if(y >= 0 && y <= 192)
|
||||
toncset(dst + y * 256 + std::max(x, 0), color, std::min(w, 256 - x));
|
||||
for(y++; y < (h - 1); y++) {
|
||||
if(y >= 0 && y <= 192 && x >= 0)
|
||||
toncset(dst + y * 256 + x, color, 1);
|
||||
if(y >= 0 && y <= 192 && x + w <= 256)
|
||||
toncset(dst + y * 256 + x + w - 1, color, 1);
|
||||
}
|
||||
if(y >= 0 && y <= 192)
|
||||
toncset(dst + y * 256 + std::max(x, 0), color, std::min(w, 256 - x));
|
||||
void Gui::clear(bool top) {
|
||||
toncset(bgGetGfxPtr(top ? bg3Main : bg3Sub), 0, 256 * 192);
|
||||
}
|
||||
|
||||
void Graphics::drawRectangle(int x, int y, int w, int h, u8 color, bool top, bool layer) {
|
||||
Graphics::drawRectangle(x, y, w, h, color, color, top, layer);
|
||||
void Gui::ScreenDraw(bool top) {
|
||||
Gui::top = top;
|
||||
}
|
||||
void Graphics::drawRectangle(int x, int y, int w, int h, u8 color1, u8 color2, bool top, bool layer) {
|
||||
u8 *dst = (u8 *)bgGetGfxPtr(top ? layer : layer + 4);
|
||||
|
||||
void Gui::Draw_Rect(int x, int y, int w, int h, u8 color) {
|
||||
SCALE_3DS(x);
|
||||
SCALE_3DS(y);
|
||||
SCALE_3DS(w);
|
||||
SCALE_3DS(h);
|
||||
|
||||
u8 *dst = (u8 *)bgGetGfxPtr(top ? bg3Main : bg3Sub);
|
||||
for(int i = 0; i < h; i++) {
|
||||
toncset(dst + ((y + i) * 256 + x), ((i % 2) ? color1 : color2), w);
|
||||
toncset(dst + ((y + i) * 256 + x), color, w);
|
||||
}
|
||||
}
|
||||
+33
-15
@@ -26,6 +26,8 @@
|
||||
|
||||
#include "image.hpp"
|
||||
|
||||
#include "gui.hpp"
|
||||
|
||||
#include "tonccpy.h"
|
||||
|
||||
Image::Image(const std::vector<std::string> &paths) {
|
||||
@@ -84,11 +86,14 @@ Image::Image(FILE *file) {
|
||||
fclose(file);
|
||||
}
|
||||
|
||||
void Image::draw(int x, int y, bool top, int layer, bool copyPal) {
|
||||
if(copyPal)
|
||||
tonccpy((top ? BG_PALETTE : BG_PALETTE_SUB) + _palOfs, _palette.data(), _palette.size() * 2);
|
||||
void Image::draw(int x, int y, bool copyPal) {
|
||||
SCALE_3DS(x);
|
||||
SCALE_3DS(y);
|
||||
|
||||
u8 *dst = (u8 *)bgGetGfxPtr(top ? layer : layer + 4) + y * 256 + x;
|
||||
if(copyPal)
|
||||
tonccpy((Gui::top ? BG_PALETTE : BG_PALETTE_SUB) + _palOfs, _palette.data(), _palette.size() * 2);
|
||||
|
||||
u8 *dst = (u8 *)bgGetGfxPtr(Gui::top ? 3 : 7) + y * 256 + x;
|
||||
|
||||
// If full width and X is 0, copy it all in one go
|
||||
if(_width == 256 && x == 0) {
|
||||
@@ -100,16 +105,22 @@ void Image::draw(int x, int y, bool top, int layer, bool copyPal) {
|
||||
}
|
||||
}
|
||||
|
||||
void Image::drawSpecial(int x, int y, bool top, int layer, float scaleX, float scaleY, int paletteOffset,
|
||||
void Image::drawSpecial(int x, int y, float scaleX, float scaleY, int paletteOffset,
|
||||
bool copyPal) {
|
||||
if(copyPal)
|
||||
tonccpy((top ? BG_PALETTE : BG_PALETTE_SUB) + _palOfs + paletteOffset, _palette.data(), _palette.size() * 2);
|
||||
SCALE_3DS(x);
|
||||
SCALE_3DS(y);
|
||||
|
||||
u8 *dst = (u8 *)bgGetGfxPtr(top ? layer : layer + 4) + y * 256 + x;
|
||||
if(copyPal)
|
||||
tonccpy((Gui::top ? BG_PALETTE : BG_PALETTE_SUB) + _palOfs + paletteOffset, _palette.data(), _palette.size() * 2);
|
||||
|
||||
u8 *dst = (u8 *)bgGetGfxPtr(Gui::top ? 3 : 7) + y * 256 + x;
|
||||
|
||||
// If the scale is 1 use faster integer math
|
||||
nocashMessage("a");
|
||||
if(scaleX == 1.0f && scaleY == 1.0f) {
|
||||
nocashMessage("b");
|
||||
for(int i = 0; i < _height; i++) {
|
||||
nocashMessage("d");
|
||||
for(int j = 0; j < _width; j++) {
|
||||
u8 px = _bitmap[i * _width + j];
|
||||
if(_palette[px - _palOfs] & 0x8000)
|
||||
@@ -117,6 +128,7 @@ void Image::drawSpecial(int x, int y, bool top, int layer, float scaleX, float s
|
||||
}
|
||||
}
|
||||
} else {
|
||||
nocashMessage("c");
|
||||
for(int i = 0; i < _height * scaleY; i++) {
|
||||
for(int j = 0; j < _width * scaleX; j++) {
|
||||
u8 px = _bitmap[int(i / scaleY) * _width + int(j / scaleX)];
|
||||
@@ -127,22 +139,28 @@ void Image::drawSpecial(int x, int y, bool top, int layer, float scaleX, float s
|
||||
}
|
||||
}
|
||||
|
||||
void Image::drawSegment(int x, int y, int imageX, int imageY, int w, int h, bool top, int layer, bool copyPal) {
|
||||
void Image::drawSegment(int x, int y, int imageX, int imageY, int w, int h, bool copyPal) {
|
||||
SCALE_3DS(x);
|
||||
SCALE_3DS(y);
|
||||
|
||||
if(copyPal)
|
||||
tonccpy((top ? BG_PALETTE : BG_PALETTE_SUB) + _palOfs, _palette.data(), _palette.size() * 2);
|
||||
tonccpy((Gui::top ? BG_PALETTE : BG_PALETTE_SUB) + _palOfs, _palette.data(), _palette.size() * 2);
|
||||
|
||||
for(int i = 0; i < h; i++) {
|
||||
tonccpy((u8 *)bgGetGfxPtr(top ? layer : layer + 4) + (y + i) * 256 + x,
|
||||
tonccpy((u8 *)bgGetGfxPtr(Gui::top ? 3 : 7) + (y + i) * 256 + x,
|
||||
_bitmap.data() + (imageY + i) * _width + imageX, w);
|
||||
}
|
||||
}
|
||||
|
||||
void Image::drawSegmentSpecial(int x, int y, int imageX, int imageY, int w, int h, bool top, int layer, float scaleX,
|
||||
void Image::drawSegmentSpecial(int x, int y, int imageX, int imageY, int w, int h, float scaleX,
|
||||
float scaleY, int paletteOffset, bool copyPal) {
|
||||
if(copyPal)
|
||||
tonccpy((top ? BG_PALETTE : BG_PALETTE_SUB) + _palOfs + paletteOffset, _palette.data(), _palette.size() * 2);
|
||||
SCALE_3DS(x);
|
||||
SCALE_3DS(y);
|
||||
|
||||
u8 *dst = (u8 *)bgGetGfxPtr(top ? layer : layer + 4) + y * 256 + x;
|
||||
if(copyPal)
|
||||
tonccpy((Gui::top ? BG_PALETTE : BG_PALETTE_SUB) + _palOfs + paletteOffset, _palette.data(), _palette.size() * 2);
|
||||
|
||||
u8 *dst = (u8 *)bgGetGfxPtr(Gui::top ? 3 : 7) + y * 256 + x;
|
||||
|
||||
// If the scale is 1 use faster integer math
|
||||
if(scaleX == 1.0f && scaleY == 1.0f) {
|
||||
|
||||
Reference in New Issue
Block a user