Skip to content

Commit

Permalink
Use Tabs for identation + fix wrongfull whitespaces
Browse files Browse the repository at this point in the history
  • Loading branch information
joyrider3774 committed May 10, 2023
1 parent b75f77e commit 9bbcc57
Show file tree
Hide file tree
Showing 42 changed files with 5,621 additions and 5,564 deletions.
356 changes: 178 additions & 178 deletions src/CAudio.cpp

Large diffs are not rendered by default.

66 changes: 33 additions & 33 deletions src/CAudio.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,39 +14,39 @@ constexpr int MUS_Max = 20;
class CAudio {

private:
bool DebugInfo;
int VolumeMusic, VolumeSound;
Mix_Chunk *Sounds[SND_Max];
Mix_Music *Music[MUS_Max];
string DataPath;
bool DebugInfo;
int VolumeMusic, VolumeSound;
Mix_Chunk *Sounds[SND_Max];
Mix_Music *Music[MUS_Max];
string DataPath;

public:
bool GlobalSoundEnabled = true;
CAudio(string AssetsPath, bool ADebugInfo);
~CAudio();
void IncVolumeMusic();
void DecVolumeMusic();
void SetVolumeMusic(const int VolumeIn);
int GetVolumeMusic();

void IncVolumeSound();
void DecVolumeSound();
void SetVolumeSound(const int VolumeIn);
int GetVolumeSound();

int LoadMusic(string FileName);
int LoadSound(string FileName);
int MusicSlotsUsed();
int MusicSlotsMax();
int SoundSlotsUsed();
int SoundSlotsMax();
void UnLoadMusic(int MusicdID);
void UnLoadSound(int SoundID);
void UnloadSounds();
void UnloadMusics();
void PlayMusic(int MusicID, int loops);
void PlaySound(int SoundID, int loops);
bool IsMusicPlaying();
void StopMusic();
void StopSound();
bool GlobalSoundEnabled = true;
CAudio(string AssetsPath, bool ADebugInfo);
~CAudio();
void IncVolumeMusic();
void DecVolumeMusic();
void SetVolumeMusic(const int VolumeIn);
int GetVolumeMusic();

void IncVolumeSound();
void DecVolumeSound();
void SetVolumeSound(const int VolumeIn);
int GetVolumeSound();

int LoadMusic(string FileName);
int LoadSound(string FileName);
int MusicSlotsUsed();
int MusicSlotsMax();
int SoundSlotsUsed();
int SoundSlotsMax();
void UnLoadMusic(int MusicdID);
void UnLoadSound(int SoundID);
void UnloadSounds();
void UnloadMusics();
void PlayMusic(int MusicID, int loops);
void PlaySound(int SoundID, int loops);
bool IsMusicPlaying();
void StopMusic();
void StopSound();
};
268 changes: 134 additions & 134 deletions src/CFont.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,159 +10,159 @@ using namespace std;

CFont::CFont(string AssetsPath, bool DebugInfo)
{
DataPath = AssetsPath;
DebugInfo = DebugInfo;
GlobalFontEnabled = (TTF_Init() == 0);
if (GlobalFontEnabled)
SDL_Log("Succesfully initialized TTF\n");
else
SDL_Log("Failed initializing SDL_ttf %s\n", SDL_GetError());
DataPath = AssetsPath;
DebugInfo = DebugInfo;
GlobalFontEnabled = (TTF_Init() == 0);
if (GlobalFontEnabled)
SDL_Log("Succesfully initialized TTF\n");
else
SDL_Log("Failed initializing SDL_ttf %s\n", SDL_GetError());
}

CFont::~CFont()
{
if(GlobalFontEnabled)
{
map<std::string, TTF_Font*>::iterator i;
for (i = FontCache.begin(); i != FontCache.end(); i++)
TTF_CloseFont(i->second);
TTF_Quit();
}
if(GlobalFontEnabled)
{
map<std::string, TTF_Font*>::iterator i;
for (i = FontCache.begin(); i != FontCache.end(); i++)
TTF_CloseFont(i->second);
TTF_Quit();
}
}

int CFont::TextWidth(string Font, int FontSize, string Tekst, size_t NrOfChars)
{
SDL_Point Tmp = TextSize(Font, FontSize, Tekst, NrOfChars, 0);
return Tmp.x;
SDL_Point Tmp = TextSize(Font, FontSize, Tekst, NrOfChars, 0);
return Tmp.x;
}

SDL_Point CFont::TextSize(string Font, int FontSize, string Tekst, size_t NrOfChars, int YSpacing)
{
SDL_Point Result = {0,0};
if(!GlobalFontEnabled || (NrOfChars == 0))
return Result;
SDL_Point Result = {0,0};
if(!GlobalFontEnabled || (NrOfChars == 0))
return Result;

TTF_Font *FontIn;
map<std::string, TTF_Font*>::iterator i;
string FontNameSize = string(Font) + to_string(FontSize);
i = FontCache.find(FontNameSize);
if (i != FontCache.end())
FontIn = i->second;
else
{
string Filename = DataPath + "fonts/" + Font + ".ttf";
FontIn = TTF_OpenFont(Filename.c_str(), FontSize);
if (!FontIn)
{
SDL_Log("Failed Loading Font %s %d\n", SDL_GetError(), FontSize);
return Result;
}
if(DebugInfo)
SDL_Log("Loaded Font %s %d\n", Filename.c_str(), FontSize);
TTF_SetFontStyle(FontIn, TTF_STYLE_NORMAL);
TTF_Font *FontIn;
map<std::string, TTF_Font*>::iterator i;
string FontNameSize = string(Font) + to_string(FontSize);
i = FontCache.find(FontNameSize);
if (i != FontCache.end())
FontIn = i->second;
else
{
string Filename = DataPath + "fonts/" + Font + ".ttf";
FontIn = TTF_OpenFont(Filename.c_str(), FontSize);
if (!FontIn)
{
SDL_Log("Failed Loading Font %s %d\n", SDL_GetError(), FontSize);
return Result;
}
if(DebugInfo)
SDL_Log("Loaded Font %s %d\n", Filename.c_str(), FontSize);
TTF_SetFontStyle(FontIn, TTF_STYLE_NORMAL);

FontCache[FontNameSize] = FontIn;
}
FontCache[FontNameSize] = FontIn;
}

char List[100][255];
size_t Lines, Teller, Chars;
Lines = 0;
Chars = 0;
for (Teller = 0; Teller < NrOfChars; Teller++)
{
if (Lines > 100)
break;
if ((Tekst[Teller] == '\n') || (Chars == 255))
{
List[Lines][Chars] = '\0';
Lines++;
Chars = 0;
}
else
{
List[Lines][Chars] = Tekst[Teller];
Chars++;
}
}
List[Lines][Chars] = '\0';
int w,h;
Result.y = (Lines)*TTF_FontLineSkip(FontIn) + (Lines * YSpacing);
for (Teller = 0; Teller <= Lines; Teller++)
{
TTF_SizeText(FontIn, List[Teller], &w, &h);
if (w > Result.x)
Result.x = w;
}
return Result;
char List[100][255];
size_t Lines, Teller, Chars;
Lines = 0;
Chars = 0;
for (Teller = 0; Teller < NrOfChars; Teller++)
{
if (Lines > 100)
break;
if ((Tekst[Teller] == '\n') || (Chars == 255))
{
List[Lines][Chars] = '\0';
Lines++;
Chars = 0;
}
else
{
List[Lines][Chars] = Tekst[Teller];
Chars++;
}
}
List[Lines][Chars] = '\0';
int w,h;
Result.y = (Lines)*TTF_FontLineSkip(FontIn) + (Lines * YSpacing);
for (Teller = 0; Teller <= Lines; Teller++)
{
TTF_SizeText(FontIn, List[Teller], &w, &h);
if (w > Result.x)
Result.x = w;
}
return Result;
}

void CFont::WriteText(SDL_Renderer *Renderer, string Font, int FontSize, string Tekst, size_t NrOfChars, int X, int Y, int YSpacing, SDL_Color ColorIn)
void CFont::WriteText(SDL_Renderer *Renderer, string Font, int FontSize, string Tekst, size_t NrOfChars, int X, int Y, int YSpacing, SDL_Color ColorIn)
{
if(!GlobalFontEnabled || (NrOfChars == 0))
return;
TTF_Font *FontIn;
map<std::string, TTF_Font*>::iterator i;
string FontNameSize = string(Font) + to_string(FontSize);
i = FontCache.find(FontNameSize);
if (i != FontCache.end())
FontIn = i->second;
else
{
string Filename = DataPath + "fonts/" + Font + ".ttf";
FontIn = TTF_OpenFont(Filename.c_str(), FontSize);
if (!FontIn)
{
SDL_Log("Failed Loading Font %s %d\n", Filename.c_str(), FontSize);
return;
}
if(DebugInfo)
SDL_Log("Loaded Font %s %d\n", Filename.c_str(), FontSize);
TTF_SetFontStyle(FontIn, TTF_STYLE_NORMAL);
if(!GlobalFontEnabled || (NrOfChars == 0))
return;
TTF_Font *FontIn;
map<std::string, TTF_Font*>::iterator i;
string FontNameSize = string(Font) + to_string(FontSize);
i = FontCache.find(FontNameSize);
if (i != FontCache.end())
FontIn = i->second;
else
{
string Filename = DataPath + "fonts/" + Font + ".ttf";
FontIn = TTF_OpenFont(Filename.c_str(), FontSize);
if (!FontIn)
{
SDL_Log("Failed Loading Font %s %d\n", Filename.c_str(), FontSize);
return;
}
if(DebugInfo)
SDL_Log("Loaded Font %s %d\n", Filename.c_str(), FontSize);
TTF_SetFontStyle(FontIn, TTF_STYLE_NORMAL);

FontCache[FontNameSize] = FontIn;
}
FontCache[FontNameSize] = FontIn;
}

char List[100][255];
size_t Lines, Teller, Chars;
SDL_Rect DstRect;
SDL_Surface *TextureBuffer1Surface1;
SDL_Texture *TextureBuffer1Texture;
Lines = 0;
Chars = 0;
for (Teller = 0; Teller < NrOfChars; Teller++)
{
if (Lines > 100)
break;
if ((Tekst[Teller] == '\n') || (Chars == 255))
{
List[Lines][Chars] = '\0';
Lines++;
Chars = 0;
}
else
{
List[Lines][Chars] = Tekst[Teller];
Chars++;
}
}
List[Lines][Chars] = '\0';
for (Teller = 0; Teller <= Lines; Teller++)
{
if (strlen(List[Teller]) > 0)
{
TextureBuffer1Surface1 = TTF_RenderText_Blended(FontIn, List[Teller], ColorIn);
if (TextureBuffer1Surface1)
{
TextureBuffer1Texture = SDL_CreateTextureFromSurface(Renderer, TextureBuffer1Surface1);
DstRect.x = X;
DstRect.y = Y + (Teller)*TTF_FontLineSkip(FontIn) + (Teller * YSpacing);
DstRect.w = TextureBuffer1Surface1->w;
DstRect.h = TextureBuffer1Surface1->h;
char List[100][255];
size_t Lines, Teller, Chars;
SDL_Rect DstRect;
SDL_Surface *TextureBuffer1Surface1;
SDL_Texture *TextureBuffer1Texture;
Lines = 0;
Chars = 0;
for (Teller = 0; Teller < NrOfChars; Teller++)
{
if (Lines > 100)
break;
if ((Tekst[Teller] == '\n') || (Chars == 255))
{
List[Lines][Chars] = '\0';
Lines++;
Chars = 0;
}
else
{
List[Lines][Chars] = Tekst[Teller];
Chars++;
}
}
List[Lines][Chars] = '\0';
for (Teller = 0; Teller <= Lines; Teller++)
{
if (strlen(List[Teller]) > 0)
{
TextureBuffer1Surface1 = TTF_RenderText_Blended(FontIn, List[Teller], ColorIn);
if (TextureBuffer1Surface1)
{
TextureBuffer1Texture = SDL_CreateTextureFromSurface(Renderer, TextureBuffer1Surface1);
DstRect.x = X;
DstRect.y = Y + (Teller)*TTF_FontLineSkip(FontIn) + (Teller * YSpacing);
DstRect.w = TextureBuffer1Surface1->w;
DstRect.h = TextureBuffer1Surface1->h;

SDL_RenderCopy(Renderer, TextureBuffer1Texture, NULL, &DstRect);
SDL_DestroyTexture(TextureBuffer1Texture);
SDL_FreeSurface(TextureBuffer1Surface1);
}
}
}
SDL_RenderCopy(Renderer, TextureBuffer1Texture, NULL, &DstRect);
SDL_DestroyTexture(TextureBuffer1Texture);
SDL_FreeSurface(TextureBuffer1Surface1);
}
}
}
}
18 changes: 9 additions & 9 deletions src/CFont.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ using namespace std;
class CFont {

private:
string DataPath;
bool DebugInfo;
bool GlobalFontEnabled = true;
map<string, TTF_Font*> FontCache;
string DataPath;
bool DebugInfo;
bool GlobalFontEnabled = true;
map<string, TTF_Font*> FontCache;
public:
CFont(string AssetsPath, bool DebugInfo);
~CFont();
int TextWidth(string Font, int FontSize, string Tekst, size_t NrOfChars);
SDL_Point TextSize(string Font, int FontSize, string Tekst, size_t NrOfChars, int YSpacing);
void WriteText(SDL_Renderer *Renderer, string Font, int FontSize, string Tekst, size_t NrOfChars, int X, int Y, int YSpacing, SDL_Color ColorIn);
CFont(string AssetsPath, bool DebugInfo);
~CFont();
int TextWidth(string Font, int FontSize, string Tekst, size_t NrOfChars);
SDL_Point TextSize(string Font, int FontSize, string Tekst, size_t NrOfChars, int YSpacing);
void WriteText(SDL_Renderer *Renderer, string Font, int FontSize, string Tekst, size_t NrOfChars, int X, int Y, int YSpacing, SDL_Color ColorIn);
};
Loading

0 comments on commit 9bbcc57

Please sign in to comment.