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 "TCanvas.h"
20#include "TPoint.h"
21#include "TError.h"
22#include "TImage.h"
23#include "TROOT.h"
24#include "TColor.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
59{
61 att.SetFillStyle(4000 + percent);
63}
64
65////////////////////////////////////////////////////////////////////////////////
66/// Provide fill attributes to gVirtualPS.
67
69{
71
72 auto fill = GetAttFillInternal(kTRUE);
73 fPS->SetFillColor(fill.GetFillColor());
74 fPS->SetFillStyle(fill.GetFillStyle());
75}
76
77////////////////////////////////////////////////////////////////////////////////
78/// Provide line attributes to gVirtualPS.
79
81{
83
84 fPS->SetLineColor(att.GetLineColor());
85 fPS->SetLineStyle(att.GetLineStyle());
86 fPS->SetLineWidth(att.GetLineWidth());
87}
88
89////////////////////////////////////////////////////////////////////////////////
90/// Provide marker attributes to gVirtualPS.
91
93{
95
96 fPS->SetMarkerColor(att.GetMarkerColor());
97 fPS->SetMarkerSize(att.GetMarkerSize());
98 fPS->SetMarkerStyle(att.GetMarkerStyle());
99}
100
101////////////////////////////////////////////////////////////////////////////////
102/// Provide text attributes to gVirtualPS.
103
105{
107
108 fPS->SetTextAlign(att.GetTextAlign());
109 fPS->SetTextAngle(att.GetTextAngle());
110 fPS->SetTextColor(att.GetTextColor());
111 fPS->SetTextSize(att.GetTextSize());
112 fPS->SetTextFont(att.GetTextFont());
113}
114
115
116////////////////////////////////////////////////////////////////////////////////
117/// Create a gVirtualX Pixmap - not implemented
118
123
124
125////////////////////////////////////////////////////////////////////////////////
126/// Clear the current gVirtualX window - noop for PS
127
131
132
133////////////////////////////////////////////////////////////////////////////////
134/// Copy a gVirtualX pixmap - not implemented
135
139
140
141////////////////////////////////////////////////////////////////////////////////
142/// Close the current gVirtualX pixmap - not implemented
143
147
148
149////////////////////////////////////////////////////////////////////////////////
150/// Select the window in which the graphics will go - not implemented
151
155
156
157////////////////////////////////////////////////////////////////////////////////
158/// Start new page on PS output
159
161{
162 fPS->NewPage();
163}
164
165
166
167////////////////////////////////////////////////////////////////////////////////
168///Noop, for non-gl pad TASImage calls gVirtualX->CopyArea.
169
170void TPadPainterPS::DrawPixels(const unsigned char * /*pixelData*/, UInt_t /*width*/, UInt_t /*height*/,
171 Int_t /*dstX*/, Int_t /*dstY*/, Bool_t /*enableAlphaBlending*/)
172{
173}
174
175
176////////////////////////////////////////////////////////////////////////////////
177/// Paint a simple line.
178
180{
181 if (GetAttLine().GetLineWidth() <= 0)
182 return;
183 Double_t x[2] = {x1, x2}, y[2] = {y1, y2};
184 fPS->DrawPS(2, x, y);
185}
186
187
188////////////////////////////////////////////////////////////////////////////////
189/// Paint a simple line in normalized coordinates.
190
192{
193 if (GetAttLine().GetLineWidth() <= 0)
194 return;
195
196 Double_t xw[2], yw[2];
197
198 xw[0] = (1 - u1) * fPad->GetX1() + u1 * fPad->GetX2();
199 xw[1] = (1 - u2) * fPad->GetX1() + u2 * fPad->GetX2();
200 yw[0] = (1 - v1) * fPad->GetY1() + v1 * fPad->GetY2();
201 yw[1] = (1 - v2) * fPad->GetY1() + v2 * fPad->GetY2();
202 fPS->DrawPS(2, xw, yw);
203}
204
205
206////////////////////////////////////////////////////////////////////////////////
207/// Paint a simple box.
208
210{
211 Int_t style0 = -1;
212
214 if (GetAttLine().GetLineWidth() <= 0)
215 return;
217 if (style0 > 0)
218 fPS->SetFillStyle(0);
219 } else if (fFullyTransparent)
220 return;
221
222 fPS->DrawBox(x1, y1, x2, y2);
223
224 if (style0 > 0)
226}
227
228////////////////////////////////////////////////////////////////////////////////
229/// Paint filled area.
230
232{
233 if (nPoints < 3) {
234 ::Error("TPadPainterPS::DrawFillArea", "invalid number of points %d", nPoints);
235 return;
236 }
237
238 if (!fFullyTransparent || (fPS->GetLineWidth() > 0))
239 fPS->DrawPS(-nPoints, const_cast<Double_t *>(xs), const_cast<Double_t *>(ys));
240}
241
242
243////////////////////////////////////////////////////////////////////////////////
244/// Paint filled area.
245
247{
248 if (nPoints < 3) {
249 ::Error("TPadPainterPS::DrawFillArea", "invalid number of points %d", nPoints);
250 return;
251 }
252
253 if (!fFullyTransparent || (fPS->GetLineWidth() > 0))
254 fPS->DrawPS(-nPoints, const_cast<Float_t *>(xs), const_cast<Float_t *>(ys));
255}
256
257////////////////////////////////////////////////////////////////////////////////
258/// Paint Polyline.
259
261{
262 if (GetAttLine().GetLineWidth() <= 0)
263 return;
264
265 if (n < 2) {
266 ::Error("TPadPainterPS::DrawPolyLine", "invalid number of points");
267 return;
268 }
269
270 fPS->DrawPS(n, const_cast<Double_t *>(xs), const_cast<Double_t *>(ys));
271}
272
273
274////////////////////////////////////////////////////////////////////////////////
275/// Paint polyline.
276
278{
279 if (GetAttLine().GetLineWidth() <= 0)
280 return;
281
282 if (n < 2) {
283 ::Error("TPadPainterPS::DrawPolyLine", "invalid number of points");
284 return;
285 }
286
287 fPS->DrawPS(n, const_cast<Float_t *>(xs), const_cast<Float_t *>(ys));
288}
289
290
291////////////////////////////////////////////////////////////////////////////////
292/// Paint polyline in normalized coordinates.
293
295{
296 if (GetAttLine().GetLineWidth() <= 0)
297 return;
298
299 if (n < 2) {
300 ::Error("TPadPainterPS::DrawPolyLineNDC", "invalid number of points %d", n);
301 return;
302 }
303
304 std::vector<Double_t> xw(n), yw(n);
305 for (Int_t i = 0; i < n; i++) {
306 xw[i] = (1 - u[i]) * fPad->GetX1() + u[i] * fPad->GetX2();
307 yw[i] = (1 - v[i]) * fPad->GetY1() + v[i] * fPad->GetY2();
308 }
309 fPS->DrawPS(n, xw.data(), yw.data());
310}
311
312////////////////////////////////////////////////////////////////////////////////
313/// Paint N segments on the pad
314
316{
317 if (GetAttLine().GetLineWidth() <= 0)
318 return;
319
320 if (n < 1) {
321 ::Error("TPadPainterPS::DrawSegments", "invalid number of segments %d", n);
322 return;
323 }
324
325 fPS->DrawSegments(n, x, y);
326}
327
328////////////////////////////////////////////////////////////////////////////////
329/// Paint N segments in normalized coordinates on the pad
330
332{
333 if (GetAttLine().GetLineWidth() <= 0)
334 return;
335
336 if (n < 1) {
337 ::Error("TPadPainterPS::DrawSegmentsNDC", "invalid number of segments %d", n);
338 return;
339 }
340 // recalculate values into normal coordiantes
341 for (Int_t i = 0; i < 2*n; i++) {
342 u[i] = (1 - u[i]) * fPad->GetX1() + u[i] * fPad->GetX2();
343 v[i] = (1 - v[i]) * fPad->GetY1() + v[i] * fPad->GetY2();
344 }
345 fPS->DrawSegments(n, u, v);
346}
347
348////////////////////////////////////////////////////////////////////////////////
349/// Paint polymarker.
350
352{
353 if (n < 1) {
354 ::Error("TPadPainterPS::DrawPolyMarker", "invalid number of points %d", n);
355 return;
356 }
357
358 fPS->DrawPolyMarker(n, const_cast<Double_t *>(x), const_cast<Double_t *>(y));
359}
360
361
362////////////////////////////////////////////////////////////////////////////////
363/// Paint polymarker.
364
366{
367 if (n < 1) {
368 ::Error("TPadPainterPS::DrawPolyMarker", "invalid number of points %d", n);
369 return;
370 }
371
372 fPS->DrawPolyMarker(n, const_cast<Float_t *>(x), const_cast<Float_t *>(y));
373}
374
375
376////////////////////////////////////////////////////////////////////////////////
377/// Paint text.
378
380{
381 fPS->Text(x, y, text);
382}
383
384
385////////////////////////////////////////////////////////////////////////////////
386/// Special version working with wchar_t and required by TMathText.
387
388void TPadPainterPS::DrawText(Double_t x, Double_t y, const wchar_t *text, ETextMode /* mode */)
389{
390 fPS->Text(x, y, text);
391}
392
393
394////////////////////////////////////////////////////////////////////////////////
395/// Drawint text with url link
396
397void TPadPainterPS::DrawTextUrl(Double_t x, Double_t y, const char *text, const char *url)
398{
399 fPS->TextUrl(x, y, text, url);
400}
401
402
403////////////////////////////////////////////////////////////////////////////////
404/// Paint text in normalized coordinates.
405
407{
408 Double_t x = (1 - u) * fPad->GetX1() + u * fPad->GetX2();
409 Double_t y = (1 - v) * fPad->GetY1() + v * fPad->GetY2();
410 fPS->Text(x, y, text);
411}
412
413
414////////////////////////////////////////////////////////////////////////////////
415/// Save the image displayed in the canvas pointed by "pad" into a binary file.
416
417void TPadPainterPS::SaveImage(TVirtualPad *, const char *, Int_t) const
418{
419}
420
421
422////////////////////////////////////////////////////////////////////////////////
423/// Paint text in normalized coordinates.
424
425void TPadPainterPS::DrawTextNDC(Double_t u, Double_t v, const wchar_t *text, ETextMode /* mode */)
426{
427 Double_t x = (1 - u) * fPad->GetX1() + u * fPad->GetX2();
428 Double_t y = (1 - v) * fPad->GetY1() + v * fPad->GetY2();
429 fPS->Text(x, y, text);
430}
float Float_t
Float 4 bytes (float)
Definition RtypesCore.h:71
constexpr Bool_t kTRUE
Definition RtypesCore.h:107
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 Width_t GetLineWidth() const
Return the line width.
Definition TAttLine.h:38
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.
const TAttFill & GetAttFill() const override
Width_t GetLineWidth() const override
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.
TAttFill GetAttFillInternal(Bool_t with_transparency)
Returns fill attributes after modification Checks for special fill styles 4000 .
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