treewars/menubutton.cpp

40 lines
770 B
C++
Raw Normal View History

#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;
}