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

📄 lua_maus.c

📁 lua脚本语言调用allegro游戏程序库的接口-跨平台
💻 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 "lua_aleg.h"
#include "lua_maus.h"


//---------------------------------------------------------------------------------------------
//------ Mouse routines -----------------------------------------------------------------------
//---------------------------------------------------------------------------------------------

//---------------------------------------------------------------------------------------------
//bool mouse.install()
static int l_install_mouse(lua_State* L)
{
lua_pushboolean(L, (install_mouse()>0) );
return 1;
}

//---------------------------------------------------------------------------------------------
//void mouse.remove()
static int l_remove_mouse(lua_State* L)
{
remove_mouse();
return 0;
}

//---------------------------------------------------------------------------------------------
//bool mouse.poll()
static int l_poll_mouse(lua_State* L)
{
lua_pushboolean(L,!poll_mouse());
return 1;
}

//---------------------------------------------------------------------------------------------
//bool mouse.needs_poll()
static int l_mouse_needs_poll(lua_State* L)
{
lua_pushboolean(L,mouse_needs_poll());
return 1;
}

//---------------------------------------------------------------------------------------------
static int l_mouse_position(lua_State* L)
{
lua_pushnumber(L,mouse_x);
lua_pushnumber(L,mouse_y);
lua_pushnumber(L,mouse_z);
lua_pushboolean(L,(mouse_b&1));
lua_pushboolean(L,(mouse_b&2));
lua_pushboolean(L,(mouse_b&4));
return 6;
}

//---------------------------------------------------------------------------------------------
// x,y= mouse.get_mickeys()
//void get_mouse_mickeys(int *mickeyx, int *mickeyy);
static int l_get_mouse_mickeys(lua_State* L)
{
int x,y;
get_mouse_mickeys(&x,&y);
lua_pushnumber(L,x);
lua_pushnumber(L,y);
return 2;
}

//---------------------------------------------------------------------------------------------
//void position_mouse(int x, int y);
//void position_mouse_z(int z);
static int l_mouse_set_position(lua_State* L)
{
int x,y;
if (lua_type(L,1)==LUA_TNUMBER)
   {
   x=lua_tonumber(L,1);
   y=lua_tonumber(L,2);
   position_mouse(x,y);
   }
if (lua_type(L,3)==LUA_TNUMBER)
   {
   position_mouse_z( (int) lua_tonumber(L,3));
   }
return 0;
}

//---------------------------------------------------------------------------------------------
//void set_mouse_range(int x1, int y1, int x2, int y2);
static int l_set_mouse_range(lua_State* L)
{
int x1 = lua_tonumber(L,1);
int y1 = lua_tonumber(L,2);
int x2 = lua_tonumber(L,3);
int y2 = lua_tonumber(L,4);
set_mouse_range(x1,y1,x2,y2);
return 0;
}

//---------------------------------------------------------------------------------------------
//void set_mouse_speed(int xspeed, int yspeed);
static int l_set_mouse_speed(lua_State* L)
{
int x = lua_tonumber(L,1);
int y = lua_tonumber(L,2);
   set_mouse_speed(x,y);
return 0;
}


//---------------------------------------------------------------------------------------------
//void show_mouse(BITMAP *bmp);
static int l_show_mouse(lua_State* L)
{
AUD* b = (AUD*) lua_touserdata(L,1);

if ((b) && (b->DataType==AL_BITMAP) && (b->DataPtr))
   show_mouse( (BITMAP*) b->DataPtr);
else
   show_mouse(screen);

return 0;
}

//---------------------------------------------------------------------------------------------
//void hide_mouse();
static int l_hide_mouse(lua_State* L)
{
show_mouse(NULL);
return 0;
}

//---------------------------------------------------------------------------------------------
//void scare_mouse();
static int l_scare_mouse(lua_State* L)
{
scare_mouse();
return 0;
}

//---------------------------------------------------------------------------------------------
//void unscare_mouse();
static int l_unscare_mouse(lua_State* L)
{
unscare_mouse();
return 0;
}


//---------------------------------------------------------------------------------------------
//void set_mouse_sprite(BITMAP *sprite);
static int l_set_mouse_sprite(lua_State* L)
{
AUD* b = (AUD*) lua_touserdata(L,1);

if ((b) && (b->DataType==AL_BITMAP) && (b->DataPtr))
   set_mouse_sprite( (BITMAP*) b->DataPtr);
else 
   set_mouse_sprite(NULL);

return 0;
}

//---------------------------------------------------------------------------------------------
//bool show_os_cursor(int cursor);
static int l_show_os_cursor(lua_State* L)
{
   int c=lua_tonumber(L,1);
   lua_pushboolean(L,!show_os_cursor(c));
   return 1;
}

//---------------------------------------------------------------------------------------------
//void select_mouse_cursor(int cursor);
static int l_select_mouse_cursor(lua_State* L)
{
   select_mouse_cursor( (int) lua_tonumber(L,1) );
   return 0;
}

//---------------------------------------------------------------------------------------------
//void enable_hardware_cursor(bool enable);
static int l_enable_hardware_cursor(lua_State* L)
{
   int enable=lua_toboolean(L,1);

   if (enable)
      enable_hardware_cursor();
   else
      disable_hardware_cursor();

   return 0;
}

//---------------------------------------------------------------------------------------------
static const struct luaL_reg mouse_lib [] = {
      {"position",               l_mouse_position},
      {"set_position",           l_mouse_set_position},
      {"set_speed",              l_set_mouse_speed},
      {"set_range",              l_set_mouse_range},
      {"install",                l_install_mouse},
      {"remove",                 l_remove_mouse},
      {"poll",                   l_poll_mouse},
      {"needs_poll",             l_mouse_needs_poll},
      {"get_mickeys",            l_get_mouse_mickeys},
      {"show",                   l_show_mouse},
      {"hide",                   l_hide_mouse},
      {"scare",                  l_scare_mouse},
      {"unscare",                l_unscare_mouse},
      {"set_sprite",             l_set_mouse_sprite},
      {"show_os_cursor",         l_show_os_cursor},
      {"enable_hardware_cursor", l_enable_hardware_cursor},
      {"select_cursor",          l_select_mouse_cursor},

      {NULL,                  NULL}  /* sentinel */
    };

//-----------------------------------------------------------------------------------------------
int luaopen_allegro_maus(lua_State *L) 
{
   luaL_openlib(L, "mouse",   mouse_lib,   0);
   return 1;
}

⌨️ 快捷键说明

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