You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ovdCFloatSettingView.cpp 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #include "ovdCFloatSettingView.h"
  2. #include "../ovd_base.h"
  3. namespace OpenViBE {
  4. namespace Designer {
  5. namespace Setting {
  6. static void OnButtonSettingFloatUpPressed(GtkButton* /*button*/, gpointer data) { static_cast<CFloatSettingView*>(data)->adjustValue(1.0); }
  7. static void OnButtonSettingFloatDownPressed(GtkButton* /*button*/, gpointer data) { static_cast<CFloatSettingView*>(data)->adjustValue(-1.0); }
  8. static void OnChange(GtkEntry* /*entry*/, gpointer data) { static_cast<CFloatSettingView*>(data)->onChange(); }
  9. CFloatSettingView::CFloatSettingView(Kernel::IBox& box, const size_t index, CString& builderName, const Kernel::IKernelContext& ctx)
  10. : CAbstractSettingView(box, index, builderName, "settings_collection-hbox_setting_float"), m_kernelCtx(ctx)
  11. {
  12. GtkWidget* settingWidget = CAbstractSettingView::getEntryFieldWidget();
  13. std::vector<GtkWidget*> widgets;
  14. CAbstractSettingView::extractWidget(settingWidget, widgets);
  15. m_entry = GTK_ENTRY(widgets[0]);
  16. g_signal_connect(G_OBJECT(m_entry), "changed", G_CALLBACK(OnChange), this);
  17. g_signal_connect(G_OBJECT(widgets[1]), "clicked", G_CALLBACK(OnButtonSettingFloatUpPressed), this);
  18. g_signal_connect(G_OBJECT(widgets[2]), "clicked", G_CALLBACK(OnButtonSettingFloatDownPressed), this);
  19. CAbstractSettingView::initializeValue();
  20. }
  21. void CFloatSettingView::getValue(CString& value) const { value = CString(gtk_entry_get_text(m_entry)); }
  22. void CFloatSettingView::setValue(const CString& value)
  23. {
  24. m_onValueSetting = true;
  25. gtk_entry_set_text(m_entry, value);
  26. m_onValueSetting = false;
  27. }
  28. void CFloatSettingView::adjustValue(const double amount)
  29. {
  30. const double value = m_kernelCtx.getConfigurationManager().expandAsFloat(gtk_entry_get_text(m_entry), 0) + amount;
  31. const std::string str = std::to_string(value);
  32. getBox().setSettingValue(getSettingIndex(), str.c_str());
  33. setValue(str.c_str());
  34. }
  35. void CFloatSettingView::onChange()
  36. {
  37. if (!m_onValueSetting)
  38. {
  39. const gchar* value = gtk_entry_get_text(m_entry);
  40. getBox().setSettingValue(getSettingIndex(), value);
  41. }
  42. }
  43. } // namespace Setting
  44. } // namespace Designer
  45. } // namespace OpenViBE