Level.cpp 16.7 KB
Newer Older
Generic for IPNL's avatar
Generic for IPNL committed
1 2
/***************************************************************************
 *   Copyright (C) 2004 by Olivier Stezowski                               *
3
 *   stezow(AT)ipnl.in2p3.fr                                                  *
Generic for IPNL's avatar
Generic for IPNL committed
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/
 
/** \file Level.cpp compiled in libGWPHYSICS.so */

23
#ifndef Gw_Level
Generic for IPNL's avatar
Generic for IPNL committed
24
#include "Level.h"
25
#endif
Generic for IPNL's avatar
Generic for IPNL committed
26

27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
#ifndef ROOT_TCanvas
//#include <TVirtualPad.h>
#include <TCanvas.h>
#endif

#ifndef ROOT_TROOT
#include <TROOT.h>
#endif

#ifndef ROOT_TClass
#include <TClass.h>
#endif

#ifndef ROOT_TVirtualX
#include <TVirtualX.h>
#endif

44 45
using namespace Gw;

Generic for IPNL's avatar
Generic for IPNL committed
46 47
ClassImp(Level);

48 49 50
const Short_t Level::fgkMaxLevelLabel    = 4;
const Int_t   Level::fgkMaxColor         = 4;
const Int_t   Level::fgkMaxStyle         = 2;
51
      Style_t Level::fgDefaultStyle[fgkMaxStyle] = {1, 2};    
C. Finck [IPHC]'s avatar
C. Finck [IPHC] committed
52
      Color_t Level::fgDefaultColor[fgkMaxColor] = {9, 2, 1, 6};  
C. Finck [IPHC]'s avatar
C. Finck [IPHC] committed
53
      Float_t Level::fgDefaultLabelSize  = 0.03; 
54 55
      Color_t Level::fgDefaultLabelColor = 1; 
      Bool_t  Level::fgMovable           = false;
C. Finck [IPHC]'s avatar
C. Finck [IPHC] committed
56 57


58 59 60 61 62

//__________________________________________________________
Level::Level()
  : TLine(),
    fVisLabel("0000"),
C. Finck [IPHC]'s avatar
C. Finck [IPHC] committed
63
    fPosLabel("0123"),
64 65 66 67 68
    fLabel0(),
    fLabel1(),
    fLabel2(),
    fLabel3(),
    fExtra(),
69
    fHasExtra(false),
70 71
    fDefaultStyle(kKnown),
    fDefaultColor(kPlus),
C. Finck [IPHC]'s avatar
C. Finck [IPHC] committed
72
    fLog("Level"),
73
    fIsSelected(false),
74 75 76
    fIsVisible(true),
	fIsModified(false),
	fDY(0.0)
77
{	
Generic for IPNL's avatar
Generic for IPNL committed
78
	TLine::SetX1(0); TLine::SetX2(0); TLine::SetY1(0); TLine::SetY2(0);
79 80 81
	fExtra.SetX1(0); 
	fExtra.SetX2(0); 
	fExtra.SetLineColor(17); fExtra.SetLineStyle(2); fExtra.SetBit(TObject::kInvalidObject);
Generic for IPNL's avatar
Generic for IPNL committed
82
	
83 84 85 86
	fLabel0.SetX(0); fLabel0.SetY(0); fLabel0.SetTextAlign(21); fLabel0.SetBit(TObject::kCannotPick);
	fLabel1.SetX(0); fLabel1.SetY(0); fLabel1.SetTextAlign(21); fLabel1.SetBit(TObject::kCannotPick);
	fLabel2.SetX(0); fLabel2.SetY(0); fLabel2.SetTextAlign(23); fLabel2.SetBit(TObject::kCannotPick);
	fLabel3.SetX(0); fLabel3.SetY(0); fLabel3.SetTextAlign(23); fLabel3.SetBit(TObject::kCannotPick);
C. Finck [IPHC]'s avatar
C. Finck [IPHC] committed
87
  
C. Finck [IPHC]'s avatar
C. Finck [IPHC] committed
88 89
	fLabel0.SetTextSize(GetDefaultLabelSize());  fLabel1.SetTextSize(GetDefaultLabelSize());  
    fLabel2.SetTextSize(GetDefaultLabelSize());  fLabel3.SetTextSize(GetDefaultLabelSize());
90 91 92

    fLabel0.SetTextFont(132);  fLabel1.SetTextFont(132);
    fLabel2.SetTextFont(132);  fLabel3.SetTextFont(132);
Generic for IPNL's avatar
Generic for IPNL committed
93 94
}

