Solved

RectInRgn()

Posted on 2000-03-07
6
195 Views
Last Modified: 2013-12-26
I am trying to prevent a Rect in a window from being redrawn if
not necessary. I tried the following code but it does not work
any suggestions. I tried putting the Draw_The_Window() within
Begin & End update and it didn't make a difference.

BTW: The code works fine when I don't check for the
RectInRgn().


case updateEvt:
BeginUpdate((DialogPtr)gMainEventRecord.message);                        
EndUpdate((DialogPtr)gMainEventRecord.message);
Draw_The_Window((DialogPtr)gMainEventRecord.message);
break;


void Draw_The_Window (DialogPtr theDialog)
{
DialogPeek            theDialogPeek;
Rect                  iconRect = {20, 32, 52, 64};

theDialogPeek - (DialogPeek)theDialog;
      
if( RectInRgn( &iconRect, theDialogPeek->window.updateRgn) )
      Display_Icon( theDialog );

}
0
Comment
Question by:gail_p
  • 4
  • 2
6 Comments
 
LVL 4

Expert Comment

by:Alex Curylo
ID: 2610963
BeginUpdate() immediately clears the update region, so that RectInRgn call will always return false. If you check against clipRgn instead this ought to work.

That's if you don't call EndUpdate() before calling your draw routine, because EndUpdate() sets the clipping region back to whatever it was before BeginUpdate() set it to the pending update region.

So move EndUpdate after the Draw_The_Window call, and check the clipping region instead of the update region, and you ought to be good to go.
0
 

Author Comment

by:gail_p
ID: 2615499
If I move Draw_The_Window() routine between the Begin and End Update the the PlotIconSuite() call in the Draw_The_Window() gets drawn over. That is why I put the Draw_The_Window() after the EndUpdate().
0
 
LVL 4

Accepted Solution

by:
Alex Curylo earned 50 total points
ID: 2616775
Check out the diagram at

http://developer.apple.com/techpubs/mac/Toolbox/Toolbox-207.html#MARKER-9-210

which shows how BeginUpdate() and EndUpdate() affect the clipping region of the window. If it's not working the way you expect, then something must be invalidating your window incorrectly.

A useful technique would be to put a call to FillRgn() on the update region in pink or something like that just before the BeginUpdate call; then you can see exactly what part of the window will be drawn over by calls within Begin/EndUpdate. If it's not what you expect, then something is wrong with your invalidation code and it ought to be fixed where the problem is instead of working around it at update time.
0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 4

Expert Comment

by:Alex Curylo
ID: 2616792
And if you draw anywhere _other_ than between Begin/End update calls, don't forget to make sure to call ValidRect/ValidRgn as appropriate, otherwise yes of course it'll flicker because the Window Manager has no way to know what part of the window you don't want redrawn now.

But it's better to never draw except at update time to avoid all these kinds of problems.
0
 

Author Comment

by:gail_p
ID: 2617874
Great, thanks for the help. Any suggestions for my Balloon Help question?
0
 
LVL 4

Expert Comment

by:Alex Curylo
ID: 2617999
You're welcome. I'll go look at it now.
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
paragon account problem 9 96
Unix / Linux grid computing 5 127
wordappend challenge 8 85
Detect file exist or not 3 81
Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now