PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

EasyCE 'hline' function...

Hi all,

It's my first post on this board and 'scuse my english, I'm a french guy! First, thank you Phantom for all your great stuffs (EasyCE & Tutorials...).

Now, here is my question...

using this hline function (from EasyCE):
void hline( int x1, int y1, int len, PIXEL color )
{
     PIXEL* addr = (PIXEL*)getbuffer();
     addr += x1 + (y1 * 240);
     for ( int i = 0; i <= len; i++ ) *addr++ = color;
}

if you call this function like this:
hline( 0, 0, 10, color);
you'll get a 11 pixels length line, no? 'cause of the "<=" sign in the FOR loop.

could someone explain me if it's a normal behaviour?

thanks
c4simir
yeah, you get 11 pixels, normal? well, #define normal... I would guess it's pretty usually if you assume that len is line lenght (name suggests so) so to draw a line from 0 to 10 you need 11, not 10 pixels (you have to place pixels on those coords 0,1,2,3,4,5,6,7,8,9,10 - 11 together)
You could probably argue about this thru...:)
ok, it's a little bit strange, but I understand. I have to add "len" to my "x1" to get x2, but the real line length in pixels is always one more than "len"... I have to assume that.

thanks for your help.

c4simir

in the same way, I have another trouble with the "bar" function:
void bar( int x1, int y1, int x2, int y2, PIXEL color )
{
     for ( int i = y1; i < y2; i++ ) hline( x1, i, x2 - x1, color );
}

For example, if I try to fill the entire screen with this function: bar(0, 0, 239, 319, color);
the last line in the bottom of the screen (y=319) is not drawn.
It's not what I expected. Why is the y2 coord' not included (I mean "<=") in the FOR loop ?

c4simir (I know, I'm boring with all my questions... ;o) )
Well it just might be wrong, if you have such problems notice Phantom about them. He is the main person behind EasyCE.
What do you guys think abou this?  The line drawing function should have either a parameter, or perferably another function that's called to enable drawing lines that include the last pixel.  Something line SetLineMode(LASTPIXEL, TRUE).

When you're drawing single lines, you probably want the last pixel drawn, however a polyline routine will end up drawing the same pixel twice if you draw the last pixel.  If you're drawing with a ROP that uses the existing destination pixel in it's calcuation for the color of the new pixel, then you'll end up with the wrong color at the last pixel in the line.  EasyCE probably doesn't support ROPs in blits or line drawing so this is moot.

The method that EasyCE uses to specify a rectangular region is probably the correct one to use.  It's the same used by Windows and most of the world, and it makes it easy to get the width and height of the inside region by simple subtraction.