aboutsummaryrefslogtreecommitdiffstats
path: root/us_maker_edition/src/lua/ULuaTextGL.pas
blob: 2e70a2c16e84131854f9eaf257055cd16fbb28b2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
{* UltraStar Deluxe - Karaoke Game
 *
 * UltraStar Deluxe is the legal property of its developers, whose names
 * are too numerous to list here. Please refer to the COPYRIGHT
 * file distributed with this source distribution.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; see the file COPYING. If not, write to
 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
 *
 * $URL$
 * $Id$
 *}

unit ULuaTextGL;

interface

{$IFDEF FPC}
  {$MODE Delphi}
{$ENDIF}

{$I switches.inc}

uses
  TextGL,
  SysUtils,
  ULua;

{ TextGl.Pos(X, Y: Float) : sets font position }
function ULuaTextGL_Pos(L: Plua_State): Integer; cdecl;

{ TextGl.Size(Size: Float) : sets font size }
function ULuaTextGL_Size(L: Plua_State): Integer; cdecl;

{ TextGl.Style(Style: int) : sets font style (from 0 to 3) }
function ULuaTextGL_Style(L: Plua_State): Integer; cdecl;

{ TextGl.Italic(isItalic: boolean) : sets if font is italic }
function ULuaTextGL_Italic(L: Plua_State): Integer; cdecl;

{ TextGl.Width(Text: String) : returns width of Text if printed
  w/ current settings in pixels }
function ULuaTextGL_Width(L: Plua_State): Integer; cdecl;

{ TextGl.Print(Text: String) : prints text to screen w/ current
  settings}
function ULuaTextGL_Print(L: Plua_State): Integer; cdecl;

const
  ULuaTextGl_Lib_f: array [0..5] of lual_reg = (
    (name:'Pos'; func:ULuaTextGl_Pos),
    (name:'Size'; func:ULuaTextGl_Size),
    (name:'Style'; func:ULuaTextGl_Style),
    (name:'Italic'; func:ULuaTextGl_Italic),
    (name:'Width'; func:ULuaTextGl_Width),
    (name:'Print'; func:ULuaTextGl_Print)
  );


implementation

{ TextGl.Pos(X, Y: Float) : sets font position }
function ULuaTextGL_Pos(L: Plua_State): Integer; cdecl;
  var X, Y: Double;
begin
  X := luaL_checknumber(L, 1);
  Y := luaL_checknumber(L, 2);

  SetFontPos(X, Y);

  Result := 0;
end;

{ TextGl.Size(Size: Float) : sets font size }
function ULuaTextGL_Size(L: Plua_State): Integer; cdecl;
  var Size: Double;
begin
  Size := luaL_checknumber(L, 1);

  SetFontSize(Size);
  
  Result := 0;
end;

{ TextGl.Style(Style: int) : sets font style (from 0 to 3) }
function ULuaTextGL_Style(L: Plua_State): Integer; cdecl;
  var Style: Integer;
begin
  Style := luaL_checkinteger(L, 1);

  if (Style >= 0) and (Style < Length(Fonts)) then
    SetFontStyle(Style)
  else
    luaL_ArgError(L, 1, PChar('number from 0 to ' + IntToStr(High(Fonts)) + ' expected'));

  Result := 0;
end;

{ TextGl.Italic(isItalic: boolean) : sets if font is italic }
function ULuaTextGL_Italic(L: Plua_State): Integer; cdecl;
  var isItalic: Boolean;
begin
  luaL_checkany(L, 1);
  isItalic := lua_toBoolean(L, 1);

  SetFontItalic(isItalic);
  
  Result := 0;
end;

{ TextGl.Width(Text: String) : returns width of Text if printed
  w/ current settings in pixels }
function ULuaTextGL_Width(L: Plua_State): Integer; cdecl;
  var Text: String;
begin
  Text := luaL_checkstring(L, 1);
  lua_pop(L, lua_gettop(L));

  lua_PushNumber(L, glTextWidth(Text));

  Result := 1;
end;

{ TextGl.Print(Text: String) : prints text to screen w/ current
  settings}
function ULuaTextGL_Print(L: Plua_State): Integer; cdecl;
  var Text: String;
begin
  Text := luaL_checkstring(L, 1);

  glPrint(Text);

  Result := 0;
end;

end.