Zadanie 2 - fix text, change bindings
This commit is contained in:
parent
d2556a6579
commit
03c5051212
@ -60,4 +60,38 @@ namespace KapitanGame
|
|||||||
}
|
}
|
||||||
return texture;
|
return texture;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
KTexture KFont::GetTextWithOutlineTexture(const std::string& text, const SDL_Color fgColor, const SDL_Color bgColor,
|
||||||
|
const int outlineSize, SDL_Renderer* renderer) const
|
||||||
|
{
|
||||||
|
KTexture texture;
|
||||||
|
const int originalOutlineSize = TTF_GetFontOutline(Font);
|
||||||
|
|
||||||
|
if (SDL_Surface* fgSurface = TTF_RenderText_Blended(Font, text.c_str(), fgColor); fgSurface == nullptr)
|
||||||
|
{
|
||||||
|
printf("Unable to render text surface! SDL_ttf Error: %s\n", TTF_GetError());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
TTF_SetFontOutline(Font, outlineSize);
|
||||||
|
SDL_Surface* bgSurface = TTF_RenderText_Blended(Font, text.c_str(), bgColor);
|
||||||
|
TTF_SetFontOutline(Font, originalOutlineSize);
|
||||||
|
if (bgSurface == nullptr)
|
||||||
|
{
|
||||||
|
printf("Unable to render text surface! SDL_ttf Error: %s\n", TTF_GetError());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
SDL_Rect rect = { outlineSize, outlineSize, fgSurface->w, fgSurface->h };
|
||||||
|
|
||||||
|
/* blit text onto its outline */
|
||||||
|
SDL_SetSurfaceBlendMode(fgSurface, SDL_BLENDMODE_BLEND);
|
||||||
|
SDL_BlitSurface(fgSurface, nullptr, bgSurface, &rect);
|
||||||
|
texture.LoadFromSurface(bgSurface, renderer);
|
||||||
|
SDL_FreeSurface(bgSurface);
|
||||||
|
}
|
||||||
|
SDL_FreeSurface(fgSurface);
|
||||||
|
}
|
||||||
|
return texture;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,6 +26,7 @@ namespace KapitanGame {
|
|||||||
void Free();
|
void Free();
|
||||||
|
|
||||||
KTexture GetTextTexture(const std::string& text, SDL_Color textColor, SDL_Renderer* renderer) const;
|
KTexture GetTextTexture(const std::string& text, SDL_Color textColor, SDL_Renderer* renderer) const;
|
||||||
|
KTexture GetTextWithOutlineTexture(const std::string& text, SDL_Color fgColor, SDL_Color bgColor, int outlineSize, SDL_Renderer* renderer) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
//The actual hardware font
|
//The actual hardware font
|
||||||
|
@ -89,7 +89,7 @@ namespace KapitanGame {
|
|||||||
pc->UnPossess();
|
pc->UnPossess();
|
||||||
}
|
}
|
||||||
Textures.erase("Text_Score");
|
Textures.erase("Text_Score");
|
||||||
Textures.emplace("Text_Score", Fonts["Roboto-Thin"].GetTextTexture(Utils::StringFormat("%d:%d", Scores[0], Scores[1]), { 0,0,0,0xFF }, Renderer));
|
Textures.emplace("Text_Score", Fonts["Roboto-Thin"].GetTextWithOutlineTexture(Utils::StringFormat("%d:%d", Scores[0], Scores[1]), { 0xFF,0xFF,0xFF,0xFF }, { 0,0,0,0xFF }, 1, Renderer));
|
||||||
if (++LvlCounter > 3)
|
if (++LvlCounter > 3)
|
||||||
{
|
{
|
||||||
int max = Scores[0];
|
int max = Scores[0];
|
||||||
@ -236,7 +236,7 @@ namespace KapitanGame {
|
|||||||
Fonts.erase("Roboto-Thin");
|
Fonts.erase("Roboto-Thin");
|
||||||
success = false;
|
success = false;
|
||||||
}
|
}
|
||||||
Textures.emplace("Text_Score", Fonts["Roboto-Thin"].GetTextTexture("0:0", { 0,0,0,0xFF }, Renderer));
|
Textures.emplace("Text_Score", Fonts["Roboto-Thin"].GetTextWithOutlineTexture("0:0", { 0xFF,0xFF,0xFF,0xFF }, { 0,0,0,0xFF }, 1, Renderer));
|
||||||
Textures.emplace("Text_Winner", KTexture());
|
Textures.emplace("Text_Winner", KTexture());
|
||||||
|
|
||||||
std::ifstream configFile("config.json");
|
std::ifstream configFile("config.json");
|
||||||
@ -364,7 +364,7 @@ namespace KapitanGame {
|
|||||||
Scores[static_cast<int>(i)] = 0;
|
Scores[static_cast<int>(i)] = 0;
|
||||||
}
|
}
|
||||||
Textures.erase("Text_Score");
|
Textures.erase("Text_Score");
|
||||||
Textures.emplace("Text_Score", Fonts["Roboto-Thin"].GetTextTexture(Utils::StringFormat("%d:%d", Scores[0], Scores[1]), { 0,0,0,0xFF }, Renderer));
|
Textures.emplace("Text_Score", Fonts["Roboto-Thin"].GetTextWithOutlineTexture(Utils::StringFormat("%d:%d", Scores[0], Scores[1]), { 0xFF,0xFF,0xFF,0xFF }, { 0,0,0,0xFF }, 1, Renderer));
|
||||||
ShowWinner = false;
|
ShowWinner = false;
|
||||||
}
|
}
|
||||||
Playing = true;
|
Playing = true;
|
||||||
|
@ -40,22 +40,22 @@
|
|||||||
{
|
{
|
||||||
"AxisName": "MoveY",
|
"AxisName": "MoveY",
|
||||||
"Scale": -1.000000,
|
"Scale": -1.000000,
|
||||||
"Key": "I"
|
"Key": "Up"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"AxisName": "MoveY",
|
"AxisName": "MoveY",
|
||||||
"Scale": 1.000000,
|
"Scale": 1.000000,
|
||||||
"Key": "K"
|
"Key": "Down"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"AxisName": "MoveX",
|
"AxisName": "MoveX",
|
||||||
"Scale": -1.000000,
|
"Scale": -1.000000,
|
||||||
"Key": "J"
|
"Key": "Left"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"AxisName": "MoveX",
|
"AxisName": "MoveX",
|
||||||
"Scale": 1.000000,
|
"Scale": 1.000000,
|
||||||
"Key": "L"
|
"Key": "Right"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"AxisName": "MoveY",
|
"AxisName": "MoveY",
|
||||||
|
Loading…
Reference in New Issue
Block a user