Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement shrink option #376

Merged
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
1 change: 1 addition & 0 deletions src/Autoload/Global.gd
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ var default_clear_color := Color.gray
# Preferences
var pressure_sensitivity_mode = Pressure_Sensitivity.NONE
var open_last_project := false
var shrink := 1.0
var smooth_zoom := true
var theme_type : int = Theme_Types.DARK
var default_image_width := 64
Expand Down
3 changes: 3 additions & 0 deletions src/Main.gd
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ func setup_application_window_size() -> void:
return
# Set a minimum window size to prevent UI elements from collapsing on each other.
OS.min_window_size = Vector2(1024, 576)

get_tree().set_screen_stretch(SceneTree.STRETCH_MODE_DISABLED,
SceneTree.STRETCH_ASPECT_IGNORE, Vector2(1014,576), Global.shrink)
Copy link
Contributor

@Calinou Calinou Nov 7, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Out of curiosity, why is this 1014 instead of 1024?

Also, you can get the base window size dynamically using ProjectSettings.get_setting("display/window/size/width") and ProjectSettings.get_setting("display/window/size/height"). This makes the code easier to reuse across projects.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is a typo :), I can fix it

Best regards

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

About ProjectSettings.get_setting("display/window/size/width"), I just followed the line above where OS.min_window_size is set to Vector2(1024, 576). The 3rd parameters of set_screen_stretch is minsize.


