Esempio n. 1
0
        public ResourceViewModel(Resource resource, ResourceFile resourceFile, string currentDirectory)
        {
            Resource = resource;
            ResourceFile = resourceFile;
            CurrentDirectory = currentDirectory;

            var bitmapFull = new BitmapImage(new Uri(CurrentDirectory + ResourceFile.BitmapFileName));
            ResourceBitmap = bitmapFull.CreateCroppedBitmapResolutionInvariant(resource.Crop);
        }
Esempio n. 2
0
        public static Resource Load(BinaryReader reader)
        {
            var resource = new Resource();
            resource.Name = reader.ReadString();
            resource.HasTransparentColor = reader.ReadInt32() == 1;

            var r = reader.ReadByte();
            var g = reader.ReadByte();
            var b = reader.ReadByte();
            var a = reader.ReadByte();
            resource.TransparentColor = Color.FromArgb(a, r, g, b);

            resource.Layer = reader.ReadString();

            var cropX = reader.ReadInt32();
            var cropY = reader.ReadInt32();
            var cropW = reader.ReadInt32();
            var cropH = reader.ReadInt32();
            resource.Crop = new Int32Rect(cropX, cropY, cropW, cropH);

            resource.ForbiddenAreas = new ObservableCollection<Int32Rect>();
            var forbiddenAreas = reader.ReadInt32();
            for (var i = 0; i < forbiddenAreas; ++i)
            {
                var x1A = reader.ReadInt32();
                var y1A = reader.ReadInt32();
                var x2A = reader.ReadInt32();
                var y1B = reader.ReadInt32();
                var x2B = reader.ReadInt32();
                var y2A = reader.ReadInt32();
                var x1B = reader.ReadInt32();
                var y2B = reader.ReadInt32();
                if (x1A != x1B || x2A != x2B || y1A != y1B || y2A != y2B)
                    throw new Exception("Invalid forbidden area (non rectangle)");

                resource.ForbiddenAreas.Add(new Int32Rect(x1A, y1A, x2A - x1A, y2A - y1A));
            }

            return resource;
        }
        private void CreateNewResource(Int32Rect rect)
        {
            if (rect.Height < 30 || rect.Width < 30)
            {
                MessageBox.Show("Too small.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            if (ResourceFile.Resources.Select(resource => resource.Crop).Any(
                roth => rect.X < roth.X + roth.Width && rect.X + rect.Width > roth.X && rect.Y < roth.Y + roth.Height && rect.Y + rect.Height > roth.Y))
            {
                MessageBox.Show("Resource shouldn't intersect any other.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            var res = new Resource
                          {
                              Name = "Unnamed",
                              Layer = "Default",
                              Crop = rect,
                              TransparentColor = ResourceFile.TransparentColor,
                              HasTransparentColor = ResourceFile.HasTransparentColor,
                              ForbiddenAreas = new ObservableCollection<Int32Rect>()
                          };

            ResourceFile.Resources.Add(res);
            UpdateFilters();
        }
 public void OpenResourceWindow(Resource resource)
 {
     dynamic settings = new ExpandoObject();
     settings.WindowStartupLocation = WindowStartupLocation.Manual;
     settings.WindowStyle = WindowStyle.ToolWindow;
     settings.ShowInTaskbar = false;
     _windowManager.ShowDialog(new ResourceViewModel(resource, ResourceFile, CurrentDirectory), null, settings);
     UpdateFilters();
 }