gVirtualX->DrawText

Hello Rooters,

in root.cern.ch/cgi-bin/print_hit_b … ice.C.html you describe how one can use gVirtualX to draw a line where the mouse pointer is.
I was wondering whether you can use the same technique to draw a text where the mouse is using gVirtualX->DrawText. (Please see the attached macro.)

Unfortunatly drawing the text at the same position doesn’t delete the text as it does with a line.

How do you have to delete the text in this case?

Thank you,
Lutz
text.c (1.42 KB)

There is apparenetly a problem in drawing the text background.
We will look into this problem.

Rene

I suggest you try the following:

in $ROOTSYS/etc/system.rootrc make sure that * .UseTTFonts is "true"
in your program replace:

pad->GetCanvas()->FeedbackMode(kTRUE);

By the 2 lines:

pad->SetDoubleBuffer(0);
gVirtualX->SetDrawMode(TVirtualX::kXor);

Let me know.

I just found an other way:

in the code do:

  pad->GetCanvas()->FeedbackMode(kTRUE);
  if(rpx) gVirtualX->DrawText(rpx, rpy, 0, 1, "test", 0) ;
  gVirtualX->DrawText(px, py, 0, 1, "test", 0) ;

(note that the last parameter of DrawText in now 0)

And in in $ROOTSYS/etc/system.rootrc make sure that * .UseTTFonts is “false”

This works on linux (for me). On windows I have not find a solution yet.

[quote=“Hoinki”]Hello Rooters,

in root.cern.ch/cgi-bin/print_hit_b … ice.C.html you describe how one can use gVirtualX to draw a line where the mouse pointer is.
I was wondering whether you can use the same technique to draw a text where the mouse is using gVirtualX->DrawText. (Please see the attached macro.)

Unfortunatly drawing the text at the same position doesn’t delete the text as it does with a line.

How do you have to delete the text in this case?

Thank you,
Lutz[/quote]

I did check your macro with Qt-layer and found no problem on either platforms.

Hi Lutz,

I do not know about Qt. But for X11 and Windows the Xor mode for text doesn’t work very well because TTF text is drawn thanks to a pixmap (Xor mode doen’ t work with pixmaps). So I have modified your macro to do what you want without using Xor mode (see the attached file).
text.c (1.33 KB)

I have modified slightly your macro to create the gif file that shows the result. No other changes were made

See: root.bnl.gov/picture/c1.gif
c1.gif.gz (575 KB)
text.c (1.78 KB)

I have tested the Couet’s modified macro under Qt. It works properly too.
text_modified.c (1.74 KB)


Not surprising …

Hello,

thanks for all the replys. Unfortunatly none of the suggested solutions work for me (I am using windows). I think I have to clarifiy what my goal is: In the end I don’t want to have a static text in the macro. I want to make a macro that gives information related to the cursors position (like the position itself or the distance from a certain point etc.). Please look at the attached example (I know that this information is also available at the status bar, but I just wanted to have a quick example to let you know what my goal is).

The macro that couet posted can be used to solve my problem, but unfortunatly my computer is not fast enough to print the text often enough. Moving the mouse gives the impression that the computer hangs somehow.

My question is: Are you planing to include the fast painting (from what you wrote I think its the Xor-Mode) for text or is it simply not possible to print a text right next to the mouse pointer fast?

Thank you,
Lutz
text_modified.c (1.59 KB)

Hmm, :open_mouth: I did conduct my tests under Windows :wink: .

(see your revised macro and the picture attached accidentally :blush: to my earlier post above)

Hello Valeri,

I have used your macro and got the attached result. I am using the latest version of root. (ftp://root.cern.ch/root/root_v5.10.00.win32gdk.tar.gz)

Is there something that I am doing wrong? You have been talking about a QT-Layer version of root. Is this an official root-version that one can download from cern?

Thank you,
Lutz


[quote=“Hoinki”]Is there something that I am doing wrong?[/quote] As soon as win32Gdk version is concern, I do not know. [quote=“Hoinki”]You have been talking about a QT-Layer version of root. Is this an official root-version that one can download from cern?[/quote]MMm :confused: I am not sure the term “official” is fully applicable for such package as ROOT. ROOT became the “official” CERN package 2 years ago only or something like this (Rene may want to correct me) . As soon as Qt/ROOT BNL project is concern:
[ul]1. There is NO such kind of thing like Qt/Root version. There is Qt-layer, which is the “standard” ROOT plugin. (see User’s Guide v5.08 root.cern.ch/viewcvs/qt/ and documented
User’s Guide v5.08 root.bnl.gov/QtRoot/QtRoot.html#free [/ul]
If you are not interesting to use Qt classes directly and want to stick with the TCanvas-like ROOT interface you can download and install the binary from root.bnl.gov. This binary contains the “official” ROOT (i.e. ROOT built from the ROOT CVS repository and Win32GDK layer) and an extra bonus, Qt-layer, that you can turn off / on . To use this distribution no extra Qt installation is required. You always can uninstall this version using the the standard Windows approach - “Control Panel” - “Add/Remove program” -> “remove ROOT” too.

I have been sent a message that says my claim:

[quote=“fine”][ul]3. However :frowning: , to install this version from the source one needs to install Qt v.3.x for Windows first. There are two ways to get Qt v.3. One way is to buy the commercial license, which is quite expansive), another one is to by $32 dollars Qt book see: root.bnl.gov/QtRoot/QtRoot.html#free [/ul][/quote]is not correct.
The free version can be obtained from
qtwin.sourceforge.net/qt3-win32/index.php

Hello,

I have tried the same thing with the “DrawLine()” and the lines stuck there, whatever drawing mode I use.
I want to draw lines that follow the cursor when on the histogram.
I am on Ubuntu 10.04, running version 5.26.00.

Lines are cleared if I click the mouse button, otherwise the line are just accumulating on the pad. So, there should be a way to clear this up if a mouse click can, but I am out of idea. :confused:

Someone have an idea?

Thanks!

Francis

What kind of plugin do you use : X11, win32gdk, Qt ?

Thanks for the fast reply,

I’m using X11 .

Francis

Hello,

I have found a solution. I just update my canvas (“c->Update()”) each time an event occur, so the line is not stuck there anymore.
It’s maybe not perfect, but it’s working :smiley:

Francis

void exec3event(Int_t event, Int_t px, Int_t py, TObject *selected)
{
  TCanvas *c = (TCanvas *) gTQSender;
  TPad *pad = (TPad *) c->GetSelectedPad();
  TH1F *histo;
  TPoint *point;
TLine *line;

  if (! pad) return;

  static Double_t x0, y0, x1, y1;
  
  static Int_t pxold, pyold;
  static Int_t px0, py0;
  static Int_t linedrawn;
   
//HERE
 c->Update();

if ( event == kMouseMotion )
   {	
	gVirtualX->SetLineColor(5);
	gVirtualX->SetLineWidth(3);
	pad->SetDoubleBuffer(0); 
	gVirtualX->SetDrawMode(TVirtualX::kXor); 
    x0 = pad->AbsPixeltoX(px);
    y0 = pad->AbsPixeltoY(py);
    histo = (TH1F*)pad->GetPrimitive("h");

    y1 = histo->GetBinContent(histo->GetXaxis()->FindFixBin(x0));

    gVirtualX->DrawLine( px,pad->YtoAbsPixel(0.),px, pad->YtoAbsPixel(y1)); 
   gVirtualX->DrawLine( pad->XtoAbsPixel(histo->GetXaxis()->GetXmin()),pad->YtoAbsPixel(y1),px, pad->YtoAbsPixel(y1));
cout<<"X0 : "<<x0<<" Y0 : "<<y0<<" Mean value : "<<histo->GetMean()<<endl;
}
 
}