void DefaultLookAndFeel::drawLinearSlider(Graphics& g, int x, int y, int width, int height,
                                          float slider_pos, float min, float max,
                                          const Slider::SliderStyle style, Slider& slider) {
  static const DropShadow thumb_shadow(Colour(0x88000000), 3, Point<int>(-1, 0));

  bool bipolar = false;
  bool active = true;
  SynthSlider* s_slider = dynamic_cast<SynthSlider*>(&slider);
  if (s_slider) {
    bipolar = s_slider->isBipolar();
    active = s_slider->isActive();
  }

  Colour slider_color(0xff888888);
  Colour thumb_color(0xffffffff);

  if (!active) {
    slider_color = Colour(0xff424242);
    thumb_color = Colour(0xff888888);
  }

  float pos = slider_pos - 1.0f;
  if (style == Slider::SliderStyle::LinearBar) {
    float h = slider.getHeight();

    g.setColour(slider_color);
    if (bipolar)
      fillHorizontalRect(g, width / 2.0f, pos, h);
    else
      fillHorizontalRect(g, 0.0f, pos, h);

    thumb_shadow.drawForRectangle(g, Rectangle<int>(pos + 0.5f, 0, 2, h));
    g.setColour(thumb_color);
    g.fillRect(pos, 0.0f, 2.0f, h);
  }
  else if (style == Slider::SliderStyle::LinearBarVertical) {
    float w = slider.getWidth();

    g.setColour(slider_color);

    if (bipolar)
      fillVerticalRect(g, height / 2.0f, pos, w);
    else
      fillVerticalRect(g, 0, pos, w);

    thumb_shadow.drawForRectangle(g, Rectangle<int>(0, pos + 0.5f, w, 2));
    g.setColour(thumb_color);
    g.fillRect(0.0f, pos, w, 2.0f);
  }
}
Exemple #2
0
RenderQueue* BREW::CreateScaleDrawable( SharedPtr<const Scale> scale ) const {
	sf::Color trough_color( GetProperty<sf::Color>( "TroughColor", scale ) );
	sf::Color slider_color( GetProperty<sf::Color>( "SliderColor", scale ) );
	sf::Color border_color( GetProperty<sf::Color>( "BorderColor", scale ) );
	int border_color_shift( GetProperty<int>( "BorderColorShift", scale ) );
	float trough_thickness( GetProperty<float>( "TroughWidth", scale ) );
	float border_width( GetProperty<float>( "BorderWidth", scale ) );

	RenderQueue* queue( new RenderQueue );

	Scale::Orientation orientation = scale->GetOrientation();

	sf::FloatRect slider_rect = scale->GetSliderRect();

	if( orientation == Scale::HORIZONTAL ) {
		// Trough
		queue->Add(
			Renderer::Get().CreateRect(
				sf::FloatRect(
					slider_rect.width / 2.f,
					( scale->GetAllocation().height - trough_thickness ) / 2.f,
					scale->GetAllocation().width - slider_rect.width,
					trough_thickness
				),
				trough_color
			)
		);
	}
	else {
		// Trough
		queue->Add(
			Renderer::Get().CreateRect(
				sf::FloatRect(
					( scale->GetAllocation().width - trough_thickness ) / 2.f,
					slider_rect.height / 2.f,
					trough_thickness,
					scale->GetAllocation().height - slider_rect.height
				),
				trough_color
			)
		);
	}

	// Slider
	queue->Add( CreateSlider( slider_rect, slider_color, border_width, border_color, border_color_shift ) );

	return queue;
}