-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathalt-group.c
88 lines (75 loc) · 2.43 KB
/
alt-group.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/*
* SPDX-FileCopyrightText: 2021 Samuel Cuella <[email protected]>
*
* This file is part of SoFIS - an open source EFIS
*
* SPDX-License-Identifier: GPL-2.0-only
*/
#include <stdio.h>
#include <stdlib.h>
#include "alt-group.h"
#include "base-gauge.h"
#include "resource-manager.h"
#include "sdl-colors.h"
#include "SDL_pcf.h"
#include "vertical-stair.h"
#include "res-dirs.h"
static BaseGaugeOps alt_group_ops = {
.render = (RenderFunc)NULL,
.update_state = (StateUpdateFunc)NULL,
.dispose = (DisposeFunc)NULL
};
AltGroup *alt_group_new(void)
{
AltGroup *self;
self = calloc(1, sizeof(AltGroup));
if(self){
if(!alt_group_init(self)){
return base_gauge_free(BASE_GAUGE(self));
}
}
return self;
}
AltGroup *alt_group_init(AltGroup *self)
{
self->altimeter = alt_indicator_new();
self->vsi = vertical_stair_new(IMG_DIR"/vs-bg.png",IMG_DIR"/vs-cursor.png",
resource_manager_get_static_font(TERMINUS_16, &SDL_WHITE, 2, PCF_DIGITS, "+-")
);
if(!self->vsi || !self->altimeter)
goto bail;
/* TODO: Move me as first operation to ensure that Ops are always
* set when we return NULL so that base_gauge_dispose (called by
* base_gauge_free) can properly dispose any gauge-allocated resources*/
base_gauge_init(
BASE_GAUGE(self),
&alt_group_ops,
base_gauge_w(BASE_GAUGE(self->altimeter)) + base_gauge_w(BASE_GAUGE(self->vsi)),
(base_gauge_h(BASE_GAUGE(self->vsi)) > base_gauge_h(BASE_GAUGE(self->altimeter))) ?
base_gauge_h(BASE_GAUGE(self->vsi)) :
base_gauge_h(BASE_GAUGE(self->altimeter))
);
base_gauge_add_child(BASE_GAUGE(self), BASE_GAUGE(self->altimeter), 0, 0);
base_gauge_add_child(BASE_GAUGE(self), BASE_GAUGE(self->vsi),
base_gauge_w(BASE_GAUGE(self->altimeter)),
base_gauge_h(BASE_GAUGE(self->altimeter))/2 - base_gauge_h(BASE_GAUGE(self->vsi))/2
);
return self;
bail:
if(self->vsi) free(self->vsi);
if(self->altimeter) free(self->altimeter);
return NULL;
}
void alt_group_set_altitude(AltGroup *self, float value)
{
alt_indicator_set_value(self->altimeter, value, true);
}
void alt_group_set_vertical_speed(AltGroup *self, float value)
{
vertical_stair_set_value(self->vsi, value, true);
}
void alt_group_set_values(AltGroup *self, float alt, float vs)
{
alt_group_set_altitude(self, alt);
alt_group_set_vertical_speed(self, vs);
}