Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TWebPadPainter.cxx
Go to the documentation of this file.
1// Author: Sergey Linev, GSI 10/04/2017
2
3/*************************************************************************
4 * Copyright (C) 1995-2019, Rene Brun and Fons Rademakers. *
5 * All rights reserved. *
6 * *
7 * For the licensing terms see $ROOTSYS/LICENSE. *
8 * For the list of contributors see $ROOTSYS/README/CREDITS. *
9 *************************************************************************/
10
11#include "TWebPadPainter.h"
12#include "TError.h"
13#include "TImage.h"
14#include "TPad.h"
15#include "TWebCanvas.h"
16
17
18/** \class TWebPadPainter
19\ingroup webgui6
20\brief Implement TVirtualPadPainter which abstracts painting operations.
21
22TWebPadPainter tries to support old Paint methods of the ROOT classes.
23Main classes (like histograms or graphs) should be painted on JavaScript side
24
25*/
26
27
28//////////////////////////////////////////////////////////////////////////
29/// Store operation identifier with appropriate attributes
30
31Float_t *TWebPadPainter::StoreOperation(const std::string &oper, unsigned attrkind, int opersize)
32{
33 if (!fPainting)
34 return nullptr;
35
36 if (attrkind & attrLine)
37 fPainting->AddLineAttr(fPS ? *((TAttLine *) fPS) : *((TAttLine *)this));
38
39 if (attrkind & attrFill)
40 fPainting->AddFillAttr(fPS ? *((TAttFill *) fPS) : *((TAttFill *)this));
41
42 if (attrkind & attrMarker)
43 fPainting->AddMarkerAttr(fPS ? *((TAttMarker *) fPS) : *((TAttMarker *)this));
44
45 if (attrkind & attrText)
46 fPainting->AddTextAttr(fPS ? *((TAttText *)fPS) : *((TAttText *)this));
47
49
50 return fPainting->Reserve(opersize);
51}
52
53////////////////////////////////////////////////////////////////////////////////
54///Noop, for non-gl pad TASImage calls gVirtualX->CopyArea.
55
56void TWebPadPainter::DrawPixels(const unsigned char * /*pixelData*/, UInt_t /*width*/, UInt_t /*height*/,
57 Int_t /*dstX*/, Int_t /*dstY*/, Bool_t /*enableAlphaBlending*/)
58{
59
60}
61
62
63////////////////////////////////////////////////////////////////////////////////
64/// Paint a simple line.
65
67{
68 if (GetLineWidth() <= 0)
69 return;
70
71 auto buf = StoreOperation("l2", attrLine, 4);
72 if (buf) {
73 buf[0] = x1;
74 buf[1] = y1;
75 buf[2] = x2;
76 buf[3] = y2;
77 }
78}
79
80
81////////////////////////////////////////////////////////////////////////////////
82/// Paint a simple line in normalized coordinates.
83
85{
86 if (GetLineWidth()<=0) return;
87
88 ::Error("DrawLineNDC", "Not supported correctly");
89
90 auto buf = StoreOperation("l2", attrLine, 4);
91 if (buf) {
92 buf[0] = u1;
93 buf[1] = v1;
94 buf[2] = u2;
95 buf[3] = v2;
96 }
97}
98
99
100////////////////////////////////////////////////////////////////////////////////
101/// Paint a simple box.
102
104{
105 if (GetLineWidth()<=0 && mode == TVirtualPadPainter::kHollow) return;
106
107 Float_t *buf = nullptr;
108
110 buf = StoreOperation("r", attrLine, 4); // only border
111 else
112 buf = StoreOperation("b", attrFill, 4); // only fill
113
114 if (buf) {
115 buf[0] = x1;
116 buf[1] = y1;
117 buf[2] = x2;
118 buf[3] = y2;
119 }
120}
121
122////////////////////////////////////////////////////////////////////////////////
123/// Paint filled area.
124
126{
127 if ((GetFillStyle() <= 0) || (nPoints < 3))
128 return;
129
130 auto buf = StoreOperation("f" + std::to_string(nPoints), attrFill, nPoints * 2);
131 if (buf)
132 for (Int_t n = 0; n < nPoints; ++n) {
133 buf[n * 2] = xs[n];
134 buf[n * 2 + 1] = ys[n];
135 }
136}
137
138////////////////////////////////////////////////////////////////////////////////
139/// Paint filled area.
140
142{
143 if ((GetFillStyle() <= 0) || (nPoints < 3))
144 return;
145
146 auto buf = StoreOperation("f" + std::to_string(nPoints), attrFill, nPoints * 2);
147 if (buf)
148 for (Int_t n = 0; n < nPoints; ++n) {
149 buf[n * 2] = xs[n];
150 buf[n * 2 + 1] = ys[n];
151 }
152}
153
154////////////////////////////////////////////////////////////////////////////////
155/// Paint Polyline.
156
158{
159 if ((GetLineWidth() <= 0) || (nPoints < 2))
160 return;
161
162 auto buf = StoreOperation("l" + std::to_string(nPoints), attrLine, nPoints * 2);
163 if (buf)
164 for (Int_t n = 0; n < nPoints; ++n) {
165 buf[n * 2] = xs[n];
166 buf[n * 2 + 1] = ys[n];
167 }
168}
169
170////////////////////////////////////////////////////////////////////////////////
171/// Paint polyline.
172
174{
175 if ((GetLineWidth() <= 0) || (nPoints < 2))
176 return;
177
178 auto buf = StoreOperation("l" + std::to_string(nPoints), attrLine, nPoints * 2);
179 if (buf)
180 for (Int_t n = 0; n < nPoints; ++n) {
181 buf[n * 2] = xs[n];
182 buf[n * 2 + 1] = ys[n];
183 }
184}
185
186////////////////////////////////////////////////////////////////////////////////
187/// Paint polyline in normalized coordinates.
188
190{
191 if ((GetLineWidth() <= 0) || (nPoints < 2))
192 return;
193
194 ::Error("DrawPolyLineNDC", "Not supported correctly");
195
196 auto buf = StoreOperation("l" + std::to_string(nPoints), attrLine, nPoints * 2);
197 if (buf)
198 for (Int_t n = 0; n < nPoints; ++n) {
199 buf[n * 2] = u[n];
200 buf[n * 2 + 1] = v[n];
201 }
202}
203
204////////////////////////////////////////////////////////////////////////////////
205/// Paint polymarker.
206
208{
209 if (nPoints < 1)
210 return;
211
212 auto buf = StoreOperation(std::string("m") + std::to_string(nPoints), attrLine | attrMarker, nPoints * 2);
213
214 if (buf)
215 for (Int_t n = 0; n < nPoints; ++n) {
216 buf[n * 2] = x[n];
217 buf[n * 2 + 1] = y[n];
218 }
219}
220
221////////////////////////////////////////////////////////////////////////////////
222/// Paint polymarker.
223
225{
226 if (nPoints < 1)
227 return;
228
229 auto buf = StoreOperation(std::string("m") + std::to_string(nPoints), attrLine | attrMarker, nPoints * 2);
230
231 if (buf)
232 for (Int_t n = 0; n < nPoints; ++n) {
233 buf[n * 2] = x[n];
234 buf[n * 2 + 1] = y[n];
235 }
236}
237
238////////////////////////////////////////////////////////////////////////////////
239/// Paint text.
240
242{
244 if (buf) {
245 buf[0] = x;
246 buf[1] = y;
247 }
248}
249
250////////////////////////////////////////////////////////////////////////////////
251/// Special version working with wchar_t and required by TMathText.
252
253void TWebPadPainter::DrawText(Double_t x, Double_t y, const wchar_t * /*text*/, ETextMode /*mode*/)
254{
255 auto buf = StoreOperation(TWebPainting::MakeTextOper("wchar_t"), attrText, 2);
256 if (buf) {
257 buf[0] = x;
258 buf[1] = y;
259 }
260}
261
262////////////////////////////////////////////////////////////////////////////////
263/// Paint text in normalized coordinates.
264
266{
267 ::Error("DrawTextNDC", "Not supported correctly");
268
270
271 if (buf) {
272 buf[0] = u;
273 buf[1] = v;
274 }
275}
276
277////////////////////////////////////////////////////////////////////////////////
278/// Paint text in normalized coordinates.
279
280void TWebPadPainter::DrawTextNDC(Double_t u , Double_t v, const wchar_t * /*text*/, ETextMode /*mode*/)
281{
282 ::Error("DrawTextNDC", "Not supported correctly");
283
284 auto buf = StoreOperation(TWebPainting::MakeTextOper("wchar_t"), attrText, 2);
285
286 if (buf) {
287 buf[0] = u;
288 buf[1] = v;
289 }
290}
291
292////////////////////////////////////////////////////////////////////////////////
293/// Produce image from WebPadPainter
294
295void TWebPadPainter::SaveImage(TVirtualPad *pad, const char *fileName, Int_t gtype) const
296{
297 (void) gtype;
298 // if ((gtype == TImage::kPng) || (gtype == TImage::kJpeg))
299 TWebCanvas::ProduceImage(dynamic_cast<TPad *>(pad), fileName);
300}
301
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 const char text
Option_t Option_t TPoint TPoint const char y1
Fill Area Attributes class.
Definition TAttFill.h:20
Line Attributes class.
Definition TAttLine.h:20
Marker Attributes class.
Definition TAttMarker.h:20
Text Attributes class.
Definition TAttText.h:20
The most important graphics class in the ROOT system.
Definition TPad.h:28
TVirtualPad is an abstract base class for the Pad and Canvas classes.
Definition TVirtualPad.h:51
static bool ProduceImage(TPad *pad, const char *filename, Int_t width=0, Int_t height=0)
Create image using batch (headless) capability of Chrome or Firefox browsers Supported png,...
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.
Style_t GetFillStyle() const override
void DrawFillArea(Int_t n, const Double_t *x, const Double_t *y) override
Paint filled area.
TWebPS * fPS
! current TWebPS instance
void DrawBox(Double_t x1, Double_t y1, Double_t x2, Double_t y2, EBoxMode mode) override
Paint a simple box.
TWebPainting * fPainting
! object to store all painting, owned by TWebPS object
void DrawTextNDC(Double_t u, Double_t v, const char *text, ETextMode mode) override
Paint text in normalized coordinates.
Float_t * StoreOperation(const std::string &oper, unsigned attrkind, int opersize=0)
Store operation identifier with appropriate attributes.
void DrawText(Double_t x, Double_t y, const char *text, ETextMode mode) override
Paint text.
void DrawLineNDC(Double_t u1, Double_t v1, Double_t u2, Double_t v2) override
Paint a simple line in normalized coordinates.
void DrawPolyMarker(Int_t n, const Double_t *x, const Double_t *y) override
Paint polymarker.
void DrawPolyLineNDC(Int_t n, const Double_t *u, const Double_t *v) override
Paint polyline in normalized coordinates.
Width_t GetLineWidth() const override
void SaveImage(TVirtualPad *, const char *, Int_t) const override
Produce image from WebPadPainter.
void DrawPolyLine(Int_t n, const Double_t *x, const Double_t *y) override
Paint Polyline.
void DrawLine(Double_t x1, Double_t y1, Double_t x2, Double_t y2) override
Paint a simple line.
void AddTextAttr(const TAttText &attr)
Store text attributes If attributes were not changed - ignore operation.
void AddMarkerAttr(const TAttMarker &attr)
Store marker attributes If attributes were not changed - ignore operation.
void AddLineAttr(const TAttLine &attr)
Store line attributes If attributes were not changed - ignore operation.
static std::string MakeTextOper(const char *str)
Create text operation If text include special symbols - use simple hex coding.
void AddOper(const std::string &oper)
Add next custom operator to painting Operations are separated by semicolons Following operations are ...
Float_t * Reserve(Int_t sz)
Reserve place in the float buffer Returns pointer on first element in reserved area.
void AddFillAttr(const TAttFill &attr)
Store fill attributes If attributes were not changed - ignore operation.
Double_t y[n]
Definition legend1.C:17
Double_t x[n]
Definition legend1.C:17
const Int_t n
Definition legend1.C:16