summaryrefslogtreecommitdiff
path: root/textwindow.c
blob: 72f3c1bc39997f1c841ede3dc9a1a40bb87ee905 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#include "textwindow.h"

cNopacityTextWindow::cNopacityTextWindow(cOsd *osd, cFont *font) {
    this->osd = osd;
    this->font = font;
    pixmap = NULL;
}

cNopacityTextWindow::~cNopacityTextWindow(void) {
    Cancel(-1);
    while (Active())
        cCondWait::SleepMs(10);
    if (pixmap) {
        osd->DestroyPixmap(pixmap);
        pixmap = NULL;
    }
}

bool cNopacityTextWindow::CreatePixmap(int border) {
    int lineHeight = font->Height();
    bool scrolling = false;
    twText.Set(text, font, geometry->Width() - 2*border);
    int pixmapTotalHeight = lineHeight * (twText.Lines()+1);
    int drawportHeight = geometry->Height();
    if (pixmapTotalHeight > drawportHeight) {
        drawportHeight = pixmapTotalHeight;
        scrolling = true;
    }
    cPixmap::Lock();
    pixmap = osd->CreatePixmap(4, cRect(geometry->X(), geometry->Y(), geometry->Width(), geometry->Height()),
                                  cRect(0, 0, geometry->Width(), drawportHeight));
    pixmap->SetAlpha(0);
    pixmap->Fill(Theme.Color(clrMenuBorder));
    pixmap->DrawRectangle(cRect(1, 1, geometry->Width()-2, drawportHeight-2), Theme.Color(clrMenuBack));
    cPixmap::Unlock();
    return scrolling;
}

void cNopacityTextWindow::DrawText(int border) {
    int lineHeight = font->Height();
    int currentLineHeight = lineHeight/2;
    cPixmap::Lock();
    for (int i=0; (i < twText.Lines()) && Running(); i++) {
        pixmap->DrawText(cPoint(border, currentLineHeight), twText.GetLine(i), Theme.Color(clrMenuFontButton), clrTransparent, font);
        currentLineHeight += lineHeight;
    }
    cPixmap::Unlock();        
}

void cNopacityTextWindow::DoSleep(int duration) {
    int sleepSlice = 10;
    for (int i = 0; Running() && (i*sleepSlice < duration); i++)
        cCondWait::SleepMs(sleepSlice);
}
   
void cNopacityTextWindow::Action(void) {
    DoSleep(config.menuInfoTextDelay*1000);
   
    int border = 5;
    bool scrolling = false;
    if (Running()) {
        scrolling = CreatePixmap(border);
    }
    if (Running()) {
        DrawText(border);
    }
    //FadeIn
    if (config.menuEPGWindowFadeTime) {
        uint64_t Start = cTimeMs::Now();
        int FadeTime = config.menuEPGWindowFadeTime;
        int FadeFrameTime = config.menuEPGWindowFrameTime;
        while (Running()) {
            uint64_t Now = cTimeMs::Now();
            cPixmap::Lock();
            double t = min(double(Now - Start) / FadeTime, 1.0);
            int Alpha = t * ALPHA_OPAQUE;
            pixmap->SetAlpha(Alpha);
            if (Running())
                osd->Flush();
            cPixmap::Unlock();
            int Delta = cTimeMs::Now() - Now;
            if (Running() && (Delta < FadeFrameTime))
                cCondWait::SleepMs(FadeFrameTime - Delta);
            if ((int)(Now - Start) > FadeTime)
                break;
        }
    }
    
    if (scrolling && Running()) {
        int scrollDelay = config.menuInfoScrollDelay * 1000;
        DoSleep(scrollDelay);
        int drawPortY;
        int FrameTime = config.menuInfoScrollFrameTime;
        int maxY = pixmap->DrawPort().Height() - pixmap->ViewPort().Height();
        bool doSleep = false;
        while (Running()) {
            uint64_t Now = cTimeMs::Now();
            cPixmap::Lock();
            drawPortY = pixmap->DrawPort().Y();
            drawPortY -= 1;
            cPixmap::Unlock();
            if (abs(drawPortY) > maxY) {
                doSleep = true;
                DoSleep(scrollDelay);
                drawPortY = 0;
            }
            cPixmap::Lock();
            if (Running())
                pixmap->SetDrawPortPoint(cPoint(0, drawPortY));
            cPixmap::Unlock();
            if (doSleep) {
                doSleep = false;
                DoSleep(scrollDelay);
            }
            int Delta = cTimeMs::Now() - Now;
            if (Running())
                osd->Flush();
            if (Running() && (Delta < FrameTime))
                cCondWait::SleepMs(FrameTime - Delta);
        }
    }
}