diff --git a/SConscript b/SConscript index 997f01ebd0..8418fb57d1 100644 --- a/SConscript +++ b/SConscript @@ -245,24 +245,24 @@ def findLibs(env, conf): if not GetOption('renderer'): #Look for SDL runSdlConfig = platform == "Linux" or compilePlatform == "Linux" or platform == "FreeBSD" - if platform == "Darwin" and conf.CheckFramework("SDL"): + if False and platform == "Darwin" and conf.CheckFramework("SDL"): runSdlConfig = False - elif not conf.CheckLib("SDL"): + elif not conf.CheckLib("SDL2"): FatalError("SDL development library not found or not installed") if runSdlConfig: try: - env.ParseConfig('sdl-config --cflags') + env.ParseConfig('sdl2-config --cflags') if GetOption('static'): - env.ParseConfig('sdl-config --static-libs') + env.ParseConfig('sdl2-config --static-libs') else: - env.ParseConfig('sdl-config --libs') + env.ParseConfig('sdl2-config --libs') except: pass #look for SDL.h - if not GetOption('renderer') and not conf.CheckCHeader('SDL.h'): - if conf.CheckCHeader('SDL/SDL.h'): + if not GetOption('renderer') and not conf.CheckCHeader('SDL2.h'): + if conf.CheckCHeader('SDL2/SDL.h'): env.Append(CPPDEFINES=["SDL_INC"]) else: FatalError("SDL.h not found") @@ -555,8 +555,8 @@ if platform == "Windows": envCopy = env.Clone() envCopy.Append(CCFLAGS='-mstackrealign') sources += envCopy.Object('src/simulation/Gravity.cpp') -elif platform == "Darwin": - sources += ["src/SDLMain.m"] +#elif platform == "Darwin": +# sources += ["src/SDLMain.m"] #Program output name diff --git a/src/PowderToy.h b/src/PowderToy.h index aa20e943d5..9907686775 100644 --- a/src/PowderToy.h +++ b/src/PowderToy.h @@ -5,5 +5,4 @@ void ClipboardPush(ByteString text); ByteString ClipboardPull(); int GetModifiers(); bool LoadWindowPosition(int scale); -void SetCursorEnabled(int enabled); unsigned int GetTicks(); diff --git a/src/PowderToySDL.cpp b/src/PowderToySDL.cpp index 304ef287af..787d9e9ba9 100644 --- a/src/PowderToySDL.cpp +++ b/src/PowderToySDL.cpp @@ -29,13 +29,6 @@ #ifndef WIN #include #endif -#ifdef MACOSX -#include -extern "C" { - char * readClipboard(); - void writeClipboard(const char * clipboardData); -} -#endif #include "Format.h" @@ -66,125 +59,22 @@ SDL_SysWMinfo sdl_wminfo; Atom XA_CLIPBOARD, XA_TARGETS, XA_UTF8_STRING; #endif -ByteString clipboardText = ""; - int desktopWidth = 1280, desktopHeight = 1024; -SDL_Surface * sdl_scrn; +SDL_Window * sdl_window; +SDL_Renderer * sdl_renderer; +SDL_Texture * sdl_texture; int scale = 1; bool fullscreen = false; void ClipboardPush(ByteString text) { - clipboardText = text; -#ifdef MACOSX - writeClipboard(text.c_str()); -#elif defined(WIN) - if (OpenClipboard(NULL)) - { - HGLOBAL cbuffer; - char * glbuffer; - - EmptyClipboard(); - - cbuffer = GlobalAlloc(GMEM_DDESHARE, text.size() + 1); - glbuffer = (char*)GlobalLock(cbuffer); - - strcpy(glbuffer, text.c_str()); - - GlobalUnlock(cbuffer); - SetClipboardData(CF_TEXT, cbuffer); - CloseClipboard(); - } -#elif defined(LIN) && defined(SDL_VIDEO_DRIVER_X11) - sdl_wminfo.info.x11.lock_func(); - XSetSelectionOwner(sdl_wminfo.info.x11.display, XA_CLIPBOARD, sdl_wminfo.info.x11.window, CurrentTime); - XFlush(sdl_wminfo.info.x11.display); - sdl_wminfo.info.x11.unlock_func(); -#else - printf("Not implemented: put text on clipboard \"%s\"\n", text.c_str()); -#endif + SDL_SetClipboardText(text.c_str()); } -void EventProcess(SDL_Event event); - ByteString ClipboardPull() { -#ifdef MACOSX - const char *text = readClipboard(); - return text ? ByteString(text) : ""; -#elif defined(WIN) - if (OpenClipboard(NULL)) - { - HANDLE cbuffer; - char * glbuffer; - - cbuffer = GetClipboardData(CF_TEXT); - glbuffer = (char*)GlobalLock(cbuffer); - GlobalUnlock(cbuffer); - CloseClipboard(); - return glbuffer ? ByteString(glbuffer) : ""; - } -#elif defined(LIN) && defined(SDL_VIDEO_DRIVER_X11) - ByteString text = ""; - Window selectionOwner; - sdl_wminfo.info.x11.lock_func(); - selectionOwner = XGetSelectionOwner(sdl_wminfo.info.x11.display, XA_CLIPBOARD); - if (selectionOwner != None) - { - unsigned char *data = NULL; - Atom type; - int format, result; - unsigned long len, bytesLeft; - XConvertSelection(sdl_wminfo.info.x11.display, XA_CLIPBOARD, XA_UTF8_STRING, XA_CLIPBOARD, sdl_wminfo.info.x11.window, CurrentTime); - XFlush(sdl_wminfo.info.x11.display); - sdl_wminfo.info.x11.unlock_func(); - while (1) - { - SDL_Event event; - SDL_WaitEvent(&event); - if (event.type == SDL_SYSWMEVENT) - { - XEvent xevent = event.syswm.msg->event.xevent; - if (xevent.type == SelectionNotify && xevent.xselection.requestor == sdl_wminfo.info.x11.window) - break; - else - EventProcess(event); - } - else - EventProcess(event); - } - sdl_wminfo.info.x11.lock_func(); - XGetWindowProperty(sdl_wminfo.info.x11.display, sdl_wminfo.info.x11.window, XA_CLIPBOARD, 0, 0, 0, AnyPropertyType, &type, &format, &len, &bytesLeft, &data); - if (data) - { - XFree(data); - data = NULL; - } - if (bytesLeft) - { - result = XGetWindowProperty(sdl_wminfo.info.x11.display, sdl_wminfo.info.x11.window, XA_CLIPBOARD, 0, bytesLeft, 0, AnyPropertyType, &type, &format, &len, &bytesLeft, &data); - if (result == Success) - { - text = data ? ByteString((char const *)data) : ""; - XFree(data); - } - else - { - printf("Failed to pull from clipboard\n"); - return "?"; - } - } - else - return ""; - XDeleteProperty(sdl_wminfo.info.x11.display, sdl_wminfo.info.x11.window, XA_CLIPBOARD); - } - sdl_wminfo.info.x11.unlock_func(); - return text; -#else - printf("Not implemented: get text from clipboard\n"); -#endif - return clipboardText; + return ByteString(SDL_GetClipboardText()); } int mousex = 0, mousey = 0; @@ -194,259 +84,12 @@ void blit() SDL_GL_SwapBuffers(); } #else -void DrawPixel(pixel * vid, pixel color, int x, int y) -{ - if (x >= 0 && x < WINDOWW && y >= 0 && y < WINDOWH) - vid[x+y*WINDOWW] = color; -} -// draws a custom cursor, used to make 3D mode work properly (normal cursor ruins the effect) -void DrawCursor(pixel * vid) -{ - for (int j = 0; j <= 9; j++) - { - for (int i = 0; i <= j; i++) - { - if (i == 0 || i == j) - DrawPixel(vid, 0xFFFFFFFF, mousex+i, mousey+j); - else - DrawPixel(vid, 0xFF000000, mousex+i, mousey+j); - } - } - DrawPixel(vid, 0xFFFFFFFF, mousex, mousey+10); - for (int i = 0; i < 5; i++) - { - DrawPixel(vid, 0xFF000000, mousex+1+i, mousey+10); - DrawPixel(vid, 0xFFFFFFFF, mousex+6+i, mousey+10); - } - DrawPixel(vid, 0xFFFFFFFF, mousex, mousey+11); - DrawPixel(vid, 0xFF000000, mousex+1, mousey+11); - DrawPixel(vid, 0xFF000000, mousex+2, mousey+11); - DrawPixel(vid, 0xFFFFFFFF, mousex+3, mousey+11); - DrawPixel(vid, 0xFF000000, mousex+4, mousey+11); - DrawPixel(vid, 0xFF000000, mousex+5, mousey+11); - DrawPixel(vid, 0xFFFFFFFF, mousex+6, mousey+11); - - DrawPixel(vid, 0xFFFFFFFF, mousex, mousey+12); - DrawPixel(vid, 0xFF000000, mousex+1, mousey+12); - DrawPixel(vid, 0xFFFFFFFF, mousex+2, mousey+12); - DrawPixel(vid, 0xFFFFFFFF, mousex+4, mousey+12); - DrawPixel(vid, 0xFF000000, mousex+5, mousey+12); - DrawPixel(vid, 0xFF000000, mousex+6, mousey+12); - DrawPixel(vid, 0xFFFFFFFF, mousex+7, mousey+12); - - DrawPixel(vid, 0xFFFFFFFF, mousex, mousey+13); - DrawPixel(vid, 0xFFFFFFFF, mousex+1, mousey+13); - DrawPixel(vid, 0xFFFFFFFF, mousex+4, mousey+13); - DrawPixel(vid, 0xFF000000, mousex+5, mousey+13); - DrawPixel(vid, 0xFF000000, mousex+6, mousey+13); - DrawPixel(vid, 0xFFFFFFFF, mousex+7, mousey+13); - - DrawPixel(vid, 0xFFFFFFFF, mousex, mousey+14); - for (int i = 0; i < 2; i++) - { - DrawPixel(vid, 0xFFFFFFFF, mousex+5, mousey+14+i); - DrawPixel(vid, 0xFF000000, mousex+6, mousey+14+i); - DrawPixel(vid, 0xFF000000, mousex+7, mousey+14+i); - DrawPixel(vid, 0xFFFFFFFF, mousex+8, mousey+14+i); - - DrawPixel(vid, 0xFFFFFFFF, mousex+6, mousey+16+i); - DrawPixel(vid, 0xFF000000, mousex+7, mousey+16+i); - DrawPixel(vid, 0xFF000000, mousex+8, mousey+16+i); - DrawPixel(vid, 0xFFFFFFFF, mousex+9, mousey+16+i); - } - - DrawPixel(vid, 0xFFFFFFFF, mousex+7, mousey+18); - DrawPixel(vid, 0xFFFFFFFF, mousex+8, mousey+18); -} void blit(pixel * vid) { - if (sdl_scrn) - { - int depth3d = ui::Engine::Ref().Get3dDepth(); - if (depth3d) - DrawCursor(vid); - pixel * src = vid; - int j, x = 0, y = 0, w = WINDOWW, h = WINDOWH, pitch = WINDOWW; - pixel *dst; - if (SDL_MUSTLOCK(sdl_scrn)) - if (SDL_LockSurface(sdl_scrn)<0) - return; - dst=(pixel *)sdl_scrn->pixels+y*sdl_scrn->pitch/PIXELSIZE+x; - if (SDL_MapRGB(sdl_scrn->format,0x33,0x55,0x77)!=PIXPACK(0x335577)) - { - //pixel format conversion, used for strange formats (OS X specifically) - int i; - unsigned int red, green, blue; - pixel px, lastpx, nextpx; - SDL_PixelFormat *fmt = sdl_scrn->format; - if(depth3d) - { - for (j=0; j= depth3d && i < w+depth3d ? src[i-depth3d] : 0; - nextpx = i >= -depth3d && i < w-depth3d ? src[i+depth3d] : 0; - int redshift = PIXB(lastpx) + PIXG(lastpx); - if (redshift > 255) - redshift = 255; - int blueshift = PIXR(nextpx) + PIXG(nextpx); - if (blueshift > 255) - blueshift = 255; - red = ((int)(PIXR(lastpx)*.69f+redshift*.3f)>>fmt->Rloss)<Rshift; - green = ((int)(PIXG(nextpx)*.3f)>>fmt->Gloss)<Gshift; - blue = ((int)(PIXB(nextpx)*.69f+blueshift*.3f)>>fmt->Bloss)<Bshift; - dst[i] = red|green|blue; - } - dst+=sdl_scrn->pitch/PIXELSIZE; - src+=pitch; - } - } - else - { - for (j=0; j>fmt->Rloss)<Rshift; - green = (PIXG(px)>>fmt->Gloss)<Gshift; - blue = (PIXB(px)>>fmt->Bloss)<Bshift; - dst[i] = red|green|blue; - } - dst+=sdl_scrn->pitch/PIXELSIZE; - src+=pitch; - } - } - } - else - { - int i; - if(depth3d) - { - pixel lastpx, nextpx; - for (j=0; j= depth3d && i < w+depth3d ? src[i-depth3d] : 0; - nextpx = i >= -depth3d && i < w-depth3d ? src[i+depth3d] : 0; - int redshift = PIXB(lastpx) + PIXG(lastpx); - if (redshift > 255) - redshift = 255; - int blueshift = PIXR(nextpx) + PIXG(nextpx); - if (blueshift > 255) - blueshift = 255; - dst[i] = PIXRGB((int)(PIXR(lastpx)*.69f+redshift*.3f), (int)(PIXG(nextpx)*.3f), (int)(PIXB(nextpx)*.69f+blueshift*.3f)); - } - dst+=sdl_scrn->pitch/PIXELSIZE; - src+=pitch; - } - } - else - { - for (j=0; jpitch/PIXELSIZE; - src+=pitch; - } - } - } - if (SDL_MUSTLOCK(sdl_scrn)) - SDL_UnlockSurface(sdl_scrn); - SDL_UpdateRect(sdl_scrn,0,0,0,0); - } -} -void blit2(pixel * vid, int currentScale) -{ - if (sdl_scrn) - { - int depth3d = ui::Engine::Ref().Get3dDepth(); - if (depth3d) - DrawCursor(vid); - pixel * src = vid; - int j, x = 0, y = 0, w = WINDOWW, h = WINDOWH, pitch = WINDOWW; - pixel *dst; - pixel px, lastpx, nextpx; - int i,k,sx; - if (SDL_MUSTLOCK(sdl_scrn)) - if (SDL_LockSurface(sdl_scrn)<0) - return; - dst=(pixel *)sdl_scrn->pixels+y*sdl_scrn->pitch/PIXELSIZE+x; - if (SDL_MapRGB(sdl_scrn->format,0x33,0x55,0x77)!=PIXPACK(0x335577)) - { - //pixel format conversion - SDL_PixelFormat *fmt = sdl_scrn->format; - int red, green, blue; - for (j=0; j= depth3d && i < w+depth3d ? src[i-depth3d] : 0; - nextpx = i >= -depth3d && i < w-depth3d ? src[i+depth3d] : 0; - int redshift = PIXB(lastpx) + PIXG(lastpx); - if (redshift > 255) - redshift = 255; - int blueshift = PIXR(nextpx) + PIXG(nextpx); - if (blueshift > 255) - blueshift = 255; - red = ((int)(PIXR(lastpx)*.69f+redshift*.3f)>>fmt->Rloss)<Rshift; - green = ((int)(PIXG(nextpx)*.3f)>>fmt->Gloss)<Gshift; - blue = ((int)(PIXB(nextpx)*.69f+blueshift*.3f)>>fmt->Bloss)<Bshift; - } - else - { - px = src[i]; - red = (PIXR(px)>>fmt->Rloss)<Rshift; - green = (PIXG(px)>>fmt->Gloss)<Gshift; - blue = (PIXB(px)>>fmt->Bloss)<Bshift; - } - for (sx=0; sxpitch/PIXELSIZE; - } - src+=pitch; - } - } - else - { - for (j=0; j= depth3d && i < w+depth3d ? src[i-depth3d] : 0; - nextpx = i >= -depth3d && i < w-depth3d ? src[i+depth3d] : 0; - int redshift = PIXB(lastpx) + PIXG(lastpx); - if (redshift > 255) - redshift = 255; - int blueshift = PIXR(nextpx) + PIXG(nextpx); - if (blueshift > 255) - blueshift = 255; - px = PIXRGB((int)(PIXR(lastpx)*.69f+redshift*.3f), (int)(PIXG(nextpx)*.3f), (int)(PIXB(nextpx)*.69f+blueshift*.3f)); - } - for (sx=0; sxpitch/PIXELSIZE; - } - src+=pitch; - } - } - if (SDL_MUSTLOCK(sdl_scrn)) - SDL_UnlockSurface(sdl_scrn); - SDL_UpdateRect(sdl_scrn,0,0,0,0); - } + SDL_UpdateTexture(sdl_texture, NULL, vid, WINDOWW * sizeof (Uint32)); + SDL_RenderClear(sdl_renderer); + SDL_RenderCopy(sdl_renderer, sdl_texture, NULL, NULL); + SDL_RenderPresent(sdl_renderer); } #endif @@ -460,10 +103,12 @@ int SDLOpen() fprintf(stderr, "Initializing SDL: %s\n", SDL_GetError()); return 1; } - const SDL_VideoInfo * vidInfo = SDL_GetVideoInfo(); - desktopWidth = vidInfo->current_w; - desktopHeight = vidInfo->current_h; - SDL_EnableUNICODE(1); + + SDL_DisplayMode SDLDisplayMode; + SDL_GetCurrentDisplayMode(0, &SDLDisplayMode); + desktopWidth = SDLDisplayMode.w; + desktopHeight = SDLDisplayMode.h; + #if defined(WIN) && defined(WINCONSOLE) //On Windows, SDL redirects stdout to stdout.txt, which can be annoying when debugging, here we redirect back to the console if (console) @@ -490,33 +135,31 @@ int SDLOpen() SendMessage(WindowHandle, WM_SETICON, ICON_BIG, (LPARAM)hIconBig); #elif defined(LIN) SDL_Surface *icon = SDL_CreateRGBSurfaceFrom((void*)app_icon, 48, 48, 24, 144, 0x00FF0000, 0x0000FF00, 0x000000FF, 0); - SDL_WM_SetIcon(icon, (Uint8*)app_icon_bitmap); + //SDL_WM_SetIcon(icon, (Uint8*)app_icon_bitmap); + SDL_SetWindowIcon(sdl_window, icon); SDL_FreeSurface(icon); #endif - SDL_WM_SetCaption("The Powder Toy", "Powder Toy"); - //SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); atexit(SDL_Quit); return 0; } -SDL_Surface * SDLSetScreen(int newScale, bool newFullscreen) +void SDLSetScreen(int newScale, bool newFullscreen) { + SDL_DestroyTexture(sdl_texture); + SDL_DestroyRenderer(sdl_renderer); + SDL_DestroyWindow(sdl_window); scale = newScale; fullscreen = newFullscreen; - SDL_Surface * surface; -#ifndef OGLI - surface = SDL_SetVideoMode(WINDOWW * newScale, WINDOWH * newScale, 32, SDL_SWSURFACE | (newFullscreen?SDL_FULLSCREEN:0)); -#else - surface = SDL_SetVideoMode(WINDOWW * newScale, WINDOWH * newScale, 32, SDL_OPENGL | SDL_RESIZABLE | (newFullscreen?SDL_FULLSCREEN:0)); -#endif - return surface; -} - -void SetCursorEnabled(int enabled) -{ - SDL_ShowCursor(enabled); + sdl_window = SDL_CreateWindow("The Powder Toy", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, WINDOWW * newScale, WINDOWH * newScale, + newFullscreen ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0); + sdl_renderer = SDL_CreateRenderer(sdl_window, -1, 0); + if (newScale > 1) + SDL_RenderSetLogicalSize(sdl_renderer, WINDOWW, WINDOWH); + sdl_texture = SDL_CreateTexture(sdl_renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, WINDOWW, WINDOWH); + //SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "linear"); + //SDL_SetWindowResizable(sdl_window, SDL_TRUE); } unsigned int GetTicks() @@ -588,7 +231,7 @@ std::map readArguments(int argc, char * argv[]) return arguments; } -SDLKey MapNumpad(SDLKey key) +/*SDLKey MapNumpad(SDLKey key) { switch(key) { @@ -613,18 +256,20 @@ SDLKey MapNumpad(SDLKey key) default: return key; } -} +}*/ int elapsedTime = 0, currentTime = 0, lastTime = 0, currentFrame = 0; unsigned int lastTick = 0; -float fps = 0, delta = 1.0f, inputScale = 1.0f; +float fps = 0, delta = 1.0f; +float inputScaleH = 1.0f, inputScaleV = 1.0f; ui::Engine * engine = NULL; bool showDoubleScreenDialog = false; float currentWidth, currentHeight; void EventProcess(SDL_Event event) { - if (event.type == SDL_KEYDOWN || event.type == SDL_KEYUP) + //inputScale= 1.0f; + /*if (event.type == SDL_KEYDOWN || event.type == SDL_KEYUP) { if (event.key.keysym.unicode==0) { @@ -638,7 +283,7 @@ void EventProcess(SDL_Event event) event.key.keysym.unicode = 0; } } - } + }*/ switch (event.type) { case SDL_QUIT: @@ -646,106 +291,61 @@ void EventProcess(SDL_Event event) engine->Exit(); break; case SDL_KEYDOWN: - if (event.key.keysym.sym == 'q' && (event.key.keysym.mod&KMOD_CTRL)) + if (!event.key.repeat && event.key.keysym.sym == 'q' && (event.key.keysym.mod&KMOD_CTRL)) engine->ConfirmExit(); else - engine->onKeyPress(event.key.keysym.sym, event.key.keysym.unicode, event.key.keysym.mod&KMOD_SHIFT, event.key.keysym.mod&KMOD_CTRL, event.key.keysym.mod&KMOD_ALT); + engine->onKeyPress(event.key.keysym.sym, event.key.keysym.scancode, event.key.repeat, event.key.keysym.mod&KMOD_SHIFT, event.key.keysym.mod&KMOD_CTRL, event.key.keysym.mod&KMOD_ALT); break; case SDL_KEYUP: - engine->onKeyRelease(event.key.keysym.sym, event.key.keysym.unicode, event.key.keysym.mod&KMOD_SHIFT, event.key.keysym.mod&KMOD_CTRL, event.key.keysym.mod&KMOD_ALT); + engine->onKeyRelease(event.key.keysym.sym, event.key.keysym.scancode, event.key.repeat, event.key.keysym.mod&KMOD_SHIFT, event.key.keysym.mod&KMOD_CTRL, event.key.keysym.mod&KMOD_ALT); break; - case SDL_MOUSEMOTION: - engine->onMouseMove(event.motion.x*inputScale, event.motion.y*inputScale); - mousex = event.motion.x*inputScale; - mousey = event.motion.y*inputScale; + case SDL_TEXTINPUT: + engine->onTextInput(ByteString(event.text.text).FromUtf8()); break; - case SDL_MOUSEBUTTONDOWN: - if (event.button.button == SDL_BUTTON_WHEELUP) - { - engine->onMouseWheel(event.motion.x*inputScale, event.motion.y*inputScale, 1); - } - else if (event.button.button == SDL_BUTTON_WHEELDOWN) - { - engine->onMouseWheel(event.motion.x*inputScale, event.motion.y*inputScale, -1); - } - else + case SDL_MOUSEWHEEL: + { + int x = event.wheel.x; + int y = event.wheel.y; + if (event.wheel.direction == SDL_MOUSEWHEEL_FLIPPED) { - engine->onMouseClick(event.motion.x*inputScale, event.motion.y*inputScale, event.button.button); + x *= -1; + y *= -1; } - mousex = event.motion.x*inputScale; - mousey = event.motion.y*inputScale; + bool positiveDir = y == 0 ? x > 0 : y > 0; + engine->onMouseWheel(event.motion.x * inputScaleH, event.motion.y * inputScaleV, positiveDir ? 1 : -1); + break; + } + case SDL_MOUSEMOTION: + engine->onMouseMove(event.motion.x * inputScaleH, event.motion.y * inputScaleV); + mousex = event.motion.x * inputScaleH; + mousey = event.motion.y * inputScaleV; + break; + case SDL_MOUSEBUTTONDOWN: + engine->onMouseClick(event.motion.x * inputScaleH, event.motion.y * inputScaleV, event.button.button); + mousex = event.motion.x * inputScaleH; + mousey = event.motion.y * inputScaleV; break; case SDL_MOUSEBUTTONUP: - if (event.button.button != SDL_BUTTON_WHEELUP && event.button.button != SDL_BUTTON_WHEELDOWN) - engine->onMouseUnclick(event.motion.x*inputScale, event.motion.y*inputScale, event.button.button); - mousex = event.motion.x*inputScale; - mousey = event.motion.y*inputScale; + engine->onMouseUnclick(event.motion.x * inputScaleH, event.motion.y * inputScaleV, event.button.button); + mousex = event.motion.x * inputScaleH; + mousey = event.motion.y * inputScaleV; break; -#ifdef OGLI - case SDL_VIDEORESIZE: + case SDL_WINDOWEVENT: { - float ratio = (float)WINDOWW / WINDOWH; - float width = event.resize.w; - float height = width/ratio; - - sdl_scrn = SDL_SetVideoMode(event.resize.w, height, 32, SDL_OPENGL | SDL_RESIZABLE); - - glViewport(0, 0, width, height); - engine->g->Reset(); - //glScaled(width/currentWidth, height/currentHeight, 1.0f); + if (event.window.event != SDL_WINDOWEVENT_RESIZED) + break; + float width = event.window.data1; + float height = event.window.data2; currentWidth = width; currentHeight = height; - inputScale = (float)WINDOWW/currentWidth; + // this "* scale" thing doesn't really work properly + // currently there is a bug where input doesn't scale properly after resizing, only when double scale mode is active + inputScaleH = (float)WINDOWW * scale / currentWidth; + inputScaleV = (float)WINDOWH * scale / currentHeight; - glLineWidth(currentWidth/(float)WINDOWW); - if(sdl_scrn == NULL) - { - std::cerr << "Oh bugger" << std::endl; - } break; } -#endif -#if defined (USE_SDL) && defined(LIN) && defined(SDL_VIDEO_DRIVER_X11) - case SDL_SYSWMEVENT: - if (event.syswm.msg->subsystem != SDL_SYSWM_X11) - break; - sdl_wminfo.info.x11.lock_func(); - XEvent xe = event.syswm.msg->event.xevent; - if (xe.type==SelectionClear) - { - clipboardText = ""; - } - else if (xe.type==SelectionRequest) - { - XEvent xr; - xr.xselection.type = SelectionNotify; - xr.xselection.requestor = xe.xselectionrequest.requestor; - xr.xselection.selection = xe.xselectionrequest.selection; - xr.xselection.target = xe.xselectionrequest.target; - xr.xselection.property = xe.xselectionrequest.property; - xr.xselection.time = xe.xselectionrequest.time; - if (xe.xselectionrequest.target==XA_TARGETS) - { - // send list of supported formats - Atom targets[] = {XA_TARGETS, XA_STRING, XA_UTF8_STRING}; - xr.xselection.property = xe.xselectionrequest.property; - XChangeProperty(sdl_wminfo.info.x11.display, xe.xselectionrequest.requestor, xe.xselectionrequest.property, XA_ATOM, 32, PropModeReplace, (unsigned char*)targets, (int)(sizeof(targets)/sizeof(Atom))); - } - // TODO: Supporting more targets would be nice - else if ((xe.xselectionrequest.target==XA_STRING || xe.xselectionrequest.target==XA_UTF8_STRING)) - { - XChangeProperty(sdl_wminfo.info.x11.display, xe.xselectionrequest.requestor, xe.xselectionrequest.property, xe.xselectionrequest.target, 8, PropModeReplace, (unsigned char*)clipboardText.c_str(), clipboardText.size()+1); - } - else - { - // refuse clipboard request - xr.xselection.property = None; - } - XSendEvent(sdl_wminfo.info.x11.display, xe.xselectionrequest.requestor, 0, 0, &xr); - } - sdl_wminfo.info.x11.unlock_func(); -#endif } } @@ -786,17 +386,13 @@ void EngineProcess() if(scale != engine->Scale || fullscreen != engine->Fullscreen) { - sdl_scrn = SDLSetScreen(engine->Scale, engine->Fullscreen); - inputScale = 1.0f/(float)scale; + SDLSetScreen(engine->Scale, engine->Fullscreen); } #ifdef OGLI blit(); #else - if(engine->Scale > 1) - blit2(engine->g->vid, engine->Scale); - else - blit(engine->g->vid); + blit(engine->g->vid); #endif int frameTime = SDL_GetTicks() - frameStart; @@ -914,7 +510,8 @@ bool SaveWindowPosition() #endif -void BlueScreen(String detailMessage){ +void BlueScreen(String detailMessage) +{ ui::Engine * engine = &ui::Engine::Ref(); engine->g->fillrect(0, 0, engine->GetWidth(), engine->GetHeight(), 17, 114, 169, 210); @@ -948,10 +545,7 @@ void BlueScreen(String detailMessage){ #ifdef OGLI blit(); #else - if(engine->Scale > 1) - blit2(engine->g->vid, engine->Scale); - else - blit(engine->g->vid); + blit(engine->g->vid); #endif } } @@ -1047,7 +641,7 @@ int main(int argc, char * argv[]) #ifdef WIN LoadWindowPosition(tempScale); #endif - sdl_scrn = SDLSetScreen(tempScale, tempFullscreen); + SDLSetScreen(tempScale, tempFullscreen); #ifdef OGLI SDL_GL_SetAttribute (SDL_GL_DOUBLEBUFFER, 1); @@ -1060,27 +654,9 @@ int main(int argc, char * argv[]) fprintf(stderr, "Initializing Glew: %d\n", status); exit(-1); } -#endif -#if defined (USE_SDL) && defined(LIN) && defined(SDL_VIDEO_DRIVER_X11) - SDL_EventState(SDL_SYSWMEVENT, SDL_ENABLE); - SDL_VERSION(&sdl_wminfo.version); - if(SDL_GetWMInfo(&sdl_wminfo) > 0) - { - sdl_wminfo.info.x11.lock_func(); - XA_CLIPBOARD = XInternAtom(sdl_wminfo.info.x11.display, "CLIPBOARD", 1); - XA_TARGETS = XInternAtom(sdl_wminfo.info.x11.display, "TARGETS", 1); - XA_UTF8_STRING = XInternAtom(sdl_wminfo.info.x11.display, "UTF8_STRING", 1); - sdl_wminfo.info.x11.unlock_func(); - } - else - { - fprintf(stderr, "X11 setup failed, X11 window info not found"); - exit(-1); - } #endif ui::Engine::Ref().g = new Graphics(); ui::Engine::Ref().Scale = scale; - inputScale = 1.0f/float(scale); ui::Engine::Ref().Fullscreen = fullscreen; engine = &ui::Engine::Ref(); @@ -1156,10 +732,7 @@ int main(int argc, char * argv[]) #ifdef OGLI blit(); #else - if(engine->Scale > 1) - blit2(engine->g->vid, engine->Scale); - else - blit(engine->g->vid); + blit(engine->g->vid); #endif ByteString ptsaveArg = arguments["ptsave"]; try @@ -1208,7 +781,7 @@ int main(int argc, char * argv[]) //initial mouse coords int sdl_x, sdl_y; SDL_GetMouseState(&sdl_x, &sdl_y); - engine->onMouseMove(sdl_x*inputScale, sdl_y*inputScale); + engine->onMouseMove(sdl_x * inputScaleH, sdl_y * inputScaleV); EngineProcess(); #ifdef WIN diff --git a/src/SDLCompat.h b/src/SDLCompat.h index 309c3915d2..c330c09116 100644 --- a/src/SDLCompat.h +++ b/src/SDLCompat.h @@ -1,7 +1,7 @@ #ifdef USE_SDL #ifdef SDL_INC -#include "SDL/SDL.h" +#include "SDL2/SDL.h" #else #include "SDL.h" #endif @@ -9,7 +9,7 @@ #ifdef INCLUDE_SYSWM #if defined(WIN) || defined(LIN) #ifdef SDL_INC -#include +#include #else #include #endif diff --git a/src/debug/DebugInfo.h b/src/debug/DebugInfo.h index 2414bd669d..d41809664e 100644 --- a/src/debug/DebugInfo.h +++ b/src/debug/DebugInfo.h @@ -11,5 +11,5 @@ class DebugInfo unsigned int debugID; virtual void Draw() {} // currentMouse doesn't belong but I don't want to create more hooks at the moment - virtual bool KeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt, ui::Point currentMouse) { return true; } + virtual bool KeyPress(int key, int scan, bool shift, bool ctrl, bool alt, ui::Point currentMouse) { return true; } }; diff --git a/src/debug/ParticleDebug.cpp b/src/debug/ParticleDebug.cpp index d50ed7a9f3..1df0e9e87c 100644 --- a/src/debug/ParticleDebug.cpp +++ b/src/debug/ParticleDebug.cpp @@ -57,7 +57,7 @@ void ParticleDebug::Debug(int mode, int x, int y) } } -bool ParticleDebug::KeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt, ui::Point currentMouse) +bool ParticleDebug::KeyPress(int key, int scan, bool shift, bool ctrl, bool alt, ui::Point currentMouse) { if (key == 'f') { diff --git a/src/debug/ParticleDebug.h b/src/debug/ParticleDebug.h index 719941615b..19ef0d613a 100644 --- a/src/debug/ParticleDebug.h +++ b/src/debug/ParticleDebug.h @@ -12,7 +12,7 @@ class ParticleDebug : public DebugInfo public: ParticleDebug(unsigned int id, Simulation * sim, GameModel * model); void Debug(int mode, int x, int y); - virtual bool KeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt, ui::Point currentMouse); + virtual bool KeyPress(int key, int scan, bool shift, bool ctrl, bool alt, ui::Point currentMouse); virtual ~ParticleDebug(); }; diff --git a/src/gui/colourpicker/ColourPickerActivity.cpp b/src/gui/colourpicker/ColourPickerActivity.cpp index 93c58b3780..e99302b3c1 100644 --- a/src/gui/colourpicker/ColourPickerActivity.cpp +++ b/src/gui/colourpicker/ColourPickerActivity.cpp @@ -239,8 +239,10 @@ void ColourPickerActivity::OnMouseUp(int x, int y, unsigned button) } } -void ColourPickerActivity::OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt) +void ColourPickerActivity::OnKeyPress(int key, int scan, bool repeat, bool shift, bool ctrl, bool alt) { + if (repeat) + return; if (key == SDLK_TAB) { if (rValue->IsFocused()) diff --git a/src/gui/colourpicker/ColourPickerActivity.h b/src/gui/colourpicker/ColourPickerActivity.h index f8213885b7..4aac2f7262 100644 --- a/src/gui/colourpicker/ColourPickerActivity.h +++ b/src/gui/colourpicker/ColourPickerActivity.h @@ -36,7 +36,7 @@ class ColourPickerActivity: public WindowActivity { virtual void OnMouseMove(int x, int y, int dx, int dy); virtual void OnMouseDown(int x, int y, unsigned button); virtual void OnMouseUp(int x, int y, unsigned button); - virtual void OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt); + virtual void OnKeyPress(int key, int scan, bool repeat, bool shift, bool ctrl, bool alt); virtual void OnTryExit(ExitMethod method); ColourPickerActivity(ui::Colour initialColour, ColourPickedCallback * callback = NULL); virtual ~ColourPickerActivity(); diff --git a/src/gui/console/ConsoleView.cpp b/src/gui/console/ConsoleView.cpp index 4a25dad7bd..a9e6467319 100644 --- a/src/gui/console/ConsoleView.cpp +++ b/src/gui/console/ConsoleView.cpp @@ -24,17 +24,15 @@ ConsoleView::ConsoleView(): commandField->SetBorder(false); } -void ConsoleView::DoKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt) +void ConsoleView::DoKeyPress(int key, int scan, bool repeat, bool shift, bool ctrl, bool alt) { + if ((scan == SDL_SCANCODE_GRAVE && key != '~') || key == SDLK_ESCAPE) + { + c->CloseConsole(); + return; + } switch(key) { - case SDLK_ESCAPE: - case '`': - if (character != '~') - c->CloseConsole(); - else - Window::DoKeyPress(key, character, shift, ctrl, alt); - break; case SDLK_RETURN: case SDLK_KP_ENTER: c->EvaluateCommand(commandField->GetText()); @@ -48,7 +46,7 @@ void ConsoleView::DoKeyPress(int key, Uint16 character, bool shift, bool ctrl, b c->PreviousCommand(); break; default: - Window::DoKeyPress(key, character, shift, ctrl, alt); + Window::DoKeyPress(key, scan, repeat, shift, ctrl, alt); break; } } diff --git a/src/gui/console/ConsoleView.h b/src/gui/console/ConsoleView.h index 22f172c8ad..9cb0ab24d2 100644 --- a/src/gui/console/ConsoleView.h +++ b/src/gui/console/ConsoleView.h @@ -20,7 +20,7 @@ class ConsoleView: public ui::Window { public: ConsoleView(); virtual void OnDraw(); - virtual void DoKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt); + virtual void DoKeyPress(int key, int scan, bool repeat, bool shift, bool ctrl, bool alt); void AttachController(ConsoleController * c_) { c = c_; } void NotifyPreviousCommandsChanged(ConsoleModel * sender); void NotifyCurrentCommandChanged(ConsoleModel * sender); diff --git a/src/gui/elementsearch/ElementSearchActivity.cpp b/src/gui/elementsearch/ElementSearchActivity.cpp index 6f23220fb9..827704b8c1 100644 --- a/src/gui/elementsearch/ElementSearchActivity.cpp +++ b/src/gui/elementsearch/ElementSearchActivity.cpp @@ -219,8 +219,10 @@ void ElementSearchActivity::OnTick(float dt) } } -void ElementSearchActivity::OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt) +void ElementSearchActivity::OnKeyPress(int key, int scan, bool repeat, bool shift, bool ctrl, bool alt) { + if (repeat) + return; switch (key) { case SDLK_KP_ENTER: @@ -245,8 +247,10 @@ void ElementSearchActivity::OnKeyPress(int key, Uint16 character, bool shift, bo } } -void ElementSearchActivity::OnKeyRelease(int key, Uint16 character, bool shift, bool ctrl, bool alt) +void ElementSearchActivity::OnKeyRelease(int key, int scan, bool repeat, bool shift, bool ctrl, bool alt) { + if (repeat) + return; switch (key) { case SDLK_LSHIFT: diff --git a/src/gui/elementsearch/ElementSearchActivity.h b/src/gui/elementsearch/ElementSearchActivity.h index a4dfb46e06..7b29bb024f 100644 --- a/src/gui/elementsearch/ElementSearchActivity.h +++ b/src/gui/elementsearch/ElementSearchActivity.h @@ -33,8 +33,8 @@ class ElementSearchActivity: public WindowActivity void SetActiveTool(int selectionState, Tool * tool); virtual ~ElementSearchActivity(); virtual void OnTick(float dt); - virtual void OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt); - virtual void OnKeyRelease(int key, Uint16 character, bool shift, bool ctrl, bool alt); + virtual void OnKeyPress(int key, int scan, bool repeat, bool shift, bool ctrl, bool alt); + virtual void OnKeyRelease(int key, int scan, bool repeat, bool shift, bool ctrl, bool alt); virtual void OnDraw(); virtual void ToolTip(ui::Point senderPosition, String ToolTip); }; diff --git a/src/gui/game/GameController.cpp b/src/gui/game/GameController.cpp index 39376c5b61..5b2a0c4a09 100644 --- a/src/gui/game/GameController.cpp +++ b/src/gui/game/GameController.cpp @@ -713,9 +713,11 @@ bool GameController::MouseWheel(int x, int y, int d) return commandInterface->OnMouseWheel(x, y, d); } -bool GameController::KeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt) +bool GameController::KeyPress(int key, int scan, bool repeat, bool shift, bool ctrl, bool alt) { - bool ret = commandInterface->OnKeyPress(key, character, shift, ctrl, alt); + bool ret = commandInterface->OnKeyPress(key, scan, repeat, shift, ctrl, alt); + if (repeat) + return ret; if (ret) { Simulation * sim = gameModel->GetSimulation(); @@ -783,16 +785,18 @@ bool GameController::KeyPress(int key, Uint16 character, bool shift, bool ctrl, for(std::vector::iterator iter = debugInfo.begin(), end = debugInfo.end(); iter != end; iter++) { if ((*iter)->debugID & debugFlags) - if (!(*iter)->KeyPress(key, character, shift, ctrl, alt, gameView->GetMousePosition())) + if (!(*iter)->KeyPress(key, scan, shift, ctrl, alt, gameView->GetMousePosition())) ret = false; } } return ret; } -bool GameController::KeyRelease(int key, Uint16 character, bool shift, bool ctrl, bool alt) +bool GameController::KeyRelease(int key, int scan, bool repeat, bool shift, bool ctrl, bool alt) { - bool ret = commandInterface->OnKeyRelease(key, character, shift, ctrl, alt); + bool ret = commandInterface->OnKeyRelease(key, scan, repeat, shift, ctrl, alt); + if (repeat) + return ret; if (ret) { Simulation * sim = gameModel->GetSimulation(); diff --git a/src/gui/game/GameController.h b/src/gui/game/GameController.h index 8449cc0893..119aeb4085 100644 --- a/src/gui/game/GameController.h +++ b/src/gui/game/GameController.h @@ -64,8 +64,8 @@ class GameController: public ClientListener bool MouseDown(int x, int y, unsigned button); bool MouseUp(int x, int y, unsigned button, char type); bool MouseWheel(int x, int y, int d); - bool KeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt); - bool KeyRelease(int key, Uint16 character, bool shift, bool ctrl, bool alt); + bool KeyPress(int key, int scan, bool repeat, bool shift, bool ctrl, bool alt); + bool KeyRelease(int key, int scan, bool repeat, bool shift, bool ctrl, bool alt); bool MouseTick(); void Tick(); void Exit(); diff --git a/src/gui/game/GameView.cpp b/src/gui/game/GameView.cpp index 49e2985d38..0a3662e0e1 100644 --- a/src/gui/game/GameView.cpp +++ b/src/gui/game/GameView.cpp @@ -1374,7 +1374,7 @@ void GameView::BeginStampSelection() buttonTipShow = 120; } -void GameView::OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt) +void GameView::OnKeyPress(int key, int scan, bool repeat, bool shift, bool ctrl, bool alt) { if (introText > 50) { @@ -1400,6 +1400,8 @@ void GameView::OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool c->TranslateSave(ui::Point(0, 1)); return; case 'r': + if (repeat) + return; if (ctrl && shift) { //Vertical flip @@ -1419,6 +1421,14 @@ void GameView::OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool } } } + + if (repeat) + return; + if (scan == SDL_SCANCODE_GRAVE) + { + c->ShowConsole(); + return; + } switch(key) { case SDLK_LALT: @@ -1456,9 +1466,6 @@ void GameView::OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool case SDLK_TAB: //Tab c->ChangeBrush(); break; - case '`': - c->ShowConsole(); - break; case 'p': case SDLK_F2: if (ctrl) @@ -1657,8 +1664,10 @@ void GameView::OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool } } -void GameView::OnKeyRelease(int key, Uint16 character, bool shift, bool ctrl, bool alt) +void GameView::OnKeyRelease(int key, int scan, bool repeat, bool shift, bool ctrl, bool alt) { + if (repeat) + return; switch(key) { case SDLK_LALT: @@ -1689,7 +1698,7 @@ void GameView::OnBlur() drawMode = DrawPoints; c->MouseUp(0, 0, 0, 1); // tell lua that mouse is up (even if it really isn't) if (GetModifiers()) - c->KeyRelease(0, 0, false, false, false); + c->KeyRelease(0, 0, false, false, false, false); } void GameView::OnTick(float dt) @@ -1823,16 +1832,16 @@ void GameView::DoMouseWheel(int x, int y, int d) Window::DoMouseWheel(x, y, d); } -void GameView::DoKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt) +void GameView::DoKeyPress(int key, int scan, bool repeat, bool shift, bool ctrl, bool alt) { - if(c->KeyPress(key, character, shift, ctrl, alt)) - Window::DoKeyPress(key, character, shift, ctrl, alt); + if (c->KeyPress(key, scan, repeat, shift, ctrl, alt)) + Window::DoKeyPress(key, scan, repeat, shift, ctrl, alt); } -void GameView::DoKeyRelease(int key, Uint16 character, bool shift, bool ctrl, bool alt) +void GameView::DoKeyRelease(int key, int scan, bool repeat, bool shift, bool ctrl, bool alt) { - if(c->KeyRelease(key, character, shift, ctrl, alt)) - Window::DoKeyRelease(key, character, shift, ctrl, alt); + if(c->KeyRelease(key, scan, repeat, shift, ctrl, alt)) + Window::DoKeyRelease(key, scan, repeat, shift, ctrl, alt); } void GameView::DoTick(float dt) diff --git a/src/gui/game/GameView.h b/src/gui/game/GameView.h index 7c25341bab..4bba4b8693 100644 --- a/src/gui/game/GameView.h +++ b/src/gui/game/GameView.h @@ -191,8 +191,8 @@ class GameView: public ui::Window virtual void OnMouseDown(int x, int y, unsigned button); virtual void OnMouseUp(int x, int y, unsigned button); virtual void OnMouseWheel(int x, int y, int d); - virtual void OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt); - virtual void OnKeyRelease(int key, Uint16 character, bool shift, bool ctrl, bool alt); + virtual void OnKeyPress(int key, int scan, bool repeat, bool shift, bool ctrl, bool alt); + virtual void OnKeyRelease(int key, int scan, bool repeat, bool shift, bool ctrl, bool alt); virtual void OnTick(float dt); virtual void OnDraw(); virtual void OnBlur(); @@ -204,8 +204,8 @@ class GameView: public ui::Window virtual void DoMouseDown(int x, int y, unsigned button); virtual void DoMouseUp(int x, int y, unsigned button); virtual void DoMouseWheel(int x, int y, int d); - virtual void DoKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt); - virtual void DoKeyRelease(int key, Uint16 character, bool shift, bool ctrl, bool alt); + virtual void DoKeyPress(int key, int scan, bool repeat, bool shift, bool ctrl, bool alt); + virtual void DoKeyRelease(int key, int scan, bool repeat, bool shift, bool ctrl, bool alt); class MenuAction; class ToolAction; diff --git a/src/gui/game/PropertyTool.cpp b/src/gui/game/PropertyTool.cpp index 5886fe646d..62efc96cdf 100644 --- a/src/gui/game/PropertyTool.cpp +++ b/src/gui/game/PropertyTool.cpp @@ -23,7 +23,7 @@ class PropertyWindow: public ui::Window PropertyWindow(PropertyTool *tool_, Simulation *sim); void SetProperty(); virtual void OnDraw(); - virtual void OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt); + virtual void OnKeyPress(int key, int scan, bool repeat, bool shift, bool ctrl, bool alt); virtual void OnTryExit(ExitMethod method); virtual ~PropertyWindow() {} class OkayAction: public ui::ButtonAction @@ -217,7 +217,7 @@ void PropertyWindow::OnDraw() g->drawrect(Position.X, Position.Y, Size.X, Size.Y, 200, 200, 200, 255); } -void PropertyWindow::OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt) +void PropertyWindow::OnKeyPress(int key, int scan, bool repeat, bool shift, bool ctrl, bool alt) { if (key == SDLK_UP) property->SetOption(property->GetOption().second-1); diff --git a/src/gui/game/SignTool.cpp b/src/gui/game/SignTool.cpp index 5302d48b88..c774398406 100644 --- a/src/gui/game/SignTool.cpp +++ b/src/gui/game/SignTool.cpp @@ -27,8 +27,8 @@ class SignWindow: public ui::Window virtual void DoMouseDown(int x, int y, unsigned button); virtual void DoMouseUp(int x, int y, unsigned button) { if(!signMoving) ui::Window::DoMouseUp(x, y, button); } virtual void DoMouseWheel(int x, int y, int d) { if(!signMoving) ui::Window::DoMouseWheel(x, y, d); } - virtual void DoKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt) { if(!signMoving) ui::Window::DoKeyPress(key, character, shift, ctrl, alt); } - virtual void DoKeyRelease(int key, Uint16 character, bool shift, bool ctrl, bool alt) { if(!signMoving) ui::Window::DoKeyRelease(key, character, shift, ctrl, alt); } + virtual void DoKeyPress(int key, int scan, bool repeat, bool shift, bool ctrl, bool alt) { if(!signMoving) ui::Window::DoKeyPress(key, scan, repeat, shift, ctrl, alt); } + virtual void DoKeyRelease(int key, int scan, bool repeat, bool shift, bool ctrl, bool alt) { if(!signMoving) ui::Window::DoKeyRelease(key, scan, repeat, shift, ctrl, alt); } virtual ~SignWindow() {} virtual void OnTryExit(ui::Window::ExitMethod method); class OkayAction: public ui::ButtonAction diff --git a/src/gui/interface/Component.cpp b/src/gui/interface/Component.cpp index e70373d701..a9e0fb5a68 100644 --- a/src/gui/interface/Component.cpp +++ b/src/gui/interface/Component.cpp @@ -190,11 +190,15 @@ void Component::Tick(float dt) { } -void Component::OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt) +void Component::OnKeyPress(int key, int scan, bool repeat, bool shift, bool ctrl, bool alt) { } -void Component::OnKeyRelease(int key, Uint16 character, bool shift, bool ctrl, bool alt) +void Component::OnKeyRelease(int key, int scan, bool repeat, bool shift, bool ctrl, bool alt) +{ +} + +void Component::OnTextInput(String text) { } diff --git a/src/gui/interface/Component.h b/src/gui/interface/Component.h index b4848ddfc6..0ff5b5b90e 100644 --- a/src/gui/interface/Component.h +++ b/src/gui/interface/Component.h @@ -66,26 +66,6 @@ namespace ui virtual void OnContextMenuAction(int item); - //UI functions: - /* - void Tick(float dt); - void Draw(const Point& screenPos); - - void OnMouseHover(int localx, int localy); - void OnMouseMoved(int localx, int localy, int dx, int dy); - void OnMouseMovedInside(int localx, int localy, int dx, int dy); - void OnMouseEnter(int localx, int localy); - void OnMouseLeave(int localx, int localy); - void OnMouseDown(int x, int y, unsigned int button); - void OnMouseUp(int x, int y, unsigned int button); - void OnMouseClick(int localx, int localy, unsigned int button); - void OnMouseUnclick(int localx, int localy, unsigned int button); - void OnMouseWheel(int localx, int localy, int d); - void OnMouseWheelInside(int localx, int localy, int d); - void OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt); - void OnKeyRelease(int key, Uint16 character, bool shift, bool ctrl, bool alt); - */ - /// // Called: Every tick. // Params: @@ -211,7 +191,7 @@ namespace ui // ctrl: Control key is down. // alt: Alternate key is down. /// - virtual void OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt); + virtual void OnKeyPress(int key, int scan, bool repeat, bool shift, bool ctrl, bool alt); /// // Called: When a key is released. @@ -221,6 +201,8 @@ namespace ui // ctrl: Control key is released. // alt: Alternate key is released. /// - virtual void OnKeyRelease(int key, Uint16 character, bool shift, bool ctrl, bool alt); + virtual void OnKeyRelease(int key, int scan, bool repeat, bool shift, bool ctrl, bool alt); + + virtual void OnTextInput(String text); }; } diff --git a/src/gui/interface/Engine.cpp b/src/gui/interface/Engine.cpp index ed0e09630e..680ef630b3 100644 --- a/src/gui/interface/Engine.cpp +++ b/src/gui/interface/Engine.cpp @@ -17,7 +17,6 @@ Engine::Engine(): FpsLimit(60.0f), Scale(1), Fullscreen(false), - Depth3d(0), FrameIndex(0), lastBuffer(NULL), prevBuffers(stack()), @@ -93,6 +92,7 @@ void Engine::ConfirmExit() void Engine::ShowWindow(Window * window) { windowOpenState = 0; + ignoreEvents = true; if(window->Position.X==-1) { window->Position.X = (width_-window->Size.X)/2; @@ -199,6 +199,7 @@ void Engine::Tick() lastTick = Platform::GetTime(); + ignoreEvents = false; /*if(statequeued_ != NULL) { if(state_ != NULL) @@ -250,29 +251,35 @@ void Engine::SetFps(float fps) this->dt = 1.0f; } -void Engine::onKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt) +void Engine::onKeyPress(int key, int scan, bool repeat, bool shift, bool ctrl, bool alt) { - if(state_) - state_->DoKeyPress(key, character, shift, ctrl, alt); + if (state_ && !ignoreEvents) + state_->DoKeyPress(key, scan, repeat, shift, ctrl, alt); } -void Engine::onKeyRelease(int key, Uint16 character, bool shift, bool ctrl, bool alt) +void Engine::onKeyRelease(int key, int scan, bool repeat, bool shift, bool ctrl, bool alt) { - if(state_) - state_->DoKeyRelease(key, character, shift, ctrl, alt); + if (state_ && !ignoreEvents) + state_->DoKeyRelease(key, scan, repeat, shift, ctrl, alt); +} + +void Engine::onTextInput(String text) +{ + if (state_ && !ignoreEvents) + state_->DoTextInput(text); } void Engine::onMouseClick(int x, int y, unsigned button) { mouseb_ |= button; - if(state_) + if (state_ && !ignoreEvents) state_->DoMouseDown(x, y, button); } void Engine::onMouseUnclick(int x, int y, unsigned button) { mouseb_ &= ~button; - if(state_) + if (state_ && !ignoreEvents) state_->DoMouseUp(x, y, button); } @@ -280,7 +287,7 @@ void Engine::onMouseMove(int x, int y) { mousex_ = x; mousey_ = y; - if(state_) + if (state_ && !ignoreEvents) { state_->DoMouseMove(x, y, mousex_ - mousexp_, mousey_ - mouseyp_); } @@ -290,7 +297,7 @@ void Engine::onMouseMove(int x, int y) void Engine::onMouseWheel(int x, int y, int delta) { - if(state_) + if (state_ && !ignoreEvents) state_->DoMouseWheel(x, y, delta); } @@ -301,6 +308,6 @@ void Engine::onResize(int newWidth, int newHeight) void Engine::onClose() { - if(state_) + if (state_) state_->DoExit(); } diff --git a/src/gui/interface/Engine.h b/src/gui/interface/Engine.h index ada38ca157..82701f799e 100644 --- a/src/gui/interface/Engine.h +++ b/src/gui/interface/Engine.h @@ -28,8 +28,9 @@ namespace ui void onMouseClick(int x, int y, unsigned button); void onMouseUnclick(int x, int y, unsigned button); void onMouseWheel(int x, int y, int delta); - void onKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt); - void onKeyRelease(int key, Uint16 character, bool shift, bool ctrl, bool alt); + void onKeyPress(int key, int scan, bool repeat, bool shift, bool ctrl, bool alt); + void onKeyRelease(int key, int scan, bool repeat, bool shift, bool ctrl, bool alt); + void onTextInput(String text); void onResize(int newWidth, int newHeight); void onClose(); @@ -47,8 +48,6 @@ namespace ui inline bool GetFullscreen() { return Fullscreen; } void SetScale(int scale) { Scale = scale; } inline int GetScale() { return Scale; } - void Set3dDepth(int depth3d) { Depth3d = depth3d; if (Depth3d) SetCursorEnabled(0); else SetCursorEnabled(1);} - inline int Get3dDepth() { return Depth3d; } void SetFastQuit(bool fastquit) { FastQuit = fastquit; } inline bool GetFastQuit() {return FastQuit; } @@ -78,7 +77,6 @@ namespace ui Graphics * g; int Scale; bool Fullscreen; - int Depth3d; unsigned int FrameIndex; private: @@ -92,6 +90,7 @@ namespace ui Window* state_; Point windowTargetPosition; int windowOpenState; + bool ignoreEvents = false; bool running_; bool break_; diff --git a/src/gui/interface/Keys.h b/src/gui/interface/Keys.h index 9e284e8023..781c3bda6f 100644 --- a/src/gui/interface/Keys.h +++ b/src/gui/interface/Keys.h @@ -20,6 +20,8 @@ slouken@libsdl.org */ +#include "SDLCompat.h" +#define _SDL_keysym_h #ifndef _SDL_keysym_h #define _SDL_keysym_h diff --git a/src/gui/interface/Label.cpp b/src/gui/interface/Label.cpp index ce4b66f5b1..4aeb8510fc 100644 --- a/src/gui/interface/Label.cpp +++ b/src/gui/interface/Label.cpp @@ -229,8 +229,10 @@ void Label::OnMouseUp(int x, int y, unsigned button) selecting = false; } -void Label::OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt) +void Label::OnKeyPress(int key, int scan, bool repeat, bool shift, bool ctrl, bool alt) { + if (repeat) + return; if(ctrl && key == 'c') { copySelection(); diff --git a/src/gui/interface/Label.h b/src/gui/interface/Label.h index 0d3338b844..5f4c06516f 100644 --- a/src/gui/interface/Label.h +++ b/src/gui/interface/Label.h @@ -62,7 +62,7 @@ namespace ui virtual void OnMouseClick(int x, int y, unsigned button); virtual void OnMouseUp(int x, int y, unsigned button); virtual void OnMouseMoved(int localx, int localy, int dx, int dy); - virtual void OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt); + virtual void OnKeyPress(int key, int scan, bool repeat, bool shift, bool ctrl, bool alt); virtual void Draw(const Point& screenPos); virtual void Tick(float dt); }; diff --git a/src/gui/interface/Mouse.h b/src/gui/interface/Mouse.h index 0e9cf5fef1..ffa7085f3e 100644 --- a/src/gui/interface/Mouse.h +++ b/src/gui/interface/Mouse.h @@ -2,7 +2,7 @@ #ifdef USE_SDL #ifdef SDL_INC -#include "SDL/SDL_mouse.h" +#include "SDL2/SDL_mouse.h" #else #include "SDL_mouse.h" #endif diff --git a/src/gui/interface/Panel.cpp b/src/gui/interface/Panel.cpp index 0d7fd7cd3d..87684acdfd 100644 --- a/src/gui/interface/Panel.cpp +++ b/src/gui/interface/Panel.cpp @@ -175,14 +175,14 @@ void Panel::Tick(float dt) children[i]->Tick(dt); } -void Panel::OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt) +void Panel::OnKeyPress(int key, int scan, bool repeat, bool shift, bool ctrl, bool alt) { - XOnKeyPress(key, character, shift, ctrl, alt); + XOnKeyPress(key, scan, repeat, shift, ctrl, alt); } -void Panel::OnKeyRelease(int key, Uint16 character, bool shift, bool ctrl, bool alt) +void Panel::OnKeyRelease(int key, int scan, bool repeat, bool shift, bool ctrl, bool alt) { - XOnKeyRelease(key, character, shift, ctrl, alt); + XOnKeyRelease(key, scan, repeat, shift, ctrl, alt); } void Panel::OnMouseClick(int localx, int localy, unsigned button) @@ -401,11 +401,11 @@ void Panel::XTick(float dt) { } -void Panel::XOnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt) +void Panel::XOnKeyPress(int key, int scan, bool repeat, bool shift, bool ctrl, bool alt) { } -void Panel::XOnKeyRelease(int key, Uint16 character, bool shift, bool ctrl, bool alt) +void Panel::XOnKeyRelease(int key, int scan, bool repeat, bool shift, bool ctrl, bool alt) { } diff --git a/src/gui/interface/Panel.h b/src/gui/interface/Panel.h index c8b3ec2586..fe9070aec3 100644 --- a/src/gui/interface/Panel.h +++ b/src/gui/interface/Panel.h @@ -72,34 +72,14 @@ class Component; void OnMouseUnclick(int localx, int localy, unsigned button); void OnMouseWheel(int localx, int localy, int d); void OnMouseWheelInside(int localx, int localy, int d); - void OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt); - void OnKeyRelease(int key, Uint16 character, bool shift, bool ctrl, bool alt); + void OnKeyPress(int key, int scan, bool repeat, bool shift, bool ctrl, bool alt); + void OnKeyRelease(int key, int scan, bool repeat, bool shift, bool ctrl, bool alt); protected: // child components std::vector children; bool mouseInside; - //UI functions: - /* - void XTick(float dt); - void XDraw(const Point& screenPos); - - void XOnMouseHover(int localx, int localy); - void XOnMouseMoved(int localx, int localy, int dx, int dy); - void XOnMouseMovedInside(int localx, int localy, int dx, int dy); - void XOnMouseEnter(int localx, int localy); - void XOnMouseLeave(int localx, int localy); - void XOnMouseDown(int x, int y, unsigned int button); - void XOnMouseUp(int x, int y, unsigned int button); - void XOnMouseClick(int localx, int localy, unsigned int button); - void XOnMouseUnclick(int localx, int localy, unsigned int button); - void XOnMouseWheel(int localx, int localy, int d); - void XOnMouseWheelInside(int localx, int localy, int d); - void XOnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt); - void XOnKeyRelease(int key, Uint16 character, bool shift, bool ctrl, bool alt); - */ - // Overridable. Called by XComponent::Tick() virtual void XTick(float dt); @@ -141,10 +121,10 @@ class Component; virtual void XOnMouseWheelInside(int localx, int localy, int d); // Overridable. Called by XComponent::OnKeyPress() - virtual void XOnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt); + virtual void XOnKeyPress(int key, int scan, bool repeat, bool shift, bool ctrl, bool alt); // Overridable. Called by XComponent::OnKeyRelease() - virtual void XOnKeyRelease(int key, Uint16 character, bool shift, bool ctrl, bool alt); + virtual void XOnKeyRelease(int key, int scan, bool repeat, bool shift, bool ctrl, bool alt); }; } diff --git a/src/gui/interface/Textbox.cpp b/src/gui/interface/Textbox.cpp index 659f909c57..c8fd1a0937 100644 --- a/src/gui/interface/Textbox.cpp +++ b/src/gui/interface/Textbox.cpp @@ -251,7 +251,7 @@ void Textbox::pasteIntoSelection() actionCallback->TextChangedCallback(this); } -bool Textbox::CharacterValid(Uint16 character) +bool Textbox::CharacterValid(int character) { switch(inputType) { @@ -270,6 +270,15 @@ bool Textbox::CharacterValid(Uint16 character) return false; } +// TODO: proper unicode validation +bool Textbox::StringValid(String text) +{ + for (String::value_type c : text) + if (!CharacterValid(c)) + return false; + return true; +} + void Textbox::Tick(float dt) { Label::Tick(dt); @@ -281,29 +290,29 @@ void Textbox::Tick(float dt) unsigned long time_pls = Platform::GetTime(); if ((keyDown || characterDown) && repeatTime <= time_pls) { - OnVKeyPress(keyDown, characterDown, false, false, false); + //OnVKeyPress(keyDown, characterDown, false, false, false); repeatTime = Platform::GetTime()+30; } } -void Textbox::OnKeyRelease(int key, Uint16 character, bool shift, bool ctrl, bool alt) +void Textbox::OnKeyRelease(int key, int scan, bool repeat, bool shift, bool ctrl, bool alt) { keyDown = 0; characterDown = 0; } -void Textbox::OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt) +void Textbox::OnKeyPress(int key, int scan, bool repeat, bool shift, bool ctrl, bool alt) { - characterDown = character; + characterDown = scan; keyDown = key; repeatTime = Platform::GetTime()+300; - OnVKeyPress(key, character, shift, ctrl, alt); + OnVKeyPress(key, scan, repeat, shift, ctrl, alt); } -void Textbox::OnVKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt) +void Textbox::OnVKeyPress(int key, int scan, bool repeat, bool shift, bool ctrl, bool alt) { bool changed = false; - if(ctrl && key == 'c' && !masked) + if(ctrl && key == 'c' && !masked && !repeat) { copySelection(); return; @@ -313,7 +322,7 @@ void Textbox::OnVKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool pasteIntoSelection(); return; } - if(ctrl && key == 'x' && !masked && !ReadOnly) + if(ctrl && key == 'x' && !masked && !repeat && !ReadOnly) { cutSelection(); return; @@ -406,38 +415,7 @@ void Textbox::OnVKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool ClearSelection(); break; case SDLK_RETURN: - character = '\n'; - default: - if (CharacterValid(character) && !ReadOnly) - { - if (HasSelection()) - { - if (getLowerSelectionBound() < 0 || getHigherSelectionBound() > (int)backingText.length()) - return; - backingText.erase(backingText.begin()+getLowerSelectionBound(), backingText.begin()+getHigherSelectionBound()); - cursor = getLowerSelectionBound(); - } - - int regionWidth = Size.X; - if (Appearance.icon) - regionWidth -= 13; - regionWidth -= Appearance.Margin.Left; - regionWidth -= Appearance.Margin.Right; - if ((limit==String::npos || backingText.length() < limit) && (Graphics::textwidth(backingText + character) <= regionWidth || multiline)) - { - if (cursor == (int)backingText.length()) - { - backingText += character; - } - else - { - backingText.Insert(cursor, character); - } - cursor++; - } - changed = true; - ClearSelection(); - } + OnTextInput("\n"); break; } } @@ -446,16 +424,23 @@ void Textbox::OnVKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool cursor = 0; backingText = ""; } - if (inputType == Number) - { - //Remove extra preceding 0's - while(backingText[0] == '0' && backingText.length()>1) - backingText.erase(backingText.begin()); - } + AfterTextChange(changed); +} + +void Textbox::AfterTextChange(bool changed) +{ if (cursor > (int)backingText.length()) cursor = backingText.length(); + if (changed) { + if (inputType == Number) + { + //Remove extra preceding 0's + while(backingText[0] == '0' && backingText.length()>1) + backingText.erase(backingText.begin()); + } + if (masked) { String maskedText = backingText; @@ -468,10 +453,10 @@ void Textbox::OnVKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool } } - if(multiline) + if (multiline) updateMultiline(); updateSelection(); - if(multiline) + if (multiline) TextPosition(textLines); else TextPosition(text); @@ -488,6 +473,40 @@ void Textbox::OnVKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool actionCallback->TextChangedCallback(this); } +void Textbox::OnTextInput(String text) +{ + if (StringValid(text) && !ReadOnly) + { + if (HasSelection()) + { + if (getLowerSelectionBound() < 0 || getHigherSelectionBound() > (int)backingText.length()) + return; + backingText.erase(backingText.begin()+getLowerSelectionBound(), backingText.begin()+getHigherSelectionBound()); + cursor = getLowerSelectionBound(); + } + + int regionWidth = Size.X; + if (Appearance.icon) + regionWidth -= 13; + regionWidth -= Appearance.Margin.Left; + regionWidth -= Appearance.Margin.Right; + if ((limit==String::npos || backingText.length() < limit) && (Graphics::textwidth(backingText + text) <= regionWidth || multiline)) + { + if (cursor == (int)backingText.length()) + { + backingText += text; + } + else + { + backingText.Insert(cursor, text); + } + cursor++; + } + ClearSelection(); + AfterTextChange(true); + } +} + void Textbox::OnMouseClick(int x, int y, unsigned button) { @@ -551,162 +570,3 @@ void Textbox::Draw(const Point& screenPos) if(Appearance.icon) g->draw_icon(screenPos.X+iconPosition.X, screenPos.Y+iconPosition.Y, Appearance.icon); } - -/* -Textbox::Textbox(Point position, Point size, std::string textboxText): - Component(position, size), - text(textboxText), - actionCallback(NULL), - masked(false), - border(true) -{ - SetText(textboxText); - cursor = text.length(); -} - -Textbox::~Textbox() -{ - delete actionCallback; -} - -void Textbox::TextPosition() -{ - if(cursor) - { - cursorPosition = Graphics::textnwidth((char *)displayText.c_str(), cursor); - } - else - { - cursorPosition = 0; - } - Component::TextPosition(displayText); -} - -void Textbox::SetText(std::string text) -{ - cursor = text.length(); - this->text = text; - this->displayText = text; - TextPosition(); -} - - -void Textbox::SetDisplayText(std::string text) -{ - displayText = text; - TextPosition(); -} - -std::string Textbox::GetText() -{ - return text; -} - -void Textbox::OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt) -{ - bool changed = false; - try - { - switch(key) - { - case KEY_HOME: - cursor = 0; - break; - case KEY_END: - cursor = text.length(); - break; - case KEY_LEFT: - if(cursor > 0) - cursor--; - break; - case KEY_RIGHT: - if(cursor < text.length()) - cursor++; - break; - case KEY_DELETE: - if(text.length() && cursor < text.length()) - { - if(ctrl) - text.erase(cursor, text.length()-cursor); - else - text.erase(cursor, 1); - changed = true; - } - break; - case KEY_BACKSPACE: - if(text.length() && cursor > 0) - { - if(ctrl) - { - text.erase(0, cursor); - cursor = 0; - } - else - { - text.erase(cursor-1, 1); - cursor--; - } - changed = true; - } - break; - } - if(character >= ' ' && character < 127) - { - if(cursor == text.length()) - { - text += character; - } - else - { - text.insert(cursor, 1, (char)character); - } - cursor++; - changed = true; - } - } - catch(std::out_of_range &e) - { - cursor = 0; - text = ""; - } - if(changed) - { - if(masked) - { - char * tempText = new char[text.length()+1]; - std::fill(tempText, tempText+text.length(), 0x8d); - tempText[text.length()] = 0; - displayText = std::string(tempText); - delete tempText; - } - else - { - displayText = text; - } - if(actionCallback) - actionCallback->TextChangedCallback(this); - } - TextPosition(); -} - -void Textbox::Draw(const Point& screenPos) -{ - if(!drawn) - { - TextPosition(); - drawn = true; - } - Graphics * g = GetGraphics(); - if(IsFocused()) - { - if(border) g->drawrect(screenPos.X, screenPos.Y, Size.X, Size.Y, 255, 255, 255, 255); - g->draw_line(screenPos.X+textPosition.X+cursorPosition, screenPos.Y+3, screenPos.X+textPosition.X+cursorPosition, screenPos.Y+12, 255, 255, 255, WINDOWW); - } - else - { - if(border) g->drawrect(screenPos.X, screenPos.Y, Size.X, Size.Y, 160, 160, 160, 255); - } - g->drawtext(screenPos.X+textPosition.X, screenPos.Y+textPosition.Y, displayText, 255, 255, 255, 255); - if(Appearance.icon) - g->draw_icon(screenPos.X+iconPosition.X, screenPos.Y+iconPosition.Y, Appearance.icon); -}*/ diff --git a/src/gui/interface/Textbox.h b/src/gui/interface/Textbox.h index 79c3b9461d..d86fb9bf4b 100644 --- a/src/gui/interface/Textbox.h +++ b/src/gui/interface/Textbox.h @@ -19,6 +19,9 @@ class TextboxAction class Textbox : public Label { friend class TextboxAction; + + void AfterTextChange(bool changed); + public: bool ReadOnly; enum ValidInput { All, Multiline, Numeric, Number }; // Numeric doesn't delete trailing 0's @@ -44,16 +47,18 @@ class Textbox : public Label void resetCursorPosition(); void TabFocus(); //Determines if the given character is valid given the input type - bool CharacterValid(Uint16 character); + bool CharacterValid(int character); + bool StringValid(String text); virtual void Tick(float dt); virtual void OnContextMenuAction(int item); virtual void OnMouseClick(int x, int y, unsigned button); virtual void OnMouseUp(int x, int y, unsigned button); virtual void OnMouseMoved(int localx, int localy, int dx, int dy); - virtual void OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt); - virtual void OnVKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt); - virtual void OnKeyRelease(int key, Uint16 character, bool shift, bool ctrl, bool alt); + virtual void OnKeyPress(int key, int scan, bool repeat, bool shift, bool ctrl, bool alt); + virtual void OnVKeyPress(int key, int scan, bool repeat, bool shift, bool ctrl, bool alt); + virtual void OnKeyRelease(int key, int scan, bool repeat, bool shift, bool ctrl, bool alt); + void OnTextInput(String text) override; virtual void Draw(const Point& screenPos); protected: diff --git a/src/gui/interface/Window.cpp b/src/gui/interface/Window.cpp index 42a011db78..a0492f9576 100644 --- a/src/gui/interface/Window.cpp +++ b/src/gui/interface/Window.cpp @@ -283,7 +283,7 @@ void Window::DoTick(float dt) finalise(); } -void Window::DoKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt) +void Window::DoKeyPress(int key, int scan, bool repeat, bool shift, bool ctrl, bool alt) { #ifdef DEBUG if (key == SDLK_TAB && ctrl) @@ -374,11 +374,11 @@ void Window::DoKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool a if (focusedComponent_ != NULL) { if (focusedComponent_->Enabled && focusedComponent_->Visible) - focusedComponent_->OnKeyPress(key, character, shift, ctrl, alt); + focusedComponent_->OnKeyPress(key, scan, repeat, shift, ctrl, alt); } if (!stop) - OnKeyPress(key, character, shift, ctrl, alt); + OnKeyPress(key, scan, repeat, shift, ctrl, alt); if (key == SDLK_ESCAPE) OnTryExit(Escape); @@ -390,7 +390,7 @@ void Window::DoKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool a finalise(); } -void Window::DoKeyRelease(int key, Uint16 character, bool shift, bool ctrl, bool alt) +void Window::DoKeyRelease(int key, int scan, bool repeat, bool shift, bool ctrl, bool alt) { #ifdef DEBUG if(debugMode) @@ -400,11 +400,30 @@ void Window::DoKeyRelease(int key, Uint16 character, bool shift, bool ctrl, bool if (focusedComponent_ != NULL) { if (focusedComponent_->Enabled && focusedComponent_->Visible) - focusedComponent_->OnKeyRelease(key, character, shift, ctrl, alt); + focusedComponent_->OnKeyRelease(key, scan, repeat, shift, ctrl, alt); } if (!stop) - OnKeyRelease(key, character, shift, ctrl, alt); + OnKeyRelease(key, scan, repeat, shift, ctrl, alt); + if (destruct) + finalise(); +} + +void Window::DoTextInput(String text) +{ +#ifdef DEBUG + if (debugMode) + return; +#endif + //on key unpress + if (focusedComponent_ != NULL) + { + if (focusedComponent_->Enabled && focusedComponent_->Visible) + focusedComponent_->OnTextInput(text); + } + + if (!stop) + OnTextInput(text); if (destruct) finalise(); } diff --git a/src/gui/interface/Window.h b/src/gui/interface/Window.h index 200aeb8dd2..4e515baeae 100644 --- a/src/gui/interface/Window.h +++ b/src/gui/interface/Window.h @@ -65,8 +65,9 @@ namespace ui virtual void DoMouseDown(int x, int y, unsigned button); virtual void DoMouseUp(int x, int y, unsigned button); virtual void DoMouseWheel(int x, int y, int d); - virtual void DoKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt); - virtual void DoKeyRelease(int key, Uint16 character, bool shift, bool ctrl, bool alt); + virtual void DoKeyPress(int key, int scan, bool repeat, bool shift, bool ctrl, bool alt); + virtual void DoKeyRelease(int key, int scan, bool repeat, bool shift, bool ctrl, bool alt); + virtual void DoTextInput(String text); // Sets halt and destroy, this causes the Windows to stop sending events and remove itself. void SelfDestruct(); @@ -102,8 +103,9 @@ namespace ui virtual void OnMouseDown(int x, int y, unsigned button) {} virtual void OnMouseUp(int x, int y, unsigned button) {} virtual void OnMouseWheel(int x, int y, int d) {} - virtual void OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt) {} - virtual void OnKeyRelease(int key, Uint16 character, bool shift, bool ctrl, bool alt) {} + virtual void OnKeyPress(int key, int scan, bool repeat, bool shift, bool ctrl, bool alt) {} + virtual void OnKeyRelease(int key, int scan, bool repeat, bool shift, bool ctrl, bool alt) {} + virtual void OnTextInput(String text) {} std::vector Components; Component *focusedComponent_; Component *hoverComponent; diff --git a/src/gui/localbrowser/LocalBrowserView.cpp b/src/gui/localbrowser/LocalBrowserView.cpp index 850264d078..703dd9213e 100644 --- a/src/gui/localbrowser/LocalBrowserView.cpp +++ b/src/gui/localbrowser/LocalBrowserView.cpp @@ -266,16 +266,20 @@ void LocalBrowserView::OnMouseWheel(int x, int y, int d) c->PrevPage(); } -void LocalBrowserView::OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt) +void LocalBrowserView::OnKeyPress(int key, int scan, bool repeat, bool shift, bool ctrl, bool alt) { + if (repeat) + return; if (key == SDLK_ESCAPE) c->Exit(); else if (key == SDLK_LCTRL || key == SDLK_RCTRL) c->SetMoveToFront(false); } -void LocalBrowserView::OnKeyRelease(int key, Uint16 character, bool shift, bool ctrl, bool alt) +void LocalBrowserView::OnKeyRelease(int key, int scan, bool repeat, bool shift, bool ctrl, bool alt) { + if (repeat) + return; if (key == SDLK_LCTRL || key == SDLK_RCTRL) c->SetMoveToFront(true); } diff --git a/src/gui/localbrowser/LocalBrowserView.h b/src/gui/localbrowser/LocalBrowserView.h index 18b9af876c..ec6a4e732c 100644 --- a/src/gui/localbrowser/LocalBrowserView.h +++ b/src/gui/localbrowser/LocalBrowserView.h @@ -38,8 +38,8 @@ class LocalBrowserView: public ui::Window { void NotifySavesListChanged(LocalBrowserModel * sender); void NotifySelectedChanged(LocalBrowserModel * sender); virtual void OnMouseWheel(int x, int y, int d); - virtual void OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt); - virtual void OnKeyRelease(int key, Uint16 character, bool shift, bool ctrl, bool alt); + virtual void OnKeyPress(int key, int scan, bool repeat, bool shift, bool ctrl, bool alt); + virtual void OnKeyRelease(int key, int scan, bool repeat, bool shift, bool ctrl, bool alt); virtual ~LocalBrowserView(); }; diff --git a/src/gui/login/LoginView.cpp b/src/gui/login/LoginView.cpp index e6646ddf0a..29e087397f 100644 --- a/src/gui/login/LoginView.cpp +++ b/src/gui/login/LoginView.cpp @@ -73,8 +73,10 @@ LoginView::LoginView(): passwordField->SetHidden(true); } -void LoginView::OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt) +void LoginView::OnKeyPress(int key, int scan, bool repeat, bool shift, bool ctrl, bool alt) { + if (repeat) + return; switch(key) { case SDLK_TAB: diff --git a/src/gui/login/LoginView.h b/src/gui/login/LoginView.h index f542796588..fab947a12a 100644 --- a/src/gui/login/LoginView.h +++ b/src/gui/login/LoginView.h @@ -27,7 +27,7 @@ class LoginView: public ui::Window { class LoginAction; class CancelAction; LoginView(); - virtual void OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt); + virtual void OnKeyPress(int key, int scan, bool repeat, bool shift, bool ctrl, bool alt); virtual void OnTryExit(ExitMethod method); void AttachController(LoginController * c_) { c = c_; } void NotifyStatusChanged(LoginModel * sender); diff --git a/src/gui/options/OptionsController.cpp b/src/gui/options/OptionsController.cpp index 36f59cf552..aeeae5a0fb 100644 --- a/src/gui/options/OptionsController.cpp +++ b/src/gui/options/OptionsController.cpp @@ -8,7 +8,6 @@ OptionsController::OptionsController(GameModel * gModel_, ControllerCallback * c callback(callback_), HasExited(false) { - this->depth3d = ui::Engine::Ref().Get3dDepth(); view = new OptionsView(); model = new OptionsModel(gModel); model->AddObserver(view); @@ -71,11 +70,6 @@ void OptionsController::SetFastQuit(bool fastquit) model->SetFastQuit(fastquit); } -void OptionsController::Set3dDepth(int depth) -{ - depth3d = depth; -} - OptionsView * OptionsController::GetView() { return view; @@ -84,8 +78,6 @@ OptionsView * OptionsController::GetView() void OptionsController::Exit() { view->CloseActiveWindow(); - // only update on close, it would be hard to edit if the changes were live - ui::Engine::Ref().Set3dDepth(depth3d); if (callback) callback->ControllerExit(); diff --git a/src/gui/options/OptionsController.h b/src/gui/options/OptionsController.h index fd6836bdf8..71e2a1b6f3 100644 --- a/src/gui/options/OptionsController.h +++ b/src/gui/options/OptionsController.h @@ -14,7 +14,6 @@ class OptionsController { OptionsView * view; OptionsModel * model; ControllerCallback * callback; - int depth3d; public: bool HasExited; OptionsController(GameModel * gModel_, ControllerCallback * callback_); @@ -29,7 +28,6 @@ class OptionsController { void SetScale(int scale); void SetFastQuit(bool fastquit); void SetShowAvatars(bool showAvatars); - void Set3dDepth(int depth); void Exit(); OptionsView * GetView(); virtual ~OptionsController(); diff --git a/src/gui/options/OptionsView.cpp b/src/gui/options/OptionsView.cpp index c2881d2cda..96e8003d13 100644 --- a/src/gui/options/OptionsView.cpp +++ b/src/gui/options/OptionsView.cpp @@ -17,7 +17,7 @@ #include "gui/dialogues/ErrorMessage.h" OptionsView::OptionsView(): - ui::Window(ui::Point(-1, -1), ui::Point(300, 348)){ + ui::Window(ui::Point(-1, -1), ui::Point(300, 329)){ ui::Label * tempLabel = new ui::Label(ui::Point(4, 5), ui::Point(Size.X-8, 14), "Simulation Options"); tempLabel->SetTextColour(style::Colour::InformationTitle); @@ -228,19 +228,7 @@ OptionsView::OptionsView(): AddComponent(tempLabel); AddComponent(showAvatars); - class DepthAction: public ui::TextboxAction - { - OptionsView * v; - public: - DepthAction(OptionsView * v_) { v = v_; } - virtual void TextChangedCallback(ui::Textbox * sender) { v->c->Set3dDepth(sender->GetText().ToNumber(true)); } - }; - depthTextbox = new ui::Textbox(ui::Point(8, Size.Y-58), ui::Point(25, 16), String::Build(ui::Engine::Ref().Get3dDepth())); - depthTextbox->SetInputType(ui::Textbox::Numeric); - depthTextbox->SetActionCallback(new DepthAction(this)); - AddComponent(depthTextbox); - - tempLabel = new ui::Label(ui::Point(depthTextbox->Position.X+depthTextbox->Size.X+3, depthTextbox->Position.Y), ui::Point(Size.X-28, 16), "\bg- Change the depth of the 3D anaglyph effect"); + tempLabel = new ui::Label(ui::Point(showAvatars->Position.X+showAvatars->Size.X+3, depthTextbox->Position.Y), ui::Point(Size.X-28, 16), "\bg- Change the depth of the 3D anaglyph effect"); tempLabel->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; tempLabel->Appearance.VerticalAlign = ui::Appearance::AlignMiddle; AddComponent(tempLabel); diff --git a/src/gui/preview/PreviewView.cpp b/src/gui/preview/PreviewView.cpp index c68783dfd8..470aecea27 100644 --- a/src/gui/preview/PreviewView.cpp +++ b/src/gui/preview/PreviewView.cpp @@ -479,8 +479,10 @@ void PreviewView::OnMouseUp(int x, int y, unsigned int button) } } -void PreviewView::OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt) +void PreviewView::OnKeyPress(int key, int scan, bool repeat, bool shift, bool ctrl, bool alt) { + if (repeat) + return; if ((key == SDLK_KP_ENTER || key == SDLK_RETURN) && (!addCommentBox || !addCommentBox->IsFocused())) openButton->DoAction(); } diff --git a/src/gui/preview/PreviewView.h b/src/gui/preview/PreviewView.h index fcf6fc1a7d..a082af4688 100644 --- a/src/gui/preview/PreviewView.h +++ b/src/gui/preview/PreviewView.h @@ -85,7 +85,7 @@ class PreviewView: public ui::Window { virtual void OnTryExit(ExitMethod method); virtual void OnMouseWheel(int x, int y, int d); virtual void OnMouseUp(int x, int y, unsigned int button); - virtual void OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt); + virtual void OnKeyPress(int key, int scan, bool repeat, bool shift, bool ctrl, bool alt); virtual ~PreviewView(); }; diff --git a/src/gui/render/RenderView.cpp b/src/gui/render/RenderView.cpp index fd486b2d23..cfc20c39b0 100644 --- a/src/gui/render/RenderView.cpp +++ b/src/gui/render/RenderView.cpp @@ -405,8 +405,10 @@ void RenderView::OnTick(float dt) } } -void RenderView::OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt) +void RenderView::OnKeyPress(int key, int scan, bool repeat, bool shift, bool ctrl, bool alt) { + if (repeat) + return; if (shift && key == '1') c->LoadRenderPreset(10); else if(key >= '0' && key <= '9') diff --git a/src/gui/render/RenderView.h b/src/gui/render/RenderView.h index 8220b91b85..9b0e5892f3 100644 --- a/src/gui/render/RenderView.h +++ b/src/gui/render/RenderView.h @@ -37,7 +37,7 @@ class RenderView: public ui::Window { void OnTryExit(ExitMethod method); virtual void OnDraw(); virtual void OnTick(float dt); - virtual void OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt); + virtual void OnKeyPress(int key, int scan, bool repeat, bool shift, bool ctrl, bool alt); virtual void ToolTip(ui::Point senderPosition, String toolTip); virtual ~RenderView(); }; diff --git a/src/gui/search/SearchView.cpp b/src/gui/search/SearchView.cpp index 2c2c5a3959..245b256a57 100644 --- a/src/gui/search/SearchView.cpp +++ b/src/gui/search/SearchView.cpp @@ -798,16 +798,20 @@ void SearchView::OnMouseWheel(int x, int y, int d) else c->PrevPage(); } -void SearchView::OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt) +void SearchView::OnKeyPress(int key, int scan, bool repeat, bool shift, bool ctrl, bool alt) { + if (repeat) + return; if (key == SDLK_ESCAPE) c->Exit(); else if (key == SDLK_LCTRL || key == SDLK_RCTRL) c->InstantOpen(true); } -void SearchView::OnKeyRelease(int key, Uint16 character, bool shift, bool ctrl, bool alt) +void SearchView::OnKeyRelease(int key, int scan, bool repeat, bool shift, bool ctrl, bool alt) { + if (repeat) + return; if (key == SDLK_LCTRL || key == SDLK_RCTRL) c->InstantOpen(false); } diff --git a/src/gui/search/SearchView.h b/src/gui/search/SearchView.h index bef054536e..14d1ec2167 100644 --- a/src/gui/search/SearchView.h +++ b/src/gui/search/SearchView.h @@ -69,8 +69,8 @@ class SearchView: public ui::Window, public ClientListener virtual void Search(String); virtual void OnTick(float dt); virtual void OnMouseWheel(int x, int y, int d); - virtual void OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt); - virtual void OnKeyRelease(int key, Uint16 character, bool shift, bool ctrl, bool alt); + virtual void OnKeyPress(int key, int scan, bool repeat, bool shift, bool ctrl, bool alt); + virtual void OnKeyRelease(int key, int scan, bool repeat, bool shift, bool ctrl, bool alt); }; diff --git a/src/gui/tags/TagsView.cpp b/src/gui/tags/TagsView.cpp index 9aca4934da..f72243898f 100644 --- a/src/gui/tags/TagsView.cpp +++ b/src/gui/tags/TagsView.cpp @@ -131,8 +131,10 @@ void TagsView::NotifyTagsChanged(TagsModel * sender) } } -void TagsView::OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt) +void TagsView::OnKeyPress(int key, int scan, bool repeat, bool shift, bool ctrl, bool alt) { + if (repeat) + return; switch(key) { case SDLK_KP_ENTER: diff --git a/src/gui/tags/TagsView.h b/src/gui/tags/TagsView.h index 06a4df8073..ff572864b7 100644 --- a/src/gui/tags/TagsView.h +++ b/src/gui/tags/TagsView.h @@ -25,7 +25,7 @@ class TagsView: public ui::Window { TagsView(); virtual void OnDraw(); void AttachController(TagsController * c_) { c = c_; } - virtual void OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt); + virtual void OnKeyPress(int key, int scan, bool repeat, bool shift, bool ctrl, bool alt); void NotifyTagsChanged(TagsModel * sender); virtual ~TagsView(); }; diff --git a/src/lua/CommandInterface.h b/src/lua/CommandInterface.h index 52ca21bd2d..516a3c312d 100644 --- a/src/lua/CommandInterface.h +++ b/src/lua/CommandInterface.h @@ -25,8 +25,8 @@ class CommandInterface { virtual bool OnMouseDown(int x, int y, unsigned button) {return true;} virtual bool OnMouseUp(int x, int y, unsigned button, char type) {return true;} virtual bool OnMouseWheel(int x, int y, int d) {return true;} - virtual bool OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt) {return true;} - virtual bool OnKeyRelease(int key, Uint16 character, bool shift, bool ctrl, bool alt) {return true;} + virtual bool OnKeyPress(int key, int scan, bool repeat, bool shift, bool ctrl, bool alt) {return true;} + virtual bool OnKeyRelease(int key, int scan, bool repeat, bool shift, bool ctrl, bool alt) {return true;} virtual bool OnMouseTick() { return true; } virtual void OnTick() { } virtual int Command(String command); diff --git a/src/lua/LegacyLuaAPI.cpp b/src/lua/LegacyLuaAPI.cpp index 652a7f1538..f22d530229 100644 --- a/src/lua/LegacyLuaAPI.cpp +++ b/src/lua/LegacyLuaAPI.cpp @@ -244,7 +244,7 @@ int luacon_elementwrite(lua_State* l) } bool shortcuts = true; -int luacon_keyevent(int key, Uint16 character, int modifier, int event) +int luacon_keyevent(int key, int scan, int modifier, int event) { ui::Engine::Ref().LastTick(Platform::GetTime()); int kycontinue = 1; @@ -263,10 +263,10 @@ int luacon_keyevent(int key, Uint16 character, int modifier, int event) for (int i = 1; i <= len && kycontinue; i++) { lua_rawgeti(l, -1, i); - if ((modifier & KMOD_CTRL) && (character < ' ' || character > '~') && key < 256) + if ((modifier & KMOD_CTRL) && (scan < ' ' || scan > '~') && key < 256) lua_pushlstring(l, (const char*)&key, 1); else - lua_pushlstring(l, (const char*)&character, 1); + lua_pushlstring(l, (const char*)&scan, 1); lua_pushinteger(l, key); lua_pushinteger(l, modifier); lua_pushinteger(l, event); diff --git a/src/lua/LuaScriptHelper.h b/src/lua/LuaScriptHelper.h index 08088c8137..c65d9c74d7 100644 --- a/src/lua/LuaScriptHelper.h +++ b/src/lua/LuaScriptHelper.h @@ -23,7 +23,7 @@ extern int tptParts, tptPartsMeta, tptElementTransitions, tptPartsCData, tptPart void luacon_hook(lua_State *L, lua_Debug *ar); int luacon_step(int mx, int my); int luacon_mouseevent(int mx, int my, int mb, int event, int mouse_wheel); -int luacon_keyevent(int key, Uint16 character, int modifier, int event); +int luacon_keyevent(int key, int scan, int modifier, int event); int luacon_eval(const char *command); String luacon_geterror(); void luacon_close(); diff --git a/src/lua/LuaScriptInterface.cpp b/src/lua/LuaScriptInterface.cpp index a4fc601f2f..5f4e3a1755 100644 --- a/src/lua/LuaScriptInterface.cpp +++ b/src/lua/LuaScriptInterface.cpp @@ -2288,17 +2288,7 @@ int LuaScriptInterface::renderer_debugHUD(lua_State * l) int LuaScriptInterface::renderer_depth3d(lua_State * l) { - int acount = lua_gettop(l); - if (acount == 0) - { - lua_pushnumber(l, ui::Engine::Ref().Get3dDepth()); - return 1; - } - int depth3d = luaL_optint(l, 1, -3); - if (depth3d < -30 || depth3d > 30) - return luaL_error(l, "3D depth is too large"); - ui::Engine::Ref().Set3dDepth(depth3d); - return 0; + return luaL_error(l, "This feature is no longer supported"); } void LuaScriptInterface::initElementsAPI() @@ -3374,12 +3364,12 @@ bool LuaScriptInterface::OnMouseWheel(int x, int y, int d) return luacon_mouseevent(x, y, luacon_mousedown?luacon_mousebutton:0, 0, d); } -bool LuaScriptInterface::OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt) +bool LuaScriptInterface::OnKeyPress(int key, int scan, bool repeat, bool shift, bool ctrl, bool alt) { - return luacon_keyevent(key, character, GetModifiers(), LUACON_KDOWN); + return luacon_keyevent(key, scan, GetModifiers(), LUACON_KDOWN); } -bool LuaScriptInterface::OnKeyRelease(int key, Uint16 character, bool shift, bool ctrl, bool alt) +bool LuaScriptInterface::OnKeyRelease(int key, int scan, bool repeat, bool shift, bool ctrl, bool alt) { int modifiers = 0; if(shift) diff --git a/src/lua/LuaScriptInterface.h b/src/lua/LuaScriptInterface.h index e5e9480a14..7b75571551 100644 --- a/src/lua/LuaScriptInterface.h +++ b/src/lua/LuaScriptInterface.h @@ -182,8 +182,8 @@ class LuaScriptInterface: public CommandInterface virtual bool OnMouseDown(int x, int y, unsigned button); virtual bool OnMouseUp(int x, int y, unsigned button, char type); virtual bool OnMouseWheel(int x, int y, int d); - virtual bool OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt); - virtual bool OnKeyRelease(int key, Uint16 character, bool shift, bool ctrl, bool alt); + virtual bool OnKeyPress(int key, int scan, bool repeat, bool shift, bool ctrl, bool alt); + virtual bool OnKeyRelease(int key, int scan, bool repeat, bool shift, bool ctrl, bool alt); virtual bool OnMouseTick(); virtual void OnTick(); virtual void Init(); diff --git a/src/lua/LuaWindow.cpp b/src/lua/LuaWindow.cpp index b7e4c79e56..dedb17ec2d 100644 --- a/src/lua/LuaWindow.cpp +++ b/src/lua/LuaWindow.cpp @@ -98,8 +98,8 @@ LuaWindow::LuaWindow(lua_State * l) : virtual void OnMouseDown(int x, int y, unsigned button) { luaWindow->triggerOnMouseDown(x, y, button); } virtual void OnMouseUp(int x, int y, unsigned button) { luaWindow->triggerOnMouseUp(x, y, button); } virtual void OnMouseWheel(int x, int y, int d) { luaWindow->triggerOnMouseWheel(x, y, d); } - virtual void OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt) { luaWindow->triggerOnKeyPress(key, character, shift, ctrl, alt); } - virtual void OnKeyRelease(int key, Uint16 character, bool shift, bool ctrl, bool alt) { luaWindow->triggerOnKeyRelease(key, character, shift, ctrl, alt); } + virtual void OnKeyPress(int key, int scan, bool repeat, bool shift, bool ctrl, bool alt) { luaWindow->triggerOnKeyPress(key, scan, repeat, shift, ctrl, alt); } + virtual void OnKeyRelease(int key, int scan, bool repeat, bool shift, bool ctrl, bool alt) { luaWindow->triggerOnKeyRelease(key, scan, repeat, shift, ctrl, alt); } }; window = new DrawnWindow(ui::Point(posX, posY), ui::Point(sizeX, sizeY), this); @@ -359,13 +359,13 @@ void LuaWindow::triggerOnMouseWheel(int x, int y, int d) } } -void LuaWindow::triggerOnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt) +void LuaWindow::triggerOnKeyPress(int key, int scan, bool repeat, bool shift, bool ctrl, bool alt) { if(onKeyPressFunction) { lua_rawgeti(l, LUA_REGISTRYINDEX, onKeyPressFunction); lua_pushinteger(l, key); - lua_pushinteger(l, character); + lua_pushinteger(l, scan); lua_pushboolean(l, shift); lua_pushboolean(l, ctrl); lua_pushboolean(l, alt); @@ -376,13 +376,13 @@ void LuaWindow::triggerOnKeyPress(int key, Uint16 character, bool shift, bool ct } } -void LuaWindow::triggerOnKeyRelease(int key, Uint16 character, bool shift, bool ctrl, bool alt) +void LuaWindow::triggerOnKeyRelease(int key, int scan, bool repeat, bool shift, bool ctrl, bool alt) { if(onKeyReleaseFunction) { lua_rawgeti(l, LUA_REGISTRYINDEX, onKeyReleaseFunction); lua_pushinteger(l, key); - lua_pushinteger(l, character); + lua_pushinteger(l, scan); lua_pushboolean(l, shift); lua_pushboolean(l, ctrl); lua_pushboolean(l, alt); diff --git a/src/lua/LuaWindow.h b/src/lua/LuaWindow.h index 7b03561765..3c697e6dd3 100644 --- a/src/lua/LuaWindow.h +++ b/src/lua/LuaWindow.h @@ -60,8 +60,8 @@ class LuaWindow void triggerOnMouseDown(int x, int y, unsigned button); void triggerOnMouseUp(int x, int y, unsigned button); void triggerOnMouseWheel(int x, int y, int d); - void triggerOnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt); - void triggerOnKeyRelease(int key, Uint16 character, bool shift, bool ctrl, bool alt); + void triggerOnKeyPress(int key, int scan, bool repeat, bool shift, bool ctrl, bool alt); + void triggerOnKeyRelease(int key, int scan, bool repeat, bool shift, bool ctrl, bool alt); public: LuaScriptInterface * ci;