~w-shackleton/droidpad-pc/trunk

« back to all changes in this revision

Viewing changes to src/if-gui/preferences.cpp

  • Committer: William Shackleton
  • Date: 2013-04-02 20:08:51 UTC
  • Revision ID: w.shackleton@gmail.com-20130402200851-ta2inum60ayg9esr
Added preferences GUI allowing slideshow keys to be changed. More preferences coming soon. Completely untested.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * This file is part of DroidPad.
 
3
 * DroidPad lets you use an Android mobile to control a joystick or mouse
 
4
 * on a Windows or Linux computer.
 
5
 *
 
6
 * DroidPad is free software: you can redistribute it and/or modify
 
7
 * it under the terms of the GNU General Public License as published by
 
8
 * the Free Software Foundation, either version 3 of the License, or
 
9
 * (at your option) any later version.
 
10
 *
 
11
 * DroidPad is distributed in the hope that it will be useful,
 
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
 * GNU General Public License for more details.
 
15
 *
 
16
 * You should have received a copy of the GNU General Public License
 
17
 * along with DroidPad, in the file COPYING.
 
18
 * If not, see <http://www.gnu.org/licenses/>.
 
19
 */
 
20
 
 
21
#include "preferences.hpp"
 
22
 
 
23
#include <wx/xrc/xmlres.h>
 
24
#include <wx/msgdlg.h>
 
25
#include "data.hpp"
 
26
#include "log.hpp"
 
27
 
 
28
BEGIN_EVENT_TABLE(Preferences, wxDialog)
 
29
        EVT_BUTTON(XRCID("okButton"), Preferences::onDone)
 
30
        EVT_BUTTON(XRCID("cancelButton"), Preferences::onCancel)
 
31
END_EVENT_TABLE()
 
32
 
 
33
using namespace droidpad;
 
34
using namespace std;
 
35
 
 
36
#ifdef __WXMSW__
 
37
#define _FRAME_ICON wxT("icon.xpm")
 
38
#else
 
39
#define _FRAME_ICON wxT("iconlarge.xpm")
 
40
#endif
 
41
 
 
42
#define CHECK_XML(_name) if(!_name) handleXMLError(wxT(#_name))
 
43
 
 
44
#define LOADXRC(_xml, _name, _type) _name = XRCCTRL(*this, #_xml, _type); \
 
45
                                            if(_name == NULL) handleXMLError(wxT(#_xml));
 
46
 
 
47
#define NUM_AXIS 6
 
48
#define NUM_BUTTONS 12
 
49
 
 
50
Preferences::Preferences(wxWindow *parent) {
 
51
        if(!wxXmlResource::Get()->LoadDialog(this, parent, wxT("preferences"))) {
 
52
                LOGE("Failed to load preferences dialog XML.");
 
53
        }
 
54
 
 
55
        SetIcon(wxIcon(Data::getFilePath(_FRAME_ICON), wxBITMAP_TYPE_XPM));
 
56
 
 
57
        LOADXRC(slideshowBlackKey, blackKey, wxTextCtrl);
 
58
        LOADXRC(slideshowWhiteKey, whiteKey, wxTextCtrl);
 
59
 
 
60
        Fit();
 
61
}
 
62
 
 
63
void Preferences::onDone(wxCommandEvent &evt) {
 
64
        // Save selection to prefs again
 
65
        if(blackKey->GetValue().size() > 0)
 
66
                Data::blackKey = blackKey->GetValue().GetChar(0);
 
67
        else Data::blackKey = 'b';
 
68
        if(whiteKey->GetValue().size() > 0)
 
69
                Data::whiteKey = whiteKey->GetValue().GetChar(0);
 
70
        else Data::whiteKey = 'w';
 
71
        Data::savePreferences();
 
72
        EndModal(1);
 
73
}
 
74
void Preferences::onCancel(wxCommandEvent &evt) {
 
75
        EndModal(0);
 
76
}
 
77
 
 
78
void Preferences::handleXMLError(wxString name)
 
79
{
 
80
        wxMessageDialog(this, wxString::Format(_("Error loading layout while loading \"%s\".\nPlease report this as a bug."), name.c_str()), _("Error loading layout"), wxOK | wxICON_EXCLAMATION).ShowModal();
 
81
}
 
82