Skip to content

Commit

Permalink
Use more reasonable precision when dragging handles (#869)
Browse files Browse the repository at this point in the history
  • Loading branch information
MewPurPur authored Aug 19, 2024
1 parent 7af24ad commit 509bb78
Show file tree
Hide file tree
Showing 10 changed files with 53 additions and 119 deletions.
4 changes: 2 additions & 2 deletions src/ui_parts/display.gd
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,9 @@ func _on_reference_pressed() -> void:

func _on_visuals_button_pressed() -> void:
var btn_arr: Array[Button] = [
ContextPopup.create_checkbox(TranslationServer.translate("Show Grid"),
ContextPopup.create_checkbox(TranslationServer.translate("Show grid"),
toggle_grid_visuals, grid_visuals.visible, "view_show_grid"),
ContextPopup.create_checkbox(TranslationServer.translate("Show Handles"),
ContextPopup.create_checkbox(TranslationServer.translate("Show handles"),
toggle_handles_visuals, controls.visible, "view_show_handles"),
ContextPopup.create_checkbox(TranslationServer.translate("Rasterized SVG"),
toggle_rasterization, viewport.display_texture.rasterized,
Expand Down
28 changes: 16 additions & 12 deletions src/ui_parts/handles_manager.gd
Original file line number Diff line number Diff line change
Expand Up @@ -640,32 +640,22 @@ func _unhandled_input(event: InputEvent) -> void:
Indications.clear_hovered()
Indications.clear_inner_hovered()

var snap_enabled := GlobalSettings.savedata.snap > 0.0
var snap_size := absf(GlobalSettings.savedata.snap)
var snap_vector := Vector2(snap_size, snap_size)

if event is InputEventMouseMotion:
# Allow moving view while dragging handle.
if event.button_mask & MOUSE_BUTTON_MASK_MIDDLE:
return

should_deselect_all = false
var event_pos: Vector2 = event.position / Indications.zoom +\
get_parent().view.position
if is_instance_valid(dragged_handle):
# Move the handle that's being dragged.
if snap_enabled:
event_pos = event_pos.snapped(snap_vector)
var event_pos := get_event_pos(event)
var new_pos := dragged_handle.transform.affine_inverse() *\
SVG.root_element.world_to_canvas(event_pos)
dragged_handle.set_pos(new_pos)
was_handle_moved = true
accept_event()
elif event is InputEventMouseButton:
var event_pos: Vector2 = event.position / Indications.zoom +\
get_parent().view.position
if snap_enabled:
event_pos = event_pos.snapped(snap_vector)
var event_pos := get_event_pos(event)

if event.button_index == MOUSE_BUTTON_LEFT:
# React to LMB actions.
Expand Down Expand Up @@ -736,6 +726,20 @@ func find_nearest_handle(event_pos: Vector2) -> Handle:
nearest_handle = handle
return nearest_handle

func get_event_pos(event: InputEvent) -> Vector2:
var snap_enabled := GlobalSettings.savedata.snap > 0.0
var snap_size := absf(GlobalSettings.savedata.snap)
var snap_vector := Vector2(snap_size, snap_size)

var event_pos: Vector2 = event.position / Indications.zoom +\
get_parent().view.position
var precision := maxi(ceili(-log(1.0 / Indications.zoom) / log(10)), 0)
event_pos = event_pos.snapped(Vector2(0.1 ** precision, 0.1 ** precision))
if snap_enabled:
event_pos = event_pos.snapped(snap_vector)
return event_pos


func _on_handle_added() -> void:
if not get_viewport_rect().has_point(get_viewport().get_mouse_position()):
if not Indications.semi_selected_xid.is_empty():
Expand Down
16 changes: 4 additions & 12 deletions translations/GodSVG.pot
Original file line number Diff line number Diff line change
Expand Up @@ -235,12 +235,12 @@ msgstr ""
msgid "Overlay reference"
msgstr ""

#: src/ui_parts/display.gd
msgid "Show Grid"
#: src/ui_parts/display.gd src/utils/TranslationUtils.gd
msgid "Show grid"
msgstr ""

#: src/ui_parts/display.gd
msgid "Show Handles"
#: src/ui_parts/display.gd src/utils/TranslationUtils.gd
msgid "Show handles"
msgstr ""

#: src/ui_parts/display.gd
Expand Down Expand Up @@ -897,14 +897,6 @@ msgstr ""
msgid "Zoom reset"
msgstr ""

#: src/utils/TranslationUtils.gd
msgid "Show grid"
msgstr ""

#: src/utils/TranslationUtils.gd
msgid "Show handles"
msgstr ""

#: src/utils/TranslationUtils.gd
msgid "Show rasterized SVG"
msgstr ""
Expand Down
16 changes: 4 additions & 12 deletions translations/bg.po
Original file line number Diff line number Diff line change
Expand Up @@ -237,12 +237,12 @@ msgstr "Покажни справочното изображение"
msgid "Overlay reference"
msgstr "Насложи справочното изображение"

#: src/ui_parts/display.gd
msgid "Show Grid"
#: src/ui_parts/display.gd src/utils/TranslationUtils.gd
msgid "Show grid"
msgstr "Покажи решетката"

#: src/ui_parts/display.gd
msgid "Show Handles"
#: src/ui_parts/display.gd src/utils/TranslationUtils.gd
msgid "Show handles"
msgstr "Покажи дръжките"

#: src/ui_parts/display.gd
Expand Down Expand Up @@ -911,14 +911,6 @@ msgstr "Намали"
msgid "Zoom reset"
msgstr "Рестартирай мащаба"

#: src/utils/TranslationUtils.gd
msgid "Show grid"
msgstr "Покажи решетката"

#: src/utils/TranslationUtils.gd
msgid "Show handles"
msgstr "Покажи дръжките"

#: src/utils/TranslationUtils.gd
msgid "Show rasterized SVG"
msgstr "Покажи растеризиран SVG"
Expand Down
19 changes: 4 additions & 15 deletions translations/de.po
Original file line number Diff line number Diff line change
Expand Up @@ -238,12 +238,12 @@ msgstr "Referenz anzeigen"
msgid "Overlay reference"
msgstr "Referenz überblenden"

#: src/ui_parts/display.gd
msgid "Show Grid"
#: src/ui_parts/display.gd src/utils/TranslationUtils.gd
msgid "Show grid"
msgstr "Raster anzeigen"

#: src/ui_parts/display.gd
msgid "Show Handles"
#: src/ui_parts/display.gd src/utils/TranslationUtils.gd
msgid "Show handles"
msgstr "Griffe anzeigen"

#: src/ui_parts/display.gd
Expand Down Expand Up @@ -912,14 +912,6 @@ msgstr "Herauszoomen"
msgid "Zoom reset"
msgstr "Zoom zurücksetzen"

#: src/utils/TranslationUtils.gd
msgid "Show grid"
msgstr "Raster anzeigen"

#: src/utils/TranslationUtils.gd
msgid "Show handles"
msgstr "Griffe anzeigen"

#: src/utils/TranslationUtils.gd
msgid "Show rasterized SVG"
msgstr "Rasterisiertes SVG anzeigen"
Expand Down Expand Up @@ -1004,9 +996,6 @@ msgstr "Kubischer Bezier to"
msgid "Shorthand Cubic Bezier to"
msgstr "Kurzhand-Kubischer Bezier to"

#~ msgid "No id attribute defined."
#~ msgstr "Kein id Attribut definiert."

#~ msgid "General"
#~ msgstr "Allgemein"

Expand Down
16 changes: 4 additions & 12 deletions translations/en.po
Original file line number Diff line number Diff line change
Expand Up @@ -235,12 +235,12 @@ msgstr ""
msgid "Overlay reference"
msgstr ""

#: src/ui_parts/display.gd
msgid "Show Grid"
#: src/ui_parts/display.gd src/utils/TranslationUtils.gd
msgid "Show grid"
msgstr ""

#: src/ui_parts/display.gd
msgid "Show Handles"
#: src/ui_parts/display.gd src/utils/TranslationUtils.gd
msgid "Show handles"
msgstr ""

#: src/ui_parts/display.gd
Expand Down Expand Up @@ -897,14 +897,6 @@ msgstr ""
msgid "Zoom reset"
msgstr ""

#: src/utils/TranslationUtils.gd
msgid "Show grid"
msgstr ""

#: src/utils/TranslationUtils.gd
msgid "Show handles"
msgstr ""

#: src/utils/TranslationUtils.gd
msgid "Show rasterized SVG"
msgstr ""
Expand Down
25 changes: 7 additions & 18 deletions translations/nl.po
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,9 @@ msgid "This group has only one element."
msgstr "Deze groep heeft alleen een element."

#: src/data_classes/ElementLinearGradient.gd
msgid "No id attribute defined."
msgstr "Geen id attribuut gedefinieert."
#: src/data_classes/ElementRadialGradient.gd
msgid "No \"id\" attribute defined."
msgstr "Geen \"id\" attribuut gedefineerd."

#: src/data_classes/ElementLinearGradient.gd
#: src/data_classes/ElementRadialGradient.gd
Expand All @@ -136,10 +137,6 @@ msgstr "Geen <stop> elementen onder deze kleurovergang."
msgid "This gradient is a solid color."
msgstr "Deze kleurovergang is een vaste kleur."

#: src/data_classes/ElementRadialGradient.gd
msgid "No \"id\" attribute defined."
msgstr "Geen \"id\" attribuut gedefineerd."

#: src/data_classes/SVGParser.gd
msgid "Doesn’t describe an SVG."
msgstr "Beschrijft geen SVG."
Expand Down Expand Up @@ -241,12 +238,12 @@ msgstr "Referentie weergeven"
msgid "Overlay reference"
msgstr "Referentie overlappen"

#: src/ui_parts/display.gd
msgid "Show Grid"
#: src/ui_parts/display.gd src/utils/TranslationUtils.gd
msgid "Show grid"
msgstr "Rooster weergeven"

#: src/ui_parts/display.gd
msgid "Show Handles"
#: src/ui_parts/display.gd src/utils/TranslationUtils.gd
msgid "Show handles"
msgstr "Hendelgrepen weergeven"

#: src/ui_parts/display.gd
Expand Down Expand Up @@ -914,14 +911,6 @@ msgstr "Uitzoomen"
msgid "Zoom reset"
msgstr "Zoom opnieuw zetten"

#: src/utils/TranslationUtils.gd
msgid "Show grid"
msgstr "Rooster weergeven"

#: src/utils/TranslationUtils.gd
msgid "Show handles"
msgstr "Hendelgrepen weergeven"

#: src/utils/TranslationUtils.gd
msgid "Show rasterized SVG"
msgstr "Gerasterd SVG weergeven"
Expand Down
16 changes: 4 additions & 12 deletions translations/ru.po
Original file line number Diff line number Diff line change
Expand Up @@ -241,12 +241,12 @@ msgstr "Показать референс-изображение"
msgid "Overlay reference"
msgstr "Наложить референс-изображение"

#: src/ui_parts/display.gd
msgid "Show Grid"
#: src/ui_parts/display.gd src/utils/TranslationUtils.gd
msgid "Show grid"
msgstr "Показать сетку"

#: src/ui_parts/display.gd
msgid "Show Handles"
#: src/ui_parts/display.gd src/utils/TranslationUtils.gd
msgid "Show handles"
msgstr "Показать ручки редактирования"

#: src/ui_parts/display.gd
Expand Down Expand Up @@ -933,14 +933,6 @@ msgstr "Отдалить масштаб"
msgid "Zoom reset"
msgstr "Сбросить масштаб"

#: src/utils/TranslationUtils.gd
msgid "Show grid"
msgstr "Показать сетку"

#: src/utils/TranslationUtils.gd
msgid "Show handles"
msgstr "Показать ручки редактирования"

#: src/utils/TranslationUtils.gd
msgid "Show rasterized SVG"
msgstr "Показать растеризованый SVG"
Expand Down
16 changes: 4 additions & 12 deletions translations/uk.po
Original file line number Diff line number Diff line change
Expand Up @@ -241,12 +241,12 @@ msgstr ""
msgid "Overlay reference"
msgstr ""

#: src/ui_parts/display.gd
msgid "Show Grid"
#: src/ui_parts/display.gd src/utils/TranslationUtils.gd
msgid "Show grid"
msgstr "Показати ґратку"

#: src/ui_parts/display.gd
msgid "Show Handles"
#: src/ui_parts/display.gd src/utils/TranslationUtils.gd
msgid "Show handles"
msgstr "Показати ручки редагування"

#: src/ui_parts/display.gd
Expand Down Expand Up @@ -937,14 +937,6 @@ msgstr "Зменшити масштаб"
msgid "Zoom reset"
msgstr "Скинути масштаб"

#: src/utils/TranslationUtils.gd
msgid "Show grid"
msgstr "Показати ґратку"

#: src/utils/TranslationUtils.gd
msgid "Show handles"
msgstr "Показати ручки редагування"

#: src/utils/TranslationUtils.gd
msgid "Show rasterized SVG"
msgstr "Показати растеризуваний SVG"
Expand Down
16 changes: 4 additions & 12 deletions translations/zh.po
Original file line number Diff line number Diff line change
Expand Up @@ -237,12 +237,12 @@ msgstr "显示参考"
msgid "Overlay reference"
msgstr "置顶参考"

#: src/ui_parts/display.gd
msgid "Show Grid"
#: src/ui_parts/display.gd src/utils/TranslationUtils.gd
msgid "Show grid"
msgstr "显示网格"

#: src/ui_parts/display.gd
msgid "Show Handles"
#: src/ui_parts/display.gd src/utils/TranslationUtils.gd
msgid "Show handles"
msgstr "显示拖拽框"

#: src/ui_parts/display.gd
Expand Down Expand Up @@ -925,14 +925,6 @@ msgstr "缩小"
msgid "Zoom reset"
msgstr "重置缩放"

#: src/utils/TranslationUtils.gd
msgid "Show grid"
msgstr "显示网格"

#: src/utils/TranslationUtils.gd
msgid "Show handles"
msgstr "显示拖拽框"

#: src/utils/TranslationUtils.gd
msgid "Show rasterized SVG"
msgstr "显示光栅化 SVG"
Expand Down

0 comments on commit 509bb78

Please sign in to comment.