All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class org.ifarchive.glk.Glk

java.lang.Object
   |
   +----org.ifarchive.glk.Glk

public class Glk
extends Object
The Glk class contains static functions wrapping non-OO Glk functions.


Variable Index

 o gestalt_CharInput
Test if a character can be input in character input.
 o gestalt_CharOutput
Test if a character can be output.
 o gestalt_CharOutput_ApproxPrint
Character may not look right.
 o gestalt_CharOutput_CannotPrint
Character cannot be meaningfully printed.
 o gestalt_CharOutput_ExactPrint
Character will be printed exactly as defined.
 o gestalt_DrawImage
Test if images can be drawn in a particular window type.
 o gestalt_Graphics
Test if graphics functions are supported.
 o gestalt_GraphicsTransparency
Test if alpha channels are supported in images.
 o gestalt_HyperlinkInput
Test if a window type allows hyperlinks.
 o gestalt_Hyperlinks
Test if hyperlink functions are supported.
 o gestalt_LineInput
Test if a character can be input in line input.
 o gestalt_MouseInput
Test if mouse input is supported in a window type.
 o gestalt_Sound
Test if sound functions are supported.
 o gestalt_SoundMusic
Test if the library supports music sound resources.
 o gestalt_SoundNotify
Test if the library supports sound notification events.
 o gestalt_SoundVolume
Test if the volume can be set for sound channels.
 o gestalt_Timer
Test if timer events are supported.
 o gestalt_Version
Return the Glk version supported by the library.
 o keycode_Delete
This code is returned by the Delete and Backspace keys.
 o keycode_Down
This code is returned by the cursor down key.
 o keycode_End
This code is returned by the End key.
 o keycode_Escape
This code is returned by the Escape key.
 o keycode_Func1
This code is returned by the F1 key.
 o keycode_Func10
This code is returned by the F10 key.
 o keycode_Func11
This code is returned by the F11 key.
 o keycode_Func12
This code is returned by the F12 key.
 o keycode_Func2
This code is returned by the F2 key.
 o keycode_Func3
This code is returned by the F3 key.
 o keycode_Func4
This code is returned by the F4 key.
 o keycode_Func5
This code is returned by the F5 key.
 o keycode_Func6
This code is returned by the F6 key.
 o keycode_Func7
This code is returned by the F7 key.
 o keycode_Func8
This code is returned by the F8 key.
 o keycode_Func9
This code is returned by the F9 key.
 o keycode_Home
This code is returned by the Home key.
 o keycode_Left
This code is returned by the cursor left key.
 o keycode_MAXVAL
This is the number of keycode_* constants.
 o keycode_PageDown
This code is returned by the PageDown key.
 o keycode_PageUp
This code is returned by the PageUp key.
 o keycode_Return
This code is returned by the Enter / Return key.
 o keycode_Right
This code is returned by the cursor right key.
 o keycode_Tab
This code is returned by the Tab key.
 o keycode_Unknown
This code is returned if a key was pressed for which there is no Glk representation.
 o keycode_Up
This code is returned by the cursor up key.

Method Index

 o charToLower(char)
Convert a character to lower case
 o charToUpper(char)
Convert a character to upper case
 o dispatchCall(int, Object[])
Dispatch interface.
 o dispatchCall(int, UniversalUnion[])
Dispatch interface (C-style version).
 o exit()
Terminate immediately.
 o gestalt(long)
Request information about the capabilities of the API.
 o gestalt(long, long)
Request information about the capabilities of the API.
 o gestalt(long, long, long[])
Request information about the capabilities of the API.
 o getStream()
Set the current output stream.
 o glkMain()
A default main() in case jniglk wasn't told what class to load
 o putBuffer(char[])
Write a character array to the currently selected stream.
 o putBuffer(char[], int, int)
Write part of a character array to the currently selected stream.
 o putChar(char)
Write a character to the currently selected stream.
 o putString(String)
Write a string to the currently selected stream.
 o requestTimerEvents(long)
Ask Glk to start sending timer events.
 o select(Event)
Wait for an event and return it.
 o selectPoll(Event)
Check for an internally spawned event.
 o setArrayRegistry(ArrayRegistry)
Set a retained array registry.
 o setHyperlink(int)
Set the current hyperlink value in the current output stream.
 o setInterruptHandler(InterruptListener)
Set an interrupt handler.
 o setStream(Stream)
Set the current output stream.
 o setStyle(int)
Set output style for the currently selected stream.
 o setWindow(Window)
Set the current stream to a window stream.
 o stringToLower(String)
Convert a string to lower case
 o stringToUpper(String)
Convert a string to upper case
 o styleDistinguish(Window, int, int)
Are two styles visually distinguishable?
 o styleHintClear(int, int, int)
Unset a stylehint for a window class.
 o styleHintSet(int, int, int, int)
Set a stylehint for a window class.
 o styleMeasure(Window, int, int, int[])
Test an attribute of a style in the given window.
 o tick()
Allow the underlying GLK library to yield if necessary.

Variables

 o gestalt_Version
 public static final int gestalt_Version
Return the Glk version supported by the library.

 o gestalt_CharInput
 public static final int gestalt_CharInput
Test if a character can be input in character input.

Pass the character as the second parameter to the gestalt() call.

Returns 1 if the character can be input, 0 if not.

 o gestalt_LineInput
 public static final int gestalt_LineInput
Test if a character can be input in line input.

Pass the character as the second parameter to the gestalt() call.

Returns 1 if the character can be input, 0 if not.

 o gestalt_CharOutput
 public static final int gestalt_CharOutput
Test if a character can be output.

Pass the character as the second parameter to the gestalt() call.

Pass an array with one entry to get the number of screen cells this character will take up when printed.

Returns one of gestalt_CharOutput_CannotPrint, gestalt_CharOutput_ApproxPrint, gestalt_CharOutput_ExactPrint

 o gestalt_CharOutput_CannotPrint
 public static final int gestalt_CharOutput_CannotPrint
Character cannot be meaningfully printed.

See Also:
gestalt_CharOutput
 o gestalt_CharOutput_ApproxPrint
 public static final int gestalt_CharOutput_ApproxPrint
Character may not look right. For example, "ae" may be used for the one-character "ae" ligature, or "e" for an accented "e".

See Also:
gestalt_CharOutput
 o gestalt_CharOutput_ExactPrint
 public static final int gestalt_CharOutput_ExactPrint
Character will be printed exactly as defined.

See Also:
gestalt_CharOutput
 o gestalt_MouseInput
 public static final int gestalt_MouseInput
Test if mouse input is supported in a window type.

Pass the window type as the second parameter to the gestalt() call.

Returns 1 if mouse input is possible, 0 if not.

 o gestalt_Timer
 public static final int gestalt_Timer
Test if timer events are supported.

Returns 1 if they are, 0 if not.

 o gestalt_Graphics
 public static final int gestalt_Graphics
Test if graphics functions are supported.

Returns 1 if they are, 0 if not.

 o gestalt_DrawImage
 public static final int gestalt_DrawImage
Test if images can be drawn in a particular window type.

Pass the window type as the second parameter to the gestalt() call.

Returns 1 if the window supports images, 0 if not.

 o gestalt_Sound
 public static final int gestalt_Sound
Test if sound functions are supported.

Returns 1 if they are, 0 if not.

 o gestalt_SoundVolume
 public static final int gestalt_SoundVolume
Test if the volume can be set for sound channels.

Returns 1 if it can, 0 if not.

 o gestalt_SoundNotify
 public static final int gestalt_SoundNotify
Test if the library supports sound notification events.

Returns 1 if it does, 0 if not.

 o gestalt_Hyperlinks
 public static final int gestalt_Hyperlinks
Test if hyperlink functions are supported.

Returns 1 if they are, 0 if not.

 o gestalt_HyperlinkInput
 public static final int gestalt_HyperlinkInput
Test if a window type allows hyperlinks.

Pass the window type as the second parameter to the gestalt() call.

Returns 1 if the window allows hyperlinks, 0 if not.

 o gestalt_SoundMusic
 public static final int gestalt_SoundMusic
Test if the library supports music sound resources.

Returns 1 if it does, 0 if not.

 o gestalt_GraphicsTransparency
 public static final int gestalt_GraphicsTransparency
Test if alpha channels are supported in images.

Returns 1 if they are, 0 if not.

 o keycode_Unknown
 public static final int keycode_Unknown
This code is returned if a key was pressed for which there is no Glk representation.

 o keycode_Left
 public static final int keycode_Left
This code is returned by the cursor left key.

 o keycode_Right
 public static final int keycode_Right
This code is returned by the cursor right key.

 o keycode_Up
 public static final int keycode_Up
This code is returned by the cursor up key.

 o keycode_Down
 public static final int keycode_Down
This code is returned by the cursor down key.

 o keycode_Return
 public static final int keycode_Return
This code is returned by the Enter / Return key.

 o keycode_Delete
 public static final int keycode_Delete
This code is returned by the Delete and Backspace keys.

 o keycode_Escape
 public static final int keycode_Escape
This code is returned by the Escape key.

 o keycode_Tab
 public static final int keycode_Tab
This code is returned by the Tab key.

 o keycode_PageUp
 public static final int keycode_PageUp
This code is returned by the PageUp key.

 o keycode_PageDown
 public static final int keycode_PageDown
This code is returned by the PageDown key.

 o keycode_Home
 public static final int keycode_Home
This code is returned by the Home key.

 o keycode_End
 public static final int keycode_End
This code is returned by the End key.

 o keycode_Func1
 public static final int keycode_Func1
This code is returned by the F1 key.

 o keycode_Func2
 public static final int keycode_Func2
This code is returned by the F2 key.

 o keycode_Func3
 public static final int keycode_Func3
This code is returned by the F3 key.

 o keycode_Func4
 public static final int keycode_Func4
This code is returned by the F4 key.

 o keycode_Func5
 public static final int keycode_Func5
This code is returned by the F5 key.

 o keycode_Func6
 public static final int keycode_Func6
This code is returned by the F6 key.

 o keycode_Func7
 public static final int keycode_Func7
This code is returned by the F7 key.

 o keycode_Func8
 public static final int keycode_Func8
This code is returned by the F8 key.

 o keycode_Func9
 public static final int keycode_Func9
This code is returned by the F9 key.

 o keycode_Func10
 public static final int keycode_Func10
This code is returned by the F10 key.

 o keycode_Func11
 public static final int keycode_Func11
This code is returned by the F11 key.

 o keycode_Func12
 public static final int keycode_Func12
This code is returned by the F12 key.

 o keycode_MAXVAL
 public static final int keycode_MAXVAL
This is the number of keycode_* constants.

Methods

 o glkMain
 public static void glkMain()
A default main() in case jniglk wasn't told what class to load

 o exit
 public static void exit()
Terminate immediately. This function does not return.

 o setInterruptHandler
 public static void setInterruptHandler(InterruptListener i)
Set an interrupt handler.

Most platforms have some provision for interrupting a program -- command-period on the Macintosh, control-C in Unix, possibly a window manager menu item, or other possibilities. This can happen at any time, including while execution is nested inside one of your own functions, or inside a Glk library function.

If you need to clean up critical resources, you can specify an interrupt handler class - one that implements the InterruptListener interface.

Initially there is no interrupt handler. You can reset to not having any by calling setInterruptHandler(null).

If you call glk_set_interrupt_handler() with a new handler function while an older one is set, the new one replaces the old one. Glk does not try to queue interrupt handlers.

Parameters:
i - The interface that will be called if the process is interrupted.
See Also:
InterruptListener
 o tick
 public static void tick()
Allow the underlying GLK library to yield if necessary.

Many platforms have some annoying thing that has to be done every so often, or the gnurrs come from the voodvork out and eat your computer.

Well, not really. But you should call glk_tick() every so often, just in case. It may be necessary to yield time to other applications in a cooperative-multitasking OS, or to check for player interrupts in an infinite loop.

This call is fast; in fact, on average, it does nothing at all. So you can call it often.

 o gestalt
 public static long gestalt(long sel)
Request information about the capabilities of the API.

This is exactly the same as the two-parameter version of gestalt(), except that the second parameter is always 0.

Parameters:
sel - The capability you are asking about
Returns:
Information on the requested capability, or 0 if no information is available.
See Also:
gestalt
 o gestalt
 public static long gestalt(long sel,
                            long param)
Request information about the capabilities of the API.

Parameters:
sel - The capability you are asking about
value - Additional information on the parameter.
Returns:
Information on the requested capability, or 0 if no information is available.
 o gestalt
 public static long gestalt(long sel,
                            long param,
                            long arr[])
Request information about the capabilities of the API.

Parameters:
sel - The capability you are asking about
value - Additional information on the parameter.
arr - More values to pass if required.
Returns:
Information on the requested capability, or 0 if no information is available.
 o charToLower
 public static char charToLower(char c)
Convert a character to lower case

Parameters:
c - The character to convert
Returns:
The lowercase version, or (if c is not uppercase) c
 o charToUpper
 public static char charToUpper(char c)
Convert a character to upper case

Parameters:
c - The character to convert
Returns:
The uppercase version, or (if c is not lowercase) c
 o stringToLower
 public static String stringToLower(String s)
Convert a string to lower case

Parameters:
s - The string to convert
Returns:
The string with any uppercase characters converted to lower
 o stringToUpper
 public static String stringToUpper(String s)
Convert a string to upper case

Parameters:
s - The string to convert
Returns:
The string with any lowercase characters converted to upper
 o select
 public static void select(Event e)
Wait for an event and return it.

Parameters:
e - An Event which will be populated when this function returns
 o selectPoll
 public static void selectPoll(Event e)
Check for an internally spawned event.

The first question you now ask is, what is an internally-spawned event? selectPoll() does *not* check for or return evtype_CharInput, evtype_LineInput, or evtype_MouseInput events. It is intended for you to test conditions which may have occurred while you are computing, and not interfacing with the player. For example, time may pass during slow computations; you can use selectPoll() to see if a evtype_Timer event has occured.

At the moment, glk_select_poll() checks for evtype_Timer, and possibly evtype_Arrange and evtype_SoundNotify events.

Parameters:
e - An Event which will be populated when this function returns
 o requestTimerEvents
 public static void requestTimerEvents(long millisecs)
Ask Glk to start sending timer events. Timer events will be sent repeatedly until you call this method with millisecs = 0. Timer events can be missed if other events also arrive.

Parameters:
millisecs - Time spent between each event, 0 to cancel events.
 o setStream
 public static void setStream(Stream s)
Set the current output stream.

This doesn't gain you as much in Java as it does in C, because there are no global functions, so the difference in typing is between Glk.putChar() and myStream.putChar() as opposed to glk_put_char(c) and glk_put_char_stream(my_stream, c)

Parameters:
s - The stream to be used as the default for output. It can be null.
 o getStream
 public static Stream getStream()
Set the current output stream.

Returns:
The current output stream, or null if there is none.
See Also:
setStream
 o setWindow
 public static void setWindow(Window w)
Set the current stream to a window stream. This is exactly identical to setStream(w.getStream()).

Parameters:
w - The window whose stream will be used.
See Also:
setStream
 o putChar
 public static void putChar(char c)
Write a character to the currently selected stream.

Parameters:
c - The character to write
See Also:
setStream, putChar
 o putString
 public static void putString(String s)
Write a string to the currently selected stream.

Parameters:
s - The string to write
See Also:
setStream, putString
 o putBuffer
 public static void putBuffer(char c[])
Write a character array to the currently selected stream.

Parameters:
c - The character array to write
See Also:
setWindow, putBuffer
 o putBuffer
 public static void putBuffer(char c[],
                              int first,
                              int len)
Write part of a character array to the currently selected stream.

Parameters:
c - The character array to write
first - The first element to write
len - The number of elements to write
See Also:
setWindow, putBuffer
 o setStyle
 public static void setStyle(int style)
Set output style for the currently selected stream.

Parameters:
style - The style to select
See Also:
setWindow, setStyle
 o styleHintSet
 public static void styleHintSet(int wintype,
                                 int styl,
                                 int hint,
                                 int val)
Set a stylehint for a window class.

Parameters:
wintype - The type of window to set the hint for, or Window.wintype_AllTypes
style - The style to set (Stream.style_*)
hint - The stylehint selector (Stream.stylehint_*)
val - The new value of the hint.
 o styleHintClear
 public static void styleHintClear(int wintype,
                                   int styl,
                                   int hint)
Unset a stylehint for a window class.

Parameters:
wintype - The type of window to set the hint for, or Window.wintype_AllTypes
style - The style to set (Stream.style_*)
hint - The stylehint selector (Stream.stylehint_*)
 o styleDistinguish
 public static boolean styleDistinguish(Window w,
                                        int styl1,
                                        int styl2)
Are two styles visually distinguishable?

Parameters:
w - The window in which to check
styl1 - The first style (Stream.style_*)
styl2 - The second style (Stream.style_*)
Returns:
true if the two styles can be distinguished, otherwise false.
 o styleMeasure
 public static boolean styleMeasure(Window w,
                                    int styl,
                                    int hint,
                                    int result[])
Test an attribute of a style in the given window.

Parameters:
w - The window in which to check.
styl - The style to test (Stream.style_*).
hint - The hint to try and read (Stream.stylehint_*)
Returns:
true if the attribute could be determined, otherwise false.
 o dispatchCall
 public static void dispatchCall(int func,
                                 Object args[])
Dispatch interface.

In Java, the normal dispatch interface is a bit different from the one that the C library provides. Each argument corresponds exactly to one entry in the args[] array. Argument encoding works like this:

Here are two examples: calling glk_select():

 
	Event e = new Event();
	Object args[] = new Object[1];
	args[0] = new Reference(null);
 	Glk.dispatchCall(0x00C0, args);
	Object out[] = (Object[])( ((Reference)args[0]).target );
	ev.type   = (Number)(out[0]).intVal();
	ev.window = (Window)(out[1]);
	ev.val1   = (Number)(out[2]).longVal();
	ev.val2   = (Number)(out[3]).longVal();
 
and calling glk_put_buffer_stream:
	byte buf[64];
	...populate buf...
 	Object args[] = new Object[2];
	args[0] = myStream;
 	args[1] = buf;
	Glk.dispatchCall(0x0085, args);
 

An important note: Any Reference argument passed into a function won't necessarily come back referring to the same object. For example, if you did this for glk_select():

 
	Event e = new Event();
 	Object in[] = new Object[4];
	Object args[] = new Object[1];
	args[0] = new Reference(in);
 	Glk.dispatchCall(0x00C0, args);
	Object out[] = (Object[])( ((Reference)args[0]).target );
 
then the array in[] would not be the same as the array out[], and it would be out[] that was populated.

Parameters:
func - The Glk function ID
args - The argument list, in Java form.
 o dispatchCall
 public static void dispatchCall(int func,
                                 UniversalUnion uargs[])
Dispatch interface (C-style version).

This version of the Dispatch interface does no marshalling, so your calling code will have to do all the setting up of UniversalUnions (1 or 2 per reference, 1 or 3 per array, etc.)

The UniversalUnion documentation contains some examples of how to do this for various different types.

Parameters:
func - ID of Glk function to call.
uargs - Marshalled arguments.
See Also:
dispatchCall, UniversalUnion
 o setHyperlink
 public static void setHyperlink(int linkval)
Set the current hyperlink value in the current output stream. A link value is any non-zero integer; zero indicates no link. Subsequent text output is considered to make up the body of the link, which continues until the link value is changed (or set to zero).

Parameters:
linkval - The link value, 0 for no hyperlink.
 o setArrayRegistry
 public static void setArrayRegistry(ArrayRegistry r)
Set a retained array registry. It will be called when Glk retains or releases arrays.

Parameters:
r - An instance of your array registry.

All Packages  Class Hierarchy  This Package  Previous  Next  Index