summaryrefslogtreecommitdiff
path: root/textwindow.c
blob: 71e020e9cc76e994e86531bd4c1de0d84403d837 (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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#include "textwindow.h"

cNopacityTextWindow::cNopacityTextWindow(cOsd *osd, cFont *font, cRect *vidWin) {
    this->osd = osd;
    this->font = font;
    this->vidWin = vidWin;
    pixmapBackground = NULL;
    pixmap = NULL;
    scaledWindow = false;
}

cNopacityTextWindow::~cNopacityTextWindow(void) {
    Cancel(-1);
    while (Active())
        cCondWait::SleepMs(10);
    if (pixmapBackground) {
        osd->DestroyPixmap(pixmapBackground);
        pixmapBackground = NULL;
    }
    if (pixmap) {
        osd->DestroyPixmap(pixmap);
        pixmap = NULL;
    }
    if ((config.scalePicture == 2) && scaledWindow) {
        cRect vidWinNew = cDevice::PrimaryDevice()->CanScaleVideo(oldVidWin);
        if (vidWinNew != cRect::Null) {
            vidWin->SetX(vidWinNew.X());
            vidWin->SetY(vidWinNew.Y());
            vidWin->SetWidth(vidWinNew.Width());
            vidWin->SetHeight(vidWinNew.Height());
        }
    }
}

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 - (lineHeight/2)) > drawportHeight) {
        drawportHeight = pixmapTotalHeight;
        scrolling = true;
    }
    cPixmap::Lock();
    pixmapBackground = osd->CreatePixmap(4, cRect(geometry->X(), geometry->Y(), geometry->Width(), geometry->Height()));
    pixmap = osd->CreatePixmap(5, cRect(geometry->X(), geometry->Y(), geometry->Width(), geometry->Height()),
                                  cRect(0, 0, geometry->Width(), drawportHeight));
    pixmapBackground->SetAlpha(0);
    pixmapBackground->Fill(clrBlack);
    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);

    if (config.scalePicture == 2) {
        oldVidWin.SetX(vidWin->X());
        oldVidWin.SetY(vidWin->Y());
        oldVidWin.SetWidth(vidWin->Width());
        oldVidWin.SetHeight(vidWin->Height());
        cRect availableRect(vidWin->X(), vidWin->Y(), vidWin->Width(), vidWin->Height() - geometry->Height());
        cRect vidWinNew = cDevice::PrimaryDevice()->CanScaleVideo(availableRect);
        if (vidWinNew != cRect::Null) {
            vidWin->SetX(vidWinNew.X());
            vidWin->SetY(vidWinNew.Y());
            vidWin->SetWidth(vidWinNew.Width());
            vidWin->SetHeight(vidWinNew.Height());
            scaledWindow = true;
        }
    }
    
    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;
            pixmapBackground->SetAlpha(Alpha);
            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);
        }
    }
}