From 22c57a1b368b8920066aa52bdf188e1bfa888691 Mon Sep 17 00:00:00 2001 From: OverloadedOrama <35376950+OverloadedOrama@users.noreply.github.com> Date: Tue, 19 Nov 2019 03:52:04 +0200 Subject: [PATCH] Backend for rulers - Added HorizontalRuler.gd and VerticalRuler.gd - UI for the rulers will arrive soon, along with the other UI changes - Changed transparency background --- Assets/Fonts/Roboto-Small.tres | 9 +++ Assets/Graphics/Transparent Background.png | Bin 84 -> 84 bytes .../Transparent Background.png.import | 1 + README.md | 2 +- Scripts/HorizontalRuler.gd | 53 ++++++++++++++++++ Scripts/VerticalRuler.gd | 53 ++++++++++++++++++ 6 files changed, 117 insertions(+), 1 deletion(-) create mode 100644 Assets/Fonts/Roboto-Small.tres create mode 100644 Scripts/HorizontalRuler.gd create mode 100644 Scripts/VerticalRuler.gd diff --git a/Assets/Fonts/Roboto-Small.tres b/Assets/Fonts/Roboto-Small.tres new file mode 100644 index 000000000..57bb57983 --- /dev/null +++ b/Assets/Fonts/Roboto-Small.tres @@ -0,0 +1,9 @@ +[gd_resource type="DynamicFont" load_steps=2 format=2] + +[ext_resource path="res://Assets/Fonts/Roboto-Regular.ttf" type="DynamicFontData" id=1] + +[resource] +size = 8 +use_mipmaps = true +use_filter = true +font_data = ExtResource( 1 ) diff --git a/Assets/Graphics/Transparent Background.png b/Assets/Graphics/Transparent Background.png index 581ba5f010143c9804f3b617bf186e4f60fb404c..190dba94e733da6e39b88f80ba8140e5dbd617a2 100644 GIT binary patch delta 46 zcmWFunV_wi9J3+e;Q!g?c?Je|_Y^ie#yU4MGQ{rW$eCK%=+6KIp00i_>zopr0I|#w A2mk;8 delta 46 zcmWFunV_x7da#j^fq{it;otu=J2XR$xuqtpW^a1MyXTSM9YqEp@O1TaS?83{1ORMX B53T?J diff --git a/Assets/Graphics/Transparent Background.png.import b/Assets/Graphics/Transparent Background.png.import index 9345897f5..6c63960ff 100644 --- a/Assets/Graphics/Transparent Background.png.import +++ b/Assets/Graphics/Transparent Background.png.import @@ -10,3 +10,4 @@ source_file="res://Assets/Graphics/Transparent Background.png" dest_files=[ "res://.import/Transparent Background.png-62a2c5eb3e805ff7dbb890edc2b8d883.image" ] [params] + diff --git a/README.md b/README.md index e9a6e6823..f677ce6ad 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # Pixelorama - your free and open-source sprite editor! Your free & open-source 2D sprite editor, made in the Godot Engine, using GDScript! - [![Pixelorama's horrible UI](https://functionoverload590613498.files.wordpress.com/2019/11/screenshot_268.png)](https://www.youtube.com/watch?v=h3OJROgAR-A) + [![Pixelorama's horrible UI](https://functionoverload590613498.files.wordpress.com/2019/11/screenshot_268.png)](https://www.youtube.com/watch?v=h3OJROgAR-A&list=PLVEP1Zz6BUpBiQC0CB6eNBhhLF4tEwBB-) Current features as of version v0.4: diff --git a/Scripts/HorizontalRuler.gd b/Scripts/HorizontalRuler.gd new file mode 100644 index 000000000..5c20cc0ba --- /dev/null +++ b/Scripts/HorizontalRuler.gd @@ -0,0 +1,53 @@ +extends Panel + +const RULER_WIDTH := 16 + +var font := preload("res://Assets/Fonts/Roboto-Small.tres") +var major_subdivision := 2 +var minor_subdivision := 5 + +var first : Vector2 +var last : Vector2 + +func _process(delta) -> void: + update() + +func _draw() -> void: + var transform := Transform2D() + var ruler_transform := Transform2D() + var major_subdivide := Transform2D() + var minor_subdivide := Transform2D() + var zoom := 1 / Global.camera.zoom.x + transform.x = Vector2(zoom, zoom) + + transform.origin = Global.main_viewport.rect_size / 2 + (Global.camera.offset) * -zoom + + var basic_rule := 100.0 + var i := 0 + while(basic_rule * zoom > 100): + basic_rule /= 5.0 if i % 2 else 2.0 + i += 1 + i = 0 + while(basic_rule * zoom < 100): + basic_rule *= 2.0 if i % 2 else 5.0 + i += 1 + + 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(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))) + 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) \ No newline at end of file diff --git a/Scripts/VerticalRuler.gd b/Scripts/VerticalRuler.gd new file mode 100644 index 000000000..8225f187b --- /dev/null +++ b/Scripts/VerticalRuler.gd @@ -0,0 +1,53 @@ +extends Panel + +const RULER_WIDTH := 16 + +var font := preload("res://Assets/Fonts/Roboto-Small.tres") +var major_subdivision := 2 +var minor_subdivision := 5 + +var first : Vector2 +var last : Vector2 + +func _process(delta) -> void: + update() + +func _draw() -> void: + var transform := Transform2D() + var ruler_transform := Transform2D() + var major_subdivide := Transform2D() + var minor_subdivide := Transform2D() + var zoom := 1 / Global.camera.zoom.x + transform.y = Vector2(zoom, zoom) + + transform.origin = Global.main_viewport.rect_size / 2 + (Global.camera.offset) * -zoom + + var basic_rule := 100.0 + var i := 0 + while(basic_rule * zoom > 100): + basic_rule /= 5.0 if i % 2 else 2.0 + i += 1 + i = 0 + while(basic_rule * zoom < 100): + basic_rule *= 2.0 if i % 2 else 5.0 + i += 1 + + 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(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))) + else: + if i % minor_subdivision == 0: + draw_line(Vector2(RULER_WIDTH * 0.33, position.y), Vector2(RULER_WIDTH, position.y), Color.white) + else: + draw_line(Vector2(RULER_WIDTH * 0.66, position.y), Vector2(RULER_WIDTH, position.y), Color.white) \ No newline at end of file