18 mGeometryOutdated(false),
24 mCurrentColour(0xFFFFFFFF),
31 inline float len(
float x,
float y)
33 return std::sqrt(x * x + y * y);
38 if (_points.size() < 2)
41 mResultVerticiesPos.clear();
42 mResultVerticiesUV.clear();
43 mLinePoints = _points;
48 finalPoints.reserve(_points.size());
52 finalPoints.push_back(point);
54 for (std::vector<FloatPoint>::const_iterator iter = _points.begin() + 1; iter != _points.end(); ++iter)
58 finalPoints.push_back(*iter);
59 mLineLength +=
len(iter->left - point.
left, iter->top - point.
top);
64 mLinePoints = finalPoints;
66#ifdef MYGUI_NO_POLYGONAL_SKIN_CROPPING
74 if (count > mVertexCount)
77 if (
nullptr != mRenderItem) mRenderItem->
reallockDrawItem(
this, mVertexCount);
101 mGeometryOutdated =
true;
103 if (
nullptr != mNode)
110 mCurrentColour = (mCurrentColour & 0x00FFFFFF) | (alpha & 0xFF000000);
112 if (
nullptr != mNode)
118 mGeometryOutdated =
true;
120 if (
nullptr != mNode)
171 mGeometryOutdated =
true;
186 if (
nullptr != mNode)
202 if (
nullptr != mNode)
208 MYGUI_ASSERT(!mRenderItem,
"mRenderItem must be nullptr");
217 MYGUI_ASSERT(mRenderItem,
"mRenderItem must be not nullptr");
221 mRenderItem =
nullptr;
231 mGeometryOutdated =
true;
237 if (mGeometryOutdated)
242 size_t size = mResultVerticiesPos.size();
244 for (
size_t i = 0; i < size; ++i)
246 verticies[i].
set(mResultVerticiesPos[i].left, mResultVerticiesPos[i].top, vertex_z, mResultVerticiesUV[i].left, mResultVerticiesUV[i].top, mCurrentColour);
256 mCurrentColour = (colour & 0x00FFFFFF) | (mCurrentColour & 0xFF000000);
258 if (
nullptr != mNode)
269 mCurrentTexture = _rect;
271 mGeometryOutdated =
true;
273 if (
nullptr != mNode)
279 if (mLinePoints.size() < 2)
284 mGeometryOutdated =
false;
298 FloatPoint vectorU = baseVerticiesUV[1] - baseVerticiesUV[0];
303 mResultVerticiesPos.clear();
304 mResultVerticiesUV.clear();
308 FloatPoint points[2] = {mLinePoints[0] + normal, mLinePoints[0] - normal};
309 FloatPoint pointsUV[2] = {baseVerticiesUV[0], baseVerticiesUV[3]};
315 float currentLength = 0.0f;
316 for (
size_t i = 1; i < mLinePoints.size(); ++i)
318 if (mLineStroke != 0)
321 if (stroke == mLineStroke)
328 currentLength +=
len(mLinePoints[i - 1].left - mLinePoints[i].left, mLinePoints[i - 1].top - mLinePoints[i].top);
331 if (i != mLinePoints.size() - 1)
332 normal =
_getMiddleLine(mLinePoints[i - 1], mLinePoints[i + 1], mLinePoints[i]);
343 else if (
len(normal.
left, normal.
top) > mLineWidth * 1.5f)
350 FloatPoint lineDir = mLinePoints[i] - mLinePoints[i - 1];
357 FloatPoint UVoffset(currentLength / mLineLength * vectorU.
left, currentLength / mLineLength * vectorU.
top);
361 mResultVerticiesPos.push_back(points[0]);
362 mResultVerticiesPos.push_back(points[1]);
363 mResultVerticiesPos.push_back(mLinePoints[i] + normal);
364 mResultVerticiesUV.push_back(pointsUV[0]);
365 mResultVerticiesUV.push_back(pointsUV[1]);
366 mResultVerticiesUV.push_back(baseVerticiesUV[0] + UVoffset);
368 mResultVerticiesPos.push_back(points[1]);
369 mResultVerticiesPos.push_back(mLinePoints[i] - normal);
370 mResultVerticiesPos.push_back(mLinePoints[i] + normal);
371 mResultVerticiesUV.push_back(pointsUV[1]);
372 mResultVerticiesUV.push_back(baseVerticiesUV[3] + UVoffset);
373 mResultVerticiesUV.push_back(baseVerticiesUV[0] + UVoffset);
376 points[edge ? 1 : 0] = mLinePoints[i] + normal;
377 points[edge ? 0 : 1] = mLinePoints[i] - normal;
378 pointsUV[0] = baseVerticiesUV[0] + UVoffset;
379 pointsUV[1] = baseVerticiesUV[3] + UVoffset;
383 normal =
_getMiddleLine(mLinePoints[i - 1], mLinePoints[i + 1], mLinePoints[i]);
385 float sharpness =
len(normal.left, normal.top) / mLineWidth;
387 float length =
len(normal.left, normal.top);
388 normal.left *= 2 * mLineWidth / length / (sharpness - 0.5f);
389 normal.top *= 2 * mLineWidth / length / (sharpness - 0.5f);
392 lineDir = mLinePoints[i] - mLinePoints[i - 1];
393 if (lineDir.
left * normal.top - lineDir.
top * normal.left < 0)
395 normal.
left = -normal.left;
396 normal.top = -normal.top;
398 FloatPoint lineDir1 = mLinePoints[i] - mLinePoints[i - 1];
399 FloatPoint lineDir2 = mLinePoints[i + 1] - mLinePoints[i];
400 if (lineDir1.
left * lineDir2.
top - lineDir1.
top * lineDir2.
left > 0)
402 normal.
left = -normal.left;
403 normal.top = -normal.top;
408 lineDir = mLinePoints[i - 1] - mLinePoints[i];
412 normal2.
top = -normal2.
top;
415 FloatPoint UVcenter((baseVerticiesUV[0].left + baseVerticiesUV[3].left) / 2, (baseVerticiesUV[0].top + baseVerticiesUV[3].top) / 2);
419 mResultVerticiesPos.push_back(points[0]);
420 mResultVerticiesPos.push_back(mLinePoints[i] + normal);
421 mResultVerticiesPos.push_back(mLinePoints[i]);
422 mResultVerticiesUV.push_back(pointsUV[0]);
423 mResultVerticiesUV.push_back(baseVerticiesUV[0] + UVoffset);
424 mResultVerticiesUV.push_back(UVcenter + UVoffset);
426 mResultVerticiesPos.push_back(mLinePoints[i] + normal);
427 mResultVerticiesPos.push_back(mLinePoints[i] + normal2);
428 mResultVerticiesPos.push_back(mLinePoints[i]);
429 mResultVerticiesUV.push_back(baseVerticiesUV[0] + UVoffset);
430 mResultVerticiesUV.push_back(baseVerticiesUV[0] + UVoffset);
431 mResultVerticiesUV.push_back(UVcenter + UVoffset);
434 points[0] = mLinePoints[i] + normal2;
435 points[1] = mLinePoints[i] - normal2;
436 pointsUV[0] = baseVerticiesUV[0] + UVoffset;
437 pointsUV[1] = baseVerticiesUV[3] + UVoffset;
442#ifndef MYGUI_NO_POLYGONAL_SKIN_CROPPING
453 newResultVerticiesPos.reserve(mResultVerticiesPos.size());
454 newResultVerticiesUV.reserve(mResultVerticiesPos.size());
455 for (
size_t i = 0; i < mResultVerticiesPos.size(); i += 3)
459 if (!croppedTriangle.empty())
461 FloatPoint v0 = mResultVerticiesUV[i + 2] - mResultVerticiesUV[i];
462 FloatPoint v1 = mResultVerticiesUV[i + 1] - mResultVerticiesUV[i];
464 for (
size_t j = 1; j < croppedTriangle.size() - 1; ++j)
466 newResultVerticiesPos.push_back(croppedTriangle[0]);
467 newResultVerticiesPos.push_back(croppedTriangle[j]);
468 newResultVerticiesPos.push_back(croppedTriangle[j + 1]);
481 std::swap(mResultVerticiesPos, newResultVerticiesPos);
482 std::swap(mResultVerticiesUV, newResultVerticiesUV);
491 for (
size_t i = 0; i < mResultVerticiesPos.size(); ++i)
493 mResultVerticiesPos[i].left = vertex_left_base + mResultVerticiesPos[i].left * info.
pixScaleX * 2;
494 mResultVerticiesPos[i].top = vertex_top_base + mResultVerticiesPos[i].top * info.
pixScaleY * -2;
504 result.
left /= length;
505 result.
top /= length;
506 result.
left *= mLineWidth / 2;
507 result.
top *= mLineWidth / 2;
517 line1.
left /= length;
520 line2.
left /= length;
529 result.
left /= length;
530 result.
top /= length;
533 float angle = std::acos(cos);
536 if (std::fabs(angle) < 1e-6f )
539 float width = mLineWidth / 2 / std::sin(angle);
540 result.
left *= width;
#define MYGUI_ASSERT(exp, dest)
int getAbsoluteLeft() const
bool _checkOutside() const
ICroppedRectangle * mCroppedParent
int getAbsoluteTop() const
int _getViewWidth() const
int _getViewHeight() const
virtual float getNodeDepth() const =0
virtual void outOfDate(RenderItem *_item)=0
virtual RenderItem * addToRenderItem(ITexture *_texture, bool _firstQueue, bool _separate)=0
Type * castType(bool _throw=true)
virtual const RenderTargetInfo & getInfo() const =0
FloatPoint _getMiddleLine(const FloatPoint &_point1, const FloatPoint &_point2, const FloatPoint &_point3) const
void _correctView() override
void destroyDrawItem() override
void createDrawItem(ITexture *_texture, ILayerNode *_node) override
void _setAlign(const IntSize &_oldsize) override
FloatPoint _getPerpendicular(const FloatPoint &_point1, const FloatPoint &_point2) const
void setPoints(const std::vector< FloatPoint > &_points)
void setStateData(IStateInfo *_data) override
void setVisible(bool _visible) override
void setAlpha(float _alpha) override
void _setUVSet(const FloatRect &_rect) override
void setWidth(float _width)
void _updateView() override
void _setColour(const Colour &_value) override
void setStroke(size_t _value)
void addDrawItem(ISubWidget *_item, size_t _count)
bool getCurrentUpdate() const
IRenderTarget * getRenderTarget()
void reallockDrawItem(ISubWidget *_item, size_t _count)
void removeDrawItem(ISubWidget *_item)
Vertex * getCurrentVertexBuffer() const
void setLastVertexCount(size_t _count)
virtual VertexColourType getVertexFormat() const =0
static RenderManager & getInstance()
const FloatRect & getRect() const
FloatPoint getUVFromPositionInsideRect(const FloatPoint &_point, const FloatPoint &_v0, const FloatPoint &_v1, const FloatPoint &_baseUV)
FloatPoint getPositionInsideRect(const FloatPoint &_point, const FloatPoint &_corner0, const FloatPoint &_corner1, const FloatPoint &_corner2)
VectorFloatPoint cropPolygon(FloatPoint *_baseVerticiesPos, size_t _size, const IntCoord &_cropRectangle)
void convertColour(uint32 &_colour, VertexColourType _format)
uint32 toColourARGB(const Colour &_colour)
std::vector< FloatPoint > VectorFloatPoint
types::TPoint< float > FloatPoint
float len(float x, float y)
void set(float _x, float _y, float _z, float _u, float _v, uint32 _colour)