diff --git a/dependencies/meson.build b/dependencies/meson.build index 023cbe7c7489805f53604a5ed7ef7296504f4f67..17d8011d125348af648940a7f32a1bed1376bded 100644 --- a/dependencies/meson.build +++ b/dependencies/meson.build @@ -1,7 +1,7 @@ project('testproject', 'cpp', version : '0.1', default_options : ['warning_level=0', - 'cpp_std=c++17', + 'cpp_std=c++20', 'c_std=c17', 'default_library=static']) diff --git a/dependencies/subprojects/animationwindow/include/widgets/Button.h b/dependencies/subprojects/animationwindow/include/widgets/Button.h index 5379f231c5f30c87eb5d58a0c43791c24adf12a1..a899860a083efbea4970ba2b2f2d95bb350c6f08 100644 --- a/dependencies/subprojects/animationwindow/include/widgets/Button.h +++ b/dependencies/subprojects/animationwindow/include/widgets/Button.h @@ -4,6 +4,7 @@ #include "Point.h" #include <string> #include "Color.h" + namespace TDT4102 { class Button : public TDT4102::Widget { private: @@ -19,7 +20,7 @@ namespace TDT4102 { void update(nk_context* context) override; public: explicit Button(TDT4102::Point location, unsigned int width, unsigned int height, std::string label); - void setLabel(std::string newlabel); + void setLabel(std::string newLabel); void setLabelColor(Color newColor) {labelColor = nk_color{(nk_byte)newColor.redChannel, (nk_byte)newColor.greenChannel, (nk_byte)newColor.blueChannel, (nk_byte)newColor.alphaChannel};}; void setButtonColor(Color newColor) {buttonColor = nk_color{(nk_byte)newColor.redChannel, (nk_byte)newColor.greenChannel, (nk_byte)newColor.blueChannel, (nk_byte)newColor.alphaChannel};} void setButtonColorHover(Color newColor) {buttonColorHover = nk_color{(nk_byte)newColor.redChannel, (nk_byte)newColor.greenChannel, (nk_byte)newColor.blueChannel, (nk_byte)newColor.alphaChannel};} diff --git a/dependencies/subprojects/animationwindow/include/widgets/CheckBox.h b/dependencies/subprojects/animationwindow/include/widgets/CheckBox.h new file mode 100644 index 0000000000000000000000000000000000000000..d4375d2d025f7eb8f665597365fa4455ad7f881b --- /dev/null +++ b/dependencies/subprojects/animationwindow/include/widgets/CheckBox.h @@ -0,0 +1,31 @@ +#pragma once + +#include "Widget.h" +#include "Point.h" +#include <string> +#include "Color.h" + +namespace TDT4102 { + class CheckBox : public TDT4102::Widget { + private: + std::string label; + nk_bool isSelected_ = false; + bool lastRightMouseButtonState = false; + bool lastLeftMouseButtonState = false; + nk_color labelColor = nk_rgba(100, 100, 100, 255); + nk_color checkBoxColor = nk_rgba(150, 150, 150, 255); + nk_color checkBoxColorHover = nk_rgba(150, 150, 150, 255); + nk_color checkBoxColorActive = nk_rgba(150, 150, 150, 255); + + protected: + void update(nk_context* context) override; + public: + explicit CheckBox(TDT4102::Point location, unsigned int width, unsigned int height, std::string label); + bool isSelected() const; + void setLabel(std::string newLabel); + void setLabelColor(Color newColor) {labelColor = nk_color{(nk_byte)newColor.redChannel, (nk_byte)newColor.greenChannel, (nk_byte)newColor.blueChannel, (nk_byte)newColor.alphaChannel};}; + void setCheckBoxColor(Color newColor) {checkBoxColor = nk_color{(nk_byte)newColor.redChannel, (nk_byte)newColor.greenChannel, (nk_byte)newColor.blueChannel, (nk_byte)newColor.alphaChannel};} + void setCheckBoxColorHover(Color newColor) {checkBoxColorHover = nk_color{(nk_byte)newColor.redChannel, (nk_byte)newColor.greenChannel, (nk_byte)newColor.blueChannel, (nk_byte)newColor.alphaChannel};} + void setCheckBoxColorActive(Color newColor) {checkBoxColorActive = 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/include/widgets/RadioButton.h b/dependencies/subprojects/animationwindow/include/widgets/RadioButton.h new file mode 100644 index 0000000000000000000000000000000000000000..b2f0149c98e3ec0ec3f95d16232dc2703e4e1428 --- /dev/null +++ b/dependencies/subprojects/animationwindow/include/widgets/RadioButton.h @@ -0,0 +1,31 @@ +#pragma once + +#include "Widget.h" +#include "Point.h" +#include <string> +#include "Color.h" + +namespace TDT4102 { + class RadioButton : public TDT4102::Widget { + private: + std::string label; + nk_bool isSelected_ = false; + bool lastRightMouseButtonState = false; + bool lastLeftMouseButtonState = false; + nk_color labelColor = nk_rgba(100, 100, 100, 255); + nk_color radioColor = nk_rgba(150, 150, 150, 255); + nk_color radioColorHover = nk_rgba(150, 150, 150, 255); + nk_color radioColorActive = nk_rgba(150, 150, 150, 255); + + protected: + void update(nk_context* context) override; + public: + explicit RadioButton(TDT4102::Point location, unsigned int width, unsigned int height, std::string label); + bool isSelected() const; + void setLabel(std::string newLabel); + void setLabelColor(Color newColor) {labelColor = nk_color{(nk_byte)newColor.redChannel, (nk_byte)newColor.greenChannel, (nk_byte)newColor.blueChannel, (nk_byte)newColor.alphaChannel};}; + void setRadioColor(Color newColor) {radioColor = nk_color{(nk_byte)newColor.redChannel, (nk_byte)newColor.greenChannel, (nk_byte)newColor.blueChannel, (nk_byte)newColor.alphaChannel};} + void setRadioColorHover(Color newColor) {radioColorHover = nk_color{(nk_byte)newColor.redChannel, (nk_byte)newColor.greenChannel, (nk_byte)newColor.blueChannel, (nk_byte)newColor.alphaChannel};} + void setRadioColorActive(Color newColor) {radioColorActive = 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/include/widgets/TextBox.h b/dependencies/subprojects/animationwindow/include/widgets/TextBox.h index 4d6d9a21d23c716591559e966f50c02b8a4e9654..c4ed8e20908b5dbee9a1acbeb0b35af06a340cd1 100644 --- a/dependencies/subprojects/animationwindow/include/widgets/TextBox.h +++ b/dependencies/subprojects/animationwindow/include/widgets/TextBox.h @@ -12,7 +12,7 @@ namespace TDT4102 { class TextBox : public TDT4102::Widget { private: - std::string text; + std::string contents; nk_color textColor = nk_rgba(175, 175, 175, 255); nk_color boxColor = nk_rgba(50 , 50, 50, 255); nk_color borderColor = nk_rgba(50, 50, 50, 255); @@ -20,6 +20,7 @@ namespace TDT4102 { void update(nk_context* context) override; public: explicit TextBox(TDT4102::Point location, unsigned int width, unsigned int height, std::string initialText = ""); + std::string getText() const; void setText(std::string updatedText); void setTextColor(TDT4102::Color newColor) {textColor = nk_color{(nk_byte)newColor.redChannel, (nk_byte)newColor.greenChannel, (nk_byte)newColor.blueChannel, (nk_byte)newColor.alphaChannel};} void setBoxColor(TDT4102::Color newColor) {boxColor = nk_color{(nk_byte)newColor.redChannel, (nk_byte)newColor.greenChannel, (nk_byte)newColor.blueChannel, (nk_byte)newColor.alphaChannel};} diff --git a/dependencies/subprojects/animationwindow/meson.build b/dependencies/subprojects/animationwindow/meson.build index ae86abd0a08710f8fb365b15ef14637ce79bd6a2..a6e6e12fd5073b369677f56e1e554cb6def5c53f 100644 --- a/dependencies/subprojects/animationwindow/meson.build +++ b/dependencies/subprojects/animationwindow/meson.build @@ -1,4 +1,4 @@ -project('animationwindow', ['c', 'cpp'], version: '0.01', default_options: ['cpp_std=c++20', 'default_library=static', 'buildtype=debugoptimized']) +project('animationwindow', ['c', 'cpp'], version: '0.01', default_options: ['cpp_std=c++20', 'c_std=c17', 'default_library=static', 'buildtype=debugoptimized']) if host_machine.system() == 'windows' sdl2_dep = subproject('sdl2_windows').get_variable('sdl2_windows_dep') @@ -14,6 +14,8 @@ build_files = [ 'src/internal/KeyboardKeyConverter.cpp', 'src/internal/nuklear_implementation.cpp', 'src/widgets/Button.cpp', + 'src/widgets/RadioButton.cpp', + 'src/widgets/CheckBox.cpp', 'src/widgets/TextInput.cpp', 'src/widgets/TextBox.cpp', 'src/widgets/DropdownList.cpp', diff --git a/dependencies/subprojects/animationwindow/src/widgets/Button.cpp b/dependencies/subprojects/animationwindow/src/widgets/Button.cpp index 7b769441631ed52802460ecdf57f7a7de056c799..bd1227ccf136a7c12f4df8cd90c7a064011c9d25 100644 --- a/dependencies/subprojects/animationwindow/src/widgets/Button.cpp +++ b/dependencies/subprojects/animationwindow/src/widgets/Button.cpp @@ -32,6 +32,6 @@ void TDT4102::Button::update(nk_context *context) { nk_style_pop_style_item(context); } -void TDT4102::Button::setLabel(std::string newlabel) { - label = newlabel; +void TDT4102::Button::setLabel(std::string newLabel) { + label = newLabel; } diff --git a/dependencies/subprojects/animationwindow/src/widgets/CheckBox.cpp b/dependencies/subprojects/animationwindow/src/widgets/CheckBox.cpp new file mode 100644 index 0000000000000000000000000000000000000000..0b9d463e2fc9ab6cfb5e6bd7606795d8abcf63d8 --- /dev/null +++ b/dependencies/subprojects/animationwindow/src/widgets/CheckBox.cpp @@ -0,0 +1,44 @@ +#include "widgets/CheckBox.h" + + +TDT4102::CheckBox::CheckBox(TDT4102::Point location, unsigned int width, unsigned int height, std::string label) : + TDT4102::Widget(location, width, height), + label{std::move(label)} {} + +void TDT4102::CheckBox::update(nk_context *context) { + if (nk_input_has_mouse_click_down_in_rect(&context->input, NK_BUTTON_RIGHT, context->current->layout->clip, true)) { + isSelected_ = false; + } + if (nk_input_has_mouse_click_down_in_rect(&context->input, NK_BUTTON_LEFT, context->current->layout->clip, true)) { + isSelected_ = true; + } + + struct nk_style* s = &context->style; + nk_style_push_color(context, &s->checkbox.text_normal, labelColor); + nk_style_push_color(context, &s->checkbox.text_hover, labelColor); + nk_style_push_color(context, &s->checkbox.text_active, labelColor); + nk_style_push_style_item(context, &s->checkbox.normal, nk_style_item_color(checkBoxColor)); + nk_style_push_style_item(context, &s->checkbox.hover, nk_style_item_color(checkBoxColorHover)); + nk_style_push_style_item(context, &s->checkbox.active, nk_style_item_color(checkBoxColorActive)); + + if (nk_checkbox_label(context, label.data(), &isSelected_)) { + isSelected_ = true; + fire(); + } + + 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); + +} + +void TDT4102::CheckBox::setLabel(std::string newLabel) { + label = newLabel; +} + +bool TDT4102::CheckBox::isSelected() const { + return (bool)isSelected_; +} diff --git a/dependencies/subprojects/animationwindow/src/widgets/RadioButton.cpp b/dependencies/subprojects/animationwindow/src/widgets/RadioButton.cpp new file mode 100644 index 0000000000000000000000000000000000000000..59d9616f08f1260495b16f7886cf4a3c13110279 --- /dev/null +++ b/dependencies/subprojects/animationwindow/src/widgets/RadioButton.cpp @@ -0,0 +1,45 @@ +#include "widgets/RadioButton.h" + + +TDT4102::RadioButton::RadioButton(TDT4102::Point location, unsigned int width, unsigned int height, std::string label) : + TDT4102::Widget(location, width, height), + label{std::move(label)} {} + +void TDT4102::RadioButton::update(nk_context *context) { + if (nk_input_has_mouse_click_down_in_rect(&context->input, NK_BUTTON_RIGHT, context->current->layout->clip, true)) { + isSelected_ = false; + } + if (nk_input_has_mouse_click_down_in_rect(&context->input, NK_BUTTON_LEFT, context->current->layout->clip, true)) { + isSelected_ = true; + } + + struct nk_style* s = &context->style; + nk_style_push_color(context, &s->option.text_normal, labelColor); + nk_style_push_color(context, &s->option.text_hover, labelColor); + nk_style_push_color(context, &s->option.text_active, labelColor); + nk_style_push_style_item(context, &s->option.normal, nk_style_item_color(radioColor)); + nk_style_push_style_item(context, &s->option.hover, nk_style_item_color(radioColorHover)); + nk_style_push_style_item(context, &s->option.active, nk_style_item_color(radioColorActive)); + + if (nk_radio_label(context, label.data(), &isSelected_)) { + isSelected_ = true; + fire(); + } + + 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); + +} + +void TDT4102::RadioButton::setLabel(std::string newLabel) { + label = newLabel; +} + +bool TDT4102::RadioButton::isSelected() const { + return (bool)isSelected_; +} + diff --git a/dependencies/subprojects/animationwindow/src/widgets/TextBox.cpp b/dependencies/subprojects/animationwindow/src/widgets/TextBox.cpp index 3f4d3c2d1b877e4431304dd1bfed65de727ec8c6..f97c9609b561c7fc99c97022316ff56efb7b1551 100644 --- a/dependencies/subprojects/animationwindow/src/widgets/TextBox.cpp +++ b/dependencies/subprojects/animationwindow/src/widgets/TextBox.cpp @@ -5,7 +5,7 @@ void TDT4102::TextBox::update(nk_context *context) { nk_style_push_color(context, &s->edit.text_normal, textColor); nk_style_push_color(context, &s->edit.border_color, borderColor); nk_style_push_style_item(context, &s->edit.normal, nk_style_item_color(boxColor)); - nk_edit_string_zero_terminated(context, NK_EDIT_READ_ONLY, const_cast<char*>(text.data()), internal::TEXT_BOX_CHARACTER_LIMIT, nk_filter_ascii); + nk_edit_string_zero_terminated(context, NK_EDIT_READ_ONLY, const_cast<char*>(contents.data()), internal::TEXT_BOX_CHARACTER_LIMIT, nk_filter_ascii); nk_style_pop_color(context); nk_style_pop_color(context); nk_style_pop_style_item(context); @@ -13,13 +13,17 @@ void TDT4102::TextBox::update(nk_context *context) { TDT4102::TextBox::TextBox(TDT4102::Point location, unsigned int width, unsigned int height, std::string initialText) : TDT4102::Widget(location, width, height) { - text = initialText; - text.resize(internal::TEXT_BOX_CHARACTER_LIMIT); + contents = initialText; + contents.resize(internal::TEXT_BOX_CHARACTER_LIMIT); } +std::string TDT4102::TextBox::getText() const { + return std::string(contents.data());; +} + void TDT4102::TextBox::setText(std::string updatedText) { - text = updatedText; - text.resize(internal::TEXT_BOX_CHARACTER_LIMIT); + contents = updatedText; + contents.resize(internal::TEXT_BOX_CHARACTER_LIMIT); } diff --git a/dependencies/subprojects/std_lib_facilities/meson.build b/dependencies/subprojects/std_lib_facilities/meson.build index 9448436feea0d8199f8f25f747c9e31eb7ed2952..dfefbc90aec7840c401e5cb7bd04fabb163838f9 100644 --- a/dependencies/subprojects/std_lib_facilities/meson.build +++ b/dependencies/subprojects/std_lib_facilities/meson.build @@ -1,4 +1,4 @@ -project('std_lib_facilities', ['c', 'cpp'], version: '0.01', default_options: ['cpp_std=c++17', 'default_library=static', 'buildtype=debugoptimized']) +project('std_lib_facilities', ['c', 'cpp'], version: '0.01', default_options: ['cpp_std=c++20', 'c_std=c17', 'default_library=static', 'buildtype=debugoptimized']) incdir = include_directories('.') install_subdir('include', install_dir: '.') diff --git a/dependencies/testproject_featuredemo.cpp b/dependencies/testproject_featuredemo.cpp index 183eb88bbd200ecd0e8b799a9745b3399e46a91b..2983c2289538c0c205f88ce6ea9f2fe28ccc3777 100644 --- a/dependencies/testproject_featuredemo.cpp +++ b/dependencies/testproject_featuredemo.cpp @@ -10,7 +10,10 @@ #include "widgets/Button.h" #include "widgets/TextInput.h" +#include "widgets/RadioButton.h" #include "widgets/TextBox.h" +#include "widgets/RadioButton.h" +#include "widgets/CheckBox.h" struct Ball { float x = 0; @@ -64,24 +67,45 @@ int main(int argc, char* argv[]) { TDT4102::TextBox b{{300, 200}, 108, 35, "TEXTBOX!"}; window.add(b); + b.setBoxColor(TDT4102::Color::dark_orange); + b.setTextColor(TDT4102::Color::green); input.setCallback(&textChanged); window.add(input); + TDT4102::RadioButton rb{{200, 200}, 100, 30, "Easy"}; + window.add(rb); + + rb.setLabelColor(TDT4102::Color::salmon); + + rb.setRadioColor(TDT4102::Color::gold); + rb.setRadioColorHover(TDT4102::Color::lime_green); + rb.setRadioColorActive(TDT4102::Color::aquamarine); + + TDT4102::CheckBox cb{{200, 300}, 120, 50, "Check"}; + window.add(cb); + // cb.setLabelColor(TDT4102::Color::blue); + cb.setCheckBoxColorHover(TDT4102::Color::red); + // cb.setCheckBoxColorActive(TDT4102::Color::green); + cb.setLabel("This is a"); + int x = 10; int y = 10; // TDT4102::Image image("res/unknown.jpg"); // image.width = 100; // image.height = 100; + // // TDT4102::Image image("res/unknown.jpg"); + // // image.width = 100; + // // image.height = 100; std::vector<std::string> colors{"red", "gold", "green", "rebecca_purple", "blue"}; std::vector<Ball> circles; circles.resize(5000); for (unsigned int i = 0; i < circles.size(); i++) { - circles.at(i).x = randint(0, window.get_width()); - circles.at(i).y = randint(0, window.get_height()); + circles.at(i).x = randint(0, window.width()); + circles.at(i).y = randint(0, window.height()); circles.at(i).radius = randint(5, 10); circles.at(i).xSpeed = float(randint(-400, 400)) / 100.0f; circles.at(i).ySpeed = float(randint(-400, 400)) / 100.0f; @@ -108,10 +132,26 @@ int main(int argc, char* argv[]) { // window.draw_text({mousePosition.x, mousePosition.y + 200}, std::to_string(mousePosition.x) + ", " + std::to_string(mousePosition.y), TDT4102::Color::brown, 70, TDT4102::Font::courier_bold_italic); // window.draw_arc({500, 500}, mousePosition.x, mousePosition.y, 190, 350, TDT4102::Color::orange); // window.draw_image(mousePosition, image); + // if (rb.isSelected()) { + // std::cout << "Checked\n"; + // } else { + // std::cout << "Not checked\n"; + // } + + // window.draw_text({mousePosition.x, mousePosition.y + 100}, std::to_string(mousePosition.x) + ", " + std::to_string(mousePosition.y)); + // window.draw_text({mousePosition.x, mousePosition.y + 200}, std::to_string(mousePosition.x) + ", " + std::to_string(mousePosition.y), TDT4102::Color::brown, 70, TDT4102::Font::courier_bold_italic); + // window.draw_arc({500, 500}, mousePosition.x, mousePosition.y, 190, 350, TDT4102::Color::orange); + // window.draw_image(mousePosition, image); + // if (rb.isSelected()) { + // std::cout << "Checked\n"; + // } else { + // std::cout << "Not checked\n"; + // } + bool allAtCenter = true; for (Ball& ball : circles) { - float gravityX = (float(window.get_width()) / 2.0f) - ball.x; - float gravityY = (float(window.get_height()) / 2.0f) - ball.y; + float gravityX = (float(window.width()) / 2.0f) - ball.x; + float gravityY = (float(window.height()) / 2.0f) - ball.y; float absoluteSpeed = std::max(std::sqrt(gravityX * gravityX + gravityY * gravityY), 3.0f); const float gravity = 0.07f; ball.xSpeed += (gravityX / absoluteSpeed) * gravity; @@ -130,10 +170,12 @@ int main(int argc, char* argv[]) { } else if(ball.y + ball.radius < 0) { ball.y = window.h() + ball.radius; }*/ - if ((std::abs(ball.x - float(window.get_width()) / 2.0f) > 1.0f) && (std::abs(ball.y - float(window.get_height()) / 2.0f) > 1.0f)) { + if ((std::abs(ball.x - float(window.width()) / 2.0f) > 1.0f) && (std::abs(ball.y - float(window.height()) / 2.0f) > 1.0f)) { allAtCenter = false; } // window.draw_circle({int(ball.x), int(ball.y)}, ball.radius, ball.colour, TDT4102::Color::black); + // window.draw_circle({int(ball.x), int(ball.y)}, ball.radius, ball.colour, TDT4102::Color::black); + // window.draw_circle({int(ball.x), int(ball.y)}, ball.radius, ball.colour, TDT4102::Color::black); } if (allAtCenter) { for (int i = 0; i < circles.size(); i++) {