Exemplo n.º 1
0
		private void Collection_OnAddProject(object sender, EventArgs e)
		{
			//todo: is there a way to combine this with the similar from OneImageForm
			OpenFileDialog openFileDialog = new OpenFileDialog();
			openFileDialog.Filter = "Project and Image Files|*" + PPProject.PROJECT_EXTENSION + ";*.BMP;*.PNG;*.JPG;*.JPEG;*.GIF;*.TIFF";
			openFileDialog.Title = "Open Projects or Images";
			openFileDialog.Multiselect = true;
			if(openFileDialog.ShowDialog() != System.Windows.Forms.DialogResult.OK)
			{
				return;
			}

			foreach(string fileName in openFileDialog.FileNames)
			{
				try
				{
					PPProject project = collection.LoadProject(fileName);
					DisplayProject(project);
				}
				catch(DuplicateException)
				{
					MessageBox.Show("Skipping '" + fileName + "'. The file is already in the collection.", "Duplicate File", MessageBoxButtons.OK, MessageBoxIcon.Error);
				}
			}
		}
Exemplo n.º 2
0
        public void IO_ZipProject_GreyscaleColorConfig()
        {
            //arrange
            Color     grey            = Color.Black;
            Color     color           = Color.Red;
            string    zipFilename     = "testProject.ppp";
            Bitmap    greyscaleBitmap = MakeBitmap(grey);
            Bitmap    colorBitmap     = MakeBitmap(color);
            PPConfig  config          = new PPConfig("path\\palette_filename.gpl");
            PPProject project         = new PPProject(greyscaleBitmap, colorBitmap, config);

            //act
            PerpetualPaintLibrary.IO.ZipProject(zipFilename, project);
            //assert
            Assert.IsTrue(File.Exists(zipFilename));

            PPProject result = PerpetualPaintLibrary.IO.LoadProject(zipFilename);

            Assert.IsNull(result.ColorPalette);
            Assert.IsNotNull(result.GreyscaleBitmap);
            Assert.IsNotNull(result.ColorBitmap);
            Assert.IsNotNull(result.Config);
            Assert.IsTrue(ColorsMatch(grey, result.GreyscaleBitmap.GetPixel(0, 0)));
            Assert.IsTrue(ColorsMatch(color, result.ColorBitmap.GetPixel(0, 0)));
            Assert.AreEqual(config.PaletteFileName, result.Config.PaletteFileName);
        }
Exemplo n.º 3
0
        public void SetProject(PPProject project)
        {
            //todo: refactor: SetProject and Load are almost the same function

            StatusChanged?.Invoke(this, new TextEventArgs("Prepping image..."));
            CancelLoad();

            Project = project;

            bool runRegionsOnColorBitmap = (project.GreyscaleBitmap == null);

            editedSinceLastCleanCopy = true;

            regions.Clear();

            regionWorker                  = new RequestRegionWorker();
            regionWorker.Completed       += new RunWorkerCompletedEventHandler(OnRequestRegionCompleted);
            regionWorker.ProgressChanged += new ProgressChangedEventHandler(Worker_OnProgressChanged);
            if (runRegionsOnColorBitmap)
            {
                regionWorker.Run(Project.ColorBitmap);
                Project.GreyscaleBitmap = Utilities.GetGreyscaleOfBitmap(Project.ColorBitmap, this.regions);                 //todo: try may be a timing issue here, where the image is still being worked on but the user is allowed to interact with it
                Project.Edited();
            }
            else
            {
                regionWorker.Run(Project.GreyscaleBitmap);
            }
        }
Exemplo n.º 4
0
		/// <summary>
		/// Tells collection form that project open here has been edited in OneImageForm.
		/// Update the thumbnail.
		/// </summary>
		public void UpdateProject(PPProject project)
		{
			int index = Array.IndexOf(collection.Projects, project);
			if(index == -1)
				return;
			int i = 0;
			foreach(Control control in flowPanel.Controls)
			{
				if(!(control is PictureBox))
					continue;
				if(i == index)
				{
					PictureBox pictureBox = (control as PictureBox);
					pictureBox.Image = project.GetThumbnail(THUMBNAIL_SIZE, THUMBNAIL_SIZE);
					return;
				}
				i++;
			}
		}
