Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
3120 | serge | 1 | |
2 | #define CLIP_BOTTOM 2 |
||
3 | #define CLIP_RIGHT 4 |
||
4 | #define CLIP_LEFT 8 |
||
5 | |||
6 | |||
7 | { |
||
8 | int xmin; |
||
9 | int ymin; |
||
10 | int xmax; |
||
11 | int ymax; |
||
12 | }clip_t; |
||
13 | |||
14 | |||
15 | |||
16 | /*================================= |
||
17 | |||
18 | |||
19 | { |
||
20 | int flag; |
||
21 | |||
22 | |||
23 | if( x < clip->xmin ) { |
||
24 | flag |= CLIP_LEFT; |
||
25 | } else if( x > clip->xmax ) { |
||
26 | flag |= CLIP_RIGHT; |
||
27 | } |
||
28 | if( y < clip->ymin ) { |
||
29 | flag |= CLIP_TOP; |
||
30 | } else if( y > clip->ymax ) { |
||
31 | flag |= CLIP_BOTTOM; |
||
32 | } |
||
33 | return( flag ); |
||
34 | }; |
||
35 | |||
36 | |||
37 | /*====================================================== |
||
38 | |||
39 | |||
40 | { |
||
41 | if( flag & CLIP_TOP ) { |
||
42 | *y = clip->ymin; |
||
43 | } else if( flag & CLIP_BOTTOM ) { |
||
44 | *y = clip->ymax; |
||
45 | } else if( flag & CLIP_RIGHT ) { |
||
46 | *x = clip->xmax; |
||
47 | } else if( flag & CLIP_LEFT ) { |
||
48 | *x = clip->xmin; |
||
49 | } |
||
50 | } |
||
51 | |||
52 | |||
53 | |||
54 | /*============================================================== |
||
55 | |||
56 | |||
57 | active viewport based on the Cohen-Sutherland algorithm for line |
||
58 | clipping. Return the clipped coordinates and a decision drawing |
||
59 | flag ( 0 draw : 1 don't draw ). */ |
||
60 | { |
||
61 | int flag1; |
||
62 | int flag2; |
||
63 | |||
64 | |||
65 | flag2 = _L1OutCode( clip, *x2, *y2 ); |
||
66 | for( ;; ) { |
||
67 | if( flag1 & flag2 ) break; /* trivially outside */ |
||
68 | if( flag1 == flag2 ) break; /* completely inside */ |
||
69 | if( flag1 == 0 ) { |
||
70 | block_inter( clip, x2, y2, flag2 ); |
||
71 | flag2 = _L1OutCode( clip, *x2, *y2 ); |
||
72 | } else { |
||
73 | block_inter( clip, x1, y1, flag1 ); |
||
74 | flag1 = _L1OutCode( clip, *x1, *y1 ); |
||
75 | } |
||
76 | } |
||
77 | return( flag1 & flag2 ); |
||
78 | } |
||
79 | |||
80 | |||
81 | |||
82 | clip_t *src_clip,int *src_x, int *src_y, |
||
83 | u32_t *w, u32_t *h) |
||
84 | { |
||
85 | int sx0, sy0, sx1, sy1; |
||
86 | |||
87 | |||
88 | sy0 = *src_y; |
||
89 | |||
90 | |||
91 | sy1 = sy0 + *h - 1; |
||
92 | |||
93 | |||
94 | |||
95 | { |
||
96 | int dx0, dy0, dx1, dy1; |
||
97 | |||
98 | |||
99 | dy0 = *dst_y + sy0 - *src_y; |
||
100 | |||
101 | |||
102 | dy1 = dy0 + sy1 - sy0; |
||
103 | |||
104 | |||
105 | { |
||
106 | *w = dx1 - dx0 + 1; |
||
107 | *h = dy1 - dy0 + 1; |
||
108 | |||
109 | |||
110 | *src_y += dy0 - *dst_y; |
||
111 | |||
112 | |||
113 | *dst_y = dy0; |
||
114 | |||
115 | |||
116 | }; |
||
117 | } |
||
118 | return 1; |
||
119 | };>> |
||
120 |