Esempio n. 1
0
static int graphicsDraw(lua_State *L) { // love.graphics.draw()

	if (sf2d_get_current_screen() == currentScreen) {

		love_image *img = luaobj_checkudata(L, 1, LUAOBJ_TYPE_IMAGE);
		love_quad *quad = NULL;

		int x, y;
		float rad;

		if (!lua_isnone(L, 2) && lua_type(L, 2) != LUA_TNUMBER) {

			quad = luaobj_checkudata(L, 2, LUAOBJ_TYPE_QUAD);
			x = luaL_optnumber(L, 3, 0);
			y = luaL_optnumber(L, 4, 0);
			rad = luaL_optnumber(L, 5, 0);

		} else {

			x = luaL_optnumber(L, 2, 0);
			y = luaL_optnumber(L, 3, 0);
			rad = luaL_optnumber(L, 4, 0);

		}

		translateCoords(&x, &y);

		if (rad == 0) {

			if (!quad) {

				if (img) {
					sf2d_draw_texture_blend(img->texture, x, y, getCurrentColor());
				}
				
			} else {
				sf2d_draw_texture_part_blend(img->texture, x, y, quad->x, quad->y, quad->width, quad->height, getCurrentColor());
			}

		} else {

			sf2d_draw_texture_rotate_blend(img->texture, x + img->texture->width / 2, y + img->texture->height / 2, rad, getCurrentColor());

		}

	}

	return 0;

}
Esempio n. 2
0
int imageSetFilter(lua_State *L) { // image:setFilter()

	love_image *self = luaobj_checkudata(L, 1, CLASS_TYPE);

	char *minMode = luaL_checkstring(L, 2);
	char *magMode = luaL_optstring(L, 3, minMode);

	u32 minFilter;
	u32 magFilter;

	if (strcmp(minMode, "linear") != 0 && 
		strcmp(minMode, "nearest") != 0 &&
		strcmp(magMode, "linear") != 0 &&
		strcmp(magMode, "nearest" != 0)) {
			luaError(L, "Invalid Image Filter.");
			return 0;
		}

	if (strcmp(minMode, "linear") == 0) minFilter = GPU_TEXTURE_MIN_FILTER(GPU_LINEAR);
	if (strcmp(magMode, "linear") == 0) magFilter = GPU_TEXTURE_MAG_FILTER(GPU_LINEAR);
	if (strcmp(minMode, "nearest") == 0) minFilter = GPU_TEXTURE_MIN_FILTER(GPU_NEAREST);
	if (strcmp(magMode, "nearest") == 0) magFilter = GPU_TEXTURE_MAG_FILTER(GPU_NEAREST);

	sf2d_texture_set_params(self->texture, magFilter | minFilter);

	self->minFilter = minMode;
	self->magFilter = magMode;

	return 0;

}
Esempio n. 3
0
static int graphicsSetFont(lua_State *L) { // love.graphics.setFont()

	currentFont = luaobj_checkudata(L, 1, LUAOBJ_TYPE_FONT);

	return 0;

}
Esempio n. 4
0
int joystickIsGamepadDown(lua_State *L) { //joystick:isGamepadDown()
	
	//Check first argument is Joystick type
	love_joystick *self = luaobj_checkudata(L, 1, CLASS_TYPE);
	
	//Get input
	hidScanInput();
	u32 kHeld = hidKeysHeld();
	
	//Check arguments given
	int numBtnsCheck = lua_gettop(L);
	for (int i = 2; i <= numBtnsCheck; i++) {
		const char *str = luaL_checkstring(L, i);
		
		bool result = false;
		
		for( int i = 0; i < 32; i++ ) {
			if(kHeld & BIT(i)) {
				if( strcmp( gamepadMapping[i], "touch" ) != 0 ) {
					if( strcmp(str, gamepadMapping[i]) == 0) {
						result = true;
					}
				}
			}
		}
		
		lua_pushboolean(L, result);
	}
	return numBtnsCheck-1;

}
Esempio n. 5
0
int joystickGetID(lua_State *L) { // joystick:getID()
	
	love_joystick *self = luaobj_checkudata(L, 1, CLASS_TYPE);
	lua_pushinteger(L, self->id);
	return 1;
	
}
Esempio n. 6
0
int imageGetWidth(lua_State *L) { // image:getWidth()

	love_image *self = luaobj_checkudata(L, 1, CLASS_TYPE);
	lua_pushinteger(L, self->texture->width);

	return 1;

}
Esempio n. 7
0
int fontGetHeight(lua_State *L) { // font:getHeight()

	love_font *self = luaobj_checkudata(L, 1, CLASS_TYPE);
	lua_pushinteger(L, self->size);

	return 1;

}
Esempio n. 8
0
File: l_quad.c Progetto: rxi/lovedos
int l_quad_getViewport(lua_State *L) {
  quad_t *self = luaobj_checkudata(L, 1, CLASS_TYPE);
  lua_pushnumber(L, self->x);
  lua_pushnumber(L, self->y);
  lua_pushnumber(L, self->width);
  lua_pushnumber(L, self->height);
  return 4;
}
Esempio n. 9
0
File: l_quad.c Progetto: rxi/lovedos
int l_quad_setViewport(lua_State *L) {
  quad_t *self = luaobj_checkudata(L, 1, CLASS_TYPE);
  self->x = luaL_checknumber(L, 2);
  self->y = luaL_checknumber(L, 3);
  self->width = luaL_checknumber(L, 4);
  self->height = luaL_checknumber(L, 5);
  return 0;
}
Esempio n. 10
0
int imageGetDimensions(lua_State *L) { // image:getDimensions()

	love_image *self = luaobj_checkudata(L, 1, CLASS_TYPE);
	lua_pushinteger(L, self->texture->width);
	lua_pushinteger(L, self->texture->height);

	return 2;

}
Esempio n. 11
0
int fontGC(lua_State *L) { // Garbage Collection

	fontCounter -= 1;
	love_font *self = luaobj_checkudata(L, 1, CLASS_TYPE);
	sftd_free_font(self->font);

	return 0;

}
Esempio n. 12
0
int imageGetFilter(lua_State *L) { // image:getFilter()

	love_image *self = luaobj_checkudata(L, 1, CLASS_TYPE);

	lua_pushstring(L, self->minFilter);
	lua_pushstring(L, self->magFilter);

	return 2;

}
Esempio n. 13
0
int fontGetWidth(lua_State *L) { // font:getWidth()

	love_font *self = luaobj_checkudata(L, 1, CLASS_TYPE);
	const char *text = luaL_checkstring(L, 2);

	lua_pushinteger(L, sftd_get_text_width(self->font, self->size, text));

	return 1;

}
Esempio n. 14
0
int imageGC(lua_State *L) { // Garbage Collection

	love_image *self = luaobj_checkudata(L, 1, CLASS_TYPE);

	if (!self->texture) return 0;

	sf2d_free_texture(self->texture);
	self->texture = NULL;

	return 0;

}
Esempio n. 15
0
int joystickGetAxes(lua_State *L) {
	
	love_joystick *self = luaobj_checkudata(L, 1, CLASS_TYPE);
	
	int numAxesCheck = lua_gettop(L);
	for (int i = 2; i <= numAxesCheck; i++) {
		
		int axisId = luaL_checkinteger(L, i);
		
		if( axisId < 5 ) { // Circle Axes
			
			circlePosition circleData;
			hidCircleRead(&circleData);

			if( axisId == 1 ) lua_pushinteger(L, circleData.dx);
			if( axisId == 2 ) lua_pushinteger(L, circleData.dy);
			
			circlePosition cStickData;
			irrstCstickRead(&cStickData);

			if( axisId == 3 ) lua_pushinteger(L, cStickData.dx);
			if( axisId == 4 ) lua_pushinteger(L, cStickData.dy);

		} else if( axisId < 8 ) { // Gyro Axes
			
			HIDUSER_EnableGyroscope();
			angularRate gyroData;
			hidGyroRead(&gyroData);
			
			if( axisId == 5 ) lua_pushinteger(L, gyroData.x);
			if( axisId == 6 ) lua_pushinteger(L, gyroData.y);
			if( axisId == 7 ) lua_pushinteger(L, gyroData.z);
			
		} else if ( axisId < 11 ) { // Accelloremeter Axes
		
			HIDUSER_EnableAccelerometer();
			accelVector accelData;
			hidAccelRead(&accelData);

			if( axisId == 8 ) lua_pushinteger(L, accelData.x);
			if( axisId == 9 ) lua_pushinteger(L, accelData.y);
			if( axisId == 10 ) lua_pushinteger(L, accelData.z);
		
		} else {
			luaError(L, "AxisId out of bounds");
		}
		
	}
	
	return numAxesCheck-1;
	
}
Esempio n. 16
0
int joystickGetAxis(lua_State *L) {
	
	love_joystick *self = luaobj_checkudata(L, 1, CLASS_TYPE);
	int axisId = luaL_checkinteger(L, 2);
	
	
	if( axisId < 3 ) { // Circle Axes
		
		circlePosition circleData;
		hidCircleRead(&circleData);

		if( axisId == 1 ) lua_pushinteger(L, circleData.dx);
		if( axisId == 2 ) lua_pushinteger(L, circleData.dy);
		
	} else if( axisId < 6 ) { // Gyro Axes
		
		HIDUSER_EnableGyroscope();
		angularRate gyroData;
		hidGyroRead(&gyroData);
		
		if( axisId == 3 ) lua_pushinteger(L, gyroData.x);
		if( axisId == 4 ) lua_pushinteger(L, gyroData.y);
		if( axisId == 5 ) lua_pushinteger(L, gyroData.z);
		
	} else if ( axisId < 9 ) { // Accelloremeter Axes
	
		HIDUSER_EnableAccelerometer();
		accelVector accelData;
		hidAccelRead(&accelData);
		if( axisId == 6 ) lua_pushinteger(L, accelData.x);
		if( axisId == 7 ) lua_pushinteger(L, accelData.y);
		if( axisId == 8 ) lua_pushinteger(L, accelData.z);
	
	} else {
		luaError(L, "AxisId out of bounds");
	}
	
	return 1;
	
}