summaryrefslogtreecommitdiff
path: root/timeline.c
blob: 4355352dc125a98d6c0c0825dd9bfd3080efdb1c (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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
#include "timeline.h"

cTimeLine::cTimeLine(cMyTime *myTime) {
    this->myTime = myTime;
    if (tvguideConfig.displayMode == eVertical) {
        dateViewer = new cStyledPixmap(osdManager.requestPixmap(1, cRect(0, 
                                                                         tvguideConfig.statusHeaderHeight, 
                                                                         tvguideConfig.timeLineWidth, 
                                                                         tvguideConfig.channelHeaderHeight + tvguideConfig.channelGroupsHeight)));
        timeline = osdManager.requestPixmap(1, cRect(0, 
                                                     tvguideConfig.statusHeaderHeight + tvguideConfig.channelHeaderHeight + tvguideConfig.channelGroupsHeight, 
                                                     tvguideConfig.timeLineWidth, 
                                                     tvguideConfig.osdHeight - tvguideConfig.statusHeaderHeight - tvguideConfig.channelHeaderHeight - tvguideConfig.channelGroupsHeight - tvguideConfig.footerHeight)
                                             , cRect(0,
                                                     0, 
                                                     tvguideConfig.timeLineWidth, 
                                                     1440*tvguideConfig.minutePixel));
    } else if (tvguideConfig.displayMode == eHorizontal) {
        dateViewer = new cStyledPixmap(osdManager.requestPixmap(1, cRect(0, 
                                                                         tvguideConfig.statusHeaderHeight, 
                                                                         tvguideConfig.channelHeaderWidth + tvguideConfig.channelGroupsWidth,
                                                                         tvguideConfig.timeLineHeight)));
        timeline = osdManager.requestPixmap(1, cRect(tvguideConfig.channelHeaderWidth + tvguideConfig.channelGroupsWidth, 
                                                     tvguideConfig.statusHeaderHeight, 
                                                     tvguideConfig.osdWidth - tvguideConfig.channelHeaderWidth - tvguideConfig.channelGroupsWidth,
                                                     tvguideConfig.timeLineHeight)
                                             , cRect(0,
                                                     0, 
                                                     1440*tvguideConfig.minutePixel, 
                                                     tvguideConfig.timeLineWidth));
    }
    clock = new cStyledPixmap(osdManager.requestPixmap(1, cRect(0, 
                                                                tvguideConfig.osdHeight- tvguideConfig.footerHeight, 
                                                                tvguideConfig.timeLineWidth, 
                                                                tvguideConfig.footerHeight-9)));
}

cTimeLine::~cTimeLine(void) {
    delete dateViewer;
    osdManager.releasePixmap(timeline);
    if (clock)
        delete clock;
}

void cTimeLine::drawDateViewer() {
    cString weekDay = myTime->GetWeekday();
    cString date = myTime->GetDate();   
    dateViewer->setColor(theme.Color(clrHeader), theme.Color(clrHeaderBlending));
    dateViewer->drawBackground();
    dateViewer->drawBorder();
    tColor colorFontBack = (tvguideConfig.useBlending==0)?theme.Color(clrHeader):clrTransparent;

    if (tvguideConfig.displayMode == eVertical) {
        int textHeight = tvguideConfig.FontTimeLineWeekday->Height();
        int weekdayWidth = tvguideConfig.FontTimeLineWeekday->Width(*weekDay);
        int dateWidth = tvguideConfig.FontTimeLineDate->Width(*date);
        dateViewer->DrawText(cPoint((tvguideConfig.timeLineWidth-weekdayWidth)/2, (tvguideConfig.channelHeaderHeight + tvguideConfig.channelGroupsHeight -2*textHeight)/2), *weekDay, theme.Color(clrFontHeader), colorFontBack, tvguideConfig.FontTimeLineWeekday);
        dateViewer->DrawText(cPoint((tvguideConfig.timeLineWidth-dateWidth)/2, (tvguideConfig.channelHeaderHeight + tvguideConfig.channelGroupsHeight -2*textHeight)/2 + textHeight + 5), *date, theme.Color(clrFontHeader), colorFontBack, tvguideConfig.FontTimeLineDate);
    } else if (tvguideConfig.displayMode == eHorizontal) {
        cString strDate = cString::sprintf("%s %s", *weekDay, *date);
        int x = (dateViewer->Width() - tvguideConfig.FontTimeLineDateHorizontal->Width(*strDate))/2;
        int y = (dateViewer->Height() - tvguideConfig.FontTimeLineDateHorizontal->Height())/2;
        dateViewer->DrawText(cPoint(x, y), *strDate, theme.Color(clrFontHeader), colorFontBack, tvguideConfig.FontTimeLineDateHorizontal);
    }
}

void cTimeLine::drawTimeline() {
    timeline->SetTile(true);
    timeline->Fill(theme.Color(clrBackground));
    tColor colorFont, colorBackground;
    
    int imgWidth, imgHeight;
    if (tvguideConfig.displayMode == eVertical) {
        imgWidth = tvguideConfig.timeLineWidth-4;
        imgHeight = tvguideConfig.minutePixel*30;
    } else if (tvguideConfig.displayMode == eHorizontal) {
        imgWidth = tvguideConfig.minutePixel*30;
        imgHeight = tvguideConfig.timeLineHeight-4;
    }
    const cImage *img1 = createBackgroundImage(imgWidth, imgHeight, theme.Color(clrTimeline1), theme.Color(clrTimeline1Blending));
    const cImage *img2 = createBackgroundImage(imgWidth, imgHeight, theme.Color(clrTimeline2), theme.Color(clrTimeline2Blending));
    const cImage *img = NULL;
    
    int textWidth, posX, posY;
    char timetext[10];
    
    for (int i=0; i<48; i++) {
        if (i%2==0) {
            img = img1;
            colorFont = theme.Color(clrTimeline2);
            colorBackground = (tvguideConfig.useBlending==0)?theme.Color(clrTimeline1):clrTransparent;
            if (tvguideConfig.timeFormat == e12Hours) {
                if (i == 0)
                    sprintf(timetext, "12:00 PM");
                else if (i/2 < 13)
                    sprintf(timetext, "%d:00 AM", i/2);
                else 
                    sprintf(timetext, "%d:00 PM", i/2-12);
            } else {
                sprintf(timetext, "%d:00", i/2);
            }
        } else {
            img = img2;
            colorFont = theme.Color(clrTimeline1);
            colorBackground = (tvguideConfig.useBlending==0)?theme.Color(clrTimeline2):clrTransparent;
            if (tvguideConfig.timeFormat == e12Hours) {
                if (i == 1)
                    sprintf(timetext, "12:30 PM");
                else if (i/2 < 13)
                    sprintf(timetext, "%d:30 AM", i/2);
                else 
                    sprintf(timetext, "%d:30 PM", i/2-12);
            } else {
                sprintf(timetext, "%d:30", i/2);
            }
        }
        if (tvguideConfig.displayMode == eVertical) {
            posY = i*tvguideConfig.minutePixel*30;
            timeline->DrawImage(cPoint(2, posY), *img);
            textWidth = tvguideConfig.FontTimeLineTime->Width(timetext);
            timeline->DrawText(cPoint((tvguideConfig.timeLineWidth-textWidth)/2, posY + 5), timetext, colorFont, colorBackground, tvguideConfig.FontTimeLineTime);
        } else if (tvguideConfig.displayMode == eHorizontal) {
            posX = i*tvguideConfig.minutePixel*30;
            timeline->DrawImage(cPoint(posX, 2), *img);
            timeline->DrawText(cPoint(posX + 2, (dateViewer->Height() - tvguideConfig.FontTimeLineTimeHorizontal->Height())/2), timetext, colorFont, colorBackground, tvguideConfig.FontTimeLineTimeHorizontal);
       }
    }
    setTimeline();
    delete img1;
    delete img2;
}

cImage *cTimeLine::createBackgroundImage(int width, int height, tColor clrBgr, tColor clrBlend) {
    cImage *image = NULL;
    if (tvguideConfig.useBlending == 1) {
        image = new cImage(cSize(width, height));
        image->Fill(clrBgr);
        int stepY = 0.5*height / 64;
        int alpha = 0x00;
        tColor clr;
        for (int i = 0; i<64; i++) {
            clr = AlphaBlend(clrBgr, clrBlend, alpha);
            for (int y = i*stepY; y < (i+1)*stepY; y++) {
                for (int x=0; x<width; x++) {
                    image->SetPixel(cPoint(x,y), clr);
                }
            }
            alpha += 0x04;
        }
    } else  if (tvguideConfig.useBlending == 2) {
        cImageLoader imgLoader;
        if (imgLoader.DrawBackground(clrBgr, clrBlend, width, height)) {
            image = new cImage(imgLoader.GetImage());
        }
    } else {
        image = new cImage(cSize(width, height));
        image->Fill(clrBgr);
    }
    return image;
}

void cTimeLine::setTimeline() {
    int offset = myTime->GetTimelineOffset();
    int xNew, yNew;
    if (tvguideConfig.displayMode == eVertical) {
        xNew = 0;
        yNew = -offset*tvguideConfig.minutePixel;
    } else if (tvguideConfig.displayMode == eHorizontal) {
        xNew = -offset*tvguideConfig.minutePixel;
        yNew = 0;
    }
    timeline->SetDrawPortPoint(cPoint(xNew, yNew));
}

void cTimeLine::drawClock() {
    cString currentTime = myTime->GetCurrentTime();
    int textHeight = tvguideConfig.FontTimeLineTime->Height();
    int clockWidth = tvguideConfig.FontTimeLineTime->Width(*currentTime);
    tColor colorFontBack = (tvguideConfig.useBlending==0)?theme.Color(clrHeader):clrTransparent;
    clock->setColor(theme.Color(clrHeader), theme.Color(clrHeaderBlending));
    clock->drawBackground();
    clock->drawBorder();
    clock->DrawText(cPoint((tvguideConfig.timeLineWidth-clockWidth)/2, (tvguideConfig.footerHeight-textHeight)/2), *currentTime, theme.Color(clrFontHeader), colorFontBack, tvguideConfig.FontTimeLineTime);
}