home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!charon.amdahl.com!pacbell.com!sgiblab!spool.mu.edu!umn.edu!csus.edu!netcom.com!netcomsv!terapin!paulk
- From: paulk@terapin.com (Paul Kienitz)
- Newsgroups: comp.sys.amiga.programmer
- Subject: GRIPE! about refreshing string gadgets
- Message-ID: <paulk.28zg@terapin.com>
- Date: 17 Nov 92 23:29:11 PST
- Organization: BBS
- Lines: 64
-
- This is a gripe about the refreshing of string gadgets.
-
- In my current project, I have lots of string gadgets, and sometimes
- they need to be enabled and disabled in response to other input, and
- sometimes they need to have their text contents altered, and sometimes
- both at once. I've noticed that all versions of Intuition do a LOUSY
- JOB of refreshing string gadgets in different states, when the string
- is shorter than the gadget and I'm also using the 2.x feature of
- having different colors for active and inactive string gadgets.
- Furthermore, different versions mess up in different ways.
-
- In the effort to create a function which would correctly refresh a
- string gadget after changing its text and possibly its enabled state,
- here's what I ended up needing to do:
-
- - Pad the current string in the gadget with spaces so as to
- completely fill the visible space with text. Under 2.x, pad it
- so the terminating nul char falls just after the end of the
- visible space, under 1.x pad it so the nul is just inside the end
- or else it will refresh one character space OUTSIDE the
- boundaries of the gadget.
-
- - RefreshGList the gadget
-
- - Restore the original length of the string in the buffer
-
- - Unless the gadget is currently disabled (maybe this should be done
- anyway, come to think of it), RefreshGList the gadget a second
- time with the window rastport's write mask temporarily set to
- zero. This lets Intuition know the current string length,
- without doing any actual rendering.
-
- Here is a sketch of my refreshing function ... this one assumes that
- the font is always of 8 pixel width, and assumes that the gadget is
- currently in the window's gadget list ... of course, in my actual
- program this is more complicated:
-
-
- extern struct Library *SysBase;
-
- void PaintStringGad(struct Gadget *gg, struct Window *ww)
- {
- struct StringInfo *si = (APTR) gg->SpecialInfo;
- short wid = (gg->Width >> 3) + (SysBase->lib_Version >= 36);
- short l = strlen(si->Buffer), i;
-
- si->DispPos = 0;
- si->BufferPos = 0;
- for (i = l; i < wid; i++)
- si->Buffer[i] = ' ';
- if (wid >= l)
- si->Buffer[wid] = 0;
- RefreshGList(gg, ww, NULL, 1);
- si->Buffer[l] = 0;
- if (!(gg->Flags & GFLG_DISABLED)) {
- SetWrMsk(ww->RPort, 0);
- RefreshGList(gg, ww, NULL, 1);
- SetWrMsk(ww->RPort, 0xFF);
- }
- if (gg->Flags & GFLG_DISABLED) /* this part is optional */
- si->BufferPos = 0;
- else
- si->BufferPos = l;
- }
-