Пример #1
0
        public static void Load(XmlElementReader element)
        {
            var colors = element["colors"];

            foreach (var color in colors.Children)
            {
                int index;
                if (Colors.FromName(color.Name, out index))
                {
                    Color[index] = color.ToColor(Color[index]);
                }
            }

            var regions = element["regions"];

            Regions = new List <Region>();

            if (regions.Children.Count <= 0)
            {
                Regions.Add(new Region {
                    RColor = System.Drawing.Color.White, TextColor = System.Drawing.Color.Blue, RegionName = Region.DefaultRegion
                });
            }
            else
            {
                foreach (var region in regions.Children)
                {
                    var tRegion = new Region();
                    tRegion.TextColor = region.Attribute("TextColor").Text == string.Empty ? System.Drawing.Color.Blue : ColorTranslator.FromHtml(region.Attribute("TextColor").Text);

                    var node = region.Attribute("name");
                    tRegion.RegionName = node != null && node.Text != string.Empty ? node.Text : region.Name;

                    tRegion.RegionName = tRegion.ClearRegionNameObfuscation();
                    tRegion.RColor     = region.ToColor(System.Drawing.Color.White);
                    Regions.Add(tRegion);
                }
            }
            var fonts = element["fonts"];

            foreach (var font in fonts.Children)
            {
                var style = FontStyle.Regular;
                if (font.Attribute("bold").ToBool())
                {
                    style |= FontStyle.Bold;
                }
                if (font.Attribute("italic").ToBool())
                {
                    style |= FontStyle.Italic;
                }
                if (font.Attribute("underline").ToBool())
                {
                    style |= FontStyle.Underline;
                }
                if (font.Attribute("strikeout").ToBool())
                {
                    style |= FontStyle.Strikeout;
                }
                if (font.Name == "room")
                {
                    LargeFont = new Font(font.ToText(LargeFont.Name), Numeric.Clamp(font.Attribute("size").ToFloat(LargeFont.Size), MinFontSize, MaxFontSize), style, GraphicsUnit.World);
                }
                else if (font.Name == "object")
                {
                    SmallFont = new Font(font.ToText(SmallFont.Name), Numeric.Clamp(font.Attribute("size").ToFloat(SmallFont.Size), MinFontSize, MaxFontSize), style, GraphicsUnit.World);
                }
                else if (font.Name == "line")
                {
                    LineFont = new Font(font.ToText(SmallFont.Name), Numeric.Clamp(font.Attribute("size").ToFloat(LineFont.Size), MinFontSize, MaxFontSize), style, GraphicsUnit.World);
                }
            }

            SnapToGrid    = element["grid"]["snapTo"].ToBool(s_snapToGrid);
            IsGridVisible = element["grid"]["visible"].ToBool(s_isGridVisible);
            GridSize      = element["grid"]["size"].ToFloat(s_gridSize);
            ShowOrigin    = element["grid"]["showOrigin"].ToBool(s_showOrigin);

            LineWidth                = element["lines"]["width"].ToFloat(s_lineWidth);
            HandDrawn                = element["lines"]["handDrawn"].ToBool(HandDrawnUnchecked);
            ConnectionArrowSize      = element["lines"]["arrowSize"].ToFloat(s_connectionArrowSize);
            TextOffsetFromConnection = element["lines"]["textOffset"].ToFloat(s_textOffsetFromConnection);

            DarknessStripeSize            = element["rooms"]["darknessStripeSize"].ToFloat(s_darknessStripeSize);
            ObjectListOffsetFromRoom      = element["rooms"]["objectListOffset"].ToFloat(s_objectListOffsetFromRoom);
            ConnectionStalkLength         = element["rooms"]["connectionStalkLength"].ToFloat(s_connectionStalkLength);
            PreferredDistanceBetweenRooms = element["rooms"]["preferredDistanceBetweenRooms"].ToFloat(s_connectionStalkLength * 2); // introduced in v1.2, hence default based on existing setting

            HandleSize        = element["ui"]["handleSize"].ToFloat(s_handleSize);
            SnapToElementSize = element["ui"]["snapToElementSize"].ToFloat(s_snapToElementSize);

            KeypadNavigationCreationModifier   = StringToModifierKeys(element["keypadNavigation"]["creationModifier"].Text, s_keypadNavigationCreationModifier);
            KeypadNavigationUnexploredModifier = StringToModifierKeys(element["keypadNavigation"]["unexploredModifier"].Text, s_keypadNavigationUnexploredModifier);
        }
Пример #2
0
        public static void Load(XmlElementReader element)
        {
            var colors = element["colors"];

            foreach (var color in colors.Children)
            {
                int index;
                if (Colors.FromName(color.Name, out index))
                {
                    Color[index] = color.ToColor(Color[index]);
                }
            }

            var fonts = element["fonts"];

            foreach (var font in fonts.Children)
            {
                var style = FontStyle.Regular;
                if (font.Attribute("bold").ToBool())
                {
                    style |= FontStyle.Bold;
                }
                if (font.Attribute("italic").ToBool())
                {
                    style |= FontStyle.Italic;
                }
                if (font.Attribute("underline").ToBool())
                {
                    style |= FontStyle.Underline;
                }
                if (font.Attribute("strikeout").ToBool())
                {
                    style |= FontStyle.Strikeout;
                }
                if (font.Name == "room")
                {
                    LargeFont = new Font(font.ToText(LargeFont.Name), Numeric.Clamp(font.Attribute("size").ToFloat(LargeFont.Size), MinFontSize, MaxFontSize), style, GraphicsUnit.World);
                }
                else if (font.Name == "object")
                {
                    SmallFont = new Font(font.ToText(SmallFont.Name), Numeric.Clamp(font.Attribute("size").ToFloat(SmallFont.Size), MinFontSize, MaxFontSize), style, GraphicsUnit.World);
                }
                else if (font.Name == "line")
                {
                    LineFont = new Font(font.ToText(SmallFont.Name), Numeric.Clamp(font.Attribute("size").ToFloat(LineFont.Size), MinFontSize, MaxFontSize), style, GraphicsUnit.World);
                }
            }

            SnapToGrid    = element["grid"]["snapTo"].ToBool(s_snapToGrid);
            IsGridVisible = element["grid"]["visible"].ToBool(s_isGridVisible);
            GridSize      = element["grid"]["size"].ToFloat(s_gridSize);
            ShowOrigin    = element["grid"]["showOrigin"].ToBool(s_showOrigin);

            LineWidth                = element["lines"]["width"].ToFloat(s_lineWidth);
            HandDrawn                = element["lines"]["handDrawn"].ToBool(s_handDrawn);
            ConnectionArrowSize      = element["lines"]["arrowSize"].ToFloat(s_connectionArrowSize);
            TextOffsetFromConnection = element["lines"]["textOffset"].ToFloat(s_textOffsetFromConnection);

            DarknessStripeSize            = element["rooms"]["darknessStripeSize"].ToFloat(s_darknessStripeSize);
            ObjectListOffsetFromRoom      = element["rooms"]["objectListOffset"].ToFloat(s_objectListOffsetFromRoom);
            ConnectionStalkLength         = element["rooms"]["connectionStalkLength"].ToFloat(s_connectionStalkLength);
            PreferredDistanceBetweenRooms = element["rooms"]["preferredDistanceBetweenRooms"].ToFloat(s_connectionStalkLength * 2); // introduced in v1.2, hence default based on existing setting

            HandleSize        = element["ui"]["handleSize"].ToFloat(s_handleSize);
            SnapToElementSize = element["ui"]["snapToElementSize"].ToFloat(s_snapToElementSize);

            KeypadNavigationCreationModifier   = StringToModifierKeys(element["keypadNavigation"]["creationModifier"].Text, s_keypadNavigationCreationModifier);
            KeypadNavigationUnexploredModifier = StringToModifierKeys(element["keypadNavigation"]["unexploredModifier"].Text, s_keypadNavigationUnexploredModifier);
        }
Пример #3
0
        private void saveImage(string fileName)
        {
            var format = ImageFormat.Png;
            var ext    = Path.GetExtension(fileName);

            if (StringComparer.InvariantCultureIgnoreCase.Compare(ext, ".jpg") == 0 ||
                StringComparer.InvariantCultureIgnoreCase.Compare(ext, ".jpeg") == 0)
            {
                format = ImageFormat.Jpeg;
            }
            else if (StringComparer.InvariantCultureIgnoreCase.Compare(ext, ".bmp") == 0)
            {
                format = ImageFormat.Bmp;
            }
            else if (StringComparer.InvariantCultureIgnoreCase.Compare(ext, ".emf") == 0)
            {
                format = ImageFormat.Emf;
            }

            var size = Canvas.ComputeCanvasBounds(true).Size *(Settings.SaveAt100 ? 1.0f : Canvas.ZoomFactor);

            size.X = Numeric.Clamp(size.X, 16, 8192);
            size.Y = Numeric.Clamp(size.Y, 16, 8192);

            try
            {
                if (format == ImageFormat.Emf)
                {
                    // export as a metafile
                    using (var nativeGraphics = Graphics.FromHwnd(Canvas.Handle))
                    {
                        using (var stream = new MemoryStream())
                        {
                            try
                            {
                                var dc = nativeGraphics.GetHdc();
                                using (var metafile = new Metafile(stream, dc))
                                {
                                    using (var imageGraphics = Graphics.FromImage(metafile))
                                    {
                                        using (var graphics = XGraphics.FromGraphics(imageGraphics, new XSize(size.X, size.Y)))
                                        {
                                            Canvas.Draw(graphics, true, size.X, size.Y);
                                        }
                                    }
                                    var handle = metafile.GetHenhmetafile();
                                    var copy   = CopyEnhMetaFile(handle, fileName);
                                    DeleteEnhMetaFile(copy);
                                }
                            }
                            finally
                            {
                                nativeGraphics.ReleaseHdc();
                            }
                        }
                    }
                }
                else
                {
                    // export as an image
                    using (var bitmap = new Bitmap((int)Math.Ceiling(size.X), (int)Math.Ceiling(size.Y)))
                    {
                        using (var imageGraphics = Graphics.FromImage(bitmap))
                        {
                            using (var graphics = XGraphics.FromGraphics(imageGraphics, new XSize(size.X, size.Y)))
                            {
                                Canvas.Draw(graphics, true, size.X, size.Y);
                            }
                        }
                        bitmap.Save(fileName, format);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(Program.MainForm, string.Format("There was a problem exporting the map:\n\n{0}", ex.Message),
                                Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Пример #4
0
        private void FileExportImageMenuItem_Click(object sender, EventArgs e)
        {
            using (var dialog = new SaveFileDialog())
            {
                dialog.Filter           = "PNG Images|*.png|JPEG Images|*.jpg|BMP Images|*.bmp|Enhanced Metafiles (EMF)|*.emf|All Files|*.*||";
                dialog.Title            = "Export Image";
                dialog.InitialDirectory = PathHelper.SafeGetDirectoryName(Settings.LastExportImageFileName);
                if (dialog.ShowDialog() == DialogResult.OK)
                {
                    Settings.LastExportImageFileName = dialog.InitialDirectory;

                    var format = ImageFormat.Png;
                    var ext    = Path.GetExtension(dialog.FileName);
                    if (StringComparer.InvariantCultureIgnoreCase.Compare(ext, ".jpg") == 0 ||
                        StringComparer.InvariantCultureIgnoreCase.Compare(ext, ".jpeg") == 0)
                    {
                        format = ImageFormat.Jpeg;
                    }
                    else if (StringComparer.InvariantCultureIgnoreCase.Compare(ext, ".bmp") == 0)
                    {
                        format = ImageFormat.Bmp;
                    }
                    else if (StringComparer.InvariantCultureIgnoreCase.Compare(ext, ".emf") == 0)
                    {
                        format = ImageFormat.Emf;
                    }

                    var size = m_canvas.ComputeCanvasBounds(true).Size *m_canvas.ZoomFactor;
                    size.X = Numeric.Clamp(size.X, 16, 8192);
                    size.Y = Numeric.Clamp(size.Y, 16, 8192);

                    try
                    {
                        if (format == ImageFormat.Emf)
                        {
                            // export as a metafile
                            using (var nativeGraphics = Graphics.FromHwnd(m_canvas.Handle))
                            {
                                using (var stream = new MemoryStream())
                                {
                                    try
                                    {
                                        var dc = nativeGraphics.GetHdc();
                                        using (var metafile = new Metafile(stream, dc))
                                        {
                                            using (var imageGraphics = Graphics.FromImage(metafile))
                                            {
                                                using (var graphics = XGraphics.FromGraphics(imageGraphics, new XSize(size.X, size.Y)))
                                                {
                                                    m_canvas.Draw(graphics, true, size.X, size.Y);
                                                }
                                            }
                                            var handle = metafile.GetHenhmetafile();
                                            var copy   = CopyEnhMetaFile(handle, dialog.FileName);
                                            DeleteEnhMetaFile(copy);
                                        }
                                    }
                                    finally
                                    {
                                        nativeGraphics.ReleaseHdc();
                                    }
                                }
                            }
                        }
                        else
                        {
                            // export as an image
                            using (var bitmap = new Bitmap((int)Math.Ceiling(size.X), (int)Math.Ceiling(size.Y)))
                            {
                                using (var imageGraphics = Graphics.FromImage(bitmap))
                                {
                                    using (var graphics = XGraphics.FromGraphics(imageGraphics, new XSize(size.X, size.Y)))
                                    {
                                        m_canvas.Draw(graphics, true, size.X, size.Y);
                                    }
                                }
                                bitmap.Save(dialog.FileName, format);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(Program.MainForm, string.Format("There was a problem exporting the map:\n\n{0}", ex.Message), Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
        }