📄 lua_blit.c
字号:
/****************************************************************************
** **
** LuAllegro library - Lua port of Allegro **
** Copyright (C) 2005 Peter Jamroz **
** e-mail: peterjam at poczta dot onet dot pl **
** **
** Permission to use, copy, modify, publish this software **
** is hereby granted to any person obtaining a copy of this software, **
** FREE OF CHARGE, **
** under the following conditions: **
** **
** 1: The above copyright notice and this permission notice shall be **
** included in all copies or substantial portions of the Software. **
** **
** 2: THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, **
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF **
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.**
** IN NO EVENT SHALL THE AUTHOR OR COPYRIGHT HOLDER BE LIABLE FOR ANY **
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, **
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE **
** SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. **
** **
****************************************************************************/
#include <allegro.h>
#include <string.h>
#include "lua_aleg.h"
#include "lua_blit.h"
//------------------------------------------------------------------------------------------
#define prepare_blit()\
AUD* au_source = (AUD*) lua_touserdata (L,1);\
AUD* au_dest = (AUD*) lua_touserdata (L,2);\
BITMAP* source;\
BITMAP* dest;\
int source_x = lua_tonumber(L,3);\
int source_y = lua_tonumber(L,4);\
int dest_x = lua_tonumber(L,5);\
int dest_y = lua_tonumber(L,6);\
int width = lua_tonumber(L,7);\
int height = lua_tonumber(L,8);\
if (au_source && au_source->DataType==AL_BITMAP) source = (BITMAP*) au_source->DataPtr;\
else source = screen;\
if (au_dest && au_dest->DataType ==AL_BITMAP) dest = (BITMAP*) au_dest->DataPtr;\
else dest = screen;\
//------------------------------------------------------------------------------------------
//void blit(BITMAP *source, BITMAP *dest, int source_x, int source_y, int dest_x, int dest_y, int width, int height);
static int l_blit(lua_State *L)
{
prepare_blit();
blit(source,dest,source_x,source_y,dest_x,dest_y,width,height);
return 0;
}
//------------------------------------------------------------------------------------------
//void masked_blit(BITMAP *source, BITMAP *dest, int source_x, int source_y,
// int dest_x, int dest_y, int width, int height);
static int l_masked_blit(lua_State *L)
{
prepare_blit();
masked_blit(source,dest,source_x,source_y,dest_x,dest_y,width,height);
return 0;
}
//------------------------------------------------------------------------------------------
//void stretch_blit(BITMAP *source, BITMAP *dest, int source_x, source_y,
// source_width, source_height, int dest_x, dest_y, dest_width, dest_height);
static int l_stretch_blit(lua_State *L)
{
AUD* au_source = (AUD*) lua_touserdata (L,1);
AUD* au_dest = (AUD*) lua_touserdata (L,2);
BITMAP* source;
BITMAP* dest;
int source_x = lua_tonumber(L,3);
int source_y = lua_tonumber(L,4);
int source_width = lua_tonumber(L,5);
int source_height = lua_tonumber(L,6);
int dest_x = lua_tonumber(L,7);
int dest_y = lua_tonumber(L,8);
int dest_width = lua_tonumber(L,9);
int dest_height = lua_tonumber(L,10);
if (au_source && au_source->DataType==AL_BITMAP) source = (BITMAP*) au_source->DataPtr;
else source = screen;
if (au_dest && au_dest->DataType ==AL_BITMAP) dest = (BITMAP*) au_dest->DataPtr;
else dest = screen;
stretch_blit(source,dest,source_x,source_y,source_width,source_height,
dest_x, dest_y, dest_width, dest_height);
return 0;
}
//------------------------------------------------------------------------------------------
//void masked_stretch_blit(BITMAP *source, BITMAP *dest, int source_x, source_y,
// source_w, source_h, int dest_x, dest_y, dest_w, dest_h);
static int l_masked_stretch_blit(lua_State *L)
{
AUD* au_source = (AUD*) lua_touserdata (L,1);
AUD* au_dest = (AUD*) lua_touserdata (L,2);
BITMAP* source;
BITMAP* dest;
int source_x = lua_tonumber(L,3);
int source_y = lua_tonumber(L,4);
int source_width = lua_tonumber(L,5);
int source_height = lua_tonumber(L,6);
int dest_x = lua_tonumber(L,7);
int dest_y = lua_tonumber(L,8);
int dest_width = lua_tonumber(L,9);
int dest_height = lua_tonumber(L,10);
if (au_source && au_source->DataType==AL_BITMAP) source = (BITMAP*) au_source->DataPtr;
else source = screen;
if (au_dest && au_dest->DataType ==AL_BITMAP) dest = (BITMAP*) au_dest->DataPtr;
else dest = screen;
masked_stretch_blit(source,dest,source_x,source_y,source_width,source_height,
dest_x, dest_y, dest_width, dest_height);
return 0;
}
//------------------------------------------------------------------------------------------
#define draw_sprite_init()\
AUD* au_source = (AUD*) lua_touserdata (L,1);\
AUD* au_dest = (AUD*) lua_touserdata (L,2);\
BITMAP* source;\
BITMAP* dest;\
int x = lua_tonumber(L,3);\
int y = lua_tonumber(L,4);\
if (au_source && au_source->DataType==AL_BITMAP) source = (BITMAP*) au_source->DataPtr;\
else source = screen;\
if (au_dest && au_dest->DataType ==AL_BITMAP) dest = (BITMAP*) au_dest->DataPtr;\
else dest = screen;
//------------------------------------------------------------------------------------------
//void draw_sprite(BITMAP *bmp, BITMAP *sprite, int x, int y);
static int l_draw_sprite(lua_State *L)
{
draw_sprite_init();
draw_sprite(source,dest,x,y);
return 0;
}
//------------------------------------------------------------------------------------------
//void stretch_sprite(BITMAP *bmp, BITMAP *sprite, int x, int y, int w, int h);
static int l_stretch_sprite(lua_State *L)
{
int w= lua_tonumber(L,5);
int h= lua_tonumber(L,5);
draw_sprite_init();
stretch_sprite(source,dest,x,y,w,h);
return 0;
}
//------------------------------------------------------------------------------------------
//void draw_trans_sprite(BITMAP *bmp, BITMAP *sprite, int x, int y);
static int l_draw_trans_sprite(lua_State *L)
{
draw_sprite_init();
draw_trans_sprite(source,dest,x,y);
return 0;
}
//void draw_lit_sprite(BITMAP *bmp, BITMAP *sprite, int x, int y, int color);
static int l_draw_lit_sprite(lua_State *L)
{
int color= lua_tonumber(L,5);
draw_sprite_init();
draw_lit_sprite(source,dest,x,y,color);
return 0;
}
//------------------------------------------------------------------------------------------
//void draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int x, int y,
// int c1, int c2, int c3, int c4);
static int l_draw_gouraud_sprite(lua_State *L)
{
int c1= lua_tonumber(L,5);
int c2= lua_tonumber(L,6);
int c3= lua_tonumber(L,7);
int c4= lua_tonumber(L,8);
draw_sprite_init();
draw_gouraud_sprite(source,dest,x,y,c1,c2,c3,c4);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -