Exemplo n.º 1
0
/***
Draw a filled rectangle on the current screen.
@function rectangle
@tparam integer x rectangle origin horizontal coordinate, in pixels
@tparam integer y rectangle origin vertical coordinate, in pixels
@tparam integer width rectangle width, in pixels
@tparam integer height rectangle height, in pixels
@tparam[opt=0] number angle rectangle rotation, in radians
@tparam[opt=default color] integer color drawing color
@tparam[opt] integer color2 Second drawing color ; if the argument is not nil, the rectangle will be filled with a gradient from color to color2
@tparam[opt] integer direction Gradient drawing direction (`gfx.TOP_TO_BOTTOM` or `gfx.LEFT_TO_RIGHT`). This argument is mandatory if a second color was specified.
*/
static int gfx_rectangle(lua_State *L) {
	int x = luaL_checkinteger(L, 1);
	int y = luaL_checkinteger(L, 2);
	int width = luaL_checkinteger(L, 3);
	int height = luaL_checkinteger(L, 4);

	float angle = luaL_optnumber(L, 5, 0);
	u32 color = luaL_optinteger(L, 6, color_default);

	// Not second color : fill with plain color.
	if (lua_isnoneornil(L, 7)) {
		if (angle == 0)
			sf2d_draw_rectangle(x, y, width, height, color);
		else
			sf2d_draw_rectangle_rotate(x, y, width, height, color, angle);
	// Two colors : fill with a gradient.
	} else {
		u32 color2 = luaL_checkinteger(L, 7);
		u8 direction = luaL_checkinteger(L, 8);

		if (angle == 0)
			sf2d_draw_rectangle_gradient(x, y, width, height, color, color2, direction);
		else
			sf2d_draw_rectangle_gradient_rotate(x, y, width, height, color, color2, direction, angle);
	}

	return 0;
}
Exemplo n.º 2
0
int main()
{
    // Set the random seed based on the time
    srand(time(NULL));

    sf2d_init();
    sf2d_set_clear_color(RGBA8(0x40, 0x40, 0x40, 0xFF));


    sf2d_texture *tex1 = sf2d_create_texture_mem_RGBA8(dice_img.pixel_data, dice_img.width, dice_img.height, TEXFMT_RGBA8, SF2D_PLACE_RAM);
    sf2d_texture *tex2 = sf2d_create_texture_mem_RGBA8(citra_img.pixel_data, citra_img.width, citra_img.height, TEXFMT_RGBA8, SF2D_PLACE_RAM);

    float rad = 0.0f;
    u16 touch_x = 320/2;
    u16 touch_y = 240/2;
    touchPosition touch;
    circlePosition circle;
    u32 held;

    while (aptMainLoop()) {

        hidScanInput();
        hidCircleRead(&circle);
        held = hidKeysHeld();

        if (held & KEY_START) {
            break;
        } else if (held & KEY_TOUCH) {
            hidTouchRead(&touch);
            touch_x = touch.px;
            touch_y = touch.py;
        } else if (held & (KEY_L | KEY_R)) {
            sf2d_set_clear_color(RGBA8(rand()%255, rand()%255, rand()%255, 255));
        }

        sf2d_start_frame(GFX_TOP, GFX_LEFT);
        sf2d_draw_rectangle_rotate(260, 20, 40, 40, RGBA8(0xFF, 0xFF, 0x00, 0xFF), -2.0f*rad);
        sf2d_draw_rectangle(20, 60, 40, 40, RGBA8(0xFF, 0x00, 0x00, 0xFF));
        sf2d_draw_rectangle(5, 5, 30, 30, RGBA8(0x00, 0xFF, 0xFF, 0xFF));
        sf2d_draw_texture_rotate(tex1, 400/2 + circle.dx, 240/2 - circle.dy, rad);
        sf2d_end_frame();

        sf2d_start_frame(GFX_BOTTOM, GFX_LEFT);
        sf2d_draw_rectangle_rotate(190, 160, 70, 60, RGBA8(0xFF, 0xFF, 0xFF, 0xFF), 3.0f*rad);
        sf2d_draw_rectangle(30, 100, 40, 60, RGBA8(0xFF, 0x00, 0xFF, 0xFF));
        sf2d_draw_texture_rotate(tex2, touch_x, touch_y, -rad);
        sf2d_draw_rectangle(160-15 + cosf(rad)*50.0f, 120-15 + sinf(rad)*50.0f, 30, 30, RGBA8(0x00, 0xFF, 0xFF, 0xFF));
        sf2d_draw_fill_circle(40, 40, 35, RGBA8(0x00, 0xFF, 0x00, 0xFF));
        sf2d_end_frame();

        rad += 0.2f;

        sf2d_swapbuffers();
    }

    sf2d_free_texture(tex1);
    sf2d_free_texture(tex2);

    sf2d_fini();
    return 0;
}