]> git.vomp.tv Git - vompclient.git/blob - vteletextview.cc
Log conversion
[vompclient.git] / vteletextview.cc
1 /*
2     Copyright 2005-2020 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, see <https://www.gnu.org/licenses/>.
18 */
19
20 #include <math.h>
21
22 #include "log.h"
23 #include "video.h"
24 #include "boxstack.h"
25 #include "input.h"
26 #include "playervideolive.h"
27
28 #include "vteletextview.h"
29
30 VTeletextView::VTeletextView(TeletextDecoderVBIEBU* TTdecoder, Boxx* playerview, PlayerVideoLive* playerObj)
31 {   
32   ttdecoder = TTdecoder;
33   pv = playerview;
34   player = playerObj;
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
49   createBuffer();
50   keyindigit = 1;
51   page = 0x100;
52 }
53
54 VTeletextView::~VTeletextView()
55 {
56   LogNT::getInstance()->debug("VTeletextView", "destruct");
57   pv->draw();
58   BoxStack::getInstance()->update(pv);
59   ttdecoder->unRegisterTeletextView(this);
60 }
61
62 void VTeletextView::draw(bool completedraw, bool onlyfirstline)
63 {
64   LogNT::getInstance()->error("VTeletextView", "Start draw");
65   Boxx::draw();
66   int x, y;
67     
68   Boxx* drawtarget = NULL;
69   int ox, oy;
70   for (y = 0; y < 25; y++)
71   {
72     if (y == 0)
73     {
74       drawtarget = this;
75       ox = 0;
76       oy = 0;
77     }
78     else
79     {
80       drawtarget = pv;
81       ox = this->getScreenX();
82       oy = this->getScreenY();
83     }
84
85     for (x = 0; x < 40; x++)
86     {
87       if (ttdecoder->isDirty(x, y) || completedraw)
88       {
89         cTeletextChar c = ttdecoder->getChar(x, y);
90         c.SetDirty(false);
91         //Skip Blinking and conceal
92         drawtarget->drawTTChar(ox, oy, x, y, c);
93         ttdecoder->setChar(x, y, c);
94       }
95     }
96 //    LogNT::getInstance()->error("VTeletextView", "Line {}", y);
97     if (onlyfirstline) break;
98   }
99   //  LogNT::getInstance()->error("VTeletextView", "Start end");
100 }
101
102 int VTeletextView::handleCommand(int command)
103 {
104     if (subtitlemode) return 0; //Ok we are in subtitle mode, we are a slave of the player
105     switch (command)
106     {
107       case Input::OK:
108         return 2;
109       case Input::BACK:
110         if(player) player->tellSubtitlesOSDVisible(false); // Only on liveTV
111         return 4;
112       case Input::ZERO:
113       case Input::ONE:
114       case Input::TWO:
115       case Input::THREE:
116       case Input::FOUR:
117       case Input::FIVE:
118       case Input::SIX:
119       case Input::SEVEN:
120       case Input::EIGHT:
121       case Input::NINE:
122       {
123         // key in teletext page
124         doKey(command);
125         return 2;
126       }
127     }
128
129     return 0;
130 }
131
132 void VTeletextView::doKey(int command)
133 {
134   char pagenums[3];
135   if (keyindigit == 1)
136   {
137     if (command == 9) return; //not allowed
138     page = command << 8;
139     pagenums[0] = static_cast<char>(command + 48);
140     pagenums[1] = '-';
141     pagenums[2] = '-';
142     keyindigit++;
143   }
144   else if (keyindigit == 2)
145   {
146     page |= command << 4;
147     pagenums[0] = static_cast<char>(48 + ((page & 0xF00) >> 8));
148     pagenums[1] = static_cast<char>(command + 48);
149     pagenums[2] = '-';
150     keyindigit++;
151   }
152   else if (keyindigit == 3)
153   {
154     page |= command;
155     pagenums[0] = static_cast<char>(48 + ((page & 0xF00) >> 8));
156     pagenums[1] = static_cast<char>(48 + ((page & 0x0F0) >> 4));
157     pagenums[2] = static_cast<char>(48 + command);
158     keyindigit = 1;
159     ttdecoder->setPage(page);
160   }
161
162   ttdecoder->setKeyinDigits(pagenums, true);
163   Region toupdate;
164   toupdate.w = 16 * 40;
165   if (Video::getInstance()->getFormat() == Video::PAL)
166   {
167     toupdate.h = 22;
168   }
169   else
170   {
171     toupdate.h = 18;
172   }
173   toupdate.x = 0;
174   toupdate.y = 0;
175
176   draw(false, true);
177   BoxStack::getInstance()->update(this, &toupdate);
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     {
194       toupdate.h = 22;
195     }
196     else
197     {
198       toupdate.h = 18;
199     }
200     toupdate.x = 0;
201     toupdate.y = 0;
202
203     draw(false, true);
204     BoxStack::getInstance()->update(this, &toupdate);
205   }
206 }