Added rudimentary menu buttons, not yet connected to anything... it feels a bit hackish, to be honest, but I don't think we'll ever have too many to worry about, and if so, we can think about refactoring then
This commit is contained in:
39
menubutton.cpp
Normal file
39
menubutton.cpp
Normal file
@ -0,0 +1,39 @@
|
||||
#include "menubutton.h"
|
||||
#include "drawutils.h"
|
||||
|
||||
|
||||
MenuButton::MenuButton(string text, TTF_Font* font, int x, int y,
|
||||
ButtonAction action)
|
||||
{
|
||||
this->text = text;
|
||||
this->x = x;
|
||||
this->y = y;
|
||||
this->font = font;
|
||||
this->action = action;
|
||||
|
||||
hover = false;
|
||||
}
|
||||
|
||||
|
||||
void MenuButton::set_hover(bool is_hovering)
|
||||
{
|
||||
hover = is_hovering;
|
||||
}
|
||||
|
||||
|
||||
void MenuButton::draw(SDL_Surface* display, int colour, int background_colour)
|
||||
{
|
||||
SDL_Rect pen = {x, y, 100, 40};
|
||||
|
||||
SDL_FillRect(display, &pen, background_colour);
|
||||
|
||||
int temp_colour = 0x000000;
|
||||
|
||||
DrawUtils::draw_text(display, text, x + 50, y + 20, font, colour, 1, 1);
|
||||
}
|
||||
|
||||
|
||||
bool MenuButton::is_at(int test_x, int test_y)
|
||||
{
|
||||
return test_x >= x && test_y >= y && test_x <= x + 100 && test_y <= y + 40;
|
||||
}
|
Reference in New Issue
Block a user