Index: trunk/MagicSoft/Cosy/gui/MGCosy.cc
===================================================================
--- trunk/MagicSoft/Cosy/gui/MGCosy.cc	(revision 1531)
+++ trunk/MagicSoft/Cosy/gui/MGCosy.cc	(revision 1690)
@@ -30,8 +30,11 @@
 #include "SlaStars.h"
 
+#undef DEBUG
+
 ClassImp(MGCosy);
 
-#define IDM_EXIT 1
-#define IDM_TEXT 2
+#define IDM_EXIT   1
+#define IDM_TEXT   2
+#define IDM_ASPECT 3
 
 enum
@@ -60,4 +63,5 @@
     //
     TGPopupMenu *fFileMenu = new TGPopupMenu(gClient->GetRoot());
+    fFileMenu->AddEntry("Set Aspect", IDM_ASPECT);
     fFileMenu->AddEntry("Exit", IDM_EXIT);
     fFileMenu->Associate(this);
@@ -477,22 +481,35 @@
     fList = new MGList;
 
+#ifdef DEBUG
     cout << "MGCosy: Creating Menu" << endl;
+#endif
     CreateMenu();
 
+#ifdef DEBUG
     cout << "MGCosy: Creating TGCompositeFrame" << endl;
-    TGCompositeFrame *f = new TGCompositeFrame(this, 0, 0);
-    f->SetLayoutManager(new TGMatrixLayout(f, 3, 2, 10));
-    fList->Add(f);
-
+#endif
+    TGHorizontalFrame *f1 = new TGHorizontalFrame(this, 0, 0);
+    TGHorizontalFrame *f2 = new TGHorizontalFrame(this, 0, 0);
+    fList->Add(f1);
+    fList->Add(f2);
+
+#ifdef DEBUG
     cout << "MGCosy: Creating TGTab" << endl;
-    fTab = new TGTab(f, 300, 300);
+#endif
+    fTab = new TGTab(f1, 300, 300);
     fList->Add(fTab);
 
+#ifdef DEBUG
     cout << "MGCosy: Creating MGSkyPosition" << endl;
-    fSkyPosition = new MGSkyPosition(f, 300);
+#endif
+    fSkyPosition = new MGSkyPosition(f1, 300);
+#ifdef DEBUG
     cout << "MGCosy: Creating MGAccuracy" << endl;
-    fAccuracy    = new MGAccuracy   (f, 300);
+#endif
+    fAccuracy    = new MGAccuracy   (f1, 300);
+#ifdef DEBUG
     cout << "MGCosy: Creating MGVelocity" << endl;
-    fVelocity    = new MGVelocity   (f, "Velocity [\"/min]", 300);
+#endif
+    fVelocity    = new MGVelocity   (f2, "Velocity [\"/min]", 300);
 //    fOffset      = new MGVelocity   (f, "Offset se-re [']", 300);
 
@@ -502,33 +519,61 @@
 //    fList->Add(fOffset);
 
+#ifdef DEBUG
     cout << "MGCosy: Creating TGGroupFrame" << endl;
-    TGGroupFrame *frame = new TGGroupFrame(f, "Status");
+#endif
+    TGGroupFrame *frame = new TGGroupFrame(f2, "Status");
     frame->Resize(300, 300);
     fList->Add(frame);
 
+#ifdef DEBUG
     cout << "MGCosy: Creating TGListBox" << endl;
-    fLog = new TGListBox(f, -1, kSunkenFrame);  //kSunkenFrame|kDoubleBorder,
+#endif
+    fLog = new TGListBox(f2, -1, kSunkenFrame);  //kSunkenFrame|kDoubleBorder,
     fLog->Resize(300, 300);
     fLog->ChangeBackground(TGFrame::GetBlackPixel());
     fList->Add(fLog);
 
-    //
-    // Layout the window, tile by tile...
-    //
-    f->AddFrame(fTab);
-    f->AddFrame(fSkyPosition);
-    f->AddFrame(fAccuracy);
-    f->AddFrame(frame);
-    f->AddFrame(fVelocity);
-    f->AddFrame(fLog);
-
-    AddFrame(f, new TGLayoutHints(kLHintsNormal | kLHintsExpandX, 0, 0, 1, 0));
+    TGLayoutHints *hints1  = new TGLayoutHints(kLHintsNormal  | kLHintsExpandX|kLHintsExpandY, 6, 6, 6, 3);
+    TGLayoutHints *hints2  = new TGLayoutHints(kLHintsNormal  | kLHintsExpandX|kLHintsExpandY, 6, 6, 3, 6);
+    TGLayoutHints *hints1a = new TGLayoutHints(kLHintsLeft    | kLHintsTop   |kLHintsExpandX|kLHintsExpandY);
+    TGLayoutHints *hints2a = new TGLayoutHints(kLHintsCenterY | kLHintsTop   |kLHintsExpandX|kLHintsExpandY, 6, 6);
+    TGLayoutHints *hints3a = new TGLayoutHints(kLHintsRight   | kLHintsTop   |kLHintsExpandX|kLHintsExpandY);
+    TGLayoutHints *hints1b = new TGLayoutHints(kLHintsLeft    | kLHintsBottom|kLHintsExpandX|kLHintsExpandY);
+    TGLayoutHints *hints2b = new TGLayoutHints(kLHintsCenterY | kLHintsBottom|kLHintsExpandX|kLHintsExpandY, 6, 6);
+    TGLayoutHints *hints3b = new TGLayoutHints(kLHintsRight   | kLHintsBottom|kLHintsExpandX|kLHintsExpandY);
+
+    fList->Add(hints1);
+    fList->Add(hints2);
+    fList->Add(hints1a);
+    fList->Add(hints2a);
+    fList->Add(hints3a);
+    fList->Add(hints1b);
+    fList->Add(hints2b);
+    fList->Add(hints3b);
+
+    // Layout upper frame
+    f1->AddFrame(fTab,         hints1a);
+    f1->AddFrame(fSkyPosition, hints2a);
+    f1->AddFrame(fAccuracy,    hints3a);
+
+    // Layout upper frame
+    f2->AddFrame(frame,        hints1b);
+    f2->AddFrame(fVelocity,    hints2b);
+    f2->AddFrame(fLog,         hints3b);
+
+    // Layout window
+    AddFrame(f1, hints1);
+    AddFrame(f2, hints2);
 
     //
     // FIXME!
     //
+#ifdef DEBUG
     cout << "MGCosy: Creating Tabs" << endl;
+#endif
     CreateTabs(fTab);
+#ifdef DEBUG
     cout << "MGCosy: Creating Label" << endl;
+#endif
     CreateLabel(frame);
 
@@ -536,15 +581,19 @@
     //   Map the window, set up the layout, etc.
     //
+#ifdef DEBUG
     cout << "MGCosy: Setting Size" << endl;
+#endif
     const Int_t w = 940;
     const Int_t h = 660;
-    SetWMSizeHints(w, h, w, h, 10, 10);  // set the smallest and biggest size of the Main frame
+    SetWMSizeHints(w, h, 1280, 900, 10, 10);  // set the smallest and biggest size of the Main frame
 
     SetWindowName("Cosy Main Window");
     SetIconName("Cosy");
 
+#ifdef DEBUG
     cout << "MGCosy: Map Window" << endl;
+#endif
     MapSubwindows();
-    Resize(GetDefaultSize());
+    Resize(w, h); //GetDefaultSize());
     MapWindow();
 }
@@ -930,4 +979,13 @@
                 //CloseWindow();
                 return kTRUE;
+            case IDM_ASPECT:
+                Int_t w = GetWidth();
+                Int_t h = GetHeight();
+                if (w>940*h/660)
+                    w = 940*h/660;
+                else
+                    h = 660*w/940;
+                Resize(w, h); 
+                return kTRUE;
             }
             return kTRUE;
Index: trunk/MagicSoft/Cosy/gui/MGEmbeddedCanvas.cc
===================================================================
--- trunk/MagicSoft/Cosy/gui/MGEmbeddedCanvas.cc	(revision 1531)
+++ trunk/MagicSoft/Cosy/gui/MGEmbeddedCanvas.cc	(revision 1690)
@@ -12,4 +12,6 @@
 #include <TCanvas.h>
 
