Ejemplo n.º 1
0
        //
        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;
        }
Ejemplo n.º 2
0
        protected override void ComputePosition(int currentReDrawRequestId)
        {
            var stackTops = new int[Column];

            for (int i = 0; i < stackTops.Length; i++)
            {
                stackTops[i] = Gutter;
            }

            int        left, top;
            List <int> colId;

            for (int i = 0; i < _imgs.Count; i++)
            {
                // new redraw request has been called, skip current redraw
                if (currentReDrawRequestId < _redrawRequestId)
                {
                    return;
                }

                GetMinStackHeightAndIndex(stackTops, out top, out colId);
                left = Gutter * (1 + colId[0]) + _colWidth * colId[0];

                Img iw = _imgs[i];
                int actualImageWidth  = iw.Original.Width;
                int actualImageHeight = iw.Original.Height;
                int availableHeight   = (int)((_colWidth * 1f / actualImageWidth) * actualImageHeight);
                iw.ClippingRegion = new Rectangle(left, top - _offsetY, _colWidth, availableHeight);

                // next image in the same column will be drawned at "columnTops[colId] + availableHeight + MGutter" position
                stackTops[colId[0]] += availableHeight + Gutter;

                // increase virtual height
                if (_virtualHeight < stackTops[colId[0]])
                {
                    _virtualHeight = stackTops[colId[0]];
                }
            }
        }