• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C++ Canvas类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中Canvas的典型用法代码示例。如果您正苦于以下问题:C++ Canvas类的具体用法?C++ Canvas怎么用?C++ Canvas使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Canvas类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: reset_cliprect

void WindowManagerProvider::reset_cliprect(GUITopLevelWindow *handle, Canvas &canvas)
{
	canvas.reset_cliprect();
}
开发者ID:eoma,项目名称:totem-edk,代码行数:4,代码来源:window_manager.cpp


示例2: OnPaint

 virtual void OnPaint(Canvas &canvas) override {
   canvas.ClearWhite();
   HorizonRenderer::Draw(canvas, canvas.GetRect(), look, attitude);
 }
开发者ID:Advi42,项目名称:XCSoar,代码行数:4,代码来源:RunHorizonRenderer.cpp


示例3: PixelScalar

void
InfoBoxWindow::PaintValue(Canvas &canvas)
{
  if (data.value.empty())
    return;

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

#ifndef GNAV
  // Do text-based unit rendering on higher resolutions
  if (Layout::FastScale(10) > 18) {
    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 > value_rect.right - value_rect.left) {
      canvas.Select(*look.small_font);
      ascent_height = look.small_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;
  }
#endif

  canvas.Select(*look.value.font);
  UPixelScalar ascent_height = look.value.font->GetAscentHeight();
  UPixelScalar capital_height = look.value.font->GetCapitalHeight();

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

  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;
  }

  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,
                      look.inverse ? UnitSymbol::INVERSE : UnitSymbol::NORMAL);
  }
}
开发者ID:StefanL74,项目名称:XCSoar,代码行数:90,代码来源:InfoBoxWindow.cpp


示例4: maFillRect

void maFillRect(int left, int top, int width, int height) {
  Canvas *drawTarget = graphics->getDrawTarget();
  if (drawTarget) {
    drawTarget->fillRect(left, top, width, height, graphics->getDrawColor());
  }
}
开发者ID:MarcusWellby,项目名称:SmallBASIC,代码行数:6,代码来源:graphics.cpp


示例5: RenderWindChart

void
RenderWindChart(Canvas &canvas, const PixelRect rc,
                const ChartLook &chart_look,
                const FlightStatistics &fs,
                const NMEAInfo &nmea_info,
                const WindStore &wind_store)
{
  unsigned numsteps = 10;
  bool found = true;

  LeastSquares windstats_mag;
  ChartRenderer chart(chart_look, canvas, rc);

  if (fs.altitude_ceiling.y_max - fs.altitude_ceiling.y_min <= fixed(10)) {
    chart.DrawNoData();
    return;
  }

  for (unsigned i = 0; i < numsteps; i++) {
    fixed h = fixed(fs.altitude_ceiling.y_max - fs.altitude_base.y_min) * i /
              (numsteps - 1) + fixed(fs.altitude_base.y_min);

    Vector wind = wind_store.GetWind(nmea_info.time, h, found);
    fixed mag = wind.Magnitude();

    windstats_mag.LeastSquaresUpdate(mag, h);
  }

  chart.ScaleXFromData(windstats_mag);
  chart.ScaleXFromValue(fixed(0));
  chart.ScaleXFromValue(fixed(10));

  chart.ScaleYFromData(windstats_mag);

  chart.DrawXGrid(Units::ToSysSpeed(fixed(5)),
                  ChartLook::STYLE_THINDASHPAPER, fixed(5), true);
  chart.DrawYGrid(Units::ToSysAltitude(fixed(1000)),
                  ChartLook::STYLE_THINDASHPAPER, fixed(1000), true);
  chart.DrawLineGraph(windstats_mag, ChartLook::STYLE_MEDIUMBLACK);

#define WINDVECTORMAG 25

  numsteps = (int)((rc.bottom - rc.top) / WINDVECTORMAG) - 1;

  canvas.Select(chart_look.GetPen(ChartLook::STYLE_MEDIUMBLACK));

  // draw direction vectors
  fixed hfact;
  for (unsigned i = 0; i < numsteps; i++) {
    hfact = fixed(i + 1) / (numsteps + 1);
    fixed h = fixed(fs.altitude_ceiling.y_max - fs.altitude_base.y_min) * hfact +
              fixed(fs.altitude_base.y_min);

    Vector wind = wind_store.GetWind(nmea_info.time, h, found);
    if (windstats_mag.x_max == fixed(0))
      windstats_mag.x_max = fixed(1); // prevent /0 problems
    wind.x /= fixed(windstats_mag.x_max);
    wind.y /= fixed(windstats_mag.x_max);
    fixed mag = wind.Magnitude();
    if (negative(mag))
      continue;

    Angle angle = Angle::FromXY(wind.y, -wind.x);

    RasterPoint point = chart.ToScreen((chart.GetXMin() + chart.GetXMax()) / 2, h);

    DrawArrow(canvas, point, mag * WINDVECTORMAG, angle);
  }

  chart.DrawXLabel(_T("w"), Units::GetSpeedName());
  chart.DrawYLabel(_T("h"), Units::GetAltitudeName());
}
开发者ID:robertscottbeattie,项目名称:xcsoardev,代码行数:72,代码来源:WindChartRenderer.cpp


示例6: plus_rc

void
DigitEntry::OnPaint(Canvas &canvas)
{
  assert(cursor < length);

  const bool focused = HasCursorKeys() && HasFocus();

  if (HaveClipping())
    canvas.Clear(look.background_color);

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

  const unsigned text_height = look.text_font.GetHeight();
  const int y = (top + bottom - text_height) / 2;

  PixelRect rc;
  rc.top = top;
  rc.bottom = bottom;

  TCHAR buffer[4];

  for (unsigned i = 0; i < length; ++i) {
    const Column &c = columns[i];

    rc.left = c.left;
    rc.right = c.right;

    if (focused && i == cursor) {
      canvas.SetTextColor(look.list.focused.text_color);
      canvas.SetBackgroundColor(look.list.focused.background_color);
    } else if (c.IsEditable()) {
      canvas.SetTextColor(look.list.text_color);
      canvas.SetBackgroundColor(look.list.background_color);
    } else {
      canvas.SetTextColor(look.list.text_color);
      canvas.SetBackgroundColor(look.background_color);
    }

    const TCHAR *text = buffer;
    buffer[1] = _T('\0');

    switch (c.type) {
    case Column::Type::DIGIT:
    case Column::Type::DIGIT6:
      assert(c.value < 10);
      buffer[0] = _T('0') + c.value;
      break;

    case Column::Type::HOUR:
      assert(c.value < 24);
      _stprintf(buffer, _T("%02u"), c.value);
      break;

    case Column::Type::DIGIT36:
      assert(c.value < 36);
      _stprintf(buffer, _T("%02u"), c.value);
      break;

    case Column::Type::DIGIT19:
      assert(c.value < 19);
      _stprintf(buffer, _T("%02u"), c.value);
      break;

    case Column::Type::SIGN:
      buffer[0] = c.IsNegative() ? _T('-') : _T('+');
      break;

    case Column::Type::DECIMAL_POINT:
      buffer[0] = _T('.');
      break;

    case Column::Type::COLON:
      buffer[0] = _T(':');
      break;

    case Column::Type::NORTH_SOUTH:
      buffer[0] = c.IsNegative() ? _T('S') : _T('N');
      break;

    case Column::Type::EAST_WEST:
      buffer[0] = c.IsNegative() ? _T('W') : _T('E');
      break;

    case Column::Type::DEGREES:
      text = _T("°");
      break;

    case Column::Type::APOSTROPHE:
      text = _T("'");
      break;

    case Column::Type::QUOTE:
      text = _T("\"");
      break;

    case Column::Type::UNIT:
      // TODO: render unit symbol?
      text = Units::unit_descriptors[c.value].name;
      break;
//.........这里部分代码省略.........
开发者ID:kwtskran,项目名称:XCSoar,代码行数:101,代码来源:DigitEntry.cpp


示例7: Draw

static void
Draw(Canvas &canvas, PixelRect rc,
     const ArrivalAltitudeMapItem &item,
     const TwoTextRowsRenderer &row_renderer,
     const FinalGlideBarLook &look)
{
  const unsigned line_height = rc.bottom - rc.top;

  bool elevation_available =
      !RasterBuffer::IsSpecial((short)item.elevation);

  bool reach_relevant = item.reach.IsReachRelevant();

  RoughAltitude arrival_altitude =
    item.reach.terrain_valid == ReachResult::Validity::VALID
    ? item.reach.terrain
    : item.reach.direct;
  if (elevation_available)
    arrival_altitude -= item.elevation;

  bool reachable =
    item.reach.terrain_valid != ReachResult::Validity::UNREACHABLE &&
    arrival_altitude.IsPositive();

  // Draw final glide arrow icon

  const RasterPoint pt(rc.left + line_height / 2, rc.top + line_height / 2);

  RasterPoint arrow[] = {
      { -7, -3 }, { 0, 4 }, { 7, -3 }
  };

  Angle arrow_angle = reachable ? Angle::HalfCircle() : Angle::Zero();
  PolygonRotateShift(arrow, ARRAY_SIZE(arrow), pt, arrow_angle);

  if (reachable) {
    canvas.Select(look.brush_above);
    canvas.Select(look.pen_above);
  } else {
    canvas.Select(look.brush_below);
    canvas.Select(look.pen_below);
  }
  canvas.DrawPolygon(arrow, ARRAY_SIZE(arrow));

  const unsigned text_padding = Layout::GetTextPadding();
  rc.left += line_height + text_padding;

  // Format title row

  TCHAR altitude_buffer[32];
  StaticString<256> buffer;
  buffer.clear();

  if (elevation_available) {
    RoughAltitude relative_arrival_altitude =
      item.reach.direct - item.elevation;

    FormatRelativeUserAltitude(fixed((short)relative_arrival_altitude),
                               altitude_buffer, ARRAY_SIZE(altitude_buffer));

    buffer.AppendFormat(_T("%s %s, "), altitude_buffer, _("AGL"));
  }

  buffer.AppendFormat(_T("%s %s"),
                      FormatUserAltitude(fixed(item.reach.direct)).c_str(),
                      _("MSL"));

  // Draw title row

  row_renderer.DrawFirstRow(canvas, rc, buffer);

  // Format comment row

  if (reach_relevant) {
    buffer.Format(_T("%s: "), _("around terrain"));

    if (elevation_available) {
      RoughAltitude relative_arrival_altitude =
          item.reach.terrain - item.elevation;

      FormatRelativeUserAltitude(fixed((short)relative_arrival_altitude),
                                 altitude_buffer, ARRAY_SIZE(altitude_buffer));

     buffer.AppendFormat(_T("%s %s, "), altitude_buffer, _("AGL"));
    }

    buffer.AppendFormat(_T("%s %s, "),
                        FormatUserAltitude(fixed(item.reach.terrain)).c_str(),
                        _("MSL"));
  } else if (elevation_available &&
             (int)item.reach.direct >= (int)item.elevation &&
             item.reach.terrain_valid == ReachResult::Validity::UNREACHABLE) {
    buffer.UnsafeFormat(_T("%s "), _("Unreachable due to terrain."));
  } else {
    buffer.clear();
  }

  buffer += _("Arrival altitude incl. safety height");

  // Draw comment row
//.........这里部分代码省略.........
开发者ID:Andy-1954,项目名称:XCSoar,代码行数:101,代码来源:MapItemListRenderer.cpp


示例8: if

void
FinalGlideBarRenderer::Draw(Canvas &canvas, const PixelRect &rc,
                            const DerivedInfo &calculated) const
{
  RasterPoint GlideBar[6] = {
      { 0, 0 }, { 9, -9 }, { 18, 0 }, { 18, 0 }, { 9, 0 }, { 0, 0 }
  };
  RasterPoint GlideBar0[6] = {
      { 0, 0 }, { 9, -9 }, { 18, 0 }, { 18, 0 }, { 9, 0 }, { 0, 0 }
  };

  TCHAR Value[10];

  if (!calculated.task_stats.task_valid ||
      !calculated.task_stats.total.solution_remaining.IsOk() ||
      !calculated.task_stats.total.solution_mc0.IsDefined())
    return;

  const int y0 = (rc.bottom + rc.top) / 2;

  // 60 units is size, div by 8 means 60*8 = 480 meters.
  int Offset = ((int)calculated.task_stats.total.solution_remaining.altitude_difference) / 8;
  int Offset0 = ((int)calculated.task_stats.total.solution_mc0.altitude_difference) / 8;
  // TODO feature: should be an angle if in final glide mode

  if (Offset > 60)
    Offset = 60;
  if (Offset < -60)
    Offset = -60;

  Offset = Layout::Scale(Offset);
  if (Offset < 0)
    GlideBar[1].y = Layout::Scale(9);

  if (Offset0 > 60)
    Offset0 = 60;
  if (Offset0 < -60)
    Offset0 = -60;

  Offset0 = Layout::Scale(Offset0);
  if (Offset0 < 0)
    GlideBar0[1].y = Layout::Scale(9);

  for (unsigned i = 0; i < 6; i++) {
    GlideBar[i].y += y0;
    GlideBar[i].x = Layout::Scale(GlideBar[i].x) + rc.left;
  }

  GlideBar[0].y -= Offset;
  GlideBar[1].y -= Offset;
  GlideBar[2].y -= Offset;

  for (unsigned i = 0; i < 6; i++) {
    GlideBar0[i].y += y0;
    GlideBar0[i].x = Layout::Scale(GlideBar0[i].x) + rc.left;
  }

  GlideBar0[0].y -= Offset0;
  GlideBar0[1].y -= Offset0;
  GlideBar0[2].y -= Offset0;

  if ((Offset < 0) && (Offset0 < 0)) {
    // both below
    if (Offset0 != Offset) {
      PixelScalar dy = (GlideBar0[0].y - GlideBar[0].y) +
          (GlideBar0[0].y - GlideBar0[3].y);
      dy = max(Layout::Scale(3), dy);
      GlideBar[3].y = GlideBar0[0].y - dy;
      GlideBar[4].y = GlideBar0[1].y - dy;
      GlideBar[5].y = GlideBar0[2].y - dy;

      GlideBar0[0].y = GlideBar[3].y;
      GlideBar0[1].y = GlideBar[4].y;
      GlideBar0[2].y = GlideBar[5].y;
    } else {
      Offset0 = 0;
    }
  } else if ((Offset > 0) && (Offset0 > 0)) {
    // both above
    GlideBar0[3].y = GlideBar[0].y;
    GlideBar0[4].y = GlideBar[1].y;
    GlideBar0[5].y = GlideBar[2].y;

    if (abs(Offset0 - Offset) < Layout::Scale(4))
      Offset = Offset0;
  }

  // draw actual glide bar
  if (Offset <= 0) {
    if (calculated.common_stats.landable_reachable) {
      canvas.Select(look.hpFinalGlideBelowLandable);
      canvas.Select(look.hbFinalGlideBelowLandable);
    } else {
      canvas.Select(look.hpFinalGlideBelow);
      canvas.Select(look.hbFinalGlideBelow);
    }
  } else {
    canvas.Select(look.hpFinalGlideAbove);
    canvas.Select(look.hbFinalGlideAbove);
  }
//.........这里部分代码省略.........
开发者ID:,项目名称:,代码行数:101,代码来源:


示例9: draw

        void Player::draw(Canvas &canvas) {
            canvas.fillRect(x, y, x + WIDTH, y + HEIGHT);

            // update velocity
            computeVelocity();
        }
开发者ID:vbmacher,项目名称:learning-kit,代码行数:6,代码来源:player.cpp


示例10: activate

	/// set focus on the viewport and make canvas current
	void activate()
	{
		mSelf->setFocus();
		mCanvas->workspace()->setCurrentCanvas(mCanvas);
	}
开发者ID:h2so5,项目名称:PaintField,代码行数:6,代码来源:canvasviewport.cpp


示例11: onClicked

	void onClicked()
	{
		mSelf->setFocus();
		mCanvas->workspace()->setCurrentCanvas(mCanvas);
	}
开发者ID:h2so5,项目名称:PaintField,代码行数:5,代码来源:canvasviewport.cpp


示例12: assert

VirtualCanvas::VirtualCanvas(const Canvas &canvas, PixelSize new_size)
  :Canvas(::CreateCompatibleDC(canvas), new_size)
{
  assert(canvas.IsDefined());
}
开发者ID:DRIZO,项目名称:xcsoar,代码行数:5,代码来源:VirtualCanvas.cpp


示例13: LBASSERT

void Display::discoverLocal( Config* config, const uint32_t flags )
{
    Node* node = config->findAppNode();
    LBASSERT( node );
    if( !node )
        return;

    const Pipes& pipes = node->getPipes();
    LBASSERT( !pipes.empty( ));
    if( pipes.empty( ))
        return;

    Pipe* pipe = pipes.front();
    Window* window = new Window( pipe );
    window->setViewport( Viewport( .25f, .2f, .5f, .5f ));
    window->setName( pipe->getName() + " window" );
    window->setIAttribute( Window::IATTR_PLANES_STENCIL, 1 );

    Channel* channel = new Channel( window );
    channel->setName( pipe->getName() + " channel" );
    Observer* observer = new Observer( config );

    const PixelViewport& pvp = pipe->getPixelViewport();
    Wall wall;
    if( pvp.isValid( ))
        wall.resizeHorizontalToAR( float( pvp.w ) / float( pvp.h ));

    Canvas* canvas = new Canvas( config );
    canvas->setWall( wall );

    Segment* segment = new Segment( canvas );
    segment->setChannel( channel );

    Strings names;
    const Nodes& nodes = config->getNodes();
    const bool scalability = nodes.size() > 1 || pipes.size() > 1;

    if( scalability )
        names.push_back( EQ_SERVER_CONFIG_LAYOUT_2D_DYNAMIC );

    names.push_back( EQ_SERVER_CONFIG_LAYOUT_SIMPLE );

    if( scalability )
    {
        names.push_back( EQ_SERVER_CONFIG_LAYOUT_DB_DS );
        names.push_back( EQ_SERVER_CONFIG_LAYOUT_DB_STATIC );
        names.push_back( EQ_SERVER_CONFIG_LAYOUT_DB_DYNAMIC );
        if( flags & fabric::ConfigParams::FLAG_MULTIPROCESS_DB &&
            nodes.size() > 1 )
        {
            for( NodesCIter i = nodes.begin(); i != nodes.end(); ++i )
            {
                if( (*i)->getPipes().size() > 1 )
                {
                    names.push_back( EQ_SERVER_CONFIG_LAYOUT_DB_2D );
                    break;
                }
            }
        }
    }

    for( StringsCIter i = names.begin(); i != names.end(); ++i )
    {
        Layout* layout = new Layout( config );
        layout->setName( *i );

        View* view = new View( layout );
        view->setObserver( observer );
        view->setWall( wall );

        canvas->addLayout( layout );
    }

    config->activateCanvas( canvas );
}
开发者ID:swq0553,项目名称:Equalizer,代码行数:75,代码来源:display.cpp


示例14: load

	Font Font::load(Canvas &canvas, const std::string &family_name, const FontDescription &reference_desc, FontFamily &font_family, const XMLResourceDocument &doc, std::function<Resource<Sprite>(Canvas &, const std::string &)> cb_get_sprite)
	{
		DomElement font_element;
		XMLResourceNode resource;

		resource = doc.get_resource(family_name);
		font_element = resource.get_element();

		DomElement sprite_element = font_element.named_item("sprite").to_element();

		if (!sprite_element.is_null())
		{
			if (!sprite_element.has_attribute("glyphs"))
				throw Exception(string_format("Font resource %1 has no 'glyphs' attribute.", resource.get_name()));

			if (!sprite_element.has_attribute("letters"))
				throw Exception(string_format("Font resource %1 has no 'letters' attribute.", resource.get_name()));

			if (!cb_get_sprite)
				throw Exception(string_format("Font resource %1 requires a sprite loader callback specified.", resource.get_name()));
				
			Resource<Sprite> spr_glyphs = cb_get_sprite(canvas, sprite_element.get_attribute("glyphs"));

			const std::string &letters = sprite_element.get_attribute("letters");

			int spacelen = StringHelp::text_to_int(sprite_element.get_attribute("spacelen", "-1"));
			bool monospace = StringHelp::text_to_bool(sprite_element.get_attribute("monospace", "false"));

			// Modify the default font metrics, if specified

			float height = 0.0f;
			float line_height = 0.0f;
			float ascent = 0.0f;
			float descent = 0.0f;
			float internal_leading = 0.0f;
			float external_leading = 0.0f;

			if (sprite_element.has_attribute("height"))
				height = StringHelp::text_to_float(sprite_element.get_attribute("height", "0"));

			if (sprite_element.has_attribute("line_height"))
				line_height = StringHelp::text_to_float(sprite_element.get_attribute("line_height", "0"));

			if (sprite_element.has_attribute("ascent"))
				ascent = StringHelp::text_to_float(sprite_element.get_attribute("ascent", "0"));

			if (sprite_element.has_attribute("descent"))
				descent = StringHelp::text_to_float(sprite_element.get_attribute("descent", "0"));

			if (sprite_element.has_attribute("internal_leading"))
				internal_leading = StringHelp::text_to_float(sprite_element.get_attribute("internal_leading", "0"));

			if (sprite_element.has_attribute("external_leading"))
				external_leading = StringHelp::text_to_float(sprite_element.get_attribute("external_leading", "0"));

			FontMetrics font_metrics(height, ascent, descent, internal_leading, external_leading, line_height, canvas.get_pixel_ratio());

			font_family.add(canvas, spr_glyphs.get(), letters, spacelen, monospace, font_metrics);

			FontDescription desc = reference_desc.clone();
			return Font(font_family, desc);
		}

		DomElement ttf_element = font_element.named_item("ttf").to_element();
		if (ttf_element.is_null())
			ttf_element = font_element.named_item("freetype").to_element();

		if (!ttf_element.is_null())
		{
			FontDescription desc = reference_desc.clone();

			std::string filename;
			if (ttf_element.has_attribute("file"))
			{
				filename = PathHelp::combine(resource.get_base_path(), ttf_element.get_attribute("file"));
			}

			if (!ttf_element.has_attribute("typeface"))
				throw Exception(string_format("Font resource %1 has no 'typeface' attribute.", resource.get_name()));

			std::string font_typeface_name = ttf_element.get_attribute("typeface");

			if (ttf_element.has_attribute("height"))
				desc.set_height(ttf_element.get_attribute_int("height", 0));

			if (ttf_element.has_attribute("average_width"))
				desc.set_average_width(ttf_element.get_attribute_int("average_width", 0));

			if (ttf_element.has_attribute("anti_alias"))
				desc.set_anti_alias(ttf_element.get_attribute_bool("anti_alias", true));

			if (ttf_element.has_attribute("subpixel"))
				desc.set_subpixel(ttf_element.get_attribute_bool("subpixel", true));

			if (filename.empty())
			{
				font_family.add(font_typeface_name, desc);
				return Font(font_family, desc);
			}
			else
//.........这里部分代码省略.........
开发者ID:tornadocean,项目名称:ClanLib,代码行数:101,代码来源:font_xml.cpp


示例15: DrawElement

 result DrawElement(const Osp::Graphics::Canvas& canvas, const Osp::Graphics::Rectangle& rect, CustomListItemStatus itemStatus)
 {
     result r = E_SUCCESS;

     Canvas* pCanvas = const_cast<Canvas*>(&canvas);

     pCanvas->SetLineWidth(1);
     if (itemStatus == CUSTOM_LIST_ITEM_STATUS_SELECTED) {
    	 pCanvas->FillRectangle(Color(4,58,99), rect);
     }
     pCanvas->SetForegroundColor(Color::COLOR_WHITE);

     Font fontcol1;
     fontcol1.Construct(Osp::Graphics::FONT_STYLE_PLAIN, 36);
     Font fontcol2;
     fontcol2.Construct(Osp::Graphics::FONT_STYLE_PLAIN, 28);
     Font fontcol3;
     fontcol3.Construct(Osp::Graphics::FONT_STYLE_PLAIN, 36);
     Font fontcol4;
     fontcol4.Construct(Osp::Graphics::FONT_STYLE_PLAIN, 28);

     EnrichedText texteelcol1;
     texteelcol1.Construct(Dimension(280, 50));
     texteelcol1.SetHorizontalAlignment(Osp::Graphics::TEXT_ALIGNMENT_LEFT);
     texteelcol1.SetVerticalAlignment(Osp::Graphics::TEXT_ALIGNMENT_TOP);
     texteelcol1.SetTextAbbreviationEnabled(true);
     if ((searchq.GetLength() > 0) && (col1s.GetLength() > 0)) {
     TextElement * textelcol1b = new TextElement();
     textelcol1b->Construct(L" ");
     if (col1b.GetLength() > 0) {
     textelcol1b->SetText(col1b);
     textelcol1b->SetTextColor(Color::COLOR_WHITE);
     textelcol1b->SetFont(fontcol1);
     texteelcol1.Add(*textelcol1b);
     }
     TextElement * textelcol1s = new TextElement();
     textelcol1s->Construct(col1s);
     textelcol1s->SetTextColor(Color(237,255,0));
     textelcol1s->SetFont(fontcol1);
     texteelcol1.Add(*textelcol1s);
     TextElement * textelcol1a = new TextElement();
     textelcol1a->Construct(L" ");
     if (col1a.GetLength() > 0) {
     textelcol1a->SetText(col1a);
     textelcol1a->SetTextColor(Color::COLOR_WHITE);
     textelcol1a->SetFont(fontcol1);
     texteelcol1.Add(*textelcol1a);
     }
     pCanvas->DrawText(Point(20,15), texteelcol1);
     delete textelcol1b;
     delete textelcol1s;
     delete textelcol1a;
     } else {
     TextElement textelcol1;
     textelcol1.Construct(col1);
     textelcol1.SetTextColor(Color::COLOR_WHITE);
     textelcol1.SetFont(fontcol1);
     texteelcol1.Add(textelcol1);
     pCanvas->DrawText(Point(20,15), texteelcol1);
     }

	 EnrichedText texteelcol2;
     texteelcol2.Construct(Dimension(280, 40));
     texteelcol2.SetHorizontalAlignment(Osp::Graphics::TEXT_ALIGNMENT_LEFT);
     texteelcol2.SetVerticalAlignment(Osp::Graphics::TEXT_ALIGNMENT_TOP);
     texteelcol2.SetTextAbbreviationEnabled(true);
     TextElement textelcol2;
     textelcol2.Construct(col2);
     if (itemStatus == CUSTOM_LIST_ITEM_STATUS_SELECTED) {
     textelcol2.SetTextColor(Color::COLOR_WHITE);
     } else {
     textelcol2.SetTextColor(Color(10, 73, 136));
     }
     textelcol2.SetFont(fontcol2);
     texteelcol2.Add(textelcol2);
     if ((searchq.GetLength() > 0) && (col4.GetLength() > 0)) {
    	 pCanvas->DrawText(Point(20,53), texteelcol2);
     } else {
    	 pCanvas->DrawText(Point(20,60), texteelcol2);
     }

     EnrichedText texteelcol3;
     texteelcol3.Construct(Dimension(160, 70));
     texteelcol3.SetHorizontalAlignment(Osp::Graphics::TEXT_ALIGNMENT_RIGHT);
     texteelcol3.SetVerticalAlignment(Osp::Graphics::TEXT_ALIGNMENT_MIDDLE);
     TextElement textelcol3;
     textelcol3.Construct(col3);
     textelcol3.SetTextColor(Color::COLOR_WHITE);
     textelcol3.SetFont(fontcol3);
     texteelcol3.Add(textelcol3);
	 pCanvas->DrawText(Point(300,15), texteelcol3);

	 if ((searchq.GetLength() > 0) && (col4.GetLength() > 0)) {
	 EnrichedText texteelcol4;
     texteelcol4.Construct(Dimension(430, 60));
     texteelcol4.SetHorizontalAlignment(Osp::Graphics::TEXT_ALIGNMENT_LEFT);
     texteelcol4.SetVerticalAlignment(Osp::Graphics::TEXT_ALIGNMENT_TOP);
     texteelcol4.SetTextAbbreviationEnabled(true);
     texteelcol4.SetTextWrapStyle(TEXT_WRAP_WORD_WRAP);
     if ((searchq.GetLength() > 0) && (col4s.GetLength() > 0)) {
//.........这里部分代码省略.........
开发者ID:BoboTheRobot,项目名称:Badaprojects,代码行数:101,代码来源:FTrip.cpp


示例16: gettext

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);
}
开发者ID:kwtskran,项目名称:XCSoar,代码行数:28,代码来源:dlgConfigInfoboxes.cpp


示例17: OnAirspaceListItemPaint

static void
OnAirspaceListItemPaint(Canvas &canvas, const PixelRect paint_rc, unsigned i)
{
  TCHAR sTmp[128];
  const int paint_rc_margin = 2;   ///< This constant defines the margin that should be respected for renderring within the paint_rc area.

  bool ack1_vis;
  bool ack2_vis;
  bool ack_vis;
  bool enable_vis;
  bool update_vis = false;

  {
    ProtectedAirspaceWarningManager::Lease lease(*airspace_warnings);
    if (lease->empty()) {
      // the warnings were emptied between the opening of the dialog
      // and this refresh, so only need to display "No Warnings" for
      // top item, otherwise exit immediately
      if (i==0) {
        canvas.text(paint_rc.left + IBLSCALE(paint_rc_margin),
                    paint_rc.top + IBLSCALE(paint_rc_margin), _("No Warnings"));
      }
      return;
    }
    
    if (i >= lease->size())
      /* this cannot be an assertion, because another thread may have
         modified the AirspaceWarningManager */
      return;
    
    const AirspaceWarning warning = *(lease->get_warning(i));
    const AbstractAirspace& as = warning.get_airspace();
    const AirspaceInterceptSolution& solution = warning.get_solution();
    
    tstring sName = as.get_name_text(false);
    tstring sTop = as.get_top_text(true);
    tstring sBase = as.get_base_text(true);
    tstring sType = as.get_type_text(true);
    
    const int TextHeight = 12, TextTop = 1;

    const int statusColWidth = canvas.text_width(_T("inside"));     //<-- word "inside" is used as the etalon, because it is longer than "near" and currently (9.4.2011) there is no other possibility for the status text.
    const int heightColWidth = canvas.text_width(_T("1888 m AGL")); // <-- "1888" is used in order to have enough space for 4-digit heights with "AGL"


    /// Dynamic columns scaling - "name" column is flexible, altitude and state columns are fixed-width.
    const int Col0LeftScreenCoords = Layout::FastScale(paint_rc_margin),
        Col2LeftScreenCoords = paint_rc.right - Layout::FastScale(paint_rc_margin) - (statusColWidth + 2 * Layout::FastScale(paint_rc_margin)),
        Col1LeftScreenCoords = Col2LeftScreenCoords - Layout::FastScale(paint_rc_margin) - heightColWidth;

    PixelRect rcTextClip;
    
    rcTextClip = paint_rc;
    rcTextClip.right = Col1LeftScreenCoords - Layout::FastScale(paint_rc_margin);
    
    Color old_text_color = canvas.get_text_color();
    if (!warning.get_ack_expired())
      canvas.set_text_color(COLOR_GRAY);
    
    { // name, altitude info
      _stprintf(sTmp, _T("%-20s"), sName.c_str());
      
      canvas.text_clipped(paint_rc.left + Col0LeftScreenCoords,
                          paint_rc.top + IBLSCALE(TextTop),
                          rcTextClip, sTmp);
      
      _stprintf(sTmp, _T("%-20s"), sTop.c_str());
      canvas.text(paint_rc.left + Col1LeftScreenCoords,
                  paint_rc.top + IBLSCALE(TextTop), sTmp);
      
      _stprintf(sTmp, _T("%-20s"), sBase.c_str());
      canvas.text(paint_rc.left + Col1LeftScreenCoords,
                  paint_rc.top + IBLSCALE(TextTop + TextHeight),
                  sTmp);
    }
    
    if (warning.get_warning_state() != AirspaceWarning::WARNING_INSIDE &&
        warning.get_warning_state() > AirspaceWarning::WARNING_CLEAR) {
      
      _stprintf(sTmp, _T("%d secs dist %d m"),
                (int)solution.elapsed_time,
                (int)solution.distance);
      
      canvas.text_clipped(paint_rc.left + Col0LeftScreenCoords,
                          paint_rc.top + IBLSCALE(TextTop + TextHeight),
                          rcTextClip, sTmp);
    }
    
    /* draw the warning state indicator */
    
    Brush *state_brush;
    const TCHAR *state_text;
    
    if (warning.get_warning_state() == AirspaceWarning::WARNING_INSIDE) {
      if (warning.get_ack_expired())
        state_brush = &hBrushInsideBk;
      else
        state_brush = &hBrushInsideAckBk;
      state_text = _T("inside");
    } else if (warning.get_warning_state() > AirspaceWarning::WARNING_CLEAR) {
//.........这里部分代码省略.........
开发者ID:Mrdini,项目名称:XCSoar,代码行数:101,代码来源:dlgAirspaceWarnings.cpp


示例18: assert

void
BufferCanvas::Begin(Canvas &other)
{
  assert(IsDefined());
  assert(!active);

  Resize(other.GetSize());

  if (frame_buffer != nullptr) {
    /* activate the frame buffer */
    frame_buffer->Bind();
    texture->AttachFramebuffer(FBO::COLOR_ATTACHMENT0);

    if (OpenGL::render_buffer_stencil == OpenGL::render_buffer_depth_stencil)
      /* we don't need a depth buffer, but we must attach it to the
         FBO if the stencil Renderbuffer has one */
      stencil_buffer->AttachFramebuffer(FBO::DEPTH_ATTACHMENT);

    stencil_buffer->AttachFramebuffer(FBO::STENCIL_ATTACHMENT);

    /* save the old viewport */

#ifdef HAVE_GLES
    /* there's no glPushAttrib() on GL/ES; emulate it */
    glGetIntegerv(GL_VIEWPORT, old_viewport);
#else
    glPushAttrib(GL_VIEWPORT_BIT);
#endif

#ifdef USE_GLSL
    old_projection_matrix = OpenGL::projection_matrix;
    OpenGL::projection_matrix = glm::mat4();
#else
    glMatrixMode(GL_PROJECTION);
    glPushMatrix();
    glMatrixMode(GL_MODELVIEW);
    glPushMatrix();
#endif

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

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

    /* configure a new viewport */
    OpenGL::SetupViewport({GetWidth(), GetHeight()});
    OpenGL::translate = {0, 0};

#ifdef USE_GLSL
    glVertexAttrib4f(OpenGL::Attribute::TRANSLATE,
                     OpenGL::translate.x, OpenGL::translate.y, 0, 0);
#endif
  } else {
    offset = other.offset;
  }

#ifndef NDEBUG
  active = true;
#endif
}
开发者ID:kwtskran,项目名称:XCSoar,代码行数:63,代码来源:BufferCanvas.cpp


示例19: paint

  void paint(Canvas &canvas) {
    canvas.SelectHollowBrush();
    canvas.SelectBlackPen();

    Brush red_brush(COLOR_RED);

    const PixelRect rc = GetClientRect();
    const int width = rc.right - rc.left;
    const int height = rc.bottom - rc.top;
    const int hmiddle = (rc.left + rc.right) / 2;
    const int vmiddle = (rc.top + rc.bottom) / 2;

    RasterPoint p1[3] = {
      { -100, vmiddle },
      { (width * 2) / 3, -100 },
      { hmiddle, height * 2 },
    };

    RasterPoint p2[3] = {
      { -2000, vmiddle },
      { width * 10, -3000 },
      { width * 5, 3000 },
    };

    const TCHAR *label;
    switch (page) {
    case 0:
      canvas.DrawSegment(hmiddle, vmiddle,
                     min(width, height) / 3,
                     Angle::Zero(), Angle::Degrees(90),
                     false);
      label = _T("segment 0-90 horizon=false");
      break;

    case 1:
      canvas.DrawSegment(hmiddle, vmiddle,
                     min(width, height) / 3,
                     Angle::Degrees(45), Angle::Degrees(180),
                     true);
      label = _T("segment 45-180 horizon=true");
      break;

    case 2:
      canvas.DrawCircle(hmiddle, vmiddle,
                    min(width, height) / 3);
      label = _T("circle");
      break;

    case 3:
    case 4:
      PixelRect rc;
      rc.left = hmiddle - 50;
      rc.top = vmiddle - 20;
      rc.right = hmiddle + 50;
      rc.bottom = vmiddle + 20;
      canvas.DrawButton(rc, page == 4);
      label = page == 4
        ? _T("button down=true") : _T("button down=false");
      break;

    case 5:
      canvas.Select(red_brush);
      canvas.DrawPolygon(p1, 3);
      label = _T("big polygon");
      break;

    case 6:
      canvas.Select(red_brush);
      canvas.DrawPolygon(p2, 3);
      label = _T("huge polygon");
      break;
    }

    canvas.SetTextColor(Color(0, 0, 128));
    canvas.SetBackgroundTransparent();
    canvas.Select(normal_font);
    canvas.DrawText(5, 5, label);
#ifndef ENABLE_OPENGL
    canvas.DrawText(5, 25,
                    buffered ? _T("buffered") : _T("not buffered"));
#endif
  }
开发者ID:StefanL74,项目名称:XCSoar,代码行数:82,代码来源:RunCanvas.cpp


示例20: DrawBanner

static void
DrawBanner(Canvas &canvas, PixelRect &rc)
{
  const unsigned padding = 2;
  const Bitmap logo(IDB_LOGO);
  const unsigned banner_height = logo.GetHeight();

  /* draw the XCSoar logo */
  int x = rc.left + padding;
  canvas.Copy(x, rc.top + padding,
              logo.GetWidth(), logo.GetHeight(),
              logo, 0, 0);

  x += logo.GetWidth() + 8;

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

  /* draw the XCSoar banner text with a larger font */
  Font large_font;
  large_font.LoadFile("/opt/xcsoar/share/fonts/VeraBd.ttf", 40);
  canvas.Select(large_font);
  const unsigned name_y = rc.top
    + (banner_height - large_font.GetHeight()) / 2;

  const TCHAR *const name1 = _T("XC");
  canvas.DrawText(x, name_y, name1);
  x += canvas.CalcTextWidth(name1);

  const TCHAR *const name2 = _T("Soar");
  canvas.SetTextColor(COLOR_GRAY);
  canvas.DrawText(x, name_y, name2);
  canvas.SetTextColor(COLOR_BLACK);
  x += canvas.CalcTextWidth(name2) + 30;

  /* some more text */
  const TCHAR *const website = _T("www.xcsoar.org");
  canvas.Select(normal_font);
  canvas.DrawText(x, rc.top + (banner_height - normal_font.GetHeight()) / 2,
                  website);

  const TCHAR *const comment = _T("powered off");
  canvas.DrawText(rc.right - canvas.CalcTextWidth(comment) - padding,
                  rc.top + padding, comment);

  rc.top += banner_height + 8;
}
开发者ID:ppara,项目名称:XCSoar,代码行数:48,代码来源:PowerOff.cpp



注:本文中的Canvas类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ CarState类代码示例发布时间:2022-05-31
下一篇:
C++ Cantera类代码示例发布时间:2022-05-31
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap