diff options
Diffstat (limited to 'xbmc/addons/kodi-dev-kit/include/kodi/gui')
35 files changed, 7566 insertions, 0 deletions
diff --git a/xbmc/addons/kodi-dev-kit/include/kodi/gui/CMakeLists.txt b/xbmc/addons/kodi-dev-kit/include/kodi/gui/CMakeLists.txt new file mode 100644 index 0000000..8f12955 --- /dev/null +++ b/xbmc/addons/kodi-dev-kit/include/kodi/gui/CMakeLists.txt | |||
| @@ -0,0 +1,8 @@ | |||
| 1 | set(HEADERS General.h | ||
| 2 | ListItem.h | ||
| 3 | Window.h | ||
| 4 | renderHelper.h) | ||
| 5 | |||
| 6 | if(NOT ENABLE_STATIC_LIBS) | ||
| 7 | core_add_library(addons_kodi-dev-kit_include_kodi_gui) | ||
| 8 | endif() | ||
diff --git a/xbmc/addons/kodi-dev-kit/include/kodi/gui/General.h b/xbmc/addons/kodi-dev-kit/include/kodi/gui/General.h new file mode 100644 index 0000000..85ba3f2 --- /dev/null +++ b/xbmc/addons/kodi-dev-kit/include/kodi/gui/General.h | |||
| @@ -0,0 +1,176 @@ | |||
| 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 "../AddonBase.h" | ||
| 12 | #include "../c-api/gui/general.h" | ||
| 13 | |||
| 14 | #ifdef __cplusplus | ||
| 15 | |||
| 16 | namespace kodi | ||
| 17 | { | ||
| 18 | namespace gui | ||
| 19 | { | ||
| 20 | |||
| 21 | //============================================================================== | ||
| 22 | /// @addtogroup cpp_kodi_gui_general | ||
| 23 | /// Permits the use of the required functions of the add-on to Kodi. | ||
| 24 | /// | ||
| 25 | /// These are pure functions them no other initialization need. | ||
| 26 | /// | ||
| 27 | /// It has the header @ref kodi/gui/General.h "#include <kodi/gui/General.h>" be included | ||
| 28 | /// to enjoy it. | ||
| 29 | /// | ||
| 30 | |||
| 31 | //============================================================================== | ||
| 32 | /// @ingroup cpp_kodi_gui_general | ||
| 33 | /// @brief Performs a graphical lock of rendering engine. | ||
| 34 | /// | ||
| 35 | inline void ATTRIBUTE_HIDDEN Lock() | ||
| 36 | { | ||
| 37 | using namespace ::kodi::addon; | ||
| 38 | CAddonBase::m_interface->toKodi->kodi_gui->general->lock(); | ||
| 39 | } | ||
| 40 | //------------------------------------------------------------------------------ | ||
| 41 | |||
| 42 | //============================================================================== | ||
| 43 | /// @ingroup cpp_kodi_gui_general | ||
| 44 | /// @brief Performs a graphical unlock of previous locked rendering engine. | ||
| 45 | /// | ||
| 46 | inline void ATTRIBUTE_HIDDEN Unlock() | ||
| 47 | { | ||
| 48 | using namespace ::kodi::addon; | ||
| 49 | CAddonBase::m_interface->toKodi->kodi_gui->general->unlock(); | ||
| 50 | } | ||
| 51 | //------------------------------------------------------------------------------ | ||
| 52 | |||
| 53 | //============================================================================== | ||
| 54 | /// @ingroup cpp_kodi_gui_general | ||
| 55 | /// @brief Return the the current screen height with pixel. | ||
| 56 | /// | ||
| 57 | /// @return Screen height with pixel | ||
| 58 | /// | ||
| 59 | inline int ATTRIBUTE_HIDDEN GetScreenHeight() | ||
| 60 | { | ||
| 61 | using namespace ::kodi::addon; | ||
| 62 | return CAddonBase::m_interface->toKodi->kodi_gui->general->get_screen_height( | ||
| 63 | CAddonBase::m_interface->toKodi->kodiBase); | ||
| 64 | } | ||
| 65 | //------------------------------------------------------------------------------ | ||
| 66 | |||
| 67 | //============================================================================== | ||
| 68 | /// @ingroup cpp_kodi_gui_general | ||
| 69 | /// @brief Return the the current screen width with pixel. | ||
| 70 | /// | ||
| 71 | /// @return Screen width with pixel | ||
| 72 | /// | ||
| 73 | inline int ATTRIBUTE_HIDDEN GetScreenWidth() | ||
| 74 | { | ||
| 75 | using namespace ::kodi::addon; | ||
| 76 | return CAddonBase::m_interface->toKodi->kodi_gui->general->get_screen_width( | ||
| 77 | CAddonBase::m_interface->toKodi->kodiBase); | ||
| 78 | } | ||
| 79 | //------------------------------------------------------------------------------ | ||
| 80 | |||
| 81 | //============================================================================== | ||
| 82 | /// @ingroup cpp_kodi_gui_general | ||
| 83 | /// @brief Return the the current screen rendering resolution. | ||
| 84 | /// | ||
| 85 | /// @return Current screen rendering resolution | ||
| 86 | /// | ||
| 87 | inline int ATTRIBUTE_HIDDEN GetVideoResolution() | ||
| 88 | { | ||
| 89 | using namespace ::kodi::addon; | ||
| 90 | return CAddonBase::m_interface->toKodi->kodi_gui->general->get_video_resolution( | ||
| 91 | CAddonBase::m_interface->toKodi->kodiBase); | ||
| 92 | } | ||
| 93 | //------------------------------------------------------------------------------ | ||
| 94 | |||
| 95 | //============================================================================== | ||
| 96 | /// @ingroup cpp_kodi_gui_general | ||
| 97 | /// @brief Returns the id for the current 'active' dialog as an integer. | ||
| 98 | /// | ||
| 99 | /// @return The currently active dialog Id | ||
| 100 | /// | ||
| 101 | /// | ||
| 102 | ///------------------------------------------------------------------------- | ||
| 103 | /// | ||
| 104 | /// **Example:** | ||
| 105 | /// ~~~~~~~~~~~~~{.cpp} | ||
| 106 | /// .. | ||
| 107 | /// int wid = kodi::gui::GetCurrentWindowDialogId(); | ||
| 108 | /// .. | ||
| 109 | /// ~~~~~~~~~~~~~ | ||
| 110 | /// | ||
| 111 | inline int ATTRIBUTE_HIDDEN GetCurrentWindowDialogId() | ||
| 112 | { | ||
| 113 | using namespace ::kodi::addon; | ||
| 114 | return CAddonBase::m_interface->toKodi->kodi_gui->general->get_current_window_dialog_id( | ||
| 115 | CAddonBase::m_interface->toKodi->kodiBase); | ||
| 116 | } | ||
| 117 | //------------------------------------------------------------------------------ | ||
| 118 | |||
| 119 | //============================================================================== | ||
| 120 | /// @ingroup cpp_kodi_gui_general | ||
| 121 | /// @brief Returns the id for the current 'active' window as an integer. | ||
| 122 | /// | ||
| 123 | /// @return The currently active window Id | ||
| 124 | /// | ||
| 125 | /// | ||
| 126 | ///------------------------------------------------------------------------- | ||
| 127 | /// | ||
| 128 | /// **Example:** | ||
| 129 | /// ~~~~~~~~~~~~~{.cpp} | ||
| 130 | /// .. | ||
| 131 | /// int wid = kodi::gui::GetCurrentWindowId(); | ||
| 132 | /// .. | ||
| 133 | /// ~~~~~~~~~~~~~ | ||
| 134 | /// | ||
| 135 | inline int ATTRIBUTE_HIDDEN GetCurrentWindowId() | ||
| 136 | { | ||
| 137 | using namespace ::kodi::addon; | ||
| 138 | return CAddonBase::m_interface->toKodi->kodi_gui->general->get_current_window_id( | ||
| 139 | CAddonBase::m_interface->toKodi->kodiBase); | ||
| 140 | } | ||
| 141 | //------------------------------------------------------------------------------ | ||
| 142 | |||
| 143 | //============================================================================== | ||
| 144 | /// @ingroup cpp_kodi_gui_general | ||
| 145 | /// @brief To get hardware specific device context interface. | ||
| 146 | /// | ||
| 147 | /// @return A pointer to the used device with @ref cpp_kodi_Defs_HardwareContext "kodi::HardwareContext" | ||
| 148 | /// | ||
| 149 | /// @warning This function is only be supported under Windows, on all other | ||
| 150 | /// OS it return `nullptr`! | ||
| 151 | /// | ||
| 152 | /// @note Returned Windows class pointer is `ID3D11DeviceContext1`. | ||
| 153 | /// | ||
| 154 | /// | ||
| 155 | ///------------------------------------------------------------------------- | ||
| 156 | /// | ||
| 157 | /// **Example:** | ||
| 158 | /// ~~~~~~~~~~~~~{.cpp} | ||
| 159 | /// #include <d3d11_1.h> | ||
| 160 | /// .. | ||
| 161 | /// ID3D11DeviceContext1* context = static_cast<ID3D11DeviceContext1*>(kodi::gui::GetHWContext()); | ||
| 162 | /// .. | ||
| 163 | /// ~~~~~~~~~~~~~ | ||
| 164 | /// | ||
| 165 | inline kodi::HardwareContext GetHWContext() | ||
| 166 | { | ||
| 167 | using namespace ::kodi::addon; | ||
| 168 | return CAddonBase::m_interface->toKodi->kodi_gui->general->get_hw_context( | ||
| 169 | CAddonBase::m_interface->toKodi->kodiBase); | ||
| 170 | } | ||
| 171 | //------------------------------------------------------------------------------ | ||
| 172 | |||
| 173 | } /* namespace gui */ | ||
| 174 | } /* namespace kodi */ | ||
| 175 | |||
| 176 | #endif /* __cplusplus */ | ||
diff --git a/xbmc/addons/kodi-dev-kit/include/kodi/gui/ListItem.h b/xbmc/addons/kodi-dev-kit/include/kodi/gui/ListItem.h new file mode 100644 index 0000000..3a4d50b --- /dev/null +++ b/xbmc/addons/kodi-dev-kit/include/kodi/gui/ListItem.h | |||
| @@ -0,0 +1,345 @@ | |||
| 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 "../AddonBase.h" | ||
| 12 | #include "../c-api/gui/list_item.h" | ||
| 13 | |||
| 14 | #ifdef __cplusplus | ||
| 15 | |||
| 16 | #include <memory> | ||
| 17 | |||
| 18 | namespace kodi | ||
| 19 | { | ||
| 20 | namespace gui | ||
| 21 | { | ||
| 22 | |||
| 23 | class CWindow; | ||
| 24 | |||
| 25 | class ATTRIBUTE_HIDDEN CAddonGUIControlBase | ||
| 26 | { | ||
| 27 | public: | ||
| 28 | KODI_GUI_LISTITEM_HANDLE GetControlHandle() const { return m_controlHandle; } | ||
| 29 | |||
| 30 | protected: | ||
| 31 | explicit CAddonGUIControlBase(CAddonGUIControlBase* window) | ||
| 32 | : m_controlHandle(nullptr), | ||
| 33 | m_interface(::kodi::addon::CAddonBase::m_interface->toKodi), | ||
| 34 | m_Window(window) | ||
| 35 | { | ||
| 36 | } | ||
| 37 | |||
| 38 | virtual ~CAddonGUIControlBase() = default; | ||
| 39 | |||
| 40 | friend class CWindow; | ||
| 41 | |||
| 42 | KODI_GUI_LISTITEM_HANDLE m_controlHandle; | ||
| 43 | AddonToKodiFuncTable_Addon* m_interface; | ||
| 44 | CAddonGUIControlBase* m_Window; | ||
| 45 | |||
| 46 | private: | ||
| 47 | CAddonGUIControlBase() = delete; | ||
| 48 | CAddonGUIControlBase(const CAddonGUIControlBase&) = delete; | ||
| 49 | CAddonGUIControlBase& operator=(const CAddonGUIControlBase&) = delete; | ||
| 50 | }; | ||
| 51 | |||
| 52 | class CListItem; | ||
| 53 | |||
| 54 | //============================================================================== | ||
| 55 | /// @addtogroup cpp_kodi_gui_windows_listitem | ||
| 56 | /// @brief @cpp_class{ kodi::gui::CListItem } | ||
| 57 | /// **Selectable window list item**\n | ||
| 58 | /// The list item control is used for creating item lists in Kodi. | ||
| 59 | /// | ||
| 60 | /// The with @ref ListItem.h "#include <kodi/gui/ListItem.h>" given | ||
| 61 | /// class is used to create a item entry for a list on window and to support it's | ||
| 62 | /// control. | ||
| 63 | /// | ||
| 64 | class ATTRIBUTE_HIDDEN CListItem : public CAddonGUIControlBase | ||
| 65 | { | ||
| 66 | public: | ||
| 67 | //============================================================================ | ||
| 68 | /// @ingroup cpp_kodi_gui_windows_listitem | ||
| 69 | /// @brief Class constructor with parameters. | ||
| 70 | /// | ||
| 71 | /// @param[in] label [opt] Item label | ||
| 72 | /// @param[in] label2 [opt] Second Item label (if needed) | ||
| 73 | /// @param[in] path [opt] Path to where item is defined | ||
| 74 | /// | ||
| 75 | CListItem(const std::string& label = "", | ||
| 76 | const std::string& label2 = "", | ||
| 77 | const std::string& path = "") | ||
| 78 | : CAddonGUIControlBase(nullptr) | ||
| 79 | { | ||
| 80 | m_controlHandle = m_interface->kodi_gui->listItem->create(m_interface->kodiBase, label.c_str(), | ||
| 81 | label2.c_str(), path.c_str()); | ||
| 82 | } | ||
| 83 | |||
| 84 | /* | ||
| 85 | * Constructor used for parts given by list items from addon window | ||
| 86 | * | ||
| 87 | * Related to call of "std::shared_ptr<CListItem> kodi::gui::CWindow::GetListItem(int listPos)" | ||
| 88 | * Not needed for addon development itself | ||
| 89 | */ | ||
| 90 | explicit CListItem(KODI_GUI_LISTITEM_HANDLE listItemHandle) : CAddonGUIControlBase(nullptr) | ||
| 91 | { | ||
| 92 | m_controlHandle = listItemHandle; | ||
| 93 | } | ||
| 94 | |||
| 95 | //============================================================================ | ||
| 96 | /// @ingroup cpp_kodi_gui_windows_listitem | ||
| 97 | /// @brief Class destructor | ||
| 98 | /// | ||
| 99 | ~CListItem() override | ||
| 100 | { | ||
| 101 | m_interface->kodi_gui->listItem->destroy(m_interface->kodiBase, m_controlHandle); | ||
| 102 | } | ||
| 103 | //---------------------------------------------------------------------------- | ||
| 104 | |||
| 105 | //============================================================================ | ||
| 106 | /// @ingroup cpp_kodi_gui_windows_listitem | ||
| 107 | /// @brief Returns the listitem label. | ||
| 108 | /// | ||
| 109 | /// @return Label of item | ||
| 110 | /// | ||
| 111 | std::string GetLabel() | ||
| 112 | { | ||
| 113 | std::string label; | ||
| 114 | char* ret = m_interface->kodi_gui->listItem->get_label(m_interface->kodiBase, m_controlHandle); | ||
| 115 | if (ret != nullptr) | ||
| 116 | { | ||
| 117 | if (std::strlen(ret)) | ||
| 118 | label = ret; | ||
| 119 | m_interface->free_string(m_interface->kodiBase, ret); | ||
| 120 | } | ||
| 121 | return label; | ||
| 122 | } | ||
| 123 | //---------------------------------------------------------------------------- | ||
| 124 | |||
| 125 | //============================================================================ | ||
| 126 | /// @ingroup cpp_kodi_gui_windows_listitem | ||
| 127 | /// @brief Sets the listitem label. | ||
| 128 | /// | ||
| 129 | /// @param[in] label string or unicode - text string. | ||
| 130 | /// | ||
| 131 | void SetLabel(const std::string& label) | ||
| 132 | { | ||
| 133 | m_interface->kodi_gui->listItem->set_label(m_interface->kodiBase, m_controlHandle, | ||
| 134 | label.c_str()); | ||
| 135 | } | ||
| 136 | //---------------------------------------------------------------------------- | ||
| 137 | |||
| 138 | //============================================================================ | ||
| 139 | /// @ingroup cpp_kodi_gui_windows_listitem | ||
| 140 | /// @brief Returns the second listitem label. | ||
| 141 | /// | ||
| 142 | /// @return Second label of item | ||
| 143 | /// | ||
| 144 | std::string GetLabel2() | ||
| 145 | { | ||
| 146 | std::string label; | ||
| 147 | char* ret = m_interface->kodi_gui->listItem->get_label2(m_interface->kodiBase, m_controlHandle); | ||
| 148 | if (ret != nullptr) | ||
| 149 | { | ||
| 150 | if (std::strlen(ret)) | ||
| 151 | label = ret; | ||
| 152 | m_interface->free_string(m_interface->kodiBase, ret); | ||
| 153 | } | ||
| 154 | return label; | ||
| 155 | } | ||
| 156 | //---------------------------------------------------------------------------- | ||
| 157 | |||
| 158 | //============================================================================ | ||
| 159 | /// @ingroup cpp_kodi_gui_windows_listitem | ||
| 160 | /// @brief Sets the listitem's label2. | ||
| 161 | /// | ||
| 162 | /// @param[in] label string or unicode - text string. | ||
| 163 | /// | ||
| 164 | void SetLabel2(const std::string& label) | ||
| 165 | { | ||
| 166 | m_interface->kodi_gui->listItem->set_label2(m_interface->kodiBase, m_controlHandle, | ||
| 167 | label.c_str()); | ||
| 168 | } | ||
| 169 | //---------------------------------------------------------------------------- | ||
| 170 | |||
| 171 | //============================================================================ | ||
| 172 | /// @ingroup cpp_kodi_gui_windows_listitem | ||
| 173 | /// @brief Sets the listitem's art | ||
| 174 | /// | ||
| 175 | /// @param[in] type Type of Art to set | ||
| 176 | /// - Some default art values (any string possible): | ||
| 177 | /// | value (type) | Type | | ||
| 178 | /// |:-------------:|:--------------------------------------------------| | ||
| 179 | /// | thumb | string - image filename | ||
| 180 | /// | poster | string - image filename | ||
| 181 | /// | banner | string - image filename | ||
| 182 | /// | fanart | string - image filename | ||
| 183 | /// | clearart | string - image filename | ||
| 184 | /// | clearlogo | string - image filename | ||
| 185 | /// | landscape | string - image filename | ||
| 186 | /// | icon | string - image filename | ||
| 187 | /// @return The url to use for Art | ||
| 188 | /// | ||
| 189 | std::string GetArt(const std::string& type) | ||
| 190 | { | ||
| 191 | std::string strReturn; | ||
| 192 | char* ret = m_interface->kodi_gui->listItem->get_art(m_interface->kodiBase, m_controlHandle, | ||
| 193 | type.c_str()); | ||
| 194 | if (ret != nullptr) | ||
| 195 | { | ||
| 196 | if (std::strlen(ret)) | ||
| 197 | strReturn = ret; | ||
| 198 | m_interface->free_string(m_interface->kodiBase, ret); | ||
| 199 | } | ||
| 200 | return strReturn; | ||
| 201 | } | ||
| 202 | //---------------------------------------------------------------------------- | ||
| 203 | |||
| 204 | //============================================================================ | ||
| 205 | /// @ingroup cpp_kodi_gui_windows_listitem | ||
| 206 | /// @brief Sets the listitem's art | ||
| 207 | /// | ||
| 208 | /// @param[in] type Type of Art to set | ||
| 209 | /// @param[in] url The url to use for Art | ||
| 210 | /// - Some default art values (any string possible): | ||
| 211 | /// | value (type) | Type | | ||
| 212 | /// |:-------------:|:--------------------------------------------------| | ||
| 213 | /// | thumb | string - image filename | ||
| 214 | /// | poster | string - image filename | ||
| 215 | /// | banner | string - image filename | ||
| 216 | /// | fanart | string - image filename | ||
| 217 | /// | clearart | string - image filename | ||
| 218 | /// | clearlogo | string - image filename | ||
| 219 | /// | landscape | string - image filename | ||
| 220 | /// | icon | string - image filename | ||
| 221 | /// | ||
| 222 | void SetArt(const std::string& type, const std::string& url) | ||
| 223 | { | ||
| 224 | m_interface->kodi_gui->listItem->set_art(m_interface->kodiBase, m_controlHandle, type.c_str(), | ||
| 225 | url.c_str()); | ||
| 226 | } | ||
| 227 | //---------------------------------------------------------------------------- | ||
| 228 | |||
| 229 | //============================================================================ | ||
| 230 | /// @ingroup cpp_kodi_gui_windows_listitem | ||
| 231 | /// @brief Returns the path / filename of this listitem. | ||
| 232 | /// | ||
| 233 | /// @return Path string | ||
| 234 | /// | ||
| 235 | std::string GetPath() | ||
| 236 | { | ||
| 237 | std::string strReturn; | ||
| 238 | char* ret = m_interface->kodi_gui->listItem->get_path(m_interface->kodiBase, m_controlHandle); | ||
| 239 | if (ret != nullptr) | ||
| 240 | { | ||
| 241 | if (std::strlen(ret)) | ||
| 242 | strReturn = ret; | ||
| 243 | m_interface->free_string(m_interface->kodiBase, ret); | ||
| 244 | } | ||
| 245 | return strReturn; | ||
| 246 | } | ||
| 247 | //---------------------------------------------------------------------------- | ||
| 248 | |||
| 249 | //============================================================================ | ||
| 250 | /// @ingroup cpp_kodi_gui_windows_listitem | ||
| 251 | /// @brief Sets the listitem's path. | ||
| 252 | /// | ||
| 253 | /// @param[in] path string or unicode - path, activated when item is clicked. | ||
| 254 | /// | ||
| 255 | /// @note You can use the above as keywords for arguments. | ||
| 256 | /// | ||
| 257 | void SetPath(const std::string& path) | ||
| 258 | { | ||
| 259 | m_interface->kodi_gui->listItem->set_path(m_interface->kodiBase, m_controlHandle, path.c_str()); | ||
| 260 | } | ||
| 261 | //---------------------------------------------------------------------------- | ||
| 262 | |||
| 263 | //============================================================================ | ||
| 264 | /// @ingroup cpp_kodi_gui_windows_listitem | ||
| 265 | /// @brief Sets a listitem property, similar to an infolabel. | ||
| 266 | /// | ||
| 267 | /// @param[in] key string - property name. | ||
| 268 | /// @param[in] value string or unicode - value of property. | ||
| 269 | /// | ||
| 270 | /// @note Key is NOT case sensitive. | ||
| 271 | /// You can use the above as keywords for arguments and skip certain@n | ||
| 272 | /// optional arguments.\n | ||
| 273 | /// Once you use a keyword, all following arguments require the | ||
| 274 | /// keyword. | ||
| 275 | /// | ||
| 276 | /// Some of these are treated internally by Kodi, such as the | ||
| 277 | /// <b>'StartOffset'</b> property, which is the offset in seconds at which to | ||
| 278 | /// start playback of an item. Others may be used in the skin to add | ||
| 279 | /// extra information, such as <b>'WatchedCount'</b> for tvshow items | ||
| 280 | /// | ||
| 281 | void SetProperty(const std::string& key, const std::string& value) | ||
| 282 | { | ||
| 283 | m_interface->kodi_gui->listItem->set_property(m_interface->kodiBase, m_controlHandle, | ||
| 284 | key.c_str(), value.c_str()); | ||
| 285 | } | ||
| 286 | //---------------------------------------------------------------------------- | ||
| 287 | |||
| 288 | //============================================================================ | ||
| 289 | /// @ingroup cpp_kodi_gui_windows_listitem | ||
| 290 | /// @brief Returns a listitem property as a string, similar to an infolabel. | ||
| 291 | /// | ||
| 292 | /// @param[in] key string - property name. | ||
| 293 | /// @return string - List item property | ||
| 294 | /// | ||
| 295 | /// @note Key is NOT case sensitive.\n | ||
| 296 | /// You can use the above as keywords for arguments and skip certain | ||
| 297 | /// optional arguments.\n | ||
| 298 | /// Once you use a keyword, all following arguments require the | ||
| 299 | /// keyword. | ||
| 300 | /// | ||
| 301 | std::string GetProperty(const std::string& key) | ||
| 302 | { | ||
| 303 | std::string label; | ||
| 304 | char* ret = m_interface->kodi_gui->listItem->get_property(m_interface->kodiBase, | ||
| 305 | m_controlHandle, key.c_str()); | ||
| 306 | if (ret != nullptr) | ||
| 307 | { | ||
| 308 | if (std::strlen(ret)) | ||
| 309 | label = ret; | ||
| 310 | m_interface->free_string(m_interface->kodiBase, ret); | ||
| 311 | } | ||
| 312 | return label; | ||
| 313 | } | ||
| 314 | //---------------------------------------------------------------------------- | ||
| 315 | |||
| 316 | //============================================================================ | ||
| 317 | /// @ingroup cpp_kodi_gui_windows_listitem | ||
| 318 | /// @brief To control selection of item in list (also multiple selection, | ||
| 319 | /// in list on serveral items possible). | ||
| 320 | /// | ||
| 321 | /// @param[in] selected if true becomes set as selected | ||
| 322 | /// | ||
| 323 | void Select(bool selected) | ||
| 324 | { | ||
| 325 | m_interface->kodi_gui->listItem->select(m_interface->kodiBase, m_controlHandle, selected); | ||
| 326 | } | ||
| 327 | //---------------------------------------------------------------------------- | ||
| 328 | |||
| 329 | //============================================================================ | ||
| 330 | /// @ingroup cpp_kodi_gui_windows_listitem | ||
| 331 | /// @brief Returns the listitem's selected status. | ||
| 332 | /// | ||
| 333 | /// @return true if selected, otherwise false | ||
| 334 | /// | ||
| 335 | bool IsSelected() | ||
| 336 | { | ||
| 337 | return m_interface->kodi_gui->listItem->is_selected(m_interface->kodiBase, m_controlHandle); | ||
| 338 | } | ||
| 339 | //---------------------------------------------------------------------------- | ||
| 340 | }; | ||
| 341 | |||
| 342 | } /* namespace gui */ | ||
| 343 | } /* namespace kodi */ | ||
| 344 | |||
| 345 | #endif /* __cplusplus */ | ||
diff --git a/xbmc/addons/kodi-dev-kit/include/kodi/gui/Window.h b/xbmc/addons/kodi-dev-kit/include/kodi/gui/Window.h new file mode 100644 index 0000000..3066b3c --- /dev/null +++ b/xbmc/addons/kodi-dev-kit/include/kodi/gui/Window.h | |||
| @@ -0,0 +1,915 @@ | |||
| 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 "../AddonBase.h" | ||
| 12 | #include "../c-api/gui/window.h" | ||
| 13 | #include "ListItem.h" | ||
| 14 | #include "input/ActionIDs.h" | ||
| 15 | |||
| 16 | #ifdef __cplusplus | ||
| 17 | |||
| 18 | namespace kodi | ||
| 19 | { | ||
| 20 | namespace gui | ||
| 21 | { | ||
| 22 | |||
| 23 | //============================================================================== | ||
| 24 | /// @defgroup cpp_kodi_gui_windows_window_Defs Definitions, structures and enumerators | ||
| 25 | /// @ingroup cpp_kodi_gui_windows_window | ||
| 26 | /// @brief **Library definition values**\n | ||
| 27 | /// Additional values, structures and things that are used in the Window class. | ||
| 28 | /// | ||
| 29 | /// ------------------------------------------------------------------------ | ||
| 30 | /// | ||
| 31 | /// @link cpp_kodi_gui_windows_window Go back to normal functions from CWindow@endlink | ||
| 32 | /// | ||
| 33 | |||
| 34 | //============================================================================== | ||
| 35 | /// @ingroup cpp_kodi_gui_windows_window_Defs | ||
| 36 | /// @brief **Handler for addon-sided processing class**\n | ||
| 37 | /// If the callback functions used by the window are not used directly in the | ||
| 38 | /// @ref cpp_kodi_gui_windows_window "CWindow" class and are outside of it. | ||
| 39 | /// | ||
| 40 | /// This value here corresponds to a <b>`void*`</b> and returns the address | ||
| 41 | /// requested by the add-on for callbacks. | ||
| 42 | /// | ||
| 43 | using ClientHandle = KODI_GUI_CLIENT_HANDLE; | ||
| 44 | //------------------------------------------------------------------------------ | ||
| 45 | |||
| 46 | class CListItem; | ||
| 47 | |||
| 48 | //============================================================================== | ||
| 49 | /// @addtogroup cpp_kodi_gui_windows_window | ||
| 50 | /// @brief @cpp_class{ kodi::gui::CWindow } | ||
| 51 | /// **Main window control class**\n | ||
| 52 | /// The addon uses its own skin xml file and displays it in Kodi using this class. | ||
| 53 | /// | ||
| 54 | /// The with @ref Window.h "#include <kodi/gui/Window.h>" | ||
| 55 | /// included file brings support to create a window or dialog on Kodi. | ||
| 56 | /// | ||
| 57 | /// The add-on has to integrate its own @ref cpp_kodi_gui_windows_window_callbacks "callback functions" | ||
| 58 | /// in order to process the necessary user access to its window. | ||
| 59 | /// | ||
| 60 | /// | ||
| 61 | /// -------------------------------------------------------------------------- | ||
| 62 | /// | ||
| 63 | /// **Window header example:** | ||
| 64 | /// ~~~~~~~~~~~~~{.xml} | ||
| 65 | /// <?xml version="1.0" encoding="UTF-8"?> | ||
| 66 | /// <window> | ||
| 67 | /// <onload>RunScript(script.foobar)</onload> | ||
| 68 | /// <onunload>SetProperty(foo,bar)</onunload> | ||
| 69 | /// <defaultcontrol always="false">2</defaultcontrol> | ||
| 70 | /// <menucontrol>9000</menucontrol> | ||
| 71 | /// <backgroundcolor>0xff00ff00</backgroundcolor> | ||
| 72 | /// <views>50,51,509,510</views> | ||
| 73 | /// <visible>Window.IsActive(Home)</visible> | ||
| 74 | /// <animation effect="fade" time="100">WindowOpen</animation> | ||
| 75 | /// <animation effect="slide" end="0,576" time="100">WindowClose</animation> | ||
| 76 | /// <zorder>1</zorder> | ||
| 77 | /// <coordinates> | ||
| 78 | /// <left>40</left> | ||
| 79 | /// <top>50</top> | ||
| 80 | /// <origin x="100" y="50">Window.IsActive(Home)</origin> | ||
| 81 | /// </coordinates> | ||
| 82 | /// <previouswindow>MyVideos</previouswindow> | ||
| 83 | /// <controls> | ||
| 84 | /// <control> | ||
| 85 | /// </control> | ||
| 86 | /// .... | ||
| 87 | /// </controls> | ||
| 88 | /// </window> | ||
| 89 | /// ~~~~~~~~~~~~~ | ||
| 90 | /// | ||
| 91 | /// -------------------------------------------------------------------------- | ||
| 92 | /// | ||
| 93 | /// On functions defined input variable <b><tt>controlId</tt> (GUI control identifier)</b> | ||
| 94 | /// is the on window.xml defined value behind type added with <tt><b>id="..."</b></tt> and | ||
| 95 | /// used to identify for changes there and on callbacks. | ||
| 96 | /// | ||
| 97 | /// ~~~~~~~~~~~~~{.xml} | ||
| 98 | /// <control type="label" id="31"> | ||
| 99 | /// <description>Title Label</description> | ||
| 100 | /// ... | ||
| 101 | /// </control> | ||
| 102 | /// <control type="progress" id="32"> | ||
| 103 | /// <description>progress control</description> | ||
| 104 | /// ... | ||
| 105 | /// </control> | ||
| 106 | /// ~~~~~~~~~~~~~ | ||
| 107 | /// | ||
| 108 | /// | ||
| 109 | class ATTRIBUTE_HIDDEN CWindow : public CAddonGUIControlBase | ||
| 110 | { | ||
| 111 | public: | ||
| 112 | //============================================================================ | ||
| 113 | /// @ingroup cpp_kodi_gui_windows_window | ||
| 114 | /// @brief Class constructor with needed values for window / dialog. | ||
| 115 | /// | ||
| 116 | /// Creates a new Window class. | ||
| 117 | /// | ||
| 118 | /// @param[in] xmlFilename XML file for the skin | ||
| 119 | /// @param[in] defaultSkin Default skin to use if needed not available | ||
| 120 | /// @param[in] asDialog Use window as dialog if set | ||
| 121 | /// @param[in] isMedia [opt] bool - if False, create a regular window. | ||
| 122 | /// if True, create a mediawindow. (default=false) | ||
| 123 | /// | ||
| 124 | /// @note <b>`isMedia`</b> value as true only usable for windows not for dialogs. | ||
| 125 | /// | ||
| 126 | CWindow(const std::string& xmlFilename, | ||
| 127 | const std::string& defaultSkin, | ||
| 128 | bool asDialog, | ||
| 129 | bool isMedia = false) | ||
| 130 | : CAddonGUIControlBase(nullptr) | ||
| 131 | { | ||
| 132 | m_controlHandle = m_interface->kodi_gui->window->create( | ||
| 133 | m_interface->kodiBase, xmlFilename.c_str(), defaultSkin.c_str(), asDialog, isMedia); | ||
| 134 | if (!m_controlHandle) | ||
| 135 | kodi::Log(ADDON_LOG_FATAL, "kodi::gui::CWindow can't create window class from Kodi !!!"); | ||
| 136 | m_interface->kodi_gui->window->set_callbacks(m_interface->kodiBase, m_controlHandle, this, | ||
| 137 | CBOnInit, CBOnFocus, CBOnClick, CBOnAction, | ||
| 138 | CBGetContextButtons, CBOnContextButton); | ||
| 139 | } | ||
| 140 | //---------------------------------------------------------------------------- | ||
| 141 | |||
| 142 | //============================================================================ | ||
| 143 | /// @ingroup CWindow | ||
| 144 | /// @brief Class destructor. | ||
| 145 | /// | ||
| 146 | ~CWindow() override | ||
| 147 | { | ||
| 148 | if (m_controlHandle) | ||
| 149 | m_interface->kodi_gui->window->destroy(m_interface->kodiBase, m_controlHandle); | ||
| 150 | } | ||
| 151 | //---------------------------------------------------------------------------- | ||
| 152 | |||
| 153 | //============================================================================ | ||
| 154 | /// @ingroup cpp_kodi_gui_windows_window | ||
| 155 | /// @brief Show this window. | ||
| 156 | /// | ||
| 157 | /// Shows this window by activating it, calling close() after it wil activate | ||
| 158 | /// the current window again. | ||
| 159 | /// | ||
| 160 | /// @note If your Add-On ends this window will be closed to. To show it forever, | ||
| 161 | /// make a loop at the end of your Add-On or use @ref DoModal() instead. | ||
| 162 | /// | ||
| 163 | /// @warning If used must be the class be global present until Kodi becomes | ||
| 164 | /// closed. The creation can be done before "Show" becomes called, but | ||
| 165 | /// not delete class after them. | ||
| 166 | /// | ||
| 167 | /// @return Return true if call and show is successed, if false was something | ||
| 168 | /// failed to get needed skin parts. | ||
| 169 | /// | ||
| 170 | bool Show() | ||
| 171 | { | ||
| 172 | return m_interface->kodi_gui->window->show(m_interface->kodiBase, m_controlHandle); | ||
| 173 | } | ||
| 174 | //---------------------------------------------------------------------------- | ||
| 175 | |||
| 176 | //============================================================================ | ||
| 177 | /// @ingroup cpp_kodi_gui_windows_window | ||
| 178 | /// @brief Closes this window. | ||
| 179 | /// | ||
| 180 | /// Closes this window by activating the old window. | ||
| 181 | /// @note The window is not deleted with this method. | ||
| 182 | /// | ||
| 183 | void Close() { m_interface->kodi_gui->window->close(m_interface->kodiBase, m_controlHandle); } | ||
| 184 | //---------------------------------------------------------------------------- | ||
| 185 | |||
| 186 | //============================================================================ | ||
| 187 | /// @ingroup cpp_kodi_gui_windows_window | ||
| 188 | /// @brief Display this window until close() is called. | ||
| 189 | /// | ||
| 190 | void DoModal() | ||
| 191 | { | ||
| 192 | m_interface->kodi_gui->window->do_modal(m_interface->kodiBase, m_controlHandle); | ||
| 193 | } | ||
| 194 | //---------------------------------------------------------------------------- | ||
| 195 | |||
| 196 | //============================================================================ | ||
| 197 | /// @ingroup cpp_kodi_gui_windows_window | ||
| 198 | /// @brief Gives the control with the supplied focus. | ||
| 199 | /// | ||
| 200 | /// @param[in] controlId On skin defined id of control | ||
| 201 | /// @return Return true if call and focus is successed, if false was something | ||
| 202 | /// failed to get needed skin parts | ||
| 203 | /// | ||
| 204 | bool SetFocusId(int controlId) | ||
| 205 | { | ||
| 206 | return m_interface->kodi_gui->window->set_focus_id(m_interface->kodiBase, m_controlHandle, | ||
| 207 | controlId); | ||
| 208 | } | ||
| 209 | //---------------------------------------------------------------------------- | ||
| 210 | |||
| 211 | //============================================================================ | ||
| 212 | /// @ingroup cpp_kodi_gui_windows_window | ||
| 213 | /// @brief Returns the id of the control which is focused. | ||
| 214 | /// | ||
| 215 | /// @return Focused control id | ||
| 216 | /// | ||
| 217 | int GetFocusId() | ||
| 218 | { | ||
| 219 | return m_interface->kodi_gui->window->get_focus_id(m_interface->kodiBase, m_controlHandle); | ||
| 220 | } | ||
| 221 | //---------------------------------------------------------------------------- | ||
| 222 | |||
| 223 | //============================================================================ | ||
| 224 | /// @ingroup cpp_kodi_gui_windows_window | ||
| 225 | /// @brief To set the used label on given control id. | ||
| 226 | /// | ||
| 227 | /// @param[in] controlId Control id where label need to set | ||
| 228 | /// @param[in] label Label to use | ||
| 229 | /// | ||
| 230 | void SetControlLabel(int controlId, const std::string& label) | ||
| 231 | { | ||
| 232 | m_interface->kodi_gui->window->set_control_label(m_interface->kodiBase, m_controlHandle, | ||
| 233 | controlId, label.c_str()); | ||
| 234 | } | ||
| 235 | //---------------------------------------------------------------------------- | ||
| 236 | |||
| 237 | //============================================================================ | ||
| 238 | /// @ingroup cpp_kodi_gui_windows_window | ||
| 239 | /// @brief To set the visibility on given control id. | ||
| 240 | /// | ||
| 241 | /// @param[in] controlId Control id where visibility is changed | ||
| 242 | /// @param[in] visible Boolean value with `true` for visible, `false` for hidden | ||
| 243 | /// | ||
| 244 | void SetControlVisible(int controlId, bool visible) | ||
| 245 | { | ||
| 246 | m_interface->kodi_gui->window->set_control_visible(m_interface->kodiBase, m_controlHandle, | ||
| 247 | controlId, visible); | ||
| 248 | } | ||
| 249 | //---------------------------------------------------------------------------- | ||
| 250 | |||
| 251 | //============================================================================ | ||
| 252 | /// @ingroup cpp_kodi_gui_windows_window | ||
| 253 | /// @brief To set the selection on given control id. | ||
| 254 | /// | ||
| 255 | /// @param[in] controlId Control id where selection is changed | ||
| 256 | /// @param[in] selected Boolean value with `true` for selected, `false` for not | ||
| 257 | /// | ||
| 258 | void SetControlSelected(int controlId, bool selected) | ||
| 259 | { | ||
| 260 | m_interface->kodi_gui->window->set_control_selected(m_interface->kodiBase, m_controlHandle, | ||
| 261 | controlId, selected); | ||
| 262 | } | ||
| 263 | //---------------------------------------------------------------------------- | ||
| 264 | |||
| 265 | //============================================================================ | ||
| 266 | /// @ingroup cpp_kodi_gui_windows_window | ||
| 267 | /// @brief Sets a window property, similar to an infolabel. | ||
| 268 | /// | ||
| 269 | /// @param[in] key string - property name. | ||
| 270 | /// @param[in] value string or unicode - value of property. | ||
| 271 | /// | ||
| 272 | /// @note Key is NOT case sensitive. Setting value to an empty string is | ||
| 273 | /// equivalent to clearProperty(key).\n | ||
| 274 | /// You can use the above as keywords for arguments and skip certain | ||
| 275 | /// optional arguments.\n | ||
| 276 | /// Once you use a keyword, all following arguments require the keyword. | ||
| 277 | /// | ||
| 278 | void SetProperty(const std::string& key, const std::string& value) | ||
| 279 | { | ||
| 280 | m_interface->kodi_gui->window->set_property(m_interface->kodiBase, m_controlHandle, key.c_str(), | ||
| 281 | value.c_str()); | ||
| 282 | } | ||
| 283 | //---------------------------------------------------------------------------- | ||
| 284 | |||
| 285 | //============================================================================ | ||
| 286 | /// @ingroup cpp_kodi_gui_windows_window | ||
| 287 | /// @brief Returns a window property as a string, similar to an infolabel. | ||
| 288 | /// | ||
| 289 | /// @param[in] key string - property name. | ||
| 290 | /// @return The property as string (if present) | ||
| 291 | /// | ||
| 292 | /// @note Key is NOT case sensitive. Setting value to an empty string is | ||
| 293 | /// equivalent to clearProperty(key).\n | ||
| 294 | /// You can use the above as keywords for arguments and skip certain | ||
| 295 | /// optional arguments.\n | ||
| 296 | /// Once you use a keyword, all following arguments require the keyword. | ||
| 297 | /// | ||
| 298 | std::string GetProperty(const std::string& key) const | ||
| 299 | { | ||
| 300 | std::string label; | ||
| 301 | char* ret = m_interface->kodi_gui->window->get_property(m_interface->kodiBase, m_controlHandle, | ||
| 302 | key.c_str()); | ||
| 303 | if (ret != nullptr) | ||
| 304 | { | ||
| 305 | if (std::strlen(ret)) | ||
| 306 | label = ret; | ||
| 307 | m_interface->free_string(m_interface->kodiBase, ret); | ||
| 308 | } | ||
| 309 | return label; | ||
| 310 | } | ||
| 311 | //---------------------------------------------------------------------------- | ||
| 312 | |||
| 313 | //============================================================================ | ||
| 314 | /// @ingroup cpp_kodi_gui_windows_window | ||
| 315 | /// @brief Sets a window property with integer value | ||
| 316 | /// | ||
| 317 | /// @param[in] key string - property name. | ||
| 318 | /// @param[in] value integer value to set | ||
| 319 | /// | ||
| 320 | void SetPropertyInt(const std::string& key, int value) | ||
| 321 | { | ||
| 322 | m_interface->kodi_gui->window->set_property_int(m_interface->kodiBase, m_controlHandle, | ||
| 323 | key.c_str(), value); | ||
| 324 | } | ||
| 325 | //---------------------------------------------------------------------------- | ||
| 326 | |||
| 327 | //============================================================================ | ||
| 328 | /// @ingroup cpp_kodi_gui_windows_window | ||
| 329 | /// @brief Returns a window property with integer value | ||
| 330 | /// | ||
| 331 | /// @param[in] key string - property name. | ||
| 332 | /// @return integer value of property | ||
| 333 | /// | ||
| 334 | int GetPropertyInt(const std::string& key) const | ||
| 335 | { | ||
| 336 | return m_interface->kodi_gui->window->get_property_int(m_interface->kodiBase, m_controlHandle, | ||
| 337 | key.c_str()); | ||
| 338 | } | ||
| 339 | //---------------------------------------------------------------------------- | ||
| 340 | |||
| 341 | //============================================================================ | ||
| 342 | /// @ingroup cpp_kodi_gui_windows_window | ||
| 343 | /// @brief Sets a window property with boolean value | ||
| 344 | /// | ||
| 345 | /// @param[in] key string - property name. | ||
| 346 | /// @param[in] value boolean value to set | ||
| 347 | /// | ||
| 348 | void SetPropertyBool(const std::string& key, bool value) | ||
| 349 | { | ||
| 350 | m_interface->kodi_gui->window->set_property_bool(m_interface->kodiBase, m_controlHandle, | ||
| 351 | key.c_str(), value); | ||
| 352 | } | ||
| 353 | //---------------------------------------------------------------------------- | ||
| 354 | |||
| 355 | //============================================================================ | ||
| 356 | /// @ingroup cpp_kodi_gui_windows_window | ||
| 357 | /// @brief Returns a window property with boolean value | ||
| 358 | /// | ||
| 359 | /// @param[in] key string - property name. | ||
| 360 | /// @return boolean value of property | ||
| 361 | /// | ||
| 362 | bool GetPropertyBool(const std::string& key) const | ||
| 363 | { | ||
| 364 | return m_interface->kodi_gui->window->get_property_bool(m_interface->kodiBase, m_controlHandle, | ||
| 365 | key.c_str()); | ||
| 366 | } | ||
| 367 | //---------------------------------------------------------------------------- | ||
| 368 | |||
| 369 | //============================================================================ | ||
| 370 | /// @ingroup cpp_kodi_gui_windows_window | ||
| 371 | /// @brief Sets a window property with double value | ||
| 372 | /// | ||
| 373 | /// @param[in] key string - property name. | ||
| 374 | /// @param[in] value double value to set | ||
| 375 | /// | ||
| 376 | void SetPropertyDouble(const std::string& key, double value) | ||
| 377 | { | ||
| 378 | m_interface->kodi_gui->window->set_property_double(m_interface->kodiBase, m_controlHandle, | ||
| 379 | key.c_str(), value); | ||
| 380 | } | ||
| 381 | //---------------------------------------------------------------------------- | ||
| 382 | |||
| 383 | //============================================================================ | ||
| 384 | /// @ingroup cpp_kodi_gui_windows_window | ||
| 385 | /// @brief Returns a window property with double value | ||
| 386 | /// | ||
| 387 | /// @param[in] key string - property name. | ||
| 388 | /// @return double value of property | ||
| 389 | /// | ||
| 390 | double GetPropertyDouble(const std::string& key) const | ||
| 391 | { | ||
| 392 | return m_interface->kodi_gui->window->get_property_double(m_interface->kodiBase, | ||
| 393 | m_controlHandle, key.c_str()); | ||
| 394 | } | ||
| 395 | //---------------------------------------------------------------------------- | ||
| 396 | |||
| 397 | //============================================================================ | ||
| 398 | /// @ingroup cpp_kodi_gui_windows_window | ||
| 399 | /// @brief Remove all present properties from window | ||
| 400 | /// | ||
| 401 | void ClearProperties() | ||
| 402 | { | ||
| 403 | m_interface->kodi_gui->window->clear_properties(m_interface->kodiBase, m_controlHandle); | ||
| 404 | } | ||
| 405 | //---------------------------------------------------------------------------- | ||
| 406 | |||
| 407 | //============================================================================ | ||
| 408 | /// @ingroup cpp_kodi_gui_windows_window | ||
| 409 | /// @brief Clears the specific window property. | ||
| 410 | /// | ||
| 411 | /// @param[in] key string - property name. | ||
| 412 | /// | ||
| 413 | /// @note Key is NOT case sensitive. Equivalent to SetProperty(key, "") | ||
| 414 | /// You can use the above as keywords for arguments and skip certain | ||
| 415 | /// optional arguments. | ||
| 416 | /// Once you use a keyword, all following arguments require the | ||
| 417 | /// keyword. | ||
| 418 | /// | ||
| 419 | /// | ||
| 420 | ///----------------------------------------------------------------------- | ||
| 421 | /// | ||
| 422 | /// **Example:** | ||
| 423 | /// ~~~~~~~~~~~~~{.cpp} | ||
| 424 | /// .. | ||
| 425 | /// ClearProperty('Category') | ||
| 426 | /// .. | ||
| 427 | /// ~~~~~~~~~~~~~ | ||
| 428 | /// | ||
| 429 | void ClearProperty(const std::string& key) | ||
| 430 | { | ||
| 431 | m_interface->kodi_gui->window->clear_property(m_interface->kodiBase, m_controlHandle, | ||
| 432 | key.c_str()); | ||
| 433 | } | ||
| 434 | //---------------------------------------------------------------------------- | ||
| 435 | |||
| 436 | /// @{ | ||
| 437 | //============================================================================ | ||
| 438 | /// @ingroup cpp_kodi_gui_windows_window | ||
| 439 | /// @brief Function delete all entries in integrated list. | ||
| 440 | /// | ||
| 441 | void ClearList() | ||
| 442 | { | ||
| 443 | m_interface->kodi_gui->window->clear_item_list(m_interface->kodiBase, m_controlHandle); | ||
| 444 | } | ||
| 445 | //---------------------------------------------------------------------------- | ||
| 446 | |||
| 447 | //============================================================================ | ||
| 448 | /// @ingroup cpp_kodi_gui_windows_window | ||
| 449 | /// @brief To add a list item in the on window integrated list. | ||
| 450 | /// | ||
| 451 | /// @param[in] item List item to add | ||
| 452 | /// @param[in] itemPosition [opt] The position for item, default is on end | ||
| 453 | /// | ||
| 454 | void AddListItem(std::shared_ptr<CListItem> item, int itemPosition = -1) | ||
| 455 | { | ||
| 456 | m_interface->kodi_gui->window->add_list_item(m_interface->kodiBase, m_controlHandle, | ||
| 457 | item->m_controlHandle, itemPosition); | ||
| 458 | } | ||
| 459 | //---------------------------------------------------------------------------- | ||
| 460 | |||
| 461 | //============================================================================ | ||
| 462 | /// @ingroup cpp_kodi_gui_windows_window | ||
| 463 | /// @brief To add a list item based upon string in the on window integrated list. | ||
| 464 | /// | ||
| 465 | /// @param[in] item List item to add | ||
| 466 | /// @param[in] itemPosition [opt] The position for item, default is on end | ||
| 467 | /// | ||
| 468 | void AddListItem(const std::string item, int itemPosition = -1) | ||
| 469 | { | ||
| 470 | m_interface->kodi_gui->window->add_list_item( | ||
| 471 | m_interface->kodiBase, m_controlHandle, | ||
| 472 | std::make_shared<kodi::gui::CListItem>(item)->m_controlHandle, itemPosition); | ||
| 473 | } | ||
| 474 | //---------------------------------------------------------------------------- | ||
| 475 | |||
| 476 | //============================================================================ | ||
| 477 | /// @ingroup cpp_kodi_gui_windows_window | ||
| 478 | /// @brief Remove list item on position. | ||
| 479 | /// | ||
| 480 | /// @param[in] itemPosition List position to remove | ||
| 481 | /// | ||
| 482 | void RemoveListItem(int itemPosition) | ||
| 483 | { | ||
| 484 | m_interface->kodi_gui->window->remove_list_item_from_position(m_interface->kodiBase, | ||
| 485 | m_controlHandle, itemPosition); | ||
| 486 | } | ||
| 487 | //---------------------------------------------------------------------------- | ||
| 488 | |||
| 489 | //============================================================================ | ||
| 490 | /// @ingroup cpp_kodi_gui_windows_window | ||
| 491 | /// @brief Remove item with given control class from list. | ||
| 492 | /// | ||
| 493 | /// @param[in] item List item control class to remove | ||
| 494 | /// | ||
| 495 | void RemoveListItem(std::shared_ptr<CListItem> item) | ||
| 496 | { | ||
| 497 | m_interface->kodi_gui->window->remove_list_item(m_interface->kodiBase, m_controlHandle, | ||
| 498 | item->m_controlHandle); | ||
| 499 | } | ||
| 500 | //---------------------------------------------------------------------------- | ||
| 501 | |||
| 502 | //============================================================================ | ||
| 503 | /// @ingroup cpp_kodi_gui_windows_window | ||
| 504 | /// @brief To get list item control class on wanted position. | ||
| 505 | /// | ||
| 506 | /// @param[in] listPos Position from where control is needed | ||
| 507 | /// @return The list item control class or null if not found | ||
| 508 | /// | ||
| 509 | /// @warning Function returns a new generated **CListItem** class! | ||
| 510 | /// | ||
| 511 | std::shared_ptr<CListItem> GetListItem(int listPos) | ||
| 512 | { | ||
| 513 | KODI_GUI_LISTITEM_HANDLE handle = m_interface->kodi_gui->window->get_list_item( | ||
| 514 | m_interface->kodiBase, m_controlHandle, listPos); | ||
| 515 | if (!handle) | ||
| 516 | return std::shared_ptr<CListItem>(); | ||
| 517 | |||
| 518 | return std::make_shared<kodi::gui::CListItem>(handle); | ||
| 519 | } | ||
| 520 | //---------------------------------------------------------------------------- | ||
| 521 | |||
| 522 | //============================================================================ | ||
| 523 | /// @ingroup cpp_kodi_gui_windows_window | ||
| 524 | /// @brief To set position of selected part in list. | ||
| 525 | /// | ||
| 526 | /// @param[in] listPos Position to use | ||
| 527 | /// | ||
| 528 | void SetCurrentListPosition(int listPos) | ||
| 529 | { | ||
| 530 | m_interface->kodi_gui->window->set_current_list_position(m_interface->kodiBase, m_controlHandle, | ||
| 531 | listPos); | ||
| 532 | } | ||
| 533 | //---------------------------------------------------------------------------- | ||
| 534 | |||
| 535 | //============================================================================ | ||
| 536 | /// @ingroup cpp_kodi_gui_windows_window | ||
| 537 | /// @brief To get current selected position in list | ||
| 538 | /// | ||
| 539 | /// @return Current list position | ||
| 540 | /// | ||
| 541 | int GetCurrentListPosition() | ||
| 542 | { | ||
| 543 | return m_interface->kodi_gui->window->get_current_list_position(m_interface->kodiBase, | ||
| 544 | m_controlHandle); | ||
| 545 | } | ||
| 546 | //---------------------------------------------------------------------------- | ||
| 547 | |||
| 548 | //============================================================================ | ||
| 549 | /// @ingroup cpp_kodi_gui_windows_window | ||
| 550 | /// @brief To get the amount of entries in the list. | ||
| 551 | /// | ||
| 552 | /// @return Size of in window integrated control class | ||
| 553 | /// | ||
| 554 | int GetListSize() | ||
| 555 | { | ||
| 556 | return m_interface->kodi_gui->window->get_list_size(m_interface->kodiBase, m_controlHandle); | ||
| 557 | } | ||
| 558 | //---------------------------------------------------------------------------- | ||
| 559 | |||
| 560 | //============================================================================ | ||
| 561 | /// @ingroup cpp_kodi_gui_windows_window | ||
| 562 | /// @brief Sets a container property, similar to an infolabel. | ||
| 563 | /// | ||
| 564 | /// @param[in] key string - property name. | ||
| 565 | /// @param[in] value string or unicode - value of property. | ||
| 566 | /// | ||
| 567 | /// @note Key is NOT case sensitive.\n | ||
| 568 | /// You can use the above as keywords for arguments and skip certain | ||
| 569 | /// optional arguments.\n | ||
| 570 | /// Once you use a keyword, all following arguments require the keyword. | ||
| 571 | /// | ||
| 572 | void SetContainerProperty(const std::string& key, const std::string& value) | ||
| 573 | { | ||
| 574 | m_interface->kodi_gui->window->set_container_property(m_interface->kodiBase, m_controlHandle, | ||
| 575 | key.c_str(), value.c_str()); | ||
| 576 | } | ||
| 577 | //---------------------------------------------------------------------------- | ||
| 578 | |||
| 579 | //============================================================================ | ||
| 580 | /// @ingroup cpp_kodi_gui_windows_window | ||
| 581 | /// @brief Sets the content type of the container. | ||
| 582 | /// | ||
| 583 | /// @param[in] value string or unicode - content value. | ||
| 584 | /// | ||
| 585 | /// __Available content types__ | ||
| 586 | /// | Name | Media | | ||
| 587 | /// |:-----------:|:-----------------------------------------| | ||
| 588 | /// | actors | Videos | ||
| 589 | /// | addons | Addons, Music, Pictures, Programs, Videos | ||
| 590 | /// | albums | Music, Videos | ||
| 591 | /// | artists | Music, Videos | ||
| 592 | /// | countries | Music, Videos | ||
| 593 | /// | directors | Videos | ||
| 594 | /// | files | Music, Videos | ||
| 595 | /// | games | Games | ||
| 596 | /// | genres | Music, Videos | ||
| 597 | /// | images | Pictures | ||
| 598 | /// | mixed | Music, Videos | ||
| 599 | /// | movies | Videos | ||
| 600 | /// | Musicvideos | Music, Videos | ||
| 601 | /// | playlists | Music, Videos | ||
| 602 | /// | seasons | Videos | ||
| 603 | /// | sets | Videos | ||
| 604 | /// | songs | Music | ||
| 605 | /// | studios | Music, Videos | ||
| 606 | /// | tags | Music, Videos | ||
| 607 | /// | tvshows | Videos | ||
| 608 | /// | videos | Videos | ||
| 609 | /// | years | Music, Videos | ||
| 610 | /// | ||
| 611 | void SetContainerContent(const std::string& value) | ||
| 612 | { | ||
| 613 | m_interface->kodi_gui->window->set_container_content(m_interface->kodiBase, m_controlHandle, | ||
| 614 | value.c_str()); | ||
| 615 | } | ||
| 616 | //---------------------------------------------------------------------------- | ||
| 617 | |||
| 618 | //============================================================================ | ||
| 619 | /// @ingroup cpp_kodi_gui_windows_window | ||
| 620 | /// @brief Get the id of the currently visible container. | ||
| 621 | /// | ||
| 622 | /// @return currently visible container id | ||
| 623 | /// | ||
| 624 | int GetCurrentContainerId() | ||
| 625 | { | ||
| 626 | return m_interface->kodi_gui->window->get_current_container_id(m_interface->kodiBase, | ||
| 627 | m_controlHandle); | ||
| 628 | } | ||
| 629 | //---------------------------------------------------------------------------- | ||
| 630 | /// @} | ||
| 631 | |||
| 632 | //============================================================================ | ||
| 633 | /// @ingroup cpp_kodi_gui_windows_window | ||
| 634 | /// @brief To inform Kodi that it need to render region new. | ||
| 635 | /// | ||
| 636 | void MarkDirtyRegion() | ||
| 637 | { | ||
| 638 | return m_interface->kodi_gui->window->mark_dirty_region(m_interface->kodiBase, m_controlHandle); | ||
| 639 | } | ||
| 640 | //---------------------------------------------------------------------------- | ||
| 641 | |||
| 642 | //============================================================================ | ||
| 643 | /// @defgroup cpp_kodi_gui_windows_window_callbacks Callback functions from Kodi to add-on | ||
| 644 | /// @ingroup cpp_kodi_gui_windows_window | ||
| 645 | /// @{ | ||
| 646 | /// @brief <b>GUI window callback functions.</b>\n | ||
| 647 | /// Functions to handle control callbacks from Kodi | ||
| 648 | /// | ||
| 649 | /// ------------------------------------------------------------------------ | ||
| 650 | /// | ||
| 651 | /// @link cpp_kodi_gui_windows_window Go back to normal functions from CWindow@endlink | ||
| 652 | // | ||
| 653 | |||
| 654 | //============================================================================ | ||
| 655 | /// @ingroup cpp_kodi_gui_windows_window_callbacks | ||
| 656 | /// @brief OnInit method. | ||
| 657 | /// | ||
| 658 | /// @return Return true if initialize was done successful | ||
| 659 | /// | ||
| 660 | /// | ||
| 661 | virtual bool OnInit() { return false; } | ||
| 662 | //---------------------------------------------------------------------------- | ||
| 663 | |||
| 664 | //============================================================================ | ||
| 665 | /// @ingroup cpp_kodi_gui_windows_window_callbacks | ||
| 666 | /// @brief OnFocus method. | ||
| 667 | /// | ||
| 668 | /// @param[in] controlId GUI control identifier | ||
| 669 | /// @return Return true if focus condition was handled there or false to handle | ||
| 670 | /// them by Kodi itself | ||
| 671 | /// | ||
| 672 | /// | ||
| 673 | virtual bool OnFocus(int controlId) { return false; } | ||
| 674 | //---------------------------------------------------------------------------- | ||
| 675 | |||
| 676 | //============================================================================ | ||
| 677 | /// @ingroup cpp_kodi_gui_windows_window_callbacks | ||
| 678 | /// @brief OnClick method. | ||
| 679 | /// | ||
| 680 | /// @param[in] controlId GUI control identifier | ||
| 681 | /// @return Return true if click was handled there or false to handle them by | ||
| 682 | /// Kodi itself | ||
| 683 | /// | ||
| 684 | /// | ||
| 685 | virtual bool OnClick(int controlId) { return false; } | ||
| 686 | //---------------------------------------------------------------------------- | ||
| 687 | |||
| 688 | //============================================================================ | ||
| 689 | /// @ingroup cpp_kodi_gui_windows_window_callbacks | ||
| 690 | /// @brief OnAction method. | ||
| 691 | /// | ||
| 692 | /// @param[in] actionId The action id to perform, see | ||
| 693 | /// @ref kodi_key_action_ids to get list of | ||
| 694 | /// them | ||
| 695 | /// @return Return true if action was handled there | ||
| 696 | /// or false to handle them by Kodi itself | ||
| 697 | /// | ||
| 698 | /// | ||
| 699 | /// This method will receive all actions that the main program will send | ||
| 700 | /// to this window. | ||
| 701 | /// | ||
| 702 | /// @note | ||
| 703 | /// - By default, only the @c ADDON_ACTION_PREVIOUS_MENU and @c ADDON_ACTION_NAV_BACK actions are handled. | ||
| 704 | /// - Overwrite this method to let your code handle all actions. | ||
| 705 | /// - Don't forget to capture @ref ADDON_ACTION_PREVIOUS_MENU or @ref ADDON_ACTION_NAV_BACK, else the user can't close this window. | ||
| 706 | /// | ||
| 707 | /// | ||
| 708 | ///---------------------------------------------------------------------------- | ||
| 709 | /// | ||
| 710 | /// **Example:** | ||
| 711 | /// ~~~~~~~~~~~~~{.cpp} | ||
| 712 | /// .. | ||
| 713 | /// // Window used with parent / child way | ||
| 714 | /// bool cYOUR_CLASS::OnAction(ADDON_ACTION actionId) | ||
| 715 | /// { | ||
| 716 | /// switch (action) | ||
| 717 | /// { | ||
| 718 | /// case ADDON_ACTION_PREVIOUS_MENU: | ||
| 719 | /// case ADDON_ACTION_NAV_BACK: | ||
| 720 | /// printf("action recieved: previous"); | ||
| 721 | /// Close(); | ||
| 722 | /// return true; | ||
| 723 | /// case ADDON_ACTION_SHOW_INFO: | ||
| 724 | /// printf("action recieved: show info"); | ||
| 725 | /// break; | ||
| 726 | /// case ADDON_ACTION_STOP: | ||
| 727 | /// printf("action recieved: stop"); | ||
| 728 | /// break; | ||
| 729 | /// case ADDON_ACTION_PAUSE: | ||
| 730 | /// printf("action recieved: pause"); | ||
| 731 | /// break; | ||
| 732 | /// default: | ||
| 733 | /// break; | ||
| 734 | /// } | ||
| 735 | /// return false; | ||
| 736 | /// } | ||
| 737 | /// .. | ||
| 738 | /// ~~~~~~~~~~~~~ | ||
| 739 | /// | ||
| 740 | virtual bool OnAction(ADDON_ACTION actionId) | ||
| 741 | { | ||
| 742 | switch (actionId) | ||
| 743 | { | ||
| 744 | case ADDON_ACTION_PREVIOUS_MENU: | ||
| 745 | case ADDON_ACTION_NAV_BACK: | ||
| 746 | Close(); | ||
| 747 | return true; | ||
| 748 | default: | ||
| 749 | break; | ||
| 750 | } | ||
| 751 | return false; | ||
| 752 | } | ||
| 753 | //---------------------------------------------------------------------------- | ||
| 754 | |||
| 755 | //============================================================================ | ||
| 756 | /// @ingroup cpp_kodi_gui_windows_window_callbacks | ||
| 757 | /// @brief Get context menu buttons for list entry. | ||
| 758 | /// | ||
| 759 | /// @param[in] itemNumber Selected list item entry | ||
| 760 | /// @param[in] buttons List where context menus becomes added with his | ||
| 761 | /// identifier and name | ||
| 762 | /// | ||
| 763 | virtual void GetContextButtons(int itemNumber, | ||
| 764 | std::vector<std::pair<unsigned int, std::string>>& buttons) | ||
| 765 | { | ||
| 766 | } | ||
| 767 | //---------------------------------------------------------------------------- | ||
| 768 | |||
| 769 | //============================================================================ | ||
| 770 | /// @ingroup cpp_kodi_gui_windows_window_callbacks | ||
| 771 | /// @brief Called after selection in context menu. | ||
| 772 | /// | ||
| 773 | /// @param[in] itemNumber Selected list item entry | ||
| 774 | /// @param[in] button The pressed button id | ||
| 775 | /// @return true if handled, otherwise false | ||
| 776 | /// | ||
| 777 | virtual bool OnContextButton(int itemNumber, unsigned int button) { return false; } | ||
| 778 | //---------------------------------------------------------------------------- | ||
| 779 | |||
| 780 | //============================================================================ | ||
| 781 | /// @ingroup cpp_kodi_gui_windows_window_callbacks | ||
| 782 | /// @brief **Set independent callbacks** | ||
| 783 | /// | ||
| 784 | /// If the class is used independent (with "new CWindow") and | ||
| 785 | /// not as parent (with \"cCLASS_own : public @ref cpp_kodi_gui_windows_window "kodi::gui::CWindow"\") from own must be the | ||
| 786 | /// callback from Kodi to add-on overdriven with own functions! | ||
| 787 | /// | ||
| 788 | /// @param[in] cbhdl The pointer to own handle data structure / class | ||
| 789 | /// @param[in] CBOnInit Own defined window init function | ||
| 790 | /// @param[in] CBOnFocus Own defined focus function | ||
| 791 | /// @param[in] CBOnClick Own defined click function | ||
| 792 | /// @param[in] CBOnAction Own defined action function | ||
| 793 | /// @param[in] CBGetContextButtons [opt] To get context menu entries for | ||
| 794 | /// lists function | ||
| 795 | /// @param[in] CBOnContextButton [opt] Used context menu entry function | ||
| 796 | /// | ||
| 797 | /// | ||
| 798 | ///---------------------------------------------------------------------------- | ||
| 799 | /// | ||
| 800 | /// **Example:** | ||
| 801 | /// ~~~~~~~~~~~~~{.cpp} | ||
| 802 | /// ... | ||
| 803 | /// | ||
| 804 | /// bool OnInit(kodi::gui::ClientHandle cbhdl) | ||
| 805 | /// { | ||
| 806 | /// ... | ||
| 807 | /// return true; | ||
| 808 | /// } | ||
| 809 | /// | ||
| 810 | /// bool OnFocus(kodi::gui::ClientHandle cbhdl, int controlId) | ||
| 811 | /// { | ||
| 812 | /// ... | ||
| 813 | /// return true; | ||
| 814 | /// } | ||
| 815 | /// | ||
| 816 | /// bool OnClick(kodi::gui::ClientHandle cbhdl, int controlId) | ||
| 817 | /// { | ||
| 818 | /// ... | ||
| 819 | /// return true; | ||
| 820 | /// } | ||
| 821 | /// | ||
| 822 | /// bool OnAction(kodi::gui::ClientHandle cbhdl, ADDON_ACTION actionId) | ||
| 823 | /// { | ||
| 824 | /// ... | ||
| 825 | /// return true; | ||
| 826 | /// } | ||
| 827 | /// | ||
| 828 | /// ... | ||
| 829 | /// // Somewhere where you create the window | ||
| 830 | /// CWindow myWindow = new CWindow; | ||
| 831 | /// myWindow->SetIndependentCallbacks(myWindow, OnInit, OnFocus, OnClick, OnAction); | ||
| 832 | /// ... | ||
| 833 | /// ~~~~~~~~~~~~~ | ||
| 834 | /// | ||
| 835 | void SetIndependentCallbacks(kodi::gui::ClientHandle cbhdl, | ||
| 836 | bool (*CBOnInit)(kodi::gui::ClientHandle cbhdl), | ||
| 837 | bool (*CBOnFocus)(kodi::gui::ClientHandle cbhdl, int controlId), | ||
| 838 | bool (*CBOnClick)(kodi::gui::ClientHandle cbhdl, int controlId), | ||
| 839 | bool (*CBOnAction)(kodi::gui::ClientHandle cbhdl, | ||
| 840 | ADDON_ACTION actionId), | ||
| 841 | void (*CBGetContextButtons)(kodi::gui::ClientHandle cbhdl, | ||
| 842 | int itemNumber, | ||
| 843 | gui_context_menu_pair* buttons, | ||
| 844 | unsigned int* size) = nullptr, | ||
| 845 | bool (*CBOnContextButton)(kodi::gui::ClientHandle cbhdl, | ||
| 846 | int itemNumber, | ||
| 847 | unsigned int button) = nullptr) | ||
| 848 | { | ||
| 849 | if (!cbhdl || !CBOnInit || !CBOnFocus || !CBOnClick || !CBOnAction) | ||
| 850 | { | ||
| 851 | kodi::Log(ADDON_LOG_FATAL, "kodi::gui::CWindow::%s called with nullptr !!!", __FUNCTION__); | ||
| 852 | return; | ||
| 853 | } | ||
| 854 | |||
| 855 | m_interface->kodi_gui->window->set_callbacks(m_interface->kodiBase, m_controlHandle, cbhdl, | ||
| 856 | CBOnInit, CBOnFocus, CBOnClick, CBOnAction, | ||
| 857 | CBGetContextButtons, CBOnContextButton); | ||
| 858 | } | ||
| 859 | //---------------------------------------------------------------------------- | ||
| 860 | /// @} | ||
| 861 | |||
| 862 | private: | ||
| 863 | static bool CBOnInit(KODI_GUI_CLIENT_HANDLE cbhdl) | ||
| 864 | { | ||
| 865 | return static_cast<CWindow*>(cbhdl)->OnInit(); | ||
| 866 | } | ||
| 867 | |||
| 868 | static bool CBOnFocus(KODI_GUI_CLIENT_HANDLE cbhdl, int controlId) | ||
| 869 | { | ||
| 870 | return static_cast<CWindow*>(cbhdl)->OnFocus(controlId); | ||
| 871 | } | ||
| 872 | |||
| 873 | static bool CBOnClick(KODI_GUI_CLIENT_HANDLE cbhdl, int controlId) | ||
| 874 | { | ||
| 875 | return static_cast<CWindow*>(cbhdl)->OnClick(controlId); | ||
| 876 | } | ||
| 877 | |||
| 878 | static bool CBOnAction(KODI_GUI_CLIENT_HANDLE cbhdl, ADDON_ACTION actionId) | ||
| 879 | { | ||
| 880 | return static_cast<CWindow*>(cbhdl)->OnAction(actionId); | ||
| 881 | } | ||
| 882 | |||
| 883 | static void CBGetContextButtons(KODI_GUI_CLIENT_HANDLE cbhdl, | ||
| 884 | int itemNumber, | ||
| 885 | gui_context_menu_pair* buttons, | ||
| 886 | unsigned int* size) | ||
| 887 | { | ||
| 888 | std::vector<std::pair<unsigned int, std::string>> buttonList; | ||
| 889 | static_cast<CWindow*>(cbhdl)->GetContextButtons(itemNumber, buttonList); | ||
| 890 | if (!buttonList.empty()) | ||
| 891 | { | ||
| 892 | unsigned int presentSize = static_cast<unsigned int>(buttonList.size()); | ||
| 893 | if (presentSize > *size) | ||
| 894 | kodi::Log(ADDON_LOG_WARNING, "GetContextButtons: More as allowed '%i' entries present!", | ||
| 895 | *size); | ||
| 896 | else | ||
| 897 | *size = presentSize; | ||
| 898 | for (unsigned int i = 0; i < *size; ++i) | ||
| 899 | { | ||
| 900 | buttons[i].id = buttonList[i].first; | ||
| 901 | strncpy(buttons[i].name, buttonList[i].second.c_str(), ADDON_MAX_CONTEXT_ENTRY_NAME_LENGTH); | ||
| 902 | } | ||
| 903 | } | ||
| 904 | } | ||
| 905 | |||
| 906 | static bool CBOnContextButton(KODI_GUI_CLIENT_HANDLE cbhdl, int itemNumber, unsigned int button) | ||
| 907 | { | ||
| 908 | return static_cast<CWindow*>(cbhdl)->OnContextButton(itemNumber, button); | ||
| 909 | } | ||
| 910 | }; | ||
| 911 | |||
| 912 | } /* namespace gui */ | ||
| 913 | } /* namespace kodi */ | ||
| 914 | |||
| 915 | #endif /* __cplusplus */ | ||
diff --git a/xbmc/addons/kodi-dev-kit/include/kodi/gui/controls/Button.h b/xbmc/addons/kodi-dev-kit/include/kodi/gui/controls/Button.h new file mode 100644 index 0000000..873a549 --- /dev/null +++ b/xbmc/addons/kodi-dev-kit/include/kodi/gui/controls/Button.h | |||
| @@ -0,0 +1,166 @@ | |||
| 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/button.h" | ||
| 12 | #include "../Window.h" | ||
| 13 | |||
| 14 | #ifdef __cplusplus | ||
| 15 | |||
| 16 | namespace kodi | ||
| 17 | { | ||
| 18 | namespace gui | ||
| 19 | { | ||
| 20 | namespace controls | ||
| 21 | { | ||
| 22 | |||
| 23 | //============================================================================== | ||
| 24 | /// @defgroup cpp_kodi_gui_windows_controls_CButton Control Button | ||
| 25 | /// @ingroup cpp_kodi_gui_windows_controls | ||
| 26 | /// @brief @cpp_class{ kodi::gui::controls::CButton } | ||
| 27 | /// **Standard push button control for window**\n | ||
| 28 | /// The button control is used for creating push buttons in Kodi. | ||
| 29 | /// | ||
| 30 | /// You can choose the position, size, and look of the button, as well as | ||
| 31 | /// choosing what action(s) should be performed when pushed. | ||
| 32 | /// | ||
| 33 | /// It has the header @ref Button.h "#include <kodi/gui/controls/Button.h>" | ||
| 34 | /// be included to enjoy it. | ||
| 35 | /// | ||
| 36 | /// Here you find the needed skin part for a @ref skin_Button_control "button control" | ||
| 37 | /// | ||
| 38 | /// @note The call of the control is only possible from the corresponding | ||
| 39 | /// window as its class and identification number is required. | ||
| 40 | /// | ||
| 41 | class ATTRIBUTE_HIDDEN CButton : public CAddonGUIControlBase | ||
| 42 | { | ||
| 43 | public: | ||
| 44 | //============================================================================ | ||
| 45 | /// @ingroup cpp_kodi_gui_windows_controls_CButton | ||
| 46 | /// @brief Construct a new control. | ||
| 47 | /// | ||
| 48 | /// @param[in] window Related window control class | ||
| 49 | /// @param[in] controlId Used skin xml control id | ||
| 50 | /// | ||
| 51 | CButton(CWindow* window, int controlId) : CAddonGUIControlBase(window) | ||
| 52 | { | ||
| 53 | m_controlHandle = m_interface->kodi_gui->window->get_control_button( | ||
| 54 | m_interface->kodiBase, m_Window->GetControlHandle(), controlId); | ||
| 55 | if (!m_controlHandle) | ||
| 56 | kodi::Log(ADDON_LOG_FATAL, "kodi::gui::CButton can't create control class from Kodi !!!"); | ||
| 57 | } | ||
| 58 | //---------------------------------------------------------------------------- | ||
| 59 | |||
| 60 | //============================================================================ | ||
| 61 | /// @ingroup cpp_kodi_gui_windows_controls_CButton | ||
| 62 | /// @brief Destructor. | ||
| 63 | /// | ||
| 64 | ~CButton() override = default; | ||
| 65 | //---------------------------------------------------------------------------- | ||
| 66 | |||
| 67 | //============================================================================ | ||
| 68 | /// @ingroup cpp_kodi_gui_windows_controls_CButton | ||
| 69 | /// @brief Set the control on window to visible. | ||
| 70 | /// | ||
| 71 | /// @param[in] visible If true visible, otherwise hidden | ||
| 72 | /// | ||
| 73 | void SetVisible(bool visible) | ||
| 74 | { | ||
| 75 | m_interface->kodi_gui->control_button->set_visible(m_interface->kodiBase, m_controlHandle, | ||
| 76 | visible); | ||
| 77 | } | ||
| 78 | //---------------------------------------------------------------------------- | ||
| 79 | |||
| 80 | //============================================================================ | ||
| 81 | /// @ingroup cpp_kodi_gui_windows_controls_CButton | ||
| 82 | /// @brief Set's the control's enabled/disabled state. | ||
| 83 | /// | ||
| 84 | /// @param[in] enabled If true enabled, otherwise disabled | ||
| 85 | /// | ||
| 86 | void SetEnabled(bool enabled) | ||
| 87 | { | ||
| 88 | m_interface->kodi_gui->control_button->set_enabled(m_interface->kodiBase, m_controlHandle, | ||
| 89 | enabled); | ||
| 90 | } | ||
| 91 | //---------------------------------------------------------------------------- | ||
| 92 | |||
| 93 | //============================================================================ | ||
| 94 | /// @ingroup cpp_kodi_gui_windows_controls_CButton | ||
| 95 | /// @brief To set the text string on button. | ||
| 96 | /// | ||
| 97 | /// @param[in] label Text to show | ||
| 98 | /// | ||
| 99 | void SetLabel(const std::string& label) | ||
| 100 | { | ||
| 101 | m_interface->kodi_gui->control_button->set_label(m_interface->kodiBase, m_controlHandle, | ||
| 102 | label.c_str()); | ||
| 103 | } | ||
| 104 | //---------------------------------------------------------------------------- | ||
| 105 | |||
| 106 | //============================================================================ | ||
| 107 | /// @ingroup cpp_kodi_gui_windows_controls_CButton | ||
| 108 | /// @brief Get the used text from button. | ||
| 109 | /// | ||
| 110 | /// @return Text shown | ||
| 111 | /// | ||
| 112 | std::string GetLabel() const | ||
| 113 | { | ||
| 114 | std::string label; | ||
| 115 | char* ret = | ||
| 116 | m_interface->kodi_gui->control_button->get_label(m_interface->kodiBase, m_controlHandle); | ||
| 117 | if (ret != nullptr) | ||
| 118 | { | ||
| 119 | if (std::strlen(ret)) | ||
| 120 | label = ret; | ||
| 121 | m_interface->free_string(m_interface->kodiBase, ret); | ||
| 122 | } | ||
| 123 | return label; | ||
| 124 | } | ||
| 125 | //---------------------------------------------------------------------------- | ||
| 126 | |||
| 127 | //============================================================================ | ||
| 128 | /// @ingroup cpp_kodi_gui_windows_controls_CButton | ||
| 129 | /// @brief If two labels are used for button becomes it set with them. | ||
| 130 | /// | ||
| 131 | /// @param[in] label Text for second label | ||
| 132 | /// | ||
| 133 | void SetLabel2(const std::string& label) | ||
| 134 | { | ||
| 135 | m_interface->kodi_gui->control_button->set_label2(m_interface->kodiBase, m_controlHandle, | ||
| 136 | label.c_str()); | ||
| 137 | } | ||
| 138 | //---------------------------------------------------------------------------- | ||
| 139 | |||
| 140 | //============================================================================ | ||
| 141 | /// @ingroup cpp_kodi_gui_windows_controls_CButton | ||
| 142 | /// @brief Get the second label if present. | ||
| 143 | /// | ||
| 144 | /// @return Second label | ||
| 145 | /// | ||
| 146 | std::string GetLabel2() const | ||
| 147 | { | ||
| 148 | std::string label; | ||
| 149 | char* ret = | ||
| 150 | m_interface->kodi_gui->control_button->get_label2(m_interface->kodiBase, m_controlHandle); | ||
| 151 | if (ret != nullptr) | ||
| 152 | { | ||
| 153 | if (std::strlen(ret)) | ||
| 154 | label = ret; | ||
| 155 | m_interface->free_string(m_interface->kodiBase, ret); | ||
| 156 | } | ||
| 157 | return label; | ||
| 158 | } | ||
| 159 | //---------------------------------------------------------------------------- | ||
| 160 | }; | ||
| 161 | |||
| 162 | } /* namespace controls */ | ||
| 163 | } /* namespace gui */ | ||
| 164 | } /* namespace kodi */ | ||
| 165 | |||
| 166 | #endif /* __cplusplus */ | ||
diff --git a/xbmc/addons/kodi-dev-kit/include/kodi/gui/controls/CMakeLists.txt b/xbmc/addons/kodi-dev-kit/include/kodi/gui/controls/CMakeLists.txt new file mode 100644 index 0000000..3fdab01 --- /dev/null +++ b/xbmc/addons/kodi-dev-kit/include/kodi/gui/controls/CMakeLists.txt | |||
| @@ -0,0 +1,16 @@ | |||
| 1 | set(HEADERS Button.h | ||
| 2 | Edit.h | ||
| 3 | FadeLabel.h | ||
| 4 | Image.h | ||
| 5 | Label.h | ||
| 6 | Progress.h | ||
| 7 | RadioButton.h | ||
| 8 | Rendering.h | ||
| 9 | SettingsSlider.h | ||
| 10 | Slider.h | ||
| 11 | Spin.h | ||
| 12 | TextBox.h) | ||
| 13 | |||
| 14 | if(NOT ENABLE_STATIC_LIBS) | ||
| 15 | core_add_library(addons_kodi-dev-kit_include_kodi_gui_controls) | ||
| 16 | endif() | ||
diff --git a/xbmc/addons/kodi-dev-kit/include/kodi/gui/controls/Edit.h b/xbmc/addons/kodi-dev-kit/include/kodi/gui/controls/Edit.h new file mode 100644 index 0000000..00c6231 --- /dev/null +++ b/xbmc/addons/kodi-dev-kit/include/kodi/gui/controls/Edit.h | |||
| @@ -0,0 +1,217 @@ | |||
| 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/edit.h" | ||
| 12 | #include "../Window.h" | ||
| 13 | |||
| 14 | #ifdef __cplusplus | ||
| 15 | |||
| 16 | namespace kodi | ||
| 17 | { | ||
| 18 | namespace gui | ||
| 19 | { | ||
| 20 | namespace controls | ||
| 21 | { | ||
| 22 | |||
| 23 | //============================================================================== | ||
| 24 | /// @defgroup cpp_kodi_gui_windows_controls_CEdit Control Edit | ||
| 25 | /// @ingroup cpp_kodi_gui_windows_controls | ||
| 26 | /// @brief @cpp_class{ kodi::gui::controls::CEdit } | ||
| 27 | /// **Editable window text control used as an input control for the osd keyboard | ||
| 28 | /// and other input fields**\n | ||
| 29 | /// The edit control allows a user to input text in Kodi. | ||
| 30 | /// | ||
| 31 | /// You can choose the font, size, colour, location and header of the text to be | ||
| 32 | /// displayed. | ||
| 33 | /// | ||
| 34 | /// It has the header @ref Edit.h "#include <kodi/gui/controls/Edit.h>" | ||
| 35 | /// be included to enjoy it. | ||
| 36 | /// | ||
| 37 | /// Here you find the needed skin partfor a @ref skin_Edit_control "edit control". | ||
| 38 | /// | ||
| 39 | /// @note The call of the control is only possible from the corresponding | ||
| 40 | /// window as its class and identification number is required. | ||
| 41 | /// | ||
| 42 | |||
| 43 | //============================================================================== | ||
| 44 | // see gui/definition.h for use of group "cpp_kodi_gui_windows_controls_CEdit_Defs" | ||
| 45 | /// | ||
| 46 | /// @defgroup cpp_kodi_gui_windows_controls_CEdit_Defs Definitions, structures and enumerators | ||
| 47 | /// @ingroup cpp_kodi_gui_windows_controls_CEdit | ||
| 48 | /// @brief **Library definition values** | ||
| 49 | /// | ||
| 50 | |||
| 51 | class ATTRIBUTE_HIDDEN CEdit : public CAddonGUIControlBase | ||
| 52 | { | ||
| 53 | public: | ||
| 54 | //============================================================================ | ||
| 55 | /// @ingroup cpp_kodi_gui_windows_controls_CEdit | ||
| 56 | /// @brief Construct a new control. | ||
| 57 | /// | ||
| 58 | /// @param[in] window Related window control class | ||
| 59 | /// @param[in] controlId Used skin xml control id | ||
| 60 | /// | ||
| 61 | CEdit(CWindow* window, int controlId) : CAddonGUIControlBase(window) | ||
| 62 | { | ||
| 63 | m_controlHandle = m_interface->kodi_gui->window->get_control_edit( | ||
| 64 | m_interface->kodiBase, m_Window->GetControlHandle(), controlId); | ||
| 65 | if (!m_controlHandle) | ||
| 66 | kodi::Log(ADDON_LOG_FATAL, | ||
| 67 | "kodi::gui::control::CEdit can't create control class from Kodi !!!"); | ||
| 68 | } | ||
| 69 | //---------------------------------------------------------------------------- | ||
| 70 | |||
| 71 | //============================================================================ | ||
| 72 | /// @ingroup cpp_kodi_gui_windows_controls_CEdit | ||
| 73 | /// @brief Destructor. | ||
| 74 | /// | ||
| 75 | ~CEdit() override = default; | ||
| 76 | //---------------------------------------------------------------------------- | ||
| 77 | |||
| 78 | //============================================================================ | ||
| 79 | /// @ingroup cpp_kodi_gui_windows_controls_CEdit | ||
| 80 | /// @brief Set the control on window to visible. | ||
| 81 | /// | ||
| 82 | /// @param[in] visible If true visible, otherwise hidden | ||
| 83 | /// | ||
| 84 | void SetVisible(bool visible) | ||
| 85 | { | ||
| 86 | m_interface->kodi_gui->control_edit->set_visible(m_interface->kodiBase, m_controlHandle, | ||
| 87 | visible); | ||
| 88 | } | ||
| 89 | //---------------------------------------------------------------------------- | ||
| 90 | |||
| 91 | //============================================================================ | ||
| 92 | /// @ingroup cpp_kodi_gui_windows_controls_CEdit | ||
| 93 | /// @brief Set's the control's enabled/disabled state. | ||
| 94 | /// | ||
| 95 | /// @param[in] enabled If true enabled, otherwise disabled | ||
| 96 | /// | ||
| 97 | void SetEnabled(bool enabled) | ||
| 98 | { | ||
| 99 | m_interface->kodi_gui->control_edit->set_enabled(m_interface->kodiBase, m_controlHandle, | ||
| 100 | enabled); | ||
| 101 | } | ||
| 102 | //---------------------------------------------------------------------------- | ||
| 103 | |||
| 104 | //============================================================================ | ||
| 105 | /// @ingroup cpp_kodi_gui_windows_controls_CEdit | ||
| 106 | /// @brief To set the text string on edit control. | ||
| 107 | /// | ||
| 108 | /// @param[in] label Text to show | ||
| 109 | /// | ||
| 110 | void SetLabel(const std::string& label) | ||
| 111 | { | ||
| 112 | m_interface->kodi_gui->control_edit->set_label(m_interface->kodiBase, m_controlHandle, | ||
| 113 | label.c_str()); | ||
| 114 | } | ||
| 115 | //---------------------------------------------------------------------------- | ||
| 116 | |||
| 117 | //============================================================================ | ||
| 118 | /// @ingroup cpp_kodi_gui_windows_controls_CEdit | ||
| 119 | /// @brief Returns the text heading for this edit control. | ||
| 120 | /// | ||
| 121 | /// @return Heading text | ||
| 122 | /// | ||
| 123 | std::string GetLabel() const | ||
| 124 | { | ||
| 125 | std::string label; | ||
| 126 | char* ret = | ||
| 127 | m_interface->kodi_gui->control_edit->get_label(m_interface->kodiBase, m_controlHandle); | ||
| 128 | if (ret != nullptr) | ||
| 129 | { | ||
| 130 | if (std::strlen(ret)) | ||
| 131 | label = ret; | ||
| 132 | m_interface->free_string(m_interface->kodiBase, ret); | ||
| 133 | } | ||
| 134 | return label; | ||
| 135 | } | ||
| 136 | //---------------------------------------------------------------------------- | ||
| 137 | |||
| 138 | //============================================================================ | ||
| 139 | /// @ingroup cpp_kodi_gui_windows_controls_CEdit | ||
| 140 | /// @brief Set's text heading for this edit control. | ||
| 141 | /// | ||
| 142 | /// @param[in] text string or unicode - text string. | ||
| 143 | /// | ||
| 144 | void SetText(const std::string& text) | ||
| 145 | { | ||
| 146 | m_interface->kodi_gui->control_edit->set_text(m_interface->kodiBase, m_controlHandle, | ||
| 147 | text.c_str()); | ||
| 148 | } | ||
| 149 | //---------------------------------------------------------------------------- | ||
| 150 | |||
| 151 | //============================================================================ | ||
| 152 | /// @ingroup cpp_kodi_gui_windows_controls_CEdit | ||
| 153 | /// @brief Returns the text value for this edit control. | ||
| 154 | /// | ||
| 155 | /// @return Text value of control | ||
| 156 | /// | ||
| 157 | std::string GetText() const | ||
| 158 | { | ||
| 159 | std::string text; | ||
| 160 | char* ret = | ||
| 161 | m_interface->kodi_gui->control_edit->get_text(m_interface->kodiBase, m_controlHandle); | ||
| 162 | if (ret != nullptr) | ||
| 163 | { | ||
| 164 | if (std::strlen(ret)) | ||
| 165 | text = ret; | ||
| 166 | m_interface->free_string(m_interface->kodiBase, ret); | ||
| 167 | } | ||
| 168 | return text; | ||
| 169 | } | ||
| 170 | //---------------------------------------------------------------------------- | ||
| 171 | |||
| 172 | //============================================================================ | ||
| 173 | /// @ingroup cpp_kodi_gui_windows_controls_CEdit | ||
| 174 | /// @brief Set the cursor position on text. | ||
| 175 | /// | ||
| 176 | /// @param[in] position The position to set | ||
| 177 | /// | ||
| 178 | void SetCursorPosition(unsigned int position) | ||
| 179 | { | ||
| 180 | m_interface->kodi_gui->control_edit->set_cursor_position(m_interface->kodiBase, m_controlHandle, | ||
| 181 | position); | ||
| 182 | } | ||
| 183 | //---------------------------------------------------------------------------- | ||
| 184 | |||
| 185 | //============================================================================ | ||
| 186 | /// @ingroup cpp_kodi_gui_windows_controls_CEdit | ||
| 187 | /// @brief To get current cursor position on text field. | ||
| 188 | /// | ||
| 189 | /// @return The current cursor position | ||
| 190 | /// | ||
| 191 | unsigned int GetCursorPosition() | ||
| 192 | { | ||
| 193 | return m_interface->kodi_gui->control_edit->get_cursor_position(m_interface->kodiBase, | ||
| 194 | m_controlHandle); | ||
| 195 | } | ||
| 196 | //---------------------------------------------------------------------------- | ||
| 197 | |||
| 198 | //============================================================================ | ||
| 199 | /// @ingroup cpp_kodi_gui_windows_controls_CEdit | ||
| 200 | /// @brief To set field input type which are defined on @ref AddonGUIInputType. | ||
| 201 | /// | ||
| 202 | /// @param[in] type The @ref AddonGUIInputType "Add-on input type" to use | ||
| 203 | /// @param[in] heading The heading text for related keyboard dialog | ||
| 204 | /// | ||
| 205 | void SetInputType(AddonGUIInputType type, const std::string& heading) | ||
| 206 | { | ||
| 207 | m_interface->kodi_gui->control_edit->set_input_type(m_interface->kodiBase, m_controlHandle, | ||
| 208 | static_cast<int>(type), heading.c_str()); | ||
| 209 | } | ||
| 210 | //---------------------------------------------------------------------------- | ||
| 211 | }; | ||
| 212 | |||
| 213 | } /* namespace controls */ | ||
| 214 | } /* namespace gui */ | ||
| 215 | } /* namespace kodi */ | ||
| 216 | |||
| 217 | #endif /* __cplusplus */ | ||
diff --git a/xbmc/addons/kodi-dev-kit/include/kodi/gui/controls/FadeLabel.h b/xbmc/addons/kodi-dev-kit/include/kodi/gui/controls/FadeLabel.h new file mode 100644 index 0000000..01847fb --- /dev/null +++ b/xbmc/addons/kodi-dev-kit/include/kodi/gui/controls/FadeLabel.h | |||
| @@ -0,0 +1,148 @@ | |||
| 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/fade_label.h" | ||
| 12 | #include "../Window.h" | ||
| 13 | |||
| 14 | #ifdef __cplusplus | ||
| 15 | |||
| 16 | namespace kodi | ||
| 17 | { | ||
| 18 | namespace gui | ||
| 19 | { | ||
| 20 | namespace controls | ||
| 21 | { | ||
| 22 | |||
| 23 | //============================================================================== | ||
| 24 | /// @defgroup cpp_kodi_gui_windows_controls_CFadeLabel Control Fade Label | ||
| 25 | /// @ingroup cpp_kodi_gui_windows_controls | ||
| 26 | /// @brief @cpp_class{ kodi::gui::controls::CFadeLabel } | ||
| 27 | /// **Window control used to show multiple pieces of text in the same position, | ||
| 28 | /// by fading from one to the other**\n | ||
| 29 | /// The fade label control is used for displaying multiple pieces of text in | ||
| 30 | /// the same space in Kodi. | ||
| 31 | /// | ||
| 32 | /// You can choose the font, size, colour, location and contents of the text to | ||
| 33 | /// be displayed. The first piece of information to display fades in over 50 | ||
| 34 | /// frames, then scrolls off to the left. Once it is finished scrolling off | ||
| 35 | /// screen, the second piece of information fades in and the process repeats. | ||
| 36 | /// A fade label control is not supported in a list container. | ||
| 37 | /// | ||
| 38 | /// It has the header @ref FadeLabel.h "#include <kodi/gui/controls/FadeLabel.h>" | ||
| 39 | /// be included to enjoy it. | ||
| 40 | /// | ||
| 41 | /// Here you find the needed skin part for a @ref Fade_Label_Control "fade label control". | ||
| 42 | /// | ||
| 43 | /// @note The call of the control is only possible from the corresponding | ||
| 44 | /// window as its class and identification number is required. | ||
| 45 | /// | ||
| 46 | class ATTRIBUTE_HIDDEN CFadeLabel : public CAddonGUIControlBase | ||
| 47 | { | ||
| 48 | public: | ||
| 49 | //============================================================================ | ||
| 50 | /// @ingroup cpp_kodi_gui_windows_controls_CFadeLabel | ||
| 51 | /// @brief Construct a new control. | ||
| 52 | /// | ||
| 53 | /// @param[in] window Related window control class | ||
| 54 | /// @param[in] controlId Used skin xml control id | ||
| 55 | /// | ||
| 56 | CFadeLabel(CWindow* window, int controlId) : CAddonGUIControlBase(window) | ||
| 57 | { | ||
| 58 | m_controlHandle = m_interface->kodi_gui->window->get_control_fade_label( | ||
| 59 | m_interface->kodiBase, m_Window->GetControlHandle(), controlId); | ||
| 60 | if (!m_controlHandle) | ||
| 61 | kodi::Log(ADDON_LOG_FATAL, | ||
| 62 | "kodi::gui::controls::CFadeLabel can't create control class from Kodi !!!"); | ||
| 63 | } | ||
| 64 | //---------------------------------------------------------------------------- | ||
| 65 | |||
| 66 | //============================================================================ | ||
| 67 | /// @ingroup cpp_kodi_gui_windows_controls_CFadeLabel | ||
| 68 | /// @brief Destructor. | ||
| 69 | /// | ||
| 70 | ~CFadeLabel() override = default; | ||
| 71 | //---------------------------------------------------------------------------- | ||
| 72 | |||
| 73 | //============================================================================ | ||
| 74 | /// @ingroup cpp_kodi_gui_windows_controls_CFadeLabel | ||
| 75 | /// @brief Set the control on window to visible. | ||
| 76 | /// | ||
| 77 | /// @param[in] visible If true visible, otherwise hidden | ||
| 78 | /// | ||
| 79 | void SetVisible(bool visible) | ||
| 80 | { | ||
| 81 | m_interface->kodi_gui->control_fade_label->set_visible(m_interface->kodiBase, m_controlHandle, | ||
| 82 | visible); | ||
| 83 | } | ||
| 84 | //---------------------------------------------------------------------------- | ||
| 85 | |||
| 86 | //============================================================================ | ||
| 87 | /// @ingroup cpp_kodi_gui_windows_controls_CFadeLabel | ||
| 88 | /// @brief To add additional text string on fade label. | ||
| 89 | /// | ||
| 90 | /// @param[in] label Text to show | ||
| 91 | /// | ||
| 92 | void AddLabel(const std::string& label) | ||
| 93 | { | ||
| 94 | m_interface->kodi_gui->control_fade_label->add_label(m_interface->kodiBase, m_controlHandle, | ||
| 95 | label.c_str()); | ||
| 96 | } | ||
| 97 | //---------------------------------------------------------------------------- | ||
| 98 | |||
| 99 | //============================================================================ | ||
| 100 | /// @ingroup cpp_kodi_gui_windows_controls_CFadeLabel | ||
| 101 | /// @brief Get the used text from button. | ||
| 102 | /// | ||
| 103 | /// @return Text shown | ||
| 104 | /// | ||
| 105 | std::string GetLabel() const | ||
| 106 | { | ||
| 107 | std::string label; | ||
| 108 | char* ret = m_interface->kodi_gui->control_fade_label->get_label(m_interface->kodiBase, | ||
| 109 | m_controlHandle); | ||
| 110 | if (ret != nullptr) | ||
| 111 | { | ||
| 112 | if (std::strlen(ret)) | ||
| 113 | label = ret; | ||
| 114 | m_interface->free_string(m_interface->kodiBase, ret); | ||
| 115 | } | ||
| 116 | return label; | ||
| 117 | } | ||
| 118 | //---------------------------------------------------------------------------- | ||
| 119 | |||
| 120 | //============================================================================ | ||
| 121 | /// @ingroup cpp_kodi_gui_windows_controls_CFadeLabel | ||
| 122 | /// @brief To enable or disable scrolling on fade label. | ||
| 123 | /// | ||
| 124 | /// @param[in] scroll To enable scrolling set to true, otherwise is disabled | ||
| 125 | /// | ||
| 126 | void SetScrolling(bool scroll) | ||
| 127 | { | ||
| 128 | m_interface->kodi_gui->control_fade_label->set_scrolling(m_interface->kodiBase, m_controlHandle, | ||
| 129 | scroll); | ||
| 130 | } | ||
| 131 | //---------------------------------------------------------------------------- | ||
| 132 | |||
| 133 | //============================================================================ | ||
| 134 | /// @ingroup cpp_kodi_gui_windows_controls_CFadeLabel | ||
| 135 | /// @brief To reset al inserted labels. | ||
| 136 | /// | ||
| 137 | void Reset() | ||
| 138 | { | ||
| 139 | m_interface->kodi_gui->control_fade_label->reset(m_interface->kodiBase, m_controlHandle); | ||
| 140 | } | ||
| 141 | //---------------------------------------------------------------------------- | ||
| 142 | }; | ||
| 143 | |||
| 144 | } /* namespace controls */ | ||
| 145 | } /* namespace gui */ | ||
| 146 | } /* namespace kodi */ | ||
| 147 | |||
| 148 | #endif /* __cplusplus */ | ||
diff --git a/xbmc/addons/kodi-dev-kit/include/kodi/gui/controls/Image.h b/xbmc/addons/kodi-dev-kit/include/kodi/gui/controls/Image.h new file mode 100644 index 0000000..9dc493e --- /dev/null +++ b/xbmc/addons/kodi-dev-kit/include/kodi/gui/controls/Image.h | |||
| @@ -0,0 +1,112 @@ | |||
| 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/image.h" | ||
| 12 | #include "../Window.h" | ||
| 13 | |||
| 14 | #ifdef __cplusplus | ||
| 15 | |||
| 16 | namespace kodi | ||
| 17 | { | ||
| 18 | namespace gui | ||
| 19 | { | ||
| 20 | namespace controls | ||
| 21 | { | ||
| 22 | |||
| 23 | //============================================================================ | ||
| 24 | /// @defgroup cpp_kodi_gui_windows_controls_CImage Control Image | ||
| 25 | /// @ingroup cpp_kodi_gui_windows_controls | ||
| 26 | /// @brief @cpp_class{ kodi::gui::controls::CImage } | ||
| 27 | /// **Window control used to show an image.**\n | ||
| 28 | /// The image control is used for displaying images in Kodi. You can choose | ||
| 29 | /// the position, size, transparency and contents of the image to be displayed. | ||
| 30 | /// | ||
| 31 | /// It has the header @ref Image.h "#include <kodi/gui/controls/Image.h>" | ||
| 32 | /// be included to enjoy it. | ||
| 33 | /// | ||
| 34 | /// Here you find the needed skin part for a @ref Image_Control "image control". | ||
| 35 | /// | ||
| 36 | /// @note The call of the control is only possible from the corresponding | ||
| 37 | /// window as its class and identification number is required. | ||
| 38 | /// | ||
| 39 | class ATTRIBUTE_HIDDEN CImage : public CAddonGUIControlBase | ||
| 40 | { | ||
| 41 | public: | ||
| 42 | //========================================================================== | ||
| 43 | /// @ingroup cpp_kodi_gui_windows_controls_CImage | ||
| 44 | /// @brief Construct a new control. | ||
| 45 | /// | ||
| 46 | /// @param[in] window Related window control class | ||
| 47 | /// @param[in] controlId Used skin xml control id | ||
| 48 | /// | ||
| 49 | CImage(CWindow* window, int controlId) : CAddonGUIControlBase(window) | ||
| 50 | { | ||
| 51 | m_controlHandle = m_interface->kodi_gui->window->get_control_image( | ||
| 52 | m_interface->kodiBase, m_Window->GetControlHandle(), controlId); | ||
| 53 | if (!m_controlHandle) | ||
| 54 | kodi::Log(ADDON_LOG_FATAL, | ||
| 55 | "kodi::gui::controls::CImage can't create control class from Kodi !!!"); | ||
| 56 | } | ||
| 57 | //-------------------------------------------------------------------------- | ||
| 58 | |||
| 59 | //========================================================================== | ||
| 60 | /// @ingroup cpp_kodi_gui_windows_controls_CImage | ||
| 61 | /// @brief Destructor. | ||
| 62 | /// | ||
| 63 | ~CImage() override = default; | ||
| 64 | //-------------------------------------------------------------------------- | ||
| 65 | |||
| 66 | //========================================================================== | ||
| 67 | /// @ingroup cpp_kodi_gui_windows_controls_CImage | ||
| 68 | /// @brief Set the control on window to visible. | ||
| 69 | /// | ||
| 70 | /// @param[in] visible If true visible, otherwise hidden | ||
| 71 | /// | ||
| 72 | void SetVisible(bool visible) | ||
| 73 | { | ||
| 74 | m_interface->kodi_gui->control_image->set_visible(m_interface->kodiBase, m_controlHandle, | ||
| 75 | visible); | ||
| 76 | } | ||
| 77 | //-------------------------------------------------------------------------- | ||
| 78 | |||
| 79 | //========================================================================== | ||
| 80 | /// @ingroup cpp_kodi_gui_windows_controls_CImage | ||
| 81 | /// @brief To set the filename used on image control. | ||
| 82 | /// | ||
| 83 | /// @param[in] filename Image file to use | ||
| 84 | /// @param[in] useCache To define storage of image, default is in cache, if | ||
| 85 | /// false becomes it loaded always on changes again | ||
| 86 | /// | ||
| 87 | void SetFileName(const std::string& filename, bool useCache = true) | ||
| 88 | { | ||
| 89 | m_interface->kodi_gui->control_image->set_filename(m_interface->kodiBase, m_controlHandle, | ||
| 90 | filename.c_str(), useCache); | ||
| 91 | } | ||
| 92 | //-------------------------------------------------------------------------- | ||
| 93 | |||
| 94 | //========================================================================== | ||
| 95 | /// @ingroup cpp_kodi_gui_windows_controls_CImage | ||
| 96 | /// @brief To set set the diffuse color on image. | ||
| 97 | /// | ||
| 98 | /// @param[in] colorDiffuse Color to use for diffuse | ||
| 99 | /// | ||
| 100 | void SetColorDiffuse(uint32_t colorDiffuse) | ||
| 101 | { | ||
| 102 | m_interface->kodi_gui->control_image->set_color_diffuse(m_interface->kodiBase, m_controlHandle, | ||
| 103 | colorDiffuse); | ||
| 104 | } | ||
| 105 | //-------------------------------------------------------------------------- | ||
| 106 | }; | ||
| 107 | |||
| 108 | } /* namespace controls */ | ||
| 109 | } /* namespace gui */ | ||
| 110 | } /* namespace kodi */ | ||
| 111 | |||
| 112 | #endif /* __cplusplus */ | ||
diff --git a/xbmc/addons/kodi-dev-kit/include/kodi/gui/controls/Label.h b/xbmc/addons/kodi-dev-kit/include/kodi/gui/controls/Label.h new file mode 100644 index 0000000..d10b85f --- /dev/null +++ b/xbmc/addons/kodi-dev-kit/include/kodi/gui/controls/Label.h | |||
| @@ -0,0 +1,118 @@ | |||
| 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/label.h" | ||
| 12 | #include "../Window.h" | ||
| 13 | |||
| 14 | #ifdef __cplusplus | ||
| 15 | |||
| 16 | namespace kodi | ||
| 17 | { | ||
| 18 | namespace gui | ||
| 19 | { | ||
| 20 | namespace controls | ||
| 21 | { | ||
| 22 | |||
| 23 | //============================================================================== | ||
| 24 | /// @defgroup cpp_kodi_gui_windows_controls_CLabel Control Label | ||
| 25 | /// @ingroup cpp_kodi_gui_windows_controls | ||
| 26 | /// @brief @cpp_class{ kodi::gui::controls::CLabel } | ||
| 27 | /// **Window control used to show some lines of text**\n | ||
| 28 | /// The label control is used for displaying text in Kodi. You can choose | ||
| 29 | /// the font, size, colour, location and contents of the text to be displayed. | ||
| 30 | /// | ||
| 31 | /// It has the header @ref Label.h "#include <kodi/gui/controls/Label.h>" | ||
| 32 | /// be included to enjoy it. | ||
| 33 | /// | ||
| 34 | /// Here you find the needed skin part for a @ref Label_Control "label control". | ||
| 35 | /// | ||
| 36 | /// @note The call of the control is only possible from the corresponding | ||
| 37 | /// window as its class and identification number is required. | ||
| 38 | /// | ||
| 39 | class ATTRIBUTE_HIDDEN CLabel : public CAddonGUIControlBase | ||
| 40 | { | ||
| 41 | public: | ||
| 42 | //============================================================================ | ||
| 43 | /// @ingroup cpp_kodi_gui_windows_controls_CLabel | ||
| 44 | /// @brief Construct a new control. | ||
| 45 | /// | ||
| 46 | /// @param[in] window Related window control class | ||
| 47 | /// @param[in] controlId Used skin xml control id | ||
| 48 | /// | ||
| 49 | CLabel(CWindow* window, int controlId) : CAddonGUIControlBase(window) | ||
| 50 | { | ||
| 51 | m_controlHandle = m_interface->kodi_gui->window->get_control_label( | ||
| 52 | m_interface->kodiBase, m_Window->GetControlHandle(), controlId); | ||
| 53 | if (!m_controlHandle) | ||
| 54 | kodi::Log(ADDON_LOG_FATAL, | ||
| 55 | "kodi::gui::controls::CLabel can't create control class from Kodi !!!"); | ||
| 56 | } | ||
| 57 | //---------------------------------------------------------------------------- | ||
| 58 | |||
| 59 | //============================================================================ | ||
| 60 | /// @ingroup cpp_kodi_gui_windows_controls_CLabel | ||
| 61 | /// @brief Destructor. | ||
| 62 | /// | ||
| 63 | ~CLabel() override = default; | ||
| 64 | //---------------------------------------------------------------------------- | ||
| 65 | |||
| 66 | //============================================================================ | ||
| 67 | /// @ingroup cpp_kodi_gui_windows_controls_CLabel | ||
| 68 | /// @brief Set the control on window to visible. | ||
| 69 | /// | ||
| 70 | /// @param[in] visible If true visible, otherwise hidden | ||
| 71 | /// | ||
| 72 | void SetVisible(bool visible) | ||
| 73 | { | ||
| 74 | m_interface->kodi_gui->control_label->set_visible(m_interface->kodiBase, m_controlHandle, | ||
| 75 | visible); | ||
| 76 | } | ||
| 77 | //---------------------------------------------------------------------------- | ||
| 78 | |||
| 79 | //============================================================================ | ||
| 80 | /// @ingroup cpp_kodi_gui_windows_controls_CLabel | ||
| 81 | /// @brief To set the text string on label. | ||
| 82 | /// | ||
| 83 | /// @param[in] text Text to show | ||
| 84 | /// | ||
| 85 | void SetLabel(const std::string& text) | ||
| 86 | { | ||
| 87 | m_interface->kodi_gui->control_label->set_label(m_interface->kodiBase, m_controlHandle, | ||
| 88 | text.c_str()); | ||
| 89 | } | ||
| 90 | //---------------------------------------------------------------------------- | ||
| 91 | |||
| 92 | //============================================================================ | ||
| 93 | /// @ingroup cpp_kodi_gui_windows_controls_CLabel | ||
| 94 | /// @brief Get the used text from control. | ||
| 95 | /// | ||
| 96 | /// @return Used text on label control | ||
| 97 | /// | ||
| 98 | std::string GetLabel() const | ||
| 99 | { | ||
| 100 | std::string label; | ||
| 101 | char* ret = | ||
| 102 | m_interface->kodi_gui->control_label->get_label(m_interface->kodiBase, m_controlHandle); | ||
| 103 | if (ret != nullptr) | ||
| 104 | { | ||
| 105 | if (std::strlen(ret)) | ||
| 106 | label = ret; | ||
| 107 | m_interface->free_string(m_interface->kodiBase, ret); | ||
| 108 | } | ||
| 109 | return label; | ||
| 110 | } | ||
| 111 | //---------------------------------------------------------------------------- | ||
| 112 | }; | ||
| 113 | |||
| 114 | } /* namespace controls */ | ||
| 115 | } /* namespace gui */ | ||
| 116 | } /* namespace kodi */ | ||
| 117 | |||
| 118 | #endif /* __cplusplus */ | ||
diff --git a/xbmc/addons/kodi-dev-kit/include/kodi/gui/controls/Progress.h b/xbmc/addons/kodi-dev-kit/include/kodi/gui/controls/Progress.h new file mode 100644 index 0000000..83b16aa --- /dev/null +++ b/xbmc/addons/kodi-dev-kit/include/kodi/gui/controls/Progress.h | |||
| @@ -0,0 +1,112 @@ | |||
| 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/progress.h" | ||
| 12 | #include "../Window.h" | ||
| 13 | |||
| 14 | #ifdef __cplusplus | ||
| 15 | |||
| 16 | namespace kodi | ||
| 17 | { | ||
| 18 | namespace gui | ||
| 19 | { | ||
| 20 | namespace controls | ||
| 21 | { | ||
| 22 | |||
| 23 | //============================================================================== | ||
| 24 | /// @defgroup cpp_kodi_gui_windows_controls_CProgress Control Progress | ||
| 25 | /// @ingroup cpp_kodi_gui_windows_controls | ||
| 26 | /// @brief @cpp_class{ kodi::gui::controls::CProgress } | ||
| 27 | /// **Window control to show the progress of a particular operation**\n | ||
| 28 | /// The progress control is used to show the progress of an item that may take | ||
| 29 | /// a long time, or to show how far through a movie you are. | ||
| 30 | /// | ||
| 31 | /// You can choose the position, size, and look of the progress control. | ||
| 32 | /// | ||
| 33 | /// It has the header @ref Progress.h "#include <kodi/gui/controls/Progress.h>" | ||
| 34 | /// be included to enjoy it. | ||
| 35 | /// | ||
| 36 | /// Here you find the needed skin part for a @ref Progress_Control "progress control". | ||
| 37 | /// | ||
| 38 | /// @note The call of the control is only possible from the corresponding | ||
| 39 | /// window as its class and identification number is required. | ||
| 40 | /// | ||
| 41 | class ATTRIBUTE_HIDDEN CProgress : public CAddonGUIControlBase | ||
| 42 | { | ||
| 43 | public: | ||
| 44 | //============================================================================ | ||
| 45 | /// @ingroup cpp_kodi_gui_windows_controls_CProgress | ||
| 46 | /// @brief Construct a new control. | ||
| 47 | /// | ||
| 48 | /// @param[in] window Related window control class | ||
| 49 | /// @param[in] controlId Used skin xml control id | ||
| 50 | /// | ||
| 51 | CProgress(CWindow* window, int controlId) : CAddonGUIControlBase(window) | ||
| 52 | { | ||
| 53 | m_controlHandle = m_interface->kodi_gui->window->get_control_progress( | ||
| 54 | m_interface->kodiBase, m_Window->GetControlHandle(), controlId); | ||
| 55 | if (!m_controlHandle) | ||
| 56 | kodi::Log(ADDON_LOG_FATAL, | ||
| 57 | "kodi::gui::controls::CProgress can't create control class from Kodi !!!"); | ||
| 58 | } | ||
| 59 | //---------------------------------------------------------------------------- | ||
| 60 | |||
| 61 | //============================================================================ | ||
| 62 | /// @ingroup cpp_kodi_gui_windows_controls_CProgress | ||
| 63 | /// @brief Destructor. | ||
| 64 | /// | ||
| 65 | ~CProgress() override = default; | ||
| 66 | //---------------------------------------------------------------------------- | ||
| 67 | |||
| 68 | //============================================================================ | ||
| 69 | /// @ingroup cpp_kodi_gui_windows_controls_CProgress | ||
| 70 | /// @brief Set the control on window to visible. | ||
| 71 | /// | ||
| 72 | /// @param[in] visible If true visible, otherwise hidden | ||
| 73 | /// | ||
| 74 | void SetVisible(bool visible) | ||
| 75 | { | ||
| 76 | m_interface->kodi_gui->control_progress->set_visible(m_interface->kodiBase, m_controlHandle, | ||
| 77 | visible); | ||
| 78 | } | ||
| 79 | //---------------------------------------------------------------------------- | ||
| 80 | |||
| 81 | //============================================================================ | ||
| 82 | /// @ingroup cpp_kodi_gui_windows_controls_CProgress | ||
| 83 | /// @brief To set Percent position of control. | ||
| 84 | /// | ||
| 85 | /// @param[in] percent The percent position to use | ||
| 86 | /// | ||
| 87 | void SetPercentage(float percent) | ||
| 88 | { | ||
| 89 | m_interface->kodi_gui->control_progress->set_percentage(m_interface->kodiBase, m_controlHandle, | ||
| 90 | percent); | ||
| 91 | } | ||
| 92 | //---------------------------------------------------------------------------- | ||
| 93 | |||
| 94 | //============================================================================ | ||
| 95 | /// @ingroup cpp_kodi_gui_windows_controls_CProgress | ||
| 96 | /// @brief Get the active percent position of progress bar. | ||
| 97 | /// | ||
| 98 | /// @return Progress position as percent | ||
| 99 | /// | ||
| 100 | float GetPercentage() const | ||
| 101 | { | ||
| 102 | return m_interface->kodi_gui->control_progress->get_percentage(m_interface->kodiBase, | ||
| 103 | m_controlHandle); | ||
| 104 | } | ||
| 105 | //---------------------------------------------------------------------------- | ||
| 106 | }; | ||
| 107 | |||
| 108 | } /* namespace controls */ | ||
| 109 | } /* namespace gui */ | ||
| 110 | } /* namespace kodi */ | ||
| 111 | |||
| 112 | #endif /* __cplusplus */ | ||
diff --git a/xbmc/addons/kodi-dev-kit/include/kodi/gui/controls/RadioButton.h b/xbmc/addons/kodi-dev-kit/include/kodi/gui/controls/RadioButton.h new file mode 100644 index 0000000..3b6a23c --- /dev/null +++ b/xbmc/addons/kodi-dev-kit/include/kodi/gui/controls/RadioButton.h | |||
| @@ -0,0 +1,214 @@ | |||
| 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/radio_button.h" | ||
| 12 | #include "../Window.h" | ||
| 13 | |||
| 14 | #ifdef __cplusplus | ||
| 15 | |||
| 16 | namespace kodi | ||
| 17 | { | ||
| 18 | namespace gui | ||
| 19 | { | ||
| 20 | namespace controls | ||
| 21 | { | ||
| 22 | |||
| 23 | //============================================================================== | ||
| 24 | /// @defgroup cpp_kodi_gui_windows_controls_CRadioButton Control Radio Button | ||
| 25 | /// @ingroup cpp_kodi_gui_windows_controls | ||
| 26 | /// @brief @cpp_class{ kodi::gui::controls::CRadioButton } | ||
| 27 | /// **Window control for a radio button (as used for on/off settings)**\n | ||
| 28 | /// The radio button control is used for creating push button on/off settings | ||
| 29 | /// in Kodi. | ||
| 30 | /// | ||
| 31 | /// You can choose the position, size, and look of the button. When the user | ||
| 32 | /// clicks on the radio button, the state will change, toggling the extra | ||
| 33 | /// textures (textureradioon and textureradiooff). Used for settings | ||
| 34 | /// controls. | ||
| 35 | /// | ||
| 36 | /// It has the header @ref RadioButton.h "#include <kodi/gui/controls/RadioButton.h>" | ||
| 37 | /// be included to enjoy it. | ||
| 38 | /// | ||
| 39 | /// Here you find the needed skin part for a @ref Radio_button_control "radio button control". | ||
| 40 | /// | ||
| 41 | /// @note The call of the control is only possible from the corresponding | ||
| 42 | /// window as its class and identification number is required. | ||
| 43 | /// | ||
| 44 | /// | ||
| 45 | /// -------------------------------------------------------------------------- | ||
| 46 | /// **Example:** | ||
| 47 | /// ~~~~~~~~~~~~cpp | ||
| 48 | /// #include <kodi/gui/Window.h> | ||
| 49 | /// | ||
| 50 | /// #define MY_RADIO_BUTTON_CONTROL 1 | ||
| 51 | /// | ||
| 52 | /// class CMyWindow : public kodi::gui::CWindow | ||
| 53 | /// { | ||
| 54 | /// public: | ||
| 55 | /// CMyWindow() | ||
| 56 | /// | ||
| 57 | /// void ShowWindow(); | ||
| 58 | /// | ||
| 59 | /// bool OnInit() override; | ||
| 60 | /// bool OnClick(int controlId) override; | ||
| 61 | /// | ||
| 62 | /// private: | ||
| 63 | /// kodi::gui::controls::CSpin m_myRadioButtonControl; | ||
| 64 | /// }; | ||
| 65 | /// | ||
| 66 | /// CMyWindow::CMyWindow() | ||
| 67 | /// : kodi::gui::CWindow("my_skin.xml", "skin.estuary", true, false), | ||
| 68 | /// m_myRadioButtonControl(this, MY_RADIO_BUTTON_CONTROL) | ||
| 69 | /// { | ||
| 70 | /// } | ||
| 71 | /// | ||
| 72 | /// void CMyWindow::ShowWindow() | ||
| 73 | /// { | ||
| 74 | /// kodi::gui::CWindow::DoModal(); | ||
| 75 | /// } | ||
| 76 | /// | ||
| 77 | /// bool CMyWindow::OnInit() | ||
| 78 | /// { | ||
| 79 | /// m_myRadioButtonControl.SetSelected(false); // can also on skin set to default | ||
| 80 | /// return true; | ||
| 81 | /// } | ||
| 82 | /// | ||
| 83 | /// bool CMyWindow::OnClick(int controlId) | ||
| 84 | /// { | ||
| 85 | /// if (controlId == MY_RADIO_BUTTON_CONTROL) | ||
| 86 | /// { | ||
| 87 | /// bool selected = m_myRadioButtonControl.IsSelected(); | ||
| 88 | /// ... | ||
| 89 | /// } | ||
| 90 | /// return true; | ||
| 91 | /// } | ||
| 92 | /// return false; | ||
| 93 | /// } | ||
| 94 | /// ~~~~~~~~~~~~ | ||
| 95 | /// | ||
| 96 | class ATTRIBUTE_HIDDEN CRadioButton : public CAddonGUIControlBase | ||
| 97 | { | ||
| 98 | public: | ||
| 99 | //============================================================================ | ||
| 100 | /// @ingroup cpp_kodi_gui_windows_controls_CRadioButton | ||
| 101 | /// @brief Construct a new control. | ||
| 102 | /// | ||
| 103 | /// @param[in] window Related window control class | ||
| 104 | /// @param[in] controlId Used skin xml control id | ||
| 105 | /// | ||
| 106 | CRadioButton(CWindow* window, int controlId) : CAddonGUIControlBase(window) | ||
| 107 | { | ||
| 108 | m_controlHandle = m_interface->kodi_gui->window->get_control_radio_button( | ||
| 109 | m_interface->kodiBase, m_Window->GetControlHandle(), controlId); | ||
| 110 | if (!m_controlHandle) | ||
| 111 | kodi::Log(ADDON_LOG_FATAL, | ||
| 112 | "kodi::gui::controls::CRadioButton can't create control class from Kodi !!!"); | ||
| 113 | } | ||
| 114 | //---------------------------------------------------------------------------- | ||
| 115 | |||
| 116 | //============================================================================ | ||
| 117 | /// @ingroup cpp_kodi_gui_windows_controls_CRadioButton | ||
| 118 | /// @brief Destructor. | ||
| 119 | /// | ||
| 120 | ~CRadioButton() override = default; | ||
| 121 | //---------------------------------------------------------------------------- | ||
| 122 | |||
| 123 | //============================================================================ | ||
| 124 | /// @ingroup cpp_kodi_gui_windows_controls_CRadioButton. | ||
| 125 | /// @brief Set the control on window to visible. | ||
| 126 | /// | ||
| 127 | /// @param[in] visible If true visible, otherwise hidden | ||
| 128 | /// | ||
| 129 | void SetVisible(bool visible) | ||
| 130 | { | ||
| 131 | m_interface->kodi_gui->control_radio_button->set_visible(m_interface->kodiBase, m_controlHandle, | ||
| 132 | visible); | ||
| 133 | } | ||
| 134 | //---------------------------------------------------------------------------- | ||
| 135 | |||
| 136 | //============================================================================ | ||
| 137 | /// @ingroup cpp_kodi_gui_windows_controls_CRadioButton | ||
| 138 | /// @brief Set's the control's enabled/disabled state. | ||
| 139 | /// | ||
| 140 | /// @param[in] enabled If true enabled, otherwise disabled | ||
| 141 | /// | ||
| 142 | void SetEnabled(bool enabled) | ||
| 143 | { | ||
| 144 | m_interface->kodi_gui->control_radio_button->set_enabled(m_interface->kodiBase, m_controlHandle, | ||
| 145 | enabled); | ||
| 146 | } | ||
| 147 | //---------------------------------------------------------------------------- | ||
| 148 | |||
| 149 | //============================================================================ | ||
| 150 | /// @ingroup cpp_kodi_gui_windows_controls_CRadioButton | ||
| 151 | /// @brief To set the text string on radio button. | ||
| 152 | /// | ||
| 153 | /// @param[in] label Text to show | ||
| 154 | /// | ||
| 155 | void SetLabel(const std::string& label) | ||
| 156 | { | ||
| 157 | m_interface->kodi_gui->control_radio_button->set_label(m_interface->kodiBase, m_controlHandle, | ||
| 158 | label.c_str()); | ||
| 159 | } | ||
| 160 | //---------------------------------------------------------------------------- | ||
| 161 | |||
| 162 | //============================================================================ | ||
| 163 | /// @ingroup cpp_kodi_gui_windows_controls_CRadioButton | ||
| 164 | /// @brief Get the used text from control. | ||
| 165 | /// | ||
| 166 | /// @return Text shown | ||
| 167 | /// | ||
| 168 | std::string GetLabel() const | ||
| 169 | { | ||
| 170 | std::string label; | ||
| 171 | char* ret = m_interface->kodi_gui->control_radio_button->get_label(m_interface->kodiBase, | ||
| 172 | m_controlHandle); | ||
| 173 | if (ret != nullptr) | ||
| 174 | { | ||
| 175 | if (std::strlen(ret)) | ||
| 176 | label = ret; | ||
| 177 | m_interface->free_string(m_interface->kodiBase, ret); | ||
| 178 | } | ||
| 179 | return label; | ||
| 180 | } | ||
| 181 | //---------------------------------------------------------------------------- | ||
| 182 | |||
| 183 | //============================================================================ | ||
| 184 | /// @ingroup cpp_kodi_gui_windows_controls_CRadioButton | ||
| 185 | /// @brief To set radio button condition to on or off. | ||
| 186 | /// | ||
| 187 | /// @param[in] selected true set radio button to selection on, otherwise off | ||
| 188 | /// | ||
| 189 | void SetSelected(bool selected) | ||
| 190 | { | ||
| 191 | m_interface->kodi_gui->control_radio_button->set_selected(m_interface->kodiBase, | ||
| 192 | m_controlHandle, selected); | ||
| 193 | } | ||
| 194 | //---------------------------------------------------------------------------- | ||
| 195 | |||
| 196 | //============================================================================ | ||
| 197 | /// @ingroup cpp_kodi_gui_windows_controls_CRadioButton | ||
| 198 | /// @brief Get the current selected condition of radio button. | ||
| 199 | /// | ||
| 200 | /// @return Selected condition | ||
| 201 | /// | ||
| 202 | bool IsSelected() const | ||
| 203 | { | ||
| 204 | return m_interface->kodi_gui->control_radio_button->is_selected(m_interface->kodiBase, | ||
| 205 | m_controlHandle); | ||
| 206 | } | ||
| 207 | //---------------------------------------------------------------------------- | ||
| 208 | }; | ||
| 209 | |||
| 210 | } /* namespace controls */ | ||
| 211 | } /* namespace gui */ | ||
| 212 | } /* namespace kodi */ | ||
| 213 | |||
| 214 | #endif /* __cplusplus */ | ||
diff --git a/xbmc/addons/kodi-dev-kit/include/kodi/gui/controls/Rendering.h b/xbmc/addons/kodi-dev-kit/include/kodi/gui/controls/Rendering.h new file mode 100644 index 0000000..7f5feef --- /dev/null +++ b/xbmc/addons/kodi-dev-kit/include/kodi/gui/controls/Rendering.h | |||
| @@ -0,0 +1,217 @@ | |||
| 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 | |||
| 17 | namespace kodi | ||
| 18 | { | ||
| 19 | namespace gui | ||
| 20 | { | ||
| 21 | namespace controls | ||
| 22 | { | ||
| 23 | |||
| 24 | //============================================================================ | ||
| 25 | /// @defgroup cpp_kodi_gui_windows_controls_CRendering Control Rendering | ||
| 26 | /// @ingroup cpp_kodi_gui_windows_controls | ||
| 27 | /// @brief @cpp_class{ kodi::gui::controls::CRendering } | ||
| 28 | /// **Window control for rendering own parts**\n | ||
| 29 | /// This rendering control is used when own parts are needed. | ||
| 30 | /// | ||
| 31 | /// You have the control over them to render direct OpenGL or DirectX content | ||
| 32 | /// to the screen set by the size of them. | ||
| 33 | /// | ||
| 34 | /// Alternative can be the virtual functions from t his been ignored if the | ||
| 35 | /// callbacks are defined by the @ref CRendering_SetIndependentCallbacks | ||
| 36 | /// function and class is used as single and not as a parent class. | ||
| 37 | /// | ||
| 38 | /// It has the header @ref Rendering.h "#include <kodi/gui/controls/Rendering.h>" | ||
| 39 | /// be included to enjoy it. | ||
| 40 | /// | ||
| 41 | /// Here you find the needed skin part for a @ref Addon_Rendering_control "rendering control". | ||
| 42 | /// | ||
| 43 | /// @note The call of the control is only possible from the corresponding | ||
| 44 | /// window as its class and identification number is required. | ||
| 45 | /// | ||
| 46 | class ATTRIBUTE_HIDDEN CRendering : public CAddonGUIControlBase | ||
| 47 | { | ||
| 48 | public: | ||
| 49 | //========================================================================== | ||
| 50 | /// @ingroup cpp_kodi_gui_windows_controls_CRendering | ||
| 51 | /// @brief Construct a new control. | ||
| 52 | /// | ||
| 53 | /// @param[in] window Related window control class | ||
| 54 | /// @param[in] controlId Used skin xml control id | ||
| 55 | /// | ||
| 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 | //========================================================================== | ||
| 71 | /// @ingroup cpp_kodi_gui_windows_controls_CRendering | ||
| 72 | /// @brief Destructor. | ||
| 73 | /// | ||
| 74 | ~CRendering() override | ||
| 75 | { | ||
| 76 | m_interface->kodi_gui->control_rendering->destroy(m_interface->kodiBase, m_controlHandle); | ||
| 77 | } | ||
| 78 | //-------------------------------------------------------------------------- | ||
| 79 | |||
| 80 | //========================================================================== | ||
| 81 | /// @ingroup cpp_kodi_gui_windows_controls_CRendering | ||
| 82 | /// @brief To create rendering control on Add-on. | ||
| 83 | /// | ||
| 84 | /// Function creates the needed rendering control for Kodi which becomes | ||
| 85 | /// handled and processed from Add-on | ||
| 86 | /// | ||
| 87 | /// @note This is callback function from Kodi to Add-on and not to use | ||
| 88 | /// for calls from add-on to this function. | ||
| 89 | /// | ||
| 90 | /// @param[in] x Horizontal position | ||
| 91 | /// @param[in] y Vertical position | ||
| 92 | /// @param[in] w Width of control | ||
| 93 | /// @param[in] h Height of control | ||
| 94 | /// @param[in] device The device to use. For OpenGL is empty on Direct X is | ||
| 95 | /// the needed device send. | ||
| 96 | /// @return Add-on needs to return true if successed, otherwise false. | ||
| 97 | /// | ||
| 98 | /// @note The @ref kodi::HardwareContext is basically a simple pointer which | ||
| 99 | /// has to be changed to the desired format at the corresponding places using | ||
| 100 | /// <b>`static_cast<...>(...)`</b>. | ||
| 101 | /// | ||
| 102 | virtual bool Create(int x, int y, int w, int h, kodi::HardwareContext device) { return false; } | ||
| 103 | //-------------------------------------------------------------------------- | ||
| 104 | |||
| 105 | //========================================================================== | ||
| 106 | /// @ingroup cpp_kodi_gui_windows_controls_CRendering | ||
| 107 | /// @brief Render process call from Kodi. | ||
| 108 | /// | ||
| 109 | /// @note This is callback function from Kodi to Add-on and not to use for | ||
| 110 | /// calls from add-on to this function. | ||
| 111 | /// | ||
| 112 | virtual void Render() {} | ||
| 113 | //-------------------------------------------------------------------------- | ||
| 114 | |||
| 115 | //========================================================================== | ||
| 116 | /// @ingroup cpp_kodi_gui_windows_controls_CRendering | ||
| 117 | /// @brief Call from Kodi to stop rendering process. | ||
| 118 | /// | ||
| 119 | /// @note This is callback function from Kodi to Add-on and not to use | ||
| 120 | /// for calls from add-on to this function. | ||
| 121 | /// | ||
| 122 | virtual void Stop() {} | ||
| 123 | //-------------------------------------------------------------------------- | ||
| 124 | |||
| 125 | //========================================================================== | ||
| 126 | /// @ingroup cpp_kodi_gui_windows_controls_CRendering | ||
| 127 | /// @brief Call from Kodi where add-on becomes asked about dirty rendering | ||
| 128 | /// region. | ||
| 129 | /// | ||
| 130 | /// @note This is callback function from Kodi to Add-on and not to use | ||
| 131 | /// for calls from add-on to this function. | ||
| 132 | /// | ||
| 133 | /// @return True if a render region is dirty and need rendering. | ||
| 134 | /// | ||
| 135 | virtual bool Dirty() { return false; } | ||
| 136 | //-------------------------------------------------------------------------- | ||
| 137 | |||
| 138 | //========================================================================== | ||
| 139 | /// @ingroup cpp_kodi_gui_windows_controls_CRendering | ||
| 140 | /// @anchor CRendering_SetIndependentCallbacks | ||
| 141 | /// @brief If the class is used independent (with "new CRendering") | ||
| 142 | /// and not as parent (with "cCLASS_own : CRendering") from own must | ||
| 143 | /// be the callback from Kodi to add-on overdriven with own functions! | ||
| 144 | /// | ||
| 145 | /// @param[in] cbhdl Addon related class point where becomes given as value on | ||
| 146 | /// related functions. | ||
| 147 | /// @param[in] CBCreate External creation function pointer, see also @ref Create | ||
| 148 | /// about related values | ||
| 149 | /// @param[in] CBRender External render function pointer, see also @ref Render | ||
| 150 | /// about related values | ||
| 151 | /// @param[in] CBStop External stop function pointer, see also @ref Stop | ||
| 152 | /// about related values | ||
| 153 | /// @param[in] CBDirty External dirty function pointer, see also @ref Dirty | ||
| 154 | /// about related values | ||
| 155 | /// | ||
| 156 | void SetIndependentCallbacks(kodi::gui::ClientHandle cbhdl, | ||
| 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 | |||
| 178 | private: | ||
| 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 */ | ||
diff --git a/xbmc/addons/kodi-dev-kit/include/kodi/gui/controls/SettingsSlider.h b/xbmc/addons/kodi-dev-kit/include/kodi/gui/controls/SettingsSlider.h new file mode 100644 index 0000000..5557fc4 --- /dev/null +++ b/xbmc/addons/kodi-dev-kit/include/kodi/gui/controls/SettingsSlider.h | |||
| @@ -0,0 +1,314 @@ | |||
| 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/settings_slider.h" | ||
| 12 | #include "../Window.h" | ||
| 13 | |||
| 14 | #ifdef __cplusplus | ||
| 15 | |||
| 16 | namespace kodi | ||
| 17 | { | ||
| 18 | namespace gui | ||
| 19 | { | ||
| 20 | namespace controls | ||
| 21 | { | ||
| 22 | |||
| 23 | //============================================================================== | ||
| 24 | /// @defgroup cpp_kodi_gui_windows_controls_CSettingsSlider Control Settings Slider | ||
| 25 | /// @ingroup cpp_kodi_gui_windows_controls | ||
| 26 | /// @brief @cpp_class{ kodi::gui::controls::CSettingsSlider } | ||
| 27 | /// **Window control for moveable slider with text name**\n | ||
| 28 | /// The settings slider control is used in the settings screens for when an | ||
| 29 | /// option is best specified on a sliding scale. | ||
| 30 | /// | ||
| 31 | /// You can choose the position, size, and look of the slider control. It is | ||
| 32 | /// basically a cross between the button control and a slider control. It has a | ||
| 33 | /// label and focus and non focus textures, as well as a slider control on the | ||
| 34 | /// right. | ||
| 35 | /// | ||
| 36 | /// It has the header @ref SettingsSlider.h "#include <kodi/gui/controls/SettingsSlider.h>" | ||
| 37 | /// be included to enjoy it. | ||
| 38 | /// | ||
| 39 | /// Here you find the needed skin part for a @ref Settings_Slider_Control "settings slider control". | ||
| 40 | /// | ||
| 41 | /// @note The call of the control is only possible from the corresponding | ||
| 42 | /// window as its class and identification number is required. | ||
| 43 | /// | ||
| 44 | class ATTRIBUTE_HIDDEN CSettingsSlider : public CAddonGUIControlBase | ||
| 45 | { | ||
| 46 | public: | ||
| 47 | //============================================================================ | ||
| 48 | /// @ingroup cpp_kodi_gui_windows_controls_CSettingsSlider | ||
| 49 | /// @brief Construct a new control. | ||
| 50 | /// | ||
| 51 | /// @param[in] window Related window control class | ||
| 52 | /// @param[in] controlId Used skin xml control id | ||
| 53 | /// | ||
| 54 | CSettingsSlider(CWindow* window, int controlId) : CAddonGUIControlBase(window) | ||
| 55 | { | ||
| 56 | m_controlHandle = m_interface->kodi_gui->window->get_control_settings_slider( | ||
| 57 | m_interface->kodiBase, m_Window->GetControlHandle(), controlId); | ||
| 58 | if (!m_controlHandle) | ||
| 59 | kodi::Log(ADDON_LOG_FATAL, | ||
| 60 | "kodi::gui::controls::CSettingsSlider can't create control class from Kodi !!!"); | ||
| 61 | } | ||
| 62 | //---------------------------------------------------------------------------- | ||
| 63 | |||
| 64 | //============================================================================ | ||
| 65 | /// @ingroup cpp_kodi_gui_windows_controls_CSettingsSlider | ||
| 66 | /// @brief Destructor. | ||
| 67 | /// | ||
| 68 | ~CSettingsSlider() override = default; | ||
| 69 | //---------------------------------------------------------------------------- | ||
| 70 | |||
| 71 | //============================================================================ | ||
| 72 | /// @ingroup cpp_kodi_gui_windows_controls_CSettingsSlider | ||
| 73 | /// @brief Set the control on window to visible. | ||
| 74 | /// | ||
| 75 | /// @param[in] visible If true visible, otherwise hidden | ||
| 76 | /// | ||
| 77 | void SetVisible(bool visible) | ||
| 78 | { | ||
| 79 | m_interface->kodi_gui->control_settings_slider->set_visible(m_interface->kodiBase, | ||
| 80 | m_controlHandle, visible); | ||
| 81 | } | ||
| 82 | //---------------------------------------------------------------------------- | ||
| 83 | |||
| 84 | //============================================================================ | ||
| 85 | /// @ingroup cpp_kodi_gui_windows_controls_CSettingsSlider | ||
| 86 | /// @brief Set's the control's enabled/disabled state. | ||
| 87 | /// | ||
| 88 | /// @param[in] enabled If true enabled, otherwise disabled | ||
| 89 | /// | ||
| 90 | void SetEnabled(bool enabled) | ||
| 91 | { | ||
| 92 | m_interface->kodi_gui->control_settings_slider->set_enabled(m_interface->kodiBase, | ||
| 93 | m_controlHandle, enabled); | ||
| 94 | } | ||
| 95 | //---------------------------------------------------------------------------- | ||
| 96 | |||
| 97 | //============================================================================ | ||
| 98 | /// @ingroup cpp_kodi_gui_windows_controls_CSettingsSlider | ||
| 99 | /// @brief To set the text string on settings slider. | ||
| 100 | /// | ||
| 101 | /// @param[in] text Text to show | ||
| 102 | /// | ||
| 103 | void SetText(const std::string& text) | ||
| 104 | { | ||
| 105 | m_interface->kodi_gui->control_settings_slider->set_text(m_interface->kodiBase, m_controlHandle, | ||
| 106 | text.c_str()); | ||
| 107 | } | ||
| 108 | //---------------------------------------------------------------------------- | ||
| 109 | |||
| 110 | //============================================================================ | ||
| 111 | /// @ingroup cpp_kodi_gui_windows_controls_CSettingsSlider | ||
| 112 | /// @brief To reset slider on defaults. | ||
| 113 | /// | ||
| 114 | void Reset() | ||
| 115 | { | ||
| 116 | m_interface->kodi_gui->control_settings_slider->reset(m_interface->kodiBase, m_controlHandle); | ||
| 117 | } | ||
| 118 | //---------------------------------------------------------------------------- | ||
| 119 | |||
| 120 | //============================================================================ | ||
| 121 | /// @ingroup cpp_kodi_gui_windows_controls_CSettingsSlider | ||
| 122 | /// @brief To set the the range as integer of slider, e.g. -10 is the slider | ||
| 123 | /// start and e.g. +10 is the from here defined position where it reach the | ||
| 124 | /// end. | ||
| 125 | /// | ||
| 126 | /// Ad default is the range from 0 to 100. | ||
| 127 | /// | ||
| 128 | /// The integer interval is as default 1 and can be changed with | ||
| 129 | /// @ref SetIntInterval. | ||
| 130 | /// | ||
| 131 | /// @param[in] start Integer start value | ||
| 132 | /// @param[in] end Integer end value | ||
| 133 | /// | ||
| 134 | /// @note Percent, floating point or integer are alone possible. Combining | ||
| 135 | /// these different values can be not together and can, therefore, only | ||
| 136 | /// one each can be used. | ||
| 137 | /// | ||
| 138 | void SetIntRange(int start, int end) | ||
| 139 | { | ||
| 140 | m_interface->kodi_gui->control_settings_slider->set_int_range(m_interface->kodiBase, | ||
| 141 | m_controlHandle, start, end); | ||
| 142 | } | ||
| 143 | //---------------------------------------------------------------------------- | ||
| 144 | |||
| 145 | //============================================================================ | ||
| 146 | /// @ingroup cpp_kodi_gui_windows_controls_CSettingsSlider | ||
| 147 | /// @brief Set the slider position with the given integer value. The Range | ||
| 148 | /// must be defined with a call from @ref SetIntRange before. | ||
| 149 | /// | ||
| 150 | /// @param[in] value Position in range to set with integer | ||
| 151 | /// | ||
| 152 | /// @note Percent, floating point or integer are alone possible. Combining | ||
| 153 | /// these different values can be not together and can, therefore, only | ||
| 154 | /// one each can be used. | ||
| 155 | /// | ||
| 156 | void SetIntValue(int value) | ||
| 157 | { | ||
| 158 | m_interface->kodi_gui->control_settings_slider->set_int_value(m_interface->kodiBase, | ||
| 159 | m_controlHandle, value); | ||
| 160 | } | ||
| 161 | //---------------------------------------------------------------------------- | ||
| 162 | |||
| 163 | //============================================================================ | ||
| 164 | /// @ingroup cpp_kodi_gui_windows_controls_CSettingsSlider | ||
| 165 | /// @brief To get the current position as integer value. | ||
| 166 | /// | ||
| 167 | /// @return The position as integer | ||
| 168 | /// | ||
| 169 | /// @note Percent, floating point or integer are alone possible. Combining | ||
| 170 | /// these different values can be not together and can, therefore, only | ||
| 171 | /// one each can be used. | ||
| 172 | /// | ||
| 173 | int GetIntValue() const | ||
| 174 | { | ||
| 175 | return m_interface->kodi_gui->control_settings_slider->get_int_value(m_interface->kodiBase, | ||
| 176 | m_controlHandle); | ||
| 177 | } | ||
| 178 | //---------------------------------------------------------------------------- | ||
| 179 | |||
| 180 | //============================================================================ | ||
| 181 | /// @ingroup cpp_kodi_gui_windows_controls_CSettingsSlider | ||
| 182 | /// @brief To set the interval steps of slider, as default is it 1. If it | ||
| 183 | /// becomes changed with this function will a step of the user with the | ||
| 184 | /// value fixed here be executed. | ||
| 185 | /// | ||
| 186 | /// @param[in] interval Intervall step to set. | ||
| 187 | /// | ||
| 188 | /// @note Percent, floating point or integer are alone possible. Combining | ||
| 189 | /// these different values can be not together and can, therefore, only | ||
| 190 | /// one each can be used. | ||
| 191 | /// | ||
| 192 | void SetIntInterval(int interval) | ||
| 193 | { | ||
| 194 | m_interface->kodi_gui->control_settings_slider->set_int_interval(m_interface->kodiBase, | ||
| 195 | m_controlHandle, interval); | ||
| 196 | } | ||
| 197 | //---------------------------------------------------------------------------- | ||
| 198 | |||
| 199 | //============================================================================ | ||
| 200 | /// @ingroup cpp_kodi_gui_windows_controls_CSettingsSlider | ||
| 201 | /// @brief Sets the percent of the slider. | ||
| 202 | /// | ||
| 203 | /// @param[in] percent float - Percent value of slide | ||
| 204 | /// | ||
| 205 | /// @note Percent, floating point or integer are alone possible. Combining | ||
| 206 | /// these different values can be not together and can, therefore, only | ||
| 207 | /// one each can be used. | ||
| 208 | /// | ||
| 209 | void SetPercentage(float percent) | ||
| 210 | { | ||
| 211 | m_interface->kodi_gui->control_settings_slider->set_percentage(m_interface->kodiBase, | ||
| 212 | m_controlHandle, percent); | ||
| 213 | } | ||
| 214 | //---------------------------------------------------------------------------- | ||
| 215 | |||
| 216 | //============================================================================ | ||
| 217 | /// @ingroup cpp_kodi_gui_windows_controls_CSettingsSlider | ||
| 218 | /// @brief Returns a float of the percent of the slider. | ||
| 219 | /// | ||
| 220 | /// @return float - Percent of slider | ||
| 221 | /// | ||
| 222 | /// @note Percent, floating point or integer are alone possible. Combining | ||
| 223 | /// these different values can be not together and can, therefore, only | ||
| 224 | /// one each can be used. | ||
| 225 | /// | ||
| 226 | float GetPercentage() const | ||
| 227 | { | ||
| 228 | return m_interface->kodi_gui->control_settings_slider->get_percentage(m_interface->kodiBase, | ||
| 229 | m_controlHandle); | ||
| 230 | } | ||
| 231 | //---------------------------------------------------------------------------- | ||
| 232 | |||
| 233 | //============================================================================ | ||
| 234 | /// @ingroup cpp_kodi_gui_windows_controls_CSettingsSlider | ||
| 235 | /// @brief To set the the range as float of slider, e.g. -25.0 is the slider | ||
| 236 | /// start and e.g. +25.0 is the from here defined position where it reach | ||
| 237 | /// the end. | ||
| 238 | /// | ||
| 239 | /// As default is the range 0.0 to 1.0. | ||
| 240 | /// | ||
| 241 | /// The float interval is as default 0.1 and can be changed with | ||
| 242 | /// @ref SetFloatInterval. | ||
| 243 | /// | ||
| 244 | /// @param[in] start Integer start value | ||
| 245 | /// @param[in] end Integer end value | ||
| 246 | /// | ||
| 247 | /// @note Percent, floating point or integer are alone possible. Combining | ||
| 248 | /// these different values can be not together and can, therefore, only | ||
| 249 | /// one each can be used. | ||
| 250 | /// | ||
| 251 | void SetFloatRange(float start, float end) | ||
| 252 | { | ||
| 253 | m_interface->kodi_gui->control_settings_slider->set_float_range(m_interface->kodiBase, | ||
| 254 | m_controlHandle, start, end); | ||
| 255 | } | ||
| 256 | //---------------------------------------------------------------------------- | ||
| 257 | |||
| 258 | //============================================================================ | ||
| 259 | /// @ingroup cpp_kodi_gui_windows_controls_CSettingsSlider | ||
| 260 | /// @brief Set the slider position with the given float value. The Range can | ||
| 261 | /// be defined with a call from @ref SetIntRange before, as default it | ||
| 262 | /// is 0.0 to 1.0. | ||
| 263 | /// | ||
| 264 | /// @param[in] value Position in range to set with float | ||
| 265 | /// | ||
| 266 | /// @note Percent, floating point or integer are alone possible. Combining | ||
| 267 | /// these different values can be not together and can, therefore, only | ||
| 268 | /// one each can be used. | ||
| 269 | /// | ||
| 270 | void SetFloatValue(float value) | ||
| 271 | { | ||
| 272 | m_interface->kodi_gui->control_settings_slider->set_float_value(m_interface->kodiBase, | ||
| 273 | m_controlHandle, value); | ||
| 274 | } | ||
| 275 | //---------------------------------------------------------------------------- | ||
| 276 | |||
| 277 | //============================================================================ | ||
| 278 | /// @ingroup cpp_kodi_gui_windows_controls_CSettingsSlider | ||
| 279 | /// @brief To get the current position as float value. | ||
| 280 | /// | ||
| 281 | /// @return The position as float | ||
| 282 | /// | ||
| 283 | float GetFloatValue() const | ||
| 284 | { | ||
| 285 | return m_interface->kodi_gui->control_settings_slider->get_float_value(m_interface->kodiBase, | ||
| 286 | m_controlHandle); | ||
| 287 | } | ||
| 288 | //---------------------------------------------------------------------------- | ||
| 289 | |||
| 290 | //============================================================================ | ||
| 291 | /// @ingroup cpp_kodi_gui_windows_controls_CSettingsSlider | ||
| 292 | /// @brief To set the interval steps of slider, as default is it 0.1 If it | ||
| 293 | /// becomes changed with this function will a step of the user with the | ||
| 294 | /// value fixed here be executed. | ||
| 295 | /// | ||
| 296 | /// @param[in] interval Intervall step to set. | ||
| 297 | /// | ||
| 298 | /// @note Percent, floating point or integer are alone possible. Combining | ||
| 299 | /// these different values can be not together and can, therefore, only | ||
| 300 | /// one each can be used. | ||
| 301 | /// | ||
| 302 | void SetFloatInterval(float interval) | ||
| 303 | { | ||
| 304 | m_interface->kodi_gui->control_settings_slider->set_float_interval(m_interface->kodiBase, | ||
| 305 | m_controlHandle, interval); | ||
| 306 | } | ||
| 307 | //---------------------------------------------------------------------------- | ||
| 308 | }; | ||
| 309 | |||
| 310 | } /* namespace controls */ | ||
| 311 | } /* namespace gui */ | ||
| 312 | } /* namespace kodi */ | ||
| 313 | |||
| 314 | #endif /* __cplusplus */ | ||
diff --git a/xbmc/addons/kodi-dev-kit/include/kodi/gui/controls/Slider.h b/xbmc/addons/kodi-dev-kit/include/kodi/gui/controls/Slider.h new file mode 100644 index 0000000..077def8 --- /dev/null +++ b/xbmc/addons/kodi-dev-kit/include/kodi/gui/controls/Slider.h | |||
| @@ -0,0 +1,326 @@ | |||
| 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/slider.h" | ||
| 12 | #include "../Window.h" | ||
| 13 | |||
| 14 | #ifdef __cplusplus | ||
| 15 | |||
| 16 | namespace kodi | ||
| 17 | { | ||
| 18 | namespace gui | ||
| 19 | { | ||
| 20 | namespace controls | ||
| 21 | { | ||
| 22 | |||
| 23 | //============================================================================== | ||
| 24 | /// @defgroup cpp_kodi_gui_windows_controls_CSlider Control Slider | ||
| 25 | /// @ingroup cpp_kodi_gui_windows_controls | ||
| 26 | /// @brief @cpp_class{ kodi::gui::controls::CSlider } | ||
| 27 | /// **Window control for moveable slider**\n | ||
| 28 | /// The slider control is used for things where a sliding bar best represents | ||
| 29 | /// the operation at hand (such as a volume control or seek control). | ||
| 30 | /// | ||
| 31 | /// You can choose the position, size, and look of the slider control. | ||
| 32 | /// | ||
| 33 | /// It has the header @ref Slider.h "#include <kodi/gui/controls/Slider.h>" | ||
| 34 | /// be included to enjoy it. | ||
| 35 | /// | ||
| 36 | /// Here you find the needed skin part for a @ref Slider_Control "slider control". | ||
| 37 | /// | ||
| 38 | /// @note The call of the control is only possible from the corresponding | ||
| 39 | /// window as its class and identification number is required. | ||
| 40 | /// | ||
| 41 | class ATTRIBUTE_HIDDEN CSlider : public CAddonGUIControlBase | ||
| 42 | { | ||
| 43 | public: | ||
| 44 | //============================================================================ | ||
| 45 | /// @ingroup cpp_kodi_gui_windows_controls_CSlider | ||
| 46 | /// @brief Construct a new control. | ||
| 47 | /// | ||
| 48 | /// @param[in] window Related window control class | ||
| 49 | /// @param[in] controlId Used skin xml control id | ||
| 50 | /// | ||
| 51 | CSlider(CWindow* window, int controlId) : CAddonGUIControlBase(window) | ||
| 52 | { | ||
| 53 | m_controlHandle = m_interface->kodi_gui->window->get_control_slider( | ||
| 54 | m_interface->kodiBase, m_Window->GetControlHandle(), controlId); | ||
| 55 | if (!m_controlHandle) | ||
| 56 | kodi::Log(ADDON_LOG_FATAL, | ||
| 57 | "kodi::gui::controls::CSlider can't create control class from Kodi !!!"); | ||
| 58 | } | ||
| 59 | //---------------------------------------------------------------------------- | ||
| 60 | |||
| 61 | //============================================================================ | ||
| 62 | /// @ingroup cpp_kodi_gui_windows_controls_CSlider | ||
| 63 | /// @brief Destructor. | ||
| 64 | /// | ||
| 65 | ~CSlider() override = default; | ||
| 66 | //---------------------------------------------------------------------------- | ||
| 67 | |||
| 68 | //============================================================================ | ||
| 69 | /// @ingroup cpp_kodi_gui_windows_controls_CSlider | ||
| 70 | /// @brief Set the control on window to visible. | ||
| 71 | /// | ||
| 72 | /// @param[in] visible If true visible, otherwise hidden | ||
| 73 | /// | ||
| 74 | void SetVisible(bool visible) | ||
| 75 | { | ||
| 76 | m_interface->kodi_gui->control_slider->set_visible(m_interface->kodiBase, m_controlHandle, | ||
| 77 | visible); | ||
| 78 | } | ||
| 79 | //---------------------------------------------------------------------------- | ||
| 80 | |||
| 81 | //============================================================================ | ||
| 82 | /// @ingroup cpp_kodi_gui_windows_controls_CSlider | ||
| 83 | /// @brief Set's the control's enabled/disabled state. | ||
| 84 | /// | ||
| 85 | /// @param[in] enabled If true enabled, otherwise disabled | ||
| 86 | /// | ||
| 87 | void SetEnabled(bool enabled) | ||
| 88 | { | ||
| 89 | m_interface->kodi_gui->control_slider->set_enabled(m_interface->kodiBase, m_controlHandle, | ||
| 90 | enabled); | ||
| 91 | } | ||
| 92 | //---------------------------------------------------------------------------- | ||
| 93 | |||
| 94 | //============================================================================ | ||
| 95 | /// @ingroup cpp_kodi_gui_windows_controls_CSlider | ||
| 96 | /// @brief To reset slider on defaults. | ||
| 97 | /// | ||
| 98 | void Reset() | ||
| 99 | { | ||
| 100 | m_interface->kodi_gui->control_slider->reset(m_interface->kodiBase, m_controlHandle); | ||
| 101 | } | ||
| 102 | //---------------------------------------------------------------------------- | ||
| 103 | |||
| 104 | //============================================================================ | ||
| 105 | /// @ingroup cpp_kodi_gui_windows_controls_CSlider | ||
| 106 | /// @brief With GetDescription becomes a string value of position returned. | ||
| 107 | /// | ||
| 108 | /// @return Text string about current slider position | ||
| 109 | /// | ||
| 110 | /// The following are the text definition returned from this: | ||
| 111 | /// | Value | Without range selection | With range selection | | ||
| 112 | /// |:---------:|:------------------------|:-------------------------------| | ||
| 113 | /// | float | <c>%2.2f</c> | <c>[%2.2f, %2.2f]</c> | | ||
| 114 | /// | integer | <c>%i</c> | <c>[%i, %i]</c> | | ||
| 115 | /// | percent | <c>%i%%</c> | <c>[%i%%, %i%%]</c> | | ||
| 116 | /// | ||
| 117 | std::string GetDescription() const | ||
| 118 | { | ||
| 119 | std::string text; | ||
| 120 | char* ret = m_interface->kodi_gui->control_slider->get_description(m_interface->kodiBase, | ||
| 121 | m_controlHandle); | ||
| 122 | if (ret != nullptr) | ||
| 123 | { | ||
| 124 | if (std::strlen(ret)) | ||
| 125 | text = ret; | ||
| 126 | m_interface->free_string(m_interface->kodiBase, ret); | ||
| 127 | } | ||
| 128 | return text; | ||
| 129 | } | ||
| 130 | //---------------------------------------------------------------------------- | ||
| 131 | |||
| 132 | //============================================================================ | ||
| 133 | /// @ingroup cpp_kodi_gui_windows_controls_CSlider | ||
| 134 | /// @brief To set the the range as integer of slider, e.g. -10 is the slider | ||
| 135 | /// start and e.g. +10 is the from here defined position where it reach the | ||
| 136 | /// end. | ||
| 137 | /// | ||
| 138 | /// Ad default is the range from 0 to 100. | ||
| 139 | /// | ||
| 140 | /// The integer interval is as default 1 and can be changed with | ||
| 141 | /// @ref SetIntInterval. | ||
| 142 | /// | ||
| 143 | /// @param[in] start Integer start value | ||
| 144 | /// @param[in] end Integer end value | ||
| 145 | /// | ||
| 146 | /// @note Percent, floating point or integer are alone possible. Combining | ||
| 147 | /// these different values can be not together and can, therefore, only one | ||
| 148 | /// each can be used. | ||
| 149 | /// | ||
| 150 | void SetIntRange(int start, int end) | ||
| 151 | { | ||
| 152 | m_interface->kodi_gui->control_slider->set_int_range(m_interface->kodiBase, m_controlHandle, | ||
| 153 | start, end); | ||
| 154 | } | ||
| 155 | //---------------------------------------------------------------------------- | ||
| 156 | |||
| 157 | //============================================================================ | ||
| 158 | /// @ingroup cpp_kodi_gui_windows_controls_CSlider | ||
| 159 | /// @brief Set the slider position with the given integer value. The Range | ||
| 160 | /// must be defined with a call from @ref SetIntRange before. | ||
| 161 | /// | ||
| 162 | /// @param[in] value Position in range to set with integer | ||
| 163 | /// | ||
| 164 | /// @note Percent, floating point or integer are alone possible. Combining | ||
| 165 | /// these different values can be not together and can, therefore, only one | ||
| 166 | /// each can be used. | ||
| 167 | /// | ||
| 168 | void SetIntValue(int value) | ||
| 169 | { | ||
| 170 | m_interface->kodi_gui->control_slider->set_int_value(m_interface->kodiBase, m_controlHandle, | ||
| 171 | value); | ||
| 172 | } | ||
| 173 | //---------------------------------------------------------------------------- | ||
| 174 | |||
| 175 | //============================================================================ | ||
| 176 | /// @ingroup cpp_kodi_gui_windows_controls_CSlider | ||
| 177 | /// @brief To get the current position as integer value. | ||
| 178 | /// | ||
| 179 | /// @return The position as integer | ||
| 180 | /// | ||
| 181 | /// @note Percent, floating point or integer are alone possible. Combining | ||
| 182 | /// these different values can be not together and can, therefore, only | ||
| 183 | /// one each can be used. | ||
| 184 | /// | ||
| 185 | int GetIntValue() const | ||
| 186 | { | ||
| 187 | return m_interface->kodi_gui->control_slider->get_int_value(m_interface->kodiBase, | ||
| 188 | m_controlHandle); | ||
| 189 | } | ||
| 190 | //---------------------------------------------------------------------------- | ||
| 191 | |||
| 192 | //============================================================================ | ||
| 193 | /// @ingroup cpp_kodi_gui_windows_controls_CSlider | ||
| 194 | /// @brief To set the interval steps of slider, as default is it 1. If it | ||
| 195 | /// becomes changed with this function will a step of the user with the | ||
| 196 | /// value fixed here be executed. | ||
| 197 | /// | ||
| 198 | /// @param[in] interval Intervall step to set. | ||
| 199 | /// | ||
| 200 | /// @note Percent, floating point or integer are alone possible. Combining | ||
| 201 | /// these different values can be not together and can, therefore, only one | ||
| 202 | /// each can be used. | ||
| 203 | /// | ||
| 204 | void SetIntInterval(int interval) | ||
| 205 | { | ||
| 206 | m_interface->kodi_gui->control_slider->set_int_interval(m_interface->kodiBase, m_controlHandle, | ||
| 207 | interval); | ||
| 208 | } | ||
| 209 | //---------------------------------------------------------------------------- | ||
| 210 | |||
| 211 | //============================================================================ | ||
| 212 | /// @ingroup cpp_kodi_gui_windows_controls_CSlider | ||
| 213 | /// @brief Sets the percent of the slider. | ||
| 214 | /// | ||
| 215 | /// @param[in] percent float - Percent value of slide | ||
| 216 | /// | ||
| 217 | /// @note Percent, floating point or integer are alone possible. Combining | ||
| 218 | /// these different values can be not together and can, therefore, only one | ||
| 219 | /// each can be used. | ||
| 220 | /// | ||
| 221 | void SetPercentage(float percent) | ||
| 222 | { | ||
| 223 | m_interface->kodi_gui->control_slider->set_percentage(m_interface->kodiBase, m_controlHandle, | ||
| 224 | percent); | ||
| 225 | } | ||
| 226 | //---------------------------------------------------------------------------- | ||
| 227 | |||
| 228 | //============================================================================ | ||
| 229 | /// @ingroup cpp_kodi_gui_windows_controls_CSlider | ||
| 230 | /// @brief Returns a float of the percent of the slider. | ||
| 231 | /// | ||
| 232 | /// @return float - Percent of slider | ||
| 233 | /// | ||
| 234 | /// @note Percent, floating point or integer are alone possible. Combining | ||
| 235 | /// these different values can be not together and can, therefore, only one | ||
| 236 | /// each can be used. | ||
| 237 | /// | ||
| 238 | float GetPercentage() const | ||
| 239 | { | ||
| 240 | return m_interface->kodi_gui->control_slider->get_percentage(m_interface->kodiBase, | ||
| 241 | m_controlHandle); | ||
| 242 | } | ||
| 243 | //---------------------------------------------------------------------------- | ||
| 244 | |||
| 245 | //============================================================================ | ||
| 246 | /// @ingroup cpp_kodi_gui_windows_controls_CSlider | ||
| 247 | /// @brief To set the the range as float of slider, e.g. -25.0 is the slider | ||
| 248 | /// start and e.g. +25.0 is the from here defined position where it reach | ||
| 249 | /// the end. | ||
| 250 | /// | ||
| 251 | /// As default is the range 0.0 to 1.0. | ||
| 252 | /// | ||
| 253 | /// The float interval is as default 0.1 and can be changed with | ||
| 254 | /// @ref SetFloatInterval. | ||
| 255 | /// | ||
| 256 | /// @param[in] start Integer start value | ||
| 257 | /// @param[in] end Integer end value | ||
| 258 | /// | ||
| 259 | /// @note Percent, floating point or integer are alone possible. Combining | ||
| 260 | /// these different values can be not together and can, therefore, only | ||
| 261 | /// one each can be used. | ||
| 262 | /// | ||
| 263 | void SetFloatRange(float start, float end) | ||
| 264 | { | ||
| 265 | m_interface->kodi_gui->control_slider->set_float_range(m_interface->kodiBase, m_controlHandle, | ||
| 266 | start, end); | ||
| 267 | } | ||
| 268 | //---------------------------------------------------------------------------- | ||
| 269 | |||
| 270 | //============================================================================ | ||
| 271 | /// @ingroup cpp_kodi_gui_windows_controls_CSlider | ||
| 272 | /// @brief Set the slider position with the given float value. The Range | ||
| 273 | /// can be defined with a call from @ref SetIntRange before, as default it | ||
| 274 | /// is 0.0 to 1.0. | ||
| 275 | /// | ||
| 276 | /// @param[in] value Position in range to set with float | ||
| 277 | /// | ||
| 278 | /// @note Percent, floating point or integer are alone possible. Combining | ||
| 279 | /// these different values can be not together and can, therefore, only one | ||
| 280 | /// each can be used. | ||
| 281 | /// | ||
| 282 | void SetFloatValue(float value) | ||
| 283 | { | ||
| 284 | m_interface->kodi_gui->control_slider->set_float_value(m_interface->kodiBase, m_controlHandle, | ||
| 285 | value); | ||
| 286 | } | ||
| 287 | //---------------------------------------------------------------------------- | ||
| 288 | |||
| 289 | //============================================================================ | ||
| 290 | /// @ingroup cpp_kodi_gui_windows_controls_CSlider | ||
| 291 | /// @brief To get the current position as float value. | ||
| 292 | /// | ||
| 293 | /// @return The position as float | ||
| 294 | /// | ||
| 295 | float GetFloatValue() const | ||
| 296 | { | ||
| 297 | return m_interface->kodi_gui->control_slider->get_float_value(m_interface->kodiBase, | ||
| 298 | m_controlHandle); | ||
| 299 | } | ||
| 300 | //---------------------------------------------------------------------------- | ||
| 301 | |||
| 302 | //============================================================================ | ||
| 303 | /// @ingroup cpp_kodi_gui_windows_controls_CSlider | ||
| 304 | /// @brief To set the interval steps of slider, as default is it 0.1 If it | ||
| 305 | /// becomes changed with this function will a step of the user with the | ||
| 306 | /// value fixed here be executed. | ||
| 307 | /// | ||
| 308 | /// @param[in] interval Intervall step to set. | ||
| 309 | /// | ||
| 310 | /// @note Percent, floating point or integer are alone possible. Combining | ||
| 311 | /// these different values can be not together and can, therefore, only | ||
| 312 | /// one each can be used. | ||
| 313 | /// | ||
| 314 | void SetFloatInterval(float interval) | ||
| 315 | { | ||
| 316 | m_interface->kodi_gui->control_slider->set_float_interval(m_interface->kodiBase, | ||
| 317 | m_controlHandle, interval); | ||
| 318 | } | ||
| 319 | //---------------------------------------------------------------------------- | ||
| 320 | }; | ||
| 321 | |||
| 322 | } /* namespace controls */ | ||
| 323 | } /* namespace gui */ | ||
| 324 | } /* namespace kodi */ | ||
| 325 | |||
| 326 | #endif /* __cplusplus */ | ||
diff --git a/xbmc/addons/kodi-dev-kit/include/kodi/gui/controls/Spin.h b/xbmc/addons/kodi-dev-kit/include/kodi/gui/controls/Spin.h new file mode 100644 index 0000000..6c55243 --- /dev/null +++ b/xbmc/addons/kodi-dev-kit/include/kodi/gui/controls/Spin.h | |||
| @@ -0,0 +1,416 @@ | |||
| 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/spin.h" | ||
| 12 | #include "../Window.h" | ||
| 13 | |||
| 14 | #ifdef __cplusplus | ||
| 15 | |||
| 16 | namespace kodi | ||
| 17 | { | ||
| 18 | namespace gui | ||
| 19 | { | ||
| 20 | namespace controls | ||
| 21 | { | ||
| 22 | |||
| 23 | //============================================================================== | ||
| 24 | /// @defgroup cpp_kodi_gui_windows_controls_CSpin Control Spin | ||
| 25 | /// @ingroup cpp_kodi_gui_windows_controls | ||
| 26 | /// @brief @cpp_class{ kodi::gui::controls::CSpin } | ||
| 27 | /// **Window control used for cycling up/down controls**\n | ||
| 28 | /// The settings spin control is used in the settings screens for when a list | ||
| 29 | /// of options can be chosen from using up/down arrows. | ||
| 30 | /// | ||
| 31 | /// You can choose the position, size, and look of the spin control. It is | ||
| 32 | /// basically a cross between the button control and a spin control. It has a | ||
| 33 | /// label and focus and non focus textures, as well as a spin control on the | ||
| 34 | /// right. | ||
| 35 | /// | ||
| 36 | /// It has the header @ref Spin.h "#include <kodi/gui/controls/Spin.h>" | ||
| 37 | /// be included to enjoy it. | ||
| 38 | /// | ||
| 39 | /// Here you find the needed skin part for a @ref Spin_Control "spin control". | ||
| 40 | /// | ||
| 41 | /// @note The call of the control is only possible from the corresponding | ||
| 42 | /// window as its class and identification number is required. | ||
| 43 | /// | ||
| 44 | /// -------------------------------------------------------------------------- | ||
| 45 | /// **Example:** | ||
| 46 | /// ~~~~~~~~~~~~cpp | ||
| 47 | /// #include <kodi/gui/Window.h> | ||
| 48 | /// | ||
| 49 | /// #define MY_SPIN_CONTROL 1 | ||
| 50 | /// | ||
| 51 | /// class CMyWindow : public kodi::gui::CWindow | ||
| 52 | /// { | ||
| 53 | /// public: | ||
| 54 | /// CMyWindow() | ||
| 55 | /// | ||
| 56 | /// void ShowWindow(); | ||
| 57 | /// | ||
| 58 | /// bool OnInit() override; | ||
| 59 | /// bool OnClick(int controlId) override; | ||
| 60 | /// | ||
| 61 | /// private: | ||
| 62 | /// kodi::gui::controls::CSpin m_mySpinControl; | ||
| 63 | /// }; | ||
| 64 | /// | ||
| 65 | /// CMyWindow::CMyWindow() | ||
| 66 | /// : kodi::gui::CWindow("my_skin.xml", "skin.estuary", true, false), | ||
| 67 | /// m_mySpinControl(this, MY_SPIN_CONTROL) | ||
| 68 | /// { | ||
| 69 | /// } | ||
| 70 | /// | ||
| 71 | /// void CMyWindow::ShowWindow() | ||
| 72 | /// { | ||
| 73 | /// kodi::gui::CWindow::DoModal(); | ||
| 74 | /// } | ||
| 75 | /// | ||
| 76 | /// bool CMyWindow::OnInit() | ||
| 77 | /// { | ||
| 78 | /// m_mySpinControl.SetType(kodi::gui::controls::ADDON_SPIN_CONTROL_TYPE_INT); | ||
| 79 | /// m_mySpinControl.SetIntRange(1, 80); | ||
| 80 | /// return true; | ||
| 81 | /// } | ||
| 82 | /// | ||
| 83 | /// bool CMyWindow::OnClick(int controlId) | ||
| 84 | /// { | ||
| 85 | /// if (controlId == MY_SPIN_CONTROL) | ||
| 86 | /// { | ||
| 87 | /// int value = m_mySpinControl.GetIntValue(); | ||
| 88 | /// ... | ||
| 89 | /// } | ||
| 90 | /// return true; | ||
| 91 | /// } | ||
| 92 | /// return false; | ||
| 93 | /// } | ||
| 94 | /// ~~~~~~~~~~~~ | ||
| 95 | /// | ||
| 96 | |||
| 97 | |||
| 98 | //============================================================================== | ||
| 99 | /// @ingroup cpp_kodi_gui_windows_controls_CSpin | ||
| 100 | /// @anchor AddonGUISpinControlType | ||
| 101 | /// @brief The values here defines the used value format for steps on | ||
| 102 | /// spin control. | ||
| 103 | /// | ||
| 104 | typedef enum AddonGUISpinControlType | ||
| 105 | { | ||
| 106 | /// One spin step interpreted as integer | ||
| 107 | ADDON_SPIN_CONTROL_TYPE_INT = 1, | ||
| 108 | /// One spin step interpreted as floating point value | ||
| 109 | ADDON_SPIN_CONTROL_TYPE_FLOAT = 2, | ||
| 110 | /// One spin step interpreted as text string | ||
| 111 | ADDON_SPIN_CONTROL_TYPE_TEXT = 3, | ||
| 112 | /// One spin step interpreted as a page change value | ||
| 113 | ADDON_SPIN_CONTROL_TYPE_PAGE = 4 | ||
| 114 | } AddonGUISpinControlType; | ||
| 115 | //------------------------------------------------------------------------------ | ||
| 116 | |||
| 117 | class ATTRIBUTE_HIDDEN CSpin : public CAddonGUIControlBase | ||
| 118 | { | ||
| 119 | public: | ||
| 120 | //============================================================================ | ||
| 121 | /// @ingroup cpp_kodi_gui_windows_controls_CSpin | ||
| 122 | /// @brief Construct a new control. | ||
| 123 | /// | ||
| 124 | /// @param[in] window Related window control class | ||
| 125 | /// @param[in] controlId Used skin xml control id | ||
| 126 | /// | ||
| 127 | CSpin(CWindow* window, int controlId) : CAddonGUIControlBase(window) | ||
| 128 | { | ||
| 129 | m_controlHandle = m_interface->kodi_gui->window->get_control_spin( | ||
| 130 | m_interface->kodiBase, m_Window->GetControlHandle(), controlId); | ||
| 131 | if (!m_controlHandle) | ||
| 132 | kodi::Log(ADDON_LOG_FATAL, | ||
| 133 | "kodi::gui::controls::CSpin can't create control class from Kodi !!!"); | ||
| 134 | } | ||
| 135 | //---------------------------------------------------------------------------- | ||
| 136 | |||
| 137 | //============================================================================ | ||
| 138 | /// @ingroup cpp_kodi_gui_windows_controls_CSpin | ||
| 139 | /// @brief Destructor. | ||
| 140 | /// | ||
| 141 | ~CSpin() override = default; | ||
| 142 | //---------------------------------------------------------------------------- | ||
| 143 | |||
| 144 | //============================================================================ | ||
| 145 | /// @ingroup cpp_kodi_gui_windows_controls_CSpin | ||
| 146 | /// @brief Set the control on window to visible. | ||
| 147 | /// | ||
| 148 | /// @param[in] visible If true visible, otherwise hidden | ||
| 149 | /// | ||
| 150 | void SetVisible(bool visible) | ||
| 151 | { | ||
| 152 | m_interface->kodi_gui->control_spin->set_visible(m_interface->kodiBase, m_controlHandle, | ||
| 153 | visible); | ||
| 154 | } | ||
| 155 | //---------------------------------------------------------------------------- | ||
| 156 | |||
| 157 | //============================================================================ | ||
| 158 | /// @ingroup cpp_kodi_gui_windows_controls_CSpin | ||
| 159 | /// @brief Set's the control's enabled/disabled state. | ||
| 160 | /// | ||
| 161 | /// @param[in] enabled If true enabled, otherwise disabled | ||
| 162 | /// | ||
| 163 | void SetEnabled(bool enabled) | ||
| 164 | { | ||
| 165 | m_interface->kodi_gui->control_spin->set_enabled(m_interface->kodiBase, m_controlHandle, | ||
| 166 | enabled); | ||
| 167 | } | ||
| 168 | //---------------------------------------------------------------------------- | ||
| 169 | |||
| 170 | //============================================================================ | ||
| 171 | /// @ingroup cpp_kodi_gui_windows_controls_CSpin | ||
| 172 | /// @brief To set the text string on spin control. | ||
| 173 | /// | ||
| 174 | /// @param[in] text Text to show as name for spin | ||
| 175 | /// | ||
| 176 | void SetText(const std::string& text) | ||
| 177 | { | ||
| 178 | m_interface->kodi_gui->control_spin->set_text(m_interface->kodiBase, m_controlHandle, | ||
| 179 | text.c_str()); | ||
| 180 | } | ||
| 181 | //---------------------------------------------------------------------------- | ||
| 182 | |||
| 183 | //============================================================================ | ||
| 184 | /// @ingroup cpp_kodi_gui_windows_controls_CSpin | ||
| 185 | /// @brief To reset spin control to defaults. | ||
| 186 | /// | ||
| 187 | void Reset() | ||
| 188 | { | ||
| 189 | m_interface->kodi_gui->control_spin->reset(m_interface->kodiBase, m_controlHandle); | ||
| 190 | } | ||
| 191 | //---------------------------------------------------------------------------- | ||
| 192 | |||
| 193 | //============================================================================ | ||
| 194 | /// @ingroup cpp_kodi_gui_windows_controls_CSpin | ||
| 195 | /// @brief To set the with SpinControlType defined types of spin. | ||
| 196 | /// | ||
| 197 | /// @param[in] type The type to use | ||
| 198 | /// | ||
| 199 | /// @note See description of @ref AddonGUISpinControlType for available types. | ||
| 200 | /// | ||
| 201 | void SetType(AddonGUISpinControlType type) | ||
| 202 | { | ||
| 203 | m_interface->kodi_gui->control_spin->set_type(m_interface->kodiBase, m_controlHandle, | ||
| 204 | (int)type); | ||
| 205 | } | ||
| 206 | //---------------------------------------------------------------------------- | ||
| 207 | |||
| 208 | //============================================================================ | ||
| 209 | /// @ingroup cpp_kodi_gui_windows_controls_CSpin | ||
| 210 | /// @brief To add a label entry in spin defined with a value as string. | ||
| 211 | /// | ||
| 212 | /// Format must be set to @ref ADDON_SPIN_CONTROL_TYPE_TEXT to use this function. | ||
| 213 | /// | ||
| 214 | /// @param[in] label Label string to view on skin | ||
| 215 | /// @param[in] value String value to use for selection of them | ||
| 216 | /// | ||
| 217 | void AddLabel(const std::string& label, const std::string& value) | ||
| 218 | { | ||
| 219 | m_interface->kodi_gui->control_spin->add_string_label(m_interface->kodiBase, m_controlHandle, | ||
| 220 | label.c_str(), value.c_str()); | ||
| 221 | } | ||
| 222 | //---------------------------------------------------------------------------- | ||
| 223 | |||
| 224 | //============================================================================ | ||
| 225 | /// @ingroup cpp_kodi_gui_windows_controls_CSpin | ||
| 226 | /// @brief To add a label entry in spin defined with a value as integer. | ||
| 227 | /// | ||
| 228 | /// Format must be set to @ref ADDON_SPIN_CONTROL_TYPE_INT to use this function. | ||
| 229 | /// | ||
| 230 | /// @param[in] label Label string to view on skin | ||
| 231 | /// @param[in] value Integer value to use for selection of them. | ||
| 232 | /// | ||
| 233 | void AddLabel(const std::string& label, int value) | ||
| 234 | { | ||
| 235 | m_interface->kodi_gui->control_spin->add_int_label(m_interface->kodiBase, m_controlHandle, | ||
| 236 | label.c_str(), value); | ||
| 237 | } | ||
| 238 | //---------------------------------------------------------------------------- | ||
| 239 | |||
| 240 | //============================================================================ | ||
| 241 | /// @ingroup cpp_kodi_gui_windows_controls_CSpin | ||
| 242 | /// @brief To change the spin to position with them string as value. | ||
| 243 | /// | ||
| 244 | /// Format must be set to @ref ADDON_SPIN_CONTROL_TYPE_TEXT to use this function. | ||
| 245 | /// | ||
| 246 | /// @param[in] value String value to change to | ||
| 247 | /// | ||
| 248 | void SetStringValue(const std::string& value) | ||
| 249 | { | ||
| 250 | m_interface->kodi_gui->control_spin->set_string_value(m_interface->kodiBase, m_controlHandle, | ||
| 251 | value.c_str()); | ||
| 252 | } | ||
| 253 | //---------------------------------------------------------------------------- | ||
| 254 | |||
| 255 | //============================================================================ | ||
| 256 | /// @ingroup cpp_kodi_gui_windows_controls_CSpin | ||
| 257 | /// @brief To get the current spin control position with text string value. | ||
| 258 | /// | ||
| 259 | /// Format must be set to @ref ADDON_SPIN_CONTROL_TYPE_TEXT to use this function. | ||
| 260 | /// | ||
| 261 | /// @return Currently selected string value | ||
| 262 | /// | ||
| 263 | std::string GetStringValue() const | ||
| 264 | { | ||
| 265 | std::string value; | ||
| 266 | char* ret = m_interface->kodi_gui->control_spin->get_string_value(m_interface->kodiBase, | ||
| 267 | m_controlHandle); | ||
| 268 | if (ret != nullptr) | ||
| 269 | { | ||
| 270 | if (std::strlen(ret)) | ||
| 271 | value = ret; | ||
| 272 | m_interface->free_string(m_interface->kodiBase, ret); | ||
| 273 | } | ||
| 274 | return value; | ||
| 275 | } | ||
| 276 | //---------------------------------------------------------------------------- | ||
| 277 | |||
| 278 | //============================================================================ | ||
| 279 | /// @ingroup cpp_kodi_gui_windows_controls_CSpin | ||
| 280 | /// @brief To set the the range as integer of slider, e.g. -10 is the slider | ||
| 281 | /// start and e.g. +10 is the from here defined position where it reach the | ||
| 282 | /// end. | ||
| 283 | /// | ||
| 284 | /// Ad default is the range from 0 to 100. | ||
| 285 | /// | ||
| 286 | /// @param[in] start Integer start value | ||
| 287 | /// @param[in] end Integer end value | ||
| 288 | /// | ||
| 289 | /// @note Percent, floating point or integer are alone possible. Combining | ||
| 290 | /// these different values can be not together and can, therefore, only | ||
| 291 | /// one each can be used and must be defined with @ref SetType before. | ||
| 292 | /// | ||
| 293 | void SetIntRange(int start, int end) | ||
| 294 | { | ||
| 295 | m_interface->kodi_gui->control_spin->set_int_range(m_interface->kodiBase, m_controlHandle, | ||
| 296 | start, end); | ||
| 297 | } | ||
| 298 | //---------------------------------------------------------------------------- | ||
| 299 | |||
| 300 | //============================================================================ | ||
| 301 | /// @ingroup cpp_kodi_gui_windows_controls_CSpin | ||
| 302 | /// @brief Set the slider position with the given integer value. The Range | ||
| 303 | /// must be defined with a call from @ref SetIntRange before. | ||
| 304 | /// | ||
| 305 | /// @param[in] value Position in range to set with integer | ||
| 306 | /// | ||
| 307 | /// @note Percent, floating point or integer are alone possible. Combining | ||
| 308 | /// these different values can be not together and can, therefore, only | ||
| 309 | /// one each can be used and must be defined with @ref SetType before. | ||
| 310 | /// | ||
| 311 | void SetIntValue(int value) | ||
| 312 | { | ||
| 313 | m_interface->kodi_gui->control_spin->set_int_value(m_interface->kodiBase, m_controlHandle, | ||
| 314 | value); | ||
| 315 | } | ||
| 316 | //---------------------------------------------------------------------------- | ||
| 317 | |||
| 318 | //============================================================================ | ||
| 319 | /// @ingroup cpp_kodi_gui_windows_controls_CSpin | ||
| 320 | /// @brief To get the current position as integer value. | ||
| 321 | /// | ||
| 322 | /// @return The position as integer | ||
| 323 | /// | ||
| 324 | /// @note Percent, floating point or integer are alone possible. Combining | ||
| 325 | /// these different values can be not together and can, therefore, only | ||
| 326 | /// one each can be used and must be defined with @ref SetType before. | ||
| 327 | /// | ||
| 328 | int GetIntValue() const | ||
| 329 | { | ||
| 330 | return m_interface->kodi_gui->control_spin->get_int_value(m_interface->kodiBase, | ||
| 331 | m_controlHandle); | ||
| 332 | } | ||
| 333 | //---------------------------------------------------------------------------- | ||
| 334 | |||
| 335 | //============================================================================ | ||
| 336 | /// @ingroup cpp_kodi_gui_windows_controls_CSpin | ||
| 337 | /// @brief To set the the range as float of spin, e.g. -25.0 is the spin | ||
| 338 | /// start and e.g. +25.0 is the from here defined position where it reach | ||
| 339 | /// the end. | ||
| 340 | /// | ||
| 341 | /// As default is the range 0.0 to 1.0. | ||
| 342 | /// | ||
| 343 | /// The float interval is as default 0.1 and can be changed with | ||
| 344 | /// @ref SetFloatInterval. | ||
| 345 | /// | ||
| 346 | /// @param[in] start Integer start value | ||
| 347 | /// @param[in] end Integer end value | ||
| 348 | /// | ||
| 349 | /// @note Percent, floating point or integer are alone possible. Combining | ||
| 350 | /// these different values can be not together and can, therefore, only | ||
| 351 | /// one each can be used and must be defined with @ref SetType before. | ||
| 352 | /// | ||
| 353 | void SetFloatRange(float start, float end) | ||
| 354 | { | ||
| 355 | m_interface->kodi_gui->control_spin->set_float_range(m_interface->kodiBase, m_controlHandle, | ||
| 356 | start, end); | ||
| 357 | } | ||
| 358 | //---------------------------------------------------------------------------- | ||
| 359 | |||
| 360 | //============================================================================ | ||
| 361 | /// @ingroup cpp_kodi_gui_windows_controls_CSpin | ||
| 362 | /// @brief Set the spin position with the given float value. The Range | ||
| 363 | /// can be defined with a call from @ref SetIntRange before, as default it | ||
| 364 | /// is 0.0 to 1.0. | ||
| 365 | /// | ||
| 366 | /// @param[in] value Position in range to set with float | ||
| 367 | /// | ||
| 368 | /// @note Percent, floating point or integer are alone possible. Combining | ||
| 369 | /// these different values can be not together and can, therefore, only | ||
| 370 | /// one each can be used and must be defined with @ref SetType before. | ||
| 371 | /// | ||
| 372 | void SetFloatValue(float value) | ||
| 373 | { | ||
| 374 | m_interface->kodi_gui->control_spin->set_float_value(m_interface->kodiBase, m_controlHandle, | ||
| 375 | value); | ||
| 376 | } | ||
| 377 | //---------------------------------------------------------------------------- | ||
| 378 | |||
| 379 | //============================================================================ | ||
| 380 | /// @ingroup cpp_kodi_gui_windows_controls_CSpin | ||
| 381 | /// @brief To get the current position as float value. | ||
| 382 | /// | ||
| 383 | /// @return The position as float | ||
| 384 | /// | ||
| 385 | float GetFloatValue() const | ||
| 386 | { | ||
| 387 | return m_interface->kodi_gui->control_spin->get_float_value(m_interface->kodiBase, | ||
| 388 | m_controlHandle); | ||
| 389 | } | ||
| 390 | //---------------------------------------------------------------------------- | ||
| 391 | |||
| 392 | //============================================================================ | ||
| 393 | /// @ingroup cpp_kodi_gui_windows_controls_CSpin | ||
| 394 | /// @brief To set the interval steps of spin, as default is it 0.1 If it | ||
| 395 | /// becomes changed with this function will a step of the user with the | ||
| 396 | /// value fixed here be executed. | ||
| 397 | /// | ||
| 398 | /// @param[in] interval Intervall step to set. | ||
| 399 | /// | ||
| 400 | /// @note Percent, floating point or integer are alone possible. Combining | ||
| 401 | /// these different values can be not together and can, therefore, only | ||
| 402 | /// one each can be used and must be defined with @ref SetType before. | ||
| 403 | /// | ||
| 404 | void SetFloatInterval(float interval) | ||
| 405 | { | ||
| 406 | m_interface->kodi_gui->control_spin->set_float_interval(m_interface->kodiBase, m_controlHandle, | ||
| 407 | interval); | ||
| 408 | } | ||
| 409 | //---------------------------------------------------------------------------- | ||
| 410 | }; | ||
| 411 | |||
| 412 | } /* namespace controls */ | ||
| 413 | } /* namespace gui */ | ||
| 414 | } /* namespace kodi */ | ||
| 415 | |||
| 416 | #endif /* __cplusplus */ | ||
diff --git a/xbmc/addons/kodi-dev-kit/include/kodi/gui/controls/TextBox.h b/xbmc/addons/kodi-dev-kit/include/kodi/gui/controls/TextBox.h new file mode 100644 index 0000000..2634568 --- /dev/null +++ b/xbmc/addons/kodi-dev-kit/include/kodi/gui/controls/TextBox.h | |||
| @@ -0,0 +1,164 @@ | |||
| 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/text_box.h" | ||
| 12 | #include "../Window.h" | ||
| 13 | |||
| 14 | #ifdef __cplusplus | ||
| 15 | |||
| 16 | namespace kodi | ||
| 17 | { | ||
| 18 | namespace gui | ||
| 19 | { | ||
| 20 | namespace controls | ||
| 21 | { | ||
| 22 | |||
| 23 | //============================================================================ | ||
| 24 | /// @defgroup cpp_kodi_gui_windows_controls_CTextBox Control Text Box | ||
| 25 | /// @ingroup cpp_kodi_gui_windows_controls | ||
| 26 | /// @brief @cpp_class{ kodi::gui::controls::CTextBox } | ||
| 27 | /// **Used to show a multi-page piece of text**\n | ||
| 28 | /// The text box control can be used to display descriptions, help texts or | ||
| 29 | /// other larger texts. | ||
| 30 | /// | ||
| 31 | /// It corresponds to the representation which is also to be seen on the | ||
| 32 | /// @ref CDialogTextViewer. | ||
| 33 | /// | ||
| 34 | /// It has the header @ref TextBox.h "#include <kodi/gui/controls/TextBox.h>" | ||
| 35 | /// be included to enjoy it. | ||
| 36 | /// | ||
| 37 | /// Here you find the needed skin part for a @ref Text_Box "textbox control". | ||
| 38 | /// | ||
| 39 | /// @note The call of the control is only possible from the corresponding | ||
| 40 | /// window as its class and identification number is required. | ||
| 41 | /// | ||
| 42 | class ATTRIBUTE_HIDDEN CTextBox : public CAddonGUIControlBase | ||
| 43 | { | ||
| 44 | public: | ||
| 45 | //========================================================================== | ||
| 46 | /// @ingroup cpp_kodi_gui_windows_controls_CTextBox | ||
| 47 | /// @brief Construct a new control. | ||
| 48 | /// | ||
| 49 | /// @param[in] window related window control class | ||
| 50 | /// @param[in] controlId Used skin xml control id | ||
| 51 | /// | ||
| 52 | CTextBox(CWindow* window, int controlId) : CAddonGUIControlBase(window) | ||
| 53 | { | ||
| 54 | m_controlHandle = m_interface->kodi_gui->window->get_control_text_box( | ||
| 55 | m_interface->kodiBase, m_Window->GetControlHandle(), controlId); | ||
| 56 | if (!m_controlHandle) | ||
| 57 | kodi::Log(ADDON_LOG_FATAL, | ||
| 58 | "kodi::gui::controls::CTextBox can't create control class from Kodi !!!"); | ||
| 59 | } | ||
| 60 | //-------------------------------------------------------------------------- | ||
| 61 | |||
| 62 | //========================================================================== | ||
| 63 | /// @ingroup cpp_kodi_gui_windows_controls_CTextBox | ||
| 64 | /// @brief Destructor. | ||
| 65 | /// | ||
| 66 | ~CTextBox() override = default; | ||
| 67 | //-------------------------------------------------------------------------- | ||
| 68 | |||
| 69 | //========================================================================== | ||
| 70 | /// @ingroup cpp_kodi_gui_windows_controls_CTextBox | ||
| 71 | /// @brief Set the control on window to visible. | ||
| 72 | /// | ||
| 73 | /// @param[in] visible If true visible, otherwise hidden | ||
| 74 | /// | ||
| 75 | void SetVisible(bool visible) | ||
| 76 | { | ||
| 77 | m_interface->kodi_gui->control_text_box->set_visible(m_interface->kodiBase, m_controlHandle, | ||
| 78 | visible); | ||
| 79 | } | ||
| 80 | //-------------------------------------------------------------------------- | ||
| 81 | |||
| 82 | //========================================================================== | ||
| 83 | /// @ingroup cpp_kodi_gui_windows_controls_CTextBox | ||
| 84 | /// @brief To reset box an remove all the text. | ||
| 85 | /// | ||
| 86 | void Reset() { m_interface->kodi_gui->control_text_box->reset(m_controlHandle, m_controlHandle); } | ||
| 87 | //-------------------------------------------------------------------------- | ||
| 88 | |||
| 89 | //========================================================================== | ||
| 90 | /// @ingroup cpp_kodi_gui_windows_controls_CTextBox | ||
| 91 | /// @brief To set the text on box. | ||
| 92 | /// | ||
| 93 | /// @param[in] text Text to show | ||
| 94 | /// | ||
| 95 | void SetText(const std::string& text) | ||
| 96 | { | ||
| 97 | m_interface->kodi_gui->control_text_box->set_text(m_interface->kodiBase, m_controlHandle, | ||
| 98 | text.c_str()); | ||
| 99 | } | ||
| 100 | //-------------------------------------------------------------------------- | ||
| 101 | |||
| 102 | //========================================================================== | ||
| 103 | /// @ingroup cpp_kodi_gui_windows_controls_CTextBox | ||
| 104 | /// @brief Get the used text from control. | ||
| 105 | /// | ||
| 106 | /// @return Text shown | ||
| 107 | /// | ||
| 108 | std::string GetText() const | ||
| 109 | { | ||
| 110 | std::string text; | ||
| 111 | char* ret = | ||
| 112 | m_interface->kodi_gui->control_text_box->get_text(m_interface->kodiBase, m_controlHandle); | ||
| 113 | if (ret != nullptr) | ||
| 114 | { | ||
| 115 | if (std::strlen(ret)) | ||
| 116 | text = ret; | ||
| 117 | m_interface->free_string(m_interface->kodiBase, ret); | ||
| 118 | } | ||
| 119 | return text; | ||
| 120 | } | ||
| 121 | //-------------------------------------------------------------------------- | ||
| 122 | |||
| 123 | //========================================================================== | ||
| 124 | /// @ingroup cpp_kodi_gui_windows_controls_CTextBox | ||
| 125 | /// @brief To scroll text on other position. | ||
| 126 | /// | ||
| 127 | /// @param[in] position The line position to scroll to | ||
| 128 | /// | ||
| 129 | void Scroll(unsigned int position) | ||
| 130 | { | ||
| 131 | m_interface->kodi_gui->control_text_box->scroll(m_interface->kodiBase, m_controlHandle, | ||
| 132 | position); | ||
| 133 | } | ||
| 134 | //-------------------------------------------------------------------------- | ||
| 135 | |||
| 136 | //========================================================================== | ||
| 137 | /// @ingroup cpp_kodi_gui_windows_controls_CTextBox | ||
| 138 | /// @brief To set automatic scrolling of textbox | ||
| 139 | /// | ||
| 140 | /// Specifies the timing and conditions of any autoscrolling this textbox | ||
| 141 | /// should have. Times are in milliseconds. The content is delayed for the | ||
| 142 | /// given delay, then scrolls at a rate of one line per time interval until | ||
| 143 | /// the end. If the repeat tag is present, it then delays for the repeat | ||
| 144 | /// time, fades out over 1 second, and repeats. It does not wrap or reset | ||
| 145 | /// to the top at the end of the scroll. | ||
| 146 | /// | ||
| 147 | /// @param[in] delay Content delay | ||
| 148 | /// @param[in] time One line per time interval | ||
| 149 | /// @param[in] repeat Delays with given time, fades out over 1 second, and | ||
| 150 | /// repeats | ||
| 151 | /// | ||
| 152 | void SetAutoScrolling(int delay, int time, int repeat) | ||
| 153 | { | ||
| 154 | m_interface->kodi_gui->control_text_box->set_auto_scrolling( | ||
| 155 | m_interface->kodiBase, m_controlHandle, delay, time, repeat); | ||
| 156 | } | ||
| 157 | //-------------------------------------------------------------------------- | ||
| 158 | }; | ||
| 159 | |||
| 160 | } /* namespace controls */ | ||
| 161 | } /* namespace gui */ | ||
| 162 | } /* namespace kodi */ | ||
| 163 | |||
| 164 | #endif /* __cplusplus */ | ||
diff --git a/xbmc/addons/kodi-dev-kit/include/kodi/gui/dialogs/CMakeLists.txt b/xbmc/addons/kodi-dev-kit/include/kodi/gui/dialogs/CMakeLists.txt new file mode 100644 index 0000000..9aaee4f --- /dev/null +++ b/xbmc/addons/kodi-dev-kit/include/kodi/gui/dialogs/CMakeLists.txt | |||
| @@ -0,0 +1,14 @@ | |||
| 1 | set(HEADERS ContextMenu.h | ||
| 2 | ExtendedProgress.h | ||
| 3 | FileBrowser.h | ||
| 4 | Keyboard.h | ||
| 5 | Numeric.h | ||
| 6 | OK.h | ||
| 7 | Progress.h | ||
| 8 | Select.h | ||
| 9 | TextViewer.h | ||
| 10 | YesNo.h) | ||
| 11 | |||
| 12 | if(NOT ENABLE_STATIC_LIBS) | ||
| 13 | core_add_library(addons_kodi-dev-kit_include_kodi_gui_dialogs) | ||
| 14 | endif() | ||
diff --git a/xbmc/addons/kodi-dev-kit/include/kodi/gui/dialogs/ContextMenu.h b/xbmc/addons/kodi-dev-kit/include/kodi/gui/dialogs/ContextMenu.h new file mode 100644 index 0000000..b576b9a --- /dev/null +++ b/xbmc/addons/kodi-dev-kit/include/kodi/gui/dialogs/ContextMenu.h | |||
| @@ -0,0 +1,186 @@ | |||
| 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 "../../AddonBase.h" | ||
| 12 | #include "../../c-api/gui/dialogs/context_menu.h" | ||
| 13 | |||
| 14 | #ifdef __cplusplus | ||
| 15 | |||
| 16 | namespace kodi | ||
| 17 | { | ||
| 18 | namespace gui | ||
| 19 | { | ||
| 20 | namespace dialogs | ||
| 21 | { | ||
| 22 | |||
| 23 | //============================================================================== | ||
| 24 | /// @defgroup cpp_kodi_gui_dialogs_ContextMenu Dialog Context Menu | ||
| 25 | /// @ingroup cpp_kodi_gui_dialogs | ||
| 26 | /// @brief @cpp_namespace{ kodi::gui::dialogs::ContextMenu } | ||
| 27 | /// **Context menu dialog**@n | ||
| 28 | /// The function listed below permits the call of a dialogue as context menu to | ||
| 29 | /// select of an entry as a key | ||
| 30 | /// | ||
| 31 | /// It has the header @ref ContextMenu.h "#include <kodi/gui/dialogs/ContextMenu.h>" | ||
| 32 | /// be included to enjoy it. | ||
| 33 | /// | ||
| 34 | /// | ||
| 35 | namespace ContextMenu | ||
| 36 | { | ||
| 37 | //============================================================================== | ||
| 38 | /// @ingroup cpp_kodi_gui_dialogs_ContextMenu | ||
| 39 | /// @brief Show a context menu dialog about given parts. | ||
| 40 | /// | ||
| 41 | /// @param[in] heading Dialog heading name | ||
| 42 | /// @param[in] entries String list about entries | ||
| 43 | /// @return The selected entry, if return <tt>-1</tt> was nothing selected or canceled | ||
| 44 | /// | ||
| 45 | /// | ||
| 46 | ///------------------------------------------------------------------------- | ||
| 47 | /// | ||
| 48 | /// **Example:** | ||
| 49 | /// ~~~~~~~~~~~~~{.cpp} | ||
| 50 | /// #include <kodi/gui/dialogs/ContextMenu.h> | ||
| 51 | /// | ||
| 52 | /// const std::vector<std::string> entries | ||
| 53 | /// { | ||
| 54 | /// "Test 1", | ||
| 55 | /// "Test 2", | ||
| 56 | /// "Test 3", | ||
| 57 | /// "Test 4", | ||
| 58 | /// "Test 5" | ||
| 59 | /// }; | ||
| 60 | /// | ||
| 61 | /// int selected = kodi::gui::dialogs::ContextMenu::Show("Test selection", entries); | ||
| 62 | /// if (selected < 0) | ||
| 63 | /// fprintf(stderr, "Item selection canceled\n"); | ||
| 64 | /// else | ||
| 65 | /// fprintf(stderr, "Selected item is: %i\n", selected); | ||
| 66 | /// ~~~~~~~~~~~~~ | ||
| 67 | /// | ||
| 68 | inline int ATTRIBUTE_HIDDEN Show(const std::string& heading, | ||
| 69 | const std::vector<std::string>& entries) | ||
| 70 | { | ||
| 71 | using namespace ::kodi::addon; | ||
| 72 | unsigned int size = static_cast<unsigned int>(entries.size()); | ||
| 73 | const char** cEntries = static_cast<const char**>(malloc(size * sizeof(const char**))); | ||
| 74 | for (unsigned int i = 0; i < size; ++i) | ||
| 75 | { | ||
| 76 | cEntries[i] = entries[i].c_str(); | ||
| 77 | } | ||
| 78 | int ret = CAddonBase::m_interface->toKodi->kodi_gui->dialogContextMenu->open( | ||
| 79 | CAddonBase::m_interface->toKodi->kodiBase, heading.c_str(), cEntries, size); | ||
| 80 | free(cEntries); | ||
| 81 | return ret; | ||
| 82 | } | ||
| 83 | //------------------------------------------------------------------------------ | ||
| 84 | |||
| 85 | //============================================================================== | ||
| 86 | /// @ingroup cpp_kodi_gui_dialogs_ContextMenu | ||
| 87 | /// @brief Show a context menu dialog about given parts. | ||
| 88 | /// | ||
| 89 | /// @param[in] heading Dialog heading name | ||
| 90 | /// @param[in] entries String list about entries | ||
| 91 | /// @return The selected entry, if return <tt>-1</tt> was nothing selected or canceled | ||
| 92 | /// | ||
| 93 | /// | ||
| 94 | ///------------------------------------------------------------------------- | ||
| 95 | /// | ||
| 96 | /// **Example:** | ||
| 97 | /// ~~~~~~~~~~~~~{.cpp} | ||
| 98 | /// #include <kodi/gui/dialogs/ContextMenu.h> | ||
| 99 | /// | ||
| 100 | /// const std::vector<std::pair<std::string, std::string>> entries | ||
| 101 | /// { | ||
| 102 | /// { "ID 1", "Test 1" }, | ||
| 103 | /// { "ID 2", "Test 2" }, | ||
| 104 | /// { "ID 3", "Test 3" }, | ||
| 105 | /// { "ID 4", "Test 4" }, | ||
| 106 | /// { "ID 5", "Test 5" } | ||
| 107 | /// }; | ||
| 108 | /// | ||
| 109 | /// int selected = kodi::gui::dialogs::ContextMenu::Show("Test selection", entries); | ||
| 110 | /// if (selected < 0) | ||
| 111 | /// fprintf(stderr, "Item selection canceled\n"); | ||
| 112 | /// else | ||
| 113 | /// fprintf(stderr, "Selected item is: %i\n", selected); | ||
| 114 | /// ~~~~~~~~~~~~~ | ||
| 115 | /// | ||
| 116 | inline int ATTRIBUTE_HIDDEN Show(const std::string& heading, | ||
| 117 | const std::vector<std::pair<std::string, std::string>>& entries) | ||
| 118 | { | ||
| 119 | using namespace ::kodi::addon; | ||
| 120 | unsigned int size = static_cast<unsigned int>(entries.size()); | ||
| 121 | const char** cEntries = static_cast<const char**>(malloc(size * sizeof(const char**))); | ||
| 122 | for (unsigned int i = 0; i < size; ++i) | ||
| 123 | { | ||
| 124 | cEntries[i] = entries[i].second.c_str(); | ||
| 125 | } | ||
| 126 | int ret = CAddonBase::m_interface->toKodi->kodi_gui->dialogContextMenu->open( | ||
| 127 | CAddonBase::m_interface->toKodi->kodiBase, heading.c_str(), cEntries, size); | ||
| 128 | free(cEntries); | ||
| 129 | return ret; | ||
| 130 | } | ||
| 131 | //------------------------------------------------------------------------------ | ||
| 132 | |||
| 133 | //============================================================================== | ||
| 134 | /// @ingroup cpp_kodi_gui_dialogs_ContextMenu | ||
| 135 | /// @brief Show a context menu dialog about given parts. | ||
| 136 | /// | ||
| 137 | /// @param[in] heading Dialog heading name | ||
| 138 | /// @param[in] entries String list about entries | ||
| 139 | /// @return The selected entry, if return <tt>-1</tt> was nothing selected or canceled | ||
| 140 | /// | ||
| 141 | /// | ||
| 142 | ///------------------------------------------------------------------------- | ||
| 143 | /// | ||
| 144 | /// **Example:** | ||
| 145 | /// ~~~~~~~~~~~~~{.cpp} | ||
| 146 | /// #include <kodi/gui/dialogs/ContextMenu.h> | ||
| 147 | /// | ||
| 148 | /// const std::vector<std::pair<int, std::string>> entries | ||
| 149 | /// { | ||
| 150 | /// { 1, "Test 1" }, | ||
| 151 | /// { 2, "Test 2" }, | ||
| 152 | /// { 3, "Test 3" }, | ||
| 153 | /// { 4, "Test 4" }, | ||
| 154 | /// { 5, "Test 5" } | ||
| 155 | /// }; | ||
| 156 | /// | ||
| 157 | /// int selected = kodi::gui::dialogs::ContextMenu::Show("Test selection", entries); | ||
| 158 | /// if (selected < 0) | ||
| 159 | /// fprintf(stderr, "Item selection canceled\n"); | ||
| 160 | /// else | ||
| 161 | /// fprintf(stderr, "Selected item is: %i\n", selected); | ||
| 162 | /// ~~~~~~~~~~~~~ | ||
| 163 | /// | ||
| 164 | inline int ATTRIBUTE_HIDDEN Show(const std::string& heading, | ||
| 165 | const std::vector<std::pair<int, std::string>>& entries) | ||
| 166 | { | ||
| 167 | using namespace ::kodi::addon; | ||
| 168 | unsigned int size = static_cast<unsigned int>(entries.size()); | ||
| 169 | const char** cEntries = static_cast<const char**>(malloc(size * sizeof(const char**))); | ||
| 170 | for (unsigned int i = 0; i < size; ++i) | ||
| 171 | { | ||
| 172 | cEntries[i] = entries[i].second.c_str(); | ||
| 173 | } | ||
| 174 | int ret = CAddonBase::m_interface->toKodi->kodi_gui->dialogContextMenu->open( | ||
| 175 | CAddonBase::m_interface->toKodi->kodiBase, heading.c_str(), cEntries, size); | ||
| 176 | free(cEntries); | ||
| 177 | return ret; | ||
| 178 | } | ||
| 179 | //------------------------------------------------------------------------------ | ||
| 180 | }; // namespace ContextMenu | ||
| 181 | |||
| 182 | } /* namespace dialogs */ | ||
| 183 | } /* namespace gui */ | ||
| 184 | } /* namespace kodi */ | ||
| 185 | |||
| 186 | #endif /* __cplusplus */ | ||
diff --git a/xbmc/addons/kodi-dev-kit/include/kodi/gui/dialogs/ExtendedProgress.h b/xbmc/addons/kodi-dev-kit/include/kodi/gui/dialogs/ExtendedProgress.h new file mode 100644 index 0000000..c650483 --- /dev/null +++ b/xbmc/addons/kodi-dev-kit/include/kodi/gui/dialogs/ExtendedProgress.h | |||
| @@ -0,0 +1,242 @@ | |||
| 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 "../../AddonBase.h" | ||
| 12 | #include "../../c-api/gui/dialogs/extended_progress.h" | ||
| 13 | |||
| 14 | #ifdef __cplusplus | ||
| 15 | |||
| 16 | namespace kodi | ||
| 17 | { | ||
| 18 | namespace gui | ||
| 19 | { | ||
| 20 | namespace dialogs | ||
| 21 | { | ||
| 22 | |||
| 23 | //============================================================================== | ||
| 24 | /// @defgroup cpp_kodi_gui_dialogs_CExtendedProgress Dialog Extended Progress | ||
| 25 | /// @ingroup cpp_kodi_gui_dialogs | ||
| 26 | /// @brief @cpp_class{ kodi::gui::dialogs::ExtendedProgress } | ||
| 27 | /// **Progress dialog shown for background work** | ||
| 28 | /// | ||
| 29 | /// The with @ref ExtendedProgress.h "#include <kodi/gui/dialogs/ExtendedProgress.h>" | ||
| 30 | /// given class are basically used to create Kodi's extended progress. | ||
| 31 | /// | ||
| 32 | /// | ||
| 33 | /// -------------------------------------------------------------------------- | ||
| 34 | /// | ||
| 35 | /// **Example:** | ||
| 36 | /// ~~~~~~~~~~~~~{.cpp} | ||
| 37 | /// #include <kodi/gui/dialogs/ExtendedProgress.h> | ||
| 38 | /// | ||
| 39 | /// kodi::gui::dialogs::CExtendedProgress *ext_progress = new kodi::gui::dialogs::CExtendedProgress("Test Extended progress"); | ||
| 40 | /// ext_progress->SetText("Test progress"); | ||
| 41 | /// for (unsigned int i = 0; i < 50; i += 10) | ||
| 42 | /// { | ||
| 43 | /// ext_progress->SetProgress(i, 100); | ||
| 44 | /// sleep(1); | ||
| 45 | /// } | ||
| 46 | /// | ||
| 47 | /// ext_progress->SetTitle("Test Extended progress - Second round"); | ||
| 48 | /// ext_progress->SetText("Test progress - Step 2"); | ||
| 49 | /// | ||
| 50 | /// for (unsigned int i = 50; i < 100; i += 10) | ||
| 51 | /// { | ||
| 52 | /// ext_progress->SetProgress(i, 100); | ||
| 53 | /// sleep(1); | ||
| 54 | /// } | ||
| 55 | /// delete ext_progress; | ||
| 56 | /// ~~~~~~~~~~~~~ | ||
| 57 | /// | ||
| 58 | class ATTRIBUTE_HIDDEN CExtendedProgress | ||
| 59 | { | ||
| 60 | public: | ||
| 61 | //============================================================================ | ||
| 62 | /// @ingroup cpp_kodi_gui_dialogs_CExtendedProgress | ||
| 63 | /// Construct a new dialog. | ||
| 64 | /// | ||
| 65 | /// @param[in] title [opt] Title string | ||
| 66 | /// | ||
| 67 | explicit CExtendedProgress(const std::string& title = "") | ||
| 68 | { | ||
| 69 | using namespace ::kodi::addon; | ||
| 70 | m_DialogHandle = CAddonBase::m_interface->toKodi->kodi_gui->dialogExtendedProgress->new_dialog( | ||
| 71 | CAddonBase::m_interface->toKodi->kodiBase, title.c_str()); | ||
| 72 | if (!m_DialogHandle) | ||
| 73 | kodi::Log(ADDON_LOG_FATAL, | ||
| 74 | "kodi::gui::CDialogExtendedProgress can't create window class from Kodi !!!"); | ||
| 75 | } | ||
| 76 | //---------------------------------------------------------------------------- | ||
| 77 | |||
| 78 | //============================================================================ | ||
| 79 | /// @ingroup cpp_kodi_gui_dialogs_CExtendedProgress | ||
| 80 | /// Destructor. | ||
| 81 | /// | ||
| 82 | ~CExtendedProgress() | ||
| 83 | { | ||
| 84 | using namespace ::kodi::addon; | ||
| 85 | if (m_DialogHandle) | ||
| 86 | CAddonBase::m_interface->toKodi->kodi_gui->dialogExtendedProgress->delete_dialog( | ||
| 87 | CAddonBase::m_interface->toKodi->kodiBase, m_DialogHandle); | ||
| 88 | } | ||
| 89 | //---------------------------------------------------------------------------- | ||
| 90 | |||
| 91 | //============================================================================ | ||
| 92 | /// @ingroup cpp_kodi_gui_dialogs_CExtendedProgress | ||
| 93 | /// @brief Get the used title. | ||
| 94 | /// | ||
| 95 | /// @return Title string | ||
| 96 | /// | ||
| 97 | std::string Title() const | ||
| 98 | { | ||
| 99 | using namespace ::kodi::addon; | ||
| 100 | std::string text; | ||
| 101 | char* strMsg = CAddonBase::m_interface->toKodi->kodi_gui->dialogExtendedProgress->get_title( | ||
| 102 | CAddonBase::m_interface->toKodi->kodiBase, m_DialogHandle); | ||
| 103 | if (strMsg != nullptr) | ||
| 104 | { | ||
| 105 | if (std::strlen(strMsg)) | ||
| 106 | text = strMsg; | ||
| 107 | CAddonBase::m_interface->toKodi->free_string(CAddonBase::m_interface->toKodi->kodiBase, | ||
| 108 | strMsg); | ||
| 109 | } | ||
| 110 | return text; | ||
| 111 | } | ||
| 112 | //---------------------------------------------------------------------------- | ||
| 113 | |||
| 114 | //============================================================================ | ||
| 115 | /// @ingroup cpp_kodi_gui_dialogs_CExtendedProgress | ||
| 116 | /// @brief To set the title of dialog. | ||
| 117 | /// | ||
| 118 | /// @param[in] title Title string | ||
| 119 | /// | ||
| 120 | void SetTitle(const std::string& title) | ||
| 121 | { | ||
| 122 | using namespace ::kodi::addon; | ||
| 123 | CAddonBase::m_interface->toKodi->kodi_gui->dialogExtendedProgress->set_title( | ||
| 124 | CAddonBase::m_interface->toKodi->kodiBase, m_DialogHandle, title.c_str()); | ||
| 125 | } | ||
| 126 | //---------------------------------------------------------------------------- | ||
| 127 | |||
| 128 | //============================================================================ | ||
| 129 | /// @ingroup cpp_kodi_gui_dialogs_CExtendedProgress | ||
| 130 | /// @brief Get the used text information string. | ||
| 131 | /// | ||
| 132 | /// @return Text string | ||
| 133 | /// | ||
| 134 | std::string Text() const | ||
| 135 | { | ||
| 136 | using namespace ::kodi::addon; | ||
| 137 | std::string text; | ||
| 138 | char* strMsg = CAddonBase::m_interface->toKodi->kodi_gui->dialogExtendedProgress->get_text( | ||
| 139 | CAddonBase::m_interface->toKodi->kodiBase, m_DialogHandle); | ||
| 140 | if (strMsg != nullptr) | ||
| 141 | { | ||
| 142 | if (std::strlen(strMsg)) | ||
| 143 | text = strMsg; | ||
| 144 | CAddonBase::m_interface->toKodi->free_string(CAddonBase::m_interface->toKodi->kodiBase, | ||
| 145 | strMsg); | ||
| 146 | } | ||
| 147 | return text; | ||
| 148 | } | ||
| 149 | //---------------------------------------------------------------------------- | ||
| 150 | |||
| 151 | //============================================================================ | ||
| 152 | /// @ingroup cpp_kodi_gui_dialogs_CExtendedProgress | ||
| 153 | /// @brief To set the used text information string. | ||
| 154 | /// | ||
| 155 | /// @param[in] text Information text to set | ||
| 156 | /// | ||
| 157 | void SetText(const std::string& text) | ||
| 158 | { | ||
| 159 | using namespace ::kodi::addon; | ||
| 160 | CAddonBase::m_interface->toKodi->kodi_gui->dialogExtendedProgress->set_text( | ||
| 161 | CAddonBase::m_interface->toKodi->kodiBase, m_DialogHandle, text.c_str()); | ||
| 162 | } | ||
| 163 | //---------------------------------------------------------------------------- | ||
| 164 | |||
| 165 | //============================================================================ | ||
| 166 | /// @ingroup cpp_kodi_gui_dialogs_CExtendedProgress | ||
| 167 | /// @brief To ask dialog is finished. | ||
| 168 | /// | ||
| 169 | /// @return True if on end | ||
| 170 | /// | ||
| 171 | bool IsFinished() const | ||
| 172 | { | ||
| 173 | using namespace ::kodi::addon; | ||
| 174 | return CAddonBase::m_interface->toKodi->kodi_gui->dialogExtendedProgress->is_finished( | ||
| 175 | CAddonBase::m_interface->toKodi->kodiBase, m_DialogHandle); | ||
| 176 | } | ||
| 177 | //---------------------------------------------------------------------------- | ||
| 178 | |||
| 179 | //============================================================================ | ||
| 180 | /// @ingroup cpp_kodi_gui_dialogs_CExtendedProgress | ||
| 181 | /// @brief Mark progress finished. | ||
| 182 | /// | ||
| 183 | void MarkFinished() | ||
| 184 | { | ||
| 185 | using namespace ::kodi::addon; | ||
| 186 | CAddonBase::m_interface->toKodi->kodi_gui->dialogExtendedProgress->mark_finished( | ||
| 187 | CAddonBase::m_interface->toKodi->kodiBase, m_DialogHandle); | ||
| 188 | } | ||
| 189 | //---------------------------------------------------------------------------- | ||
| 190 | |||
| 191 | //============================================================================ | ||
| 192 | /// @ingroup cpp_kodi_gui_dialogs_CExtendedProgress | ||
| 193 | /// @brief Get the current progress position as percent. | ||
| 194 | /// | ||
| 195 | /// @return Position | ||
| 196 | /// | ||
| 197 | float Percentage() const | ||
| 198 | { | ||
| 199 | using namespace ::kodi::addon; | ||
| 200 | return CAddonBase::m_interface->toKodi->kodi_gui->dialogExtendedProgress->get_percentage( | ||
| 201 | CAddonBase::m_interface->toKodi->kodiBase, m_DialogHandle); | ||
| 202 | } | ||
| 203 | //---------------------------------------------------------------------------- | ||
| 204 | |||
| 205 | //============================================================================ | ||
| 206 | /// @ingroup cpp_kodi_gui_dialogs_CExtendedProgress | ||
| 207 | /// @brief To set the current progress position as percent. | ||
| 208 | /// | ||
| 209 | /// @param[in] percentage Position to use from 0.0 to 100.0 | ||
| 210 | /// | ||
| 211 | void SetPercentage(float percentage) | ||
| 212 | { | ||
| 213 | using namespace ::kodi::addon; | ||
| 214 | CAddonBase::m_interface->toKodi->kodi_gui->dialogExtendedProgress->set_percentage( | ||
| 215 | CAddonBase::m_interface->toKodi->kodiBase, m_DialogHandle, percentage); | ||
| 216 | } | ||
| 217 | //---------------------------------------------------------------------------- | ||
| 218 | |||
| 219 | //============================================================================ | ||
| 220 | /// @ingroup cpp_kodi_gui_dialogs_CExtendedProgress | ||
| 221 | /// @brief To set progress position with predefined places. | ||
| 222 | /// | ||
| 223 | /// @param[in] currentItem Place position to use | ||
| 224 | /// @param[in] itemCount Amount of used places | ||
| 225 | /// | ||
| 226 | void SetProgress(int currentItem, int itemCount) | ||
| 227 | { | ||
| 228 | using namespace ::kodi::addon; | ||
| 229 | CAddonBase::m_interface->toKodi->kodi_gui->dialogExtendedProgress->set_progress( | ||
| 230 | CAddonBase::m_interface->toKodi->kodiBase, m_DialogHandle, currentItem, itemCount); | ||
| 231 | } | ||
| 232 | //---------------------------------------------------------------------------- | ||
| 233 | |||
| 234 | private: | ||
| 235 | KODI_GUI_HANDLE m_DialogHandle; | ||
| 236 | }; | ||
| 237 | |||
| 238 | } /* namespace dialogs */ | ||
| 239 | } /* namespace gui */ | ||
| 240 | } /* namespace kodi */ | ||
| 241 | |||
| 242 | #endif /* __cplusplus */ | ||
diff --git a/xbmc/addons/kodi-dev-kit/include/kodi/gui/dialogs/FileBrowser.h b/xbmc/addons/kodi-dev-kit/include/kodi/gui/dialogs/FileBrowser.h new file mode 100644 index 0000000..244c76c --- /dev/null +++ b/xbmc/addons/kodi-dev-kit/include/kodi/gui/dialogs/FileBrowser.h | |||
| @@ -0,0 +1,302 @@ | |||
| 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 "../../AddonBase.h" | ||
| 12 | #include "../../c-api/gui/dialogs/filebrowser.h" | ||
| 13 | |||
| 14 | #ifdef __cplusplus | ||
| 15 | |||
| 16 | namespace kodi | ||
| 17 | { | ||
| 18 | namespace gui | ||
| 19 | { | ||
| 20 | namespace dialogs | ||
| 21 | { | ||
| 22 | |||
| 23 | //============================================================================== | ||
| 24 | /// @defgroup cpp_kodi_gui_dialogs_FileBrowser Dialog File Browser | ||
| 25 | /// @ingroup cpp_kodi_gui_dialogs | ||
| 26 | /// @brief @cpp_namespace{ kodi::gui::dialogs::FileBrowser } | ||
| 27 | /// **File browser dialog**\n | ||
| 28 | /// The functions listed below of the class "FileBrowser" offer the possibility | ||
| 29 | /// to select to a file by the user of the add-on. | ||
| 30 | /// | ||
| 31 | /// It allows all the options that are possible in Kodi itself and offers all | ||
| 32 | /// support file types. | ||
| 33 | /// | ||
| 34 | /// It has the header @ref FileBrowser.h "#include <kodi/gui/dialogs/FileBrowser.h>" | ||
| 35 | /// be included to enjoy it. | ||
| 36 | /// | ||
| 37 | namespace FileBrowser | ||
| 38 | { | ||
| 39 | //============================================================================== | ||
| 40 | /// @ingroup cpp_kodi_gui_dialogs_FileBrowser | ||
| 41 | /// @brief Directory selection dialog. | ||
| 42 | /// | ||
| 43 | /// @param[in] shares With Shares becomes the available start folders be set | ||
| 44 | /// @param[in] heading Dialog header name | ||
| 45 | /// @param[in,out] path As in the path to start and return value about | ||
| 46 | /// selected directory | ||
| 47 | /// @param[in] writeOnly [opt] If set only writeable folders are shown | ||
| 48 | /// @return False if selection becomes canceled | ||
| 49 | /// | ||
| 50 | /// **Example:** | ||
| 51 | /// ~~~~~~~~~~~~~{.cpp} | ||
| 52 | /// #include <kodi/gui/dialogs/FileBrowser.h> | ||
| 53 | /// | ||
| 54 | /// // Example show directory selection dialog with on 'share' (first value) | ||
| 55 | /// // defined directory types. | ||
| 56 | /// // | ||
| 57 | /// // If this becomes leaved empty and 'directory' is empty goes it to the | ||
| 58 | /// // base path of the hard disk. | ||
| 59 | /// // | ||
| 60 | /// // Also can be with path written to 'directory' before the dialog forced | ||
| 61 | /// // to a start place. | ||
| 62 | /// std::string directory; | ||
| 63 | /// bool ret = kodi::gui::dialogs::FileBrowser::ShowAndGetDirectory("local|network|removable", | ||
| 64 | /// "Test directory selection", | ||
| 65 | /// directory, | ||
| 66 | /// false); | ||
| 67 | /// fprintf(stderr, "Selected directory is : %s and was %s\n", directory.c_str(), ret ? "OK" : "Canceled"); | ||
| 68 | /// ~~~~~~~~~~~~~ | ||
| 69 | /// | ||
| 70 | inline bool ATTRIBUTE_HIDDEN ShowAndGetDirectory(const std::string& shares, | ||
| 71 | const std::string& heading, | ||
| 72 | std::string& path, | ||
| 73 | bool writeOnly = false) | ||
| 74 | { | ||
| 75 | using namespace ::kodi::addon; | ||
| 76 | char* retString = nullptr; | ||
| 77 | bool ret = CAddonBase::m_interface->toKodi->kodi_gui->dialogFileBrowser->show_and_get_directory( | ||
| 78 | CAddonBase::m_interface->toKodi->kodiBase, shares.c_str(), heading.c_str(), path.c_str(), | ||
| 79 | &retString, writeOnly); | ||
| 80 | if (retString != nullptr) | ||
| 81 | { | ||
| 82 | if (std::strlen(retString)) | ||
| 83 | path = retString; | ||
| 84 | CAddonBase::m_interface->toKodi->free_string(CAddonBase::m_interface->toKodi->kodiBase, | ||
| 85 | retString); | ||
| 86 | } | ||
| 87 | return ret; | ||
| 88 | } | ||
| 89 | //------------------------------------------------------------------------------ | ||
| 90 | |||
| 91 | //============================================================================== | ||
| 92 | /// @ingroup cpp_kodi_gui_dialogs_FileBrowser | ||
| 93 | /// @brief File selection dialog. | ||
| 94 | /// | ||
| 95 | /// @param[in] shares With Shares becomes the available start folders be set. | ||
| 96 | /// @param[in] mask The mask to filter visible files, e.g. ".m3u|.pls|.b4s|.wpl" | ||
| 97 | /// @param[in] heading Dialog header name | ||
| 98 | /// @param[in,out] path As in the path to start and Return value about selected | ||
| 99 | /// file | ||
| 100 | /// @param[in] useThumbs [opt] If set show thumbs if possible on dialog | ||
| 101 | /// @param[in] useFileDirectories [opt] If set also packages (e.g. *.zip) are | ||
| 102 | /// handled as directories. | ||
| 103 | /// @return False if selection becomes canceled | ||
| 104 | /// | ||
| 105 | inline bool ATTRIBUTE_HIDDEN ShowAndGetFile(const std::string& shares, | ||
| 106 | const std::string& mask, | ||
| 107 | const std::string& heading, | ||
| 108 | std::string& path, | ||
| 109 | bool useThumbs = false, | ||
| 110 | bool useFileDirectories = false) | ||
| 111 | { | ||
| 112 | using namespace ::kodi::addon; | ||
| 113 | char* retString = nullptr; | ||
| 114 | bool ret = CAddonBase::m_interface->toKodi->kodi_gui->dialogFileBrowser->show_and_get_file( | ||
| 115 | CAddonBase::m_interface->toKodi->kodiBase, shares.c_str(), mask.c_str(), heading.c_str(), | ||
| 116 | path.c_str(), &retString, useThumbs, useFileDirectories); | ||
| 117 | if (retString != nullptr) | ||
| 118 | { | ||
| 119 | if (std::strlen(retString)) | ||
| 120 | path = retString; | ||
| 121 | CAddonBase::m_interface->toKodi->free_string(CAddonBase::m_interface->toKodi->kodiBase, | ||
| 122 | retString); | ||
| 123 | } | ||
| 124 | return ret; | ||
| 125 | } | ||
| 126 | //------------------------------------------------------------------------------ | ||
| 127 | |||
| 128 | //============================================================================== | ||
| 129 | /// @ingroup cpp_kodi_gui_dialogs_FileBrowser | ||
| 130 | /// @brief File selection from a directory. | ||
| 131 | /// | ||
| 132 | /// @param[in] directory The directory name where the dialog start, possible are | ||
| 133 | /// normal names and kodi's special names | ||
| 134 | /// @param[in] mask The mask to filter visible files, e.g. ".m3u|.pls|.b4s|.wpl" | ||
| 135 | /// @param[in] heading Dialog header name | ||
| 136 | /// @param[in,out] path As in the path to start and Return value about selected | ||
| 137 | /// file | ||
| 138 | /// @param[in] useThumbs [opt] If set show thumbs if possible on dialog | ||
| 139 | /// @param[in] useFileDirectories [opt] If set also packages (e.g. *.zip) are | ||
| 140 | /// handled as directories | ||
| 141 | /// @param[in] singleList [opt] | ||
| 142 | /// @return False if selection becomes canceled | ||
| 143 | /// | ||
| 144 | inline bool ATTRIBUTE_HIDDEN ShowAndGetFileFromDir(const std::string& directory, | ||
| 145 | const std::string& mask, | ||
| 146 | const std::string& heading, | ||
| 147 | std::string& path, | ||
| 148 | bool useThumbs = false, | ||
| 149 | bool useFileDirectories = false, | ||
| 150 | bool singleList = false) | ||
| 151 | { | ||
| 152 | using namespace ::kodi::addon; | ||
| 153 | char* retString = nullptr; | ||
| 154 | bool ret = | ||
| 155 | CAddonBase::m_interface->toKodi->kodi_gui->dialogFileBrowser->show_and_get_file_from_dir( | ||
| 156 | CAddonBase::m_interface->toKodi->kodiBase, directory.c_str(), mask.c_str(), | ||
| 157 | heading.c_str(), path.c_str(), &retString, useThumbs, useFileDirectories, singleList); | ||
| 158 | if (retString != nullptr) | ||
| 159 | { | ||
| 160 | if (std::strlen(retString)) | ||
| 161 | path = retString; | ||
| 162 | CAddonBase::m_interface->toKodi->free_string(CAddonBase::m_interface->toKodi->kodiBase, | ||
| 163 | retString); | ||
| 164 | } | ||
| 165 | return ret; | ||
| 166 | } | ||
| 167 | //------------------------------------------------------------------------------ | ||
| 168 | |||
| 169 | //============================================================================== | ||
| 170 | /// @ingroup cpp_kodi_gui_dialogs_FileBrowser | ||
| 171 | /// @brief File selection dialog to get several in to a list. | ||
| 172 | /// | ||
| 173 | /// @param[in] shares With Shares becomes the available start folders be set. | ||
| 174 | /// @param[in] mask The mask to filter visible files, e.g. ".m3u|.pls|.b4s|.wpl" | ||
| 175 | /// @param[in] heading Dialog header name | ||
| 176 | /// @param[out] fileList Return value about selected files | ||
| 177 | /// @param[in] useThumbs [opt] If set show thumbs if possible on dialog. | ||
| 178 | /// @param[in] useFileDirectories [opt] If set also packages (e.g. *.zip) are | ||
| 179 | /// handled as directories. | ||
| 180 | /// @return False if selection becomes canceled. | ||
| 181 | /// | ||
| 182 | inline bool ATTRIBUTE_HIDDEN ShowAndGetFileList(const std::string& shares, | ||
| 183 | const std::string& mask, | ||
| 184 | const std::string& heading, | ||
| 185 | std::vector<std::string>& fileList, | ||
| 186 | bool useThumbs = false, | ||
| 187 | bool useFileDirectories = false) | ||
| 188 | { | ||
| 189 | using namespace ::kodi::addon; | ||
| 190 | char** list = nullptr; | ||
| 191 | unsigned int listSize = 0; | ||
| 192 | bool ret = CAddonBase::m_interface->toKodi->kodi_gui->dialogFileBrowser->show_and_get_file_list( | ||
| 193 | CAddonBase::m_interface->toKodi->kodiBase, shares.c_str(), mask.c_str(), heading.c_str(), | ||
| 194 | &list, &listSize, useThumbs, useFileDirectories); | ||
| 195 | if (ret) | ||
| 196 | { | ||
| 197 | for (unsigned int i = 0; i < listSize; ++i) | ||
| 198 | fileList.emplace_back(list[i]); | ||
| 199 | CAddonBase::m_interface->toKodi->kodi_gui->dialogFileBrowser->clear_file_list( | ||
| 200 | CAddonBase::m_interface->toKodi->kodiBase, &list, listSize); | ||
| 201 | } | ||
| 202 | return ret; | ||
| 203 | } | ||
| 204 | //------------------------------------------------------------------------------ | ||
| 205 | |||
| 206 | //============================================================================== | ||
| 207 | /// @ingroup cpp_kodi_gui_dialogs_FileBrowser | ||
| 208 | /// @brief Source selection dialog. | ||
| 209 | /// | ||
| 210 | /// @param[in,out] path As in the path to start and Return value about selected | ||
| 211 | /// source | ||
| 212 | /// @param[in] allowNetworkShares Allow also access to network | ||
| 213 | /// @param[in] additionalShare [opt] With additionalShare becomes the available | ||
| 214 | /// start folders be set. | ||
| 215 | /// @param[in] type [opt] | ||
| 216 | /// @return False if selection becomes canceled | ||
| 217 | /// | ||
| 218 | inline bool ATTRIBUTE_HIDDEN ShowAndGetSource(std::string& path, | ||
| 219 | bool allowNetworkShares, | ||
| 220 | const std::string& additionalShare = "", | ||
| 221 | const std::string& type = "") | ||
| 222 | { | ||
| 223 | using namespace ::kodi::addon; | ||
| 224 | char* retString = nullptr; | ||
| 225 | bool ret = CAddonBase::m_interface->toKodi->kodi_gui->dialogFileBrowser->show_and_get_source( | ||
| 226 | CAddonBase::m_interface->toKodi->kodiBase, path.c_str(), &retString, allowNetworkShares, | ||
| 227 | additionalShare.c_str(), type.c_str()); | ||
| 228 | if (retString != nullptr) | ||
| 229 | { | ||
| 230 | if (std::strlen(retString)) | ||
| 231 | path = retString; | ||
| 232 | CAddonBase::m_interface->toKodi->free_string(CAddonBase::m_interface->toKodi->kodiBase, | ||
| 233 | retString); | ||
| 234 | } | ||
| 235 | return ret; | ||
| 236 | } | ||
| 237 | //------------------------------------------------------------------------------ | ||
| 238 | |||
| 239 | //============================================================================== | ||
| 240 | /// @ingroup cpp_kodi_gui_dialogs_FileBrowser | ||
| 241 | /// @brief Image selection dialog. | ||
| 242 | /// | ||
| 243 | /// @param[in] shares With Shares becomes the available start folders be set | ||
| 244 | /// @param[in] heading Dialog header name | ||
| 245 | /// @param[out] path Return value about selected image | ||
| 246 | /// @return False if selection becomes canceled | ||
| 247 | /// | ||
| 248 | inline bool ATTRIBUTE_HIDDEN ShowAndGetImage(const std::string& shares, | ||
| 249 | const std::string& heading, | ||
| 250 | std::string& path) | ||
| 251 | { | ||
| 252 | using namespace ::kodi::addon; | ||
| 253 | char* retString = nullptr; | ||
| 254 | bool ret = CAddonBase::m_interface->toKodi->kodi_gui->dialogFileBrowser->show_and_get_image( | ||
| 255 | CAddonBase::m_interface->toKodi->kodiBase, shares.c_str(), heading.c_str(), path.c_str(), | ||
| 256 | &retString); | ||
| 257 | if (retString != nullptr) | ||
| 258 | { | ||
| 259 | if (std::strlen(retString)) | ||
| 260 | path = retString; | ||
| 261 | CAddonBase::m_interface->toKodi->free_string(CAddonBase::m_interface->toKodi->kodiBase, | ||
| 262 | retString); | ||
| 263 | } | ||
| 264 | return ret; | ||
| 265 | } | ||
| 266 | //------------------------------------------------------------------------------ | ||
| 267 | |||
| 268 | //============================================================================== | ||
| 269 | /// @ingroup cpp_kodi_gui_dialogs_FileBrowser | ||
| 270 | /// @brief Image selection dialog to get several in to a list. | ||
| 271 | /// | ||
| 272 | /// @param[in] shares With Shares becomes the available start folders be set | ||
| 273 | /// @param[in] heading Dialog header name | ||
| 274 | /// @param[out] file_list Return value about selected images | ||
| 275 | /// @return False if selection becomes canceled | ||
| 276 | /// | ||
| 277 | inline bool ATTRIBUTE_HIDDEN ShowAndGetImageList(const std::string& shares, | ||
| 278 | const std::string& heading, | ||
| 279 | std::vector<std::string>& file_list) | ||
| 280 | { | ||
| 281 | using namespace ::kodi::addon; | ||
| 282 | char** list = nullptr; | ||
| 283 | unsigned int listSize = 0; | ||
| 284 | bool ret = CAddonBase::m_interface->toKodi->kodi_gui->dialogFileBrowser->show_and_get_image_list( | ||
| 285 | CAddonBase::m_interface->toKodi->kodiBase, shares.c_str(), heading.c_str(), &list, &listSize); | ||
| 286 | if (ret) | ||
| 287 | { | ||
| 288 | for (unsigned int i = 0; i < listSize; ++i) | ||
| 289 | file_list.emplace_back(list[i]); | ||
| 290 | CAddonBase::m_interface->toKodi->kodi_gui->dialogFileBrowser->clear_file_list( | ||
| 291 | CAddonBase::m_interface->toKodi->kodiBase, &list, listSize); | ||
| 292 | } | ||
| 293 | return ret; | ||
| 294 | } | ||
| 295 | //------------------------------------------------------------------------------ | ||
| 296 | }; // namespace FileBrowser | ||
| 297 | |||
| 298 | } /* namespace dialogs */ | ||
| 299 | } /* namespace gui */ | ||
| 300 | } /* namespace kodi */ | ||
| 301 | |||
| 302 | #endif /* __cplusplus */ | ||
diff --git a/xbmc/addons/kodi-dev-kit/include/kodi/gui/dialogs/Keyboard.h b/xbmc/addons/kodi-dev-kit/include/kodi/gui/dialogs/Keyboard.h new file mode 100644 index 0000000..710b7dd --- /dev/null +++ b/xbmc/addons/kodi-dev-kit/include/kodi/gui/dialogs/Keyboard.h | |||
| @@ -0,0 +1,404 @@ | |||
| 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 "../../AddonBase.h" | ||
| 12 | #include "../../c-api/gui/dialogs/keyboard.h" | ||
| 13 | |||
| 14 | #ifdef __cplusplus | ||
| 15 | |||
| 16 | namespace kodi | ||
| 17 | { | ||
| 18 | namespace gui | ||
| 19 | { | ||
| 20 | namespace dialogs | ||
| 21 | { | ||
| 22 | |||
| 23 | //================================================================================ | ||
| 24 | /// @defgroup cpp_kodi_gui_dialogs_Keyboard Dialog Keyboard | ||
| 25 | /// @ingroup cpp_kodi_gui_dialogs | ||
| 26 | /// @brief @cpp_namespace{ kodi::gui::dialogs::Keyboard } | ||
| 27 | /// **Keyboard dialogs**\n | ||
| 28 | /// The functions listed below have to be permitted by the user for the | ||
| 29 | /// representation of a keyboard around an input. | ||
| 30 | /// | ||
| 31 | /// The class supports several kinds, from an easy text choice up to the | ||
| 32 | /// passport Word production and their confirmation for add-on. | ||
| 33 | /// | ||
| 34 | /// It has the header @ref Keyboard.h "#include <kodi/gui/dialogs/Keyboard.h>" | ||
| 35 | /// be included to enjoy it. | ||
| 36 | /// | ||
| 37 | namespace Keyboard | ||
| 38 | { | ||
| 39 | //============================================================================== | ||
| 40 | /// @ingroup cpp_kodi_gui_dialogs_Keyboard | ||
| 41 | /// @brief Show keyboard with initial value `text` and replace with result | ||
| 42 | /// string. | ||
| 43 | /// | ||
| 44 | /// @param[in,out] text Overwritten with user input if return=true. | ||
| 45 | /// @param[in] heading String shown on dialog title. | ||
| 46 | /// @param[in] allowEmptyResult Whether a blank password is valid or not. | ||
| 47 | /// @param[in] hiddenInput [opt] The inserted input is not shown as text. | ||
| 48 | /// @param[in] autoCloseMs [opt] To close the dialog after a specified time, in | ||
| 49 | /// milliseconds, default is 0 which keeps the dialog | ||
| 50 | /// open indefinitely. | ||
| 51 | /// @return true if successful display and user input. false if unsuccessful | ||
| 52 | /// display, no user input, or canceled editing. | ||
| 53 | /// | ||
| 54 | /// | ||
| 55 | ///------------------------------------------------------------------------- | ||
| 56 | /// | ||
| 57 | /// **Example:** | ||
| 58 | /// ~~~~~~~~~~~~~{.cpp} | ||
| 59 | /// #include <kodi/gui/dialogs/Keyboard.h> | ||
| 60 | /// | ||
| 61 | /// // The example shows the display of keyboard call dialog at Kodi from the add-on. | ||
| 62 | /// // Below all values are set, however, can last two (hidden input = false and autoCloseMs = 0) | ||
| 63 | /// // to be released if not needed. | ||
| 64 | /// std::string text = "Please change me to them want you want"; // It can be leaved empty or a entry text added | ||
| 65 | /// bool bRet = ::kodi::gui::dialogs::Keyboard::ShowAndGetInput(text, | ||
| 66 | /// "Demonstration text entry", | ||
| 67 | /// true, | ||
| 68 | /// false, | ||
| 69 | /// 0); | ||
| 70 | /// fprintf(stderr, "Written keyboard input is : '%s' and was %s\n", | ||
| 71 | /// text.c_str(), bRet ? "OK" : "Canceled"); | ||
| 72 | /// ~~~~~~~~~~~~~ | ||
| 73 | /// | ||
| 74 | inline bool ATTRIBUTE_HIDDEN ShowAndGetInput(std::string& text, | ||
| 75 | const std::string& heading, | ||
| 76 | bool allowEmptyResult, | ||
| 77 | bool hiddenInput = false, | ||
| 78 | unsigned int autoCloseMs = 0) | ||
| 79 | { | ||
| 80 | using namespace ::kodi::addon; | ||
| 81 | char* retString = nullptr; | ||
| 82 | bool ret = | ||
| 83 | CAddonBase::m_interface->toKodi->kodi_gui->dialogKeyboard->show_and_get_input_with_head( | ||
| 84 | CAddonBase::m_interface->toKodi->kodiBase, text.c_str(), &retString, heading.c_str(), | ||
| 85 | allowEmptyResult, hiddenInput, autoCloseMs); | ||
| 86 | if (retString != nullptr) | ||
| 87 | { | ||
| 88 | text = retString; | ||
| 89 | CAddonBase::m_interface->toKodi->free_string(CAddonBase::m_interface->toKodi->kodiBase, | ||
| 90 | retString); | ||
| 91 | } | ||
| 92 | return ret; | ||
| 93 | } | ||
| 94 | //------------------------------------------------------------------------------ | ||
| 95 | |||
| 96 | //============================================================================== | ||
| 97 | /// @ingroup cpp_kodi_gui_dialogs_Keyboard | ||
| 98 | /// @brief The example shows the display of keyboard call dialog at Kodi | ||
| 99 | /// from the add-on. | ||
| 100 | /// | ||
| 101 | /// @param[out] text Overwritten with user input if return=true. | ||
| 102 | /// @param[in] allowEmptyResult If set to true keyboard can also exited without | ||
| 103 | /// entered text. | ||
| 104 | /// @param[in] autoCloseMs [opt] To close the dialog after a specified time, in | ||
| 105 | /// milliseconds, default is 0 which keeps the dialog | ||
| 106 | /// open indefinitely. | ||
| 107 | /// @return true if successful display and user input. false if unsuccessful | ||
| 108 | /// display, no user input, or canceled editing. | ||
| 109 | /// | ||
| 110 | inline bool ATTRIBUTE_HIDDEN ShowAndGetInput(std::string& text, | ||
| 111 | bool allowEmptyResult, | ||
| 112 | unsigned int autoCloseMs = 0) | ||
| 113 | { | ||
| 114 | using namespace ::kodi::addon; | ||
| 115 | char* retString = nullptr; | ||
| 116 | bool ret = CAddonBase::m_interface->toKodi->kodi_gui->dialogKeyboard->show_and_get_input( | ||
| 117 | CAddonBase::m_interface->toKodi->kodiBase, text.c_str(), &retString, allowEmptyResult, | ||
| 118 | autoCloseMs); | ||
| 119 | if (retString != nullptr) | ||
| 120 | { | ||
| 121 | text = retString; | ||
| 122 | CAddonBase::m_interface->toKodi->free_string(CAddonBase::m_interface->toKodi->kodiBase, | ||
| 123 | retString); | ||
| 124 | } | ||
| 125 | return ret; | ||
| 126 | } | ||
| 127 | //------------------------------------------------------------------------------ | ||
| 128 | |||
| 129 | //============================================================================== | ||
| 130 | /// @ingroup cpp_kodi_gui_dialogs_Keyboard | ||
| 131 | /// @brief Shows keyboard and prompts for a password. Differs from | ||
| 132 | /// `ShowAndVerifyNewPassword()` in that no second verification. | ||
| 133 | /// | ||
| 134 | /// @param[in,out] newPassword Overwritten with user input if return=true. | ||
| 135 | /// @param[in] heading String shown on dialog title. | ||
| 136 | /// @param[in] allowEmptyResult Whether a blank password is valid or not. | ||
| 137 | /// @param[in] autoCloseMs [opt] To close the dialog after a specified time, in | ||
| 138 | /// milliseconds, default is 0 which keeps the dialog | ||
| 139 | /// open indefinitely. | ||
| 140 | /// @return true if successful display and user input. false if unsuccessful | ||
| 141 | /// display, no user input, or canceled editing. | ||
| 142 | /// | ||
| 143 | inline bool ATTRIBUTE_HIDDEN ShowAndGetNewPassword(std::string& newPassword, | ||
| 144 | const std::string& heading, | ||
| 145 | bool allowEmptyResult, | ||
| 146 | unsigned int autoCloseMs = 0) | ||
| 147 | { | ||
| 148 | using namespace ::kodi::addon; | ||
| 149 | char* retString = nullptr; | ||
| 150 | bool ret = CAddonBase::m_interface->toKodi->kodi_gui->dialogKeyboard | ||
| 151 | ->show_and_get_new_password_with_head( | ||
| 152 | CAddonBase::m_interface->toKodi->kodiBase, newPassword.c_str(), &retString, | ||
| 153 | heading.c_str(), allowEmptyResult, autoCloseMs); | ||
| 154 | if (retString != nullptr) | ||
| 155 | { | ||
| 156 | newPassword = retString; | ||
| 157 | CAddonBase::m_interface->toKodi->free_string(CAddonBase::m_interface->toKodi->kodiBase, | ||
| 158 | retString); | ||
| 159 | } | ||
| 160 | return ret; | ||
| 161 | } | ||
| 162 | //------------------------------------------------------------------------------ | ||
| 163 | |||
| 164 | //============================================================================== | ||
| 165 | /// @ingroup cpp_kodi_gui_dialogs_Keyboard | ||
| 166 | /// @brief Shows keyboard and prompts for a password. Differs from | ||
| 167 | /// `ShowAndVerifyNewPassword()` in that no second verification. | ||
| 168 | /// | ||
| 169 | /// @param[in,out] newPassword Overwritten with user input if return=true. | ||
| 170 | /// @param[in] autoCloseMs [opt] To close the dialog after a specified time, in | ||
| 171 | /// milliseconds, default is 0 which keeps the dialog | ||
| 172 | /// open indefinitely. | ||
| 173 | /// @return true if successful display and user input. false if unsuccessful | ||
| 174 | /// display, no user input, or canceled editing. | ||
| 175 | /// | ||
| 176 | inline bool ATTRIBUTE_HIDDEN ShowAndGetNewPassword(std::string& newPassword, | ||
| 177 | unsigned int autoCloseMs = 0) | ||
| 178 | { | ||
| 179 | using namespace ::kodi::addon; | ||
| 180 | char* retString = nullptr; | ||
| 181 | bool ret = CAddonBase::m_interface->toKodi->kodi_gui->dialogKeyboard->show_and_get_new_password( | ||
| 182 | CAddonBase::m_interface->toKodi->kodiBase, newPassword.c_str(), &retString, autoCloseMs); | ||
| 183 | if (retString != nullptr) | ||
| 184 | { | ||
| 185 | newPassword = retString; | ||
| 186 | CAddonBase::m_interface->toKodi->free_string(CAddonBase::m_interface->toKodi->kodiBase, | ||
| 187 | retString); | ||
| 188 | } | ||
| 189 | return ret; | ||
| 190 | } | ||
| 191 | //------------------------------------------------------------------------------ | ||
| 192 | |||
| 193 | //============================================================================== | ||
| 194 | /// @ingroup cpp_kodi_gui_dialogs_Keyboard | ||
| 195 | /// @brief Show keyboard twice to get and confirm a user-entered password | ||
| 196 | /// string. | ||
| 197 | /// | ||
| 198 | /// @param[out] newPassword Overwritten with user input if return=true. | ||
| 199 | /// @param[in] heading String shown on dialog title. | ||
| 200 | /// @param[in] allowEmptyResult | ||
| 201 | /// @param[in] autoCloseMs [opt] To close the dialog after a specified time, in | ||
| 202 | /// milliseconds, default is 0 which keeps the dialog | ||
| 203 | /// open indefinitely. | ||
| 204 | /// @return true if successful display and user input. false if unsuccessful | ||
| 205 | /// display, no user input, or canceled editing. | ||
| 206 | /// | ||
| 207 | /// | ||
| 208 | ///------------------------------------------------------------------------- | ||
| 209 | /// | ||
| 210 | /// **Example:** | ||
| 211 | /// ~~~~~~~~~~~~~{.cpp} | ||
| 212 | /// #include <kodi/General.h> | ||
| 213 | /// #include <kodi/gui/dialogs/Keyboard.h> | ||
| 214 | /// | ||
| 215 | /// // The example below shows the complete use of keyboard dialog for password | ||
| 216 | /// // check. If only one check from add-on needed can be function with retries | ||
| 217 | /// // set to '0' called alone. | ||
| 218 | /// // | ||
| 219 | /// // The use of MD5 translated password is always required for the check on Kodi! | ||
| 220 | /// | ||
| 221 | /// int maxretries = 3; | ||
| 222 | /// // Password names need to be send as md5 sum to kodi. | ||
| 223 | /// std::string password; | ||
| 224 | /// kodi::GetMD5("kodi", password); | ||
| 225 | /// | ||
| 226 | /// // To the loop about password checks. | ||
| 227 | /// int ret; | ||
| 228 | /// for (unsigned int i = 0; i < maxretries; i++) | ||
| 229 | /// { | ||
| 230 | /// // Ask the user about the password. | ||
| 231 | /// ret = ::kodi::gui::dialogs::Keyboard::ShowAndVerifyPassword(password, "Demo password call for PW 'kodi'", i, 0); | ||
| 232 | /// if (ret == 0) | ||
| 233 | /// { | ||
| 234 | /// fprintf(stderr, "Password successfull confirmed after '%i' tries\n", i+1); | ||
| 235 | /// break; | ||
| 236 | /// } | ||
| 237 | /// else if (ret < 0) | ||
| 238 | /// { | ||
| 239 | /// fprintf(stderr, "Canceled editing on try '%i'\n", i+1); | ||
| 240 | /// break; | ||
| 241 | /// } | ||
| 242 | /// else // if (ret > 0) | ||
| 243 | /// { | ||
| 244 | /// fprintf(stderr, "Wrong password entered on try '%i'\n", i+1); | ||
| 245 | /// } | ||
| 246 | /// } | ||
| 247 | /// ~~~~~~~~~~~~~ | ||
| 248 | /// | ||
| 249 | inline bool ATTRIBUTE_HIDDEN ShowAndVerifyNewPassword(std::string& newPassword, | ||
| 250 | const std::string& heading, | ||
| 251 | bool allowEmptyResult, | ||
| 252 | unsigned int autoCloseMs = 0) | ||
| 253 | { | ||
| 254 | using namespace ::kodi::addon; | ||
| 255 | char* retString = nullptr; | ||
| 256 | bool ret = CAddonBase::m_interface->toKodi->kodi_gui->dialogKeyboard | ||
| 257 | ->show_and_verify_new_password_with_head(CAddonBase::m_interface->toKodi->kodiBase, | ||
| 258 | &retString, heading.c_str(), | ||
| 259 | allowEmptyResult, autoCloseMs); | ||
| 260 | if (retString != nullptr) | ||
| 261 | { | ||
| 262 | newPassword = retString; | ||
| 263 | CAddonBase::m_interface->toKodi->free_string(CAddonBase::m_interface->toKodi->kodiBase, | ||
| 264 | retString); | ||
| 265 | } | ||
| 266 | return ret; | ||
| 267 | } | ||
| 268 | //------------------------------------------------------------------------------ | ||
| 269 | |||
| 270 | //============================================================================== | ||
| 271 | /// @ingroup cpp_kodi_gui_dialogs_Keyboard | ||
| 272 | /// @brief Show keyboard twice to get and confirm a user-entered password | ||
| 273 | /// string. | ||
| 274 | /// | ||
| 275 | /// @param[out] newPassword Overwritten with user input if return=true. | ||
| 276 | /// @param[in] autoCloseMs [opt] To close the dialog after a specified time, in | ||
| 277 | /// milliseconds, default is 0 which keeps the dialog | ||
| 278 | /// open indefinitely. | ||
| 279 | /// @return true if successful display and user input. false if unsuccessful | ||
| 280 | /// display, no user input, or canceled editing. | ||
| 281 | /// | ||
| 282 | inline bool ATTRIBUTE_HIDDEN ShowAndVerifyNewPassword(std::string& newPassword, | ||
| 283 | unsigned int autoCloseMs = 0) | ||
| 284 | { | ||
| 285 | using namespace ::kodi::addon; | ||
| 286 | char* retString = nullptr; | ||
| 287 | bool ret = | ||
| 288 | CAddonBase::m_interface->toKodi->kodi_gui->dialogKeyboard->show_and_verify_new_password( | ||
| 289 | CAddonBase::m_interface->toKodi->kodiBase, &retString, autoCloseMs); | ||
| 290 | if (retString != nullptr) | ||
| 291 | { | ||
| 292 | newPassword = retString; | ||
| 293 | CAddonBase::m_interface->toKodi->free_string(CAddonBase::m_interface->toKodi->kodiBase, | ||
| 294 | retString); | ||
| 295 | } | ||
| 296 | return ret; | ||
| 297 | } | ||
| 298 | //------------------------------------------------------------------------------ | ||
| 299 | |||
| 300 | //============================================================================== | ||
| 301 | /// @ingroup cpp_kodi_gui_dialogs_Keyboard | ||
| 302 | /// @brief Show keyboard and verify user input against `password`. | ||
| 303 | /// | ||
| 304 | /// @param[in,out] password Value to compare against user input. | ||
| 305 | /// @param[in] heading String shown on dialog title. | ||
| 306 | /// @param[in] retries If greater than 0, shows "Incorrect password, %d retries | ||
| 307 | /// left" on dialog line 2, else line 2 is blank. | ||
| 308 | /// @param[in] autoCloseMs [opt] To close the dialog after a specified time, in | ||
| 309 | /// milliseconds, default is 0 which keeps the dialog | ||
| 310 | /// open indefinitely. | ||
| 311 | /// @return 0 if successful display and user input. 1 if unsuccessful input. | ||
| 312 | /// -1 if no user input or canceled editing. | ||
| 313 | /// | ||
| 314 | inline int ATTRIBUTE_HIDDEN ShowAndVerifyPassword(std::string& password, | ||
| 315 | const std::string& heading, | ||
| 316 | int retries, | ||
| 317 | unsigned int autoCloseMs = 0) | ||
| 318 | { | ||
| 319 | using namespace ::kodi::addon; | ||
| 320 | char* retString = nullptr; | ||
| 321 | int ret = CAddonBase::m_interface->toKodi->kodi_gui->dialogKeyboard->show_and_verify_password( | ||
| 322 | CAddonBase::m_interface->toKodi->kodiBase, password.c_str(), &retString, heading.c_str(), | ||
| 323 | retries, autoCloseMs); | ||
| 324 | if (retString != nullptr) | ||
| 325 | { | ||
| 326 | password = retString; | ||
| 327 | CAddonBase::m_interface->toKodi->free_string(CAddonBase::m_interface->toKodi->kodiBase, | ||
| 328 | retString); | ||
| 329 | } | ||
| 330 | return ret; | ||
| 331 | } | ||
| 332 | //------------------------------------------------------------------------------ | ||
| 333 | |||
| 334 | //============================================================================== | ||
| 335 | /// @ingroup cpp_kodi_gui_dialogs_Keyboard | ||
| 336 | /// @brief Shows a filter related keyboard. | ||
| 337 | /// | ||
| 338 | /// @param[in,out] text Overwritten with user input if return=true. | ||
| 339 | /// @param[in] searching Use dialog for search and send our search message in | ||
| 340 | /// safe way (only the active window needs it) | ||
| 341 | /// - header name if true is "Enter search string" | ||
| 342 | /// - header name if false is "Enter value" | ||
| 343 | /// @param autoCloseMs [opt] To close the dialog after a specified time, in | ||
| 344 | /// milliseconds, default is 0 which keeps the dialog open | ||
| 345 | /// indefinitely. | ||
| 346 | /// @return true if successful display and user input. false if unsuccessful | ||
| 347 | /// display, no user input, or canceled editing. | ||
| 348 | /// | ||
| 349 | inline bool ATTRIBUTE_HIDDEN ShowAndGetFilter(std::string& text, | ||
| 350 | bool searching, | ||
| 351 | unsigned int autoCloseMs = 0) | ||
| 352 | { | ||
| 353 | using namespace ::kodi::addon; | ||
| 354 | char* retString = nullptr; | ||
| 355 | bool ret = CAddonBase::m_interface->toKodi->kodi_gui->dialogKeyboard->show_and_get_filter( | ||
| 356 | CAddonBase::m_interface->toKodi->kodiBase, text.c_str(), &retString, searching, autoCloseMs); | ||
| 357 | if (retString != nullptr) | ||
| 358 | { | ||
| 359 | text = retString; | ||
| 360 | CAddonBase::m_interface->toKodi->free_string(CAddonBase::m_interface->toKodi->kodiBase, | ||
| 361 | retString); | ||
| 362 | } | ||
| 363 | return ret; | ||
| 364 | } | ||
| 365 | //------------------------------------------------------------------------------ | ||
| 366 | |||
| 367 | //============================================================================== | ||
| 368 | /// @ingroup cpp_kodi_gui_dialogs_Keyboard | ||
| 369 | /// @brief Send a text to a visible keyboard. | ||
| 370 | /// | ||
| 371 | /// @param[in] text Overwritten with user input if return=true. | ||
| 372 | /// @param[in] closeKeyboard [opt] The open dialog is if also closed on 'true'. | ||
| 373 | /// @return true if successful done, false if unsuccessful or keyboard not | ||
| 374 | /// present. | ||
| 375 | /// | ||
| 376 | inline bool ATTRIBUTE_HIDDEN SendTextToActiveKeyboard(const std::string& text, | ||
| 377 | bool closeKeyboard = false) | ||
| 378 | { | ||
| 379 | using namespace ::kodi::addon; | ||
| 380 | return CAddonBase::m_interface->toKodi->kodi_gui->dialogKeyboard->send_text_to_active_keyboard( | ||
| 381 | CAddonBase::m_interface->toKodi->kodiBase, text.c_str(), closeKeyboard); | ||
| 382 | } | ||
| 383 | //------------------------------------------------------------------------------ | ||
| 384 | |||
| 385 | //============================================================================== | ||
| 386 | /// @ingroup cpp_kodi_gui_dialogs_Keyboard | ||
| 387 | /// @brief Check for visible keyboard on GUI. | ||
| 388 | /// | ||
| 389 | /// @return true if keyboard present, false if not present | ||
| 390 | /// | ||
| 391 | inline bool ATTRIBUTE_HIDDEN IsKeyboardActivated() | ||
| 392 | { | ||
| 393 | using namespace ::kodi::addon; | ||
| 394 | return CAddonBase::m_interface->toKodi->kodi_gui->dialogKeyboard->is_keyboard_activated( | ||
| 395 | CAddonBase::m_interface->toKodi->kodiBase); | ||
| 396 | } | ||
| 397 | //------------------------------------------------------------------------------ | ||
| 398 | }; // namespace Keyboard | ||
| 399 | |||
| 400 | } /* namespace dialogs */ | ||
| 401 | } /* namespace gui */ | ||
| 402 | } /* namespace kodi */ | ||
| 403 | |||
| 404 | #endif /* __cplusplus */ | ||
diff --git a/xbmc/addons/kodi-dev-kit/include/kodi/gui/dialogs/Numeric.h b/xbmc/addons/kodi-dev-kit/include/kodi/gui/dialogs/Numeric.h new file mode 100644 index 0000000..835a8d4 --- /dev/null +++ b/xbmc/addons/kodi-dev-kit/include/kodi/gui/dialogs/Numeric.h | |||
| @@ -0,0 +1,346 @@ | |||
| 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 "../../AddonBase.h" | ||
| 12 | #include "../../c-api/gui/dialogs/numeric.h" | ||
| 13 | |||
| 14 | #ifdef __cplusplus | ||
| 15 | |||
| 16 | namespace kodi | ||
| 17 | { | ||
| 18 | namespace gui | ||
| 19 | { | ||
| 20 | namespace dialogs | ||
| 21 | { | ||
| 22 | |||
| 23 | //============================================================================== | ||
| 24 | /// @defgroup cpp_kodi_gui_dialogs_Numeric Dialog Numeric | ||
| 25 | /// @ingroup cpp_kodi_gui_dialogs | ||
| 26 | /// @{ | ||
| 27 | /// @brief @cpp_namespace{ kodi::gui::dialogs::Numeric } | ||
| 28 | /// **Numeric dialogs**\n | ||
| 29 | /// The functions listed below have to be permitted by the user for the | ||
| 30 | /// representation of a numeric keyboard around an input. | ||
| 31 | /// | ||
| 32 | /// The class supports several kinds, from an easy number choice up to the | ||
| 33 | /// passport Word production and their confirmation for add-on. | ||
| 34 | /// | ||
| 35 | /// It has the header @ref Numeric.h "#include <kodi/gui/dialogs/Numeric.h>" | ||
| 36 | /// be included to enjoy it. | ||
| 37 | /// | ||
| 38 | namespace Numeric | ||
| 39 | { | ||
| 40 | //============================================================================== | ||
| 41 | /// @ingroup cpp_kodi_gui_dialogs_Numeric | ||
| 42 | /// @brief Use dialog to get numeric new password | ||
| 43 | /// | ||
| 44 | /// @param[out] newPassword String to preload into the keyboard accumulator. | ||
| 45 | /// Overwritten with user input if return=true. | ||
| 46 | /// Returned in MD5 format. | ||
| 47 | /// @return true if successful display and user input entry/re-entry. false if | ||
| 48 | /// unsuccessful display, no user input, or canceled editing. | ||
| 49 | /// | ||
| 50 | inline bool ATTRIBUTE_HIDDEN ShowAndVerifyNewPassword(std::string& newPassword) | ||
| 51 | { | ||
| 52 | using namespace ::kodi::addon; | ||
| 53 | char* pw = nullptr; | ||
| 54 | bool ret = CAddonBase::m_interface->toKodi->kodi_gui->dialogNumeric->show_and_verify_new_password( | ||
| 55 | CAddonBase::m_interface->toKodi->kodiBase, &pw); | ||
| 56 | if (pw != nullptr) | ||
| 57 | { | ||
| 58 | newPassword = pw; | ||
| 59 | CAddonBase::m_interface->toKodi->free_string(CAddonBase::m_interface->toKodi->kodiBase, pw); | ||
| 60 | } | ||
| 61 | return ret; | ||
| 62 | } | ||
| 63 | //------------------------------------------------------------------------------ | ||
| 64 | |||
| 65 | //============================================================================== | ||
| 66 | /// | ||
| 67 | /// @ingroup cpp_kodi_gui_dialogs_Numeric | ||
| 68 | /// @brief Use dialog to verify numeric password. | ||
| 69 | /// | ||
| 70 | /// @param[in] password Password to compare with user input, need | ||
| 71 | /// in MD5 format. | ||
| 72 | /// @param[in] heading Heading to display | ||
| 73 | /// @param[in] retries If greater than 0, shows "Incorrect | ||
| 74 | /// password, %d retries left" on dialog | ||
| 75 | /// line 2, else line 2 is blank. | ||
| 76 | /// @return Possible values: | ||
| 77 | /// - 0 if successful display and user input. | ||
| 78 | /// - 1 if unsuccessful input. | ||
| 79 | /// - -1 if no user input or canceled editing. | ||
| 80 | /// | ||
| 81 | /// | ||
| 82 | ///------------------------------------------------------------------------- | ||
| 83 | /// | ||
| 84 | /// **Example:** | ||
| 85 | /// ~~~~~~~~~~~~~{.cpp} | ||
| 86 | /// #include <stdio.h> // fprintf | ||
| 87 | /// #include <kodi/General.h> | ||
| 88 | /// #include <kodi/gui/dialogs/Numeric.h> | ||
| 89 | /// | ||
| 90 | /// // The example below shows the complete use of keyboard dialog for password | ||
| 91 | /// // check. If only one check from add-on needed can be function with retries | ||
| 92 | /// // set to '0' called alone. | ||
| 93 | /// // | ||
| 94 | /// // The use of MD5 translated password is always required for the check on Kodi! | ||
| 95 | /// | ||
| 96 | /// int maxretries = 3; | ||
| 97 | /// | ||
| 98 | /// // Password names need to be send as md5 sum to kodi. | ||
| 99 | /// std::string password = kodi::GetMD5("1234"); | ||
| 100 | /// | ||
| 101 | /// // To the loop about password checks. | ||
| 102 | /// int ret; | ||
| 103 | /// for (unsigned int i = 0; i < maxretries; i++) | ||
| 104 | /// { | ||
| 105 | /// // Ask the user about the password. | ||
| 106 | /// ret = kodi::gui::dialogs::Numeric::ShowAndVerifyPassword(password, "Demo numeric password call for PW '1234'", i); | ||
| 107 | /// if (ret == 0) | ||
| 108 | /// { | ||
| 109 | /// fprintf(stderr, "Numeric password successfull confirmed after '%i' tries\n", i+1); | ||
| 110 | /// break; | ||
| 111 | /// } | ||
| 112 | /// else if (ret < 0) | ||
| 113 | /// { | ||
| 114 | /// fprintf(stderr, "Canceled editing on try '%i'\n", i+1); | ||
| 115 | /// break; | ||
| 116 | /// } | ||
| 117 | /// else // if (ret > 0) | ||
| 118 | /// { | ||
| 119 | /// fprintf(stderr, "Wrong numeric password entered on try '%i'\n", i+1); | ||
| 120 | /// } | ||
| 121 | /// } | ||
| 122 | /// ~~~~~~~~~~~~~ | ||
| 123 | /// | ||
| 124 | inline int ATTRIBUTE_HIDDEN ShowAndVerifyPassword(const std::string& password, | ||
| 125 | const std::string& heading, | ||
| 126 | int retries) | ||
| 127 | { | ||
| 128 | using namespace ::kodi::addon; | ||
| 129 | return CAddonBase::m_interface->toKodi->kodi_gui->dialogNumeric->show_and_verify_password( | ||
| 130 | CAddonBase::m_interface->toKodi->kodiBase, password.c_str(), heading.c_str(), retries); | ||
| 131 | } | ||
| 132 | //------------------------------------------------------------------------------ | ||
| 133 | |||
| 134 | //============================================================================== | ||
| 135 | /// @ingroup cpp_kodi_gui_dialogs_Numeric | ||
| 136 | /// @brief Use dialog to verify numeric password | ||
| 137 | /// | ||
| 138 | /// @param[in,out] toVerify Value to compare against user input. | ||
| 139 | /// @param[in] heading Heading to display | ||
| 140 | /// @param[in] verifyInput If set as true we verify the users input versus | ||
| 141 | /// toVerify. | ||
| 142 | /// @return true if successful display and user input. false if unsuccessful | ||
| 143 | /// display, no user input, or canceled editing. | ||
| 144 | /// | ||
| 145 | inline bool ATTRIBUTE_HIDDEN ShowAndVerifyInput(std::string& toVerify, | ||
| 146 | const std::string& heading, | ||
| 147 | bool verifyInput) | ||
| 148 | { | ||
| 149 | using namespace ::kodi::addon; | ||
| 150 | char* retString = nullptr; | ||
| 151 | bool ret = CAddonBase::m_interface->toKodi->kodi_gui->dialogNumeric->show_and_verify_input( | ||
| 152 | CAddonBase::m_interface->toKodi->kodiBase, toVerify.c_str(), &retString, heading.c_str(), | ||
| 153 | verifyInput); | ||
| 154 | if (retString != nullptr) | ||
| 155 | { | ||
| 156 | toVerify = retString; | ||
| 157 | CAddonBase::m_interface->toKodi->free_string(CAddonBase::m_interface->toKodi->kodiBase, | ||
| 158 | retString); | ||
| 159 | } | ||
| 160 | return ret; | ||
| 161 | } | ||
| 162 | //------------------------------------------------------------------------------ | ||
| 163 | |||
| 164 | //============================================================================== | ||
| 165 | /// @ingroup cpp_kodi_gui_dialogs_Numeric | ||
| 166 | /// @brief Use dialog to get time value. | ||
| 167 | /// | ||
| 168 | /// @param[out] time Overwritten with user input if return=true and time | ||
| 169 | /// inserted. | ||
| 170 | /// @param[in] heading Heading to display. | ||
| 171 | /// @return true if successful display and user input. false if unsuccessful | ||
| 172 | /// display, no user input, or canceled editing. | ||
| 173 | /// | ||
| 174 | /// | ||
| 175 | ///------------------------------------------------------------------------- | ||
| 176 | /// | ||
| 177 | /// **Example:** | ||
| 178 | /// ~~~~~~~~~~~~~{.cpp} | ||
| 179 | /// #include <stdio.h> // printf | ||
| 180 | /// #include <time.h> // time_t, struct tm, time, localtime, strftime | ||
| 181 | /// #include <kodi/gui/dialogs/Numeric.h> | ||
| 182 | /// | ||
| 183 | /// time_t rawtime; | ||
| 184 | /// struct tm * timeinfo; | ||
| 185 | /// char buffer [10]; | ||
| 186 | /// | ||
| 187 | /// time (&rawtime); | ||
| 188 | /// timeinfo = localtime(&rawtime); | ||
| 189 | /// bool bRet = kodi::gui::dialogs::Numeric::ShowAndGetTime(*timeinfo, "Selected time test call"); | ||
| 190 | /// strftime(buffer, sizeof(buffer), "%H:%M.", timeinfo); | ||
| 191 | /// printf("Selected time it's %s and was on Dialog %s\n", buffer, bRet ? "OK" : "Canceled"); | ||
| 192 | /// ~~~~~~~~~~~~~ | ||
| 193 | /// | ||
| 194 | inline bool ATTRIBUTE_HIDDEN ShowAndGetTime(tm& time, const std::string& heading) | ||
| 195 | { | ||
| 196 | using namespace ::kodi::addon; | ||
| 197 | return CAddonBase::m_interface->toKodi->kodi_gui->dialogNumeric->show_and_get_time( | ||
| 198 | CAddonBase::m_interface->toKodi->kodiBase, &time, heading.c_str()); | ||
| 199 | } | ||
| 200 | //------------------------------------------------------------------------------ | ||
| 201 | |||
| 202 | //============================================================================== | ||
| 203 | /// @ingroup cpp_kodi_gui_dialogs_Numeric | ||
| 204 | /// @brief Use dialog to get date value. | ||
| 205 | /// | ||
| 206 | /// @param[in,out] date Overwritten with user input if return=true and date | ||
| 207 | /// inserted. | ||
| 208 | /// @param[in] heading Heading to display | ||
| 209 | /// @return true if successful display and user input. false if unsuccessful | ||
| 210 | /// display, no user input, or canceled editing. | ||
| 211 | /// | ||
| 212 | /// | ||
| 213 | ///------------------------------------------------------------------------- | ||
| 214 | /// | ||
| 215 | /// **Example:** | ||
| 216 | /// ~~~~~~~~~~~~~{.cpp} | ||
| 217 | /// #include <stdio.h> // printf | ||
| 218 | /// #include <time.h> // time_t, struct tm, time, localtime, strftime | ||
| 219 | /// #include <kodi/gui/dialogs/Numeric.h> | ||
| 220 | /// | ||
| 221 | /// time_t rawtime; | ||
| 222 | /// struct tm * timeinfo; | ||
| 223 | /// char buffer [20]; | ||
| 224 | /// | ||
| 225 | /// time (&rawtime); | ||
| 226 | /// timeinfo = localtime(&rawtime); | ||
| 227 | /// bool bRet = kodi::gui::dialogs::Numeric::ShowAndGetDate(*timeinfo, "Selected date test call"); | ||
| 228 | /// strftime(buffer, sizeof(buffer), "%Y-%m-%d", timeinfo); | ||
| 229 | /// printf("Selected date it's %s and was on Dialog %s\n", buffer, bRet ? "OK" : "Canceled"); | ||
| 230 | /// ~~~~~~~~~~~~~ | ||
| 231 | /// | ||
| 232 | inline bool ATTRIBUTE_HIDDEN ShowAndGetDate(tm& date, const std::string& heading) | ||
| 233 | { | ||
| 234 | using namespace ::kodi::addon; | ||
| 235 | return CAddonBase::m_interface->toKodi->kodi_gui->dialogNumeric->show_and_get_date( | ||
| 236 | CAddonBase::m_interface->toKodi->kodiBase, &date, heading.c_str()); | ||
| 237 | } | ||
| 238 | //------------------------------------------------------------------------------ | ||
| 239 | |||
| 240 | //============================================================================== | ||
| 241 | /// @ingroup cpp_kodi_gui_dialogs_Numeric | ||
| 242 | /// @brief Use dialog to get a IP | ||
| 243 | /// | ||
| 244 | /// @param[in,out] ipAddress Overwritten with user input if return=true and | ||
| 245 | /// IP address inserted. | ||
| 246 | /// @param[in] heading Heading to display. | ||
| 247 | /// @return true if successful display and user input. false if unsuccessful | ||
| 248 | /// display, no user input, or canceled editing. | ||
| 249 | /// | ||
| 250 | inline bool ATTRIBUTE_HIDDEN ShowAndGetIPAddress(std::string& ipAddress, const std::string& heading) | ||
| 251 | { | ||
| 252 | using namespace ::kodi::addon; | ||
| 253 | char* retString = nullptr; | ||
| 254 | bool ret = CAddonBase::m_interface->toKodi->kodi_gui->dialogNumeric->show_and_get_ip_address( | ||
| 255 | CAddonBase::m_interface->toKodi->kodiBase, ipAddress.c_str(), &retString, heading.c_str()); | ||
| 256 | if (retString != nullptr) | ||
| 257 | { | ||
| 258 | ipAddress = retString; | ||
| 259 | CAddonBase::m_interface->toKodi->free_string(CAddonBase::m_interface->toKodi->kodiBase, | ||
| 260 | retString); | ||
| 261 | } | ||
| 262 | return ret; | ||
| 263 | } | ||
| 264 | //------------------------------------------------------------------------------ | ||
| 265 | |||
| 266 | //============================================================================== | ||
| 267 | /// @ingroup cpp_kodi_gui_dialogs_Numeric | ||
| 268 | /// @brief Use dialog to get normal number. | ||
| 269 | /// | ||
| 270 | /// @param[in,out] input Overwritten with user input if return=true and time | ||
| 271 | /// in seconds inserted | ||
| 272 | /// @param[in] heading Heading to display | ||
| 273 | /// @param[in] autoCloseTimeoutMs [opt] To close the dialog after a specified | ||
| 274 | /// time, in milliseconds, default is 0 | ||
| 275 | /// which keeps the dialog open | ||
| 276 | /// indefinitely. | ||
| 277 | /// @return true if successful display and user input. false if unsuccessful | ||
| 278 | /// display, no user input, or canceled editing. | ||
| 279 | /// | ||
| 280 | /// | ||
| 281 | ///------------------------------------------------------------------------- | ||
| 282 | /// | ||
| 283 | /// **Example:** | ||
| 284 | /// ~~~~~~~~~~~~~{.cpp} | ||
| 285 | /// #include <stdio.h> // printf | ||
| 286 | /// #include <stdlib.h> // strtoull (C++11) | ||
| 287 | /// #include <kodi/gui/dialogs/Numeric.h> | ||
| 288 | /// | ||
| 289 | /// std::string number; | ||
| 290 | /// bool bRet = kodi::gui::dialogs::Numeric::ShowAndGetNumber(number, "Number test call"); | ||
| 291 | /// printf("Written number input is : %llu and was %s\n", | ||
| 292 | /// strtoull(number.c_str(), nullptr, 0), bRet ? "OK" : "Canceled"); | ||
| 293 | /// ~~~~~~~~~~~~~ | ||
| 294 | /// | ||
| 295 | inline bool ATTRIBUTE_HIDDEN ShowAndGetNumber(std::string& input, | ||
| 296 | const std::string& heading, | ||
| 297 | unsigned int autoCloseTimeoutMs = 0) | ||
| 298 | { | ||
| 299 | using namespace ::kodi::addon; | ||
| 300 | char* retString = nullptr; | ||
| 301 | bool ret = CAddonBase::m_interface->toKodi->kodi_gui->dialogNumeric->show_and_get_number( | ||
| 302 | CAddonBase::m_interface->toKodi->kodiBase, input.c_str(), &retString, heading.c_str(), | ||
| 303 | autoCloseTimeoutMs); | ||
| 304 | if (retString != nullptr) | ||
| 305 | { | ||
| 306 | input = retString; | ||
| 307 | CAddonBase::m_interface->toKodi->free_string(CAddonBase::m_interface->toKodi->kodiBase, | ||
| 308 | retString); | ||
| 309 | } | ||
| 310 | return ret; | ||
| 311 | } | ||
| 312 | //------------------------------------------------------------------------------ | ||
| 313 | |||
| 314 | //============================================================================== | ||
| 315 | /// @ingroup cpp_kodi_gui_dialogs_Numeric | ||
| 316 | /// @brief Show numeric keypad to get seconds. | ||
| 317 | /// | ||
| 318 | /// @param[in,out] time Overwritten with user input if return=true and time | ||
| 319 | /// in seconds inserted. | ||
| 320 | /// @param[in] heading Heading to display | ||
| 321 | /// @return true if successful display and user input. false if unsuccessful | ||
| 322 | /// display, no user input, or canceled editing. | ||
| 323 | /// | ||
| 324 | inline bool ATTRIBUTE_HIDDEN ShowAndGetSeconds(std::string& time, const std::string& heading) | ||
| 325 | { | ||
| 326 | using namespace ::kodi::addon; | ||
| 327 | char* retString = nullptr; | ||
| 328 | bool ret = CAddonBase::m_interface->toKodi->kodi_gui->dialogNumeric->show_and_get_seconds( | ||
| 329 | CAddonBase::m_interface->toKodi->kodiBase, time.c_str(), &retString, heading.c_str()); | ||
| 330 | if (retString != nullptr) | ||
| 331 | { | ||
| 332 | time = retString; | ||
| 333 | CAddonBase::m_interface->toKodi->free_string(CAddonBase::m_interface->toKodi->kodiBase, | ||
| 334 | retString); | ||
| 335 | } | ||
| 336 | return ret; | ||
| 337 | } | ||
| 338 | //------------------------------------------------------------------------------ | ||
| 339 | }; // namespace Numeric | ||
| 340 | /// @} | ||
| 341 | |||
| 342 | } /* namespace dialogs */ | ||
| 343 | } /* namespace gui */ | ||
| 344 | } /* namespace kodi */ | ||
| 345 | |||
| 346 | #endif /* __cplusplus */ | ||
diff --git a/xbmc/addons/kodi-dev-kit/include/kodi/gui/dialogs/OK.h b/xbmc/addons/kodi-dev-kit/include/kodi/gui/dialogs/OK.h new file mode 100644 index 0000000..747ab9d --- /dev/null +++ b/xbmc/addons/kodi-dev-kit/include/kodi/gui/dialogs/OK.h | |||
| @@ -0,0 +1,101 @@ | |||
| 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 "../../AddonBase.h" | ||
| 12 | #include "../../c-api/gui/dialogs/ok.h" | ||
| 13 | |||
| 14 | #ifdef __cplusplus | ||
| 15 | |||
| 16 | namespace kodi | ||
| 17 | { | ||
| 18 | namespace gui | ||
| 19 | { | ||
| 20 | namespace dialogs | ||
| 21 | { | ||
| 22 | |||
| 23 | //============================================================================== | ||
| 24 | /// @defgroup cpp_kodi_gui_dialogs_OK Dialog OK | ||
| 25 | /// @ingroup cpp_kodi_gui_dialogs | ||
| 26 | /// @{ | ||
| 27 | /// @brief @cpp_namespace{ kodi::gui::dialogs::OK } | ||
| 28 | /// **OK dialog**\n | ||
| 29 | /// The functions listed below permit the call of a dialogue of information, a | ||
| 30 | /// confirmation of the user by press from OK required. | ||
| 31 | /// | ||
| 32 | /// It has the header @ref OK.h "#include <kodi/gui/dialogs/OK.h>" | ||
| 33 | /// be included to enjoy it. | ||
| 34 | /// | ||
| 35 | namespace OK | ||
| 36 | { | ||
| 37 | //============================================================================== | ||
| 38 | /// @ingroup cpp_kodi_gui_dialogs_OK | ||
| 39 | /// @brief Use dialog to inform user with text and confirmation with OK with | ||
| 40 | /// continued string. | ||
| 41 | /// | ||
| 42 | /// @param[in] heading Dialog heading. | ||
| 43 | /// @param[in] text Multi-line text. | ||
| 44 | /// | ||
| 45 | /// | ||
| 46 | ///------------------------------------------------------------------------- | ||
| 47 | /// | ||
| 48 | /// **Example:** | ||
| 49 | /// ~~~~~~~~~~~~~{.cpp} | ||
| 50 | /// #include <kodi/gui/dialogs/OK.h> | ||
| 51 | /// ... | ||
| 52 | /// kodi::gui::dialogs::OK::ShowAndGetInput("Test dialog", "Hello World!\nI'm a call from add-on\n :) :D"); | ||
| 53 | /// ~~~~~~~~~~~~~ | ||
| 54 | /// | ||
| 55 | inline void ATTRIBUTE_HIDDEN ShowAndGetInput(const std::string& heading, const std::string& text) | ||
| 56 | { | ||
| 57 | using namespace ::kodi::addon; | ||
| 58 | CAddonBase::m_interface->toKodi->kodi_gui->dialogOK->show_and_get_input_single_text( | ||
| 59 | CAddonBase::m_interface->toKodi->kodiBase, heading.c_str(), text.c_str()); | ||
| 60 | } | ||
| 61 | //------------------------------------------------------------------------------ | ||
| 62 | |||
| 63 | //============================================================================== | ||
| 64 | /// @ingroup cpp_kodi_gui_dialogs_OK | ||
| 65 | /// @brief Use dialog to inform user with text and confirmation with OK with | ||
| 66 | /// strings separated to the lines. | ||
| 67 | /// | ||
| 68 | /// @param[in] heading Dialog heading. | ||
| 69 | /// @param[in] line0 Line #1 text. | ||
| 70 | /// @param[in] line1 Line #2 text. | ||
| 71 | /// @param[in] line2 Line #3 text. | ||
| 72 | /// | ||
| 73 | /// | ||
| 74 | ///------------------------------------------------------------------------- | ||
| 75 | /// | ||
| 76 | /// **Example:** | ||
| 77 | /// ~~~~~~~~~~~~~{.cpp} | ||
| 78 | /// #include <kodi/gui/dialogs/OK.h> | ||
| 79 | /// ... | ||
| 80 | /// kodi::gui::dialogs::OK::ShowAndGetInput("Test dialog", "Hello World!", "I'm a call from add-on", " :) :D"); | ||
| 81 | /// ~~~~~~~~~~~~~ | ||
| 82 | /// | ||
| 83 | inline void ATTRIBUTE_HIDDEN ShowAndGetInput(const std::string& heading, | ||
| 84 | const std::string& line0, | ||
| 85 | const std::string& line1, | ||
| 86 | const std::string& line2) | ||
| 87 | { | ||
| 88 | using namespace ::kodi::addon; | ||
| 89 | CAddonBase::m_interface->toKodi->kodi_gui->dialogOK->show_and_get_input_line_text( | ||
| 90 | CAddonBase::m_interface->toKodi->kodiBase, heading.c_str(), line0.c_str(), line1.c_str(), | ||
| 91 | line2.c_str()); | ||
| 92 | } | ||
| 93 | //------------------------------------------------------------------------------ | ||
| 94 | } // namespace OK | ||
| 95 | /// @} | ||
| 96 | |||
| 97 | } /* namespace dialogs */ | ||
| 98 | } /* namespace gui */ | ||
| 99 | } /* namespace kodi */ | ||
| 100 | |||
| 101 | #endif /* __cplusplus */ | ||
diff --git a/xbmc/addons/kodi-dev-kit/include/kodi/gui/dialogs/Progress.h b/xbmc/addons/kodi-dev-kit/include/kodi/gui/dialogs/Progress.h new file mode 100644 index 0000000..d242a56 --- /dev/null +++ b/xbmc/addons/kodi-dev-kit/include/kodi/gui/dialogs/Progress.h | |||
| @@ -0,0 +1,244 @@ | |||
| 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 "../../AddonBase.h" | ||
| 12 | #include "../../c-api/gui/dialogs/progress.h" | ||
| 13 | |||
| 14 | #ifdef __cplusplus | ||
| 15 | |||
| 16 | namespace kodi | ||
| 17 | { | ||
| 18 | namespace gui | ||
| 19 | { | ||
| 20 | namespace dialogs | ||
| 21 | { | ||
| 22 | |||
| 23 | //============================================================================== | ||
| 24 | /// @defgroup cpp_kodi_gui_dialogs_CProgress Dialog Progress | ||
| 25 | /// @ingroup cpp_kodi_gui_dialogs | ||
| 26 | /// @brief @cpp_class{ kodi::gui::dialogs::CProgress } | ||
| 27 | /// **Progress dialog shown in center**\n | ||
| 28 | /// The with @ref Progress.h "#include <kodi/gui/dialogs/Progress.h>" | ||
| 29 | /// given class are basically used to create Kodi's progress dialog with named | ||
| 30 | /// text fields. | ||
| 31 | /// | ||
| 32 | /// **Example:** | ||
| 33 | /// ~~~~~~~~~~~~~{.cpp} | ||
| 34 | /// #include <kodi/gui/dialogs/Progress.h> | ||
| 35 | /// | ||
| 36 | /// kodi::gui::dialogs::CProgress *progress = new kodi::gui::dialogs::CProgress; | ||
| 37 | /// progress->SetHeading("Test progress"); | ||
| 38 | /// progress->SetLine(1, "line 1"); | ||
| 39 | /// progress->SetLine(2, "line 2"); | ||
| 40 | /// progress->SetLine(3, "line 3"); | ||
| 41 | /// progress->SetCanCancel(true); | ||
| 42 | /// progress->ShowProgressBar(true); | ||
| 43 | /// progress->Open(); | ||
| 44 | /// for (unsigned int i = 0; i < 100; i += 10) | ||
| 45 | /// { | ||
| 46 | /// progress->SetPercentage(i); | ||
| 47 | /// sleep(1); | ||
| 48 | /// } | ||
| 49 | /// delete progress; | ||
| 50 | /// ~~~~~~~~~~~~~ | ||
| 51 | /// | ||
| 52 | class ATTRIBUTE_HIDDEN CProgress | ||
| 53 | { | ||
| 54 | public: | ||
| 55 | //============================================================================ | ||
| 56 | /// @ingroup cpp_kodi_gui_dialogs_CProgress | ||
| 57 | /// @brief Construct a new dialog | ||
| 58 | /// | ||
| 59 | CProgress() | ||
| 60 | { | ||
| 61 | using namespace ::kodi::addon; | ||
| 62 | m_DialogHandle = CAddonBase::m_interface->toKodi->kodi_gui->dialogProgress->new_dialog( | ||
| 63 | CAddonBase::m_interface->toKodi->kodiBase); | ||
| 64 | if (!m_DialogHandle) | ||
| 65 | kodi::Log(ADDON_LOG_FATAL, | ||
| 66 | "kodi::gui::dialogs::CProgress can't create window class from Kodi !!!"); | ||
| 67 | } | ||
| 68 | //---------------------------------------------------------------------------- | ||
| 69 | |||
| 70 | //============================================================================ | ||
| 71 | /// @ingroup cpp_kodi_gui_dialogs_CProgress | ||
| 72 | /// @brief Destructor | ||
| 73 | /// | ||
| 74 | ~CProgress() | ||
| 75 | { | ||
| 76 | using namespace ::kodi::addon; | ||
| 77 | if (m_DialogHandle) | ||
| 78 | CAddonBase::m_interface->toKodi->kodi_gui->dialogProgress->delete_dialog( | ||
| 79 | CAddonBase::m_interface->toKodi->kodiBase, m_DialogHandle); | ||
| 80 | } | ||
| 81 | //---------------------------------------------------------------------------- | ||
| 82 | |||
| 83 | //============================================================================ | ||
| 84 | /// @ingroup cpp_kodi_gui_dialogs_CProgress | ||
| 85 | /// @brief To open the dialog | ||
| 86 | /// | ||
| 87 | void Open() | ||
| 88 | { | ||
| 89 | using namespace ::kodi::addon; | ||
| 90 | CAddonBase::m_interface->toKodi->kodi_gui->dialogProgress->open( | ||
| 91 | CAddonBase::m_interface->toKodi->kodiBase, m_DialogHandle); | ||
| 92 | } | ||
| 93 | //---------------------------------------------------------------------------- | ||
| 94 | |||
| 95 | //============================================================================ | ||
| 96 | /// @ingroup cpp_kodi_gui_dialogs_CProgress | ||
| 97 | /// @brief Set the heading title of dialog | ||
| 98 | /// | ||
| 99 | /// @param[in] heading Title string to use | ||
| 100 | /// | ||
| 101 | void SetHeading(const std::string& heading) | ||
| 102 | { | ||
| 103 | using namespace ::kodi::addon; | ||
| 104 | CAddonBase::m_interface->toKodi->kodi_gui->dialogProgress->set_heading( | ||
| 105 | CAddonBase::m_interface->toKodi->kodiBase, m_DialogHandle, heading.c_str()); | ||
| 106 | } | ||
| 107 | //---------------------------------------------------------------------------- | ||
| 108 | |||
| 109 | //============================================================================ | ||
| 110 | /// @ingroup cpp_kodi_gui_dialogs_CProgress | ||
| 111 | /// @brief To set the line text field on dialog from 0 - 2 | ||
| 112 | /// | ||
| 113 | /// @param[in] iLine Line number | ||
| 114 | /// @param[in] line Text string | ||
| 115 | /// | ||
| 116 | void SetLine(unsigned int iLine, const std::string& line) | ||
| 117 | { | ||
| 118 | using namespace ::kodi::addon; | ||
| 119 | CAddonBase::m_interface->toKodi->kodi_gui->dialogProgress->set_line( | ||
| 120 | CAddonBase::m_interface->toKodi->kodiBase, m_DialogHandle, iLine, line.c_str()); | ||
| 121 | } | ||
| 122 | //---------------------------------------------------------------------------- | ||
| 123 | |||
| 124 | //============================================================================ | ||
| 125 | /// @ingroup cpp_kodi_gui_dialogs_CProgress | ||
| 126 | /// @brief To enable and show cancel button on dialog | ||
| 127 | /// | ||
| 128 | /// @param[in] canCancel if true becomes it shown | ||
| 129 | /// | ||
| 130 | void SetCanCancel(bool canCancel) | ||
| 131 | { | ||
| 132 | using namespace ::kodi::addon; | ||
| 133 | CAddonBase::m_interface->toKodi->kodi_gui->dialogProgress->set_can_cancel( | ||
| 134 | CAddonBase::m_interface->toKodi->kodiBase, m_DialogHandle, canCancel); | ||
| 135 | } | ||
| 136 | //---------------------------------------------------------------------------- | ||
| 137 | |||
| 138 | //============================================================================ | ||
| 139 | /// @ingroup cpp_kodi_gui_dialogs_CProgress | ||
| 140 | /// @brief To check dialog for clicked cancel button | ||
| 141 | /// | ||
| 142 | /// @return True if canceled | ||
| 143 | /// | ||
| 144 | bool IsCanceled() const | ||
| 145 | { | ||
| 146 | using namespace ::kodi::addon; | ||
| 147 | return CAddonBase::m_interface->toKodi->kodi_gui->dialogProgress->is_canceled( | ||
| 148 | CAddonBase::m_interface->toKodi->kodiBase, m_DialogHandle); | ||
| 149 | } | ||
| 150 | //---------------------------------------------------------------------------- | ||
| 151 | |||
| 152 | //============================================================================ | ||
| 153 | /// @ingroup cpp_kodi_gui_dialogs_CProgress | ||
| 154 | /// @brief Get the current progress position as percent | ||
| 155 | /// | ||
| 156 | /// @param[in] percentage Position to use from 0 to 100 | ||
| 157 | /// | ||
| 158 | void SetPercentage(int percentage) | ||
| 159 | { | ||
| 160 | using namespace ::kodi::addon; | ||
| 161 | CAddonBase::m_interface->toKodi->kodi_gui->dialogProgress->set_percentage( | ||
| 162 | CAddonBase::m_interface->toKodi->kodiBase, m_DialogHandle, percentage); | ||
| 163 | } | ||
| 164 | //---------------------------------------------------------------------------- | ||
| 165 | |||
| 166 | //============================================================================ | ||
| 167 | /// @ingroup cpp_kodi_gui_dialogs_CProgress | ||
| 168 | /// @brief To set the current progress position as percent | ||
| 169 | /// | ||
| 170 | /// @return Current Position used from 0 to 100 | ||
| 171 | /// | ||
| 172 | int GetPercentage() const | ||
| 173 | { | ||
| 174 | using namespace ::kodi::addon; | ||
| 175 | return CAddonBase::m_interface->toKodi->kodi_gui->dialogProgress->get_percentage( | ||
| 176 | CAddonBase::m_interface->toKodi->kodiBase, m_DialogHandle); | ||
| 177 | } | ||
| 178 | //---------------------------------------------------------------------------- | ||
| 179 | |||
| 180 | //============================================================================ | ||
| 181 | /// @ingroup cpp_kodi_gui_dialogs_CProgress | ||
| 182 | /// @brief To show or hide progress bar dialog | ||
| 183 | /// | ||
| 184 | /// @param[in] onOff If true becomes it shown | ||
| 185 | /// | ||
| 186 | void ShowProgressBar(bool onOff) | ||
| 187 | { | ||
| 188 | using namespace ::kodi::addon; | ||
| 189 | CAddonBase::m_interface->toKodi->kodi_gui->dialogProgress->show_progress_bar( | ||
| 190 | CAddonBase::m_interface->toKodi->kodiBase, m_DialogHandle, onOff); | ||
| 191 | } | ||
| 192 | //---------------------------------------------------------------------------- | ||
| 193 | |||
| 194 | //============================================================================ | ||
| 195 | /// @ingroup cpp_kodi_gui_dialogs_CProgress | ||
| 196 | /// @brief Set the maximum position of progress, needed if `SetProgressAdvance(...)` is used | ||
| 197 | /// | ||
| 198 | /// @param[in] max Biggest usable position to use | ||
| 199 | /// | ||
| 200 | void SetProgressMax(int max) | ||
| 201 | { | ||
| 202 | using namespace ::kodi::addon; | ||
| 203 | CAddonBase::m_interface->toKodi->kodi_gui->dialogProgress->set_progress_max( | ||
| 204 | CAddonBase::m_interface->toKodi->kodiBase, m_DialogHandle, max); | ||
| 205 | } | ||
| 206 | //---------------------------------------------------------------------------- | ||
| 207 | |||
| 208 | //============================================================================ | ||
| 209 | /// @ingroup cpp_kodi_gui_dialogs_CProgress | ||
| 210 | /// @brief To increase progress bar by defined step size until reach of maximum position | ||
| 211 | /// | ||
| 212 | /// @param[in] steps Step size to increase, default is 1 | ||
| 213 | /// | ||
| 214 | void SetProgressAdvance(int steps = 1) | ||
| 215 | { | ||
| 216 | using namespace ::kodi::addon; | ||
| 217 | CAddonBase::m_interface->toKodi->kodi_gui->dialogProgress->set_progress_advance( | ||
| 218 | CAddonBase::m_interface->toKodi->kodiBase, m_DialogHandle, steps); | ||
| 219 | } | ||
| 220 | //---------------------------------------------------------------------------- | ||
| 221 | |||
| 222 | //============================================================================ | ||
| 223 | /// @ingroup cpp_kodi_gui_dialogs_CProgress | ||
| 224 | /// @brief To check progress was canceled on work | ||
| 225 | /// | ||
| 226 | /// @return True if aborted | ||
| 227 | /// | ||
| 228 | bool Abort() | ||
| 229 | { | ||
| 230 | using namespace ::kodi::addon; | ||
| 231 | return CAddonBase::m_interface->toKodi->kodi_gui->dialogProgress->abort( | ||
| 232 | CAddonBase::m_interface->toKodi->kodiBase, m_DialogHandle); | ||
| 233 | } | ||
| 234 | //---------------------------------------------------------------------------- | ||
| 235 | |||
| 236 | private: | ||
| 237 | KODI_GUI_HANDLE m_DialogHandle; | ||
| 238 | }; | ||
| 239 | |||
| 240 | } /* namespace dialogs */ | ||
| 241 | } /* namespace gui */ | ||
| 242 | } /* namespace kodi */ | ||
| 243 | |||
| 244 | #endif /* __cplusplus */ | ||
diff --git a/xbmc/addons/kodi-dev-kit/include/kodi/gui/dialogs/Select.h b/xbmc/addons/kodi-dev-kit/include/kodi/gui/dialogs/Select.h new file mode 100644 index 0000000..9b1923e --- /dev/null +++ b/xbmc/addons/kodi-dev-kit/include/kodi/gui/dialogs/Select.h | |||
| @@ -0,0 +1,269 @@ | |||
| 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 "../../AddonBase.h" | ||
| 12 | #include "../../c-api/gui/dialogs/select.h" | ||
| 13 | |||
| 14 | #ifdef __cplusplus | ||
| 15 | |||
| 16 | namespace kodi | ||
| 17 | { | ||
| 18 | namespace gui | ||
| 19 | { | ||
| 20 | namespace dialogs | ||
| 21 | { | ||
| 22 | |||
| 23 | //============================================================================== | ||
| 24 | /// @defgroup cpp_kodi_gui_dialogs_Select_Defs Definitions, structures and enumerators | ||
| 25 | /// @ingroup cpp_kodi_gui_dialogs_Select | ||
| 26 | /// @brief **Dialog Select definition values**\n | ||
| 27 | /// Data structures associated with this dialog. | ||
| 28 | /// | ||
| 29 | //------------------------------------------------------------------------------ | ||
| 30 | |||
| 31 | //============================================================================== | ||
| 32 | /// @ingroup cpp_kodi_gui_dialogs_Select_Defs | ||
| 33 | /// @brief **Selection entry structure**\n | ||
| 34 | /// Used to provide the necessary data for the selection dialog and to declare | ||
| 35 | /// the selected position in it. | ||
| 36 | /// | ||
| 37 | typedef struct SSelectionEntry | ||
| 38 | { | ||
| 39 | /*! \cond PRIVATE */ | ||
| 40 | SSelectionEntry() = default; | ||
| 41 | /*! \endcond */ | ||
| 42 | |||
| 43 | /// Entry identfication string | ||
| 44 | std::string id; | ||
| 45 | |||
| 46 | /// Entry name to show on GUI dialog | ||
| 47 | std::string name; | ||
| 48 | |||
| 49 | /// Place where entry can be preselected and after return the from user | ||
| 50 | /// selected is set. | ||
| 51 | bool selected = false; | ||
| 52 | } SSelectionEntry; | ||
| 53 | //------------------------------------------------------------------------------ | ||
| 54 | |||
| 55 | //============================================================================== | ||
| 56 | /// @defgroup cpp_kodi_gui_dialogs_Select Dialog Select | ||
| 57 | /// @ingroup cpp_kodi_gui_dialogs | ||
| 58 | /// @{ | ||
| 59 | /// @brief @cpp_namespace{ kodi::gui::dialogs::Select } | ||
| 60 | /// **Selection dialog**\n | ||
| 61 | /// The function listed below permits the call of a dialogue to select of an | ||
| 62 | /// entry as a key | ||
| 63 | /// | ||
| 64 | /// It has the header @ref Select.h "#include <kodi/gui/dialogs/Select.h>" | ||
| 65 | /// be included to enjoy it. | ||
| 66 | /// | ||
| 67 | /// | ||
| 68 | namespace Select | ||
| 69 | { | ||
| 70 | //============================================================================== | ||
| 71 | /// @ingroup cpp_kodi_gui_dialogs_Select | ||
| 72 | /// @brief Show a selection dialog about given parts. | ||
| 73 | /// | ||
| 74 | /// @param[in] heading Dialog heading name | ||
| 75 | /// @param[in] entries String list about entries | ||
| 76 | /// @param[in] selected [opt] Predefined selection (default is <tt>-1</tt> for | ||
| 77 | /// the first) | ||
| 78 | /// @param[in] autoclose [opt] To close dialog automatic after the given time | ||
| 79 | /// in ms. As '0' it stays open. | ||
| 80 | /// @return The selected entry, if return <tt>-1</tt> was nothing selected or | ||
| 81 | /// canceled | ||
| 82 | /// | ||
| 83 | /// | ||
| 84 | ///------------------------------------------------------------------------- | ||
| 85 | /// | ||
| 86 | /// **Example:** | ||
| 87 | /// ~~~~~~~~~~~~~{.cpp} | ||
| 88 | /// #include <kodi/gui/dialogs/Select.h> | ||
| 89 | /// | ||
| 90 | /// const std::vector<std::string> entries | ||
| 91 | /// { | ||
| 92 | /// "Test 1", | ||
| 93 | /// "Test 2", | ||
| 94 | /// "Test 3", | ||
| 95 | /// "Test 4", | ||
| 96 | /// "Test 5" | ||
| 97 | /// }; | ||
| 98 | /// | ||
| 99 | /// int selected = kodi::gui::dialogs::Select::Show("Test selection", entries, -1); | ||
| 100 | /// if (selected < 0) | ||
| 101 | /// fprintf(stderr, "Item selection canceled\n"); | ||
| 102 | /// else | ||
| 103 | /// fprintf(stderr, "Selected item is: %i\n", selected); | ||
| 104 | /// ~~~~~~~~~~~~~ | ||
| 105 | /// | ||
| 106 | inline int ATTRIBUTE_HIDDEN Show(const std::string& heading, | ||
| 107 | const std::vector<std::string>& entries, | ||
| 108 | int selected = -1, | ||
| 109 | unsigned int autoclose = 0) | ||
| 110 | { | ||
| 111 | using namespace ::kodi::addon; | ||
| 112 | unsigned int size = static_cast<unsigned int>(entries.size()); | ||
| 113 | const char** cEntries = (const char**)malloc(size * sizeof(const char**)); | ||
| 114 | for (unsigned int i = 0; i < size; ++i) | ||
| 115 | { | ||
| 116 | cEntries[i] = entries[i].c_str(); | ||
| 117 | } | ||
| 118 | int ret = CAddonBase::m_interface->toKodi->kodi_gui->dialogSelect->open( | ||
| 119 | CAddonBase::m_interface->toKodi->kodiBase, heading.c_str(), cEntries, size, selected, | ||
| 120 | autoclose); | ||
| 121 | free(cEntries); | ||
| 122 | return ret; | ||
| 123 | } | ||
| 124 | //------------------------------------------------------------------------------ | ||
| 125 | |||
| 126 | //============================================================================== | ||
| 127 | /// @ingroup cpp_kodi_gui_dialogs_Select | ||
| 128 | /// @brief Show a selection dialog about given parts. | ||
| 129 | /// | ||
| 130 | /// This function is mostly equal to the other, only becomes the string list | ||
| 131 | /// here done by a @ref SSelectionEntry, where a ID string can be defined. | ||
| 132 | /// | ||
| 133 | /// @param[in] heading Dialog heading name | ||
| 134 | /// @param[in] entries @ref SSelectionEntry list about entries | ||
| 135 | /// @param[in] selected [opt] Predefined selection (default is <tt>-1</tt> for | ||
| 136 | /// the first) | ||
| 137 | /// @param[in] autoclose [opt] To close dialog automatic after the given time | ||
| 138 | /// in ms. As '0' it stays open. | ||
| 139 | /// @return The selected entry, if return <tt>-1</tt> was nothing selected | ||
| 140 | /// or canceled | ||
| 141 | /// | ||
| 142 | /// | ||
| 143 | ///------------------------------------------------------------------------- | ||
| 144 | /// | ||
| 145 | /// **Example:** | ||
| 146 | /// ~~~~~~~~~~~~~{.cpp} | ||
| 147 | /// #include <kodi/gui/dialogs/Select.h> | ||
| 148 | /// | ||
| 149 | /// std::vector<kodi::gui::dialogs::SSelectionEntry> entries | ||
| 150 | /// { | ||
| 151 | /// { "ID 1", "Test 1", false }, | ||
| 152 | /// { "ID 2", "Test 2", false }, | ||
| 153 | /// { "ID 3", "Test 3", false }, | ||
| 154 | /// { "ID 4", "Test 4", false }, | ||
| 155 | /// { "ID 5", "Test 5", false } | ||
| 156 | /// }; | ||
| 157 | /// | ||
| 158 | /// int selected = kodi::gui::dialogs::Select::Show("Test selection", entries, -1); | ||
| 159 | /// if (selected < 0) | ||
| 160 | /// fprintf(stderr, "Item selection canceled\n"); | ||
| 161 | /// else | ||
| 162 | /// fprintf(stderr, "Selected item is: %i\n", selected); | ||
| 163 | /// ~~~~~~~~~~~~~ | ||
| 164 | /// | ||
| 165 | inline int ATTRIBUTE_HIDDEN Show(const std::string& heading, | ||
| 166 | std::vector<kodi::gui::dialogs::SSelectionEntry>& entries, | ||
| 167 | int selected = -1, | ||
| 168 | unsigned int autoclose = 0) | ||
| 169 | { | ||
| 170 | using namespace ::kodi::addon; | ||
| 171 | unsigned int size = static_cast<unsigned int>(entries.size()); | ||
| 172 | const char** cEntries = static_cast<const char**>(malloc(size * sizeof(const char*))); | ||
| 173 | for (unsigned int i = 0; i < size; ++i) | ||
| 174 | { | ||
| 175 | cEntries[i] = entries[i].name.c_str(); | ||
| 176 | if (selected == -1 && entries[i].selected) | ||
| 177 | selected = i; | ||
| 178 | } | ||
| 179 | int ret = CAddonBase::m_interface->toKodi->kodi_gui->dialogSelect->open( | ||
| 180 | CAddonBase::m_interface->toKodi->kodiBase, heading.c_str(), cEntries, size, selected, | ||
| 181 | autoclose); | ||
| 182 | if (ret >= 0) | ||
| 183 | { | ||
| 184 | entries[ret].selected = true; | ||
| 185 | } | ||
| 186 | free(cEntries); | ||
| 187 | return ret; | ||
| 188 | } | ||
| 189 | //------------------------------------------------------------------------------ | ||
| 190 | |||
| 191 | //============================================================================== | ||
| 192 | /// @ingroup cpp_kodi_gui_dialogs_Select | ||
| 193 | /// @brief Show a multiple selection dialog about given parts. | ||
| 194 | /// | ||
| 195 | /// @param[in] heading Dialog heading name | ||
| 196 | /// @param[in] entries @ref SSelectionEntry list about entries | ||
| 197 | /// @param[in] autoclose [opt] To close dialog automatic after the given time in | ||
| 198 | /// ms. As '0' it stays open. | ||
| 199 | /// @return The selected entries, if return <tt>empty</tt> was nothing selected | ||
| 200 | /// or canceled | ||
| 201 | /// | ||
| 202 | /// With selected on @ref SSelectionEntry can be a pre selection defined. | ||
| 203 | /// | ||
| 204 | ///------------------------------------------------------------------------- | ||
| 205 | /// | ||
| 206 | /// **Example:** | ||
| 207 | /// ~~~~~~~~~~~~~{.cpp} | ||
| 208 | /// #include <kodi/gui/dialogs/Select.h> | ||
| 209 | /// | ||
| 210 | /// std::vector<kodi::gui::dialogs::SSelectionEntry> entries | ||
| 211 | /// { | ||
| 212 | /// { "ID 1", "Test 1", false }, | ||
| 213 | /// { "ID 2", "Test 2", false }, | ||
| 214 | /// { "ID 3", "Test 3", false }, | ||
| 215 | /// { "ID 4", "Test 4", false }, | ||
| 216 | /// { "ID 5", "Test 5", false } | ||
| 217 | /// }; | ||
| 218 | /// | ||
| 219 | /// bool ret = kodi::gui::dialogs::Select::ShowMultiSelect("Test selection", entries); | ||
| 220 | /// if (!ret) | ||
| 221 | /// fprintf(stderr, "Selection canceled\n"); | ||
| 222 | /// else | ||
| 223 | /// { | ||
| 224 | /// fprintf(stderr, "Selected items:\n"); | ||
| 225 | /// for (const auto& entry : entries) | ||
| 226 | /// { | ||
| 227 | /// if (entry.selected) | ||
| 228 | /// fprintf(stderr, " - %s\n", entry.selected.id.c_str()); | ||
| 229 | /// } | ||
| 230 | /// } | ||
| 231 | /// ~~~~~~~~~~~~~ | ||
| 232 | /// | ||
| 233 | inline bool ATTRIBUTE_HIDDEN ShowMultiSelect(const std::string& heading, | ||
| 234 | std::vector<kodi::gui::dialogs::SSelectionEntry>& entries, | ||
| 235 | int autoclose = 0) | ||
| 236 | { | ||
| 237 | using namespace ::kodi::addon; | ||
| 238 | unsigned int size = static_cast<unsigned int>(entries.size()); | ||
| 239 | const char** cEntryIDs = static_cast<const char**>(malloc(size * sizeof(const char*))); | ||
| 240 | const char** cEntryNames = static_cast<const char**>(malloc(size * sizeof(const char*))); | ||
| 241 | bool* cEntriesSelected = static_cast<bool*>(malloc(size * sizeof(bool))); | ||
| 242 | for (unsigned int i = 0; i < size; ++i) | ||
| 243 | { | ||
| 244 | cEntryIDs[i] = entries[i].id.c_str(); | ||
| 245 | cEntryNames[i] = entries[i].name.c_str(); | ||
| 246 | cEntriesSelected[i] = entries[i].selected; | ||
| 247 | } | ||
| 248 | bool ret = CAddonBase::m_interface->toKodi->kodi_gui->dialogSelect->open_multi_select( | ||
| 249 | CAddonBase::m_interface->toKodi->kodiBase, heading.c_str(), cEntryIDs, cEntryNames, | ||
| 250 | cEntriesSelected, size, autoclose); | ||
| 251 | if (ret) | ||
| 252 | { | ||
| 253 | for (unsigned int i = 0; i < size; ++i) | ||
| 254 | entries[i].selected = cEntriesSelected[i]; | ||
| 255 | } | ||
| 256 | free(cEntryNames); | ||
| 257 | free(cEntryIDs); | ||
| 258 | free(cEntriesSelected); | ||
| 259 | return ret; | ||
| 260 | } | ||
| 261 | //------------------------------------------------------------------------------ | ||
| 262 | }; // namespace Select | ||
| 263 | /// @} | ||
| 264 | |||
| 265 | } /* namespace dialogs */ | ||
| 266 | } /* namespace gui */ | ||
| 267 | } /* namespace kodi */ | ||
| 268 | |||
| 269 | #endif /* __cplusplus */ | ||
diff --git a/xbmc/addons/kodi-dev-kit/include/kodi/gui/dialogs/TextViewer.h b/xbmc/addons/kodi-dev-kit/include/kodi/gui/dialogs/TextViewer.h new file mode 100644 index 0000000..42a86f3 --- /dev/null +++ b/xbmc/addons/kodi-dev-kit/include/kodi/gui/dialogs/TextViewer.h | |||
| @@ -0,0 +1,109 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (C) 2015-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 "../../AddonBase.h" | ||
| 12 | #include "../../c-api/gui/dialogs/text_viewer.h" | ||
| 13 | |||
| 14 | #ifdef __cplusplus | ||
| 15 | |||
| 16 | namespace kodi | ||
| 17 | { | ||
| 18 | namespace gui | ||
| 19 | { | ||
| 20 | namespace dialogs | ||
| 21 | { | ||
| 22 | |||
| 23 | //============================================================================== | ||
| 24 | /// @defgroup cpp_kodi_gui_dialogs_TextViewer Dialog Text Viewer | ||
| 25 | /// @ingroup cpp_kodi_gui_dialogs | ||
| 26 | /// @{ | ||
| 27 | /// @brief @cpp_namespace{ kodi::gui::dialogs::TextViewer } | ||
| 28 | /// **Text viewer dialog**\n | ||
| 29 | /// The text viewer dialog can be used to display descriptions, help texts or | ||
| 30 | /// other larger texts. | ||
| 31 | /// | ||
| 32 | /// In order to achieve a line break is a <b>\\n</b> directly in the text or | ||
| 33 | /// in the <em>"./resources/language/resource.language.??_??/strings.po"</em> | ||
| 34 | /// to call with <b>std::string kodi::general::GetLocalizedString(...);</b>. | ||
| 35 | /// | ||
| 36 | /// It has the header \ref TextViewer.h "#include <kodi/gui/dialogs/TextViewer.h>" | ||
| 37 | /// be included to enjoy it. | ||
| 38 | /// | ||
| 39 | namespace TextViewer | ||
| 40 | { | ||
| 41 | //============================================================================== | ||
| 42 | /// @ingroup cpp_kodi_gui_dialogs_TextViewer | ||
| 43 | /// @brief Show info text dialog | ||
| 44 | /// | ||
| 45 | /// @param[in] heading mall heading text | ||
| 46 | /// @param[in] text Showed text on dialog | ||
| 47 | /// | ||
| 48 | /// | ||
| 49 | ///------------------------------------------------------------------------- | ||
| 50 | /// | ||
| 51 | /// **Example:** | ||
| 52 | /// ~~~~~~~~~~~~~{.cpp} | ||
| 53 | /// #include <kodi/gui/dialogs/TextViewer.h> | ||
| 54 | /// | ||
| 55 | /// kodi::gui::dialogs::TextViewer::Show("The Wizard of Oz (1939 film)", | ||
| 56 | /// "The Wizard of Oz is a 1939 American musical comedy-drama fantasy film " | ||
| 57 | /// "produced by Metro-Goldwyn-Mayer, and the most well-known and commercially " | ||
| 58 | /// "successful adaptation based on the 1900 novel The Wonderful Wizard of Oz " | ||
| 59 | /// "by L. Frank Baum. The film stars Judy Garland as Dorothy Gale. The film" | ||
| 60 | /// "co-stars Terry the dog, billed as Toto; Ray Bolger, Jack Haley, Bert Lahr, " | ||
| 61 | /// "Frank Morgan, Billie Burke, Margaret Hamilton, with Charley Grapewin and " | ||
| 62 | /// "Clara Blandick, and the Singer Midgets as the Munchkins.\n" | ||
| 63 | /// "\n" | ||
| 64 | /// "Notable for its use of Technicolor, fantasy storytelling, musical score and " | ||
| 65 | /// "unusual characters, over the years it has become an icon of American popular " | ||
| 66 | /// "culture. It was nominated for six Academy Awards, including Best Picture but " | ||
| 67 | /// "lost to Gone with the Wind. It did win in two other categories including Best " | ||
| 68 | /// "Original Song for \"Over the Rainbow\". However, the film was a box office " | ||
| 69 | /// "disappointment on its initial release, earning only $3,017,000 on a $2,777,000 " | ||
| 70 | /// "budget, despite receiving largely positive reviews. It was MGM's most " | ||
| 71 | /// "expensive production at that time, and did not completely recoup the studio's " | ||
| 72 | /// "investment and turn a profit until theatrical re-releases starting in 1949.\n" | ||
| 73 | /// "\n" | ||
| 74 | /// "The 1956 broadcast television premiere of the film on CBS re-introduced the " | ||
| 75 | /// "film to the wider public and eventually made the presentation an annual " | ||
| 76 | /// "tradition, making it one of the most known films in cinema history. The " | ||
| 77 | /// "film was named the most-viewed motion picture on television syndication by " | ||
| 78 | /// "the Library of Congress who also included the film in its National Film " | ||
| 79 | /// "Registry in its inaugural year in 1989. Designation on the registry calls " | ||
| 80 | /// "for efforts to preserve it for being \"culturally, historically, and " | ||
| 81 | /// "aesthetically significant\". It is also one of the few films on UNESCO's " | ||
| 82 | /// "Memory of the World Register.\n" | ||
| 83 | /// "\n" | ||
| 84 | /// "The Wizard of Oz is often ranked on best-movie lists in critics' and public " | ||
| 85 | /// "polls. It is the source of many quotes referenced in modern popular culture. " | ||
| 86 | /// "It was directed primarily by Victor Fleming (who left production to take " | ||
| 87 | /// "over direction on the troubled Gone with the Wind production). Noel Langley, " | ||
| 88 | /// "Florence Ryerson and Edgar Allan Woolf received credit for the screenplay, " | ||
| 89 | /// "but there were uncredited contributions by others. The songs were written " | ||
| 90 | /// "by Edgar \"Yip\" Harburg (lyrics) and Harold Arlen (music). The incidental " | ||
| 91 | /// "music, based largely on the songs, was composed by Herbert Stothart, with " | ||
| 92 | /// "interspersed renderings from classical composers.\n"); | ||
| 93 | /// ~~~~~~~~~~~~~ | ||
| 94 | /// | ||
| 95 | inline void ATTRIBUTE_HIDDEN Show(const std::string& heading, const std::string& text) | ||
| 96 | { | ||
| 97 | using namespace ::kodi::addon; | ||
| 98 | CAddonBase::m_interface->toKodi->kodi_gui->dialogTextViewer->open( | ||
| 99 | CAddonBase::m_interface->toKodi->kodiBase, heading.c_str(), text.c_str()); | ||
| 100 | } | ||
| 101 | //------------------------------------------------------------------------------ | ||
| 102 | }; // namespace TextViewer | ||
| 103 | /// @} | ||
| 104 | |||
| 105 | } /* namespace dialogs */ | ||
| 106 | } /* namespace gui */ | ||
| 107 | } /* namespace kodi */ | ||
| 108 | |||
| 109 | #endif /* __cplusplus */ | ||
diff --git a/xbmc/addons/kodi-dev-kit/include/kodi/gui/dialogs/YesNo.h b/xbmc/addons/kodi-dev-kit/include/kodi/gui/dialogs/YesNo.h new file mode 100644 index 0000000..6e6e069 --- /dev/null +++ b/xbmc/addons/kodi-dev-kit/include/kodi/gui/dialogs/YesNo.h | |||
| @@ -0,0 +1,188 @@ | |||
| 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 "../../AddonBase.h" | ||
| 12 | #include "../../c-api/gui/dialogs/yes_no.h" | ||
| 13 | |||
| 14 | #ifdef __cplusplus | ||
| 15 | |||
| 16 | namespace kodi | ||
| 17 | { | ||
| 18 | namespace gui | ||
| 19 | { | ||
| 20 | namespace dialogs | ||
| 21 | { | ||
| 22 | |||
| 23 | //============================================================================== | ||
| 24 | /// @defgroup cpp_kodi_gui_dialogs_YesNo Dialog Yes/No | ||
| 25 | /// @ingroup cpp_kodi_gui_dialogs | ||
| 26 | /// @{ | ||
| 27 | /// @brief @cpp_namespace{ kodi::gui::dialogs::YesNo } | ||
| 28 | /// **Yes / No dialog**\n | ||
| 29 | /// The Yes / No dialog can be used to inform the user about questions and get | ||
| 30 | /// the answer. | ||
| 31 | /// | ||
| 32 | /// In order to achieve a line break is a <b>\\n</b> directly in the text or | ||
| 33 | /// in the <em>"./resources/language/resource.language.??_??/strings.po"</em> | ||
| 34 | /// to call with <b>std::string kodi::general::GetLocalizedString(...);</b>. | ||
| 35 | /// | ||
| 36 | /// It has the header @ref YesNo.h "#include <kodi/gui/dialogs/YesNo.h>" | ||
| 37 | /// be included to enjoy it. | ||
| 38 | /// | ||
| 39 | namespace YesNo | ||
| 40 | { | ||
| 41 | //============================================================================== | ||
| 42 | /// @ingroup cpp_kodi_gui_dialogs_YesNo | ||
| 43 | /// @brief Use dialog to get numeric new password with one text string shown | ||
| 44 | /// everywhere and cancel return field. | ||
| 45 | /// | ||
| 46 | /// @param[in] heading Dialog heading | ||
| 47 | /// @param[in] text Multi-line text | ||
| 48 | /// @param[out] canceled Return value about cancel button | ||
| 49 | /// @param[in] noLabel [opt] label to put on the no button | ||
| 50 | /// @param[in] yesLabel [opt] label to put on the yes button | ||
| 51 | /// @return Returns True if 'Yes' was pressed, else False | ||
| 52 | /// | ||
| 53 | /// @note It is preferred to only use this as it is actually a multi-line text. | ||
| 54 | /// | ||
| 55 | /// | ||
| 56 | ///------------------------------------------------------------------------- | ||
| 57 | /// | ||
| 58 | /// **Example:** | ||
| 59 | /// ~~~~~~~~~~~~~{.cpp} | ||
| 60 | /// #include <kodi/gui/dialogs/YesNo.h> | ||
| 61 | /// | ||
| 62 | /// bool canceled = false; | ||
| 63 | /// bool ret = kodi::gui::dialogs::YesNo::ShowAndGetInput( | ||
| 64 | /// "Yes / No test call", // The Header | ||
| 65 | /// "You has opened Yes / No dialog for test\n\nIs this OK for you?", | ||
| 66 | /// canceled, // return value about cancel button | ||
| 67 | /// "Not really", // No label, is optional and if empty "No" | ||
| 68 | /// "Ohhh yes"); // Yes label, also optional and if empty "Yes" | ||
| 69 | /// fprintf(stderr, "You has called Yes/No, returned '%s' and was %s\n", | ||
| 70 | /// ret ? "yes" : "no", | ||
| 71 | /// canceled ? "canceled" : "not canceled"); | ||
| 72 | /// ~~~~~~~~~~~~~ | ||
| 73 | /// | ||
| 74 | inline bool ATTRIBUTE_HIDDEN ShowAndGetInput(const std::string& heading, | ||
| 75 | const std::string& text, | ||
| 76 | bool& canceled, | ||
| 77 | const std::string& noLabel = "", | ||
| 78 | const std::string& yesLabel = "") | ||
| 79 | { | ||
| 80 | using namespace ::kodi::addon; | ||
| 81 | return CAddonBase::m_interface->toKodi->kodi_gui->dialogYesNo->show_and_get_input_single_text( | ||
| 82 | CAddonBase::m_interface->toKodi->kodiBase, heading.c_str(), text.c_str(), &canceled, | ||
| 83 | noLabel.c_str(), yesLabel.c_str()); | ||
| 84 | } | ||
| 85 | //------------------------------------------------------------------------------ | ||
| 86 | |||
| 87 | //============================================================================== | ||
| 88 | /// @ingroup cpp_kodi_gui_dialogs_YesNo | ||
| 89 | /// @brief Use dialog to get numeric new password with separated line strings. | ||
| 90 | /// | ||
| 91 | /// @param[in] heading Dialog heading | ||
| 92 | /// @param[in] line0 Line #0 text | ||
| 93 | /// @param[in] line1 Line #1 text | ||
| 94 | /// @param[in] line2 Line #2 text | ||
| 95 | /// @param[in] noLabel [opt] label to put on the no button | ||
| 96 | /// @param[in] yesLabel [opt] label to put on the yes button | ||
| 97 | /// @return Returns True if 'Yes' was pressed, else False | ||
| 98 | /// | ||
| 99 | /// | ||
| 100 | ///------------------------------------------------------------------------- | ||
| 101 | /// | ||
| 102 | /// **Example:** | ||
| 103 | /// ~~~~~~~~~~~~~{.cpp} | ||
| 104 | /// #include <kodi/gui/dialogs/YesNo.h> | ||
| 105 | /// | ||
| 106 | /// bool ret = kodi::gui::dialogs::YesNo::ShowAndGetInput( | ||
| 107 | /// "Yes / No test call", // The Header | ||
| 108 | /// "You has opened Yes / No dialog for test", | ||
| 109 | /// "", | ||
| 110 | /// "Is this OK for you?", | ||
| 111 | /// "Not really", // No label, is optional and if empty "No" | ||
| 112 | /// "Ohhh yes"); // Yes label, also optional and if empty "Yes" | ||
| 113 | /// fprintf(stderr, "You has called Yes/No, returned '%s'\n", | ||
| 114 | /// ret ? "yes" : "no"); | ||
| 115 | /// ~~~~~~~~~~~~~ | ||
| 116 | /// | ||
| 117 | inline bool ATTRIBUTE_HIDDEN ShowAndGetInput(const std::string& heading, | ||
| 118 | const std::string& line0, | ||
| 119 | const std::string& line1, | ||
| 120 | const std::string& line2, | ||
| 121 | const std::string& noLabel = "", | ||
| 122 | const std::string& yesLabel = "") | ||
| 123 | { | ||
| 124 | using namespace ::kodi::addon; | ||
| 125 | return CAddonBase::m_interface->toKodi->kodi_gui->dialogYesNo->show_and_get_input_line_text( | ||
| 126 | CAddonBase::m_interface->toKodi->kodiBase, heading.c_str(), line0.c_str(), line1.c_str(), | ||
| 127 | line2.c_str(), noLabel.c_str(), yesLabel.c_str()); | ||
| 128 | } | ||
| 129 | //------------------------------------------------------------------------------ | ||
| 130 | |||
| 131 | //============================================================================== | ||
| 132 | /// @ingroup cpp_kodi_gui_dialogs_YesNo | ||
| 133 | /// @brief Use dialog to get numeric new password with separated line strings | ||
| 134 | /// and cancel return field. | ||
| 135 | /// | ||
| 136 | /// @param[in] heading Dialog heading | ||
| 137 | /// @param[in] line0 Line #0 text | ||
| 138 | /// @param[in] line1 Line #1 text | ||
| 139 | /// @param[in] line2 Line #2 text | ||
| 140 | /// @param[out] canceled Return value about cancel button | ||
| 141 | /// @param[in] noLabel [opt] label to put on the no button | ||
| 142 | /// @param[in] yesLabel [opt] label to put on the yes button | ||
| 143 | /// @return Returns True if 'Yes' was pressed, else False | ||
| 144 | /// | ||
| 145 | /// | ||
| 146 | ///------------------------------------------------------------------------- | ||
| 147 | /// | ||
| 148 | /// **Example:** | ||
| 149 | /// ~~~~~~~~~~~~~{.cpp} | ||
| 150 | /// #include <kodi/gui/dialogs/YesNo.h> | ||
| 151 | /// | ||
| 152 | /// bool canceled = false; | ||
| 153 | /// bool ret = kodi::gui::dialogs::YesNo::ShowAndGetInput( | ||
| 154 | /// "Yes / No test call", // The Header | ||
| 155 | /// "You has opened Yes / No dialog for test", | ||
| 156 | /// "", | ||
| 157 | /// "Is this OK for you?", | ||
| 158 | /// canceled, // return value about cancel button | ||
| 159 | /// "Not really", // No label, is optional and if empty "No" | ||
| 160 | /// "Ohhh yes"); // Yes label, also optional and if empty "Yes" | ||
| 161 | /// fprintf(stderr, "You has called Yes/No, returned '%s' and was %s\n", | ||
| 162 | /// ret ? "yes" : "no", | ||
| 163 | /// canceled ? "canceled" : "not canceled"); | ||
| 164 | /// ~~~~~~~~~~~~~ | ||
| 165 | /// | ||
| 166 | inline bool ATTRIBUTE_HIDDEN ShowAndGetInput(const std::string& heading, | ||
| 167 | const std::string& line0, | ||
| 168 | const std::string& line1, | ||
| 169 | const std::string& line2, | ||
| 170 | bool& canceled, | ||
| 171 | const std::string& noLabel = "", | ||
| 172 | const std::string& yesLabel = "") | ||
| 173 | { | ||
| 174 | using namespace ::kodi::addon; | ||
| 175 | return CAddonBase::m_interface->toKodi->kodi_gui->dialogYesNo | ||
| 176 | ->show_and_get_input_line_button_text( | ||
| 177 | CAddonBase::m_interface->toKodi->kodiBase, heading.c_str(), line0.c_str(), line1.c_str(), | ||
| 178 | line2.c_str(), &canceled, noLabel.c_str(), yesLabel.c_str()); | ||
| 179 | } | ||
| 180 | //------------------------------------------------------------------------------ | ||
| 181 | }; // namespace YesNo | ||
| 182 | /// @} | ||
| 183 | |||
| 184 | } /* namespace dialogs */ | ||
| 185 | } /* namespace gui */ | ||
| 186 | } /* namespace kodi */ | ||
| 187 | |||
| 188 | #endif /* __cplusplus */ | ||
diff --git a/xbmc/addons/kodi-dev-kit/include/kodi/gui/gl/CMakeLists.txt b/xbmc/addons/kodi-dev-kit/include/kodi/gui/gl/CMakeLists.txt new file mode 100644 index 0000000..844902d --- /dev/null +++ b/xbmc/addons/kodi-dev-kit/include/kodi/gui/gl/CMakeLists.txt | |||
| @@ -0,0 +1,7 @@ | |||
| 1 | set(HEADERS GL.h | ||
| 2 | GLonDX.h | ||
| 3 | Shader.h) | ||
| 4 | |||
| 5 | if(NOT ENABLE_STATIC_LIBS) | ||
| 6 | core_add_library(addons_kodi-dev-kit_include_kodi_gui_gl) | ||
| 7 | endif() | ||
diff --git a/xbmc/addons/kodi-dev-kit/include/kodi/gui/gl/GL.h b/xbmc/addons/kodi-dev-kit/include/kodi/gui/gl/GL.h new file mode 100644 index 0000000..16d43e3 --- /dev/null +++ b/xbmc/addons/kodi-dev-kit/include/kodi/gui/gl/GL.h | |||
| @@ -0,0 +1,112 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (C) 2005-2019 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 | #ifdef __cplusplus | ||
| 12 | |||
| 13 | //============================================================================== | ||
| 14 | /// @defgroup cpp_kodi_gui_helpers_gl OpenGL helpers | ||
| 15 | /// @ingroup cpp_kodi_gui_helpers | ||
| 16 | /// @brief **Auxiliary functions for Open GL**\n | ||
| 17 | /// This group includes help for definitions, functions, and classes for | ||
| 18 | /// OpenGL. | ||
| 19 | /// | ||
| 20 | /// To use OpenGL for your system, add the @ref GL.h "#include <kodi/gui/gl/GL.h>". | ||
| 21 | /// | ||
| 22 | /// The @ref HAS_GL is declared if Open GL is required and @ref HAS_GLES if Open GL | ||
| 23 | /// Embedded Systems (ES) is required, with ES the version is additionally given | ||
| 24 | /// in the definition, this can be "2" or "3". | ||
| 25 | /// | ||
| 26 | /// | ||
| 27 | ///----------------------------------------------------------------------------- | ||
| 28 | /// | ||
| 29 | /// Following @ref GL_TYPE_STRING define can be used, for example, to manage | ||
| 30 | /// different folders for GL and GLES and make the selection easier. | ||
| 31 | /// This are on OpenGL <b>"GL"</b> and on Open GL|ES <b>"GLES"</b>. | ||
| 32 | /// | ||
| 33 | /// **Example:** | ||
| 34 | /// ~~~~~~~~~~~~~~~~~{.cpp} | ||
| 35 | /// kodi::GetAddonPath("resources/shaders/" GL_TYPE_STRING "/frag.glsl"); | ||
| 36 | /// ~~~~~~~~~~~~~~~~~ | ||
| 37 | /// | ||
| 38 | /// | ||
| 39 | ///---------------------------------------------------------------------------- | ||
| 40 | /// | ||
| 41 | /// In addition, @ref BUFFER_OFFSET is declared in it which can be used to give an | ||
| 42 | /// offset on the array to GL. | ||
| 43 | /// | ||
| 44 | /// **Example:** | ||
| 45 | /// ~~~~~~~~~~~~~~~~~{.cpp} | ||
| 46 | /// const struct PackedVertex { | ||
| 47 | /// float position[3]; // Position x, y, z | ||
| 48 | /// float color[4]; // Color r, g, b, a | ||
| 49 | /// } vertices[3] = { | ||
| 50 | /// { { -0.5f, -0.5f, 0.0f }, { 1.0f, 0.0f, 0.0f, 1.0f } }, | ||
| 51 | /// { { 0.5f, -0.5f, 0.0f }, { 0.0f, 1.0f, 0.0f, 1.0f } }, | ||
| 52 | /// { { 0.0f, 0.5f, 0.0f }, { 0.0f, 0.0f, 1.0f, 1.0f } } | ||
| 53 | /// }; | ||
| 54 | /// | ||
| 55 | /// glVertexAttribPointer(m_aPosition, 3, GL_FLOAT, GL_FALSE, sizeof(PackedVertex), BUFFER_OFFSET(offsetof(PackedVertex, position))); | ||
| 56 | /// glEnableVertexAttribArray(m_aPosition); | ||
| 57 | /// | ||
| 58 | /// glVertexAttribPointer(m_aColor, 4, GL_FLOAT, GL_FALSE, sizeof(PackedVertex), BUFFER_OFFSET(offsetof(PackedVertex, color))); | ||
| 59 | /// glEnableVertexAttribArray(m_aColor); | ||
| 60 | /// ~~~~~~~~~~~~~~~~~ | ||
| 61 | |||
| 62 | #if HAS_GL | ||
| 63 | #define GL_TYPE_STRING "GL" | ||
| 64 | // always define GL_GLEXT_PROTOTYPES before include gl headers | ||
| 65 | #if !defined(GL_GLEXT_PROTOTYPES) | ||
| 66 | #define GL_GLEXT_PROTOTYPES | ||
| 67 | #endif | ||
| 68 | #if defined(TARGET_LINUX) | ||
| 69 | #include <GL/gl.h> | ||
| 70 | #include <GL/glext.h> | ||
| 71 | #elif defined(TARGET_FREEBSD) | ||
| 72 | #include <GL/gl.h> | ||
| 73 | #elif defined(TARGET_DARWIN) | ||
| 74 | #include <OpenGL/gl3.h> | ||
| 75 | #include <OpenGL/gl3ext.h> | ||
| 76 | #elif defined(WIN32) | ||
| 77 | #error Use of GL under Windows is not possible | ||
| 78 | #endif | ||
| 79 | #elif HAS_GLES >= 2 | ||
| 80 | #define GL_TYPE_STRING "GLES" | ||
| 81 | #if defined(WIN32) | ||
| 82 | #if defined(HAS_ANGLE) | ||
| 83 | #include <angle_gl.h> | ||
| 84 | #else | ||
| 85 | #error Use of GLES only be available under Windows by the use of angle | ||
| 86 | #endif | ||
| 87 | #elif defined(TARGET_DARWIN) | ||
| 88 | #if HAS_GLES == 3 | ||
| 89 | #include <OpenGLES/ES3/gl.h> | ||
| 90 | #include <OpenGLES/ES3/glext.h> | ||
| 91 | #else | ||
| 92 | #include <OpenGLES/ES2/gl.h> | ||
| 93 | #include <OpenGLES/ES2/glext.h> | ||
| 94 | #endif | ||
| 95 | #else | ||
| 96 | #if HAS_GLES == 3 | ||
| 97 | #include <GLES3/gl3.h> | ||
| 98 | #include <GLES3/gl3ext.h> | ||
| 99 | #else | ||
| 100 | #include <GLES2/gl2.h> | ||
| 101 | #include <GLES2/gl2ext.h> | ||
| 102 | #endif | ||
| 103 | #endif | ||
| 104 | #endif | ||
| 105 | |||
| 106 | #ifndef BUFFER_OFFSET | ||
| 107 | /// @ingroup cpp_kodi_gui_helpers_gl | ||
| 108 | /// @brief To give a offset number as pointer value. | ||
| 109 | #define BUFFER_OFFSET(i) ((char*)nullptr + (i)) | ||
| 110 | #endif | ||
| 111 | |||
| 112 | #endif /* __cplusplus */ | ||
diff --git a/xbmc/addons/kodi-dev-kit/include/kodi/gui/gl/GLonDX.h b/xbmc/addons/kodi-dev-kit/include/kodi/gui/gl/GLonDX.h new file mode 100644 index 0000000..4dd97af --- /dev/null +++ b/xbmc/addons/kodi-dev-kit/include/kodi/gui/gl/GLonDX.h | |||
| @@ -0,0 +1,389 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (C) 2005-2019 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 | #ifdef __cplusplus | ||
| 12 | |||
| 13 | #include <EGL/egl.h> | ||
| 14 | #include <EGL/eglext.h> | ||
| 15 | #include <angle_gl.h> | ||
| 16 | #include <d3d11.h> | ||
| 17 | #include <d3dcompiler.h> | ||
| 18 | #include <kodi/AddonBase.h> | ||
| 19 | #include <kodi/gui/General.h> | ||
| 20 | #include <wrl/client.h> | ||
| 21 | |||
| 22 | #pragma comment(lib, "d3dcompiler.lib") | ||
| 23 | #ifndef GL_CLIENT_VERSION | ||
| 24 | #define GL_CLIENT_VERSION 3 | ||
| 25 | #endif | ||
| 26 | |||
| 27 | namespace kodi | ||
| 28 | { | ||
| 29 | namespace gui | ||
| 30 | { | ||
| 31 | namespace gl | ||
| 32 | { | ||
| 33 | |||
| 34 | class ATTRIBUTE_HIDDEN CGLonDX : public kodi::gui::IRenderHelper | ||
| 35 | { | ||
| 36 | public: | ||
| 37 | explicit CGLonDX() : m_pContext(reinterpret_cast<ID3D11DeviceContext*>(kodi::gui::GetHWContext())) | ||
| 38 | { | ||
| 39 | } | ||
| 40 | ~CGLonDX() override { destruct(); } | ||
| 41 | |||
| 42 | bool Init() override | ||
| 43 | { | ||
| 44 | EGLint egl_display_attrs[] = {EGL_PLATFORM_ANGLE_TYPE_ANGLE, | ||
| 45 | EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE, | ||
| 46 | EGL_PLATFORM_ANGLE_MAX_VERSION_MAJOR_ANGLE, | ||
| 47 | EGL_DONT_CARE, | ||
| 48 | EGL_PLATFORM_ANGLE_MAX_VERSION_MAJOR_ANGLE, | ||
| 49 | EGL_DONT_CARE, | ||
| 50 | EGL_EXPERIMENTAL_PRESENT_PATH_ANGLE, | ||
| 51 | EGL_EXPERIMENTAL_PRESENT_PATH_FAST_ANGLE, | ||
| 52 | EGL_NONE}; | ||
| 53 | EGLint egl_config_attrs[] = {EGL_RED_SIZE, | ||
| 54 | 8, | ||
| 55 | EGL_GREEN_SIZE, | ||
| 56 | 8, | ||
| 57 | EGL_BLUE_SIZE, | ||
| 58 | 8, | ||
| 59 | EGL_ALPHA_SIZE, | ||
| 60 | 8, | ||
| 61 | EGL_BIND_TO_TEXTURE_RGBA, | ||
| 62 | EGL_TRUE, | ||
| 63 | EGL_RENDERABLE_TYPE, | ||
| 64 | GL_CLIENT_VERSION == 3 ? EGL_OPENGL_ES3_BIT : EGL_OPENGL_ES2_BIT, | ||
| 65 | EGL_SURFACE_TYPE, | ||
| 66 | EGL_PBUFFER_BIT, | ||
| 67 | EGL_NONE}; | ||
| 68 | EGLint egl_context_attrs[] = {EGL_CONTEXT_CLIENT_VERSION, GL_CLIENT_VERSION, EGL_NONE}; | ||
| 69 | |||
| 70 | m_eglDisplay = | ||
| 71 | eglGetPlatformDisplayEXT(EGL_PLATFORM_ANGLE_ANGLE, EGL_DEFAULT_DISPLAY, egl_display_attrs); | ||
| 72 | if (m_eglDisplay == EGL_NO_DISPLAY) | ||
| 73 | { | ||
| 74 | Log(ADDON_LOG_ERROR, "GLonDX: unable to get EGL display (%s)", eglGetErrorString()); | ||
| 75 | return false; | ||
| 76 | } | ||
| 77 | |||
| 78 | if (eglInitialize(m_eglDisplay, nullptr, nullptr) != EGL_TRUE) | ||
| 79 | { | ||
| 80 | Log(ADDON_LOG_ERROR, "GLonDX: unable to init EGL display (%s)", eglGetErrorString()); | ||
| 81 | return false; | ||
| 82 | } | ||
| 83 | |||
| 84 | EGLint numConfigs = 0; | ||
| 85 | if (eglChooseConfig(m_eglDisplay, egl_config_attrs, &m_eglConfig, 1, &numConfigs) != EGL_TRUE || | ||
| 86 | numConfigs == 0) | ||
| 87 | { | ||
| 88 | Log(ADDON_LOG_ERROR, "GLonDX: unable to get EGL config (%s)", eglGetErrorString()); | ||
| 89 | return false; | ||
| 90 | } | ||
| 91 | |||
| 92 | m_eglContext = eglCreateContext(m_eglDisplay, m_eglConfig, nullptr, egl_context_attrs); | ||
| 93 | if (m_eglContext == EGL_NO_CONTEXT) | ||
| 94 | { | ||
| 95 | Log(ADDON_LOG_ERROR, "GLonDX: unable to create EGL context (%s)", eglGetErrorString()); | ||
| 96 | return false; | ||
| 97 | } | ||
| 98 | |||
| 99 | if (!createD3DResources()) | ||
| 100 | return false; | ||
| 101 | |||
| 102 | if (eglMakeCurrent(m_eglDisplay, m_eglBuffer, m_eglBuffer, m_eglContext) != EGL_TRUE) | ||
| 103 | { | ||
| 104 | Log(ADDON_LOG_ERROR, "GLonDX: unable to make current EGL (%s)", eglGetErrorString()); | ||
| 105 | return false; | ||
| 106 | } | ||
| 107 | return true; | ||
| 108 | } | ||
| 109 | |||
| 110 | void CheckGL(ID3D11DeviceContext* device) | ||
| 111 | { | ||
| 112 | if (m_pContext != device) | ||
| 113 | { | ||
| 114 | m_pSRView = nullptr; | ||
| 115 | m_pVShader = nullptr; | ||
| 116 | m_pPShader = nullptr; | ||
| 117 | m_pContext = device; | ||
| 118 | |||
| 119 | if (m_eglBuffer != EGL_NO_SURFACE) | ||
| 120 | { | ||
| 121 | eglMakeCurrent(m_eglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); | ||
| 122 | eglDestroySurface(m_eglDisplay, m_eglBuffer); | ||
| 123 | m_eglBuffer = EGL_NO_SURFACE; | ||
| 124 | } | ||
| 125 | |||
| 126 | // create new resources | ||
| 127 | if (!createD3DResources()) | ||
| 128 | return; | ||
| 129 | |||
| 130 | eglMakeCurrent(m_eglDisplay, m_eglBuffer, m_eglBuffer, m_eglContext); | ||
| 131 | } | ||
| 132 | } | ||
| 133 | |||
| 134 | void Begin() override | ||
| 135 | { | ||
| 136 | // confirm on begin D3D context is correct | ||
| 137 | CheckGL(reinterpret_cast<ID3D11DeviceContext*>(kodi::gui::GetHWContext())); | ||
| 138 | |||
| 139 | glClearColor(0.0f, 0.0f, 0.0f, 1.0f); | ||
| 140 | glClear(GL_COLOR_BUFFER_BIT); | ||
| 141 | } | ||
| 142 | |||
| 143 | void End() override | ||
| 144 | { | ||
| 145 | glFlush(); | ||
| 146 | |||
| 147 | // set our primitive shaders | ||
| 148 | m_pContext->VSSetShader(m_pVShader.Get(), nullptr, 0); | ||
| 149 | m_pContext->PSSetShader(m_pPShader.Get(), nullptr, 0); | ||
| 150 | m_pContext->PSSetShaderResources(0, 1, m_pSRView.GetAddressOf()); | ||
| 151 | // draw texture | ||
| 152 | m_pContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP); | ||
| 153 | m_pContext->IASetVertexBuffers(0, 0, nullptr, nullptr, nullptr); | ||
| 154 | m_pContext->IASetInputLayout(nullptr); | ||
| 155 | m_pContext->Draw(4, 0); | ||
| 156 | // unset shaders | ||
| 157 | m_pContext->PSSetShader(nullptr, nullptr, 0); | ||
| 158 | m_pContext->VSSetShader(nullptr, nullptr, 0); | ||
| 159 | // unbind our view | ||
| 160 | ID3D11ShaderResourceView* views[1] = {}; | ||
| 161 | m_pContext->PSSetShaderResources(0, 1, views); | ||
| 162 | } | ||
| 163 | |||
| 164 | private: | ||
| 165 | enum ShaderType | ||
| 166 | { | ||
| 167 | VERTEX_SHADER, | ||
| 168 | PIXEL_SHADER | ||
| 169 | }; | ||
| 170 | |||
| 171 | bool createD3DResources() | ||
| 172 | { | ||
| 173 | HANDLE sharedHandle; | ||
| 174 | Microsoft::WRL::ComPtr<ID3D11Device> pDevice; | ||
| 175 | Microsoft::WRL::ComPtr<ID3D11RenderTargetView> pRTView; | ||
| 176 | Microsoft::WRL::ComPtr<ID3D11Resource> pRTResource; | ||
| 177 | Microsoft::WRL::ComPtr<ID3D11Texture2D> pRTTexture; | ||
| 178 | Microsoft::WRL::ComPtr<ID3D11Texture2D> pOffScreenTexture; | ||
| 179 | Microsoft::WRL::ComPtr<IDXGIResource> dxgiResource; | ||
| 180 | |||
| 181 | m_pContext->GetDevice(&pDevice); | ||
| 182 | m_pContext->OMGetRenderTargets(1, &pRTView, nullptr); | ||
| 183 | if (!pRTView) | ||
| 184 | return false; | ||
| 185 | |||
| 186 | pRTView->GetResource(&pRTResource); | ||
| 187 | if (FAILED(pRTResource.As(&pRTTexture))) | ||
| 188 | return false; | ||
| 189 | |||
| 190 | D3D11_TEXTURE2D_DESC texDesc; | ||
| 191 | pRTTexture->GetDesc(&texDesc); | ||
| 192 | texDesc.Format = DXGI_FORMAT_B8G8R8A8_UNORM; | ||
| 193 | texDesc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_RENDER_TARGET; | ||
| 194 | texDesc.MiscFlags = D3D11_RESOURCE_MISC_SHARED; | ||
| 195 | if (FAILED(pDevice->CreateTexture2D(&texDesc, nullptr, &pOffScreenTexture))) | ||
| 196 | { | ||
| 197 | Log(ADDON_LOG_ERROR, "GLonDX: unable to create intermediate texture"); | ||
| 198 | return false; | ||
| 199 | } | ||
| 200 | |||
| 201 | CD3D11_SHADER_RESOURCE_VIEW_DESC srvDesc(pOffScreenTexture.Get(), | ||
| 202 | D3D11_SRV_DIMENSION_TEXTURE2D); | ||
| 203 | if (FAILED(pDevice->CreateShaderResourceView(pOffScreenTexture.Get(), &srvDesc, &m_pSRView))) | ||
| 204 | { | ||
| 205 | Log(ADDON_LOG_ERROR, "GLonDX: unable to create shader view"); | ||
| 206 | return false; | ||
| 207 | } | ||
| 208 | |||
| 209 | if (FAILED(pOffScreenTexture.As(&dxgiResource)) || | ||
| 210 | FAILED(dxgiResource->GetSharedHandle(&sharedHandle))) | ||
| 211 | { | ||
| 212 | Log(ADDON_LOG_ERROR, "GLonDX: unable get shared handle for texture"); | ||
| 213 | return false; | ||
| 214 | } | ||
| 215 | |||
| 216 | // initiate simple shaders | ||
| 217 | if (FAILED(d3dCreateShader(VERTEX_SHADER, vs_out_shader_text, &m_pVShader))) | ||
| 218 | { | ||
| 219 | Log(ADDON_LOG_ERROR, "GLonDX: unable to create vertex shader view"); | ||
| 220 | return false; | ||
| 221 | } | ||
| 222 | |||
| 223 | if (FAILED(d3dCreateShader(PIXEL_SHADER, ps_out_shader_text, &m_pPShader))) | ||
| 224 | { | ||
| 225 | Log(ADDON_LOG_ERROR, "GLonDX: unable to create pixel shader view"); | ||
| 226 | return false; | ||
| 227 | } | ||
| 228 | |||
| 229 | // create EGL buffer from D3D shared texture | ||
| 230 | EGLint egl_buffer_attrs[] = {EGL_WIDTH, | ||
| 231 | static_cast<EGLint>(texDesc.Width), | ||
| 232 | EGL_HEIGHT, | ||
| 233 | static_cast<EGLint>(texDesc.Height), | ||
| 234 | EGL_TEXTURE_TARGET, | ||
| 235 | EGL_TEXTURE_2D, | ||
| 236 | EGL_TEXTURE_FORMAT, | ||
| 237 | EGL_TEXTURE_RGBA, | ||
| 238 | EGL_NONE}; | ||
| 239 | |||
| 240 | m_eglBuffer = | ||
| 241 | eglCreatePbufferFromClientBuffer(m_eglDisplay, EGL_D3D_TEXTURE_2D_SHARE_HANDLE_ANGLE, | ||
| 242 | sharedHandle, m_eglConfig, egl_buffer_attrs); | ||
| 243 | |||
| 244 | if (m_eglBuffer == EGL_NO_SURFACE) | ||
| 245 | { | ||
| 246 | Log(ADDON_LOG_ERROR, "GLonDX: unable to create EGL buffer (%s)", eglGetErrorString()); | ||
| 247 | return false; | ||
| 248 | } | ||
| 249 | return true; | ||
| 250 | } | ||
| 251 | |||
| 252 | HRESULT d3dCreateShader(ShaderType shaderType, | ||
| 253 | const std::string& source, | ||
| 254 | IUnknown** ppShader) const | ||
| 255 | { | ||
| 256 | Microsoft::WRL::ComPtr<ID3DBlob> pBlob; | ||
| 257 | Microsoft::WRL::ComPtr<ID3DBlob> pErrors; | ||
| 258 | |||
| 259 | auto hr = D3DCompile(source.c_str(), source.length(), nullptr, nullptr, nullptr, "main", | ||
| 260 | shaderType == PIXEL_SHADER ? "ps_4_0" : "vs_4_0", 0, 0, &pBlob, &pErrors); | ||
| 261 | |||
| 262 | if (SUCCEEDED(hr)) | ||
| 263 | { | ||
| 264 | Microsoft::WRL::ComPtr<ID3D11Device> pDevice; | ||
| 265 | m_pContext->GetDevice(&pDevice); | ||
| 266 | |||
| 267 | if (shaderType == PIXEL_SHADER) | ||
| 268 | { | ||
| 269 | hr = pDevice->CreatePixelShader(pBlob->GetBufferPointer(), pBlob->GetBufferSize(), nullptr, | ||
| 270 | reinterpret_cast<ID3D11PixelShader**>(ppShader)); | ||
| 271 | } | ||
| 272 | else | ||
| 273 | { | ||
| 274 | hr = pDevice->CreateVertexShader(pBlob->GetBufferPointer(), pBlob->GetBufferSize(), nullptr, | ||
| 275 | reinterpret_cast<ID3D11VertexShader**>(ppShader)); | ||
| 276 | } | ||
| 277 | |||
| 278 | if (FAILED(hr)) | ||
| 279 | { | ||
| 280 | Log(ADDON_LOG_ERROR, "GLonDX: unable to create %s shader", | ||
| 281 | shaderType == PIXEL_SHADER ? "pixel" : "vertex"); | ||
| 282 | } | ||
| 283 | } | ||
| 284 | else | ||
| 285 | { | ||
| 286 | Log(ADDON_LOG_ERROR, "GLonDX: unable to compile shader (%s)", pErrors->GetBufferPointer()); | ||
| 287 | } | ||
| 288 | return hr; | ||
| 289 | } | ||
| 290 | |||
| 291 | static const char* eglGetErrorString() | ||
| 292 | { | ||
| 293 | #define CASE_STR(value) \ | ||
| 294 | case value: \ | ||
| 295 | return #value | ||
| 296 | switch (eglGetError()) | ||
| 297 | { | ||
| 298 | CASE_STR(EGL_SUCCESS); | ||
| 299 | CASE_STR(EGL_NOT_INITIALIZED); | ||
| 300 | CASE_STR(EGL_BAD_ACCESS); | ||
| 301 | CASE_STR(EGL_BAD_ALLOC); | ||
| 302 | CASE_STR(EGL_BAD_ATTRIBUTE); | ||
| 303 | CASE_STR(EGL_BAD_CONTEXT); | ||
| 304 | CASE_STR(EGL_BAD_CONFIG); | ||
| 305 | CASE_STR(EGL_BAD_CURRENT_SURFACE); | ||
| 306 | CASE_STR(EGL_BAD_DISPLAY); | ||
| 307 | CASE_STR(EGL_BAD_SURFACE); | ||
| 308 | CASE_STR(EGL_BAD_MATCH); | ||
| 309 | CASE_STR(EGL_BAD_PARAMETER); | ||
| 310 | CASE_STR(EGL_BAD_NATIVE_PIXMAP); | ||
| 311 | CASE_STR(EGL_BAD_NATIVE_WINDOW); | ||
| 312 | CASE_STR(EGL_CONTEXT_LOST); | ||
| 313 | default: | ||
| 314 | return "Unknown"; | ||
| 315 | } | ||
| 316 | #undef CASE_STR | ||
| 317 | } | ||
| 318 | |||
| 319 | void destruct() | ||
| 320 | { | ||
| 321 | if (m_eglDisplay != EGL_NO_DISPLAY) | ||
| 322 | { | ||
| 323 | eglMakeCurrent(m_eglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); | ||
| 324 | |||
| 325 | if (m_eglBuffer != EGL_NO_SURFACE) | ||
| 326 | { | ||
| 327 | eglDestroySurface(m_eglDisplay, m_eglBuffer); | ||
| 328 | m_eglBuffer = EGL_NO_SURFACE; | ||
| 329 | } | ||
| 330 | |||
| 331 | if (m_eglContext != EGL_NO_CONTEXT) | ||
| 332 | { | ||
| 333 | eglDestroyContext(m_eglDisplay, m_eglContext); | ||
| 334 | m_eglContext = EGL_NO_CONTEXT; | ||
| 335 | } | ||
| 336 | |||
| 337 | eglTerminate(m_eglDisplay); | ||
| 338 | m_eglDisplay = EGL_NO_DISPLAY; | ||
| 339 | } | ||
| 340 | |||
| 341 | m_pSRView = nullptr; | ||
| 342 | m_pVShader = nullptr; | ||
| 343 | m_pPShader = nullptr; | ||
| 344 | m_pContext = nullptr; | ||
| 345 | } | ||
| 346 | |||
| 347 | EGLConfig m_eglConfig = EGL_NO_CONFIG_KHR; | ||
| 348 | EGLDisplay m_eglDisplay = EGL_NO_DISPLAY; | ||
| 349 | EGLContext m_eglContext = EGL_NO_CONTEXT; | ||
| 350 | EGLSurface m_eglBuffer = EGL_NO_SURFACE; | ||
| 351 | |||
| 352 | ID3D11DeviceContext* m_pContext = nullptr; // don't hold context | ||
| 353 | Microsoft::WRL::ComPtr<ID3D11ShaderResourceView> m_pSRView = nullptr; | ||
| 354 | Microsoft::WRL::ComPtr<ID3D11VertexShader> m_pVShader = nullptr; | ||
| 355 | Microsoft::WRL::ComPtr<ID3D11PixelShader> m_pPShader = nullptr; | ||
| 356 | |||
| 357 | #define TO_STRING(...) #__VA_ARGS__ | ||
| 358 | std::string vs_out_shader_text = TO_STRING(void main(uint id | ||
| 359 | : SV_VertexId, out float2 tex | ||
| 360 | : TEXCOORD0, out float4 pos | ||
| 361 | : SV_POSITION) { | ||
| 362 | tex = float2(id % 2, (id % 4) >> 1); | ||
| 363 | pos = float4((tex.x - 0.5f) * 2, -(tex.y - 0.5f) * 2, 0, 1); | ||
| 364 | }); | ||
| 365 | |||
| 366 | std::string ps_out_shader_text = TO_STRING( | ||
| 367 | Texture2D texMain : register(t0); | ||
| 368 | SamplerState Sampler | ||
| 369 | { | ||
| 370 | Filter = MIN_MAG_MIP_LINEAR; | ||
| 371 | AddressU = CLAMP; | ||
| 372 | AddressV = CLAMP; | ||
| 373 | Comparison = NEVER; | ||
| 374 | }; | ||
| 375 | |||
| 376 | float4 main(in float2 tex : TEXCOORD0) : SV_TARGET | ||
| 377 | { | ||
| 378 | return texMain.Sample(Sampler, tex); | ||
| 379 | }); | ||
| 380 | #undef TO_STRING | ||
| 381 | }; /* class CGLonDX */ | ||
| 382 | |||
| 383 | } /* namespace gl */ | ||
| 384 | |||
| 385 | using CRenderHelper = gl::CGLonDX; | ||
| 386 | } /* namespace gui */ | ||
| 387 | } /* namespace kodi */ | ||
| 388 | |||
| 389 | #endif /* __cplusplus */ | ||
diff --git a/xbmc/addons/kodi-dev-kit/include/kodi/gui/gl/Shader.h b/xbmc/addons/kodi-dev-kit/include/kodi/gui/gl/Shader.h new file mode 100644 index 0000000..bf6d48c --- /dev/null +++ b/xbmc/addons/kodi-dev-kit/include/kodi/gui/gl/Shader.h | |||
| @@ -0,0 +1,571 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (C) 2005-2019 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 "GL.h" | ||
| 12 | |||
| 13 | #ifdef __cplusplus | ||
| 14 | |||
| 15 | #include <stdio.h> | ||
| 16 | #include <string> | ||
| 17 | #include <vector> | ||
| 18 | |||
| 19 | #include <kodi/AddonBase.h> | ||
| 20 | #include <kodi/Filesystem.h> | ||
| 21 | |||
| 22 | #define LOG_SIZE 1024 | ||
| 23 | #define GLchar char | ||
| 24 | |||
| 25 | namespace kodi | ||
| 26 | { | ||
| 27 | namespace gui | ||
| 28 | { | ||
| 29 | namespace gl | ||
| 30 | { | ||
| 31 | |||
| 32 | //======================================================================== | ||
| 33 | /// CShader - base class | ||
| 34 | class ATTRIBUTE_HIDDEN CShader | ||
| 35 | { | ||
| 36 | public: | ||
| 37 | CShader() = default; | ||
| 38 | virtual ~CShader() = default; | ||
| 39 | virtual bool Compile(const std::string& extraBegin = "", const std::string& extraEnd = "") = 0; | ||
| 40 | virtual void Free() = 0; | ||
| 41 | virtual GLuint Handle() = 0; | ||
| 42 | |||
| 43 | bool LoadSource(const std::string& file) | ||
| 44 | { | ||
| 45 | char buffer[16384]; | ||
| 46 | |||
| 47 | kodi::vfs::CFile source; | ||
| 48 | if (!source.OpenFile(file)) | ||
| 49 | { | ||
| 50 | kodi::Log(ADDON_LOG_ERROR, "CShader::%s: Failed to open file '%s'", __FUNCTION__, | ||
| 51 | file.c_str()); | ||
| 52 | return false; | ||
| 53 | } | ||
| 54 | size_t len = source.Read(buffer, sizeof(buffer)); | ||
| 55 | m_source.assign(buffer); | ||
| 56 | m_source[len] = 0; | ||
| 57 | source.Close(); | ||
| 58 | return true; | ||
| 59 | } | ||
| 60 | |||
| 61 | bool OK() const { return m_compiled; } | ||
| 62 | |||
| 63 | protected: | ||
| 64 | std::string m_source; | ||
| 65 | std::string m_lastLog; | ||
| 66 | bool m_compiled = false; | ||
| 67 | }; | ||
| 68 | //------------------------------------------------------------------------ | ||
| 69 | |||
| 70 | //======================================================================== | ||
| 71 | /// CVertexShader | ||
| 72 | class ATTRIBUTE_HIDDEN CVertexShader : public CShader | ||
| 73 | { | ||
| 74 | public: | ||
| 75 | CVertexShader() = default; | ||
| 76 | ~CVertexShader() override { Free(); } | ||
| 77 | |||
| 78 | void Free() override | ||
| 79 | { | ||
| 80 | if (m_vertexShader) | ||
| 81 | glDeleteShader(m_vertexShader); | ||
| 82 | m_vertexShader = 0; | ||
| 83 | } | ||
| 84 | |||
| 85 | bool Compile(const std::string& extraBegin = "", const std::string& extraEnd = "") override | ||
| 86 | { | ||
| 87 | GLint params[4]; | ||
| 88 | |||
| 89 | Free(); | ||
| 90 | |||
| 91 | m_vertexShader = glCreateShader(GL_VERTEX_SHADER); | ||
| 92 | |||
| 93 | GLsizei count = 0; | ||
| 94 | const char* sources[3]; | ||
| 95 | if (!extraBegin.empty()) | ||
| 96 | sources[count++] = extraBegin.c_str(); | ||
| 97 | if (!m_source.empty()) | ||
| 98 | sources[count++] = m_source.c_str(); | ||
| 99 | if (!extraEnd.empty()) | ||
| 100 | sources[count++] = extraEnd.c_str(); | ||
| 101 | |||
| 102 | glShaderSource(m_vertexShader, count, sources, nullptr); | ||
| 103 | glCompileShader(m_vertexShader); | ||
| 104 | glGetShaderiv(m_vertexShader, GL_COMPILE_STATUS, params); | ||
| 105 | if (params[0] != GL_TRUE) | ||
| 106 | { | ||
| 107 | GLchar log[LOG_SIZE]; | ||
| 108 | glGetShaderInfoLog(m_vertexShader, LOG_SIZE, nullptr, log); | ||
| 109 | kodi::Log(ADDON_LOG_ERROR, "CVertexShader::%s: %s", __FUNCTION__, log); | ||
| 110 | fprintf(stderr, "CVertexShader::%s: %s\n", __FUNCTION__, log); | ||
| 111 | m_lastLog = log; | ||
| 112 | m_compiled = false; | ||
| 113 | } | ||
| 114 | else | ||
| 115 | { | ||
| 116 | GLchar log[LOG_SIZE]; | ||
| 117 | glGetShaderInfoLog(m_vertexShader, LOG_SIZE, nullptr, log); | ||
| 118 | m_lastLog = log; | ||
| 119 | m_compiled = true; | ||
| 120 | } | ||
| 121 | return m_compiled; | ||
| 122 | } | ||
| 123 | |||
| 124 | GLuint Handle() override { return m_vertexShader; } | ||
| 125 | |||
| 126 | protected: | ||
| 127 | GLuint m_vertexShader = 0; | ||
| 128 | }; | ||
| 129 | //------------------------------------------------------------------------ | ||
| 130 | |||
| 131 | //======================================================================== | ||
| 132 | /// CPixelShader | ||
| 133 | class ATTRIBUTE_HIDDEN CPixelShader : public CShader | ||
| 134 | { | ||
| 135 | public: | ||
| 136 | CPixelShader() = default; | ||
| 137 | ~CPixelShader() { Free(); } | ||
| 138 | void Free() override | ||
| 139 | { | ||
| 140 | if (m_pixelShader) | ||
| 141 | glDeleteShader(m_pixelShader); | ||
| 142 | m_pixelShader = 0; | ||
| 143 | } | ||
| 144 | |||
| 145 | bool Compile(const std::string& extraBegin = "", const std::string& extraEnd = "") override | ||
| 146 | { | ||
| 147 | GLint params[4]; | ||
| 148 | |||
| 149 | Free(); | ||
| 150 | |||
| 151 | m_pixelShader = glCreateShader(GL_FRAGMENT_SHADER); | ||
| 152 | |||
| 153 | GLsizei count = 0; | ||
| 154 | const char* sources[3]; | ||
| 155 | if (!extraBegin.empty()) | ||
| 156 | sources[count++] = extraBegin.c_str(); | ||
| 157 | if (!m_source.empty()) | ||
| 158 | sources[count++] = m_source.c_str(); | ||
| 159 | if (!extraEnd.empty()) | ||
| 160 | sources[count++] = extraEnd.c_str(); | ||
| 161 | |||
| 162 | glShaderSource(m_pixelShader, count, sources, 0); | ||
| 163 | glCompileShader(m_pixelShader); | ||
| 164 | glGetShaderiv(m_pixelShader, GL_COMPILE_STATUS, params); | ||
| 165 | if (params[0] != GL_TRUE) | ||
| 166 | { | ||
| 167 | GLchar log[LOG_SIZE]; | ||
| 168 | glGetShaderInfoLog(m_pixelShader, LOG_SIZE, nullptr, log); | ||
| 169 | kodi::Log(ADDON_LOG_ERROR, "CPixelShader::%s: %s", __FUNCTION__, log); | ||
| 170 | fprintf(stderr, "CPixelShader::%s: %s\n", __FUNCTION__, log); | ||
| 171 | m_lastLog = log; | ||
| 172 | m_compiled = false; | ||
| 173 | } | ||
| 174 | else | ||
| 175 | { | ||
| 176 | GLchar log[LOG_SIZE]; | ||
| 177 | glGetShaderInfoLog(m_pixelShader, LOG_SIZE, nullptr, log); | ||
| 178 | m_lastLog = log; | ||
| 179 | m_compiled = true; | ||
| 180 | } | ||
| 181 | return m_compiled; | ||
| 182 | } | ||
| 183 | |||
| 184 | GLuint Handle() override { return m_pixelShader; } | ||
| 185 | |||
| 186 | protected: | ||
| 187 | GLuint m_pixelShader = 0; | ||
| 188 | }; | ||
| 189 | //------------------------------------------------------------------------ | ||
| 190 | |||
| 191 | //============================================================================ | ||
| 192 | /// @defgroup cpp_kodi_gui_helpers_gl_CShaderProgram GL Shader Program | ||
| 193 | /// @ingroup cpp_kodi_gui_helpers_gl | ||
| 194 | /// @brief @cpp_class{ kodi::gui::gl::CShaderProgram } | ||
| 195 | /// **Class to manage an OpenGL shader program**\n | ||
| 196 | /// With this class the used GL shader code can be defined on the GPU and | ||
| 197 | /// its variables can be managed between CPU and GPU. | ||
| 198 | /// | ||
| 199 | /// It has the header @ref Shader.h "#include <kodi/gui/gl/Shader.h>" | ||
| 200 | /// be included to enjoy it. | ||
| 201 | /// | ||
| 202 | /// ---------------------------------------------------------------------------- | ||
| 203 | /// | ||
| 204 | /// <b>Example:</b> | ||
| 205 | /// | ||
| 206 | /// ~~~~~~~~~~~~~{.cpp} | ||
| 207 | /// | ||
| 208 | /// #include <kodi/gui/gl/Shader.h> | ||
| 209 | /// ... | ||
| 210 | /// | ||
| 211 | /// class ATTRIBUTE_HIDDEN CExample | ||
| 212 | /// : ..., | ||
| 213 | /// public kodi::gui::gl::CShaderProgram | ||
| 214 | /// { | ||
| 215 | /// public: | ||
| 216 | /// CExample() = default; | ||
| 217 | /// | ||
| 218 | /// bool Start(); | ||
| 219 | /// void Render(); | ||
| 220 | /// | ||
| 221 | /// // override functions for kodi::gui::gl::CShaderProgram | ||
| 222 | /// void OnCompiledAndLinked() override; | ||
| 223 | /// bool OnEnabled() override; | ||
| 224 | /// | ||
| 225 | /// private: | ||
| 226 | /// ... | ||
| 227 | /// GLint m_aPosition = -1; | ||
| 228 | /// GLint m_aColor = -1; | ||
| 229 | /// }; | ||
| 230 | /// | ||
| 231 | /// bool CExample::Start() | ||
| 232 | /// { | ||
| 233 | /// // Define shaders and load | ||
| 234 | /// std::string fraqShader = kodi::GetAddonPath("resources/shaders/" GL_TYPE_STRING "/glsl.frag"); | ||
| 235 | /// std::string vertShader = kodi::GetAddonPath("resources/shaders/" GL_TYPE_STRING "/glsl.vert"); | ||
| 236 | /// if (!LoadShaderFiles(vertShader, fraqShader) || !CompileAndLink()) | ||
| 237 | /// return false; | ||
| 238 | /// | ||
| 239 | /// ... | ||
| 240 | /// return true; | ||
| 241 | /// } | ||
| 242 | /// | ||
| 243 | /// ... | ||
| 244 | /// | ||
| 245 | /// void CExample::Render() | ||
| 246 | /// { | ||
| 247 | /// ... | ||
| 248 | /// | ||
| 249 | /// EnableShader(); | ||
| 250 | /// ... | ||
| 251 | /// DO WORK | ||
| 252 | /// ... | ||
| 253 | /// DisableShader(); | ||
| 254 | /// } | ||
| 255 | /// | ||
| 256 | /// void CExample::OnCompiledAndLinked() | ||
| 257 | /// { | ||
| 258 | /// ... | ||
| 259 | /// DO YOUR WORK HERE FOR WHAT IS ONE TIME REQUIRED DURING COMPILE OF SHADER, E.G.: | ||
| 260 | /// | ||
| 261 | /// m_aPosition = glGetAttribLocation(ProgramHandle(), "a_position"); | ||
| 262 | /// m_aColor = glGetAttribLocation(ProgramHandle(), "a_color"); | ||
| 263 | /// } | ||
| 264 | /// | ||
| 265 | /// bool OnEnabled() override | ||
| 266 | /// { | ||
| 267 | /// ... | ||
| 268 | /// DO YOUR WORK HERE FOR WHAT REQUIRED DURING ENABLE OF SHADER | ||
| 269 | /// ... | ||
| 270 | /// return true; | ||
| 271 | /// } | ||
| 272 | /// | ||
| 273 | /// ADDONCREATOR(CExample); | ||
| 274 | /// ~~~~~~~~~~~~~ | ||
| 275 | /// | ||
| 276 | class ATTRIBUTE_HIDDEN CShaderProgram | ||
| 277 | { | ||
| 278 | public: | ||
| 279 | //========================================================================== | ||
| 280 | /// @ingroup cpp_kodi_gui_helpers_gl_CShaderProgram | ||
| 281 | /// @brief Construct a new shader. | ||
| 282 | /// | ||
| 283 | /// Load must be done later with @ref LoadShaderFiles. | ||
| 284 | /// | ||
| 285 | CShaderProgram() = default; | ||
| 286 | //-------------------------------------------------------------------------- | ||
| 287 | |||
| 288 | //========================================================================== | ||
| 289 | /// @ingroup cpp_kodi_gui_helpers_gl_CShaderProgram | ||
| 290 | /// @brief Construct a new shader and load defined shader files. | ||
| 291 | /// | ||
| 292 | /// @param[in] vert Path to used GL vertext shader | ||
| 293 | /// @param[in] frag Path to used GL fragment shader | ||
| 294 | /// | ||
| 295 | CShaderProgram(const std::string& vert, const std::string& frag) { LoadShaderFiles(vert, frag); } | ||
| 296 | //-------------------------------------------------------------------------- | ||
| 297 | |||
| 298 | //========================================================================== | ||
| 299 | /// @ingroup cpp_kodi_gui_helpers_gl_CShaderProgram | ||
| 300 | /// @brief Destructor. | ||
| 301 | /// | ||
| 302 | virtual ~CShaderProgram() { ShaderFree(); } | ||
| 303 | //-------------------------------------------------------------------------- | ||
| 304 | |||
| 305 | //========================================================================== | ||
| 306 | /// @ingroup cpp_kodi_gui_helpers_gl_CShaderProgram | ||
| 307 | /// @brief To load manually the needed shader files. | ||
| 308 | /// | ||
| 309 | /// @param[in] vert Path to used GL vertext shader | ||
| 310 | /// @param[in] frag Path to used GL fragment shader | ||
| 311 | /// | ||
| 312 | /// | ||
| 313 | /// @note The use of the files is optional, but it must either be passed over | ||
| 314 | /// here or via @ref CompileAndLink, or both of the source code. | ||
| 315 | /// | ||
| 316 | bool LoadShaderFiles(const std::string& vert, const std::string& frag) | ||
| 317 | { | ||
| 318 | if (!kodi::vfs::FileExists(vert) || !m_pVP.LoadSource(vert)) | ||
| 319 | { | ||
| 320 | kodi::Log(ADDON_LOG_ERROR, "%s: Failed to load '%s'", __func__, vert.c_str()); | ||
| 321 | return false; | ||
| 322 | } | ||
| 323 | |||
| 324 | if (!kodi::vfs::FileExists(frag) || !m_pFP.LoadSource(frag)) | ||
| 325 | { | ||
| 326 | kodi::Log(ADDON_LOG_ERROR, "%s: Failed to load '%s'", __func__, frag.c_str()); | ||
| 327 | return false; | ||
| 328 | } | ||
| 329 | |||
| 330 | return true; | ||
| 331 | } | ||
| 332 | //-------------------------------------------------------------------------- | ||
| 333 | |||
| 334 | //========================================================================== | ||
| 335 | /// @ingroup cpp_kodi_gui_helpers_gl_CShaderProgram | ||
| 336 | /// @brief To compile and link the shader to the GL interface. | ||
| 337 | /// | ||
| 338 | /// Optionally, additional source code can be transferred here, or it can be | ||
| 339 | /// used independently without any files | ||
| 340 | /// | ||
| 341 | /// @param[in] vertexExtraBegin [opt] To additionally add vextex source | ||
| 342 | /// code to the beginning of the loaded file | ||
| 343 | /// source code | ||
| 344 | /// @param[in] vertexExtraEnd [opt] To additionally add vextex source | ||
| 345 | /// code to the end of the loaded file | ||
| 346 | /// source code | ||
| 347 | /// @param[in] fragmentExtraBegin [opt] To additionally add fragment source | ||
| 348 | /// code to the beginning of the loaded file | ||
| 349 | /// source code | ||
| 350 | /// @param[in] fragmentExtraEnd [opt] To additionally add fragment source | ||
| 351 | /// code to the end of the loaded file | ||
| 352 | /// source code | ||
| 353 | /// @return true if compile was successed | ||
| 354 | /// | ||
| 355 | /// | ||
| 356 | /// @note In the case of a compile error, it will be written once into the Kodi | ||
| 357 | /// log and in addition to the console output to quickly detect the errors when | ||
| 358 | /// writing the damage. | ||
| 359 | /// | ||
| 360 | /// | ||
| 361 | bool CompileAndLink(const std::string& vertexExtraBegin = "", | ||
| 362 | const std::string& vertexExtraEnd = "", | ||
| 363 | const std::string& fragmentExtraBegin = "", | ||
| 364 | const std::string& fragmentExtraEnd = "") | ||
| 365 | { | ||
| 366 | GLint params[4]; | ||
| 367 | |||
| 368 | // free resources | ||
| 369 | ShaderFree(); | ||
| 370 | m_ok = false; | ||
| 371 | |||
| 372 | // compiled vertex shader | ||
| 373 | if (!m_pVP.Compile(vertexExtraBegin, vertexExtraEnd)) | ||
| 374 | { | ||
| 375 | kodi::Log(ADDON_LOG_ERROR, "GL: Error compiling vertex shader"); | ||
| 376 | return false; | ||
| 377 | } | ||
| 378 | |||
| 379 | // compile pixel shader | ||
| 380 | if (!m_pFP.Compile(fragmentExtraBegin, fragmentExtraEnd)) | ||
| 381 | { | ||
| 382 | m_pVP.Free(); | ||
| 383 | kodi::Log(ADDON_LOG_ERROR, "GL: Error compiling fragment shader"); | ||
| 384 | return false; | ||
| 385 | } | ||
| 386 | |||
| 387 | // create program object | ||
| 388 | m_shaderProgram = glCreateProgram(); | ||
| 389 | if (!m_shaderProgram) | ||
| 390 | { | ||
| 391 | kodi::Log(ADDON_LOG_ERROR, "CShaderProgram::%s: Failed to create GL program", __FUNCTION__); | ||
| 392 | ShaderFree(); | ||
| 393 | return false; | ||
| 394 | } | ||
| 395 | |||
| 396 | // attach the vertex shader | ||
| 397 | glAttachShader(m_shaderProgram, m_pVP.Handle()); | ||
| 398 | glAttachShader(m_shaderProgram, m_pFP.Handle()); | ||
| 399 | |||
| 400 | // link the program | ||
| 401 | glLinkProgram(m_shaderProgram); | ||
| 402 | glGetProgramiv(m_shaderProgram, GL_LINK_STATUS, params); | ||
| 403 | if (params[0] != GL_TRUE) | ||
| 404 | { | ||
| 405 | GLchar log[LOG_SIZE]; | ||
| 406 | glGetProgramInfoLog(m_shaderProgram, LOG_SIZE, nullptr, log); | ||
| 407 | kodi::Log(ADDON_LOG_ERROR, "CShaderProgram::%s: %s", __FUNCTION__, log); | ||
| 408 | fprintf(stderr, "CShaderProgram::%s: %s@n", __FUNCTION__, log); | ||
| 409 | ShaderFree(); | ||
| 410 | return false; | ||
| 411 | } | ||
| 412 | |||
| 413 | m_validated = false; | ||
| 414 | m_ok = true; | ||
| 415 | OnCompiledAndLinked(); | ||
| 416 | return true; | ||
| 417 | } | ||
| 418 | //-------------------------------------------------------------------------- | ||
| 419 | |||
| 420 | //========================================================================== | ||
| 421 | /// @ingroup cpp_kodi_gui_helpers_gl_CShaderProgram | ||
| 422 | /// @brief To activate the shader and use it on the GPU. | ||
| 423 | /// | ||
| 424 | /// @return true if enable was successfull done | ||
| 425 | /// | ||
| 426 | /// | ||
| 427 | /// @note During this call, the @ref OnEnabled stored in the child is also | ||
| 428 | /// called | ||
| 429 | /// | ||
| 430 | bool EnableShader() | ||
| 431 | { | ||
| 432 | if (ShaderOK()) | ||
| 433 | { | ||
| 434 | glUseProgram(m_shaderProgram); | ||
| 435 | if (OnEnabled()) | ||
| 436 | { | ||
| 437 | if (!m_validated) | ||
| 438 | { | ||
| 439 | // validate the program | ||
| 440 | GLint params[4]; | ||
| 441 | glValidateProgram(m_shaderProgram); | ||
| 442 | glGetProgramiv(m_shaderProgram, GL_VALIDATE_STATUS, params); | ||
| 443 | if (params[0] != GL_TRUE) | ||
| 444 | { | ||
| 445 | GLchar log[LOG_SIZE]; | ||
| 446 | glGetProgramInfoLog(m_shaderProgram, LOG_SIZE, nullptr, log); | ||
| 447 | kodi::Log(ADDON_LOG_ERROR, "CShaderProgram::%s: %s", __FUNCTION__, log); | ||
| 448 | fprintf(stderr, "CShaderProgram::%s: %s\n", __FUNCTION__, log); | ||
| 449 | } | ||
| 450 | m_validated = true; | ||
| 451 | } | ||
| 452 | return true; | ||
| 453 | } | ||
| 454 | else | ||
| 455 | { | ||
| 456 | glUseProgram(0); | ||
| 457 | return false; | ||
| 458 | } | ||
| 459 | return true; | ||
| 460 | } | ||
| 461 | return false; | ||
| 462 | } | ||
| 463 | //-------------------------------------------------------------------------- | ||
| 464 | |||
| 465 | //========================================================================== | ||
| 466 | /// @ingroup cpp_kodi_gui_helpers_gl_CShaderProgram | ||
| 467 | /// @brief To deactivate the shader use on the GPU. | ||
| 468 | /// | ||
| 469 | void DisableShader() | ||
| 470 | { | ||
| 471 | if (ShaderOK()) | ||
| 472 | { | ||
| 473 | glUseProgram(0); | ||
| 474 | OnDisabled(); | ||
| 475 | } | ||
| 476 | } | ||
| 477 | //-------------------------------------------------------------------------- | ||
| 478 | |||
| 479 | //========================================================================== | ||
| 480 | /// @ingroup cpp_kodi_gui_helpers_gl_CShaderProgram | ||
| 481 | /// @brief Used to check if shader has been loaded before. | ||
| 482 | /// | ||
| 483 | /// @return true if enable was successfull done | ||
| 484 | /// | ||
| 485 | /// @note The CompileAndLink call sets these values | ||
| 486 | /// | ||
| 487 | ATTRIBUTE_FORCEINLINE bool ShaderOK() const { return m_ok; } | ||
| 488 | //-------------------------------------------------------------------------- | ||
| 489 | |||
| 490 | //========================================================================== | ||
| 491 | /// @ingroup cpp_kodi_gui_helpers_gl_CShaderProgram | ||
| 492 | /// @brief To get the vertex shader class used by Kodi at the addon. | ||
| 493 | /// | ||
| 494 | /// @return pointer to vertex shader class | ||
| 495 | /// | ||
| 496 | ATTRIBUTE_FORCEINLINE CVertexShader& VertexShader() { return m_pVP; } | ||
| 497 | //-------------------------------------------------------------------------- | ||
| 498 | |||
| 499 | //========================================================================== | ||
| 500 | /// @ingroup cpp_kodi_gui_helpers_gl_CShaderProgram | ||
| 501 | /// @brief To get the fragment shader class used by Kodi at the addon. | ||
| 502 | /// | ||
| 503 | /// @return pointer to fragment shader class | ||
| 504 | /// | ||
| 505 | ATTRIBUTE_FORCEINLINE CPixelShader& PixelShader() { return m_pFP; } | ||
| 506 | //-------------------------------------------------------------------------- | ||
| 507 | |||
| 508 | //========================================================================== | ||
| 509 | /// @ingroup cpp_kodi_gui_helpers_gl_CShaderProgram | ||
| 510 | /// @brief Used to get the definition created in the OpenGL itself. | ||
| 511 | /// | ||
| 512 | /// @return GLuint of GL shader program handler | ||
| 513 | /// | ||
| 514 | ATTRIBUTE_FORCEINLINE GLuint ProgramHandle() { return m_shaderProgram; } | ||
| 515 | //-------------------------------------------------------------------------- | ||
| 516 | |||
| 517 | //========================================================================== | ||
| 518 | /// @defgroup cpp_kodi_gui_helpers_gl_CShaderProgram_child Child Functions | ||
| 519 | /// @ingroup cpp_kodi_gui_helpers_gl_CShaderProgram | ||
| 520 | /// @brief @cpp_class{ kodi::gui::gl::CShaderProgram child functions } | ||
| 521 | /// | ||
| 522 | /// Functions that are added by parent in the child | ||
| 523 | /// @{ | ||
| 524 | //========================================================================== | ||
| 525 | /// | ||
| 526 | /// @ingroup cpp_kodi_gui_helpers_gl_CShaderProgram_child | ||
| 527 | /// @brief Mandatory child function to set the necessary CPU to GPU data | ||
| 528 | /// | ||
| 529 | virtual void OnCompiledAndLinked(){}; | ||
| 530 | //-------------------------------------------------------------------------- | ||
| 531 | |||
| 532 | //========================================================================== | ||
| 533 | /// @ingroup cpp_kodi_gui_helpers_gl_CShaderProgram_child | ||
| 534 | /// @brief Optional function to exchange data between CPU and GPU while | ||
| 535 | /// activating the shader | ||
| 536 | /// | ||
| 537 | /// @return true if enable was successfull done | ||
| 538 | /// | ||
| 539 | virtual bool OnEnabled() { return true; }; | ||
| 540 | //-------------------------------------------------------------------------- | ||
| 541 | |||
| 542 | //========================================================================== | ||
| 543 | /// @ingroup cpp_kodi_gui_helpers_gl_CShaderProgram_child | ||
| 544 | /// @brief Optional child function that may have to be performed when | ||
| 545 | /// switching off the shader | ||
| 546 | virtual void OnDisabled(){}; | ||
| 547 | //-------------------------------------------------------------------------- | ||
| 548 | /// @} | ||
| 549 | |||
| 550 | private: | ||
| 551 | void ShaderFree() | ||
| 552 | { | ||
| 553 | if (m_shaderProgram) | ||
| 554 | glDeleteProgram(m_shaderProgram); | ||
| 555 | m_shaderProgram = 0; | ||
| 556 | m_ok = false; | ||
| 557 | } | ||
| 558 | |||
| 559 | CVertexShader m_pVP; | ||
| 560 | CPixelShader m_pFP; | ||
| 561 | GLuint m_shaderProgram = 0; | ||
| 562 | bool m_ok = false; | ||
| 563 | bool m_validated = false; | ||
| 564 | }; | ||
| 565 | //------------------------------------------------------------------------ | ||
| 566 | |||
| 567 | } /* namespace gl */ | ||
| 568 | } /* namespace gui */ | ||
| 569 | } /* namespace kodi */ | ||
| 570 | |||
| 571 | #endif /* __cplusplus */ | ||
diff --git a/xbmc/addons/kodi-dev-kit/include/kodi/gui/input/ActionIDs.h b/xbmc/addons/kodi-dev-kit/include/kodi/gui/input/ActionIDs.h new file mode 100644 index 0000000..4c816a4 --- /dev/null +++ b/xbmc/addons/kodi-dev-kit/include/kodi/gui/input/ActionIDs.h | |||
| @@ -0,0 +1,11 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (C) 2005-2020 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/input/action_ids.h" | ||
diff --git a/xbmc/addons/kodi-dev-kit/include/kodi/gui/input/CMakeLists.txt b/xbmc/addons/kodi-dev-kit/include/kodi/gui/input/CMakeLists.txt new file mode 100644 index 0000000..d576974 --- /dev/null +++ b/xbmc/addons/kodi-dev-kit/include/kodi/gui/input/CMakeLists.txt | |||
| @@ -0,0 +1,5 @@ | |||
| 1 | set(HEADERS ActionIDs.h) | ||
| 2 | |||
| 3 | if(NOT ENABLE_STATIC_LIBS) | ||
| 4 | core_add_library(addons_kodi-dev-kit_include_kodi_gui_input) | ||
| 5 | endif() | ||
diff --git a/xbmc/addons/kodi-dev-kit/include/kodi/gui/renderHelper.h b/xbmc/addons/kodi-dev-kit/include/kodi/gui/renderHelper.h new file mode 100644 index 0000000..dabe101 --- /dev/null +++ b/xbmc/addons/kodi-dev-kit/include/kodi/gui/renderHelper.h | |||
| @@ -0,0 +1,82 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (C) 2005-2019 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 "../AddonBase.h" | ||
| 12 | |||
| 13 | #ifdef __cplusplus | ||
| 14 | |||
| 15 | namespace kodi | ||
| 16 | { | ||
| 17 | namespace gui | ||
| 18 | { | ||
| 19 | struct ATTRIBUTE_HIDDEN IRenderHelper | ||
| 20 | { | ||
| 21 | virtual ~IRenderHelper() = default; | ||
| 22 | virtual bool Init() = 0; | ||
| 23 | virtual void Begin() = 0; | ||
| 24 | virtual void End() = 0; | ||
| 25 | }; /* class IRenderHelper */ | ||
| 26 | } /* namespace gui */ | ||
| 27 | } /* namespace kodi */ | ||
| 28 | |||
| 29 | #if defined(WIN32) && defined(HAS_ANGLE) | ||
| 30 | #include "gl/GLonDX.h" | ||
| 31 | #else | ||
| 32 | /* | ||
| 33 | * Default background GUI render helper class | ||
| 34 | */ | ||
| 35 | namespace kodi | ||
| 36 | { | ||
| 37 | namespace gui | ||
| 38 | { | ||
| 39 | struct ATTRIBUTE_HIDDEN CRenderHelperStub : public IRenderHelper | ||
| 40 | { | ||
| 41 | bool Init() override { return true; } | ||
| 42 | void Begin() override {} | ||
| 43 | void End() override {} | ||
| 44 | }; /* class CRenderHelperStub */ | ||
| 45 | |||
| 46 | using CRenderHelper = CRenderHelperStub; | ||
| 47 | } /* namespace gui */ | ||
| 48 | } /* namespace kodi */ | ||
| 49 | #endif | ||
| 50 | |||
| 51 | namespace kodi | ||
| 52 | { | ||
| 53 | namespace gui | ||
| 54 | { | ||
| 55 | |||
| 56 | /* | ||
| 57 | * Create render background handler, e.g. becomes on "Windows" Angle used | ||
| 58 | * to emulate GL. | ||
| 59 | * | ||
| 60 | * This only be used internal and not from addon's direct. | ||
| 61 | * | ||
| 62 | * Function defines here and not in CAddonBase because of a hen and egg problem. | ||
| 63 | */ | ||
| 64 | inline std::shared_ptr<IRenderHelper> ATTRIBUTE_HIDDEN GetRenderHelper() | ||
| 65 | { | ||
| 66 | using namespace ::kodi::addon; | ||
| 67 | if (static_cast<CAddonBase*>(CAddonBase::m_interface->addonBase)->m_renderHelper) | ||
| 68 | return static_cast<CAddonBase*>(CAddonBase::m_interface->addonBase)->m_renderHelper; | ||
| 69 | |||
| 70 | const std::shared_ptr<kodi::gui::IRenderHelper> renderHelper(new CRenderHelper()); | ||
| 71 | if (!renderHelper->Init()) | ||
| 72 | return nullptr; | ||
| 73 | |||
| 74 | static_cast<CAddonBase*>(CAddonBase::m_interface->addonBase)->m_renderHelper = | ||
| 75 | renderHelper; // Hold on base for other types | ||
| 76 | return renderHelper; | ||
| 77 | } | ||
| 78 | |||
| 79 | } /* namespace gui */ | ||
| 80 | } /* namespace kodi */ | ||
| 81 | |||
| 82 | #endif /* __cplusplus */ | ||
