Hi
Here is my current design:
In the drawing function, i declared an array : PIXEL[1024][768], the
drawing function will keep drawing every pixel in the array to the
screen.
There are many kind of component in my GUI library, all of them have an
OnPaint() method. The drawing function will pass a pointer to each
component like OnPaint(Pixel+(x+y*768)), then component draw whatever
they like to that array.
Is it good?
thanks
from Peter (
[email protected])
Peter,
your method will work, but it will, as others have said, be very slow.
the method would be fine for something like a microcontroller, where
processing power is limited, but for a PC, where you expect speed, this
would be incredibly slow.
By looping around your putpixel() routine, you are repeatedly redrawing
pixels which have not changed, rather than concentrating on those that
have.
Think about it this way; Every high level drawing function MUST be
designed to check whether the thing being drawn is totally inside the
window, totally outside it, or partway in and partway outside. it can
then crop off the bits that would otherwise be outside the drawing area,
(or more importantly, outside your array of pixels!) This makes high
level functions slow. It is therefore important to avoid simple
functions like putpixel(), which only place a single pixel once the
checks are done, in preference for bitblit() which does the same tests,
but then puts perhaps 10000 pixels.
What you could do is this:
Each high level drawing function is given a pointer to your
pixel_buffer, and access to two x,y coordinates, the top_left, and
bottom_right points. These are initialised to impossible values
(top_left set to the bottom right of the screen and vice-versa.) Each
drawing function then checks to see if the thing it has to draw is
inside the valid range of pixels (in other words, on the screen) and
draws what it can to your pixel_buffer. It then updates the top_left and
bottom_right values to the extremes of a box containing the object. Each
drawing function can expand the region, but not shrink it. When all of
your functions have finished, the two points define a box containing all
the parts of the screen that need to be updated. You then bitblit() only
this rectangle to the screen.
Obviously, this process can be made asynchronous, by interrupting the
drawing process and bitblitting what has changed so far, then
continuing, but this is more complex.
Hope this helps
matt