-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #192 from horriblename/feature/debug-circles
Add circles on touch for debugging
- Loading branch information
Showing
5 changed files
with
171 additions
and
3 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
#include "TouchVisualizer.hpp" | ||
#include "src/devices/ITouch.hpp" | ||
#include "src/macros.hpp" | ||
#include "src/render/OpenGL.hpp" | ||
#include "src/render/Renderer.hpp" | ||
#include <cairo/cairo.h> | ||
#include <hyprland/src/Compositor.hpp> | ||
#include <hyprland/src/SharedDefs.hpp> | ||
#include <optional> | ||
|
||
CBox boxAroundCenter(Vector2D center, double radius) { | ||
return CBox(center.x - radius, center.y - radius, 2 * radius, 2 * radius); | ||
} | ||
|
||
Visualizer::Visualizer() { | ||
const int R = TOUCH_POINT_RADIUS; | ||
|
||
this->cairoSurface = | ||
cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 2 * TOUCH_POINT_RADIUS, 2 * TOUCH_POINT_RADIUS); | ||
auto cairo = cairo_create(cairoSurface); | ||
|
||
cairo_arc(cairo, R, R, R, 0, 2 * PI); | ||
cairo_set_source_rgba(cairo, 0.8, 0.8, 0.1, 0.6); | ||
cairo_fill(cairo); | ||
|
||
cairo_destroy(cairo); | ||
|
||
const unsigned char* data = cairo_image_surface_get_data(this->cairoSurface); | ||
|
||
this->texture->allocate(); | ||
glBindTexture(GL_TEXTURE_2D, this->texture->m_iTexID); | ||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); | ||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); | ||
|
||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 2 * TOUCH_POINT_RADIUS, 2 * TOUCH_POINT_RADIUS, 0, GL_RGBA, | ||
GL_UNSIGNED_BYTE, data); | ||
} | ||
|
||
Visualizer::~Visualizer() { | ||
if (this->cairoSurface) | ||
cairo_surface_destroy(this->cairoSurface); | ||
} | ||
|
||
void Visualizer::onPreRender() {} | ||
|
||
void Visualizer::onRender() { | ||
if (this->finger_positions.size() < 1) { | ||
return; | ||
} | ||
|
||
const auto monitor = g_pCompositor->m_pLastMonitor.lock(); | ||
|
||
// HACK: should not damage monitor, however, I don't understand jackshit | ||
// about damage so here we are. | ||
// If you know how to do damage properly I BEG OF YOU PLEASE ABSOLVE ME | ||
// OF MY SINS | ||
if (this->finger_positions.size()) { | ||
g_pHyprRenderer->damageMonitor(monitor); | ||
} | ||
|
||
for (auto& finger : this->finger_positions) { | ||
CBox dmg = boxAroundCenter(finger.second.curr, TOUCH_POINT_RADIUS); | ||
g_pHyprOpenGL->renderTexture(this->texture, &dmg, 1.f, 0, true); | ||
} | ||
} | ||
|
||
void Visualizer::onTouchDown(ITouch::SDownEvent ev) { | ||
auto mon = g_pCompositor->m_pLastMonitor.lock(); | ||
this->finger_positions.emplace(ev.touchID, FingerPos{ev.pos * mon->vecPixelSize + mon->vecPosition, std::nullopt}); | ||
g_pCompositor->scheduleFrameForMonitor(mon); | ||
} | ||
|
||
void Visualizer::onTouchUp(ITouch::SUpEvent ev) { | ||
this->damageFinger(ev.touchID); | ||
this->finger_positions.erase(ev.touchID); | ||
g_pCompositor->scheduleFrameForMonitor(g_pCompositor->m_pLastMonitor.lock()); | ||
} | ||
|
||
void Visualizer::onTouchMotion(ITouch::SMotionEvent ev) { | ||
auto mon = g_pCompositor->m_pLastMonitor.lock(); | ||
this->finger_positions[ev.touchID] = {ev.pos * mon->vecPixelSize + mon->vecPosition, std::nullopt}; | ||
g_pCompositor->scheduleFrameForMonitor(mon); | ||
} | ||
|
||
void Visualizer::damageFinger(int32_t id) { | ||
auto finger = this->finger_positions.at(id); | ||
|
||
CBox dm = boxAroundCenter(finger.curr, TOUCH_POINT_RADIUS); | ||
g_pHyprRenderer->damageBox(&dm); | ||
|
||
if (finger.last_rendered.has_value()) { | ||
dm = boxAroundCenter(finger.last_rendered.value(), TOUCH_POINT_RADIUS); | ||
g_pHyprRenderer->damageBox(&dm); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#include "src/devices/ITouch.hpp" | ||
#include "src/render/Texture.hpp" | ||
#include <cairo/cairo.h> | ||
#include <hyprland/src/render/OpenGL.hpp> | ||
#include <hyprland/src/render/Shaders.hpp> | ||
#include <hyprutils/memory/SharedPtr.hpp> | ||
#include <optional> | ||
#include <unordered_map> | ||
|
||
struct FingerPos { | ||
Vector2D curr; | ||
std::optional<Vector2D> last_rendered; | ||
}; | ||
|
||
class Visualizer { | ||
public: | ||
Visualizer(); | ||
~Visualizer(); | ||
void onPreRender(); | ||
void onRender(); | ||
void damageFinger(int32_t id); | ||
|
||
void onTouchDown(ITouch::SDownEvent); | ||
void onTouchUp(ITouch::SUpEvent); | ||
void onTouchMotion(ITouch::SMotionEvent); | ||
|
||
private: | ||
SP<CTexture> texture = makeShared<CTexture>(); | ||
cairo_surface_t* cairoSurface; | ||
bool tempDamaged = false; | ||
const int TOUCH_POINT_RADIUS = 30; | ||
std::unordered_map<int32_t, FingerPos> finger_positions; | ||
}; |
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
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