~loic.molinari/ubuntu-ui-toolkit/ubuntu-ui-toolkit-dynamic-shapes-for-new-design

« back to all changes in this revision

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

  • Committer: Loïc Molinari
  • Date: 2016-03-08 18:27:03 UTC
  • Revision ID: loic.molinari@canonical.com-20160308182703-4el3my4ayi8ra1o8
Cleaned up inner frame's zero radius case.

Show diffs side-by-side

added added

removed removed

Lines of Context:
191
191
 
192
192
static quint8* renderShape(int radius, UCFrame::Shape shape)
193
193
{
194
 
    DASSERT(radius >= 0);
 
194
    DASSERT(radius > 0);
195
195
 
196
196
    const int border = 1;  // 1 pixel border around the edges for clamping reasons.
197
197
    const int width = getStride(radius + 2 * border, 1, textureStride);
244
244
void UCFrameCornerMaterial::updateTexture(
245
245
    int index, UCFrame::Shape shape, int radius, UCFrame::Shape newShape, int newRadius)
246
246
{
247
 
    DASSERT(newRadius > 0);
 
247
    DASSERT(newRadius >= 0);
248
248
 
249
249
    QOpenGLFunctions* funcs = QOpenGLContext::currentContext()->functions();
250
250
    bool isNewTexture = false;
278
278
        }
279
279
    }
280
280
 
281
 
    quint8* buffer = renderShape(newRadius, newShape);
 
281
    // Render the texture in memory.
 
282
    const int border = 1;
 
283
    const int newSize = newRadius + 2 * border;
 
284
    const int newSizeRounded = getStride(newSize, 1, textureStride);
 
285
    quint8* buffer;
 
286
    if (newRadius > 0) {
 
287
        buffer = renderShape(newRadius, newShape);
 
288
    } else {
 
289
        const int bufferSize = newSizeRounded * newSizeRounded;
 
290
        buffer = (quint8*) malloc(bufferSize);
 
291
        memset(buffer, 0, bufferSize);
 
292
    }
282
293
 
283
294
    // Upload texture. The texture size is a multiple of textureStride to allow
284
295
    // GPUs to speed up uploads and optimise storage.
285
296
    funcs->glBindTexture(GL_TEXTURE_2D, m_textureId[index]);
286
 
    const int border = 1;
287
 
    const int newSize = newRadius + 2 * border;
288
 
    const int newSizeRounded = getStride(newSize, 1, textureStride);
289
297
    if (isNewTexture) {
290
298
        funcs->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
291
299
        funcs->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
418
426
    const float outerS2 = outerTextureFactor * (outerRadiusOffset + clampedThickness);
419
427
    const float outerS3 = outerTextureFactor * (outerRadiusOffset + clampedThickness + innerRadius);
420
428
 
421
 
    const float innerRadiusOffset =
422
 
        innerRadius > 0.0f ? innerRadiusRounded - innerRadius - border : -FLT_MAX;
 
429
    const float innerRadiusOffset = innerRadiusRounded - innerRadius - border;
423
430
    const float innerTextureFactor = 1.0f / innerRadiusRounded;
424
431
    const float innerS0 = innerTextureFactor * innerRadiusOffset;
425
432
    const float innerS1 = innerTextureFactor * (innerRadiusOffset + innerRadius);
582
589
    if (m_radius[0] != static_cast<quint8>(outerRadius)) {
583
590
        m_newRadius[0] = static_cast<quint8>(outerRadius);
584
591
    }
585
 
    const quint8 nonNullInnerRadius = qMax(1, static_cast<int>(innerRadius));
586
 
    if (m_radius[1] != nonNullInnerRadius) {
587
 
        m_newRadius[1] = nonNullInnerRadius;
 
592
    if (m_radius[1] != static_cast<quint8>(innerRadius)) {
 
593
        m_newRadius[1] = static_cast<quint8>(innerRadius);
588
594
    }
589
595
}
590
596