Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // RGLab1View.cpp : implementation of the CRGLab1View class
- //
- #include "stdafx.h"
- // SHARED_HANDLERS can be defined in an ATL project implementing preview, thumbnail
- // and search filter handlers and allows sharing of document code with that project.
- #ifndef SHARED_HANDLERS
- #include "RGLab1.h"
- #include "resource.h"
- #include "DImage.h"
- #include <stdint.h>
- #endif
- #include "RGLab1Doc.h"
- #include "RGLab1View.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #endif
- // CRGLab1View
- IMPLEMENT_DYNCREATE(CRGLab1View, CView)
- BEGIN_MESSAGE_MAP(CRGLab1View, CView)
- // Standard printing commands
- ON_COMMAND(ID_FILE_PRINT, &CView::OnFilePrint)
- ON_COMMAND(ID_FILE_PRINT_DIRECT, &CView::OnFilePrint)
- ON_COMMAND(ID_FILE_PRINT_PREVIEW, &CView::OnFilePrintPreview)
- ON_WM_LBUTTONDOWN()
- ON_WM_KEYDOWN()
- ON_WM_ERASEBKGND()
- END_MESSAGE_MAP()
- // CRGLab1View construction/destruction
- CRGLab1View::CRGLab1View() noexcept
- {
- // TODO: add construction code here
- isSideOpen = false;
- isKeyFound = false;
- isDoorOpen = false;
- r = b = g = false;
- }
- CRGLab1View::~CRGLab1View()
- {
- }
- BOOL CRGLab1View::PreCreateWindow(CREATESTRUCT& cs)
- {
- // TODO: Modify the Window class or styles here by modifying
- // the CREATESTRUCT cs
- return CView::PreCreateWindow(cs);
- }
- // CRGLab1View drawing
- void DrawWalls(CDC* pDC, CRect window)
- {
- // front wall
- CBrush* orangeBrush = new CBrush(RGB(255, 191, 127));
- CBrush* oldBrush = pDC->SelectObject(orangeBrush);
- pDC->Rectangle(window.right*0.1, window.bottom*0.1, window.right*0.9, window.bottom*0.9);
- delete orangeBrush;
- // left and right walls
- CBrush* brownBrush = new CBrush(RGB(195, 147, 98));
- pDC->SelectObject(brownBrush);
- CPoint leftWall[4];
- leftWall[0] = CPoint(0, 0);
- leftWall[1] = CPoint(window.right*0.1, window.bottom*0.1);
- leftWall[2] = CPoint(window.right*0.1, window.bottom*0.9);
- leftWall[3] = CPoint(0, window.bottom);
- pDC->Polygon(leftWall, 4);
- CPoint rightWall[4];
- rightWall[0] = CPoint(window.right, 0);
- rightWall[1] = CPoint(window.right*0.9, window.bottom*0.1);
- rightWall[2] = CPoint(window.right*0.9, window.bottom*0.9);
- rightWall[3] = CPoint(window.right, window.bottom);
- pDC->Polygon(rightWall, 4);
- delete brownBrush;
- // ceiling
- pDC->SelectStockObject(WHITE_BRUSH);
- CPoint ceiling[4];
- ceiling[0] = CPoint(0, 0);
- ceiling[1] = CPoint(window.right*0.1, window.bottom*0.1);
- ceiling[2] = CPoint(window.right*0.9, window.bottom*0.1);
- ceiling[3] = CPoint(window.right, 0);
- pDC->Polygon(ceiling, 4);
- // floor
- pDC->SelectStockObject(LTGRAY_BRUSH);
- CPoint floor[4];
- floor[0] = CPoint(0, window.bottom);
- floor[1] = CPoint(window.right*0.1, window.bottom*0.9);
- floor[2] = CPoint(window.right*0.9, window.bottom*0.9);
- floor[3] = CPoint(window.right, window.bottom);
- pDC->Polygon(floor, 4);
- //end
- pDC->SelectObject(oldBrush);
- }
- void DrawDoor(CDC* pDC, CRect window, bool isDoorOpen, HENHMETAFILE keyMeta){
- // door
- CBrush* brownBrush = new CBrush(RGB(132, 99, 66));
- CBrush* oldBrush = pDC->SelectObject(brownBrush);
- long offsetX = window.right*0.1*0.1;
- long offsetY = window.bottom*0.1*0.1;
- if (!isDoorOpen) {
- CPoint door[4];
- door[0] = CPoint(window.right - offsetX, window.bottom*0.15);
- door[1] = CPoint(window.right*0.9 + offsetX, window.bottom*0.2);
- door[2] = CPoint(window.right*0.9 + offsetX, window.bottom*0.9 + offsetY);
- door[3] = CPoint(window.right - offsetX, window.bottom - offsetY);
- pDC->Polygon(door, 4);
- // doorknob
- CBrush* orangeBrush = new CBrush(RGB(235, 154, 0));
- pDC->SelectObject(orangeBrush);
- 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);
- 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);
- delete orangeBrush;
- // keyhole
- pDC->SelectStockObject(BLACK_BRUSH);
- 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
- + 28);
- }
- else {
- long doorX = window.right * 0.2;
- pDC->Rectangle(
- window.right*0.9 + offsetX - doorX,
- window.bottom*0.2,
- window.right*0.9 + offsetX,
- window.bottom*0.9 + offsetY
- );
- CBrush* oldBrownBrush = (CBrush*)pDC->SelectStockObject(BLACK_BRUSH);
- CPoint door[4];
- door[0] = CPoint(window.right - offsetX, window.bottom*0.15);
- door[1] = CPoint(window.right*0.9 + offsetX, window.bottom*0.2);
- door[2] = CPoint(window.right*0.9 + offsetX, window.bottom*0.9 + offsetY);
- door[3] = CPoint(window.right - offsetX, window.bottom - offsetY);
- pDC->Polygon(door, 4);
- pDC->SelectObject(oldBrownBrush);
- }
- pDC->SelectObject(oldBrush);
- }
- void DrawGlass(CDC* pDC, long x1, long y1, long x2, long y2) {
- CBrush* blueBrush = new CBrush(RGB(0, 186, 219));
- CBrush* oldBrush = pDC->SelectObject(blueBrush);
- pDC->Rectangle(x1, y1, x2, y2);
- pDC->SelectObject(oldBrush);
- }
- void DrawWindow(CDC* pDC, CRect window) {
- // curtain...something
- long leftWallX = window.right * 0.1;
- long frontWallX = window.right * 0.8;
- long curtainRailX = frontWallX * 0.4;
- long curtainRailX1 = leftWallX + (frontWallX - curtainRailX) / 2;
- long curtainRailX2 = curtainRailX1 + curtainRailX;
- long topWallX = window.bottom * 0.1;
- long railOffsetY = window.bottom * 0.05;
- long curtainRailY = window.bottom * 0.05;
- long curtainRailY1 = topWallX + railOffsetY;
- long curtainRailY2 = curtainRailY1 + curtainRailY;
- long curtainRailY3 = curtainRailY;
- long curtainRailX3 = curtainRailY;
- CBrush* brownBrush = new CBrush(RGB(132, 99, 66));
- CBrush* oldBrush = pDC->SelectObject(brownBrush);
- pDC->RoundRect(curtainRailX1, curtainRailY1, curtainRailX2, curtainRailY2, curtainRailY, curtainRailY);
- // window
- long windowOffsetX = 10;
- long windowX = curtainRailX - curtainRailX3 - 2 * windowOffsetX; // subtract the rounded area
- long windowX1 = curtainRailX1 + curtainRailY / 2 + windowOffsetX;
- long windowX2 = windowX1 + windowX;
- long windowY = window.bottom * 0.45;
- long windowY1 = curtainRailY2;
- long windowY2 = windowY1 + windowY;
- pDC->Rectangle(windowX1, windowY1, windowX2, windowY2);
- delete brownBrush;
- // glass
- long glassOffsetX = 5;
- long glassOffsetY = 10;
- long glassX = (windowX - 3 * glassOffsetX) / 2;
- long glassY = windowY - 2 * glassOffsetY;
- long leftGlassX1 = windowX1 + glassOffsetX;
- long leftGlassX2 = leftGlassX1 + glassX;
- long leftGlassY1 = windowY1 + glassOffsetY;
- long leftGlassY2 = leftGlassY1 + glassY;
- long rightGlassX1 = leftGlassX2 + glassOffsetX;
- long rightGlassX2 = rightGlassX1 + glassX;
- long rightGlassY1 = windowY1 + glassOffsetY;
- long rightGlassY2 = rightGlassY1 + glassY;
- DrawGlass(pDC, leftGlassX1, leftGlassY1, leftGlassX2, leftGlassY2);
- DrawGlass(pDC, rightGlassX1, rightGlassY1, rightGlassX2, rightGlassY2);
- // curtain
- CBrush* yellowBrush = new CBrush(RGB(249, 254, 160));
- pDC->SelectObject(yellowBrush);
- long curtainX = curtainRailX - curtainRailX3;
- long curtainY = windowY * 0.9;
- long curtainX1 = curtainRailX1 + curtainRailY / 2;
- long curtainX2 = curtainX1 + curtainX;
- long curtainY1 = curtainRailY2;
- long curtainY2 = curtainY1 + curtainY;
- CPoint curtain[4];
- curtain[0] = CPoint(curtainX2, curtainY2);
- curtain[1] = CPoint(curtainX2, curtainY1);
- curtain[2] = CPoint(curtainX1, curtainY1);
- curtain[3] = CPoint(curtainX1, curtainY2);
- CPoint bezier[3];
- bezier[0] = CPoint(curtainX1 + curtainX / 4, curtainY2 - 35);
- bezier[1] = CPoint(curtainX2 - curtainX / 4, curtainY2 + 35);
- bezier[2] = CPoint(curtainX2, curtainY2);
- pDC->BeginPath();
- //pDC->Rectangle(curtainX1, curtainY1, curtainX2, curtainY2);
- pDC->MoveTo(curtainX2, curtainY2);
- pDC->PolylineTo(curtain, 4);
- pDC->PolyBezierTo(bezier, 3);
- pDC->EndPath();
- pDC->StrokeAndFillPath();
- delete yellowBrush;
- pDC->SelectObject(oldBrush);
- }
- void DrawHandle(CDC* pDC, long x, long y) {
- CBrush* orangeBrush = new CBrush(RGB(235, 154, 0));
- CBrush* oldBrush = pDC->SelectObject(orangeBrush);
- pDC->Ellipse(x, y, x + 14, y + 10);
- delete orangeBrush;
- pDC->SelectObject(oldBrush);
- }
- void DrawWardrobe(CDC* pDC, CRect window, bool isSideOpen, bool isKeyFound, HENHMETAFILE keyMeta) {
- CBrush* brownBrush = new CBrush(RGB(132, 99, 66));
- CBrush* oldBrush = pDC->SelectObject(brownBrush);
- // wardrobe
- long topOffset = window.bottom * 0.2;
- long leftOffset = window.right * 0.05;
- long wardrobeX = window.right * 0.15;
- long wardrobeY = window.bottom * 0.75;
- long wardrobeScaledY = wardrobeY * 0.9;
- long wardrobeScaledX = window.right * 0.05;
- long wardrobeX1 = leftOffset;
- long wardrobeX2 = wardrobeX1 + wardrobeX;
- long wardrobeY1 = topOffset;
- long wardrobeY2 = wardrobeY1 + wardrobeY;
- long wardrobeX3 = wardrobeX2 + wardrobeScaledX;
- long wardrobeY3 = wardrobeY1 + (wardrobeY - wardrobeScaledY) / 2;
- long wardrobeY4 = window.bottom * 0.9;
- CPoint side[4];
- side[0] = CPoint(wardrobeX2, wardrobeY1);
- side[1] = CPoint(wardrobeX2, wardrobeY2);
- side[2] = CPoint(wardrobeX3, wardrobeY4);
- side[3] = CPoint(wardrobeX3, wardrobeY3);
- pDC->Rectangle(wardrobeX1, wardrobeY1, wardrobeX2, wardrobeY2);
- pDC->Polygon(side, 4);
- // cabinets
- long spacingY = 10;
- long spacingX = 5;
- long doorY = wardrobeY * 0.6;
- long doorX = wardrobeX / 2 - spacingX;
- long drawerY = (wardrobeY - 4 * spacingY - doorY) / 2;
- long drawerX = wardrobeX - 2 * spacingX;
- //left door
- if (!isSideOpen) {
- pDC->Rectangle(
- wardrobeX1 + spacingX,
- wardrobeY1 + spacingY,
- wardrobeX1 + spacingX + doorX,
- wardrobeY1 + spacingY + doorY
- );
- DrawHandle(pDC, wardrobeX1 + spacingX + doorX - 22, wardrobeY1 + spacingY + doorY / 2 - 5);
- }
- else {
- pDC->SelectStockObject(BLACK_BRUSH);
- pDC->Rectangle(
- wardrobeX1 + spacingX,
- wardrobeY1 + spacingY,
- wardrobeX1 + spacingX + doorX,
- wardrobeY1 + spacingY + doorY
- );
- pDC->SelectObject(brownBrush);
- CPoint openDoor[4];
- openDoor[0] = CPoint(wardrobeX1 + spacingX, wardrobeY1 + spacingY);
- openDoor[1] = CPoint(wardrobeX1 + spacingX, wardrobeY1 + spacingY + doorY);
- openDoor[2] = CPoint(wardrobeX1 + spacingX - doorX * 0.7, wardrobeY1 + 2 * spacingY + doorY);
- openDoor[3] = CPoint(wardrobeX1 + spacingX - doorX * 0.7, wardrobeY1);
- pDC->Polygon(openDoor, 4);
- if (!isKeyFound) {
- CRect keyPos = CRect(
- wardrobeX1 + spacingX + doorX * 0.15,
- wardrobeY1 + spacingY + doorY - doorX * 0.15 - doorX * 0.7,
- wardrobeX1 + spacingX + doorX * 0.85,
- wardrobeY1 + spacingY + doorY - doorX * 0.15
- );
- pDC->PlayMetaFile(keyMeta, keyPos);
- }
- }
- //right door
- pDC->Rectangle(
- wardrobeX2 - spacingX - doorX,
- wardrobeY1 + spacingY,
- wardrobeX2 - spacingX,
- wardrobeY1 + spacingY + doorY
- );
- DrawHandle(pDC, wardrobeX1 + spacingX + doorX + 8, wardrobeY1 + spacingY + doorY / 2 - 5);
- // first drawer
- pDC->Rectangle(
- wardrobeX1 + spacingX,
- wardrobeY1 + 2 * spacingY + doorY,
- wardrobeX1 + spacingX + drawerX,
- wardrobeY1 + 2 * spacingY + doorY + drawerY
- );
- DrawHandle(pDC, wardrobeX1 + spacingX + drawerX / 2 - 7, wardrobeY1 + 2 * spacingY + doorY + drawerY / 2 - 5);
- //second drawer
- pDC->Rectangle(
- wardrobeX1 + spacingX,
- wardrobeY2 - spacingY - drawerY,
- wardrobeX1 + spacingX + drawerX,
- wardrobeY2 - spacingY
- );
- DrawHandle(pDC, wardrobeX1 + spacingX + drawerX / 2 - 7, wardrobeY1 + 3 * spacingY + doorY + drawerY + drawerY / 2 - 5);
- pDC->SelectObject(brownBrush);
- delete brownBrush;
- }
- void DrawInventory(CDC* pDC, CRect window, HENHMETAFILE keyMeta, bool isKeyFound) {
- CBrush* oldBrush = (CBrush*) pDC->SelectStockObject(LTGRAY_BRUSH);
- long offsetX = window.right * 0.01;
- long offsetY = window.bottom * 0.01;
- long invX = window.right * 0.08;
- long invY = window.bottom * 0.08;
- pDC->RoundRect(
- offsetX,
- offsetY,
- offsetX + invX,
- offsetY + invY,
- 5,
- 5
- );
- if (isKeyFound) {
- CRect keyPos = CRect(
- offsetX + invX * 0.1,
- offsetY + invY * 0.1,
- offsetX + invX * 0.9,
- offsetY + invY * 0.9
- );
- pDC->PlayMetaFile(keyMeta, keyPos);
- }
- pDC->SelectObject(oldBrush);
- }
- void CRGLab1View::SetBitmapTransform(CDC* pDC, float cx, float cy, float bw, float bh, float scale, float alpha, bool mirror, XFORM* oldXForm) {
- XFORM preT, rotation, postT, mirrorT, translate2;
- GetWorldTransform(pDC->m_hDC, oldXForm);
- preT.eDx = -bw * scale / 2;
- preT.eDy = -bh * scale / 2;
- preT.eM11 = 1;
- preT.eM12 = 0;
- preT.eM21 = 0;
- preT.eM22 = 1;
- rotation.eDx = 0;
- rotation.eDy = 0;
- rotation.eM11 = cos(alpha);
- rotation.eM12 = sin(alpha);
- rotation.eM21 = -sin(alpha);
- rotation.eM22 = cos(alpha);
- mirrorT.eDx = 0;
- mirrorT.eDy = 0;
- mirrorT.eM11 = -1;
- mirrorT.eM12 = 0;
- mirrorT.eM21 = 0;
- mirrorT.eM22 = 1;
- postT.eDx = bw * scale / 2;
- postT.eDy = bh * scale / 2;
- postT.eM11 = 1;
- postT.eM12 = 0;
- postT.eM21 = 0;
- postT.eM22 = 1;
- translate2.eDx = cx;
- translate2.eDy = cy;
- translate2.eM11 = 1;
- translate2.eM12 = 0;
- translate2.eM21 = 0;
- translate2.eM22 = 1;
- SetWorldTransform(pDC->m_hDC, &preT);
- ModifyWorldTransform(pDC->m_hDC, &rotation, MWT_RIGHTMULTIPLY);
- if (mirror) {
- ModifyWorldTransform(pDC->m_hDC, &mirrorT, MWT_RIGHTMULTIPLY);
- }
- ModifyWorldTransform(pDC->m_hDC, &postT, MWT_RIGHTMULTIPLY);
- ModifyWorldTransform(pDC->m_hDC, &translate2, MWT_RIGHTMULTIPLY);
- }
- void CRGLab1View::SetBitmapRGBFilter(CBitmap* bmp, bool r, bool g, bool b) {
- uint32_t filter;
- if (r) {
- filter = (uint32_t)16711680;
- }
- else if (g) {
- filter = (uint32_t)65280;
- }
- else if (b) {
- filter = (uint32_t)255;
- }
- else {
- filter = INT32_MAX;
- }
- BITMAP bm;
- bmp->GetBitmap(&bm);
- int size = bm.bmHeight * bm.bmWidth * bm.bmBitsPixel;
- uint32_t* buffer = new uint32_t[size];
- bmp->GetBitmapBits(size, buffer);
- for (int i = 0; i < size; i++) {
- buffer[i] = buffer[i] & (uint32_t)filter;
- }
- bmp->SetBitmapBits(size, buffer);
- }
- void CRGLab1View::DrawBitmap(CDC* pDC, int x, int y, float scale, CString name) {
- DImage image;
- image.Load(name);
- image.Draw(pDC, CRect(0, 0, image.Width(), image.Height()), CRect(x, y, x + image.Width() * scale, y + image.Height() * scale));
- }
- void CRGLab1View::DrawTransparentBitmap(CDC* pDC, int x, int y, float scale, bool r, bool g, bool b, CString name) {
- DImage image;
- CBitmap bitmapa;
- image.Load(name);
- int size = image.BPP() * image.Width() * image.Height();
- bitmapa.CreateCompatibleBitmap(pDC, image.Width(), image.Height());
- bitmapa.SetBitmapBits(size, image.GetDIBBits());
- SetBitmapRGBFilter(&bitmapa, r, g, b);
- CBitmap mask;
- BITMAP bm;
- bitmapa.GetBitmap(&bm);
- mask.CreateBitmap(bm.bmWidth, bm.bmHeight, 1, 1, NULL);
- CDC* SrcDC = new CDC();
- SrcDC->CreateCompatibleDC(NULL);
- CDC* DstDC = new CDC();
- DstDC->CreateCompatibleDC(NULL);
- CBitmap* pOldSrcBmp = SrcDC->SelectObject(&bitmapa);
- CBitmap* pOldDstBmp = DstDC->SelectObject(&mask);
- COLORREF clrTopLeft = SrcDC->GetPixel(0, 0);
- COLORREF clrSaveBk = SrcDC->SetBkColor(clrTopLeft);
- DstDC->BitBlt(0, 0, bm.bmWidth, bm.bmHeight, SrcDC, 0, 0, SRCCOPY);
- COLORREF clrSaveDstText = SrcDC->SetTextColor(RGB(255, 255, 255));
- SrcDC->SetBkColor(RGB(0, 0, 0));
- SrcDC->BitBlt(0, 0, bm.bmWidth, bm.bmHeight, DstDC, 0, 0, SRCAND);
- DstDC->SetTextColor(clrSaveDstText);
- SrcDC->SetBkColor(clrSaveBk);
- SrcDC->SelectObject(pOldSrcBmp);
- DstDC->SelectObject(pOldDstBmp);
- CDC* MemDC = new CDC();
- MemDC->CreateCompatibleDC(NULL);
- CBitmap* bmpOldT = MemDC->SelectObject(&mask);
- pDC->StretchBlt(0, 0, bm.bmWidth * scale, bm.bmHeight * scale, MemDC, 0, 0, bm.bmWidth, bm.bmHeight, SRCAND);
- MemDC->SelectObject(&bitmapa);
- pDC->StretchBlt(0, 0, bm.bmWidth * scale, bm.bmHeight * scale, MemDC, 0, 0, bm.bmWidth, bm.bmHeight, SRCPAINT);
- //pDC->StretchBlt(x, y, x + bm.bmWidth * scale, y + bm.bmHeight * scale, MemDC, 0, 0, bm.bmWidth, bm.bmHeight, SRCPAINT);
- MemDC->SelectObject(bmpOldT);
- MemDC->DeleteDC();
- delete MemDC;
- //DImage image1 = DImage(bitmapa);
- //image1.Draw(pDC, CRect(0, 0, image1.Width(), image1.Height()), CRect(x, y, x + image1.Width() * scale, y + image1.Height() * scale));
- }
- void CRGLab1View::DrawPuzzlePart(CDC* pDC, int x, int y, float scale, float angle, bool mirror, bool r, bool g, bool b, CString name) {
- int prevMode = SetGraphicsMode(pDC->m_hDC, GM_ADVANCED);
- DWORD dw = GetLastError();
- XFORM oldXForm;
- DImage image;
- image.Load(name);
- SetBitmapTransform(pDC, x, y, image.Width(), image.Height(), scale, angle, mirror, &oldXForm);
- DrawTransparentBitmap(pDC, x, y, scale, r, g, b, name);
- SetWorldTransform(pDC->m_hDC, &oldXForm);
- SetGraphicsMode(pDC->m_hDC, prevMode);
- }
- void CRGLab1View::OnDraw(CDC* pDC)
- {
- CRGLab1Doc* pDoc = GetDocument();
- ASSERT_VALID(pDoc);
- if (!pDoc)
- return;
- // TODO: add draw code for native data here
- CPen* newPen = new CPen(PS_SOLID, 2, RGB(71, 8, 0));
- CPen* oldPen = pDC->SelectObject(newPen);
- CRect window;
- GetClientRect(&window);
- CString path = CString("res/Key.emf");
- HENHMETAFILE keyMeta = GetEnhMetaFile(path);
- DrawWalls(pDC, window);
- DrawWindow(pDC, window);
- DrawWardrobe(pDC, window, isSideOpen, isKeyFound, keyMeta);
- DrawInventory(pDC, window, keyMeta, isKeyFound);
- DrawBitmap(pDC, window.right * 0.7, window.bottom * 0.15, 0.5, CString("res/Ram.bmp"));
- DrawPuzzlePart(pDC, window.right * 0.7, window.bottom * 0.15 + 15, 0.5, 0, false, r, g, b, CString("res/part1.bmp"));
- 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"));
- 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"));
- 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"));
- DrawDoor(pDC, window, isDoorOpen, keyMeta);
- pDC->SelectObject(oldPen);
- delete newPen;
- }
- // CRGLab1View printing
- BOOL CRGLab1View::OnPreparePrinting(CPrintInfo* pInfo)
- {
- // default preparation
- return DoPreparePrinting(pInfo);
- }
- void CRGLab1View::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
- {
- // TODO: add extra initialization before printing
- }
- void CRGLab1View::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
- {
- // TODO: add cleanup after printing
- }
- // CRGLab1View diagnostics
- #ifdef _DEBUG
- void CRGLab1View::AssertValid() const
- {
- CView::AssertValid();
- }
- void CRGLab1View::Dump(CDumpContext& dc) const
- {
- CView::Dump(dc);
- }
- CRGLab1Doc* CRGLab1View::GetDocument() const // non-debug version is inline
- {
- ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CRGLab1Doc)));
- return (CRGLab1Doc*)m_pDocument;
- }
- #endif //_DEBUG
- // CRGLab1View message handlers
- void CRGLab1View::OnLButtonDown(UINT nFlags, CPoint point)
- {
- // TODO: Add your message handler code here and/or call default
- CView::OnLButtonDown(nFlags, point);
- CRgn wardrobeDoor, key, door;
- CRect window;
- GetClientRect(&window);
- // wardrobe door
- wardrobeDoor.CreateRectRgn(
- window.right * 0.05 + 5,
- window.bottom * 0.2 + 10,
- window.right * 0.05 + 5 + (window.right * 0.2) /2 - 5,
- window.bottom * 0.2 + 10 + (window.bottom * 0.75) * 0.6
- );
- // key
- key.CreateRectRgn(
- window.right * 0.05 + 5 + (window.right * 0.15 / 2 - 5) * 0.15,
- 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,
- window.right * 0.05 + 5 + (window.right * 0.15 / 2 - 5) * 0.85,
- window.bottom * 0.2 + 10 + (window.bottom * 0.75) * 0.6 - (window.right * 0.15 / 2 - 5) * 0.15
- );
- if (wardrobeDoor.PtInRegion(point)) {
- if (!isSideOpen) {
- isSideOpen = true;
- Invalidate();
- }
- else if (key.PtInRegion(point) && !isKeyFound) {
- isKeyFound = true;
- Invalidate();
- }
- }
- // door
- long offsetX = window.right*0.1*0.1;
- long offsetY = window.bottom*0.1*0.1;
- CPoint doorPoints[4];
- doorPoints[0] = CPoint(window.right - offsetX, window.bottom*0.15);
- doorPoints[1] = CPoint(window.right*0.9 + offsetX, window.bottom*0.2);
- doorPoints[2] = CPoint(window.right*0.9 + offsetX, window.bottom*0.9 + offsetY);
- doorPoints[3] = CPoint(window.right - offsetX, window.bottom - offsetY);
- door.CreatePolygonRgn(doorPoints, 4, WINDING);
- if (door.PtInRegion(point) && isKeyFound) {
- isDoorOpen = true;
- Invalidate();
- }
- wardrobeDoor.DeleteObject();
- }
- void CRGLab1View::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
- {
- // TODO: Add your message handler code here and/or call default
- if (nChar == 'R') {
- r = !r;
- g = false;
- b = false;
- Invalidate(FALSE);
- }
- if (nChar == 'G') {
- r = false;
- g = !g;
- b = false;
- Invalidate(FALSE);
- }
- if (nChar == 'B') {
- r = false;
- g = false;
- b = !b;
- Invalidate(FALSE);
- }
- CView::OnKeyDown(nChar, nRepCnt, nFlags);
- }
- BOOL CRGLab1View::OnEraseBkgnd(CDC* pDC)
- {
- // TODO: Add your message handler code here and/or call default
- return CView::OnEraseBkgnd(pDC);
- //return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement