tools_panel.gd 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. extends Panel
  2. @onready var brush_settings = $BrushSettings
  3. @onready var label_brush_size = brush_settings.get_node(^"LabelBrushSize")
  4. @onready var label_brush_shape = brush_settings.get_node(^"LabelBrushShape")
  5. @onready var label_stats = $LabelStats
  6. @onready var label_tools = $LabelTools
  7. @onready var _parent = get_parent()
  8. @onready var save_dialog = _parent.get_node(^"SaveFileDialog")
  9. @onready var paint_control = _parent.get_node(^"PaintControl")
  10. func _ready():
  11. # Assign all of the needed signals for the oppersation buttons.
  12. $ButtonUndo.pressed.connect(self.button_pressed.bind("undo_stroke"))
  13. $ButtonSave.pressed.connect(self.button_pressed.bind("save_picture"))
  14. $ButtonClear.pressed.connect(self.button_pressed.bind("clear_picture"))
  15. # Assign all of the needed signals for the brush buttons.
  16. $ButtonToolPencil.pressed.connect(self.button_pressed.bind("mode_pencil"))
  17. $ButtonToolEraser.pressed.connect(self.button_pressed.bind("mode_eraser"))
  18. $ButtonToolRectangle.pressed.connect(self.button_pressed.bind("mode_rectangle"))
  19. $ButtonToolCircle.pressed.connect(self.button_pressed.bind("mode_circle"))
  20. $BrushSettings/ButtonShapeBox.pressed.connect(self.button_pressed.bind("shape_rectangle"))
  21. $BrushSettings/ButtonShapeCircle.pressed.connect(self.button_pressed.bind("shape_circle"))
  22. # Assign all of the needed signals for the other brush settings (and ColorPickerBackground).
  23. $ColorPickerBrush.color_changed.connect(self.brush_color_changed)
  24. $ColorPickerBackground.color_changed.connect(self.background_color_changed)
  25. $BrushSettings/HScrollBarBrushSize.value_changed.connect(self.brush_size_changed)
  26. # Assign the "file_selected" signal in SaveFileDialog.
  27. save_dialog.file_selected.connect(self.save_file_selected)
  28. # Set physics process so we can update the status label.
  29. set_physics_process(true)
  30. func _physics_process(_delta):
  31. # Update the status label with the newest brush element count.
  32. label_stats.text = "Brush objects: " + str(paint_control.brush_data_list.size())
  33. func button_pressed(button_name):
  34. # If a brush mode button is pressed.
  35. var tool_name = null
  36. var shape_name = null
  37. if button_name == "mode_pencil":
  38. paint_control.brush_mode = paint_control.BrushModes.PENCIL
  39. brush_settings.modulate = Color(1, 1, 1, 1)
  40. tool_name = "Pencil"
  41. elif button_name == "mode_eraser":
  42. paint_control.brush_mode = paint_control.BrushModes.ERASER
  43. brush_settings.modulate = Color(1, 1, 1, 1)
  44. tool_name = "Eraser"
  45. elif button_name == "mode_rectangle":
  46. paint_control.brush_mode = paint_control.BrushModes.RECTANGLE_SHAPE
  47. brush_settings.modulate = Color(1, 1, 1, 0.5)
  48. tool_name = "Rectangle shape"
  49. elif button_name == "mode_circle":
  50. paint_control.brush_mode = paint_control.BrushModes.CIRCLE_SHAPE
  51. brush_settings.modulate = Color(1, 1, 1, 0.5)
  52. tool_name = "Circle shape"
  53. # If a brush shape button is pressed
  54. elif button_name == "shape_rectangle":
  55. paint_control.brush_shape = paint_control.BrushShapes.RECTANGLE
  56. shape_name = "Rectangle"
  57. elif button_name == "shape_circle":
  58. paint_control.brush_shape = paint_control.BrushShapes.CIRCLE
  59. shape_name = "Circle";
  60. # If a opperation button is pressed
  61. elif button_name == "clear_picture":
  62. paint_control.brush_data_list = []
  63. paint_control.queue_redraw()
  64. elif button_name == "save_picture":
  65. save_dialog.popup_centered()
  66. elif button_name == "undo_stroke":
  67. paint_control.undo_stroke()
  68. # Update the labels (in case the brush mode or brush shape has changed).
  69. if tool_name != null:
  70. label_tools.text = "Selected tool: " + tool_name
  71. if shape_name != null:
  72. label_brush_shape.text = "Brush shape: " + shape_name
  73. func brush_color_changed(color):
  74. # Change the brush color to whatever color the color picker is.
  75. paint_control.brush_color = color
  76. func background_color_changed(color):
  77. # Change the background color to whatever colorthe background color picker is.
  78. get_parent().get_node(^"DrawingAreaBG").modulate = color
  79. paint_control.bg_color = color
  80. # Because of how the eraser works we also need to redraw the paint control.
  81. paint_control.queue_redraw()
  82. func brush_size_changed(value):
  83. # Change the size of the brush, and update the label to reflect the new value.
  84. paint_control.brush_size = ceil(value)
  85. label_brush_size.text = "Brush size: " + str(ceil(value)) + "px"
  86. func save_file_selected(path):
  87. # Call save_picture in paint_control, passing in the path we recieved from SaveFileDialog.
  88. paint_control.save_picture(path)