Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
resources
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TDT4102
VS-Code
resources
Commits
1c6bc0ec
Commit
1c6bc0ec
authored
3 months ago
by
Joakim Hunskaar
Browse files
Options
Downloads
Patches
Plain Diff
added three sliders to change bg color
parent
34a41f41
No related branches found
No related tags found
1 merge request
!11
New widget slider
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
dependencies/testproject_featuredemo.cpp
+22
-14
22 additions, 14 deletions
dependencies/testproject_featuredemo.cpp
with
22 additions
and
14 deletions
dependencies/testproject_featuredemo.cpp
+
22
−
14
View file @
1c6bc0ec
...
@@ -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.0
f
;
circles
.
at
(
i
).
xSpeed
=
float
(
randint
(
-
400
,
400
))
/
100.0
f
;
circles
.
at
(
i
).
ySpeed
=
float
(
randint
(
-
400
,
400
))
/
100.0
f
;
circles
.
at
(
i
).
ySpeed
=
float
(
randint
(
-
400
,
400
))
/
100.0
f
;
...
@@ -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.0
f
)
-
ball
.
x
;
float
gravityX
=
(
float
(
window
.
width
())
/
2.0
f
)
-
ball
.
x
;
float
gravityY
=
(
float
(
window
.
get_
height
())
/
2.0
f
)
-
ball
.
y
;
float
gravityY
=
(
float
(
window
.
height
())
/
2.0
f
)
-
ball
.
y
;
float
absoluteSpeed
=
std
::
max
(
std
::
sqrt
(
gravityX
*
gravityX
+
gravityY
*
gravityY
),
3.0
f
);
float
absoluteSpeed
=
std
::
max
(
std
::
sqrt
(
gravityX
*
gravityX
+
gravityY
*
gravityY
),
3.0
f
);
const
float
gravity
=
0.07
f
;
const
float
gravity
=
0.07
f
;
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.0
f
)
>
1.0
f
)
&&
(
std
::
abs
(
ball
.
y
-
float
(
window
.
get_
height
())
/
2.0
f
)
>
1.0
f
))
{
if
((
std
::
abs
(
ball
.
x
-
float
(
window
.
width
())
/
2.0
f
)
>
1.0
f
)
&&
(
std
::
abs
(
ball
.
y
-
float
(
window
.
height
())
/
2.0
f
)
>
1.0
f
))
{
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);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment