Пример #1
0
 public Initiative(bool isAIControlledi, LocalObject o)
     : base(o)
 {
     value = 0;
     r = new RPoint();
     animations = new AnimationQueue();
     isAIControlled = isAIControlledi;
     movementCounter = 3;
 }
Пример #2
0
    public RMove(RPoint targeti, Vector2 v, float gameTime)
    {
        Log.Assert(gameTime > 0, "speed is less then zero in RMove");
        target = targeti;

        maxFrameTime = (int)(gameTime * FramesInOneGameTime);
        if (maxFrameTime == 0) maxFrameTime = 1;
        delta = v / maxFrameTime;
        frameTime = 0;
    }
Пример #3
0
    public Vector2 GraphicCoordinates(RPoint p)
    {
        Vector2 result = new Vector2();

        result.X = (p.x - World.Instance.camera.x) * 40;
        result.Y = (p.y - World.Instance.camera.y) * 48 + MyMath.SawFunction(p.x) * 24 - MyMath.IsOdd(World.Instance.camera.x) * 24;
        result = result + ZeroGraphicCoordinates - new Vector2(26, 24);

        return result;
    }
Пример #4
0
 public void Draw(Texture2D texture, RPoint rPosition, float scaling, Color color)
 {
     if (scaling == 1.0f) Draw(texture, rPosition, color);
     else
     {
         int width = (int)(scaling * texture.Width);
         int height = (int)(scaling * texture.Height);
         ZPoint center = new ZPoint(GraphicCoordinates(rPosition)) + new ZPoint(16, 32 - height / 2);
         M.spriteBatch.Draw(texture, new Rectangle(center.x - width/2, center.y - height/2, width, height), color);
     }
 }
Пример #5
0
        /// <summary>
        /// Paints the fragment
        /// </summary>
        /// <param name="g">the device to draw to</param>
        protected override void PaintImp(RGraphics g)
        {
            // load image if it is in visible rectangle
            if (this._imageLoadHandler == null)
            {
                this._imageLoadHandler = new ImageLoadHandler(this.HtmlContainer, this.OnLoadImageComplete);
                this._imageLoadHandler.LoadImage(this.GetAttribute("src"), this.HtmlTag != null ? this.HtmlTag.Attributes : null);
            }

            var    rect   = CommonUtils.GetFirstValueOrDefault(this.Rectangles);
            RPoint offset = RPoint.Empty;

            if (!this.IsFixed)
            {
                offset = this.HtmlContainer.ScrollOffset;
            }

            rect.Offset(offset);

            var clipped = RenderUtils.ClipGraphicsByOverflow(g, this);

            this.PaintBackground(g, rect, true, true);
            BordersDrawHandler.DrawBoxBorders(g, this, rect, true, true);

            RRect r = this._imageWord.Rectangle;

            r.Offset(offset);
            r.Height -= this.ActualBorderTopWidth + this.ActualBorderBottomWidth + this.ActualPaddingTop + this.ActualPaddingBottom;
            r.Y      += this.ActualBorderTopWidth + this.ActualPaddingTop;
            r.X       = Math.Floor(r.X);
            r.Y       = Math.Floor(r.Y);

            if (this._imageWord.Image != null)
            {
                if (r.Width > 0 && r.Height > 0)
                {
                    if (this._imageWord.ImageRectangle == RRect.Empty)
                    {
                        g.DrawImage(this._imageWord.Image, r);
                    }
                    else
                    {
                        g.DrawImage(this._imageWord.Image, r, this._imageWord.ImageRectangle);
                    }

                    if (this._imageWord.Selected)
                    {
                        g.DrawRectangle(this.GetSelectionBackBrush(g, true), this._imageWord.Left + offset.X, this._imageWord.Top + offset.Y, this._imageWord.Width + 2, DomUtils.GetCssLineBoxByWord(this._imageWord).LineHeight);
                    }
                }
            }
            else if (this._imageLoadingComplete)
            {
                if (this._imageLoadingComplete && r.Width > 19 && r.Height > 19)
                {
                    RenderUtils.DrawImageErrorIcon(g, this.HtmlContainer, r);
                }
            }
            else
            {
                RenderUtils.DrawImageLoadingIcon(g, this.HtmlContainer, r);
                if (r.Width > 19 && r.Height > 19)
                {
                    g.DrawRectangle(g.GetPen(RColor.LightGray), r.X, r.Y, r.Width, r.Height);
                }
            }

            if (clipped)
            {
                g.PopClip();
            }
        }
 public override void Start(double x, double y)
 {
     _lastPoint = new RPoint(x, y);
 }
