GUI: statusbar TImage drawobjects

Not trying to be a pain, but this works only when creating a new canvas c1, not if I try to replace an existing image in an embedded GUI canvas…

Can you modify the little example I sent ?

Here’s the modified statusBar.C example. Function DoDrawCircle() contains your suggestions. As in the snippet below, a click on the “DrawCircle” button will produce an extra canvas c1 with the correct image + circle.

If you comment out that line and try with the embedded canvas fEcan by uncommenting the following line “fEcan = new TRootEmbeddedCanvas…” plus the last line of the function, then you get the image but the circle is missing again.

void MyMainFrame::DoDrawCircle()
{
  DoDrawImage();
  
  TImage *fImg2 = (TImage*)fImg->Clone("fImg2");
  if (!fImg) {
    printf("Could not create an image... exit\n");
    return;
  }

  fImg2->SetConstRatio(kFALSE);
  fImg2->SetImageQuality(TAttImage::kImgBest);

  //fImg2->DrawText(0, 0, "");
  fImg2->BeginPaint();
  fImg2->DrawCircle(50, 50, 10, "#00FF00", 1);

  TCanvas *c1 = new TCanvas("c1", "c1", 500, 500);
  //fEcan = new TRootEmbeddedCanvas(0,this,512,450);

  fImg2->Draw();
  //fEcan->GetCanvas()->Update();
}

So, it all works if you forget about creating any new canvas (comment out all “= new” statements) and rather take in the line “fImg2->DrawText(120, 160, “”);” and the last line. And all shall be well for the embedded canvas, image and circle.

My question is simply for understanding more of ROOT and C++ in general: What does the “->DrawText” do, that makes it all work all of a sudden? Somehow it must modify/instantiate the cloned TImage better than everything else we’ve tried…
statusBar_mod.C (5.67 KB)

What does the "->DrawText" do, that makes it all work all of a sudden? 

Nothing special … I just put it there to havel extra graphics. I took it from the example in ROOTSYS/tutorials. As I said the little exemple I sent works also without DrawText… I am sorry to have put some extra confusion there … In fact the problem seems more related to the fact you embed your canvas… right ?

Yeah, but try the different steps from my last post.

Without the “DrawText” the embedded canvas version doesn’t work, but if you take it in, all it once it does work! In my logic that means, calling “->DrawText()” must fix/establish something in the background, so that ROOT is happy with the embedded canvas and produces the result I want.

Ok… I’ll check asap… I am in something else now…

I tried quickly … I must have missed something because I cannot get a version of your macro working with DrawText. Can you send me a macro which works with DrawText and does not without… thanks.
(sorry but I am doing several things at the same time…)

No worries, since it’s working now, I’m not in a hurry and I just want to finish this up some time with an understanding of why things are as they are. Take your time! Thanks heaps already!

Attached are 4 versions:

  1. statusBar_mod_works.C: embedded canvas works because of “fImg->DrawText(…)”

  2. statusBar_mod_works_addCanvas.C: works because of new external TCanvas

  3. statusBar_mod_works_notEmbed1.C: creating new embedded canvas won’t work

  4. statusBar_mod_works_notEmbed2.C: not even if you do the “fImg->DrawText(…)” thing
    statusBar_mod_works_notEmbed2.C (5.68 KB)
    statusBar_mod_works_notEmbed1.C (5.68 KB)
    statusBar_mod_works_addCanvas.C (5.68 KB)
    statusBar_mod_works.C (5.67 KB)

I am interested only in statusBar_mod_works.C. But the file you send contains:

statusBar_mod_works_addCanvas()

Can you send me only the proper statusBar_mod_works.C ?

Thanks.

oops
statusBar_mod_works.C (5.67 KB)

I investigated further inside DrawText. What I found does not really help.
I then tried other things in your macro, But right now only this weird DrawText makes it work.
I am a bit stuck right now and do not have any more ideas …
If you do not mind having this call in your macro for the moment you can may be keep it for the time being ?

I’m happy my code’s working like that, so no worries. The reason why it won’t do without the DrawText() I’d just like to know out of pure curiosity…