📄 i_ugldsp.cpp
字号:
else if (vtJustify == ZAF_VT_CENTER) { topText += (pixelBottom - pixelTop - pixelHeight + 1) / 2; if (topText < pixelTop) topText = pixelTop; } // Save the user's clip region so can restore it when done drawing. ZafRegionStruct clip, saveClip = ClipRegion(); uglLineWidthSet(gc, 0); // Draw the text. UGL_COLOR saveColor; if (fill) uglRectangle(gc, pixelLeft, pixelTop, pixelRight, pixelBottom); else { uglBackgroundColorGet(gc, &saveColor); uglBackgroundColorSet(gc, UGL_COLOR_TRANSPARENT); }#if !defined(ZAF_UNICODE) uglTextDraw(gc, leftText, topText, -1, fillLine);#else int i; for (i = 0; fillLine[i]; i++) fillLineW[i] = fillLine[i]; fillLineW[i] = 0; uglTextDrawW(gc, leftText, topText, -1, (const UGL_WCHAR *)fillLineW);#endif // Restore saved color. if (!fill) uglBackgroundColorSet(gc, saveColor); if (hotKeyIndex >= 0) { uglLineWidthSet(gc, 1); uglLine(gc, hotKeyLeft, topText + pixelHeight, hotKeyRight, topText + pixelHeight); }#if defined(ZAF_RTOS) ZafScreenDisplay::classSem->Give();#endif return (ZAF_ERROR_NONE);}ZafRegionStruct ZafScreenDisplay::TextSize(const ZafIChar *string, int length){ ZafRegionStruct size; size.Assign(1, 1, 0, 0, ZAF_PIXEL); if (!string || !string[0]) return (size);#if defined(ZAF_RTOS) ZafScreenDisplay::classSem->Take(ZAF_WAIT_FOREVER_SEMAPHORE);#endif ZafIChar *tString = (ZafIChar *)string; if (length > 0) { tString = new ZafIChar[length + 1]; strncpy(tString, string, length); tString[length] = 0; }#if !defined(ZAF_UNICODE) uglTextSizeGet(fontTable[palette.font], &size.right, &size.bottom, -1, tString);#else int len = strlen(tString); UGL_WCHAR *tStringW = new UGL_WCHAR[len+1]; UGL_WCHAR *tmp = tStringW; *tmp = 0; while (*tString) { *tmp = *tString; tmp++; tString++; } tStringW[len] = 0; uglTextSizeGetW(fontTable[palette.font], &size.right, &size.bottom, -1, tStringW);// size.right = uglTextWidthW(gc, (const UGL_WCHAR *)tStringW);// size.bottom = uglTextHeightW(gc, (const UGL_WCHAR *)tStringW); delete [] tStringW;#endif if (length > 0) delete [] tString; // left and top stay 1 so that right and bottom contain the width & height. size.right = (int)(ConvertXValue(size.right, ZAF_PIXEL, coordinateType)); size.bottom = (int)(ConvertYValue(size.bottom, ZAF_PIXEL, coordinateType)); size.coordinateType = coordinateType;#if defined(ZAF_RTOS) ZafScreenDisplay::classSem->Give();#endif return (size);}// --- Primitives -----------------------------------------------------------ZafError ZafScreenDisplay::BitmapBlt(const ZafBitmapStruct *source, ZafCoordinate sourceLeft, ZafCoordinate sourceTop, ZafCoordinate sourceRight, ZafCoordinate sourceBottom, ZafBitmapStruct *dest, ZafCoordinate destLeft, ZafCoordinate destTop){ UGL_DDB_ID srcDDB, dstDDB; if (!source) srcDDB = UGL_DEFAULT_ID; else srcDDB = source->handle; if (!dest) dstDDB = UGL_DEFAULT_ID; else dstDDB = dest->handle;#if defined(ZAF_RTOS) ZafScreenDisplay::classSem->Take(ZAF_WAIT_FOREVER_SEMAPHORE);#endif int pixelSrcLeft, pixelSrcTop, pixelDestLeft, pixelDestTop; int width = sourceRight - sourceLeft + 1; int height = sourceBottom - sourceTop + 1; int scaledWidth = (int)((long)width * scaleNumerator / scaleDenominator); int scaledHeight = (int)((long)height * scaleNumerator / scaleDenominator); if (coordinateType == ZAF_PIXEL) { pixelSrcLeft = (int)(sourceLeft * scaleNumerator / scaleDenominator + originX); pixelSrcTop = (int)(sourceTop * scaleNumerator / scaleDenominator + originY); pixelDestLeft = (int)(destLeft * scaleNumerator / scaleDenominator + originX); pixelDestTop = (int)(destTop * scaleNumerator / scaleDenominator + originY); } else { pixelSrcLeft = (int)(ConvertXValue(sourceLeft, coordinateType, ZAF_PIXEL) * scaleNumerator / scaleDenominator + originX); pixelSrcTop = (int)(ConvertYValue(sourceTop, coordinateType, ZAF_PIXEL) * scaleNumerator / scaleDenominator + originY); pixelDestLeft = (int)(ConvertXValue(destLeft, coordinateType, ZAF_PIXEL) * scaleNumerator / scaleDenominator + originX); pixelDestTop = (int)(ConvertYValue(destTop, coordinateType, ZAF_PIXEL) * scaleNumerator / scaleDenominator + originY); } if (Scale() == 100) uglBitmapBlt(gc, srcDDB, pixelSrcLeft, pixelSrcTop, pixelSrcLeft + width, pixelSrcTop + height, dstDDB, pixelDestLeft, pixelDestTop); else uglBitmapStretchBlt(gc, srcDDB, pixelSrcLeft, pixelSrcTop, pixelSrcLeft + width, pixelSrcTop + height, dstDDB, pixelDestLeft, pixelDestTop, pixelDestLeft + scaledWidth, pixelDestTop + scaledHeight);#if defined(ZAF_RTOS) ZafScreenDisplay::classSem->Give();#endif return (ZAF_ERROR_NONE);}ZafError ZafScreenDisplay::Ellipse(ZafCoordinate left, ZafCoordinate top, ZafCoordinate right, ZafCoordinate bottom, float startAngle, float endAngle, int width, bool fill){#if defined(ZAF_RTOS) ZafAutoSemaphore autoSem(ZafScreenDisplay::classSem);#endif int pixelLeft; int pixelTop; int pixelRight; int pixelBottom; int pixelWidth; if (coordinateType == ZAF_PIXEL) { pixelLeft = int(left * scaleNumerator / scaleDenominator + originX); pixelTop = int(top * scaleNumerator / scaleDenominator + originY); pixelRight = int(right * scaleNumerator / scaleDenominator + originX); pixelBottom = int(bottom * scaleNumerator / scaleDenominator + originY); pixelWidth = (width > 0) ? ZafMax(int(width * scaleNumerator / scaleDenominator), 1) : (width == ZAF_HAIR_LINE ? 1 : 0); } else { pixelLeft = (int)(ConvertXValue(left, coordinateType, ZAF_PIXEL) * scaleNumerator / scaleDenominator + originX); pixelTop = (int)(ConvertYValue(top, coordinateType, ZAF_PIXEL) * scaleNumerator / scaleDenominator + originY); pixelRight = (int)(ConvertXValue(right, coordinateType, ZAF_PIXEL) * scaleNumerator / scaleDenominator + originX); pixelBottom = (int)(ConvertYValue(bottom, coordinateType, ZAF_PIXEL) * scaleNumerator / scaleDenominator + originY); pixelWidth = (width > 0) ? ZafMax((int)(ConvertXValue(width, coordinateType, ZAF_PIXEL) * scaleNumerator / scaleDenominator), 1) : (width == ZAF_HAIR_LINE ? 1 : 0); } if (pixelRight < pixelLeft || pixelBottom < pixelTop) return (ZAF_ERROR_VALUE_MISSING); float angleSize = endAngle - startAngle; UGL_COLOR saveColor; if (!fill) { uglBackgroundColorGet(gc, &saveColor); uglBackgroundColorSet(gc, UGL_COLOR_TRANSPARENT); } ZafRegionStruct clip, saveClip = ClipRegion(); // Draw the ellipse on the display. uglLineWidthSet(gc, pixelWidth); if (angleSize == 0.0 || angleSize == 360.0) uglEllipse(gc, pixelLeft, pixelTop, pixelRight, pixelBottom, 0, 0, 0, 0); else { ZafCoordinate a = (pixelRight - pixelLeft + 1) / 2; ZafCoordinate b = (pixelBottom - pixelTop + 1) / 2; // Convert angles to radians; const double pi = 3.1415926535897932384626433832795; double rStartAngle = startAngle * 2 * pi / 360.0; double rEndAngle = endAngle * 2 * pi / 360.0; double r = 1000; // Make sure r is sufficiently large. ZafCoordinate startX = pixelLeft + a + (int)(r * cos(rStartAngle)); ZafCoordinate startY = pixelTop + b - (int)(r *sin(rStartAngle)); ZafCoordinate endX = pixelLeft + a + (int)(r * cos(rEndAngle)); ZafCoordinate endY = pixelTop + b - (int)(r * sin(rEndAngle)); uglEllipse(gc, pixelLeft, pixelTop, pixelRight, pixelBottom, (UGL_POS)startX, (UGL_POS)startY, (UGL_POS)endX, (UGL_POS)endY); } if (!fill) uglBackgroundColorSet(gc, saveColor); return (ZAF_ERROR_NONE);}ZafError ZafScreenDisplay::Line(ZafCoordinate x1, ZafCoordinate y1, ZafCoordinate x2, ZafCoordinate y2, int width){#if defined(ZAF_RTOS) ZafScreenDisplay::classSem->Take(ZAF_WAIT_FOREVER_SEMAPHORE);#endif int pixelX1; int pixelY1; int pixelX2; int pixelY2; int pixelWidth; if (coordinateType == ZAF_PIXEL) { pixelX1 = int(x1 * scaleNumerator / scaleDenominator + originX); pixelY1 = int(y1 * scaleNumerator / scaleDenominator + originY); pixelX2 = int(x2 * scaleNumerator / scaleDenominator + originX); pixelY2 = int(y2 * scaleNumerator / scaleDenominator + originY); pixelWidth = (width > 0) ? ZafMax(int(width * scaleNumerator / scaleDenominator), 1) : (width == ZAF_HAIR_LINE ? 1 : 0); } else { pixelX1 = (int)(ConvertXValue(x1, coordinateType, ZAF_PIXEL) * scaleNumerator / scaleDenominator + originX); pixelY1 = (int)(ConvertYValue(y1, coordinateType, ZAF_PIXEL) * scaleNumerator / scaleDenominator + originY); pixelX2 = (int)(ConvertXValue(x2, coordinateType, ZAF_PIXEL) * scaleNumerator / scaleDenominator + originX); pixelY2 = (int)(ConvertYValue(y2, coordinateType, ZAF_PIXEL) * scaleNumerator / scaleDenominator + originY); pixelWidth = (width > 0) ? ZafMax((int)(ConvertXValue(width, coordinateType, ZAF_PIXEL) * scaleNumerator / scaleDenominator), 1) : (width == ZAF_HAIR_LINE ? 1 : 0); } // Save the user's clip region so can restore it when done drawing. ZafRegionStruct clip, saveClip = ClipRegion(); // Draw the line on the display. uglLineWidthSet(gc, pixelWidth); uglLine(gc, pixelX1, pixelY1, pixelX2, pixelY2);#if defined(ZAF_RTOS) ZafScreenDisplay::classSem->Give();#endif return (ZAF_ERROR_NONE);}ZafError ZafScreenDisplay::Pixel(ZafCoordinate column, ZafCoordinate line, ZafLogicalColor color, ZafLogicalColor){#if defined(ZAF_RTOS) ZafScreenDisplay::classSem->Take(ZAF_WAIT_FOREVER_SEMAPHORE);#endif int pixelColumn; int pixelLine; if (coordinateType == ZAF_PIXEL) { pixelColumn = int(column * scaleNumerator / scaleDenominator + originX); pixelLine = int(line * scaleNumerator / scaleDenominator + originY); } else { pixelColumn = (int)(ConvertXValue(column, coordinateType, ZAF_PIXEL) * scaleNumerator / scaleDenominator + originX); pixelLine = (int)(ConvertYValue(line, coordinateType, ZAF_PIXEL) * scaleNumerator / scaleDenominator + originY); } // Save the user's clip region so can restore it when done drawing. ZafRegionStruct clip, saveClip = ClipRegion(); // Draw the pixel on the display. uglPixelSet(gc, pixelColumn, pixelLine, colorTable[color]);#if defined(ZAF_RTOS) ZafScreenDisplay::classSem->Give();#endif return (ZAF_ERROR_NONE);}ZafError ZafScreenDisplay::Polygon(int numPoints, const ZafCoordinate *polygonPoints, int width, bool fill, bool close){#if defined(ZAF_RTOS) ZafScreenDisplay::classSem->Take(ZAF_WAIT_FOREVER_SEMAPHORE);#endif int pixelWidth = (width > 0) ? ZafMax((int)(ConvertXValue(width, coordinateType, ZAF_PIXEL) * scaleNumerator / scaleDenominator), 1) : (width == ZAF_HAIR_LINE ? 1 : 0); if (fill && !close && (polygonPoints[2 * numPoints - 2] != polygonPoints[0] || polygonPoints[2 * numPoints - 1] != polygonPoints[1])) close = true; int realNumPoints = numPoints; if (close) ++realNumPoints; // Create a list of UGL points. bool allocatedPoints = false; int *realPoints; if (!close && coordinateType == ZAF_PIXEL && sizeof(ZafCoordinate) == sizeof(int)) realPoints = (int *)polygonPoints; else { allocatedPoints = true; realPoints = new int[realNumPoints * 2]; for (int p = 0; p < numPoints; ++p) { realPoints[2 * p] = (int)(ConvertXValue(polygonPoints[2 * p], coordinateType, ZAF_PIXEL) * scaleNumerator / scaleDenominator + originX); realPoints[2 * p + 1] = (int)(ConvertYValue(polygonPoints[2 * p + 1], coordinateType, ZAF_PIXEL) * scaleNumerator / scaleDenominator + originY); } } if (close) { realPoints[2 * numPoints] = realPoints[0]; realPoints[2 * numPoints + 1] = realPoints[1]; } UGL_COLOR saveColor; if (!fill) { uglBackgroundColorGet(gc, &saveColor); uglBackgroundColorSet(gc, UGL_COLOR_TRANSPARENT); } // Save the user's clip region so can restore it when done drawing. ZafRegionStruct clip, saveClip = ClipRegion(); // Draw the polygon on the display. uglLineWidthSet(gc, pixelWidth); uglPolygon(gc, realNumPoints, realPoints); if (!fill) uglBackgroundColorSet(gc, saveColor); if (allocatedPoints) delete []realPoints;#if defined(ZAF_RTOS) ZafScreenDisplay::classSem->Give();#endif return (ZAF_ERROR_NONE);}ZafError ZafScreenDisplay::Rectangle(ZafCoordinate left, ZafCoordinate top, ZafCoordinate right, ZafCoordinate bottom, int width, bool fill){#if defined(ZAF_RTOS) ZafScreenDisplay::classSem->Take(ZAF_WAIT_FOREVER_SEMAPHORE);#endif int pixelLeft, pixelTop, pixelRight, pixelBottom, pixelWidth; if (coordinateType == ZAF_PIXEL) { pixelLeft = int(left * scaleNumerator / scaleDenominator + originX); pixelTop = int(top * scaleNumerator / scaleDenominator + originY); pixelRight = int(right * scaleNumerator / scaleDenominator + originX); pixelBottom = int(bottom * scaleNumerator / scaleDenominator + originY); pixelWidth = (width > 0) ? ZafMax(int(width * scaleNumerator / scaleDenominator), 1) : (width == ZAF_HAIR_LINE ? 1 : 0); } else { pixelLeft = (int)(ConvertXValue(left, coordinateType, ZAF_PIXEL) * scaleNumerator / scaleDenominator + originX); pixelTop = (int)(ConvertYValue(top, coordinateType, ZAF_PIXEL) * scaleNumerator / scaleDenominator + originY); pixelRight = (int)(ConvertXValue(right, coordinateType, ZAF_PIXEL) * scaleNumerator / scaleDenominator + originX); pixelBottom = (int)(ConvertYValue(bottom, coordinateType, ZAF_PIXEL) * scaleNumerator / scaleDenominator + originY); pixelWidth = (width > 0) ? ZafMax((int)(ConvertXValue(width, coordinateType, ZAF_PIXEL) * scaleNumerator / scaleDenominator), 1) : (width == ZAF_HAIR_LINE ? 1 : 0); } UGL_COLOR saveColor; if (!fill) { uglBackgroundColorGet(gc, &saveColor); uglBackgroundColorSet(gc, UGL_COLOR_TRANSPARENT); } // Save the user's clip region so can restore it when done drawing. ZafRegionStruct clip, saveClip = ClipRegion(); // Draw the rectangle on the display. uglLineWidthSet(gc, pixelWidth); uglRectangle(gc, pixelLeft, pixelTop, pixelRight, pixelBottom); if (!fill) uglBackgroundColorSet(gc, saveColor);#if defined(ZAF_RTOS) ZafScreenDisplay::classSem->Give();#endif return (ZAF_ERROR_NONE);}ZafError ZafScreenDisplay::RectangleXORDiff(const ZafRegionStruct *oldRegion, const ZafRegionStruct *newRegion){#if defined(ZAF_RTOS) ZafScreenDisplay::classSem->Take(ZAF_WAIT_FOREVER_SEMAPHORE);#endif // See if the regions match. if (oldRegion && newRegion && oldRegion->left == newRegion->left && oldRegion->top == newRegion->top && oldRegion->right == newRegion->right && oldRegion->bottom == newRegion->bottom)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -