--- previous/src/gui-sdl/sdlgui.c 2018/04/24 19:26:17 1.1.1.2 +++ previous/src/gui-sdl/sdlgui.c 2018/04/24 19:30:53 1.1.1.4 @@ -76,7 +76,7 @@ static SDL_Surface *SDLGui_LoadXBM(int w */ int SDLGui_Init(void) { - SDL_Color blackWhiteColors[2] = {{255, 255, 255, 0}, {0, 0, 0, 0}}; + SDL_Color blackWhiteColors[2] = {{255, 255, 255, 255}, {0, 0, 0, 255}}; if (pSmallFontGfx && pBigFontGfx) { @@ -94,12 +94,12 @@ int SDLGui_Init(void) } /* Set color palette of the font graphics: */ - SDL_SetColors(pSmallFontGfx, blackWhiteColors, 0, 2); - SDL_SetColors(pBigFontGfx, blackWhiteColors, 0, 2); + SDL_SetPaletteColors(pSmallFontGfx->format->palette, blackWhiteColors, 0, 2); + SDL_SetPaletteColors(pBigFontGfx->format->palette, blackWhiteColors, 0, 2); /* Set font color 0 as transparent: */ - SDL_SetColorKey(pSmallFontGfx, (SDL_SRCCOLORKEY|SDL_RLEACCEL), 0); - SDL_SetColorKey(pBigFontGfx, (SDL_SRCCOLORKEY|SDL_RLEACCEL), 0); + SDL_SetColorKey(pSmallFontGfx, (SDL_TRUE|SDL_RLEACCEL), 0); + SDL_SetColorKey(pBigFontGfx, (SDL_TRUE|SDL_RLEACCEL), 0); return 0; } @@ -135,7 +135,7 @@ int SDLGui_UnInit(void) int SDLGui_SetScreen(SDL_Surface *pScrn) { pSdlGuiScrn = pScrn; - + /* Decide which font to use - small or big one: */ if (pSdlGuiScrn->w >= 640 && pSdlGuiScrn->h >= 400 && pBigFontGfx != NULL) { @@ -151,7 +151,7 @@ int SDLGui_SetScreen(SDL_Surface *pScrn) fprintf(stderr, "Error: A problem with the font occured!\n"); return -1; } - + /* Get the font width and height: */ sdlgui_fontwidth = pFontGfx->w/16; sdlgui_fontheight = pFontGfx->h/16; @@ -250,7 +250,7 @@ static void SDLGui_DrawBox(const SGOBJ * { SDL_Rect rect; int x, y, w, h, offset; - Uint32 grey = SDL_MapRGB(pSdlGuiScrn->format,192,192,192); + Uint32 grey = SDL_MapRGB(pSdlGuiScrn->format,181,183,170); Uint32 upleftc, downrightc; x = bdlg[objnum].x*sdlgui_fontwidth; @@ -266,13 +266,13 @@ static void SDLGui_DrawBox(const SGOBJ * if (bdlg[objnum].state & SG_SELECTED) { - upleftc = SDL_MapRGB(pSdlGuiScrn->format,128,128,128); + upleftc = SDL_MapRGB(pSdlGuiScrn->format,147,145,170); downrightc = SDL_MapRGB(pSdlGuiScrn->format,255,255,255); } else { upleftc = SDL_MapRGB(pSdlGuiScrn->format,255,255,255); - downrightc = SDL_MapRGB(pSdlGuiScrn->format,128,128,128); + downrightc = SDL_MapRGB(pSdlGuiScrn->format,147,145,170); } /* The root box should be bigger than the screen, so we disable the offset there: */ @@ -394,9 +394,9 @@ static void SDLGui_DrawScrollbar(const S { SDL_Rect rect; int x, y, w, h; - Uint32 grey0 = SDL_MapRGB(pSdlGuiScrn->format,128,128,128); - Uint32 grey1 = SDL_MapRGB(pSdlGuiScrn->format,196,196,196); - Uint32 grey2 = SDL_MapRGB(pSdlGuiScrn->format, 64, 64, 64); + Uint32 grey0 = SDL_MapRGB(pSdlGuiScrn->format,147,145,170); + Uint32 grey1 = SDL_MapRGB(pSdlGuiScrn->format,181,183,170); + Uint32 grey2 = SDL_MapRGB(pSdlGuiScrn->format, 73, 72, 85); x = bdlg[objnum].x * sdlgui_fontwidth; y = bdlg[objnum].y * sdlgui_fontheight + bdlg[objnum].h; @@ -465,13 +465,13 @@ static void SDLGui_EditField(SGOBJ *dlg, SDL_Rect rect; Uint32 grey, cursorCol; SDL_Event event; - int nOldUnicodeMode; - /* Enable unicode translation to get proper characters with SDL_PollEvent */ - nOldUnicodeMode = SDL_EnableUNICODE(true); + /* Enable text input to get unicode characters with SDL_TEXTINPUT event */ + SDL_SetTextInputRect(&rect); + SDL_StartTextInput(); - grey = SDL_MapRGB(pSdlGuiScrn->format, 192, 192, 192); - cursorCol = SDL_MapRGB(pSdlGuiScrn->format, 128, 128, 128); + grey = SDL_MapRGB(pSdlGuiScrn->format, 181, 183, 170); + cursorCol = SDL_MapRGB(pSdlGuiScrn->format, 147, 145, 170); rect.x = (dlg[0].x + dlg[objnum].x) * sdlgui_fontwidth; rect.y = (dlg[0].y + dlg[objnum].y) * sdlgui_fontheight; @@ -497,6 +497,12 @@ static void SDLGui_EditField(SGOBJ *dlg, { switch (event.type) { + case SDL_WINDOWEVENT: + if(event.window.event == SDL_WINDOWEVENT_CLOSE) { + bQuitProgram = true; + bStopEditing = true; + } + break; case SDL_QUIT: /* User wants to quit */ bQuitProgram = true; bStopEditing = true; @@ -531,22 +537,21 @@ static void SDLGui_EditField(SGOBJ *dlg, 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; - } - } + /* Get other keys from SDL_TEXTINPUT event */ + break; + } + break; + case SDL_TEXTINPUT: + if (strlen(txt) < (size_t)dlg[objnum].w) + { + memmove(&txt[cursorPos+1], &txt[cursorPos], strlen(&txt[cursorPos])+1); + txt[cursorPos] = event.text.text[0]; + cursorPos += 1; + } break; } break; } - } while (SDL_PollEvent(&event)); blinkState = 1; @@ -569,7 +574,7 @@ static void SDLGui_EditField(SGOBJ *dlg, } while (!bStopEditing); - SDL_EnableUNICODE(nOldUnicodeMode); + SDL_StopTextInput(); } @@ -698,7 +703,7 @@ int SDLGui_DoDialog(SGOBJ *dlg, SDL_Even return SDLGUI_ERROR; } - grey = SDL_MapRGB(pSdlGuiScrn->format,192,192,192); + grey = SDL_MapRGB(pSdlGuiScrn->format,181,183,170); dlgrect.x = dlg[0].x * sdlgui_fontwidth; dlgrect.y = dlg[0].y * sdlgui_fontheight; @@ -714,7 +719,7 @@ int SDLGui_DoDialog(SGOBJ *dlg, SDL_Even pSdlGuiScrn->format->Rmask, pSdlGuiScrn->format->Gmask, pSdlGuiScrn->format->Bmask, pSdlGuiScrn->format->Amask); if (pSdlGuiScrn->format->palette != NULL) { - SDL_SetColors(pBgSurface, pSdlGuiScrn->format->palette->colors, 0, pSdlGuiScrn->format->palette->ncolors-1); + SDL_SetPaletteColors(pBgSurface->format->palette, pSdlGuiScrn->format->palette->colors, 0, pSdlGuiScrn->format->palette->ncolors-1); } if (pBgSurface != NULL) @@ -867,6 +872,7 @@ int SDLGui_DoDialog(SGOBJ *dlg, SDL_Even SDL_FillRect(pSdlGuiScrn, &rct, grey); /* Clear old */ SDLGui_DrawRadioButton(dlg, obj); SDL_UpdateRects(pSdlGuiScrn, 1, &rct); + retbutton = obj; // added by andreas_g break; case SGCHECKBOX: dlg[obj].state ^= SG_SELECTED; @@ -877,6 +883,7 @@ int SDLGui_DoDialog(SGOBJ *dlg, SDL_Even SDL_FillRect(pSdlGuiScrn, &rct, grey); /* Clear old */ SDLGui_DrawCheckBox(dlg, obj); SDL_UpdateRects(pSdlGuiScrn, 1, &rct); + retbutton = obj; // added by andreas_g break; case SGPOPUP: dlg[obj].state |= SG_SELECTED;