static IList* shiftLeft(IList* list){ IList *temp = newList(); temp->addAll(list); assert(temp != nullptr); temp->addBack(0); return temp; }
static IList* shiftRight(IList* list){ IList *temp = newList(); temp->addAll(list); assert(temp != nullptr); temp->addFront(0); return temp; }
//---------------------------------------------------------------------------------------- void UIJumpRegion::_clear() { IList* regionList = getLayout()->getList("list_regionMap"); DYNAMIC_ASSERT(regionList); regionList->removeAllItems(); mRegionMap.clear(); }
void CCEGLView::onTouchEvent(const Control& source, TouchStatus status) { IList *pList = null; do { CC_BREAK_IF(!m_pDelegate); int i = 0; Touch touch; pList = touch.GetTouchInfoListN(source); CC_BREAK_IF(pList == NULL); int pointerNumber = pList->GetCount(); CC_BREAK_IF(pointerNumber <= 0); int id[30] = {0}; float x[30] = {0}; float y[30] = {0}; for (i = 0; i < pointerNumber; i++) { TouchInfo *pTouchInfo = static_cast<TouchInfo *>(pList->GetAt(i)); id[i] = (int)pTouchInfo->id; float tmpX = (float)pTouchInfo->position.x; float tmpY = (float)pTouchInfo->position.y; if (!m_bNotHVGA) { x[i] = tmpX * 2 / 3; y[i] = tmpY * 2 / 3; } else { x[i] = tmpX; y[i] = tmpY; } } if (TOUCH_PRESSED == status) { onTouchesBegin(id, x, y, pointerNumber); } else if (TOUCH_MOVED == status) { onTouchesMove(id, x, y, pointerNumber); } else if (TOUCH_RELEASED == status) { onTouchesEnd(id, x, y, pointerNumber); } } while (0); if (pList != null) { pList->RemoveAll(true); delete pList; } }
IList<event::IKeyListener*> IGUIElement::getKeyListeners() const { IList<event::IKeyListener*> mListeners; for(std::set<event::IKeyListener*>::iterator iter = mKeyListeners.begin(); iter != mKeyListeners.end(); iter++) { mListeners.add(*iter); } return mListeners; }
static IList* addList(IList* list1, IList* list2){ IList *temp = newList(); IIterator* iter1 = list1->iterator(); IIterator* iter2 = list2->iterator(); while(iter1->hasNext()){ temp->addBack(iter1->next() + iter2->next()); } delete iter1; // don't forget delete iter2; // don't forget return temp; }
//---------------------------------------------------------------------------------------- void UIJumpRegion::setEvent() { IForm* mainForm = getLayout()->getForm("_Main"); DYNAMIC_ASSERT(mainForm); mainForm->setWindowButtonPressedEvent(onClickCloseBtn); IList* regionList = getLayout()->getList("list_regionMap"); DYNAMIC_ASSERT(regionList); regionList->setEventListMouseItemActivate(onSelectRegion); IButton* enterBtn = getLayout()->getButton("btn_enterRegion"); DYNAMIC_ASSERT(enterBtn); enterBtn->getWidget()->setMouseButtonClickEvent(onEnterRegion); }
v8::Handle<v8::Value> Contacts::isExistCategory(const v8::Arguments& args) { AppLogTag("Contacts", "Entered Contacts::isExistCategory (args: length:%d)", args.Length()); if (args.Length() < 1 || Util::isArgumentNull(args[0])) { AppLog("Bad parameters"); return v8::ThrowException(v8::String::New("Bad parameters")); } String name = null; v8::HandleScope scope; if(args[0]->IsString()) { name = UNWRAP_STRING(args[0]).c_str(); AppLogTag("Contacts","check Category:%ls", name.GetPointer()); } if(name == null) { AppLogTag("Contacts","category name is null"); return scope.Close(v8::Boolean::New(false)); } AddressbookManager* pAddressbookManager = AddressbookManager::GetInstance(); Addressbook* pAddressbook = pAddressbookManager->GetAddressbookN(DEFAULT_ADDRESSBOOK_ID); IList* pCategoryList = pAddressbook->GetAllCategoriesN(); result r = GetLastResult(); if (IsFailed(r)) { AppLog("Failed to get addressbook: %s", GetErrorMessage(r)); return scope.Close(v8::Boolean::New(false)); } if (pCategoryList != null && pCategoryList->GetCount() > 0) { IEnumerator* pCategoryEnum = pCategoryList->GetEnumeratorN(); Category* pCategory = null; while (pCategoryEnum->MoveNext() == E_SUCCESS) { pCategory = static_cast<Category*>(pCategoryEnum->GetCurrent()); if (pCategory->GetName().Equals(name)) { AppLog("It is existed category"); return scope.Close(v8::Boolean::New(true)); } } } AppLog("Non-exist category"); return scope.Close(v8::Boolean::New(false)); }
static IList *fastPascal(int n){ if(n == 1){ IList* list = newList(); list->addBack(1); // IList needs an 'add' method return list; } else{ IList* list = fastPascal(n-1); IList* list1 = shiftLeft(list); // need to keep track of object for clean up IList* list2 = shiftRight(list); // delete list; list = addList(list1,list2); delete list1; delete list2; return list; } }
void TouchEventForm::DisplayMultipointTouchInfo(const Control &source) { Touch touch; IList *pList = null; pList = touch.GetTouchInfoListN(source); if (pList) { for(int i=0; i<pList->GetCount(); i++ ) { TouchInfo *pTouchInfo = static_cast<TouchInfo *>(pList->GetAt(i)); AppLog("OnTouchMoved : [%d]%d,%d - %d", pTouchInfo->id, pTouchInfo->position.x ,pTouchInfo->position.y,pTouchInfo->status); } pList->RemoveAll(true); delete pList; } }
void badaNet::OnDnsResolutionCompletedN(IpHostEntry* ipHostEntry, result r) { if (r == E_SUCCESS && ipHostEntry != null) { IList* addressList = ipHostEntry->GetAddressList(); Ip4Address* pIp4Address = static_cast<Ip4Address*> (addressList->GetAt(0)); addr->pHostaddr = new String(pIp4Address->ToString()); char buf[64] = { 0 }; wcstombs(buf, pIp4Address->ToString().GetPointer(), 64); delete ipHostEntry; /* * go to ssh backend, let her know we're done */ plug_dns(plug, addr); }else{ plug_dns(plug, NULL); } delete pDns; pDns = 0; }
v8::Handle<v8::Value> Contacts::removeCategory(const v8::Arguments& args) { AppLog("Entered Contacts::removeCategory (args length:%d)", args.Length()); if (args.Length() < 2 || Util::isArgumentNull(args[0]) || Util::isArgumentNull(args[1])) { AppLog("Bad parameters"); return v8::ThrowException(v8::String::New("Bad parameters")); } v8::HandleScope scope; String category = UNWRAP_STRING(args[0]).c_str(); String force = UNWRAP_STRING(args[1]).c_str(); AddressbookManager* pAddressbookManager = AddressbookManager::GetInstance(); Addressbook* pAddressbook = pAddressbookManager->GetAddressbookN(DEFAULT_ADDRESSBOOK_ID); IList* pCategoryList = pAddressbook->GetAllCategoriesN(); result r = GetLastResult(); if (IsFailed(r)) { AppLog("Failed to get addressbook: %s", GetErrorMessage(r)); return scope.Close(v8::Boolean::New(false)); } if (pCategoryList != null && pCategoryList->GetCount() > 0) { IEnumerator* pCategoryEnum = pCategoryList->GetEnumeratorN(); Category* pCategory = null; while (pCategoryEnum->MoveNext() == E_SUCCESS) { pCategory = static_cast<Category*>(pCategoryEnum->GetCurrent()); if (pCategory->GetName().Equals(category)) { r = pAddressbook->RemoveCategory(*pCategory); if (IsFailed(r)) { AppLog("Fail to remove category: %s", GetErrorMessage(r)); return scope.Close(v8::Boolean::New(false)); } else { AppLog("Succeed to remove category"); break; } } } } return scope.Close(v8::Boolean::New(true)); }
void ImportsList::initialise( IList<IPosition<SourceToken> >& importPositions ) { IIterator<IPosition<SourceToken> >* it = importPositions.elements(); while ( it->hasNext() ) { this->imports->insertLast( new Import( this->cu, it->next() ) ); } delete it; this->addBlank(); }
IList<INode*> INode::GetNodeByName(IString name, bool recursive) { IList<INode*> result; FOREACH(INode*,ite,m_aChildren) { if (ite.GetData()) { INode *node = ite.GetData(); if (name==node->m_sName) result.PushBack(node); if (recursive) { IList<INode*> resultRec = node->GetNodeByName(name,true); for (UINT j=0;j<resultRec.Count();j++) result.PushBack(resultRec[j]); } } } return result; }
IList<INode*> INode::GetNodeByClass(IObject::IObjectInfo *classinfo, bool recursive, bool noSubClass) { IList<INode*> result; FOREACH(INode*,ite,m_aChildren) { if (ite.GetData()) { INode *node = ite.GetData(); if (noSubClass) { if (node->GetStaticClass()==classinfo) result.PushBack(node); }else{ if (node->IsKindOf(classinfo)) result.PushBack(node); } if (recursive) { IList<INode*> resultRec = node->GetNodeByClass(classinfo,true); for (UINT j=0;j<resultRec.Count();j++) result.PushBack(resultRec[j]); } } } return result; }
int main() { IList<int> list; list.add(1); list.add(2); list.add(3); list.add(2); list.add(1); list.add(2); list.size(); list.numberOf(2); list.removeAll(1); list.size(); return 0; }
IPlayer *PlayerBinder::BindPlayerData() { // First we need to create a list of ICharacter's assume NULL active character. IList<ICharacter*> *characterList = new List<ICharacter*>(); ICharacter *activeCharacter = NULL; // Retrieve the active character ID column from databasePlayer unsigned int activeCharacterId = this->databasePlayer->GetActiveCharacterID(); // Get the counts of the database collections (for looping) unsigned int characterCount = this->dbCharacters->Size(); unsigned int skillCount = this->databaseSkills->Size(); unsigned int questCount = this->databaseQuests->Size(); unsigned int itemCount = this->databaseItems->Size(); // Loop through the database characters for(unsigned int characterIndex = 0; characterIndex < characterCount; characterIndex++) { IDBCharacter *dbCharacter = this->dbCharacters->At(characterIndex); // Retrieve the ID column from dbCharacter unsigned int characterId = dbCharacter->GetID(); // Create lists for ISkill's, IItem's, and IQuest's IList<ISkill*> *skillList = new List<ISkill*>(); IList<IItem*> *itemList = new List<IItem*>(); IList<IQuest*> *questList = new List<IQuest*>(); // Loop through the database items and determine which pertain to dbCharacter for(unsigned int itemIndex = 0; itemIndex < itemCount; itemIndex++) { IDBItem *dbItem = this->databaseItems->At(itemIndex); // If the item doesn't belong to dbCharacter, skip it if(dbItem->GetCharacterID() != characterId) { continue; } IMap<String> *properties = this->_ParseKVToMap(dbItem->GetData()); IItem *item = new Item("ITEM NAME", dbItem->GetClass(), properties); itemList->Append(item); } // Loop through the database skills and determine which pertain to dbCharacter for(unsigned int skillIndex = 0; skillIndex < skillCount; skillIndex++) { IDBSkill *dbSkill = this->databaseSkills->At(skillIndex); // If the item doesn't belong to dbCharacter, skip it if(dbSkill->GetCharacterID() != characterId) { continue; } ISkill *skill = new Skill("SKILL NAME", dbSkill->GetClass(), dbSkill->GetLevel()); skillList->Append(skill); } // Loop through the database quests and determine which pertain to dbCharacter for(unsigned int questIndex = 0; questIndex < questCount; questIndex++) { IDBQuest *dbQuest = this->databaseQuests->At(questIndex); // If the item doesn't belong to dbCharacter, skip it if(dbQuest->GetCharacterID() != characterId) { continue; } IMap<String> *properties = this->_ParseKVToMap(dbQuest->GetData()); IQuest *quest = new Quest("QUEST NAME", dbQuest->GetClass(), properties); questList->Append(quest); } ICharacter *character = new Character("CHAR NAME", dbCharacter->GetClass(), dbCharacter->GetLevel(), dbCharacter->GetXP(), skillList, itemList, questList); if(activeCharacterId == characterId) { activeCharacter = character; } characterList->Append(character); } IPlayer *player = new Player(characterList, activeCharacter); return player; }
int main(int argc, char *argv[]) { try { // Retrieve program options string compilerName; string logfile; string loglevel = Log::UnMapLevel(Log::INFO); string graphdir; po::options_description desc(PROGRAM_NAME + " usage"); desc.add_options() ("help,h", "show help message") ("compiler,c", po::value<string>(&compilerName), "compiler name") ("logfile,f", po::value<string>(&logfile), "output log file") ("loglevel,L", po::value<string>(&loglevel), "log level: debug, info, warning, error") ("graphdir,g", po::value<string>(&graphdir), "output graph directory") ; po::positional_options_description p; p.add("compiler", 1); po::variables_map vm; try { po::store(po::command_line_parser(argc, argv).options(desc).positional(p).run(), vm); po::notify(vm); if (vm.count("help")) { cout << desc; return 0; } } catch (po::error& e) { cout << desc; return 1; } // Initialize logging if (!logfile.empty()) { g_log.setLevel(loglevel); g_log.Init(logfile); } auto_ptr<Compiler> compiler = MakeCompiler(compilerName); if (compiler->empty()) { throw statik::SError("Empty compiler; nothing to do"); } typedef boost::ptr_vector<Connector> connector_vec; typedef connector_vec::iterator connector_mod_iter; connector_vec connectors; for (Compiler_iter i = compiler->begin(); i != compiler->end(); ++i) { g_log.info() << "Compiler item: " << i->Print(); connectors.push_back(new Connector(*i, i->Name(), graphdir)); } IList* start = NULL; IList* prev = NULL; string line; while (getline(cin, line)) { //line += "\n"; // check for delete if (line.size() >= 2 && line.size() <= 3 && line[0] == 'D' && line[1] >= '0' && line[1] <= '9') { if (!start) { throw SError("Cannot delete start of input: no input yet"); } int delnum = line[1] - '0'; if (line.size() == 3 && line[2] >= '0' && line[2] <= '9') { delnum *= 10; delnum += line[2] - '0'; } IList* s = start; if (!s) { throw SError("Cannot delete entry without start"); } if (0 == delnum) { start = start->right; } for (int i = 0; i < delnum; ++i) { s = s->right; if (!s) { throw SError("Reached end of input before reaching deletion index"); } } g_log.info(); g_log.info() << "* main: Deleting character '" << *s; if (s->left) { s->left->right = s->right; } if (s->right) { s->right->left = s->left; } connectors.at(0).Delete(*s); const Hotlist* hotlist = &connectors.at(0).GetHotlist(); connector_mod_iter prevConnector = connectors.begin(); for (connector_mod_iter i = connectors.begin()+1; i != connectors.end(); ++i) { if (hotlist->IsEmpty()) { g_log.info() << "* main: Connector returned no hotlist items."; break; } else { g_log.info() << "* main: Connector returned hotlist; sending to parser. Hotlist:" << hotlist->Print(); i->UpdateWithHotlist(hotlist->GetHotlist()); prevConnector->ClearHotlist(); hotlist = &i->GetHotlist(); } } continue; } for (size_t i=0; i < line.size(); ++i) { IList* c = new IList("", string(1, line.at(i))); if (!start) { start = c; } if (prev) { prev->right = c; c->left = prev; } g_log.info(); g_log.info() << "* main: Inserting character '" << c->Print(); connectors.at(0).Insert(*c); const Hotlist* hotlist = &connectors.at(0).GetHotlist(); connector_mod_iter prevConnector = connectors.begin(); for (connector_mod_iter i = connectors.begin()+1; i != connectors.end(); ++i) { if (hotlist->IsEmpty()) { g_log.info() << "* main: Connector returned no hotlist items."; break; } else { g_log.info() << "* main: Connector returned hotlist; sending to parser. Hotlist:" << hotlist->Print(); i->UpdateWithHotlist(hotlist->GetHotlist()); prevConnector->ClearHotlist(); hotlist = &i->GetHotlist(); } } prev = c; } } g_log.info() << "Clearing input"; IList* i = start; while (i) { IList* j = i->right; delete i; i = j; } } catch (const SError& e) { g_log.error() << "Compilation framework error: " << e.what() << endl; return 1; } catch (const std::exception& e) { g_log.error() << "Unknown error: " << e.what() << endl; return 1; } catch (...) { g_log.error() << "Unknown error" << endl; return 1; } return 0; }
void UsersPanel::BuildIndexForUser(JsonArray * friends) { /* String letter, prevLetter = L""; int currentGroup = 0; JsonArray * array = new JsonArray(); array->Construct(); for (int i=0; i<friends->GetCount(); i++) { JsonObject *user; JsonParseUtils::GetObject(friends, i, user); String name; JsonParseUtils::GetString(*user, L"first_name", name); name.SubString(0, 1, letter); if (letter != prevLetter) { _fastScrollIndex.Append(letter); _pCurrentModel->AddUserGroup(prevLetter, array); if (prevLetter.GetLength() > 0) { AppLog("Adding %ls to %d item", prevLetter.GetPointer(), currentGroup); _pLetterNav->Add(new String(prevLetter), new Integer(currentGroup)); currentGroup++; } prevLetter = letter; delete array; array = new JsonArray(); array->Construct(); } else { array->Add(user); } }*/ HashMap *letterMap = new HashMap(); letterMap->Construct(); for(int i = 0; i < friends->GetCount(); i++) { JsonObject *user; JsonParseUtils::GetObject(friends, i, user); String name; JsonParseUtils::GetString(*user, L"first_name", name); String letter; name.SubString(0, 1, letter); JsonArray *letterArray; if(!letterMap->ContainsKey(letter)) { letterArray = new JsonArray(); letterArray->Construct(); letterMap->Add(new String(letter), letterArray); } else { letterArray = static_cast<JsonArray*>(letterMap->GetValue(letter)); } letterArray->Add(user); } IList *letterList = letterMap->GetKeysN(); StringComparer comparer; letterList->Sort(comparer); for(int i = 0; i < letterList->GetCount(); i++) { String *letter = static_cast<String *>(letterList->GetAt(i)); _fastScrollIndex.Append(*letter); _pCurrentModel->AddUserGroup(*letter, static_cast<JsonArray *>(letterMap->GetValue(*letter))); _pLetterNav->Add(new String(*letter), new Integer(i)); } delete letterList; delete letterMap; }
INavMesh *NavMeshLoader::Load(char *error, int errorMaxlen) { strcpy_s(error, errorMaxlen, ""); char navPath[1024]; g_pSM->BuildPath(Path_Game, navPath, sizeof(navPath), "maps\\%s.nav", this->mapName); FILE *fileHandle = fopen(navPath, "rb"); if(!fileHandle) { sprintf_s(error, errorMaxlen, "Unable to find navigation mesh: %s", navPath); return NULL; } unsigned int magicNumber; int elementsRead = this->ReadData(&magicNumber, sizeof(unsigned int), 1, fileHandle); if(elementsRead != 1) { fclose(fileHandle); sprintf_s(error, errorMaxlen, "Error reading magic number value from navigation mesh: %s", navPath); return NULL; } if(magicNumber != 0xFEEDFACE) { fclose(fileHandle); sprintf_s(error, errorMaxlen, "Invalid magic number value from navigation mesh: %s [%p]", navPath, magicNumber); return NULL; } unsigned int version; elementsRead = this->ReadData(&version, sizeof(unsigned int), 1, fileHandle); if(elementsRead != 1) { fclose(fileHandle); sprintf_s(error, errorMaxlen, "Error reading version number from navigation mesh: %s", navPath); return NULL; } if (version < 6 || version > 16) { fclose(fileHandle); sprintf_s(error, errorMaxlen, "Invalid version number value from navigation mesh: %s [%d]", navPath, version); return NULL; } unsigned int navMeshSubVersion = 0; if(version >= 10) { this->ReadData(&navMeshSubVersion, sizeof(unsigned int), 1, fileHandle); } unsigned int saveBspSize; this->ReadData(&saveBspSize, sizeof(unsigned int), 1, fileHandle); char bspPath[1024]; g_pSM->BuildPath(Path_Game, bspPath, sizeof(bspPath), "maps\\%s.bsp", this->mapName); unsigned int actualBspSize = 0; #ifdef PLATFORM_WINDOWS struct _stat s; _stat(bspPath, &s); actualBspSize = s.st_size; #elif defined PLATFORM_POSIX struct stat s; stat(bspPath, &s); actualBspSize = s.st_size; #endif if(actualBspSize != saveBspSize) { META_CONPRINTF("WARNING: Navigation mesh was not built with the same version of the map [%d vs %d].\n", actualBspSize, saveBspSize); } unsigned char meshAnalyzed = 0; if(version >= 14) { this->ReadData(&meshAnalyzed, sizeof(unsigned char), 1, fileHandle); } bool isMeshAnalyzed = meshAnalyzed != 0; //META_CONPRINTF("Is mesh analyzed: %s\n", isMeshAnalyzed ? "yes" : "no"); unsigned short placeCount; this->ReadData(&placeCount, sizeof(unsigned short), 1, fileHandle); //META_CONPRINTF("Nav version: %d; BSPSize: %d; MagicNumber: %p; SubVersion: %d [v10+only]; Place Count: %d\n", version, saveBspSize, magicNumber, navMeshSubVersion, placeCount); List<INavMeshPlace*> *places = new List<INavMeshPlace*>(); for(unsigned int placeIndex = 0; placeIndex < placeCount; placeIndex++) { unsigned short placeSize; this->ReadData(&placeSize, sizeof(unsigned short), 1, fileHandle); char placeName[256]; this->ReadData(placeName, sizeof(unsigned char), placeSize, fileHandle); places->Append(new NavMeshPlace(placeIndex, placeName)); //META_CONPRINTF("Parsed place: %s [%d]\n", placeName, placeIndex); } unsigned char unnamedAreas = 0; if(version > 11) { this->ReadData(&unnamedAreas, sizeof(unsigned char), 1, fileHandle); } bool hasUnnamedAreas = unnamedAreas != 0; //META_CONPRINTF("Has unnamed areas: %s\n", hasUnnamedAreas ? "yes" : "no"); IList<INavMeshArea*> *areas = new List<INavMeshArea*>(); unsigned int areaCount; this->ReadData(&areaCount, sizeof(unsigned int), 1, fileHandle); //META_CONPRINTF("Area count: %d\n", areaCount); for(unsigned int areaIndex = 0; areaIndex < areaCount; areaIndex++) { unsigned int areaID; float x1, y1, z1, x2, y2, z2; unsigned int areaFlags = 0; IList<INavMeshConnection*> *connections = new List<INavMeshConnection*>(); IList<INavMeshHidingSpot*> *hidingSpots = new List<INavMeshHidingSpot*>(); IList<INavMeshEncounterPath*> *encounterPaths = new List<INavMeshEncounterPath*>(); IList<INavMeshLadderConnection*> *ladderConnections = new List<INavMeshLadderConnection*>(); IList<INavMeshCornerLightIntensity*> *cornerLightIntensities = new List<INavMeshCornerLightIntensity*>(); IList<INavMeshVisibleArea*> *visibleAreas = new List<INavMeshVisibleArea*>(); unsigned int inheritVisibilityFrom = 0; unsigned char hidingSpotCount = 0; unsigned int visibleAreaCount = 0; float earliestOccupyTimeFirstTeam = 0.0f; float earliestOccupyTimeSecondTeam = 0.0f; float northEastCornerZ; float southWestCornerZ; unsigned short placeID = 0; unsigned char unk01 = 0; this->ReadData(&areaID, sizeof(unsigned int), 1, fileHandle); //META_CONPRINTF("Area ID: %d\n", areaID); if(version <= 8) { this->ReadData(&areaFlags, sizeof(unsigned char), 1, fileHandle); } else if(version < 13) { this->ReadData(&areaFlags, sizeof(unsigned short), 1, fileHandle); } else { this->ReadData(&areaFlags, sizeof(unsigned int), 1, fileHandle); } //META_CONPRINTF("Area Flags: %d\n", areaFlags); this->ReadData(&x1, sizeof(float), 1, fileHandle); this->ReadData(&y1, sizeof(float), 1, fileHandle); this->ReadData(&z1, sizeof(float), 1, fileHandle); this->ReadData(&x2, sizeof(float), 1, fileHandle); this->ReadData(&y2, sizeof(float), 1, fileHandle); this->ReadData(&z2, sizeof(float), 1, fileHandle); //META_CONPRINTF("Area extent: (%f, %f, %f), (%f, %f, %f)\n", x1, y1, z1, x2, y2, z2); this->ReadData(&northEastCornerZ, sizeof(float), 1, fileHandle); this->ReadData(&southWestCornerZ, sizeof(float), 1, fileHandle); //META_CONPRINTF("Corners: NW(%f), SW(%f)\n", northEastCornerZ, southWestCornerZ); // CheckWaterLevel() are we underwater in this area? for(unsigned int direction = 0; direction < NAV_DIR_COUNT; direction++) { unsigned int connectionCount; this->ReadData(&connectionCount, sizeof(unsigned int), 1, fileHandle); //META_CONPRINTF("Connection count: %d (%p)\n", connectionCount, connectionCount); for(int connectionIndex = 0; connectionIndex < connectionCount; connectionIndex++) { unsigned int connectingAreaID; this->ReadData(&connectingAreaID, sizeof(unsigned int), 1, fileHandle); INavMeshConnection *connection = new NavMeshConnection(connectingAreaID, (NavDirType)direction); connections->Append(connection); } } this->ReadData(&hidingSpotCount, sizeof(unsigned char), 1, fileHandle); //META_CONPRINTF("Hiding Spot Count: %d\n", hidingSpotCount); for(unsigned int hidingSpotIndex = 0; hidingSpotIndex < hidingSpotCount; hidingSpotIndex++) { unsigned int hidingSpotID; this->ReadData(&hidingSpotID, sizeof(unsigned int), 1, fileHandle); float hidingSpotX, hidingSpotY, hidingSpotZ; this->ReadData(&hidingSpotX, sizeof(float), 1, fileHandle); this->ReadData(&hidingSpotY, sizeof(float), 1, fileHandle); this->ReadData(&hidingSpotZ, sizeof(float), 1, fileHandle); unsigned char hidingSpotFlags; this->ReadData(&hidingSpotFlags, sizeof(unsigned char), 1, fileHandle); INavMeshHidingSpot *hidingSpot = new NavMeshHidingSpot(hidingSpotID, hidingSpotX, hidingSpotY, hidingSpotZ, hidingSpotFlags); hidingSpots->Append(hidingSpot); //META_CONPRINTF("Parsed hiding spot (%f, %f, %f) with ID [%p] and flags [%p]\n", hidingSpotX, hidingSpotY, hidingSpotZ, hidingSpotID, hidingSpotFlags); } // These are old but we just need to read the data. if(version < 15) { unsigned char approachAreaCount; this->ReadData(&approachAreaCount, sizeof(unsigned char), 1, fileHandle); for(unsigned int approachAreaIndex = 0; approachAreaIndex < approachAreaCount; approachAreaIndex++) { unsigned int approachHereID; this->ReadData(&approachHereID, sizeof(unsigned int), 1, fileHandle); unsigned int approachPrevID; this->ReadData(&approachPrevID, sizeof(unsigned int), 1, fileHandle); unsigned char approachType; this->ReadData(&approachType, sizeof(unsigned char), 1, fileHandle); unsigned int approachNextID; this->ReadData(&approachNextID, sizeof(unsigned int), 1, fileHandle); unsigned char approachHow; this->ReadData(&approachHow, sizeof(unsigned char), 1, fileHandle); } } unsigned int encounterPathCount; this->ReadData(&encounterPathCount, sizeof(unsigned int), 1, fileHandle); //META_CONPRINTF("Encounter Path Count: %d\n", encounterPathCount); for(unsigned int encounterPathIndex = 0; encounterPathIndex < encounterPathCount; encounterPathIndex++) { unsigned int encounterFromID; this->ReadData(&encounterFromID, sizeof(unsigned int), 1, fileHandle); unsigned char encounterFromDirection; this->ReadData(&encounterFromDirection, sizeof(unsigned char), 1, fileHandle); unsigned int encounterToID; this->ReadData(&encounterToID, sizeof(unsigned int), 1, fileHandle); unsigned char encounterToDirection; this->ReadData(&encounterToDirection, sizeof(unsigned char), 1, fileHandle); unsigned char encounterSpotCount; this->ReadData(&encounterSpotCount, sizeof(unsigned char), 1, fileHandle); //META_CONPRINTF("Encounter [from ID %d] [from dir %p] [to ID %d] [to dir %p] [spot count %d]\n", encounterFromID, encounterFromDirection, encounterToID, encounterToDirection, encounterSpotCount); IList<INavMeshEncounterSpot*> *encounterSpots = new List<INavMeshEncounterSpot*>(); for(int encounterSpotIndex = 0; encounterSpotIndex < encounterSpotCount; encounterSpotIndex++) { unsigned int encounterSpotOrderId; this->ReadData(&encounterSpotOrderId, sizeof(unsigned int), 1, fileHandle); unsigned char encounterSpotT; this->ReadData(&encounterSpotT, sizeof(unsigned char), 1, fileHandle); float encounterSpotParametricDistance = (float)encounterSpotT / 255.0f; INavMeshEncounterSpot *encounterSpot = new NavMeshEncounterSpot(encounterSpotOrderId, encounterSpotParametricDistance); encounterSpots->Append(encounterSpot); //META_CONPRINTF("Encounter spot [order id %d] and [T %p]\n", encounterSpotOrderId, encounterSpotT); } INavMeshEncounterPath *encounterPath = new NavMeshEncounterPath(encounterFromID, (NavDirType)encounterFromDirection, encounterToID, (NavDirType)encounterToDirection, encounterSpots); encounterPaths->Append(encounterPath); } this->ReadData(&placeID, sizeof(unsigned short), 1, fileHandle); //META_CONPRINTF("Place ID: %d\n", placeID); for(unsigned int ladderDirection = 0; ladderDirection < NAV_LADDER_DIR_COUNT; ladderDirection++) { unsigned int ladderConnectionCount; this->ReadData(&ladderConnectionCount, sizeof(unsigned int), 1, fileHandle); //META_CONPRINTF("Ladder Connection Count: %d\n", ladderConnectionCount); for(unsigned int ladderConnectionIndex = 0; ladderConnectionIndex < ladderConnectionCount; ladderConnectionIndex++) { unsigned int ladderConnectID; this->ReadData(&ladderConnectID, sizeof(unsigned int), 1, fileHandle); INavMeshLadderConnection *ladderConnection = new NavMeshLadderConnection(ladderConnectID, (NavLadderDirType)ladderDirection); ladderConnections->Append(ladderConnection); //META_CONPRINTF("Parsed ladder connect [ID %d]\n", ladderConnectID); } } this->ReadData(&earliestOccupyTimeFirstTeam, sizeof(float), 1, fileHandle); this->ReadData(&earliestOccupyTimeSecondTeam, sizeof(float), 1, fileHandle); if(version >= 11) { for (int navCornerIndex = 0; navCornerIndex < NAV_CORNER_COUNT; navCornerIndex++) { float navCornerLightIntensity; this->ReadData(&navCornerLightIntensity, sizeof(float), 1, fileHandle); INavMeshCornerLightIntensity *cornerLightIntensity = new NavMeshCornerLightIntensity((NavCornerType)navCornerIndex, navCornerLightIntensity); cornerLightIntensities->Append(cornerLightIntensity); //META_CONPRINTF("Light intensity: [%f] [idx %d]\n", navCornerLightIntensity, navCornerIndex); } if(version >= 16) { this->ReadData(&visibleAreaCount, sizeof(unsigned int), 1, fileHandle); //META_CONPRINTF("Visible area count: %d\n", visibleAreaCount); for(unsigned int visibleAreaIndex = 0; visibleAreaIndex < visibleAreaCount; visibleAreaIndex++) { unsigned int visibleAreaID; this->ReadData(&visibleAreaID, sizeof(unsigned int), 1, fileHandle); unsigned char visibleAreaAttributes; this->ReadData(&visibleAreaAttributes, sizeof(unsigned char), 1, fileHandle); INavMeshVisibleArea *visibleArea = new NavMeshVisibleArea(visibleAreaID, visibleAreaAttributes); visibleAreas->Append(visibleArea); //META_CONPRINTF("Parsed visible area [%d] with attr [%p]\n", visibleAreaID, visibleAreaAttributes); } this->ReadData(&inheritVisibilityFrom, sizeof(unsigned int), 1, fileHandle); //META_CONPRINTF("Inherit visibilty from: %d\n", inheritVisibilityFrom); this->ReadData(&unk01, sizeof(unsigned char), 1, fileHandle); } } INavMeshArea *area = new NavMeshArea(areaID, areaFlags, placeID, x1, y1, z1, x2, y2, z2, northEastCornerZ, southWestCornerZ, connections, hidingSpots, encounterPaths, ladderConnections, cornerLightIntensities, visibleAreas, inheritVisibilityFrom, earliestOccupyTimeFirstTeam, earliestOccupyTimeSecondTeam, unk01); areas->Append(area); } unsigned int ladderCount; this->ReadData(&ladderCount, sizeof(unsigned int), 1, fileHandle); //META_CONPRINTF("Ladder count: %d\n", ladderCount); IList<INavMeshLadder*> *ladders = new List<INavMeshLadder*>(); for(unsigned int ladderIndex = 0; ladderIndex < ladderCount; ladderIndex++) { unsigned int ladderID; this->ReadData(&ladderID, sizeof(unsigned int), 1, fileHandle); float ladderWidth; this->ReadData(&ladderWidth, sizeof(float), 1, fileHandle); float ladderTopX, ladderTopY, ladderTopZ, ladderBottomX, ladderBottomY, ladderBottomZ; this->ReadData(&ladderTopX, sizeof(float), 1, fileHandle); this->ReadData(&ladderTopY, sizeof(float), 1, fileHandle); this->ReadData(&ladderTopZ, sizeof(float), 1, fileHandle); this->ReadData(&ladderBottomX, sizeof(float), 1, fileHandle); this->ReadData(&ladderBottomY, sizeof(float), 1, fileHandle); this->ReadData(&ladderBottomZ, sizeof(float), 1, fileHandle); float ladderLength; this->ReadData(&ladderLength, sizeof(float), 1, fileHandle); unsigned int ladderDirection; this->ReadData(&ladderDirection, sizeof(unsigned int), 1, fileHandle); unsigned int ladderTopForwardAreaID; this->ReadData(&ladderTopForwardAreaID, sizeof(unsigned int), 1, fileHandle); unsigned int ladderTopLeftAreaID; this->ReadData(&ladderTopLeftAreaID, sizeof(unsigned int), 1, fileHandle); unsigned int ladderTopRightAreaID; this->ReadData(&ladderTopRightAreaID, sizeof(unsigned int), 1, fileHandle); unsigned int ladderTopBehindAreaID; this->ReadData(&ladderTopBehindAreaID, sizeof(unsigned int), 1, fileHandle); unsigned int ladderBottomAreaID; this->ReadData(&ladderBottomAreaID, sizeof(unsigned int), 1, fileHandle); INavMeshLadder *ladder = new NavMeshLadder(ladderID, ladderWidth, ladderLength, ladderTopX, ladderTopY, ladderTopZ, ladderBottomX, ladderBottomY, ladderBottomZ, (NavDirType)ladderDirection, ladderTopForwardAreaID, ladderTopLeftAreaID, ladderTopRightAreaID, ladderTopBehindAreaID, ladderBottomAreaID); ladders->Append(ladder); } fclose(fileHandle); INavMesh *mesh = new NavMesh(magicNumber, version, navMeshSubVersion, saveBspSize, isMeshAnalyzed, places, areas, ladders); return mesh; }
result CameraRecorderForm::__InitCameraRecorder( void ) { result r = E_SUCCESS; IListT<CodecType>* pAudioCodecList = null; IListT<CodecType>* pVideoCodecList = null; IListT<MediaContainerType>* pMediaContainerList = null; IList* pRecordingResolutionList = null; CodecType audioCodec = CODEC_NONE; CodecType videoCodec = CODEC_NONE; MediaContainerType mediaContainer = MEDIA_CONTAINER_NONE; Dimension cameraPreviewDim; String fileExt; __pCameraRecorder = new CameraRecorder(); if(null == __pCameraRecorder) { AppLogException("Creating CameraRecorder failed.."); return E_OUT_OF_MEMORY; } r = __pCameraRecorder->Construct(*this, *__pCamera); if (IsFailed(r)) { AppLogException("Construct of camera recorder failed."); goto CATCH; } pAudioCodecList = __pCameraRecorder->GetSupportedAudioCodecListN(); if (pAudioCodecList == null ) { AppLogException("There is no supported audio codec."); goto CATCH; } #ifdef __DEBUG { int count = pAudioCodecList->GetCount (); for ( int i = 0; i < count; i++ ) { pAudioCodecList->GetAt(i,audioCodec); AppLog("Codec[%dst] is 0x%x", i, (int)audioCodec); } } #endif pVideoCodecList = __pCameraRecorder->GetSupportedVideoCodecListN(); if (pAudioCodecList == null ) { AppLogException("There is no supported audio codec."); goto CATCH; } #ifdef __DEBUG { int count = pVideoCodecList->GetCount (); for ( int i = 0; i < count; i++ ) { pVideoCodecList->GetAt(i, videoCodec); AppLog("Codec[%dst] is 0x%x", i, (int)videoCodec); } } #endif pMediaContainerList = __pCameraRecorder->GetSupportedContainerListN(); if (pMediaContainerList == null ) { AppLogException("There is no supported container."); goto CATCH; } #ifdef __DEBUG { int count = pMediaContainerList->GetCount (); for ( int i = 0; i < count; i++ ) { pMediaContainerList->GetAt(i, mediaContainer); AppLog("Container[%dst] is 0x%x", i, (int)mediaContainer); } } #endif //Getting default codec and container r = __pCameraRecorder->GetFormat( audioCodec, videoCodec, mediaContainer); if (IsFailed(r)) { AppLogException("__pCameraRecorder->GetFormat has failed."); goto CATCH; } if (pAudioCodecList->Contains(CODEC_AAC) &&pVideoCodecList->Contains(CODEC_H264) &&pMediaContainerList->Contains(MEDIA_CONTAINER_MP4)) { r = __pCameraRecorder->SetFormat( CODEC_AAC, CODEC_H264, MEDIA_CONTAINER_MP4); mediaContainer = MEDIA_CONTAINER_MP4; audioCodec = CODEC_AAC; videoCodec = CODEC_H264; } else if (pAudioCodecList->Contains(CODEC_AMR_NB) &&pVideoCodecList->Contains(CODEC_H263) &&pMediaContainerList->Contains(MEDIA_CONTAINER_3GP)) { r = __pCameraRecorder->SetFormat( CODEC_AMR_NB, CODEC_H263, MEDIA_CONTAINER_3GP); mediaContainer = MEDIA_CONTAINER_3GP; audioCodec = CODEC_AMR_NB; videoCodec = CODEC_H263; } else { // system default setting r = E_SUCCESS; } if (IsFailed(r)) { AppLogException("Setting codecs and container failed."); goto CATCH; } SampleVideoFile = String(SAMPLE_FILE); SampleVideoFile.Append(L"."); switch (mediaContainer) { case MEDIA_CONTAINER_3GP: fileExt = L"3GP"; break; case MEDIA_CONTAINER_MP4: fileExt = L"MP4"; break; default: fileExt = L"unknown"; break; } SampleVideoFile.Append(fileExt); /* -------------------------------------------------------------------------------------------------------------------- * This is important. VideoRecorder's recording resolution SHOULD follow the Camera's preview resolution. */ pRecordingResolutionList = __pCameraRecorder->GetSupportedRecordingResolutionListN(); if (pRecordingResolutionList == null ) { AppLogException("There is no supported recording resolution."); goto CATCH; } cameraPreviewDim = GetCamera()->GetPreviewResolution(); #ifdef __DEBUG { int count = pRecordingResolutionList->GetCount (); for ( int i = 0; i < count; i++ ) { Dimension* pRecordingResolution = (Dimension*)pRecordingResolutionList->GetAt(i); AppLog("Resolution[%dst] is (%d, %d)", i, pRecordingResolution->width, pRecordingResolution->height); } } #endif r = __pCameraRecorder->SetRecordingResolution(cameraPreviewDim); if (IsFailed(r)) { // Camera's preview resolution should be same with one of recorder's supported resolutions. // Camera should be stopped for changing the preview resolution. AppLog("Currently camera's preview resolution(%d,%d) is not supported for the video recorder.", cameraPreviewDim.width, cameraPreviewDim.height); int recorderSupportedResolutionCount = pRecordingResolutionList->GetCount(); if ( recorderSupportedResolutionCount <= 0 ) goto CATCH; int i = recorderSupportedResolutionCount-1; r = CameraForm::Stop(); if ( IsFailed(r) ) goto CATCH; for ( ; i >= 0; i-- ) { Object* pObj = null; Dimension* pDim = null; pObj = pRecordingResolutionList->GetAt( i ); pDim = static_cast<Dimension*>(pObj); if ( pDim == null ) goto CATCH; AppLog("Try to set camera preview resolution with video recorder's resolution(%d,%d).", pDim->width, pDim->height); r = GetCamera()->SetPreviewResolution(*pDim); if ( r == E_SUCCESS ) { r = __pCameraRecorder->SetRecordingResolution(*pDim); if ( IsFailed(r) ) goto CATCH; AppLog("Complete to set camera and video recorder's resolution to (%d,%d).", pDim->width, pDim->height); break; } } if ( i < 0 ) goto CATCH; r = CameraForm::Start(); if ( IsFailed(r) ) goto CATCH; } /* * ------------------------------------------------------------------------------------------------ */ r = __pCameraRecorder->SetMaxRecordingSize(1024*5); //1024*5 Kb if (IsFailed(r)) { AppLogException("Setting max recording size failed."); goto CATCH; } r = __pCameraRecorder->SetMaxRecordingTime(120*1000); // 120 sec if (IsFailed(r)) { AppLogException("Setting max recording time failed."); goto CATCH; } pAudioCodecList->RemoveAll(); delete pAudioCodecList; pAudioCodecList = null; pVideoCodecList->RemoveAll(); delete pVideoCodecList; pVideoCodecList = null; pMediaContainerList->RemoveAll(); delete pMediaContainerList; pMediaContainerList = null; pRecordingResolutionList->RemoveAll(true); delete pRecordingResolutionList; pRecordingResolutionList = null; return E_SUCCESS; CATCH: if ( pAudioCodecList ) { pAudioCodecList->RemoveAll(); delete pAudioCodecList; } if ( pVideoCodecList ) { pVideoCodecList->RemoveAll(); delete pVideoCodecList; } if ( pMediaContainerList ) { pMediaContainerList->RemoveAll(); delete pMediaContainerList; } if ( pRecordingResolutionList ) { pRecordingResolutionList->RemoveAll(true); delete pRecordingResolutionList; } if ( __pCameraRecorder ) { delete __pCameraRecorder; __pCameraRecorder = null; } return r; }
int main(int argc, char* argv[]){ IList *list = fastPascal(20); std::cout << list->toString() << std:: endl; delete list; // we have to do this for lack of better design return 0; }
//TODO: Is it possible to set additional information? v8::Handle<v8::Value> Contacts::add(const v8::Arguments& args) { AppLog("Entered Contacts::addContact (args length:%d)", args.Length()); // if (args.Length() < 1 || Util::isArgumentNull(args[0])) { if (args.Length() < 1) { AppLog("Bad parameters"); return v8::ThrowException(v8::String::New("Bad parameters")); } v8::HandleScope scope; String category; String name; String number; v8::Local<v8::Object> obj = args[0]->ToObject(); if(args[0]->IsObject()) { v8::Local<v8::Value> obj_category = obj->Get(v8::String::New("category")); if(obj_category->IsString()) { category = UNWRAP_STRING(obj_category).c_str(); AppLogTag("Contacts","Add Contacts: [Category:%ls]", category.GetPointer()); } v8::Local<v8::Value> obj_name = obj->Get(v8::String::New("name")); if(obj_name->IsString()) { name = UNWRAP_STRING(obj_name).c_str(); AppLogTag("Contacts","Add Contacts: [Name:%ls]", name.GetPointer()); } } if(category == null || name == null) { AppLogTag("Contacts","Failed to add Contact"); return scope.Close(v8::Boolean::New(false)); } //CREATE CONTACT Contact contact; contact.SetValue(CONTACT_PROPERTY_ID_FIRST_NAME, name); v8::Local<v8::Value> obj_number = obj->Get(v8::String::New("number")); if(!obj_number->IsNull() && obj_number->IsString()) { number = UNWRAP_STRING(obj_number).c_str(); AppLogTag("Contacts","Add Contacts: [Number:%ls]", number.GetPointer()); PhoneNumber phoneNumber; phoneNumber.SetPhoneNumber(number); contact.AddPhoneNumber(phoneNumber); } AddressbookManager* pAddressbookManager = AddressbookManager::GetInstance(); Addressbook* pAddressbook = pAddressbookManager->GetAddressbookN(DEFAULT_ADDRESSBOOK_ID); //GET CATEGORIES TO ADD A CONTACT IList* pCategoryList = pAddressbook->GetAllCategoriesN(); result r = GetLastResult(); if (IsFailed(r)) { AppLogTag("Contacts", "Failed to get categories: %s", GetErrorMessage(r)); return scope.Close(v8::Boolean::New(false)); } if (pCategoryList != null && pCategoryList->GetCount() > 0) { IEnumerator* pCategoryEnum = pCategoryList->GetEnumeratorN(); Category* pCategory = null; while (pCategoryEnum->MoveNext() == E_SUCCESS) { pCategory = static_cast<Category*>(pCategoryEnum->GetCurrent()); if (pCategory->GetName().Equals(category)) { pAddressbook->AddContact(contact); pAddressbook->AddMemberToCategory(pCategory->GetRecordId(), contact.GetRecordId()); if (IsFailed(GetLastResult())) { return scope.Close(v8::Boolean::New(false)); } else { AppLogTag("Contacts", "%d", contact.GetRecordId()); return scope.Close(v8::Boolean::New(true)); } } } } AppLogTag("Contacts","No Categories"); return scope.Close(v8::Boolean::New(false)); }
v8::Handle<v8::Value> Contacts::list(const v8::Arguments& args) { AppLogTag("Contacts", "Entered Contacts::list (args length:%d)", args.Length()); v8::HandleScope scope; AddressbookManager* pAddressbookManager = AddressbookManager::GetInstance(); IList* pCategoryList = pAddressbookManager->GetAllCategoriesN(); AppLogTag("Contacts", "TEST1"); Category* pCategory = null; Contact* pContact = null; AppLogTag("Contacts", "TEST2"); IEnumerator* pCategoryEnum = pCategoryList->GetEnumeratorN(); v8::Local<v8::Object> categoryObject = v8::Object::New(); while (pCategoryEnum->MoveNext() == E_SUCCESS) { AppLogTag("Contacts", "TEST"); pCategory = static_cast<Category*>(pCategoryEnum->GetCurrent()); char category[STRING_MAX]; IList* pContactList = pAddressbookManager->GetContactsByCategoryN(pCategory->GetRecordId()); IEnumerator* pContactEnum = pContactList->GetEnumeratorN(); v8::Local<v8::Array> personList = v8::Array::New(); AppLogTag("Contacts", "Fetching category: %ls", pCategory->GetName().GetPointer()); int person_cnt = 0; while (pContactEnum->MoveNext() == E_SUCCESS) { pContact = static_cast<Contact*>(pContactEnum->GetCurrent()); String fullName = L"", firstName, lastName; v8::Local<v8::Object> personObject = v8::Object::New(); char buf[STRING_MAX]; pContact->GetValue(CONTACT_PROPERTY_ID_FIRST_NAME, firstName); pContact->GetValue(CONTACT_PROPERTY_ID_LAST_NAME, lastName); fullName.Append(firstName); fullName.Append(L" "); fullName.Append(lastName); AppLogTag("Contacts", "Getting person: %ls", fullName.GetPointer()); IList* pPhoneNumberList = pContact->GetValuesN(CONTACT_MPROPERTY_ID_PHONE_NUMBERS); v8::Local<v8::Array> phoneList = v8::Array::New(); if (pPhoneNumberList != null) { IEnumerator* pEnum = pPhoneNumberList->GetEnumeratorN(); int number_cnt = 0; while (pEnum->MoveNext() == E_SUCCESS) { PhoneNumber* pPhoneNumber = static_cast<PhoneNumber*>(pEnum->GetCurrent()); String number = pPhoneNumber->GetPhoneNumber(); AppLogTag("Contacts", "Getting person's phonenumber: %ls", number.GetPointer()); phoneList->Set(number_cnt++, v8::String::New(Util::toAnsi(buf, number.GetPointer(), STRING_MAX))); } delete pEnum; pPhoneNumberList->RemoveAll(true); delete pPhoneNumberList; } personObject->Set(v8::String::New("name"), v8::String::New(Util::toAnsi(buf, fullName.GetPointer(), STRING_MAX))); personObject->Set(v8::String::New("phoneNumber"), phoneList); personList->Set(person_cnt++, personObject); } categoryObject->Set(v8::String::New(Util::toAnsi(category, pCategory->GetName(), STRING_MAX)), personList); delete pContactEnum; pContactList->RemoveAll(true); delete pContactList; } return scope.Close(categoryObject); }
bool drawText(const char * pszText, Dimension& dimensions, CCImage::ETextAlign alignment, const char * fontName = NULL, int fontSize = 0) { bool nRet = false; do { CC_BREAK_IF(pszText == NULL || strlen(pszText) <= 0); // text Osp::Base::String strText(pszText); // Set a font to the TextElement Font font; bool bUseDefaultFont = true; if (fontName != NULL && strlen(fontName) > 0) { String strFonName(fontName); if (strFonName.EndsWith(".ttf") || strFonName.EndsWith(".TTF")) { bUseDefaultFont = false; const char* pFullFontPath = CCFileUtils::fullPathFromRelativePath(fontName); font.Construct(pFullFontPath, FONT_STYLE_PLAIN, fontSize); } else { IList* pSystemFontList = Font::GetSystemFontListN(); if (pSystemFontList != NULL) { IEnumerator* pEnum = pSystemFontList->GetEnumeratorN(); Object* pObj = null; while (pEnum->MoveNext() == E_SUCCESS) { pObj = pEnum->GetCurrent(); String* pStrName = static_cast<String*>(pObj); if (pStrName->Equals(strFonName, false)) { bUseDefaultFont = false; font.Construct(*pStrName, FONT_STYLE_PLAIN, fontSize); break; } } delete pEnum; pSystemFontList->RemoveAll(true); delete pSystemFontList; } } } if (bUseDefaultFont) { font.Construct(FONT_STYLE_PLAIN, fontSize); } // calculate text size if (dimensions.width <= 0) { Dimension dim; font.GetTextExtent(strText, strText.GetLength(), dim); dimensions.width = dim.width; dimensions.height = dim.height; } CC_BREAK_IF(dimensions.width <= 0); // Create an EnrichedText m_pEnrichedText = new EnrichedText(); m_pEnrichedText->Construct(Dimension(dimensions.width, 10)); switch (alignment) { case CCImage::kAlignCenter: m_pEnrichedText->SetHorizontalAlignment(TEXT_ALIGNMENT_CENTER); m_pEnrichedText->SetVerticalAlignment(TEXT_ALIGNMENT_MIDDLE); break; case CCImage::kAlignTop: m_pEnrichedText->SetHorizontalAlignment(TEXT_ALIGNMENT_CENTER); m_pEnrichedText->SetVerticalAlignment(TEXT_ALIGNMENT_TOP); break; case CCImage::kAlignTopRight: m_pEnrichedText->SetHorizontalAlignment(TEXT_ALIGNMENT_RIGHT); m_pEnrichedText->SetVerticalAlignment(TEXT_ALIGNMENT_TOP); break; case CCImage::kAlignRight: m_pEnrichedText->SetHorizontalAlignment(TEXT_ALIGNMENT_RIGHT); m_pEnrichedText->SetVerticalAlignment(TEXT_ALIGNMENT_MIDDLE); break; case CCImage::kAlignBottomRight: m_pEnrichedText->SetHorizontalAlignment(TEXT_ALIGNMENT_RIGHT); m_pEnrichedText->SetVerticalAlignment(TEXT_ALIGNMENT_BOTTOM); break; case CCImage::kAlignBottom: m_pEnrichedText->SetHorizontalAlignment(TEXT_ALIGNMENT_CENTER); m_pEnrichedText->SetVerticalAlignment(TEXT_ALIGNMENT_BOTTOM); break; case CCImage::kAlignBottomLeft: m_pEnrichedText->SetHorizontalAlignment(TEXT_ALIGNMENT_LEFT); m_pEnrichedText->SetVerticalAlignment(TEXT_ALIGNMENT_BOTTOM); break; case CCImage::kAlignLeft: m_pEnrichedText->SetHorizontalAlignment(TEXT_ALIGNMENT_LEFT); m_pEnrichedText->SetVerticalAlignment(TEXT_ALIGNMENT_MIDDLE); break; case CCImage::kAlignTopLeft: m_pEnrichedText->SetHorizontalAlignment(TEXT_ALIGNMENT_LEFT); m_pEnrichedText->SetVerticalAlignment(TEXT_ALIGNMENT_TOP); break; default: m_pEnrichedText->SetHorizontalAlignment(TEXT_ALIGNMENT_CENTER); m_pEnrichedText->SetVerticalAlignment(TEXT_ALIGNMENT_MIDDLE); break; } // Set attributes of the EnrichedText m_pEnrichedText->SetTextWrapStyle(TEXT_WRAP_CHARACTER_WRAP); m_pEnrichedText->SetTextAbbreviationEnabled(true); // Create a TextElement TextElement* pTextElement = new TextElement(); pTextElement->Construct(strText); // After Adding, set attributes of the TextElement pTextElement->SetTextColor(Color::COLOR_WHITE); pTextElement->SetFont(font); // Add the TextElement to the EnrichedText m_pEnrichedText->Add(*pTextElement); m_pEnrichedText->Refresh(); dimensions.height = m_pEnrichedText->GetTotalLineHeight(); m_pEnrichedText->SetSize(dimensions.width, dimensions.height); CC_SAFE_DELETE(m_pCanvas); m_pCanvas = new Canvas(); m_pCanvas->Construct(Rectangle(0, 0, dimensions.width, dimensions.height)); m_pCanvas->DrawText(Point(0, 0), *m_pEnrichedText); m_pEnrichedText->RemoveAllTextElements(true); CC_SAFE_DELETE(m_pEnrichedText); nRet = true; } while (0); return nRet; }