Пример #7
0
 public static Vector2 GC(RPoint p)
 {
     return GraphicCoordinates(p);
 }
 /// <summary>
 /// 点是否在线段上
 /// </summary>
 /// <param name="P">任意的点</param>
 /// <param name="S">任意线段</param>
 /// <returns></returns>
 public static int In2D_Point_Segment(RPoint P, RSegment S)
 {
     return(0);
 }
Пример #9
0
        /// <summary>
        /// Get css link href at the given x,y location.
        /// </summary>
        /// <param name="location">the location to find the link at</param>
        /// <returns>css link href if exists or null</returns>
        public string GetLinkAt(RPoint location)
        {
            var link = DomUtils.GetLinkBox(_root, OffsetByScroll(location));

            return(link != null ? link.HrefLink : null);
        }
Пример #10
0
        //===================================================================
        //3D空间任意多边形面积
        // area3D_Polygon(): computes the area of a 3D planar polygon
        //    Input:  int n = the number of vertices in the polygon
        //            Point* V = an array of n+2 vertices in a plane
        //                       with V[n]=V[0] and V[n+1]=V[1]
        //            Point N = unit normal vector of the polygon's plane
        //    Return: the (float) area of the polygon
        public static double area3D_Polygon(int n, RPoint[] V, RPoint N)
        {
            double area = 0;
            double an, ax, ay, az; // abs value of normal and its coords
            int    coord;          // coord to ignore: 1=x, 2=y, 3=z
            int    i, j, k;        // loop indices

            // select largest abs coordinate to ignore for projection
            ax = (N.X > 0 ? N.X : -N.X);   // abs x-coord
            ay = (N.Y > 0 ? N.Y : -N.Y);   // abs y-coord
            az = (N.Z > 0 ? N.Z : -N.Z);   // abs z-coord

            coord = 3;                     // ignore z-coord
            if (ax > ay)
            {
                if (ax > az)
                {
                    coord = 1;             // ignore x-coord
                }
            }
            else if (ay > az)
            {
                coord = 2;                 // ignore y-coord
            }
            // compute area of the 2D projection
            for (i = 1, j = 2, k = 0; i <= n; i++, j++, k++)
            {
                switch (coord)
                {
                case 1:
                    area += (V[i].Y * (V[j].Z - V[k].Z));
                    continue;

                case 2:
                    area += (V[i].X * (V[j].Z - V[k].Z));
                    continue;

                case 3:
                    area += (V[i].X * (V[j].Y - V[k].Y));
                    continue;
                }
            }

            // scale to get area before projection
            an = Math.Sqrt(ax * ax + ay * ay + az * az);  // length of normal vector
            switch (coord)
            {
            case 1:
                area *= (an / (2 * ax));
                break;

            case 2:
                area *= (an / (2 * ay));
                break;

            case 3:
                area *= (an / (2 * az));
                break;
            }
            return(area);
        }
Пример #11
0
 public override void Show(RControl parent, RPoint location)
 {
     _contextMenu.Show(((ControlAdapter)parent).Control, Utils.ConvertRound(location));
 }
