Kodi Development 22.0
for Binary and Script based Add-Ons
 
Loading...
Searching...
No Matches
Rendering.h
1/*
2 * Copyright (C) 2005-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
4 *
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
7 */
8
9#pragma once
10
11#include "../../c-api/gui/controls/rendering.h"
12#include "../Window.h"
13#include "../renderHelper.h"
14
15#ifdef __cplusplus
16
17namespace kodi
18{
19namespace gui
20{
21namespace controls
22{
23
24//============================================================================
46class ATTR_DLL_LOCAL CRendering : public CAddonGUIControlBase
47{
48public:
49 //==========================================================================
56 CRendering(CWindow* window, int controlId) : CAddonGUIControlBase(window)
57 {
58 m_controlHandle = m_interface->kodi_gui->window->get_control_render_addon(
59 m_interface->kodiBase, m_Window->GetControlHandle(), controlId);
60 if (m_controlHandle)
61 m_interface->kodi_gui->control_rendering->set_callbacks(m_interface->kodiBase,
62 m_controlHandle, this, OnCreateCB,
63 OnRenderCB, OnStopCB, OnDirtyCB);
64 else
65 kodi::Log(ADDON_LOG_FATAL, "kodi::gui::controls::%s can't create control class from Kodi !!!",
66 __FUNCTION__);
67 }
68 //--------------------------------------------------------------------------
69
70 //==========================================================================
74 ~CRendering() override
75 {
76 m_interface->kodi_gui->control_rendering->destroy(m_interface->kodiBase, m_controlHandle);
77 }
78 //--------------------------------------------------------------------------
79
80 //==========================================================================
102 virtual bool Create(int x, int y, int w, int h, kodi::HardwareContext device) { return false; }
103 //--------------------------------------------------------------------------
104
105 //==========================================================================
112 virtual void Render() {}
113 //--------------------------------------------------------------------------
114
115 //==========================================================================
122 virtual void Stop() {}
123 //--------------------------------------------------------------------------
124
125 //==========================================================================
135 virtual bool Dirty() { return false; }
136 //--------------------------------------------------------------------------
137
138 //==========================================================================
157 bool (*CBCreate)(kodi::gui::ClientHandle cbhdl,
158 int x,
159 int y,
160 int w,
161 int h,
162 kodi::HardwareContext device),
163 void (*CBRender)(kodi::gui::ClientHandle cbhdl),
164 void (*CBStop)(kodi::gui::ClientHandle cbhdl),
165 bool (*CBDirty)(kodi::gui::ClientHandle cbhdl))
166 {
167 if (!cbhdl || !CBCreate || !CBRender || !CBStop || !CBDirty)
168 {
169 kodi::Log(ADDON_LOG_ERROR, "kodi::gui::controls::%s called with nullptr !!!", __FUNCTION__);
170 return;
171 }
172
173 m_interface->kodi_gui->control_rendering->set_callbacks(
174 m_interface->kodiBase, m_controlHandle, cbhdl, CBCreate, CBRender, CBStop, CBDirty);
175 }
176 //--------------------------------------------------------------------------
177
178private:
179 /*
180 * Defined callback functions from Kodi to add-on, for use in parent / child system
181 * (is private)!
182 */
183 static bool OnCreateCB(
184 KODI_GUI_CLIENT_HANDLE cbhdl, int x, int y, int w, int h, ADDON_HARDWARE_CONTEXT device)
185 {
186 static_cast<CRendering*>(cbhdl)->m_renderHelper = kodi::gui::GetRenderHelper();
187 return static_cast<CRendering*>(cbhdl)->Create(x, y, w, h, device);
188 }
189
190 static void OnRenderCB(KODI_GUI_CLIENT_HANDLE cbhdl)
191 {
192 if (!static_cast<CRendering*>(cbhdl)->m_renderHelper)
193 return;
194 static_cast<CRendering*>(cbhdl)->m_renderHelper->Begin();
195 static_cast<CRendering*>(cbhdl)->Render();
196 static_cast<CRendering*>(cbhdl)->m_renderHelper->End();
197 }
198
199 static void OnStopCB(KODI_GUI_CLIENT_HANDLE cbhdl)
200 {
201 static_cast<CRendering*>(cbhdl)->Stop();
202 static_cast<CRendering*>(cbhdl)->m_renderHelper = nullptr;
203 }
204
205 static bool OnDirtyCB(KODI_GUI_CLIENT_HANDLE cbhdl)
206 {
207 return static_cast<CRendering*>(cbhdl)->Dirty();
208 }
209
210 std::shared_ptr<kodi::gui::IRenderHelper> m_renderHelper;
211};
212
213} /* namespace controls */
214} /* namespace gui */
215} /* namespace kodi */
216
217#endif /* __cplusplus */
Definition ListItem.h:26
Definition Window.h:110
Definition Rendering.h:47
@ ADDON_LOG_FATAL
4 : To notify fatal unrecoverable errors, which can may also indicate upcoming crashes.
Definition addon_base.h:197
@ ADDON_LOG_ERROR
3 : To report error messages in the log file.
Definition addon_base.h:193
virtual void Render()
Render process call from Kodi.
Definition Rendering.h:112
virtual bool Create(int x, int y, int w, int h, kodi::HardwareContext device)
To create rendering control on Add-on.
Definition Rendering.h:102
~CRendering() override
Destructor.
Definition Rendering.h:74
void SetIndependentCallbacks(kodi::gui::ClientHandle cbhdl, bool(*CBCreate)(kodi::gui::ClientHandle cbhdl, int x, int y, int w, int h, kodi::HardwareContext device), void(*CBRender)(kodi::gui::ClientHandle cbhdl), void(*CBStop)(kodi::gui::ClientHandle cbhdl), bool(*CBDirty)(kodi::gui::ClientHandle cbhdl))
If the class is used independent (with "new CRendering") and not as parent (with "cCLASS_own : CRende...
Definition Rendering.h:156
virtual bool Dirty()
Call from Kodi where add-on becomes asked about dirty rendering region.
Definition Rendering.h:135
CRendering(CWindow *window, int controlId)
Construct a new control.
Definition Rendering.h:56
virtual void Stop()
Call from Kodi to stop rendering process.
Definition Rendering.h:122
KODI_GUI_CLIENT_HANDLE ClientHandle
Handler for addon-sided processing class If the callback functions used by the window are not used di...
Definition Window.h:43
void ATTR_DLL_LOCAL Log(const ADDON_LOG loglevel, const char *format,...)
Add a message to Kodi's log.
Definition AddonBase.h:1938