65 ClassImp(TGDoubleSlider);
66 ClassImp(TGDoubleVSlider);
67 ClassImp(TGDoubleHSlider);
72 TGDoubleSlider::TGDoubleSlider(
const TGWindow *p, UInt_t w, UInt_t h, UInt_t type, Int_t
id,
73 UInt_t options, ULong_t back,
74 Bool_t reversed, Bool_t mark_ends)
75 : TGFrame(p, w, h, options, back)
80 fWidgetFlags = kWidgetWantFocus;
87 fPos = fSmin = fSmax = 0.0;
91 fPressSmin = fPressSmax = 0.0;
93 fReversedScale = reversed;
94 fMarkEnds = mark_ends;
96 gVirtualX->GrabButton(fId, kAnyButton, kAnyModifier,
97 kButtonPressMask | kButtonReleaseMask |
98 kPointerMotionMask, kNone, kNone);
99 AddInput(kPointerMotionMask);
106 void TGDoubleSlider::FixBounds(Float_t &min, Float_t &max)
108 if (min > max) min = max;
111 if (max - min < eps) {
126 TString TGDoubleSlider::GetSString()
const
131 if (fScaleType & kDoubleScaleNo) {
132 if (stype.Length() == 0)
133 stype =
"kDoubleScaleNo";
135 stype +=
" | kDoubleScaleNo";
137 if (fScaleType & kDoubleScaleDownRight) {
138 if (stype.Length() == 0)
139 stype =
"kDoubleScaleDownRight";
141 stype +=
" | kDoubleScaleDownRight";
143 if (fScaleType & kDoubleScaleBoth) {
144 if (stype.Length() == 0)
145 stype =
"kDoubleScaleBoth";
147 stype +=
" | kDoubleScaleBoth";
156 void TGDoubleSlider::ChangeCursor(Event_t *event)
158 static Cursor_t topCur = kNone, leftCur = kNone;
159 static Cursor_t botCur = kNone, rightCur = kNone;
160 Int_t hw = 0, wh = 0, xy = 0, yx = 0;
161 Cursor_t minCur = kNone, maxCur = kNone;
164 topCur = gVirtualX->CreateCursor(kTopSide);
165 if (leftCur == kNone)
166 leftCur = gVirtualX->CreateCursor(kLeftSide);
168 botCur = gVirtualX->CreateCursor(kBottomSide);
169 if (rightCur == kNone)
170 rightCur = gVirtualX->CreateCursor(kRightSide);
171 if (GetOptions() & kVerticalFrame) {
174 xy = (Int_t)event->fX;
175 yx = (Int_t)
event->fY;
179 else if (GetOptions() & kHorizontalFrame) {
182 xy = (Int_t)event->fY;
183 yx = (Int_t)
event->fX;
189 Int_t relMin = (Int_t)((wh-16) * (fSmin - fVmin) / (fVmax - fVmin)) + 1;
190 Int_t relMax = (Int_t)((wh-16) * (fSmax - fVmin) / (fVmax - fVmin) + 15);
192 if (xy > hw/2-7 && xy < hw/2+7 && fMove != 3) {
196 if ((yx <= (relMax - relMin) / 4 + relMin) &&
197 (yx >= relMin) && (fMove != 2))
198 gVirtualX->SetCursor(fId, minCur);
202 else if ((yx >= (relMax - relMin) / 4 * 3 + relMin) &&
203 (yx <= relMax) && (fMove != 1))
204 gVirtualX->SetCursor(fId, maxCur);
206 else if ((fMove < 1) || (fMove > 2))
207 gVirtualX->SetCursor(fId, kNone);
211 else if ((fMove < 1) || (fMove > 2))
212 gVirtualX->SetCursor(fId, kNone);
218 TGDoubleVSlider::TGDoubleVSlider(
const TGWindow *p, UInt_t h, UInt_t type, Int_t
id,
219 UInt_t options, ULong_t back,
220 Bool_t reversed, Bool_t mark_ends)
221 : TGDoubleSlider(p, kDoubleSliderWidth, h, type, id, options, back,
225 fSliderPic = fClient->GetPicture(
"sliderv.xpm");
228 Error(
"TGDoubleVSlider",
"sliderv.xpm not found");
230 fSmin = h/8*3; fSmax = h/8*5; fVmin = 0; fVmax = h;
231 FixBounds(fVmin, fVmax);
238 TGDoubleVSlider::~TGDoubleVSlider()
240 if (fSliderPic) fClient->FreePicture(fSliderPic);
246 void TGDoubleVSlider::DoRedraw()
248 FixBounds(fVmin, fVmax);
251 gVirtualX->ClearWindow(fId);
253 if (fSmin < fVmin) fSmin = fVmin;
254 if (fSmax < fVmin) fSmax = fVmin;
255 if (fSmin > fVmax) fSmin = fVmax;
256 if (fSmax > fVmax) fSmax = fVmax;
257 if (fSmin > fSmax) fSmin = fSmax = (fSmin + fSmax) / 2;
259 int relMin = (int)((fHeight-16) * (fSmin - fVmin) / (fVmax - fVmin)) + 1;
260 int relMax = (int)((fHeight-16) * (fSmax - fVmin) / (fVmax - fVmin) + 15);
262 gVirtualX->DrawLine(fId, GetHilightGC()(), fWidth/2-6, relMin, fWidth/2+5, relMin);
263 gVirtualX->DrawLine(fId, GetHilightGC()(), fWidth/2-6, relMin, fWidth/2-6, relMax);
264 gVirtualX->DrawLine(fId, GetBlackGC()(), fWidth/2+5, relMax, fWidth/2-6, relMax);
265 gVirtualX->DrawLine(fId, GetBlackGC()(), fWidth/2+5, relMax, fWidth/2+5, relMin);
268 gVirtualX->DrawLine(fId, GetShadowGC()(), fWidth/2-1, 8, fWidth/2-1, relMin-1);
269 gVirtualX->DrawLine(fId, GetHilightGC()(), fWidth/2+1, 8, fWidth/2+1, relMin-1);
270 gVirtualX->DrawLine(fId, GetBlackGC()(), fWidth/2, 8, fWidth/2, relMin-1);
272 if (relMax+1 < (
int)fHeight-8) {
273 gVirtualX->DrawLine(fId, GetShadowGC()(), fWidth/2-1, relMax+1, fWidth/2-1, fHeight-8);
274 gVirtualX->DrawLine(fId, GetHilightGC()(), fWidth/2+1, relMax+1, fWidth/2+1, fHeight-8);
275 gVirtualX->DrawLine(fId, GetBlackGC()(), fWidth/2, relMax+1, fWidth/2, fHeight-8);
279 if (fScale == 1) fScale++;
280 if (fScale * 2 > (
int)fHeight) fScale = 0;
281 if (fScale > 0 && !(fScaleType & kDoubleScaleNo)) {
282 int lines = ((int)fHeight-16) / fScale;
283 int remain = ((int)fHeight-16) % fScale;
284 if (lines < 1) lines = 1;
285 for (
int i = 0; i <= lines; i++) {
286 int y = i * fScale + (i * remain) / lines;
287 gVirtualX->DrawLine(fId, GetBlackGC()(), fWidth/2+8, y+7, fWidth/2+10, y+7);
288 if ((fScaleType & kDoubleScaleBoth))
289 gVirtualX->DrawLine(fId, GetBlackGC()(), fWidth/2-9, y+7, fWidth/2-11, y+7);
294 Int_t xpos = (fWidth/2) - (fSliderPic->GetWidth()/2);
295 Int_t ypos = relMin + 2;
296 fSliderPic->Draw(fId, GetBckgndGC()(), xpos, ypos);
297 ypos = relMax - fSliderPic->GetHeight() - 2;
298 fSliderPic->Draw(fId, GetBckgndGC()(), xpos, ypos);
302 int y1 = (relMax - relMin) / 4 + relMin;
303 int y2 = (relMax - relMin) / 4 * 3 + relMin;
304 gVirtualX->DrawLine(fId, GetBlackGC()(), fWidth/2-6, y1, fWidth/2+5, y1);
305 gVirtualX->DrawLine(fId, GetBlackGC()(), fWidth/2-6, y2, fWidth/2+5, y2);
312 Bool_t TGDoubleVSlider::HandleButton(Event_t *event)
314 if (event->fType == kButtonPress && event->fCode == kButton1) {
316 if (event->fX < (Int_t)fWidth/2-7 || event->fX > (Int_t)fWidth/2+7) {
319 fPressPoint =
event->fY;
323 int relMin = (int)((fHeight-16) * (fSmin - fVmin) / (fVmax - fVmin)) + 1;
324 int relMax = (int)((fHeight-16) * (fSmax - fVmin) / (fVmax - fVmin) + 15);
325 if (fPressPoint < (relMax - relMin) / 4 + relMin)
328 else if (fPressPoint > (relMax - relMin) / 4 * 3 + relMin)
335 SendMessage(fMsgWindow, MK_MSG(kC_VSLIDER, kSL_PRESS), fWidgetId, 0);
336 fClient->ProcessLine(fCommand, MK_MSG(kC_VSLIDER, kSL_PRESS), fWidgetId, 0);
340 gVirtualX->GrabPointer(fId, kButtonPressMask | kButtonReleaseMask |
341 kPointerMotionMask, kNone, kNone,
343 }
else if (event->fType == kButtonRelease && event->fCode == kButton1) {
344 SendMessage(fMsgWindow, MK_MSG(kC_VSLIDER, kSL_RELEASE), fWidgetId, 0);
345 fClient->ProcessLine(fCommand, MK_MSG(kC_VSLIDER, kSL_RELEASE), fWidgetId, 0);
349 gVirtualX->GrabPointer(0, 0, 0, 0, kFALSE);
359 Bool_t TGDoubleVSlider::HandleMotion(Event_t *event)
362 if (fMove == 0)
return kTRUE;
364 static Long64_t was = gSystem->Now();
365 Long64_t now = gSystem->Now();
367 if ((now-was) < 50)
return kTRUE;
371 Float_t oldMin, oldMax;
373 diff =
event->fY - fPressPoint;
379 fSmin = fPressSmin + diff * (fVmax - fVmin) / (fHeight-16);
380 if (fSmin < fVmin) fSmin = fVmin;
381 if (fSmin > fSmax) fSmin = fSmax;
382 }
else if (fMove == 2) {
384 fSmax = fPressSmax + diff * (fVmax - fVmin) / (fHeight-16);
385 if (fSmax > fVmax) fSmax = fVmax;
386 if (fSmax < fSmin) fSmax = fSmin;
387 }
else if (fMove == 3) {
390 logicalDiff = diff * (fVmax - fVmin) / (fHeight-16);
391 if (fPressSmax + logicalDiff > fVmax)
392 logicalDiff = fVmax - fPressSmax;
393 if (fPressSmin + logicalDiff < fVmin)
394 logicalDiff = fVmin - fPressSmin;
395 fSmax = fPressSmax + logicalDiff;
396 fSmin = fPressSmin + logicalDiff;
400 if (fMove != 0 && (fSmax != oldMax || fSmin != oldMin)) {
401 fClient->NeedRedraw(
this);
402 SendMessage(fMsgWindow, MK_MSG(kC_VSLIDER, kSL_POS), fWidgetId, 0);
403 fClient->ProcessLine(fCommand, MK_MSG(kC_VSLIDER, kSL_POS), fWidgetId, 0);
412 TGDoubleHSlider::TGDoubleHSlider(
const TGWindow *p, UInt_t w, UInt_t type, Int_t
id,
413 UInt_t options, ULong_t back,
414 Bool_t reversed, Bool_t mark_ends)
415 : TGDoubleSlider(p, w, kDoubleSliderHeight, type, id, options, back,
419 fSliderPic = fClient->GetPicture(
"sliderh.xpm");
422 Error(
"TGDoubleHSlider",
"sliderh.xpm not found");
424 fSmin = w/8*3; fSmax = w/8*5; fVmin = 0; fVmax = w;
425 FixBounds(fVmin, fVmax);
432 TGDoubleHSlider::~TGDoubleHSlider()
434 if (fSliderPic) fClient->FreePicture(fSliderPic);
440 void TGDoubleHSlider::DoRedraw()
442 FixBounds(fVmin, fVmax);
445 gVirtualX->ClearWindow(fId);
447 if (fSmin < fVmin) fSmin = fVmin;
448 if (fSmax > fVmax) fSmax = fVmax;
449 if (fSmin > fSmax) fSmin = fSmax = (fSmin + fSmax) / 2;
451 int relMin = (int)((fWidth-16) * (fSmin - fVmin) / (fVmax - fVmin)) + 1;
452 int relMax = (int)((fWidth-16) * (fSmax - fVmin) / (fVmax - fVmin) + 15);
454 gVirtualX->DrawLine(fId, GetHilightGC()(), relMin, fHeight/2-6, relMin, fHeight/2+5);
455 gVirtualX->DrawLine(fId, GetHilightGC()(), relMax, fHeight/2-6, relMin, fHeight/2-6);
456 gVirtualX->DrawLine(fId, GetBlackGC()(), relMax, fHeight/2+5, relMax, fHeight/2-6);
457 gVirtualX->DrawLine(fId, GetBlackGC()(), relMin, fHeight/2+5, relMax, fHeight/2+5);
460 gVirtualX->DrawLine(fId, GetShadowGC()(), 8, fHeight/2-1, relMin-1, fHeight/2-1);
461 gVirtualX->DrawLine(fId, GetHilightGC()(), 8, fHeight/2+1, relMin-1, fHeight/2+1);
462 gVirtualX->DrawLine(fId, GetBlackGC()(), 8, fHeight/2, relMin-1, fHeight/2);
464 if (relMax+1 < (
int)fWidth-8) {
465 gVirtualX->DrawLine(fId, GetShadowGC()(), relMax+1, fHeight/2-1, fWidth-8, fHeight/2-1);
466 gVirtualX->DrawLine(fId, GetHilightGC()(), relMax+1, fHeight/2+1, fWidth-8, fHeight/2+1);
467 gVirtualX->DrawLine(fId, GetBlackGC()(), relMax+1, fHeight/2, fWidth-8, fHeight/2);
470 if (fScale == 1) fScale++;
471 if (fScale * 2 > (
int)fWidth) fScale = 0;
472 if (fScale > 0 && !(fScaleType & kDoubleScaleNo)) {
473 int lines = ((int)fWidth-16) / fScale;
474 int remain = ((int)fWidth-16) % fScale;
475 if (lines < 1) lines = 1;
476 for (
int i = 0; i <= lines; i++) {
477 int x = i * fScale + (i * remain) / lines;
478 gVirtualX->DrawLine(fId, GetBlackGC()(), x+7, fHeight/2+8, x+7, fHeight/2+10);
479 if ((fScaleType & kDoubleScaleBoth))
480 gVirtualX->DrawLine(fId, GetBlackGC()(), x+7, fHeight/2-9, x+7, fHeight/2-11);
485 Int_t ypos = (fHeight/2) - (fSliderPic->GetHeight()/2);
486 Int_t xpos = relMin + 2;
487 fSliderPic->Draw(fId, GetBckgndGC()(), xpos, ypos);
488 xpos = relMax - fSliderPic->GetWidth() - 2;
489 fSliderPic->Draw(fId, GetBckgndGC()(), xpos, ypos);
493 int x1 = (relMax - relMin) / 4 + relMin;
494 int x2 = (relMax - relMin) / 4 * 3 + relMin;
495 gVirtualX->DrawLine(fId, GetBlackGC()(), x1, fHeight/2-6, x1, fHeight/2+5);
496 gVirtualX->DrawLine(fId, GetBlackGC()(), x2, fHeight/2-6, x2, fHeight/2+5);
503 Bool_t TGDoubleHSlider::HandleButton(Event_t *event)
505 if (event->fType == kButtonPress && event->fCode == kButton1) {
507 if (event->fY < (Int_t)fHeight/2-7 || event->fY > (Int_t)fHeight/2+7) {
510 fPressPoint =
event->fX;
514 int relMin = (int)((fWidth-16) * (fSmin - fVmin) / (fVmax - fVmin)) + 1;
515 int relMax = (int)((fWidth-16) * (fSmax - fVmin) / (fVmax - fVmin) + 15);
516 if (fPressPoint < (relMax - relMin) / 4 + relMin)
519 else if (fPressPoint > (relMax - relMin) / 4 * 3 + relMin)
526 SendMessage(fMsgWindow, MK_MSG(kC_HSLIDER, kSL_PRESS), fWidgetId, 0);
527 fClient->ProcessLine(fCommand, MK_MSG(kC_HSLIDER, kSL_PRESS), fWidgetId, 0);
531 gVirtualX->GrabPointer(fId, kButtonPressMask | kButtonReleaseMask |
532 kPointerMotionMask, kNone, kNone,
534 }
else if (event->fType == kButtonRelease && event->fCode == kButton1) {
535 SendMessage(fMsgWindow, MK_MSG(kC_HSLIDER, kSL_RELEASE), fWidgetId, 0);
536 fClient->ProcessLine(fCommand, MK_MSG(kC_HSLIDER, kSL_RELEASE), fWidgetId, 0);
540 gVirtualX->GrabPointer(0, 0, 0, 0, kFALSE);
550 Bool_t TGDoubleHSlider::HandleMotion(Event_t *event)
553 if (fMove == 0)
return kTRUE;
555 static Long64_t was = gSystem->Now();
556 Long64_t now = gSystem->Now();
558 if ((now-was) < 50)
return kTRUE;
562 Float_t oldMin, oldMax;
564 diff =
event->fX - fPressPoint;
570 fSmin = fPressSmin + diff * (fVmax - fVmin) / (fWidth-16);
571 if (fSmin < fVmin) fSmin = fVmin;
572 if (fSmin > fSmax) fSmin = fSmax;
573 }
else if (fMove == 2) {
575 fSmax = fPressSmax + diff * (fVmax - fVmin) / (fWidth-16);
576 if (fSmax > fVmax) fSmax = fVmax;
577 if (fSmax < fSmin) fSmax = fSmin;
578 }
else if (fMove == 3) {
581 logicalDiff = diff * (fVmax - fVmin) / (fWidth-16);
582 if (fPressSmax + logicalDiff > fVmax)
583 logicalDiff = fVmax - fPressSmax;
584 if (fPressSmin + logicalDiff < fVmin)
585 logicalDiff = fVmin - fPressSmin;
586 fSmax = fPressSmax + logicalDiff;
587 fSmin = fPressSmin + logicalDiff;
591 if (fMove != 0 && (fSmax != oldMax || fSmin != oldMin)) {
592 fClient->NeedRedraw(
this);
593 SendMessage(fMsgWindow, MK_MSG(kC_HSLIDER, kSL_POS), fWidgetId, 0);
594 fClient->ProcessLine(fCommand, MK_MSG(kC_HSLIDER, kSL_POS), fWidgetId, 0);
603 void TGDoubleHSlider::SavePrimitive(std::ostream &out, Option_t *option )
605 SaveUserColor(out, option);
607 out <<
" TGDoubleHSlider *";
608 out << GetName() <<
" = new TGDoubleHSlider(" << fParent->GetName()
609 <<
"," << GetWidth() <<
",";
610 out << GetSString() <<
"," << WidgetId() <<
",";
611 out << GetOptionString() <<
",ucolor";
614 out <<
",kTRUE,kTRUE);" << std::endl;
616 out <<
",kFALSE,kTRUE);" << std::endl;
617 }
else if (fReversedScale) {
618 out <<
",kTRUE);" << std::endl;
620 out <<
");" << std::endl;
622 if (option && strstr(option,
"keep_names"))
623 out <<
" " << GetName() <<
"->SetName(\"" << GetName() <<
"\");" << std::endl;
625 if (fVmin != 0 || fVmax != (Int_t)fWidth)
626 out <<
" " << GetName() <<
"->SetRange(" << fVmin <<
"," << fVmax
627 <<
");" << std::endl;
629 if (fSmin != fWidth/8*3 || fSmax != fWidth/8*5)
630 out <<
" " << GetName() <<
"->SetPosition(" << GetMinPosition()
631 <<
"," << GetMaxPosition() <<
");" << std::endl;
634 out <<
" " << GetName() <<
"->SetScale(" << fScale <<
");" << std::endl;
641 void TGDoubleVSlider::SavePrimitive(std::ostream &out, Option_t *option )
643 SaveUserColor(out, option);
645 out<<
" TGDoubleVSlider *";
646 out << GetName() <<
" = new TGDoubleVSlider("<< fParent->GetName()
647 <<
"," << GetHeight() <<
",";
648 out << GetSString() <<
"," << WidgetId() <<
",";
649 out << GetOptionString() <<
",ucolor";
652 out <<
",kTRUE,kTRUE);" << std::endl;
654 out <<
",kFALSE,kTRUE);" << std::endl;
655 }
else if (fReversedScale) {
656 out <<
",kTRUE);" << std::endl;
658 out <<
");" << std::endl;
660 if (option && strstr(option,
"keep_names"))
661 out <<
" " << GetName() <<
"->SetName(\"" << GetName() <<
"\");" << std::endl;
663 if (fVmin != 0 || fVmax != (Int_t)fHeight)
664 out <<
" " << GetName() <<
"->SetRange(" << fVmin <<
"," << fVmax
665 <<
");" << std::endl;
668 if (fSmin != fHeight/8*3 || fSmax != fHeight/8*5)
669 out <<
" " << GetName() <<
"->SetPosition(" << GetMinPosition()
670 <<
"," << GetMaxPosition() <<
");" << std::endl;
674 out <<
" " << GetName() <<
"->SetScale(" << fScale <<
");" << std::endl;