DXGL r873 - Code Review

Jump to navigation Jump to search
Repository:DXGL
Revision:r872‎ | r873 | r874 >
Date:01:25, 6 October 2018
Author:admin
Status:new
Tags:
Comment:
Initial work on surface formats test.
Modified paths:
  • /dxglcfg/surfacegen.cpp (modified) (history)
  • /dxglcfg/surfacegen.h (modified) (history)
  • /dxglcfg/tests.cpp (modified) (history)

Diff [purge]

Index: dxglcfg/surfacegen.cpp
@@ -1615,4 +1615,100 @@
16161616 break;
16171617 }
16181618 }
 1619+}
 1620+
 1621+BOOL TextOutShadow(HDC hDC, int x, int y, LPCTSTR string, int count, COLORREF shadow)
 1622+{
 1623+ int bkmode;
 1624+ BOOL ret;
 1625+ COLORREF color;
 1626+ int x2, y2;
 1627+ x2 = x + 1;
 1628+ y2 = y + 1;
 1629+ bkmode = GetBkMode(hDC);
 1630+ if (bkmode == OPAQUE) TextOut(hDC, x, y, string, count); // Ensure background is painted
 1631+ bkmode = SetBkMode(hDC, TRANSPARENT);
 1632+ color = SetTextColor(hDC, shadow);
 1633+ TextOut(hDC, x2, y2, string, count);
 1634+ SetTextColor(hDC, color);
 1635+ ret = TextOut(hDC, x, y, string, count);
 1636+ SetBkMode(hDC, bkmode);
 1637+ return ret;
 1638+}
 1639+
 1640+static const TCHAR strFormatTestTitle[] = _T("Surface format test");
 1641+static const TCHAR strFormatTestKeys1[] = _T("UP/DOWN: src type PGUP/DN: dest type ");
 1642+static const TCHAR strFormatTestKeys2[] = _T("LEFT/RIGHT: pattern TAB: render method");
 1643+static const TCHAR strFormatTestKeys3[] = _T("SPACE: show/hide help/info");
 1644+
 1645+void DrawFormatTestHUD(MultiDirectDrawSurface *surface, int srcformat, int destformat, int showhud, int testpattern, int testmethod, int x, int y)
 1646+{
 1647+ HDC hdc;
 1648+ HRESULT error;
 1649+ COLORREF oldcolor;
 1650+ COLORREF oldbkcolor;
 1651+ HFONT DefaultFont;
 1652+ HFONT newfont;
 1653+ RECT r;
 1654+ int oldbk;
 1655+ SIZE charsize;
 1656+ int rows, cols;
 1657+ int posx, posy;
 1658+ if (!showhud) return;
 1659+ error = surface->GetDC(&hdc);
 1660+ if (FAILED(error)) return;
 1661+ if (y < 350)
 1662+ {
 1663+ newfont = CreateFont(-8, -8, 0, 0, 0, 0, 0, 0, OEM_CHARSET, OUT_DEVICE_PRECIS,
 1664+ CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH, _T("Terminal"));
 1665+ charsize.cx = 8;
 1666+ charsize.cy = 8;
 1667+ }
 1668+ else if ((x > 1024) && (y > 600))
 1669+ {
 1670+ newfont = CreateFont(-16, -12, 0, 0, 0, 0, 0, 0, OEM_CHARSET, OUT_DEVICE_PRECIS,
 1671+ CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH, _T("Terminal"));
 1672+ charsize.cx = 12;
 1673+ charsize.cy = 16;
 1674+ }
 1675+ else
 1676+ {
 1677+ newfont = CreateFont(-12, -8, 0, 0, 0, 0, 0, 0, OEM_CHARSET, OUT_DEVICE_PRECIS,
 1678+ CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH, _T("Terminal"));
 1679+ charsize.cx = 8;
 1680+ charsize.cy = 12;
 1681+ }
 1682+ rows = y / charsize.cy;
 1683+ cols = x / charsize.cx;
 1684+ DefaultFont = (HFONT)SelectObject(hdc, newfont);
 1685+ r.left = 0;
 1686+ r.right = 128;
 1687+ r.top = 0;
 1688+ r.bottom = 16;
 1689+ oldcolor = SetTextColor(hdc, RGB(255, 255, 255));
 1690+ oldbkcolor = SetBkColor(hdc, RGB(0, 0, 255));
 1691+ if(showhud == 2) oldbk = SetBkMode(hdc, TRANSPARENT);
 1692+ else oldbk = SetBkMode(hdc, OPAQUE);
 1693+ TextOutShadow(hdc, 0, 0, strFormatTestTitle, _tcslen(strFormatTestTitle), RGB(0, 0, 192));
 1694+ TextOutShadow(hdc, 0, charsize.cy, strFormatTestKeys1, _tcslen(strFormatTestKeys1), RGB(0, 0, 192));
 1695+ if (cols < (_tcslen(strFormatTestKeys1) + _tcslen(strFormatTestKeys2)))
 1696+ {
 1697+ posx = 0;
 1698+ posy = 2 * charsize.cy;
 1699+ }
 1700+ else
 1701+ {
 1702+ posx = _tcslen(strFormatTestKeys1) * charsize.cx;
 1703+ posy = charsize.cy;
 1704+ }
 1705+ TextOutShadow(hdc, posx, posy, strFormatTestKeys2, _tcslen(strFormatTestKeys2), RGB(0, 0, 192));
 1706+ posx = 0;
 1707+ posy += charsize.cy;
 1708+ TextOutShadow(hdc, posx, posy, strFormatTestKeys3, _tcslen(strFormatTestKeys3), RGB(0, 0, 192));
 1709+ SelectObject(hdc, DefaultFont);
 1710+ DeleteObject(newfont);
 1711+ SetTextColor(hdc, oldcolor);
 1712+ SetBkColor(hdc, oldbkcolor);
 1713+ SetBkMode(hdc, oldbk);
 1714+ surface->ReleaseDC(hdc);
16191715 }
\ No newline at end of file
Index: dxglcfg/surfacegen.h
@@ -28,5 +28,6 @@
2929 HWND hwnd, LPDIRECTDRAWPALETTE palette); // ROP pattern test
3030 void DrawRotatedBlt(MultiDirectDrawSurface *primary, DDSPRITE *sprites);
3131 void DrawColorKeyCompPatterns(DDSURFACEDESC2 ddsd, unsigned char *buffer, int bpp, int index);
 32+void DrawFormatTestHUD(MultiDirectDrawSurface *surface, int srcformat, int destformat, int showhud, int testpattern, int testmethod, int x, int y);
