Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TPadPainter.cxx
Go to the documentation of this file.
1// @(#)root/gl:$Id$
2// Author: Olivier Couet, Timur Pocheptsov (vertex merge) 06/05/2009
3
4/*************************************************************************
5 * Copyright (C) 1995-2009, Rene Brun and Fons Rademakers. *
6 * All rights reserved. *
7 * *
8 * For the licensing terms see $ROOTSYS/LICENSE. *
9 * For the list of contributors see $ROOTSYS/README/CREDITS. *
10 *************************************************************************/
11
12#include <algorithm>
13#include <limits>
14#include <memory>
15#include <vector>
16
17#include "TPadPainter.h"
18#include "TVirtualX.h"
19#include "TCanvas.h"
20#include "TPoint.h"
21#include "TError.h"
22#include "TImage.h"
23#include "TROOT.h"
24#include "TMath.h"
25#include "TPad.h"
26
27namespace {
28
29//Typedef is fine, but let's pretend we look cool and modern:
30using size_type = std::vector<TPoint>::size_type;
31
32template<typename T>
33void ConvertPoints(TVirtualPad *pad, unsigned nPoints, const T *xs, const T *ys,
34 std::vector<TPoint> &dst);
35inline
36void MergePointsX(std::vector<TPoint> &points, unsigned nMerged, SCoord_t yMin,
38
39inline
40size_type MergePointsInplaceY(std::vector<TPoint> &dst, size_type nMerged, SCoord_t xMin,
41 SCoord_t xMax, SCoord_t xLast, size_type first);
42
43template<typename T>
44void ConvertPointsAndMergePassX(TVirtualPad *pad, unsigned nPoints, const T *x, const T *y,
45 std::vector<TPoint> &dst);
46
47void ConvertPointsAndMergeInplacePassY(std::vector<TPoint> &dst);
48
49template<class T>
51
52template<typename T>
53void DrawPolyLineAux(TVirtualPad *pad, WinContext_t cont, unsigned nPoints, const T *xs, const T *ys);
54
55template<class T>
56void DrawPolyMarkerAux(TVirtualPad *pad, WinContext_t cont, unsigned nPoints, const T *xs, const T *ys);
57
58
59}
60
61
62/** \class TPadPainter
63\ingroup gpad
64
65Implement TVirtualPadPainter which abstracts painting operations.
66*/
67
68////////////////////////////////////////////////////////////////////////////////
69///Empty ctor. We need it only because of explicit copy ctor.
70
76
77/*
78Line/fill/etc. attributes can be set inside TPad, but not only where:
79many of them are set by base sub-objects of 2d primitives
80(2d primitives usually inherit TAttLine or TAttFill etc.). And these sub-objects
81call gVirtualX->SetLineWidth ... etc. So, if I save some attributes in my painter,
82it will be mess - at any moment I do not know, where to take line attribute - from
83gVirtualX or from my own member. So! All attributed, _ALL_ go to/from gVirtualX.
84*/
85
86
87////////////////////////////////////////////////////////////////////////////////
88/// Delegate to gVirtualX.
89
94
95////////////////////////////////////////////////////////////////////////////////
96/// Delegate to gVirtualX.
97
99{
100 return gVirtualX->GetTextMagnitude();
101}
102
103////////////////////////////////////////////////////////////////////////////////
104/// Create a gVirtualX Pixmap.
105
107{
108 return gVirtualX->OpenPixmap(Int_t(w), Int_t(h));
109}
110
111////////////////////////////////////////////////////////////////////////////////
112/// Resize a gVirtualX Pixmap.
113
115{
116 return gVirtualX->ResizePixmap(device, w, h);
117}
118
119
120////////////////////////////////////////////////////////////////////////////////
121/// Returns true when cocoa backend is used
122
124{
125 return gVirtualX->InheritsFrom("TGCocoa");
126}
127
128////////////////////////////////////////////////////////////////////////////////
129/// Returns true if trasnparent colors are supported
130
132{
133 return gVirtualX->InheritsFrom("TGQuartz");
134}
135
136////////////////////////////////////////////////////////////////////////////////
137/// Clear the current gVirtualX window - calling gVirtualX->ClearWindowW
138
140{
141 if (fWinContext)
142 gVirtualX->ClearWindowW(fWinContext);
143}
144
145////////////////////////////////////////////////////////////////////////////////
146/// Clear specified window - calling gVirtualX->ClearWindowW
147
149{
150 auto ctxt = gVirtualX->GetWindowContext(device);
151 if (ctxt)
152 gVirtualX->ClearWindowW(ctxt);
153}
154
155////////////////////////////////////////////////////////////////////////////////
156/// Copy a gVirtualX pixmap.
157
159{
160 gVirtualX->CopyPixmapW(fWinContext, device, px, py);
161}
162
163////////////////////////////////////////////////////////////////////////////////
164/// Close the current gVirtualX pixmap.
165
167{
168 gVirtualX->SelectWindow(device);
169 gVirtualX->ClosePixmap();
171}
172
173////////////////////////////////////////////////////////////////////////////////
174/// Select the window in which the graphics will go.
175
177{
178 gVirtualX->SelectWindow(device);
179 fWinContext = gVirtualX->GetWindowContext(device);
180}
181
182////////////////////////////////////////////////////////////////////////////////
183/// Call low-level update of selected drawable, redirect to gVirtualX.
184
186{
187 gVirtualX->UpdateWindowW(fWinContext, mode);
188}
189
190////////////////////////////////////////////////////////////////////////////////
191/// Set drawing mode for specified device
192
194{
195 gVirtualX->SetDrawModeW(gVirtualX->GetWindowContext(device), (TVirtualX::EDrawMode) mode);
196}
197
198////////////////////////////////////////////////////////////////////////////////
199/// Set double buffer mode for specified device
200
202{
203 // important flag - when disabled canvas pixmap used directly
204 // so one need to use absolute coordinates
206
207 gVirtualX->SetDoubleBuffer(device, mode);
208}
209
210////////////////////////////////////////////////////////////////////////////////
211///Noop, for non-gl pad TASImage calls gVirtualX->CopyArea.
212
213void TPadPainter::DrawPixels(const unsigned char * /*pixelData*/, UInt_t /*width*/, UInt_t /*height*/,
214 Int_t /*dstX*/, Int_t /*dstY*/, Bool_t /*enableAlphaBlending*/)
215{
216}
217
218////////////////////////////////////////////////////////////////////////////////
219/// Set fill attributes
220
222{
224
226
227 gVirtualX->SetAttFill(fWinContext, fill);
228}
229
230////////////////////////////////////////////////////////////////////////////////
231/// Set line attributes
232
239
240////////////////////////////////////////////////////////////////////////////////
241/// Set marker attributes
242
249
250////////////////////////////////////////////////////////////////////////////////
251/// Set text attributes
252
259
260////////////////////////////////////////////////////////////////////////////////
261/// Paint a simple line.
262
264{
265 if (fAttLine.GetLineWidth() <= 0)
266 return;
267
268 const Int_t px1 = fDoubleBuffer ? gPad->XtoPixel(x1) : gPad->XtoAbsPixel(x1);
269 const Int_t px2 = fDoubleBuffer ? gPad->XtoPixel(x2) : gPad->XtoAbsPixel(x2);
270 const Int_t py1 = fDoubleBuffer ? gPad->YtoPixel(y1) : gPad->YtoAbsPixel(y1);
271 const Int_t py2 = fDoubleBuffer ? gPad->YtoPixel(y2) : gPad->YtoAbsPixel(y2);
272 gVirtualX->DrawLineW(fWinContext, px1, py1, px2, py2);
273}
274
275
276////////////////////////////////////////////////////////////////////////////////
277/// Paint a simple line in normalized coordinates.
278
280{
281 if (fAttLine.GetLineWidth() <= 0)
282 return;
283
284 const Int_t px1 = fDoubleBuffer ? gPad->UtoPixel(u1) : gPad->UtoAbsPixel(u1);
285 const Int_t py1 = fDoubleBuffer ? gPad->VtoPixel(v1) : gPad->VtoAbsPixel(v1);
286 const Int_t px2 = fDoubleBuffer ? gPad->UtoPixel(u2) : gPad->UtoAbsPixel(u2);
287 const Int_t py2 = fDoubleBuffer ? gPad->VtoPixel(v2) : gPad->VtoAbsPixel(v2);
288 gVirtualX->DrawLineW(fWinContext, px1, py1, px2, py2);
289}
290
291
292////////////////////////////////////////////////////////////////////////////////
293/// Paint a simple box.
294
296{
298 return;
299
301 return;
302
303 Int_t px1 = fDoubleBuffer ? gPad->XtoPixel(x1) : gPad->XtoAbsPixel(x1);
304 Int_t px2 = fDoubleBuffer ? gPad->XtoPixel(x2) : gPad->XtoAbsPixel(x2);
305 Int_t py1 = fDoubleBuffer ? gPad->YtoPixel(y1) : gPad->YtoAbsPixel(y1);
306 Int_t py2 = fDoubleBuffer ? gPad->YtoPixel(y2) : gPad->YtoAbsPixel(y2);
307
308 // Box width must be at least one pixel (WTF is this code???)
309 if (TMath::Abs(px2 - px1) < 1)
310 px2 = px1 + 1;
311 if (TMath::Abs(py1 - py2) < 1)
312 py1 = py2 + 1;
313
314 gVirtualX->DrawBoxW(fWinContext, px1, py1, px2, py2, (TVirtualX::EBoxMode)mode);
315}
316
317////////////////////////////////////////////////////////////////////////////////
318/// Paint filled area.
319
321{
322 if (nPoints < 3) {
323 ::Error("TPadPainter::DrawFillArea", "invalid number of points %d", nPoints);
324 return;
325 }
326
327 // if fully transparent, add first point to draw line
329}
330
331
332////////////////////////////////////////////////////////////////////////////////
333/// Paint filled area.
334
336{
337 if (nPoints < 3) {
338 ::Error("TPadPainter::DrawFillArea", "invalid number of points %d", nPoints);
339 return;
340 }
341
342 // if fully transparent, add first point to draw line
344}
345
346////////////////////////////////////////////////////////////////////////////////
347/// Paint Polyline.
348
350{
351 if (fAttLine.GetLineWidth() <= 0)
352 return;
353
354 if (n < 2) {
355 ::Error("TPadPainter::DrawPolyLine", "invalid number of points");
356 return;
357 }
358
360}
361
362
363////////////////////////////////////////////////////////////////////////////////
364/// Paint polyline.
365
367{
368 if (fAttLine.GetLineWidth() <= 0)
369 return;
370
371 if (n < 2) {
372 ::Error("TPadPainter::DrawPolyLine", "invalid number of points");
373 return;
374 }
375
377}
378
379
380////////////////////////////////////////////////////////////////////////////////
381/// Paint polyline in normalized coordinates.
382
384{
385 if (fAttLine.GetLineWidth() <= 0)
386 return;
387
388 if (n < 2) {
389 ::Error("TPadPainter::DrawPolyLineNDC", "invalid number of points %d", n);
390 return;
391 }
392
393 std::vector<TPoint> xy(n);
394
395 for (Int_t i = 0; i < n; ++i) {
396 xy[i].fX = (SCoord_t)gPad->UtoPixel(u[i]);
397 xy[i].fY = (SCoord_t)gPad->VtoPixel(v[i]);
398 }
399
400 gVirtualX->DrawPolyLineW(fWinContext, n, &xy[0]);
401}
402
403////////////////////////////////////////////////////////////////////////////////
404/// Paint N segments on the pad
405
407{
408 if (fAttLine.GetLineWidth() <= 0)
409 return;
410
411 if (n < 1) {
412 ::Error("TPadPainter::DrawSegments", "invalid number of segments %d", n);
413 return;
414 }
415
416 std::vector<TPoint> xy(n*2);
417 Int_t cnt = 0;
418 for (Int_t i = 0; i < n*2; ++i) {
419 if ((i % 2 == 0) && (x[i] == x[i+1]) && (y[i] == y[i+1])) {
420 // exclude empty segment
421 i++;
422 continue;
423 }
424
425 xy[cnt].fX = (SCoord_t)gPad->XtoPixel(x[i]);
426 xy[cnt].fY = (SCoord_t)gPad->YtoPixel(y[i]);
427 cnt++;
428 }
429
430 if (cnt > 1)
431 gVirtualX->DrawLinesSegmentsW(fWinContext, cnt/2, &xy[0]);
432}
433
434////////////////////////////////////////////////////////////////////////////////
435/// Paint N segments in normalized coordinates on the pad
436
438{
439 if (fAttLine.GetLineWidth() <= 0)
440 return;
441
442 if (n < 1) {
443 ::Error("TPadPainter::DrawSegmentsNDC", "invalid number of segments %d", n);
444 return;
445 }
446
447 std::vector<TPoint> xy(n*2);
448 Int_t cnt = 0;
449 for (Int_t i = 0; i < n*2; ++i) {
450 if ((i % 2 == 0) && (u[i] == u[i+1]) && (v[i] == v[i+1])) {
451 // exclude empty segment
452 i++;
453 continue;
454 }
455
456 xy[cnt].fX = (SCoord_t)gPad->UtoPixel(u[i]);
457 xy[cnt].fY = (SCoord_t)gPad->VtoPixel(v[i]);
458 cnt++;
459 }
460
461 if (cnt > 1)
462 gVirtualX->DrawLinesSegmentsW(fWinContext, cnt/2, &xy[0]);
463}
464
465
466
467////////////////////////////////////////////////////////////////////////////////
468/// Paint polymarker.
469
471{
472 if (n < 1) {
473 ::Error("TPadPainter::DrawPolyMarker", "invalid number of points %d", n);
474 return;
475 }
476
478}
479
480
481////////////////////////////////////////////////////////////////////////////////
482/// Paint polymarker.
483
485{
486 if (n < 1) {
487 ::Error("TPadPainter::DrawPolyMarker", "invalid number of points %d", n);
488 return;
489 }
490
492}
493
494
495////////////////////////////////////////////////////////////////////////////////
496/// Paint text.
497
499{
500 const Int_t px = gPad->XtoPixel(x);
501 const Int_t py = gPad->YtoPixel(y);
502 const Double_t angle = GetTextAngle();
503 const Double_t mgn = GetTextMagnitude();
505}
506
507
508////////////////////////////////////////////////////////////////////////////////
509/// Special version working with wchar_t and required by TMathText.
510
512{
513 const Int_t px = gPad->XtoPixel(x);
514 const Int_t py = gPad->YtoPixel(y);
515 const Double_t angle = GetTextAngle();
516 const Double_t mgn = GetTextMagnitude();
518}
519
520
521////////////////////////////////////////////////////////////////////////////////
522/// Paint text in normalized coordinates.
523
525{
526 const Int_t px = gPad->UtoPixel(u);
527 const Int_t py = gPad->VtoPixel(v);
528 const Double_t angle = GetTextAngle();
529 const Double_t mgn = GetTextMagnitude();
531}
532
533
534////////////////////////////////////////////////////////////////////////////////
535/// Save the image displayed in the canvas pointed by "pad" into a binary file.
536
537void TPadPainter::SaveImage(TVirtualPad *pad, const char *fileName, Int_t type) const
538{
539 if (gVirtualX->InheritsFrom("TGCocoa") && !gROOT->IsBatch() &&
540 pad->GetCanvas() && pad->GetCanvas()->GetCanvasID() != -1) {
541
542 TCanvas * const canvas = pad->GetCanvas();
543 //Force TCanvas::CopyPixmaps.
544 canvas->Flush();
545
546 const UInt_t w = canvas->GetWw();
547 const UInt_t h = canvas->GetWh();
548
549 const std::unique_ptr<unsigned char[]>
550 pixelData(gVirtualX->GetColorBits(canvas->GetCanvasID(), 0, 0, w, h));
551
552 if (pixelData.get()) {
553 const std::unique_ptr<TImage> image(TImage::Create());
554 if (image.get()) {
555 image->DrawRectangle(0, 0, w, h);
556 if (unsigned char *argb = (unsigned char *)image->GetArgbArray()) {
557 //Ohhh.
558 if (sizeof(UInt_t) == 4) {
559 //For sure the data returned from TGCocoa::GetColorBits,
560 //it's 4 * w * h bytes with what TASImage considers to be argb.
561 std::copy(pixelData.get(), pixelData.get() + 4 * w * h, argb);
562 } else {
563 //A bit paranoid, don't you think so?
564 //Will Quartz/TASImage work at all on such a fancy platform? ;)
565 const unsigned shift = std::numeric_limits<unsigned char>::digits;
566 //
567 unsigned *dstPixel = (unsigned *)argb, *end = dstPixel + w * h;
568 const unsigned char *srcPixel = pixelData.get();
569 for (;dstPixel != end; ++dstPixel, srcPixel += 4) {
570 //Looks fishy but should work, trust me :)
571 *dstPixel = srcPixel[0] & (srcPixel[1] << shift) &
572 (srcPixel[2] << 2 * shift) &
573 (srcPixel[3] << 3 * shift);
574 }
575 }
576
577 image->WriteImage(fileName, (TImage::EImageFileTypes)type);
578 //Success.
579 return;
580 }
581 }
582 }
583 }
584
585 if (type == TImage::kGif) {
586 gVirtualX->WriteGIF((char*)fileName);
587 } else {
588 const std::unique_ptr<TImage> img(TImage::Create());
589 if (img.get()) {
590 img->FromPad(pad);
591 img->WriteImage(fileName, (TImage::EImageFileTypes)type);
592 }
593 }
594}
595
596
597////////////////////////////////////////////////////////////////////////////////
598/// Paint text in normalized coordinates.
599
601{
602 const Int_t px = gPad->UtoPixel(u);
603 const Int_t py = gPad->VtoPixel(v);
604 const Double_t angle = GetTextAngle();
605 const Double_t mgn = GetTextMagnitude();
607}
608
609//Aux. private functions.
610namespace {
611
612////////////////////////////////////////////////////////////////////////////////
613///I'm using 'pad' pointer to get rid of this damned gPad.
614///Unfortunately, TPadPainter itself still has to use it.
615///But at least this code does not have to be fixed.
616
617template<typename T>
618void ConvertPoints(TVirtualPad *pad, unsigned nPoints, const T *x, const T *y,
619 std::vector<TPoint> &dst)
620{
621 if (!nPoints)
622 return;
623
624 dst.resize(nPoints);
625
626 for (unsigned i = 0; i < nPoints; ++i) {
627 dst[i].fX = (SCoord_t)pad->XtoPixel(x[i]);
628 dst[i].fY = (SCoord_t)pad->YtoPixel(y[i]);
629 }
630}
631
632////////////////////////////////////////////////////////////////////////////////
633
634inline void MergePointsX(std::vector<TPoint> &points, unsigned nMerged, SCoord_t yMin,
636{
637 const auto firstPointX = points.back().fX;
638 const auto firstPointY = points.back().fY;
639
640 if (nMerged == 2) {
641 points.push_back(TPoint(firstPointX, yLast));//We have not merge anything.
642 } else if (nMerged == 3) {
643 yMin == firstPointY ? points.push_back(TPoint(firstPointX, yMax)) :
644 points.push_back(TPoint(firstPointX, yMin));
645 points.push_back(TPoint(firstPointX, yLast));
646 } else {
647 points.push_back(TPoint(firstPointX, yMin));
648 points.push_back(TPoint(firstPointX, yMax));
649 points.push_back(TPoint(firstPointX, yLast));
650 }
651}
652
653////////////////////////////////////////////////////////////////////////////////
654///Indices below are _valid_.
655
656inline size_type MergePointsInplaceY(std::vector<TPoint> &dst, size_type nMerged, SCoord_t xMin,
657 SCoord_t xMax, SCoord_t xLast, size_type first)
658{
659 const TPoint &firstPoint = dst[first];//This point is never updated.
660
661 if (nMerged == 2) {
662 dst[first + 1].fX = xLast;
663 dst[first + 1].fY = firstPoint.fY;
664 } else if (nMerged == 3) {
665 dst[first + 1].fX = xMin == firstPoint.fX ? xMax : xMin;
666 dst[first + 1].fY = firstPoint.fY;
667 dst[first + 2].fX = xLast;
668 dst[first + 2].fY = firstPoint.fY;
669 } else {
670 dst[first + 1].fX = xMin;
671 dst[first + 1].fY = firstPoint.fY;
672 dst[first + 2].fX = xMax;
673 dst[first + 2].fY = firstPoint.fY;
674 dst[first + 3].fX = xLast;
675 dst[first + 3].fY = firstPoint.fY;
676 nMerged = 4;//Adjust the shift.
677 }
678
679 return nMerged;
680}
681
682////////////////////////////////////////////////////////////////////////////////
683/// I'm using 'pad' pointer to get rid of this damned gPad.
684/// Unfortunately, TPadPainter itself still has to use it.
685/// But at least this code does not have to be fixed.
686
687template<typename T>
688void ConvertPointsAndMergePassX(TVirtualPad *pad, unsigned nPoints, const T *x, const T *y,
689 std::vector<TPoint> &dst)
690{
691 //The "first" pass along X axis.
693 SCoord_t yMin = 0, yMax = 0, yLast = 0;
694 unsigned nMerged = 0;
695
696 //The first pass along X.
697 for (unsigned i = 0; i < nPoints;) {
698 currentPoint.fX = (SCoord_t)pad->XtoPixel(x[i]);
699 currentPoint.fY = (SCoord_t)pad->YtoPixel(y[i]);
700
701 yMin = currentPoint.fY;
702 yMax = yMin;
703
704 dst.push_back(currentPoint);
705 bool merged = false;
706 nMerged = 1;
707
708 for (unsigned j = i + 1; j < nPoints; ++j) {
709 const SCoord_t newX = pad->XtoPixel(x[j]);
710
711 if (newX == currentPoint.fX) {
712 yLast = pad->YtoPixel(y[j]);
714 yMax = TMath::Max(yMax, yLast);//We continue.
715 ++nMerged;
716 } else {
717 if (nMerged > 1)
719 merged = true;
720 break;
721 }
722 }
723
724 if (!merged && nMerged > 1)
726
727 i += nMerged;
728 }
729}
730
731////////////////////////////////////////////////////////////////////////////////
732/// This pass is a bit more complicated, since we have to 'compact' in-place.
733
734void ConvertPointsAndMergeInplacePassY(std::vector<TPoint> &dst)
735{
736 size_type i = 0;
737 for (size_type j = 1, nPoints = dst.size(); i < nPoints;) {
738 //i is always less than j, so i is always valid here.
739 const TPoint &currentPoint = dst[i];
740
743 SCoord_t xLast = 0;
744
745 bool merged = false;
746 size_type nMerged = 1;
747
748 for (; j < nPoints; ++j) {
749 const TPoint &nextPoint = dst[j];
750
751 if (nextPoint.fY == currentPoint.fY) {
752 xLast = nextPoint.fX;
755 ++nMerged;//and we continue ...
756 } else {
757 if (nMerged > 1)
759 merged = true;
760 break;
761 }
762 }
763
764 if (!merged && nMerged > 1)
766
767 i += nMerged;
768
769 if (j < nPoints) {
770 dst[i] = dst[j];
771 ++j;
772 } else
773 break;
774 }
775
776 dst.resize(i);
777}
778
779////////////////////////////////////////////////////////////////////////////////
780/// This is a quite simple algorithm, using the fact, that after conversion many
781/// subsequent vertices can have the same 'x' or 'y' coordinate and this part of
782/// a polygon will look like a line on the screen.
783
784template<typename T>
785void ConvertPointsAndMerge(TVirtualPad *pad, unsigned threshold, unsigned nPoints, const T *x,
786 const T *y, std::vector<TPoint> &dst)
787{
788 //I'm using 'pad' pointer to get rid of this damned gPad.
789 //Unfortunately, TPadPainter itself still has to use it.
790 //But at least this code does not have to be fixed.
791
792 if (!nPoints)
793 return;
794
795 dst.clear();
796 dst.reserve(threshold);
797
799
800 if (dst.size() < threshold)
801 return;
802
804}
805
806////////////////////////////////////////////////////////////////////////////////
807
808template<class T>
810{
811 std::vector<TPoint> xy;
812
813 const Int_t threshold = Int_t(TMath::Min(pad->GetWw() * pad->GetAbsWNDC(),
814 pad->GetWh() * pad->GetAbsHNDC())) * 2;
815
816 if (threshold <= 0) {
817 //Ooops, pad is invisible or something really bad and stupid happened.
818 ::Error("DrawFillAreaAux", "invalid pad's geometry");
819 return;
820 }
821
822 if (nPoints < threshold)
824 else
826
827 //We close the 'polygon' so it can be rendered as a polyline by gVirtualX.
828 if (add_first_point)
829 xy.push_back(xy.front());
830
831 if (xy.size() > 2)
832 gVirtualX->DrawFillAreaW(cont, xy.size(), xy.data());
833}
834
835////////////////////////////////////////////////////////////////////////////////
836
837template<typename T>
838void DrawPolyLineAux(TVirtualPad *pad, WinContext_t cont, unsigned nPoints, const T *xs, const T *ys)
839{
840 std::vector<TPoint> xy;
841
842 const Int_t threshold = Int_t(TMath::Min(pad->GetWw() * pad->GetAbsWNDC(),
843 pad->GetWh() * pad->GetAbsHNDC())) * 2;
844
845 if (threshold <= 0) {//Ooops, pad is invisible or something really bad and stupid happened.
846 ::Error("DrawPolyLineAux", "invalid pad's geometry");
847 return;
848 }
849
850 if (nPoints < (unsigned)threshold)
852 else
854
855 if (xy.size() > 1)
856 gVirtualX->DrawPolyLineW(cont, xy.size(), &xy[0]);
857
858}
859
860////////////////////////////////////////////////////////////////////////////////
861
862template<class T>
863void DrawPolyMarkerAux(TVirtualPad *pad, WinContext_t cont, unsigned nPoints, const T *xs, const T *ys)
864{
865 std::vector<TPoint> xy(nPoints);
866
867 for (unsigned i = 0; i < nPoints; ++i) {
868 xy[i].fX = (SCoord_t)pad->XtoPixel(xs[i]);
869 xy[i].fY = (SCoord_t)pad->YtoPixel(ys[i]);
870 }
871
872 gVirtualX->DrawPolyMarkerW(cont, nPoints, &xy[0]);
873}
874
875}
Handle_t WinContext_t
Window drawing context.
Definition GuiTypes.h:30
#define h(i)
Definition RSha256.hxx:106
bool Bool_t
Boolean (0=false, 1=true) (bool)
Definition RtypesCore.h:77
int Int_t
Signed integer 4 bytes (int)
Definition RtypesCore.h:59
short SCoord_t
Screen coordinates (short)
Definition RtypesCore.h:100
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
void Error(const char *location, const char *msgfmt,...)
Use this function in case an error occurred.
Definition TError.cxx:208
Option_t Option_t mgn
Option_t Option_t TPoint TPoint const char x2
Option_t Option_t TPoint TPoint const char x1
Option_t Option_t TPoint TPoint angle
Option_t Option_t TPoint xy
Option_t Option_t TPoint TPoint const char mode
Option_t Option_t TPoint TPoint const char y2
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t points
Option_t Option_t TPoint TPoint percent
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t type
Option_t Option_t TPoint TPoint const char text
Option_t Option_t TPoint TPoint const char y1
#define gROOT
Definition TROOT.h:426
#define gPad
#define gVirtualX
Definition TVirtualX.h:367
Fill Area Attributes class.
Definition TAttFill.h:21
Line Attributes class.
Definition TAttLine.h:21
virtual Width_t GetLineWidth() const
Return the line width.
Definition TAttLine.h:38
Marker Attributes class.
Definition TAttMarker.h:21
Text Attributes class.
Definition TAttText.h:21
The Canvas class.
Definition TCanvas.h:23
Int_t GetCanvasID() const override
Definition TCanvas.h:161
UInt_t GetWw() const override
Definition TCanvas.h:167
UInt_t GetWh() const override
Definition TCanvas.h:168
void Flush()
Flush canvas buffers.
Definition TCanvas.cxx:1141
EImageFileTypes
Definition TImage.h:36
@ kGif
Definition TImage.h:48
static TImage * Create()
Create an image.
Definition TImage.cxx:34
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 fDoubleBuffer
Definition TPadPainter.h:27
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.
WinContext_t fWinContext
Definition TPadPainter.h:26
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.
SCoord_t fY
Definition TPoint.h:36
SCoord_t fX
Definition TPoint.h:35
TVirtualPad is an abstract base class for the Pad and Canvas classes.
Definition TVirtualPad.h:51
Double_t y[n]
Definition legend1.C:17
Double_t x[n]
Definition legend1.C:17
const Int_t n
Definition legend1.C:16
Short_t Max(Short_t a, Short_t b)
Returns the largest of a and b.
Definition TMathBase.h:249
Short_t Min(Short_t a, Short_t b)
Returns the smallest of a and b.
Definition TMathBase.h:197
Short_t Abs(Short_t d)
Returns the absolute value of parameter Short_t d.
Definition TMathBase.h:122