home *** CD-ROM | disk | FTP | other *** search
- // Zinc Interface Library - WINDSP.CPP
- // COPYRIGHT (C) 1990, 1991. All Rights Reserved.
- // Zinc Software Incorporated. Pleasant Grove, Utah USA
-
- #include "ui_win.hpp"
-
- const int pSin[] = { 0, 871, 1736, 2588, 3420, 4226, 5000, 5736, 6428,
- 7071, 7660, 8191, 8660, 9063, 9397, 9659, 9848, 9962, 10000 };
-
- DWORD MapColor(const UI_PALETTE *palette, int foreground)
- {
- DWORD color = foreground ? palette->colorForeground : palette->colorBackground;
-
- // If RGB color specified then mask extra RGB bit, otherwise get the
- // system color from the index given. (Colors found in [COLORS] in WIN.INI)
- if (color & 0x80000000L)
- color &= ~0x80000000L;
- else
- color = GetSysColor((int)color);
- return (color);
- }
-
- UI_MSWINDOWS_DISPLAY::UI_MSWINDOWS_DISPLAY(HANDLE _hInstance, HANDLE _hPrevInstance, int _nCmdShow):
- UI_DISPLAY(FALSE, (4 * LOWORD(GetDialogBaseUnits())) / 4, (14 * HIWORD(GetDialogBaseUnits())) / 8)
- {
- WNDCLASS wndClass;
-
- hInstance = _hInstance;
- hPrevInstance = _hPrevInstance;
- nCmdShow = _nCmdShow;
-
- // Get the maximum screen size in pixels.
- lines = GetSystemMetrics(SM_CYSCREEN);
- columns = GetSystemMetrics(SM_CXSCREEN);
- installed = TRUE;
-
- // Register the MS Windows class for generic Zinc windows.
- if ( !hPrevInstance )
- {
- wndClass.style = CS_HREDRAW | CS_VREDRAW;
- wndClass.lpfnWndProc = MSWindowsProc;
- wndClass.cbClsExtra = 0;
-
- // Reserve extra bytes for each window object to point
- // to the Zinc class structure.
- wndClass.cbWndExtra = sizeof( UIW_WINDOW * );
- wndClass.hInstance = hInstance;
- wndClass.hIcon = LoadIcon( 0, IDI_APPLICATION );
- wndClass.hCursor = LoadCursor( 0, IDC_ARROW );
- wndClass.hbrBackground = COLOR_WINDOW+1;
- wndClass.lpszMenuName = NULL;
- wndClass.lpszClassName = "UIW_WINDOW";
-
- if (!RegisterClass(&wndClass))
- installed = FALSE;
- }
- }
-
- UI_MSWINDOWS_DISPLAY::~UI_MSWINDOWS_DISPLAY(void)
- {
- }
-
- #pragma argsused
- void UI_MSWINDOWS_DISPLAY::Bitmap(SCREENID screenID, int column, int line,
- int bitmapWidth, int bitmapHeight, const UCHAR *bitmapArray,
- const UI_PALETTE *palette, const UI_REGION *clipRegion)
- {
- if (!screenID)
- return;
-
- HDC hDC = GetDC(screenID);
-
- UI_REGION region;
- region.left = column;
- region.top = line;
- region.right = column + bitmapWidth - 1;
- region.bottom = line + bitmapHeight - 1;
- if (clipRegion)
- {
- region.left = Max(region.left, clipRegion->left);
- region.top = Max(region.top, clipRegion->top);
- region.right = Min(region.right, clipRegion->right);
- region.bottom = Min(region.bottom, clipRegion->bottom);
- }
-
- for (int row = region.top; row <= region.bottom; row++)
- {
- UCHAR *pixel = (UCHAR *)(bitmapArray + (row - region.top) * bitmapWidth);
- for (int column = region.left; column <= region.right; column++, pixel++)
- SetPixel(hDC, column, row, *pixel);
- }
-
- ReleaseDC(screenID, hDC);
- }
-
- // Ellipse can be used to draw circles, ellipses, arcs, pie slices, etc.
- // using the foreground color for the border and background color to fill.
- #pragma argsused
- void UI_MSWINDOWS_DISPLAY::Ellipse(SCREENID screenID, int column, int line, int startAngle,
- int endAngle, int xRadius, int yRadius, const UI_PALETTE *palette,
- int fill, int xor, const UI_REGION *clipRegion)
- {
- if (!screenID)
- return;
-
- HBRUSH oldBrush;
-
- HDC hDC = GetDC(screenID);
- int oldROP2 = SetROP2(hDC, (xor == TRUE) ? R2_XORPEN : R2_COPYPEN);
-
- // Set up the coordinates.
- DWORD topLeft = GetDCOrg(hDC);
- int left = column - xRadius - LOWORD(topLeft);
- int top = line - yRadius - HIWORD(topLeft);
- int right = column + xRadius - LOWORD(topLeft);
- int bottom = line + yRadius - HIWORD(topLeft);
-
- // Compute points to start and stop.
- int startX = 0;
- int startY = 0;
- int endX = 0;
- int endY = 0;
- if (startAngle <= 90)
- {
- startX = column - LOWORD(topLeft) + (int)(1L * pSin[(90 - startAngle) / 5] * xRadius / 10000L);
- startY = line - HIWORD(topLeft) + (int)(1L * pSin[startAngle / 5] * yRadius / 10000L);
- }
- else if (startAngle <= 180)
- {
- startX = column - LOWORD(topLeft) - (int)(1L * pSin[(startAngle - 90) / 5] * xRadius / 10000L);
- startY = line - HIWORD(topLeft) + (int)(1L * pSin[(180 - startAngle) / 5] * yRadius / 10000L);
- }
- else if (startAngle <= 270)
- {
- startX = column - LOWORD(topLeft) - (int)(1L * pSin[(270 - startAngle) / 5] * xRadius / 10000L);
- startY = line - HIWORD(topLeft) - (int)(1L * pSin[(startAngle - 180) / 5] * yRadius / 10000L);
- }
- else if (startAngle <= 360)
- {
- startX = column - LOWORD(topLeft) + (int)(1L * pSin[(startAngle - 270) / 5] * xRadius / 10000L);
- startY = line - HIWORD(topLeft) - (int)(1L * pSin[(360 - startAngle) / 5] * yRadius / 10000L);
- }
-
- if (endAngle <= 90)
- {
- endX = column - LOWORD(topLeft) + (int)(1L * pSin[(90 - endAngle) / 5] * xRadius / 10000L);
- endY = line - HIWORD(topLeft) + (int)(1L * pSin[endAngle / 5] * yRadius / 10000L);
- }
- else if (endAngle <= 180)
- {
- endX = column - LOWORD(topLeft) - (int)(1L * pSin[(endAngle - 90) / 5] * xRadius / 10000L);
- endY = line - HIWORD(topLeft) + (int)(1L * pSin[(180 - endAngle) / 5] * yRadius / 10000L);
- }
- else if (endAngle <= 270)
- {
- endX = column - LOWORD(topLeft) - (int)(1L * pSin[(270 - endAngle) / 5] * xRadius / 10000L);
- endY = line - HIWORD(topLeft) - (int)(1L * pSin[(endAngle - 180) / 5] * yRadius / 10000L);
- }
- else if (endAngle <= 360)
- {
- endX = column - LOWORD(topLeft) + (int)(1L * pSin[(endAngle - 270) / 5] * xRadius / 10000L);
- endY = line - HIWORD(topLeft) - (int)(1L * pSin[(360 - endAngle) / 5] * yRadius / 10000L);
- }
-
- HANDLE oldPen = SelectObject(hDC, CreatePen(PS_SOLID, 1, MapColor(palette, TRUE)));
-
- if (fill)
- {
- // Draw an filled ellipse.
- if (palette->hatchStyle == HS_NONE)
- oldBrush = SelectObject(hDC, CreateSolidBrush(MapColor(palette, FALSE)));
- else
- oldBrush = SelectObject(hDC, CreateHatchBrush(palette->hatchStyle, MapColor(palette, FALSE)));
- if (startAngle == 0 && endAngle == 360)
- ::Ellipse(hDC, left, top, right, bottom);
- else
- Pie(hDC, left, top, right, bottom, endX, endY, startX, startY);
-
- DeleteObject(SelectObject(hDC, oldBrush));
- }
- else
- // Draw a line ellipse.
- Arc(hDC, left, top, right, bottom, endX, endY, startX, startY);
-
- SetROP2(hDC, oldROP2);
- DeleteObject(SelectObject(hDC, oldPen));
- ReleaseDC(screenID, hDC);
- }
-
- #pragma argsused
- void UI_MSWINDOWS_DISPLAY::Line(SCREENID screenID, int column1, int line1, int column2, int line2,
- const UI_PALETTE *palette, int width, int xor, const UI_REGION *clipRegion)
- {
- if (!screenID)
- return;
-
- HDC hDC = GetDC(screenID);
- int oldROP2 = SetROP2(hDC, (xor == TRUE) ? R2_XORPEN : R2_COPYPEN);
-
- // Set up the proper region.
- DWORD topLeft = GetDCOrg(hDC);
- column1 -= LOWORD(topLeft);
- line1 -= HIWORD(topLeft);
- column2 -= LOWORD(topLeft);
- line2 -= HIWORD(topLeft);
-
- // Draw the line using the background palette color.
- HANDLE oldPen = SelectObject(hDC, CreatePen(PS_SOLID, width, MapColor(palette, TRUE)));
- MoveTo(hDC, column1, line1);
- LineTo(hDC, column2, line2);
-
- SetROP2(hDC, oldROP2);
- DeleteObject(SelectObject(hDC, oldPen));
- ReleaseDC(screenID, hDC);
- }
-
- #pragma argsused
- void UI_MSWINDOWS_DISPLAY::Polygon(SCREENID screenID, int numPoints,
- const int *polygonPoints, const UI_PALETTE *palette, int fill, int xor,
- const UI_REGION *clipRegion)
- {
- if (!screenID)
- return;
-
- HBRUSH oldBrush;
-
- HDC hDC = GetDC(screenID);
- int oldROP2 = SetROP2(hDC, (xor == TRUE) ? R2_XORPEN : R2_COPYPEN);
-
- // Set up the coordinates.
- DWORD topLeft = GetDCOrg(hDC);
- LPPOINT tPolygon = new POINT[numPoints];
- for (int i = 0; i < numPoints; i++)
- {
- tPolygon[i].x = polygonPoints[i*2] - LOWORD(topLeft);
- tPolygon[i].y = polygonPoints[i*2+1] - HIWORD(topLeft);
- }
-
- HANDLE oldPen = SelectObject(hDC, CreatePen(PS_SOLID, 1, MapColor(palette, TRUE)));
-
- if (fill)
- {
- // Draw an filled polygon.
- if (palette->hatchStyle == HS_NONE)
- oldBrush = SelectObject(hDC, CreateSolidBrush(MapColor(palette, FALSE)));
- else
- oldBrush = SelectObject(hDC, CreateHatchBrush(palette->hatchStyle, MapColor(palette, FALSE)));
- ::Polygon(hDC, tPolygon, numPoints);
- DeleteObject(SelectObject(hDC, oldBrush));
- }
- else
- // Draw a line polygon.
- Polyline(hDC, tPolygon, numPoints);
-
- delete tPolygon;
-
- SetROP2(hDC, oldROP2);
- DeleteObject(SelectObject(hDC, oldPen));
- ReleaseDC(screenID, hDC);
- }
-
- #pragma argsused
- void UI_MSWINDOWS_DISPLAY::Rectangle(SCREENID screenID, int left, int top, int right,
- int bottom, const UI_PALETTE *palette, int width, int fill, int xor,
- const UI_REGION *clipRegion)
- {
- if (!screenID)
- return;
-
- HBRUSH oldBrush;
-
- HDC hDC = GetDC(screenID);
- int oldROP2 = SetROP2(hDC, (xor == TRUE) ? R2_XORPEN : R2_COPYPEN);
-
- // Set up the coordinates.
- DWORD topLeft = GetDCOrg(hDC);
- left -= LOWORD(topLeft);
- top -= HIWORD(topLeft);
- right -= LOWORD(topLeft);
- bottom -= HIWORD(topLeft);
-
- HANDLE oldPen = SelectObject(hDC, CreatePen(PS_SOLID, width, MapColor(palette, (width == 0) ? FALSE : TRUE)));
-
- if (fill)
- {
- // Increase bottom and right by one (Rectangle does not include bottom
- // and right lines).
- right++;
- bottom++;
-
- // Draw an filled rectangle.
- if (palette->hatchStyle == HS_NONE)
- oldBrush = SelectObject(hDC, CreateSolidBrush(MapColor(palette, FALSE)));
- else
- oldBrush = SelectObject(hDC, CreateHatchBrush(palette->hatchStyle, MapColor(palette, FALSE)));
- ::Rectangle(hDC, left, top, right, bottom);
- DeleteObject(SelectObject(hDC, oldBrush));
- }
- else
- {
- // Draw a line rectangle.
- MoveTo(hDC, left, top);
- LineTo(hDC, right, top);
- LineTo(hDC, right, bottom);
- LineTo(hDC, left, bottom);
- LineTo(hDC, left, top);
- }
-
- SetROP2(hDC, oldROP2);
- DeleteObject(SelectObject(hDC, oldPen));
- ReleaseDC(screenID, hDC);
- }
-
- #pragma argsused
- void UI_MSWINDOWS_DISPLAY::RectangleXORDiff(const UI_REGION &oldRegion,
- const UI_REGION &newRegion)
- {
- // Stub for MS Windows.
- }
-
- #pragma argsused
- void UI_MSWINDOWS_DISPLAY::RegionConvert(UI_REGION ®ion, USHORT *oldFlags, USHORT newFlags)
- {
- if (FlagSet(*oldFlags, newFlags))
- return;
-
- // These variables handle Text<-->Graphics coordinate problems.
- *oldFlags |= newFlags;
-
- region.left *= cellWidth;
- region.top *= cellHeight;
- region.right = (region.right + 1) * cellWidth - 1;
- region.bottom = (region.bottom + 1) * cellHeight - 1;
- }
-
- #pragma argsused
- void UI_MSWINDOWS_DISPLAY::RegionMove(const UI_REGION &oldRegion, int newColumn, int newLine,
- SCREENID oldScreenID, SCREENID newScreenID)
- {
- // Stub ?
- }
-
- #pragma argsused
- void UI_MSWINDOWS_DISPLAY::Text(SCREENID screenID, int left, int top,
- const char *text, const UI_PALETTE *palette, int length,
- int fill, int xor, const UI_REGION *clipRegion)
- {
- if (!screenID)
- return;
-
- // Set up the coordinates.
- HDC hDC = GetDC(screenID);
- int oldROP2 = SetROP2(hDC, (xor == TRUE) ? R2_XORPEN : R2_COPYPEN);
-
- DWORD topLeft = GetDCOrg(hDC);
- left -= LOWORD(topLeft);
- top -= HIWORD(topLeft);
-
- // Set up the text colors.
- SetTextColor(hDC, MapColor(palette, TRUE));
- SetBkColor(hDC, MapColor(palette, FALSE));
-
- // Draw the text.
- if (length == -1)
- length = lstrlen((LPSTR)text);
- TextOut(hDC, left, top, (LPSTR)text, length);
-
- SetROP2(hDC, oldROP2);
- ReleaseDC(screenID, hDC);
- }
-
- int UI_MSWINDOWS_DISPLAY::TextHeight(const char *string, SCREENID screenID)
- {
- if (!screenID)
- return (-1);
-
- HDC hDC = GetDC(screenID);
-
- // Get the height of the string.
- DWORD textExtent = GetTextExtent(hDC, (LPSTR)string, ui_strlen(string));
- ReleaseDC(screenID, hDC);
-
- return (HIWORD(textExtent));
- }
-
- int UI_MSWINDOWS_DISPLAY::TextWidth(const char *string, SCREENID screenID)
- {
- if (!screenID)
- return (-1);
-
- HDC hDC = GetDC(screenID);
-
- // Get the width of the string.
- DWORD textExtent = GetTextExtent(hDC, (LPSTR)string, ui_strlen(string));
- ReleaseDC(screenID, hDC);
-
- return (LOWORD(textExtent));
- }
-