95 96 97 98
//__________________________________________________________
Level::~Level() 
{
}
Generic for IPNL's avatar
Generic for IPNL committed
99

100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116

//__________________________________________________________
void Level::SetStyle(EDefaultStyle style)
{
  Style_t st = GetDefaultStyle(style);
  SetLineStyle(st);
  fDefaultStyle = style;
}

//__________________________________________________________
void Level::SetColor(EDefaultColor color)
{
  Color_t co  = GetDefaultColor(color);
  SetLineColor(co);
  fDefaultColor = color;
}

C. Finck [IPHC]'s avatar
C. Finck [IPHC] committed
117 118 119 120 121 122 123 124 125 126

//__________________________________________________________
void Level::SetLabelsSize(Float_t size)
{
  fLabel0.SetTextSize(size);
  fLabel1.SetTextSize(size);
  fLabel2.SetTextSize(size);
  fLabel3.SetTextSize(size);  
}

127 128 129 130 131 132 133 134 135
//__________________________________________________________
void Level::SetLabelsColor(Color_t color)
{
  fLabel0.SetTextColor(color);
  fLabel1.SetTextColor(color);
  fLabel2.SetTextColor(color);
  fLabel3.SetTextColor(color);  
}

136
//__________________________________________________________
137 138 139 140 141
void Level::SetExtraLine(Double_t x1, Double_t x2)
{
	SetExtraLineX1(x1); SetExtraLineX2(x2);
}

142
//__________________________________________________________
143 144 145 146 147
void Level::SetExtraLineX1(Double_t x1)
{	
	if ( fExtra.TestBit(TObject::kInvalidObject) ) { // not yet initialised
		fExtra.SetBit(TObject::kCannotPick);
		fExtra.SetX1(TLine::GetX1());fExtra.SetX2(TLine::GetX2());
148
	    fExtra.SetBit(TObject::kInvalidObject, false);
149
	}
C. Finck [IPHC]'s avatar
C. Finck [IPHC] committed
150
  
151
	if ( x1 < GetX1() ) {
C. Finck [IPHC]'s avatar
C. Finck [IPHC] committed
152
	  fExtra.SetX1(x1);
153
      fExtra.SetX2(TMath::Max(TLine::GetX1(),fExtra.GetX2()));
154
	  fHasExtra = true;
C. Finck [IPHC]'s avatar
C. Finck [IPHC] committed
155
	}
156 157
}

158
//__________________________________________________________
159 160 161 162 163
void Level::SetExtraLineX2(Double_t x2)
{
	if ( fExtra.TestBit(TObject::kInvalidObject) ) { // not yet initialised
		fExtra.SetBit(TObject::kCannotPick);
		fExtra.SetX1(TLine::GetX1());fExtra.SetX2(TLine::GetX2());
164
	    fExtra.SetBit(TObject::kInvalidObject, false);
165
	}
166 167

	if ( x2 > GetX2() ) {
C. Finck [IPHC]'s avatar
C. Finck [IPHC] committed
168
	  fExtra.SetX2(x2);
169
      fExtra.SetX1(TMath::Min(TLine::GetX2(),fExtra.GetX1()));
170
	  fHasExtra = true;
C. Finck [IPHC]'s avatar
C. Finck [IPHC] committed
171
	}
172
}
173 174
    
//__________________________________________________________
175 176
void Level::SetVisLabel(const char *s)
{
177
	TString st = s; Short_t end = (st.Length() < fgkMaxLevelLabel) ? st.Length(): fgkMaxLevelLabel;
178 179 180 181 182 183 184 185 186 187
	
	for( Short_t i = 0; i < end; i++ ) {
		if ( st[i] == '0' ) {
			fVisLabel[i] = '0';
		}
		else {
			fVisLabel[i] = '1';
		}
	}
}
C. Finck [IPHC]'s avatar
C. Finck [IPHC] committed
188 189 190 191 192 193 194 195 196

//__________________________________________________________
void Level::SetPosLabel(const char *s)
{
      TString st = s; Short_t end = (st.Length() < fgkMaxLevelLabel) ? st.Length(): fgkMaxLevelLabel;
      
      for( Short_t i = 0; i < end; ++i ) {
        if (st.CountChar(st[i]) > 1) {
          fPosLabel = "0123";
197
		  fLog.SetProcessMethod("SetPosLabel(const char* )");
C. Finck [IPHC]'s avatar
C. Finck [IPHC] committed
198 199 200 201 202 203 204
          fLog << warning << Form("Unambiguous position label pattern, set to %s", fPosLabel.Data()) << dolog;
          return;
        }
      }
      fPosLabel = s;
}

