public static Point GetPoint(this IScreenSize sz, IScreenSize source, Point point) { var x = (point.X - source.X) / source.Width; var y = (point.Y - source.Y) / source.Height; return(new Point(sz.X + x * sz.Width, sz.Y + y * sz.Height)); }
public ElementSize(Settings settings, IScreenSize screenSize) { _settings = settings; screenSize.ChangeSizeEvent += CalcNewSize; SpeedFactor = _settings.ElementSpeed; CalcNewSize(screenSize.Size); }
public static Point Inside(this IScreenSize sz, Point p) { var x = p.X < sz.X ? sz.X : (p.X > sz.Bounds.Right - 1) ? (sz.Bounds.Right - 1) : p.X; var y = p.Y < sz.Y ? sz.Y : (p.Y > sz.Bounds.Bottom - 1) ? (sz.Bounds.Bottom - 1) : p.Y; return(new Point(x, y)); }
public BallPresenter(IInfrastructureFactory infrastructureFactory, IScreenSize screenSize, IElementSize elementSize) { _elementSize = elementSize; _view = infrastructureFactory.Cteate(Data.Enum.Infrastructure.Ball) as IBallView; screenSize.ChangeSizeEvent += ChangeScreenSize; }
public FirstViewModel(IScreenSize screenSize, IEncode encode) { _screenSize = screenSize; Height = _screenSize.Height; Width = _screenSize.Width; _encode = encode; Foo = _encode.Encode(DateTime.Now.ToString()); }
public EnemySpawner(UnityPoolManager <Enemy, EnemyView> enemyPool, AsyncProcessor asyncProcessor, Settings settings, IScreenSize screenSize, Camera camera, IElementSize size) { _enemyPool = enemyPool; _asyncProcessor = asyncProcessor; _settings = settings; _camera = camera; _size = size; screenSize.ChangeSizeEvent += ScreenSizeChange; ScreenSizeChange(screenSize.Size); asyncProcessor.StartCoroutine(SpawnPoint()); asyncProcessor.StartCoroutine(SpawnDamage()); }
public BottomPresenter(IInfrastructureFactory infrastructureFactory, IBottom bottom, IScreenSize screenSize) { _view = infrastructureFactory.Cteate(Data.Enum.Infrastructure.Bottom) as IBottomView; _model = bottom; _view.ViewEvent += ViewEventHandler; screenSize.ChangeSizeEvent += ChangeSizeEventHandler; ChangeSizeEventHandler(screenSize.Size); _bottomEventActions = new Dictionary <string, Action>() { { BottomEvent.ButtonDown, () => _model.StartDrag() }, { BottomEvent.Drag, () => _view.SetIncline(_model.Drag()) }, { BottomEvent.ButtonUp, () => _model.EndDrag() } }; }
public BorderPresenter(IInfrastructureFactory infrastructureFactory, IBorder border, IScreenSize screenSize) { _border = border; _view = infrastructureFactory.Cteate(Data.Enum.Infrastructure.Border) as ISceneBorderView; screenSize.ChangeSizeEvent += ChangeSizeEventHandler; ChangeSizeEventHandler(screenSize.Size); }
public static IScreenSize Scale(this IScreenSize source, IScreenRatio ratio) => new ScreenScale(source, ratio);
protected ScreenSize(IScreenSize source) { Source = source; }
public ScreenLocate(IScreenSize source, Point?point = null) : base(source) { Initialize(); Location = point ?? new Point(); }
public ScreenTranslate(IScreenSize source, Vector?translation = null) : base(source) { Translation = translation ?? new Vector(); }
public ScreenRotate(IScreenSize source, int rotation = 0) : base(source) { Rotation = rotation; Initialize(); }
public static IScreenSize Locate(this IScreenSize source, Point?point = null) => new ScreenLocate(source, point);
public ScreenSizeWpf(IScreenSize source) : base(source) { }
public static IScreenSize ScaleDip(this IScreenSize source, Screen screen) => new ScreenScaleDip(source, screen);
public static IScreenSize Rotate(this IScreenSize source, int rotation) => new ScreenRotate(source, rotation);
public void DrawGraphics(IHost _host, IGame _game, bool IsDebugEnabled) { var drawables = _game.Entities.Cast<Entity>().Where(e => e.IsDrawable).OrderBy(d => d.ZIndex).Cast<IDrawable>().ToList(); // Draw graphics _host.GraphicsProvider.BeginFrame(); _screenSize = _host.GraphicsProvider.ScreenSize; _squareSize = Math.Min(_screenSize.Width, _screenSize.Height); _unitSize = _squareSize / 2.0; _midPoint = new ScreenPoint( (_screenSize.Width) / 2.0, (_screenSize.Height) / 2.0 ); // Debug if (IsDebugEnabled) { _host.GraphicsProvider.DrawDebugRectangle(new ScreenRect() { Point = new ScreenPoint( (_screenSize.Width - _squareSize) / 2.0, (_screenSize.Height - _squareSize) / 2.0 ), Size = new ScreenSize() { Width = _squareSize, Height = _squareSize } }); } drawables.ForEach(d => { var name = d.ResourceUrl; if (d._ImageSize == null) { d._ImageSize = _host.GraphicsProvider.GetImageSize(d.ResourceUrl); } var gameBounds = d.GetBounds(); // Size var wTarget = gameBounds.Width * _unitSize; var hTarget = gameBounds.Height * _unitSize; var wRatio = wTarget / d._ImageSize.Width; var hRatio = hTarget / d._ImageSize.Height; var ratio = wRatio; if (d.FitType == FitType.Fit) { ratio = Math.Min(wRatio, hRatio); } else { ratio = Math.Max(wRatio, hRatio); } var wActual = d._ImageSize.Width * ratio; var hActual = d._ImageSize.Height * ratio; var s = new ScreenSize() { Width = wActual, Height = hActual }; // Alignment var widthGap = wTarget - wActual; var heightGap = hTarget - hActual; var offsetLeft = d.Alignment.Horizontal == HorizontalAlignment.Left ? 0.0 : d.Alignment.Horizontal == HorizontalAlignment.Center ? (widthGap) * 0.5 : widthGap; var offsetTop = d.Alignment.Vertical == VerticalAlignment.Top ? 0.0 : d.Alignment.Vertical == VerticalAlignment.Middle ? (heightGap) * 0.5 : heightGap; // Top Left var screenLeft = (gameBounds.Left * _unitSize) + (_screenSize.Width / 2.0); var screenTop = (-gameBounds.Top * _unitSize) + (_screenSize.Height / 2.0); var p = new ScreenPoint(screenLeft + offsetLeft, screenTop + offsetTop); if (!(d as Entity).IsTileable) { _host.GraphicsProvider.DrawImage(name, new ScreenRect() { Point = p, Size = s }); } else { // TODO: Prerender the tiled image with an overlap border to eliminate lines between images // Tile the drawings that are needed to fill the screen // (The image should ensure that it fills the size at the tile edges) // Example: If tiling side-to-side, the image should fill and // the width should be larger than the height porportional to the actual image size // Repeat the screen rect as needed to fill the screen in the tile direction var t = d as ITileable; // Tuncate figures to ints to eliminate lines p = new ScreenPoint((int)p.X, (int)p.Y); s = new ScreenSize() { Width = (int)s.Width, Height = (int)s.Height }; if (t.TileDirection == TileDirection.Horizontal) { var positions = new List<double>(); // Start left of screen var start = p.X % s.Width; start -= s.Width; // Go past right of screen while adding while (start < _screenSize.Width) { positions.Add(start); start += s.Width; } // Draw each position positions.ForEach(p2 => _host.GraphicsProvider.DrawImage(name, new ScreenRect() { Point = new ScreenPoint(p2, p.Y), Size = s })); } else { // TODO: Implement vertical tiling throw new NotImplementedException(); } } // Debug if (IsDebugEnabled) { // Position Rect var pos = new ScreenPoint ( ((d as IPlaceable).Position.X * _unitSize) + (_screenSize.Width / 2.0), (-(d as IPlaceable).Position.Y * _unitSize) + (_screenSize.Height / 2.0) ); _host.GraphicsProvider.DrawDebugRectangle(new ScreenRect() { Point = pos, Size = new ScreenSize() { Width = 1, Height = 10 } }); _host.GraphicsProvider.DrawDebugRectangle(new ScreenRect() { Point = pos, Size = new ScreenSize() { Width = 10, Height = 1 } }); // Image Rect _host.GraphicsProvider.DrawDebugRectangle(new ScreenRect() { Point = p, Size = s }); // Box Rect var boxTopLeft = new ScreenPoint(screenLeft, screenTop); var boxSize = new ScreenSize() { Width = wTarget, Height = hTarget }; _host.GraphicsProvider.DrawDebugRectangle(new ScreenRect() { Point = boxTopLeft, Size = boxSize }); } }); _host.GraphicsProvider.EndFrame(); }
public ScreenScaleDip(IScreenSize source, Screen screen) : base(source) { Screen = screen; Initialize(); }
public ScreenScale(IScreenSize source, IScreenRatio ratio) : base(source) { Initialize(); Ratio = ratio; }
public static IScreenSize Translate(this IScreenSize source, Vector translation) => new ScreenTranslate(source, translation);