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