-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathairspeed-page-descriptor.c
More file actions
141 lines (113 loc) · 4.51 KB
/
Copy pathairspeed-page-descriptor.c
File metadata and controls
141 lines (113 loc) · 4.51 KB
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/*
* SPDX-FileCopyrightText: 2021 Samuel Cuella <samuel.cuella@gmail.com>
*
* This file is part of SoFIS - an open source EFIS
*
* SPDX-License-Identifier: GPL-2.0-only
*/
#include <stdio.h>
#include <stdlib.h>
#include "airspeed-page-descriptor.h"
#include "generic-layer.h"
#include "ladder-page.h"
#include "sdl-colors.h"
#include "vertical-strip.h"
LadderPage *airspeed_ladder_page_init(LadderPage *self);
static void airspeed_ladder_page_draw_arc(LadderPage *self, float start, float end, uintf8_t width, Uint32 color);
static void airspeed_ladder_page_draw_arcs(LadderPage *self);
AirspeedPageDescriptor *airspeed_page_descriptor_new(int page_w, int page_h_min, uintf8_t unit_px_sz,
int small_step_width, int big_step_width,
speed_t v_so, speed_t v_s1, speed_t v_fe,
speed_t v_no, speed_t v_ne)
{
AirspeedPageDescriptor *self;
int pattern_h;
self = calloc(1, sizeof(AirspeedPageDescriptor));
if(!self)
return NULL;
self->v_so = v_so;
self->v_s1 = v_s1;
self->v_fe = v_fe;
self->v_no = v_no;
self->v_ne = v_ne;
vruler_page_descriptor_init(
VRULER_PAGE_DESCRIPTOR(self),
page_w, page_h_min,
unit_px_sz,
small_step_width, big_step_width,
10, 5,
BOTTUM_UP, airspeed_ladder_page_init
);
return self;
}
LadderPage *airspeed_ladder_page_init(LadderPage *self)
{
vruler_ladder_page_init(self, LocationRight);
airspeed_ladder_page_draw_arcs(self);
generic_layer_build_texture(GENERIC_LAYER(self));
return self;
}
void airspeed_ladder_page_draw_arcs(LadderPage *self)
{
AirspeedPageDescriptor *descriptor;
float green_start, green_end;
float yellow_start, yellow_end;
float white_start, white_end;
descriptor = (AirspeedPageDescriptor *)self->descriptor;
green_start = (descriptor->v_s1);
green_end = (descriptor->v_no);
yellow_start = (descriptor->v_no);
yellow_end = (descriptor->v_ne);
white_start = (descriptor->v_so);
white_end = (descriptor->v_fe);
/*Green arc*/
// printf("Green arc from %d kts to %d kts\n",descriptor->v_s1, descriptor->v_no);
airspeed_ladder_page_draw_arc(self, descriptor->v_s1, descriptor->v_no, 4, SDL_UGREEN(GENERIC_LAYER(self)->canvas));
/*Yellow*/
airspeed_ladder_page_draw_arc(self, descriptor->v_no, descriptor->v_ne, 4, SDL_UYELLOW(GENERIC_LAYER(self)->canvas));
/*White last, over any existing*/
airspeed_ladder_page_draw_arc(self, descriptor->v_so, descriptor->v_fe, 2, SDL_UGREY(GENERIC_LAYER(self)->canvas));
/*VNE*/
airspeed_ladder_page_draw_arc(self, descriptor->v_ne, descriptor->v_ne+2, 4, SDL_URED(GENERIC_LAYER(self)->canvas));
}
static void airspeed_ladder_page_draw_arc(LadderPage *self, float start, float end, uintf8_t width, Uint32 color)
{
float istart, iend;
float ystart, yend;
int firsty, lasty;
Uint32 *pixels;
SDL_Surface *surface;
int x;
Uint32 white;
if(interval_intersect(start, end, VERTICAL_STRIP(self)->start, VERTICAL_STRIP(self)->end, &istart, &iend)){
surface = GENERIC_LAYER(self)->canvas;
white = SDL_UWHITE(surface);
ystart = ladder_page_resolve_value(self, istart);
yend = ladder_page_resolve_value(self, iend);
firsty = (ystart < yend) ? ystart : yend;
lasty = (yend > ystart) ? yend : ystart;
if(firsty < 0) firsty = 0;
if(lasty > (surface->h-1)) lasty = surface->h-1;
/*
printf("Intersection between arc from %f to %f and current page from %f to %f is %f,%f and will be starting at Y:%d to Y:%d\n",
start, end, VERTICAL_STRIP(self)->start, VERTICAL_STRIP(self)->end,
istart, iend,
firsty, lasty
);*/
SDL_LockSurface(surface);
pixels = surface->pixels;
for(int i = firsty; i <= lasty; i++){
x = ((surface->w-1)-1) - (width-1); /*second -1 to avoid eating the border*/
for(int j = x; j < surface->w; j++){
Uint32 idx = i * surface->w + j;
if(pixels[idx] != white) /*Avoid eating the marks*/
pixels[idx] = color;
}
}
SDL_UnlockSurface(surface);
}else{/*
printf("No intersection between arc from %f to %f and current page from %f to %f\n",
start, end, VERTICAL_STRIP(self)->start, VERTICAL_STRIP(self)->end
);*/
}
}