- moved the script exports to the base class as wello.

This commit is contained in:
Christoph Oelckers 2020-10-28 07:29:52 +01:00
parent be5d25a7b1
commit 783d532bbe
3 changed files with 189 additions and 180 deletions

View file

@ -48,6 +48,179 @@
#include "printf.h"
#include "s_music.h"
#include "i_interface.h"
#include "base_sbar.h"
//==========================================================================
//
// status bar exports
//
//==========================================================================
static double StatusbarToRealCoords(DStatusBarCore* self, double x, double y, double w, double h, double* py, double* pw, double* ph)
{
self->StatusbarToRealCoords(x, y, w, h);
*py = y;
*pw = w;
*ph = h;
return x;
}
DEFINE_ACTION_FUNCTION_NATIVE(DStatusBarCore, StatusbarToRealCoords, StatusbarToRealCoords)
{
PARAM_SELF_PROLOGUE(DStatusBarCore);
PARAM_FLOAT(x);
PARAM_FLOAT(y);
PARAM_FLOAT(w);
PARAM_FLOAT(h);
self->StatusbarToRealCoords(x, y, w, h);
if (numret > 0) ret[0].SetFloat(x);
if (numret > 1) ret[1].SetFloat(y);
if (numret > 2) ret[2].SetFloat(w);
if (numret > 3) ret[3].SetFloat(h);
return MIN(4, numret);
}
void SBar_DrawTexture(DStatusBarCore* self, int texid, double x, double y, int flags, double alpha, double w, double h, double scaleX, double scaleY)
{
if (!twod->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);
}
DEFINE_ACTION_FUNCTION_NATIVE(DStatusBarCore, DrawTexture, SBar_DrawTexture)
{
PARAM_SELF_PROLOGUE(DStatusBarCore);
PARAM_INT(texid);
PARAM_FLOAT(x);
PARAM_FLOAT(y);
PARAM_INT(flags);
PARAM_FLOAT(alpha);
PARAM_FLOAT(w);
PARAM_FLOAT(h);
PARAM_FLOAT(scaleX);
PARAM_FLOAT(scaleY);
SBar_DrawTexture(self, texid, x, y, flags, alpha, w, h, scaleX, scaleY);
return 0;
}
void SBar_DrawImage(DStatusBarCore* self, const FString& texid, double x, double y, int flags, double alpha, double w, double h, double scaleX, double scaleY)
{
if (!twod->HasBegun2D()) ThrowAbortException(X_OTHER, "Attempt to draw to screen outside a draw function");
self->DrawGraphic(TexMan.CheckForTexture(texid, ETextureType::Any), x, y, flags, alpha, w, h, scaleX, scaleY);
}
DEFINE_ACTION_FUNCTION_NATIVE(DStatusBarCore, DrawImage, SBar_DrawImage)
{
PARAM_SELF_PROLOGUE(DStatusBarCore);
PARAM_STRING(texid);
PARAM_FLOAT(x);
PARAM_FLOAT(y);
PARAM_INT(flags);
PARAM_FLOAT(alpha);
PARAM_FLOAT(w);
PARAM_FLOAT(h);
PARAM_FLOAT(scaleX);
PARAM_FLOAT(scaleY);
SBar_DrawImage(self, texid, x, y, flags, alpha, w, h, scaleX, scaleY);
return 0;
}
void SBar_DrawString(DStatusBarCore* self, DHUDFont* font, const FString& string, double x, double y, int flags, int trans, double alpha, int wrapwidth, int linespacing, double scaleX, double scaleY);
DEFINE_ACTION_FUNCTION_NATIVE(DStatusBarCore, DrawString, SBar_DrawString)
{
PARAM_SELF_PROLOGUE(DStatusBarCore);
PARAM_POINTER_NOT_NULL(font, DHUDFont);
PARAM_STRING(string);
PARAM_FLOAT(x);
PARAM_FLOAT(y);
PARAM_INT(flags);
PARAM_INT(trans);
PARAM_FLOAT(alpha);
PARAM_INT(wrapwidth);
PARAM_INT(linespacing);
PARAM_FLOAT(scaleX);
PARAM_FLOAT(scaleY);
SBar_DrawString(self, font, string, x, y, flags, trans, alpha, wrapwidth, linespacing, scaleX, scaleY);
return 0;
}
static double SBar_TransformRect(DStatusBarCore* self, double x, double y, double w, double h, int flags, double* py, double* pw, double* ph)
{
self->TransformRect(x, y, w, h, flags);
*py = y;
*pw = w;
*ph = h;
return x;
}
DEFINE_ACTION_FUNCTION_NATIVE(DStatusBarCore, TransformRect, SBar_TransformRect)
{
PARAM_SELF_PROLOGUE(DStatusBarCore);
PARAM_FLOAT(x);
PARAM_FLOAT(y);
PARAM_FLOAT(w);
PARAM_FLOAT(h);
PARAM_INT(flags);
self->TransformRect(x, y, w, h, flags);
if (numret > 0) ret[0].SetFloat(x);
if (numret > 1) ret[1].SetFloat(y);
if (numret > 2) ret[2].SetFloat(w);
if (numret > 3) ret[3].SetFloat(h);
return MIN(4, numret);
}
static void SBar_Fill(DStatusBarCore* self, int color, double x, double y, double w, double h, int flags)
{
if (!twod->HasBegun2D()) ThrowAbortException(X_OTHER, "Attempt to draw to screen outside a draw function");
self->Fill(color, x, y, w, h, flags);
}
DEFINE_ACTION_FUNCTION_NATIVE(DStatusBarCore, Fill, SBar_Fill)
{
PARAM_SELF_PROLOGUE(DStatusBarCore);
PARAM_COLOR(color);
PARAM_FLOAT(x);
PARAM_FLOAT(y);
PARAM_FLOAT(w);
PARAM_FLOAT(h);
PARAM_INT(flags);
SBar_Fill(self, color, x, y, w, h, flags);
return 0;
}
static void SBar_SetClipRect(DStatusBarCore* self, double x, double y, double w, double h, int flags)
{
self->SetClipRect(x, y, w, h, flags);
}
DEFINE_ACTION_FUNCTION_NATIVE(DStatusBarCore, SetClipRect, SBar_SetClipRect)
{
PARAM_SELF_PROLOGUE(DStatusBarCore);
PARAM_FLOAT(x);
PARAM_FLOAT(y);
PARAM_FLOAT(w);
PARAM_FLOAT(h);
PARAM_INT(flags);
self->SetClipRect(x, y, w, h, flags);
return 0;
}
void FormatNumber(int number, int minsize, int maxsize, int flags, const FString& prefix, FString* result);
DEFINE_ACTION_FUNCTION_NATIVE(DStatusBarCore, FormatNumber, FormatNumber)
{
PARAM_PROLOGUE;
PARAM_INT(number);
PARAM_INT(minsize);
PARAM_INT(maxsize);
PARAM_INT(flags);
PARAM_STRING(prefix);
FString fmt;
FormatNumber(number, minsize, maxsize, flags, prefix, &fmt);
ACTION_RETURN_STRING(fmt);
}
//==========================================================================

