- add a method for filling a shape2d instead of using a texture (#1661)

Co-authored-by: Christoph Oelckers <coelckers@users.noreply.github.com>
This commit is contained in:
Gutawer 2022-07-16 13:57:22 +01:00 committed by GitHub
parent ee0d90a983
commit 937c22ff14
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 40 additions and 6 deletions

View file

@ -621,7 +621,7 @@ void F2DDrawer::AddShape(FGameTexture* img, DShape2D* shape, DrawParms& parms)
shape->lastParms = new DrawParms(parms); shape->lastParms = new DrawParms(parms);
} }
if (!img->isHardwareCanvas() && parms.TranslationId != -1) if (!(img != nullptr && img->isHardwareCanvas()) && parms.TranslationId != -1)
dg.mTranslationId = parms.TranslationId; dg.mTranslationId = parms.TranslationId;
auto osave = offset; auto osave = offset;

View file

@ -289,6 +289,19 @@ void DrawShape(F2DDrawer *drawer, FGameTexture *img, DShape2D *shape, VMVa_List
drawer->AddShape(img, shape, parms); drawer->AddShape(img, shape, parms);
} }
void DrawShapeFill(F2DDrawer *drawer, int color, DShape2D *shape, VMVa_List &args)
{
DrawParms parms;
uint32_t tag = ListGetInt(args);
bool res = ParseDrawTextureTags(drawer, nullptr, 0, 0, tag, args, &parms, false, false);
if (!res) return;
parms.fillcolor = color;
drawer->AddShape(nullptr, shape, parms);
}
DEFINE_ACTION_FUNCTION(_Screen, DrawShape) DEFINE_ACTION_FUNCTION(_Screen, DrawShape)
{ {
PARAM_PROLOGUE; PARAM_PROLOGUE;
@ -307,6 +320,25 @@ DEFINE_ACTION_FUNCTION(_Screen, DrawShape)
return 0; return 0;
} }
DEFINE_ACTION_FUNCTION(_Screen, DrawShapeFill)
{
PARAM_PROLOGUE;
PARAM_COLOR(color);
PARAM_FLOAT(amount);
PARAM_POINTER(shape, DShape2D);
PARAM_VA_POINTER(va_reginfo) // Get the hidden type information array
if (!twod->HasBegun2D()) ThrowAbortException(X_OTHER, "Attempt to draw to screen outside a draw function");
VMVa_List args = { param + 3, 0, numparam - 4, va_reginfo + 3 };
color.a = int(amount * 255.0f);
DrawShapeFill(twod, color, shape, args);
return 0;
}
//========================================================================== //==========================================================================
// //
// Clipping rect // Clipping rect
@ -682,13 +714,13 @@ static inline FSpecialColormap * ListGetSpecialColormap(VMVa_List &tags)
//========================================================================== //==========================================================================
template<class T> template<class T>
bool ParseDrawTextureTags(F2DDrawer *drawer, FGameTexture *img, double x, double y, uint32_t tag, T& tags, DrawParms *parms, bool fortext) bool ParseDrawTextureTags(F2DDrawer *drawer, FGameTexture *img, double x, double y, uint32_t tag, T& tags, DrawParms *parms, bool fortext, bool checkimage)
{ {
INTBOOL boolval; INTBOOL boolval;
int intval; int intval;
bool fillcolorset = false; bool fillcolorset = false;
if (!fortext) if (!fortext && checkimage)
{ {
if (img == NULL || !img->isValid()) if (img == NULL || !img->isValid())
{ {
@ -1285,8 +1317,8 @@ bool ParseDrawTextureTags(F2DDrawer *drawer, FGameTexture *img, double x, double
} }
// explicitly instantiate both versions for v_text.cpp. // explicitly instantiate both versions for v_text.cpp.
template bool ParseDrawTextureTags<Va_List>(F2DDrawer* drawer, FGameTexture *img, double x, double y, uint32_t tag, Va_List& tags, DrawParms *parms, bool fortext); template bool ParseDrawTextureTags<Va_List>(F2DDrawer* drawer, FGameTexture *img, double x, double y, uint32_t tag, Va_List& tags, DrawParms *parms, bool fortext, bool checkimage);
template bool ParseDrawTextureTags<VMVa_List>(F2DDrawer* drawer, FGameTexture *img, double x, double y, uint32_t tag, VMVa_List& tags, DrawParms *parms, bool fortext); template bool ParseDrawTextureTags<VMVa_List>(F2DDrawer* drawer, FGameTexture *img, double x, double y, uint32_t tag, VMVa_List& tags, DrawParms *parms, bool fortext, bool checkimage);
//========================================================================== //==========================================================================
// //
@ -1681,3 +1713,4 @@ DEFINE_ACTION_FUNCTION(_Screen, ClearTransform)
twod->ClearTransform(); twod->ClearTransform();
return 0; return 0;
} }

View file

@ -259,7 +259,7 @@ inline int active_con_scale(F2DDrawer *drawer)
#endif #endif
template<class T> template<class T>
bool ParseDrawTextureTags(F2DDrawer *drawer, FGameTexture* img, double x, double y, uint32_t tag, T& tags, DrawParms* parms, bool fortext); bool ParseDrawTextureTags(F2DDrawer *drawer, FGameTexture* img, double x, double y, uint32_t tag, T& tags, DrawParms* parms, bool fortext, bool checkimage = true);
template<class T> template<class T>
void DrawTextCommon(F2DDrawer *drawer, FFont* font, int normalcolor, double x, double y, const T* string, DrawParms& parms); void DrawTextCommon(F2DDrawer *drawer, FFont* font, int normalcolor, double x, double y, const T* string, DrawParms& parms);

View file

@ -513,6 +513,7 @@ struct Screen native
native static vararg void DrawTexture(TextureID tex, bool animate, double x, double y, ...); native static vararg void DrawTexture(TextureID tex, bool animate, double x, double y, ...);
native static vararg void DrawShape(TextureID tex, bool animate, Shape2D s, ...); native static vararg void DrawShape(TextureID tex, bool animate, Shape2D s, ...);
native static vararg void DrawShapeFill(Color col, double amount, Shape2D s, ...);
native static vararg void DrawChar(Font font, int normalcolor, double x, double y, int character, ...); native static vararg void DrawChar(Font font, int normalcolor, double x, double y, int character, ...);
native static vararg void DrawText(Font font, int normalcolor, double x, double y, String text, ...); native static vararg void DrawText(Font font, int normalcolor, double x, double y, String text, ...);
native static void DrawLine(int x0, int y0, int x1, int y1, Color color, int alpha = 255); native static void DrawLine(int x0, int y0, int x1, int y1, Color color, int alpha = 255);