11extends Panel
22
3-
43var paint_control
54
6- var label_tools
7- var label_brush_size
8- var label_brush_shape
9- var label_stats
5+ onready var brush_settings = $ BrushSettings
6+ onready var label_tools = $ LabelTools
7+ onready var label_brush_size = $ BrushSettings/LabelBrushSize
8+ onready var label_brush_shape = $ BrushSettings/LabelBrushShape
9+ onready var label_stats = $ LabelStats
1010
1111var save_dialog
1212
13-
1413func _ready ():
15- # Get PaintControl and SaveFileDialog
14+ # Get PaintControl and SaveFileDialog.
1615 paint_control = get_parent ().get_node ("PaintControl" )
1716 save_dialog = get_parent ().get_node ("SaveFileDialog" )
1817
1918 # warning-ignore-all:return_value_discarded
20- # Assign all of the needed signals for the oppersation buttons
21- get_node ( " ButtonUndo" ) .connect ("pressed" , self , "button_pressed" , ["undo_stroke" ])
22- get_node ( " ButtonSave" ) .connect ("pressed" , self , "button_pressed" , ["save_picture" ])
23- get_node ( " ButtonClear" ) .connect ("pressed" , self , "button_pressed" , ["clear_picture" ])
24-
25- # Assign all of the needed signals for the brush buttons
26- get_node ( " ButtonToolPencil" ) .connect ("pressed" , self , "button_pressed" , ["mode_pencil" ])
27- get_node ( " ButtonToolEraser" ) .connect ("pressed" , self , "button_pressed" , ["mode_eraser" ])
28- get_node ( " ButtonToolRectangle" ) .connect ("pressed" , self , "button_pressed" , ["mode_rectangle" ])
29- get_node ( " ButtonToolCircle" ) .connect ("pressed" , self , "button_pressed" , ["mode_circle" ])
30- get_node ( " ButtonShapeBox" ) .connect ("pressed" , self , "button_pressed" , ["shape_rectangle" ])
31- get_node ( " ButtonShapeCircle" ) .connect ("pressed" , self , "button_pressed" , ["shape_circle" ])
32-
33- # Assign all of the needed signals for the other brush settings (and ColorPickerBackground)
34- get_node ( " ColorPickerBrush" ) .connect ("color_changed" , self , "brush_color_changed" )
35- get_node ( " ColorPickerBackground" ) .connect ("color_changed" , self , "background_color_changed" )
36- get_node ( " HScrollBarBrushSize" ) .connect ("value_changed" , self , "brush_size_changed" )
37-
38- # Assign the 'file_selected' signal in SaveFileDialog
19+ # Assign all of the needed signals for the oppersation buttons.
20+ $ ButtonUndo .connect ("pressed" , self , "button_pressed" , ["undo_stroke" ])
21+ $ ButtonSave .connect ("pressed" , self , "button_pressed" , ["save_picture" ])
22+ $ ButtonClear .connect ("pressed" , self , "button_pressed" , ["clear_picture" ])
23+
24+ # Assign all of the needed signals for the brush buttons.
25+ $ ButtonToolPencil .connect ("pressed" , self , "button_pressed" , ["mode_pencil" ])
26+ $ ButtonToolEraser .connect ("pressed" , self , "button_pressed" , ["mode_eraser" ])
27+ $ ButtonToolRectangle .connect ("pressed" , self , "button_pressed" , ["mode_rectangle" ])
28+ $ ButtonToolCircle .connect ("pressed" , self , "button_pressed" , ["mode_circle" ])
29+ $ BrushSettings/ ButtonShapeBox .connect ("pressed" , self , "button_pressed" , ["shape_rectangle" ])
30+ $ BrushSettings/ ButtonShapeCircle .connect ("pressed" , self , "button_pressed" , ["shape_circle" ])
31+
32+ # Assign all of the needed signals for the other brush settings (and ColorPickerBackground).
33+ $ ColorPickerBrush .connect ("color_changed" , self , "brush_color_changed" )
34+ $ ColorPickerBackground .connect ("color_changed" , self , "background_color_changed" )
35+ $ BrushSettings/ HScrollBarBrushSize .connect ("value_changed" , self , "brush_size_changed" )
36+
37+ # Assign the 'file_selected' signal in SaveFileDialog.
3938 save_dialog .connect ("file_selected" , self , "save_file_selected" )
4039
41- # Get all of the labels so we can update them when settings change
42- label_tools = get_node ("LabelTools" )
43- label_brush_size = get_node ("LabelBrushSize" )
44- label_brush_shape = get_node ("LabelBrushShape" )
45- label_stats = get_node ("LabelStats" )
46-
47- # Set physics process so we can update the status label
40+ # Set physics process so we can update the status label.
4841 set_physics_process (true )
4942
5043
5144func _physics_process (_delta ):
52- # Update the status label with the newest brush element count
45+ # Update the status label with the newest brush element count.
5346 label_stats .text = "Brush objects: " + String (paint_control .brush_data_list .size ())
5447
5548
5649func button_pressed (button_name ):
57- # If a brush mode button is pressed
50+ # If a brush mode button is pressed.
5851 var tool_name = null
5952 var shape_name = null
6053
6154 if button_name == "mode_pencil" :
62- paint_control .brush_mode = paint_control .BRUSH_MODES .pencil
63- tool_name = "pencil"
55+ paint_control .brush_mode = paint_control .BrushModes .PENCIL
56+ brush_settings .modulate = Color (1 , 1 , 1 , 1 )
57+ tool_name = "Pencil"
6458 elif button_name == "mode_eraser" :
65- paint_control .brush_mode = paint_control .BRUSH_MODES .eraser
66- tool_name = "eraser"
59+ paint_control .brush_mode = paint_control .BrushModes .ERASER
60+ brush_settings .modulate = Color (1 , 1 , 1 , 1 )
61+ tool_name = "Eraser"
6762 elif button_name == "mode_rectangle" :
68- paint_control .brush_mode = paint_control .BRUSH_MODES .rectangle_shape
69- tool_name = "rectangle shape"
63+ paint_control .brush_mode = paint_control .BrushModes .RECTANGLE_SHAPE
64+ brush_settings .modulate = Color (1 , 1 , 1 , 0.5 )
65+ tool_name = "Rectangle shape"
7066 elif button_name == "mode_circle" :
71- paint_control .brush_mode = paint_control .BRUSH_MODES .circle_shape
72- tool_name = "circle shape"
67+ paint_control .brush_mode = paint_control .BrushModes .CIRCLE_SHAPE
68+ brush_settings .modulate = Color (1 , 1 , 1 , 0.5 )
69+ tool_name = "Circle shape"
7370
7471 # If a brush shape button is pressed
7572 elif button_name == "shape_rectangle" :
76- paint_control .brush_shape = paint_control .BRUSH_SHAPES . rectangle
77- shape_name = "rectangle "
73+ paint_control .brush_shape = paint_control .BrushShapes . RECTANGLE
74+ shape_name = "Rectangle "
7875 elif button_name == "shape_circle" :
79- paint_control .brush_shape = paint_control .BRUSH_SHAPES . circle
80- shape_name = "circle " ;
76+ paint_control .brush_shape = paint_control .BrushShapes . CIRCLE
77+ shape_name = "Circle " ;
8178
8279 # If a opperation button is pressed
8380 elif button_name == "clear_picture" :
@@ -88,33 +85,32 @@ func button_pressed(button_name):
8885 elif button_name == "undo_stroke" :
8986 paint_control .undo_stroke ()
9087
91- # Update the labels (in case the brush mode or brush shape has changed)
88+ # Update the labels (in case the brush mode or brush shape has changed).
9289 if tool_name != null :
9390 label_tools .text = "Selected tool: " + tool_name
9491 if shape_name != null :
9592 label_brush_shape .text = "Brush shape: " + shape_name
9693
9794
9895func brush_color_changed (color ):
99- # Change the brush color to whatever color the color picker is
96+ # Change the brush color to whatever color the color picker is.
10097 paint_control .brush_color = color
10198
10299
103100func background_color_changed (color ):
104- # Change the background color to whatever colorthe background color picker is
101+ # Change the background color to whatever colorthe background color picker is.
105102 get_parent ().get_node ("DrawingAreaBG" ).modulate = color
106103 paint_control .bg_color = color
107- # Because of how the eraser works we also need to redraw the paint control
104+ # Because of how the eraser works we also need to redraw the paint control.
108105 paint_control .update ()
109106
110107
111108func brush_size_changed (value ):
112- # Change the size of the brush, and update the label to reflect the new value
109+ # Change the size of the brush, and update the label to reflect the new value.
113110 paint_control .brush_size = ceil (value )
114111 label_brush_size .text = "Brush size: " + String (ceil (value )) + "px"
115112
116113
117114func save_file_selected (path ):
118- # Call save_picture in paint_control, passing in the path we recieved from SaveFileDialog
115+ # Call save_picture in paint_control, passing in the path we recieved from SaveFileDialog.
119116 paint_control .save_picture (path )
120-
0 commit comments