View file

@ -2081,30 +2081,6 @@ DEFINE_ACTION_FUNCTION_NATIVE(DBaseStatusBar, ScreenSizeChanged, SBar_ScreenSize
return 0;
}
static double StatusbarToRealCoords(DBaseStatusBar *self, double x, double y, double w, double h, double *py, double *pw, double *ph)
{
self->StatusbarToRealCoords(x, y, w, h);
*py = y;
*pw = w;
*ph = h;
return x;
}
DEFINE_ACTION_FUNCTION_NATIVE(DBaseStatusBar, StatusbarToRealCoords, StatusbarToRealCoords)
{
PARAM_SELF_PROLOGUE(DBaseStatusBar);
PARAM_FLOAT(x);
PARAM_FLOAT(y);
PARAM_FLOAT(w);
PARAM_FLOAT(h);
self->StatusbarToRealCoords(x, y, w, h);
if (numret > 0) ret[0].SetFloat(x);
if (numret > 1) ret[1].SetFloat(y);
if (numret > 2) ret[2].SetFloat(w);
if (numret > 3) ret[3].SetFloat(h);
return MIN(4, numret);
}
static int GetTopOfStatusbar(DBaseStatusBar *self)
{
return self->GetTopOfStatusbar();
@ -2116,147 +2092,6 @@ DEFINE_ACTION_FUNCTION_NATIVE(DBaseStatusBar, GetTopOfStatusbar, GetTopOfStatusb
ACTION_RETURN_INT(self->GetTopOfStatusbar());
}
void SBar_DrawTexture(DBaseStatusBar *self, int texid, double x, double y, int flags, double alpha, double w, double h, double scaleX, double scaleY)
{
if (!twod->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);
}
DEFINE_ACTION_FUNCTION_NATIVE(DBaseStatusBar, DrawTexture, SBar_DrawTexture)
{
PARAM_SELF_PROLOGUE(DBaseStatusBar);
PARAM_INT(texid);
PARAM_FLOAT(x);
PARAM_FLOAT(y);
PARAM_INT(flags);
PARAM_FLOAT(alpha);
PARAM_FLOAT(w);
PARAM_FLOAT(h);
PARAM_FLOAT(scaleX);
PARAM_FLOAT(scaleY);
SBar_DrawTexture(self, texid, x, y, flags, alpha, w, h, scaleX, scaleY);
return 0;
}
void SBar_DrawImage(DBaseStatusBar *self, const FString &texid, double x, double y, int flags, double alpha, double w, double h, double scaleX, double scaleY)
{
if (!twod->HasBegun2D()) ThrowAbortException(X_OTHER, "Attempt to draw to screen outside a draw function");
self->DrawGraphic(TexMan.CheckForTexture(texid, ETextureType::Any), x, y, flags, alpha, w, h, scaleX, scaleY);
}
DEFINE_ACTION_FUNCTION_NATIVE(DBaseStatusBar, DrawImage, SBar_DrawImage)
{
PARAM_SELF_PROLOGUE(DBaseStatusBar);
PARAM_STRING(texid);
PARAM_FLOAT(x);
PARAM_FLOAT(y);
PARAM_INT(flags);
PARAM_FLOAT(alpha);
PARAM_FLOAT(w);
PARAM_FLOAT(h);
PARAM_FLOAT(scaleX);
PARAM_FLOAT(scaleY);
SBar_DrawImage(self, texid, x, y, flags, alpha, w, h, scaleX, scaleY);
return 0;
}
void SBar_DrawString(DStatusBarCore *self, DHUDFont *font, const FString &string, double x, double y, int flags, int trans, double alpha, int wrapwidth, int linespacing, double scaleX, double scaleY);
DEFINE_ACTION_FUNCTION_NATIVE(DBaseStatusBar, DrawString, SBar_DrawString)
{
PARAM_SELF_PROLOGUE(DBaseStatusBar);
PARAM_POINTER_NOT_NULL(font, DHUDFont);
PARAM_STRING(string);
PARAM_FLOAT(x);
PARAM_FLOAT(y);
PARAM_INT(flags);
PARAM_INT(trans);
PARAM_FLOAT(alpha);
PARAM_INT(wrapwidth);
PARAM_INT(linespacing);
PARAM_FLOAT(scaleX);
PARAM_FLOAT(scaleY);
SBar_DrawString(self, font, string, x, y, flags, trans, alpha, wrapwidth, linespacing, scaleX, scaleY);
return 0;
}
static double SBar_TransformRect(DBaseStatusBar *self, double x, double y, double w, double h, int flags, double *py, double *pw, double *ph)
{
self->TransformRect(x, y, w, h, flags);
*py = y;
*pw = w;
*ph = h;
return x;
}
DEFINE_ACTION_FUNCTION_NATIVE(DBaseStatusBar, TransformRect, SBar_TransformRect)
{
PARAM_SELF_PROLOGUE(DBaseStatusBar);
PARAM_FLOAT(x);
PARAM_FLOAT(y);
PARAM_FLOAT(w);
PARAM_FLOAT(h);
PARAM_INT(flags);
self->TransformRect(x, y, w, h, flags);
if (numret > 0) ret[0].SetFloat(x);
if (numret > 1) ret[1].SetFloat(y);
if (numret > 2) ret[2].SetFloat(w);
if (numret > 3) ret[3].SetFloat(h);
return MIN(4, numret);
}
static void SBar_Fill(DBaseStatusBar *self, int color, double x, double y, double w, double h, int flags)
{
if (!twod->HasBegun2D()) ThrowAbortException(X_OTHER, "Attempt to draw to screen outside a draw function");
self->Fill(color, x, y, w, h, flags);
}
DEFINE_ACTION_FUNCTION_NATIVE(DBaseStatusBar, Fill, SBar_Fill)
{
PARAM_SELF_PROLOGUE(DBaseStatusBar);
PARAM_COLOR(color);
PARAM_FLOAT(x);
PARAM_FLOAT(y);
PARAM_FLOAT(w);
PARAM_FLOAT(h);
PARAM_INT(flags);
SBar_Fill(self, color, x, y, w, h, flags);
return 0;
}
static void SBar_SetClipRect(DBaseStatusBar *self, double x, double y, double w, double h, int flags)
{
self->SetClipRect(x, y, w, h, flags);
}
DEFINE_ACTION_FUNCTION_NATIVE(DBaseStatusBar, SetClipRect, SBar_SetClipRect)
{
PARAM_SELF_PROLOGUE(DBaseStatusBar);
PARAM_FLOAT(x);
PARAM_FLOAT(y);
PARAM_FLOAT(w);
PARAM_FLOAT(h);
PARAM_INT(flags);
self->SetClipRect(x, y, w, h, flags);
return 0;
}
void FormatNumber(int number, int minsize, int maxsize, int flags, const FString& prefix, FString* result);
DEFINE_ACTION_FUNCTION_NATIVE(DStatusBarCore, FormatNumber, FormatNumber)
{
PARAM_PROLOGUE;
PARAM_INT(number);
PARAM_INT(minsize);
PARAM_INT(maxsize);
PARAM_INT(flags);
PARAM_STRING(prefix);
FString fmt;
FormatNumber(number, minsize, maxsize, flags, prefix, &fmt);
ACTION_RETURN_STRING(fmt);
}
static void GetGlobalACSString(int index, FString *result)
{
*result = primaryLevel->Behaviors.LookupString(ACS_GlobalVars[index]);

View file

@ -1,6 +1,19 @@
class StatusBarCore native
{
native static String FormatNumber(int number, int minsize = 0, int maxsize = 0, int format = 0, String prefix = "");
native double, double, double, double StatusbarToRealCoords(double x, double y=0, double w=0, double h=0);
native void DrawTexture(TextureID texture, Vector2 pos, int flags = 0, double Alpha = 1., Vector2 box = (-1, -1), Vector2 scale = (1, 1));
native void DrawImage(String texture, Vector2 pos, int flags = 0, double Alpha = 1., Vector2 box = (-1, -1), Vector2 scale = (1, 1));
native void DrawString(HUDFont font, String string, Vector2 pos, int flags = 0, int translation = Font.CR_UNTRANSLATED, double Alpha = 1., int wrapwidth = -1, int linespacing = 4, Vector2 scale = (1, 1));
native double, double, double, double TransformRect(double x, double y, double w, double h, int flags = 0);
native void Fill(Color col, double x, double y, double w, double h, int flags = 0);
native void SetClipRect(double x, double y, double w, double h, int flags = 0);
void ClearClipRect()
{
screen.ClearClipRect();
}
}
struct MugShot
@ -347,23 +360,11 @@ class BaseStatusBar : StatusBarCore native ui
virtual bool DrawChat(String txt) { return false; }
native TextureID GetMugshot(int accuracy, int stateflags=MugShot.STANDARD, String default_face = "STF");
native int GetTopOfStatusBar();
// These functions are kept native solely for performance reasons. They get called repeatedly and can drag down performance easily if they get too slow.
native static TextureID, bool GetInventoryIcon(Inventory item, int flags);
native void DrawTexture(TextureID texture, Vector2 pos, int flags = 0, double Alpha = 1., Vector2 box = (-1, -1), Vector2 scale = (1, 1));
native void DrawImage(String texture, Vector2 pos, int flags = 0, double Alpha = 1., Vector2 box = (-1, -1), Vector2 scale = (1, 1));
native void DrawString(HUDFont font, String string, Vector2 pos, int flags = 0, int translation = Font.CR_UNTRANSLATED, double Alpha = 1., int wrapwidth = -1, int linespacing = 4, Vector2 scale = (1, 1));
native double, double, double, double TransformRect(double x, double y, double w, double h, int flags = 0);
native void Fill(Color col, double x, double y, double w, double h, int flags = 0);
native double, double, double, double StatusbarToRealCoords(double x, double y=0, double w=0, double h=0);
native int GetTopOfStatusBar();
native void SetClipRect(double x, double y, double w, double h, int flags = 0);
void ClearClipRect()
{
screen.ClearClipRect();
}
//---------------------------------------------------------------------------
//
// ValidateInvFirst