Status: New
Owner: ----

New issue 219 by steeve.s...@gmail.com: PSWTText not respecting bounds.x and bounds.y in painting
http://code.google.com/p/piccolo2d/issues/detail?id=219

What steps will reproduce the problem?
1. create a composite PNode containing a child of type PSWTText
2. in layoutChildren() method write the following code

                PBounds bounds = getBounds();
                bounds.x = 5;
                bounds.y = 5;
                bounds.width -= 10;
                bounds.height -= 10;
                this.textNode.setBounds(bounds);

3. run the program

What is the expected output? What do you see instead?

this code should produce a text with a xmargin and a ymargin of 5 from its parent .

Instead x and y left and top margin are ignored. bottom and right margin are ok.

It work if i use translate method, but it should also work with plain x and y set.

//see in code replacement to fix it

    /**
* Paints this object normally (show it's text). Note that the entire text
     * gets rendered so that it's upper left corner appears at the origin of
     * this local object.
     *
     * @param ppc The graphics context to paint into.
     */
    @Override
        public void paintAsText(final PPaintContext ppc) {
        final SWTGraphics2D sg2 = (SWTGraphics2D) ppc.getGraphics();

        if (!isTransparent()) {
            if (getPaint() == null) {
                sg2.setBackground(Color.WHITE);
            }
            else {
                sg2.setBackground((Color) getPaint());
            }

            //bad sg2.fillRect(0, 0, (int) getWidth(), (int) getHeight());
sg2.fillRect(getX(), getY(), (int) getWidth(), (int) getHeight()); //fixed
        }

        sg2.translate(this.padding, this.padding);

        sg2.setColor(this.penColor);
        sg2.setFont(this.font);

        String line;
        //bad double y = 0;
        double y = getY(); //fixed

        final FontMetrics fontMetrics = sg2.getSWTFontMetrics();

        final Iterator lineIterator = this.lines.iterator();
        while (lineIterator.hasNext()) {
            line = (String) lineIterator.next();
            if (line.length() != 0) {
                //bad sg2.drawString(line, 0, y, true);
                sg2.drawString(line, getX(), y, true); //fixed
            }

            y += fontMetrics.getHeight();
        }

        sg2.translate(-this.padding, -this.padding);
    }


--
Piccolo2D Developers Group: http://groups.google.com/group/piccolo2d-dev?hl=en

Reply via email to