-
Notifications
You must be signed in to change notification settings - Fork 4
/
View.cpp
150 lines (118 loc) · 4.38 KB
/
View.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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
/////////////////////////////////////////////////////////////////////////////////////
// //
// Copyright 2011-2013 NYU Polytechnic School of Engineering. //
// Copyright 2010-2011 University of Utah. //
// //
// Permission is hereby granted, free of charge, to any person obtaining a copy //
// of this software and associated documentation files (the "Software"), to dea //
// in the Software without restriction, including without limitation the rights //
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell //
// copies of the Software, and to permit persons to whom the Software is //
// furnished to do so, subject to the following conditions: //
// //
// The above copyright notice and this permission notice shall be included in //
// all copies or substantial portions of the Software. //
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR //
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, //
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE //
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER //
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, //
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN //
// THE SOFTWARE. //
// //
/////////////////////////////////////////////////////////////////////////////////////
#include "View.hpp"
View::View(){
}
View::View(int x, int y, int width, int height){
this->x = x;
this->y = y;
this->width = width;
this->height = height;
this->setBackgroundColor(0.05,0.05,0.05,0.93);
}
int View::getX(){
return this->x;
}
void View::setX(int newX){
this->x = newX;
}
int View::getY(){
return this->y;
}
void View::setY(int newY){
this->y = newY;
}
int View::getWidth(){
return this->width;
}
void View::setWidth(int newWidth){
this->width = newWidth;
}
int View::getHeight(){
return this->height;
}
void View::setHeight(int newHeight){
this->height = newHeight;
}
bool View::contains(int x, int y){
bool horizontal = false;
bool vertical = false;
horizontal = (this->x <= x) && (x <= (this->x + this->width));
vertical = (this->y <= y) && (y <= (this->y + this->height));
// cout << "horizontal = " << horizontal << endl;
// cout << "vertical = " << vertical << endl;
return horizontal && vertical;
}
bool View::isInResize(int x, int y){
int pi1;
int pi2;
int pi3;
int vec1[2];
vec1[0] = x - (this->x + this->width - 10);
vec1[1] = y - (this->y+this->height);
int vec2[2];
vec2[0] = x - (this->x + this->width);
vec2[1] = y - (this->y+this->height);
int vec3[2];
vec3[0] = x - (this->x + this->width);
vec3[1] = y - (this->y+this->height - 10);
pi1 = vec1[0]*vec2[0] + vec1[1]*vec2[1] ;
pi2 = vec1[0]*vec3[0] + vec1[1]*vec3[1] ;
pi3 = vec3[0]*vec2[0] + vec3[1]*vec2[1] ;
// cout << "pi1 = " << pi1 << endl;
// cout << "pi2 = " << pi2 << endl;
// cout << "pi3 = " << pi3 << endl;
int score = 0;
if(pi1 < 0) score--;
if(pi2 < 0) score--;
if(pi3 < 0) score--;
cout << "Result = " << (score <=-2) << endl;
return score <=-2;
}
void View::getBackgroundColor(float *r,float *g,
float *b,float *a){
(*r) = this->backgroundColor[0];
(*g) = this->backgroundColor[1];
(*b) = this->backgroundColor[2];
(*a) = this->backgroundColor[3];
}
void View::setBackgroundColor(float r,float g,
float b,float a){
this->backgroundColor[0] = r;
this->backgroundColor[1] = g;
this->backgroundColor[2] = b;
this->backgroundColor[3] = a;
}
void View::translate(int dx, int dy){
this->x += dx;
this->y += dy;
}
void View::resize(int dx, int dy){
if(this->width + dx <= 50) this->width = 50;
else this->width += dx;
if(this->height + dy <= 50) this->height = 50;
else this->height += dy;
}
void View::paint() { };