-
Notifications
You must be signed in to change notification settings - Fork 0
/
checkBox.cpp
128 lines (107 loc) · 3.64 KB
/
checkBox.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
//
// checkBox.cpp
// visuals
//
// Created by Matthew Eatough on 19/1/2022.
// Copyright © 2022 The Good Goomba. All rights reserved.
//
#include "Headers/checkBox.hpp"
void checkBox::startUp(float x, float y, float size)
{
outer = sf::RectangleShape(sf::Vector2f(size,size));
outer.setOrigin(0,size/2);
outer.setPosition(x, y);
outer.setFillColor(sf::Color::Black);
outer.setOutlineColor(sf::Color(200,200,200));
outer.setOutlineThickness(2);
pointX = {6,0,20,20,47,50};
pointY = {14,20,27,40,0,10};
for(int i=0; i<pointY.size();i++){
pointX[i] = ((pointX[i] + 15)*size*0.01) + x;
pointY[i] = ((pointY[i] -10)*size*0.01) + y;
}
M[0] = (pointY[0]-pointY[2])/(pointX[0]-pointX[2]);
M[1] = (pointY[1]-pointY[3])/(pointX[1]-pointX[3]);
M[2] = (pointY[2]-pointY[4])/(pointX[2]-pointX[4]);
M[3] = (pointY[3]-pointY[5])/(pointX[3]-pointX[5]);
animating = false;
checked = false;
animationPhase = 0;
}
bool checkBox::touchy(float mouseX, float mouseY)
{
sf::FloatRect rectangel{
outer.getPosition().x,
outer.getPosition().y-outer.getGlobalBounds().height/2,
outer.getGlobalBounds().width,
outer.getGlobalBounds().height
};
if(rectangel.contains(mouseX, mouseY))
return true;
else
return false;
}
void checkBox::animate(bool click)
{
if (click){
if (checked)
checked = false;
else
checked = true;
animating = true;
} else
{
if (checked)
{
animationPhase += 0.1;
if (animationPhase>=1){
animationPhase = 1;
animating = false;
}
} else
{
animationPhase -= 0.1;
if (animationPhase<=0){
animationPhase = 0;
animating = false;
check.clear();
return;
}
}
check.clear();
if (animationPhase<0.5)
{
for (int i=0; i<2;i++){
check.append(sf::Vertex());
check[i].position = sf::Vector2f(pointX[i],pointY[i]);
}
check.append(sf::Vertex());
check.append(sf::Vertex());
check[2] = sf::Vector2f((pointX[0])+((pointX[2]-pointX[0])/4)*10*animationPhase,
pointY[0]+((pointX[2]-pointX[0])/4)*10*animationPhase*M[0]);
check[3] = sf::Vector2f((pointX[1])+((pointX[3]-pointX[1])/4)*10*animationPhase,
pointY[1]+((pointX[3]-pointX[1])/4)*10*animationPhase*M[1]);
} else
{
for (int i=0; i<4;i++){
check.append(sf::Vertex());
check[i].position = sf::Vector2f(pointX[i],pointY[i]);
check[i].color = sf::Color::White;
}
check.append(sf::Vertex());
check[4] = sf::Vector2f((pointX[2])+((pointX[4]-pointX[2])/6)*10*animationPhase,
pointY[2]+((pointX[4]-pointX[2])/6)*10*animationPhase*M[2]);
check.append(sf::Vertex());
check[5] = sf::Vector2f((pointX[3])+((pointX[5]-pointX[3])/6)*10*animationPhase,
pointY[3]+((pointX[5]-pointX[3])/6)*10*animationPhase*M[3]);
}
for (int i=0; i<check.getVertexCount();i++)
{
check[i].color = sf::Color::White;
}
}
}
// for (int i=0; i<2;i++){
// check[0].position = sf::Vector2f(pointX[i],pointY[i]);
// check[i].color = sf::Color::White;
// }