Example #1
0
        private void BuildImage(Frame frm)
        {
            if (frm != null)
            {
                
                Bitmap newImage;

                Rectangle destRect;

                newImage = new Bitmap(256, 192);

                Graphics g = Graphics.FromImage(newImage);

                if (_disableTransparency) g.CompositingMode = CompositingMode.SourceCopy;
                else g.CompositingMode = CompositingMode.SourceOver;

                g.CompositingQuality = CompositingQuality.Default;
                g.InterpolationMode = InterpolationMode.NearestNeighbor;
                g.SmoothingMode = SmoothingMode.None;


                if (_backgroundStyle == BackgroundStyle.Image)
                {
                    if (_currentBackground != "")
                    {
                        if (!File.Exists(_currentBackground))
                        {
                            _currentBackground = "";
                            SaveConfig();
                        }
                        else
                        {
                            Bitmap bmpSourceBG = new Bitmap(_currentBackground);

                            destRect = new Rectangle(0, 0, bmpSourceBG.Width, bmpSourceBG.Height);

                            g.DrawImage(bmpSourceBG, destRect, 0, 0, bmpSourceBG.Width, bmpSourceBG.Height, GraphicsUnit.Pixel, null);
                        }
                    }
                }
                else if (_backgroundStyle == BackgroundStyle.Black)
                {
                    g.FillRectangle(Brushes.Black, 0, 0, newImage.Width, newImage.Height);
                }
                else if (_backgroundStyle == BackgroundStyle.Green)
                {
                    g.FillRectangle(Brushes.Green, 0, 0, newImage.Width, newImage.Height);
                }
                else if (_backgroundStyle == BackgroundStyle.Red)
                {
                    g.FillRectangle(Brushes.Red, 0, 0, newImage.Width, newImage.Height);
                }
                else if (_backgroundStyle == BackgroundStyle.Blue)
                {
                    g.FillRectangle(Brushes.Blue, 0, 0, newImage.Width, newImage.Height);
                }
                else if (_backgroundStyle == BackgroundStyle.White)
                {
                    g.FillRectangle(Brushes.White, 0, 0, newImage.Width, newImage.Height);
                }


                Bitmap bmpSourceSprite = new Bitmap(frm.Path);

                int w = bmpSourceSprite.Width;
                int h = bmpSourceSprite.Height;

                int x = frm.EffectiveX;
                int y = frm.EffectiveY;

                destRect = new Rectangle(x, y, w, h);

                g.DrawImage(bmpSourceSprite, destRect, 0, 0, w, h, GraphicsUnit.Pixel, null);


                if (!_disableHelpers)
                {
                    if (udX1.Value > 0)
                        g.DrawLine(Pens.Black, (int)udX1.Value, 0, (int)udX1.Value, pictureBox1.Height);

                    if (udX2.Value > 0)
                        g.DrawLine(Pens.Black, (int)udX2.Value, 0, (int)udX2.Value, pictureBox1.Height);

                    if (udY1.Value > 0)
                        g.DrawLine(Pens.Black, 0, (int)udY1.Value, pictureBox1.Width, (int)udY1.Value);

                    if (udY2.Value > 0)
                        g.DrawLine(Pens.Black, 0, (int)udY2.Value, pictureBox1.Width, (int)udY2.Value);
                }

                g.Dispose();

                frm.Width = (UInt16)w;
                frm.Height = (UInt16)h;
                frm.ImageCache = newImage;
                frm.Dirty = false;

            }
        }
Example #2
0
        private void LoadDirectory()
        {
            if (_currentPath != "")
            {
                Application.UseWaitCursor = true;

                toolStripStatusLabel1.Text = "Loading";

                _characters.Clear();

                try
                {

                    Bitmap tmpBitmap;

                    DirectoryInfo dir = new DirectoryInfo(_currentPath);

                    foreach (FileInfo file in dir.GetFiles("*.png"))
                    {
                        string[] filenameparts = file.Name.Split(new char[] { '.' });

                        string[] elements = filenameparts[0].Split(new char[] { '_' });

                        if (elements.Length == 4)
                        {

                            Character character = _characters.FindByName(elements[0]);
                            if (character == null)
                            {
                                character = new Character(elements[0]);
                                _characters.Add(character);
                            }

                            Group group = character.Groups.FindByName(elements[1]);
                            if (group == null)
                            {
                                group = new Group(elements[1]);
                                character.Groups.Add(group);
                            }

                            Animation animation = group.Animations.FindByID(elements[2]);
                            if (animation == null)
                            {
                                animation = new Animation(elements[2]);
                                group.Animations.Add(animation);
                                group.Animations.Sort();
                            }

                            Frame frame = animation.Frames.FindByID(int.Parse(elements[3]));
                            if (frame == null)
                            {
                                frame = new Frame(UInt16.Parse(elements[3]));
                                frame.Path = file.FullName;
                                animation.Frames.Add(frame);
                                animation.Frames.Sort();

                                tmpBitmap = new Bitmap(_currentPath + "\\" + file.Name);
                                frame.Width = (ushort)tmpBitmap.Width;
                                frame.Height = (ushort)tmpBitmap.Height;
                            }

                        }
                        else
                        {
                            // MessageBox.Show("Invalid Filename: " + file.Name, "Warning", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        }
                    }


                    LoadData();

                    Display();

                    SaveConfig();

                }

                catch
                {
                    MessageBox.Show("Error loading directory " + _currentPath, "Flipbook", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }

                //finally
                //{
                //    
                //}

                Application.UseWaitCursor = false;
                toolStripStatusLabel1.Text = "Ready";
                
            }

        }
Example #3
0
        private void DisplayFrame(Frame frm)
        {
            if (frm != null)
            {
                _currentFrame = frm;

                int index;

                index = _currentAnimation.Frames.IndexOf(frm);

                if (index >= 0)
                {
                    _currentAnimation.LastSelectedFrame = _currentFrame;
                    // System.Diagnostics.Debug.WriteLine(_currentAnimation.ID + " -> " + _currentFrame.ID);
                    _updateSliderEventDisable = true;
                    tbFramePosition.Value = index;
                    _updateSliderEventDisable = false;

                    txtFrameNo.Text = tbFramePosition.Value.ToString();

                    udFrameOffsetX.Value = _currentFrame.OffsetX;
                    udFrameOffsetY.Value = _currentFrame.OffsetY;
                    udFrameDelay.Value = _currentFrame.Delay;

                    txtFrameHeight.Text = _currentFrame.Height.ToString();
                    txtFrameWidth.Text = _currentFrame.Width.ToString();
                    txtFrameEffectiveX.Text = _currentFrame.EffectiveX.ToString();
                    txtFrameEffectiveY.Text = _currentFrame.EffectiveY.ToString();
                    txtFrameEffectiveDelay.Text = _currentFrame.EffectiveDelay.ToString();

                    if (_currentFrame.Dirty) BuildImage(_currentFrame);

                    pictureBox1.Image = _currentFrame.ImageCache;

                    if (_zoomform != null) _zoomform.ShowImage(_currentFrame.ImageCache);
                }
                else
                {
                    MessageBox.Show("Bing");
                }
            }
        }
Example #4
0
        private void DisplayAnimation(Animation ani)
        {
            timer1.Stop();
            _currentAnimation = ani;
            _currentAnimation.AllFramesDirty();

            ddbID.Text = _currentAnimation.ID.ToString();
            
            txtAnimationFrames.Text = _currentAnimation.FrameCount.ToString();

            // muss vor DisplayFrame gesetzt werden, sonst evtl Überlauf
            _updateSliderEventDisable = true;
            tbFramePosition.Value = 0;
            _updateSliderEventDisable = false;
            tbFramePosition.Maximum = _currentAnimation.FrameCount - 1;

            if (_currentAnimation.Frames.Count > 0)
            {
                if (_currentAnimation.LastSelectedFrame != null)
                {
                    DisplayFrame(_currentAnimation.LastSelectedFrame);
                }
                else
                {
                    DisplayFrame(_currentAnimation.Frames[0]);
                }
            }
            else
            {
                _currentFrame = null;
            }

            // muss nach DisplayFrame gesetzt werden, sonst mehrfaches BuildImage durch ValueChange-Ereignisse
            udAnimationPositionX.Value = _currentAnimation.PositionX;
            udAnimationPositionY.Value = _currentAnimation.PositionY;
            udAnimationDelay.Value = _currentAnimation.Delay;
        }
Example #5
0
        private void Display()
        {
            ddbCharacter.DropDownItems.Clear();
            ddbCharacter.Text = "(none)";

            ddbGroup.DropDownItems.Clear();
            ddbGroup.Text = "(none)";

            ddbID.DropDownItems.Clear();
            ddbID.Text = "(none)";

            _currentAnimation = null;
            _currentFrame = null;
            
            foreach (Character chr in _characters)
            {
               ToolStripMenuItem itm = new ToolStripMenuItem();
               itm.DisplayStyle = ToolStripItemDisplayStyle.Text;
               itm.Text = chr.Name;
               itm.Tag = chr;
               ddbCharacter.DropDownItems.Add(itm);
            }
            if (_characters.Count > 0) DisplayCharacter(_characters[0]);
            else
            {
                ddbCharacter.Text = "(none)";
            }
            
        }
Example #6
0
 public int IndexOf(Frame value)
 {
     return (base.IndexOf(value));
 }
Example #7
0
 public int Add(Frame objItemToAdd)
 {
     return (base.Add(objItemToAdd));
 }