Skip to content

Commit 2ce4bdd

Browse files
authored
get font scale options for lua (#6876)
1 parent bbb838a commit 2ce4bdd

File tree

1 file changed

+28
-10
lines changed

1 file changed

+28
-10
lines changed

code/scripting/api/objs/font.cpp

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ bool font_h::isValid() const {
3636

3737
ADE_OBJ(l_Font, font_h, "font", "font handle");
3838

39-
ADE_FUNC(__tostring, l_Font, NULL, "Name of font", "string", "Font filename, or an empty string if the handle is invalid")
39+
ADE_FUNC(__tostring, l_Font, nullptr, "Name of font", "string", "Font filename, or an empty string if the handle is invalid")
4040
{
41-
font_h *fh = NULL;
41+
font_h* fh = nullptr;
4242
if (!ade_get_args(L, "o", l_Font.GetPtr(&fh)))
4343
return ade_set_error(L, "s", "");
4444

@@ -60,9 +60,9 @@ ADE_FUNC(__eq, l_Font, "font, font", "Checks if the two fonts are equal", "boole
6060
return ade_set_args(L, "b", fh1->Get()->getName() == fh2->Get()->getName());
6161
}
6262

63-
ADE_VIRTVAR(Filename, l_Font, "string", "Name of font (including extension)<br><b>Important:</b>This variable is deprecated. Use <i>Name</i> instead.", "string", NULL)
63+
ADE_VIRTVAR(Filename, l_Font, "string", "Name of font (including extension)<br><b>Important:</b>This variable is deprecated. Use <i>Name</i> instead.", "string", nullptr)
6464
{
65-
font_h *fh = NULL;
65+
font_h* fh = nullptr;
6666
const char* newname = nullptr;
6767
if (!ade_get_args(L, "o|s", l_Font.GetPtr(&fh), &newname))
6868
return ade_set_error(L, "s", "");
@@ -78,9 +78,9 @@ ADE_VIRTVAR(Filename, l_Font, "string", "Name of font (including extension)<br><
7878
return ade_set_args(L, "s", fh->Get()->getName().c_str());
7979
}
8080

81-
ADE_VIRTVAR(Name, l_Font, "string", "Name of font (including extension)", "string", NULL)
81+
ADE_VIRTVAR(Name, l_Font, "string", "Name of font (including extension)", "string", nullptr)
8282
{
83-
font_h *fh = NULL;
83+
font_h* fh = nullptr;
8484
const char* newname = nullptr;
8585
if (!ade_get_args(L, "o|s", l_Font.GetPtr(&fh), &newname))
8686
return ade_set_error(L, "s", "");
@@ -116,7 +116,7 @@ ADE_VIRTVAR(FamilyName, l_Font, "string", "Family Name of font. Bitmap fonts alw
116116

117117
ADE_VIRTVAR(Height, l_Font, "number", "Height of font (in pixels)", "number", "Font height, or 0 if the handle is invalid")
118118
{
119-
font_h *fh = NULL;
119+
font_h* fh = nullptr;
120120
int newheight = -1;
121121
if (!ade_get_args(L, "o|i", l_Font.GetPtr(&fh), &newheight))
122122
return ade_set_error(L, "i", 0);
@@ -134,7 +134,7 @@ ADE_VIRTVAR(Height, l_Font, "number", "Height of font (in pixels)", "number", "F
134134

135135
ADE_VIRTVAR(TopOffset, l_Font, "number", "The offset this font has from the baseline of textdrawing downwards. (in pixels)", "number", "Font top offset, or 0 if the handle is invalid")
136136
{
137-
font_h *fh = NULL;
137+
font_h* fh = nullptr;
138138
float newOffset = -1;
139139
if (!ade_get_args(L, "o|f", l_Font.GetPtr(&fh), &newOffset))
140140
return ade_set_error(L, "f", 0.0f);
@@ -152,7 +152,7 @@ ADE_VIRTVAR(TopOffset, l_Font, "number", "The offset this font has from the base
152152

153153
ADE_VIRTVAR(BottomOffset, l_Font, "number", "The space (in pixels) this font skips downwards after drawing a line of text", "number", "Font bottom offset, or 0 if the handle is invalid")
154154
{
155-
font_h *fh = NULL;
155+
font_h* fh = nullptr;
156156
float newOffset = -1;
157157
if (!ade_get_args(L, "o|f", l_Font.GetPtr(&fh), &newOffset))
158158
return ade_set_error(L, "f", 0.0f);
@@ -168,7 +168,25 @@ ADE_VIRTVAR(BottomOffset, l_Font, "number", "The space (in pixels) this font ski
168168
return ade_set_args(L, "f", fh->Get()->getBottomOffset());
169169
}
170170

171-
ADE_FUNC(isValid, l_Font, NULL, "True if valid, false or nil if not", "boolean", "Detects whether handle is valid")
171+
ADE_FUNC(hasAutoSize, l_Font, nullptr, "True if FSO will auto size this font, false or nil if not", "boolean", "Detects whether the font has Auto Size activated")
172+
{
173+
font_h* fh = nullptr;
174+
if (!ade_get_args(L, "o", l_Font.GetPtr(&fh)))
175+
return ADE_RETURN_NIL;
176+
177+
return ade_set_args(L, "b", fh != nullptr && fh->Get()->getAutoScaleBehavior());
178+
}
179+
180+
ADE_FUNC(hasCanScale, l_Font, nullptr, "True if this font is allowed to scale based on user settings, false or nil if not", "boolean", "Detects whether the font can scale")
181+
{
182+
font_h* fh = nullptr;
183+
if (!ade_get_args(L, "o", l_Font.GetPtr(&fh)))
184+
return ADE_RETURN_NIL;
185+
186+
return ade_set_args(L, "b", fh != nullptr && fh->Get()->getScaleBehavior());
187+
}
188+
189+
ADE_FUNC(isValid, l_Font, nullptr, "True if valid, false or nil if not", "boolean", "Detects whether handle is valid")
172190
{
173191
font_h *fh = nullptr;
174192
if (!ade_get_args(L, "o", l_Font.GetPtr(&fh)))

0 commit comments

Comments
 (0)