mirror of
https://github.com/Relintai/pandemonium_engine.git
synced 2025-02-03 06:45:53 +01:00
Added a PaintIcons header to the paint module to reduce code duplication, and to fix compile on the platforms where it failed.
This commit is contained in:
parent
a7afeb93e3
commit
74a7615168
@ -33,31 +33,7 @@ SOFTWARE.
|
||||
|
||||
#include "paint_canvas_layer.h"
|
||||
|
||||
#include "../paint_icons/paint_icons.h"
|
||||
|
||||
static float scale = 1;
|
||||
|
||||
template <class T>
|
||||
static Ref<Texture> make_icon(T p_src) {
|
||||
Ref<ImageTexture> texture(memnew(ImageTexture));
|
||||
Ref<Image> img = memnew(Image(p_src));
|
||||
if (scale > 1) {
|
||||
Size2 orig_size = Size2(img->get_width(), img->get_height());
|
||||
|
||||
img->convert(Image::FORMAT_RGBA8);
|
||||
img->expand_x2_hq2x();
|
||||
if (scale != 2.0) {
|
||||
img->resize(orig_size.x * scale, orig_size.y * scale);
|
||||
}
|
||||
} else if (scale < 1) {
|
||||
Size2 orig_size = Size2(img->get_width(), img->get_height());
|
||||
img->convert(Image::FORMAT_RGBA8);
|
||||
img->resize(orig_size.x * scale, orig_size.y * scale);
|
||||
}
|
||||
texture->create_from_image(img, ImageTexture::FLAG_FILTER);
|
||||
|
||||
return texture;
|
||||
}
|
||||
#include "../paint_icons/icons.h"
|
||||
|
||||
void PaintCanvasOld::_process(float delta) {
|
||||
if (!is_visible_in_tree()) {
|
||||
|
@ -34,31 +34,7 @@ SOFTWARE.
|
||||
#include "scene/gui/margin_container.h"
|
||||
#include "scene/gui/texture_button.h"
|
||||
|
||||
#include "../paint_icons/paint_icons.h"
|
||||
|
||||
static float scale = 1;
|
||||
|
||||
template <class T>
|
||||
static Ref<Texture> make_icon(T p_src) {
|
||||
Ref<ImageTexture> texture(memnew(ImageTexture));
|
||||
Ref<Image> img = memnew(Image(p_src));
|
||||
if (scale > 1) {
|
||||
Size2 orig_size = Size2(img->get_width(), img->get_height());
|
||||
|
||||
img->convert(Image::FORMAT_RGBA8);
|
||||
img->expand_x2_hq2x();
|
||||
if (scale != 2.0) {
|
||||
img->resize(orig_size.x * scale, orig_size.y * scale);
|
||||
}
|
||||
} else if (scale < 1) {
|
||||
Size2 orig_size = Size2(img->get_width(), img->get_height());
|
||||
img->convert(Image::FORMAT_RGBA8);
|
||||
img->resize(orig_size.x * scale, orig_size.y * scale);
|
||||
}
|
||||
texture->create_from_image(img, ImageTexture::FLAG_FILTER);
|
||||
|
||||
return texture;
|
||||
}
|
||||
#include "../paint_icons/icons.h"
|
||||
|
||||
PaintLayerButton::PaintLayerButton() {
|
||||
set_custom_minimum_size(Size2(0, 32));
|
||||
@ -112,8 +88,8 @@ PaintLayerButton::PaintLayerButton() {
|
||||
// Visible Button
|
||||
visible_button = memnew(CheckButton);
|
||||
visible_button->set_pressed(true);
|
||||
visible_button->set("custom_icons/off", make_icon(minidotta_invis_png));
|
||||
visible_button->set("custom_icons/on", make_icon(minidotta_png));
|
||||
visible_button->set("custom_icons/off", PaintIcons::make_icon_minidotta_invis_png());
|
||||
visible_button->set("custom_icons/on", PaintIcons::make_icon_minidotta_png());
|
||||
style_box.instance();
|
||||
style_box->set("bg_color", Color(0.6, 0.6, 0.6));
|
||||
layer_button->set("custom_styles/normal", style_box);
|
||||
@ -122,8 +98,8 @@ PaintLayerButton::PaintLayerButton() {
|
||||
// Lock Button
|
||||
lock_button = memnew(CheckButton);
|
||||
lock_button->set_pressed(false);
|
||||
lock_button->set("custom_icons/off", make_icon(unlock_layer_png));
|
||||
lock_button->set("custom_icons/on", make_icon(lock_layer_1_png));
|
||||
lock_button->set("custom_icons/off", PaintIcons::make_icon_unlock_layer_png());
|
||||
lock_button->set("custom_icons/on", PaintIcons::make_icon_lock_layer_1_png());
|
||||
style_box.instance();
|
||||
style_box->set("bg_color", Color(0.6, 0.6, 0.6));
|
||||
layer_button->set("custom_styles/normal", style_box);
|
||||
@ -138,8 +114,8 @@ PaintLayerButton::PaintLayerButton() {
|
||||
up_button->set_stretch_mode(TextureButton::STRETCH_KEEP_CENTERED);
|
||||
up_button->set_h_size_flags(SIZE_EXPAND_FILL);
|
||||
up_button->set_v_size_flags(SIZE_EXPAND_FILL);
|
||||
up_button->set_normal_texture(make_icon(arrow_up_png));
|
||||
up_button->set_pressed_texture(make_icon(minidotta_png));
|
||||
up_button->set_normal_texture(PaintIcons::make_icon_arrow_up_png());
|
||||
up_button->set_pressed_texture(PaintIcons::make_icon_minidotta_png());
|
||||
up_button->set_custom_minimum_size(Vector2(15, 15));
|
||||
right_main_container->add_child(up_button);
|
||||
|
||||
@ -148,8 +124,8 @@ PaintLayerButton::PaintLayerButton() {
|
||||
down_button->set_stretch_mode(TextureButton::STRETCH_KEEP_CENTERED);
|
||||
down_button->set_h_size_flags(SIZE_EXPAND_FILL);
|
||||
down_button->set_v_size_flags(SIZE_EXPAND_FILL);
|
||||
down_button->set_normal_texture(make_icon(arrow_down_png));
|
||||
down_button->set_pressed_texture(make_icon(minidotta_png));
|
||||
down_button->set_normal_texture(PaintIcons::make_icon_arrow_down_png());
|
||||
down_button->set_pressed_texture(PaintIcons::make_icon_minidotta_png());
|
||||
down_button->set_custom_minimum_size(Vector2(15, 15));
|
||||
right_main_container->add_child(down_button);
|
||||
}
|
||||
|
@ -67,31 +67,7 @@ SOFTWARE.
|
||||
#include "dialogs/paint_save_file_dialog.h"
|
||||
#include "paint_settings.h"
|
||||
|
||||
#include "../paint_icons/paint_icons.h"
|
||||
|
||||
static float scale = 1;
|
||||
|
||||
template <class T>
|
||||
static Ref<Texture> make_icon(T p_src) {
|
||||
Ref<ImageTexture> texture(memnew(ImageTexture));
|
||||
Ref<Image> img = memnew(Image(p_src));
|
||||
if (scale > 1) {
|
||||
Size2 orig_size = Size2(img->get_width(), img->get_height());
|
||||
|
||||
img->convert(Image::FORMAT_RGBA8);
|
||||
img->expand_x2_hq2x();
|
||||
if (scale != 2.0) {
|
||||
img->resize(orig_size.x * scale, orig_size.y * scale);
|
||||
}
|
||||
} else if (scale < 1) {
|
||||
Size2 orig_size = Size2(img->get_width(), img->get_height());
|
||||
img->convert(Image::FORMAT_RGBA8);
|
||||
img->resize(orig_size.x * scale, orig_size.y * scale);
|
||||
}
|
||||
texture->create_from_image(img, ImageTexture::FLAG_FILTER);
|
||||
|
||||
return texture;
|
||||
}
|
||||
#include "../paint_icons/icons.h"
|
||||
|
||||
Control *PaintWindow::get_navbar() {
|
||||
return navbar;
|
||||
@ -1366,29 +1342,29 @@ PaintWindow::PaintWindow() {
|
||||
left_main_vbox_container->add_child(brush_container);
|
||||
|
||||
TextureButton *brush_rect_button = memnew(TextureButton);
|
||||
brush_rect_button->set_normal_texture(make_icon(brush_rect_png));
|
||||
brush_rect_button->set_hover_texture(make_icon(brush_rect_hovered_png));
|
||||
brush_rect_button->set_normal_texture(PaintIcons::make_icon_brush_rect_png());
|
||||
brush_rect_button->set_hover_texture(PaintIcons::make_icon_brush_rect_hovered_png());
|
||||
brush_rect_button->set_custom_minimum_size(Size2(25, 25));
|
||||
brush_rect_button->connect("pressed", this, "_on_BrushRect_pressed");
|
||||
brush_container->add_child(brush_rect_button);
|
||||
|
||||
TextureButton *brush_circle_button = memnew(TextureButton);
|
||||
brush_circle_button->set_normal_texture(make_icon(brush_circle_png));
|
||||
brush_circle_button->set_hover_texture(make_icon(brush_circle_hovered_png));
|
||||
brush_circle_button->set_normal_texture(PaintIcons::make_icon_brush_circle_png());
|
||||
brush_circle_button->set_hover_texture(PaintIcons::make_icon_brush_circle_hovered_png());
|
||||
brush_circle_button->set_custom_minimum_size(Size2(25, 25));
|
||||
brush_circle_button->connect("pressed", this, "_on_BrushCircle_pressed");
|
||||
brush_container->add_child(brush_circle_button);
|
||||
|
||||
TextureButton *brush_v_line_button = memnew(TextureButton);
|
||||
brush_v_line_button->set_normal_texture(make_icon(brush_v_line_png));
|
||||
brush_v_line_button->set_hover_texture(make_icon(brush_v_line_hovered_png));
|
||||
brush_v_line_button->set_normal_texture(PaintIcons::make_icon_brush_v_line_png());
|
||||
brush_v_line_button->set_hover_texture(PaintIcons::make_icon_brush_v_line_hovered_png());
|
||||
brush_v_line_button->set_custom_minimum_size(Size2(25, 25));
|
||||
brush_v_line_button->connect("pressed", this, "_on_BrushVLine_pressed");
|
||||
brush_container->add_child(brush_v_line_button);
|
||||
|
||||
TextureButton *brush_h_line_button = memnew(TextureButton);
|
||||
brush_h_line_button->set_normal_texture(make_icon(brush_h_line_png));
|
||||
brush_h_line_button->set_hover_texture(make_icon(brush_h_line_hovered_png));
|
||||
brush_h_line_button->set_normal_texture(PaintIcons::make_icon_brush_h_line_png());
|
||||
brush_h_line_button->set_hover_texture(PaintIcons::make_icon_brush_h_line_hovered_png());
|
||||
brush_h_line_button->set_custom_minimum_size(Size2(25, 25));
|
||||
brush_h_line_button->connect("pressed", this, "_on_BrushHLine_pressed");
|
||||
brush_container->add_child(brush_h_line_button);
|
||||
|
100
modules/paint/paint_icons/icons.h
Normal file
100
modules/paint/paint_icons/icons.h
Normal file
@ -0,0 +1,100 @@
|
||||
#ifndef PAINT_ICONS_H
|
||||
#define PAINT_ICONS_H
|
||||
|
||||
#include "paint_icons.h"
|
||||
|
||||
#include "core/io/image.h"
|
||||
#include "scene/resources/texture.h"
|
||||
|
||||
class PaintIcons {
|
||||
public:
|
||||
template <class T>
|
||||
static Ref<Texture> make_icon(T p_src) {
|
||||
float scale = 1;
|
||||
|
||||
Ref<ImageTexture> texture(memnew(ImageTexture));
|
||||
Ref<Image> img = memnew(Image(p_src));
|
||||
if (scale > 1) {
|
||||
Size2 orig_size = Size2(img->get_width(), img->get_height());
|
||||
|
||||
img->convert(Image::FORMAT_RGBA8);
|
||||
img->expand_x2_hq2x();
|
||||
if (scale != 2.0) {
|
||||
img->resize(orig_size.x * scale, orig_size.y * scale);
|
||||
}
|
||||
} else if (scale < 1) {
|
||||
Size2 orig_size = Size2(img->get_width(), img->get_height());
|
||||
img->convert(Image::FORMAT_RGBA8);
|
||||
img->resize(orig_size.x * scale, orig_size.y * scale);
|
||||
}
|
||||
texture->create_from_image(img, ImageTexture::FLAG_FILTER);
|
||||
|
||||
return texture;
|
||||
}
|
||||
|
||||
static Ref<Texture> make_icon_arrow_down_png() {
|
||||
return make_icon(arrow_down_png);
|
||||
}
|
||||
|
||||
static Ref<Texture> make_icon_arrow_up_png() {
|
||||
return make_icon(arrow_up_png);
|
||||
}
|
||||
|
||||
static Ref<Texture> make_icon_brush_circle_png() {
|
||||
return make_icon(brush_circle_png);
|
||||
}
|
||||
|
||||
static Ref<Texture> make_icon_brush_circle_hovered_png() {
|
||||
return make_icon(brush_circle_hovered_png);
|
||||
}
|
||||
|
||||
static Ref<Texture> make_icon_brush_h_line_png() {
|
||||
return make_icon(brush_h_line_png);
|
||||
}
|
||||
|
||||
static Ref<Texture> make_icon_brush_h_line_hovered_png() {
|
||||
return make_icon(brush_h_line_hovered_png);
|
||||
}
|
||||
|
||||
static Ref<Texture> make_icon_brush_rect_png() {
|
||||
return make_icon(brush_rect_png);
|
||||
}
|
||||
|
||||
static Ref<Texture> make_icon_brush_rect_hovered_png() {
|
||||
return make_icon(brush_rect_hovered_png);
|
||||
}
|
||||
|
||||
static Ref<Texture> make_icon_brush_v_line_png() {
|
||||
return make_icon(brush_v_line_png);
|
||||
}
|
||||
|
||||
static Ref<Texture> make_icon_brush_v_line_hovered_png() {
|
||||
return make_icon(brush_v_line_hovered_png);
|
||||
}
|
||||
|
||||
static Ref<Texture> make_icon_grid_png() {
|
||||
return make_icon(grid_png);
|
||||
}
|
||||
|
||||
static Ref<Texture> make_icon_lock_layer_png() {
|
||||
return make_icon(lock_layer_png);
|
||||
}
|
||||
|
||||
static Ref<Texture> make_icon_lock_layer_1_png() {
|
||||
return make_icon(lock_layer_1_png);
|
||||
}
|
||||
|
||||
static Ref<Texture> make_icon_minidotta_png() {
|
||||
return make_icon(minidotta_png);
|
||||
}
|
||||
|
||||
static Ref<Texture> make_icon_minidotta_invis_png() {
|
||||
return make_icon(minidotta_invis_png);
|
||||
}
|
||||
|
||||
static Ref<Texture> make_icon_unlock_layer_png() {
|
||||
return make_icon(unlock_layer_png);
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
@ -31,31 +31,7 @@ SOFTWARE.
|
||||
|
||||
#include "../shaders/shaders.h"
|
||||
|
||||
#include "../paint_icons/paint_icons.h"
|
||||
|
||||
static float scale = 1;
|
||||
|
||||
template <class T>
|
||||
static Ref<Texture> make_icon(T p_src) {
|
||||
Ref<ImageTexture> texture(memnew(ImageTexture));
|
||||
Ref<Image> img = memnew(Image(p_src));
|
||||
if (scale > 1) {
|
||||
Size2 orig_size = Size2(img->get_width(), img->get_height());
|
||||
|
||||
img->convert(Image::FORMAT_RGBA8);
|
||||
img->expand_x2_hq2x();
|
||||
if (scale != 2.0) {
|
||||
img->resize(orig_size.x * scale, orig_size.y * scale);
|
||||
}
|
||||
} else if (scale < 1) {
|
||||
Size2 orig_size = Size2(img->get_width(), img->get_height());
|
||||
img->convert(Image::FORMAT_RGBA8);
|
||||
img->resize(orig_size.x * scale, orig_size.y * scale);
|
||||
}
|
||||
texture->create_from_image(img, ImageTexture::FLAG_FILTER);
|
||||
|
||||
return texture;
|
||||
}
|
||||
#include "../paint_icons/icons.h"
|
||||
|
||||
float PaintCanvasBackground::get_pixel_size() const {
|
||||
return _pixel_size;
|
||||
@ -72,7 +48,7 @@ PaintCanvasBackground::PaintCanvasBackground() {
|
||||
set_expand(true);
|
||||
set_stretch_mode(TextureRect::STRETCH_TILE);
|
||||
|
||||
set_texture(make_icon(grid_png));
|
||||
set_texture(PaintIcons::make_icon_grid_png());
|
||||
|
||||
_shader.instance();
|
||||
_shader->set_code(background_shader_shader_code);
|
||||
|
Loading…
Reference in New Issue
Block a user