10 const ImGuiIO& io = ImGui::GetIO();
18 ImVec2 mouse_pos = io.MousePos;
23 ImVec2 canvas_mouse_pos =
24 ImVec2(mouse_pos.x - canvas_pos.x, mouse_pos.y - canvas_pos.y);
27 if (ImGui::IsMouseClicked(ImGuiMouseButton_Left)) {
28 if (ImGui::IsKeyDown(ImGuiKey_LeftCtrl) ||
29 ImGui::IsKeyDown(ImGuiKey_RightCtrl)) {
39 auto [room_x, room_y] =
41 static_cast<int>(canvas_mouse_pos.y));
53 if (
is_selecting_ && ImGui::IsMouseDragging(ImGuiMouseButton_Left)) {
58 if (
is_dragging_ && ImGui::IsMouseDragging(ImGuiMouseButton_Left)) {
64 if (ImGui::IsMouseReleased(ImGuiMouseButton_Left)) {
78 int tile_delta_x =
static_cast<int>(drag_delta.x) / 8;
79 int tile_delta_y =
static_cast<int>(drag_delta.y) / 8;
82 auto& objects = room.GetTileObjects();
84 if (index < objects.size()) {
85 objects[index].x_ += tile_delta_x;
86 objects[index].y_ += tile_delta_y;
89 objects[index].x_ = std::clamp(
static_cast<int>(objects[index].x_), 0, 63);
90 objects[index].y_ = std::clamp(
static_cast<int>(objects[index].y_), 0, 63);
116 const ImGuiIO& io = ImGui::GetIO();
118 const ImVec2 mouse_pos =
119 ImVec2(io.MousePos.x - canvas_pos.x, io.MousePos.y - canvas_pos.y);
121 static bool dragging =
false;
122 static ImVec2 drag_start_pos;
125 if (ImGui::IsMouseClicked(ImGuiMouseButton_Right) && !
object_loaded_) {
126 drag_start_pos = mouse_pos;
134 if (ImGui::IsMouseDragging(ImGuiMouseButton_Right) && !
object_loaded_) {
140 ImVec2(canvas_pos.x + std::min(drag_start_pos.x, mouse_pos.x),
141 canvas_pos.y + std::min(drag_start_pos.y, mouse_pos.y));
142 ImVec2 end = ImVec2(canvas_pos.x + std::max(drag_start_pos.x, mouse_pos.x),
143 canvas_pos.y + std::max(drag_start_pos.y, mouse_pos.y));
145 ImDrawList* draw_list = ImGui::GetWindowDrawList();
146 draw_list->AddRect(start, end, IM_COL32(255, 255, 0, 255), 0.0f, 0, 2.0f);
147 draw_list->AddRectFilled(start, end, IM_COL32(255, 255, 0, 32));
151 if (dragging && !ImGui::IsMouseDown(ImGuiMouseButton_Right)) {
184 if (!
rooms_ || current_room_id_ < 0 || current_room_id_ >= 296)
return;
187 const auto& objects = room.GetTileObjects();
190 ImDrawList* draw_list = ImGui::GetWindowDrawList();
194 if (index < objects.size()) {
195 const auto&
object = objects[index];
199 int obj_width = 8 + (
object.size_ & 0x0F) * 4;
200 int obj_height = 8 + ((
object.size_ >> 4) & 0x0F) * 4;
201 obj_width = std::min(obj_width, 64);
202 obj_height = std::min(obj_height, 64);
205 ImVec2 obj_start(canvas_pos.x + canvas_x - 2,
206 canvas_pos.y + canvas_y - 2);
207 ImVec2 obj_end(canvas_pos.x + canvas_x + obj_width + 2,
208 canvas_pos.y + canvas_y + obj_height + 2);
211 float pulse = 0.7f + 0.3f * std::sin(
static_cast<float>(ImGui::GetTime()) * 4.0f);
212 draw_list->AddRect(obj_start, obj_end,
213 IM_COL32(0,
static_cast<int>(255 * pulse), 255, 255),
217 constexpr float handle_size = 4.0f;
218 draw_list->AddRectFilled(
219 ImVec2(obj_start.x - handle_size/2, obj_start.y - handle_size/2),
220 ImVec2(obj_start.x + handle_size/2, obj_start.y + handle_size/2),
221 IM_COL32(0, 255, 255, 255));
222 draw_list->AddRectFilled(
223 ImVec2(obj_end.x - handle_size/2, obj_start.y - handle_size/2),
224 ImVec2(obj_end.x + handle_size/2, obj_start.y + handle_size/2),
225 IM_COL32(0, 255, 255, 255));
226 draw_list->AddRectFilled(
227 ImVec2(obj_start.x - handle_size/2, obj_end.y - handle_size/2),
228 ImVec2(obj_start.x + handle_size/2, obj_end.y + handle_size/2),
229 IM_COL32(0, 255, 255, 255));
230 draw_list->AddRectFilled(
231 ImVec2(obj_end.x - handle_size/2, obj_end.y - handle_size/2),
232 ImVec2(obj_end.x + handle_size/2, obj_end.y + handle_size/2),
233 IM_COL32(0, 255, 255, 255));
284 if (current_room_id_ < 0 || current_room_id_ >= 296)
return;
287 ImDrawList* draw_list = ImGui::GetWindowDrawList();
293 const auto& objects = room.GetTileObjects();
297 if (index < objects.size()) {
298 const auto&
object = objects[index];
302 int obj_width = 8 + (
object.size_ & 0x0F) * 4;
303 int obj_height = 8 + ((
object.size_ >> 4) & 0x0F) * 4;
304 obj_width = std::min(obj_width, 64);
305 obj_height = std::min(obj_height, 64);
308 ImVec2 preview_start(canvas_pos.x + canvas_x + drag_delta.x,
309 canvas_pos.y + canvas_y + drag_delta.y);
310 ImVec2 preview_end(preview_start.x + obj_width, preview_start.y + obj_height);
313 draw_list->AddRectFilled(preview_start, preview_end, IM_COL32(0, 255, 255, 64));
314 draw_list->AddRect(preview_start, preview_end, IM_COL32(0, 255, 255, 255), 0.0f, 0, 1.5f);
477 if (current_room_id_ < 0 || current_room_id_ >= 296)
return;
482 const ImGuiIO& io = ImGui::GetIO();
483 ImVec2 mouse_pos = io.MousePos;
485 ImVec2 canvas_mouse_pos =
486 ImVec2(mouse_pos.x - canvas_pos.x, mouse_pos.y - canvas_pos.y);
488 static_cast<int>(canvas_mouse_pos.x),
489 static_cast<int>(canvas_mouse_pos.y));
499 new_obj.x_ = obj.x_ + offset_x;
500 new_obj.y_ = obj.y_ + offset_y;
503 new_obj.x_ = std::clamp(
static_cast<int>(new_obj.x_), 0, 63);
504 new_obj.y_ = std::clamp(
static_cast<int>(new_obj.y_), 0, 63);
506 room.AddTileObject(new_obj);