📄 lua_text.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_text.h"
//------------------------------------------------------------------------------------------
//--- Text output functions ----------------------------------------------------------------
//------------------------------------------------------------------------------------------
//deprecated int text_mode(int mode);
/*static int l_text_mode(lua_State* L)
{
int mode= lua_tonumber(L,1);
lua_pushnumber(L,text_mode(mode));
return 1;
}*/
//------------------------------------------------------------------------------------------
//int text_length(const FONT *f, const char *str);
static int l_text_length(lua_State* L)
{
AUD* ad = (AUD*) lua_touserdata(L,1);
char* str = (char*) lua_tostring(L,2);
if (!(ad) || (ad->DataType!=AL_FONT) || !(ad->DataPtr))
lua_pushnumber(L,text_length(font,str));
else
lua_pushnumber(L,text_length((FONT*) ad->DataPtr,str));
return 1;
}
//------------------------------------------------------------------------------------------
//int text_height(const FONT *f)
static int l_text_height(lua_State* L)
{
AUD* ad = lua_touserdata(L,1);
if (!(ad) || (ad->DataType!=AL_FONT) || !(ad->DataPtr))
lua_pushnumber(L,text_height(font));
else
lua_pushnumber(L,text_height( (FONT*) ad->DataPtr ));
return 1;
}
//------------------------------------------------------------------------------------------
//void textout(BITMAP *bmp, const FONT *f, const char *s, int x, y, int color, int bg);
static int l_textout(lua_State* L)
{
int i , x , y , color, bg;
char* s;
AUD* au_bitmap;
BITMAP* dest;
AUD* fd;
FONT* f;
get_first_param(au_bitmap,dest,i);
fd=lua_touserdata (L,++i);
if ((fd) && (fd->DataType==AL_FONT) && (fd->DataPtr))
f= (FONT*) fd->DataPtr;
else
f= font;
s=(char*) lua_tostring(L,++i); if (!s) return 0;
get_param(x);
get_param(y);
get_param_def(color,-1);
get_param_def(bg,-1);
textout_ex(dest,f,s,x,y,color,bg);
return 0;
}
//------------------------------------------------------------------------------------------
//void textout_centre(BITMAP *bmp, const FONT *f, const char *s, int x, y, color);
static int l_textout_centre(lua_State* L)
{
int i , x , y , color,bg;
char* s;
AUD* au_bitmap;
BITMAP* dest;
AUD* fd;
FONT* f;
get_first_param(au_bitmap,dest,i);
fd=lua_touserdata (L,++i);
if ((fd) && (fd->DataType==AL_FONT) && (fd->DataPtr))
f= (FONT*) fd->DataPtr;
else
f= font;
s=(char*) lua_tostring(L,++i); if (!s) return 0;
get_param(x);
get_param(y);
get_param_def(color,-1);
get_param_def(bg,-1);
textout_centre_ex(dest,f,s,x,y,color,bg);
return 0;
}
//------------------------------------------------------------------------------------------
//void textout_right(BITMAP *bmp, const FONT *f, const char *s, int x, y, color);
static int l_textout_right(lua_State* L)
{
int i , x , y , color,bg;
char* s;
AUD* au_bitmap;
BITMAP* dest;
AUD* fd;
FONT* f;
get_first_param(au_bitmap,dest,i);
fd=lua_touserdata (L,++i);
if ((fd) && (fd->DataType==AL_FONT) && (fd->DataPtr))
f= (FONT*) fd->DataPtr;
else
f= font;
s=(char*) lua_tostring(L,++i); if (!s) return 0;
get_param(x);
get_param(y);
get_param_def(color,-1);
get_param_def(bg,-1);
textout_right_ex(dest,f,s,x,y,color,bg);
return 0;
}
//------------------------------------------------------------------------------------------
//void textout_justify(BITMAP *bmp,FONT *f,char *s,int x1,int x2,int y,int diff,int color);
static int l_textout_justify(lua_State* L)
{
int i , x1 , x2 , y , diff , color, bg;
char* s;
AUD* au_bitmap;
BITMAP* dest;
AUD* fd;
FONT* f;
get_first_param(au_bitmap,dest,i);
fd=lua_touserdata (L,++i);
if ((fd) && (fd->DataType==AL_FONT) && (fd->DataPtr))
f= (FONT*) fd->DataPtr;
else
f= font;
s=(char*) lua_tostring(L,++i); if (!s) return 0;
get_param(x1);
get_param(x2);
get_param(y);
get_param_def(diff,10000);
get_param_def(color,-1);
get_param_def(bg,-1);
textout_justify_ex(dest,f,s,x1,x2,y,diff,color,bg);
return 0;
}
//---------------------------------------------------------------------------------------------
static const struct luaL_reg allegro_text_lib [] = {
//deprecated {"text_mode", l_text_mode},
{"text_length", l_text_length},
{"text_height", l_text_height},
{"textout", l_textout},
{"textout_right", l_textout_right},
{"textout_centre", l_textout_centre},
{"textout_justify", l_textout_justify},
{NULL, NULL} /* sentinel */
};
//-----------------------------------------------------------------------------------------------
int luaopen_allegro_text(lua_State *L)
{
luaL_openlib(L, "allegro", allegro_text_lib, 0);
return 1;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -