//! Only renders the shield background, the text is rendered in renderLabels void Renderer::renderShields(const Cairo::RefPtr<Cairo::Context>& cr, std::vector<shared_ptr<Shield> >& shields) const { cr->save(); cr->set_line_join(Cairo::LINE_JOIN_ROUND); for (auto& shield : shields) { const Style* s = shield->style; double x0, y0, height, width; double border = ceil(s->shield_frame_width/2.0 + s->shield_casing_width); x0 = shield->shield.minX + border; y0 = shield->shield.minY + border; width = shield->shield.getWidth() - 2*border; height = shield->shield.getHeight() - 2*border; if ((int) s->shield_frame_width % 2 == 1) { x0 -= 0.5; y0 -= 0.5; } if (s->shield_shape == Style::ShieldShape::ROUNDED) { cr->arc(x0 + height/2.0, y0 + height/2.0, height/2.0, boost::math::constants::pi<double>()/2.0, 3.0*boost::math::constants::pi<double>()/2.0); cr->arc(x0 + width - height/2.0, y0 + height/2.0, height/2.0, 3.0*boost::math::constants::pi<double>()/2.0, boost::math::constants::pi<double>()/2.0); cr->close_path(); } else cr->rectangle(x0, y0, width, height); // shield casing if (s->shield_casing_width > 0) { cr->set_source_color(s->shield_casing_color), cr->set_line_width(s->shield_frame_width + s->shield_casing_width * 2.0); cr->stroke_preserve(); } // shield background cr->set_source_color(s->shield_color), cr->fill_preserve(); // shield frame cr->set_source_color(s->shield_frame_color), cr->set_line_width(s->shield_frame_width); cr->stroke(); } cr->restore(); }
void Renderer::renderLabels(const Cairo::RefPtr<Cairo::Context>& cr, std::vector<shared_ptr<LabelType> >& labels, AssetCache& cache) const { cr->save(); cr->set_line_join(Cairo::LINE_JOIN_ROUND); for (auto it = labels.rbegin(); it != labels.rend(); it++) { const shared_ptr<LabelType>& label = *it; const Style* s = label->style; cr->set_font_size(s->font_size); cr->move_to(label->origin.x, label->origin.y); cr->set_font_face(cache.getFont( s->font_family.str(), s->font_style == Style::STYLE_ITALIC ? Cairo::FONT_SLANT_ITALIC : Cairo::FONT_SLANT_NORMAL, s->font_weight == Style::WEIGHT_BOLD ? Cairo::FONT_WEIGHT_BOLD : Cairo::FONT_WEIGHT_NORMAL )); cr->text_path(label->text.str()); if (s->text_halo_radius > 0.0) { cr->set_source_color(s->text_halo_color); cr->set_line_width(s->text_halo_radius*2.0); cr->stroke_preserve(); } cr->set_source_color(s->text_color); cr->fill(); } cr->restore(); }
void NodeRenderer::stroke(const Cairo::RefPtr<Cairo::Context>& cr) { // nothing to stroke if (s->width <= 0.0) return; cr->save(); cr->arc(location.x, location.y, s->width/2.0, 0, 2*M_PI); cr->set_source_color(s->color); cr->fill(); cr->restore(); }
void NodeRenderer::casing(const Cairo::RefPtr<Cairo::Context>& cr) { // nothing to render if (s->casing_width <= 0.0) return; cr->save(); cr->arc(location.x, location.y, s->width/2.0 + s->casing_width, 0, 2*boost::math::constants::pi<double>()); cr->set_source_color(s->casing_color); cr->fill(); cr->restore(); }