protected override void PaintImages(Graphics g, IEnumerable <Img> images) { var pickedDrawRegion = Rectangle.Empty; var drawRegion = Rectangle.Empty; foreach (Img image in images) { if (_dragItem == null || _dragItem.ItemRef != image) { // translate draw region switch (DisplayMode) { case ImageGridDisplayMode.StretchImage: drawRegion = ImageDisplayModeHelper.GetImageRect( image.DrawingRegion, new Rectangle(0, 0, image.Original.Width, image.Original.Height), Mmosoft.Oops.Controls.DisplayMode.StretchImage); break; case ImageGridDisplayMode.ScaleLossCenter: drawRegion = ImageDisplayModeHelper.GetImageRect( image.DrawingRegion, new Rectangle(0, 0, image.Original.Width, image.Original.Height), Mmosoft.Oops.Controls.DisplayMode.ScaleLossCenter); break; } // set clip to image boundary to clipped outside edges g.SetClip(image.ClippingRegion); g.DrawImage(image.Resized, drawRegion); } } // draw floating picked item if (_dragItem != null) { switch (DisplayMode) { case ImageGridDisplayMode.StretchImage: drawRegion = ImageDisplayModeHelper.GetImageRect( _dragItem.Boundary, new Rectangle(0, 0, _dragItem.Image.Width, _dragItem.Image.Height), Mmosoft.Oops.Controls.DisplayMode.StretchImage); break; case ImageGridDisplayMode.ScaleLossCenter: drawRegion = ImageDisplayModeHelper.GetImageRect( _dragItem.Boundary, new Rectangle(0, 0, _dragItem.Image.Width, _dragItem.Image.Height), Mmosoft.Oops.Controls.DisplayMode.ScaleLossCenter); break; } g.SetClip(_dragItem.Boundary); g.DrawImage(_dragItem.Image, drawRegion); } }
// protected override void ComputePosition(int currentReDrawRequestId) { var availableWidth = _colWidth; var rowHeight = _squareSized ? availableWidth: _rowHeight; var slotMgr = new BlockMgr(_column); var takenSlots = new List <Block>(); for (int i = 0; i < _imgs.Count; i++) { if (currentReDrawRequestId < _redrawRequestId) { return; } if (ImageDisplayModeHelper.IsPortrait(_imgs[i].ClippingRegion)) { takenSlots.Add(slotMgr.FindAvailableSlot(1)); } else // square or landscape { // check if we need more slots for landspace image float imageRatio = 1f * _imgs[i].Original.Width / _imgs[i].Original.Height; int slotNeeded = MergeColumn ? (int)Math.Round(imageRatio, MidpointRounding.AwayFromZero) : 1; takenSlots.Add(slotMgr.FindAvailableSlot(slotNeeded)); } } // converting slots to specific position in grid for (int i = 0; i < takenSlots.Count; i++) { if (currentReDrawRequestId < _redrawRequestId) { return; } Img iw = _imgs[i]; Block slot = takenSlots[i]; iw.ClippingRegion = new Rectangle { X = (slot.SlotIndex + 1) * _gutter + slot.SlotIndex * availableWidth, Y = (slot.LaneIndex + 1) * _gutter + slot.LaneIndex * rowHeight - _offsetY, Width = (slot.SlotNeeded - 1) * _gutter + slot.SlotNeeded * availableWidth, Height = rowHeight }; } _virtualHeight = (slotMgr.LaneCount * rowHeight) + (slotMgr.LaneCount - 1) * _gutter; }