Esempio n. 1
0
static void testStrokeShape(BView *view, BRect frame)
{
	frame.InsetBy(2, 2);
	BShape shape;
	shape.MoveTo(BPoint(frame.left, frame.bottom));
	shape.LineTo(BPoint(frame.right, frame.top));
	shape.LineTo(BPoint(frame.left, frame.top));
	shape.LineTo(BPoint(frame.right, frame.bottom));
	view->StrokeShape(&shape);
}
Esempio n. 2
0
void
LineChartRenderer::Render(BView* view, BRect updateRect)
{
	if (!updateRect.IsValid() || updateRect.left > fFrame.right
		|| fFrame.left > updateRect.right) {
		return;
	}

	if (fDomain.min >= fDomain.max || fRange.min >= fRange.max)
		return;

	if (!_UpdateSamples())
		return;

	// get the range to draw (draw one more sample on each side)
	int32 left = (int32)fFrame.left;
	int32 first = (int32)updateRect.left - left - 1;
	int32 last = (int32)updateRect.right - left + 1;
	if (first < 0)
		first = 0;
	if (last > fFrame.IntegerWidth())
		last = fFrame.IntegerWidth();
	if (first > last)
		return;

	double minRange = fRange.min;
	double sampleRange = fRange.max - minRange;
	if (sampleRange == 0) {
		minRange = fRange.min - 0.5;
		sampleRange = 1;
	}
	double scale = (double)fFrame.IntegerHeight() / sampleRange;

	// draw
	view->SetLineMode(B_ROUND_CAP, B_ROUND_JOIN);
	for (int32 i = 0; DataSourceInfo* info = fDataSources.ItemAt(i); i++) {

		float bottom = fFrame.bottom;
		BShape shape;
		shape.MoveTo(BPoint(left + first,
			bottom - ((info->samples[first] - minRange) * scale)));

		for (int32 i = first; i <= last; i++) {
			shape.LineTo(BPoint(float(left + i),
				float(bottom - ((info->samples[i] - minRange) * scale))));
		}
		view->SetHighColor(info->config.Color());
		view->MovePenTo(B_ORIGIN);
		view->StrokeShape(&shape);
	}
}
Esempio n. 3
0
BShape*
TransportControlGroup::_CreatePlayShape(float height) const
{
	BShape* shape = new BShape();

	float step = floorf(height / 8);

	shape->MoveTo(BPoint(height + step, height / 2));
	shape->LineTo(BPoint(-step, height + step));
	shape->LineTo(BPoint(-step, 0 - step));
	shape->Close();

	return shape;
}
Esempio n. 4
0
void
MouseView::_CreateButtonsPicture()
{
	BeginPicture(&fButtonsPicture);
	SetScale(1.8 * fScaling);
	SetOrigin(-21 * fScaling, -14 * fScaling);

	BShape mouseShape;
	mouseShape.MoveTo(BPoint(48, 12));
	// top
	BPoint control3[3] = { BPoint(44, 8), BPoint(20, 8), BPoint(16, 12) };
	mouseShape.BezierTo(control3);
	// left
	BPoint control[3] = { BPoint(12, 16), BPoint(13, 27), BPoint(13, 27) };
	mouseShape.BezierTo(control);
	// bottom
	BPoint control4[] = { BPoint(18, 30), BPoint(46, 30), BPoint(51, 27) };
	mouseShape.BezierTo(control4);
	// right
	BPoint control2[3] = { BPoint(51, 27), BPoint(50, 14), BPoint(48, 12) };
	mouseShape.BezierTo(control2);

	mouseShape.Close();

	SetHighColor(255, 0, 0, 255);
	FillShape(&mouseShape, B_SOLID_HIGH);

	EndPicture();
	SetScale(1);
}
Esempio n. 5
0
static void
draw_shape(void* _context, const BShape& shape, bool fill)
{
	DrawingContext* context = reinterpret_cast<DrawingContext *>(_context);
	ShapePainter drawShape(context);

	drawShape.Iterate(&shape);
	drawShape.Draw(shape.Bounds(), fill);
}
Esempio n. 6
0
static void
draw_shape(void* _canvas, const BShape& shape, bool fill)
{
	Canvas* const canvas = reinterpret_cast<Canvas*>(_canvas);
	ShapePainter drawShape(canvas);

	drawShape.Iterate(&shape);
	drawShape.Draw(shape.Bounds(), fill);
}
Esempio n. 7
0
static void
DrawStuff(BView *view)
{
	// StrokeShape
	BShape shape;
	BPoint bezier[3] = {BPoint(100,0), BPoint(100, 100), BPoint(25, 50)};
	shape.MoveTo(BPoint(150,0));
	shape.LineTo(BPoint(200,100));
	shape.BezierTo(bezier);
	shape.Close();
	view->StrokeShape(&shape);
	
	// Stroke/FillRect, Push/PopState, SetHighColor, SetLineMode, SetPenSize
	view->PushState();
	const rgb_color blue = { 0, 0, 240, 0 };
	view->SetHighColor(blue);
	view->SetLineMode(B_BUTT_CAP, B_BEVEL_JOIN);
	view->SetPenSize(7);
	view->StrokeRect(BRect(10, 220, 50, 260));
	view->FillRect(BRect(65, 245, 120, 300));
	view->PopState();
	
	// Stroke/FillEllipse
	view->StrokeEllipse(BPoint(50, 150), 50, 50);
	view->FillEllipse(BPoint(100, 120), 50, 50);
	
	// Stroke/FillArc
	view->StrokeArc(BRect(0, 200, 50, 250), 180, 180);
	view->FillArc(BPoint(150, 250), 50, 50, 0, 125);
	
	// DrawString, SetHighColor, SetFontSize
	const rgb_color red = { 240, 0, 0, 0 };
	view->SetHighColor(red);
	view->SetFontSize(20);
	view->DrawString("BPicture ", BPoint(30, 20));
	view->DrawString("test");

	// DrawLine with pen position
	const rgb_color purple = { 200, 0, 220, 0 };
	view->SetHighColor(purple);
	view->StrokeLine(BPoint(50, 30), BPoint(30, 50));
	view->StrokeLine(BPoint(80, 50));
	view->StrokeLine(BPoint(50, 30));
}
Esempio n. 8
0
void
Leaves::Draw(BView* view, int32 frame)
{
	float scale = fLeafSize / kLeafWidth / (kMaximumLeafSize * 2);
	scale *= view->Bounds().Width();
	scale += scale * drand48() * fSizeVariation / 100.;

	BAffineTransform transform;
	transform.TranslateBy(-kLeafWidth / 2, -kLeafHeight / 2);
		// draw the leaf centered on the point
	transform.RotateBy(drand48() * 2. * M_PI);
	if ((rand() & 64) == 0) transform.ScaleBy(-1., 1.);
		// flip half of the time
	transform.ScaleBy(scale);
	transform.TranslateBy(_RandomPoint(view->Bounds()));

	BPoint center = transform.Apply(BPoint(kLeafWidth / 2, kLeafHeight / 2));
	BPoint gradientOffset = BPoint(60 * scale, 80 * scale);
	BGradientLinear gradient(center - gradientOffset, center + gradientOffset);
	int color = (rand() / 7) % kColorCount;
	gradient.AddColor(kColors[color][0], 0.f);
	gradient.AddColor(kColors[color][1], 255.f);

	BShape leafShape;
	leafShape.MoveTo(transform.Apply(kLeafBegin));
	for (int i = 0; i < kLeafCurveCount; ++i) {
		BPoint control[3];
		for (int j = 0; j < 3; ++j)
			control[j] = transform.Apply(kLeafCurves[i][j]);
		leafShape.BezierTo(control);
	}
	leafShape.Close();

	view->PushState();
	view->SetDrawingMode(B_OP_ALPHA);
	view->SetHighColor(0, 0, 0, 50);
	for (int i = 2; i >= 0; --i) {
		view->SetOrigin(i * 0.1, i * 0.3);
		view->SetPenSize(i * 2);
		view->StrokeShape(&leafShape);
	}
	view->PopState();
	view->FillShape(&leafShape, gradient);
}
Esempio n. 9
0
BShape*
TransportControlGroup::_CreateForwardShape(float height) const
{
	BShape* shape = new BShape();

	shape->MoveTo(BPoint(height, height / 2));
	shape->LineTo(BPoint(0, height));
	shape->LineTo(BPoint(0, 0));
	shape->Close();

	shape->MoveTo(BPoint(height * 2, height / 2));
	shape->LineTo(BPoint(height, height));
	shape->LineTo(BPoint(height, 0));
	shape->Close();

	return shape;
}
Esempio n. 10
0
void
PDFWriter::ClipChar(BFont* font, const char* unicode, const char* utf8,
	int16 size, float width)
{
	BShape glyph;
	bool hasGlyph[1];
	font->GetHasGlyphs(utf8, 1, hasGlyph);
	if (hasGlyph[0]) {
		BShape *glyphs[1];
		glyphs[0] = &glyph;
		font->GetGlyphShapes(utf8, 1, glyphs);
	} else {
		REPORT(kWarning, fPage, "glyph for %*.*s not found!", size, size, utf8);
		// create a rectangle instead
		font_height height;
		fState->beFont.GetHeight(&height);
		BRect r(0, 0, width, height.ascent);
		float w = r.Width() < r.Height() ? r.Width()*0.1 : r.Height()*0.1;
		BRect o = r; o.InsetBy(w, w);
		w *= 2.0;
		BRect i = r; i.InsetBy(w, w);

		o.OffsetBy(0, -height.ascent);
		i.OffsetBy(0, -height.ascent);

		glyph.MoveTo(BPoint(o.left,  o.top));
		glyph.LineTo(BPoint(o.right, o.top));
		glyph.LineTo(BPoint(o.right, o.bottom));
		glyph.LineTo(BPoint(o.left,  o.bottom));
		glyph.Close();

		glyph.MoveTo(BPoint(i.left,  i.top));
		glyph.LineTo(BPoint(i.left,  i.bottom));
		glyph.LineTo(BPoint(i.right, i.bottom));
		glyph.LineTo(BPoint(i.right, i.top));
		glyph.Close();
	}

	BPoint p(fState->penX, fState->penY);
	PushInternalState(); SetOrigin(p);
	{
		DrawShape iterator(this, false);
		iterator.Iterate(&glyph);
	}
	PopInternalState();
}
Esempio n. 11
0
void
BMenuItem::_DrawSubmenuSymbol(rgb_color bgColor)
{
	fSuper->PushState();

	BRect r(fBounds);
	float rightMargin;
	MenuPrivate(fSuper).GetItemMargins(NULL, NULL, &rightMargin, NULL);
	r.left = r.right - rightMargin + 3;
	r.right -= 1;

	BPoint center(floorf((r.left + r.right) / 2.0),
		floorf((r.top + r.bottom) / 2.0));

	float size = min_c(r.Height() - 2, r.Width());
	r.top = floorf(center.y - size / 2 + 0.5);
	r.bottom = floorf(center.y + size / 2 + 0.5);
	r.left = floorf(center.x - size / 2 + 0.5);
	r.right = floorf(center.x + size / 2 + 0.5);

	BShape arrowShape;
	center.x += 0.5;
	center.y += 0.5;
	size *= 0.25;
	float hSize = size * 0.7;
	arrowShape.MoveTo(BPoint(center.x - hSize, center.y - size));
	arrowShape.LineTo(BPoint(center.x + hSize, center.y));
	arrowShape.LineTo(BPoint(center.x - hSize, center.y + size));

	fSuper->SetDrawingMode(B_OP_OVER);
	fSuper->SetHighColor(tint_color(bgColor, B_DARKEN_MAX_TINT));
	fSuper->SetPenSize(ceilf(size * 0.4));
	// NOTE: StrokeShape() offsets the shape by the current pen position,
	// it is not documented in the BeBook, but it is true!
	fSuper->MovePenTo(B_ORIGIN);
	fSuper->StrokeShape(&arrowShape);

	fSuper->PopState();
}
Esempio n. 12
0
void
LeafView::Draw(BRect updateRect)
{
	float scale = Bounds().Width() / kLeafWidth;
	BAffineTransform transform;
	transform.ScaleBy(scale);

	// BGradientRadial gradient(BPoint(kLeafWidth * 0.75, kLeafHeight * 1.5),
	//	kLeafWidth * 2);
	BGradientLinear gradient(B_ORIGIN,
		transform.Apply(BPoint(kLeafWidth, kLeafHeight)));
	rgb_color lightBlue = make_color(6, 169, 255);
	rgb_color darkBlue = make_color(0, 50, 126);
	gradient.AddColor(darkBlue, 0.0);
	gradient.AddColor(lightBlue, 255.0);

	// build leaf shape
	BShape leafShape;
	leafShape.MoveTo(transform.Apply(kLeafBegin));
	for (int i = 0; i < kNumLeafCurves; ++i) {
		BPoint controlPoints[3];
		for (int j = 0; j < 3; ++j)
			controlPoints[j] = transform.Apply(kLeafCurves[i][j]);
		leafShape.BezierTo(controlPoints);
	}
	leafShape.Close();

	PushState();
	SetDrawingMode(B_OP_ALPHA);
	SetHighColor(0, 0, 0, 50);
	for (int i = 2; i >= 0; --i) {
		SetOrigin(i * 0.1, i * 0.3);
		SetPenSize(i * 2);
		StrokeShape(&leafShape);
	}
	PopState();

	FillShape(&leafShape, gradient);
}
Esempio n. 13
0
void PathView::Draw(BRect updateRect) {
	if (fMode == kDrawOutline) {

	} else if (fMode == kStroke) {
		const int n = fPath.CountPoints();
		BShape shape;
		for (int i = 0; i < n; i++) {
			if (i == 0)
				shape.MoveTo(fPath.PointAt(i));
			else
				shape.LineTo(fPath.PointAt(i));
		}
		if (fPath.IsClosed()) shape.Close();
		SetPenSize(fWidth);
		StrokeShape(&shape);

		ShapeLPB path(&fPath, fWidth, LineCapMode(), LineJoinMode(), LineMiterLimit()); 
		path.CreateLinePath();
		SetPenSize(1);

		BPicture picture;
		BeginPicture(&picture);
		FillShape(path.Shape());
		EndPicture();

		PushState();
		ClipToPicture(&picture);
		SetHighColor(0, 255, 0);
		FillRect(Bounds());
		PopState();
		
		SetOrigin(200, 0);
		SetHighColor(255, 0, 0);
		StrokeShape(path.Shape());
		Flush();
	}
}
status_t
ServerLink::AttachShape(BShape& shape)
{
	int32 opCount, ptCount;
	uint32* opList;
	BPoint* ptList;

	shape.GetData(&opCount, &ptCount, &opList, &ptList);

	fSender->Attach(&opCount, sizeof(int32));
	fSender->Attach(&ptCount, sizeof(int32));
	if (opCount > 0)
		fSender->Attach(opList, opCount * sizeof(uint32));
	if (ptCount > 0)
		fSender->Attach(ptList, ptCount * sizeof(BPoint));
	return B_OK;
}
Esempio n. 15
0
void
MouseView::Draw(BRect updateFrame)
{
	SetDrawingMode(B_OP_ALPHA);
	SetBlendingMode(B_PIXEL_ALPHA, B_ALPHA_OVERLAY);
	SetScale(fScaling * 1.8);

	BShape mouseShape;
	mouseShape.MoveTo(BPoint(16, 12));
	// left
	BPoint control[3] = { BPoint(12, 16), BPoint(8, 64), BPoint(32, 64) };
	mouseShape.BezierTo(control);
	// right
	BPoint control2[3] = { BPoint(56, 64), BPoint(52, 16), BPoint(48, 12) };
	mouseShape.BezierTo(control2);
	// top
	BPoint control3[3] = { BPoint(44, 8), BPoint(20, 8), BPoint(16, 12) };
	mouseShape.BezierTo(control3);
	mouseShape.Close();

	// Draw the shadow
	SetOrigin(-17 * fScaling, -11 * fScaling);
	SetHighColor(kMouseShadowColor);
	FillShape(&mouseShape, B_SOLID_HIGH);

	// Draw the body
	SetOrigin(-21 * fScaling, -14 * fScaling);
	BGradientRadial bodyGradient(28, 24, 128);
	bodyGradient.AddColor(kMouseBodyTopColor, 0);
	bodyGradient.AddColor(kMouseBodyBottomColor, 255);

	FillShape(&mouseShape, bodyGradient);

	// Draw the outline
	SetPenSize(1 / 1.8 / fScaling);
	SetDrawingMode(B_OP_OVER);
	SetHighColor(kMouseOutlineColor);

	StrokeShape(&mouseShape, B_SOLID_HIGH);

	// bottom button border
	BShape buttonsOutline;
	buttonsOutline.MoveTo(BPoint(13, 27));
	BPoint control4[] = { BPoint(18, 30), BPoint(46, 30), BPoint(51, 27) };
	buttonsOutline.BezierTo(control4);

	SetHighColor(kMouseButtonOutlineColor);
	StrokeShape(&buttonsOutline, B_SOLID_HIGH);

	SetScale(1);
	SetOrigin(0, 0);

	// Separator between the buttons
	const int32* offset = getButtonOffsets(fType);
	for (int32 i = 1; i < fType; i++) {
		BRect buttonRect = _ButtonRect(offset, i);
		StrokeLine(buttonRect.LeftTop(), buttonRect.LeftBottom());
	}

	mouse_map map;
	fSettings.Mapping(map);

	SetDrawingMode(B_OP_OVER);

	if (fButtons != 0)
		ClipToPicture(&fButtonsPicture, B_ORIGIN, false);

	for (int32 i = 0; i < fType; i++) {
		// draw mapping number centered over the button

		bool pressed = (fButtons & map.button[_ConvertFromVisualOrder(i)]) != 0;
			// is button currently pressed?
		if (pressed) {
			SetDrawingMode(B_OP_ALPHA);
			SetHighColor(kButtonPressedColor);
			FillRect(_ButtonRect(offset, i));
		}

		BRect border(fScaling * (offset[i] + 1), fScaling * (kButtonTop + 5),
			fScaling * offset[i + 1] - 1,
			fScaling * (kButtonTop + kMouseDownHeight - 4));
		if (i == 0)
			border.left += fScaling * 5;
		if (i == fType - 1)
			border.right -= fScaling * 4;

		char number[2] = {0};
		number[0] = getMappingNumber(map.button[_ConvertFromVisualOrder(i)])
			+ '1';

		SetDrawingMode(B_OP_OVER);
		SetHighColor(kButtonTextColor);
		DrawString(number, BPoint(
			border.left + (border.Width() - StringWidth(number)) / 2,
			border.top + fDigitBaseline
				+ (border.IntegerHeight() - fDigitHeight) / 2));
	}

	if (fButtons != 0)
		ClipToPicture(NULL);
}
Esempio n. 16
0
BShape*
TransportControlGroup::_CreateSpeakerShape(float height) const
{
	BShape* shape = new BShape();

	float step = floorf(height / 8);
	float magnetWidth = floorf(height / 5);
	float chassieWidth = floorf(height / 1.5);
	float chassieHeight = floorf(height / 4);

	shape->MoveTo(BPoint(0, height - step));
	shape->LineTo(BPoint(magnetWidth, height - step));
	shape->LineTo(BPoint(magnetWidth, height / 2 + chassieHeight));
	shape->LineTo(BPoint(magnetWidth + chassieWidth - step, height + step));
	shape->LineTo(BPoint(magnetWidth + chassieWidth, height + step));
	shape->LineTo(BPoint(magnetWidth + chassieWidth, -step));
	shape->LineTo(BPoint(magnetWidth + chassieWidth - step, -step));
	shape->LineTo(BPoint(magnetWidth, height / 2 - chassieHeight));
	shape->LineTo(BPoint(magnetWidth, step));
	shape->LineTo(BPoint(0, step));
	shape->Close();

	float offset = magnetWidth + chassieWidth + step * 2;
	add_bow(shape, offset, 3 * step, height, step * 2);
	offset += step * 2;
	add_bow(shape, offset, 5 * step, height, step * 2);
	offset += step * 2;
	add_bow(shape, offset, 7 * step, height, step * 2);

	return shape;
}
Esempio n. 17
0
			point.x += fOffsetX;
			point.y += fOffsetY;
			return B_OK;
		}

	private:
		float fOffsetX;
		float fOffsetY;
	} translator;

	MovePenTo(B_ORIGIN);

	const float arcRX = 50;
	const float arcRY = 80;

	BShape shape;
	shape.MoveTo(BPoint(20, 10));
	shape.LineTo(BPoint(10, 90));
	shape.LineTo(BPoint(90, 100));
	shape.ArcTo(arcRX, arcRY, 45, true, true, BPoint(100, 20));
	shape.Close();

	StrokeShape(&shape);

	shape.Clear();
	shape.MoveTo(BPoint(20, 10));
	shape.LineTo(BPoint(10, 90));
	shape.LineTo(BPoint(90, 100));
	shape.ArcTo(arcRX, arcRY, 45, false, true, BPoint(100, 20));
	shape.Close();
void
ActivityView::_DrawHistory(bool drawBackground)
{
	_UpdateOffscreenBitmap();

	BView* view = this;
	if (fOffscreen != NULL) {
		fOffscreen->Lock();
		view = _OffscreenView();
	}

	BRect frame = _HistoryFrame();
	BRect outerFrame = frame.InsetByCopy(-2, -2);

	// draw the outer frame
	uint32 flags = 0;
	if (!drawBackground)
		flags |= BControlLook::B_BLEND_FRAME;
	be_control_look->DrawTextControlBorder(this, outerFrame,
		outerFrame, fLegendBackgroundColor, flags);

	// convert to offscreen view if necessary
	if (view != this)
		frame.OffsetTo(B_ORIGIN);

	view->SetLowColor(fHistoryBackgroundColor);
	view->FillRect(frame, B_SOLID_LOW);

	uint32 step = 2;
	uint32 resolution = fDrawResolution;
	if (fDrawResolution > 1) {
		step = 1;
		resolution--;
	}

	uint32 width = frame.IntegerWidth() - 10;
	uint32 steps = width / step;
	bigtime_t timeStep = RefreshInterval() * resolution;
	bigtime_t now = system_time();

	// Draw scale
	// TODO: add second markers?

	view->SetPenSize(1);

	rgb_color scaleColor = view->LowColor();
	uint32 average = (scaleColor.red + scaleColor.green + scaleColor.blue) / 3;
	if (average < 96)
		scaleColor = tint_color(scaleColor, B_LIGHTEN_2_TINT);
	else
		scaleColor = tint_color(scaleColor, B_DARKEN_2_TINT);

	view->SetHighColor(scaleColor);
	view->StrokeLine(BPoint(frame.left, frame.top + frame.Height() / 2),
		BPoint(frame.right, frame.top + frame.Height() / 2));

	// Draw values

	view->SetPenSize(1.5);
	BAutolock _(fSourcesLock);

	for (uint32 i = fSources.CountItems(); i-- > 0;) {
		ViewHistory* viewValues = fViewValues.ItemAt(i);
		DataSource* source = fSources.ItemAt(i);
		DataHistory* values = fValues.ItemAt(i);

		viewValues->Update(values, steps, fDrawResolution, now, timeStep,
			RefreshInterval());

		uint32 x = viewValues->Start() * step;
		BShape shape;
		bool first = true;

		for (uint32 i = viewValues->Start(); i < steps; x += step, i++) {
			float y = _PositionForValue(source, values,
				viewValues->ValueAt(i));

			if (first) {
				shape.MoveTo(BPoint(x, y));
				first = false;
			} else
				shape.LineTo(BPoint(x, y));
		}

		view->SetHighColor(source->Color());
		view->SetLineMode(B_BUTT_CAP, B_ROUND_JOIN);
		view->MovePenTo(B_ORIGIN);
		view->StrokeShape(&shape);
	}

	// TODO: add marks when an app started or quit
	view->Sync();
	if (fOffscreen != NULL) {
		fOffscreen->Unlock();
		DrawBitmap(fOffscreen, outerFrame.LeftTop());
	}
}
Esempio n. 19
0
BShape*
TransportControlGroup::_CreatePauseShape(float height) const
{
	BShape* shape = new BShape();

	float stemWidth = floorf(height / 3);

	shape->MoveTo(BPoint(0, height));
	shape->LineTo(BPoint(stemWidth, height));
	shape->LineTo(BPoint(stemWidth, 0));
	shape->LineTo(BPoint(0, 0));
	shape->Close();

	shape->MoveTo(BPoint(height - stemWidth, height));
	shape->LineTo(BPoint(height, height));
	shape->LineTo(BPoint(height, 0));
	shape->LineTo(BPoint(height - stemWidth, 0));
	shape->Close();

	return shape;
}
Esempio n. 20
0
BShape*
TransportControlGroup::_CreateSkipForwardShape(float height) const
{
	BShape* shape = new BShape();

	shape->MoveTo(BPoint(height, height / 2));
	shape->LineTo(BPoint(0, height));
	shape->LineTo(BPoint(0, 0));
	shape->Close();

	shape->MoveTo(BPoint(height * 2, height / 2));
	shape->LineTo(BPoint(height, height));
	shape->LineTo(BPoint(height, 0));
	shape->Close();

	float stopWidth = ceilf(height / 6);

	shape->MoveTo(BPoint(height * 2, height));
	shape->LineTo(BPoint(height * 2 + stopWidth, height));
	shape->LineTo(BPoint(height * 2 + stopWidth, 0));
	shape->LineTo(BPoint(height * 2, 0));
	shape->Close();

	return shape;
}
Esempio n. 21
0
void ShapeLPB::LineTo(BPoint p)
{
	fShape.LineTo(p);
}
Esempio n. 22
0
void
TextDocumentView::_GetSelectionShape(BShape& shape, int32 start, int32 end)
{
	float startX1;
	float startY1;
	float startX2;
	float startY2;
	fTextDocumentLayout.GetTextBounds(start, startX1, startY1, startX2,
		startY2);

	startX1 = floorf(startX1);
	startY1 = floorf(startY1);
	startX2 = ceilf(startX2);
	startY2 = ceilf(startY2);

	float endX1;
	float endY1;
	float endX2;
	float endY2;
	fTextDocumentLayout.GetTextBounds(end, endX1, endY1, endX2, endY2);

	endX1 = floorf(endX1);
	endY1 = floorf(endY1);
	endX2 = ceilf(endX2);
	endY2 = ceilf(endY2);

	int32 startLineIndex = fTextDocumentLayout.LineIndexForOffset(start);
	int32 endLineIndex = fTextDocumentLayout.LineIndexForOffset(end);

	if (startLineIndex == endLineIndex) {
		// Selection on one line
		BPoint lt(startX1, startY1);
		BPoint rt(endX1, endY1);
		BPoint rb(endX1, endY2);
		BPoint lb(startX1, startY2);

		shape.MoveTo(lt);
		shape.LineTo(rt);
		shape.LineTo(rb);
		shape.LineTo(lb);
		shape.Close();
	} else if (startLineIndex == endLineIndex - 1 && endX1 <= startX1) {
		// Selection on two lines, with gap:
		// ---------
		// ------###
		// ##-------
		// ---------
		float width = ceilf(fTextDocumentLayout.Width());

		BPoint lt(startX1, startY1);
		BPoint rt(width, startY1);
		BPoint rb(width, startY2);
		BPoint lb(startX1, startY2);

		shape.MoveTo(lt);
		shape.LineTo(rt);
		shape.LineTo(rb);
		shape.LineTo(lb);
		shape.Close();

		lt = BPoint(0, endY1);
		rt = BPoint(endX1, endY1);
		rb = BPoint(endX1, endY2);
		lb = BPoint(0, endY2);

		shape.MoveTo(lt);
		shape.LineTo(rt);
		shape.LineTo(rb);
		shape.LineTo(lb);
		shape.Close();
	} else {
		// Selection over multiple lines
		float width = ceilf(fTextDocumentLayout.Width());

		shape.MoveTo(BPoint(startX1, startY1));
		shape.LineTo(BPoint(width, startY1));
		shape.LineTo(BPoint(width, endY1));
		shape.LineTo(BPoint(endX1, endY1));
		shape.LineTo(BPoint(endX1, endY2));
		shape.LineTo(BPoint(0, endY2));
		shape.LineTo(BPoint(0, startY2));
		shape.LineTo(BPoint(startX1, startY2));
		shape.Close();
	}
}
Esempio n. 23
0
void GraphicsContext::fillRoundedRect(const IntRect& rect, const IntSize& topLeft, const IntSize& topRight, const IntSize& bottomLeft, const IntSize& bottomRight, const Color& color, ColorSpace colorSpace)
{
    if (paintingDisabled() || !color.alpha())
        return;

    BPoint points[3];
    const float kRadiusBezierScale = 0.56f;

    BShape shape;
    shape.MoveTo(BPoint(rect.x() + topLeft.width(), rect.y()));
    shape.LineTo(BPoint(rect.maxX() - topRight.width(), rect.y()));
    points[0].x = rect.maxX() - kRadiusBezierScale * topRight.width();
    points[0].y = rect.y();
    points[1].x = rect.maxX();
    points[1].y = rect.y() + kRadiusBezierScale * topRight.height();
    points[2].x = rect.maxX();
    points[2].y = rect.y() + topRight.height();
    shape.BezierTo(points);
    shape.LineTo(BPoint(rect.maxX(), rect.maxY() - bottomRight.height()));
    points[0].x = rect.maxX();
    points[0].y = rect.maxY() - kRadiusBezierScale * bottomRight.height();
    points[1].x = rect.maxX() - kRadiusBezierScale * bottomRight.width();
    points[1].y = rect.maxY();
    points[2].x = rect.maxX() - bottomRight.width();
    points[2].y = rect.maxY();
    shape.BezierTo(points);
    shape.LineTo(BPoint(rect.x() + bottomLeft.width(), rect.maxY()));
    points[0].x = rect.x() + kRadiusBezierScale * bottomLeft.width();
    points[0].y = rect.maxY();
    points[1].x = rect.x();
    points[1].y = rect.maxY() - kRadiusBezierScale * bottomRight.height();
    points[2].x = rect.x();
    points[2].y = rect.maxY() - bottomRight.height();
    shape.BezierTo(points);
    shape.LineTo(BPoint(rect.x(), rect.y() + topLeft.height()));
    points[0].x = rect.x();
    points[0].y = rect.y() - kRadiusBezierScale * topLeft.height();
    points[1].x = rect.x() + kRadiusBezierScale * topLeft.width();
    points[1].y = rect.y();
    points[2].x = rect.x() + topLeft.width();
    points[2].y = rect.y();
    shape.BezierTo(points);
    shape.Close();

    rgb_color oldColor = m_data->view()->HighColor();
    m_data->view()->SetHighColor(color);
    m_data->view()->MovePenTo(B_ORIGIN);
    m_data->view()->FillShape(&shape);
    m_data->view()->SetHighColor(oldColor);
}
Esempio n. 24
0
void ShapeLPB::MoveTo(BPoint p)
{
	fShape.MoveTo(p);
}
Esempio n. 25
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. 27
0
status_t
PicturePlayer::_Play(const picture_player_callbacks& callbacks, void* userData,
	const void* buffer, size_t length, uint16 parentOp)
{
#if DEBUG
	printf("Start rendering %sBPicture...\n", parentOp != 0 ? "sub " : "");
	bigtime_t startTime = system_time();
	int32 numOps = 0;
#endif

	DataReader pictureReader(buffer, length);

	while (pictureReader.Remaining() > 0) {
		const picture_data_entry_header* header;
		const uint8* opData = NULL;
		if (!pictureReader.Get(header)
			|| !pictureReader.Get(opData, header->size)) {
			return B_BAD_DATA;
		}

		DataReader reader(opData, header->size);

		// Disallow ops that don't fit the parent.
		switch (parentOp) {
			case 0:
				// No parent op, no restrictions.
				break;

			case B_PIC_ENTER_STATE_CHANGE:
				if (header->op <= B_PIC_ENTER_STATE_CHANGE
					|| header->op > B_PIC_SET_TRANSFORM) {
					return B_BAD_DATA;
				}
				break;

			case B_PIC_ENTER_FONT_STATE:
				if (header->op < B_PIC_SET_FONT_FAMILY
					|| header->op > B_PIC_SET_FONT_FACE) {
					return B_BAD_DATA;
					}
				break;

			default:
				return B_BAD_DATA;
		}

#if DEBUG > 1
		bigtime_t startOpTime = system_time();
		printf("Op %s ", PictureOpToString(header->op));
#endif
		switch (header->op) {
			case B_PIC_MOVE_PEN_BY:
			{
				const BPoint* where;
				if (callbacks.move_pen_by == NULL || !reader.Get(where))
					break;

				callbacks.move_pen_by(userData, *where);
				break;
			}

			case B_PIC_STROKE_LINE:
			{
				const BPoint* start;
				const BPoint* end;
				if (callbacks.stroke_line == NULL || !reader.Get(start)
					|| !reader.Get(end)) {
					break;
				}

				callbacks.stroke_line(userData, *start, *end);
				break;
			}

			case B_PIC_STROKE_RECT:
			case B_PIC_FILL_RECT:
			{
				const BRect* rect;
				if (callbacks.draw_rect == NULL || !reader.Get(rect))
					break;

				callbacks.draw_rect(userData, *rect,
					header->op == B_PIC_FILL_RECT);
				break;
			}

			case B_PIC_STROKE_ROUND_RECT:
			case B_PIC_FILL_ROUND_RECT:
			{
				const BRect* rect;
				const BPoint* radii;
				if (callbacks.draw_round_rect == NULL || !reader.Get(rect)
					|| !reader.Get(radii)) {
					break;
				}

				callbacks.draw_round_rect(userData, *rect, *radii,
					header->op == B_PIC_FILL_ROUND_RECT);
				break;
			}

			case B_PIC_STROKE_BEZIER:
			case B_PIC_FILL_BEZIER:
			{
				const size_t kNumControlPoints = 4;
				const BPoint* controlPoints;
				if (callbacks.draw_bezier == NULL
					|| !reader.Get(controlPoints, kNumControlPoints)) {
					break;
				}

				callbacks.draw_bezier(userData, kNumControlPoints,
					controlPoints, header->op == B_PIC_FILL_BEZIER);
				break;
			}

			case B_PIC_STROKE_ARC:
			case B_PIC_FILL_ARC:
			{
				const BPoint* center;
				const BPoint* radii;
				const float* startTheta;
				const float* arcTheta;
				if (callbacks.draw_arc == NULL || !reader.Get(center)
					|| !reader.Get(radii) || !reader.Get(startTheta)
					|| !reader.Get(arcTheta)) {
					break;
				}

				callbacks.draw_arc(userData, *center, *radii, *startTheta,
					*arcTheta, header->op == B_PIC_FILL_ARC);
				break;
			}

			case B_PIC_STROKE_ELLIPSE:
			case B_PIC_FILL_ELLIPSE:
			{
				const BRect* rect;
				if (callbacks.draw_ellipse == NULL || !reader.Get(rect))
					break;

				callbacks.draw_ellipse(userData, *rect,
					header->op == B_PIC_FILL_ELLIPSE);
				break;
			}

			case B_PIC_STROKE_POLYGON:
			case B_PIC_FILL_POLYGON:
			{
				const uint32* numPoints;
				const BPoint* points;
				if (callbacks.draw_polygon == NULL || !reader.Get(numPoints)
					|| !reader.Get(points, *numPoints)) {
					break;
				}

				bool isClosed = true;
				const bool* closedPointer;
				if (header->op != B_PIC_FILL_POLYGON) {
					if (!reader.Get(closedPointer))
						break;

					isClosed = *closedPointer;
				}

				callbacks.draw_polygon(userData, *numPoints, points, isClosed,
					header->op == B_PIC_FILL_POLYGON);
				break;
			}

			case B_PIC_STROKE_SHAPE:
			case B_PIC_FILL_SHAPE:
			{
				const uint32* opCount;
				const uint32* pointCount;
				const uint32* opList;
				const BPoint* pointList;
				if (callbacks.draw_shape == NULL || !reader.Get(opCount)
					|| !reader.Get(pointCount) || !reader.Get(opList, *opCount)
					|| !reader.Get(pointList, *pointCount)) {
					break;
				}

				// TODO: remove BShape data copying
				BShape shape;
				shape.SetData(*opCount, *pointCount, opList, pointList);

				callbacks.draw_shape(userData, shape,
					header->op == B_PIC_FILL_SHAPE);
				break;
			}

			case B_PIC_DRAW_STRING:
			{
				const float* escapementSpace;
				const float* escapementNonSpace;
				const char* string;
				size_t length;
				if (callbacks.draw_string == NULL
					|| !reader.Get(escapementSpace)
					|| !reader.Get(escapementNonSpace)
					|| !reader.GetRemaining(string, length)) {
					break;
				}

				callbacks.draw_string(userData, string, length,
					*escapementSpace, *escapementNonSpace);
				break;
			}

			case B_PIC_DRAW_PIXELS:
			{
				const BRect* sourceRect;
				const BRect* destinationRect;
				const uint32* width;
				const uint32* height;
				const uint32* bytesPerRow;
				const uint32* colorSpace;
				const uint32* flags;
				const void* data;
				size_t length;
				if (callbacks.draw_pixels == NULL || !reader.Get(sourceRect)
					|| !reader.Get(destinationRect) || !reader.Get(width)
					|| !reader.Get(height) || !reader.Get(bytesPerRow)
					|| !reader.Get(colorSpace) || !reader.Get(flags)
					|| !reader.GetRemaining(data, length)) {
					break;
				}

				callbacks.draw_pixels(userData, *sourceRect, *destinationRect,
					*width, *height, *bytesPerRow, (color_space)*colorSpace,
					*flags, data, length);
				break;
			}

			case B_PIC_DRAW_PICTURE:
			{
				const BPoint* where;
				const int32* token;
				if (callbacks.draw_picture == NULL || !reader.Get(where)
					|| !reader.Get(token)) {
					break;
				}

				callbacks.draw_picture(userData, *where, *token);
				break;
			}

			case B_PIC_SET_CLIPPING_RECTS:
			{
				const uint32* numRects;
				const BRect* rects;
				if (callbacks.set_clipping_rects == NULL
					|| !reader.Get(numRects) || !reader.Get(rects, *numRects)) {
					break;
				}

				callbacks.set_clipping_rects(userData, *numRects, rects);
				break;
			}

			case B_PIC_CLEAR_CLIPPING_RECTS:
			{
				if (callbacks.set_clipping_rects == NULL)
					break;

				callbacks.set_clipping_rects(userData, 0, NULL);
				break;
			}

			case B_PIC_CLIP_TO_PICTURE:
			{
				const int32* token;
				const BPoint* where;
				const bool* inverse;
				if (callbacks.clip_to_picture == NULL || !reader.Get(token)
					|| !reader.Get(where) || !reader.Get(inverse))
					break;

				callbacks.clip_to_picture(userData, *token, *where, *inverse);
				break;
			}

			case B_PIC_PUSH_STATE:
			{
				if (callbacks.push_state == NULL)
					break;

				callbacks.push_state(userData);
				break;
			}

			case B_PIC_POP_STATE:
			{
				if (callbacks.pop_state == NULL)
					break;

				callbacks.pop_state(userData);
				break;
			}

			case B_PIC_ENTER_STATE_CHANGE:
			case B_PIC_ENTER_FONT_STATE:
			{
				const void* data;
				size_t length;
				if (!reader.GetRemaining(data, length))
					break;

				if (header->op == B_PIC_ENTER_STATE_CHANGE) {
					if (callbacks.enter_state_change != NULL)
						callbacks.enter_state_change(userData);
				} else if (callbacks.enter_font_state != NULL)
					callbacks.enter_font_state(userData);

				status_t result = _Play(callbacks, userData, data, length,
					header->op);
				if (result != B_OK)
					return result;

				if (header->op == B_PIC_ENTER_STATE_CHANGE) {
					if (callbacks.exit_state_change != NULL)
						callbacks.exit_state_change(userData);
				} else if (callbacks.exit_font_state != NULL)
					callbacks.exit_font_state(userData);

				break;
			}

			case B_PIC_SET_ORIGIN:
			{
				const BPoint* origin;
				if (callbacks.set_origin == NULL || !reader.Get(origin))
					break;

				callbacks.set_origin(userData, *origin);
				break;
			}

			case B_PIC_SET_PEN_LOCATION:
			{
				const BPoint* location;
				if (callbacks.set_pen_location == NULL || !reader.Get(location))
					break;

				callbacks.set_pen_location(userData, *location);
				break;
			}

			case B_PIC_SET_DRAWING_MODE:
			{
				const uint16* mode;
				if (callbacks.set_drawing_mode == NULL || !reader.Get(mode))
					break;

				callbacks.set_drawing_mode(userData, (drawing_mode)*mode);
				break;
			}

			case B_PIC_SET_LINE_MODE:
			{
				const uint16* capMode;
				const uint16* joinMode;
				const float* miterLimit;
				if (callbacks.set_line_mode == NULL || !reader.Get(capMode)
					|| !reader.Get(joinMode) || !reader.Get(miterLimit)) {
					break;
				}

				callbacks.set_line_mode(userData, (cap_mode)*capMode,
					(join_mode)*joinMode, *miterLimit);
				break;
			}

			case B_PIC_SET_PEN_SIZE:
			{
				const float* penSize;
				if (callbacks.set_pen_size == NULL || !reader.Get(penSize))
					break;

				callbacks.set_pen_size(userData, *penSize);
				break;
			}

			case B_PIC_SET_FORE_COLOR:
			{
				const rgb_color* color;
				if (callbacks.set_fore_color == NULL || !reader.Get(color))
					break;

				callbacks.set_fore_color(userData, *color);
				break;
			}

			case B_PIC_SET_BACK_COLOR:
			{
				const rgb_color* color;
				if (callbacks.set_back_color == NULL || !reader.Get(color))
					break;

				callbacks.set_back_color(userData, *color);
				break;
			}

			case B_PIC_SET_STIPLE_PATTERN:
			{
				const pattern* stipplePattern;
				if (callbacks.set_stipple_pattern == NULL
					|| !reader.Get(stipplePattern)) {
					break;
				}

				callbacks.set_stipple_pattern(userData, *stipplePattern);
				break;
			}

			case B_PIC_SET_SCALE:
			{
				const float* scale;
				if (callbacks.set_scale == NULL || !reader.Get(scale))
					break;

				callbacks.set_scale(userData, *scale);
				break;
			}

			case B_PIC_SET_FONT_FAMILY:
			{
				const char* family;
				size_t length;
				if (callbacks.set_font_family == NULL
					|| !reader.GetRemaining(family, length)) {
					break;
				}

				callbacks.set_font_family(userData, family, length);
				break;
			}

			case B_PIC_SET_FONT_STYLE:
			{
				const char* style;
				size_t length;
				if (callbacks.set_font_style == NULL
					|| !reader.GetRemaining(style, length)) {
					break;
				}

				callbacks.set_font_style(userData, style, length);
				break;
			}

			case B_PIC_SET_FONT_SPACING:
			{
				const uint32* spacing;
				if (callbacks.set_font_spacing == NULL || !reader.Get(spacing))
					break;

				callbacks.set_font_spacing(userData, *spacing);
				break;
			}

			case B_PIC_SET_FONT_SIZE:
			{
				const float* size;
				if (callbacks.set_font_size == NULL || !reader.Get(size))
					break;

				callbacks.set_font_size(userData, *size);
				break;
			}

			case B_PIC_SET_FONT_ROTATE:
			{
				const float* rotation;
				if (callbacks.set_font_rotation == NULL
					|| !reader.Get(rotation)) {
					break;
				}

				callbacks.set_font_rotation(userData, *rotation);
				break;
			}

			case B_PIC_SET_FONT_ENCODING:
			{
				const uint32* encoding;
				if (callbacks.set_font_encoding == NULL
					|| !reader.Get(encoding)) {
					break;
				}

				callbacks.set_font_encoding(userData, *encoding);
				break;
			}

			case B_PIC_SET_FONT_FLAGS:
			{
				const uint32* flags;
				if (callbacks.set_font_flags == NULL || !reader.Get(flags))
					break;

				callbacks.set_font_flags(userData, *flags);
				break;
			}

			case B_PIC_SET_FONT_SHEAR:
			{
				const float* shear;
				if (callbacks.set_font_shear == NULL || !reader.Get(shear))
					break;

				callbacks.set_font_shear(userData, *shear);
				break;
			}

			case B_PIC_SET_FONT_FACE:
			{
				const uint32* face;
				if (callbacks.set_font_face == NULL || !reader.Get(face))
					break;

				callbacks.set_font_face(userData, *face);
				break;
			}

			case B_PIC_SET_BLENDING_MODE:
			{
				const uint16* alphaSourceMode;
				const uint16* alphaFunctionMode;
				if (callbacks.set_blending_mode == NULL
					|| !reader.Get(alphaSourceMode)
					|| !reader.Get(alphaFunctionMode)) {
					break;
				}

				callbacks.set_blending_mode(userData,
					(source_alpha)*alphaSourceMode,
					(alpha_function)*alphaFunctionMode);
				break;
			}

			case B_PIC_SET_TRANSFORM:
			{
				const BAffineTransform* transform;
				if (callbacks.set_transform == NULL || !reader.Get(transform))
					break;

				callbacks.set_transform(userData, *transform);
				break;
			}

			case B_PIC_AFFINE_TRANSLATE:
			{
				const double* x;
				const double* y;
				if (callbacks.translate_by == NULL || !reader.Get(x)
					|| !reader.Get(y)) {
					break;
				}

				callbacks.translate_by(userData, *x, *y);
				break;
			}

			case B_PIC_AFFINE_SCALE:
			{
				const double* x;
				const double* y;
				if (callbacks.scale_by == NULL || !reader.Get(x)
					|| !reader.Get(y)) {
					break;
				}

				callbacks.scale_by(userData, *x, *y);
				break;
			}

			case B_PIC_AFFINE_ROTATE:
			{
				const double* angleRadians;
				if (callbacks.rotate_by == NULL || !reader.Get(angleRadians))
					break;

				callbacks.rotate_by(userData, *angleRadians);
				break;
			}

			case B_PIC_BLEND_LAYER:
			{
				Layer* const* layer;
				if (callbacks.blend_layer == NULL || !reader.Get<Layer*>(layer))
					break;

				callbacks.blend_layer(userData, *layer);
				break;
			}

			case B_PIC_CLIP_TO_RECT:
			{
				const bool* inverse;
				const BRect* rect;

				if (callbacks.clip_to_rect == NULL || !reader.Get(inverse)
					|| !reader.Get(rect)) {
					break;
				}

				callbacks.clip_to_rect(userData, *rect, *inverse);
				break;
			}

			case B_PIC_CLIP_TO_SHAPE:
			{
				const bool* inverse;
				const uint32* opCount;
				const uint32* pointCount;
				const uint32* opList;
				const BPoint* pointList;
				if (callbacks.clip_to_shape == NULL || !reader.Get(inverse)
					|| !reader.Get(opCount) || !reader.Get(pointCount)
					|| !reader.Get(opList, *opCount)
					|| !reader.Get(pointList, *pointCount)) {
					break;
				}

				callbacks.clip_to_shape(userData, *opCount, opList,
					*pointCount, pointList, *inverse);
				break;
			}

			default:
				break;
		}

#if DEBUG
		numOps++;
#if DEBUG > 1
		printf("executed in %" B_PRId64 " usecs\n", system_time()
			- startOpTime);
#endif
#endif
	}

#if DEBUG
	printf("Done! %" B_PRId32 " ops, rendering completed in %" B_PRId64
		" usecs.\n", numOps, system_time() - startTime);
#endif
	return B_OK;
}
Esempio n. 28
0
void ShapeLPB::BezierTo(BPoint p[3])
{
	fShape.BezierTo(p);
}
Esempio n. 29
0
// _Import
status_t
StyledTextImporter::_Import(Icon* icon, const char *text, text_run_array *runs)
{
	CALLED();
	status_t ret = Init(icon);
	if (ret < B_OK) {
		printf("StyledTextImporter::Import() - "
			   "Init() error: %s\n", strerror(ret));
		return ret;
	}

	BString str(text);
	if (str.Length() > 50) {
		BAlert* alert = new BAlert("too big",
			"The text you are trying to import is quite long, are you sure?",
			"Yes", "No", NULL, B_WIDTH_AS_USUAL, B_WARNING_ALERT);
		if (alert->Go())
			return B_CANCELED;
	}

	// import run colors as styles
	if (runs) {
		delete[] fStyleMap;
		fStyleMap = new struct style_map[runs->count];
		for (int32 i = 0; runs && i < runs->count; i++) {
			_AddStyle(icon, &runs->runs[i]);
		}
	}

	int32 currentRun = 0;
	text_run *run = NULL;
	if (runs)
		run = &runs->runs[0];
	int32 len = str.Length();
	int32 chars = str.CountChars();
	BPoint origin(0,0);
	BPoint offset(origin);

	for (int32 i = 0, c = 0; i < len && c < chars; c++) {
		// make sure we are still on the (good) run
		while (run && currentRun < runs->count - 1 &&
			i >= runs->runs[currentRun + 1].offset) {
			run = &runs->runs[++currentRun];
			//printf("switching to run %d\n", currentRun);
		}

		int charLen;
		for (charLen = 1; str.ByteAt(i + charLen) & 0x80; charLen++);

		BShape glyph;
		BShape *glyphs[1] = { &glyph };
		BFont font(be_plain_font);
		if (run)
			font = run->font;

		// first char
		if (offset == BPoint(0,0)) {
			font_height height;
			font.GetHeight(&height);
			origin.y += height.ascent;
			offset = origin;
		}
		// LF
		if (str[i] == '\n') {
			// XXX: should take the MAX() for the line
			// XXX: should use descent + leading from previous line
			font_height height;
			font.GetHeight(&height);
			origin.y += height.ascent + height.descent + height.leading;
			offset = origin;
			i++;
			continue;
		}

		float charWidth;
		charWidth = font.StringWidth(str.String() + i, charLen);
		//printf("StringWidth( %d) = %f\n", charLen, charWidth);
		BString glyphName(str.String() + i, charLen);
		glyphName.Prepend("Glyph (");
		glyphName.Append(")");

		font.GetGlyphShapes((str.String() + i), 1, glyphs);
		if (glyph.Bounds().IsValid()) {
			//offset.x += glyph.Bounds().Width();
			offset.x += charWidth;
			Shape* shape = new (nothrow) Shape(NULL);
			shape->SetName(glyphName.String());
			if (!shape || !icon->Shapes()->AddShape(shape)) {
				delete shape;
				return B_NO_MEMORY;
			}
			for (int j = 0; run && j < fStyleCount; j++) {
				if (fStyleMap[j].run == run) {
					shape->SetStyle(fStyleMap[j].style);
					break;
				}
			}
			ShapeIterator iterator(icon, shape, offset, glyphName.String());
			if (iterator.Iterate(&glyph) < B_OK)
				return B_ERROR;

		}

		// skip the rest of UTF-8 char bytes
		for (i++; i < len && str[i] & 0x80; i++);
	}

	delete[] fStyleMap;
	fStyleMap = NULL;

	return B_OK;
}
Esempio n. 30
0
void ShapeLPB::ClosePath(void)
{
	fShape.Close();
}