Example #1
0
        public void EnsureCaretVisible()
        {
            SRectangle rcClient = new SRectangle();

            GetViewRectangle(rcClient);
            int   height        = rcClient.bottom - rcClient.top;
            int   posCaret      = textArea.sr.Caret();
            int   line          = textArea.tv.DisplayLineFromPosition(textArea.sr.Caret());
            Point pt            = new Point(0, (line - ScrollPos()) * textArea.tv.lineHeight);
            Point ptBottomCaret = new Point(pt.x, pt.y + textArea.tv.lineHeight - 1);
            int   lineCaret     = line;

            // Vertical positioning
            if (pt.y < rcClient.top || ptBottomCaret.y > height)
            {
                int newTopLine = ScrollPos();
                if (lineCaret < ScrollPos())
                {
                    // Caret goes too high
                    newTopLine = lineCaret;
                }
                else if (lineCaret > ScrollPos() + PageSize() - 1)
                {
                    // Caret goes too low
                    newTopLine = lineCaret - PageSize() + 1;
                }
                ScrollTo(newTopLine);
            }
        }
Example #2
0
 internal SRectangle(SRectangle other)
 {
     left   = other.left;
     top    = other.top;
     right  = other.right;
     bottom = other.bottom;
 }
Example #3
0
 //============================================================
 // <T>接收矩形对象。</T>
 //
 // @param rectangle 矩形对象
 //============================================================
 public void Assign(SRectangle <T> rectangle)
 {
     Left   = rectangle.Left;
     Top    = rectangle.Top;
     Width  = rectangle.Width;
     Height = rectangle.Height;
 }
Example #4
0
    public void InvalidateRange(int a, int b)
    {
        if (a < 0)
        {
            a = 0;
        }
        if (b < 0)
        {
            b = 0;
        }
        if (a > b)
        {
            int t = b;
            b = a;
            a = t;
        }
        int        lineTop       = tv.DisplayLineFromPosition(a);
        int        lineDocBottom = panel.pdoc.pbuffer.LineFromPosition(b) + 1;
        int        lineBottom    = tv.fs.DisplayFromDoc(lineDocBottom);
        SRectangle rcInvalidate  = new SRectangle();

        rcInvalidate.left   = 0;
        rcInvalidate.right  = 2000;
        rcInvalidate.top    = (lineTop - panel.ScrollPos()) * tv.lineHeight;
        rcInvalidate.bottom = (lineBottom - panel.ScrollPos()) * tv.lineHeight;
        // Allow for decorators that go 2 pixels beyond line.
        rcInvalidate.top    -= 2;
        rcInvalidate.bottom += 2;
        Invalidate(new Rectangle(rcInvalidate.left, rcInvalidate.top,
                                 rcInvalidate.Width(), rcInvalidate.Height()));
    }
Example #5
0
        public virtual void SetClip(SRectangle rc)
        {
            Rectangle clipRect = new Rectangle(
                rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top);
            Region clipRegion = new Region(clipRect);

            g.Clip = clipRegion;
        }
Example #6
0
        internal void GetViewRectangle(SRectangle rc)
        {
            Rectangle r = textArea.Bounds;

            rc.left   = r.X;
            rc.top    = r.Y;
            rc.right  = r.X + r.Width;
            rc.bottom = r.Y + r.Height;
        }
Example #7
0
        public override void serialize(BinaryFormatter formatter, Stream fileStream)
        {
            SRectangle sr = new SRectangle()
            {
                x = areaRectGeom.Rect.X, y = areaRectGeom.Rect.Y, width = areaRectGeom.Rect.Width, height = areaRectGeom.Rect.Height
            };

            formatter.Serialize(fileStream, sr);
        }
Example #8
0
 public virtual void PaintText(byte[] s, int len, SRectangle rcw, int ascentLine, int enc)
 {
     try {
         System.String sg = System.Text.Encoding.UTF8.GetString(s, 0, len);
         g.DrawString(sg, fontHandle, textBrush, rcw.left, rcw.top + ascentLine - ascent, sf);
     }
     catch (System.IO.IOException) {
         System.Console.Out.WriteLine("Failed to convert");
     }
 }
Example #9
0
 public virtual void PaintText(SplitText st, int position, int len, SRectangle rcw, int ascentLine)
 {
     try {
         byte[]        s       = new byte[len * 3];
         int           lenUTF8 = st.RetrieveUTF8(position, s, len);
         System.String sg      = System.Text.Encoding.UTF8.GetString(s, 0, lenUTF8);
         g.DrawString(sg, fontHandle, textBrush, rcw.left, rcw.top + ascentLine - ascent, sf);
     }
     catch (System.IO.IOException) {
         System.Console.Out.WriteLine("Failed to convert");
     }
 }
Example #10
0
        public override void deSerialize(BinaryFormatter formatter, Stream fileStream)
        {
            SRectangle sr = (SRectangle)formatter.Deserialize(fileStream);

            try
            {
                areaRectGeom.Rect = new Rect(sr.x, sr.y, sr.width, sr.height);
            }
            catch (Exception exp)
            {
                areaRectGeom.Rect = new Rect(0, 0, 0, 0);
            }
        }
