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 __TNGTEXTG_H
20 #define __TNGTEXTG_H
21 
22 /*
23  * $Source: n:/project/lib/src/ui/RCS/tngtextg.h $
24  * $Revision: 1.4 $
25  * $Author: dc $
26  * $Date: 1993/10/11 20:27:44 $
27  *
28  * $Log: tngtextg.h $
29  * Revision 1.4  1993/10/11  20:27:44  dc
30  * Angle is fun, fun fun fun
31  *
32  * Revision 1.3  1993/05/04  17:53:15  xemu
33  * TNG_TX_ADDSTRING changed to use sequencing
34  *
35  * Revision 1.2  1993/04/28  14:40:28  mahk
36  * Preparing for second exodus
37  *
38  * Revision 1.1  1993/04/27  16:37:25  xemu
39  * Initial revision
40  *
41  *
42  */
43 
44 // Includes
45 #include "lg.h"  // every file should have this
46 #include "texttool.h"
47 #include "tng.h"
48 
49 typedef struct {
50    TNG *tng_data;
51    LGPoint size;
52    short last_key;
53    ulong options;
54    TextTool *tt;
55    TNG *hscroll_tng, *vscroll_tng;
56 } TNG_textgadget;
57 
58 #define TNG_TG_TEXTAREA   0x0001
59 #define TNG_TG_HSCROLL  0x0002
60 #define TNG_TG_VSCROLL  0x0004
61 
62 #define TNG_TG_BORDER_WIDTH   1
63 #define TNG_TG_SCROLL_X       14
64 #define TNG_TG_SCROLL_Y       14
65 
66 #define TNG_TG_RETURN_KEY          0xd
67 #define TNG_TG_UP_KEY              0x48
68 #define TNG_TG_DOWN_KEY            0x50
69 #define TNG_TG_LEFT_KEY            0x4b
70 #define TNG_TG_RIGHT_KEY           0x4d
71 #define TNG_TG_SCROLL_LEFT_KEY     0x47
72 #define TNG_TG_SCROLL_RIGHT_KEY    0x4f
73 #define TNG_TG_SCROLL_UP_KEY       0x49
74 #define TNG_TG_SCROLL_DOWN_KEY     0x51
75 
76 #define TNG_TG_SINGLE_LINE        0x0001
77 #define TNG_TG_LINE_SET           0x0002
78 #define TNG_TG_READ_ONLY          0x0004
79 
80 #define TNG_TG_HORZ_SCROLL        0x1000
81 #define TNG_TG_VERT_SCROLL        0x2000
82 
83 #define TNG_TG_SCROLLBARS   TNG_TG_HORZ_SCROLL | TNG_TG_VERT_SCROLL
84 // Prototypes
85 
86 // Initializes the TNG
87 // Note that both of these must be called!
88 // _init is called before the UI deals appropriately, _init2 is called afterwards.
89 errtype tng_textgadget_init(void *ui_data, TNG *ptng, TNGStyle *sty, ulong options, LGPoint size, LGPoint abs_loc);
90 errtype tng_textgadget_init2(TNG *ptng);
91 
92 // Deallocate all memory used by the TNG
93 errtype tng_textgadget_destroy(TNG *ptng);
94 
95 // Draw the specified parts (may be all) of the TNG at screen coordinates loc
96 // assumes all appropriate setup has already been done!
97 errtype tng_textgadget_2d_draw(TNG *ptng, ushort partmask, LGPoint loc);
98 
99 // Fill in ppt with the size of the TNG
100 errtype tng_textgadget_size(TNG *ptng, LGPoint *ppt);
101 
102 // Returns the current "value" of the TNG
103 int tng_textgadget_getvalue(TNG *ptng);
104 
105 // React appropriately for receiving the specified cooked key
106 uchar tng_textgadget_keycooked(TNG *ptng, ushort key);
107 
108 // React appropriately for receiving the specified mouse button event
109 uchar tng_textgadget_mousebutt(TNG *ptng, uchar type, LGPoint loc);
110 
111 // Handle incoming signals
112 uchar tng_textgadget_signal(TNG *ptng, ushort signal);
113 
114 errtype tng_textgadget_scroll(TNG *ptng);
115 
116 errtype tng_textgadget_addstring(TNG *ptng, char *s);
117 
118 // Macros
119 #define TNG_TG(ptng) ((TNG_textgadget *)(ptng->type_data))
120 #define TNG_TG_SIZE(ptng) ((TNG_textgadget *)(ptng->type_data))->size
121 #define TNG_TG_LASTKEY(ptng) ((TNG_textgadget *)(ptng->type_data))->last_key
122 #define TNG_TG_TT(ptng) ((TNG_textgadget *)(ptng->type_data))->tt
123 
124 #define TNG_TX_GETLINE(ptng,l) tt_get(TNG_TG_TT(ptng),(l))
125 #define TNG_TX_ADDSTRING(ptng,s) tng_textgadget_addstring(ptng, s);
126 #define TNG_TX_CLEARLINE(ptng,l) tt_fill_line(TNG_TG_TT(ptng),TTF_REPLACE,(l),"\0"); _tt_do_event(TTEV_BOL)
127 
128 #endif // __TNGTEXTG_H
129 
130