示例#1
0
文件: GlkIO.cs 项目: hackerlank/zlr
        void IZMachineIO.PutTextRectangle(string[] lines)
        {
            if (lineInputActive)
            {
                Glk.glk_cancel_line_event(currentWin, out canceledLineEvent);
                lineInputActive = false;
            }

            if (currentWin == lowerWin)
            {
                foreach (string str in lines)
                {
                    if (unicode)
                    {
                        Glk.glk_put_string_uni(str);
                    }
                    else
                    {
                        Glk.glk_put_string(str);
                    }
                    Glk.glk_put_char((byte)'\n');
                }
            }
            else
            {
                int oxpos = xpos;

                foreach (string str in lines)
                {
                    Glk.glk_window_move_cursor(upperWin, (uint)oxpos, (uint)ypos);
                    if (unicode)
                    {
                        Glk.glk_put_string_uni(str);
                    }
                    else
                    {
                        Glk.glk_put_string(str);
                    }

                    ypos++;
                    if (ypos >= screenHeight)
                    {
                        ypos = (int)screenHeight - 1;
                    }

                    xpos = oxpos + str.Length;
                    if (xpos >= screenWidth)
                    {
                        xpos = (int)screenWidth - 1;
                    }
                }
            }
        }
示例#2
0
文件: GlkIO.cs 项目: hackerlank/zlr
 void IZMachineIO.EraseLine()
 {
     if (currentWin == upperWin)
     {
         uint width, height;
         Glk.glk_window_get_size(upperWin, out width, out height);
         for (int i = xpos; i < width; i++)
         {
             Glk.glk_put_char((byte)' ');
         }
         Glk.glk_window_move_cursor(upperWin, (uint)xpos, (uint)ypos);
     }
 }
示例#3
0
文件: GlkIO.cs 项目: hackerlank/zlr
        void IZMachineIO.PutChar(char ch)
        {
            if (lineInputActive)
            {
                Glk.glk_cancel_line_event(currentWin, out canceledLineEvent);

                lineInputActive = false;
                // glk_cancel_line_event prints a newline
                if (ch == '\n')
                {
                    return;
                }
            }

            if (unicode)
            {
                Glk.glk_put_char_uni((uint)ch);
            }
            else
            {
                byte b;
                encodingChar[0] = ch;
                int result = Encoding.GetEncoding(Glk.LATIN1).GetBytes(encodingChar, 0, 1, encodedBytes, 0);
                if (result != 1)
                {
                    b = (byte)'?';
                }
                else
                {
                    b = encodedBytes[0];
                }
                Glk.glk_put_char(b);
            }

            if (currentWin == upperWin)
            {
                xpos++;
                uint width, height;
                Glk.glk_window_get_size(upperWin, out width, out height);
                if (xpos >= width)
                {
                    xpos = 0;
                    ypos++;
                    if (ypos >= height)
                    {
                        ypos = (int)height - 1;
                    }
                }
            }
        }