summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--scene/2d/animated_sprite.cpp8
-rw-r--r--scene/2d/animated_sprite.h16
-rw-r--r--scene/resources/style_box.cpp23
-rw-r--r--scene/resources/style_box.h4
4 files changed, 49 insertions, 2 deletions
diff --git a/scene/2d/animated_sprite.cpp b/scene/2d/animated_sprite.cpp
index eba638b0f5..6a3238b64e 100644
--- a/scene/2d/animated_sprite.cpp
+++ b/scene/2d/animated_sprite.cpp
@@ -32,6 +32,8 @@
#include "scene/scene_string_names.h"
#include "scene/scene_string_names.h"
+#define NORMAL_SUFFIX "_normal"
+
////////////////////////////
void SpriteFrames::add_frame(const StringName &p_anim, const Ref<Texture> &p_frame, int p_at_pos) {
@@ -82,6 +84,7 @@ void SpriteFrames::add_animation(const StringName &p_anim) {
ERR_FAIL_COND(animations.has(p_anim));
animations[p_anim] = Anim();
+ animations[p_anim].normal_name = String(p_anim) + NORMAL_SUFFIX;
}
bool SpriteFrames::has_animation(const StringName &p_anim) const {
@@ -101,6 +104,7 @@ void SpriteFrames::rename_animation(const StringName &p_prev, const StringName &
Anim anim = animations[p_prev];
animations.erase(p_prev);
animations[p_next] = anim;
+ animations[p_next].normal_name = String(p_next) + NORMAL_SUFFIX;
}
Vector<String> SpriteFrames::_get_animation_list() const {
@@ -374,6 +378,8 @@ void AnimatedSprite::_notification(int p_what) {
return;
}
+ Ref<Texture> normal = frames->get_normal_frame(animation, frame);
+
//print_line("DECIDED TO DRAW");
RID ci = get_canvas_item();
@@ -400,7 +406,7 @@ void AnimatedSprite::_notification(int p_what) {
dst_rect.size.y = -dst_rect.size.y;
//texture->draw_rect(ci,dst_rect,false,modulate);
- texture->draw_rect_region(ci, dst_rect, Rect2(Vector2(), texture->get_size()));
+ texture->draw_rect_region(ci, dst_rect, Rect2(Vector2(), texture->get_size()), Color(1, 1, 1), false, normal);
//VisualServer::get_singleton()->canvas_item_add_texture_rect_region(ci,dst_rect,texture->get_rid(),src_rect,modulate);
} break;
diff --git a/scene/2d/animated_sprite.h b/scene/2d/animated_sprite.h
index 64794b0ca3..2274450647 100644
--- a/scene/2d/animated_sprite.h
+++ b/scene/2d/animated_sprite.h
@@ -47,6 +47,8 @@ class SpriteFrames : public Resource {
loop = true;
speed = 5;
}
+
+ StringName normal_name;
};
Map<StringName, Anim> animations;
@@ -89,6 +91,20 @@ public:
return E->get().frames[p_idx];
}
+ _FORCE_INLINE_ Ref<Texture> get_normal_frame(const StringName &p_anim, int p_idx) const {
+
+ const Map<StringName, Anim>::Element *E = animations.find(p_anim);
+ ERR_FAIL_COND_V(!E, Ref<Texture>());
+ ERR_FAIL_COND_V(p_idx < 0, Ref<Texture>());
+
+ const Map<StringName, Anim>::Element *EN = animations.find(E->get().normal_name);
+
+ if (p_idx >= EN->get().frames.size())
+ return Ref<Texture>();
+
+ return EN->get().frames[p_idx];
+ }
+
void set_frame(const StringName &p_anim, int p_idx, const Ref<Texture> &p_frame) {
Map<StringName, Anim>::Element *E = animations.find(p_anim);
ERR_FAIL_COND(!E);
diff --git a/scene/resources/style_box.cpp b/scene/resources/style_box.cpp
index 8874cbc102..2714ffec10 100644
--- a/scene/resources/style_box.cpp
+++ b/scene/resources/style_box.cpp
@@ -114,6 +114,19 @@ RES StyleBoxTexture::get_texture() const {
return texture;
}
+void StyleBoxTexture::set_normal_map(RES p_normal_map) {
+
+ if (normal_map == p_normal_map)
+ return;
+ normal_map = p_normal_map;
+ emit_changed();
+}
+
+RES StyleBoxTexture::get_normal_map() const {
+
+ return normal_map;
+}
+
void StyleBoxTexture::set_margin_size(Margin p_margin, float p_size) {
margin[p_margin] = p_size;
@@ -143,7 +156,11 @@ void StyleBoxTexture::draw(RID p_canvas_item, const Rect2 &p_rect) const {
rect.size.x += expand_margin[MARGIN_LEFT] + expand_margin[MARGIN_RIGHT];
rect.size.y += expand_margin[MARGIN_TOP] + expand_margin[MARGIN_BOTTOM];
- VisualServer::get_singleton()->canvas_item_add_nine_patch(p_canvas_item, rect, src_rect, texture->get_rid(), Vector2(margin[MARGIN_LEFT], margin[MARGIN_TOP]), Vector2(margin[MARGIN_RIGHT], margin[MARGIN_BOTTOM]), VS::NINE_PATCH_STRETCH, VS::NINE_PATCH_STRETCH, draw_center, modulate);
+ RID normal_rid;
+ if (normal_map.is_valid())
+ normal_rid = normal_map->get_rid();
+
+ VisualServer::get_singleton()->canvas_item_add_nine_patch(p_canvas_item, rect, src_rect, texture->get_rid(), Vector2(margin[MARGIN_LEFT], margin[MARGIN_TOP]), Vector2(margin[MARGIN_RIGHT], margin[MARGIN_BOTTOM]), VS::NINE_PATCH_STRETCH, VS::NINE_PATCH_STRETCH, draw_center, modulate, normal_rid);
}
void StyleBoxTexture::set_draw_center(bool p_draw) {
@@ -209,6 +226,9 @@ void StyleBoxTexture::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_texture", "texture:Texture"), &StyleBoxTexture::set_texture);
ClassDB::bind_method(D_METHOD("get_texture:Texture"), &StyleBoxTexture::get_texture);
+ ClassDB::bind_method(D_METHOD("set_normal_map", "normal_map:Texture"), &StyleBoxTexture::set_normal_map);
+ ClassDB::bind_method(D_METHOD("get_normal_map:Texture"), &StyleBoxTexture::get_normal_map);
+
ClassDB::bind_method(D_METHOD("set_margin_size", "margin", "size"), &StyleBoxTexture::set_margin_size);
ClassDB::bind_method(D_METHOD("get_margin_size", "margin"), &StyleBoxTexture::get_margin_size);
@@ -227,6 +247,7 @@ void StyleBoxTexture::_bind_methods() {
ADD_SIGNAL(MethodInfo("texture_changed"));
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "texture", PROPERTY_HINT_RESOURCE_TYPE, "Texture"), "set_texture", "get_texture");
+ ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "normal_map", PROPERTY_HINT_RESOURCE_TYPE, "Texture"), "set_normal_map", "get_normal_map");
ADD_PROPERTYNZ(PropertyInfo(Variant::RECT2, "region_rect"), "set_region_rect", "get_region_rect");
ADD_GROUP("Margin", "margin_");
ADD_PROPERTYI(PropertyInfo(Variant::REAL, "margin_left", PROPERTY_HINT_RANGE, "0,2048,1"), "set_margin_size", "get_margin_size", MARGIN_LEFT);
diff --git a/scene/resources/style_box.h b/scene/resources/style_box.h
index 97edc68bff..7547c2ea81 100644
--- a/scene/resources/style_box.h
+++ b/scene/resources/style_box.h
@@ -81,6 +81,7 @@ class StyleBoxTexture : public StyleBox {
float margin[4];
Rect2 region_rect;
Ref<Texture> texture;
+ Ref<Texture> normal_map;
bool draw_center;
Color modulate;
@@ -101,6 +102,9 @@ public:
void set_texture(RES p_texture);
RES get_texture() const;
+ void set_normal_map(RES p_normal_map);
+ RES get_normal_map() const;
+
void set_draw_center(bool p_draw);
bool get_draw_center() const;
virtual Size2 get_center_size() const;