forked from FWGS/mainui_cpp
-
Notifications
You must be signed in to change notification settings - Fork 2
/
EventSystem.cpp
115 lines (99 loc) · 2.6 KB
/
EventSystem.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
/*
EventSystem.h -- event system implementation
Copyright(C) 2017 a1batross
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
*/
#include "BaseMenu.h"
#include "BaseItem.h"
#include "EventSystem.h"
CEventCallback::CEventCallback() :
pExtra( 0 ), type( CB_OLD_EXTRA ), szName( 0 )
{
memset(&u, 0, sizeof(u));
}
CEventCallback::CEventCallback( EventCallback cb, void *ex ) :
pExtra( ex ), type( CB_OLD_EXTRA ), szName( 0 )
{
memset(&u, 0, sizeof(u));
u.cb = cb;
}
CEventCallback::CEventCallback(int execute_now, const char *sz)
{
memset(&u, 0, sizeof(u));
SetCommand( execute_now, sz );
}
CEventCallback::CEventCallback(VoidCallback cb) :
pExtra( 0 ), type( CB_OLD_VOID ), szName( 0 )
{
memset(&u, 0, sizeof(u));
u.voidCb = cb;
}
CEventCallback::CEventCallback( IHCallback cb, void *ex ) :
pExtra( ex ), type( CB_IH_EXTRA ), szName( 0 )
{
memset(&u, 0, sizeof(u));
u.itemsHolderCb = cb;
}
CEventCallback::CEventCallback( VoidIHCallback cb ) :
pExtra( 0 ), type( CB_IH_VOID ), szName( 0 )
{
memset(&u, 0, sizeof(u));
u.voidItemsHolderCb = cb;
}
void CEventCallback::operator()(CMenuBaseItem *pSelf)
{
switch( type )
{
case CB_OLD_EXTRA: u.cb( pSelf, pExtra ); break;
case CB_OLD_VOID: u.voidCb(); break;
case CB_IH_EXTRA: (pSelf->Parent()->*u.itemsHolderCb)( pExtra ); break;
case CB_IH_VOID: (pSelf->Parent()->*u.voidItemsHolderCb)(); break;
}
}
EventCallback CEventCallback::operator =( EventCallback cb )
{
type = CB_OLD_EXTRA;
return u.cb = cb;
}
VoidCallback CEventCallback::operator =( VoidCallback cb )
{
type = CB_OLD_VOID;
return u.voidCb = cb;
}
IHCallback CEventCallback::operator =( IHCallback cb )
{
type = CB_IH_EXTRA;
return u.itemsHolderCb = cb;
}
VoidIHCallback CEventCallback::operator =( VoidIHCallback cb )
{
type = CB_IH_VOID;
return u.voidItemsHolderCb = cb;
}
void CEventCallback::Reset()
{
type = CB_OLD_EXTRA;
u.cb = 0;
}
void CEventCallback::SetCommand( int execute_now, const char *sz )
{
execute_now ? operator =(CmdExecuteNowCb) : operator =(CmdExecuteNextFrameCb);
pExtra = (void*)sz;
}
size_t CEventCallback::operator =( size_t null )
{
Reset();
return 0;
}
void* CEventCallback::operator =( void *null )
{
Reset();
return NULL;
}