Subversion Repositories tpanel

Rev

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

Rev 168 Rev 169
Line 18... Line 18...
18
 
18
 
19
#include <string>
19
#include <string>
20
#include <memory>
20
#include <memory>
21
#include <algorithm>
21
#include <algorithm>
22
#include <codecvt>
22
#include <codecvt>
-
 
23
#include <fstream>
23
 
24
 
24
#include <include/core/SkPixmap.h>
25
#include <include/core/SkPixmap.h>
25
#include <include/core/SkSize.h>
26
#include <include/core/SkSize.h>
26
#include <include/core/SkColor.h>
27
#include <include/core/SkColor.h>
27
#include <include/core/SkFont.h>
28
#include <include/core/SkFont.h>
Line 33... Line 34...
33
#include <include/effects/SkImageFilters.h>
34
#include <include/effects/SkImageFilters.h>
34
#include <include/core/SkPath.h>
35
#include <include/core/SkPath.h>
35
#include <include/core/SkSurfaceProps.h>
36
#include <include/core/SkSurfaceProps.h>
36
#include <include/core/SkFilterQuality.h>
37
#include <include/core/SkFilterQuality.h>
37
#include <include/core/SkMaskFilter.h>
38
#include <include/core/SkMaskFilter.h>
-
 
39
#include <include/core/SkImageEncoder.h>
38
 
40
 
39
#ifdef __ANDROID__
41
#ifdef __ANDROID__
40
#include <QtAndroidExtras/QAndroidJniObject>
42
#include <QtAndroidExtras/QAndroidJniObject>
41
#include <QtAndroid>
43
#include <QtAndroid>
42
#endif
44
#endif
Line 4462... Line 4464...
4462
    bool classExist = (gPageManager && gPageManager->getSystemDraw());
4464
    bool classExist = (gPageManager && gPageManager->getSystemDraw());
4463
 
4465
 
4464
    if ((classExist && borderIndex >= 0 && !sysBorders[borderIndex].calc) || (classExist && borderIndex < 0))
4466
    if ((classExist && borderIndex >= 0 && !sysBorders[borderIndex].calc) || (classExist && borderIndex < 0))
