Advertisement
k0mZ

Untitled

Nov 20th, 2018
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 21.01 KB | None | 0 0
  1.  
  2. // RGLab1View.cpp : implementation of the CRGLab1View class
  3. //
  4.  
  5. #include "stdafx.h"
  6. // SHARED_HANDLERS can be defined in an ATL project implementing preview, thumbnail
  7. // and search filter handlers and allows sharing of document code with that project.
  8. #ifndef SHARED_HANDLERS
  9. #include "RGLab1.h"
  10. #include "resource.h"
  11. #include "DImage.h"
  12. #include <stdint.h>
  13. #endif
  14.  
  15. #include "RGLab1Doc.h"
  16. #include "RGLab1View.h"
  17.  
  18. #ifdef _DEBUG
  19. #define new DEBUG_NEW
  20. #endif
  21.  
  22.  
  23. // CRGLab1View
  24.  
  25. IMPLEMENT_DYNCREATE(CRGLab1View, CView)
  26.  
  27. BEGIN_MESSAGE_MAP(CRGLab1View, CView)
  28. // Standard printing commands
  29. ON_COMMAND(ID_FILE_PRINT, &CView::OnFilePrint)
  30. ON_COMMAND(ID_FILE_PRINT_DIRECT, &CView::OnFilePrint)
  31. ON_COMMAND(ID_FILE_PRINT_PREVIEW, &CView::OnFilePrintPreview)
  32. ON_WM_LBUTTONDOWN()
  33. ON_WM_KEYDOWN()
  34. ON_WM_ERASEBKGND()
  35. END_MESSAGE_MAP()
  36.  
  37. // CRGLab1View construction/destruction
  38.  
  39. CRGLab1View::CRGLab1View() noexcept
  40. {
  41. // TODO: add construction code here
  42. isSideOpen = false;
  43. isKeyFound = false;
  44. isDoorOpen = false;
  45. r = b = g = false;
  46. }
  47.  
  48. CRGLab1View::~CRGLab1View()
  49. {
  50. }
  51.  
  52. BOOL CRGLab1View::PreCreateWindow(CREATESTRUCT& cs)
  53. {
  54. // TODO: Modify the Window class or styles here by modifying
  55. // the CREATESTRUCT cs
  56.  
  57. return CView::PreCreateWindow(cs);
  58. }
  59.  
  60. // CRGLab1View drawing
  61.  
  62. void DrawWalls(CDC* pDC, CRect window)
  63. {
  64. // front wall
  65.  
  66. CBrush* orangeBrush = new CBrush(RGB(255, 191, 127));
  67. CBrush* oldBrush = pDC->SelectObject(orangeBrush);
  68.  
  69. pDC->Rectangle(window.right*0.1, window.bottom*0.1, window.right*0.9, window.bottom*0.9);
  70.  
  71. delete orangeBrush;
  72.  
  73. // left and right walls
  74.  
  75. CBrush* brownBrush = new CBrush(RGB(195, 147, 98));
  76. pDC->SelectObject(brownBrush);
  77.  
  78. CPoint leftWall[4];
  79. leftWall[0] = CPoint(0, 0);
  80. leftWall[1] = CPoint(window.right*0.1, window.bottom*0.1);
  81. leftWall[2] = CPoint(window.right*0.1, window.bottom*0.9);
  82. leftWall[3] = CPoint(0, window.bottom);
  83. pDC->Polygon(leftWall, 4);
  84.  
  85. CPoint rightWall[4];
  86. rightWall[0] = CPoint(window.right, 0);
  87. rightWall[1] = CPoint(window.right*0.9, window.bottom*0.1);
  88. rightWall[2] = CPoint(window.right*0.9, window.bottom*0.9);
  89. rightWall[3] = CPoint(window.right, window.bottom);
  90. pDC->Polygon(rightWall, 4);
  91.  
  92. delete brownBrush;
  93.  
  94. // ceiling
  95.  
  96. pDC->SelectStockObject(WHITE_BRUSH);
  97. CPoint ceiling[4];
  98. ceiling[0] = CPoint(0, 0);
  99. ceiling[1] = CPoint(window.right*0.1, window.bottom*0.1);
  100. ceiling[2] = CPoint(window.right*0.9, window.bottom*0.1);
  101. ceiling[3] = CPoint(window.right, 0);
  102. pDC->Polygon(ceiling, 4);
  103.  
  104. // floor
  105.  
  106. pDC->SelectStockObject(LTGRAY_BRUSH);
  107. CPoint floor[4];
  108. floor[0] = CPoint(0, window.bottom);
  109. floor[1] = CPoint(window.right*0.1, window.bottom*0.9);
  110. floor[2] = CPoint(window.right*0.9, window.bottom*0.9);
  111. floor[3] = CPoint(window.right, window.bottom);
  112. pDC->Polygon(floor, 4);
  113.  
  114. //end
  115. pDC->SelectObject(oldBrush);
  116. }
  117.  
  118. void DrawDoor(CDC* pDC, CRect window, bool isDoorOpen, HENHMETAFILE keyMeta){
  119. // door
  120. CBrush* brownBrush = new CBrush(RGB(132, 99, 66));
  121. CBrush* oldBrush = pDC->SelectObject(brownBrush);
  122.  
  123. long offsetX = window.right*0.1*0.1;
  124. long offsetY = window.bottom*0.1*0.1;
  125.  
  126. if (!isDoorOpen) {
  127.  
  128. CPoint door[4];
  129. door[0] = CPoint(window.right - offsetX, window.bottom*0.15);
  130. door[1] = CPoint(window.right*0.9 + offsetX, window.bottom*0.2);
  131. door[2] = CPoint(window.right*0.9 + offsetX, window.bottom*0.9 + offsetY);
  132. door[3] = CPoint(window.right - offsetX, window.bottom - offsetY);
  133. pDC->Polygon(door, 4);
  134.  
  135. // doorknob
  136.  
  137. CBrush* orangeBrush = new CBrush(RGB(235, 154, 0));
  138. pDC->SelectObject(orangeBrush);
  139.  
  140. pDC->Ellipse(door[0].x - 20, door[0].y + (door[3].y - door[0].y) / 2 - 7, door[0].x - 5, door[0].y + (door[3].y - door[0].y) / 2 + 7);
  141. pDC->Ellipse(door[0].x - 35, door[0].y + (door[3].y - door[0].y) / 2 - 10, door[0].x - 10, door[0].y + (door[3].y - door[0].y) / 2 + 10);
  142.  
  143. delete orangeBrush;
  144.  
  145. // keyhole
  146.  
  147. pDC->SelectStockObject(BLACK_BRUSH);
  148. pDC->Ellipse(door[0].x - 15, door[0].y + (door[3].y - door[0].y) / 2 + 14, door[0].x - 5, door[0].y + (door[3].y - door[0].y) / 2
  149. + 28);
  150. }
  151. else {
  152. long doorX = window.right * 0.2;
  153.  
  154. pDC->Rectangle(
  155. window.right*0.9 + offsetX - doorX,
  156. window.bottom*0.2,
  157. window.right*0.9 + offsetX,
  158. window.bottom*0.9 + offsetY
  159. );
  160.  
  161. CBrush* oldBrownBrush = (CBrush*)pDC->SelectStockObject(BLACK_BRUSH);
  162.  
  163. CPoint door[4];
  164. door[0] = CPoint(window.right - offsetX, window.bottom*0.15);
  165. door[1] = CPoint(window.right*0.9 + offsetX, window.bottom*0.2);
  166. door[2] = CPoint(window.right*0.9 + offsetX, window.bottom*0.9 + offsetY);
  167. door[3] = CPoint(window.right - offsetX, window.bottom - offsetY);
  168. pDC->Polygon(door, 4);
  169.  
  170. pDC->SelectObject(oldBrownBrush);
  171. }
  172.  
  173. pDC->SelectObject(oldBrush);
  174. }
  175.  
  176. void DrawGlass(CDC* pDC, long x1, long y1, long x2, long y2) {
  177. CBrush* blueBrush = new CBrush(RGB(0, 186, 219));
  178. CBrush* oldBrush = pDC->SelectObject(blueBrush);
  179.  
  180. pDC->Rectangle(x1, y1, x2, y2);
  181.  
  182. pDC->SelectObject(oldBrush);
  183. }
  184.  
  185. void DrawWindow(CDC* pDC, CRect window) {
  186. // curtain...something
  187.  
  188. long leftWallX = window.right * 0.1;
  189. long frontWallX = window.right * 0.8;
  190. long curtainRailX = frontWallX * 0.4;
  191. long curtainRailX1 = leftWallX + (frontWallX - curtainRailX) / 2;
  192. long curtainRailX2 = curtainRailX1 + curtainRailX;
  193.  
  194. long topWallX = window.bottom * 0.1;
  195. long railOffsetY = window.bottom * 0.05;
  196. long curtainRailY = window.bottom * 0.05;
  197. long curtainRailY1 = topWallX + railOffsetY;
  198. long curtainRailY2 = curtainRailY1 + curtainRailY;
  199.  
  200. long curtainRailY3 = curtainRailY;
  201. long curtainRailX3 = curtainRailY;
  202.  
  203. CBrush* brownBrush = new CBrush(RGB(132, 99, 66));
  204. CBrush* oldBrush = pDC->SelectObject(brownBrush);
  205.  
  206. pDC->RoundRect(curtainRailX1, curtainRailY1, curtainRailX2, curtainRailY2, curtainRailY, curtainRailY);
  207.  
  208. // window
  209.  
  210. long windowOffsetX = 10;
  211. long windowX = curtainRailX - curtainRailX3 - 2 * windowOffsetX; // subtract the rounded area
  212. long windowX1 = curtainRailX1 + curtainRailY / 2 + windowOffsetX;
  213. long windowX2 = windowX1 + windowX;
  214.  
  215. long windowY = window.bottom * 0.45;
  216. long windowY1 = curtainRailY2;
  217. long windowY2 = windowY1 + windowY;
  218.  
  219. pDC->Rectangle(windowX1, windowY1, windowX2, windowY2);
  220.  
  221. delete brownBrush;
  222.  
  223. // glass
  224.  
  225. long glassOffsetX = 5;
  226. long glassOffsetY = 10;
  227. long glassX = (windowX - 3 * glassOffsetX) / 2;
  228. long glassY = windowY - 2 * glassOffsetY;
  229.  
  230. long leftGlassX1 = windowX1 + glassOffsetX;
  231. long leftGlassX2 = leftGlassX1 + glassX;
  232. long leftGlassY1 = windowY1 + glassOffsetY;
  233. long leftGlassY2 = leftGlassY1 + glassY;
  234.  
  235. long rightGlassX1 = leftGlassX2 + glassOffsetX;
  236. long rightGlassX2 = rightGlassX1 + glassX;
  237. long rightGlassY1 = windowY1 + glassOffsetY;
  238. long rightGlassY2 = rightGlassY1 + glassY;
  239.  
  240. DrawGlass(pDC, leftGlassX1, leftGlassY1, leftGlassX2, leftGlassY2);
  241. DrawGlass(pDC, rightGlassX1, rightGlassY1, rightGlassX2, rightGlassY2);
  242.  
  243. // curtain
  244.  
  245. CBrush* yellowBrush = new CBrush(RGB(249, 254, 160));
  246. pDC->SelectObject(yellowBrush);
  247.  
  248. long curtainX = curtainRailX - curtainRailX3;
  249. long curtainY = windowY * 0.9;
  250.  
  251. long curtainX1 = curtainRailX1 + curtainRailY / 2;
  252. long curtainX2 = curtainX1 + curtainX;
  253. long curtainY1 = curtainRailY2;
  254. long curtainY2 = curtainY1 + curtainY;
  255.  
  256. CPoint curtain[4];
  257. curtain[0] = CPoint(curtainX2, curtainY2);
  258. curtain[1] = CPoint(curtainX2, curtainY1);
  259. curtain[2] = CPoint(curtainX1, curtainY1);
  260. curtain[3] = CPoint(curtainX1, curtainY2);
  261.  
  262. CPoint bezier[3];
  263. bezier[0] = CPoint(curtainX1 + curtainX / 4, curtainY2 - 35);
  264. bezier[1] = CPoint(curtainX2 - curtainX / 4, curtainY2 + 35);
  265. bezier[2] = CPoint(curtainX2, curtainY2);
  266.  
  267. pDC->BeginPath();
  268. //pDC->Rectangle(curtainX1, curtainY1, curtainX2, curtainY2);
  269. pDC->MoveTo(curtainX2, curtainY2);
  270. pDC->PolylineTo(curtain, 4);
  271. pDC->PolyBezierTo(bezier, 3);
  272. pDC->EndPath();
  273.  
  274. pDC->StrokeAndFillPath();
  275.  
  276. delete yellowBrush;
  277.  
  278. pDC->SelectObject(oldBrush);
  279. }
  280.  
  281. void DrawHandle(CDC* pDC, long x, long y) {
  282. CBrush* orangeBrush = new CBrush(RGB(235, 154, 0));
  283. CBrush* oldBrush = pDC->SelectObject(orangeBrush);
  284.  
  285. pDC->Ellipse(x, y, x + 14, y + 10);
  286.  
  287. delete orangeBrush;
  288.  
  289. pDC->SelectObject(oldBrush);
  290. }
  291.  
  292. void DrawWardrobe(CDC* pDC, CRect window, bool isSideOpen, bool isKeyFound, HENHMETAFILE keyMeta) {
  293. CBrush* brownBrush = new CBrush(RGB(132, 99, 66));
  294. CBrush* oldBrush = pDC->SelectObject(brownBrush);
  295.  
  296. // wardrobe
  297.  
  298. long topOffset = window.bottom * 0.2;
  299. long leftOffset = window.right * 0.05;
  300. long wardrobeX = window.right * 0.15;
  301. long wardrobeY = window.bottom * 0.75;
  302. long wardrobeScaledY = wardrobeY * 0.9;
  303. long wardrobeScaledX = window.right * 0.05;
  304.  
  305. long wardrobeX1 = leftOffset;
  306. long wardrobeX2 = wardrobeX1 + wardrobeX;
  307. long wardrobeY1 = topOffset;
  308. long wardrobeY2 = wardrobeY1 + wardrobeY;
  309.  
  310. long wardrobeX3 = wardrobeX2 + wardrobeScaledX;
  311. long wardrobeY3 = wardrobeY1 + (wardrobeY - wardrobeScaledY) / 2;
  312. long wardrobeY4 = window.bottom * 0.9;
  313.  
  314. CPoint side[4];
  315. side[0] = CPoint(wardrobeX2, wardrobeY1);
  316. side[1] = CPoint(wardrobeX2, wardrobeY2);
  317. side[2] = CPoint(wardrobeX3, wardrobeY4);
  318. side[3] = CPoint(wardrobeX3, wardrobeY3);
  319.  
  320. pDC->Rectangle(wardrobeX1, wardrobeY1, wardrobeX2, wardrobeY2);
  321. pDC->Polygon(side, 4);
  322.  
  323. // cabinets
  324.  
  325. long spacingY = 10;
  326. long spacingX = 5;
  327. long doorY = wardrobeY * 0.6;
  328. long doorX = wardrobeX / 2 - spacingX;
  329. long drawerY = (wardrobeY - 4 * spacingY - doorY) / 2;
  330. long drawerX = wardrobeX - 2 * spacingX;
  331.  
  332. //left door
  333. if (!isSideOpen) {
  334. pDC->Rectangle(
  335. wardrobeX1 + spacingX,
  336. wardrobeY1 + spacingY,
  337. wardrobeX1 + spacingX + doorX,
  338. wardrobeY1 + spacingY + doorY
  339. );
  340. DrawHandle(pDC, wardrobeX1 + spacingX + doorX - 22, wardrobeY1 + spacingY + doorY / 2 - 5);
  341. }
  342. else {
  343.  
  344. pDC->SelectStockObject(BLACK_BRUSH);
  345.  
  346. pDC->Rectangle(
  347. wardrobeX1 + spacingX,
  348. wardrobeY1 + spacingY,
  349. wardrobeX1 + spacingX + doorX,
  350. wardrobeY1 + spacingY + doorY
  351. );
  352.  
  353. pDC->SelectObject(brownBrush);
  354.  
  355. CPoint openDoor[4];
  356. openDoor[0] = CPoint(wardrobeX1 + spacingX, wardrobeY1 + spacingY);
  357. openDoor[1] = CPoint(wardrobeX1 + spacingX, wardrobeY1 + spacingY + doorY);
  358. openDoor[2] = CPoint(wardrobeX1 + spacingX - doorX * 0.7, wardrobeY1 + 2 * spacingY + doorY);
  359. openDoor[3] = CPoint(wardrobeX1 + spacingX - doorX * 0.7, wardrobeY1);
  360.  
  361. pDC->Polygon(openDoor, 4);
  362.  
  363. if (!isKeyFound) {
  364. CRect keyPos = CRect(
  365. wardrobeX1 + spacingX + doorX * 0.15,
  366. wardrobeY1 + spacingY + doorY - doorX * 0.15 - doorX * 0.7,
  367. wardrobeX1 + spacingX + doorX * 0.85,
  368. wardrobeY1 + spacingY + doorY - doorX * 0.15
  369. );
  370. pDC->PlayMetaFile(keyMeta, keyPos);
  371. }
  372. }
  373.  
  374.  
  375. //right door
  376.  
  377. pDC->Rectangle(
  378. wardrobeX2 - spacingX - doorX,
  379. wardrobeY1 + spacingY,
  380. wardrobeX2 - spacingX,
  381. wardrobeY1 + spacingY + doorY
  382. );
  383.  
  384. DrawHandle(pDC, wardrobeX1 + spacingX + doorX + 8, wardrobeY1 + spacingY + doorY / 2 - 5);
  385.  
  386. // first drawer
  387.  
  388. pDC->Rectangle(
  389. wardrobeX1 + spacingX,
  390. wardrobeY1 + 2 * spacingY + doorY,
  391. wardrobeX1 + spacingX + drawerX,
  392. wardrobeY1 + 2 * spacingY + doorY + drawerY
  393. );
  394.  
  395. DrawHandle(pDC, wardrobeX1 + spacingX + drawerX / 2 - 7, wardrobeY1 + 2 * spacingY + doorY + drawerY / 2 - 5);
  396.  
  397. //second drawer
  398.  
  399. pDC->Rectangle(
  400. wardrobeX1 + spacingX,
  401. wardrobeY2 - spacingY - drawerY,
  402. wardrobeX1 + spacingX + drawerX,
  403. wardrobeY2 - spacingY
  404. );
  405.  
  406. DrawHandle(pDC, wardrobeX1 + spacingX + drawerX / 2 - 7, wardrobeY1 + 3 * spacingY + doorY + drawerY + drawerY / 2 - 5);
  407.  
  408. pDC->SelectObject(brownBrush);
  409.  
  410. delete brownBrush;
  411. }
  412.  
  413. void DrawInventory(CDC* pDC, CRect window, HENHMETAFILE keyMeta, bool isKeyFound) {
  414. CBrush* oldBrush = (CBrush*) pDC->SelectStockObject(LTGRAY_BRUSH);
  415.  
  416.  
  417. long offsetX = window.right * 0.01;
  418. long offsetY = window.bottom * 0.01;
  419. long invX = window.right * 0.08;
  420. long invY = window.bottom * 0.08;
  421.  
  422. pDC->RoundRect(
  423. offsetX,
  424. offsetY,
  425. offsetX + invX,
  426. offsetY + invY,
  427. 5,
  428. 5
  429. );
  430.  
  431. if (isKeyFound) {
  432. CRect keyPos = CRect(
  433. offsetX + invX * 0.1,
  434. offsetY + invY * 0.1,
  435. offsetX + invX * 0.9,
  436. offsetY + invY * 0.9
  437. );
  438. pDC->PlayMetaFile(keyMeta, keyPos);
  439. }
  440.  
  441. pDC->SelectObject(oldBrush);
  442. }
  443.  
  444. void CRGLab1View::SetBitmapTransform(CDC* pDC, float cx, float cy, float bw, float bh, float scale, float alpha, bool mirror, XFORM* oldXForm) {
  445.  
  446.  
  447. XFORM preT, rotation, postT, mirrorT, translate2;
  448. GetWorldTransform(pDC->m_hDC, oldXForm);
  449.  
  450. preT.eDx = -bw * scale / 2;
  451. preT.eDy = -bh * scale / 2;
  452. preT.eM11 = 1;
  453. preT.eM12 = 0;
  454. preT.eM21 = 0;
  455. preT.eM22 = 1;
  456.  
  457. rotation.eDx = 0;
  458. rotation.eDy = 0;
  459. rotation.eM11 = cos(alpha);
  460. rotation.eM12 = sin(alpha);
  461. rotation.eM21 = -sin(alpha);
  462. rotation.eM22 = cos(alpha);
  463.  
  464. mirrorT.eDx = 0;
  465. mirrorT.eDy = 0;
  466. mirrorT.eM11 = -1;
  467. mirrorT.eM12 = 0;
  468. mirrorT.eM21 = 0;
  469. mirrorT.eM22 = 1;
  470.  
  471. postT.eDx = bw * scale / 2;
  472. postT.eDy = bh * scale / 2;
  473. postT.eM11 = 1;
  474. postT.eM12 = 0;
  475. postT.eM21 = 0;
  476. postT.eM22 = 1;
  477.  
  478. translate2.eDx = cx;
  479. translate2.eDy = cy;
  480. translate2.eM11 = 1;
  481. translate2.eM12 = 0;
  482. translate2.eM21 = 0;
  483. translate2.eM22 = 1;
  484.  
  485. SetWorldTransform(pDC->m_hDC, &preT);
  486. ModifyWorldTransform(pDC->m_hDC, &rotation, MWT_RIGHTMULTIPLY);
  487. if (mirror) {
  488. ModifyWorldTransform(pDC->m_hDC, &mirrorT, MWT_RIGHTMULTIPLY);
  489. }
  490. ModifyWorldTransform(pDC->m_hDC, &postT, MWT_RIGHTMULTIPLY);
  491. ModifyWorldTransform(pDC->m_hDC, &translate2, MWT_RIGHTMULTIPLY);
  492.  
  493. }
  494.  
  495. void CRGLab1View::SetBitmapRGBFilter(CBitmap* bmp, bool r, bool g, bool b) {
  496. uint32_t filter;
  497. if (r) {
  498. filter = (uint32_t)16711680;
  499. }
  500. else if (g) {
  501. filter = (uint32_t)65280;
  502. }
  503. else if (b) {
  504. filter = (uint32_t)255;
  505. }
  506. else {
  507. filter = INT32_MAX;
  508. }
  509.  
  510.  
  511. BITMAP bm;
  512. bmp->GetBitmap(&bm);
  513. int size = bm.bmHeight * bm.bmWidth * bm.bmBitsPixel;
  514. uint32_t* buffer = new uint32_t[size];
  515. bmp->GetBitmapBits(size, buffer);
  516. for (int i = 0; i < size; i++) {
  517. buffer[i] = buffer[i] & (uint32_t)filter;
  518. }
  519. bmp->SetBitmapBits(size, buffer);
  520.  
  521. }
  522.  
  523. void CRGLab1View::DrawBitmap(CDC* pDC, int x, int y, float scale, CString name) {
  524. DImage image;
  525. image.Load(name);
  526.  
  527. image.Draw(pDC, CRect(0, 0, image.Width(), image.Height()), CRect(x, y, x + image.Width() * scale, y + image.Height() * scale));
  528. }
  529.  
  530. void CRGLab1View::DrawTransparentBitmap(CDC* pDC, int x, int y, float scale, bool r, bool g, bool b, CString name) {
  531. DImage image;
  532. CBitmap bitmapa;
  533. image.Load(name);
  534. int size = image.BPP() * image.Width() * image.Height();
  535.  
  536. bitmapa.CreateCompatibleBitmap(pDC, image.Width(), image.Height());
  537. bitmapa.SetBitmapBits(size, image.GetDIBBits());
  538.  
  539. SetBitmapRGBFilter(&bitmapa, r, g, b);
  540.  
  541. CBitmap mask;
  542. BITMAP bm;
  543. bitmapa.GetBitmap(&bm);
  544.  
  545. mask.CreateBitmap(bm.bmWidth, bm.bmHeight, 1, 1, NULL);
  546.  
  547. CDC* SrcDC = new CDC();
  548. SrcDC->CreateCompatibleDC(NULL);
  549. CDC* DstDC = new CDC();
  550. DstDC->CreateCompatibleDC(NULL);
  551.  
  552. CBitmap* pOldSrcBmp = SrcDC->SelectObject(&bitmapa);
  553. CBitmap* pOldDstBmp = DstDC->SelectObject(&mask);
  554.  
  555. COLORREF clrTopLeft = SrcDC->GetPixel(0, 0);
  556. COLORREF clrSaveBk = SrcDC->SetBkColor(clrTopLeft);
  557.  
  558. DstDC->BitBlt(0, 0, bm.bmWidth, bm.bmHeight, SrcDC, 0, 0, SRCCOPY);
  559.  
  560. COLORREF clrSaveDstText = SrcDC->SetTextColor(RGB(255, 255, 255));
  561. SrcDC->SetBkColor(RGB(0, 0, 0));
  562. SrcDC->BitBlt(0, 0, bm.bmWidth, bm.bmHeight, DstDC, 0, 0, SRCAND);
  563.  
  564. DstDC->SetTextColor(clrSaveDstText);
  565. SrcDC->SetBkColor(clrSaveBk);
  566. SrcDC->SelectObject(pOldSrcBmp);
  567. DstDC->SelectObject(pOldDstBmp);
  568.  
  569. CDC* MemDC = new CDC();
  570. MemDC->CreateCompatibleDC(NULL);
  571. CBitmap* bmpOldT = MemDC->SelectObject(&mask);
  572. pDC->StretchBlt(0, 0, bm.bmWidth * scale, bm.bmHeight * scale, MemDC, 0, 0, bm.bmWidth, bm.bmHeight, SRCAND);
  573.  
  574. MemDC->SelectObject(&bitmapa);
  575. pDC->StretchBlt(0, 0, bm.bmWidth * scale, bm.bmHeight * scale, MemDC, 0, 0, bm.bmWidth, bm.bmHeight, SRCPAINT);
  576.  
  577. //pDC->StretchBlt(x, y, x + bm.bmWidth * scale, y + bm.bmHeight * scale, MemDC, 0, 0, bm.bmWidth, bm.bmHeight, SRCPAINT);
  578. MemDC->SelectObject(bmpOldT);
  579. MemDC->DeleteDC();
  580. delete MemDC;
  581.  
  582. //DImage image1 = DImage(bitmapa);
  583. //image1.Draw(pDC, CRect(0, 0, image1.Width(), image1.Height()), CRect(x, y, x + image1.Width() * scale, y + image1.Height() * scale));
  584. }
  585.  
  586. void CRGLab1View::DrawPuzzlePart(CDC* pDC, int x, int y, float scale, float angle, bool mirror, bool r, bool g, bool b, CString name) {
  587. int prevMode = SetGraphicsMode(pDC->m_hDC, GM_ADVANCED);
  588. DWORD dw = GetLastError();
  589. XFORM oldXForm;
  590.  
  591. DImage image;
  592. image.Load(name);
  593.  
  594. SetBitmapTransform(pDC, x, y, image.Width(), image.Height(), scale, angle, mirror, &oldXForm);
  595.  
  596. DrawTransparentBitmap(pDC, x, y, scale, r, g, b, name);
  597.  
  598. SetWorldTransform(pDC->m_hDC, &oldXForm);
  599. SetGraphicsMode(pDC->m_hDC, prevMode);
  600. }
  601.  
  602.  
  603. void CRGLab1View::OnDraw(CDC* pDC)
  604. {
  605. CRGLab1Doc* pDoc = GetDocument();
  606. ASSERT_VALID(pDoc);
  607. if (!pDoc)
  608. return;
  609.  
  610. // TODO: add draw code for native data here
  611.  
  612. CPen* newPen = new CPen(PS_SOLID, 2, RGB(71, 8, 0));
  613. CPen* oldPen = pDC->SelectObject(newPen);
  614.  
  615. CRect window;
  616. GetClientRect(&window);
  617.  
  618. CString path = CString("res/Key.emf");
  619. HENHMETAFILE keyMeta = GetEnhMetaFile(path);
  620.  
  621. DrawWalls(pDC, window);
  622. DrawWindow(pDC, window);
  623. DrawWardrobe(pDC, window, isSideOpen, isKeyFound, keyMeta);
  624. DrawInventory(pDC, window, keyMeta, isKeyFound);
  625.  
  626. DrawBitmap(pDC, window.right * 0.7, window.bottom * 0.15, 0.5, CString("res/Ram.bmp"));
  627. DrawPuzzlePart(pDC, window.right * 0.7, window.bottom * 0.15 + 15, 0.5, 0, false, r, g, b, CString("res/part1.bmp"));
  628. DrawPuzzlePart(pDC, window.right * 0.7 + 67, window.bottom * 0.15 + 22, 0.5, (3.14 * 1.81), false, r, g, b, CString("res/part2.bmp"));
  629. DrawPuzzlePart(pDC, window.right * 0.7 - 9, window.bottom * 0.15 + 130, 0.5, (3.14 / 1.56), false, r, g, b, CString("res/part3.bmp"));
  630. DrawPuzzlePart(pDC, window.right * 0.7 + 65, window.bottom * 0.15 + 138, 0.5, (3.14 / 3.05), true, r, g, b, CString("res/part4.bmp"));
  631.  
  632.  
  633. DrawDoor(pDC, window, isDoorOpen, keyMeta);
  634.  
  635.  
  636.  
  637. pDC->SelectObject(oldPen);
  638. delete newPen;
  639. }
  640.  
  641.  
  642. // CRGLab1View printing
  643.  
  644. BOOL CRGLab1View::OnPreparePrinting(CPrintInfo* pInfo)
  645. {
  646. // default preparation
  647. return DoPreparePrinting(pInfo);
  648. }
  649.  
  650. void CRGLab1View::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
  651. {
  652. // TODO: add extra initialization before printing
  653. }
  654.  
  655. void CRGLab1View::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
  656. {
  657. // TODO: add cleanup after printing
  658. }
  659.  
  660.  
  661. // CRGLab1View diagnostics
  662.  
  663. #ifdef _DEBUG
  664. void CRGLab1View::AssertValid() const
  665. {
  666. CView::AssertValid();
  667. }
  668.  
  669. void CRGLab1View::Dump(CDumpContext& dc) const
  670. {
  671. CView::Dump(dc);
  672. }
  673.  
  674. CRGLab1Doc* CRGLab1View::GetDocument() const // non-debug version is inline
  675. {
  676. ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CRGLab1Doc)));
  677. return (CRGLab1Doc*)m_pDocument;
  678. }
  679. #endif //_DEBUG
  680.  
  681.  
  682. // CRGLab1View message handlers
  683.  
  684.  
  685. void CRGLab1View::OnLButtonDown(UINT nFlags, CPoint point)
  686. {
  687. // TODO: Add your message handler code here and/or call default
  688.  
  689. CView::OnLButtonDown(nFlags, point);
  690.  
  691. CRgn wardrobeDoor, key, door;
  692.  
  693. CRect window;
  694. GetClientRect(&window);
  695.  
  696. // wardrobe door
  697.  
  698. wardrobeDoor.CreateRectRgn(
  699. window.right * 0.05 + 5,
  700. window.bottom * 0.2 + 10,
  701. window.right * 0.05 + 5 + (window.right * 0.2) /2 - 5,
  702. window.bottom * 0.2 + 10 + (window.bottom * 0.75) * 0.6
  703. );
  704.  
  705. // key
  706.  
  707. key.CreateRectRgn(
  708. window.right * 0.05 + 5 + (window.right * 0.15 / 2 - 5) * 0.15,
  709. window.bottom * 0.2 + 10 + (window.bottom * 0.75) * 0.6 - (window.right * 0.15 / 2 - 5) * 0.15 - (window.right * 0.15 / 2 - 5) * 0.7,
  710. window.right * 0.05 + 5 + (window.right * 0.15 / 2 - 5) * 0.85,
  711. window.bottom * 0.2 + 10 + (window.bottom * 0.75) * 0.6 - (window.right * 0.15 / 2 - 5) * 0.15
  712. );
  713.  
  714. if (wardrobeDoor.PtInRegion(point)) {
  715. if (!isSideOpen) {
  716. isSideOpen = true;
  717. Invalidate();
  718. }
  719. else if (key.PtInRegion(point) && !isKeyFound) {
  720. isKeyFound = true;
  721. Invalidate();
  722. }
  723. }
  724.  
  725. // door
  726. long offsetX = window.right*0.1*0.1;
  727. long offsetY = window.bottom*0.1*0.1;
  728. CPoint doorPoints[4];
  729. doorPoints[0] = CPoint(window.right - offsetX, window.bottom*0.15);
  730. doorPoints[1] = CPoint(window.right*0.9 + offsetX, window.bottom*0.2);
  731. doorPoints[2] = CPoint(window.right*0.9 + offsetX, window.bottom*0.9 + offsetY);
  732. doorPoints[3] = CPoint(window.right - offsetX, window.bottom - offsetY);
  733. door.CreatePolygonRgn(doorPoints, 4, WINDING);
  734.  
  735. if (door.PtInRegion(point) && isKeyFound) {
  736. isDoorOpen = true;
  737. Invalidate();
  738. }
  739.  
  740. wardrobeDoor.DeleteObject();
  741.  
  742. }
  743.  
  744.  
  745. void CRGLab1View::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
  746. {
  747. // TODO: Add your message handler code here and/or call default
  748.  
  749. if (nChar == 'R') {
  750. r = !r;
  751. g = false;
  752. b = false;
  753. Invalidate(FALSE);
  754. }
  755.  
  756. if (nChar == 'G') {
  757. r = false;
  758. g = !g;
  759. b = false;
  760. Invalidate(FALSE);
  761. }
  762.  
  763. if (nChar == 'B') {
  764. r = false;
  765. g = false;
  766. b = !b;
  767. Invalidate(FALSE);
  768. }
  769.  
  770. CView::OnKeyDown(nChar, nRepCnt, nFlags);
  771. }
  772.  
  773.  
  774. BOOL CRGLab1View::OnEraseBkgnd(CDC* pDC)
  775. {
  776. // TODO: Add your message handler code here and/or call default
  777.  
  778. return CView::OnEraseBkgnd(pDC);
  779. //return true;
  780. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement