1 /*
2 
3 Copyright (C) 2015-2018 Night Dive Studios, LLC.
4 
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9 
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 GNU General Public License for more details.
14 
15 You should have received a copy of the GNU General Public License
16 along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 
18 */
19 #ifndef __TNG_H
20 #define __TNG_H
21 
22 /*
23  * $Source: n:/project/lib/src/ui/RCS/tng.h $
24  * $Revision: 1.14 $
25  * $Author: dc $
26  * $Date: 1993/10/11 20:27:35 $
27  *
28  * $Log: tng.h $
29  * Revision 1.14  1993/10/11  20:27:35  dc
30  * Angle is fun, fun fun fun
31  *
32  * Revision 1.13  1993/06/04  15:33:21  xemu
33  * remove gfx.h
34  *
35  * Revision 1.12  1993/06/01  20:27:48  xemu
36  * cb_data added to tng stuct
37  *
38  * Revision 1.11  1993/05/12  16:29:43  xemu
39  * added tng_cb_draw
40  *
41  * Revision 1.10  1993/05/12  13:01:00  xemu
42  * event handling macors
43  *
44  * Revision 1.9  1993/05/10  11:28:52  xemu
45  * fixed strange define changes
46  *
47  * Revision 1.8  1993/05/07  18:11:56  mahk
48  * Copied resgui.h straight into the file.  So there.
49  *
50  * Revision 1.7  1993/05/04  17:51:47  xemu
51  * expose signalling
52  *
53  * Revision 1.6  1993/04/29  19:04:56  xemu
54  * removed *2* resource.h includes
55  *
56  * Revision 1.5  1993/04/28  14:40:23  mahk
57  * Preparing for second exodus
58  *
59  * Revision 1.4  1993/04/27  17:49:01  xemu
60  * resgui strip!
61  *
62  * Revision 1.3  1993/04/27  16:37:05  xemu
63  * GFX -> TNG, text support
64  *
65  * Revision 1.2  1993/04/22  15:03:44  xemu
66  * mods
67  *
68  * Revision 1.1  1993/04/21  11:30:56  xemu
69  * Initial revision
70  *
71  *
72  */
73 
74 // Includes
75 #include "lg.h"  // every file should have this
76 #include "error.h"
77 #include "2dres.h"
78 
79 
80 // Default resource id's
81 #define RES_guiIcons					400		// (0x190)
82 #define REF_IMG_iconArrowUp	0x1900000
83 #define REF_IMG_iconArrowUp1	0x1900001
84 #define REF_IMG_iconArrowDn	0x1900002
85 #define REF_IMG_iconArrowDn1	0x1900003
86 #define REF_IMG_iconArrowLt	0x1900004
87 #define REF_IMG_iconArrowLt1	0x1900005
88 #define REF_IMG_iconArrowRt	0x1900006
89 #define REF_IMG_iconArrowRt1	0x1900007
90 #define REF_IMG_iconChkbox		0x1900008
91 #define REF_IMG_iconChkbox1	0x1900009
92 #define REF_IMG_iconRadbut		0x190000a
93 #define REF_IMG_iconRadbut1		0x190000b
94 #define REF_IMG_bitmapMarble	0x190000c
95 #define REF_IMG_imgName1		0x190000d
96 #define RES_sysFont6			401		// (0x191)
97 #define RES_sysFont8			402		// (0x192)
98 #define RES_courFont8		403		// (0x193)
99 #define RES_timesFont12	404		// (0x194)
100 #define RES_timesFont18	405		// (0x195)
101 #define RES_timesFont24	406		// (0x196)
102 #define RES_ithcFont9		407		// (0x197)
103 #define RES_romanFont35	408		// (0x198)
104 #define RES_colorFont13	409		// (0x199)
105 
106 
107 // Typedefs
108 
109 typedef struct {
110 	Id font;						// text font id
111 	Ref bitmapRef;			// bitmapped backdrop (or NULL)
112    LGPoint frobsize;      		// size of non-resource frobs
113 	uchar backColor;			// background color (if bitmapRef == backColor == 0,
114 									// viewport is transparent)
115 	uchar textColor;			// text color
116 	uchar altBackColor;		// alternate background color for some gadgets
117 	uchar altTextColor;		// alternate text color for some gadgets
118 	uchar bordColor[4];	// if TNG_BEVEL, u.l. & l.r. bevel colors
119 									//	(1st pair normal, 2nd pair focus)
120 									//	if TNG_FATBORDER, 4-pixel border using these cols
121 } TNGStyle;
122 
123 #define TNG_BEVEL			0x0001	// bevel border
124 #define TNG_FATBORDER		0x0002	// fat border
125 #define TNG_BMAPBACK		0x0004	// bitmap background
126 #define TNG_TILEBACK		0x0008	// tiled bitmap background
127 #define TNG_NOBACK			0x0010	// fully transparent background
128 
129 // #define TNG_TRANSP      0x0100
130 #define TNG_ALTCOLORS		0x8000	// use alternate background & text colors
131 #define TNG_FOCUS			0x4000	// has focus (use focus bevel)
132 #define TNG_INVERTBEVEL	0x2000	// use inverted bevel
133 #define TNG_NOBORDER		0x1000	// turn off border altogether
134 
135 #define TNG_BEVELMASK	0x6000	// bottom 2 bits for bevel drawing
136 #define TNG_BEVELSHIFT	13			// shift down to put in low bits
137 
138 typedef uchar (*TNGCallback)(void *ui_data, intptr_t user_data);
139 
140 typedef struct _TNG_CB {
141    struct _TNG_CB *next_cb;
142    intptr_t user_data;
143    ushort event_type;
144    ushort condition;
145    int id;
146    TNGCallback cb;
147 } TNG_CB;
148 
149 typedef struct _TNG {
150    void *type_data;
151    void *ui_data;
152    intptr_t cb_data;
153    TNGStyle *style;
154    TNG_CB *pcb;
155    ushort flags;
156    errtype (*draw_func)(struct _TNG *ptng, ushort partmask, LGPoint loc);
157    uchar (*mousebutt)(struct _TNG *ptng, uchar type, LGPoint rel);
158    uchar (*keycooked)(struct _TNG *ptng, ushort key);
159    uchar (*signal)(struct _TNG *ptng, ushort signal);
160    uchar (*keyscan)(struct _TNG *ptng, ushort scan);
161    uchar (*mousemove)(struct _TNG *ptng, LGPoint loc);
162 } TNG;
163 
164 #define TNG_MOUSE_MOTION			0x0001
165 #define TNG_MOUSE_LDOWN			0x0002
166 #define TNG_MOUSE_LUP				0x0004
167 #define TNG_MOUSE_RDOWN			0x0008
168 #define TNG_MOUSE_RUP				0x0010
169 #define TNG_MOUSE_CDOWN			0x0020
170 #define TNG_MOUSE_CUP				0x0040
171 #define TNG_ANY_MOUSE_DOWN		TNG_MOUSE_LDOWN | TNG_MOUSE_RDOWN | TNG_MOUSE_CDOWN
172 #define TNG_ANY_MOUSE_UP			TNG_MOUSE_LUP | TNG_MOUSE_RUP | TNG_MOUSE_CUP
173 #define TNG_ANY_MOUSE_BUTTON	TNG_ANY_MOUSE_UP | TNG_ANY_MOUSE_DOWN
174 #define TNG_ANY_MOUSE				TNG_MOUSE_MOTION | TNG_ANY_MOUSE_BUTTON
175 
176 #define TNG_SIGNAL_CHANGED		0x0001
177 #define TNG_SIGNAL_SELECT			0x0002
178 #define TNG_SIGNAL_DESELECT		0x0004
179 #define TNG_SIGNAL_SCROLL			0x0008
180 #define TNG_SIGNAL_DECREMENT	0x0010
181 #define TNG_SIGNAL_INCREMENT		0x0020
182 #define TNG_SIGNAL_EXPOSE			0x0040
183 
184 #define TNG_EVENT_KBD_RAW		0x00000001
185 #define TNG_EVENT_KBD_COOKED	0x00000002
186 #define TNG_EVENT_MOUSE				0x00000004
187 #define TNG_EVENT_MOUSE_MOVE	0x00000008
188 #define TNG_EVENT_JOY					0x00000010
189 #define TNG_EVENT_SIGNAL			0x00000020
190 #define TNG_ALL_EVENTS				0xFFFFFFFF
191 
192 //#define TNG_DEFAULT_FONT "data/font5x6p.fon"
193 
194 // Prototypes
195 void TNGDrawBase(TNG *ptng, LGPoint coord, LGPoint size);
196 errtype TNGInit(TNG *ptng, TNGStyle *sty, void *ui_data);
197 void TNGDrawBitmapRef(Ref ref, LGPoint pt);
198 void TNGDrawTileMapRef(Ref ref, LGPoint pt);
199 errtype TNGDrawText(Id id, char *text, int x, int y);
200 
201 errtype tng_install_callback(TNG *ptng, ushort event_type, ushort cond, TNGCallback cbfn, intptr_t user_data, int *pid);
202 errtype tng_uninstall_callback(TNG *ptng, int id);
203 uchar tng_cb_mousebutt(TNG *ptng, uchar type, LGPoint loc);
204 uchar tng_cb_keycooked(TNG *ptng, ushort key);
205 uchar tng_cb_signal(TNG *ptng, ushort signal);
206 uchar tng_cb_keyscan(TNG *ptng, ushort scan);
207 uchar tng_cb_mousemove(TNG *ptng, LGPoint loc);
208 errtype tng_cb_draw(TNG *ptng, ushort partmask, LGPoint loc);
209 
210 // Macros
211 #define TNG_STYLE(x) (x)->tng_data->style
212 #define TNG_FLAGS(x) (x)->tng_data->flags
213 #define TNG_UI_DATA(x) (x)->tng_data->ui_data;
214 
215 #define TNG_SIGNAL(ptng, sig) (ptng)->signal((ptng),(sig))
216 
217 #define TNG_DRAW_TEXT(ptng, text, x, y) TNGDrawText((ptng)->style->font, text, x, y)
218 
219 #define IF_SET_RV(x) if (!retval) { retval = x; }
220 #define IF_RV(x) if (!retval) { x; }
221 
222 // externals
223 
224 extern LGPoint tngZeroPt;
225 
226 #include "tngapp.h"
227 
228 #endif // __TNG_H
229 
230