Subversion Repositories tpanel

Rev

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

Rev 479 Rev 486
Line 33... Line 33...
33
#include "tpage.h"
33
#include "tpage.h"
34
#include "tdrawimage.h"
34
#include "tdrawimage.h"
35
#include "texpat++.h"
35
#include "texpat++.h"
36
#include "tconfig.h"
36
#include "tconfig.h"
37
#include "terror.h"
37
#include "terror.h"
-
 
38
#include "ttpinit.h"
38
#if TESTMODE == 1
39
#if TESTMODE == 1
39
#include "testmode.h"
40
#include "testmode.h"
40
#endif
41
#endif
41
 
42
 
42
#if __cplusplus < 201402L
43
#if __cplusplus < 201402L
Line 135... Line 136...
135
 
136
 
136
    if (isValidFile())
137
    if (isValidFile())
137
        mPath = getFileName();
138
        mPath = getFileName();
138
 
139
 
139
    TExpat xml(mPath);
140
    TExpat xml(mPath);
-
 
141
 
-
 
142
    if (!TTPInit::isTP5())
140
    xml.setEncoding(ENC_CP1250);
143
        xml.setEncoding(ENC_CP1250);
-
 
144
    else
-
 
145
        xml.setEncoding(ENC_UTF8);
141
 
146
 
142
    if (!xml.parse())
147
    if (!xml.parse())
143
        return;
148
        return;
144
 
149
 
145
    int depth = 0;
150
    int depth = 0;
Line 162... Line 167...
162
        MSG_ERROR("Invalid page type \"" << type << "\"!");
167
        MSG_ERROR("Invalid page type \"" << type << "\"!");
163
        TError::setError();
168
        TError::setError();
164
        return;
169
        return;
165
    }
170
    }
166
 
171
 
-
 
172
    TError::clear();
167
    depth++;
173
    depth++;
168
    string ename, content;
174
    string ename, content;
169
 
175
 
170
    while ((index = xml.getNextElementFromIndex(index, &ename, &content, &attrs)) != TExpat::npos)
176
    while ((index = xml.getNextElementFromIndex(index, &ename, &content, &attrs)) != TExpat::npos)
171
    {
177
    {
172
        string e = ename;
178
        string e = ename;
-
 
179
        MSG_DEBUG("Element: " << ename << " at index " << index);
173
 
180
 
174
        if (e.compare("pageID") == 0)
181
        if (e.compare("pageID") == 0)
175
            mPage.pageID = xml.convertElementToInt(content);
182
            mPage.pageID = xml.convertElementToInt(content);
176
        else if (e.compare("name") == 0)
183
        else if (e.compare("name") == 0)
177
            mPage.name = content;
184
            mPage.name = content;
Line 191... Line 198...
191
            index = button->initialize(&xml, index);
198
            index = button->initialize(&xml, index);
192
            button->setParentSize(mPage.width, mPage.height);
199
            button->setParentSize(mPage.width, mPage.height);
193
 
200
 
194
            if (TError::isError())
201
            if (TError::isError())
195
            {
202
            {
196
                MSG_WARNING("Button \"" << button->getButtonName() << "\" deleted because of an error!");
203
                MSG_WARNING("Button \"" << button->getButtonName() << "\" deleted because of an error: " << TError::getErrorMsg());
197
                delete button;
204
                delete button;
198
                return;
205
                return;
199
            }
206
            }
200
 
207
 
201
            button->setHandle(((mPage.pageID << 16) & 0xffff0000) | button->getButtonIndex());
208
            button->setHandle(((mPage.pageID << 16) & 0xffff0000) | button->getButtonIndex());
202
            button->createButtons();
209
            button->createButtons();
203
            addButton(button);
210
            addButton(button);
-
 
211
            string sType1 = xml.getElementTypeStr(index);
-
 
212
            string sType2 = xml.getElementTypeStr(index+1);
-
 
213
            MSG_DEBUG("Element type 1: " << sType1);
-
 
214
            MSG_DEBUG("Element type 2: " << sType2);
-
 
215
 
-
 
216
            if (xml.isElementTypeEnd(index+1))
204
            index++;        // Jump over the end tag of the button.
217
                index++;        // Jump over the end tag of the button.
205
        }
218
        }
206
        else if (e.compare("sr") == 0)
219
        else if (e.compare("sr") == 0)
