//--------------------------------------------------------------------------- __fastcall TFormSoaSimMain::TFormSoaSimMain(TComponent* Owner) : TForm(Owner) { DrawGlobe(ImagePersonRed , 255, 0, 0); DrawGlobe(ImagePersonGreen , 0, 255, 0); DrawGlobe(ImagePersonBlue , 0, 0, 255); DrawGlobe(ImagePersonCustom, 255, 255, 255); DrawGlobe(ImageShadow , 64, 64, 64); ImagePersonRed->Transparent = true; ImagePersonGreen->Transparent = true; ImagePersonBlue->Transparent = true; ImagePersonCustom->Transparent = true; ImageShadow->Transparent = true; ImageBlaLeft->Picture->Bitmap->TransparentColor = clLime; ImageProposeUnsafe->Picture->Bitmap->TransparentColor = clLime; ImageProposeSafe->Picture->Bitmap->TransparentColor = clLime; ImageSafeSex->Picture->Bitmap->TransparentColor = clLime; ImageUnsafeSex->Picture->Bitmap->TransparentColor = clLime; ImageBlaLeft->Transparent = true; ImageProposeUnsafe->Transparent = true; ImageProposeSafe->Transparent = true; //ImageSafeSex->Transparent = true; //ImageUnsafeSex->Transparent = true; OnResize(0); //Create persons { const int nPersons = 20; //First add an infected Bad Boy AddBadBoy(true); mPersons.front()->isInfected = true; for (int i=0; i!=nPersons-1; ++i) { switch( (std::rand() >> 4) % 3) { case 0: AddBadBoy(false); break; case 1: AddPartyAnimal(false); break; case 2: AddWiseGuy(false); break; default: assert(!"Should not get here"); break; } } } }
//--------------------------------------------------------------------------- void __fastcall TFormSimBrainiacMain::FormResize(TObject *Sender) { const int width = ClientWidth / mNrows; const int height = ClientHeight / mNcols; ImageBrainiac->Picture->Bitmap->Width = width; ImageBrainiac->Picture->Bitmap->Height = height; ImageBuffer->Picture->Bitmap->Width = ClientWidth; ImageBuffer->Picture->Bitmap->Height = ClientHeight; PaintVcl(ImageBuffer,255,255,255); PaintVcl(ImageBrainiac,255,255,255); DrawGlobe(ImageBrainiac,255,255,255); }
/* Функция обработки сообщения окна. * АРГУМЕНТЫ: * - дескриптор окна: * HWND hWnd; * - номер сообщения (см. WM_***): * UINT Msg; * - параметр сообшения ('word parameter'): * WPARAM wParam; * - параметр сообшения ('long parameter'): * LPARAM lParam; * ВОЗВРАЩАЕМОЕ ЗНАЧЕНИЕ: * (LRESULT) - в зависимости от сообщения. */ LRESULT CALLBACK MyWindowFunc( HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam ) { HDC hDC; CREATESTRUCT *cs; static BITMAP bm; static HBITMAP hBm, hBmLogo; static HDC hMemDC; static INT w, h; switch (Msg) { case WM_CREATE: cs = (CREATESTRUCT *)lParam; SetTimer(hWnd, 111, 50, NULL); hDC = GetDC(hWnd); hMemDC = CreateCompatibleDC(hDC); ReleaseDC(hWnd, hDC); return 0; case WM_SIZE: w = LOWORD(lParam); h = HIWORD(lParam); if (hBm != NULL) DeleteObject(hBm); hDC = GetDC(hWnd); hBm = CreateCompatibleBitmap(hDC, w, h); ReleaseDC(hWnd, hDC); SelectObject(hMemDC, hBm); SendMessage(hWnd, WM_TIMER, 111, 0); return 0; case WM_TIMER: /* Clear Background */ SelectObject(hMemDC, GetStockObject(NULL_PEN)); SelectObject(hMemDC, GetStockObject(DC_BRUSH)); SetDCBrushColor(hMemDC, RGB(255, 255, 255)); Rectangle(hMemDC, 0, 0, w + 1, h + 1); SelectObject(hMemDC, GetStockObject(NULL_PEN)); SelectObject(hMemDC, GetStockObject(DC_BRUSH)); SetDCBrushColor(hMemDC, RGB(2, 2, 8)); DrawGlobe(hMemDC, w, h); InvalidateRect(hWnd, NULL, TRUE); return 0; case WM_ERASEBKGND: BitBlt((HDC)wParam, 0, 0, w, h, hMemDC, 0, 0, SRCCOPY); return 0; case WM_DESTROY: DeleteDC(hMemDC); DeleteObject(hBm); KillTimer(hWnd, 111); PostQuitMessage(0); return 0; } return DefWindowProc(hWnd, Msg, wParam, lParam); } /* End of 'MyWindowFunc' function */