public static SwitchDrawable Create(SvgSwitch svgSwitch, Rect skOwnerBounds, DrawableBase?parent, IAssetLoader assetLoader, Attributes ignoreAttributes = Attributes.None) { var drawable = new SwitchDrawable(assetLoader) { Element = svgSwitch, Parent = parent, IgnoreAttributes = ignoreAttributes }; drawable.IsDrawable = drawable.CanDraw(svgSwitch, drawable.IgnoreAttributes) && drawable.HasFeatures(svgSwitch, drawable.IgnoreAttributes); if (!drawable.IsDrawable) { return(drawable); } foreach (var child in svgSwitch.Children) { if (!child.IsKnownElement()) { continue; } var hasRequiredFeatures = child.HasRequiredFeatures(); var hasRequiredExtensions = child.HasRequiredExtensions(); var hasSystemLanguage = child.HasSystemLanguage(); if (hasRequiredFeatures && hasRequiredExtensions && hasSystemLanguage) { var childDrawable = DrawableFactory.Create(child, skOwnerBounds, parent, assetLoader, ignoreAttributes); if (childDrawable is { })
private void PopulateFactory() { DrawableFactory.AddStrategy("Line", Line.FromTokenString); DrawableFactory.AddStrategy("Circle", Circle.FromTokenString); DrawableFactory.AddStrategy("Rectangle", Rectangle.FromTokenString); DrawableFactory.AddStrategy("Composite", CompositeShape.FromTokenString); DrawableFactory.AddStrategy("Connector", Connector.FromTokenString); }
public Ellipse(double r, int dim = 2) { Vector <double> rad = new Vector <double>(dim); for (int i = 0; i < dim; i++) { rad[i] = r; } this.r = rad; myDraw = DrawableFactory.MakeEllipse(this.r, new GraphicsStyle(null, Pens.Red)); }
public static SP.Picture?ToModel(SvgFragment svgFragment) { var size = SvgExtensions.GetDimensions(svgFragment); var bounds = SP.Rect.Create(size); using var drawable = DrawableFactory.Create(svgFragment, bounds, null, Attributes.None); if (drawable == null) { return(null); } drawable.PostProcess(); if (bounds.IsEmpty) { var drawableBounds = drawable.Bounds; bounds = SP.Rect.Create( 0f, 0f, Math.Abs(drawableBounds.Left) + drawableBounds.Width, Math.Abs(drawableBounds.Top) + drawableBounds.Height); } return(drawable.Snapshot(bounds)); }
public static MarkerDrawable Create(SvgMarker svgMarker, SvgVisualElement pOwner, Point pMarkerPoint, float fAngle, Rect skOwnerBounds, DrawableBase?parent, IAssetLoader assetLoader, Attributes ignoreAttributes = Attributes.None) { var drawable = new MarkerDrawable(assetLoader) { Element = svgMarker, Parent = parent, IgnoreAttributes = Attributes.Display | ignoreAttributes, IsDrawable = true }; if (!drawable.IsDrawable) { return(drawable); } var markerElement = drawable.GetMarkerElement(svgMarker); if (markerElement is null) { drawable.IsDrawable = false; return(drawable); } var skMarkerMatrix = Matrix.CreateIdentity(); var skMatrixMarkerPoint = Matrix.CreateTranslation(pMarkerPoint.X, pMarkerPoint.Y); skMarkerMatrix = skMarkerMatrix.PreConcat(skMatrixMarkerPoint); var skMatrixAngle = Matrix.CreateRotationDegrees(svgMarker.Orient.IsAuto ? fAngle : svgMarker.Orient.Angle); skMarkerMatrix = skMarkerMatrix.PreConcat(skMatrixAngle); var strokeWidth = pOwner.StrokeWidth.ToDeviceValue(UnitRenderingType.Other, svgMarker, skOwnerBounds); var refX = svgMarker.RefX.ToDeviceValue(UnitRenderingType.Horizontal, svgMarker, skOwnerBounds); var refY = svgMarker.RefY.ToDeviceValue(UnitRenderingType.Vertical, svgMarker, skOwnerBounds); var markerWidth = svgMarker.MarkerWidth.ToDeviceValue(UnitRenderingType.Other, svgMarker, skOwnerBounds); var markerHeight = svgMarker.MarkerHeight.ToDeviceValue(UnitRenderingType.Other, svgMarker, skOwnerBounds); var viewBoxToMarkerUnitsScaleX = 1f; var viewBoxToMarkerUnitsScaleY = 1f; switch (svgMarker.MarkerUnits) { case SvgMarkerUnits.StrokeWidth: { var skMatrixStrokeWidth = Matrix.CreateScale(strokeWidth, strokeWidth); skMarkerMatrix = skMarkerMatrix.PreConcat(skMatrixStrokeWidth); var viewBoxWidth = svgMarker.ViewBox.Width; var viewBoxHeight = svgMarker.ViewBox.Height; var scaleFactorWidth = viewBoxWidth <= 0 ? 1 : markerWidth / viewBoxWidth; var scaleFactorHeight = viewBoxHeight <= 0 ? 1 : markerHeight / viewBoxHeight; viewBoxToMarkerUnitsScaleX = Math.Min(scaleFactorWidth, scaleFactorHeight); viewBoxToMarkerUnitsScaleY = Math.Min(scaleFactorWidth, scaleFactorHeight); var skMatrixTranslateRefXY = Matrix.CreateTranslation(-refX * viewBoxToMarkerUnitsScaleX, -refY * viewBoxToMarkerUnitsScaleY); skMarkerMatrix = skMarkerMatrix.PreConcat(skMatrixTranslateRefXY); var skMatrixScaleXY = Matrix.CreateScale(viewBoxToMarkerUnitsScaleX, viewBoxToMarkerUnitsScaleY); skMarkerMatrix = skMarkerMatrix.PreConcat(skMatrixScaleXY); } break; case SvgMarkerUnits.UserSpaceOnUse: { var skMatrixTranslateRefXY = Matrix.CreateTranslation(-refX, -refY); skMarkerMatrix = skMarkerMatrix.PreConcat(skMatrixTranslateRefXY); } break; } switch (svgMarker.Overflow) { case SvgOverflow.Auto: case SvgOverflow.Visible: case SvgOverflow.Inherit: break; default: drawable.MarkerClipRect = Rect.Create( svgMarker.ViewBox.MinX, svgMarker.ViewBox.MinY, markerWidth / viewBoxToMarkerUnitsScaleX, markerHeight / viewBoxToMarkerUnitsScaleY); break; } var markerElementDrawable = DrawableFactory.Create(markerElement, skOwnerBounds, drawable, assetLoader, Attributes.Display); if (markerElementDrawable is { })
static Point() { pointShape = DrawableFactory.MakeCircle(1, new GraphicsStyle(Brushes.Red, null)); }
static DemoHelper() { ParticleShape.Default.Tag = new GlListDrawable(DrawableFactory.CreateSprite(Cache <Surface> .GetItem("particle.png"), new Vector2D(8, 8))); }
public MainForm() { InitializeComponent(); entSpawn = new EntitySpawner(); hitby = new DefaultValueDictionary <Entity, bool>(false); double border = 40; Particle boxC = (Particle)(new Vector <double>((double)ClientRectangle.Width / 2, (double)ClientRectangle.Height / 2)); Particle boxR = (Particle)(new Vector <double>((double)ClientRectangle.Width / 2 + border, (double)ClientRectangle.Height / 2 + border)); Box bgbox = new Box(boxR); EntityClass bgClass = new EntityClass("Background"); bg = new Entity(0, boxC, bgbox, new GraphicsStyle(Brushes.Black), bgClass); bsm = new BulletStyleManager(); InitializeBulletStyles(); keyMan = new KeyManager(); InitializeKeyManager(); int vx = 1, vx2 = 2; int vy = 2, vy2 = 4; Drawable mchar = DrawableFactory.MakeCircle(8, new GraphicsStyle(Brushes.Orange, Pens.Red)); game = new Game(new MainChar(mchar, bsm["MainChar"], ClientRectangle.Width / 2, ClientRectangle.Height - 20, 40)); InitializePhysicsManager(game.PhysicsManager); InitializeRenderManager(game.RenderManager); Particle p1 = new Particle(x => vx * x, y => vy * y); Particle p2 = new Particle(Utils.MakeClosure <double, double, double>(ClientRectangle.Width, (w, x) => w - vx2 * x), y => vy2 * y); Particle q = new Particle(t => 7 * t + 10 * Utils.FastCos(t), t => 3 * t + 10 * Utils.FastSin(t)); Ellipse entEl = new Ellipse(7); o1 = entEl.MakeDrawable(new GraphicsStyle(Brushes.Green)); double FULL = 2 * Math.PI; double cd = 1; int perCirc = 12; int offsets = 6; BulletEmission[] bEms = new BulletEmission[offsets], bEms2 = new BulletEmission[offsets]; double DOWN = Math.PI / 2; // Makes the spiral pattern with bullets of shape o2 Trajectory[][] arrs = new Trajectory[offsets][]; for (int i = 0; i < offsets; i++) { arrs[i] = new Trajectory[perCirc]; } for (int i = 0; i < perCirc; i++) { for (int j = 0; j < offsets; j++) { arrs[j][i] = TrajectoryFactory.AngleMagVel((i * offsets + j) * (FULL / offsets / perCirc) + DOWN, 10); } } for (int i = 0; i < offsets; i++) { bEms[i] = new BulletEmission(cd, 0, arrs[i], bsm["OrangeRed_5"]); } // Same as above, but we're gonna change the shape for (int i = 0; i < offsets; i++) { arrs[i] = new Trajectory[perCirc]; } for (int i = 0; i < perCirc; i++) { for (int j = 0; j < offsets; j++) { arrs[j][i] = TrajectoryFactory.AngleMagVel((i * offsets + j) * (FULL / offsets / perCirc) + DOWN, 10); } } for (int i = 0; i < offsets; i++) { bEms2[i] = new BulletEmission(cd, 0, arrs[i], bsm["Azure_5"]); } // Same as above, but we're gonna change the shape again and the path BulletEmission[] bEms3 = new BulletEmission[offsets]; for (int i = 0; i < offsets; i++) { arrs[i] = new Trajectory[perCirc]; } for (int i = 0; i < perCirc; i++) { for (int j = 0; j < offsets; j++) { arrs[j][i] = TrajectoryFactory.SpinningLinearAMVel((i * offsets + j) * (FULL / offsets / perCirc) + DOWN, 7 /*3*/, 0.5, 20); } } for (int i = 0; i < offsets; i++) { bEms3[i] = new BulletEmission(cd, 0, arrs[i], bsm["HotPink_5"]); } EntityClass enemyBullet = new EntityClass("EnemyBullet", "Bullet"); EntityClass enemy = new EntityClass("Enemy", "Character"); BulletEmitter em = new BulletEmitter(new BulletPattern(bEms, enemyBullet)); BulletEmitter em2 = new BulletEmitter(new BulletPattern(bEms2, enemyBullet)); BulletEmitter em3 = new BulletEmitter(new BulletPattern(bEms3, enemyBullet)); entSpawn.MakeType("RedSpiral", null, o1, entEl, enemy, em); e = entSpawn.Build("RedSpiral", 0, p1); e2 = entSpawn.Build("RedSpiral", 0, p2); Particle p3 = new Particle(x => 0.5 * x + 500, y => 3 * y); Entity e3 = entSpawn.Build("RedSpiral", 0, p3); Particle p4 = new Particle(x => - 0.25 * x + 300, y => 3.5 * y); Entity e4 = entSpawn.Build("RedSpiral", 0, p4); Particle p5 = new Particle(x => - 0.4 * x + 800, y => 2 * y); Entity e5 = entSpawn.Build("RedSpiral", 0, p5); game += bg; game = game + e + e2 + e3 + e4 + e5; entSpawn["WhiteSpiral"] = entSpawn["RedSpiral"].ChangeEmitter(em2, true); entSpawn["PinkWaves"] = entSpawn["RedSpiral"].ChangeEmitter(em3, true); //entSpawn.MakeType("WhiteSpinningSpiral",null, o1, entEl, enemy, em2); Entity e6 = entSpawn.Build("WhiteSpiral", 0, q); game += e6; Particle r = new Particle(Utils.MakeClosure <double, double, double>((double)ClientRectangle.Width / 3, (w, t) => w + 3 * t), t => 5 * t); Entity e7 = entSpawn.Build("PinkWaves", 0, r); game += e7; game.ResetTime(); BufferedGraphicsContext c = BufferedGraphicsManager.Current; buff = c.Allocate(CreateGraphics(), ClientRectangle); }
public Ellipse(Particle rad) { r = rad; myDraw = DrawableFactory.MakeEllipse(r, new GraphicsStyle(null, Pens.Red)); }
public Box(Particle rad) { r = rad; myDraw = DrawableFactory.MakeCenteredRectangle(r, new GraphicsStyle(null, Pens.Red)); }