void IZMachineIO.SelectWindow(short num) { if (num == 0) { currentWin = lowerWin; } else if (num == 1) { /* work around a bug in some Inform games where the screen is erased, * destroying the split, but the split isn't restored before drawing * the status line. */ if (upperWin.IsNull) ((IZMachineIO)this).SplitWindow(1); currentWin = upperWin; } Glk.glk_set_window(currentWin); }
private int xpos, ypos; // in Glk coordinates (i.e. counting from 0) #endregion Fields #region Constructors public GlkIO(string[] args, string storyName) { // initialize Glk // first, add the application's path to the beginning of the arg list string[] newArgs = new string[args.Length + 1]; newArgs[0] = Application.ExecutablePath; Array.Copy(args, 0, newArgs, 1, args.Length); args = newArgs; // now, GarGlk keeps pointers into argv, so we have to copy the args into unmanaged memory argv = Marshal.AllocHGlobal(4 * (args.Length + 1)); argvStrings = new IntPtr[args.Length]; for (int i = 0; i < args.Length; i++) { IntPtr str = Marshal.StringToHGlobalAnsi(args[i]); argvStrings[i] = str; Marshal.WriteIntPtr(argv, 4 * i, str); } Marshal.WriteIntPtr(argv, 4 * args.Length, IntPtr.Zero); Glk.gli_startup(args.Length, argv); Glk.garglk_set_program_name("Demona"); Glk.garglk_set_program_info("Demona by Jesse McGrew\nA Glk interface for ZLR\nVersion " + ZMachine.ZLR_VERSION); Glk.garglk_set_story_name(storyName); // set style hints Glk.glk_stylehint_set(WinType.AllTypes, Style.User1, StyleHint.ReverseColor, 1); Glk.glk_stylehint_set(WinType.AllTypes, Style.User2, StyleHint.Weight, 1); Glk.glk_stylehint_set(WinType.AllTypes, Style.User2, StyleHint.Proportional, 0); // figure out how big the screen is winid_t tempWin = Glk.glk_window_open(winid_t.Null, 0, 0, WinType.TextGrid, 0); if (tempWin.IsNull) { screenWidth = 80; screenHeight = 25; } else { Glk.glk_window_get_size(tempWin, out screenWidth, out screenHeight); stream_result_t dummy; Glk.glk_window_close(tempWin, out dummy); } // open the lower window lowerWin = Glk.glk_window_open(winid_t.Null, 0, 0, WinType.TextBuffer, 0); if (lowerWin.IsNull) throw new Exception("glk_window_open failed"); Glk.glk_set_window(lowerWin); currentWin = lowerWin; xpos = 0; ypos = 0; unicode = (Glk.glk_gestalt(Gestalt.Unicode, 0) != 0); }
void IZMachineIO.EraseWindow(short num) { switch (num) { case 0: // lower only Glk.glk_window_clear(lowerWin); break; case 1: // upper only if (!upperWin.IsNull) Glk.glk_window_clear(upperWin); break; case -1: // erase both and unsplit if (!upperWin.IsNull) { stream_result_t dummy; Glk.glk_window_close(upperWin, out dummy); upperWin = winid_t.Null; } goto case -2; case -2: // erase both but keep split if (!upperWin.IsNull) Glk.glk_window_clear(upperWin); Glk.glk_window_clear(lowerWin); currentWin = lowerWin; xpos = 0; ypos = 0; break; } }
private void PerformSplit(int lines) { if (lines > 0) { if (upperWin.IsNull) upperWin = Glk.glk_window_open(lowerWin, WinMethod.Above | WinMethod.Fixed, (uint)lines, WinType.TextGrid, 0); else Glk.glk_window_set_arrangement(Glk.glk_window_get_parent(upperWin), WinMethod.Above | WinMethod.Fixed, (uint)lines, winid_t.Null); } else { if (!upperWin.IsNull) { stream_result_t dummy; Glk.glk_window_close(upperWin, out dummy); upperWin = winid_t.Null; currentWin = lowerWin; } } }