From 823a82611d37e618a4734ea480fab4c60b73f5b7 Mon Sep 17 00:00:00 2001 From: piernov Date: Thu, 18 Aug 2016 14:13:40 +0200 Subject: Initial Import --- menu.cpp | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100755 menu.cpp (limited to 'menu.cpp') diff --git a/menu.cpp b/menu.cpp new file mode 100755 index 0000000..d87bbdd --- /dev/null +++ b/menu.cpp @@ -0,0 +1,65 @@ +#include "menu.h" + +namespace menu +{ + std::vector 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::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; + } + +} + + +}; -- cgit v1.2.3-54-g00ecf