Exemplo n.º 1
0
 bool addSubitem(ImagesRow r, StackableImage image, int maxHeight)
 {
     for (int i = 0; i < r.Count; ++i)
     {
         if (r[i].GetItemType() == RowType.Rows)
         {
             if (Add(r[i] as ImagesRows, image, r[i].Width, r.Height, false, true))
             {
                 return(true);
             }
         }
         else
         {
             StackableImage desc = r[i] as StackableImage;
             if (r.Height - desc.Height < image.Height || desc.Width < image.Width)
             {
                 continue;
             }
             if (desc != null)
             {
                 ImagesRows subrows = new ImagesRows();
                 Add(subrows, desc, desc.Width, maxHeight, false, true);
                 Add(subrows, image, desc.Width, maxHeight, false, true);
                 r.Insert(subrows, i);
                 r.Remove(desc);
                 return(true);
             }
         }
     }
     return(false);
 }
Exemplo n.º 2
0
        void showRow(ImagesRow row, int top, int left, int width, double vgap, ImageAction action, ref int i)
        {
            int    rowWidth  = row.Width;
            int    rowHeight = row.Height;
            double gap       = ((double)(width - rowWidth) / (double)row.Count);

            for (int cell = 0; cell < row.Count; ++cell)
            {
                if (mPictures.Count <= i)
                {
                    AddPictureBox();
                }

                IRowItem item = row[cell];
                if (item.GetItemType() == RowType.Image)
                {
                    StackableImage image = item as StackableImage;
                    mPictures[i].mPictureBox.Left   = left;
                    mPictures[i].mPictureBox.Top    = top;
                    mPictures[i].mPictureBox.Height = (int)Math.Round(rowHeight + vgap);
                    mPictures[i].mPictureBox.Width  = (int)Math.Round(image.Width + gap);
                    left = mPictures[i].mPictureBox.Left + mPictures[i].mPictureBox.Width;

                    showNextImage(mPictures[i], action, image);
                    mPictures[i].mPictureBox.Show();
                    ++i;
                }
                else if (item.GetItemType() == RowType.Rows)
                {
                    showRows(item as ImagesRows, top, left, row.Height, (int)(item.Width + gap), action, ref i);
                    left += (int)(item.Width + gap);
                }
            }
        }
Exemplo n.º 3
0
 public void AddImage(StackableImage image)
 {
     lock (mLoadedQueueLock)
     {
         mPreloaded.Enqueue(image);
     }
 }
Exemplo n.º 4
0
        /// <summary>
        /// Does composition work
        /// </summary>
        void doWork()
        {
            while (!mCanceled)
            {
                StackableImage image = mImages.GetNext();
                if (image == null)
                {
                    break;
                }

                lock (mLayouts)
                {
                    if (!addImage(image))
                    {
                        ImagesLayout layout = new ImagesLayout(mLayoutSize.Width, mLayoutSize.Height);
                        mLayouts.Add(layout);
                        if (!layout.Add(image))
                        {
                            // terrible error! Shouldn't happen!
                            image.Dispose();
                        }
                        mLayoutCreated.Set();
                    }
                }
            }
            mWorkDone = true;
            mLayoutCreated.Set();
        }
Exemplo n.º 5
0
 /// <summary>
 /// Tries to add an image to one of the existing layouts.
 /// The caller need to lock mLayouts.
 /// </summary>
 /// <param name="image"></param>
 /// <returns>True if the image was added to the layout.</returns>
 bool addImage(StackableImage image)
 {
     foreach (ImagesLayout layout in mLayouts)
     {
         if (layout.Add(image))
         {
             return(true);
         }
     }
     return(false);
 }
Exemplo n.º 6
0
        bool Add(ImagesRows target, StackableImage image, int maxWidth, int maxHeight, bool addSubRows, bool useFind)
        {
            if (image.Width > maxWidth)
            {
                return(false);
            }
            int rowsHeight = 0;

            for (int row = 0; row < target.RowCount; ++row)
            {
                if (addSubRows && addSubitem(target[row] as ImagesRow, image, maxHeight))
                {
                    return(true);
                }

                int rowHeight = target[row].Height;
                int rowWidth  = target[row].Width;
                rowsHeight += rowHeight;
                int  heightDiff = rowHeight - image.Height;
                bool widthFits  = maxWidth - rowWidth >= image.Width;
                bool heightFits = heightDiff >= 0 || maxHeight - GetRowsHeight() >= Math.Abs(heightDiff);
                if (heightFits && widthFits)
                {
                    ImagesRow imagesRow = target[row] as ImagesRow;
                    imagesRow.Add(image);
                    return(true);
                }
            }
            if (maxHeight - rowsHeight >= image.Height)
            {
                ImagesRow newRow = new ImagesRow();
                newRow.Add(image);
                target.Add(newRow);
                return(true);
            }

            return(false);
        }
Exemplo n.º 7
0
 public bool Add(StackableImage image)
 {
     return(Add(mRows, image, mMaxWidth, mMaxHeight, true, false));
 }
Exemplo n.º 8
0
        void showNextImage(PictureControlDesc picture, ImageAction action, StackableImage next)
        {
            System.Drawing.Image img = next == null ? null : next.Image;
            if (picture.mPictureBox.Image != null)
            {
                picture.mPictureBox.Image.Dispose();
            }
            if (img == null)
            {
                picture.mPictureBox.Image = null;
            }
            else
            {
                try
                {
                    //TODO: optimize
                    picture.mPictureBox.Image = (System.Drawing.Image)img.Clone();
                }
                catch (Exception ex)
                {
                    MessageBox.Show("This is the exception I'm searched for! " + ex.ToString(),
                                    "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            if (picture.mImageDescriptor != null)
            {
                switch (action)
                {
                case ImageAction.Reuse:
                    mImagesLoader.Return(picture.mImageDescriptor.Path);
                    break;

                case ImageAction.Delete:
                    picture.mImageDescriptor.Dispose();
                    try
                    {
                        if (string.IsNullOrEmpty(mOptions.MoveDeletedPath))
                        {
                            System.IO.File.Delete(picture.mImageDescriptor.Path);
                        }
                        else
                        {
                            moveFile(picture.mImageDescriptor.Path, mOptions.MoveDeletedPath);
                        }
                    }
                    catch (IOException ex)
                    {
                        System.IO.File.SetAttributes(picture.mImageDescriptor.Path, FileAttributes.Normal);
                        // do nothing
                    }
                    catch (UnauthorizedAccessException ex)
                    {
                        if (System.IO.File.GetAttributes(picture.mImageDescriptor.Path).HasFlag(System.IO.FileAttributes.ReadOnly))
                        {
                            System.IO.File.SetAttributes(picture.mImageDescriptor.Path, FileAttributes.Normal);
                            System.IO.File.Delete(picture.mImageDescriptor.Path);
                        }
                    }
                    break;

                case ImageAction.Move:
                {
                    picture.mImageDescriptor.Dispose();
                    string movePath = mOptions.MovePath;
                    moveFile(picture.mImageDescriptor.Path, movePath);
                }
                break;

                case ImageAction.Skip:
                    picture.mImageDescriptor.Dispose();
                    break;
                }
            }
            picture.mImageDescriptor = next;
        }
Exemplo n.º 9
0
 public void PushBack(StackableImage img)
 {
     mImagesCache.Enqueue(img);
 }