52 int room_min_x,
int room_min_y,
int room_max_x,
int room_max_y,
53 const std::vector<zelda3::RoomObject>& objects,
SelectionMode mode) {
55 int min_x = std::min(room_min_x, room_max_x);
56 int max_x = std::max(room_min_x, room_max_x);
57 int min_y = std::min(room_min_y, room_max_y);
58 int max_y = std::max(room_min_y, room_max_y);
66 for (
size_t i = 0; i < objects.size(); ++i) {
207 gui::Canvas* canvas,
const std::vector<zelda3::RoomObject>& objects,
214 ImDrawList* draw_list = ImGui::GetWindowDrawList();
219 if (index >= objects.size()) {
223 const auto&
object = objects[index];
231 int pixel_height = 0;
232 if (bounds_calculator) {
233 auto [dx, dy, w, h] = bounds_calculator(
object);
240 auto [tile_x, tile_y, tile_width, tile_height] =
GetObjectBounds(
object);
241 offset_x = (tile_x -
object.x_) * 8;
242 offset_y = (tile_y -
object.y_) * 8;
243 pixel_width = tile_width * 8;
244 pixel_height = tile_height * 8;
251 ImVec2 obj_start(canvas_pos.x + obj_x * scale,
252 canvas_pos.y + obj_y * scale);
253 ImVec2 obj_end(obj_start.x + pixel_width * scale,
254 obj_start.y + pixel_height * scale);
257 constexpr float margin = 2.0f;
258 obj_start.x -= margin;
259 obj_start.y -= margin;
268 0.6f + 0.4f * std::sin(
static_cast<float>(ImGui::GetTime()) * 6.0f);
269 ImVec4 pulsing_color = theme.selection_primary;
270 pulsing_color.w = 0.4f + 0.4f * pulse;
272 ImU32 border_color = ImGui::GetColorU32(theme.selection_primary);
273 ImU32 pulse_color_u32 = ImGui::GetColorU32(pulsing_color);
275 draw_list->AddRect(obj_start, obj_end, border_color, 0.0f, 0, 2.0f);
276 draw_list->AddRect(obj_start, obj_end, pulse_color_u32, 0.0f, 0, 4.0f);
279 float handle_size = 6.0f * std::max(1.0f, scale * 0.5f);
280 ImU32 handle_color = ImGui::GetColorU32(theme.selection_handle);
281 ImU32 handle_outline = ImGui::GetColorU32(ImVec4(0, 0, 0, 0.8f));
283 auto draw_handle = [&](ImVec2 pos) {
284 draw_list->AddRectFilled(
285 ImVec2(pos.x - handle_size / 2, pos.y - handle_size / 2),
286 ImVec2(pos.x + handle_size / 2, pos.y + handle_size / 2),
289 ImVec2(pos.x - handle_size / 2, pos.y - handle_size / 2),
290 ImVec2(pos.x + handle_size / 2, pos.y + handle_size / 2),
291 handle_outline, 2.0f, 0, 1.0f);
294 draw_handle(obj_start);
295 draw_handle(ImVec2(obj_end.x, obj_start.y));
296 draw_handle(ImVec2(obj_start.x, obj_end.y));
297 draw_handle(obj_end);
319 ImDrawList* draw_list = ImGui::GetWindowDrawList();
327 ImVec2 box_start(canvas_pos.x + min_x * scale, canvas_pos.y + min_y * scale);
328 ImVec2 box_end(canvas_pos.x + max_x * scale, canvas_pos.y + max_y * scale);
332 ImU32 border_color = ImGui::ColorConvertFloat4ToU32(
333 ImVec4(theme.selection_secondary.x, theme.selection_secondary.y, theme.selection_secondary.z,
336 ImU32 fill_color = ImGui::ColorConvertFloat4ToU32(
337 ImVec4(theme.selection_secondary.x, theme.selection_secondary.y, theme.selection_secondary.z,
340 draw_list->AddRectFilled(box_start, box_end, fill_color);
341 draw_list->AddRect(box_start, box_end, border_color, 0.0f, 0, 2.0f);
void DrawSelectionHighlights(gui::Canvas *canvas, const std::vector< zelda3::RoomObject > &objects, std::function< std::tuple< int, int, int, int >(const zelda3::RoomObject &)> bounds_calculator)
Draw selection highlights for all selected objects.
void SelectObjectsInRect(int room_min_x, int room_min_y, int room_max_x, int room_max_y, const std::vector< zelda3::RoomObject > &objects, SelectionMode mode=SelectionMode::Single)
Select multiple objects within a rectangle.