コード例 #1
0
        public void DrawBuffer()
        {
            Graphics draw = Graphics.FromImage(_buffer);

            //Draw grid
            draw.Clear(Color.White);

            if (Settings.WhiteSpace)
            {
                draw.DrawImage(Source, new Rectangle(new Point(Settings.Step, Settings.Step), new Size(Source.Width, Source.Height)),
                               new Rectangle(0, 0, Source.Width, Source.Height), GraphicsUnit.Pixel);
            }
            else
            {
                draw.DrawImage(Source, new Point(0, 0));
            }
            var widthCount  = Source.Width / Settings.Step;
            var heightCount = Source.Height / Settings.Step;

            if (Settings.WhiteSpace)
            {
                widthCount++; heightCount++;
            }
            var pen = new Pen(Settings.Color, Settings.LineWidth);

            pen.DashPattern = Settings.GetDashPattern();
            pen.DashStyle   = Settings.DashStyle;
            Markers.IMarker horizontal = new Markers.NumberMarker();
            switch (Settings.HorizontalMarkerType)
            {
            case Markers.MarkerTypes.String:
                horizontal = new Markers.StringMarker(); break;
            }
            horizontal.Refresh(Settings.HorizontalStart, Settings.HorizontalStep);
            for (int i = 1; i < widthCount; i++)
            {
                draw.DrawLine(pen, i * Settings.Step, 0, i * Settings.Step, _buffer.Height);
                var   text      = horizontal.Next();
                var   sizeText  = draw.MeasureString(text, Settings.Font.FontValue);
                Point textpoint = new Point(i * Settings.Step + (Settings.Step - (int)sizeText.Width) / 2, (Settings.Step - (int)sizeText.Height) / 2);
                draw.DrawString(text, Settings.Font.FontValue, new SolidBrush(Settings.ColorFont), textpoint);
            }

            Markers.IMarker vertical = new Markers.NumberMarker();
            switch (Settings.VerticalMarkerType)
            {
            case Markers.MarkerTypes.String:
                vertical = new Markers.StringMarker(); break;
            }
            vertical.Refresh(Settings.VerticalStart, Settings.VerticalStep);
            for (int i = 1; i < widthCount; i++)
            {
                draw.DrawLine(pen, 0, i * Settings.Step, _buffer.Width, i * Settings.Step);
                var   text      = vertical.Next();
                var   sizeText  = draw.MeasureString(text, Settings.Font.FontValue);
                Point textpoint = new Point((Settings.Step - (int)sizeText.Width) / 2, i * Settings.Step + (Settings.Step - (int)sizeText.Height) / 2);
                draw.DrawString(text, Settings.Font.FontValue, new SolidBrush(Settings.ColorFont), textpoint);
            }
            Invalidate();
        }
コード例 #2
0
ファイル: Document.cs プロジェクト: stdcallua/mapedit
        public void DrawBuffer()
        {
            Graphics draw = Graphics.FromImage(_buffer);
            //Draw grid
            draw.Clear(Color.White);
            if (Settings.WhiteSpace)
                draw.DrawImage(Source, new Point(Settings.Step, Settings.Step));
            else
                draw.DrawImage(Source, new Point(0, 0));
            var widthCount = Source.Width / Settings.Step;
            var heightCount = Source.Height / Settings.Step;
            if (Settings.WhiteSpace)
            {
                widthCount++; heightCount++;
            }
            var pen = new Pen(Settings.Color, Settings.LineWidth);
            pen.DashPattern = Settings.GetDashPattern();
            pen.DashStyle = Settings.DashStyle;
            Markers.IMarker horizontal = new Markers.NumberMarker();
            switch (Settings.HorizontalMarkerType)
            {
                case Markers.MarkerTypes.String:
                    horizontal = new Markers.StringMarker(); break;
            }
            horizontal.Refresh(Settings.HorizontalStart, Settings.HorizontalStep);
            for (int i = 1; i < widthCount; i++)
            {
                draw.DrawLine(pen, i * Settings.Step, 0, i * Settings.Step, _buffer.Height);
                var text = horizontal.Next();
                var sizeText = draw.MeasureString(text, Settings.Font.FontValue);
                Point textpoint = new Point(i * Settings.Step + (Settings.Step - (int)sizeText.Width) / 2, (Settings.Step- (int)sizeText.Height)/2);
                draw.DrawString(text, Settings.Font.FontValue, new SolidBrush(Settings.Color), textpoint);
            }

            Markers.IMarker vertical = new Markers.NumberMarker();
            switch (Settings.VerticalMarkerType)
            {
                case Markers.MarkerTypes.String:
                    vertical = new Markers.StringMarker(); break;
            }
            vertical.Refresh(Settings.VerticalStart, Settings.VerticalStep);
            for (int i = 1; i < widthCount; i++)
            {
                draw.DrawLine(pen, 0, i * Settings.Step, _buffer.Width, i * Settings.Step);
                var text = vertical.Next();
                var sizeText = draw.MeasureString(text, Settings.Font.FontValue);
                Point textpoint = new Point((Settings.Step - (int)sizeText.Width) / 2, i * Settings.Step + (Settings.Step - (int)sizeText.Height) / 2);
                draw.DrawString(text, Settings.Font.FontValue, new SolidBrush(Settings.Color), textpoint);

            }
            Invalidate();
        }