205 206

//__________________________________________________________
Generic for IPNL's avatar
Generic for IPNL committed
207 208
void Level::SetLabel(const char *label, Int_t which)
{
209
    if (which < 0 || which >= fgkMaxLevelLabel) return;
210 211 212 213 214 215 216 217 218 219 220 221 222 223
    switch (which) {
	case 0:
		fLabel0.SetText(fLabel0.GetX(),fLabel0.GetY(),label);
		break;
	case 1:
		fLabel1.SetText(fLabel1.GetX(),fLabel1.GetY(),label);
		break;
	case 2:
		fLabel2.SetText(fLabel2.GetX(),fLabel2.GetY(),label);
		break;
	case 3:
		fLabel3.SetText(fLabel3.GetX(),fLabel3.GetY(),label);
		break;
    }
Generic for IPNL's avatar
Generic for IPNL committed
224 225
}

226
//__________________________________________________________
227 228 229 230 231 232 233
void Level::SetLabels(const char *l0, const char *l1, const char *l2, const char *l3) 
{
	fLabel0.SetText(fLabel0.GetX(),fLabel0.GetY(),l0);
	fLabel1.SetText(fLabel1.GetX(),fLabel1.GetY(),l1);
	fLabel2.SetText(fLabel2.GetX(),fLabel2.GetY(),l2);
	fLabel3.SetText(fLabel3.GetX(),fLabel3.GetY(),l3);	
}
234 235 236 237 238 239 240 241 242 243 244
  
//__________________________________________________________
void Level::ExtraLine(Bool_t extra) 
{ 
  fHasExtra = extra;
  if (fHasExtra)
	fExtra.SetBit(TObject::kInvalidObject, false);
  else
	fExtra.SetBit(TObject::kInvalidObject, true);
}

245 246 247 248
//__________________________________________________________
void Level::SetDefaultLabels()
{
  SetLabelsSize(Level::GetDefaultLabelSize());
249
  SetLabelsColor(Level::GetDefaultLabelColor());
250 251
  SetLabels(GetLabel0(), GetLabel1(), GetLabel2(), GetLabel3());
}
252 253

//__________________________________________________________
254
TLatex & Level::GetLabel(Int_t which)
Generic for IPNL's avatar
Generic for IPNL committed
255
{
256 257 258 259 260 261
    if ( which <= 0  ) return fLabel0;   
    
    if ( which == 1 )  return fLabel1;   
    if ( which == 2 )  return fLabel2;    
     
    return fLabel3;
Generic for IPNL's avatar
Generic for IPNL committed
262 263
}

264
//__________________________________________________________
Generic for IPNL's avatar
Generic for IPNL committed
265 266 267
void Level::SetX1(Double_t x1)
{
	Double_t dx = x1-TLine::GetX1(); TLine::SetX1(x1);
C. Finck [IPHC]'s avatar
C. Finck [IPHC] committed
268
        
C. Finck [IPHC]'s avatar
C. Finck [IPHC] committed
269 270 271 272
	for (Int_t i = 0; i <= 3; i+=3) {
	  Int_t idx = fPosLabel[i] - '0';
	  GetLabel(idx).SetX(GetLabel(idx).GetX()+dx);
	}
Generic for IPNL's avatar
Generic for IPNL committed
273
}
274 275

//__________________________________________________________
Generic for IPNL's avatar
Generic for IPNL committed
276 277 278
void Level::SetX2(Double_t x2)
{
	Double_t dx = x2-TLine::GetX2(); TLine::SetX2(x2);
C. Finck [IPHC]'s avatar
C. Finck [IPHC] committed
279
  
C. Finck [IPHC]'s avatar
C. Finck [IPHC] committed
280 281 282 283
	for (Int_t i = 1; i <= 2; ++i) {
	  Int_t idx = fPosLabel[i] - '0';
	  GetLabel(idx).SetX(GetLabel(idx).GetX()+dx);
	}
Generic for IPNL's avatar
Generic for IPNL committed
284 285
}    
 
