//*CMZ :  2.23/05 17/10/99  11.13.04  by  Rene Brun
//*CMZ :  2.23/04 13/10/99  10.15.44  by  Rene Brun
//*CMZ :  2.21/05 07/02/99  11.39.40  by  Rene Brun
//*CMZ :  2.21/03 21/01/99  18.54.32  by  Rene Brun
//*CMZ :  2.21/00 28/12/98  18.40.32  by  Rene Brun
//*CMZ :  2.20/05 15/12/98  09.17.21  by  Rene Brun
//*-- Author :    Rene Brun   17/10/95

//*KEEP,CopyRight,T=C.
/*************************************************************************
 * Copyright(c) 1995-1999, The ROOT System, All rights reserved.         *
 * Authors: Rene Brun and Fons Rademakers.                               *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/AA_LICENSE.                      *
 * For the list of contributors see $ROOTSYS/AA_CREDITS.                 *
 *************************************************************************/
//*KEND.

#include <fstream.h>
#include <iostream.h>

//*KEEP,TROOT.
#include "TROOT.h"
//*KEEP,TPaveLabel.
#include "TPaveLabel.h"
//*KEEP,TLatex,T=C++.
#include "TLatex.h"
//*KEEP,TVirtualPad.
#include "TVirtualPad.h"
//*KEND.

ClassImp(TPaveLabel)

//______________________________________________________________________________
//*  A PaveLabel is a Pave (see TPave) with a text centered in the Pave.
//
/*

*/
//
//

//______________________________________________________________________________
 TPaveLabel::TPaveLabel(): TPave(), TAttText()
{
//*-*-*-*-*-*-*-*-*-*-*pavelabel default constructor*-*-*-*-*-*-*-*-*-*-*-*-*
//*-*                  =============================
}

//______________________________________________________________________________
 TPaveLabel::TPaveLabel(Coord_t x1, Coord_t y1,Coord_t x2, Coord_t  y2, const Text_t *label, Option_t *option)
           :TPave(x1,y1,x2,y2,3,option), TAttText(22,0,1,62,0.99)
{
//*-*-*-*-*-*-*-*-*-*-*pavelabel normal constructor*-*-*-*-*-*-*-*-*-*-*-*-*-*
//*-*                  ============================
// a PaveLabel is a Pave with a label centered in the Pave
// The Pave is by default defined bith bordersize=5 and option ="br".
// The text size is automatically computed as a function of the pave size.
//

   fLabel  = label;
}

//______________________________________________________________________________
 TPaveLabel::~TPaveLabel()
{
//*-*-*-*-*-*-*-*-*-*-*pavelabel default destructor*-*-*-*-*-*-*-*-*-*-*-*-*-*
//*-*                  ============================
}

//______________________________________________________________________________
 TPaveLabel::TPaveLabel(const TPaveLabel &pavelabel)
{
   ((TPaveLabel&)pavelabel).Copy(*this);
}

//______________________________________________________________________________
 void TPaveLabel::Copy(TObject &obj)
{
//*-*-*-*-*-*-*-*-*-*-*Copy this pavelabel to pavelabel*-*-*-*-*-*-*-*-*-*-*-*
//*-*                  ================================

   TPave::Copy(obj);
   TAttText::Copy(((TPaveLabel&)obj));
   ((TPaveLabel&)obj).fLabel      = fLabel;
}

//______________________________________________________________________________
 void TPaveLabel::Draw(Option_t *option)
{
//*-*-*-*-*-*-*-*-*-*-*Draw this pavelabel with its current attributes*-*-*-*-*
//*-*                  ===============================================

   Option_t *opt;
   if (strlen(option)) opt = option;
   else                opt = GetOption();

   AppendPad(opt);

}

//______________________________________________________________________________
 void TPaveLabel::DrawPaveLabel(Coord_t x1, Coord_t y1, Coord_t x2, Coord_t y2, const Text_t *label, Option_t *)
{
//*-*-*-*-*-*-*-*-*-*-*Draw this pavelabel with new coordinates*-*-*-*-*-*-*-*
//*-*                  ========================================
   TPaveLabel *newpavelabel = new TPaveLabel(x1,y1,x2,y2,label);
   newpavelabel->SetBit(kCanDelete);
   newpavelabel->AppendPad();
}

//______________________________________________________________________________
 void TPaveLabel::Paint(Option_t *option)
{
//*-*-*-*-*-*-*-*-*-*-*Paint this pavelabel with its current attributes*-*-*-*
//*-*                  ================================================

//*-* Convert from NDC to pad coordinates
   TPave::ConvertNDCtoPad();

   PaintPaveLabel(fX1, fY1, fX2, fY2, GetLabel(), option);

}


