Skip to content

Commit

Permalink
3ds: changes for sdl2 port
Browse files Browse the repository at this point in the history
  • Loading branch information
vgmoose committed Jun 11, 2024
1 parent 2d9cfc8 commit e3d50ed
Show file tree
Hide file tree
Showing 10 changed files with 60 additions and 28 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
push:
branches:
- main
- sdl2-only
pull_request:
branches:
- main
Expand All @@ -20,8 +21,8 @@ jobs:
ext: wuhb
- platform: switch
ext: nro
# - platform: 3ds
# ext: 3dsx
- platform: 3ds
ext: 3dsx
- platform: wii
ext: dol
container:
Expand Down
10 changes: 5 additions & 5 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ Switch:
PLATFORM: switch
EXT: nro

# 3ds:
# <<: *common
# variables:
# PLATFORM: 3ds
# EXT: 3dsx
3ds:
<<: *common
variables:
PLATFORM: 3ds
EXT: 3dsx

Wii:
<<: *common
Expand Down
4 changes: 1 addition & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,9 @@ SOURCES += libs/chesto/libs/resinfs/source
INCLUDES += libs/chesto/libs/resinfs/include
endif

# for sdl2 platforms (wiiu or pc or switch targets) use sdl font cache
ifeq ($(filter-out wiiu pc wii switch,$(MAKECMDGOALS)),)
# for sdl2 platforms, use sdl font cache
SOURCES += $(CHESTO_DIR)/libs/SDL_FontCache
VPATH += $(CHESTO_DIR)/libs/SDL_FontCache
endif

CFLAGS += $(INCLUDE) -DAPP_VERSION=\"$(APP_VERSION)\" -frandom-seed=84248
CXXFLAGS += $(CFLAGS) -fno-exceptions -std=gnu++20
Expand Down
8 changes: 6 additions & 2 deletions helpers/Makefile.sdl2
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,9 @@ ifeq ($(OS),Windows_NT)
CFLAGS += -DWIN32
endif

LIBS += -lSDL2_ttf -lSDL2_gfx -lSDL2_image -lSDL2_mixer -lmpg123 -lSDL2 -lSDL2main -lfreetype -lpng -lbz2 -ljpeg -lz
CFLAGS += -DSDL2 -DMUSIC
LIBS += -lSDL2_ttf -lSDL2_image -lmpg123 -lSDL2 -lSDL2main -lfreetype -lpng -lbz2 -ljpeg -lz
CFLAGS += -DSDL2

ifneq (3ds,$(MAKECMDGOALS))
CFLAGS += -DMUSIC -lSDL2_gfx -lSDL2_mixer
endif
30 changes: 20 additions & 10 deletions src/DrawUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,6 @@ bool CST_DrawInit(RootDisplay* root)
SDLFlags |= SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC;
windowFlags |= SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI;

#ifdef _3DS
SDLFlags |= SDL_HWSURFACE | SDL_DUALSCR;
#endif

root->window = SDL_CreateWindow(
NULL, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
SCREEN_WIDTH, SCREEN_HEIGHT, windowFlags);
Expand All @@ -47,12 +43,6 @@ bool CST_DrawInit(RootDisplay* root)

if (root->renderer == NULL || root->window == NULL)
{
#ifdef _3DS
char* err = SDL_GetError();
FILE *file = fopen("error.txt", "w");
fprintf(file, "%s", err);
fclose(file);
#endif
SDL_Quit();
return false;
}
Expand Down Expand Up @@ -248,7 +238,10 @@ void CST_SetQualityHint(const char* quality)

void CST_filledCircleRGBA(CST_Renderer* renderer, uint32_t x, uint32_t y, uint32_t radius, uint32_t r, uint32_t g, uint32_t b, uint32_t a)
{
#if !defined(_3DS) && !defined(_3DS_MOCK)
// TODO: filledCircleRGBA needs to take a surface on 3DS
filledCircleRGBA(renderer, x, y, radius, r, g, b, a);
#endif
}

void CST_SetWindowSize(CST_Window* window, int w, int h)
Expand Down Expand Up @@ -310,15 +303,32 @@ void CST_roundedBoxRGBA (
Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2,
Sint16 rad, Uint8 r, Uint8 g, Uint8 b, Uint8 a
) {
#if !defined(_3DS) && !defined(_3DS_MOCK)
// TODO: roundedBoxRGBA needs to take a surface on 3DS
roundedBoxRGBA(renderer, x1, y1, x2, y2, rad, r, g, b, a);
#endif
}

