Added a seconds ruler for the timeline & changed brushes position

This commit is contained in:
OverloadedOrama 2019-11-20 14:41:02 +02:00
parent d70c1e5714
commit e895e82a95
10 changed files with 267 additions and 228 deletions

View file

@ -6,7 +6,7 @@ func _ready() -> void:
$AboutUI/Pixelorama.text = "Pixelorama %s\n" % current_version
func _on_Website_pressed() -> void:
OS.shell_open("http://oramagamestudios.com/")
OS.shell_open("https://www.orama-interactive.com/")
func _on_GitHub_pressed() -> void:
OS.shell_open("https://github.com/OverloadedOrama/Pixelorama")
@ -14,6 +14,3 @@ func _on_GitHub_pressed() -> void:
func _on_Donate_pressed() -> void:
OS.shell_open("https://www.paypal.com/paypalme2/OverloadedOrama")
OS.shell_open("https://ko-fi.com/overloadedorama")
func _on_Blog_pressed() -> void:
OS.shell_open("https://functionoverload590613498.wordpress.com/")

View file

@ -21,24 +21,22 @@ func _on_BrushButton_pressed() -> void:
Global.update_right_custom_brush()
func _on_DeleteButton_pressed() -> void:
var file_hbox_container := Global.find_node_by_name(get_tree().get_root(), "BrushHBoxContainer")
var custom_hbox_container := Global.find_node_by_name(get_tree().get_root(), "CustomBrushHBoxContainer")
if brush_type == Global.BRUSH_TYPES.CUSTOM:
if Global.custom_left_brush_index == custom_brush_index:
Global.custom_left_brush_index = -1
Global.current_left_brush_type = Global.BRUSH_TYPES.PIXEL
remove_child(Global.left_brush_indicator)
file_hbox_container.get_child(0).add_child(Global.left_brush_indicator)
Global.file_brush_container.get_child(0).add_child(Global.left_brush_indicator)
if Global.custom_right_brush_index == custom_brush_index:
Global.custom_right_brush_index = -1
Global.current_right_brush_type = Global.BRUSH_TYPES.PIXEL
remove_child(Global.right_brush_indicator)
file_hbox_container.get_child(0).add_child(Global.right_brush_indicator)
Global.file_brush_container.get_child(0).add_child(Global.right_brush_indicator)
Global.undos += 1
Global.undo_redo.create_action("Delete Custom Brush")
for i in range(custom_brush_index - 1, custom_hbox_container.get_child_count()):
var bb = custom_hbox_container.get_child(i)
for i in range(custom_brush_index - 1, Global.project_brush_container.get_child_count()):
var bb = Global.project_brush_container.get_child(i)
if Global.custom_left_brush_index == bb.custom_brush_index:
Global.custom_left_brush_index -= 1
if Global.custom_right_brush_index == bb.custom_brush_index:

View file

@ -69,8 +69,6 @@ func camera_zoom() -> void:
#Set camera offset to the center of canvas
Global.camera.offset = size / 2
#Global.camera.offset.x = size.x / 2 + Global.main_viewport.rect_size.x / 2 * -Global.camera.zoom.x
#Global.camera.offset.y = size.y / 2 + Global.main_viewport.rect_size.y / 2 * -Global.camera.zoom.y
Global.camera2.offset = size / 2
# warning-ignore:unused_argument

View file