4465
    {
4467
    {
4466
        int numBorders = 0;
4468
        int numBorders = 0;
-
 
4469
        bool extBorder = false;
-
 
4470
 
4467
        string borderName1 = (bs.empty() ? sr[instance].bs : bs);
4471
        string borderName1 = (bs.empty() ? sr[instance].bs : bs);
4468
        string borderName2 = (!bs.empty() && !sr[instance].bs.empty() ? sr[instance].bs : bs);
4472
        string borderName2 = (!bs.empty() && !sr[instance].bs.empty() ? sr[instance].bs : bs);
4469
MSG_DEBUG("Searching for borders \"" << borderName1 << "\" and \"" << borderName2 << "\"");
-
 
4470
        if (gPageManager->getSystemDraw()->getBorder(borderName1, TSystemDraw::LT_OFF, &bd))
-
 
4471
            numBorders++;
-
 
4472
 
4473
 
-
 
4474
        if (bs.empty())
-
 
4475
        {
-
 
4476
            if (gPageManager->getSystemDraw()->getBorder(sr[instance].bs, TSystemDraw::LT_OFF, &bd))
-
 
4477
                numBorders++;
-
 
4478
 
4473
        if (gPageManager->getSystemDraw()->getBorder(borderName2, TSystemDraw::LT_ON, &bda))
4479
            if (gPageManager->getSystemDraw()->getBorder(sr[instance].bs, TSystemDraw::LT_ON, &bda))
4474
            numBorders++;
4480
                numBorders++;
-
 
4481
 
-
 
4482
            if (numBorders == 2)
-
 
4483
                extBorder = true;
-
 
4484
        }
-
 
4485
        else if (!sr[instance].bs.empty())
-
 
4486
        {
-
 
4487
            if (gPageManager->getSystemDraw()->getBorder(bs, (instance == 0 ? TSystemDraw::LT_OFF : TSystemDraw::LT_ON), &bd, sr[instance].bs))
-
 
4488
            {
-
 
4489
                numBorders++;
-
 
4490
                extBorder = true;
-
 
4491
            }
-
 
4492
        }
4475
 
4493
 
4476
        if (numBorders == 2)
4494
        if (extBorder)
4477
        {
4495
        {
4478
            MSG_DEBUG("System border \"" << borderName1 << "\" and \"" << borderName2 << "\" found.");
4496
            MSG_DEBUG("System border \"" << borderName1 << "\" and \"" << borderName2 << "\" found.");
4479
            SkColor color = TColor::getSkiaColor(sr[instance].cb);      // border color
4497
            SkColor color = TColor::getSkiaColor(sr[instance].cb);      // border color
4480
            SkColor bgColor = TColor::getSkiaColor(sr[instance].cf);    // fill color
4498
            SkColor bgColor = TColor::getSkiaColor(sr[instance].cf);    // fill color
4481
            MSG_DEBUG("Button color: #" << std::setw(6) << std::setfill('0') << std::hex << color);
4499
            MSG_DEBUG("Button color: #" << std::setw(6) << std::setfill('0') << std::hex << color);
Line 4528... Line 4546...
4528
 
4546
 
4529
            if (imgBL.empty())
4547
            if (imgBL.empty())
4530
                return false;
4548
                return false;
4531
 
4549
 
4532
            MSG_DEBUG("Got images " << bd.bl << " and " << bda.bl << " with size " << imgBL.info().width() << " x " << imgBL.info().height());
4550
            MSG_DEBUG("Got images " << bd.bl << " and " << bda.bl << " with size " << imgBL.info().width() << " x " << imgBL.info().height());
-
 
4551
            MSG_DEBUG("Button image size: " << (imgTL.info().width() + imgT.info().width() + imgTR.info().width()) << " x " << (imgTL.info().height() + imgL.info().height() + imgBL.info().height()));
4533
            MSG_DEBUG("Total size: " << wt << " x " << ht);
4552
            MSG_DEBUG("Total size: " << wt << " x " << ht);
4534
            stretchImageWidth(&imgB, wt - imgBL.info().width() - imgBR.info().width());
4553
            stretchImageWidth(&imgB, wt - imgBL.info().width() - imgBR.info().width());
4535
            stretchImageWidth(&imgT, wt - imgTL.info().width() - imgTR.info().width());
4554
            stretchImageWidth(&imgT, wt - imgTL.info().width() - imgTR.info().width());
4536
            stretchImageHeight(&imgL, ht - imgTL.info().height() - imgBL.info().height());
4555
            stretchImageHeight(&imgL, ht - imgTL.info().height() - imgBL.info().height());
4537
            stretchImageHeight(&imgR, ht - imgTR.info().height() - imgBR.info().height());
4556
            stretchImageHeight(&imgR, ht - imgTR.info().height() - imgBR.info().height());
-
 
4557
            MSG_DEBUG("Stretched button image size: " << (imgTL.info().width() + imgT.info().width() + imgTR.info().width()) << " x " << (imgTL.info().height() + imgL.info().height() + imgBL.info().height()));
4538
            // Draw the frame
4558
            // Draw the frame
4539
            SkCanvas canvas(*bm, SkSurfaceProps(1, kUnknown_SkPixelGeometry));
4559
            SkCanvas canvas(*bm, SkSurfaceProps(1, kUnknown_SkPixelGeometry));
4540
            SkPaint paint;
4560
            SkPaint paint;
4541
 
4561
 
4542
            paint.setColor(bgColor);
-
 
4543
            paint.setBlendMode(SkBlendMode::kSrcOver);
4562
            paint.setBlendMode(SkBlendMode::kSrcOver);
4544
            canvas.drawBitmap(imgB, imgBL.info().width(), ht - imgB.info().height(), &paint);
4563
            canvas.drawBitmap(imgB, imgBL.info().width(), ht - imgB.info().height(), &paint);
4545
            canvas.drawBitmap(imgBR, wt - imgBR.info().width(), ht - imgBR.info().height(), &paint);
4564
            canvas.drawBitmap(imgBR, wt - imgBR.info().width(), ht - imgBR.info().height(), &paint);
4546
            canvas.drawBitmap(imgR, wt - imgR.info().width(), imgTR.info().height(), &paint);
4565
            canvas.drawBitmap(imgR, wt - imgR.info().width(), imgTR.info().height(), &paint);
4547
            canvas.drawBitmap(imgTR, wt - imgTR.info().width(), 0, &paint);
4566
            canvas.drawBitmap(imgTR, wt - imgTR.info().width(), 0, &paint);
Line 6060... Line 6079...
6060
    int width = base.info().width();
6079
    int width = base.info().width();
6061
    int height = base.info().height();
6080
    int height = base.info().height();
6062
 
6081
 
6063
    if (width <= 0 || height <= 0)
6082
    if (width <= 0 || height <= 0)
6064
    {
6083
    {
6065
        MSG_WARNING("Got invalid width or height! (width: " << width << ", height: " << height);
6084
        MSG_WARNING("Got invalid width or height! (width: " << width << ", height: " << height << ")");
6066
        return SkBitmap();
6085
        return SkBitmap();
6067
    }
6086
    }
6068
 
6087
 
6069
    if (width != alpha.info().width() || height != alpha.info().height())
6088
    if (!alpha.empty())
6070
    {
6089
    {
-
 
6090
        if (width != alpha.info().width() || height != alpha.info().height())
-
 
6091
        {
6071
        MSG_ERROR("Base and alpha masks have different size!")
6092
            MSG_ERROR("Base and alpha masks have different size!");
6072
        return SkBitmap();
6093
            return SkBitmap();
-
 
6094
        }
6073
    }
6095
    }
6074
 
6096
 
6075
    SkBitmap maskBm;
6097
    SkBitmap maskBm;
6076
    maskBm.allocPixels(SkImageInfo::MakeN32Premul(width, height));
6098
    maskBm.allocPixels(SkImageInfo::MakeN32Premul(width, height));
6077
    maskBm.eraseColor(SK_ColorTRANSPARENT);
6099
    maskBm.eraseColor(SK_ColorTRANSPARENT);
6078
 
6100
 
6079
    for (int ix = 0; ix < width; ix++)
6101
    for (int ix = 0; ix < width; ix++)
6080
    {
6102
    {
6081
        for (int iy = 0; iy < height; iy++)
6103
        for (int iy = 0; iy < height; iy++)
6082
        {
6104
        {
-
 
6105
            SkColor pixelAlpha = 0;
-
 
6106
 
-
 
6107
            if (!alpha.empty())
6083
            SkColor pixelAlpha = alpha.getColor(ix, iy);
6108
                pixelAlpha = alpha.getColor(ix, iy);
-
 
6109
            else
-
 
6110
                pixelAlpha = base.getColor(ix, iy);
-
 
6111
 
6084
            uint32_t *wpix = maskBm.getAddr32(ix, iy);
6112
            uint32_t *wpix = maskBm.getAddr32(ix, iy);
6085
 
6113
 
6086
            if (!wpix)
6114
            if (!wpix)
6087
            {
6115
            {
6088
                MSG_ERROR("No pixel buffer!");
6116
                MSG_ERROR("No pixel buffer!");
6089
                break;
6117
                break;
6090
            }
6118
            }
6091
 
6119
 
6092
            uint32_t alpha = SkColorGetA(pixelAlpha);
6120
            uint32_t ala = SkColorGetA(pixelAlpha);
6093
 
6121
 
6094
            if (alpha == 0 && !useBG)
6122
            if (ala == 0 && !useBG)
6095
                pixelAlpha = col;
6123
                pixelAlpha = col;
6096
            else if (alpha == 0)
6124
            else if (ala == 0)
6097
                pixelAlpha = bg;
6125
                pixelAlpha = bg;
6098
            else
6126
            else
6099
            {
6127
            {
6100
                // We've to change the red and the blue color channel because
6128
                // We've to change the red and the blue color channel because
6101
                // of an error in the Skia library.
6129
                // of an error in the Skia library.
6102
                uint32_t blue = SkColorGetR(col);
6130
                uint32_t blue = SkColorGetR(col);
6103
                uint32_t green = SkColorGetG(col);
6131
                uint32_t green = SkColorGetG(col);
6104
                uint32_t red = SkColorGetB(col);
6132
                uint32_t red = SkColorGetB(col);
6105
 
6133
 
-
 
6134
                if (alpha.empty())
-
 
6135
                {
-
 
6136
                    uint32_t pred = SkColorGetR(pixelAlpha);
-
 
6137
                    uint32_t pgreen = SkColorGetG(pixelAlpha);
-
 
6138
                    uint32_t pblue = SkColorGetB(pixelAlpha);
-
 
6139
                    uint32_t maxChan = SkColorGetG(SK_ColorWHITE);
-
 
6140
 
-
 
6141
                    red   = ((pred == maxChan) ? pred : red);
-
 
6142
                    green = ((pgreen == maxChan) ? pgreen : green);
-
 
6143
                    blue  = ((pblue == maxChan) ? pblue : blue);
-
 
6144
                }
6106
                if (alpha == 0)
6145
                else if (ala == 0)
6107
                    red = green = blue = 0;
6146
                    red = green = blue = 0;
6108
 
6147
 
6109
                pixelAlpha = SkColorSetARGB(alpha, red, green, blue);
6148
                pixelAlpha = SkColorSetARGB(ala, red, green, blue);
6110
            }
6149
            }
6111
 
6150
 
6112
            *wpix = pixelAlpha;
6151
            *wpix = pixelAlpha;
-
 
6152
//            MSG_DEBUG("Pixel " << ix << ", " << iy << ": #" << std::setw(8) << std::setfill('0') << std::hex << pixelAlpha);
6113
        }
6153
        }
6114
    }
6154
    }
6115
 
6155
 
-
 
6156
    if (!alpha.empty())
-
 
6157
    {
6116
    SkPaint paint;
6158
        SkPaint paint;
6117
    paint.setBlendMode(SkBlendMode::kSrcOver);
6159
        paint.setBlendMode(SkBlendMode::kSrcOver);
6118
    SkCanvas can(maskBm);
6160
        SkCanvas can(maskBm);
6119
    can.drawBitmap(base, 0, 0, &paint);
6161
        can.drawBitmap(base, 0, 0, &paint);
-
 
6162
    }
-
 
6163
 
6120
    return maskBm;
6164
    return maskBm;
6121
}
6165
}
6122
 
6166
 
6123
SkBitmap TButton::retrieveBorderImage(const string& pa, const string& pb, SkColor color, SkColor bgColor)
6167
SkBitmap TButton::retrieveBorderImage(const string& pa, const string& pb, SkColor color, SkColor bgColor)
6124
{
6168
{