Merge lp:~widelands-dev/widelands/bug-1395278-graphic into lp:widelands
- bug-1395278-graphic
- Merge into trunk
Proposed by
GunChleoc
Status: | Merged | ||||
---|---|---|---|---|---|
Merged at revision: | 7897 | ||||
Proposed branch: | lp:~widelands-dev/widelands/bug-1395278-graphic | ||||
Merge into: | lp:widelands | ||||
Diff against target: |
2991 lines (+649/-647) 22 files modified
src/graphic/font.cc (+18/-18) src/graphic/font.h (+6/-6) src/graphic/gl/utils.h (+1/-1) src/graphic/rendertarget.cc (+69/-69) src/graphic/rendertarget.h (+9/-9) src/graphic/screen.cc (+9/-9) src/graphic/screen.h (+1/-1) src/graphic/text/rt_errors.h (+3/-3) src/graphic/text/rt_parse.cc (+67/-67) src/graphic/text/rt_parse.h (+13/-13) src/graphic/text/rt_render.cc (+265/-263) src/graphic/text/sdl_ttf_font.cc (+3/-3) src/graphic/text/sdl_ttf_font.h (+1/-1) src/graphic/text/textstream.cc (+25/-25) src/graphic/text/textstream.h (+9/-9) src/graphic/text_layout.cc (+2/-2) src/graphic/text_parser.cc (+17/-17) src/graphic/text_parser.h (+43/-43) src/graphic/texture.cc (+34/-34) src/graphic/texture.h (+3/-3) src/graphic/wordwrap.cc (+45/-45) src/graphic/wordwrap.h (+6/-6) |
||||
To merge this branch: | bzr merge lp:~widelands-dev/widelands/bug-1395278-graphic | ||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
TiborB | Approve | ||
Review via email: mp+289402@code.launchpad.net |
Commit message
Refactored member variables in src/graphic.
Description of the change
3 remaining and then we're done...
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/font.cc' |
2 | --- src/graphic/font.cc 2016-02-03 22:42:34 +0000 |
3 | +++ src/graphic/font.cc 2016-03-17 17:18:59 +0000 |
4 | @@ -57,18 +57,18 @@ |
5 | // Load the TrueType Font |
6 | std::string filename = "i18n/fonts/"; |
7 | filename += name; |
8 | - m_size = input_size; |
9 | + size_ = input_size; |
10 | |
11 | // We must keep this File Read open, otherwise the following calls are |
12 | // crashing. do not know why... |
13 | - m_fontfile.open(*g_fs, filename); |
14 | + fontfile_.open(*g_fs, filename); |
15 | |
16 | - SDL_RWops * const ops = SDL_RWFromMem(m_fontfile.data(0), m_fontfile.get_size()); |
17 | + SDL_RWops * const ops = SDL_RWFromMem(fontfile_.data(0), fontfile_.get_size()); |
18 | if (!ops) |
19 | throw wexception("could not load font!: RWops Pointer invalid"); |
20 | |
21 | - m_font = TTF_OpenFontIndexRW(ops, 1, input_size, 0); |
22 | - if (!m_font) |
23 | + font_ = TTF_OpenFontIndexRW(ops, 1, input_size, 0); |
24 | + if (!font_) |
25 | throw wexception("could not load font!: %s", TTF_GetError()); |
26 | |
27 | // Compute the line skip based on some glyphs by sampling some letters, |
28 | @@ -76,18 +76,18 @@ |
29 | // It seems more reasonable to use TTF_FontLineSkip(), but the fonts |
30 | // we use claim to have a very excessive line skip. |
31 | static uint16_t glyphs[] = {'A', '_', '@', ',', 'q', 'y', '"', 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5}; |
32 | - m_computed_typical_miny = 0; |
33 | - m_computed_typical_maxy = 0; |
34 | + computed_typical_miny_ = 0; |
35 | + computed_typical_maxy_ = 0; |
36 | |
37 | for (unsigned int idx = 0; idx < sizeof(glyphs) / sizeof(glyphs[0]); ++idx) { |
38 | int miny, maxy; |
39 | - if (TTF_GlyphMetrics(m_font, glyphs[idx], nullptr, nullptr, &miny, &maxy, nullptr) < 0) |
40 | + if (TTF_GlyphMetrics(font_, glyphs[idx], nullptr, nullptr, &miny, &maxy, nullptr) < 0) |
41 | continue; // error, e.g. glyph not found |
42 | |
43 | - if (miny < m_computed_typical_miny) |
44 | - m_computed_typical_miny = miny; |
45 | - if (maxy > m_computed_typical_maxy) |
46 | - m_computed_typical_maxy = maxy; |
47 | + if (miny < computed_typical_miny_) |
48 | + computed_typical_miny_ = miny; |
49 | + if (maxy > computed_typical_maxy_) |
50 | + computed_typical_maxy_ = maxy; |
51 | } |
52 | } |
53 | |
54 | @@ -96,8 +96,8 @@ |
55 | */ |
56 | Font::~Font() |
57 | { |
58 | - TTF_CloseFont(m_font); |
59 | - m_font = nullptr; |
60 | + TTF_CloseFont(font_); |
61 | + font_ = nullptr; |
62 | } |
63 | |
64 | /** |
65 | @@ -105,7 +105,7 @@ |
66 | */ |
67 | uint32_t Font::height() const |
68 | { |
69 | - return TTF_FontHeight(m_font); |
70 | + return TTF_FontHeight(font_); |
71 | } |
72 | |
73 | /** |
74 | @@ -113,7 +113,7 @@ |
75 | */ |
76 | uint32_t Font::size() const |
77 | { |
78 | - return m_size; |
79 | + return size_; |
80 | } |
81 | |
82 | /** |
83 | @@ -121,7 +121,7 @@ |
84 | */ |
85 | uint32_t Font::ascent() const |
86 | { |
87 | - return TTF_FontAscent(m_font); |
88 | + return TTF_FontAscent(font_); |
89 | } |
90 | |
91 | /** |
92 | @@ -129,7 +129,7 @@ |
93 | */ |
94 | uint32_t Font::lineskip() const |
95 | { |
96 | - return m_computed_typical_maxy - m_computed_typical_miny; |
97 | + return computed_typical_maxy_ - computed_typical_miny_; |
98 | } |
99 | |
100 | /** |
101 | |
102 | === modified file 'src/graphic/font.h' |
103 | --- src/graphic/font.h 2015-10-23 12:05:36 +0000 |
104 | +++ src/graphic/font.h 2016-03-17 17:18:59 +0000 |
105 | @@ -50,23 +50,23 @@ |
106 | uint32_t height() const; |
107 | uint32_t lineskip() const; |
108 | |
109 | - TTF_Font * get_ttf_font() const {return m_font;} |
110 | + TTF_Font * get_ttf_font() const {return font_;} |
111 | |
112 | private: |
113 | Font(const std::string & name, int size); |
114 | ~Font(); |
115 | |
116 | - FileRead m_fontfile; |
117 | - TTF_Font * m_font; |
118 | + FileRead fontfile_; |
119 | + TTF_Font * font_; |
120 | |
121 | /** |
122 | * Work around weird fonts with very large lineskip, to get something |
123 | * that makes more sense as the default skip in Latin scripts. |
124 | */ |
125 | - int32_t m_computed_typical_miny; |
126 | - int32_t m_computed_typical_maxy; |
127 | + int32_t computed_typical_miny_; |
128 | + int32_t computed_typical_maxy_; |
129 | |
130 | - int m_size; |
131 | + int size_; |
132 | }; |
133 | |
134 | } // namespace UI |
135 | |
136 | === modified file 'src/graphic/gl/utils.h' |
137 | --- src/graphic/gl/utils.h 2016-02-01 10:32:12 +0000 |
138 | +++ src/graphic/gl/utils.h 2016-03-17 17:18:59 +0000 |
139 | @@ -143,7 +143,7 @@ |
140 | // Calls glVertexAttribPointer. |
141 | void vertex_attrib_pointer(int vertex_index, int num_items, int stride, int offset); |
142 | |
143 | -// Swap order of rows in m_pixels, to compensate for the upside-down nature of the |
144 | +// Swap order of rows in pixels, to compensate for the upside-down nature of the |
145 | // OpenGL coordinate system. |
146 | void swap_rows(int width, int height, int pitch, int bpp, uint8_t* pixels); |
147 | |
148 | |
149 | === modified file 'src/graphic/rendertarget.cc' |
150 | --- src/graphic/rendertarget.cc 2016-03-07 18:55:11 +0000 |
151 | +++ src/graphic/rendertarget.cc 2016-03-17 17:18:59 +0000 |
152 | @@ -29,7 +29,7 @@ |
153 | */ |
154 | RenderTarget::RenderTarget(Surface* surf) |
155 | { |
156 | - m_surface = surf; |
157 | + surface_ = surf; |
158 | reset(); |
159 | } |
160 | |
161 | @@ -38,30 +38,30 @@ |
162 | */ |
163 | void RenderTarget::set_window(const Rect& rc, const Point& ofs) |
164 | { |
165 | - m_rect = rc; |
166 | - m_offset = ofs; |
167 | + rect_ = rc; |
168 | + offset_ = ofs; |
169 | |
170 | // safeguards clipping against the bitmap itself |
171 | |
172 | - if (m_rect.x < 0) { |
173 | - m_offset.x += m_rect.x; |
174 | - m_rect.w = std::max<int32_t>(m_rect.w + m_rect.x, 0); |
175 | - m_rect.x = 0; |
176 | - } |
177 | - |
178 | - if (m_rect.x + m_rect.w > m_surface->width()) |
179 | - m_rect.w = |
180 | - std::max<int32_t>(m_surface->width() - m_rect.x, 0); |
181 | - |
182 | - if (m_rect.y < 0) { |
183 | - m_offset.y += m_rect.y; |
184 | - m_rect.h = std::max<int32_t>(m_rect.h + m_rect.y, 0); |
185 | - m_rect.y = 0; |
186 | - } |
187 | - |
188 | - if (m_rect.y + m_rect.h > m_surface->height()) |
189 | - m_rect.h = |
190 | - std::max<int32_t>(m_surface->height() - m_rect.y, 0); |
191 | + if (rect_.x < 0) { |
192 | + offset_.x += rect_.x; |
193 | + rect_.w = std::max<int32_t>(rect_.w + rect_.x, 0); |
194 | + rect_.x = 0; |
195 | + } |
196 | + |
197 | + if (rect_.x + rect_.w > surface_->width()) |
198 | + rect_.w = |
199 | + std::max<int32_t>(surface_->width() - rect_.x, 0); |
200 | + |
201 | + if (rect_.y < 0) { |
202 | + offset_.y += rect_.y; |
203 | + rect_.h = std::max<int32_t>(rect_.h + rect_.y, 0); |
204 | + rect_.y = 0; |
205 | + } |
206 | + |
207 | + if (rect_.y + rect_.h > surface_->height()) |
208 | + rect_.h = |
209 | + std::max<int32_t>(surface_->height() - rect_.y, 0); |
210 | } |
211 | |
212 | /** |
213 | @@ -80,13 +80,13 @@ |
214 | |
215 | if (clip(newrect)) { |
216 | if (previous) |
217 | - *previous = m_rect; |
218 | + *previous = rect_; |
219 | if (prevofs) |
220 | - *prevofs = m_offset; |
221 | + *prevofs = offset_; |
222 | |
223 | // Apply the changes |
224 | - m_offset = rc.origin() - (newrect.origin() - m_rect.origin() - m_offset); |
225 | - m_rect = newrect; |
226 | + offset_ = rc.origin() - (newrect.origin() - rect_.origin() - offset_); |
227 | + rect_ = newrect; |
228 | |
229 | return true; |
230 | } else return false; |
231 | @@ -97,7 +97,7 @@ |
232 | */ |
233 | int32_t RenderTarget::width() const |
234 | { |
235 | - return m_surface->width(); |
236 | + return surface_->width(); |
237 | } |
238 | |
239 | /** |
240 | @@ -105,7 +105,7 @@ |
241 | */ |
242 | int32_t RenderTarget::height() const |
243 | { |
244 | - return m_surface->height(); |
245 | + return surface_->height(); |
246 | } |
247 | |
248 | /** |
249 | @@ -117,9 +117,9 @@ |
250 | std::vector<FloatPoint> adjusted_points; |
251 | adjusted_points.reserve(points.size()); |
252 | for (const auto& p : points) { |
253 | - adjusted_points.emplace_back(p.x + m_offset.x + m_rect.x, p.y + m_offset.y + m_rect.y); |
254 | + adjusted_points.emplace_back(p.x + offset_.x + rect_.x, p.y + offset_.y + rect_.y); |
255 | } |
256 | - m_surface->draw_line_strip(adjusted_points, color, line_width); |
257 | + surface_->draw_line_strip(adjusted_points, color, line_width); |
258 | } |
259 | |
260 | /** |
261 | @@ -129,7 +129,7 @@ |
262 | { |
263 | Rect r(rect); |
264 | if (clip(r)) { |
265 | - ::draw_rect(r, clr, m_surface); |
266 | + ::draw_rect(r, clr, surface_); |
267 | } |
268 | } |
269 | |
270 | @@ -137,14 +137,14 @@ |
271 | { |
272 | Rect r(rect); |
273 | if (clip(r)) |
274 | - m_surface->fill_rect(r, clr); |
275 | + surface_->fill_rect(r, clr); |
276 | } |
277 | |
278 | void RenderTarget::brighten_rect(const Rect& rect, int32_t factor) |
279 | { |
280 | Rect r(rect); |
281 | if (clip(r)) |
282 | - m_surface->brighten_rect(r, factor); |
283 | + surface_->brighten_rect(r, factor); |
284 | } |
285 | |
286 | /** |
287 | @@ -161,7 +161,7 @@ |
288 | Rect destination_rect(destination_point.x, destination_point.y, source_rect.w, source_rect.h); |
289 | |
290 | if (to_surface_geometry(&destination_rect, &source_rect)) { |
291 | - m_surface->blit(destination_rect, *image, source_rect, 1., blend_mode); |
292 | + surface_->blit(destination_rect, *image, source_rect, 1., blend_mode); |
293 | } |
294 | } |
295 | |
296 | @@ -175,7 +175,7 @@ |
297 | Rect destination_rect(destination_point.x, destination_point.y, source_rect.w, source_rect.h); |
298 | |
299 | if (to_surface_geometry(&destination_rect, &source_rect)) { |
300 | - m_surface->blit_monochrome(destination_rect, *image, source_rect, blend_mode); |
301 | + surface_->blit_monochrome(destination_rect, *image, source_rect, blend_mode); |
302 | } |
303 | } |
304 | |
305 | @@ -197,7 +197,7 @@ |
306 | Rect destination_rect(dst.x, dst.y, source_rect.w, source_rect.h); |
307 | |
308 | if (to_surface_geometry(&destination_rect, &source_rect)) { |
309 | - m_surface->blit(destination_rect, *image, source_rect, 1., blend_mode); |
310 | + surface_->blit(destination_rect, *image, source_rect, 1., blend_mode); |
311 | } |
312 | } |
313 | |
314 | @@ -207,7 +207,7 @@ |
315 | const float opacity, |
316 | const BlendMode blend_mode) { |
317 | if (to_surface_geometry(&destination_rect, &source_rect)) { |
318 | - m_surface->blit(destination_rect, *image, source_rect, opacity, blend_mode); |
319 | + surface_->blit(destination_rect, *image, source_rect, opacity, blend_mode); |
320 | } |
321 | } |
322 | |
323 | @@ -216,7 +216,7 @@ |
324 | Rect source_rect, |
325 | const RGBAColor& blend) { |
326 | if (to_surface_geometry(&destination_rect, &source_rect)) { |
327 | - m_surface->blit_monochrome(destination_rect, *image, source_rect, blend); |
328 | + surface_->blit_monochrome(destination_rect, *image, source_rect, blend); |
329 | } |
330 | } |
331 | |
332 | @@ -234,11 +234,11 @@ |
333 | Rect r(rect); |
334 | Point ofs(gofs); |
335 | if (clip(r)) { |
336 | - if (m_offset.x < 0) |
337 | - ofs.x -= m_offset.x; |
338 | + if (offset_.x < 0) |
339 | + ofs.x -= offset_.x; |
340 | |
341 | - if (m_offset.y < 0) |
342 | - ofs.y -= m_offset.y; |
343 | + if (offset_.y < 0) |
344 | + ofs.y -= offset_.y; |
345 | |
346 | // Make sure the offset is within bounds |
347 | ofs.x = ofs.x % srcw; |
348 | @@ -273,7 +273,7 @@ |
349 | srcrc.w = r.w - tx; |
350 | |
351 | const Rect dst_rect(r.x + tx, r.y + ty, srcrc.w, srcrc.h); |
352 | - m_surface->blit(dst_rect, *image, srcrc, 1., blend_mode); |
353 | + surface_->blit(dst_rect, *image, srcrc, 1., blend_mode); |
354 | |
355 | tx += srcrc.w; |
356 | |
357 | @@ -332,7 +332,7 @@ |
358 | source_rect.h); |
359 | Rect srcrc(source_rect); |
360 | if (to_surface_geometry(&destination_rect, &srcrc)) { |
361 | - animation.blit(time, destination_rect.origin(), srcrc, player_color, m_surface); |
362 | + animation.blit(time, destination_rect.origin(), srcrc, player_color, surface_); |
363 | } |
364 | |
365 | // Look if there is a sound effect registered for this frame and trigger the |
366 | @@ -348,23 +348,23 @@ |
367 | */ |
368 | void RenderTarget::reset() |
369 | { |
370 | - m_rect.x = m_rect.y = 0; |
371 | - m_rect.w = m_surface->width(); |
372 | - m_rect.h = m_surface->height(); |
373 | + rect_.x = rect_.y = 0; |
374 | + rect_.w = surface_->width(); |
375 | + rect_.h = surface_->height(); |
376 | |
377 | - m_offset.x = m_offset.y = 0; |
378 | + offset_.x = offset_.y = 0; |
379 | } |
380 | |
381 | /** |
382 | - * Offsets r by m_offset and clips r against m_rect. |
383 | + * Offsets r by offset_ and clips r against rect_. |
384 | * |
385 | * If true is returned, r a valid rectangle that can be used. |
386 | * If false is returned, r may not be used and may be partially modified. |
387 | */ |
388 | bool RenderTarget::clip(Rect & r) const |
389 | { |
390 | - r.x += m_offset.x; |
391 | - r.y += m_offset.y; |
392 | + r.x += offset_.x; |
393 | + r.y += offset_.y; |
394 | |
395 | if (r.x < 0) { |
396 | if (r.w <= -r.x) |
397 | @@ -375,10 +375,10 @@ |
398 | r.x = 0; |
399 | } |
400 | |
401 | - if (r.x + r.w > m_rect.w) { |
402 | - if (m_rect.w <= r.x) |
403 | + if (r.x + r.w > rect_.w) { |
404 | + if (rect_.w <= r.x) |
405 | return false; |
406 | - r.w = m_rect.w - r.x; |
407 | + r.w = rect_.w - r.x; |
408 | } |
409 | |
410 | if (r.y < 0) { |
411 | @@ -388,14 +388,14 @@ |
412 | r.y = 0; |
413 | } |
414 | |
415 | - if (r.y + r.h > m_rect.h) { |
416 | - if (m_rect.h <= r.y) |
417 | + if (r.y + r.h > rect_.h) { |
418 | + if (rect_.h <= r.y) |
419 | return false; |
420 | - r.h = m_rect.h - r.y; |
421 | + r.h = rect_.h - r.y; |
422 | } |
423 | |
424 | - r.x += m_rect.x; |
425 | - r.y += m_rect.y; |
426 | + r.x += rect_.x; |
427 | + r.y += rect_.y; |
428 | |
429 | return r.w && r.h; |
430 | } |
431 | @@ -408,8 +408,8 @@ |
432 | { |
433 | assert(0 <= source_rect->x); |
434 | assert(0 <= source_rect->y); |
435 | - destination_rect->x += m_offset.x; |
436 | - destination_rect->y += m_offset.y; |
437 | + destination_rect->x += offset_.x; |
438 | + destination_rect->y += offset_.y; |
439 | |
440 | // We have to clip the target rect against our own drawing area. If we make |
441 | // changes to any side of our rectangle, we have to change the source rect |
442 | @@ -431,11 +431,11 @@ |
443 | } |
444 | |
445 | // Clipping, from the right. |
446 | - if (destination_rect->x + destination_rect->w > m_rect.w) { |
447 | - if (m_rect.w <= destination_rect->x) { |
448 | + if (destination_rect->x + destination_rect->w > rect_.w) { |
449 | + if (rect_.w <= destination_rect->x) { |
450 | return false; |
451 | } |
452 | - const int new_destination_w = m_rect.w - destination_rect->x; |
453 | + const int new_destination_w = rect_.w - destination_rect->x; |
454 | // Adding 0.5 is a cheap way of turning integer truncation into a rounded value. |
455 | source_rect->w = |
456 | 0.5 + static_cast<double>(new_destination_w) / destination_rect->w * source_rect->w; |
457 | @@ -457,18 +457,18 @@ |
458 | } |
459 | |
460 | // Clipping, from the bottom. |
461 | - if (destination_rect->y + destination_rect->h > m_rect.h) { |
462 | - if (m_rect.h <= destination_rect->y) { |
463 | + if (destination_rect->y + destination_rect->h > rect_.h) { |
464 | + if (rect_.h <= destination_rect->y) { |
465 | return false; |
466 | } |
467 | - const int new_destination_h = m_rect.h - destination_rect->y; |
468 | + const int new_destination_h = rect_.h - destination_rect->y; |
469 | // Adding 0.5 is a cheap way of turning integer truncation into a rounded value. |
470 | source_rect->h = |
471 | 0.5 + static_cast<double>(new_destination_h) / destination_rect->h * source_rect->h; |
472 | destination_rect->h = new_destination_h; |
473 | } |
474 | |
475 | - destination_rect->x += m_rect.x; |
476 | - destination_rect->y += m_rect.y; |
477 | + destination_rect->x += rect_.x; |
478 | + destination_rect->y += rect_.y; |
479 | return true; |
480 | } |
481 | |
482 | === modified file 'src/graphic/rendertarget.h' |
483 | --- src/graphic/rendertarget.h 2016-02-19 19:10:44 +0000 |
484 | +++ src/graphic/rendertarget.h 2016-03-17 17:18:59 +0000 |
485 | @@ -116,9 +116,9 @@ |
486 | |
487 | void reset(); |
488 | |
489 | - Surface* get_surface() const {return m_surface;} |
490 | - const Rect& get_rect() const {return m_rect;} |
491 | - const Point& get_offset() const {return m_offset;} |
492 | + Surface* get_surface() const {return surface_;} |
493 | + const Rect& get_rect() const {return rect_;} |
494 | + const Point& get_offset() const {return offset_;} |
495 | |
496 | protected: |
497 | bool clip(Rect & r) const; |
498 | @@ -131,12 +131,12 @@ |
499 | const RGBColor* player_color, |
500 | const Rect& source_rect); |
501 | |
502 | - ///The target surface |
503 | - Surface* m_surface; |
504 | - ///The current clip rectangle |
505 | - Rect m_rect; |
506 | - ///Drawing offset |
507 | - Point m_offset; |
508 | + /// The target surface |
509 | + Surface* surface_; |
510 | + /// The current clip rectangle |
511 | + Rect rect_; |
512 | + /// Drawing offset |
513 | + Point offset_; |
514 | }; |
515 | |
516 | #endif // end of include guard: WL_GRAPHIC_RENDERTARGET_H |
517 | |
518 | === modified file 'src/graphic/screen.cc' |
519 | --- src/graphic/screen.cc 2016-02-02 09:02:53 +0000 |
520 | +++ src/graphic/screen.cc 2016-03-17 17:18:59 +0000 |
521 | @@ -27,31 +27,31 @@ |
522 | #include "graphic/render_queue.h" |
523 | #include "graphic/texture.h" |
524 | |
525 | -Screen::Screen(int w, int h) : m_w(w), m_h(h) { |
526 | +Screen::Screen(int w, int h) : w_(w), h_(h) { |
527 | } |
528 | |
529 | int Screen::width() const { |
530 | - return m_w; |
531 | + return w_; |
532 | } |
533 | |
534 | int Screen::height() const { |
535 | - return m_h; |
536 | + return h_; |
537 | } |
538 | |
539 | std::unique_ptr<Texture> Screen::to_texture() const { |
540 | - std::unique_ptr<uint8_t[]> pixels(new uint8_t[m_w * m_h * 4]); |
541 | - glReadPixels(0, 0, m_w, m_h, GL_RGBA, GL_UNSIGNED_BYTE, pixels.get()); |
542 | + std::unique_ptr<uint8_t[]> pixels(new uint8_t[w_ * h_ * 4]); |
543 | + glReadPixels(0, 0, w_, h_, GL_RGBA, GL_UNSIGNED_BYTE, pixels.get()); |
544 | |
545 | - Gl::swap_rows(m_w, m_h, m_w * 4, 4, pixels.get()); |
546 | + Gl::swap_rows(w_, h_, w_ * 4, 4, pixels.get()); |
547 | |
548 | // Ownership of pixels is not taken here. But the Texture() transfers it to |
549 | // the GPU, frees the SDL surface and after that we are free to free |
550 | // 'pixels'. |
551 | SDL_Surface* surface = SDL_CreateRGBSurfaceFrom(pixels.get(), |
552 | - m_w, |
553 | - m_h, |
554 | + w_, |
555 | + h_, |
556 | 32, |
557 | - m_w * 4, |
558 | + w_ * 4, |
559 | 0x000000ff, |
560 | 0x0000ff00, |
561 | 0x00ff0000, |
562 | |
563 | === modified file 'src/graphic/screen.h' |
564 | --- src/graphic/screen.h 2016-02-02 09:02:53 +0000 |
565 | +++ src/graphic/screen.h 2016-03-17 17:18:59 +0000 |
566 | @@ -57,7 +57,7 @@ |
567 | void |
568 | do_fill_rect(const FloatRect& dst_rect, const RGBAColor& color, BlendMode blend_mode) override; |
569 | |
570 | - const int m_w, m_h; |
571 | + const int w_, h_; |
572 | |
573 | DISALLOW_COPY_AND_ASSIGN(Screen); |
574 | }; |
575 | |
576 | === modified file 'src/graphic/text/rt_errors.h' |
577 | --- src/graphic/text/rt_errors.h 2016-01-31 15:31:00 +0000 |
578 | +++ src/graphic/text/rt_errors.h 2016-03-17 17:18:59 +0000 |
579 | @@ -28,12 +28,12 @@ |
580 | |
581 | class Exception : public std::exception { |
582 | public: |
583 | - Exception(std::string msg) : std::exception(), m_msg(msg) { |
584 | + Exception(std::string msg) : std::exception(), msg_(msg) { |
585 | } |
586 | - const char* what() const noexcept override {return m_msg.c_str();} |
587 | + const char* what() const noexcept override {return msg_.c_str();} |
588 | |
589 | private: |
590 | - std::string m_msg; |
591 | + std::string msg_; |
592 | }; |
593 | |
594 | #define DEF_ERR(Name) class Name : public Exception { \ |
595 | |
596 | === modified file 'src/graphic/text/rt_parse.cc' |
597 | --- src/graphic/text/rt_parse.cc 2016-02-21 12:08:36 +0000 |
598 | +++ src/graphic/text/rt_parse.cc 2016-03-17 17:18:59 +0000 |
599 | @@ -34,103 +34,103 @@ |
600 | |
601 | namespace RT { |
602 | |
603 | -Attr::Attr(const std::string& gname, const std::string& value) : m_name(gname), m_value(value) { |
604 | +Attr::Attr(const std::string& gname, const std::string& value) : name_(gname), value_(value) { |
605 | } |
606 | |
607 | const std::string& Attr::name() const { |
608 | - return m_name; |
609 | + return name_; |
610 | } |
611 | |
612 | long Attr::get_int() const { |
613 | - long rv = strtol(m_value.c_str(), nullptr, 10); |
614 | + long rv = strtol(value_.c_str(), nullptr, 10); |
615 | return rv; |
616 | } |
617 | |
618 | std::string Attr::get_string() const { |
619 | - return m_value; |
620 | + return value_; |
621 | } |
622 | |
623 | bool Attr::get_bool() const { |
624 | - if (m_value == "true" || m_value == "1" || m_value == "yes") |
625 | + if (value_ == "true" || value_ == "1" || value_ == "yes") |
626 | return true; |
627 | return false; |
628 | } |
629 | |
630 | RGBColor Attr::get_color() const { |
631 | - if (m_value.size() != 6) |
632 | - throw InvalidColor((boost::format("Could not parse '%s' as a color.") % m_value).str()); |
633 | + if (value_.size() != 6) |
634 | + throw InvalidColor((boost::format("Could not parse '%s' as a color.") % value_).str()); |
635 | |
636 | - uint32_t clrn = strtol(m_value.c_str(), nullptr, 16); |
637 | + uint32_t clrn = strtol(value_.c_str(), nullptr, 16); |
638 | return RGBColor((clrn >> 16) & 0xff, (clrn >> 8) & 0xff, clrn & 0xff); |
639 | } |
640 | |
641 | void AttrMap::add_attribute(const std::string& name, Attr* a) { |
642 | - m_attrs[name] = std::unique_ptr<Attr>(a); |
643 | + attrs_[name] = std::unique_ptr<Attr>(a); |
644 | } |
645 | |
646 | const Attr& AttrMap::operator[](const std::string& s) const { |
647 | - const auto i = m_attrs.find(s); |
648 | - if (i == m_attrs.end()) { |
649 | + const auto i = attrs_.find(s); |
650 | + if (i == attrs_.end()) { |
651 | throw AttributeNotFound(s); |
652 | } |
653 | return *(i->second); |
654 | } |
655 | |
656 | bool AttrMap::has(const std::string& s) const { |
657 | - return m_attrs.count(s); |
658 | + return attrs_.count(s); |
659 | } |
660 | |
661 | const std::string& Tag::name() const { |
662 | - return m_name; |
663 | + return name_; |
664 | } |
665 | |
666 | const AttrMap& Tag::attrs() const { |
667 | - return m_am; |
668 | + return attribute_map_; |
669 | } |
670 | |
671 | -const Tag::ChildList& Tag::childs() const { |
672 | - return m_childs; |
673 | +const Tag::ChildList& Tag::children() const { |
674 | + return children_; |
675 | } |
676 | |
677 | Tag::~Tag() { |
678 | - while (m_childs.size()) { |
679 | - delete m_childs.back(); |
680 | - m_childs.pop_back(); |
681 | + while (children_.size()) { |
682 | + delete children_.back(); |
683 | + children_.pop_back(); |
684 | } |
685 | } |
686 | |
687 | -void Tag::m_parse_opening_tag(TextStream & ts, TagConstraints & tcs) { |
688 | +void Tag::parse_opening_tag(TextStream & ts, TagConstraints & tcs) { |
689 | ts.expect("<"); |
690 | - m_name = ts.till_any(" \t\n>"); |
691 | + name_ = ts.till_any(" \t\n>"); |
692 | ts.skip_ws(); |
693 | |
694 | while (ts.peek(1) != ">") { |
695 | - m_parse_attribute(ts, tcs[m_name].allowed_attrs); |
696 | + parse_attribute(ts, tcs[name_].allowed_attrs); |
697 | ts.skip_ws(); |
698 | } |
699 | |
700 | ts.expect(">"); |
701 | } |
702 | |
703 | -void Tag::m_parse_closing_tag(TextStream & ts) { |
704 | +void Tag::parse_closing_tag(TextStream & ts) { |
705 | ts.expect("</"); |
706 | - ts.expect(m_name, false); |
707 | + ts.expect(name_, false); |
708 | ts.expect(">", false); |
709 | } |
710 | |
711 | -void Tag::m_parse_attribute(TextStream & ts, std::unordered_set<std::string> & allowed_attrs) { |
712 | +void Tag::parse_attribute(TextStream & ts, std::unordered_set<std::string> & allowed_attrs) { |
713 | std::string aname = ts.till_any("="); |
714 | if (!allowed_attrs.count(aname)) |
715 | throw SyntaxErrorImpl(ts.line(), ts.col(), "an allowed attribute", aname, ts.peek(100)); |
716 | |
717 | ts.skip(1); |
718 | |
719 | - m_am.add_attribute(aname, new Attr(aname, ts.parse_string())); |
720 | + attribute_map_.add_attribute(aname, new Attr(aname, ts.parse_string())); |
721 | } |
722 | |
723 | -void Tag::m_parse_content(TextStream & ts, TagConstraints & tcs, const TagSet & allowed_tags) |
724 | +void Tag::parse_content(TextStream & ts, TagConstraints & tcs, const TagSet & allowed_tags) |
725 | { |
726 | - TagConstraint tc = tcs[m_name]; |
727 | + TagConstraint tc = tcs[name_]; |
728 | |
729 | for (;;) { |
730 | if (!tc.text_allowed) |
731 | @@ -142,31 +142,31 @@ |
732 | if (!tc.text_allowed) { |
733 | throw SyntaxErrorImpl(line, col, "no text, as only tags are allowed here", text, ts.peek(100)); |
734 | } |
735 | - m_childs.push_back(new Child(text)); |
736 | + children_.push_back(new Child(text)); |
737 | } |
738 | |
739 | - if (ts.peek(2 + m_name.size()) == ("</" + m_name)) |
740 | + if (ts.peek(2 + name_.size()) == ("</" + name_)) |
741 | break; |
742 | |
743 | Tag * child = new Tag(); |
744 | line = ts.line(); col = ts.col(); size_t cpos = ts.pos(); |
745 | child->parse(ts, tcs, allowed_tags); |
746 | - if (!tc.allowed_childs.count(child->name())) |
747 | + if (!tc.allowed_children.count(child->name())) |
748 | throw SyntaxErrorImpl(line, col, "an allowed tag", child->name(), ts.peek(100, cpos)); |
749 | if (!allowed_tags.empty() && !allowed_tags.count(child->name())) |
750 | throw SyntaxErrorImpl(line, col, "an allowed tag", child->name(), ts.peek(100, cpos)); |
751 | |
752 | - m_childs.push_back(new Child(child)); |
753 | + children_.push_back(new Child(child)); |
754 | } |
755 | } |
756 | |
757 | void Tag::parse(TextStream & ts, TagConstraints & tcs, const TagSet & allowed_tags) { |
758 | - m_parse_opening_tag(ts, tcs); |
759 | + parse_opening_tag(ts, tcs); |
760 | |
761 | - TagConstraint tc = tcs[m_name]; |
762 | + TagConstraint tc = tcs[name_]; |
763 | if (tc.has_closing_tag) { |
764 | - m_parse_content(ts, tcs, allowed_tags); |
765 | - m_parse_closing_tag(ts); |
766 | + parse_content(ts, tcs, allowed_tags); |
767 | + parse_closing_tag(ts); |
768 | } |
769 | } |
770 | |
771 | @@ -186,19 +186,19 @@ |
772 | tc.allowed_attrs.insert("keep_spaces"); // Keeps blank spaces intact for text editing |
773 | tc.allowed_attrs.insert("background"); |
774 | |
775 | - tc.allowed_childs.insert("p"); |
776 | - tc.allowed_childs.insert("vspace"); |
777 | - tc.allowed_childs.insert("font"); |
778 | - tc.allowed_childs.insert("sub"); |
779 | + tc.allowed_children.insert("p"); |
780 | + tc.allowed_children.insert("vspace"); |
781 | + tc.allowed_children.insert("font"); |
782 | + tc.allowed_children.insert("sub"); |
783 | tc.text_allowed = false; |
784 | tc.has_closing_tag = true; |
785 | - m_tcs["rt"] = tc; |
786 | + tag_constraints_["rt"] = tc; |
787 | } |
788 | { // br tag |
789 | TagConstraint tc; |
790 | tc.text_allowed = false; |
791 | tc.has_closing_tag = false; |
792 | - m_tcs["br"] = tc; |
793 | + tag_constraints_["br"] = tc; |
794 | } |
795 | { // img tag |
796 | TagConstraint tc; |
797 | @@ -206,14 +206,14 @@ |
798 | tc.allowed_attrs.insert("ref"); |
799 | tc.text_allowed = false; |
800 | tc.has_closing_tag = false; |
801 | - m_tcs["img"] = tc; |
802 | + tag_constraints_["img"] = tc; |
803 | } |
804 | { // vspace tag |
805 | TagConstraint tc; |
806 | tc.allowed_attrs.insert("gap"); |
807 | tc.text_allowed = false; |
808 | tc.has_closing_tag = false; |
809 | - m_tcs["vspace"] = tc; |
810 | + tag_constraints_["vspace"] = tc; |
811 | } |
812 | { // space tag |
813 | TagConstraint tc; |
814 | @@ -221,7 +221,7 @@ |
815 | tc.allowed_attrs.insert("fill"); |
816 | tc.text_allowed = false; |
817 | tc.has_closing_tag = false; |
818 | - m_tcs["space"] = tc; |
819 | + tag_constraints_["space"] = tc; |
820 | } |
821 | { // sub tag |
822 | TagConstraint tc; |
823 | @@ -236,14 +236,14 @@ |
824 | tc.allowed_attrs.insert("background"); |
825 | tc.allowed_attrs.insert("width"); |
826 | |
827 | - tc.allowed_childs.insert("p"); |
828 | - tc.allowed_childs.insert("vspace"); |
829 | - tc.allowed_childs.insert("font"); |
830 | - tc.allowed_childs.insert("sub"); |
831 | + tc.allowed_children.insert("p"); |
832 | + tc.allowed_children.insert("vspace"); |
833 | + tc.allowed_children.insert("font"); |
834 | + tc.allowed_children.insert("sub"); |
835 | |
836 | tc.text_allowed = false; |
837 | tc.has_closing_tag = true; |
838 | - m_tcs["sub"] = tc; |
839 | + tag_constraints_["sub"] = tc; |
840 | } |
841 | { // p tag |
842 | TagConstraint tc; |
843 | @@ -252,14 +252,14 @@ |
844 | tc.allowed_attrs.insert("valign"); |
845 | tc.allowed_attrs.insert("spacing"); |
846 | |
847 | - tc.allowed_childs.insert("font"); |
848 | - tc.allowed_childs.insert("space"); |
849 | - tc.allowed_childs.insert("br"); |
850 | - tc.allowed_childs.insert("img"); |
851 | - tc.allowed_childs.insert("sub"); |
852 | + tc.allowed_children.insert("font"); |
853 | + tc.allowed_children.insert("space"); |
854 | + tc.allowed_children.insert("br"); |
855 | + tc.allowed_children.insert("img"); |
856 | + tc.allowed_children.insert("sub"); |
857 | tc.text_allowed = true; |
858 | tc.has_closing_tag = true; |
859 | - m_tcs["p"] = tc; |
860 | + tag_constraints_["p"] = tc; |
861 | } |
862 | { // font tag |
863 | TagConstraint tc; |
864 | @@ -272,14 +272,14 @@ |
865 | tc.allowed_attrs.insert("shadow"); |
866 | tc.allowed_attrs.insert("ref"); |
867 | |
868 | - tc.allowed_childs.insert("br"); |
869 | - tc.allowed_childs.insert("space"); |
870 | - tc.allowed_childs.insert("p"); |
871 | - tc.allowed_childs.insert("font"); |
872 | - tc.allowed_childs.insert("sub"); |
873 | + tc.allowed_children.insert("br"); |
874 | + tc.allowed_children.insert("space"); |
875 | + tc.allowed_children.insert("p"); |
876 | + tc.allowed_children.insert("font"); |
877 | + tc.allowed_children.insert("sub"); |
878 | tc.text_allowed = true; |
879 | tc.has_closing_tag = true; |
880 | - m_tcs["font"] = tc; |
881 | + tag_constraints_["font"] = tc; |
882 | } |
883 | } |
884 | |
885 | @@ -289,18 +289,18 @@ |
886 | Tag * Parser::parse(std::string text, const TagSet & allowed_tags) { |
887 | boost::replace_all(text, "\\", "\\\\"); // Prevent crashes with \. |
888 | |
889 | - m_ts.reset(new TextStream(text)); |
890 | + text_stream_.reset(new TextStream(text)); |
891 | |
892 | - m_ts->skip_ws(); m_ts->rskip_ws(); |
893 | + text_stream_->skip_ws(); text_stream_->rskip_ws(); |
894 | Tag * rv = new Tag(); |
895 | - rv->parse(*m_ts, m_tcs, allowed_tags); |
896 | + rv->parse(*text_stream_, tag_constraints_, allowed_tags); |
897 | |
898 | return rv; |
899 | } |
900 | std::string Parser::remaining_text() { |
901 | - if (m_ts == nullptr) |
902 | + if (text_stream_ == nullptr) |
903 | return ""; |
904 | - return m_ts->remaining_text(); |
905 | + return text_stream_->remaining_text(); |
906 | } |
907 | |
908 | } |
909 | |
910 | === modified file 'src/graphic/text/rt_parse.h' |
911 | --- src/graphic/text/rt_parse.h 2014-09-14 11:31:58 +0000 |
912 | +++ src/graphic/text/rt_parse.h 2016-03-17 17:18:59 +0000 |
913 | @@ -49,7 +49,7 @@ |
914 | RGBColor get_color() const; |
915 | |
916 | private: |
917 | - const std::string m_name, m_value; |
918 | + const std::string name_, value_; |
919 | }; |
920 | |
921 | // This is basically a map<string, Attr>. |
922 | @@ -65,12 +65,12 @@ |
923 | bool has(const std::string& name) const; |
924 | |
925 | private: |
926 | - std::map<std::string, std::unique_ptr<Attr>> m_attrs; |
927 | + std::map<std::string, std::unique_ptr<Attr>> attrs_; |
928 | }; |
929 | |
930 | struct TagConstraint { |
931 | std::unordered_set<std::string> allowed_attrs; |
932 | - std::unordered_set<std::string> allowed_childs; |
933 | + std::unordered_set<std::string> allowed_children; |
934 | bool text_allowed; |
935 | bool has_closing_tag; |
936 | }; |
937 | @@ -85,18 +85,18 @@ |
938 | |
939 | const std::string & name() const; |
940 | const AttrMap & attrs() const; |
941 | - const ChildList & childs() const; |
942 | + const ChildList & children() const; |
943 | void parse(TextStream& ts, TagConstraints& tcs, const TagSet&); |
944 | |
945 | private: |
946 | - void m_parse_opening_tag(TextStream & ts, TagConstraints & tcs); |
947 | - void m_parse_closing_tag(TextStream & ts); |
948 | - void m_parse_attribute(TextStream & ts, std::unordered_set<std::string> &); |
949 | - void m_parse_content(TextStream & ts, TagConstraints & tc, const TagSet &); |
950 | + void parse_opening_tag(TextStream & ts, TagConstraints & tcs); |
951 | + void parse_closing_tag(TextStream & ts); |
952 | + void parse_attribute(TextStream & ts, std::unordered_set<std::string> &); |
953 | + void parse_content(TextStream & ts, TagConstraints & tc, const TagSet &); |
954 | |
955 | - std::string m_name; |
956 | - AttrMap m_am; |
957 | - ChildList m_childs; |
958 | + std::string name_; |
959 | + AttrMap attribute_map_; |
960 | + ChildList children_; |
961 | }; |
962 | |
963 | struct Child { |
964 | @@ -122,8 +122,8 @@ |
965 | std::string remaining_text(); |
966 | |
967 | private: |
968 | - TagConstraints m_tcs; |
969 | - std::unique_ptr<TextStream> m_ts; |
970 | + TagConstraints tag_constraints_; |
971 | + std::unique_ptr<TextStream> text_stream_; |
972 | }; |
973 | } |
974 | |
975 | |
976 | === modified file 'src/graphic/text/rt_render.cc' |
977 | --- src/graphic/text/rt_render.cc 2016-02-14 14:16:26 +0000 |
978 | +++ src/graphic/text/rt_render.cc 2016-03-17 17:18:59 +0000 |
979 | @@ -96,13 +96,13 @@ |
980 | using FontMap = map<FontDescr, IFont*>; |
981 | using FontMapPair = pair<const FontDescr, std::unique_ptr<IFont>>; |
982 | |
983 | - FontMap m_fontmap; |
984 | + FontMap fontmap_; |
985 | |
986 | DISALLOW_COPY_AND_ASSIGN(FontCache); |
987 | }; |
988 | |
989 | FontCache::~FontCache() { |
990 | - for (FontMap::reference& entry : m_fontmap) { |
991 | + for (FontMap::reference& entry : fontmap_) { |
992 | delete entry.second; |
993 | } |
994 | } |
995 | @@ -154,8 +154,8 @@ |
996 | uint16_t font_size = ns->font_size + ns->fontset->size_offset(); |
997 | |
998 | FontDescr fd = {ns->font_face, font_size}; |
999 | - FontMap::iterator i = m_fontmap.find(fd); |
1000 | - if (i != m_fontmap.end()) |
1001 | + FontMap::iterator i = fontmap_.find(fd); |
1002 | + if (i != fontmap_.end()) |
1003 | return *i->second; |
1004 | |
1005 | std::unique_ptr<IFont> font; |
1006 | @@ -167,7 +167,7 @@ |
1007 | } |
1008 | assert(font != nullptr); |
1009 | |
1010 | - return *m_fontmap.insert(std::make_pair(fd, font.release())).first->second; |
1011 | + return *fontmap_.insert(std::make_pair(fd, font.release())).first->second; |
1012 | } |
1013 | |
1014 | struct Reference { |
1015 | @@ -177,18 +177,18 @@ |
1016 | |
1017 | class RefMap : public IRefMap { |
1018 | public: |
1019 | - RefMap(const vector<Reference>& refs) : m_refs(refs) {} |
1020 | + RefMap(const vector<Reference>& refs) : refs_(refs) {} |
1021 | string query(int16_t x, int16_t y) override { |
1022 | // Should this linear algorithm proof to be too slow (doubtful), the |
1023 | // RefMap could also be efficiently implemented using an R-Tree |
1024 | - for (const Reference& c : m_refs) |
1025 | + for (const Reference& c : refs_) |
1026 | if (c.dim.contains(Point(x, y))) |
1027 | return c.ref; |
1028 | return ""; |
1029 | } |
1030 | |
1031 | private: |
1032 | - vector<Reference> m_refs; |
1033 | + vector<Reference> refs_; |
1034 | }; |
1035 | |
1036 | class RenderNode { |
1037 | @@ -199,7 +199,7 @@ |
1038 | FLOAT_LEFT, |
1039 | }; |
1040 | RenderNode(NodeStyle& ns) |
1041 | - : m_floating(NO_FLOAT), m_halign(ns.halign), m_valign(ns.valign), m_x(0), m_y(0) {} |
1042 | + : floating_(NO_FLOAT), halign_(ns.halign), valign_(ns.valign), x_(0), y_(0) {} |
1043 | virtual ~RenderNode() {} |
1044 | |
1045 | virtual uint16_t width() = 0; |
1046 | @@ -209,34 +209,34 @@ |
1047 | |
1048 | virtual bool is_non_mandatory_space() {return false;} |
1049 | virtual bool is_expanding() {return false;} |
1050 | - virtual void set_w(uint16_t) {} // Only, when expanding |
1051 | + virtual void set_w(uint16_t) {} // Only, when is_expanding |
1052 | |
1053 | virtual const vector<Reference> get_references() {return vector<Reference>();} |
1054 | |
1055 | - Floating get_floating() {return m_floating;} |
1056 | - void set_floating(Floating f) {m_floating = f;} |
1057 | - UI::Align halign() {return m_halign;} |
1058 | - void set_halign(UI::Align ghalign) {m_halign = ghalign;} |
1059 | - UI::Align valign() {return m_valign;} |
1060 | - void set_valign(UI::Align gvalign) {m_valign = gvalign;} |
1061 | - void set_x(int32_t nx) {m_x = nx;} |
1062 | - void set_y(int32_t ny) {m_y = ny;} |
1063 | - int32_t x() {return m_x;} |
1064 | - int32_t y() {return m_y;} |
1065 | + Floating get_floating() {return floating_;} |
1066 | + void set_floating(Floating f) {floating_ = f;} |
1067 | + UI::Align halign() {return halign_;} |
1068 | + void set_halign(UI::Align ghalign) {halign_ = ghalign;} |
1069 | + UI::Align valign() {return valign_;} |
1070 | + void set_valign(UI::Align gvalign) {valign_ = gvalign;} |
1071 | + void set_x(int32_t nx) {x_ = nx;} |
1072 | + void set_y(int32_t ny) {y_ = ny;} |
1073 | + int32_t x() {return x_;} |
1074 | + int32_t y() {return y_;} |
1075 | |
1076 | private: |
1077 | - Floating m_floating; |
1078 | - UI::Align m_halign; |
1079 | - UI::Align m_valign; |
1080 | - int32_t m_x, m_y; |
1081 | + Floating floating_; |
1082 | + UI::Align halign_; |
1083 | + UI::Align valign_; |
1084 | + int32_t x_, y_; |
1085 | }; |
1086 | |
1087 | class Layout { |
1088 | public: |
1089 | - Layout(vector<RenderNode*>& all) : m_h(0), m_idx(0), m_all_nodes(all) {} |
1090 | + Layout(vector<RenderNode*>& all) : h_(0), idx_(0), all_nodes_(all) {} |
1091 | virtual ~Layout() {} |
1092 | |
1093 | - uint16_t height() {return m_h;} |
1094 | + uint16_t height() {return h_;} |
1095 | uint16_t fit_nodes(vector<RenderNode*>& rv, uint16_t w, Borders p, bool shrink_to_fit); |
1096 | |
1097 | private: |
1098 | @@ -253,33 +253,33 @@ |
1099 | } |
1100 | }; |
1101 | |
1102 | - uint16_t m_fit_line(uint16_t w, const Borders&, vector<RenderNode*>* rv, bool shrink_to_fit); |
1103 | + uint16_t fit_line(uint16_t w, const Borders&, vector<RenderNode*>* rv, bool shrink_to_fit); |
1104 | |
1105 | - uint16_t m_h; |
1106 | - size_t m_idx; |
1107 | - vector<RenderNode*>& m_all_nodes; |
1108 | - priority_queue<ConstraintChange> m_constraint_changes; |
1109 | + uint16_t h_; |
1110 | + size_t idx_; |
1111 | + vector<RenderNode*>& all_nodes_; |
1112 | + priority_queue<ConstraintChange> constraint_changes_; |
1113 | }; |
1114 | |
1115 | -uint16_t Layout::m_fit_line(uint16_t w, const Borders& p, vector<RenderNode*>* rv, bool shrink_to_fit) { |
1116 | +uint16_t Layout::fit_line(uint16_t w, const Borders& p, vector<RenderNode*>* rv, bool shrink_to_fit) { |
1117 | assert(rv->empty()); |
1118 | |
1119 | // Remove leading spaces |
1120 | - while (m_idx < m_all_nodes.size() |
1121 | - && m_all_nodes[m_idx]->is_non_mandatory_space() |
1122 | + while (idx_ < all_nodes_.size() |
1123 | + && all_nodes_[idx_]->is_non_mandatory_space() |
1124 | && shrink_to_fit) { |
1125 | - delete m_all_nodes[m_idx++]; |
1126 | + delete all_nodes_[idx_++]; |
1127 | } |
1128 | |
1129 | uint16_t x = p.left; |
1130 | - std::size_t first_m_idx = m_idx; |
1131 | + std::size_t first_idx = idx_; |
1132 | |
1133 | // Calc fitting nodes |
1134 | - while (m_idx < m_all_nodes.size()) { |
1135 | - RenderNode* n = m_all_nodes[m_idx]; |
1136 | + while (idx_ < all_nodes_.size()) { |
1137 | + RenderNode* n = all_nodes_[idx_]; |
1138 | uint16_t nw = n->width(); |
1139 | if (x + nw + p.right > w || n->get_floating() != RenderNode::NO_FLOAT) { |
1140 | - if (m_idx == first_m_idx) { |
1141 | + if (idx_ == first_idx) { |
1142 | nw = w - p.right - x; |
1143 | } else { |
1144 | break; |
1145 | @@ -287,7 +287,7 @@ |
1146 | } |
1147 | n->set_x(x); x += nw; |
1148 | rv->push_back(n); |
1149 | - ++m_idx; |
1150 | + ++idx_; |
1151 | } |
1152 | // Remove trailing spaces |
1153 | while (!rv->empty() |
1154 | @@ -299,9 +299,9 @@ |
1155 | } |
1156 | |
1157 | // Remaining space in this line |
1158 | - uint16_t rem_space = 0; |
1159 | + uint16_t remaining_space = 0; |
1160 | if (w < INFINITE_WIDTH) { |
1161 | - rem_space = w - p.right - x; |
1162 | + remaining_space = w - p.right - x; |
1163 | } |
1164 | |
1165 | // Find expanding nodes |
1166 | @@ -311,7 +311,7 @@ |
1167 | expanding_nodes.push_back(idx); |
1168 | |
1169 | if (!expanding_nodes.empty()) { // If there are expanding nodes, we fill the space |
1170 | - const uint16_t individual_w = rem_space / expanding_nodes.size(); |
1171 | + const uint16_t individual_w = remaining_space / expanding_nodes.size(); |
1172 | for (const size_t idx : expanding_nodes) { |
1173 | rv->at(idx)->set_w(individual_w); |
1174 | for (size_t nidx = idx + 1; nidx < rv->size(); ++nidx) |
1175 | @@ -321,10 +321,10 @@ |
1176 | // Take last elements style in this line and check horizontal alignment |
1177 | if (!rv->empty() && (*rv->rbegin())->halign() != UI::Align::kLeft) { |
1178 | if ((*rv->rbegin())->halign() == UI::Align::kCenter) { |
1179 | - rem_space /= 2; // Otherwise, we align right |
1180 | + remaining_space /= 2; // Otherwise, we align right |
1181 | } |
1182 | for (RenderNode* node : *rv) { |
1183 | - node->set_x(node->x() + rem_space); |
1184 | + node->set_x(node->x() + remaining_space); |
1185 | } |
1186 | } |
1187 | } |
1188 | @@ -343,20 +343,20 @@ |
1189 | */ |
1190 | uint16_t Layout::fit_nodes(vector<RenderNode*>& rv, uint16_t w, Borders p, bool shrink_to_fit) { |
1191 | assert(rv.empty()); |
1192 | - m_h = p.top; |
1193 | + h_ = p.top; |
1194 | |
1195 | uint16_t max_line_width = 0; |
1196 | - while (m_idx < m_all_nodes.size()) { |
1197 | + while (idx_ < all_nodes_.size()) { |
1198 | vector<RenderNode*> nodes_in_line; |
1199 | - size_t m_idx_before_iteration = m_idx; |
1200 | - uint16_t biggest_hotspot = m_fit_line(w, p, &nodes_in_line, shrink_to_fit); |
1201 | + size_t idx_before_iteration_ = idx_; |
1202 | + uint16_t biggest_hotspot = fit_line(w, p, &nodes_in_line, shrink_to_fit); |
1203 | |
1204 | int line_height = 0; |
1205 | int line_start = INFINITE_WIDTH; |
1206 | // Compute real line height and width, taking into account alignement |
1207 | for (RenderNode* n : nodes_in_line) { |
1208 | line_height = max(line_height, biggest_hotspot - n->hotspot_y() + n->height()); |
1209 | - n->set_y(m_h + biggest_hotspot - n->hotspot_y()); |
1210 | + n->set_y(h_ + biggest_hotspot - n->hotspot_y()); |
1211 | if (line_start >= INFINITE_WIDTH || n->x() < line_start) { |
1212 | line_start = n->x() - p.left; |
1213 | } |
1214 | @@ -379,18 +379,18 @@ |
1215 | } |
1216 | rv.insert(rv.end(), nodes_in_line.begin(), nodes_in_line.end()); |
1217 | |
1218 | - m_h += line_height; |
1219 | - while (! m_constraint_changes.empty() && m_constraint_changes.top().at_y <= m_h) { |
1220 | - const ConstraintChange& top = m_constraint_changes.top(); |
1221 | + h_ += line_height; |
1222 | + while (! constraint_changes_.empty() && constraint_changes_.top().at_y <= h_) { |
1223 | + const ConstraintChange& top = constraint_changes_.top(); |
1224 | w += top.delta_w; |
1225 | p.left += top.delta_offset_x; |
1226 | - m_constraint_changes.pop(); |
1227 | + constraint_changes_.pop(); |
1228 | } |
1229 | |
1230 | - if ((m_idx < m_all_nodes.size()) && m_all_nodes[m_idx]->get_floating()) { |
1231 | - RenderNode* n = m_all_nodes[m_idx]; |
1232 | - n->set_y(m_h); |
1233 | - ConstraintChange cc = {m_h + n->height(), 0, 0}; |
1234 | + if ((idx_ < all_nodes_.size()) && all_nodes_[idx_]->get_floating()) { |
1235 | + RenderNode* n = all_nodes_[idx_]; |
1236 | + n->set_y(h_); |
1237 | + ConstraintChange cc = {h_ + n->height(), 0, 0}; |
1238 | if (n->get_floating() == RenderNode::FLOAT_LEFT) { |
1239 | n->set_x(p.left); |
1240 | p.left += n->width(); |
1241 | @@ -402,16 +402,16 @@ |
1242 | cc.delta_w = n->width(); |
1243 | max_line_width = max(max_line_width, w); |
1244 | } |
1245 | - m_constraint_changes.push(cc); |
1246 | + constraint_changes_.push(cc); |
1247 | rv.push_back(n); |
1248 | - ++m_idx; |
1249 | + ++idx_; |
1250 | } |
1251 | - if (m_idx == m_idx_before_iteration) { |
1252 | + if (idx_ == idx_before_iteration_) { |
1253 | throw WidthTooSmall("Could not fit a single render node in line. Width of an Element is too small!"); |
1254 | } |
1255 | } |
1256 | |
1257 | - m_h += p.bottom; |
1258 | + h_ += p.bottom; |
1259 | return max_line_width; |
1260 | } |
1261 | |
1262 | @@ -423,13 +423,13 @@ |
1263 | TextNode(FontCache& font, NodeStyle&, const string& txt); |
1264 | virtual ~TextNode() {} |
1265 | |
1266 | - uint16_t width() override {return m_w;} |
1267 | - uint16_t height() override {return m_h + m_s.spacing;} |
1268 | + uint16_t width() override {return w_;} |
1269 | + uint16_t height() override {return h_ + nodestyle_.spacing;} |
1270 | uint16_t hotspot_y() override; |
1271 | const vector<Reference> get_references() override { |
1272 | vector<Reference> rv; |
1273 | - if (!m_s.reference.empty()) { |
1274 | - Reference r = {Rect(0, 0, m_w, m_h), m_s.reference}; |
1275 | + if (!nodestyle_.reference.empty()) { |
1276 | + Reference r = {Rect(0, 0, w_, h_), nodestyle_.reference}; |
1277 | rv.push_back(r); |
1278 | } |
1279 | return rv; |
1280 | @@ -438,25 +438,25 @@ |
1281 | Texture* render(TextureCache* texture_cache) override; |
1282 | |
1283 | protected: |
1284 | - uint16_t m_w, m_h; |
1285 | - const string m_txt; |
1286 | - NodeStyle m_s; |
1287 | - FontCache& m_fontcache; |
1288 | + uint16_t w_, h_; |
1289 | + const string txt_; |
1290 | + NodeStyle nodestyle_; |
1291 | + FontCache& fontcache_; |
1292 | SdlTtfFont& font_; |
1293 | }; |
1294 | |
1295 | TextNode::TextNode(FontCache& font, NodeStyle& ns, const string& txt) |
1296 | - : RenderNode(ns), m_txt(txt), m_s(ns), m_fontcache(font), |
1297 | - font_(dynamic_cast<SdlTtfFont&>(m_fontcache.get_font(&m_s))) |
1298 | + : RenderNode(ns), txt_(txt), nodestyle_(ns), fontcache_(font), |
1299 | + font_(dynamic_cast<SdlTtfFont&>(fontcache_.get_font(&nodestyle_))) |
1300 | { |
1301 | - font_.dimensions(m_txt, ns.font_style, &m_w, &m_h); |
1302 | + font_.dimensions(txt_, ns.font_style, &w_, &h_); |
1303 | } |
1304 | uint16_t TextNode::hotspot_y() { |
1305 | - return font_.ascent(m_s.font_style); |
1306 | + return font_.ascent(nodestyle_.font_style); |
1307 | } |
1308 | |
1309 | Texture* TextNode::render(TextureCache* texture_cache) { |
1310 | - const Texture& img = font_.render(m_txt, m_s.font_color, m_s.font_style, texture_cache); |
1311 | + const Texture& img = font_.render(txt_, nodestyle_.font_color, nodestyle_.font_style, texture_cache); |
1312 | Texture* rv = new Texture(img.width(), img.height()); |
1313 | rv->blit(Rect(0, 0, img.width(), img.height()), |
1314 | img, |
1315 | @@ -473,23 +473,23 @@ |
1316 | class FillingTextNode : public TextNode { |
1317 | public: |
1318 | FillingTextNode(FontCache& font, NodeStyle& ns, uint16_t w, const string& txt, bool expanding = false) : |
1319 | - TextNode(font, ns, txt), m_expanding(expanding) { |
1320 | - m_w = w; |
1321 | + TextNode(font, ns, txt), is_expanding_(expanding) { |
1322 | + w_ = w; |
1323 | } |
1324 | virtual ~FillingTextNode() {} |
1325 | Texture* render(TextureCache*) override; |
1326 | |
1327 | - bool is_expanding() override {return m_expanding;} |
1328 | - void set_w(uint16_t w) override {m_w = w;} |
1329 | + bool is_expanding() override {return is_expanding_;} |
1330 | + void set_w(uint16_t w) override {w_ = w;} |
1331 | |
1332 | private: |
1333 | - bool m_expanding; |
1334 | + bool is_expanding_; |
1335 | }; |
1336 | Texture* FillingTextNode::render(TextureCache* texture_cache) { |
1337 | - const Texture& t = font_.render(m_txt, m_s.font_color, m_s.font_style, texture_cache); |
1338 | - Texture* rv = new Texture(m_w, m_h); |
1339 | - for (uint16_t curx = 0; curx < m_w; curx += t.width()) { |
1340 | - Rect srcrect(Point(0, 0), min<int>(t.width(), m_w - curx), m_h); |
1341 | + const Texture& t = font_.render(txt_, nodestyle_.font_color, nodestyle_.font_style, texture_cache); |
1342 | + Texture* rv = new Texture(w_, h_); |
1343 | + for (uint16_t curx = 0; curx < w_; curx += t.width()) { |
1344 | + Rect srcrect(Point(0, 0), min<int>(t.width(), w_ - curx), h_); |
1345 | rv->blit(Rect(curx, 0, srcrect.w, srcrect.h), t, srcrect, 1., BlendMode::Copy); |
1346 | } |
1347 | return rv; |
1348 | @@ -502,12 +502,12 @@ |
1349 | class WordSpacerNode : public TextNode { |
1350 | public: |
1351 | WordSpacerNode(FontCache& font, NodeStyle& ns) : TextNode(font, ns, " ") {} |
1352 | - static void show_spaces(bool t) {m_show_spaces = t;} |
1353 | + static void show_spaces(bool t) {show_spaces_ = t;} |
1354 | |
1355 | Texture* render(TextureCache* texture_cache) override { |
1356 | - if (m_show_spaces) { |
1357 | - Texture* rv = new Texture(m_w, m_h); |
1358 | - rv->fill_rect(Rect(0, 0, m_w, m_h), RGBAColor(0xcc, 0, 0, 0xcc)); |
1359 | + if (show_spaces_) { |
1360 | + Texture* rv = new Texture(w_, h_); |
1361 | + rv->fill_rect(Rect(0, 0, w_, h_), RGBAColor(0xcc, 0, 0, 0xcc)); |
1362 | return rv; |
1363 | } |
1364 | return TextNode::render(texture_cache); |
1365 | @@ -515,9 +515,9 @@ |
1366 | bool is_non_mandatory_space() override {return true;} |
1367 | |
1368 | private: |
1369 | - static bool m_show_spaces; |
1370 | + static bool show_spaces_; |
1371 | }; |
1372 | -bool WordSpacerNode::m_show_spaces; |
1373 | +bool WordSpacerNode::show_spaces_; |
1374 | |
1375 | /* |
1376 | * This is a forced newline that can either be inside the text from the user or |
1377 | @@ -541,41 +541,41 @@ |
1378 | class SpaceNode : public RenderNode { |
1379 | public: |
1380 | SpaceNode(NodeStyle& ns, uint16_t w, uint16_t h = 0, bool expanding = false) : |
1381 | - RenderNode(ns), m_w(w), m_h(h), m_bg(nullptr), m_expanding(expanding) {} |
1382 | + RenderNode(ns), w_(w), h_(h), background_image_(nullptr), is_expanding_(expanding) {} |
1383 | |
1384 | - uint16_t height() override {return m_h;} |
1385 | - uint16_t width() override {return m_w;} |
1386 | - uint16_t hotspot_y() override {return m_h;} |
1387 | + uint16_t height() override {return h_;} |
1388 | + uint16_t width() override {return w_;} |
1389 | + uint16_t hotspot_y() override {return h_;} |
1390 | Texture* render(TextureCache* /* texture_cache */) override { |
1391 | - Texture* rv = new Texture(m_w, m_h); |
1392 | + Texture* rv = new Texture(w_, h_); |
1393 | |
1394 | // Draw background image (tiling) |
1395 | - if (m_bg) { |
1396 | + if (background_image_) { |
1397 | Rect dst; |
1398 | Rect srcrect(Point(0, 0), 1, 1); |
1399 | - for (uint16_t curx = 0; curx < m_w; curx += m_bg->width()) { |
1400 | + for (uint16_t curx = 0; curx < w_; curx += background_image_->width()) { |
1401 | dst.x = curx; |
1402 | dst.y = 0; |
1403 | - srcrect.w = dst.w = min<int>(m_bg->width(), m_w - curx); |
1404 | - srcrect.h = dst.h = m_h; |
1405 | - rv->blit(dst, *m_bg, srcrect, 1., BlendMode::Copy); |
1406 | + srcrect.w = dst.w = min<int>(background_image_->width(), w_ - curx); |
1407 | + srcrect.h = dst.h = h_; |
1408 | + rv->blit(dst, *background_image_, srcrect, 1., BlendMode::Copy); |
1409 | } |
1410 | } else { |
1411 | - rv->fill_rect(Rect(0, 0, m_w, m_h), RGBAColor(255, 255, 255, 0)); |
1412 | + rv->fill_rect(Rect(0, 0, w_, h_), RGBAColor(255, 255, 255, 0)); |
1413 | } |
1414 | return rv; |
1415 | } |
1416 | - bool is_expanding() override {return m_expanding;} |
1417 | - void set_w(uint16_t w) override {m_w = w;} |
1418 | + bool is_expanding() override {return is_expanding_;} |
1419 | + void set_w(uint16_t w) override {w_ = w;} |
1420 | |
1421 | void set_background(const Image* s) { |
1422 | - m_bg = s; m_h = s->height(); |
1423 | + background_image_ = s; h_ = s->height(); |
1424 | } |
1425 | |
1426 | private: |
1427 | - uint16_t m_w, m_h; |
1428 | - const Image* m_bg; // not owned |
1429 | - bool m_expanding; |
1430 | + uint16_t w_, h_; |
1431 | + const Image* background_image_; // not owned |
1432 | + bool is_expanding_; |
1433 | }; |
1434 | |
1435 | /* |
1436 | @@ -584,17 +584,17 @@ |
1437 | class SubTagRenderNode : public RenderNode { |
1438 | public: |
1439 | SubTagRenderNode(NodeStyle& ns) : RenderNode(ns), |
1440 | - m_bg_clr(0, 0, 0), m_bg_clr_set(false), m_bg_img(nullptr) { |
1441 | + background_color_(0, 0, 0), is_background_color_set_(false), background_image_(nullptr) { |
1442 | } |
1443 | virtual ~SubTagRenderNode() { |
1444 | - for (RenderNode* n : m_nodes_to_render) { |
1445 | + for (RenderNode* n : nodes_to_render_) { |
1446 | delete n; |
1447 | } |
1448 | - m_nodes_to_render.clear(); |
1449 | + nodes_to_render_.clear(); |
1450 | } |
1451 | |
1452 | - uint16_t width() override {return m_w + m_margin.left + m_margin.right;} |
1453 | - uint16_t height() override {return m_h + m_margin.top + m_margin.bottom;} |
1454 | + uint16_t width() override {return w_ + margin_.left + margin_.right;} |
1455 | + uint16_t height() override {return h_ + margin_.top + margin_.bottom;} |
1456 | uint16_t hotspot_y() override {return height();} |
1457 | |
1458 | Texture* render(TextureCache* texture_cache) override { |
1459 | @@ -603,33 +603,33 @@ |
1460 | |
1461 | // Draw Solid background Color |
1462 | bool set_alpha = true; |
1463 | - if (m_bg_clr_set) { |
1464 | - rv->fill_rect(Rect(Point(m_margin.left, m_margin.top), m_w, m_h), m_bg_clr); |
1465 | + if (is_background_color_set_) { |
1466 | + rv->fill_rect(Rect(Point(margin_.left, margin_.top), w_, h_), background_color_); |
1467 | set_alpha = false; |
1468 | } |
1469 | |
1470 | // Draw background image (tiling) |
1471 | - if (m_bg_img) { |
1472 | + if (background_image_) { |
1473 | Rect dst; |
1474 | Rect src(0, 0, 0, 0); |
1475 | |
1476 | - for (uint16_t cury = m_margin.top; cury < m_h + m_margin.top; cury += m_bg_img->height()) { |
1477 | - for (uint16_t curx = m_margin.left; curx < m_w + m_margin.left; curx += m_bg_img->width()) { |
1478 | + for (uint16_t cury = margin_.top; cury < h_ + margin_.top; cury += background_image_->height()) { |
1479 | + for (uint16_t curx = margin_.left; curx < w_ + margin_.left; curx += background_image_->width()) { |
1480 | dst.x = curx; |
1481 | dst.y = cury; |
1482 | - src.w = dst.w = min<int>(m_bg_img->width(), m_w + m_margin.left - curx); |
1483 | - src.h = dst.h = min<int>(m_bg_img->height(), m_h + m_margin.top - cury); |
1484 | - rv->blit(dst, *m_bg_img, src, 1., BlendMode::Copy); |
1485 | + src.w = dst.w = min<int>(background_image_->width(), w_ + margin_.left - curx); |
1486 | + src.h = dst.h = min<int>(background_image_->height(), h_ + margin_.top - cury); |
1487 | + rv->blit(dst, *background_image_, src, 1., BlendMode::Copy); |
1488 | } |
1489 | } |
1490 | set_alpha = false; |
1491 | } |
1492 | |
1493 | - for (RenderNode* n : m_nodes_to_render) { |
1494 | + for (RenderNode* n : nodes_to_render_) { |
1495 | Texture* node_texture = n->render(texture_cache); |
1496 | if (node_texture) { |
1497 | - Rect dst = Rect(n->x() + m_margin.left, |
1498 | - n->y() + m_margin.top, |
1499 | + Rect dst = Rect(n->x() + margin_.left, |
1500 | + n->y() + margin_.top, |
1501 | node_texture->width(), |
1502 | node_texture->height()); |
1503 | Rect src = Rect(0, 0, node_texture->width(), node_texture->height()); |
1504 | @@ -640,54 +640,54 @@ |
1505 | delete n; |
1506 | } |
1507 | |
1508 | - m_nodes_to_render.clear(); |
1509 | + nodes_to_render_.clear(); |
1510 | |
1511 | return rv; |
1512 | } |
1513 | - const vector<Reference> get_references() override {return m_refs;} |
1514 | + const vector<Reference> get_references() override {return refs_;} |
1515 | void set_dimensions(uint16_t inner_w, uint16_t inner_h, Borders margin) { |
1516 | - m_w = inner_w; m_h = inner_h; m_margin = margin; |
1517 | + w_ = inner_w; h_ = inner_h; margin_ = margin; |
1518 | } |
1519 | void set_background(RGBColor clr) { |
1520 | - m_bg_clr = clr; |
1521 | - m_bg_clr_set = true; |
1522 | + background_color_ = clr; |
1523 | + is_background_color_set_ = true; |
1524 | } |
1525 | - void set_background(const Image* img) {m_bg_img = img;} |
1526 | - void set_nodes_to_render(vector<RenderNode*>& n) {m_nodes_to_render = n;} |
1527 | + void set_background(const Image* img) {background_image_ = img;} |
1528 | + void set_nodes_to_render(vector<RenderNode*>& n) {nodes_to_render_ = n;} |
1529 | void add_reference(int16_t gx, int16_t gy, uint16_t w, uint16_t h, const string& s) { |
1530 | Reference r = {Rect(gx, gy, w, h), s}; |
1531 | - m_refs.push_back(r); |
1532 | + refs_.push_back(r); |
1533 | } |
1534 | |
1535 | private: |
1536 | - uint16_t m_w, m_h; |
1537 | - vector<RenderNode*> m_nodes_to_render; |
1538 | - Borders m_margin; |
1539 | - RGBColor m_bg_clr; |
1540 | - bool m_bg_clr_set; |
1541 | - const Image* m_bg_img; // Not owned. |
1542 | - vector<Reference> m_refs; |
1543 | + uint16_t w_, h_; |
1544 | + vector<RenderNode*> nodes_to_render_; |
1545 | + Borders margin_; |
1546 | + RGBColor background_color_; |
1547 | + bool is_background_color_set_; |
1548 | + const Image* background_image_; // Not owned. |
1549 | + vector<Reference> refs_; |
1550 | }; |
1551 | |
1552 | class ImgRenderNode : public RenderNode { |
1553 | public: |
1554 | - ImgRenderNode(NodeStyle& ns, const Image& image) : RenderNode(ns), m_image(image) { |
1555 | + ImgRenderNode(NodeStyle& ns, const Image& image) : RenderNode(ns), image_(image) { |
1556 | } |
1557 | |
1558 | - uint16_t width() override {return m_image.width();} |
1559 | - uint16_t height() override {return m_image.height();} |
1560 | - uint16_t hotspot_y() override {return m_image.height();} |
1561 | + uint16_t width() override {return image_.width();} |
1562 | + uint16_t height() override {return image_.height();} |
1563 | + uint16_t hotspot_y() override {return image_.height();} |
1564 | Texture* render(TextureCache* texture_cache) override; |
1565 | |
1566 | private: |
1567 | - const Image& m_image; |
1568 | + const Image& image_; |
1569 | }; |
1570 | |
1571 | Texture* ImgRenderNode::render(TextureCache* /* texture_cache */) { |
1572 | - Texture* rv = new Texture(m_image.width(), m_image.height()); |
1573 | - rv->blit(Rect(0, 0, m_image.width(), m_image.height()), |
1574 | - m_image, |
1575 | - Rect(0, 0, m_image.width(), m_image.height()), |
1576 | + Texture* rv = new Texture(image_.width(), image_.height()); |
1577 | + rv->blit(Rect(0, 0, image_.width(), image_.height()), |
1578 | + image_, |
1579 | + Rect(0, 0, image_.width(), image_.height()), |
1580 | 1., |
1581 | BlendMode::Copy); |
1582 | return rv; |
1583 | @@ -702,27 +702,27 @@ |
1584 | class TagHandler { |
1585 | public: |
1586 | TagHandler(Tag& tag, FontCache& fc, NodeStyle ns, ImageCache* image_cache, |
1587 | - RendererStyle& renderer_style_, const UI::FontSets& fontsets) : |
1588 | - m_tag(tag), font_cache_(fc), m_ns(ns), image_cache_(image_cache), |
1589 | - renderer_style(renderer_style_), fontsets_(fontsets) {} |
1590 | + RendererStyle& renderer_style, const UI::FontSets& fontsets) : |
1591 | + tag_(tag), font_cache_(fc), nodestyle_(ns), image_cache_(image_cache), |
1592 | + renderer_style_(renderer_style), fontsets_(fontsets) {} |
1593 | virtual ~TagHandler() {} |
1594 | |
1595 | virtual void enter() {} |
1596 | - virtual void emit(vector<RenderNode*>&); |
1597 | + virtual void emit_nodes(vector<RenderNode*>&); |
1598 | |
1599 | private: |
1600 | - void m_make_text_nodes(const string& txt, vector<RenderNode*>& nodes, NodeStyle& ns); |
1601 | + void make_text_nodes(const string& txt, vector<RenderNode*>& nodes, NodeStyle& ns); |
1602 | |
1603 | protected: |
1604 | - Tag& m_tag; |
1605 | + Tag& tag_; |
1606 | FontCache& font_cache_; |
1607 | - NodeStyle m_ns; |
1608 | + NodeStyle nodestyle_; |
1609 | ImageCache* image_cache_; // Not owned |
1610 | - RendererStyle& renderer_style; // Reference to global renderer style in the renderer |
1611 | + RendererStyle& renderer_style_; // Reference to global renderer style in the renderer |
1612 | const UI::FontSets& fontsets_; |
1613 | }; |
1614 | |
1615 | -void TagHandler::m_make_text_nodes(const string& txt, vector<RenderNode*>& nodes, NodeStyle& ns) { |
1616 | +void TagHandler::make_text_nodes(const string& txt, vector<RenderNode*>& nodes, NodeStyle& ns) { |
1617 | TextStream ts(txt); |
1618 | std::string word; |
1619 | std::vector<RenderNode*> text_nodes; |
1620 | @@ -804,15 +804,15 @@ |
1621 | } |
1622 | } |
1623 | |
1624 | -void TagHandler::emit(vector<RenderNode*>& nodes) { |
1625 | - for (Child* c : m_tag.childs()) { |
1626 | +void TagHandler::emit_nodes(vector<RenderNode*>& nodes) { |
1627 | + for (Child* c : tag_.children()) { |
1628 | if (c->tag) { |
1629 | - std::unique_ptr<TagHandler> th(create_taghandler(*c->tag, font_cache_, m_ns, image_cache_, |
1630 | - renderer_style, fontsets_)); |
1631 | + std::unique_ptr<TagHandler> th(create_taghandler(*c->tag, font_cache_, nodestyle_, image_cache_, |
1632 | + renderer_style_, fontsets_)); |
1633 | th->enter(); |
1634 | - th->emit(nodes); |
1635 | + th->emit_nodes(nodes); |
1636 | } else |
1637 | - m_make_text_nodes(c->text, nodes, m_ns); |
1638 | + make_text_nodes(c->text, nodes, nodestyle_); |
1639 | } |
1640 | } |
1641 | |
1642 | @@ -823,15 +823,15 @@ |
1643 | : TagHandler(tag, fc, ns, image_cache, init_renderer_style, fontsets) {} |
1644 | |
1645 | void enter() override { |
1646 | - const AttrMap& a = m_tag.attrs(); |
1647 | - if (a.has("color")) m_ns.font_color = a["color"].get_color(); |
1648 | - if (a.has("size")) m_ns.font_size = a["size"].get_int(); |
1649 | - if (a.has("face")) m_ns.font_face = a["face"].get_string(); |
1650 | - if (a.has("bold")) m_ns.font_style |= a["bold"].get_bool() ? IFont::BOLD : 0; |
1651 | - if (a.has("italic")) m_ns.font_style |= a["italic"].get_bool() ? IFont::ITALIC : 0; |
1652 | - if (a.has("underline")) m_ns.font_style |= a["underline"].get_bool() ? IFont::UNDERLINE : 0; |
1653 | - if (a.has("shadow")) m_ns.font_style |= a["shadow"].get_bool() ? IFont::SHADOW : 0; |
1654 | - if (a.has("ref")) m_ns.reference = a["ref"].get_string(); |
1655 | + const AttrMap& a = tag_.attrs(); |
1656 | + if (a.has("color")) nodestyle_.font_color = a["color"].get_color(); |
1657 | + if (a.has("size")) nodestyle_.font_size = a["size"].get_int(); |
1658 | + if (a.has("face")) nodestyle_.font_face = a["face"].get_string(); |
1659 | + if (a.has("bold")) nodestyle_.font_style |= a["bold"].get_bool() ? IFont::BOLD : 0; |
1660 | + if (a.has("italic")) nodestyle_.font_style |= a["italic"].get_bool() ? IFont::ITALIC : 0; |
1661 | + if (a.has("underline")) nodestyle_.font_style |= a["underline"].get_bool() ? IFont::UNDERLINE : 0; |
1662 | + if (a.has("shadow")) nodestyle_.font_style |= a["shadow"].get_bool() ? IFont::SHADOW : 0; |
1663 | + if (a.has("ref")) nodestyle_.reference = a["ref"].get_string(); |
1664 | } |
1665 | }; |
1666 | |
1667 | @@ -839,140 +839,142 @@ |
1668 | public: |
1669 | PTagHandler(Tag& tag, FontCache& fc, NodeStyle ns, ImageCache* image_cache, |
1670 | RendererStyle& init_renderer_style, const UI::FontSets& fontsets) |
1671 | - : TagHandler(tag, fc, ns, image_cache, init_renderer_style, fontsets), m_indent(0) { |
1672 | + : TagHandler(tag, fc, ns, image_cache, init_renderer_style, fontsets), indent_(0) { |
1673 | } |
1674 | |
1675 | void enter() override { |
1676 | - const AttrMap& a = m_tag.attrs(); |
1677 | - if (a.has("indent")) m_indent = a["indent"].get_int(); |
1678 | + const AttrMap& a = tag_.attrs(); |
1679 | + if (a.has("indent")) indent_ = a["indent"].get_int(); |
1680 | if (a.has("align")) { |
1681 | const std::string align = a["align"].get_string(); |
1682 | if (align == "right") { |
1683 | - m_ns.halign = UI::Align::kRight; |
1684 | + nodestyle_.halign = UI::Align::kRight; |
1685 | } else if (align == "center" || align == "middle") { |
1686 | - m_ns.halign = UI::Align::kCenter; |
1687 | + nodestyle_.halign = UI::Align::kCenter; |
1688 | } else { |
1689 | - m_ns.halign = UI::Align::kLeft; |
1690 | + nodestyle_.halign = UI::Align::kLeft; |
1691 | } |
1692 | } |
1693 | - m_ns.halign = mirror_alignment(m_ns.halign); |
1694 | + nodestyle_.halign = mirror_alignment(nodestyle_.halign); |
1695 | if (a.has("valign")) { |
1696 | const string align = a["valign"].get_string(); |
1697 | if (align == "bottom") { |
1698 | - m_ns.valign = UI::Align::kBottom; |
1699 | + nodestyle_.valign = UI::Align::kBottom; |
1700 | } else if (align == "center" || align == "middle") { |
1701 | - m_ns.valign = UI::Align::kCenter; |
1702 | + nodestyle_.valign = UI::Align::kCenter; |
1703 | } else { |
1704 | - m_ns.valign = UI::Align::kTop; |
1705 | + nodestyle_.valign = UI::Align::kTop; |
1706 | } |
1707 | } |
1708 | if (a.has("spacing")) |
1709 | - m_ns.spacing = a["spacing"].get_int(); |
1710 | + nodestyle_.spacing = a["spacing"].get_int(); |
1711 | } |
1712 | - void emit(vector<RenderNode*>& nodes) override { |
1713 | + void emit_nodes(vector<RenderNode*>& nodes) override { |
1714 | // Put a newline if this is not the first paragraph |
1715 | if (!nodes.empty()) { |
1716 | - nodes.push_back(new NewlineNode(m_ns)); |
1717 | - } |
1718 | - if (m_indent) { |
1719 | - nodes.push_back(new SpaceNode(m_ns, m_indent)); |
1720 | - } |
1721 | - TagHandler::emit(nodes); |
1722 | + nodes.push_back(new NewlineNode(nodestyle_)); |
1723 | + } |
1724 | + if (indent_) { |
1725 | + nodes.push_back(new SpaceNode(nodestyle_, indent_)); |
1726 | + } |
1727 | + TagHandler::emit_nodes(nodes); |
1728 | } |
1729 | |
1730 | private: |
1731 | - uint16_t m_indent; |
1732 | + uint16_t indent_; |
1733 | }; |
1734 | |
1735 | class ImgTagHandler : public TagHandler { |
1736 | public: |
1737 | ImgTagHandler(Tag& tag, FontCache& fc, NodeStyle ns, ImageCache* image_cache, |
1738 | RendererStyle& init_renderer_style, const UI::FontSets& fontsets) : |
1739 | - TagHandler(tag, fc, ns, image_cache, init_renderer_style, fontsets), m_rn(nullptr) { |
1740 | + TagHandler(tag, fc, ns, image_cache, init_renderer_style, fontsets), render_node_(nullptr) { |
1741 | } |
1742 | |
1743 | void enter() override { |
1744 | - const AttrMap& a = m_tag.attrs(); |
1745 | - m_rn = new ImgRenderNode(m_ns, *image_cache_->get(a["src"].get_string())); |
1746 | + const AttrMap& a = tag_.attrs(); |
1747 | + render_node_ = new ImgRenderNode(nodestyle_, *image_cache_->get(a["src"].get_string())); |
1748 | } |
1749 | - void emit(vector<RenderNode*>& nodes) override { |
1750 | - nodes.push_back(m_rn); |
1751 | + void emit_nodes(vector<RenderNode*>& nodes) override { |
1752 | + nodes.push_back(render_node_); |
1753 | } |
1754 | |
1755 | private: |
1756 | - ImgRenderNode* m_rn; |
1757 | + ImgRenderNode* render_node_; |
1758 | }; |
1759 | |
1760 | class VspaceTagHandler : public TagHandler { |
1761 | public: |
1762 | VspaceTagHandler(Tag& tag, FontCache& fc, NodeStyle ns, ImageCache* image_cache, |
1763 | RendererStyle& init_renderer_style, const UI::FontSets& fontsets) : |
1764 | - TagHandler(tag, fc, ns, image_cache, init_renderer_style, fontsets), m_space(0) {} |
1765 | + TagHandler(tag, fc, ns, image_cache, init_renderer_style, fontsets), space_(0) {} |
1766 | |
1767 | void enter() override { |
1768 | - const AttrMap& a = m_tag.attrs(); |
1769 | + const AttrMap& a = tag_.attrs(); |
1770 | |
1771 | - m_space = a["gap"].get_int(); |
1772 | + space_ = a["gap"].get_int(); |
1773 | } |
1774 | - void emit(vector<RenderNode*>& nodes) override { |
1775 | - nodes.push_back(new SpaceNode(m_ns, 0, m_space)); |
1776 | - nodes.push_back(new NewlineNode(m_ns)); |
1777 | + void emit_nodes(vector<RenderNode*>& nodes) override { |
1778 | + nodes.push_back(new SpaceNode(nodestyle_, 0, space_)); |
1779 | + nodes.push_back(new NewlineNode(nodestyle_)); |
1780 | } |
1781 | |
1782 | private: |
1783 | - uint16_t m_space; |
1784 | + uint16_t space_; |
1785 | }; |
1786 | |
1787 | class HspaceTagHandler : public TagHandler { |
1788 | public: |
1789 | HspaceTagHandler(Tag& tag, FontCache& fc, NodeStyle ns, ImageCache* image_cache, |
1790 | RendererStyle& init_renderer_style, const UI::FontSets& fontsets) : |
1791 | - TagHandler(tag, fc, ns, image_cache, init_renderer_style, fontsets), m_bg(nullptr), m_space(0) {} |
1792 | + TagHandler(tag, fc, ns, image_cache, init_renderer_style, fontsets), |
1793 | + background_image_(nullptr), |
1794 | + space_(0) {} |
1795 | |
1796 | void enter() override { |
1797 | - const AttrMap& a = m_tag.attrs(); |
1798 | + const AttrMap& a = tag_.attrs(); |
1799 | |
1800 | if (a.has("gap")) |
1801 | - m_space = a["gap"].get_int(); |
1802 | + space_ = a["gap"].get_int(); |
1803 | else |
1804 | - m_space = INFINITE_WIDTH; |
1805 | + space_ = INFINITE_WIDTH; |
1806 | |
1807 | if (a.has("fill")) { |
1808 | - m_fill_text = a["fill"].get_string(); |
1809 | + fill_text_ = a["fill"].get_string(); |
1810 | try { |
1811 | - m_bg = image_cache_->get(m_fill_text); |
1812 | - m_fill_text = ""; |
1813 | + background_image_ = image_cache_->get(fill_text_); |
1814 | + fill_text_ = ""; |
1815 | } |
1816 | catch (ImageNotFound&) { |
1817 | } |
1818 | } |
1819 | } |
1820 | |
1821 | - void emit(vector<RenderNode*>& nodes) override { |
1822 | + void emit_nodes(vector<RenderNode*>& nodes) override { |
1823 | RenderNode* rn = nullptr; |
1824 | - if (!m_fill_text.empty()) { |
1825 | - if (m_space < INFINITE_WIDTH) |
1826 | - rn = new FillingTextNode(font_cache_, m_ns, m_space, m_fill_text); |
1827 | + if (!fill_text_.empty()) { |
1828 | + if (space_ < INFINITE_WIDTH) |
1829 | + rn = new FillingTextNode(font_cache_, nodestyle_, space_, fill_text_); |
1830 | else |
1831 | - rn = new FillingTextNode(font_cache_, m_ns, 0, m_fill_text, true); |
1832 | + rn = new FillingTextNode(font_cache_, nodestyle_, 0, fill_text_, true); |
1833 | } else { |
1834 | SpaceNode* sn; |
1835 | - if (m_space < INFINITE_WIDTH) |
1836 | - sn = new SpaceNode(m_ns, m_space, 0); |
1837 | + if (space_ < INFINITE_WIDTH) |
1838 | + sn = new SpaceNode(nodestyle_, space_, 0); |
1839 | else |
1840 | - sn = new SpaceNode(m_ns, 0, 0, true); |
1841 | + sn = new SpaceNode(nodestyle_, 0, 0, true); |
1842 | |
1843 | - if (m_bg) |
1844 | - sn->set_background(m_bg); |
1845 | + if (background_image_) |
1846 | + sn->set_background(background_image_); |
1847 | rn = sn; |
1848 | } |
1849 | nodes.push_back(rn); |
1850 | } |
1851 | |
1852 | private: |
1853 | - string m_fill_text; |
1854 | - const Image* m_bg; |
1855 | - uint16_t m_space; |
1856 | + string fill_text_; |
1857 | + const Image* background_image_; |
1858 | + uint16_t space_; |
1859 | }; |
1860 | |
1861 | class BrTagHandler : public TagHandler { |
1862 | @@ -982,8 +984,8 @@ |
1863 | TagHandler(tag, fc, ns, image_cache, init_renderer_style, fontsets) { |
1864 | } |
1865 | |
1866 | - void emit(vector<RenderNode*>& nodes) override { |
1867 | - nodes.push_back(new NewlineNode(m_ns)); |
1868 | + void emit_nodes(vector<RenderNode*>& nodes) override { |
1869 | + nodes.push_back(new NewlineNode(nodestyle_)); |
1870 | } |
1871 | }; |
1872 | |
1873 | @@ -997,8 +999,8 @@ |
1874 | : |
1875 | TagHandler(tag, fc, ns, image_cache, init_renderer_style, fontsets), |
1876 | shrink_to_fit_(shrink_to_fit), |
1877 | - m_w(max_w), |
1878 | - m_rn(new SubTagRenderNode(ns)) |
1879 | + w_(max_w), |
1880 | + render_node_(new SubTagRenderNode(ns)) |
1881 | { |
1882 | } |
1883 | |
1884 | @@ -1006,14 +1008,14 @@ |
1885 | Borders padding, margin; |
1886 | |
1887 | handle_unique_attributes(); |
1888 | - const AttrMap& a = m_tag.attrs(); |
1889 | + const AttrMap& a = tag_.attrs(); |
1890 | if (a.has("background")) { |
1891 | RGBColor clr; |
1892 | try { |
1893 | clr = a["background"].get_color(); |
1894 | - m_rn->set_background(clr); |
1895 | + render_node_->set_background(clr); |
1896 | } catch (InvalidColor&) { |
1897 | - m_rn->set_background(image_cache_->get(a["background"].get_string())); |
1898 | + render_node_->set_background(image_cache_->get(a["background"].get_string())); |
1899 | } |
1900 | } |
1901 | if (a.has("padding")) { |
1902 | @@ -1030,89 +1032,89 @@ |
1903 | } |
1904 | |
1905 | vector<RenderNode*> subnodes; |
1906 | - TagHandler::emit(subnodes); |
1907 | + TagHandler::emit_nodes(subnodes); |
1908 | |
1909 | - if (! m_w) { // Determine the width by the width of the widest subnode |
1910 | + if (! w_) { // Determine the width by the width of the widest subnode |
1911 | for (RenderNode* n : subnodes) { |
1912 | if (n->width() >= INFINITE_WIDTH) |
1913 | continue; |
1914 | - m_w = max<int>(m_w, n->width() + padding.left + padding.right); |
1915 | + w_ = max<int>(w_, n->width() + padding.left + padding.right); |
1916 | } |
1917 | } |
1918 | |
1919 | // Layout takes ownership of subnodes |
1920 | Layout layout(subnodes); |
1921 | vector<RenderNode*> nodes_to_render; |
1922 | - uint16_t max_line_width = layout.fit_nodes(nodes_to_render, m_w, padding, shrink_to_fit_); |
1923 | - uint16_t m_extra_width = 0; |
1924 | - if (m_w < INFINITE_WIDTH && m_w > max_line_width) { |
1925 | - m_extra_width = m_w - max_line_width; |
1926 | + uint16_t max_line_width = layout.fit_nodes(nodes_to_render, w_, padding, shrink_to_fit_); |
1927 | + uint16_t extra_width = 0; |
1928 | + if (w_ < INFINITE_WIDTH && w_ > max_line_width) { |
1929 | + extra_width = w_ - max_line_width; |
1930 | } |
1931 | |
1932 | // Collect all tags from children |
1933 | for (RenderNode* rn : nodes_to_render) { |
1934 | for (const Reference& r : rn->get_references()) { |
1935 | - m_rn->add_reference(rn->x() + r.dim.x, rn->y() + r.dim.y, r.dim.w, r.dim.h, r.ref); |
1936 | + render_node_->add_reference(rn->x() + r.dim.x, rn->y() + r.dim.y, r.dim.w, r.dim.h, r.ref); |
1937 | } |
1938 | if (shrink_to_fit_) { |
1939 | if (rn->halign() == UI::Align::kCenter) { |
1940 | - rn->set_x(rn->x() - m_extra_width / 2); |
1941 | + rn->set_x(rn->x() - extra_width / 2); |
1942 | } else if (rn->halign() == UI::Align::kRight) { |
1943 | - rn->set_x(rn->x() - m_extra_width); |
1944 | + rn->set_x(rn->x() - extra_width); |
1945 | } |
1946 | } |
1947 | } |
1948 | - if (shrink_to_fit_ || m_w >= INFINITE_WIDTH) { |
1949 | - m_w = max_line_width; |
1950 | + if (shrink_to_fit_ || w_ >= INFINITE_WIDTH) { |
1951 | + w_ = max_line_width; |
1952 | } |
1953 | |
1954 | - if (renderer_style.remaining_width >= m_w) { |
1955 | - renderer_style.remaining_width -= m_w; |
1956 | + if (renderer_style_.remaining_width >= w_) { |
1957 | + renderer_style_.remaining_width -= w_; |
1958 | } else { |
1959 | - renderer_style.remaining_width = renderer_style.overall_width; |
1960 | + renderer_style_.remaining_width = renderer_style_.overall_width; |
1961 | } |
1962 | |
1963 | - m_rn->set_dimensions(m_w, layout.height(), margin); |
1964 | - m_rn->set_nodes_to_render(nodes_to_render); |
1965 | + render_node_->set_dimensions(w_, layout.height(), margin); |
1966 | + render_node_->set_nodes_to_render(nodes_to_render); |
1967 | } |
1968 | - void emit(vector<RenderNode*>& nodes) override { |
1969 | - nodes.push_back(m_rn); |
1970 | + void emit_nodes(vector<RenderNode*>& nodes) override { |
1971 | + nodes.push_back(render_node_); |
1972 | } |
1973 | |
1974 | // Handle attributes that are in sub, but not in rt. |
1975 | virtual void handle_unique_attributes() { |
1976 | - const AttrMap& a = m_tag.attrs(); |
1977 | + const AttrMap& a = tag_.attrs(); |
1978 | if (a.has("width")) { |
1979 | std::string width_string = a["width"].get_string(); |
1980 | if (width_string == "*") { |
1981 | - m_w = renderer_style.remaining_width; |
1982 | + w_ = renderer_style_.remaining_width; |
1983 | } else if (boost::algorithm::ends_with(width_string, "%")) { |
1984 | width_string = width_string.substr(0, width_string.length() - 1); |
1985 | uint8_t new_width_percent = strtol(width_string.c_str(), nullptr, 10); |
1986 | - m_w = floor(renderer_style.overall_width * new_width_percent / 100); |
1987 | - m_w = std::min(m_w, renderer_style.remaining_width); |
1988 | + w_ = floor(renderer_style_.overall_width * new_width_percent / 100); |
1989 | + w_ = std::min(w_, renderer_style_.remaining_width); |
1990 | } else { |
1991 | - m_w = a["width"].get_int(); |
1992 | + w_ = a["width"].get_int(); |
1993 | } |
1994 | shrink_to_fit_ = false; |
1995 | } |
1996 | if (a.has("float")) { |
1997 | const string s = a["float"].get_string(); |
1998 | - if (s == "right") m_rn->set_floating(RenderNode::FLOAT_RIGHT); |
1999 | - else if (s == "left") m_rn->set_floating(RenderNode::FLOAT_LEFT); |
2000 | + if (s == "right") render_node_->set_floating(RenderNode::FLOAT_RIGHT); |
2001 | + else if (s == "left") render_node_->set_floating(RenderNode::FLOAT_LEFT); |
2002 | } |
2003 | if (a.has("valign")) { |
2004 | const string align = a["valign"].get_string(); |
2005 | - if (align == "top") m_rn->set_valign(UI::Align::kTop); |
2006 | - else if (align == "bottom") m_rn->set_valign(UI::Align::kBottom); |
2007 | - else if (align == "center" || align == "middle") m_rn->set_valign(UI::Align::kCenter); |
2008 | + if (align == "top") render_node_->set_valign(UI::Align::kTop); |
2009 | + else if (align == "bottom") render_node_->set_valign(UI::Align::kBottom); |
2010 | + else if (align == "center" || align == "middle") render_node_->set_valign(UI::Align::kCenter); |
2011 | } |
2012 | } |
2013 | protected: |
2014 | bool shrink_to_fit_; |
2015 | private: |
2016 | - uint16_t m_w; |
2017 | - SubTagRenderNode* m_rn; |
2018 | + uint16_t w_; |
2019 | + SubTagRenderNode* render_node_; |
2020 | }; |
2021 | |
2022 | class RTTagHandler : public SubTagHandler { |
2023 | @@ -1124,7 +1126,7 @@ |
2024 | |
2025 | // Handle attributes that are in rt, but not in sub. |
2026 | void handle_unique_attributes() override { |
2027 | - const AttrMap& a = m_tag.attrs(); |
2028 | + const AttrMap& a = tag_.attrs(); |
2029 | WordSpacerNode::show_spaces(a.has("db_show_spaces") ? a["db_show_spaces"].get_bool() : 0); |
2030 | shrink_to_fit_ = shrink_to_fit_ && (a.has("keep_spaces") ? !a["keep_spaces"].get_bool() : true); |
2031 | } |
2032 | @@ -1193,7 +1195,7 @@ |
2033 | RTTagHandler rtrn(*rt, *font_cache_, default_style, image_cache_, renderer_style_, fontsets_, width); |
2034 | vector<RenderNode*> nodes; |
2035 | rtrn.enter(); |
2036 | - rtrn.emit(nodes); |
2037 | + rtrn.emit_nodes(nodes); |
2038 | |
2039 | assert(nodes.size() == 1); |
2040 | assert(nodes[0]); |
2041 | |
2042 | === modified file 'src/graphic/text/sdl_ttf_font.cc' |
2043 | --- src/graphic/text/sdl_ttf_font.cc 2016-03-10 16:20:19 +0000 |
2044 | +++ src/graphic/text/sdl_ttf_font.cc 2016-03-17 17:18:59 +0000 |
2045 | @@ -44,7 +44,7 @@ |
2046 | } |
2047 | |
2048 | void SdlTtfFont::dimensions(const std::string& txt, int style, uint16_t * gw, uint16_t * gh) { |
2049 | - m_set_style(style); |
2050 | + set_style(style); |
2051 | |
2052 | int w, h; |
2053 | TTF_SizeUTF8(font_, txt.c_str(), &w, &h); |
2054 | @@ -64,7 +64,7 @@ |
2055 | const Texture* rv = texture_cache->get(hash); |
2056 | if (rv) return *rv; |
2057 | |
2058 | - m_set_style(style); |
2059 | + set_style(style); |
2060 | |
2061 | SDL_Surface * text_surface = nullptr; |
2062 | |
2063 | @@ -127,7 +127,7 @@ |
2064 | return rv; |
2065 | } |
2066 | |
2067 | -void SdlTtfFont::m_set_style(int style) { |
2068 | +void SdlTtfFont::set_style(int style) { |
2069 | int sdl_style = TTF_STYLE_NORMAL; |
2070 | if (style & UNDERLINE) sdl_style |= TTF_STYLE_UNDERLINE; |
2071 | |
2072 | |
2073 | === modified file 'src/graphic/text/sdl_ttf_font.h' |
2074 | --- src/graphic/text/sdl_ttf_font.h 2016-02-14 11:39:28 +0000 |
2075 | +++ src/graphic/text/sdl_ttf_font.h 2016-03-17 17:18:59 +0000 |
2076 | @@ -67,7 +67,7 @@ |
2077 | uint16_t ascent(int) const override; |
2078 | |
2079 | private: |
2080 | - void m_set_style(int); |
2081 | + void set_style(int); |
2082 | |
2083 | TTF_Font * font_; |
2084 | int style_; |
2085 | |
2086 | === modified file 'src/graphic/text/textstream.cc' |
2087 | --- src/graphic/text/textstream.cc 2016-02-21 12:06:39 +0000 |
2088 | +++ src/graphic/text/textstream.cc 2016-03-17 17:18:59 +0000 |
2089 | @@ -35,14 +35,14 @@ |
2090 | {} |
2091 | }; |
2092 | |
2093 | -void TextStream::m_consume(size_t cnt) { |
2094 | +void TextStream::consume(size_t cnt) { |
2095 | while (cnt) { |
2096 | - if (m_t[m_i] == '\n') { |
2097 | - ++m_lineno; |
2098 | - m_col = 0; |
2099 | + if (text_[pos_] == '\n') { |
2100 | + ++line_; |
2101 | + col_ = 0; |
2102 | } else |
2103 | - ++m_col; |
2104 | - ++m_i; |
2105 | + ++col_; |
2106 | + ++pos_; |
2107 | --cnt; |
2108 | } |
2109 | } |
2110 | @@ -54,19 +54,19 @@ |
2111 | * r* means skip_ws starting from the back of the string |
2112 | */ |
2113 | void TextStream::skip_ws() { |
2114 | - while (m_i < m_end && isspace(m_t[m_i])) |
2115 | - m_consume(1); |
2116 | + while (pos_ < end_ && isspace(text_[pos_])) |
2117 | + consume(1); |
2118 | } |
2119 | void TextStream::rskip_ws() { |
2120 | - while (m_i < m_end && isspace(m_t[m_end - 1])) |
2121 | - --m_end; |
2122 | + while (pos_ < end_ && isspace(text_[end_ - 1])) |
2123 | + --end_; |
2124 | } |
2125 | |
2126 | /* |
2127 | * Return the next few characters without advancing the stream |
2128 | */ |
2129 | string TextStream::peek(size_t n, size_t at) const { |
2130 | - return m_t.substr(at > m_t.size() ? m_i : at, n); |
2131 | + return text_.substr(at > text_.size() ? pos_ : at, n); |
2132 | } |
2133 | |
2134 | /* |
2135 | @@ -78,8 +78,8 @@ |
2136 | skip_ws(); |
2137 | |
2138 | if (peek(n.size()) != n) |
2139 | - throw SyntaxErrorImpl(m_lineno, m_col, (format("'%s'") % n).str(), peek(n.size()), peek(100)); |
2140 | - m_consume(n.size()); |
2141 | + throw SyntaxErrorImpl(line_, col_, (format("'%s'") % n).str(), peek(n.size()), peek(100)); |
2142 | + consume(n.size()); |
2143 | } |
2144 | |
2145 | /* |
2146 | @@ -91,12 +91,12 @@ |
2147 | // Sticking with a double loop because chars will likely be short |
2148 | string rv; |
2149 | |
2150 | - size_t j = m_i; |
2151 | - size_t started_at = m_i; |
2152 | + size_t j = pos_; |
2153 | + size_t started_at = pos_; |
2154 | bool found = false; |
2155 | - while (j < m_end) { |
2156 | + while (j < end_) { |
2157 | for (size_t k = 0; k < chars.size(); ++k) { |
2158 | - if (chars[k] == m_t[j]) { |
2159 | + if (chars[k] == text_[j]) { |
2160 | found = true; |
2161 | break; |
2162 | } |
2163 | @@ -105,7 +105,7 @@ |
2164 | |
2165 | // Get rid of control characters |
2166 | // http://en.cppreference.com/w/cpp/language/escape |
2167 | - switch (m_t[j]) { |
2168 | + switch (text_[j]) { |
2169 | case '\a': |
2170 | case '\b': |
2171 | case '\f': |
2172 | @@ -116,12 +116,12 @@ |
2173 | break; |
2174 | } |
2175 | |
2176 | - rv += m_t[j]; |
2177 | + rv += text_[j]; |
2178 | ++j; |
2179 | } |
2180 | if (!found) |
2181 | throw EndOfTextImpl(started_at, peek(100, started_at)); |
2182 | - m_consume(j - started_at); |
2183 | + consume(j - started_at); |
2184 | |
2185 | // Undo the extra \ that were inserted in Parser::parse to prevent crashes. |
2186 | boost::replace_all(rv, "\\\\", "\\"); |
2187 | @@ -137,8 +137,8 @@ |
2188 | try { |
2189 | rv = till_any(chars); |
2190 | } catch (EndOfTextImpl &) { |
2191 | - rv = m_t.substr(m_i, m_end - m_i); |
2192 | - m_consume(m_end + 1 - m_i); |
2193 | + rv = text_.substr(pos_, end_ - pos_); |
2194 | + consume(end_ + 1 - pos_); |
2195 | } |
2196 | return rv; |
2197 | } |
2198 | @@ -149,9 +149,9 @@ |
2199 | string TextStream::parse_string() { |
2200 | string delim = peek(1); |
2201 | if (delim == "'" || delim == "\"") { |
2202 | - m_consume(1); |
2203 | + consume(1); |
2204 | string rv = till_any(delim); |
2205 | - m_consume(1); |
2206 | + consume(1); |
2207 | return rv; |
2208 | } else |
2209 | return till_any(" \t>"); |
2210 | @@ -161,7 +161,7 @@ |
2211 | * Return the text that is yet to be parsed |
2212 | */ |
2213 | string TextStream::remaining_text() { |
2214 | - return m_t.substr(m_i, m_end - m_i); |
2215 | + return text_.substr(pos_, end_ - pos_); |
2216 | } |
2217 | |
2218 | } |
2219 | |
2220 | === modified file 'src/graphic/text/textstream.h' |
2221 | --- src/graphic/text/textstream.h 2014-07-05 16:41:51 +0000 |
2222 | +++ src/graphic/text/textstream.h 2016-03-17 17:18:59 +0000 |
2223 | @@ -28,11 +28,11 @@ |
2224 | |
2225 | class TextStream { |
2226 | public: |
2227 | - TextStream(std::string text) : m_t(text), m_lineno(1), m_col(0), m_i(0), m_end(text.size()) {} |
2228 | + TextStream(std::string text) : text_(text), line_(1), col_(0), pos_(0), end_(text.size()) {} |
2229 | |
2230 | - size_t line() const {return m_lineno;} |
2231 | - size_t col() const {return m_col;} |
2232 | - size_t pos() const {return m_i;} |
2233 | + size_t line() const {return line_;} |
2234 | + size_t col() const {return col_;} |
2235 | + size_t pos() const {return pos_;} |
2236 | |
2237 | std::string peek(size_t, size_t = -1) const; |
2238 | void expect(std::string, bool = true); |
2239 | @@ -41,17 +41,17 @@ |
2240 | std::string till_any_or_end(std::string); |
2241 | std::string parse_string(); |
2242 | |
2243 | - void skip(size_t d) {m_i += d;} |
2244 | + void skip(size_t d) {pos_ += d;} |
2245 | void skip_ws(); |
2246 | void rskip_ws(); |
2247 | |
2248 | std::string remaining_text(); |
2249 | |
2250 | private: |
2251 | - void m_consume(size_t); |
2252 | - std::string m_t; |
2253 | - uint32_t m_lineno, m_col; |
2254 | - size_t m_i, m_end; |
2255 | + void consume(size_t); |
2256 | + std::string text_; |
2257 | + uint32_t line_, col_; |
2258 | + size_t pos_, end_; |
2259 | }; |
2260 | |
2261 | } |
2262 | |
2263 | === modified file 'src/graphic/text_layout.cc' |
2264 | --- src/graphic/text_layout.cc 2016-03-09 07:15:44 +0000 |
2265 | +++ src/graphic/text_layout.cc 2016-03-17 17:18:59 +0000 |
2266 | @@ -210,8 +210,8 @@ |
2267 | */ |
2268 | void TextStyle::calc_bare_height_heuristic(const std::string & text, int32_t & miny, int32_t & maxy) const |
2269 | { |
2270 | - miny = font->m_computed_typical_miny; |
2271 | - maxy = font->m_computed_typical_maxy; |
2272 | + miny = font->computed_typical_miny_; |
2273 | + maxy = font->computed_typical_maxy_; |
2274 | |
2275 | setup(); |
2276 | std::string::size_type pos = 0; |
2277 | |
2278 | === modified file 'src/graphic/text_parser.cc' |
2279 | --- src/graphic/text_parser.cc 2016-03-10 15:00:32 +0000 |
2280 | +++ src/graphic/text_parser.cc 2016-03-17 17:18:59 +0000 |
2281 | @@ -33,29 +33,29 @@ |
2282 | namespace UI { |
2283 | |
2284 | RichtextBlock::RichtextBlock() : |
2285 | - m_image_align(UI::Align::kLeft), |
2286 | - m_text_align (UI::Align::kLeft) |
2287 | + image_align_(UI::Align::kLeft), |
2288 | + text_align_ (UI::Align::kLeft) |
2289 | {} |
2290 | |
2291 | RichtextBlock::RichtextBlock(const RichtextBlock & src) { |
2292 | - m_images.clear(); |
2293 | - m_text_blocks.clear(); |
2294 | - for (uint32_t i = 0; i < src.m_images.size(); ++i) |
2295 | - m_images.push_back(src.m_images[i]); |
2296 | - for (uint32_t i = 0; i < src.m_text_blocks.size(); ++i) |
2297 | - m_text_blocks.push_back(src.m_text_blocks[i]); |
2298 | - m_image_align = src.m_image_align; |
2299 | - m_text_align = src.m_text_align; |
2300 | + images_.clear(); |
2301 | + text_blocks_.clear(); |
2302 | + for (uint32_t i = 0; i < src.images_.size(); ++i) |
2303 | + images_.push_back(src.images_[i]); |
2304 | + for (uint32_t i = 0; i < src.text_blocks_.size(); ++i) |
2305 | + text_blocks_.push_back(src.text_blocks_[i]); |
2306 | + image_align_ = src.image_align_; |
2307 | + text_align_ = src.text_align_; |
2308 | } |
2309 | |
2310 | TextBlock::TextBlock() { |
2311 | - m_font_size = 10; |
2312 | - m_font_color = RGBColor(255, 255, 0); |
2313 | - m_font_weight = "normal"; |
2314 | - m_font_style = "normal"; |
2315 | - m_font_decoration = "none"; |
2316 | - m_font_face = (UI::g_fh1->fontset())->sans(); |
2317 | - m_line_spacing = 0; |
2318 | + font_size_ = 10; |
2319 | + font_color_ = RGBColor(255, 255, 0); |
2320 | + font_weight_ = "normal"; |
2321 | + font_style_ = "normal"; |
2322 | + font_decoration_ = "none"; |
2323 | + font_face_ = (UI::g_fh1->fontset())->sans(); |
2324 | + line_spacing_ = 0; |
2325 | } |
2326 | |
2327 | void TextParser::parse |
2328 | |
2329 | === modified file 'src/graphic/text_parser.h' |
2330 | --- src/graphic/text_parser.h 2014-09-10 14:48:40 +0000 |
2331 | +++ src/graphic/text_parser.h 2016-03-17 17:18:59 +0000 |
2332 | @@ -37,68 +37,68 @@ |
2333 | TextBlock(); |
2334 | // Copy and assignement operators are autogenerated. |
2335 | |
2336 | - void set_font_size(int32_t const font_size) {m_font_size = font_size;} |
2337 | - int32_t get_font_size() const {return m_font_size;} |
2338 | + void set_font_size(int32_t const font_size) {font_size_ = font_size;} |
2339 | + int32_t get_font_size() const {return font_size_;} |
2340 | |
2341 | - void set_font_color(const RGBColor & font_color) {m_font_color = font_color;} |
2342 | - RGBColor get_font_color() const {return m_font_color;} |
2343 | + void set_font_color(const RGBColor & font_color) {font_color_ = font_color;} |
2344 | + RGBColor get_font_color() const {return font_color_;} |
2345 | |
2346 | void set_font_weight(const std::string & font_weight) { |
2347 | - m_font_weight = font_weight; |
2348 | + font_weight_ = font_weight; |
2349 | } |
2350 | - const std::string & get_font_weight() const {return m_font_weight;} |
2351 | + const std::string & get_font_weight() const {return font_weight_;} |
2352 | |
2353 | void set_font_style(const std::string & font_style) { |
2354 | - m_font_style = font_style; |
2355 | + font_style_ = font_style; |
2356 | } |
2357 | - const std::string & get_font_style() const {return m_font_style;} |
2358 | + const std::string & get_font_style() const {return font_style_;} |
2359 | |
2360 | void set_font_decoration(const std::string & font_decoration) { |
2361 | - m_font_decoration = font_decoration; |
2362 | + font_decoration_ = font_decoration; |
2363 | } |
2364 | - const std::string & get_font_decoration() const {return m_font_decoration;} |
2365 | + const std::string & get_font_decoration() const {return font_decoration_;} |
2366 | |
2367 | - void set_font_face(const std::string & font_face) {m_font_face = font_face;} |
2368 | - const std::string & get_font_face() const {return m_font_face;} |
2369 | + void set_font_face(const std::string & font_face) {font_face_ = font_face;} |
2370 | + const std::string & get_font_face() const {return font_face_;} |
2371 | |
2372 | void set_line_spacing(int32_t const line_spacing) { |
2373 | - m_line_spacing = line_spacing; |
2374 | + line_spacing_ = line_spacing; |
2375 | } |
2376 | - int32_t get_line_spacing() const {return m_line_spacing;} |
2377 | + int32_t get_line_spacing() const {return line_spacing_;} |
2378 | |
2379 | - void set_words(const std::vector<std::string> & words) {m_words = words;} |
2380 | - const std::vector<std::string> & get_words() const {return m_words;} |
2381 | + void set_words(const std::vector<std::string> & words) {words_ = words;} |
2382 | + const std::vector<std::string> & get_words() const {return words_;} |
2383 | |
2384 | void set_line_breaks |
2385 | (const std::vector<std::vector<std::string>::size_type> & line_breaks) |
2386 | { |
2387 | - m_line_breaks = line_breaks; |
2388 | + line_breaks_ = line_breaks; |
2389 | } |
2390 | const std::vector<std::vector<std::string>::size_type> & get_line_breaks |
2391 | () const |
2392 | { |
2393 | - return m_line_breaks; |
2394 | + return line_breaks_; |
2395 | } |
2396 | private: |
2397 | - int32_t m_font_size; |
2398 | - RGBColor m_font_color; |
2399 | - std::string m_font_weight; |
2400 | - std::string m_font_style; |
2401 | - std::string m_font_decoration; |
2402 | - std::string m_font_face; |
2403 | - int32_t m_line_spacing; |
2404 | - std::vector<std::string> m_words; |
2405 | + int32_t font_size_; |
2406 | + RGBColor font_color_; |
2407 | + std::string font_weight_; |
2408 | + std::string font_style_; |
2409 | + std::string font_decoration_; |
2410 | + std::string font_face_; |
2411 | + int32_t line_spacing_; |
2412 | + std::vector<std::string> words_; |
2413 | |
2414 | /** |
2415 | - * Position of manual line breaks (<br>) with respect to @ref m_words. |
2416 | + * Position of manual line breaks (<br>) with respect to @ref words_. |
2417 | * Sorted in ascending order. |
2418 | * An entry j in this vector means that a manual line break occurs |
2419 | - * before the j-th word in @ref m_words. In particular, an entry 0 |
2420 | + * before the j-th word in @ref words_. In particular, an entry 0 |
2421 | * means that a manual line break occurs before the first word. |
2422 | * Entries can appear with multiplicity, indicating that multiple |
2423 | * manual line breaks exist without any words in-between. |
2424 | */ |
2425 | - std::vector<std::vector<std::string>::size_type> m_line_breaks; |
2426 | + std::vector<std::vector<std::string>::size_type> line_breaks_; |
2427 | }; |
2428 | |
2429 | struct RichtextBlock { |
2430 | @@ -106,27 +106,27 @@ |
2431 | RichtextBlock(const RichtextBlock & src); |
2432 | |
2433 | void set_images(const std::vector<std::string> & images) { |
2434 | - m_images = images; |
2435 | + images_ = images; |
2436 | } |
2437 | - const std::vector<std::string> & get_images() const {return m_images;} |
2438 | - |
2439 | - void set_image_align(Align const image_align) {m_image_align = image_align;} |
2440 | - Align get_image_align() const {return m_image_align;} |
2441 | - |
2442 | - void set_text_align(Align const text_align) {m_text_align = text_align;} |
2443 | - Align get_text_align() const {return m_text_align;} |
2444 | + const std::vector<std::string> & get_images() const {return images_;} |
2445 | + |
2446 | + void set_image_align(Align const image_align) {image_align_ = image_align;} |
2447 | + Align get_image_align() const {return image_align_;} |
2448 | + |
2449 | + void set_text_align(Align const text_align) {text_align_ = text_align;} |
2450 | + Align get_text_align() const {return text_align_;} |
2451 | |
2452 | void set_text_blocks(const std::vector<TextBlock> & text_blocks) { |
2453 | - m_text_blocks = text_blocks; |
2454 | + text_blocks_ = text_blocks; |
2455 | } |
2456 | const std::vector<TextBlock> & get_text_blocks() const { |
2457 | - return m_text_blocks; |
2458 | + return text_blocks_; |
2459 | } |
2460 | private: |
2461 | - std::vector<std::string> m_images; |
2462 | - std::vector<TextBlock> m_text_blocks; |
2463 | - Align m_image_align; |
2464 | - Align m_text_align; |
2465 | + std::vector<std::string> images_; |
2466 | + std::vector<TextBlock> text_blocks_; |
2467 | + Align image_align_; |
2468 | + Align text_align_; |
2469 | }; |
2470 | |
2471 | struct TextParser { |
2472 | |
2473 | === modified file 'src/graphic/texture.cc' |
2474 | --- src/graphic/texture.cc 2016-02-02 09:24:10 +0000 |
2475 | +++ src/graphic/texture.cc 2016-03-17 17:18:59 +0000 |
2476 | @@ -103,7 +103,7 @@ |
2477 | { |
2478 | init(w, h); |
2479 | |
2480 | - if (m_blit_data.texture_id == 0) { |
2481 | + if (blit_data_.texture_id == 0) { |
2482 | return; |
2483 | } |
2484 | |
2485 | @@ -156,9 +156,9 @@ |
2486 | throw wexception("Created a sub Texture with zero height and width parent."); |
2487 | } |
2488 | |
2489 | - m_owns_texture = false; |
2490 | + owns_texture_ = false; |
2491 | |
2492 | - m_blit_data = BlitData { |
2493 | + blit_data_ = BlitData { |
2494 | texture, |
2495 | parent_w, parent_h, |
2496 | subrect, |
2497 | @@ -167,23 +167,23 @@ |
2498 | |
2499 | Texture::~Texture() |
2500 | { |
2501 | - if (m_owns_texture) { |
2502 | - Gl::State::instance().unbind_texture_if_bound(m_blit_data.texture_id); |
2503 | - glDeleteTextures(1, &m_blit_data.texture_id); |
2504 | + if (owns_texture_) { |
2505 | + Gl::State::instance().unbind_texture_if_bound(blit_data_.texture_id); |
2506 | + glDeleteTextures(1, &blit_data_.texture_id); |
2507 | } |
2508 | } |
2509 | |
2510 | int Texture::width() const { |
2511 | - return m_blit_data.rect.w; |
2512 | + return blit_data_.rect.w; |
2513 | } |
2514 | |
2515 | int Texture::height() const { |
2516 | - return m_blit_data.rect.h; |
2517 | + return blit_data_.rect.h; |
2518 | } |
2519 | |
2520 | void Texture::init(uint16_t w, uint16_t h) |
2521 | { |
2522 | - m_blit_data = { |
2523 | + blit_data_ = { |
2524 | 0, // initialized below |
2525 | w, h, |
2526 | Rect(0, 0, w, h), |
2527 | @@ -192,9 +192,9 @@ |
2528 | return; |
2529 | } |
2530 | |
2531 | - m_owns_texture = true; |
2532 | - glGenTextures(1, &m_blit_data.texture_id); |
2533 | - Gl::State::instance().bind(GL_TEXTURE0, m_blit_data.texture_id); |
2534 | + owns_texture_ = true; |
2535 | + glGenTextures(1, &blit_data_.texture_id); |
2536 | + Gl::State::instance().bind(GL_TEXTURE0, blit_data_.texture_id); |
2537 | |
2538 | // set texture filter to use linear filtering. This looks nicer for resized |
2539 | // texture. Most textures and images are not resized so the filtering |
2540 | @@ -204,46 +204,46 @@ |
2541 | } |
2542 | |
2543 | void Texture::lock() { |
2544 | - if (m_blit_data.texture_id == 0) { |
2545 | + if (blit_data_.texture_id == 0) { |
2546 | return; |
2547 | } |
2548 | |
2549 | - if (m_pixels) { |
2550 | + if (pixels_) { |
2551 | throw wexception("Called lock() on locked surface."); |
2552 | } |
2553 | - if (!m_owns_texture) { |
2554 | + if (!owns_texture_) { |
2555 | throw wexception("A surface that does not own its pixels can not be locked.."); |
2556 | } |
2557 | |
2558 | - m_pixels.reset(new uint8_t[width() * height() * 4]); |
2559 | + pixels_.reset(new uint8_t[width() * height() * 4]); |
2560 | |
2561 | - Gl::State::instance().bind(GL_TEXTURE0, m_blit_data.texture_id); |
2562 | - glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, m_pixels.get()); |
2563 | + Gl::State::instance().bind(GL_TEXTURE0, blit_data_.texture_id); |
2564 | + glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels_.get()); |
2565 | } |
2566 | |
2567 | void Texture::unlock(UnlockMode mode) { |
2568 | if (width() <= 0 || height() <= 0) { |
2569 | return; |
2570 | } |
2571 | - assert(m_pixels); |
2572 | + assert(pixels_); |
2573 | |
2574 | if (mode == Unlock_Update) { |
2575 | - Gl::State::instance().bind(GL_TEXTURE0, m_blit_data.texture_id); |
2576 | + Gl::State::instance().bind(GL_TEXTURE0, blit_data_.texture_id); |
2577 | glTexImage2D(GL_TEXTURE_2D, 0, static_cast<GLint>(GL_RGBA), width(), height(), 0, GL_RGBA, |
2578 | - GL_UNSIGNED_BYTE, m_pixels.get()); |
2579 | + GL_UNSIGNED_BYTE, pixels_.get()); |
2580 | } |
2581 | |
2582 | - m_pixels.reset(nullptr); |
2583 | + pixels_.reset(nullptr); |
2584 | } |
2585 | |
2586 | RGBAColor Texture::get_pixel(uint16_t x, uint16_t y) { |
2587 | - assert(m_pixels); |
2588 | + assert(pixels_); |
2589 | assert(x < width()); |
2590 | assert(y < height()); |
2591 | |
2592 | RGBAColor color; |
2593 | |
2594 | - SDL_GetRGBA(*reinterpret_cast<uint32_t*>(&m_pixels[(height() - y - 1) * 4 * width() + 4 * x]), |
2595 | + SDL_GetRGBA(*reinterpret_cast<uint32_t*>(&pixels_[(height() - y - 1) * 4 * width() + 4 * x]), |
2596 | &rgba_format(), |
2597 | &color.r, |
2598 | &color.g, |
2599 | @@ -253,20 +253,20 @@ |
2600 | } |
2601 | |
2602 | void Texture::set_pixel(uint16_t x, uint16_t y, const RGBAColor& color) { |
2603 | - assert(m_pixels); |
2604 | + assert(pixels_); |
2605 | assert(x < width()); |
2606 | assert(y < height()); |
2607 | |
2608 | - uint8_t* data = &m_pixels[(height() - y - 1) * 4 * width() + 4 * x]; |
2609 | + uint8_t* data = &pixels_[(height() - y - 1) * 4 * width() + 4 * x]; |
2610 | uint32_t packed_color = SDL_MapRGBA(&rgba_format(), color.r, color.g, color.b, color.a); |
2611 | *(reinterpret_cast<uint32_t *>(data)) = packed_color; |
2612 | } |
2613 | |
2614 | |
2615 | void Texture::setup_gl() { |
2616 | - assert(m_blit_data.texture_id != 0); |
2617 | + assert(blit_data_.texture_id != 0); |
2618 | Gl::State::instance().bind_framebuffer( |
2619 | - GlFramebuffer::instance().id(), m_blit_data.texture_id); |
2620 | + GlFramebuffer::instance().id(), blit_data_.texture_id); |
2621 | glViewport(0, 0, width(), height()); |
2622 | } |
2623 | |
2624 | @@ -274,7 +274,7 @@ |
2625 | const BlitData& texture, |
2626 | float opacity, |
2627 | BlendMode blend_mode) { |
2628 | - if (m_blit_data.texture_id == 0) { |
2629 | + if (blit_data_.texture_id == 0) { |
2630 | return; |
2631 | } |
2632 | setup_gl(); |
2633 | @@ -287,7 +287,7 @@ |
2634 | const BlitData& mask, |
2635 | const RGBColor& blend) { |
2636 | |
2637 | - if (m_blit_data.texture_id == 0) { |
2638 | + if (blit_data_.texture_id == 0) { |
2639 | return; |
2640 | } |
2641 | setup_gl(); |
2642 | @@ -297,7 +297,7 @@ |
2643 | void Texture::do_blit_monochrome(const FloatRect& dst_rect, |
2644 | const BlitData& texture, |
2645 | const RGBAColor& blend) { |
2646 | - if (m_blit_data.texture_id == 0) { |
2647 | + if (blit_data_.texture_id == 0) { |
2648 | return; |
2649 | } |
2650 | setup_gl(); |
2651 | @@ -305,7 +305,7 @@ |
2652 | } |
2653 | |
2654 | void Texture::do_draw_line_strip(std::vector<DrawLineProgram::PerVertexData> vertices) { |
2655 | - if (m_blit_data.texture_id == 0) { |
2656 | + if (blit_data_.texture_id == 0) { |
2657 | return; |
2658 | } |
2659 | setup_gl(); |
2660 | @@ -315,7 +315,7 @@ |
2661 | |
2662 | void |
2663 | Texture::do_fill_rect(const FloatRect& dst_rect, const RGBAColor& color, BlendMode blend_mode) { |
2664 | - if (m_blit_data.texture_id == 0) { |
2665 | + if (blit_data_.texture_id == 0) { |
2666 | return; |
2667 | } |
2668 | setup_gl(); |
2669 | @@ -323,5 +323,5 @@ |
2670 | } |
2671 | |
2672 | const BlitData& Texture::blit_data() const { |
2673 | - return m_blit_data; |
2674 | + return blit_data_; |
2675 | } |
2676 | |
2677 | === modified file 'src/graphic/texture.h' |
2678 | --- src/graphic/texture.h 2016-02-02 09:02:53 +0000 |
2679 | +++ src/graphic/texture.h 2016-03-17 17:18:59 +0000 |
2680 | @@ -99,11 +99,11 @@ |
2681 | do_fill_rect(const FloatRect& dst_rect, const RGBAColor& color, BlendMode blend_mode) override; |
2682 | |
2683 | // True if we own the texture, i.e. if we need to delete it. |
2684 | - bool m_owns_texture; |
2685 | + bool owns_texture_; |
2686 | |
2687 | - BlitData m_blit_data; |
2688 | + BlitData blit_data_; |
2689 | /// Pixel data, while the texture is locked |
2690 | - std::unique_ptr<uint8_t[]> m_pixels; |
2691 | + std::unique_ptr<uint8_t[]> pixels_; |
2692 | |
2693 | DISALLOW_COPY_AND_ASSIGN(Texture); |
2694 | }; |
2695 | |
2696 | === modified file 'src/graphic/wordwrap.cc' |
2697 | --- src/graphic/wordwrap.cc 2016-02-03 22:42:34 +0000 |
2698 | +++ src/graphic/wordwrap.cc 2016-03-17 17:18:59 +0000 |
2699 | @@ -40,20 +40,20 @@ |
2700 | * and a default-constructed text style. |
2701 | */ |
2702 | WordWrap::WordWrap() : |
2703 | - m_wrapwidth(std::numeric_limits<uint32_t>::max()), m_draw_caret(false) |
2704 | + wrapwidth_(std::numeric_limits<uint32_t>::max()), draw_caret_(false) |
2705 | { |
2706 | } |
2707 | |
2708 | WordWrap::WordWrap(const TextStyle & style, uint32_t gwrapwidth) : |
2709 | - m_style(style), m_draw_caret(false) |
2710 | + style_(style), draw_caret_(false) |
2711 | { |
2712 | - m_wrapwidth = gwrapwidth; |
2713 | + wrapwidth_ = gwrapwidth; |
2714 | |
2715 | - if (m_wrapwidth < std::numeric_limits<uint32_t>::max()) { |
2716 | - if (m_wrapwidth < 2 * LINE_MARGIN) |
2717 | - m_wrapwidth = 0; |
2718 | + if (wrapwidth_ < std::numeric_limits<uint32_t>::max()) { |
2719 | + if (wrapwidth_ < 2 * LINE_MARGIN) |
2720 | + wrapwidth_ = 0; |
2721 | else |
2722 | - m_wrapwidth -= 2 * LINE_MARGIN; |
2723 | + wrapwidth_ -= 2 * LINE_MARGIN; |
2724 | } |
2725 | } |
2726 | |
2727 | @@ -62,7 +62,7 @@ |
2728 | */ |
2729 | void WordWrap::set_style(const TextStyle & style) |
2730 | { |
2731 | - m_style = style; |
2732 | + style_ = style; |
2733 | } |
2734 | |
2735 | /** |
2736 | @@ -70,7 +70,7 @@ |
2737 | */ |
2738 | void WordWrap::set_wrapwidth(uint32_t gwrapwidth) |
2739 | { |
2740 | - m_wrapwidth = gwrapwidth; |
2741 | + wrapwidth_ = gwrapwidth; |
2742 | } |
2743 | |
2744 | /** |
2745 | @@ -79,7 +79,7 @@ |
2746 | */ |
2747 | uint32_t WordWrap::wrapwidth() const |
2748 | { |
2749 | - return m_wrapwidth; |
2750 | + return wrapwidth_; |
2751 | } |
2752 | |
2753 | /** |
2754 | @@ -88,10 +88,10 @@ |
2755 | */ |
2756 | void WordWrap::wrap(const std::string & text) |
2757 | { |
2758 | - m_lines.clear(); |
2759 | + lines_.clear(); |
2760 | |
2761 | std::string::size_type line_start = 0; |
2762 | - uint32_t margin = m_style.calc_width_for_wrapping(0x2003); // Em space |
2763 | + uint32_t margin = style_.calc_width_for_wrapping(0x2003); // Em space |
2764 | |
2765 | while (line_start <= text.size()) { |
2766 | std::string::size_type next_line_start; |
2767 | @@ -102,7 +102,7 @@ |
2768 | LineData ld; |
2769 | ld.start = line_start; |
2770 | ld.text = text.substr(line_start, line_end - line_start); |
2771 | - m_lines.push_back(ld); |
2772 | + lines_.push_back(ld); |
2773 | |
2774 | line_start = next_line_start; |
2775 | } |
2776 | @@ -121,13 +121,13 @@ |
2777 | uint32_t safety_margin) |
2778 | { |
2779 | std::string::size_type minimum_chars = 1; // So we won't get empty lines |
2780 | - assert(text.empty() || m_wrapwidth > safety_margin); |
2781 | + assert(text.empty() || wrapwidth_ > safety_margin); |
2782 | |
2783 | std::string::size_type orig_end = text.find('\n', line_start); |
2784 | if (orig_end == std::string::npos) |
2785 | orig_end = text.size(); |
2786 | |
2787 | - if (m_wrapwidth == std::numeric_limits<uint32_t>::max() || orig_end - line_start <= minimum_chars) { |
2788 | + if (wrapwidth_ == std::numeric_limits<uint32_t>::max() || orig_end - line_start <= minimum_chars) { |
2789 | // Special fast path when wrapping is disabled or |
2790 | // original text line contains at most minimum_chars characters |
2791 | line_end = orig_end; |
2792 | @@ -137,8 +137,8 @@ |
2793 | |
2794 | |
2795 | // Optimism: perhaps the entire line fits? |
2796 | - if (text_width(text.substr(line_start, orig_end - line_start), m_style.font->size()) |
2797 | - <= m_wrapwidth - safety_margin) { |
2798 | + if (text_width(text.substr(line_start, orig_end - line_start), style_.font->size()) |
2799 | + <= wrapwidth_ - safety_margin) { |
2800 | line_end = orig_end; |
2801 | next_line_start = orig_end + 1; |
2802 | return; |
2803 | @@ -196,13 +196,13 @@ |
2804 | int32_t end = -1; |
2805 | icu::UnicodeString unicode_line; |
2806 | |
2807 | - while ((line_width < (m_wrapwidth - safety_margin)) && (end < unicode_word.length())) { |
2808 | + while ((line_width < (wrapwidth_ - safety_margin)) && (end < unicode_word.length())) { |
2809 | ++end; |
2810 | UChar c = unicode_word.charAt(end); |
2811 | // Diacritics do not add to the line width |
2812 | if (!i18n::is_diacritic(c)) { |
2813 | // This only estimates the width |
2814 | - line_width += m_style.calc_width_for_wrapping(c); |
2815 | + line_width += style_.calc_width_for_wrapping(c); |
2816 | } |
2817 | unicode_line += c; |
2818 | } |
2819 | @@ -210,7 +210,7 @@ |
2820 | // Now make sure that it really fits. |
2821 | std::string::size_type test_cutoff = line_start + end * 2 / 3; |
2822 | while ((end > 0) && (static_cast<uint32_t>(line_start + end) > test_cutoff)) { |
2823 | - if (text_width(text.substr(line_start, end), m_style.font->size()) > m_wrapwidth - safety_margin) { |
2824 | + if (text_width(text.substr(line_start, end), style_.font->size()) > wrapwidth_ - safety_margin) { |
2825 | --end; |
2826 | } else { |
2827 | break; |
2828 | @@ -241,9 +241,9 @@ |
2829 | bool WordWrap::line_fits(const std::string& text, uint32_t safety_margin) const { |
2830 | // calc_width_for_wrapping is fast, but it will underestimate the width. |
2831 | // So, we test again with text_width to make sure that the line really fits. |
2832 | - return m_style.calc_width_for_wrapping(i18n::make_ligatures(text.c_str())) |
2833 | - <= m_wrapwidth - safety_margin && |
2834 | - text_width(text, m_style.font->size()) <= m_wrapwidth - safety_margin; |
2835 | + return style_.calc_width_for_wrapping(i18n::make_ligatures(text.c_str())) |
2836 | + <= wrapwidth_ - safety_margin && |
2837 | + text_width(text, style_.font->size()) <= wrapwidth_ - safety_margin; |
2838 | } |
2839 | |
2840 | |
2841 | @@ -256,8 +256,8 @@ |
2842 | { |
2843 | uint32_t calculated_width = 0; |
2844 | |
2845 | - for (uint32_t line = 0; line < m_lines.size(); ++line) { |
2846 | - uint32_t linewidth = text_width(m_lines[line].text, m_style.font->size()); |
2847 | + for (uint32_t line = 0; line < lines_.size(); ++line) { |
2848 | + uint32_t linewidth = text_width(lines_[line].text, style_.font->size()); |
2849 | if (linewidth > calculated_width) |
2850 | calculated_width = linewidth; |
2851 | } |
2852 | @@ -271,11 +271,11 @@ |
2853 | uint32_t WordWrap::height() const |
2854 | { |
2855 | uint16_t fontheight = 0; |
2856 | - if (!m_lines.empty()) { |
2857 | - fontheight = text_height(m_lines[0].text, m_style.font->size()); |
2858 | + if (!lines_.empty()) { |
2859 | + fontheight = text_height(lines_[0].text, style_.font->size()); |
2860 | } |
2861 | |
2862 | - return fontheight * (m_lines.size()) + 2 * LINE_MARGIN; |
2863 | + return fontheight * (lines_.size()) + 2 * LINE_MARGIN; |
2864 | } |
2865 | |
2866 | /** |
2867 | @@ -284,25 +284,25 @@ |
2868 | */ |
2869 | void WordWrap::calc_wrapped_pos(uint32_t caret, uint32_t & line, uint32_t & pos) const |
2870 | { |
2871 | - assert(m_lines.size()); |
2872 | - assert(m_lines[0].start == 0); |
2873 | + assert(lines_.size()); |
2874 | + assert(lines_[0].start == 0); |
2875 | |
2876 | uint32_t min = 0; |
2877 | - uint32_t max = m_lines.size() - 1; |
2878 | + uint32_t max = lines_.size() - 1; |
2879 | |
2880 | while (max > min) { |
2881 | uint32_t mid = min + (max - min + 1) / 2; |
2882 | |
2883 | - if (caret >= m_lines[mid].start) |
2884 | + if (caret >= lines_[mid].start) |
2885 | min = mid; |
2886 | else |
2887 | max = mid - 1; |
2888 | } |
2889 | |
2890 | - assert(caret >= m_lines[min].start); |
2891 | + assert(caret >= lines_[min].start); |
2892 | |
2893 | line = min; |
2894 | - pos = caret - m_lines[min].start; |
2895 | + pos = caret - lines_[min].start; |
2896 | } |
2897 | |
2898 | /** |
2899 | @@ -310,7 +310,7 @@ |
2900 | */ |
2901 | uint32_t WordWrap::line_offset(uint32_t line) const |
2902 | { |
2903 | - return m_lines[line].start; |
2904 | + return lines_[line].start; |
2905 | } |
2906 | |
2907 | /** |
2908 | @@ -320,7 +320,7 @@ |
2909 | */ |
2910 | void WordWrap::draw(RenderTarget & dst, Point where, Align align, uint32_t caret) |
2911 | { |
2912 | - if (m_lines.empty()) return; |
2913 | + if (lines_.empty()) return; |
2914 | |
2915 | uint32_t caretline, caretpos; |
2916 | |
2917 | @@ -339,28 +339,28 @@ |
2918 | |
2919 | Align alignment = mirror_alignment(align); |
2920 | |
2921 | - uint16_t fontheight = text_height(m_lines[0].text, m_style.font->size()); |
2922 | - for (uint32_t line = 0; line < m_lines.size(); ++line, where.y += fontheight) { |
2923 | + uint16_t fontheight = text_height(lines_[0].text, style_.font->size()); |
2924 | + for (uint32_t line = 0; line < lines_.size(); ++line, where.y += fontheight) { |
2925 | if (where.y >= dst.height() || int32_t(where.y + fontheight) <= 0) |
2926 | continue; |
2927 | |
2928 | Point point(where.x, where.y); |
2929 | |
2930 | if (static_cast<int>(alignment & UI::Align::kRight)) { |
2931 | - point.x += m_wrapwidth - LINE_MARGIN; |
2932 | + point.x += wrapwidth_ - LINE_MARGIN; |
2933 | } |
2934 | |
2935 | const Image* entry_text_im = |
2936 | - UI::g_fh1->render(as_editorfont(m_lines[line].text, |
2937 | - m_style.font->size() - UI::g_fh1->fontset()->size_offset(), |
2938 | - m_style.fg)); |
2939 | + UI::g_fh1->render(as_editorfont(lines_[line].text, |
2940 | + style_.font->size() - UI::g_fh1->fontset()->size_offset(), |
2941 | + style_.fg)); |
2942 | UI::correct_for_align(alignment, entry_text_im->width(), fontheight, &point); |
2943 | dst.blit(point, entry_text_im); |
2944 | |
2945 | - if (m_draw_caret && line == caretline) { |
2946 | - std::string line_to_caret = m_lines[line].text.substr(0, caretpos); |
2947 | + if (draw_caret_ && line == caretline) { |
2948 | + std::string line_to_caret = lines_[line].text.substr(0, caretpos); |
2949 | // TODO(GunChleoc): Arabic: Fix cursor position for BIDI text. |
2950 | - int caret_x = text_width(line_to_caret, m_style.font->size()); |
2951 | + int caret_x = text_width(line_to_caret, style_.font->size()); |
2952 | |
2953 | const Image* caret_image = g_gr->images().get("images/ui_basic/caret.png"); |
2954 | Point caretpt; |
2955 | |
2956 | === modified file 'src/graphic/wordwrap.h' |
2957 | --- src/graphic/wordwrap.h 2016-01-28 21:27:04 +0000 |
2958 | +++ src/graphic/wordwrap.h 2016-03-17 17:18:59 +0000 |
2959 | @@ -45,14 +45,14 @@ |
2960 | |
2961 | uint32_t width() const; |
2962 | uint32_t height() const; |
2963 | - void set_draw_caret(bool draw_it) {m_draw_caret = draw_it;} |
2964 | + void set_draw_caret(bool draw_it) {draw_caret_ = draw_it;} |
2965 | |
2966 | void draw |
2967 | (RenderTarget & dst, Point where, Align align = UI::Align::kLeft, |
2968 | uint32_t caret = std::numeric_limits<uint32_t>::max()); |
2969 | |
2970 | void calc_wrapped_pos(uint32_t caret, uint32_t & line, uint32_t & pos) const; |
2971 | - uint32_t nrlines() const {return m_lines.size();} |
2972 | + uint32_t nrlines() const {return lines_.size();} |
2973 | uint32_t line_offset(uint32_t line) const; |
2974 | |
2975 | private: |
2976 | @@ -73,11 +73,11 @@ |
2977 | |
2978 | bool line_fits(const std::string& text, uint32_t safety_margin) const; |
2979 | |
2980 | - TextStyle m_style; |
2981 | - uint32_t m_wrapwidth; |
2982 | - bool m_draw_caret; |
2983 | + TextStyle style_; |
2984 | + uint32_t wrapwidth_; |
2985 | + bool draw_caret_; |
2986 | |
2987 | - std::vector<LineData> m_lines; |
2988 | + std::vector<LineData> lines_; |
2989 | }; |
2990 | |
2991 | } // namespace UI |
LGTM