~fighting-bytes/hexwars/trunk

« back to all changes in this revision

Viewing changes to src/shared/gui/virtual/VirtualBasicUserInterface.cpp

  • Committer: Patrik Schönfeldt
  • Date: 2013-10-30 14:48:25 UTC
  • Revision ID: patrik@proxima.snft.de-20131030144825-zipv41a0nq8xemxp
* more cleanup: removed "virtual" directory for GUI classes

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#include "VirtualBasicUserInterface.hpp"
2
 
 
3
 
void VirtualBasicUserInterface::loadUIConfig(){
4
 
    std::ifstream uisettings;
5
 
    uisettings.open(uicfgpath.c_str());
6
 
    if(!uisettings.good()){
7
 
        setDefaultConfig();
8
 
        throw Hexception( std::string("Error loading config file: '")
9
 
                          + uicfgpath.string()
10
 
                          + std::string("'. Will use default values.\n")
11
 
                        );
12
 
        return;
13
 
    }
14
 
    char tmpchar;
15
 
    std::string descripiton;
16
 
    while(uisettings.good()){
17
 
        descripiton.clear();
18
 
        for(int i=0; i<11 ; i++){
19
 
            uisettings >> tmpchar;
20
 
            descripiton.push_back(tmpchar);
21
 
        }
22
 
        if(descripiton == "sfullscreen")
23
 
            uisettings >> SFull;
24
 
        if(descripiton == "screenwidth")
25
 
            uisettings >> size.x;
26
 
        if(descripiton == "screenhight")
27
 
            uisettings >> size.y;
28
 
        if(descripiton == "scolordepth")
29
 
            uisettings >> SDepth;
30
 
        if(descripiton == "framepersec")
31
 
            uisettings >> FPS;
32
 
    }
33
 
    if(size.x <= 0 || size.y <= 0){
34
 
        setDefaultConfig();
35
 
        throw Hexception( "Error: Invalid configuration. "
36
 
                          "Will use default values.\n");
37
 
        return;
38
 
    }
39
 
}
40
 
 
41
 
void VirtualBasicUserInterface::setFullscreen(bool full){
42
 
    SFull = full;
43
 
}
44
 
 
45
 
void VirtualBasicUserInterface::setResolution(Coordinates res, int depth){
46
 
    size = res;
47
 
    SDepth = depth;
48
 
}
49
 
 
50
 
void VirtualBasicUserInterface::prepareUICfgPath(){
51
 
    uicfgpath = fsh->getSettingsDir();
52
 
 
53
 
    fsh->prepareDirectory(uicfgpath);
54
 
 
55
 
    uicfgpath /= "/cfg";
56
 
    fsh->prepareDirectory(uicfgpath);
57
 
 
58
 
    uicfgpath /= "/uisettings.cfg";
59
 
}
60
 
 
61
 
void VirtualBasicUserInterface::setDefaultConfig()
62
 
{
63
 
    SFull = false;
64
 
    size.x = 640;
65
 
    size.y = 480;
66
 
    SDepth = 16;
67
 
    FPS = 60;
68
 
}
69
 
 
70
 
void VirtualBasicUserInterface:: saveUIConfig(){
71
 
    std::ofstream uisettings;
72
 
    uisettings.open(uicfgpath.c_str());
73
 
    uisettings << "screenwidth " << size.x  << std::endl;
74
 
    uisettings << "screenhight " << size.y  << std::endl;
75
 
    uisettings << "sfullscreen " << SFull   << std::endl;
76
 
    uisettings << "scolordepth " << SDepth  << std::endl;
77
 
    uisettings << "framepersec " << FPS     << std::endl;
78
 
    uisettings.close();
79
 
}