30using size_type = std::vector<TPoint>::size_type;
33void ConvertPoints(
TVirtualPad *pad,
unsigned nPoints,
const T *xs,
const T *ys,
34 std::vector<TPoint> &dst);
36void MergePointsX(std::vector<TPoint> &
points,
unsigned nMerged,
SCoord_t yMin,
40size_type MergePointsInplaceY(std::vector<TPoint> &dst, size_type nMerged,
SCoord_t xMin,
44void ConvertPointsAndMergePassX(
TVirtualPad *pad,
unsigned nPoints,
const T *
x,
const T *
y,
45 std::vector<TPoint> &dst);
47void ConvertPointsAndMergeInplacePassY(std::vector<TPoint> &dst);
125 return gVirtualX->InheritsFrom(
"TGCocoa");
133 return gVirtualX->InheritsFrom(
"TGQuartz");
150 auto ctxt =
gVirtualX->GetWindowContext(device);
207 gVirtualX->SetDoubleBuffer(device, mode);
261 Fatal(
"SetAttText",
"Pad not specified");
332 ::Error(
"TPadPainter::DrawFillArea",
"invalid number of points %d", nPoints);
347 ::Error(
"TPadPainter::DrawFillArea",
"invalid number of points %d", nPoints);
364 ::Error(
"TPadPainter::DrawPolyLine",
"invalid number of points");
381 ::Error(
"TPadPainter::DrawPolyLine",
"invalid number of points");
398 ::Error(
"TPadPainter::DrawPolyLineNDC",
"invalid number of points %d",
n);
402 std::vector<TPoint> xy(
n);
404 for (
Int_t i = 0; i <
n; ++i) {
421 ::Error(
"TPadPainter::DrawSegments",
"invalid number of segments %d",
n);
425 std::vector<TPoint> xy(
n*2);
427 for (
Int_t i = 0; i <
n*2; ++i) {
428 if ((i % 2 == 0) && (
x[i] ==
x[i+1]) && (
y[i] ==
y[i+1])) {
452 ::Error(
"TPadPainter::DrawSegmentsNDC",
"invalid number of segments %d",
n);
456 std::vector<TPoint> xy(
n*2);
458 for (
Int_t i = 0; i <
n*2; ++i) {
459 if ((i % 2 == 0) && (u[i] == u[i+1]) && (
v[i] ==
v[i+1])) {
482 ::Error(
"TPadPainter::DrawPolyMarker",
"invalid number of points %d",
n);
496 ::Error(
"TPadPainter::DrawPolyMarker",
"invalid number of points %d",
n);
558 const std::unique_ptr<unsigned char[]>
561 if (pixelData.get()) {
564 image->DrawRectangle(0, 0, w,
h);
565 if (
unsigned char *argb = (
unsigned char *)image->GetArgbArray()) {
567 if (
sizeof(
UInt_t) == 4) {
570 std::copy(pixelData.get(), pixelData.get() + 4 * w *
h, argb);
574 const unsigned shift = std::numeric_limits<unsigned char>::digits;
576 unsigned *dstPixel = (
unsigned *)argb, *end = dstPixel + w *
h;
577 const unsigned char *srcPixel = pixelData.get();
578 for (;dstPixel != end; ++dstPixel, srcPixel += 4) {
580 *dstPixel = srcPixel[0] & (srcPixel[1] << shift) &
581 (srcPixel[2] << 2 * shift) &
582 (srcPixel[3] << 3 * shift);
596 auto ctxt =
gVirtualX->GetWindowContext(wid);
630void ConvertPoints(
TVirtualPad *pad,
unsigned nPoints,
const T *
x,
const T *
y,
631 std::vector<TPoint> &dst)
638 for (
unsigned i = 0; i < nPoints; ++i) {
646inline void MergePointsX(std::vector<TPoint> &
points,
unsigned nMerged,
SCoord_t yMin,
649 const auto firstPointX =
points.back().fX;
650 const auto firstPointY =
points.back().fY;
654 }
else if (nMerged == 3) {
655 yMin == firstPointY ?
points.push_back(
TPoint(firstPointX, yMax)) :
668inline size_type MergePointsInplaceY(std::vector<TPoint> &dst, size_type nMerged,
SCoord_t xMin,
671 const TPoint &firstPoint = dst[first];
674 dst[first + 1].fX = xLast;
675 dst[first + 1].fY = firstPoint.
fY;
676 }
else if (nMerged == 3) {
677 dst[first + 1].fX = xMin == firstPoint.
fX ? xMax : xMin;
678 dst[first + 1].fY = firstPoint.
fY;
679 dst[first + 2].fX = xLast;
680 dst[first + 2].fY = firstPoint.
fY;
682 dst[first + 1].fX = xMin;
683 dst[first + 1].fY = firstPoint.
fY;
684 dst[first + 2].fX = xMax;
685 dst[first + 2].fY = firstPoint.
fY;
686 dst[first + 3].fX = xLast;
687 dst[first + 3].fY = firstPoint.
fY;
700void ConvertPointsAndMergePassX(
TVirtualPad *pad,
unsigned nPoints,
const T *
x,
const T *
y,
701 std::vector<TPoint> &dst)
705 SCoord_t yMin = 0, yMax = 0, yLast = 0;
706 unsigned nMerged = 0;
709 for (
unsigned i = 0; i < nPoints;) {
713 yMin = currentPoint.
fY;
716 dst.push_back(currentPoint);
720 for (
unsigned j = i + 1; j < nPoints; ++j) {
723 if (newX == currentPoint.
fX) {
730 MergePointsX(dst, nMerged, yMin, yMax, yLast);
736 if (!merged && nMerged > 1)
737 MergePointsX(dst, nMerged, yMin, yMax, yLast);
746void ConvertPointsAndMergeInplacePassY(std::vector<TPoint> &dst)
749 for (size_type j = 1, nPoints = dst.size(); i < nPoints;) {
751 const TPoint ¤tPoint = dst[i];
758 size_type nMerged = 1;
760 for (; j < nPoints; ++j) {
761 const TPoint &nextPoint = dst[j];
763 if (nextPoint.
fY == currentPoint.
fY) {
764 xLast = nextPoint.
fX;
770 nMerged = MergePointsInplaceY(dst, nMerged, xMin, xMax, xLast, i);
776 if (!merged && nMerged > 1)
777 nMerged = MergePointsInplaceY(dst, nMerged, xMin, xMax, xLast, i);
797void ConvertPointsAndMerge(
TVirtualPad *pad,
unsigned threshold,
unsigned nPoints,
const T *
x,
798 const T *
y, std::vector<TPoint> &dst)
808 dst.reserve(threshold);
810 ConvertPointsAndMergePassX(pad, nPoints,
x,
y, dst);
812 if (dst.size() < threshold)
815 ConvertPointsAndMergeInplacePassY(dst);
823 std::vector<TPoint> xy;
828 if (threshold <= 0) {
830 ::Error(
"DrawFillAreaAux",
"invalid pad's geometry");
834 if (nPoints < threshold)
835 ConvertPoints(pad, nPoints, xs, ys, xy);
837 ConvertPointsAndMerge(pad, threshold, nPoints, xs, ys, xy);
841 xy.push_back(xy.front());
844 gVirtualX->DrawFillAreaW(cont, xy.size(), xy.data());
852 std::vector<TPoint> xy;
857 if (threshold <= 0) {
858 ::Error(
"DrawPolyLineAux",
"invalid pad's geometry");
862 if (nPoints < (
unsigned)threshold)
863 ConvertPoints(pad, nPoints, xs, ys, xy);
865 ConvertPointsAndMerge(pad, threshold, nPoints, xs, ys, xy);
868 gVirtualX->DrawPolyLineW(cont, xy.size(), &xy[0]);
877 std::vector<TPoint> xy(nPoints);
879 for (
unsigned i = 0; i < nPoints; ++i) {
884 gVirtualX->DrawPolyMarkerW(cont, nPoints, &xy[0]);
Handle_t WinContext_t
Window drawing context.
int Int_t
Signed integer 4 bytes (int).
unsigned int UInt_t
Unsigned integer 4 bytes (unsigned int).
bool Bool_t
Boolean (0=false, 1=true) (bool).
double Double_t
Double 8 bytes.
short SCoord_t
Screen coordinates (short).
float Float_t
Float 4 bytes (float).
Error("WriteTObject","The current directory (%s) is not associated with a file. The object (%s) has not been written.", GetName(), objname)
void Fatal(const char *location, const char *msgfmt,...)
Use this function in case of a fatal error. It will abort the program.
virtual Float_t GetTextSizePixels(TVirtualPad &pad) const
Return the text size in pixels for specified pad.
virtual void SetTextSize(Float_t tsize=1)
Set the text size.
Int_t GetCanvasID() const override
UInt_t GetWw() const override
UInt_t GetWh() const override
void Flush()
Flush canvas buffers.
static TImage * Create()
Create an image.
void SetAttFill(const TAttFill &att) override
Set fill attributes.
void SetAttText(const TAttText &att) override
Set text attributes.
TAttLine fAttLine
current line attributes
Bool_t fFullyTransparent
if transformed fill attributes fully transparent
void SetAttMarker(const TAttMarker &att) override
Set marker attributes.
void SetAttLine(const TAttLine &att) override
Set line attributes.
Float_t GetTextAngle() const override
TAttFill GetAttFillInternal(Bool_t with_transparency)
Returns fill attributes after modification Checks for special fill styles 4000 .
void DrawSegments(Int_t n, Double_t *x, Double_t *y) override
Paint N segments on the pad.
TPadPainter()
Empty ctor. We need it only because of explicit copy ctor.
void DrawFillArea(Int_t n, const Double_t *x, const Double_t *y) override
Paint filled area.
void SetAttText(const TAttText &att) override
Set text attributes.
void DrawPixels(const unsigned char *pixelData, UInt_t width, UInt_t height, Int_t dstX, Int_t dstY, Bool_t enableAlphaBlending) override
Noop, for non-gl pad TASImage calls gVirtualX->CopyArea.
void UpdateDrawable(Int_t mode) override
Call low-level update of selected drawable, redirect to gVirtualX.
void CopyDrawable(Int_t device, Int_t px, Int_t py) override
Copy a gVirtualX pixmap.
void SetAttMarker(const TAttMarker &att) override
Set marker attributes.
void DrawPolyLine(Int_t n, const Double_t *x, const Double_t *y) override
Paint Polyline.
Int_t ResizeDrawable(Int_t device, UInt_t w, UInt_t h) override
Resize a gVirtualX Pixmap.
Float_t GetTextMagnitude() const override
Delegate to gVirtualX.
Bool_t IsSupportAlpha() const override
Returns true if trasnparent colors are supported.
void ClearWindow(Int_t device) override
Clear specified window - calling gVirtualX->ClearWindowW.
Int_t CreateDrawable(UInt_t w, UInt_t h) override
Create a gVirtualX Pixmap.
void SetAttFill(const TAttFill &att) override
Set fill attributes.
void DrawPolyMarker(Int_t n, const Double_t *x, const Double_t *y) override
Paint polymarker.
void SetOpacity(Int_t percent) override
Delegate to gVirtualX.
void DrawTextNDC(Double_t u, Double_t v, const char *text, ETextMode mode) override
Paint text in normalized coordinates.
Bool_t IsCocoa() const override
Returns true when cocoa backend is used.
void SaveImage(TVirtualPad *pad, const char *fileName, Int_t type) const override
Save the image displayed in the canvas pointed by "pad" into a binary file.
void DrawPolyLineNDC(Int_t n, const Double_t *u, const Double_t *v) override
Paint polyline in normalized coordinates.
void SetDrawMode(Int_t device, Int_t mode) override
Set drawing mode for specified device.
void ClearDrawable() override
Clear the current gVirtualX window - calling gVirtualX->ClearWindowW.
void DestroyDrawable(Int_t device) override
Close the current gVirtualX pixmap.
void DrawSegmentsNDC(Int_t n, Double_t *u, Double_t *v) override
Paint N segments in normalized coordinates on the pad.
void SetAttLine(const TAttLine &att) override
Set line attributes.
void SelectDrawable(Int_t device) override
Select the window in which the graphics will go.
void DrawBox(Double_t x1, Double_t y1, Double_t x2, Double_t y2, EBoxMode mode) override
Paint a simple box.
void DrawLine(Double_t x1, Double_t y1, Double_t x2, Double_t y2) override
Paint a simple line.
void DrawLineNDC(Double_t u1, Double_t v1, Double_t u2, Double_t v2) override
Paint a simple line in normalized coordinates.
void DrawText(Double_t x, Double_t y, const char *text, ETextMode mode) override
Paint text.
void SetDoubleBuffer(Int_t device, Int_t mode) override
Set double buffer mode for specified device.
TVirtualPad is an abstract base class for the Pad and Canvas classes.
virtual Int_t YtoAbsPixel(Double_t y) const =0
virtual Int_t YtoPixel(Double_t y) const =0
virtual UInt_t GetWh() const =0
virtual Int_t XtoAbsPixel(Double_t x) const =0
virtual Int_t GetPixmapID() const =0
virtual Double_t GetAbsWNDC() const =0
virtual Double_t GetAbsHNDC() const =0
virtual Int_t XtoPixel(Double_t x) const =0
virtual UInt_t GetWw() const =0
virtual Int_t GetCanvasID() const =0
virtual TCanvas * GetCanvas() const =0
Short_t Max(Short_t a, Short_t b)
Returns the largest of a and b.
Short_t Min(Short_t a, Short_t b)
Returns the smallest of a and b.
Short_t Abs(Short_t d)
Returns the absolute value of parameter Short_t d.