Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1029 serge 1
 
2
#define CLIP_BOTTOM     2
3
#define CLIP_RIGHT      4
4
#define CLIP_LEFT       8
5
6
 
7
 
8
/*=================================
9
10
 
11
{
12
    int   flag;
13
14
 
15
    if( x < clip->xmin ) {
16
        flag |= CLIP_LEFT;
17
    } else if( x > clip->xmax ) {
18
        flag |= CLIP_RIGHT;
19
    }
20
    if( y < clip->ymin ) {
21
        flag |= CLIP_TOP;
22
    } else if( y > clip->ymax ) {
23
        flag |= CLIP_BOTTOM;
24
    }
25
    return( flag );
26
}
27
28
 
29
 
30
/*===========================================================================
31
32
 
33
    (x1, y1) is outside and ( x2, y2 ) is inside the viewport.
34
    NOTE : the signs of denom and ( x - *x1 ) cancel out during division
35
           so make both of them positive before rounding.   */
36
{
37
    int            numer;
38
    int            denom;
39
40
 
41
    numer = 2L * (long)( y2 - *y1 ) * abs( x - *x1 );
42
    if( numer > 0 ) {
43
        numer += denom;                     /* round to closest pixel   */
44
    } else {
45
        numer -= denom;
46
    }
47
    *y1 += numer / ( denom << 1 );
48
    *x1 = x;
49
}
50
51
 
52
 
53
/*=============================================================
54
55
 
56
    viewport using the Cohen-Sutherland clipping algorithm. Return the
57
    clipped coordinates and a decision drawing flag.    */
58
{
59
    int    flag1;
60
    int    flag2;
61
62
 
63
    flag2 = _L1OutCode( clip, *x2, *y2 );
64
    for( ;; ) {
65
        if( flag1 & flag2 ) break;                  /* trivially outside    */
66
        if( flag1 == flag2 ) break;                 /* completely inside    */
67
        if( flag1 == 0 ) {                          /* first point inside   */
68
            if( flag2 & CLIP_TOP ) {
69
                line_inter( y2, x2, *y1, *x1, clip->ymin );
70
            } else if( flag2 & CLIP_BOTTOM ) {
71
                line_inter( y2, x2, *y1, *x1, clip->ymax );
72
            } else if( flag2 & CLIP_RIGHT ) {
73
                line_inter( x2, y2, *x1, *y1, clip->xmax );
74
            } else if( flag2 & CLIP_LEFT ) {
75
                line_inter( x2, y2, *x1, *y1, clip->xmin );
76
            }
77
            flag2 = _L1OutCode( clip, *x2, *y2 );
78
        } else {                                    /* second point inside  */
79
            if( flag1 & CLIP_TOP ) {
80
                line_inter( y1, x1, *y2, *x2, clip->ymin );
81
            } else if( flag1 & CLIP_BOTTOM ) {
82
                line_inter( y1, x1, *y2, *x2, clip->ymax );
83
            } else if( flag1 & CLIP_RIGHT ) {
84
                line_inter( x1, y1, *x2, *y2, clip->xmax );
85
            } else if( flag1 & CLIP_LEFT ) {
86
                line_inter( x1, y1, *x2, *y2, clip->xmin );
87
            }
88
            flag1 = _L1OutCode( clip, *x1, *y1 );
89
        }
90
    }
91
    return( flag1 & flag2 );
92
}
93
94
 
95
 
96
/*======================================================
97
98
 
99
{
100
    if( flag & CLIP_TOP ) {
101
        *y = clip->ymin;
102
    } else if( flag & CLIP_BOTTOM ) {
103
        *y = clip->ymax;
104
    } else if( flag & CLIP_RIGHT ) {
105
        *x = clip->xmax;
106
    } else if( flag & CLIP_LEFT ) {
107
        *x = clip->xmin;
108
    }
109
}
110
111
 
112
 
113
/*==============================================================
114
115
 
116
    active viewport based on the Cohen-Sutherland algorithm for line
117
    clipping. Return the clipped coordinates and a decision drawing
118
    flag ( 0 draw : 1 don't draw ). */
119
{
120
    int  flag1;
121
    int  flag2;
122
123
 
124
    flag2 = _L1OutCode( clip, *x2, *y2 );
125
    for( ;; ) {
126
        if( flag1 & flag2 ) break;                  /* trivially outside    */
127
        if( flag1 == flag2 ) break;                 /* completely inside    */
128
        if( flag1 == 0 ) {
129
            block_inter( clip, x2, y2, flag2 );
130
            flag2 = _L1OutCode( clip,  *x2, *y2 );
131
        } else {
132
            block_inter( clip, x1, y1, flag1 );
133
            flag1 = _L1OutCode( clip, *x1, *y1 );
134
        }
135
    }
136
    return( flag1 & flag2 );
137
}
138
139
 
140
 
141
              clip_t *src_clip,int *src_x, int *src_y,
142
              int *w, int *h)
143
{
144
    int sx0, sy0, sx1, sy1;
145
146
 
147
    sy0 = *src_y;
148
149
 
150
    sy1 = sy0 + *h - 1;
151
152
 
153
 
154
    {
155
      int dx0, dy0, dx1, dy1;
156
157
 
158
      dy0 = *dst_y + sy0 - *src_y;
159
160
 
161
      dy1 = dy0 + sy1 - sy0;
162
163
 
164
      {
165
         *w = dx1 - dx0 + 1;
166
         *h = dy1 - dy0 + 1;
167
168
 
169
         *src_y += dy0 - *dst_y;
170
171
 
172
         *dst_y = dy0;
173
174
 
175
      };
176
      return 1;
177
    }
178
    return 1;
179
};
180