Exemplo n.º 5
0
        /// <summary>
        /// Initialize master image (if needed) and update it with the new file.
        /// Can either specify a file name, or provide the full project.
        /// </summary>
        private void UpdateMasterImage(string fileName = null, PPProject project = null)
        {
            if (masterImage == null)
            {
                masterImage = new MasterImage();
                masterImage.ProgressChanged += new ProgressChangedEventHandler(OnProgressChanged);
                masterImage.StatusChanged   += new TextEventHandler(Form_UpdateStatusText);
                masterImage.ProjectEdited   += new ProjectEventHandler(MasterImage_OnProjectEdited);
            }

            if (fileName != null)
            {
                masterImage.Load(fileName);
            }
            else
            {
                masterImage.SetProject(project);
            }

            history.Clear();
            UpdateZoomedImage(SCALE_FIT);
        }
Exemplo n.º 6
0
        public void Load(string filename)
        {
            StatusChanged?.Invoke(this, new TextEventArgs("Prepping image..."));
            CancelLoad();

            if (Project == null)
            {
                Project = new PPProject();
            }

            bool runRegionsOnColorBitmap = false;

            if (Path.GetExtension(filename) == PPProject.PROJECT_EXTENSION)
            {
                Project.LoadProject(filename);
            }
            else
            {
                bool isGreyscaleImage = Project.LoadImage(filename);
                runRegionsOnColorBitmap = !isGreyscaleImage;
            }
            editedSinceLastCleanCopy = true;

            regions.Clear();

            regionWorker                  = new RequestRegionWorker();
            regionWorker.Completed       += new RunWorkerCompletedEventHandler(OnRequestRegionCompleted);
            regionWorker.ProgressChanged += new ProgressChangedEventHandler(Worker_OnProgressChanged);
            if (runRegionsOnColorBitmap)
            {
                regionWorker.Run(Project.ColorBitmap);
                Project.GreyscaleBitmap = Utilities.GetGreyscaleOfBitmap(Project.ColorBitmap, this.regions);                 //todo: try may be a timing issue here, where the image is still being worked on but the user is allowed to interact with it
            }
            else
            {
                regionWorker.Run(Project.GreyscaleBitmap);
            }
        }
Exemplo n.º 7
0
		private void DisplayProject(PPProject project)
		{
			int padding = 4;

			Panel panel = new Panel();
			panel.Cursor = Cursors.Hand;
			panel.ContextMenu = projectContextMenu;

			PictureBox pictureBox = new PictureBox();
			pictureBox.Width = THUMBNAIL_SIZE + padding + padding;
			pictureBox.Height = THUMBNAIL_SIZE + padding + padding;
			pictureBox.Left = 0;
			pictureBox.Top = 0;
			pictureBox.Image = project.GetThumbnail(THUMBNAIL_SIZE, THUMBNAIL_SIZE);
			pictureBox.SizeMode = PictureBoxSizeMode.CenterImage;
			pictureBox.MouseEnter += new EventHandler(Project_OnMouseEnter);
			pictureBox.MouseLeave += new EventHandler(Project_OnMouseLeave);
			pictureBox.Click += new EventHandler(Project_OnClick);

			panel.Controls.Add(pictureBox);

			Label label = new Label();
			if(!String.IsNullOrEmpty(project.SaveToFileName))
			{
				label.Text = Path.GetFileNameWithoutExtension(project.SaveToFileName);
			}
			label.Width = THUMBNAIL_SIZE;
			label.Height = 20;
			label.Left = padding;
			label.Top = pictureBox.Bottom;
			panel.Controls.Add(label);

			panel.Width = pictureBox.Width;
			panel.Height = label.Bottom;
			flowPanel.Controls.Add(panel);
		}