[go: up one dir, main page]

Menu

[r15]: / LTPrintout.cpp  Maximize  Restore  History

Download this file

117 lines (101 with data), 3.6 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/* 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);
}