예제 #1
0
  /**
   * Calculate average from samples
   *
   * @return Average value in buffer
   */
  gcc_pure
  fixed Average() const {
    assert(!x.empty());

    fixed y = fixed_zero;
    for (unsigned i = 0; i < x.size(); i++)
      y += x[i];

    return y / x.size();
  }
예제 #2
0
  virtual void
  EndFan()
  {
    if (fans.full())
      return;

    // remove unnecessary inclusion of origin if next and last points are identical
    unsigned start = 0;
    const size_t gsize = g.size();
    if (gsize > 2 && g[gsize - 1] == g[1])
      start = 1;

    if (gsize < start + 3)
      return;

    // Perform clipping on the GeoPointVector (Result: clipped)
    unsigned size = clip.ClipPolygon(clipped, g.raw() + start, gsize - start);
    // With less than three points we can't draw a polygon
    if (size < 3)
      return;

    // Work directly on the RasterPoints in the fans vector
    fans.Append(size);

    // Convert GeoPoints to RasterPoints
    for (unsigned i = 0; i < size; ++i)
      fans.Append(proj.GeoToScreen(clipped[i]));
  }
예제 #3
0
static void
NextPage(int Step)
{
    assert(waypoint);

    int last_page = 2 + images.size();
    do {
        page += Step;
        if (page < 0)
            page = last_page;
        else if (page > last_page)
            page = 0;
        // skip wDetails frame, if there are no details
    } while (page == 1 &&
#ifdef ANDROID
             waypoint->files_external.empty() &&
#endif
             waypoint->details.empty());

    wInfo->SetVisible(page == 0);
    wDetails->SetVisible(page == 1);
    wCommand->SetVisible(page == 2);
    wImage->SetVisible(page >= 3);
    zoom = 0;
    wMagnify->SetVisible(page >= 3);
    wMagnify->SetEnabled(true);
    wShrink->SetVisible(page >= 3);
    wShrink->SetEnabled(false);
}
예제 #4
0
파일: State.hpp 프로젝트: macsux/XCSoar
  /**
   * Looks up an item in the traffic list.
   *
   * @param name the name or call sign
   * @return the FLARM_TRAFFIC pointer, NULL if not found
   */
  const FLARM_TRAFFIC *FindTraffic(const TCHAR *name) const {
    for (unsigned i = 0; i < traffic.size(); i++)
      if (traffic[i].name.equals(name))
        return &traffic[i];

    return NULL;
  }
예제 #5
0
 StaticArray<T>::StaticArray(const StaticArray& sa)
 {
     m_Size = sa.size();
     m_MasPoint = new T[m_Size];
     for (uint32_t i = 0; i < m_Size; i++)
         m_MasPoint[i] = sa[i];
 }
예제 #6
0
파일: State.hpp 프로젝트: macsux/XCSoar
  /**
   * Looks up an item in the traffic list.
   *
   * @param id FLARM id
   * @return the FLARM_TRAFFIC pointer, NULL if not found
   */
  FLARM_TRAFFIC *FindTraffic(FlarmId id) {
    for (unsigned i = 0; i < traffic.size(); i++)
      if (traffic[i].id == id)
        return &traffic[i];

    return NULL;
  }
예제 #7
0
static TaskPointFactoryType
GetRandomType(const LegalPointSet &l)
{
    StaticArray<TaskPointFactoryType, LegalPointSet::N> types;
    l.CopyTo(std::back_inserter(types));
    return types[(rand() % types.size())];
}
예제 #8
0
    /**
     * On devices without a touch screen, enable button selection with
     * KEY_LEFT / KEY_RIGHT.  That allows navigating a ListControl while
     * allowing the user to select an action on a list item.
     */
    void EnableCursorSelection(unsigned _index=0) {
        assert(selected_index < 0);
        assert(_index < buttons.size());

        selected_index = _index;
        buttons[selected_index]->SetSelected(true);
    }
