Skip to content

Instantly share code, notes, and snippets.

@Folling
Created September 5, 2017 11:39
Show Gist options
  • Save Folling/0deb1dbf70ff878140250706685a7ed6 to your computer and use it in GitHub Desktop.
Save Folling/0deb1dbf70ff878140250706685a7ed6 to your computer and use it in GitHub Desktop.
#pragma once
#include <string>
#include <iostream>
#include <bitset>
#include <SDL/SDL.h>
#include "Position.h"
#include "Debug.h"
// basic setup for checking things that would not cause a crash
// but are probably unwanted behavior, this just logs it.
#ifdef DEBUG
#define dLog(x) std::cout<< "Debug: " << x << '\n'
#define should(x) if(x)
#else
#define dLog(x)
#define should(x)
#endif
#undef SDL_Colour
typedef SDL_Color SDL_Colour;
typedef size_t length;
typedef size_t area;
typedef int8_t flag;
// flags
#define BORDER_ONLY 0x00000001
#define BODY_ONLY 0x00000010
#define ALL 0x00000100
class Button {
public:
Button();
~Button();
public:
// basic parameters of a Button
// TODO functionality still has to be implemented
void hide();
void show();
void makeTransparent();
void makeOpaque();
void makeRound();
void makeEdgy();
public:
void draw(SDL_Renderer* rend);
public:
// basically just setters for all attributes a Button has
// TODO implement functionality of Button
void moveTo(const int x, const int y);
void moveTo(const Position to);
void setText(const std::string to);
void setText(const char* to);
void setWidth(const length to);
void setHeight(const length to);
void setBorderSize(const length to);
void setBorderColour(const SDL_Colour to);
void setBorderColour(const Uint8 R, const Uint8 G, const Uint8 B, const Uint8 A);
void setColour(const SDL_Colour to);
void setColour(const Uint8 R, const Uint8 G, const Uint8 B, const Uint8 A);
public:
// useful getters, might be expanded
area getArea(const flag option) const;
length getLength(const flag option) const;
length getHeight(const flag option) const;
private:
// The actual Rectangle and the Button Border + Colours
// TODO consider changing to general shape, y'know, if you want like
// TODO special shapes for you button
SDL_Rect border;
SDL_Colour borderColour;
SDL_Rect body;
SDL_Colour colour;
SDL_Surface* surface;
private:
std::string text;
public:
bool hidden;
bool transparent;
bool rounded;
private:
Position pos;
length width;
length height;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment