tools_panel.gd 4.4 KB

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