// TObject.cpp: implementation of the TObject class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "TObject.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

TObject object;

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

TObject::TObject() :
   TBaseObject( OBJECT_STATE_OK )
{
   elev.setNumber(1); elev.setFloorNumbers(28);
   button.setNumber(1); button.setFloorNumbers(28);
}

TObject::~TObject()
{
}

void TObject::reset()
{
   elev.reset();
   button.reset();
}

void TObject::draw( CDialog *wnd, CPaintDC *dc )
{
   CBrush brush(RGB(100,100,100));
   CBrush* pOldBrush = dc->SelectObject( &brush );

   CPen pen( PS_SOLID, 1, RGB(100,100,100) );
   CPen* pOldPen = dc->SelectObject( &pen );

   // get our client rectangle
   CRect clientRect;
   wnd->GetClientRect( &clientRect );

   int x1 = 20 - LENGTH_EXTRAS + ELEVATOR_XDISTANCE;
   int x2 = 20 + 10 + ELEVATOR_GROUP_DISTANCE + ELEVATOR_WIDE + LENGTH_EXTRAS;

   dc->MoveTo( x1, clientRect.bottom - ELEVATOR_YCONST );
   dc->LineTo( x2, clientRect.bottom - ELEVATOR_YCONST );

   dc->MoveTo( x1, clientRect.bottom - ELEVATOR_YCONST - ELEVATOR_HEIGHT );
   dc->LineTo( x2, clientRect.bottom - ELEVATOR_YCONST - ELEVATOR_HEIGHT );

   dc->MoveTo( x1, clientRect.bottom - ELEVATOR_YCONST - 7*ELEVATOR_HEIGHT );
   dc->LineTo( x2, clientRect.bottom - ELEVATOR_YCONST - 7*ELEVATOR_HEIGHT );

   dc->MoveTo( x1, clientRect.bottom - ELEVATOR_YCONST - 8*ELEVATOR_HEIGHT );
   dc->LineTo( x2, clientRect.bottom - ELEVATOR_YCONST - 8*ELEVATOR_HEIGHT );

   dc->MoveTo( x1, clientRect.bottom - ELEVATOR_YCONST - 15*ELEVATOR_HEIGHT );
   dc->LineTo( x2, clientRect.bottom - ELEVATOR_YCONST - 15*ELEVATOR_HEIGHT );

   dc->MoveTo( x1, clientRect.bottom - ELEVATOR_YCONST - 16*ELEVATOR_HEIGHT );
   dc->LineTo( x2, clientRect.bottom - ELEVATOR_YCONST - 16*ELEVATOR_HEIGHT );

   dc->MoveTo( x1, clientRect.bottom - ELEVATOR_YCONST - 20*ELEVATOR_HEIGHT );
   dc->LineTo( x2, clientRect.bottom - ELEVATOR_YCONST - 20*ELEVATOR_HEIGHT );

   dc->MoveTo( x1, clientRect.bottom - ELEVATOR_YCONST - 21*ELEVATOR_HEIGHT );
   dc->LineTo( x2, clientRect.bottom - ELEVATOR_YCONST - 21*ELEVATOR_HEIGHT );

   CBrush dbrush(RGB(0,255,0)); 
   dc->SelectObject( &dbrush );

   CPen dpen( PS_SOLID, 1, RGB(0,255,0) );
   dc->SelectObject( &dpen );
   CRect rect;

   dc->SetBkMode( TRANSPARENT );

   for( int i = 1; i <= MAX_FLOOR_NUMBER; i++ )
   {
      rect.left = 10;
      rect.right = 30;
      rect.top = clientRect.bottom - ELEVATOR_YCONST - i*ELEVATOR_HEIGHT;
      rect.bottom = clientRect.bottom - ELEVATOR_YCONST - (i-1)*ELEVATOR_HEIGHT;
      char s[3];
      CString str( itoa( i, s, 10 ) );
      dc->DrawText( str, &rect, DT_LEFT );

      if( i == 13 )
      {
         rect.left = 97;
         rect.right = 130;
         dc->DrawText( "Îáù.", &rect, DT_LEFT );
      }
   }

   dc->SelectObject(pOldBrush);
   dc->SelectObject(pOldPen);

   elev.draw( wnd, dc );
   button.draw( wnd, dc );
}

void TObject::step()
{
   elev.step();
}
