1
0
mirror of https://github.com/Llewellynvdm/conky.git synced 2024-11-15 17:47:09 +00:00

convert meter type object values from uint8_t to double

This commit is contained in:
Phil Sutter 2009-12-04 01:11:57 +01:00
parent 1e25633fc1
commit e5d32f4ad0
4 changed files with 46 additions and 40 deletions

View File

@ -1288,8 +1288,8 @@ int draw_each_line_inner(char *s, int special_index, int last_special_applied)
case BAR:
{
int h, bar_usage, by;
float scale;
int h, by;
double bar_usage, scale;
if (cur_x - text_start_x > maximum_width
&& maximum_width > 0) {
break;
@ -1330,8 +1330,7 @@ int draw_each_line_inner(char *s, int special_index, int last_special_applied)
unsigned long last_colour = current_color;
#ifdef MATH
float angle, px, py;
int usage;
float scale;
double usage, scale;
#endif /* MATH */
if (cur_x - text_start_x > maximum_width
@ -1362,7 +1361,7 @@ int draw_each_line_inner(char *s, int special_index, int last_special_applied)
#ifdef MATH
usage = specials[special_index].arg;
scale = specials[special_index].scale;
angle = (M_PI)*(float)(usage)/scale;
angle = M_PI * usage / scale;
px = (float)(cur_x+(w/2.))-(float)(w/2.)*cos(angle);
py = (float)(by+(h))-(float)(h)*sin(angle);

View File

@ -62,20 +62,20 @@ int default_gauge_width = 40, default_gauge_height = 25;
struct bar {
char flags;
int width, height;
unsigned int scale;
double scale;
};
struct gauge {
char flags;
int width, height;
unsigned int scale;
double scale;
};
struct graph {
char flags;
int width, height;
unsigned int first_colour, last_colour;
unsigned int scale;
double scale;
char tempgrad;
};
@ -91,7 +91,7 @@ struct tab {
* Scanning arguments to various special text objects
*/
const char *scan_gauge(struct text_object *obj, const char *args, unsigned int scale)
const char *scan_gauge(struct text_object *obj, const char *args, double scale)
{
struct gauge *g;
@ -123,7 +123,7 @@ const char *scan_gauge(struct text_object *obj, const char *args, unsigned int s
return args;
}
const char *scan_bar(struct text_object *obj, const char *args, unsigned int scale)
const char *scan_bar(struct text_object *obj, const char *args, double scale)
{
struct bar *b;
@ -160,7 +160,7 @@ void scan_font(struct text_object *obj, const char *args)
obj->data.s = strndup(args, DEFAULT_TEXT_BUFFER_SIZE);
}
char *scan_graph(struct text_object *obj, const char *args, int defscale)
char *scan_graph(struct text_object *obj, const char *args, double defscale)
{
struct graph *g;
char buf[1024];
@ -184,14 +184,14 @@ char *scan_graph(struct text_object *obj, const char *args, int defscale)
if (strstr(args, " "LOGGRAPH) || strncmp(args, LOGGRAPH, strlen(LOGGRAPH)) == 0) {
g->flags |= SF_SHOWLOG;
}
if (sscanf(args, "%d,%d %x %x %u", &g->height, &g->width, &g->first_colour, &g->last_colour, &g->scale) == 5) {
if (sscanf(args, "%d,%d %x %x %lf", &g->height, &g->width, &g->first_colour, &g->last_colour, &g->scale) == 5) {
return NULL;
}
g->scale = defscale;
if (sscanf(args, "%d,%d %x %x", &g->height, &g->width, &g->first_colour, &g->last_colour) == 4) {
return NULL;
}
if (sscanf(args, "%1023s %d,%d %x %x %u", buf, &g->height, &g->width, &g->first_colour, &g->last_colour, &g->scale) == 6) {
if (sscanf(args, "%1023s %d,%d %x %x %lf", buf, &g->height, &g->width, &g->first_colour, &g->last_colour, &g->scale) == 6) {
return strndup(buf, text_buffer_size);
}
g->scale = defscale;
@ -201,14 +201,14 @@ char *scan_graph(struct text_object *obj, const char *args, int defscale)
buf[0] = '\0';
g->height = 25;
g->width = 0;
if (sscanf(args, "%x %x %u", &g->first_colour, &g->last_colour, &g->scale) == 3) {
if (sscanf(args, "%x %x %lf", &g->first_colour, &g->last_colour, &g->scale) == 3) {
return NULL;
}
g->scale = defscale;
if (sscanf(args, "%x %x", &g->first_colour, &g->last_colour) == 2) {
return NULL;
}
if (sscanf(args, "%1023s %x %x %u", buf, &g->first_colour, &g->last_colour, &g->scale) == 4) {
if (sscanf(args, "%1023s %x %x %lf", buf, &g->first_colour, &g->last_colour, &g->scale) == 4) {
return strndup(buf, text_buffer_size);
}
g->scale = defscale;
@ -218,14 +218,14 @@ char *scan_graph(struct text_object *obj, const char *args, int defscale)
buf[0] = '\0';
g->first_colour = 0;
g->last_colour = 0;
if (sscanf(args, "%d,%d %u", &g->height, &g->width, &g->scale) == 3) {
if (sscanf(args, "%d,%d %lf", &g->height, &g->width, &g->scale) == 3) {
return NULL;
}
g->scale = defscale;
if (sscanf(args, "%d,%d", &g->height, &g->width) == 2) {
return NULL;
}
if (sscanf(args, "%1023s %d,%d %u", buf, &g->height, &g->width, &g->scale) < 4) {
if (sscanf(args, "%1023s %d,%d %lf", buf, &g->height, &g->width, &g->scale) < 4) {
g->scale = defscale;
//TODO: check the return value and throw an error?
sscanf(args, "%1023s %d,%d", buf, &g->height, &g->width);
@ -259,16 +259,16 @@ static struct special_t *new_special(char *buf, enum special_types t)
return &specials[special_count++];
}
void new_gauge_in_shell(struct text_object *obj, char *p, int p_max_size, int usage)
void new_gauge_in_shell(struct text_object *obj, char *p, int p_max_size, double usage)
{
static const char *gaugevals[] = { "_. ", "\\. ", " | ", " ./", " ._" };
struct gauge *g = obj->special_data;
snprintf(p, p_max_size, "%s", gaugevals[round_to_int((double)usage * 4 / g->scale)]);
snprintf(p, p_max_size, "%s", gaugevals[round_to_int(usage * 4 / g->scale)]);
}
#ifdef X11
void new_gauge_in_x11(struct text_object *obj, char *buf, int usage)
void new_gauge_in_x11(struct text_object *obj, char *buf, double usage)
{
struct special_t *s = 0;
struct gauge *g = obj->special_data;
@ -288,7 +288,7 @@ void new_gauge_in_x11(struct text_object *obj, char *buf, int usage)
}
#endif /* X11 */
void new_gauge(struct text_object *obj, char *p, int p_max_size, int usage)
void new_gauge(struct text_object *obj, char *p, int p_max_size, double usage)
{
struct gauge *g = obj->special_data;
@ -296,9 +296,9 @@ void new_gauge(struct text_object *obj, char *p, int p_max_size, int usage)
return;
if (g->flags & SF_SCALED)
g->scale = MAX(g->scale, (unsigned int)usage);
g->scale = MAX(g->scale, usage);
else
usage = MIN(g->scale, (unsigned int)usage);
usage = MIN(g->scale, usage);
#ifdef X11
if (output_methods & TO_X)
@ -516,7 +516,7 @@ static void new_bar_in_shell(struct text_object *obj, char* buffer, int buf_max_
}
#ifdef X11
static void new_bar_in_x11(struct text_object *obj, char *buf, int usage)
static void new_bar_in_x11(struct text_object *obj, char *buf, double usage)
{
struct special_t *s = 0;
struct bar *b = obj->special_data;
@ -537,7 +537,7 @@ static void new_bar_in_x11(struct text_object *obj, char *buf, int usage)
#endif /* X11 */
/* usage is in range [0,255] */
void new_bar(struct text_object *obj, char *p, int p_max_size, int usage)
void new_bar(struct text_object *obj, char *p, int p_max_size, double usage)
{
struct bar *b = obj->special_data;
@ -545,9 +545,9 @@ void new_bar(struct text_object *obj, char *p, int p_max_size, int usage)
return;
if (b->flags & SF_SCALED)
b->scale = MAX(b->scale, (unsigned int)usage);
b->scale = MAX(b->scale, usage);
else
usage = MIN(b->scale, (unsigned int)usage);
usage = MIN(b->scale, usage);
#ifdef X11
if ((output_methods & TO_X))

View File

@ -62,7 +62,7 @@ struct special_t {
int type;
short height;
short width;
long arg;
double arg;
double *graph;
double scale; /* maximum value */
short show_scale;
@ -94,11 +94,11 @@ struct text_object;
extern int max_specials;
/* scanning special arguments */
const char *scan_bar(struct text_object *, const char *, unsigned int);
const char *scan_gauge(struct text_object *, const char *, unsigned int);
const char *scan_bar(struct text_object *, const char *, double);
const char *scan_gauge(struct text_object *, const char *, double);
#ifdef X11
void scan_font(struct text_object *, const char *);
char *scan_graph(struct text_object *, const char *, int);
char *scan_graph(struct text_object *, const char *, double);
void scan_tab(struct text_object *, const char *);
void scan_stippled_hr(struct text_object *, const char*);
@ -108,8 +108,8 @@ void new_graph(struct text_object *, char *, int, double);
void new_hr(struct text_object *, char *, int);
void new_stippled_hr(struct text_object *, char *, int);
#endif
void new_gauge(struct text_object *, char *, int, int);
void new_bar(struct text_object *, char *, int, int);
void new_gauge(struct text_object *, char *, int, double);
void new_bar(struct text_object *, char *, int, double);
void new_fg(struct text_object *, char *, int);
void new_bg(struct text_object *, char *, int);
void new_outline(struct text_object *, char *, int);

View File

@ -475,16 +475,23 @@ enum text_object_type {
struct obj_cb {
/* text object: print obj's output to p */
void (*print)(struct text_object *obj, char *p, int p_max_size);
/* ifblock object: return zero to trigger jumping */
int (*iftest)(struct text_object *obj);
/* bar object: return bar value in range [0,255] */
uint8_t (*barval)(struct text_object *obj);
/* gauge object: return gauge value in range [0,255] */
uint8_t (*gaugeval)(struct text_object *obj);
/* graph object: return graph value in range [0,255] */
uint8_t (*graphval)(struct text_object *obj);
/* percentage object: return percentage in range [0,100] */
/* meter objects:
* The following functions return the current meter-type value
* in a range between 0 and the value passed to the appropriate
* scan_* function. Or, if named function has been called with
* a value of 0, make use of auto-scaling (i.e., scaling to the
* maximum value seen so far). */
double (*barval)(struct text_object *obj);
double (*gaugeval)(struct text_object *obj);
double (*graphval)(struct text_object *obj);
/* percentage object: return value in range [0, 100] */
uint8_t (*percentage)(struct text_object *obj);
/* free obj's data */
void (*free)(struct text_object *obj);
};