summaryrefslogtreecommitdiff
path: root/support/dktools/WxdkdrawComp.cpp
blob: 64a2dc1c49bc5249c395a81199310a25c780c712 (plain)
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
/*
Copyright (C) 2019-2020, Dirk Krause
SPDX-License-Identifier: BSD-3-Clause
*/

/*
	WARNING: This file was generated by the dkct program (see
	http://dktools.sourceforge.net/ for details).
	Changes you make here will be lost if dkct is run again!
	You should modify the original source and run dkct on it.
	Original source: WxdkdrawComp.cpt
*/

/**	@file WxdkdrawComp.cpp The WxdkdrawComp module.
*/


#line 92 "WxdkdrawComp.cpt"

#include "wxdkdraw.h"





#line 98 "WxdkdrawComp.cpt"



int
drawobj_object_category(int8_t ot)
{
	int		 back	= WXD_OC_CONTROL;
	

#line 106 "WxdkdrawComp.cpt"
	switch (ot) {
		case WXD_OT_TEXT : {
			back = WXD_OC_TEXT ;
		} break;
		case WXD_OT_POLYLINE : case WXD_OT_O_SPLINE : case WXD_OT_O_ARC : {
			back = WXD_OC_OPEN ;
		} break;
		case WXD_OT_POLYGON : case WXD_OT_C_SPLINE : case WXD_OT_C_ARC :
		case WXD_OT_CIRCLE : case WXD_OT_ELLIPSE : case WXD_OT_BOX : {
			back = WXD_OC_CLOSED ;
		} break;
		case WXD_OT_IMAGE : {
			back = WXD_OC_IMAGE ;
		} break;
	}
	

#line 122 "WxdkdrawComp.cpt"
	return back;
}



static
int
cmp_u8(uint8_t a, uint8_t b)
{
	return ((a > b) ? (1) : ((a < b) ? (-1) : (0)));
}


#if	0
static
int
cmp_i8(int8_t a, int8_t b)
{
	return ((a > b) ? (1) : ((a < b) ? (-1) : (0)));
}
#endif


#if	0
static
int
cmp_u16(uint16_t a, uint16_t b)
{
	return ((a > b) ? (1) : ((a < b) ? (-1) : (0)));
}
#endif


static
int
cmp_i16(int16_t a, int16_t b)
{
	return ((a > b) ? (1) : ((a < b) ? (-1) : (0)));
}



#if	0
static
int
cmp_int(int a, int b)
{
	return ((a > b) ? (1) : ((a < b) ? (-1) : (0)));
}
#endif



int
drawobj_compare_object(const void *l, const void *r, int DK4_ARG_UNUSED(cr))
{
	const Wxd_object_t	*pl;		/* Left object */
	const Wxd_object_t	*pr;		/* Right object */
#if	0
	int					 cal;		/* Left object category */
	int					 car;		/* Right object category */
#endif
	int					 back = 0;	/* Comparison result */
	DK4_UNUSED_ARG(cr)
	

#line 187 "WxdkdrawComp.cpt"
	if (NULL != l) {
		if (NULL != r) {
			pl = (const Wxd_object_t *)l;
			pr = (const Wxd_object_t *)r;
			back = cmp_i16(pl->lay, pr->lay);
			/*
				2019-05-10	Modification
				Objects in the flat storage are compared by layer number
				only. Otherwise we would need to change object order on
				each style modification.
			*/
#if	0
			if (0 == back) {
			cal = drawobj_object_category(pl->ot);
			car = drawobj_object_category(pr->ot);
			back = cmp_int(cal, car);
			if (0 == back) {
			back = cmp_u16(pl->lw, pr->lw);
			if (0 == back) {
			back = cmp_u8(pl->ls, pr->ls);
			if (0 == back) {
			back = cmp_u8(pl->sl, pr->sl);
			if (0 == back) {
			back = cmp_u8(pl->js, pr->js);
			if (0 == back) {
			back = cmp_u8(pl->cs, pr->cs);
			if (0 == back) {
			back = cmp_u8(pl->fs, pr->fs);
			if (0 == back) {
			back = cmp_u8(pl->ml, pr->ml);
			if (0 == back) {
			back = cmp_u8(pl->sc[0], pr->sc[0]);
			if (0 == back) {
			back = cmp_u8(pl->sc[1], pr->sc[1]);
			if (0 == back) {
			back = cmp_u8(pl->sc[2], pr->sc[2]);
			if (0 == back) {
			back = cmp_u8(pl->fc[0], pr->fc[0]);
			if (0 == back) {
			back = cmp_u8(pl->fc[1], pr->fc[1]);
			if (0 == back) {
			back = cmp_u8(pl->fc[2], pr->fc[2]);
			if (0 == back) {
			back = cmp_i8(pl->ot, pr->ot);
			}
			}
			}
			}
			}
			}
			}
			}
			}
			}
			}
			}
			}
			}
			}
#endif
		}
		else {
			back = 1;
		}
	}
	else {
		if (NULL != r) {
			back = -1;
		}
	}
	

#line 258 "WxdkdrawComp.cpt"
	return back;
}



int
drawobj_compare_stipples(const void *l, const void *r, int DK4_ARG_UNUSED(cr))
{
	Wxd_stipple_t const	*pl;	/* Left stipple */
	Wxd_stipple_t const	*pr;	/* Right stipple */
	int		 back = 0;			/* Comparison result */
	DK4_UNUSED_ARG(cr)

	if (NULL != l) {
		if (NULL != r) {
			pl = (Wxd_stipple_t const *)l;
			pr = (Wxd_stipple_t const *)r;
			for (size_t i = 0; ((0 == back) && (i < 7)); i++) {
				back = cmp_u8(pl->cd[i], pr->cd[i]);
			}
		}
		else {
			back = 1;
		}
	}
	else {
		if (NULL != r) {
			back = -1;
		}
	}
	return back;
}



int
drawobj_compare_layers(const void *l, const void *r, int cr)
{
	const Wxd_layer_t	*pl;	/* Left layer structure */
	const Wxd_layer_t	*pr;	/* Right layer structure */
	const int16_t		*pnum;	/* Address of layer number variable */
	int		 back	= 0;		/* Comparison result */
	if (NULL != l) {
		if (NULL != r) {
			pl = (const Wxd_layer_t *)l;
			switch (cr) {
				case 1: {
					pnum = (const int16_t *)r;
					if (pl->lay > *pnum) {
						back = 1;
					}
					else {
						if (pl->lay < *pnum) {
							back = -1;
						}
					}
				} break;
				default: {
					pr = (const Wxd_layer_t *)r;
					if (pl->lay > pr->lay) {
						back = 1;
					}
					else {
						if (pl->lay < pr->lay) {
							back = -1;
						}
					}
				} break;
			}
		}
		else {
			back = 1;
		}
	}
	else {
		if (NULL != r) {
			back = -1;
		}
	}
	return back;
}





/* vim: set ai sw=4 ts=4 : */