+#undef DEBUG
+
 ClassImp(MGEmbeddedCanvas);
 
@@ -19,12 +21,19 @@
       fModified(kFALSE), fWidth(width), fRange(range), fPix(2.*range/width)
 {
+#ifdef DEBUG
     cout << "MGEmbeddedCanvas: Initializing." << endl;
+#endif
+
     fCanvas = GetCanvas();
 
+#ifdef DEBUG
     cout << "MGEmbeddedCanvas: fCanvas = 0x" << fCanvas << endl;
 
     cout << "MGEmbeddedCanvas: SetFillColor." << endl;
+#endif
     fCanvas->SetFillColor(39); // s. TAttFill
+#ifdef DEBUG
     cout << "MGEmbeddedCanvas: fRange=" << fRange << endl;
+#endif
     if (fRange>0)
         fCanvas->Range(-fRange, -fRange, fRange, fRange);
@@ -33,5 +42,7 @@
     fList->SetOwner();
 
+#ifdef DEBUG
     cout << "MGEmbeddedCanvas: Initializing done." << endl;
+#endif
 }
 
Index: trunk/MagicSoft/Cosy/gui/MGImage.cc
===================================================================
--- trunk/MagicSoft/Cosy/gui/MGImage.cc	(revision 1531)
+++ trunk/MagicSoft/Cosy/gui/MGImage.cc	(revision 1690)
@@ -11,4 +11,9 @@
 #include <iostream.h>
 #include <pthread.h>
+
+#include <TTimer.h>
+#include <TSystem.h>
+#include <TVirtualX.h>
+#include <TGX11.h>
 
 ClassImp(MGImage);
@@ -97,12 +102,7 @@
 
     //
-    // get frame id
-    //
-    fId = GetId();
-
-    //
     // Create Default Graphic Context (XCreateGC)
     //
-    fDefGC = gVirtualX->CreateGC(fId, 0); // GetBckgndGC(); //
+    fDefGC = gVirtualX->CreateGC(fId, 0); // GetBckgndGC().GetGC(); //
 
     //
@@ -120,9 +120,13 @@
 
     Resize(w, h);
+
+    //fTimer=new TTimer(Form("gClient->ProcessEventsFor((TGWindow*)0x%p);", this), 250, kTRUE);
+//    fTimer=new TTimer("printf(\"Timer!\\n\"); gSystem->ProcessEvents();", 250, kTRUE);
+    //fTimer->Start();
 }
 
 void MGImage::Resize(UInt_t w, UInt_t h)
 {
-    TGFrame::Resize(w+2*GetBorderWidth(), h+2*GetBorderWidth());
+//    TGFrame::Resize(w+2*GetBorderWidth(), h+2*GetBorderWidth());
     // FIXME: RESIZE THE PIXMAP
 }
@@ -130,5 +134,5 @@
 void MGImage::Resize(TGDimension size)
 {
-    TGFrame::Resize(size.fWidth+2*GetBorderWidth(), size.fHeight+2*GetBorderWidth());
+//    TGFrame::Resize(size.fWidth+2*GetBorderWidth(), size.fHeight+2*GetBorderWidth());
     // FIXME: RESIZE THE PIXMAP
 }
@@ -136,5 +140,5 @@
 void MGImage::MoveResize(Int_t x, Int_t y, UInt_t w, UInt_t h)
 {
-   TGFrame::MoveResize(x, y, w+2*GetBorderWidth(), h+2*GetBorderWidth());
+//   TGFrame::MoveResize(x, y, w+2*GetBorderWidth(), h+2*GetBorderWidth());
    // FIXME: RESIZE THE PIXMAP
 }
