// Override of Render() - RenderFullScreen() is where the action takes place
// this is called from the rendermanager, normally we won't come this way
// as player thread will handle rendering, and call this itself.
void CGUIWindowFullScreen::Render()
{
#ifdef HAS_VIDEO_PLAYBACK
  g_renderManager.RenderUpdate(true);
#endif
#ifndef HAS_XBOX_HARDWARE
  // win32 video rendering uses this path all the time (it doesn't render from the player directly)
  // so at this point we should renderfullscreen info as well.
  if (NeedRenderFullScreen())
    RenderFullScreen();
#endif
}
unsigned int OpenROM(HWND hwnd)  {
unsigned int Pointer;
unsigned int size;
unsigned int i;

   //first, we get the filename from the user.
   if (!GetROMFile(hwnd))
      return false;

   TheROM=fopen(NewFileName,"rb");
   if (TheROM==NULL)
      return DisplayErrorMessage(hwnd,-22,NewFileName);

   if (!CheckTheROM(hwnd))
   {  //Hey, this isn't SMW!
     fclose(TheROM);
     return false;
   }

   //store the new file name now that we know it's okay.
   strcpy(ROMFileName,&NewFileName[ofn.nFileOffset]);
   strcpy(ROMFilePath,NewFileName);
   ROMFilePath[ofn.nFileOffset]=0;

   //Now we get the PC address for Mario's compressed GFX.
   Pointer=GetAddressFromPointer2(0x3AD8,0x3A90,false);

   //We don't need anything else from the ROM, so close the file.
   fclose(TheROM);

   //Open the ROM in the DLL.
   if (!LunarOpenFile(NewFileName,LC_READONLY))
      return false;  //couldn't open file...!

   //Decompress Mario's GFX from the PC address we got before, and
   // store the 4bpp SNES graphics into the buffer.
   size=LunarDecompress(buffer,Pointer,0x10000,1,0,NULL);

   //The DLL doesn't need anything else from the ROM, so close the file.
   LunarCloseFile();

   if (!size)
      return false;  //decompression failed...!
   if (size>0x10000)
      size=0x10000;  //just to be on the safe side...

   //Take the graphics we just decompressed from the ROM, and have
   // the DLL convert it into a PixelMap that we'll be using later
   // for drawing the tiles in a bitmap.
   LunarCreatePixelMap(buffer,PixelMap,size/32,LC_4BPP);

   //SMW has an icky way of creating palettes, so for the sake of
   // demonstration I'm just going to place Mario's SNES palette into
   // an array directly here rather than trying to read the actual data
   // from the ROM...
   SNESPalette[0]=0;
   SNESPalette[1]=0x7FFF;
   SNESPalette[2]=0;
   SNESPalette[3]=0x0D71;
   SNESPalette[4]=0x1E9B;
   SNESPalette[5]=0x3B7F;
   SNESPalette[6]=0x635F;
   SNESPalette[7]=0x581D;
   SNESPalette[8]=0x000A;
   SNESPalette[9]=0x391F;
   SNESPalette[0xA]=0x44C4;
   SNESPalette[0xB]=0x4E08;
   SNESPalette[0xC]=0x6770;
   SNESPalette[0xD]=0x30B6;
   SNESPalette[0xE]=0x35DF;
   SNESPalette[0xF]=0x03FF;

   //Now convert all the colors in the SNES palette to a PC palette
   // that we'll be using for drawing later...
   for (i=0;i<0x10*0x10;i++)
      ThePalette[i]=LunarSNEStoPCRGB(SNESPalette[i]);

   //Do some win32 API stuff...
   MapLoaded=true;
   CreateMainBitmapXZ(hwnd,TheWindowWidth,TheWindowHeight);
   RenderFullScreen(hwnd);
   InvalidateRect(hwnd,NULL,false);
   UpdateWindow(hwnd);
   return true;
}
LRESULT CALLBACK FrameProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
{
   switch(Message)
   {
      case WM_HSCROLL:{
        int xDelta;
        int xNewPos;
        int yDelta = 0;

        switch (LOWORD(wParam)) {
            /* User clicked the shaft left of the scroll box. */
            case SB_PAGEUP:
                xNewPos = xCurrentScroll - xPageScroll;
                break;
            /* User clicked the shaft right of the scroll box. */
            case SB_PAGEDOWN:
                xNewPos = xCurrentScroll + xPageScroll;
                break;
            /* User clicked the left arrow. */
            case SB_LINEUP:
                xNewPos = xCurrentScroll - xIncrementScroll;
                break;
            /* User clicked the right arrow. */
            case SB_LINEDOWN:
                xNewPos = xCurrentScroll + xIncrementScroll;
                break;
            /* User dragged or is dragging the scroll box. */
            case SB_THUMBPOSITION:
            case SB_THUMBTRACK:
                xNewPos = HIWORD(wParam);
                break;
            default:
                xNewPos = xCurrentScroll;
        }
        /* New position must be between 0 and the screen width. */
        xNewPos = max(0, xNewPos);
        xNewPos = min(xMaxScroll, xNewPos);

        /* If the current position does not change, do not scroll.*/
        if (xNewPos == xCurrentScroll)
            break;

        /* Determine the amount scrolled (in pixels). */
        xDelta = (xNewPos - xCurrentScroll)*xPixelsPerIncrement;
                           //(-) is hit left, scroll right
        /* Reset the current scroll position. */
        xCurrentScroll = xNewPos;

        ScrollDC(hdcMemoryTheMap,-xDelta,-yDelta,NULL,NULL,NULL,NULL);
        MapPositionX=xCurrentScroll;
        if (xDelta>0)    //hit right, scroll left
          RenderScreen(hwnd,max(0,(TheMapWidth-xDelta)),0,TheMapWidth,TheMapHeight);
        else   //hit left, scroll right
          RenderScreen(hwnd,0,0,min(TheMapWidth,-xDelta),TheMapHeight);
        ScrollWindowEx(hwnd, -xDelta, -yDelta, &TheWindowRect,
            &TheWindowRect, (HRGN) NULL, (LPRECT) NULL,
            SW_INVALIDATE);
//             InvalidateRect(hwnd,&TheWindowRect,false);
        UpdateWindow(hwnd);
        ResetScrollBarX(hwnd);
      }
      break;

      case WM_VSCROLL:{
        int xDelta=0;
        int yNewPos;
        int yDelta;

        switch (LOWORD(wParam)) {
            /* User clicked the shaft above scroll box. */
            case SB_PAGEUP:
                yNewPos = yCurrentScroll - yPageScroll;
                break;
            /* User clicked the shaft below the scroll box. */
            case SB_PAGEDOWN:
                yNewPos = yCurrentScroll + yPageScroll;
                break;
            /* User clicked the up arrow. */
            case SB_LINEUP:
                yNewPos = yCurrentScroll - yIncrementScroll;
                break;
            /* User clicked the down arrow. */
            case SB_LINEDOWN:
                yNewPos = yCurrentScroll + yIncrementScroll;
                break;
            /* User dragged or is dragging the scroll box. */
            case SB_THUMBPOSITION:
            case SB_THUMBTRACK:
                yNewPos = HIWORD(wParam);
                break;
            default:
                yNewPos = yCurrentScroll;
        }
        /* New position must be between 0 and the screen height. */
        yNewPos = max(0, yNewPos);
        yNewPos = min(yMaxScroll, yNewPos);

        /* If the current position does not change, do not scroll.*/
        if (yNewPos == yCurrentScroll)
            break;

        /* Determine the amount scrolled (in pixels). */
        yDelta = (yNewPos - yCurrentScroll)*yPixelsPerIncrement;
                           //(-) is hit up, scroll down
        /* Reset the current scroll position. */
        yCurrentScroll = yNewPos;

        ScrollDC(hdcMemoryTheMap,-xDelta,-yDelta,NULL,NULL,NULL,NULL);
        MapPositionY=yCurrentScroll;
        if (yDelta>0)    //hit down, scroll up
          RenderScreen(hwnd,0,max(0,(TheMapHeight-yDelta)),TheMapWidth,TheMapHeight);
        else   //hit up, scroll down
          RenderScreen(hwnd,0,0,TheMapWidth,min(TheMapHeight,-yDelta));

        ScrollWindowEx(hwnd, -xDelta, -yDelta, &TheWindowRect,
            &TheWindowRect, (HRGN) NULL, (LPRECT) NULL,
            SW_INVALIDATE);
        UpdateWindow(hwnd);
        ResetScrollBarY(hwnd);
      }
      break;
      case WM_COMMAND:
          MainWindowCommand(hwnd,LOWORD(wParam));
          break;
      case WM_ERASEBKGND:
          if (MapLoaded)
               return 1;   //don't erase background if we have the map loaded
          return DefWindowProc(hwnd, Message, wParam, lParam);
      case WM_PAINT:
         PAINTSTRUCT ps;
         HDC hdcWindow;
         hdcWindow = BeginPaint(hwnd, &ps);

         if (!TheMapBitmap)
         {
            CreateMainBitmapX(hwnd);
            RenderFullScreen(hwnd);
         }
         DisplayFullScreen2(hdcWindow);

         EndPaint(hwnd, &ps);
         break;

      case WM_SIZE:
         //Adjust our bitmap to fit window
         if ((wParam==SIZE_MAXIMIZED)||(wParam==SIZE_RESTORED))
            AdjustScreenSize(hwnd,LOWORD(lParam),HIWORD(lParam));
         break;
      case WM_CREATE:
         CreateMainMenu(hwnd);
         break;
      case WM_CLOSE:
         DestroyWindow(hwnd);
         break;
      case WM_DESTROY:
         FreeAllData();
         if (hdcMemoryTheMap)
            DeleteDC(hdcMemoryTheMap);
         if (TheMapBitmap)
            DeleteObject(TheMapBitmap);
         PostQuitMessage(0);
         break;
      default: return DefWindowProc(hwnd, Message, wParam, lParam);
   }
   return 0;
}
void AdjustScreenSize(HWND hwnd, int Width, int Height)  {
   if (CreateMainBitmapXZ(hwnd,Width,Height))
      RenderFullScreen(hwnd);
}