Example #1
0
        // -------------------------------------------------------------------
        // LoadEventSpriteTexture
        // -------------------------------------------------------------------

        public void LoadSpriteTexture(SystemGraphic graphic)
        {
            if (!graphic.IsTileset())
            {
                MapEditor.LoadSystemGraphic(graphic, Device);
            }
        }
            // -------------------------------------------------------------------
            // OnPaint
            // -------------------------------------------------------------------

            protected override void OnPaint(PaintEventArgs e)
            {
                e.Graphics.InterpolationMode = InterpolationMode.NearestNeighbor;
                e.Graphics.PixelOffsetMode   = PixelOffsetMode.Half;

                base.OnPaint(e);

                if (Image != null)
                {
                    if (Graphic.IsTileset())
                    {
                        Size size = new Size((int)Graphic.Options[(int)SystemGraphic.OptionsEnum.TilesetWidth] * WANOK.BASIC_SQUARE_SIZE,
                                             (int)Graphic.Options[(int)SystemGraphic.OptionsEnum.TilesetHeight] * WANOK.BASIC_SQUARE_SIZE);
                        Point point = new Point((Size.Width - size.Width) / 2, (Size.Height - size.Height) / 2);
                        e.Graphics.DrawImage(Image,
                                             new Rectangle(point, size),
                                             new Rectangle(new Point((int)Graphic.Options[(int)SystemGraphic.OptionsEnum.TilesetX] * WANOK.SQUARE_SIZE,
                                                                     (int)Graphic.Options[(int)SystemGraphic.OptionsEnum.TilesetY] * WANOK.SQUARE_SIZE),
                                                           new Size((int)Graphic.Options[(int)SystemGraphic.OptionsEnum.TilesetWidth] * WANOK.SQUARE_SIZE,
                                                                    (int)Graphic.Options[(int)SystemGraphic.OptionsEnum.TilesetHeight] * WANOK.SQUARE_SIZE))
                                             , GraphicsUnit.Pixel);
                    }
                    else
                    {
                        int   frames     = (int)Graphic.Options[(int)SystemGraphic.OptionsEnum.Frames];
                        int   rows       = (int)Graphic.Options[(int)SystemGraphic.OptionsEnum.Diagonal] == 0 ? 4 : 8;
                        Size  size       = new Size((int)((Image.Size.Width / frames) * WANOK.RELATION_SIZE), (int)((Image.Size.Height / rows) * WANOK.RELATION_SIZE));
                        int   offset     = Frame % 2 == 0 ? 0 : 1;
                        Point point      = new Point((Size.Width - size.Width) / 2, ((Size.Height - size.Height) / 2) + offset);
                        int   index      = (int)Graphic.Options[(int)SystemGraphic.OptionsEnum.Index];
                        Size  frameSize  = new Size(Image.Size.Width / frames, Image.Size.Height / rows);
                        Point framePoint = Animated ? new Point(Frame * frameSize.Width, (index / frames) * frameSize.Height) : new Point((index % frames) * frameSize.Width, (index / frames) * frameSize.Height);
                        e.Graphics.DrawImage(Image, new Rectangle(point, size), new Rectangle(framePoint, frameSize), GraphicsUnit.Pixel);
                    }
                }

                if (Focused)
                {
                    e.Graphics.DrawRectangle(BorderPen, new Rectangle(ClientRectangle.X + 5, ClientRectangle.Y + 5, ClientRectangle.Width - 11, ClientRectangle.Height - 11));
                }
            }
Example #3
0
        // -------------------------------------------------------------------
        // Constructor
        // -------------------------------------------------------------------

        public DialogPreviewGraphic(SystemGraphic graphic, OptionsKind optionsKind, SystemGraphic graphicTileset = null)
        {
            InitializeComponent();

            GraphicTileset = graphicTileset;

            // Control
            Control = new DialogPreviewGraphicControl(graphic.CreateCopy());

            Text = graphic.GraphicKind.ToString() + " graphic preview";

            // list
            listView1.Select();
            listView1.HeaderStyle = ColumnHeaderStyle.None;
            ColumnHeader header = new ColumnHeader();

            header.Text = "";
            header.Name = "";
            listView1.Columns.Add(header);
            listView1.Columns[0].Width  = listView1.Size.Width - 4;
            listView1.Items[0].Selected = true;

            List <string> LocalFiles = Control.GetLocalFiles();
            List <string> RTPFiles   = Control.GetRTPFiles();

            for (int i = 0; i < LocalFiles.Count; i++)
            {
                listView1.Items.Add(Path.GetFileName(LocalFiles[i]), 0);
                if (!graphic.IsNone() && graphic.GraphicName == listView1.Items[i + 1].Text && !graphic.IsRTP)
                {
                    listView1.Items[i + 1].Selected = true;
                }
            }
            for (int i = LocalFiles.Count; i < LocalFiles.Count + RTPFiles.Count; i++)
            {
                listView1.Items.Add(Path.GetFileName(RTPFiles[i - LocalFiles.Count]), 1);
                if (!graphic.IsNone() && graphic.GraphicName == listView1.Items[i + 1].Text && graphic.IsRTP)
                {
                    listView1.Items[i + 1].Selected = true;
                }
            }

            // Picture
            PictureBox.SizeMode          = PictureBoxSizeMode.StretchImage;
            PictureBox.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor;
            PictureBox.BackColor         = WANOK.COLOR_BACKGROUND_PREVIEW_IMAGE;
            //panelPicture.Controls.Add(PictureBox);
            TilesetPictureBox.SizeMode          = PictureBoxSizeMode.StretchImage;
            TilesetPictureBox.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor;
            TilesetPictureBox.LoadTexture(graphicTileset == null ? new SystemGraphic(GraphicKind.Tileset) : graphicTileset, WANOK.RELATION_SIZE);
            TilesetPictureBox.BackColor = WANOK.COLOR_BACKGROUND_PREVIEW_IMAGE;
            if (graphic.IsTileset())
            {
                TilesetPictureBox.SetCurrentTexture((int)graphic.Options[0] * WANOK.BASIC_SQUARE_SIZE, (int)graphic.Options[1] * WANOK.BASIC_SQUARE_SIZE, (int)graphic.Options[2], (int)graphic.Options[3]);
            }
            else
            {
                TilesetPictureBox.SetCurrentTexture(0, 0, 1, 1);
            }

            // Zoom
            trackBarZoom.Minimum = -ZoomTime;
            trackBarZoom.Maximum = ZoomTime;

            // Paint groupBox
            groupBox1.Paint += MainForm.PaintBorderGroupBox;

            // Events
            AddEvent();
        }