mirror of
https://github.com/Relintai/pandemonium_engine.git
synced 2025-03-03 11:54:20 +01:00
Initial cleanup for the ImagePickerButton.
This commit is contained in:
parent
b50e8bc49b
commit
d25efcc17c
@ -1,98 +1,85 @@
|
|||||||
|
|
||||||
#include "image_picker_button.h"
|
#include "image_picker_button.h"
|
||||||
|
|
||||||
|
String ImagePickerButton::get_image_path() {
|
||||||
Variant ImagePickerButton::get_Variant() {
|
return image_path;
|
||||||
return Variant;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ImagePickerButton::set_Variant(const Variant &val) {
|
void ImagePickerButton::set_image_path(const String &path) {
|
||||||
Variant = val;
|
do_set_image_path(path);
|
||||||
|
emit_signal("on_file_selected", path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ImagePickerButton::do_set_image_path(const String &path) {
|
||||||
|
if (path == "") {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
image_path = path;
|
||||||
//tool;
|
texture_normal.load(image_path);
|
||||||
Variant = "";
|
|
||||||
signal on_file_selected(f);
|
|
||||||
|
|
||||||
void ImagePickerButton::_ready() {
|
|
||||||
texture_normal = ImageTexture.new();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ImagePickerButton::_on_ImagePicker_pressed() {
|
||||||
|
//var dialog = preload("res://addons/mat_maker_gd/windows/file_dialog/file_dialog.tscn").instance();
|
||||||
|
add_child(dialog);
|
||||||
|
dialog->set_rect_min_size(Vector2(500, 500));
|
||||||
|
dialog->set_access(FileDialog.ACCESS_FILESYSTEM);
|
||||||
|
dialog->set_mode(FileDialog.MODE_OPEN_FILE);
|
||||||
|
dialog->add_filter("*.bmp;BMP Image");
|
||||||
|
dialog->add_filter("*.exr;EXR Image");
|
||||||
|
dialog->add_filter("*.hdr;Radiance HDR Image");
|
||||||
|
dialog->add_filter("*.jpg,*.jpeg;JPEG Image");
|
||||||
|
dialog->add_filter("*.png;PNG Image");
|
||||||
|
dialog->add_filter("*.svg;SVG Image");
|
||||||
|
dialog->add_filter("*.tga;TGA Image");
|
||||||
|
dialog->add_filter("*.webp;WebP Image");
|
||||||
|
image_path = dialog->select_files();
|
||||||
|
|
||||||
void ImagePickerButton::do_set_image_path(const Variant &path) {
|
while (files is GDScriptFunctionState) {
|
||||||
|
files = yield(files, "completed");
|
||||||
|
}
|
||||||
|
|
||||||
if (path == null) {
|
if (files.size() > 0) {
|
||||||
return;
|
set_image_path(files[0]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
image_path = path;
|
void ImagePickerButton::on_drop_image_file(const String &file_name) {
|
||||||
texture_normal.load(image_path);
|
set_image_path(file_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ImagePickerButton::ImagePickerButton() {
|
||||||
|
set_custom_minimum_size(Vector2(64, 64));
|
||||||
|
set_clip_contents(true);
|
||||||
|
|
||||||
void ImagePickerButton::set_image_path(const Variant &path) {
|
Ref<ImageTexture> imagepicker_prop_texture_normal;
|
||||||
do_set_image_path(path);
|
imagepicker_prop_texture_normal.instance();
|
||||||
emit_signal("on_file_selected", path);
|
set_texture_normal(imagepicker_prop_texture_normal);
|
||||||
|
set_expand(true);
|
||||||
|
set_stretch_mode(STRETCH_KEEP_ASPECT_CENTERED);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ImagePickerButton::~ImagePickerButton() {
|
||||||
void ImagePickerButton::_on_ImagePicker_pressed() {
|
|
||||||
//var dialog = preload("res://addons/mat_maker_gd/windows/file_dialog/file_dialog.tscn").instance();
|
|
||||||
add_child(dialog);
|
|
||||||
dialog.rect_min_size = Vector2(500, 500);
|
|
||||||
dialog.access = FileDialog.ACCESS_FILESYSTEM;
|
|
||||||
dialog.mode = FileDialog.MODE_OPEN_FILE;
|
|
||||||
dialog.add_filter("*.bmp;BMP Image");
|
|
||||||
dialog.add_filter("*.exr;EXR Image");
|
|
||||||
dialog.add_filter("*.hdr;Radiance HDR Image");
|
|
||||||
dialog.add_filter("*.jpg,*.jpeg;JPEG Image");
|
|
||||||
dialog.add_filter("*.png;PNG Image");
|
|
||||||
dialog.add_filter("*.svg;SVG Image");
|
|
||||||
dialog.add_filter("*.tga;TGA Image");
|
|
||||||
dialog.add_filter("*.webp;WebP Image");
|
|
||||||
Variant = dialog.select_files();
|
|
||||||
|
|
||||||
while (files is GDScriptFunctionState) {
|
|
||||||
files = yield(files, "completed");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ImagePickerButton::_notification(int p_what) {
|
||||||
|
if (p_what == NOTIFICATION_POSTINITIALIZE) {
|
||||||
|
texture_normal = memnew(ImageTexture);
|
||||||
|
|
||||||
if (files.size() > 0) {
|
connect("pressed", this, "_on_ImagePicker_pressed");
|
||||||
set_image_path(files[0]);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ImagePickerButton::_bind_methods() {
|
||||||
|
ADD_SIGNAL(MethodInfo("on_file_selected", PropertyInfo(Variant::STRING, "file")));
|
||||||
|
|
||||||
|
ClassDB::bind_method(D_METHOD("get_image_path"), &ImagePickerButton::get_image_path);
|
||||||
|
ClassDB::bind_method(D_METHOD("set_image_path", "path"), &ImagePickerButton::set_image_path);
|
||||||
|
ADD_PROPERTY(PropertyInfo(Variant::STRING, "image_path"), "set_image_path", "get_image_path");
|
||||||
|
|
||||||
|
ClassDB::bind_method(D_METHOD("_ready"), &ImagePickerButton::_ready);
|
||||||
|
ClassDB::bind_method(D_METHOD("do_set_image_path", "path"), &ImagePickerButton::do_set_image_path);
|
||||||
|
ClassDB::bind_method(D_METHOD("set_image_path", "path"), &ImagePickerButton::set_image_path);
|
||||||
|
ClassDB::bind_method(D_METHOD("_on_ImagePicker_pressed"), &ImagePickerButton::_on_ImagePicker_pressed);
|
||||||
|
ClassDB::bind_method(D_METHOD("on_drop_image_file", "file_name"), &ImagePickerButton::on_drop_image_file);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void ImagePickerButton::on_drop_image_file(const String &file_name) {
|
|
||||||
set_image_path(file_name);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
ImagePickerButton::ImagePickerButton() {
|
|
||||||
= "";
|
|
||||||
}
|
|
||||||
|
|
||||||
ImagePickerButton::~ImagePickerButton() {
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static void ImagePickerButton::_bind_methods() {
|
|
||||||
ClassDB::bind_method(D_METHOD("get_Variant"), &ImagePickerButton::get_Variant);
|
|
||||||
ClassDB::bind_method(D_METHOD("set_Variant", "value"), &ImagePickerButton::set_Variant);
|
|
||||||
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "Variant", PROPERTY_HINT_RESOURCE_TYPE, "Variant"), "set_Variant", "get_Variant");
|
|
||||||
|
|
||||||
|
|
||||||
ClassDB::bind_method(D_METHOD("_ready"), &ImagePickerButton::_ready);
|
|
||||||
ClassDB::bind_method(D_METHOD("do_set_image_path", "path"), &ImagePickerButton::do_set_image_path);
|
|
||||||
ClassDB::bind_method(D_METHOD("set_image_path", "path"), &ImagePickerButton::set_image_path);
|
|
||||||
ClassDB::bind_method(D_METHOD("_on_ImagePicker_pressed"), &ImagePickerButton::_on_ImagePicker_pressed);
|
|
||||||
ClassDB::bind_method(D_METHOD("on_drop_image_file", "file_name"), &ImagePickerButton::on_drop_image_file);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,46 +0,0 @@
|
|||||||
|
|
||||||
void construct() {
|
|
||||||
|
|
||||||
//Script: res://addons/mat_maker_gd/widgets/image_picker_button/image_picker_button.gd
|
|
||||||
TextureButton *imagepicker = memnew(TextureButton);
|
|
||||||
imagepicker->set_name("ImagePicker");
|
|
||||||
|
|
||||||
imagepicker->set_name("ImagePicker");
|
|
||||||
//imagepicker->set("name", ImagePicker));
|
|
||||||
|
|
||||||
imagepicker->set_filename("res://addons/mat_maker_gd/widgets/image_picker_button/image_picker_button.tscn");
|
|
||||||
//imagepicker->set("filename", "res://addons/mat_maker_gd/widgets/image_picker_button/image_picker_button.tscn");
|
|
||||||
|
|
||||||
imagepicker->set_margin_right(64);
|
|
||||||
//imagepicker->set("margin_right", 64);
|
|
||||||
|
|
||||||
imagepicker->set_margin_bottom(64);
|
|
||||||
//imagepicker->set("margin_bottom", 64);
|
|
||||||
|
|
||||||
imagepicker->set_rect_size(Vector2(64, 64));
|
|
||||||
//imagepicker->set("rect_size", Vector2(64, 64));
|
|
||||||
|
|
||||||
imagepicker->set_rect_min_size(Vector2(64, 64));
|
|
||||||
//imagepicker->set("rect_min_size", Vector2(64, 64));
|
|
||||||
|
|
||||||
imagepicker->set_rect_clip_content(True);
|
|
||||||
//imagepicker->set("rect_clip_content", True);
|
|
||||||
|
|
||||||
//imagepicker property texture_normal TYPE_OBJECT value: [ImageTexture:46513]
|
|
||||||
Ref<ImageTexture> imagepicker_prop_texture_normal;
|
|
||||||
imagepicker_prop_texture_normal.instance();
|
|
||||||
imagepicker->set_texture_normal(imagepicker_prop_texture_normal);
|
|
||||||
//imagepicker->set("texture_normal", imagepicker_prop_texture_normal);
|
|
||||||
|
|
||||||
imagepicker->set_expand(True);
|
|
||||||
//imagepicker->set("expand", True);
|
|
||||||
|
|
||||||
imagepicker->set_stretch_mode(5);
|
|
||||||
//imagepicker->set("stretch_mode", 5);
|
|
||||||
|
|
||||||
//imagepicker property __meta__ TYPE_DICTIONARY value: {_edit_use_anchors_:False}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
@ -1,31 +1,30 @@
|
|||||||
#ifndef IMAGE_PICKER_BUTTON_H
|
#ifndef IMAGE_PICKER_BUTTON_H
|
||||||
#define IMAGE_PICKER_BUTTON_H
|
#define IMAGE_PICKER_BUTTON_H
|
||||||
|
|
||||||
|
#include "core/ustring.h"
|
||||||
|
|
||||||
|
#include "scene/gui/texture_button.h"
|
||||||
|
|
||||||
class ImagePickerButton : public TextureButton {
|
class ImagePickerButton : public TextureButton {
|
||||||
GDCLASS(ImagePickerButton, TextureButton);
|
GDCLASS(ImagePickerButton, TextureButton);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
String get_image_path();
|
||||||
|
void set_image_path(const String &path);
|
||||||
|
|
||||||
Variant get_Variant();
|
void do_set_image_path(const String &path);
|
||||||
void set_Variant(const Variant &val);
|
|
||||||
|
|
||||||
void _ready();
|
void _on_ImagePicker_pressed();
|
||||||
void do_set_image_path(const Variant &path);
|
void on_drop_image_file(const String &file_name);
|
||||||
void set_image_path(const Variant &path);
|
|
||||||
void _on_ImagePicker_pressed();
|
|
||||||
void on_drop_image_file(const String &file_name);
|
|
||||||
|
|
||||||
ImagePickerButton();
|
ImagePickerButton();
|
||||||
~ImagePickerButton();
|
~ImagePickerButton();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
static void _bind_methods();
|
void _notification(int p_what);
|
||||||
|
static void _bind_methods();
|
||||||
|
|
||||||
//tool
|
String image_path;
|
||||||
Variant = "";
|
|
||||||
signal on_file_selected(f);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user