mirror of
https://github.com/Relintai/pandemonium_engine.git
synced 2025-01-11 05:19:50 +01:00
Now PaintCanvasBackground and PaintVisualGrid will automatically size themselves to a parent PaintNode if they can.
This commit is contained in:
parent
17842720a5
commit
9f8f6cb3b4
@ -24,6 +24,8 @@ SOFTWARE.
|
|||||||
|
|
||||||
#include "paint_canvas_background.h"
|
#include "paint_canvas_background.h"
|
||||||
|
|
||||||
|
#include "../nodes/paint_node.h"
|
||||||
|
|
||||||
int PaintCanvasBackground::get_grid_size() const {
|
int PaintCanvasBackground::get_grid_size() const {
|
||||||
return _grid_size;
|
return _grid_size;
|
||||||
}
|
}
|
||||||
@ -51,6 +53,22 @@ void PaintCanvasBackground::set_grid_white(const Color &val) {
|
|||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PaintNode *PaintCanvasBackground::get_paint_node() {
|
||||||
|
Node *p = this;
|
||||||
|
|
||||||
|
while (p) {
|
||||||
|
PaintNode *pn = Object::cast_to<PaintNode>(p);
|
||||||
|
|
||||||
|
if (pn) {
|
||||||
|
return pn;
|
||||||
|
}
|
||||||
|
|
||||||
|
p = p->get_parent();
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
PaintCanvasBackground::PaintCanvasBackground() {
|
PaintCanvasBackground::PaintCanvasBackground() {
|
||||||
_grid_size = 8;
|
_grid_size = 8;
|
||||||
|
|
||||||
@ -63,6 +81,13 @@ PaintCanvasBackground::~PaintCanvasBackground() {
|
|||||||
|
|
||||||
void PaintCanvasBackground::_notification(int p_what) {
|
void PaintCanvasBackground::_notification(int p_what) {
|
||||||
switch (p_what) {
|
switch (p_what) {
|
||||||
|
case NOTIFICATION_ENTER_TREE: {
|
||||||
|
PaintNode *pn = get_paint_node();
|
||||||
|
|
||||||
|
if (pn) {
|
||||||
|
set_size(pn->get_size());
|
||||||
|
}
|
||||||
|
} break;
|
||||||
case NOTIFICATION_DRAW: {
|
case NOTIFICATION_DRAW: {
|
||||||
ERR_FAIL_COND(_grid_size <= 0);
|
ERR_FAIL_COND(_grid_size <= 0);
|
||||||
|
|
||||||
|
@ -32,6 +32,7 @@ SOFTWARE.
|
|||||||
class ShaderMaterial;
|
class ShaderMaterial;
|
||||||
class Shader;
|
class Shader;
|
||||||
class Image;
|
class Image;
|
||||||
|
class PaintNode;
|
||||||
|
|
||||||
class PaintCanvasBackground : public TextureRect {
|
class PaintCanvasBackground : public TextureRect {
|
||||||
GDCLASS(PaintCanvasBackground, TextureRect);
|
GDCLASS(PaintCanvasBackground, TextureRect);
|
||||||
@ -46,6 +47,8 @@ public:
|
|||||||
Color get_grid_white() const;
|
Color get_grid_white() const;
|
||||||
void set_grid_white(const Color &val);
|
void set_grid_white(const Color &val);
|
||||||
|
|
||||||
|
PaintNode *get_paint_node();
|
||||||
|
|
||||||
PaintCanvasBackground();
|
PaintCanvasBackground();
|
||||||
~PaintCanvasBackground();
|
~PaintCanvasBackground();
|
||||||
|
|
||||||
|
@ -24,6 +24,8 @@ SOFTWARE.
|
|||||||
|
|
||||||
#include "paint_visual_grid.h"
|
#include "paint_visual_grid.h"
|
||||||
|
|
||||||
|
#include "../nodes/paint_node.h"
|
||||||
|
|
||||||
int PaintVisualGrid::get_grid_size() {
|
int PaintVisualGrid::get_grid_size() {
|
||||||
return _grid_size;
|
return _grid_size;
|
||||||
}
|
}
|
||||||
@ -40,11 +42,31 @@ void PaintVisualGrid::set_grid_color(const Color &val) {
|
|||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
void PaintVisualGrid::_draw() {
|
PaintNode *PaintVisualGrid::get_paint_node() {
|
||||||
|
Node *p = this;
|
||||||
|
|
||||||
|
while (p) {
|
||||||
|
PaintNode *pn = Object::cast_to<PaintNode>(p);
|
||||||
|
|
||||||
|
if (pn) {
|
||||||
|
return pn;
|
||||||
|
}
|
||||||
|
|
||||||
|
p = p->get_parent();
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PaintVisualGrid::_notification(int p_what) {
|
void PaintVisualGrid::_notification(int p_what) {
|
||||||
switch (p_what) {
|
switch (p_what) {
|
||||||
|
case NOTIFICATION_ENTER_TREE: {
|
||||||
|
PaintNode *pn = get_paint_node();
|
||||||
|
|
||||||
|
if (pn) {
|
||||||
|
set_size(pn->get_size());
|
||||||
|
}
|
||||||
|
} break;
|
||||||
case NOTIFICATION_DRAW: {
|
case NOTIFICATION_DRAW: {
|
||||||
ERR_FAIL_COND(_grid_size <= 0);
|
ERR_FAIL_COND(_grid_size <= 0);
|
||||||
|
|
||||||
|
@ -27,6 +27,8 @@ SOFTWARE.
|
|||||||
|
|
||||||
#include "scene/gui/control.h"
|
#include "scene/gui/control.h"
|
||||||
|
|
||||||
|
class PaintNode;
|
||||||
|
|
||||||
class PaintVisualGrid : public Control {
|
class PaintVisualGrid : public Control {
|
||||||
GDCLASS(PaintVisualGrid, Control);
|
GDCLASS(PaintVisualGrid, Control);
|
||||||
|
|
||||||
@ -37,7 +39,7 @@ public:
|
|||||||
Color get_grid_color();
|
Color get_grid_color();
|
||||||
void set_grid_color(const Color &val);
|
void set_grid_color(const Color &val);
|
||||||
|
|
||||||
void _draw();
|
PaintNode *get_paint_node();
|
||||||
|
|
||||||
PaintVisualGrid();
|
PaintVisualGrid();
|
||||||
~PaintVisualGrid();
|
~PaintVisualGrid();
|
||||||
|
Loading…
Reference in New Issue
Block a user