Subversion Repositories pentevo

Rev

Rev 716 | Blame | Last modification | View Log | Download | RSS feed

  1. #include "std.h"
  2.  
  3. #include "emul.h"
  4. #include "vars.h"
  5. #include "dx.h"
  6. #include "dxovr.h"
  7. #include "dxerr.h"
  8. #include "init.h"
  9.  
  10. DWORD colorkey=-1;
  11.  
  12. void update_overlay()
  13. {
  14.  
  15.    RECT rc_src, rc_dst;
  16.  
  17.    GetClientRect(wnd, &rc_dst);
  18.    ClientToScreen(wnd, (POINT*)&rc_dst.left);
  19.    ClientToScreen(wnd, (POINT*)&rc_dst.right);
  20.  
  21.    if (rc_dst.left == rc_dst.right || rc_dst.top == rc_dst.bottom) return;
  22.  
  23.    rc_src.left = rc_src.top = 0;
  24.    rc_src.right = temp.ox, rc_src.bottom = temp.oy;
  25.  
  26.    if (wnd == GetForegroundWindow() && rc_dst.left >= 0 && rc_dst.top >= 0)
  27.    {
  28.       DDSURFACEDESC desc; desc.dwSize = sizeof desc;
  29.       if (sprim->IsLost() == DDERR_SURFACELOST)
  30.           sprim->Restore();
  31.       HRESULT r = sprim->Lock(0, &desc, DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT | DDLOCK_READONLY, 0);
  32.       if (r != DD_OK) { printrdd("IDirectDrawSurface2::Lock() [test]", r); exit(); }
  33.       char *ptr = (char*)desc.lpSurface + rc_dst.top*desc.lPitch + rc_dst.left*desc.ddpfPixelFormat.dwRGBBitCount/8;
  34.       colorkey = *(unsigned*)ptr;
  35.       sprim->Unlock(0);
  36.       if (desc.ddpfPixelFormat.dwRGBBitCount < 32)
  37.          colorkey &= (1<<desc.ddpfPixelFormat.dwRGBBitCount)-1;
  38.    }
  39.  
  40.    // use min and max stretch
  41.    DDCAPS caps; caps.dwSize = sizeof caps; dd->GetCaps(&caps,0);
  42.    if ((rc_dst.right - rc_dst.left)*1000/temp.ox > (int)caps.dwMaxOverlayStretch)
  43.       rc_dst.right = rc_dst.left + temp.ox*caps.dwMaxOverlayStretch/1000;
  44.    if ((rc_dst.bottom - rc_dst.top)*1000/temp.oy > (int)caps.dwMaxOverlayStretch)
  45.       rc_dst.bottom = rc_dst.top + temp.oy*caps.dwMaxOverlayStretch/1000;
  46.    if ((rc_dst.right - rc_dst.left)*1000/temp.ox < (int)caps.dwMinOverlayStretch)
  47.       rc_dst.right = rc_dst.left + temp.ox*caps.dwMinOverlayStretch/1000;
  48.    if ((rc_dst.bottom - rc_dst.top)*1000/temp.oy < (int)caps.dwMinOverlayStretch)
  49.       rc_dst.bottom = rc_dst.top + temp.oy*caps.dwMinOverlayStretch/1000;
  50.  
  51.    // setup boundaries for non-clipping overlay
  52.    int mx = GetSystemMetrics(SM_CXSCREEN), my = GetSystemMetrics(SM_CYSCREEN);
  53.    if (rc_dst.left < 0) rc_src.left = -rc_dst.left * (rc_src.right - rc_src.left) / (rc_dst.right - rc_dst.left), rc_dst.left = 0;
  54.    if (rc_dst.top < 0) rc_src.top = -rc_dst.top * (rc_src.bottom - rc_src.top) / (rc_dst.bottom - rc_dst.top), rc_dst.top = 0;
  55.    if (rc_dst.right > mx) rc_src.right = rc_src.left + (mx - rc_dst.left) * (rc_src.right - rc_src.left) / (rc_dst.right - rc_dst.left), rc_dst.right = mx;
  56.    if (rc_dst.bottom > my) rc_src.bottom = (my - rc_dst.top) * (rc_src.bottom - rc_src.top) / (rc_dst.bottom - rc_dst.top), rc_dst.bottom = my;
  57.  
  58.    if (colorkey==-1) return;
  59.    if (rc_dst.left >= rc_dst.right || rc_dst.top >= rc_dst.bottom) return;
  60.    if (rc_src.left >= rc_src.right || rc_src.top >= rc_src.bottom) return;
  61.  
  62.    DDOVERLAYFX fx = { sizeof fx };
  63.    fx.dckDestColorkey.dwColorSpaceLowValue = fx.dckDestColorkey.dwColorSpaceHighValue = colorkey;
  64.  
  65.    for (;;) {
  66.       HRESULT r = surf0->UpdateOverlay(&rc_src, sprim, &rc_dst, DDOVER_SHOW | DDOVER_DDFX | DDOVER_KEYDESTOVERRIDE, &fx);
  67.       if (r == DD_OK) break;
  68.       if (r == DDERR_SURFACELOST) {
  69.          if (surf0->Restore() != DD_OK) set_vidmode(); // recreate overlay
  70.          break; // another update_overlay in set_vidmode() -> UpdateWindow()
  71.       }
  72.       printrdd("IDirectDrawSurface2::UpdateOverlay()", r); exit();
  73.    }
  74. }
  75.