void Widget_DrawLabel (WIDGET *_self, int x, int y) { WIDGET_LABEL *self = (WIDGET_LABEL *)_self; COLOR oldtext = SetContextForeGroundColor (WIDGET_INACTIVE_SELECTED_COLOR); FONT oldfont = SetContextFont (StarConFont); FRAME oldFontEffect = SetContextFontEffect (NULL); TEXT t; int i; t.baseline.x = 160; t.baseline.y = y; t.align = ALIGN_CENTER; t.CharCount = ~0; for (i = 0; i < self->line_count; i++) { t.pStr = self->lines[i]; font_DrawText (&t); t.baseline.y += 8; } SetContextFontEffect (oldFontEffect); SetContextFont (oldfont); SetContextForeGroundColor (oldtext); (void) x; }
void Widget_DrawLabel (WIDGET *_self, int x, int y) { WIDGET_LABEL *self = (WIDGET_LABEL *)_self; Color oldtext = SetContextForeGroundColor (WIDGET_INACTIVE_SELECTED_COLOR); FONT oldfont = 0; FRAME oldFontEffect = SetContextFontEffect (NULL); TEXT t; int i; if (cur_font) oldfont = SetContextFont (cur_font); t.baseline.x = 160 << RESOLUTION_FACTOR; // JMS_GFX t.baseline.y = y; t.align = ALIGN_CENTER; t.CharCount = ~0; for (i = 0; i < self->line_count; i++) { t.pStr = self->lines[i]; font_DrawText (&t); t.baseline.y += (8 << RESOLUTION_FACTOR); // JMS_GFX } SetContextFontEffect (oldFontEffect); if (oldfont) SetContextFont (oldfont); SetContextForeGroundColor (oldtext); (void) x; }
void Widget_DrawButton (WIDGET *_self, int x, int y) { WIDGET_BUTTON *self = (WIDGET_BUTTON *)_self; COLOR oldtext; COLOR inactive, selected; FONT oldfont = SetContextFont (StarConFont); FRAME oldFontEffect = SetContextFontEffect (NULL); TEXT t; selected = WIDGET_ACTIVE_COLOR; inactive = WIDGET_INACTIVE_COLOR; t.baseline.x = 160; t.baseline.y = y; t.align = ALIGN_CENTER; t.CharCount = ~0; t.pStr = self->name; if (widget_focus == _self) { Widget_DrawToolTips (3, self->tooltip); oldtext = SetContextForeGroundColor (selected); } else { oldtext = SetContextForeGroundColor (inactive); } font_DrawText (&t); SetContextFontEffect (oldFontEffect); SetContextFont (oldfont); SetContextForeGroundColor (oldtext); (void) x; }
static void Widget_DrawToolTips (int numlines, const char **tips) { RECT r; FONT oldfont = SetContextFont (StarConFont); FRAME oldFontEffect = SetContextFontEffect (NULL); COLOR oldtext = SetContextForeGroundColor (WIDGET_INACTIVE_SELECTED_COLOR); TEXT t; int i; r.corner.x = 2; r.corner.y = 2; r.extent.width = SCREEN_WIDTH - 4; r.extent.height = SCREEN_HEIGHT - 4; t.align = ALIGN_CENTER; t.CharCount = ~0; t.baseline.x = r.corner.x + (r.extent.width >> 1); t.baseline.y = r.corner.y + (r.extent.height - 8 - 8 * numlines); for (i = 0; i < numlines; i++) { t.pStr = tips[i]; font_DrawText(&t); t.baseline.y += 8; } SetContextFontEffect (oldFontEffect); SetContextFont (oldfont); SetContextForeGroundColor (oldtext); }
void Widget_DrawControlEntry (WIDGET *_self, int x, int y) { WIDGET_CONTROLENTRY *self = (WIDGET_CONTROLENTRY *)_self; COLOR oldtext; COLOR inactive, default_color, selected; FONT oldfont = SetContextFont (StarConFont); FRAME oldFontEffect = SetContextFontEffect (NULL); TEXT t; int i, home_x, home_y; default_color = WIDGET_INACTIVE_SELECTED_COLOR; selected = WIDGET_ACTIVE_COLOR; inactive = WIDGET_INACTIVE_COLOR; t.baseline.x = x; t.baseline.y = y; t.align = ALIGN_LEFT; t.CharCount = ~0; t.pStr = self->category; if (widget_focus == _self) { oldtext = SetContextForeGroundColor (selected); } else { oldtext = SetContextForeGroundColor (default_color); } font_DrawText (&t); // 3 * SCREEN_WIDTH / ((self->maxcolumns + 1) * 2)) as per CHOICE, but only two options. home_x = t.baseline.x + (SCREEN_WIDTH / 2); home_y = t.baseline.y; t.align = ALIGN_CENTER; for (i = 0; i < 2; i++) { t.baseline.x = home_x + ((i % 3) * (SCREEN_WIDTH / 3)); // self->maxcolumns + 1 as per CHOICE. t.baseline.y = home_y + (8 * (i / 3)); t.pStr = self->controlname[i]; if (!t.pStr[0]) { t.pStr = "---"; } if ((widget_focus == _self) && (self->highlighted == i)) { SetContextForeGroundColor (selected); } else { SetContextForeGroundColor (default_color); } font_DrawText (&t); } SetContextFontEffect (oldFontEffect); SetContextFont (oldfont); SetContextForeGroundColor (oldtext); }
void Widget_DrawChoice (WIDGET *_self, int x, int y) { WIDGET_CHOICE *self = (WIDGET_CHOICE *)_self; COLOR oldtext; COLOR inactive, default_color, selected; FONT oldfont = SetContextFont (StarConFont); FRAME oldFontEffect = SetContextFontEffect (NULL); TEXT t; int i, home_x, home_y; default_color = WIDGET_INACTIVE_SELECTED_COLOR; selected = WIDGET_ACTIVE_COLOR; inactive = WIDGET_INACTIVE_COLOR; t.baseline.x = x; t.baseline.y = y; t.align = ALIGN_LEFT; t.CharCount = ~0; t.pStr = self->category; if (widget_focus == _self) { oldtext = SetContextForeGroundColor (selected); } else { oldtext = SetContextForeGroundColor (default_color); } font_DrawText (&t); home_x = t.baseline.x + 3 * (SCREEN_WIDTH / ((self->maxcolumns + 1) * 2)); home_y = t.baseline.y; t.align = ALIGN_CENTER; for (i = 0; i < self->numopts; i++) { t.baseline.x = home_x + ((i % 3) * (SCREEN_WIDTH / (self->maxcolumns + 1))); t.baseline.y = home_y + (8 * (i / 3)); t.pStr = self->options[i].optname; if ((widget_focus == _self) && (self->highlighted == i)) { SetContextForeGroundColor (selected); Widget_DrawToolTips (3, self->options[i].tooltip); } else if (i == self->selected) { SetContextForeGroundColor (default_color); } else { SetContextForeGroundColor (inactive); } font_DrawText (&t); } SetContextFontEffect (oldFontEffect); SetContextFont (oldfont); SetContextForeGroundColor (oldtext); }
void Widget_DrawSlider(WIDGET *_self, int x, int y) { WIDGET_SLIDER *self = (WIDGET_SLIDER *)_self; Color oldtext; Color inactive, default_color, selected; FONT oldfont = 0; FRAME oldFontEffect = SetContextFontEffect (NULL); TEXT t; RECT r; int tick = (ScreenWidth - x) / 8; if (cur_font) oldfont = SetContextFont (cur_font); default_color = WIDGET_INACTIVE_SELECTED_COLOR; selected = WIDGET_ACTIVE_COLOR; inactive = WIDGET_INACTIVE_COLOR; t.baseline.x = x + 64 * RESOLUTION_FACTOR; // JMS_GFX; t.baseline.y = y; t.align = ALIGN_LEFT; t.CharCount = ~0; t.pStr = self->category; if (widget_focus == _self) { Widget_DrawToolTips (3, self->tooltip); oldtext = SetContextForeGroundColor (selected); } else { oldtext = SetContextForeGroundColor (default_color); } font_DrawText (&t); t.baseline.x -= 64 * RESOLUTION_FACTOR; // JMS_GFX; r.corner.x = t.baseline.x + 3 * tick; r.corner.y = t.baseline.y - 4; r.extent.height = 2; r.extent.width = 3 * tick; DrawFilledRectangle (&r); r.extent.width = 3; r.extent.height = 8; r.corner.y = t.baseline.y - 7; r.corner.x = t.baseline.x + 3 * tick + (3 * tick * (self->value - self->min) / (self->max - self->min)) - 1; DrawFilledRectangle (&r); (*self->draw_value)(self, t.baseline.x + 7 * tick, t.baseline.y); SetContextFontEffect (oldFontEffect); if (oldfont) SetContextFont (oldfont); SetContextForeGroundColor (oldtext); }
void DrawLabelAsWindow(WIDGET_LABEL *label) { COLOR oldfg = SetContextForeGroundColor (WIDGET_DIALOG_TEXT_COLOR); FONT oldfont = SetContextFont (StarConFont); FRAME oldFontEffect = SetContextFontEffect (NULL); RECT r; TEXT t; int i, win_w, win_h; /* Compute the dimensions of the label */ win_h = label->height ((WIDGET *)label) + 16; win_w = 0; for (i = 0; i < label->line_count; i++) { int len = utf8StringCount (label->lines[i]); if (len > win_w) { win_w = len; } } win_w = (win_w * 6) + 16; BatchGraphics (); r.corner.x = (SCREEN_WIDTH - win_w) >> 1; r.corner.y = (SCREEN_HEIGHT - win_h) >> 1; r.extent.width = win_w; r.extent.height = win_h; DrawShadowedBox (&r, SHADOWBOX_BACKGROUND_COLOR, SHADOWBOX_DARK_COLOR, SHADOWBOX_MEDIUM_COLOR); t.baseline.x = r.corner.x + (r.extent.width >> 1); t.baseline.y = r.corner.y + 16; for (i = 0; i < label->line_count; i++) { t.pStr = label->lines[i]; t.align = ALIGN_CENTER; t.CharCount = (COUNT)~0; font_DrawText (&t); t.baseline.y += 8; } UnbatchGraphics (); SetContextFontEffect (oldFontEffect); SetContextFont (oldfont); SetContextForeGroundColor (oldfg); }
static void DrawConfirmationWindow (BOOLEAN answer) { Color oldfg = SetContextForeGroundColor (MENU_TEXT_COLOR); FONT oldfont = SetContextFont (StarConFont); FRAME oldFontEffect = SetContextFontEffect (NULL); RECT r; TEXT t; BatchGraphics (); r.corner.x = (SCREEN_WIDTH - CONFIRM_WIN_WIDTH) >> 1; r.corner.y = (SCREEN_HEIGHT - CONFIRM_WIN_HEIGHT) >> 1; r.extent.width = CONFIRM_WIN_WIDTH; r.extent.height = CONFIRM_WIN_HEIGHT; DrawShadowedBox (&r, SHADOWBOX_BACKGROUND_COLOR, SHADOWBOX_DARK_COLOR, SHADOWBOX_MEDIUM_COLOR); t.baseline.x = r.corner.x + (r.extent.width >> 1); t.baseline.y = r.corner.y + (8 << RESOLUTION_FACTOR); // JMS_GFX t.pStr = GAME_STRING (QUITMENU_STRING_BASE); // "Really Quit?" t.align = ALIGN_CENTER; t.CharCount = (COUNT)~0; font_DrawText (&t); t.baseline.y += (10 << RESOLUTION_FACTOR); // JMS_GFX t.baseline.x = r.corner.x + (r.extent.width >> 2); t.pStr = GAME_STRING (QUITMENU_STRING_BASE + 1); // "Yes" SetContextForeGroundColor (answer ? MENU_HIGHLIGHT_COLOR : MENU_TEXT_COLOR); font_DrawText (&t); t.baseline.x += (r.extent.width >> 1); t.pStr = GAME_STRING (QUITMENU_STRING_BASE + 2); // "No" SetContextForeGroundColor (answer ? MENU_TEXT_COLOR : MENU_HIGHLIGHT_COLOR); font_DrawText (&t); UnbatchGraphics (); SetContextFontEffect (oldFontEffect); SetContextFont (oldfont); SetContextForeGroundColor (oldfg); }
static void Widget_DrawToolTips (int numlines, const char **tips) { // This functions draws the text at the bottom of the screen // which explains what the current option does. RECT r; FONT oldfont = 0; FRAME oldFontEffect = SetContextFontEffect (NULL); Color oldtext = SetContextForeGroundColor (WIDGET_INACTIVE_SELECTED_COLOR); TEXT t; int i; if (cur_font) oldfont = SetContextFont (cur_font); r.corner.x = 2 << RESOLUTION_FACTOR; // JMS_GFX r.corner.y = 2 << RESOLUTION_FACTOR; // JMS_GFX r.extent.width = ScreenWidth - (4 << RESOLUTION_FACTOR); // JMS_GFX r.extent.height = ScreenHeight - (4 << RESOLUTION_FACTOR); // JMS_GFX t.align = ALIGN_CENTER; t.CharCount = ~0; t.baseline.x = r.corner.x + (r.extent.width >> 1); t.baseline.y = r.corner.y + (r.extent.height - (8 << RESOLUTION_FACTOR) - (8 << RESOLUTION_FACTOR) * numlines); // JMS_GFX for (i = 0; i < numlines; i++) { t.pStr = tips[i]; font_DrawText(&t); t.baseline.y += (8 << RESOLUTION_FACTOR); // JMS_GFX } SetContextFontEffect (oldFontEffect); if (oldfont) SetContextFont (oldfont); SetContextForeGroundColor (oldtext); }
// windowRect, if not NULL, will be filled with the dimensions of the // window drawn. void DrawLabelAsWindow (WIDGET_LABEL *label, RECT *windowRect) { Color oldfg = SetContextForeGroundColor (WIDGET_DIALOG_TEXT_COLOR); FONT oldfont = 0; FRAME oldFontEffect = SetContextFontEffect (NULL); RECT r; TEXT t; int i, win_w, win_h; if (cur_font) oldfont = SetContextFont (cur_font); /* Compute the dimensions of the label */ win_h = label->height ((WIDGET *)label) + (16 << RESOLUTION_FACTOR); // JMS_GFX win_w = 0; for (i = 0; i < label->line_count; i++) { int len = utf8StringCount (label->lines[i]); if (len > win_w) { win_w = len; } } win_w = (win_w * (6 << RESOLUTION_FACTOR)) + (16 << RESOLUTION_FACTOR); // JMS_GFX BatchGraphics (); r.corner.x = (ScreenWidth - win_w) >> 1; r.corner.y = (ScreenHeight - win_h) >> 1; r.extent.width = win_w; r.extent.height = win_h; DrawShadowedBox (&r, win_bg_clr, win_dark_clr, win_medium_clr); t.baseline.x = r.corner.x + (r.extent.width >> 1); t.baseline.y = r.corner.y + (16 << RESOLUTION_FACTOR); // JMS_GFX for (i = 0; i < label->line_count; i++) { t.pStr = label->lines[i]; t.align = ALIGN_CENTER; t.CharCount = (COUNT)~0; font_DrawText (&t); t.baseline.y += (8 << RESOLUTION_FACTOR); // JMS_GFX } UnbatchGraphics (); SetContextFontEffect (oldFontEffect); if (oldfont) SetContextFont (oldfont); SetContextForeGroundColor (oldfg); if (windowRect != NULL) { // Add the outer border added by DrawShadowedBox. // XXX: It may be nicer to add a border size parameter to // DrawShadowedBox, instead of assuming 2 here. windowRect->corner.x = r.corner.x - 2 * (1 + RESOLUTION_FACTOR); windowRect->corner.y = r.corner.y - 2 * (1 + RESOLUTION_FACTOR); windowRect->extent.width = r.extent.width + 4 * (1 + RESOLUTION_FACTOR); windowRect->extent.height = r.extent.height + 4 * (1 + RESOLUTION_FACTOR); } }
void Widget_DrawTextEntry (WIDGET *_self, int x, int y) { WIDGET_TEXTENTRY *self = (WIDGET_TEXTENTRY *)_self; Color oldtext; Color inactive, default_color, selected; FONT oldfont = 0; FRAME oldFontEffect = SetContextFontEffect (NULL); TEXT t; if (cur_font) oldfont = SetContextFont (cur_font); default_color = WIDGET_INACTIVE_SELECTED_COLOR; selected = WIDGET_ACTIVE_COLOR; inactive = WIDGET_INACTIVE_COLOR; BatchGraphics (); t.baseline.x = x + 64 * RESOLUTION_FACTOR; // JMS_GFX t.baseline.y = y; t.align = ALIGN_LEFT; t.CharCount = ~0; t.pStr = self->category; if (widget_focus == _self) { oldtext = SetContextForeGroundColor (selected); } else { oldtext = SetContextForeGroundColor (default_color); } font_DrawText (&t); t.baseline.x -= 64 * RESOLUTION_FACTOR; // JMS_GFX /* Force string termination */ self->value[WIDGET_TEXTENTRY_WIDTH-1] = 0; t.baseline.y = y; t.CharCount = utf8StringCount (self->value); t.pStr = self->value; if (!(self->state & WTE_EDITING)) { // normal or selected state t.baseline.x = 160 << RESOLUTION_FACTOR; // JMS_GFX t.align = ALIGN_CENTER; if (widget_focus == _self) { oldtext = SetContextForeGroundColor (selected); } else { oldtext = SetContextForeGroundColor (inactive); } font_DrawText (&t); } else { // editing state COUNT i; RECT text_r; BYTE char_deltas[WIDGET_TEXTENTRY_WIDTH]; BYTE *pchar_deltas; RECT r; SIZE leading; t.baseline.x = 90 << RESOLUTION_FACTOR; // JMS_GFX t.align = ALIGN_LEFT; // calc background box dimensions // XXX: this may need some tuning, especially if a // different font is used. The font 'leading' values // are not what they should be. #define BOX_VERT_OFFSET 2 GetContextFontLeading (&leading); r.corner.x = t.baseline.x - 1; r.corner.y = t.baseline.y - leading + BOX_VERT_OFFSET; r.extent.width = ScreenWidth - r.corner.x - 10; r.extent.height = leading + 2; TextRect (&t, &text_r, char_deltas); #if 0 // XXX: this should potentially be used in ChangeCallback if ((text_r.extent.width + 2) >= r.extent.width) { // the text does not fit the input box size and so // will not fit when displayed later UnbatchGraphics (); // disallow the change return (FALSE); } #endif oldtext = SetContextForeGroundColor (selected); DrawFilledRectangle (&r); // calculate the cursor position and draw it pchar_deltas = char_deltas; for (i = self->cursor_pos; i > 0; --i) r.corner.x += (SIZE)*pchar_deltas++; if (self->cursor_pos < t.CharCount) /* cursor mid-line */ --r.corner.x; if (self->state & WTE_BLOCKCUR) { // Use block cursor for keyboardless systems if (self->cursor_pos == t.CharCount) { // cursor at end-line -- use insertion point r.extent.width = 1; } else if (self->cursor_pos + 1 == t.CharCount) { // extra pixel for last char margin r.extent.width = (SIZE)*pchar_deltas + 2; } else { // normal mid-line char r.extent.width = (SIZE)*pchar_deltas + 1; } } else { // Insertion point cursor r.extent.width = 1; } // position cursor within input field rect ++r.corner.x; ++r.corner.y; r.extent.height -= 2; SetContextForeGroundColor (WIDGET_CURSOR_COLOR); DrawFilledRectangle (&r); SetContextForeGroundColor (inactive); font_DrawText (&t); } UnbatchGraphics (); SetContextFontEffect (oldFontEffect); if (oldfont) SetContextFont (oldfont); SetContextForeGroundColor (oldtext); }
void Widget_DrawMenuScreen (WIDGET *_self, int x, int y) { RECT r; Color title, oldtext; Color inactive, default_color, selected; FONT oldfont = 0; FRAME oldFontEffect = SetContextFontEffect (NULL); TEXT t; int widget_index, height, widget_y; WIDGET_MENU_SCREEN *self = (WIDGET_MENU_SCREEN *)_self; if (cur_font) oldfont = SetContextFont (cur_font); r.corner.x = (2 << RESOLUTION_FACTOR) + 2 * RESOLUTION_FACTOR; // JMS_GFX r.corner.y = (2 << RESOLUTION_FACTOR); // JMS_GFX r.extent.width = ScreenWidth - (4 << RESOLUTION_FACTOR); // JMS_GFX r.extent.height = ScreenHeight - (4 << RESOLUTION_FACTOR); // JMS_GFX title = WIDGET_INACTIVE_SELECTED_COLOR; selected = WIDGET_ACTIVE_COLOR; inactive = WIDGET_INACTIVE_COLOR; default_color = title; DrawStamp (&self->bgStamp); oldtext = SetContextForeGroundColor (title); t.baseline.x = r.corner.x + (r.extent.width >> 1); t.baseline.y = r.corner.y + (8 << RESOLUTION_FACTOR); // JMS_GFX t.pStr = self->title; t.align = ALIGN_CENTER; t.CharCount = ~0; font_DrawText (&t); t.baseline.y += 8 << RESOLUTION_FACTOR; // JMS_GFX t.pStr = self->subtitle; font_DrawText (&t); height = 0; for (widget_index = 0; widget_index < self->num_children; widget_index++) { WIDGET *child = self->child[widget_index]; height += (*child->height)(child); height += 8 << RESOLUTION_FACTOR; // JMS_GFX /* spacing */ } height -= 8 << RESOLUTION_FACTOR; // JMS_GFX widget_y = (ScreenHeight - height) >> 1; for (widget_index = 0; widget_index < self->num_children; widget_index++) { WIDGET *c = self->child[widget_index]; (*c->draw)(c, 0, widget_y); widget_y += (*c->height)(c) + (8 << RESOLUTION_FACTOR); // JMS_GFX } SetContextFontEffect (oldFontEffect); if (oldfont) SetContextFont (oldfont); SetContextForeGroundColor (oldtext); (void) x; (void) y; }
void Widget_DrawMenuScreen (WIDGET *_self, int x, int y) { RECT r; COLOR title, oldtext; COLOR inactive, default_color, selected; FONT oldfont = SetContextFont (StarConFont); FRAME oldFontEffect = SetContextFontEffect (NULL); TEXT t; int widget_index, height, widget_y; WIDGET_MENU_SCREEN *self = (WIDGET_MENU_SCREEN *)_self; r.corner.x = 2; r.corner.y = 2; r.extent.width = SCREEN_WIDTH - 4; r.extent.height = SCREEN_HEIGHT - 4; title = WIDGET_INACTIVE_SELECTED_COLOR; selected = WIDGET_ACTIVE_COLOR; inactive = WIDGET_INACTIVE_COLOR; default_color = title; DrawStamp (&self->bgStamp); oldtext = SetContextForeGroundColor (title); t.baseline.x = r.corner.x + (r.extent.width >> 1); t.baseline.y = r.corner.y + 8; t.pStr = self->title; t.align = ALIGN_CENTER; t.CharCount = ~0; font_DrawText (&t); t.baseline.y += 8; t.pStr = self->subtitle; font_DrawText (&t); height = 0; for (widget_index = 0; widget_index < self->num_children; widget_index++) { WIDGET *child = self->child[widget_index]; height += (*child->height)(child); height += 8; /* spacing */ } height -= 8; widget_y = (SCREEN_HEIGHT - height) >> 1; for (widget_index = 0; widget_index < self->num_children; widget_index++) { WIDGET *c = self->child[widget_index]; (*c->draw)(c, 0, widget_y); widget_y += (*c->height)(c) + 8; } SetContextFontEffect (oldFontEffect); SetContextFont (oldfont); SetContextForeGroundColor (oldtext); (void) x; (void) y; }