int32_t Lux_NATIVE_DrawChar( int32_t cchar, int32_t x, int32_t y, ObjectEffect effects, bool allow_custom )
{
	sf2d_texture * 	texture = NULL;
	LuxColour c = effects.primary_colour;
	LuxRect area;
	NativeTexture * ntexture = NULL;
	LuxSprite * sprite_data = NULL;
	int32_t offset = 7;

	int8_t axis;
	int8_t button;
	int8_t pointer;

	area.x = x;
	area.y = y;

	UnicodeToInput( cchar, &axis, &button, &pointer );

	if ( axis >= 0 || button >= 0 || pointer >= 0 )
	{
		c.r = c.g = c.b = 255;
		sprite_data = lux::display->GetInputSprite( 0, axis, button, pointer );
	}


	if ( sprite_data )
	{
		ntexture = (NativeTexture*)sprite_data->GetData();

		texture = ntexture->texture;

		area.w = ntexture->tw;
		area.h = ntexture->th;

		offset = ntexture->w;

	}
	else
	{
		texture = dsgraphics_bitfont->GetTexture(cchar);

		offset = 8;
		area.w = 8;
		area.h = 8;
	}


	if ( texture )
	{
		sf2d_draw_texture_blend(texture, area.x, area.y, RGBA8(effects.primary_colour.r, effects.primary_colour.g, effects.primary_colour.b, effects.primary_colour.a) 	);
	}
	return offset;
}
示例#2
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;

}
void Lux_NATIVE_DrawMessage( std::string message, uint8_t alignment )
{
	std::string::iterator object;
	LuxRect rect, area, draw;
	int16_t w = 400, h = 240;

	bool watch_for_color = false;
	bool is_whitspace = false;
	LuxColour font_color = { 255, 255,255, 255 };

	rect.x = rect.y = 0;

	Lux_Util_SetRectFromText( rect, message, 7, 10, 240 );

	area = rect;

	if ( alignment == 3 )
	{
		area.y = h - area.h;
	}
	else if ( alignment == 2 )
	{
		area.y = h - area.h;
		area.x = w - area.w;
	}
	else if ( alignment == 1 )
	{
		area.x = w - area.w;
	}


	draw = area;
	draw.w = draw.h = 8;

	for ( object = message.begin(); object != message.end(); object++ )
	{
		uint8_t utfchar = *object;
		uint32_t cchar = utfchar;

		is_whitspace = false;

		if (cchar == '\n' || cchar == '\r')
		{
			draw.y += 10;
			draw.x = area.x;
			cchar = 0;
			is_whitspace = true;
		}
		else if ( cchar <= 32 )
		{
			draw.x += 7;
			cchar = 0;
			is_whitspace = true;
		}
		else if ( cchar <= 128 )
		{

		}
		else if ( cchar < 224 )
		{
			object++;
			uint32_t next = *object;

			cchar = ((cchar << 6) & 0x7ff) + (next & 0x3f);
		}
		else if ( cchar < 240 )
		{
			uint32_t next;

			object++;
			next = (*object) & 0xff;
			cchar = ((cchar << 12) & 0xffff) + ((next << 6) & 0xfff);

			object++;
			next = (*object) & 0x3f;
			cchar += next;

		}
		else if ( cchar < 245 )
		{
			uint32_t next;

			object++;
			next = (*object) & 0xff;
			cchar = ((cchar << 18) & 0xffff) + ((next << 12) & 0x3ffff);

			object++;
			next = (*object) & 0xff;
			cchar += (next << 6) & 0xfff;

			object++;
			next = (*object) & 0x3f;
			cchar += next;
		}

		if ( cchar != 0 )
		{
			if ( !Lux_Util_CheckTextColour( cchar, font_color, watch_for_color ) )
			{
				sf2d_texture * texture = dsgraphics_bitfont->GetTexture(cchar);

				if ( texture )
				{
					sf2d_draw_texture_blend(texture, draw.x, draw.y, RGBA8(font_color.r, font_color.g, font_color.b, font_color.a) 	);
				}
				else
				{
					sf2d_draw_rectangle(draw.x, draw.y, draw.w, draw.h, RGBA8(font_color.r, font_color.g, font_color.b, font_color.a)  );
				}
				draw.x += 7;
			}
		}

		if ( is_whitspace )
		{
			/* Reset Colour if a whitespace occurs */
			font_color.r = font_color.g = font_color.b = 255;
		}
	}
}
/**
 * @brief Lux_NATIVE_DrawSprite
 * @param sprite
 * @param dest_rect
 * @param effects
 */
void Lux_NATIVE_DrawSprite( LuxSprite * sprite, LuxRect dest_rect, ObjectEffect effect )
{
	if ( !sprite->data )
		return;

	Lux_NATIVE_SetFrame(dest_rect, false);

	NativeTexture * surface = (NativeTexture*) sprite->GetData(effect);

	double angle = (double)effect.rotation;
	uint8_t flipmode = 0;

	LuxRect draw;
	LuxPath point;
	LuxRect repeat;

	draw.x = dest_rect.x;
	draw.y = dest_rect.y;
	draw.w = surface->w;
	draw.h = surface->h;

//	point.x = draw.w/2;
//	point.y = draw.h/2;

	point.x = 0;
	point.y = 0;
	/* Flip image, rotates image either 90, 180, 270 and/or mirrors. */
	if ( effect.flip_image&16 ) // Mirror Sprite.
	{
		effect.flip_image -= 16;
		flipmode = 1;
	}

	if ( effect.flip_image == 1 || effect.flip_image == 3 )
	{
		repeat.y = dest_rect.w / surface->w;
		repeat.x = dest_rect.h / surface->h;

		repeat.w = surface->h;
		repeat.h = surface->w;
	}
	else
	{
		repeat.x = dest_rect.w / surface->w;
		repeat.y = dest_rect.h / surface->h;

		repeat.w = surface->w;
		repeat.h = surface->h;
	}


	if ( effect.flip_image == 1 )// Switch Axis
	{
		angle += 90.0;

	}
	else if ( effect.flip_image == 2 )// Switch Axis
	{
		angle += 180.0;
	}
	else if ( effect.flip_image == 3 )// Switch Axis
	{
		angle += 270.0;
	}

	if ( repeat.x > 1 || repeat.y > 1 )
	{
		for( int32_t rx = 0; rx < repeat.x; rx++ )
		{
			for( int32_t ry = 0; ry < repeat.y; ry++ )
			{
				draw.x = dest_rect.x + (repeat.w*rx);
				draw.y = dest_rect.y + (repeat.h*ry);
				draw.w = repeat.w;
				draw.h = repeat.h;

				if ( effect.flip_image == 1 )// Switch Axis
				{
					draw.x += surface->h;
				}
				else if ( effect.flip_image == 2 )// Switch Axis
				{
					draw.y += surface->h;
					draw.x += surface->w;
				}
				else if ( effect.flip_image == 3 )// Switch Axis
				{
					draw.y += surface->w;
				}


				draw.w = surface->w;
				draw.h = surface->h;


				sf2d_draw_texture_blend( surface->texture,draw.x, draw.y, RGBA8(effect.primary_colour.r, effect.primary_colour.g, effect.primary_colour.b, effect.primary_colour.a));

			}
		}
	}
	else
	{
		if ( effect.flip_image == 1 )// Switch Axis
		{
			draw.x += surface->h;
		}
		else if ( effect.flip_image == 2 )// Switch Axis
		{
			draw.y += surface->h;
			draw.x += surface->w;
		}
		else if ( effect.flip_image == 3 )// Switch Axis
		{
			draw.y += surface->w;
		}
		sf2d_draw_texture_blend( surface->texture,draw.x, draw.y, RGBA8(effect.primary_colour.r, effect.primary_colour.g, effect.primary_colour.b, effect.primary_colour.a));
	}

}