diff --git a/SConstruct b/SConstruct index 41199a2..ab890b3 100644 --- a/SConstruct +++ b/SConstruct @@ -7,6 +7,6 @@ env = Environment(ENV = { 'TERM' : environ['TERM'] }, CPPPATH = 'src', CXXFLAGS = flags, LINKFLAGS = flags, - LIBS = ['SDL2', 'SDL2_ttf']) + LIBS = ['SDL2', 'SDL2_image', 'SDL2_ttf']) env.Program('laines', Glob('src/*.cpp') + Glob('src/*/*.cpp')) diff --git a/res/init.bmp b/res/init.bmp deleted file mode 100644 index 30c2bf5..0000000 Binary files a/res/init.bmp and /dev/null differ diff --git a/res/init.png b/res/init.png new file mode 100644 index 0000000..e5a9785 Binary files /dev/null and b/res/init.png differ diff --git a/src/gui.cpp b/src/gui.cpp index ca3fee5..9668e6f 100644 --- a/src/gui.cpp +++ b/src/gui.cpp @@ -1,4 +1,5 @@ #include +#include #include #include "cartridge.hpp" #include "cpu.hpp" @@ -30,6 +31,7 @@ FileMenu* fileMenu; bool pause = true; +// Controls settings: SDL_Scancode CTRL_A = SDL_SCANCODE_A; SDL_Scancode CTRL_B = SDL_SCANCODE_S; SDL_Scancode CTRL_SELECT = SDL_SCANCODE_SPACE; @@ -39,7 +41,6 @@ SDL_Scancode CTRL_DOWN = SDL_SCANCODE_DOWN; SDL_Scancode CTRL_LEFT = SDL_SCANCODE_LEFT; SDL_Scancode CTRL_RIGHT = SDL_SCANCODE_RIGHT; - /* Set the window size multiplier */ void set_size(int mul) { @@ -72,7 +73,7 @@ void init() keys = SDL_GetKeyboardState(0); // Initial background: - SDL_Surface* backSurface = SDL_LoadBMP("res/init.bmp"); + SDL_Surface* backSurface = IMG_Load("res/init.png"); background = SDL_CreateTextureFromSurface(renderer, backSurface); SDL_SetTextureColorMod(background, 60, 60, 60); SDL_FreeSurface(backSurface); @@ -191,10 +192,11 @@ void toggle_pause() SDL_SetTextureColorMod(gameTexture, 255, 255, 255); } +/* Prompt for a key, return the scancode */ SDL_Scancode query_key() { - SDL_Texture* question = gen_text("Press a key...", { 255, 255, 255 }); - render_texture(question, TEXT_CENTER, height - fontSz*4); + SDL_Texture* prompt = gen_text("Press a key...", { 255, 255, 255 }); + render_texture(prompt, TEXT_CENTER, height - fontSz*4); SDL_RenderPresent(renderer); SDL_Event e; diff --git a/src/menu.cpp b/src/menu.cpp index 309939e..2a5e261 100644 --- a/src/menu.cpp +++ b/src/menu.cpp @@ -30,6 +30,11 @@ void Entry::setLabel(string label) redTexture = gen_text(label, { 255, 0, 0 }); } +void Entry::render() +{ + render_texture(selected ? redTexture : whiteTexture, getX(), getY()); +} + ControlEntry::ControlEntry(string action, SDL_Scancode* key, int x, int y) : key(key), Entry::Entry( @@ -41,36 +46,6 @@ ControlEntry::ControlEntry(string action, SDL_Scancode* key, int x, int y) : key this->keyEntry = new Entry(SDL_GetScancodeName(*key), []{}, TEXT_RIGHT, y); } -void ControlEntry::setY(int y) -{ - Entry::setY(y); - this->keyEntry->setY(y); -} - -void ControlEntry::select() -{ - Entry::select(); - this->keyEntry->select(); -} - -void ControlEntry::unselect() -{ - Entry::unselect(); - this->keyEntry->unselect(); -} - -void ControlEntry::render() -{ - Entry::render(); - this->keyEntry->render(); -} - - -void Entry::render() -{ - render_texture(selected ? redTexture : whiteTexture, getX(), getY()); -} - void Menu::add(Entry* entry) { diff --git a/src/menu.hpp b/src/menu.hpp index ba0296c..1c3c40a 100644 --- a/src/menu.hpp +++ b/src/menu.hpp @@ -31,7 +31,7 @@ class Entry virtual void select() { selected = true; }; virtual void unselect() { selected = false; }; - void trigger() { callback(); }; + void trigger() { callback(); }; virtual void render(); }; @@ -42,10 +42,10 @@ class ControlEntry : public Entry public: ControlEntry(std::string action, SDL_Scancode* key, int x = 0, int y = 0); - void setY(int y); - void select(); - void unselect(); - void render(); + void setY(int y) { Entry::setY(y); keyEntry->setY(y); } + void select() { Entry::select(); keyEntry->select(); } + void unselect() { Entry::unselect(); keyEntry->unselect(); } + void render() { Entry::render(); keyEntry->render(); } }; class Menu