mirror of
https://github.com/Relintai/pandemonium_engine.git
synced 2024-12-23 04:16:50 +01:00
Also register PaintCanvasBackground to the ClassDB, and fix crash on exit with it.
This commit is contained in:
parent
74a7615168
commit
b574d44dd7
@ -65,7 +65,7 @@ void register_paint_types() {
|
||||
ClassDB::register_class<RainbowAction>();
|
||||
ClassDB::register_class<RectAction>();
|
||||
|
||||
//ClassDB::register_class<PaintCanvasBackground>();
|
||||
ClassDB::register_class<PaintCanvasBackground>();
|
||||
ClassDB::register_class<PaintCanvasOutline>();
|
||||
ClassDB::register_class<PaintColorGrid>();
|
||||
ClassDB::register_class<PaintSelectionBox>();
|
||||
|
@ -24,9 +24,9 @@ SOFTWARE.
|
||||
|
||||
#include "paint_canvas_background.h"
|
||||
|
||||
#include "core/io/image.h"
|
||||
#include "scene/resources/material.h"
|
||||
#include "scene/resources/shader.h"
|
||||
#include "core/io/image.h"
|
||||
#include "scene/resources/texture.h"
|
||||
|
||||
#include "../shaders/shaders.h"
|
||||
@ -39,7 +39,9 @@ float PaintCanvasBackground::get_pixel_size() const {
|
||||
void PaintCanvasBackground::set_pixel_size(const float val) {
|
||||
_pixel_size = val;
|
||||
|
||||
_material->set_shader_param("pixel_size", _pixel_size);
|
||||
if (_material.is_valid()) {
|
||||
_material->set_shader_param("pixel_size", _pixel_size);
|
||||
}
|
||||
}
|
||||
|
||||
PaintCanvasBackground::PaintCanvasBackground() {
|
||||
@ -47,22 +49,31 @@ PaintCanvasBackground::PaintCanvasBackground() {
|
||||
|
||||
set_expand(true);
|
||||
set_stretch_mode(TextureRect::STRETCH_TILE);
|
||||
|
||||
set_texture(PaintIcons::make_icon_grid_png());
|
||||
|
||||
_shader.instance();
|
||||
_shader->set_code(background_shader_shader_code);
|
||||
|
||||
_material.instance();
|
||||
_material->set_shader(_shader);
|
||||
_material->set_shader_param("pixel_size", _pixel_size);
|
||||
|
||||
set_material(_material);
|
||||
}
|
||||
|
||||
PaintCanvasBackground::~PaintCanvasBackground() {
|
||||
_material.unref();
|
||||
_shader.unref();
|
||||
}
|
||||
|
||||
void PaintCanvasBackground::_notification(int p_what) {
|
||||
switch (p_what) {
|
||||
case NOTIFICATION_ENTER_TREE:
|
||||
_shader.instance();
|
||||
_shader->set_code(background_shader_shader_code);
|
||||
|
||||
_material.instance();
|
||||
_material->set_shader(_shader);
|
||||
_material->set_shader_param("pixel_size", _pixel_size);
|
||||
|
||||
set_material(_material);
|
||||
|
||||
set_texture(PaintIcons::make_icon_grid_png());
|
||||
break;
|
||||
case NOTIFICATION_EXIT_TREE:
|
||||
set_material(Ref<Material>());
|
||||
_shader.unref();
|
||||
_material.unref();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void PaintCanvasBackground::_bind_methods() {
|
||||
|
@ -44,6 +44,8 @@ public:
|
||||
~PaintCanvasBackground();
|
||||
|
||||
protected:
|
||||
void _notification(int p_what);
|
||||
|
||||
static void _bind_methods();
|
||||
|
||||
float _pixel_size;
|
||||
|
Loading…
Reference in New Issue
Block a user