-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathCAniControl.cpp
132 lines (95 loc) · 2.49 KB
/
CAniControl.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
// CAniControl.cpp
//
// CAniControl class
// Copyright (c) 2011 by Kronosaur Productions, LLC. All Rights Reserved.
#include <windows.h>
#include "Alchemy.h"
#include "DirectXUtil.h"
#include <math.h>
#include <stdio.h>
#include "Reanimator.h"
CAniControl::~CAniControl (void)
// CAniControl destructor
{
int i;
for (i = 0; i < m_Styles.GetCount(); i++)
if (m_Styles[i].pAni)
delete m_Styles[i].pAni;
}
void CAniControl::AddListener (const CString &sEvent, IAniCommand *pListener, const CString &sCmd, DWORD dwData)
// AddListener
//
// Adds a listener
{
SListener *pEntry = m_Listeners.Insert();
pEntry->sEvent = sEvent;
pEntry->pListener = pListener;
pEntry->sCmd = sCmd;
pEntry->dwData = dwData;
}
IAnimatron *CAniControl::GetStyle (const CString &sComponent) const
// GetStyle
//
// Returns a style by name
{
// Ask our derived class to map a name to an index
int iIndex = MapStyleName(sComponent);
if (iIndex == -1)
return NULL;
return GetStyle(iIndex);
}
void CAniControl::RaiseEvent (const CString &sEvent)
// RaiseEvent
//
// Fires the event to all appropriate listeners
{
int i;
// Make a copy of events to raise (we need to do this because after firing
// any one event we might destroy everything).
CString sID = GetID();
TArray<SListener> Raised;
for (i = 0; i < m_Listeners.GetCount(); i++)
if (m_Listeners[i].sEvent.IsBlank() || strEquals(sEvent, m_Listeners[i].sEvent))
Raised.Insert(m_Listeners[i]);
// Fire
for (i = 0; i < Raised.GetCount(); i++)
Raised[i].pListener->AniCommand(sID, sEvent, Raised[i].sCmd, Raised[i].dwData);
}
void CAniControl::RemoveListener (IAniCommand *pListener, const CString &sEvent)
// RemoveListener
//
// Removes the given listener
{
int i;
for (i = 0; i < m_Listeners.GetCount(); i++)
if (m_Listeners[i].pListener == pListener
&& (sEvent.IsBlank() || strEquals(m_Listeners[i].sEvent, sEvent)))
{
m_Listeners.Delete(i);
i--;
}
}
void CAniControl::SetStyle (int iIndex, IAnimatron *pImpl)
// SetStyle
//
// Sets a style by index
{
int iCount = m_Styles.GetCount();
if (iIndex >= iCount)
m_Styles.InsertEmpty(iIndex - iCount + 1);
// Free
if (m_Styles[iIndex].pAni)
delete m_Styles[iIndex].pAni;
m_Styles[iIndex].pAni = pImpl;
}
void CAniControl::SetStyle (const CString &sComponent, IAnimatron *pImpl)
// SetStyle
//
// Sets a style by name
{
// Ask our derived class to map a name to an index
int iIndex = MapStyleName(sComponent);
if (iIndex == -1)
return;
SetStyle(iIndex, pImpl);
}