286
//__________________________________________________________
Generic for IPNL's avatar
Generic for IPNL committed
287 288 289
void Level::SetY1(Double_t y1)
{
	Double_t dy = y1-TLine::GetY1(); 
C. Finck [IPHC]'s avatar
C. Finck [IPHC] committed
290 291 292 293 294 295 296 297 298 299 300
	
	for (Int_t i = 0; i < fgkMaxLevelLabel; ++i) {
	  Int_t align = 21;
	  if (i > 1) align = 23;
	  
	  Int_t idx = fPosLabel[i] - '0';
	  GetLabel(idx).SetY(GetLabel(idx).GetY()+dy);
	  GetLabel(idx).SetTextAlign(align); 
	  
	}

301
	// a level is always horizontal
302
	TLine::SetY1(y1); TLine::SetY2(y1); 
Generic for IPNL's avatar
Generic for IPNL committed
303
}
304 305

//__________________________________________________________
Generic for IPNL's avatar
Generic for IPNL committed
306 307
void Level::SetY2(Double_t y2)
{
308
	Double_t dy = y2-TLine::GetY2();
C. Finck [IPHC]'s avatar
C. Finck [IPHC] committed
309
  
C. Finck [IPHC]'s avatar
C. Finck [IPHC] committed
310 311 312 313 314 315 316 317 318
	for (Int_t i = 0; i < fgkMaxLevelLabel; ++i) {
	  Int_t align = 21;
	  if (i > 1) align = 23;
	  
	  Int_t idx = fPosLabel[i] - '0';
	  GetLabel(idx).SetY(GetLabel(idx).GetY()+dy);
	  GetLabel(idx).SetTextAlign(align); 
	  
	}
C. Finck [IPHC]'s avatar
C. Finck [IPHC] committed
319
  
320 321
	// a level is always horizontal
	TLine::SetY1(y2); TLine::SetY2(y2); fExtra.SetY1(y2); fExtra.SetY2(y2); 
Generic for IPNL's avatar
Generic for IPNL committed
322 323
}

324
//__________________________________________________________
325
Int_t Level::Compare(const TObject *lev) const
Generic for IPNL's avatar
Generic for IPNL committed
326
{
C. Finck [IPHC]'s avatar
C. Finck [IPHC] committed
327 328 329 330 331 332
        if ( GetY1() == ((Level *)lev)->GetY1() ) 
          return  0;
        else if ( GetY1()  < ((Level *)lev)->GetY1() ) 
          return -1;
        else 
          return 1;                
Generic for IPNL's avatar
Generic for IPNL committed
333
}
334

335
//__________________________________________________________
336
void Level::Paint(Option_t* option)
337
{
338
        if ( !IsVisible() ) return;
C. Finck [IPHC]'s avatar
C. Finck [IPHC] committed
339
        
340 341 342 343
        if (!fExtra.TestBit(TObject::kInvalidObject)) 
		   fExtra.Paint(option); 

        TLine::Paint(option); 
C. Finck [IPHC]'s avatar
C. Finck [IPHC] committed
344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363
        
        Int_t idx = 0;

        if ( fVisLabel[0] == '1' ) {
          idx = fPosLabel[0] -'0';
          GetLabel(idx).Paint(option);
        }
        if ( fVisLabel[1] == '1' ) { 
          idx = fPosLabel[1] - '0';
          GetLabel(idx).Paint(option);
        }
        if ( fVisLabel[2] == '1' ) {
          idx = fPosLabel[2] -'0';
          GetLabel(idx).Paint(option);
        }
        
        if ( fVisLabel[3] == '1' ) {
          idx = fPosLabel[3] - '0';
          GetLabel(idx).Paint(option);
        }
364 365
}

366 367 368
//__________________________________________________________
void Level::Draw(Option_t* option)
{
C. Finck [IPHC]'s avatar
C. Finck [IPHC] committed
369 370
        if ( !IsVisible() ) return;
        
371 372 373
        TLine::Draw(option); 
   
        //fExtra.Draw(option); 
C. Finck [IPHC]'s avatar
C. Finck [IPHC] committed
374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393
        
        Int_t idx = 0;
        
        if ( fVisLabel[0] == '1' ) {
          idx = fPosLabel[0] -'0';
          GetLabel(idx).Draw(option);
        }
        if ( fVisLabel[1] == '1' ) { 
          idx = fPosLabel[1] - '0';
          GetLabel(idx).Draw(option);
        }
        if ( fVisLabel[2] == '1' ) {
          idx = fPosLabel[2] -'0';
          GetLabel(idx).Draw(option);
        }
        
        if ( fVisLabel[3] == '1' ) {
          idx = fPosLabel[3] - '0';
          GetLabel(idx).Draw(option);
        }  
394 395
}

