 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Tanju ÖZGÜR Guest
|
Posted: Tue Apr 11, 2006 8:03 am Post subject: Sub-classing vs direct message handling in CAD program |
|
|
Hi,
Which one is the best way to handle messages in CAD-like programs,
especially when facing with heavy work-load (such as: real-time pan
function). In fact, either techniques performs the same operation, trapping
the messages and monitors them, but it seems that sub-classing is more
efficient way because I have tested the 2 programs, first one was using
sub-classing and second one was using message handling (implementing
wm_paint, wm_mousedown etc.message handling routines), the first was
absolutely faster when it comes to the real-time panning, so it made me
think that sub-classing is most efficient way,
Am I wrong ? |
|
| Back to top |
|
 |
Nils Haeck Guest
|
Posted: Wed Apr 12, 2006 9:03 am Post subject: Re: Sub-classing vs direct message handling in CAD program |
|
|
Hi Tanju,
I cannot make cake from your description. What exactly do you mean by
"subclassing", and where exactly do you want to handle wm_paint, etc? It
would be good if you could provide some pseudo-code to illustrate your
question.
Nils
"Tanju ÖZGÜR" <tanjuozgur (AT) yahoo (DOT) com> schreef in bericht
news:443b6098 (AT) newsgroups (DOT) borland.com...
| Quote: | Hi,
Which one is the best way to handle messages in CAD-like programs,
especially when facing with heavy work-load (such as: real-time pan
function). In fact, either techniques performs the same operation,
trapping the messages and monitors them, but it seems that sub-classing is
more efficient way because I have tested the 2 programs, first one was
using sub-classing and second one was using message handling (implementing
wm_paint, wm_mousedown etc.message handling routines), the first was
absolutely faster when it comes to the real-time panning, so it made me
think that sub-classing is most efficient way,
Am I wrong ?
|
|
|
| Back to top |
|
 |
Tanju ÖZGÜR Guest
|
Posted: Wed Apr 12, 2006 11:03 am Post subject: Re: Sub-classing vs direct message handling in CAD program |
|
|
subclassing = Setting the original WinProc of an application to your-defined
procedure via "SetWindowLong" API, thus you can
monitor all the message traffic of your app.
but as you know there is the other way to do it, you can directly trap the
messages without bothering yourself to change WinProc ( such as :
procedure WMPaint ; message wm_paint; and you can implement it what ever way
you like )
Having two different app, each working with different technique, 1st with
sub-classing, 2nd with direct message handling, made me think that
sub-classing mechanism is much better than direct message handling.
"Nils Haeck" <bla (AT) bla (DOT) com>, haber iletisinde şunları
yazdı:443cb751$1 (AT) newsgroups (DOT) borland.com...
| Quote: | Hi Tanju,
I cannot make cake from your description. What exactly do you mean by
"subclassing", and where exactly do you want to handle wm_paint, etc? It
would be good if you could provide some pseudo-code to illustrate your
question.
Nils
"Tanju ÖZGÜR" <tanjuozgur (AT) yahoo (DOT) com> schreef in bericht
news:443b6098 (AT) newsgroups (DOT) borland.com...
Hi,
Which one is the best way to handle messages in CAD-like programs,
especially when facing with heavy work-load (such as: real-time pan
function). In fact, either techniques performs the same operation,
trapping the messages and monitors them, but it seems that sub-classing
is more efficient way because I have tested the 2 programs, first one was
using sub-classing and second one was using message handling
(implementing wm_paint, wm_mousedown etc.message handling routines), the
first was absolutely faster when it comes to the real-time panning, so it
made me think that sub-classing is most efficient way,
Am I wrong ?
|
|
|
| Back to top |
|
 |
Roger Lascelles Guest
|
Posted: Fri Apr 14, 2006 2:03 am Post subject: Re: Sub-classing vs direct message handling in CAD program |
|
|
"Tanju ÖZGÜR" <tanjuozgur (AT) yahoo (DOT) com> wrote in message
news:443b6098 (AT) newsgroups (DOT) borland.com...
| Quote: | wm_paint, wm_mousedown etc.message handling routines), the first was
absolutely faster when it comes to the real-time panning, so it made me
think that sub-classing is most efficient way,
|
I suggest the difference you noticed between the two programs is nothing to
do with the message handling, but rather due to the code used to pan the
screen. Fast panning requires a shift of all pixels, then a drawing of the
new strip exposed on screen. Good real time panning code takes work.
The speed of message handling is negligible. In my CAD program I use
ordinary mouse and keyboard messages as filtered through the Delphi classes
and my program feels snappy on a 100 MHz Pentium. It is my own code which
consumes most of the time, in responding to the messages. That is why CAD
programs are often heavily optimised so that on-screen objects under the
mouse can be located quickly and a minimal amount of redrawing is done.
I would use the kind of message handling which best fits your needs and
program design, because speed not a factor.
Roger Lascelles |
|
| Back to top |
|
 |
Tanju ÖZGÜR Guest
|
Posted: Fri Apr 14, 2006 8:03 am Post subject: Re: Sub-classing vs direct message handling in CAD program |
|
|
Thnx for clarifications Rogers,
| Quote: | I suggest the difference you noticed between the two programs is nothing
to
do with the message handling, but rather due to the code used to pan the
|
so now I know that to get best panning has nothing to do with message
handling mechanism. Ok.
| Quote: | screen. Fast panning requires a shift of all pixels, then a drawing of
the
new strip exposed on screen. Good real time panning code takes work
|
what is the better way other than using "BitBlt" API when it comes to the
shifting the all pixels, I have added the code (see below ) which is
embedded at "Paint" procedure of object which is descendant of
TCustomControl.
When the end user press the LeftMouse button program sets the "panning"
variable to true, and in MouseMove continuously calls
"ViewportObject.Refresh", then when MouseUp happens Panning is set to False,
this is how my Pan Code is implemented.
Can you tell me whether the code is efficacious or not?
var
R, CR :TRect ;
// CR :ClientRectangle;
Panning :Boolean;
if (FEditState = scesPan) and Panning then
begin
DX := Round(Self.FMoveRec.Test.x-Self.FHitRec.Test.x);
DY := Round(Self.FMoveRec.Test.y-Self.FHitRec.Test.y);
OffSetRect(R,-Round(Dx),-Round(Dy));
BitBlt(Canvas.Handle, CR.Left, CR.Top, W, H,
FPaintBuffer.Canvas.Handle,
R.Left - CR.Left, Round(R.Top) - CR.Top, SRCCOPY);
end
else
BitBlt(Canvas.Handle, R.Left, R.Top, W, H,
FPaintBuffer.Canvas.Handle,
R.Left - CR.Left, R.Top - CR.Top, SRCCOPY);
"Roger Lascelles" <rogerlasAToptusnet.com.au>, haber iletisinde şunları
yazdı:443f00cb (AT) newsgroups (DOT) borland.com...
| Quote: | "Tanju ÖZGÜR" <tanjuozgur (AT) yahoo (DOT) com> wrote in message
news:443b6098 (AT) newsgroups (DOT) borland.com...
wm_paint, wm_mousedown etc.message handling routines), the first was
absolutely faster when it comes to the real-time panning, so it made me
think that sub-classing is most efficient way,
I suggest the difference you noticed between the two programs is nothing
to
do with the message handling, but rather due to the code used to pan the
screen. Fast panning requires a shift of all pixels, then a drawing of
the
new strip exposed on screen. Good real time panning code takes work.
The speed of message handling is negligible. In my CAD program I use
ordinary mouse and keyboard messages as filtered through the Delphi
classes
and my program feels snappy on a 100 MHz Pentium. It is my own code which
consumes most of the time, in responding to the messages. That is why CAD
programs are often heavily optimised so that on-screen objects under the
mouse can be located quickly and a minimal amount of redrawing is done.
I would use the kind of message handling which best fits your needs and
program design, because speed not a factor.
Roger Lascelles
|
|
|
| Back to top |
|
 |
Nils Haeck Guest
|
Posted: Sat Apr 15, 2006 11:03 am Post subject: Re: Sub-classing vs direct message handling in CAD program |
|
|
Basically, Windows already handles a large part of "repainting" the screen.
Whenever you scroll your window, Windows will not ask your application to
repaint the whole window, just a small strip that appears due to the
scrolling, the rest of the window is simply copied (and you dont have to
worry about it).
You can then use the ClipRect to determine which part to paint. A good CAD
program then only repaints the objects in this part, and has fast methods to
determine which objects are visible within the ClipRect.
If you use windows GDI to draw your objects (lines, text, etc) you will have
a very fast solution, however GDI doesn't support good antialiasing of
lines, or special line drawing routines. You could have a look at Graphics32
(esp Polygon32) to allow for very high-quality line drawing, at the cost of
extra CPU cycles. I have profiled some of my applications and found that
usually the rasterizing (converting polygons to anti-aliased pixels) is
responsible for at least 90% of the CPU consumption. This by far outweighs
some of the other operations (transformations, bounding box determinations,
hittesting, bit block transfers, etc).
I have seen some very "snappy" CAD visualisation tools that use a mechanism
where during panning/zooming they redraw using GDI, and then after the user
stopped pan/zoom, redraw the screen using high-quality, antialiased line
drawing (perhaps GDI+ or their own solution).
Hope that helps, Nils |
|
| Back to top |
|
 |
