//-------------------------------------------------------------------------------------- void CProgressBarVertical::Draw ( void ) { if ( !m_bVisible ) return; CMouse *pMouse = m_pDialog->GetMouse (); if ( pMouse && m_bPressed && m_rBoundingBox.ContainsPoint ( pMouse->GetPos () ) && !m_timer.Running() ) { if ( pMouse->GetPos ().m_nY > m_rProgress.m_pos.m_nY + m_rProgress.m_size.cx ) { m_timer.Start ( PROGRESSBAR_ARROWCLICK_START ); SetValue ( m_fValue + m_fStep ); } else if ( pMouse->GetPos ().m_nY < m_rProgress.m_pos.m_nY + m_rProgress.m_size.cx ) { m_timer.Start ( PROGRESSBAR_ARROWCLICK_START ); SetValue ( m_fValue - m_fStep ); } } m_pDialog->DrawBox ( m_rBoundingBox, m_sControlColor.d3dColorBoxBack, m_sControlColor.d3dColorOutline, m_bAntAlias ); m_pDialog->DrawBox ( m_rProgress, m_sControlColor.d3dColorBoxSel, m_sControlColor.d3dColorOutline, m_bAntAlias ); }
void CBuildDialog::OnShow(){ CDialog::OnShow(); CMouse* mouse = CMouse::GetMouse(); if(this->PtInRect(mouse->Point())){ char woodStr[100]="",foodStr[100]="",stoneStr[100]="",goldStr[100]=""; if(resourceTable.Wood()!=0){ sprintf(woodStr,"木頭:%d ",resourceTable.Wood()); } if(resourceTable.Food()!=0){ sprintf(foodStr,"食物:%d ",resourceTable.Food()); } if(resourceTable.Gold()!=0){ sprintf(goldStr,"金礦:%d ",resourceTable.Gold()); } if(resourceTable.Stone()!=0){ sprintf(stoneStr,"石頭:%d ",resourceTable.Stone()); } char output[100]; CDC *pDC = CDDraw::GetBackCDC(); // 取得 Back Plain 的 CDC CFont f,*fp; f.CreatePointFont(100,"Times New Roman"); // 產生 font f; 160表示16 point的字 fp=pDC->SelectObject(&f); // 選用 font f pDC->SetBkColor(RGB(0,0,0)); pDC->SetTextColor(RGB(255,255,0)); sprintf(output,"%s%s%s%s",woodStr,foodStr,goldStr,stoneStr); pDC->TextOutA(mouse->Point().x,mouse->Point().y-20,output); pDC->SelectObject(fp); // 放掉 font f (千萬不要漏了放掉) CDDraw::ReleaseBackCDC(); // 放掉 Back Plain 的 CDC } }
//-------------------------------------------------------------------------------------- void CProgressBarHorizontal::Draw ( void ) { if ( !m_bVisible ) return; CMouse *pMouse = m_pDialog->GetMouse (); assert ( pMouse && "Invalid mouse pointer" ); if ( pMouse && m_bPressed && m_rBoundingBox.InControlArea ( pMouse->GetPos () ) && !m_timer.Running() ) { if ( pMouse->GetPos ().GetX () > m_rProgress.pos.GetX () + m_rProgress.size.cx ) { m_timer.Start ( PROGRESSBAR_ARROWCLICK_REPEAT ); SetValue ( m_fValue + m_fStep ); } else if ( pMouse->GetPos ().GetX () < m_rProgress.pos.GetX () + m_rProgress.size.cx ) { m_timer.Start ( PROGRESSBAR_ARROWCLICK_REPEAT ); SetValue ( m_fValue - m_fStep ); } } m_pDialog->DrawBox ( m_rBoundingBox, m_sControlColor.d3dColorBoxBack, m_sControlColor.d3dColorOutline, m_bAntAlias ); m_pDialog->DrawBox ( m_rProgress, m_sControlColor.d3dColorBoxSel, m_sControlColor.d3dColorOutline, m_bAntAlias ); }
int main(void) { CMouse *pMx = new CMouse; pMx->m_ix = 5; (*pMx).m_iy = 7; // 設定老鼠的位置 *(pMx->m_pcIcon) = '#'; // 設定老鼠的圖示 pMx->Show(); // 在螢幕上顯示老鼠 delete pMx; // 釋放取得的資源 system("pause"); return(0); }
void CDebugCamera::Update( const FLOAT fFrameTime, BOOL bIsCurrent ) { CMouse* pMouse = GetGameEngine()->GetInput()->GetMouse(); VECTOR vScroll = GetScroll(); if ( pMouse->IsMouseDown( EMouseButton_Middle ) ) { VECTOR vMove = pMouse->GetMousePosition() - m_vLastMousePos; vMove = vMove * GetGameEngine()->GetView()->GetZoom(); vScroll = vScroll - vMove; SetScroll( vScroll ); } m_vLastMousePos = pMouse->GetMousePosition(); }
int main(void) { char cIn; int iStatus; CMouse mouseX; // 建立時就會自動呼叫 CMouse 建構元 mouseX.Show(); // 讓老鼠自己畫出自己的位置 iStatus = mouseX.GetStatus(); while( iStatus != 0 ) { // 只要老鼠還在正常狀態就繼續讓使用者輸入 cIn = getch(); if( cIn == 'b' ) g_bBoss = !g_bBoss; // 判斷是否按下按鍵 b iStatus = mouseX.Update(cIn); // 讓老鼠自己更新狀態 if( iStatus ) mouseX.Show(); // 老鼠沒有死亡, 就必須更新老鼠位置的顯示 else cout << "老鼠已經死亡,遊戲結束" << endl; } system("pause"); return(0); }
void UIMouseHandler::captureMouse(ulong uScreenId) { /* Do not try to capture mouse if its captured already: */ if (uisession()->isMouseCaptured()) return; /* If such viewport exists: */ if (m_viewports.contains(uScreenId)) { /* Store mouse-capturing state value: */ uisession()->setMouseCaptured(true); /* Memorize the index of machine-view-viewport captured mouse: */ m_iMouseCaptureViewIndex = uScreenId; /* Memorize the host position where the cursor was captured: */ m_capturedMousePos = QCursor::pos(); /* Acquiring visible viewport rectangle in global coodrinates: */ QRect visibleRectangle = m_viewports[m_iMouseCaptureViewIndex]->visibleRegion().boundingRect(); QPoint visibleRectanglePos = m_views[m_iMouseCaptureViewIndex]->mapToGlobal(m_viewports[m_iMouseCaptureViewIndex]->pos()); visibleRectangle.translate(visibleRectanglePos); visibleRectangle = visibleRectangle.intersected(QApplication::desktop()->availableGeometry()); #ifdef Q_WS_WIN /* Move the mouse to the center of the visible area: */ m_lastMousePos = visibleRectangle.center(); QCursor::setPos(m_lastMousePos); /* Update mouse clipping: */ updateMouseCursorClipping(); #elif defined (Q_WS_MAC) /* Grab all mouse events: */ ::darwinMouseGrab(m_viewports[m_iMouseCaptureViewIndex]); #else /* Q_WS_MAC */ /* Remember current mouse position: */ m_lastMousePos = QCursor::pos(); /* Grab all mouse events: */ m_viewports[m_iMouseCaptureViewIndex]->grabMouse(); #endif /* !Q_WS_MAC */ /* Switch guest mouse to the relative mode: */ CMouse mouse = session().GetConsole().GetMouse(); mouse.PutMouseEvent(0, 0, 0, 0, 0); /* Emit signal if required: */ emit mouseStateChanged(mouseState()); } }
/*********************************************************************************** WindowProc - Main message handler ***********************************************************************************/ LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { static TRACKMOUSEEVENT tme; switch(message) { case WM_CREATE: g_pStateIntro->Initialize(); g_pStateMain->Initialize(); g_pStateControl->Initialize(); g_pStateCredits->Initialize(); g_pStatePlay1->Initialize(); //#define _WIN32_WINNT 0x0500 added before <windows.h> in order to get this to work tme.cbSize = sizeof(tme); tme.dwFlags = 0x00000002;//TME_LEAVE; tme.hwndTrack = hWnd; TrackMouseEvent(&tme); return 0; case WM_MOUSEMOVE: TrackMouseEvent(&tme); return 0; case WM_LBUTTONDBLCLK: return 0; case WM_LBUTTONDOWN: mouse.SetLeftButtonDown(true); return 0; case WM_LBUTTONUP: mouse.SetLeftButtonDown(false); return 0; case WM_RBUTTONDOWN: mouse.SetRightButtonDown(true); return 0; case WM_RBUTTONUP: mouse.SetRightButtonDown(false); return 0; case WM_MOUSELEAVE: mouse.SetLeftButtonDown(false); mouse.SetRightButtonDown(false); return 0; case WM_DESTROY: { PostQuitMessage(0); return 0; } break; } return DefWindowProc (hWnd, message, wParam, lParam); }
/* Mouse capability-change handler: */ void UIMouseHandler::sltMouseCapabilityChanged() { /* If mouse supports absolute pointing and mouse-integration activated: */ if (uisession()->isMouseSupportsAbsolute() && uisession()->isMouseIntegrated()) { /* Release the mouse: */ releaseMouse(); /* Also we should switch guest mouse to the absolute mode: */ CMouse mouse = session().GetConsole().GetMouse(); mouse.PutMouseEventAbsolute(-1, -1, 0, 0, 0); } #if 0 /* current team's decision is NOT to capture mouse on mouse-absolute mode loosing! */ /* If mouse-integration deactivated or mouse doesn't supports absolute pointing: */ else { /* Search for the machine-view focused now: */ int iFocusedView = -1; QList<ulong> screenIds = m_views.keys(); for (int i = 0; i < screenIds.size(); ++i) { if (m_views[screenIds[i]]->hasFocus()) { iFocusedView = screenIds[i]; break; } } /* If there is no focused view but views are present we will use the first one: */ if (iFocusedView == -1 && !screenIds.isEmpty()) iFocusedView = screenIds[0]; /* Capture mouse using that view: */ if (iFocusedView != -1) captureMouse(iFocusedView); } #else /* but just to switch the guest mouse into relative mode! */ /* If mouse-integration deactivated or mouse doesn't supports absolute pointing: */ else {
void ScrollBar::MouseInput(CMouse &rMouse, int32_t iButton, int32_t iX, int32_t iY, DWORD dwKeyParam) { // inherited Element::MouseInput(rMouse, iButton, iX, iY, dwKeyParam); // not if scrolling is disabled if (!fScrolling) return; // reset arrow states bool fPrevDown = fTopDown || fBottomDown; fTopDown = fBottomDown = false; // not if dragging if (rMouse.pDragElement) return; // left mouse button down? if (rMouse.IsLDown()) // non-scroll-direction area check if (fHorizontal ? Inside<int32_t>(iY, 0, C4GUI_ScrollBarHgt) : Inside<int32_t>(iX, 0, C4GUI_ScrollBarWdt)) { // scroll-direction area check: up/left arrow if (fHorizontal ? Inside<int32_t>(iX, 0, C4GUI_ScrollArrowWdt-1) : Inside<int32_t>(iY, 0, C4GUI_ScrollArrowHgt-1)) fTopDown = true; // check down arrow else if (fHorizontal ? Inside<int32_t>(iX, GetBounds().Wdt-C4GUI_ScrollArrowWdt, GetBounds().Wdt-1) : Inside<int32_t>(iY, GetBounds().Hgt-C4GUI_ScrollArrowHgt, GetBounds().Hgt-1)) fBottomDown = true; else if (HasPin() && (fHorizontal ? Inside<int32_t>(iX, C4GUI_ScrollArrowWdt, GetBounds().Wdt-C4GUI_ScrollArrowWdt-1) : Inside<int32_t>(iY, C4GUI_ScrollArrowHgt, GetBounds().Hgt-C4GUI_ScrollArrowHgt-1))) { // move thumb here iScrollPos = GetScrollByPos(iX, iY); // reflect movement in associated window or do CB OnPosChanged(); // start dragging rMouse.pDragElement = this; GUISound("UI::Select"); } } // sound effekt when buttons are pressed if ((fTopDown || fBottomDown) != fPrevDown) GUISound("UI::Tick"); }
/* * 功能: 场景相机玩家操作处理 * 摘要: - * 参数: - * 返回值: - * 作者: lpf * 创建日期: 2008.02.02 * 修改日志: * 2008.07.09- lpf * 增加了对摄象机旋转角度的锁定,主要针对玩家通过鼠标键盘控制摄象机时; * 2008.07.23- lpf * 恢复相机操作可以被键盘和鼠标中键的视距缩放操作中断; * 2008.07.30- lpf * 鼠标右键双击恢复视角的点击事件时,不恢复视距; * 2008.10.17 - lpf * 增加了游戏垂直视角控制由鼠标右键按下上下拖动; * 2008.12.04 - lpf * 增加了如果应用程序失去焦点,则清空鼠标信息的处理; * 2008.12.16 - lpf * 取消了使用键盘水平旋转视角的过度处理.在收到键盘旋转消息时,直接改变旋转角度,然后就立即改变m_nScorll变量值为0,以停止旋转; */ void CRegionCamera::Run(void) { // 输入设备对象 CMouse * pMouse = GetMouse(); CKeyBoard * pKeyboard = GetKeyboard(); // 鼠标到左右边缘,左右旋转 POINT ptMouse; ptMouse.x = pMouse->GetMouseX(); ptMouse.y = pMouse->GetMouseY(); // 键盘控制转方向 if (m_dwState & SCS_KEYBOARD_ABLE) { if (m_dwState & SCS_ROTATE_H_ABLE && !(m_dwState & SCS_LOCK_ROTATE)) { if (pKeyboard->IsKeyDown(DIK_LEFT) && pKeyboard->IsKeyDown(DIK_LCONTROL)) { //|| GetGame()->GetSetup()->lControl == 1 && pMouse->GetMouseX()<5 //&& pMouse->GetMouseY()>0 && pMouse->GetMouseY()<SCREEN_HEIGHT) m_nScorll =- 1; ResumeCamera(); } if (m_nScorll < 0) { // left m_iHoriAngle -= 3; m_iHoriAngle = m_iHoriAngle % 360; // if (abs(m_iHoriAngle%10) <= 1) m_nScorll=0; } if (pKeyboard->IsKeyDown(DIK_RIGHT) && pKeyboard->IsKeyDown(DIK_LCONTROL)) { //|| GetGame()->GetSetup()->lControl == 1 && pMouse->GetMouseX()>SCREEN_WIDTH-5 //&& pMouse->GetMouseY()>0 && pMouse->GetMouseY()<SCREEN_HEIGHT) m_nScorll = 1; ResumeCamera(); } if (m_nScorll > 0) { // right m_iHoriAngle += 3; m_iHoriAngle = m_iHoriAngle % 360; //if (abs(m_iHoriAngle%45) <= 1) m_nScorll = 0; } if (pKeyboard->IsKeyDown(DIK_NEXT) && pKeyboard->IsKeyDown(DIK_LCONTROL)) { ++m_iVertAngle; if (m_iVertAngle > m_iMaxVertAngle) m_iVertAngle = m_iMaxVertAngle; ResumeCamera(); } if (pKeyboard->IsKeyDown(DIK_PRIOR) && pKeyboard->IsKeyDown(DIK_LCONTROL)) { --m_iVertAngle; if (m_iVertAngle < m_iMinVertAngle) m_iVertAngle = m_iMinVertAngle; ResumeCamera(); } } // 有输入框时无效 //IGUIRoot *pRoot = IGUIRoot::GetGUIInstance(); //if(!pRoot->GetFocusComp()) //{ // // 键盘放缩 // if (pKeyboard->IsKeyDown(DIK_SUBTRACT) || pKeyboard->IsKeyDown(DIK_UP)) // { // s_fDistance -= 0.5f; // if (s_fDistance > s_fMaxDistance) // s_fDistance = s_fMaxDistance; // else if (s_fDistance < s_fMinDistance) // s_fDistance = s_fMinDistance; // ResumeCamera(); // RemoveCameraState(); // m_dwState &= ~SCS_SMOOTH; // } // if (pKeyboard->IsKeyDown(DIK_ADD) || pKeyboard->IsKeyDown(DIK_DOWN)) // { // s_fDistance += 0.5f; // if (s_fDistance > s_fMaxDistance) // s_fDistance = s_fMaxDistance; // else if (s_fDistance < s_fMinDistance) // s_fDistance = s_fMinDistance; // ResumeCamera(); // RemoveCameraState(); // m_dwState &= ~SCS_SMOOTH; // } //} } // 滚轮 if ((m_dwState & SCS_MOUSE_WHEEL_ABLE) && pMouse->GetCurrentButton() == MB_WHEEL) { s_fDistance -= (float)((short)HIWORD(pMouse->GetWheelDelta())) * 0.01f; if (s_fDistance > s_fMaxDistance) { s_fDistance = s_fMaxDistance; } else if (s_fDistance < s_fMinDistance) { s_fDistance = s_fMinDistance; } float fzDelta = (float)((short)HIWORD(pMouse->GetWheelDelta())); if (GetGame()->GetMainPlayer()->GetAction() != CShape::ACT_WALK&&GetGame()->GetMainPlayer()->GetAction() != CShape::ACT_RUN) { m_dwState &= ~SCS_SMOOTH; } ResumeCamera(); RemoveCameraState(); } extern bool g_bIsFocus; if (!g_bIsFocus) pMouse->ClearMessage(); // 鼠标右键操作 bool bRightUp = false; // 鼠标右键按下一次 if (pMouse->GetCurrentButton() == RB_DOWN) { m_ptOldMouse.x = pMouse->GetMouseX(); m_ptOldMouse.y = pMouse->GetMouseY(); m_iOldHoriAngle = m_iHoriAngle; m_iOldVertAngle = m_iVertAngle; ResumeCamera(); } // 鼠标右键弹起 if (pMouse->GetCurrentButton() == RB_UP) bRightUp = true; // 鼠标右键按下不放 if (pMouse->IsRightButtonDown() && !bRightUp) { if ((pMouse->GetMouseX() - m_ptOldMouse.x) > 1 || (pMouse->GetMouseX() - m_ptOldMouse.x) < -1) { if (!(m_dwState & SCS_LOCK_ROTATE)) { m_iHoriAngle = (int)( m_iOldHoriAngle + (pMouse->GetMouseX() - m_ptOldMouse.x)*0.5 ) % 360; RemoveCameraState(); } /*m_iVertAngle = (int)( m_iOldVertAngle + (pMouse->GetMouseX() - m_ptOldMouse.x)*0.5 ) % 360; m_dwState &= ~SCS_REPOS_V;*/ } m_iVertAngle += (int)(((float)pMouse->GetMouseMoveY() * 0.5f)); if (m_iVertAngle < m_iMinVertAngle) m_iVertAngle = m_iMinVertAngle; else if (m_iVertAngle > m_iMaxVertAngle) m_iVertAngle = m_iMaxVertAngle; ResumeCamera(); } //IGUIRoot *pRoot = IGUIRoot::GetGUIInstance(); //if(pRoot && pRoot->GetGUIComp()) //{ // CComponent * pComp = pRoot->GetGUIComp()->GetComponentAt(pMouse->GetMouseX(),pMouse->GetMouseY()); // if(pComp && pComp->IsEnabled() && pComp->IsVisible() && // strcmp(pComp->GetName(),"ChatInfo")!=0 && strcmp(pComp->GetName(),"TeamPage")!=0 // && strcmp(pComp->GetName(),"MedalTipPage")!=0) // { // return; // } // // 鼠标右键双击 // if (pMouse->GetCurrentButton() == RB_DCLICK && !(m_dwState & SCS_LOCK_ROTATE)) // { // m_dwState |= SCS_REPOS_H; // m_dwState |= SCS_REPOS_V; // //m_dwState |= SCS_REPOS_D; // } //} }
void onPassiveMotion(int x, int y){ mouse.onPassiveMotion(x,y); }
/*********************************************************************************** WinMain - Entry point for program. ***********************************************************************************/ int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { CLog *pLog = CLog::Instance(); pLog->Log(" "); pLog->Log("***************************************"); pLog->Log("Program Start"); pLog->LogDate(); pLog->Log("***************************************"); //request player choose fullscreen or windowed mode CConfigData cfg; cfg.LoadConfigFile("assets//data//config.cfg"); bool bFullscreen = false; bFullscreen = cfg.FullScreen; int msgReturn = ::MessageBox(NULL, "Fullscreen? (Y/N)", "Select Display Option", MB_YESNO); if(msgReturn == IDYES) bFullscreen = true; //variable declarations CGameData gameData; CTimer gTimerFPS; int gLoopCount = 0; int gSecondCount = 0; bool g_bRunning = true; bool gExitProgram = false; //this is set true with ESC, for rendering to stop properly if(bFullscreen == true) gameData.m_windowedYOffset = 0; else gameData.m_windowedYOffset = 21; //determine if we play new or saved game /* gameData.m_playNewGame = true; HRESULT hr = ::MessageBox(0, "Play new game?", "New or saved game!", MB_YESNO); if(hr == IDYES) gameData.m_playNewGame = true; else gameData.m_playNewGame = false; */ //gameData.m_playNewGame = true; //setup game data pLog->Log("Program Name", cfg.ProgramName); pLog->Log("Version", cfg.ProgramVersion); //create window HWND hWnd; WNDCLASSEX wc; ZeroMemory(&wc, sizeof(WNDCLASSEX)); wc.cbSize = sizeof(WNDCLASSEX); wc.style = CS_HREDRAW | CS_VREDRAW; wc.lpfnWndProc = (WNDPROC)WindowProc; wc.hInstance = hInstance; wc.hCursor = LoadCursor(NULL, IDC_ARROW); wc.lpszClassName = "WindowClass"; wc.hIconSm = LoadIcon (hInstance, MAKEINTRESOURCE(IDI_ICON1)); RegisterClassEx(&wc); /* //screen data - need at least 800x600 int cxScreen = ::GetSystemMetrics(SM_CXFULLSCREEN); int cyScreen = ::GetSystemMetrics(SM_CYFULLSCREEN); if(cfg.ScreenWidth < 800 || cfg.ScreenWidth > cxScreen) cfg.ScreenWidth = cxScreen; if(cfg.ScreenHeight < 600 || cfg.ScreenHeight > cyScreen) cfg.ScreenHeight = cyScreen; cfg.ScreenLeft = cxScreen/2 - cfg.ScreenWidth/2; cfg.ScreenTop = cyScreen/2 - cfg.ScreenHeight/2; */ if(!bFullscreen) { if(cfg.ScreenWidth < 800) { cfg.ScreenWidth = 800; } if(cfg.ScreenHeight < 600) { cfg.ScreenHeight = 600; } } cfg.ScreenLeft = 0; cfg.ScreenTop = 0; /* // set up and initialize Direct3D CGraphics con();// cfg.FullScreen); int screenWidth = 0; int screenHeight = 0; if(con.InitializeDirectX(screenWidth, screenHeight, bFullscreen) == false){ pLog->Log("Failure initializing DirectX!"); ::MessageBox(0,"Failed to initialize DirectX", "Error", 0); return 0; } pLog->Log("DirectX Initialized"); */ int cxScreen = ::GetSystemMetrics(SM_CXFULLSCREEN); int cyScreen = ::GetSystemMetrics(SM_CYFULLSCREEN); if(cfg.ScreenWidth < 800 || cfg.ScreenWidth > cxScreen) cfg.ScreenWidth = cxScreen; if(cfg.ScreenHeight < 600 || cfg.ScreenHeight > cyScreen) cfg.ScreenHeight = cyScreen; cfg.ScreenLeft = cxScreen/2 - cfg.ScreenWidth/2; cfg.ScreenTop = cyScreen/2 - cfg.ScreenHeight/2; //create window std::string sCaption = cfg.ProgramName + " - " + cfg.ProgramVersion; hWnd = CreateWindowEx(NULL, "WindowClass", sCaption.c_str(), //cfg.ProgramVersion.c_str(), bFullscreen == true ? WS_EX_TOPMOST | WS_POPUP : WS_BORDER | WS_CAPTION | WS_SYSMENU, cfg.ScreenLeft, cfg.ScreenTop, /*0, 0, screenWidth, screenHeight,*/ bFullscreen == true ? CW_USEDEFAULT : cfg.ScreenWidth, bFullscreen == true ? CW_USEDEFAULT : cfg.ScreenHeight, NULL,NULL,hInstance,NULL); ShowWindow(hWnd, nCmdShow); pLog->Log("Window Loaded and Displayed!"); gameData.m_hWnd = hWnd; /* // set up and initialize Direct3D CGraphics con(hWnd, cfg.ScreenWidth, cfg.ScreenHeight,bFullscreen);// cfg.FullScreen); if(con.InitializeDirectX() == false){ pLog->Log("Failure initializing DirectX!"); ::MessageBox(hWnd,"Failed to initialize DirectX", "Error", 0); return 0; } pLog->Log("DirectX Initialized"); */ CGraphics con(hWnd, cfg.ScreenWidth, cfg.ScreenHeight, bFullscreen); if(con.InitializeDirectX() == false) { ::MessageBox(hWnd, "Failed to Create IDirect3D9 Interface.", "Error", 0); return 0; } if(con.IsDisplayModeSupported() == false) { ::MessageBox(hWnd, "Display mode not supported.", "Error", 0); return 0; } if(con.InitializeDevice() == false) { ::MessageBox(hWnd, "Could not create IDirect3DDevice9 Device.", "Error", 0); return 0; } //load framework assets if(con.LoadAssetFile(cfg.FrameworkAssetFile) == false){ pLog->Log("Failure loading " + cfg.FrameworkAssetFile); ::MessageBox(hWnd,"Failed to load editor.dat file", "Error", 0); return 0; } else pLog->Log(cfg.FrameworkAssetFile + " (frame graphics) was loaded successfully!"); //load game play assets if(con.LoadAssetFile(cfg.GamePlayAssetFile) == false){ pLog->Log("Failure loading " + cfg.GamePlayAssetFile); ::MessageBox(hWnd,"Failed to load assets.dat file", "Error", 0); return 0; } else pLog->Log(cfg.GamePlayAssetFile + " (game play graphics) was loaded successfully!"); //load objects //*************************************************************************** if(gameData.LoadObjectFile(cfg.GameObjectFile) == false){ pLog->Log("Failure loading " + cfg.GameObjectFile); //::MessageBox(hWnd,"Failed to load objects.dat file", "Error", 0); // return 0; } else{ pLog->Log(cfg.GameObjectFile + " (objects file) was loaded successfully!"); // for(int i = 0; i < gameData.m_catalog.GetTableSize();++i){ // pLog->Log("object", gameData.m_catalog.GetTerm(i, 0), gameData.m_catalog.GetTerm(i, 2)); // } } gTimerKey.Initialize(); gTimerKey.ResetTimer(); mouse.SetHandle(hWnd); gTimerFPS.Initialize(); //game timer for update CTimer timerGame; timerGame.Initialize(); //define events for changing game states //************************************************************************* //g_pStateIntro->AddTransitionEvent(EVENT_GO_PLAY1, g_pStatePlay1); //g_pStatePlay1->AddTransitionEvent(EVENT_GO_CREDITS, g_pStateCredits); g_pStateIntro->AddTransitionEvent(EVENT_GO_MAIN, g_pStateMain); g_pStateMain->AddTransitionEvent(EVENT_GO_PLAY1, g_pStatePlay1); g_pStateMain->AddTransitionEvent(EVENT_GO_HELP, g_pStateHelp); g_pStateMain->AddTransitionEvent(EVENT_GO_CREDITS, g_pStateCredits); g_pStatePlay1->AddTransitionEvent(EVENT_GO_QUIT, g_pStateQuit); //g_pStatePlay1->AddTransitionEvent(EVENT_GO_MAIN, g_pStateMain); g_pStateHelp->AddTransitionEvent(EVENT_GO_MAIN, g_pStateMain); g_pStateCredits->AddTransitionEvent(EVENT_GO_QUIT, g_pStateQuit); g_pCurrent = g_pStatePlay1;// g_pStateIntro; // enter the main loop //************************************** M A I N L O O P ***************** MSG msg; pLog->Log("Entering Main Control Loop"); float timeDiff = 0.0f; g_pCurrent->Activate(gameData, cfg, con); while(g_bRunning) { DWORD starting_point = GetTickCount(); ::Sleep(0); if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { if (msg.message == WM_QUIT) break; TranslateMessage(&msg); DispatchMessage(&msg); } //manage frame count determination gLoopCount++; if(gTimerFPS.getTimer(1.0) == true){ gameData.m_FPS = static_cast<float>(gLoopCount); gLoopCount = 0; gSecondCount++; if(gSecondCount > 30){ //log every 30 seconds gSecondCount = 0; if(cfg.LogDebugInfo == true) pLog->Log("FPS",gameData.m_FPS); } } //stores mouse button status for use in other classes gameData.m_bLeftMouseDown = mouse.LeftButtonDown(); gameData.m_bRightMouseDown = mouse.RightButtonDown(); //update g_pLast = g_pCurrent; g_pNext = g_pCurrent->Update(timerGame.getTimeDifference(), gameData, cfg, con); if(g_pNext == g_pStateQuit) g_bRunning = false; else if(NULL != g_pNext) { if(g_pNext != g_pLast){ g_pLast->Deactivate(gameData, cfg, con); g_pCurrent = g_pNext; g_pCurrent->Activate(gameData, cfg, con); } } //render g_pCurrent->Render(con, gameData, cfg); // check the 'escape' key if(g_bRunning == false){ gExitProgram = true; PostMessage(hWnd, WM_DESTROY, 0, 0); } } pLog->Log("Exited main loop"); // clean up DirectX and COM con.CleanupDirectX(); Shutdown(); pLog->Log("DirectX Cleaned Up"); pLog->Log("Shutdown complete!"); pLog->Log("***************************************"); pLog->Log(" Program Terminated Normally"); pLog->Log("***************************************"); return static_cast<int>(msg.wParam); }
void reshape(int width, int height){ openglContext.reshapeWindow(width,height); mouse.centerMouse(); }
void init(int argc, char *argv[]){ openglContext.create30Context(); mouse.centerMouse(); openglContext.setupScene(argc,argv); }
//============================================================================= // エントリー関数 //============================================================================= int APIENTRY WinMain(HINSTANCE _instanceHandle ,HINSTANCE _instanceHandlePrev, LPSTR _cmdLine, int _cmdShow) { _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF); UNREFERENCED_PARAMETER(_instanceHandlePrev); UNREFERENCED_PARAMETER(_cmdLine); DWORD execLastTime; DWORD LastTimeFPS; DWORD currentTime; DWORD flameCount; WNDCLASSEX wcex = { sizeof(WNDCLASSEX), CS_CLASSDC, WndProc, 0, 0, _instanceHandle, NULL, LoadCursor(NULL, IDC_ARROW), (HBRUSH)(COLOR_WINDOW + 1), NULL, CLASS_NAME, NULL }; HWND windowHandle; MSG msg; // ウィンドウクラスの登録 RegisterClassEx(&wcex); // ウィンドウの作成 windowHandle = CreateWindowEx(0, CLASS_NAME, WINDOW_NAME, WS_OVERLAPPEDWINDOW & ~WS_MAXIMIZEBOX & ~WS_THICKFRAME, CW_USEDEFAULT, CW_USEDEFAULT, static_cast<int>(SCREEN_WIDTH + GetSystemMetrics(SM_CXDLGFRAME) * 2), static_cast<int>(SCREEN_HEIGHT + GetSystemMetrics(SM_CXDLGFRAME) * 2 + GetSystemMetrics(SM_CYCAPTION)), NULL, NULL, _instanceHandle, NULL); // フレームカウント初期化 timeBeginPeriod(1); // 分解能を設定 execLastTime = LastTimeFPS = timeGetTime(); currentTime = flameCount = 0; // ウインドウの表示(初期化処理の後に呼ばないと駄目) ShowWindow(windowHandle, _cmdShow); UpdateWindow(windowHandle); #ifndef _DEBUG LoadLibraryA("WiiYourself.dll"); #else LoadLibraryA("WiiYourself_debug.dll"); #endif LPDIRECT3D9 direct3D; // Direct3D9用デバイス LPDIRECT3DDEVICE9 device; // _deviceオブジェクト(描画に必要) D3DDISPLAYMODE displayMode; D3DPRESENT_PARAMETERS presentParameter; // Direct3Dオブジェクトの作成 direct3D = Direct3DCreate9(D3D_SDK_VERSION); direct3D->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &displayMode); // デバイスのプレゼンテーションパラメータの設定 //-------------------------------------------------------------------- // ワークをゼロクリア ZeroMemory(&presentParameter, sizeof(presentParameter)); // バックバッファの数をセット presentParameter.BackBufferCount = 1; //ゲーム画面サイズ presentParameter.BackBufferWidth = static_cast<int>SCREEN_WIDTH; presentParameter.BackBufferHeight = static_cast<int>SCREEN_HEIGHT; // バックバッファフォーマットはディスプレイモードに合わせて使う presentParameter.BackBufferFormat = displayMode.Format; // 映像信号に同期してフリップする presentParameter.SwapEffect = D3DSWAPEFFECT_DISCARD; // ウィンドウモード presentParameter.Windowed = TRUE; // デプスバッファ(Zバッファ)とステンシルバッファを作成 presentParameter.EnableAutoDepthStencil = TRUE; // デプスバッファの利用方法 // D3DFMT_D16 デプスバッファのみを16bitとして扱う // D3DFMT_D24S8 デプスバッファを24bit ステンシルバッファを8bitとして扱う presentParameter.AutoDepthStencilFormat = D3DFMT_D24S8; // ウィンドウモード presentParameter.FullScreen_RefreshRateInHz = 0; presentParameter.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE; //-------------------------------------------------------------------- direct3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, windowHandle, D3DCREATE_HARDWARE_VERTEXPROCESSING, &presentParameter, &device); CDebug* debug = new CDebug(); debug->Init(device); CKeyboard* keyboard = new CKeyboard(); keyboard->Init(_instanceHandle, windowHandle); CMouse* mouse = new CMouse(); mouse->Init(_instanceHandle, windowHandle); CWiiController* wiiController = new CWiiController(); // メッセージループ for (;;) { if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { if (msg.message == WM_QUIT) { // PostQuitMessage()が呼ばれたらループ終了 break; } else { // メッセージの翻訳とディスパッチ TranslateMessage(&msg); DispatchMessage(&msg); } } else { currentTime = timeGetTime(); if ((currentTime - LastTimeFPS) >= 500) { #ifdef _DEBUG countFPS = flameCount * 1000 / (currentTime - LastTimeFPS); #endif LastTimeFPS = currentTime; flameCount = 0; } if ((currentTime - execLastTime) >= (1000 / 60)) { execLastTime = currentTime ; keyboard->Update(); mouse->Update(); wiiController->update(); { // 本体 { debug->SetDebug("本体の加速度X [%f]\n", wiiController->getAccelerationX()); debug->SetDebug("本体の加速度Y [%f]\n", wiiController->getAccelerationY()); debug->SetDebug("本体の加速度Z [%f]\n", wiiController->getAccelerationZ()); debug->SetDebug("本体の回転角X [%f]\n", wiiController->getRotX()); debug->SetDebug("本体の回転角Y [%f]\n", wiiController->getRotY()); debug->SetDebug("本体の回転角Z [%f]\n", wiiController->getRotZ()); debug->SetDebug("本体の回転角の変異X [%f]\n", wiiController->getChangeRotX()); debug->SetDebug("本体の回転角の変異Y [%f]\n", wiiController->getChangeRotY()); debug->SetDebug("本体の回転角の変異Z [%f]\n", wiiController->getChangeRotZ()); debug->SetDebug("本体の角速度X [%f]\n", wiiController->getRotSpeedX()); debug->SetDebug("本体の角速度Y [%f]\n", wiiController->getRotSpeedY()); debug->SetDebug("本体の角速度Z [%f]\n", wiiController->getRotSpeedZ()); } // ヌンチャク { debug->SetDebug("ヌンチャクの加速度X [%f]\n", wiiController->getAccelerationNX()); debug->SetDebug("ヌンチャクの加速度Y [%f]\n", wiiController->getAccelerationNY()); debug->SetDebug("ヌンチャクの加速度Z [%f]\n", wiiController->getAccelerationNZ()); debug->SetDebug("ヌンチャクの回転角X [%f]\n", wiiController->getRotNX()); debug->SetDebug("ヌンチャクの回転角Y [%f]\n", wiiController->getRotNY()); debug->SetDebug("ヌンチャクの回転角Z [%f]\n", wiiController->getRotNZ()); debug->SetDebug("ヌンチャクの位置X [%f]\n", wiiController->getJoystick().x); debug->SetDebug("ヌンチャクの位置Y [%f]\n", wiiController->getJoystick().y); } // 赤外線 { debug->SetDebug("赤外線X [%f]\n", wiiController->getIR().x); debug->SetDebug("赤外線Y [%f]\n", wiiController->getIR().y); } debug->SetDebug("バッテリー残量[%d%]\n", wiiController->battery()); debug->SetDebug("モーションPlusの接続状態[%d]\n", wiiController->getMotionConnect()); /*if (wiiController->getTrigger(WC_A)) wiiController->rumble(true); if (wiiController->getTrigger(WC_B)) wiiController->rumble(false); if (wiiController->getTrigger(WC_UP)) wiiController->rumble((unsigned int)1000);*/ // Aボタン { if (wiiController->getPress(WC_A)) debug->SetDebug("A [ON]\n"); else debug->SetDebug("A [OFF]\n"); } // Bボタン { if (wiiController->getPress(WC_B)) debug->SetDebug("B [ON]\n"); else debug->SetDebug("B [OFF]\n"); } // Cボタン { if (wiiController->getPress(WC_C)) debug->SetDebug("C [ON]\n"); else debug->SetDebug("C [OFF]\n"); } // Zボタン { if (wiiController->getPress(WC_Z)) debug->SetDebug("Z [ON]\n"); else debug->SetDebug("Z [OFF]\n"); } // ↑ボタン { if (wiiController->getPress(WC_UP)) debug->SetDebug("UP [ON]\n"); else debug->SetDebug("UP [OFF]\n"); } // ↓ボタン { if (wiiController->getPress(WC_DOWN)) debug->SetDebug("DOWN [ON]\n"); else debug->SetDebug("DOWN [OFF]\n"); } // ←ボタン { if (wiiController->getPress(WC_LEFT)) debug->SetDebug("LEFT [ON]\n"); else debug->SetDebug("LEFT [OFF]\n"); } // →ボタン { if (wiiController->getPress(WC_RIGHT)) debug->SetDebug("RIGHT [ON]\n"); else debug->SetDebug("RIGHT [OFF]\n"); } // -ボタン { if (wiiController->getPress(WC_MINUS)) debug->SetDebug("MINUS [ON]\n"); else debug->SetDebug("MINUS [OFF]\n"); if(wiiController->getTrigger(WC_MINUS)) wiiController->rotSpeedCalibration(); } // +ボタン { if (wiiController->getPress(WC_PLUS)) debug->SetDebug("PLUS [ON]\n"); else debug->SetDebug("PLUS [OFF]\n"); if(wiiController->getTrigger(WC_PLUS)) wiiController->rotReset(); } // 1ボタン { if (wiiController->getPress(WC_ONE)) debug->SetDebug("ONE [ON]\n"); else debug->SetDebug("ONE [OFF]\n"); } // 2ボタン { if (wiiController->getPress(WC_TWO)) debug->SetDebug("TWO [ON]\n"); else debug->SetDebug("TWO [OFF]\n"); } // HOMEボタン { if (wiiController->getPress(WC_HOME)) debug->SetDebug("HOME [ON]\n"); else debug->SetDebug("HOME [OFF]\n"); } } // バックバッファ&Zバッファのクリア device->Clear(0, NULL, (D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER), D3DCOLOR_RGBA(255, 255, 255, 255), 1.0f, 0); // Direct3Dによる描画の開始 if (SUCCEEDED(device->BeginScene())) { CDebug::Draw(); // Direct3Dによる描画の終了 device->EndScene(); } // バックバッファとフロントバッファの入れ替える device->Present(NULL, NULL, NULL, NULL); flameCount++; } } } SAFE_DELETE(wiiController); SAFE_DELETE(keyboard); SAFE_DELETE(mouse); SAFE_DELETE(debug); // ウィンドウクラスの登録を解除 UnregisterClass(CLASS_NAME, wcex.hInstance); timeEndPeriod(1); // 分解能を戻す return static_cast<int>(msg.wParam); }
void onMouse(int button, int state, int x, int y){ mouse.onMouse(button,state,x,y); }