Example #11
0
    private void Me_Resize(Object sender, EventArgs e)
    {
        SRectangle rcClient = new SRectangle();

        panel.GetViewRectangle(rcClient);
        tv.SetRectangle(rcClient);
        if (nextLineWrapped >= panel.pdoc.pbuffer.Lines())
        {
            goodTopLine = tv.fs.DocFromDisplay(tv.topLine);
        }
        nextLineWrapped = 0;
        CheckWrap();
        //Console.WriteLine("Idling");
    }
Example #12
0
        public DrawingInfo(SpriteBatch batch, Texture2D texture, SRectangle?sourceRectangle, Vector2 destination, SColor tint, Vector2 origin, float rotation, SpriteEffects effects, float depth) : this()
        {
            this.Texture         = texture;
            this.SourceRectangle = sourceRectangle;
            this.Tint            = tint;
            this.Batch           = batch;
            this.Origin          = origin;
            this.Rotation        = rotation;
            this.Effects         = effects;
            this.Depth           = depth;

            SRectangle sourceBounds = this.SourceRectangle ?? this.Texture.Bounds;

            this.Destination = new SRectangle((int)destination.X, (int)destination.Y, sourceBounds.Width, sourceBounds.Height);
        }
Example #13
0
        private void Me_SizeChanged(object sender, EventArgs e)
        {
            textArea.Width    = this.ClientSize.Width - scrollbarv.Width;
            textArea.Height   = this.ClientSize.Height - scrollbarh.Height;
            scrollbarv.Top    = 0;
            scrollbarv.Left   = textArea.Width;
            scrollbarv.Height = textArea.Height;
            scrollbarh.Top    = textArea.Height;
            scrollbarh.Left   = 0;
            scrollbarh.Width  = textArea.Width;
            SRectangle rcClient = new SRectangle();

            GetViewRectangle(rcClient);
            textArea.tv.SetRectangle(rcClient);
        }
Example #14
0
        public void SetScrollBars()
        {
            SRectangle rcClient = new SRectangle();

            GetViewRectangle(rcClient);
            textArea.tv.lineWidth = rcClient.right - rcClient.left;
            int nPage      = PageSize();
            int pageScroll = PageSize();
            int nMax       = textArea.tv.fs.DisplayFromDoc(pdoc.pbuffer.Lines());

            scrollbarv.Maximum     = nMax;
            scrollbarv.LargeChange = pageScroll;
            scrollbarh.Maximum     = 1200;
            scrollbarh.SmallChange = 8;
            scrollbarh.LargeChange = 120;
        }
Example #15
0
        internal int PageSize()
        {
            SRectangle rcClient = new SRectangle();

            GetViewRectangle(rcClient);
            int linesOnScreen = (rcClient.bottom - rcClient.top) / textArea.tv.lineHeight;

            if (linesOnScreen > 0)
            {
                return(linesOnScreen);
            }
            else
            {
                return(1);
            }
        }
Example #16
0
 public bool CheckWrap()
 {
     if (nextLineWrapped < panel.pdoc.pbuffer.Lines())
     {
         bool       redisplay = false;
         SRectangle rcClient  = new SRectangle();
         panel.GetViewRectangle(rcClient);
         tv.lineWidth = rcClient.right - rcClient.left;
         if (panel.wrap)
         {
             int minBytesToWrap = tv.lineWidth / tv.tabWidth + 1;
             //ElapsedTime et;
             panel.pdoc.pbuffer.LexTo(panel.pdoc.pbuffer.Length(), 0, false);
             // Get a surface
             Surface surface = new Surface(CreateGraphics());
             for (int line = 0; line < 200 && nextLineWrapped < panel.pdoc.pbuffer.Lines(); line++)
             {
                 if (nextLineWrapped == goodTopLine)
                 {
                     redisplay = true;
                 }
                 tv.WrapLine(surface, nextLineWrapped);
                 nextLineWrapped++;
             }
         }
         else
         {
             while (nextLineWrapped < panel.pdoc.pbuffer.Lines())
             {
                 tv.fs.SetHeight(nextLineWrapped, 1);
                 nextLineWrapped++;
             }
         }
         if (redisplay)
         {
             Invalidate();
             panel.ScrollTo(tv.fs.DisplayFromDoc(goodTopLine));
         }
         if (!(nextLineWrapped < panel.pdoc.pbuffer.Lines()))
         {
             panel.ScrollTo(tv.fs.DisplayFromDoc(goodTopLine));
             panel.SetScrollBars();
             Invalidate();
         }
     }
     return(nextLineWrapped < panel.pdoc.pbuffer.Lines());
 }
Example #17
0
    private void Contents_Paint(object sender, PaintEventArgs e)
    {
        Graphics  g        = e.Graphics;
        Rectangle rc       = Rectangle.Truncate(g.ClipBounds);
        Rectangle rcBounds = Bounds;

        rc.Intersect(rcBounds);
        SRectangle rcPaint = new SRectangle();

        rcPaint.left   = rc.X;
        rcPaint.top    = rc.Y;
        rcPaint.right  = rc.X + rc.Width;
        rcPaint.bottom = rc.Y + rc.Height;
        Surface surface = new Surface(g);

        tv.PaintRect(surface, rcPaint);

        panel.SetScrollBars();
    }
