Skip to content

Commit

Permalink
DS Classic Menu: Improve clock hands and add outer shadow to the cloc…
Browse files Browse the repository at this point in the history
…k & calendar (#2450)

* Fix recent sort... again

* DS Classic Menu: Replace line renderer algorithm for a better one

* DS Classic Menu: Added an outer shadow to clock and calendar
  • Loading branch information
mentusfentus authored Aug 6, 2024
1 parent 9b58047 commit fabcfb1
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 34 deletions.
115 changes: 81 additions & 34 deletions quickmenu/arm9/source/graphics/graphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,10 @@ int iconYpos[7] = {25, 73, 73, 121, 175, 170, 175};
bool showdialogbox = false;
int dialogboxHeight = 0;

constexpr int calendarXPos = 127;
constexpr int calendarXPos = 125;
constexpr int calendarYPos = 31;
constexpr int clockXPos = 15;
constexpr int clockYPos = 47;
constexpr int clockXPos = 13;
constexpr int clockYPos = 45;
constexpr int batteryXPos = 242;
constexpr int batteryYPos = 4;

Expand All @@ -125,14 +125,14 @@ u16 bmpImageBuffer[256*192] = {0};
u16 topImageBuffer[256*192] = {0};
u16* colorTable = nullptr;

u16 calendarImageBuffer[113*113] = {0};
u16 calendarBigImageBuffer[113*129] = {0};
u16 calendarImageBuffer[117*115] = {0};
u16 calendarBigImageBuffer[117*131] = {0};
u16 markerImageBuffer[13*13] = {0};

u16 batteryFullImageBuffer[12*7] = {0};
u16 batteryLowImageBuffer[12*7] = {0};

u16 clockImageBuffer[97*97] = {0};
u16 clockImageBuffer[101*101] = {0};
u16 clockNeedleColor;
u16 clockPinColor;
u16 clockUserColor;
Expand Down Expand Up @@ -714,29 +714,45 @@ static void clockNeedleDraw(int angle, u32 length, u16 color) {

constexpr float PI = 3.1415926535897f;

// Find coords from angle & length
int x0 = clockXPos + 50;
int y0 = clockYPos + 50;

float radians = (float)(angle%360) * (PI / 180.0f);
int x1 = x0 + std::cos(radians) * length;
int y1 = y0 - std::sin(radians) * length;

// used for the calculations
float x = clockXPos + 48.0f;
float y = clockYPos + 48.0f;
// used for drawing
int xx, yy;
// Draw line using Bresenham's line algorithm
int dx = abs(x1 - x0);
int dy = -abs(y1 - y0);

int stepX = x0 < x1 ? 1 : -1;
int stepY = y0 < y1 ? 1 : -1;

float cos = std::cos(radians);
float sin = std::sin(radians);
int error = (dx + dy);
int error2;

for (u32 i = 0; i < length; i++) {
x += cos;
y -= sin;
while (true) {
BG_GFX_SUB[y0*256+x0] = color;
BG_GFX_SUB[(y0+1)*256+x0] = color;
BG_GFX_SUB[y0*256+(x0-1)] = color;
BG_GFX_SUB[(y0+1)*256+(x0-1)] = color;

xx = x;
yy = y;
if (x0 == x1 && y0 == y1) break;

BG_GFX_SUB[yy*256+xx] = color;
BG_GFX_SUB[(yy+1)*256+xx] = color;
BG_GFX_SUB[yy*256+(xx-1)] = color;
BG_GFX_SUB[(yy+1)*256+(xx-1)] = color;
error2 = error * 2;

if (error2 >= dy) {
if (x0 == x1) break;
error += dy;
x0 += stepX;
}

if (error2 <= dx) {
if (y0 == y1) break;
error += dx;
y0 += stepY;
}
}
}

Expand Down Expand Up @@ -785,7 +801,7 @@ static void calendarTextDraw(const Datetime& now) {
// Draw marker
{
int myPos = (startWeekday + now.getDay() - 1) / 7;
markerDraw(calendarXPos+now.getWeekDay()*16+2, calendarYPos+myPos*16+34);
markerDraw(calendarXPos+now.getWeekDay()*16+4, calendarYPos+myPos*14+36);
}

// Draw dates
Expand All @@ -804,29 +820,29 @@ static void calendarTextDraw(const Datetime& now) {
}

// Copy to background
updateTopTextArea(calendarXPos, calendarYPos, 113, 129);
updateTopTextArea(calendarXPos, calendarYPos, 113, 131);
}

void calendarDraw() {
if (ms().macroMode) return;

int calendarHeight = 113;
int calendarHeight = 115;
u16* src = calendarImageBuffer;

Datetime datetime = Datetime::now();
Datetime firstDay(datetime.getYear(), datetime.getMonth(), 1);

// If the dates exceed the small calendar then use the big calendar
if (firstDay.getWeekDay() + firstDay.getMonthDays() > 7*5) {
calendarHeight = 129;
calendarHeight = 131;
src = calendarBigImageBuffer;
}

int xDst = calendarXPos;
int yDst = calendarYPos;
for (int yy = 0; yy < 129; yy++) {
for (int yy = 0; yy < 131; yy++) {
xDst = calendarXPos;
for (int xx = 0; xx < 113; xx++) {
for (int xx = 0; xx < 117; xx++) {
if (yy < calendarHeight)
BG_GFX_SUB[yDst*256+xDst] = *(src++);
else
Expand All @@ -846,6 +862,8 @@ void calendarLoad(void) {
markerLoad();

// Small calendar
int calendarX = calendarXPos;
int calendarY = calendarYPos;

const char* filePath = "nitro:/graphics/calendar/calendar.png";
FILE* file = fopen(filePath, "rb");
Expand All @@ -860,12 +878,22 @@ void calendarLoad(void) {
if (colorTable) {
calendarImageBuffer[i] = colorTable[calendarImageBuffer[i]];
}

calendarImageBuffer[i] = alphablend(calendarImageBuffer[i], topImageBuffer[(calendarY*256)+calendarX], image[(i*4)+3]);

calendarX++;
if (calendarX >= calendarXPos + 117) {
calendarX = calendarXPos;
calendarY++;
}
}
}

fclose(file);

// Big calendar
calendarX = calendarXPos;
calendarY = calendarYPos;

filePath = "nitro:/graphics/calendar/calendarbig.png";
file = fopen(filePath, "rb");
Expand All @@ -880,6 +908,14 @@ void calendarLoad(void) {
if (colorTable) {
calendarBigImageBuffer[i] = colorTable[calendarBigImageBuffer[i]];
}

calendarBigImageBuffer[i] = alphablend(calendarBigImageBuffer[i], topImageBuffer[(calendarY*256)+calendarX], image[(i*4)+3]);

calendarX++;
if (calendarX >= calendarXPos + 117) {
calendarX = calendarXPos;
calendarY++;
}
}
}

Expand All @@ -894,6 +930,9 @@ void clockLoad(void) {
const char* filePath = "nitro:/graphics/clock.png";
FILE* file = fopen(filePath, "rb");

int clockX = clockXPos;
int clockY = clockYPos;

if (file) {
// Start loading
std::vector<unsigned char> image;
Expand All @@ -904,6 +943,14 @@ void clockLoad(void) {
if (colorTable) {
clockImageBuffer[i] = colorTable[clockImageBuffer[i]];
}

clockImageBuffer[i] = alphablend(clockImageBuffer[i], topImageBuffer[(clockY*256)+clockX], image[(i*4)+3]);

clockX++;
if (clockX >= clockXPos + 101) {
clockX = clockXPos;
clockY++;
}
}

clockDraw();
Expand All @@ -920,9 +967,9 @@ void clockDraw() {

int dstX = clockXPos;
int dstY = clockYPos;
for (int yy = 0; yy < 97; yy++) {
for (int yy = 0; yy < 101; yy++) {
dstX = clockXPos;
for (int xx = 0; xx < 97; xx++) {
for (int xx = 0; xx < 101; xx++) {
BG_GFX_SUB[dstY*256+dstX] = *(src++);
dstX++;
}
Expand All @@ -932,12 +979,12 @@ void clockDraw() {
float h = (float)time.getHour() + (float)time.getMinute() / 60.0f;

clockNeedleDraw(90-(h * 30), 24, clockNeedleColor); // hour
clockNeedleDraw(90-(time.getMinute() * 6), 32, clockNeedleColor); // minute
clockNeedleDraw(90-(time.getMinute() * 6), 30, clockNeedleColor); // minute
clockNeedleDraw(90-(time.getSecond() * 6), 36, clockUserColor); // second

// draw clock pin
for (int yy = clockYPos+46; yy < clockYPos+46+5; yy++) {
for (int xx = clockXPos+46; xx < clockXPos+46+5; xx++) {
for (int yy = clockYPos+48; yy < clockYPos+48+5; yy++) {
for (int xx = clockXPos+48; xx < clockXPos+48+5; xx++) {
BG_GFX_SUB[yy*256+xx] = clockPinColor;
}
}
Expand Down
Binary file modified quickmenu/nitrofiles/graphics/calendar/calendar.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified quickmenu/nitrofiles/graphics/calendar/calendarbig.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified quickmenu/nitrofiles/graphics/clock.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit fabcfb1

Please sign in to comment.