コード例 #1
0
        private void LoadItems()
        {
            foreach (var item in _rawItems)
            {
                item.OnBrowserClosed();
            }
            _rawItems.Clear();

            using (var db = new Database())
            {
                var table = db.SelectDataTable("select * from img where location_id = @location_id", "@location_id", _loc.RowId);
                foreach (DataRow row in table.Rows)
                {
                    var item = new LBItem(this, ImageRec.FromDataRow(row), _loc, _items.Count);
                    _rawItems.Add(item);
                }
            }

            lock (_thumbnailLock)
            {
                _items = _rawItems.ToList();
                ApplySort();

                _itemLayoutUpdateRequired = true;

                RenumberItems();
                RefreshStatusCounts();
                UpdateScroll();
                SetSelection(-1, -1);
                Invalidate();
            }

            Global.FileDeleted += Global_FileDeleted;
        }
コード例 #2
0
        private void LocationBrowser_MouseMove(object sender, MouseEventArgs e)
        {
            try
            {
                if (e.Button.HasFlag(MouseButtons.Left))
                {
                    var index = HitTest(e.Location);
                    if (index != -1)
                    {
                        SetSelection(_selStart, index);
                    }
                }
                else if (e.Button == MouseButtons.None)
                {
                    var index = HitTest(e.Location);
                    if (index != -1)
                    {
                        if (_mouseOverItem != _items[index])
                        {
                            if (_mouseOverItem != null)
                            {
                                _mouseOverItem.MouseOverRating = 0;
                            }
                            _mouseOverItem = _items[index];

                            var rating = HitTestRating(index, e.Location);
                            if (rating != -1)
                            {
                                _mouseOverItem.MouseOverRating = rating;
                            }
                        }
                        else                         // mouse is still over mouse-over item
                        {
                            var rating = HitTestRating(index, e.Location);
                            if (rating != -1)
                            {
                                _mouseOverItem.MouseOverRating = rating;
                            }
                            else
                            {
                                _mouseOverItem.MouseOverRating = 0;
                            }
                        }
                    }
                    else                     // index == -1
                    {
                        if (_mouseOverItem != null)
                        {
                            _mouseOverItem.MouseOverRating = 0;
                            _mouseOverItem = null;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                this.ShowError(ex);
            }
        }
コード例 #3
0
        private void ThumbnailRetrievalProc(object state)
        {
            using (var db = new Database())
            {
                while (true)
                {
                    LBItem item = null;
                    lock (_thumbnailLock)
                    {
                        if (_thumbnailQueue.Count == 0)
                        {
                            _thumbnailQueue = null;
                            return;
                        }

                        item = _thumbnailQueue.Peek();                          // Don't remove it from the queue until the image is fully loaded

                        if (!ItemIsVisible(item.Index))                         // If item is no longer visible on the screen, then don't spend time getting the thumbnail.
                        {
                            _thumbnailQueue.Dequeue();
                            item = null;
                        }
                    }

                    if (item != null)
                    {
                        var now = DateTime.Now;
                        if (now.Subtract(_lastThumbnailGenerate).TotalMilliseconds < k_thumbnailWait)
                        {
                            Thread.Sleep(k_thumbnailWait - (int)now.Subtract(_lastThumbnailGenerate).TotalMilliseconds);
                        }

                        SetStatusMessage(string.Format("Getting Thumbnail: {0}", item.ImageRec.Location));

                        item.ImageRec.Retrieve(db);
                        item.ImageRec.Release();
                        var thumb = item.ImageRec.Thumbnail;
                        if (thumb != null)
                        {
                            BeginInvoke(new Action(() => { OnThumbnailUpdated(item); }));
                        }

                        lock (_thumbnailLock)
                        {
                            _thumbnailQueue.Dequeue();
                            if (_thumbnailQueue.Count == 0)
                            {
                                _thumbnailQueue = null;
                                return;
                            }
                        }

                        _lastThumbnailGenerate = DateTime.Now;
                    }
                }
            }
        }
コード例 #4
0
 private void OnThumbnailUpdated(LBItem item)
 {
     if (item != null && item.Index >= 0)
     {
         if (ItemIsVisible(item.Index))
         {
             Invalidate();
         }
     }
 }
コード例 #5
0
        private void OpenItem(LBItem item)
        {
            var fileName = item.ImageRec.LocationOnDisk;

            if (string.IsNullOrEmpty(fileName) || !System.IO.File.Exists(fileName))
            {
                this.ShowError(Res.Error_ImageFileMissing, fileName);
                Global.OnFileDeleted(item.ImageRec.LocationOnDisk);
                return;
            }

            System.Diagnostics.Process.Start(fileName);
        }
コード例 #6
0
        private int GetItemIndex(LBItem item)
        {
            var index = 0;

            foreach (var i in _items)
            {
                if (i == item)
                {
                    return(index);
                }
                index++;
            }
            return(-1);
        }
コード例 #7
0
 private void QueueThumbnailRetrieval(LBItem item)
 {
     lock (_thumbnailLock)
     {
         if (_thumbnailQueue == null)
         {
             _thumbnailQueue = new Queue <LBItem>();
             _thumbnailQueue.Enqueue(item);
             System.Threading.ThreadPool.QueueUserWorkItem(ThumbnailRetrievalProc);
         }
         else if (!_thumbnailQueue.Contains(item))
         {
             _thumbnailQueue.Enqueue(item);
         }
     }
 }
コード例 #8
0
        private void DrawItem(Graphics g, LBItem item, Rectangle itemBounds)
        {
            // Highlight
            var selected = ItemIsSelected(item.Index);

            if (selected)
            {
                g.FillRectangle(SystemBrushes.Highlight, itemBounds);
            }

            // Border
            if (_borderPen == null)
            {
                _borderPen = new Pen(SystemBrushes.Control);
            }
            g.DrawRectangle(_borderPen, itemBounds);

            // Thumbnail background
            var maxThumbRect = new Rectangle(itemBounds.Left + _spacer, itemBounds.Top + _spacer, _maxThumbWidth, _maxThumbHeight);

            if (!selected)
            {
                var thumbBackgroundRect = maxThumbRect;
                thumbBackgroundRect.Inflate(1, 1);
                g.FillRectangle(SystemBrushes.Control, thumbBackgroundRect);
            }

            // Thumbnail
            var thumb = item.ImageRec.Thumbnail;

            if (thumb == null)
            {
                QueueThumbnailRetrieval(item);
            }
            else
            {
                var imgRect = new RectangleF(PointF.Empty, thumb.Size);
                imgRect = imgRect.ScaleRectWidth(_maxThumbWidth);
                if (imgRect.Height > _maxThumbHeight)
                {
                    imgRect = imgRect.ScaleRectHeight(_maxThumbHeight);
                }
                imgRect = imgRect.CenterInside(maxThumbRect);

                g.DrawImage(thumb, imgRect);
            }

            var infoLeft  = itemBounds.Left + _maxThumbWidth + _spacer * 2;
            var infoWidth = itemBounds.Right - infoLeft;

            if (infoWidth > 0)
            {
                var infoPt = new Point(infoLeft, itemBounds.Top + _spacer);

                // File Name
                var stringSize = g.MeasureString(item.RelativeLocation, Font, infoWidth);
                g.DrawString(item.RelativeLocation, Font, selected ? SystemBrushes.HighlightText : SystemBrushes.WindowText,
                             new RectangleF(infoPt, stringSize));
                infoPt.Y += (int)Math.Ceiling(stringSize.Height) + _spacer;

                // Size
                var imgSize = item.ImageRec.Size;
                if (imgSize.HasValue)
                {
                    if (_sizeFont == null)
                    {
                        _sizeFont = new Font(Font.FontFamily, Font.Size * .9f);
                    }

                    var str = imgSize.Value.ToSizeString();
                    stringSize = g.MeasureString(str, _sizeFont);
                    g.DrawString(str, _sizeFont, selected ? SystemBrushes.HighlightText : SystemBrushes.WindowText,
                                 new RectangleF(infoPt, stringSize));
                    infoPt.Y += (int)Math.Ceiling(stringSize.Height);
                }

                // Rating
                infoPt.Y += _spacer;
                var pt       = infoPt;
                var starSize = new Size((int)Math.Round(Images.StarUnrated.Width * g.DpiX / 96.0f),
                                        (int)Math.Round(Images.StarUnrated.Height * g.DpiY / 96.0f));

                for (int i = 0; i < 5; i++)
                {
                    item.StarRects[i] = new Rectangle(pt, starSize);
                    pt.X += starSize.Width;
                }

                var rating = item.ImageRec.Rating;
                if (item.MouseOverRating > 0 && item.MouseOverRating != rating)
                {
                    for (int i = 1; i <= 5; i++)
                    {
                        if (item.MouseOverRating >= i)
                        {
                            g.DrawImage(Images.StarMouseOver1, item.StarRects[i - 1]);
                        }
                        else
                        {
                            g.DrawImage(Images.StarMouseOver0, item.StarRects[i - 1]);
                        }
                    }
                }
                else if (rating > 0)
                {
                    for (int i = 1; i <= 5; i++)
                    {
                        if (rating >= i)
                        {
                            g.DrawImage(Images.StarRated1, item.StarRects[i - 1]);
                        }
                        else
                        {
                            g.DrawImage(Images.StarRated0, item.StarRects[i - 1]);
                        }
                    }
                }
                else
                {
                    for (int i = 0; i < 5; i++)
                    {
                        g.DrawImage(Images.StarUnrated, item.StarRects[i]);
                    }
                }
            }
        }