summaryrefslogtreecommitdiff
path: root/osdmanager.c
blob: 9347f8c7f973f45f2fdcac6eb8b5a17bdf94eda2 (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
#include <string>
#include <sstream>

#ifndef __TVGUIDE_OSDMANAGER_H
#define __TVGUIDE_OSDMANAGER_H

class cOsdManager {
    private:
        cOsd *osd;
    public:
        cOsdManager(void);
        bool setOsd();
        void setBackground();
        void flush() {osd->Flush();};
        cPixmap *requestPixmap(int Layer, const cRect &ViewPort, const cRect &DrawPort = cRect::Null);
        void releasePixmap(cPixmap *pixmap);
        void deleteOsd() {delete osd;};
        int Width() { return osd->Width(); };
        int Height() { return osd->Height(); };
        int Top() { return osd->Top(); };
        int Left() { return osd->Left(); };
};

#endif //__TVGUIDE_OSDMANAGER_H

cOsdManager::cOsdManager(void) {
}

bool cOsdManager::setOsd() {
    osd = cOsdProvider::NewOsd(cOsd::OsdLeft(), cOsd::OsdTop());
    if (osd) {
        tArea Area = { 0, 0, cOsd::OsdWidth(), cOsd::OsdHeight(),  32 };
        if (osd->SetAreas(&Area, 1) == oeOk) {  
            return true;
        }
    }
    return false;
}

void cOsdManager::setBackground() {
esyslog("tvguide: %d %d", Width(), Height());
        
    if (tvguideConfig.displayStatusHeader && tvguideConfig.scaleVideo) {
        int widthStatus = cOsd::OsdWidth() - tvguideConfig.statusHeaderHeight * 16 / 9;
        osd->DrawRectangle(0, 0, widthStatus, tvguideConfig.statusHeaderHeight, theme.Color(clrBackgroundOSD));
        osd->DrawRectangle(0, tvguideConfig.statusHeaderHeight, Width(), Height(), theme.Color(clrBackgroundOSD));    
    }
    else
        osd->DrawRectangle(0, 0, Width(), Height(), theme.Color(clrBackgroundOSD));
}

cPixmap *cOsdManager::requestPixmap(int Layer, const cRect &ViewPort, const cRect &DrawPort) {
    return osd->CreatePixmap(Layer, ViewPort, DrawPort);
}

void cOsdManager::releasePixmap(cPixmap *pixmap) {
    if (!pixmap)
        return;
    osd->DestroyPixmap(pixmap);
}

static std::string CutText(std::string text, int width, const cFont *font) {
    if (width <= font->Size())
        return text.c_str();
    if (font->Width(text.c_str()) < width)
        return text.c_str();
    cTextWrapper twText;
    twText.Set(text.c_str(), font, width);
    std::string cuttedTextNative = twText.GetLine(0);
    std::stringstream sstrText;
    sstrText << cuttedTextNative << "...";
    std::string cuttedText = sstrText.str();
    int actWidth = font->Width(cuttedText.c_str());
    if (actWidth > width) {
        int overlap = actWidth - width;
        int charWidth = font->Width(".");
        if (charWidth == 0)
            charWidth = 1;
        int cutChars = overlap / charWidth;
        if (cutChars > 0) {
            cuttedTextNative = cuttedTextNative.substr(0, cuttedTextNative.length() - cutChars);
            std::stringstream sstrText2;
            sstrText2 << cuttedTextNative << "...";
            cuttedText = sstrText2.str();
        }
    }
    return cuttedText;
}