GoogleCodeArchive / piccolo2d

Automatically exported from code.google.com/p/piccolo2d
0 stars 0 forks source link

PSWTText not respecting bounds.x and bounds.y in painting #219

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
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);
    }

Original issue reported on code.google.com by steeve.s...@gmail.com on 8 Jun 2011 at 3:49

GoogleCodeExporter commented 9 years ago
my bad, i didn't read paint method comment.
but why limiting use of direct x, y set ?

Original comment by steeve.s...@gmail.com on 8 Jun 2011 at 2:01

GoogleCodeExporter commented 9 years ago

Original comment by heue...@gmail.com on 31 Aug 2012 at 8:29