2 @Copyright Looking Glass Studios, Inc.
3 1996,1997,1998,1999,2000 Unpublished Work.
6 // $Header: r:/t2repos/thief2/libsrc/gadget/gadmenu.h,v 1.7 1996/11/08 14:23:13 xemu Exp $
13 ////////////////////////////////////////////////////////////
16 // A menu is pretty much a vertical array of buttons, usually text.
17 // It can be transient, and will save under itself.
20 typedef struct _LGadMenu LGadMenu
;
22 //------------------------------------------------------------
26 typedef bool (*LGadMenuCallback
)(int which_sel
,LGadMenu
*vm
);
27 /* When a menu item is chosen, the callback is called with the data of which item was chosen. Returns
28 TRUE if the selection was valid and the menu should be destroyed, otherwise FALSE. */
30 typedef bool (*LGadMenuRedraw
)(short x
, short y
, short w
, short h
);
31 /* After the menu goes away, it wants to restore some information underneath it. This callback gets called
32 when the menu goes away, with the dimensions of the LGadMenu so that the right thing can get done. */
34 //------------------------------------------------------------
35 // STRUCTURE DEFINITION
44 LGadMenuCallback vmenuc;\
45 LGadMenuRedraw vmredraw;\
48 grs_bitmap saveunder;\
58 //------------------------------------------------------------
62 #define LGadMenuNumElems(m) (((LGadMenu*)m)->num_elems )
63 #define LGadMenuVisibleElems(m) (((LGadMenu*)m)->vis_elems )
64 #define LGadMenuDrawElem(m,i) (&((LGadMenu*)m->elems[i] ))
65 #define LGadMenuFlags(m) (((LGadMenu*)m)->flags )
66 #define LGadMenuCallback(m) (((LGadMenu*)m)->vmenuc )
67 #define LGadMenuRedrawCall(m) (((LGadMenu*)m)->vmredraw )
68 #define LGadMenuCurrentSelection(m) (((LGadMenu*)m)->cur_sel )
70 #define LGadMenuSaveUnder(m) (&((LGadMenu*)m)->saveunder)
73 #define LGadMenuSetNumElems(m,v) (((LGadMenu*)m)->num_elems = (v))
74 #define LGadMenuSetVisibleElems(m,v) (((LGadMenu*)m)->vis_elems = (v))
75 #define LGadMenuSetDrawElem(m,i,v) (&((LGadMenu*)m)->elems[i] = *(v))
76 #define LGadMenuSetFlags(m,v) (((LGadMenu*)m)->flags = (v))
77 #define LGadMenuSetCallback(m,v) (((LGadMenu*)m)->vmenuc = (v))
78 #define LGadMenuSetRedrawCall(m,v) (((LGadMenu*)m)->vmredraw = (v))
79 #define LGadMenuSetCurrentSelection(m,v) (((LGadMenu*)m)->cur_sel = (v))
81 //------------------------------------------------------------
85 // These flags are for user configuration of the menu
86 #define MENU_TRANSIENT 0x001 // menu goes away if mouse leaves box
87 #define MENU_ALLOC_ELEMS 0x002 // allocate local copy of elems and copy in info
88 #define MENU_GRAB_FOCUS 0x004 // grab all input focus while up
89 #define MENU_HORIZONTAL 0x008 // orient it horizontally, duh
90 #define MENU_MOUSEDOWNS 0x010 // are we interested in mouse down events?
91 #define MENU_SCROLLBAR 0x020 // add a scrollbar on the left/top
92 #define MENU_MOVEKEYS 0x040 // respond to the "standard" key sets for manipulation
93 #define MENU_ESC 0x080 // respond to ESC for termination
94 #define MENU_OUTER_DISMISS 0x100 // destroy if clicks out of region when not tracking
95 #define MENU_SELBOX 0x200 // selection box around current item
96 #define MENU_NOAUTODRAW 0x400 // do not automatically draw on creation
98 #define MENU_STDKEYS (MENU_ESC|MENU_MOVEKEYS)
100 // This is some selection-specific information flags
101 #define MENU_SELINFO_LUP 0x01
102 #define MENU_SELINFO_RUP 0x02
103 #define MENU_SELINFO_LDN 0x04
104 #define MENU_SELINFO_RDN 0x08
110 // These flags are secretly used by the menu itself
111 #define MENU_ALLOC_BASE 0x010000 // did we allocate the basic memory ourselves?
112 #define MENU_SCROLLBARS_USED 0x020000 // did we actually make scrollbuttons?
113 #define MENU_SAVEUNDER_DISABLE 0x040000 // the menu has decided to disable saveunders, typically because of
114 // rendered area overlap
115 #define MENU_SAVEUNDER_TAKEN 0x080000 // have we grabbed a saveunder yet?
116 #define MENU_SCROLL_TRACK 0x100000 // are we currently tracking mouse motion for scrollbars
118 //------------------------------------------------------------
119 // MENU GADGET FUNCTIONS
123 // Creation/Destruction
126 EXTERN LGadMenu
*LGadCreateMenu(LGadMenu
*vm
, LGadRoot
*vr
, short x
, short y
, short w
, short h
, char paltype
);
127 EXTERN LGadMenu
*LGadCreateMenuArgs(LGadMenu
*vm
, LGadRoot
*vr
, short x
, short y
, short w
,
128 short h
, short num_elems
, short vis_elems
, DrawElement
*elems
, LGadMenuCallback vmc
,
129 LGadMenuRedraw vmredraw
, ushort flags
, ushort draw_flags
, DrawElement
*inner
, char paltype
);
130 EXTERN
int LGadDestroyMenu(LGadMenu
*vm
);
132 // Change the "focus" (first visible element) of the menu
133 EXTERN
int LGadFocusMenu(LGadMenu
*vm
, int new_f
);
135 // Compute the size of a menu
136 EXTERN
void LGadMenuComputeSize(short *w
, short *h
, short num_elems
, short vis_elems
, uint flags
,
137 DrawElement
*elems
, uint draw_flags
, short extra_w
, short extra_h
);
139 ////////////////////////////////////////////////////////////
142 // An edit menu is an array of editable fields. Each field edits a different variable.
145 //------------------------------------------------------------
146 // VARELEM DEFINITION
149 // A VarElem is a description of a variable, combined with all the state necessary to edit it.
150 #define VARELEM_STRING_LEN 64
153 void *vdata
; // the variable being edited
154 char vtype
; // the type of the variable (see below)
155 uchar flags
; // some flags
157 char edit
[VARELEM_STRING_LEN
];
160 //------------------------------------------------------------
164 #define EDITTYPE_INT 0
165 #define EDITTYPE_SHORT 1
166 #define EDITTYPE_CHAR 2
167 #define EDITTYPE_STRING 3
168 #define EDITTYPE_FIX 4
169 #define EDITTYPE_FLOAT 5
170 /* These 4 all interpret the vdata pointer as a pointer to that specific kind of data type. */
171 #define EDITTYPE_CALLBACK 6
172 /* This vartype will just make a button in the editable area when can be pushed to trigger the
173 callback. The vdata will be interpreted as a LGadButtonCallback. */
174 #define EDITTYPE_CLOSE 7
175 /* Really a special case of EDITTYPE_CALLBACK. Makes a "close" button which when pressed will
176 go process all the text in the various edit boxes and interpret them, storing the final values
177 into the vdata for that VarElem. The menu is then destroyed. */
178 #define EDITTYPE_CANCEL 8
179 /* A button that is like EDITTYPE_CLOSE but it doesn't process any of the edit information, just
180 terminates the menu without affecting the vdata variables. */
181 #define EDITTYPE_APPLY 9
182 /* like EDITTYPE_CLOSE but doesn't actually destroy it (just reprocesses the
184 #define EDITTYPE_TOGGLE 10
185 // when clicked, will cycle through values and pass those off to the drawelement with the value of the
186 // variable passed off to the drawelem as draw_data2. This is most useful with
187 // DRAWTYPE_VARRES and DRAWTYPE_VARSTRING. Note that vdata actually points to an EditToggleInfo struct!!
189 // Note that for EDITTYPE_CLOSE, CANCEL, and APPLY, a non-NULL vdata is interpreted as like
190 // EDITTYPE_CALLBACK.
198 //------------------------------------------------------------
202 #define EDITFLAG_NORMAL 0
204 #define EDITFLAG_HEX 0x01
205 #define EDITFLAG_OCTAL 0x02
206 #define EDITFLAG_BINARY 0x04
207 #define EDITFLAG_READONLY 0x08
208 #define EDITFLAG_UNSIGNED 0x10
209 #define EDITFLAG_INITCLEAR 0x20
210 #define EDITFLAG_PRISTINE 0x40
212 //------------------------------------------------------------
213 // EDIT MENU STRUCTURE DEFINITION
221 //------------------------------------------------------------
225 #define LGadEditMenuNumElems(m) LGadMenuNumElems(m)
226 #define LGadEditMenuVisibleElems(m) LGadMenuVisibleElems(m)
227 #define LGadEditMenuDrawElem(m,i) LGadMenuDrawElem(m,i)
228 #define LGadEditMenuFlags(m) LGadMenuFlags(m)
229 #define LGadEditMenuCallback(m) LGadMenuCallback(m)
230 #define LGadEditMenuRedrawCall(m) LGadMenuRedrawCall(m)
231 #define LGadEditMenuCurrentSelection(m) LGadMenuCurrentSelection(m)
233 #define LGadEditMenuVarElem(m,i) (&((LGadEditMenu*)m)->varlist[i])
236 #define LGadEditMenuSaveUnder(m) LGadMenuSaveUnder(m)
239 #define LGadEditMenuSetNumElems(m,v) LGadMenuSetNumElems(m,v)
240 #define LGadEditMenuSetVisibleElems(m,v) LGadMenuSetVisibleElems(m,v)
241 #define LGadEditMenuSetDrawElem(m,i,v) LGadMenuSetDrawElem(m,i,v)
242 #define LGadEditMenuSetFlags(m,v) LGadMenuSetFlags(m,v)
243 #define LGadEditMenuSetCallback(m,v) LGadMenuSetCallback(m,v)
244 #define LGadEditMenuSetRedrawCall(m,v) LGadMenuSetRedrawCall(m,v)
245 #define LGadEditMenuSetCurrentSelection(m,v) LGadMenuSetCurrentSelection(m,v)
247 //------------------------------------------------------------
248 // EDIT MENU FUNCTIONS
255 EXTERN LGadEditMenu
*LGadCreateEditMenuArgs(LGadEditMenu
*vm
, LGadRoot
*vr
, short x
, short y
, short w
,
256 short h
, short num_elems
, short vis_elems
, DrawElement
*elems
, ushort flags
, ushort draw_flags
,
257 DrawElement
*inner
, VarElem
*varlist
, char paltype
);
258 EXTERN LGadEditMenu
*LGadCreateEditMenu(LGadEditMenu
*vm
, LGadRoot
*vr
, short x
, short y
, short w
, short h
, char paltype
);
260 // Force an editmenu's variables to update
261 EXTERN
void LGadEditMenuProcess(LGadEditMenu
*vem
);
263 // Set the text fields for a menu from the data
264 EXTERN
void LGadEditMenuSetText(LGadEditMenu
*vm
);
266 #endif // __GADMENU_H