wmpager: drop tooltip suport
[dockapps.git] / wmweather+ / animation.c
blob9a831e482d75fedb929766dfae91e916fa2fe39e
1 #include "config.h"
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 #include <stdio.h>
22 #include <X11/Xlib.h>
23 #include <X11/xpm.h>
25 #include "wmgeneral/wmgeneral-x11.h"
26 #include "wmgeneral/xpm_trans.h"
28 #include "wmweather+.h"
29 #include "animation.h"
30 #include "moon.h"
31 #include "font.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,
41 double moon){
42 int i;
44 a->changed=1;
45 a->active=1;
46 a->x=x;
47 a->y=y;
48 if(sky>=0 && sky<6) a->sky=sky*27;
49 else a->sky=-1;
50 if(vis<7 && obs>0 && vis>0 && obs<4){
51 a->obs=obs*27-27;
52 a->vis=256-236*(vis-1)/6;
53 } else a->vis=0;
55 a->items[0]=frz;
56 a->items[1]=snow;
57 a->items[2]=rain;
58 a->items[3]=tstorm;
59 a->items[4]=svtstorm;
60 for(i=0; i<5; i++){
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;
64 a->items[i]*=X;
65 if(a->items[i]!=0) a->changed=1;
67 a->ac=0;
68 a->moon=moon;
71 void DoAnimation(struct animation *a){
72 int i;
73 int top, h;
75 /* Turned off? */
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 */
88 for(i=0; i<5; i++){
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 */
96 return;
98 doit:
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;
104 a->changed=0;
106 if(!a->do_animate) a->ac=a->pct;
107 copyPixmapArea(124, 18, 26, 31, a->x, a->y);
108 if(a->sky!=-1){
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);
113 for(i=0; i<5; i++){
114 if(a->items[i]==0 || a->ac>=a->items[i]+X) continue;
115 h=heights[i];
116 top=h;
117 if(a->ac<X){
118 h=h*a->ac/X;
119 } else if(a->ac>=a->items[i] && a->ac<a->items[i]+X){
120 h-=h*(a->ac%X)/X;
121 top=h;
123 combineWithTrans(i*27, 129-top, 26, h, a->x, a->y+31-top);
125 if(a->show_counter){{
126 char foo[5];
127 do_counter:
128 if(!a->do_animate){
129 snprintf(foo, 5, "%d%%", a->min_pct);
130 } else {
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);