RE: Drawing an angled box

From: Fine, Valeri <fine_at_bnl.gov>
Date: Fri, 13 Mar 2009 01:37:58 -0400


> > What about
> > http://root.cern.ch/root/html522/TPolyLine.html <http://root.cern.ch/root/html522/TPolyLine.html>
> > One can draw the contour of the polyline or/and its fill area
>
> Thanks! That works just fine.
>
> Two further questions about this:
> 1) How does one learn such things
 

   Mmm, This remind me the story:    

    The stranger asked the English man to reveal the secret of     the perfect smooth green lawn.
    He answered, "There is no secret.
    It is simple, just keep mowing daily for 200 years.     That's all it needs."     

> -- after all, it's not at
> all obvious that a polyline can fill its enclosed area
> (it can do this even if it's not closed -- it adds an
> edge to close itself).
 

   Well, I tend to agree. It is not obvious ;-)   

> 2) some objects, such as TMarker, don't need to be re-drawn
> after a change, while others, such as TPolyLine do need
> to be re-drawn. How can one tell? Or should I just
> re-draw them all?
 

   This is FAQ.    

You should apply the TObject::Draw method at once. (see: http://root.cern.ch/root/html522/src/TObject.cxx.html#EOrTy )  

This the FULL (!!!) text of that method  

 void TObject <https://webmail.bnl.gov/exchange/fine/Drafts1/TObject.html> ::Draw <https://webmail.bnl.gov/exchange/fine/Drafts1/TObject.html#TObject:Draw> (Option_t <https://webmail.bnl.gov/exchange/fine/Drafts1/ListOfTypes.html#Option_t> *option)  { AppendPad <https://webmail.bnl.gov/exchange/fine/Drafts1/TObject.html#TObject:AppendPad> (option); }

    I hope you will agree there is no big reason to do that twice (at least in theory).    "Draw object" does not draw anything.    It merely appends the object pointer to the list of the primitives of the current TPad object.    The real rendering is provided via the virtual method TObject::Paint. This method is called by TPad.    Normally, one can find no invocation of the method TObject::Paint from within the end-user code.    This method is called by "TPad::Update" if . . . the TPad object was "Modified()".    

   So to force the TPad to be updated during the next "update" circle use TPad::Modify() method.    To get the immediate effect call it in pair    

      gPad->Modified();
      gPad->Update();
      

    To answer your next question I want to call your attention to the fact that these two methods     are always called as soon as user-operator hits the "Enter" key.  

void TObject <https://webmail.bnl.gov/exchange/fine/Drafts1/TObject.html> ::AppendPad <https://webmail.bnl.gov/exchange/fine/Drafts1/TObject.html#TObject:AppendPad> (Option_t <https://webmail.bnl.gov/exchange/fine/Drafts1/ListOfTypes.html#Option_t> *option) {

   if (!gPad) {

      gROOT <https://webmail.bnl.gov/exchange/fine/Drafts1/TROOT.html> ->MakeDefCanvas <https://webmail.bnl.gov/exchange/fine/Drafts1/TROOT.html#TROOT:MakeDefCanvas> ();    }
   if (!gPad->IsEditable()) return;
   SetBit <https://webmail.bnl.gov/exchange/fine/Drafts1/TObject.html#TObject:SetBit> (kMustCleanup <https://webmail.bnl.gov/exchange/fine/Drafts1/TObject.html#TObject:kMustCleanup> );    gPad->GetListOfPrimitives()->Add(this,option);    gPad->Modified(kTRUE <https://webmail.bnl.gov/exchange/fine/Drafts1/ListOfTypes.html#Bool_t> ); }

            
      Hope this helps, Valeri
   

>> -----Original Message-----
>> From: owner-roottalk_at_root.cern.ch [mailto:owner-roottalk_at_root.cern.ch]

> On
>> Behalf Of Tom Roberts
>> Sent: Thursday, March 12, 2009 5:50 PM
>> To: 'ROOT Talk'
>> Subject: [ROOT] Drawing an angled box
>>
>> I have a need to draw a colored rectangle with arbitrary orientation

> on
>> the screen; TBox does not do that. I do not need lines around the

> edge,
>> so it is tempting to use a big fat line. Unfortunately, linewidth is
>> specified in pixels, and widths greater than about 80 pixels don't

> work.
>> The first is easily handled with a coordinate conversion, but the

> second
>> means I have to draw multiple lines, a much bigger complexity.
>>
>> Is there a good way to do this?
>>
>>      The base data I start with are: Xcenter, Ycenter, width,
>>      height, angle, color. The first 4 are in user coordinates;
>>      angle is in degrees; color is R,G,B.
>>
>>
>> Tom Roberts
>
Received on Fri Mar 13 2009 - 06:38:31 CET

This archive was generated by hypermail 2.2.0 : Fri Mar 13 2009 - 11:50:02 CET