-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDrawableShape.cpp
More file actions
122 lines (102 loc) · 4.02 KB
/
DrawableShape.cpp
File metadata and controls
122 lines (102 loc) · 4.02 KB
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
#include "DrawableShape.h"
#include "iostream"
int DrawableShape::GetHeight() {
return image->GetHeight();
}
int DrawableShape::GetWidth() {
return image->GetWidth();
}
void DrawableShape::PaintOnGraphics(Gdiplus::Graphics &graphics) {
graphics.DrawImage(image, gameZoneX0 + offsetX * scale, gameZoneY0 + offsetY * scale, this->GetWidth() * scale,
this->GetHeight() * scale);
EndPaint();
}
void DrawableShape::EndPaint() {
needRepaint = false;
SetRepaintRECT();
CalculateRECT();
wasFilled = false;
}
void DrawableShape::CalculateRECT() {
rect.left = offsetX;
rect.right = offsetX + image->GetWidth();
rect.bottom = offsetY + image->GetHeight();
rect.top = offsetY;
}
void DrawableShape::SetNeedRepaint() {
needRepaint = true;
}
bool DrawableShape::IsNeedRepaint() const {
return needRepaint;
}
void DrawableShape::SetRepaintRECT() {
repaintRect.left = round(offsetX * scale + gameZoneX0);
repaintRect.right = ceil((offsetX + image->GetWidth()) * scale + gameZoneX0);
repaintRect.bottom = ceil((offsetY + image->GetHeight()) * scale + gameZoneY0);
repaintRect.top = round(offsetY * scale + gameZoneY0);
wasFilled = true;
}
bool DrawableShape::IsWasFilled() const {
return wasFilled;
}
FloatRECT DrawableShape::GetRECT() {
return rect;
}
int DrawableShape::GetNumOfIntersection(FloatRECT TargetRect) {
BoolRECT occurrences = FindOccurrences(TargetRect, rect);
int numOfOccurrences = occurrences.leftUp + occurrences.leftDown + occurrences.rightDown + occurrences.rightUp;
switch (numOfOccurrences) {
case 0:
return INTERSECTION_NONE;
case 1: {
if (occurrences.rightDown) {
if (rect.bottom - TargetRect.top < rect.right - TargetRect.left) return INTERSECTION_UP;
if (rect.bottom - TargetRect.top > rect.right - TargetRect.left) return INTERSECTION_LEFT;
return INTERSECTION_LEFT_AND_UP;
}
if (occurrences.leftDown) {
if (rect.bottom - TargetRect.top < TargetRect.right - rect.left) return INTERSECTION_UP;
if (rect.bottom - TargetRect.top > TargetRect.right - rect.left) return INTERSECTION_RIGHT;
return INTERSECTION_RIGHT_AND_UP;
}
if (occurrences.leftUp) {
if (TargetRect.right - rect.left < TargetRect.bottom - rect.top) return INTERSECTION_RIGHT;
if (TargetRect.right - rect.left > TargetRect.bottom - rect.top) return INTERSECTION_DOWN;
return INTERSECTION_RIGHT_AND_DOWN;
}
if (occurrences.rightUp) {
if (rect.right - TargetRect.left > TargetRect.bottom - rect.top) return INTERSECTION_DOWN;
if (rect.right - TargetRect.left < TargetRect.bottom - rect.top) return INTERSECTION_LEFT;
return INTERSECTION_LEFT_AND_DOWN;
}
}
break;
case 2: {
if (occurrences.rightDown && occurrences.rightUp) return INTERSECTION_LEFT;
if (occurrences.leftDown && occurrences.rightDown) return INTERSECTION_UP;
if (occurrences.leftDown && occurrences.leftUp) return INTERSECTION_RIGHT;
if (occurrences.leftUp && occurrences.rightUp) return INTERSECTION_DOWN;
}
break;
default:
throw std::exception();
}
return 0;
}
void DrawableShape::PrepareToRelocate() {
if (!IsWasFilled()) {
SetRepaintRECT();
}
SetNeedRepaint();
}
void DrawableShape::SetOffsetX(float offset) {
PrepareToRelocate();
offsetX = offset;
}
void DrawableShape::SetOffsetY(float offset) {
PrepareToRelocate();
offsetY = offset;
}
DrawableShape::DrawableShape(float &gameZoneX0, float &gameZoneY0, Gdiplus::Image *&image, float &scale, float offsetX,
float offsetY) : gameZoneX0(gameZoneX0), gameZoneY0(gameZoneY0), image(image),
scale(scale), offsetX(offsetX), offsetY(offsetY) {}