Display order of draw objects (overlay)

Hi,

I have an additional TPad with non-transparent content (e.g. TImages) inside a TCanvas and would like to display an overlay TText with dimensions bigger than the pad and written across the whole canvas on top of the pad, but whatever I do the text will always be below the pad and hence partially covered. Any ideas on how to accomplish this?

Here is an example:

new TCanvas
p = new TPad("p", "pad", 0.2, 0.2, 0.8, 0.8, kRed)
p->Draw()
t = new TText(0.05, 0.5, "TEST TESTTESTTESTTESTTESTTESTTESTTESTTEST TEST")
t->Draw()


I do NOT want to display the text inside the pad as in

p->cd()
t->Draw()


Suggestions are welcome!

{
TCanvas *c = new TCanvas();
TPad *p1 = new TPad("p1", "p1", 0.2, 0.2, 0.8, 0.8, kRed);
p1->Draw();
TPad *p2 = new TPad("p2", "p2", 0., 0., 1., 1.);
p2->SetFillStyle(0);
p2->Draw();
p2->cd();
TText *t = new TText(0.05, 0.5, "TEST TESTTESTTESTTESTTESTTESTTESTTESTTEST TEST");
t->Draw();
}

Sorry, I forgot to mention I’m aware of the transparent pad option, the problem with that is that I cannot pick or zoom objects in p1 anymore (see TImage in example below) which is important for my application.

Is there a way to make the overlay pad p2 “invisible” to mouse interactions? I tried the bit kCannotPick for p2 but it still does not allow picking objects from pad p1.

Would it work to create a child class TransparentPad and simply overwrite the ExecuteEvent and Pick methods or should I save the trouble trying?


[code]{
c = new TCanvas;
c->SetMargin(0.0, 0.0, 0.0, 0.0);

p1 = new TPad("p1", "Image pad", 0.2, 0.0, 0.8, 1.0, kRed);
p1->SetMargin(0.0, 0.0, 0.0, 0.0);
p1->Draw();
p1->cd();

img = TImage::Open("rose512.jpg");
img->SetConstRatio(kFALSE);
img->Draw();

c->cd();

p2 = new TPad("p2", "Overlay pad", 0.0, 0.0, 1.0, 1.0, kGray);
p2->SetMargin(0.0, 0.0, 0.0, 0.0);
p2->SetFillStyle(0);
p2->SetBit(kNoContextMenu);
p2->SetBit(kCannotPick);
p2->Draw();
p2->cd();

text = new TText(0.05,0.9,"TEST TESTTESTTESTTESTTESTTESTTESTTESTTEST TEST");
text->SetBit(kNoContextMenu);
text->SetBit(kCannotPick);
text->Draw();

}[/code]

You are not oblige to make the 2nd pad p2 as large as the canvas. make it equivalent to the text size (framing the text). Then you will have to increase the text size obviously.

That’s a good idea. I still need to suppress the mouse actions and the contemplated TPad child class (see below) with invalidated ExecuteEvent and Pick methods does exactly that.

In fact, this might be a nice feature of TPad for other users as well. With a flag like fEditable, say “fInteractable” or something, ExecuteEvent and Pick could be exited right at the beginning. A SetInteractable(Bool_t on = kTRUE) function could set/unset the bits like in the constructor below. Just an idea, but one that’s easy to implement…

class TransparentPad : public TPad {
public:
	TransparentPad(const char* name, const char* title, Double_t xlow , Double_t ylow , Double_t xup, Double_t yup, Color_t color = -1, Short_t bordersize = -1, Short_t bordermode = -2) : TPad(name, title, xlow, ylow, xup, yup, color, bordersize, bordermode)
	{
		SetMargin(0.05, 0.05, 0.25, 0.25);
		SetFillStyle(kFEmpty);
		SetBit(kNoContextMenu);
		SetBit(kCannotPick);
	}
	virtual ~TransparentPad(){}

	virtual void	ExecuteEvent(Int_t event, Int_t px, Int_t py){}
	TPad 			*Pick(Int_t px, Int_t py, TObjLink*& pickobj) { return 0; }

	ClassDef(TransparentPad, 1);
};

Yes, that way you make it “Not Pickable”…

Maybe “fPickable” would be a better name for a new TPad class member… :smiley: