int ResourceManagerImpl::CreateQuad(const string &quadName, const string &textureName, float x, float y, float width, float height) { if (!quadName.size() || !textureName.size()) return INVALID_ID; if (GetQuad(quadName) != NULL) { assert(false); return ALREADY_EXISTS; } WCachedTexture * jtex = textureWCache.Retrieve(0, textureName, RETRIEVE_MANAGE); lastError = textureWCache.mError; int id = INVALID_ID; //Somehow, jtex wasn't promoted. if (RETRIEVE_MANAGE && jtex && !jtex->isPermanent()) return id; if (jtex) { JQuadPtr quad = jtex->GetQuad(x, y, width, height, quadName); if (quad.get()) { jtex->deadbolt(); WManagedQuad mq; mq.resname = quadName; mq.texture = jtex; id = AddQuadToManaged(mq); } } assert(id != INVALID_ID); return id; }
void GUITexture::Render(float elapsed, const RenderInfo& info) { if (Mat == 0) { return; } if (tex == 0) { auto findParam = Params.find(GUIMaterials::QuadDraw_Texture2D); if (findParam != Params.end()) { findParam->second.Tex() = INVALID_RENDER_OBJ_HANDLE; } } else { Params[GUIMaterials::QuadDraw_Texture2D].Tex() = tex->GetTextureHandle(); } SetUpQuad(); DrawingQuad::GetInstance()->Rotate(rotation); GetQuad()->Render(info, Params, *Mat); DrawingQuad::GetInstance()->SetRotation(0.0f); }
JQuadPtr WCachedTexture::GetCard(float offX, float offY, float width, float height, const string& resname) { JQuadPtr jq = GetQuad(offX, offY, width, height, resname); if (jq.get()) jq->SetHotSpot(static_cast<float> (jq->mTex->mWidth / 2), static_cast<float> (jq->mTex->mHeight / 2)); return jq; }
JQuadPtr ResourceManagerImpl::RetrieveQuad(const string& filename, float offX, float offY, float width, float height, string resname, int style, int submode, int id) { //Lookup managed resources, but only with a real resname. if (resname.size() && (style == RETRIEVE_MANAGE || style == RETRIEVE_RESOURCE)) { JQuadPtr quad = GetQuad(resname); if (quad.get() || style == RETRIEVE_RESOURCE) return quad; } //Aliases. if (style == RETRIEVE_THUMB) { submode = submode | TEXTURE_SUB_THUMB; style = RETRIEVE_NORMAL; } //Resname defaults to filename. if (!resname.size()) resname = filename; //No quad, but we have a managed texture for this! WCachedTexture* jtex = textureWCache.Retrieve(id, filename, style, submode); lastError = textureWCache.mError; //Somehow, jtex wasn't promoted. if (style == RETRIEVE_MANAGE && jtex && !jtex->isPermanent()) return JQuadPtr(); //Make this quad, overwriting any similarly resname'd quads. if (jtex) { JQuadPtr quad = jtex->GetQuad(offX, offY, width, height, resname); if (!quad.get()) return quad; if (style == RETRIEVE_MANAGE && resname != "") { WManagedQuad mq; mq.resname = resname; mq.texture = jtex; AddQuadToManaged(mq); } if (style == RETRIEVE_LOCK) jtex->lock(); else if (style == RETRIEVE_UNLOCK) jtex->unlock(); else if (style == RETRIEVE_MANAGE) jtex->deadbolt(); return quad; } //Texture doesn't exist, so no quad. return JQuadPtr(); }
void TitleScreen::CreateTitleScreenObject() { m_titleScreenObject = new Object(GetMaterial(), GetQuad(), Transform()); AddObject(m_titleScreenObject); PerspectiveCameraParams params(45, 1280/720.0f, 0.1f, 1000.0f); m_dummyCamera = new PerspectiveCamera(params, glm::vec3(0,5,5), glm::vec3(0,0,-1), glm::vec3(0,5,-5)); AddCamera(m_dummyCamera); SetCurrentCamera(0); }
int DockWindow::GetPointAlign(const Point p, Rect r, bool center, bool allow_lr, bool allow_tb) { Size border = r.GetSize(); border.cx = allow_lr ? border.cx/4 : 0; border.cy = allow_tb ? border.cy/4 : 0; if (center && r.Deflated(border).Contains(p)) return DOCK_NONE; int q = GetQuad(p, r); int al = DOCK_NONE; if (q == 0 || q == 1) al = DOCK_TOP; else if (q == 2 || q == 3) al = DOCK_RIGHT; else if (q == 4 || q == 5) al = DOCK_BOTTOM; else if (q == 6 || q == 7) al = DOCK_LEFT; if (!allow_lr && (al == DOCK_LEFT || al == DOCK_RIGHT)) al = (q == 7 || q == 2) ? DOCK_TOP : DOCK_BOTTOM; else if (!allow_tb && (al == DOCK_TOP || al == DOCK_BOTTOM)) al = (q == 0 || q == 5) ? DOCK_LEFT : DOCK_RIGHT; return al; }
bool JResourceManager::LoadResource(const string& resourceName) { string path = /*mResourceRoot + */resourceName; // TiXmlDocument doc(path.c_str()); // // if (!doc.LoadFile()) return false; JGE *engine = JGE::GetInstance(); if (engine == NULL) return false; JFileSystem *fileSystem = JFileSystem::GetInstance(); if (fileSystem == NULL) return false; if (!fileSystem->OpenFile(path.c_str())) return false; int size = fileSystem->GetFileSize(); char *xmlBuffer = new char[size]; fileSystem->ReadFile(xmlBuffer, size); TiXmlDocument doc; doc.Parse(xmlBuffer); TiXmlNode* resource = 0; TiXmlNode* node = 0; TiXmlElement* element = 0; resource = doc.FirstChild("resource"); if (resource) { element = resource->ToElement(); printf("---- Loading %s:%s\n", element->Value(), element->Attribute("name")); for (node = resource->FirstChild(); node; node = node->NextSibling()) { element = node->ToElement(); if (element != NULL) { if (strcmp(element->Value(), "texture")==0) { CreateTexture(element->Attribute("name")); } else if (strcmp(element->Value(), "quad")==0) { string quadName = element->Attribute("name"); string textureName = element->Attribute("texture"); float x = 0.0f; float y = 0.0f; float width = 16.0f; float height = 16.0f; float value; float hotspotX = 0.0f; float hotspotY = 0.0f; if (element->QueryFloatAttribute("x", &value) == TIXML_SUCCESS) x = value; if (element->QueryFloatAttribute("y", &value) == TIXML_SUCCESS) y = value; if (element->QueryFloatAttribute("width", &value) == TIXML_SUCCESS) width = value; if (element->QueryFloatAttribute("height", &value) == TIXML_SUCCESS) height = value; if (element->QueryFloatAttribute("w", &value) == TIXML_SUCCESS) width = value; if (element->QueryFloatAttribute("h", &value) == TIXML_SUCCESS) height = value; if (element->QueryFloatAttribute("hotspot.x", &value) == TIXML_SUCCESS) hotspotX = value; else hotspotX = width/2; if (element->QueryFloatAttribute("hotspot.y", &value) == TIXML_SUCCESS) hotspotY = value; else hotspotY = height/2; // if (element->QueryFloatAttribute("regx", &value) == TIXML_SUCCESS) // hotspotX = width/2; // // if (element->QueryFloatAttribute("regy", &value) == TIXML_SUCCESS) // hotspotY = height/2; int id = CreateQuad(quadName, textureName, x, y, width, height); if (id != INVALID_ID) { GetQuad(id)->SetHotSpot(hotspotX, hotspotY); } } else if (strcmp(element->Value(), "font")==0) { } else if (strcmp(element->Value(), "music")==0) { LoadMusic(element->Attribute("name")); } else if (strcmp(element->Value(), "sample")==0) { LoadSample(element->Attribute("name")); } // else if (strcmp(element->Value(), "effect")==0) // { // RegisterParticleEffect(element->Attribute("name")); // } // else if (strcmp(element->Value(), "motion_emitter")==0) // { // RegisterMotionEmitter(element->Attribute("name")); // } } } } fileSystem->CloseFile(); delete[] xmlBuffer; // JGERelease(); return true; }