1 | //============================================================================ |
2 | // |
3 | // SSSS tt lll lll |
4 | // SS SS tt ll ll |
5 | // SS tttttt eeee ll ll aaaa |
6 | // SSSS tt ee ee ll ll aa |
7 | // SS tt eeeeee ll ll aaaaa -- "An Atari 2600 VCS Emulator" |
8 | // SS SS tt ee ll ll aa aa |
9 | // SSSS ttt eeeee llll llll aaaaa |
10 | // |
11 | // Copyright (c) 1995-2019 by Bradford W. Mott, Stephen Anthony |
12 | // and the Stella Team |
13 | // |
14 | // See the file "License.txt" for information on usage and redistribution of |
15 | // this file, and for a DISCLAIMER OF ALL WARRANTIES. |
16 | //============================================================================ |
17 | |
18 | #include "bspf.hxx" |
19 | #include "BrowserDialog.hxx" |
20 | #include "EditTextWidget.hxx" |
21 | #include "FSNode.hxx" |
22 | #include "Font.hxx" |
23 | #include "LauncherDialog.hxx" |
24 | #include "Settings.hxx" |
25 | #include "SnapshotDialog.hxx" |
26 | |
27 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
28 | SnapshotDialog::SnapshotDialog(OSystem& osystem, DialogContainer& parent, |
29 | const GUI::Font& font, int max_w, int max_h) |
30 | : Dialog(osystem, parent, font, "Snapshot settings" ), |
31 | myFont(font) |
32 | { |
33 | const int VBORDER = 10; |
34 | const int HBORDER = 10; |
35 | const int INDENT = 16; |
36 | const int V_GAP = 4; |
37 | const int lineHeight = font.getLineHeight(), |
38 | fontWidth = font.getMaxCharWidth(), |
39 | buttonWidth = font.getStringWidth("Save path" + ELLIPSIS) + 20, |
40 | buttonHeight = font.getLineHeight() + 4; |
41 | int xpos, ypos, fwidth; |
42 | WidgetArray wid; |
43 | ButtonWidget* b; |
44 | |
45 | // Set real dimensions |
46 | setSize(64 * fontWidth + HBORDER * 2, 9 * (lineHeight + 4) + VBORDER + _th, max_w, max_h); |
47 | |
48 | xpos = HBORDER; ypos = VBORDER + _th; |
49 | |
50 | // Snapshot path (save files) |
51 | b = new ButtonWidget(this, font, xpos, ypos, buttonWidth, buttonHeight, |
52 | "Save path" + ELLIPSIS, kChooseSnapSaveDirCmd); |
53 | wid.push_back(b); |
54 | xpos += buttonWidth + 8; |
55 | mySnapSavePath = new EditTextWidget(this, font, xpos, ypos + 1, |
56 | _w - xpos - HBORDER, lineHeight, "" ); |
57 | wid.push_back(mySnapSavePath); |
58 | |
59 | // Snapshot naming |
60 | xpos = HBORDER; ypos += buttonHeight + V_GAP * 4; |
61 | |
62 | // Snapshot interval (continuous mode) |
63 | mySnapInterval = new SliderWidget(this, font, xpos, ypos, |
64 | "Continuous snapshot interval " , 0, kSnapshotInterval, |
65 | font.getStringWidth("10 seconds" )); |
66 | mySnapInterval->setMinValue(1); |
67 | mySnapInterval->setMaxValue(10); |
68 | mySnapInterval->setTickmarkIntervals(3); |
69 | wid.push_back(mySnapInterval); |
70 | |
71 | // Booleans for saving snapshots |
72 | fwidth = font.getStringWidth("When saving snapshots:" ); |
73 | xpos = HBORDER; ypos += lineHeight + V_GAP * 3; |
74 | new StaticTextWidget(this, font, xpos, ypos, fwidth, lineHeight, |
75 | "When saving snapshots:" , TextAlign::Left); |
76 | |
77 | // Snapshot single or multiple saves |
78 | xpos += INDENT; ypos += lineHeight + V_GAP; |
79 | mySnapName = new CheckboxWidget(this, font, xpos, ypos, "Use actual ROM name" ); |
80 | wid.push_back(mySnapName); |
81 | ypos += lineHeight + V_GAP; |
82 | |
83 | mySnapSingle = new CheckboxWidget(this, font, xpos, ypos, "Overwrite existing files" ); |
84 | wid.push_back(mySnapSingle); |
85 | |
86 | // Snapshot in 1x mode (ignore scaling) |
87 | ypos += lineHeight + V_GAP; |
88 | mySnap1x = new CheckboxWidget(this, font, xpos, ypos, |
89 | "Ignore scaling (1x mode)" ); |
90 | wid.push_back(mySnap1x); |
91 | |
92 | // Add Defaults, OK and Cancel buttons |
93 | addDefaultsOKCancelBGroup(wid, font); |
94 | |
95 | addToFocusList(wid); |
96 | } |
97 | |
98 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
99 | SnapshotDialog::~SnapshotDialog() |
100 | { |
101 | } |
102 | |
103 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
104 | void SnapshotDialog::loadConfig() |
105 | { |
106 | const Settings& settings = instance().settings(); |
107 | mySnapSavePath->setText(settings.getString("snapsavedir" )); |
108 | mySnapInterval->setValue(instance().settings().getInt("ssinterval" )); |
109 | mySnapName->setState(instance().settings().getString("snapname" ) == "rom" ); |
110 | mySnapSingle->setState(settings.getBool("sssingle" )); |
111 | mySnap1x->setState(settings.getBool("ss1x" )); |
112 | } |
113 | |
114 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
115 | void SnapshotDialog::saveConfig() |
116 | { |
117 | instance().settings().setValue("snapsavedir" , mySnapSavePath->getText()); |
118 | instance().settings().setValue("ssinterval" , mySnapInterval->getValue()); |
119 | instance().settings().setValue("snapname" , mySnapName->getState() ? "rom" : "int" ); |
120 | instance().settings().setValue("sssingle" , mySnapSingle->getState()); |
121 | instance().settings().setValue("ss1x" , mySnap1x->getState()); |
122 | |
123 | // Flush changes to disk and inform the OSystem |
124 | instance().saveConfig(); |
125 | instance().setConfigPaths(); |
126 | } |
127 | |
128 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
129 | void SnapshotDialog::setDefaults() |
130 | { |
131 | mySnapSavePath->setText(instance().defaultSaveDir()); |
132 | mySnapInterval->setValue(2); |
133 | mySnapName->setState(false); |
134 | mySnapSingle->setState(false); |
135 | mySnap1x->setState(false); |
136 | } |
137 | |
138 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
139 | void SnapshotDialog::handleCommand(CommandSender* sender, int cmd, |
140 | int data, int id) |
141 | { |
142 | switch (cmd) |
143 | { |
144 | case GuiObject::kOKCmd: |
145 | saveConfig(); |
146 | close(); |
147 | break; |
148 | |
149 | case GuiObject::kDefaultsCmd: |
150 | setDefaults(); |
151 | break; |
152 | |
153 | case kChooseSnapSaveDirCmd: |
154 | // This dialog is resizable under certain conditions, so we need |
155 | // to re-create it as necessary |
156 | createBrowser("Select snapshot save directory" ); |
157 | myBrowser->show(mySnapSavePath->getText(), |
158 | BrowserDialog::Directories, kSnapSaveDirChosenCmd); |
159 | break; |
160 | |
161 | case kSnapSaveDirChosenCmd: |
162 | mySnapSavePath->setText(myBrowser->getResult().getShortPath()); |
163 | break; |
164 | |
165 | case kSnapshotInterval: |
166 | if(mySnapInterval->getValue() == 1) |
167 | mySnapInterval->setValueUnit(" second" ); |
168 | else |
169 | mySnapInterval->setValueUnit(" seconds" ); |
170 | break; |
171 | |
172 | default: |
173 | Dialog::handleCommand(sender, cmd, data, 0); |
174 | break; |
175 | } |
176 | } |
177 | |
178 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
179 | void SnapshotDialog::createBrowser(const string& title) |
180 | { |
181 | uInt32 w = 0, h = 0; |
182 | getDynamicBounds(w, h); |
183 | |
184 | // Create file browser dialog |
185 | if(!myBrowser || uInt32(myBrowser->getWidth()) != w || |
186 | uInt32(myBrowser->getHeight()) != h) |
187 | myBrowser = make_unique<BrowserDialog>(this, myFont, w, h, title); |
188 | else |
189 | myBrowser->setTitle(title); |
190 | } |
191 | |