home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / sys / amiga / programm / 16009 < prev    next >
Encoding:
Text File  |  1992-11-17  |  2.8 KB  |  74 lines

  1. Path: sparky!uunet!charon.amdahl.com!pacbell.com!sgiblab!spool.mu.edu!umn.edu!csus.edu!netcom.com!netcomsv!terapin!paulk
  2. From: paulk@terapin.com (Paul Kienitz)
  3. Newsgroups: comp.sys.amiga.programmer
  4. Subject: GRIPE! about refreshing string gadgets
  5. Message-ID: <paulk.28zg@terapin.com>
  6. Date: 17 Nov 92 23:29:11 PST
  7. Organization: BBS
  8. Lines: 64
  9.  
  10. This is a gripe about the refreshing of string gadgets.
  11.  
  12. In my current project, I have lots of string gadgets, and sometimes
  13. they need to be enabled and disabled in response to other input, and
  14. sometimes they need to have their text contents altered, and sometimes
  15. both at once.  I've noticed that all versions of Intuition do a LOUSY
  16. JOB of refreshing string gadgets in different states, when the string
  17. is shorter than the gadget and I'm also using the 2.x feature of
  18. having different colors for active and inactive string gadgets.
  19. Furthermore, different versions mess up in different ways.
  20.  
  21. In the effort to create a function which would correctly refresh a
  22. string gadget after changing its text and possibly its enabled state,
  23. here's what I ended up needing to do:
  24.  
  25.  - Pad the current string in the gadget with spaces so as to
  26.     completely fill the visible space with text.  Under 2.x, pad it
  27.     so the terminating nul char falls just after the end of the
  28.     visible space, under 1.x pad it so the nul is just inside the end
  29.     or else it will refresh one character space OUTSIDE the
  30.     boundaries of the gadget.
  31.  
  32.  - RefreshGList the gadget
  33.  
  34.  - Restore the original length of the string in the buffer
  35.  
  36.  - Unless the gadget is currently disabled (maybe this should be done
  37.     anyway, come to think of it), RefreshGList the gadget a second
  38.     time with the window rastport's write mask temporarily set to
  39.     zero.  This lets Intuition know the current string length,
  40.     without doing any actual rendering.
  41.  
  42. Here is a sketch of my refreshing function ... this one assumes that
  43. the font is always of 8 pixel width, and assumes that the gadget is
  44. currently in the window's gadget list ... of course, in my actual
  45. program this is more complicated:
  46.  
  47.  
  48. extern struct Library *SysBase;
  49.  
  50. void PaintStringGad(struct Gadget *gg, struct Window *ww)
  51. {
  52.     struct StringInfo *si = (APTR) gg->SpecialInfo;
  53.     short wid = (gg->Width >> 3) + (SysBase->lib_Version >= 36);
  54.     short l = strlen(si->Buffer), i;
  55.  
  56.     si->DispPos = 0;
  57.     si->BufferPos = 0;
  58.     for (i = l; i < wid; i++)
  59.         si->Buffer[i] = ' ';
  60.     if (wid >= l)
  61.         si->Buffer[wid] = 0;
  62.     RefreshGList(gg, ww, NULL, 1);
  63.     si->Buffer[l] = 0;
  64.     if (!(gg->Flags & GFLG_DISABLED)) {
  65.         SetWrMsk(ww->RPort, 0);
  66.         RefreshGList(gg, ww, NULL, 1);
  67.         SetWrMsk(ww->RPort, 0xFF);
  68.     }
  69.     if (gg->Flags & GFLG_DISABLED)      /* this part is optional */
  70.         si->BufferPos = 0;
  71.     else
  72.         si->BufferPos = l;
  73. }
  74.