예제 #1
0
        /// <summary>
        /// Draws the specified <see cref="CatalogManager.Catalog"/> tile to the <see
        /// cref="PaintBuffer"/>, with alpha blending and color substitution.</summary>
        /// <param name="dest">
        /// The location within the <see cref="PaintBuffer"/> where to draw.</param>
        /// <param name="region">
        /// The bitmap region within the <see cref="CatalogManager.Catalog"/> to copy, relative to
        /// the tile with the specified <paramref name="index"/>.</param>
        /// <param name="index">
        /// The <see cref="CatalogManager.Catalog"/> index of the tile to draw.</param>
        /// <param name="color">
        /// The <see cref="Color"/> whose color channels are substituted for those of all <see
        /// cref="CatalogManager.Catalog"/> pixels, retaining only their alpha channel.</param>

        private void DrawTile(PointI dest, RectI region, int index, Color color)
        {
            // add upper-left corner of catalog tile
            region = region.Offset(MapView.GetTileLocation(index));

            // copy visible part of catalog tile to buffer
            PaintBuffer.Overlay(dest.X, dest.Y, MapView.Catalog, region, color);
        }
예제 #2
0
        private void DrawColorBoxes()
        {
            if (UseBitmapBuffer)
            {
                PaintBuffer.Clear();
            }
            else
            {
                PaintBitmap.Lock();
                PaintBitmap.Clear();
            }

            int step = PaintBuffer.Size.Height / _colors.Length;

            // draw color boxes on left side of bitmap
            for (int i = 0; i < _colors.Length; i++)
            {
                Color opaque      = _colors[i];
                Color translucent = Color.FromArgb(63, opaque.R, opaque.G, opaque.B);

                // draw translucent variant to the right of opaque color
                RectI opaqueBounds      = new RectI(0, i * step, _opaqueWidth, step);
                RectI translucentBounds = new RectI(
                    _opaqueWidth, i * step, _translucentWidth - _opaqueWidth, step);

                if (UseBitmapBuffer)
                {
                    PaintBuffer.Clear(opaqueBounds, opaque);
                    PaintBuffer.Clear(translucentBounds, translucent);
                }
                else
                {
                    PaintBitmap.Clear(opaqueBounds, opaque);
                    PaintBitmap.Clear(translucentBounds, translucent);
                }
            }

            if (UseBitmapBuffer)
            {
                PaintBuffer.Write();
            }
            else
            {
                PaintBitmap.Unlock();
            }
        }
예제 #3
0
        private void DrawOnBitmap(MouseEventArgs args, PointI p)
        {
            RectI bounds = RectI.Empty;

            if (!UseBitmapBuffer)
            {
                PaintBitmap.Lock();
            }

            if (args.LeftButton == MouseButtonState.Pressed)
            {
                bounds = new RectI(p.X, p.Y, 1, 1);
                DrawPixel(p.X, p.Y, PaintColor);
            }
            else if (args.RightButton == MouseButtonState.Pressed)
            {
                const int r = 4;

                // define rectangle around cursor position
                int x0 = Math.Max(_translucentWidth, p.X - r), y0 = Math.Max(0, p.Y - r),
                    x1 = Math.Min(PaintBuffer.Size.Width - 1, p.X + r),
                    y1 = Math.Min(PaintBuffer.Size.Height - 1, p.Y + r);

                bounds = new RectI(x0, y0, x1 - x0 + 1, y1 - y0 + 1);
                for (int x = x0; x <= x1; x++)
                {
                    for (int y = y0; y <= y1; y++)
                    {
                        DrawPixel(x, y, PaintColor);
                    }
                }
            }

            if (UseBitmapBuffer)
            {
                PaintBuffer.Write(bounds);
            }
            else
            {
                PaintBitmap.Unlock();
            }
        }
예제 #4
0
        private void OnBitmapMouseDown(object sender, MouseButtonEventArgs args)
        {
            args.Handled = true;

            PointI p = GetBitmapPosition(args);

            if (p.X >= _translucentWidth)
            {
                DrawOnBitmap(args, p);
            }
            else if (p.X >= 0)
            {
                // obtain new painting color from color box
                PaintColor = (UseBitmapBuffer ?
                              PaintBuffer.GetPixel(p.X, p.Y) :
                              PaintBitmap.GetPixel(p.X, p.Y));

                SelectDrawPixel();
            }
        }
예제 #5
0
        /// <summary>
        /// Implements <see cref="Action.OnMouseMove"/>. If you override this method
        /// don't forget to call the bas implementation.
        /// </summary>
        /// <param name="e"><paramref name="Action.OnMouseMove.e"/></param>
        /// <param name="vw"><paramref name="Action.OnMouseMove.vw"/></param>
        public override void OnMouseMove(MouseEventArgs e, IView vw)
        {
            switch (Mode)
            {
            case 0:
                activeView = vw;
                vw.Invalidate(PaintBuffer.DrawingAspect.Active, Rectangle.FromLTRB(vw.DisplayRectangle.Left, FirstPoint.Y, vw.DisplayRectangle.Right, FirstPoint.Y + 1));
                vw.Invalidate(PaintBuffer.DrawingAspect.Active, Rectangle.FromLTRB(FirstPoint.X, vw.DisplayRectangle.Top, FirstPoint.X + 1, vw.DisplayRectangle.Bottom));
                FirstPoint = new Point(e.X, e.Y);
                vw.Invalidate(PaintBuffer.DrawingAspect.Active, Rectangle.FromLTRB(vw.DisplayRectangle.Left, FirstPoint.Y, vw.DisplayRectangle.Right, FirstPoint.Y + 1));
                vw.Invalidate(PaintBuffer.DrawingAspect.Active, Rectangle.FromLTRB(FirstPoint.X, vw.DisplayRectangle.Top, FirstPoint.X + 1, vw.DisplayRectangle.Bottom));
                break;

            case 1:
                Rectangle Clip = PaintBuffer.RectangleFromPoints(FirstPoint, SecondPoint, new Point(e.X, e.Y));
                Clip.Width  += 1;
                Clip.Height += 1;
                vw.Invalidate(PaintBuffer.DrawingAspect.Active, Clip);
                SecondPoint = new Point(e.X, e.Y);
                break;
            }
        }
예제 #6
0
        /// <summary>
        /// Renders the visual content of the <see cref="MapViewRenderer"/>.</summary>
        /// <param name="context">
        /// The <see cref="DrawingContext"/> for the rendering.</param>
        /// <remarks><para>
        /// <b>OnRender</b> calls the base class implementation of <see cref="UIElement.OnRender"/>,
        /// and then immediately returns if the associated <see cref="MapView"/> has not been fully
        /// initialized yet, or already been disposed of.
        /// </para><para>
        /// Otherwise, <b>OnRender</b> redraws the current <see cref="MapViewControl.Viewport"/>.
        /// The <see cref="Graphics.MapView.Extent"/> of the associated <see cref="MapView"/>
        /// outside the current <see cref="MapViewControl.Viewport"/> remains empty.
        /// </para></remarks>

        protected override void OnRender(DrawingContext context)
        {
            base.OnRender(context);
            if (MapView.Catalog == null || MapView.IsDisposed)
            {
                return;
            }

            // check if there is anything to render
            Rect viewRegion = Control.Viewport;

            if (viewRegion.Width == 0 || viewRegion.Height == 0)
            {
                return;
            }

            // distance from center point to upper-left corner
            double centerX = MapView.TileWidth / 2.0;
            double centerY = MapView.TileHeight / 2.0;

            // compute sites covered by viewport
            RectD region     = viewRegion.ToRectD();
            RectI intRegion  = region.Circumscribe();
            RectI siteRegion = MapView.ViewToSite(region);

            // resize & clear paint buffer
            bool mustClear = EnsureBufferSize(intRegion.Size);

            PaintBuffer.Lock();
            if (mustClear)
            {
                PaintBuffer.Clear();
            }

            // cache performance options
            this._bitmapGrid   = ApplicationOptions.Instance.View.BitmapGrid;
            this._opaqueImages = ApplicationOptions.Instance.View.OpaqueImages;

            // draw entities of all sites within region
            for (int x = siteRegion.Left; x < siteRegion.Right; x++)
            {
                for (int y = siteRegion.Top; y < siteRegion.Bottom; y++)
                {
                    Site site = MapView.WorldState.Sites[x, y];

                    // compute upper-left corner of bitmap tile
                    PointD display = MapView.SiteToView(site.Location);
                    PointI pixel   = new PointI(
                        Fortran.NInt(display.X - centerX),
                        Fortran.NInt(display.Y - centerY));

                    // draw entities in current site
                    DrawEntities(pixel, intRegion, site);
                }
            }

            // copy paint buffer to viewport
            PaintBuffer.Unlock();
            context.DrawImage(PaintBuffer,
                              new Rect(region.Left, region.Top, PaintBuffer.Width, PaintBuffer.Height));

            // draw optional decoration on all sites
            DrawDecoration(context, siteRegion);
        }