int
FlarmDetails::LookupSecondaryIndex(FlarmId id)
{
  for (unsigned i = 0; i < FLARM_Names.size(); i++)
    if (FLARM_Names[i].ID == id)
      return i;

  return -1;
}
예제 #10
0
int main()
{
  // print my name and this assignment's title
  cout << "Lab 3b, The \"Write A Static Array Class Template\" Program \n";
  cout << "Programmer: Licong Wang\n";
  cout << "Editor(s) used: Visual studio 2013\n";
  cout << "Compiler(s) used:  Microsoft c++ complier\n";
  cout << "File: " << __FILE__ << endl;
  cout << "Complied: " << __DATE__ << " at " << __TIME__ << endl << endl;

  StaticArray<int, 100> a;
  string buf;
  int key;
  int value;

    while (true)
    {
      cout << "Input an index and a value [Q to quit]: ";
    
      cin >> buf;
      if (buf == "Q" || buf == "q")
        break;
      key = atoi(buf.c_str());

      cin >> buf;
      value = atoi(buf.c_str());
      a[key] = value;
    }

  cout << "\nI stored this many values : " << a.size() << endl;
  cout << "These values are:" << endl;

  vector<int> keys = a.keys();
  for (int i = 0; i < keys.size(); i++)
    cout << keys[i] << " " << a[keys[i]] << endl;

  while (true)
  {
    cout << "Input an index for me to look up [Q to quit]: ";
    cin >> buf;

    if (buf == "Q" || buf == "q")
      break;
    else
    {
      key = atoi(buf.c_str());
      if (a.containsKey(key))
        cout << "Found it -- the value stored at " << key << " is " << a[key] << endl;
      else
        cout << "I didn't find it" << endl;
    }
  }
  
  cout << "\nPress ENTER to continue.\n";
  cin.ignore();  // prevent cin.get() from getting a new line from previous cin
  cin.get();
}
int
FlarmDetails::LookupSecondaryIndex(const TCHAR *cn)
{
  for (unsigned i = 0; i < FLARM_Names.size(); i++)
    if (FLARM_Names[i].Name.equals(cn))
      return i;

  return -1;
}
예제 #12
0
void
QuickMenu::UpdateCaption()
{
  StaticString<32> buffer;
  unsigned pageSize = grid_view.GetNumColumns() * grid_view.GetNumRows();
  unsigned lastPage = buttons.size() / pageSize;
  buffer.Format(_T("Quick Menu  %d/%d"),
                grid_view.GetCurrentPage() + 1, lastPage + 1);
  dialog.SetCaption(buffer);
}
예제 #13
0
    void assignArray(const StaticArray<T>& array) {
      _size = 0;

      if (_data) {
        delete[] _data;
        _data = 0;
      }

      initWithData(array.cArray(), array.size());
    }
예제 #14
0
파일: State.hpp 프로젝트: macsux/XCSoar
  void Refresh(fixed Time) {
    available.Expire(Time, fixed(10));
    if (!available)
      traffic.clear();

    for (unsigned i = traffic.size(); i-- > 0;)
      if (!traffic[i].Refresh(Time))
        traffic.quick_remove(i);

    NewTraffic = false;
  }
예제 #15
0
  void Show(const PixelRect &rc) override {
    const Layout layout(rc, geometry);

    RowFormWidget::Show(layout.form);

    copy_button.MoveAndShow(layout.copy_button);
    paste_button.MoveAndShow(layout.paste_button);
    close_button.MoveAndShow(layout.close_button);

    for (unsigned i = 0; i < previews.size(); ++i)
      previews[i].MoveAndShow(layout.info_boxes.positions[i]);
  }
