]> git.vomp.tv Git - vompclient.git/blob - vchannelselect.cc
Rewrite of ImageOMX to fix the PNG problem
[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, see <https://www.gnu.org/licenses/>.
18 */
19
20 #include "input.h"
21 #include "message.h"
22 #include "boxstack.h"
23 #include "colour.h"
24 #include "vdr.h"
25 #include "messagequeue.h"
26
27 #include "vchannelselect.h"
28
29 // this class only works as it does because the remote command
30 // values for the numbers are the numbers themselves !
31
32 VChannelSelect::VChannelSelect(MessageReceiver* v)
33 {
34   parent = v;
35   numGot = 0;
36   ignoreTimer = false;
37
38   numWidth = VDR::getInstance()->getChannelNumberWidth();
39   if (numWidth > 10) numWidth = 10;
40   for (int i = 0; i < numWidth; i++) input[i] = -1;
41
42   setSize((numWidth*10) + 22, 30); // 10 px = width of number chars in font
43   createBuffer();
44   setPosition(80, 60);
45   setBackgroundColour(DrawStyle::VIEWBACKGROUND);
46 }
47
48 VChannelSelect::~VChannelSelect()
49 {
50   Timers::getInstance()->cancelTimer(this, 1);
51 }
52
53 void VChannelSelect::timercall(int /*clientReference*/)
54 {
55   if (ignoreTimer) return;
56   changeChannel();
57 }
58
59 void VChannelSelect::doInput(int number)
60 {
61   for (int i = numGot - 1; i >= 0; i--)
62   {
63     input[i+1] = input[i];
64   }
65
66   input[0] = number;
67   numGot++;
68 }
69
70 void VChannelSelect::draw()
71 {
72   Boxx::draw();
73
74   // draw numbers
75   char text[2];
76
77   for (int i = 0; i < numWidth; i++)
78   {
79     if (input[i] == -1)
80     {
81       drawText("_", 7 + ((numWidth - 1 - i) * 10), 5, DrawStyle::LIGHTTEXT);
82     }
83     else
84     {
85       sprintf(text, "%i", input[i]);
86       drawText(text, 7 + ((numWidth - 1 - i) * 10), 5, DrawStyle::LIGHTTEXT);
87     }
88   }
89 }
90
91 void VChannelSelect::changeChannel()
92 {
93   ignoreTimer = true;
94   Timers::getInstance()->cancelTimer(this, 1);
95
96   Message* m;
97
98   // Is there valid data? (is any number not-zero)
99   int i = 0;
100   for(i = 0; i < numWidth; i++) if (input[i]) break;
101
102   if (i < numWidth) // There is data
103   {
104     m = new Message();
105     m->from = this;
106     m->to = parent;
107     m->message = Message::CHANNEL_CHANGE;
108     m->parameter = 0;
109
110     for(i = numGot - 1; i >= 0; i--)
111     {
112       m->parameter += input[i] * static_cast<ULONG>(pow(10., i));
113     }
114
115     MessageQueue::getInstance()->postMessage(m);
116   }
117
118   // Close me
119   m = new Message(); // Delete self
120   m->from = this;
121   m->p_to = Message::BOXSTACK;
122   m->message = Message::CLOSE_ME;
123   MessageQueue::getInstance()->postMessage(m);
124 }
125
126 int VChannelSelect::handleCommand(int command)
127 {
128   switch(command)
129   {
130     case Input::ZERO:
131     case Input::ONE:
132     case Input::TWO:
133     case Input::THREE:
134     case Input::FOUR:
135     case Input::FIVE:
136     case Input::SIX:
137     case Input::SEVEN:
138     case Input::EIGHT:
139     case Input::NINE:
140     {
141       doInput(command);
142       draw();
143       BoxStack::getInstance()->update(this);
144       if (numGot == numWidth) changeChannel();
145       else Timers::getInstance()->setTimerD(this, 1, 3);
146       return BoxStack::COMMAND_HANDLED;
147     }
148     case Input::OK:
149     {
150       changeChannel();
151       return BoxStack::COMMAND_HANDLED;
152     }
153   }
154
155   // allow command to drop through to other views
156   return BoxStack::DROP_THROUGH;
157 }