~ubuntu-branches/debian/sid/stella/sid

« back to all changes in this revision

Viewing changes to src/gui/SnapshotDialog.cxx

  • Committer: Package Import Robot
  • Author(s): Stephen Kitt
  • Date: 2013-06-28 09:53:13 UTC
  • mfrom: (1.3.6)
  • Revision ID: package-import@ubuntu.com-20130628095313-j8jkkgxpvx1t18ym
Tags: 3.9-1
New upstream version.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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-2013 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
// $Id: SnapshotDialog.cxx 2753 2013-06-21 12:15:32Z stephena $
 
18
//============================================================================
 
19
 
 
20
#include "bspf.hxx"
 
21
 
 
22
#include "BrowserDialog.hxx"
 
23
#include "EditTextWidget.hxx"
 
24
#include "FSNode.hxx"
 
25
#include "LauncherDialog.hxx"
 
26
#include "PopUpWidget.hxx"
 
27
#include "Settings.hxx"
 
28
 
 
29
#include "SnapshotDialog.hxx"
 
30
 
 
31
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 
32
SnapshotDialog::SnapshotDialog(
 
33
      OSystem* osystem, DialogContainer* parent,
 
34
      const GUI::Font& font, GuiObject* boss,
 
35
      int max_w, int max_h)
 
36
  : Dialog(osystem, parent, 0, 0, 0, 0),
 
37
    myBrowser(NULL)
 
38
{
 
39
  const int lineHeight   = font.getLineHeight(),
 
40
            fontWidth    = font.getMaxCharWidth(),
 
41
            buttonWidth  = font.getStringWidth("Save path:") + 20,
 
42
            buttonHeight = font.getLineHeight() + 4;
 
43
  const int vBorder = 10;
 
44
  int xpos, ypos, lwidth, fwidth;
 
45
  WidgetArray wid;
 
46
  ButtonWidget* b;
 
47
 
 
48
  // Set real dimensions
 
49
  _w = 53 * fontWidth + 8;
 
50
  _h = 10 * (lineHeight + 4) + 10;
 
51
 
 
52
  xpos = vBorder;  ypos = vBorder;
 
53
 
 
54
  // Snapshot path (save files)
 
55
  b = new ButtonWidget(this, font, xpos, ypos, buttonWidth, buttonHeight,
 
56
                       "Save path:", kChooseSnapSaveDirCmd);
 
57
  wid.push_back(b);
 
58
  xpos += buttonWidth + 10;
 
59
  mySnapSavePath = new EditTextWidget(this, font, xpos, ypos + 2,
 
60
                                  _w - xpos - 10, lineHeight, "");
 
61
  wid.push_back(mySnapSavePath);
 
62
 
 
63
  // Snapshot path (load files)
 
64
  xpos = vBorder;  ypos += buttonHeight + 3;
 
65
  b = new ButtonWidget(this, font, xpos, ypos, buttonWidth, buttonHeight,
 
66
                       "Load path:", kChooseSnapLoadDirCmd);
 
67
  wid.push_back(b);
 
68
  xpos += buttonWidth + 10;
 
69
  mySnapLoadPath = new EditTextWidget(this, font, xpos, ypos + 2,
 
70
                                  _w - xpos - 10, lineHeight, "");
 
71
  wid.push_back(mySnapLoadPath);
 
72
 
 
73
  // Snapshot naming
 
74
  lwidth = font.getStringWidth("Continuous snapshot interval: ");
 
75
  fwidth = font.getStringWidth("internal database");
 
76
  VariantList items;
 
77
  items.push_back("actual ROM name", "rom");
 
78
  items.push_back("internal database", "int");
 
79
  xpos = vBorder+10;  ypos += buttonHeight + 8;
 
80
  mySnapName =
 
81
    new PopUpWidget(this, font, xpos, ypos, fwidth, lineHeight, items,
 
82
                    "Save snapshots according to: ", lwidth);
 
83
  wid.push_back(mySnapName);
 
84
 
 
85
  // Snapshot interval (continuous mode)
 
86
  items.clear();
 
87
  items.push_back("1 second", "1");
 
88
  items.push_back("2 seconds", "2");
 
89
  items.push_back("3 seconds", "3");
 
90
  items.push_back("4 seconds", "4");
 
91
  items.push_back("5 seconds", "5");
 
92
  items.push_back("6 seconds", "6");
 
93
  items.push_back("7 seconds", "7");
 
94
  items.push_back("8 seconds", "8");
 
95
  items.push_back("9 seconds", "9");
 
96
  items.push_back("10 seconds", "10");
 
97
  ypos += buttonHeight;
 
98
  mySnapInterval =
 
99
    new PopUpWidget(this, font, xpos, ypos, fwidth, lineHeight, items,
 
100
                    "Continuous snapshot interval: ", lwidth);
 
101
  wid.push_back(mySnapInterval);
 
102
 
 
103
  // Booleans for saving snapshots
 
104
  fwidth = font.getStringWidth("When saving snapshots:");
 
105
  xpos = vBorder;  ypos += buttonHeight + 5;
 
106
  new StaticTextWidget(this, font, xpos, ypos, fwidth, lineHeight,
 
107
                       "When saving snapshots:", kTextAlignLeft);
 
108
 
 
109
  // Snapshot single or multiple saves
 
110
  xpos += 30;  ypos += lineHeight + 3;
 
111
  mySnapSingle = new CheckboxWidget(this, font, xpos, ypos,
 
112
                                    "Overwrite existing files");
 
113
  wid.push_back(mySnapSingle);
 
114
 
 
115
  // Snapshot in 1x mode (ignore scaling)
 
116
  ypos += mySnapSingle->getHeight() + 4;
 
117
  mySnap1x = new CheckboxWidget(this, font, xpos, ypos,
 
118
                                "Disable image filtering (1x mode)");
 
119
  wid.push_back(mySnap1x);
 
120
 
 
121
  // Add Defaults, OK and Cancel buttons
 
122
  b = new ButtonWidget(this, font, 10, _h - buttonHeight - 10,
 
123
                       font.getStringWidth("Defaults") + 20, buttonHeight,
 
124
                       "Defaults", kDefaultsCmd);
 
125
  wid.push_back(b);
 
126
  addOKCancelBGroup(wid, font);
 
127
 
 
128
  addToFocusList(wid);
 
129
 
 
130
  // Create file browser dialog
 
131
  myBrowser = new BrowserDialog(this, font, max_w, max_h);
 
132
}
 
133
 
 
134
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 
135
SnapshotDialog::~SnapshotDialog()
 
136
{
 
137
  delete myBrowser;
 
138
}
 
139
 
 
140
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 
141
void SnapshotDialog::loadConfig()
 
142
{
 
143
  const Settings& settings = instance().settings();
 
144
  mySnapSavePath->setText(settings.getString("snapsavedir"));
 
145
  mySnapLoadPath->setText(settings.getString("snaploaddir"));
 
146
  mySnapName->setSelected(instance().settings().getString("snapname"), "int");
 
147
  mySnapInterval->setSelected(instance().settings().getString("ssinterval"), "2");
 
148
  mySnapSingle->setState(settings.getBool("sssingle"));
 
149
  mySnap1x->setState(settings.getBool("ss1x"));
 
150
}
 
151
 
 
152
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 
153
void SnapshotDialog::saveConfig()
 
154
{
 
155
  instance().settings().setValue("snapsavedir", mySnapSavePath->getText());
 
156
  instance().settings().setValue("snaploaddir", mySnapLoadPath->getText());
 
157
  instance().settings().setValue("snapname",
 
158
    mySnapName->getSelectedTag().toString());
 
159
  instance().settings().setValue("sssingle", mySnapSingle->getState());
 
160
  instance().settings().setValue("ss1x", mySnap1x->getState());
 
161
  instance().settings().setValue("ssinterval",
 
162
    mySnapInterval->getSelectedTag().toString());
 
163
 
 
164
  // Flush changes to disk and inform the OSystem
 
165
  instance().saveConfig();
 
166
  instance().setConfigPaths();
 
167
}
 
168
 
 
169
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 
170
void SnapshotDialog::setDefaults()
 
171
{
 
172
  mySnapSavePath->setText(instance().defaultSnapSaveDir());
 
173
  mySnapLoadPath->setText(instance().defaultSnapLoadDir());
 
174
 
 
175
  mySnapSingle->setState(false);
 
176
  mySnap1x->setState(false);
 
177
  mySnapInterval->setSelected("2", "2");
 
178
}
 
179
 
 
180
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 
181
void SnapshotDialog::handleCommand(CommandSender* sender, int cmd,
 
182
                                   int data, int id)
 
183
{
 
184
  switch (cmd)
 
185
  {
 
186
    case kOKCmd:
 
187
      saveConfig();
 
188
      close();
 
189
      break;
 
190
 
 
191
    case kDefaultsCmd:
 
192
      setDefaults();
 
193
      break;
 
194
 
 
195
    case kChooseSnapSaveDirCmd:
 
196
      myBrowser->show("Select snapshot save directory:", mySnapSavePath->getText(),
 
197
                      BrowserDialog::Directories, kSnapSaveDirChosenCmd);
 
198
      break;
 
199
 
 
200
    case kChooseSnapLoadDirCmd:
 
201
      myBrowser->show("Select snapshot load directory:", mySnapLoadPath->getText(),
 
202
                      BrowserDialog::Directories, kSnapLoadDirChosenCmd);
 
203
      break;
 
204
 
 
205
    case kSnapSaveDirChosenCmd:
 
206
      mySnapSavePath->setText(myBrowser->getResult().getShortPath());
 
207
      break;
 
208
 
 
209
    case kSnapLoadDirChosenCmd:
 
210
      mySnapLoadPath->setText(myBrowser->getResult().getShortPath());
 
211
      break;
 
212
 
 
213
    default:
 
214
      Dialog::handleCommand(sender, cmd, data, 0);
 
215
      break;
 
216
  }
 
217
}