예제 #16
0
uint8_t writeRegister(Spi& pSpi, FiveByteRegister pRegister, StaticArray<uint8_t,5> pValue)
{
    uint8_t cmd = CMD_W_REGISTER | (pRegister & MASK_REGISTER_CMD);

    pSpi.chipSelect(true);
    uint8_t status = pSpi.transfer(cmd);
    for (size_t i = 0 ; i < pValue.size() ; ++i) {
        pSpi.transfer(pValue[i]);
    }
    pSpi.chipSelect(false);
    return status;
}
예제 #17
0
StaticArray<uint8_t,5> readRegister(Spi& pSpi, FiveByteRegister pRegister)
{
    StaticArray<uint8_t,5> value;
    uint8_t cmd = CMD_R_REGISTER | (pRegister & MASK_REGISTER_CMD);

    pSpi.chipSelect(true);
    pSpi.transfer(cmd);
    for (size_t i = 0 ; i < value.size()  ; ++i) {
        value[i] = pSpi.transfer(CMD_NOP);
    }
    pSpi.chipSelect(false);

    return value;
}
unsigned
FlarmDetails::FindIdsByCallSign(const TCHAR *cn, const FlarmId *array[],
                                unsigned size)
{
  unsigned count = FlarmNet::FindIdsByCallSign(cn, array, size);

  for (unsigned i = 0; i < FLARM_Names.size() && count < size; i++) {
    if (FLARM_Names[i].Name.equals(cn)) {
      array[count] = &FLARM_Names[i].ID;
      count++;
    }
  }

  return count;
}
예제 #19
0
bool
QuickMenu::SetFocus()
{
  unsigned numColumns = grid_view.GetNumColumns();
  unsigned pageSize = numColumns * grid_view.GetNumRows();
  unsigned lastPage = buttons.size() / pageSize;
  unsigned currentPage = grid_view.GetCurrentPage();
  unsigned currentPageSize = currentPage == lastPage
    ? buttons.size() % pageSize
    : pageSize;
  unsigned centerCol = currentPageSize < numColumns
    ? currentPageSize / 2
    : numColumns / 2;
  unsigned centerRow = currentPageSize / numColumns / 2;
  unsigned centerPos = currentPage
    * pageSize + centerCol + centerRow * numColumns;

  if (centerPos >= buttons.size())
    return false;

  buttons[centerPos]->SetFocus();
  grid_view.RefreshLayout();
  return true;
}
void
FlarmDetails::SaveSecondary()
{
  TextWriter *writer = CreateDataTextFile(_T("xcsoar-flarm.txt"));
  if (writer == NULL)
    return;

  TCHAR id[16];

  for (unsigned i = 0; i < FLARM_Names.size(); i++)
    writer->printfln(_T("%s=%s"),
                     FLARM_Names[i].ID.format(id),
                     FLARM_Names[i].Name.c_str());

  delete writer;
}
예제 #21
0
void
InfoBoxesConfigWidget::SetCurrentInfoBox(unsigned _current_preview)
{
  assert(_current_preview < previews.size());

  if (_current_preview == current_preview)
    return;

  previews[current_preview].Invalidate();
  current_preview = _current_preview;
  previews[current_preview].Invalidate();

  LoadValueEnum(INFOBOX, current_preview);

  RefreshEditContent();
}
예제 #22
0
파일: Reference.hpp 프로젝트: DRIZO/xcsoar
  /**
   * Check if the referenced Window still exists, and return it.
   * Returns NULL if the referenced Window does not exist anymore.
   */
  Window *Get(const ContainerWindow &root) const {
    assert(window != NULL);

    const ContainerWindow *parent = &root;
    for (int i = parents.size() - 1; i >= 0; --i) {
      const ContainerWindow &current = *parents[i];
      if (!parent->HasChild(current))
        return NULL;

      parent = &current;
    }

    if (!parent->HasChild(*window))
      return NULL;

    return window;
  }
