REPORT_GENERATOR(income, rc) { std::ostringstream str; int viewing_side = rc.screen().viewing_side(); const team &viewing_team = rc.teams()[viewing_side - 1]; team_data td = rc.dc().calculate_team_data(viewing_team, viewing_side); char const *end = naps; if (viewing_side != rc.screen().playing_side()) { if (td.net_income < 0) { td.net_income = - td.net_income; str << span_color(font::GRAY_COLOR); str << utils::unicode_minus; } else { str << span_color(font::GRAY_COLOR); } } else if (td.net_income < 0) { td.net_income = - td.net_income; str << span_color(font::BAD_COLOR); str << utils::unicode_minus; } else { end = ""; } str << td.net_income << end; return text_report(str.str()); }
path text_box_rep::find_box_path (SI x, SI y, SI delta, bool force, bool& found) { (void) y; (void) force; found= true; STACK_NEW_ARRAY (xpos, SI, N(str)+1); if (is_nil (xk)) fn->get_xpositions (str, xpos); else { fn->get_xpositions (str, xpos, xk->padding); x += (xk->padding - xk->left); } int prev_i, prev_x=0, i=0; while (i<N(str)) { prev_i= i; if (str[i]=='<') while ((i<N(str)) && (str[i]!='>')) i++; i++; int m= (prev_x + xpos[i]) >> 1; if ((x<m) || ((x==m) && (delta<0))) { STACK_DELETE_ARRAY (xpos); return path (prev_i); } prev_x= xpos[i]; } STACK_DELETE_ARRAY (xpos); return path (i); }
static string get_wide (string s, font fn, SI width) { ASSERT (N(s) >= 2 && s[0] == '<' && s[N(s)-1] == '>', "invalid rubber character"); string radical= s (0, N(s)-1) * "-"; string first = radical * "0>"; metric ex; fn->get_extents (first, ex); if ((ex->x2- ex->x1) >= width) return first; string second = radical * "1>"; metric ey; fn->get_extents (second, ey); SI w1= ex->x2- ex->x1; SI w2= ey->x2- ey->x1; if ((w2 <= w1) || (w2 > width)) return first; SI d= w2- w1; int n= (width-w1) / (d+1); int credit= 20; while (true) { string test= radical * as_string (n+1) * ">"; fn->get_extents (test, ey); if (ey->x2- ey->x1 > width || credit <= 0) return radical * as_string (n) * ">"; n++; credit--; } }
selection text_box_rep::find_selection (path lbp, path rbp) { SI x1, y1, x2, y2; metric ex; fn->get_extents (str (0, lbp->item), ex); x1= ex->x2; fn->get_extents (str (0, rbp->item), ex); x2= ex->x2; if (!is_nil (xk) && N(str) != 0) { STACK_NEW_ARRAY (xpos, SI, N(str)+1); fn->get_xpositions (str, xpos, xk->padding); SI d= xk->padding - xk->left; x1= xpos[lbp->item] - d; x2= xpos[rbp->item] - d; if (lbp->item == 0) x1 += d; if (rbp->item == 0) x2 += d; if (lbp->item == N(str)) x1 += xk->right; if (rbp->item == N(str)) x2 += xk->right; STACK_DELETE_ARRAY (xpos); } fn->get_extents (str (lbp->item, rbp->item), ex); y1= ex->y1; y2= ex->y2; return selection (rectangle (x1, y1, x2, y2), find_tree_path (lbp), find_tree_path (rbp)); }
cursor text_box_rep::find_cursor (path bp) { metric ex; cursor cu (0, 0); int l= min (bp->item, N(str)); fn->get_extents (str (0, l), ex); cu->ox= ex->x2; if (!is_nil (xk) && N(str) != 0) { STACK_NEW_ARRAY (xpos, SI, N(str)+1); fn->get_xpositions (str, xpos, xk->padding); SI d= xk->padding - xk->left; cu->ox= xpos[l] - d; if (l == 0) cu->ox += d; if (l == N(str)) cu->ox += xk->right; STACK_DELETE_ARRAY (xpos); } if (l != 0) { int k= l; tm_char_backwards (str, k); fn->get_extents (str (k, l), ex); } cu->y1= min (ex->y1, 0); cu->y2= max (ex->y2, fn->yx); cu->slope= fn->get_right_slope (str); return cu; }
std::size_t font_hasher::hash(const font& v) { std::size_t seed(0); combine(seed, v.family()); combine(seed, v.style()); combine(seed, v.name()); return seed; }
glyph poor_bbb_font_rep::get_glyph (string s) { glyph gl= base->get_glyph (s); if (is_nil (gl)) return gl; font_metric fnm; font_glyphs fng; int c= base->index_glyph (s, fnm, fng); if (c < 0) return glyph (); return make_bbb (gl, c, wpen, hpen, fat); }
static config gray_inactive(reports::context & rc, const std::string &str) { if ( rc.screen().viewing_side() == rc.screen().playing_side() ) return text_report(str); return text_report(span_color(font::GRAY_COLOR) + str + naps); }
static config unit_abilities(const unit* u) { if (!u) return report(); config res; std::vector<bool> active; const std::vector<boost::tuple<t_string,t_string,t_string> > &abilities = u->ability_tooltips(&active); const size_t abilities_size = abilities.size(); for ( size_t i = 0; i != abilities_size; ++i ) { // Aliases for readability: const std::string &base_name = abilities[i].get<0>().base_str(); const t_string &display_name = abilities[i].get<1>(); const t_string &description = abilities[i].get<2>(); std::ostringstream str, tooltip; if ( active[i] ) str << display_name; else str << span_color(font::inactive_ability_color) << display_name << naps; if ( i + 1 != abilities_size ) str << ", "; tooltip << _("Ability: ") << "<b>" << display_name << "</b>"; if ( !active[i] ) tooltip << "<i>" << _(" (inactive)") << "</i>"; tooltip << '\n' << description; add_text(res, str.str(), tooltip.str(), "ability_" + base_name); } return res; }
renderer_i::texture sfml2_renderer::make_text_label(const std::u32string& text, const color& fill, const font& font, float point_size, text_style style) { const sfml2_font& tmp = dynamic_cast<const sfml2_font&>(*font); const sf::Font& sffont = tmp.sf_font(); sf::String str(reinterpret_cast<const sf::Uint32*>(text.c_str())); sf::Text label(str, sffont, (int)point_size); sf::RenderTexture rt; auto size = label.getLocalBounds(); if (!rt.create(size.width + 1, font->height(point_size) + 1)) throw std::runtime_error("cannot create sf::RenderTexture"); rt.clear(sf::Color::Transparent); label.move(0, -label.getLocalBounds().top); label.setColor(col(fill)); label.setStyle(static_cast<sf::Uint32>(style)); rt.draw(label); rt.display(); return texture{new sfml2_texture{rt.getTexture()}}; }
SI text_box_rep::get_leaf_offset (string search) { int pos= search_forwards (search, 0, str); if (pos == -1) return w(); metric ex; fn->get_extents (str (0, pos), ex); return ex->x2- ex->x1; }
box text_box_rep::adjust_kerning (int mode, double factor) { if (N(str) == 0) return this; SI pad= (SI) tm_round ((factor * fn->wfn) / 2); xkerning nxk (pad, 0, 0); if (!is_nil (xk) && (mode & PROTRUSION_MASK) == 0) { nxk->left = xk->left; nxk->right= xk->right; } if ((mode & PROTRUSION_MASK) != 0) { nxk->left = -fn->get_left_protrusion (str, mode); nxk->right= -fn->get_right_protrusion (str, mode); } if ((mode & START_OF_LINE) != 0) nxk->left -= pad; if ((mode & END_OF_LINE ) != 0) nxk->right -= pad; return tm_new<text_box_rep> (ip, pos, str, fn, pen, nxk); }
static config unit_race(const unit* u) { if (!u) return report(); std::ostringstream str, tooltip; str << span_color(font::race_color) << u->race()->name(u->gender()) << naps; tooltip << _("Race: ") << "<b>" << u->race()->name(u->gender()) << "</b>"; return text_report(str.str(), tooltip.str(), "..race_" + u->race()->id()); }
void poor_stretched_font_rep::get_extents (string s, metric& ex) { base->get_extents (s, ex); ex->y1= (SI) floor (factor * ex->y1 + 0.5); ex->y2= (SI) floor (factor * ex->y2 + 0.5); ex->y3= (SI) floor (factor * ex->y3); ex->y4= (SI) ceil (factor * ex->y4); }
int poor_stretched_font_rep::index_glyph (string s, font_metric& fnm, font_glyphs& fng) { int c= base->index_glyph (s, fnm, fng); if (c < 0) return c; fnm= stretched (fnm, 1.0, factor); fng= stretched (fng, 1.0, factor); return c; }
int poor_bbb_font_rep::index_glyph (string s, font_metric& fnm, font_glyphs& fng) { int c= base->index_glyph (s, fnm, fng); if (c < 0) return c; fnm= bolden (fnm, fat, 0); fng= make_bbb (fng, wpen, hpen, fat); return c; }
static config gray_inactive(const std::string &str) { if ( (resources::screen && (resources::screen->viewing_side() == resources::screen->playing_side()) ) || !resources::screen ) return text_report(str); return text_report(span_color(font::GRAY_COLOR) + str + naps); }
int poor_distorted_font_rep::index_glyph (string s, font_metric& fnm, font_glyphs& fng) { int c= base->index_glyph (s, fnm, fng); if (c < 0) return c; //fnm= distorted (fnm, kind); fng= distorted (fng, kind, wfn); return c; }
static config unit_type(const unit* u) { if (!u) return report(); std::ostringstream str, tooltip; str << span_color(font::unit_type_color) << u->type_name() << naps; tooltip << _("Type: ") << "<b>" << u->type_name() << "</b>\n" << u->unit_description(); return text_report(str.str(), tooltip.str(), "unit_" + u->type_id()); }
rectangle BtStyle::get_min_size( const ustring& name, const font& mfont ) const { unsigned long width; unsigned long height; mfont.compute_size( name, width, height ); name_width = width; return rectangle( width + 2*padding, height + 2*padding ); }
static config unit_moves(reports::context & rc, const unit* u) { if (!u) return config(); std::ostringstream str, tooltip; double movement_frac = 1.0; if (u->side() == rc.screen().playing_side()) { movement_frac = double(u->movement_left()) / std::max<int>(1, u->total_movement()); if (movement_frac > 1.0) movement_frac = 1.0; } std::set<t_translation::t_terrain>::const_iterator terrain_it = preferences::encountered_terrains().begin(); tooltip << _("Movement Costs:") << "\n"; for (; terrain_it != preferences::encountered_terrains().end(); ++terrain_it) { const t_translation::t_terrain terrain = *terrain_it; if (terrain == t_translation::FOGGED || terrain == t_translation::VOID_TERRAIN || terrain == t_translation::OFF_MAP_USER) continue; const terrain_type& info = rc.map().get_terrain_info(terrain); if (info.union_type().size() == 1 && info.union_type()[0] == info.number() && info.is_nonnull()) { const std::string& name = info.name(); const int moves = u->movement_cost(terrain); tooltip << name << ": "; std::string color; //movement - range: 1 .. 5, movetype::UNREACHABLE=impassable const bool cannot_move = moves > u->total_movement(); if (cannot_move) // cannot move in this terrain color = "red"; else if (moves > 1) color = "yellow"; else color = "white"; tooltip << "<span foreground=\"" << color << "\">"; // A 5 MP margin; if the movement costs go above // the unit's max moves + 5, we replace it with dashes. if(cannot_move && (moves > u->total_movement() + 5)) { tooltip << utils::unicode_figure_dash; } else { tooltip << moves; } tooltip << naps << '\n'; } } int grey = 128 + int((255 - 128) * movement_frac); SDL_Color c = create_color(grey, grey, grey); str << span_color(c) << u->movement_left() << '/' << u->total_movement() << naps; return text_report(str.str(), tooltip.str()); }
void poor_bbb_font_rep::get_extents (string s, metric& ex) { base->get_extents (s, ex); if (N(s) == 0) return; STACK_NEW_ARRAY (xpos, SI, N(s)+1); get_xpositions (s, xpos); ex->x4 += xpos[N(s)] - ex->x2; ex->x2= xpos[N(s)]; STACK_DELETE_ARRAY (xpos); }
static neogfx::size extents(const font& aFont, const_iterator aBegin, const_iterator aEnd) { neogfx::size result; bool usingNormal = false; bool usingFallback = false; for (glyph_text::const_iterator i = aBegin; i != aEnd; ++i) { result.cx += i->advance().cx; if (!i->use_fallback()) usingNormal = true; else usingFallback = true; } if (usingNormal || !usingFallback) result.cy = aFont.height(); if (usingFallback) result.cy = std::max(result.cy, aFont.fallback().height()); return neogfx::size(std::ceil(result.cx), std::ceil(result.cy)); }
static config unit_xp(const unit* u) { if (!u) return report(); std::ostringstream str, tooltip; str << span_color(u->xp_color()) << u->experience() << '/' << u->max_experience() << naps; int exp_mod = unit_type::experience_accelerator::get_acceleration(); tooltip << _("Experience Modifier: ") << exp_mod << '%'; return text_report(str.str(), tooltip.str()); }
string count_trace (font fn, array<int> cs) { array<int> a; for (int i= 0; i < N(cs); i++) { string s; s << ((char) cs[i]); glyph g= fn->get_glyph (s); if (is_nil (g)) return ""; a << pixel_count (g); } return array_trace (a); }
static config unit_defense(reports::context & rc, const unit* u, const map_location& displayed_unit_hex) { if(!u) { return config(); } std::ostringstream str, tooltip; const gamemap &map = rc.map(); if(!rc.map().on_board(displayed_unit_hex)) { return config(); } const t_translation::t_terrain &terrain = map[displayed_unit_hex]; int def = 100 - u->defense_modifier(terrain); SDL_Color color = int_to_color(game_config::red_to_green(def)); str << span_color(color) << def << '%' << naps; tooltip << _("Terrain: ") << "<b>" << map.get_terrain_info(terrain).description() << "</b>\n"; const t_translation::t_list &underlyings = map.underlying_def_terrain(terrain); if (underlyings.size() != 1 || underlyings.front() != terrain) { bool revert = false; for (const t_translation::t_terrain &t : underlyings) { if (t == t_translation::MINUS) { revert = true; } else if (t == t_translation::PLUS) { revert = false; } else { int t_def = 100 - u->defense_modifier(t); SDL_Color color = int_to_color(game_config::red_to_green(t_def)); tooltip << '\t' << map.get_terrain_info(t).description() << ": " << span_color(color) << t_def << '%' << naps << (revert ? _("maximum^max.") : _("minimum^min.")) << '\n'; } } } tooltip << "<b>" << _("Defense: ") << span_color(color) << def << '%' << naps << "</b>"; return text_report(str.str(), tooltip.str()); }
void math_font_rep::init_font (int fn_nr, font& fn) { tree t= font_name [fn_nr]; if (is_tuple (t, "virtual", 3)) fn= virtual_font (this, as_string (t[1]), as_int (t[2]), (int) tm_round (as_int (t[3]) * zf)); else fn= find_magnified_font (t, zf); ASSERT (!is_nil (fn), "font not found"); fn->copy_math_pars (base_fn); font_table [fn_nr]= fn; }
font fallback_font(font aFont) const { if (!use_fallback()) return aFont; else { font fallbackFont = aFont.fallback(); for (uint8_t i = 0; i < iFallbackIndex; ++i) fallbackFont = fallbackFont.fallback(); return fallbackFont; } }
font rubber_stix_font_rep::get_font_sub (int nr) { switch (nr) { case 0: return base; case 1: return base->magnify (sqrt (2.0)); case 2: return base->magnify (2.0); case 3: if (reg) return unicode_font ("STIXIntegralsD-Regular", base->size, dpi); else return unicode_font ("STIXIntegralsD-Bold", base->size, dpi); case 4: if (reg) return unicode_font ("STIXIntegralsUp-Regular", base->size, dpi); else return unicode_font ("STIXIntegralsD-Bold", base->size, dpi); case 5: if (reg) return unicode_font ("STIXIntegralsUpD-Regular", base->size, dpi); else return unicode_font ("STIXIntegralsUpD-Bold", base->size, dpi); case 6: if (reg) return unicode_font ("STIXSizeOneSym-Regular", base->size, dpi); else return unicode_font ("STIXSizeOneSym-Bold", base->size, dpi); case 7: if (reg) return unicode_font ("STIXSizeOneSym-Regular", base->size, dpi); else return unicode_font ("STIXSizeOneSym-Bold", base->size, dpi); case 8: if (reg) return unicode_font ("STIXSizeTwoSym-Regular", base->size, dpi); else return unicode_font ("STIXSizeTwoSym-Bold", base->size, dpi); case 9: if (reg) return unicode_font ("STIXSizeThreeSym-Regular", base->size, dpi); else return unicode_font ("STIXSizeThreeSym-Bold", base->size, dpi); case 10: if (reg) return unicode_font ("STIXSizeFourSym-Regular", base->size, dpi); else return unicode_font ("STIXSizeFourSym-Bold", base->size, dpi); case 11: return unicode_font ("STIXSizeOneSym-Regular", base->size, dpi); case 12: return unicode_font ("STIXSizeTwoSym-Regular", base->size, dpi); case 13: return unicode_font ("STIXSizeThreeSym-Regular", base->size, dpi); case 14: return unicode_font ("STIXSizeFourSym-Regular", base->size, dpi); case 15: return unicode_font ("STIXSizeFiveSym-Regular", base->size, dpi); case 16: return rubber_assemble_font (base); case 17: return rubber_assemble_font (get_font (11)); default: return base; } }
void graphics_context::draw_glyph_underline(const point& aPoint, const glyph& aGlyph, const font& aFont, const colour& aColour) const { auto yLine = logical_coordinates()[1] > logical_coordinates()[3] ? (aFont.height() + aFont.descender()) - std::ceil(aFont.native_font_face().underline_position()) : -aFont.descender() + std::ceil(aFont.native_font_face().underline_position()); const i_glyph_texture& glyphTexture = !aGlyph.use_fallback() ? aFont.native_font_face().glyph_texture(aGlyph) : aGlyph.fallback_font(aFont).native_font_face().glyph_texture(aGlyph); draw_line( aPoint + point{ glyphTexture.placement().x, yLine }, aPoint + point{ glyphTexture.placement().x + glyphTexture.extents().cx, yLine }, pen{ aColour, std::ceil(aFont.native_font_face().underline_thickness()) }); }