From c0b906df2fba8e66147de7e4beca6d9a36a69c31 Mon Sep 17 00:00:00 2001 From: veronie Date: Tue, 16 Feb 2021 16:23:01 +0100 Subject: [PATCH] Images are now shown with the correct scale. --- .../src/xyz/veronie/bgg/ui/parts/BatMain.java | 72 ++++++++++++------- 1 file changed, 47 insertions(+), 25 deletions(-) diff --git a/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/parts/BatMain.java b/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/parts/BatMain.java index cec7827..ff8c419 100644 --- a/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/parts/BatMain.java +++ b/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/parts/BatMain.java @@ -21,17 +21,22 @@ import org.eclipse.jface.viewers.ArrayContentProvider; import org.eclipse.jface.viewers.ColumnLabelProvider; import org.eclipse.jface.viewers.ISelectionChangedListener; import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.OwnerDrawLabelProvider; import org.eclipse.jface.viewers.SelectionChangedEvent; import org.eclipse.jface.viewers.TableViewer; import org.eclipse.jface.viewers.TableViewerColumn; import org.eclipse.swt.SWT; import org.eclipse.swt.events.MouseAdapter; import org.eclipse.swt.events.MouseEvent; +import org.eclipse.swt.graphics.GC; import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.graphics.ImageData; +import org.eclipse.swt.graphics.Rectangle; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Event; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Table; import org.eclipse.swt.widgets.TableColumn; @@ -44,19 +49,6 @@ import xyz.veronie.bgg.types.EventConstants; import xyz.veronie.bgg.ui.helpers.BatColors; import xyz.veronie.bgg.ui.helpers.BatLayouts; - -// TODO: import result.txt from bggtool -// TODO: image sizes in result table -// TODO: fix encoding -// TODO: fetch details from BGG -// TODO: export to results.txt format -// TODO: generate PDF with nandeck -// TODO: handle thing list overwrite -// TODO: Display selection details on game -// TODO: cache family/geeklist descriptions -// TODO: allow different screen scalings -// TODO: handle existing name - @SuppressWarnings("restriction") public class BatMain { private static final String UNNAMED_LIST = "(unsaved list)"; @@ -231,19 +223,49 @@ public class BatMain { TableViewerColumn colThumbnail = createTableViewerColumn(Thing.ThumbHeader, 120, 0); - colThumbnail.setLabelProvider(new ColumnLabelProvider() { - @Override - public Image getImage(Object element) { - Thing t = (Thing) element; +// colThumbnail.setLabelProvider(new ColumnLabelProvider() { +// @Override +// public Image getImage(Object element) { +// Thing t = (Thing) element; +// Image img = t.getThumbnail(); +// return img; +// } +// +// @Override +// public String getText(Object element) { +// return ""; +// } +// +// }); + colThumbnail.setLabelProvider(new OwnerDrawLabelProvider() { + @Override + protected void measure(Event event, Object element) { + Thing t = (Thing) element; Image img = t.getThumbnail(); - return img; - } - - @Override - public String getText(Object element) { - return ""; - } - + Rectangle rectangle = img.getBounds(); + event.setBounds(new Rectangle( + event.x, + event.y, + rectangle.width/2, + rectangle.height/2)); + } + + @Override + protected void paint(Event event, Object element) { + Thing t = (Thing) element; + Image img = t.getThumbnail(); + + final int width = img.getBounds().width; + final int height = img.getBounds().height; + + final Image scaled050 = new Image(event.display, (int)(width*0.5),(int)(height*0.5)); + GC gc = new GC(scaled050); + gc.drawImage(img, 0, 0, width, height, 0, 0, (int)(width*0.5), (int)(height*0.5)); + gc.dispose(); + + event.gc.drawImage(scaled050, event.x, event.y); + } + }); TableViewerColumn colName = createTableViewerColumn(Thing.NameHeader, 400, 1);