From 1897c62eb4387090bad579da6ee95bb83ca5d497 Mon Sep 17 00:00:00 2001 From: OverloadedOrama <35376950+OverloadedOrama@users.noreply.github.com> Date: Sun, 11 Oct 2020 03:28:29 +0300 Subject: [PATCH] Change font size --- project.godot | 7 +++++++ src/Tools/Text.gd | 18 ++++++++++++++++-- src/Tools/Text.tscn | 11 ++++++++++- 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/project.godot b/project.godot index 2586fba..06f678d 100644 --- a/project.godot +++ b/project.godot @@ -422,11 +422,18 @@ left_text_tool={ right_text_tool={ "deadzone": 0.5, "events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":true,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":65,"unicode":0,"echo":false,"script":null) + ] +} cut={ "deadzone": 0.5, "events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":true,"meta":false,"command":true,"pressed":false,"scancode":88,"unicode":0,"echo":false,"script":null) ] } +enter={ +"deadzone": 0.5, +"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777221,"unicode":0,"echo":false,"script":null) + ] +} [locale] diff --git a/src/Tools/Text.gd b/src/Tools/Text.gd index 8cb9c67..0f52231 100644 --- a/src/Tools/Text.gd +++ b/src/Tools/Text.gd @@ -3,10 +3,19 @@ extends "res://src/Tools/Base.gd" var text_edit : TextEdit var text_edit_pos := Vector2.ZERO +var text_size := 16 + +onready var font_data : DynamicFontData = preload("res://assets/fonts/Roboto-Regular.ttf") +onready var font := DynamicFont.new() + + +func _ready() -> void: + font.font_data = font_data + font.size = text_size func _input(event : InputEvent) -> void: - if event.is_action_pressed("ui_accept"): + if event.is_action_pressed("enter"): text_to_pixels() @@ -53,7 +62,7 @@ func text_to_pixels() -> void: var texture = ImageTexture.new() texture.create_from_image(current_cel) VisualServer.canvas_item_add_texture_rect(ci_rid, Rect2(Vector2(0, 0), size), texture) - var font : Font = load("res://assets/fonts/Roboto-Regular.tres") + font.draw(ci_rid, text_edit_pos, text_edit.text, tool_slot.color) VisualServer.viewport_set_update_mode(vp, VisualServer.VIEWPORT_UPDATE_ONCE) @@ -74,3 +83,8 @@ func text_to_pixels() -> void: text_edit.queue_free() text_edit = null + + +func _on_TextSizeSpinBox_value_changed(value : int) -> void: + text_size = value + font.size = text_size diff --git a/src/Tools/Text.tscn b/src/Tools/Text.tscn index d795519..4654727 100644 --- a/src/Tools/Text.tscn +++ b/src/Tools/Text.tscn @@ -3,7 +3,6 @@ [ext_resource path="res://src/Tools/Base.tscn" type="PackedScene" id=1] [ext_resource path="res://src/Tools/Text.gd" type="Script" id=2] - [node name="ToolOptions" instance=ExtResource( 1 )] script = ExtResource( 2 ) @@ -19,3 +18,13 @@ margin_bottom = 30.0 visible = false margin_top = 18.0 margin_bottom = 35.0 + +[node name="TextSizeSpinBox" type="SpinBox" parent="." index="4"] +margin_top = 18.0 +margin_right = 116.0 +margin_bottom = 42.0 +mouse_default_cursor_shape = 2 +min_value = 1.0 +max_value = 128.0 +value = 16.0 +[connection signal="value_changed" from="TextSizeSpinBox" to="." method="_on_TextSizeSpinBox_value_changed"]