summaryrefslogtreecommitdiffstats
path: root/win/tkWinDraw.c
diff options
context:
space:
mode:
Diffstat (limited to 'win/tkWinDraw.c')
-rw-r--r--win/tkWinDraw.c161
1 files changed, 122 insertions, 39 deletions
diff --git a/win/tkWinDraw.c b/win/tkWinDraw.c
index 1897bc8..1d17cc6 100644
--- a/win/tkWinDraw.c
+++ b/win/tkWinDraw.c
@@ -17,14 +17,13 @@
* These macros convert between X's bizarre angle units to radians.
*/
-#define PI 3.14159265358979
#define XAngleToRadians(a) ((double)(a) / 64 * PI / 180);
/*
* Translation table between X gc functions and Win32 raster op modes.
*/
-CONST int tkpWinRopModes[] = {
+const int tkpWinRopModes[] = {
R2_BLACK, /* GXclear */
R2_MASKPEN, /* GXand */
R2_MASKPENNOT, /* GXandReverse */
@@ -55,7 +54,7 @@ CONST int tkpWinRopModes[] = {
#define SRCORREVERSE (DWORD)0x00DD0228 /* dest = source OR (NOT dest) */
#define SRCNAND (DWORD)0x007700E6 /* dest = NOT (source AND dest) */
-CONST int tkpWinBltModes[] = {
+const int tkpWinBltModes[] = {
BLACKNESS, /* GXclear */
SRCAND, /* GXand */
SRCERASE, /* GXandReverse */
@@ -102,7 +101,7 @@ CONST int tkpWinBltModes[] = {
* The followng typedef is used to pass Windows GDI drawing functions.
*/
-typedef BOOL (CALLBACK *WinDrawFunc)(HDC dc, CONST POINT* points, int npoints);
+typedef BOOL (CALLBACK *WinDrawFunc)(HDC dc, const POINT *points, int npoints);
typedef struct ThreadSpecificData {
POINT *winPoints; /* Array of points that is reused. */
@@ -243,9 +242,9 @@ ConvertPoints(
if (npoints > tsdPtr->nWinPoints) {
if (tsdPtr->winPoints != NULL) {
- ckfree((char *) tsdPtr->winPoints);
+ ckfree(tsdPtr->winPoints);
}
- tsdPtr->winPoints = (POINT *) ckalloc(sizeof(POINT) * npoints);
+ tsdPtr->winPoints = ckalloc(sizeof(POINT) * npoints);
if (tsdPtr->winPoints == NULL) {
tsdPtr->nWinPoints = -1;
return NULL;
@@ -487,7 +486,7 @@ XCopyPlane(
/*
*----------------------------------------------------------------------
*
- * TkPutImage --
+ * TkPutImage, XPutImage --
*
* Copies a subimage from an in-memory image to a rectangle of of the
* specified drawable.
@@ -554,10 +553,10 @@ TkPutImage(
usePalette = (image->bits_per_pixel < 16);
if (usePalette) {
- infoPtr = (BITMAPINFO *) ckalloc(sizeof(BITMAPINFOHEADER)
+ infoPtr = ckalloc(sizeof(BITMAPINFOHEADER)
+ sizeof(RGBQUAD)*ncolors);
} else {
- infoPtr = (BITMAPINFO *) ckalloc(sizeof(BITMAPINFOHEADER));
+ infoPtr = ckalloc(sizeof(BITMAPINFOHEADER));
}
infoPtr->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
@@ -584,10 +583,10 @@ TkPutImage(
}
bitmap = CreateDIBitmap(dc, &infoPtr->bmiHeader, CBM_INIT,
image->data, infoPtr, DIB_RGB_COLORS);
- ckfree((char *) infoPtr);
+ ckfree(infoPtr);
}
if (!bitmap) {
- Tcl_Panic("Fail to allocate bitmap\n");
+ Tcl_Panic("Fail to allocate bitmap");
DeleteDC(dcMem);
TkWinReleaseDrawableDC(d, dc, &state);
return BadValue;
@@ -600,6 +599,21 @@ TkPutImage(
TkWinReleaseDrawableDC(d, dc, &state);
return Success;
}
+
+int
+XPutImage(
+ Display *display,
+ Drawable d, /* Destination drawable. */
+ GC gc,
+ XImage *image, /* Source image. */
+ int src_x, int src_y, /* Offset of subimage. */
+ int dest_x, int dest_y, /* Position of subimage origin in drawable. */
+ unsigned int width, unsigned int height)
+ /* Dimensions of subimage. */
+{
+ return TkPutImage(NULL, 0, display, d, gc, image,
+ src_x, src_y, dest_x, dest_y, width, height);
+}
/*
*----------------------------------------------------------------------
@@ -626,7 +640,6 @@ XFillRectangles(
int nrectangles)
{
HDC dc;
- int i;
RECT rect;
TkWinDCState state;
HBRUSH brush, oldBrush;
@@ -667,25 +680,26 @@ XFillRectangles(
* result with the stipple pattern.
*/
- for (i = 0; i < nrectangles; i++) {
- bitmap = CreateCompatibleBitmap(dc, rectangles[i].width,
- rectangles[i].height);
+ while (nrectangles-- > 0) {
+ bitmap = CreateCompatibleBitmap(dc, rectangles[0].width,
+ rectangles[0].height);
oldBitmap = SelectObject(dcMem, bitmap);
rect.left = 0;
rect.top = 0;
- rect.right = rectangles[i].width;
- rect.bottom = rectangles[i].height;
+ rect.right = rectangles[0].width;
+ rect.bottom = rectangles[0].height;
FillRect(dcMem, &rect, brush);
- BitBlt(dc, rectangles[i].x, rectangles[i].y, rectangles[i].width,
- rectangles[i].height, dcMem, 0, 0, COPYFG);
+ BitBlt(dc, rectangles[0].x, rectangles[0].y, rectangles[0].width,
+ rectangles[0].height, dcMem, 0, 0, COPYFG);
if (gc->fill_style == FillOpaqueStippled) {
FillRect(dcMem, &rect, bgBrush);
- BitBlt(dc, rectangles[i].x, rectangles[i].y,
- rectangles[i].width, rectangles[i].height, dcMem,
+ BitBlt(dc, rectangles[0].x, rectangles[0].y,
+ rectangles[0].width, rectangles[0].height, dcMem,
0, 0, COPYBG);
}
SelectObject(dcMem, oldBitmap);
DeleteObject(bitmap);
+ ++rectangles;
}
DeleteDC(dcMem);
@@ -694,22 +708,24 @@ XFillRectangles(
DeleteObject(bgBrush);
} else {
if (gc->function == GXcopy) {
- for (i = 0; i < nrectangles; i++) {
- rect.left = rectangles[i].x;
- rect.right = rect.left + rectangles[i].width;
- rect.top = rectangles[i].y;
- rect.bottom = rect.top + rectangles[i].height;
+ while (nrectangles-- > 0) {
+ rect.left = rectangles[0].x;
+ rect.right = rect.left + rectangles[0].width;
+ rect.top = rectangles[0].y;
+ rect.bottom = rect.top + rectangles[0].height;
FillRect(dc, &rect, brush);
+ ++rectangles;
}
} else {
HPEN newPen = CreatePen(PS_NULL, 0, gc->foreground);
HPEN oldPen = SelectObject(dc, newPen);
oldBrush = SelectObject(dc, brush);
- for (i = 0; i < nrectangles; i++) {
- Rectangle(dc, rectangles[i].x, rectangles[i].y,
- rectangles[i].x + rectangles[i].width + 1,
- rectangles[i].y + rectangles[i].height + 1);
+ while (nrectangles-- > 0) {
+ Rectangle(dc, rectangles[0].x, rectangles[0].y,
+ rectangles[0].x + rectangles[0].width + 1,
+ rectangles[0].y + rectangles[0].height + 1);
+ ++rectangles;
}
SelectObject(dc, oldBrush);
@@ -749,7 +765,7 @@ RenderObject(
HPEN pen,
WinDrawFunc func)
{
- RECT rect = {0, 0, 0, 0};
+ RECT rect = {0,0,0,0};
HPEN oldPen;
HBRUSH oldBrush;
POINT *winPoints = ConvertPoints(points, npoints, mode, &rect);
@@ -817,7 +833,7 @@ RenderObject(
SetPolyFillMode(dcMem, (gc->fill_rule == EvenOddRule) ? ALTERNATE
: WINDING);
oldMemBrush = SelectObject(dcMem, CreateSolidBrush(gc->foreground));
- (*func)(dcMem, winPoints, npoints);
+ func(dcMem, winPoints, npoints);
BitBlt(dc, rect.left, rect.top, width, height, dcMem, 0, 0, COPYFG);
/*
@@ -829,7 +845,7 @@ RenderObject(
if (gc->fill_style == FillOpaqueStippled) {
DeleteObject(SelectObject(dcMem,
CreateSolidBrush(gc->background)));
- (*func)(dcMem, winPoints, npoints);
+ func(dcMem, winPoints, npoints);
BitBlt(dc, rect.left, rect.top, width, height, dcMem, 0, 0,
COPYBG);
}
@@ -845,9 +861,7 @@ RenderObject(
SetPolyFillMode(dc, (gc->fill_rule == EvenOddRule) ? ALTERNATE
: WINDING);
-
- (*func)(dc, winPoints, npoints);
-
+ func(dc, winPoints, npoints);
SelectObject(dc, oldPen);
}
DeleteObject(SelectObject(dc, oldBrush));
@@ -943,7 +957,7 @@ XFillPolygon(
/*
*----------------------------------------------------------------------
*
- * XDrawRectangle --
+ * XDrawRectangle, XDrawRectangles --
*
* Draws a rectangle.
*
@@ -988,11 +1002,32 @@ XDrawRectangle(
TkWinReleaseDrawableDC(d, dc, &state);
return Success;
}
+
+int
+XDrawRectangles(
+ Display *display,
+ Drawable d,
+ GC gc,
+ XRectangle rects[],
+ int nrects)
+{
+ int ret = Success;
+
+ while (nrects-- > 0) {
+ ret = XDrawRectangle(display, d, gc, rects[0].x, rects[0].y,
+ rects[0].width, rects[0].height);
+ if (ret != Success) {
+ break;
+ }
+ ++rects;
+ }
+ return ret;
+}
/*
*----------------------------------------------------------------------
*
- * XDrawArc --
+ * XDrawArc, XDrawArcs --
*
* Draw an arc.
*
@@ -1018,11 +1053,35 @@ XDrawArc(
return DrawOrFillArc(display, d, gc, x, y, width, height, start, extent, 0);
}
+
+int
+XDrawArcs(
+ Display *display,
+ Drawable d,
+ GC gc,
+ XArc *arcs,
+ int narcs)
+{
+ int ret = Success;
+
+ display->request++;
+
+ while (narcs-- > 0) {
+ ret = DrawOrFillArc(display, d, gc, arcs[0].x, arcs[0].y,
+ arcs[0].width, arcs[0].height,
+ arcs[0].angle1, arcs[0].angle2, 0);
+ if (ret != Success) {
+ break;
+ }
+ ++arcs;
+ }
+ return ret;
+}
/*
*----------------------------------------------------------------------
*
- * XFillArc --
+ * XFillArc, XFillArcs --
*
* Draw a filled arc.
*
@@ -1048,6 +1107,30 @@ XFillArc(
return DrawOrFillArc(display, d, gc, x, y, width, height, start, extent, 1);
}
+
+int
+XFillArcs(
+ Display *display,
+ Drawable d,
+ GC gc,
+ XArc *arcs,
+ int narcs)
+{
+ int ret = Success;
+
+ display->request++;
+
+ while (narcs-- > 0) {
+ ret = DrawOrFillArc(display, d, gc, arcs[0].x, arcs[0].y,
+ arcs[0].width, arcs[0].height,
+ arcs[0].angle1, arcs[0].angle2, 1);
+ if (ret != Success) {
+ break;
+ }
+ ++arcs;
+ }
+ return ret;
+}
/*
*----------------------------------------------------------------------