207
        {
220
        {
208
            SR_T bsr;
221
            SR_T bsr;
209
            bsr.number = xml.getAttributeInt("number", attrs);
222
            bsr.number = xml.getAttributeInt("number", attrs);
-
 
223
            MSG_DEBUG("Page " << mPage.name << " at State " << bsr.number);
210
            index++;
224
            index++;
211
 
225
 
212
            while ((index = xml.getNextElementFromIndex(index, &ename, &content, &attrs)) != TExpat::npos)
226
            while ((index = xml.getNextElementFromIndex(index, &ename, &content, &attrs)) != TExpat::npos)
213
            {
227
            {
214
                if (ename.compare("bs") == 0)
228
                if (ename.compare("bs") == 0)
Line 239... Line 253...
239
                    bsr.ww = xml.convertElementToInt(content);
253
                    bsr.ww = xml.convertElementToInt(content);
240
                else if (ename.compare("jt") == 0)
254
                else if (ename.compare("jt") == 0)
241
                    bsr.jt = (Button::ORIENTATION)xml.convertElementToInt(content);
255
                    bsr.jt = (Button::ORIENTATION)xml.convertElementToInt(content);
242
                else if (ename.compare("jb") == 0)
256
                else if (ename.compare("jb") == 0)
243
                    bsr.jb = (Button::ORIENTATION)xml.convertElementToInt(content);
257
                    bsr.jb = (Button::ORIENTATION)xml.convertElementToInt(content);
-
 
258
                else if (ename.compare("bitmapEntry") == 0)
-
 
259
                {
-
 
260
                    string fname;
-
 
261
                    BITMAPS_t bitmapEntry;
-
 
262
                    MSG_DEBUG("Section: " << ename);
-
 
263
 
-
 
264
                    while ((index = xml.getNextElementFromIndex(index, &fname, &content, &attrs)) != TExpat::npos)
-
 
265
                    {
-
 
266
                        if (fname.compare("fileName") == 0)
-
 
267
                            bitmapEntry.fileName = content;
-
 
268
                        else if (fname.compare("justification") == 0)
-
 
269
                            bitmapEntry.justification = static_cast<ORIENTATION>(xml.convertElementToInt(content));
-
 
270
                        else if (fname.compare("offsetX") == 0)
-
 
271
                            bitmapEntry.offsetX = xml.convertElementToInt(content);
-
 
272
                        else if (fname.compare("offsetY") == 0)
-
 
273
                            bitmapEntry.offsetY = xml.convertElementToInt(content);
-
 
274
 
-
 
275
                        oldIndex = index;
-
 
276
                    }
-
 
277
 
-
 
278
                    MSG_DEBUG("Found image: " << bitmapEntry.fileName << ", justification: " << bitmapEntry.justification << ", Offset: " << bitmapEntry.offsetX << "x" << bitmapEntry.offsetY);
-
 
279
                    bsr.bitmaps.push_back(bitmapEntry);
-
 
280
 
-
 
281
                    if (index == TExpat::npos)
-
 
282
                        index = oldIndex + 1;
-
 
283
                }
244
 
284
 
245
                oldIndex = index;
285
                oldIndex = index;
246
            }
286
            }
247
 
287
 
248
            sr.push_back(bsr);
288
            sr.push_back(bsr);
Line 250... Line 290...
250
            if (index == TExpat::npos)
290
            if (index == TExpat::npos)
251
                index = oldIndex + 1;
291
                index = oldIndex + 1;
252
        }
292
        }
253
    }
293
    }
254
 
294
 
-
 
295
    MSG_DEBUG("Setting SR with " << sr.size() << " elements");
255
    setSR(sr);
296
    setSR(sr);
256
 
297
 
257
    if (TPageInterface::getButtons())
298
    if (TPageInterface::getButtons())
258
        sortButtons();
299
        sortButtons();
259
}
300
}
Line 435... Line 476...
435
    if (mPage.sr.size() > 0 && (!mPage.sr[0].bm.empty() || !mPage.sr[0].mi.empty()))
476
    if (mPage.sr.size() > 0 && (!mPage.sr[0].bm.empty() || !mPage.sr[0].mi.empty()))
