Draw rectangle on a Window DC
Dennis Lee Bieber
wlfraed at ix.netcom.com
Tue Nov 5 20:47:21 EST 2002
Anand fed this fish to the penguins on Tuesday 05 November 2002 01:03
am:
> Thanks Dennis. That technique worked.
> But since I use a XOR operator the outline of the rectangle
> does not have a unique color, but depends on the pixel color at (x,y).
>
When the user releases the "drag" you can redraw the final rectangle
in the desired solid color.
The other means of maintaining a fixed color for rubber banding
requires either lots of bit-planes with the resultant very large color
lookup table OR the use of a display list with the allowance of display
noise until finished.
In the first case, say you need 128 colors for the display, and only
one "overlay" (the rubber band). You allocate a color table for 256
colors (1 overlay bit, 7 color bits). The first 128 entries in the
lookup table are the desired colors -- the NEXT 128 entries are all set
to the "rubberband" color. Drawing the line will be slow on most
true-color/non-bitplane hardware as you draw the line by:
set_pixel(get_pixel(x,y) OR 0x80, x, y) and "undraw" the line by
set_pixel(get_pixel(x,y) AND 0x7F, x, y).
Bit-plane hardware (the Commodore Amiga was one such system)
simplifies the operation because they have settings for which
bitplane(s) a draw operation will affect -- no need for the OR/AND bit
manipulation. set_mask(0x80) {says only one bit will be modified in
subsequent operations}; draw_line(0xFF, x1, y1, x2, y2) {draws};
draw_line(0x00, x1, y1, x2, y2) {erases line}.
The second case requires a display list manager (GKS was one such). In
this situation, you create a new "segment" with a unique ID. You draw
with whatever color, and to erase when the rubberband moves you draw
the background color. This will result in making a mess of the
previously drawn data BUT... when the user releases the "drag" you
delete the "segment", set the active segment to the base drawing
segment, draw the final rectangle, and invoke a refresh of the display
list (the manager than processes all the drawing commands that have
been stored to recreate the display).
--
> ============================================================== <
> wlfraed at ix.netcom.com | Wulfraed Dennis Lee Bieber KD6MOG <
> wulfraed at dm.net | Bestiaria Support Staff <
> ============================================================== <
> Bestiaria Home Page: http://www.beastie.dm.net/ <
> Home Page: http://www.dm.net/~wulfraed/ <
More information about the Python-list
mailing list