// Draw wind direction arrow in the supplied widget
void qso_wx::draw_wind_dirn(Fl_Widget* w, unsigned int dirn) {
// Find central position
int x_zero = w->w() / 2;
int y_zero = w->h() / 2;
// arrow will fill 80% widget
int radius = min(x_zero, y_zero) * 7 / 10;
float angle = dirn * DEGREE_RADIAN;
int x_disp = radius * sin(angle);
int y_disp = radius * cos(angle);
int x_start = x_zero + x_disp;
int y_start = y_zero - y_disp;
int x_end = x_zero - x_disp;
int y_end = y_zero + y_disp;
// Create the drawing surface
Fl_Image_Surface* image_surface = new Fl_Image_Surface(w->w(), w->h());
Fl_Surface_Device::push_current(image_surface);
// Draw the background
fl_color(FL_BACKGROUND_COLOR);
fl_rectf(0, 0, w->w(), w->h());
// Draw the line
fl_color(FL_FOREGROUND_COLOR);
if (dirn == -1) {
// No wind draw a circle
fl_arc(x_zero-(radius/2), y_zero-(radius/2), radius, radius , 0, 360);
} else {
fl_line(x_start, y_start, x_end, y_end);
float rad45 = 15 * DEGREE_RADIAN;
int arrow_len = radius;
float arrow_l = angle + rad45;
int x_arrow_l = x_end + (arrow_len * sin(arrow_l));
int y_arrow_l = y_end - (arrow_len * cos(arrow_l));
// fl_line(x_end, y_end, x_arrow_l, y_arrow_l);
float arrow_r = angle - rad45;
int x_arrow_r = x_end + (arrow_len * sin(arrow_r));
int y_arrow_r = y_end - (arrow_len * cos(arrow_r));
// fl_line(x_end, y_end, x_arrow_r, y_arrow_r);
fl_polygon(x_end, y_end, x_arrow_l, y_arrow_l, x_arrow_r, y_arrow_r);
}
Fl_RGB_Image* image = image_surface->image();
// Restore window before drawing widget
Fl_Surface_Device::pop_current();
// Now put the image into the widget
w->label("");
w->image(image);
}