int ObstacleHandler::generateHooks(int numHooks, const Boundary &Path, const Boundary &BL, const Boundary &BR) { srand(time(NULL)); //Returns 1 if successfully generates hooks, returns 0 otherwise if(numHooks > 250) { printf("numHooks must be less than 100"); return 0; } double xtemp, ztemp; for(int i = 0; i < numHooks; i++) { Hook tempH; do{ //Place the player, and see if it is between the two boundaries xtemp=Path.x[Path.length-1]*(double)(rand()%100)/100; // create initial x coord ztemp=Path.z[Path.length-1]*(double)(rand()%100)/100; // create initial z coordinate }while(0==BetweenBounds(BL,BR,(int)xtemp,(int)ztemp)||!(ztemp<Path.z[Path.length-4])||!(ztemp>Path.z[3])); //tempH.CleanUp(); tempH.setPosition(xtemp, 1, ztemp); tempH.x0 = xtemp; tempH.z0 = ztemp; arr[i] = tempH; arraySize++; } return 1; }
bool Container::_focusRequested( Hook * pBranch, Widget * pWidgetRequesting ) { Hook * p = _hook(); if( p ) return p->_requestFocus(pWidgetRequesting); return false; }
bool Container::_focusReleased( Hook * pBranch, Widget * pWidgetReleasing ) { Hook * p = _hook(); if( p ) return p->_releaseFocus(pWidgetReleasing); return false; }
Widget * Container::_lastWidget() const { Hook * p = _lastHook(); if( p ) return p->_widget(); else return 0; }
ActiveHwndTracker::ActiveHwndTracker(QObject *parent) : QObject(parent) { d = new PrivData(); Hook *hook = new Hook(this); this->connect(hook, SIGNAL(activated(HookEvent)), SLOT(snapshot(HookEvent))); hook->hookEvent(EVENT_SYSTEM_FOREGROUND); }
void PatchLoader::patchHookReceiveHandler_(const std::vector<uint8_t>& data) { auto iterator = data.cbegin(); Hook hook; hook.deserialise(deserialiseIntegralTypeContinuousContainer<std::vector<uint8_t>>(iterator)); getSingleton().registerHook_(hook); }
void Container::_visibilityRequested( Hook * pBranch, const Rect& preferred, const Rect& prio ) { Hook * p = _hook(); if( p ) { Coord ofs = pBranch->pos(); p->_requestVisibility( preferred + ofs, prio + ofs); } }
RootPanel * Hook::_root() const { Container * pParent = _parent(); if( pParent ) { Hook * pParentHook = pParent->_hook(); if( pParentHook ) return pParentHook->_root(); } return 0; }
void Container::_collectPatches( Patches& container, const Rect& geo, const Rect& clip ) { if( m_pSkin ) container.add( Rect( geo, clip ) ); else { Rect childGeo; Hook * p = _firstHookWithGeo( childGeo ); while(p) { if( p->_isVisible() ) p->_widget()->_collectPatches( container, childGeo + geo.pos(), clip ); p = _nextHookWithGeo( childGeo, p ); } } }
void Container::_maskPatches( Patches& patches, const Rect& geo, const Rect& clip, BlendMode blendMode ) { //TODO: Don't just check isOpaque() globally, check rect by rect. if( (m_bOpaque && blendMode == BlendMode::Blend) || blendMode == BlendMode::Replace) patches.sub( Rect(geo,clip) ); else { Rect childGeo; Hook * p = _firstHookWithGeo( childGeo ); while(p) { if( p->_isVisible() ) p->_widget()->_maskPatches( patches, childGeo + geo.pos(), clip, blendMode ); p = _nextHookWithGeo( childGeo, p ); } } }
void getHooks(std::vector<HookData> &hooks, TXsheet *xsh, int row, int col, TPointD dpiScale) { // nota. hook position is in the coordinate system of the parent object. // a inch is Stage::inch TXshCell cell = xsh->getCell(row, col); if (!cell.m_level) return; TStageObjectId columnId = TStageObjectId::ColumnId(col); // handle is the current handle (pivot) of the column. It can be H1,H2,... or A,B,C,... std::string handle = xsh->getStageObject(TStageObjectId::ColumnId(col))->getHandle(); bool handleIsHook = handle.find("H") == 0; TAffine aff = xsh->getPlacement(columnId, row); // imageDpiAff represent the scale factor between the image and the camera // derived by dpi match (i.e. ignoring geometric transformation) // cameraPos = imageDpiAff * imagePos TAffine imageDpiAff; if (cell.m_level->getSimpleLevel()) imageDpiAff = getDpiAffine(cell.m_level->getSimpleLevel(), cell.m_frameId, true); // center (inches) TPointD center = xsh->getCenter(columnId, row); // getHooks if (handleIsHook) center = TPointD(0, 0); // add the hook #0 (i.e. the regular center) hooks.push_back(HookData(xsh, col, 0, aff * TScale(Stage::inch) * center)); // add the regular hooks HookSet *hookSet = cell.m_level->getHookSet(); if (hookSet && hookSet->getHookCount() > 0) { for (int j = 0; j < hookSet->getHookCount(); j++) { Hook *hook = hookSet->getHook(j); if (hook && !hook->isEmpty()) { TPointD pos = hook->getAPos(cell.m_frameId); pos = aff * imageDpiAff * pos; hooks.push_back(HookData(xsh, col, j + 1, pos)); } } } }
void Player::CheckCollision(Hook h[], int numHooks) { for(int i = 0; i < numHooks; i++) { Hook tempHook = h[i]; double dist = TrueDist(x,tempHook.getX(), z,tempHook.getZ()); //printf ("%lf truedist %lf radius\n", dist, tempHook.getRadius()); if(dist < tempHook.getRadius()) { //printf("Caught\n"); caught = 1; h[i].catchFish(); myHook = &(h[i]); break; } } }
Widget * Container::_findWidget( const Coord& ofs, SearchMode mode ) { Rect childGeo; Hook * pHook = _lastHookWithGeo( childGeo ); Widget * pResult = 0; while( pHook && !pResult ) { if( pHook->_isVisible() && childGeo.contains( ofs ) ) { if( pHook->_widget()->isContainer() ) { pResult = static_cast<Container*>(pHook->_widget())->_findWidget( ofs - childGeo.pos(), mode ); } else if( mode == SearchMode::Geometry || pHook->_widget()->markTest( ofs - childGeo.pos() ) ) { pResult = pHook->_widget(); } } pHook = _prevHookWithGeo( childGeo, pHook ); } // Check against ourselves if( !pResult && ( mode == SearchMode::Geometry || markTest(ofs)) ) pResult = this; return pResult; }
void Player::Go(Player *P, int numplayers, const Boundary &Path, const Boundary &BLL,const Boundary &BL,const Boundary &BR,const Boundary &BRR, const Button &B, Hook h[],int numHooks) { if(B.reset) { Reset(); } if(caught) { Hook myHookobj = *myHook; y = myHookobj.getY(); caught = myHookobj.caughtOrNot(); if(!caught) { y = .5; z += myHookobj.getRadius()+2; } } else { //Does everything for the player //Works for every type of player. no specifications need to be given, just a lot of objects get passed in Input(B);//Keyboard input for all players //Player-Player interaction if(!finish)//The player hasn't finished { Race(Path);//Follow the path AI(P,numplayers);//Act } else Finished(); //Act finished Bounce(P,numplayers); //Check for bounces between each player //Player-Env. Interaction DetectBoundary(BLL,BL); //Check left boundary DetectBoundary(BR,BRR); //Check right boundary DetectEndCond(Path); //Check end line&beginning if(usedtobeinabound==1||inabound==1) MoveBound(); else//if not in a boundary MoveDamp(); //Combine all Move(); //Check to see that the Players have not exicted the outer boundary Check(BLL, BL,Path,BR, BRR); CheckFinished(Path);//Check to see if the player is passed the ifinish line if(pt == 0) { CheckCollision(h, numHooks); } } }
void ModalLayer::_updateKeyboardFocus() { // Get message handler, verify that we have a root if( !hook() ) return; MsgRouter * pHandler = hook()->msgRouter().rawPtr(); if( !pHandler ) return; // Retrieve focused Widget and verify it being a descendant to us. Widget * pFocused = pHandler->keyboardFocus().rawPtr(); Widget * p = pFocused; while( p && p->parent() && p->parent() != this ) p = p->_parent(); if( p && p->_parent() != this ) return; // Focus belongs to a Widget that is not a descendant to us, // so we can't save and shouldn't steal focus. // Save old focus so we can return it properly in the future. if( p ) { if( p == m_baseHook._widget() ) m_pBaseKeyFocus = pFocused; else { ModalHook * pHook = static_cast<ModalHook*>(p->_hook()); pHook->m_pKeyFocus = pFocused; } } // Find which child-branch to focus and switch to our previously saved focus ModalHook * pHook = m_modalHooks.last(); Widget * pSavedFocus = 0; Hook * pBranch = 0; if( pHook ) { pSavedFocus = pHook->m_pKeyFocus.rawPtr(); pHook->m_pKeyFocus = 0; // Needs to be cleared for the future. pBranch = pHook; } else if( m_baseHook._widget() ) { pSavedFocus = m_pBaseKeyFocus.rawPtr(); m_pBaseKeyFocus = 0; // Needs to be cleared for the future. pBranch = &m_baseHook; } // Verify that saved focus still is within branch and is not hidden if( pSavedFocus ) { Hook * p = pSavedFocus->_hook(); while( p && p != pBranch ) { Container * pHolder = p->_parent(); if( pHolder ) p = pHolder->_hook(); else p = 0; } if( p != pBranch ) pSavedFocus = 0; // Previously focused Widget is no longer a child of focused branch. } // Switch to previously saved focus, or null if not applicable pHandler->setKeyboardFocus( pSavedFocus ); }
TPointD XshHandleManager::getHandlePos(const TStageObjectId &id, const std::string &handle, int row) const { static const double unit = 8.0; assert(m_xsh->getScene()); if (handle == "") return TPointD(); else if (handle[0] == 'H' && handle.length() > 1) { // Hook port case if (!id.isColumn()) return TPointD(); int hookIndex = 0; { int h, hLength = handle.length(); for (h = 1; h != hLength; ++h) hookIndex = hookIndex * 10 + (handle[h] - '0'); } TStageObject *obj = m_xsh->getStageObject(id); if (const PlasticSkeletonDeformationP &def = obj->getPlasticSkeletonDeformation()) { int skelId = def->skeletonId(row); PlasticSkeleton skel; def->storeDeformedSkeleton(skelId, row, skel); int v = def->vertexIndex(hookIndex, skelId); return (v >= 0) ? TScale(1.0 / Stage::inch) * skel.vertex(v).P() : TPointD(); } --hookIndex; int col = id.getIndex(); TXshCell cell(m_xsh->getCell(row, col)); TXshLevel *xl = cell.m_level.getPointer(); if (!xl) return TPointD(); TXshSimpleLevel *sl = xl->getSimpleLevel(); if (!sl) return TPointD(); Hook *hook = sl->getHookSet()->getHook(hookIndex); if (!hook) return TPointD(); TFrameId fid(cell.m_frameId); TPointD pos = hook->getAPos(fid) * (1.0 / Stage::inch); TPointD delta; for (int r = row - 1; r >= 0; --r) { cell = m_xsh->getCell(r, col); if (cell.m_level.getPointer() != xl) break; const TFrameId &precFid = cell.m_frameId; delta += computePassHook(fid, precFid, sl, hook); fid = precFid; } pos += delta * (1.0 / Stage::inch); pos = getDpiAffine(sl, cell.m_frameId, true) * pos; return pos; } else if ('A' <= handle[0] && handle[0] <= 'Z') return TPointD(unit * (handle[0] - 'B'), 0); else if ('a' <= handle[0] && handle[0] <= 'z') return TPointD(0.5 * unit * (handle[0] - 'b'), 0); else return TPointD(); }
void Container::_renderPatches( GfxDevice * pDevice, const Rect& _canvas, const Rect& _window, Patches * _pPatches ) { // We start by eliminating dirt outside our geometry Patches patches( _pPatches->size() ); // TODO: Optimize by pre-allocating? for( const Rect * pRect = _pPatches->begin() ; pRect != _pPatches->end() ; pRect++ ) { if( _canvas.intersectsWith( *pRect ) ) patches.push( Rect(*pRect,_canvas) ); } // Render container itself for( const Rect * pRect = patches.begin() ; pRect != patches.end() ; pRect++ ) _render(pDevice, _canvas, _window, *pRect ); // Render children Rect dirtBounds = patches.getUnion(); if( m_bSiblingsOverlap ) { // Create WidgetRenderContext's for siblings that might get dirty patches std::vector<WidgetRenderContext> renderList; Rect childGeo; Hook * p = _firstHookWithGeo( childGeo ); while(p) { Rect geo = childGeo + _canvas.pos(); if( p->_isVisible() && geo.intersectsWith( dirtBounds ) ) renderList.push_back( WidgetRenderContext(p->_widget(), geo ) ); p = _nextHookWithGeo( childGeo, p ); } // Go through WidgetRenderContexts in reverse order (topmost first), push and mask dirt for( int i = renderList.size()-1 ; i >= 0 ; i-- ) { WidgetRenderContext * p = &renderList[i]; p->patches.push( &patches ); p->pWidget->_maskPatches( patches, p->geo, p->geo, pDevice->blendMode() ); //TODO: Need some optimizations here, grandchildren can be called repeatedly! Expensive! if( patches.isEmpty() ) break; } // Go through WidgetRenderContexts and render the patches for( int i = 0 ; i < (int) renderList.size() ; i++ ) { WidgetRenderContext * p = &renderList[i]; p->pWidget->_renderPatches( pDevice, p->geo, p->geo, &p->patches ); } } else { Rect childGeo; Hook * p = _firstHookWithGeo( childGeo ); while(p) { Rect canvas = childGeo + _canvas.pos(); if( p->_isVisible() && canvas.intersectsWith( dirtBounds ) ) p->_widget()->_renderPatches( pDevice, canvas, canvas, &patches ); p = _nextHookWithGeo( childGeo, p ); } } }