1 | // Aseprite |
---|---|
2 | // Copyright (C) 2022 Igara Studio S.A. |
3 | // |
4 | // This program is distributed under the terms of |
5 | // the End-User License Agreement for Aseprite. |
6 | |
7 | #ifdef HAVE_CONFIG_H |
8 | #include "config.h" |
9 | #endif |
10 | |
11 | #include "app/ui/sampling_selector.h" |
12 | |
13 | #include "ui/listitem.h" |
14 | |
15 | namespace app { |
16 | |
17 | using namespace ui; |
18 | |
19 | SamplingSelector::SamplingSelector(Behavior behavior) |
20 | : m_behavior(behavior) |
21 | , m_downsamplingLabel("Downsampling:") |
22 | { |
23 | addChild(&m_downsamplingLabel); |
24 | addChild(&m_downsampling); |
25 | |
26 | m_downsampling.addItem(new ListItem("Nearest")); |
27 | m_downsampling.addItem(new ListItem("Bilinear")); |
28 | m_downsampling.addItem(new ListItem("Bilinear mipmapping")); |
29 | m_downsampling.addItem(new ListItem("Trilinear mipmapping")); |
30 | m_downsampling.setSelectedItemIndex( |
31 | (int)Preferences::instance().editor.downsampling()); |
32 | |
33 | if (m_behavior == Behavior::ChangeOnRealTime) |
34 | m_downsampling.Change.connect([this]{ save(); }); |
35 | |
36 | m_samplingChangeConn = |
37 | Preferences::instance().editor.downsampling.AfterChange.connect( |
38 | [this]{ onPreferenceChange(); }); |
39 | } |
40 | |
41 | void SamplingSelector::save() |
42 | { |
43 | const int i = m_downsampling.getSelectedItemIndex(); |
44 | Preferences::instance().editor.downsampling((gen::Downsampling)i); |
45 | } |
46 | |
47 | void SamplingSelector::onPreferenceChange() |
48 | { |
49 | const int i = (int)Preferences::instance().editor.downsampling(); |
50 | if (m_downsampling.getSelectedItemIndex() != i) |
51 | m_downsampling.setSelectedItemIndex(i); |
52 | } |
53 | |
54 | } // namespace app |
55 |