static void js_atomic_destroy_node(Node* node, duk_context* ctx, bool root = false) { if (root) { PODVector<Node*> children; node->GetChildren(children, true); for (unsigned i = 0; i < children.Size(); i++) { if (children.At(i)->JSGetHeapPtr()) js_atomic_destroy_node(children.At(i), ctx); } } const Vector<SharedPtr<Component> >& components = node->GetComponents(); for (unsigned i = 0; i < components.Size(); i++) { Component* component = components[i]; if (component->GetType() == JSComponent::GetTypeStatic()) { JSComponent* jscomponent = (JSComponent*) component; jscomponent->SetDestroyed(); } component->UnsubscribeFromAllEvents(); } node->RemoveAllComponents(); node->UnsubscribeFromAllEvents(); node->Remove(); }
void JSUI::HandleWidgetLoaded(StringHash eventType, VariantMap& eventData) { using namespace WidgetLoaded; UIWidget* widget = static_cast<UIWidget*>(eventData[P_WIDGET].GetPtr()); if (!widget) return; void* heapptr = widget->JSGetHeapPtr(); if (!heapptr) return; TBWidget* tbwidget = widget->GetInternalWidget(); assert(tbwidget); // all widgets with id's are wrapped, so that event handlers are bubbled up properly // note that all js widget object representations are kept alive in HandleObjectAdded // when pushed into the VM PODVector<TBWidget*> widgets; GatherWidgets(tbwidget, widgets); UI* ui = GetSubsystem<UI>(); for (unsigned i = 0; i < widgets.Size(); i++) { UIWidget* o = ui->WrapWidget(widgets.At(i)); if (!o) continue; js_push_class_object_instance(ctx_, o); } }