int CDialog::Units_To_Pixels_X(int units) { RECT rect; rect.left = 0; rect.top = 0; rect.right = units; rect.bottom = units; if (!MapRect(&rect)) return units * 3 / 2; return rect.right - rect.left; }
void SetMargins(CDC * pDCPrint, CPrintInfo * pPrintInfo) { CRect * pRect = &pPrintInfo->m_rectDraw; int iOldMapMode = pDCPrint->SetMapMode(MM_LOMETRIC); CRect MapRect(0, 0, 100, -100); pDCPrint->LPtoDP(&MapRect); pDCPrint->SetMapMode(iOldMapMode); pDCPrint->DPtoLP(&MapRect); pRect->left += MapRect.right - MapRect.left; pRect->right -= MapRect.right - MapRect.left; pRect->top += MapRect.bottom - MapRect.top; pRect->bottom -= MapRect.bottom - MapRect.top; }
bool CDialog::GetMargins(int margin, int &x, int &y) { x = margin; y = margin; RECT rect; rect.left = 0; rect.top = 0; rect.right = margin; rect.bottom = margin; if (!MapRect(&rect)) return false; x = rect.right - rect.left; y = rect.bottom - rect.top; return true; }
void CMapGenerator::genZones() { editManager->clearTerrain(&rand); editManager->getTerrainSelection().selectRange(MapRect(int3(0, 0, 0), mapGenOptions->getWidth(), mapGenOptions->getHeight())); editManager->drawTerrain(ETerrainType::GRASS, &rand); auto tmpl = mapGenOptions->getMapTemplate(); zones = tmpl->getZones(); //copy from template (refactor?) CZonePlacer placer(this); placer.placeZones(mapGenOptions, &rand); placer.assignZones(mapGenOptions); logGlobal->infoStream() << "Zones generated successfully"; }
LRESULT CALLBACK MainWndProc(HWND HWnd, UINT Msg, WPARAM WParam, LPARAM LParam) { switch (Msg) { case WM_CREATE: { // create a memory DC HMemDC = CreateCompatibleDC(NULL); if (HMemDC) { // load the penguin bitmap HBITMAP HBmp = static_cast<HBITMAP>( LoadImage(HInst, filename, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE | LR_DEFAULTSIZE) ); if (HBmp) { // get the bitmap's dimensions BITMAP bmp; if (GetObject(HBmp, sizeof(BITMAP), &bmp)) { RImage.right += bmp.bmWidth; RImage.bottom += bmp.bmHeight; // realize the bitmap HOldBmp = static_cast<HBITMAP>( SelectObject(HMemDC, HBmp) ); } else DeleteObject(HBmp); } } break; } case WM_LBUTTONDOWN: { PMouse.x = LOWORD(LParam); PMouse.y = HIWORD(LParam); RECT RClient; if (PtInRect(&RImage, PMouse) && GetClientRect(HWnd, &RClient)) { MapRect(HWnd, HWND_DESKTOP, RClient); ClipCursor(&RClient); // grab a handle to the screen DC and clip // all output to the client area of our window HScreenDC = GetDC(NULL); HRGN HClipRgn = CreateRectRgnIndirect(&RClient); SelectClipRgn(HScreenDC, HClipRgn); DeleteObject(HClipRgn); CopyRect(&RTrack, &RImage); MapRect(HWnd, HWND_DESKTOP, RTrack); // render the first tracking rect RenderTrackingRect(HScreenDC, RTrack); is_tracking = true; } break; } case WM_MOUSEMOVE: { if (HScreenDC && is_tracking) { POINT PCurrent = {LOWORD(LParam), HIWORD(LParam)}; const int dX = PCurrent.x - PMouse.x; const int dY = PCurrent.y - PMouse.y; // erase the previous rectangle RenderTrackingRect(HScreenDC, RTrack); // update the postion OffsetRect(&RTrack, dX, dY); // render the new tracking rectangle RenderTrackingRect(HScreenDC, RTrack); // update the mouse position memcpy(&PMouse, &PCurrent, sizeof(POINT)); } break; } case WM_LBUTTONUP: { // clean up if (is_tracking) { is_tracking = false; SelectClipRgn(HScreenDC, NULL); ReleaseDC(NULL, HScreenDC); InvalidateRect(HWnd, &RImage, true); CopyRect(&RImage, &RTrack); MapRect(HWND_DESKTOP, HWnd, RImage); InvalidateRect(HWnd, &RImage, true); ClipCursor(NULL); } break; } case WM_PAINT: { PAINTSTRUCT ps; HDC Hdc = BeginPaint(HWnd, &ps); try { // // TODO: Add palette support... // // render the penguin BitBlt(Hdc, RImage.left, RImage.top, RImage.right - RImage.left, RImage.bottom - RImage.top, HMemDC, 0, 0, SRCCOPY); } catch (...) { EndPaint(HWnd, &ps); } EndPaint(HWnd, &ps); break; } case WM_DESTROY: { // clean up if (HOldBmp) { DeleteObject(SelectObject(HMemDC, HOldBmp)); } if (HMemDC) { DeleteDC(HMemDC); } PostQuitMessage(0); return 0; } } return DefWindowProc(HWnd, Msg, WParam, LParam); }