File: xwin.c

package info (click to toggle)
xpuzzles 7.6.3-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 14,208 kB
  • sloc: ansic: 94,274; makefile: 7,477; sh: 3,221
file content (106 lines) | stat: -rw-r--r-- 2,950 bytes parent folder | download | duplicates (86)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/*
 * @(#)xwin.c
 *
 * Copyright 2005  David A. Bagley, bagleyd@tux.org
 *
 * All rights reserved.
 *
 * Permission to use, copy, modify, and distribute this software and
 * its documentation for any purpose and without fee is hereby granted,
 * provided that the above copyright notice appear in all copies and
 * that both that copyright notice and this permission notice appear in
 * supporting documentation, and that the name of the author not be
 * used in advertising or publicity pertaining to distribution of the
 * software without specific, written prior permission.
 *
 * This program is distributed in the hope that it will be "useful",
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 */

/* Methods file for xwin */

#include "xwin.h"

#ifdef WINVER
void
FILLPOLYGON(HDC hDC, HPEN *hPen, HPEN *hOldPen,
		HBRUSH *hBrush, HBRUSH *hOldBrush,
		GC color, GC lineColor, const POINT *poly, int n,
		Boolean origin)
{
	/* CoordModePrevious -> CoordModeOrigin */
	POINT *temp = NULL;
	int pt;

	if (!origin) {
		if (!(temp = (POINT *) malloc(sizeof (POINT) * n))) {
			DISPLAY_ERROR("Not enough memory (POLYGON), exiting.");
		}
		temp[0] = poly[0];
		for (pt = 1; pt < n; pt++) {
			temp[pt].x = temp[pt - 1].x + poly[pt].x,
			temp[pt].y = temp[pt - 1].y + poly[pt].y;
		}
	}
	*hPen = CreatePen(PS_SOLID, 1, lineColor);
	*hOldPen = (HPEN) SelectObject(hDC, *hPen);
	*hBrush = CreateSolidBrush(color);
	*hOldBrush = (HBRUSH) SelectObject(hDC, *hBrush);
	(void) Polygon(hDC, (origin) ? poly : temp, n);
	(void) SelectObject(hDC, *hOldBrush);
	(void) DeleteObject(*hBrush);
	(void) SelectObject(hDC, *hOldPen);
	(void) DeleteObject(*hPen);
	if (!origin) {
		free(temp);
	}
}

void
DRAWPOLYLINE(HDC hDC, HPEN *hPen, HPEN *hOldPen,
		GC color, const POINT *poly, int n,
		Boolean origin)
{
	/* CoordModePrevious -> CoordModeOrigin */
	POINT *temp = NULL;
	int pt;

	if (!origin) {
		if (!(temp = (POINT *) malloc(sizeof (POINT) * n))) {
			DISPLAY_ERROR("Not enough memory (POLYLINE), exiting.");
		}
		temp[0] = poly[0];
		for (pt = 1; pt < n; pt++) {
			temp[pt].x = temp[pt - 1].x + poly[pt].x,
			temp[pt].y = temp[pt - 1].y + poly[pt].y;
		}
	}
	*hPen = CreatePen(PS_SOLID, 1, color);
	*hOldPen = (HPEN) SelectObject(hDC, *hPen);
	(void) Polyline(hDC, (origin) ? poly : temp, n);
	(void) SelectObject(hDC, *hOldPen);
	(void) DeleteObject(*hPen);
	if (!origin) {
		free(temp);
	}
}
#endif

void
intCat(char **string, const char *var1, const int var2)
{
	if (!(*string = (char *) malloc(strlen(var1) + 21))) {
		DISPLAY_ERROR("Not enough memory (intCat), exiting.");
	}
	(void) sprintf(*string, "%s%d", var1, var2);
}

void
stringCat(char **string, const char *var1, const char *var2)
{
	if (!(*string = (char *) malloc(strlen(var1) + strlen(var2) + 1))) {
		DISPLAY_ERROR("Not enough memory (stringCat), exiting.");
	}
	(void) sprintf(*string, "%s%s", var1, var2);
}