@ -79,6 +79,8 @@ var right_brush_size := 1
var current_left_brush_type = BRUSH_TYPES.PIXEL
# warning-ignore:unused_class_variable
var current_right_brush_type = BRUSH_TYPES.PIXEL
var file_brush_container
var project_brush_container
# warning-ignore:unused_class_variable
var left_horizontal_mirror := false
# warning-ignore:unused_class_variable
@ -148,6 +150,8 @@ func _ready() -> void:
cursor_position_label = find_node_by_name(root, "CursorPosition")
zoom_level_label = find_node_by_name(root, "ZoomLevel")
current_frame_label = find_node_by_name(root, "CurrentFrame")
file_brush_container = find_node_by_name(root, "FileBrushContainer")
project_brush_container = find_node_by_name(root, "ProjectBrushContainer")
#Thanks to https://godotengine.org/qa/17524/how-to-find-an-instanced-scene-by-its-name
func find_node_by_name(root, node_name) -> Node:
@ -257,33 +261,31 @@ func frame_changed(value : int) -> void:
func create_brush_button(brush_img : Image, brush_type := BRUSH_TYPES.CUSTOM) -> void:
var hbox_container : HBoxContainer
var brush_container
var brush_button = load("res://Prefabs/BrushButton.tscn").instance()
brush_button.brush_type = brush_type
brush_button.custom_brush_index = custom_brushes.size() - 1
if brush_type == BRUSH_TYPES.FILE:
hbox_container = find_node_by_name(get_tree().get_root(), "BrushHBoxContainer")
brush_container = file_brush_container
else:
hbox_container = find_node_by_name(get_tree().get_root(), "CustomBrushHBoxContainer")
brush_container = project_brush_container
var brush_tex := ImageTexture.new()
brush_tex.create_from_image(brush_img, 0)
brush_button.get_child(0).texture = brush_tex
hbox_container.add_child(brush_button)
brush_container.add_child(brush_button)
func remove_brush_buttons() -> void:
current_left_brush_type = BRUSH_TYPES.PIXEL
current_right_brush_type = BRUSH_TYPES.PIXEL
var hbox_container := find_node_by_name(get_tree().get_root(), "CustomBrushHBoxContainer")
for child in hbox_container.get_children():
for child in project_brush_container.get_children():
child.queue_free()
func undo_custom_brush(_brush_button : Button = null) -> void:
undos -= 1
var action_name := undo_redo.get_current_action_name()
var hbox_container := find_node_by_name(get_tree().get_root(), "CustomBrushHBoxContainer")
if action_name == "Delete Custom Brush":
hbox_container.add_child(_brush_button)
hbox_container.move_child(_brush_button, _brush_button.custom_brush_index - brushes_from_files)
project_brush_container.add_child(_brush_button)
project_brush_container.move_child(_brush_button, _brush_button.custom_brush_index - brushes_from_files)
_brush_button.get_node("DeleteButton").visible = false
notification_label("Undo: %s" % action_name)
@ -291,9 +293,8 @@ func redo_custom_brush(_brush_button : Button = null) -> void:
if undos < undo_redo.get_version(): #If we did undo and then redo
undos = undo_redo.get_version()
var action_name := undo_redo.get_current_action_name()
var hbox_container := find_node_by_name(get_tree().get_root(), "CustomBrushHBoxContainer")
if action_name == "Delete Custom Brush":
hbox_container.remove_child(_brush_button)
project_brush_container.remove_child(_brush_button)
if control.redone:
notification_label("Redo: %s" % action_name)

View file

@ -13,6 +13,7 @@ var last : Vector2
func _process(delta) -> void:
update()
#Code taken and modified from Godot's source code
func _draw() -> void:
var transform := Transform2D()
var ruler_transform := Transform2D()
@ -38,15 +39,15 @@ func _draw() -> void:
major_subdivide = major_subdivide.scaled(Vector2(1.0 / major_subdivision, 1.0 / major_subdivision))
minor_subdivide = minor_subdivide.scaled(Vector2(1.0 / minor_subdivision, 1.0 / minor_subdivision))
first = (transform * ruler_transform * major_subdivide * minor_subdivide).affine_inverse().xform(Vector2.ZERO);
last = (transform * ruler_transform * major_subdivide * minor_subdivide).affine_inverse().xform(Global.main_viewport.rect_size);
first = (transform * ruler_transform * major_subdivide * minor_subdivide).affine_inverse().xform(Vector2.ZERO)
last = (transform * ruler_transform * major_subdivide * minor_subdivide).affine_inverse().xform(Global.main_viewport.rect_size)
for i in range(ceil(first.x), last.x):
var position : Vector2 = (transform * ruler_transform * major_subdivide * minor_subdivide).xform(Vector2(i, 0))
if i % (major_subdivision * minor_subdivision) == 0:
draw_line(Vector2(position.x + RULER_WIDTH, 0), Vector2(position.x + RULER_WIDTH, RULER_WIDTH), Color.white)
var val = (ruler_transform * major_subdivide * minor_subdivide).xform(Vector2(i, 0)).x
draw_string(font, Vector2(position.x + RULER_WIDTH + 2, font.get_height()), str(int(val)))
draw_string(font, Vector2(position.x + RULER_WIDTH + 2, font.get_height() - 4), str(int(val)))
else:
if i % minor_subdivision == 0:
draw_line(Vector2(position.x + RULER_WIDTH, RULER_WIDTH * 0.33), Vector2(position.x + RULER_WIDTH, RULER_WIDTH), Color.white)

View file

