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 "TCanvasImp.h"
19#include "TMath.h"
20#include "TAttMarker.h"
21#include "TPoint.h"
22
23#include <cwchar>
24#include <cstdlib>
25#include <iostream>
26
27
28
29/** \class TText
30\ingroup BasicGraphics
31
32Base class for several text objects.
33
34See TAttText for a list of text attributes or fonts,
35and also for a discussion on text speed and font quality.
36
37By default, the text is drawn in the pad coordinates system.
38One can draw in NDC coordinates [0,1] if the function SetNDC
39is called for a TText object.
40
41Example:
42Begin_Macro(source)
43{
44 TText *t = new TText(.5,.5,"Hello World !");
45 t->SetTextAlign(22);
46 t->SetTextColor(kRed+2);
47 t->SetTextFont(43);
48 t->SetTextSize(40);
49 t->SetTextAngle(45);
50 t->Draw();
51}
52End_Macro
53*/
54
55////////////////////////////////////////////////////////////////////////////////
56/// Text normal constructor.
57
58TText::TText(Double_t x, Double_t y, const char *text) : TNamed("",text), TAttText(), fWcsTitle(nullptr)
59{
60 fX = x;
61 fY = y;
62}
63
64////////////////////////////////////////////////////////////////////////////////
65/// Text normal constructor.
66
68{
69 fX = x;
70 fY = y;
71 fWcsTitle = new std::wstring(text);
72 SetName("");
74}
75
76////////////////////////////////////////////////////////////////////////////////
77/// Text default destructor.
78
80{
81 if (fWcsTitle) delete reinterpret_cast<std::wstring *>(fWcsTitle);
82}
83
84////////////////////////////////////////////////////////////////////////////////
85/// Copy constructor.
86
87TText::TText(const TText &text) : TNamed(text), TAttText(text), TAttBBox2D(text), fWcsTitle(nullptr)
88{
89 text.TText::Copy(*this);
90}
91
92////////////////////////////////////////////////////////////////////////////////
93/// Assignment operator.
94
96{
97 src.TText::Copy(*this);
98 return *this;
99}
100
101////////////////////////////////////////////////////////////////////////////////
102/// Copy this text to text.
103
104void TText::Copy(TObject &obj) const
105{
106 ((TText&)obj).fX = fX;
107 ((TText&)obj).fY = fY;
108 TNamed::Copy(obj);
109 TAttText::Copy(((TText&)obj));
110 if (((TText&)obj).fWcsTitle) {
111 if (fWcsTitle) {
112 *reinterpret_cast<std::wstring*>(((TText&)obj).fWcsTitle) = *reinterpret_cast<const std::wstring*>(fWcsTitle);
113 } else {
114 delete reinterpret_cast<std::wstring*>(((TText&)obj).fWcsTitle);
115 ((TText&)obj).fWcsTitle = nullptr;
116 }
117 } else {
118 if (fWcsTitle) {
119 ((TText&)(obj)).fWcsTitle = new std::wstring(*reinterpret_cast<const std::wstring*>(fWcsTitle));
120 }
121 }
122}
123
124////////////////////////////////////////////////////////////////////////////////
125/// Returns the text as UNICODE.
126
127const void *TText::GetWcsTitle(void) const
128{
129 if (fWcsTitle) {
130 return reinterpret_cast<std::wstring *>(fWcsTitle)->c_str();
131 } else {
132 return nullptr;
133 }
134}
135
136////////////////////////////////////////////////////////////////////////////////
137/// Compute distance from point px,py to a string.
138/// The rectangle surrounding this string is evaluated.
139/// If the point (px,py) is in the rectangle, the distance is set to zero.
140
142{
143 if (!gPad) return 9999;
144 Int_t ptx, pty;
145
146 if (TestBit(kTextNDC)) {
147 ptx = gPad->UtoAbsPixel(fX);
148 pty = gPad->VtoAbsPixel(fY);
149 } else {
150 ptx = gPad->XtoAbsPixel(gPad->XtoPad(fX));
151 pty = gPad->YtoAbsPixel(gPad->YtoPad(fY));
152 }
153
154 // Get the text control box
155 Int_t cBoxX[5], cBoxY[5];
157 cBoxY[4] = cBoxY[0];
158 cBoxX[4] = cBoxX[0];
159
160 // Check if the point (px,py) is inside the text control box
161 if (TMath::IsInside(px, py, 5, cBoxX, cBoxY)){
162 return 0;
163 } else {
164 return 9999;
165 }
166}
167
168////////////////////////////////////////////////////////////////////////////////
169/// Draw this text with new coordinates.
170
172{
173 TText *newtext = new TText(x, y, text);
175 newtext->SetBit(kCanDelete);
176 if (TestBit(kTextNDC)) newtext->SetNDC();
177 newtext->AppendPad();
178 return newtext;
179}
180
181////////////////////////////////////////////////////////////////////////////////
182/// Draw this text with new coordinates.
183
185{
186 TText *newtext = new TText(x, y, text);
188 newtext->SetBit(kCanDelete);
189 if (TestBit(kTextNDC)) newtext->SetNDC();
190 newtext->AppendPad();
191 return newtext;
192}
193
194////////////////////////////////////////////////////////////////////////////////
195/// Draw this text with new coordinates in NDC.
196
198{
200 newtext->SetNDC();
201 return newtext;
202}
203
204////////////////////////////////////////////////////////////////////////////////
205/// Draw this text with new coordinates in NDC.
206
208{
210 newtext->SetNDC();
211 return newtext;
212}
213
214////////////////////////////////////////////////////////////////////////////////
215/// Execute action corresponding to one event.
216///
217/// This member function must be implemented to realize the action
218/// corresponding to the mouse click on the object in the window
219
221{
222 if (!gPad || !gPad->IsEditable())
223 return;
224
225 auto &parent = *gPad;
226
227 static Int_t px1, py1, pxold, pyold, height, width;
228 static Bool_t resize, turn, right;
229 static Double_t theta;
230 Short_t halign = GetTextAlign() / 10;
231 Short_t valign = GetTextAlign() % 10;
232 Bool_t opaque = parent.OpaqueMoving();
233
234 switch (event) {
235
236 case kArrowKeyPress:
237 case kButton1Down:
238 case kMouseMotion: {
239 if (TestBit(kTextNDC)) {
240 px1 = parent.UtoAbsPixel(fX);
241 py1 = parent.VtoAbsPixel(fY);
242 } else {
243 px1 = parent.XtoAbsPixel(parent.XtoPad(fX));
244 py1 = parent.YtoAbsPixel(parent.YtoPad(fY));
245 }
246 theta = GetTextAngle();
247 pxold = px;
248 pyold = py;
249 auto co = TMath::Cos(theta/180.*TMath::Pi());
250 auto si = TMath::Sin(theta/180.*TMath::Pi());
251 resize = kFALSE;
252 turn = kFALSE;
253 Int_t cBoxX[4], cBoxY[4];
254 GetControlBox(px1, py1, -theta, cBoxX, cBoxY);
255 auto div = ((cBoxX[3]-cBoxX[0])*co-(cBoxY[3]-cBoxY[0])*si);
256 Int_t part = 0;
257 if (TMath::Abs(div) > 1e-8)
258 part = (Int_t)(3*((px-cBoxX[0])*co-(py-cBoxY[0])*si)/ div);
259 switch (part) {
260 case 0:
261 if (halign == 3) {
262 turn = kTRUE;
263 right = kTRUE;
264 parent.SetCursor(kRotate);
265 } else {
266 resize = kTRUE;
267 height = valign;
268 width = halign;
269 parent.SetCursor(kArrowVer);
270 }
271 break;
272 case 1:
273 parent.SetCursor(kMove);
274 break;
275 case 2:
276 if (halign == 3) {
277 resize = kTRUE;
278 height = valign;
279 width = halign;
280 parent.SetCursor(kArrowVer);
281 } else {
282 turn = kTRUE;
283 right = kFALSE;
284 parent.SetCursor(kRotate);
285 }
286 }
287 break;
288 }
289
290 case kArrowKeyRelease:
291 case kButton1Motion:
292 if (!opaque)
293 PaintControlBox(px1, py1, -theta);
294 if (turn) {
295 auto norm = TMath::Sqrt(1.*(py-py1)*(py-py1)+ 1.*(px-px1)*(px-px1));
296 if (norm > 0) {
297 theta = TMath::ACos((px - px1) / norm) / TMath::Pi() * 180;
298 auto dtheta = TMath::ASin((py1 - py) / norm);
299 if (dtheta < 0)
300 theta = -theta;
301 if (right)
302 theta += 180;
303 if (theta < 0)
304 theta += 360;
305 else if (theta >= 360)
306 theta -= 360;
307 }
308 } else if (resize) {
309 Int_t h = GetTextSizePixels(parent) / 2;
310 Int_t w = h*strlen(GetTitle()); // approximate width
311 auto co = TMath::Cos(GetTextAngle()/180.*TMath::Pi());
312 auto si = TMath::Sin(GetTextAngle()/180.*TMath::Pi());
313 Int_t ax = 0, ay = 0, bx, by;
314 if (width == 1) {
315 switch (valign) {
316 case 1 : ax = px1; ay = py1; break;
317 case 2 : ax = px1+Int_t(si*h/2); ay = py1+Int_t(co*h/2); break;
318 case 3 : ax = px1+Int_t(si*h*3/2); ay = py1+Int_t(co*h*3/2); break;
319 }
320 }
321 if (width == 2) {
322 switch (valign) {
323 case 1 : ax = px1-Int_t(co*w/2); ay = py1+Int_t(si*w/2); break;
324 case 2 : ax = px1-Int_t(co*w/2+si*h/2); ay = py1+Int_t(si*w/2+co*h/2); break;
325 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;
326 }
327 }
328 if (width == 3) {
329 switch (valign) {
330 case 1 : ax = px1-Int_t(co*w); ay = py1+Int_t(si*w); break;
331 case 2 : ax = px1-Int_t(co*w+si*h/2); ay = py1+Int_t(si*w+co*h/2); break;
332 case 3 : ax = px1-Int_t(co*w+si*h*3/2); ay = py1+Int_t(si*w+co*h*3/2); break;
333 }
334 }
335 if (height == 3) {
336 bx = ax - Int_t(si*h);
337 by = ay - Int_t(co*h);
338 } else {
339 bx = ax;
340 by = ay;
341 }
342 Int_t cx = bx+Int_t(co*w);
343 Int_t cy = by-Int_t(si*w);
344 Double_t lambda = Double_t(((px-bx)*(cx-bx)+(py-by)*(cy-by)))/Double_t(((cx-bx)*(cx-bx)+(cy-by)*(cy-by)));
345 Double_t x2 = Double_t(px) - lambda*Double_t(cx-bx)-Double_t(bx);
346 Double_t y2 = Double_t(py) - lambda*Double_t(cy-by)-Double_t(by);
347 Int_t Size = Int_t(TMath::Sqrt(x2*x2+y2*y2)*2);
348 if (Size < 4) Size = 4;
349
350 SetTextSizePixels(Size);
351 } else {
352 px1 += px - pxold; pxold = px;
353 py1 += py - pyold; pyold = py;
354 }
355 if (opaque) {
358 if (resize)
359 parent.ShowGuidelines(this, event, 't', false);
360 if (!resize && !turn)
361 parent.ShowGuidelines(this, event, 'i', true);
362 parent.ShowGuidelines(this, event, !resize && !turn);
363 SetTextAngle(theta);
364 parent.ModifiedUpdate();
365 } else {
366 PaintControlBox(px1, py1, -theta);
367 }
368 break;
369
370 case kButton1Up:
371 if (opaque) {
372 parent.ShowGuidelines(this, event, !resize && !turn);
373 } else {
376 SetTextAngle(theta);
377 }
378 parent.Modified(kTRUE);
379 break;
380
381 case kButton1Locate:
382 ExecuteEvent(kButton1Down, px, py);
383
384 while (1) {
385 px = py = 0;
386 event = parent.GetCanvasImp()->RequestLocator(px, py);
387
389
390 if (event != -1) { // button is released
391 ExecuteEvent(kButton1Up, px, py);
392 return;
393 }
394 }
395 }
396}
397
398////////////////////////////////////////////////////////////////////////////////
399/// Return the text control box. The text position coordinates is (x,y) and
400/// the text angle is theta. The control box coordinates are returned in cBoxX
401/// and cBoxY.
402
404 Int_t cBoxX[4], Int_t cBoxY[4])
405{
406 Short_t halign = fTextAlign/10; // horizontal alignment
407 Short_t valign = fTextAlign - 10*halign; // vertical alignment
408 UInt_t cBoxW = 0, cBoxH = 0; // control box width and heigh
409 UInt_t Dx = 0, Dy = 0; // delta along x and y to align the box
410
411 if (gPad) {
413 auto pp = gPad->GetPainter();
414 if (pp)
415 pp->GetTextExtent(GetTextFont(), tsize, cBoxW, cBoxH, GetTitle());
416 }
417
418 // compute the translations (Dx, Dy) required by the alignments
419 switch (halign) {
420 case 1 : Dx = 0 ; break;
421 case 2 : Dx = cBoxW/2; break;
422 case 3 : Dx = cBoxW ; break;
423 }
424 switch (valign) {
425 case 1 : Dy = 0 ; break;
426 case 2 : Dy = cBoxH/2; break;
427 case 3 : Dy = cBoxH ; break;
428 }
429
430 // compute the control box coordinates before rotation
431 cBoxX[0] = x-Dx;
432 cBoxY[0] = y+Dy;
433 cBoxX[1] = x-Dx;
434 cBoxY[1] = y-cBoxH+Dy;
435 cBoxX[2] = x+cBoxW-Dx;
436 cBoxY[2] = y-cBoxH+Dy;
437 cBoxX[3] = x+cBoxW-Dx;
438 cBoxY[3] = y+Dy;
439
440 // rotate the control box if needed
441 if (theta) {
442 Double_t cosTheta = TMath::Cos(theta*0.017453293);
443 Double_t sinTheta = TMath::Sin(theta*0.017453293);
444 for (int i=0; i<4 ; i++) {
445 Int_t hcBoxX = cBoxX[i];
446 Int_t hcBoxY = cBoxY[i];
449 }
450 }
451}
452
453////////////////////////////////////////////////////////////////////////////////
454/// Return text size in pixels. By default the size returned does not take
455/// into account the text angle (angle = kFALSE). If angle is set to kTRUE
456/// w and h take the angle into account.
457
459{
460 const char *text = GetTitle();
461 if (!text[0]) {
462 w = h = 0;
463 return;
464 }
465
466 if (!gPad)
467 return;
468 if (angle) {
469 Int_t cBoxX[4], cBoxY[4];
470 Int_t ptx, pty;
471 if (TestBit(kTextNDC)) {
472 ptx = gPad->UtoAbsPixel(fX);
473 pty = gPad->VtoAbsPixel(fY);
474 } else {
475 ptx = gPad->XtoAbsPixel(gPad->XtoPad(fX));
476 pty = gPad->YtoAbsPixel(gPad->YtoPad(fY));
477 }
479 Int_t x1 = cBoxX[0];
480 Int_t x2 = cBoxX[0];
481 Int_t y1 = cBoxY[0];
482 Int_t y2 = cBoxY[0];
483 for (Int_t i=1; i<4; i++) {
484 if (cBoxX[i] < x1) x1 = cBoxX[i];
485 if (cBoxX[i] > x2) x2 = cBoxX[i];
486 if (cBoxY[i] < y1) y1 = cBoxY[i];
487 if (cBoxY[i] > y2) y2 = cBoxY[i];
488 }
489 w = x2 - x1;
490 h = y2 - y1;
491 } else {
493 auto pp = gPad->GetPainter();
494 if (pp)
495 pp->GetTextExtent(GetTextFont(), tsize, w, h, GetTitle());
496 }
497}
498
499////////////////////////////////////////////////////////////////////////////////
500/// Return text ascent and descent for string text
501/// - in a return total text ascent
502/// - in d return text descent
503
504void TText::GetTextAscentDescent(UInt_t &a, UInt_t &d, const char *text) const
505{
506 if (!gPad)
507 return;
508
510
511 auto pp = gPad->GetPainter();
512 if (pp)
513 pp->GetTextAscentDescent(GetTextFont(), tsize, a, d, text);
514}
515
516
517////////////////////////////////////////////////////////////////////////////////
518/// Return text ascent and descent for string text
519/// - in a return total text ascent
520/// - in d return text descent
521
522void TText::GetTextAscentDescent(UInt_t &a, UInt_t &d, const wchar_t *text) const
523{
524 if (!gPad)
525 return;
526
528
529 auto pp = gPad->GetPainter();
530 if (pp)
531 pp->GetTextAscentDescent(GetTextFont(), tsize, a, d, text);
532}
533
534////////////////////////////////////////////////////////////////////////////////
535/// Return text extent for string text
536/// - in w return total text width
537/// - in h return text height
538
539void TText::GetTextExtent(UInt_t &w, UInt_t &h, const char *text) const
540{
541 if (!gPad)
542 return;
543
545
546 auto pp = gPad->GetPainter();
547 if (pp)
548 pp->GetTextExtent(GetTextFont(), tsize, w, h, text);
549}
550
551////////////////////////////////////////////////////////////////////////////////
552/// Return text advance for string text
553/// if kern is true (default) kerning is taken into account. If it is false
554/// the kerning is not taken into account.
555
556void TText::GetTextAdvance(UInt_t &a, const char *text, const Bool_t kern) const
557{
558 if (!gPad)
559 return;
560
562
563 auto pp = gPad->GetPainter();
564 if (pp)
565 a = pp->GetTextAdvance(GetTextFont(), tsize, text, kern);
566}
567
568////////////////////////////////////////////////////////////////////////////////
569/// Return text extent for string text
570/// - in w return total text width
571/// - in h return text height
572
573void TText::GetTextExtent(UInt_t &w, UInt_t &h, const wchar_t *text) const
574{
575 if (!gPad)
576 return;
577
579
580 auto pp = gPad->GetPainter();
581 if (pp)
582 pp->GetTextExtent(GetTextFont(), tsize, w, h, text);
583}
584
585////////////////////////////////////////////////////////////////////////////////
586/// List this text with its attributes.
587
588void TText::ls(Option_t *) const
589{
591 printf("Text X=%f Y=%f Text=%s\n",fX,fY,GetTitle());
592}
593
594////////////////////////////////////////////////////////////////////////////////
595/// Paint this text with its current attributes.
596
598{
599 if (!gPad) return;
600 TAttText::Modify(); //Change text attributes only if necessary
601 if (TestBit(kTextNDC)) gPad->PaintTextNDC(fX,fY,GetTitle());
602 else gPad->PaintText(gPad->XtoPad(fX),gPad->YtoPad(fY),GetTitle());
603}
604
605////////////////////////////////////////////////////////////////////////////////
606/// Paint the text control box. (x,y) are the coordinates where the control
607/// box should be painted and theta is the angle of the box.
608
610{
611 Int_t cBoxX[4], cBoxY[4];
612 Short_t halign = fTextAlign/10; // horizontal alignment
613 Short_t valign = fTextAlign - 10*halign; // vertical alignment
614
615 GetControlBox(x, y, theta, cBoxX, cBoxY);
616
617 auto pp = gPad->GetPainter();
618 if (!pp)
619 return;
620
621 // Draw the text control box outline
622 pp->SetAttLine({(Style_t)1, 1, 1});
623 for (int p1 = 0; p1 < 4; ++p1) {
624 int p2 = (p1 + 1) % 4;
625 pp->DrawLine(gPad->AbsPixeltoX(cBoxX[p1]),
626 gPad->AbsPixeltoY(cBoxY[p1]),
627 gPad->AbsPixeltoX(cBoxX[p2]),
628 gPad->AbsPixeltoY(cBoxY[p2]));
629 }
630
631 // Draw a symbol at the text starting point
632 TPoint p;
633 Int_t ix = 0, iy = 0;
634 switch (halign) {
635 case 1 :
636 switch (valign) {
637 case 1 : ix = 0 ; iy = 0 ; break;
638 case 2 : ix = 0 ; iy = 1 ; break;
639 case 3 : ix = 1 ; iy = 1 ; break;
640 }
641 break;
642 case 2 :
643 switch (valign) {
644 case 1 : ix = 0 ; iy = 3 ; break;
645 case 2 : ix = 0 ; iy = 2 ; break;
646 case 3 : ix = 1 ; iy = 2 ; break;
647 }
648 break;
649 case 3 :
650 switch (valign) {
651 case 1 : ix = 3 ; iy = 3 ; break;
652 case 2 : ix = 2 ; iy = 3 ; break;
653 case 3 : ix = 2 ; iy = 2 ; break;
654 }
655 break;
656 }
657 Double_t mX = gPad->AbsPixeltoX((cBoxX[ix]+cBoxX[iy])/2);
658 Double_t mY = gPad->AbsPixeltoY((cBoxY[ix]+cBoxY[iy])/2);
659 pp->SetAttMarker({(Color_t)1, 24, 0.7});
660 pp->DrawPolyMarker(1, &mX, &mY);
661}
662
663////////////////////////////////////////////////////////////////////////////////
664/// Draw this text with new coordinates.
665
667{
668 TAttText::Modify(); //Change text attributes only if necessary
669 if (gPad) gPad->PaintText(x,y,text);
670}
671
672////////////////////////////////////////////////////////////////////////////////
673/// Draw this text with new coordinates.
674
675void TText::PaintText(Double_t x, Double_t y, const wchar_t *text)
676{
677 TAttText::Modify(); //Change text attributes only if necessary
678 if (gPad) gPad->PaintText(x,y,text);
679}
680
681////////////////////////////////////////////////////////////////////////////////
682/// Draw this text with new coordinates in NDC.
683
685{
686 TAttText::Modify(); //Change text attributes only if necessary
687 if (gPad) gPad->PaintTextNDC(u,v,text);
688}
689
690////////////////////////////////////////////////////////////////////////////////
691/// Draw this text with new coordinates in NDC.
692
694{
695 TAttText::Modify(); //Change text attributes only if necessary
696 if (gPad) gPad->PaintTextNDC(u,v,text);
697}
698
699////////////////////////////////////////////////////////////////////////////////
700/// Dump this text with its attributes.
701
703{
704 printf("Text X=%f Y=%f Text=%s Font=%d Size=%f",fX,fY,GetTitle(),GetTextFont(),GetTextSize());
705 if (GetTextColor() != 1 ) printf(" Color=%d",GetTextColor());
706 if (GetTextAlign() != 10) printf(" Align=%d",GetTextAlign());
707 if (GetTextAngle() != 0 ) printf(" Angle=%f",GetTextAngle());
708 printf("\n");
709}
710
711////////////////////////////////////////////////////////////////////////////////
712/// Save primitive as a C++ statement(s) on output stream out
713
714void TText::SavePrimitive(std::ostream &out, Option_t *option)
715{
717 out, Class(), "text",
718 TString::Format("%g, %g, \"%s\"", fX, fY, TString(GetTitle()).ReplaceSpecialCppChars().Data()), kFALSE);
719
720 SaveTextAttributes(out, "text", 11, 0, 1, 62, 0.05);
721
722 if (TestBit(kTextNDC))
723 out << " text->SetNDC();\n";
724
725 SavePrimitiveDraw(out, "text", option);
726}
727
728////////////////////////////////////////////////////////////////////////////////
729/// Set NDC mode on if isNDC = kTRUE, off otherwise
730
735
736////////////////////////////////////////////////////////////////////////////////
737/// Change (i.e. set) the title of the TNamed.
738
739void TText::SetMbTitle(const wchar_t *title)
740{
741 char *mb_title = new char[MB_CUR_MAX * wcslen(title) + 1]();
742 char *p = mb_title;
743 size_t length = wcslen(title);
744 for (size_t i = 0; i < length; i++) {
745 const int n = wctomb(p, title[i]);
746 if (n >= 0) p += n;
747 }
749 delete [] mb_title;
750 if (gPad && TestBit(kMustCleanup)) gPad->Modified();
751}
752
753////////////////////////////////////////////////////////////////////////////////
754/// Stream an object of class TText.
755
757{
758 if (R__b.IsReading()) {
760 Version_t R__v = R__b.ReadVersion(&R__s, &R__c);
761 if (R__v > 1) {
762 R__b.ReadClassBuffer(TText::Class(), this, R__v, R__s, R__c);
763 return;
764 }
765 //====process old versions before automatic schema evolution
768 Float_t x,y;
769 R__b >> x; fX = x;
770 R__b >> y; fY = y;
771 //====end of old versions
772
773 } else {
774 R__b.WriteClassBuffer(TText::Class(),this);
775 }
776}
777////////////////////////////////////////////////////////////////////////////////
778/// Return the "bounding Box" of the Box
779
781{
782 Rectangle_t bbox{0, 0, 0, 0};
783 if (gPad) {
784 UInt_t w, h;
785 Int_t Dx = 0, Dy = 0;
786 GetBoundingBox(w, h, false);
787
790
791 switch (halign) {
792 case 1: Dx = 0; break;
793 case 2: Dx = w / 2; break;
794 case 3: Dx = w; break;
795 }
796
797 switch (valign) {
798 case 1: Dy = h; break;
799 case 2: Dy = h / 2; break;
800 case 3: Dy = 0; break;
801 }
802 if (TestBit(kTextNDC)) {
803 bbox.fX = gPad->UtoPixel(GetX()) - Dx;
804 bbox.fY = gPad->VtoPixel(GetY()) - Dy;
805 } else {
806 bbox.fX = gPad->XtoPixel(gPad->XtoPad(GetX())) - Dx;
807 bbox.fY = gPad->YtoPixel(gPad->YtoPad(GetY())) - Dy;
808 }
809 bbox.fWidth = w;
810 bbox.fHeight = h;
811 }
812 return bbox;
813}
814
815////////////////////////////////////////////////////////////////////////////////
816/// Return the point given by Alignment as 'center'
817
819{
820 TPoint p(0, 0);
821 if (gPad) {
822 if (TestBit(kTextNDC)) {
823 p.SetX(gPad->UtoPixel(GetX()));
824 p.SetY(gPad->VtoPixel(GetY()));
825 } else {
826 p.SetX(gPad->XtoPixel(gPad->XtoPad(GetX())));
827 p.SetY(gPad->YtoPixel(gPad->YtoPad(GetY())));
828 }
829 }
830 return p;
831}
832
833////////////////////////////////////////////////////////////////////////////////
834/// Set X coordinate of the point given by Alignment as 'center'
835
840
841////////////////////////////////////////////////////////////////////////////////
842/// Set Y coordinate of the point given by Alignment as 'center'
843
@ 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
cudaEvent_t event
short Style_t
Style number (short)
Definition RtypesCore.h:97
int Int_t
Signed integer 4 bytes (int)
Definition RtypesCore.h:60
short Color_t
Color number (short)
Definition RtypesCore.h:100
short Version_t
Class version identifier (short)
Definition RtypesCore.h:80
float Float_t
Float 4 bytes (float)
Definition RtypesCore.h:72
short Short_t
Signed Short integer 2 bytes (short)
Definition RtypesCore.h:54
constexpr Bool_t kFALSE
Definition RtypesCore.h:109
double Double_t
Double 8 bytes.
Definition RtypesCore.h:74
constexpr Bool_t kTRUE
Definition RtypesCore.h:108
const char Option_t
Option string (const char)
Definition RtypesCore.h:81
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 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 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
Abstract base class for elements drawn in the editor.
Definition TAttBBox2D.h:19
Double_t GetYCoord(const Int_t y, Bool_t is_ndc=kFALSE, Bool_t is_absolute=kFALSE)
Can return ndc or normal values Also one can specify to use absolute coordinates for input parameter ...
Double_t GetXCoord(const Int_t x, Bool_t is_ndc=kFALSE, Bool_t is_absolute=kFALSE)
Return user X coordinate for pixel X value Can return ndc or normal values Also one can specify to us...
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 SetTextSizePixels(Int_t npixels)
Set the text size in pixel.
Definition TAttText.cxx:441
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
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:843
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:775
@ kCanDelete
if object in a list can be deleted
Definition TObject.h:71
@ kMustCleanup
if object destructor must call RecursiveRemove()
Definition TObject.h:73
static void IndentLevel()
Functions used by ls() to indent an object hierarchy.
Definition TROOT.cxx:3067
Basic string class.
Definition TString.h:137
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:2459
Base class for several text objects.
Definition TText.h:22
@ kTextNDC
The text position is in the NDC space.
Definition TText.h:32
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:127
Rectangle_t GetBBox() override
Return the "bounding Box" of the Box.
Definition TText.cxx:780
void Copy(TObject &text) const override
Copy this text to text.
Definition TText.cxx:104
TText & operator=(const TText &src)
Assignment operator.
Definition TText.cxx:95
Double_t GetX() const
Definition TText.h:53
virtual void GetBoundingBox(UInt_t &w, UInt_t &h, Bool_t angle=kFALSE)
Return text size in pixels.
Definition TText.cxx:458
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:609
virtual TText * DrawText(Double_t x, Double_t y, const char *text)
Draw this text with new coordinates.
Definition TText.cxx:171
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:79
virtual void PaintTextNDC(Double_t u, Double_t v, const char *text)
Draw this text with new coordinates in NDC.
Definition TText.cxx:684
void SavePrimitive(std::ostream &out, Option_t *option="") override
Save primitive as a C++ statement(s) on output stream out.
Definition TText.cxx:714
void ls(Option_t *option="") const override
List this text with its attributes.
Definition TText.cxx:588
virtual void PaintText(Double_t x, Double_t y, const char *text)
Draw this text with new coordinates.
Definition TText.cxx:666
TText()
Definition TText.h:35
virtual void GetTextExtent(UInt_t &w, UInt_t &h, const char *text) const
Return text extent for string text.
Definition TText.cxx:539
virtual void GetTextAscentDescent(UInt_t &a, UInt_t &d, const char *text) const
Return text ascent and descent for string text.
Definition TText.cxx:504
Int_t DistancetoPrimitive(Int_t px, Int_t py) override
Compute distance from point px,py to a string.
Definition TText.cxx:141
TPoint GetBBoxCenter() override
Return the point given by Alignment as 'center'.
Definition TText.cxx:818
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:556
void Paint(Option_t *option="") override
Paint this text with its current attributes.
Definition TText.cxx:597
void SetBBoxCenterY(const Int_t y) override
Set Y coordinate of the point given by Alignment as 'center'.
Definition TText.cxx:844
virtual void SetNDC(Bool_t isNDC=kTRUE)
Set NDC mode on if isNDC = kTRUE, off otherwise.
Definition TText.cxx:731
void Print(Option_t *option="") const override
Dump this text with its attributes.
Definition TText.cxx:702
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:403
void SetBBoxCenterX(const Int_t x) override
Set X coordinate of the point given by Alignment as 'center'.
Definition TText.cxx:836
Double_t GetY() const
Definition TText.h:61
void Streamer(TBuffer &) override
Stream an object of class TText.
Definition TText.cxx:756
virtual TText * DrawTextNDC(Double_t x, Double_t y, const char *text)
Draw this text with new coordinates in NDC.
Definition TText.cxx:197
static TClass * Class()
virtual void SetMbTitle(const wchar_t *title=L"")
Change (i.e. set) the title of the TNamed.
Definition TText.cxx:739
void ExecuteEvent(Int_t event, Int_t px, Int_t py) override
Execute action corresponding to one event.
Definition TText.cxx:220
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:645
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:1326
Double_t ASin(Double_t)
Returns the principal value of the arc sine of x, expressed in radians.
Definition TMath.h:637
Double_t Sqrt(Double_t x)
Returns the square root of x.
Definition TMath.h:675
Double_t Cos(Double_t)
Returns the cosine of an angle of x radians.
Definition TMath.h:607
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:601
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