Debian Codegraph @

src/videooptions.cpp

raw symbols ◀ ▶
Source reconstructed at patch state 0 of 2 — not the installed (fully patched) source.
2 Debian patches touch this file
1 #include <vector>
2 #include <sstream>
3
4 #include <SDL/SDL.h>
5
6 #include "guichan/guichan.hpp"
7
8 #include "ui/menuaction.h"
9
10 #include "settings.h"
11
12 #include "videooptions.h"
13 #include "main.h"
14
15 using namespace std;
16 using namespace gcn;
17
18 VideoOptions::VideoOptions()
19 : toggleFullscreenAction(0), screenSizeAction(0), applyVideoOptionsAction(0)
20 {
21 fullscreen = Settings::getFullscreen();
22 screenWidth = Settings::getScreenWidth();
23 screenHeight = Settings::getScreenHeight();
24
25 SDL_Rect **modes = SDL_ListModes(NULL, SDL_FULLSCREEN
26 | SDL_HWSURFACE
27 | SDL_SWSURFACE);
28
29 /* Check if there are any modes available */
30 if(!modes)
31 {
32 // No modes available. :(
33 }
34 else if(modes == (SDL_Rect **)-1){
35 // This means we can chose every display size we want (will never happen).
36 }
37 else
38 {
39 for (int i=0; modes[i]; ++i)
40 sizes.push_back(pair <int, int> (modes[i]->w, modes[i]->h));
41
42 // Nicely sort the entries.
43 sort (sizes.begin(), sizes.end());
44 }
45
46 // Initializes index with the proper value denoting the current
47 // screen size.
48 index = 0;
49 int size = sizes.size();
50 for (int i=0; i<size; i++)
51 {
52 if (sizes[i].first == screenWidth
53 && sizes[i].second == screenHeight)
54 {
55 index = i;
56 break;
57 }
58 }
59
60 }
61
62 void
63 VideoOptions::toggleFullscreen()
64 {
65 fullscreen = !fullscreen;
66
67 if (toggleFullscreenAction)
68 toggleFullscreenAction->update();
69 }
70
71 class ToggleFullscreenAction : public MenuAction
72 {
73 VideoOptions &videoOptions;
74 CheckBox *check;
75
76 public:
77 ToggleFullscreenAction(VideoOptions &vo)
78 : videoOptions(vo) { }
79
80 virtual gcn::Widget *getWidget(string s)
81 {
82 return check = new CheckBox(s, videoOptions.getFullscreen());
83 }
84
85 void invoke()
86 {
87 videoOptions.toggleFullscreen();
88 }
89
90 void previous()
91 {
92 invoke();
93 }
94
95 void next()
96 {
97 invoke();
98 }
99
100 void update()
101 {
102 check->setMarked(videoOptions.getFullscreen());
103 }
104 };
105
106 MenuAction *
107 VideoOptions::getToggleFullscreenAction()
108 {
109 if (!toggleFullscreenAction)
110 toggleFullscreenAction = new ToggleFullscreenAction(*this);
111
112 return toggleFullscreenAction;
113 }
114
115 void
116 VideoOptions::nextScreenSize()
117 {
118 if (++index >= sizes.size())
119 index = 0;
120
121 screenWidth = sizes[index].first;
122 screenHeight = sizes[index].second;
123
124 if (screenSizeAction)
125 screenSizeAction->update();
126 }
127
128 void
129 VideoOptions::previousScreenSize()
130 {
131 if (--index < 0)
132 index = sizes.size() - 1;
133
134 screenWidth = sizes[index].first;
135 screenHeight = sizes[index].second;
136
137 if (screenSizeAction)
138 screenSizeAction->update();
139 }
140
141 class ScreenSizeAction : public MenuAction
142 {
143 VideoOptions &videoOptions;
144 Label *label;
145 string baseCaption;
146
147 public:
148 ScreenSizeAction(VideoOptions &vo)
149 : videoOptions(vo) { }
150
151 virtual gcn::Widget *getWidget(string s)
152 {
153 baseCaption = s;
154 stringstream ss;
155 ss << baseCaption;
156 ss << " ";
157 ss << videoOptions.getScreenWidth();
158 ss << "x";
159 ss << videoOptions.getScreenHeight();
160
161 return label = new Label(ss.str());
162 }
163
164 void invoke()
165 {
166 next();
167 }
168
169 void next()
170 {
171 videoOptions.nextScreenSize();
172 }
173
174 void previous()
175 {
176 videoOptions.previousScreenSize();
177 }
178
179 void update()
180 {
181 stringstream ss;
182 ss << baseCaption;
183 ss << " ";
184 ss << videoOptions.getScreenWidth();
185 ss << "x";
186 ss << videoOptions.getScreenHeight();
187
188 label->setCaption(ss.str());
189 label->adjustSize();
190 }
191
192 };
193
194 MenuAction *
195 VideoOptions::getScreenSizeAction()
196 {
197 if (!screenSizeAction)
198 screenSizeAction = new ScreenSizeAction(*this);
199
200 return screenSizeAction;
201 }
202
203 class ApplyVideoOptionsAction : public MenuAction
204 {
205 Main &main;
206 VideoOptions &videoOptions;
207
208 public:
209 ApplyVideoOptionsAction(Main &m, VideoOptions &vo)
210 : main(m), videoOptions(vo) { }
211
212 void invoke()
213 {
214 main.applyVideoOptions(videoOptions);
215 }
216 };
217
218 MenuAction *
219 VideoOptions::getApplyVideoOptionsAction(Main &main)
220 {
221 if (!applyVideoOptionsAction)
222 applyVideoOptionsAction = new ApplyVideoOptionsAction(main, *this);
223
224 return applyVideoOptionsAction;
225 }