1 /*
2 Copyright (C) 2017-2021, Dirk Krause
3 SPDX-License-Identifier: BSD-3-Clause
4 */
5
6 /*
7 WARNING: This file was generated by the dkct program (see
8 http://dktools.sourceforge.net/ for details).
9 Changes you make here will be lost if dkct is run again!
10 You should modify the original source and run dkct on it.
11 Original source: WxdkdrawFrameStipples.cpt
12 */
13
14 /** @file WxdkdrawFrameStipples.cpp The WxdkdrawFrameStipples module.
15 */
16
17
18 #include <wxdkdraw/wxdkdraw.h>
19
20 #ifndef WXDKDRAWFRAME_H_INCLUDED
21 #include <wxdkdraw/WxdkdrawFrame.h>
22 #endif
23
24
25
26
27
28
29
30 /** Calculate bitmap dimensions.
31 @param pw Address of width variable.
32 @param ph Address of height variable.
33 @param patt Pattern type.
34 @param patco Pattern coefficients.
35 */
36 static
37 void
calculate_bitmap_dimensions(int * pw,int * ph,int patt,double const * patco)38 calculate_bitmap_dimensions(
39 int *pw,
40 int *ph,
41 int patt,
42 double const *patco
43 )
44 {
45 int w = 0; /* Image width */
46 int h = 0; /* Image height */
47
48 switch (patt) {
49 case WXD_FS_30_DEGREE_LEFT :
50 case WXD_FS_30_DEGREE_RIGHT :
51 case WXD_FS_30_DEGREE_SIEVE : {
52 h = (int)ceil(patco[0]);
53 w = (int)ceil(patco[1]);
54 } break;
55 case WXD_FS_45_DEGREE_LEFT :
56 case WXD_FS_45_DEGREE_RIGHT :
57 case WXD_FS_45_DEGREE_SIEVE : {
58 w = h = (int)ceil(patco[2]);
59 } break;
60 case WXD_FS_HORIZONTAL_BRICKS :
61 case WXD_FS_VERTICAL_BRICKS : {
62 w = h = (int)ceil(patco[3]);
63 } break;
64 case WXD_FS_HORIZONTAL_LINES :
65 case WXD_FS_VERTICAL_LINES :
66 case WXD_FS_HORIZONTAL_VERTICAL_SIEVE : {
67 w = h = (int)ceil(patco[4]);
68 } break;
69 case WXD_FS_HORIZONTAL_SHINGLES_LEFT :
70 case WXD_FS_HORIZONTAL_SHINGLES_RIGHT :
71 case WXD_FS_VERTICAL_SHINGLES_1 :
72 case WXD_FS_VERTICAL_SHINGLES_2 : {
73 w = h = (int)ceil(patco[5]);
74 } break;
75 case WXD_FS_LARGE_FISH_SCALES : {
76 w = (int)ceil(patco[6]);
77 h = (int)ceil(patco[7]);
78 } break;
79 case WXD_FS_SMALL_FISH_SCALES : {
80 w = (int)ceil(patco[1]);
81 h = (int)ceil(patco[1]);
82 } break;
83 case WXD_FS_CIRCLES : {
84 w = h = (int)ceil(patco[3]);
85 } break;
86 case WXD_FS_HEXAGONS : {
87 h = (int)ceil(patco[3]);
88 w = (int)ceil(patco[8]);
89 } break;
90 case WXD_FS_OCTAGONS : {
91 w = h = (int)ceil(patco[3]);
92 } break;
93 case WXD_FS_HORIZONTAL_TIRES : {
94 w = (int)ceil(patco[1]);
95 h = (int)ceil(patco[4]);
96 } break;
97 case WXD_FS_VERTICAL_TIRES : {
98 h = (int)ceil(patco[1]);
99 w = (int)ceil(patco[4]);
100 } break;
101 }
102
103
104 if (NULL != pw) { *pw = w; }
105 if (NULL != ph) { *ph = h; }
106
107 }
108
109
110
111 /** Draw the fill pattern into the stipple bitmap.
112 @param gc Graphics context.
113 @param w Image width.
114 @param h Image height.
115 @param lw Line width to draw pattern.
116 @param coeff Fixed coefficients.
117 */
118 static
119 void
draw_pattern_30_left(wxGraphicsContext * gc,int w,int h,int lw,double const * coeff)120 draw_pattern_30_left(
121 wxGraphicsContext *gc,
122 int w,
123 int h,
124 int lw,
125 double const *coeff
126 )
127 {
128 double dh;
129 double dw;
130 double d_h;
131 double d_w;
132
133 wxGraphicsPath p1 = gc->CreatePath();
134 wxGraphicsPath p2 = gc->CreatePath();
135 wxGraphicsPath p3 = gc->CreatePath();
136 d_h = (double)h;
137 d_w = (double)w;
138 dh = (double)lw;
139 dw = coeff[0] * dh;
140 /*
141 Diagonal line
142 */
143 p1.MoveToPoint(0.0, 0.0);
144 p1.AddLineToPoint(d_w, d_h);
145 gc->StrokePath(p1);
146 /*
147 Line at top right corner
148 */
149 p2.MoveToPoint((d_w - dw), (0.0 - dh));
150 p2.AddLineToPoint((d_w + dw), dh);
151 gc->StrokePath(p2);
152 /*
153 Line at bottom left corner
154 */
155 p3.MoveToPoint((0.0 - dw), (d_h - dh));
156 p3.AddLineToPoint(dw, (d_h + dh));
157 gc->StrokePath(p3);
158
159 }
160
161
162
163 /** Draw the fill pattern into the stipple bitmap.
164 @param gc Graphics context.
165 @param w Image width.
166 @param h Image height.
167 @param lw Line width to draw pattern.
168 @param coeff Fixed coefficients.
169 */
170 static
171 void
draw_pattern_30_right(wxGraphicsContext * gc,int w,int h,int lw,double const * coeff)172 draw_pattern_30_right(
173 wxGraphicsContext *gc,
174 int w,
175 int h,
176 int lw,
177 double const *coeff
178 )
179 {
180 double dh;
181 double dw;
182 double d_h;
183 double d_w;
184
185 wxGraphicsPath p1 = gc->CreatePath();
186 wxGraphicsPath p2 = gc->CreatePath();
187 wxGraphicsPath p3 = gc->CreatePath();
188 d_h = (double)h;
189 d_w = (double)w;
190 dh = (double)lw;
191 dw = coeff[0] * dh;
192 /*
193 Diagonal line
194 */
195 p1.MoveToPoint(d_w, 0.0);
196 p1.AddLineToPoint(0.0, d_h);
197 gc->StrokePath(p1);
198 /*
199 Line at top left corner
200 */
201 p2.MoveToPoint((0.0 - dw), dh);
202 p2.AddLineToPoint(dw, (0.0 - dh));
203 gc->StrokePath(p2);
204 /*
205 Line at bottom right corner
206 */
207 p3.MoveToPoint((d_w - dw), (d_h + dh));
208 p3.AddLineToPoint((d_w + dw), (d_h - dh));
209 gc->StrokePath(p3);
210
211 }
212
213
214
215 /** Draw the fill pattern into the stipple bitmap.
216 @param gc Graphics context.
217 @param w Image width.
218 @param h Image height.
219 @param lw Line width to draw pattern.
220 */
221 static
222 void
draw_pattern_45_left(wxGraphicsContext * gc,int w,int h,int lw)223 draw_pattern_45_left(
224 wxGraphicsContext *gc,
225 int w,
226 int h,
227 int lw
228 )
229 {
230 double d_w;
231 double d_h;
232
233 wxGraphicsPath p1 = gc->CreatePath();
234 wxGraphicsPath p2 = gc->CreatePath();
235 wxGraphicsPath p3 = gc->CreatePath();
236 d_w = (double)w;
237 d_h = (double)h;
238 /*
239 Diagonal line
240 */
241 p1.MoveToPoint(0.0, 0.0);
242 p1.AddLineToPoint(d_w, d_h);
243 gc->StrokePath(p1);
244 /*
245 Line at top right corner
246 */
247 p2.MoveToPoint((double)(w - 2 * lw), (double)(0 - 2 * lw));
248 p2.AddLineToPoint((double)(w + 2 * lw), (double)(0 + 2 * lw));
249 gc->StrokePath(p2);
250 /*
251 Line at bottom left corner
252 */
253 p3.MoveToPoint((double)(0 - 2 * lw), (double)(h - 2 * lw));
254 p3.AddLineToPoint((double)(0 + 2 * lw), (double)(h + 2 * lw));
255 gc->StrokePath(p3);
256
257 }
258
259
260
261 /** Draw the fill pattern into the stipple bitmap.
262 @param gc Graphics context.
263 @param w Image width.
264 @param h Image height.
265 @param lw Line width to draw pattern.
266 */
267 static
268 void
draw_pattern_45_right(wxGraphicsContext * gc,int w,int h,int lw)269 draw_pattern_45_right(
270 wxGraphicsContext *gc,
271 int w,
272 int h,
273 int lw
274 )
275 {
276 double d_w;
277 double d_h;
278
279 wxGraphicsPath p1 = gc->CreatePath();
280 wxGraphicsPath p2 = gc->CreatePath();
281 wxGraphicsPath p3 = gc->CreatePath();
282 d_w = (double)w;
283 d_h = (double)h;
284 /*
285 Diagonal line
286 */
287 p1.MoveToPoint(d_w, 0.0);
288 p1.AddLineToPoint(0.0, d_h);
289 gc->StrokePath(p1);
290 /*
291 Line at top right corner
292 */
293 p2.MoveToPoint((double)(2 * lw), (double)(0 - 2 * lw));
294 p2.AddLineToPoint((double)(0 - 2 * lw), (double)(2 * lw));
295 gc->StrokePath(p2);
296 /*
297 Line at bottom left corner
298 */
299 p3.MoveToPoint((double)(w + 2 * lw), (double)(h - 2 * lw));
300 p3.AddLineToPoint((double)(w - 2 * lw), (double)(h + 2 * lw));
301 gc->StrokePath(p3);
302
303 }
304
305
306
307 /** Draw the fill pattern into the stipple bitmap.
308 @param gc Graphics context.
309 @param w Image width.
310 @param h Image height.
311 @param lw Line width to draw pattern.
312 */
313 static
314 void
draw_pattern_horizontal_bricks(wxGraphicsContext * gc,int w,int h,int lw)315 draw_pattern_horizontal_bricks(
316 wxGraphicsContext *gc,
317 int w,
318 int h,
319 int lw
320 )
321 {
322 double x;
323 double y;
324 double d_w;
325 double d_h;
326 double d_lw;
327
328 wxGraphicsPath p1 = gc->CreatePath();
329 wxGraphicsPath p2 = gc->CreatePath();
330 wxGraphicsPath p3 = gc->CreatePath();
331 wxGraphicsPath p4 = gc->CreatePath();
332 wxGraphicsPath p5 = gc->CreatePath();
333 d_w = (double)w;
334 d_h = (double)h;
335 d_lw = (double)lw;
336 y = d_h / 4.0;
337 x = d_w / 4.0;
338 p1.MoveToPoint((0.0 - d_lw), y);
339 p1.AddLineToPoint((d_w + d_lw), y);
340 gc->StrokePath(p1);
341 y = (3.0 * d_h) / 4.0;
342 p2.MoveToPoint((0.0 - d_lw), y);
343 p2.AddLineToPoint((d_w + d_lw), y);
344 gc->StrokePath(p2);
345 p3.MoveToPoint(x, y);
346 y = d_h / 4.0;
347 p3.AddLineToPoint(x, y);
348 gc->StrokePath(p3);
349 x = (3.0 * d_w) / 4.0;
350 p4.MoveToPoint(x, y);
351 p4.AddLineToPoint(x, (0.0 - d_lw));
352 gc->StrokePath(p4);
353 y = (3.0 * d_h) / 4.0;
354 p5.MoveToPoint(x, y);
355 p5.AddLineToPoint(x, (d_h + d_lw));
356 gc->StrokePath(p5);
357
358 }
359
360
361
362 /** Draw the fill pattern into the stipple bitmap.
363 @param gc Graphics context.
364 @param w Image width.
365 @param h Image height.
366 @param lw Line width to draw pattern.
367 */
368 static
369 void
draw_pattern_vertical_bricks(wxGraphicsContext * gc,int w,int h,int lw)370 draw_pattern_vertical_bricks(
371 wxGraphicsContext *gc,
372 int w,
373 int h,
374 int lw
375 )
376 {
377 double x;
378 double y;
379 double d_w;
380 double d_h;
381 double d_lw;
382
383 wxGraphicsPath p1 = gc->CreatePath();
384 wxGraphicsPath p2 = gc->CreatePath();
385 wxGraphicsPath p3 = gc->CreatePath();
386 wxGraphicsPath p4 = gc->CreatePath();
387 wxGraphicsPath p5 = gc->CreatePath();
388 d_w = (double)w;
389 d_h = (double)h;
390 d_lw = (double)lw;
391 y = d_h / 4.0;
392 x = d_w / 4.0;
393 p1.MoveToPoint(y, (0.0 - d_lw));
394 p1.AddLineToPoint(y, (d_w + d_lw));
395 gc->StrokePath(p1);
396 y = (3.0 * d_h) / 4.0;
397 p2.MoveToPoint(y, (0.0 - d_lw));
398 p2.AddLineToPoint(y, (d_w + d_lw));
399 gc->StrokePath(p2);
400 p3.MoveToPoint(y, x);
401 y = d_h / 4.0;
402 p3.AddLineToPoint(y, x);
403 gc->StrokePath(p3);
404 x = (3.0 * d_w) / 4.0;
405 p4.MoveToPoint(y, x);
406 p4.AddLineToPoint((0.0 - d_lw), x);
407 gc->StrokePath(p4);
408 y = (3.0 * d_h) / 4.0;
409 p5.MoveToPoint(y, x);
410 p5.AddLineToPoint((d_h + d_lw), x);
411 gc->StrokePath(p5);
412
413 }
414
415
416
417 /** Draw the fill pattern into the stipple bitmap.
418 @param gc Graphics context.
419 @param w Image width.
420 @param h Image height.
421 @param lw Line width to draw pattern.
422 */
423 static
424 void
draw_pattern_horizontal_lines(wxGraphicsContext * gc,int w,int h,int lw)425 draw_pattern_horizontal_lines(
426 wxGraphicsContext *gc,
427 int w,
428 int h,
429 int lw
430 )
431 {
432 double y;
433 double d_lw;
434
435 wxGraphicsPath p1 = gc->CreatePath();
436 d_lw = (double)lw;
437 y = (double)h / 2.0;
438 p1.MoveToPoint((0.0 - d_lw), y);
439 p1.AddLineToPoint(((double)w + d_lw), y);
440 gc->StrokePath(p1);
441
442 }
443
444
445
446 /** Draw the fill pattern into the stipple bitmap.
447 @param gc Graphics context.
448 @param w Image width.
449 @param h Image height.
450 @param lw Line width to draw pattern.
451 */
452 static
453 void
draw_pattern_vertical_lines(wxGraphicsContext * gc,int w,int h,int lw)454 draw_pattern_vertical_lines(
455 wxGraphicsContext *gc,
456 int w,
457 int h,
458 int lw
459 )
460 {
461 double x;
462 double d_lw;
463
464 wxGraphicsPath p1 = gc->CreatePath();
465 d_lw = (double)lw;
466 x = (double)w / 2.0;
467 p1.MoveToPoint(x, (0.0 - d_lw));
468 p1.AddLineToPoint(x, ((double)h + d_lw));
469 gc->StrokePath(p1);
470
471 }
472
473
474
475 /** Draw the fill pattern into the stipple bitmap.
476 @param gc Graphics context.
477 @param w Image width.
478 @param h Image height.
479 @param lw Line width to draw pattern.
480 */
481 static
482 void
draw_pattern_horizontal_shingles_left(wxGraphicsContext * gc,int w,int h,int lw)483 draw_pattern_horizontal_shingles_left(
484 wxGraphicsContext *gc,
485 int w,
486 int h,
487 int lw
488 )
489 {
490 double x1;
491 double x2;
492 double x3;
493 double dx;
494 double y1;
495 double y2;
496 double y3;
497 double y4;
498 double y5;
499 double d_w;
500 double d_h;
501 double d_lw;
502
503 wxGraphicsPath p1 = gc->CreatePath();
504 wxGraphicsPath p2 = gc->CreatePath();
505 wxGraphicsPath p3 = gc->CreatePath();
506 wxGraphicsPath p4 = gc->CreatePath();
507 wxGraphicsPath p5 = gc->CreatePath();
508 wxGraphicsPath p6 = gc->CreatePath();
509 wxGraphicsPath p7 = gc->CreatePath();
510 d_w = (double)w;
511 d_h = (double)h;
512 d_lw = (double)lw;
513 y1 = 0.0 - (d_h / 6.0);
514 y2 = d_h / 6.0;
515 y3 = d_h / 2.0;
516 y4 = (5.0 * d_h) / 6.0;
517 y5 = (7.0 * d_h) / 6.0;
518 x1 = d_w / 6.0;
519 x2 = d_w / 2.0;
520 x3 = (5.0 * d_w) / 6.0;
521 dx = d_w / 12.0;
522 p1.MoveToPoint((0.0 - d_lw), y2);
523 p1.AddLineToPoint((d_w + d_lw), y2);
524 gc->StrokePath(p1);
525 p2.MoveToPoint((0.0 - d_lw), y3);
526 p2.AddLineToPoint((d_w + d_lw), y3);
527 gc->StrokePath(p2);
528 p3.MoveToPoint((0.0 - d_lw), y4);
529 p3.AddLineToPoint((d_w + d_lw), y4);
530 gc->StrokePath(p3);
531 p4.MoveToPoint((x3 + dx), y1);
532 p4.AddLineToPoint((x3 - dx), y2);
533 gc->StrokePath(p4);
534 p5.MoveToPoint((x1 + dx), y2);
535 p5.AddLineToPoint((x1 - dx), y3);
536 gc->StrokePath(p5);
537 p6.MoveToPoint((x2 + dx), y3);
538 p6.AddLineToPoint((x2 - dx), y4);
539 gc->StrokePath(p6);
540 p7.MoveToPoint((x3 + dx), y4);
541 p7.AddLineToPoint((x3 - dx), y5);
542 gc->StrokePath(p7);
543
544 }
545
546
547
548 /** Draw the fill pattern into the stipple bitmap.
549 @param gc Graphics context.
550 @param w Image width.
551 @param h Image height.
552 @param lw Line width to draw pattern.
553 */
554 static
555 void
draw_pattern_horizontal_shingles_right(wxGraphicsContext * gc,int w,int h,int lw)556 draw_pattern_horizontal_shingles_right(
557 wxGraphicsContext *gc,
558 int w,
559 int h,
560 int lw
561 )
562 {
563 double x1;
564 double x2;
565 double x3;
566 double dx;
567 double y1;
568 double y2;
569 double y3;
570 double y4;
571 double y5;
572 double d_h;
573 double d_w;
574 double d_lw;
575
576 wxGraphicsPath p1 = gc->CreatePath();
577 wxGraphicsPath p2 = gc->CreatePath();
578 wxGraphicsPath p3 = gc->CreatePath();
579 wxGraphicsPath p4 = gc->CreatePath();
580 wxGraphicsPath p5 = gc->CreatePath();
581 wxGraphicsPath p6 = gc->CreatePath();
582 wxGraphicsPath p7 = gc->CreatePath();
583 d_h = (double)h;
584 d_w = (double)w;
585 d_lw = (double)lw;
586 y1 = 0.0 - (d_h / 6.0);
587 y2 = d_h / 6.0;
588 y3 = d_h / 2.0;
589 y4 = (5.0 * d_h) / 6.0;
590 y5 = (7.0 * d_h) / 6.0;
591 x1 = d_w / 6.0;
592 x2 = d_w / 2.0;
593 x3 = (5.0 * d_w) / 6.0;
594 dx = d_w / 12.0;
595 p1.MoveToPoint((0.0 - d_lw), y2);
596 p1.AddLineToPoint((d_w + d_lw), y2);
597 gc->StrokePath(p1);
598 p2.MoveToPoint((0.0 - d_lw), y3);
599 p2.AddLineToPoint((d_w + d_lw), y3);
600 gc->StrokePath(p2);
601 p3.MoveToPoint((0.0 - d_lw), y4);
602 p3.AddLineToPoint((d_w + d_lw), y4);
603 gc->StrokePath(p3);
604 p4.MoveToPoint((x3 - dx), y1);
605 p4.AddLineToPoint(x3 + dx, y2);
606 gc->StrokePath(p4);
607 p5.MoveToPoint((x2 - dx), y2);
608 p5.AddLineToPoint((x2 + dx), y3);
609 gc->StrokePath(p5);
610 p6.MoveToPoint((x1 - dx), y3);
611 p6.AddLineToPoint((x1 + dx), y4);
612 gc->StrokePath(p6);
613 p7.MoveToPoint((x3 - dx), y4);
614 p7.AddLineToPoint((x3 + dx), y5);
615 gc->StrokePath(p7);
616
617 }
618
619
620
621 /** Draw the fill pattern into the stipple bitmap.
622 @param gc Graphics context.
623 @param w Image width.
624 @param h Image height.
625 @param lw Line width to draw pattern.
626 */
627 static
628 void
draw_pattern_vertical_shingles_1(wxGraphicsContext * gc,int w,int h,int lw)629 draw_pattern_vertical_shingles_1(
630 wxGraphicsContext *gc,
631 int w,
632 int h,
633 int lw
634 )
635 {
636 double x1;
637 double x2;
638 double x3;
639 double dx;
640 double y1;
641 double y2;
642 double y3;
643 double y4;
644 double y5;
645 double d_w;
646 double d_h;
647 double d_lw;
648
649 wxGraphicsPath p1 = gc->CreatePath();
650 wxGraphicsPath p2 = gc->CreatePath();
651 wxGraphicsPath p3 = gc->CreatePath();
652 wxGraphicsPath p4 = gc->CreatePath();
653 wxGraphicsPath p5 = gc->CreatePath();
654 wxGraphicsPath p6 = gc->CreatePath();
655 wxGraphicsPath p7 = gc->CreatePath();
656 d_w = (double)w;
657 d_h = (double)h;
658 d_lw = (double)lw;
659 y1 = 0.0 - (d_h / 6.0);
660 y2 = d_h / 6.0;
661 y3 = d_h / 2.0;
662 y4 = (5.0 * d_h) / 6.0;
663 y5 = (7.0 * d_h) / 6.0;
664 x1 = d_w / 6.0;
665 x2 = d_w / 2.0;
666 x3 = (5.0 * d_w) / 6.0;
667 dx = d_w / 12.0;
668 p1.MoveToPoint(y2, (0.0 - d_lw));
669 p1.AddLineToPoint(y2, (d_w + d_lw));
670 gc->StrokePath(p1);
671 p2.MoveToPoint(y3, (0.0 - d_lw));
672 p2.AddLineToPoint(y3, (d_w + d_lw));
673 gc->StrokePath(p2);
674 p3.MoveToPoint(y4, (0.0 - d_lw));
675 p3.AddLineToPoint(y4, (d_w + d_lw));
676 gc->StrokePath(p3);
677 p4.MoveToPoint(y1, (x3 - dx));
678 p4.AddLineToPoint(y2, (x3 + dx));
679 gc->StrokePath(p4);
680 p5.MoveToPoint(y2, (x2 - dx));
681 p5.AddLineToPoint(y3, (x2 + dx));
682 gc->StrokePath(p5);
683 p6.MoveToPoint(y3, (x1 - dx));
684 p6.AddLineToPoint(y4, (x1 + dx));
685 gc->StrokePath(p6);
686 p7.MoveToPoint(y4, (x3 - dx));
687 p7.AddLineToPoint(y5, (x3 + dx));
688 gc->StrokePath(p7);
689
690 }
691
692
693
694 /** Draw the fill pattern into the stipple bitmap.
695 @param gc Graphics context.
696 @param w Image width.
697 @param h Image height.
698 @param lw Line width to draw pattern.
699 */
700 static
701 void
draw_pattern_vertical_shingles_2(wxGraphicsContext * gc,int w,int h,int lw)702 draw_pattern_vertical_shingles_2(
703 wxGraphicsContext *gc,
704 int w,
705 int h,
706 int lw
707 )
708 {
709 double x1;
710 double x2;
711 double x3;
712 double dx;
713 double y1;
714 double y2;
715 double y3;
716 double y4;
717 double y5;
718 double d_w;
719 double d_h;
720 double d_lw;
721
722 wxGraphicsPath p1 = gc->CreatePath();
723 wxGraphicsPath p2 = gc->CreatePath();
724 wxGraphicsPath p3 = gc->CreatePath();
725 wxGraphicsPath p4 = gc->CreatePath();
726 wxGraphicsPath p5 = gc->CreatePath();
727 wxGraphicsPath p6 = gc->CreatePath();
728 wxGraphicsPath p7 = gc->CreatePath();
729 d_w = (double)w;
730 d_h = (double)h;
731 d_lw = (double)lw;
732 y1 = 0.0 - (d_h / 6.0);
733 y2 = d_h / 6.0;
734 y3 = d_h / 2.0;
735 y4 = (5.0 * d_h) / 6.0;
736 y5 = (7.0 * d_h) / 6.0;
737 x1 = d_w / 6.0;
738 x2 = d_w / 2.0;
739 x3 = (5.0 * d_w) / 6.0;
740 dx = d_w / 12.0;
741 p1.MoveToPoint(y2, (0.0 - d_lw));
742 p1.AddLineToPoint(y2, (d_w + d_lw));
743 gc->StrokePath(p1);
744 p2.MoveToPoint(y3, (0.0 - d_lw));
745 p2.AddLineToPoint(y3, (d_w + d_lw));
746 gc->StrokePath(p2);
747 p3.MoveToPoint(y4, (0.0 - d_lw));
748 p3.AddLineToPoint(y4, (d_w + d_lw));
749 gc->StrokePath(p3);
750 p4.MoveToPoint(y1, (x3 + dx));
751 p4.AddLineToPoint(y2, (x3 - dx));
752 gc->StrokePath(p4);
753 p5.MoveToPoint(y2, (x1 + dx));
754 p5.AddLineToPoint(y3, (x1 - dx));
755 gc->StrokePath(p5);
756 p6.MoveToPoint(y3, (x2 + dx));
757 p6.AddLineToPoint(y4, (x2 - dx));
758 gc->StrokePath(p6);
759 p7.MoveToPoint(y4, (x3 + dx));
760 p7.AddLineToPoint(y5, (x3 - dx));
761 gc->StrokePath(p7);
762
763 }
764
765
766
767 /** Draw the fill pattern into the stipple bitmap.
768 @param gc Graphics context.
769 @param w Image width.
770 @param h Image height.
771 @param patco Coefficients for pattern drawing.
772 @param patci Index of start coefficient in array.
773 */
774 static
775 void
draw_pattern_fish_scales(wxGraphicsContext * gc,int w,int h,double const * patco,size_t patci)776 draw_pattern_fish_scales(
777 wxGraphicsContext *gc,
778 int w,
779 int h,
780 double const *patco,
781 size_t patci
782 )
783 {
784 double x0;
785 double y0;
786 double x1;
787 double y1;
788 double d_w;
789 double d_h;
790 wxGraphicsPath p1 = gc->CreatePath();
791 wxGraphicsPath p2 = gc->CreatePath();
792 wxGraphicsPath p3 = gc->CreatePath();
793 wxGraphicsPath p4 = gc->CreatePath();
794
795 d_w = (double)w;
796 d_h = (double)h;
797
798
799 x0 = 0.0;
800 y0 = 0.0;
801 x1 = d_w;
802 y1 = 0.0;
803 p1.MoveToPoint(x0, y0);
804 p1.AddCurveToPoint(
805 (x0 + patco[patci]), (y0 + patco[patci + 1]),
806 (x1 - patco[patci + 2]), (y1 - patco[patci + 3]),
807 x1, y1
808 );
809 gc->StrokePath(p1);
810 x0 = (-1.0 * d_w) / 2.0;
811 y0 = d_h / 2.0;
812 x1 = x0 + d_w;
813 y1 = y0;
814 p2.MoveToPoint(x0, y0);
815 p2.AddCurveToPoint(
816 (x0 + patco[patci]), (y0 + patco[patci + 1]),
817 (x1 - patco[patci + 2]), (y1 - patco[patci + 3]),
818 x1, y1
819 );
820 x0 += d_w;
821 x1 += d_w;
822 p2.AddCurveToPoint(
823 (x0 + patco[patci]), (y0 + patco[patci + 1]),
824 (x1 - patco[patci + 2]), (y1 - patco[patci + 3]),
825 x1, y1
826 );
827 gc->StrokePath(p2);
828 x0 = 0.0;
829 y0 = d_h;
830 x1 = d_w;
831 y1 = d_h;
832 p3.MoveToPoint(x0, y0);
833 p3.AddCurveToPoint(
834 (x0 + patco[patci]), (y0 + patco[patci + 1]),
835 (x1 - patco[patci + 2]), (y1 - patco[patci + 3]),
836 x1, y1
837 );
838 gc->StrokePath(p3);
839 x0 = (-1.0 * d_w) / 2.0;
840 y0 = (-1.0 * d_h) / 2.0;
841 x1 = x0 + d_w;
842 y1 = y0;
843 p4.MoveToPoint(x0, y0);
844 p4.AddCurveToPoint(
845 (x0 + patco[patci]), (y0 + patco[patci + 1]),
846 (x1 - patco[patci + 2]), (y1 - patco[patci + 3]),
847 x1, y1
848 );
849 x0 += d_w;
850 x1 += d_w;
851 p4.AddCurveToPoint(
852 (x0 + patco[patci]), (y0 + patco[patci + 1]),
853 (x1 - patco[patci + 2]), (y1 - patco[patci + 3]),
854 x1, y1
855 );
856 gc->StrokePath(p4);
857
858
859 }
860
861
862
863 /** Draw the fill pattern into the stipple bitmap.
864 @param gc Graphics context.
865 @param w Image width.
866 @param h Image height.
867 */
868 static
869 void
draw_pattern_circles(wxGraphicsContext * gc,int w,int h)870 draw_pattern_circles(
871 wxGraphicsContext *gc,
872 int w,
873 int h
874 )
875 {
876 double r;
877
878 wxGraphicsPath p1 = gc->CreatePath();
879 wxGraphicsPath p2 = gc->CreatePath();
880 wxGraphicsPath p3 = gc->CreatePath();
881 wxGraphicsPath p4 = gc->CreatePath();
882 wxGraphicsPath p5 = gc->CreatePath();
883 r = (double)w / 2.0;
884 p1.AddCircle(r, r, r);
885 gc->StrokePath(p1);
886 p2.AddCircle((0.0 - r), r, r);
887 gc->StrokePath(p2);
888 p3.AddCircle(r, (0.0 - r), r);
889 gc->StrokePath(p3);
890 p4.AddCircle((w + r), r, r);
891 gc->StrokePath(p4);
892 p5.AddCircle(r, (h + r), r);
893 gc->StrokePath(p5);
894
895 }
896
897
898
899 /** Draw the fill pattern into the stipple bitmap.
900 @param gc Graphics context.
901 @param w Image width.
902 @param h Image height.
903 @param coeff Fixed coefficients.
904 */
905 static
906 void
draw_pattern_hexagons(wxGraphicsContext * gc,int w,int h,double const * coeff)907 draw_pattern_hexagons(
908 wxGraphicsContext *gc,
909 int w,
910 int h,
911 double const *coeff
912 )
913 {
914 double x1;
915 double x2;
916 double x3;
917 double b;
918 double d_h;
919 wxGraphicsPath p1 = gc->CreatePath();
920 wxGraphicsPath p2 = gc->CreatePath();
921
922 d_h = (double)h;
923 b = d_h / 2.0;
924 x1 = b / coeff[0];
925 x2 = b * coeff[0];
926 x3 = (coeff[0] + 1.0 / coeff[0]) * b;
927 p1.MoveToPoint(x1, 0.0);
928 p1.AddLineToPoint(x2, 0.0);
929 p1.AddLineToPoint(x3, (d_h / 2.0));
930 p1.AddLineToPoint(x2, d_h);
931 p1.AddLineToPoint(x1, d_h);
932 p1.AddLineToPoint(0.0, (d_h / 2.0));
933 p1.AddLineToPoint(x1, 0.0);
934 p1.CloseSubpath();
935 gc->StrokePath(p1);
936 p2.MoveToPoint(x3, (d_h / 2.0));
937 p2.AddLineToPoint(w, (d_h / 2.0));
938 gc->StrokePath(p2);
939
940 }
941
942
943
944 /** Draw the fill pattern into the stipple bitmap.
945 @param gc Graphics context.
946 @param w Image width.
947 @param h Image height.
948 @param lw Line width to draw pattern.
949 */
950 static
951 void
draw_pattern_octagons(wxGraphicsContext * gc,int w,int h,int lw)952 draw_pattern_octagons(
953 wxGraphicsContext *gc,
954 int w,
955 int h,
956 int lw
957 )
958 {
959 double x1;
960 double xc;
961 double yc;
962 double d_w;
963 double d_h;
964 double d_lw;
965 wxGraphicsPath p1 = gc->CreatePath();
966 wxGraphicsPath p2 = gc->CreatePath();
967 wxGraphicsPath p3 = gc->CreatePath();
968 wxGraphicsPath p4 = gc->CreatePath();
969 wxGraphicsPath p5 = gc->CreatePath();
970
971 d_w = (double)w;
972 d_h = (double)h;
973 d_lw = (double)lw;
974 /* x1 = d_w * (1.0 - 1.0 / (1.0 + M_SQRT2)); */
975 x1 = (w * M_SQRT2) / (2.0 * (1.0 + M_SQRT2));
976 xc = d_w / 2.0;
977 yc = d_h / 2.0;
978 p1.MoveToPoint((xc - x1), yc);
979 p1.AddLineToPoint(xc, (yc - x1));
980 p1.AddLineToPoint((xc + x1), yc);
981 p1.AddLineToPoint(xc, (yc + x1));
982 p1.AddLineToPoint((xc - x1), yc);
983 p1.CloseSubpath();
984 gc->StrokePath(p1);
985 p2.MoveToPoint((xc - x1), yc);
986 p2.AddLineToPoint((0.0 - d_lw), yc);
987 gc->StrokePath(p2);
988 p3.MoveToPoint(xc, (yc - x1));
989 p3.AddLineToPoint(xc, (0.0 - d_lw));
990 gc->StrokePath(p3);
991 p4.MoveToPoint((xc + x1), yc);
992 p4.AddLineToPoint((d_w + d_lw), yc);
993 gc->StrokePath(p4);
994 p5.MoveToPoint(xc, (yc + x1));
995 p5.AddLineToPoint(xc, (d_h + d_lw));
996 gc->StrokePath(p5);
997
998 }
999
1000
1001
1002 /** Draw the fill pattern into the stipple bitmap.
1003 @param gc Graphics context.
1004 @param w Image width.
1005 @param h Image height.
1006 */
1007 static
1008 void
draw_pattern_horizontal_tires(wxGraphicsContext * gc,int w,int h)1009 draw_pattern_horizontal_tires(
1010 wxGraphicsContext *gc,
1011 int w,
1012 int h
1013 )
1014 {
1015 double y;
1016 double d_w;
1017 double d_h;
1018 size_t i;
1019
1020 d_w = (double)w;
1021 d_h = (double)h;
1022 y = 0.0;
1023 for (i = 0; i < 3; i++) {
1024 wxGraphicsPath p1 = gc->CreatePath();
1025 p1.MoveToPoint((0.0 - d_w), y);
1026 p1.AddLineToPoint((0.0 - d_w / 2.0), (y - d_h));
1027 p1.AddLineToPoint(0.0, y);
1028 p1.AddLineToPoint(((d_w) / 2.0), (y - d_h));
1029 p1.AddLineToPoint(d_w, y);
1030 p1.AddLineToPoint((1.5 * d_w), (y - d_h));
1031 p1.AddLineToPoint((2.0 * d_w), y);
1032 gc->StrokePath(p1);
1033 y += h;
1034 }
1035
1036 }
1037
1038
1039
1040 /** Draw the fill pattern into the stipple bitmap.
1041 @param gc Graphics context.
1042 @param w Image width.
1043 @param h Image height.
1044 */
1045 static
1046 void
draw_pattern_vertical_tires(wxGraphicsContext * gc,int w,int h)1047 draw_pattern_vertical_tires(
1048 wxGraphicsContext *gc,
1049 int w,
1050 int h
1051 )
1052 {
1053 double x;
1054 double d_w;
1055 double d_h;
1056 size_t i;
1057
1058 d_w = (double)w;
1059 d_h = (double)h;
1060 x = 0.0;
1061 for (i = 0; i < 3; i++) {
1062 wxGraphicsPath p = gc->CreatePath();
1063 p.MoveToPoint(x, (0.0 - d_h));
1064 p.AddLineToPoint((x - d_w), (0.0 - d_h / 2.0));
1065 p.AddLineToPoint(x, 0.0);
1066 p.AddLineToPoint((x - d_w), (d_h / 2.0));
1067 p.AddLineToPoint(x, h);
1068 p.AddLineToPoint((x - d_w), (1.5 * d_h));
1069 p.AddLineToPoint(x, (2.0 * d_h));
1070 gc->StrokePath(p);
1071 x += w;
1072 }
1073
1074 }
1075
1076
1077
1078 /** Draw the fill pattern into the stipple bitmap.
1079 @param gc Graphics context.
1080 @param w Image width.
1081 @param h Image height.
1082 @param pt Pattern type.
1083 @param lw Line width to draw pattern.
1084 @param patco Pattern coefficients.
1085 @param coeff Fixed coefficients.
1086 */
1087 static
1088 void
draw_fill_pattern(wxGraphicsContext * gc,int w,int h,int pt,int lw,double const * patco,double const * coeff)1089 draw_fill_pattern(
1090 wxGraphicsContext *gc,
1091 int w,
1092 int h,
1093 int pt,
1094 int lw,
1095 double const *patco,
1096 double const *coeff
1097 )
1098 {
1099
1100 switch (pt) {
1101 case WXD_FS_30_DEGREE_LEFT : {
1102 draw_pattern_30_left(gc, w, h, lw, coeff);
1103 } break;
1104 case WXD_FS_30_DEGREE_RIGHT : {
1105 draw_pattern_30_right(gc, w, h, lw, coeff);
1106 } break;
1107 case WXD_FS_30_DEGREE_SIEVE : {
1108 draw_pattern_30_left(gc, w, h, lw, coeff);
1109 draw_pattern_30_right(gc, w, h, lw, coeff);
1110 } break;
1111 case WXD_FS_45_DEGREE_LEFT : {
1112 draw_pattern_45_left(gc, w, h, lw);
1113 } break;
1114 case WXD_FS_45_DEGREE_RIGHT : {
1115 draw_pattern_45_right(gc, w, h, lw);
1116 } break;
1117 case WXD_FS_45_DEGREE_SIEVE : {
1118 draw_pattern_45_left(gc, w, h, lw);
1119 draw_pattern_45_right(gc, w, h, lw);
1120 } break;
1121 case WXD_FS_HORIZONTAL_BRICKS : {
1122 draw_pattern_horizontal_bricks(gc, w, h, lw);
1123 } break;
1124 case WXD_FS_VERTICAL_BRICKS : {
1125 draw_pattern_vertical_bricks(gc, w, h, lw);
1126 } break;
1127 case WXD_FS_HORIZONTAL_LINES : {
1128 draw_pattern_horizontal_lines(gc, w, h, lw);
1129 } break;
1130 case WXD_FS_VERTICAL_LINES : {
1131 draw_pattern_vertical_lines(gc, w, h, lw);
1132 } break;
1133 case WXD_FS_HORIZONTAL_VERTICAL_SIEVE : {
1134 draw_pattern_horizontal_lines(gc, w, h, lw);
1135 draw_pattern_vertical_lines(gc, w, h, lw);
1136 } break;
1137 case WXD_FS_HORIZONTAL_SHINGLES_LEFT : {
1138 draw_pattern_horizontal_shingles_left(gc, w, h, lw);
1139 } break;
1140 case WXD_FS_HORIZONTAL_SHINGLES_RIGHT : {
1141 draw_pattern_horizontal_shingles_right(gc, w, h, lw);
1142 } break;
1143 case WXD_FS_VERTICAL_SHINGLES_1 : {
1144 draw_pattern_vertical_shingles_1(gc, w, h, lw);
1145 } break;
1146 case WXD_FS_VERTICAL_SHINGLES_2 : {
1147 draw_pattern_vertical_shingles_2(gc, w, h, lw);
1148 } break;
1149 case WXD_FS_LARGE_FISH_SCALES : {
1150 draw_pattern_fish_scales(gc, w, h, patco, 9);
1151 } break;
1152 case WXD_FS_SMALL_FISH_SCALES : {
1153 draw_pattern_fish_scales(gc, w, h, patco, 13);
1154 } break;
1155 case WXD_FS_CIRCLES : {
1156 draw_pattern_circles(gc, w, h);
1157 } break;
1158 case WXD_FS_HEXAGONS : {
1159 draw_pattern_hexagons(gc, w, h, coeff);
1160 } break;
1161 case WXD_FS_OCTAGONS : {
1162 draw_pattern_octagons(gc, w, h, lw);
1163 } break;
1164 case WXD_FS_HORIZONTAL_TIRES : {
1165 draw_pattern_horizontal_tires(gc, w, h);
1166 } break;
1167 case WXD_FS_VERTICAL_TIRES : {
1168 draw_pattern_vertical_tires(gc, w, h);
1169 } break;
1170 }
1171
1172 }
1173
1174
1175
1176 void
UpdateOneStipple(Wxd_stipple_t * psti)1177 WxdkdrawFrame::UpdateOneStipple(Wxd_stipple_t *psti)
1178 {
1179 int w = 0; /* Bitmap width */
1180 int h = 0; /* Bitmap height */
1181 int lw = 0; /* Line width to draw fill pattern */
1182
1183
1184 if (NULL != psti->bm) {
1185 delete(psti->bm);
1186 psti->bm = NULL;
1187 }
1188 #if TRACE_DEBUG
1189 else {
1190 }
1191 #endif
1192 calculate_bitmap_dimensions(&w, &h, (int)(psti->cd[0]), m_dPatterns);
1193 lw = (int)dk4ma_rint(
1194 (0.45 * drawco->m_dZoom * (drawco->m_ptRes).x) / 72.0
1195 );
1196 if (0 >= lw) { lw = 1; }
1197
1198
1199
1200 if ((1 < w) && (1 < h)) {
1201 wxImage imag(w, h);
1202 wxColour fc(
1203 (int)(psti->cd[1]), (int)(psti->cd[2]), (int)(psti->cd[3])
1204 );
1205 wxColour sc(
1206 (int)(psti->cd[4]), (int)(psti->cd[5]), (int)(psti->cd[6])
1207 );
1208 wxBrush bru(fc);
1209 wxPen pen(sc, lw);
1210 wxGraphicsContext *gc = wxGraphicsContext::Create(imag);
1211 if (NULL != gc) {
1212 gc->SetPen(wxNullPen);
1213 gc->SetBrush(bru);
1214 {
1215 wxGraphicsPath p = gc->CreatePath();
1216 p.AddRectangle(0.0, 0.0, (double)w, (double)h);
1217 gc->FillPath(p);
1218 }
1219 gc->SetBrush(wxNullBrush);
1220 pen.SetCap(wxCAP_ROUND);
1221 pen.SetJoin(wxJOIN_ROUND);
1222 gc->SetPen(pen);
1223 draw_fill_pattern(gc,w,h,psti->cd[0],lw,m_dPatterns,m_dFactors);
1224 gc->SetPen(wxNullPen);
1225 gc->Flush();
1226 delete gc;
1227 psti->bm = new wxBitmap(imag);
1228 }
1229 #if TRACE_DEBUG
1230 else {
1231 }
1232 #endif
1233 }
1234 #if TRACE_DEBUG
1235 else {
1236 }
1237 #endif
1238
1239 }
1240
1241
1242
1243 void
UpdatePatternCoefficients(void)1244 WxdkdrawFrame::UpdatePatternCoefficients(void)
1245 {
1246 size_t i;
1247 m_dPatterns[0] =
1248 (drawco->m_dZoom * drawco->m_ptRes.x) / (10.0 * m_dFactors[0]);
1249 m_dPatterns[1] =
1250 (drawco->m_dZoom * drawco->m_ptRes.x) / 10.0;
1251 m_dPatterns[2] =
1252 (drawco->m_dZoom * drawco->m_ptRes.x * M_SQRT2) / 20.0;
1253 m_dPatterns[3] =
1254 (drawco->m_dZoom * drawco->m_ptRes.x) / 5.0;
1255 m_dPatterns[4] =
1256 (drawco->m_dZoom * drawco->m_ptRes.x) / 20.0;
1257 m_dPatterns[5] =
1258 (drawco->m_dZoom * drawco->m_ptRes.x * 0.3);
1259 m_dPatterns[6] =
1260 (drawco->m_dZoom * drawco->m_ptRes.x * 14.54) / 72.0;
1261 m_dPatterns[7] =
1262 (drawco->m_dZoom * drawco->m_ptRes.x * 3.7) / 36.0;
1263 m_dPatterns[8] =
1264 (drawco->m_dZoom * drawco->m_ptRes.x * m_dFactors[0]) / 5.0;
1265 /*
1266 9 to 16
1267 */
1268 for (i = 0; i < 8; i++) {
1269 m_dPatterns[9 + i] = drawco->m_dZoom * m_dFactors[1 + i];
1270 }
1271 }
1272
1273
1274
1275 void
UpdateStipples(void)1276 WxdkdrawFrame::UpdateStipples(void)
1277 {
1278 Wxd_stipple_t *psti;
1279
1280
1281 UpdatePatternCoefficients();
1282 if (NULL != m_pDrw) {
1283 dk4sto_it_reset(m_pDrw->i_stip);
1284 do {
1285 psti = (Wxd_stipple_t *)dk4sto_it_next(m_pDrw->i_stip);
1286 if (NULL != psti) {
1287 UpdateOneStipple(psti);
1288 }
1289 } while (NULL != psti);
1290 }
1291
1292 }
1293
1294
1295
1296 /* vim: set ai sw=4 ts=4 : */
1297
1298