3 /* Copyright (C) 2002 Brad Jorsch <anomie@users.sourceforge.net>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 #include "wmgeneral/wmgeneral-x11.h"
26 #include "wmgeneral/xpm_trans.h"
28 #include "wmweather+.h"
29 #include "animation.h"
33 #define P 4 /* Percent to increment by */
34 #define X 4 /* Frames to wait before incrementing */
35 #define M (((100/P)+1)*X)
37 static int heights
[5]={ 11, 12, 14, 14, 19 };
39 void SetAnimation(struct animation
*a
, int x
, int y
, int sky
, int obs
, int vis
,
40 int frz
, int snow
, int rain
, int tstorm
, int svtstorm
,
48 if(sky
>=0 && sky
<6) a
->sky
=sky
*27;
50 if(vis
<7 && obs
>0 && vis
>0 && obs
<4){
52 a
->vis
=256-236*(vis
-1)/6;
61 if(a
->items
[i
]==0) continue;
62 if(a
->items
[i
]%P
) a
->items
[i
]=a
->items
[i
]/P
+1;
63 else a
->items
[i
]=a
->items
[i
]/P
;
65 if(a
->items
[i
]!=0) a
->changed
=1;
71 void DoAnimation(struct animation
*a
){
76 if(!a
->active
) return;
78 /* Any parameters changed? If yes, draw */
79 if(a
->changed
) goto doit
;
81 /* Nothing changed, quit if not animating */
82 if(!a
->do_animate
) return;
84 /* We are animating. If it's the first frame of a cycle, draw it */
85 a
->ac
++; if(a
->ac
>=M
){ a
->ac
=0; goto doit
; }
87 /* Not the first frame, see if anything changed. If so, draw it */
89 if(a
->ac
>=a
->items
[i
] && a
->ac
<=a
->items
[i
]+X
) goto doit
;
92 /* Just draw the counter... */
93 if(a
->show_counter
) goto do_counter
;
95 /* Nothing to draw, quit */
99 if(a
->min_pct
!=a
->old_pct
){
100 if(a
->min_pct
%P
) a
->pct
=(a
->min_pct
/P
+1)*X
;
101 else a
->pct
=(a
->min_pct
/P
)*X
;
102 a
->old_pct
=a
->min_pct
;
106 if(!a
->do_animate
) a
->ac
=a
->pct
;
107 copyPixmapArea(124, 18, 26, 31, a
->x
, a
->y
);
109 copySunMoon(a
->x
, a
->y
, a
->moon
);
110 combineWithTrans(a
->sky
, 64, 26, 25, a
->x
, a
->y
);
112 if(a
->vis
>0) combineWithOpacity(a
->obs
, 89, 26, 25, a
->x
, a
->y
, a
->vis
);
114 if(a
->items
[i
]==0 || a
->ac
>=a
->items
[i
]+X
) continue;
119 } else if(a
->ac
>=a
->items
[i
] && a
->ac
<a
->items
[i
]+X
){
123 combineWithTrans(i
*27, 129-top
, 26, h
, a
->x
, a
->y
+31-top
);
125 if(a
->show_counter
){{
129 snprintf(foo
, 5, "%d%%", a
->min_pct
);
131 for(i
=0; i
<100 && a
->ac
>((i
+P
-1)/P
)*X
; i
++);
132 snprintf(foo
, 5, "%d%%", i
);
134 i
=GetStringWidth(foo
);
135 copyPixmapArea(124, 18, i
+2, 7, a
->x
+(26-i
-2)/2, a
->y
+12);
136 DrawString(a
->x
+(26-i
)/2, a
->y
+13, foo
, 2);