Merge pull request #95337 from kleonc/tile_set_editor_fix_transposed_polygons_editing
Fix polygon drawing for transposed tiles in `TileSet` editor
This commit is contained in:
commit
60b0b5cd42
4 changed files with 29 additions and 15 deletions
|
@ -372,7 +372,7 @@ void TileAtlasView::_draw_base_tiles_shape_grid() {
|
|||
for (int i = 0; i < tile_set_atlas_source->get_tiles_count(); i++) {
|
||||
Vector2i tile_id = tile_set_atlas_source->get_tile_id(i);
|
||||
Vector2 in_tile_base_offset = tile_set_atlas_source->get_tile_data(tile_id, 0)->get_texture_origin();
|
||||
if (tile_set_atlas_source->is_position_in_tile_texture_region(tile_id, 0, -tile_shape_size / 2) && tile_set_atlas_source->is_position_in_tile_texture_region(tile_id, 0, tile_shape_size / 2 - Vector2(1, 1))) {
|
||||
if (tile_set_atlas_source->is_rect_in_tile_texture_region(tile_id, 0, Rect2(Vector2(-tile_shape_size) / 2, tile_shape_size))) {
|
||||
for (int frame = 0; frame < tile_set_atlas_source->get_tile_animation_frames_count(tile_id); frame++) {
|
||||
Color color = grid_color;
|
||||
if (frame > 0) {
|
||||
|
|
|
@ -165,10 +165,14 @@ void GenericTilePolygonEditor::_base_control_draw() {
|
|||
base_control->draw_set_transform_matrix(xform);
|
||||
|
||||
// Draw fill rect under texture region.
|
||||
Rect2 texture_rect(-background_region.size / 2, background_region.size);
|
||||
Rect2 texture_rect(Vector2(), background_region.size);
|
||||
if (tile_data) {
|
||||
texture_rect.position -= tile_data->get_texture_origin();
|
||||
if (tile_data->get_transpose()) {
|
||||
texture_rect.size = Size2(texture_rect.size.y, texture_rect.size.x);
|
||||
}
|
||||
}
|
||||
texture_rect.position -= texture_rect.size / 2; // Half-size offset must be applied after transposing.
|
||||
base_control->draw_rect(texture_rect, Color(1, 1, 1, 0.3));
|
||||
|
||||
// Draw the background.
|
||||
|
@ -180,18 +184,14 @@ void GenericTilePolygonEditor::_base_control_draw() {
|
|||
if (tile_data->get_flip_v()) {
|
||||
region_size.y = -region_size.y;
|
||||
}
|
||||
base_control->draw_texture_rect_region(background_atlas_source->get_texture(), Rect2(-background_region.size / 2 - tile_data->get_texture_origin(), region_size), background_region, tile_data->get_modulate(), tile_data->get_transpose());
|
||||
// Destination rect position must account for transposing, size must not.
|
||||
base_control->draw_texture_rect_region(background_atlas_source->get_texture(), Rect2(texture_rect.position, region_size), background_region, tile_data->get_modulate(), tile_data->get_transpose());
|
||||
}
|
||||
|
||||
// Compute and draw the grid area.
|
||||
Rect2 grid_area = Rect2(-base_tile_size / 2, base_tile_size);
|
||||
if (tile_data) {
|
||||
grid_area.expand_to(-background_region.get_size() / 2 - tile_data->get_texture_origin());
|
||||
grid_area.expand_to(background_region.get_size() / 2 - tile_data->get_texture_origin());
|
||||
} else {
|
||||
grid_area.expand_to(-background_region.get_size() / 2);
|
||||
grid_area.expand_to(background_region.get_size() / 2);
|
||||
}
|
||||
grid_area.expand_to(texture_rect.position);
|
||||
grid_area.expand_to(texture_rect.get_end());
|
||||
base_control->draw_rect(grid_area, Color(1, 1, 1, 0.3), false);
|
||||
|
||||
// Draw grid.
|
||||
|
@ -1400,10 +1400,8 @@ void TileDataTextureOriginEditor::draw_over_tile(CanvasItem *p_canvas_item, Tran
|
|||
|
||||
TileSetSource *source = *(tile_set->get_source(p_cell.source_id));
|
||||
TileSetAtlasSource *atlas_source = Object::cast_to<TileSetAtlasSource>(source);
|
||||
if (atlas_source->is_position_in_tile_texture_region(p_cell.get_atlas_coords(), p_cell.alternative_tile, -tile_set_tile_size / 2) && atlas_source->is_position_in_tile_texture_region(p_cell.get_atlas_coords(), p_cell.alternative_tile, tile_set_tile_size / 2 - Vector2(1, 1))) {
|
||||
Transform2D tile_xform;
|
||||
tile_xform.set_scale(tile_set_tile_size);
|
||||
tile_set->draw_tile_shape(p_canvas_item, p_transform * tile_xform, color);
|
||||
if (atlas_source->is_rect_in_tile_texture_region(p_cell.get_atlas_coords(), p_cell.alternative_tile, Rect2(Vector2(-tile_set_tile_size) / 2, tile_set_tile_size))) {
|
||||
tile_set->draw_tile_shape(p_canvas_item, p_transform.scaled_local(tile_set_tile_size), color);
|
||||
}
|
||||
|
||||
if (atlas_source->is_position_in_tile_texture_region(p_cell.get_atlas_coords(), p_cell.alternative_tile, Vector2())) {
|
||||
|
|
|
@ -5275,11 +5275,26 @@ Rect2i TileSetAtlasSource::get_tile_texture_region(Vector2i p_atlas_coords, int
|
|||
|
||||
bool TileSetAtlasSource::is_position_in_tile_texture_region(const Vector2i p_atlas_coords, int p_alternative_tile, Vector2 p_position) const {
|
||||
Size2 size = get_tile_texture_region(p_atlas_coords).size;
|
||||
Rect2 rect = Rect2(-size / 2 - get_tile_data(p_atlas_coords, p_alternative_tile)->get_texture_origin(), size);
|
||||
TileData *tile_data = get_tile_data(p_atlas_coords, p_alternative_tile);
|
||||
if (tile_data->get_transpose()) {
|
||||
size = Size2(size.y, size.x);
|
||||
}
|
||||
Rect2 rect = Rect2(-size / 2 - tile_data->get_texture_origin(), size);
|
||||
|
||||
return rect.has_point(p_position);
|
||||
}
|
||||
|
||||
bool TileSetAtlasSource::is_rect_in_tile_texture_region(const Vector2i p_atlas_coords, int p_alternative_tile, Rect2 p_rect) const {
|
||||
Size2 size = get_tile_texture_region(p_atlas_coords).size;
|
||||
TileData *tile_data = get_tile_data(p_atlas_coords, p_alternative_tile);
|
||||
if (tile_data->get_transpose()) {
|
||||
size = Size2(size.y, size.x);
|
||||
}
|
||||
Rect2 rect = Rect2(-size / 2 - tile_data->get_texture_origin(), size);
|
||||
|
||||
return p_rect.intersection(rect) == p_rect;
|
||||
}
|
||||
|
||||
int TileSetAtlasSource::alternative_no_transform(int p_alternative_id) {
|
||||
return p_alternative_id & ~(TRANSFORM_FLIP_H | TRANSFORM_FLIP_V | TRANSFORM_TRANSPOSE);
|
||||
}
|
||||
|
|
|
@ -763,6 +763,7 @@ public:
|
|||
Vector2i get_atlas_grid_size() const;
|
||||
Rect2i get_tile_texture_region(Vector2i p_atlas_coords, int p_frame = 0) const;
|
||||
bool is_position_in_tile_texture_region(const Vector2i p_atlas_coords, int p_alternative_tile, Vector2 p_position) const;
|
||||
bool is_rect_in_tile_texture_region(const Vector2i p_atlas_coords, int p_alternative_tile, Rect2 p_rect) const;
|
||||
|
||||
static int alternative_no_transform(int p_alternative_id);
|
||||
|
||||
|
|
Loading…
Reference in a new issue