Drawing And Invalidating In Windowsexample - Casio ClassPad 300 Programming Manual

Sdk programming guide
Hide thumbs Also See for ClassPad 300:
Table of Contents

Advertisement

screen invalidation, since your Draw() function is called specifically because an area of
the screen has been invalidated.
If you need to draw on the screen outside of the draw function you need to remember to
invalidate the area you are going to draw to before you start drawing. If you want to be
allowed to draw anywhere within the client area of your object, you can simply call the
Invalidate() function with no parameters, which invalidates the area of the screen
corresponding to an objects client area. You can also calculate and specify a more
limiting rectangle to clip your drawing, and pass that rectangle to the Invalidate()
function. No matter how large the invalidated rectangle on the screen, you are never
allowed to draw outside of an object's borders.

Drawing and Invalidating in WindowsExample

WindowsExample uses invalidation to draw in the DrawLines() function of
ExampleWindow.cpp. This function is called when a user clicks on the Toggle Lines
button.
Before DrawLines() can begin drawing to the screen, it must first invalidate the area
where it will draw. In this case the entire ExampleWindow will be drawn to, so
Invalidate() with no clip region is called to invalidate then entire mClient. Let's take a
closer look at DrawLines:
void ExampleWindow::DrawLines(void)
{
PegColor Color(BLACK, WHITE, CF_FILL);
SIGNED yPos = mClient.wTop;
Invalidate(); // invalidate my client area
BeginDraw(); // prepare for drawing
Rectangle(mClient, Color, 0);
if(HasLines)
{
while(yPos <= mClient.wBottom)
{
Line(mClient.wLeft, yPos, mClient.wRight, yPos, Color);
yPos += 4;
}
}
EndDraw();
}
As you can see, before drawing the lines the entire ExampleWindow area is invalidated
with the call to Invalidate. Commenting out the Invalidate() call will give you the result
you should expect -- nothing will get drawn to the screen. You should also notice that all
drawing functions are placed in between a BeginDraw() and EndDraw() call.
Looking at ExampleWindow's draw function you may wonder why there is a call to
DrawLines(). As mentioned before, Draw gets called because the screen was
invalidated. We want to make sure the lines are redrawn after an invalidation occurs that
wasn't because a user clicked on the Toggle Lines button. Consider moving the
PanWindow with the pen. Since we are moving the location of PanWindow, a new
36

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents