Changeset 7893 for trunk/MagicSoft/Mars


Ignore:
Timestamp:
08/19/06 22:42:34 (18 years ago)
Author:
tbretz
Message:
*** empty log message ***
Location:
trunk/MagicSoft/Mars
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Mars/macros/tutorials/calendar.rc

    r7892 r7893  
    1818
    1919# define descriptions for your images
    20 01.Text: All File types supported by TASImage are supported
    21 02.Text:
    22 03.Text:
    23 04.Text:
    24 05.Text:
    25 06.Text:
     2001.Text: All File types supported by TASImage are supported.
     2102.Text: Please try to use the context menu on the small boxes.
     2203.Text: Choose SetDefaultLayout from the context menu.
     2304.Text: Play around with th eoptions in the context menu.
     2405.Text: Parts of the context menu are sensitive to the mouse position.
     2506.Text: To create a postscript file of your calendar change the macro.
    262607.Text:
    272708.Text:
  • trunk/MagicSoft/Mars/mtools/MCalendar.cc

    r7451 r7893  
    8181//
    8282//  The contents of each pave in your calendar.
    83 //      Contents: Date Day Holiday Easter Birthday
    84 //
    85 //  You can setup the contents by their names individually. The possible
    86 //  Style is defined by a TLatex object. For more details see TLatex or
    87 //  MEnv::GetAttText.
     83//      Contents: Date Day Week Holiday Birthday
     84//
     85//  There are NO predefined content-strings. All the names given here
     86//  are completely artificial. You could also call them just A and B.
     87//  If you setup them correctly they might still behave like Date and Day.
     88//  This also means that you can define as many of them as you want.
     89//
     90//  You can setup the contents by their names individually (eg. Holiday).
     91//  The possible Style is defined by a TLatex object. For more details
     92//  see TLatex or MEnv::GetAttText.
    8893//
    8994//      To setup the position in the pave use:
     
    101106//          Holiday.Format: %a
    102107//
    103 //  Contents for which a format was setup are build using MTime::GetStringFmt.
    104 //  Contents without a format set are searched in the holiday resource.
     108//  Contents for which a format was setup are compiled by using
     109//  MTime::GetStringFmt.
     110//  Contents without a format set (by eg. Holiday.Format) are searched in
     111//  the holiday resource file:
    105112//
    106113//      For the 1.1. and 25.12. the setup could be:
     
    108115//          Holiday.12/25: Christmas
    109116//
    110 //      If the contents name is "Easter" the search is done relative to Easter:
    111 //          Easter.-1: Easter Saturday
    112 //          Easter.0: Easter
    113 //          Easter.1: Easter Monday
    114 //
    115 //  In addition to this you can overwrite the this default for the active
     117//      Holidays with respect to Easter are given as
     118//          Holiday.-1: Easter Saturday
     119//          Holiday.0: Easter
     120//          Holiday.1: Easter Monday
     121//
     122//  In addition to this you can overwrite the default for the active
    116123//  and/or inactivedays by:
    117124//     Date.Active.{PaveStyle}
     
    146153//    change the Layout. For more details see section "Resource Files"
    147154//
    148 //  void ResetLayout()
    149 //    Remove everything from the layout
     155//  void ResetLayout(num)
     156//    Remove everything from the layout. num is the number of default blocks
     157//    (corresponding to NumBlocks). A value smaller or equal 0 will leave
     158//    the number of block unchanged (which is the default from the
     159//    context menu)
    150160//
    151161//  void ResetHolidays()
    152162//    remove all holidays.
    153163//
    154 //  void SetDefaultLayout()
    155 //    set the layout to the default layout
     164//  void SetDefaultLayout(num)
     165//    set the layout to the default layout. num is the number of displayed
     166//    blocks (corresponding to NumBlocks). A value smaller or equal 0 will
     167//    leave the number of block unchanged (which is the default from the
     168//    context menu)
    156169//
    157170//  void SetDefaultHolidays()
     
    185198//  void SetEaster(Float_t FontSize=0.13, Int_t Color=kBlue)
    186199//    set the current position in the pave to a holiday with name
    187 //    "Holiday", "Birthday" or "Easter". The holidays are read from the
     200//    "Holiday", "Birthday". The holidays are read from the
    188201//    holiday resource file. For more details see section "Resource files"
    189202//
     
    191204//  void AddBirthday(const char *text)
    192205//  void AddEaster(const char *text)
    193 //    Add a holiday ("Holiday.mm/dd", "Birthday.mm/dd" or "Easter.%d")
     206//    Add a holiday ("Holiday.mm/dd", "Birthday.mm/dd" or "Holiday.%d")
    194207//    for the current date (for easter the offset to easter is used instead)
    195208//    to the holiday resources.
     
    239252
    240253#include <TStyle.h>
     254#include <TArrow.h>
    241255#include <TLatex.h>
     256#include <TMarker.h>
    242257#include <TArrayD.h>
    243258#include <TCanvas.h>
     
    246261#include <TASImage.h>
    247262#include <TPaveText.h>
     263#include <THashList.h>
    248264
    249265#include "MEnv.h"
     
    359375    def.SetLineStyle(kSolid);
    360376    def.SetLineColor(kBlack);
    361     def.SetLineWidth(1);
     377    def.SetLineWidth(0);
    362378    def.SetFillColor(18);
    363379    def.SetFillStyle(1001);
     
    486502
    487503    env.SetValue("Orientation",          fOrientation);
     504    env.SetValue("Rotation",             fRotation);
    488505
    489506    env.SetValue("Moon.Graf.Align",      fMoonAlignGraf);
     
    532549    const TString name = fname ? fname : fEnv->GetName();
    533550
    534     ResetLayout();
     551    ResetLayout(2);
    535552
    536553    delete fEnv;
     
    541558
    542559    fOrientation   = fEnv->GetValue("Orientation",          fOrientation);
     560    fRotation      = fEnv->GetValue("Rotation",             fOrientation);
    543561
    544562    fMoonAlignGraf = fEnv->GetValue("Moon.Graf.Align",      fMoonAlignGraf);
     
    576594// Reset the layout (remove everything)
    577595//
    578 void MCalendar::ResetLayout()
     596// num is the number of default blocks (corresponding to NumBlocks).
     597// A value smaller or equal 0 will leave the number of block unchanged
     598// (which is the default)
     599//
     600void MCalendar::ResetLayout(Int_t num)
    579601{
    580602    fOrientation   = kFALSE;
     603    fRotation      = kFALSE;
    581604
    582605    fFirstDay      = 1;
    583     fNumBlocks     = 2;
     606
     607    if (num>0)
     608        fNumBlocks = num;
    584609
    585610    fMoonAlignGraf = 0;
     
    621646    ResetHolidays();
    622647
    623     fEnvHolidays->SetValue("Easter.0",      "Easter");
     648    fEnvHolidays->SetValue("Holiday.0",     "Easter");
    624649    fEnvHolidays->SetValue("Holiday.01/01", "New Year");
    625650    fEnvHolidays->SetValue("Holiday.12/25", "Christmas");
     
    631656// Set the layout to the default layout
    632657//
    633 void MCalendar::SetDefaultLayout()
    634 {
    635     ResetLayout();
     658// num is the number of default blocks (corresponding to NumBlocks).
     659// A value smaller or equal 0 will leave the number of block unchanged
     660// (which is the default)
     661//
     662void MCalendar::SetDefaultLayout(Int_t num)
     663{
     664    ResetLayout(num);
    636665
    637666    fMoonAlignGraf = 11;
    638667    fMoonAlignText = 11;
    639668
    640     fEnv->SetValue("Contents", "Day Date Holiday Birthday Easter");
    641 
    642     fEnv->SetValue("Day.TextAlign",      "top left");
    643     fEnv->SetValue("Day.Format",         "%e");
    644 
    645     fEnv->SetValue("Date.TextAlign",     "bottom right");
    646     fEnv->SetValue("Date.Format",        "%a");
    647 
    648     fEnv->SetValue("Holiday.TextAlign",  "center");
    649     fEnv->SetValue("Holiday.TextSize",   0.13);
    650     fEnv->SetValue("Holiday.TextColor",  kBlue);
    651 
    652     fEnv->SetValue("Birthday.TextAlign", "center");
    653     fEnv->SetValue("Birthday.TextSize",  0.13);
    654     fEnv->SetValue("Birthday.TextColor", kBlue);
    655 
    656     fEnv->SetValue("Easter.TextAlign",   "center");
    657     fEnv->SetValue("Easter.TextSize",    0.13);
    658     fEnv->SetValue("Easter.TextColor",   kBlue);
     669    fEnv->SetValue("Contents", "Day Date Week Holiday Birthday");
     670
     671    fEnv->SetValue("Day.TextAlign",           "top left");
     672    fEnv->SetValue("Day.Format",              "%e");
     673
     674    fEnv->SetValue("Date.TextAlign",          "bottom right");
     675    fEnv->SetValue("Date.Format",             "%a");
     676
     677    fEnv->SetValue("Week.TextAlign",          "top right");
     678    fEnv->SetValue("Week.Format",             "KW%V");
     679    fEnv->SetValue("Week.TextSize",           0.1);
     680    fEnv->SetValue("Week.Restriction",        1);
     681    fEnv->SetValue("Week.Active.TextColor",   "Grey8");
     682
     683    fEnv->SetValue("Holiday.TextAlign",       "center");
     684    fEnv->SetValue("Holiday.TextSize",        0.13);
     685    fEnv->SetValue("Holiday.TextColor",       kBlue);
     686
     687    fEnv->SetValue("Birthday.TextAlign",      "center");
     688    fEnv->SetValue("Birthday.TextSize",       0.13);
     689    fEnv->SetValue("Birthday.TextColor",      kBlue);
     690
     691    //    fEnv->SetValue("Easter.TextAlign",        "center");
     692    //    fEnv->SetValue("Easter.TextSize",         0.13);
     693    //    fEnv->SetValue("Easter.TextColor",        kBlue);
    659694
    660695    fEnv->SetValue("Date.Active.0.TextColor", kRed);
    661696
    662     fEnv->SetValue("Date.Active.TextFont",    22);
    663     fEnv->SetValue("Day.Active.TextFont",     22);
    664     fEnv->SetValue("Date.Inactive.TextFont", 132);
    665     fEnv->SetValue("Day.Inactive.TextFont",  132);
     697    fEnv->SetValue("Date.Active.TextFont",     22);
     698    fEnv->SetValue("Day.Active.TextFont",      22);
     699    fEnv->SetValue("Date.Inactive.TextFont",  132);
     700    fEnv->SetValue("Day.Inactive.TextFont",   132);
    666701
    667702    // fEnv->SetValue("Date.Inactive.LineStyle", kDashed);
     
    683718    //fUpdate = kFALSE;
    684719
    685     SetDefaultLayout();
     720    SetDefaultLayout(2);
    686721    SetDefaultHolidays();
    687722
     
    731766Int_t MCalendar::Rotate(Int_t align, Bool_t fwd) const
    732767{
    733     if (!fOrientation)
     768    if (fOrientation==fRotation)
    734769        return align;
    735770
    736     static const Int_t a[4] = { 11, 31, 33, 13 };
    737     static const Int_t b[4] = { 11, 13, 33, 31 };
     771    static const Int_t b[4] = { 11, 31, 33, 13 };
     772    static const Int_t a[4] = { 11, 13, 33, 31 };
    738773
    739774    const Int_t *c = fwd ? a :b;
     
    780815    */
    781816
    782     const Double_t scale = fOrientation ? x[1]-x[0] : y[1]-y[0];
    783     const Double_t phi   = fOrientation ? 90 : 0;
     817    const Double_t scale = fOrientation            ? x[1]-x[0] : y[1]-y[0];
     818    const Double_t phi   = fOrientation!=fRotation ? -90 : 0;
    784819
    785820    Convert2Latex(str);
     
    787822    tex.SetTextAlign(align);
    788823    tex.PaintLatex(p[0], p[1], phi, att.GetTextSize()*scale, str);
     824}
     825
     826//---------------------------------------------------------------------------
     827//
     828// Paint a clock as a symbol for summer-/wintertime
     829//
     830void MCalendar::PaintClock(Double_t x[2], Double_t y[2], Double_t r[2], Int_t fill, char dir)
     831{
     832    Double_t k[2] = { (x[0]+x[1])/2, (y[0]+y[1])/2 };
     833
     834    TEllipse e(k[0], k[1], r[0]*2.5, r[1]*2.5, 30, 360, 0);
     835    e.SetLineColor(kBlack);
     836    e.SetLineStyle(kSolid);
     837    e.SetFillColor(fill);
     838    e.Paint();
     839
     840    TMarker m;
     841    m.SetMarkerStyle(kFullDotSmall);
     842    for (int i=2; i<12; i++)
     843        m.PaintMarker(k[0]+r[0]*2*cos(TMath::TwoPi()*i/12),
     844                      k[1]+r[1]*2*sin(TMath::TwoPi()*i/12));
     845
     846    TArrow a(k[0]+r[0]*3, k[1], k[0]+r[0]*2.7, k[1]+r[1]*1.5, r[1]/2);
     847    a.Paint(dir=='-'?"->":"<-");
    789848}
    790849
     
    796855// of the MTime.
    797856//
    798 // If the name is "Easter" the format of the resource searched for is
    799 //   Easter.o
    800 // while o is the offset from Easter (eg. Easter.-5, Easter.0 or Easter.22)
    801 //
    802857TString MCalendar::GetHoliday(const TObject &o, const MTime &tm)
    803858{
     
    811866    TString env(o.GetName());
    812867
    813     const TString post = env=="Easter" ?
    814         Form(".%d", (Int_t)tm.GetMjd()-easter) :
    815         Form(".%02d/%02d", tm.Month(), tm.Day());
    816 
    817     return fEnvHolidays->GetValue(env+post, "");
    818 }
    819 
    820 //#include <iostream>
     868    const TString post1 = Form(".%d", (Int_t)tm.GetMjd()-easter);
     869    const TString post2 = Form(".%02d/%02d", tm.Month(), tm.Day());
     870
     871    TString rc;
     872    for (int i=0; i<7; i++)
     873    {
     874        MTime tx(tm.GetMjd()+i);
     875        const TString post3 = Form(".%02d/%02d-%d", tx.Month(), tx.Day(), (7-tm.WeekDay())%7);
     876        rc = fEnvHolidays->GetValue(env+post3, rc);
     877    }
     878
     879    rc = fEnvHolidays->GetValue(env+post1, rc);
     880    rc = fEnvHolidays->GetValue(env+post2, rc);
     881/*
     882    if (fLanguage=="de_DE")
     883    {
     884        MTime t;
     885        t.Set(fYear, 5, 14);
     886        t.SetMjd(t.GetMjd()-t.WeekDay());
     887
     888        if ((Int_t)t.GetMjd() == easter + 49)
     889            t.SetMjd(t.GetMjd()-7);
     890
     891        if ((Int_t)tm.GetMjd()==(Int_t)t.GetMjd())
     892            return "Muttertag";
     893    }
     894
     895  */
     896    return rc;
     897}
     898
    821899void MCalendar::Paint(Option_t *o)
    822900{
     
    830908
    831909    // How should this be done?
    832     fOrientation = gPad->PixeltoX(1)>-gPad->PixeltoY(1);
     910    //fOrientation = gPad->PixeltoX(1)>-gPad->PixeltoY(1);
    833911
    834912    MTime t;
     
    870948        pave.Paint(pave.GetOption());
    871949
     950        Double_t r[2] = {
     951            fMoonRadius*ratio[0],
     952            fMoonRadius*ratio[1]
     953        };
     954
    872955        // ---------- Paint Text ----------
    873956        const TString contents = fEnv->GetValue("Contents", "");
     
    881964            latex.SetName(o->GetName());
    882965
     966            const TString res = fEnv->GetValue(Form("%s.Restriction", o->GetName()), "0123456");
     967            if (res.First('0'+tm.WeekDay())<0)
     968                continue;
     969
    883970            GetLatex(latex, active, day);
    884971
    885972            const TString text = GetHoliday(latex, tm);
     973
     974            if (text=="T+" || text=="T-")
     975            {
     976                PaintClock(x, y, r, pave.GetFillColor(), text[1]);
     977                continue;
     978            }
    886979
    887980            if (!text.IsNull())
    888981                PaintLatex(latex, latex.GetTextAlign(), x, y, ratio, text);
    889 
    890982        }
    891983
     
    893985
    894986        // ---------- Paint Moon Phase -----------
    895         Double_t r[2] = {
    896             fMoonRadius*ratio[0],
    897             fMoonRadius*ratio[1]
    898         };
     987        //Double_t r[2] = {
     988        //    fMoonRadius*ratio[0],
     989        //    fMoonRadius*ratio[1]
     990        //};
    899991        Double_t m[2] = {
    900992            fMarginX*ratio[0] + r[0],
     
    9091001        // location, the text is a discrete number and it is
    9101002        // switched to continous.
    911         const Float_t phi  = fOrientation ? 90 : 0;
    912         const Int_t   dx   = fOrientation;
    913         const Int_t   dy   = (fOrientation+1)%2;
     1003        const Bool_t  rot  = fOrientation!=fRotation;
     1004        const Float_t phi  = rot ? -90 : 0;
     1005        const Int_t   dx   = rot;
     1006        const Int_t   dy   = (rot+1)%2;
    9141007        const Bool_t  cont = fMoonTextType==0 || fMoonTextCont;
    9151008        if (fMoonAlignGraf)
     
    9181011
    9191012            if (fMoonAlignGraf==fMoonAlignText && cont && fMoonAlignGraf==22)
    920                 p[dy] += m[dy]/2;
     1013                p[dy] += rot ? -m[dy]/2 : m[dy]/2;
    9211014
    9221015            TEllipse e(p[0], p[1], r[0], r[1], -90+phi, 90+phi, 0);
     
    9371030            const Double_t R  = tm.GetMoonPhase()<0.5 ? 1-tm.GetMoonPhase() : tm.GetMoonPhase();
    9381031            const Double_t r0 = 1.0-TMath::Sqrt(2.0-2.0*R);
    939             if (fOrientation)
     1032            if (rot)
    9401033                e.SetR2(r[1]*r0);  // bug in PaintEllipse!
    9411034            else
     
    9571050            if (fMoonAlignGraf==fMoonAlignText && cont)
    9581051            {
     1052                if (rot)
     1053                {
     1054                    m[dx] = -m[dx];
     1055                    m[dy] = -m[dy];
     1056                }
     1057
    9591058                switch (fMoonAlignGraf/10)
    9601059                {
     
    9981097Bool_t MCalendar::GetBox(Int_t n, Double_t x[2], Double_t y[2], Double_t *ratio)
    9991098{
    1000     const Int_t   maxrows = 28/(7*fNumBlocks) + 1;
     1099    //const Int_t   maxrows = 6; //28/(7*fNumBlocks) + 1;
    10011100    const Float_t addrows = 0;
     1101
     1102    Int_t maxrows;
     1103    switch(fNumBlocks)
     1104    {
     1105    case 0:
     1106    case 1: maxrows=6; break;
     1107    case 2: maxrows=3; break;
     1108    case 3: maxrows=2; break;
     1109    case 4: maxrows=2; break;
     1110    default: maxrows=1; break;
     1111    }
    10021112
    10031113    const Float_t ratio0  = -gPad->PixeltoX(1)/gPad->PixeltoY(1);
     
    10111121    const Float_t  blockx = fOrientation ? fBlockSpace/ratio0 : fBlockSpace*ratio0;
    10121122
    1013     const Float_t  w      = (0.98-cellx*(7*fNumBlocks-1)-(fNumBlocks-1)*blockx)/(fNumBlocks*7);
    1014     const Float_t  h      = (0.98-celly*(maxrows-1)/*-blockspacey*/)/(maxrows+addrows);
     1123    const Float_t  w      = (0.99-cellx*(7*fNumBlocks-1)-(fNumBlocks-1)*blockx)/(fNumBlocks*7);
     1124    const Float_t  h      = (0.99-celly*(maxrows-1)/*-blockspacey*/)/(maxrows+addrows);
    10151125
    10161126
     
    10201130    const Int_t    col    = ix/7;
    10211131
    1022     const Double_t p0     = 0.01 - col*(cellx - blockx);
     1132    const Double_t p0     = 0.005 - col*(cellx - blockx);
    10231133
    10241134    TArrayD a(2), b(2);
     
    10271137    a[1] =  p0   + ix*(cellx + w) + w;
    10281138
    1029     b[0] =  0.99 - iy*(celly + h) - h;
    1030     b[1] =  0.99 - iy*(celly + h);
     1139    b[0] =  0.995 - iy*(celly + h) - h;
     1140    b[1] =  0.995 - iy*(celly + h);
    10311141
    10321142    if (ratio)
     
    10381148    if (fOrientation)
    10391149    {
    1040         x[0] = 1-b[1];
    1041         x[1] = 1-b[0];
     1150        x[0] = b[0];
     1151        x[1] = b[1];
    10421152        y[0] = a[0];
    10431153        y[1] = a[1];
     
    10501160        y[1] = b[1];
    10511161    }
     1162
     1163    if (fOrientation)
     1164    {
     1165        TArrayD d(2,y);
     1166        y[0] = 1-d[1];
     1167        y[1] = 1-d[0];
     1168    }
     1169
     1170    if (fRotation)
     1171    {
     1172        TArrayD d(2,x);
     1173        x[0] = 1-d[1];
     1174        x[1] = 1-d[0];
     1175    }
     1176
    10521177    return ix==0 && iy>0;
    10531178}
     
    11981323    const Int_t easter = (Int_t)MTime::GetEaster(fYear).GetMjd();
    11991324
    1200     const TString str = Form("Easter.%d", (Int_t)t.GetMjd()-easter);
     1325    const TString str = Form("Holiday.%d", (Int_t)t.GetMjd()-easter);
    12011326
    12021327    fEnvHolidays->SetValue(str, text);
     
    12471372// DrawImage cd()'s to the new pad.
    12481373//
    1249 TASImage *MCalendar::DrawImage(const TASImage &img, Float_t x1, Float_t y1, Float_t x2, Float_t y2) const
    1250 {
    1251     TPad *pad=new TPad("Img", "Image", x1, y1,x2, y2);
     1374TASImage *MCalendar::DrawImage(const TASImage &img, Float_t x1, Float_t y1, Float_t x2, Float_t y2, Bool_t rot) const
     1375{
     1376    TPad *pad=new TPad("Img", "Image", x1, y1, x2, y2);
    12521377    pad->SetBorderMode(0);
    12531378    pad->SetFillColor(gPad?gPad->GetFillColor():kWhite);
     
    12691394    pad->Update();
    12701395
    1271     const Int_t w = clone->GetScaledWidth();
    1272     const Int_t h = clone->GetScaledHeight();
     1396    const Int_t wi = clone->GetScaledWidth();
     1397    const Int_t hi = clone->GetScaledHeight();
    12731398
    12741399    TCanvas *c = pad->GetCanvas();
    12751400
    1276     const Float_t ml = (1-c->PixeltoX(w))/2;
    1277     const Float_t mb = (1+c->PixeltoY(h))/2;
    1278 
    1279     pad->SetPad(ml, 2*mb, 1-ml, 1);
     1401    const Float_t x = (x1+x2)/2;
     1402    const Float_t y = (y1+y2)/2;
     1403
     1404    Float_t w = TMath::Abs(x2-x1)/2;
     1405    Float_t h = TMath::Abs(y2-y1)/2;
     1406
     1407    const Float_t ri = TMath::Abs(c->PixeltoX(wi)/c->PixeltoY(hi));
     1408    const Float_t rp = TMath::Abs(w/h);
     1409
     1410    if (ri>rp)
     1411        h = w/ri;
     1412    else
     1413        w = h*ri;
     1414
     1415    pad->SetPad(x-w, y-h, x+w, y+h);
     1416    pad->SetFixedAspectRatio();
    12801417
    12811418    return clone;
     
    13111448// of deleting it)
    13121449//
    1313 TASImage *MCalendar::GetImage(TEnv *env)
     1450TASImage *MCalendar::GetImage(TEnv *env, const char *pwd)
    13141451{
    13151452    if (!env)
     
    13221459    ConvertUTF8(fStrMonth,  kFALSE);
    13231460
     1461    const TString path(pwd);
     1462
    13241463    TString file = env->GetValue(fStrMonth, "");
    13251464    if (!file.Strip(TString::kBoth).IsNull())
    1326         return ReturnFile(file);
     1465        return ReturnFile(path+file);
    13271466
    13281467    file = env->GetValue(fStrMonth3, "");
    13291468    if (!file.Strip(TString::kBoth).IsNull())
    1330         return ReturnFile(file);
     1469        return ReturnFile(path+file);
    13311470
    13321471    file = env->GetValue(Form("%02d", fMonth), "");
    13331472    if (!file.Strip(TString::kBoth).IsNull())
    1334         return ReturnFile(file);
     1473        return ReturnFile(path+file);
    13351474
    13361475    return NULL;
     
    14011540
    14021541TASImage *MCalendar::DrawTTF(Float_t x1, Float_t x2, Float_t y1, Float_t y2,
    1403                              const char *text, Int_t size, const char *font)
     1542                             const char *text, Float_t sz, const char *font)
    14041543{
    14051544    const char *file = GetTTFontPath(font);
     
    14071546        return NULL;
    14081547
     1548    const Int_t size = TMath::Nint(sz*941);
     1549
    14091550    TTF::SetTextFont(file);
     1551    TTF::SetTextSize(size);
    14101552
    14111553    delete file;
    14121554
    1413     TTF::SetRotationMatrix(0);
    1414     TTF::SetTextSize(size);
    1415     TTF::PrepareString(text);
    1416     TTF::LayoutGlyphs();
     1555    UInt_t wi, hi;;
     1556    TTF::GetTextExtent(wi, hi, (char*)text);
    14171557
    14181558    const FT_BBox &box = TTF::GetBox();
    1419 
    1420     TASImage img(3*box.xMax/2, 3*box.yMax/2);
     1559    //cout << hi-box.yMax << " " <<   wi << " "<< (float)size/hi << endl;
     1560    //wi = wi;//TMath::Nint((float)wi*(size+hi-box.yMax)/size);
     1561    //wi += TMath::Nint(((float)size/hi-1)*wi);
     1562
     1563    const UInt_t add = size-box.yMax;
     1564
     1565    wi += size*(hi+add)/hi;
     1566    hi += add;
     1567    // wi += size*(hi+size-box.yMax)/hi;
     1568    // hi += size-box.yMax;
     1569
     1570    TASImage img(wi, hi);
    14211571    img.FillRectangle();
     1572
     1573    Double_t x = (x1+x2)/2;
     1574    Double_t y = (y1+y2)/2;
     1575
     1576    Double_t w = gPad->PixeltoX(wi)/2;
     1577    Double_t h = gPad->PixeltoY(hi)/2;
    14221578
    14231579    // gROOT->GetColor(kBlack)->AsHexString()
    14241580    DrawDate(img, 0, 0, text, size, "#00000000", font);
    1425     return DrawImage(img, x1, y1, x2, y2);
    1426 }
     1581    return DrawImage(img, x-w, y-h, x+w, y+h);
     1582}
     1583
     1584/*
     1585void MCalendar::Update()
     1586{
     1587    cout << "Update" << endl;
     1588    fUpdate=kTRUE;
     1589}
     1590
     1591void MCalendar::Selected(TVirtualPad *pad,TObject *o,Int_t event)
     1592{
     1593    if (event==kButton1Down && pad)
     1594    {
     1595        pad->cd();
     1596        fAlign = GetAlign();
     1597        fActive = GetDate().Month()==fMonth;
     1598        fEnv->GetAttLine(fActive?"Date.Active":"Date.Inactive", *this);
     1599        fEnv->GetAttLine(Form(fActive?"Date.Active.%d":"Date.Inactive.%d", fDay), *this);
     1600    }
     1601
     1602    cout << "SetModel " << gPad << " " << pad << " " << o << " " << event << endl;
     1603    //Picked(fSelectedPad, fSelected, fEvent);  // emit signal
     1604
     1605}
     1606
     1607void MCalendar::SetAttributes()
     1608{
     1609    if (!gPad)
     1610        return;
     1611
     1612    TAttLine::SetLineAttributes();
     1613
     1614    cout << "gPad " << gPad << endl;
     1615
     1616    fAlign  = GetAlign();
     1617    fActive = GetDate().Month()==fMonth;
     1618    fDay    = GetDate().WeekDay();
     1619
     1620    fEnv->GetAttLine(fActive?"Date.Active":"Date.Inactive", *this);
     1621    fEnv->GetAttLine(Form(fActive?"Date.Active.%d":"Date.Inactive.%d", fDay), *this);
     1622
     1623    TQObject::Connect("TCanvas", "Selected(TVirtualPad*,TObject*,Int_t)",
     1624                      "MCalendar", this, "Selected(TVirtualPad*,TObject*,Int_t)");
     1625
     1626    TQObject::Connect("TGedPatternSelect", "PatternSelected(Style_t)", "MCalendar", this, "Update()");
     1627    TQObject::Connect("TGColorSelect",     "ColorSelected(Pixel_t)",   "MCalendar", this, "Update()");
     1628    TQObject::Connect("TGListBox",         "Selected(Int_t)",          "MCalendar", this, "Update()");
     1629}
     1630*/
     1631
  • trunk/MagicSoft/Mars/mtools/MCalendar.h

    r7451 r7893  
    1414#include <Gtypes.h>
    1515#endif
     16
     17/*
     18#include <TAttLine.h>
     19#include <TAttFill.h>
     20#include <TAttText.h>
     21*/
    1622
    1723class TEnv;
     
    2632class MTime;
    2733
    28 class MCalendar : public TObject
     34class MCalendar : public TObject//, public TAttLine, public TAttText, public TAttFill
    2935{
    3036private:
     37    /*
     38    enum {
     39        kMoonPhase,
     40        kMoonPeriod,
     41        kMagicPeriod
     42    };*/
     43
     44    /*
     45    Int_t  fAlign;
     46    Bool_t fActive;
     47    Bool_t fUpdate;
     48    Int_t  fDay;
     49    */
    3150    MEnv    *fEnv;
    3251    MEnv    *fEnvHolidays;
    3352
    3453    Bool_t   fOrientation;
     54    Bool_t   fRotation;
    3555
    3656    Int_t    fYear;
     
    7898    // Paint text
    7999    void PaintLatex(TAttText &att, Int_t align, Double_t x[2], Double_t y[2], Double_t ratio[2], /*Double_t height,*/ TString str);
     100    void PaintClock(Double_t x[2], Double_t y[2], Double_t r[2], Int_t fill, char dir);
    80101
    81102    // GUI interactions
     
    105126    Float_t     GetMoonRadius() const { return fMoonRadius; }
    106127    TString     GetStringFmt(const char *fmt="%B", Int_t day=1, Int_t h=12, Int_t m=0, Int_t s=0) const;
     128    Bool_t      IsRotated() const { return fRotation; }
     129    Bool_t      IsVertical() const { return fOrientation; }
    107130
    108131
     
    113136    void SetLayout(Byte_t NumberOfBlocks, Double_t MarginX, Double_t MarginY, Double_t CellSpace, Double_t BlockSpace) { fNumBlocks=NumberOfBlocks, fMarginX=MarginX; fMarginY=MarginY; fCellSpace=CellSpace; fBlockSpace=BlockSpace; } //*MENU* *ARGS={NumberOfBlocks=>fNumBlocks,MarginX=>fMarginX,MarginY=>fMarginY,CellSpace=>fCellSpace,BlockSpace=>fBlockSpace}
    114137
    115     void ResetLayout();   //*MENU
     138    void ResetLayout(Int_t num);
     139    void ResetLayout() { ResetLayout(-1); } //*MENU
    116140    void ResetHolidays(); //*MENU
    117141
    118     void SetDefaultLayout();   //*MENU
     142    void SetDefaultLayout(Int_t num);
     143    void SetDefaultLayout() { SetDefaultLayout(-1); } //*MENU
    119144    void SetDefaultHolidays(); //*MENU
    120145
     
    141166
    142167    //    void ToggleOrientation() { fOrientation = !fOrientation; } //*MENU
     168    void SetRotated(Bool_t b=kTRUE) { fRotation = b; } // *TOGGLE* *GETTER=IsRotated
     169    void SetVertical(Bool_t b=kTRUE) { fOrientation = b; } // *TOGGLE* *GETTER=IsVertical
    143170
    144171    void PrintEnv() const; //*MENU
     
    146173    void RemoveEnv(const char *VariableName) const;//*MENU
    147174
    148 
    149175    void SetMoonGraf(Int_t Align, Float_t Radius) { fMoonAlignGraf=Align; fMoonRadius=Radius; } //*MENU* *ARGS={Align>=fMoonAlignGraf,Radius=>fMoonRadius}
    150176    void SetMoonText(Int_t Align, Int_t Type, Int_t Continous) { fMoonAlignText=Align; fMoonTextType=Type; fMoonTextCont=Continous; } //*MENU* *ARGS={Align>=fMoonAlignText,Type=>fMoonTextType,Continous=>fMoonTextCont}
    151177
    152178    // Calendar sheet interface
    153     TASImage *DrawImage(const TASImage &img, Float_t x1, Float_t y1, Float_t x2, Float_t y2) const;
    154     TASImage *GetImage(TEnv *env=NULL);
     179    TASImage *DrawImage(const TASImage &img, Float_t x1, Float_t y1, Float_t x2, Float_t y2, Bool_t rot=kFALSE) const;
     180    TASImage *GetImage(TEnv *env=NULL, const char *path="");
    155181    void      DrawLatex(Float_t x, Float_t y, const char *text, const TAttText &att);
    156182    void      DrawDate(Float_t x, Float_t y, const char *text, const TAttText &att)
     
    168194    }
    169195    TASImage *DrawTTF(Float_t x1, Float_t x2, Float_t y1, Float_t y2,
    170                       const char *text, Int_t size, const char *font);
     196                      const char *text, Float_t size, const char *font);
    171197    TASImage *DrawTTFDate(Float_t x1, Float_t x2, Float_t y1, Float_t y2,
    172                           const char *text, Int_t size, const char *font)
     198                          const char *text, Float_t size, const char *font)
    173199    {
    174200        return DrawTTF(x1, y1, x2, y2, GetStringFmt(text), size, font);
     
    183209    void Paint(Option_t *o="");
    184210
     211    /*
     212     void Update();
     213     void SetLineAttributes() {}
     214     void SetFillAttributes() {}
     215     void SetTextAttributes() {}
     216     void SetTextAngle(Float_t) {}
     217     void Selected(TVirtualPad*,TObject*,Int_t);
     218     */
     219     //void SetAttributes(); //*MENU
     220
    185221    ClassDef(MCalendar, 1)
    186222};
Note: See TracChangeset for help on using the changeset viewer.