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"
|
||||
|
||||
|
||||
Variant ImagePickerButton::get_Variant() {
|
||||
return Variant;
|
||||
String ImagePickerButton::get_image_path() {
|
||||
return image_path;
|
||||
}
|
||||
|
||||
void ImagePickerButton::set_Variant(const Variant &val) {
|
||||
Variant = val;
|
||||
void ImagePickerButton::set_image_path(const String &path) {
|
||||
do_set_image_path(path);
|
||||
emit_signal("on_file_selected", path);
|
||||
}
|
||||
|
||||
|
||||
|
||||
//tool;
|
||||
Variant = "";
|
||||
signal on_file_selected(f);
|
||||
|
||||
void ImagePickerButton::_ready() {
|
||||
texture_normal = ImageTexture.new();
|
||||
}
|
||||
|
||||
|
||||
void ImagePickerButton::do_set_image_path(const Variant &path) {
|
||||
|
||||
if (path == null) {
|
||||
void ImagePickerButton::do_set_image_path(const String &path) {
|
||||
if (path == "") {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
image_path = path;
|
||||
texture_normal.load(image_path);
|
||||
}
|
||||
|
||||
|
||||
void ImagePickerButton::set_image_path(const Variant &path) {
|
||||
do_set_image_path(path);
|
||||
emit_signal("on_file_selected", path);
|
||||
}
|
||||
|
||||
|
||||
void ImagePickerButton::_on_ImagePicker_pressed() {
|
||||
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();
|
||||
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();
|
||||
|
||||
while (files is GDScriptFunctionState) {
|
||||
files = yield(files, "completed");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (files.size() > 0) {
|
||||
set_image_path(files[0]);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
void ImagePickerButton::on_drop_image_file(const String &file_name) {
|
||||
void ImagePickerButton::on_drop_image_file(const String &file_name) {
|
||||
set_image_path(file_name);
|
||||
}
|
||||
|
||||
ImagePickerButton::ImagePickerButton() {
|
||||
set_custom_minimum_size(Vector2(64, 64));
|
||||
set_clip_contents(true);
|
||||
|
||||
Ref<ImageTexture> imagepicker_prop_texture_normal;
|
||||
imagepicker_prop_texture_normal.instance();
|
||||
set_texture_normal(imagepicker_prop_texture_normal);
|
||||
set_expand(true);
|
||||
set_stretch_mode(STRETCH_KEEP_ASPECT_CENTERED);
|
||||
}
|
||||
|
||||
ImagePickerButton::ImagePickerButton() {
|
||||
= "";
|
||||
ImagePickerButton::~ImagePickerButton() {
|
||||
}
|
||||
|
||||
void ImagePickerButton::_notification(int p_what) {
|
||||
if (p_what == NOTIFICATION_POSTINITIALIZE) {
|
||||
texture_normal = memnew(ImageTexture);
|
||||
|
||||
connect("pressed", this, "_on_ImagePicker_pressed");
|
||||
}
|
||||
}
|
||||
|
||||
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");
|
||||
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);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -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
|
||||
#define IMAGE_PICKER_BUTTON_H
|
||||
|
||||
#include "core/ustring.h"
|
||||
|
||||
#include "scene/gui/texture_button.h"
|
||||
|
||||
class ImagePickerButton : public TextureButton {
|
||||
GDCLASS(ImagePickerButton, TextureButton);
|
||||
|
||||
public:
|
||||
public:
|
||||
String get_image_path();
|
||||
void set_image_path(const String &path);
|
||||
|
||||
Variant get_Variant();
|
||||
void set_Variant(const Variant &val);
|
||||
void do_set_image_path(const String &path);
|
||||
|
||||
void _ready();
|
||||
void do_set_image_path(const Variant &path);
|
||||
void set_image_path(const Variant &path);
|
||||
void _on_ImagePicker_pressed();
|
||||
void on_drop_image_file(const String &file_name);
|
||||
|
||||
ImagePickerButton();
|
||||
~ImagePickerButton();
|
||||
|
||||
protected:
|
||||
protected:
|
||||
void _notification(int p_what);
|
||||
static void _bind_methods();
|
||||
|
||||
//tool
|
||||
Variant = "";
|
||||
signal on_file_selected(f);
|
||||
String image_path;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user