~loic.molinari/ubuntu-ui-toolkit/ubuntu-ui-toolkit-private-shapes

« back to all changes in this revision

Viewing changes to src/Ubuntu/Components/plugin/privates/frame.cpp

  • Committer: Loïc Molinari
  • Date: 2016-01-12 22:16:02 UTC
  • Revision ID: loic.molinari@canonical.com-20160112221602-m8ghic22otrksv4v
Renamed weight property to thickness.

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
#include <QtGui/QOpenGLFunctions>
23
23
 
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;
27
27
 
28
28
// --- Shader ---
237
237
}
238
238
 
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)
241
241
{
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);
256
256
 
257
257
    // 1st row.
285
285
    v[3].color = packedColor;
286
286
 
287
287
    // 2nd row.
288
 
    v[4].x = clampedWeight + radiusIn;
289
 
    v[4].y = clampedWeight;
 
288
    v[4].x = clampedThickness + radiusIn;
 
289
    v[4].y = clampedThickness;
290
290
    v[4].s1 = tc1;
291
291
    v[4].t1 = tc2;
292
292
    v[4].s2 = 1.0f;
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;
297
297
    v[5].s1 = tc1;
298
298
    v[5].t1 = tc2;
299
299
    v[5].s2 = 1.0f;
308
308
    v[6].s2 = tc3;
309
309
    v[6].t2 = tc4;
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;
313
313
    v[7].s1 = tc2;
314
314
    v[7].t1 = tc1;
315
315
    v[7].s2 = shapeOffset;
316
316
    v[7].t2 = 1.0f;
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;
320
320
    v[8].s1 = tc2;
321
321
    v[8].t1 = tc1;
322
322
    v[8].s2 = shapeOffset;
338
338
    v[10].s2 = tc3;
339
339
    v[10].t2 = tc4;
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);
343
343
    v[11].s1 = tc2;
344
344
    v[11].t1 = tc1;
345
345
    v[11].s2 = shapeOffset;
346
346
    v[11].t2 = 1.0f;
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);
350
350
    v[12].s1 = tc2;
351
351
    v[12].t1 = tc1;
352
352
    v[12].s2 = shapeOffset;
361
361
    v[13].color = packedColor;
362
362
 
363
363
    // 5th row.
364
 
    v[14].x = clampedWeight + radiusIn;
365
 
    v[14].y = h - clampedWeight;
 
364
    v[14].x = clampedThickness + radiusIn;
 
365
    v[14].y = h - clampedThickness;
366
366
    v[14].s1 = tc1;
367
367
    v[14].t1 = tc2;
368
368
    v[14].s2 = 1.0f;
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;
373
373
    v[15].s1 = tc1;
374
374
    v[15].t1 = tc2;
375
375
    v[15].s2 = 1.0f;
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)
419
419
{
420
420
    setFlag(ItemHasContents);
421
421
}
422
422
 
423
 
void UCFrame::setWeight(qreal weight)
 
423
void UCFrame::setThickness(qreal thickness)
424
424
{
425
 
    weight = qMax(0.0f, static_cast<float>(weight));
426
 
    if (m_weight != weight) {
427
 
        m_weight = weight;
 
425
    thickness = qMax(0.0f, static_cast<float>(thickness));
 
426
    if (m_thickness != thickness) {
 
427
        m_thickness = thickness;
428
428
        update();
429
 
        Q_EMIT weightChanged();
 
429
        Q_EMIT thicknessChanged();
430
430
    }
431
431
}
432
432
 
455
455
    Q_UNUSED(data);
456
456
 
457
457
    const QSizeF itemSize(width(), height());
458
 
    if (itemSize.isEmpty() || m_weight <= 0.0f) {
 
458
    if (itemSize.isEmpty() || m_thickness <= 0.0f) {
459
459
        delete oldNode;
460
460
        return NULL;
461
461
    }
462
462
 
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);
465
465
 
466
466
    return node;
467
467
}