예제 #23
0
void
WaypointDetailsWidget::OnImagePaint(gcc_unused Canvas &canvas,
                                    gcc_unused const PixelRect &rc)
{
  canvas.ClearWhite();
  if (page >= 3 && page < 3 + (int)images.size()) {
    Bitmap &img = images[page-3];
    static constexpr int zoom_factors[] = { 1, 2, 4, 8, 16, 32 };
    RasterPoint img_pos, screen_pos;
    PixelSize screen_size;
    PixelSize img_size = img.GetSize();
    auto scale = std::min((fixed)canvas.GetWidth() / (fixed)img_size.cx,
                          (fixed)canvas.GetHeight() / (fixed)img_size.cy) *
      zoom_factors[zoom];

    // centered image and optionally zoomed into the center of the image
    auto scaled_size = img_size.cx * scale;
    if (scaled_size <= (fixed)canvas.GetWidth()) {
      img_pos.x = 0;
      screen_pos.x = (int) (((fixed)canvas.GetWidth() - scaled_size) / 2);
      screen_size.cx = (int) scaled_size;
    } else {
      scaled_size = (fixed)canvas.GetWidth() / scale;
      img_pos.x = (int) (((fixed)img_size.cx - scaled_size) / 2);
      img_size.cx = (int) scaled_size;
      screen_pos.x = 0;
      screen_size.cx = canvas.GetWidth();
    }
    scaled_size = img_size.cy * scale;
    if (scaled_size <= (fixed)canvas.GetHeight()) {
      img_pos.y = 0;
      screen_pos.y = (int) (((fixed)canvas.GetHeight() - scaled_size) / 2);
      screen_size.cy = (int) scaled_size;
    } else {
      scaled_size = (fixed)canvas.GetHeight() / scale;
      img_pos.y = (int) (((fixed)img_size.cy - scaled_size) / 2);
      img_size.cy = (int) scaled_size;
      screen_pos.y = 0;
      screen_size.cy = canvas.GetHeight();
    }
    canvas.Stretch(screen_pos.x, screen_pos.y, screen_size.cx, screen_size.cy,
                   img, img_pos.x, img_pos.y, img_size.cx, img_size.cy);
  }
}
예제 #24
0
static void
OnImagePaint(gcc_unused WndOwnerDrawFrame *Sender, Canvas &canvas)
{
    canvas.ClearWhite();
    if (page >= 3 && page < 3 + (int)images.size()) {
        Bitmap &img = images[page-3];
        static const int zoom_factors[] = { 1, 2, 4, 8, 16, 32 };
        RasterPoint img_pos, screen_pos;
        PixelSize screen_size;
        PixelSize img_size = img.GetSize();
        fixed scale = std::min((fixed)canvas.get_width() / (fixed)img_size.cx,
                               (fixed)canvas.get_height() / (fixed)img_size.cy) *
                      zoom_factors[zoom];

        // centered image and optionally zoomed into the center of the image
        fixed scaled_size = img_size.cx * scale;
        if (scaled_size <= (fixed)canvas.get_width()) {
            img_pos.x = 0;
            screen_pos.x = (int) (((fixed)canvas.get_width() - scaled_size) / 2);
            screen_size.cx = (int) scaled_size;
        } else {
            scaled_size = (fixed)canvas.get_width() / scale;
            img_pos.x = (int) (((fixed)img_size.cx - scaled_size) / 2);
            img_size.cx = (int) scaled_size;
            screen_pos.x = 0;
            screen_size.cx = canvas.get_width();
        }
        scaled_size = img_size.cy * scale;
        if (scaled_size <= (fixed)canvas.get_height()) {
            img_pos.y = 0;
            screen_pos.y = (int) (((fixed)canvas.get_height() - scaled_size) / 2);
            screen_size.cy = (int) scaled_size;
        } else {
            scaled_size = (fixed)canvas.get_height() / scale;
            img_pos.y = (int) (((fixed)img_size.cy - scaled_size) / 2);
            img_size.cy = (int) scaled_size;
            screen_pos.y = 0;
            screen_size.cy = canvas.get_height();
        }
        canvas.Stretch(screen_pos.x, screen_pos.y, screen_size.cx, screen_size.cy,
                       img, img_pos.x, img_pos.y, img_size.cx, img_size.cy);
    }
}
예제 #25
0
void
InfoBoxesConfigWidget::OnPaste()
{
  if (clipboard_size == 0)
    return;

  if(ShowMessageBox(_("Overwrite?"), _("InfoBox paste"),
                 MB_YESNO | MB_ICONQUESTION) != IDYES)
    return;

  for (unsigned item = 0; item < clipboard_size; item++) {
    InfoBoxFactory::Type content = clipboard.contents[item];
    if (content >= InfoBoxFactory::NUM_TYPES)
      continue;

    data.contents[item] = content;

    if (item < previews.size())
      previews[item].Invalidate();
  }

  RefreshEditContent();
}
예제 #26
0
void
TerrainXSRenderer::Draw(Canvas &canvas, const ChartRenderer &chart, const short *elevations) const
{
  const fixed max_distance = chart.GetXMax();

  StaticArray<RasterPoint, CrossSectionRenderer::NUM_SLICES + 2> points;

  canvas.SelectNullPen();

  RasterBuffer::TerrainType last_type = RasterBuffer::TerrainType::UNKNOWN;
  fixed last_distance = fixed(0);

  for (unsigned j = 0; j < CrossSectionRenderer::NUM_SLICES; ++j) {
    const fixed distance_factor =
        fixed(j) / (CrossSectionRenderer::NUM_SLICES - 1);
    const fixed distance = distance_factor * max_distance;

    short h = elevations[j];
    RasterBuffer::TerrainType type = RasterBuffer::GetTerrainType(h);

    if (type == RasterBuffer::TerrainType::WATER)
      h = 0;

    // Close and paint polygon
    if (j != 0 &&
        type != last_type &&
        last_type != RasterBuffer::TerrainType::UNKNOWN) {
      const fixed center_distance = (distance + last_distance) / 2;
      points.append() = chart.ToScreen(center_distance, fixed(0));
      points.append() = chart.ToScreen(center_distance, fixed(-500));

      DrawPolygon(canvas, last_type, points.begin(), points.size());
    }

    if (type != RasterBuffer::TerrainType::UNKNOWN) {
      if (j == 0) {
        // Start first polygon
        points.append() = chart.ToScreen(distance, fixed(-500));
        points.append() = chart.ToScreen(distance, fixed(h));
      } else if (type != last_type) {
        // Start new polygon
        points.clear();

        const fixed center_distance = (distance + last_distance) / 2;
        points.append() = chart.ToScreen(center_distance, fixed(-500));
        points.append() = chart.ToScreen(center_distance, fixed(0));
      }

      if (j + 1 == CrossSectionRenderer::NUM_SLICES) {
        // Close and paint last polygon
        points.append() = chart.ToScreen(distance, fixed(h));
        points.append() = chart.ToScreen(distance, fixed(-500));

        DrawPolygon(canvas, type, points.begin(), points.size());
      } else if (type == last_type && j != 0) {
        // Add single point to polygon
        points.append() = chart.ToScreen(distance, fixed(h));
      }
    }

    last_type = type;
    last_distance = distance;
  }
}
예제 #27
0
 unsigned size() const {
   return items.size();
 }
