use of net.schattenkind.androidLove.luan.obj.LuanObjImage in project love-android by hagish.
the class LuanPhone method InitLib.
// ***** ***** ***** ***** ***** init
public LuaTable InitLib() {
LuaTable t = LuaValue.tableOf();
LuaValue _G = vm.get_G();
_G.set(sMetaName_LuanSensor, LuanObjSensor.CreateMetaTable(this));
// TODO: add phone/android/iphone specific api additions here, e.g. multi-touch event stuff, accelerometer, gravity sensor, maybe intent/running apps/network/start browser etc ?
/// img = love.phone.newResourceImage(int iResID)
/// loads an image from a resource id
t.set("newResourceImage", new VarArgFunction() {
@Override
public Varargs invoke(Varargs args) {
int iResID = args.checkint(1);
try {
return LuaValue.userdataOf(new LuanObjImage(vm.getLuanGraphics(), iResID), vm.get_G().get(LuanGraphics.sMetaName_LuanImage));
} catch (Exception e) {
vm.handleError(e);
}
return LuaValue.NONE;
}
});
/// source = love.phone.newResourceAudioSource(int iResID,string type)
/// loads a sound/music/audio source from a resource id
t.set("newResourceAudioSource", new VarArgFunction() {
@Override
public Varargs invoke(Varargs args) {
int iResID = args.checkint(1);
try {
String sType = IsArgSet(args, 2) ? args.checkjstring(2) : "static";
return LuaValue.userdataOf(new LuanAudio.LuanObjSource(vm.getLuanAudio(), iResID, sType), vm.get_G().get(LuanAudio.sMetaName_LuanSource));
} catch (Exception e) {
vm.handleError(e);
}
return LuaValue.NONE;
}
});
// TODO: newResourceFontTTF !!!
/// source = love.phone.newResourceFontTTF(int iResID,int iSize)
/// loads a ttf from ressource id
/// String love.phone.getPackageName()
/// Return the name of this application's package.
t.set("getPackageName", new VarArgFunction() {
@Override
public Varargs invoke(Varargs args) {
return LuaValue.valueOf(vm.getActivity().getPackageName());
}
});
/// String love.phone.getResourceName(int iResID)
/// Return the full name for a given resource identifier.
t.set("getResourceName", new VarArgFunction() {
@Override
public Varargs invoke(Varargs args) {
try {
return LuaValue.valueOf(vm.getResources().getResourceName(args.checkint(1)));
} catch (Exception e) {
vm.handleError(e);
}
return LuaValue.NONE;
}
});
/// iResID = love.phone.getResourceID(String name, String defType, String defPackage)
/// @name The name of the desired resource.
/// @defType Optional default resource type to find, if "type/" is not included in the name. Can be null to require an explicit type.
/// @defPackage Optional default package to find, if "package:" is not included in the name. Can be null to require an explicit package.
t.set("getResourceID", new VarArgFunction() {
@Override
public Varargs invoke(Varargs args) {
return LuaValue.valueOf(vm.getResources().getIdentifier(args.checkjstring(1), IsArgSet(args, 2) ? args.checkjstring(2) : null, IsArgSet(args, 3) ? args.checkjstring(3) : null));
}
});
// int getIdentifier(String name, String defType, String defPackage)
/// {sensor,..} = love.phone.getSensorList(iSensorType)
/// see also love.phone.SENSOR_TYPE
t.set("getSensorList", new VarArgFunction() {
@Override
public Varargs invoke(Varargs args) {
List<Sensor> myList = vm.getSensorManager().getSensorList(args.checkint(1));
LuaTable t = new LuaTable(myList.size(), 0);
for (int i = 0; i < myList.size(); ++i) t.set(i + 1, LuaValue.userdataOf(new LuanObjSensor(LuanPhone.this, myList.get(i)), vm.get_G().get(sMetaName_LuanSensor)));
return t;
}
});
/// sensor = love.phone.getDefaultSensor(iSensorType)
/// see also love.phone.SENSOR_TYPE
t.set("getDefaultSensor", new VarArgFunction() {
@Override
public Varargs invoke(Varargs args) {
Sensor s = vm.getSensorManager().getDefaultSensor(args.checkint(1));
return LuaValue.userdataOf(new LuanObjSensor(LuanPhone.this, s), vm.get_G().get(sMetaName_LuanSensor));
}
});
/// love.phone.enableTouchEvents()
/// enable love.phone.touch(...) callback
t.set("enableTouchEvents", new VarArgFunction() {
@Override
public Varargs invoke(Varargs args) {
mbEnableTouchEvents = true;
return LuaValue.NONE;
}
});
/// boolean love.phone.registerSensorListener(sensor,rate)
/// Registers a SensorEventListener for the given sensor.
t.set("registerSensorListener", new VarArgFunction() {
@Override
public Varargs invoke(Varargs args) {
LuanObjSensor s = (LuanObjSensor) args.checkuserdata(1, LuanObjSensor.class);
int rate = args.checkint(2);
return LuaValue.valueOf(vm.getSensorManager().registerListener(s, s.getSensor(), rate));
}
});
/// love.phone.setBlockMainKey_Back(bBlocked)
t.set("setBlockMainKey_Back", new VarArgFunction() {
@Override
public Varargs invoke(Varargs args) {
((LoveAndroid) vm.getActivity()).setBlockMainKey_Back(args.checkboolean(1));
return LuaValue.NONE;
}
});
/// love.phone.setBlockMainKey_Menu(bBlocked)
t.set("setBlockMainKey_Menu", new VarArgFunction() {
@Override
public Varargs invoke(Varargs args) {
((LoveAndroid) vm.getActivity()).setBlockMainKey_Menu(args.checkboolean(1));
return LuaValue.NONE;
}
});
/// love.phone.setBlockMainKey_Search(bBlocked)
t.set("setBlockMainKey_Search", new VarArgFunction() {
@Override
public Varargs invoke(Varargs args) {
((LoveAndroid) vm.getActivity()).setBlockMainKey_Search(args.checkboolean(1));
return LuaValue.NONE;
}
});
/// love.phone.setHapticFeedbackEnabled(bEnabled)
t.set("setHapticFeedbackEnabled", new VarArgFunction() {
@Override
public Varargs invoke(Varargs args) {
vm.getView().setHapticFeedbackEnabled(args.checkboolean(1));
return LuaValue.NONE;
}
});
/// love.phone.performHapticFeedback(feedbackConstant)
/// see also FEEDBACK_CONSTANT
t.set("performHapticFeedback", new VarArgFunction() {
@Override
public Varargs invoke(Varargs args) {
vm.getView().performHapticFeedback(args.checkint(1));
return LuaValue.NONE;
}
});
/// love.phone.setKeepScreenOn(bool bKeepScreenOn)
t.set("setKeepScreenOn", new VarArgFunction() {
@Override
public Varargs invoke(Varargs args) {
vm.setKeepScreenOn(args.checkboolean(1));
return LuaValue.NONE;
}
});
/// love.phone.setRequestedOrientation(requestedOrientation)
/// string param : behind,full_sensor,landscape,nosensor,portrait,reverse_landscape,reverse_portrait,sensor,sensor_landscape,sensor_portrait,unspecified,user
/// for param meaning see also http://developer.android.com/reference/android/content/pm/ActivityInfo.html
/// numeric parameter are still supported but are discouraged, see SCREEN_ORIENTATION
t.set("setRequestedOrientation", new VarArgFunction() {
@Override
public Varargs invoke(Varargs args) {
vm.getActivity().setRequestedOrientation(args.isstring(1) ? Str2ScreenOrientation(args.checkjstring(1)) : args.checkint(1));
return LuaValue.NONE;
}
});
/// love.phone.SCREEN_ORIENTATION = {[name]=value,...}
/// see also http://developer.android.com/reference/android/content/pm/ActivityInfo.html
{
LuaTable c = new LuaTable();
t.set("SCREEN_ORIENTATION", c);
///< Constant corresponding to behind in the screenOrientation attribute.
c.set("SCREEN_ORIENTATION_BEHIND", android.content.pm.ActivityInfo.SCREEN_ORIENTATION_BEHIND);
//~ c.set("SCREEN_ORIENTATION_FULL_SENSOR", android.content.pm.ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR ); ///< Constant corresponding to fullSensor in the screenOrientation attribute.
///< Constant corresponding to landscape in the screenOrientation attribute.
c.set("SCREEN_ORIENTATION_LANDSCAPE", android.content.pm.ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
///< Constant corresponding to nosensor in the screenOrientation attribute.
c.set("SCREEN_ORIENTATION_NOSENSOR", android.content.pm.ActivityInfo.SCREEN_ORIENTATION_NOSENSOR);
///< Constant corresponding to portrait in the screenOrientation attribute.
c.set("SCREEN_ORIENTATION_PORTRAIT", android.content.pm.ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
//~ c.set("SCREEN_ORIENTATION_REVERSE_LANDSCAPE", android.content.pm.ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE ); ///< Constant corresponding to reverseLandscape in the screenOrientation attribute.
//~ c.set("SCREEN_ORIENTATION_REVERSE_PORTRAIT", android.content.pm.ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT ); ///< Constant corresponding to reversePortrait in the screenOrientation attribute.
///< Constant corresponding to sensor in the screenOrientation attribute.
c.set("SCREEN_ORIENTATION_SENSOR", android.content.pm.ActivityInfo.SCREEN_ORIENTATION_SENSOR);
//~ c.set("SCREEN_ORIENTATION_SENSOR_LANDSCAPE", android.content.pm.ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE ); ///< Constant corresponding to sensorLandscape in the screenOrientation attribute.
//~ c.set("SCREEN_ORIENTATION_SENSOR_PORTRAIT", android.content.pm.ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT ); ///< Constant corresponding to sensorPortrait in the screenOrientation attribute.
///< Constant corresponding to unspecified in the screenOrientation attribute.
c.set("SCREEN_ORIENTATION_UNSPECIFIED", android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
///< Constant corresponding to user in the screenOrientation attribute.
c.set("SCREEN_ORIENTATION_USER", android.content.pm.ActivityInfo.SCREEN_ORIENTATION_USER);
}
/// love.phone.FEEDBACK_CONSTANT = {[name]=value,...}
/// see also http://developer.android.com/reference/android/view/HapticFeedbackConstants.html
{
LuaTable c = new LuaTable();
t.set("FEEDBACK_CONSTANT", c);
///< Flag for View.performHapticFeedback(int, int): Ignore the global setting for whether to perform haptic feedback, do it always.
c.set("FLAG_IGNORE_GLOBAL_SETTING", android.view.HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING);
///< Flag for View.performHapticFeedback(int, int): Ignore the setting in the view for whether to perform haptic feedback, do it always.
c.set("FLAG_IGNORE_VIEW_SETTING", android.view.HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
//~ c.set("KEYBOARD_TAP", android.view.HapticFeedbackConstants.KEYBOARD_TAP ); ///< The user has pressed a soft keyboard key. // FIXME: cannot be resolved or is not a field
///< The user has performed a long press on an object that is resulting in an action being performed.
c.set("LONG_PRESS", android.view.HapticFeedbackConstants.LONG_PRESS);
///< The user has pressed on a virtual on-screen key.
c.set("VIRTUAL_KEY", android.view.HapticFeedbackConstants.VIRTUAL_KEY);
}
/// love.phone.SENSOR_TYPE = {[name]=value,...}
/// see also http://developer.android.com/reference/android/hardware/Sensor.html
/// see also http://developer.android.com/reference/android/hardware/SensorEvent.html#values
{
LuaTable c = new LuaTable();
t.set("SENSOR_TYPE", c);
c.set("TYPE_ACCELEROMETER", Sensor.TYPE_ACCELEROMETER);
c.set("TYPE_ALL", Sensor.TYPE_ALL);
//~ c.set( "TYPE_AMBIENT_TEMPERATURE", Sensor.TYPE_AMBIENT_TEMPERATURE ); // FIXME: cannot be resolved or is not a field
//~ c.set( "TYPE_GRAVITY", Sensor.TYPE_GRAVITY ); // FIXME: cannot be resolved or is not a field
c.set("TYPE_GYROSCOPE", Sensor.TYPE_GYROSCOPE);
c.set("TYPE_LIGHT", Sensor.TYPE_LIGHT);
//~ c.set( "TYPE_LINEAR_ACCELERATION", Sensor.TYPE_LINEAR_ACCELERATION ); // FIXME: cannot be resolved or is not a field
// compass
c.set("TYPE_MAGNETIC_FIELD", Sensor.TYPE_MAGNETIC_FIELD);
c.set("TYPE_ORIENTATION", Sensor.TYPE_ORIENTATION);
c.set("TYPE_PRESSURE", Sensor.TYPE_PRESSURE);
c.set("TYPE_PROXIMITY", Sensor.TYPE_PROXIMITY);
//~ c.set( "TYPE_RELATIVE_HUMIDITY", Sensor.TYPE_RELATIVE_HUMIDITY ); // FIXME: cannot be resolved or is not a field
//~ c.set( "TYPE_ROTATION_VECTOR", Sensor.TYPE_ROTATION_VECTOR ); // FIXME: cannot be resolved or is not a field
}
/// love.phone.MOTION_EVENT_ACTION_TYPE = {[name]=value,...}
/// e.g. love.phone.touch(..) event
/// see also http://developer.android.com/reference/android/view/MotionEvent.html
{
LuaTable c = new LuaTable();
t.set("MOTION_EVENT_ACTION_TYPE", c);
c.set("ACTION_CANCEL", MotionEvent.ACTION_CANCEL);
c.set("ACTION_DOWN", MotionEvent.ACTION_DOWN);
c.set("ACTION_MASK", MotionEvent.ACTION_MASK);
c.set("ACTION_MOVE", MotionEvent.ACTION_MOVE);
c.set("ACTION_OUTSIDE", MotionEvent.ACTION_OUTSIDE);
c.set("ACTION_POINTER_1_DOWN", MotionEvent.ACTION_POINTER_1_DOWN);
c.set("ACTION_POINTER_1_UP", MotionEvent.ACTION_POINTER_1_UP);
c.set("ACTION_POINTER_2_DOWN", MotionEvent.ACTION_POINTER_2_DOWN);
c.set("ACTION_POINTER_2_UP", MotionEvent.ACTION_POINTER_2_UP);
c.set("ACTION_POINTER_3_DOWN", MotionEvent.ACTION_POINTER_3_DOWN);
c.set("ACTION_POINTER_3_UP", MotionEvent.ACTION_POINTER_3_UP);
c.set("ACTION_POINTER_DOWN", MotionEvent.ACTION_POINTER_DOWN);
c.set("ACTION_POINTER_ID_MASK", MotionEvent.ACTION_POINTER_ID_MASK);
c.set("ACTION_POINTER_ID_SHIFT", MotionEvent.ACTION_POINTER_ID_SHIFT);
c.set("ACTION_POINTER_UP", MotionEvent.ACTION_POINTER_UP);
c.set("ACTION_UP", MotionEvent.ACTION_UP);
}
return t;
}
use of net.schattenkind.androidLove.luan.obj.LuanObjImage in project love-android by hagish.
the class LuanGraphics method InitLib.
public LuaTable InitLib() {
InitRenderer();
try {
mDefaultFont = new LuanObjFont(this);
mFont = mDefaultFont;
} catch (Exception e) {
Log("warning, failed to load default font in LuanGraphics:InitLib");
//~ vm.handleError(e);
}
LuaTable t = LuaValue.tableOf();
LuaValue _G = vm.get_G();
_G.set(sMetaName_LuanImage, LuanObjImage.CreateMetaTable(this));
_G.set(sMetaName_LuanQuad, LuanObjQuad.CreateMetaTable(this));
_G.set(sMetaName_LuanFont, LuanObjFont.CreateMetaTable(this));
_G.set(sMetaName_LuanParticleSystem, LuanObjParticleSystem.CreateMetaTable(this));
// ***** ***** ***** ***** ***** rest
// TODO: not yet implemented
t.set("checkMode", new VarArgFunction() {
@Override
public Varargs invoke(Varargs args) {
vm.NotImplemented("love.graphics." + "checkMode");
return LuaValue.NONE;
}
});
// TODO: not yet implemented
t.set("getCaption", new VarArgFunction() {
@Override
public Varargs invoke(Varargs args) {
vm.NotImplemented("love.graphics." + "getCaption");
return LuaValue.NONE;
}
});
// TODO: not yet implemented
t.set("isCreated", new VarArgFunction() {
@Override
public Varargs invoke(Varargs args) {
vm.NotImplemented("love.graphics." + "isCreated");
return LuaValue.NONE;
}
});
// TODO: not yet implemented
t.set("newFramebuffer", new VarArgFunction() {
@Override
public Varargs invoke(Varargs args) {
vm.NotImplemented("love.graphics." + "newFramebuffer");
return LuaValue.NONE;
}
});
// TODO: not yet implemented
t.set("newScreenshot", new VarArgFunction() {
@Override
public Varargs invoke(Varargs args) {
vm.NotImplemented("love.graphics." + "newScreenshot");
return LuaValue.NONE;
}
});
// TODO: not yet implemented
t.set("newSpriteBatch", new VarArgFunction() {
@Override
public Varargs invoke(Varargs args) {
vm.NotImplemented("love.graphics." + "newSpriteBatch");
return LuaValue.NONE;
}
});
// TODO: not yet implemented
t.set("pop", new VarArgFunction() {
@Override
public Varargs invoke(Varargs args) {
vm.NotImplemented("love.graphics." + "pop");
return LuaValue.NONE;
}
});
// TODO: not yet implemented
t.set("push", new VarArgFunction() {
@Override
public Varargs invoke(Varargs args) {
vm.NotImplemented("love.graphics." + "push");
return LuaValue.NONE;
}
});
// TODO: not yet implemented
t.set("present", new VarArgFunction() {
@Override
public Varargs invoke(Varargs args) {
vm.NotImplemented("love.graphics." + "present");
return LuaValue.NONE;
}
});
// TODO: not yet implemented
t.set("setCaption", new VarArgFunction() {
@Override
public Varargs invoke(Varargs args) {
vm.NotImplemented("love.graphics." + "setCaption");
return LuaValue.NONE;
}
});
// TODO: not yet implemented
t.set("setIcon", new VarArgFunction() {
@Override
public Varargs invoke(Varargs args) {
vm.NotImplemented("love.graphics." + "setIcon");
return LuaValue.NONE;
}
});
// TODO: not yet implemented
t.set("setRenderTarget", new VarArgFunction() {
@Override
public Varargs invoke(Varargs args) {
vm.NotImplemented("love.graphics." + "setRenderTarget");
return LuaValue.NONE;
}
});
// TODO: not yet implemented
t.set("toggleFullscreen", new VarArgFunction() {
@Override
public Varargs invoke(Varargs args) {
vm.NotImplemented("love.graphics." + "toggleFullscreen");
return LuaValue.NONE;
}
});
// ***** ***** ***** ***** ***** rendering options
// TODO: not yet implemented
t.set("getBackgroundColor", new VarArgFunction() {
@Override
public Varargs invoke(Varargs args) {
vm.NotImplemented("love.graphics." + "getBackgroundColor");
return LuaValue.NONE;
}
});
// TODO: not yet implemented
t.set("getBlendMode", new VarArgFunction() {
@Override
public Varargs invoke(Varargs args) {
vm.NotImplemented("love.graphics." + "getBlendMode");
return LuaValue.NONE;
}
});
// TODO: not yet implemented
t.set("getColor", new VarArgFunction() {
@Override
public Varargs invoke(Varargs args) {
vm.NotImplemented("love.graphics." + "getColor");
return LuaValue.NONE;
}
});
// TODO: not yet implemented
t.set("getColorMode", new VarArgFunction() {
@Override
public Varargs invoke(Varargs args) {
vm.NotImplemented("love.graphics." + "getColorMode");
return LuaValue.NONE;
}
});
// TODO: not yet implemented
t.set("setLine", new VarArgFunction() {
@Override
public Varargs invoke(Varargs args) {
vm.NotImplemented("love.graphics." + "setLine");
return LuaValue.NONE;
}
});
// TODO: not yet implemented
t.set("setLineStipple", new VarArgFunction() {
@Override
public Varargs invoke(Varargs args) {
vm.NotImplemented("love.graphics." + "setLineStipple");
return LuaValue.NONE;
}
});
// TODO: not yet implemented
t.set("setLineStyle", new VarArgFunction() {
@Override
public Varargs invoke(Varargs args) {
vm.NotImplemented("love.graphics." + "setLineStyle");
return LuaValue.NONE;
}
});
// TODO: not yet implemented
t.set("setLineWidth", new VarArgFunction() {
@Override
public Varargs invoke(Varargs args) {
vm.NotImplemented("love.graphics." + "setLineWidth");
return LuaValue.NONE;
}
});
// TODO: not yet implemented
t.set("setPoint", new VarArgFunction() {
@Override
public Varargs invoke(Varargs args) {
vm.NotImplemented("love.graphics." + "setPoint");
return LuaValue.NONE;
}
});
// TODO: not yet implemented
t.set("setPointSize", new VarArgFunction() {
@Override
public Varargs invoke(Varargs args) {
vm.NotImplemented("love.graphics." + "setPointSize");
return LuaValue.NONE;
}
});
// TODO: not yet implemented
t.set("setPointStyle", new VarArgFunction() {
@Override
public Varargs invoke(Varargs args) {
vm.NotImplemented("love.graphics." + "setPointStyle");
return LuaValue.NONE;
}
});
// love.graphics.setScissor( )
// love.graphics.setScissor( x, y, width, height )
t.set("setScissor", new VarArgFunction() {
@Override
public Varargs invoke(Varargs args) {
if (args.narg() == 0) {
setScissor();
} else if (args.narg() == 4) {
setScissor(args.checkint(1), args.checkint(2), args.checkint(3), args.checkint(4));
}
return LuaValue.NONE;
}
});
// TODO: not yet implemented
t.set("getLineStipple", new VarArgFunction() {
@Override
public Varargs invoke(Varargs args) {
vm.NotImplemented("love.graphics." + "getLineStipple");
return LuaValue.NONE;
}
});
// TODO: not yet implemented
t.set("getLineStyle", new VarArgFunction() {
@Override
public Varargs invoke(Varargs args) {
vm.NotImplemented("love.graphics." + "getLineStyle");
return LuaValue.NONE;
}
});
// TODO: not yet implemented
t.set("getLineWidth", new VarArgFunction() {
@Override
public Varargs invoke(Varargs args) {
vm.NotImplemented("love.graphics." + "getLineWidth");
return LuaValue.NONE;
}
});
// TODO: not yet implemented
t.set("getMaxPointSize", new VarArgFunction() {
@Override
public Varargs invoke(Varargs args) {
vm.NotImplemented("love.graphics." + "getMaxPointSize");
return LuaValue.NONE;
}
});
// TODO: not yet implemented
t.set("getModes", new VarArgFunction() {
@Override
public Varargs invoke(Varargs args) {
vm.NotImplemented("love.graphics." + "getModes");
return LuaValue.NONE;
}
});
// TODO: not yet implemented
t.set("getPointSize", new VarArgFunction() {
@Override
public Varargs invoke(Varargs args) {
vm.NotImplemented("love.graphics." + "getPointSize");
return LuaValue.NONE;
}
});
// TODO: not yet implemented
t.set("getPointStyle", new VarArgFunction() {
@Override
public Varargs invoke(Varargs args) {
vm.NotImplemented("love.graphics." + "getPointStyle");
return LuaValue.NONE;
}
});
// x, y, width, height = love.graphics.getScissor( )
t.set("getScissor", new VarArgFunction() {
@Override
public Varargs invoke(Varargs args) {
if (isScissorEnabled()) {
Rectangle scissorBox = getScissorBox();
return LuaValue.tableOf(new LuaValue[] { LuaValue.valueOf(scissorBox.left), LuaValue.valueOf(scissorBox.top), LuaValue.valueOf(scissorBox.width), LuaValue.valueOf(scissorBox.height) });
} else {
return LuaValue.NONE;
}
}
});
t.set("setBlendMode", new VarArgFunction() {
@Override
public Varargs invoke(Varargs args) {
setBlendMode(Str2BlendMode(args.checkjstring(1)));
return LuaValue.NONE;
}
});
t.set("setColorMode", new VarArgFunction() {
@Override
public Varargs invoke(Varargs args) {
setColorMode(Str2ColorMode(args.checkjstring(1)));
return LuaValue.NONE;
}
});
/// love.graphics.setBackgroundColor( red, green, blue ) // 0-255
t.set("setBackgroundColor", new VarArgFunction() {
@Override
public Varargs invoke(Varargs args) {
LuanColor rgba = new LuanColor(args);
setBackgroundColor(rgba);
return LuaValue.NONE;
}
});
/// love.graphics.setColor( red, green, blue, alpha ) // 0-255
t.set("setColor", new VarArgFunction() {
@Override
public Varargs invoke(Varargs args) {
LuanColor rgba = new LuanColor(args);
setForegroundColor(rgba);
return LuaValue.NONE;
}
});
// ***** ***** ***** ***** ***** basic geometry rendering
/// love.graphics.quad( mode, x1, y1, x2, y2, x3, y3, x4, y4 )
t.set("quad", new VarArgFunction() {
@Override
public Varargs invoke(Varargs args) {
DrawMode mode = Str2DrawMode(args.checkjstring(1));
float x1 = (float) args.checkdouble(2);
float y1 = (float) args.checkdouble(3);
float x2 = (float) args.checkdouble(4);
float y2 = (float) args.checkdouble(5);
float x3 = (float) args.checkdouble(6);
float y3 = (float) args.checkdouble(7);
float x4 = (float) args.checkdouble(8);
float y4 = (float) args.checkdouble(9);
renderQuad(mode, x1, y1, x2, y2, x3, y3, x4, y4);
return LuaValue.NONE;
}
});
/// love.graphics.triangle( mode, x1, y1, x2, y2, x3, y3 )
t.set("triangle", new VarArgFunction() {
@Override
public Varargs invoke(Varargs args) {
DrawMode mode = Str2DrawMode(args.checkjstring(1));
float x1 = (float) args.checkdouble(2);
float y1 = (float) args.checkdouble(3);
float x2 = (float) args.checkdouble(4);
float y2 = (float) args.checkdouble(5);
float x3 = (float) args.checkdouble(6);
float y3 = (float) args.checkdouble(7);
renderTriangle(mode, x1, y1, x2, y2, x3, y3);
return LuaValue.NONE;
}
});
/// love.graphics.circle( mode, x, y, radius, segments = 10 )
t.set("circle", new VarArgFunction() {
@Override
public Varargs invoke(Varargs args) {
DrawMode mode = Str2DrawMode(args.checkjstring(1));
float x = (float) args.checkdouble(2);
float y = (float) args.checkdouble(3);
float radius = (float) args.checkdouble(4);
int segments = IsArgSet(args, 5) ? args.checkint(5) : 10;
renderCircle(mode, x, y, radius, segments);
return LuaValue.NONE;
}
});
/// love.graphics.point( x, y )
t.set("point", new VarArgFunction() {
@Override
public Varargs invoke(Varargs args) {
float x = (float) args.checkdouble(1);
float y = (float) args.checkdouble(2);
renderPoint(x, y);
return LuaValue.NONE;
}
});
/// love.graphics.rectangle( mode, x, y, width, height )
t.set("rectangle", new VarArgFunction() {
@Override
public Varargs invoke(Varargs args) {
DrawMode mode = Str2DrawMode(args.checkjstring(1));
float x = (float) args.checkdouble(2);
float y = (float) args.checkdouble(3);
float w = (float) args.checkdouble(4);
float h = (float) args.checkdouble(5);
renderRectangle(mode, x, y, w, h);
return LuaValue.NONE;
}
});
/// love.graphics.line( x1, y1, x2, y2, ... )
t.set("line", new VarArgFunction() {
@Override
public Varargs invoke(Varargs args) {
if (IsArgSet(args, 5)) {
renderPolyLine(FloatArray(args, 1));
} else {
float x1 = (float) args.checkdouble(1);
float y1 = (float) args.checkdouble(2);
float x2 = (float) args.checkdouble(3);
float y2 = (float) args.checkdouble(4);
renderLine(x1, y1, x2, y2);
}
return LuaValue.NONE;
}
});
/// love.graphics.polygon( mode, ... )
/// Note: when in fill mode, the polygon must be convex and simple or rendering artifacts may occur.
t.set("polygon", new VarArgFunction() {
@Override
public Varargs invoke(Varargs args) {
DrawMode mode = Str2DrawMode(args.checkjstring(1));
renderPolygon(mode, FloatArray(args, 2));
return LuaValue.NONE;
}
});
/// love.graphics.clear ( )
/// Clears the screen to background color.
t.set("clear", new VarArgFunction() {
@Override
public Varargs invoke(Varargs args) {
getGL().glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
return LuaValue.NONE;
}
});
// ***** ***** ***** ***** ***** font + text
// TODO: not yet implemented
t.set("getFont", new VarArgFunction() {
@Override
public Varargs invoke(Varargs args) {
vm.NotImplemented("love.graphics." + "getFont");
return LuaValue.NONE;
}
});
/// love.graphics.print( text, x, y, r, sx, sy )
/// Draws text on screen.
t.set("print", new VarArgFunction() {
@Override
public Varargs invoke(Varargs args) {
String s = args.checkjstring(1);
float x = (float) args.checkdouble(2);
float y = (float) args.checkdouble(3);
float r = (IsArgSet(args, 4)) ? ((float) args.checkdouble(4)) : 0f;
float sx = (IsArgSet(args, 5)) ? ((float) args.checkdouble(5)) : 1f;
float sy = (IsArgSet(args, 6)) ? ((float) args.checkdouble(6)) : sx;
//~ Log("print:"+s);
if (mFont != null)
mFont.print(s, x, y, r, sx, sy);
return LuaValue.NONE;
}
});
/// love.graphics.printf( text, x, y, limit, align )
/// NOTE: not related to c printf, rather wordwrap etc
/// Draws formatted text, with word wrap and alignment.
t.set("printf", new VarArgFunction() {
@Override
public Varargs invoke(Varargs args) {
String s = args.checkjstring(1);
float x = (float) args.checkdouble(2);
float y = (float) args.checkdouble(3);
float limit = (float) args.checkdouble(4);
String align = (IsArgSet(args, 5)) ? args.checkjstring(5) : "left";
//~ Log("printf:"+align+":"+s);
if (mFont != null)
mFont.printf(s, x, y, limit, LuanObjFont.Text2Align(align));
return LuaValue.NONE;
}
});
// todo : newImageFont, setfont, print...
/// font = love.graphics.newFont( filename, size )
/// font = love.graphics.newFont( size ) (default font (Vera Sans))
t.set("newFont", new VarArgFunction() {
@Override
public Varargs invoke(Varargs args) {
if (args.isstring(1)) {
String filename = args.checkjstring(1);
int iSize = IsArgSet(args, 2) ? args.checkint(2) : 12;
try {
return LuaValue.userdataOf(new LuanObjFont(LuanGraphics.this, filename, iSize), vm.get_G().get(sMetaName_LuanFont));
} catch (Exception e) {
vm.handleError(e);
}
return LuaValue.NONE;
} else {
int iSize = (IsArgSet(args, 1)) ? args.checkint(1) : 12;
try {
return LuaValue.userdataOf(new LuanObjFont(LuanGraphics.this, iSize), vm.get_G().get(sMetaName_LuanFont));
} catch (Exception e) {
vm.handleError(e);
}
return LuaValue.NONE;
}
}
});
/// font = love.graphics.newImageFont( image, glyphs )
t.set("newImageFont", new VarArgFunction() {
@Override
public Varargs invoke(Varargs args) {
if (args.isstring(1)) {
String filename = args.checkjstring(1);
String glyphs = args.checkjstring(2);
try {
return LuaValue.userdataOf(new LuanObjFont(LuanGraphics.this, filename, glyphs), vm.get_G().get(sMetaName_LuanFont));
} catch (Exception e) {
vm.handleError(e);
}
return LuaValue.NONE;
} else {
LuanObjImage img = (LuanObjImage) args.checkuserdata(1, LuanObjImage.class);
String glyphs = args.checkjstring(2);
return LuaValue.userdataOf(new LuanObjFont(LuanGraphics.this, img, glyphs), vm.get_G().get(sMetaName_LuanFont));
}
}
});
/// love.graphics.setFont( font )
t.set("setFont", new VarArgFunction() {
@Override
public Varargs invoke(Varargs args) {
mFont = IsArgSet(args, 1) ? (LuanObjFont) args.checkuserdata(1, LuanObjFont.class) : mDefaultFont;
return LuaValue.NONE;
}
});
// ***** ***** ***** ***** ***** rest
/// img = love.graphics.newImage(sFileName)
t.set("newImage", new VarArgFunction() {
@Override
public Varargs invoke(Varargs args) {
String s = args.checkjstring(1);
try {
return LuaValue.userdataOf(new LuanObjImage(LuanGraphics.this, s), vm.get_G().get(sMetaName_LuanImage));
} catch (Exception e) {
vm.handleError(e);
}
return LuaValue.NONE;
}
});
/// quad = love.graphics.newQuad( x, y, width, height, sw, sh )
t.set("newQuad", new VarArgFunction() {
@Override
public Varargs invoke(Varargs args) {
float x = (float) args.checkdouble(1);
float y = (float) args.checkdouble(2);
float w = (float) args.checkdouble(3);
float h = (float) args.checkdouble(4);
float sw = (float) args.checkdouble(5);
float sh = (float) args.checkdouble(6);
try {
return LuaValue.userdataOf(new LuanObjQuad(LuanGraphics.this, x, y, w, h, sw, sh), vm.get_G().get(sMetaName_LuanQuad));
} catch (Exception e) {
vm.handleError(e);
}
return LuaValue.NONE;
}
});
/// system = love.graphics.newParticleSystem( image, buffer )
t.set("newParticleSystem", new VarArgFunction() {
@Override
public Varargs invoke(Varargs args) {
LuanObjImage img = (LuanObjImage) args.checkuserdata(1, LuanObjImage.class);
int iBufferSize = args.checkint(2);
try {
return LuaValue.userdataOf(new LuanObjParticleSystem(LuanGraphics.this, img, iBufferSize), vm.get_G().get(sMetaName_LuanParticleSystem));
} catch (Exception e) {
vm.handleError(e);
}
return LuaValue.NONE;
}
});
/// love.graphics.draw(drawable, x, y, r=0, sx=1, sy=1, ox=0, oy=0)
t.set("draw", new VarArgFunction() {
@Override
public Varargs invoke(Varargs args) {
LuanObjDrawable drawable = (LuanObjDrawable) args.checkuserdata(1, LuanObjDrawable.class);
float x = (float) args.checkdouble(2);
float y = (float) args.checkdouble(3);
float r = (IsArgSet(args, 4)) ? ((float) args.checkdouble(4)) : 0.0f;
float sx = (IsArgSet(args, 5)) ? ((float) args.checkdouble(5)) : 1.0f;
float sy = (IsArgSet(args, 6)) ? ((float) args.checkdouble(6)) : 1.0f;
float ox = (IsArgSet(args, 7)) ? ((float) args.checkdouble(7)) : 0.0f;
float oy = (IsArgSet(args, 8)) ? ((float) args.checkdouble(8)) : 0.0f;
if (drawable.IsImage()) {
LuanObjImage img = (LuanObjImage) drawable;
DrawSprite(img.GetTextureID(), img.mWidth, img.mHeight, x, y, r, sx, sy, ox, oy);
} else {
drawable.RenderSelf(x, y, r, sx, sy, ox, oy);
}
return LuaValue.NONE;
}
});
/// love.graphics.drawq( image, quad, x, y, r, sx, sy, ox, oy )
t.set("drawq", new VarArgFunction() {
@Override
public Varargs invoke(Varargs args) {
LuanObjImage img = (LuanObjImage) args.checkuserdata(1, LuanObjImage.class);
LuanObjQuad quad = (LuanObjQuad) args.checkuserdata(2, LuanObjQuad.class);
float x = (float) args.checkdouble(3);
float y = (float) args.checkdouble(4);
float r = (IsArgSet(args, 5)) ? ((float) args.checkdouble(5)) : 0.0f;
float sx = (IsArgSet(args, 6)) ? ((float) args.checkdouble(6)) : 1.0f;
float sy = (IsArgSet(args, 7)) ? ((float) args.checkdouble(7)) : 1.0f;
float ox = (IsArgSet(args, 8)) ? ((float) args.checkdouble(8)) : 0.0f;
float oy = (IsArgSet(args, 9)) ? ((float) args.checkdouble(9)) : 0.0f;
DrawSprite(img.GetTextureID(), quad, quad.w, quad.h, x, y, r, sx, sy, ox, oy);
return LuaValue.NONE;
}
});
/// success = love.graphics.setMode( width, height, fullscreen, vsync, fsaa )
t.set("setMode", new VarArgFunction() {
@Override
public Varargs invoke(Varargs args) {
bResolutionOverrideActive = true;
mfResolutionOverrideX = args.checkint(1);
mfResolutionOverrideY = args.checkint(2);
// TODO: idea : if w>h and natural w<h , flip 90� ?
Log("love.graphics.setMode requested resolution = " + mfResolutionOverrideX + " x " + mfResolutionOverrideY);
return LuaValue.TRUE;
}
});
/// width = love.graphics.getWidth( )
/// Gets the width of the window.
t.set("getWidth", new VarArgFunction() {
@Override
public Varargs invoke(Varargs args) {
float w = getScreenW();
Log("love.graphics.getWidth = " + w);
return LuaValue.valueOf(w);
}
});
/// height = love.graphics.getHeight( )
/// Gets the height of the window.
t.set("getHeight", new VarArgFunction() {
@Override
public Varargs invoke(Varargs args) {
float h = getScreenH();
Log("love.graphics.getHeight = " + h);
return LuaValue.valueOf(h);
}
});
// ***** ***** ***** ***** ***** global transforms / coordinate system
/// love.graphics.scale( sx, sy )
/// Scaling lasts until love.draw() exits.
t.set("scale", new VarArgFunction() {
@Override
public Varargs invoke(Varargs args) {
float sx = (float) args.checkdouble(1);
float sy = (float) args.checkdouble(2);
getGL().glScalef(sx, sy, 1);
return LuaValue.NONE;
}
});
/// love.graphics.translate( dx, dy )
/// Translates the coordinate system in two dimensions.
t.set("translate", new VarArgFunction() {
@Override
public Varargs invoke(Varargs args) {
float dx = (float) args.checkdouble(1);
float dy = (float) args.checkdouble(2);
getGL().glTranslatef(dx, dy, 1);
return LuaValue.NONE;
}
});
/// Rotates the coordinate system in two dimensions.
/// Calling this function affects all future drawing operations by rotating the coordinate system around the origin by the given amount of radians. This change lasts until love.draw() exits.
/// love.graphics.rotate( angle )
t.set("rotate", new VarArgFunction() {
@Override
public Varargs invoke(Varargs args) {
float a = (float) args.checkdouble(1);
getGL().glRotatef(LOVE_TODEG(a), 0, 0, 1);
return LuaValue.NONE;
}
});
/// love.graphics.reset( )
/// Calling reset makes the current drawing color white, the current background color black, the window title empty and removes any scissor settings. It sets the BlendMode to alpha and ColorMode to modulate.
/// It also sets both the point and line drawing modes to smooth and their sizes to 1.0 . Finally, it removes any stipple settings.
t.set("reset", new VarArgFunction() {
@Override
public Varargs invoke(Varargs args) {
setBackgroundColor(new LuanColor(0.0f, 0.0f, 0.0f, 1.0f));
setForegroundColor(new LuanColor(1f, 1f, 1f, 1f));
resetTransformMatrix(getGL());
vm.NotImplemented("love.graphics.reset (lots of settings)");
// TODO: not yet implemented
return LuaValue.NONE;
}
});
return t;
}
Aggregations