Search in sources :

Example 1 with ContentImageLoadedListener

use of com.biglybt.ui.swt.utils.TorrentUIUtilsV3.ContentImageLoadedListener in project BiglyBT by BiglySoftware.

the class ColumnThumbAndName method cellPaint.

@Override
public void cellPaint(GC gc, final TableCellSWT cell) {
    Object ds = cell.getDataSource();
    if (ds instanceof DiskManagerFileInfo) {
        cellPaintFileInfo(gc, cell, (DiskManagerFileInfo) ds);
        return;
    }
    Rectangle cellBounds = cell.getBounds();
    int originalBoundxsX = cellBounds.x;
    int textX = originalBoundxsX;
    TableRowCore rowCore = cell.getTableRowCore();
    if (rowCore != null) {
        int numSubItems = rowCore.getSubItemCount();
        int paddingX = 3;
        int width = 7;
        boolean show_twisty;
        if (NEVER_SHOW_TWISTY) {
            show_twisty = false;
        } else if (numSubItems > 1) {
            show_twisty = true;
        } else {
            Boolean show = (Boolean) rowCore.getData(ID_EXPANDOHITAREASHOW);
            if (show == null) {
                DownloadManager dm = (DownloadManager) ds;
                TOTorrent torrent = dm.getTorrent();
                show_twisty = torrent != null && !dm.getTorrent().isSimpleTorrent();
                rowCore.setData(ID_EXPANDOHITAREASHOW, Boolean.valueOf(show_twisty));
            } else {
                show_twisty = show;
            }
        }
        if (show_twisty) {
            int middleY = cellBounds.y + (cellBounds.height / 2) - 1;
            int startX = cellBounds.x + paddingX;
            int halfHeight = 2;
            Color bg = gc.getBackground();
            gc.setBackground(gc.getForeground());
            gc.setAntialias(SWT.ON);
            gc.setAdvanced(true);
            if (rowCore.isExpanded()) {
                gc.fillPolygon(new int[] { startX, middleY - halfHeight, startX + width, middleY - halfHeight, startX + (width / 2), middleY + (halfHeight * 2) + 1 });
            } else {
                gc.fillPolygon(new int[] { startX, middleY - halfHeight, startX + width, middleY + halfHeight, startX, middleY + (halfHeight * 2) + 1 });
            }
            gc.setBackground(bg);
            Rectangle hitArea = new Rectangle(paddingX, middleY - halfHeight - cellBounds.y, width, (halfHeight * 4) + 1);
            rowCore.setData(ID_EXPANDOHITAREA, hitArea);
        }
        if (!NEVER_SHOW_TWISTY) {
            cellBounds.x += paddingX * 2 + width;
            cellBounds.width -= paddingX * 2 + width;
        }
    }
    if (!showIcon) {
        cellBounds.x += 2;
        cellBounds.width -= 4;
        cellPaintName(cell, gc, cellBounds, cellBounds.x, originalBoundxsX);
        return;
    }
    Image[] imgThumbnail = TorrentUIUtilsV3.getContentImage(ds, cellBounds.height >= 20, new ContentImageLoadedListener() {

        @Override
        public void contentImageLoaded(Image image, boolean wasReturned) {
            if (!wasReturned) {
                // this may be triggered many times, so only invalidate and don't
                // force a refresh()
                cell.invalidate();
            }
        }
    });
    if (imgThumbnail != null && ImageLoader.isRealImage(imgThumbnail[0])) {
        try {
            if (cellBounds.height > 30) {
                cellBounds.y += 1;
                cellBounds.height -= 3;
            }
            Rectangle imgBounds = imgThumbnail[0].getBounds();
            int dstWidth;
            int dstHeight;
            if (imgBounds.height > cellBounds.height) {
                dstHeight = cellBounds.height;
                dstWidth = imgBounds.width * cellBounds.height / imgBounds.height;
            } else if (imgBounds.width > cellBounds.width) {
                dstWidth = cellBounds.width - 4;
                dstHeight = imgBounds.height * cellBounds.width / imgBounds.width;
            } else {
                dstWidth = imgBounds.width;
                dstHeight = imgBounds.height;
            }
            if (cellBounds.height <= 18) {
                dstWidth = Math.min(dstWidth, cellBounds.height);
                dstHeight = Math.min(dstHeight, cellBounds.height);
                if (imgBounds.width > 16) {
                    cellBounds.y++;
                    dstHeight -= 2;
                }
            }
            try {
                gc.setAdvanced(true);
                gc.setInterpolation(SWT.HIGH);
            } catch (Exception e) {
            }
            int x = cellBounds.x;
            textX = x + dstWidth + 3;
            int minWidth = dstHeight * 7 / 4;
            int imgPad = 0;
            if (dstHeight > 25) {
                if (dstWidth < minWidth) {
                    imgPad = ((minWidth - dstWidth + 1) / 2);
                    x = cellBounds.x + imgPad;
                    textX = cellBounds.x + minWidth + 3;
                }
            }
            if (cellBounds.width - dstWidth - (imgPad * 2) < 100 && dstHeight > 18) {
                dstWidth = Math.min(32, dstHeight);
                x = cellBounds.x + ((32 - dstWidth + 1) / 2);
                dstHeight = imgBounds.height * dstWidth / imgBounds.width;
                textX = cellBounds.x + dstWidth + 3;
            }
            int y = cellBounds.y + ((cellBounds.height - dstHeight + 1) / 2);
            if (dstWidth > 0 && dstHeight > 0 && !imgBounds.isEmpty()) {
                // Rectangle dst = new Rectangle(x, y, dstWidth, dstHeight);
                Rectangle lastClipping = gc.getClipping();
                try {
                    Utils.setClipping(gc, cellBounds);
                    boolean hack_adv = Constants.isWindows8OrHigher && gc.getAdvanced();
                    if (hack_adv) {
                        // problem with icon transparency on win8
                        gc.setAdvanced(false);
                    }
                    for (int i = 0; i < imgThumbnail.length; i++) {
                        Image image = imgThumbnail[i];
                        if (image == null || image.isDisposed()) {
                            continue;
                        }
                        Rectangle srcBounds = image.getBounds();
                        if (i == 0) {
                            int w = dstWidth;
                            int h = dstHeight;
                            if (imgThumbnail.length > 1) {
                                w = w * 9 / 10;
                                h = h * 9 / 10;
                            }
                            gc.drawImage(image, srcBounds.x, srcBounds.y, srcBounds.width, srcBounds.height, x, y, w, h);
                        } else {
                            int w = dstWidth * 3 / 8;
                            int h = dstHeight * 3 / 8;
                            gc.drawImage(image, srcBounds.x, srcBounds.y, srcBounds.width, srcBounds.height, x + dstWidth - w, y + dstHeight - h, w, h);
                        }
                    }
                    if (hack_adv) {
                        gc.setAdvanced(true);
                    }
                } catch (Exception e) {
                    Debug.out(e);
                } finally {
                    Utils.setClipping(gc, lastClipping);
                }
            }
            TorrentUIUtilsV3.releaseContentImage(ds);
        } catch (Throwable t) {
            Debug.out(t);
        }
    }
    cellPaintName(cell, gc, cellBounds, textX, originalBoundxsX);
}
Also used : DiskManagerFileInfo(com.biglybt.core.disk.DiskManagerFileInfo) Color(org.eclipse.swt.graphics.Color) Rectangle(org.eclipse.swt.graphics.Rectangle) ContentImageLoadedListener(com.biglybt.ui.swt.utils.TorrentUIUtilsV3.ContentImageLoadedListener) Image(org.eclipse.swt.graphics.Image) DownloadManager(com.biglybt.core.download.DownloadManager) Point(org.eclipse.swt.graphics.Point) TableRowCore(com.biglybt.ui.common.table.TableRowCore) TOTorrent(com.biglybt.core.torrent.TOTorrent)

