Subversion Repositories tpanel

Rev

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

Rev 479 Rev 486
Line 25... Line 25...
25
#include "tresources.h"
25
#include "tresources.h"
26
#include "texpat++.h"
26
#include "texpat++.h"
27
#include "tpagemanager.h"
27
#include "tpagemanager.h"
28
#include "tsubpage.h"
28
#include "tsubpage.h"
29
#include "tdrawimage.h"
29
#include "tdrawimage.h"
-
 
30
#include "ttpinit.h"
30
#include "tconfig.h"
31
#include "tconfig.h"
31
#include "terror.h"
32
#include "terror.h"
32
#if TESTMODE == 1
33
#if TESTMODE == 1
33
#include "testmode.h"
34
#include "testmode.h"
34
#endif
35
#endif
Line 140... Line 141...
140
    if (mFName.empty())
141
    if (mFName.empty())
141
        return;
142
        return;
142
 
143
 
143
    TError::clear();
144
    TError::clear();
144
    TExpat xml(mFName);
145
    TExpat xml(mFName);
-
 
146
 
-
 
147
    if (!TTPInit::isTP5())
145
    xml.setEncoding(ENC_CP1250);
148
        xml.setEncoding(ENC_CP1250);
-
 
149
    else
-
 
150
        xml.setEncoding(ENC_UTF8);
146
 
151
 
147
    if (!xml.parse())
152
    if (!xml.parse())
148
        return;
153
        return;
149
 
154
 
150
    int depth = 0;
155
    int depth = 0;
Line 235... Line 240...
235
                }
240
                }
236
 
241
 
237
                button->setHandle(((mSubpage.pageID << 16) & 0xffff0000) | button->getButtonIndex());
242
                button->setHandle(((mSubpage.pageID << 16) & 0xffff0000) | button->getButtonIndex());
238
                button->createButtons();
243
                button->createButtons();
239
                addButton(button);
244
                addButton(button);
-
 
245
                string sType1 = xml.getElementTypeStr(index);
-
 
246
                string sType2 = xml.getElementTypeStr(index+1);
-
 
247
                MSG_DEBUG("Element type 1: " << sType1);
-
 
248
                MSG_DEBUG("Element type 2: " << sType2);
-
 
249
 
-
 
250
                if (xml.isElementTypeEnd(index+1))
240
                index++;    // Jump over the end tag of the button.
251
                    index++;        // Jump over the end tag of the button.
241
            }
252
            }
242
            catch (std::exception& e)
253
            catch (std::exception& e)
243
            {
254
            {
244
                MSG_ERROR("Memory exception: " << e.what());
255
                MSG_ERROR("Memory exception: " << e.what());
245
                TError::setError();
256
                TError::setError();
Line 291... Line 302...
291
                    sr.et = xml.convertElementToInt(content);
302
                    sr.et = xml.convertElementToInt(content);
292
                else if (ename.compare("ww") == 0)
303
                else if (ename.compare("ww") == 0)
293
                    sr.ww = xml.convertElementToInt(content);
304
                    sr.ww = xml.convertElementToInt(content);
294
                else if (ename.compare("jt") == 0)
305
                else if (ename.compare("jt") == 0)
295
                    sr.jt = (Button::ORIENTATION)xml.convertElementToInt(content);
306
                    sr.jt = (Button::ORIENTATION)xml.convertElementToInt(content);
-
 
307
                else if (ename.compare("bitmapEntry") == 0)
-
 
308
                {
-
 
309
                    string fname;
-
 
310
                    BITMAPS_t bitmapEntry;
-
 
311
                    MSG_DEBUG("Section: " << ename);
-
 
312
 
-
 
313
                    while ((index = xml.getNextElementFromIndex(index, &fname, &content, &attrs)) != TExpat::npos)
-
 
314
                    {
-
 
315
                        if (fname.compare("fileName") == 0)
-
 
316
                            bitmapEntry.fileName = content;
-
 
317
                        else if (fname.compare("justification") == 0)
-
 
318
                            bitmapEntry.justification = static_cast<ORIENTATION>(xml.convertElementToInt(content));
-
 
319
                        else if (fname.compare("offsetX") == 0)
-
 
320
                            bitmapEntry.offsetX = xml.convertElementToInt(content);
-
 
321
                        else if (fname.compare("offsetY") == 0)
-
 
322
                            bitmapEntry.offsetY = xml.convertElementToInt(content);
-
 
323
 
-
 
324
                        oldIndex = index;
-
 
325
                    }
-
 
326
 
-
 
327
                    MSG_DEBUG("Found image: " << bitmapEntry.fileName << ", justification: " << bitmapEntry.justification << ", Offset: " << bitmapEntry.offsetX << "x" << bitmapEntry.offsetY);
-
 
328
                    sr.bitmaps.push_back(bitmapEntry);
-
 
329
 
-
 
330
                    if (index == TExpat::npos)
-
 
331
                        index = oldIndex + 1;
-
 
332
                }
296
 
333
 
297
                oldIndex = index;
334
                oldIndex = index;
298
            }
335
            }
