Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <SDL/SDL.h>
- #include <SDL/SDL_image.h>
- #include <SDL/SDL_Resize.h>
- #include <SDL/SDL_ttf.h>
- #include <string>
- #include <vector>
- using std::string;
- using std::vector;
- SDL_Surface* LoadImage(string);
- void ApplySurface(int, int, SDL_Surface*, SDL_Surface*);
- void Menu();
- char* GetOption(int);
- const int ScreenWidth = 1000;
- const int ScreenHeight = 800;
- const int ScreenBPP = 32;
- int State = 0;
- SDL_Surface *Screen = NULL;
- int main(int argc, char *argv[])
- {
- if(SDL_Init(SDL_INIT_EVERYTHING) == -1)
- return -1;
- else if(TTF_Init() == -1)
- return -1;
- Screen = SDL_SetVideoMode(ScreenWidth, ScreenHeight, ScreenBPP, SDL_SWSURFACE);
- if(Screen == NULL)
- return -1;
- while(true)
- {
- switch(State)
- {
- case 0:
- Menu();
- break;
- }
- }
- }
- SDL_Surface* LoadImage(string Image)
- {
- SDL_Surface* LoadedImage = NULL;
- SDL_Surface* OptimizedImage = NULL;
- LoadedImage = IMG_Load(Image.c_str());
- if(LoadedImage != NULL)
- {
- OptimizedImage = SDL_DisplayFormat(LoadedImage);
- SDL_FreeSurface(LoadedImage);
- }
- return OptimizedImage;
- }
- void ApplySurface(int XCoor, int YCoor, SDL_Surface *Source, SDL_Surface *Destination)
- {
- SDL_Rect Offset;
- Offset.x = XCoor;
- Offset.y = YCoor;
- SDL_BlitSurface(Source, NULL, Destination, &Offset);
- }
- void Menu()
- {
- bool Running = true;
- int Displace = 0, Counter;
- const int OptionCount = 4;
- SDL_Event Event;
- TTF_Font *Font = NULL;
- SDL_Color TextColor = {192, 192, 192};
- SDL_Surface *Background = NULL;
- vector<SDL_Surface*> Button(OptionCount);
- vector<SDL_Surface*> Message(OptionCount);
- SDL_WM_SetCaption("Mirrors of Elixia :: Menu", NULL);
- Font = TTF_OpenFont("DragonFont.ttf", 28);
- Background = LoadImage("background.jpg");
- Background = SDL_Resize(Background, ScreenWidth, ScreenHeight, false, 3);
- ApplySurface(0, 0, Background, Screen);
- for(Counter = 0; Counter < Button.size(); Counter++)
- {
- Message[Counter] = NULL;
- Message[Counter] = TTF_RenderText_Solid(Font, GetOption(Counter), TextColor);
- Button[Counter] = NULL;
- Button[Counter] = LoadImage("button.jpg");
- Button[Counter] = SDL_Resize(Button[Counter], Button[Counter]->w / 2, Button[Counter]->h / 2, false, 3);
- ApplySurface(ScreenWidth - Button[Counter]->w - 10, 15 + Displace, Button[Counter], Screen);
- ApplySurface(ScreenWidth - Button[Counter]->w + 40, 45 + Displace, Message[Counter], Screen);
- Displace += Button[Counter]->h + 20;
- }
- if(SDL_Flip(Screen) == -1)
- return;
- while(Running)
- {
- while(SDL_PollEvent(&Event))
- {
- if(Event.type == SDL_QUIT)
- Running = false;
- }
- }
- SDL_FreeSurface(Background);
- SDL_FreeSurface(Screen);
- SDL_Quit();
- return;
- }
- char* GetOption(int Code)
- {
- switch(Code)
- {
- case 0:
- return "New Game";
- break;
- case 1:
- return "Saved Game";
- break;
- case 2:
- return "Settings";
- break;
- case 3:
- return "Exit";
- break;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement