Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TPadPainterPS.cxx
Go to the documentation of this file.
1// @(#)root/gl:$Id$
2// Author: Sergey Linev 04/03/2026
3
4/*************************************************************************
5 * Copyright (C) 1995-2026, 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 "TPadPainterPS.h"
18#include "TVirtualPS.h"
19#include "TVirtualX.h"
20#include "TCanvas.h"
21#include "TPoint.h"
22#include "TError.h"
23#include "TImage.h"
24#include "TROOT.h"
25#include "TMath.h"
26#include "TPad.h"
27
28/** \class TPadPainter
29\ingroup gpad
30
31Implement TVirtualPadPainter which abstracts painting operations.
32*/
33
34////////////////////////////////////////////////////////////////////////////////
35/// Consructor
36/// Assigns TVirtualPS instance which will be used by the painter
37
42
43/*
44Line/fill/etc. attributes can be set inside TPad, but not only where:
45many of them are set by base sub-objects of 2d primitives
46(2d primitives usually inherit TAttLine or TAttFill etc.). And these sub-objects
47call gVirtualPS->SetLineWidth ... etc. So, if I save some attributes in my painter,
48it will be mess - at any moment I do not know, where to take line attribute - from
49gVirtualX or from my own member. So! All attributed, _ALL_ go to gVirtualPS.
50At the same time attributes copy preserved in the painter -
51so actual value can be requested without asking of gVirtualPS instance
52*/
53
54
55////////////////////////////////////////////////////////////////////////////////
56/// Delegate to gVirtualPS.
57
62
63////////////////////////////////////////////////////////////////////////////////
64/// Provide fill attributes to gVirtualPS.
65
67{
69
70 fPS->SetFillColor(att.GetFillColor());
71 fPS->SetFillStyle(att.GetFillStyle());
72}
73
74////////////////////////////////////////////////////////////////////////////////
75/// Provide line attributes to gVirtualPS.
76
78{
80
81 fPS->SetLineColor(att.GetLineColor());
82 fPS->SetLineStyle(att.GetLineStyle());
83 fPS->SetLineWidth(att.GetLineWidth());
84}
85
86////////////////////////////////////////////////////////////////////////////////
87/// Provide marker attributes to gVirtualPS.
88
90{
92
93 fPS->SetMarkerColor(att.GetMarkerColor());
94 fPS->SetMarkerSize(att.GetMarkerSize());
95 fPS->SetMarkerStyle(att.GetMarkerStyle());
96}
97
98////////////////////////////////////////////////////////////////////////////////
99/// Provide text attributes to gVirtualPS.
100
102{
104
105 fPS->SetTextAlign(att.GetTextAlign());
106 fPS->SetTextAngle(att.GetTextAngle());
107 fPS->SetTextColor(att.GetTextColor());
108 fPS->SetTextSize(att.GetTextSize());
109 fPS->SetTextFont(att.GetTextFont());
110}
111
112
113////////////////////////////////////////////////////////////////////////////////
114/// Create a gVirtualX Pixmap - not implemented
115
120
121
122////////////////////////////////////////////////////////////////////////////////
123/// Clear the current gVirtualX window - noop for PS
124
128
129
130////////////////////////////////////////////////////////////////////////////////
131/// Copy a gVirtualX pixmap - not implemented
132
136
137
138////////////////////////////////////////////////////////////////////////////////
139/// Close the current gVirtualX pixmap - not implemented
140
144
145
146////////////////////////////////////////////////////////////////////////////////
147/// Select the window in which the graphics will go - not implemented
148
152
153
154////////////////////////////////////////////////////////////////////////////////
155/// Start new page on PS output
156
158{
159 fPS->NewPage();
160}
161
162
163
164////////////////////////////////////////////////////////////////////////////////
165///Noop, for non-gl pad TASImage calls gVirtualX->CopyArea.
166
167void TPadPainterPS::DrawPixels(const unsigned char * /*pixelData*/, UInt_t /*width*/, UInt_t /*height*/,
168 Int_t /*dstX*/, Int_t /*dstY*/, Bool_t /*enableAlphaBlending*/)
169{
170}
171
172
173////////////////////////////////////////////////////////////////////////////////
174/// Paint a simple line.
175
177{
178 if (GetAttLine().GetLineWidth() <= 0)
179 return;
180 Double_t x[2] = {x1, x2}, y[2] = {y1, y2};
181 fPS->DrawPS(2, x, y);
182}
183
184
185////////////////////////////////////////////////////////////////////////////////
186/// Paint a simple line in normalized coordinates.
187
189{
190 if (GetAttLine().GetLineWidth() <= 0)
191 return;
192
193 Double_t xw[2], yw[2];
194
195 xw[0] = (1 - u1) * fPad->GetX1() + u1 * fPad->GetX2();
196 xw[1] = (1 - u2) * fPad->GetX1() + u2 * fPad->GetX2();
197 yw[0] = (1 - v1) * fPad->GetY1() + v1 * fPad->GetY2();
198 yw[1] = (1 - v2) * fPad->GetY1() + v2 * fPad->GetY2();
199 fPS->DrawPS(2, xw, yw);
200}
201
202
203////////////////////////////////////////////////////////////////////////////////
204/// Paint a simple box.
205
207{
208 Int_t style0 = -1;
209
211 if (GetAttLine().GetLineWidth() <= 0)
212 return;
214 if (style0 > 0)
215 fPS->SetFillStyle(0);
216 }
217
218 fPS->DrawBox(x1, y1, x2, y2);
219
220 if (style0 > 0)
222}
223
224////////////////////////////////////////////////////////////////////////////////
225/// Paint filled area.
226
228{
229 if (nPoints < 3) {
230 ::Error("TPadPainterPS::DrawFillArea", "invalid number of points %d", nPoints);
231 return;
232 }
233
234 fPS->DrawPS(-nPoints, const_cast<Double_t *>(xs), const_cast<Double_t *>(ys));
235}
236
237
238////////////////////////////////////////////////////////////////////////////////
239/// Paint filled area.
240
242{
243 if (nPoints < 3) {
244 ::Error("TPadPainterPS::DrawFillArea", "invalid number of points %d", nPoints);
245 return;
246 }
247
248 fPS->DrawPS(-nPoints, const_cast<Float_t *>(xs), const_cast<Float_t *>(ys));
249}
250
251////////////////////////////////////////////////////////////////////////////////
252/// Paint Polyline.
253
255{
256 if (GetAttLine().GetLineWidth() <= 0)
257 return;
258
259 if (n < 2) {
260 ::Error("TPadPainterPS::DrawPolyLine", "invalid number of points");
261 return;
262 }
263
264 fPS->DrawPS(n, const_cast<Double_t *>(xs), const_cast<Double_t *>(ys));
265}
266
267
268////////////////////////////////////////////////////////////////////////////////
269/// Paint polyline.
270
272{
273 if (GetAttLine().GetLineWidth() <= 0)
274 return;
275
276 if (n < 2) {
277 ::Error("TPadPainterPS::DrawPolyLine", "invalid number of points");
278 return;
279 }
280
281 fPS->DrawPS(n, const_cast<Float_t *>(xs), const_cast<Float_t *>(ys));
282}
283
284
285////////////////////////////////////////////////////////////////////////////////
286/// Paint polyline in normalized coordinates.
287
289{
290 if (GetAttLine().GetLineWidth() <= 0)
291 return;
292
293 if (n < 2) {
294 ::Error("TPadPainterPS::DrawPolyLineNDC", "invalid number of points %d", n);
295 return;
296 }
297
298 std::vector<Double_t> xw(n), yw(n);
299 for (Int_t i = 0; i < n; i++) {
300 xw[i] = (1 - u[i]) * fPad->GetX1() + u[i] * fPad->GetX2();
301 yw[i] = (1 - v[i]) * fPad->GetY1() + v[i] * fPad->GetY2();
302 }
303 fPS->DrawPS(n, xw.data(), yw.data());
304}
305
306////////////////////////////////////////////////////////////////////////////////
307/// Paint N segments on the pad
308
310{
311 if (GetAttLine().GetLineWidth() <= 0)
312 return;
313
314 if (n < 1) {
315 ::Error("TPadPainterPS::DrawSegments", "invalid number of segments %d", n);
316 return;
317 }
318
319 fPS->DrawSegments(n, x, y);
320}
321
322////////////////////////////////////////////////////////////////////////////////
323/// Paint N segments in normalized coordinates on the pad
324
326{
327 if (GetAttLine().GetLineWidth() <= 0)
328 return;
329
330 if (n < 1) {
331 ::Error("TPadPainterPS::DrawSegmentsNDC", "invalid number of segments %d", n);
332 return;
333 }
334 // recalculate values into normal coordiantes
335 for (Int_t i = 0; i < 2*n; i++) {
336 u[i] = (1 - u[i]) * fPad->GetX1() + u[i] * fPad->GetX2();
337 v[i] = (1 - v[i]) * fPad->GetY1() + v[i] * fPad->GetY2();
338 }
339 fPS->DrawSegments(n, u, v);
340}
341
342////////////////////////////////////////////////////////////////////////////////
343/// Paint polymarker.
344
346{
347 if (n < 1) {
348 ::Error("TPadPainterPS::DrawPolyMarker", "invalid number of points %d", n);
349 return;
350 }
351
352 fPS->DrawPolyMarker(n, const_cast<Double_t *>(x), const_cast<Double_t *>(y));
353}
354
355
356////////////////////////////////////////////////////////////////////////////////
357/// Paint polymarker.
358
360{
361 if (n < 1) {
362 ::Error("TPadPainterPS::DrawPolyMarker", "invalid number of points %d", n);
363 return;
364 }
365
366 fPS->DrawPolyMarker(n, const_cast<Float_t *>(x), const_cast<Float_t *>(y));
367}
368
369
370////////////////////////////////////////////////////////////////////////////////
371/// Paint text.
372
374{
375 fPS->Text(x, y, text);
376}
377
378
379////////////////////////////////////////////////////////////////////////////////
380/// Special version working with wchar_t and required by TMathText.
381
382void TPadPainterPS::DrawText(Double_t x, Double_t y, const wchar_t *text, ETextMode /* mode */)
383{
384 fPS->Text(x, y, text);
385}
386
387
388////////////////////////////////////////////////////////////////////////////////
389/// Drawint text with url link
390
391void TPadPainterPS::DrawTextUrl(Double_t x, Double_t y, const char *text, const char *url)
392{
393 fPS->TextUrl(x, y, text, url);
394}
395
396
397////////////////////////////////////////////////////////////////////////////////
398/// Paint text in normalized coordinates.
399
401{
402 Double_t x = (1 - u) * fPad->GetX1() + u * fPad->GetX2();
403 Double_t y = (1 - v) * fPad->GetY1() + v * fPad->GetY2();
404 fPS->Text(x, y, text);
405}
406
407
408////////////////////////////////////////////////////////////////////////////////
409/// Save the image displayed in the canvas pointed by "pad" into a binary file.
410
411void TPadPainterPS::SaveImage(TVirtualPad *, const char *, Int_t) const
412{
413}
414
415
416////////////////////////////////////////////////////////////////////////////////
417/// Paint text in normalized coordinates.
418
419void TPadPainterPS::DrawTextNDC(Double_t u, Double_t v, const wchar_t *text, ETextMode /* mode */)
420{
421 Double_t x = (1 - u) * fPad->GetX1() + u * fPad->GetX2();
422 Double_t y = (1 - v) * fPad->GetY1() + v * fPad->GetY2();
423 fPS->Text(x, y, text);
424}
float Float_t
Float 4 bytes (float)
Definition RtypesCore.h:71
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 TPoint TPoint const char x2
Option_t Option_t TPoint TPoint const char x1
Option_t Option_t TPoint TPoint const char mode
Option_t Option_t TPoint TPoint const char y2
Option_t Option_t TPoint TPoint percent
Option_t Option_t TPoint TPoint const char text
Option_t Option_t TPoint TPoint const char y1
Fill Area Attributes class.
Definition TAttFill.h:21
virtual Style_t GetFillStyle() const
Return the fill area style.
Definition TAttFill.h:33
virtual void SetFillColor(Color_t fcolor)
Set the fill area color.
Definition TAttFill.h:40
virtual void SetFillStyle(Style_t fstyle)
Set the fill area style.
Definition TAttFill.h:42
Line Attributes class.
Definition TAttLine.h:21
virtual void SetLineStyle(Style_t lstyle)
Set the line style.
Definition TAttLine.h:46
virtual void SetLineWidth(Width_t lwidth)
Set the line width.
Definition TAttLine.h:47
virtual void SetLineColor(Color_t lcolor)
Set the line color.
Definition TAttLine.h:44
Marker Attributes class.
Definition TAttMarker.h:21
virtual void SetMarkerColor(Color_t mcolor=1)
Set the marker color.
Definition TAttMarker.h:41
virtual void SetMarkerStyle(Style_t mstyle=1)
Set the marker style.
Definition TAttMarker.h:43
virtual void SetMarkerSize(Size_t msize=1)
Set the marker size.
Definition TAttMarker.h:48
Text Attributes class.
Definition TAttText.h:21
virtual void SetTextAlign(Short_t align=11)
Set the text alignment.
Definition TAttText.h:46
virtual void SetTextAngle(Float_t tangle=0)
Set the text angle.
Definition TAttText.h:47
virtual void SetTextColor(Color_t tcolor=1)
Set the text color.
Definition TAttText.h:48
virtual void SetTextFont(Font_t tfont=62)
Set the text font.
Definition TAttText.h:50
virtual void SetTextSize(Float_t tsize=1)
Set the text size.
Definition TAttText.h:51
void SetAttFill(const TAttFill &att) override
Set fill attributes.
void SetAttText(const TAttText &att) override
Set text attributes.
Width_t GetLineWidth() const override
void SetAttMarker(const TAttMarker &att) override
Set marker attributes.
void SetAttLine(const TAttLine &att) override
Set line attributes.
const TAttLine & GetAttLine() const override
Get line attributes.
void DrawPolyLineNDC(Int_t n, const Double_t *u, const Double_t *v) override
Paint polyline in normalized coordinates.
void DrawSegments(Int_t n, Double_t *x, Double_t *y) override
Paint N segments on the pad.
void ClearDrawable() override
Clear the current gVirtualX window - noop for PS.
void SetAttMarker(const TAttMarker &att) override
Provide marker attributes to gVirtualPS.
TVirtualPS * fPS
void DrawSegmentsNDC(Int_t n, Double_t *u, Double_t *v) override
Paint N segments in normalized coordinates on the pad.
void SetAttText(const TAttText &att) override
Provide text attributes to gVirtualPS.
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 DrawTextNDC(Double_t u, Double_t v, const char *text, ETextMode mode) override
Paint text in normalized coordinates.
void DrawLineNDC(Double_t u1, Double_t v1, Double_t u2, Double_t v2) override
Paint a simple line in normalized coordinates.
TPadPainterPS(TVirtualPS *ps)
Consructor Assigns TVirtualPS instance which will be used by the painter.
void NewPage() override
Start new page on PS output.
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 DrawTextUrl(Double_t x, Double_t y, const char *text, const char *url) override
Drawint text with url link.
void SelectDrawable(Int_t device) override
Select the window in which the graphics will go - not implemented.
void DrawFillArea(Int_t n, const Double_t *x, const Double_t *y) override
Paint filled area.
void SetAttLine(const TAttLine &att) override
Provide line attributes to gVirtualPS.
void DrawPolyMarker(Int_t n, const Double_t *x, const Double_t *y) override
Paint polymarker.
void DrawText(Double_t x, Double_t y, const char *text, ETextMode mode) override
Paint text.
TVirtualPad * fPad
void SetOpacity(Int_t percent) override
Delegate to gVirtualPS.
void SetAttFill(const TAttFill &att) override
Provide fill attributes to gVirtualPS.
void DrawLine(Double_t x1, Double_t y1, Double_t x2, Double_t y2) override
Paint a simple line.
Int_t CreateDrawable(UInt_t w, UInt_t h) override
Create a gVirtualX Pixmap - not implemented.
void DestroyDrawable(Int_t device) override
Close the current gVirtualX pixmap - not implemented.
void DrawBox(Double_t x1, Double_t y1, Double_t x2, Double_t y2, EBoxMode mode) override
Paint a simple box.
void CopyDrawable(Int_t device, Int_t px, Int_t py) override
Copy a gVirtualX pixmap - not implemented.
void DrawPolyLine(Int_t n, const Double_t *x, const Double_t *y) override
Paint Polyline.
TVirtualPS is an abstract interface to Postscript, PDF, SVG.
Definition TVirtualPS.h:30
virtual void Text(Double_t x, Double_t y, const char *string)=0
virtual void NewPage()=0
virtual void DrawPS(Int_t n, Float_t *xw, Float_t *yw)=0
virtual void DrawBox(Double_t x1, Double_t y1, Double_t x2, Double_t y2)=0
virtual void DrawPolyMarker(Int_t n, Float_t *x, Float_t *y)=0
virtual void DrawSegments(Int_t n, Double_t *xw, Double_t *yw)
Print N segments.
virtual void TextUrl(Double_t x, Double_t y, const char *string, const char *url)=0
TVirtualPad is an abstract base class for the Pad and Canvas classes.
Definition TVirtualPad.h:51
virtual Double_t GetX2() const =0
virtual Double_t GetY1() const =0
virtual Double_t GetY2() const =0
virtual Double_t GetX1() const =0
Double_t y[n]
Definition legend1.C:17
Double_t x[n]
Definition legend1.C:17
const Int_t n
Definition legend1.C:16