Esempio n. 1
0
void
MapItemListRenderer::Draw(Canvas &canvas, const PixelRect rc,
                          const MarkerMapItem &item,
                          const DialogLook &dialog_look,
                          const MarkerLook &look)
{
  const PixelScalar line_height = rc.bottom - rc.top;

  const Marker &marker = item.marker;

  const RasterPoint pt(rc.left + line_height / 2,
                       rc.top + line_height / 2);

  look.icon.Draw(canvas, pt);

  const Font &name_font = *dialog_look.list.font_bold;
  const Font &small_font = *dialog_look.small_font;

  PixelScalar left = rc.left + line_height + Layout::FastScale(2);

  StaticString<256> buffer;
  buffer.Format(_T("%s #%d"), _("Marker"), item.id + 1);
  canvas.Select(name_font);
  canvas.DrawClippedText(left, rc.top + Layout::FastScale(2), rc, buffer);

  TCHAR time_buffer[32], timespan_buffer[32];
  FormatSignedTimeHHMM(time_buffer, TimeLocal(marker.time.GetSecondOfDay()));
  FormatTimespanSmart(timespan_buffer, BrokenDateTime::NowUTC() - marker.time);
  buffer.Format(_("dropped %s ago"), timespan_buffer);
  buffer.AppendFormat(_T(" (%s)"), time_buffer);
  canvas.Select(small_font);
  canvas.DrawClippedText(left,
                         rc.top + name_font.GetHeight() + Layout::FastScale(4),
                         rc, buffer);
}
Esempio n. 2
0
bool
DeviceDescriptor::ReadFlightList(RecordedFlightList &flight_list,
                                 OperationEnvironment &env)
{
  assert(borrowed);
  assert(port != nullptr);
  assert(driver != nullptr);
  assert(device != nullptr);

  StaticString<60> text;

  if (driver->HasPassThrough() && second_device != nullptr) {
    text.Format(_T("%s: %s."), _("Reading flight list"),
                second_driver->display_name);
    env.SetText(text);

    device->EnablePassThrough(env);
    return second_device->ReadFlightList(flight_list, env);
  } else {
    text.Format(_T("%s: %s."), _("Reading flight list"), driver->display_name);
    env.SetText(text);

    return device->ReadFlightList(flight_list, env);
  }
}
Esempio n. 3
0
void
ManagedFileListWidget::OnPaintItem(Canvas &canvas, const PixelRect rc,
                                   unsigned i)
{
  const FileItem &file = items[i];

  canvas.Select(row_renderer.GetFirstFont());
  row_renderer.DrawFirstRow(canvas, rc, file.name.c_str());

  canvas.Select(row_renderer.GetSecondFont());

  if (file.downloading) {
    StaticString<64> text;
    if (file.download_status.position < 0) {
      text = _("Queued");
    } else if (file.download_status.size > 0) {
      text.Format(_T("%s (%u%%)"), _("Downloading"),
                    unsigned(file.download_status.position * 100
                             / file.download_status.size));
    } else {
      TCHAR size[32];
      FormatByteSize(size, ARRAY_SIZE(size), file.download_status.position);
      text.Format(_T("%s (%s)"), _("Downloading"), size);
    }

    row_renderer.DrawRightFirstRow(canvas, rc, text);
  } else if (file.failed) {
    const TCHAR *text = _("Error");
    row_renderer.DrawRightFirstRow(canvas, rc, text);
  }

  row_renderer.DrawRightSecondRow(canvas, rc, file.last_modified.c_str());

  row_renderer.DrawSecondRow(canvas, rc, file.size.c_str());
}
Esempio n. 4
0
void
RenderGlidePolarInfo(Canvas &canvas, const PixelRect rc,
                     const ChartLook &chart_look,
                     const GlidePolar &glide_polar)
{
  canvas.Select(chart_look.label_font);

  StaticString<80> text;
  StaticString<20> value;
  canvas.SetBackgroundTransparent();

  FormatUserMass(glide_polar.GetTotalMass(), value.buffer(), true);

  int left = rc.left*0.8 + rc.right*0.2;

  text.Format(_T("%s: %s"), _("Mass"), value.c_str());
  canvas.DrawText(left,
                  rc.bottom - Layout::Scale(50),
                  text);

  double wl = glide_polar.GetWingLoading();
  if (wl != 0) {
    FormatUserWingLoading(wl, value.buffer(), true);

    text.Format(_T("%s: %s"), _("Wing loading"), value.c_str());

    canvas.DrawText(left,
                    rc.bottom - Layout::Scale(35),
                    text);
  }
}
Esempio n. 5
0
const tstring 
AirspaceAltitude::GetAsTextUnits(const bool concise) const
{
  StaticString<64> buffer;

  switch (type) {
  case AGL:
    if (!positive(altitude_above_terrain))
      buffer = _T("GND");
    else
      buffer.Format(_T("%d %s AGL"),
                    iround(Units::ToUserAltitude(altitude_above_terrain)),
                    Units::GetAltitudeName());
    break;
  case FL:
    buffer.Format(_T("FL%d"), (int)flight_level);
    break;
  case MSL:
    buffer.Format(_T("%d %s"), iround(Units::ToUserAltitude(altitude)),
                  Units::GetAltitudeName());
    break;
  case UNDEFINED:
  default:
    buffer.clear();
    break;
  }

  if (!concise && type != MSL && positive(altitude))
    buffer.AppendFormat(_T(" %d %s"), iround(Units::ToUserAltitude(altitude)),
                        Units::GetAltitudeName());

  return tstring(buffer);
}
Esempio n. 6
0
bool
DeviceDescriptor::DownloadFlight(const RecordedFlightInfo &flight,
                                 Path path,
                                 OperationEnvironment &env)
{
  assert(borrowed);
  assert(port != nullptr);
  assert(driver != nullptr);
  assert(device != nullptr);

  if (port == nullptr || driver == nullptr || device == nullptr)
    return false;

  StaticString<60> text;


  if (driver->HasPassThrough() && (second_device != nullptr)) {
    text.Format(_T("%s: %s."), _("Downloading flight log"),
                second_driver->display_name);
    env.SetText(text);

    device->EnablePassThrough(env);
    return second_device->DownloadFlight(flight, path, env);
  } else {
    text.Format(_T("%s: %s."), _("Downloading flight log"),
                driver->display_name);
    env.SetText(text);

    return device->DownloadFlight(flight, path, env);
  }
}
Esempio n. 7
0
bool
DeviceDescriptor::Declare(const struct Declaration &declaration,
                          const Waypoint *home,
                          OperationEnvironment &env)
{
  if (port == NULL)
    return false;

  SetBusy(true);

  StaticString<60> text;
  text.Format(_T("%s: %s."), _("Sending declaration"), driver->display_name);
  env.SetText(text);

  port->StopRxThread();

  bool result = device != NULL && device->Declare(declaration, home, env);

  if (device_blackboard->IsFLARM(index) && !IsDriver(_T("FLARM"))) {
    text.Format(_T("%s: FLARM."), _("Sending declaration"));
    env.SetText(text);
    FlarmDevice flarm(*port);
    result = flarm.Declare(declaration, home, env) || result;
  }

  port->StartRxThread();

  SetBusy(false);
  return result;
}
  gcc_pure
  const TCHAR *MakeMessage(const AbstractAirspace &airspace,
                           AirspaceWarning::State state,
                           const AirspaceInterceptSolution &solution) {
    if (state == AirspaceWarning::WARNING_INSIDE)
      buffer.Format(_T("%s: %s"), _("Inside airspace"), airspace.GetName());
    else
      buffer.Format(_T("%s: %s (%s)"), _("Near airspace"), airspace.GetName(),
                    FormatTimespanSmart(int(solution.elapsed_time),
                                        2).c_str());

    return buffer;
  }
