mirror of
https://github.com/Relintai/pandemonium_engine.git
synced 2025-01-11 21:31:10 +01:00
Cleaned up BrushPrefabs. Also started cleaning up actions.
This commit is contained in:
parent
d3c039be7e
commit
a3fc87a576
@ -24,33 +24,53 @@ SOFTWARE.
|
|||||||
|
|
||||||
#include "brighten_action.h"
|
#include "brighten_action.h"
|
||||||
|
|
||||||
|
#include "../paint_canvas_layer.h"
|
||||||
|
#include "../paint_canvas.h"
|
||||||
|
#include "../paint_utilities.h"
|
||||||
|
|
||||||
void BrightenAction::do_action(PaintCanvas *canvas, const Array &data) {
|
void BrightenAction::do_action(PaintCanvas *canvas, const Array &data) {
|
||||||
/*
|
PaintAction::do_action(canvas, data);
|
||||||
.do_action(canvas, data)
|
/*
|
||||||
|
PoolVector2iArray undo_cells = action_data_undo["cells"];
|
||||||
|
PoolColorArray undo_colors = action_data_undo["colors"];
|
||||||
|
PoolVector2iArray redo_cells = action_data_redo["cells"];
|
||||||
|
PoolColorArray redo_colors = action_data_redo["colors"];
|
||||||
|
|
||||||
var pixels = GEUtils.get_pixels_in_line(data[0], data[1])
|
PoolVector2iArray pixels = PaintUtilities::get_pixels_in_line(data[0], data[1]);
|
||||||
for pixel in pixels:
|
|
||||||
if canvas.get_pixel_v(pixel) == null:
|
|
||||||
continue
|
|
||||||
|
|
||||||
if canvas.is_alpha_locked() and canvas.get_pixel_v(pixel) == Color.transparent:
|
for (int i = 0; i < pixels.size(); ++i) {
|
||||||
continue
|
Vector2i pixel = pixels[i];
|
||||||
|
|
||||||
|
Color col = canvas->get_pixel_v(pixel);
|
||||||
|
|
||||||
|
if (canvas->is_alpha_locked() && col.a < 0.00001) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if pixel in action_data.undo.cells:
|
if pixel in action_data.undo.cells:
|
||||||
var brightened_color = canvas.get_pixel_v(pixel).lightened(0.1)
|
var brightened_color = canvas.get_pixel_v(pixel).lightened(0.1);
|
||||||
canvas.set_pixel_v(pixel, brightened_color)
|
canvas.set_pixel_v(pixel, brightened_color);
|
||||||
|
|
||||||
action_data.redo.cells.append(pixel)
|
action_data.redo.cells.append(pixel);
|
||||||
action_data.redo.colors.append(brightened_color)
|
action_data.redo.colors.append(brightened_color);
|
||||||
continue
|
continue;
|
||||||
|
|
||||||
action_data.undo.colors.append(canvas.get_pixel_v(pixel))
|
action_data.undo.colors.append(canvas.get_pixel_v(pixel));
|
||||||
action_data.undo.cells.append(pixel)
|
action_data.undo.cells.append(pixel);
|
||||||
var brightened_color = canvas.get_pixel_v(pixel).lightened(0.1)
|
Color brightened_color = canvas.get_pixel_v(pixel).lightened(0.1);
|
||||||
canvas.set_pixel_v(pixel, brightened_color)
|
canvas.set_pixel_v(pixel, brightened_color);
|
||||||
|
|
||||||
|
action_data.redo.cells.append(pixel);
|
||||||
|
action_data.redo.colors.append(brightened_color);
|
||||||
|
}
|
||||||
|
|
||||||
|
PoolVector2iArray undo_cells = action_data_undo["cells"] = undo_cells;
|
||||||
|
PoolColorArray undo_colors = action_data_undo["colors"] = undo_colors;
|
||||||
|
PoolVector2iArray redo_cells = action_data_redo["cells"] = redo_cells;
|
||||||
|
PoolColorArray redo_colors = action_data_redo["colors"] = redo_colors;
|
||||||
|
|
||||||
action_data.redo.cells.append(pixel)
|
|
||||||
action_data.redo.colors.append(brightened_color)
|
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
void BrightenAction::commit_action(PaintCanvas *canvas) {
|
void BrightenAction::commit_action(PaintCanvas *canvas) {
|
||||||
@ -61,20 +81,20 @@ void BrightenAction::commit_action(PaintCanvas *canvas) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void BrightenAction::undo_action(PaintCanvas *canvas) {
|
void BrightenAction::undo_action(PaintCanvas *canvas) {
|
||||||
/*
|
PoolVector2iArray cells = action_data_undo["cells"];
|
||||||
var cells = action_data.undo.cells
|
PoolColorArray colors = action_data_undo["colors"];
|
||||||
var colors = action_data.undo.colors
|
|
||||||
for idx in range(cells.size()):
|
for (int idx = 0; idx < cells.size(); ++idx) {
|
||||||
canvas._set_pixel_v(action_data.layer, cells[idx], colors[idx])
|
canvas->_set_pixel_v(action_data["layer"], cells[idx], colors[idx]);
|
||||||
*/
|
}
|
||||||
}
|
}
|
||||||
void BrightenAction::redo_action(PaintCanvas *canvas) {
|
void BrightenAction::redo_action(PaintCanvas *canvas) {
|
||||||
/*
|
PoolVector2iArray cells = action_data_redo["cells"];
|
||||||
var cells = action_data.redo.cells
|
PoolColorArray colors = action_data_redo["colors"];
|
||||||
var colors = action_data.redo.colors
|
|
||||||
for idx in range(cells.size()):
|
for (int idx = 0; idx < cells.size(); ++idx) {
|
||||||
canvas._set_pixel_v(action_data.layer, cells[idx], colors[idx])
|
canvas->_set_pixel_v(action_data["layer"], cells[idx], colors[idx]);
|
||||||
*/
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BrightenAction::BrightenAction() {
|
BrightenAction::BrightenAction() {
|
||||||
|
@ -24,24 +24,27 @@ SOFTWARE.
|
|||||||
|
|
||||||
#include "paint_action.h"
|
#include "paint_action.h"
|
||||||
|
|
||||||
|
#include "../paint_canvas.h"
|
||||||
|
#include "../paint_canvas_layer.h"
|
||||||
|
|
||||||
void PaintAction::do_action(PaintCanvas *canvas, const Array &data) {
|
void PaintAction::do_action(PaintCanvas *canvas, const Array &data) {
|
||||||
if (!action_data_redo.has("cells")) {
|
if (!action_data_redo.has("cells")) {
|
||||||
action_data_redo["cells"] = Array();
|
action_data_redo["cells"] = PoolVector2iArray();
|
||||||
action_data_redo["colors"] = Array();
|
action_data_redo["colors"] = PoolColorArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!action_data_undo.has("cells")) {
|
if (!action_data_undo.has("cells")) {
|
||||||
action_data_undo["cells"] = Array();
|
action_data_undo["cells"] = PoolVector2iArray();
|
||||||
action_data_undo["colors"] = Array();
|
action_data_undo["colors"] = PoolColorArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!action_data_preview.has("cells")) {
|
if (!action_data_preview.has("cells")) {
|
||||||
action_data_preview["cells"] = Array();
|
action_data_preview["cells"] = PoolVector2iArray();
|
||||||
action_data_preview["colors"] = Array();
|
action_data_preview["colors"] = PoolColorArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!action_data.has("layer")) {
|
if (!action_data.has("layer")) {
|
||||||
//action_data["layer"] = canvas->get_active_layer();
|
action_data["layer"] = canvas->get_active_layer();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void PaintAction::commit_action(PaintCanvas *canvas) {
|
void PaintAction::commit_action(PaintCanvas *canvas) {
|
||||||
|
@ -44,85 +44,107 @@ const list = [
|
|||||||
]
|
]
|
||||||
*/
|
*/
|
||||||
|
|
||||||
PoolVector2iArray BrushPrefabs::get_brush(const BrushPrefabs::Type type, const int size) {
|
PoolVector2iArray BrushPrefabs::get_brush(const BrushPrefabs::Type type, int size) {
|
||||||
/*
|
PoolVector2iArray pixels;
|
||||||
var pixels = []
|
|
||||||
if size < 1:
|
|
||||||
size = 1
|
|
||||||
|
|
||||||
match type:
|
if (size < 1) {
|
||||||
Type.CIRCLE:
|
size = 1;
|
||||||
size += 1
|
}
|
||||||
var center = Vector2.ZERO
|
|
||||||
var last = center
|
|
||||||
var radius = size / 2.0
|
|
||||||
for x in range(size):
|
|
||||||
for y in range(size):
|
|
||||||
if Vector2(x - radius, y - radius).length() < size / 3.0:
|
|
||||||
pixels.append(Vector2(x, y))
|
|
||||||
|
|
||||||
var avg = Vector2(size / 2, size / 2)
|
switch (type) {
|
||||||
avg = Vector2(floor(avg.x), floor(avg.y))
|
case CIRCLE: {
|
||||||
|
size += 1;
|
||||||
|
Vector2 center;
|
||||||
|
int radius = size / 2.0;
|
||||||
|
|
||||||
for i in range(pixels.size()):
|
for (int x = 0; x < size; ++x) {
|
||||||
pixels[i] -= avg
|
for (int y = 0; y < size; ++y) {
|
||||||
|
if (Vector2(x - radius, y - radius).length() < size / 3.0) {
|
||||||
|
pixels.append(Vector2(x, y));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Type.RECT:
|
int av = static_cast<int>(size / 2);
|
||||||
var center = Vector2.ZERO
|
Vector2i avg = Vector2i(av, av);
|
||||||
var last = center
|
|
||||||
for x in range(size):
|
|
||||||
for y in range(size):
|
|
||||||
pixels.append(Vector2(x, y))
|
|
||||||
|
|
||||||
var avg = Vector2.ZERO
|
for (int i = 0; i < pixels.size(); ++i) {
|
||||||
for cell in pixels:
|
Vector2i p = pixels[i];
|
||||||
avg += cell
|
p -= avg;
|
||||||
|
pixels.set(i, p);
|
||||||
|
}
|
||||||
|
} break;
|
||||||
|
case RECT: {
|
||||||
|
for (int x = 0; x < size; ++x) {
|
||||||
|
for (int y = 0; y < size; ++y) {
|
||||||
|
pixels.append(Vector2(x, y));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
avg.x /= pixels.size()
|
Vector2i avg;
|
||||||
avg.y /= pixels.size()
|
for (int i = 0; i < pixels.size(); ++i) {
|
||||||
|
Vector2i p = pixels[i];
|
||||||
|
avg += p;
|
||||||
|
}
|
||||||
|
|
||||||
avg = Vector2(floor(avg.x), floor(avg.y))
|
avg.x /= pixels.size();
|
||||||
|
avg.y /= pixels.size();
|
||||||
|
|
||||||
for i in range(pixels.size()):
|
for (int i = 0; i < pixels.size(); ++i) {
|
||||||
pixels[i] -= avg
|
Vector2i p = pixels[i];
|
||||||
|
p -= avg;
|
||||||
|
pixels.set(i, p);
|
||||||
|
}
|
||||||
|
} break;
|
||||||
|
case V_LINE: {
|
||||||
|
Vector2i center;
|
||||||
|
Vector2i last = center;
|
||||||
|
pixels.append(Vector2i());
|
||||||
|
|
||||||
Type.V_LINE:
|
for (int i = 0; i < size - 1; ++i) {
|
||||||
var center = Vector2.ZERO
|
int sig = SGN(last.y);
|
||||||
var last = center
|
|
||||||
pixels.append(Vector2.ZERO)
|
|
||||||
|
|
||||||
for i in range(size - 1):
|
if (sig == 0) {
|
||||||
var sig = sign(last.y)
|
sig = 1;
|
||||||
if sig == 0:
|
}
|
||||||
sig = 1
|
|
||||||
|
|
||||||
if last.y < 0:
|
if (last.y < 0) {
|
||||||
center.y = abs(last.y) * -sig
|
center.y = abs(last.y) * -sig;
|
||||||
else:
|
} else {
|
||||||
center.y = abs(last.y+1) * -sig
|
center.y = abs(last.y + 1) * -sig;
|
||||||
last = center
|
}
|
||||||
pixels.append(center)
|
|
||||||
Type.H_LINE:
|
|
||||||
var center = Vector2.ZERO
|
|
||||||
var last = center
|
|
||||||
pixels.append(Vector2.ZERO)
|
|
||||||
|
|
||||||
for i in range(size - 1):
|
last = center;
|
||||||
var sig = sign(last.x)
|
pixels.append(center);
|
||||||
if sig == 0:
|
}
|
||||||
sig = 1
|
|
||||||
|
|
||||||
if last.x < 0:
|
} break;
|
||||||
center.x = abs(last.x) * -sig
|
case H_LINE: {
|
||||||
else:
|
Vector2i center;
|
||||||
center.x = abs(last.x+1) * -sig
|
Vector2i last = center;
|
||||||
last = center
|
pixels.append(Vector2i());
|
||||||
pixels.append(center)
|
|
||||||
|
|
||||||
return pixels
|
for (int i = 0; i < size - 1; ++i) {
|
||||||
*/
|
int sig = SGN(last.x);
|
||||||
|
|
||||||
return PoolVector2iArray();
|
if (sig == 0) {
|
||||||
|
sig = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (last.x < 0) {
|
||||||
|
center.x = abs(last.x) * -sig;
|
||||||
|
} else {
|
||||||
|
center.x = abs(last.x + 1) * -sig;
|
||||||
|
}
|
||||||
|
|
||||||
|
last = center;
|
||||||
|
pixels.append(center);
|
||||||
|
}
|
||||||
|
|
||||||
|
} break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return pixels;
|
||||||
}
|
}
|
||||||
|
|
||||||
BrushPrefabs::BrushPrefabs() {
|
BrushPrefabs::BrushPrefabs() {
|
||||||
|
@ -39,7 +39,7 @@ public:
|
|||||||
CIRCLE,
|
CIRCLE,
|
||||||
};
|
};
|
||||||
|
|
||||||
static PoolVector2iArray get_brush(const Type type, const int size);
|
static PoolVector2iArray get_brush(const Type type, int size);
|
||||||
|
|
||||||
BrushPrefabs();
|
BrushPrefabs();
|
||||||
~BrushPrefabs();
|
~BrushPrefabs();
|
||||||
|
Loading…
Reference in New Issue
Block a user