Logo ROOT  
Reference Guide
TMarker.cxx
Go to the documentation of this file.
1// @(#)root/graf:$Id$
2// Author: Rene Brun 12/05/95
3
4/*************************************************************************
5 * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
6 * All rights reserved. *
7 * *
8 * For the licensing terms see $ROOTSYS/LICENSE. *
9 * For the list of contributors see $ROOTSYS/README/CREDITS. *
10 *************************************************************************/
11
12#include <stdlib.h>
13
14#include "Riostream.h"
15#include "TROOT.h"
16#include "TBuffer.h"
17#include "TVirtualPad.h"
18#include "TMarker.h"
19#include "TVirtualX.h"
20#include "TMath.h"
21#include "TPoint.h"
22#include "TText.h"
23#include "TClass.h"
24
26
27
28/** \class TMarker
29\ingroup BasicGraphics
30
31Manages Markers. Marker attributes are managed by TAttMarker.
32*/
33
34////////////////////////////////////////////////////////////////////////////////
35/// Marker default constructor.
36
38{
39 fX = 0;
40 fY = 0;
41}
42
43////////////////////////////////////////////////////////////////////////////////
44/// Marker normal constructor.
45
48{
49 fX = x;
50 fY = y;
51 fMarkerStyle = marker;
52}
53
54////////////////////////////////////////////////////////////////////////////////
55/// Marker default destructor.
56
58{
59}
60
61////////////////////////////////////////////////////////////////////////////////
62/// Marker copy constructor.
63
64TMarker::TMarker(const TMarker &marker) : TObject(marker), TAttMarker(marker), TAttBBox2D(marker)
65{
66 fX = 0;
67 fY = 0;
68 ((TMarker&)marker).Copy(*this);
69}
70
71////////////////////////////////////////////////////////////////////////////////
72/// Copy this marker to marker.
73
74void TMarker::Copy(TObject &obj) const
75{
76 TObject::Copy(obj);
78 ((TMarker&)obj).fX = fX;
79 ((TMarker&)obj).fY = fY;
80}
81
82////////////////////////////////////////////////////////////////////////////////
83/// Display the table of markers with their numbers.
84
86{
87 TMarker *marker = new TMarker();
88 marker->SetMarkerSize(3);
89 TText *text = new TText();
90 text->SetTextFont(62);
91 text->SetTextAlign(22);
92 text->SetTextSize(0.1);
93 char atext[] = " ";
94 Double_t x = 0;
95 Double_t dx = 1/16.0;
96 for (Int_t i=1;i<16;i++) {
97 x += dx;
98 snprintf(atext,7,"%d",i);
99 marker->SetMarkerStyle(i);
100 marker->DrawMarker(x,.25);
101 text->DrawText(x,.12,atext);
102 snprintf(atext,7,"%d",i+19);
103 marker->SetMarkerStyle(i+19);
104 marker->DrawMarker(x,.55);
105 text->DrawText(x,.42,atext);
106 snprintf(atext,7,"%d",i+34);
107 marker->SetMarkerStyle(i+34);
108 marker->DrawMarker(x,.85);
109 text->DrawText(x,.72,atext);
110 }
111 delete marker;
112 delete text;
113}
114
115////////////////////////////////////////////////////////////////////////////////
116/// Display the table of markers with different line widths and their numbers.
117
119{
120 TMarker *marker = new TMarker();
121 marker->SetMarkerSize(3);
122 TText *text = new TText();
123 text->SetTextFont(62);
124 text->SetTextAlign(22);
125 text->SetTextSize(0.075);
126 char atext[] = " ";
127 Double_t x = 0;
128 Double_t dx = 1/19.0;
129 for (Int_t i=1;i<19;i++) {
130 x += dx;
131 snprintf(atext,7,"%d",i+49);
132 marker->SetMarkerStyle(i+49);
133 marker->DrawMarker(x,0.19);
134 text->DrawText(x,0.08,atext);
135 snprintf(atext,7,"%d",i+67);
136 marker->SetMarkerStyle(i+67);
137 marker->DrawMarker(x,0.42);
138 text->DrawText(x,0.31,atext);
139 snprintf(atext,7,"%d",i+85);
140 marker->SetMarkerStyle(i+85);
141 marker->DrawMarker(x,0.65);
142 text->DrawText(x,0.54,atext);
143 snprintf(atext,7,"%d",i+103);
144 marker->SetMarkerStyle(i+103);
145 marker->DrawMarker(x,0.88);
146 text->DrawText(x,0.77,atext);
147 }
148 delete marker;
149 delete text;
150}
151
152////////////////////////////////////////////////////////////////////////////////
153/// Compute distance from point px,py to a marker.
154///
155/// Compute the closest distance of approach from point px,py to this marker.
156/// The distance is computed in pixels units.
157
159{
160 Int_t pxm, pym;
161 if (TestBit(kMarkerNDC)) {
162 pxm = gPad->UtoPixel(fX);
163 pym = gPad->VtoPixel(fY);
164 } else {
165 pxm = gPad->XtoAbsPixel(gPad->XtoPad(fX));
166 pym = gPad->YtoAbsPixel(gPad->YtoPad(fY));
167 }
168 Int_t dist = (Int_t)TMath::Sqrt((px-pxm)*(px-pxm) + (py-pym)*(py-pym));
169
170 //marker size = 1 is about 8 pixels
171 Int_t markerRadius = Int_t(4*fMarkerSize);
172 if (dist <= markerRadius) return 0;
173 if (dist > markerRadius+3) return 999;
174 return dist;
175}
176
177////////////////////////////////////////////////////////////////////////////////
178/// Draw this marker with its current attributes.
179
181{
182 AppendPad(option);
183
184}
185
186////////////////////////////////////////////////////////////////////////////////
187/// Draw this marker with new coordinates.
188
190{
191 TMarker *newmarker = new TMarker(x, y, 1);
192 TAttMarker::Copy(*newmarker);
193 newmarker->SetBit(kCanDelete);
194 newmarker->AppendPad();
195}
196
197////////////////////////////////////////////////////////////////////////////////
198/// Execute action corresponding to one event.
199///
200/// This member function is called when a marker is clicked with the locator
201///
202/// If Left button is clicked on a marker, the marker is moved to
203/// a new position when the mouse button is released.
204
206{
207 if (!gPad) return;
208
209 TPoint p;
210 static Int_t pxold, pyold;
211 static Bool_t ndcsav;
212 Double_t dpx, dpy, xp1,yp1;
213 Bool_t opaque = gPad->OpaqueMoving();
214
215 if (!gPad->IsEditable()) return;
216
217 switch (event) {
218
219 case kButton1Down:
220 ndcsav = TestBit(kMarkerNDC);
221 if (!opaque) {
222 gVirtualX->SetTextColor(-1); // invalidate current text color (use xor mode)
223 TAttMarker::Modify(); //Change marker attributes only if necessary
224 }
225 // No break !!!
226
227 case kMouseMotion:
228 pxold = px; pyold = py;
229 gPad->SetCursor(kMove);
230 break;
231
232 case kButton1Motion:
233 p.fX = pxold; p.fY = pyold;
234 if (!opaque) gVirtualX->DrawPolyMarker(1, &p);
235 p.fX = px; p.fY = py;
236 if (!opaque) gVirtualX->DrawPolyMarker(1, &p);
237 pxold = px; pyold = py;
238 if (opaque) {
239 if (ndcsav) this->SetNDC(kFALSE);
240 this->SetX(gPad->PadtoX(gPad->AbsPixeltoX(px)));
241 this->SetY(gPad->PadtoY(gPad->AbsPixeltoY(py)));
242 gPad->ShowGuidelines(this, event, 'i', true);
243 gPad->Modified(kTRUE);
244 gPad->Update();
245 }
246 break;
247
248 case kButton1Up:
249 if (opaque) {
250 if (ndcsav && !this->TestBit(kMarkerNDC)) {
251 this->SetX((fX - gPad->GetX1())/(gPad->GetX2()-gPad->GetX1()));
252 this->SetY((fY - gPad->GetY1())/(gPad->GetY2()-gPad->GetY1()));
253 this->SetNDC();
254 }
255 gPad->ShowGuidelines(this, event);
256 } else {
257 if (TestBit(kMarkerNDC)) {
258 dpx = gPad->GetX2() - gPad->GetX1();
259 dpy = gPad->GetY2() - gPad->GetY1();
260 xp1 = gPad->GetX1();
261 yp1 = gPad->GetY1();
262 fX = (gPad->AbsPixeltoX(pxold)-xp1)/dpx;
263 fY = (gPad->AbsPixeltoY(pyold)-yp1)/dpy;
264 } else {
265 fX = gPad->PadtoX(gPad->AbsPixeltoX(px));
266 fY = gPad->PadtoY(gPad->AbsPixeltoY(py));
267 }
268 gPad->Modified(kTRUE);
269 gPad->Update();
270 gVirtualX->SetTextColor(-1);
271 }
272 break;
273 }
274}
275
276////////////////////////////////////////////////////////////////////////////////
277/// List this marker with its attributes.
278
280{
282 printf("Marker X=%f Y=%f marker type=%d\n",fX,fY,fMarkerStyle);
283}
284
285////////////////////////////////////////////////////////////////////////////////
286/// Paint this marker with its current attributes.
287
289{
290 if (TestBit(kMarkerNDC)) {
291 Double_t u = gPad->GetX1() + fX*(gPad->GetX2()-gPad->GetX1());
292 Double_t v = gPad->GetY1() + fY*(gPad->GetY2()-gPad->GetY1());
293 PaintMarker(u,v);
294 } else {
295 PaintMarker(gPad->XtoPad(fX),gPad->YtoPad(fY));
296 }
297}
298
299////////////////////////////////////////////////////////////////////////////////
300/// Draw this marker with new coordinates.
301
303{
304 TAttMarker::Modify(); //Change line attributes only if necessary
305 gPad->PaintPolyMarker(-1,&x,&y,"");
306}
307
308////////////////////////////////////////////////////////////////////////////////
309/// Draw this marker with new coordinates in NDC.
310
312{
313}
314
315////////////////////////////////////////////////////////////////////////////////
316/// Dump this marker with its attributes.
317
319{
320 printf("Marker X=%f Y=%f",fX,fY);
321 if (GetMarkerColor() != 1) printf(" Color=%d",GetMarkerColor());
322 if (GetMarkerStyle() != 1) printf(" MarkerStyle=%d",GetMarkerStyle());
323 if (GetMarkerSize() != 1) printf(" MarkerSize=%f",GetMarkerSize());
324 printf("\n");
325}
326
327////////////////////////////////////////////////////////////////////////////////
328/// Save primitive as a C++ statement(s) on output stream out
329
330void TMarker::SavePrimitive(std::ostream &out, Option_t * /*= ""*/)
331{
332 if (gROOT->ClassSaved(TMarker::Class())) {
333 out<<" ";
334 } else {
335 out<<" TMarker *";
336 }
337 out<<"marker = new TMarker("<<fX<<","<<fY<<","<<fMarkerStyle<<");"<<std::endl;
338
339 SaveMarkerAttributes(out,"marker",1,1,1);
340
341 out<<" marker->Draw();"<<std::endl;
342}
343
344////////////////////////////////////////////////////////////////////////////////
345/// Set NDC mode on if isNDC = kTRUE, off otherwise
346
348{
350 if (isNDC) SetBit(kMarkerNDC);
351}
352
353////////////////////////////////////////////////////////////////////////////////
354/// Stream an object of class TMarker.
355
356void TMarker::Streamer(TBuffer &R__b)
357{
358 if (R__b.IsReading()) {
359 UInt_t R__s, R__c;
360 Version_t R__v = R__b.ReadVersion(&R__s, &R__c);
361 if (R__v > 1) {
362 R__b.ReadClassBuffer(TMarker::Class(), this, R__v, R__s, R__c);
363 return;
364 }
365 //====process old versions before automatic schema evolution
366 TObject::Streamer(R__b);
367 TAttMarker::Streamer(R__b);
368 Float_t x,y;
369 R__b >> x; fX = x;
370 R__b >> y; fY = y;
371 //====end of old versions
372
373 } else {
374 R__b.WriteClassBuffer(TMarker::Class(),this);
375 }
376}
377
378////////////////////////////////////////////////////////////////////////////////
379/// Return the bounding Box of the Line
380
382{
383 Double_t size = this->GetMarkerSize();
384
385 Rectangle_t BBox;
386 BBox.fX = gPad->XtoPixel(fX)+(Int_t)(2*size);
387 BBox.fY = gPad->YtoPixel(fY)-(Int_t)(2*size);
388 BBox.fWidth = 2*size;
389 BBox.fHeight = 2*size;
390 return (BBox);
391}
392
393////////////////////////////////////////////////////////////////////////////////
394/// Return the center of the BoundingBox as TPoint in pixels
395
397{
398 TPoint p;
399 p.SetX(gPad->XtoPixel(fX));
400 p.SetY(gPad->YtoPixel(fY));
401 return(p);
402}
403
404////////////////////////////////////////////////////////////////////////////////
405/// Set center of the BoundingBox
406
408{
409 fX = gPad->PixeltoX(p.GetX());
410 fY = gPad->PixeltoY(p.GetY() - gPad->VtoPixel(0));
411}
412
413////////////////////////////////////////////////////////////////////////////////
414/// Set X coordinate of the center of the BoundingBox
415
417{
418 fX = gPad->PixeltoX(x);
419}
420
421////////////////////////////////////////////////////////////////////////////////
422/// Set Y coordinate of the center of the BoundingBox
423
425{
426 fY = gPad->PixeltoY(y - gPad->VtoPixel(0));
427}
428
429////////////////////////////////////////////////////////////////////////////////
430/// Set left hand side of BoundingBox to a value
431/// (resize in x direction on left)
432
434{
435 Double_t size = this->GetMarkerSize();
436 fX = gPad->PixeltoX(x + (Int_t)size);
437}
438
439////////////////////////////////////////////////////////////////////////////////
440/// Set right hand side of BoundingBox to a value
441/// (resize in x direction on right)
442
444{
445 Double_t size = this->GetMarkerSize();
446 fX = gPad->PixeltoX(x - (Int_t)size);
447}
448
449////////////////////////////////////////////////////////////////////////////////
450/// Set top of BoundingBox to a value (resize in y direction on top)
451
453{
454 Double_t size = this->GetMarkerSize();
455 fY = gPad->PixeltoY(y - (Int_t)size - gPad->VtoPixel(0));
456}
457
458////////////////////////////////////////////////////////////////////////////////
459/// Set bottom of BoundingBox to a value
460/// (resize in y direction on bottom)
461
463{
464 Double_t size = this->GetMarkerSize();
465 fY = gPad->PixeltoY(y + (Int_t)size - gPad->VtoPixel(0));
466}
@ kMouseMotion
Definition: Buttons.h:23
@ kButton1Motion
Definition: Buttons.h:20
@ kButton1Up
Definition: Buttons.h:19
@ kButton1Down
Definition: Buttons.h:17
void Class()
Definition: Class.C:29
@ kMove
Definition: GuiTypes.h:373
int Int_t
Definition: RtypesCore.h:43
short Version_t
Definition: RtypesCore.h:63
unsigned int UInt_t
Definition: RtypesCore.h:44
const Bool_t kFALSE
Definition: RtypesCore.h:90
double Double_t
Definition: RtypesCore.h:57
float Float_t
Definition: RtypesCore.h:55
const Bool_t kTRUE
Definition: RtypesCore.h:89
const char Option_t
Definition: RtypesCore.h:64
#define ClassImp(name)
Definition: Rtypes.h:361
#define gROOT
Definition: TROOT.h:406
#define gPad
Definition: TVirtualPad.h:287
#define gVirtualX
Definition: TVirtualX.h:338
#define snprintf
Definition: civetweb.c:1540
Abstract base class for elements drawn in the editor.
Definition: TAttBBox2D.h:19
Marker Attributes class.
Definition: TAttMarker.h:19
virtual void SaveMarkerAttributes(std::ostream &out, const char *name, Int_t coldef=1, Int_t stydef=1, Int_t sizdef=1)
Save line attributes as C++ statement(s) on output stream out.
Definition: TAttMarker.cxx:339
virtual void Modify()
Change current marker attributes if necessary.
Definition: TAttMarker.cxx:314
virtual Style_t GetMarkerStyle() const
Return the marker style.
Definition: TAttMarker.h:32
virtual Color_t GetMarkerColor() const
Return the marker color.
Definition: TAttMarker.h:31
virtual Size_t GetMarkerSize() const
Return the marker size.
Definition: TAttMarker.h:33
virtual void SetMarkerStyle(Style_t mstyle=1)
Set the marker style.
Definition: TAttMarker.h:40
void Copy(TAttMarker &attmarker) const
Copy this marker attributes to a new TAttMarker.
Definition: TAttMarker.cxx:235
virtual void SetMarkerSize(Size_t msize=1)
Set the marker size.
Definition: TAttMarker.h:41
Size_t fMarkerSize
Marker size.
Definition: TAttMarker.h:24
Style_t fMarkerStyle
Marker style.
Definition: TAttMarker.h:23
virtual void SetTextAlign(Short_t align=11)
Set the text alignment.
Definition: TAttText.h:41
virtual void SetTextFont(Font_t tfont=62)
Set the text font.
Definition: TAttText.h:45
virtual void SetTextSize(Float_t tsize=1)
Set the text size.
Definition: TAttText.h:46
Buffer base class used for serializing objects.
Definition: TBuffer.h:42
virtual Int_t ReadClassBuffer(const TClass *cl, void *pointer, const TClass *onfile_class=0)=0
virtual Version_t ReadVersion(UInt_t *start=0, UInt_t *bcnt=0, const TClass *cl=0)=0
Bool_t IsReading() const
Definition: TBuffer.h:85
virtual Int_t WriteClassBuffer(const TClass *cl, void *pointer)=0
Manages Markers.
Definition: TMarker.h:23
Double_t fX
X position of marker (left,center,etc..)
Definition: TMarker.h:26
virtual void SetX(Double_t x)
Definition: TMarker.h:54
virtual void SetBBoxCenter(const TPoint &p)
Set center of the BoundingBox.
Definition: TMarker.cxx:407
virtual void SetNDC(Bool_t isNDC=kTRUE)
Set NDC mode on if isNDC = kTRUE, off otherwise.
Definition: TMarker.cxx:347
virtual void SavePrimitive(std::ostream &out, Option_t *option="")
Save primitive as a C++ statement(s) on output stream out.
Definition: TMarker.cxx:330
TMarker()
Marker default constructor.
Definition: TMarker.cxx:37
Double_t fY
Y position of marker (left,center,etc..)
Definition: TMarker.h:27
virtual void SetBBoxCenterY(const Int_t y)
Set Y coordinate of the center of the BoundingBox.
Definition: TMarker.cxx:424
virtual void SetBBoxX2(const Int_t x)
Set right hand side of BoundingBox to a value (resize in x direction on right)
Definition: TMarker.cxx:443
virtual void Print(Option_t *option="") const
Dump this marker with its attributes.
Definition: TMarker.cxx:318
virtual void Paint(Option_t *option="")
Paint this marker with its current attributes.
Definition: TMarker.cxx:288
virtual void SetY(Double_t y)
Definition: TMarker.h:55
virtual void SetBBoxY2(const Int_t y)
Set bottom of BoundingBox to a value (resize in y direction on bottom)
Definition: TMarker.cxx:462
virtual Rectangle_t GetBBox()
Return the bounding Box of the Line.
Definition: TMarker.cxx:381
virtual void Draw(Option_t *option="")
Draw this marker with its current attributes.
Definition: TMarker.cxx:180
@ kMarkerNDC
Marker position is in NDC.
Definition: TMarker.h:32
void Copy(TObject &marker) const
Copy this marker to marker.
Definition: TMarker.cxx:74
virtual void ExecuteEvent(Int_t event, Int_t px, Int_t py)
Execute action corresponding to one event.
Definition: TMarker.cxx:205
virtual void SetBBoxCenterX(const Int_t x)
Set X coordinate of the center of the BoundingBox.
Definition: TMarker.cxx:416
virtual ~TMarker()
Marker default destructor.
Definition: TMarker.cxx:57
virtual void PaintMarker(Double_t x, Double_t y)
Draw this marker with new coordinates.
Definition: TMarker.cxx:302
virtual TPoint GetBBoxCenter()
Return the center of the BoundingBox as TPoint in pixels.
Definition: TMarker.cxx:396
static void DisplayMarkerLineWidths()
Display the table of markers with different line widths and their numbers.
Definition: TMarker.cxx:118
virtual void SetBBoxY1(const Int_t y)
Set top of BoundingBox to a value (resize in y direction on top)
Definition: TMarker.cxx:452
virtual Int_t DistancetoPrimitive(Int_t px, Int_t py)
Compute distance from point px,py to a marker.
Definition: TMarker.cxx:158
virtual void SetBBoxX1(const Int_t x)
Set left hand side of BoundingBox to a value (resize in x direction on left)
Definition: TMarker.cxx:433
virtual void ls(Option_t *option="") const
List this marker with its attributes.
Definition: TMarker.cxx:279
virtual void DrawMarker(Double_t x, Double_t y)
Draw this marker with new coordinates.
Definition: TMarker.cxx:189
static void DisplayMarkerTypes()
Display the table of markers with their numbers.
Definition: TMarker.cxx:85
virtual void PaintMarkerNDC(Double_t u, Double_t v)
Draw this marker with new coordinates in NDC.
Definition: TMarker.cxx:311
Mother of all ROOT objects.
Definition: TObject.h:37
R__ALWAYS_INLINE Bool_t TestBit(UInt_t f) const
Definition: TObject.h:187
virtual void AppendPad(Option_t *option="")
Append graphics object to current pad.
Definition: TObject.cxx:105
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
Definition: TObject.cxx:694
virtual void Copy(TObject &object) const
Copy this to obj.
Definition: TObject.cxx:61
void ResetBit(UInt_t f)
Definition: TObject.h:186
@ kCanDelete
if object in a list can be deleted
Definition: TObject.h:58
Definition: TPoint.h:31
SCoord_t fY
Definition: TPoint.h:36
SCoord_t fX
Definition: TPoint.h:35
SCoord_t GetY() const
Definition: TPoint.h:47
void SetX(SCoord_t x)
Definition: TPoint.h:48
void SetY(SCoord_t y)
Definition: TPoint.h:49
SCoord_t GetX() const
Definition: TPoint.h:46
static void IndentLevel()
Functions used by ls() to indent an object hierarchy.
Definition: TROOT.cxx:2781
Base class for several text objects.
Definition: TText.h:23
virtual TText * DrawText(Double_t x, Double_t y, const char *text)
Draw this text with new coordinates.
Definition: TText.cxx:175
TText * text
Double_t y[n]
Definition: legend1.C:17
Double_t x[n]
Definition: legend1.C:17
double dist(Rotation3D const &r1, Rotation3D const &r2)
Definition: 3DDistances.cxx:48
Double_t Sqrt(Double_t x)
Definition: TMath.h:681
Short_t fX
Definition: GuiTypes.h:361
UShort_t fHeight
Definition: GuiTypes.h:362
Short_t fY
Definition: GuiTypes.h:361
UShort_t fWidth
Definition: GuiTypes.h:362