Exemple #1
0
        public static T Create <T> (RipDocument document)
            where T : RipCommand
        {
            var type = Types.Values.FirstOrDefault(r => r.CommandType == typeof(T));

            return((T)type.Create(document));
        }
        public static void ReadCommands(this NetIncomingMessage message, RipDocument document, IList <RipCommand> commands)
        {
            var stream = message.ReadStream();
            var reader = new BinaryReader(stream);

            try {
                while (true)
                {
                    char b = (char)reader.ReadRipByte();
                    if (b == '|')
                    {
                        string op = ((char)reader.ReadRipByte()).ToString();
                        if (op == "1")
                        {
                            op += (char)reader.ReadRipByte();
                        }

                        var command = RipCommands.Create(op, document);
                        if (command != null)
                        {
                            command.Read(reader);
                            if (command.Store)
                            {
                                commands.Add(command);
                            }
                        }
                    }
                }
            } catch (EndOfStreamException) {
            }
        }
Exemple #3
0
        public void ApplyIfNeeded <T>(IList <Rectangle> updates = null)
            where T : RipOptionalCommand
        {
            var cmd = RipDocument.Create <T>();

            ApplyIfNeeded(cmd, updates);
        }
Exemple #4
0
 public RipHandler(RipDocument doc) : base(doc)
 {
     /* Disable dos aspect here *
      * if (doc.EditMode)
      *      EnableZoom = false;
      * /**/
 }
Exemple #5
0
        public override Document Create(Platform generator)
        {
            Document doc = new RipDocument(this);

            doc.Generator = generator;
            return(doc);
        }
Exemple #6
0
        public static T Create <T, CT> (RipDocument document)
            where T : RipCommand, new()
            where CT : RipCommandType
        {
            var type = Types.Values.FirstOrDefault(r => r.GetType() == typeof(CT));

            return((T)type.Create <T>(document));
        }
Exemple #7
0
        public static RipCommand Create(string id, RipDocument document)
        {
            RipCommandType type;

            if (Types.TryGetValue(id, out type))
            {
                return(type.Create(document));
            }
            return(null);
        }
Exemple #8
0
        public void Save(Stream stream, RipDocument document)
        {
            var writer = new RipWriter(stream);

            foreach (var command in document.Commands)
            {
                command.Write(writer);
            }
            writer.WriteNewCommand("#|#|#");
            writer.WriteNewLine();
        }
        public static List <RipCommand> ReadCommands(this NetIncomingMessage message, RipDocument document)
        {
            var commands = new List <RipCommand>();

            ReadCommands(message, document, commands);
            return(commands);
        }
Exemple #10
0
 public abstract RipCommand Create <R> (RipDocument document)
     where R : RipCommand, new();
Exemple #11
0
 public abstract RipCommand Create(RipDocument document);
Exemple #12
0
        public void Load(Stream stream, RipDocument document, RipHandler handler)
        {
            var reader   = new BinaryReader(stream);
            var commands = document.Commands;

            commands.Clear();
            bool lastEnableZoom = true;

            /*
             */
            if (document.AnimateView && Application.Instance != null)
            {
                document.BGI.DelayDraw = true;                 // for faster animation
                Application.Instance.Invoke(delegate {
                    //lastEnableZoom = handler.EnableZoom;
#if DESKTOP
                    handler.EnableZoom = false;
#endif
                });
            }

            try {
                var args = new WaitEventArgs();
                while (true)
                {
                    if (document.AnimateView)
                    {
                        document.OnWait(args);
                        if (args.Exit)
                        {
                            break;
                        }
                    }
                    byte b = reader.ReadRipByte();

                    /*
                     */
                    if (b == (byte)'|')
                    {
                        string op = ((char)reader.ReadRipByte()).ToString();
                        if (op == "1")
                        {
                            op += ((char)reader.ReadRipByte());
                        }
                        else if (op == "#")
                        {
                            break;                             // done reading rip!
                        }
                        var command = RipCommands.Create(op, document);
                        if (command != null)
                        {
                            command.Read(reader);
                            command.Apply();
                            if (command.Store)
                            {
                                commands.Add(command);
                            }
                        }
                    }

                    /*
                     */
                }
            } catch (EndOfStreamException) {
            } finally {
                if (document.AnimateView && Application.Instance != null)
                {
                    Application.Instance.Invoke(delegate {
                        if (document.AnimateView)
                        {
                            handler.EnableZoom = lastEnableZoom;
                        }
                    });
                }
            }
        }
Exemple #13
0
        public RipHandler(RipDocument doc) : base(doc)
        {
            /* Disable dos aspect here */
            if (doc.EditMode)
            {
                EnableZoom = false;
            }
            /**/
        }

        protected override void OnZoomChanged(EventArgs e)
        {
            base.OnZoomChanged(e);
            if (BGI != null)
            {
                BGI.Scale = new SizeF(1 / this.ZoomRatio.Width, 1 / this.ZoomRatio.Height);
            }
        }

        public RipDocument RipDocument
        {
            get { return((RipDocument)Document); }
        }

        public BGICanvas BGI
        {
            get { return(RipDocument.BGI); }
        }

        public override bool CanEdit
        {
            get { return(true); }
        }

        public override Size Size
        {
            get { return(new Size(640, 350)); }
        }

        public override SizeF Ratio
        {
            get
            {
                if (!EnableZoom)
                {
                    return(base.Ratio);
                }
                if (RipDocument.Info.DosAspect)
                {
                    return(new SizeF(1.0F, (640.0F / 350.0F) / (640.0F / 480.0F)));
                }
                else
                {
                    return(base.Ratio);
                }
            }
        }

        public override void GenerateRegion(Graphics graphics, Rectangle rectSource, Rectangle rectDest)
        {
            if (this.ZoomRatio.Width == 1 && this.ZoomRatio.Height == 1)
            {
                graphics.ImageInterpolation = ImageInterpolation.None;
            }
            else
            {
                graphics.ImageInterpolation = ImageInterpolation.Default;
            }

            if (BGI != null)
            {
                BGI.DrawRegion(graphics, rectSource, rectDest);
            }
            else if (RipDocument.Image != null)
            {
                graphics.DrawImage(RipDocument.Image, rectSource, rectDest);
            }
        }

        public override void GenerateCommands(GenerateCommandArgs args)
        {
            base.GenerateCommands(args);

            string area = args.Area;

            if (area == "viewer")
            {
                var control   = args.Control;
                var actionDos = new CheckCommand {
                    ID      = "dosAspect", MenuText = "Emulate Legacy &Aspect", ToolTip = "Stretch image vertically to emulate DOS",
                    Checked = !RipDocument.EditMode && RipDocument.Info.DosAspect,
                    Enabled = !RipDocument.EditMode
                };
                actionDos.CheckedChanged += actionDos_CheckedChanged;

                var aiView = args.Menu.Items.GetSubmenu("&View", 500);
                var aiEdit = args.Menu.Items.GetSubmenu("&Edit", 200);

                aiView.Items.Add(actionDos, 500);

                if (Generator.IsMac)
                {
                    control.MapPlatformCommand("undo", new Actions.Undo(this));
                    control.MapPlatformCommand("redo", new Actions.Redo(this));
                }
                else
                {
                    aiEdit.Items.Add(new Actions.Undo(this), 100);
                    aiEdit.Items.Add(new Actions.Redo(this), 100);
                }
            }
        }

        protected override Control CreateViewerControl()
        {
            var control = new ViewerPane(this, false);

#if DESKTOP
            if (this.Document.EditMode)
            {
                control.Viewer.Cursor = new Cursor(CursorType.Crosshair);
            }
#endif
            control.SizeChanged += delegate
            {
                //Console.WriteLine ("What the f!");
                //if (BGI != null)
                //	BGI.ResetGraphics ();
            };

            /*if (Generator.IsMac) {
             *      // ugh
             *      control.Scroll += delegate {
             *              if (BGI != null)
             *                      BGI.ResetGraphics ();
             *      };
             * }*/
            return(control);
        }