3233
3334 #endif //_SURFACEGEN_H
\ No newline at end of file
Index: dxglcfg/tests.cpp
@@ -49,7 +49,13 @@
5050 static int testtypes[] = {0,1,0,1,0,1,0,0,-1,1,0,0,0,0,0,0,0,0,2};
5151 static DWORD counter;
5252 static DWORD hotspotx,hotspoty;
 53+static int srcformat = 0;
 54+static int destformat = -1;
 55+static int showhud = 1;
 56+static int testpattern = 0;
 57+static int testmethod = 0;
5358
 59+
5460 #define FVF_COLORVERTEX (D3DFVF_VERTEX | D3DFVF_DIFFUSE | D3DFVF_SPECULAR)
5561 struct COLORVERTEX
5662 {
@@ -289,18 +295,22 @@
290296 {
291297 switch (wParam)
292298 {
293 - case VK_SPACE:
 299+ case VK_SPACE: // Show/hide HUD
294300 break;
295 - case VK_UP:
 301+ case VK_UP: // Source format -
296302 break;
297 - case VK_DOWN:
 303+ case VK_DOWN: // Source format +
298304 break;
299 - case VK_LEFT:
 305+ case VK_LEFT: // Test pattern -
300306 break;
301 - case VK_RIGHT:
 307+ case VK_RIGHT: // Test pattern +
302308 break;
303 - case 'P':
 309+ case VK_PRIOR: // Dest format - (PgUp)
304310 break;
 311+ case VK_NEXT: // Dest format + (PgDn)
 312+ break;
 313+ case VK_TAB: // Render method
 314+ break;
305315 }
306316 }
307317 }
@@ -832,7 +842,8 @@
833843 HBITMAP bitmap;
834844 HGDIOBJ temp;
835845 HBRUSH brush;
836 - RECT r;
 846+ RECT r, r1, r2;
 847+ POINT p;
837848 DDCOLORKEY colorkey;
838849 DDBLTFX bltfx;
839850 void *bmppointer;
@@ -1429,6 +1440,21 @@
14301441 }
14311442 }
14321443 break;
 1444+ case 18: // Surface format test
 1445+ ddsrender->GetSurfaceDesc(&ddsd);
 1446+ ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;
 1447+ ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
 1448+ ddinterface->CreateSurface(&ddsd, &sprites[0].surface, NULL); // Initial source surface
 1449+ srcformat = 0;
 1450+ destformat = -1;
 1451+ showhud = 1;
 1452+ testpattern = 0;
 1453+ testmethod = 0;
 1454+ error = sprites[0].surface->Lock(NULL, &ddsd, DDLOCK_WAIT, NULL);
 1455+ DrawPalette(ddsd, (unsigned char*)ddsd.lpSurface);
 1456+ error = sprites[0].surface->Unlock(NULL);
 1457+ ddsrender->Blt(NULL, sprites[0].surface, NULL, DDBLT_WAIT, NULL);
 1458+ DrawFormatTestHUD(ddsrender, 0, -1, 1, 0, 0, ddsd.dwWidth, ddsd.dwHeight);
14331459 default:
14341460 break;
14351461 }