mirror of
https://github.com/tonytins/CozyPixelStudio.git
synced 2025-08-11 21:44:43 -04:00
Use enums instead of strings for tools
This could be a slight increase in performance
This commit is contained in:
parent
bda9e6267d
commit
5b7d161ecf
6 changed files with 71 additions and 72 deletions
|
@ -14,7 +14,7 @@ var mouse_press_pixels := [] # Cleared after mouse release
|
|||
var mouse_press_pressure_values := [] # Cleared after mouse release
|
||||
|
||||
|
||||
func draw_brush(sprite : Image, pos : Vector2, color : Color, current_mouse_button : String, pen_pressure : float, current_action := "None") -> void:
|
||||
func draw_brush(sprite : Image, pos : Vector2, color : Color, current_mouse_button : String, pen_pressure : float, current_action := -1) -> void:
|
||||
if Global.can_draw && Global.has_focus:
|
||||
var west_limit = Global.canvas.west_limit
|
||||
var east_limit = Global.canvas.east_limit
|
||||
|
@ -33,9 +33,9 @@ func draw_brush(sprite : Image, pos : Vector2, color : Color, current_mouse_butt
|
|||
var ld := 0
|
||||
var ld_amount := 0.1
|
||||
if Global.pressure_sensitivity_mode == Global.Pressure_Sensitivity.ALPHA:
|
||||
if current_action == "Pencil":
|
||||
if current_action == Global.Tools.PENCIL:
|
||||
color.a *= pen_pressure
|
||||
elif current_action == "Eraser": # This is not working
|
||||
elif current_action == Global.Tools.ERASER: # This is not working
|
||||
color.a *= (1.0 - pen_pressure)
|
||||
if current_mouse_button == "left_mouse":
|
||||
brush_size = Global.left_brush_size
|
||||
|
@ -86,7 +86,7 @@ func draw_brush(sprite : Image, pos : Vector2, color : Color, current_mouse_butt
|
|||
var end_pos_x
|
||||
var end_pos_y
|
||||
|
||||
if brush_type == Global.Brush_Types.PIXEL || current_action == "LightenDarken":
|
||||
if brush_type == Global.Brush_Types.PIXEL || current_action == Global.Tools.LIGHTENDARKEN:
|
||||
var drawer = pixel_perfect_drawer if pixel_perfect else simple_drawer
|
||||
var drawer_v_mirror = pixel_perfect_drawer_v_mirror if pixel_perfect else simple_drawer
|
||||
var drawer_h_mirror = pixel_perfect_drawer_h_mirror if pixel_perfect else simple_drawer
|
||||
|
@ -103,12 +103,12 @@ func draw_brush(sprite : Image, pos : Vector2, color : Color, current_mouse_butt
|
|||
# Don't draw the same pixel over and over and don't re-lighten/darken it
|
||||
var current_pixel_color : Color = sprite.get_pixel(cur_pos_x, cur_pos_y)
|
||||
var _c := color
|
||||
if current_action == "Pencil" && color.a < 1:
|
||||
if current_action == Global.Tools.PENCIL && color.a < 1:
|
||||
_c = DrawingAlgos.blend_colors(color, current_pixel_color)
|
||||
|
||||
var saved_pixel_index = DrawingAlgos.mouse_press_pixels.find(pos_floored)
|
||||
if current_pixel_color != _c && (saved_pixel_index == -1 || pen_pressure > DrawingAlgos.mouse_press_pressure_values[saved_pixel_index]):
|
||||
if current_action == "LightenDarken":
|
||||
if current_action == Global.Tools.LIGHTENDARKEN:
|
||||
_c = current_pixel_color
|
||||
if _c.a > 0:
|
||||
if ld == 0: # Lighten
|
||||
|
@ -129,7 +129,7 @@ func draw_brush(sprite : Image, pos : Vector2, color : Color, current_mouse_butt
|
|||
if horizontal_mirror:
|
||||
current_pixel_color = sprite.get_pixel(mirror_x, cur_pos_y)
|
||||
if current_pixel_color != _c: # don't draw the same pixel over and over
|
||||
if current_action == "LightenDarken":
|
||||
if current_action == Global.Tools.LIGHTENDARKEN:
|
||||
if ld == 0: # Lighten
|
||||
_c = current_pixel_color.lightened(ld_amount)
|
||||
else:
|
||||
|
@ -142,7 +142,7 @@ func draw_brush(sprite : Image, pos : Vector2, color : Color, current_mouse_butt
|
|||
if vertical_mirror:
|
||||
current_pixel_color = sprite.get_pixel(cur_pos_x, mirror_y)
|
||||
if current_pixel_color != _c: # don't draw the same pixel over and over
|
||||
if current_action == "LightenDarken":
|
||||
if current_action == Global.Tools.LIGHTENDARKEN:
|
||||
if ld == 0: # Lighten
|
||||
_c = current_pixel_color.lightened(ld_amount)
|
||||
else:
|
||||
|
@ -154,7 +154,7 @@ func draw_brush(sprite : Image, pos : Vector2, color : Color, current_mouse_butt
|
|||
if horizontal_mirror && vertical_mirror:
|
||||
current_pixel_color = sprite.get_pixel(mirror_x, mirror_y)
|
||||
if current_pixel_color != _c: # don't draw the same pixel over and over
|
||||
if current_action == "LightenDarken":
|
||||
if current_action == Global.Tools.LIGHTENDARKEN:
|
||||
if ld == 0: # Lighten
|
||||
_c = current_pixel_color.lightened(ld_amount)
|
||||
else:
|
||||
|
@ -255,7 +255,7 @@ func draw_brush(sprite : Image, pos : Vector2, color : Color, current_mouse_butt
|
|||
|
||||
# Bresenham's Algorithm
|
||||
# Thanks to https://godotengine.org/qa/35276/tile-based-line-drawing-algorithm-efficiency
|
||||
func fill_gaps(sprite : Image, end_pos : Vector2, start_pos : Vector2, color : Color, current_mouse_button : String, pen_pressure : float, current_action := "None") -> void:
|
||||
func fill_gaps(sprite : Image, end_pos : Vector2, start_pos : Vector2, color : Color, current_mouse_button : String, pen_pressure : float, current_action := -1) -> void:
|
||||
var previous_mouse_pos_floored = start_pos.floor()
|
||||
var mouse_pos_floored = end_pos.floor()
|
||||
var dx := int(abs(mouse_pos_floored.x - previous_mouse_pos_floored.x))
|
||||
|
@ -509,7 +509,6 @@ func scale3X(sprite : Image, tol : float = 50) -> Image:
|
|||
|
||||
|
||||
func rotxel(sprite : Image, angle : float) -> void:
|
||||
|
||||
# If angle is simple, then nn rotation is the best
|
||||
|
||||
if angle == 0 || angle == PI/2 || angle == PI || angle == 2*PI:
|
||||
|
|
|
@ -3,24 +3,19 @@ extends Node
|
|||
enum Grid_Types {CARTESIAN, ISOMETRIC, ALL}
|
||||
enum Pressure_Sensitivity {NONE, ALPHA, SIZE, ALPHA_AND_SIZE}
|
||||
enum Brush_Types {PIXEL, CIRCLE, FILLED_CIRCLE, FILE, RANDOM_FILE, CUSTOM}
|
||||
|
||||
var root_directory := "."
|
||||
var window_title := "" setget title_changed # Why doesn't Godot have get_window_title()?
|
||||
var config_cache := ConfigFile.new()
|
||||
var XDGDataPaths = preload("res://src/XDGDataPaths.gd")
|
||||
var directory_module : Reference
|
||||
enum Direction {UP, DOWN, LEFT, RIGHT}
|
||||
enum Tools {PENCIL, ERASER, BUCKET, LIGHTENDARKEN, RECTSELECT, COLORPICKER, ZOOM}
|
||||
|
||||
# Stuff for arrowkey-based canvas movements nyaa ^.^
|
||||
const low_speed_move_rate := 150.0
|
||||
const medium_speed_move_rate := 750.0
|
||||
const high_speed_move_rate := 3750.0
|
||||
|
||||
enum Direction {
|
||||
UP = 0,
|
||||
DOWN = 1,
|
||||
LEFT = 2,
|
||||
RIGHT = 3
|
||||
}
|
||||
var root_directory := "."
|
||||
var window_title := "" setget title_changed # Why doesn't Godot have get_window_title()?
|
||||
var config_cache := ConfigFile.new()
|
||||
var XDGDataPaths = preload("res://src/XDGDataPaths.gd")
|
||||
var directory_module : Reference
|
||||
|
||||
# Indices are as in the Direction enum
|
||||
# This is the total time the key for
|
||||
|
@ -69,8 +64,8 @@ var checker_color_1 := Color(0.47, 0.47, 0.47, 1)
|
|||
var checker_color_2 := Color(0.34, 0.35, 0.34, 1)
|
||||
|
||||
# Tools & options
|
||||
var current_left_tool := "Pencil"
|
||||
var current_right_tool := "Eraser"
|
||||
var current_left_tool : int = Tools.PENCIL
|
||||
var current_right_tool :int = Tools.ERASER
|
||||
var show_left_tool_icon := true
|
||||
var show_right_tool_icon := true
|
||||
var left_square_indicator_visible := true
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue