aboutsummaryrefslogtreecommitdiff
path: root/Src/Wasabi/api/script/objects/spopup.cpp
blob: 84cc62544f65681758274b94a34768f2571d6095 (plain) (blame)
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
#include <precomp.h>
#include <api/script/objects/spopup.h>
#include <api/script/scriptmgr.h>

SPopup::SPopup() {
	getScriptObject()->vcpu_setInterface(popupGuid, (void *)static_cast<SPopup*>(this));
	getScriptObject()->vcpu_setClassName(L"Popup");
	getScriptObject()->vcpu_setController(popupController);
}

SPopup::~SPopup() {
}

PopupScriptController _popupController;
PopupScriptController *popupController = &_popupController;

// -- Functions table -------------------------------------
function_descriptor_struct PopupScriptController::exportedFunction[] = {
  {L"addSubMenu",      2, (void*)SPopup::script_vcpu_addSubMenu },
  {L"addCommand",      4, (void*)SPopup::script_vcpu_addCommand },
  {L"addSeparator",    0, (void*)SPopup::script_vcpu_addSeparator },
  {L"popAtXY",         2, (void*)SPopup::script_vcpu_popAtXY },
  {L"popAtMouse",      0, (void*)SPopup::script_vcpu_popAtMouse },
  {L"getNumCommands",  0, (void*)SPopup::script_vcpu_getNumCommands },
  {L"checkCommand",    2, (void*)SPopup::script_vcpu_checkCommand },
  {L"disableCommand",  2, (void*)SPopup::script_vcpu_disableCommand },

//todo: events
};

// --------------------------------------------------------
const wchar_t *PopupScriptController::getClassName() {
	return L"Popup";
}

const wchar_t *PopupScriptController::getAncestorClassName() {
	return L"Object";
}

ScriptObject *PopupScriptController::instantiate() {
	SPopup *p = new SPopup;
	ASSERT(p != NULL);
	return p->getScriptObject();
}

void PopupScriptController::destroy(ScriptObject *o) { 
	SPopup *p = static_cast<SPopup *>(o->vcpu_getInterface(popupGuid));
	ASSERT(p != NULL);
	delete p;
}

void *PopupScriptController::encapsulate(ScriptObject *o) {
	return NULL; // no encapsulation for popups yet
}

void PopupScriptController::deencapsulate(void *o) {
}

int PopupScriptController::getNumFunctions() {
	return sizeof(exportedFunction) / sizeof(function_descriptor_struct); 
}

const function_descriptor_struct *PopupScriptController::getExportedFunctions() {
	return exportedFunction;                                                        
}

GUID PopupScriptController::getClassGuid() {
	return popupGuid;
}

// -----------------------------------------------------------------------
scriptVar SPopup::script_vcpu_addSubMenu(SCRIPT_FUNCTION_PARAMS, ScriptObject *o, scriptVar popup, scriptVar str) 
{
	SCRIPT_FUNCTION_INIT; 
	ASSERT(str.type == SCRIPT_STRING); // compiler discarded
	SPopup *p = static_cast<SPopup *>(o->vcpu_getInterface(popupGuid));
	SPopup *p2 = static_cast<SPopup *>(GET_SCRIPT_OBJECT_AS(popup, popupGuid));
	if (p) p->addSubMenu(p2, GET_SCRIPT_STRING(str));
	RETURN_SCRIPT_VOID;
}

scriptVar SPopup::script_vcpu_addCommand(SCRIPT_FUNCTION_PARAMS, ScriptObject *o, scriptVar str, scriptVar cmd, scriptVar checked, scriptVar disabled) {
	SCRIPT_FUNCTION_INIT; 
	ASSERT(str.type == SCRIPT_STRING); // compiler discarded
	ASSERT(SOM::isNumeric(&cmd)); // compiler discarded
	ASSERT(SOM::isNumeric(&checked)); // compiler discarded
	ASSERT(SOM::isNumeric(&disabled)); // compiler discarded
	SPopup *p = static_cast<SPopup *>(o->vcpu_getInterface(popupGuid));
	if (p)
		p->addCommand(str.data.sdata, SOM::makeInt(&cmd), SOM::makeBoolean(&checked), SOM::makeBoolean(&disabled));
	RETURN_SCRIPT_VOID;
}

scriptVar SPopup::script_vcpu_addSeparator(SCRIPT_FUNCTION_PARAMS, ScriptObject *o) {
	SCRIPT_FUNCTION_INIT; 
	SPopup *p = static_cast<SPopup *>(o->vcpu_getInterface(popupGuid));
	if (p) p->addSeparator();
	RETURN_SCRIPT_VOID;
}

scriptVar SPopup::script_vcpu_checkCommand(SCRIPT_FUNCTION_PARAMS, ScriptObject *o, scriptVar i, scriptVar check) {
	SCRIPT_FUNCTION_INIT; 
	ASSERT(SOM::isNumeric(&i));
	ASSERT(SOM::isNumeric(&check));
	SPopup *p = static_cast<SPopup *>(o->vcpu_getInterface(popupGuid));
	if (p) p->checkCommand(SOM::makeInt(&i), SOM::makeBoolean(&check));
	RETURN_SCRIPT_VOID;
}

scriptVar SPopup::script_vcpu_disableCommand(SCRIPT_FUNCTION_PARAMS, ScriptObject *o, scriptVar i, scriptVar disable) {
	SCRIPT_FUNCTION_INIT; 
	ASSERT(SOM::isNumeric(&i));
	ASSERT(SOM::isNumeric(&disable));
	SPopup *p = static_cast<SPopup *>(o->vcpu_getInterface(popupGuid));
	if (p) p->disableCommand(SOM::makeInt(&i), SOM::makeBoolean(&disable));
	RETURN_SCRIPT_VOID;
}

scriptVar SPopup::script_vcpu_popAtXY(SCRIPT_FUNCTION_PARAMS, ScriptObject *o, scriptVar x, scriptVar y) {
	SCRIPT_FUNCTION_INIT; 
	ASSERT(SOM::isNumeric(&x));
	ASSERT(SOM::isNumeric(&y));
	SPopup *p = static_cast<SPopup *>(o->vcpu_getInterface(popupGuid));
	if (p) return MAKE_SCRIPT_INT(p->popAtXY(SOM::makeInt(&x), SOM::makeInt(&y)));
	RETURN_SCRIPT_ZERO;
}

scriptVar SPopup::script_vcpu_popAtMouse(SCRIPT_FUNCTION_PARAMS, ScriptObject *o) {
	SCRIPT_FUNCTION_INIT; 
	SPopup *p = static_cast<SPopup *>(o->vcpu_getInterface(popupGuid));
	if (p) return MAKE_SCRIPT_INT(p->popAtMouse());
	RETURN_SCRIPT_ZERO;
}

scriptVar SPopup::script_vcpu_getNumCommands(SCRIPT_FUNCTION_PARAMS, ScriptObject *o) {
	SCRIPT_FUNCTION_INIT; 
	SPopup *p = static_cast<SPopup *>(o->vcpu_getInterface(popupGuid));
	if (p) return MAKE_SCRIPT_INT(p->getNumCommands());
	RETURN_SCRIPT_ZERO;
}