18 mGeometryOutdated(false),
24 mCurrentColour(0xFFFFFFFF),
35 inline float len(
float x,
float y)
37 return sqrt(x * x + y * y);
42 if (_points.size() < 2)
45 mResultVerticiesPos.clear();
46 mResultVerticiesUV.clear();
47 mLinePoints = _points;
52 finalPoints.reserve(_points.size());
56 finalPoints.push_back(point);
58 for (std::vector<FloatPoint>::const_iterator iter = _points.begin() + 1; iter != _points.end(); ++iter)
62 finalPoints.push_back(*iter);
63 mLineLength +=
len(iter->left - point.
left, iter->top - point.
top);
68 mLinePoints = finalPoints;
70 #ifdef MYGUI_NO_POLYGONAL_SKIN_CROPPING
78 if (count > mVertexCount)
81 if (
nullptr != mRenderItem) mRenderItem->
reallockDrawItem(
this, mVertexCount);
105 mGeometryOutdated =
true;
107 if (
nullptr != mNode)
114 mCurrentColour = (mCurrentColour & 0x00FFFFFF) | (alpha & 0xFF000000);
116 if (
nullptr != mNode)
122 mGeometryOutdated =
true;
124 if (
nullptr != mNode)
131 bool need_update =
true;
187 mGeometryOutdated =
true;
202 if (
nullptr != mNode)
218 if (
nullptr != mNode)
224 MYGUI_ASSERT(!mRenderItem,
"mRenderItem must be nullptr");
233 MYGUI_ASSERT(mRenderItem,
"mRenderItem must be not nullptr");
237 mRenderItem =
nullptr;
247 mGeometryOutdated =
true;
253 if (mGeometryOutdated)
258 size_t size = mResultVerticiesPos.size();
260 for (
size_t i = 0; i < size; ++i)
262 verticies[i].
set(mResultVerticiesPos[i].left, mResultVerticiesPos[i].top, vertex_z, mResultVerticiesUV[i].left, mResultVerticiesUV[i].top, mCurrentColour);
272 mCurrentColour = (colour & 0x00FFFFFF) | (mCurrentColour & 0xFF000000);
274 if (
nullptr != mNode)
285 mCurrentTexture = _rect;
287 mGeometryOutdated =
true;
289 if (
nullptr != mNode)
295 if (mLinePoints.size() < 2)
300 mGeometryOutdated =
false;
314 FloatPoint vectorU = baseVerticiesUV[1] - baseVerticiesUV[0];
315 FloatPoint vectorV = baseVerticiesUV[3] - baseVerticiesUV[0];
319 mResultVerticiesPos.clear();
320 mResultVerticiesUV.clear();
324 FloatPoint points[2] = {mLinePoints[0] + normal, mLinePoints[0] - normal};
325 FloatPoint pointsUV[2] = {baseVerticiesUV[0], baseVerticiesUV[3]};
331 float currentLength = 0.0f;
332 for (
size_t i = 1; i < mLinePoints.size(); ++i)
334 if (mLineStroke != 0)
337 if (stroke == mLineStroke)
344 currentLength +=
len(mLinePoints[i - 1].left - mLinePoints[i].left, mLinePoints[i - 1].top - mLinePoints[i].top);
347 if (i != mLinePoints.size() - 1)
348 normal =
_getMiddleLine(mLinePoints[i - 1], mLinePoints[i + 1], mLinePoints[i]);
359 else if (
len(normal.
left, normal.
top) > mLineWidth * 1.5)
366 FloatPoint lineDir = mLinePoints[i] - mLinePoints[i - 1];
373 FloatPoint UVoffset(currentLength / mLineLength * vectorU.
left, currentLength / mLineLength * vectorU.
top);
377 mResultVerticiesPos.push_back(points[0]);
378 mResultVerticiesPos.push_back(points[1]);
379 mResultVerticiesPos.push_back(mLinePoints[i] + normal);
380 mResultVerticiesUV.push_back(pointsUV[0]);
381 mResultVerticiesUV.push_back(pointsUV[1]);
382 mResultVerticiesUV.push_back(baseVerticiesUV[0] + UVoffset);
384 mResultVerticiesPos.push_back(points[1]);
385 mResultVerticiesPos.push_back(mLinePoints[i] - normal);
386 mResultVerticiesPos.push_back(mLinePoints[i] + normal);
387 mResultVerticiesUV.push_back(pointsUV[1]);
388 mResultVerticiesUV.push_back(baseVerticiesUV[3] + UVoffset);
389 mResultVerticiesUV.push_back(baseVerticiesUV[0] + UVoffset);
392 points[edge ? 1 : 0] = mLinePoints[i] + normal;
393 points[edge ? 0 : 1] = mLinePoints[i] - normal;
394 pointsUV[0] = baseVerticiesUV[0] + UVoffset;
395 pointsUV[1] = baseVerticiesUV[3] + UVoffset;
399 normal =
_getMiddleLine(mLinePoints[i - 1], mLinePoints[i + 1], mLinePoints[i]);
401 float sharpness =
len(normal.left, normal.top) / mLineWidth;
403 float length =
len(normal.left, normal.top);
404 normal.left *= 2 * mLineWidth / length / (sharpness - 0.5f);
405 normal.top *= 2 * mLineWidth / length / (sharpness - 0.5f);
408 lineDir = mLinePoints[i] - mLinePoints[i - 1];
409 if (lineDir.
left * normal.top - lineDir.
top * normal.left < 0)
411 normal.
left = -normal.left;
412 normal.top = -normal.top;
414 FloatPoint lineDir1 = mLinePoints[i] - mLinePoints[i - 1];
415 FloatPoint lineDir2 = mLinePoints[i + 1] - mLinePoints[i];
416 if (lineDir1.
left * lineDir2.
top - lineDir1.
top * lineDir2.
left > 0)
418 normal.
left = -normal.left;
419 normal.top = -normal.top;
424 lineDir = mLinePoints[i - 1] - mLinePoints[i];
428 normal2.
top = -normal2.
top;
431 FloatPoint UVcenter((baseVerticiesUV[0].left + baseVerticiesUV[3].left) / 2, (baseVerticiesUV[0].top + baseVerticiesUV[3].top) / 2);
435 mResultVerticiesPos.push_back(points[0]);
436 mResultVerticiesPos.push_back(mLinePoints[i] + normal);
437 mResultVerticiesPos.push_back(mLinePoints[i]);
438 mResultVerticiesUV.push_back(pointsUV[0]);
439 mResultVerticiesUV.push_back(baseVerticiesUV[0] + UVoffset);
440 mResultVerticiesUV.push_back(UVcenter + UVoffset);
442 mResultVerticiesPos.push_back(mLinePoints[i] + normal);
443 mResultVerticiesPos.push_back(mLinePoints[i] + normal2);
444 mResultVerticiesPos.push_back(mLinePoints[i]);
445 mResultVerticiesUV.push_back(baseVerticiesUV[0] + UVoffset);
446 mResultVerticiesUV.push_back(baseVerticiesUV[0] + UVoffset);
447 mResultVerticiesUV.push_back(UVcenter + UVoffset);
450 points[0] = mLinePoints[i] + normal2;
451 points[1] = mLinePoints[i] - normal2;
452 pointsUV[0] = baseVerticiesUV[0] + UVoffset;
453 pointsUV[1] = baseVerticiesUV[3] + UVoffset;
458 #ifndef MYGUI_NO_POLYGONAL_SKIN_CROPPING
469 newResultVerticiesPos.reserve(mResultVerticiesPos.size());
470 newResultVerticiesUV.reserve(mResultVerticiesPos.size());
471 for (
size_t i = 0; i < mResultVerticiesPos.size(); i += 3)
475 if (!croppedTriangle.empty())
477 FloatPoint v0 = mResultVerticiesUV[i + 2] - mResultVerticiesUV[i];
478 FloatPoint v1 = mResultVerticiesUV[i + 1] - mResultVerticiesUV[i];
480 for (
size_t j = 1; j < croppedTriangle.size() - 1; ++j)
482 newResultVerticiesPos.push_back(croppedTriangle[0]);
483 newResultVerticiesPos.push_back(croppedTriangle[j]);
484 newResultVerticiesPos.push_back(croppedTriangle[j + 1]);
497 std::swap(mResultVerticiesPos, newResultVerticiesPos);
498 std::swap(mResultVerticiesUV, newResultVerticiesUV);
507 for (
size_t i = 0; i < mResultVerticiesPos.size(); ++i)
509 mResultVerticiesPos[i].left = vertex_left_base + mResultVerticiesPos[i].left * info.
pixScaleX * 2;
510 mResultVerticiesPos[i].top = vertex_top_base + mResultVerticiesPos[i].top * info.
pixScaleY * -2;
520 result.
left /= length;
521 result.
top /= length;
522 result.
left *= mLineWidth / 2;
523 result.
top *= mLineWidth / 2;
533 line1.
left /= length;
536 line2.
left /= length;
545 result.
left /= length;
546 result.
top /= length;
549 float angle = acos(cos);
552 if (fabs(angle) < 1e-6 )
555 float width = mLineWidth / 2 / sin(angle);
556 result.
left *= width;