mirror of
https://github.com/Orama-Interactive/Pixelorama.git
synced 2025-02-22 05:23:14 +00:00
Fix pivot drag not working in the Web version
This commit is contained in:
parent
dfc8499d06
commit
42942d2c0a
1 changed files with 25 additions and 20 deletions
|
@ -3,6 +3,7 @@ extends ImageEffect
|
||||||
var live_preview: bool = true
|
var live_preview: bool = true
|
||||||
var shader: Shader = preload("res://src/Shaders/Rotation.shader")
|
var shader: Shader = preload("res://src/Shaders/Rotation.shader")
|
||||||
var pivot := Vector2.INF
|
var pivot := Vector2.INF
|
||||||
|
var drag_pivot := false
|
||||||
|
|
||||||
onready var type_option_button: OptionButton = $VBoxContainer/HBoxContainer2/TypeOptionButton
|
onready var type_option_button: OptionButton = $VBoxContainer/HBoxContainer2/TypeOptionButton
|
||||||
onready var pivot_indicator: Control = $VBoxContainer/AspectRatioContainer/Indicator
|
onready var pivot_indicator: Control = $VBoxContainer/AspectRatioContainer/Indicator
|
||||||
|
@ -10,8 +11,8 @@ onready var x_pivot: SpinBox = $VBoxContainer/Pivot/TitleButtons/XPivot
|
||||||
onready var y_pivot: SpinBox = $VBoxContainer/Pivot/TitleButtons/YPivot
|
onready var y_pivot: SpinBox = $VBoxContainer/Pivot/TitleButtons/YPivot
|
||||||
onready var angle_hslider: HSlider = $VBoxContainer/AngleOptions/AngleHSlider
|
onready var angle_hslider: HSlider = $VBoxContainer/AngleOptions/AngleHSlider
|
||||||
onready var angle_spinbox: SpinBox = $VBoxContainer/AngleOptions/AngleSpinBox
|
onready var angle_spinbox: SpinBox = $VBoxContainer/AngleOptions/AngleSpinBox
|
||||||
onready var wait_apply_timer = $WaitApply
|
onready var wait_apply_timer: Timer = $WaitApply
|
||||||
onready var wait_time_spinbox = $VBoxContainer/WaitSettings/WaitTime
|
onready var wait_time_spinbox: SpinBox = $VBoxContainer/WaitSettings/WaitTime
|
||||||
|
|
||||||
|
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
|
@ -30,6 +31,7 @@ func set_nodes() -> void:
|
||||||
|
|
||||||
|
|
||||||
func _about_to_show() -> void:
|
func _about_to_show() -> void:
|
||||||
|
drag_pivot = false
|
||||||
if pivot == Vector2.INF:
|
if pivot == Vector2.INF:
|
||||||
decide_pivot()
|
decide_pivot()
|
||||||
confirmed = false
|
confirmed = false
|
||||||
|
@ -139,7 +141,7 @@ func _on_SpinBox_value_changed(_value: float) -> void:
|
||||||
|
|
||||||
func _on_TypeOptionButton_item_selected(_id: int) -> void:
|
func _on_TypeOptionButton_item_selected(_id: int) -> void:
|
||||||
if type_option_button.text == "Nearest neighbour (Shader)":
|
if type_option_button.text == "Nearest neighbour (Shader)":
|
||||||
var sm = ShaderMaterial.new()
|
var sm := ShaderMaterial.new()
|
||||||
sm.shader = shader
|
sm.shader = shader
|
||||||
preview.set_material(sm)
|
preview.set_material(sm)
|
||||||
else:
|
else:
|
||||||
|
@ -203,14 +205,14 @@ func _on_Pivot_value_changed(value: float, is_x: bool) -> void:
|
||||||
func _on_Indicator_draw() -> void:
|
func _on_Indicator_draw() -> void:
|
||||||
var img_size := preview_image.get_size()
|
var img_size := preview_image.get_size()
|
||||||
# find the scale using the larger measurement
|
# find the scale using the larger measurement
|
||||||
var ratio = pivot_indicator.rect_size / img_size
|
var ratio := pivot_indicator.rect_size / img_size
|
||||||
# we need to set the scale according to the larger side
|
# we need to set the scale according to the larger side
|
||||||
var conversion_scale: float
|
var conversion_scale: float
|
||||||
if img_size.x > img_size.y:
|
if img_size.x > img_size.y:
|
||||||
conversion_scale = ratio.x
|
conversion_scale = ratio.x
|
||||||
else:
|
else:
|
||||||
conversion_scale = ratio.y
|
conversion_scale = ratio.y
|
||||||
var pivot_position = pivot * conversion_scale
|
var pivot_position := pivot * conversion_scale
|
||||||
pivot_indicator.draw_arc(pivot_position, 2, 0, 360, 360, Color.yellow, 0.5)
|
pivot_indicator.draw_arc(pivot_position, 2, 0, 360, 360, Color.yellow, 0.5)
|
||||||
pivot_indicator.draw_arc(pivot_position, 6, 0, 360, 360, Color.white, 0.5)
|
pivot_indicator.draw_arc(pivot_position, 6, 0, 360, 360, Color.white, 0.5)
|
||||||
pivot_indicator.draw_line(
|
pivot_indicator.draw_line(
|
||||||
|
@ -222,18 +224,21 @@ func _on_Indicator_draw() -> void:
|
||||||
|
|
||||||
|
|
||||||
func _on_Indicator_gui_input(event: InputEvent) -> void:
|
func _on_Indicator_gui_input(event: InputEvent) -> void:
|
||||||
if event is InputEventMouseMotion:
|
if event.is_action_pressed("left_mouse"):
|
||||||
if event.pressure == 1.0:
|
drag_pivot = true
|
||||||
var img_size := preview_image.get_size()
|
if event.is_action_released("left_mouse"):
|
||||||
var mouse_pos := get_local_mouse_position() - pivot_indicator.rect_position
|
drag_pivot = false
|
||||||
var ratio := img_size / pivot_indicator.rect_size
|
if drag_pivot:
|
||||||
# we need to set the scale according to the larger side
|
var img_size := preview_image.get_size()
|
||||||
var conversion_scale: float
|
var mouse_pos := get_local_mouse_position() - pivot_indicator.rect_position
|
||||||
if img_size.x > img_size.y:
|
var ratio := img_size / pivot_indicator.rect_size
|
||||||
conversion_scale = ratio.x
|
# we need to set the scale according to the larger side
|
||||||
else:
|
var conversion_scale: float
|
||||||
conversion_scale = ratio.y
|
if img_size.x > img_size.y:
|
||||||
var new_pos := mouse_pos * conversion_scale
|
conversion_scale = ratio.x
|
||||||
x_pivot.value = new_pos.x
|
else:
|
||||||
y_pivot.value = new_pos.y
|
conversion_scale = ratio.y
|
||||||
pivot_indicator.update()
|
var new_pos := mouse_pos * conversion_scale
|
||||||
|
x_pivot.value = new_pos.x
|
||||||
|
y_pivot.value = new_pos.y
|
||||||
|
pivot_indicator.update()
|
||||||
|
|
Loading…
Add table
Reference in a new issue