Editor: let the help text switch between the top and bottom of the screen

If the northmost hexes of the map are visible, put the text on the bottom; if
the southmost are visible, put it on the top. Also, make the text smaller if
it's very wide.

It used to be fixed to the bottom of the screen, but this meant that it always
obscured the southmost hexes of the map, and the only way to avoid that is to
scroll east/west, or to add an extra row on the south. Similarly, having it at
the very top obscures the northmost hexes.

Moving it to any fixed location that isn't the edge of the screen makes it
possible to edit all the hexes, but also makes it more annoying when working
elsewhere on the map; that trade-off was rejected in review.

For very small maps, it will be at the bottom of the screen in the border
outside the map area. For any screen resolution there will be a specific
map-height that still has the old issue, but that's an improvement on it
happening for every map size.
This commit is contained in:
Steve Cotton 2023-02-06 06:45:59 +01:00 committed by Steve Cotton
parent 76306d3fb6
commit 29d86d2c36
3 changed files with 29 additions and 3 deletions

View file

@ -0,0 +1,2 @@
### Editor
* Scrolling the map north or south can move the text that overlays the map, so it doesn't always obscure the southmost hexes of the map. (issue #6422}

View file

@ -71,6 +71,22 @@ void editor_display::rebuild_terrain(const map_location &loc) {
void editor_display::pre_draw()
{
// If we're showing hexes near the north of the map, put the help string at the bottom of the screen.
// Otherwise, put it at the top.
if(help_handle_ != 0) {
const bool place_at_top = get_visible_hexes().top[0] > 2;
if(place_at_top != help_string_at_top_) {
const auto& r = font::get_floating_label_rect(help_handle_);
double delta = map_outside_area().h - r.h;
if(place_at_top) {
font::move_floating_label(help_handle_, 0.0, -delta);
} else {
font::move_floating_label(help_handle_, 0.0, delta);
}
help_string_at_top_ = place_at_top;
}
}
}
image::TYPE editor_display::get_image_type(const map_location& loc)
@ -152,7 +168,7 @@ void editor_display::set_help_string(const std::string& str)
int size = font::SIZE_LARGE;
while(size > 0) {
if(font::pango_line_width(str, size) > video().get_width()) {
if(font::pango_line_width(str, size) * 2 > video().get_width()) {
size--;
} else {
break;
@ -169,6 +185,9 @@ void editor_display::set_help_string(const std::string& str)
help_handle_ = font::add_floating_label(flabel);
// Put the label near the bottom of the screen. In pre_draw it'll be moved to the top if the
// user is editing hexes at the south edge of the map.
help_string_at_top_ = false;
const auto& r = font::get_floating_label_rect(help_handle_);
font::move_floating_label(help_handle_, 0.0, -double(r.h));
}

View file

@ -43,8 +43,7 @@ public:
}
/**
* Displays a help string with the given text. A 'help string' is like a tooltip,
* but appears at the bottom of the screen so as to not be intrusive.
* Sets and shows the tooltip-like text at the top or bottom of the map area.
*
* @param str The text to display.
*/
@ -76,6 +75,12 @@ protected:
private:
/** ID of the floating label that's controlled by set_help_string() / clear_help_string(). */
int help_handle_ = 0;
/**
* Ignored when help_handle_ == 0. Othewise, true if the help label obscures the
* northern hexes in the map area, false if it's over the southern hexes instead.
*/
bool help_string_at_top_ = false;
};
} //end namespace editor