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