Example #1
0
void
TerminalWindow::OnPaint(Canvas &canvas, const PixelRect &p_dirty)
{
  canvas.SetBackgroundTransparent();
  canvas.SetTextColor(look.text_color);
  canvas.Select(look.font);

  const PixelRect cell_dirty = {
    p_dirty.left / cell_size.cx,
    p_dirty.top / cell_size.cy,
    std::min(PixelScalar(p_dirty.right / cell_size.cx + 1),
             PixelScalar(data.GetWidth())),
    std::min(PixelScalar(p_dirty.bottom / cell_size.cy + 1),
             PixelScalar(data.GetHeight())),
  };

  const PixelScalar x(cell_dirty.left * cell_size.cx);
  const size_t length = cell_dirty.right - cell_dirty.left;

  auto text = data.GetPointerAt(cell_dirty.left, cell_dirty.top);
  for (int cell_y = cell_dirty.top, p_y = cell_y * cell_size.cy;
       cell_y < cell_dirty.bottom;
       ++cell_y, p_y += cell_size.cy, text += data.GetWidth()) {
    canvas.DrawFilledRectangle(p_dirty.left, p_y,
                          p_dirty.right, p_y + cell_size.cy,
                          look.background_color);
    canvas.DrawText(x, p_y, text, length);
  }

  PixelScalar cell_bottom_y(cell_dirty.bottom * cell_size.cy);
  if (cell_bottom_y < p_dirty.bottom)
    canvas.DrawFilledRectangle(p_dirty.left, cell_bottom_y,
                          p_dirty.right, p_dirty.bottom,
                          look.background_color);
}
Example #2
0
void
QuickMenuButtonRenderer::DrawButton(Canvas &canvas, const PixelRect &rc,
                                    bool enabled, bool focused,
                                    bool pressed) const
{
  // Draw focus rectangle
  if (pressed) {
    canvas.DrawFilledRectangle(rc, look.list.pressed.background_color);
    canvas.SetTextColor(look.list.pressed.text_color);
  } else if (focused) {
    canvas.DrawFilledRectangle(rc, look.focused.background_color);
    canvas.SetTextColor(enabled
                        ? look.focused.text_color
                        : look.button.disabled.color);
  } else {
    if (HaveClipping())
      canvas.DrawFilledRectangle(rc, look.background_brush);
    canvas.SetTextColor(enabled ? look.text_color : look.button.disabled.color);
  }

  canvas.Select(*look.button.font);
  canvas.SetBackgroundTransparent();

  text_renderer.Draw(canvas, rc, caption);
}
Example #3
0
void
ProgressBar::OnPaint(Canvas &canvas)
{
  unsigned position = 0;
  if (min_value < max_value) {
    unsigned value = this->value;
    if (value < min_value)
      value = min_value;
    else if (value > max_value)
      value = max_value;
#ifdef EYE_CANDY
    position = (value - min_value) * (GetWidth() - GetHeight()) /
               (max_value - min_value);
#else
    position = (value - min_value) * GetWidth() / (max_value - min_value);
#endif
  }

#ifdef EYE_CANDY
  unsigned margin = GetHeight() / 9;

  canvas.SelectNullPen();
  canvas.SelectWhiteBrush();
  canvas.DrawRoundRectangle(0, 0, GetWidth(), GetHeight(),
                            GetHeight(), GetHeight());

  Brush progress_brush(COLOR_XCSOAR_LIGHT);
  canvas.Select(progress_brush);
  canvas.DrawRoundRectangle(margin, margin, margin + position,
                            GetHeight() - margin, GetHeight(), GetHeight());
#else
  canvas.DrawFilledRectangle(0, 0, position, GetHeight(), COLOR_GREEN);
  canvas.DrawFilledRectangle(position, 0, GetWidth(), GetHeight(), COLOR_WHITE);
#endif
}
Example #4
0
void
ButtonFrameRenderer::DrawButton(Canvas &canvas, PixelRect rc,
                                bool focused, bool pressed) const
{
  const ButtonLook::StateLook &_look = focused ? look.focused : look.standard;

  canvas.DrawFilledRectangle(rc, _look.background_color);

  const unsigned margin = GetMargin();

  if (margin < 4) {
    /* draw 1-pixel lines */

    canvas.Select(pressed ? _look.dark_border_pen : _look.light_border_pen);
    for (unsigned i = 0; i < margin; ++i)
      canvas.DrawTwoLinesExact(rc.left + i, rc.bottom - 2 - i,
                               rc.left + i, rc.top + i,
                               rc.right - 2 - i, rc.top + i);

    canvas.Select(pressed ? _look.light_border_pen : _look.dark_border_pen);
    for (unsigned i = 0; i < margin; ++i)
      canvas.DrawTwoLinesExact(rc.left + 1 + i, rc.bottom - 1 - i,
                               rc.right - 1 - i, rc.bottom - 1 - i,
                               rc.right - 1 - i, rc.top + 1 + i);
  } else {
    /* at 4 pixels or more, it's more efficient to draw a filled
       polygon */

    const RasterPoint p1[] = {
      RasterPoint(rc.left, rc.top),
      RasterPoint(rc.right, rc.top),
      RasterPoint(rc.right - margin, rc.top + margin),
      RasterPoint(rc.left + margin, rc.top + margin),
      RasterPoint(rc.left + margin, rc.bottom - margin),
      RasterPoint(rc.left, rc.bottom),
    };

    canvas.SelectNullPen();
    canvas.Select(pressed
                  ? _look.dark_border_brush
                  : _look.light_border_brush);
    canvas.DrawTriangleFan(p1, ARRAY_SIZE(p1));

    const RasterPoint p2[] = {
      RasterPoint(rc.right, rc.bottom),
      RasterPoint(rc.right, rc.top),
      RasterPoint(rc.right - margin, rc.top + margin),
      RasterPoint(rc.right - margin, rc.bottom - margin),
      RasterPoint(rc.left + margin, rc.bottom - margin),
      RasterPoint(rc.left, rc.bottom),
    };

    canvas.Select(pressed
                  ? _look.light_border_brush
                  : _look.dark_border_brush);
    canvas.DrawTriangleFan(p2, ARRAY_SIZE(p2));
}
}
Example #5
0
void
ListControl::DrawItems(Canvas &canvas, unsigned start, unsigned end) const
{
  PixelRect rc = item_rect(start);

  canvas.SetBackgroundColor(look.list.background_color);
  canvas.SetBackgroundTransparent();
  canvas.Select(*look.list.font);

#ifdef ENABLE_OPENGL
  /* enable clipping */
  GLScissor scissor(OpenGL::translate.x,
                    OpenGL::screen_height - OpenGL::translate.y - canvas.GetHeight() - 1,
                    scroll_bar.GetLeft(GetSize()), canvas.GetHeight());
#endif

  unsigned last_item = std::min(length, end);

  const bool focused = HasFocus();

  for (unsigned i = start; i < last_item; i++) {
    const bool selected = i == cursor;
    const bool pressed = selected && drag_mode == DragMode::CURSOR;

    canvas.DrawFilledRectangle(rc,
                               look.list.GetBackgroundColor(selected,
                                                            focused,
                                                            pressed));

    canvas.SetTextColor(look.list.GetTextColor(selected, focused, pressed));

    if (item_renderer != nullptr)
      item_renderer->OnPaintItem(canvas, rc, i);

    if (focused && selected)
      canvas.DrawFocusRectangle(rc);

    rc.Offset(0, rc.bottom - rc.top);
  }

  /* paint the bottom part below the last item */
  rc.bottom = canvas.GetHeight();
  if (rc.bottom > rc.top)
    canvas.DrawFilledRectangle(rc, look.list.background_color);
}
Example #6
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);
}
Example #7
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);
}
void
TaskMapButtonRenderer::DrawButton(Canvas &canvas, const PixelRect &rc,
                                  gcc_unused bool enabled,
                                  gcc_unused bool focused,
                                  bool pressed) const
{
  if (task == nullptr) {
    canvas.ClearWhite();
    return;
  }

  const PixelSize new_size(rc.right - rc.left,
                           rc.bottom - rc.top);
  if (!IsBufferValid(new_size)) {
    if (!buffer.IsDefined()) {
#ifdef ENABLE_OPENGL
      buffer.Create(new_size);
#else
      buffer.Create(canvas, new_size);
#endif
    } else
      buffer.Grow(new_size);

    size = new_size;

#ifdef ENABLE_OPENGL
    buffer.Begin(canvas);
#endif

    const PixelRect buffer_rc(0, 0, new_size.cx, new_size.cy);
    DrawTask(buffer, buffer_rc, look, *task);

#ifdef ENABLE_OPENGL
    buffer.Commit(canvas);
#endif
  } else {
#ifdef ENABLE_OPENGL
    buffer.CopyTo(canvas);
#endif
  }

#ifndef ENABLE_OPENGL
  canvas.Copy(buffer);
#endif

  if (pressed) {
#ifdef ENABLE_OPENGL
    const ScopeAlphaBlend alpha_blend;
    canvas.DrawFilledRectangle(rc, COLOR_YELLOW.WithAlpha(80));
#else
    canvas.InvertRectangle(rc);
#endif
  }
}
Example #9
0
void
CrossSectionWindow::OnPaintBuffer(Canvas &canvas)
{
  const PixelRect rc = GetClientRect();

#ifdef ENABLE_OPENGL
  const GLCanvasScissor scissor(rc);
#endif
  canvas.DrawFilledRectangle(rc, renderer.inverse? COLOR_BLACK: COLOR_WHITE);
  renderer.Paint(canvas, rc);
}
Example #10
0
void
MainWindow::OnPaint(Canvas &canvas)
{
  if (bottom_widget != nullptr && map != nullptr) {
    /* draw a separator between main area and bottom area */
    PixelRect rc = map->GetPosition();
    rc.top = rc.bottom;
    rc.bottom += separator_height;
    canvas.DrawFilledRectangle(rc, COLOR_BLACK);
  }

  SingleWindow::OnPaint(canvas);
}
Example #11
0
void
WndCustomButton::OnPaint(Canvas &canvas)
{
#ifdef HAVE_CLIPPING
  /* background and selector */
  canvas.Clear(look.background_brush);
#endif

  PixelRect rc = GetClientRect();

  // Draw focus rectangle
  if (HasFocus()) {
    canvas.DrawFilledRectangle(rc, look.focused.background_color);
    canvas.SetTextColor(IsEnabled()
                        ? look.focused.text_color : look.button.disabled.color);
  } else {
    canvas.DrawFilledRectangle(rc, look.background_color);
    canvas.SetTextColor(IsEnabled() ? look.text_color : look.button.disabled.color);
  }

  // If button has text on it
  tstring caption = get_text();
  if (caption.empty())
    return;

  // If button is pressed, offset the text for 3D effect
  if (is_down())
    OffsetRect(&rc, 1, 1);

  canvas.SelectNullPen();
  canvas.SetBackgroundTransparent();
#ifndef USE_GDI
  canvas.formatted_text(&rc, caption.c_str(), GetTextStyle());
#else
  unsigned s = DT_CENTER | DT_NOCLIP | DT_WORDBREAK;
  canvas.Select(*(look.button.font));
  canvas.formatted_text(&rc, caption.c_str(), s);
#endif
}
Example #12
0
void
TabDisplay::PaintButton(Canvas &canvas, unsigned CaptionStyle,
                        const TCHAR *caption, const PixelRect &rc,
                        const Bitmap *bmp, const bool isDown, bool inverse)
{
  PixelRect rcTextFinal = rc;
  const UPixelScalar buttonheight = rc.bottom - rc.top;
  const PixelSize text_size = canvas.CalcTextSize(caption);
  const int textwidth = text_size.cx;
  const int textheight = text_size.cy;
  UPixelScalar textheightoffset = 0;

  if (textwidth > (rc.right - rc.left)) // assume 2 lines
    textheightoffset = std::max(0, (int)(buttonheight - textheight * 2) / 2);
  else
    textheightoffset = std::max(0, (int)(buttonheight - textheight) / 2);

  rcTextFinal.top += textheightoffset;

  canvas.DrawFilledRectangle(rc, canvas.GetBackgroundColor());

  if (bmp != NULL) {
    const PixelSize bitmap_size = bmp->GetSize();
    const int offsetx = (rc.right - rc.left - bitmap_size.cx / 2) / 2;
    const int offsety = (rc.bottom - rc.top - bitmap_size.cy) / 2;

    if (inverse) // black background
      canvas.CopyNotOr(rc.left + offsetx,
                       rc.top + offsety,
                       bitmap_size.cx / 2,
                       bitmap_size.cy,
                       *bmp,
                       bitmap_size.cx / 2, 0);

    else
      canvas.CopyAnd(rc.left + offsetx,
                      rc.top + offsety,
                      bitmap_size.cx / 2,
                      bitmap_size.cy,
                      *bmp,
                      bitmap_size.cx / 2, 0);

  } else {
#ifndef USE_GDI
    if (IsDithered())
      CaptionStyle |= DT_UNDERLINE;
#endif

    canvas.DrawFormattedText(&rcTextFinal, caption, CaptionStyle);
  }
}
Example #13
0
void
SmallTrafficWindow::OnPaint(Canvas &canvas)
{
  FlarmTrafficWindow::OnPaint(canvas);

  if (pressed) {
#ifdef ENABLE_OPENGL
    const GLBlend blend(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    canvas.DrawFilledRectangle(0, 0, canvas.GetWidth(), canvas.GetHeight(),
                               COLOR_YELLOW.WithAlpha(80));
#else
    canvas.InvertRectangle(GetClientRect());
#endif
  }
}
Example #14
0
void
SmallTrafficWindow::OnPaint(Canvas &canvas)
{
  FlarmTrafficWindow::OnPaint(canvas);

  if (pressed) {
#ifdef ENABLE_OPENGL
    const ScopeAlphaBlend alpha_blend;
    canvas.DrawFilledRectangle(0, 0, canvas.GetWidth(), canvas.GetHeight(),
                               COLOR_YELLOW.WithAlpha(80));
#else
    canvas.InvertRectangle(GetClientRect());
#endif
  }
}
Example #15
0
void
InfoBoxWindow::PaintTitle(Canvas &canvas)
{
  if (data.title.empty())
    return;

  if (!pressed && !HasFocus() && !dragging && !force_draw_selector &&
      settings.border_style == InfoBoxSettings::BorderStyle::SHADED)
    canvas.DrawFilledRectangle(title_rect, look.caption_background_color);

  canvas.SetTextColor(look.GetTitleColor(data.title_color));

  const Font &font = look.title_font;
  canvas.Select(font);

  PixelSize tsize = canvas.CalcTextSize(data.title);

  PixelScalar halftextwidth = (title_rect.left + title_rect.right - tsize.cx) / 2;
  PixelScalar x = std::max(PixelScalar(1),
                           PixelScalar(title_rect.left + halftextwidth));
  PixelScalar y = title_rect.top;

  canvas.TextAutoClipped(x, y, data.title);

  if (settings.border_style == InfoBoxSettings::BorderStyle::TAB &&
      halftextwidth > Layout::Scale(3)) {
    PixelScalar ytop = title_rect.top + font.GetCapitalHeight() / 2;
    PixelScalar ytopedge = ytop + Layout::GetTextPadding();
    PixelScalar ybottom = title_rect.top + Layout::Scale(6)
      + font.GetCapitalHeight();

    canvas.Select(look.border_pen);

    RasterPoint tab[8];
    tab[0].x = tab[1].x = title_rect.left;
    tab[0].y = tab[7].y = ybottom;
    tab[2].x = title_rect.left + Layout::GetTextPadding();
    tab[2].y = tab[5].y = tab[3].y = tab[4].y = ytop;
    tab[1].y = tab[6].y = ytopedge;
    tab[5].x = title_rect.right - Layout::GetTextPadding();
    tab[6].x = tab[7].x = title_rect.right;
    tab[3].x = title_rect.left + halftextwidth - Layout::Scale(1);
    tab[4].x = title_rect.right - halftextwidth + Layout::Scale(1);

    canvas.DrawPolyline(tab, 4);
    canvas.DrawPolyline(tab + 4, 4);
  }
}
Example #16
0
void
GaugeVario::RenderClimb(Canvas &canvas)
{
  const PixelRect rc = GetClientRect();
  int x = rc.right - Layout::Scale(14);
  int y = rc.bottom - Layout::Scale(24);

  if (!dirty)
    return;

  if (Basic().switch_state.flight_mode == SwitchState::FlightMode::CIRCLING)
    canvas.ScaleCopy(x, y, look.climb_bitmap, 12, 0, 12, 12);
  else if (IsPersistent())
    canvas.DrawFilledRectangle(x, y, x + Layout::Scale(12), y + Layout::Scale(12),
                          look.background_color);
}
void
DrawGlassBackground(Canvas &canvas, const PixelRect &rc, Color color)
{
  canvas.DrawFilledRectangle(rc, color);

#if defined(EYE_CANDY) && defined(ENABLE_OPENGL)
  if (color != COLOR_WHITE)
    /* apply only to white background for now */
    return;

  const GLCanvasScissor scissor(rc);

  const Color shadow = color.Shadow();

  const RasterPoint center = rc.GetCenter();
  const int size = std::min(rc.right - rc.left, rc.bottom - rc.top) / 4;

  const RasterPoint vertices[] = {
    { center.x + 1024, center.y - 1024 },
    { center.x + 1024 + size, center.y - 1024 + size },
    { center.x - 1024, center.y + 1024 },
    { center.x - 1024 + size, center.y + 1024 + size },
  };

  glVertexPointer(2, GL_VALUE, 0, vertices);

  const Color colors[] = {
    shadow, color,
    shadow, color,
  };

  glEnableClientState(GL_COLOR_ARRAY);

#ifdef HAVE_GLES
  glColorPointer(4, GL_FIXED, 0, colors);
#else
  glColorPointer(4, GL_UNSIGNED_BYTE, 0, colors);
#endif

  static_assert(ARRAY_SIZE(vertices) == ARRAY_SIZE(colors),
                "Array size mismatch");

  glDrawArrays(GL_TRIANGLE_STRIP, 0, ARRAY_SIZE(vertices));

  glDisableClientState(GL_COLOR_ARRAY);
#endif
}
Example #18
0
void
SmallTrafficWindow::OnPaint(Canvas &canvas)
{
  FlarmTrafficWindow::OnPaint(canvas);

  if (pressed) {
#ifdef ENABLE_OPENGL
    GLEnable blend(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    canvas.DrawFilledRectangle(0, 0, canvas.GetWidth(), canvas.GetHeight(),
                               COLOR_YELLOW.WithAlpha(80));
#elif defined(USE_GDI)
    const PixelRect rc = GetClientRect();
    ::InvertRect(canvas, &rc);
#endif
  }
}
Example #19
0
void
ButtonFrameRenderer::DrawButton(Canvas &canvas, PixelRect rc,
                                bool focused, bool pressed) const
{
  const ButtonLook::StateLook &_look = focused ? look.focused : look.standard;

  canvas.DrawFilledRectangle(rc, _look.background_color);

  canvas.Select(pressed ? _look.dark_border_pen : _look.light_border_pen);
  canvas.DrawTwoLinesExact(rc.left, rc.bottom - 2, rc.left, rc.top, rc.right - 2,
                           rc.top);
  canvas.DrawTwoLinesExact(rc.left + 1, rc.bottom - 3, rc.left + 1, rc.top + 1,
                           rc.right - 3, rc.top + 1);

  canvas.Select(pressed ? _look.light_border_pen : _look.dark_border_pen);
  canvas.DrawTwoLinesExact(rc.left + 1, rc.bottom - 1, rc.right - 1, rc.bottom - 1,
                           rc.right - 1, rc.top + 1);
  canvas.DrawTwoLinesExact(rc.left + 2, rc.bottom - 2, rc.right - 2, rc.bottom - 2,
                           rc.right - 2, rc.top + 2);
}
Example #20
0
void
TabRenderer::Draw(Canvas &canvas, const PixelRect &rc,
                  const DialogLook &look,
                  const TCHAR *caption, const MaskedIcon *icon,
                  bool focused, bool pressed, bool selected) const
{
  canvas.DrawFilledRectangle(rc,
                             look.list.GetBackgroundColor(selected, focused,
                                                          pressed));

  canvas.Select(*look.button.font);
  canvas.SetTextColor(look.list.GetTextColor(selected, focused, pressed));
  canvas.SetBackgroundTransparent();

  if (icon != nullptr) {
    icon->Draw(canvas, rc, selected);
  } else {
    text_renderer.Draw(canvas, rc, caption);
  }
}
Example #21
0
static void
OnPaintListItem(Canvas &canvas, const PixelRect rc, unsigned i)
{
  assert(i < ARRAY_SIZE(AirspaceLook::preset_colors));

  const Color color(AirspaceLook::preset_colors[i]);

  PixelRect rc2 = rc;
  rc2.Grow(-Layout::FastScale(2));

#ifdef USE_GDI
  canvas.DrawFilledRectangle(rc2, color);
  canvas.SelectHollowBrush();
#else
  Brush brush(color);
  canvas.Select(brush);
#endif

  canvas.SelectBlackPen();
  canvas.Rectangle(rc2.left, rc2.top, rc2.right, rc2.bottom);
}
Example #22
0
void
DrawVerticalGradient(Canvas &canvas, const PixelRect &rc,
                     Color top_color, Color bottom_color, Color fallback_color)
{
#if defined(EYE_CANDY) && defined(ENABLE_OPENGL)
  const RasterPoint vertices[] = {
    rc.GetTopLeft(),
    rc.GetTopRight(),
    rc.GetBottomLeft(),
    rc.GetBottomRight(),
  };

  glVertexPointer(2, GL_VALUE, 0, vertices);

  const Color colors[] = {
    top_color,
    top_color,
    bottom_color,
    bottom_color,
  };

  glEnableClientState(GL_COLOR_ARRAY);

#ifdef HAVE_GLES
  glColorPointer(4, GL_FIXED, 0, colors);
#else
  glColorPointer(4, GL_UNSIGNED_BYTE, 0, colors);
#endif

  static_assert(ARRAY_SIZE(vertices) == ARRAY_SIZE(colors),
                "Array size mismatch");

  glDrawArrays(GL_TRIANGLE_STRIP, 0, ARRAY_SIZE(vertices));

  glDisableClientState(GL_COLOR_ARRAY);
#else
  canvas.DrawFilledRectangle(rc, fallback_color);
#endif
}
Example #23
0
//------------------------------------------------------------------------------
int
main(int argc, char *argv[])
  {
  QApplication app(argc, argv);
  Canvas c;
  Pen(Pen::SOLID, 1, Color(0, 0, 0));
    {
    c.Select(Brush(Color(128, 128, 0, Color::TRANSPARENT)));
    c.DrawKeyhole(200, 100, 50, 100, Angle::Degrees(-20), Angle::Degrees(20));
    c.DrawKeyhole(400, 100, 50, 100, Angle::Degrees(70), Angle::Degrees(110));
    c.DrawKeyhole(200, 300, 50, 100, Angle::Degrees(160), Angle::Degrees(200));
    c.DrawKeyhole(400, 300, 50, 100, Angle::Degrees(-110), Angle::Degrees(-70));
    c.show();
    app.exec();
    }
    {
    c.Clear();
    c.DrawKeyhole(200, 100, 50, 100, Angle::Degrees(35), Angle::Degrees(55));
    c.DrawKeyhole(400, 100, 50, 100, Angle::Degrees(125), Angle::Degrees(145));
    c.DrawKeyhole(200, 300, 50, 100, Angle::Degrees(215), Angle::Degrees(235));
    c.DrawKeyhole(400, 300, 50, 100, Angle::Degrees(305), Angle::Degrees(325));
    c.show();
    app.exec();
    }
    {
    c.Clear();
    c.DrawFilledRectangle(0, 0, 100, 100, Color(128, 128, 128,
                                                Color::TRANSPARENT));
    c.DrawFilledRectangle(100, 100, 200, 200, Color(128, 0, 0,
                                                    Color::TRANSPARENT));
    c.DrawFilledRectangle(150, 150, 250, 250, Color(0, 128, 0,
                                                    Color::TRANSPARENT));
    c.DrawFilledRectangle(200, 200, 300, 300, Color(0, 0, 128,
                                                    Color::TRANSPARENT));
    c.DrawTransparentText(0, 0, "0");
    c.DrawTransparentText(0, 100, "100");
    c.DrawTransparentText(0, 200, "200");
    c.DrawTransparentText(0, 300, "300");
    c.DrawTransparentText(0, 400, "400");
    c.DrawTransparentText(0, 500, "500");
    c.DrawTransparentText(100, c.GetFontHeight(), "100");
    c.DrawTransparentText(200, c.GetFontHeight(), "200");
    c.DrawTransparentText(300, c.GetFontHeight(), "300");
    c.DrawTransparentText(400, c.GetFontHeight(), "400");
    c.DrawTransparentText(500, c.GetFontHeight(), "500");
    c.show();
    app.exec();
    }
    {
    c.Clear();
    c.DrawOutlineRectangle(100, 100, 200, 200, Color(255, 0, 0));
    c.show();
    app.exec();
    }
    {
    c.Clear();
    c.DrawRoundRectangle(100, 100, 200, 200, 10, 10);
    c.DrawRoundRectangle(200, 200, 300, 300, 100, 100);
    c.DrawRoundRectangle(300, 300, 400, 400, 50, 50);
    c.show();
    app.exec();
    }
    {
    c.Clear();
    PixelRect rc;
    rc.left   = 100;
    rc.top    = 100;
    rc.right  = 200;
    rc.bottom = 200;
    c.DrawRaisedEdge(rc);
    c.show();
    app.exec();
    }
    {
    c.Clear();
    RasterPoint rp[4];
    rp[0] = {100, 100};
    rp[1] = {200, 200};
    rp[2] = {200, 300};
    rp[3] = {300, 400};
    c.DrawPolyline(rp, 4);
    c.show();
    app.exec();
    }
    {
    c.Clear();
    RasterPoint rp[6];
    rp[0] = {100, 100};
    rp[1] = {150,  50};
    rp[2] = {200, 100};
    rp[3] = {200, 200};
    rp[4] = {150, 200};
    rp[5] = {100, 100};
    c.DrawPolygon(rp, 6);
    c.show();
    app.exec();
    }
    {
    c.Clear();
    RasterPoint rp[4];
    rp[0] = {100, 100};
    rp[1] = {200,  50};
    rp[2] = {200, 150};
    rp[3] = {150, 200};
    c.DrawTriangleFan(rp, 4);
    c.show();
    app.exec();
    }
    {
    c.Clear();
    c.DrawHLine(100, 200, 100, Color(255, 0, 0));
    c.DrawHLine(100, 200, 200, Color(0, 255, 0));
    c.DrawHLine(100, 200, 300, Color(0, 0, 255));
    c.show();
    app.exec();
    }
    {
    c.Clear();
    c.DrawLine(100, 100, 200, 200);
    c.DrawCircle(250, 250, 50);
    c.DrawSegment(100, 250, 50, Angle::Degrees(10), Angle::Degrees(30), false);
    c.show();
    app.exec();
    }
    {
    c.Clear();
    c.DrawAnnulus(100, 100, 50, 100, Angle::Degrees(10), Angle::Degrees(60));
    c.DrawAnnulus(300, 100, 50, 100, Angle::Degrees(0),  Angle::Degrees(360));
    c.DrawAnnulus(100, 300, 50, 100, Angle::Degrees(0),  Angle::Degrees(0));
    c.show();
    app.exec();
    }
    {
    PixelSize rc = c.CalcTextSize("Hello");
    std::cout << "Size of \"Hello\": " << rc.cx << ", " << rc.cy << std::endl;
    c.DrawClippedText(100, 100, rc.cx / 2, "Hello");
    c.show();
    app.exec();
    }
    {
    std::cout << "Height of font: " << c.GetFontHeight() << std::endl;
    }
    {
    c.Clear();
    c.DrawText(0, 50, "50");
    c.Clear();
    c.show();
    return app.exec();
    }
  }
Example #24
0
void
GaugeVario::RenderBugs(Canvas &canvas)
{
  static int last_bugs = -1;
  static PixelRect label_rect = {-1,-1,-1,-1};
  static PixelRect value_rect = {-1,-1,-1,-1};
  static RasterPoint label_pos = {-1,-1};
  static RasterPoint value_pos = {-1,-1};

  if (!bugs_initialised) {
    const PixelRect rc = GetClientRect();
    PixelSize tSize;

    label_pos.x = 1;
    label_pos.y = rc.bottom - 2
      - look.text_font->GetCapitalHeight()
      - look.text_font->GetAscentHeight();

    value_pos.x = 1;
    value_pos.y = rc.bottom - 1
      - look.text_font->GetAscentHeight();

    label_rect.left = label_pos.x;
    label_rect.top = label_pos.y
      + look.text_font->GetAscentHeight()
      - look.text_font->GetCapitalHeight();
    value_rect.left = value_pos.x;
    value_rect.top = value_pos.y
      + look.text_font->GetAscentHeight()
      - look.text_font->GetCapitalHeight();

    canvas.Select(*look.text_font);
    tSize = canvas.CalcTextSize(TEXT_BUG);

    label_rect.right = label_rect.left + tSize.cx;
    label_rect.bottom = label_rect.top
      + look.text_font->GetCapitalHeight()
      + look.text_font->GetHeight()
      - look.text_font->GetAscentHeight();

    tSize = canvas.CalcTextSize(_T("100%"));

    value_rect.right = value_rect.left + tSize.cx;
    value_rect.bottom = value_rect.top +
      look.text_font->GetCapitalHeight();

    bugs_initialised = true;
  }

  int bugs = iround((fixed(1) - GetComputerSettings().polar.bugs) * 100);
  if (!IsPersistent() || bugs != last_bugs) {

    canvas.Select(*look.text_font);

    if (IsPersistent())
      canvas.SetBackgroundColor(look.background_color);
    else
      canvas.SetBackgroundTransparent();

    if (IsPersistent() || last_bugs < 1 || bugs < 1) {
      if (bugs > 0) {
        canvas.SetTextColor(look.dimmed_text_color);
        if (IsPersistent())
          canvas.DrawOpaqueText(label_pos.x, label_pos.y, label_rect, TEXT_BUG);
        else
          canvas.DrawText(label_pos.x, label_pos.y, TEXT_BUG);
      } else if (IsPersistent())
        canvas.DrawFilledRectangle(label_rect, look.background_color);
    }

    if (bugs > 0) {
      TCHAR buffer[18];
      _stprintf(buffer, _T("%d%%"), bugs);
      canvas.SetTextColor(look.text_color);
      if (IsPersistent())
        canvas.DrawOpaqueText(value_pos.x, value_pos.y, value_rect, buffer);
      else 
        canvas.DrawText(value_pos.x, value_pos.y, buffer);
    } else if (IsPersistent())
      canvas.DrawFilledRectangle(value_rect, look.background_color);

    if (IsPersistent())
      last_bugs = bugs;
  }
}
Example #25
0
void
GaugeVario::RenderBallast(Canvas &canvas)
{
  static int last_ballast = -1;
  static PixelRect label_rect = {-1,-1,-1,-1};
  static PixelRect value_rect = {-1,-1,-1,-1};
  static RasterPoint label_pos = {-1,-1};
  static RasterPoint value_pos = {-1,-1};

  if (!ballast_initialised) { // ontime init, origin and background rect
    const PixelRect rc = GetClientRect();

    PixelSize tSize;

    // position of ballast label
    label_pos.x = 1;
    label_pos.y = rc.top + 2
      + look.text_font->GetCapitalHeight() * 2
      - look.text_font->GetAscentHeight();

    // position of ballast value
    value_pos.x = 1;
    value_pos.y = rc.top + 1
      + look.text_font->GetCapitalHeight()
      - look.text_font->GetAscentHeight();

    // set upper left corner
    label_rect.left = label_pos.x;
    label_rect.top = label_pos.y
      + look.text_font->GetAscentHeight()
      - look.text_font->GetCapitalHeight();

    // set upper left corner
    value_rect.left = value_pos.x;
    value_rect.top = value_pos.y
      + look.text_font->GetAscentHeight()
      - look.text_font->GetCapitalHeight();

    // get max label size
    canvas.Select(*look.text_font);
    tSize = canvas.CalcTextSize(TEXT_BALLAST);

    // update back rect with max label size
    label_rect.right = label_rect.left + tSize.cx;
    label_rect.bottom = label_rect.top +
      look.text_font->GetCapitalHeight();

    // get max value size
    tSize = canvas.CalcTextSize(_T("100%"));

    value_rect.right = value_rect.left + tSize.cx;
    // update back rect with max label size
    value_rect.bottom = value_rect.top +
      look.text_font->GetCapitalHeight();

    ballast_initialised = true;
  }

  int ballast = iround(GetGlidePolar().GetBallast() * 100);

  if (!IsPersistent() || ballast != last_ballast) {
    // ballast hase been changed

    canvas.Select(*look.text_font);

    if (IsPersistent())
      canvas.SetBackgroundColor(look.background_color);
    else
      canvas.SetBackgroundTransparent();

    if (IsPersistent() || last_ballast < 1 || ballast < 1) {
      // new ballast is 0, hide label
      if (ballast > 0) {
        canvas.SetTextColor(look.dimmed_text_color);
        // ols ballast was 0, show label
        if (IsPersistent())
          canvas.DrawOpaqueText(label_pos.x, label_pos.y, label_rect, TEXT_BALLAST);
        else
          canvas.DrawText(label_pos.x, label_pos.y, TEXT_BALLAST);
      } else if (IsPersistent())
        canvas.DrawFilledRectangle(label_rect, look.background_color);
    }

    // new ballast 0, hide value
    if (ballast > 0) {
      TCHAR buffer[18];
      _stprintf(buffer, _T("%u%%"), ballast);
      canvas.SetTextColor(look.text_color);

      if (IsPersistent())
        canvas.DrawOpaqueText(value_pos.x, value_pos.y, value_rect, buffer);
      else
        canvas.DrawText(value_pos.x, value_pos.y, buffer);
    } else if (IsPersistent())
      canvas.DrawFilledRectangle(value_rect, look.background_color);

    if (IsPersistent())
      last_ballast = ballast;
  }
}
Example #26
0
void
GaugeVario::RenderSpeedToFly(Canvas &canvas, int x, int y)
{
  if (!Basic().airspeed_available ||
      !Basic().total_energy_vario_available)
    return;

  static fixed last_v_diff;
  fixed v_diff;

  const unsigned arrow_y_size = Layout::Scale(3);
  const unsigned arrow_x_size = Layout::Scale(7);

  const PixelRect rc = GetClientRect();

  int nary = NARROWS * arrow_y_size;
  int ytop = rc.top + YOFFSET + nary; // JMW
  int ybottom = rc.bottom - YOFFSET - nary - Layout::FastScale(1);

  ytop += Layout::Scale(14);
  ybottom -= Layout::Scale(14);

  x = rc.right - 2 * arrow_x_size;

  // only draw speed command if flying and vario is not circling
  if ((Calculated().flight.flying)
      && (!Basic().gps.simulator || !Calculated().circling)) {
    v_diff = Calculated().V_stf - Basic().indicated_airspeed;
    v_diff = Clamp(v_diff, -DELTA_V_LIMIT, DELTA_V_LIMIT); // limit it
    v_diff = iround(v_diff/DELTA_V_STEP) * DELTA_V_STEP;
  } else
    v_diff = fixed(0);

  if (!IsPersistent() || last_v_diff != v_diff || dirty) {
    last_v_diff = v_diff;

    if (IsPersistent()) {
      // bottom (too slow)
      canvas.DrawFilledRectangle(x, ybottom + YOFFSET,
                                 x + arrow_x_size * 2 + 1,
                                 ybottom + YOFFSET + nary + arrow_y_size +
                                 Layout::FastScale(2),
                                 look.background_color);

      // top (too fast)
      canvas.DrawFilledRectangle(x, ytop - YOFFSET + 1,
                                 x + arrow_x_size * 2  +1,
                                 ytop - YOFFSET - nary + 1 - arrow_y_size -
                                 Layout::FastScale(2),
                                 look.background_color);
    }

    RenderClimb(canvas);

    canvas.SelectNullPen();

    if (look.colors) {
      if (positive(v_diff)) {
        // too slow
        canvas.Select(look.sink_brush);
      } else {
        canvas.Select(look.lift_brush);
      }
    } else {
      if (look.inverse)
        canvas.SelectWhiteBrush();
      else
        canvas.SelectBlackBrush();
    }

    if (positive(v_diff)) {
      // too slow
      y = ybottom;
      y += YOFFSET;

      while (positive(v_diff)) {
        if (v_diff > DELTA_V_STEP) {
          canvas.Rectangle(x, y,
                           x + arrow_x_size * 2 + 1, y + arrow_y_size - 1);
        } else {
          RasterPoint arrow[3];
          arrow[0].x = x;
          arrow[0].y = y;
          arrow[1].x = x + arrow_x_size;
          arrow[1].y = y + arrow_y_size - 1;
          arrow[2].x = x + 2 * arrow_x_size;
          arrow[2].y = y;
          canvas.DrawTriangleFan(arrow, 3);
        }
        v_diff -= DELTA_V_STEP;
        y += arrow_y_size;
      }
    } else if (negative(v_diff)) {
      // too fast
      y = ytop;
      y -= YOFFSET;

      while (negative(v_diff)) {
        if (v_diff < -DELTA_V_STEP) {
          canvas.Rectangle(x, y + 1,
                           x + arrow_x_size * 2 + 1, y - arrow_y_size + 2);
        } else {
          RasterPoint arrow[3];
          arrow[0].x = x;
          arrow[0].y = y;
          arrow[1].x = x + arrow_x_size;
          arrow[1].y = y - arrow_y_size + 1;
          arrow[2].x = x + 2 * arrow_x_size;
          arrow[2].y = y;
          canvas.DrawTriangleFan(arrow, 3);
        }
        v_diff += DELTA_V_STEP;
        y -= arrow_y_size;
      }
    }
  }
}
void
TabDisplay::PaintButton(Canvas &canvas, unsigned CaptionStyle,
                        const TCHAR *caption, const PixelRect &rc,
                        const Bitmap *bmp, const bool isDown, bool inverse)
{
  PixelRect rcTextFinal = rc;
  const UPixelScalar buttonheight = rc.bottom - rc.top;
  const PixelSize text_size = canvas.CalcTextSize(caption);
  const int textwidth = text_size.cx;
  const int textheight = text_size.cy;
  UPixelScalar textheightoffset = 0;

  if (textwidth > (rc.right - rc.left)) // assume 2 lines
    textheightoffset = std::max(0, (int)(buttonheight - textheight * 2) / 2);
  else
    textheightoffset = std::max(0, (int)(buttonheight - textheight) / 2);

  rcTextFinal.top += textheightoffset;

  canvas.DrawFilledRectangle(rc, canvas.GetBackgroundColor());

  if (bmp != nullptr) {
    const PixelSize bitmap_size = bmp->GetSize();
    const int offsetx = (rc.right - rc.left - bitmap_size.cx / 2) / 2;
    const int offsety = (rc.bottom - rc.top - bitmap_size.cy) / 2;

#ifdef ENABLE_OPENGL

    if (inverse) {
      OpenGL::glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);

      /* invert the texture color */
      OpenGL::glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_REPLACE);
      OpenGL::glTexEnvi(GL_TEXTURE_ENV, GL_SRC0_RGB, GL_TEXTURE);
      OpenGL::glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_ONE_MINUS_SRC_COLOR);

      /* copy the texture alpha */
      OpenGL::glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_REPLACE);
      OpenGL::glTexEnvi(GL_TEXTURE_ENV, GL_SRC0_ALPHA, GL_TEXTURE);
      OpenGL::glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA, GL_SRC_ALPHA);
    } else
      /* simple copy */
      OpenGL::glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);

    const GLEnable scope(GL_TEXTURE_2D);
    const GLBlend blend(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

    GLTexture &texture = *bmp->GetNative();
    texture.Bind();
    texture.Draw(rc.left + offsetx, rc.top + offsety);

#else
    if (inverse) // black background
      canvas.CopyNotOr(rc.left + offsetx,
                       rc.top + offsety,
                       bitmap_size.cx / 2,
                       bitmap_size.cy,
                       *bmp,
                       bitmap_size.cx / 2, 0);

    else
      canvas.CopyAnd(rc.left + offsetx,
                      rc.top + offsety,
                      bitmap_size.cx / 2,
                      bitmap_size.cy,
                      *bmp,
                      bitmap_size.cx / 2, 0);
#endif

  } else {
#ifndef USE_GDI
    if (IsDithered())
      CaptionStyle |= DT_UNDERLINE;
#endif

    canvas.DrawFormattedText(&rcTextFinal, caption, CaptionStyle);
  }
}
Example #28
0
void
Background::OnPaint(Canvas &canvas)
{
  canvas.DrawFilledRectangle(this->rect, this->color);
}
Example #29
0
void
GaugeVario::RenderBugs(Canvas &canvas)
{
    static int last_bugs = -1;
    static PixelRect recLabelBk = {-1,-1,-1,-1};
    static PixelRect recValueBk = {-1,-1,-1,-1};
    static RasterPoint orgLabel = {-1,-1};
    static RasterPoint orgValue = {-1,-1};

    if (!bugs_initialised) {
        const PixelRect rc = get_client_rect();
        PixelSize tSize;

        orgLabel.x = 1;
        orgLabel.y = rc.bottom - 2
                     - look.text_font->GetCapitalHeight()
                     - look.text_font->GetAscentHeight();

        orgValue.x = 1;
        orgValue.y = rc.bottom - 1
                     - look.text_font->GetAscentHeight();

        recLabelBk.left = orgLabel.x;
        recLabelBk.top = orgLabel.y
                         + look.text_font->GetAscentHeight()
                         - look.text_font->GetCapitalHeight();
        recValueBk.left = orgValue.x;
        recValueBk.top = orgValue.y
                         + look.text_font->GetAscentHeight()
                         - look.text_font->GetCapitalHeight();

        canvas.Select(*look.text_font);
        tSize = canvas.CalcTextSize(TextBug);

        recLabelBk.right = recLabelBk.left + tSize.cx;
        recLabelBk.bottom = recLabelBk.top
                            + look.text_font->GetCapitalHeight()
                            + look.text_font->GetHeight()
                            - look.text_font->GetAscentHeight();

        tSize = canvas.CalcTextSize(_T("100%"));

        recValueBk.right = recValueBk.left + tSize.cx;
        recValueBk.bottom = recValueBk.top +
                            look.text_font->GetCapitalHeight();

        bugs_initialised = true;
    }

    int bugs = iround((fixed_one - GetComputerSettings().polar.bugs) * 100);
    if (is_persistent() || bugs != last_bugs) {

        canvas.Select(*look.text_font);

        if (is_persistent())
            canvas.SetBackgroundColor(look.background_color);
        else
            canvas.SetBackgroundTransparent();

        if (is_persistent() || last_bugs < 1 || bugs < 1) {
            if (bugs > 0) {
                canvas.SetTextColor(look.dimmed_text_color);
                if (is_persistent())
                    canvas.text_opaque(orgLabel.x, orgLabel.y, recLabelBk, TextBug);
                else
                    canvas.text(orgLabel.x, orgLabel.y, TextBug);
            } else if (is_persistent())
                canvas.DrawFilledRectangle(recLabelBk, look.background_color);
        }

        if (bugs > 0) {
            TCHAR buffer[18];
            _stprintf(buffer, _T("%d%%"), bugs);
            canvas.SetTextColor(look.text_color);
            if (is_persistent())
                canvas.text_opaque(orgValue.x, orgValue.y, recValueBk, buffer);
            else
                canvas.text(orgValue.x, orgValue.y, buffer);
        } else if (is_persistent())
            canvas.DrawFilledRectangle(recValueBk, look.background_color);

        if (is_persistent())
            last_bugs = bugs;
    }
}
Example #30
0
void
GaugeVario::RenderBallast(Canvas &canvas)
{
    static unsigned last_ballast = -1;
    static PixelRect recLabelBk = {-1,-1,-1,-1};
    static PixelRect recValueBk = {-1,-1,-1,-1};
    static RasterPoint orgLabel = {-1,-1};
    static RasterPoint orgValue = {-1,-1};

    if (!ballast_initialised) { // ontime init, origin and background rect
        const PixelRect rc = get_client_rect();

        PixelSize tSize;

        // position of ballast label
        orgLabel.x = 1;
        orgLabel.y = rc.top + 2
                     + look.text_font->GetCapitalHeight() * 2
                     - look.text_font->GetAscentHeight();

        // position of ballast value
        orgValue.x = 1;
        orgValue.y = rc.top + 1
                     + look.text_font->GetCapitalHeight()
                     - look.text_font->GetAscentHeight();

        // set upper left corner
        recLabelBk.left = orgLabel.x;
        recLabelBk.top = orgLabel.y
                         + look.text_font->GetAscentHeight()
                         - look.text_font->GetCapitalHeight();

        // set upper left corner
        recValueBk.left = orgValue.x;
        recValueBk.top = orgValue.y
                         + look.text_font->GetAscentHeight()
                         - look.text_font->GetCapitalHeight();

        // get max label size
        canvas.Select(*look.text_font);
        tSize = canvas.CalcTextSize(TextBal);

        // update back rect with max label size
        recLabelBk.right = recLabelBk.left + tSize.cx;
        recLabelBk.bottom = recLabelBk.top +
                            look.text_font->GetCapitalHeight();

        // get max value size
        tSize = canvas.CalcTextSize(_T("100%"));

        recValueBk.right = recValueBk.left + tSize.cx;
        // update back rect with max label size
        recValueBk.bottom = recValueBk.top +
                            look.text_font->GetCapitalHeight();

        ballast_initialised = true;
    }

    unsigned ballast = uround(Calculated().common_stats.current_ballast * 100);

    if (!is_persistent() || ballast != last_ballast) {
        // ballast hase been changed

        canvas.Select(*look.text_font);

        if (is_persistent())
            canvas.SetBackgroundColor(look.background_color);
        else
            canvas.SetBackgroundTransparent();

        if (is_persistent() || last_ballast == 0 || ballast == 0) {
            // new ballast is 0, hide label
            if (ballast > 0) {
                canvas.SetTextColor(look.dimmed_text_color);
                // ols ballast was 0, show label
                if (is_persistent())
                    canvas.text_opaque(orgLabel.x, orgLabel.y, recLabelBk, TextBal);
                else
                    canvas.text(orgLabel.x, orgLabel.y, TextBal);
            } else if (is_persistent())
                canvas.DrawFilledRectangle(recLabelBk, look.background_color);
        }

        // new ballast 0, hide value
        if (ballast > 0) {
            TCHAR buffer[18];
            _stprintf(buffer, _T("%u%%"), ballast);
            canvas.SetTextColor(look.text_color);

            if (is_persistent())
                canvas.text_opaque(orgValue.x, orgValue.y, recValueBk, buffer);
            else
                canvas.text(orgValue.x, orgValue.y, buffer);
        } else if (is_persistent())
            canvas.DrawFilledRectangle(recValueBk, look.background_color);

        if (is_persistent())
            last_ballast = ballast;
    }
}