⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 view.cs

📁 一个远程终端软件的源码
💻 CS
📖 第 1 页 / 共 5 页
字号:
        // around a bug in Windows.
        switch(connOpts.ViewOpts.Orientation)
        {
          case Orientation.Portrait180:
          case Orientation.Landscape270:
            hScrlBar.Value = hScrlBar.Maximum - Math.Min(value, hScrlBar.Maximum - hScrlBar.LargeChange) - hScrlBar.LargeChange;
            break;
          default:
            hScrlBar.Value = Math.Min(value, hScrlBar.Maximum - hScrlBar.LargeChange);
            break;
        }
      }
    }

    private UInt16 VScrlBarVal
    {
      get
      {
        if(!vScrlBar.Visible)
          return 0;

        switch(connOpts.ViewOpts.Orientation)
        {
          case Orientation.Landscape90:
          case Orientation.Portrait180:
            return (UInt16)(vScrlBar.Maximum + 1 - vScrlBar.Value - vScrlBar.LargeChange);
          default:
            return (UInt16)vScrlBar.Value;
        }
      }
      set
      {
        if(!vScrlBar.Visible)
          value = 0;

        // The maximum that we can assign should be vScrlBar.Maximum - vScrlBar.LargeChange + 1.
        // The maximum that we assign here is vScrlBar.Maximum - vScrlBar.LargeChange to work
        // around a bug in Windows.
        switch(connOpts.ViewOpts.Orientation)
        {
          case Orientation.Landscape90:
          case Orientation.Portrait180:
            vScrlBar.Value = vScrlBar.Maximum - Math.Min(value, vScrlBar.Maximum - vScrlBar.LargeChange) - vScrlBar.LargeChange;
            break;
          default:
            vScrlBar.Value = Math.Min(value, vScrlBar.Maximum - vScrlBar.LargeChange);
            break;
        }
      }
    }

    private void SetupScrlBars()
    {
      UInt16 oldHScrlBarVal = HScrlBarVal;
      UInt16 oldVScrlBarVal = VScrlBarVal;

      bool hScrlBarUnknown = false;
      bool vScrlBarUnknown = false;
      if(ClientSize.Width < scaledFBWidth)
        hScrlBar.Visible = true;
      else if(ClientSize.Width >= scaledFBWidth + vScrlBar.Width)
        hScrlBar.Visible = false;
      else
        hScrlBarUnknown = true;
      if(ClientSize.Height < scaledFBHeight)
        vScrlBar.Visible = true;
      else if(ClientSize.Height >= scaledFBHeight + hScrlBar.Height)
        vScrlBar.Visible = false;
      else
        vScrlBarUnknown = true;
      if(hScrlBarUnknown && vScrlBarUnknown)
      {
        hScrlBar.Visible = false;
        vScrlBar.Visible = false;
      }
      else if(hScrlBarUnknown)
        hScrlBar.Visible = vScrlBar.Visible;
      else if(vScrlBarUnknown)
        vScrlBar.Visible = hScrlBar.Visible;

      if(hScrlBar.Visible)
      {
        if(vScrlBar.Visible)
        {
          hScrlBar.Width = ClientSize.Width - vScrlBar.Width;
          switch(connOpts.ViewOpts.Orientation)
          {
            case Orientation.Landscape90:
              hScrlBar.Location = new Point(0, 0);
              break;
            case Orientation.Portrait180:
              hScrlBar.Location = new Point(vScrlBar.Width, 0);
              break;
            case Orientation.Landscape270:
              hScrlBar.Location = new Point(vScrlBar.Width, ClientSize.Height - hScrlBar.Height);
              break;
            default:
              hScrlBar.Location = new Point(0, ClientSize.Height - hScrlBar.Height);
              break;
          }
        }
        else
        {
          hScrlBar.Width = ClientSize.Width;
          switch(connOpts.ViewOpts.Orientation)
          {
            case Orientation.Landscape90:
            case Orientation.Portrait180:
              hScrlBar.Location = new Point(0, 0);
              break;
            default:
              hScrlBar.Location = new Point(0, ClientSize.Height - hScrlBar.Height);
              break;
          }
        }
        hScrlBar.LargeChange = hScrlBar.Width;
        hScrlBar.SmallChange = hScrlBar.LargeChange / 10; // TODO: Make this configurable
        hScrlBar.Minimum = 0;
        hScrlBar.Maximum = scaledFBWidth - 1;
        HScrlBarVal = oldHScrlBarVal;
      }

      if(vScrlBar.Visible)
      {
        if(hScrlBar.Visible)
        {
          vScrlBar.Height = ClientSize.Height - hScrlBar.Height;
          switch(connOpts.ViewOpts.Orientation)
          {
            case Orientation.Landscape90:
              vScrlBar.Location = new Point(ClientSize.Width - vScrlBar.Width, hScrlBar.Height);
              break;
            case Orientation.Portrait180:
              vScrlBar.Location = new Point(0, hScrlBar.Height);
              break;
            case Orientation.Landscape270:
              vScrlBar.Location = new Point(0, 0);
              break;
            default:
              vScrlBar.Location = new Point(ClientSize.Width - vScrlBar.Width, 0);
              break;
          }
        }
        else
        {
          vScrlBar.Height = ClientSize.Height;
          switch(connOpts.ViewOpts.Orientation)
          {
            case Orientation.Portrait180:
            case Orientation.Landscape270:
              vScrlBar.Location = new Point(0, 0);
              break;
            default:
              vScrlBar.Location = new Point(ClientSize.Width - vScrlBar.Width, 0);
              break;
          }
        }
        vScrlBar.LargeChange = vScrlBar.Height;
        vScrlBar.SmallChange = vScrlBar.LargeChange / 10; // TODO: Make this configurable
        vScrlBar.Minimum = 0;
        vScrlBar.Maximum = scaledFBHeight - 1;
        VScrlBarVal = oldVScrlBarVal;
      }
    }

    private void ResizeCore()
    {
      if(connOpts.ViewOpts.CliScaling == CliScaling.Auto)
      {
        scaledFBWidth = (UInt16)ClientSize.Width;
        scaledFBHeight = (UInt16)ClientSize.Height;
      }
      SetupScrlBars();
      Invalidate();

      if(connOpts.ViewOpts.CliScaling == CliScaling.Auto)
        return;

      // .NET CF does not support MaximumSize...
      if(WindowState == FormWindowState.Maximized)
      {
        if(FormBorderStyle != FormBorderStyle.None)
        {
          WindowState = FormWindowState.Normal;
          ClientSize = new Size(scaledFBWidth, scaledFBHeight);
        }
      }
      else
      {
        Rectangle usableRect = UsableRect;
        if(usableRect.Width > scaledFBWidth || usableRect.Height > scaledFBHeight)
        {
          int width = Math.Min(usableRect.Width, scaledFBWidth);
          int height = Math.Min(usableRect.Height, scaledFBHeight);
          width += vScrlBar.Visible? vScrlBar.Width : 0;
          height += hScrlBar.Visible? hScrlBar.Height : 0;
          ClientSize = new Size(width, height);
        }
      }
    }

    protected override void OnResize(EventArgs e)
    {
      base.OnResize(e);
      ResizeCore();
    }

    private void Scrled(object sender, EventArgs e)
    {
      Invalidate();
    }

    private void RotateClicked(object sender, EventArgs e)
    {
      Orientation newOrientation;
      string menuText = ((MenuItem)sender).Text;
      if(menuText == App.GetStr("Screen rotated clockwise"))
        newOrientation = Orientation.Landscape90;
      else if(menuText == App.GetStr("Screen rotated counter-clockwise"))
        newOrientation = Orientation.Landscape270;
      else if(menuText == App.GetStr("Upside down"))
        newOrientation = Orientation.Portrait180;
      else
        newOrientation = Orientation.Portrait;

      UInt16 newHScrlBarVal;
      UInt16 newVScrlBarVal;
      if(((connOpts.ViewOpts.Orientation == Orientation.Portrait || connOpts.ViewOpts.Orientation == Orientation.Portrait180) &&
          (newOrientation == Orientation.Landscape90 || newOrientation == Orientation.Landscape270)) ||
         ((connOpts.ViewOpts.Orientation == Orientation.Landscape90 || connOpts.ViewOpts.Orientation == Orientation.Landscape270) &&
          (newOrientation == Orientation.Portrait || newOrientation == Orientation.Portrait180)))
      {
        newHScrlBarVal = VScrlBarVal;
        newVScrlBarVal = HScrlBarVal;
      }
      else
      {
        newHScrlBarVal = HScrlBarVal;
        newVScrlBarVal = VScrlBarVal;
      }
      UInt16 newWidth;
      UInt16 newHeight;
      switch(connOpts.ViewOpts.Orientation)
      {
        case Orientation.Landscape90:
        case Orientation.Landscape270:
          newWidth = rawFBHeight;
          newHeight = rawFBWidth;
          break;
        default:
          newWidth = rawFBWidth;
          newHeight = rawFBHeight;
          break;
      }

      ResizeFrameBufCore(newOrientation, newWidth, newHeight);
      SetScaledDims();

      try
      {
        conn.SendUpdReq(false);
      }
      catch(IOException)
      {
        Close();
      }

      ResizeCore();

      HScrlBarVal = newHScrlBarVal;
      VScrlBarVal = newVScrlBarVal;

      CheckRotate();
    }

    private void CloseClicked(object sender, EventArgs e)
    {
      Close();
    }

    private void FullScrn()
    {
      // The order of execution is very important.
      // It has a big impact on the window size when we quit full screen mode.
      Menu = null;
      FormBorderStyle = FormBorderStyle.None;
      WindowState = FormWindowState.Maximized; // This has to be after setting FormBorderStyle to have Resize work correctly.
    }

    private void QuitFullScrn()
    {
      // The order of execution is very important.
      // If the order is altered, the program can actually loop forever.
      WindowState = FormWindowState.Normal;
      FormBorderStyle = FormBorderStyle.Sizable;
      Menu = menu;
      ClientSize = new Size(scaledFBWidth, scaledFBHeight);
    }

    protected void ToggleFullScrn()
    {
      connOpts.ViewOpts.IsFullScrn = !connOpts.ViewOpts.IsFullScrn;
      if(connOpts.ViewOpts.IsFullScrn)
        FullScrn();
      else
        QuitFullScrn();
    }

    private void FullScrnClicked(object sender, EventArgs e)
    {
      ToggleFullScrn();
    }

    protected override void OnLoad(EventArgs e)
    {
      base.OnLoad(e);

      if(connOpts.ViewOpts.IsFullScrn)
        FullScrn();
      else
        QuitFullScrn();

      SetupScrlBars();
      HScrlBarVal = 0;
      VScrlBarVal = 0;
      Controls.Add(hScrlBar);
      Controls.Add(vScrlBar);
    }

    protected Rectangle UsableRect
    {
      get
      {
        Rectangle rect = new Rectangle();
        if(hScrlBar.Visible)
        {
          rect.Height = ClientRectangle.Height - hScrlBar.Height;
          if(hScrlBar.Top <= 0) // At the top
            rect.Y = hScrlBar.Height;
          else
            rect.Y = 0;
        }
        else
        {
          rect.Height = ClientRectangle.Height;
          rect.Y = 0;
        }
        if(vScrlBar.Visible)
        {
          rect.Width = ClientRectangle.Width - vScrlBar.Width;
          if(vScrlBar.Left <= 0) // At the left edge
            rect.X = vScrlBar.Width;
          else
            rect.X = 0;
        }
        else
        {
          rect.Width = ClientRectangle.Width;
          rect.X = 0;
        }
        return rect;
      }
    }

    protected Rectangle ViewableRect
    {
      get
      {
        Rectangle usable = UsableRect;
        Rectangle rect = new Rectangle();
        if(hScrlBar.Visible)
        {
          rect.X = usable.X;
          rect.Width = usable.Width;
        }
        else
        {
          rect.X = usable.X + (usable.Width - scaledFBWidth) / 2;
          rect.Width = scaledFBWidth;
        }
        if(vScrlBar.Visible)
        {
          rect.Y = usable.Y;
          rect.Height = usable.Height;
        }
        else
        {
          rect.Y = usable.Y + (usable.Height - scaledFBHeight) / 2;
          rect.Height = scaledFBHeight;
        }
        return rect;
      }
    }

    protected override void OnPaint(PaintEventArgs e)
    {
      base.OnPaint(e);
      Graphics graphics = e.Graphics;
      Rectangle usable = UsableRect;
      Rectangle viewable = ViewableRect;

      Rectangle destRect = Rectangle.Intersect(viewable, e.ClipRectangle);
      if(destRect != Rectangle.Empty)
      {
        if(connOpts.ViewOpts.CliScaling == CliScaling.None)
        {
          Rectangle srcRect = new Rectangle(destRect.X, destRect.Y, destRect.Width, destRect.Height);
          ScrnToFrameBufRect(ref srcRect);
          LockFrameBuf();
          graphics.DrawImage(frameBuf, destRect, srcRect, GraphicsUnit.Pixel);
          UnlockFrameBuf();
        }
        else
        {
          // We don't limit ourselves to the invalidated area because doing so will introduce
          // rounding error and the screen will look strange.
          Rectangle srcRect = viewable;
          ScrnToFrameBufRect(ref srcRect);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -