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, Size, height, width;
228 static Bool_t resize,turn;
229 Int_t dx, dy;
230 const char *text = GetTitle();
231 Int_t len = strlen(text);
232 Double_t sizetowin = parent.GetAbsHNDC()*Double_t(parent.GetWh());
234 Int_t h = Int_t(fh/2);
235 Int_t w = h*len;
239 static Bool_t right;
240 static Double_t theta;
241 Int_t ax = 0, ay = 0, bx, by, cx, cy;
242 Double_t lambda, x2,y2;
243 Int_t cBoxX[4], cBoxY[4], part;
244 Double_t div = 0;
245 Bool_t opaque = parent.OpaqueMoving();
246
247 switch (event) {
248
249 case kArrowKeyPress:
250 case kButton1Down:
251 case kMouseMotion:
252 if (TestBit(kTextNDC)) {
253 px1 = parent.UtoAbsPixel(fX);
254 py1 = parent.VtoAbsPixel(fY);
255 } else {
256 px1 = parent.XtoAbsPixel(parent.XtoPad(fX));
257 py1 = parent.YtoAbsPixel(parent.YtoPad(fY));
258 }
259 theta = GetTextAngle();
260 Size = 0;
261 pxold = px;
262 pyold = py;
263 co = TMath::Cos(theta*0.017453293);
264 si = TMath::Sin(theta*0.017453293);
265 resize = kFALSE;
266 turn = kFALSE;
267 GetControlBox(px1, py1, -theta, cBoxX, cBoxY);
268 div = ((cBoxX[3]-cBoxX[0])*co-(cBoxY[3]-cBoxY[0])*si);
269 if (TMath::Abs(div) > 1e-8)
270 part = (Int_t)(3*((px-cBoxX[0])*co-(py-cBoxY[0])*si)/ div);
271 else
272 part = 0;
273 switch (part) {
274 case 0:
275 if (halign == 3) {
276 turn = kTRUE;
277 right = kTRUE;
278 parent.SetCursor(kRotate);
279 } else {
280 resize = kTRUE;
281 height = valign;
282 width = halign;
283 parent.SetCursor(kArrowVer);
284 }
285 break;
286 case 1:
287 parent.SetCursor(kMove);
288 break;
289 case 2:
290 if (halign == 3) {
291 resize = kTRUE;
292 height = valign;
293 width = halign;
294 parent.SetCursor(kArrowVer);
295 } else {
296 turn = kTRUE;
297 right = kFALSE;
298 parent.SetCursor(kRotate);
299 }
300 }
301 break;
302
303 case kArrowKeyRelease:
304 case kButton1Motion:
305 if (!opaque)
306 PaintControlBox(px1, py1, -theta);
307 if (turn) {
308 norm = TMath::Sqrt(Double_t((py-py1)*(py-py1)+(px-px1)*(px-px1)));
309 if (norm>0) {
310 theta = TMath::ACos((px-px1)/norm);
311 dtheta= TMath::ASin((py1-py)/norm);
312 if (dtheta<0) theta = -theta;
313 theta = theta/TMath::Pi()*180;
314 if (theta<0) theta += 360;
315 if (right) {theta = theta+180; if (theta>=360) theta -= 360;}
316 }
317 } else if (resize) {
318 co = TMath::Cos(fTextAngle*0.017453293);
319 si = TMath::Sin(fTextAngle*0.017453293);
320 if (width == 1) {
321 switch (valign) {
322 case 1 : ax = px1; ay = py1; break;
323 case 2 : ax = px1+Int_t(si*h/2); ay = py1+Int_t(co*h/2); break;
324 case 3 : ax = px1+Int_t(si*h*3/2); ay = py1+Int_t(co*h*3/2); break;
325 }
326 }
327 if (width == 2) {
328 switch (valign) {
329 case 1 : ax = px1-Int_t(co*w/2); ay = py1+Int_t(si*w/2); break;
330 case 2 : ax = px1-Int_t(co*w/2+si*h/2); ay = py1+Int_t(si*w/2+co*h/2); break;
331 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;
332 }
333 }
334 if (width == 3) {
335 switch (valign) {
336 case 1 : ax = px1-Int_t(co*w); ay = py1+Int_t(si*w); break;
337 case 2 : ax = px1-Int_t(co*w+si*h/2); ay = py1+Int_t(si*w+co*h/2); break;
338 case 3 : ax = px1-Int_t(co*w+si*h*3/2); ay = py1+Int_t(si*w+co*h*3/2); break;
339 }
340 }
341 if (height == 3) {
342 bx = ax-Int_t(si*h);
343 by = ay-Int_t(co*h);
344 } else {
345 bx = ax;
346 by = ay;
347 }
348 cx = bx+Int_t(co*w); cy = by-Int_t(si*w);
349 lambda = Double_t(((px-bx)*(cx-bx)+(py-by)*(cy-by)))/Double_t(((cx-bx)*(cx-bx)+(cy-by)*(cy-by)));
350 x2 = Double_t(px) - lambda*Double_t(cx-bx)-Double_t(bx);
351 y2 = Double_t(py) - lambda*Double_t(cy-by)-Double_t(by);
352 Size = Int_t(TMath::Sqrt(x2*x2+y2*y2)*2);
353 if (Size<4) Size = 4;
354
356 } else {
357 dx = px - pxold; px1 += dx;
358 dy = py - pyold; py1 += dy;
359 }
360 if (opaque) {
363 if (resize)
364 parent.ShowGuidelines(this, event, 't', false);
365 if (!resize && !turn)
366 parent.ShowGuidelines(this, event, 'i', true);
367 parent.ShowGuidelines(this, event, !resize && !turn);
368 SetTextAngle(theta);
369 parent.ModifiedUpdate();
370 }
371 if (!opaque)
372 PaintControlBox(px1, py1, -theta);
373 pxold = px; pyold = py;
374 break;
375
376 case kButton1Up:
377 if (opaque) {
378 parent.ShowGuidelines(this, event, !resize && !turn);
379 } else {
382 SetTextAngle(theta);
383 }
384 parent.Modified(kTRUE);
385 break;
386
387 case kButton1Locate:
388 ExecuteEvent(kButton1Down, px, py);
389
390 while (1) {
391 px = py = 0;
392 event = parent.GetCanvasImp()->RequestLocator(px, py);
393
395
396 if (event != -1) { // button is released
397 ExecuteEvent(kButton1Up, px, py);
398 return;
399 }
400 }
401 }
402}
403
404////////////////////////////////////////////////////////////////////////////////
405/// Return the text control box. The text position coordinates is (x,y) and
406/// the text angle is theta. The control box coordinates are returned in cBoxX
407/// and cBoxY.
408
410 Int_t cBoxX[4], Int_t cBoxY[4])
411{
412 Short_t halign = fTextAlign/10; // horizontal alignment
413 Short_t valign = fTextAlign - 10*halign; // vertical alignment
414 UInt_t cBoxW = 0, cBoxH = 0; // control box width and heigh
415 UInt_t Dx = 0, Dy = 0; // delta along x and y to align the box
416
417 if (gPad) {
419 auto pp = gPad->GetPainter();
420 if (pp)
421 pp->GetTextExtent(GetTextFont(), tsize, cBoxW, cBoxH, GetTitle());
422 }
423
424 // compute the translations (Dx, Dy) required by the alignments
425 switch (halign) {
426 case 1 : Dx = 0 ; break;
427 case 2 : Dx = cBoxW/2; break;
428 case 3 : Dx = cBoxW ; break;
429 }
430 switch (valign) {
431 case 1 : Dy = 0 ; break;
432 case 2 : Dy = cBoxH/2; break;
433 case 3 : Dy = cBoxH ; break;
434 }
435
436 // compute the control box coordinates before rotation
437 cBoxX[0] = x-Dx;
438 cBoxY[0] = y+Dy;
439 cBoxX[1] = x-Dx;
440 cBoxY[1] = y-cBoxH+Dy;
441 cBoxX[2] = x+cBoxW-Dx;
442 cBoxY[2] = y-cBoxH+Dy;
443 cBoxX[3] = x+cBoxW-Dx;
444 cBoxY[3] = y+Dy;
445
446 // rotate the control box if needed
447 if (theta) {
448 Double_t cosTheta = TMath::Cos(theta*0.017453293);
449 Double_t sinTheta = TMath::Sin(theta*0.017453293);
450 for (int i=0; i<4 ; i++) {
451 Int_t hcBoxX = cBoxX[i];
452 Int_t hcBoxY = cBoxY[i];
455 }
456 }
457}
458
459////////////////////////////////////////////////////////////////////////////////
460/// Return text size in pixels. By default the size returned does not take
461/// into account the text angle (angle = kFALSE). If angle is set to kTRUE
462/// w and h take the angle into account.
463
465{
466 const char *text = GetTitle();
467 if (!text[0]) {
468 w = h = 0;
469 return;
470 }
471
472 if (!gPad)
473 return;
474 if (angle) {
475 Int_t cBoxX[4], cBoxY[4];
476 Int_t ptx, pty;
477 if (TestBit(kTextNDC)) {
478 ptx = gPad->UtoAbsPixel(fX);
479 pty = gPad->VtoAbsPixel(fY);
480 } else {
481 ptx = gPad->XtoAbsPixel(gPad->XtoPad(fX));
482 pty = gPad->YtoAbsPixel(gPad->YtoPad(fY));
483 }
485 Int_t x1 = cBoxX[0];
486 Int_t x2 = cBoxX[0];
487 Int_t y1 = cBoxY[0];
488 Int_t y2 = cBoxY[0];
489 for (Int_t i=1; i<4; i++) {
490 if (cBoxX[i] < x1) x1 = cBoxX[i];
491 if (cBoxX[i] > x2) x2 = cBoxX[i];
492 if (cBoxY[i] < y1) y1 = cBoxY[i];
493 if (cBoxY[i] > y2) y2 = cBoxY[i];
494 }
495 w = x2 - x1;
496 h = y2 - y1;
497 } else {
499 auto pp = gPad->GetPainter();
500 if (pp)
501 pp->GetTextExtent(GetTextFont(), tsize, w, h, GetTitle());
502 }
503}
504
505////////////////////////////////////////////////////////////////////////////////
506/// Return text ascent and descent for string text
507/// - in a return total text ascent
508/// - in d return text descent
509
510void TText::GetTextAscentDescent(UInt_t &a, UInt_t &d, const char *text) const
511{
512 if (!gPad)
513 return;
514
516
517 auto pp = gPad->GetPainter();
518 if (pp)
519 pp->GetTextAscentDescent(GetTextFont(), tsize, a, d, text);
520}
521
522
523////////////////////////////////////////////////////////////////////////////////
524/// Return text ascent and descent for string text
525/// - in a return total text ascent
526/// - in d return text descent
527
528void TText::GetTextAscentDescent(UInt_t &a, UInt_t &d, const wchar_t *text) const
529{
530 if (!gPad)
531 return;
532
534
535 auto pp = gPad->GetPainter();
536 if (pp)
537 pp->GetTextAscentDescent(GetTextFont(), tsize, a, d, text);
538}
539
540////////////////////////////////////////////////////////////////////////////////
541/// Return text extent for string text
542/// - in w return total text width
543/// - in h return text height
544
545void TText::GetTextExtent(UInt_t &w, UInt_t &h, const char *text) const
546{
547 if (!gPad)
548 return;
549
551
552 auto pp = gPad->GetPainter();
553 if (pp)
554 pp->GetTextExtent(GetTextFont(), tsize, w, h, text);
555}
556
557////////////////////////////////////////////////////////////////////////////////
558/// Return text advance for string text
559/// if kern is true (default) kerning is taken into account. If it is false
560/// the kerning is not taken into account.
561
562void TText::GetTextAdvance(UInt_t &a, const char *text, const Bool_t kern) const
563{
564 if (!gPad)
565 return;
566
568
569 auto pp = gPad->GetPainter();
570 if (pp)
571 a = pp->GetTextAdvance(GetTextFont(), tsize, text, kern);
572}
573
574////////////////////////////////////////////////////////////////////////////////
575/// Return text extent for string text
576/// - in w return total text width
577/// - in h return text height
578
579void TText::GetTextExtent(UInt_t &w, UInt_t &h, const wchar_t *text) const
580{
581 if (!gPad)
582 return;
583
585
586 auto pp = gPad->GetPainter();
587 if (pp)
588 pp->GetTextExtent(GetTextFont(), tsize, w, h, text);
589}
590
591////////////////////////////////////////////////////////////////////////////////
592/// List this text with its attributes.
593
594void TText::ls(Option_t *) const
595{
597 printf("Text X=%f Y=%f Text=%s\n",fX,fY,GetTitle());
598}
599
600////////////////////////////////////////////////////////////////////////////////
601/// Paint this text with its current attributes.
602
604{
605 if (!gPad) return;
606 TAttText::Modify(); //Change text attributes only if necessary
607 if (TestBit(kTextNDC)) gPad->PaintTextNDC(fX,fY,GetTitle());
608 else gPad->PaintText(gPad->XtoPad(fX),gPad->YtoPad(fY),GetTitle());
609}
610
611////////////////////////////////////////////////////////////////////////////////
612/// Paint the text control box. (x,y) are the coordinates where the control
613/// box should be painted and theta is the angle of the box.
614
616{
617 Int_t cBoxX[4], cBoxY[4];
618 Short_t halign = fTextAlign/10; // horizontal alignment
619 Short_t valign = fTextAlign - 10*halign; // vertical alignment
620
621 GetControlBox(x, y, theta, cBoxX, cBoxY);
622
623 auto pp = gPad->GetPainter();
624 if (!pp)
625 return;
626
627 // Draw the text control box outline
628 pp->SetAttLine({(Style_t)1, 1, 1});
629 for (int p1 = 0; p1 < 4; ++p1) {
630 int p2 = (p1 + 1) % 4;
631 pp->DrawLine(gPad->AbsPixeltoX(cBoxX[p1]),
632 gPad->AbsPixeltoY(cBoxY[p1]),
633 gPad->AbsPixeltoX(cBoxX[p2]),
634 gPad->AbsPixeltoY(cBoxY[p2]));
635 }
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 Double_t mX = gPad->AbsPixeltoX((cBoxX[ix]+cBoxX[iy])/2);
664 Double_t mY = gPad->AbsPixeltoY((cBoxY[ix]+cBoxY[iy])/2);
665 pp->SetAttMarker({(Color_t)1, 24, 0.7});
666 pp->DrawPolyMarker(1, &mX, &mY);
667}
668
669////////////////////////////////////////////////////////////////////////////////
670/// Draw this text with new coordinates.
671
673{
674 TAttText::Modify(); //Change text attributes only if necessary
675 if (gPad) gPad->PaintText(x,y,text);
676}
677
678////////////////////////////////////////////////////////////////////////////////
679/// Draw this text with new coordinates.
680
681void TText::PaintText(Double_t x, Double_t y, const wchar_t *text)
682{
683 TAttText::Modify(); //Change text attributes only if necessary
684 if (gPad) gPad->PaintText(x,y,text);
685}
686
687////////////////////////////////////////////////////////////////////////////////
688/// Draw this text with new coordinates in NDC.
689
691{
692 TAttText::Modify(); //Change text attributes only if necessary
693 if (gPad) gPad->PaintTextNDC(u,v,text);
694}
695
696////////////////////////////////////////////////////////////////////////////////
697/// Draw this text with new coordinates in NDC.
698
700{
701 TAttText::Modify(); //Change text attributes only if necessary
702 if (gPad) gPad->PaintTextNDC(u,v,text);
703}
704
705////////////////////////////////////////////////////////////////////////////////
706/// Dump this text with its attributes.
707
709{
710 printf("Text X=%f Y=%f Text=%s Font=%d Size=%f",fX,fY,GetTitle(),GetTextFont(),GetTextSize());
711 if (GetTextColor() != 1 ) printf(" Color=%d",GetTextColor());
712 if (GetTextAlign() != 10) printf(" Align=%d",GetTextAlign());
713 if (GetTextAngle() != 0 ) printf(" Angle=%f",GetTextAngle());
714 printf("\n");
715}
716
717////////////////////////////////////////////////////////////////////////////////
718/// Save primitive as a C++ statement(s) on output stream out
719
720void TText::SavePrimitive(std::ostream &out, Option_t *option)
721{
723 out, Class(), "text",
724 TString::Format("%g, %g, \"%s\"", fX, fY, TString(GetTitle()).ReplaceSpecialCppChars().Data()), kFALSE);
725
726 SaveTextAttributes(out, "text", 11, 0, 1, 62, 0.05);
727
728 if (TestBit(kTextNDC))
729 out << " text->SetNDC();\n";
730
731 SavePrimitiveDraw(out, "text", option);
732}
733
734////////////////////////////////////////////////////////////////////////////////
735/// Set NDC mode on if isNDC = kTRUE, off otherwise
736
741
742////////////////////////////////////////////////////////////////////////////////
743/// Change (i.e. set) the title of the TNamed.
744
745void TText::SetMbTitle(const wchar_t *title)
746{
747 char *mb_title = new char[MB_CUR_MAX * wcslen(title) + 1]();
748 char *p = mb_title;
749 size_t length = wcslen(title);
750 for (size_t i = 0; i < length; i++) {
751 const int n = wctomb(p, title[i]);
752 if (n >= 0) p += n;
753 }
755 delete [] mb_title;
756 if (gPad && TestBit(kMustCleanup)) gPad->Modified();
757}
758
759////////////////////////////////////////////////////////////////////////////////
760/// Stream an object of class TText.
761
763{
764 if (R__b.IsReading()) {
766 Version_t R__v = R__b.ReadVersion(&R__s, &R__c);
767 if (R__v > 1) {
768 R__b.ReadClassBuffer(TText::Class(), this, R__v, R__s, R__c);
769 return;
770 }
771 //====process old versions before automatic schema evolution
774 Float_t x,y;
775 R__b >> x; fX = x;
776 R__b >> y; fY = y;
777 //====end of old versions
778
779 } else {
780 R__b.WriteClassBuffer(TText::Class(),this);
781 }
782}
783////////////////////////////////////////////////////////////////////////////////
784/// Return the "bounding Box" of the Box
785
787{
788 Rectangle_t bbox{0, 0, 0, 0};
789 if (gPad) {
790 UInt_t w, h;
791 Int_t Dx = 0, Dy = 0;
792 GetBoundingBox(w, h, false);
793
796
797 switch (halign) {
798 case 1: Dx = 0; break;
799 case 2: Dx = w / 2; break;
800 case 3: Dx = w; break;
801 }
802
803 switch (valign) {
804 case 1: Dy = h; break;
805 case 2: Dy = h / 2; break;
806 case 3: Dy = 0; break;
807 }
808 if (TestBit(kTextNDC)) {
809 bbox.fX = gPad->UtoPixel(GetX()) - Dx;
810 bbox.fY = gPad->VtoPixel(GetY()) - Dy;
811 } else {
812 bbox.fX = gPad->XtoPixel(gPad->XtoPad(GetX())) - Dx;
813 bbox.fY = gPad->YtoPixel(gPad->YtoPad(GetY())) - Dy;
814 }
815 bbox.fWidth = w;
816 bbox.fHeight = h;
817 }
818 return bbox;
819}
820
821////////////////////////////////////////////////////////////////////////////////
822/// Return the point given by Alignment as 'center'
823
825{
826 TPoint p(0, 0);
827 if (gPad) {
828 if (TestBit(kTextNDC)) {
829 p.SetX(gPad->UtoPixel(GetX()));
830 p.SetY(gPad->VtoPixel(GetY()));
831 } else {
832 p.SetX(gPad->XtoPixel(gPad->XtoPad(GetX())));
833 p.SetY(gPad->YtoPixel(gPad->YtoPad(GetY())));
834 }
835 }
836 return p;
837}
838
839////////////////////////////////////////////////////////////////////////////////
840/// Set X coordinate of the point given by Alignment as 'center'
841
846
847////////////////////////////////////////////////////////////////////////////////
848/// Set Y coordinate of the point given by Alignment as 'center'
849
@ 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 Color_t
Color number (short)
Definition RtypesCore.h:99
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
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 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:888
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:845
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:777
@ 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: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:127
Rectangle_t GetBBox() override
Return the "bounding Box" of the Box.
Definition TText.cxx:786
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
@ kTextNDC
The text position is in the NDC space.
Definition TText.h:32
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:464
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:615
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:690
void SavePrimitive(std::ostream &out, Option_t *option="") override
Save primitive as a C++ statement(s) on output stream out.
Definition TText.cxx:720
void ls(Option_t *option="") const override
List this text with its attributes.
Definition TText.cxx:594
virtual void PaintText(Double_t x, Double_t y, const char *text)
Draw this text with new coordinates.
Definition TText.cxx:672
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:545
virtual void GetTextAscentDescent(UInt_t &a, UInt_t &d, const char *text) const
Return text ascent and descent for string text.
Definition TText.cxx:510
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:824
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:562
void Paint(Option_t *option="") override
Paint this text with its current attributes.
Definition TText.cxx:603
void SetBBoxCenterY(const Int_t y) override
Set Y coordinate of the point given by Alignment as 'center'.
Definition TText.cxx:850
virtual void SetNDC(Bool_t isNDC=kTRUE)
Set NDC mode on if isNDC = kTRUE, off otherwise.
Definition TText.cxx:737
void Print(Option_t *option="") const override
Dump this text with its attributes.
Definition TText.cxx:708
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:409
void SetBBoxCenterX(const Int_t x) override
Set X coordinate of the point given by Alignment as 'center'.
Definition TText.cxx:842
Double_t GetY() const
Definition TText.h:61
void Streamer(TBuffer &) override
Stream an object of class TText.
Definition TText.cxx:762
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:745
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: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