473,396 Members | 1,966 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

DrawReversible

Hi!
My application contains a simple drawing module. The user can draw
lines, ellipses and so on. Now, I'm a fan of visual feedback. The user
should see the changes he or she does at the very instant they have been
done. For example, the user draws an ellipse. The ellipse need to be
moved a tad to the left, so the user grabs it with the mouse and moves
it in place. Most professional applications solve this by drawing a
reversible outline of the object(s) selected as they are moved, and then
redraw them in full when the mouse releases them. However, no
DrawReversibleEllipse or DrawReversiblePath are included in the API. how
can this be achieved?

Thanks!

- Peder -
Nov 16 '05 #1
4 4782
You could draw to a GraphicsPath, flatten the path to create a set of points
then do DrawReversibleLine calls for each line segment in the PathPonts
array.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.

"Peder Y" <1@nowhere.com> wrote in message
news:e$**************@TK2MSFTNGP15.phx.gbl...
Hi!
My application contains a simple drawing module. The user can draw
lines, ellipses and so on. Now, I'm a fan of visual feedback. The user
should see the changes he or she does at the very instant they have been
done. For example, the user draws an ellipse. The ellipse need to be
moved a tad to the left, so the user grabs it with the mouse and moves
it in place. Most professional applications solve this by drawing a
reversible outline of the object(s) selected as they are moved, and then
redraw them in full when the mouse releases them. However, no
DrawReversibleEllipse or DrawReversiblePath are included in the API. how
can this be achieved?

Thanks!

- Peder -

Nov 16 '05 #2
Actualy most professional applications don't work this way any more. (Not
the good ones, anyway.)

This 'reversible' drawing simply uses XOR to draw the features, and there
are lots of good reasons not to do this. The only reason this technique
became popular is because it is fairly efficient, and back in the early
1990s, it was the only way of drawing things fast enough to be interactive
and usable. But graphics cards these days are fast enough that this isn't
necessary any more, and you can get much better results using other
techniques. I wrote this a while ago describing some of the techniques:

http://www.interact-sw.co.uk/graphic...ideredharmful/

If you want an example of the kinds of things that go wrong when you use
XOR, I also wrote about that...

http://www.interact-sw.co.uk/iangblo...9/xorartifacts

Hope that helps.
--
Ian Griffiths - http://www.interact-sw.co.uk/iangblog/
DevelopMentor - http://www.develop.com/

"Peder Y" <1@nowhere.com> wrote:
My application contains a simple drawing module. The user can draw lines,
ellipses and so on. Now, I'm a fan of visual feedback. The user should see
the changes he or she does at the very instant they have been done. For
example, the user draws an ellipse. The ellipse need to be moved a tad to
the left, so the user grabs it with the mouse and moves it in place. Most
professional applications solve this by drawing a reversible outline of
the object(s) selected as they are moved, and then redraw them in full
when the mouse releases them. However, no DrawReversibleEllipse or
DrawReversiblePath are included in the API. how can this be achieved?

Nov 16 '05 #3
Hi Ian and thanks for nice pointers!
I have read all your articles and find them very useful. However, I must
admit I approached this another way at first. My original attempt was to
move the graphics primitives themselves and invalidate the area(s) in
question. Now, try painting a 1024x768 image at the bottommost z-order
on a panel, then move the primitives that are placed on top. Maybe I was
going about this the wrong way, but I get a lot of flicker. I'd love to
solve this with transparent objects, but GDI+ seems to produce flicker
no matter. I totally agree with your xor standpoints, but resolved to it
as a last (-intermediate:) solution. Surely someone must have written an
article on this somtime?

- Peder -
Ian Griffiths [C# MVP] wrote:
Actualy most professional applications don't work this way any more. (Not
the good ones, anyway.)

This 'reversible' drawing simply uses XOR to draw the features, and there
are lots of good reasons not to do this. The only reason this technique
became popular is because it is fairly efficient, and back in the early
1990s, it was the only way of drawing things fast enough to be interactive
and usable. But graphics cards these days are fast enough that this isn't
necessary any more, and you can get much better results using other
techniques. I wrote this a while ago describing some of the techniques:

http://www.interact-sw.co.uk/graphic...ideredharmful/

If you want an example of the kinds of things that go wrong when you use
XOR, I also wrote about that...

http://www.interact-sw.co.uk/iangblo...9/xorartifacts

Hope that helps.

Nov 16 '05 #4
Flicker occurs when the contents of the screen alternate rapidly between two
or more different sets of contents.

This occurs naturally when you redraw stuff on the screen if you're drawing
anything more than a single primitive. For example, if you draw a grey
background, and then you draw a black ellipse on top of that, there will be
a point in time where you've drawn the grey bit but not the black bit.
Sometimes what you see on screen will therefore just be the grey background,
and sometimes it will be the black ellipse on top of the grey background.

So if you repeatedly update the screen, it'll alternate rapidly between grey
and black, and this is what causes flicker. (Invalidating a screen area
causes it to be redrawn from scratch.)

There are two ways around this:

(1) Draw everything so fast that you don't get to see the intermediate
state.

(2) Do all your drawing off-screen into a bitmap, and then copy that onto
the screen when you're done.

Both of these work by making sure that the screen never contains
partially-drawn results. (1) is pretty hard to achieve on Windows, mainly
because it's very hard to know how long you've got before your results will
next be refreshed to the monitor. So (2) is the usual approach.

Windows Forms has built-in support for (2). Just set the DoubleBuffer and
AllPaintingInWmPaint styles on your control, and it arranges for all
repainting to go via an off-screen bitmap, eliminating flicker.
--
Ian Griffiths - http://www.interact-sw.co.uk/iangblog/
DevelopMentor - http://www.develop.com/

"Peder Y" wrote:
Hi Ian and thanks for nice pointers!
I have read all your articles and find them very useful. However, I must
admit I approached this another way at first. My original attempt was to
move the graphics primitives themselves and invalidate the area(s) in
question. Now, try painting a 1024x768 image at the bottommost z-order on
a panel, then move the primitives that are placed on top. Maybe I was
going about this the wrong way, but I get a lot of flicker. I'd love to
solve this with transparent objects, but GDI+ seems to produce flicker no
matter. I totally agree with your xor standpoints, but resolved to it as a
last (-intermediate:) solution. Surely someone must have written an
article on this somtime?

Nov 16 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Tim Bücker | last post by:
Hello. I want to paint some geometric shapes on the graphic context from a picture box. This picture box has dock style set to fill and is filling out the whole form. The form is maximized. This...
3
by: tony lock | last post by:
In VB 6 your could set the drawmode property to 7 (XorPen), which meant if you drew a line twice it disappeared, is there a way of getting an equivalent effect in VB.Net
1
by: anniejacob | last post by:
Hi, I got Form F1 which consists of one label and on click of this label it creates a new form F2 with three dynamically created buttons(the number of button to be created is passed from the label...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.