Skip to content

Instantly share code, notes, and snippets.

@curiousdannii
Last active August 29, 2015 14:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save curiousdannii/ef113d8245941f0d89db to your computer and use it in GitHub Desktop.
Save curiousdannii/ef113d8245941f0d89db to your computer and use it in GitHub Desktop.
Cut down Flexible Windows for bug 0001511
Version 1/150127 of Flexible Windows (for Glulx only) by Dannii Willis begins here.
"Exposes the Glk windows system so authors can completely control the creation and use of windows"
[ Flexible Windows was originally by Jon Ingold, with many contributions by Erik Temple. This version has been essentially rewritten from scratch for 6L38 by Dannii Willis. ]
Use authorial modesty.
Include version 1/140512 of Alternative Startup Rules by Dannii Willis.
Include version 10/150124 of Glulx Entry Points by Emily Short.
Include version 5/140516 of Glulx Text Effects by Emily Short.
Part - Windows
Chapter - The g-window kind
[ g-windows must be a kind of container in order to use the containment relation as the spawning relation. Be careful if you iterate through all containers! ]
A g-window is a kind of container.
The specification of a g-window is "Models the Glk window system."
A g-window type is a kind of value.
The g-window types are g-text-buffer, g-text-grid and g-graphics.
The specification of a g-window type is "Glk windows are one of these three types."
A g-window has a g-window type called type.
Definition: a g-window is graphical rather than textual if the type of it is g-graphics.
A graphics g-window is a kind of g-window.
The type of a graphics g-window is g-graphics.
A text buffer g-window is a kind of g-window.
The type of a text buffer g-window is g-text-buffer.
A text grid g-window is a kind of g-window.
The type of a text grid g-window is g-text-grid.
A g-window position is a kind of value.
The g-window positions are g-placenull, g-placeleft, g-placeright, g-placeabove and g-placebelow.
The specification of a g-window position is "Specifies which direction a window will be split off from its parent window."
A g-window has a g-window position called position.
Definition: a g-window is vertically positioned rather than horizontally positioned if the position of it is at least g-placeabove.
A g-window scale method is a kind of value.
The g-window scale methods are g-proportional, g-fixed-size and g-using-minimum.
The specification of a g-window scale method is "Specifies how a new window will be split from its parent window."
A g-window has a g-window scale method called scale method.
A g-window has a number called measurement.
The measurement of a g-window is usually 40.
A g-window has a number called minimum size.
A g-window has a number called the rock.
A g-window has a number called ref number.
A g-window can be g-required or g-unrequired.
A g-window is usually g-unrequired.
A g-window can be g-present or g-unpresent.
A g-window is usually g-unpresent.
Chapter - The spawning relation
[ The most efficient relations use the object tree. Inform will only use the object tree for a few built in relations however, so we piggy back on to the containment relation. ]
The verb to spawn implies the containment relation.
The verb to be ancestral to implies the enclosure relation.
The verb to be descended from implies the reversed enclosure relation.
Chapter - The built-in windows
The main window is a text buffer g-window.
The status window is a text grid g-window spawned by the main window.
The position of the status window is g-placeabove.
The scale method of the status window is g-fixed-size.
The measurement of the status window is 1.
Use no status line translates as (- Constant USE_NO_STATUS_LINE 1; -).
Section - Open the built-in windows
The open the built-in windows using Flexible Windows rule is listed instead of the open built-in windows rule in the for starting the virtual machine rulebook.
This is the open the built-in windows using Flexible Windows rule:
if the main window is g-unpresent:
open the main window;
if the no status line option is active:
close the status window;
otherwise:
open the status window;
continue the activity;
Part - Variables and phrases to access the I6 template layer - unindexed
GG_MAINWIN_ROCK is a number variable.
GG_MAINWIN_ROCK variable translates into I6 as "GG_MAINWIN_ROCK".
GG_STATUSWIN_ROCK is a number variable.
GG_STATUSWIN_ROCK variable translates into I6 as "GG_STATUSWIN_ROCK".
gg_mainwin is a number variable.
The gg_mainwin variable translates into I6 as "gg_mainwin".
gg_statuswin is a number variable.
The gg_statuswin variable translates into I6 as "gg_statuswin".
[ We often wrap a phrase or rule around a core glk function, so that there is no good name to give to the actual function's phrase. So instead let's just define them using the I6 function's name here. This also means we can reduce the number of unindexed sections. ]
To call glk_set_window for (win - a g-window):
(- glk_set_window( {win}.(+ ref number +) ); -).
To call FW_glk_window_close for (ref - a number):
(- glk_window_close( {ref}, 0 ); -).
Section - And some phrases to find windows - unindexed
To decide which g-window is the invalid window:
(- ( nothing ) -).
To decide which g-window is the window with ref (ref - a number):
if ref is not 0:
repeat with win running through g-windows:
if the ref number of win is ref:
decide on win;
decide on the invalid window;
To decide which g-window is the window with rock (rock - a number):
if rock is not 0:
repeat with win running through g-windows:
if the rock of win is rock:
decide on win;
decide on the invalid window;
Part - The Flexible Windows API
Chapter - Opening and closing windows
To open up/-- (win - a g-window), as the acting main window:
if win is g-unpresent and (win is the main window or the main window is ancestral to win):
now win is g-required;
now every g-window ancestral to win is g-required;
calibrate windows;
To close (win - a g-window):
if win is g-present:
now win is g-unrequired;
now every g-window descended from win is g-unrequired;
calibrate windows;
Section - Calibrating windows - unindexed
A g-window can be currently being processed.
Definition: a g-window is paternal rather than childless if it spawns a g-present g-window.
Definition: a g-window is a next-step if it is the main window or it is spawned by something g-present.
To calibrate windows:
[ Close windows that shouldn't be open and then open windows that shouldn't be closed ]
while there is a not currently being processed g-unrequired g-present childless g-window (called win):
[ Only run each window once, even if we end up back in this loop (by open/close being called in a before rule), to prevent infinite loops ]
now win is currently being processed;
carry out the deconstructing activity with win;
now win is not currently being processed;
while there is a not currently being processed g-required g-unpresent next-step g-window (called win):
now win is currently being processed;
carry out the constructing activity with win;
now win is not currently being processed;
Section - Constructing a window
Constructing something is an activity on g-windows.
The construct a g-window rule is listed in the for constructing rules.
The construct a g-window rule translates into I6 as "FW_ConstructGWindow".
Include (-
[ FW_ConstructGWindow win parentwin method size type rock;
win = parameter_value;
! Fill in parentwin, method and size only if the window is not the main window
if ( win ~= (+ main window +) )
{
parentwin = parent( win ).(+ ref number +);
if ( win.(+ scale method +) == (+ g-proportional +) )
{
method = winmethod_Proportional;
}
else
{
method = winmethod_Fixed;
}
method = method + win.(+ position +) - 2;
if ( win.(+ scale method +) == (+ g-using-minimum +) )
{
size = win.(+ minimum size +);
}
else
{
size = win.(+ measurement +);
}
}
type = win.(+ type +) + 2;
rock = win.(+ rock +);
win.(+ ref number +) = glk_window_open( parentwin, method, size, type, rock );
rfalse;
];
-).
First after constructing a g-window (called win) (this is the check if the window was created rule):
if the ref number of win is zero:
now win is g-unrequired;
rule fails;
otherwise:
now win is g-present;
Section - Deconstructing windows
Deconstructing something is an activity on g-windows.
For deconstructing a g-window (called win) (this is the basic deconstruction rule):
say "basic deconstruction rule: [printed name of win] [ref number of win][line break]";
now win is g-unpresent;
call FW_glk_window_close for the ref number of win;
[if win is the main window:
open the file stream;]
say "basic deconstruction succeeded[line break]";
To open the file stream:
(-
gg_scriptfref = glk_fileref_create_by_name( fileusage_Transcript + fileusage_TextMode, Glulx_ChangeAnyToCString( "testlog" ), GG_SCRIPTFREF_ROCK );
gg_scriptstr = glk_stream_open_file( gg_scriptfref, filemode_WriteAppend, GG_SCRIPTSTR_ROCK );
!glk_window_set_echo_stream( glk_window_get_root(), gg_scriptstr );
glk_stream_set_current( gg_scriptstr );
-).
Chapter - Focus and changing the acting main window
The current focus window is a g-window variable.
To focus (win - a g-window):
if win is g-present:
now the current focus window is win;
call glk_set_window for win;
Part - Keeping the built-in windows up to date
Chapter - Handling GGRecoverObjects()
[ First ensure that window rocks are assigned ]
A glulx zeroing-reference rule (this is the set g-window rocks rule):
if the rock of the main window is 0:
now the rock of the main window is GG_MAINWIN_ROCK;
now the rock of the status window is GG_STATUSWIN_ROCK;
let i be 1000;
repeat with win running through g-windows:
if the rock of win is 0:
now the rock of win is i;
increase i by 10;
A glulx zeroing-reference rule (this is the reset window properties rule):
repeat with win running through g-windows:
now the ref number of win is 0;
now win is g-unpresent;
now win is not currently being processed;
[ Find all present windows, mark them as present and store their ref numbers. Note this will not run for the built in windows. ]
A glulx resetting-windows rule (this is the find existing windows rule):
let win be the window with rock current glulx rock;
if win is not the invalid window:
now the ref number of win is the current glulx rock-ref;
now win is g-present;
A first glulx object-updating rule (this is the recalibrate windows rule):
[ I used to think it wasn't safe to call the calibrate windows phrase here, but I can't really think why now ]
calibrate windows;
focus the current focus window;
A first glulx object-updating rule (this is the find the built in windows rule):
if gg_mainwin is not 0:
now the ref number of the main window is gg_mainwin;
now the main window is g-present;
if gg_statuswin is not 0:
now the ref number of the status window is gg_statuswin;
now the status window is g-present;
[A glulx zeroing-reference rule:
enable RulesOnSub;]
To enable RulesOnSub:
(- if ( glk_window_get_root() )
{
RulesOnSub();
} -).
Chapter - Updating windows that we control
After constructing a textual g-window (called win) (this is the focus the acting main window rule):
if win is the main window:
focus the main window;
After constructing a textual g-window (called win) (this is the update the I6 window variables rule):
if win is the main window:
now gg_mainwin is the ref number of win;
if win is the status window:
now gg_statuswin is the ref number of win;
Flexible Windows ends here.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment