void CAbstractLabel::OnTextUpdated() { if(m_Localize) m_TextCache.SetText(Localization()->Localize(m_aText)); else m_TextCache.SetText(m_aText); }
void CTextRenderer::UpdateTextCache_BiDi(array<CHarfbuzzGlyph>* pGlyphChain, const char* pText) { //Use ICU for bidirectional text //note: bidirectional texts appear for example when a latin username is displayed in a arabic text UErrorCode ICUError = U_ZERO_ERROR; UnicodeString UTF16Text = icu::UnicodeString::fromUTF8(pText); UBiDi* pICUBiDi = ubidi_openSized(UTF16Text.length(), 0, &ICUError); //Perform the BiDi algorithm //TODO: change UBIDI_DEFAULT_LTR by some variable dependend of the user config ubidi_setPara(pICUBiDi, UTF16Text.getBuffer(), UTF16Text.length(), (Localization()->GetWritingDirection() == CLocalization::DIRECTION_RTL ? UBIDI_DEFAULT_RTL : UBIDI_DEFAULT_LTR), 0, &ICUError); if(U_SUCCESS(ICUError)) { UBiDiLevel ICULevel = 1&ubidi_getParaLevel(pICUBiDi); UBiDiDirection Direction = ubidi_getDirection(pICUBiDi); if(Direction != UBIDI_MIXED) { UpdateTextCache_Font(pGlyphChain, UTF16Text.getBuffer(), 0, UTF16Text.length(), (Direction == UBIDI_RTL)); } else { int CharStart = 0; UBiDiLevel level; int NumberOfParts = ubidi_countRuns(pICUBiDi, &ICUError); if(U_SUCCESS(ICUError)) { for(int i=0; i<NumberOfParts; i++) { int Start; int SubLength; Direction = ubidi_getVisualRun(pICUBiDi, i, &Start, &SubLength); UpdateTextCache_Font(pGlyphChain, UTF16Text.getBuffer(), Start, SubLength, (Direction == UBIDI_RTL)); } } else { dbg_msg("TextRenderer", "BiDi algorithm failed (ubidi_countRuns): %s", u_errorName(ICUError)); return; } } } else { dbg_msg("TextRenderer", "BiDi algorithm failed: %s", u_errorName(ICUError)); return; } }
void Bank::loadFile(string data) { if (data == "customers") { ifstream customersFile; // (1) Read Customers File customersFile.open("customers.txt"); if (customersFile.is_open()) { string line; getline(customersFile, line); customers[0]->nextCustomerID = atol(line.c_str()); getline(customersFile, line); unsigned int totalCustomers = atoi(line.c_str()); for (int unsigned i = 0; i < totalCustomers; i++) { string typeRead, nothing; customersFile.ignore(256, ' '); getline(customersFile, typeRead); vector<string> vars; powerfullRead(11, vars, customersFile); if (typeRead == "particular") { particular *p; p = new particular(vars[1], vars[2], vars[3], vars[4], atol(vars[5].c_str()), atol(vars[6].c_str()), atol(vars[10].c_str()), vars[7], atoi(vars[8].c_str()), atoi(vars[0].c_str())); p->setAgencyNumb(atol(vars[9].c_str())); customers.push_back(p); } else { company *c; c = new company(vars[1], vars[2], vars[3], vars[4], atol(vars[5].c_str()), atol(vars[6].c_str()), atol(vars[10].c_str()), vars[7], atoi(vars[8].c_str()), atoi(vars[0].c_str())); c->setAgencyNumb(atol(vars[9].c_str())); customers.push_back(c); } getline(customersFile, nothing); } customersFile.close(); } return; } if (data == "accounts") { ifstream accountsFile; // (1) Read Accounts File accountsFile.open("accounts.txt"); if (accountsFile.is_open()) { string line; getline(accountsFile, line); accounts[0]->nextAccountID = atol(line.c_str()); getline(accountsFile, line); unsigned int totalAccounts = atoi(line.c_str()); for (int unsigned i = 0; i < totalAccounts; i++) { string typeRead, nothing, numHolders; accountsFile.ignore(256, ' '); getline(accountsFile, typeRead); vector<string> vars; vector<string> holders; vector<int> holdersVector; if (typeRead == "term") { accountsFile.ignore(256, ' '); getline(accountsFile, numHolders); powerfullRead(atoi(numHolders.c_str()), holders, accountsFile); //Read all holders for (int i = 0; i < atoi(numHolders.c_str()); i++) holdersVector.push_back(atoi(holders[i].c_str())); powerfullRead(6, vars, accountsFile); Term *t; money initialDeposit = atof(vars[1].c_str()); t = new Term(initialDeposit, holdersVector, atoi(vars[2].c_str()), vars[3], vars[4], atof(vars[5].c_str()), atoi(vars[0].c_str())); accounts.push_back(t); } else { accountsFile.ignore(256, ' '); getline(accountsFile, numHolders); powerfullRead(atoi(numHolders.c_str()), holders, accountsFile); //Read all holders for (int i = 0; i < atoi(numHolders.c_str()); i++) holdersVector.push_back(atoi(holders[i].c_str())); powerfullRead(3, vars, accountsFile); Order *o; money initialDeposit = atof(vars[1].c_str()); o = new Order(initialDeposit, holdersVector, atoi(vars[2].c_str()), atoi(vars[0].c_str())); accounts.push_back(o); } getline(accountsFile, nothing); } accountsFile.close(); } return; } if (data == "employees") { ifstream employeesFile; // (1) Read Employees File employeesFile.open("employees.txt"); if (employeesFile.is_open()) { string line; getline(employeesFile, line); employees[0]->nextEmployeeID = atol(line.c_str()); getline(employeesFile, line); unsigned int totalEmployees = atoi(line.c_str()); for (int unsigned i = 0; i < totalEmployees; i++) { string nothing; vector<string> vars; powerfullRead(11, vars, employeesFile); employee *e; e = new employee(vars[1], vars[2], vars[3], vars[4], atol(vars[5].c_str()), atol(vars[6].c_str()), atol(vars[7].c_str()), atol(vars[8].c_str()), vars[9], vars[10], atoi(vars[0].c_str())); employees.push_back(e); getline(employeesFile, nothing); } employeesFile.close(); } return; } if (data == "bank") { ifstream bankFile; bankFile.open("bank.txt"); if (bankFile.is_open()) { vector<string> vars; powerfullRead(5, vars, bankFile); setName(vars[0]); setBankNumber(atol(vars[1].c_str())); setAgencyNumber(atol(vars[2].c_str())); local = Localization(atof(vars[3].c_str()), atof(vars[4].c_str())); ATM::setTarget(local); account::setBank(bankNumber); account::setAgency(agencyNumber); bankFile.close(); } else { clearscreen(); stringstream text; text.str(""); text << "* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n"; text << "Create Bank" << endl; text << "* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n\n"; string tempString, location, postalCode, Address; long tempLong, contact; double lat, lon; do{ clearscreen(); cout<<text.str(); cout << "Bank name: "; getline(cin, tempString); }while(tempString.size()<=0); setName(tempString); clearscreen(); cout<<text.str(); cout << "Bank number: "; cin >> tempLong; setBankNumber(tempLong); clearscreen(); cout<<text.str(); cout << "Latitude: "; cin >> lat; clearscreen(); cout<<text.str(); cout << "Longitude: "; cin >> lon; do{ clearscreen(); cout<<text.str(); cout << "Location: "; getline(cin, location); }while(location.size()<=0); do{ clearscreen(); cout<<text.str(); cout << "Address: "; getline(cin, Address); }while(Address.size()<=0); clearscreen(); cout<<text.str(); cout << "PostalCode: "; cin >> postalCode; clearscreen(); cout<<text.str(); cout << "Contact: "; cin >> contact; this->headquarters.setAddress(Address); this->headquarters.setContact(contact); this->headquarters.setLocation(location); this->headquarters.setNumber(1); this->headquarters.setPostalCode(postalCode); this->headquarters.setNumClients(0); this->addAgency(this->headquarters); local = Localization(lat, lon); ATM::setTarget(local); account::setAgency(agencyNumber); account::setBank(bankNumber); saveFile("bank"); } return; }
gui::CWidget* CSettings::CreateGeneralTab() { gui::CHListLayout* pTab = new gui::CHListLayout(Context()); pTab->SetBoxStyle(CAssetPath::GuiBoxStyleSystem(GUIBOXSTYLE_MENU_COLUMNS)); gui::CVScrollLayout* pLeftList = new gui::CVScrollLayout(Context()); pLeftList->SetBoxStyle(CAssetPath::GuiBoxStyleSystem(GUIBOXSTYLE_MENU_SECTIONLIST)); pTab->Add(pLeftList, true); gui::CVScrollLayout* pRightList = new gui::CVScrollLayout(Context()); pRightList->SetBoxStyle(CAssetPath::GuiBoxStyleSystem(GUIBOXSTYLE_MENU_SECTIONLIST)); pTab->Add(pRightList, true); { gui::CVListLayout* pSection = new gui::CVListLayout(Context()); pLeftList->Add(pSection, false); pSection->SetBoxStyle(CAssetPath::GuiBoxStyleSystem(GUIBOXSTYLE_MENU_SECTION)); pSection->Add(new gui::CLabelHeader(Context(), _("Game")), false); pSection->Add(new CConfigDynamicCamera(Context(), _("Dynamic Camera")), false); pSection->Add(new CConfigCheckBox(Context(), &g_Config.m_ClAutoswitchWeapons, _("Switch weapon on pickup")), false); pSection->Add(new CConfigCheckBox(Context(), &g_Config.m_ClShowhud, _("Show ingame HUD")), false); pSection->Add(new CConfigCheckBox(Context(), &g_Config.m_ClShowChatFriends, _("Show only chat messages from friends")), false); pSection->Add(new CConfigCheckBox(Context(), &g_Config.m_ClShowsocial, _("Show social")), false); { CConfigCheckBox* pTitle = new CConfigCheckBox(Context(), &g_Config.m_ClNameplates, _("Show name plates")); CConfigExpand* pExpand = new CConfigExpand(Context(), pTitle); pExpand->Add(new CConfigCheckBox(Context(), &g_Config.m_ClNameplatesAlways, _("Always show name plates"))); gui::CHListLayout* pList = new gui::CHListLayout(Context()); pList->SetBoxStyle(CAssetPath::GuiBoxStyleSystem(GUIBOXSTYLE_MENU_ITEM)); pList->Add(new gui::CLabel(Context(), _("Size"), CAssetPath::SpriteSystem(SPRITE_MENU_VOID)), false, 200); pList->Add(new CConfigSlider(Context(), &g_Config.m_ClNameplatesSize, 0, 100), true); pExpand->Add(pList); pExpand->Add(new CConfigCheckBox(Context(), &g_Config.m_ClNameplatesTeamcolors, _("Use team colors for name plates"))); pSection->Add(pExpand, false); } } { gui::CVListLayout* pSection = new gui::CVListLayout(Context()); pLeftList->Add(pSection, false); pSection->SetBoxStyle(CAssetPath::GuiBoxStyleSystem(GUIBOXSTYLE_MENU_SECTION)); pSection->Add(new gui::CLabelHeader(Context(), _("Client")), false); { CConfigCheckBox* pTitle = new CConfigCheckBox(Context(), &g_Config.m_ClAutoDemoRecord, _("Automatically record demos")); CConfigExpand* pExpand = new CConfigExpand(Context(), pTitle); pSection->Add(pExpand, false); gui::CHListLayout* pList = new gui::CHListLayout(Context()); pList->SetBoxStyle(CAssetPath::GuiBoxStyleSystem(GUIBOXSTYLE_MENU_ITEM)); pList->Add(new gui::CLabel(Context(), _("Max"), CAssetPath::SpriteSystem(SPRITE_MENU_VOID)), false, 200); pList->Add(new CConfigSlider(Context(), &g_Config.m_ClAutoDemoMax, 0, 100), true); pExpand->Add(pList); } { CConfigCheckBox* pTitle = new CConfigCheckBox(Context(), &g_Config.m_ClAutoScreenshot, _("Automatically take game over screenshot")); CConfigExpand* pExpand = new CConfigExpand(Context(), pTitle); pSection->Add(pExpand, false); gui::CHListLayout* pList = new gui::CHListLayout(Context()); pList->SetBoxStyle(CAssetPath::GuiBoxStyleSystem(GUIBOXSTYLE_MENU_ITEM)); pList->Add(new gui::CLabel(Context(), _("Max"), CAssetPath::SpriteSystem(SPRITE_MENU_VOID)), false, 200); pList->Add(new CConfigSlider(Context(), &g_Config.m_ClAutoScreenshotMax, 0, 100), true); pExpand->Add(pList); } } { gui::CVListLayout* pSection = new gui::CVListLayout(Context()); pRightList->Add(pSection, true); pSection->SetBoxStyle(CAssetPath::GuiBoxStyleSystem(GUIBOXSTYLE_MENU_SECTION)); pSection->Add(new gui::CLabelHeader(Context(), _("Language")), false); gui::CVScrollLayout* pLanguageList = new gui::CVScrollLayout(Context()); pLanguageList->SetBoxStyle(CAssetPath::GuiBoxStyleSystem(GUIBOXSTYLE_MENU_LIST)); pSection->Add(pLanguageList, true); pLanguageList->Add(new CLanguageButton(Context(), "English", ""), false); for(int i=0; i<Localization()->m_pLanguages.size(); i++) { pLanguageList->Add(new CLanguageButton(Context(), Localization()->m_pLanguages[i]->GetName(), Localization()->m_pLanguages[i]->GetFilename()), false); } } return pTab; }
void CAbstractLabel::Render() { CRect Rect = m_DrawRect; CRect ClipRect = m_DrawRect; vec4 FontColor = 1.0f; int Alignment = CAsset_GuiLabelStyle::TEXTALIGNMENT_LEFT; int Spacing = 0; const CAsset_GuiLabelStyle* pLabelStyle = AssetsManager()->GetAsset<CAsset_GuiLabelStyle>(m_LabelStylePath); if(pLabelStyle) { FontColor = pLabelStyle->m_TextColor; Alignment = pLabelStyle->m_TextAlignment; Rect.RemoveMargin(Context()->ApplyGuiScale(pLabelStyle->GetMargin())); ClipRect.RemoveMargin(Context()->ApplyGuiScale(pLabelStyle->GetMargin())); AssetsRenderer()->DrawGuiRect(&Rect, pLabelStyle->GetRectPath()); Rect.RemoveMargin(Context()->ApplyGuiScale(pLabelStyle->GetPadding())); } int IconWidth = 0; int TextWidth = 0; const CAsset_Sprite* pSprite = AssetsManager()->GetAsset<CAsset_Sprite>(m_IconPath); if(pSprite) { IconWidth = Context()->ApplyGuiScale(Context()->GetImageScale()*pSprite->GetPixelWidth()); } m_TextCache.SetBoxSize(ivec2(-1, Rect.h)); if(GetText()[0]) { if(pSprite && pLabelStyle) Spacing = Context()->ApplyGuiScale(pLabelStyle->GetSpacing()); TextWidth = TextRenderer()->GetTextWidth(&m_TextCache); } int TotalWidth = IconWidth + Spacing + TextWidth; int PosX = 0; if(Localization()->GetWritingDirection() == CLocalization::DIRECTION_RTL) { if(Alignment == CAsset_GuiLabelStyle::TEXTALIGNMENT_LEFT) Alignment = CAsset_GuiLabelStyle::TEXTALIGNMENT_RIGHT; else if(Alignment == CAsset_GuiLabelStyle::TEXTALIGNMENT_RIGHT) Alignment = CAsset_GuiLabelStyle::TEXTALIGNMENT_LEFT; } if(Alignment == CAsset_GuiLabelStyle::TEXTALIGNMENT_LEFT) PosX = Rect.x; else if(Alignment == CAsset_GuiLabelStyle::TEXTALIGNMENT_RIGHT) PosX = Rect.x + Rect.w - TotalWidth; else PosX = Rect.x + Rect.w/2 - TotalWidth/2; Graphics()->ClipPush(ClipRect.x, ClipRect.y, ClipRect.w, ClipRect.h); if(Localization()->GetWritingDirection() == CLocalization::DIRECTION_RTL) { if(GetText()[0]) { m_TextRect.x = PosX; m_TextRect.y = Rect.y; m_TextRect.w = TextRenderer()->GetTextWidth(&m_TextCache); m_TextRect.h = Rect.h; m_TextCache.SetBoxSize(ivec2(-1, m_TextRect.h)); TextRenderer()->DrawText(&m_TextCache, ivec2(m_TextRect.x, m_TextRect.y), FontColor); PosX += TextWidth; } PosX += Spacing; if(IconWidth > 0) { AssetsRenderer()->DrawSprite( m_IconPath, vec2(PosX + IconWidth/2, Rect.y + Rect.h/2), Context()->GetImageScale()*Context()->GetGuiScale(), 0.0f, 0x0, 1.0f ); } } else { if(IconWidth > 0) { AssetsRenderer()->DrawSprite( m_IconPath, vec2(PosX + IconWidth/2, Rect.y + Rect.h/2), Context()->GetImageScale()*Context()->GetGuiScale(), 0.0f, 0x0, 1.0f ); PosX += IconWidth; } PosX += Spacing; if(GetText()[0]) { m_TextRect.x = PosX; m_TextRect.y = Rect.y; m_TextRect.w = TextRenderer()->GetTextWidth(&m_TextCache); m_TextRect.h = Rect.h; m_TextCache.SetBoxSize(ivec2(-1, m_TextRect.h)); TextRenderer()->DrawText(&m_TextCache, ivec2(m_TextRect.x, m_TextRect.y), FontColor); } } Graphics()->ClipPop(); }
void CAbstractLabel::Update() { if(m_Localize && Context()->LocalizationUpdated()) m_TextCache.SetText(Localization()->Localize(m_aText)); }