436
    {
477
    {
437
        TDrawImage dImage;
478
        TDrawImage dImage;
438
        dImage.setWidth(mPage.width);
479
        dImage.setWidth(mPage.width);
439
        dImage.setHeight(mPage.height);
480
        dImage.setHeight(mPage.height);
-
 
481
        dImage.setSr(mPage.sr);
440
 
482
 
441
        if (!mPage.sr[0].bm.empty())
483
        if (!mPage.sr[0].bm.empty())
442
        {
484
        {
443
            MSG_DEBUG("Loading image " << mPage.sr[0].bm);
485
            MSG_DEBUG("Loading image " << mPage.sr[0].bm);
444
            sk_sp<SkData> rawImage = readImage(mPage.sr[0].bm);
486
            sk_sp<SkData> rawImage = readImage(mPage.sr[0].bm);
Line 603... Line 645...
603
        setScreenDone();
645
        setScreenDone();
604
#endif
646
#endif
605
        return;
647
        return;
606
    }
648
    }
607
 
649
 
-
 
650
    if (sr.empty())
-
 
651
    {
-
 
652
        MSG_WARNING("Page " << mPage.name << " (" << mPage.pageID << "): The SR is empty!");
-
 
653
    }
-
 
654
 
-
 
655
    if (sr.size() > 0)
608
    target.eraseColor(TColor::getSkiaColor(sr[0].cf));
656
        target.eraseColor(TColor::getSkiaColor(sr[0].cf));
-
 
657
    else
-
 
658
        target.eraseColor(SK_ColorTRANSPARENT);
-
 
659
 
609
    // Draw the background, if any
660
    // Draw the background, if any
610
    if (sr.size() > 0 && (!sr[0].bm.empty() || !sr[0].mi.empty()))
661
    if (sr.size() > 0 && (!sr[0].bm.empty() || !sr[0].mi.empty() || sr[0].bitmaps.size() > 0))
611
    {
662
    {
612
        TDrawImage dImage;
663
        TDrawImage dImage;
613
        dImage.setWidth(mPage.width);
664
        dImage.setWidth(mPage.width);
614
        dImage.setHeight(mPage.height);
665
        dImage.setHeight(mPage.height);
-
 
666
        dImage.setSr(sr);
615
 
667
 
616
        if (!sr[0].bm.empty())
668
        if (!TTPInit::isTP5() && !sr[0].bm.empty())
617
        {
669
        {
618
            MSG_DEBUG("Loading image " << sr[0].bm);
670
            MSG_DEBUG("Loading image " << sr[0].bm);
619
            sk_sp<SkData> rawImage = readImage(sr[0].bm);
671
            sk_sp<SkData> rawImage = readImage(sr[0].bm);
620
            SkBitmap bm;
672
            SkBitmap bm;
621
 
673
 
Line 640... Line 692...
640
                {
692
                {
641
                    MSG_WARNING("BM image " << sr[0].bm << " seems to be empty!");
693
                    MSG_WARNING("BM image " << sr[0].bm << " seems to be empty!");
642
                }
694
                }
643
            }
695
            }
644
        }
696
        }
-
 
697
        else if (TTPInit::isTP5() && sr[0].bitmaps.size() > 0)
-
 
698
        {
-
 
699
            vector<BITMAPS_t>::iterator iter;
-
 
700
            SkBitmap image;
-
 
701
 
-
 
702
            for (iter = sr[0].bitmaps.begin(); iter != sr[0].bitmaps.end(); ++iter)
-
 
703
            {
-
 
704
                MSG_DEBUG("Loading TP5 image " << iter->fileName);
-
 
705
                sk_sp<SkData> rawImage = readImage(iter->fileName);
-
 
706
                SkBitmap bm;
-
 
707
 
-
 
708
                if (rawImage && !rawImage->isEmpty())
-
 
709
                {
-
 
710
                    MSG_DEBUG("Decoding image BM ...");
-
 
711
 
-
 
712
                    if (!DecodeDataToBitmap(rawImage, &bm))
-
 
713
                    {
-
 
714
                        MSG_WARNING("Problem while decoding image " << iter->fileName);
-
 
715
                    }
-
 
716
                    else if (!bm.isNull() && !bm.empty())
-
 
717
                    {
-
 
718
                        dImage.setImageBm(bm);
-
 
719
                        SkImageInfo info = bm.info();
-
 
720
                        haveImage = true;
-
 
721
                        MSG_DEBUG("Image " << iter->fileName << " has dimension " << bm.width() << " x " << bm.height());
-
 
722
                    }
-
 
723
                    else
-
 
724
                    {
-
 
725
                        MSG_WARNING("BM image " << sr[0].bm << " seems to be empty!");
-
 
726
                    }
-
 
727
                }
-
 
728
            }
-
 
729
        }
645
 
730
 
646
        MSG_DEBUG("haveImage: " << (haveImage ? "TRUE" : "FALSE"));
731
        MSG_DEBUG("haveImage: " << (haveImage ? "TRUE" : "FALSE"));
647
 
732
 
648
        if (!sr[0].mi.empty())
733
        if (!sr[0].mi.empty())
649
        {
734
        {
Line 730... Line 815...
730
                SkRect rect = SkRect::MakeXYWH(left, top, lwidth, lheight);
815
                SkRect rect = SkRect::MakeXYWH(left, top, lwidth, lheight);
731
                can.drawImageRect(im, rect, &paint);
816
                can.drawImageRect(im, rect, &paint);
732
                MSG_DEBUG("Scaled size of background image: " << left << ", " << top << ", " << lwidth << ", " << lheight);
817
                MSG_DEBUG("Scaled size of background image: " << left << ", " << top << ", " << lwidth << ", " << lheight);
733
            }
818
            }
734
#endif
819
#endif
735
/*
-
 
736
            TBitmap image((unsigned char *)target.getPixels(), target.info().width(), target.info().height());
-
 
737
#ifdef _OPAQUE_SKIA_
-
 
738
            if (sr[0].te.empty() && sr[0].bs.empty())
-
 
739
                _setBackground(handle, image, target.info().width(), target.info().height(), TColor::getColor(sr[0].cf));
-
 
740
#else
-
 
741
            if (sr[0].te.empty() && sr[0].bs.empty())
-
 
742
                _setBackground(handle, image, target.info().width(), target.info().height(), TColor::getColor(sr[0].cf), sr[0].oo);
-
 
743
#endif
-
 
744
*/
-
 
745
        }
820
        }
