This repository has been archived on 2022-05-31. You can view files and clone it, but cannot push or open issues or pull requests.
Luma3DS-3GX/source/draw.c

99 lines
2.9 KiB
C
Raw Normal View History

2015-08-05 11:54:00 +02:00
/*
2016-07-05 16:05:53 +02:00
* This file is part of Luma3DS
* Copyright (C) 2016 Aurora Wright, TuxSH
*
2016-07-05 16:05:53 +02:00
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b of GPLv3 applies to this file: Requiring preservation of specified
* reasonable legal notices or author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
*/
/*
2016-04-23 01:43:11 +02:00
* Code to print to the screen by mid-kid @CakesFW
2016-07-05 16:05:53 +02:00
* https://github.com/mid-kid/CakesForeveryWan/
2015-08-05 11:54:00 +02:00
*/
#include "draw.h"
#include "screen.h"
#include "utils.h"
2015-08-05 11:54:00 +02:00
#include "fs.h"
#include "font.h"
static inline int strlen(const char *string)
{
char *stringEnd = (char *)string;
2016-04-26 20:06:31 +02:00
while(*stringEnd) stringEnd++;
return stringEnd - string;
2016-02-29 16:28:43 +01:00
}
bool loadSplash(void)
{
//Don't delay boot nor init the screens if no splash image is on the SD
if(getFileSize("/luma/splash.bin") + getFileSize("/luma/splash.bin") == 0)
return false;
initScreens();
fileRead(fb->top_left, "/luma/splash.bin");
fileRead(fb->bottom, "/luma/splashbottom.bin");
return true;
}
void drawCharacter(char character, int posX, int posY, u32 color)
{
2016-03-24 16:02:00 +01:00
u8 *const select = fb->top_left;
for(int y = 0; y < 8; y++)
{
char charPos = font[character * 8 + y];
for(int x = 7; x >= 0; x--)
if ((charPos >> x) & 1)
{
int screenPos = (posX * SCREEN_TOP_HEIGHT * 3 + (SCREEN_TOP_HEIGHT - y - posY - 1) * 3) + (7 - x) * 3 * SCREEN_TOP_HEIGHT;
select[screenPos] = color >> 16;
select[screenPos + 1] = color >> 8;
select[screenPos + 2] = color;
}
}
}
int drawString(const char *string, int posX, int posY, u32 color)
{
for(int i = 0, line_i = 0; i < strlen(string); i++, line_i++)
{
if(string[i] == '\n')
{
posY += SPACING_Y;
line_i = 0;
i++;
2016-04-02 18:48:31 +02:00
}
else if(line_i >= (SCREEN_TOP_WIDTH - posX) / SPACING_X)
{
// Make sure we never get out of the screen.
posY += SPACING_Y;
line_i = 2; //Little offset so we know the same string continues.
if(string[i] == ' ') i++; //Spaces at the start look weird
}
drawCharacter(string[i], posX + line_i * SPACING_X, posY, color);
}
return posY;
2015-08-05 11:54:00 +02:00
}