|
|
@@ -1,5 +1,5 @@
|
|
|
//
|
|
|
-// Copyright (c) 2008-2017 the Urho3D project.
|
|
|
+// Copyright (c) 2008-2018 the Urho3D project.
|
|
|
//
|
|
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
// of this software and associated documentation files (the "Software"), to deal
|
|
|
@@ -37,9 +37,9 @@ namespace
|
|
|
{
|
|
|
|
|
|
void checkBorder(int border, float drawSize)
|
|
|
-{ /* not clamping yet, as drawSize may still change and come to accommodate
|
|
|
- large borders */
|
|
|
- if(border < 0 || border * PIXEL_SIZE > drawSize)
|
|
|
+{
|
|
|
+ /* not clamping yet, as drawSize may still change and come to accommodate large borders */
|
|
|
+ if (border < 0 || border * PIXEL_SIZE > drawSize)
|
|
|
URHO3D_LOGWARNINGF("Border out of bounds (%d), may be clamped", border);
|
|
|
}
|
|
|
|
|
|
@@ -47,23 +47,18 @@ Rect calcEffectiveBorder(const IntRect& border, const Vector2& drawSize)
|
|
|
{
|
|
|
Vector2 min{Clamp(border.left_ * PIXEL_SIZE, 0.0f, drawSize.x_),
|
|
|
Clamp(border.bottom_ * PIXEL_SIZE, 0.0f, drawSize.y_)};
|
|
|
- return Rect{
|
|
|
- min,
|
|
|
- {Clamp(border.right_ * PIXEL_SIZE, 0.0f, drawSize.x_ - min.x_),
|
|
|
- Clamp(border.top_ * PIXEL_SIZE, 0.0f, drawSize.y_ - min.y_)} // max
|
|
|
- };
|
|
|
+ return Rect{min, {Clamp(border.right_ * PIXEL_SIZE, 0.0f, drawSize.x_ - min.x_),
|
|
|
+ Clamp(border.top_ * PIXEL_SIZE, 0.0f, drawSize.y_ - min.y_)} /* max*/ };
|
|
|
}
|
|
|
|
|
|
-void prepareXYCoords(float coords[4], float low, float high,
|
|
|
- float lowBorder,
|
|
|
- float highBorder, float scale)
|
|
|
+void prepareXYCoords(float coords[4], float low, float high, float lowBorder, float highBorder, float scale)
|
|
|
{
|
|
|
coords[0] = low * scale;
|
|
|
coords[3] = high * scale;
|
|
|
|
|
|
auto scaleSign = Sign(scale);
|
|
|
auto borderSize = lowBorder + highBorder;
|
|
|
- if(borderSize > scaleSign * (coords[3] - coords[0]))
|
|
|
+ if (borderSize > scaleSign * (coords[3] - coords[0]))
|
|
|
{
|
|
|
auto size = high - low;
|
|
|
coords[1] = coords[2] = scale * (low + (lowBorder * size / borderSize));
|
|
|
@@ -76,9 +71,7 @@ void prepareXYCoords(float coords[4], float low, float high,
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-void prepareUVCoords(float coords[4], float low, float high,
|
|
|
- float lowBorder,
|
|
|
- float highBorder, float drawSize)
|
|
|
+void prepareUVCoords(float coords[4], float low, float high, float lowBorder, float highBorder, float drawSize)
|
|
|
{
|
|
|
coords[0] = low;
|
|
|
coords[1] = low + lowBorder / drawSize;
|
|
|
@@ -86,16 +79,14 @@ void prepareUVCoords(float coords[4], float low, float high,
|
|
|
coords[3] = high;
|
|
|
}
|
|
|
|
|
|
-void prepareVertices(Vertex2D vtx[4][4], const float xs[4], const float ys[4],
|
|
|
- const float us[4], const float vs[4], unsigned color,
|
|
|
- const Vector3& position, const Quaternion& rotation)
|
|
|
+void prepareVertices(Vertex2D vtx[4][4], const float xs[4], const float ys[4], const float us[4], const float vs[4], unsigned color,
|
|
|
+ const Vector3& position, const Quaternion& rotation)
|
|
|
{
|
|
|
- for(unsigned i = 0; i < 4; ++i)
|
|
|
+ for (unsigned i = 0; i < 4; ++i)
|
|
|
{
|
|
|
- for(unsigned j = 0; j < 4; ++j)
|
|
|
+ for (unsigned j = 0; j < 4; ++j)
|
|
|
{
|
|
|
- vtx[i][j].position_ =
|
|
|
- position + rotation * Vector3{xs[i], ys[j], 0.0f};
|
|
|
+ vtx[i][j].position_ = position + rotation * Vector3{xs[i], ys[j], 0.0f};
|
|
|
vtx[i][j].color_ = color;
|
|
|
vtx[i][j].uv_ = Vector2{us[i], vs[j]};
|
|
|
}
|
|
|
@@ -104,20 +95,20 @@ void prepareVertices(Vertex2D vtx[4][4], const float xs[4], const float ys[4],
|
|
|
|
|
|
void pushVertices(Vector<Vertex2D>& target, const Vertex2D source[4][4])
|
|
|
{
|
|
|
- for(unsigned i = 0; i < 3; ++i) // iterate over 3 columns
|
|
|
+ for (unsigned i = 0; i < 3; ++i) // iterate over 3 columns
|
|
|
{
|
|
|
- if(!Equals(source[i][0].position_.x_,
|
|
|
- source[i+1][0].position_.x_)) // if width != 0
|
|
|
+ if (!Equals(source[i][0].position_.x_,
|
|
|
+ source[i + 1][0].position_.x_)) // if width != 0
|
|
|
{
|
|
|
- for(unsigned j = 0; j < 3; ++j) // iterate over 3 lines
|
|
|
+ for (unsigned j = 0; j < 3; ++j) // iterate over 3 lines
|
|
|
{
|
|
|
- if(!Equals(source[0][j].position_.y_,
|
|
|
- source[0][j+1].position_.y_)) // if height != 0
|
|
|
+ if (!Equals(source[0][j].position_.y_,
|
|
|
+ source[0][j + 1].position_.y_)) // if height != 0
|
|
|
{
|
|
|
- target.Push(source[i][j]); // V0 in V1---V2
|
|
|
- target.Push(source[i][j+1]); // V1 in | / |
|
|
|
- target.Push(source[i+1][j+1]); // V2 in | / |
|
|
|
- target.Push(source[i+1][j]); // V3 in V0---V3
|
|
|
+ target.Push(source[i][j]); // V0 in V1---V2
|
|
|
+ target.Push(source[i][j + 1]); // V1 in | / |
|
|
|
+ target.Push(source[i + 1][j + 1]); // V2 in | / |
|
|
|
+ target.Push(source[i + 1][j]); // V3 in V0---V3
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -128,8 +119,8 @@ void pushVertices(Vector<Vertex2D>& target, const Vertex2D source[4][4])
|
|
|
|
|
|
extern const char* URHO2D_CATEGORY;
|
|
|
|
|
|
-StretchableSprite2D::StretchableSprite2D(Context* context)
|
|
|
- : StaticSprite2D{context}
|
|
|
+StretchableSprite2D::StretchableSprite2D(Context* context) :
|
|
|
+ StaticSprite2D{context}
|
|
|
{
|
|
|
}
|
|
|
|
|
|
@@ -138,8 +129,7 @@ void StretchableSprite2D::RegisterObject(Context* context)
|
|
|
context->RegisterFactory<StretchableSprite2D>(URHO2D_CATEGORY);
|
|
|
|
|
|
URHO3D_COPY_BASE_ATTRIBUTES(StaticSprite2D);
|
|
|
- URHO3D_ACCESSOR_ATTRIBUTE("Border", GetBorder, SetBorder, IntRect,
|
|
|
- IntRect::ZERO, AM_DEFAULT);
|
|
|
+ URHO3D_ACCESSOR_ATTRIBUTE("Border", GetBorder, SetBorder, IntRect, IntRect::ZERO, AM_DEFAULT);
|
|
|
}
|
|
|
|
|
|
void StretchableSprite2D::SetBorder(const IntRect& border)
|
|
|
@@ -176,8 +166,7 @@ void StretchableSprite2D::UpdateSourceBatches()
|
|
|
scaled, maintaining their relative size. The same principle applies for
|
|
|
Y scaling (but with lines rather than columns). */
|
|
|
|
|
|
- if(!sourceBatchesDirty_ || !sprite_ || (!useTextureRect_ &&
|
|
|
- !sprite_->GetTextureRectangle(textureRect_, flipX_, flipY_)))
|
|
|
+ if (!sourceBatchesDirty_ || !sprite_ || (!useTextureRect_ && !sprite_->GetTextureRectangle(textureRect_, flipX_, flipY_)))
|
|
|
return;
|
|
|
|
|
|
Vector<Vertex2D>& vertices = sourceBatches_[0].vertices_;
|
|
|
@@ -188,24 +177,16 @@ void StretchableSprite2D::UpdateSourceBatches()
|
|
|
float xs[4], ys[4], us[4], vs[4]; // prepare all coordinates
|
|
|
const auto signedScale = node_->GetSignedWorldScale();
|
|
|
|
|
|
- prepareXYCoords(xs, drawRect_.min_.x_, drawRect_.max_.x_,
|
|
|
- effectiveBorder.min_.x_, effectiveBorder.max_.x_,
|
|
|
- signedScale.x_);
|
|
|
- prepareXYCoords(ys, drawRect_.min_.y_, drawRect_.max_.y_,
|
|
|
- effectiveBorder.min_.y_, effectiveBorder.max_.y_,
|
|
|
- signedScale.y_);
|
|
|
-
|
|
|
- prepareUVCoords(us, textureRect_.min_.x_, textureRect_.max_.x_,
|
|
|
- effectiveBorder.min_.x_, effectiveBorder.max_.x_,
|
|
|
- drawRect_.max_.x_ - drawRect_.min_.x_);
|
|
|
- prepareUVCoords(vs, textureRect_.min_.y_, textureRect_.max_.y_,
|
|
|
- -effectiveBorder.min_.y_,
|
|
|
- -effectiveBorder.max_.y_, // texture y direction inverted
|
|
|
- drawRect_.max_.y_ - drawRect_.min_.y_);
|
|
|
+ prepareXYCoords(xs, drawRect_.min_.x_, drawRect_.max_.x_, effectiveBorder.min_.x_, effectiveBorder.max_.x_, signedScale.x_);
|
|
|
+ prepareXYCoords(ys, drawRect_.min_.y_, drawRect_.max_.y_, effectiveBorder.min_.y_, effectiveBorder.max_.y_, signedScale.y_);
|
|
|
+
|
|
|
+ prepareUVCoords(us, textureRect_.min_.x_, textureRect_.max_.x_, effectiveBorder.min_.x_, effectiveBorder.max_.x_,
|
|
|
+ drawRect_.max_.x_ - drawRect_.min_.x_);
|
|
|
+ prepareUVCoords(vs, textureRect_.min_.y_, textureRect_.max_.y_, -effectiveBorder.min_.y_,
|
|
|
+ -effectiveBorder.max_.y_ /* texture y direction inverted*/, drawRect_.max_.y_ - drawRect_.min_.y_);
|
|
|
|
|
|
Vertex2D vtx[4][4]; // prepare all vertices
|
|
|
- prepareVertices(vtx, xs, ys, us, vs, color_.ToUInt(),
|
|
|
- node_->GetWorldPosition(), node_->GetWorldRotation());
|
|
|
+ prepareVertices(vtx, xs, ys, us, vs, color_.ToUInt(), node_->GetWorldPosition(), node_->GetWorldRotation());
|
|
|
|
|
|
pushVertices(vertices, vtx); // push the vertices that make up each patch
|
|
|
|