예제 #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));
        }
예제 #2
0
        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) {
            }
        }
예제 #3
0
        public void ApplyIfNeeded <T>(IList <Rectangle> updates = null)
            where T : RipOptionalCommand
        {
            var cmd = RipDocument.Create <T>();

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

            doc.Generator = generator;
            return(doc);
        }
예제 #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));
        }
예제 #7
0
        public static RipCommand Create(string id, RipDocument document)
        {
            RipCommandType type;

            if (Types.TryGetValue(id, out type))
            {
                return(type.Create(document));
            }
            return(null);
        }
예제 #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();
        }
예제 #9
0
        public static List <RipCommand> ReadCommands(this NetIncomingMessage message, RipDocument document)
        {
            var commands = new List <RipCommand>();

            ReadCommands(message, document, commands);
            return(commands);
        }
예제 #10
0
 public abstract RipCommand Create <R> (RipDocument document)
     where R : RipCommand, new();
예제 #11
0
 public abstract RipCommand Create(RipDocument document);
예제 #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;
                        }
                    });
                }
            }
        }
예제 #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);
        }