aboutsummaryrefslogtreecommitdiff
path: root/src/client/window/button_window.cc
diff options
context:
space:
mode:
authorNicolas James <Eele1Ephe7uZahRie@tutanota.com>2025-02-12 21:57:46 +1100
committerNicolas James <Eele1Ephe7uZahRie@tutanota.com>2025-02-12 21:57:46 +1100
commite4483eca01b48b943cd0461e24a74ae1a3139ed4 (patch)
treeed58c3c246e3af1af337697695d780aa31f6ad9a /src/client/window/button_window.cc
parent1cc08c51eb4b0f95c30c0a98ad1fc5ad3459b2df (diff)
Update to most recent version (old initial commit)
Diffstat (limited to 'src/client/window/button_window.cc')
-rw-r--r--src/client/window/button_window.cc71
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