//Attaches the OTHER element to THIS void GuiElement::attach(GuiAttachment desc) { //Make sure these elements can be attached -- this element must either be its parent or share the same parent // (Otherwise they're not in the same tree level, and can't logically be attached) desc.child = (GuiElement*)desc.element->parent == this; if(desc.child || desc.element->parent == parent) { if(desc.element->attachedTo[desc.side] == this) { //Find attachment, and edit its offset for(auto a : attachments) { if(a.element == desc.element && a.side == desc.side) { a.offset = desc.offset; break; } } } else { desc.element->detach(desc.side); desc.element->attachedTo[desc.side] = this; attachments.push_back(desc); onAttach(attachments[attachments.size() - 1]); } resolveAttachments(); } //else not a valid attachment }
int BaseNode::insertNode( int n, BaseNode * pChild ) { if (! pChild ) return -1; if ( this == NULL || pChild == NULL ) return -1; if ( pChild->isChild( this ) ) // assert that this isn't a circular attachment return -1; // grab a reference to the child, otherwise when we detach from the old parent the child // may get deleted. Ref rChild( pChild ); if ( pChild->m_pParent != NULL ) pChild->m_pParent->detachNode( pChild ); updateVersion(); pChild->m_pParent = this; m_Children.insert( m_Children.begin() + n, pChild ); // notify ourselves onAttach( pChild ); // notify the child object pChild->onAttached(); return n; }
void Entity::addSystem(const sbeID sID) { auto S = Engine::GetEntityMgr()->createSystem(sID); if (S) { Systems[sID] = S; S->onAttach(*this); changed = true; } }
int BaseNode::attachNode( BaseNode * pChild ) { if ( this == NULL || pChild == NULL ) return -1; if ( pChild->isChild( this ) ) // assert that this isn't a circular attachment return -1; // this checks if this node is already attached to this node, if so just pretend we are attaching.. if ( this == pChild->m_pParent ) { for(size_t i=0;i<m_Children.size();++i) if ( m_Children[i] == pChild ) { // notify ourselves onAttach( pChild ); // notify the child object pChild->onAttached(); return (int)i; } return -1; } // grab a reference to the child, otherwise when we detach from the old parent the child // may get deleted. Ref rChild( pChild ); if ( pChild->m_pParent != NULL ) pChild->m_pParent->detachNode( pChild ); // update the internal version number of the parent object, this is important for // serialization reasons. updateVersion(); pChild->m_pParent = this; m_Children.push_back( pChild ); // notify ourselves onAttach( pChild ); // notify the child object pChild->onAttached(); return( m_Children.size() - 1 ); }
void Container::attach(Element_shared_ptr element) { if(element->_upper) { fprintf(stderr,"Can't attach a view to two parents\n"); return; } element->_upper = this; if (_root != nullptr)element->_root = _root; else element->_root = this; element->_depthLevel = _depthLevel +1; element->requestLayout(); _children.push_back(element); onAttach(element.get()); }
bool WINAPI DllMain (HMODULE dll, DWORD reason, LPVOID reserved) { switch (reason) { case DLL_PROCESS_ATTACH: onAttach(); break; case DLL_PROCESS_DETACH: onDetach(); break; } return true; }
void UnitSAO::setAttachment(int parent_id, const std::string &bone, v3f position, v3f rotation) { // Attachments need to be handled on both the server and client. // If we just attach on the server, we can only copy the position of the parent. Attachments // are still sent to clients at an interval so players might see them lagging, plus we can't // read and attach to skeletal bones. // If we just attach on the client, the server still sees the child at its original location. // This breaks some things so we also give the server the most accurate representation // even if players only see the client changes. int old_parent = m_attachment_parent_id; m_attachment_parent_id = parent_id; m_attachment_bone = bone; m_attachment_position = position; m_attachment_rotation = rotation; m_attachment_sent = false; if (parent_id != old_parent) { onDetach(old_parent); onAttach(parent_id); } }
void Recorder::messagePump() { XnStatus nRetVal = XN_STATUS_OK; Message msg = { Message::MESSAGE_NO_OPERATION, 0, NULL, {NULL}, 0, 0 }; { xnl::LockGuard<MessageQueue> guard(m_queue); nRetVal = m_queue.Pop(msg); } if (XN_STATUS_OK == nRetVal) { switch (msg.type) { case Message::MESSAGE_INITIALIZE: { onInitialize(); } break; case Message::MESSAGE_TERMINATE: { onTerminate(); m_running = FALSE; } break; case Message::MESSAGE_ATTACH: { xnl::LockGuard<AttachedStreams> streamsGuard(m_streams); AttachedStreams::Iterator i = m_streams.Find(msg.pStream); if (i != m_streams.End()) { onAttach(i->Value().nodeId, msg.pStream); } } break; case Message::MESSAGE_DETACH: { xnl::LockGuard<AttachedStreams> streamsGuard(m_streams); AttachedStreams::Iterator i = m_streams.Find(msg.pStream); if (i != m_streams.End()) { onDetach(i->Value().nodeId); XN_DELETE(m_streams[msg.pStream].pCodec); m_streams.Remove(msg.pStream); } } break; case Message::MESSAGE_START: { xnl::LockGuard<AttachedStreams> streamsGuard(m_streams); for (AttachedStreams::Iterator i = m_streams.Begin(), e = m_streams.End(); i != e; ++i) { onStart(i->Value().nodeId); } m_started = true; } break; case Message::MESSAGE_RECORD: { xnl::LockGuard<AttachedStreams> streamsGuard(m_streams); AttachedStreams::Iterator i = m_streams.Find(msg.pStream); if (i != m_streams.End()) { XnCodecBase* pCodec = m_streams[msg.pStream].pCodec; XnUInt32 frameId = ++m_streams[msg.pStream].frameId; XnUInt64 timestamp = 0; if (frameId > 1) { timestamp = m_streams[msg.pStream].lastOutputTimestamp + (msg.pFrame->timestamp - m_streams[msg.pStream].lastInputTimestamp); } m_streams[msg.pStream].lastInputTimestamp = msg.pFrame->timestamp; m_streams[msg.pStream].lastOutputTimestamp = timestamp; onRecord(i->Value().nodeId, pCodec, msg.pFrame, frameId, timestamp); msg.pStream->frameRelease(msg.pFrame); } } break; case Message::MESSAGE_RECORDPROPERTY: { xnl::LockGuard<AttachedStreams> streamsGuard(m_streams); AttachedStreams::Iterator i = m_streams.Find(msg.pStream); if (i != m_streams.End()) { onRecordProperty( i->Value().nodeId, msg.propertyId, msg.pData, msg.dataSize); } // free the temporary buffer allocated earlier xnOSFree((void*)msg.pData); } break; default: ; } } }