-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathIPropertyAnimator.cpp
87 lines (64 loc) · 1.97 KB
/
IPropertyAnimator.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
// PropertyAnimators.cpp
//
// Property animator classes
// Copyright (c) 2014 by Kronosaur Productions, LLC.
#include <windows.h>
#include "Alchemy.h"
#include "DirectXUtil.h"
#include <math.h>
#include <stdio.h>
#include "Reanimator.h"
#define EVENT_ON_ANIMATION_DONE CONSTLIT("onAnimationDone")
void IPropertyAnimator::AddListener (const CString &sEvent, IAniCommand *pListener, const CString &sCmd, DWORD dwData)
// AddListener
//
// Adds a listener to this animator
{
SAniEvent *pEntry = m_Listeners.Insert();
pEntry->sEvent = sEvent;
pEntry->pListener = pListener;
pEntry->sCmd = sCmd;
pEntry->dwData = dwData;
}
void IPropertyAnimator::OnDoneAnimating (SAniUpdateCtx &Ctx)
// OnDoneAnimating
//
// Animation complete
{
int i;
// Loop over all listeners and add events to the context (they will fire
// when paint/update is done).
for (i = 0; i < m_Listeners.GetCount(); i++)
if (m_Listeners[i].sEvent.IsBlank() || strEquals(m_Listeners[i].sEvent, EVENT_ON_ANIMATION_DONE))
Ctx.EventsToFire.Insert(m_Listeners[i]);
}
void IPropertyAnimator::RaiseEvent (const CString &sID, 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).
TArray<SAniEvent> 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 IPropertyAnimator::RemoveListener (IAniCommand *pListener, const CString &sEvent)
// RemoveListener
//
// Removes a 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--;
}
}