Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 6 additions & 10 deletions graf2d/gpad/inc/TSliderBox.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Author: Rene Brun 23/11/96

/*************************************************************************
* Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
* Copyright (C) 1995-2026, Rene Brun and Fons Rademakers. *
* All rights reserved. *
* *
* For the licensing terms see $ROOTSYS/LICENSE. *
Expand All @@ -12,30 +12,26 @@
#ifndef ROOT_TSliderBox
#define ROOT_TSliderBox


#include "TWbox.h"

class TSlider;

class TSliderBox : public TWbox {

protected:
TSlider *fSlider; ///< Pointer to slider
TSlider *fSlider = nullptr; ///< Pointer to slider

TSliderBox(const TSliderBox& sb)
: TWbox(sb), fSlider(sb.fSlider) { }
TSliderBox& operator=(const TSliderBox& sb)
{if(this!=&sb) {TWbox::operator=(sb); fSlider=sb.fSlider;}
return *this; }
TSliderBox(const TSliderBox&) = delete;
TSliderBox& operator=(const TSliderBox&) = delete;

public:
TSliderBox();
TSliderBox(Double_t x1, Double_t y1,Double_t x2 ,Double_t y2,
Color_t color=18, Short_t bordersize=2 ,Short_t bordermode=-1);
Color_t color=18, Short_t bordersize=2, Short_t bordermode=-1);
~TSliderBox() override;
void ExecuteEvent(Int_t event, Int_t px, Int_t py) override;
void SavePrimitive(std::ostream &out, Option_t *option = "") override;
void SetSlider(TSlider*slider) { fSlider=slider; }
void SetSlider(TSlider*slider) { fSlider = slider; }

ClassDefOverride(TSliderBox,1) //The moving box of a TSlider
};
Expand Down
1 change: 0 additions & 1 deletion graf2d/gpad/src/TPad.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
#include "TBaseClass.h"
#include "TClassTable.h"
#include "TVirtualPS.h"
#include "TVirtualX.h"
#include "TVirtualViewer3D.h"
#include "TView.h"
#include "TPoint.h"
Expand Down
244 changes: 30 additions & 214 deletions graf2d/gpad/src/TSliderBox.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Author: Rene Brun 23/11/96

/*************************************************************************
* Copyright (C) 1995-2021, Rene Brun and Fons Rademakers. *
* Copyright (C) 1995-2026, Rene Brun and Fons Rademakers. *
* All rights reserved. *
* *
* For the licensing terms see $ROOTSYS/LICENSE. *
Expand All @@ -12,7 +12,7 @@
#include "TROOT.h"
#include "TSlider.h"
#include "TSliderBox.h"
#include "TVirtualX.h"
#include "TMath.h"

#include <cstring>

Expand Down Expand Up @@ -48,240 +48,56 @@ TSliderBox::~TSliderBox()
{
}


////////////////////////////////////////////////////////////////////////////////
/// Interaction with a slider.

void TSliderBox::ExecuteEvent(Int_t event, Int_t px, Int_t py)
{
if (!gPad) return;

const Int_t kMaxDiff = 5;
const Int_t kMinSize = 20;

static Int_t px1, px2, py1, py2, pxl, pyl, pxt, pyt, pxold, pyold;
static Int_t px1p, px2p, py1p, py2p;
static Bool_t pL, pR, pTop, pBot, pINSIDE;
Int_t wx, wy;
Bool_t doing_again = kFALSE;
Bool_t opaque = gPad->OpaqueMoving();
Bool_t ropaque = gPad->OpaqueResizing();

TVirtualPad *parent = gPad;

Int_t border = parent->GetBorderSize();
Int_t pxpadmin = parent->XtoAbsPixel(parent->GetX1()) + border;
Int_t pxpadmax = parent->XtoAbsPixel(parent->GetX2()) - border;
Int_t pypadmin = parent->YtoAbsPixel(parent->GetY1()) - border;
Int_t pypadmax = parent->YtoAbsPixel(parent->GetY2()) + border;

Bool_t vertical = kTRUE;
if (pxpadmax-pxpadmin > pypadmin-pypadmax) vertical = kFALSE;

again:

switch (event) {
Bool_t vertical = fSlider ? fSlider->GetAbsWNDC() < fSlider->GetAbsHNDC() : kTRUE;

case kButton1Down:
TWbox::ExecuteEvent((vertical ? 20000 : 10000) + event, px, py);

gVirtualX->SetLineColor(-1);
TAttLine::Modify(); //Change line attributes only if necessary
if (GetFillColor())
gVirtualX->SetLineColor(GetFillColor());
else
gVirtualX->SetLineColor(1);
gVirtualX->SetLineWidth(2);

// No break !!!
if (!fSlider)
return;

case kMouseMotion:
Int_t bordersize = fSlider->GetBorderSize();
Double_t dx = fSlider->PixeltoX(bordersize);
Double_t dy = fSlider->PixeltoY(-bordersize);
Double_t v1, v2, d;

px1 = gPad->XtoAbsPixel(GetX1());
py1 = gPad->YtoAbsPixel(GetY1());
px2 = gPad->XtoAbsPixel(GetX2());
py2 = gPad->YtoAbsPixel(GetY2());
// Give control to object using the slider
if (vertical) {
v1 = GetY1();
v2 = GetY2();
d = TMath::Min(0.3, dy);
} else {
v1 = GetX1();
v2 = GetX2();
d = TMath::Min(0.3, dx);
}
fSlider->SetMinimum(TMath::Max(0., (v1 - d) / (1 - 2*d)));
fSlider->SetMaximum(TMath::Min(1., (v2 - d) / (1 - 2*d)));

if (px1 < px2) {
pxl = px1;
pxt = px2;
} else {
pxl = px2;
pxt = px1;
}
if (py1 < py2) {
pyl = py1;
pyt = py2;
if (event == kButton1Up) {
if (vertical) {
SetX1(dx); SetX2(1 - dx);
} else {
pyl = py2;
pyt = py1;
}

px1p = pxpadmin;
py1p = pypadmin;
px2p = pxpadmax;
py2p = pypadmax;

pL = pR = pTop = pBot = pINSIDE = kFALSE;

if (vertical && (px > pxl+kMaxDiff && px < pxt-kMaxDiff) &&
std::abs(py - pyl) < kMaxDiff) { // top edge
pxold = pxl; pyold = pyl; pTop = kTRUE;
gPad->SetCursor(kTopSide);
}

if (vertical && (px > pxl+kMaxDiff && px < pxt-kMaxDiff) &&
std::abs(py - pyt) < kMaxDiff) { // bottom edge
pxold = pxt; pyold = pyt; pBot = kTRUE;
gPad->SetCursor(kBottomSide);
}

if (!vertical && (py > pyl+kMaxDiff && py < pyt-kMaxDiff) &&
std::abs(px - pxl) < kMaxDiff) { // left edge
pxold = pxl; pyold = pyl; pL = kTRUE;
gPad->SetCursor(kLeftSide);
}

if (!vertical && (py > pyl+kMaxDiff && py < pyt-kMaxDiff) &&
std::abs(px - pxt) < kMaxDiff) { // right edge
pxold = pxt; pyold = pyt; pR = kTRUE;
gPad->SetCursor(kRightSide);
}

if ((px > pxl+kMaxDiff && px < pxt-kMaxDiff) &&
(py > pyl+kMaxDiff && py < pyt-kMaxDiff)) { // inside box
pxold = px; pyold = py; pINSIDE = kTRUE;
if (event == kButton1Down)
gPad->SetCursor(kMove);
else
gPad->SetCursor(kCross);
}

fResizing = kFALSE;
if ( pL || pR || pTop || pBot)
fResizing = kTRUE;

if ( !pL && !pR && !pTop && !pBot && !pINSIDE)
gPad->SetCursor(kCross);

break;

case kButton1Motion:

wx = wy = 0;

if (pTop) {
if (!ropaque) gVirtualX->DrawBox(px1, py1, px2, py2, TVirtualX::kHollow);
py2 += py - pyold;
if (py2 > py1-kMinSize) { py2 = py1-kMinSize; wy = py2; }
if (py2 < py2p) { py2 = py2p; wy = py2; }
if (!ropaque) gVirtualX->DrawBox(px1, py1, px2, py2, TVirtualX::kHollow);
}
if (pBot) {
if (!ropaque) gVirtualX->DrawBox(px1, py1, px2, py2, TVirtualX::kHollow);
py1 += py - pyold;
if (py1 < py2+kMinSize) { py1 = py2+kMinSize; wy = py1; }
if (py1 > py1p) { py1 = py1p; wy = py1; }
if (!ropaque) gVirtualX->DrawBox(px1, py1, px2, py2, TVirtualX::kHollow);
}
if (pL) {
if (!ropaque) gVirtualX->DrawBox(px1, py1, px2, py2, TVirtualX::kHollow);
px1 += px - pxold;
if (px1 > px2-kMinSize) { px1 = px2-kMinSize; wx = px1; }
if (px1 < px1p) { px1 = px1p; wx = px1; }
if (!ropaque) gVirtualX->DrawBox(px1, py1, px2, py2, TVirtualX::kHollow);
}
if (pR) {
if (!ropaque) gVirtualX->DrawBox(px1, py1, px2, py2, TVirtualX::kHollow);
px2 += px - pxold;
if (px2 < px1+kMinSize) { px2 = px1+kMinSize; wx = px2; }
if (px2 > px2p) { px2 = px2p; wx = px2; }
if (!ropaque) gVirtualX->DrawBox(px1, py1, px2, py2, TVirtualX::kHollow);
}
if (pINSIDE) {
if (!opaque) gVirtualX->DrawBox(px1, py1, px2, py2, TVirtualX::kHollow); // draw the old box
Int_t dx = px - pxold;
Int_t dy = py - pyold;
px1 += dx; py1 += dy; px2 += dx; py2 += dy;
if (px1 < px1p) { dx = px1p - px1; px1 += dx; px2 += dx; wx = px+dx; }
if (px2 > px2p) { dx = px2 - px2p; px1 -= dx; px2 -= dx; wx = px-dx; }
if (py1 > py1p) { dy = py1 - py1p; py1 -= dy; py2 -= dy; wy = py-dy; }
if (py2 < py2p) { dy = py2p - py2; py1 += dy; py2 += dy; wy = py+dy; }
if (!opaque) gVirtualX->DrawBox(px1, py1, px2, py2, TVirtualX::kHollow); // draw the new box
}

if (wx || wy) {
if (wx) px = wx;
if (wy) py = wy;
gVirtualX->Warp(px, py);
}

pxold = px;
pyold = py;

if ((pINSIDE && opaque) || (fResizing && ropaque)) {
event = kButton1Up;
doing_again = kTRUE;
goto again;
}

break;

case kButton1Up:

if (pTop || pBot || pL || pR || pINSIDE) {
fX1 = gPad->AbsPixeltoX(px1);
fY1 = gPad->AbsPixeltoY(py1);
fX2 = gPad->AbsPixeltoX(px2);
fY2 = gPad->AbsPixeltoY(py2);
}

if (pINSIDE) {
// if it was not a pad that was moved then it must have been
// a box or something like that so we have to redraw the pad
if (parent == gPad) gPad->Modified(kTRUE);
if (!doing_again) gPad->SetCursor(kCross);
SetY1(dy); SetY2(1 - dy);
}

if (pTop || pBot || pL || pR )
gPad->Modified(kTRUE);

// Restore original event type
if (doing_again)
event = kButton1Motion;
else {
gVirtualX->SetLineColor(-1);
gVirtualX->SetLineWidth(-1);
}

break;
}


// Give control to object using the slider

Float_t xpmin,xpmax;
if (vertical) {
xpmin = Float_t(pypadmin-py1)/Float_t(pypadmin-pypadmax);
xpmax = Float_t(pypadmin-py2)/Float_t(pypadmin-pypadmax);
} else { //vertical slider
xpmin = Float_t(px1-pxpadmin)/Float_t(pxpadmax-pxpadmin);
xpmax = Float_t(px2-pxpadmin)/Float_t(pxpadmax-pxpadmin);
}
fSlider->SetMinimum(xpmin);
fSlider->SetMaximum(xpmax);

//A user method to execute?
Int_t lenMethod = strlen(fSlider->GetMethod());
if (event == kButton1Up && lenMethod > 0 ) {
if (event == kButton1Up && (strlen(fSlider->GetMethod()) > 0)) {
gPad->SetCursor(kWatch);
gROOT->ProcessLine(fSlider->GetMethod());
return;
}

//An object connected to this slider?
TObject *obj = fSlider->GetObject();
if (obj) {
obj->ExecuteEvent(event,0,0);
}
if (obj)
obj->ExecuteEvent(event, 0, 0);
}

////////////////////////////////////////////////////////////////////////////////
Expand Down
Loading
Loading