Merge lp:~widelands-dev/widelands/remove_cached_resizing into lp:widelands
- remove_cached_resizing
- Merge into trunk
Proposed by
SirVer
Status: | Merged | ||||
---|---|---|---|---|---|
Merged at revision: | 7303 | ||||
Proposed branch: | lp:~widelands-dev/widelands/remove_cached_resizing | ||||
Merge into: | lp:widelands | ||||
Diff against target: |
1231 lines (+210/-349) 29 files modified
CMakeLists.txt (+0/-1) cmake/Modules/FindSDL2_gfx.cmake (+0/-60) cmake/WlFunctions.cmake (+0/-6) src/editor/ui_menus/categorized_item_selection_menu.h (+1/-9) src/editor/ui_menus/editor_tool_set_terrain_options_menu.cc (+19/-8) src/graphic/CMakeLists.txt (+0/-1) src/graphic/animation.cc (+1/-1) src/graphic/image_transformations.cc (+0/-110) src/graphic/image_transformations.h (+0/-3) src/graphic/rendertarget.cc (+40/-17) src/graphic/rendertarget.h (+8/-0) src/graphic/surface.cc (+3/-2) src/graphic/surface.h (+1/-1) src/graphic/text/CMakeLists.txt (+0/-1) src/graphic/text/rt_render.cc (+21/-11) src/graphic/texture.cc (+1/-1) src/graphic/texture.h (+1/-1) src/graphic/texture_atlas.cc (+4/-3) src/ui_basic/button.cc (+15/-9) src/ui_basic/icon.cc (+10/-5) src/ui_basic/icon.h (+2/-1) src/ui_basic/progresswindow.cc (+10/-22) src/ui_basic/progresswindow.h (+0/-3) src/ui_basic/tabpanel.cc (+56/-41) src/ui_fsmenu/base.cc (+3/-6) src/ui_fsmenu/base.h (+1/-1) src/ui_fsmenu/loadgame.cc (+2/-6) src/wui/fieldaction.cc (+10/-18) utils/win32/mingw/Makefile (+1/-1) |
||||
To merge this branch: | bzr merge lp:~widelands-dev/widelands/remove_cached_resizing | ||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Tino | Approve | ||
Review via email: mp+243584@code.launchpad.net |
Commit message
Description of the change
Suggested commit message:
- Remove ImageTransforma
- Removes the dependency to sdl_gfx and all mentions of it in the project.
- Buttons and tab panels will now shrink images to fit in their drawing area. This exposes some overly big graphics we use in some places.
- Increase the size of the buildings in the BuildGrid preview from 34 pixels to 50. I think that looks much nicer
To post a comment you must log in.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'CMakeLists.txt' |
2 | --- CMakeLists.txt 2014-11-12 21:01:23 +0000 |
3 | +++ CMakeLists.txt 2014-12-04 06:52:36 +0000 |
4 | @@ -44,7 +44,6 @@ |
5 | find_package(OpenGL REQUIRED) |
6 | find_package(PNG REQUIRED) |
7 | find_package(SDL2 REQUIRED) |
8 | -find_package(SDL2_gfx REQUIRED) |
9 | find_package(SDL2_image REQUIRED) |
10 | find_package(SDL2_mixer REQUIRED) |
11 | find_package(SDL2_net REQUIRED) |
12 | |
13 | === removed file 'cmake/Modules/FindSDL2_gfx.cmake' |
14 | --- cmake/Modules/FindSDL2_gfx.cmake 2014-10-13 15:04:50 +0000 |
15 | +++ cmake/Modules/FindSDL2_gfx.cmake 1970-01-01 00:00:00 +0000 |
16 | @@ -1,60 +0,0 @@ |
17 | -# Locate SDL2_gfx library |
18 | -# This module defines |
19 | -# SDL2GFX_LIBRARY, the name of the library to link against |
20 | -# SDL2GFX_FOUND, if false, do not try to link to SDL2 |
21 | -# SDL2GFX_INCLUDE_DIR, where to find SDL2/SDL.h |
22 | -# |
23 | -# $SDLDIR is an environment variable that would |
24 | -# correspond to the ./configure --prefix=$SDL2DIR |
25 | -# used in building SDL2. |
26 | -# |
27 | -# Created by Eric Wing. This was influenced by the FindSDL.cmake |
28 | -# module, but with modifications to recognize OS X frameworks and |
29 | -# additional Unix paths (FreeBSD, etc). |
30 | - |
31 | -FIND_PATH(SDL2GFX_INCLUDE_DIR SDL2_framerate.h |
32 | - SDL2_gfxPrimitives.h |
33 | - SDL2_imageFilter.h SDL2_rotozoom.h |
34 | - HINTS |
35 | - $ENV{SDL2GFXDIR} |
36 | - $ENV{SDL2DIR} |
37 | - PATH_SUFFIXES include SDL2 |
38 | - PATHS |
39 | - ~/Library/Frameworks |
40 | - /Library/Frameworks |
41 | - /usr/local/include/SDL2 |
42 | - /usr/include/SDL2 |
43 | - /usr/local/include |
44 | - /usr/include |
45 | - /sw/include/SDL2 # Fink |
46 | - /sw/include |
47 | - /opt/local/include/SDL2 # DarwinPorts |
48 | - /opt/local/include |
49 | - /opt/csw/include/SDL2 # Blastwave |
50 | - /opt/csw/include |
51 | - /opt/include/SDL2 |
52 | - /opt/include |
53 | -) |
54 | - |
55 | -FIND_LIBRARY(SDL2GFX_LIBRARY |
56 | - NAMES SDL2_gfx |
57 | - HINTS |
58 | - $ENV{SDL2GFXDIR} |
59 | - $ENV{SDL2DIR} |
60 | - PATH_SUFFIXES lib64 lib |
61 | - PATHS |
62 | - ~/Library/Frameworks |
63 | - /Library/Frameworks |
64 | - /usr/local |
65 | - /usr |
66 | - /sw |
67 | - /opt/local |
68 | - /opt/csw |
69 | - /opt |
70 | -) |
71 | - |
72 | -SET(SDL2GFX_FOUND "NO") |
73 | -IF(SDL2GFX_LIBRARY AND SDL2GFX_INCLUDE_DIR) |
74 | - SET(SDL2GFX_FOUND "YES") |
75 | -ENDIF(SDL2GFX_LIBRARY AND SDL2GFX_INCLUDE_DIR) |
76 | - |
77 | |
78 | === modified file 'cmake/WlFunctions.cmake' |
79 | --- cmake/WlFunctions.cmake 2014-11-12 20:12:48 +0000 |
80 | +++ cmake/WlFunctions.cmake 2014-12-04 06:52:36 +0000 |
81 | @@ -10,7 +10,6 @@ |
82 | USES_OPENGL |
83 | USES_PNG |
84 | USES_SDL2 |
85 | - USES_SDL2_GFX |
86 | USES_SDL2_IMAGE |
87 | USES_SDL2_MIXER |
88 | USES_SDL2_NET |
89 | @@ -118,11 +117,6 @@ |
90 | target_link_libraries(${NAME} ${SDL2IMAGE_LIBRARY}) |
91 | endif() |
92 | |
93 | - if(ARG_USES_SDL2_GFX) |
94 | - wl_include_system_directories(${NAME} ${SDL2GFX_INCLUDE_DIR}) |
95 | - target_link_libraries(${NAME} ${SDL2GFX_LIBRARY}) |
96 | - endif() |
97 | - |
98 | if(ARG_USES_SDL2_TTF) |
99 | wl_include_system_directories(${NAME} ${SDL2TTF_INCLUDE_DIR}) |
100 | target_link_libraries(${NAME} ${SDL2TTF_LIBRARY}) |
101 | |
102 | === modified file 'src/editor/ui_menus/categorized_item_selection_menu.h' |
103 | --- src/editor/ui_menus/categorized_item_selection_menu.h 2014-10-14 06:30:20 +0000 |
104 | +++ src/editor/ui_menus/categorized_item_selection_menu.h 2014-12-04 06:52:36 +0000 |
105 | @@ -122,15 +122,7 @@ |
106 | horizontal->add_space(kSpacing); |
107 | ++nitems_handled; |
108 | } |
109 | - |
110 | - const Image* category_picture = category.picture(); |
111 | - const int kCategoryImageSize = 24; |
112 | - if (category_picture->width() > kCategoryImageSize || |
113 | - category_picture->height() > kCategoryImageSize) { |
114 | - category_picture = |
115 | - ImageTransformations::resize(category_picture, kCategoryImageSize, kCategoryImageSize); |
116 | - } |
117 | - tab_panel->add(category.name(), category_picture, vertical, category.descname()); |
118 | + tab_panel->add(category.name(), category.picture(), vertical, category.descname()); |
119 | } |
120 | add(¤t_selection_names_, UI::Align_Center, true); |
121 | } |
122 | |
123 | === modified file 'src/editor/ui_menus/editor_tool_set_terrain_options_menu.cc' |
124 | --- src/editor/ui_menus/editor_tool_set_terrain_options_menu.cc 2014-11-27 21:29:21 +0000 |
125 | +++ src/editor/ui_menus/editor_tool_set_terrain_options_menu.cc 2014-12-04 06:52:36 +0000 |
126 | @@ -76,44 +76,55 @@ |
127 | |
128 | const Texture& terrain_texture = terrain_descr.get_texture(0); |
129 | Texture* texture = new Texture(terrain_texture.width(), terrain_texture.height()); |
130 | - texture->blit(Point(0, 0), |
131 | + texture->blit(Rect(0, 0, terrain_texture.width(), terrain_texture.height()), |
132 | &terrain_texture, |
133 | Rect(0, 0, terrain_texture.width(), terrain_texture.height())); |
134 | Point pt(1, terrain_texture.height() - kSmallPicHeight - 1); |
135 | |
136 | if (ter_is == TerrainDescription::GREEN) { |
137 | - texture->blit(pt, green->texture(), Rect(0, 0, green->width(), green->height())); |
138 | + texture->blit(Rect(pt.x, pt.y, green->width(), green->height()), |
139 | + green->texture(), |
140 | + Rect(0, 0, green->width(), green->height())); |
141 | pt.x += kSmallPicWidth + 1; |
142 | /** TRANSLATORS: This is a terrain type tooltip in the editor */ |
143 | tooltips.push_back(_("arable")); |
144 | } else { |
145 | if (ter_is & TerrainDescription::WATER) { |
146 | - texture->blit(pt, water->texture(), Rect(0, 0, water->width(), water->height())); |
147 | + texture->blit(Rect(pt.x, pt.y, water->width(), water->height()), |
148 | + water->texture(), |
149 | + Rect(0, 0, water->width(), water->height())); |
150 | pt.x += kSmallPicWidth + 1; |
151 | /** TRANSLATORS: This is a terrain type tooltip in the editor */ |
152 | tooltips.push_back(_("aquatic")); |
153 | } |
154 | else if (ter_is & TerrainDescription::MOUNTAIN) { |
155 | - texture->blit(pt, mountain->texture(), Rect(0, 0, mountain->width(), mountain->height())); |
156 | + texture->blit(Rect(pt.x, pt.y, mountain->width(), mountain->height()), |
157 | + mountain->texture(), |
158 | + Rect(0, 0, mountain->width(), mountain->height())); |
159 | pt.x += kSmallPicWidth + 1; |
160 | /** TRANSLATORS: This is a terrain type tooltip in the editor */ |
161 | tooltips.push_back(_("mountainous")); |
162 | } |
163 | if (ter_is & TerrainDescription::ACID) { |
164 | - texture->blit(pt, dead->texture(), Rect(0, 0, dead->width(), dead->height())); |
165 | + texture->blit(Rect(pt.x, pt.y, dead->width(), dead->height()), |
166 | + dead->texture(), |
167 | + Rect(0, 0, dead->width(), dead->height())); |
168 | pt.x += kSmallPicWidth + 1; |
169 | /** TRANSLATORS: This is a terrain type tooltip in the editor */ |
170 | tooltips.push_back(_("dead")); |
171 | } |
172 | if (ter_is & TerrainDescription::UNPASSABLE) { |
173 | - texture->blit( |
174 | - pt, unpassable->texture(), Rect(0, 0, unpassable->width(), unpassable->height())); |
175 | + texture->blit(Rect(pt.x, pt.y, unpassable->width(), unpassable->height()), |
176 | + unpassable->texture(), |
177 | + Rect(0, 0, unpassable->width(), unpassable->height())); |
178 | pt.x += kSmallPicWidth + 1; |
179 | /** TRANSLATORS: This is a terrain type tooltip in the editor */ |
180 | tooltips.push_back(_("unpassable")); |
181 | } |
182 | if (ter_is & TerrainDescription::DRY) { |
183 | - texture->blit(pt, dry->texture(), Rect(0, 0, dry->width(), dry->height())); |
184 | + texture->blit(Rect(pt.x, pt.y, dry->width(), dry->height()), |
185 | + dry->texture(), |
186 | + Rect(0, 0, dry->width(), dry->height())); |
187 | /** TRANSLATORS: This is a terrain type tooltip in the editor */ |
188 | tooltips.push_back(_("treeless")); |
189 | } |
190 | |
191 | === modified file 'src/graphic/CMakeLists.txt' |
192 | --- src/graphic/CMakeLists.txt 2014-12-01 21:28:21 +0000 |
193 | +++ src/graphic/CMakeLists.txt 2014-12-04 06:52:36 +0000 |
194 | @@ -131,7 +131,6 @@ |
195 | wordwrap.h |
196 | USES_OPENGL |
197 | USES_SDL2 |
198 | - USES_SDL2_GFX |
199 | USES_SDL2_TTF |
200 | DEPENDS |
201 | base_exceptions |
202 | |
203 | === modified file 'src/graphic/animation.cc' |
204 | --- src/graphic/animation.cc 2014-11-28 16:40:55 +0000 |
205 | +++ src/graphic/animation.cc 2014-12-04 06:52:36 +0000 |
206 | @@ -323,7 +323,7 @@ |
207 | assert(target); |
208 | |
209 | const Image& frame = get_frame(time, clr); |
210 | - target->blit(dst, frame.texture(), srcrc); |
211 | + target->blit(Rect(dst.x, dst.y, srcrc.w, srcrc.h), frame.texture(), srcrc); |
212 | } |
213 | |
214 | const Image& NonPackedAnimation::get_frame(uint32_t time, const RGBColor* playercolor) const { |
215 | |
216 | === modified file 'src/graphic/image_transformations.cc' |
217 | --- src/graphic/image_transformations.cc 2014-11-26 19:53:52 +0000 |
218 | +++ src/graphic/image_transformations.cc 2014-12-04 06:52:36 +0000 |
219 | @@ -22,7 +22,6 @@ |
220 | #include <string> |
221 | |
222 | #include <SDL.h> |
223 | -#include <SDL2_rotozoom.h> |
224 | #include <boost/format.hpp> |
225 | |
226 | #include "base/macros.h" |
227 | @@ -77,79 +76,6 @@ |
228 | } |
229 | |
230 | /** |
231 | - * Produces a resized version of the specified image |
232 | - */ |
233 | -Texture* resize_surface(Texture* src, uint32_t w, uint32_t h) { |
234 | - assert(w != src->width() || h != src->height()); |
235 | - |
236 | - // First step: compute scaling factors |
237 | - Rect srcrect = Rect(Point(0, 0), src->width(), src->height()); |
238 | - |
239 | - // Second step: get source material |
240 | - SDL_Surface * srcsdl = extract_sdl_surface(*src, srcrect); |
241 | - bool free_source = true; |
242 | - |
243 | - // If we actually shrink a texture, ballpark the zoom so that the shrinking |
244 | - // effect is weakened. |
245 | - int factor = 1; |
246 | - while ((static_cast<double>(w) * factor / srcsdl->w) < 1. || |
247 | - (static_cast<double>(h) * factor / srcsdl->h) < 1.) { |
248 | - ++factor; |
249 | - } |
250 | - if (factor > 2) { |
251 | - SDL_Surface* temp = shrinkSurface(srcsdl, factor - 1, factor - 1); |
252 | - if (free_source) { |
253 | - SDL_FreeSurface(srcsdl); |
254 | - } |
255 | - srcsdl = temp; |
256 | - free_source = true; |
257 | - } |
258 | - |
259 | - // Third step: perform the zoom and placement |
260 | - SDL_Surface* zoomed = zoomSurface(srcsdl, double(w) / srcsdl->w, double(h) / srcsdl->h, 1); |
261 | - |
262 | - if (free_source) |
263 | - SDL_FreeSurface(srcsdl); |
264 | - |
265 | - if (uint32_t(zoomed->w) != w || uint32_t(zoomed->h) != h) { |
266 | - const SDL_PixelFormat & fmt = *zoomed->format; |
267 | - SDL_Surface * placed = SDL_CreateRGBSurface |
268 | - (SDL_SWSURFACE, w, h, |
269 | - fmt.BitsPerPixel, fmt.Rmask, fmt.Gmask, fmt.Bmask, fmt.Amask); |
270 | - SDL_Rect srcrc = |
271 | - {0, 0, |
272 | - static_cast<uint16_t>(zoomed->w), static_cast<uint16_t>(zoomed->h) |
273 | - }; // For some reason SDL_Surface and SDL_Rect express w,h in different types |
274 | - SDL_Rect dstrc = {0, 0, 0, 0}; |
275 | - SDL_SetSurfaceAlphaMod(zoomed, SDL_ALPHA_TRANSPARENT); |
276 | - SDL_SetSurfaceBlendMode(zoomed, SDL_BLENDMODE_NONE); |
277 | - SDL_BlitSurface(zoomed, &srcrc, placed, &dstrc); // Updates dstrc |
278 | - |
279 | - uint32_t fillcolor = SDL_MapRGBA(zoomed->format, 0, 0, 0, 255); |
280 | - |
281 | - if (zoomed->w < placed->w) { |
282 | - dstrc.x = zoomed->w; |
283 | - dstrc.y = 0; |
284 | - dstrc.w = placed->w - zoomed->w; |
285 | - dstrc.h = zoomed->h; |
286 | - SDL_FillRect(placed, &dstrc, fillcolor); |
287 | - } |
288 | - if (zoomed->h < placed->h) { |
289 | - dstrc.x = 0; |
290 | - dstrc.y = zoomed->h; |
291 | - dstrc.w = placed->w; |
292 | - dstrc.h = placed->h - zoomed->h; |
293 | - SDL_FillRect(placed, &dstrc, fillcolor); |
294 | - } |
295 | - |
296 | - SDL_FreeSurface(zoomed); |
297 | - zoomed = placed; |
298 | - } |
299 | - |
300 | - return new Texture(zoomed); |
301 | -} |
302 | - |
303 | -/** |
304 | * Create a grayed version of the given texture. |
305 | */ |
306 | Texture* gray_out_texture(Texture* texture) { |
307 | @@ -320,31 +246,6 @@ |
308 | TextureCache* const texture_cache_; // not owned |
309 | }; |
310 | |
311 | -// A resized copy of an Image. |
312 | -class ResizedImage : public TransformedImage { |
313 | -public: |
314 | - ResizedImage |
315 | - (const string& ghash, const Image& original, |
316 | - TextureCache* texture_cache, uint16_t w, uint16_t h) |
317 | - : TransformedImage(ghash, original, texture_cache), w_(w), h_(h) { |
318 | - assert(w != original.width() || h != original.height()); |
319 | - } |
320 | - virtual ~ResizedImage() {} |
321 | - |
322 | - // Overwrites TransformedImage. |
323 | - uint16_t width() const override {return w_;} |
324 | - uint16_t height() const override {return h_;} |
325 | - |
326 | - // Implements TransformedImage. |
327 | - Texture* recalculate_texture() const override { |
328 | - Texture* rv = resize_surface(original_.texture(), w_, h_); |
329 | - return rv; |
330 | - } |
331 | - |
332 | -private: |
333 | - uint16_t w_, h_; |
334 | -}; |
335 | - |
336 | // A grayed out copy of an Image. |
337 | class GrayedOutImage : public TransformedImage { |
338 | public: |
339 | @@ -419,17 +320,6 @@ |
340 | } |
341 | } |
342 | |
343 | -const Image* resize(const Image* original, uint16_t w, uint16_t h) { |
344 | - if (original->width() == w && original->height() == h) |
345 | - return original; |
346 | - |
347 | - const string new_hash = (boost::format("%s:%i:%i") % original->hash() % w % h).str(); |
348 | - if (g_gr->images().has(new_hash)) |
349 | - return g_gr->images().get(new_hash); |
350 | - return |
351 | - g_gr->images().insert(new ResizedImage(new_hash, *original, &g_gr->textures(), w, h)); |
352 | -} |
353 | - |
354 | const Image* gray_out(const Image* original) { |
355 | const string new_hash = original->hash() + ":greyed_out"; |
356 | if (g_gr->images().has(new_hash)) |
357 | |
358 | === modified file 'src/graphic/image_transformations.h' |
359 | --- src/graphic/image_transformations.h 2014-07-05 16:41:51 +0000 |
360 | +++ src/graphic/image_transformations.h 2014-12-04 06:52:36 +0000 |
361 | @@ -37,9 +37,6 @@ |
362 | // safe to call the methods with the same arguments multiple times without |
363 | // construction cost. |
364 | |
365 | -// Returns a resized image of the original. |
366 | -const Image* resize(const Image* original, uint16_t w, uint16_t h); |
367 | - |
368 | // Returns a grayed out image of the original. |
369 | const Image* gray_out(const Image* original); |
370 | |
371 | |
372 | === modified file 'src/graphic/rendertarget.cc' |
373 | --- src/graphic/rendertarget.cc 2014-11-30 17:11:22 +0000 |
374 | +++ src/graphic/rendertarget.cc 2014-12-04 06:52:36 +0000 |
375 | @@ -163,19 +163,22 @@ |
376 | * Blits a Image on another Surface |
377 | * |
378 | * This blit function copies the pixels to the destination surface. |
379 | - * If the source surface contains a alpha channel this is used during |
380 | - * the blit. |
381 | */ |
382 | void RenderTarget::blit(const Point& dst, const Image* image, BlendMode blend_mode, UI::Align align) |
383 | { |
384 | - Point dstpoint(dst); |
385 | + Point destination_point(dst); |
386 | |
387 | - UI::correct_for_align(align, image->width(), image->height(), &dstpoint); |
388 | + UI::correct_for_align(align, image->width(), image->height(), &destination_point); |
389 | |
390 | Rect srcrc(Point(0, 0), image->width(), image->height()); |
391 | |
392 | - if (to_surface_geometry(&dstpoint, &srcrc)) |
393 | - m_surface->blit(dstpoint, image->texture(), srcrc, blend_mode); |
394 | + if (to_surface_geometry(&destination_point, &srcrc)) { |
395 | + m_surface->blit( |
396 | + Rect(destination_point.x, destination_point.y, srcrc.w, srcrc.h), |
397 | + image->texture(), |
398 | + srcrc, |
399 | + blend_mode); |
400 | + } |
401 | } |
402 | |
403 | /** |
404 | @@ -194,9 +197,28 @@ |
405 | std::min<int32_t>(image->width() - gsrcrc.x, gsrcrc.w), |
406 | std::min<int32_t>(image->height() - gsrcrc.y, gsrcrc.h)); |
407 | |
408 | - Point dstpt(dst); |
409 | - if (to_surface_geometry(&dstpt, &srcrc)) |
410 | - m_surface->blit(dstpt, image->texture(), srcrc, blend_mode); |
411 | + Point destination_point(dst); |
412 | + if (to_surface_geometry(&destination_point, &srcrc)) |
413 | + m_surface->blit( |
414 | + Rect(destination_point.x, destination_point.y, srcrc.w, srcrc.h), |
415 | + image->texture(), |
416 | + srcrc, |
417 | + blend_mode); |
418 | +} |
419 | + |
420 | +void RenderTarget::blitrect_scale(const Rect& dst, |
421 | + const Image* image, |
422 | + const Rect& src, |
423 | + const BlendMode blend_mode) { |
424 | + |
425 | + Point destination_point(dst.x, dst.y); |
426 | + Rect srcrect(src); |
427 | + if (to_surface_geometry(&destination_point, &srcrect)) { |
428 | + m_surface->blit(Rect(destination_point.x, destination_point.y, dst.w, dst.h), |
429 | + image->texture(), |
430 | + src, |
431 | + blend_mode); |
432 | + } |
433 | } |
434 | |
435 | /** |
436 | @@ -251,7 +273,8 @@ |
437 | if (tx + srcrc.w > r.w) |
438 | srcrc.w = r.w - tx; |
439 | |
440 | - m_surface->blit(r.top_left() + Point(tx, ty), image->texture(), srcrc, blend_mode); |
441 | + const Rect dst_rect(r.x + tx, r.y + ty, srcrc.w, srcrc.h); |
442 | + m_surface->blit(dst_rect, image->texture(), srcrc, blend_mode); |
443 | |
444 | tx += srcrc.w; |
445 | |
446 | @@ -283,12 +306,12 @@ |
447 | { |
448 | const Animation& anim = g_gr->animations().get_animation(animation); |
449 | |
450 | - Point dstpt = dst - anim.hotspot(); |
451 | + Point destination_point = dst - anim.hotspot(); |
452 | |
453 | Rect srcrc(Point(0, 0), anim.width(), anim.height()); |
454 | |
455 | - if (to_surface_geometry(&dstpt, &srcrc)) |
456 | - anim.blit(time, dstpt, srcrc, player ? &player->get_playercolor() : NULL, m_surface); |
457 | + if (to_surface_geometry(&destination_point, &srcrc)) |
458 | + anim.blit(time, destination_point, srcrc, player ? &player->get_playercolor() : NULL, m_surface); |
459 | |
460 | // Look if there is a sound effect registered for this frame and trigger |
461 | // the effect (see SoundHandler::stereo_position). |
462 | @@ -303,13 +326,13 @@ |
463 | { |
464 | const Animation& anim = g_gr->animations().get_animation(animation); |
465 | |
466 | - Point dstpt = dst - anim.hotspot(); |
467 | - dstpt += gsrcrc.top_left(); |
468 | + Point destination_point = dst - anim.hotspot(); |
469 | + destination_point += gsrcrc.top_left(); |
470 | |
471 | Rect srcrc(gsrcrc); |
472 | |
473 | - if (to_surface_geometry(&dstpt, &srcrc)) |
474 | - anim.blit(time, dstpt, srcrc, player ? &player->get_playercolor() : NULL, m_surface); |
475 | + if (to_surface_geometry(&destination_point, &srcrc)) |
476 | + anim.blit(time, destination_point, srcrc, player ? &player->get_playercolor() : NULL, m_surface); |
477 | } |
478 | |
479 | /** |
480 | |
481 | === modified file 'src/graphic/rendertarget.h' |
482 | --- src/graphic/rendertarget.h 2014-11-24 07:25:21 +0000 |
483 | +++ src/graphic/rendertarget.h 2014-12-04 06:52:36 +0000 |
484 | @@ -49,6 +49,8 @@ |
485 | * \note If the sub-window would be empty/invisible, \ref enter_window() returns |
486 | * false and doesn't change the window state at all. |
487 | */ |
488 | +// TODO(sirver): remove window functions and merge with surface once |
489 | +// the old richtext renderer is gone. |
490 | class RenderTarget { |
491 | public: |
492 | RenderTarget(Surface*); |
493 | @@ -74,6 +76,12 @@ |
494 | const Rect& src, |
495 | BlendMode blend_mode = BlendMode::UseAlpha); |
496 | |
497 | + void blitrect_scale( |
498 | + const Rect& dst, |
499 | + const Image* image, |
500 | + const Rect& src, |
501 | + BlendMode blend_mode = BlendMode::UseAlpha); |
502 | + |
503 | void tile(const Rect&, |
504 | const Image* image, |
505 | const Point& ofs, |
506 | |
507 | === modified file 'src/graphic/surface.cc' |
508 | --- src/graphic/surface.cc 2014-11-27 20:31:39 +0000 |
509 | +++ src/graphic/surface.cc 2014-12-04 06:52:36 +0000 |
510 | @@ -158,7 +158,7 @@ |
511 | } |
512 | |
513 | void Surface::blit |
514 | - (const Point& dst, const Texture* texture, const Rect& srcrc, BlendMode blend_mode) |
515 | + (const Rect& dst, const Texture* texture, const Rect& srcrc, BlendMode blend_mode) |
516 | { |
517 | glViewport(0, 0, width(), height()); |
518 | |
519 | @@ -188,7 +188,8 @@ |
520 | gl_src_rect.h = y2 - y1; |
521 | } |
522 | |
523 | - const FloatRect gl_dst_rect = to_opengl(Rect(dst.x, dst.y, srcrc.w, srcrc.h), ConversionMode::kExact); |
524 | + const FloatRect gl_dst_rect = |
525 | + to_opengl(Rect(dst.x, dst.y, dst.w, dst.h), ConversionMode::kExact); |
526 | |
527 | BlitProgram::instance().draw(gl_dst_rect, gl_src_rect, texture->get_gl_texture(), blend_mode); |
528 | } |
529 | |
530 | === modified file 'src/graphic/surface.h' |
531 | --- src/graphic/surface.h 2014-11-24 07:25:21 +0000 |
532 | +++ src/graphic/surface.h 2014-12-04 06:52:36 +0000 |
533 | @@ -43,7 +43,7 @@ |
534 | uint16_t height() const; |
535 | |
536 | /// This draws a part of another surface to this surface |
537 | - virtual void blit(const Point&, |
538 | + virtual void blit(const Rect& dst, |
539 | const Texture*, |
540 | const Rect& srcrc, |
541 | BlendMode blend_mode = BlendMode::UseAlpha); |
542 | |
543 | === modified file 'src/graphic/text/CMakeLists.txt' |
544 | --- src/graphic/text/CMakeLists.txt 2014-11-23 10:13:14 +0000 |
545 | +++ src/graphic/text/CMakeLists.txt 2014-12-04 06:52:36 +0000 |
546 | @@ -16,7 +16,6 @@ |
547 | textstream.h |
548 | USES_SDL2 |
549 | USES_SDL2_TTF |
550 | - USES_SDL2_GFX |
551 | DEPENDS |
552 | graphic_sdl_utils |
553 | base_exceptions |
554 | |
555 | === modified file 'src/graphic/text/rt_render.cc' |
556 | --- src/graphic/text/rt_render.cc 2014-11-24 07:25:21 +0000 |
557 | +++ src/graphic/text/rt_render.cc 2014-12-04 06:52:36 +0000 |
558 | @@ -333,7 +333,10 @@ |
559 | Texture* TextNode::render(TextureCache* texture_cache) { |
560 | const Texture& img = m_font.render(m_txt, m_s.font_color, m_s.font_style, texture_cache); |
561 | Texture* rv = new Texture(img.width(), img.height()); |
562 | - rv->blit(Point(0, 0), &img, Rect(0, 0, img.width(), img.height()), BlendMode::Copy); |
563 | + rv->blit(Rect(0, 0, img.width(), img.height()), |
564 | + &img, |
565 | + Rect(0, 0, img.width(), img.height()), |
566 | + BlendMode::Copy); |
567 | return rv; |
568 | } |
569 | |
570 | @@ -361,7 +364,7 @@ |
571 | Texture* rv = new Texture(m_w, m_h); |
572 | for (uint16_t curx = 0; curx < m_w; curx += t.width()) { |
573 | Rect srcrect(Point(0, 0), min<int>(t.width(), m_w - curx), m_h); |
574 | - rv->blit(Point(curx, 0), &t, srcrect, BlendMode::Copy); |
575 | + rv->blit(Rect(curx, 0, srcrect.w, srcrect.h), &t, srcrect, BlendMode::Copy); |
576 | } |
577 | return rv; |
578 | } |
579 | @@ -423,13 +426,13 @@ |
580 | |
581 | // Draw background image (tiling) |
582 | if (m_bg) { |
583 | - Point dst; |
584 | + Rect dst; |
585 | Rect srcrect(Point(0, 0), 1, 1); |
586 | for (uint16_t curx = 0; curx < m_w; curx += m_bg->width()) { |
587 | dst.x = curx; |
588 | dst.y = 0; |
589 | - srcrect.w = min<int>(m_bg->width(), m_w - curx); |
590 | - srcrect.h = m_h; |
591 | + srcrect.w = dst.w = min<int>(m_bg->width(), m_w - curx); |
592 | + srcrect.h = dst.h = m_h; |
593 | rv->blit(dst, m_bg->texture(), srcrect, BlendMode::Copy); |
594 | } |
595 | } else { |
596 | @@ -482,14 +485,15 @@ |
597 | |
598 | // Draw background image (tiling) |
599 | if (m_bg_img) { |
600 | - Point dst; |
601 | + Rect dst; |
602 | Rect src(0, 0, 0, 0); |
603 | |
604 | for (uint16_t cury = m_margin.top; cury < m_h + m_margin.top; cury += m_bg_img->height()) { |
605 | for (uint16_t curx = m_margin.left; curx < m_w + m_margin.left; curx += m_bg_img->width()) { |
606 | - dst.x = curx; dst.y = cury; |
607 | - src.w = min<int>(m_bg_img->width(), m_w + m_margin.left - curx); |
608 | - src.h = min<int>(m_bg_img->height(), m_h + m_margin.top - cury); |
609 | + dst.x = curx; |
610 | + dst.y = cury; |
611 | + src.w = dst.w = min<int>(m_bg_img->width(), m_w + m_margin.left - curx); |
612 | + src.h = dst.h = min<int>(m_bg_img->height(), m_h + m_margin.top - cury); |
613 | rv->blit(dst, m_bg_img->texture(), src, BlendMode::Copy); |
614 | } |
615 | } |
616 | @@ -499,7 +503,10 @@ |
617 | for (RenderNode* n : m_nodes_to_render) { |
618 | Texture* node_texture = n->render(texture_cache); |
619 | if (node_texture) { |
620 | - Point dst = Point(n->x() + m_margin.left, n->y() + m_margin.top); |
621 | + Rect dst = Rect(n->x() + m_margin.left, |
622 | + n->y() + m_margin.top, |
623 | + node_texture->width(), |
624 | + node_texture->height()); |
625 | Rect src = Rect(0, 0, node_texture->width(), node_texture->height()); |
626 | |
627 | rv->blit(dst, node_texture, src, set_alpha ? BlendMode::Copy : BlendMode::UseAlpha); |
628 | @@ -553,7 +560,10 @@ |
629 | |
630 | Texture* ImgRenderNode::render(TextureCache* /* texture_cache */) { |
631 | Texture* rv = new Texture(m_image.width(), m_image.height()); |
632 | - rv->blit(Point(0, 0), m_image.texture(), Rect(0, 0, m_image.width(), m_image.height()), BlendMode::Copy); |
633 | + rv->blit(Rect(0, 0, m_image.width(), m_image.height()), |
634 | + m_image.texture(), |
635 | + Rect(0, 0, m_image.width(), m_image.height()), |
636 | + BlendMode::Copy); |
637 | return rv; |
638 | } |
639 | // End: Helper Stuff |
640 | |
641 | === modified file 'src/graphic/texture.cc' |
642 | --- src/graphic/texture.cc 2014-12-01 06:06:41 +0000 |
643 | +++ src/graphic/texture.cc 2014-12-04 06:52:36 +0000 |
644 | @@ -265,7 +265,7 @@ |
645 | } |
646 | |
647 | void Texture::blit |
648 | - (const Point& dst, const Texture* src, const Rect& srcrc, BlendMode blend_mode) |
649 | + (const Rect& dst, const Texture* src, const Rect& srcrc, BlendMode blend_mode) |
650 | { |
651 | if (m_w <= 0 || m_h <= 0) { |
652 | return; |
653 | |
654 | === modified file 'src/graphic/texture.h' |
655 | --- src/graphic/texture.h 2014-11-27 18:47:26 +0000 |
656 | +++ src/graphic/texture.h 2014-12-04 06:52:36 +0000 |
657 | @@ -58,7 +58,7 @@ |
658 | void brighten_rect(const Rect&, int32_t factor) override; |
659 | virtual void draw_line |
660 | (int32_t x1, int32_t y1, int32_t x2, int32_t y2, const RGBColor&, uint8_t width) override; |
661 | - void blit(const Point&, |
662 | + void blit(const Rect& dstretc, |
663 | const Texture*, |
664 | const Rect& srcrc, |
665 | BlendMode blend_mode = BlendMode::UseAlpha) override; |
666 | |
667 | === modified file 'src/graphic/texture_atlas.cc' |
668 | --- src/graphic/texture_atlas.cc 2014-11-28 09:02:24 +0000 |
669 | +++ src/graphic/texture_atlas.cc 2014-12-04 06:52:36 +0000 |
670 | @@ -141,9 +141,10 @@ |
671 | }); |
672 | |
673 | for (Block& block : blocks_) { |
674 | - packed_texture->blit(block.node->r.top_left(), |
675 | - block.texture, |
676 | - Rect(0, 0, block.texture->width(), block.texture->height())); |
677 | + packed_texture->blit( |
678 | + Rect(block.node->r.x, block.node->r.y, block.texture->width(), block.texture->height()), |
679 | + block.texture, |
680 | + Rect(0, 0, block.texture->width(), block.texture->height())); |
681 | textures->emplace_back(new Texture( |
682 | packed_texture->get_gl_texture(), |
683 | Rect(block.node->r.top_left(), block.texture->width(), block.texture->height()), |
684 | |
685 | === modified file 'src/ui_basic/button.cc' |
686 | --- src/ui_basic/button.cc 2014-11-22 11:32:06 +0000 |
687 | +++ src/ui_basic/button.cc 2014-12-04 06:52:36 +0000 |
688 | @@ -32,6 +32,9 @@ |
689 | |
690 | namespace UI { |
691 | |
692 | +// Margin around image. The image will be scaled down to fit into this rectangle with preserving size. |
693 | +constexpr int kButtonImageMargin = 2; |
694 | + |
695 | Button::Button // for textual buttons |
696 | (Panel * const parent, |
697 | const std::string & name, |
698 | @@ -169,16 +172,19 @@ |
699 | |
700 | // if we got a picture, draw it centered |
701 | if (m_pic_custom) { |
702 | - uint16_t cpw = m_pic_custom->width(); |
703 | - uint16_t cph = m_pic_custom->height(); |
704 | + const int max_image_w = get_w() - 2 * kButtonImageMargin; |
705 | + const int max_image_h = get_h() - 2 * kButtonImageMargin; |
706 | + double image_scale = |
707 | + std::min(1., |
708 | + std::min(static_cast<double>(max_image_w) / m_pic_custom->width(), |
709 | + static_cast<double>(max_image_h) / m_pic_custom->height())); |
710 | + int blit_width = image_scale * m_pic_custom->width(); |
711 | + int blit_height = image_scale * m_pic_custom->height(); |
712 | |
713 | - // ">> 1" is almost like "/ 2", but simpler for signed types (difference |
714 | - // is that -1 >> 1 is -1 but -1 / 2 is 0). |
715 | - dst.blit |
716 | - (Point |
717 | - ((get_w() - static_cast<int32_t>(cpw)) >> 1, |
718 | - (get_h() - static_cast<int32_t>(cph)) >> 1), |
719 | - m_enabled ? m_pic_custom : m_pic_custom_disabled); |
720 | + dst.blitrect_scale( |
721 | + Rect((get_w() - blit_width) / 2, (get_h() - blit_height) / 2, blit_width, blit_height), |
722 | + m_enabled ? m_pic_custom : m_pic_custom_disabled, |
723 | + Rect(0, 0, m_pic_custom->width(), m_pic_custom->height())); |
724 | |
725 | } else if (m_title.length()) { |
726 | // otherwise draw title string centered |
727 | |
728 | === modified file 'src/ui_basic/icon.cc' |
729 | --- src/ui_basic/icon.cc 2014-11-22 10:18:20 +0000 |
730 | +++ src/ui_basic/icon.cc 2014-12-04 06:52:36 +0000 |
731 | @@ -54,13 +54,18 @@ |
732 | m_draw_frame = false; |
733 | } |
734 | |
735 | - |
736 | - |
737 | void Icon::draw(RenderTarget & dst) { |
738 | if (m_pic) { |
739 | - int32_t w = (get_w() - m_pic->width()) / 2; |
740 | - int32_t h = (get_h() - m_pic->height()) / 2; |
741 | - dst.blit(Point(w, h), m_pic); |
742 | + double scale = std::min(static_cast<double>(get_w()) / m_pic->width(), |
743 | + static_cast<double>(get_h()) / m_pic->height()); |
744 | + scale = std::min(1., scale); |
745 | + |
746 | + int width = scale * get_w(); |
747 | + int height = scale * get_h(); |
748 | + int x = (get_w() - width) / 2; |
749 | + int y = (get_h() - height) / 2; |
750 | + dst.blitrect_scale( |
751 | + Rect(x, y, width, height), m_pic, Rect(0, 0, m_pic->width(), m_pic->height())); |
752 | } |
753 | if (m_draw_frame) { |
754 | dst.draw_rect(Rect(0, 0, get_w(), get_h()), m_framecolor); |
755 | |
756 | === modified file 'src/ui_basic/icon.h' |
757 | --- src/ui_basic/icon.h 2014-09-19 09:07:14 +0000 |
758 | +++ src/ui_basic/icon.h 2014-12-04 06:52:36 +0000 |
759 | @@ -26,7 +26,8 @@ |
760 | namespace UI { |
761 | |
762 | /** |
763 | - * A simple icon drawn in the center of the area |
764 | + * A simple icon drawn in the center of the area. If the image is |
765 | + * bigger than the icon, the image will be scaled to fit. |
766 | */ |
767 | struct Icon : public Panel { |
768 | Icon |
769 | |
770 | === modified file 'src/ui_basic/progresswindow.cc' |
771 | --- src/ui_basic/progresswindow.cc 2014-11-28 16:40:55 +0000 |
772 | +++ src/ui_basic/progresswindow.cc 2014-12-04 06:52:36 +0000 |
773 | @@ -27,7 +27,6 @@ |
774 | #include "graphic/font.h" |
775 | #include "graphic/font_handler.h" |
776 | #include "graphic/graphic.h" |
777 | -#include "graphic/image_transformations.h" |
778 | #include "graphic/rendertarget.h" |
779 | #include "io/filesystem/layered_filesystem.h" |
780 | #include "wui/text_constants.h" |
781 | @@ -42,10 +41,7 @@ |
782 | |
783 | namespace UI { |
784 | |
785 | -ProgressWindow::ProgressWindow(const std::string & background) |
786 | - : m_xres(0), m_yres(0), |
787 | - m_background_pic(nullptr) |
788 | -{ |
789 | +ProgressWindow::ProgressWindow(const std::string& background) { |
790 | set_background(background); |
791 | step(_("Preparing...")); |
792 | } |
793 | @@ -63,22 +59,15 @@ |
794 | m_label_center.y = yres * PROGRESS_LABEL_POSITION_Y / 100; |
795 | Rect wnd_rect(Point(0, 0), xres, yres); |
796 | |
797 | - if (!m_background_pic || xres != m_xres || yres != m_yres) { |
798 | - // (Re-)Load background graphics |
799 | - m_background_pic = ImageTransformations::resize(g_gr->images().get(m_background), xres, yres); |
800 | - |
801 | - const uint32_t h = g_fh->get_fontheight (UI_FONT_SMALL); |
802 | - m_label_rectangle.x = xres / 4; |
803 | - m_label_rectangle.w = xres / 2; |
804 | - m_label_rectangle.y = |
805 | - m_label_center.y - h / 2 - PROGRESS_STATUS_RECT_PADDING; |
806 | - m_label_rectangle.h = h + 2 * PROGRESS_STATUS_RECT_PADDING; |
807 | - // remember last resolution |
808 | - m_xres = xres; |
809 | - m_yres = yres; |
810 | - } |
811 | - |
812 | - rt.blit(Point(0, 0), m_background_pic); |
813 | + const uint32_t h = g_fh->get_fontheight (UI_FONT_SMALL); |
814 | + m_label_rectangle.x = xres / 4; |
815 | + m_label_rectangle.w = xres / 2; |
816 | + m_label_rectangle.y = |
817 | + m_label_center.y - h / 2 - PROGRESS_STATUS_RECT_PADDING; |
818 | + m_label_rectangle.h = h + 2 * PROGRESS_STATUS_RECT_PADDING; |
819 | + |
820 | + const Image* bg = g_gr->images().get(m_background); |
821 | + rt.blitrect_scale(Rect(0, 0, xres, yres), bg, Rect(0, 0, bg->width(), bg->height())); |
822 | |
823 | Rect border_rect = m_label_rectangle; |
824 | border_rect.x -= PROGRESS_STATUS_BORDER_X; |
825 | @@ -97,7 +86,6 @@ |
826 | } else { |
827 | m_background = "pics/progress.png"; |
828 | } |
829 | - m_background_pic = nullptr; |
830 | draw_background(rt, g_gr->get_xres(), g_gr->get_yres()); |
831 | update(true); |
832 | } |
833 | |
834 | === modified file 'src/ui_basic/progresswindow.h' |
835 | --- src/ui_basic/progresswindow.h 2014-09-14 11:31:58 +0000 |
836 | +++ src/ui_basic/progresswindow.h 2014-12-04 06:52:36 +0000 |
837 | @@ -62,13 +62,10 @@ |
838 | |
839 | private: |
840 | using VisualizationArray = std::vector<IProgressVisualization *>; |
841 | - uint32_t m_xres; |
842 | - uint32_t m_yres; |
843 | Point m_label_center; |
844 | Rect m_label_rectangle; |
845 | VisualizationArray m_visualizations; |
846 | std::string m_background; |
847 | - const Image* m_background_pic; |
848 | |
849 | void draw_background(RenderTarget & rt, uint32_t xres, uint32_t yres); |
850 | void update(bool repaint); |
851 | |
852 | === modified file 'src/ui_basic/tabpanel.cc' |
853 | --- src/ui_basic/tabpanel.cc 2014-09-10 14:48:40 +0000 |
854 | +++ src/ui_basic/tabpanel.cc 2014-12-04 06:52:36 +0000 |
855 | @@ -23,11 +23,15 @@ |
856 | #include "ui_basic/mouse_constants.h" |
857 | |
858 | namespace UI { |
859 | -#define TP_BUTTON_WIDTH 34 |
860 | -#define TP_BUTTON_HEIGHT 34 |
861 | + |
862 | +// Button size of tab buttons in pixels. |
863 | +constexpr int kTabPanelButtonSize = 34; |
864 | + |
865 | +// Margin around image. The image will be scaled down to fit into this rectangle with preserving size. |
866 | +constexpr int kTabPanelImageMargin = 2; |
867 | |
868 | // height of the bar separating buttons and tab contents |
869 | -#define TP_SEPARATOR_HEIGHT 4 |
870 | +constexpr int kTabPanelSeparatorHeight = 4; |
871 | |
872 | /* |
873 | * ================= |
874 | @@ -43,8 +47,8 @@ |
875 | Panel * const gpanel) |
876 | : |
877 | NamedPanel |
878 | - (parent, name, id * TP_BUTTON_WIDTH, 0, TP_BUTTON_WIDTH, |
879 | - TP_BUTTON_HEIGHT, gtooltip), |
880 | + (parent, name, id * kTabPanelButtonSize, 0, kTabPanelButtonSize, |
881 | + kTabPanelButtonSize, gtooltip), |
882 | m_parent(parent), |
883 | m_id(id), |
884 | pic(gpic), |
885 | @@ -102,7 +106,7 @@ |
886 | uint32_t h = get_h(); |
887 | |
888 | // avoid excessive craziness in case there is a wraparound |
889 | - h = std::min(h, h - (TP_BUTTON_HEIGHT + TP_SEPARATOR_HEIGHT)); |
890 | + h = std::min(h, h - (kTabPanelButtonSize + kTabPanelSeparatorHeight)); |
891 | panel->set_size(get_w(), h); |
892 | } |
893 | } |
894 | @@ -116,8 +120,8 @@ |
895 | uint32_t h; |
896 | |
897 | // size of button row |
898 | - w = TP_BUTTON_WIDTH * m_tabs.size(); |
899 | - h = TP_BUTTON_HEIGHT + TP_SEPARATOR_HEIGHT; |
900 | + w = kTabPanelButtonSize * m_tabs.size(); |
901 | + h = kTabPanelButtonSize + kTabPanelSeparatorHeight; |
902 | |
903 | // size of contents |
904 | if (m_active < m_tabs.size()) { |
905 | @@ -156,7 +160,7 @@ |
906 | uint32_t id = m_tabs.size(); |
907 | m_tabs.push_back(new Tab(this, id, name, pic, tooltip_text, panel)); |
908 | |
909 | - panel->set_pos(Point(0, TP_BUTTON_HEIGHT + TP_SEPARATOR_HEIGHT)); |
910 | + panel->set_pos(Point(0, kTabPanelButtonSize + kTabPanelSeparatorHeight)); |
911 | panel->set_visible(id == m_active); |
912 | update_desired_size(); |
913 | |
914 | @@ -202,70 +206,81 @@ |
915 | uint32_t x; |
916 | |
917 | // draw the background |
918 | - static_assert(2 < TP_BUTTON_WIDTH, "assert(2 < TP_BUTTON_WIDTH) failed."); |
919 | - static_assert(4 < TP_BUTTON_HEIGHT, "assert(4 < TP_BUTTON_HEIGHT) failed."); |
920 | + static_assert(2 < kTabPanelButtonSize, "assert(2 < kTabPanelButtonSize) failed."); |
921 | + static_assert(4 < kTabPanelButtonSize, "assert(4 < kTabPanelButtonSize) failed."); |
922 | |
923 | if (m_pic_background) { |
924 | dst.tile |
925 | - (Rect(Point(0, 0), m_tabs.size() * TP_BUTTON_WIDTH, TP_BUTTON_HEIGHT - 2), |
926 | + (Rect(Point(0, 0), m_tabs.size() * kTabPanelButtonSize, kTabPanelButtonSize - 2), |
927 | m_pic_background, Point(get_x(), get_y())); |
928 | - assert(TP_BUTTON_HEIGHT - 2 <= get_h()); |
929 | + assert(kTabPanelButtonSize - 2 <= get_h()); |
930 | dst.tile |
931 | (Rect |
932 | - (Point(0, TP_BUTTON_HEIGHT - 2), |
933 | - get_w(), get_h() - TP_BUTTON_HEIGHT + 2), |
934 | + (Point(0, kTabPanelButtonSize - 2), |
935 | + get_w(), get_h() - kTabPanelButtonSize + 2), |
936 | m_pic_background, |
937 | - Point(get_x(), get_y() + TP_BUTTON_HEIGHT - 2)); |
938 | + Point(get_x(), get_y() + kTabPanelButtonSize - 2)); |
939 | } |
940 | |
941 | // draw the buttons |
942 | - for (idx = 0, x = 0; idx < m_tabs.size(); idx++, x += TP_BUTTON_WIDTH) { |
943 | + for (idx = 0, x = 0; idx < m_tabs.size(); idx++, x += kTabPanelButtonSize) { |
944 | if (m_highlight == static_cast<int32_t>(idx)) |
945 | dst.brighten_rect |
946 | - (Rect(Point(x, 0), TP_BUTTON_WIDTH, TP_BUTTON_HEIGHT), |
947 | + (Rect(Point(x, 0), kTabPanelButtonSize, kTabPanelButtonSize), |
948 | MOUSE_OVER_BRIGHT_FACTOR); |
949 | |
950 | // Draw the icon |
951 | assert(m_tabs[idx]->pic); |
952 | - uint16_t cpw = m_tabs[idx]->pic->width(); |
953 | - uint16_t cph = m_tabs[idx]->pic->height(); |
954 | - dst.blit |
955 | - (Point(x + (TP_BUTTON_WIDTH - cpw) / 2, (TP_BUTTON_HEIGHT - cph) / 2), |
956 | - m_tabs[idx]->pic); |
957 | + |
958 | + // Scale the image down if needed, but keep the ratio. |
959 | + constexpr int kMaxImageSize = kTabPanelButtonSize - 2 * kTabPanelImageMargin; |
960 | + double image_scale = |
961 | + std::min(1., |
962 | + std::min(static_cast<double>(kMaxImageSize) / m_tabs[idx]->pic->width(), |
963 | + static_cast<double>(kMaxImageSize) / m_tabs[idx]->pic->height())); |
964 | + |
965 | + uint16_t picture_width = image_scale * m_tabs[idx]->pic->width(); |
966 | + uint16_t picture_height = image_scale * m_tabs[idx]->pic->height(); |
967 | + dst.blitrect_scale(Rect(x + (kTabPanelButtonSize - picture_width) / 2, |
968 | + (kTabPanelButtonSize - picture_height) / 2, |
969 | + picture_width, |
970 | + picture_height), |
971 | + m_tabs[idx]->pic, |
972 | + Rect(0, 0, m_tabs[idx]->pic->width(), m_tabs[idx]->pic->height())); |
973 | |
974 | // Draw top part of border |
975 | RGBColor black(0, 0, 0); |
976 | |
977 | dst.brighten_rect |
978 | - (Rect(Point(x, 0), TP_BUTTON_WIDTH, 2), BUTTON_EDGE_BRIGHT_FACTOR); |
979 | + (Rect(Point(x, 0), kTabPanelButtonSize, 2), BUTTON_EDGE_BRIGHT_FACTOR); |
980 | dst.brighten_rect |
981 | - (Rect(Point(x, 2), 2, TP_BUTTON_HEIGHT - 4), |
982 | + (Rect(Point(x, 2), 2, kTabPanelButtonSize - 4), |
983 | BUTTON_EDGE_BRIGHT_FACTOR); |
984 | dst.fill_rect |
985 | - (Rect(Point(x + TP_BUTTON_WIDTH - 2, 2), 1, TP_BUTTON_HEIGHT - 4), |
986 | + (Rect(Point(x + kTabPanelButtonSize - 2, 2), 1, kTabPanelButtonSize - 4), |
987 | black); |
988 | dst.fill_rect |
989 | - (Rect(Point(x + TP_BUTTON_WIDTH - 1, 1), 1, TP_BUTTON_HEIGHT - 3), |
990 | + (Rect(Point(x + kTabPanelButtonSize - 1, 1), 1, kTabPanelButtonSize - 3), |
991 | black); |
992 | |
993 | // Draw bottom part |
994 | if (m_active != idx) |
995 | dst.brighten_rect |
996 | - (Rect(Point(x, TP_BUTTON_HEIGHT - 2), TP_BUTTON_WIDTH, 2), |
997 | + (Rect(Point(x, kTabPanelButtonSize - 2), kTabPanelButtonSize, 2), |
998 | 2 * BUTTON_EDGE_BRIGHT_FACTOR); |
999 | else { |
1000 | dst.brighten_rect |
1001 | - (Rect(Point(x, TP_BUTTON_HEIGHT - 2), 2, 2), |
1002 | + (Rect(Point(x, kTabPanelButtonSize - 2), 2, 2), |
1003 | BUTTON_EDGE_BRIGHT_FACTOR); |
1004 | |
1005 | dst.brighten_rect |
1006 | - (Rect(Point(x + TP_BUTTON_WIDTH - 2, TP_BUTTON_HEIGHT - 2), 2, 2), |
1007 | + (Rect(Point(x + kTabPanelButtonSize - 2, kTabPanelButtonSize - 2), 2, 2), |
1008 | 2 * BUTTON_EDGE_BRIGHT_FACTOR); |
1009 | dst.fill_rect |
1010 | - (Rect(Point(x + TP_BUTTON_WIDTH - 2, TP_BUTTON_HEIGHT - 1), 1, 1), |
1011 | + (Rect(Point(x + kTabPanelButtonSize - 2, kTabPanelButtonSize - 1), 1, 1), |
1012 | black); |
1013 | dst.fill_rect |
1014 | - (Rect(Point(x + TP_BUTTON_WIDTH - 2, TP_BUTTON_HEIGHT - 2), 2, 1), |
1015 | + (Rect(Point(x + kTabPanelButtonSize - 2, kTabPanelButtonSize - 2), 2, 1), |
1016 | black); |
1017 | } |
1018 | } |
1019 | @@ -273,7 +288,7 @@ |
1020 | // draw the remaining separator |
1021 | assert(x <= static_cast<uint32_t>(get_w())); |
1022 | dst.brighten_rect |
1023 | - (Rect(Point(x, TP_BUTTON_HEIGHT - 2), get_w() - x, 2), |
1024 | + (Rect(Point(x, kTabPanelButtonSize - 2), get_w() - x, 2), |
1025 | 2 * BUTTON_EDGE_BRIGHT_FACTOR); |
1026 | } |
1027 | |
1028 | @@ -285,7 +300,7 @@ |
1029 | { |
1030 | if (!inside && m_highlight >= 0) { |
1031 | update |
1032 | - (m_highlight * TP_BUTTON_WIDTH, 0, TP_BUTTON_WIDTH, TP_BUTTON_HEIGHT); |
1033 | + (m_highlight * kTabPanelButtonSize, 0, kTabPanelButtonSize, kTabPanelButtonSize); |
1034 | |
1035 | m_highlight = -1; |
1036 | } |
1037 | @@ -300,10 +315,10 @@ |
1038 | { |
1039 | int32_t hl; |
1040 | |
1041 | - if (y < 0 || y >= TP_BUTTON_HEIGHT) |
1042 | + if (y < 0 || y >= kTabPanelButtonSize) |
1043 | hl = -1; |
1044 | else { |
1045 | - hl = x / TP_BUTTON_WIDTH; |
1046 | + hl = x / kTabPanelButtonSize; |
1047 | |
1048 | if (m_tabs.size() <= static_cast<size_t>(hl)) |
1049 | hl = -1; |
1050 | @@ -316,11 +331,11 @@ |
1051 | } |
1052 | if (m_highlight >= 0) |
1053 | update |
1054 | - (m_highlight * TP_BUTTON_WIDTH, 0, |
1055 | - TP_BUTTON_WIDTH, TP_BUTTON_HEIGHT); |
1056 | + (m_highlight * kTabPanelButtonSize, 0, |
1057 | + kTabPanelButtonSize, kTabPanelButtonSize); |
1058 | if (hl >= 0) |
1059 | update |
1060 | - (hl * TP_BUTTON_WIDTH, 0, TP_BUTTON_WIDTH, TP_BUTTON_HEIGHT); |
1061 | + (hl * kTabPanelButtonSize, 0, kTabPanelButtonSize, kTabPanelButtonSize); |
1062 | |
1063 | m_highlight = hl; |
1064 | } |
1065 | @@ -335,10 +350,10 @@ |
1066 | if (btn == SDL_BUTTON_LEFT) { |
1067 | int32_t id; |
1068 | |
1069 | - if (y >= TP_BUTTON_HEIGHT) |
1070 | + if (y >= kTabPanelButtonSize) |
1071 | return false; |
1072 | |
1073 | - id = x / TP_BUTTON_WIDTH; |
1074 | + id = x / kTabPanelButtonSize; |
1075 | |
1076 | if (static_cast<size_t>(id) < m_tabs.size()) { |
1077 | activate(id); |
1078 | |
1079 | === modified file 'src/ui_fsmenu/base.cc' |
1080 | --- src/ui_fsmenu/base.cc 2014-12-04 06:44:42 +0000 |
1081 | +++ src/ui_fsmenu/base.cc 2014-12-04 06:52:36 +0000 |
1082 | @@ -27,7 +27,6 @@ |
1083 | #include "base/wexception.h" |
1084 | #include "graphic/font.h" |
1085 | #include "graphic/graphic.h" |
1086 | -#include "graphic/image_transformations.h" |
1087 | #include "graphic/rendertarget.h" |
1088 | #include "io/filesystem/filesystem.h" |
1089 | #include "profile/profile.h" |
1090 | @@ -49,15 +48,12 @@ |
1091 | */ |
1092 | FullscreenMenuBase::FullscreenMenuBase(char const* const bgpic) |
1093 | : UI::Panel(nullptr, 0, 0, g_gr->get_xres(), g_gr->get_yres()) { |
1094 | - // Load background graphics |
1095 | - const std::string bgpicpath = (boost::format("pics/%s") % bgpic).str(); |
1096 | - background_ = ImageTransformations::resize(g_gr->images().get(bgpicpath), get_w(), get_h()); |
1097 | - |
1098 | textstyle_small_ = UI::TextStyle::ui_small(); |
1099 | textstyle_small_.font = UI::Font::get(ui_fn(), fs_small()); |
1100 | |
1101 | textstyle_big_ = UI::TextStyle::ui_big(); |
1102 | textstyle_big_.font = UI::Font::get(ui_fn(), fs_big()); |
1103 | + background_image_ = (boost::format("pics/%s") % bgpic).str(); |
1104 | } |
1105 | |
1106 | FullscreenMenuBase::~FullscreenMenuBase() |
1107 | @@ -69,7 +65,8 @@ |
1108 | * Draw the background / splash screen |
1109 | */ |
1110 | void FullscreenMenuBase::draw(RenderTarget & dst) { |
1111 | - dst.blit(Point(0, 0), background_); |
1112 | + const Image* bg = g_gr->images().get(background_image_); |
1113 | + dst.blitrect_scale(Rect(0, 0, get_w(), get_h()), bg, Rect(0, 0, bg->width(), bg->height())); |
1114 | } |
1115 | |
1116 | uint32_t FullscreenMenuBase::fs_small() { |
1117 | |
1118 | === modified file 'src/ui_fsmenu/base.h' |
1119 | --- src/ui_fsmenu/base.h 2014-12-04 06:44:42 +0000 |
1120 | +++ src/ui_fsmenu/base.h 2014-12-04 06:52:36 +0000 |
1121 | @@ -54,7 +54,7 @@ |
1122 | private: |
1123 | UI::TextStyle textstyle_big_; |
1124 | UI::TextStyle textstyle_small_; |
1125 | - const Image* background_; |
1126 | + std::string background_image_; |
1127 | }; |
1128 | |
1129 | |
1130 | |
1131 | === modified file 'src/ui_fsmenu/loadgame.cc' |
1132 | --- src/ui_fsmenu/loadgame.cc 2014-11-24 07:10:03 +0000 |
1133 | +++ src/ui_fsmenu/loadgame.cc 2014-12-04 06:52:36 +0000 |
1134 | @@ -334,11 +334,6 @@ |
1135 | if (scale > 1.0) scale = 1.0; // Don't make the image too big; fuzziness will result |
1136 | uint16_t w = scale * m_minimap_image->width(); |
1137 | uint16_t h = scale * m_minimap_image->height(); |
1138 | - const Image* resized = ImageTransformations::resize(m_minimap_image.get(), w, h); |
1139 | - // keeps our in_memory_image around and give to icon the one |
1140 | - // from resize that is handled by the cache. It is still linked to our |
1141 | - // texture. |
1142 | - m_minimap_icon.set_size(w, h); |
1143 | |
1144 | // Center the minimap in the available space |
1145 | int32_t xpos = m_right_column_x + (get_w() - m_right_column_margin - w - m_right_column_x) / 2; |
1146 | @@ -351,10 +346,11 @@ |
1147 | ypos += (m_minimap_h - h) / 2; |
1148 | } |
1149 | |
1150 | + m_minimap_icon.set_size(w, h); |
1151 | m_minimap_icon.set_pos(Point(xpos, ypos)); |
1152 | m_minimap_icon.set_frame(UI_FONT_CLR_FG); |
1153 | m_minimap_icon.set_visible(true); |
1154 | - m_minimap_icon.set_icon(resized); |
1155 | + m_minimap_icon.set_icon(m_minimap_image.get()); |
1156 | } catch (const std::exception & e) { |
1157 | log("Failed to load the minimap image : %s\n", e.what()); |
1158 | } |
1159 | |
1160 | === modified file 'src/wui/fieldaction.cc' |
1161 | --- src/wui/fieldaction.cc 2014-11-30 18:49:38 +0000 |
1162 | +++ src/wui/fieldaction.cc 2014-12-04 06:52:36 +0000 |
1163 | @@ -52,11 +52,7 @@ |
1164 | using Widelands::EditorGameBase; |
1165 | using Widelands::Game; |
1166 | |
1167 | -#define BG_CELL_WIDTH 34 // extents of one cell |
1168 | -#define BG_CELL_HEIGHT 34 |
1169 | - |
1170 | -//sizes for the images in the build menu (containing building icons) |
1171 | -#define BUILDMENU_IMAGE_SIZE 30. // used for width and height |
1172 | +constexpr int kBuildGridCellSize = 50; |
1173 | |
1174 | // The BuildGrid presents a selection of buildable buildings |
1175 | struct BuildGrid : public UI::IconGrid { |
1176 | @@ -86,7 +82,7 @@ |
1177 | BuildGrid::BuildGrid( |
1178 | UI::Panel* parent, const RGBColor& player_color, const Widelands::TribeDescr& tribe, |
1179 | int32_t x, int32_t y, int32_t cols) : |
1180 | - UI::IconGrid(parent, x, y, BG_CELL_WIDTH, BG_CELL_HEIGHT, cols), |
1181 | + UI::IconGrid(parent, x, y, kBuildGridCellSize, kBuildGridCellSize, cols), |
1182 | player_color_(player_color), |
1183 | tribe_(tribe) |
1184 | { |
1185 | @@ -104,17 +100,13 @@ |
1186 | { |
1187 | const Widelands::BuildingDescr & descr = |
1188 | *tribe_.get_building_descr(Widelands::BuildingIndex(id)); |
1189 | - const Image& anim_frame = g_gr->animations().get_animation(descr.get_animation("idle")) |
1190 | - .representative_image(player_color_); |
1191 | - const uint16_t image_w = anim_frame.width(); |
1192 | - const uint16_t image_h = anim_frame.height(); |
1193 | - double ratio = BUILDMENU_IMAGE_SIZE / std::max(image_w, image_h); |
1194 | - const Image* menu_image = ImageTransformations::resize(&anim_frame, image_w * ratio, image_h * ratio); |
1195 | - UI::IconGrid::add |
1196 | - (descr.name(), menu_image, |
1197 | - reinterpret_cast<void *>(id), |
1198 | - descr.descname() + "<br><font size=11>" + _("Construction costs:") + "</font><br>" + |
1199 | - waremap_to_richtext(tribe_, descr.buildcost())); |
1200 | + UI::IconGrid::add( |
1201 | + descr.name(), |
1202 | + &g_gr->animations().get_animation(descr.get_animation("idle")).representative_image( |
1203 | + player_color_), |
1204 | + reinterpret_cast<void*>(id), |
1205 | + descr.descname() + "<br><font size=11>" + _("Construction costs:") + "</font><br>" + |
1206 | + waremap_to_richtext(tribe_, descr.buildcost())); |
1207 | } |
1208 | |
1209 | |
1210 | @@ -329,7 +321,7 @@ |
1211 | |
1212 | // Now force the mouse onto the first button |
1213 | set_mouse_pos |
1214 | - (Point(17 + BG_CELL_WIDTH * m_best_tab, m_fastclick ? 51 : 17)); |
1215 | + (Point(17 + kBuildGridCellSize * m_best_tab, m_fastclick ? 51 : 17)); |
1216 | |
1217 | // Will only do something if we explicitly set another fast click panel |
1218 | // than the first button |
1219 | |
1220 | === modified file 'utils/win32/mingw/Makefile' |
1221 | --- utils/win32/mingw/Makefile 2014-03-01 12:35:59 +0000 |
1222 | +++ utils/win32/mingw/Makefile 2014-12-04 06:52:36 +0000 |
1223 | @@ -107,7 +107,7 @@ |
1224 | OBJECT_DIR:=../../$(TARGET)-$(BUILD) |
1225 | CFLAGS:=-Wall $(shell $(SDL_CONFIG) --cflags) $(ADD_CFLAGS) |
1226 | CXXFLAGS:=$(CFLAGS) |
1227 | -LDFLAGS:=$(shell $(SDL_CONFIG) --libs) icon.o $(ADD_LDFLAGS) -lz -lpng -lSDL_image -lSDL_mixer -lSDL_ttf -lSDL_net -lSDL_gfx -lwsock32 -llua |
1228 | +LDFLAGS:=$(shell $(SDL_CONFIG) --libs) icon.o $(ADD_LDFLAGS) -lz -lpng -lSDL_image -lSDL_mixer -lSDL_ttf -lSDL_net -lwsock32 -llua |
1229 | |
1230 | ############################################################################## |
1231 | # Building |
Does work well on win.
I am for merging and getting rid of the old MinGW Makfile completely. It does miss all SDL2 related changes and CMake+Ninja|Make work fine on windows.