4 * Scrolling text in an icon
6 * © 1994-1998 Straylight
9 /*----- Licensing note ----------------------------------------------------*
11 * This file is part of Straylight's Steel library.
13 * Steel is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2, or (at your option)
18 * Steel is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with Steel. If not, write to the Free Software Foundation,
25 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
39 typedef struct scroller__str
41 wimp_w w; /* Window handle of scroller */
42 wimp_i i; /* icon Handle */
43 char *string; /* Scrolling Message */
44 char *initText; /* Start Message */
45 int index; /* Index into actual string */
46 int chars; /* Printable string index */
47 int initIndent; /* X indent for initial message */
48 int speed; /* Speed of scroll */
49 int cspeed; /* Current speed of scroll */
50 int counter; /* Current value of delay */
51 wimp_box box; /* Icon bounding box */
52 int baseline; /* Y Position of message */
53 int len; /* Length of printable string */
54 int cfg; /* Current foreground colour */
55 int fg :4; /* Defualt foreground colour */
56 int bg :4; /* Defualt background colour */
57 int pixel :8; /* Current pixel offset */
58 BOOL started :1; /* Have we wrapped around? */
62 #define max2(x,y) ((x)>(y) ? (x) : (y))
63 #define min2(x,y) ((x)<(y) ? (x) : (y))
65 /* Display the entire string - used for redraw events */
67 static void scroller__display(scroller s,char *p)
77 sscanf(p+1,"%i",&col);
81 wimp_setcolour(s->fg);
91 /* Calculate the length of the string, without control codes */
93 static int scroller__length(char *p)
108 /* Redraw the icon */
110 void scroller_redraw(scroller s,wimp_redrawstr *r)
113 int dx=wimpt_dx(),dy=wimpt_dy();
117 /* Does icon bounding box intersect with graphics window */
119 if ( !( ox+s->box.x0 <= r->g.x1-dx &&
120 oy+s->box.y0 <= r->g.y1-dy &&
121 ox+s->box.x1-dx >= r->g.x0 &&
122 oy+s->box.y1-dy >= r->g.y0))
125 /* Yes -- Set graphics window to insection */
127 bbc_gwindow(max2(ox+s->box.x0,r->g.x0),
128 max2(oy+s->box.y0,r->g.y0),
129 min2(ox+s->box.x1,r->g.x1)-dx,
130 min2(oy+s->box.y1,r->g.y1)-dy);
132 wimp_setcolour(s->bg | 0x80);
134 wimp_setcolour(s->fg);
138 bbc_move(ox+s->box.x1-16*(s->chars+s->len)-s->pixel,oy+s->baseline);
139 scroller__display(s,s->string);
143 bbc_move(ox+s->box.x1-16*s->chars-s->pixel-s->initIndent,oy+s->baseline);
144 bbc_stringprint(s->initText);
146 bbc_move(ox+s->box.x1-16*s->chars-s->pixel,oy+s->baseline);
147 scroller__display(s,s->string);
155 /* Called on idle events to do the scroll */
157 static void scroller__idles(void *handle)
174 if (!s->string[s->index])
180 if (s->string[s->index]=='[')
182 switch (s->string[++s->index])
185 sscanf(s->string+s->index+1,"%i",&s->counter);
186 while (s->string[s->index++]!=']') ;
190 sscanf(s->string+s->index+1,"%i",&s->cfg);
191 while (s->string[s->index++]!=']') ;
194 while (s->string[s->index++]!=']') ;
199 sscanf(s->string+s->index+1,"%i",&s->cspeed);
200 while (s->string[s->index++]!=']') ;
207 while (s->string[s->index++]!=']') ;
214 wimp_blockcopy(s->w,&r.box,s->box.x0,s->box.y0);
215 r.box.x0=r.box.x1-s->cspeed;
217 wimp_update_wind(&r,&more);
218 ox=r.box.x0-r.scx + s->box.x1-s->pixel;
219 oy=r.box.y1-r.scy + s->baseline;
222 wimp_setcolour(s->bg);
223 bbc_rectanglefill(ox,oy-28,16,28);
224 wimp_setcolour(s->cfg);
226 bbc_vdu(s->string[s->index]);
227 wimp_get_rectangle(&r,&more);
231 /* Create a new sroller */
233 scroller scroller_create(dbox d,
239 scroller s=mem_alloc(sizeof(scroller__str));
243 werr(FALSE,msgs_lookup("scrlNEM:Not enough memory for scrolltext"));
246 s->w=dbox_syshandle(d);
249 s->index=s->chars=-1;
251 s->counter=startDelay;
252 s->speed=s->cspeed=2;
254 wimpt_noerr(wimp_get_icon_info(s->w,f,&i));
256 s->len=scroller__length(string);
258 s->initIndent=((i.box.x1-i.box.x0)/2+(strlen(s->initText)*8));
259 s->fg=s->cfg=(i.flags >> 24) & 0x0f;
260 s->bg=(i.flags >> 28) & 0x0f;
261 s->baseline=s->box.y1-(s->box.y1-s->box.y0-32)/2-4;
265 void scroller_speed(scroller s,int speed)
267 s->speed=s->cspeed=speed;
270 void scroller_go(scroller s)
272 win_addIdleClaimer(scroller__idles,2,s);
275 void scroller_destroy(scroller s)
277 win_removeIdleClaimer(scroller__idles,s);