Initial
This commit is contained in:
commit
62d2de747e
12 changed files with 130940 additions and 0 deletions
22
Code blocks projekt/modules/auxiliary/auxFunctions.c
Normal file
22
Code blocks projekt/modules/auxiliary/auxFunctions.c
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
#include "auxFunctions.h"
|
||||
|
||||
|
||||
extern inline float randomWithinBorders(float base, float variance);
|
||||
extern inline int randomIntWithinBorders(int base, int variance);
|
||||
|
||||
extern inline int randomPlusOrMinus();
|
||||
|
||||
extern inline int larger(int a, int b);
|
||||
extern inline int smaller(int a, int b);
|
||||
|
||||
extern inline float largerF(float a, float b);
|
||||
extern inline float smallerF(float a, float b);
|
||||
|
||||
extern inline void putInsideInterval(int min, int* a, int max);
|
||||
extern inline void putInsideIntervalF(float min, float* a, float max);
|
||||
|
||||
extern inline float dist(int a, int b);
|
||||
extern inline float fDist(float a, float b);
|
||||
|
||||
extern inline float square(float a);
|
||||
|
||||
22
Code blocks projekt/modules/auxiliary/auxFunctions.c.save
Normal file
22
Code blocks projekt/modules/auxiliary/auxFunctions.c.save
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
#include "auxFunctions.h"
|
||||
|
||||
|
||||
extern inline float randomWithinBorders(float base, float variance);
|
||||
extern inline int randomIntWithinBorders(int base, int variance);
|
||||
|
||||
extern inline int randomPlusOrMinus();
|
||||
|
||||
extern inline int larger(int a, int b);
|
||||
extern inline int smaller(int a, int b);
|
||||
|
||||
extern inline float largerF(float a, float b);
|
||||
extern inline float smallerF(float a, float b);
|
||||
|
||||
extern inline void putInsideInterval(int min, int* a, int max);
|
||||
extern inline void putInsideIntervalF(float min, float* a, float max);
|
||||
|
||||
extern inline float dist(int a, int b);
|
||||
extern inline float fDist(float a, float b);
|
||||
|
||||
extern inline float square(float a);
|
||||
|
||||
58
Code blocks projekt/modules/auxiliary/auxFunctions.h
Normal file
58
Code blocks projekt/modules/auxiliary/auxFunctions.h
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
#ifndef AUXFUNCTIONS_H_INCLUDED
|
||||
#define AUXFUNCTIONS_H_INCLUDED
|
||||
|
||||
#include "../global.h"
|
||||
|
||||
inline float randomWithinBorders(float base, float variance) {
|
||||
int intVariance = (int)(1e4 * variance);
|
||||
return (1e4 * base + (rand() % (2 * intVariance + 1) - intVariance)) / 1e4;
|
||||
}
|
||||
|
||||
inline int randomIntWithinBorders(int base, int variance) {
|
||||
return base + (rand() % (2 * variance + 1) - variance);
|
||||
}
|
||||
|
||||
inline int randomPlusOrMinus() {
|
||||
return rand() % 2 ? 1 : -1;
|
||||
}
|
||||
|
||||
|
||||
inline int larger(int a, int b) {
|
||||
return a > b ? a : b;
|
||||
}
|
||||
|
||||
inline int smaller(int a, int b) {
|
||||
return a < b ? a : b;
|
||||
}
|
||||
|
||||
inline float largerF(float a, float b) {
|
||||
return a > b ? a : b;
|
||||
}
|
||||
|
||||
inline float smallerF(float a, float b) {
|
||||
return a < b ? a : b;
|
||||
}
|
||||
|
||||
|
||||
inline void putInsideInterval(int min, int* a, int max) {
|
||||
*a = largerF(min, smallerF(*a, max));
|
||||
}
|
||||
|
||||
inline void putInsideIntervalF(float min, float* a, float max) {
|
||||
*a = largerF(min, smallerF(*a, max));
|
||||
}
|
||||
|
||||
|
||||
inline float dist(int a, int b) {
|
||||
return sqrt(a*a + b*b);
|
||||
}
|
||||
|
||||
inline float fDist(float a, float b) {
|
||||
return sqrt(a*a + b*b);
|
||||
}
|
||||
|
||||
inline float square(float a) {
|
||||
return a*a;
|
||||
}
|
||||
|
||||
#endif // AUXFUNCTIONS_H_INCLUDED
|
||||
64
Code blocks projekt/modules/auxiliary/auxFunctions.h.save
Normal file
64
Code blocks projekt/modules/auxiliary/auxFunctions.h.save
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
#ifndef AUXFUNCTIONS_H_INCLUDED
|
||||
#define AUXFUNCTIONS_H_INCLUDED
|
||||
|
||||
#include "../global.h"
|
||||
|
||||
inline float randomWithinBorders(float base, float variance) {
|
||||
int intVariance = (int)(1e4 * variance);
|
||||
return (1e4 * base + (rand() % (2 * intVariance + 1) - intVariance)) / 1e4;
|
||||
}
|
||||
|
||||
inline int randomIntWithinBorders(int base, int variance) {
|
||||
return base + (rand() % (2 * variance + 1) - variance);
|
||||
}
|
||||
|
||||
inline int randomPlusOrMinus() {
|
||||
return rand() % 2 ? 1 : -1;
|
||||
}
|
||||
|
||||
|
||||
inline int larger(int a, int b) {
|
||||
return a > b ? a : b;
|
||||
}
|
||||
|
||||
inline int smaller(int a, int b) {
|
||||
return a < b ? a : b;
|
||||
}
|
||||
|
||||
inline float largerF(float a, float b) {
|
||||
return a > b ? a : b;
|
||||
}
|
||||
|
||||
inline float smallerF(float a, float b) {
|
||||
return a < b ? a : b;
|
||||
}
|
||||
|
||||
|
||||
inline void putInsideInterval(int min, int* a, int max) {
|
||||
*a = largerF(min, smallerF(*a, max));
|
||||
}
|
||||
|
||||
inline void putInsideIntervalF(float min, float* a, float max) {
|
||||
*a = largerF(min, smallerF(*a, max));
|
||||
}
|
||||
|
||||
|
||||
inline float dist(int a, int b) {
|
||||
return sqrt(a*a + b*b);
|
||||
}
|
||||
|
||||
inline float fDist(float a, float b) {
|
||||
return sqrt(a*a + b*b);
|
||||
}
|
||||
|
||||
inline float square(float a) {
|
||||
return a*a;
|
||||
}
|
||||
|
||||
//++print + int = print xd
|
||||
inline void print(int a) {
|
||||
printf("%d\n", a);
|
||||
}
|
||||
|
||||
|
||||
#endif // AUXFUNCTIONS_H_INCLUDED
|
||||
73
Code blocks projekt/modules/auxiliary/auxSDL.c
Normal file
73
Code blocks projekt/modules/auxiliary/auxSDL.c
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
#include "auxSDL.h"
|
||||
|
||||
mousePos mouse; /**< Az egér koordinátáit tárolja, így egyszerűbb, mint közvetlen az eventek figyelése. */
|
||||
|
||||
|
||||
/** \brief https://www.libsdl.org/release/SDL-1.2.15/docs/html/sdlcreatecursor.html
|
||||
* Hogy erre miért van szükség, az egy nagyon jó kérdés. Ha ehelyett a "SDL_ShowCursor(SDL_DISABLE);"-t
|
||||
* használnám az egér random ugrálna néha néha, így viszont ezt nem teszi.
|
||||
*/
|
||||
static SDL_Cursor* createCursor() {
|
||||
Uint8 data[4*32] = {0};
|
||||
Uint8 mask[4*32] = {0};
|
||||
return SDL_CreateCursor(data, mask, 32, 32, 0, 0);
|
||||
}
|
||||
|
||||
/** \brief Létrehozza a játék futtatásához szükséges környezetet.
|
||||
* Megnézi az elérhető legnagyobb felbontást, azzal a felbontással létrehoz egy ablakot, illetve
|
||||
* meghív pár, az inicializáláshoz szükséges függvényt.
|
||||
* \return kurzor amit fel kell később szabadítanunk
|
||||
*/
|
||||
SDL_Cursor* openWindow() {
|
||||
SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER);
|
||||
SDL_Rect** screenSizes = SDL_ListModes(NULL, SDL_FULLSCREEN);
|
||||
|
||||
screen = SDL_SetVideoMode(screenSizes[0] -> w, screenSizes[0] -> h, 0, SDL_FULLSCREEN);
|
||||
|
||||
if (!screen) {
|
||||
fprintf(stderr, "Nem sikerult megnyitni az ablakot!\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
SDL_WM_SetCaption("Platform játék", "Schmelczer András: Platform játék");
|
||||
SDL_Cursor* cursor = createCursor();
|
||||
SDL_SetCursor(cursor);
|
||||
openFonts();
|
||||
SDL_WM_GrabInput(SDL_GRAB_FULLSCREEN);
|
||||
return cursor;
|
||||
}
|
||||
|
||||
///A játék időzítéséhez szükséges.
|
||||
Uint32 timer(Uint32 ms, void* param) {
|
||||
SDL_Event event;
|
||||
event.type = SDL_USEREVENT;
|
||||
SDL_PushEvent(&event);
|
||||
return ms;
|
||||
}
|
||||
|
||||
///Frissití az egér pozicióját.
|
||||
void setMousePosition(Uint16 x, Uint16 y) {
|
||||
mouse.x = x;
|
||||
mouse.y = y;
|
||||
}
|
||||
|
||||
///Visszaadja az egérpoziciót.
|
||||
mousePos getMousePosition() {
|
||||
return mouse;
|
||||
}
|
||||
|
||||
///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 x1 = mouse.x - mouseSize / 2;
|
||||
Sint16 x2 = mouse.x + mouseSize / 2;
|
||||
Sint16 y1 = mouse.y - mouseSize / 2;
|
||||
Sint16 y2 = mouse.y + mouseSize / 2;
|
||||
boxColor(screen, x1, y1, x2, y2, isBW ? 0x7F7F7FFF : 0xFFFF00FF);
|
||||
}
|
||||
|
||||
///Egy téglalap felett van-e az egérmutató közepe?
|
||||
bool isMouseOverRect(int xCenter, int yCenter, int xSize, int ySize) {
|
||||
return
|
||||
screen -> w / 100.0 * (xCenter - xSize) < mouse.x && mouse.x < screen -> w / 100.0 * (xCenter + xSize) &&
|
||||
screen -> h / 100.0 * (yCenter - ySize) < mouse.y && mouse.y < screen -> h / 100.0 * (yCenter + ySize);
|
||||
}
|
||||
80
Code blocks projekt/modules/auxiliary/auxSDL.c.save
Normal file
80
Code blocks projekt/modules/auxiliary/auxSDL.c.save
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
#include "auxSDL.h"
|
||||
|
||||
mousePos mouse; /**< Az egér koordinátáit tárolja, így egyszerűbb, mint közvetlen az eventek figyelése. */
|
||||
|
||||
|
||||
/** \brief https://www.libsdl.org/release/SDL-1.2.15/docs/html/sdlcreatecursor.html
|
||||
* Hogy erre miért van szükség, az egy nagyon jó kérdés. Ha ehelyett a "SDL_ShowCursor(SDL_DISABLE);"-t
|
||||
* használnám az egér random ugrálna néha néha, így viszont ezt nem teszi.
|
||||
*/
|
||||
static SDL_Cursor* createCursor() {
|
||||
Uint8 data[4*32] = {0};
|
||||
Uint8 mask[4*32] = {0};
|
||||
return SDL_CreateCursor(data, mask, 32, 32, 0, 0);
|
||||
}
|
||||
|
||||
/** \brief Létrehozza a játék futtatásához szükséges környezetet.
|
||||
* Megnézi az elérhető legnagyobb felbontást, azzal a felbontással létrehoz egy ablakot, illetve
|
||||
* meghív pár, az inicializáláshoz szükséges függvényt.
|
||||
* \return kurzor amit fel kell később szabadítanunk
|
||||
*/
|
||||
SDL_Cursor* openWindow() {
|
||||
SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER);
|
||||
SDL_Rect** screenSizes = SDL_ListModes(NULL, SDL_FULLSCREEN);
|
||||
|
||||
screen = SDL_SetVideoMode(screenSizes[0] -> w, screenSizes[0] -> h, 0, SDL_FULLSCREEN);
|
||||
|
||||
if (!screen) {
|
||||
fprintf(stderr, "Nem sikerult megnyitni az ablakot!\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
SDL_WM_SetCaption("Platform játék", "Schmelczer András: Platform játék");
|
||||
SDL_Cursor* cursor = createCursor();
|
||||
SDL_SetCursor(cursor);
|
||||
openFonts();
|
||||
SDL_WM_GrabInput(SDL_GRAB_FULLSCREEN);
|
||||
return cursor;
|
||||
}
|
||||
|
||||
///A játék időzítéséhez szükséges.
|
||||
Uint32 timer(Uint32 ms, void* param) {
|
||||
SDL_Event event;
|
||||
event.type = SDL_USEREVENT;
|
||||
SDL_PushEvent(&event);
|
||||
return ms;
|
||||
}
|
||||
|
||||
///Frissití az egér pozicióját.
|
||||
void setMousePosition(Uint16 x, Uint16 y) {
|
||||
mouse.x = x;
|
||||
mouse.y = y;
|
||||
}
|
||||
|
||||
///Visszaadja az egérpoziciót.
|
||||
mousePos getMousePosition() {
|
||||
return mouse;
|
||||
}
|
||||
|
||||
///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 x1 = mouse.x - mouseSize / 2;
|
||||
Sint16 x2 = mouse.x + mouseSize / 2;
|
||||
Sint16 y1 = mouse.y - mouseSize / 2;
|
||||
Sint16 y2 = mouse.y + mouseSize / 2;
|
||||
boxColor(screen, x1, y1, x2, y2, isBW ? 0x7F7F7FFF : 0xFFFF00FF);
|
||||
}
|
||||
|
||||
bool isMouseOver(int yStart, int ySize, int y) {
|
||||
|
||||
return
|
||||
(float) screen -> h / 100 * (yStart + (y - 0.5) * ySize) < mouse.y &&
|
||||
mouse.y < (float) screen -> h / 100 * (yStart + (y + 0.5) * ySize);
|
||||
}
|
||||
|
||||
///Egy téglalap felett van-e az egérmutató közepe?
|
||||
bool isMouseOverRect(int xCenter, int yCenter, int xSize, int ySize) {
|
||||
return
|
||||
screen -> w / 100.0 * (xCenter - xSize) < mouse.x && mouse.x < screen -> w / 100.0 * (xCenter + xSize) &&
|
||||
screen -> h / 100.0 * (yCenter - ySize) < mouse.y && mouse.y < screen -> h / 100.0 * (yCenter + ySize);
|
||||
}
|
||||
20
Code blocks projekt/modules/auxiliary/auxSDL.h
Normal file
20
Code blocks projekt/modules/auxiliary/auxSDL.h
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
#ifndef AUXSDL_H_INCLUDED
|
||||
#define AUXSDL_H_INCLUDED
|
||||
|
||||
#include "../global.h"
|
||||
#include "unicodePrint.h"
|
||||
|
||||
#define mouseSize 20 /**< Az egérmutató négyzetnek az oldalhosszusága. */
|
||||
|
||||
typedef struct mousePos {
|
||||
Uint16 x, y;
|
||||
} mousePos;
|
||||
|
||||
SDL_Cursor* openWindow();
|
||||
Uint32 timer(Uint32 ms, void* param);
|
||||
void setMousePosition(Uint16 x, Uint16 y);
|
||||
mousePos getMousePosition();
|
||||
void drawMouse(bool isBW);
|
||||
bool isMouseOverRect(int xCenter, int yCenter, int xSize, int ySize);
|
||||
|
||||
#endif // AUXSDL_H_INCLUDED
|
||||
21
Code blocks projekt/modules/auxiliary/auxSDL.h.save
Normal file
21
Code blocks projekt/modules/auxiliary/auxSDL.h.save
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
#ifndef AUXSDL_H_INCLUDED
|
||||
#define AUXSDL_H_INCLUDED
|
||||
|
||||
#include "../global.h"
|
||||
#include "unicodePrint.h"
|
||||
|
||||
#define mouseSize 20 /**< Az egérmutató négyzetnek az oldalhosszusága. */
|
||||
|
||||
typedef struct mousePos {
|
||||
Uint16 x, y;
|
||||
} mousePos;
|
||||
|
||||
SDL_Cursor* openWindow();
|
||||
Uint32 timer(Uint32 ms, void* param);
|
||||
void setMousePosition(Uint16 x, Uint16 y);
|
||||
mousePos getMousePosition();
|
||||
void drawMouse(bool isBW);
|
||||
bool isMouseOver(int yStart, int ySize, int y);
|
||||
bool isMouseOverRect(int xCenter, int yCenter, int xSize, int ySize);
|
||||
|
||||
#endif // AUXSDL_H_INCLUDED
|
||||
84
Code blocks projekt/modules/auxiliary/unicodePrint.c
Normal file
84
Code blocks projekt/modules/auxiliary/unicodePrint.c
Normal file
|
|
@ -0,0 +1,84 @@
|
|||
#include "unicodePrint.h"
|
||||
|
||||
|
||||
///Indításnál betölti a szükséges betűtípusokat.
|
||||
void openFonts() {
|
||||
SDL_EnableUNICODE(1);
|
||||
TTF_Init();
|
||||
fontSmaller = TTF_OpenFont("resources/Roboto-Thin.ttf", 40);
|
||||
fontSmall = TTF_OpenFont("resources/Roboto-Thin.ttf", 48);
|
||||
fontSmallBold = TTF_OpenFont("resources/Roboto-Light.ttf", 53);
|
||||
fontLarge = TTF_OpenFont("resources/Roboto-Thin.ttf", 120);
|
||||
}
|
||||
|
||||
///Ha már nem kellenek, felszabadítja a betűtípusokat.
|
||||
void freeFonts() {
|
||||
TTF_CloseFont(fontSmaller);
|
||||
TTF_CloseFont(fontSmall);
|
||||
TTF_CloseFont(fontSmallBold);
|
||||
TTF_CloseFont(fontLarge);
|
||||
}
|
||||
|
||||
///Itt tárolom a használható karaktereket. Eldönti, hogy a bemenet köztük van-e.
|
||||
bool isValidChar(Uint16 chr) {
|
||||
if(('A' <= chr && chr <= 'Z') || ('a' <= chr && chr <= 'z') || ('0' <= chr && chr <= '9')) return true;
|
||||
|
||||
Uint16 validChars[] = L"öüóőúéáűíÖÜÓŐÚÉÁŰÍ|€ß$Łł¤<>#&@{}Đ[]đ+!%=×)(.- ";
|
||||
int i;
|
||||
for(i = 0; validChars[i] != 0; i++) if(chr == validChars[i])
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
///Az egyszerűbb kezelhetőség miatt kell. Visszadja az enumhoz tartozó ttf-et.
|
||||
TTF_Font* selectFont(fontType fontType) {
|
||||
switch(fontType) {
|
||||
case tiny:
|
||||
return fontSmaller;
|
||||
case small:
|
||||
return fontSmall;
|
||||
case smallBold:
|
||||
return fontSmallBold;
|
||||
case large:
|
||||
default:
|
||||
return fontLarge;
|
||||
}
|
||||
}
|
||||
|
||||
///A százalékot a képernyő mérete alapján átváltja pixelekre.
|
||||
Sint16 percentageToPx(int percentage, bool isWidth) {
|
||||
return (int)((float)percentage/100 * (isWidth ? screen -> w: screen -> h));
|
||||
}
|
||||
|
||||
/** \brief Uint16-ból álló stringet összefűz.
|
||||
* A két paramétert egy harmadik dinamikusan foglalt stringben fűzi össze.
|
||||
* \param string eleje
|
||||
* \param string vége
|
||||
* \return string konkatenált
|
||||
*/
|
||||
Uint16* concatUnicode(const Uint16 a[], const Uint16 b[]) {
|
||||
int aLength, bLength;
|
||||
for(aLength = 0; a[aLength] != 0; aLength++)
|
||||
;
|
||||
for(bLength = 0; b[bLength] != 0; bLength++)
|
||||
;
|
||||
|
||||
Uint16* newStr = (Uint16*) malloc((aLength + bLength - 1 + 100) * sizeof(Uint16));
|
||||
int i = 0, ai, bi;
|
||||
for(ai = 0; ai < aLength; ai++)
|
||||
newStr[i++] = a[ai];
|
||||
for(bi = 0; bi < bLength; bi++)
|
||||
newStr[i++] = b[bi];
|
||||
newStr[i] = 0;
|
||||
|
||||
return newStr;
|
||||
}
|
||||
|
||||
///A megjelenítendő szöveg közepét kell megadni x,y-ként. A szöveget Uint16*-ban, a betűtipust pedig a betűtipus enumból. Ugyan mindent x = 50-nel hívunk meg, ez később változhat, ezért hagyom meg paraméternek.
|
||||
void unicodePrintCentered(Uint16 textToWrite[], int x, int y, fontType fontType) {
|
||||
TTF_Font* currentFont = selectFont(fontType);
|
||||
SDL_FreeSurface(text);
|
||||
text = TTF_RenderUNICODE_Blended(currentFont, textToWrite, (SDL_Color) {255, 255, 255});
|
||||
SDL_BlitSurface(text, NULL, screen, &(SDL_Rect){percentageToPx(x, true) - text -> w / 2, percentageToPx(y, false) - text -> h / 2, 0, 0});
|
||||
}
|
||||
84
Code blocks projekt/modules/auxiliary/unicodePrint.c.save
Normal file
84
Code blocks projekt/modules/auxiliary/unicodePrint.c.save
Normal file
|
|
@ -0,0 +1,84 @@
|
|||
#include "unicodePrint.h"
|
||||
|
||||
|
||||
///Indításnál betölti a szükséges betűtípusokat.
|
||||
void openFonts() {
|
||||
SDL_EnableUNICODE(1);
|
||||
TTF_Init();
|
||||
fontSmaller = TTF_OpenFont("resources/Roboto-Thin.ttf", 40);
|
||||
fontSmall = TTF_OpenFont("resources/Roboto-Thin.ttf", 48);
|
||||
fontSmallBold = TTF_OpenFont("resources/Roboto-Light.ttf", 53);
|
||||
fontLarge = TTF_OpenFont("resources/Roboto-Thin.ttf", 120);
|
||||
}
|
||||
|
||||
///Ha már nem kellenek, felszabadítja a betűtípusokat.
|
||||
void freeFonts() {
|
||||
TTF_CloseFont(fontSmaller);
|
||||
TTF_CloseFont(fontSmall);
|
||||
TTF_CloseFont(fontSmallBold);
|
||||
TTF_CloseFont(fontLarge);
|
||||
}
|
||||
|
||||
///Itt tárolom a használható karaktereket. Eldönti, hogy a bemenet köztük van-e.
|
||||
bool isValidChar(Uint16 chr) {
|
||||
if(('A' <= chr && chr <= 'Z') || ('a' <= chr && chr <= 'z') || ('0' <= chr && chr <= '9')) return true;
|
||||
|
||||
Uint16 validChars[] = L"öüóőúéáűíÖÜÓŐÚÉÁŰÍ|€ß$Łł¤<>#&@{}Đ[]đ+!%=×)(.- ";
|
||||
int i;
|
||||
for(i = 0; validChars[i] != 0; i++) if(chr == validChars[i])
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
///Az egyszerűbb kezelhetőség miatt kell. Visszadja az enumhoz tartozó ttf-et.
|
||||
TTF_Font* selectFont(fontType fontType) {
|
||||
switch(fontType) {
|
||||
case tiny:
|
||||
return fontSmaller;
|
||||
case small:
|
||||
return fontSmall;
|
||||
case smallBold:
|
||||
return fontSmallBold;
|
||||
case large:
|
||||
default:
|
||||
return fontLarge;
|
||||
}
|
||||
}
|
||||
|
||||
///A százalékot a képernyő mérete alapján átváltja pixelekre.
|
||||
Sint16 percentageToPx(int percentage, bool isWidth) {
|
||||
return (int)((float)percentage/100 * (isWidth ? screen -> w: screen -> h));
|
||||
}
|
||||
|
||||
/** \brief Uint16-ból álló stringet összefűz.
|
||||
* A két paramétert egy harmadik dinamikusan foglalt stringben fűzi össze.
|
||||
* \param string eleje
|
||||
* \param string vége
|
||||
* \return string konkatenált
|
||||
*/
|
||||
Uint16* concatUnicode(const Uint16 a[], const Uint16 b[]) {
|
||||
int aLength, bLength;
|
||||
for(aLength = 0; a[aLength] != 0; aLength++)
|
||||
;
|
||||
for(bLength = 0; b[bLength] != 0; bLength++)
|
||||
;
|
||||
|
||||
Uint16* newStr = (Uint16*) malloc((aLength + bLength - 1 + 100) * sizeof(Uint16));
|
||||
int i = 0, ai, bi;
|
||||
for(ai = 0; ai < aLength; ai++)
|
||||
newStr[i++] = a[ai];
|
||||
for(bi = 0; bi < bLength; bi++)
|
||||
newStr[i++] = b[bi];
|
||||
newStr[i] = 0;
|
||||
|
||||
return newStr;
|
||||
}
|
||||
|
||||
///A megjelenítendő szöveg közepét kell megadni x,y-ként. A szöveget Uint16*-ban, a betűtipust pedig a betűtipus enumból. Ugyan mindent x = 50-nel hívunk meg, ez később változhat, ezért hagyom meg paraméternek.
|
||||
void unicodePrintCentered(Uint16 textToWrite[], int x, int y, fontType fontType) {
|
||||
TTF_Font* currentFont = selectFont(fontType);
|
||||
SDL_FreeSurface(text);
|
||||
text = TTF_RenderUNICODE_Blended(currentFont, textToWrite, (SDL_Color) {255, 255, 255});
|
||||
SDL_BlitSurface(text, NULL, screen, &(SDL_Rect){percentageToPx(x, true) - text -> w / 2, percentageToPx(y, false) - text -> h / 2, 0, 0});
|
||||
}
|
||||
16
Code blocks projekt/modules/auxiliary/unicodePrint.h
Normal file
16
Code blocks projekt/modules/auxiliary/unicodePrint.h
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
#ifndef UNICODEPRINT_H_INCLUDED
|
||||
#define UNICODEPRINT_H_INCLUDED
|
||||
|
||||
#include "../global.h"
|
||||
|
||||
typedef enum fontType {
|
||||
tiny, small, smallBold, large
|
||||
} fontType;
|
||||
|
||||
void openFonts();
|
||||
void freeFonts();
|
||||
bool isValidChar(Uint16 chr);
|
||||
Uint16* concatUnicode(const Uint16 a[], const Uint16 b[]);
|
||||
void unicodePrintCentered(Uint16 textToWrite[], int x, int y, fontType fontType);
|
||||
|
||||
#endif // UNICODEPRINT_H_INCLUDED
|
||||
16
Code blocks projekt/modules/auxiliary/unicodePrint.h.save
Normal file
16
Code blocks projekt/modules/auxiliary/unicodePrint.h.save
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
#ifndef UNICODEPRINT_H_INCLUDED
|
||||
#define UNICODEPRINT_H_INCLUDED
|
||||
|
||||
#include "../global.h"
|
||||
|
||||
typedef enum fontType {
|
||||
tiny, small, smallBold, large
|
||||
} fontType;
|
||||
|
||||
void openFonts();
|
||||
void freeFonts();
|
||||
bool isValidChar(Uint16 chr);
|
||||
Uint16* concatUnicode(const Uint16 a[], const Uint16 b[]);
|
||||
void unicodePrintCentered(Uint16 textToWrite[], int x, int y, fontType fontType);
|
||||
|
||||
#endif // UNICODEPRINT_H_INCLUDED
|
||||
Loading…
Reference in a new issue