]> git.vomp.tv Git - vompclient.git/blob - vchannellist.cc
Screenshot support for vector based osd on raspberry pi
[vompclient.git] / vchannellist.cc
1 /*
2     Copyright 2004-2007 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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
19 */
20
21 #include "vchannellist.h"
22
23 #include "remote.h"
24 #include "wsymbol.h"
25 #include "vvideolivetv.h"
26 #include "colour.h"
27 #include "video.h"
28 #include "i18n.h"
29 #include "channel.h"
30 #include "message.h"
31 #include "boxstack.h"
32 #include "vchannelselect.h"
33
34 VChannelList::VChannelList(ULONG type)
35 {
36   boxstack = BoxStack::getInstance();
37   setSize(570, 420);
38   createBuffer();
39   if (Video::getInstance()->getFormat() == Video::PAL)
40   {
41     setPosition(80, 70);
42   }
43   else
44   {
45     setPosition(70, 35);
46   }
47
48   setTitleBarOn(1);
49
50   if (type == VDR::VIDEO)
51   {
52     setTitleText(tr("Channels"));
53   }
54   else if (type == VDR::RADIO)
55   {
56     setTitleText(tr("Radio Stations"));
57   }
58   setTitleBarColour(DrawStyle::TITLEBARBACKGROUND);
59
60   sl.setPosition(10, 30 + 5);
61   sl.setSize(area.w - 20, area.h - 30 - 15 - 30);
62   add(&sl);
63 }
64
65 VChannelList::~VChannelList()
66 {
67
68   if (chanList)
69   {
70     for (UINT i = 0; i < chanList->size(); i++)
71     {
72       delete (*chanList)[i];
73     }
74
75     chanList->clear();
76     delete chanList;
77   }
78 }
79
80 void VChannelList::setList(ChannelList* tlist)
81 {
82   char str[500];
83   OsdVector *osdv=dynamic_cast<OsdVector*>(Osd::getInstance());
84
85   sl.addColumn(0);
86   if (osdv) sl.addColumn(20);
87   sl.addColumn(60);
88
89   chanList = tlist;
90
91   Channel* chan;
92   int first = 1;
93   if (chanList)
94   {
95
96     for (UINT i = 0; i < chanList->size(); i++)
97     {
98       chan = (*chanList)[i];
99       sprintf(str, "%lu\t%s", chan->number, chan->name);
100       TVMediaInfo *info=NULL;
101       if (osdv) {
102           info= new TVMediaInfo();
103           info->setChannelLogo((*chanList)[i]->number);
104       }
105       chan->index = sl.addOption(str, (ULONG)chan, first, info);
106       first = 0;
107     }
108   }
109 }
110
111 void VChannelList::highlightChannel(Channel* chan)
112 {
113   sl.hintSetCurrent(chan->index);
114   sl.draw();
115   doShowingBar();
116   boxstack->update(this);
117 }
118
119 void VChannelList::draw()
120 {
121   TBBoxx::draw();
122   sl.draw();
123
124   // Put the status stuff at the bottom
125
126   WSymbol w;
127   TEMPADD(&w);
128
129   w.nextSymbol = WSymbol::UP;
130   w.setPosition(20, 385);
131   w.draw();
132
133   w.nextSymbol = WSymbol::DOWN;
134   w.setPosition(50, 385);
135   w.draw();
136
137   w.nextSymbol = WSymbol::SKIPBACK;
138   w.setPosition(85, 385);
139   w.draw();
140
141   w.nextSymbol = WSymbol::SKIPFORWARD;
142   w.setPosition(115, 385);
143   w.draw();
144
145   w.nextSymbol = WSymbol::PLAY;
146   w.setPosition(150, 385);
147   w.draw();
148
149   doShowingBar();
150 }
151
152 void VChannelList::doShowingBar()
153 {
154   int topOption = sl.getTopOption() + 1;
155   if (sl.getNumOptions() == 0) topOption = 0;
156
157   char showing[200];
158   sprintf(showing, tr("%i to %i of %i"), topOption, sl.getBottomOption(), sl.getNumOptions());
159 #ifndef GRADIENT_DRAWING
160   rectangle(220, 385,160, 25, DrawStyle::VIEWBACKGROUND);
161 #endif
162   drawText(showing, 220, 385, DrawStyle::LIGHTTEXT);
163 }
164
165 void VChannelList::quickUpdate() { //only quick for plattform that need it!
166 #ifdef GRADIENT_DRAWING
167       draw();
168 #else
169       sl.draw();
170       doShowingBar();
171 #endif
172 }
173
174 int VChannelList::handleCommand(int command)
175 {
176   switch(command)
177   {
178     case Remote::DF_UP:
179     case Remote::UP:
180     {
181       sl.up();
182       quickUpdate();
183
184       boxstack->update(this);
185       return 2;
186     }
187     case Remote::DF_DOWN:
188     case Remote::DOWN:
189     {
190       sl.down();
191       quickUpdate();
192
193       boxstack->update(this);
194       return 2;
195     }
196     case Remote::SKIPBACK:
197     {
198       sl.pageUp();
199       quickUpdate();
200
201       boxstack->update(this);
202       return 2;
203     }
204     case Remote::SKIPFORWARD:
205     {
206       sl.pageDown();
207       quickUpdate();
208
209       boxstack->update(this);
210       return 2;
211     }
212     case Remote::ZERO:
213     case Remote::ONE:
214     case Remote::TWO:
215     case Remote::THREE:
216     case Remote::FOUR:
217     case Remote::FIVE:
218     case Remote::SIX:
219     case Remote::SEVEN:
220     case Remote::EIGHT:
221     case Remote::NINE:
222     {
223       VChannelSelect* v = new VChannelSelect(this);
224       v->draw();
225       boxstack->add(v);
226       boxstack->update(v);
227       v->handleCommand(command);
228       return 2;
229     }
230     case Remote::OK:
231     case Remote::PLAY:
232     {
233       Channel* chan = NULL;
234       if (chanList) chan = (Channel*)sl.getCurrentOptionData();
235       if (chan == NULL) return 2;
236  
237       VVideoLiveTV* v = new VVideoLiveTV(chanList, chan->number, this);
238       boxstack->add(v);
239       v->go();
240
241       return 2;
242     }
243     case Remote::BACK:
244     {
245       return 4;
246     }
247   }
248   // stop command getting to any more views
249   return 1;
250 }
251
252 void VChannelList::processMessage(Message* m)
253 {
254  /* if (m->message == Message::MOUSE_MOVE) {
255         if (sl.mouseAndroidScroll((m->tag >> 16),(m->tag & 0xFFFF),
256                         (m->parameter >> 16),(m->parameter & 0xFFFF))) {
257                 sl.draw();
258                 doShowingBar();
259                 boxstack->update(this);
260         }
261   }
262   else */if (m->message == Message::MOUSE_MOVE)
263   {
264     if (sl.mouseMove((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
265     {
266       quickUpdate();
267       boxstack->update(this);
268     }
269   }
270   else if (m->message == Message::MOUSE_LBDOWN)
271   {
272     if (sl.mouseLBDOWN((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
273     {
274       boxstack->handleCommand(Remote::OK); //simulate OK press
275     }
276     else
277     { //check if press is outside this view! then simulate cancel
278       int x=(m->parameter>>16)-getScreenX();
279       int y=(m->parameter&0xFFFF)-getScreenY();
280       if (x<0 || y <0 || x>(int)getWidth() || y>(int)getHeight())
281       {
282         boxstack->handleCommand(Remote::BACK); //simulate cancel press
283       }
284     }
285   }
286   else if (m->message == Message::CHANNEL_CHANGE)
287   {
288     Channel* chan = NULL;
289     for (UINT i = 0; i < chanList->size(); i++)
290     {
291       if ((*chanList)[i]->number == m->parameter)
292       {
293         chan = (*chanList)[i];
294         break;
295       }
296     }
297     if (!chan) return;
298
299 /*    if (chan->type == VDR::VIDEO)
300     {*/
301       VVideoLiveTV* v = new VVideoLiveTV(chanList, chan->number, this);
302       boxstack->add(v);
303       v->go();    
304 /*    }
305     else
306     {
307     
308       VVideoLive* v = new VVideoLive(chanList, chan->type, this);
309       v->draw();
310       boxstack->add(v);
311       boxstack->update(v);
312       v->channelChange(VVideoLive::NUMBER, chan->number);
313     
314     }*/
315   }
316 }