From 399abb1d550786b9077895ea1587d3f556fb0ed0 Mon Sep 17 00:00:00 2001 From: Tuukka Lehtonen Date: Fri, 7 Dec 2018 14:52:57 +0200 Subject: [PATCH] Implement ImageDescriptor.getImageData(int zoom) gitlab #228 Change-Id: I0b0294a8a48d6d633c452fee780be502f4d58406 --- .../utils/ui/gfx/ColorImageDescriptor.java | 52 +++++++++----- .../utils/ui/gfx/TextImageDescriptor.java | 72 +++++++++++-------- 2 files changed, 77 insertions(+), 47 deletions(-) diff --git a/bundles/org.simantics.utils.ui/src/org/simantics/utils/ui/gfx/ColorImageDescriptor.java b/bundles/org.simantics.utils.ui/src/org/simantics/utils/ui/gfx/ColorImageDescriptor.java index eca35f1fc..6c0f26d4e 100644 --- a/bundles/org.simantics.utils.ui/src/org/simantics/utils/ui/gfx/ColorImageDescriptor.java +++ b/bundles/org.simantics.utils.ui/src/org/simantics/utils/ui/gfx/ColorImageDescriptor.java @@ -36,28 +36,44 @@ public class ColorImageDescriptor extends ImageDescriptor { this.selected = selected; } + @Override + public ImageData getImageData(int zoom) { + int w = width; + int h = height; + if (zoom > 100) { + float s = zoom / 100.0f; + w = Math.round(width * s); + h = Math.round(height * s); + } + return getImageData(w, h); + } + @Override public ImageData getImageData() { - ImageData id = new ImageData(width, height, 24, PALETTEDATA); - int cx = width / 2; - int cy = height / 2; - int dst = height * width / 23; - for (int x=0; x 100) { + float s = zoom / 100.0f; + w = Math.round(width * s); + h = Math.round(height * s); + fs = Math.round(fontSize * s); + } + return getImageData(w, h, fs); + } + + private ImageData getImageData(int width, int height, int fontSize) { + ImageData id = new ImageData(width, height, 24, _RGB); + + BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); + Graphics2D g = (Graphics2D) bi.getGraphics(); + g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); + Font f = new Font(font, style, fontSize); + g.setFont( f ); + Color c = new Color(rgb); + g.setColor( c ); + FontMetrics fm = g.getFontMetrics(f); + Rectangle2D rect = fm.getStringBounds(text, g); + g.drawString(text, (float) ((width-rect.getWidth())/2), (float) ( (height/2) + (height-rect.getHeight())/2) ); + g.dispose(); + + Raster alpha = bi.getAlphaRaster(); + for (int x=0; x