//--------------------------------------------------------------------------- // Copyright (c) Jim Wright 2004 // // JimPage.cpp // This is the class for drawing things upon. // //--------------------------------------------------------------------------- #include "StdAfx.h" #include "jimpage.h" /* ** Basic constructor */ CJimPage::CJimPage(void) { this->m_locationx = 0; this->m_locationy = 0; this->m_width = 0; this->m_height = 0; this->m_boarder = 0; } /* ** Basic destructor */ CJimPage::~CJimPage(void) { int i; for(i=0;i<(int)m_objects.size();i++) { delete m_objects[i]; } } CJimPage::CJimPage(int locx,int locy,int width, int height, int boarder) { this->m_locationx = locx; this->m_locationy = locy; this->m_width = width; this->m_height = height; this->m_boarder = boarder; } /* ** Basically the paint the page method, it will run through all of the ** objects that are in the page and draw them. */ void CJimPage::DrawPage(CDC* hDC) { int i; double top=this->m_height,left=this->m_width,right=0.0,bottom=0.0; int width,height; CPen myPen; myPen.CreatePen( PS_SOLID, 1, RGB(0,0,0) ); hDC->SelectObject(myPen); hDC->FillSolidRect(this->m_locationx,this->m_locationy,this->m_width,this->m_height,RGB(255,255,255)); hDC->MoveTo(this->m_locationx ,this->m_locationy ); hDC->LineTo(this->m_locationx+this->m_width,this->m_locationy ); hDC->LineTo(this->m_locationx+this->m_width,this->m_locationy+this->m_height); hDC->LineTo(this->m_locationx ,this->m_locationy+this->m_height); hDC->LineTo(this->m_locationx ,this->m_locationy ); /* ** Find the size of all objects we have to work with */ for(i=0;i<(int)m_objects.size();i++) { if(left>m_objects[i]->FindLeft()) { left = m_objects[i]->FindLeft(); } if(top>m_objects[i]->FindTop()) { top = m_objects[i]->FindTop(); } if(rightFindRight()) { right = m_objects[i]->FindRight(); } if(bottomFindBottom()) { bottom = m_objects[i]->FindBottom(); } } /* ** Find the scale of the items in the page */ width = this->m_width-(2*m_boarder); height = this->m_height-(2*m_boarder); width = width/(int)(right-left); height = height/(int)(bottom-top); m_scale = height; for(i=0;i<(int)m_objects.size();i++) { m_objects[i]->Draw(hDC,(int)this->m_locationx+m_boarder,(int)this->m_locationy+m_boarder,m_scale); } } void CJimPage::AddObject(CJimDrawingObject* object) { m_objects.push_back(object); }