Skip to content

Commit 78d6a4b

Browse files
authored
Ensure lua context is used for image drawing and string sizes (#6765)
1 parent 1180f87 commit 78d6a4b

3 files changed

Lines changed: 17 additions & 4 deletions

File tree

code/graphics/render.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ void gr_aabitmap(int x, int y, int resize_mode, bool mirror, float scale_factor)
242242
resize_mode,
243243
true,
244244
mirror,
245-
&gr_screen.current_color,
245+
&GR_CURRENT_COLOR,
246246
scale_factor);
247247
}
248248
void gr_aabitmap_ex(int x, int y, int w, int h, int sx, int sy, int resize_mode, bool mirror, float scale_factor) {
@@ -383,7 +383,7 @@ void gr_aabitmap_ex(int x, int y, int w, int h, int sx, int sy, int resize_mode,
383383
resize_mode,
384384
true,
385385
mirror,
386-
&gr_screen.current_color,
386+
&GR_CURRENT_COLOR,
387387
scale_factor);
388388
}
389389
//these are penguins bitmap functions
@@ -1439,7 +1439,7 @@ void gr_aabitmap_list(bitmap_rect_list* list, int n_bm, int resize_mode, float a
14391439
render_mat.set_blend_mode(ALPHA_BLEND_ALPHA_BLEND_ALPHA);
14401440
render_mat.set_depth_mode(ZBUFFER_TYPE_NONE);
14411441
render_mat.set_texture_map(TM_BASE_TYPE, gr_screen.current_bitmap);
1442-
render_mat.set_color(gr_screen.current_color);
1442+
render_mat.set_color(GR_CURRENT_COLOR);
14431443
render_mat.set_cull_mode(false);
14441444
render_mat.set_texture_type(material::TEX_TYPE_AABITMAP);
14451445

code/graphics/software/FontManager.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ namespace font
5353

5454
FSFont *FontManager::getCurrentFont()
5555
{
56-
return getFont(currentFontIndex);
56+
int id = gr_lua_context_active() ? gr_lua_screen.current_font_index : currentFontIndex;
57+
return getFont(id);
5758
}
5859

5960
int FontManager::getCurrentFontIndex()

code/scripting/api/libs/graphics.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1559,6 +1559,8 @@ ADE_FUNC(getStringWidth, l_Graphics, "string String", "Gets string width", "numb
15591559
if(!ade_get_args(L, "s", &s))
15601560
return ade_set_error(L, "i", 0);
15611561

1562+
LuaScreenContext context;
1563+
15621564
int w;
15631565
gr_get_string_size(&w, nullptr, s);
15641566

@@ -1574,6 +1576,8 @@ ADE_FUNC(getStringHeight, l_Graphics, "string String", "Gets string height", "nu
15741576
if(!ade_get_args(L, "s", &s))
15751577
return ade_set_error(L, "i", 0);
15761578

1579+
LuaScreenContext context;
1580+
15771581
int h;
15781582
gr_get_string_size(nullptr, &h, s);
15791583

@@ -1589,6 +1593,8 @@ ADE_FUNC(getStringSize, l_Graphics, "string String", "Gets string width and heig
15891593
if(!ade_get_args(L, "s", &s))
15901594
return ade_set_error(L, "ii", 0, 0);
15911595

1596+
LuaScreenContext context;
1597+
15921598
int w, h;
15931599
gr_get_string_size(&w, &h, s);
15941600

@@ -1708,6 +1714,8 @@ ADE_FUNC(drawImage,
17081714
if(!Gr_inited)
17091715
return ade_set_error(L, "b", false);
17101716

1717+
LuaScreenContext context;
1718+
17111719
int idx;
17121720
int x1 = 0;
17131721
int y1 = 0;
@@ -1798,6 +1806,8 @@ ADE_FUNC(drawImageCentered,
17981806
if(!Gr_inited)
17991807
return ade_set_error(L, "b", false);
18001808

1809+
LuaScreenContext context;
1810+
18011811
int idx;
18021812
int x = 0;
18031813
int y = 0;
@@ -1889,6 +1899,8 @@ ADE_FUNC_DEPRECATED(drawMonochromeImage,
18891899
if(!Gr_inited)
18901900
return ade_set_error(L, "b", false);
18911901

1902+
LuaScreenContext context;
1903+
18921904
int idx;
18931905
int x,y;
18941906
int x2=INT_MAX;

0 commit comments

Comments
 (0)