Merge pull request #23195 from Liangdi/master

support New TileSet Editor zooming use CTRL/CMD + MouseWheel
This commit is contained in:
Rémi Verschelde 2018-11-01 10:37:27 +01:00 committed by GitHub
commit c7928bc27f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 50 additions and 15 deletions

View file

@ -483,6 +483,11 @@ TileSetEditor::TileSetEditor(EditorNode *p_editor) {
//---------------
helper = memnew(TilesetEditorContext(this));
tile_names_opacity = 0;
// config scale
max_scale = 10.0f;
min_scale = 0.1f;
scale_ratio = 1.2f;
}
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
if (mm.is_valid()) {
@ -1448,23 +1462,11 @@ void TileSetEditor::_on_tool_clicked(int p_tool) {
}
}
} else if (p_tool == ZOOM_OUT) {
float scale = workspace->get_scale().x;
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);
}
_zoom_out();
} else if (p_tool == ZOOM_1) {
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);
_reset_zoom();
} else if (p_tool == ZOOM_IN) {
float scale = workspace->get_scale().x;
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);
_zoom_in();
} else if (p_tool == TOOL_SELECT) {
if (creating_shape) {
// Cancel Creation
@ -1503,6 +1505,31 @@ void TileSetEditor::_set_snap_sep(Vector2 p_val) {
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() {
if (get_current_tile() >= 0) {

View file

@ -141,6 +141,10 @@ class TileSetEditor : public Control {
EditMode edit_mode;
int current_tile;
float max_scale;
float min_scale;
float scale_ratio;
void update_texture_list();
void update_texture_list_icon();
@ -178,6 +182,10 @@ private:
void _set_snap_off(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_subtile(Vector2 coord, const Vector<Vector2> &other_highlighted = Vector<Vector2>());
void draw_tile_subdivision(int p_id, Color p_color) const;