41#include "wx/tokenzr.h" 
   46DashboardInstrument_Wind::DashboardInstrument_Wind(
 
   47    wxWindow* parent, wxWindowID 
id, wxString title,
 
   51  SetOptionMarker(10, DIAL_MARKER_REDGREENBAR, 3);
 
   53  wxString labels[] = {_T(
""),    _T(
"30"),  _T(
"60"), _T(
"90"),
 
   54                       _T(
"120"), _T(
"150"), _T(
""),   _T(
"150"),
 
   55                       _T(
"120"), _T(
"90"),  _T(
"60"), _T(
"30")};
 
   56  SetOptionLabel(30, DIAL_LABEL_HORIZONTAL, wxArrayString(12, labels));
 
   59void DashboardInstrument_Wind::DrawBackground(wxGCDC* dc) {
 
   60  DrawBoat(dc, m_cx, m_cy, m_radius);
 
   63DashboardInstrument_WindCompass::DashboardInstrument_WindCompass(
 
   64    wxWindow* parent, wxWindowID 
id, wxString title,
 
   68  SetOptionMarker(5, DIAL_MARKER_SIMPLE, 2);
 
   69  wxString labels[] = {_(
"N"), _(
"NE"), _(
"E"), _(
"SE"),
 
   70                       _(
"S"), _(
"SW"), _(
"W"), _(
"NW")};
 
   71  SetOptionLabel(45, DIAL_LABEL_HORIZONTAL, wxArrayString(8, labels));
 
   74void DashboardInstrument_WindCompass::DrawBackground(wxGCDC* dc) {
 
   75  DrawCompassRose(dc, m_cx, m_cy, m_radius * 0.85, m_AngleStart, 
false,
 
   82DashboardInstrument_TrueWindAngle::DashboardInstrument_TrueWindAngle(
 
   83    wxWindow* parent, wxWindowID 
id, wxString title,
 
   87  SetOptionMarker(10, DIAL_MARKER_REDGREENBAR, 3);
 
   89  wxString labels[] = {_T(
""),    _T(
"30"),  _T(
"60"), _T(
"90"),
 
   90                       _T(
"120"), _T(
"150"), _T(
""),   _T(
"150"),
 
   91                       _T(
"120"), _T(
"90"),  _T(
"60"), _T(
"30")};
 
   92  SetOptionLabel(30, DIAL_LABEL_HORIZONTAL, wxArrayString(12, labels));
 
   95void DashboardInstrument_TrueWindAngle::DrawBackground(wxGCDC* dc) {
 
   96  DrawBoat(dc, m_cx, m_cy, m_radius);
 
  103DashboardInstrument_AppTrueWindAngle::DashboardInstrument_AppTrueWindAngle(
 
  104    wxWindow* parent, wxWindowID 
id, wxString title,
 
  108  SetOptionMarker(10, DIAL_MARKER_REDGREENBAR, 3);
 
  110  wxString labels[] = {_T(
""),    _T(
"30"),  _T(
"60"), _T(
"90"),
 
  111                       _T(
"120"), _T(
"150"), _T(
""),   _T(
"150"),
 
  112                       _T(
"120"), _T(
"90"),  _T(
"60"), _T(
"30")};
 
  113  SetOptionLabel(30, DIAL_LABEL_HORIZONTAL, wxArrayString(12, labels));
 
  116void DashboardInstrument_AppTrueWindAngle::DrawBackground(wxGCDC* dc) {
 
  117  DrawBoat(dc, m_cx, m_cy, m_radius);
 
  120void DashboardInstrument_AppTrueWindAngle::SetData(DASH_CAP st, 
double data,
 
  122  if (st == OCPN_DBP_STC_TWA) {
 
  123    m_MainValueTrue = data;
 
  124    m_MainValueTrueUnit = 
unit;
 
  125    m_MainValueOption2 = DIAL_POSITION_BOTTOMLEFT;
 
  126  } 
else if (st == OCPN_DBP_STC_AWA) {
 
  127    m_MainValueApp = data;
 
  128    m_MainValueAppUnit = 
unit;
 
  129    m_MainValueOption1 = DIAL_POSITION_TOPLEFT;
 
  130  } 
else if (st == OCPN_DBP_STC_AWS) {
 
  131    m_ExtraValueApp = data;
 
  132    m_ExtraValueAppUnit = 
unit;
 
  133    m_ExtraValueOption1 = DIAL_POSITION_TOPRIGHT;
 
  134  } 
else if (st == OCPN_DBP_STC_TWS) {
 
  135    m_ExtraValueTrue = data;
 
  136    m_ExtraValueTrueUnit = 
unit;
 
  137    m_ExtraValueOption2 = DIAL_POSITION_BOTTOMRIGHT;
 
  141void DashboardInstrument_AppTrueWindAngle::Draw(wxGCDC* bdc) {
 
  144        GetColourSchemeBackgroundColour(m_Properties->m_DataBackgroundColour));
 
  146        GetColourSchemeBackgroundColour(m_Properties->m_DataBackgroundColour));
 
  149    GetGlobalColor(_T(
"DASHB"), &c1);
 
  151    bdc->SetBackground(b1);
 
  155  wxSize size = GetClientSize();
 
  159    f = m_Properties->m_LabelFont.GetChosenFont();
 
  161    f = g_pFontLabel->GetChosenFont();
 
  162  bdc->GetTextExtent(_T(
"000"), &width, &height, 0, 0, &f);
 
  164  int availableHeight = GetDataBottom(size.y) - m_DataTop;
 
  165  InitTitleAndDataPosition(availableHeight);
 
  166  availableHeight -= height;
 
  167  m_cy = m_DataTop + height / 2;
 
  168  m_cy += availableHeight / 2;
 
  169  m_radius = availableHeight / 2.0 * 0.95;
 
  175  DrawData(bdc, m_MainValueApp, m_MainValueAppUnit, m_MainValueFormat,
 
  177  DrawData(bdc, m_MainValueTrue, m_MainValueTrueUnit, m_MainValueFormat,
 
  179  DrawData(bdc, m_ExtraValueApp, m_ExtraValueAppUnit, m_ExtraValueFormat,
 
  180           m_ExtraValueOption1);
 
  181  DrawData(bdc, m_ExtraValueTrue, m_ExtraValueTrueUnit, m_ExtraValueFormat,
 
  182           m_ExtraValueOption2);
 
  185void DashboardInstrument_AppTrueWindAngle::DrawForeground(wxGCDC* dc) {
 
  192  GetGlobalColor(_T(
"DASH2"), &cl);
 
  194  pen1.SetStyle(wxPENSTYLE_SOLID);
 
  198  GetGlobalColor(_T(
"DASH1"), &cl);
 
  200  brush1.SetStyle(wxBRUSHSTYLE_SOLID);
 
  201  brush1.SetColour(cl);
 
  202  dc->SetBrush(brush1);
 
  203  dc->DrawCircle(m_cx, m_cy, m_radius / 8);
 
  206  dc->SetPen(*wxTRANSPARENT_PEN);
 
  208    cl = GetColourSchemeFont(m_Properties->m_Arrow_Second_Colour);
 
  210    GetGlobalColor(_T(
"BLUE3"), &cl);
 
  212  brush2.SetStyle(wxBRUSHSTYLE_SOLID);
 
  213  brush2.SetColour(cl);
 
  214  dc->SetBrush(brush2);
 
  218  if (m_MainValueTrueUnit == _T(
"\u00B0L"))
 
  219    data = 360 - m_MainValueTrue;
 
  221    data = m_MainValueTrue;
 
  224  if (data < m_MainValueMin)
 
  225    val = m_MainValueMin;
 
  226  else if (data > m_MainValueMax)
 
  227    val = m_MainValueMax;
 
  231  value = deg2rad((val - m_MainValueMin) * m_AngleRange /
 
  232                  (m_MainValueMax - m_MainValueMin)) +
 
  233          deg2rad(m_AngleStart - ANGLE_OFFSET);
 
  235  points[0].x = m_cx + (m_radius * 0.95 * cos(value - .010));
 
  236  points[0].y = m_cy + (m_radius * 0.95 * sin(value - .010));
 
  237  points[1].x = m_cx + (m_radius * 0.95 * cos(value + .015));
 
  238  points[1].y = m_cy + (m_radius * 0.95 * sin(value + .015));
 
  239  points[2].x = m_cx + (m_radius * 0.22 * cos(value + 2.8));
 
  240  points[2].y = m_cy + (m_radius * 0.22 * sin(value + 2.8));
 
  241  points[3].x = m_cx + (m_radius * 0.22 * cos(value - 2.8));
 
  242  points[3].y = m_cy + (m_radius * 0.22 * sin(value - 2.8));
 
  243  dc->DrawPolygon(4, points, 0, 0);
 
  246  dc->SetPen(*wxTRANSPARENT_PEN);
 
  248    cl = GetColourSchemeFont(m_Properties->m_Arrow_First_Colour);
 
  250    GetGlobalColor(_T(
"DASHN"), &cl);
 
  252  brush.SetStyle(wxBRUSHSTYLE_SOLID);
 
  258  if (m_MainValueAppUnit == _T(
"\u00B0L"))
 
  259    data = 360 - m_MainValueApp;
 
  261    data = m_MainValueApp;
 
  264  if (data < m_MainValueMin)
 
  265    val = m_MainValueMin;
 
  266  else if (data > m_MainValueMax)
 
  267    val = m_MainValueMax;
 
  271  value = deg2rad((val - m_MainValueMin) * m_AngleRange /
 
  272                  (m_MainValueMax - m_MainValueMin)) +
 
  273          deg2rad(m_AngleStart - ANGLE_OFFSET);
 
  275  points[0].x = m_cx + (m_radius * 0.95 * cos(value - .010));
 
  276  points[0].y = m_cy + (m_radius * 0.95 * sin(value - .010));
 
  277  points[1].x = m_cx + (m_radius * 0.95 * cos(value + .015));
 
  278  points[1].y = m_cy + (m_radius * 0.95 * sin(value + .015));
 
  279  points[2].x = m_cx + (m_radius * 0.22 * cos(value + 2.8));
 
  280  points[2].y = m_cy + (m_radius * 0.22 * sin(value + 2.8));
 
  281  points[3].x = m_cx + (m_radius * 0.22 * cos(value - 2.8));
 
  282  points[3].y = m_cy + (m_radius * 0.22 * sin(value - 2.8));
 
  283  dc->DrawPolygon(4, points, 0, 0);
 
  285void DashboardInstrument_AppTrueWindAngle::DrawData(
 
  286    wxGCDC* dc, 
double value, wxString 
unit, wxString format,
 
  287    DialPositionOption position) {
 
  288  if (position == DIAL_POSITION_NONE) 
return;
 
  292    dc->SetFont(m_Properties->m_LabelFont.GetChosenFont());
 
  293    cl = GetColourSchemeFont(m_Properties->m_LabelFont.GetColour());
 
  295    dc->SetFont(g_pFontLabel->GetChosenFont());
 
  296    cl = GetColourSchemeFont(g_pFontLabel->GetColour());
 
  299  dc->SetTextForeground(cl);
 
  301  wxSize size = GetClientSize();
 
  304  if (!std::isnan(value)) {
 
  305    if (
unit == _T(
"\u00B0"))
 
  306      text = wxString::Format(format, value) + DEGREE_SIGN;
 
  307    else if (
unit == _T(
"\u00B0L"))  
 
  309      text = wxString::Format(format, value) + DEGREE_SIGN;
 
  312      text = wxString::Format(format, value) + DEGREE_SIGN;
 
  313    else if (
unit == _T(
"\u00B0T"))
 
  314      text = wxString::Format(format, value) + DEGREE_SIGN + _T(
"T");
 
  315    else if (
unit == _T(
"\u00B0M"))
 
  316      text = wxString::Format(format, value) + DEGREE_SIGN + _T(
"M");
 
  317    else if (
unit == _T(
"N"))  
 
  318      text = wxString::Format(format, value) + _T(
" Kts");
 
  320      text = wxString::Format(format, value) + _T(
" ") + 
unit;
 
  327    f = m_Properties->m_LabelFont.GetChosenFont();
 
  329    f = g_pFontLabel->GetChosenFont();
 
  330  dc->GetMultiLineTextExtent(text, &width, &height, NULL, &f);
 
  333  TextPoint.width = width;
 
  334  TextPoint.height = height;
 
  338    case DIAL_POSITION_NONE:
 
  342    case DIAL_POSITION_INSIDE: {
 
  343      TextPoint.x = m_cx - (width / 2) - 1;
 
  344      TextPoint.y = ((size.y - m_InstrumentSpacing) * .75) - height;
 
  345      if ((g_TitleAlignment & wxALIGN_BOTTOM) != 0)
 
  346        TextPoint.y -= m_TitleHeight;
 
  347      GetGlobalColor(_T(
"DASHL"), &cl);
 
  348      int penwidth = size.x / 100;
 
  350          wxThePenList->FindOrCreatePen(cl, penwidth, wxPENSTYLE_SOLID);
 
  352      GetGlobalColor(_T(
"DASHB"), &cl);
 
  356      dc->DrawRoundedRectangle(TextPoint.x - 2, TextPoint.y - 2, width + 4,
 
  360    case DIAL_POSITION_TOPLEFT:
 
  361      GetGlobalColor(_T(
"DASHN"), &c3);
 
  363      TextPoint.y = m_DataTop;
 
  364      text = _T(
"A:") + text;
 
  366    case DIAL_POSITION_TOPRIGHT:
 
  367      GetGlobalColor(_T(
"DASHN"), &c3);
 
  368      TextPoint.x = size.x - width - 1;
 
  369      TextPoint.y = m_DataTop;
 
  371    case DIAL_POSITION_BOTTOMLEFT:
 
  372      GetGlobalColor(_T(
"BLUE3"), &c3);
 
  373      text = _T(
"T:") + text;
 
  375      TextPoint.y = GetDataBottom(size.y) - height;
 
  377    case DIAL_POSITION_BOTTOMRIGHT:
 
  378      GetGlobalColor(_T(
"BLUE3"), &c3);
 
  379      TextPoint.x = size.x - width - 1;
 
  380      TextPoint.y = GetDataBottom(size.y) - height;
 
  386  GetGlobalColor(_T(
"DASHB"), &c2);
 
  387  wxStringTokenizer tkz(text, _T(
"\n"));
 
  390  token = tkz.GetNextToken();
 
  391  while (token.Length()) {
 
  393      f = m_Properties->m_LabelFont.GetChosenFont();
 
  394      dc->GetTextExtent(token, &width, &height, NULL, NULL, &f);
 
  396      f = g_pFontLabel->GetChosenFont();
 
  397      dc->GetTextExtent(token, &width, &height, NULL, NULL, &f);
 
  399    dc->DrawText(token, TextPoint.x, TextPoint.y);
 
  400    TextPoint.y += height;
 
  401    token = tkz.GetNextToken();