Browse Source

+src/geom.{cpp, h}: Rect, << for Rect and ImVec2

master
gradient 8 years ago
parent
commit
77d269e8e4
4 changed files with 43 additions and 1 deletions
  1. +1
    -1
      CMakeLists.txt
  2. +11
    -0
      src/geom.cpp
  3. +30
    -0
      src/geom.h
  4. +1
    -0
      src/main.cpp

+ 1
- 1
CMakeLists.txt View File

@ -25,7 +25,7 @@ include_directories(deps/inotify)
include_directories(deps/handmademath) include_directories(deps/handmademath)
include_directories(${PROJECT_SOURCE_DIR}) 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 src/shaders.cpp
${IMGUI_SOURCE}) ${IMGUI_SOURCE})


+ 11
- 0
src/geom.cpp View File

@ -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;
}

+ 30
- 0
src/geom.h View File

@ -0,0 +1,30 @@
#pragma once
#define IMGUI_DEFINE_MATH_OPERATORS
#include <imgui.h>
#include <imgui_internal.h>
#include <sstream>
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);

+ 1
- 0
src/main.cpp View File

@ -8,6 +8,7 @@
#include <GLFW/glfw3.h> #include <GLFW/glfw3.h>
#include "gui.h" #include "gui.h"
#include "geom.h"
#include "state.h" #include "state.h"
#include "notify.h" #include "notify.h"


Loading…
Cancel
Save