Ignore:
Timestamp:
03/01/09 21:54:27 (16 years ago)
Author:
tbretz
Message:
*** empty log message ***
Location:
trunk/MagicSoft/Mars/mtools
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Mars/mtools/MagicCivilization.cc

    r2173 r9369  
    22!
    33! *
    4 ! * This file is part of MARS, the MAGIC Analysis and Reconstruction
     4! * This file is part of CheObs, the Modular Analysis and Reconstruction
    55! * Software. It is distributed to you in the hope that it can be a useful
    66! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
     
    99! * Permission to use, copy, modify and distribute this software and its
    1010! * documentation for any purpose is hereby granted without fee,
    11 ! * provided that the above copyright notice appear in all copies and
     11! * provided that the above copyright notice appears in all copies and
    1212! * that both that copyright notice and this permission notice appear
    1313! * in supporting documentation. It is provided "as is" without express
     
    1616!
    1717!
    18 !   Author(s): Thomas Bretz 07/2002 <mailto:tbretz@astro.uni-wuerzburg.de>
    19 !
    20 !   Copyright: MAGIC Software Development, 2000-2002
     18!   Author(s): Thomas Bretz7/2002 <mailto:tbretz@astro.uni-wuerzburg.de>
     19!
     20!   Copyright: CheObs Software Development, 2000-2009
    2121!
    2222!
     
    6565#include <TInterpreter.h>
    6666
    67 #include "MHexagon.h"
     67#include "MH.h"
    6868
    6969#include "MGeomPix.h"
     
    8080        return;
    8181
    82     fPixels->Delete();
    83 
    84     delete fPixels;
    85 
    8682    delete fGeomCam;
    87 }
    88 
    89 // ------------------------------------------------------------------------
    90 //
    91 // Draw all pixels of the camera
    92 //  (means apend all pixelobjects to the current pad)
    93 //
    94 void MagicCivilization::DrawHexagons()
    95 {
    96     for (UInt_t i=0; i<fNumPixels; i++)
    97         (*this)[i].Draw();
    9883}
    9984
     
    11196    ct1 = !ct1;
    11297
    113     DrawHexagons();
     98    AppendPad();
    11499}
    115100
     
    117102{
    118103    Free();
    119 
    120     //
    121     //  Reset the display geometry
    122     //
    123     fW=0;
    124     fH=0;
    125104
    126105    //
     
    135114    fRange     = fGeomCam->GetMaxRadius();
    136115
    137     //
    138     // Construct all hexagons. Use new-operator with placement
    139     //
    140     fPixels = new TClonesArray("MHexagon", fNumPixels);
    141 
    142     for (UInt_t i=0; i<fNumPixels; i++)
    143     {
    144         MHexagon &h = *new ((*fPixels)[i]) MHexagon((*fGeomCam)[i]);
    145 #if ROOT_VERSION_CODE > ROOT_VERSION(3,01,06)
    146         h.SetBit(kNoContextMenu|kCannotPick);
    147 #endif
    148     }
     116    fColors.Set(fNumPixels);
    149117}
    150118
     
    154122//
    155123MagicCivilization::MagicCivilization(Byte_t lim, UShort_t init)
    156     : fTimer(this, 500, kTRUE), fGeomCam(NULL), fNumInit(init), fLimit(lim), fW(0), fH(0)
     124    : fTimer(this, 500, kTRUE), fGeomCam(NULL), fNumInit(init), fLimit(lim)
    157125{
    158126    SetNewCamera(new MGeomCamMagic);
     
    179147    fTimer.TurnOff();
    180148    Free();
    181 
    182     if (fDrawingPad->GetListOfPrimitives()->FindObject(this)==this)
    183     {
    184         fDrawingPad->RecursiveRemove(this);
    185         delete fDrawingPad;
    186     }
    187149}
    188150
     
    195157void MagicCivilization::Paint(Option_t *opt)
    196158{
    197     const UInt_t w = (UInt_t)(gPad->GetWw()*gPad->GetAbsWNDC());
    198     const UInt_t h = (UInt_t)(gPad->GetWh()*gPad->GetAbsHNDC());
    199 
    200     //
    201     // Check for a change in width or height, and make sure, that the
    202     // first call also sets the range
    203     //
    204     if (w*fH == h*fW && fW && fH)
    205         return;
    206 
    207     //
    208     // Calculate aspect ratio (5/4=1.25 recommended)
    209     //
    210     const Double_t ratio = (Double_t)w/h;
    211 
    212     Float_t x;
    213     Float_t y;
    214 
    215     if (ratio>1.0)
    216     {
    217         x = fRange*(ratio*2-1);
    218         y = fRange;
    219     }
    220     else
    221     {
    222         x = fRange;
    223         y = fRange/ratio;
    224     }
    225 
    226     fH = h;
    227     fW = w;
    228 
    229     //
    230     // Set new range
    231     //
    232     fDrawingPad->Range(-fRange, -y, x, y);
     159    const Float_t r = fGeomCam->GetMaxRadius();
     160
     161    MH::SetPadRange(-r, -r, r, r*1.1);
     162
     163    TAttLine line;
     164    TAttFill fill;
     165
     166    // FIXME:
     167    for (UInt_t i=0; i<fNumPixels; i++)
     168    {
     169        const MGeom &pix = (*fGeomCam)[i];
     170
     171        fill.SetFillColor(fColors[i]);
     172        pix.PaintPrimitive(line, fill);
     173    }
     174 /*
     175    for (int i=0; i<6; i++)
     176        fText[i]->Paint();
     177        */
    233178}
    234179
     
    266211    fStep = 0;
    267212
     213    fColors.Reset();
     214
    268215    Update();
    269216
    270     fDrawingPad->Modified();
    271     fDrawingPad->Update();
     217    gPad->Modified();
     218    gPad->Update();
    272219}
    273220
     
    284231    // if no canvas is yet existing to draw into, create a new one
    285232    //
    286     /*TCanvas *c =*/ new TCanvas("MagicCivilization", "Magic Civilization", 0, 0, 800, 800);
    287     //c->ToggleEventStatus();
    288 
    289     fDrawingPad = gPad;
    290     fDrawingPad->SetBorderMode(0);
    291     fDrawingPad->SetFillColor(22);
     233    new TCanvas("MagicCivilization", "Magic Civilization", 0, 0, 800, 800);
     234
     235    gPad->SetBorderMode(0);
     236    gPad->SetFillColor(22);
    292237
    293238    //
     
    296241    //
    297242    AppendPad(option);
    298 
    299     //
    300     // Reset the game pad
    301     //
    302     DrawHexagons();
    303243
    304244    fCivilization.SetTextAlign(23);   // centered/bottom
     
    349289        fAuto = !fAuto;
    350290        Update();
    351         fDrawingPad->Update();
     291        gPad->Update();
    352292        return;
    353293
     
    395335    for (int i=0; i<fNumPixels; i++)
    396336    {
    397         MGeomPix &pix = (*fGeomCam)[i];
     337        MGeom &pix = (*fGeomCam)[i];
    398338
    399339        Byte_t cnt=0;
     
    411351    for (int i=0; i<fNumPixels; i++)
    412352    {
    413         MGeomPix &pix = (*fGeomCam)[i];
    414         MHexagon &hex = (*this)[i];
     353        MGeom &pix = (*fGeomCam)[i];
    415354
    416355        if (pix.TestBit(kHasCreation))
    417356        {
    418357            pix.SetBit(kHasFlag);
    419             hex.SetFillColor(kBlack);
     358            fColors[i] = kBlack;
    420359            fNumCivilizations++;
    421360        }
     
    423362        {
    424363            pix.ResetBit(kHasFlag);
    425             hex.SetFillColor(kBackground);
     364            fColors[i] = kBackground;
    426365        }
    427366        pix.ResetBit(kHasCreation);
     
    435374    Update();
    436375
    437     fDrawingPad->Update();
     376    gPad->Update();
    438377
    439378    return kTRUE;
  • trunk/MagicSoft/Mars/mtools/MagicCivilization.h

    r1440 r9369  
    1414#ifndef ROOT_TClonesArray
    1515#include <TClonesArray.h>
     16#endif
     17#ifndef ROOT_TArrayI
     18#include <TArrayI.h>
    1619#endif
    1720
     
    5053    TText     fCivilization;    // TText showing the numbers of pixels and bombs
    5154
    52     UInt_t    fW;               // Width of canvas
    53     UInt_t    fH;               // Height of canvas
    54 
    55     TClonesArray *fPixels;      // array of all hexagons
    56     TVirtualPad  *fDrawingPad;  // pad in which we are drawing
    57 
    58     MHexagon &operator[](int i) { return *((MHexagon*)fPixels->At(i)); }
     55    TArrayI fColors;
    5956
    6057    void   Update();
    6158    void   Free();
    62     void   DrawHexagons();
    6359    void   SetNewCamera(MGeomCam *);
    6460
  • trunk/MagicSoft/Mars/mtools/MagicDomino.cc

    r8910 r9369  
    22!
    33! *
    4 ! * This file is part of MARS, the MAGIC Analysis and Reconstruction
     4! * This file is part of CheObs, the Modular Analysis and Reconstruction
    55! * Software. It is distributed to you in the hope that it can be a useful
    66! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
     
    99! * Permission to use, copy, modify and distribute this software and its
    1010! * documentation for any purpose is hereby granted without fee,
    11 ! * provided that the above copyright notice appear in all copies and
     11! * provided that the above copyright notice appears in all copies and
    1212! * that both that copyright notice and this permission notice appear
    1313! * in supporting documentation. It is provided "as is" without express
     
    1616!
    1717!
    18 !   Author(s): Thomas Bretz 07/2002 <mailto:tbretz@astro.uni-wuerzburg.de>
     18!   Author(s): Thomas Bretz7/2002 <mailto:tbretz@astro.uni-wuerzburg.de>
    1919!
    20 !   Copyright: MAGIC Software Development, 2000-2008
     20!   Copyright: CheObs Software Development, 2000-2009
    2121!
    2222!
     
    6868#include <TInterpreter.h>
    6969
    70 #include "MHexagon.h"
     70#include "MH.h"
    7171
    7272#include "MGeomPix.h"
     
    8787        return;
    8888
    89     fPixels->Delete();
    90 
    91     delete fPixels;
    92 
    9389    delete fGeomCam;
    94 }
    95 
    96 // ------------------------------------------------------------------------
    97 //
    98 // Draw all pixels of the camera
    99 //  (means apend all pixelobjects to the current pad)
    100 //
    101 void MagicDomino::DrawHexagons()
    102 {
    103     for (UInt_t i=0; i<fNumPixels; i++)
    104         (*this)[i].Draw();
    10590}
    10691
     
    123108
    124109    Reset();
    125     DrawHexagons();
     110    AppendPad();
    126111}
    127112
     
    133118{
    134119    Free();
    135 
    136     //
    137     //  Reset the display geometry
    138     //
    139     fW=0;
    140     fH=0;
    141120
    142121    //
     
    151130    fRange     = fGeomCam->GetMaxRadius();
    152131
    153     //
    154     // Construct all hexagons. Use new-operator with placement
    155     //
    156     fPixels = new TClonesArray("MHexagon", fNumPixels);
    157 
     132    fColors.Set(fNumPixels);
     133}
     134
     135// ------------------------------------------------------------------------
     136//
     137// remove the pixel numbers in the tile from the pad
     138//
     139void MagicDomino::RemoveNumbers()
     140{
     141    for (int i=0; i<6; i++)
     142        fText[i]->SetText(0, 0, "");
     143}
     144
     145// ------------------------------------------------------------------------
     146//
     147// Reset/restart the game
     148//
     149void MagicDomino::Reset()
     150{
    158151    for (UInt_t i=0; i<fNumPixels; i++)
    159152    {
    160         MHexagon &h = *new ((*fPixels)[i]) MHexagon((*fGeomCam)[i]);
     153        fColors[i] = kBackground;
     154        (*fGeomCam)[i].ResetBit(kUserBits);
     155    }
     156
     157
    161158#if ROOT_VERSION_CODE > ROOT_VERSION(3,01,06)
    162         h.SetBit(kNoContextMenu|kCannotPick);
    163 #endif
    164     }
    165 }
    166 
    167 // ------------------------------------------------------------------------
    168 //
    169 // remove the pixel numbers in the tile from the pad
    170 //
    171 void MagicDomino::RemoveNumbers()
    172 {
    173     for (int i=0; i<6; i++)
    174         if (fText[i])
    175         {
    176             delete fText[i];
    177             fText[i] = NULL;
    178         }
    179 }
    180 
    181 // ------------------------------------------------------------------------
    182 //
    183 // Reset/restart the game
    184 //
    185 void MagicDomino::Reset()
    186 {
    187     for (UInt_t i=0; i<fNumPixels; i++)
    188     {
    189         MHexagon &h = (*this)[i];
    190         h.SetFillColor(kBackground);
    191         h.ResetBit(kUserBits);
    192     }
    193 
    194 
    195 #if ROOT_VERSION_CODE > ROOT_VERSION(3,01,06)
    196     fDrawingPad->SetBit(kNoContextMenu);
    197159    SetBit(kNoContextMenu);
    198160#endif
     
    205167
    206168
    207     fDrawingPad->SetFillColor(22);
     169    gPad->SetFillColor(22);
    208170
    209171    fNumPixel = -1;
     
    218180void MagicDomino::Init()
    219181{
    220     memset(fText, 0, sizeof(fText));
     182    for (int i=0; i<6; i++)
     183    {
     184        fText[i] = new TText(0, 0, "");
     185        fText[i]->SetTextFont(122);
     186        fText[i]->SetTextAlign(22);   // centered/centered
     187    }
    221188
    222189    //
     
    260227
    261228    RemoveNumbers();
    262 
    263     if (fDrawingPad->GetListOfPrimitives()->FindObject(this)==this)
    264     {
    265         fDrawingPad->RecursiveRemove(this);
    266         delete fDrawingPad;
    267     }
    268 
    269229}
    270230
     
    277237void MagicDomino::Paint(Option_t *opt)
    278238{
    279     const UInt_t w = (UInt_t)(gPad->GetWw()*gPad->GetAbsWNDC());
    280     const UInt_t h = (UInt_t)(gPad->GetWh()*gPad->GetAbsHNDC());
    281 
    282     //
    283     // Check for a change in width or height, and make sure, that the
    284     // first call also sets the range
    285     //
    286     if (w*fH == h*fW && fW && fH)
    287         return;
    288 
    289     //
    290     // Calculate aspect ratio (5/4=1.25 recommended)
    291     //
    292     const Double_t ratio = (Double_t)w/h;
    293 
    294     Float_t x;
    295     Float_t y;
    296 
    297     if (ratio>1.0)
    298     {
    299         x = fRange*(ratio*2-1);
    300         y = fRange;
    301     }
    302     else
    303     {
    304         x = fRange;
    305         y = fRange/ratio;
    306     }
    307 
    308     fH = h;
    309     fW = w;
    310 
    311     //
    312     // Set new range
    313     //
    314     fDrawingPad->Range(-fRange, -y, x, y);
     239    const Float_t r = fGeomCam->GetMaxRadius();
     240
     241    MH::SetPadRange(-r, -r, r, r*1.1);
     242
     243    TAttLine line;
     244    TAttFill fill;
     245
     246    // FIXME:
     247    for (UInt_t i=0; i<fNumPixels; i++)
     248    {
     249        const MGeom &pix = (*fGeomCam)[i];
     250
     251        fill.SetFillColor(fColors[i]);
     252        pix.PaintPrimitive(line, fill);
     253    }
     254
     255    for (int i=0; i<6; i++)
     256        fText[i]->Paint();
    315257}
    316258
     
    327269    // if no canvas is yet existing to draw into, create a new one
    328270    //
    329     /*TCanvas *c =*/ new TCanvas("MagicDomino", "Magic Domino Next Neighbours", 0, 0, 800, 800);
    330     //c->ToggleEventStatus();
    331 
    332     fDrawingPad = gPad;
    333     fDrawingPad->SetBorderMode(0);
     271    new TCanvas("MagicDomino", "Magic Domino Next Neighbours", 0, 0, 800, 800);
     272
     273    gPad->SetBorderMode(0);
    334274
    335275    //
     
    343283    //
    344284    Reset();
    345     DrawHexagons();
    346 
    347     /*
    348      TPave *p = new TPave(-0.66*fRange, 0.895*fRange, 0.66*fRange, 0.995*fRange, 4, "br");
    349      p->ConvertNDCtoPad();
    350      p->SetFillColor(12);
    351      p->SetBit(kCanDelete);
    352      p->Draw();
    353      */
    354285
    355286    fDomino.SetTextAlign(23);   // centered/bottom
     
    408339    if (fNumPixel>=0)
    409340    {
    410         const MGeomPix &pix=(*fGeomCam)[fNumPixel];
    411         (*this)[fNumPixel].ResetBit(kIsTile);
     341        MGeom &pix=(*fGeomCam)[fNumPixel];
     342        pix.ResetBit(kIsTile);
    412343        for (int i=0; i<pix.GetNumNeighbors(); i++)
    413             (*this)[pix.GetNeighbor(i)].ResetBit(kIsTile);
     344            (*fGeomCam)[pix.GetNeighbor(i)].ResetBit(kIsTile);
    414345
    415346        fPoints += pix.GetNumNeighbors();
     
    425356    Update();
    426357
    427     fDrawingPad->Update();
     358    gPad->Update();
    428359}
    429360
     
    444375
    445376    Int_t cnt=0;
    446     const MGeomPix &pix1=(*fGeomCam)[fNumPixel];
     377    const MGeom &pix1=(*fGeomCam)[fNumPixel];
    447378    for (int i=0; i<pix1.GetNumNeighbors(); i++)
    448379    {
    449380        const Int_t idx1 = pix1.GetNeighbor(i);
    450         const MGeomPix &pix2 = (*fGeomCam)[idx1];
     381        const MGeom &pix2 = (*fGeomCam)[idx1];
    451382
    452383        Byte_t ignored = 0;
     
    454385        for (int j=0; j<pix2.GetNumNeighbors(); j++)
    455386        {
    456             const Int_t    idx2 = pix2.GetNeighbor(j);
    457             const MHexagon &hex = (*this)[idx2];
    458 
    459             if (hex.TestBit(kIsTile) || hex.GetFillColor()==kBackground)
     387            const Int_t idx2 = pix2.GetNeighbor(j);
     388            const MGeom &hex = (*fGeomCam)[idx2];
     389
     390            if (hex.TestBit(kIsTile) || fColors[idx2]==kBackground)
    460391            {
    461392                ignored++;
     
    463394            }
    464395
    465             if (hex.GetFillColor()==(*this)[idx1].GetFillColor())
     396            if (fColors[idx2]==fColors[idx1])
    466397                found++;
    467398        }
     
    487418    fDomino.SetTextColor(kBlue);
    488419
    489     fDrawingPad->SetFillColor(kRed);
     420    gPad->SetFillColor(kRed);
    490421#if ROOT_VERSION_CODE > ROOT_VERSION(3,01,06)
    491422    fDone->SetBit(kNoContextMenu|kCannotPick);
    492     fDrawingPad->ResetBit(kNoContextMenu);
    493423    ResetBit(kNoContextMenu);
    494424#endif
    495425
    496     fDrawingPad->Modified();
    497     fDrawingPad->Update();
     426    gPad->Modified();
     427    gPad->Update();
    498428}
    499429
     
    572502    Update();
    573503
    574     fDrawingPad->Modified();
    575     fDrawingPad->Update();
     504    gPad->Modified();
     505    gPad->Update();
    576506}
    577507
     
    585515        return;
    586516
    587     MagicDomino &This = *this;
    588 
    589517    RemoveNumbers();
    590518
    591     const MGeomPix &pix1=(*fGeomCam)[fNumPixel];
    592     This[fNumPixel].SetFillColor(fOldColors[6]);
    593     This[fNumPixel].ResetBit(kIsTile);
     519    MGeom &pix1=(*fGeomCam)[fNumPixel];
     520    fColors[fNumPixel] = fOldColors[6];
     521    pix1.ResetBit(kIsTile);
    594522    for (int i=0; i<pix1.GetNumNeighbors(); i++)
    595523    {
    596524        Int_t idx = pix1.GetNeighbor(i);
    597525
    598         This[idx].SetFillColor(fOldColors[i]);
    599         This[idx].ResetBit(kIsTile);
     526        fColors[idx] = fOldColors[i];
     527        (*fGeomCam)[idx].ResetBit(kIsTile);
    600528    }
    601529}
     
    609537    if (fNumPixel<0)
    610538        return;
    611 
    612     MagicDomino &This = *this;
    613539
    614540    Int_t indices[6];
     
    617543    RemoveNumbers();
    618544
    619     const MGeomPix &pix2=(*fGeomCam)[fNumPixel];
    620     fOldColors[6] = This[fNumPixel].GetFillColor();
    621     This[fNumPixel].SetFillColor(kBlack);
    622     This[fNumPixel].SetBit(kIsTile);
     545    MGeom &pix2=(*fGeomCam)[fNumPixel];
     546    fOldColors[6] = fColors[fNumPixel];
     547    fColors[fNumPixel] = kBlack;
     548    pix2.SetBit(kIsTile);
    623549    for (int i=0; i<pix2.GetNumNeighbors(); i++)
    624550    {
    625551        Int_t idx = pix2.GetNeighbor(i);
    626552
    627         fOldColors[i] = This[idx].GetFillColor();
     553        fOldColors[i] = fColors[idx];
    628554
    629555        int j=0;
     
    631557            j++;
    632558
    633         This[idx].SetFillColor(fNewColors[(j+fPosition)%6]);
    634         This[idx].SetBit(kIsTile);
     559        MGeom &pix = (*fGeomCam)[idx];
     560
     561        fColors[idx] = fNewColors[(j+fPosition)%6];
     562        pix.SetBit(kIsTile);
    635563
    636564        TString num;
    637565        num += idx;
    638566
    639         fText[i] = new TText(This[idx].GetX(), This[idx].GetY(), num);
    640         fText[i]->SetTextSize(0.3*This[idx].GetD()/fGeomCam->GetMaxRadius());
    641         fText[i]->SetTextFont(122);
    642         fText[i]->SetTextAlign(22);   // centered/centered
    643         fText[i]->Draw();
     567        fText[i]->SetText(pix.GetX(), pix.GetY(), num);
     568        fText[i]->SetTextSize(0.3*pix.GetT()/fGeomCam->GetMaxRadius());
    644569    }
    645570}
     
    659584    Update();
    660585
    661     fDrawingPad->Update();
     586    gPad->Update();
    662587}
    663588
     
    668593Short_t MagicDomino::AnalysePixel(Int_t dir)
    669594{
    670     const MGeomPix &pix=(*fGeomCam)[fNumPixel<0?0:fNumPixel];
     595    const MGeom &pix=(*fGeomCam)[fNumPixel<0?0:fNumPixel];
    671596
    672597    Double_t fAngle[6] = { -10, -10, -10, -10, -10, -10 };
     
    674599    for (int i=0; i<pix.GetNumNeighbors(); i++)
    675600    {
    676         MGeomPix &next = (*fGeomCam)[pix.GetNeighbor(i)];
     601        MGeom &next = (*fGeomCam)[pix.GetNeighbor(i)];
    677602        fAngle[i] = atan2(next.GetY()-pix.GetY(), next.GetX()-pix.GetX());
    678603    }
     
    714639void MagicDomino::GetSortedNeighbors(Int_t indices[6])
    715640{
    716     const MGeomPix &pix=(*fGeomCam)[fNumPixel<0?0:fNumPixel];
     641    const MGeom &pix=(*fGeomCam)[fNumPixel<0?0:fNumPixel];
    717642
    718643    Double_t fAngle[6] = { -10, -10, -10, -10, -10, -10 };
     
    720645    for (int i=0; i<pix.GetNumNeighbors(); i++)
    721646    {
    722         MGeomPix &next = (*fGeomCam)[pix.GetNeighbor(i)];
     647        MGeom &next = (*fGeomCam)[pix.GetNeighbor(i)];
    723648        fAngle[i] = atan2(next.GetY()-pix.GetY(), next.GetX()-pix.GetX());
    724649    }
  • trunk/MagicSoft/Mars/mtools/MagicDomino.h

    r8755 r9369  
    1111#ifndef ROOT_TClonesArray
    1212#include <TClonesArray.h>
     13#endif
     14#ifndef ROOT_TArrayI
     15#include <TArrayI.h>
    1316#endif
    1417
     
    5962    TText    *fDone;            // game over text
    6063
    61     UInt_t    fW;               // Width of canvas
    62     UInt_t    fH;               // Height of canvas
    63 
    64     TClonesArray *fPixels;      // array of all hexagons
    65     TVirtualPad  *fDrawingPad;  // pad in which we are drawing
    66 
    67     MHexagon &operator[](int i) { return *((MHexagon*)fPixels->At(i)); }
     64    TArrayI fColors;
    6865
    6966    Bool_t  CheckTile();
     
    7774    void    Done();
    7875    void    RemoveNumbers();
    79     void    DrawHexagons();
    8076    void    SetNewCamera(MGeomCam *);
    8177    void    ChangePixel(Int_t add);
  • trunk/MagicSoft/Mars/mtools/MagicJam.cc

    r9312 r9369  
    22!
    33! *
    4 ! * This file is part of MARS, the MAGIC Analysis and Reconstruction
     4! * This file is part of CheObs, the Modular Analysis and Reconstruction
    55! * Software. It is distributed to you in the hope that it can be a useful
    66! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
     
    99! * Permission to use, copy, modify and distribute this software and its
    1010! * documentation for any purpose is hereby granted without fee,
    11 ! * provided that the above copyright notice appear in all copies and
     11! * provided that the above copyright notice appears in all copies and
    1212! * that both that copyright notice and this permission notice appear
    1313! * in supporting documentation. It is provided "as is" without express
     
    141141            Float_t x0 = TMath::Odd(y) ? x-0.25 : x+0.25;
    142142
    143             cam[x + y*fWidth].Set(x0-dx, (y-dy)*0.866, 1);
    144         }
     143            cam.SetAt(x + y*fWidth, MGeomPix(x0-dx, (y-dy)*0.866, 1));
     144        }
     145
     146
     147    cam.InitGeometry();
    145148
    146149    SetGeometry(cam);
     
    442445
    443446        TVirtualPad *p = dynamic_cast<TVirtualPad*>(o);
    444         if (p && p->GetPad(1))
    445         {
    446             p->GetPad(1)->Modified();
    447             p->GetPad(1)->Update();
     447        if (p)
     448        {
     449            p->Modified();
     450            p->Update();
    448451        }
    449452    }
     
    508511    const Int_t newval = fBinEntries[idx+1]+1;
    509512
    510     const MGeomPix &gpix = (*fGeomCam)[idx];
     513    const MGeom &gpix = (*fGeomCam)[idx];
    511514    const Int_t n = gpix.GetNumNeighbors();
    512515
     
    721724        dy += y;
    722725
    723         cam[i].Set(dx, dy*0.866);
     726        cam.SetAt(i, MGeomPix(dx, dy*0.866));
    724727    }
    725728
  • trunk/MagicSoft/Mars/mtools/MagicReversi.cc

    r8756 r9369  
    22!
    33! *
    4 ! * This file is part of MARS, the MAGIC Analysis and Reconstruction
     4! * This file is part of CheObs, the Modular Analysis and Reconstruction
    55! * Software. It is distributed to you in the hope that it can be a useful
    66! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
     
    99! * Permission to use, copy, modify and distribute this software and its
    1010! * documentation for any purpose is hereby granted without fee,
    11 ! * provided that the above copyright notice appear in all copies and
     11! * provided that the above copyright notice appears in all copies and
    1212! * that both that copyright notice and this permission notice appear
    1313! * in supporting documentation. It is provided "as is" without express
     
    1616!
    1717!
    18 !   Author(s): Thomas Bretz 03/2003 <mailto:tbretz@astro.uni-wuerzburg.de>
     18!   Author(s): Thomas Bretz3/2003 <mailto:tbretz@astro.uni-wuerzburg.de>
    1919!
    20 !   Copyright: MAGIC Software Development, 2000-2003
     20!   Copyright: CheObs Software Development, 2000-2009
    2121!
    2222!
     
    6262#include <TInterpreter.h>
    6363
    64 #include "MHexagon.h"
     64#include "MH.h"
    6565
    6666#include "MGeomPix.h"
     
    8888        return;
    8989
    90     fPixels->Delete();
    9190    fText->Delete();
    9291    fFlags->Delete();
     
    9493    delete fText;
    9594    delete fFlags;
    96     delete fPixels;
    9795
    9896    delete fGeomCam;
     
    113111
    114112    Reset();
    115     DrawHexagons();
    116113}
    117114
     
    119116{
    120117    Free();
    121 
    122     //
    123     //  Reset the display geometry
    124     //
    125     fW=0;
    126     fH=0;
    127118
    128119    //
     
    144135    fText   = new TClonesArray("TText",    fNumPixels);
    145136    fFlags  = new TClonesArray("TMarker",  fNumPixels);
    146     fPixels = new TClonesArray("MHexagon", fNumPixels);
     137    fColors.Set(fNumPixels);
    147138
    148139    for (UInt_t i=0; i<fNumPixels; i++)
    149140    {
    150         MHexagon &h = *new ((*fPixels)[i]) MHexagon((*fGeomCam)[i]);
    151 #if ROOT_VERSION_CODE > ROOT_VERSION(3,01,06)
    152         h.SetBit(kNoContextMenu|kCannotPick);
    153 #endif
     141        const MGeom &pix = (*fGeomCam)[i];
    154142
    155143        TText &t = *new ((*fText)[i]) TText;
    156144        t.SetTextFont(122);
    157145        t.SetTextAlign(22);   // centered/centered
    158         t.SetTextSize(0.3*h.GetD()/fRange);
     146        t.SetTextSize(0.3*pix.GetT()/fRange);
    159147#if ROOT_VERSION_CODE > ROOT_VERSION(3,01,06)
    160148        t.SetBit(kNoContextMenu|kCannotPick);
    161149#endif
    162 
    163         const MGeomPix &pix = (*fGeomCam)[i];
    164150
    165151        TMarker &m = *new ((*fFlags)[i]) TMarker(pix.GetX(), pix.GetY(), kOpenStar);
     
    170156}
    171157
     158/*
    172159// ------------------------------------------------------------------------
    173160//
     
    180167        (*this)[i].Draw();
    181168}
     169*/
    182170
    183171void MagicReversi::Init()
     
    201189//
    202190MagicReversi::MagicReversi()
    203     : fGeomCam(NULL), fDone(NULL), fW(0), fH(0), fDrawingPad(NULL), fIsAllocated(kFALSE)
     191    : fGeomCam(NULL), fDone(NULL)
    204192{
    205193    SetNewCamera(new MGeomCamMagic);
     
    209197
    210198MagicReversi::MagicReversi(const MGeomCam &geom)
    211     : fGeomCam(NULL), fDone(NULL), fW(0), fH(0), fDrawingPad(NULL), fIsAllocated(kFALSE)
     199    : fGeomCam(NULL), fDone(NULL)
    212200{
    213201    SetNewCamera(static_cast<MGeomCam*>(geom.Clone()));
     
    229217    if (fDone)
    230218        delete fDone;
    231 
    232     if (fDrawingPad->GetListOfPrimitives()->FindObject(this)==this)
    233     {
    234         fDrawingPad->RecursiveRemove(this);
    235         delete fDrawingPad;
    236     }
    237219}
    238220
     
    245227void MagicReversi::Paint(Option_t *opt)
    246228{
    247     const UInt_t w = (UInt_t)(gPad->GetWw()*gPad->GetAbsWNDC());
    248     const UInt_t h = (UInt_t)(gPad->GetWh()*gPad->GetAbsHNDC());
    249 
    250     //
    251     // Check for a change in width or height, and make sure, that the
    252     // first call also sets the range
    253     //
    254     if (w*fH == h*fW && fW && fH)
    255         return;
    256 
    257     //
    258     // Calculate aspect ratio (5/4=1.25 recommended)
    259     //
    260     const Double_t ratio = (Double_t)w/h;
    261 
    262     Float_t x;
    263     Float_t y;
    264 
    265     if (ratio>1.0)
    266     {
    267         x = fRange*(ratio*2-1);
    268         y = fRange;
    269     }
    270     else
    271     {
    272         x = fRange;
    273         y = fRange/ratio;
    274     }
    275 
    276     fH = h;
    277     fW = w;
    278 
    279     //
    280     // Set new range
    281     //
    282     fDrawingPad->Range(-fRange, -y, x, y);
    283 
    284     //
    285     // Adopt absolute sized of markers to relative range
    286     //
     229    const Float_t r = fGeomCam->GetMaxRadius();
     230
     231    MH::SetPadRange(-r, -r, r, r*1.1);
     232
     233    TAttLine line;
     234    TAttFill fill;
     235
     236    // FIXME:
    287237    for (UInt_t i=0; i<fNumPixels; i++)
    288238    {
    289         Float_t r = (*this)[i].GetD()*gPad->XtoAbsPixel(1)/325;
     239        const MGeom &pix = (*fGeomCam)[i];
     240
     241        fill.SetFillColor(fColors[i]);
     242        pix.PaintPrimitive(line, fill);
     243
     244        //
     245        // Adopt absolute sized of markers to relative range
     246        //
     247        Float_t r = (*fGeomCam)[i].GetT()*gPad->XtoAbsPixel(1)/325;
    290248        GetFlag(i)->SetMarkerSize(20.0*r/fRange);
     249
     250        if (pix.TestBit(kHasFlag))
     251            GetFlag(i)->Paint();
     252
     253        GetText(i)->Paint();
    291254    }
    292255}
     
    301264void MagicReversi::Draw(Option_t *option)
    302265{
    303     // root 3.02:
    304     // gPad->SetFixedAspectRatio()
    305 
    306     if (fDrawingPad)
    307         return;
    308 
    309266    //
    310267    // if no canvas is yet existing to draw into, create a new one
    311268    //
    312269    if (!gPad)
    313     {
    314         /*TCanvas *c =*/ new TCanvas("MagicReversi", "Magic Reversi", 0, 0, 800, 800);
    315         //c->ToggleEventStatus();
    316         fIsAllocated = kTRUE;
    317     }
    318     else
    319         fIsAllocated = kFALSE;
    320 
    321     fDrawingPad = gPad;
    322     fDrawingPad->SetBorderMode(0);
     270        new TCanvas("MagicReversi", "Magic Reversi", 0, 0, 800, 800);
     271
     272    gPad->SetBorderMode(0);
    323273
    324274    //
     
    347297    //
    348298    Reset();
    349     DrawHexagons();
    350299}
    351300
     
    411360    for (UInt_t i=0; i<fNumPixels; i++)
    412361    {
    413         Remove(GetText(i));
    414         Remove(GetFlag(i));
    415 
    416         (*this)[i].SetFillColor(kEmpty);
     362        fColors[i] = kEmpty;
    417363        (*fGeomCam)[i].ResetBit(kUserBits);
    418364
    419365        GetFlag(i)->SetMarkerColor(kBlack);
     366        GetText(i)->SetText(0, 0, "");
    420367    }
    421368
     
    427374    for (int i=1; i<5*fNumUsers; i++)
    428375    {
    429         (*this)[i-1].SetFillColor(i%fNumUsers+kRed);
     376        fColors[i-1] = i%fNumUsers+kRed;
    430377        fUsrPts[i%fNumUsers]++;
    431378    }
     
    433380    Update();
    434381
    435     fDrawingPad->SetFillColor(22);
     382    gPad->SetFillColor(22);
    436383
    437384#if ROOT_VERSION_CODE > ROOT_VERSION(3,01,06)
    438     fDrawingPad->SetBit(kNoContextMenu);
    439385    SetBit(kNoContextMenu);
    440386#endif
     
    468414    fDone->Draw();
    469415
    470     fDrawingPad->SetFillColor(winner+kRed);
     416    gPad->SetFillColor(winner+kRed);
    471417
    472418#if ROOT_VERSION_CODE > ROOT_VERSION(3,01,06)
    473     fDrawingPad->ResetBit(kNoContextMenu);
    474419    ResetBit(kNoContextMenu);
    475420#endif
    476 }
    477 
    478 void MagicReversi::Remove(TObject *obj)
    479 {
    480     fDrawingPad->RecursiveRemove(obj);
    481421}
    482422
     
    495435        {
    496436            idx = fGeomCam->GetNeighbor(idx, dir);
    497             if (idx<0 || (*this)[idx].GetFillColor()==kEmpty)
     437            if (idx<0 || fColors[idx]==kEmpty)
    498438                break;
    499439
    500             if ((*this)[idx].GetFillColor()==col)
     440            if (fColors[idx]==col)
    501441            {
    502442                if (length!=0)
     
    523463                idx = fGeomCam->GetNeighbor(idx, dir);
    524464
    525                 fUsrPts[(*this)[idx].GetFillColor()-kRed]--;
     465                fUsrPts[fColors[idx]-kRed]--;
    526466                fUsrPts[fNumUser]++;
    527467
    528                 (*this)[idx].SetFillColor(col);
     468                fColors[idx] = col;
    529469            }
    530470    }
     
    536476{
    537477    for (unsigned int i=0; i<fNumPixels; i++)
    538         if ((*this)[i].GetFillColor()==kEmpty && Flip(i, kFALSE))
     478        if (fColors[i]==kEmpty && Flip(i, kFALSE))
    539479            return kTRUE;
    540480    return kFALSE;
     
    557497    {
    558498        Done();
    559         fDrawingPad->Modified();
    560         fDrawingPad->Update();
     499        gPad->Modified();
     500        gPad->Update();
    561501        return;
    562502    }
     
    564504    UInt_t idx;
    565505    for (idx=0; idx<fNumPixels; idx++)
    566         if ((*fPixels)[idx]->DistancetoPrimitive(px, py)==0)
     506        if ((*fGeomCam)[idx].DistancetoPrimitive(px, py)<=0)
    567507            break;
    568508
     
    570510        return;
    571511
    572     if (event==kButton1Down && (*this)[idx].GetFillColor()==kEmpty)
     512    if (event==kButton1Down && fColors[idx]==kEmpty)
    573513    {
    574514        if (!Flip(idx, kTRUE))
     
    577517        fUsrPts[fNumUser]++;
    578518
    579         (*this)[idx].SetFillColor(kRed+fNumUser);
     519        fColors[idx] = kRed+fNumUser;
    580520
    581521        Int_t start = fNumUser;
     
    600540    }
    601541
    602     fDrawingPad->Modified();
    603 }
     542    gPad->Modified();
     543}
  • trunk/MagicSoft/Mars/mtools/MagicReversi.h

    r8756 r9369  
    77#ifndef ROOT_TClonesArray
    88#include <TClonesArray.h>
     9#endif
     10#ifndef ROOT_TArrayI
     11#include <TArrayI.h>
    912#endif
    1013
     
    2427    Float_t        fRange;         // the range in millimeters of the present geometry
    2528
    26     TClonesArray  *fPixels;        // array of all hexagons
    2729    TClonesArray  *fText;          // array of all texts
    2830    TClonesArray  *fFlags;         // array of all texts
    2931
     32    TArrayI fColors;
     33
    3034    TText         *fDone;          // TText showing the 'Game over'
    3135    TText         *fUsrTxt[6];     // TText showing the numbers of pixels and bombs
    32 
    33     UInt_t         fW;             // Width of canvas
    34     UInt_t         fH;             // Height of canvas
    35     TVirtualPad   *fDrawingPad;    // pad in which we are drawing
    36     Bool_t         fIsAllocated;
    3736
    3837    Int_t          fNumUsers;
     
    4948    };
    5049
    51     MHexagon &operator[](int i) { return *((MHexagon*)fPixels->At(i)); }
    52 
    5350    TText   *GetText(Int_t i) { return (TText*)fText->At(i); }
    5451    TMarker *GetFlag(Int_t i) { return (TMarker*)fFlags->At(i); }
    5552
    56     void  Remove(TObject *);
    5753    void  Done();
    5854    void  Update();
    5955    void  SetNewCamera(MGeomCam *);
    60     void  DrawHexagons();
    6156    void  Free();
    6257    void  Init();
  • trunk/MagicSoft/Mars/mtools/MagicShow.cc

    r8755 r9369  
    6464#include <TInterpreter.h>
    6565
    66 #include "MHexagon.h"
     66#include "MH.h"
    6767
    6868#include "MGeomPix.h"
     
    8383        return;
    8484
    85     fPixels->Delete();
    86 
    87     delete fPixels;
    88 
    8985    delete fGeomCam;
    90 }
    91 
    92 // ------------------------------------------------------------------------
    93 //
    94 // Draw all pixels of the camera
    95 //  (means apend all pixelobjects to the current pad)
    96 //
    97 void MagicShow::DrawHexagons()
    98 {
    99     for (UInt_t i=0; i<fNumPixels; i++)
    100     {
    101         MHexagon &h = (*this)[i];
    102 
    103         h.SetFillColor(kBackground);
    104         h.Draw();
    105     }
    10686}
    10787
     
    123103    ct1 = !ct1;
    124104
    125     DrawHexagons();
     105    Update();
     106
     107    fColors.Reset();
     108
     109    // FIXME: Reset all texts
     110
     111    AppendPad();
    126112}
    127113
     
    133119{
    134120    Free();
    135 
    136     //
    137     //  Reset the display geometry
    138     //
    139     fW=0;
    140     fH=0;
    141121
    142122    //
     
    151131    fRange     = fGeomCam->GetMaxRadius();
    152132
    153     fNumPixel  = fNumPixels-1;
    154 
    155     //
    156     // Construct all hexagons. Use new-operator with placement
    157     //
    158     fPixels = new TClonesArray("MHexagon", fNumPixels);
    159 
    160     for (UInt_t i=0; i<fNumPixels; i++)
    161     {
    162         MHexagon &h = *new ((*fPixels)[i]) MHexagon((*fGeomCam)[i]);
    163 #if ROOT_VERSION_CODE > ROOT_VERSION(3,01,06)
    164         h.SetBit(kNoContextMenu|kCannotPick);
    165 #endif
    166     }
     133    fNumPixel  = 0;//fNumPixels-1;
     134
     135    fColors.Set(fNumPixels);
     136
     137    for (int i=0; i<6; i++)
     138    {
     139        fText[i] = new TText(0, 0, "");
     140        fText[i]->SetTextFont(122);
     141        fText[i]->SetTextAlign(22);   // centered/centered
     142    }
     143
    167144}
    168145
    169146void MagicShow::Init()
    170147{
    171     memset(fText, 0, sizeof(fText));
    172 
    173148    //
    174149    // Make sure, that the object is destroyed when the canvas/pad is
     
    189164//
    190165MagicShow::MagicShow()
    191     : fTimer(this, 250, kTRUE), fGeomCam(NULL), fNumPixel(-1), fAuto(kTRUE), fW(0), fH(0)
     166    : fTimer(this, 250, kTRUE), fGeomCam(NULL), fNumPixel(-1), fAuto(kTRUE)
    192167{
    193168    SetNewCamera(new MGeomCamMagic);
     
    200175//
    201176MagicShow::MagicShow(const MGeomCam &geom)
    202     : fTimer(this, 250, kTRUE), fGeomCam(NULL), fNumPixel(-1), fAuto(kTRUE), fW(0), fH(0)
     177    : fTimer(this, 250, kTRUE), fGeomCam(NULL), fNumPixel(-1), fAuto(kTRUE)
    203178{
    204179    SetNewCamera(static_cast<MGeomCam*>(geom.Clone()));
     
    215190
    216191    for (int i=0; i<6; i++)
    217         if (fText[i])
    218             delete fText[i];
    219 
    220     if (fDrawingPad->GetListOfPrimitives()->FindObject(this)==this)
    221     {
    222         fDrawingPad->RecursiveRemove(this);
    223         delete fDrawingPad;
    224     }
     192        delete fText[i];
    225193}
    226194
     
    233201void MagicShow::Paint(Option_t *opt)
    234202{
    235     const UInt_t w = (UInt_t)(gPad->GetWw()*gPad->GetAbsWNDC());
    236     const UInt_t h = (UInt_t)(gPad->GetWh()*gPad->GetAbsHNDC());
    237 
    238     //
    239     // Check for a change in width or height, and make sure, that the
    240     // first call also sets the range
    241     //
    242     if (w*fH == h*fW && fW && fH)
    243         return;
    244 
    245     //
    246     // Calculate aspect ratio (5/4=1.25 recommended)
    247     //
    248     const Double_t ratio = (Double_t)w/h;
    249 
    250     Float_t x;
    251     Float_t y;
    252 
    253     if (ratio>1.0)
    254     {
    255         x = fRange*(ratio*2-1);
    256         y = fRange;
    257     }
    258     else
    259     {
    260         x = fRange;
    261         y = fRange/ratio;
    262     }
    263 
    264     fH = h;
    265     fW = w;
    266 
    267     //
    268     // Set new range
    269     //
    270     fDrawingPad->Range(-fRange, -y, x, y);
     203    const Float_t r = fGeomCam->GetMaxRadius();
     204
     205    MH::SetPadRange(-r, -r, r, r*1.1);
     206
     207    TAttLine line;
     208    TAttFill fill;
     209
     210    // FIXME:
     211    for (UInt_t i=0; i<fNumPixels; i++)
     212    {
     213        const MGeom &pix = (*fGeomCam)[i];
     214
     215        fill.SetFillColor(fColors[i]);
     216        pix.PaintPrimitive(line, fill);
     217    }
     218
     219    for (int i=0; i<6; i++)
     220        fText[i]->Paint();
    271221}
    272222
     
    283233    // if no canvas is yet existing to draw into, create a new one
    284234    //
    285     /*TCanvas *c =*/ new TCanvas("MagicShow", "Magic Show Next Neighbours", 0, 0, 800, 800);
    286     //c->ToggleEventStatus();
    287 
    288     fDrawingPad = gPad;
    289     fDrawingPad->SetBorderMode(0);
    290     fDrawingPad->SetFillColor(22);
     235    new TCanvas("MagicShow", "Magic Show Next Neighbours", 0, 0, 800, 800);
     236
     237    gPad->SetBorderMode(0);
     238    gPad->SetFillColor(22);
    291239
    292240    //
     
    295243    //
    296244    AppendPad(option);
    297 
    298     //
    299     // Reset the game pad
    300     //
    301     DrawHexagons();
    302245
    303246    fShow.SetTextAlign(23);   // centered/bottom
     
    339282        fAuto = !fAuto;
    340283        Update();
    341         fDrawingPad->Update();
     284        gPad->Update();
    342285        return;
    343286
     
    382325void MagicShow::ChangePixel(Int_t add)
    383326{
    384     MagicShow &This = *this;
    385 
    386     const MGeomPix &pix1=(*fGeomCam)[fNumPixel];
    387     This[fNumPixel].SetFillColor(kBackground);
     327    const MGeom &pix1=(*fGeomCam)[fNumPixel];
     328
     329    fColors[fNumPixel] = kBackground;
    388330    for (int i=0; i<pix1.GetNumNeighbors(); i++)
    389331    {
    390         This[pix1.GetNeighbor(i)].SetFillColor(kBackground);
    391         if (!fText[i])
     332        fColors[pix1.GetNeighbor(i)] = kBackground;
     333        if (TString(fText[i]->GetTitle()).IsNull())
    392334            continue;
    393335
    394         delete fText[i];
    395         fText[i] = NULL;
     336        fText[i]->SetText(0, 0, "");
    396337    }
    397338
     
    403344        fNumPixel = fNumPixels-1;
    404345
    405     const MGeomPix &pix2=(*fGeomCam)[fNumPixel];
    406     This[fNumPixel].SetFillColor(kBlue);
     346    const MGeom &pix2=(*fGeomCam)[fNumPixel];
     347
     348    fColors[fNumPixel] = kBlue;
     349
    407350    for (int i=0; i<pix2.GetNumNeighbors(); i++)
    408351    {
    409352        Int_t idx = pix2.GetNeighbor(i);
    410353
    411         This[idx].SetFillColor(kMagenta);
     354        fColors[idx] = kMagenta;
    412355
    413356        TString num;
    414357        num += idx;
    415358
    416         fText[i] = new TText(This[idx].GetX(), This[idx].GetY(), num);
    417         fText[i]->SetTextSize(0.3*This[idx].GetD()/fGeomCam->GetMaxRadius());
    418         fText[i]->SetTextFont(122);
    419         fText[i]->SetTextAlign(22);   // centered/centered
    420         fText[i]->Draw();
     359        const MGeom &pix=(*fGeomCam)[idx];
     360
     361        fText[i]->SetText(pix.GetX(), pix.GetY(), num);
     362        fText[i]->SetTextSize(0.3*pix.GetT()/fGeomCam->GetMaxRadius());
    421363    }
    422364
    423365    Update();
    424366
    425     fDrawingPad->Update();
     367    gPad->Update();
    426368}
    427369
  • trunk/MagicSoft/Mars/mtools/MagicShow.h

    r8755 r9369  
    1414#ifndef ROOT_TClonesArray
    1515#include <TClonesArray.h>
     16#endif
     17#ifndef ROOT_TArrayI
     18#include <TArrayI.h>
    1619#endif
    1720
     
    4548    TText    *fText[6];         // ttext showing the pixel numbers of the neighbors
    4649
    47     UInt_t    fW;               // Width of canvas
    48     UInt_t    fH;               // Height of canvas
    49 
    50     TClonesArray *fPixels;      // array of all hexagons
    51     TVirtualPad  *fDrawingPad;  // pad in which we are drawing
    52 
    53     MHexagon &operator[](int i) { return *((MHexagon*)fPixels->At(i)); }
     50    TArrayI fColors;
    5451
    5552    void   Update();
    5653    void   Free();
    57     void   DrawHexagons();
    5854    void   SetNewCamera(MGeomCam *);
    5955    void   ChangePixel(Int_t add);
  • trunk/MagicSoft/Mars/mtools/MagicSnake.cc

    r8755 r9369  
    22!
    33! *
    4 ! * This file is part of MARS, the MAGIC Analysis and Reconstruction
     4! * This file is part of CheObs, the Modular Analysis and Reconstruction
    55! * Software. It is distributed to you in the hope that it can be a useful
    66! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
     
    99! * Permission to use, copy, modify and distribute this software and its
    1010! * documentation for any purpose is hereby granted without fee,
    11 ! * provided that the above copyright notice appear in all copies and
     11! * provided that the above copyright notice appears in all copies and
    1212! * that both that copyright notice and this permission notice appear
    1313! * in supporting documentation. It is provided "as is" without express
     
    1616!
    1717!
    18 !   Author(s): Thomas Bretz 07/2002 <mailto:tbretz@astro.uni-wuerzburg.de>
     18!   Author(s): Thomas Bretz7/2002 <mailto:tbretz@astro.uni-wuerzburg.de>
    1919!
    20 !   Copyright: MAGIC Software Development, 2000-2002
     20!   Copyright: CheObs Software Development, 2000-2009
    2121!
    2222!
     
    6363#include <TInterpreter.h>
    6464
    65 #include "MHexagon.h"
     65#include "MH.h"
    6666
    6767#include "MGeomPix.h"
     
    7878        return;
    7979
    80     fPixels->Delete();
    81 
    82     delete fPixels;
    83 
    8480    delete fGeomCam;
    8581
    8682    delete fArray;
    87 }
    88 
    89 // ------------------------------------------------------------------------
    90 //
    91 // Draw all pixels of the camera
    92 //  (means apend all pixelobjects to the current pad)
    93 //
    94 void MagicSnake::DrawHexagons()
    95 {
    96     for (UInt_t i=0; i<fNumPixels; i++)
    97         (*this)[i].Draw();
    9883}
    9984
     
    115100
    116101    Reset();
    117     DrawHexagons();
     102    AppendPad();
    118103}
    119104
     
    121106{
    122107    Free();
    123 
    124     //
    125     //  Reset the display geometry
    126     //
    127     fW=0;
    128     fH=0;
    129108
    130109    //
     
    139118    fRange     = fGeomCam->GetMaxRadius();
    140119
    141     //
    142     // Construct all hexagons. Use new-operator with placement
    143     //
    144     fPixels = new TClonesArray("MHexagon", fNumPixels);
    145 
    146     for (UInt_t i=0; i<fNumPixels; i++)
    147     {
    148         MHexagon &h = *new ((*fPixels)[i]) MHexagon((*fGeomCam)[i]);
    149 #if ROOT_VERSION_CODE > ROOT_VERSION(3,01,06)
    150         h.SetBit(kNoContextMenu|kCannotPick);
    151 #endif
    152     }
     120    fColors.Set(fNumPixels);
    153121}
    154122
     
    175143//
    176144MagicSnake::MagicSnake()
    177     : fTimer(this, 500, kTRUE), fGeomCam(NULL), fDone(NULL), fPaused(NULL), fW(0), fH(0)
     145    : fTimer(this, 500, kTRUE), fGeomCam(NULL), fDone(NULL), fPaused(NULL)
    178146{
    179147    SetNewCamera(new MGeomCamMagic);
     
    186154//
    187155MagicSnake::MagicSnake(const MGeomCam &geom)
    188     : fTimer(this, 500, kTRUE), fGeomCam(NULL), fDone(NULL), fPaused(NULL), fW(0), fH(0)
     156    : fTimer(this, 500, kTRUE), fGeomCam(NULL), fDone(NULL), fPaused(NULL)
    189157{
    190158    SetNewCamera(static_cast<MGeomCam*>(geom.Clone()));
     
    203171#if ROOT_VERSION_CODE > ROOT_VERSION(3,01,06)
    204172        fPaused->SetBit(kNoContextMenu|kCannotPick);
    205         fDrawingPad->ResetBit(kNoContextMenu);
    206173        ResetBit(kNoContextMenu);
    207174#endif
    208         fDrawingPad->Update();
     175        //fDrawingPad->Update();
    209176    }
    210177
     
    215182    {
    216183#if ROOT_VERSION_CODE > ROOT_VERSION(3,01,06)
    217         fDrawingPad->SetBit(kNoContextMenu);
     184        //fDrawingPad->SetBit(kNoContextMenu);
    218185        SetBit(kNoContextMenu);
    219186#endif
     
    222189        return;
    223190
    224     Remove(fPaused);
    225 
    226     fDrawingPad->Update();
     191    //fDrawingPad->Update();
    227192
    228193    delete fPaused;
     
    241206    if (fDone)
    242207        delete fDone;
    243 
     208/*
    244209    if (fDrawingPad->GetListOfPrimitives()->FindObject(this)==this)
    245210    {
    246211        fDrawingPad->RecursiveRemove(this);
    247212        delete fDrawingPad;
    248     }
     213    }*/
    249214}
    250215
     
    257222void MagicSnake::Paint(Option_t *opt)
    258223{
    259     const UInt_t w = (UInt_t)(gPad->GetWw()*gPad->GetAbsWNDC());
    260     const UInt_t h = (UInt_t)(gPad->GetWh()*gPad->GetAbsHNDC());
    261 
    262     //
    263     // Check for a change in width or height, and make sure, that the
    264     // first call also sets the range
    265     //
    266     if (w*fH == h*fW && fW && fH)
    267         return;
    268 
    269     //
    270     // Calculate aspect ratio (5/4=1.25 recommended)
    271     //
    272     const Double_t ratio = (Double_t)w/h;
    273 
    274     Float_t x;
    275     Float_t y;
    276 
    277     if (ratio>1.0)
    278     {
    279         x = fRange*(ratio*2-1);
    280         y = fRange;
    281     }
    282     else
    283     {
    284         x = fRange;
    285         y = fRange/ratio;
    286     }
    287 
    288     fH = h;
    289     fW = w;
    290 
    291     //
    292     // Set new range
    293     //
    294     fDrawingPad->Range(-fRange, -y, x, y);
     224    const Float_t r = fGeomCam->GetMaxRadius();
     225
     226    MH::SetPadRange(-r, -r, r, r*1.1);
     227
     228    TAttLine line;
     229    TAttFill fill;
     230
     231    for (UInt_t i=0; i<fNumPixels; i++)
     232    {
     233        const MGeom &pix = (*fGeomCam)[i];
     234
     235        fill.SetFillColor(fColors[i]);
     236        pix.PaintPrimitive(line, fill);
     237    }
    295238}
    296239
     
    307250    // if no canvas is yet existing to draw into, create a new one
    308251    //
    309     /*TCanvas *c =*/ new TCanvas("MagicSnake", "Magic Snake", 0, 0, 800, 800);
    310     //c->ToggleEventStatus();
    311 
    312     fDrawingPad = gPad;
    313     fDrawingPad->SetBorderMode(0);
     252    new TCanvas("MagicSnake", "Magic Snake", 0, 0, 800, 800);
     253
     254    //fDrawingPad = gPad;
     255    gPad->SetBorderMode(0);
    314256
    315257    //
     
    323265    //
    324266    Reset();
    325     DrawHexagons();
    326267
    327268    fShow.SetTextAlign(23);   // centered/bottom
     
    355296    for (UInt_t i=0; i<fNumPixels; i++)
    356297    {
    357         (*this)[i].SetFillColor(kBackground);
     298        fColors[i] = kBackground;
    358299        (*fGeomCam)[i].ResetBit(kUserBits);
    359300    }
     
    372313
    373314        (*fGeomCam)[idx].SetBit(kHasBomb);
    374         (*this)[idx].SetFillColor(kRed);
     315        fColors[idx] = kRed;
    375316    }
    376317
    377318    fNumFood = fNumPixels/6;
     319    // FIXME. gROOT->GetColor doesn't allow more than 100 colors!
     320    if (fNumFood>46)
     321        fNumFood=46;
    378322
    379323    fArray = new Int_t[fNumFood+3];
     
    395339
    396340        (*fGeomCam)[idx].SetBit(kHasFood);
    397         (*this)[idx].SetFillColor(kGreen);
     341        fColors[idx] = kGreen;
    398342    }
    399343
     
    409353        fTransport[i] = idx;
    410354        (*fGeomCam)[idx].SetBit(kHasTransport);
    411         (*this)[idx].SetFillColor(kYellow);
    412     }
    413 
    414     fDrawingPad->SetFillColor(22);
     355        fColors[idx] = kYellow;
     356    }
     357
     358    gPad->SetFillColor(22);
    415359
    416360#if ROOT_VERSION_CODE > ROOT_VERSION(3,01,06)
    417     fDrawingPad->SetBit(kNoContextMenu);
     361    //fDrawingPad->SetBit(kNoContextMenu);
    418362    SetBit(kNoContextMenu);
    419363#endif
     
    435379    fDone->SetTextSize(0.05); // white
    436380    fDone->Draw();
    437     fDrawingPad->SetFillColor(col);
     381    gPad->SetFillColor(col);
    438382#if ROOT_VERSION_CODE > ROOT_VERSION(3,01,06)
    439383    fDone->SetBit(kNoContextMenu|kCannotPick);
    440     fDrawingPad->ResetBit(kNoContextMenu);
    441384    ResetBit(kNoContextMenu);
    442385#endif
    443 }
    444 
    445 void MagicSnake::Remove(TObject *obj)
    446 {
    447     fDrawingPad->RecursiveRemove(obj);
    448386}
    449387
     
    500438    if ((*fGeomCam)[newpix].TestBit(kHasTransport))
    501439    {
    502         (*this)[fArray[0]].SetFillColor(kBackground);
     440        fColors[fArray[0]] = kBackground;
    503441        (*fGeomCam)[fArray[0]].ResetBit(kHasWorm);
    504442
     
    513451    if (!(*fGeomCam)[newpix].TestBit(kHasFood))
    514452    {
    515         MGeomPix &pix = (*fGeomCam)[fArray[0]];
     453        MGeom &pix = (*fGeomCam)[fArray[0]];
    516454
    517455        if (!pix.TestBit(kHasTransport))
     456        {
    518457            if (pix.TestBit(kHasDoor))
    519                 (*this)[fArray[0]].SetFillColor(kMagenta);
     458                fColors[fArray[0]] = kMagenta;
    520459            else
    521                 (*this)[fArray[0]].SetFillColor(kBackground);
     460                fColors[fArray[0]] = kBackground;
     461        }
    522462
    523463        pix.ResetBit(kHasWorm);
     
    538478            for (int i=1; i<7; i++)
    539479            {
    540                 (*this)[i].SetFillColor(kMagenta);
     480                fColors[i] = kMagenta;
    541481                (*fGeomCam)[i].SetBit(kHasDoor);
    542482            }
     
    552492        const Int_t idx = fArray[i];
    553493
    554         MGeomPix &pix = (*fGeomCam)[idx];
     494        MGeom &pix = (*fGeomCam)[idx];
    555495
    556496        if (pix.TestBit(kHasTransport))
     
    559499        pix.SetBit(kHasWorm);
    560500
    561         Int_t color = 51+fLength-i;
    562         (*this)[idx].SetFillColor(color);
     501        fColors[idx] = 51+fLength-i;
    563502    }
    564503}
     
    568507    const Int_t first = fArray[fLength-1];
    569508
    570     const MGeomPix &pix=(*fGeomCam)[first];
     509    const MGeom &pix=(*fGeomCam)[first];
    571510
    572511    Double_t dx = pix.GetX();
     
    577516    {
    578517        const Int_t     idx  = pix.GetNeighbor(i);
    579         const MGeomPix &next = (*fGeomCam)[idx];
     518        const MGeom &next = (*fGeomCam)[idx];
    580519
    581520        const Double_t x = next.GetX();
     
    596535        return -1;
    597536
    598     const MGeomPix &np = (*fGeomCam)[newpix];
     537    const MGeom &np = (*fGeomCam)[newpix];
    599538
    600539    if (fNumFood==0 && np.TestBit(kHasDoor))
     
    611550
    612551Bool_t MagicSnake::HandleTimer(TTimer *timer)
    613 {
     552{     
    614553    if (fDone || fPaused)
    615554        return kTRUE;
     
    637576    Update();
    638577
    639     //cout << "Update " << flush;
    640 
    641     fDrawingPad->Modified();
    642     fDrawingPad->Update();
    643 
    644     //cout << "Done." << endl;
     578    gPad->Modified();
     579    gPad->Update();
    645580
    646581    return kTRUE;
  • trunk/MagicSoft/Mars/mtools/MagicSnake.h

    r8755 r9369  
    1414#ifndef ROOT_TClonesArray
    1515#include <TClonesArray.h>
     16#endif
     17#ifndef ROOT_TArrayI
     18#include <TArrayI.h>
    1619#endif
    1720
     
    6063    Float_t   fRange;           // the range in millimeters of the present geometry
    6164
     65    TArrayI fColors;
     66
    6267    TText    *fDone;            // TText showing the 'Game over'
    6368    TText    *fPaused;          // TText showing the 'Game over'
    6469    TText     fShow;            // TText showing the numbers of pixels and bombs
    6570
    66     UInt_t    fW;               // Width of canvas
    67     UInt_t    fH;               // Height of canvas
    68 
    69     TClonesArray  *fPixels;     // array of all hexagons
    7071    TVirtualPad   *fDrawingPad; // pad in which we are drawing
    7172
    72     MHexagon &operator[](int i) { return *((MHexagon*)fPixels->At(i)); }
    73 
    74     void   Remove(TObject *);
    7573    void   Done(TString, Int_t col);
    7674    void   Step(Int_t newpix);
  • trunk/MagicSoft/Mars/mtools/MineSweeper.cc

    r8755 r9369  
    22!
    33! *
    4 ! * This file is part of MARS, the MAGIC Analysis and Reconstruction
     4! * This file is part of CheObs, the Modular Analysis and Reconstruction
    55! * Software. It is distributed to you in the hope that it can be a useful
    66! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
     
    99! * Permission to use, copy, modify and distribute this software and its
    1010! * documentation for any purpose is hereby granted without fee,
    11 ! * provided that the above copyright notice appear in all copies and
     11! * provided that the above copyright notice appears in all copies and
    1212! * that both that copyright notice and this permission notice appear
    1313! * in supporting documentation. It is provided "as is" without express
     
    1616!
    1717!
    18 !   Author(s): Thomas Bretz 07/2002 <mailto:tbretz@astro.uni-wuerzburg.de>
    19 !
    20 !   Copyright: MAGIC Software Development, 2000-2002
     18!   Author(s): Thomas Bretz7/2002 <mailto:tbretz@astro.uni-wuerzburg.de>
     19!
     20!   Copyright: CheObs Software Development, 2000-2009
    2121!
    2222!
     
    5757#include <TInterpreter.h>
    5858
    59 #include "MHexagon.h"
     59#include "MH.h"
    6060
    6161#include "MGeomPix.h"
     
    8282        return;
    8383
    84     fPixels->Delete();
    8584    fText->Delete();
    8685    fFlags->Delete();
     
    8887    delete fText;
    8988    delete fFlags;
    90     delete fPixels;
    9189
    9290    delete fGeomCam;
     
    107105
    108106    Reset();
    109     DrawHexagons();
     107    AppendPad();
    110108}
    111109
     
    113111{
    114112    Free();
    115 
    116     //
    117     //  Reset the display geometry
    118     //
    119     fW=0;
    120     fH=0;
    121113
    122114    //
     
    138130    fText   = new TClonesArray("TText",    fNumPixels);
    139131    fFlags  = new TClonesArray("TMarker",  fNumPixels);
    140     fPixels = new TClonesArray("MHexagon", fNumPixels);
     132    fColors.Set(fNumPixels);
     133    //fPixels = new TClonesArray("MHexagon", fNumPixels);
    141134
    142135    for (UInt_t i=0; i<fNumPixels; i++)
    143136    {
    144         MHexagon &h = *new ((*fPixels)[i]) MHexagon((*fGeomCam)[i]);
    145 #if ROOT_VERSION_CODE > ROOT_VERSION(3,01,06)
    146         h.SetBit(kNoContextMenu|kCannotPick);
    147 #endif
     137        const MGeom &pix = (*fGeomCam)[i];
    148138
    149139        TText &t = *new ((*fText)[i]) TText;
    150140        t.SetTextFont(122);
    151141        t.SetTextAlign(22);   // centered/centered
    152         t.SetTextSize(0.3*h.GetD()/fRange);
     142        t.SetTextSize(0.3*pix.GetT()/fRange);
    153143#if ROOT_VERSION_CODE > ROOT_VERSION(3,01,06)
    154144        t.SetBit(kNoContextMenu|kCannotPick);
    155145#endif
    156146
    157         const MGeomPix &pix = (*fGeomCam)[i];
    158 
    159147        TMarker &m = *new ((*fFlags)[i]) TMarker(pix.GetX(), pix.GetY(), kOpenStar);
    160148#if ROOT_VERSION_CODE > ROOT_VERSION(3,01,06)
     
    162150#endif
    163151    }
    164 }
    165 
    166 // ------------------------------------------------------------------------
    167 //
    168 // Draw all pixels of the camera
    169 //  (means apend all pixelobjects to the current pad)
    170 //
    171 void MineSweeper::DrawHexagons()
    172 {
    173     for (UInt_t i=0; i<fNumPixels; i++)
    174         (*this)[i].Draw();
    175152}
    176153
     
    193170//
    194171MineSweeper::MineSweeper()
    195     : fGeomCam(NULL), fDone(NULL), fShow(NULL), fW(0), fH(0), fDrawingPad(NULL), fIsAllocated(kFALSE)
     172    : fGeomCam(NULL), fDone(NULL), fShow(NULL)
    196173{
    197174    SetNewCamera(new MGeomCamMagic);
     
    200177
    201178MineSweeper::MineSweeper(const MGeomCam &geom)
    202     : fGeomCam(NULL), fDone(NULL), fShow(NULL), fW(0), fH(0), fDrawingPad(NULL), fIsAllocated(kFALSE)
     179    : fGeomCam(NULL), fDone(NULL), fShow(NULL)
    203180{
    204181    SetNewCamera(static_cast<MGeomCam*>(geom.Clone()));
     
    218195    if (fDone)
    219196        delete fDone;
    220 
    221     if (fDrawingPad->GetListOfPrimitives()->FindObject(this)==this)
    222     {
    223         fDrawingPad->RecursiveRemove(this);
    224         delete fDrawingPad;
    225     }
    226197}
    227198
     
    234205void MineSweeper::Paint(Option_t *opt)
    235206{
    236     const UInt_t w = (UInt_t)(gPad->GetWw()*gPad->GetAbsWNDC());
    237     const UInt_t h = (UInt_t)(gPad->GetWh()*gPad->GetAbsHNDC());
    238 
    239     //
    240     // Check for a change in width or height, and make sure, that the
    241     // first call also sets the range
    242     //
    243     if (w*fH == h*fW && fW && fH)
    244         return;
    245 
    246     //
    247     // Calculate aspect ratio (5/4=1.25 recommended)
    248     //
    249     const Double_t ratio = (Double_t)w/h;
    250 
    251     Float_t x;
    252     Float_t y;
    253 
    254     if (ratio>1.0)
    255     {
    256         x = fRange*(ratio*2-1);
    257         y = fRange;
    258     }
    259     else
    260     {
    261         x = fRange;
    262         y = fRange/ratio;
    263     }
    264 
    265     fH = h;
    266     fW = w;
    267 
    268     //
    269     // Set new range
    270     //
    271     fDrawingPad->Range(-fRange, -y, x, y);
    272 
    273     //
    274     // Adopt absolute sized of markers to relative range
    275     //
     207    const Float_t r = fGeomCam->GetMaxRadius();
     208
     209    MH::SetPadRange(-r, -r, r, r*1.1);
     210
     211    TAttLine line;
     212    TAttFill fill;
     213
     214    // FIXME:
    276215    for (UInt_t i=0; i<fNumPixels; i++)
    277216    {
    278         Float_t r = (*this)[i].GetD()*gPad->XtoAbsPixel(1)/325;
     217        const MGeom &pix = (*fGeomCam)[i];
     218
     219        fill.SetFillColor(fColors[i]);
     220        pix.PaintPrimitive(line, fill);
     221
     222        //
     223        // Adopt absolute sized of markers to relative range
     224        //
     225        Float_t r = (*fGeomCam)[i].GetT()*gPad->XtoAbsPixel(1)/325;
    279226        GetFlag(i)->SetMarkerSize(20.0*r/fRange);
     227
     228        if (pix.TestBit(kHasFlag))
     229            GetFlag(i)->Paint();
     230
     231        GetText(i)->Paint();
    280232    }
    281233}
     
    293245    // gPad->SetFixedAspectRatio()
    294246
    295     if (fDrawingPad)
    296         return;
    297 
    298247    //
    299248    // if no canvas is yet existing to draw into, create a new one
    300249    //
    301250    if (!gPad)
    302     {
    303         /*TCanvas *c =*/ new TCanvas("MineSweeper", "Magic Mine Sweeper", 0, 0, 800, 800);
    304         //c->ToggleEventStatus();
    305         fIsAllocated = kTRUE;
    306     }
    307     else
    308         fIsAllocated = kFALSE;
    309 
    310     fDrawingPad = gPad;
    311     fDrawingPad->SetBorderMode(0);
     251        new TCanvas("MineSweeper", "Magic Mine Sweeper", 0, 0, 800, 800);
     252
     253    gPad->SetBorderMode(0);
    312254
    313255    //
     
    330272    //
    331273    Reset();
    332     DrawHexagons();
    333274}
    334275
     
    357298    for (UInt_t i=0; i<fNumPixels; i++)
    358299    {
    359         Remove(GetText(i));
    360         Remove(GetFlag(i));
    361 
    362         (*this)[i].SetFillColor(kHidden);
     300        fColors[i] = kHidden;
    363301        (*fGeomCam)[i].ResetBit(kUserBits);
    364302
    365303        GetFlag(i)->SetMarkerColor(kBlack);
     304        GetText(i)->SetText(0, 0, "");
    366305    }
    367306    Update(fNumBombs);
     
    378317    }
    379318
    380     fDrawingPad->SetFillColor(22);
    381 
    382 #if ROOT_VERSION_CODE > ROOT_VERSION(3,01,06)
    383     fDrawingPad->SetBit(kNoContextMenu);
     319    gPad->SetFillColor(22);
     320
     321#if ROOT_VERSION_CODE > ROOT_VERSION(3,01,06)
     322    gPad->SetBit(kNoContextMenu);
    384323    SetBit(kNoContextMenu);
    385324#endif
     
    391330        if ((*fGeomCam)[j].TestBit(kHasBomb))
    392331        {
    393             (*this)[j].SetFillColor(kBlack);
     332            fColors[j] = kBlack;
    394333            GetFlag(j)->SetMarkerColor(kWhite);
    395334        }
     
    404343    fDone->Draw();
    405344
    406     fDrawingPad->SetFillColor(col);
    407 
    408 #if ROOT_VERSION_CODE > ROOT_VERSION(3,01,06)
    409     fDrawingPad->ResetBit(kNoContextMenu);
     345    gPad->SetFillColor(col);
     346
     347#if ROOT_VERSION_CODE > ROOT_VERSION(3,01,06)
     348    gPad->ResetBit(kNoContextMenu);
    410349    ResetBit(kNoContextMenu);
    411350#endif
     
    419358void MineSweeper::OpenHexagon(Int_t idx)
    420359{
    421     MGeomPix &pix=(*fGeomCam)[idx];
     360    MGeom &pix=(*fGeomCam)[idx];
    422361
    423362    if (pix.TestBit(kIsVisible))
    424363        return;
    425 
    426     if (pix.TestBit(kHasFlag))
    427         Remove(GetFlag(idx));
    428364
    429365    pix.SetBit(kIsVisible);
     
    435371            cnt++;
    436372
    437     (*this)[idx].SetFillColor(fColorBombs[cnt]);
    438 
     373    fColors[idx] = fColorBombs[cnt];
     374
     375    TString str;
    439376    if (cnt)
    440     {
    441         TText *txt = GetText(idx);
    442         TString str;
    443377        str += cnt;
    444         txt->SetText(pix.GetX(), pix.GetY(), str);
    445         txt->Draw();
    446         return;
    447     }
     378
     379    TText *txt = GetText(idx);
     380    txt->SetText(pix.GetX(), pix.GetY(), str);
     381
     382    if (cnt)
     383        return;
    448384
    449385    for (int j=0; j<pix.GetNumNeighbors(); j++)
    450386        OpenHexagon(pix.GetNeighbor(j));
    451 }
    452 
    453 void MineSweeper::Remove(TObject *obj)
    454 {
    455     fDrawingPad->RecursiveRemove(obj);
    456387}
    457388
     
    479410    UInt_t idx;
    480411    for (idx=0; idx<fNumPixels; idx++)
    481         if ((*fPixels)[idx]->DistancetoPrimitive(px, py)==0)
     412        if ((*fGeomCam)[idx].DistancetoPrimitive(px, py)<=0)
    482413            break;
    483414
     
    485416        return;
    486417
    487     MGeomPix &pix=(*fGeomCam)[idx];
     418    MGeom &pix=(*fGeomCam)[idx];
    488419
    489420    if (event==kButton1Double)
     
    496427
    497428    if (event==kButton1Down && !pix.TestBit(kIsVisible))
    498     {
    499         if (pix.TestBit(kHasFlag))
    500             Remove(GetFlag(idx));
    501         else
    502             GetFlag(idx)->Draw();
    503 
    504429        pix.InvertBit(kHasFlag);
    505     }
    506430
    507431    UInt_t vis=fNumBombs;
     
    520444        Done("Great! Congratulations, you did it!", kGreen);
    521445
    522     fDrawingPad->Modified();
     446    gPad->Modified();
    523447
    524448    /*
  • trunk/MagicSoft/Mars/mtools/MineSweeper.h

    r8755 r9369  
    88#include <TClonesArray.h>
    99#endif
     10#ifndef ROOT_TArrayI
     11#include <TArrayI.h>
     12#endif
    1013
    1114class TText;
     
    1316class TVirtualPad;
    1417
     18class MGeom;
    1519class MGeomCam;
    1620class MHexagon;
     
    2731    Float_t        fRange;         // the range in millimeters of the present geometry
    2832
    29     TClonesArray  *fPixels;        // array of all hexagons
    3033    TClonesArray  *fText;          // array of all texts
    3134    TClonesArray  *fFlags;         // array of all texts
    3235
     36    TArrayI fColors;
     37
    3338    TText         *fDone;          // TText showing the 'Game over'
    3439    TText         *fShow;          // TText showing the numbers of pixels and bombs
    35 
    36     UInt_t         fW;             // Width of canvas
    37     UInt_t         fH;             // Height of canvas
    38     TVirtualPad   *fDrawingPad;    // pad in which we are drawing
    39     Bool_t         fIsAllocated;
    4040
    4141    enum
     
    4848    };
    4949
    50     MHexagon &operator[](int i) { return *((MHexagon*)fPixels->At(i)); }
    51 
    5250    TText   *GetText(Int_t i) { return (TText*)fText->At(i); }
    5351    TMarker *GetFlag(Int_t i) { return (TMarker*)fFlags->At(i); }
    5452
    55     void  Remove(TObject *);
    5653    void  OpenHexagon(Int_t idx);
    5754    void  Done(TString, Int_t);
    5855    void  Update(Int_t);
    5956    void  SetNewCamera(MGeomCam *);
    60     void  DrawHexagons();
     57    void  PaintPrimitives();
    6158    void  Free();
    6259    void  Init();
Note: See TracChangeset for help on using the changeset viewer.