00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include <stdio.h>
00021
00022 #include "wx/wx.h"
00023
00024 #include "ewx.h"
00025
00026 #include "dic.h"
00027 #include "pldrack.h"
00028 #include "round.h"
00029 #include "turn.h"
00030 #include "player.h"
00031 #include "turn.h"
00032 #include "game.h"
00033
00034 #include "configdb.h"
00035 #include "printout.h"
00036
00037 bool
00038 GamePrintout::OnPrintPage(int page)
00039 {
00040 wxDC *dc = GetDC();
00041 if (dc)
00042 {
00043 if (page == 1)
00044 DrawPage(dc);
00045
00046 return TRUE;
00047 }
00048 else
00049 return FALSE;
00050 }
00051
00052 bool
00053 GamePrintout::HasPage(int pageNum)
00054 {
00055 return pageNum == 1;
00056 }
00057
00058 bool
00059 GamePrintout::OnBeginDocument(int startPage, int endPage)
00060 {
00061 if (!wxPrintout::OnBeginDocument(startPage, endPage))
00062 return FALSE;
00063
00064 return TRUE;
00065 }
00066
00067 void
00068 GamePrintout::GetPageInfo(int *minPage, int *maxPage, int *selPageFrom, int *selPageTo)
00069 {
00070 *minPage = 1;
00071 *maxPage = 1;
00072 *selPageFrom = 1;
00073 *selPageTo = 1;
00074 }
00075
00076 void
00077 GamePrintout::SetSpaces(wxString* str, int spaces)
00078 {
00079 size_t i;
00080 wxString strs = wxT("");
00081 if (str->Len() == 0)
00082 return ;
00083 for(i=0; i < (str->Len()-1); i++) {
00084 strs = strs + str->GetChar(i);
00085 strs = strs + wxString(wxChar(' '), spaces);
00086 }
00087 strs = strs + str->GetChar(str->Len() - 1);
00088 *str = strs;
00089 }
00090
00091 void
00092 GamePrintout::DrawStringJustif(wxDC *dc, wxString *str, long x, long y, long w,
00093 enum Justif justif, int spaces)
00094 {
00095 long wtext,htext;
00096
00097 SetSpaces(str,spaces);
00098 dc->GetTextExtent(*str,&wtext,&htext);
00099
00100 switch (justif)
00101 {
00102 case LEFT:
00103 break;
00104 case CENTER:
00105 x = x + (w - wtext) / 2;
00106 break;
00107 case RIGHT:
00108 x = x + w - wtext;
00109 break;
00110 }
00111 dc->DrawText(*str,x,y);
00112 }
00113
00114 void
00115 GamePrintout::DrawHeadingLine(wxDC *dc, long heightH, float mmToLogical)
00116 {
00117 long i,x,w,y;
00118 wxString str;
00119
00120 x = config.getMarginX() + config.getDxBegin();
00121 y = config.getMarginY() + config.getDyT1();
00122 for (i = 0; i < 5; i++)
00123 {
00124 w = config.getDxText(i);
00125 str = config.getNameH(i);
00126 DrawStringJustif(dc,&str,
00127 (long) (mmToLogical*x),
00128 (long) (mmToLogical*y),
00129 (long) (mmToLogical*w),
00130 config.getJustifH(i),
00131 config.getSpacesH(i));
00132 x += w + config.getDxEnd() + config.getDxBegin();
00133 }
00134 }
00135
00136 void
00137 GamePrintout::DrawTextLine(wxDC *dc, int numline, long basey, long heightT, float mmToLogical)
00138 {
00139 #define DIM(i) \
00140 x += w + config.getDxEnd() + config.getDxBegin(); \
00141 w = config.getDxText(i)
00142
00143 #define DRW(i) \
00144 DrawStringJustif(dc,&str,(long) (mmToLogical*x), \
00145 (long) (mmToLogical*y), \
00146 (long) (mmToLogical*w), \
00147 config.getJustifT(i), \
00148 config.getSpacesT(i))
00149
00150 long x,y,w;
00151 wxString str;
00152
00153 x = config.getMarginX() + config.getDxBegin();
00154 y = basey + config.getDyT1()
00155 + numline * (config.getDyT1() + heightT + config.getDyT2());
00156 w = config.getDxText(0);
00157 str = wxT("");
00158
00159 int NRounds = m_game.getHistory().getSize();
00160
00161
00162 if (numline < NRounds)
00163 {
00164 str = wxT("");
00165 str << (numline + 1);
00166 DRW(0);
00167 }
00168
00169 DIM(1);
00170 if (numline < NRounds)
00171 {
00172 str = wxU(m_game.getHistory().getTurn(numline).getPlayedRack().toString().c_str());
00173 DRW(1);
00174 }
00175
00176 DIM(2);
00177 if ((numline > 0) && (numline <= NRounds))
00178 {
00179 str = wxU(m_game.getHistory().getTurn(numline - 1).getRound().getWord().c_str());
00180 DRW(2);
00181 }
00182
00183 DIM(3);
00184 if ((numline > 0) && (numline <= NRounds))
00185 {
00186 str = wxU(m_game.getHistory().getTurn(numline - 1).getRound().getCoord().toString().c_str());
00187 DRW(3);
00188 }
00189
00190 DIM(4);
00191 if ((numline > 0) && (numline <= NRounds))
00192 {
00193 str = wxT("");
00194 str << m_game.getHistory().getTurn(numline - 1).getRound().getPoints();
00195 DRW(4);
00196 }
00197
00198 if (numline == NRounds + 1)
00199 {
00200 str = wxT("");
00201 str << m_game.getPlayer(0).getPoints();
00202 DRW(4);
00203 }
00204 #undef DIM
00205 #undef DRW
00206 }
00207
00208 void
00209 GamePrintout::DrawPage(wxDC *dc)
00210 {
00211
00212
00213
00214
00215 int dcSizeW, dcSizeH;
00216 int pageWidthPix, pageHeightPix;
00217 int ppiScreenX, ppiScreenY;
00218 int ppiPrinterX, ppiPrinterY;
00219
00220 GetPPIScreen(&ppiScreenX, &ppiScreenY);
00221 GetPPIPrinter(&ppiPrinterX, &ppiPrinterY);
00222 dc->GetSize(&dcSizeW, &dcSizeH);
00223 GetPageSizePixels(&pageWidthPix, &pageHeightPix);
00224
00225
00226
00227
00228
00229
00230 float scale = (float)((float)ppiPrinterX/(float)ppiScreenX);
00231
00232
00233
00234
00235
00236 float overallScaleX = scale * (float)(dcSizeW/(float)pageWidthPix);
00237 float overallScaleY = scale * (float)(dcSizeH/(float)pageHeightPix);
00238 dc->SetUserScale(overallScaleX, overallScaleY);
00239 float mmToLogical = (float)(ppiPrinterX/(scale*25.1));
00240
00241 long i,basey;
00242 long heightH, heightT;
00243 wxFont Hfont = config.getFont(PRINTHFONT);
00244 wxFont Tfont = config.getFont(PRINTTFONT);
00245
00246 #if wxCHECK_VERSION(2,5,0)
00247 wxColour wxBlack = wxTheColourDatabase->Find(wxT("BLACK"));
00248 wxColour wxWhite = wxTheColourDatabase->Find(wxT("WHITE"));
00249 wxPen *blackPen = wxThePenList->FindOrCreatePen(wxBlack, 1, wxSOLID);
00250 wxBrush *whiteBrush = wxTheBrushList->FindOrCreateBrush(wxWhite, wxSOLID);
00251 #else
00252 wxColour *wxBlack = wxTheColourDatabase->FindColour(wxT("BLACK"));
00253 wxColour *wxWhite = wxTheColourDatabase->FindColour(wxT("WHITE"));
00254 wxPen *blackPen = wxThePenList->FindOrCreatePen(*wxBlack, 1, wxSOLID);
00255 wxBrush *whiteBrush = wxTheBrushList->FindOrCreateBrush(*wxWhite, wxSOLID);
00256 #endif
00257
00258
00259 dc->SetPen(* blackPen);
00260 dc->SetBrush(* whiteBrush);
00261 dc->SetFont(Hfont);
00262 heightH = (long) (dc->GetCharHeight() / mmToLogical);
00263 DrawHeadingLine(dc,heightH,mmToLogical);
00264 basey = config.getMarginY() + config.getDyH1() + heightH + config.getDyH2();
00265 dc->SetFont(Tfont);
00266 heightT = (long) (dc->GetCharHeight() / mmToLogical);
00267 int NRounds = m_game.getHistory().getSize();
00268 for(i=0; i < (NRounds+3);i++)
00269 {
00270 DrawTextLine(dc,i,basey,heightT,mmToLogical);
00271 }
00272 dc->SetFont(wxNullFont);
00273 DrawGameLines(dc,heightH,heightT,mmToLogical,overallScaleX,overallScaleY);
00274 }
00275
00276 void
00277 GamePrintout::DrawGameLines(wxDC *dc, long heightH, long heightT,
00278 float mmToLogical, float overallScaleX,
00279 float overallScaleY)
00280 {
00281 int i, nTextLines;
00282 long col,lin, StartX, StartY;
00283 long HeadHeight, LineHeight;
00284 long TextStart, TextHeight, TextBottom, TextRight;
00285
00286 float SCALE = config.getPrintLineScale();
00287 dc->SetUserScale(SCALE,SCALE);
00288
00289 int NRounds = m_game.getHistory().getSize();
00290 nTextLines = NRounds + 2;
00291 StartX = config.getMarginX();
00292 StartY = config.getMarginY();
00293
00294 HeadHeight = config.getDyH1() + heightH + config.getDyH2();
00295 LineHeight = config.getDyT1() + heightT + config.getDyT2();
00296 TextStart = StartY + HeadHeight;
00297 TextHeight = nTextLines * LineHeight;
00298 TextBottom = TextStart + TextHeight;
00299
00300
00301
00302
00303 float scalefactorX = mmToLogical * overallScaleX / SCALE;
00304 float scalefactorY = mmToLogical * overallScaleY / SCALE;
00305
00306 col = StartX;
00307 for (i = 0; i <= 5; i++)
00308 {
00309 dc->DrawLine((long) (col * scalefactorX),
00310 (long) (StartY * scalefactorY),
00311 (long) (col * scalefactorX),
00312 (long) (TextBottom * scalefactorY));
00313 col += i == 5 ? 0 : config.getDxBegin() + config.getDxText(i) + config.getDxEnd();
00314 }
00315 TextRight = col;
00316
00317
00318
00319 lin = StartY;
00320 for (i = 0; i <= (nTextLines + 1); i++)
00321 {
00322 dc->DrawLine((long) (StartX * scalefactorX),
00323 (long) (lin * scalefactorY),
00324 (long) (TextRight * scalefactorX),
00325 (long) (lin * scalefactorY));
00326 lin = StartY + HeadHeight + i * LineHeight;
00327 }
00328 }
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338