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:
+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