From 70bd1dde43a8142de925450e23fa1f483a9303d0 Mon Sep 17 00:00:00 2001 From: OverloadedOrama <35376950+OverloadedOrama@users.noreply.github.com> Date: Tue, 3 Dec 2019 02:30:38 +0200 Subject: [PATCH] Added show rulers & guides in the View menu --- Scripts/Global.gd | 6 ++++++ Scripts/HorizontalRuler.gd | 2 ++ Scripts/Main.gd | 18 +++++++++++++++++- Scripts/VerticalRuler.gd | 2 ++ 4 files changed, 27 insertions(+), 1 deletion(-) diff --git a/Scripts/Global.gd b/Scripts/Global.gd index bf98f97a2..1cd058f0a 100644 --- a/Scripts/Global.gd +++ b/Scripts/Global.gd @@ -17,6 +17,10 @@ var onion_skinning_blue_red := false var tile_mode := false # warning-ignore:unused_class_variable var draw_grid := false +# warning-ignore:unused_class_variable +var show_rulers := true +# warning-ignore:unused_class_variable +var show_guides := true var canvases := [] # warning-ignore:unused_class_variable var hidden_canvases := [] @@ -34,6 +38,7 @@ var right_square_indicator_visible := false var camera : Camera2D var camera2 : Camera2D var selection_rectangle : Polygon2D +var horizontal_ruler : BaseButton var vertical_ruler : BaseButton # warning-ignore:unused_class_variable var selected_pixels := [] @@ -126,6 +131,7 @@ func _ready() -> void: camera = find_node_by_name(canvas_parent, "Camera2D") camera2 = find_node_by_name(root, "Camera2D2") selection_rectangle = find_node_by_name(root, "SelectionRectangle") + horizontal_ruler = find_node_by_name(root, "HorizontalRuler") vertical_ruler = find_node_by_name(root, "VerticalRuler") image_clipboard = Image.new() diff --git a/Scripts/HorizontalRuler.gd b/Scripts/HorizontalRuler.gd index 4927d36ba..7845731a4 100644 --- a/Scripts/HorizontalRuler.gd +++ b/Scripts/HorizontalRuler.gd @@ -55,6 +55,8 @@ func _draw() -> void: draw_line(Vector2(position.x + RULER_WIDTH, RULER_WIDTH * 0.66), Vector2(position.x + RULER_WIDTH, RULER_WIDTH), Color.white) func _on_HorizontalRuler_pressed() -> void: + if !Global.show_guides: + return var mouse_pos := get_local_mouse_position() if mouse_pos.x < RULER_WIDTH: #For double guides Global.vertical_ruler._on_VerticalRuler_pressed() diff --git a/Scripts/Main.gd b/Scripts/Main.gd index dc1335d29..7ae760f90 100644 --- a/Scripts/Main.gd +++ b/Scripts/Main.gd @@ -57,7 +57,9 @@ func _ready() -> void: } var view_menu_items := { "Tile Mode" : KEY_MASK_CTRL + KEY_T, - "Show Grid" : KEY_MASK_CTRL + KEY_G + "Show Grid" : KEY_MASK_CTRL + KEY_G, + "Show Rulers": KEY_MASK_CTRL + KEY_R, + "Show Guides": KEY_MASK_CTRL + KEY_Y } var help_menu_items := { "About Pixelorama" : 0 @@ -79,6 +81,8 @@ func _ready() -> void: for item in view_menu_items.keys(): view_menu.add_check_item(item, i, view_menu_items[item]) i += 1 + view_menu.set_item_checked(2, true) #Show Rulers + view_menu.set_item_checked(3, true) #Show Guides i = 0 for item in help_menu_items.keys(): help_menu.add_item(item, i, help_menu_items[item]) @@ -257,6 +261,18 @@ func view_menu_id_pressed(id : int) -> void: 1: #Show grid Global.draw_grid = !Global.draw_grid view_menu.set_item_checked(1, Global.draw_grid) + 2: #Show rulers + Global.show_rulers = !Global.show_rulers + view_menu.set_item_checked(2, Global.show_rulers) + Global.horizontal_ruler.visible = Global.show_rulers + Global.vertical_ruler.visible = Global.show_rulers + 3: #Show guides + Global.show_guides = !Global.show_guides + view_menu.set_item_checked(3, Global.show_guides) + for canvas in Global.canvases: + for guide in canvas.get_children(): + if guide is Guide: + guide.visible = Global.show_guides func help_menu_id_pressed(id : int) -> void: match id: diff --git a/Scripts/VerticalRuler.gd b/Scripts/VerticalRuler.gd index 5e12182d7..5077cffd6 100644 --- a/Scripts/VerticalRuler.gd +++ b/Scripts/VerticalRuler.gd @@ -55,6 +55,8 @@ func _draw() -> void: draw_line(Vector2(RULER_WIDTH * 0.66, position.y), Vector2(RULER_WIDTH, position.y), Color.white) func _on_VerticalRuler_pressed() -> void: + if !Global.show_guides: + return var guide := Guide.new() guide.type = guide.TYPE.VERTICAL guide.default_color = Color.purple