void Camera3::CameraRotation(float CAMERASPEED) { int WIDTH, HEIGHT; glfwGetWindowSize(m_window, &WIDTH, &HEIGHT); POINT p; GetCursorPos(&p); SetCursorPos(WIDTH/2, HEIGHT/2); rotationY -= (p.x - (float)WIDTH / 2) / (1 / CAMERASPEED); rotationX -= (p.y - (float)HEIGHT / 2) / (1 / CAMERASPEED); if (rotationX > 80.f) { rotationX = 80.f; } else if (rotationX < -80.f) { rotationX = -80.f; } if (rotationY >= 360.f || rotationY <= -360.f) { rotationY = 0.f; } target = Vector3( cos(Math::DegreeToRadian(rotationX)) * cos(Math::DegreeToRadian(rotationY)) + this->position.x, sin(Math::DegreeToRadian(rotationX)) + this->position.y, -(cos(Math::DegreeToRadian(rotationX)) * sin(Math::DegreeToRadian(rotationY))) + this->position.z ); }
static void Test_NonClientMetrics() { NONCLIENTMETRICS NonClientMetrics; /* WARNING: this test requires themes and dwm to be disabled */ SetCursorPos(0,0); /* Retrieve th non client metrics */ NonClientMetrics.cbSize = sizeof(NONCLIENTMETRICS); SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(NONCLIENTMETRICS), &NonClientMetrics, 0); FlushMessages(); COMPARE_CACHE(empty_chain); /* Set the non client metric without making any change */ SystemParametersInfo(SPI_SETNONCLIENTMETRICS, sizeof(NONCLIENTMETRICS), &NonClientMetrics, 0); FlushMessages(); COMPARE_CACHE(NcMetricsChange_chain); /* Set the same metrics again with the SPIF_SENDCHANGE param */ SystemParametersInfo(SPI_SETNONCLIENTMETRICS, sizeof(NONCLIENTMETRICS), &NonClientMetrics, SPIF_SENDCHANGE|SPIF_UPDATEINIFILE ); FlushMessages(); COMPARE_CACHE(NcMetricsChange1_chain); /* Slightly change the caption height */ NonClientMetrics.iCaptionHeight += 1; SystemParametersInfo(SPI_SETNONCLIENTMETRICS, sizeof(NONCLIENTMETRICS), &NonClientMetrics, 0); FlushMessages(); COMPARE_CACHE(CaptionHeight_chain); /* Restore the original caption height */ NonClientMetrics.iCaptionHeight -= 1; SystemParametersInfo(SPI_SETNONCLIENTMETRICS, sizeof(NONCLIENTMETRICS), &NonClientMetrics, 0); FlushMessages(); COMPARE_CACHE(CaptionHeight_chain); }
void _restoreInputGrab_() { #ifdef G3D_WIN32 // Restore the old clipping region ClipCursor(&oldCursorRect); SetCursorPos(oldCursorPos.x, oldCursorPos.y); // Restore the old cursor SetCursor(oldCursor); // Restore old visibility count if (oldShowCursorCount < 0) { for (int c = 0; c > oldShowCursorCount; --c) { ShowCursor(false); } } #elif defined(G3D_LINUX) // TODO: Linux #elif defined(G3D_OSX) // TODO: OS X #endif }
bool CScene::ProcessInput( HWND hWnd, CGameTimer timer ) { static UCHAR pKeyBuffer[256]; DWORD dwDirection = 0; if (GetKeyboardState( pKeyBuffer )) { if (pKeyBuffer['W'] & 0xF0) dwDirection |= DIR_FORWARD; if (pKeyBuffer['S'] & 0xF0) dwDirection |= DIR_BACKWARD; if (pKeyBuffer['A'] & 0xF0) dwDirection |= DIR_LEFT; if (pKeyBuffer['D'] & 0xF0) dwDirection |= DIR_RIGHT; if (pKeyBuffer['1'] & 0xF0) m_pCamera->Move( XMFLOAT3( 0.0f, 10.f, 10.0f )); } float cxDelta = 0.0f, cyDelta = 0.0f; POINT ptCursorPos; /*마우스를 캡쳐했으면 마우스가 얼마만큼 이동하였는 가를 계산한다. 마우스 왼쪽 또는 오른쪽 버튼이 눌러질 때의 메시지(WM_LBUTTONDOWN, WM_RBUTTONDOWN)를 처리할 때 마우스를 캡쳐하였다. 그러므로 마우스가 캡쳐된 것은 마우스 버튼이 눌려진 상태를 의미한다. 마우스를 좌우 또는 상하로 움직이면 플레이어를 x-축 또는 y-축으로 회전한다.*/ if (GetCapture( ) == hWnd) { SetCursor( NULL ); GetCursorPos( &ptCursorPos ); cxDelta = (float)( ptCursorPos.x - m_ptOldCursorPos.x ) / 5.0f; cyDelta = (float)( ptCursorPos.y - m_ptOldCursorPos.y ) / 5.0f; SetCursorPos( ptCursorPos.x, ptCursorPos.y ); } if (dwDirection != 0 || cxDelta != 0.0f || cyDelta != 0.0f) { if (cxDelta || cyDelta) { /*cxDelta는 y-축의 회전을 나타내고 cyDelta는 x-축의 회전을 나타낸다. 오른쪽 마우스 버튼이 눌려진 경우 cxDelta는 z-축의 회전을 나타낸다.*/ // 마우스 클릭시 공격 애니메이션이 행해지도록 해야함 if (pKeyBuffer[VK_RBUTTON] & 0xF0){ //m_pCamera->Move( XMFLOAT3( cyDelta, 0.0f, -cxDelta ) ); /// m_pCamera->Rotate(0.0f, cxDelta, 0.0f); // m_pCamera->Update( XMFLOAT3( 0.0f, 0.0f, 0.0f ), timer.GetTimeElapsed( ) ); } // else // m_pCamera->Rotate( cyDelta, cxDelta, 0.0f ); //if (pKeyBuffer[VK_LBUTTON] & 0xF0) //{ // //m_pPlayer->m_iAnimState = static_cast<int>( AnimationState::ANIM_LATTACK1 ); // SoundManager::GetInstance( )->Play( ATTACK ); //} } /*플레이어를 dwDirection 방향으로 이동한다(실제로는 속도 벡터를 변경한다). 이동 거리는 시간에 비례하도록 한다. 플레이어의 이동 속력은 (50/초)로 가정한다. 만약 플레이어의 이동 속력이 있다면 그 값을 사용한다.*/ if (dwDirection) { // 현재 플레이어의 AABB 박스의 y좌표 최소가 -0.5임. 따라서 0보다 작으므로 바닥과 겹침, 그로 인해 못움직임 // 충돌체크 자체는 제대로 되고 있으나 플레이어의 위치가 문제 // if (!CollisionCheck( )) m_pPlayer->Move( dwDirection, 50.0f * timer.GetTimeElapsed( ), false ); } } // if (!CollisionCheck( )) m_pPlayer->Update( timer.GetTimeElapsed( ), vPickPos ); return true; }
void MouseControl2(POINT p) { SetCursorPos(p.x,p.y); //마우스 위치를 이동시키기 }
void MakeMove() { int x; int y; // Reset heuristic if (gem_matched) { current_error_threshold = error_threshold; gem_matched = false; } for (y = 0; y < cell_count; y++) { for (x = 0; x < cell_count; x++) { // Try move left if (x - 1 >= 0) { CopyGrid(); if (CheckMatch(x, y, x - 1, y)) { MoveGem(x, y, x - 1, y); gem_matched = true; break; } } // Try move right if (x + 1 < cell_count) { CopyGrid(); if (CheckMatch(x,y,x+1,y)) { MoveGem(x, y, x + 1, y); gem_matched = true; break; } } // Try move up if (y - 1 >= 0) { CopyGrid(); if (CheckMatch(x, y, x, y - 1)) { MoveGem(x, y, x, y - 1); gem_matched = true; break; } } // Try move down if (y + 1 < cell_count) { CopyGrid(); if (CheckMatch(x, y, x, y + 1)) { MoveGem(x, y, x, y + 1); gem_matched = true; break; } } } if (gem_matched) break; } // If we didn't find a match, we'll need to make // our heuristic less picky. Increment threshold if (!gem_matched && current_error_threshold < 255) { // Before taking screenshot we'll want to reset the cursor // position to prevent hover animations of gems. This // could possibly help in the detection of matches SetCursorPos(game_origin.x, game_origin.y); current_error_threshold += 5; if (current_error_threshold >= 255) { printf("Need some help here.\n"); current_error_threshold = 255; } } }
KEYBOARDDLL_API int SendKey(const HWND hwnd, const RECT rect, UINT vkey, const HWND restore_focus, const POINT restore_cursor) { INPUT input[4]; POINT pt = RandomizeClickLocation(rect); double fScreenWidth = ::GetSystemMetrics( SM_CXSCREEN )-1; double fScreenHeight = ::GetSystemMetrics( SM_CYSCREEN )-1; // Translate click point to screen/mouse coords ClientToScreen(hwnd, &pt); double fx = pt.x*(65535.0f/fScreenWidth); double fy = pt.y*(65535.0f/fScreenHeight); // Set up the input structure int input_count=0; // First click in the rect to select it, if rect is not passed in as {-1, -1, -1, -1} if (rect.left!=-1 || rect.top!=-1 || rect.right!=-1 || rect.bottom!=-1) { ZeroMemory(&input[input_count],sizeof(INPUT)); input[input_count].type = INPUT_MOUSE; input[input_count].mi.dx = (LONG) fx; input[input_count].mi.dy = (LONG) fy; input[input_count].mi.dwFlags = MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_MOVE | MOUSEEVENTF_LEFTDOWN; input_count++; ZeroMemory(&input[input_count],sizeof(INPUT)); input[input_count].type = INPUT_MOUSE; input[input_count].mi.dx = (LONG) fx; input[input_count].mi.dy = (LONG) fy; input[input_count].mi.dwFlags = MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_MOVE | MOUSEEVENTF_LEFTUP; input_count++; } // Add vkey to the input struct ZeroMemory(&input[input_count],sizeof(INPUT)); input[input_count].type = INPUT_KEYBOARD; input[input_count].ki.wVk = vkey; input_count++; ZeroMemory(&input[input_count],sizeof(INPUT)); input[input_count].type = INPUT_KEYBOARD; input[input_count].ki.wVk = vkey; input[input_count].ki.dwFlags = KEYEVENTF_KEYUP; input_count++; // Set focus to target window SetFocus(hwnd); SetForegroundWindow(hwnd); SetActiveWindow(hwnd); // Send input SendInput(input_count, input, sizeof(INPUT)); // Restore previous window state and cursor position if (restore_focus!=NULL) { SetActiveWindow(restore_focus); SetForegroundWindow(restore_focus); SetFocus(restore_focus); } // Remove that code-block, if you don't want to restore the mouse-cursor! if (restore_cursor.x!=-1 && restore_cursor.y!=-1) { SetCursorPos(restore_cursor.x, restore_cursor.y); } return (int) true; }
//============================================================================== //============================================================================== geBoolean GMain_Startup(DRV_DriverHook *Hook) { int32 VidMode; //SetEnvironmentVariable("SST_GAMMA", "1.0"); switch(Hook->Mode) { case 0: { ClientWindow.Width = 512; ClientWindow.Height = 384; VidMode = GR_RESOLUTION_512x384; break; } case 1: { ClientWindow.Width = 640; ClientWindow.Height = 480; VidMode = GR_RESOLUTION_640x480; break; } case 2: { ClientWindow.Width = 800; ClientWindow.Height = 600; VidMode = GR_RESOLUTION_800x600; break; } case 3: { ClientWindow.Width = 1024; ClientWindow.Height = 768; VidMode = GR_RESOLUTION_1024x768; break; } default: { SetLastDrvError(DRV_ERROR_NULL_WINDOW, "GLIDE_DrvInit: Invalid display mode."); return FALSE; } } ClientWindow.hWnd = Hook->hWnd; // Go full-screen so we won't lose the mouse { RECT DeskTop; // Save the old window size GetWindowRect(ClientWindow.hWnd, &OldWindow); // Get the size of the desktop GetWindowRect(GetDesktopWindow(), &DeskTop); // Resize the window to the size of the desktop MoveWindow(ClientWindow.hWnd, DeskTop.left-4, DeskTop.top-40, DeskTop.right+20, DeskTop.bottom+20, TRUE); // Center the mouse SetCursorPos(ClientWindow.Width / 2, ClientWindow.Height / 2); } // initialize the Glide library grGlideInit(); // Get the info about this board if (!GMain_GetBoardInfo(&g_BoardInfo)) return FALSE; if (g_BoardInfo.NumTMU <= 0) { SetLastDrvError(DRV_ERROR_INIT_ERROR, "GLIDE_DrvInit: Not enough texture mapping units."); return GE_FALSE; } // select the current graphics system grSstSelect(0); // initialize and open the graphics system if (!grSstWinOpen( (U32)ClientWindow.hWnd, VidMode, GR_REFRESH_60Hz, GR_COLORFORMAT_ABGR, GR_ORIGIN_UPPER_LEFT, 2, 1 )) { SetLastDrvError(DRV_ERROR_INIT_ERROR, "GLIDE_DrvInit: grSstWinOpen failed."); return GE_FALSE; } // We know that GLIDE will be in 5-6-5 mode... ClientWindow.R_shift = 5+6; ClientWindow.G_shift = 5; ClientWindow.B_shift = 0; ClientWindow.R_mask = 0xf800; ClientWindow.G_mask = 0x07e0; ClientWindow.B_mask = 0x001f; ClientWindow.R_width = 5; ClientWindow.G_width = 6; ClientWindow.B_width = 5; SetLastDrvError(DRV_ERROR_NONE, "GMain_Startup: No error."); if (!GTHandle_Startup()) { SetLastDrvError(DRV_ERROR_GENERIC, "GMain_Startup: GTHandle_Startup failed...\n"); return GE_FALSE; } if (!GMain_InitGlideRegisters()) { SetLastDrvError(DRV_ERROR_GENERIC, "GMain_Startup: GMain_InitGlideRegisters failed...\n"); return GE_FALSE; } // Init the 3d display //grSstControl(GR_CONTROL_ACTIVATE); grGammaCorrectionValue(1.0f); return GE_TRUE; }
void g2LabelEdit::CopyBuffer() { // Win32 implementation #ifdef _WIN32 // Attempt to open clipboard if(!OpenClipboard(GetForegroundWindow())) return; // Empty current clipboard EmptyClipboard(); // Allocate a system resource (a memory buffer for the text) HGLOBAL TextHandle = GlobalAlloc(GMEM_MOVEABLE, (strlen(TextBuffer) + 1) * sizeof(char)); if(TextHandle == NULL) return; LPTSTR StringLock = (LPTSTR)GlobalLock(TextHandle); if(StringLock == NULL) return; strcpy(StringLock, TextBuffer); GlobalUnlock(TextHandle); // Copy to the clipboard SetClipboardData(CF_TEXT, TextHandle); // Close clipboard CloseClipboard(); // OSX implementation #elif __APPLE__ // Allocate or get a reference to the application's active clipboard PasteboardRef ClipboardHandle; if(PasteboardCreate(kPasteboardClipboard, &ClipboardHandle) != noErr) return; // Clear current clipboard if(PasteboardClear(ClipboardHandle) != noErr) return; // Explicitly update (after cleaning is important) PasteboardSynchronize(ClipboardHandle); // Create a system-wide buffer to give to the clipboard CFDataRef DataBuffer = CFDataCreate(kCFAllocatorDefault, (const UInt8*)TextBuffer, CFIndex((strlen(TextBuffer) + 1) * sizeof(char))); if(DataBuffer == NULL) return; // Paste into clipboard PasteboardPutItemFlavor(ClipboardHandle, (PasteboardItemID)1, CFSTR("public.utf8-plain-text"), DataBuffer, kPasteboardFlavorNoFlags); // Release data buffer CFRelease(DataBuffer); // Linux clipboard implementation #elif __linux__ // Paste into UI from linux buffer strcpy(__LinuxClipboard, TextBuffer); SetCursorPos((int)strlen(__LinuxClipboard)); #endif }
static void test_customdraw(void) { static struct { LRESULT FirstReturnValue; int ExpectedCalls; } expectedResults[] = { /* Valid notification responses */ {CDRF_DODEFAULT, TEST_CDDS_PREPAINT}, {CDRF_SKIPDEFAULT, TEST_CDDS_PREPAINT}, {CDRF_NOTIFYPOSTPAINT, TEST_CDDS_PREPAINT | TEST_CDDS_POSTPAINT}, /* Invalid notification responses */ {CDRF_NOTIFYITEMDRAW, TEST_CDDS_PREPAINT}, {CDRF_NOTIFYPOSTERASE, TEST_CDDS_PREPAINT}, {CDRF_NEWFONT, TEST_CDDS_PREPAINT} }; DWORD iterationNumber; WNDCLASSA wc; LRESULT lResult; /* Create a class to use the custom draw wndproc */ wc.style = CS_HREDRAW | CS_VREDRAW; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = GetModuleHandleA(NULL); wc.hIcon = NULL; wc.hCursor = LoadCursorA(NULL, (LPCSTR)IDC_ARROW); wc.hbrBackground = GetSysColorBrush(COLOR_WINDOW); wc.lpszMenuName = NULL; wc.lpszClassName = "CustomDrawClass"; wc.lpfnWndProc = custom_draw_wnd_proc; RegisterClassA(&wc); for (iterationNumber = 0; iterationNumber < sizeof(expectedResults)/sizeof(expectedResults[0]); iterationNumber++) { HWND parent, hwndTip; RECT rect; TTTOOLINFOA toolInfo = { 0 }; /* Create a main window */ parent = CreateWindowExA(0, "CustomDrawClass", NULL, WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_VISIBLE, 50, 50, 300, 300, NULL, NULL, NULL, 0); ok(parent != NULL, "Creation of main window failed\n"); /* Make it show */ ShowWindow(parent, SW_SHOWNORMAL); flush_events(100); /* Create Tooltip */ hwndTip = CreateWindowExA(WS_EX_TOPMOST, TOOLTIPS_CLASSA, NULL, TTS_NOPREFIX | TTS_ALWAYSTIP, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, parent, NULL, GetModuleHandleA(NULL), 0); ok(hwndTip != NULL, "Creation of tooltip window failed\n"); /* Set up parms for the wndproc to handle */ CD_Stages = 0; CD_Result = expectedResults[iterationNumber].FirstReturnValue; g_hwnd = hwndTip; /* Make it topmost, as per the MSDN */ SetWindowPos(hwndTip, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE); /* Create a tool */ toolInfo.cbSize = TTTOOLINFOA_V1_SIZE; toolInfo.hwnd = parent; toolInfo.hinst = GetModuleHandleA(NULL); toolInfo.uFlags = TTF_SUBCLASS; toolInfo.uId = 0x1234ABCD; toolInfo.lpszText = (LPSTR)"This is a test tooltip"; toolInfo.lParam = 0xdeadbeef; GetClientRect (parent, &toolInfo.rect); lResult = SendMessageA(hwndTip, TTM_ADDTOOLA, 0, (LPARAM)&toolInfo); ok(lResult, "Adding the tool to the tooltip failed\n"); /* Make tooltip appear quickly */ SendMessageA(hwndTip, TTM_SETDELAYTIME, TTDT_INITIAL, MAKELPARAM(1,0)); /* Put cursor inside window, tooltip will appear immediately */ GetWindowRect( parent, &rect ); SetCursorPos( (rect.left + rect.right) / 2, (rect.top + rect.bottom) / 2 ); flush_events(200); if (CD_Stages) { /* Check CustomDraw results */ ok(CD_Stages == expectedResults[iterationNumber].ExpectedCalls || broken(CD_Stages == (expectedResults[iterationNumber].ExpectedCalls & ~TEST_CDDS_POSTPAINT)), /* nt4 */ "CustomDraw run %d stages %x, expected %x\n", iterationNumber, CD_Stages, expectedResults[iterationNumber].ExpectedCalls); } /* Clean up */ DestroyWindow(hwndTip); DestroyWindow(parent); } }
void Win32Wrapper::MySetCursorPos(int x, int y) { SetCursorPos(x, y); }
BOOL CGmodeWnd::Exec() { int i; BOOL bPush = FALSE; POINT icPt; char str[MAX_PATH]; if(cgview_mode!=sysInf.execMode)return FALSE; switch(state){ case 0: case 2: case 4: case 5: time = bgInf.look_cnt-timeGetTime(); baseWnd.alpha = float(bgInf.look_max-time)/bgInf.look_max; if(time<=0){ baseWnd.alpha = 1.0f; bgInf.look_cnt = 0; if(state==4)state = 1; else state ++; } if(state==3 && (selectNum==5 || selectNum==6 || selectNum==7)){ bgInf.look_max = 2100; bgInf.look_cnt = timeGetTime() +bgInf.look_max; }else if(state==5){ baseWnd.alpha = 1.0f -baseWnd.alpha; }else if(state==6){ changeExecMode( opening_mode ); } panel[0].alpha = panel[1].alpha = button.alpha = baseWnd.alpha; return TRUE; case 1: if(keyState.push_action && selectNum>=0){ if(AVG_GetCgFlag(selectNum+1)==FALSE)break; PlayEffectNum(evtHandle[1],SelectSnd); wsprintf(str,"v00%02d0",selectNum); baseWnd.loadLGF(pack_eventcg,str); state = 2; bgInf.look_max = 900; bgInf.look_cnt = timeGetTime() +bgInf.look_max; panel[0].alpha = panel[1].alpha = button.alpha = baseWnd.alpha = 0; switch(selectNum){ case 5: scrollOffset.x = 680; scrollOffset.y = 0; break; case 6: scrollOffset.x = 0; scrollOffset.y = 600; break; case 7: scrollOffset.x = 0; scrollOffset.y = 0; break; } break; }else if(keyState.push_left || keyState.push_up){ bPush = TRUE; if(selectNum==0)selectNum = 11; else selectNum --; }else if(keyState.push_right || keyState.push_down){ bPush = TRUE; selectNum ++; if(selectNum > 11)selectNum = 0; } if(bPush){ icPt.x = 54 +(selectNum%4)*177 +50; icPt.y = 104 +(selectNum/4)*136 +50; ClientToScreen(sysInf.hWnd,&icPt); SetCursorPos(icPt.x, icPt.y); }else{ selectNum = -1; } for(i=0;i<12;i++){ rect.left = 54+ 177*(i%4); rect.right = rect.left +160; rect.top = 104+136*(i/4); rect.bottom = rect.top +120; if(PtInRect(&rect,sysInf.msPoint)){ selectNum = i; break; } } if(btn.CheckState(&sysInf.msPoint) || keyState.push_cancel){ PlayEffectNum(evtHandle[1],CancelSnd); baseWnd.BltFast(0,0,&g_DibInf.colorBuf,NULL,FALSE); state = 5; bgInf.look_max = 900; bgInf.look_cnt = timeGetTime() +bgInf.look_max; return TRUE; } break; case 3: switch(selectNum){ case 5: time = bgInf.look_cnt-timeGetTime(); if(time<=0){ scrollOffset.x = 0; scrollOffset.y = 680; }else{ scrollOffset.x = 680 -(bgInf.look_max-time)*680/bgInf.look_max; scrollOffset.y = (bgInf.look_max-time)*680/bgInf.look_max; } break; case 6: time = bgInf.look_cnt-timeGetTime(); scrollOffset.x = 0; if(time<=0){ scrollOffset.y = 0; }else{ scrollOffset.y = 600-(bgInf.look_max-time)*600/bgInf.look_max; } break; case 7: time = bgInf.look_cnt-timeGetTime(); scrollOffset.x = 0; if(time<=0){ scrollOffset.y = 600; }else{ scrollOffset.y = (bgInf.look_max-time)*600/bgInf.look_max; } break; } if(keyState.push_action || keyState.push_cancel){ PlayEffectNum(evtHandle[1],CancelSnd); baseWnd.loadLGF(pack_gparts,"CGmodeBase"); state = 4; bgInf.look_max = 900; bgInf.look_cnt = timeGetTime() +bgInf.look_max; panel[0].alpha = panel[1].alpha = button.alpha = baseWnd.alpha = 0; } break; } return TRUE; } // CGmodeWnd::Exec
//-------------------------------------------------------------- void testApp::setup() { ofSetFrameRate(30); //Initialize the training and info variables infoText = ""; trainingClassLabel = 1; record = false; noOfHands = 1; noOfTrackedHands = 0; //The input to the training data will be the [x y] from the mouse, so we set the number of dimensions to 2 trainingData.setNumDimensions( noOfHands*3 ); //trainingData.setNumDimensions( 3 ); //Initialize the DTW classifier DTW dtw; //Turn on null rejection, this lets the classifier output the predicted class label of 0 when the likelihood of a gesture is low dtw.enableNullRejection( true ); //Set the null rejection coefficient to 3, this controls the thresholds for the automatic null rejection //You can increase this value if you find that your real-time gestures are not being recognized //If you are getting too many false positives then you should decrease this value dtw.setNullRejectionCoeff( 3 ); //Turn on the automatic data triming, this will remove any sections of none movement from the start and end of the training samples dtw.enableTrimTrainingData(true, 0.1, 90); //Offset the timeseries data by the first sample, this makes your gestures (more) invariant to the location the gesture is performed dtw.setOffsetTimeseriesUsingFirstSample(true); //Add the classifier to the pipeline (after we do this, we don't need the DTW classifier anymore) pipeline.setClassifier( dtw ); //pipeline.inputVectorDimensions(3*noOfHands); ///setup nite niteRc = nite::NiTE::initialize(); if (niteRc != nite::STATUS_OK) { printf("NiTE initialization failed\n"); return; } niteRc = handTracker.create(); if (niteRc != nite::STATUS_OK) { printf("Couldn't create user tracker\n"); return; } handTracker.startGestureDetection(nite::GESTURE_CLICK); printf("\nPoint with your hand to start tracking it...\n"); //put cursor in the middle of the screen: SPI_GETWORKAREA int screenX = GetSystemMetrics(SM_CXSCREEN); int screenY = GetSystemMetrics(SM_CYSCREEN); SetCursorPos(screenX / 2, screenY / 2); xcursorpos = 500; ycursorpos = 500; }
void WinWindow::warpMouse(int x, int y) { SetCursorPos(x, y); }
bool ControllerInput::OISMouse_MouseMoved(const OIS::MouseEvent &arg) { // delta pixels int dx = arg.state.X.rel; int dy = arg.state.Y.rel; int dz = arg.state.Z.rel; if (dx == 0 && dy == 0 && dz == 0) return true; bool isAiming = false; // update flag whether mouse is in window or not IsMouseInWindow = ( arg.state.X.abs > 0 && arg.state.Y.abs > 0 && arg.state.X.abs < arg.state.width && arg.state.Y.abs < arg.state.height); // inject mousemove to cegui ControllerUI::InjectMousePosition((float)arg.state.X.abs, (float)arg.state.Y.abs); // if the cursor moved outside the window // make sure to release any pressed keys if (!isMouseInWindow) { if (IsLeftMouseDown) ControllerUI::InjectMouseButtonUp(CEGUI::MouseButton::LeftButton); if (IsRightMouseDown) ControllerUI::InjectMouseButtonUp(CEGUI::MouseButton::RightButton); } // exit conditions if (!OgreClient::Singleton->RenderWindow || !OgreClient::Singleton->RenderWindow->isVisible() || !OgreClient::Singleton->RenderWindow->isActive() || !OgreClient::Singleton->HasFocus || !isMouseInWindow) return true; // inject wheel ControllerUI::InjectMouseWheelChange((float)dz / 120.0f); // the cameranode SceneNode* cameraNode = OgreClient::Singleton->CameraNode; // exit conditions for 'actual playing' e.g. with avatar set if (OgreClient::Singleton->Data->IsWaiting || Avatar == nullptr || Avatar->SceneNode == nullptr || cameraNode == nullptr) return true; if (!isMouseWentDownOnUI) { // there is a small delay until aiming starts, to not shackle the // camera with any short mouseclick double dtRightButton = OgreClient::Singleton->GameTick->Current - tickMouseDownRight; double dtLeftButton = OgreClient::Singleton->GameTick->Current - tickMouseDownLeft; // right mousebutton (or both) pressed and dleay for mouseaim exceeded if (IsRightMouseDown && dtRightButton > MOUSELOOKMINDELAY) { if (dx != 0) { // stop immediately if we switched directions if (::System::Math::Sign(dx) != ::System::Math::Sign(avatarYawDelta)) avatarYawDelta = 0.0f; // set a new delta and stepsize // this will be processed tick based avatarYawDelta += MOUSELOOKSPEED * (float)OgreClient::Singleton->Config->MouseAimSpeed * (float)dx; avatarYawStep = MOUSELOOKSTEPFACT * avatarYawDelta * ::System::Math::Max((float)OgreClient::Singleton->GameTick->Span, 1.0f); isAiming = true; } if (dy != 0) { // invert mouse y if enabled in config if (OgreClient::Singleton->Config->InvertMouseY) dy = -dy; // stop immediately if we switched directions if (::System::Math::Sign(dy) != ::System::Math::Sign(cameraPitchDelta)) cameraPitchDelta = 0.0f; // set a new delta and stepsize // this will be processed tick based cameraPitchDelta += MOUSELOOKSPEED * (float)OgreClient::Singleton->Config->MouseAimSpeed * (float)dy; cameraPitchStep = MOUSELOOKSTEPFACT * cameraPitchDelta * ::System::Math::Max((float)OgreClient::Singleton->GameTick->Span, 1.0f); isAiming = true; } } // left mousebutton pressed and delay for mouseaim exceeded else if (IsLeftMouseDown && dtLeftButton > MOUSELOOKMINDELAY) { if (dx != 0) { // stop immediately if we switched directions if (::System::Math::Sign(dx) != ::System::Math::Sign(cameraYawDelta)) cameraYawDelta = 0.0f; // set a new delta and stepsize // this will be processed tick based cameraYawDelta += MOUSELOOKSPEED * (float)OgreClient::Singleton->Config->MouseAimSpeed * (float)dx; cameraYawStep = MOUSELOOKSTEPFACT * cameraYawDelta * ::System::Math::Max((float)OgreClient::Singleton->GameTick->Span, 1.0f); isAiming = true; } if (dy != 0) { // invert mouse y if enabled in config if (OgreClient::Singleton->Config->InvertMouseY) dy = -dy; // stop immediately if we switched directions if (::System::Math::Sign(dy) != ::System::Math::Sign(cameraPitchDelta)) cameraPitchDelta = 0.0f; // set a new delta and stepsize // this will be processed tick based cameraPitchDelta += MOUSELOOKSPEED * (float)OgreClient::Singleton->Config->MouseAimSpeed * (float)dy; cameraPitchStep = MOUSELOOKSTEPFACT * cameraPitchDelta * ::System::Math::Max((float)OgreClient::Singleton->GameTick->Span, 1.0f); isAiming = true; } } // mousewheel / zoom if (dz != 0 && ControllerUI::IgnoreTopControlForMouseInput) { // set a new delta and stepsize // this will be processed tick based cameraZDelta += ZOOMSPEED * (float)dz; cameraZStep = MOUSELOOKSTEPFACT * cameraZDelta * ::System::Math::Max((float)OgreClient::Singleton->GameTick->Span, 1.0f); } // restore/fixed windows cursor position on mouse look if (IsAnyMouseDown) SetCursorPos(mouseDownWindowsPosition->x, mouseDownWindowsPosition->y); } if (!isAiming && ControllerUI::IgnoreTopControlForMouseInput) PerformMouseOver(arg.state.X.abs, arg.state.Y.abs, false); return true; };
extern "C" BOOL EditPrint(HWND hwnd,LPCWSTR pszDocTitle,LPCWSTR pszPageFormat) { // Don't print empty documents if (SendMessage(hwnd,SCI_GETLENGTH,0,0) == 0) { MsgBox(MBWARN,IDS_PRINT_EMPTY); return TRUE; } int startPos; int endPos; HDC hdc; RECT rectMargins; RECT rectPhysMargins; RECT rectSetup; POINT ptPage; POINT ptDpi; //RECT rectSetup; TEXTMETRIC tm; int headerLineHeight; HFONT fontHeader; int footerLineHeight; HFONT fontFooter; WCHAR dateString[MIDSZ_BUFFER] = { L'\0' }; DOCINFO di = {sizeof(DOCINFO), nullptr, nullptr, nullptr, 0}; int lengthDoc; int lengthDocMax; int lengthPrinted; struct Sci_RangeToFormat frPrint; int pageNum; BOOL printPage; WCHAR pageString[32] = { L'\0' }; HPEN pen; HPEN penOld; PRINTDLG pdlg = { sizeof(PRINTDLG), nullptr, nullptr, nullptr, nullptr, 0, 0, 0, 0, 0, 0, nullptr, 0, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr }; pdlg.hwndOwner = GetParent(hwnd); pdlg.hInstance = g_hInstance; pdlg.Flags = PD_USEDEVMODECOPIES | PD_ALLPAGES | PD_RETURNDC; pdlg.nFromPage = 1; pdlg.nToPage = 1; pdlg.nMinPage = 1; pdlg.nMaxPage = 0xffffU; pdlg.nCopies = 1; pdlg.hDC = nullptr; pdlg.hDevMode = hDevMode; pdlg.hDevNames = hDevNames; startPos = (int)SendMessage(hwnd,SCI_GETSELECTIONSTART,0,0); endPos = (int)SendMessage(hwnd,SCI_GETSELECTIONEND,0,0); if (startPos == endPos) { pdlg.Flags |= PD_NOSELECTION; } else { pdlg.Flags |= PD_SELECTION; } // |= 0 - Don't display dialog box, just use the default printer and options pdlg.Flags |= (flagPrintFileAndLeave == 1) ? PD_RETURNDEFAULT : 0; if (!PrintDlg(&pdlg)) { return TRUE; // False means error... } hDevMode = pdlg.hDevMode; hDevNames = pdlg.hDevNames; hdc = pdlg.hDC; // Get printer resolution ptDpi.x = GetDeviceCaps(hdc, LOGPIXELSX); // dpi in X direction ptDpi.y = GetDeviceCaps(hdc, LOGPIXELSY); // dpi in Y direction // Start by getting the physical page size (in device units). ptPage.x = GetDeviceCaps(hdc, PHYSICALWIDTH); // device units ptPage.y = GetDeviceCaps(hdc, PHYSICALHEIGHT); // device units // Get the dimensions of the unprintable // part of the page (in device units). rectPhysMargins.left = GetDeviceCaps(hdc, PHYSICALOFFSETX); rectPhysMargins.top = GetDeviceCaps(hdc, PHYSICALOFFSETY); // To get the right and lower unprintable area, // we take the entire width and height of the paper and // subtract everything else. rectPhysMargins.right = ptPage.x // total paper width - GetDeviceCaps(hdc, HORZRES) // printable width - rectPhysMargins.left; // left unprintable margin rectPhysMargins.bottom = ptPage.y // total paper height - GetDeviceCaps(hdc, VERTRES) // printable height - rectPhysMargins.top; // right unprintable margin // At this point, rectPhysMargins contains the widths of the // unprintable regions on all four sides of the page in device units. // Take in account the page setup given by the user (if one value is not null) if (pagesetupMargin.left != 0 || pagesetupMargin.right != 0 || pagesetupMargin.top != 0 || pagesetupMargin.bottom != 0) { // Convert the hundredths of millimeters (HiMetric) or // thousandths of inches (HiEnglish) margin values // from the Page Setup dialog to device units. // (There are 2540 hundredths of a mm in an inch.) WCHAR localeInfo[3]; GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_IMEASURE, localeInfo, 3); if (localeInfo[0] == L'0') { // Metric system. L'1' is US System rectSetup.left = MulDiv (pagesetupMargin.left, ptDpi.x, 2540); rectSetup.top = MulDiv (pagesetupMargin.top, ptDpi.y, 2540); rectSetup.right = MulDiv(pagesetupMargin.right, ptDpi.x, 2540); rectSetup.bottom = MulDiv(pagesetupMargin.bottom, ptDpi.y, 2540); } else { rectSetup.left = MulDiv(pagesetupMargin.left, ptDpi.x, 1000); rectSetup.top = MulDiv(pagesetupMargin.top, ptDpi.y, 1000); rectSetup.right = MulDiv(pagesetupMargin.right, ptDpi.x, 1000); rectSetup.bottom = MulDiv(pagesetupMargin.bottom, ptDpi.y, 1000); } // Dont reduce margins below the minimum printable area rectMargins.left = max(rectPhysMargins.left, rectSetup.left); rectMargins.top = max(rectPhysMargins.top, rectSetup.top); rectMargins.right = max(rectPhysMargins.right, rectSetup.right); rectMargins.bottom = max(rectPhysMargins.bottom, rectSetup.bottom); } else { rectMargins.left = rectPhysMargins.left; rectMargins.top = rectPhysMargins.top; rectMargins.right = rectPhysMargins.right; rectMargins.bottom = rectPhysMargins.bottom; } // rectMargins now contains the values used to shrink the printable // area of the page. // Convert device coordinates into logical coordinates DPtoLP(hdc, (LPPOINT)&rectMargins, 2); DPtoLP(hdc, (LPPOINT)&rectPhysMargins, 2); // Convert page size to logical units and we're done! DPtoLP(hdc, (LPPOINT) &ptPage, 1); headerLineHeight = MulDiv(8,ptDpi.y, 72); fontHeader = CreateFont(headerLineHeight, 0, 0, 0, FW_BOLD, 0, 0, 0, 0, 0, 0, 0, 0, L"Arial"); SelectObject(hdc, fontHeader); GetTextMetrics(hdc, &tm); headerLineHeight = tm.tmHeight + tm.tmExternalLeading; if (iPrintHeader == 3) headerLineHeight = 0; footerLineHeight = MulDiv(7,ptDpi.y, 72); fontFooter = CreateFont(footerLineHeight, 0, 0, 0, FW_NORMAL, 0, 0, 0, 0, 0, 0, 0, 0, L"Arial"); SelectObject(hdc, fontFooter); GetTextMetrics(hdc, &tm); footerLineHeight = tm.tmHeight + tm.tmExternalLeading; if (iPrintFooter == 1) footerLineHeight = 0; di.lpszDocName = pszDocTitle; di.lpszOutput = nullptr; di.lpszDatatype = nullptr; di.fwType = 0; if (StartDoc(hdc, &di) < 0) { DeleteDC(hdc); if (fontHeader) DeleteObject(fontHeader); if (fontFooter) DeleteObject(fontFooter); return FALSE; } // Get current date... SYSTEMTIME st; GetLocalTime(&st); GetDateFormat(LOCALE_USER_DEFAULT,DATE_SHORTDATE,&st,nullptr,dateString,MIDSZ_BUFFER); // Get current time... if (iPrintHeader == 0) { WCHAR timeString[SMALL_BUFFER] = { L'\0' }; GetTimeFormat(LOCALE_USER_DEFAULT,TIME_NOSECONDS,&st,nullptr,timeString,SMALL_BUFFER); StringCchCat(dateString,COUNTOF(dateString),L" "); StringCchCat(dateString,COUNTOF(dateString),timeString); } // Set print color mode int printColorModes[5] = { SC_PRINT_NORMAL, SC_PRINT_INVERTLIGHT, SC_PRINT_BLACKONWHITE, SC_PRINT_COLOURONWHITE, SC_PRINT_COLOURONWHITEDEFAULTBG }; SendMessage(hwnd,SCI_SETPRINTCOLOURMODE,printColorModes[iPrintColor],0); // Set print zoom... SendMessage(hwnd,SCI_SETPRINTMAGNIFICATION,(WPARAM)iPrintZoom,0); lengthDoc = (int)SendMessage(hwnd,SCI_GETLENGTH,0,0); lengthDocMax = lengthDoc; lengthPrinted = 0; // Requested to print selection if (pdlg.Flags & PD_SELECTION) { if (startPos > endPos) { lengthPrinted = endPos; lengthDoc = startPos; } else { lengthPrinted = startPos; lengthDoc = endPos; } if (lengthPrinted < 0) lengthPrinted = 0; if (lengthDoc > lengthDocMax) lengthDoc = lengthDocMax; } // We must substract the physical margins from the printable area frPrint.hdc = hdc; frPrint.hdcTarget = hdc; frPrint.rc.left = rectMargins.left - rectPhysMargins.left; frPrint.rc.top = rectMargins.top - rectPhysMargins.top; frPrint.rc.right = ptPage.x - rectMargins.right - rectPhysMargins.left; frPrint.rc.bottom = ptPage.y - rectMargins.bottom - rectPhysMargins.top; frPrint.rcPage.left = 0; frPrint.rcPage.top = 0; frPrint.rcPage.right = ptPage.x - rectPhysMargins.left - rectPhysMargins.right - 1; frPrint.rcPage.bottom = ptPage.y - rectPhysMargins.top - rectPhysMargins.bottom - 1; frPrint.rc.top += headerLineHeight + headerLineHeight / 2; frPrint.rc.bottom -= footerLineHeight + footerLineHeight / 2; // Print each page pageNum = 1; while (lengthPrinted < lengthDoc) { printPage = (!(pdlg.Flags & PD_PAGENUMS) || (pageNum >= pdlg.nFromPage) && (pageNum <= pdlg.nToPage)); StringCchPrintf(pageString,COUNTOF(pageString),pszPageFormat,pageNum); if (printPage) { // Show wait cursor... SendMessage(g_hwndEdit, SCI_SETCURSOR, (WPARAM)SC_CURSORWAIT, 0); // Display current page number in Statusbar StatusUpdatePrintPage(pageNum); StartPage(hdc); SetTextColor(hdc, RGB(0,0,0)); SetBkColor(hdc, RGB(0xFF, 0xFF, 0xFF)); SelectObject(hdc, fontHeader); UINT ta = SetTextAlign(hdc, TA_BOTTOM); RECT rcw = {frPrint.rc.left, frPrint.rc.top - headerLineHeight - headerLineHeight / 2, frPrint.rc.right, frPrint.rc.top - headerLineHeight / 2}; rcw.bottom = rcw.top + headerLineHeight; if (iPrintHeader < 3) { ExtTextOut(hdc, frPrint.rc.left + 5, frPrint.rc.top - headerLineHeight / 2, /*ETO_OPAQUE*/0, &rcw, pszDocTitle, lstrlen(pszDocTitle), nullptr); } // Print date in header if (iPrintHeader == 0 || iPrintHeader == 1) { SIZE sizeInfo; SelectObject(hdc,fontFooter); GetTextExtentPoint32(hdc,dateString,StringCchLenW(dateString,COUNTOF(dateString)),&sizeInfo); ExtTextOut(hdc, frPrint.rc.right - 5 - sizeInfo.cx, frPrint.rc.top - headerLineHeight / 2, /*ETO_OPAQUE*/0, &rcw, dateString, StringCchLenW(dateString,COUNTOF(dateString)), nullptr); } if (iPrintHeader < 3) { SetTextAlign(hdc, ta); pen = CreatePen(0, 1, RGB(0,0,0)); penOld = (HPEN)SelectObject(hdc, pen); MoveToEx(hdc, frPrint.rc.left, frPrint.rc.top - headerLineHeight / 4, nullptr); LineTo(hdc, frPrint.rc.right, frPrint.rc.top - headerLineHeight / 4); SelectObject(hdc, penOld); DeleteObject(pen); } } frPrint.chrg.cpMin = lengthPrinted; frPrint.chrg.cpMax = lengthDoc; lengthPrinted = (int)SendMessage(hwnd, SCI_FORMATRANGE, printPage, (LPARAM)&frPrint); if (printPage) { SetTextColor(hdc, RGB(0,0,0)); SetBkColor(hdc, RGB(0xFF, 0xFF, 0xFF)); SelectObject(hdc, fontFooter); UINT ta = SetTextAlign(hdc, TA_TOP); RECT rcw = {frPrint.rc.left, frPrint.rc.bottom + footerLineHeight / 2, frPrint.rc.right, frPrint.rc.bottom + footerLineHeight + footerLineHeight / 2}; if (iPrintFooter == 0) { SIZE sizeFooter; GetTextExtentPoint32(hdc,pageString,StringCchLenW(pageString,COUNTOF(pageString)),&sizeFooter); ExtTextOut(hdc, frPrint.rc.right - 5 - sizeFooter.cx, frPrint.rc.bottom + footerLineHeight / 2, /*ETO_OPAQUE*/0, &rcw, pageString, StringCchLenW(pageString,COUNTOF(pageString)), nullptr); SetTextAlign(hdc, ta); pen = ::CreatePen(0, 1, RGB(0,0,0)); penOld = (HPEN)SelectObject(hdc, pen); SetBkColor(hdc, RGB(0,0,0)); MoveToEx(hdc, frPrint.rc.left, frPrint.rc.bottom + footerLineHeight / 4, nullptr); LineTo(hdc, frPrint.rc.right, frPrint.rc.bottom + footerLineHeight / 4); SelectObject(hdc, penOld); DeleteObject(pen); } EndPage(hdc); } pageNum++; if ((pdlg.Flags & PD_PAGENUMS) && (pageNum > pdlg.nToPage)) break; } SendMessage(hwnd,SCI_FORMATRANGE, FALSE, 0); EndDoc(hdc); DeleteDC(hdc); if (fontHeader) DeleteObject(fontHeader); if (fontFooter) DeleteObject(fontFooter); // Reset Statusbar to default mode StatusSetSimple(g_hwndStatus,FALSE); // Remove wait cursor... { POINT pt; SendMessage(g_hwndEdit, SCI_SETCURSOR, (WPARAM)SC_CURSORNORMAL, 0); GetCursorPos(&pt); SetCursorPos(pt.x, pt.y); } return TRUE; }
/************* * DESCRIPTION: handles movement of mouse * calls DoMouseMove from mouse.cpp * INPUT: nFlags Specifies if various flags are set * point coordinates of mouse cursor * OUTPUT: - *************/ void CCamView::OnMouseMove(UINT nFlags, CPoint point) { CPoint pntScreen; RECTANGLE r; pntScreen = point; ClientToScreen(&point); if (!bLeftButton) return; // return when OnMouseMove was caused from SetCursorPos if (pntOldCursor == point) return; if (pDisplay->editmode & EDIT_SELBOX) { if (pDisplay->boxmode == BOXMODE_RENDERWINDOW) pDisplay->GetRenderRect(&r); else { r.left = pDisplay->view->left; r.right = pDisplay->view->right; r.top = pDisplay->view->top; r.bottom = pDisplay->view->bottom; } pDisplay->DrawSelBox(); if (pntScreen.x < r.left) pDisplay->selbox.right = r.left; else { if (pntScreen.x > r.right) pDisplay->selbox.right = r.right; else pDisplay->selbox.right = pntScreen.x; } if (pntScreen.y < r.top) pDisplay->selbox.bottom = r.top; else { if (pntScreen.y > r.bottom) pDisplay->selbox.bottom = r.bottom; else pDisplay->selbox.bottom = pntScreen.y; } pDisplay->DrawSelBox(); } else { if (pDisplay->editmode & EDIT_ACTIVE) { if (nFlags & (MK_LBUTTON | MK_RBUTTON)) { mouse_data.oldmousex = pntOldCursor.x; mouse_data.oldmousey = pntOldCursor.y; DoMouseMove(pDisplay, point.x, point.y, &mouse_data); // Invalidate(FALSE); Redraw(REDRAW_OBJECTS, mouse_data.changed); SetCursorPos(pntOldCursor.x, pntOldCursor.y); mouse_data.changed = TRUE; } } } }
void IN_MouseMove (usercmd_t *cmd) { int mx, my; HDC hdc; int i; DIDEVICEOBJECTDATA od; DWORD dwElements; HRESULT hr; if (!mouseactive) return; if (dinput) { mx = 0; my = 0; for (;;) { dwElements = 1; hr = IDirectInputDevice_GetDeviceData(g_pMouse, sizeof(DIDEVICEOBJECTDATA), &od, &dwElements, 0); if ((hr == DIERR_INPUTLOST) || (hr == DIERR_NOTACQUIRED)) { dinput_acquired = true; IDirectInputDevice_Acquire(g_pMouse); break; } /* Unable to read data or no data available */ if (FAILED(hr) || dwElements == 0) { break; } /* Look at the element to see what happened */ switch (od.dwOfs) { case DIMOFS_X: mx += od.dwData; break; case DIMOFS_Y: my += od.dwData; break; case DIMOFS_BUTTON0: if (od.dwData & 0x80) mstate_di |= 1; else mstate_di &= ~1; break; case DIMOFS_BUTTON1: if (od.dwData & 0x80) mstate_di |= (1<<1); else mstate_di &= ~(1<<1); break; case DIMOFS_BUTTON2: if (od.dwData & 0x80) mstate_di |= (1<<2); else mstate_di &= ~(1<<2); break; } } // perform button actions for (i=0 ; i<mouse_buttons ; i++) { if ( (mstate_di & (1<<i)) && !(mouse_oldbuttonstate & (1<<i)) ) { Key_Event (K_MOUSE1 + i, true); } if ( !(mstate_di & (1<<i)) && (mouse_oldbuttonstate & (1<<i)) ) { Key_Event (K_MOUSE1 + i, false); } } mouse_oldbuttonstate = mstate_di; } else { GetCursorPos (¤t_pos); mx = current_pos.x - window_center_x + mx_accum; my = current_pos.y - window_center_y + my_accum; mx_accum = 0; my_accum = 0; } //if (mx || my) // Con_DPrintf("mx=%d, my=%d\n", mx, my); if (m_filter.value) { mouse_x = (mx + old_mouse_x) * 0.5; mouse_y = (my + old_mouse_y) * 0.5; } else { mouse_x = mx; mouse_y = my; } old_mouse_x = mx; old_mouse_y = my; mouse_x *= sensitivity.value; mouse_y *= sensitivity.value; // add mouse X/Y movement to cmd if ( (in_strafe.state & 1) || (lookstrafe.value && (in_mlook.state & 1) )) cmd->sidemove += m_side.value * mouse_x; else cl.viewangles[YAW] -= m_yaw.value * mouse_x; if (in_mlook.state & 1) V_StopPitchDrift (); if ( (in_mlook.state & 1) && !(in_strafe.state & 1)) { cl.viewangles[PITCH] += m_pitch.value * mouse_y; if (cl.viewangles[PITCH] > 80) cl.viewangles[PITCH] = 80; if (cl.viewangles[PITCH] < -70) cl.viewangles[PITCH] = -70; } else { if ((in_strafe.state & 1) && noclip_anglehack) cmd->upmove -= m_forward.value * mouse_y; else cmd->forwardmove -= m_forward.value * mouse_y; } // if the mouse has moved, force it to the center, so there's room to move if (mx || my) { SetCursorPos (window_center_x, window_center_y); } }
void g2LabelEdit::PasteBuffer() { // Win32 implementation #ifdef _WIN32 // Attempt to open clipboard if(!OpenClipboard(GetForegroundWindow())) return; // Get the windows clipboard text buffer HGLOBAL ClipboardHandle = GetClipboardData(CF_TEXT); if(ClipboardHandle != NULL) { // Actually copy the text LPTSTR StringLock = (LPTSTR)GlobalLock(ClipboardHandle); if (StringLock != NULL) { // Copy as much as we can char TempClipBuffer[g2LabelEdit_TextBufferLength]; strncpy(TempClipBuffer, StringLock, g2LabelEdit_TextBufferLength - strlen(TextBuffer) - strlen(StringLock) - 1); // Copy the current text buffer char TempTextBuffer[g2LabelEdit_TextBufferLength]; strcpy(TempTextBuffer, TextBuffer); // Copy into the full buffer (only if text is small enough) if(strlen(TempTextBuffer) + strlen(TempClipBuffer) + 1 < g2LabelEdit_TextBufferLength) { char NewTextBuffer[g2LabelEdit_TextBufferLength]; sprintf(NewTextBuffer, "%s%s", TempTextBuffer, TempClipBuffer); SetText(NewTextBuffer); } // Release the lock GlobalUnlock(StringLock); } } // Close clipboard CloseClipboard(); // OSX implementation #elif __APPLE__ // Allocate or get a reference to the application's active clipboard PasteboardRef ClipboardHandle; if(PasteboardCreate(kPasteboardClipboard, &ClipboardHandle) != noErr) return; // Explicitly update (possibly not needed...) PasteboardSynchronize(ClipboardHandle); // Get the item count ItemCount ClipboardItems; if(PasteboardGetItemCount(ClipboardHandle, &ClipboardItems) != noErr) return; // Keep searching until we find valid text for(ItemCount ItemIndex = 1; ItemIndex <= ClipboardItems; ItemIndex++) { // Get item's ID PasteboardItemID ItemID; if(PasteboardGetItemIdentifier(ClipboardHandle, ItemIndex, &ItemID) != noErr) continue; // Get this item's data types CFArrayRef ItemTypes; if(PasteboardCopyItemFlavors(ClipboardHandle, ItemID, &ItemTypes) != noErr) continue; // For each data type for this clipboard item CFIndex ItemCount = CFArrayGetCount(ItemTypes); for(CFIndex ItemTypeIndex = 0; ItemTypeIndex < ItemCount; ItemTypeIndex++) { // Get the data type CFStringRef ItemType = (CFStringRef)CFArrayGetValueAtIndex(ItemTypes, ItemTypeIndex); // If we have any text-type, then paste and stop if(UTTypeConformsTo(ItemType, CFSTR("public.utf8-plain-text"))) { // Copy from clipboard CFDataRef ItemData; if(PasteboardCopyItemFlavorData(ClipboardHandle, ItemID, ItemType, &ItemData) != noErr) continue; // Paste into active buffer CFIndex DateLength = CFDataGetLength(ItemData); size_t StartIndex = strlen(TextBuffer); char NewTempBuffer[g2LabelEdit_TextBufferLength]; strcpy(NewTempBuffer, TextBuffer); for(CFIndex i = 0; (i < DateLength) && (StartIndex + i < g2LabelEdit_TextBufferLength); i++) { char byte = *(CFDataGetBytePtr(ItemData) + i); NewTempBuffer[StartIndex + i] = byte; } // Cap string and set to current buffer NewTempBuffer[StartIndex + DateLength] = '\0'; SetText(NewTempBuffer); SetCursorPos((int)strlen(NewTempBuffer)); // Release CFRelease(ItemData); // Pasted and done! return; } } } // Linux clipboard implementation #elif __linux__ // Paste into UI from linux buffer SetText(__LinuxClipboard); SetCursorPos((int)strlen(__LinuxClipboard)); #endif }
void CheckBringKeyboard(void) { HMENU bringsysmenu = NULL; MENUITEMINFO mii; int input_count = 0, i = 0; INPUT input[100] = {0}; char temp[256] = {0}; CString c_text = ""; int keybd_item_pos = 0; int e = SUCCESS; if (!p_symbol_engine_casino->ConnectedToBring()) { write_log(preferences.debug_autoplayer(), "[BringKeyBoard] Not connected to bring, therefore no bring-keyboard to be enabled.\n"); return; } write_log(preferences.debug_autoplayer(), "[BringKeyBoard] Connected to bring.\n"); write_log(preferences.debug_autoplayer(), "[BringKeyBoard] Enabling bring-keyboard if necessary.\n"); // Init locals memset(&mii, 0, sizeof(MENUITEMINFO)); // Find position of "Keyboard" item on system menu bringsysmenu = GetSystemMenu(p_autoconnector->attached_hwnd(), false); mii.cbSize = sizeof(MENUITEMINFO); mii.fMask = MIIM_STRING; mii.fType = MFT_STRING; mii.dwTypeData = temp; keybd_item_pos = kUndefined; for (int i=GetMenuItemCount(bringsysmenu)-1; i>=0; --i) { mii.cch = 256; // Get the text of this menu item GetMenuItemInfo(bringsysmenu, i, true, &mii); c_text = temp; // See if this is the "keyboard" menu item if (c_text.MakeLower().Find("keyboard") != -1) { keybd_item_pos = i; continue; } } // Get state of keyboard menu item if (keybd_item_pos == kUndefined) { return; } mii.cbSize = sizeof(MENUITEMINFO); mii.fMask = MIIM_STATE; GetMenuItemInfo(bringsysmenu, keybd_item_pos, true, &mii); if (!(mii.fState&MFS_CHECKED)) { HWND hwnd_focus; POINT cur_pos = {0}; input_count = 0; // Alt key down ZeroMemory(&input[input_count],sizeof(INPUT)); input[input_count].type = INPUT_KEYBOARD; input[input_count].ki.wVk = VK_MENU; input_count++; // Space bar down ZeroMemory(&input[input_count],sizeof(INPUT)); input[input_count].type = INPUT_KEYBOARD; input[input_count].ki.wVk = VK_SPACE; input_count++; // Space bar up ZeroMemory(&input[input_count],sizeof(INPUT)); input[input_count].type = INPUT_KEYBOARD; input[input_count].ki.wVk = VK_SPACE; input[input_count].ki.dwFlags = KEYEVENTF_KEYUP; input_count++; // Alt key up ZeroMemory(&input[input_count],sizeof(INPUT)); input[input_count].type = INPUT_KEYBOARD; input[input_count].ki.wVk = VK_MENU; input[input_count].ki.dwFlags = KEYEVENTF_KEYUP; input_count++; CMyMutex mutex; if (!mutex.IsLocked()) return; hwnd_focus = GetFocus(); GetCursorPos(&cur_pos); SetFocus(p_autoconnector->attached_hwnd()); SetForegroundWindow(p_autoconnector->attached_hwnd()); SetActiveWindow(p_autoconnector->attached_hwnd()); SendInput(input_count, input, sizeof(INPUT)); Sleep(200); input_count = 0; // K down ZeroMemory(&input[input_count],sizeof(INPUT)); input[input_count].type = INPUT_KEYBOARD; input[input_count].ki.wVk = 'K'; input_count++; // K up ZeroMemory(&input[input_count],sizeof(INPUT)); input[input_count].type = INPUT_KEYBOARD; input[input_count].ki.wVk = 'K'; input[input_count].ki.dwFlags = KEYEVENTF_KEYUP; input_count++; SetFocus(p_autoconnector->attached_hwnd()); SetForegroundWindow(p_autoconnector->attached_hwnd()); SetActiveWindow(p_autoconnector->attached_hwnd()); SendInput(input_count, input, sizeof(INPUT)); SetActiveWindow(hwnd_focus); SetForegroundWindow(hwnd_focus); SetFocus(hwnd_focus); SetCursorPos(cur_pos.x, cur_pos.y); } }
void mouseMove(uint32_t x, uint32_t y) { SetCursorPos(x, y); }
LRESULT CALLBACK Window::windowProc( HWND hWnd, UINT uMessage, WPARAM wParam, LPARAM lParam ) { PAINTSTRUCT ps; switch (uMessage) { case WM_LBUTTONDOWN: break; case WM_MOUSEMOVE: static POINT cursor; //Refactor later; POINT cur; GetCursorPos(&cur); if ((cursor.x != cur.x) || (cursor.y != cur.y)) { RECT rect; //GetClientRect(hWnd, rect); GetWindowRect(GetDesktopWindow(),(LPRECT)&rect); InputManager::instance()->onMouseMove(cursor); SetCursorPos(rect.right/2,rect.bottom/2); cursor.x = cur.x; cursor.y = cur.y; } break; case WM_LBUTTONUP: break; case WM_SIZE: switch (wParam) { case SIZE_RESTORED: //CCApplication::sharedApplication().applicationWillEnterForeground(); break; case SIZE_MINIMIZED: //CCApplication::sharedApplication().applicationDidEnterBackground(); break; } break; case WM_KEYDOWN: InputManager::instance()->onKeyDown(wParam); break; case WM_KEYUP: InputManager::instance()->onKeyUp(wParam); break; case WM_CHAR: { if (wParam < 0x20) { if (VK_BACK == wParam) { } else if (VK_RETURN == wParam) { } else if (VK_TAB == wParam) { } else if (VK_ESCAPE == wParam) { // ESC input //CCDirector::sharedDirector()->end(); } } else if (wParam < 128) { } } break; case WM_PAINT: BeginPaint(_hwnd, &ps); EndPaint(_hwnd, &ps); break; case WM_CLOSE: //CCDirector::sharedDirector()->end(); Director::instance()->end(); break; case WM_DESTROY: PostQuitMessage(0); break; default: return DefWindowProc(_hwnd, uMessage, wParam, lParam); } return 0; }
KEYBOARDDLL_API int SendString(const HWND hwnd, const RECT rect, const CString s, const bool use_comma, const HWND restore_focus, const POINT restore_cursor) { INPUT input[102]; POINT pt = RandomizeClickLocation(rect); double fScreenWidth = ::GetSystemMetrics( SM_CXSCREEN )-1; double fScreenHeight = ::GetSystemMetrics( SM_CYSCREEN )-1; // Translate click point to screen/mouse coords ClientToScreen(hwnd, &pt); double fx = pt.x*(65535.0f/fScreenWidth); double fy = pt.y*(65535.0f/fScreenHeight); // Set up the input structure int input_count=0; // First click in the rect to select it, if rect is not passed in as {-1, -1, -1, -1} if (rect.left!=-1 || rect.top!=-1 || rect.right!=-1 || rect.bottom!=-1) { ZeroMemory(&input[input_count],sizeof(INPUT)); input[input_count].type = INPUT_MOUSE; input[input_count].mi.dx = (LONG) fx; input[input_count].mi.dy = (LONG) fy; input[input_count].mi.dwFlags = MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_MOVE | MOUSEEVENTF_LEFTDOWN; input_count++; ZeroMemory(&input[input_count],sizeof(INPUT)); input[input_count].type = INPUT_MOUSE; input[input_count].mi.dx = (LONG) fx; input[input_count].mi.dy = (LONG) fy; input[input_count].mi.dwFlags = MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_MOVE | MOUSEEVENTF_LEFTUP; input_count++; } // Set focus to target window SetFocus(hwnd); SetForegroundWindow(hwnd); SetActiveWindow(hwnd); // Send input SendInput(input_count, input, sizeof(INPUT)); // Send each character of the string via PlayKeyboardEvent char ch_str[100]; sprintf_s(ch_str, 100, "%s", s.GetString()); int vkey = 0; int i = 0, strlength = (int)strlen(ch_str); short KeyScan; for (int i=0; i<strlength; i++) { Sleep(20); if (use_comma && ch_str[i]=='.') ch_str[i] = ','; KeyScan = VkKeyScan(ch_str[i]); PlayKeyboardEvent(LOBYTE(KeyScan), HIBYTE(KeyScan)); } Sleep(20); // Restore previous window state and cursor position if (restore_focus!=NULL) { SetActiveWindow(restore_focus); SetForegroundWindow(restore_focus); SetFocus(restore_focus); } // Remove that code-block, if you don't want to restore the mouse-cursor! if (restore_cursor.x!=-1 && restore_cursor.y!=-1) { SetCursorPos(restore_cursor.x, restore_cursor.y); } return (int) true; }
unsigned int CGame::Update(void) { if ( KEYMGR->OnceKeyDown('K') ) SOUNDMGR->PlaySound(MOB_KNIGHT_ATTACK); if ( !m_bIsStop ) { //세이브 (일단 실시간) DATAMGR->Save(); GetCursorPos(&CMouse); // 마우스 위치 받음 ScreenToClient(HWnd,&CMouse); // 현재 게임창의 왼쪽 맨위 를 0,0으로 인식하게 함 if(m_bSelectEnemy == false) //적 선택하기 { //마우스로 고를때 if(( 100 < CMouse.x && CMouse.x < 600) && (220 < CMouse.y && CMouse.y < 860)) { EnemySelect = 1; if(KEYMGR->OnceKeyDown(VK_LBUTTON)) { EnemyClick = 1; m_bSelectEnemy = true; } } else if((680 < CMouse.x && CMouse.x < 1180) && (220 < CMouse.y && CMouse.y < 860)) { EnemySelect = 2; if(KEYMGR->OnceKeyDown(VK_LBUTTON)) { EnemyClick = 2; m_bSelectEnemy = true; } } // //키보드로 고를때 if(KEYMGR->OnceKeyDown(VK_LEFT)) EnemySelect -= 1; if(KEYMGR->OnceKeyDown(VK_RIGHT)) EnemySelect += 1; if(EnemySelect > 2) EnemySelect = 1; if(EnemySelect < 1) EnemySelect = 2; if(KEYMGR->OnceKeyDown(VK_RETURN)) { if (EnemySelect == 1) EnemyClick = 1, m_bSelectEnemy = true; else if (EnemySelect == 2) EnemyClick = 2, m_bSelectEnemy = true; } // } //난이도 고르기 if((m_bSelectEnemy == true) && (m_bSelectDifficulty == false)) { //마우스로 고를때 //이지 if(( 500 < CMouse.x && CMouse.x < 780) && (210 < CMouse.y && CMouse.y < 330)) { DSelect = 1; if(KEYMGR->OnceKeyDown(VK_LBUTTON)) { DClick = 1; m_bSelectDifficulty = true; } } //노말 else if((500 < CMouse.x && CMouse.x < 780) && (420 < CMouse.y && CMouse.y < 540)) { DSelect = 2; if(KEYMGR->OnceKeyDown(VK_LBUTTON)) { DClick = 2; m_bSelectDifficulty = true; } } //하드 else if((500 < CMouse.x && CMouse.x < 780) && (625 < CMouse.y && CMouse.y < 745)) { DSelect = 3; if(KEYMGR->OnceKeyDown(VK_LBUTTON)) { DClick = 3; m_bSelectDifficulty = true; } } // //키보드로 고를때 if(KEYMGR->OnceKeyDown(VK_UP)) DSelect -= 1; if(KEYMGR->OnceKeyDown(VK_DOWN)) DSelect += 1; if(DSelect > 3) DSelect = 1; if(DSelect < 1) DSelect = 3; if(KEYMGR->OnceKeyDown(VK_RETURN)) { if (DSelect == 1) DClick = 1, m_bSelectDifficulty = true; else if (DSelect == 2) DClick = 2, m_bSelectDifficulty = true; else if (DSelect == 3) DClick = 3, m_bSelectDifficulty = true; } if(m_bSelectEnemy) { //난이도에 따라 적 증감 switch(EnemyClick) { case 1: MOBMGR->FreeInst(); if(DClick == 1) { MOBMGR->AddMob( KNIGHT ); } else if(DClick == 2) { MOBMGR->AddMob( KNIGHT ); MOBMGR->AddMob( KNIGHT, D3DXVECTOR3( 120.0f, 0.0f, 100.0f ), D3DXVECTOR3 ( 0.1f, 0.15f, 0.15f ), 2.7f ); } else if(DClick == 3) { MOBMGR->AddMob( KNIGHT ); MOBMGR->AddMob( KNIGHT, D3DXVECTOR3( 120.0f, 0.0f, 100.0f ), D3DXVECTOR3 ( 0.1f, 0.15f, 0.15f ), 2.7f ); MOBMGR->AddMob( KNIGHT, D3DXVECTOR3( 80.0f, 0.0f, 100.0f ), D3DXVECTOR3 ( 0.1f, 0.15f, 0.15f ), 2.7f ); } break; case 2: MOBMGR->FreeInst(); if(DClick == 1) { MOBMGR->AddMob( ALDUIN ); } else if(DClick == 2) { MOBMGR->AddMob( ALDUIN ); MOBMGR->AddMob( ALDUIN, D3DXVECTOR3( -100.0f, 0.0f, -100.0f ), D3DXVECTOR3 ( 0.1f, 0.1f, 0.1f ), 2.7f); } else if(DClick == 3) { MOBMGR->AddMob( ALDUIN ); MOBMGR->AddMob( ALDUIN, D3DXVECTOR3( -100.0f, 0.0f, -100.0f ), D3DXVECTOR3 ( 0.1f, 0.1f, 0.1f ), 2.7f); MOBMGR->AddMob( ALDUIN, D3DXVECTOR3( 130.0f, 0.0f, 0.0f ), D3DXVECTOR3 ( 0.1f, 0.1f, 0.1f ), 2.7f ); } break; } // } } //적선택이 끝나면 무기선택시작 if((m_bSelectEnemy == true) && (m_bChoiceWp == false) && (DClick >= 1)) { //마우스로 선택 if(( 100 < CMouse.x && CMouse.x < 600) && (220 < CMouse.y && CMouse.y < 860)) { Select = 1; if(KEYMGR->OnceKeyDown(VK_LBUTTON)) { Click = 1; m_bChoiceWp = true; } } else if((680 < CMouse.x && CMouse.x < 1180) && (220 < CMouse.y && CMouse.y < 860)) { Select = 2; if(KEYMGR->OnceKeyDown(VK_LBUTTON)) { Click = 2; m_bChoiceWp = true; } } // //키보드로 고를때 if(KEYMGR->OnceKeyDown(VK_LEFT)) Select -= 1; if(KEYMGR->OnceKeyDown(VK_RIGHT)) Select += 1; if(Select > 2) Select = 1; if(Select < 1) Select = 2; if(KEYMGR->OnceKeyDown(VK_RETURN)) { if (Select == 1) Click = 1, m_bChoiceWp = true; else if (Select == 2) Click = 2, m_bChoiceWp = true; } // if(m_bChoiceWp) { //무기선택 완료시 캐릭터 초기화 switch(Click) { case 1: CHARMGR->Init(1); break; case 2: CHARMGR->Init(2); break; } } } //적선택과 무기선택이 끝난 후 실행되는 업데이트 if(( m_bChoiceWp == true) && ( m_bSelectEnemy == true)) { if( m_bIsShowMS == TRUE ) { m_bIsShowMS = FALSE; ShowCursor(m_bIsShowMS); } MOBMGR->Update(); MOBMGR->SetIterBengin(); while ( MOBMGR->GetIter() != MOBMGR->IterEnd() ) { //(MOBMGR->MobVec(MOBMGR->GetIter()))->Update(); UIBAR( (MOBMGR->MobVec(MOBMGR->GetIter()))->GetBeHit() ); // HP 바 MOBMGR->IterInc(); } CHARMGR->Update(); CAMMGR->Update(); //마우스 위치 초기화 SetCursorPos(CENTERPOS_X,CENTERPOS_Y); //마우스커서 숨기기 //LoadCursor(NULL,NULL); } } // esc를 한번도 안눌렀다면 들어옴 누르면 안들어옴 다시 누르면 들어옴 if ( KEYMGR->OnceKeyDown(VK_ESCAPE) && ( m_bSelectEnemy == true) && (m_bChoiceWp == true)) { //멈춤 switch( m_bIsStop ) { case 0: { m_bIsStop = TRUE; ShowCursor(m_bIsStop); break; } case 1: { m_bIsStop = FALSE; ShowCursor(m_bIsStop); break; } } } //옵션켰을때 게임업데이트 멈추고 옵션업데이트 if ( m_bIsStop ) { COPTION->Update(); } return 0UL; }
void Int10Handler(struct Registers * registers) { //Call the function for this function code switch(registers->r_ax.b.h) { //int 0x10/ah=0x00: Set video mode case 0x00: SetMode(registers); break; //int 0x10/ah=0x01: Set text mode cursor shape - Unimplemented case 0x01: break; //int 0x10/ah=0x02: Set cursor position case 0x02: SetCursorPos(registers->r_dx.b.l, registers->r_dx.b.h); break; //int 0x10/ah=0x03: Get cursor position and size //TODO: Cursor size case 0x03: registers->r_dx.w = *(Word far *)MK_FP(BDA_SEG, BDA_CURSOR_X); break; //int 0x10/ah=0x05: Set active display page - Unimplemented case 0x05: break; //int 0x10/ah=0x06: Scroll up window case 0x06: ScrollUpWindow(registers); break; //int 0x10/ah=0x07: Scroll down window case 0x07: ScrollDownWindow(registers); break; //int 0x10/ah=0x08: Read character and attribute case 0x08: ReadCharacterAndAttribute(registers); break; //int 0x10/ah=0x09: Write character and attribute case 0x09: { Word i; for(i = 0; i < registers->r_cx.w; ++i) WriteCharacter(registers->r_ax.b.l, TRUE, registers->r_bx.b.l); } break; //int 0x10/ah=0x0a: Write character case 0x0a: { Word i; for(i = 0; i < registers->r_cx.w; ++i) WriteCharacter(registers->r_ax.b.l, FALSE, 0x00); } break; //int 0x10/ah=0x0b: Function selected by bh - None implemented case 0x0b: break; //int 0x10/ah=0x0e: Teletype output case 0x0e: WriteCharacter(registers->r_ax.b.l, FALSE, 0x00); break; //int 0x10/ah=0x0f: Get current video mode case 0x0f: registers->r_ax.b.h = 0x50; //AH: Number of character columns - TODO registers->r_ax.b.l = *(Byte far *)MK_FP(BDA_SEG, BDA_VIDEO_MODE); //AL: Video mode break; //int 0x10/ah=0x10: Function selected by al case 0x10: switch(registers->r_ax.b.l) { //int 0x10/ax=0x1000: Set palette register case 0x00: { Word ioPortBase = *(Word far *)MK_FP(BDA_SEG, BDA_VGA_IO_PORT_BASE); inportb(ioPortBase + 6); outportb(0x3c0, registers->r_bx.b.l); outportb(0x3c0, registers->r_bx.b.h); } break; //int 0x10/ax=0x1001: Set border color - Not supported case 0x01: break; //int 0x10/ax=0x1002: Set all palette registers case 0x02: SetAllPaletteRegisters(registers); break; //int 0x10/ax=0x1003: Toggle intensity/blinking bit case 0x03: ToggleBlinking(registers->r_bx.b.l); break; //int 0x10/ax=0x1010: Set color register case 0x10: outportb(0x03c8, registers->r_bx.b.l); outportb(0x03c9, registers->r_cx.b.h); outportb(0x03c9, registers->r_cx.b.l); outportb(0x03c9, registers->r_dx.b.h); break; //int 0x10/ax=0x1012: Set block of color registers case 0x12: SetColorRegisters(registers); break; } break; //int 0x10/ah=0x11: Character generator functions - Unimplemented case 0x11: break; //int 0x10/ah=0x12: Alternate function select, selected by bl case 0x12: switch(registers->r_bx.b.l) { //int 0x10/ah=0x12/bl=0x10: Get EGA info case 0x10: registers->r_ax.b.l = 0x03; //AL: Unknown //BH: Color/Mono mode in effect registers->r_bx.b.h = (*(Word far *)MK_FP(BDA_SEG, BDA_VGA_IO_PORT_BASE) == 0x3d4) ? 0x00 : 0x01; registers->r_bx.b.l = 0x03; //BL: 256K memory installed registers->r_cx.b.h = 0x00; //CH: Feature connector bits registers->r_cx.b.l = 0x09; //CL: Switch settings break; } break; //int 0x10/ah=0x1a: Display combination code functions, selected by al case 0x1a: switch(registers->r_ax.b.l) { //int 0x10/ax=0x1a00: Get display combination code case 0x00: registers->r_bx.w = *(Word far *)MK_FP(EBDA_SEG, EBDA_DISPLAY_CODE); //Return "function supported" registers->r_ax.b.l = 0x1a; break; //int 0x10/ax=0x1a01: Set display combination code case 0x01: *(Word far *)MK_FP(EBDA_SEG, EBDA_DISPLAY_CODE) = registers->r_bx.w; //Return "function supported" registers->r_ax.b.l = 0x1a; break; } break; //int 0x10/ah=0x1b: Functionality/state information - Unimplemented case 0x1b: break; //int 0x10/ah=0x4f: VESA VBE functions - Unimplemented case 0x4f: break; //int 0x10/ah=0x6f: Video7 VGA functions, selected by al - None supported case 0x6f: break; } }
void CL_DLLEXPORT CAM_Think( void ) { RecClCamThink(); #ifdef HL_CAMERA vec3_t origin; vec3_t ext, pnt, camForward, camRight, camUp; moveclip_t clip; float dist; vec3_t camAngles; float flSensitivity; #ifdef LATER int i; #endif vec3_t viewangles; switch( (int) cam_command->value ) { case CAM_COMMAND_TOTHIRDPERSON: CAM_ToThirdPerson(); break; case CAM_COMMAND_TOFIRSTPERSON: CAM_ToFirstPerson(); break; case CAM_COMMAND_NONE: default: break; } if( !cam_thirdperson ) return; #ifdef LATER if ( cam_contain->value ) { gEngfuncs.GetClientOrigin( origin ); ext[0] = ext[1] = ext[2] = 0.0; } #endif camAngles[ PITCH ] = cam_idealpitch->value; camAngles[ YAW ] = cam_idealyaw->value; dist = cam_idealdist->value; // //movement of the camera with the mouse // if (cam_mousemove) { //get windows cursor position GetCursorPos (&cam_mouse); //check for X delta values and adjust accordingly //eventually adjust YAW based on amount of movement //don't do any movement of the cam using YAW/PITCH if we are zooming in/out the camera if (!cam_distancemove) { //keep the camera within certain limits around the player (ie avoid certain bad viewing angles) if (cam_mouse.x>gEngfuncs.GetWindowCenterX()) { //if ((camAngles[YAW]>=225.0)||(camAngles[YAW]<135.0)) if (camAngles[YAW]<c_maxyaw->value) { camAngles[ YAW ] += (CAM_ANGLE_MOVE)*((cam_mouse.x-gEngfuncs.GetWindowCenterX())/2); } if (camAngles[YAW]>c_maxyaw->value) { camAngles[YAW]=c_maxyaw->value; } } else if (cam_mouse.x<gEngfuncs.GetWindowCenterX()) { //if ((camAngles[YAW]<=135.0)||(camAngles[YAW]>225.0)) if (camAngles[YAW]>c_minyaw->value) { camAngles[ YAW ] -= (CAM_ANGLE_MOVE)* ((gEngfuncs.GetWindowCenterX()-cam_mouse.x)/2); } if (camAngles[YAW]<c_minyaw->value) { camAngles[YAW]=c_minyaw->value; } } //check for y delta values and adjust accordingly //eventually adjust PITCH based on amount of movement //also make sure camera is within bounds if (cam_mouse.y>gEngfuncs.GetWindowCenterY()) { if(camAngles[PITCH]<c_maxpitch->value) { camAngles[PITCH] +=(CAM_ANGLE_MOVE)* ((cam_mouse.y-gEngfuncs.GetWindowCenterY())/2); } if (camAngles[PITCH]>c_maxpitch->value) { camAngles[PITCH]=c_maxpitch->value; } } else if (cam_mouse.y<gEngfuncs.GetWindowCenterY()) { if (camAngles[PITCH]>c_minpitch->value) { camAngles[PITCH] -= (CAM_ANGLE_MOVE)*((gEngfuncs.GetWindowCenterY()-cam_mouse.y)/2); } if (camAngles[PITCH]<c_minpitch->value) { camAngles[PITCH]=c_minpitch->value; } } //set old mouse coordinates to current mouse coordinates //since we are done with the mouse if ( ( flSensitivity = gHUD.GetSensitivity() ) != 0 ) { cam_old_mouse_x=cam_mouse.x*flSensitivity; cam_old_mouse_y=cam_mouse.y*flSensitivity; } else { cam_old_mouse_x=cam_mouse.x; cam_old_mouse_y=cam_mouse.y; } SetCursorPos (gEngfuncs.GetWindowCenterX(), gEngfuncs.GetWindowCenterY()); } } //Nathan code here if( CL_KeyState( &cam_pitchup ) ) camAngles[ PITCH ] += CAM_ANGLE_DELTA; else if( CL_KeyState( &cam_pitchdown ) ) camAngles[ PITCH ] -= CAM_ANGLE_DELTA; if( CL_KeyState( &cam_yawleft ) ) camAngles[ YAW ] -= CAM_ANGLE_DELTA; else if( CL_KeyState( &cam_yawright ) ) camAngles[ YAW ] += CAM_ANGLE_DELTA; if( CL_KeyState( &cam_in ) ) { dist -= CAM_DIST_DELTA; if( dist < CAM_MIN_DIST ) { // If we go back into first person, reset the angle camAngles[ PITCH ] = 0; camAngles[ YAW ] = 0; dist = CAM_MIN_DIST; } } else if( CL_KeyState( &cam_out ) ) dist += CAM_DIST_DELTA; if (cam_distancemove) { if (cam_mouse.y>gEngfuncs.GetWindowCenterY()) { if(dist<c_maxdistance->value) { dist +=CAM_DIST_DELTA * ((cam_mouse.y-gEngfuncs.GetWindowCenterY())/2); } if (dist>c_maxdistance->value) { dist=c_maxdistance->value; } } else if (cam_mouse.y<gEngfuncs.GetWindowCenterY()) { if (dist>c_mindistance->value) { dist -= (CAM_DIST_DELTA)*((gEngfuncs.GetWindowCenterY()-cam_mouse.y)/2); } if (dist<c_mindistance->value) { dist=c_mindistance->value; } } //set old mouse coordinates to current mouse coordinates //since we are done with the mouse cam_old_mouse_x=cam_mouse.x*gHUD.GetSensitivity(); cam_old_mouse_y=cam_mouse.y*gHUD.GetSensitivity(); SetCursorPos (gEngfuncs.GetWindowCenterX(), gEngfuncs.GetWindowCenterY()); } #ifdef LATER if( cam_contain->value ) { // check new ideal VectorCopy( origin, pnt ); AngleVectors( camAngles, camForward, camRight, camUp ); for (i=0 ; i<3 ; i++) pnt[i] += -dist*camForward[i]; // check line from r_refdef.vieworg to pnt memset ( &clip, 0, sizeof ( moveclip_t ) ); clip.trace = SV_ClipMoveToEntity( sv.edicts, r_refdef.vieworg, ext, ext, pnt ); if( clip.trace.fraction == 1.0 ) { // update ideal cam_idealpitch->value = camAngles[ PITCH ]; cam_idealyaw->value = camAngles[ YAW ]; cam_idealdist->value = dist; } } else #endif { // update ideal cam_idealpitch->value = camAngles[ PITCH ]; cam_idealyaw->value = camAngles[ YAW ]; cam_idealdist->value = dist; } // Move towards ideal VectorCopy( cam_ofs, camAngles ); gEngfuncs.GetViewAngles( (float *)viewangles ); if( cam_snapto->value ) { camAngles[ YAW ] = cam_idealyaw->value + viewangles[ YAW ]; camAngles[ PITCH ] = cam_idealpitch->value + viewangles[ PITCH ]; camAngles[ 2 ] = cam_idealdist->value; } else { if( camAngles[ YAW ] - viewangles[ YAW ] != cam_idealyaw->value ) camAngles[ YAW ] = MoveToward( camAngles[ YAW ], cam_idealyaw->value + viewangles[ YAW ], CAM_ANGLE_SPEED ); if( camAngles[ PITCH ] - viewangles[ PITCH ] != cam_idealpitch->value ) camAngles[ PITCH ] = MoveToward( camAngles[ PITCH ], cam_idealpitch->value + viewangles[ PITCH ], CAM_ANGLE_SPEED ); if( abs( camAngles[ 2 ] - cam_idealdist->value ) < 2.0 ) camAngles[ 2 ] = cam_idealdist->value; else camAngles[ 2 ] += ( cam_idealdist->value - camAngles[ 2 ] ) / 4.0; } #ifdef LATER if( cam_contain->value ) { // Test new position dist = camAngles[ ROLL ]; camAngles[ ROLL ] = 0; VectorCopy( origin, pnt ); AngleVectors( camAngles, camForward, camRight, camUp ); for (i=0 ; i<3 ; i++) pnt[i] += -dist*camForward[i]; // check line from r_refdef.vieworg to pnt memset ( &clip, 0, sizeof ( moveclip_t ) ); ext[0] = ext[1] = ext[2] = 0.0; clip.trace = SV_ClipMoveToEntity( sv.edicts, r_refdef.vieworg, ext, ext, pnt ); if( clip.trace.fraction != 1.0 ) return; } #endif cam_ofs[ 0 ] = camAngles[ 0 ]; cam_ofs[ 1 ] = camAngles[ 1 ]; cam_ofs[ 2 ] = dist; // HL_CAMERA #endif }
bool TextEntry::OnKeyDown(const SDL_Keysym *sym) { bool accepted = false; bool changed = false; int oldNewlineCount = m_newlineCount; // XXX moving the cursor is not UTF-8 safe if (sym->sym == SDLK_LEFT || sym->sym == SDLK_RIGHT) { bool forward = (sym->sym == SDLK_RIGHT); int direction = (forward) ? 1 : -1; if (!(sym->mod & KMOD_CTRL)) { SetCursorPos(m_cursPos + direction); } else { int inspect_offset = (forward) ? 0 : -1; // When going back, we need the character before the cursor. int ending = (forward) ? m_text.size() : 0; int current = m_cursPos+inspect_offset; bool found_word = false; while(current != ending) { bool alphanum; alphanum = Text::is_alphanumunderscore(m_text[current]); if (found_word && !alphanum) { // Word boundary. current -= inspect_offset; // Make up for the initial offset. break; } current += direction; found_word = found_word || alphanum; // You need to be in a word before finding its boudaries. } SetCursorPos(current); } accepted = true; } // XXX deleting characters is not UTF-8 safe if (sym->sym == SDLK_BACKSPACE) { if (m_cursPos > 0) { if (m_text[m_cursPos-1] == '\n') --m_newlineCount; m_text = m_text.substr(0, m_cursPos-1) + m_text.substr(m_cursPos); SetCursorPos(m_cursPos-1); changed = true; } accepted = true; } if (sym->sym == SDLK_DELETE) { if (m_cursPos < signed(m_text.size())) { if (m_text[m_cursPos] == '\n') --m_newlineCount; m_text = m_text.substr(0, m_cursPos) + m_text.substr(m_cursPos+1); changed = true; } accepted = true; } if (sym->sym == SDLK_HOME) { size_t pos = m_text.rfind('\n', std::max(m_cursPos-1, 0)); if (pos == std::string::npos) pos = 0; else ++pos; m_cursPos = int(pos); accepted = true; } if (sym->sym == SDLK_END) { size_t pos = m_text.find('\n', m_cursPos); if (pos == std::string::npos) pos = m_text.size(); m_cursPos = int(pos); accepted = true; } if (sym->sym == SDLK_RETURN) { switch (m_newlineMode) { case IgnoreNewline: accepted = false; break; case AcceptNewline: accepted = true; break; case AcceptCtrlNewline: accepted = sym->mod & KMOD_CTRL; break; } if (accepted) { ++m_newlineCount; OnTextInput('\n'); } } if (oldNewlineCount != m_newlineCount) ResizeRequest(); onKeyPress.emit(sym); if (changed) onValueChanged.emit(); return accepted; }
// ================================================================================================ // Run! // ================================================================================================ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { HWND hwnd; HBITMAP hBitmap; HDC hdc; unsigned long *rawBits = NULL; Register(hInstance); hi = hInstance; SetCursorPos(0, 0); totblt.QuadPart = 0; totrev.QuadPart = 0; totmemcpy.QuadPart = 0; // ------------------------------------------------------------------------------------------------ // Create a window // ------------------------------------------------------------------------------------------------ { hwnd = ::CreateWindowEx(WS_EX_TOPMOST, "BltTest", "", WS_POPUP | WS_EX_TOOLWINDOW, 256, 16, kWidth, kHeight, (HWND)NULL, (HMENU)NULL, hInstance, LPVOID(NULL)); ::ShowWindow((HWND)hwnd, SW_SHOWNORMAL); if (!hwnd) { MessageBox(NULL, TEXT("unable to create window?"), NULL, MB_OK); return -1; } } // ------------------------------------------------------------------------------------------------' // Create a checker-board bitmap // ------------------------------------------------------------------------------------------------ { BITMAPINFO bmi; int bmihsize = sizeof(BITMAPINFOHEADER); memset(&bmi, 0, bmihsize); BITMAPINFOHEADER &h = bmi.bmiHeader; h.biSize = bmihsize; h.biWidth = kWidth; h.biHeight = -kHeight; h.biPlanes = 1; h.biBitCount = 32; h.biCompression = BI_RGB; hdc = CreateCompatibleDC(NULL); hBitmap = CreateDIBSection(NULL, &bmi, DIB_RGB_COLORS, (void**)&rawBits, NULL, 0); if (!hdc || !hBitmap) return -1; } // ------------------------------------------------------------------------------------------------ // Simple contents // ------------------------------------------------------------------------------------------------ for (int y = 0; y < kHeight; y++) { unsigned long *p0 = rawBits + kWidth * y; for (int x = 0; x < kWidth; x++) { unsigned long g = (x ^ y) & 0xFF; p0[x] = (g << 16) + (g << 8) + g; } } // make the capture from window look like a chess board HDC dc = (HDC)GetDC(hwnd); HBITMAP oldbitmap = (HBITMAP)SelectObject((HDC)hdc, hBitmap); ::BitBlt(dc, 0, 0, kWidth, kHeight, (HDC)hdc, 0, 0, SRCCOPY); SelectObject((HDC)hdc, oldbitmap); DeleteDC(dc); ::GdiFlush(); // ------------------------------------------------------------------------------------------------ // main loop // ------------------------------------------------------------------------------------------------ for (int framecount = 0; framecount < kFramesBlt + kFramesRev + kFramesWithMemCpy; framecount++) { int result = 1; MSG msg; while (result) { result = PeekMessage(&msg, (HWND)NULL, 0, 0, PM_REMOVE); if (result != 0) { TranslateMessage(&msg); DispatchMessage(&msg); } } // Message dispatching done, so draw a frame and measure timing LARGE_INTEGER s1, s2; QueryPerformanceCounter(&s1); if (framecount < kFramesBlt) { // from the desktop HDC dc = GetDC(NULL); // desktop HWND //HDC dc = CreateDC(TEXT("DISPLAY"), NULL, NULL, NULL); ::CaptureDC(hBitmap, dc); } else if (framecount < (kFramesBlt + kFramesRev)) { // from the window HDC dc = (HDC)GetDC(hwnd); ::CaptureDC(hBitmap, dc); } else { HDC dc = GetDC(NULL); ::CaptureDC(hBitmap, dc); } QueryPerformanceCounter(&s2); LARGE_INTEGER diff; diff.QuadPart = s2.QuadPart - s1.QuadPart; if (framecount < kFramesBlt) { if (diff.QuadPart < minblt) minblt = diff.QuadPart; if (diff.QuadPart > maxblt) maxblt = diff.QuadPart; totblt.QuadPart += s2.QuadPart - s1.QuadPart; } else if (framecount < (kFramesBlt + kFramesRev)) { if (diff.QuadPart < minrev) minrev = diff.QuadPart; if (diff.QuadPart > maxrev) maxrev = diff.QuadPart; totrev.QuadPart += s2.QuadPart - s1.QuadPart; } else { totmemcpy.QuadPart += s2.QuadPart - s1.QuadPart; } } ::DestroyWindow(hwnd); ::DialogBoxParam(hi, MAKEINTRESOURCE(IDD_RESULTS), NULL, DlgProc, NULL); return 0; }
/* ======================================================================================================================= ======================================================================================================================= */ void Sys_SetCursorPos(int x, int y) { SetCursorPos(x, y); }
HEIMY_API void moveMouse(POINT pos){ SetCursorPos(pos.x, pos.y); }