Exemple #1
0
static int
log_working_directory (int entering)
{
  static char *buf = NULL;
  static unsigned int len = 0;
  unsigned int need;
  const char *fmt;
  char *p;

  /* Get enough space for the longest possible output.  */
  need = strlen (program) + INTSTR_LENGTH + 2 + 1;
  need += COLOR_MAX_SPACE;
  if (starting_directory)
    need += strlen (starting_directory);

  /* Use entire sentences to give the translators a fighting chance.  */
  if (makelevel == 0)
    if (starting_directory == 0)
      if (entering)
        fmt = _("%s: Entering an unknown directory\n");
      else
        fmt = _("%s: Leaving an unknown directory\n");
    else
      if (entering)
        fmt = _("%s: Entering directory '%s'\n");
      else
        fmt = _("%s: Leaving directory '%s'\n");
  else
    if (starting_directory == 0)
      if (entering)
        fmt = _("%s[%u]: Entering an unknown directory\n");
      else
        fmt = _("%s[%u]: Leaving an unknown directory\n");
    else
      if (entering)
        fmt = _("%s[%u]: Entering directory '%s'\n");
      else
        fmt = _("%s[%u]: Leaving directory '%s'\n");

  need += strlen (fmt);

  if (need > len)
    {
      buf = xrealloc (buf, need);
      len = need;
    }

  /* mmc: now start typing into the buffer: */
  if (color_flag)
    {
    /* fixme:  negative value on error! */
      p = buf + start_color (buf, entering?color_dir_enter:color_dir_leave);
    }
  else
    p = buf;
  if (print_data_base_flag)
    {
      *(p++) = '#';
      *(p++) = ' ';
    }

  if (makelevel == 0)
    {
    if (starting_directory == 0)
      sprintf (p, fmt, program);
    else
      sprintf (p, fmt, program, starting_directory);
    }
  else if (starting_directory == 0)
    sprintf (p, fmt, program, makelevel);
  else
    sprintf (p, fmt, program, makelevel, starting_directory);

  if (color_flag)
    /* we overwrite the newline! */
    /* this is optional, we yes, we have to overwrite: */
    stop_color (buf + strlen(buf) -1);

  strcat (buf, "\n");

  /* I'd say stderr! */
  _outputs (NULL, 0, buf);

  return 1;
}
Exemple #2
0
std::unique_ptr<RenderQueue> BREW::CreateSpinnerDrawable( std::shared_ptr<const Spinner> spinner ) const {
	auto color = GetProperty<sf::Color>( "Color", spinner );
	auto background_color = GetProperty<sf::Color>( "BackgroundColor", spinner );
	auto steps = GetProperty<unsigned int>( "Steps", spinner );
	auto inner_radius = GetProperty<float>( "InnerRadius", spinner );
	auto rod_thickness = GetProperty<float>( "RodThickness", spinner );
	auto stopped_alpha = GetProperty<unsigned int>( "StoppedAlpha", spinner );
	auto radius = std::min( spinner->GetAllocation().width, spinner->GetAllocation().height ) / 2.f;

	std::unique_ptr<RenderQueue> queue( new RenderQueue );

	// Make sure steps is sane.
	steps = std::max( steps, 3u );

	// SFML does this too, for compatibility reasons, so lay off the flame :P
	static const auto two_pi = 3.141592654f * 2.f;

	sf::Vector2f center_offset( spinner->GetAllocation().width / 2.f, spinner->GetAllocation().height / 2.f );

	// We just have to produce the spinner in stopped state.
	// The class itself will take care of the started state.
	auto blend = ( 255.f - static_cast<float>( stopped_alpha ) ) / 255.f;

	sf::Color stop_color(
		static_cast<sf::Uint8>( static_cast<float>( color.r ) * ( 1.f - blend ) + static_cast<float>( background_color.r ) * blend ),
		static_cast<sf::Uint8>( static_cast<float>( color.g ) * ( 1.f - blend ) + static_cast<float>( background_color.g ) * blend ),
		static_cast<sf::Uint8>( static_cast<float>( color.b ) * ( 1.f - blend ) + static_cast<float>( background_color.b ) * blend )
	);

	auto started = spinner->Started();
	auto current_stage = spinner->GetStage();

	for( unsigned int index = 0; index < steps; index++ ) {
		// Time for some hardcore trigonometry...
		sf::Vector2f inner_point(
			std::cos( two_pi * static_cast<float>( index ) / -static_cast<float>( steps ) ) * inner_radius,
			std::sin( two_pi * static_cast<float>( index ) / -static_cast<float>( steps ) ) * inner_radius
		);

		sf::Vector2f outer_point(
			std::cos( two_pi * static_cast<float>( index ) / -static_cast<float>( steps ) ) * radius,
			std::sin( two_pi * static_cast<float>( index ) / -static_cast<float>( steps ) ) * radius
		);

		unsigned int rod_stage = ( current_stage + index ) % steps;

		auto rod_alpha = static_cast<float>( rod_stage ) / ( static_cast<float>( steps ) - 1.f );

		sf::Color rod_color(
			static_cast<sf::Uint8>( static_cast<float>( color.r ) * ( 1.f - rod_alpha ) + static_cast<float>( background_color.r ) * rod_alpha ),
			static_cast<sf::Uint8>( static_cast<float>( color.g ) * ( 1.f - rod_alpha ) + static_cast<float>( background_color.g ) * rod_alpha ),
			static_cast<sf::Uint8>( static_cast<float>( color.b ) * ( 1.f - rod_alpha ) + static_cast<float>( background_color.b ) * rod_alpha )
		);

		queue->Add(
			Renderer::Get().CreateLine(
				inner_point + center_offset,
				outer_point + center_offset,
				started ? rod_color : stop_color,
				rod_thickness
			)
		);
	}

	return queue;
}