diff --git a/dependencies/subprojects/animationwindow/include/widgets/Slider.h b/dependencies/subprojects/animationwindow/include/widgets/Slider.h new file mode 100644 index 0000000000000000000000000000000000000000..280f07115fcf7ca75f8c581be64b3c5535fb45a9 --- /dev/null +++ b/dependencies/subprojects/animationwindow/include/widgets/Slider.h @@ -0,0 +1,34 @@ +#pragma once + +#include "Widget.h" +#include "Point.h" +#include "Color.h" + +namespace TDT4102 { + class Slider : public TDT4102::Widget { + private: + int value; + int minValue; + int maxValue; + int stepValue; + nk_color sliderBarColor = nk_rgba(100, 100, 100, 255); + nk_color sliderBarColorActive = nk_rgba(100, 100, 100, 255); + nk_color sliderBarColorHover = nk_rgba(100, 100, 100, 255); + nk_color sliderBarColorFilled = nk_rgba(100, 100, 100, 255); + nk_color sliderCursorColor = nk_rgba(180, 180, 180, 255); + nk_color sliderCursorColorActive = nk_rgba(180, 180, 180, 255); + nk_color sliderCursorColorHover = nk_rgba(180, 180, 180, 255); + protected: + void update(nk_context* context) override; + public: + explicit Slider(TDT4102::Point location, unsigned int width, unsigned int height, int min = 0, int max = 100, int initialValue = 0, int step = 1); + int getValue() const; + void setSliderBarColor(Color newColor) {sliderBarColor = nk_color{(nk_byte)newColor.redChannel, (nk_byte)newColor.greenChannel, (nk_byte)newColor.blueChannel, (nk_byte)newColor.alphaChannel};}; + void setSliderBarColorActive(Color newColor) {sliderBarColorActive = nk_color{(nk_byte)newColor.redChannel, (nk_byte)newColor.greenChannel, (nk_byte)newColor.blueChannel, (nk_byte)newColor.alphaChannel};} + void setSliderBarColorHover(Color newColor) {sliderBarColorHover = nk_color{(nk_byte)newColor.redChannel, (nk_byte)newColor.greenChannel, (nk_byte)newColor.blueChannel, (nk_byte)newColor.alphaChannel};} + void setSliderBarColorFilled(Color newColor) {sliderBarColorFilled = nk_color{(nk_byte)newColor.redChannel, (nk_byte)newColor.greenChannel, (nk_byte)newColor.blueChannel, (nk_byte)newColor.alphaChannel};} + void setSliderCursorColor(Color newColor) {sliderCursorColor = nk_color{(nk_byte)newColor.redChannel, (nk_byte)newColor.greenChannel, (nk_byte)newColor.blueChannel, (nk_byte)newColor.alphaChannel};} + void setSliderCursorColorHover(Color newColor) {sliderCursorColorHover = nk_color{(nk_byte)newColor.redChannel, (nk_byte)newColor.greenChannel, (nk_byte)newColor.blueChannel, (nk_byte)newColor.alphaChannel};} + void setSliderCurserColorActive(Color newColor) {sliderCursorColorActive = nk_color{(nk_byte)newColor.redChannel, (nk_byte)newColor.greenChannel, (nk_byte)newColor.blueChannel, (nk_byte)newColor.alphaChannel};} + }; +} \ No newline at end of file diff --git a/dependencies/subprojects/animationwindow/meson.build b/dependencies/subprojects/animationwindow/meson.build index a6e6e12fd5073b369677f56e1e554cb6def5c53f..f7f9dfc89f10ad3321d8fc24f4f7652aef6552d2 100644 --- a/dependencies/subprojects/animationwindow/meson.build +++ b/dependencies/subprojects/animationwindow/meson.build @@ -19,6 +19,7 @@ build_files = [ 'src/widgets/TextInput.cpp', 'src/widgets/TextBox.cpp', 'src/widgets/DropdownList.cpp', + 'src/widgets/Slider.cpp', 'src/AnimationWindow.cpp', 'src/Color.cpp', 'src/Image.cpp', diff --git a/dependencies/subprojects/animationwindow/src/widgets/Slider.cpp b/dependencies/subprojects/animationwindow/src/widgets/Slider.cpp new file mode 100644 index 0000000000000000000000000000000000000000..2a80404ae0d37242e888645cfd0ce4edc6499f9b --- /dev/null +++ b/dependencies/subprojects/animationwindow/src/widgets/Slider.cpp @@ -0,0 +1,38 @@ +#include "widgets/Slider.h" + +TDT4102::Slider::Slider(TDT4102::Point location, unsigned int width, unsigned int height, int min, int max, int initialValue, int step) + : TDT4102::Widget(location, width, height) { + minValue = min; + maxValue = max; + value = initialValue; + stepValue = step; +} + +int TDT4102::Slider::getValue() const { + return value; +} + +void TDT4102::Slider::update(nk_context *context) { + + struct nk_style* s = &context->style; + nk_style_push_color(context, &s->slider.bar_normal, sliderBarColor); + nk_style_push_color(context, &s->slider.bar_hover, sliderBarColorHover); + nk_style_push_color(context, &s->slider.bar_active, sliderBarColorActive); + nk_style_push_color(context, &s->slider.bar_filled, sliderBarColorFilled); + nk_style_push_style_item(context, &s->slider.cursor_normal, nk_style_item_color(sliderCursorColor)); + nk_style_push_style_item(context, &s->slider.cursor_hover, nk_style_item_color(sliderCursorColorHover)); + nk_style_push_style_item(context, &s->slider.cursor_active, nk_style_item_color(sliderCursorColorActive)); + + if (nk_slider_int(context, minValue, &value, maxValue, stepValue)) { + fire(); + } + + nk_style_pop_color(context); + nk_style_pop_color(context); + nk_style_pop_color(context); + nk_style_pop_color(context); + nk_style_pop_style_item(context); + nk_style_pop_style_item(context); + nk_style_pop_style_item(context); +} + diff --git a/dependencies/testproject_featuredemo.cpp b/dependencies/testproject_featuredemo.cpp index 2983c2289538c0c205f88ce6ea9f2fe28ccc3777..dc0ae92109ce70127a6bed2d7d59290211d58062 100644 --- a/dependencies/testproject_featuredemo.cpp +++ b/dependencies/testproject_featuredemo.cpp @@ -12,6 +12,7 @@ #include "widgets/TextInput.h" #include "widgets/RadioButton.h" #include "widgets/TextBox.h" +#include "widgets/Slider.h" #include "widgets/RadioButton.h" #include "widgets/CheckBox.h" @@ -50,6 +51,14 @@ void textChanged() { std::cout << "The input text is now: " << input.getText() << std::endl; } + TDT4102::Slider rv{{200, 300}, 300, 80}; + TDT4102::Slider gv{{200, 420}, 300, 80, 0, 255, 7}; + TDT4102::Slider bv{{200, 540}, 300, 80, 0, 255, 240}; + +// void sliderValue() { +// std::cout << "Value is: " << s.getValue() << std::endl; +// } + int main(int argc, char* argv[]) { TDT4102::AnimationWindow window(100, 100, 1000, 800, "Test"); // window.keep_previous_frame(true); @@ -73,6 +82,20 @@ int main(int argc, char* argv[]) { input.setCallback(&textChanged); window.add(input); + + rv.setCallback([&window] {window.setBackgroundColor(TDT4102::Color(rv.getValue(), gv.getValue(), bv.getValue()));}); + gv.setCallback([&window] {window.setBackgroundColor(TDT4102::Color(rv.getValue(), gv.getValue(), bv.getValue()));}); + bv.setCallback([&window] {window.setBackgroundColor(TDT4102::Color(rv.getValue(), gv.getValue(), bv.getValue()));}); + + // s.setSliderCursorColor(TDT4102::Color::lime_green); + // s.setSliderCursorColorHover(TDT4102::Color::lime_green); + // s.setSliderBarColorFilled(TDT4102::Color::pink); + + // s.setCallback(&sliderValue); + window.add(rv); + window.add(bv); + window.add(gv); + TDT4102::RadioButton rb{{200, 200}, 100, 30, "Easy"}; window.add(rb);