Пример #12
0
        /// <summary>
        /// Measures the bounds of box and children, recursively.<br/>
        /// Performs layout of the DOM structure creating lines by set bounds restrictions.
        /// </summary>
        /// <param name="g">Device context to use</param>
        protected override void PerformLayoutImp(RGraphics g)
        {
            if (Display == CssConstants.None)
            {
                return;
            }

            RectanglesReset();

            var    prevSibling = DomUtils.GetPreviousSibling(this);
            double left        = ContainingBlock.Location.X + ContainingBlock.ActualPaddingLeft + ActualMarginLeft +
                                 ContainingBlock.ActualBorderLeftWidth;
            double top =
                (prevSibling == null && ParentBox != null ? ParentBox.ClientTop : ParentBox == null ? Location.Y : 0) +
                MarginTopCollapse(prevSibling) + (prevSibling != null
                                        ? prevSibling.ActualBottom + prevSibling.ActualBorderBottomWidth
                                        : 0);

            Location     = new RPoint(left, top);
            ActualBottom = top;

            //width at 100% (or auto)
            double minwidth = GetMinimumWidth();
            double width    = ContainingBlock.Size.Width
                              - ContainingBlock.ActualPaddingLeft - ContainingBlock.ActualPaddingRight
                              - ContainingBlock.ActualBorderLeftWidth - ContainingBlock.ActualBorderRightWidth
                              - ActualMarginLeft - ActualMarginRight - ActualBorderLeftWidth - ActualBorderRightWidth;

            //Check width if not auto
            if (Width != CssConstants.Auto && !string.IsNullOrEmpty(Width))
            {
                width = CssValueParser.ParseLength(Width, width, this);
            }

            if (width < minwidth || width >= 9999)
            {
                width = minwidth;
            }

            double height = ActualHeight;

            if (height < 1)
            {
                height = Size.Height + ActualBorderTopWidth + ActualBorderBottomWidth;
            }

            if (height < 1)
            {
                height = 2;
            }

            if (height <= 2 && ActualBorderTopWidth < 1 && ActualBorderBottomWidth < 1)
            {
                BorderTopStyle    = BorderBottomStyle = CssConstants.Solid;
                BorderTopWidth    = "1px";
                BorderBottomWidth = "1px";
            }

            Size = new RSize(width, height);

            ActualBottom = Location.Y + ActualPaddingTop + ActualPaddingBottom + height;
        }
Пример #13
0
 public override RBrush GetTextureBrush(RImage image, RRect dstRect, RPoint translateTransformLocation)
 {
     return(new BrushAdapter(image, dstRect, translateTransformLocation));
 }
Пример #14
0
 /// <summary>
 /// Get css link href at the given x,y location.
 /// </summary>
 /// <param name="location">the location to find the link at</param>
 /// <returns>css link href if exists or null</returns>
 public string GetLinkAt(RPoint location)
 {
     return(_htmlContainerInt.GetLinkAt(location));
 }
Пример #15
0
 /// <summary>
 /// Get attribute value of element at the given x,y location by given key.<br/>
 /// If more than one element exist with the attribute at the location the inner most is returned.
 /// </summary>
 /// <param name="location">the location to find the attribute at</param>
 /// <param name="attribute">the attribute key to get value by</param>
 /// <returns>found attribute value or null if not found</returns>
 public string GetAttributeAt(RPoint location, string attribute)
 {
     return(_htmlContainerInt.GetAttributeAt(location, attribute));
 }
Пример #16
0
        /// <summary>
        /// 点在多边形中
        /// </summary>
        /// <param name="rPt"></param>
        /// <param name="rLine"></param>
        /// <returns></returns>
        public static bool IsInPolygon(RPoint rPt, RPolygon rPolygon)
        {
            bool flag = false;

            return(flag);
        }
Пример #17
0
        /// <summary>
        /// Paints the fragment
        /// </summary>
        /// <param name="g">the device to draw to</param>
        protected override void PaintImp(RGraphics g)
        {
            var    rect   = CommonUtils.GetFirstValueOrDefault(Rectangles);
            RPoint offset = RPoint.Empty;

            if (!IsFixed)
            {
                offset = HtmlContainer.ScrollOffset;
            }

            rect.Offset(offset);

            var clipped = RenderUtils.ClipGraphicsByOverflow(g, this);

            PaintBackground(g, rect, true, true);
            BordersDrawHandler.DrawBoxBorders(g, this, rect, true, true);

            RRect r = _imageWord.Rectangle;

            r.Offset(offset);
            r.Height -= ActualBorderTopWidth + ActualBorderBottomWidth + ActualPaddingTop + ActualPaddingBottom;
            r.Y      += ActualBorderTopWidth + ActualPaddingTop;
            r.X       = Math.Floor(r.X);
            r.Y       = Math.Floor(r.Y);

            if (_imageWord.Image != null)
            {
                if (r.Width > 0 && r.Height > 0)
                {
                    if (_imageWord.ImageRectangle == RRect.Empty)
                    {
                        g.DrawImage(_imageWord.Image, r);
                    }
                    else
                    {
                        g.DrawImage(_imageWord.Image, r, _imageWord.ImageRectangle);
                    }

                    if (_imageWord.Selected)
                    {
                        g.DrawRectangle(GetSelectionBackBrush(g, true), _imageWord.Left + offset.X, _imageWord.Top + offset.Y, _imageWord.Width + 2, DomUtils.GetCssLineBoxByWord(_imageWord).LineHeight);
                    }
                }
            }
            else if (_imageLoadingComplete)
            {
                if (_imageLoadingComplete && r.Width > 19 && r.Height > 19)
                {
                    RenderUtils.DrawImageErrorIcon(g, HtmlContainer, r);
                }
            }
            else
            {
                RenderUtils.DrawImageLoadingIcon(g, HtmlContainer, r);
                if (r.Width > 19 && r.Height > 19)
                {
                    g.DrawRectangle(g.GetPen(RColor.LightGray), r.X, r.Y, r.Width, r.Height);
                }
            }

            if (clipped)
            {
                g.PopClip();
            }
        }
Пример #18
0
        /// <summary>
        /// Handle html text selection by mouse move over the html with left mouse button pressed.<br/>
        /// Calculate the words in the selected range and set their selected property.
        /// </summary>
        /// <param name="control">the control hosting the html to invalidate</param>
        /// <param name="loc">the mouse location</param>
        /// <param name="allowPartialSelect">true - partial word selection allowed, false - only full words selection</param>
        private void HandleSelection(RControl control, RPoint loc, bool allowPartialSelect)
        {
            // get the line under the mouse or nearest from the top
            var lineBox = DomUtils.GetCssLineBox(_root, loc);

            if (lineBox != null)
            {
                // get the word under the mouse
                var word = DomUtils.GetCssBoxWord(lineBox, loc);

                // if no word found under the mouse use the last or the first word in the line
                if (word == null && lineBox.Words.Count > 0)
                {
                    if (loc.Y > lineBox.LineBottom)
                    {
                        // under the line
                        word = lineBox.Words[lineBox.Words.Count - 1];
                    }
                    else if (loc.X < lineBox.Words[0].Left)
                    {
                        // before the line
                        word = lineBox.Words[0];
                    }
                    else if (loc.X > lineBox.Words[lineBox.Words.Count - 1].Right)
                    {
                        // at the end of the line
                        word = lineBox.Words[lineBox.Words.Count - 1];
                    }
                }

                // if there is matching word
                if (word != null)
                {
                    if (_selectionStart == null)
                    {
                        // on start set the selection start word
                        _selectionStartPoint = loc;
                        _selectionStart      = word;
                        if (allowPartialSelect)
                        {
                            CalculateWordCharIndexAndOffset(control, word, loc, true);
                        }
                    }

                    // always set selection end word
                    _selectionEnd = word;
                    if (allowPartialSelect)
                    {
                        CalculateWordCharIndexAndOffset(control, word, loc, false);
                    }

                    ClearSelection(_root);
                    if (CheckNonEmptySelection(loc, allowPartialSelect))
                    {
                        CheckSelectionDirection();
                        SelectWordsInRange(_root, _backwardSelection ? _selectionEnd : _selectionStart, _backwardSelection ? _selectionStart : _selectionEnd);
                    }
                    else
                    {
                        _selectionEnd = null;
                    }

                    _cursorChanged = true;
                    control.SetCursorIBeam();
                    control.Invalidate();
                }
            }
        }
Пример #19
0
 /// <summary>
 /// Draw the given string using the given font and foreground color at given location.
 /// </summary>
 /// <param name="str">the string to draw</param>
 /// <param name="font">the font to use to draw the string</param>
 /// <param name="color">the text color to set</param>
 /// <param name="point">the location to start string draw (top-left)</param>
 /// <param name="size">used to know the size of the rendered text for transparent text support</param>
 /// <param name="rtl">is to render the string right-to-left (true - RTL, false - LTR)</param>
 public abstract void DrawString(String str, RFont font, RColor color, RPoint point, RSize size, bool rtl);
Пример #20
0
 /// <summary>
 /// Adjust the offset of the given location by the current scroll offset.
 /// </summary>
 /// <param name="location">the location to adjust</param>
 /// <returns>the adjusted location</returns>
 private RPoint OffsetByScroll(RPoint location)
 {
     return(new RPoint(location.X - ScrollOffset.X, location.Y - ScrollOffset.Y));
 }
Пример #21
0
 //===================================================================
 //测试三角形坐标点排列的方向
 // orientation2D_Triangle(): test the orientation of a triangle
 //    Input:  three vertex points V0, V1, V2
 //    Return: >0 for counterclockwise
 //            =0 for none (degenerate)
 //            <0 for clockwise
 public static int orientation2D_Triangle(RPoint V0, RPoint V1, RPoint V2)
 {
     return(RMath.isLeft(V0, V1, V2));
 }
Пример #22
0
        /// <summary>
        /// 点在直线上
        /// </summary>
        /// <param name="rPt"></param>
        /// <param name="rLine"></param>
        /// <returns></returns>
        public static bool IsInLine(RPoint rPt, RLine rLine)
        {
            bool flag = false;

            return(flag);
        }
Пример #23
0
        /// <summary>
        /// Calculate the character index and offset by characters for the given word and given offset.<br/>
        /// If the location is below the word line then set the selection to the end.<br/>
        /// If the location is to the right of the word then set the selection to the end.<br/>
        /// If the offset is to the left of the word set the selection to the beginning.<br/>
        /// Otherwise calculate the width of each substring to find the char the location is on.
        /// </summary>
        /// <param name="control">used to create graphics to measure string</param>
        /// <param name="word">the word to calculate its index and offset</param>
        /// <param name="loc">the location to calculate for</param>
        /// <param name="inclusive">is to include the first character in the calculation</param>
        /// <param name="selectionIndex">return the index of the char under the location</param>
        /// <param name="selectionOffset">return the offset of the char under the location</param>
        private static void CalculateWordCharIndexAndOffset(RControl control, CssRect word, RPoint loc, bool inclusive, out int selectionIndex, out double selectionOffset)
        {
            selectionIndex  = 0;
            selectionOffset = 0f;
            var offset = loc.X - word.Left;

            if (word.Text == null)
            {
                // not a text word - set full selection
                selectionIndex  = -1;
                selectionOffset = -1;
            }
            else if (offset > word.Width - word.OwnerBox.ActualWordSpacing || loc.Y > DomUtils.GetCssLineBoxByWord(word).LineBottom)
            {
                // mouse under the line, to the right of the word - set to the end of the word
                selectionIndex  = word.Text.Length;
                selectionOffset = word.Width;
            }
            else if (offset > 0)
            {
                // calculate partial word selection
                int    charFit;
                double charFitWidth;
                var    maxWidth = offset + (inclusive ? 0 : 1.5f * word.LeftGlyphPadding);
                control.MeasureString(word.Text, word.OwnerBox.ActualFont, maxWidth, out charFit, out charFitWidth);

                selectionIndex  = charFit;
                selectionOffset = charFitWidth;
            }
        }
Пример #24
0
        //===================================================================

        // area2D_Triangle(): compute the area of a triangle
        //    Input:  three vertex points V0, V1, V2
        //    Return: the (float) area of T
        public static float area2D_Triangle(RPoint V0, RPoint V1, RPoint V2)
        {
            return((float)(RMath.isLeft(V0, V1, V2) / 2.0));
        }
Пример #25
0
 /// <summary>
 /// Check if the mouse is currently on the html container.<br/>
 /// Relevant if the html container is not filled in the hosted control (location is not zero and the size is not the full size of the control).
 /// </summary>
 private bool IsMouseInContainer(RPoint location)
 {
     return(location.X >= _location.X && location.X <= _location.X + _actualSize.Width && location.Y >= _location.Y + ScrollOffset.Y && location.Y <= _location.Y + ScrollOffset.Y + _actualSize.Height);
 }
Пример #26
0
        public override void DrawString(string str, RFont font, RColor color, RPoint point, RSize size, bool rtl)
        {
            var xBrush = ((BrushAdapter)_adapter.GetSolidBrush(color)).Brush;

            _g.DrawString(str, ((FontAdapter)font).Font, (XBrush)xBrush, point.X, point.Y, _stringFormat);
        }
Пример #27
0
 public static void Draw(Texture2D texture, RPoint rPosition)
 {
     Draw(texture, rPosition, Color.White);
 }
Пример #28
0
 public override RBrush GetTextureBrush(RImage image, RRect dstRect, RPoint translateTransformLocation)
 {
     return(new BrushAdapter(new XTextureBrush(((ImageAdapter)image).Image, Utils.Convert(dstRect), Utils.Convert(translateTransformLocation))));
 }
Пример #29
0
 public static Vector2 GraphicCoordinates(RPoint p)
 {
     return ScreenPosition + new Vector2(32 * p.x, 32 * p.y);
 }
Пример #30
0
 /// <summary>
 /// Convert from core point to WPF point.
 /// </summary>
 public static Point ConvertRound(RPoint p)
 {
     return(new Point((int)p.X, (int)p.Y));
 }
Пример #31
0
 private static void Draw(Texture2D texture, RPoint rPosition, Color color)
 {
     M.Draw(texture, new ZPoint(GraphicCoordinates(rPosition) - new Vector2(texture.Width/2 - 16, texture.Height - 32)), color);
 }
Пример #32
0
 /// <summary>
 /// Convert from core point to WinForms point.
 /// </summary>
 public static XPoint Convert(RPoint p)
 {
     return(new XPoint(p.X, p.Y));
 }
 public override void LineTo(double x, double y)
 {
     _graphicsPath.AddLine((float)_lastPoint.X, (float)_lastPoint.Y, (float)x, (float)y);
     _lastPoint = new RPoint(x, y);
 }
Пример #34
0
 /// <summary>
 /// Show the context menu in the given parent control at the given location.
 /// </summary><param name="parent">the parent control to show in</param><param name="location">the location to show at relative to the parent control</param>
 public abstract void Show(RControl parent, RPoint location);
Пример #35
0
 /// <summary>
 /// Init.
 /// </summary>
 /// <param name="location">the location to scroll to</param>
 public HtmlScrollEventArgs(RPoint location)
 {
     _location = location;
 }
Пример #36
0
 /// <summary>
 /// Convert from core point to WinForms point.
 /// </summary>
 public static PointF Convert(RPoint p)
 {
     return(new PointF((float)p.X, (float)p.Y));
 }
Пример #37
0
 /// <summary>
 /// Get TextureBrush object that uses the specified image and bounding rectangle.
 /// </summary>
 /// <param name="image">The Image object with which this TextureBrush object fills interiors.</param>
 /// <param name="dstRect">A Rectangle structure that represents the bounding rectangle for this TextureBrush object.</param>
 /// <param name="translateTransformLocation">The dimension by which to translate the transformation</param>
 public abstract RBrush GetTextureBrush(RImage image, RRect dstRect, RPoint translateTransformLocation);
Пример #38
0
 /// <summary>
 /// Convert from core point to WinForms point.
 /// </summary>
 public static Point ConvertRound(RPoint p)
 {
     return(new Point((int)Math.Round(p.X), (int)Math.Round(p.Y)));
 }
Пример #39
0
 public LocalPosition(LocalObject o)
     : base(o)
 {
     r = new RPoint();
     animations = new AnimationQueue();
 }
Пример #40
0
    public TextureAnimation(Texture2D texturei, Vector2 start, Vector2 finish, float gameTime)
    {
        position = new RPoint(start);
        rMove = new RMove(position, finish - start, gameTime);
        texture = texturei;

        maxFrameTime = (int)(gameTime * FramesInOneGameTime);
        frameTime = 0;
    }