bool RocketUIManager::handleMouseEvent(EventDispatcher* sender, const Event& event) { const MouseEvent& e = static_cast<const MouseEvent&>(event); if(!mRenderSystemWrapper || !mRenderSystemWrapper->getContext(e.dispatcher)) return true; Rocket::Core::Context* ctx = mRenderSystemWrapper->getContext(e.dispatcher); if(e.getType() == MouseEvent::MOUSE_MOVE) { int keyModifierState = getKeyModifierState(); ctx->ProcessMouseMove(e.mouseX, e.mouseY, keyModifierState); if (e.relativeZ != 0) { ctx->ProcessMouseWheel(e.relativeZ / -120, keyModifierState); return !doCapture(ctx); } } else if(e.getType() == MouseEvent::MOUSE_DOWN) { ctx->ProcessMouseButtonDown((int) e.button, getKeyModifierState()); return !doCapture(ctx); } else if(e.getType() == MouseEvent::MOUSE_UP) { ctx->ProcessMouseButtonUp((int) e.button, getKeyModifierState()); } return true; }
/* * WndProc * * Process window message for the main window. */ LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { HWND selectedHwnd; switch (message) { case WM_CREATE: /* The window is created... Send the capture message */ PostMessage(hwnd, WM_DOCAPTURE, 0, 0); break; case WM_DOCAPTURE: /* Get the selected window handle */ selectedHwnd = (HWND) DialogBox(hInst, MAKEINTRESOURCE(IDD_SELECT), hwnd, (DLGPROC) dialogProc); if (selectedHwnd) doCapture(selectedHwnd); PostQuitMessage(0); break; case WM_DESTROY: PostQuitMessage(0); break; default: return (DefWindowProc(hwnd, message, wParam, lParam)); } return 0; }
void BehaviorTankAI::controlTank() { // do nothing if you're dead tank_t me = getMyTank(); if(me.status.compare("dead") == 0) { return; } switch(currentPriority) { case CAPTURE: doCapture(); break; case DEFEND: doDefend(); break; case EVADE: doEvade(); cout << "doing evade" << endl; break; } currentBehavior->doMove(); if(BZRCTools::simpleShouldShoot(connection, enemies, me)) { connection->shoot(tankNumber); } }
int main(int argc, char *argv[]) { ltr_int_check_root(); if(!checkCmdLine(argc, argv)){ ltr_int_log_message("Wrong arguments!\n"); return EXIT_FAILURE; } if(doEnumCams()){ enumerateCameras(); }else if(doCapture()){ int x, y; getRes(&x, &y); // Double buffer... if(ltr_int_mmap_file(getMapFileName(), ltr_int_get_com_size() + x * y, &mmm)){ ltr_int_setCommand(&mmm, WAKEUP); capture(&mmm); ltr_int_unmap_file(&mmm); }else{ ltr_int_log_message("Can't mmap!\n"); return EXIT_FAILURE; } }else{ return EXIT_FAILURE; } return EXIT_SUCCESS; }
// This method is to process userInput. // It receives player, userInput and the whole board as the parameter // and returns 1 or 0 to check whether the last piece to drop is users own // store in order to receive a extra game int pieceToMove(int player, char userInput, Hole board[]){ int index = -1; if(player == 0){ index = userInput - 'A'; }else { index = 12 - (userInput - 'A'); } int pieces = board[index].capacity; board[index].capacity = 0; int i; for(i = 0; i < pieces; i++){ board[(index+1+i)%14].capacity += 1; } index = (index + i) % 14; //check whether if last piece to drop is an empty hole if(board[index].capacity == 1 && index !=13 && index != 6){ doCapture(player,board, index); } //check whether if the last piece to drop is in your own store if((player == 1 && index == 13) || (player == 0 && index == 6)){ return 1; }else return 0; }// end of pieceToMove
DWORD WINAPI _camThread(LPVOID lpParam) { _camThreadLaunched=true; while (_camThreadLaunched) { static bool firstHere=true; if (firstHere) displayAcknowledgment=true; firstHere=false; EnterCriticalSection(&m_cs); for (int i=0;i<4;i++) { if (openCaptureDevices[i]) { if (isCaptureDone(i)) doCapture(i); } } LeaveCriticalSection(&m_cs); Sleep(10); } for (int i=0;i<4;i++) { if (openCaptureDevices[i]) { deinitCapture(i); delete[] captureInfo[i].mTargetBuf; } openCaptureDevices[i]=false; } _camThreadLaunched=true; return(0); }
/// /// @return Returns TRUE upon completion /// bool SimpleDirectShowAcq::CaptureFrame() { doCapture(m_cameraIndex); while (!isCaptureDone(m_cameraIndex)) // captures into m_buf { Sleep(1); } return true; }
/** Called when asyn clients call pasynInt32->write(). * This function performs actions for some parameters, including NDReadFile, NDWriteFile and NDFileCapture. * For other parameters it calls NDPluginDriver::writeInt32 to see if that method understands the parameter. * For all parameters it sets the value in the parameter library and calls any registered callbacks.. * \param[in] pasynUser pasynUser structure that encodes the reason and address. * \param[in] value Value to write. */ asynStatus NDPluginFile::writeInt32(asynUser *pasynUser, epicsInt32 value) { int function = pasynUser->reason; asynStatus status = asynSuccess; const char* functionName = "writeInt32"; /* Set the parameter in the parameter library. */ status = (asynStatus) setIntegerParam(function, value); if (function == NDWriteFile) { if (value) { /* Call the callbacks so the status changes */ callParamCallbacks(); if (this->pArrays[0]) { status = writeFileBase(); } else { asynPrint(pasynUser, ASYN_TRACE_ERROR, "%s:%s: ERROR, no valid array to write", driverName, functionName); status = asynError; } /* Set the flag back to 0, since this could be a busy record */ setIntegerParam(NDWriteFile, 0); } } else if (function == NDReadFile) { if (value) { /* Call the callbacks so the status changes */ callParamCallbacks(); status = readFileBase(); /* Set the flag back to 0, since this could be a busy record */ setIntegerParam(NDReadFile, 0); } } else if (function == NDFileCapture) { /* Must call doCapture if capturing was just started or stopped */ status = doCapture(value); } else { /* This was not a parameter that this driver understands, try the base class */ if (function <= LAST_NDPLUGIN_PARAM) status = NDPluginDriver::writeInt32(pasynUser, value); } /* Do callbacks so higher layers see any changes */ status = callParamCallbacks(); if (status) asynPrint(pasynUser, ASYN_TRACE_ERROR, "%s:%s error, status=%d function=%d, value=%d\n", driverName, functionName, status, function, value); else asynPrint(pasynUser, ASYN_TRACEIO_DRIVER, "%s:%s: function=%d, value=%d\n", driverName, functionName, function, value); return status; }
/* * doRootWindowCapture * * Capture the root window */ static void doRootWindowCapture(void) { /* Do the window capture */ doCapture(0); }
/** Called when asyn clients call pasynInt32->write(). * This function performs actions for some parameters, including NDReadFile, NDWriteFile and NDFileCapture. * For other parameters it calls NDPluginDriver::writeInt32 to see if that method understands the parameter. * For all parameters it sets the value in the parameter library and calls any registered callbacks.. * \param[in] pasynUser pasynUser structure that encodes the reason and address. * \param[in] value Value to write. */ asynStatus NDPluginFile::writeInt32(asynUser *pasynUser, epicsInt32 value) { int function = pasynUser->reason; asynStatus status = asynSuccess; static const char* functionName = "writeInt32"; /* Set the parameter in the parameter library. */ status = (asynStatus) setIntegerParam(function, value); if (function == NDWriteFile) { if (value) { /* Call the callbacks so the status changes */ callParamCallbacks(); if (this->pArrays[0]) { status = writeFileBase(); } else { asynPrint(pasynUser, ASYN_TRACE_ERROR, "%s::%s: ERROR, no valid array to write", driverName, functionName); status = asynError; } /* Set the flag back to 0, since this could be a busy record */ setIntegerParam(NDWriteFile, 0); } } else if (function == NDReadFile) { if (value) { /* Call the callbacks so the status changes */ callParamCallbacks(); status = readFileBase(); /* Set the flag back to 0, since this could be a busy record */ setIntegerParam(NDReadFile, 0); } } else if (function == NDFileCapture) { if (value) { // Started capture or stream // Reset the value temporarily until the doCapture() has called the // inherited openFile() method and the writer is in a good state to // start writing frames. // See comments on: https://github.com/areaDetector/ADCore/pull/100 setIntegerParam(NDFileCapture, 0); /* Latch the NDFileLazyOpen parameter so that we don't need to care * if the user modifies this parameter before first frame has arrived. */ int paramFileLazyOpen = 0; getIntegerParam(NDFileLazyOpen, ¶mFileLazyOpen); this->lazyOpen = (paramFileLazyOpen != 0); /* So far everything is OK, so we just clear the FileWriteStatus parameters */ setIntegerParam(NDFileWriteStatus, NDFileWriteOK); setStringParam(NDFileWriteMessage, ""); setStringParam(NDFullFileName, ""); } /* Must call doCapture if capturing was just started or stopped */ status = doCapture(value); if (status == asynSuccess) { if (this->lazyOpen) setStringParam(NDFileWriteMessage, "Lazy Open..."); setIntegerParam(NDFileCapture, value); } else { setIntegerParam(NDFileCapture, 0); } } else { /* This was not a parameter that this driver understands, try the base class */ status = NDPluginDriver::writeInt32(pasynUser, value); } /* Do callbacks so higher layers see any changes */ status = callParamCallbacks(); if (status) asynPrint(pasynUser, ASYN_TRACE_ERROR, "%s::%s error, status=%d function=%d, value=%d\n", driverName, functionName, status, function, value); else asynPrint(pasynUser, ASYN_TRACEIO_DRIVER, "%s::%s: function=%d, value=%d\n", driverName, functionName, function, value); return status; }
/** Callback function that is called by the NDArray driver with new NDArray data. * Saves a single file if NDFileWriteMode=NDFileModeSingle and NDAutoSave=1. * Stores array in a capture buffer if NDFileWriteMode=NDFileModeCapture and NDFileCapture=1. * Appends data to an open file if NDFileWriteMode=NDFileModeStream and NDFileCapture=1. * In capture or stream mode if the desired number of arrays has been saved (NDFileNumCaptured=NDFileNumCapture) * then it stops capture or streaming. * \param[in] pArray The NDArray from the callback. */ void NDPluginFile::processCallbacks(NDArray *pArray) { int fileWriteMode, autoSave, capture; int arrayCounter; int numCapture, numCaptured; asynStatus status = asynSuccess; //static const char* functionName = "processCallbacks"; /* First check if the callback is really for this file saving plugin */ if (!this->attrIsProcessingRequired(pArray->pAttributeList)) return; /* Most plugins want to increment the arrayCounter each time they are called, which NDPluginDriver * does. However, for this plugin we only want to increment it when we actually got a callback we were * supposed to save. So we save the array counter before calling base method, increment it here */ getIntegerParam(NDArrayCounter, &arrayCounter); /* Call the base class method */ NDPluginDriver::beginProcessCallbacks(pArray); getIntegerParam(NDAutoSave, &autoSave); getIntegerParam(NDFileCapture, &capture); getIntegerParam(NDFileWriteMode, &fileWriteMode); getIntegerParam(NDFileNumCapture, &numCapture); getIntegerParam(NDFileNumCaptured, &numCaptured); /* We always keep the last array so read() can use it. * Release previous one, reserve new one */ if (this->pArrays[0]) this->pArrays[0]->release(); pArray->reserve(); this->pArrays[0] = pArray; switch(fileWriteMode) { case NDFileModeSingle: if (autoSave) { arrayCounter++; writeFileBase(); } break; case NDFileModeCapture: if (capture) { if (numCaptured < numCapture && this->isFrameValid(pArray)) { this->pNDArrayPool->copy(pArray, this->pCapture[numCaptured++], 1); arrayCounter++; setIntegerParam(NDFileNumCaptured, numCaptured); } if (numCaptured == numCapture) { if (autoSave) { writeFileBase(); } capture = 0; setIntegerParam(NDFileCapture, capture); } } break; case NDFileModeStream: if (capture) { arrayCounter++; status = writeFileBase(); if (status == asynSuccess) { numCaptured++; setIntegerParam(NDFileNumCaptured, numCaptured); } if (numCaptured == numCapture) { doCapture(0); } } break; } /* Update the parameters. */ setIntegerParam(NDArrayCounter, arrayCounter); callParamCallbacks(); }
void LUA_START_CALLBACK(SLuaCallBack* p) { // the callback function of the new Lua command int result=-1; // error int returnResolution[2]={0,0}; if (p->inputArgCount>2) { // Ok, we have at least 3 input argument if ( (p->inputArgTypeAndSize[0*2+0]==sim_lua_arg_int)&&(p->inputArgTypeAndSize[1*2+0]==sim_lua_arg_int)&&(p->inputArgTypeAndSize[2*2+0]==sim_lua_arg_int) ) { // Ok, we have (at least) 3 ints as argument if ( (countCaptureDevices()>p->inputInt[0])&&(p->inputInt[0]>=0)&&(p->inputInt[0]<4) ) { if (!openCaptureDevices[p->inputInt[0]]) { // We can set the new resolution bool goOn=true; if (startCountOverall==0) { // Launch the thread! _camThreadLaunched=false; CreateThread(NULL,0,_camThread,NULL,THREAD_PRIORITY_NORMAL,NULL); while (!_camThreadLaunched) Sleep(2); if (deviceCount<1) { simSetLastError(LUA_START,"ESCAPI initialization failure or no devices found."); // output an error killThread(); goOn=false; } } if (goOn) { captureInfo[p->inputInt[0]].mWidth=p->inputInt[1]; captureInfo[p->inputInt[0]].mHeight=p->inputInt[2]; captureInfo[p->inputInt[0]].mTargetBuf=new int[p->inputInt[1]*p->inputInt[2]]; if (initCapture(p->inputInt[0],&captureInfo[p->inputInt[0]])!=0) { doCapture(p->inputInt[0]); openCaptureDevices[p->inputInt[0]]=true; returnResolution[0]=p->inputInt[1]; returnResolution[1]=p->inputInt[2]; result=1; // success! startCountOverall++; startCountPerDevice[p->inputInt[0]]++; } else { delete[] captureInfo[p->inputInt[0]].mTargetBuf; simSetLastError(LUA_START,"Device may already be in use."); // output an error } } } else { // We have to retrieve the current resolution returnResolution[0]=captureInfo[p->inputInt[0]].mWidth; returnResolution[1]=captureInfo[p->inputInt[0]].mHeight; result=0; startCountOverall++; startCountPerDevice[p->inputInt[0]]++; } } else simSetLastError(LUA_START,"Invalid device index."); // output an error } else simSetLastError(LUA_START,"Wrong argument type/size."); // output an error } else simSetLastError(LUA_START,"Not enough arguments."); // output an error // Now we prepare the return value: if (result>-1) { p->outputArgCount=3; // 3 return values p->outputArgTypeAndSize=(simInt*)simCreateBuffer(p->outputArgCount*2*sizeof(simInt)); // x return values takes x*2 simInt for the type and size buffer p->outputArgTypeAndSize[2*0+0]=sim_lua_arg_int; // The return value is an int p->outputArgTypeAndSize[2*0+1]=1; // Not used (table size if the return value was a table) p->outputArgTypeAndSize[2*1+0]=sim_lua_arg_int; // The return value is an int p->outputArgTypeAndSize[2*1+1]=1; // Not used (table size if the return value was a table) p->outputArgTypeAndSize[2*2+0]=sim_lua_arg_int; // The return value is an int p->outputArgTypeAndSize[2*2+1]=1; // Not used (table size if the return value was a table) p->outputInt=(simInt*)simCreateBuffer(3*sizeof(result)); // 1 int return value p->outputInt[0]=result; // This is the int value we want to return p->outputInt[1]=returnResolution[0]; // This is the int value we want to return p->outputInt[2]=returnResolution[1]; // This is the int value we want to return } else { p->outputArgCount=1; // 1 return value p->outputArgTypeAndSize=(simInt*)simCreateBuffer(p->outputArgCount*2*sizeof(simInt)); // x return values takes x*2 simInt for the type and size buffer p->outputArgTypeAndSize[2*0+0]=sim_lua_arg_int; // The return value is an int p->outputArgTypeAndSize[2*0+1]=1; // Not used (table size if the return value was a table) p->outputInt=(simInt*)simCreateBuffer(1*sizeof(result)); // 1 int return value p->outputInt[0]=result; // This is the int value we want to return } }