Esempio n. 1
0
PixelSize
Font::TextSize(const TCHAR *text) const
{
  AnyCanvas canvas;
  canvas.Select(*this);
  return canvas.CalcTextSize(text);
}
Esempio n. 2
0
unsigned
WndFrame::GetTextHeight() const
{
  PixelRect rc = GetClientRect();
  const int padding = Layout::GetTextPadding();
  rc.Grow(-padding);

  AnyCanvas canvas;
  canvas.Select(look.text_font);

  return text_renderer.GetHeight(canvas, rc, text.c_str());
}
Esempio n. 3
0
unsigned
WndFrame::GetTextHeight()
{
  PixelRect rc = get_client_rect();
  ::InflateRect(&rc, -2, -2); // todo border width

  AnyCanvas canvas;
  canvas.Select(*font);
  canvas.formatted_text(&rc, text.c_str(), mCaptionStyle | DT_CALCRECT);

  return rc.bottom - rc.top;
}
Esempio n. 4
0
void
Font::CalculateHeights()
{
  AnyCanvas canvas;
  canvas.Select(*this);

  TEXTMETRIC tm;
  ::GetTextMetrics(canvas, &tm);

  height = tm.tmHeight;
  ascent_height = tm.tmAscent;

  if (IsAltair()) {
    // JMW: don't know why we need this in GNAV, but we do.

    BufferCanvas buffer(canvas, tm.tmAveCharWidth, tm.tmHeight);
    const HWColor white = buffer.map(COLOR_WHITE);

    buffer.SetBackgroundOpaque();
    buffer.SetBackgroundColor(COLOR_WHITE);
    buffer.SetTextColor(COLOR_BLACK);
    buffer.Select(*this);

    RECT rec;
    rec.left = 0;
    rec.top = 0;
    rec.right = tm.tmAveCharWidth;
    rec.bottom = tm.tmHeight;
    buffer.text_opaque(0, 0, rec, _T("M"));

    UPixelScalar top = tm.tmHeight, bottom = 0;

    for (UPixelScalar x = 0; x < (UPixelScalar)tm.tmAveCharWidth; ++x) {
      for (UPixelScalar y = 0; y < (UPixelScalar)tm.tmHeight; ++y) {
        if (buffer.GetPixel(x, y) != white) {
          if (top > y)
            top = y;
          if (bottom < y)
            bottom = y;
        }
      }
    }

    capital_height = bottom - top + 1;
  } else {
    // This works for PPC
    capital_height = tm.tmAscent - 1 - tm.tmHeight / 10;
  }
}
Esempio n. 5
0
void PopupMessage::Resize() {
  PixelRect rthis;

  if (*msgText == _T('\0')) {
    hide();
  } else {
    set_text(msgText);

    AnyCanvas canvas;
    canvas.select(Fonts::MapBold);
    PixelSize tsize = canvas.text_size(msgText);

    int linecount = max((unsigned)nvisible, max((unsigned)1, get_row_count()));

    int width =// min((rc.right-rc.left)*0.8,tsize.cx);
      (int)((rc.right-rc.left)*0.9);
    int height = min((int)((rc.bottom-rc.top) * 0.8),
                     (int)tsize.cy * (linecount + 1));
    int h1 = height/2;
    int h2 = height-h1;

    int midx = (rc.right+rc.left)/2;
    int midy = (rc.bottom+rc.top)/2;

    if (Appearance.StateMessageAlign == smAlignTopLeft){
      rthis.top = 0;
      rthis.left = 0;
      rthis.bottom = height;
      rthis.right = Layout::FastScale(206);
      // TODO code: this shouldn't be hard-coded
    } else {
      rthis.left = midx-width/2;
      rthis.right = midx+width/2;
      rthis.top = midy-h1;
      rthis.bottom = midy+h2;
    }

    move(rthis.left, rthis.top,
         rthis.right - rthis.left,
         rthis.bottom - rthis.top);
    show_on_top();
  }

}
Esempio n. 6
0
static int
ShowMapItemListDialog(SingleWindow &parent)
{
  unsigned num_items = list->size();

  UPixelScalar item_height = Fonts::map_bold.GetHeight() + Layout::Scale(6) +
                             Fonts::map_label.GetHeight();

  assert(num_items <= 0x7fffffff);
  assert(item_height > 0);

  wf = LoadDialog(CallBackTable, parent, Layout::landscape ?
                  _T("IDR_XML_MAPITEMLIST_L") : _T("IDR_XML_MAPITEMLIST"));
  assert(wf != NULL);

  details_button = (WndButton *)wf->FindByName(_T("cmdDetails"));
  assert(details_button);

  WndListFrame *list_control =
      (WndListFrame *)wf->FindByName(_T("frmComboPopupList"));
  assert(list_control != NULL);
  list_control->SetItemHeight(item_height);
  list_control->SetLength(num_items);
  list_control->SetCursorIndex(0);
  list_control->SetActivateCallback(OnComboPopupListEnter);
  list_control->SetPaintItemCallback(PaintListItem);
  list_control->SetCursorCallback(OnListIndexChange);
  OnListIndexChange(0);

  WndFrame *info_label = (WndFrame *)wf->FindByName(_T("lblInfo"));
  assert(info_label);
  info_label->SetAlignCenter();
  info_label->SetVAlignCenter();

  TCHAR info_buffer[256], distance_buffer[32], direction_buffer[32];
  if (vector.IsValid()) {
    Units::FormatUserDistance(vector.distance, distance_buffer, 32);
    FormatBearing(direction_buffer, ARRAY_SIZE(direction_buffer),
                  vector.bearing, _T("T"));
    _stprintf(info_buffer, _T("%s: %s - %s: %s"),
              _("Distance"), distance_buffer,
              _("Direction"), direction_buffer);
  } else {
    _stprintf(info_buffer, _T("%s: %s - %s: %s"),
              _("Distance"), _T("???"), _("Direction"), _T("???"));
  }

  TCHAR elevation_buffer[32];
  if (elevation != RasterBuffer::TERRAIN_INVALID) {
    Units::FormatUserAltitude(fixed(elevation), elevation_buffer, 32);
    _stprintf(info_buffer + _tcslen(info_buffer), _T(" - %s: %s"),
              _("Elevation"), elevation_buffer);
  }

  AnyCanvas canvas;
  canvas.Select(info_label->GetFont());
  UPixelScalar text_width = canvas.CalcTextWidth(info_buffer);
  if (text_width > info_label->get_width()) {
    if (vector.IsValid())
      _stprintf(info_buffer, _T("%s - %s"), distance_buffer, direction_buffer);
    else
      _stprintf(info_buffer, _T("%s - %s"), _T("???"), _T("???"));

    if (elevation != RasterBuffer::TERRAIN_INVALID)
      _stprintf(info_buffer + _tcslen(info_buffer), _T(" - %s"), elevation_buffer);
  }

  info_label->SetCaption(info_buffer);

  int result = wf->ShowModal() == mrOK
    ? (int)list_control->GetCursorIndex()
    : -1;
  delete wf;

  return result;
}