// Constructors should be used to initialize things only once on scene creation StartScreen() : Scene() , renderer(AppWindow::getInstance(), 4242) { // Load and store calls to a resource manager should be done only once, but for demonstration purposes.. texture_1 = Manager::TextureManager::store( Manager::TextureManager::load("Multimedia/Assets/Art/Misc/placeholder.png") ); texture_2 = Manager::TextureManager::store( Manager::TextureManager::load("Multimedia/Assets/Art/Player/Idle/vessel-idle.png") ); // configure the sprite //background().setTexture(*Manager::TextureManager::get(texture_1)); sgo().setTexture(*Manager::TextureManager::get(texture_2)); v = new Vessel(0,NULL,0,0); // might want to have another resource manager for fonts... font.loadFromFile("Multimedia/Assets/Fonts/arial.ttf"); // configure the text this doesn't compile :/ //welcomeText().setFont(font); //welcomeText().setCharacterSize(30); //welcomeText().setString("Welcome to Spectre"); }
// Update callback, do logical stuff here void update(sf::Time t) override { /* This code moves the background but keeps the vessel centered */ view_main.move(v->getXSpeed(), v->getYSpeed()); sgo().setPosition(view_main.getCenter()); //*/ /* This code moves the vessel around but keeps the screen centered sgo().setPosition(v->getXPosition(), v->getYPosition()); //*/ }
// // Method for creating a new InstallTriggerGlobal JavaScript object // nsresult NS_NewScriptInstallTriggerGlobal(nsIScriptContext *aContext, nsISupports *aSupports, nsISupports *aParent, void **aReturn) { NS_PRECONDITION(nsnull != aContext && nsnull != aSupports && nsnull != aReturn, "null argument to NS_NewScriptInstallTriggerGlobal"); JSObject *proto; JSObject *parent = nsnull; JSContext *jscontext = (JSContext *)aContext->GetNativeContext(); nsresult result = NS_OK; nsIDOMInstallTriggerGlobal *installTriggerGlobal; nsCOMPtr<nsIScriptObjectOwner> owner(do_QueryInterface(aParent)); if (owner) { if (NS_OK != owner->GetScriptObject(aContext, (void **)&parent)) { return NS_ERROR_FAILURE; } } else { nsCOMPtr<nsIScriptGlobalObject> sgo(do_QueryInterface(aParent)); if (sgo) { parent = sgo->GetGlobalJSObject(); } else { return NS_ERROR_FAILURE; } } if (NS_OK != NS_InitInstallTriggerGlobalClass(aContext, (void **)&proto)) { return NS_ERROR_FAILURE; } result = CallQueryInterface(aSupports, &installTriggerGlobal); if (NS_OK != result) { return result; } // create a js object for this class *aReturn = JS_NewObject(jscontext, &InstallTriggerGlobalClass, proto, parent); if (nsnull != *aReturn) { // connect the native object to the js object JS_SetPrivate(jscontext, (JSObject *)*aReturn, installTriggerGlobal); } else { NS_RELEASE(installTriggerGlobal); return NS_ERROR_FAILURE; } return NS_OK; }
nsIScriptGlobalObject * nsJSUtils::GetStaticScriptGlobal(JSObject* aObj) { const JSClass* clazz; JSObject* glob = aObj; // starting point for search if (!glob) return nullptr; glob = js::GetGlobalForObjectCrossCompartment(glob); NS_ABORT_IF_FALSE(glob, "Infallible returns null"); clazz = JS_GetClass(glob); // Whenever we end up with globals that are JSCLASS_IS_DOMJSCLASS // and have an nsISupports DOM object, we will need to modify this // check here. MOZ_ASSERT(!(clazz->flags & JSCLASS_IS_DOMJSCLASS)); nsISupports* supports; if (!(clazz->flags & JSCLASS_HAS_PRIVATE) || !(clazz->flags & JSCLASS_PRIVATE_IS_NSISUPPORTS) || !(supports = (nsISupports*)::JS_GetPrivate(glob))) { return nullptr; } // We might either have a window directly (e.g. if the global is a // sandbox whose script object principal pointer is a window), or an // XPCWrappedNative for a window. We could also have other // sandbox-related script object principals, but we can't do much // about those short of trying to walk the proto chain of |glob| // looking for a window or something. nsCOMPtr<nsIScriptGlobalObject> sgo(do_QueryInterface(supports)); if (!sgo) { nsCOMPtr<nsIXPConnectWrappedNative> wrapper(do_QueryInterface(supports)); if (!wrapper) { return nullptr; } sgo = do_QueryWrappedNative(wrapper); } // We're returning a pointer to something that's about to be // released, but that's ok here. return sgo; }
nsIScriptGlobalObject * nsJSUtils::GetStaticScriptGlobal(JSContext* aContext, JSObject* aObj) { nsISupports* supports; JSClass* clazz; JSObject* glob = aObj; // starting point for search if (!glob) return nsnull; glob = JS_GetGlobalForObject(aContext, glob); NS_ABORT_IF_FALSE(glob, "Infallible returns null"); clazz = JS_GetClass(glob); if (!clazz || !(clazz->flags & JSCLASS_HAS_PRIVATE) || !(clazz->flags & JSCLASS_PRIVATE_IS_NSISUPPORTS) || !(supports = (nsISupports*)::JS_GetPrivate(glob))) { return nsnull; } // We might either have a window directly (e.g. if the global is a // sandbox whose script object principal pointer is a window), or an // XPCWrappedNative for a window. We could also have other // sandbox-related script object principals, but we can't do much // about those short of trying to walk the proto chain of |glob| // looking for a window or something. nsCOMPtr<nsIScriptGlobalObject> sgo(do_QueryInterface(supports)); if (!sgo) { nsCOMPtr<nsIXPConnectWrappedNative> wrapper(do_QueryInterface(supports)); NS_ENSURE_TRUE(wrapper, nsnull); sgo = do_QueryWrappedNative(wrapper); } // We're returning a pointer to something that's about to be // released, but that's ok here. return sgo; }
nsIScriptGlobalObject * nsWWJSUtils::GetStaticScriptGlobal(JSContext* aContext, JSObject* aObj) { nsISupports* supports; JSClass* clazz; JSObject* parent; JSObject* glob = aObj; // starting point for search if (!glob) return nsnull; while (nsnull != (parent = JS_GetParent(aContext, glob))) glob = parent; #ifdef JS_THREADSAFE clazz = JS_GetClass(aContext, glob); #else clazz = JS_GetClass(glob); #endif if (!clazz || !(clazz->flags & JSCLASS_HAS_PRIVATE) || !(clazz->flags & JSCLASS_PRIVATE_IS_NSISUPPORTS) || !(supports = (nsISupports*) JS_GetPrivate(aContext, glob))) { return nsnull; } nsCOMPtr<nsIXPConnectWrappedNative> wrapper(do_QueryInterface(supports)); NS_ENSURE_TRUE(wrapper, nsnull); nsCOMPtr<nsIScriptGlobalObject> sgo(do_QueryWrappedNative(wrapper)); // This will return a pointer to something we're about to release, // but that's ok here. return sgo; }