widelands-dev team mailing list archive
-
widelands-dev team
-
Mailing list archive
-
Message #06776
[Merge] lp:~widelands-dev/widelands/bug-1395278-graphic into lp:widelands
GunChleoc has proposed merging lp:~widelands-dev/widelands/bug-1395278-graphic into lp:widelands.
Commit message:
Refactored member variables in src/graphic.
Requested reviews:
Widelands Developers (widelands-dev)
Related bugs:
Bug #1395278 in widelands: "Consolidate naming of member variables"
https://bugs.launchpad.net/widelands/+bug/1395278
For more details, see:
https://code.launchpad.net/~widelands-dev/widelands/bug-1395278-graphic/+merge/289402
3 remaining and then we're done...
--
Your team Widelands Developers is requested to review the proposed merge of lp:~widelands-dev/widelands/bug-1395278-graphic into lp:widelands.
=== modified file 'src/graphic/font.cc'
--- src/graphic/font.cc 2016-02-03 22:42:34 +0000
+++ src/graphic/font.cc 2016-03-17 17:18:59 +0000
@@ -57,18 +57,18 @@
// Load the TrueType Font
std::string filename = "i18n/fonts/";
filename += name;
- m_size = input_size;
+ size_ = input_size;
// We must keep this File Read open, otherwise the following calls are
// crashing. do not know why...
- m_fontfile.open(*g_fs, filename);
+ fontfile_.open(*g_fs, filename);
- SDL_RWops * const ops = SDL_RWFromMem(m_fontfile.data(0), m_fontfile.get_size());
+ SDL_RWops * const ops = SDL_RWFromMem(fontfile_.data(0), fontfile_.get_size());
if (!ops)
throw wexception("could not load font!: RWops Pointer invalid");
- m_font = TTF_OpenFontIndexRW(ops, 1, input_size, 0);
- if (!m_font)
+ font_ = TTF_OpenFontIndexRW(ops, 1, input_size, 0);
+ if (!font_)
throw wexception("could not load font!: %s", TTF_GetError());
// Compute the line skip based on some glyphs by sampling some letters,
@@ -76,18 +76,18 @@
// It seems more reasonable to use TTF_FontLineSkip(), but the fonts
// we use claim to have a very excessive line skip.
static uint16_t glyphs[] = {'A', '_', '@', ',', 'q', 'y', '"', 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5};
- m_computed_typical_miny = 0;
- m_computed_typical_maxy = 0;
+ computed_typical_miny_ = 0;
+ computed_typical_maxy_ = 0;
for (unsigned int idx = 0; idx < sizeof(glyphs) / sizeof(glyphs[0]); ++idx) {
int miny, maxy;
- if (TTF_GlyphMetrics(m_font, glyphs[idx], nullptr, nullptr, &miny, &maxy, nullptr) < 0)
+ if (TTF_GlyphMetrics(font_, glyphs[idx], nullptr, nullptr, &miny, &maxy, nullptr) < 0)
continue; // error, e.g. glyph not found
- if (miny < m_computed_typical_miny)
- m_computed_typical_miny = miny;
- if (maxy > m_computed_typical_maxy)
- m_computed_typical_maxy = maxy;
+ if (miny < computed_typical_miny_)
+ computed_typical_miny_ = miny;
+ if (maxy > computed_typical_maxy_)
+ computed_typical_maxy_ = maxy;
}
}
@@ -96,8 +96,8 @@
*/
Font::~Font()
{
- TTF_CloseFont(m_font);
- m_font = nullptr;
+ TTF_CloseFont(font_);
+ font_ = nullptr;
}
/**
@@ -105,7 +105,7 @@
*/
uint32_t Font::height() const
{
- return TTF_FontHeight(m_font);
+ return TTF_FontHeight(font_);
}
/**
@@ -113,7 +113,7 @@
*/
uint32_t Font::size() const
{
- return m_size;
+ return size_;
}
/**
@@ -121,7 +121,7 @@
*/
uint32_t Font::ascent() const
{
- return TTF_FontAscent(m_font);
+ return TTF_FontAscent(font_);
}
/**
@@ -129,7 +129,7 @@
*/
uint32_t Font::lineskip() const
{
- return m_computed_typical_maxy - m_computed_typical_miny;
+ return computed_typical_maxy_ - computed_typical_miny_;
}
/**
=== modified file 'src/graphic/font.h'
--- src/graphic/font.h 2015-10-23 12:05:36 +0000
+++ src/graphic/font.h 2016-03-17 17:18:59 +0000
@@ -50,23 +50,23 @@
uint32_t height() const;
uint32_t lineskip() const;
- TTF_Font * get_ttf_font() const {return m_font;}
+ TTF_Font * get_ttf_font() const {return font_;}
private:
Font(const std::string & name, int size);
~Font();
- FileRead m_fontfile;
- TTF_Font * m_font;
+ FileRead fontfile_;
+ TTF_Font * font_;
/**
* Work around weird fonts with very large lineskip, to get something
* that makes more sense as the default skip in Latin scripts.
*/
- int32_t m_computed_typical_miny;
- int32_t m_computed_typical_maxy;
+ int32_t computed_typical_miny_;
+ int32_t computed_typical_maxy_;
- int m_size;
+ int size_;
};
} // namespace UI
=== modified file 'src/graphic/gl/utils.h'
--- src/graphic/gl/utils.h 2016-02-01 10:32:12 +0000
+++ src/graphic/gl/utils.h 2016-03-17 17:18:59 +0000
@@ -143,7 +143,7 @@
// Calls glVertexAttribPointer.
void vertex_attrib_pointer(int vertex_index, int num_items, int stride, int offset);
-// Swap order of rows in m_pixels, to compensate for the upside-down nature of the
+// Swap order of rows in pixels, to compensate for the upside-down nature of the
// OpenGL coordinate system.
void swap_rows(int width, int height, int pitch, int bpp, uint8_t* pixels);
=== modified file 'src/graphic/rendertarget.cc'
--- src/graphic/rendertarget.cc 2016-03-07 18:55:11 +0000
+++ src/graphic/rendertarget.cc 2016-03-17 17:18:59 +0000
@@ -29,7 +29,7 @@
*/
RenderTarget::RenderTarget(Surface* surf)
{
- m_surface = surf;
+ surface_ = surf;
reset();
}
@@ -38,30 +38,30 @@
*/
void RenderTarget::set_window(const Rect& rc, const Point& ofs)
{
- m_rect = rc;
- m_offset = ofs;
+ rect_ = rc;
+ offset_ = ofs;
// safeguards clipping against the bitmap itself
- if (m_rect.x < 0) {
- m_offset.x += m_rect.x;
- m_rect.w = std::max<int32_t>(m_rect.w + m_rect.x, 0);
- m_rect.x = 0;
- }
-
- if (m_rect.x + m_rect.w > m_surface->width())
- m_rect.w =
- std::max<int32_t>(m_surface->width() - m_rect.x, 0);
-
- if (m_rect.y < 0) {
- m_offset.y += m_rect.y;
- m_rect.h = std::max<int32_t>(m_rect.h + m_rect.y, 0);
- m_rect.y = 0;
- }
-
- if (m_rect.y + m_rect.h > m_surface->height())
- m_rect.h =
- std::max<int32_t>(m_surface->height() - m_rect.y, 0);
+ if (rect_.x < 0) {
+ offset_.x += rect_.x;
+ rect_.w = std::max<int32_t>(rect_.w + rect_.x, 0);
+ rect_.x = 0;
+ }
+
+ if (rect_.x + rect_.w > surface_->width())
+ rect_.w =
+ std::max<int32_t>(surface_->width() - rect_.x, 0);
+
+ if (rect_.y < 0) {
+ offset_.y += rect_.y;
+ rect_.h = std::max<int32_t>(rect_.h + rect_.y, 0);
+ rect_.y = 0;
+ }
+
+ if (rect_.y + rect_.h > surface_->height())
+ rect_.h =
+ std::max<int32_t>(surface_->height() - rect_.y, 0);
}
/**
@@ -80,13 +80,13 @@
if (clip(newrect)) {
if (previous)
- *previous = m_rect;
+ *previous = rect_;
if (prevofs)
- *prevofs = m_offset;
+ *prevofs = offset_;
// Apply the changes
- m_offset = rc.origin() - (newrect.origin() - m_rect.origin() - m_offset);
- m_rect = newrect;
+ offset_ = rc.origin() - (newrect.origin() - rect_.origin() - offset_);
+ rect_ = newrect;
return true;
} else return false;
@@ -97,7 +97,7 @@
*/
int32_t RenderTarget::width() const
{
- return m_surface->width();
+ return surface_->width();
}
/**
@@ -105,7 +105,7 @@
*/
int32_t RenderTarget::height() const
{
- return m_surface->height();
+ return surface_->height();
}
/**
@@ -117,9 +117,9 @@
std::vector<FloatPoint> adjusted_points;
adjusted_points.reserve(points.size());
for (const auto& p : points) {
- adjusted_points.emplace_back(p.x + m_offset.x + m_rect.x, p.y + m_offset.y + m_rect.y);
+ adjusted_points.emplace_back(p.x + offset_.x + rect_.x, p.y + offset_.y + rect_.y);
}
- m_surface->draw_line_strip(adjusted_points, color, line_width);
+ surface_->draw_line_strip(adjusted_points, color, line_width);
}
/**
@@ -129,7 +129,7 @@
{
Rect r(rect);
if (clip(r)) {
- ::draw_rect(r, clr, m_surface);
+ ::draw_rect(r, clr, surface_);
}
}
@@ -137,14 +137,14 @@
{
Rect r(rect);
if (clip(r))
- m_surface->fill_rect(r, clr);
+ surface_->fill_rect(r, clr);
}
void RenderTarget::brighten_rect(const Rect& rect, int32_t factor)
{
Rect r(rect);
if (clip(r))
- m_surface->brighten_rect(r, factor);
+ surface_->brighten_rect(r, factor);
}
/**
@@ -161,7 +161,7 @@
Rect destination_rect(destination_point.x, destination_point.y, source_rect.w, source_rect.h);
if (to_surface_geometry(&destination_rect, &source_rect)) {
- m_surface->blit(destination_rect, *image, source_rect, 1., blend_mode);
+ surface_->blit(destination_rect, *image, source_rect, 1., blend_mode);
}
}
@@ -175,7 +175,7 @@
Rect destination_rect(destination_point.x, destination_point.y, source_rect.w, source_rect.h);
if (to_surface_geometry(&destination_rect, &source_rect)) {
- m_surface->blit_monochrome(destination_rect, *image, source_rect, blend_mode);
+ surface_->blit_monochrome(destination_rect, *image, source_rect, blend_mode);
}
}
@@ -197,7 +197,7 @@
Rect destination_rect(dst.x, dst.y, source_rect.w, source_rect.h);
if (to_surface_geometry(&destination_rect, &source_rect)) {
- m_surface->blit(destination_rect, *image, source_rect, 1., blend_mode);
+ surface_->blit(destination_rect, *image, source_rect, 1., blend_mode);
}
}
@@ -207,7 +207,7 @@
const float opacity,
const BlendMode blend_mode) {
if (to_surface_geometry(&destination_rect, &source_rect)) {
- m_surface->blit(destination_rect, *image, source_rect, opacity, blend_mode);
+ surface_->blit(destination_rect, *image, source_rect, opacity, blend_mode);
}
}
@@ -216,7 +216,7 @@
Rect source_rect,
const RGBAColor& blend) {
if (to_surface_geometry(&destination_rect, &source_rect)) {
- m_surface->blit_monochrome(destination_rect, *image, source_rect, blend);
+ surface_->blit_monochrome(destination_rect, *image, source_rect, blend);
}
}
@@ -234,11 +234,11 @@
Rect r(rect);
Point ofs(gofs);
if (clip(r)) {
- if (m_offset.x < 0)
- ofs.x -= m_offset.x;
+ if (offset_.x < 0)
+ ofs.x -= offset_.x;
- if (m_offset.y < 0)
- ofs.y -= m_offset.y;
+ if (offset_.y < 0)
+ ofs.y -= offset_.y;
// Make sure the offset is within bounds
ofs.x = ofs.x % srcw;
@@ -273,7 +273,7 @@
srcrc.w = r.w - tx;
const Rect dst_rect(r.x + tx, r.y + ty, srcrc.w, srcrc.h);
- m_surface->blit(dst_rect, *image, srcrc, 1., blend_mode);
+ surface_->blit(dst_rect, *image, srcrc, 1., blend_mode);
tx += srcrc.w;
@@ -332,7 +332,7 @@
source_rect.h);
Rect srcrc(source_rect);
if (to_surface_geometry(&destination_rect, &srcrc)) {
- animation.blit(time, destination_rect.origin(), srcrc, player_color, m_surface);
+ animation.blit(time, destination_rect.origin(), srcrc, player_color, surface_);
}
// Look if there is a sound effect registered for this frame and trigger the
@@ -348,23 +348,23 @@
*/
void RenderTarget::reset()
{
- m_rect.x = m_rect.y = 0;
- m_rect.w = m_surface->width();
- m_rect.h = m_surface->height();
+ rect_.x = rect_.y = 0;
+ rect_.w = surface_->width();
+ rect_.h = surface_->height();
- m_offset.x = m_offset.y = 0;
+ offset_.x = offset_.y = 0;
}
/**
- * Offsets r by m_offset and clips r against m_rect.
+ * Offsets r by offset_ and clips r against rect_.
*
* If true is returned, r a valid rectangle that can be used.
* If false is returned, r may not be used and may be partially modified.
*/
bool RenderTarget::clip(Rect & r) const
{
- r.x += m_offset.x;
- r.y += m_offset.y;
+ r.x += offset_.x;
+ r.y += offset_.y;
if (r.x < 0) {
if (r.w <= -r.x)
@@ -375,10 +375,10 @@
r.x = 0;
}
- if (r.x + r.w > m_rect.w) {
- if (m_rect.w <= r.x)
+ if (r.x + r.w > rect_.w) {
+ if (rect_.w <= r.x)
return false;
- r.w = m_rect.w - r.x;
+ r.w = rect_.w - r.x;
}
if (r.y < 0) {
@@ -388,14 +388,14 @@
r.y = 0;
}
- if (r.y + r.h > m_rect.h) {
- if (m_rect.h <= r.y)
+ if (r.y + r.h > rect_.h) {
+ if (rect_.h <= r.y)
return false;
- r.h = m_rect.h - r.y;
+ r.h = rect_.h - r.y;
}
- r.x += m_rect.x;
- r.y += m_rect.y;
+ r.x += rect_.x;
+ r.y += rect_.y;
return r.w && r.h;
}
@@ -408,8 +408,8 @@
{
assert(0 <= source_rect->x);
assert(0 <= source_rect->y);
- destination_rect->x += m_offset.x;
- destination_rect->y += m_offset.y;
+ destination_rect->x += offset_.x;
+ destination_rect->y += offset_.y;
// We have to clip the target rect against our own drawing area. If we make
// changes to any side of our rectangle, we have to change the source rect
@@ -431,11 +431,11 @@
}
// Clipping, from the right.
- if (destination_rect->x + destination_rect->w > m_rect.w) {
- if (m_rect.w <= destination_rect->x) {
+ if (destination_rect->x + destination_rect->w > rect_.w) {
+ if (rect_.w <= destination_rect->x) {
return false;
}
- const int new_destination_w = m_rect.w - destination_rect->x;
+ const int new_destination_w = rect_.w - destination_rect->x;
// Adding 0.5 is a cheap way of turning integer truncation into a rounded value.
source_rect->w =
0.5 + static_cast<double>(new_destination_w) / destination_rect->w * source_rect->w;
@@ -457,18 +457,18 @@
}
// Clipping, from the bottom.
- if (destination_rect->y + destination_rect->h > m_rect.h) {
- if (m_rect.h <= destination_rect->y) {
+ if (destination_rect->y + destination_rect->h > rect_.h) {
+ if (rect_.h <= destination_rect->y) {
return false;
}
- const int new_destination_h = m_rect.h - destination_rect->y;
+ const int new_destination_h = rect_.h - destination_rect->y;
// Adding 0.5 is a cheap way of turning integer truncation into a rounded value.
source_rect->h =
0.5 + static_cast<double>(new_destination_h) / destination_rect->h * source_rect->h;
destination_rect->h = new_destination_h;
}
- destination_rect->x += m_rect.x;
- destination_rect->y += m_rect.y;
+ destination_rect->x += rect_.x;
+ destination_rect->y += rect_.y;
return true;
}
=== modified file 'src/graphic/rendertarget.h'
--- src/graphic/rendertarget.h 2016-02-19 19:10:44 +0000
+++ src/graphic/rendertarget.h 2016-03-17 17:18:59 +0000
@@ -116,9 +116,9 @@
void reset();
- Surface* get_surface() const {return m_surface;}
- const Rect& get_rect() const {return m_rect;}
- const Point& get_offset() const {return m_offset;}
+ Surface* get_surface() const {return surface_;}
+ const Rect& get_rect() const {return rect_;}
+ const Point& get_offset() const {return offset_;}
protected:
bool clip(Rect & r) const;
@@ -131,12 +131,12 @@
const RGBColor* player_color,
const Rect& source_rect);
- ///The target surface
- Surface* m_surface;
- ///The current clip rectangle
- Rect m_rect;
- ///Drawing offset
- Point m_offset;
+ /// The target surface
+ Surface* surface_;
+ /// The current clip rectangle
+ Rect rect_;
+ /// Drawing offset
+ Point offset_;
};
#endif // end of include guard: WL_GRAPHIC_RENDERTARGET_H
=== modified file 'src/graphic/screen.cc'
--- src/graphic/screen.cc 2016-02-02 09:02:53 +0000
+++ src/graphic/screen.cc 2016-03-17 17:18:59 +0000
@@ -27,31 +27,31 @@
#include "graphic/render_queue.h"
#include "graphic/texture.h"
-Screen::Screen(int w, int h) : m_w(w), m_h(h) {
+Screen::Screen(int w, int h) : w_(w), h_(h) {
}
int Screen::width() const {
- return m_w;
+ return w_;
}
int Screen::height() const {
- return m_h;
+ return h_;
}
std::unique_ptr<Texture> Screen::to_texture() const {
- std::unique_ptr<uint8_t[]> pixels(new uint8_t[m_w * m_h * 4]);
- glReadPixels(0, 0, m_w, m_h, GL_RGBA, GL_UNSIGNED_BYTE, pixels.get());
+ std::unique_ptr<uint8_t[]> pixels(new uint8_t[w_ * h_ * 4]);
+ glReadPixels(0, 0, w_, h_, GL_RGBA, GL_UNSIGNED_BYTE, pixels.get());
- Gl::swap_rows(m_w, m_h, m_w * 4, 4, pixels.get());
+ Gl::swap_rows(w_, h_, w_ * 4, 4, pixels.get());
// Ownership of pixels is not taken here. But the Texture() transfers it to
// the GPU, frees the SDL surface and after that we are free to free
// 'pixels'.
SDL_Surface* surface = SDL_CreateRGBSurfaceFrom(pixels.get(),
- m_w,
- m_h,
+ w_,
+ h_,
32,
- m_w * 4,
+ w_ * 4,
0x000000ff,
0x0000ff00,
0x00ff0000,
=== modified file 'src/graphic/screen.h'
--- src/graphic/screen.h 2016-02-02 09:02:53 +0000
+++ src/graphic/screen.h 2016-03-17 17:18:59 +0000
@@ -57,7 +57,7 @@
void
do_fill_rect(const FloatRect& dst_rect, const RGBAColor& color, BlendMode blend_mode) override;
- const int m_w, m_h;
+ const int w_, h_;
DISALLOW_COPY_AND_ASSIGN(Screen);
};
=== modified file 'src/graphic/text/rt_errors.h'
--- src/graphic/text/rt_errors.h 2016-01-31 15:31:00 +0000
+++ src/graphic/text/rt_errors.h 2016-03-17 17:18:59 +0000
@@ -28,12 +28,12 @@
class Exception : public std::exception {
public:
- Exception(std::string msg) : std::exception(), m_msg(msg) {
+ Exception(std::string msg) : std::exception(), msg_(msg) {
}
- const char* what() const noexcept override {return m_msg.c_str();}
+ const char* what() const noexcept override {return msg_.c_str();}
private:
- std::string m_msg;
+ std::string msg_;
};
#define DEF_ERR(Name) class Name : public Exception { \
=== modified file 'src/graphic/text/rt_parse.cc'
--- src/graphic/text/rt_parse.cc 2016-02-21 12:08:36 +0000
+++ src/graphic/text/rt_parse.cc 2016-03-17 17:18:59 +0000
@@ -34,103 +34,103 @@
namespace RT {
-Attr::Attr(const std::string& gname, const std::string& value) : m_name(gname), m_value(value) {
+Attr::Attr(const std::string& gname, const std::string& value) : name_(gname), value_(value) {
}
const std::string& Attr::name() const {
- return m_name;
+ return name_;
}
long Attr::get_int() const {
- long rv = strtol(m_value.c_str(), nullptr, 10);
+ long rv = strtol(value_.c_str(), nullptr, 10);
return rv;
}
std::string Attr::get_string() const {
- return m_value;
+ return value_;
}
bool Attr::get_bool() const {
- if (m_value == "true" || m_value == "1" || m_value == "yes")
+ if (value_ == "true" || value_ == "1" || value_ == "yes")
return true;
return false;
}
RGBColor Attr::get_color() const {
- if (m_value.size() != 6)
- throw InvalidColor((boost::format("Could not parse '%s' as a color.") % m_value).str());
+ if (value_.size() != 6)
+ throw InvalidColor((boost::format("Could not parse '%s' as a color.") % value_).str());
- uint32_t clrn = strtol(m_value.c_str(), nullptr, 16);
+ uint32_t clrn = strtol(value_.c_str(), nullptr, 16);
return RGBColor((clrn >> 16) & 0xff, (clrn >> 8) & 0xff, clrn & 0xff);
}
void AttrMap::add_attribute(const std::string& name, Attr* a) {
- m_attrs[name] = std::unique_ptr<Attr>(a);
+ attrs_[name] = std::unique_ptr<Attr>(a);
}
const Attr& AttrMap::operator[](const std::string& s) const {
- const auto i = m_attrs.find(s);
- if (i == m_attrs.end()) {
+ const auto i = attrs_.find(s);
+ if (i == attrs_.end()) {
throw AttributeNotFound(s);
}
return *(i->second);
}
bool AttrMap::has(const std::string& s) const {
- return m_attrs.count(s);
+ return attrs_.count(s);
}
const std::string& Tag::name() const {
- return m_name;
+ return name_;
}
const AttrMap& Tag::attrs() const {
- return m_am;
+ return attribute_map_;
}
-const Tag::ChildList& Tag::childs() const {
- return m_childs;
+const Tag::ChildList& Tag::children() const {
+ return children_;
}
Tag::~Tag() {
- while (m_childs.size()) {
- delete m_childs.back();
- m_childs.pop_back();
+ while (children_.size()) {
+ delete children_.back();
+ children_.pop_back();
}
}
-void Tag::m_parse_opening_tag(TextStream & ts, TagConstraints & tcs) {
+void Tag::parse_opening_tag(TextStream & ts, TagConstraints & tcs) {
ts.expect("<");
- m_name = ts.till_any(" \t\n>");
+ name_ = ts.till_any(" \t\n>");
ts.skip_ws();
while (ts.peek(1) != ">") {
- m_parse_attribute(ts, tcs[m_name].allowed_attrs);
+ parse_attribute(ts, tcs[name_].allowed_attrs);
ts.skip_ws();
}
ts.expect(">");
}
-void Tag::m_parse_closing_tag(TextStream & ts) {
+void Tag::parse_closing_tag(TextStream & ts) {
ts.expect("</");
- ts.expect(m_name, false);
+ ts.expect(name_, false);
ts.expect(">", false);
}
-void Tag::m_parse_attribute(TextStream & ts, std::unordered_set<std::string> & allowed_attrs) {
+void Tag::parse_attribute(TextStream & ts, std::unordered_set<std::string> & allowed_attrs) {
std::string aname = ts.till_any("=");
if (!allowed_attrs.count(aname))
throw SyntaxErrorImpl(ts.line(), ts.col(), "an allowed attribute", aname, ts.peek(100));
ts.skip(1);
- m_am.add_attribute(aname, new Attr(aname, ts.parse_string()));
+ attribute_map_.add_attribute(aname, new Attr(aname, ts.parse_string()));
}
-void Tag::m_parse_content(TextStream & ts, TagConstraints & tcs, const TagSet & allowed_tags)
+void Tag::parse_content(TextStream & ts, TagConstraints & tcs, const TagSet & allowed_tags)
{
- TagConstraint tc = tcs[m_name];
+ TagConstraint tc = tcs[name_];
for (;;) {
if (!tc.text_allowed)
@@ -142,31 +142,31 @@
if (!tc.text_allowed) {
throw SyntaxErrorImpl(line, col, "no text, as only tags are allowed here", text, ts.peek(100));
}
- m_childs.push_back(new Child(text));
+ children_.push_back(new Child(text));
}
- if (ts.peek(2 + m_name.size()) == ("</" + m_name))
+ if (ts.peek(2 + name_.size()) == ("</" + name_))
break;
Tag * child = new Tag();
line = ts.line(); col = ts.col(); size_t cpos = ts.pos();
child->parse(ts, tcs, allowed_tags);
- if (!tc.allowed_childs.count(child->name()))
+ if (!tc.allowed_children.count(child->name()))
throw SyntaxErrorImpl(line, col, "an allowed tag", child->name(), ts.peek(100, cpos));
if (!allowed_tags.empty() && !allowed_tags.count(child->name()))
throw SyntaxErrorImpl(line, col, "an allowed tag", child->name(), ts.peek(100, cpos));
- m_childs.push_back(new Child(child));
+ children_.push_back(new Child(child));
}
}
void Tag::parse(TextStream & ts, TagConstraints & tcs, const TagSet & allowed_tags) {
- m_parse_opening_tag(ts, tcs);
+ parse_opening_tag(ts, tcs);
- TagConstraint tc = tcs[m_name];
+ TagConstraint tc = tcs[name_];
if (tc.has_closing_tag) {
- m_parse_content(ts, tcs, allowed_tags);
- m_parse_closing_tag(ts);
+ parse_content(ts, tcs, allowed_tags);
+ parse_closing_tag(ts);
}
}
@@ -186,19 +186,19 @@
tc.allowed_attrs.insert("keep_spaces"); // Keeps blank spaces intact for text editing
tc.allowed_attrs.insert("background");
- tc.allowed_childs.insert("p");
- tc.allowed_childs.insert("vspace");
- tc.allowed_childs.insert("font");
- tc.allowed_childs.insert("sub");
+ tc.allowed_children.insert("p");
+ tc.allowed_children.insert("vspace");
+ tc.allowed_children.insert("font");
+ tc.allowed_children.insert("sub");
tc.text_allowed = false;
tc.has_closing_tag = true;
- m_tcs["rt"] = tc;
+ tag_constraints_["rt"] = tc;
}
{ // br tag
TagConstraint tc;
tc.text_allowed = false;
tc.has_closing_tag = false;
- m_tcs["br"] = tc;
+ tag_constraints_["br"] = tc;
}
{ // img tag
TagConstraint tc;
@@ -206,14 +206,14 @@
tc.allowed_attrs.insert("ref");
tc.text_allowed = false;
tc.has_closing_tag = false;
- m_tcs["img"] = tc;
+ tag_constraints_["img"] = tc;
}
{ // vspace tag
TagConstraint tc;
tc.allowed_attrs.insert("gap");
tc.text_allowed = false;
tc.has_closing_tag = false;
- m_tcs["vspace"] = tc;
+ tag_constraints_["vspace"] = tc;
}
{ // space tag
TagConstraint tc;
@@ -221,7 +221,7 @@
tc.allowed_attrs.insert("fill");
tc.text_allowed = false;
tc.has_closing_tag = false;
- m_tcs["space"] = tc;
+ tag_constraints_["space"] = tc;
}
{ // sub tag
TagConstraint tc;
@@ -236,14 +236,14 @@
tc.allowed_attrs.insert("background");
tc.allowed_attrs.insert("width");
- tc.allowed_childs.insert("p");
- tc.allowed_childs.insert("vspace");
- tc.allowed_childs.insert("font");
- tc.allowed_childs.insert("sub");
+ tc.allowed_children.insert("p");
+ tc.allowed_children.insert("vspace");
+ tc.allowed_children.insert("font");
+ tc.allowed_children.insert("sub");
tc.text_allowed = false;
tc.has_closing_tag = true;
- m_tcs["sub"] = tc;
+ tag_constraints_["sub"] = tc;
}
{ // p tag
TagConstraint tc;
@@ -252,14 +252,14 @@
tc.allowed_attrs.insert("valign");
tc.allowed_attrs.insert("spacing");
- tc.allowed_childs.insert("font");
- tc.allowed_childs.insert("space");
- tc.allowed_childs.insert("br");
- tc.allowed_childs.insert("img");
- tc.allowed_childs.insert("sub");
+ tc.allowed_children.insert("font");
+ tc.allowed_children.insert("space");
+ tc.allowed_children.insert("br");
+ tc.allowed_children.insert("img");
+ tc.allowed_children.insert("sub");
tc.text_allowed = true;
tc.has_closing_tag = true;
- m_tcs["p"] = tc;
+ tag_constraints_["p"] = tc;
}
{ // font tag
TagConstraint tc;
@@ -272,14 +272,14 @@
tc.allowed_attrs.insert("shadow");
tc.allowed_attrs.insert("ref");
- tc.allowed_childs.insert("br");
- tc.allowed_childs.insert("space");
- tc.allowed_childs.insert("p");
- tc.allowed_childs.insert("font");
- tc.allowed_childs.insert("sub");
+ tc.allowed_children.insert("br");
+ tc.allowed_children.insert("space");
+ tc.allowed_children.insert("p");
+ tc.allowed_children.insert("font");
+ tc.allowed_children.insert("sub");
tc.text_allowed = true;
tc.has_closing_tag = true;
- m_tcs["font"] = tc;
+ tag_constraints_["font"] = tc;
}
}
@@ -289,18 +289,18 @@
Tag * Parser::parse(std::string text, const TagSet & allowed_tags) {
boost::replace_all(text, "\\", "\\\\"); // Prevent crashes with \.
- m_ts.reset(new TextStream(text));
+ text_stream_.reset(new TextStream(text));
- m_ts->skip_ws(); m_ts->rskip_ws();
+ text_stream_->skip_ws(); text_stream_->rskip_ws();
Tag * rv = new Tag();
- rv->parse(*m_ts, m_tcs, allowed_tags);
+ rv->parse(*text_stream_, tag_constraints_, allowed_tags);
return rv;
}
std::string Parser::remaining_text() {
- if (m_ts == nullptr)
+ if (text_stream_ == nullptr)
return "";
- return m_ts->remaining_text();
+ return text_stream_->remaining_text();
}
}
=== modified file 'src/graphic/text/rt_parse.h'
--- src/graphic/text/rt_parse.h 2014-09-14 11:31:58 +0000
+++ src/graphic/text/rt_parse.h 2016-03-17 17:18:59 +0000
@@ -49,7 +49,7 @@
RGBColor get_color() const;
private:
- const std::string m_name, m_value;
+ const std::string name_, value_;
};
// This is basically a map<string, Attr>.
@@ -65,12 +65,12 @@
bool has(const std::string& name) const;
private:
- std::map<std::string, std::unique_ptr<Attr>> m_attrs;
+ std::map<std::string, std::unique_ptr<Attr>> attrs_;
};
struct TagConstraint {
std::unordered_set<std::string> allowed_attrs;
- std::unordered_set<std::string> allowed_childs;
+ std::unordered_set<std::string> allowed_children;
bool text_allowed;
bool has_closing_tag;
};
@@ -85,18 +85,18 @@
const std::string & name() const;
const AttrMap & attrs() const;
- const ChildList & childs() const;
+ const ChildList & children() const;
void parse(TextStream& ts, TagConstraints& tcs, const TagSet&);
private:
- void m_parse_opening_tag(TextStream & ts, TagConstraints & tcs);
- void m_parse_closing_tag(TextStream & ts);
- void m_parse_attribute(TextStream & ts, std::unordered_set<std::string> &);
- void m_parse_content(TextStream & ts, TagConstraints & tc, const TagSet &);
+ void parse_opening_tag(TextStream & ts, TagConstraints & tcs);
+ void parse_closing_tag(TextStream & ts);
+ void parse_attribute(TextStream & ts, std::unordered_set<std::string> &);
+ void parse_content(TextStream & ts, TagConstraints & tc, const TagSet &);
- std::string m_name;
- AttrMap m_am;
- ChildList m_childs;
+ std::string name_;
+ AttrMap attribute_map_;
+ ChildList children_;
};
struct Child {
@@ -122,8 +122,8 @@
std::string remaining_text();
private:
- TagConstraints m_tcs;
- std::unique_ptr<TextStream> m_ts;
+ TagConstraints tag_constraints_;
+ std::unique_ptr<TextStream> text_stream_;
};
}
=== modified file 'src/graphic/text/rt_render.cc'
--- src/graphic/text/rt_render.cc 2016-02-14 14:16:26 +0000
+++ src/graphic/text/rt_render.cc 2016-03-17 17:18:59 +0000
@@ -96,13 +96,13 @@
using FontMap = map<FontDescr, IFont*>;
using FontMapPair = pair<const FontDescr, std::unique_ptr<IFont>>;
- FontMap m_fontmap;
+ FontMap fontmap_;
DISALLOW_COPY_AND_ASSIGN(FontCache);
};
FontCache::~FontCache() {
- for (FontMap::reference& entry : m_fontmap) {
+ for (FontMap::reference& entry : fontmap_) {
delete entry.second;
}
}
@@ -154,8 +154,8 @@
uint16_t font_size = ns->font_size + ns->fontset->size_offset();
FontDescr fd = {ns->font_face, font_size};
- FontMap::iterator i = m_fontmap.find(fd);
- if (i != m_fontmap.end())
+ FontMap::iterator i = fontmap_.find(fd);
+ if (i != fontmap_.end())
return *i->second;
std::unique_ptr<IFont> font;
@@ -167,7 +167,7 @@
}
assert(font != nullptr);
- return *m_fontmap.insert(std::make_pair(fd, font.release())).first->second;
+ return *fontmap_.insert(std::make_pair(fd, font.release())).first->second;
}
struct Reference {
@@ -177,18 +177,18 @@
class RefMap : public IRefMap {
public:
- RefMap(const vector<Reference>& refs) : m_refs(refs) {}
+ RefMap(const vector<Reference>& refs) : refs_(refs) {}
string query(int16_t x, int16_t y) override {
// Should this linear algorithm proof to be too slow (doubtful), the
// RefMap could also be efficiently implemented using an R-Tree
- for (const Reference& c : m_refs)
+ for (const Reference& c : refs_)
if (c.dim.contains(Point(x, y)))
return c.ref;
return "";
}
private:
- vector<Reference> m_refs;
+ vector<Reference> refs_;
};
class RenderNode {
@@ -199,7 +199,7 @@
FLOAT_LEFT,
};
RenderNode(NodeStyle& ns)
- : m_floating(NO_FLOAT), m_halign(ns.halign), m_valign(ns.valign), m_x(0), m_y(0) {}
+ : floating_(NO_FLOAT), halign_(ns.halign), valign_(ns.valign), x_(0), y_(0) {}
virtual ~RenderNode() {}
virtual uint16_t width() = 0;
@@ -209,34 +209,34 @@
virtual bool is_non_mandatory_space() {return false;}
virtual bool is_expanding() {return false;}
- virtual void set_w(uint16_t) {} // Only, when expanding
+ virtual void set_w(uint16_t) {} // Only, when is_expanding
virtual const vector<Reference> get_references() {return vector<Reference>();}
- Floating get_floating() {return m_floating;}
- void set_floating(Floating f) {m_floating = f;}
- UI::Align halign() {return m_halign;}
- void set_halign(UI::Align ghalign) {m_halign = ghalign;}
- UI::Align valign() {return m_valign;}
- void set_valign(UI::Align gvalign) {m_valign = gvalign;}
- void set_x(int32_t nx) {m_x = nx;}
- void set_y(int32_t ny) {m_y = ny;}
- int32_t x() {return m_x;}
- int32_t y() {return m_y;}
+ Floating get_floating() {return floating_;}
+ void set_floating(Floating f) {floating_ = f;}
+ UI::Align halign() {return halign_;}
+ void set_halign(UI::Align ghalign) {halign_ = ghalign;}
+ UI::Align valign() {return valign_;}
+ void set_valign(UI::Align gvalign) {valign_ = gvalign;}
+ void set_x(int32_t nx) {x_ = nx;}
+ void set_y(int32_t ny) {y_ = ny;}
+ int32_t x() {return x_;}
+ int32_t y() {return y_;}
private:
- Floating m_floating;
- UI::Align m_halign;
- UI::Align m_valign;
- int32_t m_x, m_y;
+ Floating floating_;
+ UI::Align halign_;
+ UI::Align valign_;
+ int32_t x_, y_;
};
class Layout {
public:
- Layout(vector<RenderNode*>& all) : m_h(0), m_idx(0), m_all_nodes(all) {}
+ Layout(vector<RenderNode*>& all) : h_(0), idx_(0), all_nodes_(all) {}
virtual ~Layout() {}
- uint16_t height() {return m_h;}
+ uint16_t height() {return h_;}
uint16_t fit_nodes(vector<RenderNode*>& rv, uint16_t w, Borders p, bool shrink_to_fit);
private:
@@ -253,33 +253,33 @@
}
};
- uint16_t m_fit_line(uint16_t w, const Borders&, vector<RenderNode*>* rv, bool shrink_to_fit);
+ uint16_t fit_line(uint16_t w, const Borders&, vector<RenderNode*>* rv, bool shrink_to_fit);
- uint16_t m_h;
- size_t m_idx;
- vector<RenderNode*>& m_all_nodes;
- priority_queue<ConstraintChange> m_constraint_changes;
+ uint16_t h_;
+ size_t idx_;
+ vector<RenderNode*>& all_nodes_;
+ priority_queue<ConstraintChange> constraint_changes_;
};
-uint16_t Layout::m_fit_line(uint16_t w, const Borders& p, vector<RenderNode*>* rv, bool shrink_to_fit) {
+uint16_t Layout::fit_line(uint16_t w, const Borders& p, vector<RenderNode*>* rv, bool shrink_to_fit) {
assert(rv->empty());
// Remove leading spaces
- while (m_idx < m_all_nodes.size()
- && m_all_nodes[m_idx]->is_non_mandatory_space()
+ while (idx_ < all_nodes_.size()
+ && all_nodes_[idx_]->is_non_mandatory_space()
&& shrink_to_fit) {
- delete m_all_nodes[m_idx++];
+ delete all_nodes_[idx_++];
}
uint16_t x = p.left;
- std::size_t first_m_idx = m_idx;
+ std::size_t first_idx = idx_;
// Calc fitting nodes
- while (m_idx < m_all_nodes.size()) {
- RenderNode* n = m_all_nodes[m_idx];
+ while (idx_ < all_nodes_.size()) {
+ RenderNode* n = all_nodes_[idx_];
uint16_t nw = n->width();
if (x + nw + p.right > w || n->get_floating() != RenderNode::NO_FLOAT) {
- if (m_idx == first_m_idx) {
+ if (idx_ == first_idx) {
nw = w - p.right - x;
} else {
break;
@@ -287,7 +287,7 @@
}
n->set_x(x); x += nw;
rv->push_back(n);
- ++m_idx;
+ ++idx_;
}
// Remove trailing spaces
while (!rv->empty()
@@ -299,9 +299,9 @@
}
// Remaining space in this line
- uint16_t rem_space = 0;
+ uint16_t remaining_space = 0;
if (w < INFINITE_WIDTH) {
- rem_space = w - p.right - x;
+ remaining_space = w - p.right - x;
}
// Find expanding nodes
@@ -311,7 +311,7 @@
expanding_nodes.push_back(idx);
if (!expanding_nodes.empty()) { // If there are expanding nodes, we fill the space
- const uint16_t individual_w = rem_space / expanding_nodes.size();
+ const uint16_t individual_w = remaining_space / expanding_nodes.size();
for (const size_t idx : expanding_nodes) {
rv->at(idx)->set_w(individual_w);
for (size_t nidx = idx + 1; nidx < rv->size(); ++nidx)
@@ -321,10 +321,10 @@
// Take last elements style in this line and check horizontal alignment
if (!rv->empty() && (*rv->rbegin())->halign() != UI::Align::kLeft) {
if ((*rv->rbegin())->halign() == UI::Align::kCenter) {
- rem_space /= 2; // Otherwise, we align right
+ remaining_space /= 2; // Otherwise, we align right
}
for (RenderNode* node : *rv) {
- node->set_x(node->x() + rem_space);
+ node->set_x(node->x() + remaining_space);
}
}
}
@@ -343,20 +343,20 @@
*/
uint16_t Layout::fit_nodes(vector<RenderNode*>& rv, uint16_t w, Borders p, bool shrink_to_fit) {
assert(rv.empty());
- m_h = p.top;
+ h_ = p.top;
uint16_t max_line_width = 0;
- while (m_idx < m_all_nodes.size()) {
+ while (idx_ < all_nodes_.size()) {
vector<RenderNode*> nodes_in_line;
- size_t m_idx_before_iteration = m_idx;
- uint16_t biggest_hotspot = m_fit_line(w, p, &nodes_in_line, shrink_to_fit);
+ size_t idx_before_iteration_ = idx_;
+ uint16_t biggest_hotspot = fit_line(w, p, &nodes_in_line, shrink_to_fit);
int line_height = 0;
int line_start = INFINITE_WIDTH;
// Compute real line height and width, taking into account alignement
for (RenderNode* n : nodes_in_line) {
line_height = max(line_height, biggest_hotspot - n->hotspot_y() + n->height());
- n->set_y(m_h + biggest_hotspot - n->hotspot_y());
+ n->set_y(h_ + biggest_hotspot - n->hotspot_y());
if (line_start >= INFINITE_WIDTH || n->x() < line_start) {
line_start = n->x() - p.left;
}
@@ -379,18 +379,18 @@
}
rv.insert(rv.end(), nodes_in_line.begin(), nodes_in_line.end());
- m_h += line_height;
- while (! m_constraint_changes.empty() && m_constraint_changes.top().at_y <= m_h) {
- const ConstraintChange& top = m_constraint_changes.top();
+ h_ += line_height;
+ while (! constraint_changes_.empty() && constraint_changes_.top().at_y <= h_) {
+ const ConstraintChange& top = constraint_changes_.top();
w += top.delta_w;
p.left += top.delta_offset_x;
- m_constraint_changes.pop();
+ constraint_changes_.pop();
}
- if ((m_idx < m_all_nodes.size()) && m_all_nodes[m_idx]->get_floating()) {
- RenderNode* n = m_all_nodes[m_idx];
- n->set_y(m_h);
- ConstraintChange cc = {m_h + n->height(), 0, 0};
+ if ((idx_ < all_nodes_.size()) && all_nodes_[idx_]->get_floating()) {
+ RenderNode* n = all_nodes_[idx_];
+ n->set_y(h_);
+ ConstraintChange cc = {h_ + n->height(), 0, 0};
if (n->get_floating() == RenderNode::FLOAT_LEFT) {
n->set_x(p.left);
p.left += n->width();
@@ -402,16 +402,16 @@
cc.delta_w = n->width();
max_line_width = max(max_line_width, w);
}
- m_constraint_changes.push(cc);
+ constraint_changes_.push(cc);
rv.push_back(n);
- ++m_idx;
+ ++idx_;
}
- if (m_idx == m_idx_before_iteration) {
+ if (idx_ == idx_before_iteration_) {
throw WidthTooSmall("Could not fit a single render node in line. Width of an Element is too small!");
}
}
- m_h += p.bottom;
+ h_ += p.bottom;
return max_line_width;
}
@@ -423,13 +423,13 @@
TextNode(FontCache& font, NodeStyle&, const string& txt);
virtual ~TextNode() {}
- uint16_t width() override {return m_w;}
- uint16_t height() override {return m_h + m_s.spacing;}
+ uint16_t width() override {return w_;}
+ uint16_t height() override {return h_ + nodestyle_.spacing;}
uint16_t hotspot_y() override;
const vector<Reference> get_references() override {
vector<Reference> rv;
- if (!m_s.reference.empty()) {
- Reference r = {Rect(0, 0, m_w, m_h), m_s.reference};
+ if (!nodestyle_.reference.empty()) {
+ Reference r = {Rect(0, 0, w_, h_), nodestyle_.reference};
rv.push_back(r);
}
return rv;
@@ -438,25 +438,25 @@
Texture* render(TextureCache* texture_cache) override;
protected:
- uint16_t m_w, m_h;
- const string m_txt;
- NodeStyle m_s;
- FontCache& m_fontcache;
+ uint16_t w_, h_;
+ const string txt_;
+ NodeStyle nodestyle_;
+ FontCache& fontcache_;
SdlTtfFont& font_;
};
TextNode::TextNode(FontCache& font, NodeStyle& ns, const string& txt)
- : RenderNode(ns), m_txt(txt), m_s(ns), m_fontcache(font),
- font_(dynamic_cast<SdlTtfFont&>(m_fontcache.get_font(&m_s)))
+ : RenderNode(ns), txt_(txt), nodestyle_(ns), fontcache_(font),
+ font_(dynamic_cast<SdlTtfFont&>(fontcache_.get_font(&nodestyle_)))
{
- font_.dimensions(m_txt, ns.font_style, &m_w, &m_h);
+ font_.dimensions(txt_, ns.font_style, &w_, &h_);
}
uint16_t TextNode::hotspot_y() {
- return font_.ascent(m_s.font_style);
+ return font_.ascent(nodestyle_.font_style);
}
Texture* TextNode::render(TextureCache* texture_cache) {
- const Texture& img = font_.render(m_txt, m_s.font_color, m_s.font_style, texture_cache);
+ const Texture& img = font_.render(txt_, nodestyle_.font_color, nodestyle_.font_style, texture_cache);
Texture* rv = new Texture(img.width(), img.height());
rv->blit(Rect(0, 0, img.width(), img.height()),
img,
@@ -473,23 +473,23 @@
class FillingTextNode : public TextNode {
public:
FillingTextNode(FontCache& font, NodeStyle& ns, uint16_t w, const string& txt, bool expanding = false) :
- TextNode(font, ns, txt), m_expanding(expanding) {
- m_w = w;
+ TextNode(font, ns, txt), is_expanding_(expanding) {
+ w_ = w;
}
virtual ~FillingTextNode() {}
Texture* render(TextureCache*) override;
- bool is_expanding() override {return m_expanding;}
- void set_w(uint16_t w) override {m_w = w;}
+ bool is_expanding() override {return is_expanding_;}
+ void set_w(uint16_t w) override {w_ = w;}
private:
- bool m_expanding;
+ bool is_expanding_;
};
Texture* FillingTextNode::render(TextureCache* texture_cache) {
- const Texture& t = font_.render(m_txt, m_s.font_color, m_s.font_style, texture_cache);
- Texture* rv = new Texture(m_w, m_h);
- for (uint16_t curx = 0; curx < m_w; curx += t.width()) {
- Rect srcrect(Point(0, 0), min<int>(t.width(), m_w - curx), m_h);
+ const Texture& t = font_.render(txt_, nodestyle_.font_color, nodestyle_.font_style, texture_cache);
+ Texture* rv = new Texture(w_, h_);
+ for (uint16_t curx = 0; curx < w_; curx += t.width()) {
+ Rect srcrect(Point(0, 0), min<int>(t.width(), w_ - curx), h_);
rv->blit(Rect(curx, 0, srcrect.w, srcrect.h), t, srcrect, 1., BlendMode::Copy);
}
return rv;
@@ -502,12 +502,12 @@
class WordSpacerNode : public TextNode {
public:
WordSpacerNode(FontCache& font, NodeStyle& ns) : TextNode(font, ns, " ") {}
- static void show_spaces(bool t) {m_show_spaces = t;}
+ static void show_spaces(bool t) {show_spaces_ = t;}
Texture* render(TextureCache* texture_cache) override {
- if (m_show_spaces) {
- Texture* rv = new Texture(m_w, m_h);
- rv->fill_rect(Rect(0, 0, m_w, m_h), RGBAColor(0xcc, 0, 0, 0xcc));
+ if (show_spaces_) {
+ Texture* rv = new Texture(w_, h_);
+ rv->fill_rect(Rect(0, 0, w_, h_), RGBAColor(0xcc, 0, 0, 0xcc));
return rv;
}
return TextNode::render(texture_cache);
@@ -515,9 +515,9 @@
bool is_non_mandatory_space() override {return true;}
private:
- static bool m_show_spaces;
+ static bool show_spaces_;
};
-bool WordSpacerNode::m_show_spaces;
+bool WordSpacerNode::show_spaces_;
/*
* This is a forced newline that can either be inside the text from the user or
@@ -541,41 +541,41 @@
class SpaceNode : public RenderNode {
public:
SpaceNode(NodeStyle& ns, uint16_t w, uint16_t h = 0, bool expanding = false) :
- RenderNode(ns), m_w(w), m_h(h), m_bg(nullptr), m_expanding(expanding) {}
+ RenderNode(ns), w_(w), h_(h), background_image_(nullptr), is_expanding_(expanding) {}
- uint16_t height() override {return m_h;}
- uint16_t width() override {return m_w;}
- uint16_t hotspot_y() override {return m_h;}
+ uint16_t height() override {return h_;}
+ uint16_t width() override {return w_;}
+ uint16_t hotspot_y() override {return h_;}
Texture* render(TextureCache* /* texture_cache */) override {
- Texture* rv = new Texture(m_w, m_h);
+ Texture* rv = new Texture(w_, h_);
// Draw background image (tiling)
- if (m_bg) {
+ if (background_image_) {
Rect dst;
Rect srcrect(Point(0, 0), 1, 1);
- for (uint16_t curx = 0; curx < m_w; curx += m_bg->width()) {
+ for (uint16_t curx = 0; curx < w_; curx += background_image_->width()) {
dst.x = curx;
dst.y = 0;
- srcrect.w = dst.w = min<int>(m_bg->width(), m_w - curx);
- srcrect.h = dst.h = m_h;
- rv->blit(dst, *m_bg, srcrect, 1., BlendMode::Copy);
+ srcrect.w = dst.w = min<int>(background_image_->width(), w_ - curx);
+ srcrect.h = dst.h = h_;
+ rv->blit(dst, *background_image_, srcrect, 1., BlendMode::Copy);
}
} else {
- rv->fill_rect(Rect(0, 0, m_w, m_h), RGBAColor(255, 255, 255, 0));
+ rv->fill_rect(Rect(0, 0, w_, h_), RGBAColor(255, 255, 255, 0));
}
return rv;
}
- bool is_expanding() override {return m_expanding;}
- void set_w(uint16_t w) override {m_w = w;}
+ bool is_expanding() override {return is_expanding_;}
+ void set_w(uint16_t w) override {w_ = w;}
void set_background(const Image* s) {
- m_bg = s; m_h = s->height();
+ background_image_ = s; h_ = s->height();
}
private:
- uint16_t m_w, m_h;
- const Image* m_bg; // not owned
- bool m_expanding;
+ uint16_t w_, h_;
+ const Image* background_image_; // not owned
+ bool is_expanding_;
};
/*
@@ -584,17 +584,17 @@
class SubTagRenderNode : public RenderNode {
public:
SubTagRenderNode(NodeStyle& ns) : RenderNode(ns),
- m_bg_clr(0, 0, 0), m_bg_clr_set(false), m_bg_img(nullptr) {
+ background_color_(0, 0, 0), is_background_color_set_(false), background_image_(nullptr) {
}
virtual ~SubTagRenderNode() {
- for (RenderNode* n : m_nodes_to_render) {
+ for (RenderNode* n : nodes_to_render_) {
delete n;
}
- m_nodes_to_render.clear();
+ nodes_to_render_.clear();
}
- uint16_t width() override {return m_w + m_margin.left + m_margin.right;}
- uint16_t height() override {return m_h + m_margin.top + m_margin.bottom;}
+ uint16_t width() override {return w_ + margin_.left + margin_.right;}
+ uint16_t height() override {return h_ + margin_.top + margin_.bottom;}
uint16_t hotspot_y() override {return height();}
Texture* render(TextureCache* texture_cache) override {
@@ -603,33 +603,33 @@
// Draw Solid background Color
bool set_alpha = true;
- if (m_bg_clr_set) {
- rv->fill_rect(Rect(Point(m_margin.left, m_margin.top), m_w, m_h), m_bg_clr);
+ if (is_background_color_set_) {
+ rv->fill_rect(Rect(Point(margin_.left, margin_.top), w_, h_), background_color_);
set_alpha = false;
}
// Draw background image (tiling)
- if (m_bg_img) {
+ if (background_image_) {
Rect dst;
Rect src(0, 0, 0, 0);
- for (uint16_t cury = m_margin.top; cury < m_h + m_margin.top; cury += m_bg_img->height()) {
- for (uint16_t curx = m_margin.left; curx < m_w + m_margin.left; curx += m_bg_img->width()) {
+ for (uint16_t cury = margin_.top; cury < h_ + margin_.top; cury += background_image_->height()) {
+ for (uint16_t curx = margin_.left; curx < w_ + margin_.left; curx += background_image_->width()) {
dst.x = curx;
dst.y = cury;
- src.w = dst.w = min<int>(m_bg_img->width(), m_w + m_margin.left - curx);
- src.h = dst.h = min<int>(m_bg_img->height(), m_h + m_margin.top - cury);
- rv->blit(dst, *m_bg_img, src, 1., BlendMode::Copy);
+ src.w = dst.w = min<int>(background_image_->width(), w_ + margin_.left - curx);
+ src.h = dst.h = min<int>(background_image_->height(), h_ + margin_.top - cury);
+ rv->blit(dst, *background_image_, src, 1., BlendMode::Copy);
}
}
set_alpha = false;
}
- for (RenderNode* n : m_nodes_to_render) {
+ for (RenderNode* n : nodes_to_render_) {
Texture* node_texture = n->render(texture_cache);
if (node_texture) {
- Rect dst = Rect(n->x() + m_margin.left,
- n->y() + m_margin.top,
+ Rect dst = Rect(n->x() + margin_.left,
+ n->y() + margin_.top,
node_texture->width(),
node_texture->height());
Rect src = Rect(0, 0, node_texture->width(), node_texture->height());
@@ -640,54 +640,54 @@
delete n;
}
- m_nodes_to_render.clear();
+ nodes_to_render_.clear();
return rv;
}
- const vector<Reference> get_references() override {return m_refs;}
+ const vector<Reference> get_references() override {return refs_;}
void set_dimensions(uint16_t inner_w, uint16_t inner_h, Borders margin) {
- m_w = inner_w; m_h = inner_h; m_margin = margin;
+ w_ = inner_w; h_ = inner_h; margin_ = margin;
}
void set_background(RGBColor clr) {
- m_bg_clr = clr;
- m_bg_clr_set = true;
+ background_color_ = clr;
+ is_background_color_set_ = true;
}
- void set_background(const Image* img) {m_bg_img = img;}
- void set_nodes_to_render(vector<RenderNode*>& n) {m_nodes_to_render = n;}
+ void set_background(const Image* img) {background_image_ = img;}
+ void set_nodes_to_render(vector<RenderNode*>& n) {nodes_to_render_ = n;}
void add_reference(int16_t gx, int16_t gy, uint16_t w, uint16_t h, const string& s) {
Reference r = {Rect(gx, gy, w, h), s};
- m_refs.push_back(r);
+ refs_.push_back(r);
}
private:
- uint16_t m_w, m_h;
- vector<RenderNode*> m_nodes_to_render;
- Borders m_margin;
- RGBColor m_bg_clr;
- bool m_bg_clr_set;
- const Image* m_bg_img; // Not owned.
- vector<Reference> m_refs;
+ uint16_t w_, h_;
+ vector<RenderNode*> nodes_to_render_;
+ Borders margin_;
+ RGBColor background_color_;
+ bool is_background_color_set_;
+ const Image* background_image_; // Not owned.
+ vector<Reference> refs_;
};
class ImgRenderNode : public RenderNode {
public:
- ImgRenderNode(NodeStyle& ns, const Image& image) : RenderNode(ns), m_image(image) {
+ ImgRenderNode(NodeStyle& ns, const Image& image) : RenderNode(ns), image_(image) {
}
- uint16_t width() override {return m_image.width();}
- uint16_t height() override {return m_image.height();}
- uint16_t hotspot_y() override {return m_image.height();}
+ uint16_t width() override {return image_.width();}
+ uint16_t height() override {return image_.height();}
+ uint16_t hotspot_y() override {return image_.height();}
Texture* render(TextureCache* texture_cache) override;
private:
- const Image& m_image;
+ const Image& image_;
};
Texture* ImgRenderNode::render(TextureCache* /* texture_cache */) {
- Texture* rv = new Texture(m_image.width(), m_image.height());
- rv->blit(Rect(0, 0, m_image.width(), m_image.height()),
- m_image,
- Rect(0, 0, m_image.width(), m_image.height()),
+ Texture* rv = new Texture(image_.width(), image_.height());
+ rv->blit(Rect(0, 0, image_.width(), image_.height()),
+ image_,
+ Rect(0, 0, image_.width(), image_.height()),
1.,
BlendMode::Copy);
return rv;
@@ -702,27 +702,27 @@
class TagHandler {
public:
TagHandler(Tag& tag, FontCache& fc, NodeStyle ns, ImageCache* image_cache,
- RendererStyle& renderer_style_, const UI::FontSets& fontsets) :
- m_tag(tag), font_cache_(fc), m_ns(ns), image_cache_(image_cache),
- renderer_style(renderer_style_), fontsets_(fontsets) {}
+ RendererStyle& renderer_style, const UI::FontSets& fontsets) :
+ tag_(tag), font_cache_(fc), nodestyle_(ns), image_cache_(image_cache),
+ renderer_style_(renderer_style), fontsets_(fontsets) {}
virtual ~TagHandler() {}
virtual void enter() {}
- virtual void emit(vector<RenderNode*>&);
+ virtual void emit_nodes(vector<RenderNode*>&);
private:
- void m_make_text_nodes(const string& txt, vector<RenderNode*>& nodes, NodeStyle& ns);
+ void make_text_nodes(const string& txt, vector<RenderNode*>& nodes, NodeStyle& ns);
protected:
- Tag& m_tag;
+ Tag& tag_;
FontCache& font_cache_;
- NodeStyle m_ns;
+ NodeStyle nodestyle_;
ImageCache* image_cache_; // Not owned
- RendererStyle& renderer_style; // Reference to global renderer style in the renderer
+ RendererStyle& renderer_style_; // Reference to global renderer style in the renderer
const UI::FontSets& fontsets_;
};
-void TagHandler::m_make_text_nodes(const string& txt, vector<RenderNode*>& nodes, NodeStyle& ns) {
+void TagHandler::make_text_nodes(const string& txt, vector<RenderNode*>& nodes, NodeStyle& ns) {
TextStream ts(txt);
std::string word;
std::vector<RenderNode*> text_nodes;
@@ -804,15 +804,15 @@
}
}
-void TagHandler::emit(vector<RenderNode*>& nodes) {
- for (Child* c : m_tag.childs()) {
+void TagHandler::emit_nodes(vector<RenderNode*>& nodes) {
+ for (Child* c : tag_.children()) {
if (c->tag) {
- std::unique_ptr<TagHandler> th(create_taghandler(*c->tag, font_cache_, m_ns, image_cache_,
- renderer_style, fontsets_));
+ std::unique_ptr<TagHandler> th(create_taghandler(*c->tag, font_cache_, nodestyle_, image_cache_,
+ renderer_style_, fontsets_));
th->enter();
- th->emit(nodes);
+ th->emit_nodes(nodes);
} else
- m_make_text_nodes(c->text, nodes, m_ns);
+ make_text_nodes(c->text, nodes, nodestyle_);
}
}
@@ -823,15 +823,15 @@
: TagHandler(tag, fc, ns, image_cache, init_renderer_style, fontsets) {}
void enter() override {
- const AttrMap& a = m_tag.attrs();
- if (a.has("color")) m_ns.font_color = a["color"].get_color();
- if (a.has("size")) m_ns.font_size = a["size"].get_int();
- if (a.has("face")) m_ns.font_face = a["face"].get_string();
- if (a.has("bold")) m_ns.font_style |= a["bold"].get_bool() ? IFont::BOLD : 0;
- if (a.has("italic")) m_ns.font_style |= a["italic"].get_bool() ? IFont::ITALIC : 0;
- if (a.has("underline")) m_ns.font_style |= a["underline"].get_bool() ? IFont::UNDERLINE : 0;
- if (a.has("shadow")) m_ns.font_style |= a["shadow"].get_bool() ? IFont::SHADOW : 0;
- if (a.has("ref")) m_ns.reference = a["ref"].get_string();
+ const AttrMap& a = tag_.attrs();
+ if (a.has("color")) nodestyle_.font_color = a["color"].get_color();
+ if (a.has("size")) nodestyle_.font_size = a["size"].get_int();
+ if (a.has("face")) nodestyle_.font_face = a["face"].get_string();
+ if (a.has("bold")) nodestyle_.font_style |= a["bold"].get_bool() ? IFont::BOLD : 0;
+ if (a.has("italic")) nodestyle_.font_style |= a["italic"].get_bool() ? IFont::ITALIC : 0;
+ if (a.has("underline")) nodestyle_.font_style |= a["underline"].get_bool() ? IFont::UNDERLINE : 0;
+ if (a.has("shadow")) nodestyle_.font_style |= a["shadow"].get_bool() ? IFont::SHADOW : 0;
+ if (a.has("ref")) nodestyle_.reference = a["ref"].get_string();
}
};
@@ -839,140 +839,142 @@
public:
PTagHandler(Tag& tag, FontCache& fc, NodeStyle ns, ImageCache* image_cache,
RendererStyle& init_renderer_style, const UI::FontSets& fontsets)
- : TagHandler(tag, fc, ns, image_cache, init_renderer_style, fontsets), m_indent(0) {
+ : TagHandler(tag, fc, ns, image_cache, init_renderer_style, fontsets), indent_(0) {
}
void enter() override {
- const AttrMap& a = m_tag.attrs();
- if (a.has("indent")) m_indent = a["indent"].get_int();
+ const AttrMap& a = tag_.attrs();
+ if (a.has("indent")) indent_ = a["indent"].get_int();
if (a.has("align")) {
const std::string align = a["align"].get_string();
if (align == "right") {
- m_ns.halign = UI::Align::kRight;
+ nodestyle_.halign = UI::Align::kRight;
} else if (align == "center" || align == "middle") {
- m_ns.halign = UI::Align::kCenter;
+ nodestyle_.halign = UI::Align::kCenter;
} else {
- m_ns.halign = UI::Align::kLeft;
+ nodestyle_.halign = UI::Align::kLeft;
}
}
- m_ns.halign = mirror_alignment(m_ns.halign);
+ nodestyle_.halign = mirror_alignment(nodestyle_.halign);
if (a.has("valign")) {
const string align = a["valign"].get_string();
if (align == "bottom") {
- m_ns.valign = UI::Align::kBottom;
+ nodestyle_.valign = UI::Align::kBottom;
} else if (align == "center" || align == "middle") {
- m_ns.valign = UI::Align::kCenter;
+ nodestyle_.valign = UI::Align::kCenter;
} else {
- m_ns.valign = UI::Align::kTop;
+ nodestyle_.valign = UI::Align::kTop;
}
}
if (a.has("spacing"))
- m_ns.spacing = a["spacing"].get_int();
+ nodestyle_.spacing = a["spacing"].get_int();
}
- void emit(vector<RenderNode*>& nodes) override {
+ void emit_nodes(vector<RenderNode*>& nodes) override {
// Put a newline if this is not the first paragraph
if (!nodes.empty()) {
- nodes.push_back(new NewlineNode(m_ns));
- }
- if (m_indent) {
- nodes.push_back(new SpaceNode(m_ns, m_indent));
- }
- TagHandler::emit(nodes);
+ nodes.push_back(new NewlineNode(nodestyle_));
+ }
+ if (indent_) {
+ nodes.push_back(new SpaceNode(nodestyle_, indent_));
+ }
+ TagHandler::emit_nodes(nodes);
}
private:
- uint16_t m_indent;
+ uint16_t indent_;
};
class ImgTagHandler : public TagHandler {
public:
ImgTagHandler(Tag& tag, FontCache& fc, NodeStyle ns, ImageCache* image_cache,
RendererStyle& init_renderer_style, const UI::FontSets& fontsets) :
- TagHandler(tag, fc, ns, image_cache, init_renderer_style, fontsets), m_rn(nullptr) {
+ TagHandler(tag, fc, ns, image_cache, init_renderer_style, fontsets), render_node_(nullptr) {
}
void enter() override {
- const AttrMap& a = m_tag.attrs();
- m_rn = new ImgRenderNode(m_ns, *image_cache_->get(a["src"].get_string()));
+ const AttrMap& a = tag_.attrs();
+ render_node_ = new ImgRenderNode(nodestyle_, *image_cache_->get(a["src"].get_string()));
}
- void emit(vector<RenderNode*>& nodes) override {
- nodes.push_back(m_rn);
+ void emit_nodes(vector<RenderNode*>& nodes) override {
+ nodes.push_back(render_node_);
}
private:
- ImgRenderNode* m_rn;
+ ImgRenderNode* render_node_;
};
class VspaceTagHandler : public TagHandler {
public:
VspaceTagHandler(Tag& tag, FontCache& fc, NodeStyle ns, ImageCache* image_cache,
RendererStyle& init_renderer_style, const UI::FontSets& fontsets) :
- TagHandler(tag, fc, ns, image_cache, init_renderer_style, fontsets), m_space(0) {}
+ TagHandler(tag, fc, ns, image_cache, init_renderer_style, fontsets), space_(0) {}
void enter() override {
- const AttrMap& a = m_tag.attrs();
+ const AttrMap& a = tag_.attrs();
- m_space = a["gap"].get_int();
+ space_ = a["gap"].get_int();
}
- void emit(vector<RenderNode*>& nodes) override {
- nodes.push_back(new SpaceNode(m_ns, 0, m_space));
- nodes.push_back(new NewlineNode(m_ns));
+ void emit_nodes(vector<RenderNode*>& nodes) override {
+ nodes.push_back(new SpaceNode(nodestyle_, 0, space_));
+ nodes.push_back(new NewlineNode(nodestyle_));
}
private:
- uint16_t m_space;
+ uint16_t space_;
};
class HspaceTagHandler : public TagHandler {
public:
HspaceTagHandler(Tag& tag, FontCache& fc, NodeStyle ns, ImageCache* image_cache,
RendererStyle& init_renderer_style, const UI::FontSets& fontsets) :
- TagHandler(tag, fc, ns, image_cache, init_renderer_style, fontsets), m_bg(nullptr), m_space(0) {}
+ TagHandler(tag, fc, ns, image_cache, init_renderer_style, fontsets),
+ background_image_(nullptr),
+ space_(0) {}
void enter() override {
- const AttrMap& a = m_tag.attrs();
+ const AttrMap& a = tag_.attrs();
if (a.has("gap"))
- m_space = a["gap"].get_int();
+ space_ = a["gap"].get_int();
else
- m_space = INFINITE_WIDTH;
+ space_ = INFINITE_WIDTH;
if (a.has("fill")) {
- m_fill_text = a["fill"].get_string();
+ fill_text_ = a["fill"].get_string();
try {
- m_bg = image_cache_->get(m_fill_text);
- m_fill_text = "";
+ background_image_ = image_cache_->get(fill_text_);
+ fill_text_ = "";
}
catch (ImageNotFound&) {
}
}
}
- void emit(vector<RenderNode*>& nodes) override {
+ void emit_nodes(vector<RenderNode*>& nodes) override {
RenderNode* rn = nullptr;
- if (!m_fill_text.empty()) {
- if (m_space < INFINITE_WIDTH)
- rn = new FillingTextNode(font_cache_, m_ns, m_space, m_fill_text);
+ if (!fill_text_.empty()) {
+ if (space_ < INFINITE_WIDTH)
+ rn = new FillingTextNode(font_cache_, nodestyle_, space_, fill_text_);
else
- rn = new FillingTextNode(font_cache_, m_ns, 0, m_fill_text, true);
+ rn = new FillingTextNode(font_cache_, nodestyle_, 0, fill_text_, true);
} else {
SpaceNode* sn;
- if (m_space < INFINITE_WIDTH)
- sn = new SpaceNode(m_ns, m_space, 0);
+ if (space_ < INFINITE_WIDTH)
+ sn = new SpaceNode(nodestyle_, space_, 0);
else
- sn = new SpaceNode(m_ns, 0, 0, true);
+ sn = new SpaceNode(nodestyle_, 0, 0, true);
- if (m_bg)
- sn->set_background(m_bg);
+ if (background_image_)
+ sn->set_background(background_image_);
rn = sn;
}
nodes.push_back(rn);
}
private:
- string m_fill_text;
- const Image* m_bg;
- uint16_t m_space;
+ string fill_text_;
+ const Image* background_image_;
+ uint16_t space_;
};
class BrTagHandler : public TagHandler {
@@ -982,8 +984,8 @@
TagHandler(tag, fc, ns, image_cache, init_renderer_style, fontsets) {
}
- void emit(vector<RenderNode*>& nodes) override {
- nodes.push_back(new NewlineNode(m_ns));
+ void emit_nodes(vector<RenderNode*>& nodes) override {
+ nodes.push_back(new NewlineNode(nodestyle_));
}
};
@@ -997,8 +999,8 @@
:
TagHandler(tag, fc, ns, image_cache, init_renderer_style, fontsets),
shrink_to_fit_(shrink_to_fit),
- m_w(max_w),
- m_rn(new SubTagRenderNode(ns))
+ w_(max_w),
+ render_node_(new SubTagRenderNode(ns))
{
}
@@ -1006,14 +1008,14 @@
Borders padding, margin;
handle_unique_attributes();
- const AttrMap& a = m_tag.attrs();
+ const AttrMap& a = tag_.attrs();
if (a.has("background")) {
RGBColor clr;
try {
clr = a["background"].get_color();
- m_rn->set_background(clr);
+ render_node_->set_background(clr);
} catch (InvalidColor&) {
- m_rn->set_background(image_cache_->get(a["background"].get_string()));
+ render_node_->set_background(image_cache_->get(a["background"].get_string()));
}
}
if (a.has("padding")) {
@@ -1030,89 +1032,89 @@
}
vector<RenderNode*> subnodes;
- TagHandler::emit(subnodes);
+ TagHandler::emit_nodes(subnodes);
- if (! m_w) { // Determine the width by the width of the widest subnode
+ if (! w_) { // Determine the width by the width of the widest subnode
for (RenderNode* n : subnodes) {
if (n->width() >= INFINITE_WIDTH)
continue;
- m_w = max<int>(m_w, n->width() + padding.left + padding.right);
+ w_ = max<int>(w_, n->width() + padding.left + padding.right);
}
}
// Layout takes ownership of subnodes
Layout layout(subnodes);
vector<RenderNode*> nodes_to_render;
- uint16_t max_line_width = layout.fit_nodes(nodes_to_render, m_w, padding, shrink_to_fit_);
- uint16_t m_extra_width = 0;
- if (m_w < INFINITE_WIDTH && m_w > max_line_width) {
- m_extra_width = m_w - max_line_width;
+ uint16_t max_line_width = layout.fit_nodes(nodes_to_render, w_, padding, shrink_to_fit_);
+ uint16_t extra_width = 0;
+ if (w_ < INFINITE_WIDTH && w_ > max_line_width) {
+ extra_width = w_ - max_line_width;
}
// Collect all tags from children
for (RenderNode* rn : nodes_to_render) {
for (const Reference& r : rn->get_references()) {
- m_rn->add_reference(rn->x() + r.dim.x, rn->y() + r.dim.y, r.dim.w, r.dim.h, r.ref);
+ render_node_->add_reference(rn->x() + r.dim.x, rn->y() + r.dim.y, r.dim.w, r.dim.h, r.ref);
}
if (shrink_to_fit_) {
if (rn->halign() == UI::Align::kCenter) {
- rn->set_x(rn->x() - m_extra_width / 2);
+ rn->set_x(rn->x() - extra_width / 2);
} else if (rn->halign() == UI::Align::kRight) {
- rn->set_x(rn->x() - m_extra_width);
+ rn->set_x(rn->x() - extra_width);
}
}
}
- if (shrink_to_fit_ || m_w >= INFINITE_WIDTH) {
- m_w = max_line_width;
+ if (shrink_to_fit_ || w_ >= INFINITE_WIDTH) {
+ w_ = max_line_width;
}
- if (renderer_style.remaining_width >= m_w) {
- renderer_style.remaining_width -= m_w;
+ if (renderer_style_.remaining_width >= w_) {
+ renderer_style_.remaining_width -= w_;
} else {
- renderer_style.remaining_width = renderer_style.overall_width;
+ renderer_style_.remaining_width = renderer_style_.overall_width;
}
- m_rn->set_dimensions(m_w, layout.height(), margin);
- m_rn->set_nodes_to_render(nodes_to_render);
+ render_node_->set_dimensions(w_, layout.height(), margin);
+ render_node_->set_nodes_to_render(nodes_to_render);
}
- void emit(vector<RenderNode*>& nodes) override {
- nodes.push_back(m_rn);
+ void emit_nodes(vector<RenderNode*>& nodes) override {
+ nodes.push_back(render_node_);
}
// Handle attributes that are in sub, but not in rt.
virtual void handle_unique_attributes() {
- const AttrMap& a = m_tag.attrs();
+ const AttrMap& a = tag_.attrs();
if (a.has("width")) {
std::string width_string = a["width"].get_string();
if (width_string == "*") {
- m_w = renderer_style.remaining_width;
+ w_ = renderer_style_.remaining_width;
} else if (boost::algorithm::ends_with(width_string, "%")) {
width_string = width_string.substr(0, width_string.length() - 1);
uint8_t new_width_percent = strtol(width_string.c_str(), nullptr, 10);
- m_w = floor(renderer_style.overall_width * new_width_percent / 100);
- m_w = std::min(m_w, renderer_style.remaining_width);
+ w_ = floor(renderer_style_.overall_width * new_width_percent / 100);
+ w_ = std::min(w_, renderer_style_.remaining_width);
} else {
- m_w = a["width"].get_int();
+ w_ = a["width"].get_int();
}
shrink_to_fit_ = false;
}
if (a.has("float")) {
const string s = a["float"].get_string();
- if (s == "right") m_rn->set_floating(RenderNode::FLOAT_RIGHT);
- else if (s == "left") m_rn->set_floating(RenderNode::FLOAT_LEFT);
+ if (s == "right") render_node_->set_floating(RenderNode::FLOAT_RIGHT);
+ else if (s == "left") render_node_->set_floating(RenderNode::FLOAT_LEFT);
}
if (a.has("valign")) {
const string align = a["valign"].get_string();
- if (align == "top") m_rn->set_valign(UI::Align::kTop);
- else if (align == "bottom") m_rn->set_valign(UI::Align::kBottom);
- else if (align == "center" || align == "middle") m_rn->set_valign(UI::Align::kCenter);
+ if (align == "top") render_node_->set_valign(UI::Align::kTop);
+ else if (align == "bottom") render_node_->set_valign(UI::Align::kBottom);
+ else if (align == "center" || align == "middle") render_node_->set_valign(UI::Align::kCenter);
}
}
protected:
bool shrink_to_fit_;
private:
- uint16_t m_w;
- SubTagRenderNode* m_rn;
+ uint16_t w_;
+ SubTagRenderNode* render_node_;
};
class RTTagHandler : public SubTagHandler {
@@ -1124,7 +1126,7 @@
// Handle attributes that are in rt, but not in sub.
void handle_unique_attributes() override {
- const AttrMap& a = m_tag.attrs();
+ const AttrMap& a = tag_.attrs();
WordSpacerNode::show_spaces(a.has("db_show_spaces") ? a["db_show_spaces"].get_bool() : 0);
shrink_to_fit_ = shrink_to_fit_ && (a.has("keep_spaces") ? !a["keep_spaces"].get_bool() : true);
}
@@ -1193,7 +1195,7 @@
RTTagHandler rtrn(*rt, *font_cache_, default_style, image_cache_, renderer_style_, fontsets_, width);
vector<RenderNode*> nodes;
rtrn.enter();
- rtrn.emit(nodes);
+ rtrn.emit_nodes(nodes);
assert(nodes.size() == 1);
assert(nodes[0]);
=== modified file 'src/graphic/text/sdl_ttf_font.cc'
--- src/graphic/text/sdl_ttf_font.cc 2016-03-10 16:20:19 +0000
+++ src/graphic/text/sdl_ttf_font.cc 2016-03-17 17:18:59 +0000
@@ -44,7 +44,7 @@
}
void SdlTtfFont::dimensions(const std::string& txt, int style, uint16_t * gw, uint16_t * gh) {
- m_set_style(style);
+ set_style(style);
int w, h;
TTF_SizeUTF8(font_, txt.c_str(), &w, &h);
@@ -64,7 +64,7 @@
const Texture* rv = texture_cache->get(hash);
if (rv) return *rv;
- m_set_style(style);
+ set_style(style);
SDL_Surface * text_surface = nullptr;
@@ -127,7 +127,7 @@
return rv;
}
-void SdlTtfFont::m_set_style(int style) {
+void SdlTtfFont::set_style(int style) {
int sdl_style = TTF_STYLE_NORMAL;
if (style & UNDERLINE) sdl_style |= TTF_STYLE_UNDERLINE;
=== modified file 'src/graphic/text/sdl_ttf_font.h'
--- src/graphic/text/sdl_ttf_font.h 2016-02-14 11:39:28 +0000
+++ src/graphic/text/sdl_ttf_font.h 2016-03-17 17:18:59 +0000
@@ -67,7 +67,7 @@
uint16_t ascent(int) const override;
private:
- void m_set_style(int);
+ void set_style(int);
TTF_Font * font_;
int style_;
=== modified file 'src/graphic/text/textstream.cc'
--- src/graphic/text/textstream.cc 2016-02-21 12:06:39 +0000
+++ src/graphic/text/textstream.cc 2016-03-17 17:18:59 +0000
@@ -35,14 +35,14 @@
{}
};
-void TextStream::m_consume(size_t cnt) {
+void TextStream::consume(size_t cnt) {
while (cnt) {
- if (m_t[m_i] == '\n') {
- ++m_lineno;
- m_col = 0;
+ if (text_[pos_] == '\n') {
+ ++line_;
+ col_ = 0;
} else
- ++m_col;
- ++m_i;
+ ++col_;
+ ++pos_;
--cnt;
}
}
@@ -54,19 +54,19 @@
* r* means skip_ws starting from the back of the string
*/
void TextStream::skip_ws() {
- while (m_i < m_end && isspace(m_t[m_i]))
- m_consume(1);
+ while (pos_ < end_ && isspace(text_[pos_]))
+ consume(1);
}
void TextStream::rskip_ws() {
- while (m_i < m_end && isspace(m_t[m_end - 1]))
- --m_end;
+ while (pos_ < end_ && isspace(text_[end_ - 1]))
+ --end_;
}
/*
* Return the next few characters without advancing the stream
*/
string TextStream::peek(size_t n, size_t at) const {
- return m_t.substr(at > m_t.size() ? m_i : at, n);
+ return text_.substr(at > text_.size() ? pos_ : at, n);
}
/*
@@ -78,8 +78,8 @@
skip_ws();
if (peek(n.size()) != n)
- throw SyntaxErrorImpl(m_lineno, m_col, (format("'%s'") % n).str(), peek(n.size()), peek(100));
- m_consume(n.size());
+ throw SyntaxErrorImpl(line_, col_, (format("'%s'") % n).str(), peek(n.size()), peek(100));
+ consume(n.size());
}
/*
@@ -91,12 +91,12 @@
// Sticking with a double loop because chars will likely be short
string rv;
- size_t j = m_i;
- size_t started_at = m_i;
+ size_t j = pos_;
+ size_t started_at = pos_;
bool found = false;
- while (j < m_end) {
+ while (j < end_) {
for (size_t k = 0; k < chars.size(); ++k) {
- if (chars[k] == m_t[j]) {
+ if (chars[k] == text_[j]) {
found = true;
break;
}
@@ -105,7 +105,7 @@
// Get rid of control characters
// http://en.cppreference.com/w/cpp/language/escape
- switch (m_t[j]) {
+ switch (text_[j]) {
case '\a':
case '\b':
case '\f':
@@ -116,12 +116,12 @@
break;
}
- rv += m_t[j];
+ rv += text_[j];
++j;
}
if (!found)
throw EndOfTextImpl(started_at, peek(100, started_at));
- m_consume(j - started_at);
+ consume(j - started_at);
// Undo the extra \ that were inserted in Parser::parse to prevent crashes.
boost::replace_all(rv, "\\\\", "\\");
@@ -137,8 +137,8 @@
try {
rv = till_any(chars);
} catch (EndOfTextImpl &) {
- rv = m_t.substr(m_i, m_end - m_i);
- m_consume(m_end + 1 - m_i);
+ rv = text_.substr(pos_, end_ - pos_);
+ consume(end_ + 1 - pos_);
}
return rv;
}
@@ -149,9 +149,9 @@
string TextStream::parse_string() {
string delim = peek(1);
if (delim == "'" || delim == "\"") {
- m_consume(1);
+ consume(1);
string rv = till_any(delim);
- m_consume(1);
+ consume(1);
return rv;
} else
return till_any(" \t>");
@@ -161,7 +161,7 @@
* Return the text that is yet to be parsed
*/
string TextStream::remaining_text() {
- return m_t.substr(m_i, m_end - m_i);
+ return text_.substr(pos_, end_ - pos_);
}
}
=== modified file 'src/graphic/text/textstream.h'
--- src/graphic/text/textstream.h 2014-07-05 16:41:51 +0000
+++ src/graphic/text/textstream.h 2016-03-17 17:18:59 +0000
@@ -28,11 +28,11 @@
class TextStream {
public:
- TextStream(std::string text) : m_t(text), m_lineno(1), m_col(0), m_i(0), m_end(text.size()) {}
+ TextStream(std::string text) : text_(text), line_(1), col_(0), pos_(0), end_(text.size()) {}
- size_t line() const {return m_lineno;}
- size_t col() const {return m_col;}
- size_t pos() const {return m_i;}
+ size_t line() const {return line_;}
+ size_t col() const {return col_;}
+ size_t pos() const {return pos_;}
std::string peek(size_t, size_t = -1) const;
void expect(std::string, bool = true);
@@ -41,17 +41,17 @@
std::string till_any_or_end(std::string);
std::string parse_string();
- void skip(size_t d) {m_i += d;}
+ void skip(size_t d) {pos_ += d;}
void skip_ws();
void rskip_ws();
std::string remaining_text();
private:
- void m_consume(size_t);
- std::string m_t;
- uint32_t m_lineno, m_col;
- size_t m_i, m_end;
+ void consume(size_t);
+ std::string text_;
+ uint32_t line_, col_;
+ size_t pos_, end_;
};
}
=== modified file 'src/graphic/text_layout.cc'
--- src/graphic/text_layout.cc 2016-03-09 07:15:44 +0000
+++ src/graphic/text_layout.cc 2016-03-17 17:18:59 +0000
@@ -210,8 +210,8 @@
*/
void TextStyle::calc_bare_height_heuristic(const std::string & text, int32_t & miny, int32_t & maxy) const
{
- miny = font->m_computed_typical_miny;
- maxy = font->m_computed_typical_maxy;
+ miny = font->computed_typical_miny_;
+ maxy = font->computed_typical_maxy_;
setup();
std::string::size_type pos = 0;
=== modified file 'src/graphic/text_parser.cc'
--- src/graphic/text_parser.cc 2016-03-10 15:00:32 +0000
+++ src/graphic/text_parser.cc 2016-03-17 17:18:59 +0000
@@ -33,29 +33,29 @@
namespace UI {
RichtextBlock::RichtextBlock() :
- m_image_align(UI::Align::kLeft),
- m_text_align (UI::Align::kLeft)
+ image_align_(UI::Align::kLeft),
+ text_align_ (UI::Align::kLeft)
{}
RichtextBlock::RichtextBlock(const RichtextBlock & src) {
- m_images.clear();
- m_text_blocks.clear();
- for (uint32_t i = 0; i < src.m_images.size(); ++i)
- m_images.push_back(src.m_images[i]);
- for (uint32_t i = 0; i < src.m_text_blocks.size(); ++i)
- m_text_blocks.push_back(src.m_text_blocks[i]);
- m_image_align = src.m_image_align;
- m_text_align = src.m_text_align;
+ images_.clear();
+ text_blocks_.clear();
+ for (uint32_t i = 0; i < src.images_.size(); ++i)
+ images_.push_back(src.images_[i]);
+ for (uint32_t i = 0; i < src.text_blocks_.size(); ++i)
+ text_blocks_.push_back(src.text_blocks_[i]);
+ image_align_ = src.image_align_;
+ text_align_ = src.text_align_;
}
TextBlock::TextBlock() {
- m_font_size = 10;
- m_font_color = RGBColor(255, 255, 0);
- m_font_weight = "normal";
- m_font_style = "normal";
- m_font_decoration = "none";
- m_font_face = (UI::g_fh1->fontset())->sans();
- m_line_spacing = 0;
+ font_size_ = 10;
+ font_color_ = RGBColor(255, 255, 0);
+ font_weight_ = "normal";
+ font_style_ = "normal";
+ font_decoration_ = "none";
+ font_face_ = (UI::g_fh1->fontset())->sans();
+ line_spacing_ = 0;
}
void TextParser::parse
=== modified file 'src/graphic/text_parser.h'
--- src/graphic/text_parser.h 2014-09-10 14:48:40 +0000
+++ src/graphic/text_parser.h 2016-03-17 17:18:59 +0000
@@ -37,68 +37,68 @@
TextBlock();
// Copy and assignement operators are autogenerated.
- void set_font_size(int32_t const font_size) {m_font_size = font_size;}
- int32_t get_font_size() const {return m_font_size;}
+ void set_font_size(int32_t const font_size) {font_size_ = font_size;}
+ int32_t get_font_size() const {return font_size_;}
- void set_font_color(const RGBColor & font_color) {m_font_color = font_color;}
- RGBColor get_font_color() const {return m_font_color;}
+ void set_font_color(const RGBColor & font_color) {font_color_ = font_color;}
+ RGBColor get_font_color() const {return font_color_;}
void set_font_weight(const std::string & font_weight) {
- m_font_weight = font_weight;
+ font_weight_ = font_weight;
}
- const std::string & get_font_weight() const {return m_font_weight;}
+ const std::string & get_font_weight() const {return font_weight_;}
void set_font_style(const std::string & font_style) {
- m_font_style = font_style;
+ font_style_ = font_style;
}
- const std::string & get_font_style() const {return m_font_style;}
+ const std::string & get_font_style() const {return font_style_;}
void set_font_decoration(const std::string & font_decoration) {
- m_font_decoration = font_decoration;
+ font_decoration_ = font_decoration;
}
- const std::string & get_font_decoration() const {return m_font_decoration;}
+ const std::string & get_font_decoration() const {return font_decoration_;}
- void set_font_face(const std::string & font_face) {m_font_face = font_face;}
- const std::string & get_font_face() const {return m_font_face;}
+ void set_font_face(const std::string & font_face) {font_face_ = font_face;}
+ const std::string & get_font_face() const {return font_face_;}
void set_line_spacing(int32_t const line_spacing) {
- m_line_spacing = line_spacing;
+ line_spacing_ = line_spacing;
}
- int32_t get_line_spacing() const {return m_line_spacing;}
+ int32_t get_line_spacing() const {return line_spacing_;}
- void set_words(const std::vector<std::string> & words) {m_words = words;}
- const std::vector<std::string> & get_words() const {return m_words;}
+ void set_words(const std::vector<std::string> & words) {words_ = words;}
+ const std::vector<std::string> & get_words() const {return words_;}
void set_line_breaks
(const std::vector<std::vector<std::string>::size_type> & line_breaks)
{
- m_line_breaks = line_breaks;
+ line_breaks_ = line_breaks;
}
const std::vector<std::vector<std::string>::size_type> & get_line_breaks
() const
{
- return m_line_breaks;
+ return line_breaks_;
}
private:
- int32_t m_font_size;
- RGBColor m_font_color;
- std::string m_font_weight;
- std::string m_font_style;
- std::string m_font_decoration;
- std::string m_font_face;
- int32_t m_line_spacing;
- std::vector<std::string> m_words;
+ int32_t font_size_;
+ RGBColor font_color_;
+ std::string font_weight_;
+ std::string font_style_;
+ std::string font_decoration_;
+ std::string font_face_;
+ int32_t line_spacing_;
+ std::vector<std::string> words_;
/**
- * Position of manual line breaks (<br>) with respect to @ref m_words.
+ * Position of manual line breaks (<br>) with respect to @ref words_.
* Sorted in ascending order.
* An entry j in this vector means that a manual line break occurs
- * before the j-th word in @ref m_words. In particular, an entry 0
+ * before the j-th word in @ref words_. In particular, an entry 0
* means that a manual line break occurs before the first word.
* Entries can appear with multiplicity, indicating that multiple
* manual line breaks exist without any words in-between.
*/
- std::vector<std::vector<std::string>::size_type> m_line_breaks;
+ std::vector<std::vector<std::string>::size_type> line_breaks_;
};
struct RichtextBlock {
@@ -106,27 +106,27 @@
RichtextBlock(const RichtextBlock & src);
void set_images(const std::vector<std::string> & images) {
- m_images = images;
+ images_ = images;
}
- const std::vector<std::string> & get_images() const {return m_images;}
-
- void set_image_align(Align const image_align) {m_image_align = image_align;}
- Align get_image_align() const {return m_image_align;}
-
- void set_text_align(Align const text_align) {m_text_align = text_align;}
- Align get_text_align() const {return m_text_align;}
+ const std::vector<std::string> & get_images() const {return images_;}
+
+ void set_image_align(Align const image_align) {image_align_ = image_align;}
+ Align get_image_align() const {return image_align_;}
+
+ void set_text_align(Align const text_align) {text_align_ = text_align;}
+ Align get_text_align() const {return text_align_;}
void set_text_blocks(const std::vector<TextBlock> & text_blocks) {
- m_text_blocks = text_blocks;
+ text_blocks_ = text_blocks;
}
const std::vector<TextBlock> & get_text_blocks() const {
- return m_text_blocks;
+ return text_blocks_;
}
private:
- std::vector<std::string> m_images;
- std::vector<TextBlock> m_text_blocks;
- Align m_image_align;
- Align m_text_align;
+ std::vector<std::string> images_;
+ std::vector<TextBlock> text_blocks_;
+ Align image_align_;
+ Align text_align_;
};
struct TextParser {
=== modified file 'src/graphic/texture.cc'
--- src/graphic/texture.cc 2016-02-02 09:24:10 +0000
+++ src/graphic/texture.cc 2016-03-17 17:18:59 +0000
@@ -103,7 +103,7 @@
{
init(w, h);
- if (m_blit_data.texture_id == 0) {
+ if (blit_data_.texture_id == 0) {
return;
}
@@ -156,9 +156,9 @@
throw wexception("Created a sub Texture with zero height and width parent.");
}
- m_owns_texture = false;
+ owns_texture_ = false;
- m_blit_data = BlitData {
+ blit_data_ = BlitData {
texture,
parent_w, parent_h,
subrect,
@@ -167,23 +167,23 @@
Texture::~Texture()
{
- if (m_owns_texture) {
- Gl::State::instance().unbind_texture_if_bound(m_blit_data.texture_id);
- glDeleteTextures(1, &m_blit_data.texture_id);
+ if (owns_texture_) {
+ Gl::State::instance().unbind_texture_if_bound(blit_data_.texture_id);
+ glDeleteTextures(1, &blit_data_.texture_id);
}
}
int Texture::width() const {
- return m_blit_data.rect.w;
+ return blit_data_.rect.w;
}
int Texture::height() const {
- return m_blit_data.rect.h;
+ return blit_data_.rect.h;
}
void Texture::init(uint16_t w, uint16_t h)
{
- m_blit_data = {
+ blit_data_ = {
0, // initialized below
w, h,
Rect(0, 0, w, h),
@@ -192,9 +192,9 @@
return;
}
- m_owns_texture = true;
- glGenTextures(1, &m_blit_data.texture_id);
- Gl::State::instance().bind(GL_TEXTURE0, m_blit_data.texture_id);
+ owns_texture_ = true;
+ glGenTextures(1, &blit_data_.texture_id);
+ Gl::State::instance().bind(GL_TEXTURE0, blit_data_.texture_id);
// set texture filter to use linear filtering. This looks nicer for resized
// texture. Most textures and images are not resized so the filtering
@@ -204,46 +204,46 @@
}
void Texture::lock() {
- if (m_blit_data.texture_id == 0) {
+ if (blit_data_.texture_id == 0) {
return;
}
- if (m_pixels) {
+ if (pixels_) {
throw wexception("Called lock() on locked surface.");
}
- if (!m_owns_texture) {
+ if (!owns_texture_) {
throw wexception("A surface that does not own its pixels can not be locked..");
}
- m_pixels.reset(new uint8_t[width() * height() * 4]);
+ pixels_.reset(new uint8_t[width() * height() * 4]);
- Gl::State::instance().bind(GL_TEXTURE0, m_blit_data.texture_id);
- glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, m_pixels.get());
+ Gl::State::instance().bind(GL_TEXTURE0, blit_data_.texture_id);
+ glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels_.get());
}
void Texture::unlock(UnlockMode mode) {
if (width() <= 0 || height() <= 0) {
return;
}
- assert(m_pixels);
+ assert(pixels_);
if (mode == Unlock_Update) {
- Gl::State::instance().bind(GL_TEXTURE0, m_blit_data.texture_id);
+ Gl::State::instance().bind(GL_TEXTURE0, blit_data_.texture_id);
glTexImage2D(GL_TEXTURE_2D, 0, static_cast<GLint>(GL_RGBA), width(), height(), 0, GL_RGBA,
- GL_UNSIGNED_BYTE, m_pixels.get());
+ GL_UNSIGNED_BYTE, pixels_.get());
}
- m_pixels.reset(nullptr);
+ pixels_.reset(nullptr);
}
RGBAColor Texture::get_pixel(uint16_t x, uint16_t y) {
- assert(m_pixels);
+ assert(pixels_);
assert(x < width());
assert(y < height());
RGBAColor color;
- SDL_GetRGBA(*reinterpret_cast<uint32_t*>(&m_pixels[(height() - y - 1) * 4 * width() + 4 * x]),
+ SDL_GetRGBA(*reinterpret_cast<uint32_t*>(&pixels_[(height() - y - 1) * 4 * width() + 4 * x]),
&rgba_format(),
&color.r,
&color.g,
@@ -253,20 +253,20 @@
}
void Texture::set_pixel(uint16_t x, uint16_t y, const RGBAColor& color) {
- assert(m_pixels);
+ assert(pixels_);
assert(x < width());
assert(y < height());
- uint8_t* data = &m_pixels[(height() - y - 1) * 4 * width() + 4 * x];
+ uint8_t* data = &pixels_[(height() - y - 1) * 4 * width() + 4 * x];
uint32_t packed_color = SDL_MapRGBA(&rgba_format(), color.r, color.g, color.b, color.a);
*(reinterpret_cast<uint32_t *>(data)) = packed_color;
}
void Texture::setup_gl() {
- assert(m_blit_data.texture_id != 0);
+ assert(blit_data_.texture_id != 0);
Gl::State::instance().bind_framebuffer(
- GlFramebuffer::instance().id(), m_blit_data.texture_id);
+ GlFramebuffer::instance().id(), blit_data_.texture_id);
glViewport(0, 0, width(), height());
}
@@ -274,7 +274,7 @@
const BlitData& texture,
float opacity,
BlendMode blend_mode) {
- if (m_blit_data.texture_id == 0) {
+ if (blit_data_.texture_id == 0) {
return;
}
setup_gl();
@@ -287,7 +287,7 @@
const BlitData& mask,
const RGBColor& blend) {
- if (m_blit_data.texture_id == 0) {
+ if (blit_data_.texture_id == 0) {
return;
}
setup_gl();
@@ -297,7 +297,7 @@
void Texture::do_blit_monochrome(const FloatRect& dst_rect,
const BlitData& texture,
const RGBAColor& blend) {
- if (m_blit_data.texture_id == 0) {
+ if (blit_data_.texture_id == 0) {
return;
}
setup_gl();
@@ -305,7 +305,7 @@
}
void Texture::do_draw_line_strip(std::vector<DrawLineProgram::PerVertexData> vertices) {
- if (m_blit_data.texture_id == 0) {
+ if (blit_data_.texture_id == 0) {
return;
}
setup_gl();
@@ -315,7 +315,7 @@
void
Texture::do_fill_rect(const FloatRect& dst_rect, const RGBAColor& color, BlendMode blend_mode) {
- if (m_blit_data.texture_id == 0) {
+ if (blit_data_.texture_id == 0) {
return;
}
setup_gl();
@@ -323,5 +323,5 @@
}
const BlitData& Texture::blit_data() const {
- return m_blit_data;
+ return blit_data_;
}
=== modified file 'src/graphic/texture.h'
--- src/graphic/texture.h 2016-02-02 09:02:53 +0000
+++ src/graphic/texture.h 2016-03-17 17:18:59 +0000
@@ -99,11 +99,11 @@
do_fill_rect(const FloatRect& dst_rect, const RGBAColor& color, BlendMode blend_mode) override;
// True if we own the texture, i.e. if we need to delete it.
- bool m_owns_texture;
+ bool owns_texture_;
- BlitData m_blit_data;
+ BlitData blit_data_;
/// Pixel data, while the texture is locked
- std::unique_ptr<uint8_t[]> m_pixels;
+ std::unique_ptr<uint8_t[]> pixels_;
DISALLOW_COPY_AND_ASSIGN(Texture);
};
=== modified file 'src/graphic/wordwrap.cc'
--- src/graphic/wordwrap.cc 2016-02-03 22:42:34 +0000
+++ src/graphic/wordwrap.cc 2016-03-17 17:18:59 +0000
@@ -40,20 +40,20 @@
* and a default-constructed text style.
*/
WordWrap::WordWrap() :
- m_wrapwidth(std::numeric_limits<uint32_t>::max()), m_draw_caret(false)
+ wrapwidth_(std::numeric_limits<uint32_t>::max()), draw_caret_(false)
{
}
WordWrap::WordWrap(const TextStyle & style, uint32_t gwrapwidth) :
- m_style(style), m_draw_caret(false)
+ style_(style), draw_caret_(false)
{
- m_wrapwidth = gwrapwidth;
+ wrapwidth_ = gwrapwidth;
- if (m_wrapwidth < std::numeric_limits<uint32_t>::max()) {
- if (m_wrapwidth < 2 * LINE_MARGIN)
- m_wrapwidth = 0;
+ if (wrapwidth_ < std::numeric_limits<uint32_t>::max()) {
+ if (wrapwidth_ < 2 * LINE_MARGIN)
+ wrapwidth_ = 0;
else
- m_wrapwidth -= 2 * LINE_MARGIN;
+ wrapwidth_ -= 2 * LINE_MARGIN;
}
}
@@ -62,7 +62,7 @@
*/
void WordWrap::set_style(const TextStyle & style)
{
- m_style = style;
+ style_ = style;
}
/**
@@ -70,7 +70,7 @@
*/
void WordWrap::set_wrapwidth(uint32_t gwrapwidth)
{
- m_wrapwidth = gwrapwidth;
+ wrapwidth_ = gwrapwidth;
}
/**
@@ -79,7 +79,7 @@
*/
uint32_t WordWrap::wrapwidth() const
{
- return m_wrapwidth;
+ return wrapwidth_;
}
/**
@@ -88,10 +88,10 @@
*/
void WordWrap::wrap(const std::string & text)
{
- m_lines.clear();
+ lines_.clear();
std::string::size_type line_start = 0;
- uint32_t margin = m_style.calc_width_for_wrapping(0x2003); // Em space
+ uint32_t margin = style_.calc_width_for_wrapping(0x2003); // Em space
while (line_start <= text.size()) {
std::string::size_type next_line_start;
@@ -102,7 +102,7 @@
LineData ld;
ld.start = line_start;
ld.text = text.substr(line_start, line_end - line_start);
- m_lines.push_back(ld);
+ lines_.push_back(ld);
line_start = next_line_start;
}
@@ -121,13 +121,13 @@
uint32_t safety_margin)
{
std::string::size_type minimum_chars = 1; // So we won't get empty lines
- assert(text.empty() || m_wrapwidth > safety_margin);
+ assert(text.empty() || wrapwidth_ > safety_margin);
std::string::size_type orig_end = text.find('\n', line_start);
if (orig_end == std::string::npos)
orig_end = text.size();
- if (m_wrapwidth == std::numeric_limits<uint32_t>::max() || orig_end - line_start <= minimum_chars) {
+ if (wrapwidth_ == std::numeric_limits<uint32_t>::max() || orig_end - line_start <= minimum_chars) {
// Special fast path when wrapping is disabled or
// original text line contains at most minimum_chars characters
line_end = orig_end;
@@ -137,8 +137,8 @@
// Optimism: perhaps the entire line fits?
- if (text_width(text.substr(line_start, orig_end - line_start), m_style.font->size())
- <= m_wrapwidth - safety_margin) {
+ if (text_width(text.substr(line_start, orig_end - line_start), style_.font->size())
+ <= wrapwidth_ - safety_margin) {
line_end = orig_end;
next_line_start = orig_end + 1;
return;
@@ -196,13 +196,13 @@
int32_t end = -1;
icu::UnicodeString unicode_line;
- while ((line_width < (m_wrapwidth - safety_margin)) && (end < unicode_word.length())) {
+ while ((line_width < (wrapwidth_ - safety_margin)) && (end < unicode_word.length())) {
++end;
UChar c = unicode_word.charAt(end);
// Diacritics do not add to the line width
if (!i18n::is_diacritic(c)) {
// This only estimates the width
- line_width += m_style.calc_width_for_wrapping(c);
+ line_width += style_.calc_width_for_wrapping(c);
}
unicode_line += c;
}
@@ -210,7 +210,7 @@
// Now make sure that it really fits.
std::string::size_type test_cutoff = line_start + end * 2 / 3;
while ((end > 0) && (static_cast<uint32_t>(line_start + end) > test_cutoff)) {
- if (text_width(text.substr(line_start, end), m_style.font->size()) > m_wrapwidth - safety_margin) {
+ if (text_width(text.substr(line_start, end), style_.font->size()) > wrapwidth_ - safety_margin) {
--end;
} else {
break;
@@ -241,9 +241,9 @@
bool WordWrap::line_fits(const std::string& text, uint32_t safety_margin) const {
// calc_width_for_wrapping is fast, but it will underestimate the width.
// So, we test again with text_width to make sure that the line really fits.
- return m_style.calc_width_for_wrapping(i18n::make_ligatures(text.c_str()))
- <= m_wrapwidth - safety_margin &&
- text_width(text, m_style.font->size()) <= m_wrapwidth - safety_margin;
+ return style_.calc_width_for_wrapping(i18n::make_ligatures(text.c_str()))
+ <= wrapwidth_ - safety_margin &&
+ text_width(text, style_.font->size()) <= wrapwidth_ - safety_margin;
}
@@ -256,8 +256,8 @@
{
uint32_t calculated_width = 0;
- for (uint32_t line = 0; line < m_lines.size(); ++line) {
- uint32_t linewidth = text_width(m_lines[line].text, m_style.font->size());
+ for (uint32_t line = 0; line < lines_.size(); ++line) {
+ uint32_t linewidth = text_width(lines_[line].text, style_.font->size());
if (linewidth > calculated_width)
calculated_width = linewidth;
}
@@ -271,11 +271,11 @@
uint32_t WordWrap::height() const
{
uint16_t fontheight = 0;
- if (!m_lines.empty()) {
- fontheight = text_height(m_lines[0].text, m_style.font->size());
+ if (!lines_.empty()) {
+ fontheight = text_height(lines_[0].text, style_.font->size());
}
- return fontheight * (m_lines.size()) + 2 * LINE_MARGIN;
+ return fontheight * (lines_.size()) + 2 * LINE_MARGIN;
}
/**
@@ -284,25 +284,25 @@
*/
void WordWrap::calc_wrapped_pos(uint32_t caret, uint32_t & line, uint32_t & pos) const
{
- assert(m_lines.size());
- assert(m_lines[0].start == 0);
+ assert(lines_.size());
+ assert(lines_[0].start == 0);
uint32_t min = 0;
- uint32_t max = m_lines.size() - 1;
+ uint32_t max = lines_.size() - 1;
while (max > min) {
uint32_t mid = min + (max - min + 1) / 2;
- if (caret >= m_lines[mid].start)
+ if (caret >= lines_[mid].start)
min = mid;
else
max = mid - 1;
}
- assert(caret >= m_lines[min].start);
+ assert(caret >= lines_[min].start);
line = min;
- pos = caret - m_lines[min].start;
+ pos = caret - lines_[min].start;
}
/**
@@ -310,7 +310,7 @@
*/
uint32_t WordWrap::line_offset(uint32_t line) const
{
- return m_lines[line].start;
+ return lines_[line].start;
}
/**
@@ -320,7 +320,7 @@
*/
void WordWrap::draw(RenderTarget & dst, Point where, Align align, uint32_t caret)
{
- if (m_lines.empty()) return;
+ if (lines_.empty()) return;
uint32_t caretline, caretpos;
@@ -339,28 +339,28 @@
Align alignment = mirror_alignment(align);
- uint16_t fontheight = text_height(m_lines[0].text, m_style.font->size());
- for (uint32_t line = 0; line < m_lines.size(); ++line, where.y += fontheight) {
+ uint16_t fontheight = text_height(lines_[0].text, style_.font->size());
+ for (uint32_t line = 0; line < lines_.size(); ++line, where.y += fontheight) {
if (where.y >= dst.height() || int32_t(where.y + fontheight) <= 0)
continue;
Point point(where.x, where.y);
if (static_cast<int>(alignment & UI::Align::kRight)) {
- point.x += m_wrapwidth - LINE_MARGIN;
+ point.x += wrapwidth_ - LINE_MARGIN;
}
const Image* entry_text_im =
- UI::g_fh1->render(as_editorfont(m_lines[line].text,
- m_style.font->size() - UI::g_fh1->fontset()->size_offset(),
- m_style.fg));
+ UI::g_fh1->render(as_editorfont(lines_[line].text,
+ style_.font->size() - UI::g_fh1->fontset()->size_offset(),
+ style_.fg));
UI::correct_for_align(alignment, entry_text_im->width(), fontheight, &point);
dst.blit(point, entry_text_im);
- if (m_draw_caret && line == caretline) {
- std::string line_to_caret = m_lines[line].text.substr(0, caretpos);
+ if (draw_caret_ && line == caretline) {
+ std::string line_to_caret = lines_[line].text.substr(0, caretpos);
// TODO(GunChleoc): Arabic: Fix cursor position for BIDI text.
- int caret_x = text_width(line_to_caret, m_style.font->size());
+ int caret_x = text_width(line_to_caret, style_.font->size());
const Image* caret_image = g_gr->images().get("images/ui_basic/caret.png");
Point caretpt;
=== modified file 'src/graphic/wordwrap.h'
--- src/graphic/wordwrap.h 2016-01-28 21:27:04 +0000
+++ src/graphic/wordwrap.h 2016-03-17 17:18:59 +0000
@@ -45,14 +45,14 @@
uint32_t width() const;
uint32_t height() const;
- void set_draw_caret(bool draw_it) {m_draw_caret = draw_it;}
+ void set_draw_caret(bool draw_it) {draw_caret_ = draw_it;}
void draw
(RenderTarget & dst, Point where, Align align = UI::Align::kLeft,
uint32_t caret = std::numeric_limits<uint32_t>::max());
void calc_wrapped_pos(uint32_t caret, uint32_t & line, uint32_t & pos) const;
- uint32_t nrlines() const {return m_lines.size();}
+ uint32_t nrlines() const {return lines_.size();}
uint32_t line_offset(uint32_t line) const;
private:
@@ -73,11 +73,11 @@
bool line_fits(const std::string& text, uint32_t safety_margin) const;
- TextStyle m_style;
- uint32_t m_wrapwidth;
- bool m_draw_caret;
+ TextStyle style_;
+ uint32_t wrapwidth_;
+ bool draw_caret_;
- std::vector<LineData> m_lines;
+ std::vector<LineData> lines_;
};
} // namespace UI
Follow ups