-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathCAniRect.cpp
161 lines (117 loc) · 3.77 KB
/
CAniRect.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
151
152
153
154
155
156
157
158
159
160
161
// CAniRect.cpp
//
// CAniRect class
#include <windows.h>
#include "Alchemy.h"
#include "DirectXUtil.h"
#include <math.h>
#include <stdio.h>
#include "Reanimator.h"
const int INDEX_VISIBLE = 0;
#define PROP_VISIBLE CONSTLIT("visible")
const int INDEX_POSITION = 1;
#define PROP_POSITION CONSTLIT("position")
const int INDEX_SCALE = 2;
#define PROP_SCALE CONSTLIT("scale")
const int INDEX_ROTATION = 3;
#define PROP_ROTATION CONSTLIT("rotation")
const int INDEX_LINE_PADDING = 4;
#define PROP_LINE_PADDING CONSTLIT("linePadding")
const int INDEX_OPACITY = 5;
#define PROP_OPACITY CONSTLIT("opacity")
#define PROP_COLOR CONSTLIT("color")
#define PROP_LINE_WIDTH CONSTLIT("lineWidth")
const int PADDING_BOTTOM = 8;
const int PADDING_LEFT = 8;
const int PADDING_RIGHT = 8;
const int PADDING_TOP = 8;
CAniRect::CAniRect (void)
// CAniRect constructor
{
m_Properties.SetInteger(PROP_VISIBLE, 1);
m_Properties.SetVector(PROP_POSITION, CVector());
m_Properties.SetVector(PROP_SCALE, CVector(1.0, 1.0));
m_Properties.SetInteger(PROP_ROTATION, 0);
m_Properties.SetInteger(PROP_LINE_PADDING, 0);
m_Properties.SetOpacity(PROP_OPACITY, 255);
}
void CAniRect::Create (const CVector &vPos,
const CVector &vSize,
CG32bitPixel rgbColor,
DWORD dwOpacity,
IAnimatron **retpAni)
// Create
//
// Creates an element
{
CAniRect *pRect = new CAniRect;
pRect->SetPropertyVector(PROP_POSITION, vPos);
pRect->SetPropertyVector(PROP_SCALE, vSize);
pRect->SetPropertyColor(PROP_COLOR, rgbColor);
pRect->SetPropertyOpacity(PROP_OPACITY, dwOpacity);
*retpAni = pRect;
}
void CAniRect::GetContentRect (RECT *retrcRect)
// GetContentRect
//
// Returns a RECT of the content area (relative to the rect itself)
{
CVector vScale = m_Properties[INDEX_SCALE].GetVector();
int iPadding = m_Properties[INDEX_LINE_PADDING].GetInteger();
retrcRect->left = iPadding + PADDING_LEFT;
retrcRect->top = iPadding + PADDING_TOP;
retrcRect->right = (int)vScale.GetX() - (iPadding + PADDING_RIGHT);
retrcRect->bottom = (int)vScale.GetY() - (iPadding + PADDING_BOTTOM);
}
void CAniRect::GetSpacingRect (RECT *retrcRect)
// GetSpacingRect
//
// Returns the size
{
CVector vScale = m_Properties[INDEX_SCALE].GetVector();
retrcRect->left = 0;
retrcRect->top = 0;
retrcRect->right = (int)vScale.GetX();
retrcRect->bottom = (int)vScale.GetY();
}
void CAniRect::Paint (SAniPaintCtx &Ctx)
// Paint
//
// Paints the element
{
// Position and size
CVector vPos = Ctx.ToDest.Transform(m_Properties[INDEX_POSITION].GetVector());
CVector vPos2 = Ctx.ToDest.Transform(m_Properties[INDEX_POSITION].GetVector() + m_Properties[INDEX_SCALE].GetVector());
CVector vSize = vPos2 - vPos;
// Get the size in integer values
int x = (int)vPos.GetX();
int y = (int)vPos.GetY();
int cxWidth = (int)vSize.GetX();
int cyHeight = (int)vSize.GetY();
// Fill method
IAniFillMethod *pFill = GetFillMethod();
if (pFill)
{
int iLinePadding = m_Properties[INDEX_LINE_PADDING].GetInteger();
// Init
pFill->InitPaint(Ctx, x, y, m_Properties);
// Paint
pFill->Fill(Ctx, x + iLinePadding, y + iLinePadding, cxWidth - (2 * iLinePadding), cyHeight - (2 * iLinePadding));
}
// Line method
IAniLineMethod *pLine = GetLineMethod();
if (pLine)
{
pLine->InitPaint(Ctx, x, y, m_Properties);
// Draw the edges
pLine->Line(Ctx, x, y, x + cxWidth, y);
pLine->Line(Ctx, x + cxWidth - 1, y, x + cxWidth - 1, y + cyHeight);
pLine->Line(Ctx, x, y + cyHeight - 1, x + cxWidth, y + cyHeight - 1);
pLine->Line(Ctx, x, y, x, y + cyHeight);
// Draw the corners
pLine->Corner(Ctx, x, y);
pLine->Corner(Ctx, x + cxWidth - 1, y);
pLine->Corner(Ctx, x, y + cyHeight - 1);
pLine->Corner(Ctx, x + cxWidth - 1, y + cyHeight - 1);
}
}