Skip to content
Snippets Groups Projects
Commit 1c6bc0ec authored by Joakim Hunskaar's avatar Joakim Hunskaar
Browse files

added three sliders to change bg color

parent 34a41f41
No related branches found
No related tags found
1 merge request!11New widget slider
...@@ -48,11 +48,13 @@ void textChanged() { ...@@ -48,11 +48,13 @@ void textChanged() {
std::cout << "The input text is now: " << input.getText() << std::endl; std::cout << "The input text is now: " << input.getText() << std::endl;
} }
TDT4102::Slider s{{200, 300}, 200, 100, 0, 100, 0}; 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() { // void sliderValue() {
std::cout << "Value is: " << s.getValue() << std::endl; // std::cout << "Value is: " << s.getValue() << std::endl;
} // }
int main(int argc, char* argv[]) { int main(int argc, char* argv[]) {
TDT4102::AnimationWindow window(100, 100, 1000, 800, "Test"); TDT4102::AnimationWindow window(100, 100, 1000, 800, "Test");
...@@ -75,12 +77,18 @@ int main(int argc, char* argv[]) { ...@@ -75,12 +77,18 @@ int main(int argc, char* argv[]) {
input.setCallback(&textChanged); input.setCallback(&textChanged);
window.add(input); window.add(input);
s.setSliderCursorColor(TDT4102::Color::lime_green); rv.setCallback([&window] {window.setBackgroundColor(TDT4102::Color(rv.getValue(), gv.getValue(), bv.getValue()));});
s.setSliderCursorColorHover(TDT4102::Color::lime_green); gv.setCallback([&window] {window.setBackgroundColor(TDT4102::Color(rv.getValue(), gv.getValue(), bv.getValue()));});
s.setSliderBarColorFilled(TDT4102::Color::pink); 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); // s.setCallback(&sliderValue);
window.add(s); window.add(rv);
window.add(bv);
window.add(gv);
int x = 10; int x = 10;
int y = 10; int y = 10;
...@@ -94,8 +102,8 @@ int main(int argc, char* argv[]) { ...@@ -94,8 +102,8 @@ int main(int argc, char* argv[]) {
std::vector<Ball> circles; std::vector<Ball> circles;
circles.resize(5000); circles.resize(5000);
for (unsigned int i = 0; i < circles.size(); i++) { for (unsigned int i = 0; i < circles.size(); i++) {
circles.at(i).x = randint(0, window.get_width()); circles.at(i).x = randint(0, window.width());
circles.at(i).y = randint(0, window.get_height()); circles.at(i).y = randint(0, window.height());
circles.at(i).radius = randint(5, 10); circles.at(i).radius = randint(5, 10);
circles.at(i).xSpeed = float(randint(-400, 400)) / 100.0f; circles.at(i).xSpeed = float(randint(-400, 400)) / 100.0f;
circles.at(i).ySpeed = float(randint(-400, 400)) / 100.0f; circles.at(i).ySpeed = float(randint(-400, 400)) / 100.0f;
...@@ -124,8 +132,8 @@ int main(int argc, char* argv[]) { ...@@ -124,8 +132,8 @@ int main(int argc, char* argv[]) {
// window.draw_image(mousePosition, image); // window.draw_image(mousePosition, image);
bool allAtCenter = true; bool allAtCenter = true;
for (Ball& ball : circles) { for (Ball& ball : circles) {
float gravityX = (float(window.get_width()) / 2.0f) - ball.x; float gravityX = (float(window.width()) / 2.0f) - ball.x;
float gravityY = (float(window.get_height()) / 2.0f) - ball.y; float gravityY = (float(window.height()) / 2.0f) - ball.y;
float absoluteSpeed = std::max(std::sqrt(gravityX * gravityX + gravityY * gravityY), 3.0f); float absoluteSpeed = std::max(std::sqrt(gravityX * gravityX + gravityY * gravityY), 3.0f);
const float gravity = 0.07f; const float gravity = 0.07f;
ball.xSpeed += (gravityX / absoluteSpeed) * gravity; ball.xSpeed += (gravityX / absoluteSpeed) * gravity;
...@@ -144,7 +152,7 @@ int main(int argc, char* argv[]) { ...@@ -144,7 +152,7 @@ int main(int argc, char* argv[]) {
} else if(ball.y + ball.radius < 0) { } else if(ball.y + ball.radius < 0) {
ball.y = window.h() + ball.radius; 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; 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);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment