Gabrielle wrote:
I have some questions about your attachment file:TestRectSelect.py
Q1: Why you write ogl.OGLInitialize()? Is it a must to write this when
using wx.lib.ogl? But I found some other demos, there isn't such code.
OGLInitialize sets up some things that the OGL library sometimes needs.
Not every application needs what it does, but since it costs very
little, you should get in the habit of using it every time.
Q2: ...
rect.Inflate(2,2) . I can see the difference if I set Inflate(0,0), but I
can't tell the differenct if I set Inflate(5,5). In doc, it tells this
method is used to increase the size of rectangle, but I can't understand it
well...Could you explain it in detail ?
It's not really that hard to understand, is it? A rectangle is nothing
other than a container that holds four numbers: x, y, width, and
height. That's it, nothing more. When you call rect.Inflate(2,2), you
are adding 2 to the width and to the height.
So, why didn't it make a visible difference? Take some time to read
through and understand what the code is doing, instead of just making
random changes. The rectangle you are changing is the one returned by
that _getRect function. That function is internal to the OnDragLeft
method, and it is only used in the calls to RefreshRect later.
RefreshRect is just used to tell the system that "the pixels within this
region need to be redrawn". The drawing will actually be done later.
Remember that the operating system and the graphics card don't have any
idea about shapes and circles and rectangles. When you drag a shape,
what actually happens is that you draw the shape in the new location,
and you erase the pixels where the shape used to be, by redrawing
whatever colors were underneath it. That can be an expensive operation
if the object is large, so you try to redraw as few pixels as possible.
That's what this is doing. It is coming up with the smallest region
that will make everything look up to date.
So, when you increase the size of the rectangle in that one function,
all you're doing is causing extra pixels to be redrawn that didn't
really need to be redrawn. Since those pixels haven't changed, you
won't see the effect. When you reduce the size of the rectangle, the
system doesn't know that it needs to redraw those newly exposed pixels,
so the remnants of your object will remain.
···
--
Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.