@@ -142,4 +146,7 @@
 MGImage::~MGImage()
 {
+    //fTimer->Stop();
+    //delete fTimer;
+
     pthread_mutex_lock((pthread_mutex_t*)fMuxPixmap);
 
@@ -154,8 +161,12 @@
 
     if (fPixmap!=kNone) // @@@
+    {
+        cout << "Delete Pixmap" << endl;
         gVirtualX->DeletePixmap(fPixmap);  // XFreePixmap(fDisplay, (Pixmap) pmap);
+    }
 
     cout << "Deleting GC..." << endl;
 
+
     gVirtualX->DeleteGC(fDefGC);       // XFreeGC(fDisplay, (GC) gc);
 
@@ -165,6 +176,6 @@
 }
 
+#include <X11/Xlib.h>
 /*
-#include <X11/Xlib.h>
 #include <X11/Xutil.h>
 #include <X11/Intrinsic.h>
@@ -174,8 +185,29 @@
 void MGImage::DoRedraw()
 {
-    // Pixmap_t pm = gVirtualX->CreatePixmap(this->GetId(), buffer,
-    //                                       768, 576, 0, 0xff, 8);
-    TGFrame::DrawBorder();
+//    TGFrame::DrawBorder();
     pthread_mutex_lock((pthread_mutex_t*)fMuxPixmap);
+
+    //===========================
+    if (TestBit(kNeedRecreate))
+    {
+        Pixmap_t mask = kNone;
+        PictureAttributes_t attr;
+        attr.fMask = kNone;
+
+        if (fPixmap!=kNone)
+            gVirtualX->DeletePixmap(fPixmap);
+
+        fPixmap=kNone;
+
+        if (!gVirtualX->CreatePictureFromData(fId, fBuffer, fPixmap,
+                                              mask, attr))
+        {
+            cout << "Warning: Error in CreatePictureFromData" << endl;
+            fPixmap=kNone;
+        }
+        ResetBit(kNeedRecreate);
+    }
+
+    //===========================
 
     // Copy a drawable (i.e. pixmap) to another drawable (pixmap, window).
@@ -185,7 +217,19 @@
     //           dest_x, dest_y);
     if (fPixmap!=kNone) //@@@
-    gVirtualX->CopyArea(fPixmap, fId, fDefGC,
-                        0, 0, fWidth, fHeight,
-                        GetBorderWidth(), GetBorderWidth());
+    {
+//        gVirtualX->DrawString(fId, fDefGC, 20, 20, "HELLO WORLD!", 12);
+//        gVirtualX->FillRectangle(fId, fDefGC, 10, 10, 50, 50);
+
+        //        cout << gVirtualX->IsA()->GetName() << endl;
+        gVirtualX->CopyArea(fPixmap, fId, fDefGC,
+                            0, 0, fWidth, fHeight,
+                            GetBorderWidth(), GetBorderWidth());
+
+        /*
+        XCopyArea((Display*)gVirtualX->GetDisplay(), pm, fId,
+                  (GC)fDefGC, 0, 0, fWidth, fHeight,
+                  GetBorderWidth(), GetBorderWidth());
+                  */
+    }
 /*
      if (fPix)
@@ -271,9 +315,11 @@
     cout << "Done " << (void*)fPix << endl;
     */
+
+/*
     Pixmap_t mask = kNone;
     PictureAttributes_t attr;
     attr.fMask = kNone;
     if (fPixmap!=kNone) // @@@
-    gVirtualX->DeletePixmap(fPixmap); // XFreePixmap(fDisplay, (Pixmap) pmap);
+        gVirtualX->DeletePixmap(fPixmap); // XFreePixmap(fDisplay, (Pixmap) pmap);
 
     // Create a pixture pixmap from data. The picture attributes
@@ -310,7 +356,13 @@
         fPixmap=kNone;
     }
-
+*/
+    SetBit(kNeedRecreate);
     pthread_mutex_unlock((pthread_mutex_t*)fMuxPixmap);
-    DoRedraw();
+    //gClient->NeedRedraw(this);
+    //fTimer->Start(10, kTRUE);
+    //gVirtualX->UpdateWindow(1);
+    //    ((TGX11*)gVirtualX)->Sync(1);
+    //new TTimer(Form("gClient->ProcessEventsFor((TGWindow*)0x%p);", this), 1, kFALSE);
+    //    DoRedraw();
 }
 
@@ -339,5 +391,5 @@
         }
     }
-
+/*
     Pixmap_t mask = kNone;
     PictureAttributes_t attr;
@@ -346,4 +398,5 @@
     if (fPixmap!=kNone)
         gVirtualX->DeletePixmap(fPixmap);
+
     fPixmap=kNone;
 
@@ -354,7 +407,13 @@
         fPixmap=kNone;
     }
-
+    */
+    SetBit(kNeedRecreate);
     pthread_mutex_unlock((pthread_mutex_t*)fMuxPixmap);
-    DoRedraw();
-}
-
+    //gClient->NeedRedraw(this);
+    //fTimer->Start(10, kTRUE);
+    //gVirtualX->UpdateWindow(1);
+    //    ((TGX11*)gVirtualX)->Sync(1);
+    //new TTimer(Form("gClient->ProcessEventsFor((TGWindow*)0x%p);", this), 1, kFALSE);
+    //    DoRedraw();
+}
+
Index: trunk/MagicSoft/Cosy/gui/MGImage.h
===================================================================
--- trunk/MagicSoft/Cosy/gui/MGImage.h	(revision 1531)
+++ trunk/MagicSoft/Cosy/gui/MGImage.h	(revision 1690)
@@ -10,4 +10,6 @@
 #include <TGFrame.h>
 
+class TTimer;
+
 typedef unsigned char byte;
 
@@ -20,5 +22,4 @@
 
     GContext_t fDefGC;
-    Drawable_t fId;
     Pixmap_t   fPixmap;
 
@@ -28,5 +29,7 @@
     void *fMuxPixmap; //! test
 
-public:
+    TTimer *fTimer;
+
+    enum { kNeedRecreate = BIT(17) };
 
 public:
Index: trunk/MagicSoft/Cosy/gui/MGSkyPosition.cc
===================================================================
--- trunk/MagicSoft/Cosy/gui/MGSkyPosition.cc	(revision 1531)
+++ trunk/MagicSoft/Cosy/gui/MGSkyPosition.cc	(revision 1690)
@@ -172,5 +172,4 @@
     : MGEmbeddedCanvas("SkyPosition", p, w, 110)
 {
-    cout << "MGSkyPosition: Initilizing." << endl;
     DrawCoordinateSystem();
     InitPlanets();
@@ -178,5 +177,4 @@
     InitText();
     InitCanvas();
-    cout << "MGSkyPosition: Initilizing done." << endl;
 }
 
@@ -278,11 +276,11 @@
     static int Y = ~0;
 
-    int xd = (int)floor(x);
-    int yd = (int)floor(y);
+    int xd = (int)/*floor*/(x);
+    int yd = (int)/*floor*/(y);
     x *= 60.;
     y *= 60.;
 
-    int fx = (int)floor(x*10.);
-    int fy = (int)floor(y*10.);
+    int fx = (int)/*floor*/(x*10.);
+    int fy = (int)/*floor*/(y*10.);
 
     if (X==fx && Y==fy)
@@ -296,6 +294,6 @@
 
     char txt[100];
-    sprintf(txt, "Zd=%d\xb0%02.1f'\nAz=%d\xb0%02.1f'",
-            xd, xm, yd, ym);
+    sprintf(txt, "Zd=%s%d\xb0%02.1f'\nAz=%s%d\xb0%02.1f'",
+            x<0?"-":"", abs(xd), xm, y<0?"-":"", abs(yd), ym);
 
     fText->SetText(fText->GetX(), fText->GetY(), txt);
