diff options
Diffstat (limited to 'src/client/window/button_window.cc')
| -rw-r--r-- | src/client/window/button_window.cc | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/src/client/window/button_window.cc b/src/client/window/button_window.cc new file mode 100644 index 0000000..4743c0a --- /dev/null +++ b/src/client/window/button_window.cc @@ -0,0 +1,71 @@ +#include "client/window/button_window.hh" + +namespace client { +namespace window { + +using bw = class button_window; + +void bw::handle_mousebuttondown(const SDL_Event& event) noexcept { + if (event.button.button != SDL_BUTTON_LEFT) { + return; + } + this->is_pressed = true; +} + +void bw::handle_mousebuttonup(const SDL_Event& event) noexcept { + if (event.button.button != SDL_BUTTON_LEFT) { + return; + } + if (!this->is_pressed) { + return; + } + this->is_pressed = false; + std::invoke(this->callback); // edge +} + +const glm::vec3& bw::get_draw_colour() noexcept { + if (!this->is_inside(client::input::state.mouse_pos)) { + this->is_pressed = false; + return this->primary_clr; + } + + if (!this->is_pressed) { + return this->secondary_clr; + } + + return this->highlight_clr; +} + +bool bw::maybe_handle_event(const SDL_Event& event) noexcept { + if (this->is_inside(client::input::state.mouse_pos)) { + switch (event.type) { + case SDL_MOUSEBUTTONDOWN: + this->handle_mousebuttondown(event); + return true; + case SDL_MOUSEBUTTONUP: + this->handle_mousebuttonup(event); + return true; + } + } + + return basic_window::maybe_handle_event(event); +} + +void bw::draw() noexcept { + basic_window::draw(); + + client::render::draw_rectangle({.pos = {.offset = this->pos}, + .size = {.offset = this->size}, + .colour = {this->get_draw_colour(), 1.0f}}); + client::render::draw_text( + this->name, {.pos = {.extent = {0.0f, 0.0f}, + .offset = this->pos + (this->size / 2.0f)}, + .offset_height = this->size.y / 2.0f, + .colour = {this->font_colour, 1.0f}, + .has_backing = false, + .is_centered = true, + .is_vcentered = true}); +}; + +} // namespace window +} // namespace client |
