Esempio n. 1
0
PixelRect GetButtonPosition(unsigned MenuID, const PixelRect& rcScreen) {
    PixelRect rc = rcScreen;
    rc.Grow(-1); // remove Margin

    unsigned i = MenuID - 1;
    
    assert(i < MenuButtons.size());
    
    const PixelScalar row   = ScreenLandscape ? LandscapeLayout[i].row : PortraitLayout[i].row;
    const PixelScalar col   = ScreenLandscape ? LandscapeLayout[i].col :PortraitLayout[i].col;
    const PixelScalar nbRow = ScreenLandscape ? 5 : 7;
    const PixelScalar nbCol = ScreenLandscape ? 5 : 4;

    const PixelSize size = {
        std::min<PixelScalar>((rc.GetSize().cx-(nbCol-1))/nbCol, NIBLSCALE(80)), 
        std::min<PixelScalar>((rc.GetSize().cy-nbRow-1)/nbRow, NIBLSCALE(40))
    };
    
    const double x_interval = (rc.GetSize().cx - size.cx * nbCol) / (nbCol-1);
    const double y_interval = (rc.GetSize().cy - size.cy * nbRow) / (nbRow-1);

    const RasterPoint origin = {
        rc.left + (PixelScalar)(col * (size.cx + x_interval)),
        rc.top + (PixelScalar)(row * (size.cy + y_interval))
    };

    return PixelRect(origin, size);
}
Esempio n. 2
0
static void
Draw(Canvas &canvas)
{
  PixelRect rc = canvas.GetRect();
  rc.Grow(-16);

  DrawBanner(canvas, rc);
  DrawFlights(canvas, rc);
}
Esempio n. 3
0
PixelRect
ButtonFrameRenderer::GetDrawingRect(PixelRect rc, bool pressed) const
{
  rc.Grow(-2);
  if (pressed)
    rc.Offset(1, 1);

  return rc;
}
Esempio n. 4
0
inline void
TabMenuDisplay::PaintMainMenuBorder(Canvas &canvas) const
{
  PixelRect rc = GetMainMenuButtonSize(0);
  rc.bottom = GetMainMenuButtonSize(GetNumMainMenuItems() - 1).bottom;
  rc.Grow(GetTabLineHeight());

  canvas.DrawFilledRectangle(rc, COLOR_BLACK);
}
Esempio n. 5
0
inline void
TabMenuDisplay::PaintSubMenuBorder(Canvas &canvas,
                                   const MainMenuButton &main_button) const
{
  PixelRect rc = GetSubMenuButtonSize(main_button.first_page_index);
  rc.bottom = GetSubMenuButtonSize(main_button.last_page_index).bottom;
  rc.Grow(GetTabLineHeight());

  canvas.DrawFilledRectangle(rc, COLOR_BLACK);
}
Esempio n. 6
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. 7
0
bool
WndForm::OnMouseMove(PixelScalar x, PixelScalar y, unsigned keys)
{
  if (ContainerWindow::OnMouseMove(x, y, keys))
    return true;

  if (dragging) {
    const PixelRect position = GetPosition();
    const int dx = position.left + x - last_drag.x;
    const int dy = position.top + y - last_drag.y;
    last_drag.x = position.left + x;
    last_drag.y = position.top + y;

    PixelRect parent = GetParentClientRect();
    parent.Grow(-client_rect.top);

    PixelRect new_position = position;
    new_position.Offset(dx, dy);

    if (new_position.right < parent.left)
      new_position.Offset(parent.left - new_position.right, 0);

    if (new_position.left > parent.right)
      new_position.Offset(parent.right - new_position.left, 0);

    if (new_position.top > parent.bottom)
      new_position.Offset(0, parent.bottom - new_position.top);

    if (new_position.top < 0)
      new_position.Offset(0, -new_position.top);

#ifdef USE_MEMORY_CANVAS
    /* the RasterCanvas class doesn't clip negative window positions
       properly, therefore we avoid this problem at this stage */
    if (new_position.left < 0)
      new_position.left = 0;

    if (new_position.top < 0)
      new_position.top = 0;
#endif

    Move(new_position.left, new_position.top);

    return true;
  }

  return false;
}
Esempio n. 8
0
void
WndFrame::OnPaint(Canvas &canvas)
{
  if (HaveClipping())
    canvas.Clear(look.background_brush);

  canvas.SetTextColor(caption_color);
  canvas.SetBackgroundTransparent();

  canvas.Select(look.text_font);

  PixelRect rc = GetClientRect();
  const int padding = Layout::GetTextPadding();
  rc.Grow(-padding);

  text_renderer.Draw(canvas, rc, text.c_str());
}
Esempio n. 9
0
inline void
AirspaceIntersectionVisitorSlice::RenderBox(const PixelRect rc,
                                            AirspaceClass type) const
{
  if (AirspacePreviewRenderer::PrepareFill(canvas, type, airspace_look,
                                           settings)) {
    const auto &class_settings = settings.classes[type];

    // Draw thick brushed outlines
    const int border_width = class_settings.fill_mode ==
      AirspaceClassRendererSettings::FillMode::PADDING
      ? Layout::ScalePenWidth(10)
      : 0;

    if (border_width > 0 &&
        (rc.right - rc.left) > border_width * 2 &&
        (rc.bottom - rc.top) > border_width * 2) {
      PixelRect border = rc;
      border.Grow(-border_width);

      // Left border
      canvas.Rectangle(rc.left, rc.top, border.left, rc.bottom);

      // Right border
      canvas.Rectangle(border.right, rc.top, rc.right, rc.bottom);

      // Bottom border
      canvas.Rectangle(border.left, border.bottom, border.right, rc.bottom);

      // Top border
      canvas.Rectangle(border.left, rc.top, border.right, border.top);
    } else {
      // .. or fill the entire rect if the outlines would overlap
      canvas.Rectangle(rc.left, rc.top, rc.right, rc.bottom);
    }

    AirspacePreviewRenderer::UnprepareFill(canvas);
  }

  // Use transparent brush and type-dependent pen for the outlines
  if (AirspacePreviewRenderer::PrepareOutline(canvas, type, airspace_look,
                                              settings))
    canvas.Rectangle(rc.left, rc.top, rc.right, rc.bottom);
}
Esempio n. 10
0
static void
Draw(Canvas &canvas)
{
  PixelRect rc = canvas.GetRect();
  rc.Grow(-0.2 * rc.GetSize().cx);
  
  /* draw the banner text with a large font */
  Font small_font;
  small_font.LoadFile("/opt/LK8000/share/fonts/DejaVuSansCondensed.ttf", (rc.GetSize().cy / 25));
  canvas.Select(small_font);
  canvas.SetTextColor(COLOR_BLACK);
  canvas.SetBackgroundTransparent();

  const TCHAR *const text = _T("Powered Off");
  const PixelSize text_size = canvas.CalcTextSize(text);
  const RasterPoint text_pos = {
      rc.left + 16,
      rc.bottom - 16 - text_size.cy
  };
  canvas.DrawText(text_pos.x, text_pos.y, text);
  
  Font big_font;
  big_font.LoadFile("/opt/LK8000/share/fonts/DejaVuSansCondensed-Bold.ttf", (rc.GetSize().cy / 10));
  canvas.Select(big_font);
  
  const TCHAR *const text2 = _T("LK8000");
  const PixelSize text2_size = canvas.CalcTextSize(text2);
  const RasterPoint text2_pos = {
      (rc.left + rc.GetSize().cx + text2_size.cx) / 2,
      (rc.top + (rc.GetSize().cy / 10))
  };
  canvas.DrawText(text2_pos.x, text2_pos.y, text2);
  
  const double Scale = (double)rc.GetSize().cx / (double)bird_size.cx;
  
  RasterPoint polygon[array_size(bird_polygon)] = {};
  std::transform(std::begin(bird_polygon), std::end(bird_polygon), std::begin(polygon), [Scale, rc, text2_size, text2_pos]( const RasterPoint& pt ) {
      return RasterPoint(pt.x*Scale + rc.left, pt.y*Scale + text2_pos.y + text2_size.cy);
  });
  
  canvas.SelectBlackBrush();
  canvas.DrawPolygon(polygon, array_size(polygon));
}
Esempio n. 11
0
bool
WndForm::OnMouseMove(PixelScalar x, PixelScalar y, unsigned keys)
{
  if (ContainerWindow::OnMouseMove(x, y, keys))
    return true;

  if (dragging) {
    const PixelRect position = GetPosition();
    const int dx = position.left + x - last_drag.x;
    const int dy = position.top + y - last_drag.y;
    last_drag.x = position.left + x;
    last_drag.y = position.top + y;

    PixelRect parent = GetParentClientRect();
    parent.Grow(-client_rect.top);

    PixelRect new_position = position;
    new_position.Offset(dx, dy);

    if (new_position.right < parent.left)
      new_position.Offset(parent.left - new_position.right, 0);

    if (new_position.left > parent.right)
      new_position.Offset(parent.right - new_position.left, 0);

    if (new_position.top > parent.bottom)
      new_position.Offset(0, parent.bottom - new_position.top);

    if (new_position.top < 0)
      new_position.Offset(0, -new_position.top);

    Move(new_position.left, new_position.top);

    return true;
  }

  return false;
}
Esempio n. 12
0
bool
dlgConfigInfoboxesShowModal(SingleWindow &parent,
                            const DialogLook &dialog_look,
                            const InfoBoxLook &_look,
                            InfoBoxSettings::Geometry geometry,
                            InfoBoxSettings::Panel &data_r,
                            bool allow_name_change)
{
  current_preview = 0;
  look = &_look;
  data = data_r;

  PixelRect rc = parent.GetClientRect();
  wf = new WndForm(parent, dialog_look, rc);

#ifdef _WIN32_WCE
  if (IsAltair())
    wf->SetKeyDownFunction(OnKeyDown);
#endif

  ContainerWindow &client_area = wf->GetClientAreaWindow();
  rc = client_area.GetClientRect();
  rc.Grow(Layout::FastScale(-2));
  info_box_layout = InfoBoxLayout::Calculate(rc, geometry);

  WindowStyle preview_style;
  preview_style.EnableDoubleClicks();
  for (unsigned i = 0; i < info_box_layout.count; ++i) {
    rc = info_box_layout.positions[i];
    previews[i].Create(client_area, rc, preview_style);
  }

  rc = info_box_layout.remaining;

  WindowStyle style;
  style.TabStop();

  PixelRect control_rc = rc;
  control_rc.right -= Layout::FastScale(2);

  const UPixelScalar height = Layout::Scale(22);
  const UPixelScalar caption_width = Layout::Scale(60);

  ButtonWindowStyle button_style;
  button_style.TabStop();

  control_rc.bottom = control_rc.top + height;
  edit_name = new WndProperty(client_area, dialog_look, _("Name"),
                              control_rc, caption_width,
                              style);
  DataFieldString *dfs = new DataFieldString(allow_name_change
                                             ? (const TCHAR *)data.name
                                             : gettext(data.name));
  edit_name->SetDataField(dfs);
  edit_name->SetReadOnly(!allow_name_change);

  control_rc.top = control_rc.bottom;
  control_rc.bottom = control_rc.top + height;

  edit_select = new WndProperty(client_area, dialog_look, _("InfoBox"),
                                control_rc, caption_width,
                                style);

  DataFieldEnum *dfe = new DataFieldEnum(OnSelectAccess);
  for (unsigned i = 0; i < info_box_layout.count; ++i) {
    TCHAR label[32];
    _stprintf(label, _T("%u"), i + 1);
    dfe->addEnumText(label, i);
  }

  edit_select->SetDataField(dfe);

  control_rc.top += height;
  control_rc.bottom += height;

  edit_content = new WndProperty(client_area, dialog_look, _("Content"),
                                 control_rc, caption_width,
                                 style);

  dfe = new DataFieldEnum(OnContentAccess);
  for (unsigned i = InfoBoxFactory::MIN_TYPE_VAL; i < InfoBoxFactory::NUM_TYPES; i++) {
    const TCHAR *name = InfoBoxFactory::GetName((InfoBoxFactory::Type) i);
    const TCHAR *desc = InfoBoxFactory::GetDescription((InfoBoxFactory::Type) i);
    if (name != NULL)
      dfe->addEnumText(gettext(name), i, desc != NULL ? gettext(desc) : NULL);
  }

  dfe->EnableItemHelp(true);
  dfe->Sort(0);

  edit_content->SetDataField(dfe);

  control_rc.top += height;
  control_rc.bottom += height * 5;
  edit_content_description = new WndFrame(client_area, dialog_look,
                                          control_rc, style);

  RefreshEditContent();

  const UPixelScalar button_width = Layout::Scale(60);
  const UPixelScalar button_height = Layout::Scale(28);

  PixelRect button_rc = rc;
  button_rc.right = button_rc.left + button_width;
  button_rc.top = button_rc.bottom - button_height;

  WndButton *close_button =
    new WndButton(client_area, dialog_look.button, _("Close"),
                  button_rc, button_style, *wf, mrOK);

  button_rc.left += button_width + Layout::Scale(2);
  button_rc.right += button_width + Layout::Scale(2);
  WndButton *copy_button =
    new WndButton(client_area, dialog_look.button, _("Copy"),
                  button_rc, button_style, OnCopy);

  button_rc.left += button_width + Layout::Scale(2);
  button_rc.right += button_width + Layout::Scale(2);
  buttonPaste =
    new WndButton(client_area, dialog_look.button, _("Paste"),
                  button_rc, button_style, OnPaste);

  RefreshPasteButton();

  int result = wf->ShowModal();

  if (result == mrOK && allow_name_change)
    data.name = edit_name->GetDataField()->GetAsString();

  delete wf;
  delete edit_name;
  delete edit_select;
  delete edit_content;
  delete close_button;
  delete copy_button;
  delete buttonPaste;

  bool changed = false;
  if (result == mrOK) {
    for (unsigned i = 0; i < InfoBoxSettings::Panel::MAX_CONTENTS; ++i)
      if (data.contents[i] != data_r.contents[i])
        changed = true;
    changed |= (_tcscmp(data.name, data_r.name) != 0);

    if (changed)
      data_r = data;
  }

  return changed;
}