140 if (!gStyle) {fLineColor=1; fLineWidth=1; fLineStyle=1;
return;}
141 fLineColor = gStyle->GetLineColor();
142 fLineWidth = gStyle->GetLineWidth();
143 fLineStyle = gStyle->GetLineStyle();
155 TAttLine::TAttLine(Color_t color, Style_t style, Width_t width)
165 TAttLine::~TAttLine()
172 void TAttLine::Copy(TAttLine &attline)
const
174 attline.fLineColor = fLineColor;
175 attline.fLineStyle = fLineStyle;
176 attline.fLineWidth = fLineWidth;
206 Int_t TAttLine::DistancetoLine(Int_t px, Int_t py, Double_t xp1, Double_t yp1, Double_t xp2, Double_t yp2 )
208 Double_t xl, xt, yl, yt;
211 Double_t x1 = gPad->XtoAbsPixel(xp1);
212 Double_t y1 = gPad->YtoAbsPixel(yp1);
213 Double_t x2 = gPad->XtoAbsPixel(xp2);
214 Double_t y2 = gPad->YtoAbsPixel(yp2);
215 if (x1 < x2) {xl = x1; xt = x2;}
216 else {xl = x2; xt = x1;}
217 if (y1 < y2) {yl = y1; yt = y2;}
218 else {yl = y2; yt = y1;}
219 if (x < xl-2 || x> xt+2)
return 9999;
220 if (y < yl-2 || y> yt+2)
return 9999;
221 Double_t xx1 = x - x1;
222 Double_t xx2 = x - x2;
223 Double_t x1x2 = x1 - x2;
224 Double_t yy1 = y - y1;
225 Double_t yy2 = y - y2;
226 Double_t y1y2 = y1 - y2;
227 Double_t a = xx1*xx1 + yy1*yy1;
228 Double_t b = xx2*xx2 + yy2*yy2;
229 Double_t c = x1x2*x1x2 + y1y2*y1y2;
230 if (c <= 0)
return 9999;
231 Double_t v = sqrt(c);
232 Double_t u = (a - b + c)/(2*v);
233 Double_t d = TMath::Abs(a - u*u);
234 if (d < 0)
return 9999;
236 return Int_t(sqrt(d) - 0.5*Double_t(fLineWidth));
242 void TAttLine::Modify()
245 Int_t lineWidth = TMath::Abs(fLineWidth%100);
246 if (!gPad->IsBatch()) {
247 gVirtualX->SetLineColor(fLineColor);
248 if (fLineStyle > 0 && fLineStyle < 30) gVirtualX->SetLineStyle(fLineStyle);
249 else gVirtualX->SetLineStyle(1);
250 gVirtualX->SetLineWidth(lineWidth);
253 if (fLineStyle > 0 && fLineStyle < 30) gPad->SetAttLinePS(fLineColor,fLineStyle,lineWidth);
254 else gPad->SetAttLinePS(fLineColor,1,lineWidth);
260 void TAttLine::ResetAttLine(Option_t *)
270 void TAttLine::SaveLineAttributes(std::ostream &out,
const char *name, Int_t coldef, Int_t stydef, Int_t widdef)
272 if (fLineColor != coldef) {
273 if (fLineColor > 228) {
274 TColor::SaveColor(out, fLineColor);
275 out<<
" "<<name<<
"->SetLineColor(ci);" << std::endl;
277 out<<
" "<<name<<
"->SetLineColor("<<fLineColor<<
");"<<std::endl;
279 if (fLineStyle != stydef) {
280 out<<
" "<<name<<
"->SetLineStyle("<<fLineStyle<<
");"<<std::endl;
282 if (fLineWidth != widdef) {
283 out<<
" "<<name<<
"->SetLineWidth("<<fLineWidth<<
");"<<std::endl;
290 void TAttLine::SetLineAttributes()
292 TVirtualPadEditor::UpdateLineAttributes(fLineColor,fLineStyle,fLineWidth);
299 void TAttLine::SetLineColorAlpha(Color_t lcolor, Float_t lalpha)
301 fLineColor = TColor::GetColorTransparent(lcolor, lalpha);