Avionics
Dropship Simulator
Printer.cpp
Go to the documentation of this file.
1 #include "Printer.h"
2 
3 #include <time.h>
4 
5 namespace Devices
6 {
7  void Printer::Initialize(Logger* prmLogger, Bus* prmBus, HWND prmhWnd)
8  {
9  logger = prmLogger;
10  bus = prmBus;
11  hWnd = prmhWnd;
12  }
13 
15  {
16  for (UINT i = 0; i < bus->commandStream.size(); i++)
17  {
18  Command command = bus->commandStream.at(i);
19  if (command.delay != 0.0f) continue;
20 
22  if (command.name == "PrintReceipt")
23  {
24  ZeroMemory(&hBitmap, sizeof(HBITMAP));
26  hBitmap = static_cast<HBITMAP>(LoadImage(nullptr, L"Textures/Receipt/logo.bmp", IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION | LR_DEFAULTSIZE | LR_LOADFROMFILE | LR_VGACOLOR));
27  if (hBitmap)
28  {
29  GetObject(hBitmap, sizeof(BITMAP), &bitmap);
30  bxWidth = bitmap.bmWidth;
31  bxHeight = bitmap.bmHeight;
32  }
33 
34  DOCINFO di;
35  ZeroMemory(&di, sizeof(DOCINFO));
36  di.cbSize = sizeof(DOCINFO);
37  di.lpszDocName = TEXT("Receipt") ;
38 
39  HDC prn = GetPrinterDC();
40  cxpage = GetDeviceCaps(prn, HORZRES);
41  cypage = GetDeviceCaps(prn, VERTRES);
42  hdcMem = CreateCompatibleDC(prn);
43  SelectObject(hdcMem, hBitmap);
44 
45  StartDoc(prn, &di);
46  StartPage(prn);
47  SetMapMode(prn, MM_ISOTROPIC);
48  SetWindowExtEx(prn, cxpage, cypage, nullptr);
49  SetViewportExtEx(prn, cxpage, cypage, nullptr);
50 
51  SetViewportOrgEx(prn, 0, 0, nullptr);
52 
53  RECT lRect;
54  lRect.left = 0;
55  lRect.right = 384;
56  int topmargin = 0;
57 
58  StretchBlt(prn, 0, topmargin, bxWidth, bxHeight, hdcMem, 0, 0, bxWidth, bxHeight, SRCCOPY);
59 
60  topmargin += 400; // logo
61 
62 
63  HFONT font;
64 
65  font = CreateFontA(48, 0, 0, 0, FW_BOLD, false, false, false, 0, 0, 0, 0, 0, "Microsoft Sans Serif");
66  SelectObject(prn, font);
67 
68  lRect.top = topmargin;
69  topmargin += 96;
70  lRect.bottom = topmargin;
71 
72  // Draws the text on to the device context of the print job
73  std::string content = "PARAGALACTIC\nATTRACTIONS";
74  DrawTextA(prn, content.c_str(), -1, &lRect, DT_CENTER);
75 
76 
77  font = CreateFontA(34, 0, 0, 0, FW_BOLD, true, false, false, 0, 0, 0, 0, 0, "Microsoft Sans Serif");
78  SelectObject(prn, font);
79 
80  lRect.top = topmargin;
81  topmargin += 96;
82  lRect.bottom = topmargin;
83 
84  // Draws the text on to the device context of the print job
85  content = "MORE THAN JUST A RIDE";
86  DrawTextA(prn, content.c_str(), -1, &lRect, DT_CENTER);
87 
88 
89  font = CreateFontA(42, 0, 0, 0, FW_NORMAL, false, false, false, 0, 0, 0, 0, 0, "Microsoft Sans Serif");
90  SelectObject(prn, font);
91 
92  lRect.top = topmargin;
93  topmargin += 42 * 6;
94  lRect.bottom = topmargin;
95 
96  // Draws the text on to the device context of the print job
97  char scenariotimeC[99];
98  sprintf_s(scenariotimeC, 99, "%.1f min", bus->ScenarioTimer / 60.0f);
99  std::string scenariotime = scenariotimeC;
100  time_t rawtime;
101  time(&rawtime);
102  struct tm* timeinfo;
103  timeinfo = localtime(&rawtime);
104  char dateC[99];
105  strftime(dateC, 99, "%m/%d/%Y", timeinfo);
106  std::string date = dateC;
107  char timeC[99];
108  strftime(timeC, 99, "%H:%M:%S", timeinfo);
109  std::string time = timeC;
110  char scorestr[99];
111  sprintf_s(scorestr, 99, "%.0f", bus->ScenarioScore);
112 
113 
114  content = "\"WALK IN THE PARK\"\nDATE: " + date + "\nTIME: " + time + "\nDURATION: " + scenariotime + "\nSCORE: " + scorestr;
115  DrawTextA(prn, content.c_str(), -1, &lRect, DT_LEFT);
116 
117 
118  /*
119  SCORING
120  -------
121  STABILIZED CHECK 1: PASS
122  STABILIZED CHECK 2: FAIL
123  THROTTLE COMPLY 1: FAIL
124  STABILIZED CHECK 3: PASS
125  THROTTLE COMPLY 2: PASS
126 
127  OVERALL SCORE: 60%
128 
129  */
130 
131 
132  font = CreateFontA(36, 0, 0, 0, FW_NORMAL, false, false, false, 0, 0, 0, 0, 0, "Microsoft Sans Serif");
133  SelectObject(prn, font);
134 
135  lRect.top = topmargin;
136  topmargin += 36 * 18;
137  lRect.bottom = topmargin;
138 
139  // Draws the text on to the device context of the print job
140  content = "Please check for your free cockpit video recording after your flight. Share it with your friends!\n\nparagalactic.com?v=" + bus->receiptNumber + "\n_________________________\nBring us to your next birthday party or event!\n\nparagalactic.com/Booking\n\nUse discount code:\n\n" + bus->receiptNumber + "\n\nand receive";
141  DrawTextA(prn, content.c_str(), -1, &lRect, DT_CENTER | DT_WORDBREAK);
142 
143 
144  font = CreateFontA(48, 0, 0, 0, FW_BOLD, false, false, false, 0, 0, 0, 0, 0, "Microsoft Sans Serif");
145  SelectObject(prn, font);
146 
147  lRect.top = topmargin;
148  topmargin += 48;
149  lRect.bottom = topmargin;
150 
151  // Draws the text on to the device context of the print job
152  content = "$50 OFF!";
153  DrawTextA(prn, content.c_str(), -1, &lRect, DT_CENTER);
154 
155  EndPage(prn);
156  EndDoc(prn);
157  DeleteDC(prn);
158  DeleteDC(hdcMem);
159 
160  bus->commandStream.erase(bus->commandStream.begin() + i);
161  break;
162  }
163  }
164  }
165 
167  {
169  HDC hdc = CreateDC(L"WINSPOOL\0", L"hp LaserJet 1320 PCL 5", nullptr, nullptr);
170  if (!hdc)
171  hdc = CreateDC(L"WINSPOOL\0", L"POS58", nullptr, nullptr);
172  return hdc;
173  }
174 }
HBITMAP hBitmap
Definition: Printer.h:21
BITMAP bitmap
Definition: Printer.h:22
std::vector< Command > commandStream
Definition: Bus.h:20
Definition: Logger.h:5
static HDC GetPrinterDC()
Definition: Printer.cpp:166
okay, the portable keyboard numbers don&#39;t work like the outside keypad because the outside keypad is ...
Definition: Analog.cpp:3
Definition: Bus.h:12
std::string name
command name
Definition: Command.h:11
void FrameMove()
Definition: Printer.cpp:14
void Initialize(Logger *logger, Bus *prmBus, HWND hWnd)
Definition: Printer.cpp:7
Definition: Command.h:5
std::string receiptNumber
Definition: Bus.h:293
Logger * logger
Definition: Printer.h:17
float delay
wait number of seconds before executing command
Definition: Command.h:8
float ScenarioScore
Definition: Bus.h:294
float ScenarioTimer
Definition: Bus.h:292