Esempio n. 9
0
void
TaskManagerDialog::UpdateCaption()
{
  StaticString<128> title;
  if (task->GetName().empty())
    title.Format(_T("%s: %s"), _("Task Manager"),
                 tab_bar->GetButtonCaption(tab_bar->GetCurrentPage()));
  else
    title.Format(_T("%s: %s - %s"), _("Task Manager"),
                 task->GetName().c_str(),
                 tab_bar->GetButtonCaption(tab_bar->GetCurrentPage()));
  SetCaption(title);
}
Esempio n. 10
0
static void
UpdateButtons()
{
  StaticString<64> text;

  text.Format(_T("%s: %s"), _("Name"),
              global_wpt->name.empty()
              ? _("(blank)") : global_wpt->name.c_str());
  buttonName->SetCaption(text);

  text.Format(_T("%s: %s"), _("Comment"),
              global_wpt->comment.empty()
              ? _("(blank)") : global_wpt->comment.c_str());
  buttonComment->SetCaption(text);
}
Esempio n. 11
0
static void
UpdateCaption(WndForm *form, const Waypoint *waypoint)
{
  StaticString<256> buffer;
  buffer.Format(_T("%s: %s"), _("Waypoint"), waypoint->name.c_str());

  const char *key = nullptr;
  switch (waypoint->file_num) {
  case 1:
    key = ProfileKeys::WaypointFile;
    break;
  case 2:
    key = ProfileKeys::AdditionalWaypointFile;
    break;
  case 3:
    key = ProfileKeys::WatchedWaypointFile;
    break;
  }

  if (key != nullptr) {
    const TCHAR *filename = Profile::GetPathBase(key);
    if (filename != nullptr)
      buffer.AppendFormat(_T(" (%s)"), filename);
  }

  form->SetCaption(buffer);
}
Esempio n. 12
0
static void
Draw(Canvas &canvas, PixelRect rc,
     const ThermalMapItem &item,
     RoughTimeDelta utc_offset,
     const TwoTextRowsRenderer &row_renderer,
     const MapLook &look)
{
  const unsigned line_height = rc.GetHeight();
  const unsigned text_padding = Layout::GetTextPadding();

  const ThermalSource &thermal = item.thermal;

  const PixelPoint pt(rc.left + line_height / 2,
                      rc.top + line_height / 2);

  look.thermal_source_icon.Draw(canvas, pt);

  rc.left += line_height + text_padding;

  row_renderer.DrawFirstRow(canvas, rc, _("Thermal"));

  StaticString<256> buffer;
  TCHAR lift_buffer[32];
  FormatUserVerticalSpeed(thermal.lift_rate, lift_buffer, 32);

  int timespan = BrokenDateTime::NowUTC().GetSecondOfDay() - (int)thermal.time;
  if (timespan < 0)
    timespan += 24 * 60 * 60;

  buffer.Format(_T("%s: %s - left %s ago (%s)"),
                _("Avg. lift"), lift_buffer,
                FormatTimespanSmart(timespan).c_str(),
                FormatLocalTimeHHMM((int)thermal.time, utc_offset).c_str());
  row_renderer.DrawSecondRow(canvas, rc, buffer);
}
Esempio n. 13
0
void
WindArrowRenderer::Draw(Canvas &canvas, const Angle screen_angle,
                        const SpeedVector wind, const PixelPoint pos,
                        const PixelRect rc, WindArrowStyle arrow_style)
{
  // Draw arrow (and tail)

  const unsigned length = uround(Quadruple(wind.norm));
  DrawArrow(canvas, pos, wind.bearing - screen_angle, length, arrow_style);

  // Draw wind speed label

  StaticString<12> buffer;
  buffer.Format(_T("%i"), iround(Units::ToUserWindSpeed(wind.norm)));

  canvas.SetTextColor(COLOR_BLACK);
  canvas.Select(*look.font);

  const unsigned offset = uround(M_SQRT2 * wind.norm);
  BulkPixelPoint label[] = {
    { 18, -26 - int(offset) },
  };
  PolygonRotateShift(label, ARRAY_SIZE(label),
                     pos, wind.bearing - screen_angle);

  TextInBoxMode style;
  style.align = TextInBoxMode::Alignment::CENTER;
  style.vertical_position = TextInBoxMode::VerticalPosition::CENTERED;
  style.shape = LabelShape::OUTLINED;

  TextInBox(canvas, buffer, label[0].x, label[0].y, style, rc);
}
Esempio n. 14
0
static void
UpdateCaption(const TCHAR *waypoint_name, int8_t file_num)
{
    StaticString<256> buffer;
    buffer.Format(_T("%s: %s"), _("Waypoint"), waypoint_name);

    if (file_num > 0) {
        const TCHAR *key;
        switch (file_num) {
        case 1:
            key = szProfileWaypointFile;
            break;
        case 2:
            key = szProfileAdditionalWaypointFile;
            break;
        case 3:
            key = szProfileWatchedWaypointFile;
            break;
        }

        const TCHAR *filename = Profile::GetPathBase(key);
        if (filename != NULL)
            buffer.AppendFormat(_T(" (%s)"), filename);
    }

    wf->SetCaption(buffer);
}
Esempio n. 15
0
void
TabMenuControl::SetCurrentPage(unsigned page)
{
  assert(page < buttons.size());

  if (!pager.ClickPage(page))
    return;

  if (page == GetMenuPage()) {
    form.SetCaption(caption);
    const MenuTabIndex di = FindPage(last_content_page);
    this->GetTabMenuDisplay()->SetSelectedIndex(di);

  } else {
    const PageItem& theitem = GetPageItem(page);
    SetLastContentPage(page);
    const MainMenuButton &main_button =
      GetMainMenuButton(theitem.main_menu_index);
    StaticString<128> caption;
    caption.Format(_T("%s > %s"),
                   gettext(main_button.caption),
                   gettext(theitem.menu_caption));
    form.SetCaption(caption);
  }
}
Esempio n. 16
0
static void
NewClicked(gcc_unused WndButton &button)
{
  Plane plane = CommonInterface::GetComputerSettings().plane;

  while (dlgPlaneDetailsShowModal(*(SingleWindow*)dialog->get_root_owner(), plane)) {
    if (plane.registration.empty()) {
      MessageBoxX(_("Please enter the registration of the plane!"),
                  _("Error"), MB_OK);
      continue;
    }

    StaticString<42> filename(plane.registration);
    filename += _T(".xcp");

    StaticString<MAX_PATH> path;
    LocalPath(path.buffer(), filename);

    if (File::Exists(path)) {
      StaticString<256> tmp;
      tmp.Format(_("A plane profile \"%s\" already exists. "
                   "Do you want to overwrite it?"),
                   filename.c_str());
      if (MessageBoxX(tmp, _("Overwrite"), MB_YESNO) != IDYES)
        continue;
    }

    PlaneGlue::WriteFile(plane, path);
    UpdateList();
    break;
  }
}
Esempio n. 17
0
void
TaskListPanel::DeleteTask()
{
  const unsigned cursor_index = GetList().GetCursorIndex();
  if (cursor_index >= task_store->Size())
    return;

  const TCHAR *path = task_store->GetPath(cursor_index);
  if (StringEndsWithIgnoreCase(path, _T(".cup"))) {
    ShowMessageBox(_("Can't delete .CUP files"), _("Error"),
                   MB_OK | MB_ICONEXCLAMATION);
    return;
  }

  const TCHAR *fname = task_store->GetName(cursor_index);

  StaticString<1024> text;
  text.Format(_T("%s\n(%s)"), _("Delete the selected task?"), fname);
  if (ShowMessageBox(text.c_str(), _("Task Browser"),
                  MB_YESNO | MB_ICONQUESTION) != IDYES)
    return;

  File::Delete(path);

  task_store->Scan(more);
  RefreshView();
}
Esempio n. 18
0
bool
FlarmDevice::SetRange(unsigned range, OperationEnvironment &env)
{
  StaticString<32> buffer;
  buffer.Format(_T("%d"), range);
  return SetConfig("RANGE", buffer, env);
}
Esempio n. 19
0
bool
NMEALogger::Start()
{
  if (writer != nullptr)
    return true;

  BrokenDateTime dt = BrokenDateTime::NowUTC();
  assert(dt.IsPlausible());

  StaticString<64> name;
  name.Format(_T("%04u-%02u-%02u_%02u-%02u.nmea"),
              dt.year, dt.month, dt.day,
              dt.hour, dt.minute);

  const auto logs_path = MakeLocalPath(_T("logs"));

  const auto path = AllocatedPath::Build(logs_path, name);
  writer = new TextWriter(path, false);
  if (writer == nullptr)
    return false;

  if (!writer->IsOpen()) {
    delete writer;
    writer = nullptr;
    return false;
  }

  return true;
}
Esempio n. 20
0
inline void
WifiListWidget::Connect()
{
  if (!EnsureConnected()) {
    ShowMessageBox(_T("Network failure"), _("Connect"), MB_OK);
    return;
  }

  const unsigned i = GetList().GetCursorIndex();
  if (i >= networks.size())
    return;

  const auto &info = networks[i];
  if (info.id < 0) {
    const auto ssid = info.ssid;

    StaticString<256> caption;
    caption.Format(_("Passphrase of network '%s'"), ssid.c_str());

    StaticString<32> passphrase;
    passphrase.clear();
    if (info.security == OPEN_SECURITY)
      passphrase.clear();
    else if (!TextEntryDialog(passphrase, caption, false))
      return;

    if (!WifiConnect(info.security, wpa_supplicant, info.ssid, passphrase))
      ShowMessageBox(_T("Network failure"), _("Connect"), MB_OK);
  } else {
    if (!wpa_supplicant.RemoveNetwork(info.id) || !wpa_supplicant.SaveConfig())
      ShowMessageBox(_T("Error"), _("Remove"), MB_OK);
  }

  UpdateList();
}
Esempio n. 21
0
bool
FlarmDevice::SetRange(unsigned range)
{
  StaticString<32> buffer;
  buffer.Format(_T("%d"), range);
  return SetConfig("RANGE", buffer);
}
Esempio n. 22
0
inline void
PlaneListWidget::NewClicked()
{
  Plane plane = CommonInterface::GetComputerSettings().plane;

  while (dlgPlaneDetailsShowModal(plane)) {
    if (plane.registration.empty()) {
      ShowMessageBox(_("Please enter the registration of the plane!"),
                  _("Error"), MB_OK);
      continue;
    }

    StaticString<42> filename(plane.registration);
    filename += _T(".xcp");

    StaticString<MAX_PATH> path;
    LocalPath(path.buffer(), filename);

    if (File::Exists(path)) {
      StaticString<256> tmp;
      tmp.Format(_("Plane \"%s\" already exists. "
                   "Overwrite it?"),
                   plane.registration.c_str());
      if (ShowMessageBox(tmp, _("Overwrite"), MB_YESNO) != IDYES)
        continue;
    }

    PlaneGlue::WriteFile(plane, path);
    UpdateList();
    break;
  }
}
Esempio n. 23
0
void
TaskListPanel::LoadTask()
{
  const OrderedTask* orig = get_cursor_task();
  if (orig == nullptr)
    return;

  StaticString<1024> text;
  text.Format(_T("%s\n(%s)"), _("Load the selected task?"),
              get_cursor_name());

  if (ShowMessageBox(text.c_str(), _("Task Browser"),
                  MB_YESNO | MB_ICONQUESTION) != IDYES)
    return;

  // create new task first to guarantee pointers are different
  OrderedTask* temptask = orig->Clone(CommonInterface::GetComputerSettings().task);
  delete *active_task;
  *active_task = temptask;

  const unsigned cursor_index = GetList().GetCursorIndex();
  (*active_task)->SetName(StaticString<64>(task_store->GetName(cursor_index)));

  RefreshView();
  *task_modified = true;

  dialog.SwitchToEditTab();
}
Esempio n. 24
0
bool
FlarmDevice::SetBaudRate(unsigned baud_id, OperationEnvironment &env)
{
  StaticString<32> buffer;
  buffer.Format(_T("%u"), baud_id);
  return SetConfig("BAUD", buffer, env);
}
Esempio n. 25
0
void
PlaneListWidget::OnPaintItem(Canvas &canvas, const PixelRect rc, unsigned i)
{
  assert(i < list.size());

  const DialogLook &look = UIGlobals::GetDialogLook();
  const Font &name_font = *look.list.font_bold;
  const Font &details_font = *look.small_font;

  canvas.Select(name_font);

  if (Profile::GetPathIsEqual("PlanePath", list[i].path)) {
    StaticString<256> buffer;
    buffer.Format(_T("%s - %s"), list[i].name.c_str(), _("Active"));
    canvas.DrawClippedText(rc.left + Layout::GetTextPadding(),
                           rc.top + Layout::GetTextPadding(), rc, buffer);
  } else
    canvas.DrawClippedText(rc.left + Layout::GetTextPadding(),
                           rc.top + Layout::GetTextPadding(), rc, list[i].name);

  canvas.Select(details_font);

  canvas.DrawClippedText(rc.left + Layout::GetTextPadding(),
                         rc.top + name_font.GetHeight() + Layout::FastScale(4),
                         rc, list[i].path);
}
Esempio n. 26
0
void
ShowPortMonitor(SingleWindow &parent, const DialogLook &dialog_look,
                const TerminalLook &terminal_look,
                DeviceDescriptor &device)
{
  /* create the dialog */

  WindowStyle dialog_style;
  dialog_style.Hide();
  dialog_style.ControlParent();

  TCHAR buffer[64];
  StaticString<128> caption;
  caption.Format(_T("%s: %s"), _("Port monitor"),
                 device.GetConfig().GetPortName(buffer, ARRAY_SIZE(buffer)));

  WndForm dialog(dialog_look);
  dialog.Create(parent, caption, dialog_style);

  ContainerWindow &client_area = dialog.GetClientAreaWindow();

  PortMonitorGlue glue(device, terminal_look);

  ButtonPanel buttons(client_area, dialog_look);
  buttons.Add(_("Close"), dialog, mrOK);
  glue.CreateButtons(buttons);
  glue.CreateTerminal(client_area, buttons.UpdateLayout());

  /* run it */

  dialog.ShowModal();
}
Esempio n. 27
0
static void
OnPlaneListPaint(Canvas &canvas, const PixelRect rc, unsigned i)
{
  assert(i < list.size());

  const Font &name_font = Fonts::map_bold;
  const Font &details_font = Fonts::map_label;

  canvas.Select(name_font);

  if (Profile::GetPathIsEqual(_T("PlanePath"), list[i].path)) {
    StaticString<256> buffer;
    buffer.Format(_T("%s - %s"), list[i].name.c_str(), _("Active"));
    canvas.text_clipped(rc.left + Layout::FastScale(2),
                        rc.top + Layout::FastScale(2), rc, buffer);
  } else
    canvas.text_clipped(rc.left + Layout::FastScale(2),
                        rc.top + Layout::FastScale(2), rc, list[i].name);

  canvas.Select(details_font);

  canvas.text_clipped(rc.left + Layout::FastScale(2),
                      rc.top + name_font.GetHeight() + Layout::FastScale(4),
                      rc, list[i].path);
}
Esempio n. 28
0
static void
UpdateCaption()
{
  StaticString<128> tmp;
  tmp.Format(_T("%s: %s"), _("Plane Details"), plane.registration.c_str());
  dialog->SetCaption(tmp);
}
Esempio n. 29
0
static void
SetTitle()
{
  StaticString<128> title;
  title.Format(_T("%s: %s"), _("Status"),
               wTabBar->GetButtonCaption((wTabBar->GetCurrentPage())));
  wf->SetCaption(title);
}
Esempio n. 30
0
static void
UpdateCaption()
{
  StaticString<128> tmp;
  tmp.Format(_T("%s: %s"), _("Plane Details"),
             GetFormValueString(*dialog, _T("Registration")));
  dialog->SetCaption(tmp);
}