DXGL r836 - Code Review

Jump to navigation Jump to search
Repository:DXGL
Revision:r835‎ | r836 | r837 >
Date:23:47, 17 July 2018
Author:admin
Status:new
Tags:
Comment:
Fix mouse pointer tests when the default cursor has a hotspot other than at 0,0.
Modified paths:
  • /dxglcfg/tests.cpp (modified) (history)

Diff [purge]

Index: dxglcfg/tests.cpp
@@ -48,6 +48,7 @@
4949 static unsigned int randnum;
5050 static int testtypes[] = {0,1,0,1,0,1,0,0,2,1,0,0,0,0,0,0,0};
5151 static DWORD counter;
 52+static DWORD hotspotx,hotspoty;
5253
5354 #define FVF_COLORVERTEX (D3DFVF_VERTEX | D3DFVF_DIFFUSE | D3DFVF_SPECULAR)
5455 struct COLORVERTEX
@@ -800,6 +801,7 @@
801802 bgcolor = 0;
802803 DDCOLORKEY ckey;
803804 HCURSOR cursor;
 805+ ICONINFO iconinfo;
804806 HDC memorydc;
805807 BITMAPINFO bitmapinfo;
806808 HBITMAP bitmap;
@@ -1045,6 +1047,11 @@
10461048 bitmap = CreateDIBSection(memorydc, &bitmapinfo, DIB_RGB_COLORS, &bmppointer, NULL, 0);
10471049 temp = SelectObject(memorydc, bitmap);
10481050 DeleteObject(temp);
 1051+ GetIconInfo(cursor,&iconinfo);
 1052+ hotspotx = iconinfo.xHotspot;
 1053+ hotspoty = iconinfo.yHotspot;
 1054+ if(iconinfo.hbmColor) DeleteObject(iconinfo.hbmColor);
 1055+ if(iconinfo.hbmMask) DeleteObject(iconinfo.hbmMask);
10491056 for (i = 0; i < 7; i++)
10501057 {
10511058 DrawIcon(memorydc, i*sprites[0].ddsd.dwWidth, 0, cursor);
@@ -1318,6 +1325,11 @@
13191326 bltfx.dwFillColor = 0;
13201327 sprites[0].surface->Blt(NULL, NULL, NULL, DDBLT_COLORFILL, &bltfx);
13211328 cursor = LoadCursor(NULL, IDC_ARROW);
 1329+ GetIconInfo(cursor,&iconinfo);
 1330+ hotspotx = iconinfo.xHotspot;
 1331+ hotspoty = iconinfo.yHotspot;
 1332+ if(iconinfo.hbmColor) DeleteObject(iconinfo.hbmColor);
 1333+ if(iconinfo.hbmMask) DeleteObject(iconinfo.hbmMask);
13221334 sprites[0].surface->GetDC(&hRenderDC);
13231335 DrawIcon(hRenderDC, 0, 0, cursor);
13241336 sprites[0].surface->ReleaseDC(hRenderDC);
@@ -1535,29 +1547,53 @@
15361548 {
15371549 if (!out[i])
15381550 {
1539 - destrect.left = GET_X_LPARAM(lastmouselparam[i]);
1540 - destrect.top = GET_Y_LPARAM(lastmouselparam[i]);
1541 - destrect.right = GET_X_LPARAM(lastmouselparam[i]) + sprites[0].ddsd.dwWidth;
 1551+ destrect.left = GET_X_LPARAM(lastmouselparam[i])-hotspotx;
 1552+ destrect.top = GET_Y_LPARAM(lastmouselparam[i])-hotspoty;
 1553+ destrect.right = (GET_X_LPARAM(lastmouselparam[i])-hotspotx) + sprites[0].ddsd.dwWidth;
15421554 if (destrect.right > width) destrect.right = width;
1543 - destrect.bottom = GET_Y_LPARAM(lastmouselparam[i]) + sprites[0].ddsd.dwHeight;
 1555+ destrect.bottom = (GET_Y_LPARAM(lastmouselparam[i])-hotspoty) + sprites[0].ddsd.dwHeight;
15441556 if (destrect.bottom > height) destrect.bottom = height;
15451557 srcrect.left = srcrect.top = 0;
1546 - srcrect.right = destrect.right - destrect.left;
1547 - srcrect.bottom = destrect.bottom - destrect.top;
 1558+ if(destrect.left >= 0) srcrect.right = destrect.right - destrect.left;
 1559+ else
 1560+ {
 1561+ srcrect.left = -destrect.left-1;
 1562+ destrect.left = 0;
 1563+ srcrect.right = sprites[0].ddsd.dwWidth;
 1564+ }
 1565+ if(destrect.top >= 0) srcrect.bottom = destrect.bottom - destrect.top;
 1566+ else
 1567+ {
 1568+ srcrect.top = -destrect.top-1;
 1569+ destrect.top = 0;
 1570+ srcrect.bottom = sprites[0].ddsd.dwWidth;
 1571+ }
15481572 temp1->Blt(&destrect, sprites[0].surface, &srcrect, DDBLT_KEYSRC | DDBLT_WAIT, NULL);
15491573 }
15501574 }
15511575 if (!out[8])
15521576 {
1553 - destrect.left = p.x;
1554 - destrect.top = p.y;
1555 - destrect.right = p.x + sprites[1].ddsd.dwWidth;
 1577+ destrect.left = p.x-hotspotx;
 1578+ destrect.top = p.y-hotspoty;
 1579+ destrect.right = (p.x-hotspotx) + sprites[1].ddsd.dwWidth;
15561580 if (destrect.right > width) destrect.right = width;
1557 - destrect.bottom = p.y + sprites[1].ddsd.dwHeight;
 1581+ destrect.bottom = (p.y-hotspoty) + sprites[1].ddsd.dwHeight;
15581582 if (destrect.bottom > height) destrect.bottom = height;
15591583 srcrect.left = srcrect.top = 0;
1560 - srcrect.right = destrect.right - destrect.left;
1561 - srcrect.bottom = destrect.bottom - destrect.top;
 1584+ if(destrect.left >= 0) srcrect.right = destrect.right - destrect.left;
 1585+ else
 1586+ {
 1587+ srcrect.left = -destrect.left-1;
 1588+ destrect.left = 0;
 1589+ srcrect.right = sprites[0].ddsd.dwWidth;
 1590+ }
 1591+ if(destrect.top >= 0) srcrect.bottom = destrect.bottom - destrect.top;
 1592+ else
 1593+ {
 1594+ srcrect.top = -destrect.top-1;
 1595+ destrect.top = 0;
 1596+ srcrect.bottom = sprites[0].ddsd.dwWidth;
 1597+ }
15621598 temp1->Blt(&destrect, sprites[1].surface, &srcrect, DDBLT_KEYSRC | DDBLT_WAIT, NULL);
15631599 }
15641600 if (backbuffers) temp1->Release();
@@ -1988,15 +2024,27 @@
19892025 {
19902026 if (backbuffers) ddsrender->GetAttachedSurface(&ddscaps, &temp1);
19912027 else temp1 = ddsrender;
1992 - destrect.left = (LONG)sprites[0].x;
1993 - destrect.top = (LONG)sprites[0].y;
1994 - destrect.right = (LONG)sprites[0].x + sprites[0].ddsd.dwWidth;
 2028+ destrect.left = (LONG)sprites[0].x-hotspotx;
 2029+ destrect.top = (LONG)sprites[0].y-hotspoty;
 2030+ destrect.right = (LONG)(sprites[0].x-hotspotx) + sprites[0].ddsd.dwWidth;
19952031 if (destrect.right > width) destrect.right = width;
1996 - destrect.bottom = (LONG)sprites[0].y + sprites[0].ddsd.dwHeight;
 2032+ destrect.bottom = (LONG)(sprites[0].y-hotspoty) + sprites[0].ddsd.dwHeight;
19972033 if (destrect.bottom > height) destrect.bottom = height;
19982034 srcrect.left = srcrect.top = 0;
1999 - srcrect.right = destrect.right - destrect.left;
2000 - srcrect.bottom = destrect.bottom - destrect.top;
 2035+ if(destrect.left >= 0) srcrect.right = destrect.right - destrect.left;
 2036+ else
 2037+ {
 2038+ srcrect.left = -destrect.left-1;
 2039+ destrect.left = 0;
 2040+ srcrect.right = sprites[0].ddsd.dwWidth;
 2041+ }
 2042+ if(destrect.top >= 0) srcrect.bottom = destrect.bottom - destrect.top;
 2043+ else
 2044+ {
 2045+ srcrect.top = -destrect.top-1;
 2046+ destrect.top = 0;
 2047+ srcrect.bottom = sprites[0].ddsd.dwWidth;
 2048+ }
20012049 temp1->Blt(&destrect, sprites[0].surface, &srcrect, DDBLT_KEYSRC | DDBLT_WAIT, NULL);
20022050 if (backbuffers) temp1->Release();
20032051 }