diff --git a/src/UI/CMakeLists.txt b/src/UI/CMakeLists.txt index 0d5f243..f3f1318 100644 --- a/src/UI/CMakeLists.txt +++ b/src/UI/CMakeLists.txt @@ -12,14 +12,16 @@ target_compile_options(UI PRIVATE $<$: target_sources(UI PRIVATE ${CMAKE_CURRENT_LIST_DIR}/UI_item.cpp + ${CMAKE_CURRENT_LIST_DIR}/UI_button.cpp + ${CMAKE_CURRENT_LIST_DIR}/UI_checkbox.cpp + ${CMAKE_CURRENT_LIST_DIR}/UI_combobox.cpp + ${CMAKE_CURRENT_LIST_DIR}/UI_dial.cpp ${CMAKE_CURRENT_LIST_DIR}/UI_label.cpp ${CMAKE_CURRENT_LIST_DIR}/UI_led.cpp - ${CMAKE_CURRENT_LIST_DIR}/UI_button.cpp ${CMAKE_CURRENT_LIST_DIR}/UI_slider.cpp ${CMAKE_CURRENT_LIST_DIR}/UI_textbox.cpp + ${CMAKE_CURRENT_LIST_DIR}/UI_thermo.cpp ${CMAKE_CURRENT_LIST_DIR}/UI_x_boxes.cpp - ${CMAKE_CURRENT_LIST_DIR}/UI_combobox.cpp - ${CMAKE_CURRENT_LIST_DIR}/UI_checkbox.cpp ) target_include_directories(UI diff --git a/src/UI/UI.hpp b/src/UI/UI.hpp index 31659b4..84e0ab4 100644 --- a/src/UI/UI.hpp +++ b/src/UI/UI.hpp @@ -3,6 +3,8 @@ #include "UI_button.hpp" #include "UI_checkbox.hpp" #include "UI_combobox.hpp" +#include "UI_dial.hpp" #include "UI_label.hpp" #include "UI_led.hpp" -#include "UI_slider.hpp" \ No newline at end of file +#include "UI_slider.hpp" +#include "UI_thermo.hpp" \ No newline at end of file diff --git a/src/UI/UI_dial.cpp b/src/UI/UI_dial.cpp new file mode 100644 index 0000000..106637d --- /dev/null +++ b/src/UI/UI_dial.cpp @@ -0,0 +1,45 @@ +#include "UI_dial.hpp" + +UI_dial::UI_dial(std::string id, std::string text, Color fg_color, Color bg_color, double min, double max, double value) + : UI_item(id, UI_DIAL_TYPE, text, 12, fg_color, bg_color), m_min(min), m_max(max), m_value(value) +{ +} + +UI_dial::UI_dial(const json& j) +: UI_item(UI_DIAL_TYPE) +{ + from_json(j); +} + +void UI_dial::set_value(double value) +{ + if (value < m_min || value > m_max) + return; + if (value == m_value) + return; + + this->m_value = value; +} + +double UI_dial::value() const +{ + return m_value; +} + +void UI_dial::from_json(const json& j) +{ + UI_item::from_json(j); + + this->m_min = j["min"]; + this->m_max = j["max"]; + this->m_value = j["value"]; +} + +json UI_dial::to_json() const +{ + json j = UI_item::to_json(); + j["min"] = this->m_min; + j["max"] = this->m_max; + j["value"] = this->m_value; + return j; +} \ No newline at end of file diff --git a/src/UI/UI_dial.hpp b/src/UI/UI_dial.hpp new file mode 100644 index 0000000..b94a85a --- /dev/null +++ b/src/UI/UI_dial.hpp @@ -0,0 +1,21 @@ +#pragma once +#include "UI_item.hpp" + +#define UI_DIAL_TYPE std::string("UI_dial") + +class UI_dial : public UI_item +{ + public: + UI_dial(std::string id, std::string text, Color fg_color, Color bg_color, double min, double max, double value); + UI_dial(const json& j); + + void set_value(double value) override; + double value() const; + + void from_json(const json& j) override; + json to_json() const override; + private: + double m_min; + double m_max; + double m_value; +}; \ No newline at end of file diff --git a/src/UI/UI_thermo.cpp b/src/UI/UI_thermo.cpp new file mode 100644 index 0000000..bb62dcd --- /dev/null +++ b/src/UI/UI_thermo.cpp @@ -0,0 +1,45 @@ +#include "UI_thermo.hpp" + +UI_thermo::UI_thermo(std::string id, std::string text, Color fg_color, Color bg_color, double min, double max, double value) + : UI_item(id, UI_THERMO_TYPE, text, 12, fg_color, bg_color), m_min(min), m_max(max), m_value(value) +{ +} + +UI_thermo::UI_thermo(const json& j) +: UI_item(UI_THERMO_TYPE) +{ + from_json(j); +} + +void UI_thermo::set_value(double value) +{ + if (value < m_min || value > m_max) + return; + if (value == m_value) + return; + + this->m_value = value; +} + +double UI_thermo::value() const +{ + return m_value; +} + +void UI_thermo::from_json(const json& j) +{ + UI_item::from_json(j); + + this->m_min = j["min"]; + this->m_max = j["max"]; + this->m_value = j["value"]; +} + +json UI_thermo::to_json() const +{ + json j = UI_item::to_json(); + j["min"] = this->m_min; + j["max"] = this->m_max; + j["value"] = this->m_value; + return j; +} \ No newline at end of file diff --git a/src/UI/UI_thermo.hpp b/src/UI/UI_thermo.hpp new file mode 100644 index 0000000..9e99257 --- /dev/null +++ b/src/UI/UI_thermo.hpp @@ -0,0 +1,22 @@ +#pragma once +#include "UI_item.hpp" + +#define UI_THERMO_TYPE std::string("UI_thermo") + +// TODO: Add color scale +class UI_thermo : public UI_item +{ + public: + UI_thermo(std::string id, std::string text, Color fg_color, Color bg_color, double min, double max, double value); + UI_thermo(const json& j); + + void set_value(double value) override; + double value() const; + + void from_json(const json& j) override; + json to_json() const override; + private: + double m_min; + double m_max; + double m_value; +}; \ No newline at end of file