151 int current_tile, ImVec2* out_drawn_pos) {
155 const ImGuiIO& io = ImGui::GetIO();
158 const ImVec2 mouse_pos(io.MousePos.x - origin.x, io.MousePos.y - origin.y);
170 ImVec2 paint_pos = AlignPosToGridHelper(mouse_pos, scaled_size);
174 if (tiles_per_row > 0) {
175 int tile_x = (current_tile % tiles_per_row) * tilemap.
tile_size.
x;
176 int tile_y = (current_tile / tiles_per_row) * tilemap.
tile_size.
y;
178 if (tile_x >= 0 && tile_x < tilemap.
atlas.
width() && tile_y >= 0 &&
181 ImVec2(
static_cast<float>(tile_x) / tilemap.
atlas.
width(),
182 static_cast<float>(tile_y) / tilemap.
atlas.
height());
183 ImVec2 uv1 = ImVec2(
static_cast<float>(tile_x + tilemap.
tile_size.
x) /
185 static_cast<float>(tile_y + tilemap.
tile_size.
y) /
191 ImVec2(origin.x + paint_pos.x, origin.y + paint_pos.y),
192 ImVec2(origin.x + paint_pos.x + scaled_size,
193 origin.y + paint_pos.y + scaled_size),
194 uv0, uv1, ImGui::GetColorU32(ImVec4(1, 1, 1, 1)));
199 if (ImGui::IsMouseClicked(ImGuiMouseButton_Left) ||
200 ImGui::IsMouseDragging(ImGuiMouseButton_Left)) {
202 *out_drawn_pos = paint_pos;
239 const ImGuiIO& io = ImGui::GetIO();
242 const ImVec2 mouse_pos(io.MousePos.x - origin.x, io.MousePos.y - origin.y);
243 static ImVec2 drag_start_pos;
244 const float scaled_size = tile_size * scale;
245 static bool dragging =
false;
246 constexpr int small_map_size = 0x200;
247 constexpr uint32_t kWhite = IM_COL32(255, 255, 255, 255);
254 if (current_map < 0x40) {
255 superY = current_map / 8;
256 superX = current_map % 8;
257 }
else if (current_map < 0x80) {
258 superY = (current_map - 0x40) / 8;
259 superX = (current_map - 0x40) % 8;
261 superY = (current_map - 0x80) / 8;
262 superX = (current_map - 0x80) % 8;
265 if (ImGui::IsMouseClicked(ImGuiMouseButton_Right)) {
266 ImVec2 painter_pos = AlignPosToGridHelper(mouse_pos, scaled_size);
267 int world_x =
static_cast<int>(painter_pos.x / scale);
268 int world_y =
static_cast<int>(painter_pos.y / scale);
270 auto tile16_x = (world_x % small_map_size) / (small_map_size / 0x20);
271 auto tile16_y = (world_y % small_map_size) / (small_map_size / 0x20);
273 int index_x = superX * 0x20 + tile16_x;
274 int index_y = superY * 0x20 + tile16_y;
276 ImVec2(
static_cast<float>(index_x),
static_cast<float>(index_y));
280 drag_start_pos = AlignPosToGridHelper(mouse_pos, scaled_size);
283 ImVec2 drag_end_pos = AlignPosToGridHelper(mouse_pos, scaled_size);
284 if (ImGui::IsMouseDragging(ImGuiMouseButton_Right)) {
287 const float min_x = std::min(drag_start_pos.x, drag_end_pos.x);
288 const float min_y = std::min(drag_start_pos.y, drag_end_pos.y);
289 const float max_x = std::max(drag_start_pos.x, drag_end_pos.x);
290 const float max_y = std::max(drag_start_pos.y, drag_end_pos.y);
291 auto start = ImVec2(origin.x + min_x, origin.y + min_y);
293 ImVec2(origin.x + max_x + scaled_size, origin.y + max_y + scaled_size);
294 rt.
draw_list->AddRect(start, end, kWhite);
298 if (dragging && !ImGui::IsMouseDown(ImGuiMouseButton_Right)) {
301 constexpr int tile16_size = 16;
302 int start_x =
static_cast<int>(std::floor(drag_start_pos.x / scaled_size)) *
304 int start_y =
static_cast<int>(std::floor(drag_start_pos.y / scaled_size)) *
306 int end_x =
static_cast<int>(std::floor(drag_end_pos.x / scaled_size)) *
308 int end_y =
static_cast<int>(std::floor(drag_end_pos.y / scaled_size)) *
312 std::swap(start_x, end_x);
314 std::swap(start_y, end_y);
318 static_cast<size_t>(((end_x - start_x) / tile16_size + 1) *
319 ((end_y - start_y) / tile16_size + 1)));
321 constexpr int tiles_per_local_map = small_map_size / 16;
323 for (
int y = start_y; y <= end_y; y += tile16_size) {
324 for (
int x = start_x; x <= end_x; x += tile16_size) {
325 int local_map_x = (x / small_map_size) % 8;
326 int local_map_y = (y / small_map_size) % 8;
327 int tile16_x = (x % small_map_size) / tile16_size;
328 int tile16_y = (y % small_map_size) / tile16_size;
329 int index_x = local_map_x * tiles_per_local_map + tile16_x;
330 int index_y = local_map_y * tiles_per_local_map + tile16_y;
331 selection.
selected_tiles.emplace_back(
static_cast<float>(index_x),
332 static_cast<float>(index_y));
338 ImVec2(drag_start_pos.x / scale, drag_start_pos.y / scale));
340 ImVec2(drag_end_pos.x / scale, drag_end_pos.y / scale));