2016-05-23 20:10:26 +00:00
|
|
|
#include "texture_editor_plugin.h"
|
|
|
|
|
2017-03-18 22:45:45 +00:00
|
|
|
#include "editor/editor_settings.h"
|
2017-03-18 23:36:26 +00:00
|
|
|
#include "globals.h"
|
|
|
|
#include "io/resource_loader.h"
|
2016-05-23 20:10:26 +00:00
|
|
|
|
|
|
|
void TextureEditor::_input_event(InputEvent p_event) {
|
|
|
|
}
|
|
|
|
|
|
|
|
void TextureEditor::_notification(int p_what) {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (p_what == NOTIFICATION_FIXED_PROCESS) {
|
2016-05-23 20:10:26 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (p_what == NOTIFICATION_READY) {
|
2016-05-23 20:10:26 +00:00
|
|
|
|
|
|
|
//get_scene()->connect("node_removed",this,"_node_removed");
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (p_what == NOTIFICATION_DRAW) {
|
2016-05-23 20:10:26 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
Ref<Texture> checkerboard = get_icon("Checkerboard", "EditorIcons");
|
2016-05-23 20:10:26 +00:00
|
|
|
Size2 size = get_size();
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
draw_texture_rect(checkerboard, Rect2(Point2(), size), true);
|
2016-05-23 20:10:26 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
int tex_width = texture->get_width() * size.height / texture->get_height();
|
2016-05-23 20:10:26 +00:00
|
|
|
int tex_height = size.height;
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (tex_width > size.width) {
|
|
|
|
tex_width = size.width;
|
|
|
|
tex_height = texture->get_height() * tex_width / texture->get_width();
|
2016-05-23 20:10:26 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
int ofs_x = (size.width - tex_width) / 2;
|
|
|
|
int ofs_y = (size.height - tex_height) / 2;
|
2016-05-23 20:10:26 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
draw_texture_rect(texture, Rect2(ofs_x, ofs_y, tex_width, tex_height));
|
2016-05-23 20:10:26 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
Ref<Font> font = get_font("font", "Label");
|
2016-05-23 20:10:26 +00:00
|
|
|
|
|
|
|
String format;
|
|
|
|
if (texture->cast_to<ImageTexture>()) {
|
|
|
|
format = Image::get_format_name(texture->cast_to<ImageTexture>()->get_format());
|
|
|
|
} else {
|
2017-03-18 23:36:26 +00:00
|
|
|
format = texture->get_type();
|
2016-05-23 20:10:26 +00:00
|
|
|
}
|
2017-03-18 23:36:26 +00:00
|
|
|
String text = itos(texture->get_width()) + "x" + itos(texture->get_height()) + " " + format;
|
2016-05-23 20:10:26 +00:00
|
|
|
|
|
|
|
Size2 rect = font->get_string_size(text);
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
Vector2 draw_from = size - rect + Size2(-2, font->get_ascent() - 2);
|
|
|
|
if (draw_from.x < 0)
|
|
|
|
draw_from.x = 0;
|
2016-05-23 20:10:26 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
draw_string(font, draw_from + Vector2(2, 2), text, Color(0, 0, 0, 0.5), size.width);
|
|
|
|
draw_string(font, draw_from - Vector2(2, 2), text, Color(0, 0, 0, 0.5), size.width);
|
|
|
|
draw_string(font, draw_from, text, Color(1, 1, 1, 1), size.width);
|
2016-05-23 20:10:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void TextureEditor::edit(Ref<Texture> p_texture) {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
texture = p_texture;
|
2016-05-23 20:10:26 +00:00
|
|
|
|
|
|
|
if (!texture.is_null())
|
|
|
|
update();
|
|
|
|
else {
|
|
|
|
|
|
|
|
hide();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void TextureEditor::_bind_methods() {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
ObjectTypeDB::bind_method(_MD("_input_event"), &TextureEditor::_input_event);
|
2016-05-23 20:10:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TextureEditor::TextureEditor() {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
set_custom_minimum_size(Size2(1, 150));
|
2016-05-23 20:10:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void TextureEditorPlugin::edit(Object *p_object) {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
Texture *s = p_object->cast_to<Texture>();
|
2016-05-23 20:10:26 +00:00
|
|
|
if (!s)
|
|
|
|
return;
|
|
|
|
|
|
|
|
texture_editor->edit(Ref<Texture>(s));
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TextureEditorPlugin::handles(Object *p_object) const {
|
|
|
|
|
|
|
|
return p_object->is_type("Texture");
|
|
|
|
}
|
|
|
|
|
|
|
|
void TextureEditorPlugin::make_visible(bool p_visible) {
|
|
|
|
|
|
|
|
if (p_visible) {
|
|
|
|
texture_editor->show();
|
2017-03-18 23:36:26 +00:00
|
|
|
// texture_editor->set_process(true);
|
2016-05-23 20:10:26 +00:00
|
|
|
} else {
|
|
|
|
|
|
|
|
texture_editor->hide();
|
2017-03-18 23:36:26 +00:00
|
|
|
// texture_editor->set_process(false);
|
2016-05-23 20:10:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TextureEditorPlugin::TextureEditorPlugin(EditorNode *p_node) {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
editor = p_node;
|
|
|
|
texture_editor = memnew(TextureEditor);
|
|
|
|
add_control_to_container(CONTAINER_PROPERTY_EDITOR_BOTTOM, texture_editor);
|
2016-05-23 20:10:26 +00:00
|
|
|
texture_editor->hide();
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
TextureEditorPlugin::~TextureEditorPlugin() {
|
2016-05-23 20:10:26 +00:00
|
|
|
}
|