/** * Draw a dialog popup button object. */ static void SDLGui_DrawPopupButton(const SGOBJ *pdlg, int32_t objnum) { int32_t x, y, w; const char *downstr = "\x02"; SDLGui_DrawBox(pdlg, objnum); x = (pdlg[0].x + pdlg[objnum].x) * sdlgui_fontwidth; y = (pdlg[0].y + pdlg[objnum].y) * sdlgui_fontheight; w = pdlg[objnum].w * sdlgui_fontwidth; SDLGui_Text(x, y, pdlg[objnum].txt); SDLGui_Text(x+w-sdlgui_fontwidth, y, downstr); }
/** * Draw a dialog text object. */ static void SDLGui_DrawText(const SGOBJ *tdlg, int32_t objnum) { int32_t x, y; x = (tdlg[0].x+tdlg[objnum].x)*sdlgui_fontwidth; y = (tdlg[0].y+tdlg[objnum].y)*sdlgui_fontheight; SDLGui_Text(x, y, tdlg[objnum].txt); }
/* Draw a normal button. */ void SDLGui_DrawButton(SGOBJ *bdlg, int objnum) { SDL_Rect coord; int x, y; int textc; SDLGui_ObjCoord(bdlg, objnum, &coord); x = coord.x + ((coord.w - (strlen(bdlg[objnum].txt) * fontwidth)) / 2); y = coord.y + ((coord.h - fontheight) / 2); if (bdlg[objnum].state & SG_SELECTED) { x += 1; y += 1; } if (bdlg[objnum].state & SG_DISABLED) textc = darkgreyc; else textc = blackc; SDLGui_DrawBox(bdlg, objnum); SDLGui_Text(x, y, bdlg[objnum].txt, textc); }
/* Draw a dialog text object. */ void SDLGui_DrawText(SGOBJ *tdlg, int objnum) { SDL_Rect coord; int textc, backgroundc; if (tdlg[objnum].state & SG_SELECTED) { textc = whitec; backgroundc = darkgreyc; } else if (tdlg[objnum].state & SG_DISABLED) { textc = darkgreyc; backgroundc = greyc; } else { textc = blackc; backgroundc = greyc; } SDLGui_ObjCoord(tdlg, objnum, &coord); SDL_FillRect(sdlscrn, &coord, SDLGui_MapColor(backgroundc)); SDLGui_Text(coord.x, coord.y, tdlg[objnum].txt, textc); }
/* Draw a dialog popup button object. */ void SDLGui_DrawPopupButton(SGOBJ *pdlg, int objnum) { SDL_Rect coord; const char *downstr = "\x02"; int textc; if (pdlg[objnum].state & SG_DISABLED) textc = darkgreyc; else textc = blackc; SDLGui_DrawBox(pdlg, objnum); SDLGui_ObjCoord(pdlg, objnum, &coord); SDLGui_Text(coord.x, coord.y, pdlg[objnum].txt, textc); SDLGui_Text(coord.x+coord.w-fontwidth, coord.y, downstr, textc); }
/** * Draw a edit field object. */ static void SDLGui_DrawEditField(const SGOBJ *edlg, int32_t objnum) { int32_t x, y; SDL_Rect rect; x = (edlg[0].x+edlg[objnum].x)*sdlgui_fontwidth; y = (edlg[0].y+edlg[objnum].y)*sdlgui_fontheight; SDLGui_Text(x, y, edlg[objnum].txt); DrawBoxF(x,y+ edlg[objnum].h * fontheight,0,edlg[objnum].w * fontwidth,1,0xA0A0A0FF); }
/** * Draw 'msg' centered to the message area */ static void Statusbar_DrawMessage(SDL_Surface *surf, const char *msg) { int fontw, fonth, offset; SDL_FillRect(surf, &MessageRect, GrayBg); if (*msg) { SDLGui_GetFontSize(&fontw, &fonth); offset = (MessageRect.w - strlen(msg) * fontw) / 2; SDLGui_Text(MessageRect.x + offset, MessageRect.y, msg); } SDL_UpdateRects(surf, 1, &MessageRect); DEBUGPRINT(("Draw message: '%s'\n", msg)); }
/** * Draw a edit field object. */ static void SDLGui_DrawEditField(const SGOBJ *edlg, int objnum) { int x, y; SDL_Rect rect; x = (edlg[0].x+edlg[objnum].x)*sdlgui_fontwidth; y = (edlg[0].y+edlg[objnum].y)*sdlgui_fontheight; SDLGui_Text(x, y, edlg[objnum].txt); rect.x = x; rect.y = y + edlg[objnum].h * sdlgui_fontheight; rect.w = edlg[objnum].w * sdlgui_fontwidth; rect.h = 1; SDL_FillRect(pSdlGuiScrn, &rect, colors.editfield); }
/* Draw a dialog check box object state. */ void SDLGui_DrawCheckBoxState(SGOBJ *cdlg, int objnum) { Uint32 grey = SDLGui_MapColor(greyc); SDL_Rect coord; char str[3]; int textc; SDLGui_ObjCoord(cdlg, objnum, &coord); if (cdlg[objnum].flags & SG_RADIO) { if (cdlg[objnum].state & SG_SELECTED) { str[0]=SGCHECKBOX_RADIO_SELECTED; str[1]=SGCHECKBOX_RADIO_SELECTEd; } else { str[0]=SGCHECKBOX_RADIO_NORMAL; str[1]=SGCHECKBOX_RADIO_NORMAl; } } else { if (cdlg[objnum].state & SG_SELECTED) { str[0]=SGCHECKBOX_SELECTED; str[1]=SGCHECKBOX_SELECTEd; } else { str[0]=SGCHECKBOX_NORMAL; str[1]=SGCHECKBOX_NORMAl; } } if (cdlg[objnum].state & SG_DISABLED) textc = darkgreyc; else textc = blackc; str[2]='\0'; coord.w = fontwidth*2; coord.h = fontheight; if (cdlg[objnum].flags & SG_BUTTON_RIGHT) coord.x += ((strlen(cdlg[objnum].txt) + 1) * fontwidth); SDL_FillRect(sdlscrn, &coord, grey); SDLGui_Text(coord.x, coord.y, str, textc); }
/** * Draw a normal button. */ static void SDLGui_DrawButton(const SGOBJ *bdlg, int32_t objnum) { int32_t x,y; SDLGui_DrawBox(bdlg, objnum); x = (bdlg[0].x + bdlg[objnum].x + (bdlg[objnum].w-strlen(bdlg[objnum].txt))/2) * sdlgui_fontwidth; y = (bdlg[0].y + bdlg[objnum].y + (bdlg[objnum].h-1)/2) * sdlgui_fontheight; if (bdlg[objnum].state & SG_SELECTED) { x+=1; y+=1; } SDLGui_Text(x, y, bdlg[objnum].txt); }
/** * Draw a dialog check box object. */ static void SDLGui_DrawCheckBox(const SGOBJ *cdlg, int32_t objnum) { char str[80]; int32_t x, y; x = (cdlg[0].x + cdlg[objnum].x) * sdlgui_fontwidth; y = (cdlg[0].y + cdlg[objnum].y) * sdlgui_fontheight; if ( cdlg[objnum].state&SG_SELECTED ) str[0]=SGCHECKBOX_SELECTED; else str[0]=SGCHECKBOX_NORMAL; str[1]=' '; strcpy(&str[2], cdlg[objnum].txt); SDLGui_Text(x, y, str); }
/** * Draw a dialog radio button object. */ static void SDLGui_DrawRadioButton(const SGOBJ *rdlg, int32_t objnum) { char str[80]; int32_t x, y; x = (rdlg[0].x + rdlg[objnum].x) * sdlgui_fontwidth; y = (rdlg[0].y + rdlg[objnum].y) * sdlgui_fontheight; if (rdlg[objnum].state & SG_SELECTED) str[0]=SGRADIOBUTTON_SELECTED; else str[0]=SGRADIOBUTTON_NORMAL; str[1]=' '; strcpy(&str[2], rdlg[objnum].txt); SDLGui_Text(x, y, str); }
/* Draw a dialog check box object. */ void SDLGui_DrawCheckBox(SGOBJ *cdlg, int objnum) { SDL_Rect coord; int textc; SDLGui_ObjCoord(cdlg, objnum, &coord); if (!(cdlg[objnum].flags&SG_BUTTON_RIGHT)) coord.x += (fontwidth * 3); // 2 chars for the box plus 1 space if (cdlg[objnum].state & SG_DISABLED) textc = darkgreyc; else textc = blackc; SDLGui_Text(coord.x, coord.y, cdlg[objnum].txt, textc); SDLGui_DrawCheckBoxState(cdlg, objnum); }
/* Draw an edit field object. */ void SDLGui_DrawEditField(SGOBJ *edlg, int objnum) { SDL_Rect coord; int textc; if (edlg[objnum].state & SG_DISABLED) textc = darkgreyc; else textc = blackc; SDLGui_ObjCoord(edlg, objnum, &coord); coord.w += 1; SDL_FillRect(sdlscrn, &coord, SDLGui_MapColor(greyc)); SDLGui_Text(coord.x, coord.y, edlg[objnum].txt, textc); // Draw a line below. coord.y = coord.y + coord.h; coord.h = 1; SDL_FillRect(sdlscrn, &coord, SDLGui_MapColor(darkgreyc)); }
/** * Draw a dialog text object. */ static void SDLGui_DrawText(const SGOBJ *tdlg, int objnum) { int x, y; x = (tdlg[0].x+tdlg[objnum].x)*sdlgui_fontwidth; y = (tdlg[0].y+tdlg[objnum].y)*sdlgui_fontheight; if (tdlg[objnum].flags & SG_EXIT) { SDL_Rect rect; /* Draw background: */ rect.x = x; rect.y = y; rect.w = tdlg[objnum].w * sdlgui_fontwidth; rect.h = tdlg[objnum].h * sdlgui_fontheight; if (tdlg[objnum].state & SG_FOCUSED) SDL_FillRect(pSdlGuiScrn, &rect, colors.focus); else SDL_FillRect(pSdlGuiScrn, &rect, colors.midgrey); } SDLGui_Text(x, y, tdlg[objnum].txt); }
/** * Let the user insert text into an edit field object. * NOTE: The dlg[objnum].txt must point to an an array that is big enough * for dlg[objnum].w characters! */ static void SDLGui_EditField(SGOBJ *dlg, int32_t objnum) { size_t cursorPos; /* Position of the cursor in the edit field */ int32_t blinkState = 0; /* Used for cursor blinking */ int32_t bStopEditing = false; /* true if user wants to exit the edit field */ char *txt; /* Shortcut for dlg[objnum].txt */ SDL_Rect rect; Uint32 grey, cursorCol; SDL_Event event; int32_t nOldUnicodeMode; /* Enable unicode translation to get proper characters with SDL_PollEvent */ nOldUnicodeMode = SDL_EnableUNICODE(true); grey = SDL_MapRGB(pSdlGuiScrn->format, 192, 192, 192); cursorCol = SDL_MapRGB(pSdlGuiScrn->format, 128, 128, 128); rect.x = (dlg[0].x + dlg[objnum].x) * sdlgui_fontwidth; rect.y = (dlg[0].y + dlg[objnum].y) * sdlgui_fontheight; rect.w = (dlg[objnum].w + 1) * sdlgui_fontwidth - 1; rect.h = dlg[objnum].h * sdlgui_fontheight; txt = dlg[objnum].txt; cursorPos = strlen(txt); do { /* Look for events */ if (SDL_PollEvent(&event) == 0) { /* No event: Wait some time for cursor blinking */ SDL_Delay(250); blinkState ^= 1; } else { /* Handle events */ do { switch (event.type) { case SDL_QUIT: /* User wants to quit */ bQuitProgram = true; bStopEditing = true; break; case SDL_MOUSEBUTTONDOWN: /* Mouse pressed -> stop editing */ bStopEditing = true; break; case SDL_KEYDOWN: /* Key pressed */ switch (event.key.keysym.sym) { case SDLK_RETURN: case SDLK_KP_ENTER: bStopEditing = true; break; case SDLK_LEFT: if (cursorPos > 0) cursorPos -= 1; break; case SDLK_RIGHT: if (cursorPos < strlen(txt)) cursorPos += 1; break; case SDLK_BACKSPACE: if (cursorPos > 0) { memmove(&txt[cursorPos-1], &txt[cursorPos], strlen(&txt[cursorPos])+1); cursorPos -= 1; } break; case SDLK_DELETE: if (cursorPos < strlen(txt)) memmove(&txt[cursorPos], &txt[cursorPos+1], strlen(&txt[cursorPos+1])+1); break; default: /* If it is a "good" key then insert it into the text field */ if (event.key.keysym.unicode >= 32 && event.key.keysym.unicode < 128 && event.key.keysym.unicode != PATHSEP) { if (strlen(txt) < (size_t)dlg[objnum].w) { memmove(&txt[cursorPos+1], &txt[cursorPos], strlen(&txt[cursorPos])+1); txt[cursorPos] = event.key.keysym.unicode; cursorPos += 1; } } break; } break; } } while (SDL_PollEvent(&event)); blinkState = 1; } /* Redraw the text field: */ SDL_FillRect(pSdlGuiScrn, &rect, grey); /* Draw background */ /* Draw the cursor: */ if (blinkState && !bStopEditing) { SDL_Rect cursorrect; cursorrect.x = rect.x + cursorPos * sdlgui_fontwidth; cursorrect.y = rect.y; cursorrect.w = sdlgui_fontwidth; cursorrect.h = rect.h; SDL_FillRect(pSdlGuiScrn, &cursorrect, cursorCol); } SDLGui_Text(rect.x, rect.y, dlg[objnum].txt); /* Draw text */ SDL_UpdateRects(pSdlGuiScrn, 1, &rect); } while (!bStopEditing); SDL_EnableUNICODE(nOldUnicodeMode); }
/** * (re-)initialize statusbar internal variables for given screen surface * (sizes&colors may need to be re-calculated for the new SDL surface) * and draw the statusbar background. */ void Statusbar_Init(SDL_Surface *surf) { msg_item_t *item; SDL_Rect ledbox, sbarbox; int i, fontw, fonth, offset; const char *text[NUM_DEVICE_LEDS] = { "EN:", "MO:", "SD:", "FD:" }; assert(surf); /* dark green and light green for leds themselves */ LedColorOff = SDL_MapRGB(surf->format, 0x00, 0x40, 0x00); LedColorOn = SDL_MapRGB(surf->format, 0x00, 0xe0, 0x00); LedColorBg = SDL_MapRGB(surf->format, 0x00, 0x00, 0x00); SysColorOff = SDL_MapRGB(surf->format, 0x40, 0x00, 0x00); SysColorOn = SDL_MapRGB(surf->format, 0xe0, 0x00, 0x00); DspColorOff = SDL_MapRGB(surf->format, 0x00, 0x00, 0x40); DspColorOn = SDL_MapRGB(surf->format, 0x00, 0x00, 0xe0); GrayBg = SDL_MapRGB(surf->format, 0xb5, 0xb7, 0xaa); /* disable leds */ for (i = 0; i < NUM_DEVICE_LEDS; i++) { Led[i].state = Led[i].oldstate = false; Led[i].expire = 0; } Statusbar_OverlayInit(surf); /* disable statusbar if it doesn't fit to video mode */ if (surf->h < ScreenHeight + StatusbarHeight) { StatusbarHeight = 0; } if (!StatusbarHeight) { return; } /* prepare fonts */ SDLGui_Init(); SDLGui_SetScreen(surf); SDLGui_GetFontSize(&fontw, &fonth); /* video mode didn't match, need to recalculate sizes */ if (surf->h > ScreenHeight + StatusbarHeight) { StatusbarHeight = fonth + 2; /* actually statusbar vertical offset */ ScreenHeight = surf->h - StatusbarHeight; } else { assert(fonth+2 < StatusbarHeight); } /* draw statusbar background gray so that text shows */ sbarbox.x = 0; sbarbox.y = surf->h - StatusbarHeight; sbarbox.w = surf->w; sbarbox.h = StatusbarHeight; SDL_FillRect(surf, &sbarbox, GrayBg); /* led size */ LedRect.w = fonth/2; LedRect.h = fonth - 4; LedRect.y = ScreenHeight + StatusbarHeight/2 - LedRect.h/2; /* black box for the leds */ ledbox = LedRect; ledbox.y -= 1; ledbox.w += 2; ledbox.h += 2; offset = fontw; MessageRect.y = LedRect.y - 2; /* draw led texts and boxes + calculate box offsets */ for (i = 0; i < NUM_DEVICE_LEDS; i++) { SDLGui_Text(offset, MessageRect.y, text[i]); offset += strlen(text[i]) * fontw; offset += fontw/2; ledbox.x = offset - 1; SDL_FillRect(surf, &ledbox, LedColorBg); LedRect.x = offset; SDL_FillRect(surf, &LedRect, LedColorOff); Led[i].offset = offset; offset += LedRect.w + fontw; } #if 0 /* draw frameskip */ FrameSkipsRect.x = offset; FrameSkipsRect.y = MessageRect.y; SDLGui_Text(FrameSkipsRect.x, FrameSkipsRect.y, "FS:"); FrameSkipsRect.x += 3 * fontw + fontw/2; FrameSkipsRect.w = 4 * fontw; FrameSkipsRect.h = fonth; if(ConfigureParams.System.bFastForward) { SDLGui_Text(FrameSkipsRect.x, FrameSkipsRect.y, "0 >>"); } else { SDLGui_Text(FrameSkipsRect.x, FrameSkipsRect.y, "0"); } nOldFrameSkips = 0; /* intialize messages */ MessageRect.x = FrameSkipsRect.x + FrameSkipsRect.w + fontw; #else MessageRect.x = offset + fontw; #endif MessageRect.w = MAX_MESSAGE_LEN * fontw; MessageRect.h = fonth; for (item = MessageList; item; item = item->next) { item->shown = false; } /* draw dsp led box */ DspLedRect = LedRect; DspLedRect.x = surf->w - 8*fontw - DspLedRect.w; ledbox.x = DspLedRect.x - 1; SDLGui_Text(ledbox.x - 4*fontw - fontw/2, MessageRect.y, "DSP:"); SDL_FillRect(surf, &ledbox, LedColorBg); SDL_FillRect(surf, &DspLedRect, DspColorOff); bOldSystemLed = false; /* draw system led box */ SystemLedRect = LedRect; SystemLedRect.x = surf->w - fontw - SystemLedRect.w; ledbox.x = SystemLedRect.x - 1; SDLGui_Text(ledbox.x - 4*fontw - fontw/2, MessageRect.y, "LED:"); SDL_FillRect(surf, &ledbox, LedColorBg); SDL_FillRect(surf, &SystemLedRect, SysColorOff); bOldSystemLed = false; /* and blit statusbar on screen */ SDL_UpdateRects(surf, 1, &sbarbox); DEBUGPRINT(("Draw statusbar\n")); }