Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TLineInteractive.h
Go to the documentation of this file.
1// @(#)root/graf:$Id$
2// Author: Sergey Linev 25/09/2026
3
4/*************************************************************************
5 * Copyright (C) 1995-2026, 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#ifndef ROOT_TLineInteractive
13#define ROOT_TLineInteractive
14
15#include "TVirtualPad.h"
16
17#include "TMath.h"
18#include "TLine.h"
19
21
22protected:
23 Double_t oldX1 = 0., oldY1 = 0., oldX2 = 0., oldY2 = 0.;
24 Double_t newX1 = 0., newY1 = 0., newX2 = 0., newY2 = 0.;
26 Int_t dx1 = 0, dx2 = 0, dy1 = 0, dy2 = 0;
28
29public:
30
39
40 void SelectPoint(TVirtualPad &parent, Int_t px, Int_t py)
41 {
42 constexpr Int_t kMaxDiff = 20;
43
44 Int_t px1, py1, px2, py2;
45 if (isNDC) {
46 px1 = parent.UtoAbsPixel(newX1);
47 py1 = parent.VtoAbsPixel(newY1);
48 px2 = parent.UtoAbsPixel(newX2);
49 py2 = parent.VtoAbsPixel(newY2);
50 } else {
51 px1 = parent.XtoAbsPixel(parent.XtoPad(newX1));
52 py1 = parent.YtoAbsPixel(parent.YtoPad(newY1));
53 px2 = parent.XtoAbsPixel(parent.XtoPad(newX2));
54 py2 = parent.YtoAbsPixel(parent.YtoPad(newY2));
55 }
56
57 if (abs(px1 - px) + abs(py1 - py) < kMaxDiff) {
58 selectPoint = 1;
59 parent.SetCursor(kPointer);
60 } else if (abs(px2 - px) + abs(py2 - py) < kMaxDiff) {
61 selectPoint = 2;
62 parent.SetCursor(kPointer);
63 } else {
64 selectPoint = 3;
65 dx1 = px1 - px;
66 dx2 = px2 - px;
67 dy1 = py1 - py;
68 dy2 = py2 - py;
69 parent.SetCursor(kMove);
70 }
71 }
72
74 {
75 if (!isNDC)
76 return parent.PadtoX(parent.AbsPixeltoX(px));
77 Double_t ww = parent.GetWw();
78 Double_t wndc = parent.GetAbsWNDC();
79 return ww > 0 && wndc > 0 ? (px / ww - parent.GetAbsXlowNDC()) / wndc : 0.;
80 }
81
83 {
84 if (!isNDC)
85 return parent.PadtoY(parent.AbsPixeltoY(py));
86
87 Double_t wh = parent.GetWh();
88 Double_t hndc = parent.GetAbsHNDC();
89 return wh > 0 && hndc > 0 ? ((1. - py / wh) - parent.GetAbsYlowNDC()) / hndc : 0.;
90 }
91
93 {
94 Bool_t m = selectPoint == 3;
95 if (selectPoint & 1) {
96 newX1 = GetXCoord(parent, px + (m ? dx1 : 0));
97 newY1 = GetYCoord(parent, py + (m ? dy1 : 0));
98 }
99 if (selectPoint & 2) {
100 newX2 = GetXCoord(parent, px + (m ? dx2 : 0));
101 newY2 = GetYCoord(parent, py + (m ? dy2 : 0));
102 }
103
104 if (vert) {
105 if (selectPoint & 1)
106 newX2 = newX1;
107 else
108 newX1 = newX2;
109 }
110 if (horiz) {
111 if (selectPoint & 1)
112 newY2 = newY1;
113 else
114 newY1 = newY2;
115 }
116 }
117
118 void PaintLine(TVirtualPad &parent)
119 {
120 if (isNDC) {
121 Double_t xx[2] = {newX1, newX2};
122 Double_t yy[2] = {newY1, newY2};
123 parent.PaintPolyLineNDC(2, xx, yy, "iline");
124 } else {
125 Double_t xx[2] = {parent.XtoPad(newX1), parent.XtoPad(newX2)};
126 Double_t yy[2] = {parent.YtoPad(newY1), parent.YtoPad(newY2)};
127 parent.PaintPolyLine(2, xx, yy, "iline");
128 }
129 }
130
131 char GetGuideChar() const
132 {
133 if ((selectPoint == 1) || (selectPoint == 2)) {
134 static const char GUIDES[2][2][2] = {{{'4', '1'}, {'3', '2'}}, {{'2', '3'}, {'1', '4'}}};
135 int x_idx = newX1 > newX2 ? 1 : 0;
136 int y_idx = newY1 > newY2 ? 1 : 0;
137 return GUIDES[selectPoint - 1][x_idx][y_idx];
138 }
139 return selectPoint == 3 ? 'i' : '\0';
140 }
141
143 {
144 l->SetX1(usenew ? newX1 : oldX1);
145 l->SetY1(usenew ? newY1 : oldY1);
146 l->SetX2(usenew ? newX2 : oldX2);
147 l->SetY2(usenew ? newY2 : oldY2);
148 }
149
150};
151
152#endif
@ kMove
Definition GuiTypes.h:375
@ kPointer
Definition GuiTypes.h:376
constexpr Bool_t kFALSE
Definition RtypesCore.h:109
constexpr Bool_t kTRUE
Definition RtypesCore.h:108
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Option_t Option_t TPoint TPoint const char x2
Option_t Option_t TPoint TPoint const char x1
Option_t Option_t TPoint TPoint const char y2
Option_t Option_t TPoint TPoint const char y1
Double_t GetXCoord(TVirtualPad &parent, Int_t px)
Double_t GetYCoord(TVirtualPad &parent, Int_t py)
void Apply(TLine *l, Bool_t usenew=kTRUE)
TLineInteractive(Double_t x1, Double_t y1, Double_t x2, Double_t y2, Bool_t ndc=kFALSE)
void SelectPoint(TVirtualPad &parent, Int_t px, Int_t py)
char GetGuideChar() const
void ChangeCoordinate(TVirtualPad &parent, Int_t px, Int_t py, Bool_t vert=kFALSE, Bool_t horiz=kFALSE)
void PaintLine(TVirtualPad &parent)
Use the TLine constructor to create a simple line.
Definition TLine.h:22
virtual void SetY2(Double_t y2)
Definition TLine.h:70
virtual void SetX2(Double_t x2)
Definition TLine.h:68
virtual void SetX1(Double_t x1)
Definition TLine.h:67
virtual void SetY1(Double_t y1)
Definition TLine.h:69
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 Double_t PadtoX(Double_t x) const =0
virtual Int_t YtoAbsPixel(Double_t y) const =0
virtual void PaintPolyLineNDC(Int_t n, Double_t *x, Double_t *y, Option_t *option="")=0
virtual Double_t GetAbsYlowNDC() const =0
virtual Double_t AbsPixeltoX(Double_t px)=0
virtual UInt_t GetWh() const =0
virtual Int_t XtoAbsPixel(Double_t x) const =0
virtual Int_t UtoAbsPixel(Double_t u) const =0
virtual Double_t PadtoY(Double_t y) 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 GetAbsWNDC() const =0
virtual Double_t GetAbsXlowNDC() const =0
virtual Double_t XtoPad(Double_t x) const =0
virtual Int_t VtoAbsPixel(Double_t v) const =0
virtual Double_t GetAbsHNDC() const =0
virtual UInt_t GetWw() const =0
virtual Double_t AbsPixeltoY(Double_t py)=0
virtual void SetCursor(ECursor cursor)=0
TMarker m
Definition textangle.C:8
TLine l
Definition textangle.C:4