Exemplo n.º 1
0
void
ButtonWindow::OnPaint(Canvas &canvas)
{
  const bool focused = HasCursorKeys() ? HasFocus() : down;

  if (focused) {
    Pen pen(Layout::Scale(1), COLOR_BLACK);
    canvas.Select(pen);
    canvas.SelectHollowBrush();
    canvas.Rectangle(-1, -1, canvas.GetWidth(), canvas.GetHeight());
  }

  PixelRect rc(2, 2, canvas.GetWidth() - 4, canvas.GetHeight() - 4);

  if (down) {
    rc.left += Layout::FastScale(1);
    rc.top += Layout::FastScale(1);
  }

  canvas.DrawButton(GetClientRect(), down);

  canvas.SetTextColor(IsEnabled()
                      ? (IsDithered() && down ? COLOR_WHITE : COLOR_BLACK)
                      : COLOR_GRAY);
  canvas.SetBackgroundTransparent();

  unsigned style = GetTextStyle();
  if (IsDithered())
    style |= DT_UNDERLINE;

  canvas.DrawFormattedText(&rc, text.c_str(), style);
}
void
TerrainPreviewWindow::OnPaint(Canvas &canvas)
{
  const GlueMapWindow *map = UIGlobals::GetMap();
  if (map == nullptr)
    return;

  MapWindowProjection projection = map->VisibleProjection();
  if (!projection.IsValid()) {
    /* TODO: initialise projection to middle of map instead of bailing
       out */
    canvas.ClearWhite();
    return;
  }

  projection.SetScreenSize(canvas.GetSize());
  projection.SetScreenOrigin(canvas.GetWidth() / 2, canvas.GetHeight() / 2);

  Angle sun_azimuth(Angle::Degrees(-45));
  if (renderer.GetSettings().slope_shading == SlopeShading::SUN &&
      CommonInterface::Calculated().sun_data_available)
    sun_azimuth = CommonInterface::Calculated().sun_azimuth;

  renderer.Generate(projection, sun_azimuth);

#ifdef ENABLE_OPENGL
  /* enable clipping because the OpenGL terrain renderer uses a large
     texture that exceeds the window dimensions */
  GLCanvasScissor scissor(canvas);
#endif

  renderer.Draw(canvas, projection);
}
Exemplo n.º 3
0
gcc_pure
static bool
IsCircleVisible(const Canvas &canvas, PixelPoint center, unsigned radius)
{
  return int(center.x + radius) >= 0 && center.x < int(canvas.GetWidth() + radius) &&
    int(center.y + radius) >= 0 && center.y < int(canvas.GetHeight() + radius);
}
Exemplo n.º 4
0
void
BufferCanvas::Commit(Canvas &other)
{
  assert(IsDefined());
  assert(active);
  assert(GetWidth() == other.GetWidth());
  assert(GetHeight() == other.GetHeight());

  if (frame_buffer != NULL) {
    frame_buffer->Unbind();

    /* restore the old viewport */

    assert(OpenGL::translate == RasterPoint(0, 0));

    OpenGL::SetupViewport(old_size);

    OpenGL::translate = old_translate;

    glPopMatrix();

    /* copy frame buffer to screen */
    CopyTo(other);
  } else {
    assert(offset == other.offset);

    /* copy screen to texture */
    CopyToTexture(*texture, GetRect());
  }

  active = false;
}
Exemplo n.º 5
0
void
WindowList::Paint(Canvas &canvas)
{
    const auto &list = this->list;

    auto begin = list.rbegin(), end = list.rend();

    /* find the last full window which covers all the other windows
       behind it */
    for (auto i = begin; i != end; ++i) {
        Window &child = **i;
        if (IsFullWindow(child, canvas.GetWidth(), canvas.GetHeight()))
            begin = i;
    }

    for (auto i = begin; i != end; ++i) {
        Window &child = **i;
        if (!child.IsVisible())
            continue;

        SubCanvas sub_canvas(canvas, { child.GetLeft(), child.GetTop() },
                             child.GetSize());
        child.Setup(sub_canvas);
        child.OnPaint(sub_canvas);
    }
}
Exemplo n.º 6
0
void
WindowList::Paint(Canvas &canvas)
{
    const auto &list = this->list;

    auto begin = list.rbegin(), end = list.rend();

    /* find the last full window which covers all the other windows
       behind it */
    for (auto i = begin; i != end; ++i) {
        Window &child = **i;
        if (IsFullWindow(child, canvas.GetWidth(), canvas.GetHeight()))
            begin = i;
    }

    for (auto i = begin; i != end; ++i) {
        Window &child = **i;
        if (!child.IsVisible())
            continue;

        SubCanvas sub_canvas(canvas, { child.GetLeft(), child.GetTop() },
                             child.GetSize());
#ifdef USE_MEMORY_CANVAS
        if (sub_canvas.GetWidth() == 0 || sub_canvas.GetHeight() == 0)
            /* this child window is completely outside the physical
               screen */
            continue;
#endif

        child.Setup(sub_canvas);
        child.OnPaint(sub_canvas);
    }
}
Exemplo n.º 7
0
void
LargeTextWindow::OnPaint(Canvas &canvas)
{
    canvas.ClearWhite();

    PixelRect rc(0, 0, canvas.GetWidth() - 1, canvas.GetHeight() - 1);
    canvas.DrawOutlineRectangle(rc.left, rc.top, rc.right, rc.bottom,
                                COLOR_BLACK);

    if (value.empty())
        return;

    const PixelScalar padding = Layout::GetTextPadding();
    rc.Grow(-padding);

    canvas.SetBackgroundTransparent();
    canvas.SetTextColor(COLOR_BLACK);

    rc.top -= origin * GetFont().GetHeight();

#ifndef USE_GDI
    canvas.Select(GetFont());
#endif
    canvas.DrawFormattedText(&rc, value.c_str(), DT_LEFT | DT_WORDBREAK);
}
Exemplo n.º 8
0
gcc_pure
static bool
IsCircleVisible(const Canvas &canvas, int x, int y, unsigned radius)
{
  return int(x + radius) >= 0 && x < int(canvas.GetWidth() + radius) &&
    int(y + radius) >= 0 && y < int(canvas.GetHeight() + radius);
}
Exemplo n.º 9
0
void
InfoBoxPreview::OnPaint(Canvas &canvas)
{
  const bool is_current = i == parent->GetCurrentInfoBox();

  if (is_current)
    canvas.Clear(COLOR_BLACK);
  else
    canvas.ClearWhite();

  canvas.SelectHollowBrush();
  canvas.SelectBlackPen();
  canvas.Rectangle(0, 0, canvas.GetWidth() - 1, canvas.GetHeight() - 1);

  InfoBoxFactory::Type type = parent->GetContents(i);
  const TCHAR *caption = type < InfoBoxFactory::NUM_TYPES
    ? InfoBoxFactory::GetCaption(type)
    : NULL;
  if (caption == NULL)
    caption = _("Invalid");
  else
    caption = gettext(caption);

  canvas.Select(parent->GetInfoBoxLook().title_font);
  canvas.SetBackgroundTransparent();
  canvas.SetTextColor(is_current ? COLOR_WHITE : COLOR_BLACK);
  canvas.DrawText(2, 2, caption);
}
Exemplo n.º 10
0
void
InfoBoxPreview::OnPaint(Canvas &canvas)
{
  const unsigned i = this - previews;
  const bool is_current = i == current_preview;

  if (is_current)
    canvas.Clear(COLOR_BLACK);
  else
    canvas.ClearWhite();

  canvas.SelectHollowBrush();
  canvas.SelectBlackPen();
  canvas.Rectangle(0, 0, canvas.GetWidth() - 1, canvas.GetHeight() - 1);

  InfoBoxFactory::Type type = data.contents[i];
  const TCHAR *caption = type < InfoBoxFactory::NUM_TYPES
    ? InfoBoxFactory::GetCaption(type)
    : NULL;
  if (caption == NULL)
    caption = _("Invalid");
  else
    caption = gettext(caption);

  canvas.Select(*look->title.font);
  canvas.SetBackgroundTransparent();
  canvas.SetTextColor(is_current ? COLOR_WHITE : COLOR_BLACK);
  canvas.DrawText(2, 2, caption);
}
Exemplo n.º 11
0
  virtual void OnPaint(Canvas &canvas) override {
    canvas.ClearWhite();

    const GeoPoint a(Angle::Degrees(7.70722),
                     Angle::Degrees(51.052));
    const GeoPoint b(Angle::Degrees(11.5228),
                     Angle::Degrees(50.3972));

    WindowProjection projection;
    projection.SetScreenOrigin(canvas.GetWidth() / 2, canvas.GetHeight() / 2);
    projection.SetGeoLocation(a.Middle(b));
    projection.SetScreenSize(canvas.GetSize());
    projection.SetScaleFromRadius(fixed(400000));
    projection.UpdateScreenBounds();

    canvas.SelectBlackPen();
    canvas.SelectHollowBrush();

    RasterPoint pa = projection.GeoToScreen(a);
    canvas.DrawCircle(pa.x, pa.y, 4);

    RasterPoint pb = projection.GeoToScreen(b);
    canvas.DrawCircle(pb.x, pb.y, 4);

    RenderFAISector(canvas, projection, a, b, false, settings);
  }
