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:
47
menubutton.h
Normal file
47
menubutton.h
Normal file
@ -0,0 +1,47 @@
|
||||
/* A clickable button widget
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _MENUBUTTON_H_
|
||||
#define _MENUBUTTON_H_
|
||||
|
||||
#include <SDL.h>
|
||||
#include <SDL_ttf.h>
|
||||
#include <string>
|
||||
|
||||
using std::string;
|
||||
|
||||
// fixme: there's probably a better way to do this, but SDL's event model
|
||||
// has me hard-pressed to figure out what it is.
|
||||
enum ButtonAction {BUTTON_BUILD, BUTTON_ATTACK, BUTTON_MOVE,
|
||||
BUTTON_BUILD_ATTACKER, BUTTON_BUILD_DEFENDER,
|
||||
BUTTON_BUILD_PRODUCER};
|
||||
|
||||
class MenuButton
|
||||
{
|
||||
public:
|
||||
MenuButton(string text = "", TTF_Font* font = NULL, int x = 0, int y = 0,
|
||||
ButtonAction action = BUTTON_BUILD);
|
||||
|
||||
// Selectable buttons change colour for the duration they are selected,
|
||||
// and should ignore clicks while selected
|
||||
void set_hover(bool is_hovering);
|
||||
void draw(SDL_Surface* display, int colour = 0x000000,
|
||||
int background_colour = 0x888888);
|
||||
|
||||
bool is_at(int test_x, int test_y);
|
||||
ButtonAction get_action() const { return action; }
|
||||
|
||||
private:
|
||||
string text;
|
||||
int x;
|
||||
int y;
|
||||
|
||||
bool hover;
|
||||
|
||||
TTF_Font* font;
|
||||
|
||||
ButtonAction action;
|
||||
};
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user