alaCarte Maps
Renderer for OpenStreetMap tiles
renderer_private.hpp
Go to the documentation of this file.
1 
21 #ifndef RENDERER_PRIVATE_HPP
22 #define RENDERER_PRIVATE_HPP
23 
24 #include <boost/unordered_map.hpp>
25 
26 #include <cairo.h>
27 
28 #define RENDERER_SHIELD_DISTANCE 128.0
29 #define RENDERER_SHIELD_OVERLAP 0.1
30 #define RENDERER_LABEL_OVERLAP 0.1
31 
32 #define COLOR2RGBA(_X) _X.r, _X.g, _X.b, _X.a
33 
34 class Style;
35 
36 // TODO make thread safe
37 class AssetCache {
38 private:
39  boost::unordered_map<string, cairo_surface_t*> images;
40 
41 public:
43  {
44  for (auto& pair : images)
45  cairo_surface_destroy(pair.second);
46  }
47 
48  cairo_surface_t* getImage(string path)
49  {
50  auto it = images.find(path);
51  if (it != images.end())
52  return (*it).second;
53 
54  cairo_surface_t* image = cairo_image_surface_create_from_png(path.c_str());
55  images.insert(std::make_pair(path, image));
56  return image;
57  }
58 };
59 
61 struct Label {
62  Label(const FloatRect& box, const FloatRect& owner, const MaybeCachedString& text,
63  const Style* s, const FloatPoint& origin)
64  : box(box),
65  owner(owner),
66  text(text),
67  style(s),
68  origin(origin) {}
69 
77  const Style* style;
80 
82  void translate(double dx, double dy)
83  {
84  box = box.translate(dx, dy);
85  origin.x += dx;
86  origin.y += dy;
87  }
88 };
89 
90 struct Shield : public Label {
91  Shield(const FloatRect& box, const FloatRect& owner, const MaybeCachedString& text,
92  const Style* s, const FloatPoint& origin, const FloatRect& shield)
93  : Label(box, owner, text, s, origin),
94  shield(shield) {}
95 
98 
100  void translate(double dx, double dy)
101  {
102  Label::translate(dx, dy);
103  shield = shield.translate(dx, dy);
104  }
105 };
106 
107 #endif
void translate(double dx, double dy)
used by the placement algorith to move the shield
boost::unordered_map< string, cairo_surface_t * > images
Represents a string which could be cached into an internal cache.
void translate(double dx, double dy)
used by the placement algorith to move the label
Stores bounding box and style of a label that needs to be placed.
Shield(const FloatRect &box, const FloatRect &owner, const MaybeCachedString &text, const Style *s, const FloatPoint &origin, const FloatRect &shield)
A Style stores the MapCSS properties for a single Node or Way, or a Relation of type multipolygon...
Definition: style.hpp:35
const Style * style
Style that is used to paint the label.
const MaybeCachedString & text
The text that should be used (don&#39;t use the style text to make it generic)
FloatRect shield
Dimensions of the shield that should be painted.
basic_rect< T > translate(T dx, T dy) const
Definition: rect.hpp:86
FloatRect owner
bounding box of the object owing the label in device-space coordinates
FloatRect box
bounding box in device-space coordinates
cairo_surface_t * getImage(string path)
FloatPoint origin
Origin of the label.
Label(const FloatRect &box, const FloatRect &owner, const MaybeCachedString &text, const Style *s, const FloatPoint &origin)