void CST_roundedRectangleRGBA (
CST_Renderer *renderer,
Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2,
Sint16 rad, Uint8 r, Uint8 g, Uint8 b, Uint8 a
) {
#if !defined(_3DS) && !defined(_3DS_MOCK)
// TODO: roundedRectangleRGBA needs to take a surface on 3DS
roundedRectangleRGBA(renderer, x1, y1, x2, y2, rad, r, g, b, a);
#endif
}

void CST_rectangleRGBA (
CST_Renderer *renderer,
Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2,
Uint8 r, Uint8 g, Uint8 b, Uint8 a
) {
#if !defined(_3DS) && !defined(_3DS_MOCK)
// TODO: rectangleRGBA needs to take a surface on 3DS
rectangleRGBA(renderer, x1, y1, x2, y2, rad, r, g, b, a);
#endif
}

#ifdef MUSIC
Expand Down
14 changes: 12 additions & 2 deletions src/DrawUtils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,19 @@
#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
#include <SDL2/SDL_ttf.h>

#if defined(_3DS)
#include <SDL2/SDL_gfxPrimitives.h> // this file has a different name on 3ds
#else
#include <SDL2/SDL2_gfxPrimitives.h>
#include <SDL2/SDL2_gfxPrimitives.h>
#endif

#include "../libs/SDL_FontCache/SDL_FontCache.h"

#include <string>

#if defined(MUSIC)
#include <SDL2/SDL_mixer.h>
#include <string>
#include <mpg123.h>
typedef Mix_Music CST_Music;
#endif
Expand Down Expand Up @@ -60,6 +65,11 @@ void CST_roundedRectangleRGBA (
Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2,
Sint16 rad, Uint8 r, Uint8 g, Uint8 b, Uint8 a
);
void CST_rectangleRGBA (
CST_Renderer *renderer,
Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2,
Uint8 r, Uint8 g, Uint8 b, Uint8 a
);
float CST_GetDpiScale();
void CST_SetWindowSize(CST_Window* renderer, int w, int h);
void CST_Delay(int time);
Expand Down
4 changes: 2 additions & 2 deletions src/Element.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,14 @@ void Element::render(Element* parent)
if (this->touchable && this->elasticCounter > NO_HIGHLIGHT)
{
CST_Rect d = { this->xAbs - 5, this->yAbs - 5, this->width + 10, this->height + 10 };
rectangleRGBA(renderer, d.x, d.y, d.x + d.w, d.y + d.h, 0x66, 0x7c, 0x89, 0xFF);
CST_rectangleRGBA(renderer, d.x, d.y, d.x + d.w, d.y + d.h, 0x66, 0x7c, 0x89, 0xFF);

if (this->elasticCounter == THICK_HIGHLIGHT)
{
// make it a little thicker by drawing more rectangles TODO: better way to do this?
for (int x = 0; x < 5; x++)
{
rectangleRGBA(renderer, d.x + x, d.y + x, d.x + d.w - x, d.y + d.h - x, 0x66 - x * 10, 0x7c + x * 20, 0x89 + x * 10, 0xFF);
CST_rectangleRGBA(renderer, d.x + x, d.y + x, d.x + d.w - x, d.y + d.h - x, 0x66 - x * 10, 0x7c + x * 20, 0x89 + x * 10, 0xFF);
}
}
}
Expand Down
7 changes: 7 additions & 0 deletions src/InputEvents.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
#pragma once

#include <SDL2/SDL.h>

#if !defined(_3DS) && !defined(_3DS_MOCK)
// 3ds has no sdl keycodes
typedef SDL_Keycode CST_Keycode;
#else
typedef int CST_Keycode;
#endif

typedef uint16_t CST_Keymod;

#include <functional>
Expand Down
2 changes: 1 addition & 1 deletion src/ProgressBar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,5 @@ void ProgressBar::render(Element* parent)
CST_FillRect(renderer, &blue_rect);

// draw right "circle" (rounded part of bar, and ending)
filledCircleRGBA(renderer, this->xAbs + width * this->percent, this->yAbs, 4, 0x56, 0xc1, 0xdf, 0xff);
CST_filledCircleRGBA(renderer, this->xAbs + width * this->percent, this->yAbs, 4, 0x56, 0xc1, 0xdf, 0xff);
}
4 changes: 3 additions & 1 deletion src/RootDisplay.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#if defined(SWITCH)
#if defined(__EMSCRIPTEN__)
#include <emscripten.h>
#elif defined(SWITCH)
#include <switch.h>
#define PLATFORM "Switch"
#elif defined(__WIIU__)
Expand Down

0 comments on commit e3d50ed

Please sign in to comment.