summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAki <please@ignore.pl>2022-05-17 19:17:31 +0200
committerAki <please@ignore.pl>2022-05-17 19:17:31 +0200
commit405563345e30b757829b3411b0f33cb166793ad7 (patch)
treea764cdc0841f9ca85de58e85e442411ea0e0f3ad
parente49474fc0dcff041a9fae2857273938481cc9ec9 (diff)
downloadderelict-405563345e30b757829b3411b0f33cb166793ad7.zip
derelict-405563345e30b757829b3411b0f33cb166793ad7.tar.gz
derelict-405563345e30b757829b3411b0f33cb166793ad7.tar.bz2
Added simple hovering
-rw-r--r--Label.h1
-rw-r--r--View.cpp28
-rw-r--r--View.h1
3 files changed, 26 insertions, 4 deletions
diff --git a/Label.h b/Label.h
index 688dead..6372a6f 100644
--- a/Label.h
+++ b/Label.h
@@ -9,4 +9,5 @@ struct Label
Vector2 base;
float depth;
float length;
+ bool hover;
};
diff --git a/View.cpp b/View.cpp
index debf10c..0aa3b7b 100644
--- a/View.cpp
+++ b/View.cpp
@@ -14,7 +14,8 @@ View::View(std::vector<Grid> grids) :
m_grids {grids},
m_labels {},
m_grid {0},
- m_texture {LoadTexture("resources/wreck.png")}
+ m_texture {LoadTexture("resources/wreck.png")},
+ m_active {nullptr}
{
m_camera.position = Vector3{10.0f, 10.0f, 10.0f};
m_camera.target = Vector3{0.0f, 0.0f, 0.0f};
@@ -45,6 +46,7 @@ View::update(const float dt)
const auto wrecks = m_grids.at(m_grid).wrecks;
m_labels.clear();
m_labels.reserve(wrecks.size());
+ auto mouse = GetMousePosition();
for (const auto& wreck : wrecks) {
const auto pos = GetWorldToScreen(wreck.position, m_camera);
const auto base = GetWorldToScreen({wreck.position.x, 0.0f, wreck.position.z}, m_camera);
@@ -60,9 +62,27 @@ View::update(const float dt)
std::sqrt(
std::pow(pos.x - base.x, 2) +
std::pow(pos.y - base.y, 2));
- m_labels.push_back(Label{pos, base, depth, length});
+ const bool hover =
+ 8.0f > std::sqrt(
+ std::pow(mouse.x - pos.x, 2) +
+ std::pow(mouse.y - pos.y, 2));
+ m_labels.push_back(Label{pos, base, depth, length, hover});
}
std::sort(m_labels.begin(), m_labels.end(), [](auto& a, auto& b){ return a.depth > b.depth; });
+ m_active = nullptr;
+ for (auto& label : m_labels) {
+ if (label.hover) {
+ if (m_active) {
+ if (label.depth < m_active->depth)
+ m_active = &label;
+ }
+ else
+ m_active = &label;
+ label.hover = false;
+ }
+ }
+ if (m_active)
+ m_active->hover = true;
}
@@ -76,8 +96,8 @@ View::draw() const
EndMode3D();
for (const auto& point : m_labels) {
if (point.length > 8)
- DrawLine(point.base.x, point.base.y, point.pos.x, point.pos.y, DARKGRAY);
- DrawTexture(m_texture, point.pos.x - 8, point.pos.y - 8, WHITE);
+ DrawLine(point.base.x, point.base.y, point.pos.x, point.pos.y, point.hover ? ORANGE : DARKGRAY);
+ DrawTexture(m_texture, point.pos.x - 8, point.pos.y - 8, point.hover ? ORANGE : WHITE);
}
DrawFPS(5, 5);
DrawText(TextFormat("%d", m_labels.size()), 5, 25, 20, DARKGRAY);
diff --git a/View.h b/View.h
index e259132..e58b539 100644
--- a/View.h
+++ b/View.h
@@ -22,4 +22,5 @@ private:
int m_grid;
float m_timer;
Texture2D m_texture;
+ Label* m_active;
};