Roger Lascelles Guest
|
Posted: Sun Apr 16, 2006 5:03 am Post subject: Re: Sub-classing vs direct message handling in CAD program |
|
|
"Tanju ÖZGÜR" <tanjuozgur (AT) yahoo (DOT) com> wrote in message
news:443f4963 (AT) newsgroups (DOT) borland.com...
| Quote: | When the end user press the LeftMouse button program sets the "panning"
variable to true, and in MouseMove continuously calls
"ViewportObject.Refresh", then when MouseUp happens Panning is set to
False,
this is how my Pan Code is implemented.
Can you tell me whether the code is efficacious or not?
var
R, CR :TRect ;
// CR :ClientRectangle;
Panning :Boolean;
if (FEditState = scesPan) and Panning then
begin
DX := Round(Self.FMoveRec.Test.x-Self.FHitRec.Test.x);
DY := Round(Self.FMoveRec.Test.y-Self.FHitRec.Test.y);
OffSetRect(R,-Round(Dx),-Round(Dy));
BitBlt(Canvas.Handle, CR.Left, CR.Top, W, H,
FPaintBuffer.Canvas.Handle,
R.Left - CR.Left, Round(R.Top) - CR.Top, SRCCOPY);
end
|
Tanju
I think you are panning by doing a BitBlt of your offscreen image to your
screen canvast, using an offset. This would require a complete Blit of a
large image, and it seems this is not fast enough.
In Windows.pas, you will find an API function which does scrolling very
fast, probably by the graphics hardware :
function ScrollWindowEx(hWnd: HWND; dx, dy: Integer;
prcScroll, prcClip: PRect;
hrgnUpdate: HRGN; prcUpdate: PRect; flags: UINT): BOOL; stdcall;
hWnd is Form.Handle
dx, dy is similar to your DX, DY
prcScroll is the rectangle you want to shift on the screen
prcClip is same as prcScroll, for this job, I think?
hrgnUpdate = nil
prcUpdate = nil
flags = 0
After this function, you have to BitBlt the "missing" piece of image from
your offscreen bitmap, but this might only be 10% of the total picture, in
effect giving you a 10 times scroll speed improvement. If you watch
scrolling on many programs, you can actually see the strip getting drawn.
There is also ScrollDC API function, which does a similar job and takes as
its DC parameter the Canvas.Handle.
Roger Lascelles |
|
| Back to top |
|
 |
Tanju ÖZGÜR Guest
|
Posted: Mon Apr 17, 2006 6:03 am Post subject: Re: Sub-classing vs direct message handling in CAD program |
|
|
Thank you both for helping me,
Althought Roger's technique is reasonable it seems hard to implement, but
make sure that I'll give it a try.
Best Regards,
"Roger Lascelles" <rogerlasAToptusnet.com.au>, haber iletisinde şunları
yazdı:4441c25f$1 (AT) newsgroups (DOT) borland.com...
| Quote: | "Tanju ÖZGÜR" <tanjuozgur (AT) yahoo (DOT) com> wrote in message
news:443f4963 (AT) newsgroups (DOT) borland.com...
When the end user press the LeftMouse button program sets the "panning"
variable to true, and in MouseMove continuously calls
"ViewportObject.Refresh", then when MouseUp happens Panning is set to
False,
this is how my Pan Code is implemented.
Can you tell me whether the code is efficacious or not?
var
R, CR :TRect ;
// CR :ClientRectangle;
Panning :Boolean;
if (FEditState = scesPan) and Panning then
begin
DX := Round(Self.FMoveRec.Test.x-Self.FHitRec.Test.x);
DY := Round(Self.FMoveRec.Test.y-Self.FHitRec.Test.y);
OffSetRect(R,-Round(Dx),-Round(Dy));
BitBlt(Canvas.Handle, CR.Left, CR.Top, W, H,
FPaintBuffer.Canvas.Handle,
R.Left - CR.Left, Round(R.Top) - CR.Top, SRCCOPY);
end
Tanju
I think you are panning by doing a BitBlt of your offscreen image to your
screen canvast, using an offset. This would require a complete Blit of a
large image, and it seems this is not fast enough.
In Windows.pas, you will find an API function which does scrolling very
fast, probably by the graphics hardware :
function ScrollWindowEx(hWnd: HWND; dx, dy: Integer;
prcScroll, prcClip: PRect;
hrgnUpdate: HRGN; prcUpdate: PRect; flags: UINT): BOOL; stdcall;
hWnd is Form.Handle
dx, dy is similar to your DX, DY
prcScroll is the rectangle you want to shift on the screen
prcClip is same as prcScroll, for this job, I think?
hrgnUpdate = nil
prcUpdate = nil
flags = 0
After this function, you have to BitBlt the "missing" piece of image from
your offscreen bitmap, but this might only be 10% of the total picture, in
effect giving you a 10 times scroll speed improvement. If you watch
scrolling on many programs, you can actually see the strip getting drawn.
There is also ScrollDC API function, which does a similar job and takes as
its DC parameter the Canvas.Handle.
Roger Lascelles
|
|
|
| Back to top |
|
 |
Nils Haeck Guest
|
Posted: Tue Apr 18, 2006 7:03 am Post subject: Re: Sub-classing vs direct message handling in CAD program |
|
|
ScrollWindowEx is what I meant too. I have created a component called
VirtualScrollbox using this technique. More info here:
http://www.simdesign.nl/virtualscrollbox.html
Kind regards,
Nils
"Tanju ÖZGÜR" <tanjuozgur (AT) yahoo (DOT) com> schreef in bericht
news:4443291c (AT) newsgroups (DOT) borland.com...
| Quote: | Thank you both for helping me,
Althought Roger's technique is reasonable it seems hard to implement, but
make sure that I'll give it a try.
Best Regards,
|
|
|
| Back to top |
|
 |
Tanju ÖZGÜR Guest
|
Posted: Tue Apr 18, 2006 10:03 am Post subject: Re: Sub-classing vs direct message handling in CAD program |
|
|
Do you really think that ScrollWindowEx function can serve as real-time
panning ? I've been struggling for 2 days and end up with nothing.
"Nils Haeck" <bla (AT) bla (DOT) com>, haber iletisinde şunları
yazdı:4444834c (AT) newsgroups (DOT) borland.com...
| Quote: | ScrollWindowEx is what I meant too. I have created a component called
VirtualScrollbox using this technique. More info here:
http://www.simdesign.nl/virtualscrollbox.html
Kind regards,
Nils
"Tanju ÖZGÜR" <tanjuozgur (AT) yahoo (DOT) com> schreef in bericht
news:4443291c (AT) newsgroups (DOT) borland.com...
Thank you both for helping me,
Althought Roger's technique is reasonable it seems hard to implement, but
make sure that I'll give it a try.
Best Regards,
|
|
|
| Back to top |
|
 |
Roger Lascelles Guest
|
Posted: Tue Apr 18, 2006 1:06 pm Post subject: Re: Sub-classing vs direct message handling in CAD program |
|
|
"Tanju ÖZGÜR" <tanjuozgur (AT) yahoo (DOT) com> wrote in message
news:4444b1a8 (AT) newsgroups (DOT) borland.com...
| Quote: | Do you really think that ScrollWindowEx function can serve as real-time
panning ? I've been struggling for 2 days and end up with nothing.
|
Step one is to get ScrollWindowEx to move your image. Put a button on a
form and in the OnClick handler just call ScrollWindowEx and move the image
say 100 pixels to the right. When it is working, you will see it on screen.
Once it is working, you can connect it to your scrollbar messages.
Finally, add the BitBlt code to copy the missing pieces to screen.
Even if Nils component does not suit your needs, his sourcecode will help
you.
ScrollWindowEx lies behind almost all the fast scrolling you see on Windows.
Everything from word processors to graphics programs. It is the API tool
you need.
The Delphi VCL source file might help - search for ScrollWindow in
controls.pas, grids.pas, dbgrids.pas - where you can see ScrollWindow and
ScrollWindowEx are scrolling your forms, grids etc.
If your graphics display is a descendant of TWinControl or
TScrollingWinControl, you get a lot of the work done for you.
If you really get stuck, build a test app with a single form so you can post
the sourcecode.
Roger Lascelles |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|