Add mobile support
All checks were successful
Build & deploy web version / Build WebAssembly & deploy (push) Successful in 1m1s

This commit is contained in:
Andras Schmelczer 2026-08-09 20:39:30 +01:00
commit c4f7565d18
5 changed files with 567 additions and 69 deletions

View file

@ -99,10 +99,12 @@ void handleResize() {
if(screen != NULL && screen -> w == outputWidth && screen -> h == outputHeight) return;
bool heightChanged = screen == NULL || screen -> h != outputHeight;
//a betűméret a kisebbik képernyőoldalhoz igazodik, csak annak változásakor kell újratölteni
bool scaleChanged = screen == NULL ||
smaller(screen -> w, screen -> h) != smaller(outputWidth, outputHeight);
createDrawingSurface(outputWidth, outputHeight);
if(heightChanged) {
if(scaleChanged) {
freeFonts();
openFonts();
}
@ -218,7 +220,7 @@ mousePos getMousePosition() {
///Lerajzolja a képernyőre az egeret, erre azért van szükség, mert az SDL csak fekete-fehér egérmutatót kezel.
void drawMouse(bool isBW) {
Sint16 size = larger(4, mouseSize * screen -> h / designHeight);
Sint16 size = larger(4, (int)(mouseSize * uiScale()));
Sint16 x1 = mouse.x - size / 2;
Sint16 x2 = mouse.x + size / 2;
Sint16 y1 = mouse.y - size / 2;

View file

@ -197,7 +197,7 @@ int aacircleColor(SDL_Surface* dst, Sint16 x, Sint16 y, Sint16 rad, Uint32 color
return 0;
}
int filledPolygonRGBA(SDL_Surface* dst, const Sint16* vx, const Sint16* vy, int n, Uint8 r, Uint8 g, Uint8 b, Uint8 a) {
int filledPolygonRGBA(SDL_Surface* dst, const float* vx, const float* vy, int n, Uint8 r, Uint8 g, Uint8 b, Uint8 a) {
if(n < 3) return -1;
target t;
@ -212,26 +212,32 @@ int filledPolygonRGBA(SDL_Surface* dst, const Sint16* vx, const Sint16* vy, int
if(crossings == NULL) { endTarget(&t); return -1; }
}
int minY = vy[0], maxY = vy[0];
double minY = vy[0], maxY = vy[0];
int i;
for(i = 1; i < n; i++) {
if(vy[i] < minY) minY = vy[i];
if(vy[i] > maxY) maxY = vy[i];
}
int yStart = minY < 0 ? 0 : minY;
int yEnd = maxY > t.h - 1 ? t.h - 1 : maxY;
//A vágás még a törtszámokon megtörténik, így a kerekítés biztosan nem lóg ki az int-ből
if(minY < 0) minY = 0;
if(maxY > t.h - 1) maxY = t.h - 1;
if(minY > maxY) { if(crossings != inlineCrossings) free(crossings); endTarget(&t); return 0; }
int yStart = (int) ceil(minY);
int yEnd = (int) floor(maxY);
int y;
for(y = yStart; y <= yEnd; y++) {
int count = 0;
for(i = 0; i < n; i++) {
int j = (i + 1) % n;
int y1 = vy[i], y2 = vy[j], x1 = vx[i], x2 = vx[j];
if(y1 > y2) { int tmp = y1; y1 = y2; y2 = tmp; tmp = x1; x1 = x2; x2 = tmp; }
double y1 = vy[i], y2 = vy[j], x1 = vx[i], x2 = vx[j];
if(y1 > y2) { double tmp = y1; y1 = y2; y2 = tmp; tmp = x1; x1 = x2; x2 = tmp; }
if((y >= y1 && y < y2) || (y == maxY && y > y1 && y <= y2))
crossings[count++] = x1 + ((double) (y - y1) * (x2 - x1)) / (y2 - y1);
//Félig nyílt intervallum, hogy a két él közös csúcsát pontosan egyszer számoljuk
if(y >= y1 && y < y2)
crossings[count++] = x1 + ((y - y1) * (x2 - x1)) / (y2 - y1);
}
if(count < 2) continue;
@ -244,8 +250,15 @@ int filledPolygonRGBA(SDL_Surface* dst, const Sint16* vx, const Sint16* vy, int
crossings[k + 1] = key;
}
for(i = 0; i + 1 < count; i += 2)
blendHLine(&t, (int) floor(crossings[i] + 0.5), (int) floor(crossings[i + 1] + 0.5), y, r, g, b, a);
for(i = 0; i + 1 < count; i += 2) {
double left = crossings[i], right = crossings[i + 1];
if(left < 0) left = 0;
if(right > t.w - 1) right = t.w - 1;
if(left > right) continue;
int xa = (int) ceil(left), xb = (int) floor(right);
if(xa <= xb) blendHLine(&t, xa, xb, y, r, g, b, a);
}
}
if(crossings != inlineCrossings) free(crossings);
@ -283,7 +296,7 @@ static void aaLine(const target* t, double x0, double y0, double x1, double y1,
}
}
int aapolygonRGBA(SDL_Surface* dst, const Sint16* vx, const Sint16* vy, int n, Uint8 r, Uint8 g, Uint8 b, Uint8 a) {
int aapolygonRGBA(SDL_Surface* dst, const float* vx, const float* vy, int n, Uint8 r, Uint8 g, Uint8 b, Uint8 a) {
if(n < 2) return -1;
target t;

View file

@ -12,7 +12,7 @@
int lineColor(SDL_Surface* dst, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Uint32 color);
int filledCircleColor(SDL_Surface* dst, Sint16 x, Sint16 y, Sint16 rad, Uint32 color);
int aacircleColor(SDL_Surface* dst, Sint16 x, Sint16 y, Sint16 rad, Uint32 color);
int filledPolygonRGBA(SDL_Surface* dst, const Sint16* vx, const Sint16* vy, int n, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
int aapolygonRGBA(SDL_Surface* dst, const Sint16* vx, const Sint16* vy, int n, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
int filledPolygonRGBA(SDL_Surface* dst, const float* vx, const float* vy, int n, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
int aapolygonRGBA(SDL_Surface* dst, const float* vx, const float* vy, int n, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
#endif // GFXPRIMITIVES_H_INCLUDED

View file

@ -1,11 +1,23 @@
#include "unicodePrint.h"
/** \brief A feliratok és a felület méretezéséhez használt arányszám.
* A program az 1920x1080-as képernyőre készült, minden mérete ehhez képest értendő.
* Csak a magassághoz kötni viszont nem szabad: álló tájolású telefonon a képernyő magas,
* de keskeny, így a magasságból számolt betűk kilógnának a szélességből. A kisebbik
* képernyőoldalhoz igazítva a szöveg akkora lesz, amekkorára a fekvő képernyőn is, tehát
* a készülék elforgatása nem változtatja meg a méretét.
*/
float uiScale() {
if(screen == NULL) return 1;
return (float) smaller(screen -> w, screen -> h) / designHeight;
}
///Indításnál betölti a szükséges betűtípusokat.
void openFonts() {
if(!TTF_WasInit()) TTF_Init();
float scale = (float) screen -> h / designHeight;
float scale = uiScale();
fontSmaller = TTF_OpenFont("resources/Roboto-Thin.ttf", larger(1, (int)(40 * scale)));
fontSmall = TTF_OpenFont("resources/Roboto-Thin.ttf", larger(1, (int)(48 * scale)));
fontSmallBold = TTF_OpenFont("resources/Roboto-Light.ttf", larger(1, (int)(53 * scale)));

View file

@ -7,6 +7,7 @@
tiny, small, smallBold, large
} fontType;
float uiScale();
void openFonts();
void freeFonts();
bool isValidChar(wchar_t chr);