Constant Story "ImageTest"; Constant Headline "^Not a game.^"; Release 3; Include "Parser"; Include "VerbLib"; [ Initialise; if (~~graphics_supported()) print "This interpreter does not support graphics!^^"; glk_request_hyperlink_event(gg_mainwin); location = Kitchen; selfobj.description = "You're some kind of person."; ]; Object Kitchen "Image Room" with description [; print "A voice booooms out: Try ~image~, or ~image NUMBER~, or ~image NUMBER ALIGN~. Alignment are ~up~, ~down~, ~center~, ~left~, ~right~. Throw in the word ~caption~ to mix some text on the line. Throw in ~link~ to make the image a hyperlink. Adding a term like ~100x200~ will scale the image to those dimensions.^^ You can also type ~size NUMBER~ to check an image size. Type ~text~ for a long text paragraph, ~clear~ to clear the text buffer, and ~break~ for a flow break.^^ Images that should be available (imported from Sensory Jam): 0, 1, 2, 5, 10, 11.^"; ], has light; [ HandleGlkEvent ev ischar buffer linknum; if (ischar == 0 && ev-->0 == 8) { ! evtype_Hyperlink linknum = ev-->2; glk_cancel_line_event(gg_mainwin, gg_event); print "Clicked hyperlink: ", linknum, ".^"; print ">"; glk_request_line_event(gg_mainwin, buffer+WORDSIZE, INPUT_BUFFER_LEN-WORDSIZE, gg_event-->2); glk_request_hyperlink_event(gg_mainwin); } ]; Include "Grammar"; Global parsed_alignment; Global parsed_caption; Global parsed_hyperlink; Global parsed_dimensions; [ TryDimensions wordnum ix addr len ch xcount val res; addr = WordAddress(wordnum); len = WordLength(wordnum); res = 0; xcount = 0; val = 0; for (ix=0 : ixix; if (ch == 'x') { xcount++; res = val; val = 0; continue; } if (ch >= '0' && ch <= '9') { val = 10*val + (ch-'0'); continue; } return 0; } if (xcount ~= 1) return 0; if (res == 0 || val == 0) return 0; return ((res * $10000) | val); ]; [ ImageSpec startwn wd res; parsed_number = 0; parsed_alignment = 1; parsed_dimensions = 0; parsed_caption = false; parsed_hyperlink = false; startwn = wn; while (1) { wd = NextWordStopped(); if (wd == comma_word or THEN1__WD or -1) { if (wn-1 == startwn) { parsed_number = -1; return GPR_NUMBER; } return GPR_NUMBER; } res = TryNumber(wn-1); if (res >= 0) { parsed_number = res; continue; } res = TryDimensions(wn-1); if (res) { parsed_dimensions = res; continue; } if (wd == 'text' or 'caption') { parsed_caption = true; continue; } if (wd == 'hyper' or 'link' or 'hyperlink') { parsed_hyperlink = true; continue; } if (wd == 'up' or 'inlineup') { parsed_alignment = 1; continue; } if (wd == 'down' or 'inlinedown') { parsed_alignment = 2; continue; } if (wd == 'center' or 'inlinecenter') { parsed_alignment = 3; continue; } if (wd == 'left' or 'marginleft') { parsed_alignment = 4; continue; } if (wd == 'right' or 'inlineright') { parsed_alignment = 5; continue; } if (1) return GPR_FAIL; } ]; Verb 'size' * number -> Size; Verb 'image' * ImageSpec -> Image; Verb 'text' * -> Text; Extend 'break' replace * -> Break; Extend 'clear' replace * -> Clear; Array info_array --> 2; [ SizeSub res; if (~~graphics_supported()) print_ret "This interpreter does not support graphics."; res = glk_image_get_info(parsed_number, info_array, info_array+WORDSIZE); if (~~res) print_ret "There is no image ", parsed_number, "."; print_ret "Image ", parsed_number, " size: ", info_array-->0, " by ", info_array-->1, "."; ]; [ ImageSub wid hgt; !print_ret "Image ", parsed_number, " align ", parsed_alignment, "."; if (~~bufgraphics_supported()) print_ret "This window does not support image display."; if (parsed_number < 0) { print "Here are several images in a row:^"; print "With inlineup: "; glk_image_draw(gg_mainwin, 0, 1, 0); print " With inlinedown: "; glk_image_draw(gg_mainwin, 10, 2, 0); print " With inlinecenter: "; glk_image_draw(gg_mainwin, 5, 3, 0); new_line; rtrue; } if (parsed_hyperlink) glk_set_hyperlink(1000+parsed_number); if (parsed_dimensions == 0) { glk_image_draw(gg_mainwin, parsed_number, parsed_alignment, 0); } else { wid = ((parsed_dimensions / $10000) & $FFFF); hgt = (parsed_dimensions & $FFFF); glk_image_draw_scaled(gg_mainwin, parsed_number, parsed_alignment, 0, wid, hgt); } if (parsed_hyperlink) glk_set_hyperlink(0); if (parsed_caption) print " -- that is an image.^"; ]; [ TextSub ix val; print "Here is some"; for (ix=0 : ix<100 : ix++) { val = random("random", "wacky", "arbitrary", "mixed-up", "fool"); print " ", (string) val; } print_ret " text."; ]; [ BreakSub; if (~~bufgraphics_supported()) print_ret "This window does not support image display."; glk_window_flow_break(gg_mainwin); ]; [ ClearSub; glk_window_clear(gg_mainwin); print_ret "You erase history."; ]; [ graphics_supported; return glk_gestalt(6, 0); ! gestalt_Graphics ]; [ bufgraphics_supported; if (~~glk_gestalt(6, 0)) ! gestalt_Graphics return false; if (~~glk_gestalt(7, 3)) ! gestalt_DrawImage, wintype_TextBuffer return false; rtrue; ]; [ glk_gestalt _vararg_count ret; ! glk_gestalt(uint, uint) => uint @glk 4 _vararg_count ret; return ret; ]; [ glk_window_clear _vararg_count; ! glk_window_clear(window) @glk 42 _vararg_count 0; return 0; ]; [ glk_request_line_event _vararg_count; ! glk_request_line_event(window, nativechararray, arraylen, uint) @glk 208 _vararg_count 0; return 0; ]; [ glk_cancel_line_event _vararg_count; ! glk_cancel_line_event(window, &{uint, window, uint, uint}) @glk 209 _vararg_count 0; return 0; ]; [ glk_image_get_info _vararg_count ret; ! glk_image_get_info(uint, &uint, &uint) => uint @glk 224 _vararg_count ret; return ret; ]; [ glk_image_draw _vararg_count ret; ! glk_image_draw(window, uint, int, int) => uint @glk 225 _vararg_count ret; return ret; ]; [ glk_image_draw_scaled _vararg_count ret; ! glk_image_draw_scaled(window, uint, int, int, uint, uint) => uint @glk 226 _vararg_count ret; return ret; ]; [ glk_window_flow_break _vararg_count; ! glk_window_flow_break(window) @glk 232 _vararg_count 0; return 0; ]; [ glk_set_hyperlink _vararg_count; ! glk_set_hyperlink(uint) @glk 256 _vararg_count 0; return 0; ]; [ glk_request_hyperlink_event _vararg_count; ! glk_request_hyperlink_event(window) @glk 258 _vararg_count 0; return 0; ];