Instantly share code, notes, and snippets.
Created
September 5, 2017 11:39
-
Star
(0)
0
You must be signed in to star a gist -
Fork
(0)
0
You must be signed in to fork a gist
-
Save Folling/10dc2d1fe19ed6fe56da769fb5411419 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "Button.h" | |
Button::Button() { | |
} | |
Button::~Button() { | |
} | |
void Button::hide() { | |
should(this->hidden) dLog("Button was already hidden"); | |
this->hidden = true; | |
} | |
void Button::show() { | |
should(!this->hidden) dLog("Button was already visible"); | |
this->hidden = false; | |
} | |
void Button::makeTransparent() { | |
should(this->transparent) dLog("Button was already transparent"); | |
this->transparent = true; | |
} | |
void Button::makeOpaque() { | |
should(!this->transparent) dLog("Button was already opaque"); | |
this->transparent = false; | |
} | |
void Button::makeRound() { | |
should(this->rounded) dLog("Button was already rounded"); | |
this->rounded = true; | |
} | |
void Button::makeEdgy() { | |
should(!this->rounded) dLog("Button was already edgy"); | |
this->rounded = false; | |
} | |
void Button::draw(SDL_Renderer* rend) { | |
SDL_RenderDrawRect(rend, &this->border); | |
SDL_RenderDrawRect(rend, &this->body); | |
} | |
void Button::moveTo(const int x, const int y) { | |
should(this->pos == Position(x, y)) dLog("Button was already at " << x << y); | |
this->pos = Position(x, y); | |
} | |
void Button::moveTo(const Position to) { | |
should(this->pos == to) dLog("Button was already at " << to.x << to.y); | |
this->pos = to; | |
} | |
void Button::setText(const std::string to) { | |
should(this->text == to) dLog("Button text is identical"); | |
this->text = to; | |
} | |
void Button::setText(const char* to) { | |
should(this->text.c_str() == to) dLog("Button text is identical"); | |
this->text = to; | |
} | |
void Button::setWidth(const length to) { | |
should(this->width == to) dLog("Length was identical"); | |
this->width = to; | |
} | |
void Button::setHeight(const length to) { | |
should(this->height == to) dLog("Height was identical"); | |
this->height = to; | |
} | |
void Button::setBorderSize(const length to) { | |
should(this->border.w - this->body.w == to/2) dLog("Border's width was identical"); | |
this->border.w = (to + this->body.w) / 2; | |
} | |
void Button::setBorderColour(const SDL_Colour to) { | |
SDL_FillRect( | |
this->surface, | |
&this->border, | |
SDL_MapRGBA( | |
surface->format, | |
to.r, | |
to.g, | |
to.b, | |
to.a | |
) | |
); | |
} | |
void Button::setBorderColour(const Uint8 R, const Uint8 G, const Uint8 B, const Uint8 A) { | |
SDL_FillRect( | |
this->surface, | |
&this->border, | |
SDL_MapRGBA( | |
surface->format, | |
R, | |
G, | |
B, | |
A | |
) | |
); | |
} | |
void Button::setColour(const SDL_Colour to) { | |
SDL_FillRect( | |
this->surface, | |
&this->border, | |
SDL_MapRGBA( | |
surface->format, | |
to.r, | |
to.g, | |
to.b, | |
to.a | |
) | |
); | |
} | |
void Button::setColour(const Uint8 R, const Uint8 G, const Uint8 B, const Uint8 A) { | |
SDL_FillRect( | |
this->surface, | |
&this->border, | |
SDL_MapRGBA( | |
surface->format, | |
R, | |
G, | |
B, | |
A | |
) | |
); | |
} | |
area Button::getArea(const flag option)const { | |
switch(option) { | |
case ALL: | |
return border.w * border.h; | |
case BODY_ONLY: | |
return body.w * body.h; | |
case BORDER_ONLY: | |
return (border.w * border.h - body.w * body.h); | |
default: dLog("Unable to resolve flag: " << std::bitset<8>(option)); | |
} | |
return 0; | |
} | |
length Button::getLength(const flag option)const { | |
switch(option) { | |
case ALL: | |
return border.w; | |
case BODY_ONLY: | |
return body.w; | |
case BORDER_ONLY: | |
return border.w - body.w; | |
default: dLog("Unable to resolve flag: " << std::bitset<8>(option)); | |
} | |
return 0; | |
} | |
length Button::getHeight(const flag option)const { | |
switch(option) { | |
case ALL: | |
return border.h; | |
case BODY_ONLY: | |
return body.h; | |
case BORDER_ONLY: | |
return border.h - body.w; | |
default: dLog("Unable to resolve flag: " << std::bitset<8>(option)); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment