[videodb] remove unused seasons table from episode_view
[xbmc.git] / xbmc / video / dialogs / GUIDialogTeletext.cpp
blob8335c64ce698609e1bc186d873756969b4c15d4d
1 /*
2 * Copyright (C) 2005-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
7 */
9 #include "GUIDialogTeletext.h"
11 #include "ServiceBroker.h"
12 #include "application/ApplicationComponents.h"
13 #include "application/ApplicationPlayer.h"
14 #include "dialogs/GUIDialogKaiToast.h"
15 #include "guilib/GUIMessage.h"
16 #include "guilib/GUITexture.h"
17 #include "guilib/LocalizeStrings.h"
18 #include "guilib/Texture.h"
19 #include "settings/Settings.h"
20 #include "settings/SettingsComponent.h"
21 #include "utils/ColorUtils.h"
22 #include "utils/log.h"
24 static int teletextFadeAmount = 0;
26 CGUIDialogTeletext::CGUIDialogTeletext()
27 : CGUIDialog(WINDOW_DIALOG_OSD_TELETEXT, ""), m_pTxtTexture(nullptr)
29 m_renderOrder = RENDER_ORDER_DIALOG_TELETEXT;
32 CGUIDialogTeletext::~CGUIDialogTeletext() = default;
34 bool CGUIDialogTeletext::OnAction(const CAction& action)
36 if (m_TextDecoder.HandleAction(action))
38 MarkDirtyRegion();
39 return true;
42 return CGUIDialog::OnAction(action);
45 bool CGUIDialogTeletext::OnBack(int actionID)
47 m_bClose = true;
48 MarkDirtyRegion();
49 return true;
52 bool CGUIDialogTeletext::OnMessage(CGUIMessage& message)
54 if (message.GetMessage() == GUI_MSG_WINDOW_INIT)
56 /* Do not open if no teletext is available */
57 const auto& components = CServiceBroker::GetAppComponents();
58 const auto appPlayer = components.GetComponent<CApplicationPlayer>();
59 if (!appPlayer->HasTeletextCache())
61 Close();
62 CGUIDialogKaiToast::QueueNotification(CGUIDialogKaiToast::Info, g_localizeStrings.Get(23049), "", 1500, false);
63 return true;
66 else if (message.GetMessage() == GUI_MSG_NOTIFY_ALL)
68 if (message.GetParam1() == GUI_MSG_WINDOW_RESIZE)
70 SetCoordinates();
73 return CGUIDialog::OnMessage(message);
76 void CGUIDialogTeletext::Process(unsigned int currentTime, CDirtyRegionList &dirtyregions)
78 if (m_TextDecoder.Changed())
80 MarkDirtyRegion();
82 CGUIDialog::Process(currentTime, dirtyregions);
83 m_renderRegion = m_vertCoords;
86 void CGUIDialogTeletext::Render()
88 if (CServiceBroker::GetWinSystem()->GetGfxContext().GetRenderOrder() ==
89 RENDER_ORDER_FRONT_TO_BACK)
90 return;
91 // Do not render if we have no texture
92 if (!m_pTxtTexture)
94 CLog::Log(LOGERROR, "CGUITeletextBox::Render called without texture");
95 return;
98 m_TextDecoder.RenderPage();
100 if (!m_bClose)
102 if (teletextFadeAmount < 100)
104 teletextFadeAmount = std::min(100, teletextFadeAmount + 5);
105 MarkDirtyRegion();
108 else
110 if (teletextFadeAmount > 0)
112 teletextFadeAmount = std::max(0, teletextFadeAmount - 10);
113 MarkDirtyRegion();
116 if (teletextFadeAmount == 0)
117 Close();
120 unsigned char* textureBuffer = (unsigned char*)m_TextDecoder.GetTextureBuffer();
121 if (!m_bClose && m_TextDecoder.NeedRendering() && textureBuffer)
123 m_pTxtTexture->Update(m_TextDecoder.GetWidth(), m_TextDecoder.GetHeight(), m_TextDecoder.GetWidth()*4, XB_FMT_A8R8G8B8, textureBuffer, false);
124 m_TextDecoder.RenderingDone();
125 MarkDirtyRegion();
128 KODI::UTILS::COLOR::Color color =
129 (static_cast<KODI::UTILS::COLOR::Color>(teletextFadeAmount * 2.55f) & 0xff) << 24 | 0xFFFFFF;
130 CGUITexture::DrawQuad(m_vertCoords, color, m_pTxtTexture.get(), nullptr, -1.0f);
132 CGUIDialog::Render();
135 void CGUIDialogTeletext::OnInitWindow()
137 teletextFadeAmount = 0;
138 m_bClose = false;
139 m_windowLoaded = true;
141 SetCoordinates();
143 if (!m_TextDecoder.InitDecoder())
145 CLog::Log(LOGERROR, "{}: failed to init teletext decoder", __FUNCTION__);
146 Close();
149 m_pTxtTexture =
150 CTexture::CreateTexture(m_TextDecoder.GetWidth(), m_TextDecoder.GetHeight(), XB_FMT_A8R8G8B8);
151 if (!m_pTxtTexture)
153 CLog::Log(LOGERROR, "{}: failed to create texture", __FUNCTION__);
154 Close();
157 CGUIDialog::OnInitWindow();
160 void CGUIDialogTeletext::OnDeinitWindow(int nextWindowID)
162 m_windowLoaded = false;
163 m_TextDecoder.EndDecoder();
165 m_pTxtTexture.reset();
167 CGUIDialog::OnDeinitWindow(nextWindowID);
170 void CGUIDialogTeletext::SetCoordinates()
172 float left, right, top, bottom;
174 CServiceBroker::GetWinSystem()->GetGfxContext().SetScalingResolution(m_coordsRes, m_needsScaling);
176 left = CServiceBroker::GetWinSystem()->GetGfxContext().ScaleFinalXCoord(0, 0);
177 right = CServiceBroker::GetWinSystem()->GetGfxContext().ScaleFinalXCoord((float)m_coordsRes.iWidth, 0);
178 top = CServiceBroker::GetWinSystem()->GetGfxContext().ScaleFinalYCoord(0, 0);
179 bottom = CServiceBroker::GetWinSystem()->GetGfxContext().ScaleFinalYCoord(0, (float)m_coordsRes.iHeight);
181 if (CServiceBroker::GetSettingsComponent()->GetSettings()->GetBool(CSettings::SETTING_VIDEOPLAYER_TELETEXTSCALE))
183 /* Fixed aspect ratio to 4:3 for teletext */
184 float width = right - left;
185 float height = bottom - top;
186 if (width / 4 > height / 3)
188 left = (width - height * 4 / 3) / 2;
189 right = width - left;
191 else
193 top = (height - width * 3 / 4) / 2;
194 bottom = height - top;
198 m_vertCoords.SetRect(left,
199 top,
200 right,
201 bottom);
203 MarkDirtyRegion();