mirror of
https://github.com/tonytins/CozyPixelStudio.git
synced 2025-05-05 16:44:50 -04:00
Change font & load font from file explorer
This commit is contained in:
parent
fdd1833bd7
commit
baae34f467
4 changed files with 90 additions and 8 deletions
|
@ -13,12 +13,12 @@ margin_right = 128.0
|
|||
margin_right = 128.0
|
||||
|
||||
[node name="Type" parent="Brush" index="0"]
|
||||
margin_left = 7.0
|
||||
margin_right = 43.0
|
||||
margin_left = 9.0
|
||||
margin_right = 41.0
|
||||
|
||||
[node name="Size" parent="Brush" index="1"]
|
||||
margin_left = 47.0
|
||||
margin_right = 121.0
|
||||
margin_left = 45.0
|
||||
margin_right = 119.0
|
||||
|
||||
[node name="BrushSize" parent="." index="2"]
|
||||
margin_left = 18.0
|
||||
|
|
|
@ -1,15 +1,22 @@
|
|||
extends "res://src/Tools/Base.gd"
|
||||
|
||||
|
||||
var loaded_fonts := [
|
||||
preload("res://assets/fonts/Roboto-Regular.ttf"),
|
||||
preload("res://assets/fonts/CJK/NotoSansCJKtc-Regular.otf")
|
||||
]
|
||||
var text_edit : TextEdit
|
||||
var text_edit_pos := Vector2.ZERO
|
||||
var text_size := 16
|
||||
var font_data : DynamicFontData
|
||||
|
||||
onready var font_data : DynamicFontData = preload("res://assets/fonts/Roboto-Regular.ttf")
|
||||
onready var font := DynamicFont.new()
|
||||
onready var font_optionbutton : OptionButton = $FontOptionButton
|
||||
onready var font_filedialog : FileDialog = $FontFileDialog
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
font_data = loaded_fonts[0]
|
||||
font.font_data = font_data
|
||||
font.size = text_size
|
||||
|
||||
|
@ -89,3 +96,32 @@ func text_to_pixels() -> void:
|
|||
func _on_TextSizeSpinBox_value_changed(value : int) -> void:
|
||||
text_size = value
|
||||
font.size = text_size
|
||||
|
||||
|
||||
func _on_FontOptionButton_item_selected(index : int):
|
||||
if index >= loaded_fonts.size():
|
||||
return
|
||||
font_data = loaded_fonts[index]
|
||||
font.font_data = font_data
|
||||
|
||||
|
||||
func _on_LoadFontButton_pressed() -> void:
|
||||
font_filedialog.popup_centered()
|
||||
Global.dialog_open(true)
|
||||
|
||||
|
||||
func _on_FontFileDialog_files_selected(paths : PoolStringArray) -> void:
|
||||
for path in paths:
|
||||
var file = DynamicFont.new()
|
||||
file = load(path)
|
||||
if !file:
|
||||
print("Failed ", path)
|
||||
continue
|
||||
loaded_fonts.append(file)
|
||||
var file_name = path.get_file().get_basename()
|
||||
font_optionbutton.add_item(file_name)
|
||||
print("Success ", path)
|
||||
|
||||
|
||||
func _on_FontFileDialog_popup_hide() -> void:
|
||||
Global.dialog_open(false)
|
||||
|
|
|
@ -19,12 +19,58 @@ visible = false
|
|||
margin_top = 18.0
|
||||
margin_bottom = 35.0
|
||||
|
||||
[node name="TextSizeSpinBox" type="SpinBox" parent="." index="4"]
|
||||
[node name="FontLabel" type="Label" parent="." index="4"]
|
||||
margin_top = 18.0
|
||||
margin_right = 116.0
|
||||
margin_bottom = 42.0
|
||||
margin_bottom = 32.0
|
||||
text = "Font:"
|
||||
align = 1
|
||||
|
||||
[node name="FontOptionButton" type="OptionButton" parent="." index="5"]
|
||||
margin_top = 36.0
|
||||
margin_right = 116.0
|
||||
margin_bottom = 56.0
|
||||
mouse_default_cursor_shape = 2
|
||||
text = "Roboto"
|
||||
items = [ "Roboto", null, false, 0, null, "NotoSansCJK", null, false, 1, null ]
|
||||
selected = 0
|
||||
|
||||
[node name="TextSizeLabel" type="Label" parent="." index="6"]
|
||||
margin_top = 60.0
|
||||
margin_right = 116.0
|
||||
margin_bottom = 74.0
|
||||
text = "Text size:"
|
||||
align = 1
|
||||
|
||||
[node name="TextSizeSpinBox" type="SpinBox" parent="." index="7"]
|
||||
margin_top = 78.0
|
||||
margin_right = 116.0
|
||||
margin_bottom = 102.0
|
||||
mouse_default_cursor_shape = 2
|
||||
min_value = 1.0
|
||||
max_value = 128.0
|
||||
value = 16.0
|
||||
|
||||
[node name="LoadFontButton" type="Button" parent="." index="8"]
|
||||
margin_top = 106.0
|
||||
margin_right = 116.0
|
||||
margin_bottom = 126.0
|
||||
mouse_default_cursor_shape = 2
|
||||
text = "Load Font"
|
||||
|
||||
[node name="FontFileDialog" type="FileDialog" parent="." index="9"]
|
||||
margin_right = 400.0
|
||||
margin_bottom = 400.0
|
||||
rect_min_size = Vector2( 400, 400 )
|
||||
window_title = "Open File(s)"
|
||||
resizable = true
|
||||
mode = 1
|
||||
access = 2
|
||||
filters = PoolStringArray( "*.ttf", "*.otf" )
|
||||
current_dir = "/Users/Overloaded/Documents/#Orama Stuff/Pixelorama/#Main Repos/Pixelorama"
|
||||
current_path = "/Users/Overloaded/Documents/#Orama Stuff/Pixelorama/#Main Repos/Pixelorama/"
|
||||
[connection signal="item_selected" from="FontOptionButton" to="." method="_on_FontOptionButton_item_selected"]
|
||||
[connection signal="value_changed" from="TextSizeSpinBox" to="." method="_on_TextSizeSpinBox_value_changed"]
|
||||
[connection signal="pressed" from="LoadFontButton" to="." method="_on_LoadFontButton_pressed"]
|
||||
[connection signal="files_selected" from="FontFileDialog" to="." method="_on_FontFileDialog_files_selected"]
|
||||
[connection signal="popup_hide" from="FontFileDialog" to="." method="_on_FontFileDialog_popup_hide"]
|
||||
|
|
|
@ -61,7 +61,7 @@ __meta__ = {
|
|||
margin_left = 7.0
|
||||
margin_top = 7.0
|
||||
margin_right = 39.0
|
||||
margin_bottom = 255.0
|
||||
margin_bottom = 291.0
|
||||
size_flags_horizontal = 4
|
||||
size_flags_vertical = 0
|
||||
script = ExtResource( 1 )
|
||||
|
|
Loading…
Add table
Reference in a new issue