Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 41 additions & 6 deletions src/ui_widgets/eyedropper_popup.gd
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,69 @@ const GRID_COLOR = Color(0.5, 0.5, 0.5, 0.35)
const PIXEL_SIZE = 7
const FRAME_RADIUS = 50
const FRAME_WIDTH = 5
const KEYBOARD_DELAY_DURATION = 0.5

var color: Color
var ci := get_canvas_item()
var keyboard_offset := Vector2.ZERO
var keyboard_scrolled_time := -1.0


func pick_color() -> void:
color_picked.emit(color)
queue_free()


func _enter_tree() -> void:
DisplayServer.mouse_set_mode(DisplayServer.MOUSE_MODE_HIDDEN)
await RenderingServer.frame_post_draw
texture = ImageTexture.create_from_image(get_viewport().get_texture().get_image())
size = get_window().get_visible_rect().size


var shortcuts := ShortcutsRegistration.new()
shortcuts.add_shortcut("ui_accept", pick_color)
HandlerGUI.register_shortcuts(self, shortcuts)

func _exit_tree() -> void:
DisplayServer.mouse_set_mode(DisplayServer.MOUSE_MODE_VISIBLE)


func _input(event: InputEvent) -> void:
if event is InputEventMouseMotion:
keyboard_offset = Vector2.ZERO
keyboard_scrolled_time = -1.0
queue_redraw()
elif event is InputEventMouseButton:
if event.button_index in [MOUSE_BUTTON_LEFT, MOUSE_BUTTON_RIGHT]:
color_picked.emit(color)
queue_free()
pick_color()
elif event is InputEventKey:
for action_name in ["ui_left", "ui_right", "ui_up", "ui_down"]:
if event.is_action_pressed(action_name, true, true):
accept_event()

func _process(delta: float) -> void:
var vector := Input.get_vector("ui_left", "ui_right", "ui_up", "ui_down").round()
if not vector.is_zero_approx():
var offset_change := 0
if keyboard_scrolled_time < 0:
keyboard_scrolled_time = 0.0
offset_change = 1
elif keyboard_scrolled_time > KEYBOARD_DELAY_DURATION:
offset_change = clampi(roundi(keyboard_scrolled_time * delta * 200.0), 1, 10)
keyboard_scrolled_time += delta
keyboard_offset = (keyboard_offset + vector * offset_change).round()
var mouse_pos := get_global_mouse_position()
keyboard_offset = keyboard_offset.clamp(-mouse_pos, size - mouse_pos - Vector2(1, 1))
queue_redraw()
elif keyboard_scrolled_time >= 0:
keyboard_scrolled_time = -1.0

func _draw() -> void:
if texture == null:
if not is_instance_valid(texture):
return

var pos := get_global_mouse_position()
var texture_pos := get_global_mouse_position() * get_window().get_final_transform()
var pos := get_global_mouse_position() + keyboard_offset
var texture_pos := pos * get_window().get_final_transform()

if pos.x < 0 or pos.x >= size.x or pos.y < 0 or pos.y >= size.y:
return
Expand Down
8 changes: 4 additions & 4 deletions src/ui_widgets/good_color_picker.gd
Original file line number Diff line number Diff line change
Expand Up @@ -439,13 +439,13 @@ func _on_hslider_text_submitted(new_text: String, index: int) -> void:
sync_hslider(index)

func sync_hslider(index: int) -> void:
var num_value: float
if Configs.savedata.color_picker_current_model == ColorPickerUtils.ColorModel.RGB:
# In this case, it's better to use the hex value, as it benefits from paint calibration.
fields_arr[index].text = String.num_uint64(roundi(
Color.html(color_config.color.paint)[index] * ColorPickerUtils.get_channel_fidelity(index)))
num_value = ColorParser.text_to_color(ColorParser.add_hash_if_hex(color_config.color.paint))[index]
else:
fields_arr[index].text = String.num_uint64(roundi(
ColorPickerUtils.get_channel_offset(color_config.color, index) * ColorPickerUtils.get_channel_fidelity(index)))
num_value = ColorPickerUtils.get_channel_offset(color_config.color, index)
fields_arr[index].text = String.num_uint64(roundi(num_value * ColorPickerUtils.get_channel_fidelity(index)))


func _on_keyword_button_pressed() -> void:
Expand Down