Update documentation after 0.1.1 release
[clnl] / docs / DocsGltk.md
1 # Package CLNL-GLTK
2
3 Main clnl-gltk package.
4
5 Use widgets available in clnl-gltk to create NetLogo user interface widgets in pure opengl.  This project doesn't have much usefulness outside of CLNL.
6
7 ## Contents
8
9 * **variable [\*font\-height\*](#variable-font-height)** - The height of the font used by CLNL-GLTK.
10 * **variable [\*font\-width\*](#variable-font-width)** - The width of the font used by CLNL-GLTK.
11 * **variable [\*slider\-height\*](#variable-slider-height)** - The default slider height.
12 * **variable [\*switch\-height\*](#variable-switch-height)** - The default switch height.
13 * **function [button](#function-button)** - _button_ creates a button widget.
14 * **function [clear](#function-clear)** - Rests the inputbox _ib_ to empty.
15 * **function [font-print](#function-font-print)** - _font-print_ prints _str_ to the screen.
16 * **function [inputbox](#function-inputbox)** - _inputbox_ creates an inputbox widget.
17 * **function [key-pressed](#function-key-pressed)** - _key-pressed_ will do the appropriate thing in the case of a key being pressed.
18 * **function [mousedown](#function-mousedown)** - _mousedown_ is the general purpose mousedown entry point for all widgets.  It is used to alert widgets that a mouse button has been pressed, and where. There's no information on which button has been pressed.
19 * **function [mousemove](#function-mousemove)** - _mousemove_ is the general purpose mousemove entry point for all widgets.  It is used to alert widgets to movements of the mouse, regardless of button state.
20 * **function [mouseup](#function-mouseup)** - _mouseup_ is the general purpose mouseup entry point for all widgets.  It is used to alert widgets to that a mouse button has been released, and where. There's no information on which button has been released, and it is up to the widget to decide if a click was triggered.
21 * **function [render](#function-render)** - _render_ is the entry point for rendering different items in the CLNL-GLTK package.
22 * **function [reposition](#function-reposition)** - _reposition_ is the general purpose resizing entry point for all widgets.
23 * **function [resize](#function-resize)** - _resize_ is the general purpose resizing entry point for all widgets.
24 * **function [setup](#function-setup)** - _setup_ sets up the clnl-gltk system, calling all the necessary underlying functions.
25 * **function [slider](#function-slider)** - _slider_ creates a button widget.
26 * **function [switch](#function-switch)** - _switch_ creates a switch widget.
27 * **function [textbox](#function-textbox)** - _textbox_ creates a textbox widget.
28 * **function [textbox-text](#function-textbox-text)** - _textbox-text_ allows for the retrieving and setting of the internal text of textbox _tb_.
29 * **function [toggle](#function-toggle)** - _toggle_ toggles an _item_.
30 * **function [value](#function-value)** - Returns the _text_ that currently resides in the inputbox _ib_.
31
32 ## Variable \*FONT\-HEIGHT\*
33
34 #### Value Type:
35
36 an integer
37
38 #### Initial Value:
39
40 14
41
42 #### Description:
43
44 The height of the font used by CLNL-GLTK.
45
46 This can be used to calculate appropriate sizes of things that may have fonts displayed in them.
47
48 ## Variable \*FONT\-WIDTH\*
49
50 #### Value Type:
51
52 an integer
53
54 #### Initial Value:
55
56 7.
57
58 #### Description:
59
60 The width of the font used by CLNL-GLTK.
61
62 This can be used to calculate appropriate sizes of things that may have fonts displayed in them.
63
64 ## Variable \*SLIDER\-HEIGHT\*
65
66 #### Value Type:
67
68 an integer
69
70 #### Initial Value:
71
72 33
73
74 #### Description:
75
76 The default slider height.
77
78 ## Variable \*SWITCH\-HEIGHT\*
79
80 #### Value Type:
81
82 an integer
83
84 #### Initial Value:
85
86 33
87
88 #### Description:
89
90 The default switch height.
91
92 ## Function **BUTTON**
93
94 #### Syntax:
95
96 **button** _x_ _y_ _width_ _height_ _text_ _callback_ _&key_ _forever_ => _button_
97
98 #### Arguments and Values:
99
100 _x_---x offset, in pixels  
101 _y_---y offset, in pixels  
102 _width_---width, in pixels  
103 _height_---height, in pixels  
104 _text_---string for the textual display  
105 _callback_---a function  
106 _forever_---a boolean, including whether this button is a forever button  
107 _button_---a button that can later be rendered  
108
109 #### Description:
110
111 _button_ creates a button widget.
112
113 The widget will center the viewable TE_x_T inside itself, replacing the last three characters with an ellipses if the text is too large for the given dimensions.  It will never clip a character.
114
115 _button_ objects also work with mouse movement functions.  When it identifies that a click has happened, _callback_ will be called.
116
117 When _forever_ is non NIL, an extra icon is added to the button.
118
119 ## Function **CLEAR**
120
121 #### Syntax:
122
123 **clear** _ib_ => _result_
124
125 #### Arguments and Values:
126
127 _ib_---an inputbox  
128 _result_---undefined  
129
130 #### Description:
131
132 Rests the inputbox _ib_ to empty.
133
134 ## Function **FONT-PRINT**
135
136 #### Syntax:
137
138 **font-print** _str_ => _result_
139
140 #### Arguments and Values:
141
142 _str_---a string to be printed to screen  
143 _result_---undefined  
144
145 #### Description:
146
147 _font-print_ prints _str_ to the screen.
148
149 It affirms no assumptions that are required for it to run, in the interest of speed.  Those assumptions include that an opengl window has been opened, that all matrices are correct, and that SETUP-FONT has been run.
150
151 #### Examples:
152
153 ```(font-print #P"Hello World" t)``` => ```nil```  
154
155 ## Function **INPUTBOX**
156
157 #### Syntax:
158
159 **inputbox** _x_ _y_ _width_ => _ib_
160
161 #### Arguments and Values:
162
163 _x_---x offset, in pixels  
164 _y_---y offset, in pixels  
165 _width_---width, in characters  
166 _ib_---an inputbox that can later be rendered  
167
168 #### Description:
169
170 _inputbox_ creates an inputbox widget.
171
172 The inputbox is a simple, single lined, box that can hold a mutating string. Use the various _inputbox_-* functions to add to it and modify it.  As a string is added to it that is too large, it will scroll the characters automatically.
173
174 The widget is defined in terms of characters, rather than pixels.  In this way, it will never clip a portion of a character off.
175
176 ## Function **KEY-PRESSED**
177
178 #### Syntax:
179
180 **key-pressed** _ib_ _key_ => _result_
181
182 #### Arguments and Values:
183
184 _ib_---An inputbox  
185 _key_---Key pressed, an integer or a symbol  
186 _result_---Undefined  
187
188 #### Description:
189
190 _key-pressed_ will do the appropriate thing in the case of a key being pressed.
191
192 When an integer, will insert the text into the appropriate location, if it's an ascii character less than 256.
193
194 The other values acceptable are:
195
196 :key-left moves the cursor one to the left :key-right moves the cursor one to the right
197
198 ## Function **MOUSEDOWN**
199
200 #### Syntax:
201
202 **mousedown** _item_ _x_ _y_ => _result_
203
204 #### Arguments and Values:
205
206 _item_---item handling event  
207 _x_---an integer  
208 _y_---an integer  
209 _result_---undefined  
210
211 #### Description:
212
213 _mousedown_ is the general purpose mousedown entry point for all widgets.  It is used to alert widgets that a mouse button has been pressed, and where. There's no information on which button has been pressed.
214
215 _x_ and _y_ are absolute coordinates, and assumed to be opengl coordinates, not window coordinates (meaning they match the render and setup functions of widgets).
216
217 A catchall method that does nothing is also defined so that mouse functions can loop over all available widgets and let them decide what they want to do.
218
219 ## Function **MOUSEMOVE**
220
221 #### Syntax:
222
223 **mousemove** _item_ _x_ _y_ => _result_
224
225 #### Arguments and Values:
226
227 _item_---item handling event  
228 _x_---an integer  
229 _y_---an integer  
230 _result_---undefined  
231
232 #### Description:
233
234 _mousemove_ is the general purpose mousemove entry point for all widgets.  It is used to alert widgets to movements of the mouse, regardless of button state.
235
236 _x_ and _y_ are absolute coordinates, and assumed to be opengl coordinates, not window coordinates (meaning they match the render and setup functions of widgets).
237
238 A catchall method that does nothing is also defined so that mouse functions can loop over all available widgets and let them decide what they want to do.
239
240 ## Function **MOUSEUP**
241
242 #### Syntax:
243
244 **mouseup** _item_ _x_ _y_ => _result_
245
246 #### Arguments and Values:
247
248 _item_---item handling event  
249 _x_---an integer  
250 _y_---an integer  
251 _result_---undefined  
252
253 #### Description:
254
255 _mouseup_ is the general purpose mouseup entry point for all widgets.  It is used to alert widgets to that a mouse button has been released, and where. There's no information on which button has been released, and it is up to the widget to decide if a click was triggered.
256
257 _x_ and _y_ are absolute coordinates, and assumed to be opengl coordinates, not window coordinates (meaning they match the render and setup functions of widgets).
258
259 A catchall method that does nothing is also defined so that mouse functions can loop over all available widgets and let them decide what they want to do.
260
261 ## Function **RENDER**
262
263 #### Syntax:
264
265 **render** _item_ => _result_
266
267 #### Arguments and Values:
268
269 _item_---item to be rendered  
270 _result_---undefined  
271
272 #### Description:
273
274 _render_ is the entry point for rendering different items in the CLNL-GLTK package.
275
276 _render_ will return the opengl world to the way it found it after finishing, usually via just popping the matrix.
277
278 ## Function **REPOSITION**
279
280 #### Syntax:
281
282 **reposition** _item_ _x_ _y_ => _result_
283
284 #### Arguments and Values:
285
286 _item_---item to be rendered  
287 _x_---an integer  
288 _y_---an integer  
289 _result_---undefined  
290
291 #### Description:
292
293 _reposition_ is the general purpose resizing entry point for all widgets.
294
295 _x_ and _y_ are contextual to the actual item being repositioned, and may be even be ignored.
296
297 ## Function **RESIZE**
298
299 #### Syntax:
300
301 **resize** _item_ _width_ _height_ => _result_
302
303 #### Arguments and Values:
304
305 _item_---item to be rendered  
306 _width_---an integer  
307 _height_---an integer  
308 _result_---undefined  
309
310 #### Description:
311
312 _resize_ is the general purpose resizing entry point for all widgets.
313
314 _width_ and _height_ are contextual to the actual item being resized, and may be even be ignored.
315
316 ## Function **SETUP**
317
318 #### Syntax:
319
320 **setup** => _result_
321
322 #### Arguments and Values:
323
324 _result_---undefined  
325
326 #### Description:
327
328 _setup_ sets up the clnl-gltk system, calling all the necessary underlying functions.
329
330 Calling before the opengl system has been initialized properly may or may not work, so calling it after everything else has been initialized is recommended.
331
332 ## Function **SLIDER**
333
334 #### Syntax:
335
336 **slider** _x_ _y_ _width_ _text_ _callback_ _min_ _max_ _increment_ _value_ => _slider_
337
338 #### Arguments and Values:
339
340 _x_---x offset, in pixels  
341 _y_---y offset, in pixels  
342 _width_---width, in pixels  
343 _text_---string for the textual display  
344 _callback_---a function  
345 _min_---minimum value  
346 _max_---maximum value  
347 _increment_---increment when moving the slider  
348 _value_---inital value  
349 _slider_---a slider that can later be rendered  
350
351 #### Description:
352
353 _slider_ creates a button widget.
354
355 TODO: The rest of this description needs to be updated!
356
357 ## Function **SWITCH**
358
359 #### Syntax:
360
361 **switch** _x_ _y_ _width_ _text_ _callback_ _&optional_ _initial-state_ => _switch_
362
363 #### Arguments and Values:
364
365 _x_---x offset, in pixels  
366 _y_---y offset, in pixels  
367 _width_---width, in pixels  
368 _text_---string for the textual display  
369 _callback_---a function  
370 _initial-state_---a boolean, defaulting to nil  
371 _switch_---a switch that can later be rendered  
372
373 #### Description:
374
375 _switch_ creates a switch widget.
376
377 The widget will center the viewable TE_x_T inside itself, replacing the last three characters with an ellipses if the text is too large for the given dimensions.  It will never clip a character.
378
379 _switch_ objects also work with mouse movement functions.  When it identifies that a mousedown has happened, the state of the _switch_ will be changed, and _callback_ will be called with the new state.
380
381 The _initial-state_ defines whether the switch starts on or off.
382
383 ## Function **TEXTBOX**
384
385 #### Syntax:
386
387 **textbox** _x_ _y_ _width_ _height_ _&key_ _text_ _border_ _word-wrap_ => _tb_
388
389 #### Arguments and Values:
390
391 _x_---x offset, in pixels  
392 _y_---y offset, in pixels  
393 _width_---width, in characters  
394 _height_---height, in characters  
395 _text_---optional string for the textual display  
396 _border_---boolean, whether we draw a border, defaults to t  
397 _word-wrap_---boolean, whether we attempt to wrap the text  
398 _tb_---a textbox that can later be rendered  
399
400 #### Description:
401
402 _textbox_ creates a textbox widget.
403
404 The widget is defined in terms of characters, rather than pixels.  In this way, it will never clip a portion of a character off.  It will also display whatever it can of its text, clipping off characters that are outside.
405
406 Multiline strings are supported, and each one appears on a new line.
407
408 When _border_ is NIL, no border is drawn and the text box floats, which can be useful for labels.
409
410 When _word-wrap_ is non NIL, the text is attempted to wrap by the following rules. The wrapping is done at the line if possible, at a breaking character if possible, or just fits as many letters as it can befoer wrapping.  It then only clips off on the bottom.  The only breaking character currently is #Space.
411
412 ## Function **TEXTBOX-TEXT**
413
414 #### Syntax:
415
416 **textbox-text** _tb_ => _text_
417
418 #### Arguments and Values:
419
420 _tb_---a textbox  
421 _text_---string currently being displayed  
422
423 #### Description:
424
425 _textbox-text_ allows for the retrieving and setting of the internal text of textbox _tb_.
426
427 ## Function **TOGGLE**
428
429 #### Syntax:
430
431 **toggle** _item_ _&optional_ _state_ => _new-state_
432
433 #### Arguments and Values:
434
435 _item_---an item  
436 _state_---a boolean, the state to set to  
437 _new-state_---a boolean, the state after being set  
438
439 #### Description:
440
441 _toggle_ toggles an _item_.
442
443 Inverts the current toggle status of the _item_ if no _state_ passed in, otherwise sets to _state_.
444
445 ## Function **VALUE**
446
447 #### Syntax:
448
449 **value** _ib_ => _text_
450
451 #### Arguments and Values:
452
453 _ib_---an inputbox  
454 _text_---a string, the text currently in _ib_  
455
456 #### Description:
457
458 Returns the _text_ that currently resides in the inputbox _ib_.