Kodi Development  20.0
for Binary and Script based Add-Ons
Spin.h
1 /*
2  * Copyright (C) 2005-2018 Team Kodi
3  * This file is part of Kodi - https://kodi.tv
4  *
5  * SPDX-License-Identifier: GPL-2.0-or-later
6  * See LICENSES/README.md for more information.
7  */
8 
9 #pragma once
10 
11 #include "../../c-api/gui/controls/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 //==============================================================================
96 
97 
98 //==============================================================================
105 {
115 //------------------------------------------------------------------------------
116 
117 class ATTRIBUTE_HIDDEN CSpin : public CAddonGUIControlBase
118 {
119 public:
120  //============================================================================
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)
133  "kodi::gui::controls::CSpin can't create control class from Kodi !!!");
134  }
135  //----------------------------------------------------------------------------
136 
137  //============================================================================
141  ~CSpin() override = default;
142  //----------------------------------------------------------------------------
143 
144  //============================================================================
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  //============================================================================
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  //============================================================================
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  //============================================================================
187  void Reset()
188  {
189  m_interface->kodi_gui->control_spin->reset(m_interface->kodiBase, m_controlHandle);
190  }
191  //----------------------------------------------------------------------------
192 
193  //============================================================================
202  {
203  m_interface->kodi_gui->control_spin->set_type(m_interface->kodiBase, m_controlHandle,
204  (int)type);
205  }
206  //----------------------------------------------------------------------------
207 
208  //============================================================================
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  //============================================================================
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  //============================================================================
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  //============================================================================
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  //============================================================================
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  //============================================================================
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  //============================================================================
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  //============================================================================
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  //============================================================================
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  //============================================================================
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  //============================================================================
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 */
Definition: ListItem.h:26
Definition: Window.h:110
Definition: Spin.h:118
@ ADDON_LOG_FATAL
4 : To notify fatal unrecoverable errors, which can may also indicate upcoming crashes.
Definition: addon_base.h:187
CSpin(CWindow *window, int controlId)
Construct a new control.
Definition: Spin.h:127
void SetFloatInterval(float interval)
To set the interval steps of spin, as default is it 0.1 If it becomes changed with this function will...
Definition: Spin.h:404
void SetIntRange(int start, int end)
To set the the range as integer of slider, e.g. -10 is the slider start and e.g. +10 is the from here...
Definition: Spin.h:293
void SetIntValue(int value)
Set the slider position with the given integer value. The Range must be defined with a call from SetI...
Definition: Spin.h:311
void SetType(AddonGUISpinControlType type)
To set the with SpinControlType defined types of spin.
Definition: Spin.h:201
void SetStringValue(const std::string &value)
To change the spin to position with them string as value.
Definition: Spin.h:248
void Reset()
To reset spin control to defaults.
Definition: Spin.h:187
float GetFloatValue() const
To get the current position as float value.
Definition: Spin.h:385
void SetVisible(bool visible)
Set the control on window to visible.
Definition: Spin.h:150
void SetText(const std::string &text)
To set the text string on spin control.
Definition: Spin.h:176
void AddLabel(const std::string &label, const std::string &value)
To add a label entry in spin defined with a value as string.
Definition: Spin.h:217
AddonGUISpinControlType
The values here defines the used value format for steps on spin control.
Definition: Spin.h:105
~CSpin() override=default
Destructor.
void SetEnabled(bool enabled)
Set's the control's enabled/disabled state.
Definition: Spin.h:163
void SetFloatValue(float value)
Set the spin position with the given float value. The Range can be defined with a call from SetIntRan...
Definition: Spin.h:372
int GetIntValue() const
To get the current position as integer value.
Definition: Spin.h:328
std::string GetStringValue() const
To get the current spin control position with text string value.
Definition: Spin.h:263
void AddLabel(const std::string &label, int value)
To add a label entry in spin defined with a value as integer.
Definition: Spin.h:233
void SetFloatRange(float start, float end)
To set the the range as float of spin, e.g. -25.0 is the spin start and e.g. +25.0 is the from here d...
Definition: Spin.h:353
@ ADDON_SPIN_CONTROL_TYPE_TEXT
One spin step interpreted as text string.
Definition: Spin.h:111
@ ADDON_SPIN_CONTROL_TYPE_PAGE
One spin step interpreted as a page change value.
Definition: Spin.h:113
@ ADDON_SPIN_CONTROL_TYPE_INT
One spin step interpreted as integer.
Definition: Spin.h:107
@ ADDON_SPIN_CONTROL_TYPE_FLOAT
One spin step interpreted as floating point value.
Definition: Spin.h:109
void ATTRIBUTE_HIDDEN Log(const AddonLog loglevel, const char *format,...)
Add a message to Kodi's log.
Definition: AddonBase.h:749