Re: mouse button: 2 questions

From: Rene Brun <brun_at_pcroot.cern.ch>
Date: Thu, 14 Apr 2005 09:33:32 +0200 (MEST)


Alexis,

Note that what you try to do is already provided by the graphics editor ::)

Anyhow, I suggest the simple modification in your script as shown below. You start in input mode. you can enter markers. As soon as you want to edit, press any key while your mouse is in the canvas. To toggle input mode again, press again any key.

Rene Brun

void test() {

  TH1F * hALL = new TH1F("hALL","hALL",100,-3,3);   //TFile f("test.root","READ") ;
  hALL->FillRandom("gaus",1000);
  TCanvas * c1 = new TCanvas("c1");
  hALL->Draw();
  c1->Update();
  c1->AddExec("test","exectest()");   

}

void exectest(){   

  int event = gPad->GetEvent();
  float iix = gPad->GetEventX();
  float iiy = gPad->GetEventY();

  float roix = gPad->AbsPixeltoX(iix);
  float roiy = gPad->AbsPixeltoY(iiy);     

  static Bool_t edit = kFALSE;
  if (event == 24) { //when typing a keyboard key in the pad

     if (edit) {edit = kFALSE; printf("switching to input mode\n");}
     else      {edit = kTRUE;  printf("switching to edit mode\n");}
  }
  if (event == 1 && !edit){ //button down     

    TMarker *m = new TMarker(roix, roiy, 800) ;     printf("creating new TMarker at %x\n",m);     m->SetMarkerStyle(3);
    m->SetMarkerColor(2);     

    m->Draw("SAME");        

  }   

}

On
Thu, 14 Apr 2005, Alexis Cothenet wrote:

>
> Hi Rene,
>
> Thank you. You were right now it works for both cases.
> So, in the macro i do:
> void exectest(){
> int event = gPad->GetEvent();
> float iix = gPad->GetEventX();
> float iiy = gPad->GetEventY();
> float roix = gPad->AbsPixeltoX(iix);
> float roiy = gPad->AbsPixeltoY(iiy);
>
> if (event == 1){ //button down
>
> TMarker *m = new TMarker(roix, roiy, 800) ;
> m->SetMarkerStyle(3);
> m->SetMarkerColor(2);
> m->Draw("SAME");
> }
> }
>
> but i'd like also to be able that if i click on a marker with the mouse
> button, i could move it at another place. I have no idea how to do that, i
> checked the functions in Tpad but didn't see what could help...
> Would you have a such example ?
> Thank you,
>
> Alexis
>
>
>
>
>
>
> On Thu, 14 Apr 2005, Rene Brun wrote:
>
> > When you run the script test.C, the function exectest is known to CINT.
> > If you type the commands without telling CINT where to find
> > the function, it is clear that it cannot work.
> > I suggest adding the following line
> > gROOT->ProcessLine(".L exectest.C")
> > before executing:
> > c1->AddExec("test","exectest()");
> >
> > where exectest.C is a file containing only the function exectest
> >
> > Rene Brun
> >
> > On
> > Wed, 13 Apr 2005 alexis.cothenet_at_free.fr wrote:
> >
> > > Hi all,
> > >
> > > I have two questions about the macro that i put in attachment.
> > >
> > > 1) If i run it like this, it works well.
> > > But if i prefer to do in root:
> > > TFile * f = new TFile("test.root","RECREATE");
> > > TH1F * hALL = new TH1F("hALL","hALL",100,-3,3);
> > > hALL->FillRandom("gaus",1000);
> > > f->Write();
> > > and then to change test() like this:
> > > //TH1F * hALL = new TH1F("hALL","hALL",100,-3,3);
> > > TFile f("test.root","READ") ;
> > > // hALL->FillRandom("gaus",1000);
> > > TCanvas * c1 = new TCanvas("c1");
> > > hALL->Draw();
> > > c1->Update();
> > > c1->AddExec("test","exectest()");
> > >
> > >
> > > I cannot see any more the hitogramm hALL...it seems to be masked by something
> > > empty...do you understand my problem ?
> > >
> > > 2) once i clicked on the canvas with the mouse and that some markers appeared,
> > > i'd like to be able to move some of them at another place in the canvas by the
> > > way of the mouse.
> > > Could you explain me how to do that ?
> > >
> > > Thank you a lot by advance!
> > >
> > > Regards,
> > > Alexis
> > >
> > >
> >
> >
>
Received on Thu Apr 14 2005 - 09:33:36 MEST

This archive was generated by hypermail 2.2.0 : Tue Jan 02 2007 - 14:45:06 MET