Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TText.cxx
Go to the documentation of this file.
1// @(#)root/graf:$Id$
2// Author: Nicolas Brun 12/12/94
3
4/*************************************************************************
5 * Copyright (C) 1995-2000, 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 "TText.h"
13
14#include "TROOT.h"
15#include "TBuffer.h"
16#include "TVirtualPad.h"
17#include "TVirtualPadPainter.h"
18#include "TVirtualX.h"
19#include "TMath.h"
20#include "TPoint.h"
21
22#include <cwchar>
23#include <cstdlib>
24#include <iostream>
25
26
27
28/** \class TText
29\ingroup BasicGraphics
30
31Base class for several text objects.
32
33See TAttText for a list of text attributes or fonts,
34and also for a discussion on text speed and font quality.
35
36By default, the text is drawn in the pad coordinates system.
37One can draw in NDC coordinates [0,1] if the function SetNDC
38is called for a TText object.
39
40Example:
41Begin_Macro(source)
42{
43 TText *t = new TText(.5,.5,"Hello World !");
44 t->SetTextAlign(22);
45 t->SetTextColor(kRed+2);
46 t->SetTextFont(43);
47 t->SetTextSize(40);
48 t->SetTextAngle(45);
49 t->Draw();
50}
51End_Macro
52*/
53
54////////////////////////////////////////////////////////////////////////////////
55/// Text normal constructor.
56
57TText::TText(Double_t x, Double_t y, const char *text) : TNamed("",text), TAttText(), fWcsTitle(nullptr)
58{
59 fX = x;
60 fY = y;
61}
62
63////////////////////////////////////////////////////////////////////////////////
64/// Text normal constructor.
65
67{
68 fX = x;
69 fY = y;
70 fWcsTitle = new std::wstring(text);
71 SetName("");
73}
74
75////////////////////////////////////////////////////////////////////////////////
76/// Text default destructor.
77
79{
80 if (fWcsTitle) delete reinterpret_cast<std::wstring *>(fWcsTitle);
81}
82
83////////////////////////////////////////////////////////////////////////////////
84/// Copy constructor.
85
86TText::TText(const TText &text) : TNamed(text), TAttText(text), TAttBBox2D(text), fWcsTitle(nullptr)
87{
88 text.TText::Copy(*this);
89}
90
91////////////////////////////////////////////////////////////////////////////////
92/// Assignment operator.
93
95{
96 src.TText::Copy(*this);
97 return *this;
98}
99
100////////////////////////////////////////////////////////////////////////////////
101/// Copy this text to text.
102
103void TText::Copy(TObject &obj) const
104{
105 ((TText&)obj).fX = fX;
106 ((TText&)obj).fY = fY;
107 TNamed::Copy(obj);
108 TAttText::Copy(((TText&)obj));
109 if (((TText&)obj).fWcsTitle) {
110 if (fWcsTitle) {
111 *reinterpret_cast<std::wstring*>(((TText&)obj).fWcsTitle) = *reinterpret_cast<const std::wstring*>(fWcsTitle);
112 } else {
113 delete reinterpret_cast<std::wstring*>(((TText&)obj).fWcsTitle);
114 ((TText&)obj).fWcsTitle = nullptr;
115 }
116 } else {
117 if (fWcsTitle) {
118 ((TText&)(obj)).fWcsTitle = new std::wstring(*reinterpret_cast<const std::wstring*>(fWcsTitle));
119 }
120 }
121}
122
123////////////////////////////////////////////////////////////////////////////////
124/// Returns the text as UNICODE.
125
126const void *TText::GetWcsTitle(void) const
127{
128 if (fWcsTitle) {
129 return reinterpret_cast<std::wstring *>(fWcsTitle)->c_str();
130 } else {
131 return nullptr;
132 }
133}
134
135////////////////////////////////////////////////////////////////////////////////
136/// Compute distance from point px,py to a string.
137/// The rectangle surrounding this string is evaluated.
138/// If the point (px,py) is in the rectangle, the distance is set to zero.
139
141{
142 if (!gPad) return 9999;
143 Int_t ptx, pty;
144
145 TAttText::Modify(); // change text attributes only if necessary
146
147 if (TestBit(kTextNDC)) {
148 ptx = gPad->UtoPixel(fX);
149 pty = gPad->VtoPixel(fY);
150 } else {
151 ptx = gPad->XtoAbsPixel(gPad->XtoPad(fX));
152 pty = gPad->YtoAbsPixel(gPad->YtoPad(fY));
153 }
154
155 // Get the text control box
156 Int_t cBoxX[5], cBoxY[5];
158 cBoxY[4] = cBoxY[0];
159 cBoxX[4] = cBoxX[0];
160
161 // Check if the point (px,py) is inside the text control box
162 if (TMath::IsInside(px, py, 5, cBoxX, cBoxY)){
163 return 0;
164 } else {
165 return 9999;
166 }
167}
168
169////////////////////////////////////////////////////////////////////////////////
170/// Draw this text with new coordinates.
171
173{
174 TText *newtext = new TText(x, y, text);
176 newtext->SetBit(kCanDelete);
177 if (TestBit(kTextNDC)) newtext->SetNDC();
178 newtext->AppendPad();
179 return newtext;
180}
181
182////////////////////////////////////////////////////////////////////////////////
183/// Draw this text with new coordinates.
184
186{
187 TText *newtext = new TText(x, y, text);
189 newtext->SetBit(kCanDelete);
190 if (TestBit(kTextNDC)) newtext->SetNDC();
191 newtext->AppendPad();
192 return newtext;
193}
194
195////////////////////////////////////////////////////////////////////////////////
196/// Draw this text with new coordinates in NDC.
197
199{
201 newtext->SetNDC();
202 return newtext;
203}
204
205////////////////////////////////////////////////////////////////////////////////
206/// Draw this text with new coordinates in NDC.
207
209{
211 newtext->SetNDC();
212 return newtext;
213}
214
215////////////////////////////////////////////////////////////////////////////////
216/// Execute action corresponding to one event.
217///
218/// This member function must be implemented to realize the action
219/// corresponding to the mouse click on the object in the window
220
222{
223 if (!gPad) return;
224
225 static Int_t px1, py1, pxold, pyold, Size, height, width;
226 static Bool_t resize,turn;
227 Int_t dx, dy;
228 const char *text = GetTitle();
229 Int_t len = strlen(text);
230 Double_t sizetowin = gPad->GetAbsHNDC()*Double_t(gPad->GetWh());
232 Int_t h = Int_t(fh/2);
233 Int_t w = h*len;
237 static Bool_t right, ndcsav;
238 static Double_t theta;
239 Int_t ax, ay, bx, by, cx, cy;
240 ax = ay = 0;
241 Double_t lambda, x2,y2;
243 Int_t cBoxX[4], cBoxY[4], part;
244 Double_t div = 0;
245 Bool_t opaque = gPad->OpaqueMoving();
246
247 if (!gPad->IsEditable()) return;
248 switch (event) {
249
250 case kArrowKeyPress:
251 case kButton1Down:
253 // No break !!!
254
255 case kMouseMotion:
256 if (TestBit(kTextNDC)) {
257 px1 = gPad->UtoPixel(fX);
258 py1 = gPad->VtoPixel(fY);
259 } else {
260 px1 = gPad->XtoAbsPixel(gPad->XtoPad(fX));
261 py1 = gPad->YtoAbsPixel(gPad->YtoPad(fY));
262 }
263 theta = fTextAngle;
264 Size = 0;
265 pxold = px;
266 pyold = py;
267 co = TMath::Cos(fTextAngle*0.017453293);
268 si = TMath::Sin(fTextAngle*0.017453293);
269 resize = kFALSE;
270 turn = kFALSE;
271 GetControlBox(px1, py1, -theta, cBoxX, cBoxY);
272 div = ((cBoxX[3]-cBoxX[0])*co-(cBoxY[3]-cBoxY[0])*si);
273 if (TMath::Abs(div) > 1e-8) part = (Int_t)(3*((px-cBoxX[0])*co-(py-cBoxY[0])*si)/ div);
274 else part = 0;
275 switch (part) {
276 case 0:
277 if (halign == 3) {
278 turn = kTRUE;
279 right = kTRUE;
280 gPad->SetCursor(kRotate);
281 } else {
282 resize = kTRUE;
283 height = valign;
284 width = halign;
285 gPad->SetCursor(kArrowVer);
286 }
287 break;
288 case 1:
289 gPad->SetCursor(kMove);
290 break;
291 case 2:
292 if (halign == 3) {
293 resize = kTRUE;
294 height = valign;
295 width = halign;
296 gPad->SetCursor(kArrowVer);
297 } else {
298 turn = kTRUE;
299 right = kFALSE;
300 gPad->SetCursor(kRotate);
301 }
302 }
303 break;
304
305 case kArrowKeyRelease:
306 case kButton1Motion:
307 if (!opaque) PaintControlBox(px1, py1, -theta);
308 if (turn) {
309 norm = TMath::Sqrt(Double_t((py-py1)*(py-py1)+(px-px1)*(px-px1)));
310 if (norm>0) {
311 theta = TMath::ACos((px-px1)/norm);
312 dtheta= TMath::ASin((py1-py)/norm);
313 if (dtheta<0) theta = -theta;
314 theta = theta/TMath::Pi()*180;
315 if (theta<0) theta += 360;
316 if (right) {theta = theta+180; if (theta>=360) theta -= 360;}
317 }
318 } else if (resize) {
319
320 co = TMath::Cos(fTextAngle*0.017453293);
321 si = TMath::Sin(fTextAngle*0.017453293);
322 if (width == 1) {
323 switch (valign) {
324 case 1 : ax = px1; ay = py1; break;
325 case 2 : ax = px1+Int_t(si*h/2); ay = py1+Int_t(co*h/2); break;
326 case 3 : ax = px1+Int_t(si*h*3/2); ay = py1+Int_t(co*h*3/2); break;
327 }
328 }
329 if (width == 2) {
330 switch (valign) {
331 case 1 : ax = px1-Int_t(co*w/2); ay = py1+Int_t(si*w/2); break;
332 case 2 : ax = px1-Int_t(co*w/2+si*h/2); ay = py1+Int_t(si*w/2+co*h/2); break;
333 case 3 : ax = px1-Int_t(co*w/2+si*h*3/2); ay = py1+Int_t(si*w/2+co*h*3/2); break;
334 }
335 }
336 if (width == 3) {
337 switch (valign) {
338 case 1 : ax = px1-Int_t(co*w); ay = py1+Int_t(si*w); break;
339 case 2 : ax = px1-Int_t(co*w+si*h/2); ay = py1+Int_t(si*w+co*h/2); break;
340 case 3 : ax = px1-Int_t(co*w+si*h*3/2); ay = py1+Int_t(si*w+co*h*3/2); break;
341 }
342 }
343 if (height == 3) {bx = ax-Int_t(si*h); by = ay-Int_t(co*h);}
344 else {bx = ax; by = ay;}
345 cx = bx+Int_t(co*w); cy = by-Int_t(si*w);
346 lambda = Double_t(((px-bx)*(cx-bx)+(py-by)*(cy-by)))/Double_t(((cx-bx)*(cx-bx)+(cy-by)*(cy-by)));
347 x2 = Double_t(px) - lambda*Double_t(cx-bx)-Double_t(bx);
348 y2 = Double_t(py) - lambda*Double_t(cy-by)-Double_t(by);
349 Size = Int_t(TMath::Sqrt(x2*x2+y2*y2)*2);
350 if (Size<4) Size = 4;
351
354 } else {
355 dx = px - pxold; px1 += dx;
356 dy = py - pyold; py1 += dy;
357 }
358 if (opaque) {
359 if (ndcsav) this->SetNDC(kFALSE);
360 this->SetX(gPad->PadtoX(gPad->AbsPixeltoX(px1)));
361 this->SetY(gPad->PadtoY(gPad->AbsPixeltoY(py1)));
362 if (resize) gPad->ShowGuidelines(this, event, 't', false);
363 if ((!resize)&&(!turn)) gPad->ShowGuidelines(this, event, 'i', true);
364 gPad->ShowGuidelines(this, event, !resize&!turn);
365 this->SetTextAngle(theta);
366 gPad->Modified(kTRUE);
367 gPad->Update();
368 }
369 if (!opaque) PaintControlBox(px1, py1, -theta);
370 pxold = px; pyold = py;
371 break;
372
373 case kButton1Up:
374 if (opaque) {
375 if (ndcsav && !this->TestBit(kTextNDC)) {
376 this->SetX((fX - gPad->GetX1())/(gPad->GetX2()-gPad->GetX1()));
377 this->SetY((fY - gPad->GetY1())/(gPad->GetY2()-gPad->GetY1()));
378 this->SetNDC();
379 }
380 gPad->ShowGuidelines(this, event, !resize&!turn);
381 } else {
382 if (TestBit(kTextNDC)) {
383 dpx = gPad->GetX2() - gPad->GetX1();
384 dpy = gPad->GetY2() - gPad->GetY1();
385 xp1 = gPad->GetX1();
386 yp1 = gPad->GetY1();
387 fX = (gPad->AbsPixeltoX(px1)-xp1)/dpx;
388 fY = (gPad->AbsPixeltoY(py1)-yp1)/dpy;
389 } else {
390 fX = gPad->PadtoX(gPad->AbsPixeltoX(px1));
391 fY = gPad->PadtoY(gPad->AbsPixeltoY(py1));
392 }
393 fTextAngle = theta;
394 }
395 gPad->Modified(kTRUE);
396 break;
397
398 case kButton1Locate:
399 ExecuteEvent(kButton1Down, px, py);
400
401 while (1) {
402 px = py = 0;
403 event = gVirtualX->RequestLocator(1, 1, px, py);
404
406
407 if (event != -1) { // button is released
408 ExecuteEvent(kButton1Up, px, py);
409 return;
410 }
411 }
412 }
413}
414
415////////////////////////////////////////////////////////////////////////////////
416/// Return the text control box. The text position coordinates is (x,y) and
417/// the text angle is theta. The control box coordinates are returned in cBoxX
418/// and cBoxY.
419
421 Int_t cBoxX[4], Int_t cBoxY[4])
422{
423 Short_t halign = fTextAlign/10; // horizontal alignment
424 Short_t valign = fTextAlign - 10*halign; // vertical alignment
425 UInt_t cBoxW, cBoxH; // control box width and heigh
426 UInt_t Dx = 0, Dy = 0; // delta along x and y to align the box
427
429
430 // compute the translations (Dx, Dy) required by the alignments
431 switch (halign) {
432 case 1 : Dx = 0 ; break;
433 case 2 : Dx = cBoxW/2; break;
434 case 3 : Dx = cBoxW ; break;
435 }
436 switch (valign) {
437 case 1 : Dy = 0 ; break;
438 case 2 : Dy = cBoxH/2; break;
439 case 3 : Dy = cBoxH ; break;
440 }
441
442 // compute the control box coordinates before rotation
443 cBoxX[0] = x-Dx;
444 cBoxY[0] = y+Dy;
445 cBoxX[1] = x-Dx;
446 cBoxY[1] = y-cBoxH+Dy;
447 cBoxX[2] = x+cBoxW-Dx;
448 cBoxY[2] = y-cBoxH+Dy;
449 cBoxX[3] = x+cBoxW-Dx;
450 cBoxY[3] = y+Dy;
451
452 // rotate the control box if needed
453 if (theta) {
454 Double_t cosTheta = TMath::Cos(theta*0.017453293);
455 Double_t sinTheta = TMath::Sin(theta*0.017453293);
456 for (int i=0; i<4 ; i++) {
457 Int_t hcBoxX = cBoxX[i];
458 Int_t hcBoxY = cBoxY[i];
461 }
462 }
463}
464
465////////////////////////////////////////////////////////////////////////////////
466/// Return text size in pixels. By default the size returned does not take
467/// into account the text angle (angle = kFALSE). If angle is set to kTRUE
468/// w and h take the angle into account.
469
471{
472 const char *text = GetTitle();
473 if (!text[0]) {
474 w = h = 0;
475 return;
476 }
477
478 if (!gPad)
479 return;
480 if (angle) {
481 Int_t cBoxX[4], cBoxY[4];
482 Int_t ptx, pty;
483 if (TestBit(kTextNDC)) {
484 ptx = gPad->UtoPixel(fX);
485 pty = gPad->VtoPixel(fY);
486 } else {
487 ptx = gPad->XtoAbsPixel(gPad->XtoPad(fX));
488 pty = gPad->YtoAbsPixel(gPad->YtoPad(fY));
489 }
491 Int_t x1 = cBoxX[0];
492 Int_t x2 = cBoxX[0];
493 Int_t y1 = cBoxY[0];
494 Int_t y2 = cBoxY[0];
495 for (Int_t i=1; i<4; i++) {
496 if (cBoxX[i] < x1) x1 = cBoxX[i];
497 if (cBoxX[i] > x2) x2 = cBoxX[i];
498 if (cBoxY[i] < y1) y1 = cBoxY[i];
499 if (cBoxY[i] > y2) y2 = cBoxY[i];
500 }
501 w = x2-x1;
502 h = y2-y1;
503 } else {
505 auto pp = gPad->GetPainter();
506 if (pp)
507 pp->GetTextExtent(GetTextFont(), tsize, w, h, GetTitle());
508 }
509}
510
511////////////////////////////////////////////////////////////////////////////////
512/// Return text ascent and descent for string text
513/// - in a return total text ascent
514/// - in d return text descent
515
516void TText::GetTextAscentDescent(UInt_t &a, UInt_t &d, const char *text) const
517{
518 if (!gPad)
519 return;
520
522
523 auto pp = gPad->GetPainter();
524 if (pp)
525 pp->GetTextAscentDescent(GetTextFont(), tsize, a, d, text);
526}
527
528
529////////////////////////////////////////////////////////////////////////////////
530/// Return text ascent and descent for string text
531/// - in a return total text ascent
532/// - in d return text descent
533
534void TText::GetTextAscentDescent(UInt_t &a, UInt_t &d, const wchar_t *text) const
535{
536 if (!gPad)
537 return;
538
540
541 auto pp = gPad->GetPainter();
542 if (pp)
543 pp->GetTextAscentDescent(GetTextFont(), tsize, a, d, text);
544}
545
546////////////////////////////////////////////////////////////////////////////////
547/// Return text extent for string text
548/// - in w return total text width
549/// - in h return text height
550
551void TText::GetTextExtent(UInt_t &w, UInt_t &h, const char *text) const
552{
553 if (!gPad)
554 return;
555
557
558 auto pp = gPad->GetPainter();
559 if (pp)
560 pp->GetTextExtent(GetTextFont(), tsize, w, h, text);
561}
562
563////////////////////////////////////////////////////////////////////////////////
564/// Return text advance for string text
565/// if kern is true (default) kerning is taken into account. If it is false
566/// the kerning is not taken into account.
567
568void TText::GetTextAdvance(UInt_t &a, const char *text, const Bool_t kern) const
569{
570 if (!gPad)
571 return;
572
574
575 auto pp = gPad->GetPainter();
576 if (pp)
577 a = pp->GetTextAdvance(GetTextFont(), tsize, text, kern);
578}
579
580////////////////////////////////////////////////////////////////////////////////
581/// Return text extent for string text
582/// - in w return total text width
583/// - in h return text height
584
585void TText::GetTextExtent(UInt_t &w, UInt_t &h, const wchar_t *text) const
586{
587 if (!gPad)
588 return;
589
591
592 auto pp = gPad->GetPainter();
593 if (pp)
594 pp->GetTextExtent(GetTextFont(), tsize, w, h, text);
595}
596
597////////////////////////////////////////////////////////////////////////////////
598/// List this text with its attributes.
599
600void TText::ls(Option_t *) const
601{
603 printf("Text X=%f Y=%f Text=%s\n",fX,fY,GetTitle());
604}
605
606////////////////////////////////////////////////////////////////////////////////
607/// Paint this text with its current attributes.
608
610{
611 if (!gPad) return;
612 TAttText::Modify(); //Change text attributes only if necessary
613 if (TestBit(kTextNDC)) gPad->PaintTextNDC(fX,fY,GetTitle());
614 else gPad->PaintText(gPad->XtoPad(fX),gPad->YtoPad(fY),GetTitle());
615}
616
617////////////////////////////////////////////////////////////////////////////////
618/// Paint the text control box. (x,y) are the coordinates where the control
619/// box should be painted and theta is the angle of the box.
620
622{
623 Int_t cBoxX[4], cBoxY[4];
624 Short_t halign = fTextAlign/10; // horizontal alignment
625 Short_t valign = fTextAlign - 10*halign; // vertical alignment
626
627 GetControlBox(x, y, theta, cBoxX, cBoxY);
628 // Draw the text control box outline
629 gVirtualX->SetLineStyle((Style_t)1);
630 gVirtualX->SetLineWidth(1);
631 gVirtualX->SetLineColor(1);
632 gVirtualX->DrawLine(cBoxX[0], cBoxY[0], cBoxX[1], cBoxY[1]);
633 gVirtualX->DrawLine(cBoxX[1], cBoxY[1], cBoxX[2], cBoxY[2]);
634 gVirtualX->DrawLine(cBoxX[2], cBoxY[2], cBoxX[3], cBoxY[3]);
635 gVirtualX->DrawLine(cBoxX[3], cBoxY[3], cBoxX[0], cBoxY[0]);
636
637 // Draw a symbol at the text starting point
638 TPoint p;
639 Int_t ix = 0, iy = 0;
640 switch (halign) {
641 case 1 :
642 switch (valign) {
643 case 1 : ix = 0 ; iy = 0 ; break;
644 case 2 : ix = 0 ; iy = 1 ; break;
645 case 3 : ix = 1 ; iy = 1 ; break;
646 }
647 break;
648 case 2 :
649 switch (valign) {
650 case 1 : ix = 0 ; iy = 3 ; break;
651 case 2 : ix = 0 ; iy = 2 ; break;
652 case 3 : ix = 1 ; iy = 2 ; break;
653 }
654 break;
655 case 3 :
656 switch (valign) {
657 case 1 : ix = 3 ; iy = 3 ; break;
658 case 2 : ix = 2 ; iy = 3 ; break;
659 case 3 : ix = 2 ; iy = 2 ; break;
660 }
661 break;
662 }
663 p.fX = (cBoxX[ix]+cBoxX[iy])/2;
664 p.fY = (cBoxY[ix]+cBoxY[iy])/2;
665 gVirtualX->SetMarkerColor(1);
666 gVirtualX->SetMarkerStyle(24);
667 gVirtualX->SetMarkerSize(0.7);
668 gVirtualX->DrawPolyMarker(1, &p);
669}
670
671////////////////////////////////////////////////////////////////////////////////
672/// Draw this text with new coordinates.
673
675{
676 TAttText::Modify(); //Change text attributes only if necessary
677 if (gPad) gPad->PaintText(x,y,text);
678}
679
680////////////////////////////////////////////////////////////////////////////////
681/// Draw this text with new coordinates.
682
683void TText::PaintText(Double_t x, Double_t y, const wchar_t *text)
684{
685 TAttText::Modify(); //Change text attributes only if necessary
686 if (gPad) gPad->PaintText(x,y,text);
687}
688
689////////////////////////////////////////////////////////////////////////////////
690/// Draw this text with new coordinates in NDC.
691
693{
694 TAttText::Modify(); //Change text attributes only if necessary
695 if (gPad) gPad->PaintTextNDC(u,v,text);
696}
697
698////////////////////////////////////////////////////////////////////////////////
699/// Draw this text with new coordinates in NDC.
700
702{
703 TAttText::Modify(); //Change text attributes only if necessary
704 if (gPad) gPad->PaintTextNDC(u,v,text);
705}
706
707////////////////////////////////////////////////////////////////////////////////
708/// Dump this text with its attributes.
709
711{
712 printf("Text X=%f Y=%f Text=%s Font=%d Size=%f",fX,fY,GetTitle(),GetTextFont(),GetTextSize());
713 if (GetTextColor() != 1 ) printf(" Color=%d",GetTextColor());
714 if (GetTextAlign() != 10) printf(" Align=%d",GetTextAlign());
715 if (GetTextAngle() != 0 ) printf(" Angle=%f",GetTextAngle());
716 printf("\n");
717}
718
719////////////////////////////////////////////////////////////////////////////////
720/// Save primitive as a C++ statement(s) on output stream out
721
722void TText::SavePrimitive(std::ostream &out, Option_t *option)
723{
725 out, Class(), "text",
726 TString::Format("%g, %g, \"%s\"", fX, fY, TString(GetTitle()).ReplaceSpecialCppChars().Data()), kFALSE);
727
728 SaveTextAttributes(out, "text", 11, 0, 1, 62, 0.05);
729
730 if (TestBit(kTextNDC))
731 out << " text->SetNDC();\n";
732
733 SavePrimitiveDraw(out, "text", option);
734}
735
736////////////////////////////////////////////////////////////////////////////////
737/// Set NDC mode on if isNDC = kTRUE, off otherwise
738
743
744////////////////////////////////////////////////////////////////////////////////
745/// Change (i.e. set) the title of the TNamed.
746
747void TText::SetMbTitle(const wchar_t *title)
748{
749 char *mb_title = new char[MB_CUR_MAX * wcslen(title) + 1]();
750 char *p = mb_title;
751 size_t length = wcslen(title);
752 for (size_t i = 0; i < length; i++) {
753 const int n = wctomb(p, title[i]);
754 if (n >= 0) p += n;
755 }
757 delete [] mb_title;
758 if (gPad && TestBit(kMustCleanup)) gPad->Modified();
759}
760
761////////////////////////////////////////////////////////////////////////////////
762/// Stream an object of class TText.
763
765{
766 if (R__b.IsReading()) {
768 Version_t R__v = R__b.ReadVersion(&R__s, &R__c);
769 if (R__v > 1) {
770 R__b.ReadClassBuffer(TText::Class(), this, R__v, R__s, R__c);
771 return;
772 }
773 //====process old versions before automatic schema evolution
776 Float_t x,y;
777 R__b >> x; fX = x;
778 R__b >> y; fY = y;
779 //====end of old versions
780
781 } else {
782 R__b.WriteClassBuffer(TText::Class(),this);
783 }
784}
785////////////////////////////////////////////////////////////////////////////////
786/// Return the "bounding Box" of the Box
787
789{
790 Rectangle_t BBox{0, 0, 0, 0};
791 if (gPad) {
792 UInt_t w, h;
793 Int_t Dx = 0, Dy = 0;
794 GetBoundingBox(w, h, false);
795
798
799 switch (halign) {
800 case 1: Dx = 0; break;
801 case 2: Dx = w / 2; break;
802 case 3: Dx = w; break;
803 }
804
805 switch (valign) {
806 case 1: Dy = h; break;
807 case 2: Dy = h / 2; break;
808 case 3: Dy = 0; break;
809 }
810
811 BBox.fX = gPad->XtoPixel(fX) - Dx;
812 BBox.fY = gPad->YtoPixel(fY) - Dy;
813 BBox.fWidth = w;
814 BBox.fHeight = h;
815 }
816 return BBox;
817}
818
819////////////////////////////////////////////////////////////////////////////////
820/// Return the point given by Alignment as 'center'
821
823{
824 TPoint p(0, 0);
825 if (gPad) {
826 p.SetX(gPad->XtoPixel(fX));
827 p.SetY(gPad->YtoPixel(fY));
828 }
829 return p;
830}
831
832////////////////////////////////////////////////////////////////////////////////
833/// Set the point given by Alignment as 'center'
834
836{
837 if (!gPad) return;
838 this->SetX(gPad->PixeltoX(p.GetX()));
839 this->SetY(gPad->PixeltoY(p.GetY()-gPad->VtoPixel(0)));
840}
841
842////////////////////////////////////////////////////////////////////////////////
843/// Set X coordinate of the point given by Alignment as 'center'
844
846{
847 if (!gPad) return;
848 this->SetX(gPad->PixeltoX(x));
849}
850
851////////////////////////////////////////////////////////////////////////////////
852/// Set Y coordinate of the point given by Alignment as 'center'
853
855{
856 if (!gPad) return;
857 this->SetY(gPad->PixeltoY(y - gPad->VtoPixel(0)));
858}
859
860////////////////////////////////////////////////////////////////////////////////
861/// Set left hand side of BoundingBox to a value
862/// (resize in x direction on left)
863
864void TText::SetBBoxX1(const Int_t /*x*/)
865{
866 //NOT IMPLEMENTED
867}
868
869////////////////////////////////////////////////////////////////////////////////
870/// Set right hand side of BoundingBox to a value
871/// (resize in x direction on right)
872
873void TText::SetBBoxX2(const Int_t /*x*/)
874{
875 //NOT IMPLEMENTED
876}
877
878////////////////////////////////////////////////////////////////////////////////
879/// Set top of BoundingBox to a value (resize in y direction on top)
880
881void TText::SetBBoxY1(const Int_t /*y*/)
882{
883 //NOT IMPLEMENTED
884}
885
886////////////////////////////////////////////////////////////////////////////////
887/// Set bottom of BoundingBox to a value
888/// (resize in y direction on bottom)
889
890void TText::SetBBoxY2(const Int_t /*y*/)
891{
892 //NOT IMPLEMENTED
893}
@ kMouseMotion
Definition Buttons.h:23
@ kArrowKeyRelease
Definition Buttons.h:21
@ kButton1Motion
Definition Buttons.h:20
@ kButton1Up
Definition Buttons.h:19
@ kArrowKeyPress
Definition Buttons.h:21
@ kButton1Down
Definition Buttons.h:17
@ kButton1Locate
Definition Buttons.h:22
@ kArrowVer
Definition GuiTypes.h:375
@ kMove
Definition GuiTypes.h:375
@ kRotate
Definition GuiTypes.h:375
#define d(i)
Definition RSha256.hxx:102
#define a(i)
Definition RSha256.hxx:99
#define h(i)
Definition RSha256.hxx:106
#define e(i)
Definition RSha256.hxx:103
short Style_t
Style number (short)
Definition RtypesCore.h:96
int Int_t
Signed integer 4 bytes (int)
Definition RtypesCore.h:59
short Version_t
Class version identifier (short)
Definition RtypesCore.h:79
float Float_t
Float 4 bytes (float)
Definition RtypesCore.h:71
short Short_t
Signed Short integer 2 bytes (short)
Definition RtypesCore.h:53
constexpr Bool_t kFALSE
Definition RtypesCore.h:108
double Double_t
Double 8 bytes.
Definition RtypesCore.h:73
constexpr Bool_t kTRUE
Definition RtypesCore.h:107
const char Option_t
Option string (const char)
Definition RtypesCore.h:80
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
winID h TVirtualViewer3D TVirtualGLPainter p
Option_t Option_t option
Option_t Option_t SetTextSize
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 length
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 UChar_t len
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 TPoint const char y2
Option_t Option_t width
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t src
Option_t Option_t TPoint TPoint DrawText
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t height
Option_t Option_t TPoint TPoint const char text
Option_t Option_t TPoint TPoint const char y1
#define gPad
#define gVirtualX
Definition TVirtualX.h:375
Abstract base class for elements drawn in the editor.
Definition TAttBBox2D.h:19
Text Attributes class.
Definition TAttText.h:21
virtual Float_t GetTextSize() const
Return the text size.
Definition TAttText.h:39
virtual void Modify()
Change current text attributes if necessary.
Definition TAttText.cxx:364
virtual Short_t GetTextAlign() const
Return the text alignment.
Definition TAttText.h:35
virtual Font_t GetTextFont() const
Return the text font.
Definition TAttText.h:38
Float_t fTextAngle
Text angle.
Definition TAttText.h:24
virtual Color_t GetTextColor() const
Return the text color.
Definition TAttText.h:37
virtual void Streamer(TBuffer &)
virtual void SetTextAngle(Float_t tangle=0)
Set the text angle.
Definition TAttText.h:49
virtual Float_t GetTextAngle() const
Return the text angle.
Definition TAttText.h:36
virtual void SaveTextAttributes(std::ostream &out, const char *name, Int_t alidef=12, Float_t angdef=0, Int_t coldef=1, Int_t fondef=61, Float_t sizdef=1)
Save text attributes as C++ statement(s) on output stream out.
Definition TAttText.cxx:399
Short_t fTextAlign
Text alignment.
Definition TAttText.h:26
void Copy(TAttText &atttext) const
Copy this text attributes to a new TAttText.
Definition TAttText.cxx:300
virtual Float_t GetTextSizePixels(TVirtualPad &pad) const
Return the text size in pixels for specified pad.
Definition TAttText.cxx:350
Float_t fTextSize
Text size.
Definition TAttText.h:25
Buffer base class used for serializing objects.
Definition TBuffer.h:43
The TNamed class is the base class for all named ROOT classes.
Definition TNamed.h:29
void Copy(TObject &named) const override
Copy this to obj.
Definition TNamed.cxx:93
void Streamer(TBuffer &) override
Stream an object of class TObject.
const char * GetTitle() const override
Returns title of object.
Definition TNamed.h:50
TString fTitle
Definition TNamed.h:33
virtual void SetName(const char *name)
Set the name of the TNamed.
Definition TNamed.cxx:149
Mother of all ROOT objects.
Definition TObject.h:42
R__ALWAYS_INLINE Bool_t TestBit(UInt_t f) const
Definition TObject.h:204
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
Definition TObject.cxx:885
static void SavePrimitiveDraw(std::ostream &out, const char *variable_name, Option_t *option=nullptr)
Save invocation of primitive Draw() method Skipped if option contains "nodraw" string.
Definition TObject.cxx:842
static void SavePrimitiveConstructor(std::ostream &out, TClass *cl, const char *variable_name, const char *constructor_agrs="", Bool_t empty_line=kTRUE)
Save object constructor in the output stream "out".
Definition TObject.cxx:774
@ kCanDelete
if object in a list can be deleted
Definition TObject.h:71
@ kMustCleanup
if object destructor must call RecursiveRemove()
Definition TObject.h:73
SCoord_t GetY() const
Definition TPoint.h:47
SCoord_t GetX() const
Definition TPoint.h:46
static void IndentLevel()
Functions used by ls() to indent an object hierarchy.
Definition TROOT.cxx:3052
Basic string class.
Definition TString.h:138
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString.
Definition TString.cxx:2385
Base class for several text objects.
Definition TText.h:22
Double_t fY
Y position of text (left,center,etc..)
Definition TText.h:26
const void * GetWcsTitle(void) const
Returns the text as UNICODE.
Definition TText.cxx:126
void SetBBoxCenter(const TPoint &p) override
Set the point given by Alignment as 'center'.
Definition TText.cxx:835
Rectangle_t GetBBox() override
Return the "bounding Box" of the Box.
Definition TText.cxx:788
void Copy(TObject &text) const override
Copy this text to text.
Definition TText.cxx:103
TText & operator=(const TText &src)
Assignment operator.
Definition TText.cxx:94
@ kTextNDC
The text position is in the NDC space.
Definition TText.h:32
virtual void GetBoundingBox(UInt_t &w, UInt_t &h, Bool_t angle=kFALSE)
Return text size in pixels.
Definition TText.cxx:470
virtual void SetY(Double_t y)
Definition TText.h:77
virtual void PaintControlBox(Int_t x, Int_t y, Double_t theta)
Paint the text control box.
Definition TText.cxx:621
virtual TText * DrawText(Double_t x, Double_t y, const char *text)
Draw this text with new coordinates.
Definition TText.cxx:172
void * fWcsTitle
!Used by TMathText
Definition TText.h:27
Double_t fX
X position of text (left,center,etc..)
Definition TText.h:25
~TText() override
Text default destructor.
Definition TText.cxx:78
virtual void PaintTextNDC(Double_t u, Double_t v, const char *text)
Draw this text with new coordinates in NDC.
Definition TText.cxx:692
void SavePrimitive(std::ostream &out, Option_t *option="") override
Save primitive as a C++ statement(s) on output stream out.
Definition TText.cxx:722
void ls(Option_t *option="") const override
List this text with its attributes.
Definition TText.cxx:600
virtual void PaintText(Double_t x, Double_t y, const char *text)
Draw this text with new coordinates.
Definition TText.cxx:674
TText()
Definition TText.h:35
void SetBBoxY2(const Int_t) override
Set bottom of BoundingBox to a value (resize in y direction on bottom)
Definition TText.cxx:890
virtual void GetTextExtent(UInt_t &w, UInt_t &h, const char *text) const
Return text extent for string text.
Definition TText.cxx:551
virtual void GetTextAscentDescent(UInt_t &a, UInt_t &d, const char *text) const
Return text ascent and descent for string text.
Definition TText.cxx:516
Int_t DistancetoPrimitive(Int_t px, Int_t py) override
Compute distance from point px,py to a string.
Definition TText.cxx:140
TPoint GetBBoxCenter() override
Return the point given by Alignment as 'center'.
Definition TText.cxx:822
virtual void SetX(Double_t x)
Definition TText.h:76
virtual void GetTextAdvance(UInt_t &a, const char *text, const Bool_t kern=kTRUE) const
Return text advance for string text if kern is true (default) kerning is taken into account.
Definition TText.cxx:568
void Paint(Option_t *option="") override
Paint this text with its current attributes.
Definition TText.cxx:609
void SetBBoxCenterY(const Int_t y) override
Set Y coordinate of the point given by Alignment as 'center'.
Definition TText.cxx:854
virtual void SetNDC(Bool_t isNDC=kTRUE)
Set NDC mode on if isNDC = kTRUE, off otherwise.
Definition TText.cxx:739
void Print(Option_t *option="") const override
Dump this text with its attributes.
Definition TText.cxx:710
void SetBBoxY1(const Int_t) override
Set top of BoundingBox to a value (resize in y direction on top)
Definition TText.cxx:881
virtual void GetControlBox(Int_t x, Int_t y, Double_t theta, Int_t cBoxX[4], Int_t cBoxY[4])
Return the text control box.
Definition TText.cxx:420
void SetBBoxX2(const Int_t) override
Set right hand side of BoundingBox to a value (resize in x direction on right)
Definition TText.cxx:873
void SetBBoxCenterX(const Int_t x) override
Set X coordinate of the point given by Alignment as 'center'.
Definition TText.cxx:845
void SetBBoxX1(const Int_t) override
Set left hand side of BoundingBox to a value (resize in x direction on left)
Definition TText.cxx:864
void Streamer(TBuffer &) override
Stream an object of class TText.
Definition TText.cxx:764
virtual TText * DrawTextNDC(Double_t x, Double_t y, const char *text)
Draw this text with new coordinates in NDC.
Definition TText.cxx:198
static TClass * Class()
virtual void SetMbTitle(const wchar_t *title=L"")
Change (i.e. set) the title of the TNamed.
Definition TText.cxx:747
void ExecuteEvent(Int_t event, Int_t px, Int_t py) override
Execute action corresponding to one event.
Definition TText.cxx:221
Double_t y[n]
Definition legend1.C:17
Double_t x[n]
Definition legend1.C:17
const Int_t n
Definition legend1.C:16
Double_t ACos(Double_t)
Returns the principal value of the arc cosine of x, expressed in radians.
Definition TMath.h:643
Bool_t IsInside(T xp, T yp, Int_t np, T *x, T *y)
Function which returns kTRUE if point xp,yp lies inside the polygon defined by the np points in array...
Definition TMath.h:1320
Double_t ASin(Double_t)
Returns the principal value of the arc sine of x, expressed in radians.
Definition TMath.h:635
Double_t Sqrt(Double_t x)
Returns the square root of x.
Definition TMath.h:673
Double_t Cos(Double_t)
Returns the cosine of an angle of x radians.
Definition TMath.h:605
constexpr Double_t Pi()
Definition TMath.h:40
Double_t Sin(Double_t)
Returns the sine of an angle of x radians.
Definition TMath.h:599
Short_t Abs(Short_t d)
Returns the absolute value of parameter Short_t d.
Definition TMathBase.h:122
Rectangle structure (maps to the X11 XRectangle structure)
Definition GuiTypes.h:362