Example #1
1
void WindowManagerProvider::reset_cliprect(GUITopLevelWindow *handle, Canvas &canvas)
{
	canvas.reset_cliprect();
}
Example #2
0
 virtual void OnPaint(Canvas &canvas) override {
   canvas.ClearWhite();
   HorizonRenderer::Draw(canvas, canvas.GetRect(), look, attitude);
 }
Example #3
0
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);
  }
}
Example #4
0
void maFillRect(int left, int top, int width, int height) {
  Canvas *drawTarget = graphics->getDrawTarget();
  if (drawTarget) {
    drawTarget->fillRect(left, top, width, height, graphics->getDrawColor());
  }
}
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());
}
Example #6
0
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;
    }

    if (c.IsEditable() && !valid)
      buffer[0] = _T('\0');

    const int x = (c.left + c.right - canvas.CalcTextWidth(text)) / 2;

    canvas.DrawOpaqueText(x, y, rc, text);
  }

  canvas.SetBackgroundTransparent();
  canvas.SetTextColor(look.text_color);

  unsigned control_height = Layout::GetMaximumControlHeight();

  PixelRect plus_rc(0, top - control_height, 0, top);
  PixelRect minus_rc(0, bottom, 0, bottom + control_height);

  for (unsigned i = 0; i < length; ++i) {
    const Column &c = columns[i];
    if (!c.IsEditable())
      continue;

    plus_rc.left = minus_rc.left = c.left;
    plus_rc.right = minus_rc.right = c.right;

    button_renderer.DrawButton(canvas, plus_rc, false, false);
    button_renderer.DrawButton(canvas, minus_rc, false, false);

    canvas.SelectNullPen();
    canvas.Select(look.button.standard.foreground_brush);

    SymbolRenderer::DrawArrow(canvas, plus_rc, SymbolRenderer::UP);
    SymbolRenderer::DrawArrow(canvas, minus_rc, SymbolRenderer::DOWN);
  }
}
Example #7
0
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

  row_renderer.DrawSecondRow(canvas, rc, buffer);
}
Example #8
0
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);
  }
  canvas.polygon(GlideBar, 6);

  // draw glide bar at mc 0
  if (Offset0 <= 0) {
    if (calculated.common_stats.landable_reachable) {
      canvas.Select(look.hpFinalGlideBelowLandable);
      canvas.SelectHollowBrush();
    } else {
      canvas.Select(look.hpFinalGlideBelow);
      canvas.SelectHollowBrush();
    }
  } else {
    canvas.Select(look.hpFinalGlideAbove);
    canvas.SelectHollowBrush();
  }

  if (Offset != Offset0)
    canvas.polygon(GlideBar0, 6);

  // draw cross (x) on final glide bar if unreachable at current Mc
  // or above final glide but impeded by obstacle
  int cross_sign = 0;

  if (!calculated.task_stats.total.IsAchievable())
    cross_sign = 1;
  if (calculated.terrain_warning && (Offset>0))
    cross_sign = -1;

  if (cross_sign != 0) {
    canvas.Select(task_look.bearing_pen);
    canvas.line(Layout::Scale(9 - 5), y0 + cross_sign * Layout::Scale(9 - 5),
                Layout::Scale(9 + 5), y0 + cross_sign * Layout::Scale(9 + 5));
    canvas.line(Layout::Scale(9 - 5), y0 + cross_sign * Layout::Scale(9 + 5),
                Layout::Scale(9 + 5), y0 + cross_sign * Layout::Scale(9 - 5));
  }

  Units::FormatUserAltitude(calculated.task_stats.total.solution_remaining.altitude_difference,
                            Value, ARRAY_SIZE(Value),
                            false);

  if (Offset >= 0)
    Offset = GlideBar[2].y + Offset + Layout::Scale(5);
  else if (Offset0 > 0)
    Offset = GlideBar0[1].y - Layout::Scale(15);
  else
    Offset = GlideBar[2].y + Offset - Layout::Scale(15);

  canvas.SetTextColor(COLOR_BLACK);
  canvas.SetBackgroundColor(COLOR_WHITE);

  TextInBoxMode style;
  style.mode = RM_ROUNDED_BLACK;
  style.bold = true;
  style.move_in_view = true;
  TextInBox(canvas, Value, 0, (int)Offset, style, rc);
}
Example #9
0
        void Player::draw(Canvas &canvas) {
            canvas.fillRect(x, y, x + WIDTH, y + HEIGHT);

            // update velocity
            computeVelocity();
        }
Example #10
0
	/// set focus on the viewport and make canvas current
	void activate()
	{
		mSelf->setFocus();
		mCanvas->workspace()->setCurrentCanvas(mCanvas);
	}
Example #11
0
	void onClicked()
	{
		mSelf->setFocus();
		mCanvas->workspace()->setCurrentCanvas(mCanvas);
	}
Example #12
0
VirtualCanvas::VirtualCanvas(const Canvas &canvas, PixelSize new_size)
  :Canvas(::CreateCompatibleDC(canvas), new_size)
{
  assert(canvas.IsDefined());
}
Example #13
0
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 );
}
Example #14
0
	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
			{
				font_family.add(desc, filename, resource.get_file_system());
				return Font(font_family, desc);
			}
		}

		throw Exception(string_format("Font resource %1 did not have a <sprite> or <ttf> child element", resource.get_name()));
	}
Example #15
0
 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)) {
     TextElement * textelcol4b = new TextElement();
     textelcol4b->Construct(L" ");
     if (col4b.GetLength() > 0) {
     textelcol4b->SetText(col4b);
     textelcol4b->SetTextColor(Color(220, 220, 220));
     textelcol4b->SetFont(fontcol4);
     texteelcol4.Add(*textelcol4b);
     }
     TextElement * textelcol4s = new TextElement();
     textelcol4s->Construct(col4s);
     textelcol4s->SetTextColor(Color(237,255,0));
     textelcol4s->SetFont(fontcol4);
     texteelcol4.Add(*textelcol4s);
     TextElement * textelcol4a = new TextElement();
     textelcol4a->Construct(L" ");
     if (col4a.GetLength() > 0) {
     textelcol4a->SetText(col4a);
     textelcol4a->SetTextColor(Color(220, 220, 220));
     textelcol4a->SetFont(fontcol4);
     texteelcol4.Add(*textelcol4a);
     }
     pCanvas->DrawText(Point(20,85), texteelcol4);
     delete textelcol4b;
     delete textelcol4s;
     delete textelcol4a;
     } else {
     TextElement textelcol4;
     textelcol4.Construct(col4);
     textelcol4.SetTextColor(Color(220, 220, 220));
     textelcol4.SetFont(fontcol4);
     texteelcol4.Add(textelcol4);
	 pCanvas->DrawText(Point(20,85), texteelcol4);
     }
	 }

     pCanvas->DrawLine(Point(rect.x, rect.height - 1), Point(rect.width, rect.height - 1));
     return r;
 }
Example #16
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);
}
Example #17
0
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) {
      if (warning.get_ack_expired())
        state_brush = &hBrushNearBk;
      else
        state_brush = &hBrushNearAckBk;
      state_text = _T("near");
    } else {
      state_brush = NULL;
      state_text = NULL;
    }
    
    const PixelSize state_text_size =
      canvas.text_size(state_text != NULL ? state_text : _T("W"));
    
    if (state_brush != NULL) {
      /* colored background */
      PixelRect rc;
      
      rc.left = paint_rc.left + Col2LeftScreenCoords;
      rc.top = paint_rc.top + Layout::FastScale(paint_rc_margin);
      rc.right = paint_rc.right - Layout::FastScale(paint_rc_margin);
      rc.bottom = paint_rc.bottom - Layout::FastScale(paint_rc_margin);
      
      canvas.fill_rectangle(rc, *state_brush);
    }
    
    if (state_text != NULL) {
      // -- status text will be centered inside its table cell:
      canvas.text(paint_rc.left + Col2LeftScreenCoords + Layout::FastScale(paint_rc_margin) + (statusColWidth / 2)  - (canvas.text_width(state_text) / 2),
                  (paint_rc.bottom + paint_rc.top - state_text_size.cy) / 2,
                  state_text);
    }
    
    if (!warning.get_ack_expired())
      canvas.set_text_color(old_text_color);
        
    if (CursorAirspace == &as) {
      update_vis = true;
      if (!warning.get_ack_expired()) {
        ack1_vis = false;
        ack_vis = false;
      } else {
        if (warning.get_warning_state() == 
            AirspaceWarning::WARNING_INSIDE) {
          ack_vis = true;
          ack1_vis = false;
        } else {
          ack_vis = false;
          ack1_vis = true;
        }
      }
      ack2_vis = !warning.get_ack_day();
      enable_vis = !warning.get_ack_expired();
    }
  } // close scope
  if (update_vis) {
    wbAck1->set_visible(ack1_vis);
    wbAck2->set_visible(ack2_vis);
    wbAck->set_visible(ack_vis);
    wbEnable->set_visible(enable_vis);
  }
}
Example #18
0
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
}
Example #19
0
  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
  }
Example #20
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());
  }

#ifndef NDEBUG
  active = false;
#endif
}
Example #21
0
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;
}
Example #22
0
void PixSliderControl::Transition(ControlTransitionEnum  eTrans,
                                  Pos                   *pMousePos)
{
    Canvas *pCanvas;
    
    if (m_eCurrentState == CS_Pressed && eTrans == CT_SetValue)
        return;

    switch(eTrans)
    {
       case CT_MouseEnter:
          m_pParent->SendControlMessage(this, CM_MouseEnter);
          return;
       case CT_MouseLeave:
          m_pParent->SendControlMessage(this, CM_MouseLeave);
          return;
       case CT_SetValue: {
          if (m_iValue < 0 || m_iValue > 100)
              return;
         
          int temp = m_iValue * m_iNumStates / 100; 
          m_iState = min(temp, m_iNumStates - 1);

         if (!m_bActivationReveal) 
             BlitFrame(CS_Normal, m_iState);
         else
             DrawReveal((float)m_iValue * 2.55);

         return; }
       case CT_Hide:
       {
       	  Rect oRect = m_oRect;

           if (m_pPanel->IsHidden())
               return;

           pCanvas = m_pParent->GetCanvas();
           pCanvas->Erase(oRect);
           pCanvas->Invalidate(oRect);
       	   return;
       }   

       default:
          break;
    }

    if (m_pPanel->IsHidden())
        return;
    
    if (m_bHasActivationBitmap && pMousePos)
        m_iState = GetStateNum(*pMousePos);

    if (m_eCurrentState == CS_MouseOver && 
        eTrans == CT_MouseLButtonUp)
        m_pParent->SendControlMessage(this, CM_Pressed);

    if (m_eCurrentState == CS_MouseOver &&
        eTrans == CT_MouseLButtonUp) {
        if (!m_bActivationReveal)
            m_iValue = (int)((float)(m_iState * 100) / m_iNumStates);
        else
            m_iValue = (int)((float)(m_iState * 100) / 255); 
        m_pParent->SendControlMessage(this, CM_ValueChanged);
    }

    if (!m_bActivationReveal)
        BlitFrame(CS_Normal, m_iState);
    else if (pMousePos)
        DrawReveal(*pMousePos);
    else
        DrawReveal((float)m_iValue * 2.55);
}
void
BufferCanvas::set(const Canvas &canvas)
{
  set(canvas, canvas.get_width(), canvas.get_height());
}
Example #24
0
void PixSliderControl::DrawReveal(int reveal)
{
   int x, y, testreveal;
   Canvas *pCanvas;
   Color trans, color;
   Pos point;
   Rect blit;
   Bitmap *copy;
   int type = 0;

   if (reveal == m_iOldRevealPos)
       return;

   if (reveal == 0) {
       m_iOldRevealPos = 0;
       return;
   }

   m_pActivationBitmap->GetTransColor(trans);
   pCanvas = m_pParent->GetCanvas();

   for (y = m_oRect.y1; y < m_oRect.y2; y++) 
   {
       point.y = y;
       blit.y1 = blit.y2 = y;
       blit.y2++;
       blit.x1 = blit.x2 = m_oRect.x1;
       for (x = m_oRect.x1; x < m_oRect.x2; x++) 
       {
           point.x = x; 
           
           m_pActivationBitmap->GetColor(point, color);
           if (!color.IsEqual(trans)) {
               testreveal = (color.red + color.green + color.blue) / 3;
               if (testreveal <= reveal) {
                   if (type != 1) {
                       if (type == 2) {
                           copy = m_oStateBitmaps[0][CS_Normal];
                           pCanvas->MaskBlitRect(copy, blit, blit);
                       }
                       blit.x1 = blit.x2 = x;
                       blit.y1 = blit.y2 = y;
                       blit.y2++;
                       type = 1;
                   }
                   else 
                       blit.x2++;
               }
               else {
                   if (type != 2) {
                       if (type == 1) {
                           copy = m_oStateBitmaps[0][CS_Pressed];
                           pCanvas->MaskBlitRect(copy, blit, blit);
                       }
                       blit.x1 = blit.x2 = x;
                       blit.y1 = blit.y2 = y;
                       blit.y2++;
                       type = 2;
                   }
                   else 
                       blit.x2++;
               }
           }
           else {
               if (type != 0) {
                   if (type == 2)
                       copy = m_oStateBitmaps[0][CS_Normal]; 
                   else
                       copy = m_oStateBitmaps[0][CS_Pressed];
                   pCanvas->MaskBlitRect(copy, blit, blit);
                   blit.x1 = blit.x2 = x;
                   blit.y1 = blit.y2 = y;
                   blit.y2++;
                   type = 0;
               } 
           }   
       }
       if (type != 0) {
           if (type == 2)
               copy = m_oStateBitmaps[0][CS_Normal];
           else
               copy = m_oStateBitmaps[0][CS_Pressed];
           pCanvas->MaskBlitRect(copy, blit, blit);
           type = 0;
       } 
    }

    m_iOldRevealPos = reveal;

    pCanvas->Invalidate(m_oRect);
    pCanvas->Update();    
}
Example #25
0
void
DeviceListWidget::OnPaintItem(Canvas &canvas, const PixelRect rc, unsigned idx)
{
  assert(idx < NUMDEV);

  const DeviceConfig &config =
    CommonInterface::SetSystemSettings().devices[idx];
  const Flags flags(*items[idx]);

  const UPixelScalar margin = Layout::GetTextPadding();

  TCHAR port_name_buffer[128];
  const TCHAR *port_name =
    config.GetPortName(port_name_buffer, ARRAY_SIZE(port_name_buffer));

  StaticString<256> text(_T("A: "));
  text[0u] += idx;

  if (config.UsesDriver()) {
    const TCHAR *driver_name = FindDriverDisplayName(config.driver_name);

    text.AppendFormat(_("%s on %s"), driver_name, port_name);
  } else {
    text.append(port_name);
  }

  canvas.Select(*look.list.font);
  canvas.DrawText(rc.left + margin, rc.top + margin, text);

  /* show a list of features that are available in the second row */

  StaticString<256> buffer;
  const TCHAR *status;
  if (flags.alive) {
    if (flags.location) {
      buffer = _("GPS fix");
    } else if (flags.gps) {
      /* device sends GPGGA, but no valid location */
      buffer = _("Bad GPS");
    } else {
      buffer = _("Connected");
    }

    if (flags.baro) {
      buffer.append(_T("; "));
      buffer.append(_("Baro"));
    }

    if (flags.airspeed) {
      buffer.append(_T("; "));
      buffer.append(_("Airspeed"));
    }

    if (flags.vario) {
      buffer.append(_T("; "));
      buffer.append(_("Vario"));
    }

    if (flags.traffic)
      buffer.append(_T("; FLARM"));

    status = buffer;
  } else if (config.IsDisabled()) {
    status = _("Disabled");
  } else if (is_simulator() || !config.IsAvailable()) {
    status = _("N/A");
  } else if (flags.open) {
    status = _("No data");
#ifdef ANDROID
  } else if ((config.port_type == DeviceConfig::PortType::RFCOMM ||
              config.port_type == DeviceConfig::PortType::RFCOMM_SERVER) &&
             !BluetoothHelper::isEnabled(Java::GetEnv())) {
    status = _("Bluetooth is disabled");
#endif
  } else if (flags.error) {
    status = _("Error");
  } else {
    status = _("Not connected");
  }

  canvas.Select(*look.small_font);
  canvas.DrawText(rc.left + margin, rc.top + 2 * margin + font_height,
                  status);
}
void
ThermalAssistantWindow::PaintRadarBackground(Canvas &canvas) const
{
  canvas.Clear(look.background_color);
  canvas.SelectHollowBrush();

  canvas.Select(look.inner_circle_pen);
  canvas.DrawCircle(mid.x, mid.y, radius / 2);
  canvas.Select(look.outer_circle_pen);
  canvas.DrawCircle(mid.x, mid.y, radius);

  if (small)
    return;

  canvas.SetTextColor(COLOR_BLACK);
  canvas.Select(look.circle_label_font);
  canvas.SetBackgroundColor(look.background_color);
  canvas.SetBackgroundOpaque();

  TCHAR lift_string[10];
  FormatUserVerticalSpeed(max_lift, lift_string, ARRAY_SIZE(lift_string));
  PixelSize s = canvas.CalcTextSize(lift_string);
  canvas.text(mid.x - s.cx / 2,
              mid.y + radius - s.cy * 0.75, lift_string);

  FormatUserVerticalSpeed(fixed_zero, lift_string, ARRAY_SIZE(lift_string));
  s = canvas.CalcTextSize(lift_string);
  canvas.text(mid.x - s.cx / 2,
              mid.y + radius / 2 - s.cy * 0.75, lift_string);

  canvas.SetBackgroundTransparent();
}
Example #27
0
void WindowManagerProvider::end_paint(Canvas &canvas, GUITopLevelWindow *handle, const Rect &update_region)
{
	canvas.set_modelview(Mat4f::identity());
	canvas.flush();
}
void
ThermalAssistantWindow::PaintAdvisor(Canvas &canvas) const
{
  canvas.DrawLine(mid.x, mid.y, lift_point_avg.x, lift_point_avg.y);
}
Example #29
0
void WindowManagerProvider::push_cliprect(GUITopLevelWindow *handle, Canvas &canvas, const Rect &rect)
{
	Rect box = rect;
	box.translate(windows[handle].box.get_top_left());
	canvas.push_cliprect(box);
}
Example #30
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 != 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

#ifdef USE_GLSL
    if (inverse)
      OpenGL::invert_shader->Use();
    else
      OpenGL::texture_shader->Use();
#else
    const GLEnable<GL_TEXTURE_2D> scope;

    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);
#endif

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