void editor_map::sanity_check() { int errors = 0; if (total_width() != static_cast<int>(tiles_.size())) { ERR_ED << "total_width is " << total_width() << " but tiles_.size() is " << tiles_.size() << "\n"; ++errors; } if (total_height() != static_cast<int>(tiles_[0].size())) { ERR_ED << "total_height is " << total_height() << " but tiles_[0].size() is " << tiles_.size() << "\n"; ++errors; } if (w() + 2 * border_size() != total_width()) { ERR_ED << "h is " << h_ << " and border_size is " << border_size() << " but total_width is " << total_width() << "\n"; ++errors; } if (h() + 2 * border_size() != total_height()) { ERR_ED << "w is " << w_ << " and border_size is " << border_size() << " but total_height is " << total_height() << "\n"; ++errors; } for (size_t i = 1; i < tiles_.size(); ++i) { if (tiles_[i].size() != tiles_[0].size()) { ERR_ED << "tiles_[ " << i << "] has size() " << tiles_[i].size() << " but tiles[0] has size() " << tiles_[0].size() << "\n"; ++errors; } } BOOST_FOREACH(const map_location& loc, selection_) { if (!on_board_with_border(loc)) { ERR_ED << "Off-map tile in selection: " << loc << "\n"; } } if (errors) { throw editor_map_integrity_error(); } }
void gamemap::read(const std::string& data, const bool allow_invalid) { tiles_ = t_translation::ter_map(); villages_.clear(); starting_positions_.clear(); if(data.empty()) { w_ = 0; h_ = 0; if(allow_invalid) return; } int offset = read_header(data); const std::string& data_only = std::string(data, offset); try { tiles_ = t_translation::read_game_map(data_only, starting_positions_, t_translation::coordinate{ border_size(), border_size() }); } catch(const t_translation::error& e) { // We re-throw the error but as map error. // Since all codepaths test for this, it's the least work. throw incorrect_map_format_error(e.message); } // Post processing on the map w_ = total_width() - 2 * border_size(); h_ = total_height() - 2 * border_size(); //Disabled since there are callcases which pass along a valid map header but empty //map data. Still, loading (and actually applying) an empty map causes problems later on. //Other callcases which need to load a dummy map use completely empty data :(. //VALIDATE((w_ >= 1 && h_ >= 1), "A map needs at least 1 tile, the map cannot be loaded."); for(int x = 0; x < total_width(); ++x) { for(int y = 0; y < total_height(); ++y) { // Is the terrain valid? t_translation::terrain_code t = tiles_.get(x, y); if(tdata_->map().count(t) == 0) { if(!tdata_->try_merge_terrains(t)) { std::stringstream ss; ss << "Unknown tile in map: (" << t_translation::write_terrain_code(t) << ") '" << t << "'"; throw incorrect_map_format_error(ss.str().c_str()); } } // Is it a village? if(x >= border_size() && y >= border_size() && x < total_width()- border_size() && y < total_height()- border_size() && tdata_->is_village(tiles_.get(x, y))) { villages_.push_back(map_location(x - border_size(), y - border_size())); } } } }
static void compute_punctuation_extent(TextNode * node) { int twidth; int nextwidth; int incwidth; node->height = normal_text_height; node->width = strlen(node->data.text); incwidth = twidth = XTextWidth(gTopOfGroupStack->cur_font, node->data.text, node->width); /* always check to see if there was some space in front of us */ if (gInLine && (node->space & FRONTSPACE)) twidth += inter_word_space; /* * now calcualte the width of the next one if it needs to be considered */ if (!(node->space & BACKSPACE)) nextwidth = total_width(node->next, Endtokens); else nextwidth = 0; if ((!(node->space & BACKSPACE)) && (text_x + twidth + nextwidth > right_margin) && gInLine) { start_newline(present_line_height, node); if (in_fricas_command) { text_x = indent + spadcom_indent; } else text_x = indent; } if (node->space & FRONTSPACE) text_x += inter_word_space; node->x = text_x; /* * Now try to see if we should leave space after myself. Always leave * space when there is space */ if (node->space & BACKSPACE) { switch (node->data.text[0]) { case '.': case '?': case '!': text_x += term_punct_space; break; } } text_x += incwidth; node->y = text_y - word_off_height; gInLine = 1; }
void for_each_loc(const F& f) const { for (int x = 0; x < total_width(); ++x) { for (int y = 0; y < total_height(); ++y) { f({ x, y , wml_loc()}); } } }
static void compute_dash_extent(TextNode *node) { int num_dashes; int twidth; int nextwidth; node->height = normal_text_height; num_dashes = strlen(node->data.text); if (num_dashes > 1) twidth = node->width = num_dashes * dash_width; else twidth = node->width = XTextWidth(gTopOfGroupStack->cur_font, node->data.text, 1); if (gInLine && node->space) twidth += inter_word_space; /* * Now what we should do is find all the things after us that have no * space in front and add there width on. */ nextwidth = total_width(node->next, Endtokens); /* * Should we start a new line? */ if (text_x + twidth + nextwidth > right_margin) { start_newline(present_line_height, node); if (in_fricas_command) { text_x = indent + spadcom_indent; } else text_x = indent; } /* * Now see if we am on the beginning of a line, and if not add some space * if we need to */ if (gInLine && node->space) text_x += inter_word_space; node->x = text_x; if (num_dashes > 1) node->y = text_y - dash_y; else node->y = text_y - word_off_height; text_x += node->width; gInLine = 1; return; }
void scrollBar_t::resize () { int delayed_init = 0; int window_sb_x = 0; if (term->option (Opt_scrollBar_right)) window_sb_x = term->szHint.width - total_width (); update_data (); if (!win) { /* create the scrollbar window */ win = XCreateSimpleWindow (term->dpy, term->parent[0], window_sb_x, 0, total_width (), term->szHint.height, 0, term->pix_colors[Color_fg], term->pix_colors[Color_border]); XDefineCursor (term->dpy, win, leftptr_cursor); XSelectInput (term->dpy, win, ExposureMask | ButtonPressMask | ButtonReleaseMask | Button1MotionMask | Button2MotionMask | Button3MotionMask); term->scrollbar_ev.start (term->display, win); delayed_init = 1; } else XMoveResizeWindow (term->dpy, win, window_sb_x, 0, total_width (), term->szHint.height); show (1); if (delayed_init) XMapWindow (term->dpy, win); }
bool editor_map::everything_selected() const { LOG_ED << selection_.size() << " " << total_width() * total_height() << "\n"; return static_cast<int>(selection_.size()) == total_width() * total_height(); }
bool on_map_noborder(const map_location& loc) const { return loc.wml_x() > 0 && loc.wml_x() < total_width() - 1 && loc.wml_y() > 0 && loc.wml_y() < total_height() - 1; }
bool on_map(const map_location& loc) const { return loc.wml_x() >= 0 && loc.wml_x() < total_width() && loc.wml_y() >= 0 && loc.wml_y() < total_height(); }
/** Effective map width. */ int w() const { return total_width() - 2; }