Canvas co-ordinates, root.width, root.height and missing pixels.

55 views
Skip to first unread message

David Goadby

unread,
Apr 29, 2016, 3:43:10 PM4/29/16
to Kivy users support
I am using an HDMI with a 800x600 monitor. I am creating a screen for testing the touch screen calibration. I am trying to draw a rectangle around the outer edge of the screen. I think there is a pixel addressing anomaly that results in missing pixels.

These are the kv statments I use for creating a border rectangle:

canvas:  
        #  screen border for overscan check               
        Line:
            rectangle: 0, 0, root.width, root.height
            dash_offset: 5
            dash_length: 3

When I run this I get lines along the left side and along the bottom of the screen. The expected right hand and top edge have no visible lines.

I then change the kv statements to this:

canvas:   
        #  screen border for overscan check            
        Line:
            rectangle: 0, 0, root.width - 1, root.height - 1
            dash_offset: 5
            dash_length: 3

The result is now a perfect rectangle around the edges of the monitor screen.

I have repeated this with another (different) monitor and the results are the same. Kivy reports the screen size from root.width and root.height as 800 and 600 which is correct.

What seems to be happening is the rectangle code adds the width (800) to the left location (0) giving 800 for the rightmost X coordinate.  With a screen width of 800 then the maximum value of X is 799 which explains why the pixels are lost. Ditto the vertical axis.

I guess that one pixel at the edge of the screen is rarely noticed. I see a lot of code where the width value is used for labels, buttons etc. Again, a single pixel will seldom show particularly if it is not at the screen edge.

So, Is this actually a bug or is there something about canvas vertex instructions that I have not understood?




OlyGrim

unread,
Apr 30, 2016, 9:25:58 AM4/30/16
to Kivy users support
I think, but i'm not sure, it's because the (0, 0) pixel is counted, as general in python. So width is right 800 pixels, but the first pixel starts at 0




David Goadby

unread,
Apr 30, 2016, 3:07:02 PM4/30/16
to Kivy users support

Well that's the issue here I think.

If we have a screen which is 10 pixels wide then do we have pixels 0,1,2,3,4,5,6,7,8,9  - which is 10 pixels and 9 "gaps" or
do we have pixels 0,1,2,3,5,6,7,8,9,10 - which is 11 pixels and 10 "gaps".

Is the width (or height) the number of pixels or the number of "gaps".

If we have one pixel then are we saying it is width 0 or width 1? If width 1 then the first example is correct for a width of 10. If it is width 1 then the second example is right.

I think it's only a problem when you use canvas instructions; and maybe I am worrying too much. ;-)

OlyGrim

unread,
Apr 30, 2016, 3:53:03 PM4/30/16
to Kivy users support
Look this code:

Widget:
    Widget:
        center: root.center
        size: 500, 500
        canvas:
            Color:
                rgba: 0, 0, 1, 1
            Rectangle:
                pos: self.pos
                size: self.size
            Color:
                rgba: 1, 0, 0, 1
            Line:
                rounded_rectangle: (*self.pos, *self.size, 60, 60, 60, 60, 100)
                width: 10

we see that the line is half inside and half outside. So i think the problem comes from there

PS: Sorry for my bad english

Reply all
Reply to author
Forward
0 new messages