Example #1
0
			public sd2.LinearGradientBrush GetBrush(RectangleF rect)
			{
				var start = StartPoint;
				var end = EndPoint;
				if (wrapMode == GradientWrapMode.Pad)
				{
					// winforms does not support pad, so extend to fill entire drawing region
					if (transform != null)
					{
						start = transform.TransformPoint(start);
						end = transform.TransformPoint(end);
					}
					PointF min, max;
					GradientHelper.GetLinearMinMax(start, end, rect, out min, out max, true);
					var len = max.LengthTo(min);
					// find start/end pos based on entire position
					var startpos = min.LengthTo(start) / len;
					var endpos = min.LengthTo(end) / len;
					if (brush == null || lastStartPos != startpos)
					{
						lastStartPos = startpos;
						start = min;
						end = max;
						var diff = end - start;
						// account for innacuracies in system.drawing when nearing horizontal or vertical
						if (Math.Abs(diff.X) < 0.0001)
							end.X = start.X;
						if (Math.Abs(diff.Y) < 0.0001)
							end.Y = start.Y;

						brush = new sd2.LinearGradientBrush(start.ToSD(), end.ToSD(), StartColor, EndColor);
						brush.WrapMode = sd2.WrapMode.Tile;
						brush.InterpolationColors = new sd2.ColorBlend
						{
							Colors = new[]
						{
							StartColor,
							StartColor,
							EndColor,
							EndColor
						},
							Positions = new[]
						{
							0f,
							startpos,
							endpos,
							1f,
						}
						};
					}
				}
				else if (brush == null)
				{
					brush = new sd2.LinearGradientBrush(StartPoint.ToSD(), EndPoint.ToSD(), StartColor, EndColor);
					brush.WrapMode = wrapMode.ToSD();
					if (transform != null)
						brush.MultiplyTransform(transform.ToSD());
				}
				return brush;
			}
Example #2
0
        public UIView(AtlasGlobal atlas, RectangleF frame)
            : base(atlas)
        {
            Frame = frame;

            InitializeView();
        }
        protected override void DrawCore(RenderContext context, RenderItemCollection renderItems, int fromIndex, int toIndex)
        {
            var graphicsDevice = context.GraphicsDevice;
            var destination = new RectangleF(0, 0, 1, 1);

            spriteBatch.Begin(SpriteSortMode.FrontToBack, graphicsDevice.BlendStates.Opaque, graphicsDevice.SamplerStates.LinearClamp, graphicsDevice.DepthStencilStates.None);

            for(var i = fromIndex; i <= toIndex; ++i)
            {
                var background = (BackgroundComponent)renderItems[i].DrawContext;
                var texture = background.Texture;
                if (texture == null)
                    continue;
                
                var target = CurrentRenderFrame;

                var imageBufferMinRatio = Math.Min(texture.ViewWidth / (float)target.Width, texture.ViewHeight / (float)target.Height);
                var sourceSize = new Vector2(target.Width * imageBufferMinRatio, target.Height * imageBufferMinRatio);
                var source = new RectangleF((texture.ViewWidth - sourceSize.X) / 2, (texture.ViewHeight - sourceSize.Y) / 2, sourceSize.X, sourceSize.Y);

                spriteBatch.Draw(texture, destination, source, Color.White, 0, Vector2.Zero);
            }

            spriteBatch.End();
        }
Example #4
0
        public void FromLTRBTest(float left, float top, float right, float bottom)
        {
            RectangleF expected = new RectangleF(left, top, right - left, bottom - top);
            RectangleF actual = RectangleF.FromLTRB(left, top, right, bottom);

            Assert.Equal(expected, actual);
        }
Example #5
0
		/// <summary>
		/// Over de Draw
		/// </summary>
		public static void Draw (this SpriteBatch bat,
		                         Texture2D texture,
		                         RectangleF rectangle,
		                         Color color)
		{
			bat.Draw (texture, (Rectangle)rectangle, color);
		}
Example #6
0
    /// <summary>
    /// Method for creating pie chart symbols
    /// </summary>
    /// <remarks>
    /// <para>In this example we just create some random pie charts, 
    /// but it probably should be based on attributes read from the row.</para>
    ///	<para>Credits goes to gonzalo_ar for posting this in the forum</para></remarks>
    /// <param name="row"></param>
    /// <returns></returns>
    private static Bitmap GetPieChart(GeoAPI.Features.IFeature row)
    {
        // Replace polygon with a center point (this is where we place the symbol
        row.Geometry = row.Geometry.Centroid;

        // Just for the example I use random values 
        int size = rand.Next(20, 35);
        int angle1 = rand.Next(60, 180);
        int angle2 = rand.Next(angle1 + 60, 300);
        RectangleF rect = new RectangleF(0, 0, size, size);
        Bitmap b = new Bitmap(size, size);
        using (IGraphics g = Graphics.FromImage(b).G())
        {
            // Draw Pie 
            g.FillPie(Brushes.LightGreen, rect, 0, angle1);
            g.FillPie(Brushes.Pink, rect, angle1, angle2 - angle1);
            g.FillPie(Brushes.PeachPuff, rect, angle2, 360 - angle2);

            // Draw Borders 
            g.DrawPie(Pens.Green, rect, 0, angle1);
            g.DrawPie(Pens.Red, rect, angle1, angle2 - angle1);
            g.DrawPie(Pens.Orange, rect, angle2, 360 - angle2);
        }
        return b;
    }
Example #7
0
 public RenderContext Derive(RectangleF bounds, Matrix? localLayoutTransform,
     Matrix? localRenderTransform, Vector2? renderTransformOrigin,
     double localOpacity)
 {
   Matrix finalTransform = _transform.Clone();
   if (localLayoutTransform.HasValue && localLayoutTransform != Matrix.Identity)
   {
     // Layout transforms don't support translations, so center the transformation matrix at the start point
     // of the control and apply the layout transform without translation
     Vector2 origin = new Vector2(bounds.X + 0.5f*bounds.Width, bounds.Y + 0.5f*bounds.Height);
     Matrix transform = Matrix.Translation(new Vector3(-origin.X, -origin.Y, 0));
     transform *= localLayoutTransform.Value.RemoveTranslation();
     transform *= Matrix.Translation(new Vector3(origin.X, origin.Y, 0));
     finalTransform = transform * finalTransform;
   }
   if (localRenderTransform.HasValue && localRenderTransform != Matrix.Identity)
   {
     Vector2 origin = renderTransformOrigin.HasValue ? new Vector2(
         bounds.X + bounds.Width * renderTransformOrigin.Value.X,
         bounds.Y + bounds.Height * renderTransformOrigin.Value.Y) : new Vector2(bounds.X, bounds.Y);
     Matrix transform = Matrix.Translation(new Vector3(-origin.X, -origin.Y, 0));
     transform *= localRenderTransform.Value;
     transform *= Matrix.Translation(new Vector3(origin.X, origin.Y, 0));
     finalTransform = transform * finalTransform;
   }
   RenderContext result = new RenderContext(finalTransform, _opacity * localOpacity, bounds, _zOrder - 0.001f);
   return result;
 }
Example #8
0
 public QuadTree(int level, RectangleF bounds)
 {
     this.Level = level;
     this.Objects = new List<BaseEntity>();
     this.Bounds = bounds;
     this.Nodes = new QuadTree[4];
 }
Example #9
0
        private void ClientAreaChanged(Vector2 position, Vector2 size)
        {
            mPosition = position;
            mSize = size;

            mTargetRectangle = new RectangleF(position.X, position.Y, size.X, size.Y);
        }
        public override void Draw(SharpDXRenderer renderer)
        {
            base.Draw(renderer);

            if (this.ChildControls.Count == 0)
                return;

            TabHeaders = new RectangleF[ChildControls.Count];
            int idx = 0;
            Vector2 location = this.GetAbsoluteLocation();

            foreach (SharpDXControl panel in ChildControls)
            {
                Vector2 size = renderer.MeasureString(panel.Text, this.Font);
                if (idx == 0)
                    TabHeaders[idx] = new RectangleF(0, 0, (float)Math.Max(MinimumHeaderWidth, size.X + this.MarginLeft + this.MarginRight), size.Y);
                else
                    TabHeaders[idx] = new RectangleF(TabHeaders[idx - 1].X + TabHeaders[idx - 1].Width, TabHeaders[idx - 1].Y, (float)Math.Max(MinimumHeaderWidth, size.X + this.MarginLeft + this.MarginRight), size.Y);

                Vector2 tabLocation = location + new Vector2(TabHeaders[idx].X, TabHeaders[idx].Y);

                renderer.FillRectangle(this.BackColor, tabLocation, new Vector2(TabHeaders[idx].Width, TabHeaders[idx].Height));

                if (this.SelectedIndex == idx)
                    renderer.FillRectangle(this.ForeColor * 0.1f, tabLocation, new Vector2(TabHeaders[idx].Width, TabHeaders[idx].Height));

                renderer.DrawRectangle(this.ForeColor, tabLocation, new Vector2(TabHeaders[idx].Width, TabHeaders[idx].Height));
                renderer.DrawText(panel.Text, this.ForeColor, this.Font, tabLocation + Vector2.UnitX * this.MarginLeft);
                idx++;
            }
        }
		private void Init(float x1, float y1, Color color1, float x2, float y2, Color color2, LinearGradientMode linearGradientMode) {
			_gradientRectangle = new RectangleF(x1, y1, x2-x1, y2-y1);
			PointF [] points;

			switch (linearGradientMode) {
				case LinearGradientMode.Horizontal :
					Init(x1, y1, color1, x2, y1, color2, false);
					break;

				case LinearGradientMode.Vertical :
					Init(x1, y1, color1, x1, y2, color2, false);
					break;

				case LinearGradientMode.BackwardDiagonal :
					points = GetMedianeEnclosingRect(x1, y1, x2, y2, false);
					Init(points[0].X, points[0].Y, color2, points[1].X, points[1].Y, color1, false);
					break;

				case LinearGradientMode.ForwardDiagonal :
					points = GetMedianeEnclosingRect(x1, y1, x2, y2, true);
					Init(points[0].X, points[0].Y, color1, points[1].X, points[1].Y, color2, false);
					break;

				default :
					throw new ArgumentException("LinearGradientMode");
			}
		}
Example #12
0
 /// <summary>
 /// Creates a new instance of this class. This constructor gets typically called from the <see cref="Derive"/> method.
 /// </summary>
 /// <param name="transform">Combined current transformation to use in this context.</param>
 /// <param name="opacity">Combined opacity value.</param>
 /// <param name="untransformedBounds">Bounds of the element currently being rendered, in local space.</param>
 /// <param name="zOrder">Z coordinate of the currently rendered element.</param>
 public RenderContext(Matrix transform, double opacity, RectangleF untransformedBounds, float zOrder)
 {
   _zOrder = zOrder;
   _opacity = opacity;
   _transform = transform;
   SetUntransformedContentsBounds(untransformedBounds);
 }
        public override void Draw(RectangleF visibleRectangle)
        {
            var renderOrderFunction = GetRenderOrderFunction();
            var tileLocationFunction = GetTileLocationFunction();
            var firstCol = (int)Math.Floor(visibleRectangle.Left / _map.TileWidth);
            var firstRow = (int)Math.Floor(visibleRectangle.Top / _map.TileHeight);

            // +3 to cover any gaps
            var columns = Math.Min(_map.Width, (int)visibleRectangle.Width / _map.TileWidth) + 3;
            var rows = Math.Min(_map.Height, (int)visibleRectangle.Height / _map.TileHeight) + 3;

            _spriteBatch.Begin(blendState: BlendState.AlphaBlend, samplerState: SamplerState.PointClamp);

            foreach (var tile in renderOrderFunction(firstCol, firstRow, firstCol + columns, firstRow + rows))
            {
                var region = tile != null ? _map.GetTileRegion(tile.Id) : null;

                if (region != null)
                {
                    var point = tileLocationFunction(tile);
                    var destinationRectangle = new Rectangle(point.X, point.Y, region.Width, region.Height);
                    _spriteBatch.Draw(region, destinationRectangle, Color.White);
                }
            }

            _spriteBatch.End();
        }
        protected override void DrawCore(RenderContext context, RenderItemCollection renderItems, int fromIndex, int toIndex)
        {
            var graphicsDevice = context.GraphicsDevice;
            var destination = new RectangleF(0, 0, 1, 1);

            // find the last background to display with valid texture
            BackgroundComponent background = null;
            for (var i = toIndex; i >= fromIndex; --i)
            {
                background = (BackgroundComponent)renderItems[i].DrawContext;
                if (background.Texture != null)
                    break;
            }

            // Abort if not valid background component
            if (background == null || background.Texture == null)
                return;

            var texture = background.Texture;
            var target = CurrentRenderFrame;
            var imageBufferMinRatio = Math.Min(texture.ViewWidth / (float)target.Width, texture.ViewHeight / (float)target.Height);
            var sourceSize = new Vector2(target.Width * imageBufferMinRatio, target.Height * imageBufferMinRatio);
            var source = new RectangleF((texture.ViewWidth - sourceSize.X) / 2, (texture.ViewHeight - sourceSize.Y) / 2, sourceSize.X, sourceSize.Y);

            spriteBatch.Parameters.Add(BackgroundEffectKeys.Intensity, background.Intensity);
            spriteBatch.Begin(SpriteSortMode.FrontToBack, graphicsDevice.BlendStates.Opaque, graphicsDevice.SamplerStates.LinearClamp, graphicsDevice.DepthStencilStates.None, null, backgroundEffect);
            spriteBatch.Draw(texture, destination, source, Color.White, 0, Vector2.Zero);
            spriteBatch.End();
        }
Example #15
0
        public static bool Overlap(LineF line, RectangleF rect)
        {
            line.Setup();

            float tmin, tmax, tymin, tymax;

            if (line._dx >= 0)
            {
                tmin = (rect.X - line.Start.X) * line._idx;
                tmax = (rect.X + rect.Width - line.Start.X) * line._idx;
            }
            else
            {
                tmin = (rect.X + rect.Width - line.Start.X) * line._idx;
                tmax = (rect.X - line.Start.X) * line._idx;
            }
            if (line._dy >= 0)
            {
                tymin = (rect.Y - line.Start.Y) * line._idy;
                tymax = (rect.Y + rect.Height - line.Start.Y) * line._idy;
            }
            else
            {
                tymin = (rect.Y + rect.Height - line.Start.Y) * line._idy;
                tymax = (rect.Y - line.Start.Y) * line._idy;
            }
            return !((tmin > tymax) || (tymin > tmax));
        }
Example #16
0
        /// <summary>
        /// Calculates the signed depth of intersection between two rectangles.
        /// </summary>
        /// <returns>
        /// The amount of overlap between two intersecting rectangles. These
        /// depth values can be negative depending on which wides the rectangles
        /// intersect. This allows callers to determine the correct direction
        /// to push objects in order to resolve collisions.
        /// If the rectangles are not intersecting, Vector2.Zero is returned.
        /// </returns>
        public static Vector2 GetIntersectionDepth(this RectangleF rectA, RectangleF rectB)
        {
            // Calculate half sizes.
            float halfWidthA = rectA.Width / 2.0f;
            float halfHeightA = rectA.Height / 2.0f;
            float halfWidthB = rectB.Width / 2.0f;
            float halfHeightB = rectB.Height / 2.0f;

            // Calculate centers.
            Vector2 centerA = new Vector2(rectA.Left + halfWidthA, rectA.Top + halfHeightA);
            Vector2 centerB = new Vector2(rectB.Left + halfWidthB, rectB.Top + halfHeightB);

            // Calculate current and minimum-non-intersecting distances between centers.
            float distanceX = centerA.X - centerB.X;
            float distanceY = centerA.Y - centerB.Y;
            float minDistanceX = halfWidthA + halfWidthB;
            float minDistanceY = halfHeightA + halfHeightB;

            // If we are not intersecting at all, return (0, 0).
            if (Math.Abs(distanceX) >= minDistanceX || Math.Abs(distanceY) >= minDistanceY)
                return Vector2.Zero;

            // Calculate and return intersection depths.
            float depthX = distanceX > 0 ? minDistanceX - distanceX : -minDistanceX - distanceX;
            float depthY = distanceY > 0 ? minDistanceY - distanceY : -minDistanceY - distanceY;
            return new Vector2(depthX, depthY);
        }
 private void InitView(RectangleF viewArea)
 {
     BackgroundColor = UIColor.FromRGB (0xFF, 0xFF, 0xFF);
     Frame = viewArea;
     ContentSize = viewArea.Size;
     AutoresizingMask = UIViewAutoresizing.All;
 }
