/* LTPrintout.cpp
**
** This file is part of wxLaserTank.
**
** Copyright © 2002, 2009 Gary Harris
**
** Based on LaserTank ver 4.1.2 by Jim Kindley.
**
** wxLaserTank is free software; you can redistribute it and/or
** modify it under the terms of the GNU General Public License as
** published by the Free Software Foundation; either version 2 of
** the License, or (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; see the file docs\gpl.txt.
** If not, write to the Free Software Foundation, Inc.,
** 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
**
** Gary Harris
** garyjharris@sourceforge.net
*/
// Printing class for Laser Tank.
// Based on printing sample provided with wxWindows.
// Gary Harris
// 24/3/02
// For compilers that support pre-compilation, includes "wx.h".
#include <wx/wxprec.h>
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#ifndef WX_PRECOMP
// Include your minimal set of headers here, or wx.h
#include <wx/wx.h>
#endif
#include <wx/print.h>
#include "LTPrintout.h"
#include "LaserTankFrm.h"
LTPrintout::LTPrintout(wxWindow* panel, wxRect rectGame, long lLevel, wxWord wMove, wxWord wShot, wxString title) : wxPrintout(title)
{
this->m_Panel = panel;
this->m_rectGame = rectGame;
this->m_PrintJobName.Printf(wxT("%s %ld"), LTG->txt036() .c_str(), lLevel);
wxString sFormat = _("Moves") + wxString(wxT(" = %d ")) + _("Shots") + wxString(wxT(" = %d"));
this->m_PrintInfo.Printf(sFormat, wMove, wShot);
}
bool LTPrintout::OnPrintPage(int page)
{
wxDC *dc = GetDC(); // Get PrinterDC.
if(dc){
if(page == 1){
DrawPageOne(dc);
}
return true;
}
else{
return false;
}
}
bool LTPrintout::OnBeginDocument(int startPage, int endPage)
{
if (!wxPrintout::OnBeginDocument(startPage, endPage)){
return false;
}
return true;
}
void LTPrintout::GetPageInfo(int *minPage, int *maxPage, int *selPageFrom, int *selPageTo)
{
*minPage = 1; // Just the one page i.e. the Game board.
*maxPage = 1;
*selPageFrom = 1;
*selPageTo = 1;
}
void LTPrintout::DrawPageOne(wxDC *dc)
{
MapScreenSizeToPage();
wxRect fitRect = GetLogicalPageRect();
// This offsets the image so that it is centered within the reference
// rectangle defined above.
wxCoord xoff = (fitRect.width - m_rectGame.GetWidth()) / 2;
wxCoord yoff = (fitRect.height - m_rectGame.GetHeight()) / 2;
OffsetLogicalOrigin(xoff, yoff);
// Draw the game board.
wxBitmap bitmap(m_rectGame.GetWidth(), m_rectGame.GetHeight());
wxClientDC cDC(this->m_Panel);
wxMemoryDC memDC;
memDC.SelectObject(bitmap);
memDC.Blit(0, 0, m_rectGame.GetWidth(), m_rectGame.GetHeight(), &cDC, m_rectGame.x, m_rectGame.y);
memDC.SelectObject(wxNullBitmap);
dc->DrawBitmap (bitmap, 0, 0);
// Moves, shots.
const wxString strLevel(this->m_PrintJobName);
wxSize size = dc->GetTextExtent(strLevel);
dc->DrawText(this->m_PrintJobName, fitRect.x + m_rectGame.GetWidth() / 2 - size.GetWidth() / 2, yoff - m_rectGame.GetHeight());
// Level number.
dc->DrawText(this->m_PrintInfo, fitRect.x, yoff + 60);
}