RECT.H
[目次 | 型・クラス・構造体 | マクロ]
1|/***********************************************************************
2| 1. <<< 矩形 (Rect) >>>
3|************************************************************************/
4|
5|#ifndef __RECT_H
6|#define __RECT_H
7|
8|
9|/****************************************************************
10| 2. <<< モジュール・プロパティ >>>
11|*****************************************************************/
12|/*----------------------------------------------------------------------
13|[Module Property]
14|name = Rect
15|title = 矩形
16|category = 基本型
17|src = rect.c
18|depend =
19|priority =
20|accord =
21|----------------------------------------------------------------------*/
22|
23|
24|/****************************************************************
25| 3. <<< 優先ヘッダ >>>
26|*****************************************************************/
27|#ifndef USES_PRIORITY_HEADER
28|/*[START_OF_PRIORITY_HEADER]*/
29|
30|#ifndef USES_RECT
31|#define USES_RECT
32|typedef struct _Rect Rect;
33|typedef struct _Rect_2XY Rect_2XY;
34|typedef struct _Rect_Ex Rect_Ex;
35|
36|/*#define RECT_USES_WINDOWS_DC*/ /* DC へ描画するルーチンを使う */
37|
38|#endif
39|
40|/*[END_OF_PRIORITY_HEADER]*/
41|#endif /* USES_PRIORITY_HEADER */
42|
43|
44|
45|/*-----------------------------------------------------------------*/
46|/* 4. <<< Interface Area ---------------------------------------- >>> */
47|/*-----------------------------------------------------------------*/
48|
49|#ifdef __cplusplus
50|extern "C" {
51|#endif
52|
53|/***********************************************************************
54| 5. <<< [Rect] 矩形(幅・高さ指定) >>>
55|************************************************************************/
56|struct _Rect {
57| int x, y; /* 左上(x,yの最小値)の座標 */
58| int w, h; /* 幅と高さ */
59|};
60|
61|void Rect_init( Rect*, int x, int y, int w, int h );
62|void Rect_init_by2XY( Rect*, int x1, int y1, int x2, int y2 );
63|void Rect_copy( Rect*, Rect* );
64|void Rect_toAnd( Rect* ans, Rect* a, Rect* b );
65|bool Rect_isPointIn( Rect* rect, int x, int y );
66|int Rect_getPointPos( Rect* rect, int x, int y );
67|#ifndef ERRORS_CUT_DEBUG_TOOL
68| void Rect_print( Rect*, const char* title );
69|#endif
70|
71|#define Rect_nHandle 8
72|int Rect_getHitHandleNum( Rect*, int x, int y, int* dx, int* dy );
73|void Rect_moveByHandle( Rect*, int iHandle, int x, int y );
74|void Rect_getCenterOfHandle( Rect*, int iHandle, int* x, int* y );
75|
76|
77|/***********************************************************************
78| 6. <<< [Rect_2XY] 矩形(2点指定)>>>
79|************************************************************************/
80|struct _Rect_2XY {
81| int x1, y1; /* ある頂点の座標 */
82| int x2, y2; /* x1,y1 と対角線上の頂点の座標 */
83|};
84|
85|void Rect_2XY_init( Rect_2XY*, int x1, int y1, int x2, int y2 );
86|void Rect_2XY_copy( Rect_2XY* dst, Rect_2XY* src );
87|void Rect_2XY_moveTo( Rect_2XY* m, int x, int y );
88|void Rect_2XY_setInDesktop( Rect_2XY* wnd, Rect_2XY* desktop );
89|
90|
91|
92|/***********************************************************************
93| 7. <<< [RECT_X_LT] 矩形と点の位置関係 >>>
94|【補足】
95|・それぞれの座標が矩形領域に対して次の5つの領域に分けます。
96| LT = Less Than(<), LE = Less Equal(<=), E = In(Equal)
97| GT = Greater Than(<), GE = Greater Equal(<=)
98|・端を含む領域を判定する場合、次のようにします。
99| ret = getRelation();
100| if ( ( ret & (RECT_X_LE | RECT_X_E | RECT_X_GE) ) &&
101| ( ret & (RECT_Y_LE | RECT_Y_E | RECT_Y_GE) ) ) ...
102|************************************************************************/
103|#define RECT_X 0x01F /* X 座標に関するマスク */
104|#define RECT_X_LT 0x001 /* X が矩形領域の左外 */
105|#define RECT_X_LE 0x002 /* X が左端 */
106|#define RECT_X_E 0x004 /* X が中 */
107|#define RECT_X_GE 0x008 /* X が右端 */
108|#define RECT_X_GT 0x010 /* X が右外 */
109|
110|#define RECT_Y 0x3E0 /* Y 座標に関するマスク */
111|#define RECT_Y_LT 0x020 /* Y が上外 */
112|#define RECT_Y_LE 0x040 /* Y が上端 */
113|#define RECT_Y_E 0x080 /* Y が中 */
114|#define RECT_Y_GE 0x100 /* Y が下端 */
115|#define RECT_Y_GT 0x200 /* Y が下外 */
116|
117|
118|#ifdef __cplusplus
119|}
120|#endif
121|
122|/*-----------------------------------------------------------------*/
123|/* 8. <<< Mapping Area ------------------------------------------ >>> */
124|/*-----------------------------------------------------------------*/
125|
126|
127|/***********************************************************************
128| 9. <<< [Rect_init_by2XY] 2点指定で初期化する >>>
129|************************************************************************/
130|#define Rect_init_by2XY( this, _x1, _y1, _x2, _y2 ) \
131| ( (this)->x = (_x1), \
132| (this)->w = (_x2)-(_x1)+1, \
133| (this)->y = (_y1), \
134| (this)->h = (_y2)-(_y1)+1 )
135|
136|
137|/***********************************************************************
138| 10. <<< [Rect_copy] コピーする >>>
139|************************************************************************/
140|#define Rect_copy( ra, rb ) *(ra) = *(rb)
141|
142|
143|/***********************************************************************
144| 11. <<< [Rect_setSize] 矩形のサイズを変更する >>>
145|【補足】
146|・左上端は固定です。
147|************************************************************************/
148|#define Rect_setSize( this, _w, _h ) \
149| ( (this)->w = (_w), (this)->h = (_h) )
150|
151|
152|/***********************************************************************
153| 12. <<< [Rect_2XY_init] 初期化する >>>
154|************************************************************************/
155|#define Rect_2XY_init( this, _x1, _y1, _x2, _y2 ) \
156| ( (this)->x1 = (_x1), (this)->x2 = (_x2), (this)->y1 = (_y1), (this)->y2 = (_y2) )
157|
158|
159|/***********************************************************************
160| 13. <<< [Rect_2XY_copy] コピーする >>>
161|************************************************************************/
162|#define Rect_2XY_copy( ra, rb ) *(ra) = *(rb)
163|
164|
165|/***********************************************************************
166| 14. <<< [Rect_2XY_moveTo] 移動する >>>
167|【引数】
168| ・Rect_2XY* m; ウィンドウの位置(入出力)
169| ・int x,y; 移動先となるウィンドウ左上の座標
170|【補足】
171|・以下のように使います。
172| GetDesktopWindow()->GetWindowRect( &desktop );
173| GetWindowRect( &rect );
174| Rect_2XY_moveTo( (Rect_2XY*)&rect, m_domain->wnd_x, m_domain->wnd_y );
175| Rect_2XY_setInDesktop( (Rect_2XY*)&rect, (Rect_2XY*)&desktop );
176| MoveWindow( &rect );
177|************************************************************************/
178|#define Rect_2XY_moveTo( m, x, y ) \
179| ( ((m)->x2 -= (m)->x1 - x), ((m)->x1 = x), \
180| ((m)->y2 -= (m)->y1 - y), ((m)->y1 = y) )
181|
182|
183|
184|#endif
185|
186|