Subversion Repositories tpanel

Rev

Rev 400 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 400 Rev 401
Line 5378... Line 5378...
5378
 
5378
 
5379
    int instance = inst;
5379
    int instance = inst;
5380
 
5380
 
5381
    if (instance < 0)
5381
    if (instance < 0)
5382
        instance = 0;
5382
        instance = 0;
5383
    else if ((size_t)instance > sr.size())
5383
    else if (static_cast<size_t>(instance) > sr.size())
5384
        instance = (int)sr.size() - 1;
5384
        instance = static_cast<int>(sr.size()) - 1;
5385
 
5385
 
5386
    if (sr[instance].bs.empty())
5386
    if (sr[instance].bs.empty())
5387
    {
5387
    {
5388
        MSG_DEBUG("No border defined.");
5388
        MSG_DEBUG("No border defined.");
5389
        return true;
5389
        return true;
Line 5397... Line 5397...
5397
    // The border was not found or defined to be not drawn. Therefor we look
5397
    // The border was not found or defined to be not drawn. Therefor we look
5398
    // into the system directory (__system/graphics/borders). If the wanted
5398
    // into the system directory (__system/graphics/borders). If the wanted
5399
    // border exists there, we're drawing it.
5399
    // border exists there, we're drawing it.
5400
    BORDER_t bd, bda;
5400
    BORDER_t bd, bda;
5401
    int numBorders = 0;
5401
    int numBorders = 0;
5402
    bool extBorder = false;
-
 
5403
 
5402
 
5404
    if (sr.size() == 2)
5403
    if (sr.size() == 2)
5405
    {
5404
    {
5406
        if (gPageManager->getSystemDraw()->getBorder(bname, TSystemDraw::LT_OFF, &bd))
5405
        if (gPageManager->getSystemDraw()->getBorder(bname, TSystemDraw::LT_OFF, &bd))
5407
            numBorders++;
5406
            numBorders++;
-
 
5407
 
-
 
5408
        if (gPageManager->getSystemDraw()->getBorder(bname, TSystemDraw::LT_ON, &bda))
-
 
5409
            numBorders++;
5408
    }
5410
    }
5409
    else if (gPageManager->getSystemDraw()->getBorder(bname, TSystemDraw::LT_ON, &bd))
5411
    else if (gPageManager->getSystemDraw()->getBorder(bname, TSystemDraw::LT_ON, &bd))
5410
        numBorders++;
5412
        numBorders++;
5411
 
5413
 
5412
    if (numBorders)
5414
    if (numBorders > 0)
5413
        extBorder = true;
-
 
5414
 
-
 
5415
    if (extBorder)
-
 
5416
    {
5415
    {
5417
        SkColor color = TColor::getSkiaColor(sr[instance].cb);      // border color
5416
        SkColor color = TColor::getSkiaColor(sr[instance].cb);      // border color
5418
        MSG_DEBUG("Button color: #" << std::setw(6) << std::setfill('0') << std::hex << color);
5417
        MSG_DEBUG("Button color: #" << std::setw(6) << std::setfill('0') << std::hex << color);
5419
        // Load images
5418
        // Load images
5420
        SkBitmap imgB, imgBR, imgR, imgTR, imgT, imgTL, imgL, imgBL;
5419
        SkBitmap imgB, imgBR, imgR, imgTR, imgT, imgTL, imgL, imgBL;
5421
 
5420
 
5422
        if (!retrieveImage(bd.b, &imgB) || imgB.empty())
5421
        if (!retrieveImage(bd.b, bda.b, &imgB) || imgB.empty())
5423
            return false;
5422
            return false;
5424
 
5423
 
5425
        MSG_DEBUG("Got images " << bd.b << " and " << bda.b << " with size " << imgB.info().width() << " x " << imgB.info().height());
5424
        MSG_DEBUG("Got images " << bd.b << " and " << bda.b << " with size " << imgB.info().width() << " x " << imgB.info().height());
5426
        if (!retrieveImage(bd.br, &imgBR) || imgBR.empty())
5425
        if (!retrieveImage(bd.br, bda.br, &imgBR) || imgBR.empty())
5427
            return false;
5426
            return false;
5428
 
5427
 
5429
        MSG_DEBUG("Got images " << bd.br << " and " << bda.br << " with size " << imgBR.info().width() << " x " << imgBR.info().height());
5428
        MSG_DEBUG("Got images " << bd.br << " and " << bda.br << " with size " << imgBR.info().width() << " x " << imgBR.info().height());
5430
        if (!retrieveImage(bd.r, &imgR) || imgR.empty())
5429
        if (!retrieveImage(bd.r, bda.r, &imgR) || imgR.empty())
5431
            return false;
5430
            return false;
5432
 
5431
 
5433
        MSG_DEBUG("Got images " << bd.r << " and " << bda.r << " with size " << imgR.info().width() << " x " << imgR.info().height());
5432
        MSG_DEBUG("Got images " << bd.r << " and " << bda.r << " with size " << imgR.info().width() << " x " << imgR.info().height());
5434
        if (!retrieveImage(bd.tr, &imgTR) || imgTR.empty())
5433
        if (!retrieveImage(bd.tr, bda.tr, &imgTR) || imgTR.empty())
5435
            return false;
5434
            return false;
5436
 
5435
 
5437
        MSG_DEBUG("Got images " << bd.tr << " and " << bda.tr << " with size " << imgTR.info().width() << " x " << imgTR.info().height());
5436
        MSG_DEBUG("Got images " << bd.tr << " and " << bda.tr << " with size " << imgTR.info().width() << " x " << imgTR.info().height());
5438
        if (!retrieveImage(bd.t, &imgT) || imgT.empty())
5437
        if (!retrieveImage(bd.t, bda.t, &imgT) || imgT.empty())
5439
            return false;
5438
            return false;
5440
 
5439
 
5441
        MSG_DEBUG("Got images " << bd.t << " and " << bda.t << " with size " << imgT.info().width() << " x " << imgT.info().height());
5440
        MSG_DEBUG("Got images " << bd.t << " and " << bda.t << " with size " << imgT.info().width() << " x " << imgT.info().height());
5442
        if (!retrieveImage(bd.tl, &imgTL) || imgTL.empty())
5441
        if (!retrieveImage(bd.tl, bda.tl, &imgTL) || imgTL.empty())
5443
            return false;
5442
            return false;
5444
 
5443
 
5445
        MSG_DEBUG("Got images " << bd.tl << " and " << bda.tl << " with size " << imgTL.info().width() << " x " << imgTL.info().height());
5444
        MSG_DEBUG("Got images " << bd.tl << " and " << bda.tl << " with size " << imgTL.info().width() << " x " << imgTL.info().height());
5446
        if (!retrieveImage(bd.l, &imgL) || imgL.empty())
5445
        if (!retrieveImage(bd.l, bda.l, &imgL) || imgL.empty())
5447
            return false;
5446
            return false;
5448
 
5447
 
5449
        mBorderWidth = imgL.info().width();
5448
        mBorderWidth = imgL.info().width();
5450
 
-
 
5451
        MSG_DEBUG("Got images " << bd.l << " and " << bda.l << " with size " << imgL.info().width() << " x " << imgL.info().height());
5449
        MSG_DEBUG("Got images " << bd.l << " and " << bda.l << " with size " << imgL.info().width() << " x " << imgL.info().height());
-
 
5450
 
5452
        if (!retrieveImage(bd.bl, &imgBL) || imgBL.empty())
5451
        if (!retrieveImage(bd.bl, bda.bl, &imgBL) || imgBL.empty())
5453
            return false;
5452
            return false;
5454
 
5453
 
5455
        MSG_DEBUG("Got images " << bd.bl << " and " << bda.bl << " with size " << imgBL.info().width() << " x " << imgBL.info().height());
5454
        MSG_DEBUG("Got images " << bd.bl << " and " << bda.bl << " with size " << imgBL.info().width() << " x " << imgBL.info().height());
5456
        MSG_DEBUG("Button image size: " << (imgTL.info().width() + imgT.info().width() + imgTR.info().width()) << " x " << (imgTL.info().height() + imgL.info().height() + imgBL.info().height()));
5455
        MSG_DEBUG("Button image size: " << (imgTL.info().width() + imgT.info().width() + imgTR.info().width()) << " x " << (imgTL.info().height() + imgL.info().height() + imgBL.info().height()));
5457
        MSG_DEBUG("Total size: " << wt << " x " << ht);
5456
        MSG_DEBUG("Total size: " << wt << " x " << ht);
Line 5467... Line 5466...
5467
        SkCanvas target(*bm, SkSurfaceProps());
5466
        SkCanvas target(*bm, SkSurfaceProps());
5468
        SkCanvas canvas(frame, SkSurfaceProps());
5467
        SkCanvas canvas(frame, SkSurfaceProps());
5469
        SkPaint paint;
5468
        SkPaint paint;
5470
 
5469
 
5471
        paint.setBlendMode(SkBlendMode::kSrcOver);
5470
        paint.setBlendMode(SkBlendMode::kSrcOver);
5472
        sk_sp<SkImage> _image = SkImages::RasterFromBitmap(imgB);
5471
        sk_sp<SkImage> _image = SkImages::RasterFromBitmap(imgB);   // bottom
5473
        canvas.drawImage(_image, imgBL.info().width(), ht - imgB.info().height(), SkSamplingOptions(), &paint);
5472
        canvas.drawImage(_image, imgBL.info().width(), ht - imgB.info().height(), SkSamplingOptions(), &paint);
5474
        _image = SkImages::RasterFromBitmap(imgBR);
5473
        _image = SkImages::RasterFromBitmap(imgT);                  // top
-
 
5474
        canvas.drawImage(_image, imgTL.info().width(), 0, SkSamplingOptions(), &paint);
-
 
5475
        _image = SkImages::RasterFromBitmap(imgL);                  // left
5475
        canvas.drawImage(_image, wt - imgBR.info().width(), ht - imgBR.info().height(), SkSamplingOptions(), &paint);
5476
        canvas.drawImage(_image, 0, imgTL.info().height(), SkSamplingOptions(), &paint);
5476
        _image = SkImages::RasterFromBitmap(imgR);
5477
        _image = SkImages::RasterFromBitmap(imgR);                  // right
5477
        canvas.drawImage(_image, wt - imgR.info().width(), imgTR.info().height(), SkSamplingOptions(), &paint);
5478
        canvas.drawImage(_image, wt - imgR.info().width(), imgTR.info().height(), SkSamplingOptions(), &paint);
-
 
5479
        _image = SkImages::RasterFromBitmap(imgBR);                 // bottom right
-
 
5480
        canvas.drawImage(_image, wt - imgBR.info().width(), ht - imgBR.info().height(), SkSamplingOptions(), &paint);
5478
        _image = SkImages::RasterFromBitmap(imgTR);
5481
        _image = SkImages::RasterFromBitmap(imgTR);                 // top right
5479
        canvas.drawImage(_image, wt - imgTR.info().width(), 0, SkSamplingOptions(), &paint);
5482
        canvas.drawImage(_image, wt - imgTR.info().width(), 0, SkSamplingOptions(), &paint);
5480
        _image = SkImages::RasterFromBitmap(imgT);
-
 
5481
        canvas.drawImage(_image, imgTL.info().width(), 0, SkSamplingOptions(), &paint);
-
 
5482
        _image = SkImages::RasterFromBitmap(imgTL);
5483
        _image = SkImages::RasterFromBitmap(imgTL);                 // top left
5483
        canvas.drawImage(_image, 0, 0, SkSamplingOptions(), &paint);
5484
        canvas.drawImage(_image, 0, 0, SkSamplingOptions(), &paint);
5484
        _image = SkImages::RasterFromBitmap(imgL);
-
 
5485
        canvas.drawImage(_image, 0, imgTL.info().height(), SkSamplingOptions(), &paint);
-
 
5486
        _image = SkImages::RasterFromBitmap(imgBL);
5485
        _image = SkImages::RasterFromBitmap(imgBL);                 // bottom left
5487
        canvas.drawImage(_image, 0, ht - imgBL.info().height(), SkSamplingOptions(), &paint);
5486
        canvas.drawImage(_image, 0, ht - imgBL.info().height(), SkSamplingOptions(), &paint);
5488
 
5487
 
5489
        erasePart(bm, frame, Border::ERASE_OUTSIDE);
5488
        erasePart(bm, frame, Border::ERASE_OUTSIDE, imgL.info().width());
5490
        backgroundFrame(bm, frame, color);
5489
        backgroundFrame(bm, frame, color);
5491
        _image = SkImages::RasterFromBitmap(frame);
5490
        _image = SkImages::RasterFromBitmap(frame);
5492
        paint.setBlendMode(SkBlendMode::kSrcATop);
5491
        paint.setBlendMode(SkBlendMode::kSrcATop);
5493
        target.drawImage(_image, 0, 0, SkSamplingOptions(), &paint);
5492
        target.drawImage(_image, 0, 0, SkSamplingOptions(), &paint);
5494
    }
5493
    }
Line 7280... Line 7279...
7280
    }
7279
    }
