Beispiel #1
0
 public CityBarRenderer(Group parent,
                        IRendererControl viewport)
 {
     this.viewport             = viewport ?? throw new ArgumentNullException(nameof(viewport));
     this.parent               = parent ?? throw new ArgumentNullException(nameof(parent));
     this.pool                 = new Stack <CityBarWidget>();
     this.widgetsByMapPosition = new Dictionary <MapCoordinate, CityBarWidget>();
 }
Beispiel #2
0
        public MonoGameRenderer(IGraphicsDeviceService graphicsDeviceService,
                                IRendererControl viewport)
        {
            Viewport    = viewport ?? throw new ArgumentNullException(nameof(viewport));
            SpriteBatch = new SpriteBatch(graphicsDeviceService.GraphicsDevice);

            this.GraphicsDeviceService = graphicsDeviceService;
            offsetsBySpritePosition    = SpritePositionExtensions.OffsetsFor(viewport.ActiveRenderType);

            tileSize = viewport.TileSize;

            enableScissorTest = RasterizerState.CullCounterClockwise.Copy();
            enableScissorTest.ScissorTestEnable = true;
        }
Beispiel #3
0
        /// <summary>
        ///  Calculates the difference in pixels between the available space on screen
        ///  and the numbers of tiles rendered. A MapViewPort only deals with full
        ///  tiles, but correct rendering with smooth scrolling requires fractional
        ///  tiles to offset the rendered content on screen.
        /// </summary>
        /// <returns></returns>
        public static IntPoint CalculateTileOffset(this IRendererControl viewport)
        {
            var ctr = viewport.Bounds;
            var tileSize = viewport.TileSize;

            // Calculate the number of full tiles rendered in each direction in pixel units.
            var cw = Math.Ceiling(ctr.Width / tileSize.Width) * tileSize.Width;
            var ch = Math.Ceiling(ctr.Height / tileSize.Height) * tileSize.Height;
            // Calculate excess to the available screen space (how many pixels of overdraw do we have)
            var rmx = cw - ctr.Width;
            var rmy = ch - ctr.Height;
            // .. reduce by half to get the offset on the top/left size
            var rdx = (int)Math.Round(rmx / 2);
            var rdy = (int)Math.Round(rmy / 2);

            return new IntPoint(-rdx + (int)ctr.X, -rdy + (int)ctr.Y);
        }