Merge lp:~sequba/millenniumduel/widgets-margin into lp:millenniumduel
- widgets-margin
- Merge into trunk
Proposed by
Jakub Sękowski
Status: | Merged | ||||
---|---|---|---|---|---|
Approved by: | Jakub Sękowski | ||||
Approved revision: | 28 | ||||
Merged at revision: | 26 | ||||
Proposed branch: | lp:~sequba/millenniumduel/widgets-margin | ||||
Merge into: | lp:millenniumduel | ||||
Diff against target: |
687 lines (+146/-129) 20 files modified
src/IBox.cpp (+5/-5) src/IBox.hpp (+1/-7) src/IDrawable.cpp (+38/-13) src/IDrawable.hpp (+32/-14) src/IOrderedContainer.cpp (+0/-2) src/IOrderedContainer.hpp (+0/-7) src/WButton.cpp (+3/-3) src/WButton.hpp (+8/-5) src/WFixed.cpp (+3/-3) src/WFixed.hpp (+9/-5) src/WHBox.cpp (+9/-10) src/WHBox.hpp (+5/-4) src/WImage.cpp (+2/-2) src/WImage.hpp (+2/-3) src/WLabel.cpp (+3/-5) src/WLabel.hpp (+4/-3) src/WLayeredView.cpp (+3/-16) src/WLayeredView.hpp (+5/-8) src/WVBox.cpp (+9/-10) src/WVBox.hpp (+5/-4) |
||||
To merge this branch: | bzr merge lp:~sequba/millenniumduel/widgets-margin | ||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Rafał Cieślak | Approve | ||
Review via email: mp+177284@code.launchpad.net |
Commit message
Description of the change
Bug #1204286 fix. I've achieve this in exactly the way specified here: https:/
To post a comment you must log in.
- 27. By Jakub Sękowski
-
fixed problem with left and bottom margin and changed some variables names to avoid similar misunderstandings later on
- 28. By Jakub Sękowski
-
removed some redundant allegro transformations
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'src/IBox.cpp' |
2 | --- src/IBox.cpp 2013-07-28 08:39:44 +0000 |
3 | +++ src/IBox.cpp 2013-07-28 20:35:33 +0000 |
4 | @@ -1,13 +1,13 @@ |
5 | #include "IBox.hpp" |
6 | |
7 | -IBox::IBox() : _spacing(0), _margin(0) {} |
8 | +IBox::IBox() : |
9 | + _spacing(0), |
10 | + _current_width(-1), |
11 | + _current_height(-1) {} |
12 | |
13 | void IBox::SetSpacing(int s){ |
14 | _spacing = s; |
15 | } |
16 | -void IBox::SetMargin(int m){ |
17 | - _margin = m; |
18 | -} |
19 | |
20 | void IBox::_RecalculateSizes(int total, int (IDrawable::*size_func)()){ |
21 | if(children.size() == 0) return; |
22 | @@ -30,7 +30,7 @@ |
23 | if (shrinked_sum > 0) shrinked_sum -= _spacing; |
24 | |
25 | if(expand_count > 0){ |
26 | - int rest = total - 2*_margin - shrinked_sum; |
27 | + int rest = total - shrinked_sum; |
28 | int expand_size = rest / expand_count; |
29 | int last_expand_size = rest - (expand_size * expand_count) + expand_size; |
30 | |
31 | |
32 | === modified file 'src/IBox.hpp' |
33 | --- src/IBox.hpp 2013-07-28 08:39:44 +0000 |
34 | +++ src/IBox.hpp 2013-07-28 20:35:33 +0000 |
35 | @@ -10,18 +10,12 @@ |
36 | |
37 | public: |
38 | void SetSpacing(int spacing); |
39 | - void SetMargin(int margin); |
40 | |
41 | - //Drawable Methods: |
42 | virtual void Redraw(int w, int h) = 0; |
43 | - virtual int GetMinimalHeight() = 0; |
44 | - virtual int GetMinimalWidth () = 0; |
45 | - virtual void OnClicked(SCoordinates p) = 0; |
46 | |
47 | protected: |
48 | int _spacing; |
49 | - int _margin; |
50 | - int _current_width, _current_height; |
51 | + int _current_width, _current_height; //just "inner", excluding the margin |
52 | |
53 | void _RecalculateSizes(int total, int (IDrawable::*size_func)()); |
54 | }; |
55 | |
56 | === modified file 'src/IDrawable.cpp' |
57 | --- src/IDrawable.cpp 2013-07-28 08:39:44 +0000 |
58 | +++ src/IDrawable.cpp 2013-07-28 20:35:33 +0000 |
59 | @@ -12,12 +12,13 @@ |
60 | |
61 | IDrawable::IDrawable(){ |
62 | parent = nullptr; |
63 | - _previous_height = -1; |
64 | - _previous_width = -1; |
65 | + _last_drawn_height = -1; |
66 | + _last_drawn_width = -1; |
67 | _needs_redrawing = true; |
68 | _cache_bitmap = al_create_bitmap(0,0); |
69 | |
70 | _background_color = al_map_rgba(0,0,0,0); //fully transparent background by default |
71 | + _margin = 0; // by default: no margin |
72 | } |
73 | |
74 | IDrawable::~IDrawable(){ |
75 | @@ -37,24 +38,29 @@ |
76 | _background_color = al_map_rgba(0,0,0,0); |
77 | } |
78 | |
79 | +void IDrawable::SetMargin(int margin) |
80 | +{ |
81 | + _margin = margin; |
82 | +} |
83 | + |
84 | void IDrawable::Draw(SDrawArea area){ |
85 | - if(_needs_redrawing || area.w != _previous_width || area.h != _previous_height){ |
86 | + if(_needs_redrawing || area.w != _last_drawn_width || area.h != _last_drawn_height){ |
87 | // Somethings changed, this drawable's buffer needs to be redrawn |
88 | |
89 | - if(area.w != _previous_width || area.h != _previous_height) _ResizeCacheBitmap(area.w, area.h); |
90 | + if(area.w != _last_drawn_width || area.h != _last_drawn_height) _ResizeCacheBitmap(area.w, area.h); |
91 | |
92 | ALLEGRO_BITMAP* last_bitmap = al_get_target_bitmap(); |
93 | al_set_target_bitmap(_cache_bitmap); |
94 | - UseNewTransformTo(0,0); |
95 | al_clear_to_color(_background_color); |
96 | |
97 | - Redraw(area.w, area.h); |
98 | + UseNewTransformTo(_margin,_margin); |
99 | + Redraw(area.w-2*_margin, area.h-2*_margin); |
100 | |
101 | al_set_target_bitmap(last_bitmap); |
102 | |
103 | _needs_redrawing = false; |
104 | - _previous_height = area.h; |
105 | - _previous_width = area.w; |
106 | + _last_drawn_height = area.h; |
107 | + _last_drawn_width = area.w; |
108 | } |
109 | |
110 | // Draw this widget's cached version |
111 | @@ -67,9 +73,28 @@ |
112 | if(parent != nullptr) parent->SetNeedsRedrawing(); |
113 | } |
114 | |
115 | +int IDrawable::GetMinimalWidth () |
116 | +{ |
117 | + return _GetInnerMinimalWidth() + 2*_margin; |
118 | +} |
119 | +int IDrawable::GetMinimalHeight() |
120 | +{ |
121 | + return _GetInnerMinimalHeight() + 2*_margin; |
122 | +} |
123 | + |
124 | void IDrawable::OnClicked(SCoordinates p){ |
125 | - OnClicked(); //by default, use the ignoring position version |
126 | -} |
127 | - |
128 | -void IDrawable::OnClicked(){ |
129 | -} |
130 | + if(p.x < 0 || p.y < 0 || p.x > _last_drawn_width || p.y > _last_drawn_height) |
131 | + return; |
132 | + |
133 | + if(p.x <= _margin || p.y <= _margin || p.x > _last_drawn_width-_margin || p.y > _last_drawn_height-_margin) |
134 | + _OnMarginClicked(); |
135 | + else |
136 | + _OnInnerClicked(SCoordinates(p.x-_margin,p.y-_margin)); |
137 | +} |
138 | + |
139 | +void IDrawable::_OnInnerClicked(SCoordinates p) |
140 | +{ |
141 | + _OnInnerClicked(); |
142 | +} |
143 | +void IDrawable::_OnInnerClicked() {} |
144 | +void IDrawable::_OnMarginClicked() {} |
145 | |
146 | === modified file 'src/IDrawable.hpp' |
147 | --- src/IDrawable.hpp 2013-07-27 14:48:54 +0000 |
148 | +++ src/IDrawable.hpp 2013-07-28 20:35:33 +0000 |
149 | @@ -32,32 +32,36 @@ |
150 | /* Used to restore the default, transparent background */ |
151 | void RemoveBackgroundColor(); |
152 | |
153 | + void SetMargin(int margin); // - set widget's margin size |
154 | |
155 | /* This method can be called to draw this widget's graphical contents |
156 | * onto the current surface, in the place specified by the argument |
157 | * (coordinates + size). If possible, this method will avoid rendering |
158 | * the widget and will copy a cached bitmap instead, to maximize efficency. |
159 | + * Also, it takes care of widget's margin. |
160 | * This method should be never overwritten by any widgets. */ |
161 | void Draw(SDrawArea area); |
162 | |
163 | /* The redraw(...) method is used to re-render this widget's contents. |
164 | * It is used by draw(...) in case the cached bitmap requires updating. |
165 | * This is the method you should override when creating a custom widget. |
166 | - * The caller takes care of proper target bitmap, transformation and the |
167 | - * background, so you do not need to worry about these - just draw your |
168 | - * widget from (0,0) to (w,h). |
169 | + * The caller takes care of proper target bitmap, transformation, the |
170 | + * background and margin size, so you do not need to worry about these |
171 | + * - just draw your widget from (0,0) to (w,h) (ignoring background and |
172 | + * margin). |
173 | * Looking at other widgets' redraw(...) may be helpful when writing a |
174 | * new widget */ |
175 | virtual void Redraw(int w, int h) = 0; |
176 | |
177 | - |
178 | - /* Click coordinates are relative to widget position */ |
179 | - virtual void OnClicked(SCoordinates p); |
180 | - /* This version ignores position */ |
181 | - virtual void OnClicked(); |
182 | + /* This method should be called on widget when clicked. |
183 | + * It should be never overwritten by any widgets. */ |
184 | + void OnClicked(SCoordinates p); //click coordinates are relative to widget position |
185 | |
186 | - virtual int GetMinimalWidth () = 0; |
187 | - virtual int GetMinimalHeight() = 0; |
188 | + /* These two methods can be used to calculate widget's total size. They |
189 | + * make use of GetInnerMinimalWidth and GetInnerMinimalHeight |
190 | + * They should be never overwritten by any widgets. */ |
191 | + int GetMinimalWidth (); |
192 | + int GetMinimalHeight(); |
193 | |
194 | /* A helpful macro, used by probably every drawable in its draw() func */ |
195 | static void UseNewTransformTo(int x, int y); |
196 | @@ -77,16 +81,30 @@ |
197 | bool _needs_redrawing; |
198 | private: |
199 | ALLEGRO_COLOR _background_color; |
200 | + int _margin; |
201 | + |
202 | + /* These methods should specify widget's reaction for click respectively on |
203 | + * it's interior or margin. |
204 | + * These are the methods you should override when creating a custom widget. */ |
205 | + virtual void _OnInnerClicked(SCoordinates p); |
206 | + virtual void _OnInnerClicked(); |
207 | + virtual void _OnMarginClicked(); |
208 | + |
209 | + /* These methods should calculate widget's interior's size (excluding the |
210 | + * margin). |
211 | + * These are the methods you should override when creating a custom widget. */ |
212 | + virtual int _GetInnerMinimalWidth () = 0; |
213 | + virtual int _GetInnerMinimalHeight() = 0; |
214 | |
215 | /* The cached appearance of this widget. */ |
216 | ALLEGRO_BITMAP* _cache_bitmap; |
217 | /* A convenience method that creates a new bitmap of a new size. */ |
218 | void _ResizeCacheBitmap(int w, int h); |
219 | |
220 | - /* The previous widget size is stored to detect when a widget is resized |
221 | - * and needs redrawing. */ |
222 | - int _previous_width; |
223 | - int _previous_height; |
224 | + /* The widget size (as it was drawn the last time) is stored to detect when |
225 | + * a widget is resized and needs redrawing. */ |
226 | + int _last_drawn_width; |
227 | + int _last_drawn_height; |
228 | }; |
229 | |
230 | #endif //__IDRAWABLE_HPP__ |
231 | |
232 | === modified file 'src/IOrderedContainer.cpp' |
233 | --- src/IOrderedContainer.cpp 2013-07-28 08:39:44 +0000 |
234 | +++ src/IOrderedContainer.cpp 2013-07-28 20:35:33 +0000 |
235 | @@ -1,8 +1,6 @@ |
236 | #include "IOrderedContainer.hpp" |
237 | #include <iostream> |
238 | |
239 | -IOrderedContainer::IOrderedContainer() {}; |
240 | - |
241 | void IOrderedContainer::Add(IDrawable& item, int position, BoxPackingMode mode, bool is_visible){ |
242 | if(item.parent != nullptr){ |
243 | std::cerr << "Unable to add item to OrderedContainer: item already has a parent" << std::endl; |
244 | |
245 | === modified file 'src/IOrderedContainer.hpp' |
246 | --- src/IOrderedContainer.hpp 2013-07-28 08:39:44 +0000 |
247 | +++ src/IOrderedContainer.hpp 2013-07-28 20:35:33 +0000 |
248 | @@ -10,18 +10,11 @@ |
249 | }; |
250 | |
251 | class IOrderedContainer : public IDrawable{ |
252 | -protected: |
253 | - IOrderedContainer(); |
254 | - |
255 | public: |
256 | void Add(IDrawable& item, int position, BoxPackingMode mode = BOX_SHRINK, bool is_visible = true); |
257 | void SetVisibility(IDrawable& item, bool isVisible); |
258 | |
259 | - //Drawable Methods: |
260 | virtual void Redraw(int w, int h) = 0; |
261 | - virtual int GetMinimalHeight() = 0; |
262 | - virtual int GetMinimalWidth () = 0; |
263 | - virtual void OnClicked(SCoordinates p) = 0; |
264 | |
265 | protected: |
266 | struct ContainerEntry{ |
267 | |
268 | === modified file 'src/WButton.cpp' |
269 | --- src/WButton.cpp 2013-07-28 08:39:44 +0000 |
270 | +++ src/WButton.cpp 2013-07-28 20:35:33 +0000 |
271 | @@ -19,12 +19,12 @@ |
272 | al_draw_text(CDisplay::main_font, al_map_rgb(255,255,255), w/2, h/2 - 8, ALLEGRO_ALIGN_CENTRE, text.c_str()); |
273 | } |
274 | |
275 | -void WButton::OnClicked(){ |
276 | +void WButton::_OnInnerClicked(){ |
277 | if(_click_reaction == nullptr) return; |
278 | _click_reaction(); |
279 | } |
280 | |
281 | -int WButton::GetMinimalHeight() {return 20;} |
282 | -int WButton::GetMinimalWidth () { |
283 | +int WButton::_GetInnerMinimalHeight() {return 20;} |
284 | +int WButton::_GetInnerMinimalWidth () { |
285 | return al_get_text_width(CDisplay::main_font, text.c_str()) + 6; // 3px margin from both sides |
286 | } |
287 | |
288 | === modified file 'src/WButton.hpp' |
289 | --- src/WButton.hpp 2013-07-27 14:48:54 +0000 |
290 | +++ src/WButton.hpp 2013-07-28 20:35:33 +0000 |
291 | @@ -7,17 +7,20 @@ |
292 | class WButton : public IDrawable{ |
293 | public: |
294 | WButton(std::string); |
295 | + |
296 | + std::string text; |
297 | + |
298 | void SetClickReaction(void (*f)()); |
299 | |
300 | - std::string text; |
301 | - |
302 | virtual void Redraw(int w, int h) override; |
303 | - virtual void OnClicked() override; |
304 | |
305 | - virtual int GetMinimalHeight() override; |
306 | - virtual int GetMinimalWidth () override; |
307 | private: |
308 | void (*_click_reaction)() = nullptr; |
309 | + |
310 | + virtual void _OnInnerClicked() override; |
311 | + |
312 | + virtual int _GetInnerMinimalHeight() override; |
313 | + virtual int _GetInnerMinimalWidth () override; |
314 | }; |
315 | |
316 | #endif //__BUTTON_HPP__ |
317 | |
318 | === modified file 'src/WFixed.cpp' |
319 | --- src/WFixed.cpp 2013-07-28 08:39:44 +0000 |
320 | +++ src/WFixed.cpp 2013-07-28 20:35:33 +0000 |
321 | @@ -30,7 +30,7 @@ |
322 | SetNeedsRedrawing(); |
323 | } |
324 | |
325 | -void WFixed::OnClicked(SCoordinates p){ |
326 | +void WFixed::_OnInnerClicked(SCoordinates p){ |
327 | for(auto q : items){ |
328 | IDrawable* d = q.first; |
329 | SCoordinates c = q.second; |
330 | @@ -40,5 +40,5 @@ |
331 | } |
332 | } |
333 | |
334 | -int WFixed::GetMinimalHeight(){ return _height; } |
335 | -int WFixed::GetMinimalWidth() { return _width; } |
336 | +int WFixed::_GetInnerMinimalHeight(){ return _height; } |
337 | +int WFixed::_GetInnerMinimalWidth() { return _width; } |
338 | |
339 | === modified file 'src/WFixed.hpp' |
340 | --- src/WFixed.hpp 2013-07-28 08:39:44 +0000 |
341 | +++ src/WFixed.hpp 2013-07-28 20:35:33 +0000 |
342 | @@ -7,18 +7,22 @@ |
343 | class WFixed : public IDrawable{ |
344 | public: |
345 | WFixed(int w = 0, int h = 0); |
346 | - void Redraw(int w, int h); |
347 | + |
348 | void AddItem(IDrawable& d, SCoordinates c); |
349 | void RemoveItem(IDrawable& d); |
350 | - void OnClicked(SCoordinates p); |
351 | - |
352 | - virtual int GetMinimalWidth () override; |
353 | - virtual int GetMinimalHeight() override; |
354 | + |
355 | + void Redraw(int w, int h); |
356 | + |
357 | private: |
358 | std::map<IDrawable*,SCoordinates> items; |
359 | |
360 | int _width; |
361 | int _height; |
362 | + |
363 | + virtual void _OnInnerClicked(SCoordinates p); |
364 | + |
365 | + virtual int _GetInnerMinimalWidth () override; |
366 | + virtual int _GetInnerMinimalHeight() override; |
367 | }; |
368 | |
369 | #endif //__WFIXED_HPP__ |
370 | |
371 | === modified file 'src/WHBox.cpp' |
372 | --- src/WHBox.cpp 2013-07-28 09:06:58 +0000 |
373 | +++ src/WHBox.cpp 2013-07-28 20:35:33 +0000 |
374 | @@ -5,14 +5,13 @@ |
375 | |
376 | _RecalculateSizes(w, &IDrawable::GetMinimalWidth); |
377 | |
378 | - int x = _margin, y = _margin; |
379 | + int x=0, y=0; |
380 | |
381 | for(auto i : children){ |
382 | if(!i.is_visible) continue; //an unvisible widget. skip it... |
383 | |
384 | int width = i.size; |
385 | - int height = h - 2*_margin; |
386 | - |
387 | + int height = h; |
388 | |
389 | i.item.Draw(SDrawArea(x,y,width,height)); |
390 | |
391 | @@ -25,17 +24,17 @@ |
392 | _current_width = w; |
393 | } |
394 | |
395 | -int WHBox::GetMinimalHeight() { |
396 | +int WHBox::_GetInnerMinimalHeight() { |
397 | // Maximum of all items' heights |
398 | int max = 0; |
399 | for(auto i : children){ |
400 | int h = i.item.GetMinimalHeight(); |
401 | if (h > max) max = h; |
402 | } |
403 | - return max + 2*_margin; |
404 | + return max; |
405 | |
406 | } |
407 | -int WHBox::GetMinimalWidth () { |
408 | +int WHBox::_GetInnerMinimalWidth () { |
409 | // Sum of all items' widths and gaps |
410 | int sum = 0; |
411 | for(auto i : children){ |
412 | @@ -43,12 +42,12 @@ |
413 | sum += _spacing; |
414 | } |
415 | if(sum >= 0) sum -= _spacing; |
416 | - return sum + 2*_margin; |
417 | + return sum; |
418 | } |
419 | |
420 | -void WHBox::OnClicked(SCoordinates p){ |
421 | - if (p.x < _margin || p.y < _margin || _current_height - _margin <= p.y) return; |
422 | - int sum = _margin; |
423 | +void WHBox::_OnInnerClicked(SCoordinates p){ |
424 | + if(_current_height < p.y || _current_width < p.x) return; |
425 | + int sum=0; |
426 | for(auto i : children){ |
427 | if(!i.is_visible) continue; |
428 | if(p.x < sum + i.size) { // This item was clicked! |
429 | |
430 | === modified file 'src/WHBox.hpp' |
431 | --- src/WHBox.hpp 2013-07-27 17:01:04 +0000 |
432 | +++ src/WHBox.hpp 2013-07-28 20:35:33 +0000 |
433 | @@ -7,10 +7,11 @@ |
434 | public: |
435 | virtual void Redraw(int w, int h) override; |
436 | |
437 | - virtual int GetMinimalHeight() override; |
438 | - virtual int GetMinimalWidth () override; |
439 | - |
440 | - virtual void OnClicked(SCoordinates p) override; |
441 | +private: |
442 | + virtual void _OnInnerClicked(SCoordinates p) override; |
443 | + |
444 | + virtual int _GetInnerMinimalHeight() override; |
445 | + virtual int _GetInnerMinimalWidth () override; |
446 | }; |
447 | |
448 | #endif //__WHBOX_HPP__ |
449 | |
450 | === modified file 'src/WImage.cpp' |
451 | --- src/WImage.cpp 2013-07-28 08:39:44 +0000 |
452 | +++ src/WImage.cpp 2013-07-28 20:35:33 +0000 |
453 | @@ -16,8 +16,8 @@ |
454 | al_destroy_bitmap(_bitmap); |
455 | } |
456 | |
457 | -int WImage::GetMinimalHeight(){return _height;} |
458 | -int WImage::GetMinimalWidth (){return _width; } |
459 | +int WImage::_GetInnerMinimalHeight(){return _height;} |
460 | +int WImage::_GetInnerMinimalWidth (){return _width; } |
461 | void WImage::SetMinimalHeight(int h) {_height = h; SetNeedsRedrawing();} |
462 | void WImage::SetMinimalWidth (int w) {_width = w; SetNeedsRedrawing();} |
463 | |
464 | |
465 | === modified file 'src/WImage.hpp' |
466 | --- src/WImage.hpp 2013-07-28 08:39:44 +0000 |
467 | +++ src/WImage.hpp 2013-07-28 20:35:33 +0000 |
468 | @@ -14,9 +14,6 @@ |
469 | |
470 | virtual void Redraw(int w, int h) override; |
471 | |
472 | - virtual int GetMinimalHeight() override; |
473 | - virtual int GetMinimalWidth () override; |
474 | - |
475 | void SetMinimalHeight(int); |
476 | void SetMinimalWidth (int); |
477 | private: |
478 | @@ -28,6 +25,8 @@ |
479 | int _bitmap_height; |
480 | int _bitmap_width; |
481 | |
482 | + virtual int _GetInnerMinimalHeight() override; |
483 | + virtual int _GetInnerMinimalWidth () override; |
484 | }; |
485 | |
486 | #endif //__WIMAGE_HPP__ |
487 | |
488 | === modified file 'src/WLabel.cpp' |
489 | --- src/WLabel.cpp 2013-07-28 08:39:44 +0000 |
490 | +++ src/WLabel.cpp 2013-07-28 20:35:33 +0000 |
491 | @@ -8,17 +8,15 @@ |
492 | //extern ALLEGRO_FONT* main_font; |
493 | |
494 | |
495 | -WLabel::WLabel(std::string _text) : text(_text){ |
496 | - |
497 | -} |
498 | +WLabel::WLabel(std::string _text) : text(_text) {} |
499 | |
500 | void WLabel::Redraw(int w, int h){ |
501 | ALLEGRO_COLOR white = al_map_rgb(255, 255, 255); |
502 | al_draw_text(CDisplay::main_font, white, w/2, h/2 - 8 ,ALLEGRO_ALIGN_CENTRE, text.c_str()); |
503 | } |
504 | |
505 | -int WLabel::GetMinimalHeight() {return 20;} |
506 | -int WLabel::GetMinimalWidth () { |
507 | +int WLabel::_GetInnerMinimalHeight() {return 20;} |
508 | +int WLabel::_GetInnerMinimalWidth () { |
509 | return al_get_text_width(CDisplay::main_font, text.c_str()) + 6; // 3px margin from both sides |
510 | } |
511 | |
512 | |
513 | === modified file 'src/WLabel.hpp' |
514 | --- src/WLabel.hpp 2013-07-27 14:48:54 +0000 |
515 | +++ src/WLabel.hpp 2013-07-28 20:35:33 +0000 |
516 | @@ -10,9 +10,10 @@ |
517 | std::string text; |
518 | |
519 | virtual void Redraw(int w, int h) override; |
520 | - |
521 | - virtual int GetMinimalHeight() override; |
522 | - virtual int GetMinimalWidth () override; |
523 | + |
524 | +private: |
525 | + virtual int _GetInnerMinimalHeight() override; |
526 | + virtual int _GetInnerMinimalWidth () override; |
527 | }; |
528 | |
529 | #endif //__WLABEL_HPP__ |
530 | |
531 | === modified file 'src/WLayeredView.cpp' |
532 | --- src/WLayeredView.cpp 2013-07-28 08:39:44 +0000 |
533 | +++ src/WLayeredView.cpp 2013-07-28 20:35:33 +0000 |
534 | @@ -1,7 +1,5 @@ |
535 | #include "WLayeredView.hpp" |
536 | |
537 | -WLayeredView::WLayeredView() {} |
538 | - |
539 | void WLayeredView::ActivateLayer(IDrawable& layer) |
540 | { |
541 | //move layer to the front and make it visible |
542 | @@ -41,7 +39,7 @@ |
543 | i->item.Draw(SDrawArea(0,0,w,h)); |
544 | } |
545 | |
546 | -void WLayeredView::OnClicked(SCoordinates p) |
547 | +void WLayeredView::_OnInnerClicked(SCoordinates p) |
548 | { |
549 | //pass "click signal" to currently active layer |
550 | for(auto i = children.begin() ; i != children.end() ; i++) |
551 | @@ -52,18 +50,7 @@ |
552 | } |
553 | } |
554 | |
555 | -void WLayeredView::OnClicked() |
556 | -{ |
557 | - //pass "click signal" to currently active layer |
558 | - for(auto i = children.begin() ; i != children.end() ; i++) |
559 | - if(i->is_visible) |
560 | - { |
561 | - i->item.OnClicked(); |
562 | - break; |
563 | - } |
564 | -} |
565 | - |
566 | -int WLayeredView::GetMinimalWidth() |
567 | +int WLayeredView::_GetInnerMinimalWidth() |
568 | { |
569 | //find maximum of layers' widths |
570 | int max = 0; |
571 | @@ -75,7 +62,7 @@ |
572 | return max; |
573 | } |
574 | |
575 | -int WLayeredView::GetMinimalHeight() |
576 | +int WLayeredView::_GetInnerMinimalHeight() |
577 | { |
578 | //find maximum of layers' heights |
579 | int max = 0; |
580 | |
581 | === modified file 'src/WLayeredView.hpp' |
582 | --- src/WLayeredView.hpp 2013-07-27 17:01:04 +0000 |
583 | +++ src/WLayeredView.hpp 2013-07-28 20:35:33 +0000 |
584 | @@ -6,19 +6,16 @@ |
585 | class WLayeredView : public IOrderedContainer |
586 | { |
587 | public: |
588 | - WLayeredView(); |
589 | - |
590 | void ActivateLayer(IDrawable& layer); |
591 | void HideLayer(IDrawable& layer); |
592 | void SetOnlyVisibleLayer(IDrawable& layer); |
593 | |
594 | - //Drawable Methods: |
595 | virtual void Redraw(int w, int h); |
596 | - virtual void OnClicked(SCoordinates p); |
597 | - virtual void OnClicked(); |
598 | - |
599 | - virtual int GetMinimalWidth (); |
600 | - virtual int GetMinimalHeight(); |
601 | +private: |
602 | + virtual void _OnInnerClicked(SCoordinates p); |
603 | + |
604 | + virtual int _GetInnerMinimalWidth (); |
605 | + virtual int _GetInnerMinimalHeight(); |
606 | }; |
607 | |
608 | #endif // __WLAYEREDVIEW_HPP__ |
609 | |
610 | === modified file 'src/WVBox.cpp' |
611 | --- src/WVBox.cpp 2013-07-28 09:06:58 +0000 |
612 | +++ src/WVBox.cpp 2013-07-28 20:35:33 +0000 |
613 | @@ -5,15 +5,14 @@ |
614 | |
615 | _RecalculateSizes(h, &IDrawable::GetMinimalHeight); |
616 | |
617 | - int x = _margin, y = _margin; |
618 | + int x=0, y=0; |
619 | |
620 | for(auto i : children){ |
621 | if(!i.is_visible) continue; //an unvisible widget. skip it... |
622 | |
623 | - int width = w - 2*_margin; |
624 | + int width = w; |
625 | int height = i.size; |
626 | |
627 | - |
628 | i.item.Draw(SDrawArea(x,y,width,height)); |
629 | |
630 | y += i.size; |
631 | @@ -26,7 +25,7 @@ |
632 | |
633 | } |
634 | |
635 | -int WVBox::GetMinimalHeight() { |
636 | +int WVBox::_GetInnerMinimalHeight() { |
637 | // Sum of all items' heights and gaps |
638 | int sum = 0; |
639 | for(auto i : children){ |
640 | @@ -34,21 +33,21 @@ |
641 | sum += _spacing; |
642 | } |
643 | if(sum >= 0) sum -= _spacing; |
644 | - return sum + 2*_margin; |
645 | + return sum; |
646 | } |
647 | -int WVBox::GetMinimalWidth () { |
648 | +int WVBox::_GetInnerMinimalWidth () { |
649 | // Maximum of all items' widths |
650 | int max = 0; |
651 | for(auto i : children){ |
652 | int w = i.item.GetMinimalWidth(); |
653 | if (w > max) max = w; |
654 | } |
655 | - return max + 2*_margin; |
656 | + return max; |
657 | } |
658 | |
659 | -void WVBox::OnClicked(SCoordinates p){ |
660 | - if (p.y < _margin || p.x < _margin || _current_width - _margin <= p.x) return; |
661 | - int sum = _margin; |
662 | +void WVBox::_OnInnerClicked(SCoordinates p){ |
663 | + if(_current_height < p.y || _current_width < p.x) return; |
664 | + int sum=0; |
665 | for(auto i : children){ |
666 | if(!i.is_visible) continue; |
667 | if(p.y < sum + i.size) { // This item was clicked! |
668 | |
669 | === modified file 'src/WVBox.hpp' |
670 | --- src/WVBox.hpp 2013-07-27 17:01:04 +0000 |
671 | +++ src/WVBox.hpp 2013-07-28 20:35:33 +0000 |
672 | @@ -7,10 +7,11 @@ |
673 | public: |
674 | virtual void Redraw(int w, int h) override; |
675 | |
676 | - virtual int GetMinimalHeight() override; |
677 | - virtual int GetMinimalWidth () override; |
678 | - |
679 | - virtual void OnClicked(SCoordinates p) override; |
680 | +private: |
681 | + virtual void _OnInnerClicked(SCoordinates p) override; |
682 | + |
683 | + virtual int _GetInnerMinimalHeight() override; |
684 | + virtual int _GetInnerMinimalWidth () override; |
685 | }; |
686 | |
687 | #endif //__WVBOX_HPP__ |
This looks perfect. Thanks!