mirror of
https://github.com/enduro2d/enduro2d.git
synced 2025-12-13 07:45:39 +07:00
remove sprite pivot
This commit is contained in:
@@ -29,17 +29,14 @@ namespace e2d
|
||||
sprite& assign(sprite&& other) noexcept;
|
||||
sprite& assign(const sprite& other);
|
||||
|
||||
sprite& set_pivot(const v2f& pivot) noexcept;
|
||||
sprite& set_inner_texrect(const b2f& texrect) noexcept;
|
||||
sprite& set_outer_texrect(const b2f& texrect) noexcept;
|
||||
sprite& set_texture(const texture_asset::ptr& texture) noexcept;
|
||||
|
||||
const v2f& pivot() const noexcept;
|
||||
const b2f& inner_texrect() const noexcept;
|
||||
const b2f& outer_texrect() const noexcept;
|
||||
const texture_asset::ptr& texture() const noexcept;
|
||||
private:
|
||||
v2f pivot_;
|
||||
b2f inner_texrect_;
|
||||
b2f outer_texrect_;
|
||||
texture_asset::ptr texture_;
|
||||
|
||||
@@ -36,20 +36,18 @@ namespace
|
||||
"sprite" : {
|
||||
"anyOf" : [{
|
||||
"type" : "object",
|
||||
"required" : [ "name", "pivot", "texrect" ],
|
||||
"required" : [ "name", "texrect" ],
|
||||
"additionalProperties" : false,
|
||||
"properties" : {
|
||||
"name" : { "$ref": "#/common_definitions/name" },
|
||||
"pivot" : { "$ref": "#/common_definitions/v2" },
|
||||
"texrect" : { "$ref": "#/common_definitions/b2" }
|
||||
}
|
||||
},{
|
||||
"type" : "object",
|
||||
"required" : [ "name", "pivot", "inner_texrect", "outer_texrect" ],
|
||||
"required" : [ "name", "inner_texrect", "outer_texrect" ],
|
||||
"additionalProperties" : false,
|
||||
"properties" : {
|
||||
"name" : { "$ref": "#/common_definitions/name" },
|
||||
"pivot" : { "$ref": "#/common_definitions/v2" },
|
||||
"inner_texrect" : { "$ref": "#/common_definitions/b2" },
|
||||
"outer_texrect" : { "$ref": "#/common_definitions/b2" }
|
||||
}
|
||||
@@ -78,7 +76,6 @@ namespace
|
||||
|
||||
struct sprite_desc {
|
||||
str_hash name;
|
||||
v2f pivot;
|
||||
b2f inner_texrect;
|
||||
b2f outer_texrect;
|
||||
};
|
||||
@@ -100,12 +97,6 @@ namespace
|
||||
return false;
|
||||
}
|
||||
|
||||
E2D_ASSERT(sprite_json.HasMember("pivot"));
|
||||
if ( !json_utils::try_parse_value(sprite_json["pivot"], tsprite_descs[i].pivot) ) {
|
||||
the<debug>().error("ATLAS: Incorrect formatting of 'pivot' property");
|
||||
return false;
|
||||
}
|
||||
|
||||
E2D_ASSERT(
|
||||
sprite_json.HasMember("texrect") ||
|
||||
(sprite_json.HasMember("inner_texrect") && sprite_json.HasMember("outer_texrect")));
|
||||
@@ -163,7 +154,6 @@ namespace
|
||||
nested_content ncontent;
|
||||
for ( const sprite_desc& desc : sprite_descs ) {
|
||||
sprite spr;
|
||||
spr.set_pivot(desc.pivot);
|
||||
spr.set_inner_texrect(desc.inner_texrect);
|
||||
spr.set_outer_texrect(desc.outer_texrect);
|
||||
spr.set_texture(texture);
|
||||
|
||||
@@ -23,20 +23,18 @@ namespace
|
||||
const char* sprite_asset_schema_source = R"json({
|
||||
"anyOf" : [{
|
||||
"type" : "object",
|
||||
"required" : [ "texture", "pivot", "texrect" ],
|
||||
"required" : [ "texture", "texrect" ],
|
||||
"additionalProperties" : false,
|
||||
"properties" : {
|
||||
"texture" : { "$ref": "#/common_definitions/address" },
|
||||
"pivot" : { "$ref": "#/common_definitions/v2" },
|
||||
"texrect" : { "$ref": "#/common_definitions/b2" }
|
||||
}
|
||||
},{
|
||||
"type" : "object",
|
||||
"required" : [ "texture", "pivot", "inner_texrect", "outer_texrect" ],
|
||||
"required" : [ "texture", "inner_texrect", "outer_texrect" ],
|
||||
"additionalProperties" : false,
|
||||
"properties" : {
|
||||
"texture" : { "$ref": "#/common_definitions/address" },
|
||||
"pivot" : { "$ref": "#/common_definitions/v2" },
|
||||
"inner_texrect" : { "$ref": "#/common_definitions/b2" },
|
||||
"outer_texrect" : { "$ref": "#/common_definitions/b2" }
|
||||
}
|
||||
@@ -70,16 +68,9 @@ namespace
|
||||
auto texture_p = library.load_asset_async<texture_asset>(
|
||||
path::combine(parent_address, root["texture"].GetString()));
|
||||
|
||||
v2f pivot;
|
||||
b2f inner_texrect;
|
||||
b2f outer_texrect;
|
||||
|
||||
E2D_ASSERT(root.HasMember("pivot"));
|
||||
if ( !json_utils::try_parse_value(root["pivot"], pivot) ) {
|
||||
the<debug>().error("SPRITE: Incorrect formatting of 'pivot' property");
|
||||
return stdex::make_rejected_promise<sprite>(sprite_asset_loading_exception());
|
||||
}
|
||||
|
||||
E2D_ASSERT(
|
||||
root.HasMember("texrect") ||
|
||||
(root.HasMember("inner_texrect") && root.HasMember("outer_texrect")));
|
||||
@@ -105,12 +96,10 @@ namespace
|
||||
}
|
||||
|
||||
return texture_p.then([
|
||||
pivot,
|
||||
inner_texrect,
|
||||
outer_texrect
|
||||
](const texture_asset::load_result& texture){
|
||||
sprite content;
|
||||
content.set_pivot(pivot);
|
||||
content.set_inner_texrect(inner_texrect);
|
||||
content.set_outer_texrect(outer_texrect);
|
||||
content.set_texture(texture);
|
||||
|
||||
@@ -245,10 +245,9 @@ namespace e2d
|
||||
|
||||
const b2f& outer_r = spr.outer_texrect();
|
||||
const v2f size = outer_r.size * c->scale();
|
||||
const v2f poff = (outer_r.position - spr.pivot()) * c->scale();
|
||||
|
||||
ctx.draw_wire_rect(
|
||||
poff + size * 0.5f,
|
||||
size * 0.5f,
|
||||
size,
|
||||
ctx.selected() ? color32::yellow() : color32::magenta());
|
||||
}
|
||||
|
||||
@@ -25,7 +25,6 @@ namespace e2d
|
||||
}
|
||||
|
||||
void sprite::clear() noexcept {
|
||||
pivot_ = v2f::zero();
|
||||
inner_texrect_ = b2f::zero();
|
||||
outer_texrect_ = b2f::zero();
|
||||
texture_.reset();
|
||||
@@ -33,7 +32,6 @@ namespace e2d
|
||||
|
||||
void sprite::swap(sprite& other) noexcept {
|
||||
using std::swap;
|
||||
swap(pivot_, other.pivot_);
|
||||
swap(inner_texrect_, other.inner_texrect_);
|
||||
swap(outer_texrect_, other.outer_texrect_);
|
||||
swap(texture_, other.texture_);
|
||||
@@ -50,7 +48,6 @@ namespace e2d
|
||||
sprite& sprite::assign(const sprite& other) {
|
||||
if ( this != &other ) {
|
||||
sprite s;
|
||||
s.pivot_ = other.pivot_;
|
||||
s.inner_texrect_ = other.inner_texrect_;
|
||||
s.outer_texrect_ = other.outer_texrect_;
|
||||
s.texture_ = other.texture_;
|
||||
@@ -59,11 +56,6 @@ namespace e2d
|
||||
return *this;
|
||||
}
|
||||
|
||||
sprite& sprite::set_pivot(const v2f& pivot) noexcept {
|
||||
pivot_ = pivot;
|
||||
return *this;
|
||||
}
|
||||
|
||||
sprite& sprite::set_inner_texrect(const b2f& texrect) noexcept {
|
||||
inner_texrect_ = texrect;
|
||||
return *this;
|
||||
@@ -79,10 +71,6 @@ namespace e2d
|
||||
return *this;
|
||||
}
|
||||
|
||||
const v2f& sprite::pivot() const noexcept {
|
||||
return pivot_;
|
||||
}
|
||||
|
||||
const b2f& sprite::inner_texrect() const noexcept {
|
||||
return inner_texrect_;
|
||||
}
|
||||
@@ -103,8 +91,7 @@ namespace e2d
|
||||
}
|
||||
|
||||
bool operator==(const sprite& l, const sprite& r) noexcept {
|
||||
return l.pivot() == r.pivot()
|
||||
&& l.inner_texrect() == r.inner_texrect()
|
||||
return l.inner_texrect() == r.inner_texrect()
|
||||
&& l.outer_texrect() == r.outer_texrect()
|
||||
&& l.texture() == r.texture();
|
||||
}
|
||||
|
||||
@@ -496,13 +496,12 @@ namespace e2d::render_system_impl
|
||||
const b2f& outer_r = spr.outer_texrect();
|
||||
|
||||
const v2f size = outer_r.size * spr_r.scale();
|
||||
const v2f poff = (outer_r.position - spr.pivot()) * spr_r.scale();
|
||||
|
||||
const v2f pos_xs = v2f{
|
||||
0.f, size.x} + poff.x;
|
||||
0.f, size.x};
|
||||
|
||||
const v2f pos_ys = v2f{
|
||||
0.f, size.y} + poff.y;
|
||||
0.f, size.y};
|
||||
|
||||
const v2f tex_xs = v2f{
|
||||
outer_r.position.x,
|
||||
@@ -550,7 +549,6 @@ namespace e2d::render_system_impl
|
||||
const f32 top = (outer_r.size.y - inner_r.size.y) - bottom;
|
||||
|
||||
const v2f size = outer_r.size * spr_r.scale();
|
||||
const v2f poff = (outer_r.position - spr.pivot()) * spr_r.scale();
|
||||
|
||||
const f32 sides_width = left + right;
|
||||
const f32 sides_height = bottom + top;
|
||||
@@ -569,13 +567,13 @@ namespace e2d::render_system_impl
|
||||
0.f,
|
||||
adj_left,
|
||||
size.x - adj_right,
|
||||
size.x} + poff.x;
|
||||
size.x};
|
||||
|
||||
const v4f pos_ys = v4f{
|
||||
0.f,
|
||||
adj_bottom,
|
||||
size.y - adj_top,
|
||||
size.y} + poff.y;
|
||||
size.y};
|
||||
|
||||
const v4f tex_xs = v4f{
|
||||
outer_r.position.x,
|
||||
|
||||
Reference in New Issue
Block a user