7281
 
7280
 
7282
    return true;
7281
    return true;
7283
}
7282
}
7284
 
7283
 
-
 
7284
bool TButton::retrieveImage(const string& path, const string& pathAlpha, SkBitmap* image)
-
 
7285
{
-
 
7286
    DECL_TRACER("TButton::retrieveImage(const string& path, const string& pathAlpha, SkBitmap* image)");
-
 
7287
 
-
 
7288
    sk_sp<SkData> im;
-
 
7289
    SkBitmap bm;
-
 
7290
 
-
 
7291
    if (!(im = readImage(path)))
-
 
7292
        return false;
-
 
7293
 
-
 
7294
    DecodeDataToBitmap(im, image);
-
 
7295
 
-
 
7296
    if (image->empty())
-
 
7297
    {
-
 
7298
        MSG_WARNING("Could not create the image " << path);
-
 
7299
        return false;
-
 
7300
    }
-
 
7301
 
-
 
7302
    if (pathAlpha.empty())
-
 
7303
        return true;
-
 
7304
 
-
 
7305
    if (!(im = readImage(pathAlpha)))
-
 
7306
        return true;
-
 
7307
 
-
 
7308
    DecodeDataToBitmap(im, &bm);
-
 
7309
 
-
 
7310
    if (bm.empty())
-
 
7311
    {
-
 
7312
        MSG_WARNING("Could not create alpha mask image " << pathAlpha);
-
 
7313
        return true;
-
 
7314
    }
-
 
7315
 
-
 
7316
    if (image->info().dimensions() == bm.info().dimensions())
-
 
7317
    {
-
 
7318
        for (int x = 0; x < image->info().width(); ++x)
-
 
7319
        {
-
 
7320
            for (int y = 0; y < image->info().height(); ++y)
-
 
7321
            {
-
 
7322
                uint32_t *pixImage = image->getAddr32(x, y);
-
 
7323
                SkColor colImage = image->getColor(x, y);
-
 
7324
                SkColor colAlpha = bm.getColor(x, y);
-
 
7325
                SkColor alpha = SkColorGetA(colImage);
-
 
7326
 
-
 
7327
                if (alpha == 0)
-
 
7328
                    *pixImage = colAlpha;
-
 
7329
            }
-
 
7330
        }
-
 
7331
    }
-
 
7332
    else
-
 
7333
    {
-
 
7334
        SkPaint paint;
-
 
7335
        paint.setBlendMode(SkBlendMode::kSoftLight);
-
 
7336
        SkCanvas can(*image);
-
 
7337
        sk_sp<SkImage> _image = SkImages::RasterFromBitmap(bm);
-
 
7338
        can.drawImage(_image, 0, 0, SkSamplingOptions(), &paint);
-
 
7339
    }
-
 
7340
 
-
 
7341
    return true;
-
 
7342
 
-
 
7343
}
-
 
7344
 
7285
void TButton::show()
7345
void TButton::show()
7286
{
7346
{
7287
    DECL_TRACER("TButton::show()");
7347
    DECL_TRACER("TButton::show()");
7288
 
7348
 
7289
    // First we detect whether we have a dynamic button or not.
7349
    // First we detect whether we have a dynamic button or not.
Line 7916... Line 7976...
7916
                msg = "Enter [" + intToString(pp) + "] password";
7976
                msg = "Enter [" + intToString(pp) + "] password";
7917
            else
7977
            else
7918
                msg = "Enter password for user " + mUser;
7978
                msg = "Enter password for user " + mUser;
7919
 
7979
 
7920
            mPassword.clear();
7980
            mPassword.clear();
7921
            gPageManager->getAskPassword()(mHandle, msg, "Password");
7981
            gPageManager->getAskPassword()(mHandle, msg, "Password", x, y);
7922
            return true;
7982
            return true;
7923
        }
7983
        }
7924
        else
7984
        else
7925
            return false;
7985
            return false;
7926
    }
7986
    }