38 ClassImp(TAttLineEditor);
43 TAttLineEditor::TAttLineEditor(
const TGWindow *p, Int_t width,
44 Int_t height, UInt_t options, Pixel_t back)
45 : TGedFrame(p, width, height, options | kVerticalFrame, back)
60 TGCompositeFrame *f2 =
new TGCompositeFrame(
this, 80, 20, kHorizontalFrame);
61 AddFrame(f2,
new TGLayoutHints(kLHintsTop, 1, 1, 0, 0));
63 fColorSelect =
new TGColorSelect(f2, 0, kCOLOR);
64 f2->AddFrame(fColorSelect,
new TGLayoutHints(kLHintsLeft, 1, 1, 1, 1));
65 fColorSelect->Associate(
this);
67 fStyleCombo =
new TGLineStyleComboBox(
this, kLINE_STYLE);
68 fStyleCombo->Resize(137, 20);
69 AddFrame(fStyleCombo,
new TGLayoutHints(kLHintsLeft, 3, 1, 1, 1));
70 fStyleCombo->Associate(
this);
72 fWidthCombo =
new TGLineWidthComboBox(f2, kLINE_WIDTH);
73 fWidthCombo->Resize(90, 20);
74 f2->AddFrame(fWidthCombo,
new TGLayoutHints(kLHintsLeft, 3, 1, 1, 1));
75 fWidthCombo->Associate(
this);
77 TGLabel *AlphaLabel =
new TGLabel(
this,
"Opacity");
79 new TGLayoutHints(kLHintsLeft | kLHintsCenterY));
80 TGHorizontalFrame *f2a =
new TGHorizontalFrame(
this);
81 fAlpha =
new TGHSlider(f2a,100,kSlider2|kScaleNo,kALPHA);
82 fAlpha->SetRange(0,1000);
83 f2a->AddFrame(fAlpha,
new TGLayoutHints(kLHintsLeft | kLHintsCenterY));
84 fAlphaField =
new TGNumberEntryField(f2a, kALPHAFIELD, 0,
85 TGNumberFormat::kNESReal,
86 TGNumberFormat::kNEANonNegative);
87 fAlphaField->Resize(40,20);
88 if (!TCanvas::SupportAlpha()) {
89 fAlpha->SetEnabled(kFALSE);
90 AlphaLabel->Disable(kTRUE);
91 fAlphaField->SetEnabled(kFALSE);
93 f2a->AddFrame(fAlphaField,
new TGLayoutHints(kLHintsLeft | kLHintsCenterY));
94 AddFrame(f2a,
new TGLayoutHints(kLHintsLeft | kLHintsCenterY));
100 TAttLineEditor::~TAttLineEditor()
107 void TAttLineEditor::ConnectSignals2Slots()
109 fColorSelect->Connect(
"ColorSelected(Pixel_t)",
"TAttLineEditor",
this,
"DoLineColor(Pixel_t)");
110 fColorSelect->Connect(
"AlphaColorSelected(ULong_t)",
"TAttLineEditor",
this,
"DoLineAlphaColor(ULong_t)");
111 fStyleCombo->Connect(
"Selected(Int_t)",
"TAttLineEditor",
this,
"DoLineStyle(Int_t)");
112 fWidthCombo->Connect(
"Selected(Int_t)",
"TAttLineEditor",
this,
"DoLineWidth(Int_t)");
113 fAlpha->Connect(
"Released()",
"TAttLineEditor",
this,
"DoAlpha()");
114 fAlpha->Connect(
"PositionChanged(Int_t)",
"TAttLineEditor",
this,
"DoLiveAlpha(Int_t)");
115 fAlphaField->Connect(
"ReturnPressed()",
"TAttLineEditor",
this,
"DoAlphaField()");
116 fAlpha->Connect(
"Pressed()",
"TAttLineEditor",
this,
"GetCurAlpha()");
124 void TAttLineEditor::SetModel(TObject* obj)
126 TAttLine *attline =
dynamic_cast<TAttLine*
>(obj);
127 if (!attline)
return;
130 fAvoidSignal = kTRUE;
132 fStyleCombo->Select(fAttLine->GetLineStyle());
134 if (obj->InheritsFrom(TGraph::Class())) {
135 fWidthCombo->Select(TMath::Abs(fAttLine->GetLineWidth()%100));
137 fWidthCombo->Select(fAttLine->GetLineWidth());
140 Color_t c = fAttLine->GetLineColor();
141 Pixel_t p = TColor::Number2Pixel(c);
142 fColorSelect->SetColor(p);
144 if (fInit) ConnectSignals2Slots();
146 fAvoidSignal = kFALSE;
148 if (TColor *color = gROOT->GetColor(fAttLine->GetLineColor())) {
149 fAlpha->SetPosition((Int_t)(color->GetAlpha()*1000));
150 fAlphaField->SetNumber(color->GetAlpha());
157 void TAttLineEditor::DoLineColor(Pixel_t color)
159 if (fAvoidSignal)
return;
160 fAttLine->SetLineColor(TColor::GetColor(color));
162 if (TColor *tcolor = gROOT->GetColor(TColor::GetColor(color))) {
163 fAlpha->SetPosition((Int_t)(tcolor->GetAlpha()*1000));
164 fAlphaField->SetNumber(tcolor->GetAlpha());
174 void TAttLineEditor::DoLineAlphaColor(ULong_t p)
176 TColor *color = (TColor *)p;
178 if (fAvoidSignal)
return;
179 fAttLine->SetLineColor(color->GetNumber());
180 fAlpha->SetPosition((Int_t)(color->GetAlpha()*1000));
181 fAlphaField->SetNumber(color->GetAlpha());
189 void TAttLineEditor::DoLineStyle(Int_t style)
191 if (fAvoidSignal)
return;
192 fAttLine->SetLineStyle(style);
200 void TAttLineEditor::DoLineWidth(Int_t width)
202 if (fAvoidSignal)
return;
203 if (dynamic_cast<TGraph*>(fAttLine)) {
204 Int_t graphLineWidth = 100*Int_t(fAttLine->GetLineWidth()/100);
205 if (graphLineWidth >= 0) {
206 fAttLine->SetLineWidth(graphLineWidth+width);
208 fAttLine->SetLineWidth(-(TMath::Abs(graphLineWidth)+width));
211 fAttLine->SetLineWidth(width);
219 void TAttLineEditor::DoAlphaField()
221 if (fAvoidSignal)
return;
223 if (TColor *color = gROOT->GetColor(fAttLine->GetLineColor())) {
224 color->SetAlpha((Float_t)fAlphaField->GetNumber());
225 fAlpha->SetPosition((Int_t)fAlphaField->GetNumber()*1000);
233 void TAttLineEditor::DoAlpha()
235 if (fAvoidSignal)
return;
237 if (TColor *color = gROOT->GetColor(fAttLine->GetLineColor())) {
238 color->SetAlpha((Float_t)fAlpha->GetPosition()/1000);
239 fAlphaField->SetNumber((Float_t)fAlpha->GetPosition()/1000);
247 void TAttLineEditor::DoLiveAlpha(Int_t a)
249 if (fAvoidSignal)
return;
250 fAlphaField->SetNumber((Float_t)a/1000);
252 if (TColor *color = gROOT->GetColor(fAttLine->GetLineColor())) {
254 if (color->GetAlpha() == 1.) {
255 fAttLine->SetLineColor(TColor::GetColorTransparent(color->GetNumber(),0.99));
257 color->SetAlpha((Float_t)a/1000);
266 void TAttLineEditor::GetCurAlpha()
268 if (fAvoidSignal)
return;
270 if (TColor *color = gROOT->GetColor(fAttLine->GetLineColor())) {
271 fAlpha->SetPosition((Int_t)(color->GetAlpha()*1000));
272 fAlphaField->SetNumber(color->GetAlpha());