mirror of
https://github.com/Orama-Interactive/Pixelorama.git
synced 2025-02-20 12:33:14 +00:00
Moved the _min and _max variables to Project.gd
This commit is contained in:
parent
60126e46d3
commit
35969b2f67
5 changed files with 60 additions and 60 deletions
|
@ -13,10 +13,10 @@ func reset() -> void:
|
|||
|
||||
|
||||
func draw_pixel_blended(sprite : Image, pos : Vector2, color : Color, pen_pressure : float, current_mouse_button := -1, current_action := -1) -> void:
|
||||
var x_min = Global.canvas.x_min
|
||||
var x_max = Global.canvas.x_max
|
||||
var y_min = Global.canvas.y_min
|
||||
var y_max = Global.canvas.y_max
|
||||
var x_min = Global.current_project.x_min
|
||||
var x_max = Global.current_project.x_max
|
||||
var y_min = Global.current_project.y_min
|
||||
var y_max = Global.current_project.y_max
|
||||
if !point_in_rectangle(pos, Vector2(x_min - 1, y_min - 1), Vector2(x_max, y_max)):
|
||||
return
|
||||
|
||||
|
@ -45,10 +45,10 @@ func draw_pixel_blended(sprite : Image, pos : Vector2, color : Color, pen_pressu
|
|||
|
||||
func draw_brush(sprite : Image, pos : Vector2, color : Color, current_mouse_button : int, pen_pressure : float, current_action := -1) -> void:
|
||||
if Global.can_draw && Global.has_focus:
|
||||
var x_min = Global.canvas.x_min
|
||||
var x_max = Global.canvas.x_max
|
||||
var y_min = Global.canvas.y_min
|
||||
var y_max = Global.canvas.y_max
|
||||
var x_min = Global.current_project.x_min
|
||||
var x_max = Global.current_project.x_max
|
||||
var y_min = Global.current_project.y_min
|
||||
var y_max = Global.current_project.y_max
|
||||
|
||||
if Global.pressure_sensitivity_mode == Global.Pressure_Sensitivity.ALPHA:
|
||||
if current_action == Global.Tools.PENCIL:
|
||||
|
@ -226,10 +226,10 @@ func plot_circle(sprite : Image, xm : int, ym : int, r : int, color : Color, fil
|
|||
|
||||
# Thanks to https://en.wikipedia.org/wiki/Flood_fill
|
||||
func flood_fill(sprite : Image, pos : Vector2, target_color : Color, replace_color : Color) -> void:
|
||||
var x_min = Global.canvas.x_min
|
||||
var x_max = Global.canvas.x_max
|
||||
var y_min = Global.canvas.y_min
|
||||
var y_max = Global.canvas.y_max
|
||||
var x_min = Global.current_project.x_min
|
||||
var x_max = Global.current_project.x_max
|
||||
var y_min = Global.current_project.y_min
|
||||
var y_max = Global.current_project.y_max
|
||||
pos = pos.floor()
|
||||
var pixel = sprite.get_pixelv(pos)
|
||||
if target_color == replace_color:
|
||||
|
@ -268,10 +268,10 @@ func flood_fill(sprite : Image, pos : Vector2, target_color : Color, replace_col
|
|||
|
||||
|
||||
func pattern_fill(sprite : Image, pos : Vector2, pattern : Image, target_color : Color, var offset : Vector2) -> void:
|
||||
var x_min = Global.canvas.x_min
|
||||
var x_max = Global.canvas.x_max
|
||||
var y_min = Global.canvas.y_min
|
||||
var y_max = Global.canvas.y_max
|
||||
var x_min = Global.current_project.x_min
|
||||
var x_max = Global.current_project.x_max
|
||||
var y_min = Global.current_project.y_min
|
||||
var y_max = Global.current_project.y_max
|
||||
pos = pos.floor()
|
||||
if !point_in_rectangle(pos, Vector2(x_min - 1, y_min - 1), Vector2(x_max, y_max)):
|
||||
return
|
||||
|
@ -558,10 +558,10 @@ func colorDistance(c1 : Color, c2 : Color) -> float:
|
|||
|
||||
|
||||
func adjust_hsv(img: Image, id : int, delta : float) -> void:
|
||||
var x_min = Global.canvas.x_min
|
||||
var x_max = Global.canvas.x_max
|
||||
var y_min = Global.canvas.y_min
|
||||
var y_max = Global.canvas.y_max
|
||||
var x_min = Global.current_project.x_min
|
||||
var x_max = Global.current_project.x_max
|
||||
var y_min = Global.current_project.y_min
|
||||
var y_max = Global.current_project.y_max
|
||||
img.lock()
|
||||
|
||||
match id:
|
||||
|
|
|
@ -10,10 +10,6 @@ var previous_mouse_pos_for_lines := Vector2.ZERO
|
|||
var can_undo := true
|
||||
var cursor_image_has_changed := false
|
||||
var previous_action := -1
|
||||
var x_min := 0
|
||||
var x_max := 64
|
||||
var y_min := 0
|
||||
var y_max := 64
|
||||
var sprite_changed_this_frame := false # for optimization purposes
|
||||
var is_making_line := false
|
||||
var made_line := false
|
||||
|
@ -24,10 +20,6 @@ var pen_pressure := 1.0 # For tablet pressure sensitivity
|
|||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
x_min = location.x
|
||||
x_max = location.x + Global.current_project.size.x
|
||||
y_min = location.y
|
||||
y_max = location.y + Global.current_project.size.y
|
||||
var frame : Frame = new_empty_frame(true)
|
||||
Global.current_project.frames.append(frame)
|
||||
camera_zoom()
|
||||
|
@ -124,16 +116,17 @@ func _input(event : InputEvent) -> void:
|
|||
var mouse_pos := current_pixel
|
||||
var mouse_pos_floored := mouse_pos.floor()
|
||||
var current_mouse_button := -1
|
||||
var current_project : Project = Global.current_project
|
||||
|
||||
x_min = location.x
|
||||
x_max = location.x + Global.current_project.size.x
|
||||
y_min = location.y
|
||||
y_max = location.y + Global.current_project.size.y
|
||||
if Global.current_project.selected_pixels.size() != 0:
|
||||
x_min = max(x_min, Global.selection_rectangle.polygon[0].x)
|
||||
x_max = min(x_max, Global.selection_rectangle.polygon[2].x)
|
||||
y_min = max(y_min, Global.selection_rectangle.polygon[0].y)
|
||||
y_max = min(y_max, Global.selection_rectangle.polygon[2].y)
|
||||
current_project.x_min = location.x
|
||||
current_project.x_max = location.x + current_project.size.x
|
||||
current_project.y_min = location.y
|
||||
current_project.y_max = location.y + current_project.size.y
|
||||
if current_project.selected_pixels.size() != 0:
|
||||
current_project.x_min = max(current_project.x_min, Global.selection_rectangle.polygon[0].x)
|
||||
current_project.x_max = min(current_project.x_max, Global.selection_rectangle.polygon[2].x)
|
||||
current_project.y_min = max(current_project.y_min, Global.selection_rectangle.polygon[0].y)
|
||||
current_project.y_max = min(current_project.y_max, Global.selection_rectangle.polygon[2].y)
|
||||
|
||||
if Input.is_mouse_button_pressed(BUTTON_LEFT):
|
||||
current_mouse_button = Global.Mouse_Button.LEFT
|
||||
|
@ -144,7 +137,7 @@ func _input(event : InputEvent) -> void:
|
|||
var current_action : int = Global.current_tools[current_mouse_button] if current_mouse_button != -1 else -1
|
||||
|
||||
if Global.has_focus:
|
||||
Global.cursor_position_label.text = "[%s×%s] %s, %s" % [Global.current_project.size.x, Global.current_project.size.y, mouse_pos_floored.x, mouse_pos_floored.y]
|
||||
Global.cursor_position_label.text = "[%s×%s] %s, %s" % [current_project.size.x, current_project.size.y, mouse_pos_floored.x, mouse_pos_floored.y]
|
||||
if !cursor_image_has_changed:
|
||||
cursor_image_has_changed = true
|
||||
if Global.cursor_image.get_data().get_size() != Vector2.ZERO:
|
||||
|
@ -154,7 +147,7 @@ func _input(event : InputEvent) -> void:
|
|||
if Global.show_right_tool_icon:
|
||||
Global.right_cursor.visible = true
|
||||
else:
|
||||
Global.cursor_position_label.text = "[%s×%s]" % [Global.current_project.size.x, Global.current_project.size.y]
|
||||
Global.cursor_position_label.text = "[%s×%s]" % [current_project.size.x, current_project.size.y]
|
||||
if cursor_image_has_changed:
|
||||
cursor_image_has_changed = false
|
||||
Global.left_cursor.visible = false
|
||||
|
@ -173,7 +166,7 @@ func _input(event : InputEvent) -> void:
|
|||
else:
|
||||
handle_undo("Draw")
|
||||
elif (Input.is_action_just_released("left_mouse") && !Input.is_action_pressed("right_mouse")) || (Input.is_action_just_released("right_mouse") && !Input.is_action_pressed("left_mouse")):
|
||||
if can_handle || Global.current_project.undos == Global.current_project.undo_redo.get_version():
|
||||
if can_handle || current_project.undos == current_project.undo_redo.get_version():
|
||||
if previous_action != -1 && previous_action != Global.Tools.RECTSELECT && current_action != Global.Tools.COLORPICKER && current_action != Global.Tools.ZOOM:
|
||||
handle_redo("Draw")
|
||||
|
||||
|
@ -223,14 +216,14 @@ func _input(event : InputEvent) -> void:
|
|||
|
||||
for xx in range(start_pos.x, end_pos.x):
|
||||
for yy in range(start_pos.y, end_pos.y):
|
||||
Global.current_project.selected_pixels.append(Vector2(xx, yy))
|
||||
current_project.selected_pixels.append(Vector2(xx, yy))
|
||||
is_making_selection = -1
|
||||
handle_redo("Rectangle Select")
|
||||
|
||||
previous_action = current_action
|
||||
previous_mouse_pos = current_pixel
|
||||
if sprite_changed_this_frame:
|
||||
update_texture(Global.current_project.current_layer)
|
||||
update_texture(current_project.current_layer)
|
||||
|
||||
|
||||
func camera_zoom() -> void:
|
||||
|
@ -274,7 +267,8 @@ func new_empty_frame(first_time := false) -> Frame:
|
|||
|
||||
|
||||
func handle_tools(current_mouse_button : int, current_action : int, mouse_pos : Vector2, can_handle : bool) -> void:
|
||||
var current_cel : Cel = Global.current_project.frames[Global.current_project.current_frame].cels[Global.current_project.current_layer]
|
||||
var current_project : Project = Global.current_project
|
||||
var current_cel : Cel = current_project.frames[current_project.current_frame].cels[current_project.current_layer]
|
||||
var sprite : Image = current_cel.image
|
||||
var mouse_pos_floored := mouse_pos.floor()
|
||||
var mouse_pos_ceiled := mouse_pos.ceil()
|
||||
|
@ -298,8 +292,8 @@ func handle_tools(current_mouse_button : int, current_action : int, mouse_pos :
|
|||
var pattern_offset : Vector2 = Global.fill_pattern_offsets[current_mouse_button]
|
||||
|
||||
if fill_area == Global.Fill_Area.SAME_COLOR_AREA: # Paint the specific area of the same color
|
||||
var mirror_x := x_max + x_min - mouse_pos_floored.x - 1
|
||||
var mirror_y := y_max + y_min - mouse_pos_floored.y - 1
|
||||
var mirror_x := current_project.x_max + current_project.x_min - mouse_pos_floored.x - 1
|
||||
var mirror_y := current_project.y_max + current_project.y_min - mouse_pos_floored.y - 1
|
||||
var horizontal_mirror : bool = Global.horizontal_mirror[current_mouse_button]
|
||||
var vertical_mirror : bool = Global.vertical_mirror[current_mouse_button]
|
||||
|
||||
|
@ -329,8 +323,8 @@ func handle_tools(current_mouse_button : int, current_action : int, mouse_pos :
|
|||
|
||||
else: # Paint all pixels of the same color
|
||||
var pixel_color : Color = sprite.get_pixelv(mouse_pos)
|
||||
for xx in range(x_min, x_max):
|
||||
for yy in range(y_min, y_max):
|
||||
for xx in range(current_project.x_min, current_project.x_max):
|
||||
for yy in range(current_project.y_min, current_project.y_max):
|
||||
var c : Color = sprite.get_pixel(xx, yy)
|
||||
if c == pixel_color:
|
||||
if fill_with == Global.Fill_With.PATTERN && pattern_image: # Pattern fill
|
||||
|
@ -357,7 +351,7 @@ func handle_tools(current_mouse_button : int, current_action : int, mouse_pos :
|
|||
# Check SelectionRectangle.gd for more code on Rectangle Selection
|
||||
if Global.can_draw && Global.has_focus:
|
||||
# If we're creating a new selection
|
||||
if Global.current_project.selected_pixels.size() == 0 || !point_in_rectangle(mouse_pos_floored, Global.selection_rectangle.polygon[0] - Vector2.ONE, Global.selection_rectangle.polygon[2]):
|
||||
if current_project.selected_pixels.size() == 0 || !point_in_rectangle(mouse_pos_floored, Global.selection_rectangle.polygon[0] - Vector2.ONE, Global.selection_rectangle.polygon[2]):
|
||||
var mouse_button_string := "left_mouse" if current_mouse_button == Global.Mouse_Button.LEFT else "right_mouse"
|
||||
|
||||
if Input.is_action_just_pressed(mouse_button_string):
|
||||
|
@ -366,7 +360,7 @@ func handle_tools(current_mouse_button : int, current_action : int, mouse_pos :
|
|||
Global.selection_rectangle.polygon[2] = mouse_pos_floored
|
||||
Global.selection_rectangle.polygon[3] = mouse_pos_floored
|
||||
is_making_selection = current_mouse_button
|
||||
Global.current_project.selected_pixels.clear()
|
||||
current_project.selected_pixels.clear()
|
||||
else:
|
||||
if is_making_selection != -1: # If we're making a new selection...
|
||||
var start_pos = Global.selection_rectangle.polygon[0]
|
||||
|
@ -380,7 +374,7 @@ func handle_tools(current_mouse_button : int, current_action : int, mouse_pos :
|
|||
Global.selection_rectangle.polygon[2] = end_pos
|
||||
Global.selection_rectangle.polygon[3] = Vector2(start_pos.x, end_pos.y)
|
||||
Global.Tools.COLORPICKER:
|
||||
var canvas_rect := Rect2(location, Global.current_project.size)
|
||||
var canvas_rect := Rect2(location, current_project.size)
|
||||
if can_handle && canvas_rect.has_point(mouse_pos):
|
||||
var image_data := Image.new()
|
||||
image_data.copy_from(sprite)
|
||||
|
|
|
@ -53,8 +53,8 @@ func set_pixel_perfect(value: bool) -> void:
|
|||
|
||||
|
||||
func set_pixel(_sprite: Image, _pos: Vector2, _new_color: Color) -> void:
|
||||
var mirror_x = Global.canvas.x_max + Global.canvas.x_min - _pos.x - 1
|
||||
var mirror_y = Global.canvas.y_max + Global.canvas.y_min - _pos.y - 1
|
||||
var mirror_x = Global.current_project.x_max + Global.current_project.x_min - _pos.x - 1
|
||||
var mirror_y = Global.current_project.y_max + Global.current_project.y_min - _pos.y - 1
|
||||
|
||||
drawers[0].set_pixel(_sprite, _pos, _new_color)
|
||||
if h_mirror:
|
||||
|
|
|
@ -19,12 +19,18 @@ var brush_images := [Image.new(), Image.new()]
|
|||
var brush_textures := [ImageTexture.new(), ImageTexture.new()]
|
||||
|
||||
var selected_pixels := []
|
||||
var x_min := 0
|
||||
var x_max := 64
|
||||
var y_min := 0
|
||||
var y_max := 64
|
||||
|
||||
|
||||
func _init(_frames := [], _name := tr("untitled"), _size := Vector2(64, 64)) -> void:
|
||||
frames = _frames
|
||||
name = _name
|
||||
size = _size
|
||||
x_max = size.x
|
||||
y_max = size.y
|
||||
layers.append(Layer.new())
|
||||
undo_redo = UndoRedo.new()
|
||||
|
||||
|
@ -112,7 +118,7 @@ func frames_changed(value : Array) -> void:
|
|||
|
||||
layers[i].frame_container.add_child(cel_button)
|
||||
|
||||
set_first_and_last_frames()
|
||||
set_timeline_first_and_last_frames()
|
||||
|
||||
|
||||
func layers_changed(value : Array) -> void:
|
||||
|
@ -257,10 +263,10 @@ func animation_tags_changed(value : Array) -> void:
|
|||
tag_c.get_node("Line2D").points[2] = Vector2(tag_c.rect_min_size.x, 0)
|
||||
tag_c.get_node("Line2D").points[3] = Vector2(tag_c.rect_min_size.x, 32)
|
||||
|
||||
set_first_and_last_frames()
|
||||
set_timeline_first_and_last_frames()
|
||||
|
||||
|
||||
func set_first_and_last_frames() -> void:
|
||||
func set_timeline_first_and_last_frames() -> void:
|
||||
# This is useful in case tags get modified DURING the animation is playing
|
||||
# otherwise, this code is useless in this context, since these values are being set
|
||||
# when the play buttons get pressed anyway
|
||||
|
|
|
@ -209,11 +209,11 @@ size_flags_horizontal = 3
|
|||
size_flags_vertical = 3
|
||||
custom_constants/separation = 0
|
||||
|
||||
[node name="TabContainer" type="PanelContainer" parent="CanvasAndTimeline/ViewportAndRulers"]
|
||||
[node name="TabsContainer" type="PanelContainer" parent="CanvasAndTimeline/ViewportAndRulers"]
|
||||
margin_right = 902.0
|
||||
margin_bottom = 38.0
|
||||
|
||||
[node name="Tabs" type="Tabs" parent="CanvasAndTimeline/ViewportAndRulers/TabContainer"]
|
||||
[node name="Tabs" type="Tabs" parent="CanvasAndTimeline/ViewportAndRulers/TabsContainer"]
|
||||
margin_left = 7.0
|
||||
margin_top = 7.0
|
||||
margin_right = 895.0
|
||||
|
@ -386,9 +386,9 @@ margin_bottom = 248.0
|
|||
[node name="PalettePanelContainer" parent="RightPanel/PreviewAndPalettes/ToolAndPaletteVSplit" instance=ExtResource( 20 )]
|
||||
margin_top = 260.0
|
||||
margin_bottom = 508.0
|
||||
[connection signal="reposition_active_tab_request" from="CanvasAndTimeline/ViewportAndRulers/TabContainer/Tabs" to="CanvasAndTimeline/ViewportAndRulers/TabContainer/Tabs" method="_on_Tabs_reposition_active_tab_request"]
|
||||
[connection signal="tab_changed" from="CanvasAndTimeline/ViewportAndRulers/TabContainer/Tabs" to="CanvasAndTimeline/ViewportAndRulers/TabContainer/Tabs" method="_on_Tabs_tab_changed"]
|
||||
[connection signal="tab_close" from="CanvasAndTimeline/ViewportAndRulers/TabContainer/Tabs" to="CanvasAndTimeline/ViewportAndRulers/TabContainer/Tabs" method="_on_Tabs_tab_close"]
|
||||
[connection signal="reposition_active_tab_request" from="CanvasAndTimeline/ViewportAndRulers/TabsContainer/Tabs" to="CanvasAndTimeline/ViewportAndRulers/TabsContainer/Tabs" method="_on_Tabs_reposition_active_tab_request"]
|
||||
[connection signal="tab_changed" from="CanvasAndTimeline/ViewportAndRulers/TabsContainer/Tabs" to="CanvasAndTimeline/ViewportAndRulers/TabsContainer/Tabs" method="_on_Tabs_tab_changed"]
|
||||
[connection signal="tab_close" from="CanvasAndTimeline/ViewportAndRulers/TabsContainer/Tabs" to="CanvasAndTimeline/ViewportAndRulers/TabsContainer/Tabs" method="_on_Tabs_tab_close"]
|
||||
[connection signal="mouse_entered" from="CanvasAndTimeline/ViewportAndRulers/HorizontalRuler" to="CanvasAndTimeline/ViewportAndRulers/HorizontalRuler" method="_on_HorizontalRuler_mouse_entered"]
|
||||
[connection signal="pressed" from="CanvasAndTimeline/ViewportAndRulers/HorizontalRuler" to="CanvasAndTimeline/ViewportAndRulers/HorizontalRuler" method="_on_HorizontalRuler_pressed"]
|
||||
[connection signal="pressed" from="CanvasAndTimeline/ViewportAndRulers/HSplitContainer/ViewportandVerticalRuler/VerticalRuler" to="CanvasAndTimeline/ViewportAndRulers/HSplitContainer/ViewportandVerticalRuler/VerticalRuler" method="_on_VerticalRuler_pressed"]
|
||||
|
|
Loading…
Add table
Reference in a new issue