diff --git a/CMakeLists.txt b/CMakeLists.txt index 15be850..8a2001f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,7 +25,7 @@ include_directories(deps/inotify) include_directories(deps/handmademath) include_directories(${PROJECT_SOURCE_DIR}) -add_executable(zinnia src/main.cpp src/gui.cpp src/project.cpp +add_executable(zinnia src/main.cpp src/geom.cpp src/gui/gui.cpp src/project.cpp src/shaders.cpp ${IMGUI_SOURCE}) diff --git a/src/geom.cpp b/src/geom.cpp new file mode 100644 index 0000000..b4dffbb --- /dev/null +++ b/src/geom.cpp @@ -0,0 +1,11 @@ +#include "geom.h" + +std::ostream &operator<<(std::ostream &os, const ImVec2 &vec) { + os << "[" << vec.x << ", " << vec.y << "]"; + return os; +} + +std::ostream &operator<<(std::ostream &os, const Rect &rect) { + os << "Rect { pos: " << rect.pos << ", size: " << rect.size << " }"; + return os; +} diff --git a/src/geom.h b/src/geom.h new file mode 100644 index 0000000..cbbb0e0 --- /dev/null +++ b/src/geom.h @@ -0,0 +1,30 @@ +#pragma once + +#define IMGUI_DEFINE_MATH_OPERATORS +#include +#include +#include + +class Rect { +public: + Rect(ImVec2 pos, ImVec2 size) : pos(pos), size(size) {} + Rect(float x, float y, float w, float h) : pos(x, y), size(w, h) {} + + ImVec2 pos; + ImVec2 size; + + float top() const { return pos.y; } + float left() const { return pos.x; } + float bottom() const { return pos.y + size.y; } + float right() const { return pos.x + size.x; } + + bool intersects(const Rect &other) { + return this->left() < other.right() && + this->right() > other.left() && + this->top() < other.bottom() && + this->bottom() > other.top(); + } +}; + +std::ostream &operator<<(std::ostream &os, const ImVec2 &vec); +std::ostream &operator<<(std::ostream &os, const Rect &rect); diff --git a/src/main.cpp b/src/main.cpp index 4506d8e..4b2bb2e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -8,6 +8,7 @@ #include #include "gui.h" +#include "geom.h" #include "state.h" #include "notify.h"