mirror of
https://github.com/subsurface/subsurface.git
synced 2024-12-01 06:30:26 +00:00
Add new helper function to get temperature and unit
Designed along the lines of get_depth_units - except we don't define a specific number of digits to show. Use this in the one spot we need it right now in profile.c Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
43601f6546
commit
18b8247cb3
3 changed files with 22 additions and 10 deletions
17
dive.c
17
dive.c
|
@ -29,6 +29,23 @@ void add_event(struct dive *dive, int time, int type, int flags, int value, cons
|
||||||
remember_event(name);
|
remember_event(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
double get_temp_units(unsigned int mk, const char **units)
|
||||||
|
{
|
||||||
|
double deg;
|
||||||
|
const char *unit;
|
||||||
|
|
||||||
|
if (output_units.temperature == FAHRENHEIT) {
|
||||||
|
deg = mkelvin_to_F(mk);
|
||||||
|
unit = UTF8_DEGREE "F";
|
||||||
|
} else {
|
||||||
|
deg = mkelvin_to_C(mk);
|
||||||
|
unit = UTF8_DEGREE "C";
|
||||||
|
}
|
||||||
|
if (units)
|
||||||
|
*units = unit;
|
||||||
|
return deg;
|
||||||
|
}
|
||||||
|
|
||||||
double get_depth_units(unsigned int mm, int *frac, const char **units)
|
double get_depth_units(unsigned int mm, int *frac, const char **units)
|
||||||
{
|
{
|
||||||
int decimals;
|
int decimals;
|
||||||
|
|
1
dive.h
1
dive.h
|
@ -87,6 +87,7 @@ typedef struct {
|
||||||
} cylinder_t;
|
} cylinder_t;
|
||||||
|
|
||||||
extern double get_depth_units(unsigned int mm, int *frac, const char **units);
|
extern double get_depth_units(unsigned int mm, int *frac, const char **units);
|
||||||
|
extern double get_temp_units(unsigned int mm, const char **units);
|
||||||
|
|
||||||
static inline double mm_to_feet(int mm)
|
static inline double mm_to_feet(int mm)
|
||||||
{
|
{
|
||||||
|
|
14
profile.c
14
profile.c
|
@ -485,19 +485,13 @@ static int setup_temperature_limits(struct graphics_context *gc, struct plot_inf
|
||||||
|
|
||||||
static void plot_single_temp_text(struct graphics_context *gc, int sec, int mkelvin)
|
static void plot_single_temp_text(struct graphics_context *gc, int sec, int mkelvin)
|
||||||
{
|
{
|
||||||
int deg;
|
double deg;
|
||||||
const char *unit;
|
const char *unit;
|
||||||
static const text_render_options_t tro = {12, 0.2, 0.2, 1.0, LEFT, TOP};
|
static const text_render_options_t tro = {12, 0.2, 0.2, 1.0, LEFT, TOP};
|
||||||
temperature_t temperature = { mkelvin };
|
|
||||||
|
|
||||||
if (output_units.temperature == FAHRENHEIT) {
|
deg = get_temp_units(mkelvin, &unit);
|
||||||
deg = to_F(temperature);
|
|
||||||
unit = UTF8_DEGREE "F";
|
plot_text(gc, &tro, sec, mkelvin, "%d%s", (int)(deg + 0.5), unit);
|
||||||
} else {
|
|
||||||
deg = to_C(temperature);
|
|
||||||
unit = UTF8_DEGREE "C";
|
|
||||||
}
|
|
||||||
plot_text(gc, &tro, sec, temperature.mkelvin, "%d%s", deg, unit);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void plot_temperature_text(struct graphics_context *gc, struct plot_info *pi)
|
static void plot_temperature_text(struct graphics_context *gc, struct plot_info *pi)
|
||||||
|
|
Loading…
Reference in a new issue