-
Notifications
You must be signed in to change notification settings - Fork 0
/
number.cpp
51 lines (42 loc) · 1.31 KB
/
number.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <SDL_ttf.h>
#include "number.h"
#include "check and init.h"
RightBackGround::RightBackGround(SDL_Renderer* ren_):renderer(ren_)
{
}
int RightBackGround::createRightBackGround(const int& posiY,const int& heightNumber,const int& number)
{
// init ttf
if (TTF_Init() < 0)
{
logError(std::cout,"TTF_Init Error: ",TTF_GetError(),false);
return -1;
}
// check font
if (TTF_OpenFont(fontnumber.c_str(), sizeFont) == nullptr)
{
logError(std::cout,"TTF_Init Error: ",TTF_GetError(),false);
return -1;
}
// number to string
std::string s = genericToString(number);
// load font
TTF_Font* font = TTF_OpenFont(fontnumber.c_str(), sizeFont);
// ttf
SDL_Surface* surFace = TTF_RenderText_Solid(font, s.c_str(), Color);
SDL_Texture* texTure = SDL_CreateTextureFromSurface(renderer, surFace);
SDL_FreeSurface(surFace);
SDL_RenderCopy(renderer, texTure, NULL,new SDL_Rect{ posiX, posiY, lengthRight, heightNumber });
// destroy
TTF_CloseFont(font);
font = NULL;
SDL_DestroyTexture(texTure);
TTF_Quit();
return 1;
}
std::string RightBackGround::genericToString(const int& number)
{
std::ostringstream stringNumber;
stringNumber << number;
return stringNumber.str();
}