示例#1
0
 public SaveAsCommand(Corner2CornerProject project, ICorner2CornerCommandsInput commandsInput)
     : base(
         project,
         commandsInput,
         Corner2CornerCommandOptions.New().WithoutUndo())
 {
 }
示例#2
0
 public SaveIfRequiredCommand(Corner2CornerProject project, ICorner2CornerCommandsInput commandsInput, IUndoRedoManager undoRedoManager)
 {
     this.saveCommand     = new SaveCommand(project, commandsInput);
     this.project         = project;
     this.commandsInput   = commandsInput;
     this.undoRedoManager = undoRedoManager;
 }
 public static void Save(string fileName, Corner2CornerProject project)
 {
     using (FileStream stream = new FileStream(fileName, FileMode.Create))
     {
         Save(stream, project);
         project.FileName = fileName;
     }
 }
示例#4
0
 public LoadCommand(Corner2CornerProject project, ICorner2CornerCommandsInput commandsInput, IUndoRedoManager undoRedoManager)
     : base(
         project,
         commandsInput,
         Corner2CornerCommandOptions.New().ChangesEverything().ResetsOperations())
 {
     this.undoRedoManager = undoRedoManager;
 }
        public static ICorner2CornerProject Create(ICorner2CornerCommandsInput commandsInput, IUndoRedoManager undoRedoManager)
        {
            Corner2CornerProject result = new Corner2CornerProject();

            result.Commands = new CommandFactory(commandsInput, result, undoRedoManager);
            result.ChangeTracking.Track(ChangeTrackingOperation.SetNew);
            return(result);
        }
 protected BaseCorner2CornerCommand(
     Corner2CornerProject project,
     ICorner2CornerCommandsInput commandsInput,
     Corner2CornerCommandOptions options)
 {
     this.Project       = project ?? throw new ArgumentNullException(nameof(project));
     this.options       = options ?? throw new ArgumentNullException(nameof(options));
     this.CommandsInput = commandsInput;
 }
示例#7
0
        public static SetPaletteItemTextCommand CreateWithContext(
            Corner2CornerProject project,
            ICorner2CornerCommandsInput commandsInput,
            IPaletteItem context)
        {
            SetPaletteItemTextCommand result = new SetPaletteItemTextCommand(project, commandsInput);

            result.context = context;
            return(result);
        }
        public static bool Load(string fileName, Corner2CornerProject project)
        {
            using (Stream stream = new FileStream(fileName, FileMode.Open))
            {
                if (Load(stream, project))
                {
                    project.FileName = fileName;
                    return(true);
                }
            }

            return(false);
        }
            public CommandFactory(ICorner2CornerCommandsInput commandsInput, Corner2CornerProject project, IUndoRedoManager undoRedoManager)
            {
                ContainerBuilder builder = new ContainerBuilder();

                builder.RegisterInstance(commandsInput).As <ICorner2CornerCommandsInput>();
                builder.RegisterInstance(project).As <Corner2CornerProject>();
                builder.RegisterInstance(undoRedoManager).As <IUndoRedoManager>();

                var commands = CommandDiscovery.FindCommands <Corner2CornerCommandAttribute, Corner2CornerCommand>(Assembly.GetExecutingAssembly());

                foreach (var command in commands)
                {
                    builder.RegisterType(command.Value).Keyed <ICommand>(command.Key);
                }

                container = builder.Build();
            }
        public static bool Load(Stream stream, Corner2CornerProject project)
        {
            using (BinaryReader reader = new BinaryReader(stream))
            {
                if (!HeaderPersistence.Read(reader))
                {
                    stream.Position = 0;
                    return(false);
                }

                Image image = ImagePersistence.Read(reader);
                int   width = reader.ReadInt32();

                int paletteItemCount         = reader.ReadInt32();
                Corner2CornerPalette palette = new Corner2CornerPalette();

                for (int i = 0; i < paletteItemCount; i++)
                {
                    var pi = PaletteItemPersistence.Read(reader);
                    palette.Add(color: pi.Color, text: pi.Text);
                }

                IPaletteItem selectedPaletteItem = PaletteItemPersistence.Read(reader);
                palette.Find(selectedPaletteItem?.Color ?? Color.Empty, out selectedPaletteItem);

                ImageGrid imageGrid = ImageGridPersistence.Read(reader, palette);

                Color gridBackgroundColor = Color.FromArgb(reader.ReadInt32());

                //read everything successfully so populate the project;

                project.Image               = image;
                project.Width               = width;
                project.Palette             = palette;
                project.SelectedPaletteItem = selectedPaletteItem;
                project.ImageGrid           = imageGrid;
                project.GridBackgroundColor = gridBackgroundColor;
                project.ChangeTracking.Track(ChangeTrackingOperation.SetSaved);

                return(true);
            }
        }
        public static void Save(Stream stream, Corner2CornerProject project)
        {
            using (BinaryWriter writer = new BinaryWriter(stream))
            {
                HeaderPersistence.Write(writer);
                ImagePersistence.Write(writer, project.Image);
                writer.Write(project.Width);

                List <IPaletteItem> palette = project.Palette.ToList();
                writer.Write(palette.Count);

                foreach (var paletteItem in palette)
                {
                    PaletteItemPersistence.Write(writer, paletteItem);
                }

                PaletteItemPersistence.Write(writer, project.SelectedPaletteItem);
                ImageGridPersistence.Write(writer, project.ImageGrid);
                writer.Write(project.GridBackgroundColor.ToArgb());
            }

            project.ChangeTracking.Track(ChangeTrackingOperation.SetSaved);
        }
 public SaveTextPatternCommand(Corner2CornerProject project, ICorner2CornerCommandsInput commandsInput, IUndoRedoManager undoRedoManager)
     : base(project, commandsInput, Corner2CornerCommandOptions.New().WithoutUndo())
 {
     this.undoRedoManager = undoRedoManager;
 }
示例#13
0
 public SetImageGridCellCommand(Corner2CornerProject project, ICorner2CornerCommandsInput commandsInput)
     : base(project, commandsInput, Corner2CornerCommandOptions.New().ChangesImage())
 {
 }
示例#14
0
 public ClickImageCommand(Corner2CornerProject project, ICorner2CornerCommandsInput commandsInput)
 {
     this.project       = project;
     this.commandsInput = commandsInput;
 }
 public SetSelectedPaletteItemCommand(Corner2CornerProject project, ICorner2CornerCommandsInput commandsInput)
     : base(project, commandsInput, Corner2CornerCommandOptions.New().ChangesPalette())
 {
 }
 public SetGridBackgroundCommand(Corner2CornerProject project, ICorner2CornerCommandsInput commandsInput)
     : base(project, commandsInput, Corner2CornerCommandOptions.New().ChangesImage())
 {
 }
示例#17
0
 public SetWidthCommand(Corner2CornerProject project, ICorner2CornerCommandsInput commandsInput)
     : base(project, commandsInput, Corner2CornerCommandOptions.New())
 {
 }