-
Notifications
You must be signed in to change notification settings - Fork 0
/
Parameters.cpp
159 lines (144 loc) · 4.95 KB
/
Parameters.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
#include <Windows.h>
#include "CKAll.h"
#define CKOGUID_GETMOUSEPOSITION CKGUID(0x6ea0201, 0x680e3a62)
#define CKOGUID_GETMOUSEX CKGUID(0x53c51abe, 0xeba68de)
#define CKOGUID_GETMOUSEY CKGUID(0x27af3c9f, 0xdbc4eb3)
int CKKeyStringFunc(CKParameter *param, CKSTRING ValueString, CKBOOL ReadFromString)
{
if (!param) return 0;
CKInputManager *im = (CKInputManager *)param->m_Context->GetManagerByGuid(INPUT_MANAGER_GUID);
if (ReadFromString)
{
if (!ValueString) return 0;
CKSTRING name = NULL;
if (ValueString[0] != '\0')
name = (CKSTRING)im->GetKeyFromName(ValueString);
param->SetValue(&name);
}
else
{
CKDWORD key = NULL;
param->GetValue(&key, FALSE);
int len = im->GetKeyName(key, ValueString);
if (len > 1) return len;
}
return 0;
}
void CK2dVectorGetMousePos(CKContext *context, CKParameterOut *res, CKParameterIn *p1, CKParameterIn *p2)
{
CKInputManager *im = (CKInputManager *)context->GetManagerByGuid(INPUT_MANAGER_GUID);
if (im)
{
Vx2DVector pos;
im->GetMousePosition(pos, TRUE);
CKParameter *param = p1->GetRealSource();
if (!param)
{
*(Vx2DVector *)res->GetWriteDataPtr() = pos;
return;
}
CKBOOL absolute = FALSE;
param->GetValue(&absolute);
if (absolute)
{
CKRenderContext *rc = context->GetPlayerRenderContext();
if (rc)
{
HWND hWnd = (HWND)rc->GetWindowHandle();
POINT pt;
pt.x = (LONG)pos.x;
pt.y = (LONG)pos.y;
::ScreenToClient(hWnd, &pt);
if (pt.x >= 0)
{
int width = rc->GetWidth();
if (pt.x >= width)
pt.x = width - 1;
}
else
{
pt.x = 0;
}
if (pt.y >= 0)
{
int height = rc->GetHeight();
if (pt.y >= height)
pt.y = height - 1;
}
else
{
pt.y = 0;
}
pos.x = (float)pt.x;
pos.y = (float)pt.y;
}
}
*(Vx2DVector *)res->GetWriteDataPtr() = pos;
}
}
void CKIntGetMouseX(CKContext *context, CKParameterOut *res, CKParameterIn *p1, CKParameterIn *p2)
{
CKInputManager *im = (CKInputManager *)context->GetManagerByGuid(INPUT_MANAGER_GUID);
if (im)
{
Vx2DVector pos;
im->GetMousePosition(pos, TRUE);
*(int *)res->GetWriteDataPtr() = (int)pos.x;
}
}
void CKIntGetMouseY(CKContext *context, CKParameterOut *res, CKParameterIn *p1, CKParameterIn *p2)
{
CKInputManager *im = (CKInputManager *)context->GetManagerByGuid(INPUT_MANAGER_GUID);
if (im)
{
Vx2DVector pos;
im->GetMousePosition(pos, TRUE);
*(int *)res->GetWriteDataPtr() = (int)pos.y;
}
}
void CKInitializeParameterTypes(CKContext *context)
{
CKParameterTypeDesc desc;
desc.TypeName = "Keyboard Key";
desc.Guid = CKPGUID_KEY;
desc.DerivedFrom = CKPGUID_INT;
desc.Valid = TRUE;
desc.DefaultSize = 4;
desc.CreateDefaultFunction = NULL;
desc.DeleteFunction = NULL;
desc.SaveLoadFunction = NULL;
desc.StringFunction = CKKeyStringFunc;
desc.UICreatorFunction = NULL;
desc.dwParam = 0;
desc.dwFlags = 0;
desc.Cid = 0;
CKParameterManager *pm = context->GetParameterManager();
pm->RegisterParameterType(&desc);
}
void CKInitializeOperationTypes(CKContext *context)
{
CKParameterManager *pm = context->GetParameterManager();
pm->RegisterOperationType(CKOGUID_GETMOUSEPOSITION, "Get Mouse Position");
pm->RegisterOperationType(CKOGUID_GETMOUSEX, "Get Mouse X");
pm->RegisterOperationType(CKOGUID_GETMOUSEY, "Get Mouse Y");
}
void CKInitializeOperationFunctions(CKContext *context)
{
CKParameterManager *pm = context->GetParameterManager();
pm->RegisterOperationFunction(CKOGUID_GETMOUSEX, CKPGUID_INT, CKPGUID_NONE, CKPGUID_NONE, CKIntGetMouseX);
pm->RegisterOperationFunction(CKOGUID_GETMOUSEY, CKPGUID_INT, CKPGUID_NONE, CKPGUID_NONE, CKIntGetMouseY);
pm->RegisterOperationFunction(CKOGUID_GETMOUSEPOSITION, CKPGUID_2DVECTOR, CKPGUID_NONE, CKPGUID_NONE, CK2dVectorGetMousePos);
pm->RegisterOperationFunction(CKOGUID_GETMOUSEPOSITION, CKPGUID_2DVECTOR, CKPGUID_BOOL, CKPGUID_NONE, CK2dVectorGetMousePos);
}
void CKUnInitializeParameterTypes(CKContext *context)
{
CKParameterManager *pm = context->GetParameterManager();
pm->UnRegisterParameterType(CKPGUID_KEY);
}
void CKUnInitializeOperationTypes(CKContext *context)
{
CKParameterManager *pm = context->GetParameterManager();
pm->UnRegisterOperationType(CKOGUID_GETMOUSEPOSITION);
pm->UnRegisterOperationType(CKOGUID_GETMOUSEX);
pm->UnRegisterOperationType(CKOGUID_GETMOUSEY);
}