From: Tuukka Lehtonen Date: Fri, 7 Dec 2018 12:52:57 +0000 (+0200) Subject: Implement ImageDescriptor.getImageData(int zoom) X-Git-Tag: v1.43.0~136^2~224^2 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F33%2F2533%2F1;p=simantics%2Fplatform.git Implement ImageDescriptor.getImageData(int zoom) gitlab #228 Change-Id: I0b0294a8a48d6d633c452fee780be502f4d58406 --- 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