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