chiark / gitweb /
Initial revision
[ssr] / StraySrc / Libraries / Steel / h / coords
1 /*
2  * coords.h
3  *
4  * Miscellaneous handling of window-related geometries
5  *
6  * © 1994-1998 Straylight
7  */
8
9 /*----- Licensing note ----------------------------------------------------*
10  *
11  * This file is part of Straylight's Steel library.
12  *
13  * Steel is free software; you can redistribute it and/or modify
14  * it under the terms of the GNU General Public License as published by
15  * the Free Software Foundation; either version 2, or (at your option)
16  * any later version.
17  *
18  * Steel is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with Steel.  If not, write to the Free Software Foundation,
25  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26  */
27
28 #ifndef __coords_h
29 #define __coords_h
30
31 #ifndef __wimp
32   #include "wimp.h"
33 #endif
34
35 /* --- Passing window information to coords --- */
36
37 typedef struct
38 {
39   wimp_box box;
40   int scx;
41   int scy;
42 }
43 coords_cvtstr;
44
45 /* --- Passing individual points --- *
46  *
47  * This is actually slightly silly, but we do it this way for compatibility
48  * with RISC_OSLib
49  */
50
51 typedef struct
52 {
53   int x;
54   int y;
55 }
56 coords_pointstr;
57
58 /*
59  * int coords_x_toscreen(int x,coords_cvtstr *c)
60  * int coords_y_toscreen(int y,coords_cvtstr *c)
61  * int coords_x_toworkarea(int x,coords_cvtstr *c)
62  * int coords_y_toworkarea(int y,coords_cvtstr *c)
63  *
64  * Use
65  *  Convert x- or y-coordinates from window to screen coordinates or vice-
66  *  versa.
67  *
68  * Parameters
69  *  int x or int y == the coordinate to convert
70  *  coords_cvtstr *c == pointer to window information (e.g. cast from a
71  *    wimp_wstate or a wimp_redrawstr)
72  *
73  * Returns
74  *  The appropriate screen- or window-relative coordinate
75  */
76
77 int coords_x_toscreen(int x,coords_cvtstr *c);
78 int coords_y_toscreen(int y,coords_cvtstr *c);
79 int coords_x_toworkarea(int x,coords_cvtstr *c);
80 int coords_y_toworkarea(int y,coords_cvtstr *c);
81
82 /*
83  * void coords_box_toscreen(wimp_box *b,coords_cvtstr *c)
84  * void coords_box_toworkarea(wimp_box *b,coords_cvtstr *c)
85  *
86  * Use
87  *  Converts a whole rectangle from window to screen coordinates or vice-
88  *  versa.
89  *
90  * Parameters
91  *  wimp_box *b == pointer to the rectangle to convert
92  *  coords_cvtstr *c == pointer to the window information to use
93  */
94
95 void coords_box_toscreen(wimp_box *b,coords_cvtstr *c);
96 void coords_box_toworkarea(wimp_box *b,coords_cvtstr *c);
97
98 /*
99  * void coords_point_toscreen(coords_pointstr *p,coords_cvtstr *c)
100  * void coords_point_toworkarea(coords_pointstr *p,coords_cvtstr *c)
101  *
102  * Use
103  *  Converts a single point from window to screen coordinates or vice-versa.
104  *
105  * Parameters
106  *  coords_pointstr *p == pointer to the rectangle to convert
107  *  coords_cvtstr *c == pointer to the window information to use
108  */
109
110 void coords_point_toscreen(coords_pointstr *p,coords_cvtstr *c);
111 void coords_point_toworkarea(wimp_box *b,coords_cvtstr *c);
112
113 /*
114  * BOOL coords_withinbox(coords_pointstr *p,wimp_box *b)
115  *
116  * Use
117  *  Returns whether the given point lies within (or on the edge of) the
118  *  specified box
119  *
120  * Parameters
121  *  coords_pointstr *p == pointer to the point
122  *  wimp_box *b == pointer to the box
123  *
124  * Returns
125  *  TRUE if the point is indeed within the box, and FALSE otherwise
126  */
127
128 BOOL coords_withinbox(coords_pointstr *p,wimp_box *b);
129
130 /*
131  * void coords_offsetbox(wimp_box *source,int ox,int oy,wimp_box *dest)
132  *
133  * Use
134  *  Nudges the given rectangle by adding the given offsets to the x and y
135  *  coordinates.
136  *
137  * Parameters
138  *  wimp_box *source == pointer to the rectangle to nudge
139  *  int ox == amount to nudge the x-coordinates of the box
140  *  int oy == amount to nudge the y-coordinates of the box
141  *  wimp_box *dest == pointer to where to put the nudged rectangle (may be
142  *    the same as source)
143  */
144
145 void coords_offsetbox(wimp_box *source,int ox,int oy,wimp_box *dest);
146
147 /*
148  * BOOL coords_intersects(wimp_box *line,wimp_box *box,int width)
149  *
150  * Use
151  *  Returns FALSE only if the line specified does not intersect the specified
152  *  box.  The line is considered to have a thickness of width.  The method
153  *  used is very approximate, and false positives may occur.
154  *
155  * Parameters
156  *  wimp_box *line == pointer to the coordinates of the line
157  *  wimp_box *box == pointer to the coordinates of the box
158  *
159  * Returns
160  *  FALSE if the line does not intersect the box
161  */
162
163 BOOL coords_intersects(wimp_box *line,wimp_box *box,int width);
164
165 /*
166  * BOOL coords_boxesoverlap(wimp_box *a,wimp_box *b)
167  *
168  * Use
169  *  Determines whether two boxes overlap at all (useful for checking whether
170  *  to redraw something).
171  *
172  * Parameters
173  *  wimp_box *a == pointer to one of the rectangles to test
174  *  wimp_box *b == pointer to the other rectangle
175  *
176  * Returns
177  *  TRUE if the boxes overlap, or FALSE if they don't
178  */
179
180 BOOL coords_boxesoverlap(wimp_box *a,wimp_box *b);
181
182 #endif