- added DFrameBuffer::HasBegun2D to allow scripting to test if 2D drawing is active (instead of using IsLocked, which may return false when vid_hw2d is active)

This commit is contained in:
Magnus Norddahl 2017-03-29 00:45:53 +02:00
parent 054d9a5bcc
commit d160424aea
6 changed files with 14 additions and 10 deletions

View file

@ -1700,7 +1700,7 @@ DEFINE_ACTION_FUNCTION(DBaseStatusBar, DrawTexture)
PARAM_FLOAT_DEF(h); PARAM_FLOAT_DEF(h);
PARAM_FLOAT_DEF(scaleX); PARAM_FLOAT_DEF(scaleX);
PARAM_FLOAT_DEF(scaleY); PARAM_FLOAT_DEF(scaleY);
if (!screen->IsLocked()) ThrowAbortException(X_OTHER, "Attempt to draw to screen outside a draw function"); if (!screen->HasBegun2D()) ThrowAbortException(X_OTHER, "Attempt to draw to screen outside a draw function");
self->DrawGraphic(FSetTextureID(texid), x, y, flags, alpha, w, h, scaleX, scaleY); self->DrawGraphic(FSetTextureID(texid), x, y, flags, alpha, w, h, scaleX, scaleY);
return 0; return 0;
} }
@ -1717,7 +1717,7 @@ DEFINE_ACTION_FUNCTION(DBaseStatusBar, DrawImage)
PARAM_FLOAT_DEF(h); PARAM_FLOAT_DEF(h);
PARAM_FLOAT_DEF(scaleX); PARAM_FLOAT_DEF(scaleX);
PARAM_FLOAT_DEF(scaleY); PARAM_FLOAT_DEF(scaleY);
if (!screen->IsLocked()) ThrowAbortException(X_OTHER, "Attempt to draw to screen outside a draw function"); if (!screen->HasBegun2D()) ThrowAbortException(X_OTHER, "Attempt to draw to screen outside a draw function");
self->DrawGraphic(TexMan.CheckForTexture(texid, FTexture::TEX_Any), x, y, flags, alpha, w, h, scaleX, scaleY); self->DrawGraphic(TexMan.CheckForTexture(texid, FTexture::TEX_Any), x, y, flags, alpha, w, h, scaleX, scaleY);
return 0; return 0;
} }
@ -1910,7 +1910,7 @@ DEFINE_ACTION_FUNCTION(DBaseStatusBar, DrawString)
PARAM_INT_DEF(wrapwidth); PARAM_INT_DEF(wrapwidth);
PARAM_INT_DEF(linespacing); PARAM_INT_DEF(linespacing);
if (!screen->IsLocked()) ThrowAbortException(X_OTHER, "Attempt to draw to screen outside a draw function"); if (!screen->HasBegun2D()) ThrowAbortException(X_OTHER, "Attempt to draw to screen outside a draw function");
// resolve auto-alignment before making any adjustments to the position values. // resolve auto-alignment before making any adjustments to the position values.
if (!(flags & DI_SCREEN_MANUAL_ALIGN)) if (!(flags & DI_SCREEN_MANUAL_ALIGN))
@ -2015,7 +2015,7 @@ DEFINE_ACTION_FUNCTION(DBaseStatusBar, Fill)
PARAM_FLOAT(w); PARAM_FLOAT(w);
PARAM_FLOAT(h); PARAM_FLOAT(h);
PARAM_INT_DEF(flags); PARAM_INT_DEF(flags);
if (!screen->IsLocked()) ThrowAbortException(X_OTHER, "Attempt to draw to screen outside a draw function"); if (!screen->HasBegun2D()) ThrowAbortException(X_OTHER, "Attempt to draw to screen outside a draw function");
self->Fill(color, x, y, w, h); self->Fill(color, x, y, w, h);
return 0; return 0;
} }

View file

@ -33,7 +33,7 @@ public:
OpenGLSWFrameBuffer(void *hMonitor, int width, int height, int bits, int refreshHz, bool fullscreen, bool bgra); OpenGLSWFrameBuffer(void *hMonitor, int width, int height, int bits, int refreshHz, bool fullscreen, bool bgra);
~OpenGLSWFrameBuffer(); ~OpenGLSWFrameBuffer();
bool HasBegun2D() override { return In2D || IsLocked(); }
bool IsValid() override; bool IsValid() override;
bool Lock(bool buffered) override; bool Lock(bool buffered) override;
void Unlock() override; void Unlock() override;

View file

