[comp.sys.mac.programmer] Window Updates

jtgorman@cs.arizona.edu (J. Taggart Gorman) (06/16/91)

  Okay, here's my next trauma.  And I think there are many more to come.  Here's
the plan :  The following routine is DrawMainWindow, which is called when the
main window receives an unpdate event.
  When my program runs, the first time this function is called, it draws the
string to the window just fine.  But.... When characterOpen is set to TRUE (by
the user opeing a character), the screen will not reflect the new changes.
  I _thought_ EraseRect() or PaintRect() would "wipe out" the window, but the
old string NO_NAME_STR still appears on the screen.  What is wrong?  Why won't
EraseRect() or PaintRect() clear the window?  Will Rocky and Bullwinkle escape?
  Arrrrggg!!!!!

DrawMainWindow()
{
  Rect      screenRect;
  int       xDisp;
  char      *cp, *cp1, *cp2;
  
  SetPort(mainWindow);

  screenRect = ((*mainWindow).portRect);
  
  MoveTo(0,0);
  
  TextMode(srcCopy);
  PenMode(patCopy);

  BackPat(white);  
  EraseRect(&screenRect);

  ForeColor(whiteColor);
  PaintRect(&screenRect);
  ForeColor(blackColor);

  TextFont(geneva);
  TextSize(12);
  TextFace(bold);

  if (characterOpen)
    cp = theCharacter.name;
  else
    cp = NO_NAME_STR;
  
  xDisp = CenterString(StringWidth(cp), BOTTOM_X-STATUS_LINE_X);
  if (xDisp >= 0) {
    MoveTo(STATUS_LINE_X+xDisp, NAME_STR_Y);
    DrawString(cp);
  }
  
  if (characterOpen) {
    switch (theCharacter.location) {
      case TOP :
             cp2 = TOP_STR;
             break;
      case STORE :
             cp2 = STORE_STR;
             break;
      case FIXER :
             cp2 = FIXER_STR;
             break;
      case ELSE :
             cp2 = "Some Where or Other";
             break;
    }
    if (theCharacter.location == ELSE)
      cp1 = ELSE_STR;
    else
      cp1 = NOT_ELSE_STR;
    cp1 = strcat(cp1, cp2);

    xDisp = CenterString(StringWidth(CtoPstr(cp1)), STATUS_LINE_X);
    if (xDisp >= 0) {
      MoveTo(xDisp, LOCATION_STR_Y);
      DrawString(cp1);
    }
  }
}  /* DrawMainWindow */

  I really appreciate all the help that this newsgroup has provided me over the
last 6 months.  Thanks for helping a fellow Mac user to try to achieve
enlightenment!

|      J. Taggart Gorman Jr.     | "I'm a no rust build up man myself."
|                                |          -Christian Slater
| jtgorman@caslon.cs.arizona.edu |             in 'Heathers'