59 const gfx::Bitmap& bitmap, ImDrawList* draw_list, ImVec2 canvas_p0,
60 ImVec2 scrolling,
float global_scale,
float tile_size,
bool is_hovered) {
62 const ImGuiIO& imgui_io = ImGui::GetIO();
63 const ImVec2 origin(canvas_p0.x + scrolling.x, canvas_p0.y + scrolling.y);
64 const ImVec2 mouse_pos(imgui_io.MousePos.x - origin.x, imgui_io.MousePos.y - origin.y);
65 const auto scaled_size = tile_size * global_scale;
77 ImVec2 paint_pos = AlignToGrid(mouse_pos, scaled_size);
79 auto paint_pos_end = ImVec2(paint_pos.x + scaled_size, paint_pos.y + scaled_size);
87 (ImTextureID)(intptr_t)bitmap.
texture(),
88 ImVec2(origin.x + paint_pos.x, origin.y + paint_pos.y),
89 ImVec2(origin.x + paint_pos.x + scaled_size, origin.y + paint_pos.y + scaled_size));
93 if (ImGui::IsMouseClicked(ImGuiMouseButton_Left) &&
94 ImGui::IsMouseDragging(ImGuiMouseButton_Left)) {
103 gfx::Tilemap& tilemap,
int current_tile, ImDrawList* draw_list,
104 ImVec2 canvas_p0, ImVec2 scrolling,
float global_scale,
bool is_hovered) {
106 const ImGuiIO& imgui_io = ImGui::GetIO();
107 const ImVec2 origin(canvas_p0.x + scrolling.x, canvas_p0.y + scrolling.y);
108 const ImVec2 mouse_pos(imgui_io.MousePos.x - origin.x, imgui_io.MousePos.y - origin.y);
115 const auto scaled_size = tilemap.
tile_size.
x * global_scale;
124 ImVec2 paint_pos = AlignToGrid(mouse_pos, scaled_size);
128 hover_points_.push_back(ImVec2(paint_pos.x + scaled_size, paint_pos.y + scaled_size));
133 if (tiles_per_row > 0) {
134 int tile_x = (current_tile % tiles_per_row) * tilemap.
tile_size.
x;
135 int tile_y = (current_tile / tiles_per_row) * tilemap.
tile_size.
y;
137 if (tile_x >= 0 && tile_x < tilemap.
atlas.
width() &&
140 ImVec2 uv0 = ImVec2(
static_cast<float>(tile_x) / tilemap.
atlas.
width(),
141 static_cast<float>(tile_y) / tilemap.
atlas.
height());
147 ImVec2(origin.x + paint_pos.x, origin.y + paint_pos.y),
148 ImVec2(origin.x + paint_pos.x + scaled_size, origin.y + paint_pos.y + scaled_size),
154 if (ImGui::IsMouseClicked(ImGuiMouseButton_Left) ||
155 ImGui::IsMouseDragging(ImGuiMouseButton_Left)) {
164 const ImVec4& color, ImDrawList* draw_list, ImVec2 canvas_p0,
165 ImVec2 scrolling,
float global_scale,
float tile_size,
bool is_hovered) {
167 const ImGuiIO& imgui_io = ImGui::GetIO();
168 const ImVec2 origin(canvas_p0.x + scrolling.x, canvas_p0.y + scrolling.y);
169 const ImVec2 mouse_pos(imgui_io.MousePos.x - origin.x, imgui_io.MousePos.y - origin.y);
170 auto scaled_tile_size = tile_size * global_scale;
171 static bool is_dragging =
false;
172 static ImVec2 start_drag_pos;
181 ImVec2 paint_pos = AlignToGrid(mouse_pos, scaled_tile_size);
188 hover_points_.push_back(ImVec2(paint_pos.x + scaled_tile_size, paint_pos.y + scaled_tile_size));
191 draw_list->AddRectFilled(
192 ImVec2(origin.x + paint_pos.x + 1, origin.y + paint_pos.y + 1),
193 ImVec2(origin.x + paint_pos.x + scaled_tile_size,
194 origin.y + paint_pos.y + scaled_tile_size),
195 IM_COL32(color.x * 255, color.y * 255, color.z * 255, 255));
198 if (ImGui::IsMouseClicked(ImGuiMouseButton_Left)) {
200 start_drag_pos = paint_pos;
203 if (is_dragging && ImGui::IsMouseReleased(ImGuiMouseButton_Left)) {
213 ImDrawList* , ImVec2 canvas_p0, ImVec2 scrolling,
float tile_size,
216 const ImGuiIO& imgui_io = ImGui::GetIO();
217 const ImVec2 origin(canvas_p0.x + scrolling.x, canvas_p0.y + scrolling.y);
218 const ImVec2 mouse_pos(imgui_io.MousePos.x - origin.x, imgui_io.MousePos.y - origin.y);
220 if (is_hovered && ImGui::IsMouseClicked(ImGuiMouseButton_Left)) {
222 ImVec2 painter_pos = AlignToGrid(mouse_pos, tile_size);
225 hover_points_.push_back(ImVec2(painter_pos.x + tile_size, painter_pos.y + tile_size));
229 if (is_hovered && ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left)) {
237 int current_map, ImDrawList* draw_list, ImVec2 canvas_p0, ImVec2 scrolling,
238 float global_scale,
float tile_size,
bool is_hovered) {
240 const ImGuiIO& imgui_io = ImGui::GetIO();
241 const ImVec2 origin(canvas_p0.x + scrolling.x, canvas_p0.y + scrolling.y);
242 const ImVec2 mouse_pos(imgui_io.MousePos.x - origin.x, imgui_io.MousePos.y - origin.y);
243 const float scaled_size = tile_size * global_scale;
244 static ImVec2 drag_start_pos;
245 static bool dragging =
false;
246 constexpr int small_map_size = 0x200;
255 if (current_map < 0x40) {
256 super_y = current_map / 8;
257 super_x = current_map % 8;
258 }
else if (current_map < 0x80) {
259 super_y = (current_map - 0x40) / 8;
260 super_x = (current_map - 0x40) % 8;
262 super_y = (current_map - 0x80) / 8;
263 super_x = (current_map - 0x80) % 8;
267 if (ImGui::IsMouseClicked(ImGuiMouseButton_Right)) {
268 ImVec2 painter_pos = AlignToGrid(mouse_pos, scaled_size);
269 int painter_x = painter_pos.x;
270 int painter_y = painter_pos.y;
272 auto tile16_x = (painter_x % small_map_size) / (small_map_size / 0x20);
273 auto tile16_y = (painter_y % small_map_size) / (small_map_size / 0x20);
275 int index_x = super_x * 0x20 + tile16_x;
276 int index_y = super_y * 0x20 + tile16_y;
281 drag_start_pos = AlignToGrid(mouse_pos, scaled_size);
285 ImVec2 drag_end_pos = AlignToGrid(mouse_pos, scaled_size);
286 if (ImGui::IsMouseDragging(ImGuiMouseButton_Right) && draw_list) {
287 auto start = ImVec2(canvas_p0.x + drag_start_pos.x,
288 canvas_p0.y + drag_start_pos.y);
289 auto end = ImVec2(canvas_p0.x + drag_end_pos.x + tile_size,
290 canvas_p0.y + drag_end_pos.y + tile_size);
291 draw_list->AddRect(start, end, IM_COL32(255, 255, 255, 255));
296 if (dragging && !ImGui::IsMouseDown(ImGuiMouseButton_Right)) {
299 constexpr int tile16_size = 16;
300 int start_x = std::floor(drag_start_pos.x / scaled_size) * tile16_size;
301 int start_y = std::floor(drag_start_pos.y / scaled_size) * tile16_size;
302 int end_x = std::floor(drag_end_pos.x / scaled_size) * tile16_size;
303 int end_y = std::floor(drag_end_pos.y / scaled_size) * tile16_size;
305 if (start_x > end_x) std::swap(start_x, end_x);
306 if (start_y > end_y) std::swap(start_y, end_y);
310 ((end_y - start_y) / tile16_size + 1));
312 constexpr int tiles_per_local_map = small_map_size / 16;
314 for (
int tile_y = start_y; tile_y <= end_y; tile_y += tile16_size) {
315 for (
int tile_x = start_x; tile_x <= end_x; tile_x += tile16_size) {
316 int local_map_x = tile_x / small_map_size;
317 int local_map_y = tile_y / small_map_size;
319 int tile16_x = (tile_x % small_map_size) / tile16_size;
320 int tile16_y = (tile_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;