diff --git a/sdl/sdl-display.cpp b/sdl/sdl-display.cpp index 671ff17..bd80e1b 100644 --- a/sdl/sdl-display.cpp +++ b/sdl/sdl-display.cpp @@ -57,7 +57,7 @@ SDLDisplay::SDLDisplay() SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SDLDISPLAY_WIDTH, SDLDISPLAY_HEIGHT, - SDL_WINDOW_SHOWN); + SDL_WINDOW_SHOWN|SDL_WINDOW_RESIZABLE); // SDL_RENDERER_SOFTWARE because, at least on my Mac, this has some // serious issues with hardware accelerated drawing (flashing and crashing). @@ -65,6 +65,12 @@ SDLDisplay::SDLDisplay() SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255); // set to white SDL_RenderClear(renderer); // clear it to the selected color SDL_RenderPresent(renderer); // perform the render + + buffer = SDL_CreateTexture(renderer, + SDL_PIXELFORMAT_RGB888, + SDL_TEXTUREACCESS_STREAMING, + SDLDISPLAY_WIDTH, + SDLDISPLAY_HEIGHT); } SDLDisplay::~SDLDisplay() @@ -102,56 +108,45 @@ void SDLDisplay::drawImageOfSizeAt(const uint8_t *img, for (uint16_t x=0; x> 16; - g = (colorIdx & 0x00FF00) >> 8; - b = (colorIdx & 0x0000FF); - - if (g_displayType == m_monochrome) { - // float fv = 0.2125 * r + 0.7154 * g + 0.0721 * b; - // r = b = 0; - // g = fv; - } - else if (g_displayType == m_blackAndWhite) { - // Used to reduce to B&W in this driver, but now it's up in the apple display - // float fv = 0.2125 * r + 0.7154 * g + 0.0721 * b; - // r = g = b = fv; - } - - SDL_SetRenderDrawColor(renderer, r, g, b, 255); - SDL_RenderDrawPoint(renderer, x+SCREENINSET_X, y+SCREENINSET_Y); - } - } - + blit(); + /* if (overlayMessage[0]) { drawString(M_SELECTDISABLED, 1, 240 - 16 - 12, overlayMessage); } SDL_RenderPresent(renderer); + */ } inline void putpixel(SDL_Renderer *renderer, int x, int y, uint8_t r, uint8_t g, uint8_t b) @@ -164,7 +159,7 @@ void SDLDisplay::drawUIPixel(uint16_t x, uint16_t y, uint16_t color) { for (int yoff=0; yoff>1)*SDLDISPLAY_SCALE]; + uint32_t origColor = videoBuffer[y+SCREENINSET_Y][(x>>1)*SDLDISPLAY_SCALE+SCREENINSET_X]; uint32_t newColor = packColor32(loresPixelColors[color]); if (g_displayType == m_blackAndWhite) { // There are four reasonable decisions here: if either pixel @@ -306,7 +299,7 @@ void SDLDisplay::cachePixel(uint16_t x, uint16_t y, uint8_t color) x = (x * SDLDISPLAY_SCALE)/2; for (int yoff=0; yoff 320.0/240.0) { + h = ((1.f * 240.0) / 320.0) * w; + } else { + w = (320.0/240.0) * h; + } + } + + SDL_SetWindowSize(screen, w, h); +} diff --git a/sdl/sdl-display.h b/sdl/sdl-display.h index 46f8acd..55a5ba4 100644 --- a/sdl/sdl-display.h +++ b/sdl/sdl-display.h @@ -10,7 +10,7 @@ // scale can be 1,2,4. '1' is half-width at the highest resolution // (80-col mode). '2' is full width. '4' is double full width. -#define SDLDISPLAY_SCALE 1 +#define SDLDISPLAY_SCALE 2 #define SDLDISPLAY_WIDTH (320*SDLDISPLAY_SCALE) #define SDLDISPLAY_HEIGHT (240*SDLDISPLAY_SCALE) @@ -41,12 +41,14 @@ class SDLDisplay : public PhysicalDisplay { void cacheDoubleWidePixel(uint16_t x, uint16_t y, uint32_t packedColor); virtual void cache2DoubleWidePixels(uint16_t x, uint16_t y, uint8_t colorA, uint8_t colorB); + void windowResized(uint32_t w, uint32_t h); private: uint32_t videoBuffer[SDLDISPLAY_HEIGHT][SDLDISPLAY_WIDTH]; SDL_Window *screen; SDL_Renderer *renderer; + SDL_Texture *buffer; }; #endif diff --git a/sdl/sdl-keyboard.cpp b/sdl/sdl-keyboard.cpp index bb81c34..ac6799b 100644 --- a/sdl/sdl-keyboard.cpp +++ b/sdl/sdl-keyboard.cpp @@ -3,6 +3,7 @@ #include "sdl-paddles.h" #include "sdl-mouse.h" #include "globals.h" +#include "sdl-display.h" SDLKeyboard::SDLKeyboard(VMKeyboard *k) : PhysicalKeyboard(k) { @@ -164,6 +165,15 @@ void SDLKeyboard::maintainKeyboard() event.motion.xrel, event.motion.yrel); break; + // FIXME: this really doesn't belong here. The mouse kinda + // didn't belong here, but this REALLY is wrong. + case SDL_WINDOWEVENT: + if (event.window.event == SDL_WINDOWEVENT_RESIZED) { + printf("Window was resized\n"); + ((SDLDisplay *)g_display)->windowResized(event.window.data1, event.window.data2); + } + break; + case SDL_QUIT: exit(0); }