Fix position of tile names in TileSet editor when zooming in/out

Fixes #27713.

(cherry picked from commit d2a7624687)
This commit is contained in:
Michael Alexsander Silva Dias 2019-04-11 19:01:18 -03:00 committed by Rémi Verschelde
parent 965b13d62a
commit 7ddd4f7232
1 changed files with 20 additions and 19 deletions

View File

@ -996,25 +996,26 @@ void TileSetEditor::_on_workspace_overlay_draw() {
tileset->get_tile_list(tiles); tileset->get_tile_list(tiles);
for (List<int>::Element *E = tiles->front(); E; E = E->next()) { for (List<int>::Element *E = tiles->front(); E; E = E->next()) {
int t_id = E->get(); int t_id = E->get();
if (tileset->tile_get_texture(t_id)->get_rid() == current_texture_rid) { if (tileset->tile_get_texture(t_id)->get_rid() != current_texture_rid)
Rect2i region = tileset->tile_get_region(t_id); continue;
region.position += WORKSPACE_MARGIN;
region.position *= workspace->get_scale().x; Rect2 region = tileset->tile_get_region(t_id);
Color c; region.position += WORKSPACE_MARGIN;
if (tileset->tile_get_tile_mode(t_id) == TileSet::SINGLE_TILE) region.position *= workspace->get_scale().x;
c = COLOR_SINGLE; Color c;
else if (tileset->tile_get_tile_mode(t_id) == TileSet::AUTO_TILE) if (tileset->tile_get_tile_mode(t_id) == TileSet::SINGLE_TILE)
c = COLOR_AUTOTILE; c = COLOR_SINGLE;
else if (tileset->tile_get_tile_mode(t_id) == TileSet::ATLAS_TILE) else if (tileset->tile_get_tile_mode(t_id) == TileSet::AUTO_TILE)
c = COLOR_ATLAS; c = COLOR_AUTOTILE;
String tile_id_name = String::num(t_id, 0) + ": " + tileset->tile_get_name(t_id); else if (tileset->tile_get_tile_mode(t_id) == TileSet::ATLAS_TILE)
Ref<Font> font = get_font("font", "Label"); c = COLOR_ATLAS;
region.set_size(font->get_string_size(tile_id_name)); String tile_id_name = String::num(t_id, 0) + ": " + tileset->tile_get_name(t_id);
workspace_overlay->draw_rect(region, c); Ref<Font> font = get_font("font", "Label");
region.position.y += region.size.y - 2; region.set_size(font->get_string_size(tile_id_name));
c = Color(0.1, 0.1, 0.1); workspace_overlay->draw_rect(region, c);
workspace_overlay->draw_string(font, region.position, tile_id_name, c); region.position.y += region.size.y - 2;
} c = Color(0.1, 0.1, 0.1);
workspace_overlay->draw_string(font, region.position, tile_id_name, c);
} }
} }