⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lua_bmp.c

📁 lua脚本语言调用allegro游戏程序库的接口-跨平台
💻 C
📖 第 1 页 / 共 2 页
字号:
/****************************************************************************
**                                                                         **
**                  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_bmp.h"

//#define ALLEGRO_META "allegro_meta"

#define return_bitmap()\
   if (bmp==NULL)\
      {\
      lua_pushnil(L);\
      return 1;\
      }\
   else\
      {\
      ad= (AUD*) lua_newuserdata (L, sizeof(AUD));\
      if (!ad)\
      {destroy_bitmap(bmp);return 0;}\
      luaL_getmetatable(L,"allegro_meta");\
      lua_setmetatable(L,-2);\
      ad->DataType=AL_BITMAP;\
      ad->DataPtr=bmp;\
      return 1;}


//------------------------------------------------------------------------------------------
//BITMAP *create_bitmap(int width, int height);
//------------------------------------------------------------------------------------------
static int l_create_bitmap(lua_State *L)
{
   int width   = min(max(1,lua_tonumber(L,1)),10000);
   int height  = min(max(1,lua_tonumber(L,2)),10000);

   BITMAP*          bmp = create_bitmap(width,height);
   AUD* ad;
   return_bitmap();
}

//------------------------------------------------------------------------------------------
//BITMAP *create_bitmap_ex(int color_depth, int width, int height);
//------------------------------------------------------------------------------------------
static int l_create_bitmap_ex(lua_State *L)
{
   int color_depth  = lua_tonumber(L,1);
   int width        = min(max(1,lua_tonumber(L,2)),10000);
   int height       = min(max(1,lua_tonumber(L,3)),10000);

   BITMAP*      bmp = create_bitmap_ex(color_depth,width,height);
   AUD* ad;
   return_bitmap();
}

//------------------------------------------------------------------------------------------
//BITMAP *create_system_bitmap(int width, int height);
//------------------------------------------------------------------------------------------
static int l_create_system_bitmap(lua_State *L)
{
   int width   = min(max(1,lua_tonumber(L,1)),10000);
   int height  = min(max(1,lua_tonumber(L,2)),10000);

   BITMAP*          bmp = create_system_bitmap(width,height);
   AUD* ad;
   return_bitmap();
}

//------------------------------------------------------------------------------------------
//BITMAP *create_video_bitmap(int width, int height);
//------------------------------------------------------------------------------------------
static int l_create_video_bitmap(lua_State *L)
{
   int width   = min(max(1,lua_tonumber(L,1)),10000);
   int height  = min(max(1,lua_tonumber(L,2)),10000);

   BITMAP*          bmp = create_video_bitmap(width,height);
   AUD* ad;
   return_bitmap();
}

//---------------------------------------------------------------------------------------------
#define get_bitmap_userdata()\
   AUD*    au_bitmap = (AUD*) lua_touserdata (L,1);\
   BITMAP* bitmap;\
   if (au_bitmap && au_bitmap->DataType==AL_BITMAP) bitmap = (BITMAP*) au_bitmap->DataPtr;\
                                               else bitmap = screen;

//------------------------------------------------------------------------------------------
//BITMAP *create_sub_bitmap(BITMAP *parent, int x, y, width, height);
//------------------------------------------------------------------------------------------
static int l_create_sub_bitmap(lua_State *L)
{
   BITMAP*     bmp;   
   AUD*        ad;

   int x       = min(max(1,lua_tonumber(L,2)),10000);
   int y       = min(max(1,lua_tonumber(L,3)),10000);
   int width   = min(max(1,lua_tonumber(L,4)),10000);
   int height  = min(max(1,lua_tonumber(L,5)),10000);
   get_bitmap_userdata();

   bmp = create_sub_bitmap(bitmap,x,y,width,height);
   return_bitmap();
}


//---------------------------------------------------------------------------------------------
//void acquire_bitmap(BITMAP *bmp);
static int l_acquire_bitmap(lua_State *L)
{
   get_bitmap_userdata();
   acquire_bitmap(bitmap);
return 0;
}
//---------------------------------------------------------------------------------------------
//void release_bitmap(BITMAP *bmp);
static int l_release_bitmap(lua_State *L)
{
   get_bitmap_userdata();
   release_bitmap(bitmap);
return 0;
}

//---------------------------------------------------------------------------------------------
//void acquire_screen();
static int l_acquire_screen(lua_State *L)
{
   acquire_screen();
return 0;
}

//---------------------------------------------------------------------------------------------
//void release_screen();
static int l_release_screen(lua_State *L)
{
   release_screen();
return 0;
}

//---------------------------------------------------------------------------------------------
//void get_clip_rect(BITMAP *bitmap, int *x1, int *y1, int *x2, int *y2);
static int l_get_clip_rect(lua_State *L)
{
   int x1,y1,x2,y2;
   get_bitmap_userdata();

   get_clip_rect(bitmap,&x1,&y1,&x2,&y2);
   lua_pushnumber(L,x1);
   lua_pushnumber(L,y1);
   lua_pushnumber(L,x2);
   lua_pushnumber(L,y2);
return 4;
}


//---------------------------------------------------------------------------------------------
//bool get_clip_state(BITMAP *bitmap)
static int l_get_clip_state(lua_State *L)
{
   get_bitmap_userdata();
   lua_pushboolean(L,get_clip_state(bitmap));
return 1;
}


//------------------------------------------------------------------------------------------
//void set_clip_rect(BITMAP *bitmap, int x1, int y1, int x2, int y2);
//------------------------------------------------------------------------------------------
static int l_set_clip_rect(lua_State *L)
{
   int x1       = lua_tonumber(L,2);
   int y1       = lua_tonumber(L,3);
   int x2       = lua_tonumber(L,4);
   int y2       = lua_tonumber(L,5);
   get_bitmap_userdata();
   set_clip_rect(bitmap,x1,y1,x2,y2);   
   return 0;
}

//------------------------------------------------------------------------------------------
//void add_clip_rect(BITMAP *bitmap, int x1, int y1, int x2, int y2);
//------------------------------------------------------------------------------------------
static int l_add_clip_rect(lua_State *L)
{
   int x1       = lua_tonumber(L,2);
   int y1       = lua_tonumber(L,3);
   int x2       = lua_tonumber(L,4);
   int y2       = lua_tonumber(L,5);
   get_bitmap_userdata();
   add_clip_rect(bitmap,x1,y1,x2,y2);   
   return 0;
}

//------------------------------------------------------------------------------------------
//void set_clip_state(BITMAP *bitmap, int state)
//------------------------------------------------------------------------------------------
static int l_set_clip_state(lua_State *L)
{
   int state    = lua_toboolean(L,2);
   get_bitmap_userdata();
   set_clip_state(bitmap,state);   
   return 0;
}

//---------------------------------------------------------------------------------------------
//int bitmap_color_depth(BITMAP *bmp);
//---------------------------------------------------------------------------------------------
static int l_bitmap_color_depth(lua_State *L)
{

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -