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/// Set opacity - similar to TVirtualPS usecase
29
34
35//////////////////////////////////////////////////////////////////////////
36/// Store operation identifier with appropriate attributes
37
38Float_t *TWebPadPainter::StoreOperation(const std::string &oper, unsigned attrkind, int opersize)
39{
40 if (!fPainting)
41 return nullptr;
42
43 if (attrkind & attrLine)
45
46 if (attrkind & attrFill)
48
49 if (attrkind & attrMarker)
51
52 if (attrkind & attrText)
54
56
57 return fPainting->Reserve(opersize);
58}
59
60////////////////////////////////////////////////////////////////////////////////
61///Noop, for non-gl pad TASImage calls gVirtualX->CopyArea.
62
63void TWebPadPainter::DrawPixels(const unsigned char * /*pixelData*/, UInt_t /*width*/, UInt_t /*height*/,
64 Int_t /*dstX*/, Int_t /*dstY*/, Bool_t /*enableAlphaBlending*/)
65{
66
67}
68
69
70////////////////////////////////////////////////////////////////////////////////
71/// Paint a simple line.
72
74{
75 if (GetAttLine().GetLineWidth() <= 0)
76 return;
77
78 auto buf = StoreOperation("l2", attrLine, 4);
79 if (buf) {
80 buf[0] = x1;
81 buf[1] = y1;
82 buf[2] = x2;
83 buf[3] = y2;
84 }
85}
86
87
88////////////////////////////////////////////////////////////////////////////////
89/// Paint a simple line in normalized coordinates.
90
92{
93 if (GetAttLine().GetLineWidth() <= 0)
94 return;
95
96 ::Error("DrawLineNDC", "Not supported correctly");
97
98 auto buf = StoreOperation("l2", attrLine, 4);
99 if (buf) {
100 buf[0] = u1;
101 buf[1] = v1;
102 buf[2] = u2;
103 buf[3] = v2;
104 }
105}
106
107
108////////////////////////////////////////////////////////////////////////////////
109/// Paint a simple box.
110
112{
114 return;
115
116 Float_t *buf = nullptr;
117
119 buf = StoreOperation("r", attrLine, 4); // only border
120 else
121 buf = StoreOperation("b", attrFill, 4); // only fill
122
123 if (buf) {
124 buf[0] = x1;
125 buf[1] = y1;
126 buf[2] = x2;
127 buf[3] = y2;
128 }
129}
130
131////////////////////////////////////////////////////////////////////////////////
132/// Paint filled area.
133
135{
136 if ((GetAttFill().GetFillStyle() <= 0) || (nPoints < 3))
137 return;
138
139 auto buf = StoreOperation("f" + std::to_string(nPoints), attrFill, nPoints * 2);
140 if (buf)
141 for (Int_t n = 0; n < nPoints; ++n) {
142 buf[n * 2] = xs[n];
143 buf[n * 2 + 1] = ys[n];
144 }
145}
146
147////////////////////////////////////////////////////////////////////////////////
148/// Paint filled area.
149
151{
152 if ((GetAttFill().GetFillStyle() <= 0) || (nPoints < 3))
153 return;
154
155 auto buf = StoreOperation("f" + std::to_string(nPoints), attrFill, nPoints * 2);
156 if (buf)
157 for (Int_t n = 0; n < nPoints; ++n) {
158 buf[n * 2] = xs[n];
159 buf[n * 2 + 1] = ys[n];
160 }
161}
162
163////////////////////////////////////////////////////////////////////////////////
164/// Paint Polyline.
165
167{
168 if ((GetAttLine().GetLineWidth() <= 0) || (nPoints < 2))
169 return;
170
171 auto buf = StoreOperation("l" + std::to_string(nPoints), attrLine, nPoints * 2);
172 if (buf)
173 for (Int_t n = 0; n < nPoints; ++n) {
174 buf[n * 2] = xs[n];
175 buf[n * 2 + 1] = ys[n];
176 }
177}
178
179////////////////////////////////////////////////////////////////////////////////
180/// Paint polyline.
181
183{
184 if ((GetAttLine().GetLineWidth() <= 0) || (nPoints < 2))
185 return;
186
187 auto buf = StoreOperation("l" + std::to_string(nPoints), attrLine, nPoints * 2);
188 if (buf)
189 for (Int_t n = 0; n < nPoints; ++n) {
190 buf[n * 2] = xs[n];
191 buf[n * 2 + 1] = ys[n];
192 }
193}
194
195////////////////////////////////////////////////////////////////////////////////
196/// Paint polyline in normalized coordinates.
197
199{
200 if ((GetAttLine().GetLineWidth() <= 0) || (nPoints < 2))
201 return;
202
203 ::Error("DrawPolyLineNDC", "Not supported correctly");
204
205 auto buf = StoreOperation("l" + std::to_string(nPoints), attrLine, nPoints * 2);
206 if (buf)
207 for (Int_t n = 0; n < nPoints; ++n) {
208 buf[n * 2] = u[n];
209 buf[n * 2 + 1] = v[n];
210 }
211}
212
213////////////////////////////////////////////////////////////////////////////////
214/// Paint polymarker.
215
217{
218 if (nPoints < 1)
219 return;
220
221 auto buf = StoreOperation(std::string("m") + std::to_string(nPoints), attrLine | attrMarker, nPoints * 2);
222
223 if (buf)
224 for (Int_t n = 0; n < nPoints; ++n) {
225 buf[n * 2] = x[n];
226 buf[n * 2 + 1] = y[n];
227 }
228}
229
230////////////////////////////////////////////////////////////////////////////////
231/// Paint polymarker.
232
234{
235 if (nPoints < 1)
236 return;
237
238 auto buf = StoreOperation(std::string("m") + std::to_string(nPoints), attrLine | attrMarker, nPoints * 2);
239
240 if (buf)
241 for (Int_t n = 0; n < nPoints; ++n) {
242 buf[n * 2] = x[n];
243 buf[n * 2 + 1] = y[n];
244 }
245}
246
247////////////////////////////////////////////////////////////////////////////////
248/// Paint text.
249
251{
253 if (buf) {
254 buf[0] = x;
255 buf[1] = y;
256 }
257}
258
259////////////////////////////////////////////////////////////////////////////////
260/// Paint text with url
261
262void TWebPadPainter::DrawTextUrl(Double_t x, Double_t y, const char *text, const char * /* url */)
263{
264 ::Error("DrawTextUrl", "Not supported yet in web painter");
265
267 if (buf) {
268 buf[0] = x;
269 buf[1] = y;
270 }
271}
272
273
274////////////////////////////////////////////////////////////////////////////////
275/// Special version working with wchar_t and required by TMathText.
276
277void TWebPadPainter::DrawText(Double_t x, Double_t y, const wchar_t * /*text*/, ETextMode /*mode*/)
278{
279 ::Error("DrawText", "Not supported wchar_t yet");
280
281 auto buf = StoreOperation(TWebPainting::MakeTextOper("wchar_t"), attrText, 2);
282 if (buf) {
283 buf[0] = x;
284 buf[1] = y;
285 }
286}
287
288////////////////////////////////////////////////////////////////////////////////
289/// Paint text in normalized coordinates.
290
292{
293 ::Error("DrawTextNDC", "Not supported correctly");
294
296
297 if (buf) {
298 buf[0] = u;
299 buf[1] = v;
300 }
301}
302
303////////////////////////////////////////////////////////////////////////////////
304/// Paint text in normalized coordinates.
305
306void TWebPadPainter::DrawTextNDC(Double_t u , Double_t v, const wchar_t * /*text*/, ETextMode /*mode*/)
307{
308 ::Error("DrawTextNDC", "Not supported correctly");
309
310 auto buf = StoreOperation(TWebPainting::MakeTextOper("wchar_t"), attrText, 2);
311
312 if (buf) {
313 buf[0] = u;
314 buf[1] = v;
315 }
316}
317
318
319////////////////////////////////////////////////////////////////////////////////
320/// Produce image from WebPadPainter
321
322void TWebPadPainter::SaveImage(TVirtualPad *pad, const char *fileName, Int_t gtype) const
323{
324 (void) gtype;
325 // if ((gtype == TImage::kPng) || (gtype == TImage::kJpeg))
326 TWebCanvas::ProduceImage(dynamic_cast<TPad *>(pad), fileName);
327}
328
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
virtual void SetFillStyle(Style_t fstyle)
Set the fill area style.
Definition TAttFill.h:42
const TAttText & GetAttText() const override
Get text attributes.
const TAttMarker & GetAttMarker() const override
Get marker attributes.
const TAttFill & GetAttFill() const override
Width_t GetLineWidth() const override
TAttFill fAttFill
current fill attributes
const TAttLine & GetAttLine() const override
Get line attributes.
Style_t GetFillStyle() const override
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.
void DrawFillArea(Int_t n, const Double_t *x, const Double_t *y) override
Paint filled area.
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.
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 DrawTextUrl(Double_t x, Double_t y, const char *text, const char *url) override
Paint text with url.
void DrawLine(Double_t x1, Double_t y1, Double_t x2, Double_t y2) override
Paint a simple line.
void SetOpacity(Int_t percent) override
Set opacity - similar to TVirtualPS usecase.
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