From 60048f36023653db5a5672f0217c7b1c5a039a4a Mon Sep 17 00:00:00 2001 From: Relintai Date: Fri, 15 Apr 2022 20:05:56 +0200 Subject: [PATCH] Also convert the leftover dialogs. --- modules/paint/dialogs/ChangeGridSizeDialog.gd | 28 ---- modules/paint/dialogs/ConfirmationDialog.gd | 20 --- modules/paint/dialogs/LoadFileDialog.gd | 70 ---------- modules/paint/dialogs/LoadFileDialog.tscn | 22 ---- modules/paint/dialogs/paint_canvas_dialog.cpp | 57 ++++++++ modules/paint/dialogs/paint_canvas_dialog.h | 45 +++++++ .../dialogs/paint_change_grid_size_dialog.cpp | 63 +++++++++ .../dialogs/paint_change_grid_size_dialog.h | 46 +++++++ .../paint/dialogs/paint_load_file_dialog.cpp | 124 ++++++++++++++++++ .../paint/dialogs/paint_load_file_dialog.h | 50 +++++++ 10 files changed, 385 insertions(+), 140 deletions(-) delete mode 100644 modules/paint/dialogs/ChangeGridSizeDialog.gd delete mode 100644 modules/paint/dialogs/ConfirmationDialog.gd delete mode 100644 modules/paint/dialogs/LoadFileDialog.gd delete mode 100644 modules/paint/dialogs/LoadFileDialog.tscn create mode 100644 modules/paint/dialogs/paint_canvas_dialog.cpp create mode 100644 modules/paint/dialogs/paint_canvas_dialog.h create mode 100644 modules/paint/dialogs/paint_change_grid_size_dialog.cpp create mode 100644 modules/paint/dialogs/paint_change_grid_size_dialog.h create mode 100644 modules/paint/dialogs/paint_load_file_dialog.cpp create mode 100644 modules/paint/dialogs/paint_load_file_dialog.h diff --git a/modules/paint/dialogs/ChangeGridSizeDialog.gd b/modules/paint/dialogs/ChangeGridSizeDialog.gd deleted file mode 100644 index 2aea630e9..000000000 --- a/modules/paint/dialogs/ChangeGridSizeDialog.gd +++ /dev/null @@ -1,28 +0,0 @@ -extends AcceptDialog -tool - -func _ready(): - yield(owner, "ready") - find_node("GridValue").value = owner.paint_canvas.grid_size - find_node("BigGridValue").value = owner.paint_canvas.big_grid_size - - -func _on_ChangeGridSizeDialog_confirmed(): - var grid_size = find_node("GridValue").value - var big_grid_size = find_node("BigGridValue").value - owner.paint_canvas.grid_size = grid_size - owner.paint_canvas.big_grid_size = big_grid_size - - -func _on_GridValue_value_changed(value): - var grid_size = value - owner.paint_canvas.grid_size = grid_size - - -func _on_BigGridValue_value_changed(value): - var big_grid_size = value - owner.paint_canvas.big_grid_size = big_grid_size - - -func _on_ChangeGridSizeDialog_visibility_changed(): - pass # Replace with function body. diff --git a/modules/paint/dialogs/ConfirmationDialog.gd b/modules/paint/dialogs/ConfirmationDialog.gd deleted file mode 100644 index 07b15a01d..000000000 --- a/modules/paint/dialogs/ConfirmationDialog.gd +++ /dev/null @@ -1,20 +0,0 @@ -extends ConfirmationDialog -tool - -func _ready(): - yield(owner, "ready") - find_node("Width").value = owner.paint_canvas.canvas_width - find_node("Height").value = owner.paint_canvas.canvas_height - - -func _on_ConfirmationDialog_confirmed(): - var width = find_node("Width").value - var height = find_node("Height").value - print("change canvas size: ", width, " ", height) - owner.paint_canvas.resize(width, height) - - -func _on_ChangeCanvasSize_visibility_changed(): - if visible: - find_node("Width").value = owner.paint_canvas.canvas_width - find_node("Height").value = owner.paint_canvas.canvas_height diff --git a/modules/paint/dialogs/LoadFileDialog.gd b/modules/paint/dialogs/LoadFileDialog.gd deleted file mode 100644 index 858f2d376..000000000 --- a/modules/paint/dialogs/LoadFileDialog.gd +++ /dev/null @@ -1,70 +0,0 @@ -tool -extends FileDialog - - -var canvas: GECanvas - -var file_path = "" - - -func _ready(): - get_line_edit().connect("text_entered", self, "_on_LineEdit_text_entered") - invalidate() - clear_filters() - add_filter("*.png ; PNG Images") - - -func _on_LineEdit_text_entered(_text): - return -# print(_text) - #load_img() -# print("hsadfasd") - - -func _on_LoadFileDialog_file_selected(path): - file_path = path - #print("1ere") - load_img() - - -func _on_LoadFileDialog_confirmed(): - return - #print("ere") - #load_img() - - -func load_img(): - var image = Image.new() - if image.load(file_path) != OK: - print("couldn't load image!") - return - - var image_data = image.get_data() - var layer: GELayer = owner.add_new_layer() - - var width = image.get_width() - var height = image.get_height() - - if owner.paint_canvas.canvas_width < width: - owner.paint_canvas.resize(width, owner.paint_canvas.canvas_height) - - if owner.paint_canvas.canvas_height < height: - owner.paint_canvas.resize(owner.paint_canvas.canvas_width, height) - - for i in range(image_data.size() / 4): - var color = Color(image_data[i*4] / 255.0, image_data[i*4+1] / 255.0, image_data[i*4+2] / 255.0, image_data[i*4+3] / 255.0) - var pos = GEUtils.to_2D(i, image.get_width()) - if pos.x > layer.layer_width: - continue - - layer.set_pixel(pos.x, pos.y, color) - layer.update_texture() - - - -func _on_LoadFileDialog_about_to_show(): - invalidate() - - -func _on_LoadFileDialog_visibility_changed(): - invalidate() diff --git a/modules/paint/dialogs/LoadFileDialog.tscn b/modules/paint/dialogs/LoadFileDialog.tscn deleted file mode 100644 index 0d083c02e..000000000 --- a/modules/paint/dialogs/LoadFileDialog.tscn +++ /dev/null @@ -1,22 +0,0 @@ -[gd_scene load_steps=2 format=2] - -[sub_resource type="GDScript" id=1] -script/source = "extends ConfirmationDialog - -func _ready(): - get_ok().connect(\"pressed\", self, \"hide\") - get_cancel().connect(\"pressed\", self, \"hide\") - - - -" - -[node name="LoadFileDialog" type="FileDialog"] -margin_right = 604.0 -margin_bottom = 367.0 -window_title = "Open a File" -mode = 0 -access = 2 -current_dir = "/Projects/BitBucket/GraphicsEditor" -current_path = "/Projects/BitBucket/GraphicsEditor/" -script = SubResource( 1 ) diff --git a/modules/paint/dialogs/paint_canvas_dialog.cpp b/modules/paint/dialogs/paint_canvas_dialog.cpp new file mode 100644 index 000000000..54951be6a --- /dev/null +++ b/modules/paint/dialogs/paint_canvas_dialog.cpp @@ -0,0 +1,57 @@ +/* +Copyright (c) 2019 Flairieve +Copyright (c) 2020-2022 cobrapitz +Copyright (c) 2022 Péter Magyar + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ + +#include "paint_canvas_dialog.h" + +void PaintCanvasDialog::_ready() { + /* + yield(owner, "ready") + find_node("Width").value = owner.paint_canvas.canvas_width + find_node("Height").value = owner.paint_canvas.canvas_height + */ +} +void PaintCanvasDialog::_on_ConfirmationDialog_confirmed() { + /* + var width = find_node("Width").value + var height = find_node("Height").value + print("change canvas size: ", width, " ", height) + owner.paint_canvas.resize(width, height) + */ +} +void PaintCanvasDialog::_on_ChangeCanvasSize_visibility_changed() { + /* + if visible: + find_node("Width").value = owner.paint_canvas.canvas_width + find_node("Height").value = owner.paint_canvas.canvas_height + */ +} + +PaintCanvasDialog::PaintCanvasDialog() { +} + +PaintCanvasDialog::~PaintCanvasDialog() { +} + +void PaintCanvasDialog::_bind_methods() { +} diff --git a/modules/paint/dialogs/paint_canvas_dialog.h b/modules/paint/dialogs/paint_canvas_dialog.h new file mode 100644 index 000000000..8ffb1009e --- /dev/null +++ b/modules/paint/dialogs/paint_canvas_dialog.h @@ -0,0 +1,45 @@ +#ifndef PAINT_CANVAS_DIALOG_H +#define PAINT_CANVAS_DIALOG_H + +/* +Copyright (c) 2019 Flairieve +Copyright (c) 2020-2022 cobrapitz +Copyright (c) 2022 Péter Magyar + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ + +#include "scene/gui/dialogs.h" + +class PaintCanvasDialog : public ConfirmationDialog { + GDCLASS(PaintCanvasDialog, ConfirmationDialog); + +public: + void _ready(); + void _on_ConfirmationDialog_confirmed(); + void _on_ChangeCanvasSize_visibility_changed(); + + PaintCanvasDialog(); + ~PaintCanvasDialog(); + +protected: + static void _bind_methods(); +}; + +#endif diff --git a/modules/paint/dialogs/paint_change_grid_size_dialog.cpp b/modules/paint/dialogs/paint_change_grid_size_dialog.cpp new file mode 100644 index 000000000..f01a0d88e --- /dev/null +++ b/modules/paint/dialogs/paint_change_grid_size_dialog.cpp @@ -0,0 +1,63 @@ +/* +Copyright (c) 2019 Flairieve +Copyright (c) 2020-2022 cobrapitz +Copyright (c) 2022 Péter Magyar + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ + +#include "paint_change_grid_size_dialog.h" + +void PaintChangeGridSizeDialog::_ready() { + /* + yield(owner, "ready") + find_node("GridValue").value = owner.paint_canvas.grid_size + find_node("BigGridValue").value = owner.paint_canvas.big_grid_size + */ +} + +void PaintChangeGridSizeDialog::_on_ChangeGridSizeDialog_confirmed() { + /* + var grid_size = find_node("GridValue").value + var big_grid_size = find_node("BigGridValue").value + owner.paint_canvas.grid_size = grid_size + owner.paint_canvas.big_grid_size = big_grid_size + */ +} +void PaintChangeGridSizeDialog::_on_GridValue_value_changed(float value) { + /* + var grid_size = value + owner.paint_canvas.grid_size = grid_size + */ +} +void PaintChangeGridSizeDialog::_on_BigGridValue_value_changed(float value) { + /* + var big_grid_size = value + owner.paint_canvas.big_grid_size = big_grid_size + */ +} + +PaintChangeGridSizeDialog::PaintChangeGridSizeDialog() { +} + +PaintChangeGridSizeDialog::~PaintChangeGridSizeDialog() { +} + +void PaintChangeGridSizeDialog::_bind_methods() { +} diff --git a/modules/paint/dialogs/paint_change_grid_size_dialog.h b/modules/paint/dialogs/paint_change_grid_size_dialog.h new file mode 100644 index 000000000..a0920d64f --- /dev/null +++ b/modules/paint/dialogs/paint_change_grid_size_dialog.h @@ -0,0 +1,46 @@ +#ifndef PAINT_CHANGE_GRID_SIZE_DIALOG_H +#define PAINT_CHANGE_GRID_SIZE_DIALOG_H + +/* +Copyright (c) 2019 Flairieve +Copyright (c) 2020-2022 cobrapitz +Copyright (c) 2022 Péter Magyar + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ + +#include "scene/gui/dialogs.h" + +class PaintChangeGridSizeDialog : public AcceptDialog { + GDCLASS(PaintChangeGridSizeDialog, AcceptDialog); + +public: + void _ready(); + void _on_ChangeGridSizeDialog_confirmed(); + void _on_GridValue_value_changed(float value); + void _on_BigGridValue_value_changed(float value); + + PaintChangeGridSizeDialog(); + ~PaintChangeGridSizeDialog(); + +protected: + static void _bind_methods(); +}; + +#endif diff --git a/modules/paint/dialogs/paint_load_file_dialog.cpp b/modules/paint/dialogs/paint_load_file_dialog.cpp new file mode 100644 index 000000000..a05b88173 --- /dev/null +++ b/modules/paint/dialogs/paint_load_file_dialog.cpp @@ -0,0 +1,124 @@ +/* +Copyright (c) 2019 Flairieve +Copyright (c) 2020-2022 cobrapitz +Copyright (c) 2022 Péter Magyar + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ + +#include "paint_load_file_dialog.h" + +void PaintLoadFileDialog::_on_LoadFileDialog_file_selected(String path) { + /* + file_path = path + #print("1ere") + load_img() + */ +} +void PaintLoadFileDialog::_on_LoadFileDialog_confirmed() { + /* + return + #print("ere") + #load_img() + */ +} +void PaintLoadFileDialog::load_img() { + /* + var image = Image.new() + if image.load(file_path) != OK: + print("couldn't load image!") + return + + var image_data = image.get_data() + var layer: GELayer = owner.add_new_layer() + + var width = image.get_width() + var height = image.get_height() + + if owner.paint_canvas.canvas_width < width: + owner.paint_canvas.resize(width, owner.paint_canvas.canvas_height) + + if owner.paint_canvas.canvas_height < height: + owner.paint_canvas.resize(owner.paint_canvas.canvas_width, height) + + for i in range(image_data.size() / 4): + var color = Color(image_data[i*4] / 255.0, image_data[i*4+1] / 255.0, image_data[i*4+2] / 255.0, image_data[i*4+3] / 255.0) + var pos = GEUtils.to_2D(i, image.get_width()) + if pos.x > layer.layer_width: + continue + + layer.set_pixel(pos.x, pos.y, color) + layer.update_texture() + */ +} +void PaintLoadFileDialog::_on_LoadFileDialog_about_to_show() { + /* + invalidate() + */ +} +void PaintLoadFileDialog::_on_LoadFileDialog_visibility_changed() { + /* + invalidate() + */ +} + +PaintLoadFileDialog::PaintLoadFileDialog() { + //var file_path = "" + +/* + get_line_edit().connect("text_entered", self, "_on_LineEdit_text_entered") + invalidate() + clear_filters() + add_filter("*.png ; PNG Images") +*/ + + /* + +[gd_scene load_steps=2 format=2] + +[sub_resource type="GDScript" id=1] +script/source = "extends ConfirmationDialog + +func _ready(): + get_ok().connect(\"pressed\", self, \"hide\") + get_cancel().connect(\"pressed\", self, \"hide\") + + + +" + +[node name="LoadFileDialog" type="FileDialog"] +margin_right = 604.0 +margin_bottom = 367.0 +window_title = "Open a File" +mode = 0 +access = 2 +current_dir = "/Projects/BitBucket/GraphicsEditor" +current_path = "/Projects/BitBucket/GraphicsEditor/" +script = SubResource( 1 ) + + + */ +} + +PaintLoadFileDialog::~PaintLoadFileDialog() { +} + +void PaintLoadFileDialog::_bind_methods() { +} diff --git a/modules/paint/dialogs/paint_load_file_dialog.h b/modules/paint/dialogs/paint_load_file_dialog.h new file mode 100644 index 000000000..1d503429f --- /dev/null +++ b/modules/paint/dialogs/paint_load_file_dialog.h @@ -0,0 +1,50 @@ +#ifndef PAINT_LOAD_FILE_DIALOG_H +#define PAINT_LOAD_FILE_DIALOG_H + +/* +Copyright (c) 2019 Flairieve +Copyright (c) 2020-2022 cobrapitz +Copyright (c) 2022 Péter Magyar + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ + +#include "scene/gui/file_dialog.h" + +class PaintLoadFileDialog : public FileDialog { + GDCLASS(PaintLoadFileDialog, FileDialog); + +public: + void _on_LoadFileDialog_file_selected(String path); + void _on_LoadFileDialog_confirmed(); + void load_img(); + void _on_LoadFileDialog_about_to_show(); + void _on_LoadFileDialog_visibility_changed(); + + PaintLoadFileDialog(); + ~PaintLoadFileDialog(); + +protected: + static void _bind_methods(); + + //var file_path = "" + //var canvas: GECanvas +}; + +#endif