summaryrefslogtreecommitdiff
path: root/scene/2d/sprite.cpp
diff options
context:
space:
mode:
authorRémi Verschelde <rverschelde@gmail.com>2017-03-05 16:44:50 +0100
committerRémi Verschelde <rverschelde@gmail.com>2017-03-05 16:44:50 +0100
commit5dbf1809c6e3e905b94b8764e99491e608122261 (patch)
tree5e5a5360db15d86d59ec8c6e4f7eb511388c5a9a /scene/2d/sprite.cpp
parent45438e9918d421b244bfd7776a30e67dc7f2d3e3 (diff)
A Whole New World (clang-format edition)
I can show you the code Pretty, with proper whitespace Tell me, coder, now when did You last write readable code? I can open your eyes Make you see your bad indent Force you to respect the style The core devs agreed upon A whole new world A new fantastic code format A de facto standard With some sugar Enforced with clang-format A whole new world A dazzling style we all dreamed of And when we read it through It's crystal clear That now we're in a whole new world of code
Diffstat (limited to 'scene/2d/sprite.cpp')
-rw-r--r--scene/2d/sprite.cpp190
1 files changed, 88 insertions, 102 deletions
diff --git a/scene/2d/sprite.cpp b/scene/2d/sprite.cpp
index 26c2756acd..41ea6a39e5 100644
--- a/scene/2d/sprite.cpp
+++ b/scene/2d/sprite.cpp
@@ -28,14 +28,13 @@
/*************************************************************************/
#include "sprite.h"
#include "core/core_string_names.h"
-#include "scene/scene_string_names.h"
-#include "scene/main/viewport.h"
#include "os/os.h"
+#include "scene/main/viewport.h"
+#include "scene/scene_string_names.h"
-void Sprite::edit_set_pivot(const Point2& p_pivot) {
+void Sprite::edit_set_pivot(const Point2 &p_pivot) {
set_offset(p_pivot);
-
}
Point2 Sprite::edit_get_pivot() const {
@@ -49,16 +48,13 @@ bool Sprite::edit_has_pivot() const {
void Sprite::_notification(int p_what) {
- switch(p_what) {
+ switch (p_what) {
case NOTIFICATION_DRAW: {
if (texture.is_null())
return;
-
-
-
RID ci = get_canvas_item();
/*
@@ -71,52 +67,51 @@ void Sprite::_notification(int p_what) {
if (region) {
- s=region_rect.size;
- src_rect=region_rect;
+ s = region_rect.size;
+ src_rect = region_rect;
} else {
s = Size2(texture->get_size());
- s=s/Size2(hframes,vframes);
-
- src_rect.size=s;
- src_rect.pos.x+=float(frame%hframes)*s.x;
- src_rect.pos.y+=float(frame/hframes)*s.y;
+ s = s / Size2(hframes, vframes);
+ src_rect.size = s;
+ src_rect.pos.x += float(frame % hframes) * s.x;
+ src_rect.pos.y += float(frame / hframes) * s.y;
}
- Point2 ofs=offset;
+ Point2 ofs = offset;
if (centered)
- ofs-=s/2;
+ ofs -= s / 2;
if (Engine::get_singleton()->get_use_pixel_snap()) {
- ofs=ofs.floor();
+ ofs = ofs.floor();
}
- Rect2 dst_rect(ofs,s);
+ Rect2 dst_rect(ofs, s);
if (hflip)
- dst_rect.size.x=-dst_rect.size.x;
+ dst_rect.size.x = -dst_rect.size.x;
if (vflip)
- dst_rect.size.y=-dst_rect.size.y;
+ dst_rect.size.y = -dst_rect.size.y;
- texture->draw_rect_region(ci,dst_rect,src_rect);
+ texture->draw_rect_region(ci, dst_rect, src_rect);
} break;
}
}
-void Sprite::set_texture(const Ref<Texture>& p_texture) {
+void Sprite::set_texture(const Ref<Texture> &p_texture) {
- if (p_texture==texture)
+ if (p_texture == texture)
return;
#ifdef DEBUG_ENABLED
if (texture.is_valid()) {
- texture->disconnect(CoreStringNames::get_singleton()->changed,this,SceneStringNames::get_singleton()->update);
+ texture->disconnect(CoreStringNames::get_singleton()->changed, this, SceneStringNames::get_singleton()->update);
}
#endif
- texture=p_texture;
+ texture = p_texture;
#ifdef DEBUG_ENABLED
if (texture.is_valid()) {
texture->set_flags(texture->get_flags()); //remove repeat from texture, it looks bad in sprites
- texture->connect(CoreStringNames::get_singleton()->changed,this,SceneStringNames::get_singleton()->update);
+ texture->connect(CoreStringNames::get_singleton()->changed, this, SceneStringNames::get_singleton()->update);
}
#endif
update();
@@ -131,7 +126,7 @@ Ref<Texture> Sprite::get_texture() const {
void Sprite::set_centered(bool p_center) {
- centered=p_center;
+ centered = p_center;
update();
item_rect_changed();
}
@@ -141,9 +136,9 @@ bool Sprite::is_centered() const {
return centered;
}
-void Sprite::set_offset(const Point2& p_offset) {
+void Sprite::set_offset(const Point2 &p_offset) {
- offset=p_offset;
+ offset = p_offset;
update();
item_rect_changed();
_change_notify("offset");
@@ -155,7 +150,7 @@ Point2 Sprite::get_offset() const {
void Sprite::set_flip_h(bool p_flip) {
- hflip=p_flip;
+ hflip = p_flip;
update();
}
bool Sprite::is_flipped_h() const {
@@ -165,7 +160,7 @@ bool Sprite::is_flipped_h() const {
void Sprite::set_flip_v(bool p_flip) {
- vflip=p_flip;
+ vflip = p_flip;
update();
}
bool Sprite::is_flipped_v() const {
@@ -175,24 +170,24 @@ bool Sprite::is_flipped_v() const {
void Sprite::set_region(bool p_region) {
- if (p_region==region)
+ if (p_region == region)
return;
- region=p_region;
+ region = p_region;
update();
}
-bool Sprite::is_region() const{
+bool Sprite::is_region() const {
return region;
}
-void Sprite::set_region_rect(const Rect2& p_region_rect) {
+void Sprite::set_region_rect(const Rect2 &p_region_rect) {
- if (region_rect==p_region_rect)
+ if (region_rect == p_region_rect)
return;
- region_rect=p_region_rect;
+ region_rect = p_region_rect;
if (region)
item_rect_changed();
@@ -207,12 +202,12 @@ Rect2 Sprite::get_region_rect() const {
void Sprite::set_frame(int p_frame) {
- ERR_FAIL_INDEX(p_frame,vframes*hframes);
+ ERR_FAIL_INDEX(p_frame, vframes * hframes);
if (frame != p_frame)
item_rect_changed();
- frame=p_frame;
+ frame = p_frame;
_change_notify("frame");
emit_signal(SceneStringNames::get_singleton()->frame_changed);
@@ -225,8 +220,8 @@ int Sprite::get_frame() const {
void Sprite::set_vframes(int p_amount) {
- ERR_FAIL_COND(p_amount<1);
- vframes=p_amount;
+ ERR_FAIL_COND(p_amount < 1);
+ vframes = p_amount;
update();
item_rect_changed();
_change_notify("frame");
@@ -238,8 +233,8 @@ int Sprite::get_vframes() const {
void Sprite::set_hframes(int p_amount) {
- ERR_FAIL_COND(p_amount<1);
- hframes=p_amount;
+ ERR_FAIL_COND(p_amount < 1);
+ hframes = p_amount;
update();
item_rect_changed();
_change_notify("frame");
@@ -249,12 +244,10 @@ int Sprite::get_hframes() const {
return hframes;
}
-
-
Rect2 Sprite::get_item_rect() const {
if (texture.is_null())
- return Rect2(0,0,1,1);
+ return Rect2(0, 0, 1, 1);
/*
if (texture.is_null())
return CanvasItem::get_item_rect();
@@ -264,99 +257,92 @@ Rect2 Sprite::get_item_rect() const {
if (region) {
- s=region_rect.size;
+ s = region_rect.size;
} else {
s = texture->get_size();
- s=s/Point2(hframes,vframes);
+ s = s / Point2(hframes, vframes);
}
- Point2 ofs=offset;
+ Point2 ofs = offset;
if (centered)
- ofs-=s/2;
+ ofs -= s / 2;
- if (s==Size2(0,0))
- s=Size2(1,1);
+ if (s == Size2(0, 0))
+ s = Size2(1, 1);
- return Rect2(ofs,s);
+ return Rect2(ofs, s);
}
+void Sprite::_validate_property(PropertyInfo &property) const {
+ if (property.name == "frame") {
-void Sprite::_validate_property(PropertyInfo& property) const {
-
- if (property.name=="frame") {
-
- property.hint=PROPERTY_HINT_SPRITE_FRAME;
+ property.hint = PROPERTY_HINT_SPRITE_FRAME;
- property.hint_string="0,"+itos(vframes*hframes-1)+",1";
+ property.hint_string = "0," + itos(vframes * hframes - 1) + ",1";
}
}
void Sprite::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_texture","texture:Texture"),&Sprite::set_texture);
- ClassDB::bind_method(D_METHOD("get_texture:Texture"),&Sprite::get_texture);
+ ClassDB::bind_method(D_METHOD("set_texture", "texture:Texture"), &Sprite::set_texture);
+ ClassDB::bind_method(D_METHOD("get_texture:Texture"), &Sprite::get_texture);
- ClassDB::bind_method(D_METHOD("set_centered","centered"),&Sprite::set_centered);
- ClassDB::bind_method(D_METHOD("is_centered"),&Sprite::is_centered);
+ ClassDB::bind_method(D_METHOD("set_centered", "centered"), &Sprite::set_centered);
+ ClassDB::bind_method(D_METHOD("is_centered"), &Sprite::is_centered);
- ClassDB::bind_method(D_METHOD("set_offset","offset"),&Sprite::set_offset);
- ClassDB::bind_method(D_METHOD("get_offset"),&Sprite::get_offset);
+ ClassDB::bind_method(D_METHOD("set_offset", "offset"), &Sprite::set_offset);
+ ClassDB::bind_method(D_METHOD("get_offset"), &Sprite::get_offset);
- ClassDB::bind_method(D_METHOD("set_flip_h","flip_h"),&Sprite::set_flip_h);
- ClassDB::bind_method(D_METHOD("is_flipped_h"),&Sprite::is_flipped_h);
+ ClassDB::bind_method(D_METHOD("set_flip_h", "flip_h"), &Sprite::set_flip_h);
+ ClassDB::bind_method(D_METHOD("is_flipped_h"), &Sprite::is_flipped_h);
- ClassDB::bind_method(D_METHOD("set_flip_v","flip_v"),&Sprite::set_flip_v);
- ClassDB::bind_method(D_METHOD("is_flipped_v"),&Sprite::is_flipped_v);
+ ClassDB::bind_method(D_METHOD("set_flip_v", "flip_v"), &Sprite::set_flip_v);
+ ClassDB::bind_method(D_METHOD("is_flipped_v"), &Sprite::is_flipped_v);
- ClassDB::bind_method(D_METHOD("set_region","enabled"),&Sprite::set_region);
- ClassDB::bind_method(D_METHOD("is_region"),&Sprite::is_region);
+ ClassDB::bind_method(D_METHOD("set_region", "enabled"), &Sprite::set_region);
+ ClassDB::bind_method(D_METHOD("is_region"), &Sprite::is_region);
- ClassDB::bind_method(D_METHOD("set_region_rect","rect"),&Sprite::set_region_rect);
- ClassDB::bind_method(D_METHOD("get_region_rect"),&Sprite::get_region_rect);
+ ClassDB::bind_method(D_METHOD("set_region_rect", "rect"), &Sprite::set_region_rect);
+ ClassDB::bind_method(D_METHOD("get_region_rect"), &Sprite::get_region_rect);
- ClassDB::bind_method(D_METHOD("set_frame","frame"),&Sprite::set_frame);
- ClassDB::bind_method(D_METHOD("get_frame"),&Sprite::get_frame);
+ ClassDB::bind_method(D_METHOD("set_frame", "frame"), &Sprite::set_frame);
+ ClassDB::bind_method(D_METHOD("get_frame"), &Sprite::get_frame);
- ClassDB::bind_method(D_METHOD("set_vframes","vframes"),&Sprite::set_vframes);
- ClassDB::bind_method(D_METHOD("get_vframes"),&Sprite::get_vframes);
+ ClassDB::bind_method(D_METHOD("set_vframes", "vframes"), &Sprite::set_vframes);
+ ClassDB::bind_method(D_METHOD("get_vframes"), &Sprite::get_vframes);
- ClassDB::bind_method(D_METHOD("set_hframes","hframes"),&Sprite::set_hframes);
- ClassDB::bind_method(D_METHOD("get_hframes"),&Sprite::get_hframes);
+ ClassDB::bind_method(D_METHOD("set_hframes", "hframes"), &Sprite::set_hframes);
+ ClassDB::bind_method(D_METHOD("get_hframes"), &Sprite::get_hframes);
ADD_SIGNAL(MethodInfo("frame_changed"));
ADD_SIGNAL(MethodInfo("texture_changed"));
- ADD_PROPERTYNZ( PropertyInfo( Variant::OBJECT, "texture", PROPERTY_HINT_RESOURCE_TYPE,"Texture"), "set_texture","get_texture");
- ADD_PROPERTYNO( PropertyInfo( Variant::BOOL, "centered"), "set_centered","is_centered");
- ADD_PROPERTYNZ( PropertyInfo( Variant::VECTOR2, "offset"), "set_offset","get_offset");
- ADD_PROPERTYNZ( PropertyInfo( Variant::BOOL, "flip_h"), "set_flip_h","is_flipped_h");
- ADD_PROPERTYNZ( PropertyInfo( Variant::BOOL, "flip_v"), "set_flip_v","is_flipped_v");
- ADD_PROPERTYNO( PropertyInfo( Variant::INT, "vframes",PROPERTY_HINT_RANGE,"1,16384,1"), "set_vframes","get_vframes");
- ADD_PROPERTYNO( PropertyInfo( Variant::INT, "hframes",PROPERTY_HINT_RANGE,"1,16384,1"), "set_hframes","get_hframes");
- ADD_PROPERTYNZ( PropertyInfo( Variant::INT, "frame",PROPERTY_HINT_SPRITE_FRAME), "set_frame","get_frame");
- ADD_PROPERTYNZ( PropertyInfo( Variant::BOOL, "region"), "set_region","is_region");
- ADD_PROPERTYNZ( PropertyInfo( Variant::RECT2, "region_rect"), "set_region_rect","get_region_rect");
-
+ ADD_PROPERTYNZ(PropertyInfo(Variant::OBJECT, "texture", PROPERTY_HINT_RESOURCE_TYPE, "Texture"), "set_texture", "get_texture");
+ ADD_PROPERTYNO(PropertyInfo(Variant::BOOL, "centered"), "set_centered", "is_centered");
+ ADD_PROPERTYNZ(PropertyInfo(Variant::VECTOR2, "offset"), "set_offset", "get_offset");
+ ADD_PROPERTYNZ(PropertyInfo(Variant::BOOL, "flip_h"), "set_flip_h", "is_flipped_h");
+ ADD_PROPERTYNZ(PropertyInfo(Variant::BOOL, "flip_v"), "set_flip_v", "is_flipped_v");
+ ADD_PROPERTYNO(PropertyInfo(Variant::INT, "vframes", PROPERTY_HINT_RANGE, "1,16384,1"), "set_vframes", "get_vframes");
+ ADD_PROPERTYNO(PropertyInfo(Variant::INT, "hframes", PROPERTY_HINT_RANGE, "1,16384,1"), "set_hframes", "get_hframes");
+ ADD_PROPERTYNZ(PropertyInfo(Variant::INT, "frame", PROPERTY_HINT_SPRITE_FRAME), "set_frame", "get_frame");
+ ADD_PROPERTYNZ(PropertyInfo(Variant::BOOL, "region"), "set_region", "is_region");
+ ADD_PROPERTYNZ(PropertyInfo(Variant::RECT2, "region_rect"), "set_region_rect", "get_region_rect");
}
Sprite::Sprite() {
- centered=true;
- hflip=false;
- vflip=false;
- region=false;
-
- frame=0;
+ centered = true;
+ hflip = false;
+ vflip = false;
+ region = false;
- vframes=1;
- hframes=1;
+ frame = 0;
+ vframes = 1;
+ hframes = 1;
}
-
-
-
//////////////////////////// VPSPRITE
///
///