=== modified file 'src/com/goldencode/p2j/ui/client/gui/ImageGuiImpl.java' --- src/com/goldencode/p2j/ui/client/gui/ImageGuiImpl.java 2015-09-01 18:27:30 +0000 +++ src/com/goldencode/p2j/ui/client/gui/ImageGuiImpl.java 2015-09-01 20:02:46 +0000 @@ -348,7 +348,90 @@ return screen().coordinates().rowToNative(height()); } } - + + /** + * Calculates the drawing parameters: + * width = (Integer) drawingParameters[0]; + * height = (Integer) drawingParameters[1]; + * offsetX = (Integer) drawingParameters[2]; + * offsetY = (Integer) drawingParameters[3]; + * transparent = (Boolean) drawingParameters[4]; + * stretchToFit = (Boolean) drawingParameters[5]; + * retainShape = (Boolean) drawingParameters[6]; + * convert3D = (Boolean) drawingParameters[7]; + * + * @return The array filled with drawing parameters. + */ + protected Object[] calculateDrawingParameters() + { + if (img == null) + { + return null; + } + CoordinatesConversion c = screen().coordinates(); + + // get the current image config + ImageConfig icfg = (ImageConfig) config(); + + // the width and height in pixels or chars overridden by size phrase has higher priority + // than natural image size itself + int w = icfg.widthPixels > 0 ? icfg.widthPixels : icfg.widthChars > 0 ? + c.widthToNative(icfg.widthChars) : c.widthToNative(width()); + int h = icfg.heightPixels > 0 ? icfg.heightPixels : icfg.heightChars > 0 ? + c.heightToNative(icfg.heightChars) : c.heightToNative(height()); + + // compute final image dimensions + int iw = 0; + int ih = 0; + + if (icfg.stretchToFit && !isIcon) + { + // need to fit the image to display area size + iw = w; + ih = h; + } + else + { + // take the final image size as minimum from requested and real image sizes + iw = Math.min(img.getWidth(), w); + ih = Math.min(img.getHeight(), h); + } + + // recalculate image offsets that can be changed + int offsetX = -1; + int offsetY = -1; + + // check if we have the offset variables changed + if (icfg.offsetX != -1) + { + offsetX = icfg.offsetX; + } + else if (icfg.offsetCol != 0.0) + { + offsetX = screen().coordinates().columnToNative(icfg.offsetCol); + } + else if (icfg.widthPixels != 0 || icfg.widthChars != 0.0) + { + offsetX = 0; + } + // Y coordinate + if (icfg.offsetY != -1) + { + offsetY = icfg.offsetY; + } + else if (icfg.offsetRow != 0.0) + { + offsetY = screen().coordinates().rowToNative(icfg.offsetRow); + } + else if (icfg.heightPixels != 0 || icfg.heightChars != 0.0) + { + offsetY = 0; + } + + return new Object[] { iw, ih, offsetX, offsetY, icfg.transparent, + icfg.stretchToFit && !isIcon, icfg.retainShape, icfg.convert3D}; + } + /** * Draw this image. */ @@ -356,77 +439,18 @@ { if (img != null) { - CoordinatesConversion c = screen().coordinates(); - - // get the current image config - ImageConfig icfg = (ImageConfig) config(); - - // the width and height in pixels or chars overridden by size phrase has higher priority - // than natural image size itself - int w = icfg.widthPixels > 0 ? icfg.widthPixels : icfg.widthChars > 0 ? - c.widthToNative(icfg.widthChars) : c.widthToNative(width()); - int h = icfg.heightPixels > 0 ? icfg.heightPixels : icfg.heightChars > 0 ? - c.heightToNative(icfg.heightChars) : c.heightToNative(height()); - - // compute final image dimensions - int iw = 0; - int ih = 0; - - if (icfg.stretchToFit && !isIcon) - { - // need to fit the image to display area size - iw = w; - ih = h; - } - else - { - // take the final image size as minimum from requested and real image sizes - iw = Math.min(img.getWidth(), w); - ih = Math.min(img.getHeight(), h); - } - - // recalculate image offsets that can be changed - int offsetX = -1; - int offsetY = -1; - - // check if we have the offset variables changed - if (icfg.offsetX != -1) - { - offsetX = icfg.offsetX; - } - else if (icfg.offsetCol != 0.0) - { - offsetX = screen().coordinates().columnToNative(icfg.offsetCol); - } - else if (icfg.widthPixels != 0 || icfg.widthChars != 0.0) - { - offsetX = 0; - } - // Y coordinate - if (icfg.offsetY != -1) - { - offsetY = icfg.offsetY; - } - else if (icfg.offsetRow != 0.0) - { - offsetY = screen().coordinates().rowToNative(icfg.offsetRow); - } - else if (icfg.heightPixels != 0 || icfg.heightChars != 0.0) - { - offsetY = 0; - } - /** - * Sets the window icon. The drawing parameters are due to the drawing operations are - * performed on the server side for the web rendering engine implementation. - */ - if (isIcon) - { - gd.setIcon(img, 0, 0, iw, ih, offsetX, offsetY, icfg.transparent, - icfg.stretchToFit && !isIcon, icfg.retainShape, icfg.convert3D); - } + Object[] drawingParameters = calculateDrawingParameters(); + int iw = (Integer) drawingParameters[0]; + int ih = (Integer) drawingParameters[1]; + int offsetX = (Integer) drawingParameters[2]; + int offsetY = (Integer) drawingParameters[3]; + boolean transparent = (Boolean) drawingParameters[4]; + boolean stretchToFit = (Boolean) drawingParameters[5]; + boolean retainShape = (Boolean) drawingParameters[6]; + boolean convert3D = (Boolean) drawingParameters[7]; // render image - gd.drawImage(img, 0, 0, iw, ih, offsetX, offsetY, icfg.transparent, - icfg.stretchToFit && !isIcon, icfg.retainShape, icfg.convert3D); + gd.drawImage(img, 0, 0, iw, ih, offsetX, offsetY, transparent, + stretchToFit, retainShape, convert3D); } return img != null; === modified file 'src/com/goldencode/p2j/ui/client/gui/WindowTitleBar.java' --- src/com/goldencode/p2j/ui/client/gui/WindowTitleBar.java 2015-08-26 22:14:27 +0000 +++ src/com/goldencode/p2j/ui/client/gui/WindowTitleBar.java 2015-09-01 20:11:17 +0000 @@ -288,6 +288,24 @@ title.location().x - c.widthFromNative(nativeInsets.right); title.setWidth(twidth); + if (icon != null && icon.img != null) + { + Object[] drawingParameters = icon.calculateDrawingParameters(); + int iw = (Integer) drawingParameters[0]; + int ih = (Integer) drawingParameters[1]; + int offsetX = (Integer) drawingParameters[2]; + int offsetY = (Integer) drawingParameters[3]; + boolean transparent = (Boolean) drawingParameters[4]; + boolean stretchToFit = (Boolean) drawingParameters[5]; + boolean retainShape = (Boolean) drawingParameters[6]; + boolean convert3D = (Boolean) drawingParameters[7]; + /** + * Sets the window icon. The drawing parameters are due to the drawing operations are + * performed on the server side for the web rendering engine implementation. + */ + gd.setIcon(icon.img, 0, 0, iw, ih, offsetX, offsetY, transparent, + stretchToFit, retainShape, convert3D); + } } /**