void
LanguageListView::Draw(BRect updateRect)
{
	BOutlineListView::Draw(updateRect);

	if (fDropIndex >= 0 && fDropTargetHighlightFrame.IsValid()) {
		// TODO: decide if drawing of a drop target indicator should be moved
		//       into ControlLook
		BGradientLinear gradient;
		int step = fGlobalDropTargetIndicator ? 64 : 128;
		for (int i = 0; i < 256; i += step)
			gradient.AddColor(i % (step * 2) == 0
				? ViewColor() : ui_color(B_CONTROL_HIGHLIGHT_COLOR), i);
		gradient.AddColor(ViewColor(), 255);
		gradient.SetStart(fDropTargetHighlightFrame.LeftTop());
		gradient.SetEnd(fDropTargetHighlightFrame.RightBottom());
		if (fGlobalDropTargetIndicator) {
			BRegion region(fDropTargetHighlightFrame);
			region.Exclude(fDropTargetHighlightFrame.InsetByCopy(2.0, 2.0));
			ConstrainClippingRegion(&region);
			FillRect(fDropTargetHighlightFrame, gradient);
			ConstrainClippingRegion(NULL);
		} else
			FillRect(fDropTargetHighlightFrame, gradient);
	}
}
Esempio n. 2
0
void
GradientsView::DrawLinear(BRect update)
{
	BGradientLinear gradient;
	rgb_color c;
	c.red = 255;
	c.green = 0;
	c.blue = 0;
	gradient.AddColor(c, 0);
	c.red = 0;
	c.green = 255;
	c.blue = 0;
	gradient.AddColor(c, 127);
	c.red = 0;
	c.green = 0;
	c.blue = 255;
	gradient.AddColor(c, 255);

	// RoundRect
	SetHighColor(0, 0, 0);
	FillRoundRect(BRect(10, 10, 110, 110), 5, 5);
	gradient.SetStart(BPoint(120, 10));
	gradient.SetEnd(BPoint(220, 110));
	FillRoundRect(BRect(120, 10, 220, 110), 5, 5, gradient);

	// Rect
	SetHighColor(0, 0, 0);
	FillRect(BRect(10, 120, 110, 220));
	gradient.SetStart(BPoint(120, 120));
	gradient.SetEnd(BPoint(220, 220));
	FillRect(BRect(120, 120, 220, 220), gradient);

	// Triangle
	SetHighColor(0, 0, 0);
	FillTriangle(BPoint(60, 230), BPoint(10, 330), BPoint(110, 330));
	gradient.SetStart(BPoint(60, 230));
	gradient.SetEnd(BPoint(60, 330));
	FillTriangle(BPoint(170, 230), BPoint(120, 330), BPoint(220, 330), 
		gradient);

	// Ellipse
	SetHighColor(0, 0, 0);
	FillEllipse(BPoint(60, 390), 50, 50);
	gradient.SetStart(BPoint(60, 340));
	gradient.SetEnd(BPoint(60, 440));
	FillEllipse(BPoint(170, 390), 50, 50, gradient);
}
Esempio n. 3
0
/*!	\brief Draws a rectangle with a gradient.
  \param down The rectangle should be drawn recessed or not
*/
void
MacDecorator::_DrawBlendedRect(DrawingEngine* engine, BRect rect,
                               bool down/*, bool focus*/)
{
    // figure out which colors to use
    rgb_color startColor, endColor;
    if (down) {
        startColor = fButtonLowColor;
        endColor = frame_highcol;
    } else {
        startColor = fButtonHighColor;
        endColor = frame_lowercol;
    }

    // fill
    BGradientLinear gradient;
    gradient.SetStart(rect.LeftTop());
    gradient.SetEnd(rect.RightBottom());
    gradient.AddColor(startColor, 0);
    gradient.AddColor(endColor, 255);

    engine->FillRect(rect, gradient);
}
Esempio n. 4
0
//! converts a gradient from local *drawing* to screen coordinate system
void
View::ConvertToScreenForDrawing(BGradient* gradient) const
{
    switch(gradient->GetType()) {
    case BGradient::TYPE_LINEAR: {
        BGradientLinear* linear = (BGradientLinear*) gradient;
        BPoint start = linear->Start();
        BPoint end = linear->End();
        fDrawState->Transform(&start);
        ConvertToScreen(&start);
        fDrawState->Transform(&end);
        ConvertToScreen(&end);
        linear->SetStart(start);
        linear->SetEnd(end);
        linear->SortColorStopsByOffset();
        break;
    }
    case BGradient::TYPE_RADIAL: {
        BGradientRadial* radial = (BGradientRadial*) gradient;
        BPoint center = radial->Center();
        fDrawState->Transform(&center);
        ConvertToScreen(&center);
        radial->SetCenter(center);
        radial->SortColorStopsByOffset();
        break;
    }
    case BGradient::TYPE_RADIAL_FOCUS: {
        BGradientRadialFocus* radialFocus = (BGradientRadialFocus*) gradient;
        BPoint center = radialFocus->Center();
        BPoint focal = radialFocus->Focal();
        fDrawState->Transform(&center);
        ConvertToScreen(&center);
        fDrawState->Transform(&focal);
        ConvertToScreen(&focal);
        radialFocus->SetCenter(center);
        radialFocus->SetFocal(focal);
        radialFocus->SortColorStopsByOffset();
        break;
    }
    case BGradient::TYPE_DIAMOND: {
        BGradientDiamond* diamond = (BGradientDiamond*) gradient;
        BPoint center = diamond->Center();
        fDrawState->Transform(&center);
        ConvertToScreen(&center);
        diamond->SetCenter(center);
        diamond->SortColorStopsByOffset();
        break;
    }
    case BGradient::TYPE_CONIC: {
        BGradientConic* conic = (BGradientConic*) gradient;
        BPoint center = conic->Center();
        fDrawState->Transform(&center);
        ConvertToScreen(&center);
        conic->SetCenter(center);
        conic->SortColorStopsByOffset();
        break;
    }
    case BGradient::TYPE_NONE: {
        break;
    }
    }
}
Esempio n. 5
0
void
PlaylistListView::Item::Draw(BView* owner, BRect frame, const font_height& fh,
                             bool tintedLine, uint32 mode, bool active, uint32 playbackState)
{
    rgb_color color = (rgb_color) {
        255, 255, 255, 255
    };
    if (tintedLine)
        color = tint_color(color, 1.04);
    // background
    if (IsSelected())
        color = tint_color(color, B_DARKEN_2_TINT);
    owner->SetLowColor(color);
    owner->FillRect(frame, B_SOLID_LOW);
    // label
    rgb_color black = (rgb_color) {
        0, 0, 0, 255
    };
    owner->SetHighColor(black);
    const char* text = Text();
    switch (mode) {
    case DISPLAY_NAME:
        // TODO
        break;
    case DISPLAY_PATH:
        // TODO
        break;
    default:
        break;
    }

    float playbackMarkSize = playback_mark_size(fh);
    float textOffset = text_offset(fh);

    BString truncatedString(text);
    owner->TruncateString(&truncatedString, B_TRUNCATE_MIDDLE,
                          frame.Width() - playbackMarkSize - textOffset);
    owner->DrawString(truncatedString.String(),
                      BPoint(frame.left + playbackMarkSize + textOffset,
                             floorf(frame.top + frame.bottom + fh.ascent) / 2 - 1));

    // playmark
    if (active) {
        rgb_color green = (rgb_color) {
            0, 255, 0, 255
        };
        if (playbackState != PLAYBACK_STATE_PLAYING)
            green = tint_color(color, B_DARKEN_1_TINT);

        BRect r(0, 0, playbackMarkSize, playbackMarkSize);
        r.OffsetTo(frame.left + 4,
                   ceilf((frame.top + frame.bottom - playbackMarkSize) / 2));

#ifdef __ANTARES__
        uint32 flags = owner->Flags();
        owner->SetFlags(flags | B_SUBPIXEL_PRECISE);

        BShape shape;
        shape.MoveTo(r.LeftTop());
        shape.LineTo(r.LeftBottom());
        shape.LineTo(BPoint(r.right, (r.top + r.bottom) / 2));
        shape.Close();

        owner->MovePenTo(B_ORIGIN);
        owner->FillShape(&shape);

        shape.Clear();
        r.InsetBy(1, 1);
        shape.MoveTo(r.LeftTop());
        shape.LineTo(r.LeftBottom());
        shape.LineTo(BPoint(r.right, (r.top + r.bottom) / 2));
        shape.Close();

        BGradientLinear gradient;
        gradient.SetStart(r.LeftTop());
        gradient.SetEnd(r.LeftBottom());
        gradient.AddColor(tint_color(green, B_LIGHTEN_1_TINT), 0);
        gradient.AddColor(tint_color(green, B_DARKEN_1_TINT), 255.0);

        owner->FillShape(&shape, gradient);

        owner->SetFlags(flags);
#else
        BPoint arrow[3];
        arrow[0] = r.LeftTop();
        arrow[1] = r.LeftBottom();
        arrow[2].x = r.right;
        arrow[2].y = (r.top + r.bottom) / 2;

        rgb_color lightGreen = tint_color(green, B_LIGHTEN_2_TINT);
        rgb_color darkGreen = tint_color(green, B_DARKEN_2_TINT);
        owner->BeginLineArray(6);
        // black outline
        owner->AddLine(arrow[0], arrow[1], black);
        owner->AddLine(BPoint(arrow[1].x + 1.0, arrow[1].y - 1.0),
                       arrow[2], black);
        owner->AddLine(arrow[0], arrow[2], black);
        // inset arrow
        arrow[0].x += 1.0;
        arrow[0].y += 2.0;
        arrow[1].x += 1.0;
        arrow[1].y -= 2.0;
        arrow[2].x -= 2.0;
        // highlights and shadow
        owner->AddLine(arrow[1], arrow[2], darkGreen);
        owner->AddLine(arrow[0], arrow[2], lightGreen);
        owner->AddLine(arrow[0], arrow[1], lightGreen);
        owner->EndLineArray();
        // fill green
        arrow[0].x += 1.0;
        arrow[0].y += 1.0;
        arrow[1].x += 1.0;
        arrow[1].y -= 1.0;
        arrow[2].x -= 2.0;

        owner->SetLowColor(owner->HighColor());
        owner->SetHighColor(green);
        owner->FillPolygon(arrow, 3);
#endif // __ANTARES__
    }
}
void
PlaylistListView::Item::Draw(BView* owner, BRect frame, const font_height& fh,
	bool tintedLine, uint32 mode, bool active, uint32 playbackState)
{
	rgb_color color = (rgb_color){ 255, 255, 255, 255 };
	if (tintedLine)
		color = tint_color(color, 1.04);
	// background
	if (IsSelected())
		color = tint_color(color, B_DARKEN_2_TINT);
	owner->SetLowColor(color);
	owner->FillRect(frame, B_SOLID_LOW);
	// label
	rgb_color black = (rgb_color){ 0, 0, 0, 255 };
	owner->SetHighColor(black);
	const char* text = Text();
	switch (mode) {
		case DISPLAY_NAME:
			// TODO
			break;
		case DISPLAY_PATH:
			// TODO
			break;
		default:
			break;
	}

	float playbackMarkSize = playback_mark_size(fh);
	float textOffset = text_offset(fh);

	BString truncatedString(text);
	owner->TruncateString(&truncatedString, B_TRUNCATE_MIDDLE,
		frame.Width() - playbackMarkSize - textOffset);
	owner->DrawString(truncatedString.String(),
		BPoint(frame.left + playbackMarkSize + textOffset,
			floorf(frame.top + frame.bottom + fh.ascent) / 2 - 1));

	// playmark
	if (active) {
		rgb_color green = (rgb_color){ 0, 255, 0, 255 };
		if (playbackState != PLAYBACK_STATE_PLAYING)
			green = tint_color(color, B_DARKEN_1_TINT);

		BRect r(0, 0, playbackMarkSize, playbackMarkSize);
		r.OffsetTo(frame.left + 4,
			ceilf((frame.top + frame.bottom - playbackMarkSize) / 2));

		uint32 flags = owner->Flags();
		owner->SetFlags(flags | B_SUBPIXEL_PRECISE);

		BShape shape;
		shape.MoveTo(r.LeftTop());
		shape.LineTo(r.LeftBottom());
		shape.LineTo(BPoint(r.right, (r.top + r.bottom) / 2));
		shape.Close();

		owner->MovePenTo(B_ORIGIN);
		owner->FillShape(&shape);

		shape.Clear();
		r.InsetBy(1, 1);
		shape.MoveTo(r.LeftTop());
		shape.LineTo(r.LeftBottom());
		shape.LineTo(BPoint(r.right, (r.top + r.bottom) / 2));
		shape.Close();

		BGradientLinear gradient;
		gradient.SetStart(r.LeftTop());
		gradient.SetEnd(r.LeftBottom());
		gradient.AddColor(tint_color(green, B_LIGHTEN_1_TINT), 0);
		gradient.AddColor(tint_color(green, B_DARKEN_1_TINT), 255.0);

		owner->FillShape(&shape, gradient);

		owner->SetFlags(flags);
	}
}
Esempio n. 7
0
status_t
LinkReceiver::ReadGradient(BGradient** _gradient)
{
	GTRACE(("LinkReceiver::ReadGradient\n"));

	BGradient::Type gradientType;
	int32 colorsCount;
	Read(&gradientType, sizeof(BGradient::Type));
	status_t status = Read(&colorsCount, sizeof(int32));
	if (status != B_OK)
		return status;

	BGradient* gradient = gradient_for_type(gradientType);
	if (!gradient)
		return B_NO_MEMORY;

	*_gradient = gradient;

	if (colorsCount > 0) {
		BGradient::ColorStop stop;
		for (int i = 0; i < colorsCount; i++) {
			if ((status = Read(&stop, sizeof(BGradient::ColorStop))) != B_OK)
				return status;
			if (!gradient->AddColorStop(stop, i))
				return B_NO_MEMORY;
		}
	}

	switch (gradientType) {
		case BGradient::TYPE_LINEAR:
		{
			GTRACE(("LinkReceiver::ReadGradient> type == TYPE_LINEAR\n"));
			BGradientLinear* linear = (BGradientLinear*)gradient;
			BPoint start;
			BPoint end;
			Read(&start, sizeof(BPoint));
			if ((status = Read(&end, sizeof(BPoint))) != B_OK)
				return status;
			linear->SetStart(start);
			linear->SetEnd(end);
			return B_OK;
		}
		case BGradient::TYPE_RADIAL:
		{
			GTRACE(("LinkReceiver::ReadGradient> type == TYPE_RADIAL\n"));
			BGradientRadial* radial = (BGradientRadial*)gradient;
			BPoint center;
			float radius;
			Read(&center, sizeof(BPoint));
			if ((status = Read(&radius, sizeof(float))) != B_OK)
				return status;
			radial->SetCenter(center);
			radial->SetRadius(radius);
			return B_OK;
		}
		case BGradient::TYPE_RADIAL_FOCUS:
		{
			GTRACE(("LinkReceiver::ReadGradient> type == TYPE_RADIAL_FOCUS\n"));
			BGradientRadialFocus* radialFocus =
				(BGradientRadialFocus*)gradient;
			BPoint center;
			BPoint focal;
			float radius;
			Read(&center, sizeof(BPoint));
			Read(&focal, sizeof(BPoint));
			if ((status = Read(&radius, sizeof(float))) != B_OK)
				return status;
			radialFocus->SetCenter(center);
			radialFocus->SetFocal(focal);
			radialFocus->SetRadius(radius);
			return B_OK;
		}
		case BGradient::TYPE_DIAMOND:
		{
			GTRACE(("LinkReceiver::ReadGradient> type == TYPE_DIAMOND\n"));
			BGradientDiamond* diamond = (BGradientDiamond*)gradient;
			BPoint center;
			if ((status = Read(&center, sizeof(BPoint))) != B_OK)
				return status;
			diamond->SetCenter(center);
			return B_OK;
		}
		case BGradient::TYPE_CONIC:
		{
			GTRACE(("LinkReceiver::ReadGradient> type == TYPE_CONIC\n"));
			BGradientConic* conic = (BGradientConic*)gradient;
			BPoint center;
			float angle;
			Read(&center, sizeof(BPoint));
			if ((status = Read(&angle, sizeof(float))) != B_OK)
				return status;
			conic->SetCenter(center);
			conic->SetAngle(angle);
			return B_OK;
		}
		case BGradient::TYPE_NONE:
		{
			GTRACE(("LinkReceiver::ReadGradient> type == TYPE_NONE\n"));
			break;
		}
	}

	return B_ERROR;
}
Esempio n. 8
0
void
VolumeSlider::DrawThumb()
{
#if ROUND_KNOB
	// Draw a round thumb
	BRect rect(ThumbFrame());

	rgb_color base = ui_color(B_PANEL_BACKGROUND_COLOR);
	rgb_color frameLightColor;
	rgb_color frameShadowColor;
	rgb_color shadowColor = (rgb_color){ 0, 0, 0, 60 };

	float topTint = 0.49;
	float middleTint1 = 0.62;
	float middleTint2 = 0.76;
	float bottomTint = 0.90;

	if (!IsEnabled()) {
		topTint = (topTint + B_NO_TINT) / 2;
		middleTint1 = (middleTint1 + B_NO_TINT) / 2;
		middleTint2 = (middleTint2 + B_NO_TINT) / 2;
		bottomTint = (bottomTint + B_NO_TINT) / 2;
		shadowColor = (rgb_color){ 0, 0, 0, 30 };
	}

	// Draw shadow
#if !KNOB_EMBEDDED
	rect.left++;
	rect.top++;
	SetDrawingMode(B_OP_ALPHA);
	SetHighColor(shadowColor);
	FillEllipse(rect);

	// Draw thumb shape
	rect.OffsetBy(-1, -1);
#endif

	if (IsFocus()) {
		// focused
		frameLightColor = ui_color(B_KEYBOARD_NAVIGATION_COLOR);
		frameShadowColor = frameLightColor;
	} else {
		// figure out the tints to be used
		float frameLightTint;
		float frameShadowTint;

		if (!IsEnabled()) {
			frameLightTint = 1.30;
			frameShadowTint = 1.35;
			shadowColor.alpha = 30;
		} else {
			frameLightTint = 1.6;
			frameShadowTint = 1.65;
		}

		frameLightColor = tint_color(base, frameLightTint);
		frameShadowColor = tint_color(base, frameShadowTint);
	}

	BGradientLinear frameGradient;
	frameGradient.AddColor(frameShadowColor, 0);
	frameGradient.AddColor(frameLightColor, 255);
	frameGradient.SetStart(rect.LeftTop());
	frameGradient.SetEnd(rect.RightBottom());

	FillEllipse(rect, frameGradient);
	rect.InsetBy(1, 1);

//	frameGradient.MakeEmpty();
//	frameGradient.AddColor(borderColor, 0);
//	frameGradient.AddColor(tint_color(borderColor, 0.8), 255);
//	view->FillEllipse(rect, frameGradient);
//	rect.InsetBy(1, 1);

	BGradientLinear gradient;
	if (!IsEnabled()) {
		gradient.AddColor(tint_color(base, topTint), 0);
		gradient.AddColor(tint_color(base, bottomTint), 255);
	} else {
		gradient.AddColor(tint_color(base, topTint), 0);
		gradient.AddColor(tint_color(base, middleTint1), 132);
		gradient.AddColor(tint_color(base, middleTint2), 136);
		gradient.AddColor(tint_color(base, bottomTint), 255);
	}
	gradient.SetStart(rect.LeftTop());
	gradient.SetEnd(rect.LeftBottom());
	FillEllipse(rect, gradient);
#else
	BSlider::DrawThumb();
#endif
}