static void TXT_KeyInputDrawer(TXT_UNCAST_ARG(key_input)) { TXT_CAST_ARG(txt_key_input_t, key_input); char buf[20]; int i; if (*key_input->variable == 0) { M_StringCopy(buf, "(none)", sizeof(buf)); } else { TXT_GetKeyDescription(*key_input->variable, buf, sizeof(buf)); } TXT_SetWidgetBG(key_input); TXT_FGColor(TXT_COLOR_BRIGHT_WHITE); TXT_DrawString(buf); for (i=strlen(buf); i<KEY_INPUT_WIDTH; ++i) { TXT_DrawString(" "); } }
static void TXT_MouseInputDrawer(TXT_UNCAST_ARG(mouse_input)) { TXT_CAST_ARG(txt_mouse_input_t, mouse_input); char buf[20]; int i; if (*mouse_input->variable < 0) { M_StringCopy(buf, "(none)", sizeof(buf)); } else { GetMouseButtonDescription(*mouse_input->variable, buf, sizeof(buf)); } TXT_SetWidgetBG(mouse_input); TXT_FGColor(TXT_COLOR_BRIGHT_WHITE); TXT_DrawString(buf); for (i=strlen(buf); i<MOUSE_INPUT_WIDTH; ++i) { TXT_DrawString(" "); } }
static void TXT_JoystickInputDrawer(TXT_UNCAST_ARG(joystick_input)) { TXT_CAST_ARG(txt_joystick_input_t, joystick_input); char buf[20]; int i; if (*joystick_input->variable < 0) { M_StringCopy(buf, "(none)", sizeof(buf)); } else { GetJoystickButtonDescription(*joystick_input->variable, buf, sizeof(buf)); } TXT_SetWidgetBG(joystick_input); TXT_FGColor(TXT_COLOR_BRIGHT_WHITE); TXT_DrawString(buf); for (i=strlen(buf); i<JOYSTICK_INPUT_WIDTH; ++i) { TXT_DrawString(" "); } }
static void TXT_JoystickInputDrawer(TXT_UNCAST_ARG(joystick_input), int selected) { TXT_CAST_ARG(txt_joystick_input_t, joystick_input); char buf[20]; int i; if (*joystick_input->variable < 0) { strcpy(buf, "(none)"); } else { GetJoystickButtonDescription(*joystick_input->variable, buf); } if (selected) { TXT_BGColor(TXT_COLOR_GREY, 0); } else { TXT_BGColor(TXT_COLOR_BLUE, 0); } TXT_FGColor(TXT_COLOR_BRIGHT_WHITE); TXT_DrawString(buf); for (i=strlen(buf); i<JOYSTICK_INPUT_WIDTH; ++i) { TXT_DrawString(" "); } }
static void TXT_SeparatorDrawer(TXT_UNCAST_ARG(separator)) { TXT_CAST_ARG(txt_separator_t, separator); int x, y; int w; w = separator->widget.w; TXT_GetXY(&x, &y); // Draw separator. Go back one character and draw two extra // to overlap the window borders. TXT_DrawSeparator(x-2, y, w + 4); if (separator->label != NULL) { TXT_GotoXY(x, y); TXT_FGColor(TXT_COLOR_BRIGHT_GREEN); TXT_DrawString(" "); TXT_DrawString(separator->label); TXT_DrawString(" "); } }
static void TXT_WindowActionDrawer(TXT_UNCAST_ARG(action)) { TXT_CAST_ARG(txt_window_action_t, action); char buf[10]; TXT_GetKeyDescription(action->key, buf); if (TXT_HoveringOverWidget(action)) { TXT_BGColor(TXT_COLOR_BLACK, 0); } else { TXT_BGColor(TXT_WINDOW_BACKGROUND, 0); } TXT_DrawString(" "); TXT_FGColor(TXT_COLOR_BRIGHT_GREEN); TXT_DrawString(buf); TXT_FGColor(TXT_COLOR_BRIGHT_CYAN); TXT_DrawString("="); TXT_FGColor(TXT_COLOR_BRIGHT_WHITE); TXT_DrawString(action->label); TXT_DrawString(" "); }
static void TXT_InputBoxDrawer(TXT_UNCAST_ARG(inputbox)) { TXT_CAST_ARG(txt_inputbox_t, inputbox); int focused; int i; int chars; int w; focused = inputbox->widget.focused; w = inputbox->widget.w; // Select the background color based on whether we are currently // editing, and if not, whether the widget is focused. if (inputbox->editing && focused) { TXT_BGColor(TXT_COLOR_BLACK, 0); } else { TXT_SetWidgetBG(inputbox); } if (!inputbox->editing) { // If not editing, use the current value from inputbox->value. SetBufferFromValue(inputbox); } // If string size exceeds the widget's width, show only the end. if (TXT_UTF8_Strlen(inputbox->buffer) > w - 1) { TXT_DrawString("\xae"); TXT_DrawUTF8String( TXT_UTF8_SkipChars(inputbox->buffer, TXT_UTF8_Strlen(inputbox->buffer) - w + 2)); chars = w - 1; } else { TXT_DrawUTF8String(inputbox->buffer); chars = TXT_UTF8_Strlen(inputbox->buffer); } if (chars < w && inputbox->editing && focused) { TXT_BGColor(TXT_COLOR_BLACK, 1); TXT_DrawString("_"); ++chars; } for (i=chars; i < w; ++i) { TXT_DrawString(" "); } }
static void TXT_LabelDrawer(TXT_UNCAST_ARG(label), int selected) { TXT_CAST_ARG(txt_label_t, label); unsigned int x, y; int origin_x, origin_y; unsigned int align_indent = 0; unsigned int w; w = label->widget.w; TXT_BGColor(label->bgcolor, 0); TXT_FGColor(label->fgcolor); TXT_GetXY(&origin_x, &origin_y); for (y=0; y<label->h; ++y) { // Calculate the amount to indent this line due to the align // setting switch (label->widget.align) { case TXT_HORIZ_LEFT: align_indent = 0; break; case TXT_HORIZ_CENTER: align_indent = (label->w - strlen(label->lines[y])) / 2; break; case TXT_HORIZ_RIGHT: align_indent = label->w - strlen(label->lines[y]); break; } // Draw this line TXT_GotoXY(origin_x, origin_y + y); // Gap at the start for (x=0; x<align_indent; ++x) { TXT_DrawString(" "); } // The string itself TXT_DrawString(label->lines[y]); x += strlen(label->lines[y]); // Gap at the end for (; x<w; ++x) { TXT_DrawString(" "); } } }
void TXT_DrawWindowFrame(const char *title, int x, int y, int w, int h) { int x1, y1; int bx, by; TXT_FGColor(TXT_COLOR_BRIGHT_CYAN); TXT_BGColor(TXT_WINDOW_BACKGROUND, 0); for (y1=y; y1<y+h; ++y1) { // Select the appropriate row and column in the borders // array to pick the appropriate character to draw at // this location. // // Draw a horizontal line on the third line down, so we // draw a box around the title. by = y1 == y ? 0 : y1 == y + 2 && title != NULL ? 2 : y1 == y + h - 1 ? 3 : 1; for (x1=x; x1<x+w; ++x1) { bx = x1 == x ? 0 : x1 == x + w - 1 ? 3 : 1; if (VALID_X(x1) && VALID_Y(y1)) { TXT_GotoXY(x1, y1); TXT_PutChar(borders[by][bx]); } } } // Draw the title if (title != NULL) { TXT_GotoXY(x + 1, y + 1); TXT_BGColor(TXT_COLOR_GREY, 0); TXT_FGColor(TXT_COLOR_BLUE); for (x1=0; x1<w-2; ++x1) { TXT_DrawString(" "); } TXT_GotoXY(x + (w - strlen(title)) / 2, y + 1); TXT_DrawString(title); } // Draw the window's shadow. TXT_DrawShadow(x + 2, y + h, w, 1); TXT_DrawShadow(x + w, y + 1, 2, h); }
static void TXT_SpinControlDrawer(TXT_UNCAST_ARG(spincontrol), int selected) { TXT_CAST_ARG(txt_spincontrol_t, spincontrol); unsigned int i; unsigned int padding; TXT_FGColor(TXT_COLOR_BRIGHT_CYAN); TXT_BGColor(TXT_COLOR_BLUE, 0); TXT_DrawString("\x1b "); TXT_FGColor(TXT_COLOR_BRIGHT_WHITE); // Choose background color if (selected && spincontrol->editing) { TXT_BGColor(TXT_COLOR_BLACK, 0); } else if (selected) { TXT_BGColor(TXT_COLOR_GREY, 0); } else { TXT_BGColor(TXT_COLOR_BLUE, 0); } if (!spincontrol->editing) { SetBuffer(spincontrol); } i = 0; padding = spincontrol->widget.w - strlen(spincontrol->buffer) - 4; while (i < padding) { TXT_DrawString(" "); ++i; } TXT_DrawString(spincontrol->buffer); i += strlen(spincontrol->buffer); while (i < spincontrol->widget.w - 4) { TXT_DrawString(" "); ++i; } TXT_FGColor(TXT_COLOR_BRIGHT_CYAN); TXT_BGColor(TXT_COLOR_BLUE, 0); TXT_DrawString(" \x1a"); }
static void TXT_SpinControlDrawer(TXT_UNCAST_ARG(spincontrol)) { TXT_CAST_ARG(txt_spincontrol_t, spincontrol); unsigned int i; unsigned int padding; int focused; focused = spincontrol->widget.focused; TXT_FGColor(TXT_COLOR_BRIGHT_CYAN); TXT_BGColor(TXT_WINDOW_BACKGROUND, 0); TXT_DrawString("\x1b "); TXT_FGColor(TXT_COLOR_BRIGHT_WHITE); // Choose background color if (focused && spincontrol->editing) { TXT_BGColor(TXT_COLOR_BLACK, 0); } else { TXT_SetWidgetBG(spincontrol); } if (!spincontrol->editing) { SetBuffer(spincontrol); } i = 0; padding = spincontrol->widget.w - strlen(spincontrol->buffer) - 4; while (i < padding) { TXT_DrawString(" "); ++i; } TXT_DrawString(spincontrol->buffer); i += strlen(spincontrol->buffer); while (i < spincontrol->widget.w - 4) { TXT_DrawString(" "); ++i; } TXT_FGColor(TXT_COLOR_BRIGHT_CYAN); TXT_BGColor(TXT_WINDOW_BACKGROUND, 0); TXT_DrawString(" \x1a"); }
static void TXT_InputBoxDrawer(TXT_UNCAST_ARG(inputbox), int selected) { TXT_CAST_ARG(txt_inputbox_t, inputbox); int i; int chars; int w; w = inputbox->widget.w; // Select the background color based on whether we are currently // editing, and if not, whether the widget is selected. if (inputbox->editing && selected) { TXT_BGColor(TXT_COLOR_BLACK, 0); } else if (selected) { TXT_BGColor(TXT_COLOR_GREY, 0); } else { // Not even selected TXT_BGColor(TXT_COLOR_BLUE, 0); } TXT_FGColor(TXT_COLOR_BRIGHT_WHITE); if (!inputbox->editing) { // If not editing, use the current value from inputbox->value. SetBufferFromValue(inputbox); } TXT_DrawString(inputbox->buffer); chars = strlen(inputbox->buffer); if (chars < w && inputbox->editing && selected) { TXT_BGColor(TXT_COLOR_BLACK, 1); TXT_DrawString("_"); ++chars; } for (i=chars; i < w; ++i) { TXT_DrawString(" "); } }
static void TXT_WindowActionDrawer(TXT_UNCAST_ARG(action), int selected) { TXT_CAST_ARG(txt_window_action_t, action); char buf[10]; TXT_GetKeyDescription(action->key, buf); TXT_FGColor(TXT_COLOR_BRIGHT_GREEN); TXT_DrawString(buf); TXT_FGColor(TXT_COLOR_BRIGHT_CYAN); TXT_DrawString("="); TXT_FGColor(TXT_COLOR_BRIGHT_WHITE); TXT_DrawString(action->label); }
void TXT_DrawDesktopBackground(const char *title) { int i; unsigned char *screendata; unsigned char *p; screendata = TXT_GetScreenData(); // Fill the screen with gradient characters p = screendata; for (i=0; i<TXT_SCREEN_W * TXT_SCREEN_H; ++i) { *p++ = 0xb1; *p++ = TXT_COLOR_GREY | (TXT_COLOR_BLUE << 4); } // Draw the top and bottom banners p = screendata; for (i=0; i<TXT_SCREEN_W; ++i) { *p++ = ' '; *p++ = TXT_COLOR_BLACK | (TXT_COLOR_GREY << 4); } p = screendata + (TXT_SCREEN_H - 1) * TXT_SCREEN_W * 2; for (i=0; i<TXT_SCREEN_W; ++i) { *p++ = ' '; *p++ = TXT_COLOR_BLACK | (TXT_COLOR_GREY << 4); } // Print the title TXT_GotoXY(0, 0); TXT_FGColor(TXT_COLOR_BLACK); TXT_BGColor(TXT_COLOR_GREY, 0); TXT_DrawString(" "); TXT_DrawString(title); }
static void TXT_JoystickAxisDrawer(TXT_UNCAST_ARG(joystick_axis)) { TXT_CAST_ARG(txt_joystick_axis_t, joystick_axis); char buf[JOYSTICK_AXIS_WIDTH + 1]; int i; if (*joystick_axis->axis < 0) { M_StringCopy(buf, "(none)", sizeof(buf)); } else if (IS_BUTTON_AXIS(*joystick_axis->axis)) { int neg, pos; neg = BUTTON_AXIS_NEG(*joystick_axis->axis); pos = BUTTON_AXIS_POS(*joystick_axis->axis); M_snprintf(buf, sizeof(buf), "BUTTONS #%i+#%i", neg, pos); } else if (IS_HAT_AXIS(*joystick_axis->axis)) { int hat, dir; hat = HAT_AXIS_HAT(*joystick_axis->axis); dir = HAT_AXIS_DIRECTION(*joystick_axis->axis); M_snprintf(buf, sizeof(buf), "HAT #%i (%s)", hat, dir == HAT_AXIS_HORIZONTAL ? "horizontal" : "vertical"); } else { M_snprintf(buf, sizeof(buf), "AXIS #%i", *joystick_axis->axis); } TXT_SetWidgetBG(joystick_axis); TXT_FGColor(TXT_COLOR_BRIGHT_WHITE); TXT_DrawString(buf); for (i = TXT_UTF8_Strlen(buf); i < joystick_axis->widget.w; ++i) { TXT_DrawString(" "); } }
static void TXT_DropdownListDrawer(TXT_UNCAST_ARG(list), int selected) { TXT_CAST_ARG(txt_dropdown_list_t, list); unsigned int i; const char *str; // Set bg/fg text colors. if (selected) { TXT_BGColor(TXT_COLOR_GREY, 0); } else { TXT_BGColor(TXT_COLOR_BLUE, 0); } TXT_FGColor(TXT_COLOR_BRIGHT_WHITE); // Select a string to draw from the list, if the current value is // in range. Otherwise fall back to a default. if (ValidSelection(list)) { str = list->values[*list->variable]; } else { str = "???"; } // Draw the string and fill to the end with spaces TXT_DrawString(str); for (i=strlen(str); i<list->widget.w; ++i) { TXT_DrawString(" "); } }
static void TXT_ButtonDrawer(TXT_UNCAST_ARG(button), int selected) { TXT_CAST_ARG(txt_button_t, button); int i; int w; w = button->widget.w; TXT_BGColor(TXT_COLOR_BLUE, 0); TXT_FGColor(TXT_COLOR_BRIGHT_WHITE); if (selected) { TXT_BGColor(TXT_COLOR_GREY, 0); } TXT_DrawString(button->label); for (i=strlen(button->label); i < w; ++i) { TXT_DrawString(" "); } }
static void TXT_CheckBoxDrawer(TXT_UNCAST_ARG(checkbox), int selected) { TXT_CAST_ARG(txt_checkbox_t, checkbox); int i; int w; w = checkbox->widget.w; TXT_BGColor(TXT_COLOR_BLUE, 0); TXT_FGColor(TXT_COLOR_BRIGHT_CYAN); TXT_DrawString(" ("); TXT_FGColor(TXT_COLOR_BRIGHT_WHITE); if ((*checkbox->variable != 0) ^ checkbox->inverted) { TXT_DrawString("\x07"); } else { TXT_DrawString(" "); } TXT_FGColor(TXT_COLOR_BRIGHT_CYAN); TXT_DrawString(") "); if (selected) { TXT_BGColor(TXT_COLOR_GREY, 0); } TXT_FGColor(TXT_COLOR_BRIGHT_WHITE); TXT_DrawString(checkbox->label); for (i=strlen(checkbox->label); i < w-6; ++i) { TXT_DrawString(" "); } }
static void TXT_CheckBoxDrawer(TXT_UNCAST_ARG(checkbox)) { TXT_CAST_ARG(txt_checkbox_t, checkbox); int i; int w; w = checkbox->widget.w; TXT_BGColor(TXT_WINDOW_BACKGROUND, 0); TXT_FGColor(TXT_COLOR_BRIGHT_CYAN); TXT_DrawString("("); TXT_FGColor(TXT_COLOR_BRIGHT_WHITE); if ((*checkbox->variable != 0) ^ checkbox->inverted) { TXT_DrawString("\x07"); } else { TXT_DrawString(" "); } TXT_FGColor(TXT_COLOR_BRIGHT_CYAN); TXT_DrawString(") "); TXT_SetWidgetBG(checkbox); TXT_FGColor(TXT_COLOR_BRIGHT_WHITE); TXT_DrawString(checkbox->label); for (i=strlen(checkbox->label); i < w-5; ++i) { TXT_DrawString(" "); } }
static void TXT_RadioButtonDrawer(TXT_UNCAST_ARG(radiobutton)) { TXT_CAST_ARG(txt_radiobutton_t, radiobutton); int i; int w; w = radiobutton->widget.w; TXT_BGColor(TXT_WINDOW_BACKGROUND, 0); TXT_FGColor(TXT_COLOR_BRIGHT_CYAN); TXT_DrawString("("); TXT_FGColor(TXT_COLOR_BRIGHT_WHITE); if (*radiobutton->variable == radiobutton->value) { TXT_DrawString("\x07"); } else { TXT_DrawString(" "); } TXT_FGColor(TXT_COLOR_BRIGHT_CYAN); TXT_DrawString(") "); TXT_SetWidgetBG(radiobutton); TXT_FGColor(TXT_COLOR_BRIGHT_WHITE); TXT_DrawString(radiobutton->label); for (i=strlen(radiobutton->label); i < w-5; ++i) { TXT_DrawString(" "); } }