]> git.vomp.tv Git - vompclient-marten.git/blob - vteletextview.cc
Apply JTE subtitles patch for not destroying OSD
[vompclient-marten.git] / vteletextview.cc
1 /*
2     Copyright 2005-2008 Chris Tallon, Marten Richter
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 #include <math.h>
21 #include "vteletextview.h"
22 #include "video.h"
23 #include "timers.h"
24 #include "boxstack.h"
25 #include "remote.h"
26 #include "playerlivetv.h"
27
28
29 VTeletextView::VTeletextView(TeletextDecoderVBIEBU* TTdecoder,Boxx* playerview, PlayerLiveTV* playerObj)
30 {   
31     ttdecoder=TTdecoder;
32     pv=playerview;
33     player=playerObj;
34     subtitlemode=false;
35     
36     
37
38     if (Video::getInstance()->getFormat() == Video::PAL)
39     { 
40         //setSize(680, 550);
41         setSize(680,22); //Only first line
42         setPosition(40, 26);
43     }
44     else
45     {
46         setPosition(40, 30);
47         //setSize(680, 450);
48         setSize(680,18);//only first line
49     }
50     createBuffer();
51     keyindigit=1;
52     page=0x100;
53     
54 }
55
56 VTeletextView::~VTeletextView ()
57 {
58     // Make sure the timer is deleted
59         Log::getInstance()->log("VTeletextView", Log::DEBUG, "VTeletextView destruct");
60   pv->draw();
61   BoxStack::getInstance()->update(pv);
62   Timers::getInstance()->cancelTimer(this, 1);
63   ttdecoder->unRegisterTeletextView(this);
64     
65 }
66
67 void VTeletextView::draw(bool completedraw, bool onlyfirstline)
68 {
69         //Log::getInstance()->log("VTeletextView", Log::ERR, "Start draw");
70     Boxx::draw();
71     int x,y;
72     
73     Boxx *drawtarget=NULL;
74     int ox,oy;
75     for (y=0;y<25;y++) {
76         if (y==0) {
77                 drawtarget=this;
78                 ox=0;
79                 oy=0;
80         } else {
81                 drawtarget=pv;
82                 ox=this->getScreenX();
83                 oy=this->getScreenY();
84         }
85
86         for (x=0;x<40;x++) {
87             if (ttdecoder->isDirty(x,y) || completedraw) {
88                 cTeletextChar c=ttdecoder->getChar(x,y);
89                 c.SetDirty(false);
90                 //Skip Blinking and conceal
91                 drawtarget->drawTTChar(ox,oy,x,y,c);
92                 ttdecoder->setChar(x,y,c);
93             }
94         }
95     //    Log::getInstance()->log("VTeletextView", Log::ERR, "Line %d",y);
96         if (onlyfirstline) break;
97     }
98   //  Log::getInstance()->log("VTeletextView", Log::ERR, "Start end");
99    
100     
101 }
102
103
104
105
106
107 int VTeletextView::handleCommand(int command) {
108     if (subtitlemode) return 0; //Ok we are in  subtitle mode, we are a slave of the player
109     switch (command) {
110     case Remote::OK:
111         return 2;
112     case Remote::BACK:
113         if(player) player->tellSubtitlesOSDVisible(false); // Only on liveTV
114         return 4;
115     case Remote::ZERO:
116     case Remote::ONE:
117     case Remote::TWO:
118     case Remote::THREE:
119     case Remote::FOUR:
120     case Remote::FIVE:
121     case Remote::SIX:
122     case Remote::SEVEN:
123     case Remote::EIGHT:
124     case Remote::NINE:
125     {
126       // key in teletext page
127       doKey(command);
128       return 2;
129     }
130     };
131
132     return 0;
133     
134 }
135
136 void VTeletextView::doKey(int command)
137 {
138     char pagenums[3];
139     if (keyindigit==1){
140         if (command==9) return; //not allowed
141         page=command<<8;
142         pagenums[0]=command+ 48;
143         pagenums[1]='-';
144         pagenums[2]='-';
145         keyindigit++;
146     } else if (keyindigit==2) {
147         page|=command<<4;
148         pagenums[0]=48+((page &0xF00)>>8);
149         pagenums[1]=command+ 48;
150         pagenums[2]='-';
151         keyindigit++;
152     } else if (keyindigit==3) {
153         page|=command;
154         pagenums[0]=48+((page &0xF00)>>8);
155         pagenums[1]=48+((page &0x0F0)>>4);
156         pagenums[2]=48+command;
157         keyindigit=1;
158         ttdecoder->setPage(page);
159     }
160     ttdecoder->setKeyinDigits(pagenums,true);
161     Region toupdate;
162     toupdate.w=16*40;
163     if (Video::getInstance()->getFormat() == Video::PAL) {
164         toupdate.h=22;
165         
166      } else {
167         toupdate.h=18;
168         
169       }
170      toupdate.x=0;
171      toupdate.y=0;
172             
173      draw(false,true);
174      BoxStack::getInstance()->update(this,&toupdate);
175
176 }
177
178 void VTeletextView::timercall(int clientReference)
179 {
180     
181 }
182
183 void VTeletextView::processMessage(Message* m)
184 {
185     if (m->message == Message::TELETEXTUPDATE)
186     {
187         draw(false,false);
188         BoxStack::getInstance()->update(this);
189         BoxStack::getInstance()->update(pv);
190
191     } else if (m->message == Message::TELETEXTUPDATEFIRSTLINE) 
192     {
193         Region toupdate;
194         toupdate.w=16*40;
195         if (Video::getInstance()->getFormat() == Video::PAL) {
196             toupdate.h=22;
197             
198         } else {
199             toupdate.h=18;
200             
201         }
202         toupdate.x=0;
203         toupdate.y=0;
204
205
206             
207         draw(false,true);
208         BoxStack::getInstance()->update(this,&toupdate);
209
210     }
211 }
212
213