Exemplo n.º 12
0
void
BufferCanvas::Commit(Canvas &other)
{
  assert(IsDefined());
  assert(active);
  assert(GetWidth() == other.GetWidth());
  assert(GetHeight() == other.GetHeight());

  if (frame_buffer != nullptr) {
    assert(OpenGL::translate.x == 0);
    assert(OpenGL::translate.y == 0);

    frame_buffer->Unbind();

    /* restore the old viewport */

    assert(OpenGL::translate == RasterPoint(0, 0));

#ifdef HAVE_GLES
    /* there's no glPopAttrib() on GL/ES; emulate it */
    glViewport(old_viewport[0], old_viewport[1],
               old_viewport[2], old_viewport[3]);
#else
    glPopAttrib();
#endif

#ifdef USE_GLSL
    OpenGL::projection_matrix = old_projection_matrix;
    OpenGL::UpdateShaderProjectionMatrix();
#else
    glMatrixMode(GL_PROJECTION);
    glPopMatrix();
    glMatrixMode(GL_MODELVIEW);
    glPopMatrix();
#endif

    OpenGL::translate = old_translate;
    OpenGL::viewport_size = old_size;

#ifdef USE_GLSL
    glVertexAttrib4f(OpenGL::Attribute::TRANSLATE,
                     OpenGL::translate.x, OpenGL::translate.y, 0, 0);
#endif

#ifdef SOFTWARE_ROTATE_DISPLAY
    OpenGL::display_orientation = old_orientation;
#endif

    /* copy frame buffer to screen */
    CopyTo(other);
  } else {
    assert(offset == other.offset);

    /* copy screen to texture */
    CopyToTexture(*texture, GetRect());
  }

  active = false;
}
Exemplo n.º 13
0
 /**
  * Basic ctor.
  */
 void testBasicCtor()
   {
   int argc = 0;
   TS_TRACE("Canvas basic ctor");
   QApplication app(argc, (char **)nullptr, 0); // Necessary to run up a Canvas.
   Canvas c;
   TS_ASSERT_EQUALS(c.IsDefined(), true);
   TS_ASSERT_EQUALS(c.GetWidth(), 0);
   TS_ASSERT_EQUALS(c.GetHeight(), 0);
   }