//______________________________________________________________________________
 void TPaveLabel::PaintPaveLabel(Coord_t x1, Coord_t y1,Coord_t x2, Coord_t  y2,
                      const Text_t *label ,Option_t *option)
{
//*-*-*-*-*-*-*-*-*-*-*Draw this pavelabel with new coordinates*-*-*-*-*-*-*-*
//*-*                  ========================================

   Int_t nch = strlen(label);

//*-*- Draw the pave
   TPave::PaintPave(x1,y1,x2,y2,GetBorderSize(),option);

   Float_t nspecials = 0;
   for (Int_t i=0;i<nch;i++) {
      if (label[i] == '!') nspecials += 1;
      if (label[i] == '?') nspecials += 1.5;
      if (label[i] == '#') nspecials += 1;
      if (label[i] == '`') nspecials += 1;
      if (label[i] == '^') nspecials += 1.5;
      if (label[i] == '~') nspecials += 1;
      if (label[i] == '&') nspecials += 2;
      if (label[i] == '\') nspecials += 3;  // octal characters very likely
   }
   nch -= Int_t(nspecials + 0.5);
   if (nch <= 0) return;

//*-*- Draw label
   Float_t wh   = (Float_t)gPad->XtoPixel(gPad->GetX2());
   Float_t hh   = (Float_t)gPad->YtoPixel(gPad->GetY1());
   Float_t textsize  = GetTextSize();
   if (TMath::Abs(textsize -0.7) < 0.001) textsize=0.99;
   Int_t ypixel      = gPad->YtoPixel(y1) - gPad->YtoPixel(y2);
   Float_t labelsize = textsize*ypixel/hh;
   if (wh < hh) labelsize *= hh/wh;
   TLatex latex;
   latex.SetTextAngle(GetTextAngle());
   latex.SetTextFont(GetTextFont());
   latex.SetTextAlign(GetTextAlign());
   latex.SetTextColor(GetTextColor());
   latex.SetTextSize(labelsize);
   UInt_t w,h;
   latex.GetTextExtent(w,h,GetTitle());
   labelsize = h/hh;
   Float_t wxlabel   = gPad->XtoPixel(x2) - gPad->XtoPixel(x1);
//printf("w=%d, h=%d, wxlabel=%f, ypixel=%d, lsize=%f, text=%sn",w,h,wxlabel,ypixel,labelsize,GetTitle());
   if (w > 0.99*wxlabel) {labelsize *= 0.99*wxlabel/w; h = UInt_t(h*0.99*wxlabel/w);}
   if (h < 1) h = 1;
   labelsize   = Float_t(h)/hh;
   if (wh < hh) labelsize *= hh/wh;
   latex.SetTextSize(labelsize);
   Int_t halign = GetTextAlign()/10;
   Int_t valign = GetTextAlign()%10;
   Float_t x = 0.5*(x1+x2);
   if (halign == 1) x = x1 + 0.02*(x2-x1);
   if (halign == 3) x = x2 - 0.02*(x2-x1);
   Float_t y = 0.5*(y1+y2);
   if (valign == 1) y = y1 + 0.02*(y2-y1);
   if (valign == 3) y = y2 - 0.02*(y2-y1);
   latex.PaintLatex(x, y, GetTextAngle(),labelsize,GetLabel());
}

//______________________________________________________________________________
 void TPaveLabel::Print(Option_t *option)
{
//*-*-*-*-*-*-*-*-*-*-*Dump this pavelabel with its attributes*-*-*-*-*-*-*-*
//*-*                  =======================================
   TPave::Print(option);
}

//______________________________________________________________________________
 void TPaveLabel::SavePrimitive(ofstream &out, Option_t *)
{
    // Save primitive as a C++ statement(s) on output stream out

   char quote = '"';
   out<<"   "<<endl;
   if (gROOT->ClassSaved(TPaveLabel::Class())) {
       out<<"   ";
   } else {
       out<<"   TPaveLabel *";
   }
   out<<"pl = new TPaveLabel("<<fX1<<","<<fY1<<","<<fX2<<","<<fY2
      <<","<<quote<<fLabel<<quote<<","<<quote<<fOption<<quote<<");"<<endl;

   SaveFillAttributes(out,"pl",0,1001);
   SaveLineAttributes(out,"pl",1,1,1);
   SaveTextAttributes(out,"pl",22,0,1,62,0);

   out<<"   pl->Draw();"<<endl;
}


ROOT page - Class index - Top of the page

This page has been automatically generated. If you have any comments or suggestions about the page layout send a mail to ROOT support, or contact the developers with any questions or problems regarding ROOT.