Skip to content

Commit 1b35a01

Browse files
authored
Add files via upload
1 parent e172b2d commit 1b35a01

12 files changed

+4183
-0
lines changed

CXTypes.c

+228
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,228 @@
1+
//
2+
// CoreX library
3+
//
4+
// Created by error on 21.01.18.
5+
// Copyright © 2018 errorsoft. All rights reserved.
6+
//
7+
8+
#include "CXTypes.h"
9+
10+
// --------------------------------------------------------------------
11+
// CXPoint support
12+
// --------------------------------------------------------------------
13+
14+
CXPoint CXMakePoint(int x, int y) {
15+
CXPoint point;
16+
point.x = x;
17+
point.y = y;
18+
return point;
19+
}
20+
21+
void CXSetPoint(CXPointRef point, int x, int y) {
22+
CXSetPointM(*point, x, y);
23+
}
24+
25+
void CXOffsetPoint(CXPointRef point, int dx, int dy) {
26+
CXOffsetPointM(*point, dx, dy);
27+
}
28+
29+
CXBool CXIsPointInRect(CXPointRef point, CXRectRef rect) {
30+
return CXIsPointInRectM(*point, *rect);
31+
}
32+
33+
// --------------------------------------------------------------------
34+
// CXRect support
35+
// --------------------------------------------------------------------
36+
37+
// Make
38+
CXRect CXMakeRect(int left, int top, int right, int bottom) {
39+
CXRect rect;
40+
rect.left = left;
41+
rect.top = top;
42+
rect.right = right;
43+
rect.bottom = bottom;
44+
return rect;
45+
}
46+
47+
CXRect CXMakeRectEx(int left, int top, int width, int height) {
48+
CXRect rect;
49+
rect.left = left;
50+
rect.top = top;
51+
rect.right = left + width;
52+
rect.bottom = top + height;
53+
return rect;
54+
}
55+
56+
void CXSetRect(CXRectRef rect, int left, int top, int right, int bottom) {
57+
CXSetRectM(*rect, left, top, right, bottom);
58+
}
59+
60+
void CXSetRectEx(CXRectRef rect, int left, int top, int width, int height) {
61+
CXSetRectExM(*rect, left, top, width, height);
62+
}
63+
64+
void CXOffsetRect(CXRectRef rect, int dx, int dy) {
65+
CXOffsetRectM(*rect, dx, dy);
66+
}
67+
68+
void CXNormalizeRect(CXRectRef rect) {
69+
int t;
70+
CXNormalizeRectM(*rect, t);
71+
}
72+
73+
int CXRectClipLine(CXRect rect, int *x1, int *y1, int *x2, int *y2) {
74+
int p1, p2;
75+
int *t;
76+
int result = 0;
77+
78+
p1 = CXCalcClipCodeM(rect, *x1, *y1);
79+
p2 = CXCalcClipCodeM(rect, *x2, *y2);
80+
81+
result += p1 + p2 * 2;
82+
83+
// if need clipping
84+
while(p1 | p2) {
85+
86+
// p1 and p2 locate on some side, all clipped
87+
if(p1 & p2)
88+
return -1;
89+
90+
if (!p1) {
91+
t = y1; y1 = y2; y2 = t;
92+
t = x1; x1 = x2; x2 = t;
93+
94+
p1 = p2;
95+
p2 = 0;
96+
}
97+
98+
if(p1 & CCLeft) {
99+
*y1 = InterM(*y1, *y2, *x1, *x2, rect.left);
100+
*x1 = rect.left;
101+
} else if(p1 & CCTop) {
102+
*x1 = InterM(*x1, *x2, *y1, *y2, rect.top);
103+
*y1 = rect.top;
104+
} else if(p1 & CCRight) {
105+
*y1 = InterM(*y1, *y2, *x1, *x2, rect.right - 1);
106+
*x1 = rect.right - 1;
107+
} else if(p1 & CCBottom) {
108+
*x1 = InterM(*x1, *x2, *y1, *y2, rect.bottom - 1);
109+
*y1 = rect.bottom - 1;
110+
}
111+
112+
p1 = CXCalcClipCodeM(rect, *x1, *y1);
113+
}
114+
115+
return result;
116+
}
117+
118+
int CXCalcClipCode(CXRect rect, int x, int y) {
119+
return CalcClipCode(rect.left, rect.top, rect.right, rect.bottom, x, y);
120+
}
121+
122+
// --------------------------------------------------------------------
123+
// Utils
124+
// --------------------------------------------------------------------
125+
126+
int CalcClipCode(int left, int top, int right, int bottom, int x, int y) {
127+
return CalcClipCodeM(left, top, right, bottom, x, y);
128+
}
129+
130+
int IsIntersectBars(int a1, int a2, int b1, int b2) {
131+
int t;
132+
133+
if(a1 > a2) {
134+
Swap(a1, a2, t);
135+
}
136+
137+
if(b1 > b2) {
138+
Swap(b1, b2, t);
139+
}
140+
141+
return Max(a1, b1) <= Min(a2, b2);
142+
}
143+
144+
int ClipLineForSize(int width, int height, int *x1, int *y1, int *x2, int *y2) {
145+
int p1, p2;
146+
int *t;
147+
int result = 0;
148+
149+
p1 = CalcClipCodeM(0, 0, width, height, *x1, *y1);
150+
p2 = CalcClipCodeM(0, 0, width, height, *x2, *y2);
151+
152+
result += p1 + p2 * 2;
153+
154+
// if need clipping
155+
while(p1 | p2) {
156+
157+
// p1 and p2 locate on some side, all clipped
158+
if(p1 & p2)
159+
return -1;
160+
161+
if (!p1) {
162+
t = y1; y1 = y2; y2 = t;
163+
t = x1; x1 = x2; x2 = t;
164+
165+
p1 = p2;
166+
p2 = 0;
167+
}
168+
169+
if(p1 & CCLeft) {
170+
*y1 = InterM(*y1, *y2, *x1, *x2, 0);
171+
*x1 = 0;
172+
} else if(p1 & CCTop) {
173+
*x1 = InterM(*x1, *x2, *y1, *y2, 0);
174+
*y1 = 0;
175+
} else if(p1 & CCRight) {
176+
*y1 = InterM(*y1, *y2, *x1, *x2, width - 1);
177+
*x1 = width - 1;
178+
} else if(p1 & CCBottom) {
179+
*x1 = InterM(*x1, *x2, *y1, *y2, height - 1);
180+
*y1 = height - 1;
181+
}
182+
183+
p1 = CalcClipCodeM(0, 0, width, height, *x1, *y1);
184+
}
185+
186+
return result;
187+
}
188+
189+
int IsPointInRect(int x, int y, int left, int top, int right, int bottom) {
190+
return IsPointInRectM(x, y, left, top, right, bottom);
191+
}
192+
193+
int IsPointInSize(int x, int y, int width, int height) {
194+
return IsPointInSizeM(x, y, width, height);
195+
}
196+
197+
int IsDrawRectIntersectRect(int x, int y, int width, int height, CXRect rect) {
198+
return IsDrawRectIntersectRectM(x, y, width, height, rect);
199+
}
200+
201+
int IsDrawRectIntersectSize(int drawX, int drawY, int drawWidth, int drawHeight, int width, int height) {
202+
return IsDrawRectIntersectSizeM(drawX, drawY, drawWidth, drawHeight, width, height);
203+
}
204+
205+
void NormalizeRect(int *x1, int *y1, int *x2, int *y2) {
206+
int t;
207+
NormalizeRectM(*x1, *y1, *x2, *y2, t);
208+
}
209+
210+
void ClipSpan(int clip1, int clip2, int *val1, int *val2) {
211+
ClipSpanM(clip1, clip2, *val1, *val2);
212+
}
213+
214+
int ClipValue(int min, int max, int val) {
215+
return ClipValueM(min, max, val);
216+
}
217+
218+
int Inter(int y1, int y2, int x1, int x2, int x) {
219+
return InterM(y1, y2, x1, x2, x);
220+
}
221+
222+
float InterF(float y1, float y2, float x1, float x2, float x) {
223+
return InterM(y1, y2, x1, x2, x);
224+
}
225+
226+
227+
228+

0 commit comments

Comments
 (0)