=== modified file 'src/com/goldencode/p2j/ui/client/gui/ComboBoxGuiImpl.java' --- src/com/goldencode/p2j/ui/client/gui/ComboBoxGuiImpl.java 2016-05-02 13:37:02 +0000 +++ src/com/goldencode/p2j/ui/client/gui/ComboBoxGuiImpl.java 2016-05-12 15:39:07 +0000 @@ -1499,7 +1499,6 @@ int yt = orig.y + 1 + (dim.height + fnt.pointSize)/2; gd.setFontStyle(fnt.style); // enabled state controls text drawing - int boxWidth = dim.width - DROP_DOWN_BUTTON_SIZE; if (isEnabled()) { if (focused) @@ -1510,14 +1509,14 @@ { gd.setColor(gc.fgColor); } - gd.drawString(display, boxWidth, dim.height, xt, yt, 0, 0); + gd.drawString(display, xt, yt, w, h, orig.x, orig.y); } else { gd.setColor(lightShadow); - gd.drawString(display, boxWidth, dim.height, xt + 1, yt + 1, 1, 1); + gd.drawString(display, xt + 1, yt + 1, w, h, orig.x, orig.y); gd.setColor(darkShadow); - gd.drawString(display, boxWidth, dim.height, xt, yt, 0, 0); + gd.drawString(display, xt, yt, w, h, orig.x, orig.y); } // draw dotted rectangle around focused item text === modified file 'src/com/goldencode/p2j/ui/client/gui/ScrollableSelectionListGuiImpl.java' --- src/com/goldencode/p2j/ui/client/gui/ScrollableSelectionListGuiImpl.java 2016-05-02 13:37:02 +0000 +++ src/com/goldencode/p2j/ui/client/gui/ScrollableSelectionListGuiImpl.java 2016-05-12 15:35:04 +0000 @@ -699,11 +699,11 @@ } // draw item text - gd.drawString(getItemText(number), rw - ((ComboBoxGuiImpl)box).getDropDownScrollBarWidth(), - rh, + gd.drawString(getItemText(number), box != null && box.config().mode == ComboBoxConfig.Mode.SIMPLE ? x + ComboBoxGuiImpl.ENTRY_SHIFT : x + ComboBoxGuiImpl.TEXT_SHIFT, - y + 1 + (rh + fontSize)/2, 0, 0); + y + 1 + (rh + fontSize)/2, rw - ((ComboBoxGuiImpl)box).getDropDownScrollBarWidth() - ComboBoxGuiImpl.ENTRY_SHIFT, + rh, x, y); // draw the dotted line for selected item (not for SIMPLE mode of the combo-box) if (enabled && number == currentRow() && === modified file 'src/com/goldencode/p2j/ui/client/gui/driver/AbstractGuiDriver.java' --- src/com/goldencode/p2j/ui/client/gui/driver/AbstractGuiDriver.java 2016-05-06 16:14:46 +0000 +++ src/com/goldencode/p2j/ui/client/gui/driver/AbstractGuiDriver.java 2016-05-12 14:52:07 +0000 @@ -706,29 +706,26 @@ } /** - * Draw a string which can be centered within its box and can have an offset along horizontal - * and/or vertical. If the box is provided width its nonzero width and height, then x and y - * coordinates don't take into account and the given text is centered within the provided box - * and shifted along horizontal and/or vertical. + * Draw a string using the provided text box and text offset position. * - * @param text - * text string to draw. - * @param boxWidth - * The text box width, which needs to be matched when drawing. - * @param boxHeight - * The text box width, which needs to be matched when drawing. - * @param x - * The left position. - * @param y - * The top position. - * @param xOffset - * The horizontal text offset from its centered position. - * @param yOffset - * The vertical text offset from its centered position. + * @param text + * text string to draw. + * @param x + * The left text position. + * @param y + * The top text position. + * @param boxWidth + * The text box width, which needs to be matched when drawing. + * @param boxHeight + * The text box height, which needs to be matched when drawing. + * @param xBoxOffset + * The horizontal box position. + * @param yBoxOffset + * The vertical box position. */ @Override - public void drawString(String text, int boxWidth, int boxHeight, int x, int y, - int xOffset, int yOffset) + public void drawString(String text, int x, int y, int boxWidth, int boxHeight, + int xBoxOffset, int yBoxOffset) { if (isEmptyText(text)) { @@ -741,8 +738,8 @@ ps.y = y; ps.width = boxWidth; ps.height = boxHeight; - ps.xOffset = xOffset; - ps.yOffset = yOffset; + ps.xOffset = xBoxOffset; + ps.yOffset = yBoxOffset; ews.offer(ps); } === modified file 'src/com/goldencode/p2j/ui/client/gui/driver/GuiDriver.java' --- src/com/goldencode/p2j/ui/client/gui/driver/GuiDriver.java 2016-05-02 13:05:43 +0000 +++ src/com/goldencode/p2j/ui/client/gui/driver/GuiDriver.java 2016-05-12 14:51:49 +0000 @@ -178,28 +178,25 @@ public void drawStringCentered(String text, int legacyWidth, int legacyHeight, int x, int height); /** - * Draw a string which can be centered within its box and can have an offset along horizontal - * and/or vertical. If the box is provided width its nonzero width and height, then x and y - * coordinates don't take into account and the given text is centered within the provided box - * and shifted along horizontal and/or vertical. + * Draw a string using the provided text box and text offset position. * * @param text * text string to draw. + * @param x + * The left text position. + * @param y + * The top text position. * @param boxWidth * The text box width, which needs to be matched when drawing. * @param boxHeight - * The text box width, which needs to be matched when drawing. - * @param x - * The left position. - * @param y - * The top position. - * @param xOffset - * The horizontal text offset from its centered position. - * @param yOffset - * The vertical text offset from its centered position. + * The text box height, which needs to be matched when drawing. + * @param xBoxOffset + * The horizontal box position. + * @param yBoxOffset + * The vertical box position. */ - public void drawString(String text, int boxWidth, int boxHeight, int x, int y, - int xOffset, int yOffset); + public void drawString(String text, int x, int y, int boxWidth, int boxHeight, + int xBoxOffset, int yBoxOffset); /** * The method performs a layout operation on the supplied text and === modified file 'src/com/goldencode/p2j/ui/client/gui/driver/web/GuiWebSocket.java' --- src/com/goldencode/p2j/ui/client/gui/driver/web/GuiWebSocket.java 2016-05-02 13:05:43 +0000 +++ src/com/goldencode/p2j/ui/client/gui/driver/web/GuiWebSocket.java 2016-05-12 14:52:31 +0000 @@ -2540,30 +2540,27 @@ } /** - * Draw a string which can be centered within its box and can have an offset along horizontal - * and/or vertical. If the box is provided width its nonzero width and height, then x and y - * coordinates don't take into account and the given text is centered within the provided box - * and shifted along horizontal and/or vertical. + * Draw a string using the provided text box and text offset position. * * @param text * text string to draw. * @param centered * Flag indicating if the text is centered vertically. * @param x - * The left position. + * The left text position. * @param y - * The top position. + * The top text position. * @param boxWidth * The text box width, which needs to be matched when drawing. * @param boxHeight - * The text box width, which needs to be matched when drawing. - * @param xOffset - * The horizontal text offset from its centered position. - * @param yOffset - * The vertical text offset from its centered position. + * The text box height, which needs to be matched when drawing. + * @param xBoxOffset + * The horizontal box position. + * @param yBoxOffset + * The vertical box position. */ public void drawString(String text, boolean centered, int x, int y, int boxWidth, int boxHeight, - int xOffset, int yOffset) + int xBoxOffset, int yBoxOffset) { int length = text.length() * 2 + 33; byte[] message = allocateDrawingOp(PaintPrimitives.DRAW_STRING, length); @@ -2590,10 +2587,10 @@ writeMessageInt32(message, offset, boxHeight); offset += 4; - writeMessageInt32(message, offset, xOffset); + writeMessageInt32(message, offset, xBoxOffset); offset += 4; - writeMessageInt32(message, offset, yOffset); + writeMessageInt32(message, offset, yBoxOffset); offset += 4; } === modified file 'src/com/goldencode/p2j/ui/client/gui/driver/web/res/p2j.canvas_renderer.js' --- src/com/goldencode/p2j/ui/client/gui/driver/web/res/p2j.canvas_renderer.js 2016-05-05 16:12:00 +0000 +++ src/com/goldencode/p2j/ui/client/gui/driver/web/res/p2j.canvas_renderer.js 2016-05-12 15:33:22 +0000 @@ -1778,63 +1778,47 @@ } /** - * Draw a string that can be centered within its box and can have an offset along horizontal - * and/or vertical. If the box is provided width its nonzero width and height, then x and y - * coordinates don't take into account and the given text is centered within the provided box - * and shifted along horizontal and/or vertical. + * Draw a string within its box. * * @param {String} text * The text to draw. * @param {Number} x - * The left position. + * The left text position. * @param {Number} y - * The top position. + * The top text position. * @param {Number} boxWidth * The text box width, which needs to be matched when drawing. * @param {Number} boxHeight * The text box width, which needs to be matched when drawing. - * @param {Number} xOffset - * The horizontal text offset from its centered position. - * @param {Number} yOffset - * The vertical text offset from its centered position. + * @param {Number} xBoxOffset + * The horizontal box position. + * @param {Number} yBoxOffset + * The vertical box position. */ -CanvasRenderer.prototype.drawTextBoxAlligned = function(text, x, y, boxWidth, boxHeight, - xOffset, yOffset) +CanvasRenderer.prototype.drawTextWithinBox = function(text, x, y, boxWidth, boxHeight, + xBoxOffset, yBoxOffset) { - var origY = y; - - var textWidth; - var cfont = p2j.screen.getCurrentFont(); - if (cfont) + var currentFont = p2j.screen.getCurrentFont(); + if (currentFont) { - textWidth = p2j.fonts.getTextWidth(cfont, text); - if (boxWidth > 0 && textWidth > 0 && boxWidth - x - textWidth <= 1) - { // ignore x padding and draw text centered. - x = (boxWidth - textWidth) / 2 + xOffset; - } - } + var lwidth = boxWidth - x + xBoxOffset; + var textHeight = this.fontsManager.getTextHeight(currentFont, text); + var textWidth = this.fontsManager.getTextWidth(currentFont, text); + + var widthScale = lwidth / textWidth; + + // scale drawing context to computed width + // this scales the desired structure.x as well so it needs adjusting + this.ctx.save(); + this.ctx.scale(widthScale, 1); + + this.ctx.textBaseline = 'bottom'; - this.ctx.textBaseline = 'bottom'; - - this.ctx.fillText(text, x, y); - - if (p2j.fonts.isUnderlined(cfont)) - { - // if the style is underline, draw a line under the text - var txtHeight = p2j.fonts.getTextHeight(cfont, text); - if (textWidth === undefined) - { - textWidth = p2j.fonts.getTextWidth(cfont, text); - } - - var x1 = x; - var x2 = x + textWidth; - var y1 = origY; - var y2 = y1; - - this.strokeLineSegment(x1, y1, x2, y2, this.rawColor); + this.ctx.fillText(text, x / widthScale, y); + this.ctx.restore(); } } + /** * Draws a given text at the given (x,y) position fitted to the given text rectangle. * === modified file 'src/com/goldencode/p2j/ui/client/gui/driver/web/res/p2j.screen.js' --- src/com/goldencode/p2j/ui/client/gui/driver/web/res/p2j.screen.js 2016-05-06 16:14:46 +0000 +++ src/com/goldencode/p2j/ui/client/gui/driver/web/res/p2j.screen.js 2016-05-12 14:59:34 +0000 @@ -1381,20 +1381,21 @@ var boxHeight = p2j.socket.readInt32BinaryMessage(message, idx + offset); offset = offset + 4; - var xOffset = p2j.socket.readInt32BinaryMessage(message, idx + offset); - offset = offset + 4; - - var yOffset = p2j.socket.readInt32BinaryMessage(message, idx + offset); - offset = offset + 4; - + var xBoxOffset = p2j.socket.readInt32BinaryMessage(message, idx + offset); + offset = offset + 4; + + var yBoxOffset = p2j.socket.readInt32BinaryMessage(message, idx + offset); + offset = offset + 4; + + this.canvasRenderer.drawText(text, x, y, centered); if (boxWidth === 0 || boxHeight === 0) { this.canvasRenderer.drawText(text, x, y, centered); } else { - this.canvasRenderer.drawTextBoxAlligned(text, x, y, boxWidth, boxHeight, - xOffset, yOffset); + this.canvasRenderer.drawTextWithinBox(text, x, y, boxWidth, boxHeight, + xBoxOffset, yBoxOffset); } extra = " text = " + text + "; x = " + x + "; y = " + y +