Exemplo n.º 1
0
static void
draw_polygon(void* _context, size_t numPoints, const BPoint viewPoints[],
	bool isClosed, bool fill)
{
	DrawingContext* context = reinterpret_cast<DrawingContext *>(_context);

	if (numPoints == 0)
		return;

	const size_t kMaxStackCount = 200;
	char stackData[kMaxStackCount * sizeof(BPoint)];
	BPoint* points = (BPoint*)stackData;
	if (numPoints > kMaxStackCount) {
		points = (BPoint*)malloc(numPoints * sizeof(BPoint));
		if (points == NULL)
			return;
	}

	context->ConvertToScreenForDrawing(points, viewPoints, numPoints);

	BRect polyFrame;
	get_polygon_frame(points, numPoints, &polyFrame);

	context->GetDrawingEngine()->DrawPolygon(points, numPoints, polyFrame,
		fill, isClosed && numPoints > 2);

	if (numPoints > kMaxStackCount)
		free(points);
}
Exemplo n.º 2
0
static void
stroke_line(void* _context, const BPoint& _start, const BPoint& _end)
{
	DrawingContext* context = reinterpret_cast<DrawingContext *>(_context);
	BPoint start = _start;
	BPoint end = _end;

	context->ConvertToScreenForDrawing(&start);
	context->ConvertToScreenForDrawing(&end);
	context->GetDrawingEngine()->StrokeLine(start, end);

	context->CurrentState()->SetPenLocation(_end);
	// the DrawingEngine/Painter does not need to be updated, since this
	// effects only the view->screen coord conversion, which is handled
	// by the view only
}
Exemplo n.º 3
0
static void
draw_ellipse(void* _context, const BRect& _rect, bool fill)
{
	DrawingContext* context = reinterpret_cast<DrawingContext *>(_context);

	BRect rect = _rect;
	context->ConvertToScreenForDrawing(&rect);
	context->GetDrawingEngine()->DrawEllipse(rect, fill);
}
Exemplo n.º 4
0
static void
pop_state(void* _context)
{
	DrawingContext* context = reinterpret_cast<DrawingContext *>(_context);
	context->PopState();

	BPoint p(0, 0);
	context->ConvertToScreenForDrawing(&p);
	context->GetDrawingEngine()->SetDrawState(context->CurrentState(),
		(int32)p.x, (int32)p.y);
}
Exemplo n.º 5
0
static void
draw_arc(void* _context, const BPoint& center, const BPoint& radii,
	float startTheta, float arcTheta, bool fill)
{
	DrawingContext* context = reinterpret_cast<DrawingContext *>(_context);

	BRect rect(center.x - radii.x, center.y - radii.y,
		center.x + radii.x - 1, center.y + radii.y - 1);
	context->ConvertToScreenForDrawing(&rect);
	context->GetDrawingEngine()->DrawArc(rect, startTheta, arcTheta, fill);
}
Exemplo n.º 6
0
static void
draw_round_rect(void* _context, const BRect& _rect, const BPoint& radii,
	bool fill)
{
	DrawingContext* context = reinterpret_cast<DrawingContext *>(_context);
	BRect rect = _rect;

	context->ConvertToScreenForDrawing(&rect);
	float scale = context->CurrentState()->CombinedScale();
	context->GetDrawingEngine()->DrawRoundRect(rect, radii.x * scale,
		radii.y * scale, fill);
}
Exemplo n.º 7
0
static void
draw_rect(void* _context, const BRect& _rect, bool fill)
{
	DrawingContext* context = reinterpret_cast<DrawingContext *>(_context);
	BRect rect = _rect;

	context->ConvertToScreenForDrawing(&rect);
	if (fill)
		context->GetDrawingEngine()->FillRect(rect);
	else
		context->GetDrawingEngine()->StrokeRect(rect);
}
Exemplo n.º 8
0
static void
draw_bezier(void* _context, size_t numPoints, const BPoint viewPoints[],
	bool fill)
{
	DrawingContext* context = reinterpret_cast<DrawingContext *>(_context);

	const size_t kSupportedPoints = 4;
	if (numPoints != kSupportedPoints)
		return;

	BPoint points[kSupportedPoints];
	context->ConvertToScreenForDrawing(points, viewPoints, kSupportedPoints);

	context->GetDrawingEngine()->DrawBezier(points, fill);
}
Exemplo n.º 9
0
static void
draw_pixels(void* _context, const BRect& src, const BRect& _dest, uint32 width,
	uint32 height, size_t bytesPerRow, color_space pixelFormat, uint32 options,
	const void* data, size_t length)
{
	DrawingContext* context = reinterpret_cast<DrawingContext *>(_context);

	UtilityBitmap bitmap(BRect(0, 0, width - 1, height - 1),
		(color_space)pixelFormat, 0, bytesPerRow);

	if (!bitmap.IsValid())
		return;

	memcpy(bitmap.Bits(), data, std::min(height * bytesPerRow, length));

	BRect dest = _dest;
	context->ConvertToScreenForDrawing(&dest);
	context->GetDrawingEngine()->DrawBitmap(&bitmap, src, dest, options);
}
Exemplo n.º 10
0
static void
draw_string(void* _context, const char* string, size_t length, float deltaSpace,
	float deltaNonSpace)
{
	DrawingContext* context = reinterpret_cast<DrawingContext *>(_context);

	// NOTE: the picture data was recorded with a "set pen location"
	// command inserted before the "draw string" command, so we can
	// use PenLocation()
	BPoint location = context->CurrentState()->PenLocation();

	escapement_delta delta = { deltaSpace, deltaNonSpace };
	context->ConvertToScreenForDrawing(&location);
	location = context->GetDrawingEngine()->DrawString(string, length,
		location, &delta);

	context->ConvertFromScreenForDrawing(&location);
	context->CurrentState()->SetPenLocation(location);
	// the DrawingEngine/Painter does not need to be updated, since this
	// effects only the view->screen coord conversion, which is handled
	// by the view only
}
Exemplo n.º 11
0
void
ShapePainter::Draw(BRect frame, bool filled)
{
	// We're going to draw the currently iterated shape.
	// TODO: This can be more efficient by skipping the conversion.
	int32 opCount = fOpStack.size();
	int32 ptCount = fPtStack.size();

	if (opCount > 0 && ptCount > 0) {
		int32 i;
		uint32* opList = new(std::nothrow) uint32[opCount];
		if (opList == NULL)
			return;

		BPoint* ptList = new(std::nothrow) BPoint[ptCount];
		if (ptList == NULL) {
			delete[] opList;
			return;
		}

		for (i = opCount - 1; i >= 0; i--) {
			opList[i] = fOpStack.top();
			fOpStack.pop();
		}

		for (i = ptCount - 1; i >= 0; i--) {
			ptList[i] = fPtStack.top();
			fPtStack.pop();
		}

		BPoint offset(fContext->CurrentState()->PenLocation());
		fContext->ConvertToScreenForDrawing(&offset);
		fContext->GetDrawingEngine()->DrawShape(frame, opCount, opList,
			ptCount, ptList, filled, offset, fContext->Scale());

		delete[] opList;
		delete[] ptList;
	}
}