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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
#include "menu.h"
namespace menu
{
std::vector<musicfile> songs;
SDL_Texture *background;
int init_menu()
{
SDL_Texture *image;
songs = loadSongs();
screen.state = STATE_MENU;
}
int update_menu()
{
int height = 0;
for(std::vector<musicfile>::iterator songData = songs.begin(); songData != songs.end(); ++songData) {
std::string path = songData->path + songData->background;
background = loadTexture(path, screen.renderer);
path = songData->path + songData->banner;
image = loadTexture(path, screen.renderer);
path = songData->path + songData->file;
if (background == nullptr || image == nullptr)
continue;
SDL_RenderClear(screen.renderer);
SDL_Color color={255,0,0};
SDL_Surface *text = TTF_RenderText_Blended(screen.font, path.c_str(), color);
SDL_Texture* texture = SDL_CreateTextureFromSurface(screen.renderer, text);
renderTexture(texture, screen.renderer, 0.5f, 0.5f);
int w, h;
float bW, bH;
SDL_QueryTexture(background, NULL, NULL, &w, &h);
bW = (float)w / (float)screen.width;
bH = (float)h / (float)screen.height;
float iW, iH;
SDL_QueryTexture(image, NULL, NULL, &w, &h);
//iW = 0.5f - ( / ( ) /2;
//iH = 0.5f - ( (float)h / (float)screen.height ) /2;
iW = (float)screen.width - (float)w;
iH = height;
renderTexture(background, renderer, bW, bH);
renderTexture(image, renderer, iW, iH);
SDL_RenderPresent(screen.renderer);
height += height + 0.02f;
}
}
};
|