1
0
Fork 0
mirror of https://github.com/Orama-Interactive/Pixelorama.git synced 2025-01-18 17:19:50 +00:00

One shared offset for rectangular and isometric grids, added "Draw Grid over Tile Mode" toggle (#434)

* One shared offset for rectangular and isometric grids

* One draw call per grid

* Added "Draw Grid over Tile Mode" toggle
This commit is contained in:
kleonc 2021-01-20 01:17:33 +01:00 committed by GitHub
parent c60fb0632e
commit eeb97f71e4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 110 additions and 51 deletions

View file

@ -795,16 +795,16 @@ msgstr ""
msgid "All"
msgstr ""
msgid "Grid width:"
msgid "Rectangular grid width:"
msgstr ""
msgid "Sets how far apart are vertical lines of the grid"
msgid "Sets how far apart are vertical lines of the rectangular grid"
msgstr ""
msgid "Grid height:"
msgid "Rectangular grid height:"
msgstr ""
msgid "Sets how far apart are horizontal lines of the grid"
msgid "Sets how far apart are horizontal lines of rectangular the grid"
msgstr ""
msgid "Isometric cell bounds width:"
@ -819,16 +819,22 @@ msgstr ""
msgid "Sets the height of the isometric cell's axis aligned bounding box"
msgstr ""
msgid "Isometric grid offset x:"
msgid "Grid offset x:"
msgstr ""
msgid "Sets isometric grid's x offset from the canvas origin (top left corner of the image)"
msgid "Sets grid's x offset from the canvas origin (top left corner of the image)"
msgstr ""
msgid "Isometric grid offset y:"
msgid "Grid offset y:"
msgstr ""
msgid "Sets isometric grid's y offset from the canvas origin (top left corner of the image)"
msgid "Sets grid's y offset from the canvas origin (top left corner of the image)"
msgstr ""
msgid "Draw over Tile Mode:"
msgstr ""
msgid "If disabled grid will be drawn only over the original image"
msgstr ""
msgid "Grid color:"

View file

@ -56,8 +56,9 @@ var grid_width := 2
var grid_height := 2
var grid_isometric_cell_bounds_width := 16
var grid_isometric_cell_bounds_height := 8
var grid_isometric_offset_x := 0
var grid_isometric_offset_y := 0
var grid_offset_x := 0
var grid_offset_y := 0
var grid_draw_over_tile_mode := false
var grid_color := Color.black
var pixel_grid_show_at_zoom := 1500.0 # percentage
var pixel_grid_color := Color("91212121")

View file

@ -22,8 +22,9 @@ var preferences = [
["grid_height", "Canvas/GridOptions/GridHeightValue", "value", Global.grid_height],
["grid_isometric_cell_bounds_width", "Canvas/GridOptions/IsometricCellBoundsWidthValue", "value", Global.grid_isometric_cell_bounds_width],
["grid_isometric_cell_bounds_height", "Canvas/GridOptions/IsometricCellBoundsHeightValue", "value", Global.grid_isometric_cell_bounds_height],
["grid_isometric_offset_x", "Canvas/GridOptions/IsometricGridOffsetXValue", "value", Global.grid_isometric_offset_x],
["grid_isometric_offset_y", "Canvas/GridOptions/IsometricGridOffsetYValue", "value", Global.grid_isometric_offset_y],
["grid_offset_x", "Canvas/GridOptions/GridOffsetXValue", "value", Global.grid_offset_x],
["grid_offset_y", "Canvas/GridOptions/GridOffsetYValue", "value", Global.grid_offset_y],
["grid_draw_over_tile_mode", "Canvas/GridOptions/GridDrawOverTileMode", "pressed", Global.grid_draw_over_tile_mode],
["grid_color", "Canvas/GridOptions/GridColor", "color", Global.grid_color],
["pixel_grid_show_at_zoom", "Canvas/PixelGridOptions/ShowAtZoom", "value", Global.pixel_grid_show_at_zoom],
["pixel_grid_color", "Canvas/PixelGridOptions/GridColor", "color", Global.pixel_grid_color],
@ -131,7 +132,7 @@ func preference_update(prop : String) -> void:
else:
autosave_interval.mouse_default_cursor_shape = Control.CURSOR_FORBIDDEN
if prop in ["grid_type", "grid_width", "grid_height", "grid_isometric_cell_bounds_width", "grid_isometric_cell_bounds_height", "grid_isometric_offset_x", "grid_isometric_offset_y", "grid_color"]:
if prop in ["grid_type", "grid_width", "grid_height", "grid_isometric_cell_bounds_width", "grid_isometric_cell_bounds_height", "grid_offset_x", "grid_offset_y", "grid_draw_over_tile_mode", "grid_color"]:
Global.canvas.grid.update()
if prop in ["pixel_grid_show_at_zoom", "pixel_grid_color"]:

View file

@ -275,7 +275,7 @@ custom_constants/vseparation = 4
custom_constants/hseparation = 4
columns = 3
[node name="TypeLabel" type="Label" parent="HSplitContainer/ScrollContainer/VBoxContainer/Canvas/GridOptions"]
[node name="GridTypeLabel" type="Label" parent="HSplitContainer/ScrollContainer/VBoxContainer/Canvas/GridOptions"]
margin_top = 3.0
margin_right = 123.0
margin_bottom = 17.0
@ -296,48 +296,48 @@ text = "Rectangular"
items = [ "Rectangular", null, false, 0, null, "Isometric", null, false, 1, null, "All", null, false, 2, null ]
selected = 0
[node name="WidthLabel" type="Label" parent="HSplitContainer/ScrollContainer/VBoxContainer/Canvas/GridOptions"]
[node name="GridWidthLabel" type="Label" parent="HSplitContainer/ScrollContainer/VBoxContainer/Canvas/GridOptions"]
margin_left = 234.0
margin_top = 3.0
margin_right = 344.0
margin_bottom = 17.0
rect_min_size = Vector2( 110, 0 )
hint_tooltip = "Sets how far apart are vertical lines of the grid"
hint_tooltip = "Sets how far apart are vertical lines of the rectangular grid"
mouse_filter = 0
text = "Grid width:"
text = "Rectangular grid width:"
[node name="GridWidthValue" type="SpinBox" parent="HSplitContainer/ScrollContainer/VBoxContainer/Canvas/GridOptions"]
margin_top = 24.0
margin_right = 123.0
margin_bottom = 48.0
hint_tooltip = "Sets how far apart are vertical lines of the grid"
hint_tooltip = "Sets how far apart are vertical lines of the rectangular grid"
mouse_default_cursor_shape = 2
min_value = 1.0
max_value = 16384.0
value = 1.0
value = 2.0
rounded = true
align = 2
suffix = "px"
[node name="Height" type="Label" parent="HSplitContainer/ScrollContainer/VBoxContainer/Canvas/GridOptions"]
[node name="GridHeightLabel" type="Label" parent="HSplitContainer/ScrollContainer/VBoxContainer/Canvas/GridOptions"]
margin_left = 127.0
margin_top = 29.0
margin_right = 230.0
margin_bottom = 43.0
hint_tooltip = "Sets how far apart are horizontal lines of the grid"
hint_tooltip = "Sets how far apart are horizontal lines of the rectangular grid"
mouse_filter = 0
text = "Grid height:"
text = "Rectangular grid height:"
[node name="GridHeightValue" type="SpinBox" parent="HSplitContainer/ScrollContainer/VBoxContainer/Canvas/GridOptions"]
margin_left = 234.0
margin_top = 24.0
margin_right = 344.0
margin_bottom = 48.0
hint_tooltip = "Sets how far apart are horizontal lines of the grid"
hint_tooltip = "Sets how far apart are horizontal lines of the rectangular grid"
mouse_default_cursor_shape = 2
min_value = 1.0
max_value = 16384.0
value = 1.0
value = 2.0
rounded = true
align = 2
suffix = "px"
@ -386,20 +386,20 @@ rounded = true
align = 2
suffix = "px"
[node name="IsometricGridOffsetXLabel" type="Label" parent="HSplitContainer/ScrollContainer/VBoxContainer/Canvas/GridOptions"]
[node name="GridOffsetXLabel" type="Label" parent="HSplitContainer/ScrollContainer/VBoxContainer/Canvas/GridOptions"]
margin_top = 57.0
margin_right = 123.0
margin_bottom = 71.0
hint_tooltip = "Sets isometric grid's x offset from the canvas origin (top left corner of the image)"
hint_tooltip = "Sets grid's x offset from the canvas origin (top left corner of the image)"
mouse_filter = 0
text = "Isometric grid offset x:"
text = "Grid offset x:"
[node name="IsometricGridOffsetXValue" type="SpinBox" parent="HSplitContainer/ScrollContainer/VBoxContainer/Canvas/GridOptions"]
[node name="GridOffsetXValue" type="SpinBox" parent="HSplitContainer/ScrollContainer/VBoxContainer/Canvas/GridOptions"]
margin_left = 127.0
margin_top = 52.0
margin_right = 230.0
margin_bottom = 76.0
hint_tooltip = "Sets isometric grid's x offset from the canvas origin (top left corner of the image)"
hint_tooltip = "Sets grid's x offset from the canvas origin (top left corner of the image)"
mouse_default_cursor_shape = 2
min_value = -16384.0
max_value = 16384.0
@ -407,20 +407,20 @@ rounded = true
align = 2
suffix = "px"
[node name="IsometricGridOffsetYLabel" type="Label" parent="HSplitContainer/ScrollContainer/VBoxContainer/Canvas/GridOptions"]
[node name="GridOffsetYLabel" type="Label" parent="HSplitContainer/ScrollContainer/VBoxContainer/Canvas/GridOptions"]
margin_top = 57.0
margin_right = 123.0
margin_bottom = 71.0
hint_tooltip = "Sets isometric grid's y offset from the canvas origin (top left corner of the image)"
hint_tooltip = "Sets grid's y offset from the canvas origin (top left corner of the image)"
mouse_filter = 0
text = "Isometric grid offset y:"
text = "Grid offset y:"
[node name="IsometricGridOffsetYValue" type="SpinBox" parent="HSplitContainer/ScrollContainer/VBoxContainer/Canvas/GridOptions"]
[node name="GridOffsetYValue" type="SpinBox" parent="HSplitContainer/ScrollContainer/VBoxContainer/Canvas/GridOptions"]
margin_left = 127.0
margin_top = 52.0
margin_right = 230.0
margin_bottom = 76.0
hint_tooltip = "Sets isometric grid's y offset from the canvas origin (top left corner of the image)"
hint_tooltip = "Sets grid's y offset from the canvas origin (top left corner of the image)"
mouse_default_cursor_shape = 2
min_value = -16384.0
max_value = 16384.0
@ -428,6 +428,24 @@ rounded = true
align = 2
suffix = "px"
[node name="GridDrawOverTileModeLabel" type="Label" parent="HSplitContainer/ScrollContainer/VBoxContainer/Canvas/GridOptions"]
margin_top = -99.0
margin_right = 131.0
margin_bottom = -85.0
rect_min_size = Vector2( 110, 0 )
hint_tooltip = "If disabled grid will be drawn only over the original image"
mouse_filter = 0
text = "Draw over Tile Mode:"
[node name="GridDrawOverTileMode" type="CheckBox" parent="HSplitContainer/ScrollContainer/VBoxContainer/Canvas/GridOptions"]
margin_left = 114.0
margin_top = -104.0
margin_right = 161.0
margin_bottom = -80.0
hint_tooltip = "If disabled grid will be drawn only over the original image"
mouse_default_cursor_shape = 2
text = "On"
[node name="GridColorLabel" type="Label" parent="HSplitContainer/ScrollContainer/VBoxContainer/Canvas/GridOptions"]
margin_left = 234.0
margin_top = 57.0

View file

@ -5,22 +5,43 @@ func _draw() -> void:
if not Global.draw_grid:
return
var rect := Rect2(Vector2.ZERO, Global.current_project.size)
if rect.has_no_area():
var target_rect : Rect2
if Global.grid_draw_over_tile_mode:
target_rect = Global.current_project.get_tile_mode_rect()
else:
target_rect = Rect2(Vector2.ZERO, Global.current_project.size)
if target_rect.has_no_area():
return
var grid_type : int = Global.grid_type
if grid_type == Global.Grid_Types.CARTESIAN || grid_type == Global.Grid_Types.ALL:
var start_x : float = wrapf(0, rect.position.x, rect.position.x + Global.grid_width)
for x in range(start_x, rect.end.x + 1, Global.grid_width):
draw_line(Vector2(x, rect.position.y), Vector2(x, rect.end.y), Global.grid_color)
var start_y : float = wrapf(0, rect.position.y, rect.position.y + Global.grid_height)
for y in range(start_y, rect.end.y + 1, Global.grid_height):
draw_line(Vector2(rect.position.x, y), Vector2(rect.end.x, y), Global.grid_color)
_draw_cartesian_grid(target_rect)
if grid_type == Global.Grid_Types.ISOMETRIC || grid_type == Global.Grid_Types.ALL:
_draw_isometric_grid(rect)
_draw_isometric_grid(target_rect)
func _draw_cartesian_grid(target_rect : Rect2) -> void:
# Using Array instead of PoolVector2Array to avoid kinda
# random "resize: Can't resize PoolVector if locked" errors.
# See: https://github.com/Orama-Interactive/Pixelorama/issues/331
# It will be converted to PoolVector2Array before being sent to be rendered.
var grid_multiline_points := []
var x : float = target_rect.position.x + fposmod(Global.grid_offset_x - target_rect.position.x, Global.grid_width)
while x <= target_rect.end.x:
grid_multiline_points.push_back(Vector2(x, target_rect.position.y))
grid_multiline_points.push_back(Vector2(x, target_rect.end.y))
x += Global.grid_width
var y : float = target_rect.position.y + fposmod(Global.grid_offset_y - target_rect.position.y, Global.grid_height)
while y <= target_rect.end.y:
grid_multiline_points.push_back(Vector2(target_rect.position.x, y))
grid_multiline_points.push_back(Vector2(target_rect.end.x, y))
y += Global.grid_height
if not grid_multiline_points.empty():
draw_multiline(grid_multiline_points, Global.grid_color)
func _draw_isometric_grid(target_rect : Rect2) -> void:
@ -33,7 +54,7 @@ func _draw_isometric_grid(target_rect : Rect2) -> void:
var cell_size := Vector2(Global.grid_isometric_cell_bounds_width, Global.grid_isometric_cell_bounds_height)
var max_cell_count : Vector2 = target_rect.size / cell_size
var origin := Vector2(Global.grid_isometric_offset_x, Global.grid_isometric_offset_y)
var origin := Vector2(Global.grid_offset_x, Global.grid_offset_y)
var origin_offset : Vector2 = (origin - target_rect.position).posmodv(cell_size)
# lines ↗↗↗ (from bottom-left to top-right)

View file

@ -9,11 +9,23 @@ func _draw() -> void:
if zoom_percentage < Global.pixel_grid_show_at_zoom:
return
var rect : Rect2 = Global.current_project.get_tile_mode_rect()
if rect.has_no_area():
var target_rect : Rect2 = Global.current_project.get_tile_mode_rect()
if target_rect.has_no_area():
return
for x in range(ceil(rect.position.x), floor(rect.end.x) + 1):
draw_line(Vector2(x, rect.position.y), Vector2(x, rect.end.y), Global.pixel_grid_color)
for y in range(ceil(rect.position.y), floor(rect.end.y) + 1):
draw_line(Vector2(rect.position.x, y), Vector2(rect.end.x, y), Global.pixel_grid_color)
# Using Array instead of PoolVector2Array to avoid kinda
# random "resize: Can't resize PoolVector if locked" errors.
# See: https://github.com/Orama-Interactive/Pixelorama/issues/331
# It will be converted to PoolVector2Array before being sent to be rendered.
var grid_multiline_points := []
for x in range(ceil(target_rect.position.x), floor(target_rect.end.x) + 1):
grid_multiline_points.push_back(Vector2(x, target_rect.position.y))
grid_multiline_points.push_back(Vector2(x, target_rect.end.y))
for y in range(ceil(target_rect.position.y), floor(target_rect.end.y) + 1):
grid_multiline_points.push_back(Vector2(target_rect.position.x, y))
grid_multiline_points.push_back(Vector2(target_rect.end.x, y))
if not grid_multiline_points.empty():
draw_multiline(grid_multiline_points, Global.pixel_grid_color)