Example #18
0
        public HazardBox( CubeGame game,
                          World world,
                          RectangleF rec,
                          BodyType bodyType = BodyType.Static,
                          float density = 1,
                          Category categories = Constants.Categories.DEFAULT,
                          Category killCategories = Constants.Categories.ACTORS )
            : base(game, world, rec.Center.ToUnits(), 0, new HazardBoxMaker( rec.Width, rec.Height ))
        {
            mWidth = rec.Width;
            mHeight = rec.Height;

            Fixture box = FixtureFactory.AttachRectangle(
                    mWidth.ToUnits(),
                    mHeight.ToUnits(),
                    density,
                    Vector2.Zero,
                    Body,
                    new Flat() );

            Fixture killBox = box.CloneOnto( Body );
            killBox.IsSensor = true;
            killBox.UserData = new Hazard( "killbox" );

            Body.BodyType = bodyType;
            Body.CollisionCategories = categories;

            killBox.CollidesWith = killCategories;
            box.CollidesWith ^= killCategories;
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="RectangleRenderUnit" /> class.
 /// </summary>
 /// <param name="rectangle">The rectangle.</param>
 /// <param name="stroke">The stroke.</param>
 /// <param name="fill">The fill.</param>
 /// <param name="thickness">The thickness.</param>
 public RectangleRenderUnit(RectangleF rectangle, Brush stroke, Brush fill, float thickness)
 {
     this.rectangle = rectangle;
     this.stroke = stroke;
     this.fill = fill;
     this.thickness = thickness;
 }
Example #20
0
 public override void DrawRectangle(Rectangle area)
 {
     Rectangle pixelRect = device.Screen.ToPixelSpace(area);
     var sharpRect = new RectangleF(pixelRect.Left, pixelRect.Top, pixelRect.Right,
         pixelRect.Bottom);
     device.RenderTarget.FillRectangle(sharpRect, solidColorBrush);
 }
Example #21
0
		public LinearGradientBrush (RectangleF rect, Color color1, Color color2, LinearGradientMode linearGradientMode)
		{
			Status status = GDIPlus.GdipCreateLineBrushFromRect (ref rect, color1.ToArgb (), color2.ToArgb (), linearGradientMode, WrapMode.Tile, out nativeObject);
			GDIPlus.CheckStatus (status);

			rectangle = rect;
		}
Example #22
0
 public override void AddPotentialFocusableElements(RectangleF? startingRect, ICollection<FrameworkElement> elements)
 {
   // if the focus comes from outside the ListView, then we add only the lastSelectedItem to the PotentialFocusableElements
   // if the focus is inside the ListViewAlreay, then act as normal
   if (HomeMenuModel != null)
   {
     lock (_itemsHostPanel.Children.SyncRoot)
     {
       // find ListViewItem of LastSelectedItem
       foreach (FrameworkElement child in _itemsHostPanel.Children)
       {
         var item = child as ListViewItem;
         if (item != null)
         {
           // get the real ListItem from the DataContext and check if this is the currently focused item
           IDataDescriptor listItem;
           var lastSelectedItem =  HomeMenuModel.MainMenuGroupList.OfType<GroupMenuListItem>().FirstOrDefault(i => i.IsActive);
           if (item.DataContext.Evaluate(out listItem) && ReferenceEquals(listItem.Value, lastSelectedItem))
           {
             // if LastSelectedItem is not currently focused, then the focus comes from the outside, and it's the focus candidate then
             if (!ReferenceEquals(item, Screen.FocusedElement))
             {
               elements.Add(item);
               return;
             }
             break;
           }
         }
       }
     }
   }
   base.AddPotentialFocusableElements(startingRect, elements);
 }
Example #23
0
        /// <summary>
        /// returns all objects in cells that the bounding box intersects
        /// </summary>
        /// <returns>The neighbors.</returns>
        /// <param name="bounds">Bounds.</param>
        /// <param name="layerMask">Layer mask.</param>
        public HashSet<Collider> aabbBroadphase( ref RectangleF bounds, Collider excludeCollider, int layerMask )
        {
            _tempHashset.Clear();

            var p1 = cellCoords( bounds.x, bounds.y );
            var p2 = cellCoords( bounds.right, bounds.bottom );

            for( var x = p1.X; x <= p2.X; x++ )
            {
                for( var y = p1.Y; y <= p2.Y; y++ )
                {
                    var cell = cellAtPosition( x, y );
                    if( cell == null )
                        continue;

                    // we have a cell. loop through and fetch all the Colliders
                    for( var i = 0; i < cell.Count; i++ )
                    {
                        var collider = cell[i];

                        // skip this collider if it is our excludeCollider or if it doesnt match our layerMask
                        if( collider == excludeCollider || !Flags.isFlagSet( layerMask, collider.physicsLayer ) )
                            continue;

                        if( bounds.intersects( collider.bounds ) )
                            _tempHashset.Add( collider );
                    }
                }
            }

            return _tempHashset;
        }
Example #24
0
        public TextButton(string text, Vector2 position)
        {
            _centerPosition = position;
            this.Text = text;

            _area = new RectangleF(_centerPosition.X, _centerPosition.Y, 1, 1);
        }
        public void CollidesWith(RectangleF boundingBox, Action<CollisionInfo> onCollision)
        {
            var sx = (int)(boundingBox.Left / CellWidth);
            var sy = (int)(boundingBox.Top / CellHeight);
            var ex = (int)((boundingBox.Right / CellWidth) + 1);
            var ey = (int)((boundingBox.Bottom / CellHeight) + 1);

            for (var y = sy; y < ey; y++)
            {
                for (var x = sx; x < ex; x++)
                {
                    if (GetDataAt(x, y) == 0)
                        continue;

                    var cellRectangle = GetCellRectangle(x, y);
                    var intersectingRectangle = RectangleF.Intersect(cellRectangle.ToRectangleF(), boundingBox);

                    if (intersectingRectangle.IsEmpty)
                        continue;

                    var collisionInfo = new CollisionInfo
                    {
                        Row = y,
                        Column = x,
                        IntersectingRectangle = intersectingRectangle,
                        CellRectangle = cellRectangle
                    };

                    onCollision(collisionInfo);
                }
            }
        }
Example #26
0
		internal override void recalculateBounds( Collider collider )
		{
			// if we dont have rotation or dont care about TRS we use localOffset as the center so we'll start with that
			center = collider.localOffset;

			if( collider.shouldColliderScaleAndRotateWithTransform )
			{
				// we only scale lineraly being a circle so we'll use the max value
				var scale = collider.entity.transform.scale;
				var hasUnitScale = scale.X == 1 && scale.Y == 1;
				var maxScale = Math.Max( scale.X, scale.Y );
				radius = _originalRadius * maxScale;

				if( collider.entity.transform.rotation != 0 )
				{
					// to deal with rotation with an offset origin we just move our center in a circle around 0,0 with our offset making the 0 angle
					var offsetAngle = Mathf.atan2( collider.localOffset.Y, collider.localOffset.X ) * Mathf.rad2Deg;
					var offsetLength = hasUnitScale ? collider._localOffsetLength : ( collider.localOffset * collider.entity.transform.scale ).Length();
					center = Mathf.pointOnCircle( Vector2.Zero, offsetLength, collider.entity.transform.rotationDegrees + offsetAngle );
				}
			}

			position = collider.entity.transform.position + center;
			bounds = new RectangleF( position.X - radius, position.Y - radius, radius * 2f, radius * 2f );
		}
Example #27
0
        public PipeSet(Entity referencePipeEntity, float scrollSpeed, float startScrollPos, float screenWidth)
        {
            this.scrollSpeed = scrollSpeed;
            this.startScrollPos = startScrollPos;
            halfScrollWidth = screenWidth / 2f;

            // Store Entity and create another one for two rendering:
            // top and bottom sprite of pipe.
            var spriteComp = referencePipeEntity.Get<SpriteComponent>();
             bottomPipe = referencePipeEntity.Clone();
            topPipe = referencePipeEntity.Clone();
            Entity.AddChild(bottomPipe);
            Entity.AddChild(topPipe);

            var sprite = spriteComp.CurrentSprite;
            pipeWidth = sprite.SizeInPixels.X;
            pipeHeight = sprite.SizeInPixels.Y;
            halfPipeWidth = pipeWidth/2f;

            // Setup pipeCollider
            pipeCollider = new RectangleF(0, 0, pipeWidth, pipeHeight);

            // Place the top/bottom pipes relatively to the root.
            topPipe.Transform.Position.Y = -(VerticalDistanceBetweenPipe + pipeHeight) * 0.5f;
            bottomPipe.Transform.Position.Y = (VerticalDistanceBetweenPipe + pipeHeight) * 0.5f;
            bottomPipe.Transform.Rotation = Quaternion.RotationZ(MathUtil.Pi);

            ResetPipe();
        }
Example #28
0
		/// <summary>
		/// internal hack used by Particles so they can reuse a Circle for all collision checks
		/// </summary>
		/// <param name="radius">Radius.</param>
		/// <param name="position">Position.</param>
		internal void recalculateBounds( float radius, Vector2 position )
		{
			_originalRadius = radius;
			this.radius = radius;
			this.position = position;
			bounds = new RectangleF( position.X - radius, position.Y - radius, radius * 2f, radius * 2f );
		}
Example #29
0
		internal GPRECTF(RectangleF rect)
		{
			this.X = rect.X;
			this.Y = rect.Y;
			this.Width = rect.Width;
			this.Height = rect.Height;
		}
    public void AddImage(Image image) {
        // scale image
        float widthMultiplier = maxDimension / (float)image.Width;
        float heightMultiplier = maxDimension / (float)image.Height;
        float minMultiplier = Math.Min(Math.Min(widthMultiplier, heightMultiplier), 1f);
        float newWidth = minMultiplier * (float)image.Width;
        float newHeight = minMultiplier * (float)image.Height;

        // choose a random translation & rotation
        float angle = GetRandomAngle();
        PointF newDimensions = RotateAndFindNewDimensions(new PointF(newWidth, newHeight), angle);
        PointF offset = GetRandomOffset(newDimensions);
        surfaceGraphics.TranslateTransform(offset.X, offset.Y);
        surfaceGraphics.RotateTransform(angle);

        // draw borders + image
        DrawRectangle(Brushes.White, newWidth, newHeight, thickLineWidth);
        DrawRectangle(Brushes.Black, newWidth, newHeight, thinLineWidth);
        surfaceGraphics.DrawImage(image, -newWidth / 2f, -newHeight / 2f, newWidth, newHeight);

        // calculate new image boundaries
        RectangleF newBounds = new RectangleF(
            offset.X - newDimensions.X / 2f,
            offset.Y - newDimensions.Y / 2f,
            newDimensions.X,
            newDimensions.Y);

        if (surfaceBounds.HasValue) {
            surfaceBounds = Union(surfaceBounds.Value, newBounds);
        } else {
            surfaceBounds = newBounds;
        }

        surfaceGraphics.ResetTransform();
    }
Example #31
0
        public override void Render(float delta, float mouseX, float mouseY)
        {
            var editor = (GuiScreenEditor)EditorWindow.Instance.GuiScreen;

            var rect      = ClientRectangle;
            var mouseOver = false;
            // grid transparency
            int griddim = EditorSettings.GridOpacity;

            GL.Color4(Color.FromArgb(griddim, 36, 35, 33));
            Glu.RenderQuad(rect.X, rect.Y, rect.Width, rect.Height);

            var cellSize = rect.Width / 3f;
            var noteSize = cellSize * 0.75f;

            var gap = cellSize - noteSize;

            var audioTime = EditorWindow.Instance.MusicPlayer.CurrentTime.TotalMilliseconds;

            if (editor.Numpad.Toggle)
            {
                if (EditorWindow.Instance.inputState == "keyboard")
                {
                    EditorWindow.Instance.ChangeKeyMapping("numpad");
                }
            }
            else
            {
                if (EditorWindow.Instance.inputState == "numpad")
                {
                    EditorWindow.Instance.ChangeKeyMapping("keyboard");
                }
            }

            GL.Color3(0.2, 0.2, 0.2f);

            for (float y = 0; y <= 3; y++)
            {
                var ly = y * cellSize;

                Glu.RenderQuad((int)(rect.X), (int)(rect.Y + ly), rect.Width + 1, 1);
            }

            for (float x = 0; x <= 3; x++)
            {
                var lx = x * cellSize;

                Glu.RenderQuad((int)(rect.X + lx), (int)(rect.Y), 1, rect.Height + 1);
            }

            if (editor.NoteAlign.Value != 1 && editor.QuantumGridLines.Toggle)
            {
                GL.Begin(PrimitiveType.Lines);

                var div = editor.NoteAlign.Value + 1;

                for (int i = 1; i < div; i++)
                {
                    //GL.Vertex2(rect.X + rect.Width / div * i, rect.Y);
                    //GL.Vertex2(rect.X + rect.Width / div * i, rect.Y + rect.Height / div * i);

                    GL.Vertex2(rect.X + rect.Width / div * i, rect.Y);
                    GL.Vertex2(rect.X + rect.Width / div * i, rect.Y + rect.Height);

                    GL.Vertex2(rect.X, rect.Y + rect.Height / div * i);
                    GL.Vertex2(rect.X + rect.Width, rect.Y + rect.Height / div * i);
                }
                GL.End();
            }

            var fr = EditorWindow.Instance.FontRenderer;

            GL.Color3(0.2f, 0.2f, 0.2f);
            foreach (var pair in EditorWindow.Instance.KeyMapping)
            {
                if (pair.Key == Key.Y)
                {
                    continue;
                }

                var letter = pair.Key == Key.Z ? "Y/Z" : pair.Key.ToString();

                if (letter.Length > 1)
                {
                    letter = letter.Replace("Keypad", "");
                }

                var tuple = pair.Value;

                var x = rect.X + tuple.Item1 * cellSize + cellSize / 2;
                var y = rect.Y + tuple.Item2 * cellSize + cellSize / 2;

                var width  = fr.GetWidth(letter, 38);
                var height = fr.GetHeight(38);

                fr.Render(letter, (int)(x - width / 2f), (int)(y - height / 2), 38);
            }

            Note last = null;
            Note next = null;

            for (var index = 0; index < EditorWindow.Instance.Notes.Count; index++)
            {
                var note    = EditorWindow.Instance.Notes[index];
                var passed  = audioTime > note.Ms + 1;
                var visible = !passed && note.Ms - audioTime <= 750;

                if (passed)
                {
                    last = note;
                }
                else if (next == null)
                {
                    next = note;
                }

                if (!visible)
                {
                    if (passed && next != null)
                    {
                        break;
                    }

                    continue;
                }

                var x = rect.X + note.X * cellSize + gap / 2;
                var y = rect.Y + note.Y * cellSize + gap / 2;

                var progress = (float)Math.Pow(1 - Math.Min(1, (note.Ms - audioTime) / 750.0), 2);
                var noteRect = new RectangleF(x, y, noteSize, noteSize);
                OpenTK.Graphics.Color4 colora = new OpenTK.Graphics.Color4(note.Color.R, note.Color.G, note.Color.B, progress * 0.15f);
                GL.Color4(colora);
                Glu.RenderQuad(noteRect);
                OpenTK.Graphics.Color4 color = new OpenTK.Graphics.Color4(note.Color.R, note.Color.G, note.Color.B, progress);
                GL.Color4(color);
                Glu.RenderOutline(noteRect);
                if (editor.ApproachSquares.Toggle)
                {
                    var outlineSize = 4 + noteSize + noteSize * (1 - progress) * 2;
                    Glu.RenderOutline(x - outlineSize / 2 + noteSize / 2, y - outlineSize / 2 + noteSize / 2,
                                      outlineSize,
                                      outlineSize);
                }

                if (editor.GridNumbers.Toggle)
                {
                    GL.Color4(1, 1, 1, progress);
                    var s = $"{(index + 1):#,##}";
                    var w = fr.GetWidth(s, 24);
                    var h = fr.GetHeight(24);

                    fr.Render(s, (int)(noteRect.X + noteRect.Width / 2 - w / 2f),
                              (int)(noteRect.Y + noteRect.Height / 2 - h / 2f), 24);
                }

                if (!mouseOver)
                {
                    MouseOverNote = null;
                }

                if (EditorWindow.Instance.SelectedNotes.Contains(note))
                {
                    var outlineSize = noteSize + 8;

                    GL.Color4(0, 0.5f, 1f, progress);
                    Glu.RenderOutline(x - outlineSize / 2 + noteSize / 2, y - outlineSize / 2 + noteSize / 2,
                                      outlineSize, outlineSize);
                }

                if (!mouseOver && noteRect.Contains(mouseX, mouseY))
                {
                    MouseOverNote = note;
                    mouseOver     = true;

                    GL.Color3(0, 1, 0.25f);
                    Glu.RenderOutline(x - 4, y - 4, noteSize + 8, noteSize + 8);
                }
            }

            //RENDER AUTOPLAY
            if (editor.Autoplay.Toggle)
            {
                RenderAutoPlay(last, next, cellSize, rect, audioTime);
            }
        }
Example #32
0
 public static PortableRectangle ToPortable(this RectangleF rectangle)
 {
     return(new PortableRectangle(rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height));
 }
Example #33
0
        protected override void Layout()
        {
            base.Layout();
            // Set the actual layout of the component here:

            // first change the width to suit; using max to determine component visualisation style
            FixLayout();

            int s = 3; //spacing to edges and internal between boxes

            //spacer and title
            int h0 = 0;

            if (SpacerTxt1 != "")
            {
                h0            = 10;
                SpacerBounds1 = new RectangleF(Bounds.X, Bounds.Bottom + s / 2, Bounds.Width, h0);
            }

            // create annotation (x, y, z, xx, yy, zz) placeholders
            float w  = (Bounds.Width - 6 * s) / 6; // width of each check box
            int   h2 = 15;                         // height

            xTxtBounds1  = new RectangleF(Bounds.X + s, Bounds.Bottom + h0, w, h2);
            yTxtBounds1  = new RectangleF(Bounds.X + 1.5f * s + w, Bounds.Bottom + h0, w, h2);
            zTxtBounds1  = new RectangleF(Bounds.X + 2.5f * s + 2 * w, Bounds.Bottom + h0, w, h2);
            xxTxtBounds1 = new RectangleF(Bounds.X + 3f * s + 3 * w, Bounds.Bottom + h0, w + s, h2);
            yyTxtBounds1 = new RectangleF(Bounds.X + 4f * s + 4 * w, Bounds.Bottom + h0, w + s, h2);
            zzTxtBounds1 = new RectangleF(Bounds.X + 5f * s - 1 + 5 * w, Bounds.Bottom + h0, w + s, h2);

            // create check box placeholders
            int h3 = 15;

            xBounds1  = new RectangleF(Bounds.X + s / 2, Bounds.Bottom + h0 + h2, w, h3);
            yBounds1  = new RectangleF(Bounds.X + 1.5f * s + w, Bounds.Bottom + h0 + h2, w, h3);
            zBounds1  = new RectangleF(Bounds.X + 2.5f * s + 2 * w, Bounds.Bottom + h0 + h2, w, h3);
            xxBounds1 = new RectangleF(Bounds.X + 3.5f * s + 3 * w, Bounds.Bottom + h0 + h2, w, h3);
            yyBounds1 = new RectangleF(Bounds.X + 4.5f * s + 4 * w, Bounds.Bottom + h0 + h2, w, h3);
            zzBounds1 = new RectangleF(Bounds.X + 5.5f * s - 1 + 5 * w, Bounds.Bottom + h0 + h2, w, h3);

            Bounds = new RectangleF(Bounds.X, Bounds.Y, Bounds.Width, Bounds.Height + h0 + h2 + h3 + s);

            h0 = 0;
            if (SpacerTxt2 != "")
            {
                h0            = 10;
                SpacerBounds2 = new RectangleF(Bounds.X, Bounds.Bottom + s / 2, Bounds.Width, h0);
            }

            // create annotation (x, y, z, xx, yy, zz) placeholders
            xTxtBounds2  = new RectangleF(Bounds.X + s, Bounds.Bottom + h0, w, h2);
            yTxtBounds2  = new RectangleF(Bounds.X + 1.5f * s + w, Bounds.Bottom + h0, w, h2);
            zTxtBounds2  = new RectangleF(Bounds.X + 2.5f * s + 2 * w, Bounds.Bottom + h0, w, h2);
            xxTxtBounds2 = new RectangleF(Bounds.X + 3f * s + 3 * w, Bounds.Bottom + h0, w + s, h2);
            yyTxtBounds2 = new RectangleF(Bounds.X + 4f * s + 4 * w, Bounds.Bottom + h0, w + s, h2);
            zzTxtBounds2 = new RectangleF(Bounds.X + 5f * s - 1 + 5 * w, Bounds.Bottom + h0, w + s, h2);

            // create check box placeholders
            xBounds2  = new RectangleF(Bounds.X + s / 2 + 1, Bounds.Bottom + h0 + h2, w, h3);
            yBounds2  = new RectangleF(Bounds.X + 1.5f * s + w, Bounds.Bottom + h0 + h2, w, h3);
            zBounds2  = new RectangleF(Bounds.X + 2.5f * s + 2 * w, Bounds.Bottom + h0 + h2, w, h3);
            xxBounds2 = new RectangleF(Bounds.X + 3.5f * s + 3 * w, Bounds.Bottom + h0 + h2, w, h3);
            yyBounds2 = new RectangleF(Bounds.X + 4.5f * s + 4 * w, Bounds.Bottom + h0 + h2, w, h3);
            zzBounds2 = new RectangleF(Bounds.X + 5.5f * s - 1 + 5 * w, Bounds.Bottom + h0 + h2, w, h3);

            Bounds = new RectangleF(Bounds.X, Bounds.Y, Bounds.Width, Bounds.Height + h0 + h2 + h3 + s);
        }
Example #34
0
		public TiledLayerDelegate (TiledPdfView view)
		{
			this.view = view;
			bounds = view.Bounds;
		}
 public DrawingView(RectangleF rect) : base(rect)
 {
     ContentMode           = UIViewContentMode.Redraw;
     this.AutoresizingMask = UIViewAutoresizing.All;
     BackgroundColor       = UIColor.White;
 }
Example #36
0
 // masking breaks the pan-out transform with nested sub-settings panels.
 protected override bool ComputeIsMaskedAway(RectangleF maskingBounds) => false;
Example #37
0
 public static Rectangle ToRectangle(RectangleF rectF)
 {
     return(new Rectangle((int)rectF.X, (int)rectF.Y, (int)rectF.Width, (int)rectF.Height));
 }
Example #38
0
        /// <summary>
        /// DrawTab method
        /// </summary>
        /// <param name="g">Graphic Object</param>
        /// <param name="tabPage">TagPage object</param>
        /// <param name="nIndex">integer index</param>
        internal void DrawTab(Graphics g, TabPage tabPage, int nIndex)
        {
            Rectangle  recBounds   = this.GetTabRect(nIndex);
            RectangleF tabTextArea = (RectangleF)this.GetTabRect(nIndex);

            bool bSelected = (this.SelectedIndex == nIndex);

            Point[] pt = new Point[7];
            if (this.Alignment == TabAlignment.Top)
            {
                pt[0] = new Point(recBounds.Left, recBounds.Bottom);
                pt[1] = new Point(recBounds.Left, recBounds.Top + 3);
                pt[2] = new Point(recBounds.Left + 3, recBounds.Top);
                pt[3] = new Point(recBounds.Right - 3, recBounds.Top);
                pt[4] = new Point(recBounds.Right, recBounds.Top + 3);
                pt[5] = new Point(recBounds.Right, recBounds.Bottom);
                pt[6] = new Point(recBounds.Left, recBounds.Bottom);
            }
            else
            {
                pt[0] = new Point(recBounds.Left, recBounds.Top);
                pt[1] = new Point(recBounds.Right, recBounds.Top);
                pt[2] = new Point(recBounds.Right, recBounds.Bottom - 3);
                pt[3] = new Point(recBounds.Right - 3, recBounds.Bottom);
                pt[4] = new Point(recBounds.Left + 3, recBounds.Bottom);
                pt[5] = new Point(recBounds.Left, recBounds.Bottom - 3);
                pt[6] = new Point(recBounds.Left, recBounds.Top);
            }

            //----------------------------
            // fill this tab with background color
            Brush br = new SolidBrush(tabPage.BackColor);

            g.FillPolygon(br, pt);
            br.Dispose();
            //----------------------------

            //----------------------------
            // draw border
            //g.DrawRectangle(SystemPens.ControlDark, recBounds);
            g.DrawPolygon(SystemPens.ControlDark, pt);

            if (bSelected)
            {
                //----------------------------
                // clear bottom lines
                Pen pen = new Pen(tabPage.BackColor);

                switch (this.Alignment)
                {
                case TabAlignment.Top:
                    g.DrawLine(pen, recBounds.Left + 1, recBounds.Bottom, recBounds.Right - 1, recBounds.Bottom);
                    g.DrawLine(pen, recBounds.Left + 1, recBounds.Bottom + 1, recBounds.Right - 1, recBounds.Bottom + 1);
                    break;

                case TabAlignment.Bottom:
                    g.DrawLine(pen, recBounds.Left + 1, recBounds.Top, recBounds.Right - 1, recBounds.Top);
                    g.DrawLine(pen, recBounds.Left + 1, recBounds.Top - 1, recBounds.Right - 1, recBounds.Top - 1);
                    g.DrawLine(pen, recBounds.Left + 1, recBounds.Top - 2, recBounds.Right - 1, recBounds.Top - 2);
                    break;
                }

                pen.Dispose();
                //----------------------------
            }
            //----------------------------

            //----------------------------
            // draw tab's icon
            if ((tabPage.ImageIndex >= 0) && (ImageList != null) && (ImageList.Images[tabPage.ImageIndex] != null))
            {
                int nLeftMargin  = 8;
                int nRightMargin = 2;

                Image img = ImageList.Images[tabPage.ImageIndex];

                Rectangle rimage = new Rectangle(recBounds.X + nLeftMargin, recBounds.Y + 1, img.Width, img.Height);

                // adjust rectangles
                float nAdj = (float)(nLeftMargin + img.Width + nRightMargin);

                rimage.Y          += (recBounds.Height - img.Height) / 2;
                tabTextArea.X     += nAdj;
                tabTextArea.Width -= nAdj;

                // draw icon
                g.DrawImage(img, rimage);
            }
            //----------------------------

            //----------------------------
            // draw string
            StringFormat stringFormat = new StringFormat();

            stringFormat.Alignment     = StringAlignment.Center;
            stringFormat.LineAlignment = StringAlignment.Center;
            br = new SolidBrush(tabPage.ForeColor);
            g.DrawString(tabPage.Text, Font, br, tabTextArea, stringFormat);
            //----------------------------
        }
Example #39
0
 public void IntersectClip(RectangleF rect)
 {
     g.IntersectClip(rect);
 }
Example #40
0
 public void DrawRectangle(AbstractBrush brush, RectangleF rect)
 {
     Apply(brush); g.FillRectangle(this.brush, rect);
 }
Example #41
0
 public static void setClip(RectangleF limitRect)
 {
     setClip((int)limitRect.X, (int)limitRect.Y, (int)limitRect.Width, (int)limitRect.Height);
 }
Example #42
0
        public static void drawTextureImage(TextureImage textrueImage, RectangleF srcRect, RectangleF destRect, Matrix4 matrix, float alpha)
        {
            alpha = MathUtil.limitNumber(alpha, 0, 1);
            //GLGraphics.setColor((uint)(0xFFFFFF | (((int)(alpha*255))<<24)));
            GL.Color4(1.0f, 1.0f, 1.0f, alpha);
            GL.PushMatrix();
            GL.Enable(EnableCap.Texture2D);
            GL.Enable(EnableCap.LineSmooth);

            //目标尺寸
            float _dw = destRect.Width;
            float _dh = destRect.Height;

            //贴图坐标
            float txW = textrueImage.TextureWidth;
            float txH = textrueImage.TextureHight;
            float ltX = srcRect.X / txW;
            float ltY = srcRect.Y / txH;
            float rbX = (srcRect.X + srcRect.Width) / txW;
            float rbY = (srcRect.Y + srcRect.Height) / txH;

            GL.BindTexture(TextureTarget.Texture2D, textrueImage._name);
            matrixDraw.identity();
            matrixDraw.preTranslate(destRect.X, destRect.Y);
            if (matrix != null)
            {
                matrix.multiply(matrixDraw, matrixDraw);
            }
            float[] data = matrixDraw.getValue();
            GL.MultMatrix(data);
            GL.Begin(BeginMode.Quads);
            GL.TexCoord2(ltX, ltY);
            GL.Vertex3(0, 0, 0);
            GL.TexCoord2(rbX, ltY);
            GL.Vertex3(_dw, 0, 0);
            GL.TexCoord2(rbX, rbY);
            GL.Vertex3(_dw, _dh, 0);
            GL.TexCoord2(ltX, rbY);
            GL.Vertex3(0, _dh, 0);
            GL.End();


            GL.Disable(EnableCap.Texture2D);
            GL.PopMatrix();
        }
Example #43
0
 /**
  * 简易的绘图方式
  */
 public static void drawTextureImage(TextureImage textrueImage, RectangleF srcRect, float destX, float destY)
 {
     drawTextureImage(textrueImage, srcRect, new RectangleF(destX, destY, srcRect.Width, srcRect.Height), null, 1.0f);
 }
Example #44
0
		public override void Draw (RectangleF rect)
		{
			// empty (on purpose so the delegate will draw)
		}
Example #45
0
 public EllipseShape(RectangleF rect) : base(rect)
 {
 }
Example #46
0
        // 進行と描画


        /// <summary>
        ///     アイキャッチのアニメーションを進行し、アイキャッチ画像を描画する。
        /// </summary>
        protected override void 進行描画する(DeviceContext dc, StoryboardStatus 描画しないStatus)
        {
            bool すべて完了 = true;

            var preTrans = dc.Transform;

            #region " シャッター "
            //----------------
            for (int i = シャッター枚数 - 1; i >= 0; i--)
            {
                var context = this._シャッターアニメーション[i];

                if (context.ストーリーボード.Status != StoryboardStatus.Ready)
                {
                    すべて完了 = false;
                }

                if (context.ストーリーボード.Status == 描画しないStatus)
                {
                    continue;
                }

                dc.Transform =
                    Matrix3x2.Rotation(context.角度rad) *
                    Matrix3x2.Translation(context.開き中心位置 + (context.閉じ中心位置 - context.開き中心位置) * new Vector2((float)context.開to閉割合.Value)) *
                    preTrans;
                float w  = context.矩形サイズ.Width;
                float h  = context.矩形サイズ.Height;
                var   rc = new RectangleF(-w / 2f, -h / 2f, w, h);
                dc.FillRectangle(rc, context.ブラシ);
                dc.DrawRectangle(rc, this._白ブラシ, 3.0f);
            }

            dc.Transform = preTrans;
            //----------------
            #endregion

            if (null != this._ロゴ不透明度)
            {
                #region " ロゴ "
                //----------------
                if (this._ロゴボード.Status != StoryboardStatus.Ready)
                {
                    すべて完了 = false;
                }

                float 率 = this._ロゴ表示幅 / this._ロゴ.サイズ.Width;
                this._ロゴ.描画する(
                    dc,
                    this._ロゴ表示位置.Width,
                    this._ロゴ表示位置.Height,
                    透明度0to1: (float)this._ロゴ不透明度.Value,
                    X方向拡大率:  率,
                    Y方向拡大率:  率);
                //----------------
                #endregion
            }


            if (すべて完了)
            {
                if (this.現在のフェーズ == フェーズ.クローズ)
                {
                    this.現在のフェーズ = フェーズ.クローズ完了;
                }
                else if (this.現在のフェーズ == フェーズ.オープン)
                {
                    this.現在のフェーズ = フェーズ.オープン完了;
                }
            }
        }
Example #47
0
        private void WriteError(String msg, String code)
        {
            if (this.Format == WMSImageFormat.kml)
            {
                WriteKMLError(msg, code);
            }
            if (this.Exceptions == WMSExceptionType.se_xml)
            {
                String sMsg = @"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""no"" ?>
<!DOCTYPE ServiceExceptionReport SYSTEM
 ""http://www.digitalearth.gov/wmt/xml/exception_1_1_0.dtd"">
<ServiceExceptionReport version=""1.1.0"">
  <ServiceException>
    message.
  </ServiceException>     
</ServiceExceptionReport>";
                sMsg = sMsg.Replace("message.", msg);
                if (code != null)
                {
                    sMsg = sMsg.Replace("<ServiceException>", "<ServiceException code=\"" + code + "\">");
                }
                //Response.ContentType = "application/vnd.ogc.se_xml";
                //Response.Write(sMsg);
                //Response.End();
            }
            else if (this.Exceptions == WMSExceptionType.se_in_image)
            {
                Bitmap   bt = new Bitmap(this.Width, this.Height, PixelFormat.Format32bppArgb);
                Graphics g  = Graphics.FromImage(bt);
                if (!this.Transparent)
                {
                    g.Clear(this.BgColor);
                }
                else
                {
                    bt.MakeTransparent(this.BgColor);
                    g.Clear(this.BgColor);
                }
                Font       f    = new Font("Tahoma", 12, FontStyle.Regular);
                SizeF      sz   = g.MeasureString(msg, f);
                RectangleF rect = new RectangleF(5f, 5f, sz.Width, sz.Height);
                g.DrawString(msg, f, new SolidBrush(Color.Black), rect);
                g.Save();
                if (this.Format == WMSImageFormat.gif)
                {
                    bt = this.CreateTransparentGif(bt, bt.Palette);
                }
                MemoryStream oStr = new MemoryStream();
                bt.Save(oStr, SystemDrawingGetImageFormat());
                //Response.ContentType = this.MimeType;
                //byte[] img = oStr.ToArray();
                //Response.OutputStream.Write(img, 0, img.Length);
                //Response.End();
            }
            else
            {
                Bitmap   bt = new Bitmap(this.Width, this.Height, PixelFormat.Format32bppArgb);
                Graphics g  = Graphics.FromImage(bt);
                if (!this.Transparent)
                {
                    g.Clear(this.BgColor);
                }
                else
                {
                    bt.MakeTransparent(this.BgColor);
                    g.Clear(this.BgColor);
                }
                g.Save();
                if (this.Format == WMSImageFormat.gif)
                {
                    bt = this.CreateTransparentGif(bt, bt.Palette);
                }
                MemoryStream oStr = new MemoryStream();
                bt.Save(oStr, SystemDrawingGetImageFormat());
                //Response.ContentType = this.MimeType;
                //byte[] img = oStr.ToArray();
                //Response.OutputStream.Write(img, 0, img.Length);
                //Response.End();
            }
        }
Example #48
0
 private GraphicsPath FillRoundedRectangle(Graphics graphics, SolidBrush brush, RectangleF rect, int borderRadius)
 {
     throw new NotImplementedException();
 }
 protected NativeListViewBase(RectangleF frame, UICollectionViewLayout layout)
     : base(frame, layout)
 {
     Initialize();
 }
Example #50
0
 /// <summary>
 /// Creates a path rotated by the specified radians around its center.
 /// </summary>
 /// <param name="path">The path to rotate.</param>
 /// <param name="radians">The radians to rotate the path.</param>
 /// <returns>A <see cref="IPath"/> with a rotate transform applied.</returns>
 public static IPath Rotate(this IPath path, float radians)
 {
     return(path.Transform(Matrix3x2.CreateRotation(radians, RectangleF.Center(path.Bounds))));
 }
Example #51
0
 public object Create(RectangleF rectangle, Color startColor, Color endColor, float angle)
 {
     GradientHelper.GetLinearFromRectangle(rectangle, angle, out var startPoint, out var endPoint);
     return(Create(startColor, endColor, startPoint, endPoint));
 }
Example #52
0
 // --- constructors ---
 /// <summary>Creates a new character.</summary>
 /// <param name="textureCoordinates">The texture coordinates that represent the character in the underlying texture.</param>
 /// <param name="physicalSize">The physical size of the character.</param>
 /// <param name="typographicSize">The typographic size of the character.</param>
 internal OpenGlFontChar(RectangleF textureCoordinates, Size physicalSize, Size typographicSize)
 {
     this.TextureCoordinates = textureCoordinates;
     this.PhysicalSize       = physicalSize;
     this.TypographicSize    = typographicSize;
 }
Example #53
0
 /// <summary>
 /// Creates a path rotated by the specified radians around its center.
 /// </summary>
 /// <param name="path">The path to rotate.</param>
 /// <param name="radians">The radians to rotate the path.</param>
 /// <returns>A <see cref="IPath"/> with a rotate transform applied.</returns>
 public static IPathCollection Rotate(this IPathCollection path, float radians)
 {
     return(path.Transform(Matrix3x2Extensions.CreateRotation(radians, RectangleF.Center(path.Bounds))));
 }
        /// <summary>
        /// Creates a <see cref="Bitmap"/> of a <see cref="Metafile"/> instance specified in the <paramref name="metafile"/> parameter.
        /// </summary>
        /// <param name="metafile">The <see cref="Metafile"/> to convert.</param>
        /// <param name="requestedSize">The requested size of the result <see cref="Bitmap"/>.</param>
        /// <param name="antiAliased"><see langword="true"/>&#160;to create an anti-aliased result; otherwise, <see langword="false"/>.</param>
        /// <param name="keepAspectRatio"><see langword="true"/>&#160;to keep aspect ratio of the source <paramref name="metafile"/>; otherwise, <see langword="false"/>.</param>
        /// <returns>A <see cref="Bitmap"/> instance of the requested size.</returns>
        public static Bitmap ToBitmap(this Metafile metafile, Size requestedSize, bool antiAliased, bool keepAspectRatio)
        {
            if (metafile == null)
            {
                throw new ArgumentNullException(nameof(metafile), PublicResources.ArgumentNull);
            }

            if (requestedSize.Width < 1 || requestedSize.Height < 1)
            {
                throw new ArgumentOutOfRangeException(nameof(requestedSize), PublicResources.ArgumentOutOfRange);
            }

            Size      sourceSize      = metafile.Size;
            Rectangle targetRectangle = new Rectangle(Point.Empty, requestedSize);

            if (keepAspectRatio && requestedSize != sourceSize)
            {
                float ratio = Math.Min((float)requestedSize.Width / sourceSize.Width, (float)requestedSize.Height / sourceSize.Height);
                targetRectangle.Size     = new Size((int)(sourceSize.Width * ratio), (int)(sourceSize.Height * ratio));
                targetRectangle.Location = new Point((requestedSize.Width >> 1) - (targetRectangle.Width >> 1), (requestedSize.Height >> 1) - (targetRectangle.Height >> 1));
            }

            if (!antiAliased && requestedSize == targetRectangle.Size)
            {
                return(new Bitmap(metafile, requestedSize));
            }

            var result = new Bitmap(requestedSize.Width, requestedSize.Height);

            if (!antiAliased)
            {
                if (OSUtils.IsWindows)
                {
                    using (Graphics g = Graphics.FromImage(result))
                    {
                        // it can happen that metafile bounds is not at 0, 0 location
                        GraphicsUnit unit            = GraphicsUnit.Pixel;
                        RectangleF   sourceRectangle = metafile.GetBounds(ref unit);

                        // no process-wide lock occurs here because the source image is a Metafile
                        g.DrawImage(metafile, targetRectangle, sourceRectangle, unit);
                        g.Flush();
                    }
                }
                else
                {
                    // On Linux there comes a NotImplementedException for Graphics.DrawImage(metafile, ...) so creating a temp buffer
                    // Note: though this does not crash it can happen that an empty bitmap is created... at least we are future proof in case it will be fixed
                    // Note 2: The result still can be wrong if bounds is not at 0, 0 location
                    using (Bitmap buf = new Bitmap(metafile, targetRectangle.Width, targetRectangle.Height))
                        buf.DrawInto(result, targetRectangle);
                }

                return(result);
            }

            // for anti-aliasing using self resizing to prevent process-wide lock that Graphics.DrawImage would cause (even if it is slower)
            using (Bitmap bmpDouble = new Bitmap(metafile, targetRectangle.Width << 1, targetRectangle.Height << 1))
                bmpDouble.DrawInto(result, targetRectangle);

            return(result);
        }
Example #55
0
 /// <summary>
 /// Creates a path translated by the supplied postion
 /// </summary>
 /// <param name="path">The path to translate.</param>
 /// <param name="scaleX">The amount to scale along the X axis.</param>
 /// <param name="scaleY">The amount to scale along the Y axis.</param>
 /// <returns>A <see cref="IPath"/> with a translate transform applied.</returns>
 public static IPath Scale(this IPath path, float scaleX, float scaleY)
 {
     return(path.Transform(Matrix3x2.CreateScale(scaleX, scaleY, RectangleF.Center(path.Bounds))));
 }
Example #56
0
 /// <summary>
 /// Creates a path translated by the supplied postion
 /// </summary>
 /// <param name="path">The path to translate.</param>
 /// <param name="scale">The amount to scale along both the x and y axis.</param>
 /// <returns>A <see cref="IPath"/> with a translate transform applied.</returns>
 public static IPathCollection Scale(this IPathCollection path, float scale)
 {
     return(path.Transform(Matrix3x2.CreateScale(scale, RectangleF.Center(path.Bounds))));
 }
Example #57
0
        internal void RenderBackgroundInternal(
            Graphics g,
            Rectangle rect,
            Color baseColor,
            Color borderColor,
            Color innerBorderColor,
            RoundStyle style,
            int roundWidth,
            float basePosition,
            bool drawBorder,
            bool drawGlass,
            LinearGradientMode mode)
        {
            if (drawBorder)
            {
                rect.Width--;
                rect.Height--;
            }

            using (LinearGradientBrush brush = new LinearGradientBrush(
                       rect, Color.Transparent, Color.Transparent, mode))
            {
                Color[] colors = new Color[4];
                colors[0] = GetColor(baseColor, 0, 35, 24, 9);
                colors[1] = GetColor(baseColor, 0, 13, 8, 3);
                colors[2] = baseColor;
                colors[3] = GetColor(baseColor, 0, 68, 69, 54);

                ColorBlend blend = new ColorBlend();
                blend.Positions           = new float[] { 0.0f, basePosition, basePosition + 0.05f, 1.0f };
                blend.Colors              = colors;
                brush.InterpolationColors = blend;
                if (style != RoundStyle.None)
                {
                    using (GraphicsPath path =
                               GraphicsPathHelper.CreatePath(rect, roundWidth, style, false))
                    {
                        g.FillPath(brush, path);
                    }

                    if (baseColor.A > 80)
                    {
                        Rectangle rectTop = rect;

                        if (mode == LinearGradientMode.Vertical)
                        {
                            rectTop.Height = (int)(rectTop.Height * basePosition);
                        }
                        else
                        {
                            rectTop.Width = (int)(rect.Width * basePosition);
                        }
                        using (GraphicsPath pathTop = GraphicsPathHelper.CreatePath(
                                   rectTop, roundWidth, RoundStyle.Top, false))
                        {
                            using (SolidBrush brushAlpha =
                                       new SolidBrush(Color.FromArgb(80, 255, 255, 255)))
                            {
                                g.FillPath(brushAlpha, pathTop);
                            }
                        }
                    }

                    if (drawGlass)
                    {
                        RectangleF glassRect = rect;
                        if (mode == LinearGradientMode.Vertical)
                        {
                            glassRect.Y      = rect.Y + rect.Height * basePosition;
                            glassRect.Height = (rect.Height - rect.Height * basePosition) * 2;
                        }
                        else
                        {
                            glassRect.X     = rect.X + rect.Width * basePosition;
                            glassRect.Width = (rect.Width - rect.Width * basePosition) * 2;
                        }
                        ControlPaintEx.DrawGlass(g, glassRect, 170, 0);
                    }

                    if (drawBorder)
                    {
                        using (GraphicsPath path =
                                   GraphicsPathHelper.CreatePath(rect, roundWidth, style, false))
                        {
                            using (Pen pen = new Pen(borderColor))
                            {
                                g.DrawPath(pen, path);
                            }
                        }

                        rect.Inflate(-1, -1);
                        using (GraphicsPath path =
                                   GraphicsPathHelper.CreatePath(rect, roundWidth, style, false))
                        {
                            using (Pen pen = new Pen(innerBorderColor))
                            {
                                g.DrawPath(pen, path);
                            }
                        }
                    }
                }
                else
                {
                    g.FillRectangle(brush, rect);
                    if (baseColor.A > 80)
                    {
                        Rectangle rectTop = rect;
                        if (mode == LinearGradientMode.Vertical)
                        {
                            rectTop.Height = (int)(rectTop.Height * basePosition);
                        }
                        else
                        {
                            rectTop.Width = (int)(rect.Width * basePosition);
                        }
                        using (SolidBrush brushAlpha =
                                   new SolidBrush(Color.FromArgb(80, 255, 255, 255)))
                        {
                            g.FillRectangle(brushAlpha, rectTop);
                        }
                    }

                    if (drawGlass)
                    {
                        RectangleF glassRect = rect;
                        if (mode == LinearGradientMode.Vertical)
                        {
                            glassRect.Y      = rect.Y + rect.Height * basePosition;
                            glassRect.Height = (rect.Height - rect.Height * basePosition) * 2;
                        }
                        else
                        {
                            glassRect.X     = rect.X + rect.Width * basePosition;
                            glassRect.Width = (rect.Width - rect.Width * basePosition) * 2;
                        }
                        ControlPaintEx.DrawGlass(g, glassRect, 200, 0);
                    }

                    if (drawBorder)
                    {
                        using (Pen pen = new Pen(borderColor))
                        {
                            g.DrawRectangle(pen, rect);
                        }

                        rect.Inflate(-1, -1);
                        using (Pen pen = new Pen(innerBorderColor))
                        {
                            g.DrawRectangle(pen, rect);
                        }
                    }
                }
            }
        }
Example #58
0
        /// <summary>
        /// The Control is being redrawn
        /// </summary>
        protected override void OnPaint(PaintEventArgs e)
        {
            Graphics gResult = e.Graphics;

            if (!_locked)
            {
                _locked = true;
                Graphics g = Graphics.FromImage(_backBuffer);
                g.Clear(Color.Transparent);

                // drawing color band (all in case it's disabled or a half of it)
                int positionY = (chkEnabled.Checked) ? _topHandle.Position : BAND_OFFSET_Y;
                int dy        = (chkEnabled.Checked) ? _bottomHandle.Position - _topHandle.Position : Height - 2 * BAND_OFFSET_Y;

                Rectangle rect = new Rectangle(BAND_OFFSET_X, positionY, BAND_WIDTH, dy);
                if (dy > 0)
                {
                    Brush brush;
                    if (_colorFill1 != _colorFill2)
                    {
                        Color clr1 = chkEnabled.Checked ? _colorFill1 : Color.FromArgb(120, _colorFill1);
                        brush = new LinearGradientBrush(rect, clr1, clr1, LinearGradientMode.Horizontal);
                    }
                    else
                    {
                        Color clr = chkEnabled.Checked ? _colorFill1 : Color.FromArgb(120, _colorFill1);
                        brush = new SolidBrush(clr);
                    }
                    g.FillRectangle(brush, rect);
                }

                rect = new Rectangle(BAND_OFFSET_X, BAND_OFFSET_Y, BAND_WIDTH, Height - 2 * BAND_OFFSET_Y);
                Pen pen = new Pen(_colorOutline);
                g.DrawRectangle(pen, rect);

                // -------------------------------------------------
                // drawing the scale
                // -------------------------------------------------
                float step = (Height - BAND_OFFSET_Y * 2) / 9.0f;

                g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAliasGridFit;

                var color     = UseDynamicVisibility ? Color.Black : Color.Gray;
                var textBrush = new SolidBrush(color);

                for (int i = 0; i < 10; i++)
                {
                    float y = BAND_OFFSET_Y + step * i;
                    g.DrawLine(pen, (float)BAND_OFFSET_X - 5, y, BAND_OFFSET_X, y);
                    g.DrawLine(pen, (float)(BAND_OFFSET_X + BAND_WIDTH), y, BAND_OFFSET_X + BAND_WIDTH + 5, y);

                    string s    = "1×e" + (9 - i);
                    SizeF  size = g.MeasureString(s, _font);
                    size.Width += 2;
                    PointF     pos = new PointF(BAND_OFFSET_X - 5.0f - size.Width, y - size.Height / 2.0f);
                    RectangleF r   = new RectangleF(pos, size);
                    g.DrawString(s, _font, textBrush, r);
                }

                if (chkEnabled.Checked)
                {
                    if (_topHandle.Selected)
                    {
                        DrawHandle(g, _bottomHandle);
                        DrawHandle(g, _topHandle);
                    }
                    else
                    {
                        DrawHandle(g, _topHandle);
                        DrawHandle(g, _bottomHandle);
                    }
                }

                // drawing current scale
                if (_currentScale != -1.0)
                {
                    int position = Scale2Position(_currentScale);
                    Pen p        = new Pen(Color.Red); //_colorSelection
                    g.DrawRectangle(p, BAND_OFFSET_X - 3, position - 1, BAND_WIDTH + 6, 2);
                    g.FillRectangle(new SolidBrush(Color.Red), BAND_OFFSET_X - 3, position - 1, BAND_WIDTH + 6, 2);
                }

                g.Flush();

                _locked = false;
            }

            gResult.DrawImage(_backBuffer, 0, 0);

            if (_draggingIsPerformed)
            {
                gResult.Flush(FlushIntention.Sync);
            }
        }
Example #59
0
        // Cohen-Sutherland algorithm
        public static Line2D ClipToRectangle(Line2D line, RectangleF rect, out bool intersects)
        {
            int flags1 = MapSet.GetCSFieldBits(line.v1, ref rect);
            int flags2 = MapSet.GetCSFieldBits(line.v2, ref rect);

            intersects = false;

            Line2D result = line;

            while (true)
            {
                if (flags1 == 0 && flags2 == 0)
                {
                    // Line is fully inside the box
                    intersects = true;
                    return(result);
                }

                if ((flags1 & flags2) != 0)
                {
                    // Both points are in the same outer area
                    intersects = false;
                    return(new Line2D());
                }

                float x, y;
                int   outFlags = flags1 != 0 ? flags1 : flags2;
                if ((outFlags & 0x1) > 0)     // Top
                {
                    x = result.v1.x + (result.v2.x - result.v1.x) * (rect.Top - result.v1.y) / (result.v2.y - result.v1.y);
                    y = rect.Top;
                }
                else if ((outFlags & 0x2) > 0)     // Bottom
                {
                    x = result.v1.x + (result.v2.x - result.v1.x) * (rect.Bottom - result.v1.y) / (result.v2.y - result.v1.y);
                    y = rect.Bottom;
                }
                else if ((outFlags & 0x4) > 0)     // Left
                {
                    y = result.v1.y + (result.v2.y - result.v1.y) * (rect.Left - result.v1.x) / (result.v2.x - result.v1.x);
                    x = rect.Left;
                }
                else if ((outFlags & 0x8) > 0)     // Right
                {
                    y = result.v1.y + (result.v2.y - result.v1.y) * (rect.Right - result.v1.x) / (result.v2.x - result.v1.x);
                    x = rect.Right;
                }
                else
                {
                    intersects = true;
                    return(result);
                }

                if (outFlags == flags1)
                {
                    result.v1 = new Vector2D(x, y);
                    flags1    = MapSet.GetCSFieldBits(result.v1, ref rect);
                }
                else
                {
                    result.v2 = new Vector2D(x, y);
                    flags2    = MapSet.GetCSFieldBits(result.v2, ref rect);
                }
            }
        }
Example #60
0
    public HeaderRectangleActual()
    {
        Syncfusion.Windows.Forms.Diagram.Rectangle MainRect = new Syncfusion.Windows.Forms.Diagram.Rectangle(0, 0, 200, 150);
        MainRect.FillStyle.Color     = Color.White;
        MainRect.LineStyle.LineColor = Color.Black;

        Syncfusion.Windows.Forms.Diagram.Rectangle HeadContent = new Syncfusion.Windows.Forms.Diagram.Rectangle(MainRect.BoundingRectangle.Width / 2 - 50, -10, 100, 20);
        HeadContent.FillStyle.Color = Color.LightYellow;
        Syncfusion.Windows.Forms.Diagram.Label lbl = new Syncfusion.Windows.Forms.Diagram.Label();
        lbl.Text           = "Actual";
        lbl.SizeToNode     = true;
        lbl.Position       = Position.Center;
        lbl.FontStyle.Size = 12;
        lbl.FontStyle.Bold = true;
        HeadContent.Labels.Add(lbl);
        this.AppendChild(MainRect);
        this.AppendChild(HeadContent);

        Syncfusion.Windows.Forms.Diagram.Ellipse ellipse;
        ellipse = new Syncfusion.Windows.Forms.Diagram.Ellipse(10, 40, 15, 15);
        ellipse.FillStyle.Color = Color.Green;

        RectangleF rect       = new RectangleF(30, 35, 150, 25);
        TextNode   txtContent = new TextNode("=OnSchedule", rect);

        txtContent.BackgroundStyle.Color = Color.Transparent;
        txtContent.LineStyle.LineWidth   = 0;
        txtContent.FontStyle.Size        = 10;
        txtContent.ReadOnly            = true;
        txtContent.HorizontalAlignment = StringAlignment.Near;
        txtContent.VerticalAlignment   = StringAlignment.Center;
        this.AppendChild(txtContent);
        this.AppendChild(ellipse);

        ellipse = new Syncfusion.Windows.Forms.Diagram.Ellipse(10, 70, 15, 15);
        ellipse.FillStyle.Color = Color.Yellow;

        rect       = new RectangleF(30, 65, 150, 25);
        txtContent = new TextNode("=Behind Schedule", rect);
        txtContent.BackgroundStyle.Color = Color.Transparent;
        txtContent.LineStyle.LineWidth   = 0;
        txtContent.FontStyle.Size        = 10;
        txtContent.ReadOnly            = true;
        txtContent.HorizontalAlignment = StringAlignment.Near;
        txtContent.VerticalAlignment   = StringAlignment.Center;
        this.AppendChild(txtContent);
        this.AppendChild(ellipse);

        ellipse = new Syncfusion.Windows.Forms.Diagram.Ellipse(10, 100, 15, 15);
        ellipse.FillStyle.Color = Color.Red;

        rect       = new RectangleF(30, 95, 150, 25);
        txtContent = new TextNode("=Critically Behind", rect);
        txtContent.BackgroundStyle.Color = Color.Transparent;
        txtContent.LineStyle.LineWidth   = 0;
        txtContent.FontStyle.Size        = 10;
        txtContent.ReadOnly            = true;
        txtContent.HorizontalAlignment = StringAlignment.Near;
        txtContent.VerticalAlignment   = StringAlignment.Center;
        this.AppendChild(txtContent);
        this.AppendChild(ellipse);

        ellipse = new Syncfusion.Windows.Forms.Diagram.Ellipse(10, 130, 15, 15);
        ellipse.FillStyle.Color = Color.Blue;

        rect       = new RectangleF(30, 125, 120, 25);
        txtContent = new TextNode("=Complete", rect);
        txtContent.BackgroundStyle.Color = Color.Transparent;
        txtContent.LineStyle.LineWidth   = 0;
        txtContent.FontStyle.Size        = 10;
        txtContent.ReadOnly            = true;
        txtContent.HorizontalAlignment = StringAlignment.Near;
        txtContent.VerticalAlignment   = StringAlignment.Center;
        this.AppendChild(txtContent);
        this.AppendChild(ellipse);
        this.EditStyle.AllowSelect = false;
    }