Merge lp:~widelands-dev/widelands/buildicon_playercolors into lp:widelands

Proposed by Jens Beyer
Status: Merged
Merged at revision: 6909
Proposed branch: lp:~widelands-dev/widelands/buildicon_playercolors
Merge into: lp:widelands
Diff against target: 202 lines (+60/-37)
4 files modified
src/constants.h (+3/-0)
src/graphic/animation.h (+4/-3)
src/graphic/image_transformations.cc (+18/-2)
src/wui/fieldaction.cc (+35/-32)
To merge this branch: bzr merge lp:~widelands-dev/widelands/buildicon_playercolors
Reviewer Review Type Date Requested Status
Widelands Developers Pending
Review via email: mp+211401@code.launchpad.net

Description of the change

Ok, new try for the player-colored build-icons. Now with the code merged by the sprite-maps branch.

We now have one main advantage - we really do not need all those menu.png for the buildings anymore.

But there are two disadvantages - some of the icons are really barely distinguishable from the background, like the Barbarian Well; and the details of the large buildings somehow distract the eye in the menu, but this could also only be me.

I can imagine making the menu slightly bigger allowing for bigger buttons (like 50x50px). But the problem with the Well persists.

Before merging, we need to remove all menu.png in the tribes (not done yet, I just want code and design review; if you approve, I will remove those files and the sources related to them).

To post a comment you must log in.
Revision history for this message
SirVer (sirver) wrote :

looks good and works great. I changed the code to use get_animation("idle") instead of main_animation() - which should probably be removed anyways. I also dropped a NOCOM(#qcs) for you.

I would also suggest doing a side by side comparison between the new menu and the old to see if quality has decreased before submitting.

When you remove the menu.png, keep in mind that they sometimes are used as idle animation too - so you'll need to check the conf files real quick too.

I suggest making the images bigger - resolutions have changed over the years. But that can be done separately if you prefer.

Revision history for this message
Jens Beyer (qcumber-some) wrote :

I fixed the NOCOM.
But there is one problem which was not present yesterday: The playercolors in the building menu are completely wrong. I remember that it definitely worked. What could have caused this?

Revision history for this message
Jens Beyer (qcumber-some) wrote :

I am not sure why, but the playercolors in the build menu do not work on the branch, even with trunk merged; but merging this branch into trunk makes the playercolor work in the build menu.
Now I am totally confused.

Revision history for this message
SirVer (sirver) wrote :

const Image& anim_frame = g_gr->animations().get_animation(descr.get_animation("idle"))
.representative_image(RGBColor(0, 0, 0));

well, here was the problem. You construct an image with playercolor black, always. I changed it to use the true player color.

While doing that I also checked the differences in the resized image - and they look awful. The menu.png images are much prettier - especially noticable in the big buildings. I think the zoomSurface method is not cutting it really - we need something fancier that does proper filtering. The plus side is that we then can get rid of the SDLgfx dependency which we only use for resizing. The downside is that we need to add another library or roll our own - keep in mind that we also need to upscale sometimes (menus). I think this is really important, but can be done after this is merged - however if this is merged, it needs to be done and soonish.

This looks sophisticated:
http://www.codeproject.com/Articles/11143/Image-Resizing-outperform-GDI

This should give some ideas:
http://stackoverflow.com/questions/3086770/what-algorithms-to-use-for-image-downsizing

Revision history for this message
SirVer (sirver) wrote :

And there is a bilinear interpolation ready to be copy&pasted: http://www.scratchapixel.com/lessons/3d-advanced-lessons/interpolation/bilinear-interpolation/

That is maybe already good enough.

Revision history for this message
SirVer (sirver) wrote :

I looked around the SDLgfx source code real quick and saw that it provides a shrinking method that gives better quality then just using zoom to shrink. I added a quick hack to shrink the image to ballpark the size, then zoomSurface to get it correct. It still looks worse than menu.png, but much better than before. I think we can ship this and see if somebody complains. Or we enhance the image rescaling later anyways.

Revision history for this message
SirVer (sirver) wrote :

ping?

Revision history for this message
Jens Beyer (qcumber-some) wrote :

Sorry, got distracted by 'the other life'.

I say this is good enough to go on trunk.

Few words:
1) We can not get rid yet of the menu.png files as they are used at other places (Editor, Messages...). Those should be targetted next.
2) I agree that I can live with the current state of the menu images on this branch. Though I did not have a look at them with very low resolution, rather the opposite ;-) But I trust your eyes more than mine.
3) Maybe we should file two new bugs then after merging this: Get rid of menu.png files, and find a better scaling algorithm.

Unfortunately I can not contribute to widelands development for the next few weeks.

Revision history for this message
SirVer (sirver) wrote :

