Solved

RectInRgn()

Posted on 2000-03-07
6
201 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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

830 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