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); }
static void set_drawing_mode(void* _context, drawing_mode mode) { DrawingContext* context = reinterpret_cast<DrawingContext *>(_context); context->CurrentState()->SetDrawingMode(mode); context->GetDrawingEngine()->SetDrawingMode(mode); }
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); }
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); }
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); }
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); }
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. }
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); }
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); }
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); }
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); }
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); }
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 }
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); }
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 }
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; } }
static void exit_font_state(void* _context) { DrawingContext* context = reinterpret_cast<DrawingContext *>(_context); context->GetDrawingEngine()->SetFont(context->CurrentState()->Font()); }