diff --git a/src/ui/libraries.cpp b/src/ui/libraries.cpp index 0ee34ed..fce4872 100644 --- a/src/ui/libraries.cpp +++ b/src/ui/libraries.cpp @@ -92,8 +92,7 @@ void libraries_update(Panel& panel) [&](int id) { auto loaded = loaded_get(id); auto isValid = loaded && loaded->model.isValid; - auto& texture = resources.icons[isValid ? ICON_ANIMATION : ICON_NONE]; - return CardImage{.texture = &texture, .size = Vec2(texture.size), .isValid = isValid}; + return icon_card_get(resources, ICON_ANIMATION, isValid); }, .activate = open, .cardLines = LIBRARY_CARD_LINES}; diff --git a/src/ui/panel.h b/src/ui/panel.h index fdbc846..62c7aed 100644 --- a/src/ui/panel.h +++ b/src/ui/panel.h @@ -108,6 +108,13 @@ bool tooltip_begin(const PanelState&, bool = true); void tooltip_end(); void tooltip_name_draw(Resources&, const std::string&); void tooltip_image_draw(const CardImage&, const std::function&); + +// A card showing `icon` for a valid item, and the none icon for one that isn't. +inline CardImage icon_card_get(Resources& resources, Icon icon, bool isValid) +{ + auto& texture = resources.icons[isValid ? icon : ICON_NONE]; + return {.texture = &texture, .size = Vec2(texture.size), .isValid = isValid}; +} void directory_open(Dialog&, Document&, const std::filesystem::path&); std::filesystem::path asset_path_get(Document&, const std::filesystem::path&); // The confirm and cancel buttons that end a popup, side by side, on the confirm and cancel shortcuts. diff --git a/src/ui/sounds.cpp b/src/ui/sounds.cpp index 0246f52..5cbad48 100644 --- a/src/ui/sounds.cpp +++ b/src/ui/sounds.cpp @@ -97,8 +97,7 @@ void sounds_update(Panel& panel) [&](int id) { auto audio = document.sound_get(id); auto isValid = audio && audio->is_valid(); - auto& texture = resources.icons[isValid ? ICON_SOUND : ICON_NONE]; - return CardImage{.texture = &texture, .size = Vec2(texture.size), .isValid = isValid}; + return icon_card_get(resources, ICON_SOUND, isValid); }, .select = [&](int id) { diff --git a/src/ui/timeline_frames.cpp b/src/ui/timeline_frames.cpp index bf50564..0403bde 100644 --- a/src/ui/timeline_frames.cpp +++ b/src/ui/timeline_frames.cpp @@ -470,28 +470,23 @@ void TimelineContext::frame_child(const TimelineRow& row, int& index, float widt ImGui::PopStyleColor(4); - if (!isDraggedFrameActive && ImGui::IsItemHovered() && ImGui::IsMouseDown(ImGuiMouseButton_Left)) + if (!isDraggedFrameActive && ImGui::IsItemHovered() && ImGui::IsMouseDown(ImGuiMouseButton_Left) && + (type == TRIGGER || ImGui::IsKeyDown(ImGuiMod_Ctrl))) { - if (ImGui::IsMouseDown(ImGuiMouseButton_Left)) + isDraggedFrameActive = true; + draggedFrameReference = frameReference; + draggedFrameType = type; + draggedFrameStart = hoveredTime; + draggedFrameStartDurations.clear(); + if (type != TRIGGER) { - if (type == TRIGGER || ImGui::IsKeyDown(ImGuiMod_Ctrl)) - { - isDraggedFrameActive = true; - draggedFrameReference = frameReference; - draggedFrameType = type; - draggedFrameStart = hoveredTime; - if (type != TRIGGER) - draggedFrameStartDuration = frame.duration; - draggedFrameStartDurations.clear(); - if (type != TRIGGER) - for (auto selectedReference : drag_frame_references_get(frameReference)) - if (auto selectedFrame = document.model.frame_get(selectedReference)) - draggedFrameStartDurations.push_back( - {selectedReference, selectedFrame->duration}); - draggedFrameStartMouseX = ImGui::GetIO().MousePos.x; - draggedFrameWidth = frameSize.x; - } + draggedFrameStartDuration = frame.duration; + for (auto selectedReference : drag_frame_references_get(frameReference)) + if (auto selectedFrame = document.model.frame_get(selectedReference)) + draggedFrameStartDurations.push_back({selectedReference, selectedFrame->duration}); } + draggedFrameStartMouseX = ImGui::GetIO().MousePos.x; + draggedFrameWidth = frameSize.x; } if (type != TRIGGER)