#include <stdlib.h>
#include "Riostream.h"
#include "TROOT.h"
#include "TVirtualPad.h"
#include "TMarker.h"
#include "TVirtualX.h"
#include "TMath.h"
#include "TPoint.h"
#include "TText.h"
#include "TClass.h"
ClassImp(TMarker)
/*
<img src="gif/markers.gif">
*/
//End_Html
TMarker::TMarker(): TObject(), TAttMarker()
{
fX = 0;
fY = 0;
}
TMarker::TMarker(Double_t x, Double_t y, Int_t marker)
:TObject(), TAttMarker()
{
fX = x;
fY = y;
fMarkerStyle = marker;
}
TMarker::~TMarker()
{
}
TMarker::TMarker(const TMarker &marker) : TObject(marker), TAttMarker(marker)
{
((TMarker&)marker).Copy(*this);
}
void TMarker::Copy(TObject &obj) const
{
TObject::Copy(obj);
TAttMarker::Copy(((TMarker&)obj));
((TMarker&)obj).fX = fX;
((TMarker&)obj).fY = fY;
}
void TMarker::DisplayMarkerTypes()
{
TMarker *marker = new TMarker();
marker->SetMarkerSize(3);
TText *text = new TText();
text->SetTextFont(62);
text->SetTextAlign(22);
text->SetTextSize(0.1);
char atext[] = " ";
Double_t x = 0;
Double_t dx = 1/12.0;
for (Int_t i=1;i<12;i++) {
x += dx;
sprintf(atext,"%d",i);
marker->SetMarkerStyle(i);
marker->DrawMarker(x,.35);
text->DrawText(x,.17,atext);
sprintf(atext,"%d",i+19);
marker->SetMarkerStyle(i+19);
marker->DrawMarker(x,.8);
text->DrawText(x,.62,atext);
}
delete marker;
delete text;
}
Int_t TMarker::DistancetoPrimitive(Int_t px, Int_t py)
{
const Int_t kMaxDiff = 10;
Int_t pxm, pym;
if (TestBit(kMarkerNDC)) {
pxm = gPad->UtoPixel(fX);
pym = gPad->VtoPixel(fY);
} else {
pxm = gPad->XtoAbsPixel(gPad->XtoPad(fX));
pym = gPad->YtoAbsPixel(gPad->YtoPad(fY));
}
Int_t dist = (px-pxm)*(px-pxm) + (py-pym)*(py-pym);
if (dist > kMaxDiff) return 9999;
return dist;
}
void TMarker::Draw(Option_t *option)
{
AppendPad(option);
}
void TMarker::DrawMarker(Double_t x, Double_t y)
{
TMarker *newmarker = new TMarker(x, y, 1);
TAttMarker::Copy(*newmarker);
newmarker->SetBit(kCanDelete);
newmarker->AppendPad();
}
void TMarker::ExecuteEvent(Int_t event, Int_t px, Int_t py)
{
TPoint p;
static Int_t pxold, pyold;
if (!gPad->IsEditable()) return;
switch (event) {
case kButton1Down:
gVirtualX->SetTextColor(-1);
TAttMarker::Modify();
case kMouseMotion:
pxold = px; pyold = py;
gPad->SetCursor(kMove);
break;
case kButton1Motion:
p.fX = pxold; p.fY = pyold;
gVirtualX->DrawPolyMarker(1, &p);
p.fX = px; p.fY = py;
gVirtualX->DrawPolyMarker(1, &p);
pxold = px; pyold = py;
break;
case kButton1Up:
Double_t dpx, dpy, xp1,yp1;
if (TestBit(kMarkerNDC)) {
dpx = gPad->GetX2() - gPad->GetX1();
dpy = gPad->GetY2() - gPad->GetY1();
xp1 = gPad->GetX1();
yp1 = gPad->GetY1();
fX = (gPad->AbsPixeltoX(pxold)-xp1)/dpx;
fY = (gPad->AbsPixeltoY(pyold)-yp1)/dpy;
} else {
fX = gPad->PadtoX(gPad->AbsPixeltoX(px));
fY = gPad->PadtoY(gPad->AbsPixeltoY(py));
}
gPad->Modified(kTRUE);
gVirtualX->SetTextColor(-1);
break;
}
}
void TMarker::ls(Option_t *) const
{
TROOT::IndentLevel();
printf("Marker X=%f Y=%f marker type=%d\n",fX,fY,fMarkerStyle);
}
void TMarker::Paint(Option_t *)
{
if (TestBit(kMarkerNDC)) {
Double_t u = gPad->GetX1() + fX*(gPad->GetX2()-gPad->GetX1());
Double_t v = gPad->GetY1() + fY*(gPad->GetY2()-gPad->GetY1());
PaintMarker(u,v);
} else {
PaintMarker(gPad->XtoPad(fX),gPad->YtoPad(fY));
}
}
void TMarker::PaintMarker(Double_t x, Double_t y)
{
TAttMarker::Modify();
gPad->PaintPolyMarker(-1,&x,&y,"");
}
void TMarker::PaintMarkerNDC(Double_t, Double_t)
{
}
void TMarker::Print(Option_t *) const
{
printf("Marker X=%f Y=%f",fX,fY);
if (GetMarkerColor() != 1) printf(" Color=%d",GetMarkerColor());
if (GetMarkerStyle() != 1) printf(" MarkerStyle=%d",GetMarkerStyle());
if (GetMarkerSize() != 1) printf(" MarkerSize=%f",GetMarkerSize());
printf("\n");
}
void TMarker::SavePrimitive(ostream &out, Option_t * )
{
if (gROOT->ClassSaved(TMarker::Class())) {
out<<" ";
} else {
out<<" TMarker *";
}
out<<"marker = new TMarker("<<fX<<","<<fY<<","<<fMarkerStyle<<");"<<endl;
SaveMarkerAttributes(out,"marker",1,1,1);
out<<" marker->Draw();"<<endl;
}
void TMarker::SetNDC(Bool_t isNDC)
{
ResetBit(kMarkerNDC);
if (isNDC) SetBit(kMarkerNDC);
}
void TMarker::Streamer(TBuffer &R__b)
{
if (R__b.IsReading()) {
UInt_t R__s, R__c;
Version_t R__v = R__b.ReadVersion(&R__s, &R__c);
if (R__v > 1) {
R__b.ReadClassBuffer(TMarker::Class(), this, R__v, R__s, R__c);
return;
}
TObject::Streamer(R__b);
TAttMarker::Streamer(R__b);
Float_t x,y;
R__b >> x; fX = x;
R__b >> y; fY = y;
} else {
R__b.WriteClassBuffer(TMarker::Class(),this);
}
}
Last change: Wed Jun 25 08:49:03 2008
Last generated: 2008-06-25 08:49
This page has been automatically generated. If you have any comments or suggestions about the page layout send a mail to ROOT support, or contact the developers with any questions or problems regarding ROOT.