GUI/scripting updates
This was SVN commit r708.
This commit is contained in:
parent
5645a13d1a
commit
2537d1bc6e
@ -1053,7 +1053,7 @@ void CGUI::Xeromyces_ReadObject(XMBElement Element, CXeromyces* pFile, IGUIObjec
|
||||
XMBAttribute attr = attributes.item(i);
|
||||
|
||||
// If value is "null", then it is equivalent as never being entered
|
||||
if ((CStr8)attr.Value == (CStr8)"null")
|
||||
if ((CStr)attr.Value == (CStr)"null")
|
||||
continue;
|
||||
|
||||
// Ignore "type" and "style", we've already checked it
|
||||
@ -1136,7 +1136,7 @@ void CGUI::Xeromyces_ReadObject(XMBElement Element, CXeromyces* pFile, IGUIObjec
|
||||
// Scripted <action> element
|
||||
|
||||
// Check for a 'file' parameter
|
||||
CStr file (Element.getAttributes().getNamedItem(attr_file));
|
||||
CStr file (child.getAttributes().getNamedItem(attr_file));
|
||||
|
||||
CStr code;
|
||||
|
||||
@ -1162,7 +1162,7 @@ void CGUI::Xeromyces_ReadObject(XMBElement Element, CXeromyces* pFile, IGUIObjec
|
||||
}
|
||||
|
||||
// Read the inline code (concatenating to the file code, if both are specified)
|
||||
code += (CStr)Element.getText();
|
||||
code += (CStr)child.getText();
|
||||
|
||||
CStr action = (CStr)child.getAttributes().getNamedItem(attr_on);
|
||||
object->RegisterScriptHandler(action.LowerCase(), code, this);
|
||||
@ -1222,7 +1222,7 @@ void CGUI::Xeromyces_ReadScript(XMBElement Element, CXeromyces* pFile)
|
||||
// Check for a 'file' parameter
|
||||
CStr file (Element.getAttributes().getNamedItem( pFile->getAttributeID("file") ));
|
||||
|
||||
// If there is a file, open and execute it
|
||||
// If there is a file specified, open and execute it
|
||||
if (file.Length())
|
||||
{
|
||||
Handle h = vfs_open(file);
|
||||
@ -1237,7 +1237,7 @@ void CGUI::Xeromyces_ReadScript(XMBElement Element, CXeromyces* pFile)
|
||||
assert(err == 0);
|
||||
|
||||
jsval result;
|
||||
JS_EvaluateScript(g_ScriptingHost.getContext(), (JSObject*)m_ScriptObject, (const char*)data, (int)len, file, 0, &result);
|
||||
JS_EvaluateScript(g_ScriptingHost.getContext(), (JSObject*)m_ScriptObject, (const char*)data, (int)len, file, 1, &result);
|
||||
|
||||
vfs_unmap(h);
|
||||
vfs_close(h);
|
||||
@ -1248,7 +1248,7 @@ void CGUI::Xeromyces_ReadScript(XMBElement Element, CXeromyces* pFile)
|
||||
CStr code (Element.getText());
|
||||
|
||||
jsval result;
|
||||
JS_EvaluateScript(g_ScriptingHost.getContext(), (JSObject*)m_ScriptObject, code.c_str(), (int)code.Length(), "", 0, &result);
|
||||
JS_EvaluateScript(g_ScriptingHost.getContext(), (JSObject*)m_ScriptObject, code.c_str(), (int)code.Length(), "", 1, &result);
|
||||
}
|
||||
|
||||
void CGUI::Xeromyces_ReadSprite(XMBElement Element, CXeromyces* pFile)
|
||||
|
@ -416,7 +416,10 @@ void IGUIObject::RegisterScriptHandler(const CStr& Action, const CStr& Code, CGU
|
||||
const int paramCount = 1;
|
||||
const char* paramNames[paramCount] = { "mouse" };
|
||||
|
||||
JSFunction* func = JS_CompileFunction(g_ScriptingHost.getContext(), (JSObject*)pGUI->m_ScriptObject, "", paramCount, paramNames, (const char*)Code, Code.Length(), "GUI script", 0);
|
||||
// Location to report errors from
|
||||
CStr CodeName = GetName()+" "+Action;
|
||||
|
||||
JSFunction* func = JS_CompileFunction(g_ScriptingHost.getContext(), (JSObject*)pGUI->m_ScriptObject, NULL, paramCount, paramNames, (const char*)Code, Code.Length(), CodeName, 0);
|
||||
m_ScriptHandlers[Action] = func;
|
||||
}
|
||||
|
||||
|
@ -1,8 +1,9 @@
|
||||
// $Id: JSInterface_GUITypes.cpp,v 1.2 2004/07/11 16:21:52 philip Exp $
|
||||
// $Id: JSInterface_GUITypes.cpp,v 1.3 2004/07/11 18:18:27 philip Exp $
|
||||
|
||||
#include "precompiled.h"
|
||||
|
||||
#include "JSInterface_GUITypes.h"
|
||||
#include "CStr.h"
|
||||
|
||||
/**** GUISize ****/
|
||||
|
||||
@ -17,10 +18,14 @@ JSClass JSI_GUISize::JSI_class = {
|
||||
|
||||
JSPropertySpec JSI_GUISize::JSI_props[] =
|
||||
{
|
||||
{ "left", 0, JSPROP_ENUMERATE},
|
||||
{ "top", 1, JSPROP_ENUMERATE},
|
||||
{ "right", 2, JSPROP_ENUMERATE},
|
||||
{ "bottom", 3, JSPROP_ENUMERATE},
|
||||
{ "left", 0, JSPROP_ENUMERATE},
|
||||
{ "top", 1, JSPROP_ENUMERATE},
|
||||
{ "right", 2, JSPROP_ENUMERATE},
|
||||
{ "bottom", 3, JSPROP_ENUMERATE},
|
||||
{ "rleft", 4, JSPROP_ENUMERATE},
|
||||
{ "rtop", 5, JSPROP_ENUMERATE},
|
||||
{ "rright", 6, JSPROP_ENUMERATE},
|
||||
{ "rbottom", 7, JSPROP_ENUMERATE},
|
||||
{ 0 }
|
||||
};
|
||||
|
||||
@ -32,12 +37,28 @@ JSFunctionSpec JSI_GUISize::JSI_methods[] =
|
||||
|
||||
JSBool JSI_GUISize::construct(JSContext* cx, JSObject* obj, unsigned int argc, jsval* argv, jsval* rval)
|
||||
{
|
||||
if (argc == 4)
|
||||
if (argc == 8)
|
||||
{
|
||||
JS_SetProperty(cx, obj, "left", &argv[0]);
|
||||
JS_SetProperty(cx, obj, "top", &argv[1]);
|
||||
JS_SetProperty(cx, obj, "right", &argv[2]);
|
||||
JS_SetProperty(cx, obj, "bottom", &argv[3]);
|
||||
JS_SetProperty(cx, obj, "left", &argv[0]);
|
||||
JS_SetProperty(cx, obj, "top", &argv[1]);
|
||||
JS_SetProperty(cx, obj, "right", &argv[2]);
|
||||
JS_SetProperty(cx, obj, "bottom", &argv[3]);
|
||||
JS_SetProperty(cx, obj, "rleft", &argv[4]);
|
||||
JS_SetProperty(cx, obj, "rtop", &argv[5]);
|
||||
JS_SetProperty(cx, obj, "rright", &argv[6]);
|
||||
JS_SetProperty(cx, obj, "rbottom", &argv[7]);
|
||||
}
|
||||
else if (argc == 4)
|
||||
{
|
||||
jsval zero = JSVAL_ZERO;
|
||||
JS_SetProperty(cx, obj, "left", &argv[0]);
|
||||
JS_SetProperty(cx, obj, "top", &argv[1]);
|
||||
JS_SetProperty(cx, obj, "right", &argv[2]);
|
||||
JS_SetProperty(cx, obj, "bottom", &argv[3]);
|
||||
JS_SetProperty(cx, obj, "rleft", &zero);
|
||||
JS_SetProperty(cx, obj, "rtop", &zero);
|
||||
JS_SetProperty(cx, obj, "rright", &zero);
|
||||
JS_SetProperty(cx, obj, "rbottom", &zero);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -46,19 +67,36 @@ JSBool JSI_GUISize::construct(JSContext* cx, JSObject* obj, unsigned int argc, j
|
||||
JS_SetProperty(cx, obj, "top", &zero);
|
||||
JS_SetProperty(cx, obj, "right", &zero);
|
||||
JS_SetProperty(cx, obj, "bottom", &zero);
|
||||
JS_SetProperty(cx, obj, "rleft", &zero);
|
||||
JS_SetProperty(cx, obj, "rtop", &zero);
|
||||
JS_SetProperty(cx, obj, "rright", &zero);
|
||||
JS_SetProperty(cx, obj, "rbottom", &zero);
|
||||
}
|
||||
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
// Produces "10", "-10", "50%", "50%-10", "50%+10", etc
|
||||
CStr ToPercentString(int pix, int per)
|
||||
{
|
||||
if (per == 0)
|
||||
return CStr(pix);
|
||||
else
|
||||
return CStr(per)+CStr("%")+( pix == 0 ? CStr() : pix > 0 ? CStr("+")+CStr(pix) : CStr(pix) );
|
||||
}
|
||||
|
||||
JSBool JSI_GUISize::toString(JSContext* cx, JSObject* obj, uintN argc, jsval* argv, jsval* rval)
|
||||
{
|
||||
char buffer[256];
|
||||
snprintf(buffer, 256, "%i %i %i %i",
|
||||
JSVAL_TO_INT(g_ScriptingHost.GetObjectProperty(obj, "left" )),
|
||||
JSVAL_TO_INT(g_ScriptingHost.GetObjectProperty(obj, "top" )),
|
||||
JSVAL_TO_INT(g_ScriptingHost.GetObjectProperty(obj, "right" )),
|
||||
JSVAL_TO_INT(g_ScriptingHost.GetObjectProperty(obj, "bottom")) );
|
||||
snprintf(buffer, 256, "%s %s %s %s",
|
||||
ToPercentString(JSVAL_TO_INT(g_ScriptingHost.GetObjectProperty(obj, "left" )),
|
||||
JSVAL_TO_INT(g_ScriptingHost.GetObjectProperty(obj, "rleft" ))).c_str(),
|
||||
ToPercentString(JSVAL_TO_INT(g_ScriptingHost.GetObjectProperty(obj, "top" )),
|
||||
JSVAL_TO_INT(g_ScriptingHost.GetObjectProperty(obj, "rtop" ))).c_str(),
|
||||
ToPercentString(JSVAL_TO_INT(g_ScriptingHost.GetObjectProperty(obj, "right" )),
|
||||
JSVAL_TO_INT(g_ScriptingHost.GetObjectProperty(obj, "rright" ))).c_str(),
|
||||
ToPercentString(JSVAL_TO_INT(g_ScriptingHost.GetObjectProperty(obj, "bottom" )),
|
||||
JSVAL_TO_INT(g_ScriptingHost.GetObjectProperty(obj, "rbottom" ))).c_str() );
|
||||
|
||||
*rval = STRING_TO_JSVAL(JS_NewStringCopyZ(cx, buffer));
|
||||
return JS_TRUE;
|
||||
@ -188,7 +226,7 @@ JSBool JSI_GUIMouse::toString(JSContext* cx, JSObject* obj, uintN argc, jsval* a
|
||||
// Initialise all the types at once:
|
||||
void JSI_GUITypes::init()
|
||||
{
|
||||
g_ScriptingHost.DefineCustomObjectType(&JSI_GUISize::JSI_class, JSI_GUISize::construct, 1, JSI_GUISize::JSI_props, JSI_GUISize::JSI_methods, NULL, NULL);
|
||||
g_ScriptingHost.DefineCustomObjectType(&JSI_GUISize::JSI_class, JSI_GUISize::construct, 1, JSI_GUISize::JSI_props, JSI_GUISize::JSI_methods, NULL, NULL);
|
||||
g_ScriptingHost.DefineCustomObjectType(&JSI_GUIColor::JSI_class, JSI_GUIColor::construct, 1, JSI_GUIColor::JSI_props, JSI_GUIColor::JSI_methods, NULL, NULL);
|
||||
g_ScriptingHost.DefineCustomObjectType(&JSI_GUIMouse::JSI_class, JSI_GUIMouse::construct, 1, JSI_GUIMouse::JSI_props, JSI_GUIMouse::JSI_methods, NULL, NULL);
|
||||
g_ScriptingHost.DefineCustomObjectType(&JSI_GUIMouse::JSI_class, JSI_GUIMouse::construct, 1, JSI_GUIMouse::JSI_props, JSI_GUIMouse::JSI_methods, NULL, NULL);
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
// $Id: JSInterface_IGUIObject.cpp,v 1.3 2004/07/11 16:21:52 philip Exp $
|
||||
// $Id: JSInterface_IGUIObject.cpp,v 1.4 2004/07/11 18:18:27 philip Exp $
|
||||
|
||||
#include "precompiled.h"
|
||||
|
||||
@ -126,16 +126,17 @@ JSBool JSI_IGUIObject::getProperty(JSContext* cx, JSObject* obj, jsval id, jsval
|
||||
{
|
||||
CClientArea area;
|
||||
GUI<CClientArea>::GetSetting(e, propName, area);
|
||||
CRect size = area.pixel;
|
||||
JSObject* obj = JS_NewObject(cx, &JSI_GUISize::JSI_class, NULL, NULL);
|
||||
jsval left = INT_TO_JSVAL(size.left);
|
||||
jsval top = INT_TO_JSVAL(size.top);
|
||||
jsval right = INT_TO_JSVAL(size.right);
|
||||
jsval bottom = INT_TO_JSVAL(size.bottom);
|
||||
JS_SetProperty(cx, obj, "left", &left);
|
||||
JS_SetProperty(cx, obj, "top", &top);
|
||||
JS_SetProperty(cx, obj, "right", &right);
|
||||
JS_SetProperty(cx, obj, "bottom", &bottom);
|
||||
#define P(x, y, z) jsval z = INT_TO_JSVAL(area.x.y); JS_SetProperty(cx, obj, #z, &z)
|
||||
P(pixel, left, left);
|
||||
P(pixel, top, top);
|
||||
P(pixel, right, right);
|
||||
P(pixel, bottom, bottom);
|
||||
P(percent, left, rleft);
|
||||
P(percent, top, rtop);
|
||||
P(percent, right, rright);
|
||||
P(percent, bottom, rbottom);
|
||||
#undef P
|
||||
*vp = OBJECT_TO_JSVAL(obj);
|
||||
break;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user