2 * wmmisc - WindowMaker Dockapp for monitoring misc. information.
3 * Copyright (C) 2003-2006 Jesse S. (luxorfalls@sbcglobal.net)
5 * wmmisc 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 * wmmisc 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 wmmisc; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24 #include <libdockapp/wmgeneral.h>
25 #include "dockapp_draw.h"
26 #include "dockapp_utils.h"
28 static dockapp_proc_t dockapp_proc
;
31 dockapp_draw_big_digit( unsigned int digit_value
,
33 int digit_draw_location_x
,
34 int digit_draw_location_y
)
36 int digit_value_of_ten
= 1;
37 int digit_maximum_value_of_ten
= 0;
38 int digit_new_draw_location_x
= 0;
40 if ( ( ( DOCKAPP_WIDTH
- DOCKAPP_BIG_CHAR_WIDTH
) < digit_draw_location_x
41 || ( DOCKAPP_HEIGHT
- DOCKAPP_BIG_CHAR_HEIGHT
) < digit_draw_location_y
)
42 || ( 0 > digit_draw_location_x
|| 0 > digit_draw_location_y
) )
45 "%s: Invalid x,y position: %d,%d\n",
47 digit_draw_location_x
,
48 digit_draw_location_y
);
52 for ( digit_maximum_value_of_ten
= 0;
53 digit_maximum_value_of_ten
< digit_zero_count
;
54 ++digit_maximum_value_of_ten
)
56 digit_value_of_ten
*= 10;
59 digit_new_draw_location_x
= digit_draw_location_x
;
63 copyXPMArea( ( ( ( digit_value
/ digit_value_of_ten
) % 10 ) *
64 DOCKAPP_BIG_CHAR_WIDTH
+ DOCKAPP_BIG_DIGIT_X
),
66 DOCKAPP_BIG_CHAR_WIDTH
,
67 DOCKAPP_BIG_CHAR_HEIGHT
,
68 digit_new_draw_location_x
,
69 digit_draw_location_y
);
71 digit_value_of_ten
/= 10;
72 digit_new_draw_location_x
+= DOCKAPP_BIG_CHAR_WIDTH
;
73 } while ( 0 < digit_value_of_ten
);
79 dockapp_draw_small_digit( unsigned int d_value
,
81 int digit_draw_location_x
,
82 int digit_draw_location_y
)
84 int digit_value_of_ten
= 1;
85 int digit_maximum_value_of_ten
= 0;
86 int digit_new_draw_location_x
= 0;
88 if ( ( ( DOCKAPP_WIDTH
- DOCKAPP_BIG_CHAR_WIDTH
) < digit_draw_location_x
89 || ( DOCKAPP_HEIGHT
- DOCKAPP_BIG_CHAR_HEIGHT
) < digit_draw_location_y
)
90 || ( 0 > digit_draw_location_x
|| 0 > digit_draw_location_y
) )
93 "%s: Invalid x,y position: %d,%d\n",
95 digit_draw_location_x
,
96 digit_draw_location_y
);
100 for ( digit_maximum_value_of_ten
= 0;
101 digit_maximum_value_of_ten
< d_zero
;
102 ++digit_maximum_value_of_ten
)
104 digit_value_of_ten
*= 10;
107 digit_new_draw_location_x
= digit_draw_location_x
;
111 copyXPMArea( ( ( ( d_value
/ digit_value_of_ten
) % 10) *
112 DOCKAPP_SMALL_CHAR_WIDTH
+ DOCKAPP_SMALL_DIGIT_X
),
113 DOCKAPP_SMALL_DIGIT_Y
,
114 DOCKAPP_SMALL_CHAR_WIDTH
,
115 DOCKAPP_SMALL_CHAR_HEIGHT
,
116 digit_new_draw_location_x
,
117 digit_draw_location_y
);
119 digit_value_of_ten
/= 10;
120 digit_new_draw_location_x
+= DOCKAPP_SMALL_CHAR_WIDTH
;
121 } while ( 0 < digit_value_of_ten
);
127 dockapp_draw_big_str( const char* string_to_draw
,
128 int digit_draw_location_x
,
129 int digit_draw_location_y
)
131 int string_length
= 0;
132 int string_character_position
= 0;
133 int string_character
= 0;
134 int digit_new_draw_location_x
= 0;
136 string_length
= strlen( string_to_draw
);
138 if ( ( ( DOCKAPP_WIDTH
- DOCKAPP_BIG_CHAR_WIDTH
) < digit_draw_location_x
139 || ( DOCKAPP_HEIGHT
- DOCKAPP_BIG_CHAR_HEIGHT
) < digit_draw_location_y
)
140 || ( 0 > digit_draw_location_x
|| 0 > digit_draw_location_y
) )
143 "%s: Invalid x,y position: %d,%d\n",
145 digit_draw_location_x
,
146 digit_draw_location_y
);
150 else if ( 0 == string_length
)
152 fprintf( stderr
, "%s: Draw string is empty!\n", __func__
);
155 else if ( ( DOCKAPP_WIDTH
/ DOCKAPP_BIG_CHAR_WIDTH
) < string_length
)
157 fprintf( stderr
, "%s: Draw string is too long!", __func__
);
161 digit_new_draw_location_x
= digit_draw_location_x
;
163 for ( string_character_position
= 0;
164 string_character_position
< string_length
;
165 ++string_character_position
)
167 string_character
= dockapp_utils_get_char( string_to_draw
[string_character_position
] );
169 copyXPMArea( string_character
* DOCKAPP_BIG_CHAR_WIDTH
+ DOCKAPP_BIG_LETTER_X
,
170 DOCKAPP_BIG_LETTER_Y
,
171 DOCKAPP_BIG_CHAR_WIDTH
,
172 DOCKAPP_BIG_CHAR_HEIGHT
,
173 digit_new_draw_location_x
,
174 digit_draw_location_y
);
176 digit_new_draw_location_x
+= DOCKAPP_BIG_CHAR_WIDTH
;
183 dockapp_draw_small_str( const char* string_to_draw
,
184 int digit_draw_location_x
,
185 int digit_draw_location_y
)
187 int string_length
= 0;
188 int string_character_position
= 0;
189 int string_character
= 0;
190 int digit_new_draw_location_x
= 0;
192 string_length
= strlen( string_to_draw
);
194 if ( ( ( DOCKAPP_WIDTH
- DOCKAPP_BIG_CHAR_WIDTH
) < digit_draw_location_x
195 || ( DOCKAPP_HEIGHT
- DOCKAPP_BIG_CHAR_HEIGHT
) < digit_draw_location_y
)
196 || ( 0 > digit_draw_location_x
|| 0 > digit_draw_location_y
) )
199 "%s: Invalid x,y position: %d,%d\n",
201 digit_draw_location_x
,
202 digit_draw_location_y
);
205 else if ( 0 == string_length
)
207 fprintf( stderr
, "%s: Draw string is empty!\n", __func__
);
210 else if ( ( DOCKAPP_WIDTH
/ DOCKAPP_SMALL_CHAR_WIDTH
) < string_length
)
212 fprintf( stderr
, "%s: Draw string is too long!", __func__
);
216 digit_new_draw_location_x
= digit_draw_location_x
;
218 for (string_character_position
= 0;
219 string_character_position
< string_length
;
220 ++string_character_position
)
222 string_character
= dockapp_utils_get_char( string_to_draw
[string_character_position
] );
224 copyXPMArea( string_character
* DOCKAPP_SMALL_CHAR_WIDTH
+ DOCKAPP_SMALL_LETTER_X
,
225 DOCKAPP_SMALL_LETTER_Y
,
226 DOCKAPP_SMALL_CHAR_WIDTH
,
227 DOCKAPP_SMALL_CHAR_HEIGHT
,
228 digit_new_draw_location_x
,
229 digit_draw_location_y
);
231 digit_new_draw_location_x
+= DOCKAPP_SMALL_CHAR_WIDTH
;
239 dockapp_draw_bar( int bar_draw_width
,
245 if ( 0 > bar_draw_width
|| DOCKAPP_BAR_WIDTH
< bar_draw_width
)
247 fprintf( stderr
, "%s: Invalid bar width!\n", __func__
);
250 else if ( ( 0 > bar_draw_x
|| DOCKAPP_WIDTH
< bar_draw_x
) ||
251 ( 0 > bar_draw_y
|| DOCKAPP_WIDTH
< bar_draw_y
) )
254 "%s: Invalid x,y position: %d,%d\n",
260 else if ( 0 >= bar_x
|| 0 >= bar_y
)
263 "%s: Invalid x,y position: %d,%d\n",
281 dockapp_draw_bar_calculate( float draw_size
, int bar_draw_x
, int bar_draw_y
)
283 float draw_percent_f
;
286 draw_percent_f
= ( GET_HRS_F( draw_size
) / DOCKAPP_BAR_WIDTH
) * 100.0f
;
287 draw_percent
= ( int ) nearbyint( draw_percent_f
);
289 if ( DOCKAPP_BAR_WIDTH
== draw_percent
)
291 dockapp_draw_bar( draw_percent
,
299 dockapp_draw_bar( draw_percent
,
309 dockapp_draw_data( void )
311 dockapp_proc
= dockapp_utils_get_proc();
313 dockapp_draw_small_digit( dockapp_proc
.users
, 2, 45, 4 );
314 dockapp_draw_small_digit( dockapp_proc
.total
, 2, 45, 11 );
315 dockapp_draw_small_digit( dockapp_proc
.running
, 2, 45, 18 );
317 dockapp_draw_small_digit( dockapp_proc
.hours
, 1, 36, 28 );
318 dockapp_draw_small_digit( dockapp_proc
.minutes
, 1, 50, 28 );
320 dockapp_draw_small_digit( dockapp_proc
.days
, 0, 55, 37 );
321 dockapp_draw_small_digit( dockapp_proc
.weeks
, 2, 45, 44 );
323 dockapp_draw_small_digit( dockapp_proc
.load
[0], 1, 36, 53 );
324 dockapp_draw_small_digit( dockapp_proc
.load
[1], 1, 50, 53 );