150 int current_tile, ImVec2* out_drawn_pos) {
154 const ImGuiIO& io = ImGui::GetIO();
157 const ImVec2 mouse_pos(io.MousePos.x - origin.x, io.MousePos.y - origin.y);
169 ImVec2 paint_pos = AlignPosToGridHelper(mouse_pos, scaled_size);
173 if (tiles_per_row > 0) {
174 int tile_x = (current_tile % tiles_per_row) * tilemap.
tile_size.
x;
175 int tile_y = (current_tile / tiles_per_row) * tilemap.
tile_size.
y;
177 if (tile_x >= 0 && tile_x < tilemap.
atlas.
width() && tile_y >= 0 &&
180 ImVec2(
static_cast<float>(tile_x) / tilemap.
atlas.
width(),
181 static_cast<float>(tile_y) / tilemap.
atlas.
height());
182 ImVec2 uv1 = ImVec2(
static_cast<float>(tile_x + tilemap.
tile_size.
x) /
184 static_cast<float>(tile_y + tilemap.
tile_size.
y) /
189 ImVec2(origin.x + paint_pos.x, origin.y + paint_pos.y),
190 ImVec2(origin.x + paint_pos.x + scaled_size,
191 origin.y + paint_pos.y + scaled_size),
197 if (ImGui::IsMouseClicked(ImGuiMouseButton_Left) ||
198 ImGui::IsMouseDragging(ImGuiMouseButton_Left)) {
200 *out_drawn_pos = paint_pos;
208 ImVec2* out_selected_pos) {
209 const ImGuiIO& io = ImGui::GetIO();
212 const ImVec2 mouse_pos(io.MousePos.x - origin.x, io.MousePos.y - origin.y);
218 if (rt.
hovered && ImGui::IsMouseClicked(ImGuiMouseButton_Left)) {
220 AlignPosToGridHelper(mouse_pos,
static_cast<float>(size));
221 if (out_selected_pos)
222 *out_selected_pos = painter_pos;
225 if (rt.
hovered && ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left)) {
237 const ImGuiIO& io = ImGui::GetIO();
240 const ImVec2 mouse_pos(io.MousePos.x - origin.x, io.MousePos.y - origin.y);
241 static ImVec2 drag_start_pos;
242 const float scaled_size = tile_size * scale;
243 static bool dragging =
false;
244 constexpr int small_map_size = 0x200;
245 constexpr uint32_t kWhite = IM_COL32(255, 255, 255, 255);
252 if (current_map < 0x40) {
253 superY = current_map / 8;
254 superX = current_map % 8;
255 }
else if (current_map < 0x80) {
256 superY = (current_map - 0x40) / 8;
257 superX = (current_map - 0x40) % 8;
259 superY = (current_map - 0x80) / 8;
260 superX = (current_map - 0x80) % 8;
263 if (ImGui::IsMouseClicked(ImGuiMouseButton_Right)) {
264 ImVec2 painter_pos = AlignPosToGridHelper(mouse_pos, scaled_size);
265 int world_x =
static_cast<int>(painter_pos.x / scale);
266 int world_y =
static_cast<int>(painter_pos.y / scale);
268 auto tile16_x = (world_x % small_map_size) / (small_map_size / 0x20);
269 auto tile16_y = (world_y % small_map_size) / (small_map_size / 0x20);
271 int index_x = superX * 0x20 + tile16_x;
272 int index_y = superY * 0x20 + tile16_y;
274 ImVec2(
static_cast<float>(index_x),
static_cast<float>(index_y));
278 drag_start_pos = AlignPosToGridHelper(mouse_pos, scaled_size);
281 ImVec2 drag_end_pos = AlignPosToGridHelper(mouse_pos, scaled_size);
282 if (ImGui::IsMouseDragging(ImGuiMouseButton_Right)) {
284 ImVec2(origin.x + drag_start_pos.x, origin.y + drag_start_pos.y);
285 auto end = ImVec2(origin.x + drag_end_pos.x + scaled_size,
286 origin.y + drag_end_pos.y + scaled_size);
287 rt.
draw_list->AddRect(start, end, kWhite);
291 if (dragging && !ImGui::IsMouseDown(ImGuiMouseButton_Right)) {
294 constexpr int tile16_size = 16;
295 int start_x =
static_cast<int>(std::floor(drag_start_pos.x / scaled_size)) *
297 int start_y =
static_cast<int>(std::floor(drag_start_pos.y / scaled_size)) *
299 int end_x =
static_cast<int>(std::floor(drag_end_pos.x / scaled_size)) *
301 int end_y =
static_cast<int>(std::floor(drag_end_pos.y / scaled_size)) *
305 std::swap(start_x, end_x);
307 std::swap(start_y, end_y);
311 static_cast<size_t>(((end_x - start_x) / tile16_size + 1) *
312 ((end_y - start_y) / tile16_size + 1)));
314 constexpr int tiles_per_local_map = small_map_size / 16;
316 for (
int y = start_y; y <= end_y; y += tile16_size) {
317 for (
int x = start_x; x <= end_x; x += tile16_size) {
318 int local_map_x = (x / small_map_size) % 8;
319 int local_map_y = (y / small_map_size) % 8;
320 int tile16_x = (x % small_map_size) / tile16_size;
321 int tile16_y = (y % small_map_size) / tile16_size;
322 int index_x = local_map_x * tiles_per_local_map + tile16_x;
323 int index_y = local_map_y * tiles_per_local_map + tile16_y;
324 selection.
selected_tiles.emplace_back(
static_cast<float>(index_x),
325 static_cast<float>(index_y));
331 ImVec2(drag_start_pos.x / scale, drag_start_pos.y / scale));
333 ImVec2(drag_end_pos.x / scale, drag_end_pos.y / scale));