]> git.vomp.tv Git - vompclient.git/blob - vteletextview.cc
Remove deprecated max() function
[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   MessageQueue::getInstance()->addReceiver(this);
54 }
55
56 VTeletextView::~VTeletextView()
57 {
58   MessageQueue::getInstance()->removeReceiver(this);
59   LogNT::getInstance()->debug("VTeletextView", "destruct");
60   pv->draw();
61   BoxStack::getInstance()->update(pv);
62   ttdecoder->unRegisterTeletextView(this);
63 }
64
65 void VTeletextView::draw(bool completedraw, bool onlyfirstline)
66 {
67   LogNT::getInstance()->error("VTeletextView", "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   {
75     if (y == 0)
76     {
77       drawtarget = this;
78       ox = 0;
79       oy = 0;
80     }
81     else
82     {
83       drawtarget = pv;
84       ox = this->getScreenX();
85       oy = this->getScreenY();
86     }
87
88     for (x = 0; x < 40; x++)
89     {
90       if (ttdecoder->isDirty(x, y) || completedraw)
91       {
92         cTeletextChar c = ttdecoder->getChar(x, y);
93         c.SetDirty(false);
94         //Skip Blinking and conceal
95         drawtarget->drawTTChar(ox, oy, x, y, c);
96         ttdecoder->setChar(x, y, c);
97       }
98     }
99 //    LogNT::getInstance()->error("VTeletextView", "Line {}", y);
100     if (onlyfirstline) break;
101   }
102   //  LogNT::getInstance()->error("VTeletextView", "Start end");
103 }
104
105 int VTeletextView::handleCommand(int command)
106 {
107     if (subtitlemode) return BoxStack::DROP_THROUGH; //Ok we are in subtitle mode, we are a slave of the player
108     switch (command)
109     {
110       case Input::OK:
111         return BoxStack::COMMAND_HANDLED;
112       case Input::BACK:
113         if(player) player->tellSubtitlesOSDVisible(false); // Only on liveTV
114         return BoxStack::DELETE_ME;
115       case Input::ZERO:
116       case Input::ONE:
117       case Input::TWO:
118       case Input::THREE:
119       case Input::FOUR:
120       case Input::FIVE:
121       case Input::SIX:
122       case Input::SEVEN:
123       case Input::EIGHT:
124       case Input::NINE:
125       {
126         // key in teletext page
127         doKey(command);
128         return BoxStack::COMMAND_HANDLED;
129       }
130     }
131
132     return BoxStack::DROP_THROUGH;
133 }
134
135 void VTeletextView::doKey(int command)
136 {
137   char pagenums[3];
138   if (keyindigit == 1)
139   {
140     if (command == 9) return; //not allowed
141     page = command << 8;
142     pagenums[0] = static_cast<char>(command + 48);
143     pagenums[1] = '-';
144     pagenums[2] = '-';
145     keyindigit++;
146   }
147   else if (keyindigit == 2)
148   {
149     page |= command << 4;
150     pagenums[0] = static_cast<char>(48 + ((page & 0xF00) >> 8));
151     pagenums[1] = static_cast<char>(command + 48);
152     pagenums[2] = '-';
153     keyindigit++;
154   }
155   else if (keyindigit == 3)
156   {
157     page |= command;
158     pagenums[0] = static_cast<char>(48 + ((page & 0xF00) >> 8));
159     pagenums[1] = static_cast<char>(48 + ((page & 0x0F0) >> 4));
160     pagenums[2] = static_cast<char>(48 + command);
161     keyindigit = 1;
162     ttdecoder->setPage(page);
163   }
164
165   ttdecoder->setKeyinDigits(pagenums, true);
166   Region toupdate;
167   toupdate.w = 16 * 40;
168   if (Video::getInstance()->getFormat() == Video::PAL)
169   {
170     toupdate.h = 22;
171   }
172   else
173   {
174     toupdate.h = 18;
175   }
176   toupdate.x = 0;
177   toupdate.y = 0;
178
179   draw(false, true);
180   BoxStack::getInstance()->update(this, &toupdate);
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     {
197       toupdate.h = 22;
198     }
199     else
200     {
201       toupdate.h = 18;
202     }
203     toupdate.x = 0;
204     toupdate.y = 0;
205
206     draw(false, true);
207     BoxStack::getInstance()->update(this, &toupdate);
208   }
209 }