299
 
336
 
300
            mSubpage.sr.push_back(sr);
337
            mSubpage.sr.push_back(sr);
Line 355... Line 392...
355
#endif
392
#endif
356
            return;
393
            return;
357
        }
394
        }
358
    }
395
    }
359
 
396
 
-
 
397
    bool noSr = mSubpage.sr.empty();
360
    bool haveImage = false;
398
    bool haveImage = false;
361
    ulong handle = (mSubpage.pageID << 16) & 0xffff0000;
399
    ulong handle = (mSubpage.pageID << 16) & 0xffff0000;
362
    MSG_DEBUG("Processing subpage " << mSubpage.pageID << ": " << mSubpage.name);
400
    MSG_DEBUG("Processing subpage " << mSubpage.pageID << ": " << mSubpage.name);
363
    SkBitmap target;
401
    SkBitmap target;
364
 
402
 
Line 376... Line 414...
376
        mSubpage.top = mSubpage.topOrig;
414
        mSubpage.top = mSubpage.topOrig;
377
        mSubpage.width = mSubpage.widthOrig;
415
        mSubpage.width = mSubpage.widthOrig;
378
        mSubpage.height = mSubpage.heightOrig;
416
        mSubpage.height = mSubpage.heightOrig;
379
    }
417
    }
380
 
418
 
-
 
419
    if (!noSr)
381
    target.eraseColor(TColor::getSkiaColor(mSubpage.sr[0].cf));
420
        target.eraseColor(TColor::getSkiaColor(mSubpage.sr[0].cf));
-
 
421
    else
-
 
422
        target.eraseColor(SK_ColorTRANSPARENT);
-
 
423
 
-
 
424
    MSG_DEBUG("Number TP5 images: " << mSubpage.sr[0].bitmaps.size());
382
    // Draw the background, if any
425
    // Draw the background, if any
383
    if (mSubpage.sr.size() > 0 && (!mSubpage.sr[0].bm.empty() || !mSubpage.sr[0].mi.empty()))
426
    if (!noSr && (!mSubpage.sr[0].bm.empty() || !mSubpage.sr[0].mi.empty() || !mSubpage.sr[0].bitmaps.empty()))
384
    {
427
    {
385
        TDrawImage dImage;
428
        TDrawImage dImage;
386
        dImage.setWidth(mSubpage.width);
429
        dImage.setWidth(mSubpage.width);
387
        dImage.setHeight(mSubpage.height);
430
        dImage.setHeight(mSubpage.height);
-
 
431
        dImage.setSr(mSubpage.sr);
388
 
432
 
389
        if (!mSubpage.sr[0].bm.empty())
433
        if (!TTPInit::isTP5() && !mSubpage.sr[0].bm.empty())
390
        {
434
        {
391
            MSG_DEBUG("Loading image " << mSubpage.sr[0].bm);
435
            MSG_DEBUG("Loading image " << mSubpage.sr[0].bm);
392
            sk_sp<SkData> rawImage = readImage(mSubpage.sr[0].bm);
436
            sk_sp<SkData> rawImage = readImage(mSubpage.sr[0].bm);
393
            SkBitmap bm;
437
            SkBitmap bm;
394
 
438
 
Line 412... Line 456...
412
                {
456
                {
413
                    MSG_WARNING("BM image " << mSubpage.sr[0].bm << " seems to be empty!");
457
                    MSG_WARNING("BM image " << mSubpage.sr[0].bm << " seems to be empty!");
414
                }
458
                }
415
            }
459
            }
416
        }
460
        }
-
 
461
        else if (TTPInit::isTP5() && mSubpage.sr[0].bitmaps.size() > 0)
-
 
462
        {
-
 
463
            MSG_DEBUG("Loading TP5 image(s) ...");
-
 
464
            vector<Button::BITMAPS_t>::iterator iter;
-
 
465
 
-
 
466
            for (iter = mSubpage.sr[0].bitmaps.begin(); iter != mSubpage.sr[0].bitmaps.end(); ++iter)
-
 
467
            {
-
 
468
                sk_sp<SkData> rawImage = readImage(iter->fileName);
-
 
469
                SkBitmap bm;
-
 
470
 
-
 
471
                if (rawImage)
-
 
472
                {
-
 
473
                    MSG_DEBUG("Decoding image BM ...");
-
 
474
 
-
 
475
                    if (!DecodeDataToBitmap(rawImage, &bm))
-
 
476
                    {
-
 
477
                        MSG_WARNING("Problem while decoding image " << iter->fileName);
-
 
478
                    }
-
 
479
                    else if (!bm.empty())
-
 
480
                    {
-
 
481
                        dImage.setImageBm(bm);
-
 
482
                        SkImageInfo info = bm.info();
-
 
483
                        haveImage = true;
-
 
484
                    }
-
 
485
                    else
-
 
486
                    {
-
 
487
                        MSG_WARNING("BM image " << iter->fileName << " seems to be empty!");
-
 
488
                    }
-
 
489
                }
-
 
490
            }
-
 
491
        }
417
 
492
 
418
        if (!mSubpage.sr[0].mi.empty())
493
        if (!mSubpage.sr[0].mi.empty())
419
        {
494
        {
420
            MSG_DEBUG("Loading image " << mSubpage.sr[0].mi);
495
            MSG_DEBUG("Loading image " << mSubpage.sr[0].mi);
421
            sk_sp<SkData> rawImage = readImage(mSubpage.sr[0].mi);
496
            sk_sp<SkData> rawImage = readImage(mSubpage.sr[0].mi);
Line 510... Line 585...
510
            }
585
            }
511
#endif
586
#endif
512
        }
587
        }
513
    }
588
    }
514
 
589
 
515
    if (mSubpage.sr.size() > 0 && !mSubpage.sr[0].te.empty())
590
    if (!noSr && !mSubpage.sr[0].te.empty())
516
    {
591
    {
517
        MSG_DEBUG("Drawing a text only on background image ...");
592
        MSG_DEBUG("Drawing a text only on background image ...");
518
 
593
 
519
        if (drawText(mSubpage, &target))
594
        if (drawText(mSubpage, &target))
520
            haveImage = true;
595
            haveImage = true;
521
    }
596
    }
522
 
597
 
523
    // Check for a frame and draw it if there is one.
598
    // Check for a frame and draw it if there is one.
524
    if (!mSubpage.sr[0].bs.empty())
599
    if (!noSr && !mSubpage.sr[0].bs.empty())
525
    {
600
    {
526
        if (drawFrame(mSubpage, &target))
601
        if (drawFrame(mSubpage, &target))
527
            haveImage = true;
602
            haveImage = true;
528
    }
603
    }
529
 
604
 
