// 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); 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(); } }