Example #18
0
 public DrawingInfo(SpriteBatch batch, Texture2D texture, SRectangle?sourceRectangle, SRectangle destination, SColor tint, Vector2 origin, float rotation, SpriteEffects effects, float depth) : this()
 {
     this.Texture         = texture;
     this.SourceRectangle = sourceRectangle;
     this.Destination     = destination;
     this.Tint            = tint;
     this.Batch           = batch;
     this.Origin          = origin;
     this.Rotation        = rotation;
     this.Effects         = effects;
     this.Depth           = depth;
 }
Example #19
0
 public virtual void FillRectangle(SRectangle rc, RGBColor color)
 {
     SetPen(color);
     g.FillRectangle(textBrush, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top);
 }
Example #20
0
 public virtual void FrameRectangle(SRectangle rc, RGBColor color)
 {
     SetPen(color);
     g.DrawRectangle(linePen, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top);
 }
Example #21
0
        private void DrawButton_Click(object sender, EventArgs e)
        {
            // The Draw Button's actions depend on which controls are visible;
            // If a user clicks the Draw Button without having supplied all the
            // required information, an exception is thrown and the user is ad-
            // vised through a MessageBox to observe the correct sequence.
            try
            {
                if (CircleButton.Visible) //instantiate and display a circle
                {
                    Circle bob = new Circle(double.Parse(radiusTxtBx.Text),
                                            int.Parse(xTextBox.Text), int.Parse(yTextBx.Text), 0);
                    string output = bob.Name + " " + bob;
                    ShapePictureBx.ImageLocation = "circle.png";
                    DescriptionLabel.Text        = output;
                }

                if (SquareButton.Visible) //instantiate and display a square
                {
                    Square lucy = new Square(int.Parse(xTextBox.Text),
                                             int.Parse(yTextBx.Text), int.Parse(sideTxtBx.Text));
                    string output = lucy.Name + " " + lucy + "\n";
                    ShapePictureBx.ImageLocation = "square.png";
                    DescriptionLabel.Text        = output;
                }

                if (RectangleButton.Visible) //instantiate and display a rectangle
                {
                    SRectangle fred = new SRectangle(int.Parse(xTextBox.Text),
                                                     int.Parse(yTextBx.Text), int.Parse(lengthTxtBx.Text),
                                                     int.Parse(widthTxtBx.Text));
                    string output = fred.Name + " " + fred + "\n";
                    ShapePictureBx.ImageLocation = "rectangle.png";
                    DescriptionLabel.Text        = output;
                }

                if (SphereButton.Visible) //instantiate and display a sphere
                {
                    Sphere heather = new Sphere(int.Parse(xTextBox.Text),
                                                int.Parse(yTextBx.Text), int.Parse(zTextBx.Text),
                                                double.Parse(radiusTxtBx.Text));
                    string output = heather.Name + " " + heather + "\n";
                    ShapePictureBx.ImageLocation = "sphere.png";
                    DescriptionLabel.Text        = output;
                }

                if (CubeButton.Visible) //instantiate and display a cube
                {
                    Cube newton = new Cube(int.Parse(xTextBox.Text), int.Parse(yTextBx.Text),
                                           int.Parse(zTextBx.Text), int.Parse(sideTxtBx.Text));
                    string output = newton.Name + " " + newton + "\n";
                    ShapePictureBx.ImageLocation = "cube.png";
                    DescriptionLabel.Text        = output;
                }

                if (CylinderButton.Visible) //instantiate and display a cylinder
                {
                    Cylinder felix = new Cylinder(double.Parse(radiusTxtBx.Text),
                                                  int.Parse(xTextBox.Text), int.Parse(yTextBx.Text),
                                                  int.Parse(zTextBx.Text), double.Parse(heightTxtBx.Text));
                    string output = felix.Name + " " + felix + "\n";
                    ShapePictureBx.ImageLocation = "cylinder.png";
                    DescriptionLabel.Text        = output;
                }
            }

            catch (Exception ex) // display the system message and specific instructions
            {
                MessageBox.Show(ex.Message + " Please select a shape  and enter "
                                + "the required data before clicking the Draw button.");
            }
        }
Example #22
0
        public Vector2 GetScale()
        {
            SRectangle source = this.SourceRectangle ?? this.Texture.Bounds;

            return(new Vector2((float)this.Destination.Width / source.Width, (float)this.Destination.Height / source.Height));
        }
Example #23
0
 public Sprite(int index, ISpriteSheet parentSheet, SRectangle sourceRectangle) : base(index, parentSheet)
 {
     this.SourceRectangle = sourceRectangle;
 }
Example #24
0
 public PaintContext(Surface surface_, SRectangle rc_)
 {
     surface = surface_;
     rc      = rc_;
 }