530
    if (haveImage)
605
    if (!noSr && haveImage)
531
    {
606
    {
532
#ifdef _OPAQUE_SKIA_
607
#ifdef _OPAQUE_SKIA_
533
        if (mSubpage.sr[0].oo < 255)
608
        if (mSubpage.sr[0].oo < 255)
534
            setOpacity(&target, mSubpage.sr[0].oo);
609
            setOpacity(&target, mSubpage.sr[0].oo);
535
#endif
610
#endif
Line 538... Line 613...
538
        _setBackground(handle, image, target.info().width(), target.info().height(), TColor::getColor(mSubpage.sr[0].cf));
613
        _setBackground(handle, image, target.info().width(), target.info().height(), TColor::getColor(mSubpage.sr[0].cf));
539
#else
614
#else
540
        _setBackground(handle, image, target.info().width(), target.info().height(), TColor::getColor(mSubpage.sr[0].cf), mSubpage.sr[0].oo);
615
        _setBackground(handle, image, target.info().width(), target.info().height(), TColor::getColor(mSubpage.sr[0].cf), mSubpage.sr[0].oo);
541
#endif
616
#endif
542
    }
617
    }
543
    else if (mSubpage.sr.size() > 0 && !haveImage)
618
    else if (!noSr && !haveImage)
544
    {
619
    {
545
        MSG_DEBUG("Calling \"setBackground\" with no image ...");
620
        MSG_DEBUG("Calling \"setBackground\" with no image ...");
546
#ifdef _OPAQUE_SKIA_
621
#ifdef _OPAQUE_SKIA_
547
        _setBackground(handle, TBitmap(), 0, 0, TColor::getColor(mSubpage.sr[0].cf));
622
        _setBackground(handle, TBitmap(), 0, 0, TColor::getColor(mSubpage.sr[0].cf));
548
#else
623
#else
Line 563... Line 638...
563
            button->button->regCallPlayVideo(_playVideo);
638
            button->button->regCallPlayVideo(_playVideo);
564
            button->button->setFonts(getFonts());
639
            button->button->setFonts(getFonts());
565
            button->button->setPalette(mPalette);
640
            button->button->setPalette(mPalette);
566
            button->button->createButtons();
641
            button->button->createButtons();
567
 
642
 
568
            if (mSubpage.sr.size() > 0)
643
            if (!noSr)
569
                button->button->setGlobalOpacity(mSubpage.sr[0].oo);
644
                button->button->setGlobalOpacity(mSubpage.sr[0].oo);
570
 
645
 
571
            if (mSubpage.resetPos != 0)
646
            if (mSubpage.resetPos != 0)
572
                button->button->resetButton();
647
                button->button->resetButton();
573
 
648
 
Line 603... Line 678...
603
    if (mSubpage.sr.size() > 0 && (!mSubpage.sr[0].bm.empty() || !mSubpage.sr[0].mi.empty()))
678
    if (mSubpage.sr.size() > 0 && (!mSubpage.sr[0].bm.empty() || !mSubpage.sr[0].mi.empty()))
604
    {
679
    {
605
        TDrawImage dImage;
680
        TDrawImage dImage;
606
        dImage.setWidth(mSubpage.width);
681
        dImage.setWidth(mSubpage.width);
607
        dImage.setHeight(mSubpage.height);
682
        dImage.setHeight(mSubpage.height);
-
 
683
        dImage.setSr(mSubpage.sr);
608
 
684
 
609
        if (!mSubpage.sr[0].bm.empty())
685
        if (!mSubpage.sr[0].bm.empty())
610
        {
686
        {
611
            MSG_DEBUG("Loading image " << mSubpage.sr[0].bm);
687
            MSG_DEBUG("Loading image " << mSubpage.sr[0].bm);
612
            sk_sp<SkData> rawImage = readImage(mSubpage.sr[0].bm);
688
            sk_sp<SkData> rawImage = readImage(mSubpage.sr[0].bm);