@ -137,7 +137,7 @@ DEFINE_ACTION_FUNCTION(_Screen, DrawTexture)
PARAM_FLOAT(x); PARAM_FLOAT(x);
PARAM_FLOAT(y); PARAM_FLOAT(y);
if (!screen->IsLocked()) ThrowAbortException(X_OTHER, "Attempt to draw to screen outside a draw function"); if (!screen->HasBegun2D()) ThrowAbortException(X_OTHER, "Attempt to draw to screen outside a draw function");
FTexture *tex = animate ? TexMan(FSetTextureID(texid)) : TexMan[FSetTextureID(texid)]; FTexture *tex = animate ? TexMan(FSetTextureID(texid)) : TexMan[FSetTextureID(texid)];
VMVa_List args = { param + 4, 0, numparam - 4 }; VMVa_List args = { param + 4, 0, numparam - 4 };
@ -961,7 +961,7 @@ DEFINE_ACTION_FUNCTION(_Screen, Clear)
PARAM_INT(y2); PARAM_INT(y2);
PARAM_INT(color); PARAM_INT(color);
PARAM_INT_DEF(palcol); PARAM_INT_DEF(palcol);
if (!screen->IsLocked()) ThrowAbortException(X_OTHER, "Attempt to draw to screen outside a draw function"); if (!screen->HasBegun2D()) ThrowAbortException(X_OTHER, "Attempt to draw to screen outside a draw function");
screen->Clear(x1, y1, x2, y2, palcol, color); screen->Clear(x1, y1, x2, y2, palcol, color);
return 0; return 0;
} }
@ -1013,7 +1013,7 @@ DEFINE_ACTION_FUNCTION(_Screen, Dim)
PARAM_INT(y1); PARAM_INT(y1);
PARAM_INT(w); PARAM_INT(w);
PARAM_INT(h); PARAM_INT(h);
if (!screen->IsLocked()) ThrowAbortException(X_OTHER, "Attempt to draw to screen outside a draw function"); if (!screen->HasBegun2D()) ThrowAbortException(X_OTHER, "Attempt to draw to screen outside a draw function");
screen->Dim(color, float(amount), x1, y1, w, h); screen->Dim(color, float(amount), x1, y1, w, h);
return 0; return 0;
} }

View file

@ -116,7 +116,7 @@ DEFINE_ACTION_FUNCTION(_Screen, DrawChar)
PARAM_FLOAT(y); PARAM_FLOAT(y);
PARAM_INT(chr); PARAM_INT(chr);
if (!screen->IsLocked()) ThrowAbortException(X_OTHER, "Attempt to draw to screen outside a draw function"); if (!screen->HasBegun2D()) ThrowAbortException(X_OTHER, "Attempt to draw to screen outside a draw function");
VMVa_List args = { param + 5, 0, numparam - 5 }; VMVa_List args = { param + 5, 0, numparam - 5 };
screen->DrawChar(font, cr, x, y, chr, args); screen->DrawChar(font, cr, x, y, chr, args);
return 0; return 0;
@ -242,7 +242,7 @@ DEFINE_ACTION_FUNCTION(_Screen, DrawText)
PARAM_FLOAT(y); PARAM_FLOAT(y);
PARAM_STRING(chr); PARAM_STRING(chr);
if (!screen->IsLocked()) ThrowAbortException(X_OTHER, "Attempt to draw to screen outside a draw function"); if (!screen->HasBegun2D()) ThrowAbortException(X_OTHER, "Attempt to draw to screen outside a draw function");
VMVa_List args = { param + 5, 0, numparam - 5 }; VMVa_List args = { param + 5, 0, numparam - 5 };
const char *txt = chr[0] == '$' ? GStrings(&chr[1]) : chr.GetChars(); const char *txt = chr[0] == '$' ? GStrings(&chr[1]) : chr.GetChars();
screen->DrawText(font, cr, x, y, txt, args); screen->DrawText(font, cr, x, y, txt, args);

View file

@ -410,6 +410,9 @@ public:
// Returns true if hardware-accelerated 2D has been entered, false if not. // Returns true if hardware-accelerated 2D has been entered, false if not.
virtual bool Begin2D(bool copy3d); virtual bool Begin2D(bool copy3d);
// Returns true if Begin2D has been called and 2D drawing is now active
virtual bool HasBegun2D() { return IsLocked(); }
// DrawTexture calls after Begin2D use native textures. // DrawTexture calls after Begin2D use native textures.
// Draws the blending rectangle over the viewwindow if in hardware- // Draws the blending rectangle over the viewwindow if in hardware-

View file

@ -105,6 +105,7 @@ public:
D3DFB (UINT adapter, int width, int height, bool bgra, bool fullscreen); D3DFB (UINT adapter, int width, int height, bool bgra, bool fullscreen);
~D3DFB (); ~D3DFB ();
bool HasBegun2D() override { return In2D || IsLocked(); }
bool IsValid (); bool IsValid ();
bool Lock (bool buffered); bool Lock (bool buffered);
void Unlock (); void Unlock ();