예제 #28
0
void
WaypointDetailsWidget::Prepare(ContainerWindow &parent, const PixelRect &rc)
{
  for (const auto &i : waypoint.files_embed) {
    if (images.full())
      break;

    try {
      if (!images.append().LoadFile(LocalPath(i.c_str())))
        images.shrink(images.size() - 1);
    } catch (const std::exception &e) {
      LogFormat("Failed to load %s: %s",
                (const char *)NarrowPathName(Path(i.c_str())),
                e.what());
      images.shrink(images.size() - 1);
    }
  }

  const Layout layout(rc, waypoint);

  WindowStyle dock_style;
  dock_style.Hide();
  dock_style.ControlParent();

  WindowStyle button_style;
  button_style.Hide();
  button_style.TabStop();

  if (allow_navigation)
    goto_button.Create(parent, look.button, _("GoTo"), layout.goto_button,
                       button_style, *this, GOTO);

  if (!images.empty()) {
    magnify_button.Create(parent, layout.magnify_button, button_style,
                          new SymbolButtonRenderer(look.button, _T("+")),
                          *this, MAGNIFY);
    shrink_button.Create(parent, layout.shrink_button, button_style,
                         new SymbolButtonRenderer(look.button, _T("-")),
                         *this, SHRINK);
  }

  if (allow_navigation) {
    previous_button.Create(parent, layout.previous_button, button_style,
                           new SymbolButtonRenderer(look.button, _T("<")),
                           *this, PREVIOUS);
    next_button.Create(parent, layout.next_button, button_style,
                       new SymbolButtonRenderer(look.button, _T(">")),
                       *this, NEXT);
  }

  close_button.Create(parent, look.button, _("Close"), layout.close_button,
                      button_style, dialog, mrOK);

  info_dock.Create(parent, layout.main, dock_style);
  info_dock.SetWidget(&info_widget);

  details_panel.Create(parent, look, layout.main, dock_style);
  details_text.Create(details_panel, layout.details_text);
  details_text.SetFont(look.text_font);
  details_text.SetText(waypoint.details.c_str());

#ifdef HAVE_RUN_FILE
  const unsigned num_files = std::distance(waypoint.files_external.begin(),
                                           waypoint.files_external.end());
  if (num_files > 0) {
    file_list.Create(details_panel, layout.file_list,
                     WindowStyle(), layout.file_list_item_height);
    file_list.SetItemRenderer(&file_list_handler);
    file_list.SetCursorHandler(&file_list_handler);
    file_list.SetLength(num_files);
  }
#endif

  commands_dock.Create(parent, layout.main, dock_style);
  commands_dock.SetWidget(&commands_widget);

  if (!images.empty())
    image_window.Create(parent, layout.main, dock_style,
                        [this](Canvas &canvas, const PixelRect &rc){
                          OnImagePaint(canvas, rc);
                        });

  last_page = 2 + images.size();
}
예제 #29
0
 unsigned GetSize() const {
   return buttons.size();
 }
예제 #30
0
 unsigned GetSize() const {
   return children.size();
 }