Merge pull request #23195 from Liangdi/master
support New TileSet Editor zooming use CTRL/CMD + MouseWheel
This commit is contained in:
commit
c7928bc27f
2 changed files with 50 additions and 15 deletions
|
@ -483,6 +483,11 @@ TileSetEditor::TileSetEditor(EditorNode *p_editor) {
|
||||||
//---------------
|
//---------------
|
||||||
helper = memnew(TilesetEditorContext(this));
|
helper = memnew(TilesetEditorContext(this));
|
||||||
tile_names_opacity = 0;
|
tile_names_opacity = 0;
|
||||||
|
|
||||||
|
// config scale
|
||||||
|
max_scale = 10.0f;
|
||||||
|
min_scale = 0.1f;
|
||||||
|
scale_ratio = 1.2f;
|
||||||
}
|
}
|
||||||
|
|
||||||
TileSetEditor::~TileSetEditor() {
|
TileSetEditor::~TileSetEditor() {
|
||||||
|
@ -972,6 +977,15 @@ void TileSetEditor::_on_workspace_input(const Ref<InputEvent> &p_ie) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Mouse Wheel Event
|
||||||
|
const int _mouse_button_index = mb->get_button_index();
|
||||||
|
if (_mouse_button_index == BUTTON_WHEEL_UP && mb->get_control()) {
|
||||||
|
_zoom_in();
|
||||||
|
|
||||||
|
} else if (_mouse_button_index == BUTTON_WHEEL_DOWN && mb->get_control()) {
|
||||||
|
_zoom_out();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// Drag Middle Mouse
|
// Drag Middle Mouse
|
||||||
if (mm.is_valid()) {
|
if (mm.is_valid()) {
|
||||||
|
@ -1448,23 +1462,11 @@ void TileSetEditor::_on_tool_clicked(int p_tool) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (p_tool == ZOOM_OUT) {
|
} else if (p_tool == ZOOM_OUT) {
|
||||||
float scale = workspace->get_scale().x;
|
_zoom_out();
|
||||||
if (scale > 0.1) {
|
|
||||||
scale /= 2;
|
|
||||||
workspace->set_scale(Vector2(scale, scale));
|
|
||||||
workspace_container->set_custom_minimum_size(workspace->get_rect().size * scale);
|
|
||||||
workspace_overlay->set_custom_minimum_size(workspace->get_rect().size * scale);
|
|
||||||
}
|
|
||||||
} else if (p_tool == ZOOM_1) {
|
} else if (p_tool == ZOOM_1) {
|
||||||
workspace->set_scale(Vector2(1, 1));
|
_reset_zoom();
|
||||||
workspace_container->set_custom_minimum_size(workspace->get_rect().size);
|
|
||||||
workspace_overlay->set_custom_minimum_size(workspace->get_rect().size);
|
|
||||||
} else if (p_tool == ZOOM_IN) {
|
} else if (p_tool == ZOOM_IN) {
|
||||||
float scale = workspace->get_scale().x;
|
_zoom_in();
|
||||||
scale *= 2;
|
|
||||||
workspace->set_scale(Vector2(scale, scale));
|
|
||||||
workspace_container->set_custom_minimum_size(workspace->get_rect().size * scale);
|
|
||||||
workspace_overlay->set_custom_minimum_size(workspace->get_rect().size * scale);
|
|
||||||
} else if (p_tool == TOOL_SELECT) {
|
} else if (p_tool == TOOL_SELECT) {
|
||||||
if (creating_shape) {
|
if (creating_shape) {
|
||||||
// Cancel Creation
|
// Cancel Creation
|
||||||
|
@ -1503,6 +1505,31 @@ void TileSetEditor::_set_snap_sep(Vector2 p_val) {
|
||||||
workspace->update();
|
workspace->update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TileSetEditor::_zoom_in() {
|
||||||
|
float scale = workspace->get_scale().x;
|
||||||
|
if (scale < max_scale) {
|
||||||
|
scale *= scale_ratio;
|
||||||
|
workspace->set_scale(Vector2(scale, scale));
|
||||||
|
workspace_container->set_custom_minimum_size(workspace->get_rect().size * scale);
|
||||||
|
workspace_overlay->set_custom_minimum_size(workspace->get_rect().size * scale);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void TileSetEditor::_zoom_out() {
|
||||||
|
|
||||||
|
float scale = workspace->get_scale().x;
|
||||||
|
if (scale > min_scale) {
|
||||||
|
scale /= scale_ratio;
|
||||||
|
workspace->set_scale(Vector2(scale, scale));
|
||||||
|
workspace_container->set_custom_minimum_size(workspace->get_rect().size * scale);
|
||||||
|
workspace_overlay->set_custom_minimum_size(workspace->get_rect().size * scale);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void TileSetEditor::_reset_zoom() {
|
||||||
|
workspace->set_scale(Vector2(1, 1));
|
||||||
|
workspace_container->set_custom_minimum_size(workspace->get_rect().size);
|
||||||
|
workspace_overlay->set_custom_minimum_size(workspace->get_rect().size);
|
||||||
|
}
|
||||||
|
|
||||||
void TileSetEditor::draw_highlight_current_tile() {
|
void TileSetEditor::draw_highlight_current_tile() {
|
||||||
|
|
||||||
if (get_current_tile() >= 0) {
|
if (get_current_tile() >= 0) {
|
||||||
|
|
|
@ -141,6 +141,10 @@ class TileSetEditor : public Control {
|
||||||
EditMode edit_mode;
|
EditMode edit_mode;
|
||||||
int current_tile;
|
int current_tile;
|
||||||
|
|
||||||
|
float max_scale;
|
||||||
|
float min_scale;
|
||||||
|
float scale_ratio;
|
||||||
|
|
||||||
void update_texture_list();
|
void update_texture_list();
|
||||||
void update_texture_list_icon();
|
void update_texture_list_icon();
|
||||||
|
|
||||||
|
@ -178,6 +182,10 @@ private:
|
||||||
void _set_snap_off(Vector2 p_val);
|
void _set_snap_off(Vector2 p_val);
|
||||||
void _set_snap_sep(Vector2 p_val);
|
void _set_snap_sep(Vector2 p_val);
|
||||||
|
|
||||||
|
void _zoom_in();
|
||||||
|
void _zoom_out();
|
||||||
|
void _reset_zoom();
|
||||||
|
|
||||||
void draw_highlight_current_tile();
|
void draw_highlight_current_tile();
|
||||||
void draw_highlight_subtile(Vector2 coord, const Vector<Vector2> &other_highlighted = Vector<Vector2>());
|
void draw_highlight_subtile(Vector2 coord, const Vector<Vector2> &other_highlighted = Vector<Vector2>());
|
||||||
void draw_tile_subdivision(int p_id, Color p_color) const;
|
void draw_tile_subdivision(int p_id, Color p_color) const;
|
||||||
|
|
Loading…
Reference in a new issue