]> git.vomp.tv Git - vompclient.git/blob - vchannelselect.cc
Variable width channel numbers
[vompclient.git] / vchannelselect.cc
1 /*
2     Copyright 2004-2005 Chris Tallon
3
4     This file is part of VOMP.
5
6     VOMP is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10
11     VOMP is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with VOMP; if not, write to the Free Software
18     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19 */
20
21 #include "vchannelselect.h"
22
23 // this class only works as it does because the remote command
24 // values for the numbers are the numbers themselves !
25
26 VChannelSelect::VChannelSelect(View* v)
27 {
28   parent = v;
29   numGot = 0;
30   ignoreTimer = false;
31
32   numWidth = (int)VDR::getInstance()->getChannelNumberWidth();
33   if (numWidth > 10) numWidth = 10;
34   for (int i = 0; i < numWidth; i++) input[i] = -1;
35
36   create((numWidth*10) + 22, 30); // 10 px = width of number chars in font
37   setScreenPos(80, 60);
38   setBackgroundColour(Colour::VIEWBACKGROUND);
39 }
40
41 VChannelSelect::~VChannelSelect()
42 {
43   Timers::getInstance()->cancelTimer(this, 1);
44 }
45
46 void VChannelSelect::timercall(int clientReference)
47 {
48   Log::getInstance()->log("VChannelSelect", Log::DEBUG, "Timer call");
49   if (ignoreTimer) return;
50   changeChannel(false);
51 }
52
53 void VChannelSelect::doInput(int number)
54 {
55   for (int i = numGot - 1; i >= 0; i--)
56   {
57     input[i+1] = input[i];
58   }
59
60   input[0] = number;
61   numGot++;
62 }
63
64 void VChannelSelect::draw()
65 {
66   View::draw();
67
68   // draw numbers
69   char text[2];
70
71   for (int i = 0; i < numWidth; i++)
72   {
73     if (input[i] == -1)
74     {
75       drawText("_", 7 + ((numWidth - 1 - i) * 10), 5, Colour::LIGHTTEXT);
76     }
77     else
78     {
79       sprintf(text, "%i", input[i]);
80       drawText(text, 7 + ((numWidth - 1 - i) * 10), 5, Colour::LIGHTTEXT);
81     }
82   }
83 }
84
85 void VChannelSelect::changeChannel(bool which)
86 {
87   ignoreTimer = true;
88   Timers::getInstance()->cancelTimer(this, 1);
89
90   Message* m;
91
92   // Is there valid data? (is any number not-zero)
93   int i = 0;
94   for(i = 0; i < numWidth; i++) if (input[i]) break;
95
96   if (i < numWidth) // There is data
97   {
98     m = new Message();
99     m->from = this;
100     m->to = parent;
101     m->message = Message::CHANNEL_CHANGE;
102     m->parameter = 0;
103
104     for(i = numGot - 1; i >= 0; i--)
105     {
106       m->parameter += input[i] * (ULONG)pow(10, i);
107     }
108
109     if (which)
110       Command::getInstance()->postMessageNoLock(m);
111     else
112       Command::getInstance()->postMessageFromOuterSpace(m);
113   }
114
115   // Close me
116   m = new Message(); // Delete self
117   m->from = this;
118   m->to = ViewMan::getInstance();
119   m->message = Message::CLOSE_ME;
120   if (which)
121     Command::getInstance()->postMessageNoLock(m);
122   else
123     Command::getInstance()->postMessageFromOuterSpace(m);
124 }
125
126 int VChannelSelect::handleCommand(int command)
127 {
128   switch(command)
129   {
130     case Remote::ZERO:
131     case Remote::ONE:
132     case Remote::TWO:
133     case Remote::THREE:
134     case Remote::FOUR:
135     case Remote::FIVE:
136     case Remote::SIX:
137     case Remote::SEVEN:
138     case Remote::EIGHT:
139     case Remote::NINE:
140     {
141       doInput(command);
142       draw();
143       ViewMan::getInstance()->updateView(this);
144       if (numGot == numWidth) changeChannel(true);
145       else Timers::getInstance()->setTimerD(this, 1, 3);
146       return 2;
147     }
148   }
149
150   // allow command to drop through to other views
151   return 0;
152 }