1 | // Aseprite |
2 | // Copyright (C) 2019-2022 Igara Studio S.A. |
3 | // Copyright (C) 2001-2016 David Capello |
4 | // |
5 | // This program is distributed under the terms of |
6 | // the End-User License Agreement for Aseprite. |
7 | |
8 | #ifdef HAVE_CONFIG_H |
9 | #include "config.h" |
10 | #endif |
11 | |
12 | #include "app/ui/tag_window.h" |
13 | |
14 | #include "app/doc.h" |
15 | #include "app/pref/preferences.h" |
16 | #include "app/ui/layer_frame_comboboxes.h" |
17 | #include "app/ui/user_data_view.h" |
18 | #include "doc/sprite.h" |
19 | #include "doc/tag.h" |
20 | #include "ui/manager.h" |
21 | |
22 | #include <algorithm> |
23 | |
24 | namespace app { |
25 | |
26 | TagWindow::TagWindow(const doc::Sprite* sprite, const doc::Tag* tag) |
27 | : m_sprite(sprite) |
28 | , m_base(Preferences::instance().document( |
29 | static_cast<Doc*>(sprite->document())).timeline.firstFrame()) |
30 | , m_userData(tag->userData()) |
31 | , m_userDataView(Preferences::instance().tags.userDataVisibility) |
32 | { |
33 | m_userDataView.configureAndSet(m_userData, propertiesGrid()); |
34 | |
35 | name()->setText(tag->name()); |
36 | from()->setTextf("%d" , tag->fromFrame()+m_base); |
37 | to()->setTextf("%d" , tag->toFrame()+m_base); |
38 | |
39 | fill_anidir_combobox(anidir(), tag->aniDir()); |
40 | userData()->Click.connect([this]{ onToggleUserData(); }); |
41 | } |
42 | |
43 | bool TagWindow::show() |
44 | { |
45 | openWindowInForeground(); |
46 | return (closer() == ok()); |
47 | } |
48 | |
49 | std::string TagWindow::nameValue() |
50 | { |
51 | return name()->text(); |
52 | } |
53 | |
54 | void TagWindow::rangeValue(doc::frame_t& from, doc::frame_t& to) |
55 | { |
56 | doc::frame_t first = 0; |
57 | doc::frame_t last = m_sprite->lastFrame(); |
58 | |
59 | from = this->from()->textInt()-m_base; |
60 | to = this->to()->textInt()-m_base; |
61 | from = std::clamp(from, first, last); |
62 | to = std::clamp(to, from, last); |
63 | } |
64 | |
65 | doc::AniDir TagWindow::aniDirValue() |
66 | { |
67 | return (doc::AniDir)anidir()->getSelectedItemIndex(); |
68 | } |
69 | |
70 | void TagWindow::onToggleUserData() |
71 | { |
72 | m_userDataView.toggleVisibility(); |
73 | remapWindow(); |
74 | manager()->invalidate(); |
75 | } |
76 | |
77 | } // namespace app |
78 | |