Merged.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/constants.h'
2--- src/constants.h 2013-10-14 07:20:46 +0000
3+++ src/constants.h 2014-03-18 19:28:13 +0000
4@@ -38,6 +38,9 @@
5 #define TEXTURE_HEIGHT TEXTURE_WIDTH
6 //@}
7
8+//sizes for the images in the build menu (containing building icons)
9+#define BUILDMENU_IMAGE_SIZE 30. // used for width and height
10+
11 #define XRES 800 ///< Fullscreen Menu Width
12 #define YRES 600 ///< Fullscreen Menu Height
13
14
15=== modified file 'src/graphic/animation.h'
16--- src/graphic/animation.h 2014-03-16 20:55:15 +0000
17+++ src/graphic/animation.h 2014-03-18 19:28:13 +0000
18@@ -63,9 +63,10 @@
19 /// so the caller has to adjust for the hotspot himself.
20 virtual const Point& hotspot() const = 0;
21
22- /// An image frame that shows a singular animation frame. This can be used in
23- /// the UI (e.g. buildingwindow to represent this image.
24- virtual const Image& representative_image(const RGBColor& clr) const = 0;
25+ // An image frame that shows the first animation frame, colored using the
26+ // 'player_clr'. This can be used in the UI (e.g. buildingwindow) to
27+ // represent this image.
28+ virtual const Image& representative_image(const RGBColor& player_clr) const = 0;
29
30 /// Blit the animation frame that should be displayed at the given time index
31 /// so that the given point is at the top left of the frame. Srcrc defines
32
33=== modified file 'src/graphic/image_transformations.cc'
34--- src/graphic/image_transformations.cc 2014-02-22 18:04:02 +0000
35+++ src/graphic/image_transformations.cc 2014-03-18 19:28:13 +0000
36@@ -97,9 +97,25 @@
37 srcsdl = extract_sdl_surface(*src, srcrect);
38 }
39
40+ // If we actually shrink a surface, ballpark the zoom so that the shrinking
41+ // effect is weakened.
42+ int factor = 1;
43+ while ((static_cast<double>(w) * factor / srcsdl->w) < 1. ||
44+ (static_cast<double>(h) * factor / srcsdl->h) < 1.) {
45+ ++factor;
46+ }
47+ if (factor > 2) {
48+ SDL_Surface* temp = shrinkSurface(srcsdl, factor - 1, factor - 1);
49+ if (free_source) {
50+ SDL_FreeSurface(srcsdl);
51+ }
52+ srcsdl = temp;
53+ free_source = true;
54+ }
55+
56 // Third step: perform the zoom and placement
57- SDL_Surface * zoomed = zoomSurface
58- (srcsdl, double(w) / srcsdl->w, double(h) / srcsdl->h, 1);
59+ SDL_Surface* zoomed = zoomSurface(srcsdl, double(w) / srcsdl->w, double(h) / srcsdl->h, 1);
60+
61 if (free_source)
62 SDL_FreeSurface(srcsdl);
63
64
65=== modified file 'src/wui/fieldaction.cc'
66--- src/wui/fieldaction.cc 2014-03-07 19:12:24 +0000
67+++ src/wui/fieldaction.cc 2014-03-18 19:28:13 +0000
68@@ -23,6 +23,7 @@
69 #include "economy/flag.h"
70 #include "economy/road.h"
71 #include "graphic/graphic.h"
72+#include "graphic/image_transformations.h"
73 #include "i18n.h"
74 #include "logic/attackable.h"
75 #include "logic/cmd_queue.h"
76@@ -59,15 +60,16 @@
77
78 // The BuildGrid presents a selection of buildable buildings
79 struct BuildGrid : public UI::Icon_Grid {
80- BuildGrid
81- (UI::Panel * parent,
82- const Widelands::Tribe_Descr & tribe,
83- int32_t x, int32_t y,
84- int32_t cols);
85+ BuildGrid(UI::Panel* parent,
86+ const RGBColor& player_color,
87+ const Widelands::Tribe_Descr& tribe,
88+ int32_t x,
89+ int32_t y,
90+ int32_t cols);
91
92- boost::signals2::signal<void (Widelands::Building_Index::value_t)> buildclicked;
93- boost::signals2::signal<void (Widelands::Building_Index::value_t)> buildmouseout;
94- boost::signals2::signal<void (Widelands::Building_Index::value_t)> buildmousein;
95+ boost::signals2::signal<void(Widelands::Building_Index::value_t)> buildclicked;
96+ boost::signals2::signal<void(Widelands::Building_Index::value_t)> buildmouseout;
97+ boost::signals2::signal<void(Widelands::Building_Index::value_t)> buildmousein;
98
99 void add(Widelands::Building_Index::value_t);
100
101@@ -77,26 +79,22 @@
102 void mouseinslot(int32_t idx);
103
104 private:
105- const Widelands::Tribe_Descr & m_tribe;
106+ const RGBColor player_color_;
107+ const Widelands::Tribe_Descr& tribe_;
108 };
109
110-
111-BuildGrid::BuildGrid
112- (UI::Panel * parent,
113- const Widelands::Tribe_Descr & tribe,
114- int32_t x, int32_t y,
115- int32_t cols)
116-:
117- UI::Icon_Grid
118- (parent, x, y, BG_CELL_WIDTH, BG_CELL_HEIGHT, cols),
119- m_tribe(tribe)
120+BuildGrid::BuildGrid(
121+ UI::Panel* parent, const RGBColor& player_color, const Widelands::Tribe_Descr& tribe,
122+ int32_t x, int32_t y, int32_t cols) :
123+ UI::Icon_Grid(parent, x, y, BG_CELL_WIDTH, BG_CELL_HEIGHT, cols),
124+ player_color_(player_color),
125+ tribe_(tribe)
126 {
127 clicked.connect(boost::bind(&BuildGrid::clickslot, this, _1));
128 mouseout.connect(boost::bind(&BuildGrid::mouseoutslot, this, _1));
129 mousein.connect(boost::bind(&BuildGrid::mouseinslot, this, _1));
130 }
131
132-
133 /*
134 ===============
135 Add a new building to the list of buildable buildings
136@@ -105,13 +103,18 @@
137 void BuildGrid::add(Widelands::Building_Index::value_t id)
138 {
139 const Widelands::Building_Descr & descr =
140- *m_tribe.get_building_descr(Widelands::Building_Index(id));
141+ *tribe_.get_building_descr(Widelands::Building_Index(id));
142+ const Image& anim_frame = g_gr->animations().get_animation(descr.get_animation("idle"))
143+ .representative_image(player_color_);
144+ const uint16_t image_w = anim_frame.width();
145+ const uint16_t image_h = anim_frame.height();
146+ double ratio = BUILDMENU_IMAGE_SIZE / std::max(image_w, image_h);
147+ const Image* menu_image = ImageTransformations::resize(&anim_frame, image_w * ratio, image_h * ratio);
148 UI::Icon_Grid::add
149- (descr.name(), descr.get_buildicon(),
150+ (descr.name(), menu_image,
151 reinterpret_cast<void *>(id),
152 descr.descname() + "<br><font size=11>" + _("Construction costs:") + "</font><br>" +
153- waremap_to_richtext(m_tribe, descr.buildcost()));
154-;
155+ waremap_to_richtext(tribe_, descr.buildcost()));
156 }
157
158
159@@ -181,7 +184,7 @@
160
161 void init();
162 void add_buttons_auto();
163- void add_buttons_build(int32_t buildcaps);
164+ void add_buttons_build(int32_t buildcaps, const RGBColor& player_color);
165 void add_buttons_road(bool flag);
166 void add_buttons_attack();
167
168@@ -396,11 +399,11 @@
169 const int32_t buildcaps = m_plr ? m_plr->get_buildcaps(m_node) : 0;
170
171 // Add house building
172- if
173- ((buildcaps & Widelands::BUILDCAPS_SIZEMASK)
174- ||
175- (buildcaps & Widelands::BUILDCAPS_MINE))
176- add_buttons_build(buildcaps);
177+ if ((buildcaps & Widelands::BUILDCAPS_SIZEMASK) ||
178+ (buildcaps & Widelands::BUILDCAPS_MINE)) {
179+ assert(igbase->get_player());
180+ add_buttons_build(buildcaps, igbase->get_player()->get_playercolor());
181+ }
182
183 // Add build actions
184 if ((m_fastclick = buildcaps & Widelands::BUILDCAPS_FLAG))
185@@ -508,7 +511,7 @@
186 Add buttons for house building.
187 ===============
188 */
189-void FieldActionWindow::add_buttons_build(int32_t buildcaps)
190+void FieldActionWindow::add_buttons_build(int32_t buildcaps, const RGBColor& player_color)
191 {
192 if (not m_plr)
193 return;
194@@ -558,7 +561,7 @@
195
196 // Allocate the tab's grid if necessary
197 if (!*ppgrid) {
198- *ppgrid = new BuildGrid(&m_tabpanel, tribe, 0, 0, 5);
199+ *ppgrid = new BuildGrid(&m_tabpanel, player_color, tribe, 0, 0, 5);
200 (*ppgrid)->buildclicked.connect(boost::bind(&FieldActionWindow::act_build, this, _1));
201 (*ppgrid)->buildmouseout.connect
202 (boost::bind(&FieldActionWindow::building_icon_mouse_out, this, _1));

Subscribers

People subscribed via source and target branches

to status/vote changes: