Skip to content

Commit 213cbd3

Browse files
committed
Begun working on a hyperlinks framework - supports rules and keypresses
1 parent f3472f4 commit 213cbd3

File tree

9 files changed

+5627
-9
lines changed

9 files changed

+5627
-9
lines changed

.editorconfig

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,9 @@ insert_final_newline = false
1212
[*.{i6t,i7,i7x,neptune,ni,txt,w}]
1313
indent_style = tab
1414

15+
[*.{i6t,w}]
16+
insert_final_newline = true
17+
1518
[*.json]
1619
indent_style = space
17-
indent_size = 4
18-
19-
[inform7/Tests/Test Cases/*.txt]
20-
indent_style = tab
21-
22-
[resources/Documentation/**.txt]
23-
indent_style = tab
20+
indent_size = 4

inform7/Internal/Extensions/Graham Nelson/Basic Inform.i7xd/Materials/Inter/Architecture32Kit/Sections/Glk.i6t

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -740,6 +740,63 @@ requested.
740740
return 0;
741741
];
742742

743+
@h Hyperlinks.
744+
A simple framework for handling hyperlinks in an interoperable manner.
745+
We combine a hyperlink tag with a payload in one 32-bit value. The tag is stored
746+
in the lowest bits, and the payload above it.
747+
748+
=
749+
Global hyperlink_payload_mask;
750+
Global hyperlink_tag_mask;
751+
Global hyperlink_tag_width;
752+
Global hyperlink_value;
753+
754+
[ CALCULATE_HYPERLINK_TAG_WIDTH_R;
755+
if (ICOUNT_HYPERLINK_TAG < 8) {
756+
hyperlink_tag_mask = $07;
757+
hyperlink_tag_width = 3;
758+
}
759+
else if (ICOUNT_HYPERLINK_TAG < 16) {
760+
hyperlink_tag_mask = $0F;
761+
hyperlink_tag_width = 4;
762+
}
763+
else {
764+
! Enough for 31 tags, which better be enough!
765+
hyperlink_tag_mask = $1F;
766+
hyperlink_tag_width = 5;
767+
}
768+
hyperlink_payload_mask = ~hyperlink_tag_mask;
769+
rfalse;
770+
];
771+
772+
[ MakeTaggedHyperlink tag val;
773+
if (Cached_Glk_Gestalts-->gestalt_Hyperlinks) {
774+
if (val > 0) {
775+
@shiftl val hyperlink_tag_width val;
776+
}
777+
else {
778+
val = val & hyperlink_payload_mask;
779+
}
780+
glk_set_hyperlink(tag | val);
781+
}
782+
];
783+
784+
[ HANDLE_HYPERLINK_R val;
785+
if (current_glk_event-->GLK_EVENT_TYPE_SF == evtype_Hyperlink) {
786+
val = current_glk_event-->GLK_EVENT_VALUE1_SF;
787+
glk_request_hyperlink_event((current_glk_event-->GLK_EVENT_WINDOW_SF).glk_ref);
788+
hyperlink_value = val & hyperlink_payload_mask;
789+
if (hyperlink_value < 0) {
790+
hyperlink_value = hyperlink_value | hyperlink_tag_mask;
791+
}
792+
else {
793+
@ushiftr hyperlink_value hyperlink_tag_width hyperlink_value;
794+
}
795+
FollowRulebook(HYPERLINK_HANDLING_RB, val & hyperlink_tag_mask, true);
796+
}
797+
rfalse;
798+
];
799+
743800
@h Suspending and resuming text input.
744801
These functions allow the author to suspend and then resume a window's text
745802
input requests.

inform7/Internal/Extensions/Graham Nelson/Basic Inform.i7xd/Materials/Inter/Architecture32Kit/Sections/Startup.i6t

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,9 @@ Global Pre_Startup_Text_Capture_Stream;
113113
if (BasicInformKit`MANUAL_INPUT_ECHOING_CFGF && Cached_Glk_Gestalts-->gestalt_LineInputEcho) {
114114
glk_set_echo_line_event(gg_mainwin, 0);
115115
}
116+
if (Cached_Glk_Gestalts-->gestalt_Hyperlinks) {
117+
glk_request_hyperlink_event(gg_mainwin);
118+
}
116119
} else {
117120
! There was already a story window. We should erase it.
118121
glk_window_clear(gg_mainwin);
@@ -124,6 +127,9 @@ Global Pre_Startup_Text_Capture_Stream;
124127
gg_statuswin =
125128
glk_window_open(gg_mainwin, winmethod_Fixed + winmethod_Above,
126129
statuswin_cursize, wintype_TextGrid, GG_STATUSWIN_ROCK);
130+
if (Cached_Glk_Gestalts-->gestalt_Hyperlinks) {
131+
glk_request_hyperlink_event(gg_statuswin);
132+
}
127133
}
128134
}
129135
else if (gg_statuswin) {

inform7/Internal/Extensions/Graham Nelson/Basic Inform.i7xd/Source/Sections/Glulx and Glk.w

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,57 @@ To replace current event with (ev - glk event):
195195
Glk event handling rule for a screen resize event (this is the redraw the status line rule):
196196
redraw the status window;
197197

198+
@h Hyperlinks.
199+
A simple framework for handling hyperlinks in an interoperable manner.
200+
201+
=
202+
Chapter - Hyperlinks
203+
204+
A hyperlink tag is a kind of value.
205+
206+
The hyperlink value is a number variable.
207+
The hyperlink value variable is defined by Inter as "hyperlink_value".
208+
209+
The hyperlink handling rules is a hyperlink tag based rulebook.
210+
The hyperlink handling rules is accessible to Inter as "HYPERLINK_HANDLING_RB".
211+
212+
The handle hyperlinks rule is listed in the glk event handling rules.
213+
The handle hyperlinks rule is defined by Inter as "HANDLE_HYPERLINK_R".
214+
215+
To say end link:
216+
(- if (Cached_Glk_Gestalts-->gestalt_Hyperlinks) { glk_set_hyperlink(0); } -).
217+
218+
@ And some built-in hyperlink tags:
219+
220+
- A rule hyperlink runs a rule when clicked; that in turn allows you to run any other code you like.
221+
- A keypress hyperlink converts a hyperlink event into a character event, for the specified unicode character.
222+
223+
=
224+
225+
Rule hyperlink is a hyperlink tag.
226+
227+
To say link (R - rule):
228+
(- MakeTaggedHyperlink((+ rule hyperlink +), {R}); -).
229+
230+
Hyperlink handling rule for a rule hyperlink (this is the rule hyperlink rule):
231+
run rule at address hyperlink value;
232+
233+
Keypress hyperlink is a hyperlink tag.
234+
235+
To say link (C - unicode character):
236+
(- MakeTaggedHyperlink((+ keypress hyperlink +), {C}); -).
237+
238+
Hyperlink handling rule for a keypress hyperlink (this is the keypress hyperlink rule):
239+
process a character event for (hyperlink value of the current glk event as a unicode character) in (window of the current glk event);
240+
241+
Section - unindexed
242+
243+
To run rule at address (R - number):
244+
(- ({R})(); -).
245+
246+
To decide what unicode character is (N - number) as a unicode character:
247+
(- ({N}) -).
248+
198249
@h Suspending input.
199250
These properties and phrases allow the author to suspend and resume input requests.
200251

inform7/Internal/Extensions/Graham Nelson/Basic Inform.i7xd/Source/Sections/Miscellaneous Definitions.w

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,13 @@ Section - Startup C (for Glulx only)
154154
The start capturing startup text rule is listed first in the before starting the virtual machine rules. [1st]
155155
The start capturing startup text rule translates into Inter as "CAPTURE_STARTUP_TEXT_R".
156156

157+
The calculate hyperlink tag width rule is listed in the before starting the virtual machine rules. [6th]
158+
The calculate hyperlink tag width rule translates into Inter as "CALCULATE_HYPERLINK_TAG_WIDTH_R".
159+
157160
@ These rules now set up the built in sound channels and windows.
158161

159162
=
160-
The set default stylehints rule is listed in the before starting the virtual machine rules. [6th]
163+
The set default stylehints rule is listed in the before starting the virtual machine rules. [7th]
161164
The set default stylehints rule translates into Inter as "SET_DEFAULT_STYLEHINTS_R".
162165

163166
The sound channel initialisation rule is listed in the for starting the virtual machine rules.

inform7/Internal/Extensions/Graham Nelson/Basic Inform.i7xd/Source/Sections/Phrase Definitions.w

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2046,4 +2046,4 @@ Chapter 11 - Use Options
20462046
Section 1 - Numerical Value
20472047

20482048
To decide what number is the numerical value of (U - a use option):
2049-
(- USE_OPTION_VALUES-->({U}) -).
2049+
(- USE_OPTION_VALUES-->({U}) -).

inform7/Internal/Extensions/Graham Nelson/English Language.i7xd/Materials/Languages/English/Index.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,7 @@
314314
%Index.Elements.St.IdentifySchannelsRules = Identify glk sound channels rules
315315
%Index.Elements.St.GlkObjectUpdatingRules = Glk object updating rules
316316
%Index.Elements.St.GlkEventHandlingRules = Glk event handling rules
317+
%Index.Elements.St.HyperlinkHandlingRules = Hyperlink handling rules
317318

318319
%Index.Elements.St.CheckRules =
319320
Check rules are tied to specific actions, and there are too many to index here.

0 commit comments

Comments
 (0)