@@ -305,11 +303,11 @@
 
 
-void MGSkyPosition::Update(ZdAz &pos)
+void MGSkyPosition::Update(ZdAz &pos, double mjd)
 {
     //
     // calculate actual time for planet positions
     //
-    fSlaPlanet->SetMjd2Now();
-    fSlaStar->SetMjd2Now();
+    fSlaPlanet->SetMjd(mjd);
+    fSlaStar->SetMjd(mjd);
 
     UpdatePlanet(kESun,     fSun);
Index: trunk/MagicSoft/Cosy/gui/MGSkyPosition.h
===================================================================
--- trunk/MagicSoft/Cosy/gui/MGSkyPosition.h	(revision 1531)
+++ trunk/MagicSoft/Cosy/gui/MGSkyPosition.h	(revision 1690)
@@ -66,5 +66,5 @@
     ~MGSkyPosition();
 
-    void Update(ZdAz &pos);
+    void Update(ZdAz &pos, double mjd);
 
     ClassDef(MGSkyPosition, 0)
Index: trunk/MagicSoft/Cosy/gui/MGStarguider.cc
===================================================================
--- trunk/MagicSoft/Cosy/gui/MGStarguider.cc	(revision 1531)
+++ trunk/MagicSoft/Cosy/gui/MGStarguider.cc	(revision 1690)
@@ -3,5 +3,7 @@
 #include <fstream.h>    // ifstream
 #include <iostream.h>   // cout
-#
+
+#include <TTimer.h>
+
 #include <TGMenu.h>
 #include <TSystem.h>
@@ -61,4 +63,11 @@
 };
 
+Bool_t MGStarguider::HandleTimer(TTimer *t)
+{
+    fImage->DoRedraw();
+    fZoomImage->DoRedraw();
+    return kTRUE;
+}
+
 #define kZOOM 96
 
@@ -199,4 +208,9 @@
     // Create Image Display
     //
+    fZoomImage = new MGImage(this, kZOOM, kZOOM);
+    fZoomImage->Move(768-kZOOM-2, 700-kZOOM-2);
+    AddFrame(fZoomImage);
+    fList->Add(fZoomImage);
+
     fImage = new MGImage(this, 768, 576);
     fImage->Move(0, fMenu->GetDefaultHeight());
@@ -204,9 +218,4 @@
     fList->Add(fImage);
 
-    fZoomImage = new MGImage(this, kZOOM, kZOOM);
-    fZoomImage->Move(768-kZOOM-2, 700-kZOOM-2);
-    AddFrame(fZoomImage);
-    fList->Add(fZoomImage);
-
     //
     // Make everything visible
@@ -217,8 +226,14 @@
     MapSubwindows();
     MapWindow();
+
+    fTimer=new TTimer(this, 100); // 100ms
+    fTimer->TurnOn();
 }
 
 MGStarguider::~MGStarguider()
 {
+    fTimer->TurnOff();
+    delete fTimer;
+
     delete fSao;
     delete fRaDec;
Index: trunk/MagicSoft/Cosy/gui/MGStarguider.h
===================================================================
--- trunk/MagicSoft/Cosy/gui/MGStarguider.h	(revision 1531)
+++ trunk/MagicSoft/Cosy/gui/MGStarguider.h	(revision 1690)
@@ -14,4 +14,6 @@
 class AltAz;
 class RaDec;
+
+class TTimer;
 
 class TGMenuBar;
@@ -52,4 +54,6 @@
     RaDec *fRaDec;
 
+    TTimer *fTimer;
+
     Int_t fDx;
     Int_t fDy;
@@ -62,4 +66,6 @@
     void GetCoordinates();
     void CalcTrackingError(MStarList &, MStarList &);
+
+    Bool_t HandleTimer(TTimer *t);
 
 public:
Index: trunk/MagicSoft/Cosy/gui/MGVelocity.cc
===================================================================
--- trunk/MagicSoft/Cosy/gui/MGVelocity.cc	(revision 1531)
+++ trunk/MagicSoft/Cosy/gui/MGVelocity.cc	(revision 1690)
@@ -279,6 +279,6 @@
     vy /= 60.;  //['/min]
 
-    int fx = (int)floor(vx*10.);
-    int fy = (int)floor(vy*10.);
+    int fx = (int)/*floor*/(vx*10.);
+    int fy = (int)/*floor*/(vy*10.);
 
     if (X==fx && Y==fy)
@@ -290,5 +290,5 @@
     char txt[100];
     sprintf(txt, "Zd=%.1f'\nAz=%.1f'",
-            vx, vy);
+            vy, vx);
 
     fTextVel->SetText(fTextVel->GetX(), fTextVel->GetY(), txt);
