summaryrefslogtreecommitdiff
path: root/channeljump.c
blob: 58fa77f38daa91f605be90fe5afbdd719d6ee2d9 (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
#include <vdr/channels.h>
#include "config.h"
#include "geometrymanager.h"
#include "osdmanager.h"
#include "fontmanager.h"
#include "channelgroups.h"
#include "channeljump.h"

cChannelJump::cChannelJump(cChannelGroups *channelGroups) {
    this->channelGroups = channelGroups;
    pixmapText = NULL;
    channel = 0;
	if (!tvguideConfig.hideLastGroup) {
        maxChannels = Channels.MaxNumber();
	} else {
        maxChannels = channelGroups->GetLastValidChannel();
    }
    timeout = Setup.ChannelEntryTimeout;
    startTime = cTimeMs::Now();
    SetPixmaps();
    Draw();
}

cChannelJump::~cChannelJump(void) {
    osdManager.releasePixmap(pixmapBack);
    osdManager.releasePixmap(pixmapText);
}

void cChannelJump::SetPixmaps(void) {
	int x = (geoManager.osdWidth - geoManager.channelJumpWidth)/2;
	int y = (geoManager.osdHeight - geoManager.channelJumpHeight)/2;
	
	pixmapBack = osdManager.requestPixmap(4, cRect(x, y, geoManager.channelJumpWidth, geoManager.channelJumpHeight));
	pixmap = osdManager.requestPixmap(5, cRect(x, y, geoManager.channelJumpWidth, geoManager.channelJumpHeight));
	pixmapText = osdManager.requestPixmap(6, cRect(x, y, geoManager.channelJumpWidth, geoManager.channelJumpHeight));
}

void cChannelJump::Draw(void) {
	if (tvguideConfig.style == eStyleGraphical) {
        drawBackgroundGraphical(bgChannelJump);
	} else {
        pixmap->Fill(theme.Color(clrBackground));
        drawBorder();
	}
	pixmapBack->Fill(clrTransparent);
	pixmapBack->DrawRectangle(cRect(5, Height()/2, Width()-10, Height()-3), theme.Color(clrBackground));
}

void cChannelJump::DrawText(void) {
    pixmapText->Fill(clrTransparent);

    cString header = cString::sprintf("%s:", tr("Channel"));

	const cFont *font = fontManager.FontMessageBox;
	const cFont *fontHeader = fontManager.FontMessageBoxLarge;

	int xHeader = (Width() - fontHeader->Width(*header)) / 2;
	int yHeader = (Height()/2 - fontHeader->Height()) / 2;
	pixmapText->DrawText(cPoint(xHeader, yHeader), *header, theme.Color(clrFont), clrTransparent, fontHeader);

	cString strChannel = BuildChannelString();
	int xChannel = (Width() - font->Width(*strChannel)) / 2;
	int yChannel = Height()/2 + (Height()/2 - font->Height()) / 2;
	pixmapText->DrawText(cPoint(xChannel, yChannel), *strChannel, theme.Color(clrFont), clrTransparent, font);

}

void cChannelJump::Set(int num) {
    startTime = cTimeMs::Now();
    if (channel == 0) {
	    channel = num;
	    return;
    }
    int newChannel = channel * 10 + num;
    if (newChannel <= maxChannels)
    	channel = newChannel;
}

cString cChannelJump::BuildChannelString(void) {
	if (channel*10 <= maxChannels)
		return cString::sprintf("%d-", channel);
	else
		return cString::sprintf("%d", channel); 
}

 bool cChannelJump::TimeOut(void) {
 	if ((cTimeMs::Now() - startTime) > timeout)
	 	return true;
	return false;
 }