# Restore the window position/size if values are present in the configuration cache
if Global.config_cache.has_section_key("window", "screen"):
Expand Down
14 changes: 14 additions & 0 deletions src/Preferences/PreferencesDialog.gd
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ extends AcceptDialog
# Preferences table: [Prop name in Global, relative node path, value type, default value]
var preferences = [
["open_last_project", "Startup/StartupContainer/OpenLastProject", "pressed", Global.open_last_project],
["shrink", "Startup/ShrinkContainer/ShrinkHSlider", "value", Global.shrink],
["smooth_zoom", "Canvas/ZoomOptions/SmoothZoom", "pressed", Global.smooth_zoom],
["pressure_sensitivity_mode", "Startup/PressureSentivity/PressureSensitivityOptionButton", "selected", Global.pressure_sensitivity_mode],
["show_left_tool_icon", "Indicators/IndicatorsContainer/LeftToolIconCheckbox", "pressed", Global.show_left_tool_icon],
Expand Down Expand Up @@ -35,6 +36,7 @@ onready var list : ItemList = $HSplitContainer/List
onready var right_side : VBoxContainer = $HSplitContainer/ScrollContainer/VBoxContainer
onready var autosave_interval : SpinBox = $HSplitContainer/ScrollContainer/VBoxContainer/Backup/AutosaveContainer/AutosaveInterval
onready var restore_default_button_scene = preload("res://src/Preferences/RestoreDefaultButton.tscn")
onready var shrink_label : Label = $HSplitContainer/ScrollContainer/VBoxContainer/Startup/ShrinkContainer/ShrinkLabel


func _ready() -> void:
Expand Down Expand Up @@ -171,3 +173,15 @@ func _on_List_item_selected(index : int) -> void:
if OS.get_name() == "HTML5":
content_list.erase("Startup")
child.visible = child.name == content_list[index]


func _on_HSlider_value_changed(value):
shrink_label.text = str(value)


func _on_ShrinkApplyButton_pressed():
get_tree().set_screen_stretch(SceneTree.STRETCH_MODE_DISABLED,
SceneTree.STRETCH_ASPECT_IGNORE, Vector2(1014,576), Global.shrink)
Global.preferences_dialog.popup_centered(Vector2(400, 280))
Global.camera.zoom_100()

51 changes: 46 additions & 5 deletions src/Preferences/PreferencesDialog.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
[sub_resource type="ButtonGroup" id=1]

[node name="PreferencesDialog" type="AcceptDialog"]
visible = true
margin_left = -3.0
margin_top = 9.0
margin_right = 419.0
Expand Down Expand Up @@ -51,12 +52,12 @@ size_flags_horizontal = 3

[node name="VBoxContainer" type="VBoxContainer" parent="HSplitContainer/ScrollContainer"]
margin_right = 498.0
margin_bottom = 24.0
margin_bottom = 48.0
size_flags_horizontal = 3

[node name="Startup" type="VBoxContainer" parent="HSplitContainer/ScrollContainer/VBoxContainer"]
margin_right = 498.0
margin_bottom = 24.0
margin_bottom = 48.0

[node name="StartupContainer" type="HBoxContainer" parent="HSplitContainer/ScrollContainer/VBoxContainer/Startup"]
margin_right = 498.0
Expand All @@ -78,9 +79,9 @@ text = "On"

[node name="PressureSentivity" type="HBoxContainer" parent="HSplitContainer/ScrollContainer/VBoxContainer/Startup"]
visible = false
margin_top = 100.0
margin_right = 506.0
margin_bottom = 120.0
margin_top = 28.0
margin_right = 498.0
margin_bottom = 48.0

[node name="PressureSensitivityLabel" type="Label" parent="HSplitContainer/ScrollContainer/VBoxContainer/Startup/PressureSentivity"]
margin_top = 3.0
Expand All @@ -96,6 +97,44 @@ text = "Affect Brush's Alpha"
items = [ "None", null, false, 0, null, "Affect Brush's Alpha", null, false, 1, null ]
selected = 1

[node name="ShrinkContainer" type="HBoxContainer" parent="HSplitContainer/ScrollContainer/VBoxContainer/Startup"]
margin_top = 28.0
margin_right = 498.0
margin_bottom = 48.0

[node name="Label" type="Label" parent="HSplitContainer/ScrollContainer/VBoxContainer/Startup/ShrinkContainer"]
margin_top = 3.0
margin_right = 68.0
margin_bottom = 17.0
text = "Shrink GUI"

[node name="ShrinkLabel" type="Label" parent="HSplitContainer/ScrollContainer/VBoxContainer/Startup/ShrinkContainer"]
margin_left = 72.0
margin_top = 3.0
margin_right = 122.0
margin_bottom = 17.0
rect_min_size = Vector2( 50, 0 )
text = "1"
align = 2

[node name="ShrinkHSlider" type="HSlider" parent="HSplitContainer/ScrollContainer/VBoxContainer/Startup/ShrinkContainer"]
margin_left = 126.0
margin_right = 446.0
margin_bottom = 16.0
size_flags_horizontal = 3
min_value = 1.0
max_value = 4.0
step = 0.5
value = 1.0
tick_count = 7
ticks_on_borders = true

[node name="ShrinkApplyButton" type="Button" parent="HSplitContainer/ScrollContainer/VBoxContainer/Startup/ShrinkContainer"]
margin_left = 450.0
margin_right = 498.0
margin_bottom = 20.0
text = "Apply"

[node name="Languages" type="VBoxContainer" parent="HSplitContainer/ScrollContainer/VBoxContainer"]
visible = false
margin_top = 184.0
Expand Down Expand Up @@ -912,6 +951,8 @@ __meta__ = {
[connection signal="about_to_show" from="." to="." method="_on_PreferencesDialog_about_to_show"]
[connection signal="popup_hide" from="." to="." method="_on_PreferencesDialog_popup_hide"]
[connection signal="item_selected" from="HSplitContainer/List" to="." method="_on_List_item_selected"]
[connection signal="value_changed" from="HSplitContainer/ScrollContainer/VBoxContainer/Startup/ShrinkContainer/ShrinkHSlider" to="." method="_on_HSlider_value_changed"]
[connection signal="pressed" from="HSplitContainer/ScrollContainer/VBoxContainer/Startup/ShrinkContainer/ShrinkApplyButton" to="." method="_on_ShrinkApplyButton_pressed"]
[connection signal="item_selected" from="HSplitContainer/ScrollContainer/VBoxContainer/Shortcuts/HBoxContainer/PresetOptionButton" to="HSplitContainer/ScrollContainer/VBoxContainer/Shortcuts" method="_on_PresetOptionButton_item_selected"]
[connection signal="confirmed" from="Popups/ShortcutSelector" to="HSplitContainer/ScrollContainer/VBoxContainer/Shortcuts" method="_on_ShortcutSelector_confirmed"]
[connection signal="popup_hide" from="Popups/ShortcutSelector" to="HSplitContainer/ScrollContainer/VBoxContainer/Shortcuts" method="_on_ShortcutSelector_popup_hide"]
5 changes: 4 additions & 1 deletion src/UI/Canvas/Canvas.gd
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ func _input(event : InputEvent) -> void:
# elif not get_viewport_rect().has_point(event.position):
# return

current_pixel = get_local_mouse_position() + location
#current_pixel = get_local_mouse_position() + location
var tmp_transform = get_canvas_transform().affine_inverse()
var tmp_position = Global.main_viewport.get_local_mouse_position()
current_pixel = tmp_transform.basis_xform(tmp_position)+tmp_transform.origin

if Global.has_focus:
update()
Expand Down