22
22
#include <QtGui/QOpenGLFunctions>
24
24
const QRgb defaultColor = qRgba(255, 255, 255, 255);
25
const float defaultWeight = 20.0f;
25
const float defaultThickness = 20.0f;
26
26
const float defaultRadius = 50.0f;
239
239
void UCFrameNode::updateGeometry(
240
const QSizeF& itemSize, float weight, float radius, QRgb color)
240
const QSizeF& itemSize, float thickness, float radius, QRgb color)
242
242
UCFrameNode::Vertex* v = reinterpret_cast<UCFrameNode::Vertex*>(m_geometry.vertexData());
243
243
const float w = static_cast<float>(itemSize.width());
244
244
const float h = static_cast<float>(itemSize.height());
245
245
const float maxSize = qMin(w, h) * 0.5f;
246
const float clampedWeight = qMin(weight, maxSize);
246
const float clampedThickness = qMin(thickness, maxSize);
247
247
const float radiusOut = qBound(0.01f, radius, maxSize);
248
const float radiusIn = radiusOut * ((maxSize - clampedWeight) / maxSize);
248
const float radiusIn = radiusOut * ((maxSize - clampedThickness) / maxSize);
249
249
const float tc1 =
250
(((1.0f - shapeOffset) / radiusOut) * (clampedWeight + radiusIn)) + shapeOffset;
251
const float tc2 = (((1.0f - shapeOffset) / radiusOut) * clampedWeight) + shapeOffset;
252
const float tc3 = (((1.0f - shapeOffset) / radiusIn) * -clampedWeight) + shapeOffset;
250
(((1.0f - shapeOffset) / radiusOut) * (clampedThickness + radiusIn)) + shapeOffset;
251
const float tc2 = (((1.0f - shapeOffset) / radiusOut) * clampedThickness) + shapeOffset;
252
const float tc3 = (((1.0f - shapeOffset) / radiusIn) * -clampedThickness) + shapeOffset;
253
253
const float tc4 =
254
(((1.0f - shapeOffset) / radiusIn) * (radiusOut - clampedWeight)) + shapeOffset;
254
(((1.0f - shapeOffset) / radiusIn) * (radiusOut - clampedThickness)) + shapeOffset;
255
255
const quint32 packedColor = packColor(color);
285
285
v[3].color = packedColor;
288
v[4].x = clampedWeight + radiusIn;
289
v[4].y = clampedWeight;
288
v[4].x = clampedThickness + radiusIn;
289
v[4].y = clampedThickness;
293
293
v[4].t2 = shapeOffset;
294
294
v[4].color = packedColor;
295
v[5].x = w - (clampedWeight + radiusIn);
296
v[5].y = clampedWeight;
295
v[5].x = w - (clampedThickness + radiusIn);
296
v[5].y = clampedThickness;
310
310
v[6].color = packedColor;
311
v[7].x = clampedWeight;
312
v[7].y = clampedWeight + radiusIn;
311
v[7].x = clampedThickness;
312
v[7].y = clampedThickness + radiusIn;
315
315
v[7].s2 = shapeOffset;
317
317
v[7].color = packedColor;
318
v[8].x = w - clampedWeight;
319
v[8].y = clampedWeight + radiusIn;
318
v[8].x = w - clampedThickness;
319
v[8].y = clampedThickness + radiusIn;
322
322
v[8].s2 = shapeOffset;
340
340
v[10].color = packedColor;
341
v[11].x = clampedWeight;
342
v[11].y = h - (clampedWeight + radiusIn);
341
v[11].x = clampedThickness;
342
v[11].y = h - (clampedThickness + radiusIn);
345
345
v[11].s2 = shapeOffset;
347
347
v[11].color = packedColor;
348
v[12].x = w - clampedWeight;
349
v[12].y = h - (clampedWeight + radiusIn);
348
v[12].x = w - clampedThickness;
349
v[12].y = h - (clampedThickness + radiusIn);
352
352
v[12].s2 = shapeOffset;
361
361
v[13].color = packedColor;
364
v[14].x = clampedWeight + radiusIn;
365
v[14].y = h - clampedWeight;
364
v[14].x = clampedThickness + radiusIn;
365
v[14].y = h - clampedThickness;
369
369
v[14].t2 = shapeOffset;
370
370
v[14].color = packedColor;
371
v[15].x = w - (clampedWeight + radiusIn);
372
v[15].y = h - clampedWeight;
371
v[15].x = w - (clampedThickness + radiusIn);
372
v[15].y = h - clampedThickness;
414
414
UCFrame::UCFrame(QQuickItem* parent)
415
415
: QQuickItem(parent)
416
416
, m_color(defaultColor)
417
, m_weight(defaultWeight)
417
, m_thickness(defaultThickness)
418
418
, m_radius(defaultRadius)
420
420
setFlag(ItemHasContents);
423
void UCFrame::setWeight(qreal weight)
423
void UCFrame::setThickness(qreal thickness)
425
weight = qMax(0.0f, static_cast<float>(weight));
426
if (m_weight != weight) {
425
thickness = qMax(0.0f, static_cast<float>(thickness));
426
if (m_thickness != thickness) {
427
m_thickness = thickness;
429
Q_EMIT weightChanged();
429
Q_EMIT thicknessChanged();
457
457
const QSizeF itemSize(width(), height());
458
if (itemSize.isEmpty() || m_weight <= 0.0f) {
458
if (itemSize.isEmpty() || m_thickness <= 0.0f) {
463
463
UCFrameNode* node = oldNode ? static_cast<UCFrameNode*>(oldNode) : new UCFrameNode();
464
node->updateGeometry(itemSize, m_weight, m_radius, m_color);
464
node->updateGeometry(itemSize, m_thickness, m_radius, m_color);