746
    }
821
    }
747
 
822
 
748
    if (sr.size() > 0 && !sr[0].te.empty())
823
    if (sr.size() > 0 && !sr[0].te.empty())
749
    {
824
    {
Line 752... Line 827...
752
        if (drawText(mPage, &target))
827
        if (drawText(mPage, &target))
753
            haveImage = true;
828
            haveImage = true;
754
    }
829
    }
755
 
830
 
756
    // Check for a frame and draw it if there is one.
831
    // Check for a frame and draw it if there is one.
757
    if (!sr[0].bs.empty())
832
    if (sr.size() > 0 && !sr[0].bs.empty())
758
    {
833
    {
759
        if (drawFrame(mPage, &target))
834
        if (drawFrame(mPage, &target))
760
            haveImage = true;
835
            haveImage = true;
761
    }
836
    }
762
 
837
 
763
    if (haveImage)
838
    if (haveImage)
764
    {
839
    {
765
        SkImageInfo info = target.info();
840
        SkImageInfo info = target.info();
766
        TBitmap image((unsigned char *)target.getPixels(), info.width(), info.height());
841
        TBitmap image((unsigned char *)target.getPixels(), info.width(), info.height());
-
 
842
 
-
 
843
        if (sr.size() > 0)
-
 
844
        {
767
#ifdef _OPAQUE_SKIA_
845
#ifdef _OPAQUE_SKIA_
768
        _setBackground(handle, image, target.info().width(), target.info().height(), TColor::getColor(sr[0].cf));
846
            _setBackground(handle, image, target.info().width(), target.info().height(), TColor::getColor(sr[0].cf));
769
#else
847
#else
770
        _setBackground(handle, image, target.info().width(), target.info().height(), TColor::getColor(sr[0].cf), sr[0].oo);
848
            _setBackground(handle, image, target.info().width(), target.info().height(), TColor::getColor(sr[0].cf), sr[0].oo);
771
#endif
849
#endif
-
 
850
        }
772
    }
851
    }
773
    else if (sr.size() > 0 && !haveImage)
852
    else if (sr.size() > 0 && !haveImage)
774
    {
853
    {
775
        MSG_DEBUG("Calling \"setBackground\" with no image ...");
854
        MSG_DEBUG("Calling \"setBackground\" with no image ...");
776
#ifdef _OPAQUE_SKIA_
855
#ifdef _OPAQUE_SKIA_