Exemplo n.º 14
0
void
WaypointDetailsWidget::OnImagePaint(Canvas &canvas, 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();
    fixed 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
    fixed 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);
  }
}
Exemplo n.º 15
0
void
InfoBoxWindow::Paint(Canvas &canvas)
{
  const Color background_color = pressed
    ? look.pressed_background_color
    : (HasFocus() || dragging || force_draw_selector
       ? look.focused_background_color
       : look.background_color);
  if (settings.border_style == InfoBoxSettings::BorderStyle::GLASS)
    DrawGlassBackground(canvas, canvas.GetRect(), background_color);
  else
    canvas.Clear(background_color);

  if (data.GetCustom() && content != NULL) {
    /* if there's no comment, the content object may paint that area,
       too */
    const PixelRect &rc = data.comment.empty()
      ? value_and_comment_rect
      : value_rect;
    content->OnCustomPaint(canvas, rc);
  }

  canvas.SetBackgroundTransparent();

  PaintTitle(canvas);
  PaintComment(canvas);
  PaintValue(canvas, background_color);

  if (border_kind != 0) {
    canvas.Select(look.border_pen);

    const UPixelScalar width = canvas.GetWidth(),
      height = canvas.GetHeight();

    if (border_kind & BORDERTOP) {
      canvas.DrawExactLine(0, 0, width - 1, 0);
    }

    if (border_kind & BORDERRIGHT) {
      canvas.DrawExactLine(width - 1, 0, width - 1, height);
    }

    if (border_kind & BORDERBOTTOM) {
      canvas.DrawExactLine(0, height - 1, width - 1, height - 1);
    }

    if (border_kind & BORDERLEFT) {
      canvas.DrawExactLine(0, 0, 0, height - 1);
    }
  }
}
Exemplo n.º 16
0
/**
 * Paints the basic info for the selected target on the given canvas
 * @param canvas The canvas to paint on
 */
void
FlarmTrafficControl::PaintTrafficInfo(Canvas &canvas) const
{
  // Don't paint numbers if no plane selected
  if (selection == -1 && !WarningMode())
    return;

  // Shortcut to the selected traffic
  FlarmTraffic traffic = data.list[WarningMode() ? warning : selection];
  assert(traffic.IsDefined());

  const unsigned padding = Layout::GetTextPadding();
  PixelRect rc;
  rc.left = padding;
  rc.top = padding;
  rc.right = canvas.GetWidth() - padding;
  rc.bottom = canvas.GetHeight() - padding;

  // Set the text color and background
  switch (traffic.alarm_level) {
  case FlarmTraffic::AlarmType::LOW:
  case FlarmTraffic::AlarmType::INFO_ALERT:
    canvas.SetTextColor(look.warning_color);
    break;
  case FlarmTraffic::AlarmType::IMPORTANT:
  case FlarmTraffic::AlarmType::URGENT:
    canvas.SetTextColor(look.alarm_color);
    break;
  case FlarmTraffic::AlarmType::NONE:
    canvas.SetTextColor(look.default_color);
    break;
  }

  canvas.SetBackgroundTransparent();

  // Climb Rate
  if (!WarningMode() && traffic.climb_rate_avg30s_available)
    PaintClimbRate(canvas, rc, traffic.climb_rate_avg30s);

  // Distance
  PaintDistance(canvas, rc, traffic.distance);

  // Relative Height
  PaintRelativeAltitude(canvas, rc, traffic.relative_altitude);

  // ID / Name
  if (!traffic.HasAlarm())
    canvas.SetTextColor(look.selection_color);

  PaintID(canvas, rc, traffic);
}
Exemplo n.º 17
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
  }
}
Exemplo n.º 18
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
  }
}
Exemplo n.º 19
0
bool
MapCanvas::IsVisible(const Canvas &canvas,
                     const RasterPoint *screen, unsigned num)
{
  PixelRect bounds;
  bounds.left = 0x7fff;
  bounds.top = 0x7fff;
  bounds.right = -1;
  bounds.bottom = -1;

  for (unsigned i = 0; i < num; ++i)
    UpdateBounds(bounds, screen[i]);

  return bounds.left < (int)canvas.GetWidth() && bounds.right >= 0 &&
    bounds.top < (int)canvas.GetHeight() && bounds.bottom >= 0;
}
Exemplo n.º 20
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
  }
}
Exemplo n.º 21
0
static void
OnLogoPaint(gcc_unused WndOwnerDrawFrame *Sender, Canvas &canvas)
{
  const UPixelScalar width = canvas.GetWidth();
  PixelScalar x = Layout::FastScale(10), y = x;

  canvas.ClearWhite();

  Bitmap title(width > 360 ? IDB_TITLE_HD : IDB_TITLE);

  // Determine title image size
  PixelSize title_size = title.GetSize();

  // Draw 'XCSoar N.N' title
  canvas.Copy(x, y, title_size.cx, title_size.cy, title, 0, 0);
  y += title_size.cy + Layout::FastScale(20);

  Font font;
  font.Load(GetStandardFontFace(), Layout::FastScale(16));
  canvas.Select(font);
  canvas.SetTextColor(COLOR_BLACK);
  canvas.SetBackgroundTransparent();

  canvas.DrawText(x, y, _T("version: "));
  canvas.DrawText(x + Layout::FastScale(80), y, XCSoar_VersionString);
  y += Layout::FastScale(22);

  canvas.DrawText(x, y, _T("date: "));
  canvas.DrawText(x + Layout::FastScale(80), y, _T(__DATE__));
#ifdef GIT_COMMIT_ID
  y += Layout::FastScale(22);

  canvas.DrawText(x, y, _T("git: "));
  canvas.DrawText(x + Layout::FastScale(80), y, _T(GIT_COMMIT_ID));
#endif
  y += Layout::FastScale(37);

  canvas.DrawText(x, y, _T("more information at"));
  y += Layout::FastScale(22);

  canvas.SetTextColor(COLOR_XCSOAR);
  canvas.DrawText(x, y, _T("http://www.xcsoar.org"));
}
Exemplo n.º 22
0
void
ProgressWindow::OnPaint(Canvas &canvas)
{
  canvas.Clear(background_color);

  // Determine window size
  const unsigned window_width = canvas.GetWidth();
  const unsigned window_height = canvas.GetHeight();

  PixelRect logo_rect;
  logo_rect.left = 0;
  logo_rect.top = 0;
  logo_rect.right = window_width;
  logo_rect.bottom = window_height - progress_border_height;
  logo.draw(canvas, logo_rect);

  // Draw progress bar background
  canvas.Stretch(0, (window_height - progress_border_height),
                 window_width, progress_border_height,
                 bitmap_progress_border);

  ContainerWindow::OnPaint(canvas);
}
Exemplo n.º 23
0
void
Canvas::Copy(const Canvas &src, int src_x, int src_y)
{
  Copy(0, 0, src.GetWidth(), src.GetHeight(), src, src_x, src_y);
}
Exemplo n.º 24
0
 void CopyAnd(const Canvas &src) {
   CopyAnd(0, 0, src.GetWidth(), src.GetHeight(),
           src.buffer, 0, 0);
 }
Exemplo n.º 25
0
 void Create(const Canvas &canvas) {
   Create(canvas, canvas.GetWidth(), canvas.GetHeight());
 }
Exemplo n.º 26
0
TEXLoader::IoStatus TEXLoader::WriteJpeg(const Canvas& canvas) {
	int size_offset = (int)save_file_->Tell();
	unsigned size = 0;
	save_file_->Write(size);	// We will update this data after writing the jpeg image.
	int start_offset = (int)save_file_->Tell();

	jpeg_compress_struct _c_info;
	jpeg_error_mgr j_err;
	_c_info.err = jpeg_std_error(&j_err);
	jpeg_create_compress(&_c_info);

	InitDestinationManager(&_c_info);

	_c_info.image_width = canvas.GetWidth();
	_c_info.image_height = canvas.GetHeight();

	if (canvas.GetBitDepth() == Canvas::kBitdepth8Bit) {
		_c_info.input_components = 1;
		_c_info.in_color_space = JCS_GRAYSCALE;
	} else {
		_c_info.input_components = 3;
		_c_info.in_color_space = JCS_RGB;
	}

	// If the image is in 8-bit mode, it is considered to be a grayscale image.
	// Otherwise, we must make sure that the image is in 24-bit kRgb mode.
	Canvas copy(canvas, true);
	if (copy.GetBitDepth() != Canvas::kBitdepth24Bit &&
	   copy.GetBitDepth() != Canvas::kBitdepth8Bit) {
		copy.ConvertBitDepth(Canvas::kBitdepth24Bit);
	}

	jpeg_set_defaults(&_c_info);
	jpeg_start_compress(&_c_info, TRUE);

	uint8* buffer = (uint8*)copy.GetBuffer();
	int row_stride = copy.GetPitch() * copy.GetPixelByteSize();
	int scan_lines = copy.GetHeight();

	JSAMPROW offset[1];
	offset[0] = buffer;

	for (int i = 0; i < scan_lines; i++) {
		jpeg_write_scanlines(&_c_info, offset, 1);
		offset[0] += row_stride;
	}

	jpeg_finish_compress(&_c_info);
	jpeg_destroy_compress(&_c_info);

	// Calculate and write the size of this jpeg image.
	const int end_offset = (int)save_file_->Tell();
	size = (unsigned)(end_offset - start_offset);
	save_file_->SeekSet(size_offset);
	save_file_->Write(size);

	// Go back to where we were...
	save_file_->SeekEnd(0);

	return kStatusSuccess;
}
Exemplo n.º 27
0
void
MapWindow::OnPaint(Canvas &canvas)
{
#ifdef ENABLE_OPENGL
  DoubleBufferWindow::OnPaint(canvas);
#else /* !ENABLE_OPENGL */
  if (buffer_generation == ui_generation)
    DoubleBufferWindow::OnPaint(canvas);
  else if (scale_buffer > 0 && visible_projection.IsValid() &&
           buffer_projection.IsValid()) {
    /* while zooming/panning, project the current buffer into the
       Canvas */

    --scale_buffer;

    /* do the projection */

    const UPixelScalar buffer_width = buffer_projection.GetScreenWidth();
    const UPixelScalar buffer_height = buffer_projection.GetScreenHeight();

    const RasterPoint top_left =
      visible_projection.GeoToScreen(buffer_projection.ScreenToGeo(0, 0));
    RasterPoint bottom_right =
      visible_projection.GeoToScreen(buffer_projection.ScreenToGeo(buffer_width,
                                                                   buffer_height));

    /* compensate for rounding errors in destination area */

    if (abs(buffer_width - (bottom_right.x - top_left.x)) < 5)
      bottom_right.x = top_left.x + buffer_width;

    if (abs(buffer_height - (bottom_right.y - top_left.y)) < 5)
      bottom_right.y = top_left.y + buffer_height;

    if (top_left.x > bottom_right.x || top_left.y > bottom_right.y) {
      /* paranoid sanity check */
      canvas.ClearWhite();
      return;
    }

    /* clear the areas around the buffer */

    canvas.SelectNullPen();
    canvas.SelectWhiteBrush();

    if (top_left.x > 0)
      canvas.Rectangle(0, 0, top_left.x, canvas.GetHeight());

    if (bottom_right.x < (int)canvas.GetWidth())
      canvas.Rectangle(bottom_right.x, 0,
                       canvas.GetWidth(), canvas.GetHeight());

    if (top_left.y > 0)
      canvas.Rectangle(top_left.x, 0, bottom_right.x, top_left.y);

    if (bottom_right.y < (int)canvas.GetHeight())
      canvas.Rectangle(top_left.x, bottom_right.y,
                       bottom_right.x, canvas.GetHeight());

    /* now stretch the buffer into the window Canvas */

    ScopeLock protect(DoubleBufferWindow::mutex);
    const Canvas &src = GetVisibleCanvas();
    canvas.Stretch(top_left.x, top_left.y,
                   bottom_right.x - top_left.x, bottom_right.y - top_left.y,
                   src, 0, 0, buffer_width, buffer_height);
  } else
    /* the UI has changed since the last DrawThread iteration has
       started: the buffer has invalid data, paint a white window
       instead */
    canvas.ClearWhite();
#endif /* !ENABLE_OPENGL */
}
Exemplo n.º 28
0
void
WndForm::OnPaint(Canvas &canvas)
{
  const SingleWindow &main_window = GetMainWindow();
  gcc_unused const bool is_active = main_window.IsTopDialog(*this);

#ifdef ENABLE_OPENGL
  if (!IsMaximised() && is_active) {
    /* draw a shade around the current dialog to emphasise it */
    GLEnable blend(GL_BLEND);
    glEnableClientState(GL_COLOR_ARRAY);

    const PixelRect rc = GetClientRect();
    const PixelScalar size = Layout::SmallScale(4);

    const RasterPoint vertices[8] = {
      { rc.left, rc.top },
      { rc.right, rc.top },
      { rc.right, rc.bottom },
      { rc.left, rc.bottom },
      { rc.left - size, rc.top - size },
      { rc.right + size, rc.top - size },
      { rc.right + size, rc.bottom + size },
      { rc.left - size, rc.bottom + size },
    };

    glVertexPointer(2, GL_VALUE, 0, vertices);

    static constexpr Color inner_color = COLOR_BLACK.WithAlpha(192);
    static constexpr Color outer_color = COLOR_BLACK.WithAlpha(16);
    static constexpr Color colors[8] = {
      inner_color,
      inner_color,
      inner_color,
      inner_color,
      outer_color,
      outer_color,
      outer_color,
      outer_color,
    };

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

    static constexpr GLubyte indices[] = {
      0, 4, 1, 4, 5, 1,
      1, 5, 2, 5, 6, 2,
      2, 6, 3, 6, 7, 3,
      3, 7, 0, 7, 4, 0,
    };

    glDrawElements(GL_TRIANGLES, ARRAY_SIZE(indices),
                   GL_UNSIGNED_BYTE, indices);

    glDisableClientState(GL_COLOR_ARRAY);
  }
#endif

  ContainerWindow::OnPaint(canvas);

  // Get window coordinates
  PixelRect rcClient = GetClientRect();

  // Draw the borders
  canvas.DrawRaisedEdge(rcClient);

  if (!caption.empty()) {
    // Set the colors
    canvas.SetTextColor(COLOR_WHITE);

    // Set the titlebar font and font-size
    canvas.Select(*look.caption.font);

    // JMW todo add here icons?

#ifdef EYE_CANDY
    canvas.SetBackgroundTransparent();
    canvas.Stretch(title_rect.left, title_rect.top,
                   title_rect.right - title_rect.left,
                   title_rect.bottom - title_rect.top,
                   look.caption.background_bitmap);

    // Draw titlebar text
    canvas.DrawText(title_rect.left + Layout::FastScale(2), title_rect.top,
                    caption.c_str());
#else
    canvas.SetBackgroundColor(is_active
                              ? look.caption.background_color
                              : look.caption.inactive_background_color);
    canvas.DrawOpaqueText(title_rect.left + Layout::FastScale(2),
                          title_rect.top, title_rect, caption.c_str());
#endif
  }

  if (dragging) {
#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)
    ::InvertRect(canvas, &title_rect);
#endif
  }
}
Exemplo n.º 29
0
void
WndForm::OnPaint(Canvas &canvas)
{
  const SingleWindow &main_window = GetMainWindow();
  gcc_unused const bool is_active = main_window.IsTopDialog(*this);

#ifdef ENABLE_OPENGL
  if (!IsDithered() && !IsMaximised() && is_active) {
    /* draw a shade around the current dialog to emphasise it */
    const ScopeAlphaBlend alpha_blend;

    const PixelRect rc = GetClientRect();
    const PixelScalar size = Layout::VptScale(4);

    const RasterPoint vertices[8] = {
      { rc.left, rc.top },
      { rc.right, rc.top },
      { rc.right, rc.bottom },
      { rc.left, rc.bottom },
      { rc.left - size, rc.top - size },
      { rc.right + size, rc.top - size },
      { rc.right + size, rc.bottom + size },
      { rc.left - size, rc.bottom + size },
    };

    const ScopeVertexPointer vp(vertices);

    static constexpr Color inner_color = COLOR_BLACK.WithAlpha(192);
    static constexpr Color outer_color = COLOR_BLACK.WithAlpha(16);
    static constexpr Color colors[8] = {
      inner_color,
      inner_color,
      inner_color,
      inner_color,
      outer_color,
      outer_color,
      outer_color,
      outer_color,
    };

    const ScopeColorPointer cp(colors);

    static constexpr GLubyte indices[] = {
      0, 4, 1, 4, 5, 1,
      1, 5, 2, 5, 6, 2,
      2, 6, 3, 6, 7, 3,
      3, 7, 0, 7, 4, 0,
    };

    glDrawElements(GL_TRIANGLES, ARRAY_SIZE(indices),
                   GL_UNSIGNED_BYTE, indices);
  }
#endif

  ContainerWindow::OnPaint(canvas);

  // Get window coordinates
  PixelRect rcClient = GetClientRect();

  // Draw the borders
  if (!IsMaximised()) {
#ifndef USE_GDI
    if (IsDithered())
      canvas.DrawOutlineRectangle(rcClient.left, rcClient.top,
                                  rcClient.right - 1, rcClient.bottom - 1,
                                  COLOR_BLACK);
    else
#endif
      canvas.DrawRaisedEdge(rcClient);
  }

  if (!caption.empty()) {
    // Set the colors
    canvas.SetTextColor(COLOR_WHITE);

    // Set the titlebar font and font-size
    canvas.Select(*look.caption.font);

    // JMW todo add here icons?

#ifdef EYE_CANDY
    if (!IsDithered() && is_active) {
      canvas.SetBackgroundTransparent();
      canvas.Stretch(title_rect.left, title_rect.top,
                     title_rect.right - title_rect.left,
                     title_rect.bottom - title_rect.top,
                     look.caption.background_bitmap);

      // Draw titlebar text
      canvas.DrawText(title_rect.left + Layout::GetTextPadding(),
                      title_rect.top, caption.c_str());
    } else {
#endif
      canvas.SetBackgroundColor(is_active
                                ? look.caption.background_color
                                : look.caption.inactive_background_color);
      canvas.DrawOpaqueText(title_rect.left + Layout::GetTextPadding(),
                            title_rect.top, title_rect, caption.c_str());
#ifdef EYE_CANDY
    }
#endif
  }

  if (dragging) {
#ifdef ENABLE_OPENGL
    const ScopeAlphaBlend alpha_blend;
    canvas.DrawFilledRectangle(0, 0, canvas.GetWidth(), canvas.GetHeight(),
                               COLOR_YELLOW.WithAlpha(80));
#elif defined(USE_GDI)
    canvas.InvertRectangle(title_rect);
#else
    canvas.InvertRectangle(GetClientRect());
#endif
  }
}
Exemplo n.º 30
0
void
InfoBoxWindow::PaintValue(Canvas &canvas, Color background_color)
{
  if (data.value.empty())
    return;

  canvas.SetTextColor(look.GetValueColor(data.value_color));

  // Do text-based unit rendering on higher resolutions
  if (look.unit_font.IsDefined()) {
    canvas.Select(look.unit_font);
    PixelScalar unit_width =
        UnitSymbolRenderer::GetSize(canvas, data.value_unit).cx;

    canvas.Select(look.value_font);
    int ascent_height = look.value_font.GetAscentHeight();

    PixelSize value_size = canvas.CalcTextSize(data.value);
    if (value_size.cx + unit_width > value_rect.right - value_rect.left) {
      canvas.Select(look.small_value_font);
      ascent_height = look.small_value_font.GetAscentHeight();
      value_size = canvas.CalcTextSize(data.value);
    }

    PixelScalar x = std::max(PixelScalar(0),
                             PixelScalar((value_rect.left + value_rect.right
                                          - value_size.cx - unit_width) / 2));

    PixelScalar y = (value_rect.top + value_rect.bottom - value_size.cy) / 2;

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

    if (unit_width != 0) {
      const int unit_height =
        UnitSymbolRenderer::GetAscentHeight(look.unit_font, data.value_unit);

      canvas.Select(look.unit_font);
      UnitSymbolRenderer::Draw(canvas,
                               { x + value_size.cx,
                                 y + ascent_height - unit_height },
                               data.value_unit, look.unit_fraction_pen);
    }
    return;
  }

  canvas.Select(look.value_font);
  UPixelScalar ascent_height = look.value_font.GetAscentHeight();
  UPixelScalar capital_height = look.value_font.GetCapitalHeight();

  PixelSize unit_size;
  const UnitSymbol *unit_symbol = units_look.GetSymbol(data.value_unit);
  if (unit_symbol != NULL) {
    unit_size = unit_symbol->GetSize();
  } else {
    unit_size.cx = 0;
    unit_size.cy = 0;
  }

  PixelSize value_size = canvas.CalcTextSize(data.value);
  if (value_size.cx + unit_size.cx > value_rect.right - value_rect.left) {
    canvas.Select(look.small_value_font);
    ascent_height = look.small_value_font.GetAscentHeight();
    capital_height = look.small_value_font.GetCapitalHeight();
    value_size = canvas.CalcTextSize(data.value);
  }

  PixelScalar x = std::max(PixelScalar(1),
                           PixelScalar((value_rect.left + value_rect.right
                                        - value_size.cx
                                        - Layout::FastScale(unit_size.cx)) / 2));

  PixelScalar y = value_rect.top + 1 - ascent_height +
    (value_rect.bottom - value_rect.top + capital_height) / 2;

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

  if (unit_symbol != NULL) {
#ifndef HAVE_CLIPPING
    /* sort-of clipping */
    if (x + value_size.cx >= (int)canvas.GetWidth())
      return;
#endif

    unit_symbol->Draw(canvas, x + value_size.cx,
                      y + ascent_height - unit_symbol->GetScreenSize().cy,
                      background_color,
                      look.GetValueColor(data.value_color));
  }
}