Skip to content

Commit 1ab72f6

Browse files
committed
[tline] use pad painter in ExecuteEvent
Use line native coordinates for painting - they are anyway needed when set back Therefore exclude conversion from NDC to normal coordinates during moving Simplify/harmonize logic how first/second points are handled during movement
1 parent 7973dad commit 1ab72f6

1 file changed

Lines changed: 119 additions & 174 deletions

File tree

graf2d/graf/src/TLine.cxx

Lines changed: 119 additions & 174 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
#include "TLine.h"
1818
#include "TVirtualPad.h"
1919
#include "TClass.h"
20-
#include "TVirtualX.h"
20+
#include "TVirtualPadPainter.h"
21+
#include "TCanvasImp.h"
2122
#include "TMath.h"
2223
#include "TPoint.h"
2324

@@ -130,19 +131,69 @@ TLine *TLine::DrawLineNDC(Double_t x1, Double_t y1, Double_t x2, Double_t y2)
130131

131132
void TLine::ExecuteEvent(Int_t event, Int_t px, Int_t py)
132133
{
133-
if (!gPad) return;
134+
if (!gPad || !gPad->IsEditable()) return;
134135

135-
Int_t kMaxDiff = 20;
136-
static Int_t d1,d2,px1,px2,py1,py2;
137-
static Int_t pxold, pyold, px1old, py1old, px2old, py2old;
136+
constexpr Int_t kMaxDiff = 20;
137+
static Int_t px1,px2,py1,py2,pxold,pyold;
138138
static Double_t oldX1, oldY1, oldX2, oldY2;
139-
static Bool_t p1, p2, pL, ndcsav;
140-
Double_t dpx,dpy,xp1,yp1;
141-
Int_t dx, dy;
139+
static Int_t selectPoint;
140+
141+
auto parent = gPad;
142+
143+
Bool_t opaque = parent->OpaqueMoving();
142144

143-
Bool_t opaque = gPad->OpaqueMoving();
145+
auto action = [this, parent](Int_t code, Int_t _x1, Int_t _y1, Int_t _x2 = 0, Int_t _y2 = 0) {
146+
Double_t x1, y1, x2, y2;
144147

145-
if (!gPad->IsEditable()) return;
148+
if (TestBit(kLineNDC)) {
149+
x1 = (1. * _x1 / parent->GetWw() - parent->GetAbsXlowNDC()) / parent->GetAbsWNDC();
150+
y1 = ((1 - 1. * _y1 / parent->GetWh()) - parent->GetAbsYlowNDC()) / parent->GetAbsHNDC();
151+
x2 = (1. * _x2 / parent->GetWw() - parent->GetAbsXlowNDC()) / parent->GetAbsWNDC();
152+
y2 = ((1 - 1. * _y2 / parent->GetWh()) - parent->GetAbsYlowNDC()) / parent->GetAbsHNDC();
153+
} else {
154+
x1 = parent->AbsPixeltoX(_x1);
155+
y1 = parent->AbsPixeltoY(_y1);
156+
x2 = parent->AbsPixeltoX(_x2);
157+
y2 = parent->AbsPixeltoY(_y2);
158+
if (parent->GetLogx()) {
159+
x1 = TMath::Power(10, x1);
160+
x2 = TMath::Power(10, x2);
161+
}
162+
if (parent->GetLogy()) {
163+
y1 = TMath::Power(10, y1);
164+
y2 = TMath::Power(10, y2);
165+
}
166+
}
167+
if (code == 0) {
168+
auto pp = parent->GetPainter();
169+
pp->SetAttLine(*this);
170+
if (TestBit(kLineNDC))
171+
pp->DrawLineNDC(x1, y1, x2, y2);
172+
else
173+
pp->DrawLine(x1, y1, x2, y2);
174+
} else {
175+
if (code & 1) {
176+
SetX1(x1);
177+
SetY1(y1);
178+
}
179+
if (code & 2) {
180+
SetX2(x2);
181+
SetY2(y2);
182+
}
183+
if (TestBit(kVertical)) {
184+
if (code & 1)
185+
SetX2(GetX1());
186+
else
187+
SetX1(GetX2());
188+
}
189+
if (TestBit(kHorizontal)) {
190+
if (code & 1)
191+
SetY2(GetY1());
192+
else
193+
SetY1(GetY2());
194+
}
195+
}
196+
};
146197

147198
switch (event) {
148199

@@ -152,134 +203,76 @@ void TLine::ExecuteEvent(Int_t event, Int_t px, Int_t py)
152203
oldY1 = GetY1();
153204
oldX2 = GetX2();
154205
oldY2 = GetY2();
155-
ndcsav = TestBit(kLineNDC);
156-
if (!opaque) {
157-
gVirtualX->SetLineColor(-1);
158-
TAttLine::Modify(); //Change line attributes only if necessary
159-
}
160206

161207
// No break !!!
162208

163209
case kMouseMotion:
164210

165211
if (TestBit(kLineNDC)) {
166-
px1 = gPad->UtoPixel(GetX1());
167-
py1 = gPad->VtoPixel(GetY1());
168-
px2 = gPad->UtoPixel(GetX2());
169-
py2 = gPad->VtoPixel(GetY2());
212+
px1 = parent->UtoAbsPixel(GetX1());
213+
py1 = parent->VtoAbsPixel(GetY1());
214+
px2 = parent->UtoAbsPixel(GetX2());
215+
py2 = parent->VtoAbsPixel(GetY2());
170216
} else {
171-
px1 = gPad->XtoAbsPixel(gPad->XtoPad(GetX1()));
172-
py1 = gPad->YtoAbsPixel(gPad->YtoPad(GetY1()));
173-
px2 = gPad->XtoAbsPixel(gPad->XtoPad(GetX2()));
174-
py2 = gPad->YtoAbsPixel(gPad->YtoPad(GetY2()));
217+
px1 = parent->XtoAbsPixel(parent->XtoPad(GetX1()));
218+
py1 = parent->YtoAbsPixel(parent->YtoPad(GetY1()));
219+
px2 = parent->XtoAbsPixel(parent->XtoPad(GetX2()));
220+
py2 = parent->YtoAbsPixel(parent->YtoPad(GetY2()));
175221
}
176-
p1 = p2 = pL = kFALSE;
177222

178-
d1 = abs(px1 - px) + abs(py1-py); //simply take sum of pixels differences
179-
if (d1 < kMaxDiff) { //*-*================>OK take point number 1
180-
px1old = px1; py1old = py1;
181-
p1 = kTRUE;
182-
gPad->SetCursor(kPointer);
183-
return;
184-
}
185-
d2 = abs(px2 - px) + abs(py2-py); //simply take sum of pixels differences
186-
if (d2 < kMaxDiff) { //*-*================>OK take point number 2
187-
px2old = px2; py2old = py2;
188-
p2 = kTRUE;
189-
gPad->SetCursor(kPointer);
190-
return;
223+
//simply take sum of pixels differences
224+
if (abs(px1 - px) + abs(py1 - py) < kMaxDiff) { //*-*================>OK take point number 1
225+
selectPoint = 1;
226+
parent->SetCursor(kPointer);
227+
} else if (abs(px2 - px) + abs(py2 - py) < kMaxDiff) { //*-*================>OK take point number 2
228+
selectPoint = 2;
229+
parent->SetCursor(kPointer);
230+
} else {
231+
selectPoint = 3;
232+
pxold = px;
233+
pyold = py;
234+
parent->SetCursor(kMove);
191235
}
192236

193-
pL = kTRUE;
194-
pxold = px; pyold = py;
195-
gPad->SetCursor(kMove);
196-
197237
break;
198238

199239
case kArrowKeyRelease:
200240
case kButton1Motion:
201-
202-
if (p1) {
203-
if (!opaque) {
204-
gVirtualX->DrawLine(px1old, py1old, px2, py2);
205-
gVirtualX->DrawLine(px, py, px2, py2);
206-
} else {
207-
if (ndcsav) {
208-
SetNDC(kFALSE);
209-
SetX2(gPad->GetX1() + oldX2*(gPad->GetX2()-gPad->GetX1()));
210-
SetY2(gPad->GetY1() + oldY2*(gPad->GetY2()-gPad->GetY1()));
211-
}
212-
SetX1(gPad->AbsPixeltoX(px));
213-
SetY1(gPad->AbsPixeltoY(py));
214-
}
215-
px1old = px;
216-
py1old = py;
217-
}
218-
if (p2) {
219-
if (!opaque) {
220-
gVirtualX->DrawLine(px1, py1, px2old, py2old);
221-
gVirtualX->DrawLine(px1, py1, px, py);
222-
} else {
223-
if (ndcsav) {
224-
SetNDC(kFALSE);
225-
SetX1(gPad->GetX1() + oldX1*(gPad->GetX2()-gPad->GetX1()));
226-
SetY1(gPad->GetY1() + oldY1*(gPad->GetY2()-gPad->GetY1()));
227-
}
228-
SetX2(gPad->AbsPixeltoX(px));
229-
SetY2(gPad->AbsPixeltoY(py));
230-
}
231-
px2old = px;
232-
py2old = py;
233-
}
234-
if (pL) {
235-
if (!opaque) gVirtualX->DrawLine(px1, py1, px2, py2);
236-
dx = px-pxold; dy = py-pyold;
237-
px1 += dx; py1 += dy; px2 += dx; py2 += dy;
238-
if (!opaque) gVirtualX->DrawLine(px1, py1, px2, py2);
241+
if (!opaque)
242+
action(0, px1, py1, px2, py2);
243+
if (selectPoint == 1) {
244+
px1 = px;
245+
py1 = py;
246+
} else if (selectPoint == 2) {
247+
px2 = px;
248+
py2 = py;
249+
} else if (selectPoint == 3) {
250+
px1 += px - pxold;
251+
py1 += py - pyold;
252+
px2 += px - pxold;
253+
py2 += py -pyold;
239254
pxold = px;
240255
pyold = py;
241-
if (opaque) {
242-
if (ndcsav) SetNDC(kFALSE);
243-
SetX1(gPad->AbsPixeltoX(px1));
244-
SetY1(gPad->AbsPixeltoY(py1));
245-
SetX2(gPad->AbsPixeltoX(px2));
246-
SetY2(gPad->AbsPixeltoY(py2));
247-
}
248256
}
257+
action(!opaque ? 0 : selectPoint, px1, py1, px2, py2);
249258
if (opaque) {
250-
if (p1) {
259+
if (selectPoint == 1) {
251260
//check in which corner the BBox is edited
252-
if (GetX1() > GetX2()) {
253-
if (GetY1() > GetY2())
254-
gPad->ShowGuidelines(this, event, '2', true);
255-
else
256-
gPad->ShowGuidelines(this, event, '3', true);
257-
} else {
258-
if (GetY1() > GetY2())
259-
gPad->ShowGuidelines(this, event, '1', true);
260-
else
261-
gPad->ShowGuidelines(this, event, '4', true);
262-
}
263-
}
264-
if (p2) {
261+
if (GetX1() > GetX2())
262+
parent->ShowGuidelines(this, event, GetY1() > GetY2() ? '2' : '3', true);
263+
else
264+
parent->ShowGuidelines(this, event, GetY1() > GetY2() ? '1' : '4', true);
265+
} else if (selectPoint == 2) {
265266
//check in which corner the BBox is edited
266-
if (GetX1() > GetX2()) {
267-
if (GetY1() > GetY2())
268-
gPad->ShowGuidelines(this, event, '4', true);
269-
else
270-
gPad->ShowGuidelines(this, event, '1', true);
271-
} else {
272-
if (GetY1() > GetY2())
273-
gPad->ShowGuidelines(this, event, '3', true);
274-
else
275-
gPad->ShowGuidelines(this, event, '2', true);
276-
}
277-
}
278-
if (pL) {
279-
gPad->ShowGuidelines(this, event, 'i', true);
267+
if (GetX1() > GetX2())
268+
parent->ShowGuidelines(this, event, GetY1() > GetY2() ? '4' : '1', true);
269+
else
270+
parent->ShowGuidelines(this, event, GetY1() > GetY2() ? '3' : '2', true);
271+
} else if (selectPoint == 3) {
272+
parent->ShowGuidelines(this, event, 'i', true);
280273
}
281-
gPad->Modified(kTRUE);
282-
gPad->Update();
274+
parent->Modified(kTRUE);
275+
parent->Update();
283276
}
284277
break;
285278

@@ -292,77 +285,29 @@ void TLine::ExecuteEvent(Int_t event, Int_t px, Int_t py)
292285
SetY1(oldY1);
293286
SetX2(oldX2);
294287
SetY2(oldY2);
295-
gPad->ShowGuidelines(this, event);
296-
gPad->Modified(kTRUE);
297-
gPad->Update();
288+
parent->ShowGuidelines(this, event);
289+
parent->Modified(kTRUE);
290+
parent->Update();
298291
}
299292
break;
300293
}
301294
if (opaque) {
302-
if (ndcsav && !TestBit(kLineNDC)) {
303-
SetX1((GetX1() - gPad->GetX1())/(gPad->GetX2()-gPad->GetX1()));
304-
SetX2((GetX2() - gPad->GetX1())/(gPad->GetX2()-gPad->GetX1()));
305-
SetY1((GetY1() - gPad->GetY1())/(gPad->GetY2()-gPad->GetY1()));
306-
SetY2((GetY2() - gPad->GetY1())/(gPad->GetY2()-gPad->GetY1()));
307-
SetNDC();
308-
}
309-
gPad->ShowGuidelines(this, event);
295+
parent->ShowGuidelines(this, event);
310296
} else {
311-
if (TestBit(kLineNDC)) {
312-
dpx = gPad->GetX2() - gPad->GetX1();
313-
dpy = gPad->GetY2() - gPad->GetY1();
314-
xp1 = gPad->GetX1();
315-
yp1 = gPad->GetY1();
316-
if (p1) {
317-
SetX1((gPad->AbsPixeltoX(px)-xp1)/dpx);
318-
SetY1((gPad->AbsPixeltoY(py)-yp1)/dpy);
319-
}
320-
if (p2) {
321-
SetX2((gPad->AbsPixeltoX(px)-xp1)/dpx);
322-
SetY2((gPad->AbsPixeltoY(py)-yp1)/dpy);
323-
}
324-
if (pL) {
325-
SetX1((gPad->AbsPixeltoX(px1)-xp1)/dpx);
326-
SetY1((gPad->AbsPixeltoY(py1)-yp1)/dpy);
327-
SetX2((gPad->AbsPixeltoX(px2)-xp1)/dpx);
328-
SetY2((gPad->AbsPixeltoY(py2)-yp1)/dpy);
329-
}
330-
} else {
331-
if (p1) {
332-
SetX1(gPad->PadtoX(gPad->AbsPixeltoX(px)));
333-
SetY1(gPad->PadtoY(gPad->AbsPixeltoY(py)));
334-
}
335-
if (p2) {
336-
SetX2(gPad->PadtoX(gPad->AbsPixeltoX(px)));
337-
SetY2(gPad->PadtoY(gPad->AbsPixeltoY(py)));
338-
}
339-
if (pL) {
340-
SetX1(gPad->PadtoX(gPad->AbsPixeltoX(px1)));
341-
SetY1(gPad->PadtoY(gPad->AbsPixeltoY(py1)));
342-
SetX2(gPad->PadtoX(gPad->AbsPixeltoX(px2)));
343-
SetY2(gPad->PadtoY(gPad->AbsPixeltoY(py2)));
344-
}
345-
}
346-
if (TestBit(kVertical)) {
347-
if (p1) SetX2(GetX1());
348-
if (p2) SetX1(GetX2());
349-
}
350-
if (TestBit(kHorizontal)) {
351-
if (p1) SetY2(GetY1());
352-
if (p2) SetY1(GetY2());
353-
}
354-
gPad->Modified(kTRUE);
355-
gPad->Update();
356-
if (!opaque) gVirtualX->SetLineColor(-1);
297+
action(selectPoint, px1, py1, px2, py2);
298+
parent->Modified(kTRUE);
299+
parent->Update();
357300
}
301+
selectPoint = 0;
358302
break;
359303

360304
case kButton1Locate:
361305

306+
// Sergey: code is never used, has to be removed in ROOT7
362307
ExecuteEvent(kButton1Down, px, py);
363308
while (true) {
364309
px = py = 0;
365-
event = gVirtualX->RequestLocator(1,1,px,py);
310+
event = parent->GetCanvasImp()->RequestLocator(px, py);
366311

367312
ExecuteEvent(kButton1Motion, px, py);
368313

0 commit comments

Comments
 (0)