📄 lua_mode.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_mode.h"
//------------------------------------------------------------------------------------------
#define set_field_i(L,key,intvalue){\
lua_pushstring(L,key);\
lua_pushnumber(L,intvalue);\
lua_settable(L,-3);}
//------------------------------------------------------------------------------------------
#define set_field_n(L,indx,intvalue){\
lua_pushnumber(L,indx);\
lua_pushnumber(L,intvalue);\
lua_settable(L,-3);}
//------------------------------------------------------------------------------------------
//----- Allegro chapter "Graphics modes" --------------------------------------------------
//------------------------------------------------------------------------------------------
//int get_screen_width(void);
static int l_get_screen_width (lua_State *L)
{
int screen_width = SCREEN_W;
lua_pushnumber (L, screen_width );
return 1; /* number of results */
}
//------------------------------------------------------------------------------------------
//int get_screen_height(void);
static int l_get_screen_height (lua_State *L)
{
int screen_height = SCREEN_H;
lua_pushnumber (L, screen_height );
return 1; /* number of results */
}
//------------------------------------------------------------------------------------------
//int get_color_depth(void);
static int l_get_color_depth (lua_State *L)
{
int color_depth=bitmap_color_depth(screen);
lua_pushnumber (L, color_depth);
return 1; /* number of results */
}
//------------------------------------------------------------------------------------------
//int get_refresh_rate(void);
static int l_get_refresh_rate (lua_State *L)
{
lua_pushnumber (L, get_refresh_rate());
return 1; /* number of results */
}
//------------------------------------------------------------------------------------------
//void request_refresh_rate(int rate);
static int l_request_refresh_rate (lua_State *L)
{
int refresh_rate = (int) lua_tonumber(L,1);
if ((refresh_rate<0) || (refresh_rate>150))
refresh_rate=0;
request_refresh_rate(refresh_rate);
return 0; /* number of results */
}
//------------------------------------------------------------------------------------------
//void set_color_depth(int depth);
static int l_set_color_depth (lua_State *L)
{
int depth=lua_tonumber(L,1);
if ((depth!=8) && (depth!=15) && (depth!=16) && (depth!=24) && (depth!=32)) depth=8;
set_color_depth(depth);
return 0; /* number of results */
}
//------------------------------------------------------------------------------------------
//bool set_gfx_mode(int card, int w, int h, int v_w, int v_h);
static int l_set_gfx_mode(lua_State* L)
{
int card = lua_tonumber(L,1);
int w = lua_tonumber(L,2);
int h = lua_tonumber(L,3);
int v_w = lua_tonumber(L,4);
int v_h = lua_tonumber(L,5);
int result;
result=set_gfx_mode(card,w,h,v_w,v_h);
lua_pushboolean (L, !(result));
return 1;
}
//------------------------------------------------------------------------------------------
//bool scroll_screen(int x, int y);
static int l_scroll_screen(lua_State* L)
{
int x = lua_tonumber(L,1);
int y = lua_tonumber(L,2);
int result;
result = scroll_screen(x,y);
lua_pushboolean (L, !(result));
return 1;
}
//------------------------------------------------------------------------------------------
//bool request_scroll(int x, int y);
static int l_request_scroll(lua_State* L)
{
int x = lua_tonumber(L,1);
int y = lua_tonumber(L,2);
int result;
result = request_scroll(x,y);
lua_pushboolean (L, !(result));
return 1;
}
//------------------------------------------------------------------------------------------
//bool poll_scroll();
static int l_poll_scroll(lua_State* L)
{
lua_pushboolean (L, poll_scroll());
return 1;
}
//------------------------------------------------------------------------------------------
//int show_video_bitmap(BITMAP *bitmap);
static int l_show_video_bitmap(lua_State* L)
{
AUD* ad = lua_touserdata(L,1);
if (!(ad) || (ad->DataType!=AL_BITMAP) || !(ad->DataPtr))
{
show_video_bitmap(screen);
lua_pushboolean (L,0);
return 1;
}
else
{
lua_pushboolean (L,!show_video_bitmap( (BITMAP*) ad->DataPtr));
return 1;
}
}
//------------------------------------------------------------------------------------------
//int request_video_bitmap(BITMAP *bitmap);
static int l_request_video_bitmap(lua_State* L)
{
AUD* ad = lua_touserdata(L,1);
if (!(ad) || (ad->DataType!=AL_BITMAP) || !(ad->DataPtr))
{
request_video_bitmap(screen);
lua_pushboolean (L,0);
return 1;
}
else
{
lua_pushboolean (L,!(request_video_bitmap( (BITMAP*) ad->DataPtr)));
return 1;
}
}
//------------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------------
//int is_windowed_mode(void);
static int l_is_windowed_mode(lua_State* L)
{
int result = is_windowed_mode();
lua_pushnumber (L, result);
return 1;
}
//------------------------------------------------------------------------------------------
//bool set_display_switch_mode(int mode);
static int l_set_display_switch_mode(lua_State* L)
{
int result = set_display_switch_mode((int) lua_tonumber(L,1));
lua_pushboolean (L, !result);
return 1;
}
//------------------------------------------------------------------------------------------
//void vsync();
static int l_vsync(lua_State* L)
{
vsync();
return 0;
}
//------------------------------------------------------------------------------------------
//int gfx_capabilities()
static int l_gfx_capabilities(lua_State* L)
{
lua_pushnumber (L, gfx_capabilities);
return 1;
}
//------------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------------
static struct
{
int value;
char* key;
} al_const[]={
{ SWITCH_NONE, "SWITCH_NONE" },
{ SWITCH_PAUSE, "SWITCH_PAUSE" },
{ SWITCH_AMNESIA, "SWITCH_AMNESIA" },
{ SWITCH_BACKGROUND, "SWITCH_BACKGROUND" },
{ SWITCH_BACKAMNESIA, "SWITCH_BACKAMNESIA" },
{ GFX_TEXT, "GFX_TEXT" },
{ GFX_AUTODETECT, "GFX_AUTODETECT" },
{ GFX_AUTODETECT_FULLSCREEN, "GFX_AUTODETECT_FULLSCREEN"},
{ GFX_AUTODETECT_WINDOWED, "GFX_AUTODETECT_WINDOWED" },
{ GFX_SAFE, "GFX_SAFE" },
{ AL_ID('V','G','A',' '), "GFX_VGA" },
{ AL_ID('M','O','D','X'), "GFX_MODEX" },
{ AL_ID('V','B','E','1'), "GFX_VESA1" },
{ AL_ID('V','B','2','B'), "GFX_VESA2B" },
{ AL_ID('V','B','2','L'), "GFX_VESA2L" },
{ AL_ID('V','B','E','3'), "GFX_VESA3" },
{ AL_ID('V','B','A','F'), "GFX_VBEAF" },
{ AL_ID('X','T','N','D'), "GFX_XTENDED" },
{ AL_ID('D','X','A','C'), "GFX_DIRECTX" },
{ AL_ID('D','X','A','C'), "GFX_DIRECTX_ACCEL" },
{ AL_ID('D','X','S','A'), "GFX_DIRECTX_SAFE" },
{ AL_ID('D','X','S','O'), "GFX_DIRECTX_SOFT" },
{ AL_ID('D','X','W','N'), "GFX_DIRECTX_WIN" },
{ AL_ID('D','X','O','V'), "GFX_DIRECTX_OVL" },
{ AL_ID('G','D','I','B'), "GFX_GDI" },
{ AL_ID('Q','P','H',' '), "GFX_PHOTON" },
{ AL_ID('Q','P','H','D'), "GFX_PHOTON_DIRECT" },
{ AL_ID('B','F','S',' '), "GFX_DRIVER_BEOS" },
{ AL_ID('B','F','S',' '), "GFX_BEOS_FULLSCREEN" },
{ AL_ID('B','F','S','S'), "GFX_BEOS_FULLSCREEN_SAFE" },
{ AL_ID('B','W','N',' '), "GFX_BEOS_WINDOWED" },
{ AL_ID('B','W','N','S'), "GFX_BEOS_WINDOWED_SAFE" },
{ AL_ID('F','B',' ',' '), "GFX_FBCON" },
{ AL_ID('S','V','G','A'), "GFX_SVGALIB" },
{ AL_ID('X','W','I','N'), "GFX_XWINDOWS" },
{ AL_ID('X','W','F','S'), "GFX_XWINDOWS_FULLSCREEN" },
{ 0 , NULL }};
//------------------------------------------------------------------------------------------
//GFX_MODE_LIST* get_gfx_mode_list(int card);
static int l_get_gfx_mode_list (lua_State *L)
{
int card=lua_tonumber(L,1);
int i=0;
GFX_MODE_LIST* list;
//char* param1;
/*if (lua_isstring(L,1))
{
param1=(char*) lua_tostring (L,1);
}
else*/
card=lua_tonumber(L,1);
list=get_gfx_mode_list(card);
if (!list) return 0;
lua_newtable (L);
while ( (list->mode[i].width) && (list->mode[i].height) && (list->mode[i].bpp) )
{
//new_record:
lua_pushnumber(L, i+1 );
lua_newtable(L);
set_field_i(L, "width" , list->mode[i].width );
set_field_i(L, "height" , list->mode[i].height );
set_field_i(L, "bpp" , list->mode[i].bpp );
//store_record:
lua_settable(L, -3);
i++;
}
destroy_gfx_mode_list(list);
return 1; /* number of results */
}
//---------------------------------------------------------------------------------------------
static const struct luaL_reg allegro_mode_lib [] = {
{"get_screen_width", l_get_screen_width},
{"get_screen_height", l_get_screen_height},
{"get_color_depth", l_get_color_depth},
{"set_color_depth", l_set_color_depth},
{"get_refresh_rate", l_get_refresh_rate},
{"request_refresh_rate", l_request_refresh_rate},
{"get_gfx_mode_list", l_get_gfx_mode_list},
{"set_gfx_mode", l_set_gfx_mode},
{"scroll_screen", l_scroll_screen},
{"request_scroll", l_request_scroll},
{"poll_scroll", l_poll_scroll},
{"show_video_bitmap", l_show_video_bitmap},
{"request_video_bitmap", l_request_video_bitmap},
{"is_windowed_mode", l_is_windowed_mode},
{"set_display_switch_mode", l_set_display_switch_mode},
{"vsync", l_vsync},
{"gfx_capabilities", l_gfx_capabilities},
{NULL, NULL} /* sentinel */
};
//-----------------------------------------------------------------------------------------------
int luaopen_allegro_mode(lua_State *L)
{
int i=0;
luaL_openlib(L, "allegro", allegro_mode_lib, 0);
//zarejestruj sta砮 allegro
lua_getglobal(L, "allegro");
while(al_const[i].key!=NULL)
{setfield(L,al_const[i].key,al_const[i].value);i++;}
lua_pop(L,1);
return 1;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -