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
215public:
216 Int_t px1 = 0, py1 = 0, pxold = 0, pyold = 0, height = 0, width = 0;
219
221 {
222 if (ndc) {
223 px1 = parent.UtoAbsPixel(x);
224 py1 = parent.VtoAbsPixel(y);
225 } else {
226 px1 = parent.XtoAbsPixel(parent.XtoPad(x));
227 py1 = parent.YtoAbsPixel(parent.YtoPad(y));
228 }
229 theta = angle;
230 }
231
233 {
234 switch (part) {
235 case 0:
236 if (halign == 3) {
237 turn = kTRUE;
238 right = kTRUE;
239 parent.SetCursor(kRotate);
240 } else {
241 resize = kTRUE;
242 height = valign;
243 width = halign;
244 parent.SetCursor(kArrowVer);
245 }
246 break;
247 case 1: parent.SetCursor(kMove); break;
248 case 2:
249 if (halign == 3) {
250 resize = kTRUE;
251 height = valign;
252 width = halign;
253 parent.SetCursor(kArrowVer);
254 } else {
255 turn = kTRUE;
256 right = kFALSE;
257 parent.SetCursor(kRotate);
258 }
259 }
260 }
261
262 void ProcessMove(TVirtualPad &parent, TText *txt, Int_t px, Int_t py)
263 {
264 if (turn) {
265 auto norm = TMath::Sqrt(1.*(py-py1)*(py-py1)+ 1.*(px-px1)*(px-px1));
266 if (norm > 0) {
267 theta = TMath::ACos((px - px1) / norm) / TMath::Pi() * 180;
268 auto dtheta = TMath::ASin((py1 - py) / norm);
269 if (dtheta < 0)
270 theta = -theta;
271 if (right)
272 theta += 180;
273 if (theta < 0)
274 theta += 360;
275 else if (theta >= 360)
276 theta -= 360;
277 }
278 } else if (resize) {
279 Int_t valign = txt->GetTextAlign() % 10;
280 Int_t h = txt->GetTextSizePixels(parent) / 2;
281 Int_t w = h*strlen(txt->GetTitle()); // approximate width
282 auto co = TMath::Cos(txt->GetTextAngle()/180.*TMath::Pi());
283 auto si = TMath::Sin(txt->GetTextAngle()/180.*TMath::Pi());
284 Int_t ax = 0, ay = 0, bx, by;
285 if (width == 1) {
286 switch (valign) {
287 case 1:
288 ax = px1;
289 ay = py1;
290 break;
291 case 2:
292 ax = px1 + Int_t(si * h / 2);
293 ay = py1 + Int_t(co * h / 2);
294 break;
295 case 3:
296 ax = px1 + Int_t(si * h * 3 / 2);
297 ay = py1 + Int_t(co * h * 3 / 2);
298 break;
299 }
300 } else if (width == 2) {
301 switch (valign) {
302 case 1:
303 ax = px1 - Int_t(co * w / 2);
304 ay = py1 + Int_t(si * w / 2);
305 break;
306 case 2:
307 ax = px1 - Int_t(co * w / 2 + si * h / 2);
308 ay = py1 + Int_t(si * w / 2 + co * h / 2);
309 break;
310 case 3:
311 ax = px1 - Int_t(co * w / 2 + si * h * 3 / 2);
312 ay = py1 + Int_t(si * w / 2 + co * h * 3 / 2);
313 break;
314 }
315 } else if (width == 3) {
316 switch (valign) {
317 case 1:
318 ax = px1 - Int_t(co * w);
319 ay = py1 + Int_t(si * w);
320 break;
321 case 2:
322 ax = px1 - Int_t(co * w + si * h / 2);
323 ay = py1 + Int_t(si * w + co * h / 2);
324 break;
325 case 3:
326 ax = px1 - Int_t(co * w + si * h * 3 / 2);
327 ay = py1 + Int_t(si * w + co * h * 3 / 2);
328 break;
329 }
330 }
331 if (height == 3) {
332 bx = ax - Int_t(si*h);
333 by = ay - Int_t(co*h);
334 } else {
335 bx = ax;
336 by = ay;
337 }
338 Int_t cx = bx+Int_t(co*w);
339 Int_t cy = by-Int_t(si*w);
340 Double_t lambda = Double_t(((px-bx)*(cx-bx)+(py-by)*(cy-by)))/Double_t(((cx-bx)*(cx-bx)+(cy-by)*(cy-by)));
341 Double_t x2 = Double_t(px) - lambda*Double_t(cx-bx)-Double_t(bx);
342 Double_t y2 = Double_t(py) - lambda*Double_t(cy-by)-Double_t(by);
343 Int_t Size = Int_t(TMath::Sqrt(x2*x2+y2*y2)*2);
344 if (Size < 4) Size = 4;
345
346 txt->SetTextSizePixels(Size);
347 } else {
348 px1 += px - pxold; pxold = px;
349 py1 += py - pyold; pyold = py;
350 }
351 }
352
354 {
355 Double_t xx[5], yy[5];
356 for(Int_t p = 0; p < 4; ++p) {
357 xx[p] = parent.AbsPixeltoX(cBoxX[p]);
358 yy[p] = parent.AbsPixeltoY(cBoxY[p]);
359 }
360 xx[4] = xx[0];
361 yy[4] = yy[0];
362 parent.PaintPolyLine(5, xx, yy, "itextbox");
363
364 if (show_corner) {
365 Double_t mX = parent.AbsPixeltoX(px1);
366 Double_t mY = parent.AbsPixeltoY(py1);
367
368 Double_t dx = (parent.GetX2() - parent.GetX1()) / parent.GetPadWidth() * 6;
369 Double_t dy = (parent.GetY2() - parent.GetY1()) / parent.GetPadHeight() * 6;
370
371 Double_t xc[5] = { mX, mX + dx, mX, mX - dx, mX };
372 Double_t yc[5] = { mY - dy, mY, mY + dy, mY, mY - dy };
373 parent.PaintFillArea(5, xc, yc, "itextcorner");
374 }
375 }
376
377};
378
379////////////////////////////////////////////////////////////////////////////////
380/// Execute action corresponding to one event.
381///
382/// This member function must be implemented to realize the action
383/// corresponding to the mouse click on the object in the window
384
386{
387 if (!gPad || !gPad->IsEditable())
388 return;
389
390 auto &parent = *gPad;
391
392 Short_t halign = GetTextAlign() / 10;
393 Short_t valign = GetTextAlign() % 10;
394 Bool_t opaque = parent.OpaqueMoving();
395
396 auto inter = dynamic_cast<TTextInteractive *>(parent.Interactive(this));
397
398 switch (event) {
399
400 case kArrowKeyPress:
401 case kButton1Down:
402 case kMouseMotion: {
404 parent.Interactive(this, inter);
405 inter->pxold = px;
406 inter->pyold = py;
407 auto co = TMath::Cos(GetTextAngle()/180.*TMath::Pi());
408 auto si = TMath::Sin(GetTextAngle()/180.*TMath::Pi());
409 Int_t cBoxX[4], cBoxY[4];
410 GetControlBox(inter->px1, inter->py1, -inter->theta, cBoxX, cBoxY);
411 auto div = ((cBoxX[3]-cBoxX[0])*co-(cBoxY[3]-cBoxY[0])*si);
412 Int_t part = TMath::Abs(div) < 1e-8 ? 0 : (Int_t)(3 * ((px - cBoxX[0]) * co - (py - cBoxY[0]) * si) / div);
413 inter->SelectPart(parent, part, halign, valign);
414 break;
415 }
416
417 case kArrowKeyRelease:
418 case kButton1Motion:
419 if (!inter)
420 return;
421
422 inter->ProcessMove(parent, this, px, py);
423
424 if (opaque) {
427 SetTextAngle(inter->theta);
428 if (inter->resize)
429 parent.ShowGuidelines(this, event, 't', false);
430 if (!inter->resize && !inter->turn)
431 parent.ShowGuidelines(this, event, 'i', true);
432 parent.Modified();
433 } else {
434 Int_t cBoxX[4], cBoxY[4];
435 GetControlBox(inter->px1, inter->py1, -inter->theta, cBoxX, cBoxY);
436 inter->PaintControlBox(parent, cBoxX, cBoxY, (halign != 2) || (valign != 2));
437 }
438 parent.UpdateAsync();
439 break;
440
441 case kButton1Up:
442 if (opaque) {
443 parent.ShowGuidelines(this, event);
444 } else {
447 SetTextAngle(inter->theta);
448 }
449 parent.Modified(kTRUE);
450 parent.Interactive(); // delete interactive object
451 break;
452
453 case kButton1Locate:
454 ExecuteEvent(kButton1Down, px, py);
455
456 while (1) {
457 px = py = 0;
458 event = parent.GetCanvasImp()->RequestLocator(px, py);
459
461
462 if (event != -1) { // button is released
463 ExecuteEvent(kButton1Up, px, py);
464 return;
465 }
466 }
467 }
468}
469
470////////////////////////////////////////////////////////////////////////////////
471/// Return the text control box. The text position coordinates is (x,y) and
472/// the text angle is theta. The control box coordinates are returned in cBoxX
473/// and cBoxY.
474
476 Int_t cBoxX[4], Int_t cBoxY[4])
477{
478 Short_t halign = fTextAlign/10; // horizontal alignment
479 Short_t valign = fTextAlign - 10*halign; // vertical alignment
480 UInt_t cBoxW = 0, cBoxH = 0; // control box width and heigh
481 UInt_t Dx = 0, Dy = 0; // delta along x and y to align the box
482
483 if (gPad) {
485 auto pp = gPad->GetPainter();
486 if (pp)
487 pp->GetTextExtent(GetTextFont(), tsize, cBoxW, cBoxH, GetTitle());
488 }
489
490 // compute the translations (Dx, Dy) required by the alignments
491 switch (halign) {
492 case 1 : Dx = 0 ; break;
493 case 2 : Dx = cBoxW/2; break;
494 case 3 : Dx = cBoxW ; break;
495 }
496 switch (valign) {
497 case 1 : Dy = 0 ; break;
498 case 2 : Dy = cBoxH/2; break;
499 case 3 : Dy = cBoxH ; break;
500 }
501
502 // compute the control box coordinates before rotation
503 cBoxX[0] = x-Dx;
504 cBoxY[0] = y+Dy;
505 cBoxX[1] = x-Dx;
506 cBoxY[1] = y-cBoxH+Dy;
507 cBoxX[2] = x+cBoxW-Dx;
508 cBoxY[2] = y-cBoxH+Dy;
509 cBoxX[3] = x+cBoxW-Dx;
510 cBoxY[3] = y+Dy;
511
512 // rotate the control box if needed
513 if (theta) {
514 Double_t cosTheta = TMath::Cos(theta*0.017453293);
515 Double_t sinTheta = TMath::Sin(theta*0.017453293);
516 for (int i=0; i<4 ; i++) {
517 Int_t hcBoxX = cBoxX[i];
518 Int_t hcBoxY = cBoxY[i];
521 }
522 }
523}
524
525////////////////////////////////////////////////////////////////////////////////
526/// Return text size in pixels. By default the size returned does not take
527/// into account the text angle (angle = kFALSE). If angle is set to kTRUE
528/// w and h take the angle into account.
529
531{
532 const char *text = GetTitle();
533 if (!text[0]) {
534 w = h = 0;
535 return;
536 }
537
538 if (!gPad)
539 return;
540 if (angle) {
541 Int_t cBoxX[4], cBoxY[4];
542 Int_t ptx, pty;
543 if (TestBit(kTextNDC)) {
544 ptx = gPad->UtoAbsPixel(fX);
545 pty = gPad->VtoAbsPixel(fY);
546 } else {
547 ptx = gPad->XtoAbsPixel(gPad->XtoPad(fX));
548 pty = gPad->YtoAbsPixel(gPad->YtoPad(fY));
549 }
551 Int_t x1 = cBoxX[0];
552 Int_t x2 = cBoxX[0];
553 Int_t y1 = cBoxY[0];
554 Int_t y2 = cBoxY[0];
555 for (Int_t i=1; i<4; i++) {
556 if (cBoxX[i] < x1) x1 = cBoxX[i];
557 if (cBoxX[i] > x2) x2 = cBoxX[i];
558 if (cBoxY[i] < y1) y1 = cBoxY[i];
559 if (cBoxY[i] > y2) y2 = cBoxY[i];
560 }
561 w = x2 - x1;
562 h = y2 - y1;
563 } else {
565 auto pp = gPad->GetPainter();
566 if (pp)
567 pp->GetTextExtent(GetTextFont(), tsize, w, h, GetTitle());
568 }
569}
570
571////////////////////////////////////////////////////////////////////////////////
572/// Return text ascent and descent for string text
573/// - in a return total text ascent
574/// - in d return text descent
575
576void TText::GetTextAscentDescent(UInt_t &a, UInt_t &d, const char *text) const
577{
578 if (!gPad)
579 return;
580
582
583 auto pp = gPad->GetPainter();
584 if (pp)
585 pp->GetTextAscentDescent(GetTextFont(), tsize, a, d, text);
586}
587
588
589////////////////////////////////////////////////////////////////////////////////
590/// Return text ascent and descent for string text
591/// - in a return total text ascent
592/// - in d return text descent
593
594void TText::GetTextAscentDescent(UInt_t &a, UInt_t &d, const wchar_t *text) const
595{
596 if (!gPad)
597 return;
598
600
601 auto pp = gPad->GetPainter();
602 if (pp)
603 pp->GetTextAscentDescent(GetTextFont(), tsize, a, d, text);
604}
605
606////////////////////////////////////////////////////////////////////////////////
607/// Return text extent for string text
608/// - in w return total text width
609/// - in h return text height
610
611void TText::GetTextExtent(UInt_t &w, UInt_t &h, const char *text) const
612{
613 if (!gPad)
614 return;
615
617
618 auto pp = gPad->GetPainter();
619 if (pp)
620 pp->GetTextExtent(GetTextFont(), tsize, w, h, text);
621}
622
623////////////////////////////////////////////////////////////////////////////////
624/// Return text advance for string text
625/// if kern is true (default) kerning is taken into account. If it is false
626/// the kerning is not taken into account.
627
628void TText::GetTextAdvance(UInt_t &a, const char *text, const Bool_t kern) const
629{
630 if (!gPad)
631 return;
632
634
635 auto pp = gPad->GetPainter();
636 if (pp)
637 a = pp->GetTextAdvance(GetTextFont(), tsize, text, kern);
638}
639
640////////////////////////////////////////////////////////////////////////////////
641/// Return text extent for string text
642/// - in w return total text width
643/// - in h return text height
644
645void TText::GetTextExtent(UInt_t &w, UInt_t &h, const wchar_t *text) const
646{
647 if (!gPad)
648 return;
649
651
652 auto pp = gPad->GetPainter();
653 if (pp)
654 pp->GetTextExtent(GetTextFont(), tsize, w, h, text);
655}
656
657////////////////////////////////////////////////////////////////////////////////
658/// List this text with its attributes.
659
660void TText::ls(Option_t *) const
661{
663 printf("Text X=%f Y=%f Text=%s\n",fX,fY,GetTitle());
664}
665
666////////////////////////////////////////////////////////////////////////////////
667/// Paint this text with its current attributes.
668
670{
671 if (!gPad) return;
672 TAttText::Modify(); //Change text attributes only if necessary
673 if (TestBit(kTextNDC)) gPad->PaintTextNDC(fX,fY,GetTitle());
674 else gPad->PaintText(gPad->XtoPad(fX),gPad->YtoPad(fY),GetTitle());
675}
676
677////////////////////////////////////////////////////////////////////////////////
678/// Paint the text control box. (x,y) are the coordinates where the control
679/// box should be painted and theta is the angle of the box.
680
682{
683 Int_t cBoxX[4], cBoxY[4];
684 Short_t halign = fTextAlign/10; // horizontal alignment
685 Short_t valign = fTextAlign - 10*halign; // vertical alignment
686
687 GetControlBox(x, y, theta, cBoxX, cBoxY);
688
689 auto pp = gPad->GetPainter();
690 if (!pp)
691 return;
692
693 // Draw the text control box outline
694 pp->SetAttLine({(Style_t)1, 1, 1});
695 for (int p1 = 0; p1 < 4; ++p1) {
696 int p2 = (p1 + 1) % 4;
697 pp->DrawLine(gPad->AbsPixeltoX(cBoxX[p1]),
698 gPad->AbsPixeltoY(cBoxY[p1]),
699 gPad->AbsPixeltoX(cBoxX[p2]),
700 gPad->AbsPixeltoY(cBoxY[p2]));
701 }
702
703 // Draw a symbol at the text starting point
704 TPoint p;
705 Int_t ix = 0, iy = 0;
706 switch (halign) {
707 case 1 :
708 switch (valign) {
709 case 1 : ix = 0 ; iy = 0 ; break;
710 case 2 : ix = 0 ; iy = 1 ; break;
711 case 3 : ix = 1 ; iy = 1 ; break;
712 }
713 break;
714 case 2 :
715 switch (valign) {
716 case 1 : ix = 0 ; iy = 3 ; break;
717 case 2 : ix = 0 ; iy = 2 ; break;
718 case 3 : ix = 1 ; iy = 2 ; break;
719 }
720 break;
721 case 3 :
722 switch (valign) {
723 case 1 : ix = 3 ; iy = 3 ; break;
724 case 2 : ix = 2 ; iy = 3 ; break;
725 case 3 : ix = 2 ; iy = 2 ; break;
726 }
727 break;
728 }
729 Double_t mX = gPad->AbsPixeltoX((cBoxX[ix]+cBoxX[iy])/2);
730 Double_t mY = gPad->AbsPixeltoY((cBoxY[ix]+cBoxY[iy])/2);
731 pp->SetAttMarker({(Color_t)1, 24, 0.7});
732 pp->DrawPolyMarker(1, &mX, &mY);
733}
734
735////////////////////////////////////////////////////////////////////////////////
736/// Draw this text with new coordinates.
737
739{
740 TAttText::Modify(); //Change text attributes only if necessary
741 if (gPad) gPad->PaintText(x,y,text);
742}
743
744////////////////////////////////////////////////////////////////////////////////
745/// Draw this text with new coordinates.
746
747void TText::PaintText(Double_t x, Double_t y, const wchar_t *text)
748{
749 TAttText::Modify(); //Change text attributes only if necessary
750 if (gPad) gPad->PaintText(x,y,text);
751}
752
753////////////////////////////////////////////////////////////////////////////////
754/// Draw this text with new coordinates in NDC.
755
757{
758 TAttText::Modify(); //Change text attributes only if necessary
759 if (gPad) gPad->PaintTextNDC(u,v,text);
760}
761
762////////////////////////////////////////////////////////////////////////////////
763/// Draw this text with new coordinates in NDC.
764
766{
767 TAttText::Modify(); //Change text attributes only if necessary
768 if (gPad) gPad->PaintTextNDC(u,v,text);
769}
770
771////////////////////////////////////////////////////////////////////////////////
772/// Dump this text with its attributes.
773
775{
776 printf("Text X=%f Y=%f Text=%s Font=%d Size=%f",fX,fY,GetTitle(),GetTextFont(),GetTextSize());
777 if (GetTextColor() != 1 ) printf(" Color=%d",GetTextColor());
778 if (GetTextAlign() != 10) printf(" Align=%d",GetTextAlign());
779 if (GetTextAngle() != 0 ) printf(" Angle=%f",GetTextAngle());
780 printf("\n");
781}
782
783////////////////////////////////////////////////////////////////////////////////
784/// Save primitive as a C++ statement(s) on output stream out
785
786void TText::SavePrimitive(std::ostream &out, Option_t *option)
787{
789 out, Class(), "text",
790 TString::Format("%g, %g, \"%s\"", fX, fY, TString(GetTitle()).ReplaceSpecialCppChars().Data()), kFALSE);
791
792 SaveTextAttributes(out, "text", 11, 0, 1, 62, 0.05);
793
794 if (TestBit(kTextNDC))
795 out << " text->SetNDC();\n";
796
797 SavePrimitiveDraw(out, "text", option);
798}
799
800////////////////////////////////////////////////////////////////////////////////
801/// Set NDC mode on if isNDC = kTRUE, off otherwise
802
804{
805 SetBit(kTextNDC, isNDC);
806}
807
808////////////////////////////////////////////////////////////////////////////////
809/// Change (i.e. set) the title of the TNamed.
810
811void TText::SetMbTitle(const wchar_t *title)
812{
813 char *mb_title = new char[MB_CUR_MAX * wcslen(title) + 1]();
814 char *p = mb_title;
815 size_t length = wcslen(title);
816 for (size_t i = 0; i < length; i++) {
817 const int n = wctomb(p, title[i]);
818 if (n >= 0) p += n;
819 }
821 delete [] mb_title;
822 if (gPad && TestBit(kMustCleanup)) gPad->Modified();
823}
824
825////////////////////////////////////////////////////////////////////////////////
826/// Stream an object of class TText.
827
829{
830 if (R__b.IsReading()) {
832 Version_t R__v = R__b.ReadVersion(&R__s, &R__c);
833 if (R__v > 1) {
834 R__b.ReadClassBuffer(TText::Class(), this, R__v, R__s, R__c);
835 return;
836 }
837 //====process old versions before automatic schema evolution
840 Float_t x,y;
841 R__b >> x; fX = x;
842 R__b >> y; fY = y;
843 //====end of old versions
844
845 } else {
846 R__b.WriteClassBuffer(TText::Class(),this);
847 }
848}
849////////////////////////////////////////////////////////////////////////////////
850/// Return the "bounding Box" of the Box
851
853{
854 Rectangle_t bbox{0, 0, 0, 0};
855 if (gPad) {
856 UInt_t w, h;
857 Int_t Dx = 0, Dy = 0;
858 GetBoundingBox(w, h, false);
859
862
863 switch (halign) {
864 case 1: Dx = 0; break;
865 case 2: Dx = w / 2; break;
866 case 3: Dx = w; break;
867 }
868
869 switch (valign) {
870 case 1: Dy = h; break;
871 case 2: Dy = h / 2; break;
872 case 3: Dy = 0; break;
873 }
874 if (TestBit(kTextNDC)) {
875 bbox.fX = gPad->UtoPixel(GetX()) - Dx;
876 bbox.fY = gPad->VtoPixel(GetY()) - Dy;
877 } else {
878 bbox.fX = gPad->XtoPixel(gPad->XtoPad(GetX())) - Dx;
879 bbox.fY = gPad->YtoPixel(gPad->YtoPad(GetY())) - Dy;
880 }
881 bbox.fWidth = w;
882 bbox.fHeight = h;
883 }
884 return bbox;
885}
886
887////////////////////////////////////////////////////////////////////////////////
888/// Return the point given by Alignment as 'center'
889
891{
892 TPoint p(0, 0);
893 if (gPad) {
894 if (TestBit(kTextNDC)) {
895 p.SetX(gPad->UtoPixel(GetX()));
896 p.SetY(gPad->VtoPixel(GetY()));
897 } else {
898 p.SetX(gPad->XtoPixel(gPad->XtoPad(GetX())));
899 p.SetY(gPad->YtoPixel(gPad->YtoPad(GetY())));
900 }
901 }
902 return p;
903}
904
905////////////////////////////////////////////////////////////////////////////////
906/// Set X coordinate of the point given by Alignment as 'center'
907
912
913////////////////////////////////////////////////////////////////////////////////
914/// Set Y coordinate of the point given by Alignment as 'center'
915
@ 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 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 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
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:886
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:844
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:776
@ 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:2460
void SelectPart(TVirtualPad &parent, Int_t part, Int_t halign, Int_t valign)
Definition TText.cxx:232
void PaintControlBox(TVirtualPad &parent, Int_t *cBoxX, Int_t *cBoxY, Bool_t show_corner)
Definition TText.cxx:353
void ProcessMove(TVirtualPad &parent, TText *txt, Int_t px, Int_t py)
Definition TText.cxx:262
Double_t theta
Definition TText.cxx:218
TTextInteractive(TVirtualPad &parent, Bool_t ndc, Double_t x, Double_t y, Double_t angle)
Definition TText.cxx:220
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:852
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
virtual void PaintControlBox(Int_t x, Int_t y, Double_t theta) R__DEPRECATED(6
Paint the text control box.
Definition TText.cxx:681
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:530
virtual void SetY(Double_t y)
Definition TText.h:77
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:756
void SavePrimitive(std::ostream &out, Option_t *option="") override
Save primitive as a C++ statement(s) on output stream out.
Definition TText.cxx:786
void ls(Option_t *option="") const override
List this text with its attributes.
Definition TText.cxx:660
virtual void PaintText(Double_t x, Double_t y, const char *text)
Draw this text with new coordinates.
Definition TText.cxx:738
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:611
virtual void GetTextAscentDescent(UInt_t &a, UInt_t &d, const char *text) const
Return text ascent and descent for string text.
Definition TText.cxx:576
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:890
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:628
void Paint(Option_t *option="") override
Paint this text with its current attributes.
Definition TText.cxx:669
void SetBBoxCenterY(const Int_t y) override
Set Y coordinate of the point given by Alignment as 'center'.
Definition TText.cxx:916
virtual void SetNDC(Bool_t isNDC=kTRUE)
Set NDC mode on if isNDC = kTRUE, off otherwise.
Definition TText.cxx:803
void Print(Option_t *option="") const override
Dump this text with its attributes.
Definition TText.cxx:774
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:475
void SetBBoxCenterX(const Int_t x) override
Set X coordinate of the point given by Alignment as 'center'.
Definition TText.cxx:908
Double_t GetY() const
Definition TText.h:61
void Streamer(TBuffer &) override
Stream an object of class TText.
Definition TText.cxx:828
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:811
void ExecuteEvent(Int_t event, Int_t px, Int_t py) override
Execute action corresponding to one event.
Definition TText.cxx:385
Helper class to store interactive parameters for individual objects Should be used via gPad->Interact...
Definition TVirtualPad.h:75
TVirtualPad is an abstract base class for the Pad and Canvas classes.
Definition TVirtualPad.h:51
virtual void PaintFillArea(Int_t n, Float_t *x, Float_t *y, Option_t *option="")=0
virtual Int_t YtoAbsPixel(Double_t y) const =0
virtual Double_t GetX2() const =0
virtual Double_t AbsPixeltoX(Double_t px)=0
virtual Int_t XtoAbsPixel(Double_t x) const =0
virtual Double_t GetY1() const =0
virtual Int_t UtoAbsPixel(Double_t u) const =0
virtual UInt_t GetPadWidth() const =0
virtual Double_t YtoPad(Double_t y) const =0
virtual void PaintPolyLine(Int_t n, Float_t *x, Float_t *y, Option_t *option="")=0
virtual UInt_t GetPadHeight() const =0
virtual Double_t XtoPad(Double_t x) const =0
virtual Int_t VtoAbsPixel(Double_t v) const =0
virtual Double_t GetY2() const =0
virtual Double_t AbsPixeltoY(Double_t py)=0
virtual void SetCursor(ECursor cursor)=0
virtual Double_t GetX1() const =0
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