Example 2 with ContentImageLoadedListener

use of com.biglybt.ui.swt.utils.TorrentUIUtilsV3.ContentImageLoadedListener in project BiglyBT by BiglySoftware.

the class ColumnThumbnail method cellPaint.

// @see com.biglybt.ui.swt.views.table.TableCellSWTPaintListener#cellPaint(org.eclipse.swt.graphics.GC, com.biglybt.ui.swt.views.table.TableCellSWT)
@Override
public void cellPaint(GC gc, final TableCellSWT cell) {
    Object ds = cell.getDataSource();
    Rectangle cellBounds = cell.getBounds();
    Image[] imgThumbnail = TorrentUIUtilsV3.getContentImage(ds, cellBounds.width >= 20 && cellBounds.height >= 20, new ContentImageLoadedListener() {

        @Override
        public void contentImageLoaded(Image image, boolean wasReturned) {
            if (!wasReturned) {
                // this may be triggered many times, so only invalidate and don't
                // force a refresh()
                cell.invalidate();
            }
        }
    });
    if (imgThumbnail == null || imgThumbnail[0] == null) {
        // don't need to release a null image
        return;
    }
    if (cellBounds.height > 30) {
        cellBounds.y += 2;
        cellBounds.height -= 4;
    }
    Rectangle imgBounds = imgThumbnail[0].getBounds();
    int dstWidth;
    int dstHeight;
    if (imgBounds.height > cellBounds.height) {
        dstHeight = cellBounds.height;
        dstWidth = imgBounds.width * cellBounds.height / imgBounds.height;
    } else if (imgBounds.width > cellBounds.width) {
        dstWidth = cellBounds.width - 4;
        dstHeight = imgBounds.height * cellBounds.width / imgBounds.width;
    } else {
        dstWidth = imgBounds.width;
        dstHeight = imgBounds.height;
    }
    try {
        gc.setAdvanced(true);
        gc.setInterpolation(SWT.HIGH);
    } catch (Exception e) {
    }
    int x = cellBounds.x + ((cellBounds.width - dstWidth + 1) / 2);
    int y = cellBounds.y + ((cellBounds.height - dstHeight + 1) / 2);
    if (dstWidth > 0 && dstHeight > 0 && !imgBounds.isEmpty()) {
        Rectangle dst = new Rectangle(x, y, dstWidth, dstHeight);
        Rectangle lastClipping = gc.getClipping();
        try {
            Utils.setClipping(gc, cellBounds);
            for (int i = 0; i < imgThumbnail.length; i++) {
                Image image = imgThumbnail[i];
                if (image == null) {
                    continue;
                }
                Rectangle srcBounds = image.getBounds();
                if (i == 0) {
                    int w = dstWidth;
                    int h = dstHeight;
                    if (imgThumbnail.length > 1) {
                        w = w * 9 / 10;
                        h = h * 9 / 10;
                    }
                    gc.drawImage(image, srcBounds.x, srcBounds.y, srcBounds.width, srcBounds.height, x, y, w, h);
                } else {
                    int w = dstWidth * 3 / 8;
                    int h = dstHeight * 3 / 8;
                    gc.drawImage(image, srcBounds.x, srcBounds.y, srcBounds.width, srcBounds.height, x + dstWidth - w, y + dstHeight - h, w, h);
                }
            }
        } catch (Exception e) {
            Debug.out(e);
        } finally {
            Utils.setClipping(gc, lastClipping);
        }
    }
    TorrentUIUtilsV3.releaseContentImage(ds);
}
Also used : Rectangle(org.eclipse.swt.graphics.Rectangle) ContentImageLoadedListener(com.biglybt.ui.swt.utils.TorrentUIUtilsV3.ContentImageLoadedListener) Image(org.eclipse.swt.graphics.Image)

Example 3 with ContentImageLoadedListener

use of com.biglybt.ui.swt.utils.TorrentUIUtilsV3.ContentImageLoadedListener in project BiglyBT by BiglySoftware.

the class ColumnThumbnail method cellHover.

// @see com.biglybt.pif.ui.tables.TableCellToolTipListener#cellHover(com.biglybt.pif.ui.tables.TableCell)
@Override
public void cellHover(TableCell cell) {
    final Object ds = cell.getDataSource();
    Image[] imgThumbnail = TorrentUIUtilsV3.getContentImage(ds, true, new ContentImageLoadedListener() {

        @Override
        public void contentImageLoaded(Image image, boolean wasReturned) {
            TorrentUIUtilsV3.releaseContentImage(ds);
        }
    });
    cell.setToolTip(imgThumbnail == null ? null : imgThumbnail[0]);
}
Also used : ContentImageLoadedListener(com.biglybt.ui.swt.utils.TorrentUIUtilsV3.ContentImageLoadedListener) Image(org.eclipse.swt.graphics.Image)

Aggregations

ContentImageLoadedListener (com.biglybt.ui.swt.utils.TorrentUIUtilsV3.ContentImageLoadedListener)3 Image (org.eclipse.swt.graphics.Image)3 Rectangle (org.eclipse.swt.graphics.Rectangle)2 DiskManagerFileInfo (com.biglybt.core.disk.DiskManagerFileInfo)1 DownloadManager (com.biglybt.core.download.DownloadManager)1 TOTorrent (com.biglybt.core.torrent.TOTorrent)1 TableRowCore (com.biglybt.ui.common.table.TableRowCore)1 Color (org.eclipse.swt.graphics.Color)1 Point (org.eclipse.swt.graphics.Point)1