Merge lp:~timfelgentreff/stratagus/timfelgentreff-zoomeable-view into lp:stratagus
- timfelgentreff-zoomeable-view
- Merge into trunk
Status: | Merged |
---|---|
Approved by: | Pali |
Approved revision: | 8707 |
Merged at revision: | 8727 |
Proposed branch: | lp:~timfelgentreff/stratagus/timfelgentreff-zoomeable-view |
Merge into: | lp:stratagus |
Diff against target: |
337 lines (+131/-17) 7 files modified
src/include/video.h (+8/-0) src/stratagus/stratagus.cpp (+28/-1) src/ui/interface.cpp (+7/-0) src/ui/script_ui.cpp (+18/-0) src/video/movie.cpp (+17/-8) src/video/sdl.cpp (+37/-3) src/video/video.cpp (+16/-5) |
To merge this branch: | bzr merge lp:~timfelgentreff/stratagus/timfelgentreff-zoomeable-view |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Pali | Approve | ||
Joris Dauphin | Approve | ||
Review via email: mp+159929@code.launchpad.net |
Commit message
Description of the change
This branch adds an option to zoom the viewport using opengl. This is particularily useful when playing on tablets using the touchscreen, as the zoomed view provides large targets. Also, it looks retro with the pixelation :)
Kyran Jackson (erstmap) wrote : | # |
Travis (dinky-dye-aussie) wrote : | # |
oh nice this sounds like a great addition! :)
- 8699. By timfelgentreff
-
* Translate touch coordinates when using OpenGL zoom
* have the resolution option affect the viewport when using OpenGL zoom - 8700. By timfelgentreff
-
Fix bogus rectangle select when touch events jump around
- 8701. By timfelgentreff
-
Ensure we use absolute mouse coordinates on Windows touchscreen devices in fullscreen
timfelgentreff (timfelgentreff) wrote : | # |
The additional commits fix mouse-coordinates and -behaviour on windows in both fullscreen and windowed modes
- 8702. By timfelgentreff
-
merge lp:stratagus
timfelgentreff (timfelgentreff) wrote : | # |
Hi, just wondering if you can provide any feedback on this (even if it is "we don't want this / we're not going to merge this")
Joris Dauphin (joris-dauphin) wrote : | # |
By a quick code review, it seems good, but I don't have touch screen, so I can't test it.
So I let someone else review/commit (Pali ?).
Pali (pali) wrote : | # |
I see that all touchscreen code changes are only for windows platform (#ifdef USE_WIN32). I added touchscreen code to Stratagus for Nokia N900 device which is Linux (Xserver/X11) based. So this (windows) not changing anything for my N900.
But I can test OpenGL ES changes on Linux desktop and Nokia N900.
timfelgentreff (timfelgentreff) wrote : | # |
@Pali The relative mouse coordinates in fullscreen can on Linux be disabled by setting SDL_MOUSE_RELATIVE (or something like it) in your environment, but not on Windows, so this really only applies to Windows.
On any touchscreen device you'll need to test whether the changes from line 87 in the diff work for you, if not I'll need to #ifdef those, too. I had to click twice very often on my tablet to get rid of the selection rectangle without that change.
Besides that, could you also test whether the viewport zooming works with OpenGL ES? I tested with OpenGL on Windows and Linux (played through half the Tides of Darkness campaign with it).
Pali (pali) wrote : | # |
Matchbox Window Manager on Maemo 5 does not support resizing application windows, so I cannot test this on Nokia N900.
But I have working OpenGL ES driver on desktop, so I can test that here.
Joris Dauphin (joris-dauphin) wrote : | # |
I suggest to merge if all (partial) tests pass.
Pali (pali) wrote : | # |
I tested it on Linux in both opengl and opengles and there is problem. Resolution of monitor is 800x600 and original resolution of stratagus is 1600x900. In this mode I can move mouse only in rectangle (800/1600 * 800) x (600/900 * 600). So I cannot click on exit button, because mouse is only in subrectangle 800x600 from full screen 1600x900 (scaled to 800x600).
timfelgentreff (timfelgentreff) wrote : | # |
ah, okay, i hadn't thought about scaling down. i'll get on it.
Pali (pali) wrote : | # |
Fix also function PlayMovie in https:/
Because YUV overlay cannot be created in OpenGL mode, that function first turn off OpenGL. And that function using Video.Width Video.Height, so movie is not scaled to full screen.
- 8703. By timfelgentreff
-
merge lp:stratagus
- 8704. By timfelgentreff
-
use Viewport dimensions for video when using OpenGL
- 8705. By timfelgentreff
-
always translate mouse coordinates if we are zoomed
timfelgentreff (timfelgentreff) wrote : | # |
@Pali I fixed the video dimensions and the issue with the mouse coordinates.
Pali (pali) wrote : | # |
Ok, now scaling working fine on desktop with both OpenGL and OpenGL ES.
But there is problem if I compile stratagus with OpenGL/ES and start it with param -o (disable opengl/es). then stratagus freeze and show this error.
$ ./stratagus-dbg -d /usr/share/
...
X Error of failed request: BadValue (integer parameter out of range for operation)
Major opcode of failed request: 130 (MIT-SHM)
Minor opcode of failed request: 3 (X_ShmPutImage)
Value in failed request: 0x640
Serial number of failed request: 25
Current serial number in output stream: 26
And other small note: Help text for -Z should not be visible/compiled if opengl/es is not enabled at compile time (like options -O and -O)
timfelgentreff (timfelgentreff) wrote : | # |
Since disabling OpenGL with -Z is illegal, should I just print an error message in this case and exit? Or should it be a warning and I continue launching with zoom disabled in this case?
Pali (pali) wrote : | # |
I think that when opengl is disabled (via -o or via preferences/game menu) startagus should write error message when -Z is specified and exit. (Like when opengl is disabled and compile time and stratagus write error message that -Z is incorrect param)
- 8706. By timfelgentreff
-
Only show -Z option in help text if compiled with OpenGL(ES) and make certain that -Z only works with OpenGL enabled
- 8707. By timfelgentreff
-
print error message to stderr, not stdout
timfelgentreff (timfelgentreff) wrote : | # |
@Pali I have clarified that using -Z implies -O. If you use "-Z -o" in that order, it now prints an error message and exits. The other way around works, which I think is consistent with what happens if you do "-o -O".
Pali (pali) wrote : | # |
Ok, I think this merge request can be merged to trunk now.
Pali (pali) wrote : | # |
@Joris: It is Ok for merging?
Joris Dauphin (joris-dauphin) wrote : | # |
No objection.
Pali (pali) wrote : | # |
@timfelgentreff: Go ahead and merge code to trunk.
Preview Diff
1 | === modified file 'src/include/video.h' |
2 | --- src/include/video.h 2013-04-13 00:57:39 +0000 |
3 | +++ src/include/video.h 2013-05-01 16:44:24 +0000 |
4 | @@ -53,6 +53,7 @@ |
5 | #if defined(USE_OPENGL) || defined(USE_GLES) |
6 | extern char ForceUseOpenGL; |
7 | extern bool UseOpenGL; |
8 | +extern bool ZoomNoResize; |
9 | #endif |
10 | |
11 | class CGraphic : public gcn::Image |
12 | @@ -351,6 +352,13 @@ |
13 | |
14 | int Width; |
15 | int Height; |
16 | +#if defined(USE_OPENGL) || defined(USE_GLES) |
17 | + int ViewportWidth; /// Actual width of the window |
18 | + int ViewportHeight; /// Actual height of the window |
19 | +#endif |
20 | +#if defined(USE_TOUCHSCREEN) && defined(USE_WIN32) |
21 | + SDL_Cursor *blankCursor; |
22 | +#endif |
23 | int Depth; |
24 | bool FullScreen; |
25 | }; |
26 | |
27 | === modified file 'src/stratagus/stratagus.cpp' |
28 | --- src/stratagus/stratagus.cpp 2013-04-29 13:31:19 +0000 |
29 | +++ src/stratagus/stratagus.cpp 2013-05-01 16:44:24 +0000 |
30 | @@ -456,6 +456,9 @@ |
31 | "\t-u userpath\tPath where stratagus saves preferences, log and savegame\n" |
32 | "\t-v mode\t\tVideo mode resolution in format <xres>x<yres>\n" |
33 | "\t-W\t\tWindowed video mode\n" |
34 | +#if defined(USE_OPENGL) || defined(USE_GLES) |
35 | + "\t-Z\t\tUse OpenGL to scale the screen to the viewport (retro-style). Implies -O.\n" |
36 | +#endif |
37 | "map is relative to StratagusLibPath=datapath, use ./map for relative to cwd\n", |
38 | Parameters::Instance.applicationName.c_str()); |
39 | } |
40 | @@ -506,7 +509,7 @@ |
41 | void ParseCommandLine(int argc, char **argv, Parameters ¶meters) |
42 | { |
43 | for (;;) { |
44 | - switch (getopt(argc, argv, "ac:d:D:eE:FhiI:lN:oOP:ps:S:u:v:W?")) { |
45 | + switch (getopt(argc, argv, "ac:d:D:eE:FhiI:lN:oOP:ps:S:u:v:WZ?")) { |
46 | case 'a': |
47 | EnableAssert = true; |
48 | continue; |
49 | @@ -550,6 +553,11 @@ |
50 | case 'o': |
51 | ForceUseOpenGL = 1; |
52 | UseOpenGL = 0; |
53 | + if (ZoomNoResize) { |
54 | + fprintf(stderr, "Error: -Z only works with OpenGL enabled\n"); |
55 | + Usage(); |
56 | + ExitFatal(-1); |
57 | + } |
58 | continue; |
59 | case 'O': |
60 | ForceUseOpenGL = 1; |
61 | @@ -586,12 +594,31 @@ |
62 | Usage(); |
63 | ExitFatal(-1); |
64 | } |
65 | +#if defined(USE_OPENGL) || defined(USE_GLES) |
66 | + if (ZoomNoResize) { |
67 | + Video.ViewportHeight = Video.Height; |
68 | + Video.ViewportWidth = Video.Width; |
69 | + Video.Height = 0; |
70 | + Video.Width = 0; |
71 | + } |
72 | +#endif |
73 | continue; |
74 | } |
75 | case 'W': |
76 | VideoForceFullScreen = 1; |
77 | Video.FullScreen = 0; |
78 | continue; |
79 | +#if defined(USE_OPENGL) || defined(USE_GLES) |
80 | + case 'Z': |
81 | + ForceUseOpenGL = 1; |
82 | + UseOpenGL = 1; |
83 | + ZoomNoResize = 1; |
84 | + Video.ViewportHeight = Video.Height; |
85 | + Video.ViewportWidth = Video.Width; |
86 | + Video.Height = 0; |
87 | + Video.Width = 0; |
88 | + continue; |
89 | +#endif |
90 | case -1: |
91 | break; |
92 | case '?': |
93 | |
94 | === modified file 'src/ui/interface.cpp' |
95 | --- src/ui/interface.cpp 2013-04-16 17:55:29 +0000 |
96 | +++ src/ui/interface.cpp 2013-05-01 16:44:24 +0000 |
97 | @@ -1367,6 +1367,13 @@ |
98 | || ((y - buff) <= MouseY && MouseY <= (y + buff)) == 0) { |
99 | MouseState = InitialMouseState; |
100 | LastMouseTicks = ticks; |
101 | + // Reset rectangle select cursor state if we moved by a lot |
102 | + // - rectangle select should be a drag, not a tap |
103 | + if (CursorState == CursorStateRectangle |
104 | + && (((x - buff * 2) <= MouseX && MouseX <= (x + buff * 2)) == 0 |
105 | + || ((y - buff * 2) <= MouseY && MouseY <= (y + buff * 2)) == 0)) { |
106 | + CursorState = CursorStatePoint; |
107 | + } |
108 | } |
109 | if (MouseX != x || MouseY != y) { |
110 | MouseX = x; |
111 | |
112 | === modified file 'src/ui/script_ui.cpp' |
113 | --- src/ui/script_ui.cpp 2013-04-25 13:57:02 +0000 |
114 | +++ src/ui/script_ui.cpp 2013-05-01 16:44:24 +0000 |
115 | @@ -203,6 +203,23 @@ |
116 | return 0; |
117 | } |
118 | |
119 | +static int CclSetZoomNoResize(lua_State *l) |
120 | +{ |
121 | + LuaCheckArgs(l, 1); |
122 | +#if defined(USE_OPENGL) || defined(USE_GLES) |
123 | + if (CclInConfigFile) { |
124 | + // May have been set from the command line |
125 | + if (!ForceUseOpenGL) { |
126 | + ZoomNoResize = LuaToBoolean(l, 1); |
127 | + if (ZoomNoResize) { |
128 | + UseOpenGL = true; |
129 | + } |
130 | + } |
131 | + } |
132 | +#endif |
133 | + return 0; |
134 | +} |
135 | + |
136 | /** |
137 | ** Set the video resolution. |
138 | ** |
139 | @@ -1151,6 +1168,7 @@ |
140 | |
141 | lua_register(Lua, "SetMaxOpenGLTexture", CclSetMaxOpenGLTexture); |
142 | lua_register(Lua, "SetUseOpenGL", CclSetUseOpenGL); |
143 | + lua_register(Lua, "SetZoomNoResize", CclSetZoomNoResize); |
144 | lua_register(Lua, "SetVideoResolution", CclSetVideoResolution); |
145 | lua_register(Lua, "GetVideoResolution", CclGetVideoResolution); |
146 | lua_register(Lua, "SetVideoFullScreen", CclSetVideoFullScreen); |
147 | |
148 | === modified file 'src/video/movie.cpp' |
149 | --- src/video/movie.cpp 2013-02-08 17:53:21 +0000 |
150 | +++ src/video/movie.cpp 2013-05-01 16:44:24 +0000 |
151 | @@ -175,6 +175,15 @@ |
152 | { |
153 | char buffer[PATH_MAX]; |
154 | |
155 | + int videoWidth, videoHeight; |
156 | +#if defined(USE_OPENGL) || defined(USE_GLES) |
157 | + videoWidth = Video.ViewportWidth; |
158 | + videoHeight = Video.ViewportHeight; |
159 | +#else |
160 | + videoWidth = Video.Width; |
161 | + videoHeight = Video.Height; |
162 | +#endif |
163 | + |
164 | LibraryFileName(name.c_str(), buffer, sizeof(buffer)); |
165 | |
166 | CFile f; |
167 | @@ -195,14 +204,14 @@ |
168 | SDL_Rect rect; |
169 | |
170 | if (data.tinfo.frame_width * 300 / 4 > data.tinfo.frame_height * 100) { |
171 | - rect.w = Video.Width; |
172 | - rect.h = Video.Width * data.tinfo.frame_height / data.tinfo.frame_width; |
173 | + rect.w = videoWidth; |
174 | + rect.h = videoWidth * data.tinfo.frame_height / data.tinfo.frame_width; |
175 | rect.x = 0; |
176 | - rect.y = (Video.Height - rect.h) / 2; |
177 | + rect.y = (videoHeight - rect.h) / 2; |
178 | } else { |
179 | - rect.w = Video.Height * data.tinfo.frame_width / data.tinfo.frame_height; |
180 | - rect.h = Video.Height; |
181 | - rect.x = (Video.Width - rect.w) / 2; |
182 | + rect.w = videoHeight * data.tinfo.frame_width / data.tinfo.frame_height; |
183 | + rect.h = videoHeight; |
184 | + rect.x = (videoWidth - rect.w) / 2; |
185 | rect.y = 0; |
186 | } |
187 | |
188 | @@ -210,7 +219,7 @@ |
189 | // When SDL_OPENGL is used, it is not possible to call SDL_CreateYUVOverlay, so turn temporary OpenGL off |
190 | // With GLES is all ok |
191 | if (UseOpenGL) { |
192 | - SDL_SetVideoMode(Video.Width, Video.Height, Video.Depth, SDL_GetVideoSurface()->flags & ~SDL_OPENGL); |
193 | + SDL_SetVideoMode(Video.ViewportWidth, Video.ViewportHeight, Video.Depth, SDL_GetVideoSurface()->flags & ~SDL_OPENGL); |
194 | } |
195 | #endif |
196 | |
197 | @@ -291,7 +300,7 @@ |
198 | |
199 | #ifdef USE_OPENGL |
200 | if (UseOpenGL) { |
201 | - SDL_SetVideoMode(Video.Width, Video.Height, Video.Depth, SDL_GetVideoSurface()->flags | SDL_OPENGL); |
202 | + SDL_SetVideoMode(Video.ViewportWidth, Video.ViewportHeight, Video.Depth, SDL_GetVideoSurface()->flags | SDL_OPENGL); |
203 | ReloadOpenGL(); |
204 | } |
205 | #endif |
206 | |
207 | === modified file 'src/video/sdl.cpp' |
208 | --- src/video/sdl.cpp 2013-04-13 00:57:39 +0000 |
209 | +++ src/video/sdl.cpp 2013-05-01 16:44:24 +0000 |
210 | @@ -270,7 +270,7 @@ |
211 | |
212 | InitOpenGLExtensions(); |
213 | |
214 | - glViewport(0, 0, (GLsizei)Video.Width, (GLsizei)Video.Height); |
215 | + glViewport(0, 0, (GLsizei)Video.ViewportWidth, (GLsizei)Video.ViewportHeight); |
216 | |
217 | #ifdef USE_OPENGL |
218 | glMatrixMode(GL_PROJECTION); |
219 | @@ -628,11 +628,23 @@ |
220 | Video.Depth = 32; |
221 | } |
222 | |
223 | +#if defined(USE_OPENGL) || defined(USE_GLES) |
224 | + if (!Video.ViewportWidth || !Video.ViewportHeight) { |
225 | + Video.ViewportWidth = Video.Width; |
226 | + Video.ViewportHeight = Video.Height; |
227 | + } |
228 | + TheScreen = SDL_SetVideoMode(Video.ViewportWidth, Video.ViewportHeight, Video.Depth, flags); |
229 | +#else |
230 | TheScreen = SDL_SetVideoMode(Video.Width, Video.Height, Video.Depth, flags); |
231 | +#endif |
232 | if (TheScreen && (TheScreen->format->BitsPerPixel != 16 |
233 | && TheScreen->format->BitsPerPixel != 32)) { |
234 | // Only support 16 and 32 bpp, default to 16 |
235 | +#if defined(USE_OPENGL) || defined(USE_GLES) |
236 | + TheScreen = SDL_SetVideoMode(Video.ViewportWidth, Video.ViewportHeight, 16, flags); |
237 | +#else |
238 | TheScreen = SDL_SetVideoMode(Video.Width, Video.Height, 16, flags); |
239 | +#endif |
240 | } |
241 | if (TheScreen == NULL) { |
242 | fprintf(stderr, "Couldn't set %dx%dx%d video mode: %s\n", |
243 | @@ -643,8 +655,17 @@ |
244 | Video.FullScreen = (TheScreen->flags & SDL_FULLSCREEN) ? 1 : 0; |
245 | Video.Depth = TheScreen->format->BitsPerPixel; |
246 | |
247 | +#if defined(USE_TOUCHSCREEN) && defined(USE_WIN32) |
248 | + // Must not allow SDL to switch to relative mouse coordinates |
249 | + // with touchscreen when going fullscreen. So we don't hide the |
250 | + // cursor, but instead set a transparent 1px cursor |
251 | + Uint8 emptyCursor[] = {'\0'}; |
252 | + Video.blankCursor = SDL_CreateCursor(emptyCursor, emptyCursor, 1, 1, 0, 0); |
253 | + SDL_SetCursor(Video.blankCursor); |
254 | +#else |
255 | // Turn cursor off, we use our own. |
256 | - SDL_ShowCursor(0); |
257 | + SDL_ShowCursor(SDL_DISABLE); |
258 | +#endif |
259 | |
260 | // Make default character translation easier |
261 | SDL_EnableUNICODE(1); |
262 | @@ -797,8 +818,15 @@ |
263 | ** @param callbacks Callback structure for events. |
264 | ** @param event SDL event structure pointer. |
265 | */ |
266 | -static void SdlDoEvent(const EventCallback &callbacks, const SDL_Event &event) |
267 | +static void SdlDoEvent(const EventCallback &callbacks, SDL_Event &event) |
268 | { |
269 | +#if (defined(USE_OPENGL) || defined(USE_GLES)) |
270 | + // Scale mouse-coordinates to viewport |
271 | + if (ZoomNoResize && (event.type & (SDL_MOUSEBUTTONUP | SDL_MOUSEBUTTONDOWN | SDL_MOUSEMOTION))) { |
272 | + event.button.x = (Uint16)floor(event.button.x * float(Video.Width) / Video.ViewportWidth); |
273 | + event.button.y = (Uint16)floor(event.button.y * float(Video.Height) / Video.ViewportHeight); |
274 | + } |
275 | +#endif |
276 | switch (event.type) { |
277 | case SDL_MOUSEBUTTONDOWN: |
278 | InputMouseButtonPress(callbacks, SDL_GetTicks(), event.button.button); |
279 | @@ -1151,10 +1179,16 @@ |
280 | } |
281 | } |
282 | |
283 | +#ifndef USE_TOUCHSCREEN |
284 | + // Cannot hide cursor on Windows with touchscreen, as it switches |
285 | + // to relative mouse coordinates in fullscreen. See above initial |
286 | + // call to ShowCursor |
287 | + // |
288 | // Windows shows the SDL cursor when starting in fullscreen mode |
289 | // then switching to window mode. This hides the cursor again. |
290 | SDL_ShowCursor(SDL_ENABLE); |
291 | SDL_ShowCursor(SDL_DISABLE); |
292 | +#endif |
293 | |
294 | #if defined(USE_OPENGL) || defined(USE_GLES) |
295 | if (UseOpenGL) { |
296 | |
297 | === modified file 'src/video/video.cpp' |
298 | --- src/video/video.cpp 2013-04-13 00:57:39 +0000 |
299 | +++ src/video/video.cpp 2013-05-01 16:44:24 +0000 |
300 | @@ -168,6 +168,7 @@ |
301 | #if defined(USE_OPENGL) || defined(USE_GLES) |
302 | char ForceUseOpenGL; |
303 | bool UseOpenGL; /// Use OpenGL |
304 | +bool ZoomNoResize; |
305 | #endif |
306 | |
307 | char VideoForceFullScreen; /// fullscreen set from commandline |
308 | @@ -289,14 +290,24 @@ |
309 | UI.Minimap.FreeOpenGL(); |
310 | } |
311 | #endif |
312 | + TheScreen = SDL_SetVideoMode(w, h, TheScreen->format->BitsPerPixel, TheScreen->flags); |
313 | +#if defined(USE_OPENGL) || defined(USE_GLES) |
314 | + ViewportWidth = w; |
315 | + ViewportHeight = h; |
316 | + if (ZoomNoResize) { |
317 | + ReloadOpenGL(); |
318 | + } else { |
319 | + Width = w; |
320 | + Height = h; |
321 | + SetClipping(0, 0, Video.Width - 1, Video.Height - 1); |
322 | + if (UseOpenGL) { |
323 | + ReloadOpenGL(); |
324 | + } |
325 | + } |
326 | +#else |
327 | Width = w; |
328 | Height = h; |
329 | - TheScreen = SDL_SetVideoMode(w, h, TheScreen->format->BitsPerPixel, TheScreen->flags); |
330 | SetClipping(0, 0, Video.Width - 1, Video.Height - 1); |
331 | -#if defined(USE_OPENGL) || defined(USE_GLES) |
332 | - if (UseOpenGL) { |
333 | - ReloadOpenGL(); |
334 | - } |
335 | #endif |
336 | return true; |
337 | } |
Goooooooooooooo ooooood.