Format like smack-a-brother, and write comments as sentences
Four-space indents, braces on their own lines, and one-statement bodies without braces. Semicolons in comments became full stops. Designated initializers may leave fields out without a warning.
This commit is contained in:
1 parent
40f6b554b5
commit
7afdf709c3
176 files changed
+20500
-19048
No files matched your search
+159
-145
@@ -1,13 +1,13 @@
|
||||
#include "ui/timeline_context.h"
|
||||
|
||||
constexpr StringType FRAME_PROPERTY_LABELS[] = {
|
||||
BASIC_POSITION, BASIC_SCALE, BASIC_ROTATION, BASIC_SKEW, BASIC_PIVOT, BASIC_CROP, BASIC_SIZE,
|
||||
BASIC_REGION, BASIC_TINT, BASIC_COLOR_OFFSET, BASIC_VISIBLE, BASIC_INTERPOLATED, BASIC_DURATION, BASIC_SHADER,
|
||||
BASIC_DEPTH, BASIC_BLUR, LABEL_CHILD, LABEL_EVENTS, LABEL_SOUNDS};
|
||||
static_assert(std::size(FRAME_PROPERTY_LABELS) == (std::size_t)FrameProperty::COUNT);
|
||||
constexpr StringType FRAME_PROPERTY_LABELS[] = {
|
||||
BASIC_POSITION, BASIC_SCALE, BASIC_ROTATION, BASIC_SKEW, BASIC_PIVOT, BASIC_CROP, BASIC_SIZE,
|
||||
BASIC_REGION, BASIC_TINT, BASIC_COLOR_OFFSET, BASIC_VISIBLE, BASIC_INTERPOLATED, BASIC_DURATION, BASIC_SHADER,
|
||||
BASIC_DEPTH, BASIC_BLUR, LABEL_CHILD, LABEL_EVENTS, LABEL_SOUNDS};
|
||||
static_assert(std::size(FRAME_PROPERTY_LABELS) == (std::size_t)FrameProperty::COUNT);
|
||||
|
||||
void TimelineContext::frame_begin()
|
||||
{
|
||||
void TimelineContext::frame_begin()
|
||||
{
|
||||
iconTintDefault = isLightTheme ? ICON_TINT_DEFAULT_LIGHT : ICON_TINT_DEFAULT_DARK;
|
||||
itemIconTint = isLightTheme ? ICON_TINT_DEFAULT_LIGHT : iconTintDefault;
|
||||
frameBorderColor = isLightTheme ? FRAME_BORDER_COLOR_LIGHT : FRAME_BORDER_COLOR_DARK;
|
||||
@@ -22,59 +22,70 @@
|
||||
timelinePlayheadRectColor = isLightTheme ? TIMELINE_PLAYHEAD_RECT_COLOR_LIGHT : TIMELINE_PLAYHEAD_RECT_COLOR_DARK;
|
||||
timelineTickColor = isLightTheme ? TIMELINE_TICK_COLOR_LIGHT : frameBorderColor;
|
||||
itemTextColor = isLightTheme ? ITEM_TEXT_COLOR_LIGHT : ITEM_TEXT_COLOR_DARK;
|
||||
}
|
||||
}
|
||||
|
||||
void TimelineContext::overlay_icon(GLuint textureId, ImVec4 tint, bool isForced)
|
||||
{
|
||||
if (!isForced && !isLightTheme) return;
|
||||
void TimelineContext::overlay_icon(GLuint textureId, ImVec4 tint, bool isForced)
|
||||
{
|
||||
if (!isForced && !isLightTheme)
|
||||
return;
|
||||
auto min = ImGui::GetItemRectMin();
|
||||
auto max = ImGui::GetItemRectMax();
|
||||
ImGui::GetWindowDrawList()->AddImage((ImTextureID)(intptr_t)textureId, min, max, ImVec2(0, 0), ImVec2(1, 1),
|
||||
ImGui::GetColorU32(tint));
|
||||
}
|
||||
}
|
||||
|
||||
void TimelineContext::playback_stop()
|
||||
{
|
||||
void TimelineContext::playback_stop()
|
||||
{
|
||||
playback.isPlaying = false;
|
||||
playback.isFinished = false;
|
||||
playback.timing_reset();
|
||||
}
|
||||
}
|
||||
|
||||
void TimelineContext::context_menu()
|
||||
{
|
||||
void TimelineContext::context_menu()
|
||||
{
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, style.WindowPadding);
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, style.ItemSpacing);
|
||||
|
||||
if (shortcut(manager.chords[SHORTCUT_CUT], SCOPE_FOCUSED)) cut();
|
||||
if (shortcut(manager.chords[SHORTCUT_COPY], SCOPE_FOCUSED)) copy();
|
||||
if (shortcut(manager.chords[SHORTCUT_PASTE], SCOPE_FOCUSED)) paste();
|
||||
if (shortcut(manager.chords[SHORTCUT_SPLIT], SCOPE_FOCUSED)) frame_split();
|
||||
if (shortcut(manager.chords[SHORTCUT_BAKE], SCOPE_FOCUSED)) frames_bake();
|
||||
if (shortcut(manager.chords[SHORTCUT_FIT], SCOPE_FOCUSED)) fit_animation_length();
|
||||
if (shortcut(manager.chords[SHORTCUT_CUT], SCOPE_FOCUSED))
|
||||
cut();
|
||||
if (shortcut(manager.chords[SHORTCUT_COPY], SCOPE_FOCUSED))
|
||||
copy();
|
||||
if (shortcut(manager.chords[SHORTCUT_PASTE], SCOPE_FOCUSED))
|
||||
paste();
|
||||
if (shortcut(manager.chords[SHORTCUT_SPLIT], SCOPE_FOCUSED))
|
||||
frame_split();
|
||||
if (shortcut(manager.chords[SHORTCUT_BAKE], SCOPE_FOCUSED))
|
||||
frames_bake();
|
||||
if (shortcut(manager.chords[SHORTCUT_FIT], SCOPE_FOCUSED))
|
||||
fit_animation_length();
|
||||
|
||||
auto make_region = [&]()
|
||||
{
|
||||
auto targetReference = reference;
|
||||
auto frame = frame_get();
|
||||
if (!frame || targetReference.itemType != LAYER || targetReference.itemID == -1) return;
|
||||
if (frame->regionId != -1) return;
|
||||
auto layer = ::item_get(model.content.layers, targetReference.itemID);
|
||||
if (!layer) return;
|
||||
auto make_region = [&]() {
|
||||
auto targetReference = reference;
|
||||
auto frame = frame_get();
|
||||
if (!frame || targetReference.itemType != LAYER || targetReference.itemID == -1)
|
||||
return;
|
||||
if (frame->regionId != -1)
|
||||
return;
|
||||
auto layer = ::item_get(model.content.layers, targetReference.itemID);
|
||||
if (!layer)
|
||||
return;
|
||||
|
||||
auto spritesheetID = layer->spritesheetId;
|
||||
if (!::item_get(model.content.spritesheets, spritesheetID)) return;
|
||||
auto spritesheetID = layer->spritesheetId;
|
||||
if (!::item_get(model.content.spritesheets, spritesheetID))
|
||||
return;
|
||||
|
||||
auto settingsPtr = &settings;
|
||||
command_push(
|
||||
[=, this](Manager& manager, Document& document)
|
||||
{
|
||||
auto settingsPtr = &settings;
|
||||
command_push([=, this](Manager& manager, Document& document) {
|
||||
auto frame = document.model.frame_get(targetReference);
|
||||
if (!frame || frame->regionId != -1) return;
|
||||
if (!frame || frame->regionId != -1)
|
||||
return;
|
||||
auto layer = ::item_get(document.model.content.layers, targetReference.itemID);
|
||||
if (!layer) return;
|
||||
if (!layer)
|
||||
return;
|
||||
|
||||
auto spritesheetID = layer->spritesheetId;
|
||||
if (!::item_get(document.model.content.spritesheets, spritesheetID)) return;
|
||||
if (!::item_get(document.model.content.spritesheets, spritesheetID))
|
||||
return;
|
||||
|
||||
Region region = {.crop = frame->crop, .size = frame->size, .pivot = frame->pivot};
|
||||
|
||||
@@ -83,7 +94,7 @@
|
||||
manager.makeRegionSpritesheetId = spritesheetID;
|
||||
manager.makeRegion = region;
|
||||
manager.isMakeRegionRequested = true;
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
auto item = selected_item_get();
|
||||
@@ -92,13 +103,12 @@
|
||||
auto selectedBakeFrames = selectedFrames;
|
||||
std::erase_if(selectedBakeFrames, is_trigger_reference);
|
||||
auto isReverseFrames = is_frames_reverse_available(selectedFrames);
|
||||
auto is_region_makeable = [&](const Reference& frameReference)
|
||||
{
|
||||
if (frameReference.itemType != LAYER || frameReference.frameIndex < 0) return false;
|
||||
auto frame = document.model.frame_get(frameReference);
|
||||
auto layer = ::item_get(model.content.layers, frameReference.itemID);
|
||||
return frame && frame->regionId == -1 && layer &&
|
||||
::item_get(model.content.spritesheets, layer->spritesheetId);
|
||||
auto is_region_makeable = [&](const Reference& frameReference) {
|
||||
if (frameReference.itemType != LAYER || frameReference.frameIndex < 0)
|
||||
return false;
|
||||
auto frame = document.model.frame_get(frameReference);
|
||||
auto layer = ::item_get(model.content.layers, frameReference.itemID);
|
||||
return frame && frame->regionId == -1 && layer && ::item_get(model.content.spritesheets, layer->spritesheetId);
|
||||
};
|
||||
auto selectedRegionFrames = selectedFrames;
|
||||
std::erase_if(selectedRegionFrames,
|
||||
@@ -132,22 +142,21 @@
|
||||
.shortcut = -1,
|
||||
.isEnabled = [=, this]() { return !selectedRootFrames.empty(); },
|
||||
.run = [&]() { bakeIntoOtherFramesPopup.open(); }});
|
||||
actions.add(
|
||||
{.label = LABEL_FIT_ANIMATION_LENGTH,
|
||||
.shortcut = SHORTCUT_FIT,
|
||||
.isEnabled = [&]() { return animation && animation->frameNum != animation_length_get(*animation); },
|
||||
.run = [&]() { fit_animation_length(); }});
|
||||
actions.add({.label = LABEL_FIT_ANIMATION_LENGTH,
|
||||
.shortcut = SHORTCUT_FIT,
|
||||
.isEnabled = [&]() { return animation && animation->frameNum != animation_length_get(*animation); },
|
||||
.run = [&]() { fit_animation_length(); }});
|
||||
actions.separator();
|
||||
actions.add({.label = isMakeManyRegions ? LABEL_MAKE_MANY_REGIONS : LABEL_MAKE_REGION,
|
||||
.shortcut = -1,
|
||||
.isEnabled = [=, this]() { return isMakeManyRegions || isMakeRegion; },
|
||||
.run =
|
||||
[&]()
|
||||
{
|
||||
if (!isMakeManyRegions) return make_region();
|
||||
makeManyRegionReferences = selectedRegionFrames;
|
||||
makeManyRegionsPopup.open();
|
||||
}});
|
||||
[&]() {
|
||||
if (!isMakeManyRegions)
|
||||
return make_region();
|
||||
makeManyRegionReferences = selectedRegionFrames;
|
||||
makeManyRegionsPopup.open();
|
||||
}});
|
||||
actions.separator();
|
||||
actions.add({.label = LABEL_DELETE,
|
||||
.shortcut = SHORTCUT_REMOVE,
|
||||
@@ -160,33 +169,35 @@
|
||||
auto clipboardFrame = property_clipboard_frame_get();
|
||||
// A submenu of the properties a frame type has.
|
||||
auto properties_get = [&](int itemType, std::function<bool(FrameProperty)> is_property_enabled,
|
||||
std::function<void(FrameProperty)> property_run)
|
||||
{
|
||||
Action properties = {.label = LABEL_PROPERTY};
|
||||
for (int i = 0; i < (int)FrameProperty::COUNT; ++i)
|
||||
{
|
||||
auto property = (FrameProperty)i;
|
||||
if (!is_frame_property_valid(property, (ItemType)itemType)) continue;
|
||||
properties.children.push_back({.label = FRAME_PROPERTY_LABELS[i],
|
||||
.isEnabled = [=]() { return is_property_enabled(property); },
|
||||
.run = [=]() { property_run(property); }});
|
||||
}
|
||||
properties.isEnabled = [children = properties.children]()
|
||||
{ return std::ranges::any_of(children, is_action_enabled); };
|
||||
return properties;
|
||||
std::function<void(FrameProperty)> property_run) {
|
||||
Action properties = {.label = LABEL_PROPERTY};
|
||||
for (int i = 0; i < (int)FrameProperty::COUNT; ++i)
|
||||
{
|
||||
auto property = (FrameProperty)i;
|
||||
if (!is_frame_property_valid(property, (ItemType)itemType))
|
||||
continue;
|
||||
properties.children.push_back({.label = FRAME_PROPERTY_LABELS[i],
|
||||
.isEnabled = [=]() { return is_property_enabled(property); },
|
||||
.run = [=]() { property_run(property); }});
|
||||
}
|
||||
properties.isEnabled = [children = properties.children]() {
|
||||
return std::ranges::any_of(children, is_action_enabled);
|
||||
};
|
||||
return properties;
|
||||
};
|
||||
auto clipboard_menu_add =
|
||||
[&](ActionType type, std::function<bool()> isFrameEnabled, std::function<void()> frameRun, Action property)
|
||||
{
|
||||
actions.add({.label = ACTION_INFOS[type].label,
|
||||
.children = {{.label = BASIC_FRAME,
|
||||
.shortcut = ACTION_INFOS[type].shortcut,
|
||||
.isEnabled = isFrameEnabled,
|
||||
.run = frameRun},
|
||||
property}});
|
||||
auto clipboard_menu_add = [&](ActionType type, std::function<bool()> isFrameEnabled, std::function<void()> frameRun,
|
||||
Action property) {
|
||||
actions.add({.label = ACTION_INFOS[type].label,
|
||||
.children = {{.label = BASIC_FRAME,
|
||||
.shortcut = ACTION_INFOS[type].shortcut,
|
||||
.isEnabled = isFrameEnabled,
|
||||
.run = frameRun},
|
||||
property}});
|
||||
};
|
||||
auto sourceType = source ? source->itemType : NONE;
|
||||
auto is_source = [=](FrameProperty) { return sourceFrame != nullptr; };
|
||||
auto is_source = [=](FrameProperty) {
|
||||
return sourceFrame != nullptr;
|
||||
};
|
||||
clipboard_menu_add(
|
||||
ACTION_CUT, [=, this]() { return !selectedFrames.empty(); }, [this]() { cut(); },
|
||||
properties_get(sourceType, is_source, [this](FrameProperty property) { property_cut(property); }));
|
||||
@@ -198,72 +209,74 @@
|
||||
clipboard_menu_add(
|
||||
ACTION_PASTE, [&]() { return !clipboard.is_empty(); }, [this]() { paste(); },
|
||||
{.label = LABEL_PROPERTY,
|
||||
.isEnabled = [=, this]()
|
||||
{ return clipboardFrame && frameClipboard.property != -1 && is_property_pasteable(clipboardProperty); },
|
||||
.isEnabled =
|
||||
[=, this]() {
|
||||
return clipboardFrame && frameClipboard.property != -1 && is_property_pasteable(clipboardProperty);
|
||||
},
|
||||
.run = [=, this]() { property_paste(clipboardProperty); }});
|
||||
// The numbered row has its own (marker) menu.
|
||||
if (isRulerHovered)
|
||||
actions_popup_draw("##Context Menu", actions, settings);
|
||||
actions_popup_draw("##Context Menu", actions, settings);
|
||||
else
|
||||
actions_context_window_draw("##Context Menu", actions, settings, ImGuiPopupFlags_MouseButtonRight,
|
||||
ImGuiHoveredFlags_ChildWindows);
|
||||
actions_context_window_draw("##Context Menu", actions, settings, ImGuiPopupFlags_MouseButtonRight,
|
||||
ImGuiHoveredFlags_ChildWindows);
|
||||
|
||||
ImGui::PopStyleVar(2);
|
||||
}
|
||||
}
|
||||
|
||||
void TimelineContext::item_base_properties_open(int type, int id)
|
||||
{
|
||||
void TimelineContext::item_base_properties_open(int type, int id)
|
||||
{
|
||||
manager.item_properties_open(type == LAYER ? ElementType::LAYER_ELEMENT : ElementType::NULL_ELEMENT, id);
|
||||
}
|
||||
}
|
||||
|
||||
void TimelineContext::group_properties_open(const TimelineRow& row, const TrackGroup& group)
|
||||
{
|
||||
void TimelineContext::group_properties_open(const TimelineRow& row, const TrackGroup& group)
|
||||
{
|
||||
groupName = group.name.empty() ? std::string(localize.get(TEXT_NEW_GROUP)) : group.name;
|
||||
groupAnimationIndex = reference.animationIndex;
|
||||
groupType = row.type;
|
||||
groupId = row.id;
|
||||
groupPropertiesPopup.open();
|
||||
}
|
||||
}
|
||||
|
||||
void TimelineContext::group_properties_update()
|
||||
{
|
||||
void TimelineContext::group_properties_update()
|
||||
{
|
||||
groupPropertiesPopup.trigger();
|
||||
|
||||
if (ImGui::BeginPopupModal(groupPropertiesPopup.label(), &groupPropertiesPopup.isOpen, ImGuiWindowFlags_NoResize))
|
||||
{
|
||||
auto childSize = child_size_get(1);
|
||||
if (ImGui::BeginChild("##Group Properties Child", childSize, ImGuiChildFlags_Borders))
|
||||
{
|
||||
if (groupPropertiesPopup.isJustOpened) ImGui::SetKeyboardFocusHere();
|
||||
input_text_string(localize.get(BASIC_NAME), &groupName);
|
||||
ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_ITEM_NAME));
|
||||
}
|
||||
ImGui::EndChild();
|
||||
auto childSize = child_size_get(1);
|
||||
if (ImGui::BeginChild("##Group Properties Child", childSize, ImGuiChildFlags_Borders))
|
||||
{
|
||||
if (groupPropertiesPopup.isJustOpened)
|
||||
ImGui::SetKeyboardFocusHere();
|
||||
input_text_string(localize.get(BASIC_NAME), &groupName);
|
||||
ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_ITEM_NAME));
|
||||
}
|
||||
ImGui::EndChild();
|
||||
|
||||
auto result = popup_buttons_draw(manager, localize.get(BASIC_CONFIRM));
|
||||
if (result == PopupButton::CONFIRM)
|
||||
{
|
||||
auto targetName = groupName;
|
||||
auto targetAnimationIndex = groupAnimationIndex;
|
||||
auto targetType = groupType;
|
||||
auto targetId = groupId;
|
||||
edit_push(EDIT_RENAME_GROUP,
|
||||
[=](Model& model)
|
||||
{
|
||||
if (auto group = model.track_group_edit(targetAnimationIndex, targetType, targetId))
|
||||
group->name = targetName;
|
||||
});
|
||||
}
|
||||
if (result != PopupButton::NONE) groupPropertiesPopup.close();
|
||||
auto result = popup_buttons_draw(manager, localize.get(BASIC_CONFIRM));
|
||||
if (result == PopupButton::CONFIRM)
|
||||
{
|
||||
auto targetName = groupName;
|
||||
auto targetAnimationIndex = groupAnimationIndex;
|
||||
auto targetType = groupType;
|
||||
auto targetId = groupId;
|
||||
edit_push(EDIT_RENAME_GROUP, [=](Model& model) {
|
||||
if (auto group = model.track_group_edit(targetAnimationIndex, targetType, targetId))
|
||||
group->name = targetName;
|
||||
});
|
||||
}
|
||||
if (result != PopupButton::NONE)
|
||||
groupPropertiesPopup.close();
|
||||
|
||||
ImGui::EndPopup();
|
||||
ImGui::EndPopup();
|
||||
}
|
||||
|
||||
groupPropertiesPopup.end();
|
||||
}
|
||||
}
|
||||
|
||||
void TimelineContext::item_context_menu()
|
||||
{
|
||||
void TimelineContext::item_context_menu()
|
||||
{
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, style.WindowPadding);
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, style.ItemSpacing);
|
||||
|
||||
@@ -277,34 +290,33 @@
|
||||
const TrackGroup* selectedGroup = nullptr;
|
||||
if (selectedRows.size() == 1 && selectedRows.front().isGroup)
|
||||
{
|
||||
auto row = selectedRows.front();
|
||||
selectedGroupRow = row;
|
||||
selectedGroup = row_group_get(selectedGroupRow);
|
||||
auto row = selectedRows.front();
|
||||
selectedGroupRow = row;
|
||||
selectedGroup = row_group_get(selectedGroupRow);
|
||||
}
|
||||
auto isRemoveAvailable = std::ranges::any_of(selectedRows, [](const TimelineRow& row)
|
||||
{ return row.type == LAYER || row.type == NULL_; });
|
||||
auto item_cut = [&]()
|
||||
{
|
||||
if (copyFrames.empty() || !isRemoveAvailable) return;
|
||||
frame_references_copy(copyFrames);
|
||||
item_remove();
|
||||
auto isRemoveAvailable = std::ranges::any_of(
|
||||
selectedRows, [](const TimelineRow& row) { return row.type == LAYER || row.type == NULL_; });
|
||||
auto item_cut = [&]() {
|
||||
if (copyFrames.empty() || !isRemoveAvailable)
|
||||
return;
|
||||
frame_references_copy(copyFrames);
|
||||
item_remove();
|
||||
};
|
||||
|
||||
if (ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenOverlappedByWindow) &&
|
||||
ImGui::IsMouseClicked(ImGuiMouseButton_Right))
|
||||
ImGui::OpenPopup("##Items Context Menu");
|
||||
ImGui::OpenPopup("##Items Context Menu");
|
||||
|
||||
Actions actions = {};
|
||||
actions_undo_redo_add(actions, manager, document);
|
||||
actions.separator();
|
||||
actions.add(
|
||||
ACTION_PROPERTIES, [&]() { return selectedGroup || (item && (type == LAYER || type == NULL_)); },
|
||||
[&]()
|
||||
{
|
||||
if (selectedGroup)
|
||||
group_properties_open(selectedGroupRow, *selectedGroup);
|
||||
else
|
||||
item_base_properties_open(type, id);
|
||||
[&]() {
|
||||
if (selectedGroup)
|
||||
group_properties_open(selectedGroupRow, *selectedGroup);
|
||||
else
|
||||
item_base_properties_open(type, id);
|
||||
});
|
||||
actions.add(ACTION_ADD, [&]() { return animation; }, [&]() { itemProperties.open(); });
|
||||
actions.add(ACTION_REMOVE, [=, this]() { return isRemoveAvailable; }, [&]() { item_remove(); });
|
||||
@@ -314,10 +326,12 @@
|
||||
actions.add(ACTION_COPY, [=, this]() { return !copyFrames.empty(); }, [this]() { copy(); });
|
||||
actions.add(ACTION_PASTE, [&]() { return item && !clipboard.is_empty(); }, [this]() { paste(); });
|
||||
if (shortcut(manager.chords[SHORTCUT_CUT], SCOPE_FOCUSED) && !copyFrames.empty() && isRemoveAvailable)
|
||||
item_cut();
|
||||
if (shortcut(manager.chords[SHORTCUT_COPY], SCOPE_FOCUSED) && !copyFrames.empty()) copy();
|
||||
if (shortcut(manager.chords[SHORTCUT_PASTE], SCOPE_FOCUSED) && item && !clipboard.is_empty()) paste();
|
||||
item_cut();
|
||||
if (shortcut(manager.chords[SHORTCUT_COPY], SCOPE_FOCUSED) && !copyFrames.empty())
|
||||
copy();
|
||||
if (shortcut(manager.chords[SHORTCUT_PASTE], SCOPE_FOCUSED) && item && !clipboard.is_empty())
|
||||
paste();
|
||||
actions_popup_draw("##Items Context Menu", actions, settings);
|
||||
|
||||
ImGui::PopStyleVar(2);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user