Merge lp:~nomeata/widelands/plot-improvements into lp:widelands

Proposed by Joachim Breitner
Status: Merged
Merged at revision: 6072
Proposed branch: lp:~nomeata/widelands/plot-improvements
Merge into: lp:widelands
Diff against target: 563 lines (+124/-150)
12 files modified
src/graphic/render/gl_surface_screen.cc (+1/-11)
src/graphic/render/gl_surface_screen.h (+1/-1)
src/graphic/render/render_sdl.cc (+4/-5)
src/graphic/render/surface_sdl.h (+1/-1)
src/graphic/rendertarget.cc (+1/-6)
src/graphic/surface.h (+1/-2)
src/ui_basic/slider.cc (+22/-12)
src/wui/plot_area.cc (+1/-4)
src/wui/ware_statistics_menu.cc (+52/-101)
src/wui/ware_statistics_menu.h (+1/-1)
src/wui/waresdisplay.cc (+28/-5)
src/wui/waresdisplay.h (+11/-1)
To merge this branch: bzr merge lp:~nomeata/widelands/plot-improvements
Reviewer Review Type Date Requested Status
Widelands Developers Pending
Review via email: mp+81371@code.launchpad.net

This proposal supersedes a proposal from 2011-11-05.

Description of the change

Now with the horizontal layout for wares, related to https://bugs.launchpad.net/widelands/+bug/672085

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 'src/graphic/render/gl_surface_screen.cc'
2--- src/graphic/render/gl_surface_screen.cc 2011-02-21 18:04:56 +0000
3+++ src/graphic/render/gl_surface_screen.cc 2011-11-05 18:50:31 +0000
4@@ -230,15 +230,8 @@
5 int32_t y1,
6 int32_t x2,
7 int32_t y2,
8- RGBColor color,
9- const Rect * clip)
10+ RGBColor color)
11 {
12- if (clip) {
13- glPushAttrib(GL_ENABLE_BIT | GL_SCISSOR_BIT);
14- glScissor
15- (clip->x, g_gr->get_yres() - clip->y - clip->h, clip->w, clip->h);
16- glEnable(GL_SCISSOR_TEST);
17- }
18 glDisable(GL_BLEND);
19 glDisable(GL_TEXTURE_2D);
20 glBegin(GL_LINES); {
21@@ -246,9 +239,6 @@
22 glVertex2f(x1 + 0.5f, y1 + 0.5f);
23 glVertex2f(x2 + 0.5f, y2 + 0.5f);
24 } glEnd();
25- if (clip) {
26- glPopAttrib();
27- }
28 }
29
30 /**
31
32=== modified file 'src/graphic/render/gl_surface_screen.h'
33--- src/graphic/render/gl_surface_screen.h 2011-02-20 16:42:42 +0000
34+++ src/graphic/render/gl_surface_screen.h 2011-11-05 18:50:31 +0000
35@@ -57,7 +57,7 @@
36 virtual void draw_line
37 (int32_t x1, int32_t y1,
38 int32_t x2, int32_t y2,
39- RGBColor, Rect const * clip = 0);
40+ RGBColor);
41
42 virtual void blit(Point, PictureID, Rect srcrc, Composite cm);
43 virtual void fast_blit(PictureID);
44
45=== modified file 'src/graphic/render/render_sdl.cc'
46--- src/graphic/render/render_sdl.cc 2010-12-04 23:11:18 +0000
47+++ src/graphic/render/render_sdl.cc 2011-11-05 18:50:31 +0000
48@@ -204,8 +204,7 @@
49 int32_t y1,
50 int32_t x2,
51 int32_t y2,
52- RGBColor color,
53- const Rect * clip)
54+ RGBColor color)
55 {
56 int32_t dx = x2 - x1; /* the horizontal distance of the line */
57 int32_t dy = y2 - y1; /* the vertical distance of the line */
58@@ -217,7 +216,7 @@
59 uint32_t y = dxabs / 2;
60 Point p(x1, y1);
61
62- draw_pixel(p, *clip, color);
63+ set_pixel(p.x, p.y, color.map(format()));
64
65 if (dxabs >= dyabs) // the line is more horizontal than vertical
66 for (uint32_t i = 0; i < dxabs; ++i) {
67@@ -229,7 +228,7 @@
68 }
69
70 p.x += sdx;
71- draw_pixel(p, *clip, color);
72+ set_pixel(p.x, p.y, color.map(format()));
73 }
74 else // the line is more vertical than horizontal
75 for (uint32_t i = 0; i < dyabs; ++i) {
76@@ -241,7 +240,7 @@
77 }
78
79 p.y += sdy;
80- draw_pixel(p, *clip, color);
81+ set_pixel(p.x, p.y, color.map(format()));
82 }
83 }
84
85
86=== modified file 'src/graphic/render/surface_sdl.h'
87--- src/graphic/render/surface_sdl.h 2010-11-27 16:23:39 +0000
88+++ src/graphic/render/surface_sdl.h 2011-11-05 18:50:31 +0000
89@@ -80,7 +80,7 @@
90 void draw_line
91 (int32_t x1, int32_t y1,
92 int32_t x2, int32_t y2,
93- RGBColor, Rect const * clip = 0);
94+ RGBColor);
95
96 void blit(Point, PictureID, Rect srcrc, Composite cm);
97 void fast_blit(PictureID);
98
99=== modified file 'src/graphic/rendertarget.cc'
100--- src/graphic/rendertarget.cc 2010-11-27 16:23:39 +0000
101+++ src/graphic/rendertarget.cc 2011-11-05 18:50:31 +0000
102@@ -141,14 +141,9 @@
103 (int32_t const x1, int32_t const y1, int32_t const x2, int32_t const y2,
104 RGBColor const color)
105 {
106- Rect clipr = Rect
107- (Point(m_rect.x + m_offset.x, m_rect.y + m_offset.y),
108- m_rect.w, m_rect.h);
109-
110 m_surface->draw_line
111 (x1 + m_offset.x + m_rect.x, y1 + m_offset.y + m_rect.y,
112- x2 + m_offset.x + m_rect.x, y2 + m_offset.y + m_rect.y, color,
113- &clipr);
114+ x2 + m_offset.x + m_rect.x, y2 + m_offset.y + m_rect.y, color);
115 }
116
117 /**
118
119=== modified file 'src/graphic/surface.h'
120--- src/graphic/surface.h 2010-11-27 13:30:37 +0000
121+++ src/graphic/surface.h 2011-11-05 18:50:31 +0000
122@@ -60,8 +60,7 @@
123 int32_t y1,
124 int32_t x2,
125 int32_t y2,
126- RGBColor color,
127- Rect const * clip = 0)
128+ RGBColor color)
129 {
130 throw wexception("draw_line() not implemented");
131 }
132
133=== modified file 'src/ui_basic/slider.cc'
134--- src/ui_basic/slider.cc 2011-11-05 13:50:56 +0000
135+++ src/ui_basic/slider.cc 2011-11-05 18:50:31 +0000
136@@ -245,12 +245,18 @@
137 m_pressed = false;
138
139 // cursor position: align to integer value
140- m_cursor_pos =
141- m_value == m_min_value ? 0 :
142- m_value == m_max_value ? get_bar_size() :
143- (m_value - m_min_value) * get_bar_size()
144- /
145- (m_max_value - m_min_value);
146+ if (m_max_value == m_min_value) {
147+ m_cursor_pos = m_min_value;
148+ } else if (m_value == m_min_value) {
149+ m_cursor_pos = 0;
150+ } else if (m_value == m_max_value) {
151+ m_cursor_pos = get_bar_size();
152+ } else {
153+ m_cursor_pos =
154+ (m_value - m_min_value) * get_bar_size()
155+ /
156+ (m_max_value - m_min_value);
157+ }
158
159 update();
160 }
161@@ -346,12 +352,16 @@
162 m_cursor_pos = pointer - ofs;
163
164 // absolute value
165- m_value =
166- static_cast<int32_t>
167- (rint
168- (static_cast<double>((m_max_value - m_min_value) * m_cursor_pos)
169- /
170- get_bar_size()));
171+ if (get_bar_size() == 0) {
172+ m_value = 0;
173+ } else {
174+ m_value =
175+ static_cast<int32_t>
176+ (rint
177+ (static_cast<double>((m_max_value - m_min_value) * m_cursor_pos)
178+ /
179+ get_bar_size()));
180+ }
181
182 // relative value in bounds
183 if (m_value < m_min_value)
184
185=== modified file 'src/wui/plot_area.cc'
186--- src/wui/plot_area.cc 2011-11-05 14:55:53 +0000
187+++ src/wui/plot_area.cc 2011-11-05 18:50:31 +0000
188@@ -89,10 +89,8 @@
189 time_in_ms_ += - (time_in_ms_ % (20 * hours)) + 20 * hours;
190 } else if (time_in_ms_ > 4 * hours) {
191 time_in_ms_ += - (time_in_ms_ % (2 * hours)) + 2 * hours;
192- } else if (time_in_ms_ > 40 * minutes) {
193- time_in_ms_ += - (time_in_ms_ % (20 * minutes)) + 20 * minutes;
194 } else {
195- time_in_ms_ += - (time_in_ms_ % (4 * minutes)) + 5 * minutes;
196+ time_in_ms_ += - (time_in_ms_ % (15 * minutes)) + 15 * minutes;
197 }
198 return time_in_ms_;
199 } else {
200@@ -149,7 +147,6 @@
201 * Draw this. This is the main function
202 */
203 void WUIPlot_Area::draw(RenderTarget & dst) {
204-
205 uint32_t time_in_ms_, how_many_ticks, max_x;
206
207 time_in_ms_ = get_plot_time();
208
209=== modified file 'src/wui/ware_statistics_menu.cc'
210--- src/wui/ware_statistics_menu.cc 2011-11-04 22:07:49 +0000
211+++ src/wui/ware_statistics_menu.cc 2011-11-05 18:50:31 +0000
212@@ -27,6 +27,7 @@
213 #include "logic/tribe.h"
214 #include "logic/warelist.h"
215 #include "plot_area.h"
216+#include "waresdisplay.h"
217
218 #include "ui_basic/button.h"
219 #include "ui_basic/checkbox.h"
220@@ -288,60 +289,34 @@
221 RGBColor(255, 255, 255),
222 };
223
224-/*
225- * This class is only needed here, that's
226- * why it is defined here.
227- *
228- * This class is the same as an ordinary
229- * checkbox, the only difference is, it has
230- * a small rectangle on it with the color
231- * of the graph and it needs a picture
232- */
233-struct WSM_Checkbox : public UI::Checkbox {
234- WSM_Checkbox(UI::Panel *, Point, int32_t id, PictureID picid, RGBColor);
235-
236- virtual void draw(RenderTarget &);
237-
238-private:
239- PictureID m_pic;
240- RGBColor m_color;
241+
242+struct StatisticWaresDisplay : public AbstractWaresDisplay {
243+ typedef AbstractWaresDisplay::wdType wdType;
244+
245+ StatisticWaresDisplay
246+ (UI::Panel * const parent,
247+ int32_t const x, int32_t const y,
248+ Widelands::Tribe_Descr const & tribe,
249+ boost::function<void(Widelands::Ware_Index, bool)> callback_function)
250+ :
251+ AbstractWaresDisplay(parent, x, y, tribe, WaresDisplay::WARE, true, callback_function)
252+ {
253+ uint32_t w, h;
254+ get_desired_size(w, h);
255+ set_size(w, h);
256+ }
257+protected:
258+ std::string info_for_ware(Widelands::Ware_Index const ware) {
259+ return "";
260+ }
261+
262+ RGBColor info_color_for_ware(Widelands::Ware_Index const ware)
263+ {
264+ return colors[static_cast<size_t>(ware)];
265+ }
266 };
267
268
269-WSM_Checkbox::WSM_Checkbox
270- (UI::Panel * const parent,
271- Point const p,
272- int32_t const id,
273- PictureID const picid,
274- RGBColor const color)
275-:
276-UI::Checkbox(parent, p, g_gr->get_picture(PicMod_Game, WARES_DISPLAY_BG)),
277-m_pic (picid),
278-m_color (color)
279-{
280- set_id(id);
281-}
282-
283-/*
284- * draw
285- */
286-void WSM_Checkbox::draw(RenderTarget & dst) {
287- // First, draw normal.
288- UI::Checkbox::draw(dst);
289-
290- // Now, draw a small box with the color.
291- assert(1 <= get_inner_w());
292- compile_assert(2 <= COLOR_BOX_HEIGHT);
293- dst.fill_rect
294- (Rect(Point(1, 1), get_inner_w() - 1, COLOR_BOX_HEIGHT - 2), m_color);
295-
296- // and the item
297- dst.blit
298- (Point((get_inner_w() - WARE_MENU_PIC_WIDTH) / 2, COLOR_BOX_HEIGHT),
299- m_pic);
300-}
301-
302-
303 Ware_Statistics_Menu::Ware_Statistics_Menu
304 (Interactive_Player & parent, UI::UniqueWindow::Registry & registry)
305 :
306@@ -353,74 +328,49 @@
307
308 // First, we must decide about the size.
309 uint8_t const nr_wares = parent.get_player()->tribe().get_nrwares().value();
310- uint32_t wares_per_row = MIN_WARES_PER_LINE;
311- while (nr_wares % wares_per_row && wares_per_row <= MAX_WARES_PER_LINE)
312- ++wares_per_row;
313- const uint32_t nr_rows =
314- nr_wares / wares_per_row + (nr_wares % wares_per_row ? 1 : 0);
315
316 #define spacing 5
317 Point const offs(spacing, 30);
318 Point pos (offs);
319
320- set_inner_size
321- (10,
322- (offs.y + spacing + PLOT_HEIGHT + spacing +
323- nr_rows * (WARE_MENU_PIC_HEIGHT + spacing) + 100));
324-
325-
326+
327+ // Setup Wares selectoin widget first, because the window size depends on it.
328+ pos.y += PLOT_HEIGHT + 2 * spacing;
329+ pos.x = spacing;
330+
331+ StatisticWaresDisplay * swd =
332+ new StatisticWaresDisplay
333+ (this, spacing, pos.y, parent.get_player()->tribe(),
334+ boost::bind(&Ware_Statistics_Menu::cb_changed_to, boost::ref(*this), _1, _2));
335+
336+ pos.y += swd->get_h();
337+ pos.y += spacing;
338+
339+ // Setup plot widget
340 m_plot =
341 new WUIPlot_Area
342 (this,
343- spacing, offs.y + spacing, get_inner_w() - 2 * spacing, PLOT_HEIGHT);
344+ spacing, offs.y + spacing, swd->get_w(), PLOT_HEIGHT);
345 m_plot->set_sample_rate(STATISTICS_SAMPLE_TIME);
346 m_plot->set_plotmode(WUIPlot_Area::PLOTMODE_RELATIVE);
347
348- // all wares
349- Widelands::Ware_Index::value_t cur_ware = 0;
350- int32_t dposy = 0;
351- pos.y += PLOT_HEIGHT + 2 * spacing;
352- Widelands::Tribe_Descr const & tribe = parent.get_player()->tribe();
353- for (uint32_t y = 0; y < nr_rows; ++y) {
354- pos.x = spacing;
355- for
356- (uint32_t x = 0;
357- x < wares_per_row and cur_ware < nr_wares;
358- ++x, ++cur_ware)
359- {
360- Widelands::Item_Ware_Descr const & ware =
361- *tribe.get_ware_descr(Widelands::Ware_Index(cur_ware));
362- WSM_Checkbox & cb =
363- *new WSM_Checkbox
364- (this, pos, cur_ware, ware.icon(), colors[cur_ware]);
365- cb.set_tooltip(ware.descname().c_str());
366- cb.changedtoid.set(this, &Ware_Statistics_Menu::cb_changed_to);
367- pos.x += cb.get_w() + spacing;
368- dposy = cb.get_h() + spacing;
369- set_inner_size
370- (spacing + (cb.get_w() + spacing) * wares_per_row, get_inner_h());
371- m_plot->register_plot_data
372- (cur_ware,
373- parent.get_player()->get_ware_production_statistics
374- (Widelands::Ware_Index(cur_ware)),
375- colors[cur_ware]);
376- }
377- pos.y += dposy;
378+ for (Widelands::Ware_Index::value_t cur_ware = 0; cur_ware < nr_wares; ++cur_ware) {
379+ m_plot->register_plot_data
380+ (cur_ware,
381+ parent.get_player()->get_ware_production_statistics
382+ (Widelands::Ware_Index(cur_ware)),
383+ colors[cur_ware]);
384 }
385
386- m_plot->set_size(get_inner_w() - 2 * spacing, PLOT_HEIGHT);
387-
388- pos.x = spacing;
389- pos.y += spacing + spacing;
390
391 new WUIPlot_Area_Slider
392 (this, *m_plot,
393- pos.x, pos.y, get_inner_w() - 2 * spacing, 45,
394+ pos.x, pos.y, swd->get_w(), 45,
395 g_gr->get_picture(PicMod_UI, "pics/but1.png"));
396
397 pos.y += 45 + spacing;
398
399- set_inner_size(get_inner_w(), pos.y);
400+ set_inner_size(swd->get_w() + 2 * spacing, pos.y);
401 }
402
403
404@@ -433,6 +383,7 @@
405 /*
406 * Cb has been changed to this state
407 */
408-void Ware_Statistics_Menu::cb_changed_to(int32_t const id, bool const what) {
409- m_plot->show_plot(id, what);
410+void Ware_Statistics_Menu::cb_changed_to(Widelands::Ware_Index id, bool what) {
411+ m_plot->show_plot(static_cast<size_t>(id), what);
412 }
413+
414
415=== modified file 'src/wui/ware_statistics_menu.h'
416--- src/wui/ware_statistics_menu.h 2009-05-06 20:54:01 +0000
417+++ src/wui/ware_statistics_menu.h 2011-11-05 18:50:31 +0000
418@@ -33,7 +33,7 @@
419 WUIPlot_Area * m_plot;
420
421 void clicked_help();
422- void cb_changed_to(int32_t, bool);
423+ void cb_changed_to(Widelands::Ware_Index, bool);
424 };
425
426 #endif
427
428=== modified file 'src/wui/waresdisplay.cc'
429--- src/wui/waresdisplay.cc 2011-09-17 11:33:34 +0000
430+++ src/wui/waresdisplay.cc 2011-11-05 18:50:31 +0000
431@@ -37,7 +37,9 @@
432 int32_t const x, int32_t const y,
433 Widelands::Tribe_Descr const & tribe,
434 wdType type,
435- bool selectable)
436+ bool selectable,
437+ boost::function<void(Widelands::Ware_Index, bool)> callback_function,
438+ bool horizontal)
439 :
440 // Size is set when add_warelist is called, as it depends on the m_type.
441 UI::Panel(parent, x, y, 0, 0),
442@@ -55,7 +57,9 @@
443 m_hidden
444 (m_type == WORKER ? m_tribe.get_nrworkers()
445 : m_tribe.get_nrwares(), false),
446- m_selectable(selectable)
447+ m_selectable(selectable),
448+ m_horizontal(horizontal),
449+ m_callback_function(callback_function)
450 {
451 //resize the configuration of our wares if they won't fit in the current window
452 int number = (g_gr->get_yres() - 160) / (WARE_MENU_PIC_HEIGHT + 8 + 3);
453@@ -67,6 +71,11 @@
454 for (unsigned int i = 0; i < icons_order().size(); i++)
455 if (icons_order()[i].size() > rows)
456 rows = icons_order()[i].size();
457+ if (m_horizontal) {
458+ unsigned int s = columns;
459+ columns = rows;
460+ rows = s;
461+ }
462
463 // 25 is height of m_curware text
464 set_desired_size
465@@ -121,6 +130,11 @@
466
467 unsigned int i = x / (WARE_MENU_PIC_WIDTH + 4);
468 unsigned int j = y / (WARE_MENU_PIC_HEIGHT + 8 + 3);
469+ if (m_horizontal) {
470+ unsigned int s = i;
471+ i = j;
472+ j = s;
473+ }
474 if (i < icons_order().size() && j < icons_order()[i].size()) {
475 Widelands::Ware_Index ware = icons_order()[i][j];
476 if (not m_hidden[ware]) {
477@@ -190,8 +204,13 @@
478 Point AbstractWaresDisplay::ware_position(Widelands::Ware_Index id) const
479 {
480 Point p(2, 2);
481- p.x += icons_order_coords()[id].first * (WARE_MENU_PIC_WIDTH + 3);
482- p.y += icons_order_coords()[id].second * (WARE_MENU_PIC_HEIGHT + 3 + 8);
483+ if (m_horizontal) {
484+ p.x += icons_order_coords()[id].second * (WARE_MENU_PIC_WIDTH + 3);
485+ p.y += icons_order_coords()[id].first * (WARE_MENU_PIC_HEIGHT + 3 + 8);
486+ } else {
487+ p.x += icons_order_coords()[id].first * (WARE_MENU_PIC_WIDTH + 3);
488+ p.y += icons_order_coords()[id].second * (WARE_MENU_PIC_HEIGHT + 3 + 8);
489+ }
490 return p;
491 }
492
493@@ -229,7 +248,7 @@
494 m_tribe.get_ware_descr (id)->icon());
495 dst.fill_rect
496 (Rect(pos + Point(0, WARE_MENU_PIC_HEIGHT), WARE_MENU_PIC_WIDTH, 8),
497- RGBColor(0, 0, 0));
498+ info_color_for_ware(id));
499
500 UI::g_fh->draw_text
501 (dst, UI::TextStyle::ui_ultrasmall(),
502@@ -293,6 +312,10 @@
503 : AbstractWaresDisplay(parent, x, y, tribe, type, selectable)
504 {}
505
506+RGBColor AbstractWaresDisplay::info_color_for_ware(Widelands::Ware_Index const ware) {
507+ return RGBColor(0, 0, 0);
508+}
509+
510 WaresDisplay::~WaresDisplay()
511 {
512 remove_all_warelists();
513
514=== modified file 'src/wui/waresdisplay.h'
515--- src/wui/waresdisplay.h 2010-11-05 19:36:57 +0000
516+++ src/wui/waresdisplay.h 2011-11-05 18:50:31 +0000
517@@ -23,6 +23,8 @@
518 #include "logic/warelist.h"
519 #include "logic/tribe.h"
520
521+#include "graphic/graphic.h"
522+
523 #include "ui_basic/textarea.h"
524
525 #include <vector>
526@@ -50,7 +52,9 @@
527 int32_t const x, int32_t const y,
528 Widelands::Tribe_Descr const &,
529 wdType type,
530- bool selectable);
531+ bool selectable,
532+ boost::function<void(Widelands::Ware_Index, bool)> callback_function = NULL,
533+ bool horizontal = true);
534
535 bool handle_mousemove
536 (Uint8 state, int32_t x, int32_t y, int32_t xdiff, int32_t ydiff);
537@@ -67,6 +71,8 @@
538 unselect_ware(ware);
539 else
540 select_ware(ware);
541+ if (m_callback_function)
542+ m_callback_function(ware, ware_selected(ware));
543 }
544
545 // Wares may be hidden
546@@ -82,6 +88,8 @@
547
548 virtual std::string info_for_ware(Widelands::Ware_Index const) = 0;
549
550+ virtual RGBColor info_color_for_ware(Widelands::Ware_Index);
551+
552 Widelands::Tribe_Descr::WaresOrder const & icons_order() const;
553 Widelands::Tribe_Descr::WaresOrderCoords const & icons_order_coords() const;
554 virtual Point ware_position(Widelands::Ware_Index) const;
555@@ -100,6 +108,8 @@
556 selection_type m_selected;
557 selection_type m_hidden;
558 bool m_selectable;
559+ bool m_horizontal;
560+ boost::function<void(Widelands::Ware_Index, bool)> m_callback_function;
561 };
562
563 /*

Subscribers

People subscribed via source and target branches

to status/vote changes: