Skip to content

Commit 3727857

Browse files
committed
Calculate which brick is clicked on the canvas
1 parent 52352a9 commit 3727857

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

source/code/puzzle_editor/PuzzleEditorState.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ Source information and contacts persons can be found at
2727
#include <fmt/core.h>
2828

2929
#include "imgui.h"
30+
#include "imgui_internal.h"
3031
#include "backends/imgui_impl_sdl2.h"
3132
#include "backends/imgui_impl_sdlrenderer2.h"
3233
#include "../sago/SagoMisc.hpp"
@@ -142,6 +143,23 @@ void PuzzleEditorState::Draw(SDL_Renderer* target) {
142143
p2.y += yoffset;
143144
ImGui::GetWindowDrawList()->AddLine(p1, p2, IM_COL32(255, 0, 0, 100));
144145
}
146+
ImGuiIO& io = ImGui::GetIO();
147+
if (ImGui::IsMouseReleased(0) && io.MouseDownDurationPrev[0] < 0.3f && !ImGui::IsMouseDragPastThreshold(0)) {
148+
ImVec2 pos = io.MousePos;
149+
pos.x -= xoffset;
150+
pos.y -= yoffset;
151+
int logical_pos_x = 0;
152+
int logical_pos_y = 0;
153+
window_resize.PhysicalToLogical(pos.x, pos.y, logical_pos_x, logical_pos_y);
154+
//std::cout << "Clicked at: " << pos.x << "," << pos.y << "\n";
155+
//std::cout << "Logical Pos: " << logical_pos_x << "," << logical_pos_y << "\n";
156+
int board_x = logical_pos_x / 50;
157+
int board_y = logical_pos_y / 50;
158+
if (board_x >=0 && board_x < 6 && board_y >= 0 && board_y < 12) {
159+
std::cout << "Board Pos: " << board_x << "," << board_y << "\n";
160+
}
161+
162+
}
145163
ImGui::EndChild();
146164
ImGui::End();
147165

0 commit comments

Comments
 (0)