396
//__________________________________________________________
397 398
void Level::ExecuteEvent(Int_t event, Int_t px, Int_t py)
{
399
  
400 401 402 403 404 405 406 407 408
   // Execute action corresponding to one event.
   //  This member function is called when a line is clicked with the locator
	//
   //  If Left button clicked on one of the line end points, this point
   //     follows the cursor until button is released.
	//
   //  if Middle button clicked, the line is moved parallel to itself
   //     until the button is released.

409 410
        if ( !IsMovable() ) return;

411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427
	Int_t kMaxDiff = 20;
	static Int_t d1,d2,px1,px2,py1,py2;
	static Int_t pxold, pyold, px1old, py1old, px2old, py2old;
	static Bool_t p1, p2, pL;
	Double_t dpx,dpy,xp1,yp1;
	Int_t dx, dy;
	Double_t vx0,vx1,vx2,vx3,vy0,vy1,vy2,vy3;
	vx0 = fLabel0.GetX() - GetX1(); vy0 = fLabel0.GetY() - GetY1(); // offsets label 0
	vx1 = fLabel1.GetX() - GetX2(); vy1 = fLabel1.GetY() - GetY1(); // offsets label 1
	vx2 = fLabel2.GetX() - GetX2(); vy2 = fLabel2.GetY() - GetY1(); // offsets label 2
	vx3 = fLabel3.GetX() - GetX1(); vy3 = fLabel3.GetY() - GetY1(); // offsets label 3

	if (!gPad->IsEditable()) return;
	switch (event) {

		case kButton1Down:
			gVirtualX->SetLineColor(-1);
Jérémie Dudouet's avatar
Jérémie Dudouet committed
428 429 430 431
            TAttLine::Modify();  //Change line attributes only if necessary
            /* fall through */

        case kMouseMotion:
432 433 434 435 436 437 438 439 440 441 442 443 444 445

			if (TestBit(kLineNDC)) {
				px1 = gPad->UtoPixel(fX1);
				py1 = gPad->VtoPixel(fY1);
				px2 = gPad->UtoPixel(fX2);
				py2 = gPad->VtoPixel(fY2);
			} else {
				px1 = gPad->XtoAbsPixel(gPad->XtoPad(fX1));
				py1 = gPad->YtoAbsPixel(gPad->YtoPad(fY1));
				px2 = gPad->XtoAbsPixel(gPad->XtoPad(fX2));
				py2 = gPad->YtoAbsPixel(gPad->YtoPad(fY2));
			}
			p1 = p2 = pL = kFALSE;

Stezowski Olivier's avatar
Stezowski Olivier committed
446
			d1  = TMath::Abs(px1 - px) + TMath::Abs(py1-py); //simply take sum of pixels differences
447 448 449 450 451 452
			if (d1 < kMaxDiff) { //*-*================>OK take point number 1
				px1old = px1; py1old = py1;
				p1 = kTRUE;
				gPad->SetCursor(kPointer);
				return;
			}
Stezowski Olivier's avatar
Stezowski Olivier committed
453
			d2  = TMath::Abs(px2 - px) + TMath::Abs(py2-py); //simply take sum of pixels differences
454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552
			if (d2 < kMaxDiff) { //*-*================>OK take point number 2
				px2old = px2; py2old = py2;
				p2 = kTRUE;
				gPad->SetCursor(kPointer);
				return;
			}

			pL = kTRUE;
			pxold = px; pyold = py;
			gPad->SetCursor(kMove);

			break;

		case kButton1Motion:

			if (p1) {
				gVirtualX->DrawLine(px1old, py1old, px2, py2);
				gVirtualX->DrawLine(px, py, px2, py2);
				px1old = px;
				py1old = py;
			}
			if (p2) {
				gVirtualX->DrawLine(px1, py1, px2old, py2old);
				gVirtualX->DrawLine(px1, py1, px, py);
				px2old = px;
				py2old = py;
			}
			if (pL) {
				gVirtualX->DrawLine(px1, py1, px2, py2);
				dx = px-pxold;  dy = py-pyold;
				px1 += dx; py1 += dy; px2 += dx; py2 += dy;
				gVirtualX->DrawLine(px1, py1, px2, py2);
				pxold = px;
				pyold = py;
			}
			break;

		case kButton1Up:

			if (TestBit(kLineNDC)) {
				dpx  = gPad->GetX2() - gPad->GetX1();
				dpy  = gPad->GetY2() - gPad->GetY1();
				xp1  = gPad->GetX1();
				yp1  = gPad->GetY1();
				if (p1) {
					fX1 = (gPad->AbsPixeltoX(px)-xp1)/dpx;
					fY1 = (gPad->AbsPixeltoY(py)-yp1)/dpy;
					fY2 = fY1;
				}
				if (p2) {
					fX2 = (gPad->AbsPixeltoX(px)-xp1)/dpx;
					fY2 = (gPad->AbsPixeltoY(py)-yp1)/dpy;
					fY1 = fY2;
				}
				if (pL) {
					fX1 = (gPad->AbsPixeltoX(px1)-xp1)/dpx;
					fY1 = (gPad->AbsPixeltoY(py1)-yp1)/dpy;
					fX2 = (gPad->AbsPixeltoX(px2)-xp1)/dpx;
					fY2 = (gPad->AbsPixeltoY(py2)-yp1)/dpy;
				}
				if (fX1 <= fX2 ) {
					//vx = fLabel0.GetX()-fX1;
					fLabel0.SetX(fX1+vx0); fLabel0.SetY(fY1+vy0);
					fLabel1.SetX(fX2); fLabel1.SetY(fY1);
					fLabel2.SetX(fX2); fLabel2.SetY(fY1);
					fLabel3.SetX(fX1); fLabel3.SetY(fY1);
				} else {
					fLabel1.SetX(fX1); fLabel1.SetY(fY1);
					fLabel0.SetX(fX2+vx0); fLabel0.SetY(fY1+vy0);
					fLabel3.SetX(fX2); fLabel3.SetY(fY1);
					fLabel2.SetX(fX1); fLabel2.SetY(fY1);
				}
			} else {
				if (p1) {
					fX1 = gPad->PadtoX(gPad->AbsPixeltoX(px));
					fY1 = gPad->PadtoY(gPad->AbsPixeltoY(py));
					fY2 = fY1;
				}
				if (p2) {
					fX2 = gPad->PadtoX(gPad->AbsPixeltoX(px));
					fY2 = gPad->PadtoY(gPad->AbsPixeltoY(py));
					fY1 = fY2;
				}
				if (pL) {
					fX1 = gPad->PadtoX(gPad->AbsPixeltoX(px1));
					fY1 = gPad->PadtoY(gPad->AbsPixeltoY(py1));
					fX2 = gPad->PadtoX(gPad->AbsPixeltoX(px2));
					fY2 = gPad->PadtoY(gPad->AbsPixeltoY(py2));
				}
				if (fX1 > fX2) {
					Double_t fX3;
					fX3 = fX1;
					fX1 = fX2;
					fX2 = fX3;
				}
				fLabel0.SetX(fX1+vx0); fLabel0.SetY(fY1+vy0);
				fLabel1.SetX(fX2+vx1); fLabel1.SetY(fY1+vy1);
				fLabel2.SetX(fX2+vx2); fLabel2.SetY(fY1+vy2);
				fLabel3.SetX(fX1+vx3); fLabel3.SetY(fY1+vy3);
553

554 555 556 557 558 559 560 561 562
			    if (fHasExtra) {
				  if (fExtra.GetX1() < fX1)
					fExtra.SetX2(fX1);
				  
				  if (fExtra.GetX2() > fX2)
					fExtra.SetX1(fX2);
				  
				  fExtra.SetY1(fY1); fExtra.SetY2(fY1);
				}
563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594
				/*if (fX1 <= fX2 ) {
					fLabel0.SetX(fX1+vx0); fLabel0.SetY(fY1+vy0);
					fLabel1.SetX(fX2); fLabel1.SetY(fY1);
					fLabel2.SetX(fX2); fLabel2.SetY(fY1);
					fLabel3.SetX(fX1); fLabel3.SetY(fY1);
				} else {
					fLabel1.SetX(fX1); fLabel1.SetY(fY1);
					fLabel0.SetX(fX2+vx0); fLabel0.SetY(fY1+vy0);
					fLabel3.SetX(fX2); fLabel3.SetY(fY1);
					fLabel2.SetX(fX1); fLabel2.SetY(fY1);
				}*/
			}
			gPad->Modified(kTRUE);
			gVirtualX->SetLineColor(-1);
			break;

		case kButton1Locate:

			ExecuteEvent(kButton1Down, px, py);
			while (1) {
				px = py = 0;
				event = gVirtualX->RequestLocator(1,1,px,py);

				ExecuteEvent(kButton1Motion, px, py);

				if (event != -1) {                     // button is released
					ExecuteEvent(kButton1Up, px, py);
					return;
				}
			}
	}

595
}