Working on the ui, incomplete
This commit is contained in:
+21
-54
@@ -21,71 +21,38 @@
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include "bounding_box.hpp"
|
||||
#include "image.hpp"
|
||||
#include "raster_font.hpp"
|
||||
|
||||
#include "SDL2/SDL_ttf.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
/* 3-phases, no toggle, centred text
|
||||
* This class uses the size of the provided image as its bounds. Also,
|
||||
* The provided image should be formatted correctly.
|
||||
*
|
||||
* The button's image should be divided into 3 sections virtucally,
|
||||
* which act as the different button images. The clip width & height of the
|
||||
* Image should be set manually, and the height should be 1/3 of the total
|
||||
* graphical data.
|
||||
*/
|
||||
class Button {
|
||||
public:
|
||||
enum State {
|
||||
NORMAL = 0, HOVER = 1, PRESSED = 2
|
||||
//states available
|
||||
enum class State {
|
||||
NORMAL, HOVER, PRESSED
|
||||
};
|
||||
|
||||
//methods
|
||||
Button() = default;
|
||||
~Button() = default;
|
||||
|
||||
//handle input
|
||||
State MouseMotion(SDL_MouseMotionEvent const&);
|
||||
State MouseButtonDown(SDL_MouseButtonEvent const&);
|
||||
State MouseButtonUp(SDL_MouseButtonEvent const&);
|
||||
void RenderText(std::string s);
|
||||
bool CaptureInput(int x, int y, bool pressed);
|
||||
void DrawTo(SDL_Renderer*, int camX, int camY);
|
||||
|
||||
//yet another draw function
|
||||
void DrawTo(SDL_Surface* const);
|
||||
//accessors & mutators
|
||||
int SetX(int x) { return posX = x; }
|
||||
int SetY(int y) { return posY = y; }
|
||||
int GetX() { return posX; }
|
||||
int GetY() { return posY; }
|
||||
Image* GetImage() { return ℑ }
|
||||
BoundingBox* GetBoundingBox() { return &boundingBox; }
|
||||
|
||||
//accessors and mutators
|
||||
Image* SetImage(Image* const ptr) { return image = ptr; }
|
||||
Image* GetImage() { return image; }
|
||||
RasterFont* SetFont(RasterFont* const ptr) { return font = ptr; }
|
||||
RasterFont* GetFont() { return font; }
|
||||
|
||||
Sint16 SetX(Sint16 i) { return x = i; }
|
||||
Sint16 SetY(Sint16 i) { return y = i; }
|
||||
Sint16 GetX() const { return x; }
|
||||
Sint16 GetY() const { return y; }
|
||||
|
||||
Sint16 SetTextX(Sint16 i) { return textX = i; }
|
||||
Sint16 SetTextY(Sint16 i) { return textY = i; }
|
||||
Sint16 GetTextX() const { return textX; }
|
||||
Sint16 GetTextY() const { return textY; }
|
||||
|
||||
State SetState(State s) { return state = s; }
|
||||
State GetState() const { return state; }
|
||||
|
||||
std::string SetText(std::string);
|
||||
std::string GetText() const { return text; }
|
||||
|
||||
private:
|
||||
State CalcState(Sint16 x, Sint16 y, bool leftPressed);
|
||||
|
||||
//point to the provided external objects
|
||||
Image* image = nullptr;
|
||||
RasterFont* font = nullptr;
|
||||
|
||||
//positions
|
||||
Sint16 x = 0, y = 0;
|
||||
Sint16 textX = 0, textY = 0;
|
||||
|
||||
//
|
||||
State state = State::NORMAL;
|
||||
std::string text;
|
||||
protected:
|
||||
Image image;
|
||||
BoundingBox boundingBox;
|
||||
int posX = 0, posY = 0;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user