- scriptified DTextEnterMenu::Drawer.

This commit is contained in:
Christoph Oelckers 2017-02-18 20:12:06 +01:00
parent 06141338f1
commit 0c41a9dee7
5 changed files with 113 additions and 110 deletions

View file

@ -373,11 +373,9 @@ public:
// [TP] Added allowcolors
DTextEnterMenu(DMenu *parent, const char *textbuffer, int maxlen, int sizemode, bool showgrid, bool allowcolors = false);
void Drawer ();
bool MenuEvent (int mkey, bool fromcontroller);
bool Responder(event_t *ev);
bool MouseEvent(int type, int x, int y);
FString GetText();
};

View file

@ -61,8 +61,6 @@ static const char InputGridChars[INPUTGRID_WIDTH * INPUTGRID_HEIGHT] =
CVAR(Bool, m_showinputgrid, false, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
DEFINE_FIELD(DTextEnterMenu, mInputGridOkay)
//=============================================================================
//
//
@ -91,24 +89,6 @@ DTextEnterMenu::DTextEnterMenu(DMenu *parent, const char *textbuffer, int maxlen
AllowColors = allowcolors; // [TP]
}
//=============================================================================
//
//
//
//=============================================================================
FString DTextEnterMenu::GetText()
{
return mEnterString;
}
//=============================================================================
//
//
//
//=============================================================================
//=============================================================================
//
//
@ -294,88 +274,6 @@ bool DTextEnterMenu::MenuEvent (int key, bool fromcontroller)
return false;
}
//=============================================================================
//
//
//
//=============================================================================
void DTextEnterMenu::Drawer ()
{
mParentMenu->CallDrawer();
if (mInputGridOkay)
{
const int cell_width = 18 * CleanXfac;
const int cell_height = 12 * CleanYfac;
const int top_padding = cell_height / 2 - SmallFont->GetHeight() * CleanYfac / 2;
// Darken the background behind the character grid.
// Unless we frame it with a border, I think it looks better to extend the
// background across the full width of the screen.
screen->Dim(0, 0.8f,
0 /*screen->GetWidth()/2 - 13 * cell_width / 2*/,
screen->GetHeight() - INPUTGRID_HEIGHT * cell_height,
screen->GetWidth() /*13 * cell_width*/,
INPUTGRID_HEIGHT * cell_height);
if (InputGridX >= 0 && InputGridY >= 0)
{
// Highlight the background behind the selected character.
screen->Dim(MAKERGB(255,248,220), 0.6f,
InputGridX * cell_width - INPUTGRID_WIDTH * cell_width / 2 + screen->GetWidth() / 2,
InputGridY * cell_height - INPUTGRID_HEIGHT * cell_height + screen->GetHeight(),
cell_width, cell_height);
}
for (int y = 0; y < INPUTGRID_HEIGHT; ++y)
{
const int yy = y * cell_height - INPUTGRID_HEIGHT * cell_height + screen->GetHeight();
for (int x = 0; x < INPUTGRID_WIDTH; ++x)
{
int width;
const int xx = x * cell_width - INPUTGRID_WIDTH * cell_width / 2 + screen->GetWidth() / 2;
const int ch = InputGridChars[y * INPUTGRID_WIDTH + x];
FTexture *pic = SmallFont->GetChar(ch, &width);
EColorRange color;
// The highlighted character is yellow; the rest are dark gray.
color = (x == InputGridX && y == InputGridY) ? CR_YELLOW : CR_DARKGRAY;
if (pic != NULL)
{
// Draw a normal character.
screen->DrawChar(SmallFont, color, xx + cell_width/2 - width*CleanXfac/2, yy + top_padding, ch, DTA_CleanNoMove, true, TAG_DONE);
}
else if (ch == ' ')
{
FRemapTable *remap = SmallFont->GetColorTranslation(color);
// Draw the space as a box outline. We also draw it 50% wider than it really is.
const int x1 = xx + cell_width/2 - width * CleanXfac * 3 / 4;
const int x2 = x1 + width * 3 * CleanXfac / 2;
const int y1 = yy + top_padding;
const int y2 = y1 + SmallFont->GetHeight() * CleanYfac;
const int palentry = remap->Remap[remap->NumEntries * 2 / 3];
const uint32 palcolor = remap->Palette[remap->NumEntries * 2 / 3];
screen->Clear(x1, y1, x2, y1+CleanYfac, palentry, palcolor); // top
screen->Clear(x1, y2, x2, y2+CleanYfac, palentry, palcolor); // bottom
screen->Clear(x1, y1+CleanYfac, x1+CleanXfac, y2, palentry, palcolor); // left
screen->Clear(x2-CleanXfac, y1+CleanYfac, x2, y2, palentry, palcolor); // right
}
else if (ch == '\b' || ch == 0)
{
// Draw the backspace and end "characters".
const char *const str = ch == '\b' ? "BS" : "ED";
screen->DrawText(SmallFont, color,
xx + cell_width/2 - SmallFont->StringWidth(str)*CleanXfac/2,
yy + top_padding, str, DTA_CleanNoMove, true, TAG_DONE);
}
}
}
}
Super::Drawer();
}
DEFINE_ACTION_FUNCTION(DTextEnterMenu, Open)
{
PARAM_PROLOGUE;
@ -389,8 +287,11 @@ DEFINE_ACTION_FUNCTION(DTextEnterMenu, Open)
ACTION_RETURN_OBJECT(m);
}
DEFINE_ACTION_FUNCTION(DTextEnterMenu, GetText)
{
PARAM_SELF_PROLOGUE(DTextEnterMenu);
ACTION_RETURN_STRING(self->GetText());
}
DEFINE_FIELD(DTextEnterMenu, mEnterString);
DEFINE_FIELD(DTextEnterMenu, mEnterSize);
DEFINE_FIELD(DTextEnterMenu, mEnterPos);
DEFINE_FIELD(DTextEnterMenu, mSizeMode); // 1: size is length in chars. 2: also check string width
DEFINE_FIELD(DTextEnterMenu, mInputGridOkay);
DEFINE_FIELD(DTextEnterMenu, InputGridX);
DEFINE_FIELD(DTextEnterMenu, InputGridY);
DEFINE_FIELD(DTextEnterMenu, AllowColors);

View file

@ -398,6 +398,20 @@ void DCanvas::Dim (PalEntry color, float damount, int x1, int y1, int w, int h)
}
}
DEFINE_ACTION_FUNCTION(_Screen, Dim)
{
PARAM_PROLOGUE;
PARAM_INT(color);
PARAM_FLOAT(amount);
PARAM_INT(x1);
PARAM_INT(y1);
PARAM_INT(w);
PARAM_INT(h);
screen->Dim(color, float(amount), x1, y1, w, h);
return 0;
}
//==========================================================================
//
// DCanvas :: GetScreenshotBuffer

View file

@ -162,6 +162,7 @@ struct Screen native
native static int GetWidth();
native static int GetHeight();
native static void Clear(int left, int top, int right, int bottom, Color color, int palcolor = -1);
native static void Dim(Color col, double amount, int x, int y, int w, int h);
native static void DrawHUDTexture(TextureID tex, double x, double y);
native static vararg void DrawTexture(TextureID tex, bool animate, double x, double y, ...);

View file

@ -2,14 +2,103 @@
// This is only the parts that are needed to make the menu fully work right now. More to come later.
class TextEnterMenu : Menu native
{
const INPUTGRID_WIDTH = 13;
const INPUTGRID_HEIGHT = 5;
const Chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+-=.,!?@'\":;[]()<>^#$%&*/_ \b";
native String mEnterString;
native int mEnterSize;
native int mEnterPos;
native int mSizeMode; // 1: size is length in chars. 2: also check string width
native bool mInputGridOkay;
native int InputGridX;
native int InputGridY;
native bool AllowColors;
native static TextEnterMenu Open(Menu parent, String text, int maxlen, int sizemode, bool fromcontroller);
native String GetText();
String GetText()
{
return mEnterString;
}
override bool TranslateKeyboardEvents()
{
return mInputGridOkay;
}
//=============================================================================
//
//
//
//=============================================================================
override void Drawer ()
{
mParentMenu.Drawer();
if (mInputGridOkay)
{
String InputGridChars = Chars;
int cell_width = 18 * CleanXfac;
int cell_height = 12 * CleanYfac;
int top_padding = cell_height / 2 - SmallFont.GetHeight() * CleanYfac / 2;
// Darken the background behind the character grid.
screen.Dim(0, 0.8, 0, screen.GetHeight() - INPUTGRID_HEIGHT * cell_height, screen.GetWidth(), INPUTGRID_HEIGHT * cell_height);
if (InputGridX >= 0 && InputGridY >= 0)
{
// Highlight the background behind the selected character.
screen.Dim(Color(255,248,220), 0.6,
InputGridX * cell_width - INPUTGRID_WIDTH * cell_width / 2 + screen.GetWidth() / 2,
InputGridY * cell_height - INPUTGRID_HEIGHT * cell_height + screen.GetHeight(),
cell_width, cell_height);
}
for (int y = 0; y < INPUTGRID_HEIGHT; ++y)
{
int yy = y * cell_height - INPUTGRID_HEIGHT * cell_height + screen.GetHeight();
for (int x = 0; x < INPUTGRID_WIDTH; ++x)
{
int xx = x * cell_width - INPUTGRID_WIDTH * cell_width / 2 + screen.GetWidth() / 2;
int ch = InputGridChars.CharCodeAt(y * INPUTGRID_WIDTH + x);
int width = SmallFont.GetCharWidth(ch);
// The highlighted character is yellow; the rest are dark gray.
int colr = (x == InputGridX && y == InputGridY) ? Font.CR_YELLOW : Font.CR_DARKGRAY;
Color palcolor = (x == InputGridX && y == InputGridY) ? Color(160, 120, 0) : Color(120, 120, 120);
if (ch > 32)
{
// Draw a normal character.
screen.DrawChar(SmallFont, colr, xx + cell_width/2 - width*CleanXfac/2, yy + top_padding, ch, DTA_CleanNoMove, true);
}
else if (ch == 32)
{
// Draw the space as a box outline. We also draw it 50% wider than it really is.
int x1 = xx + cell_width/2 - width * CleanXfac * 3 / 4;
int x2 = x1 + width * 3 * CleanXfac / 2;
int y1 = yy + top_padding;
int y2 = y1 + SmallFont.GetHeight() * CleanYfac;
screen.Clear(x1, y1, x2, y1+CleanYfac, palcolor); // top
screen.Clear(x1, y2, x2, y2+CleanYfac, palcolor); // bottom
screen.Clear(x1, y1+CleanYfac, x1+CleanXfac, y2, palcolor); // left
screen.Clear(x2-CleanXfac, y1+CleanYfac, x2, y2, palcolor); // right
}
else if (ch == 8 || ch == 0)
{
// Draw the backspace and end "characters".
String str = ch == 8 ? "BS" : "ED";
screen.DrawText(SmallFont, colr,
xx + cell_width/2 - SmallFont.StringWidth(str)*CleanXfac/2,
yy + top_padding, str, DTA_CleanNoMove, true);
}
}
}
}
Super.Drawer();
}
}