@ -0,0 +1,54 @@
extends Control
const RULER_WIDTH := 16
var font := preload("res://Assets/Fonts/Roboto-Small.tres")
var major_subdivision := 2
var minor_subdivision := 3
var first : Vector2
var last : Vector2
# warning-ignore:unused_argument
func _process(delta) -> void:
update()
#Code taken and modified from Godot's source code
func _draw() -> void:
var transform := Transform2D()
var ruler_transform := Transform2D()
var major_subdivide := Transform2D()
var minor_subdivide := Transform2D()
var fps = Global.control.fps
var horizontal_scroll = get_parent().get_node("FrameAndButtonContainer").get_node("ScrollContainer").scroll_horizontal
var starting_pos := Vector2(26, 26)
transform.x = Vector2(fps, fps) / 2.52
transform.origin = starting_pos - Vector2(horizontal_scroll, horizontal_scroll)
var basic_rule := 100.0
while(basic_rule * fps > 100):
basic_rule /= 2.0
while(basic_rule * fps < 100):
basic_rule *= 2.0
ruler_transform = ruler_transform.scaled(Vector2(basic_rule, basic_rule))
major_subdivide = major_subdivide.scaled(Vector2(1.0 / major_subdivision, 1.0 / major_subdivision))
minor_subdivide = minor_subdivide.scaled(Vector2(1.0 / minor_subdivision, 1.0 / minor_subdivision))
first = (transform * ruler_transform * major_subdivide * minor_subdivide).affine_inverse().xform(starting_pos)
last = (transform * ruler_transform * major_subdivide * minor_subdivide).affine_inverse().xform(rect_size - starting_pos)
for i in range(ceil(first.x), last.x):
var position : Vector2 = (transform * ruler_transform * major_subdivide * minor_subdivide).xform(Vector2(i, 0))
if i % (major_subdivision * minor_subdivision) == 0:
draw_line(Vector2(position.x + RULER_WIDTH, 0), Vector2(position.x + RULER_WIDTH, RULER_WIDTH), Color.white)
var val = (ruler_transform * major_subdivide * minor_subdivide).xform(Vector2(i, 0)).x / 100
val = stepify(val, 0.01)
draw_string(font, Vector2(position.x + RULER_WIDTH + 2, font.get_height() - 6), str(val))
else:
if i % minor_subdivision == 0:
draw_line(Vector2(position.x + RULER_WIDTH, RULER_WIDTH * 0.33), Vector2(position.x + RULER_WIDTH, RULER_WIDTH), Color.white)
else:
draw_line(Vector2(position.x + RULER_WIDTH, RULER_WIDTH * 0.66), Vector2(position.x + RULER_WIDTH, RULER_WIDTH), Color.white)

View file

@ -13,6 +13,7 @@ var last : Vector2
func _process(delta) -> void:
update()
#Code taken and modified from Godot's source code
func _draw() -> void:
var transform := Transform2D()
var ruler_transform := Transform2D()
@ -38,15 +39,15 @@ func _draw() -> void:
major_subdivide = major_subdivide.scaled(Vector2(1.0 / major_subdivision, 1.0 / major_subdivision))
minor_subdivide = minor_subdivide.scaled(Vector2(1.0 / minor_subdivision, 1.0 / minor_subdivision))
first = (transform * ruler_transform * major_subdivide * minor_subdivide).affine_inverse().xform(Vector2.ZERO);
last = (transform * ruler_transform * major_subdivide * minor_subdivide).affine_inverse().xform(Global.main_viewport.rect_size);
first = (transform * ruler_transform * major_subdivide * minor_subdivide).affine_inverse().xform(Vector2.ZERO)
last = (transform * ruler_transform * major_subdivide * minor_subdivide).affine_inverse().xform(Global.main_viewport.rect_size)
for i in range(ceil(first.y), last.y):
var position : Vector2 = (transform * ruler_transform * major_subdivide * minor_subdivide).xform(Vector2(0, i))
if i % (major_subdivision * minor_subdivision) == 0:
draw_line(Vector2(0, position.y), Vector2(RULER_WIDTH, position.y), Color.white)
var val = (ruler_transform * major_subdivide * minor_subdivide).xform(Vector2(i, 0)).x
draw_string(font, Vector2(0, position.y), str(int(val)))
var val = (ruler_transform * major_subdivide * minor_subdivide).xform(Vector2(0, i)).y
draw_string(font, Vector2(0, position.y - 2), str(int(val)))
else:
if i % minor_subdivision == 0:
draw_line(Vector2(RULER_WIDTH * 0.33, position.y), Vector2(RULER_WIDTH, position.y), Color.white)