Example #1
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);
}
Example #2
0
static void
set_drawing_mode(void* _context, drawing_mode mode)
{
	DrawingContext* context = reinterpret_cast<DrawingContext *>(_context);
	context->CurrentState()->SetDrawingMode(mode);
	context->GetDrawingEngine()->SetDrawingMode(mode);
}
Example #3
0
static void
set_back_color(void* _context, const rgb_color& color)
{
	DrawingContext* context = reinterpret_cast<DrawingContext *>(_context);
	context->CurrentState()->SetLowColor(color);
	context->GetDrawingEngine()->SetLowColor(color);
}
Example #4
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);
}
Example #5
0
static void
set_stipple_pattern(void* _context, const pattern& pattern)
{
	DrawingContext* context = reinterpret_cast<DrawingContext *>(_context);
	context->CurrentState()->SetPattern(Pattern(pattern));
	context->GetDrawingEngine()->SetPattern(pattern);
}
Example #6
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);
}
Example #7
0
static void
set_pen_size(void* _context, float size)
{
	DrawingContext* context = reinterpret_cast<DrawingContext *>(_context);
	context->CurrentState()->SetPenSize(size);
	context->GetDrawingEngine()->SetPenSize(
		context->CurrentState()->PenSize());
		// DrawState::PenSize() returns the scaled pen size, so we
		// need to use that value to set the drawing engine pen size.
}
Example #8
0
static void
set_line_mode(void* _context, cap_mode capMode, join_mode joinMode,
	float miterLimit)
{
	DrawingContext* context = reinterpret_cast<DrawingContext *>(_context);
	DrawState* state = context->CurrentState();
	state->SetLineCapMode(capMode);
	state->SetLineJoinMode(joinMode);
	state->SetMiterLimit(miterLimit);
	context->GetDrawingEngine()->SetStrokeMode(capMode, joinMode, miterLimit);
}
Example #9
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);
}
Example #10
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);
}
Example #11
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);
}
Example #12
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);
}
Example #13
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
}
Example #14
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);
}
Example #15
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
}
Example #16
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;
	}
}
Example #17
0
static void
exit_font_state(void* _context)
{
	DrawingContext* context = reinterpret_cast<DrawingContext *>(_context);
	context->GetDrawingEngine()->SetFont(context->CurrentState()->Font());
}