void Label::setTextHeightSize(unsigned int size) { unsigned int i; for(i=1; m_text.getGlobalBounds().height < size || i==1; i++) setCharacterSize(i); setCharacterSize(i-1); }
void Label::setTextWidthSize(unsigned int size) { guiml::Label copy(NULL, m_text.getString(), *(m_text.getFont())); copy.setCharacterSize(getText().getCharacterSize()); if(getString().getSize() != 0) setCharacterSize(m_text.getCharacterSize() * size / copy.getVirtualSize().x); }
TextShape::TextShape(std::string command, std::string name) { // check for changed values createParameter("pos", new Vec3Type()); createParameter("color", new Vec4Type()); createParameter("bcolor", new Vec4Type()); createParameter("enableOutline", new BoolType()); createParameter("size", new FloatType()); createParameter("label", new StringType()); createParameter("font", new StringType()); _type = SimpleShape::TEXT; BasicShape::setName(name); // default color is white for font setColor(osg::Vec4(1.0, 1.0, 1.0, 1.0)); // set a default background color setBackdropColor(osg::Vec4(0.0, 0.0, 0.0, 1.0)); setCharacterSize(10.0f); setFontResolution(40,40); osgText::Font* font = NULL; // check if fontMap has been constucted if ( _fontMap == NULL ) _fontMap = new ThreadMap< std::string, osgText::Font* >(); // check if font exists in map else load it and add it if( ! _fontMap->get(std::string("/usr/share/fonts/liberation/LiberationSans-Regular.ttf"), font) ) { font = osgText::readFontFile("/usr/share/fonts/liberation/LiberationSans-Regular.ttf"); _fontMap->add(std::string("/usr/share/fonts/liberation/LiberationSans-Regular.ttf"), font); } setFont(font); if( Globals::G_ROTAXIS ) setAxisAlignment(osgText::TextBase::XY_PLANE); else setAxisAlignment(osgText::TextBase::XZ_PLANE); // off by default setBackdropType(osgText::Text::NONE); osg::StateSet* state = osgText::Text::getOrCreateStateSet(); state->setMode(GL_BLEND, osg::StateAttribute::ON); state->setMode(GL_LIGHTING, osg::StateAttribute::OFF); //osg::Material* mat = new osg::Material(); //mat->setColorMode(osg::Material::AMBIENT_AND_DIFFUSE); //state->setAttributeAndModes(mat, osg::StateAttribute::ON); setUpdateCallback(new TextUpdateCallback()); update(command); }
void TextShape::update() { OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_mutex); if( !_dirty ) return; osg::Vec3 p = getPosition(); osg::Vec4 c = getColor(); osg::Vec4 bc = getBackdropColor(); float size = getCharacterHeight(); std::string text = getText().createUTF8EncodedString(); p = getParameter("pos")->asVec3Type()->getValue(); c = getParameter("color")->asVec4Type()->getValue(); bc = getParameter("bcolor")->asVec4Type()->getValue(); size = getParameter("size")->asFloatType()->getValue(); text = getParameter("label")->asStringType()->getValue(); bool enableOutline = getParameter("enableOutline")->asBoolType()->getValue(); // TODO background color // TODO not sure if want to make it so the font gets added all the time hmmm //setFont(font); // check if outline should be enabled if( enableOutline ) { setBackdropType(osgText::Text::OUTLINE); setColor(c); setBackdropColor(bc); } else { setBackdropType(osgText::Text::NONE); setColor(c); } setText(text); setCharacterSize(size); setPosition(p); dirtyBound(); //if(c[3] != 1.0) getOrCreateStateSet()->setRenderingHint(osg::StateSet::TRANSPARENT_BIN); //else // getOrCreateStateSet()->setRenderingHint(osg::StateSet::DEFAULT_BIN); // reset flag _dirty = false; }
void UIShipData::update(HumanGameView* hgv) { // Adjust for prettiness setCharacterSize(static_cast<double>(hgv->getMapTileSize()) * 0.75); // Grab convenience pointer to ship const Ship* ship = hgv->getGameLogic()->getShip(); setRum(ship->getRum()); setGold(ship->getGold()); setSupply(ship->getMaxRum()); updateText(); }
fm::Result FontRenderer::loadFromFile(const std::string &fileName,unsigned int size) { clean(); m_ownData = true; std::ifstream in(fileName.c_str(), std::fstream::in | std::fstream::binary); if (!in) { clean(); return fm::Result("IOError",fm::Result::OPFailed,"FileNotFound","loadFromFile",__FILE__,__LINE__,fileName); } in.seekg(0, std::ios::end); m_fileSize = in.tellg(); if (in.fail()) { clean(); return fm::Result("IOError",fm::Result::OPFailed,"FileNotReadable","loadFromFile",__FILE__,__LINE__,fileName); } m_fileContent = new fm::Uint8[m_fileSize]; in.seekg(0, std::ios::beg); in.read((char*)m_fileContent, m_fileSize); if (in.fail()) { clean(); return fm::Result("IOError",fm::Result::OPFailed,"FileNotReadable","loadFromFile",__FILE__,__LINE__,fileName); } in.close(); if (!stbtt_InitFont((stbtt_fontinfo*)m_stbFontInfo, m_fileContent, stbtt_GetFontOffsetForIndex(m_fileContent,0))) { clean(); return fm::Result("TTFError",fm::Result::OPFailed,"InvalidFont","loadFromFile",__FILE__,__LINE__,fileName); } setCharacterSize(size); return fm::Result(); }
FeTextPrimative::FeTextPrimative( const sf::Font *font, const sf::Color &colour, const sf::Color &bgcolour, unsigned int charactersize, Alignment align ) : m_texts( 1, sf::Text() ), m_align( align ), m_first_line( -1 ), m_needs_pos_set( false ) { if ( font ) setFont( *font ); setColor( colour ); setBgColor( bgcolour ); setCharacterSize( charactersize ); }
fm::Result FontRenderer::loadFromMemory(const fm::Uint8 *fileContent,fm::Size fileSizeInBytes,unsigned int size) { clean(); m_ownData = false; m_fileSize = fileSizeInBytes; m_fileContent = fileContent; if (!stbtt_InitFont((stbtt_fontinfo*)m_stbFontInfo, m_fileContent, stbtt_GetFontOffsetForIndex(m_fileContent,0))) { clean(); return fm::Result("FTError",fm::Result::OPFailed,"InvalidFont","loadFromMemory",__FILE__,__LINE__); } setCharacterSize(size); return fm::Result(); }
fm::Result FontRenderer::copyFromMemory(const fm::Uint8 *fileContent,fm::Size fileSizeInBytes,unsigned int size) { clean(); m_ownData = true; m_fileSize = fileSizeInBytes; fm::Uint8 *buf = new fm::Uint8[fileSizeInBytes]; std::memcpy(buf,fileContent,fileSizeInBytes); m_fileContent = buf; if (!stbtt_InitFont((stbtt_fontinfo*)m_stbFontInfo, m_fileContent, stbtt_GetFontOffsetForIndex(m_fileContent,0))) { clean(); return fm::Result("FTError",fm::Result::OPFailed,"InvalidFont","copyFromMemory",__FILE__,__LINE__); } setCharacterSize(size); return fm::Result(); }
TextShape::TextShape(std::string command, std::string name) { _type = SimpleShape::TEXT; BasicShape::setName(name); setColor(osg::Vec4(1.0, 1.0, 1.0, 1.0)); setCharacterSize(10.0f); setFontResolution(40,40); setFont ("/usr/share/fonts/liberation/LiberationSans-Regular.ttf"); setAxisAlignment(osgText::TextBase::XZ_PLANE); setBackdropType(osgText::Text::NONE); osg::StateSet* state = osgText::Text::getOrCreateStateSet(); state->setMode(GL_BLEND, osg::StateAttribute::ON); state->setMode(GL_LIGHTING, osg::StateAttribute::OFF); //osg::Material* mat = new osg::Material(); //mat->setColorMode(osg::Material::AMBIENT_AND_DIFFUSE); //state->setAttributeAndModes(mat, osg::StateAttribute::ON); setUpdateCallback(new TextUpdateCallback()); update(command); }
void TextShape::update() { OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_mutex); if( !_dirty ) return; osg::Vec3 p = getPosition(); osg::Vec4 c = getColor(); float size = getCharacterHeight(); std::string text = getText().createUTF8EncodedString(); setParameter("x", p.x()); setParameter("y", p.y()); setParameter("z", p.z()); setParameter("r", c.r()); setParameter("g", c.g()); setParameter("b", c.b()); setParameter("a", c.a()); setParameter("size", size); setParameter("label", text); setText(text); setCharacterSize(size); setPosition(p); setColor(c); dirtyBound(); if(c[3] != 1.0) getOrCreateStateSet()->setRenderingHint(osg::StateSet::TRANSPARENT_BIN); else getOrCreateStateSet()->setRenderingHint(osg::StateSet::DEFAULT_BIN); // reset flag _dirty = false; }
Label::Label(Updatable *parent, const sf::Text &text, const sf::Vector2f &position, int characterSize) : Widget(parent, sf::FloatRect(position.x, position.y, characterSize * text.getString().getSize(), characterSize)), m_text(text) { m_focus=false; setCharacterSize(characterSize); }
Label::Label(Updatable *parent, const std::string &string, const sf::Font &font, const sf::Vector2f &position, int characterSize) : Widget(parent, sf::FloatRect(position.x, position.y, characterSize * string.size(), characterSize)), m_text(sf::String(string), font) { m_focus=false; setPosition(position); setCharacterSize(characterSize); }
/*inline*/ void GText::title() { setColor(sf::Color::Blue); setCharacterSize(32); }
/*inline*/ void GText::_default() { setColor(sf::Color::White); setCharacterSize(24); setStyle(sf::Text::Regular); }
Label::Label() : sf::Text() { setCharacterSize(TAILLE_TEXTE); }
Label::Label(std::string texte, float x, float y) : sf::Text() { setString(texte); setPosition(x, y); setCharacterSize(TAILLE_TEXTE); }
void HelpState::addPlankton(PlanktonController::Type type) { auto entity = std::make_unique<Entity>(m_messageBus); entity->setWorldPosition({ static_cast<float>(Util::Random::value(0, 1920)), static_cast<float>(Util::Random::value(0, 1080)) }); auto physComponent = m_physWorld.addBody(planktonSize); physComponent->setPosition(entity->getWorldPosition()); physComponent->setTriggerOnly(true); physComponent->setName("control"); entity->addComponent<PhysicsComponent>(physComponent); auto& appInstance = getContext().appInstance; bool colourblind = appInstance.getGameSettings().colourblindMode; AnimatedDrawable::Ptr ad; auto ident = ParticleSystem::create(Particle::Type::Ident, m_messageBus); ident->setTexture(appInstance.getTexture("assets/images/particles/ident.png")); auto text = std::make_unique<TextDrawable>(m_messageBus); text->setFont(appInstance.getFont("assets/fonts/Ardeco.ttf")); switch (type) { case PlanktonController::Type::Good: ad = std::make_unique<AnimatedDrawable>(m_messageBus, appInstance.getTexture("assets/images/player/food01.png")); ad->loadAnimationData("assets/images/player/food01.cra"); (colourblind) ? ident->setColour({ 14u, 160u, 225u }) : ident->setColour({ 84u, 150u, 75u }); text->setString("+50 HP"); break; case PlanktonController::Type::Bad: ad = std::make_unique<AnimatedDrawable>(m_messageBus, appInstance.getTexture("assets/images/player/food02.png")); ad->loadAnimationData("assets/images/player/food02.cra"); (colourblind) ? ident->setColour({ 214u, 190u, 25u }) : ident->setColour({ 184u, 67u, 51u }); text->setString("-35 HP"); break; case PlanktonController::Type::Bonus: ad = std::make_unique<AnimatedDrawable>(m_messageBus, appInstance.getTexture("assets/images/player/food03.png")); ad->loadAnimationData("assets/images/player/food03.cra"); ident->setColour({ 158u, 148u, 224u }); text->setString("+100 HP"); break; case PlanktonController::Type::UberLife: ad = std::make_unique<AnimatedDrawable>(m_messageBus, appInstance.getTexture("assets/images/player/bonus.png")); ad->loadAnimationData("assets/images/player/bonus.cra"); ident->setColour({ 158u, 148u, 224u }); text->setString("FULL HEALTH"); break; default: break; } ident->setName("ident"); entity->addComponent<ParticleSystem>(ident); text->setCharacterSize(40u); Util::Position::centreOrigin(*text); text->setPosition(0.f, 40.f); text->setName("text"); entity->addComponent<TextDrawable>(text); ad->setBlendMode(sf::BlendAdd); ad->setOrigin(sf::Vector2f(ad->getFrameSize()) / 2.f); if (!ad->getAnimations().empty()) ad->play(ad->getAnimations()[0]); ad->setName("drawable"); entity->addComponent<AnimatedDrawable>(ad); auto trail = ParticleSystem::create(Particle::Type::Trail, m_messageBus); trail->setTexture(appInstance.getTexture("assets/images/particles/circle.png")); float particleSize = planktonSize / 12.f; trail->setParticleSize({ particleSize, particleSize }); trail->setName("trail"); trail->setEmitRate(10.f); entity->addComponent<ParticleSystem>(trail); if (type == PlanktonController::Type::UberLife) { auto tails = std::make_unique<TailDrawable>(m_messageBus); tails->addTail(sf::Vector2f(-18.f, -15.f)); tails->addTail(sf::Vector2f(-8.f, -5.f)); tails->addTail(sf::Vector2f(-8.f, 5.f)); tails->addTail(sf::Vector2f(-18.f, 15.f)); tails->setName("tail"); entity->addComponent<TailDrawable>(tails); } auto controller = std::make_unique<PlanktonController>(m_messageBus); controller->setType(type); controller->setDecayRate(0.f); controller->setColourblind(colourblind); entity->addComponent<PlanktonController>(controller); m_rootNode.addChild(entity); }
// inline void GText::untitle() { // setColor(sf::Color::White); // setCharacterSize(24); // } /*inline*/ void GText::subtitle() { setColor(sf::Color::Green); setCharacterSize(32); }
void sfText_setCharacterSize(sfText* text, unsigned int size) { CSFML_CALL(text, setCharacterSize(size)); }
//private void MenuWeaponState::buildMenu(const sf::Font& font) { const float centreX = xy::DefaultSceneSize.x / 2.f; auto label = xy::UI::create<xy::UI::Label>(font); label->setString("Select Secondary Weapon"); label->setAlignment(xy::UI::Alignment::Centre); label->setPosition(centreX, 86.f); label->setCharacterSize(40u); m_uiContainer.addControl(label); label = xy::UI::create<xy::UI::Label>(font); label->setString("Rank " + std::to_string(m_profile.getRank()) + ": " +std::to_string(m_profile.getXP()) + "XP"); label->setAlignment(xy::UI::Alignment::Centre); label->setPosition(centreX, 160.f); m_uiContainer.addControl(label); //weapon selector auto weaponSelect = xy::UI::create<lm::ui::WeaponSelect>(m_textureResource.get("assets/images/ui/weapon_select.png")); weaponSelect->setAlignment(xy::UI::Alignment::Centre); weaponSelect->setPosition(centreX, 420.f); sf::Int32 count = AchievementID::Rank50 - AchievementID::Rank10; sf::Uint8 flags = 0xff; for (auto i = 0; i < count; ++i) { if (m_profile.hasAchievement(static_cast<AchievementID>(AchievementID::Rank10 + i))) { flags &= ~(1 << i); } } weaponSelect->setLockedFlags(flags); m_uiContainer.addControl(weaponSelect); auto button = xy::UI::create<xy::UI::Button>(font, m_textureResource.get("assets/images/ui/start_button.png")); button->setString("Back"); button->setAlignment(xy::UI::Alignment::Centre); button->setPosition(600.f, 975.f); button->addCallback([this]() { auto msg = m_messageBus.post<xy::Message::UIEvent>(xy::Message::UIMessage); msg->type = xy::Message::UIEvent::MenuClosed; msg->value = 0.f; msg->stateID = States::ID::MenuWeapon; requestStackPop(); requestStackPush(States::ID::MenuMain); }); m_uiContainer.addControl(button); button = xy::UI::create<xy::UI::Button>(font, m_textureResource.get("assets/images/ui/start_button.png")); button->setString("Begin!"); button->setAlignment(xy::UI::Alignment::Centre); button->setPosition(1320.f, 975.f); button->addCallback([this, weaponSelect, flags]() { //set the currently selected weapon lm::SpecialWeapon weapon = lm::SpecialWeapon::None; auto idx = weaponSelect->getSelectedIndex(); if ((flags & (1 << idx)) == 0) { weapon = static_cast<lm::SpecialWeapon>(idx + 1); } m_profile.setSpecialWeapon(weapon); //and raise message to say we're done auto msg = m_messageBus.post<xy::Message::UIEvent>(xy::Message::UIMessage); msg->type = xy::Message::UIEvent::MenuClosed; msg->value = 0.f; msg->stateID = States::ID::MenuWeapon; requestStackClear(); requestStackPush(States::ID::SinglePlayer); }); m_uiContainer.addControl(button); }
void Demo1Scene::onInitialize(caDraw::Window& owner) { auto winSize = owner.getSize(); auto smallFont = m_pool.createFont(L"SmallFont"); smallFont->loadFromFile("NanumGothic.ttf"); smallFont->setCharacterSize(18); smallFont->setStyle(caDraw::FontStyles::Bold); m_panel = caFactory->createPanel(); m_panel->transform.position = { 0, 0 }; m_panel->size = static_cast<caDraw::SizeF>(winSize); m_font = caFactory->createFont(); m_font->loadFromFile("NanumGothic.ttf"); m_font->setCharacterSize(64); m_font->setStyle(caDraw::FontStyles::Bold); m_rect1 = canew<caDraw::DrawableRectangle>(32, 64, 256, 128); m_rect1->edgeColor = caDraw::Color::Magenta; m_rect1->fillColor = caDraw::Color::Yellow; m_rect1->edgeWidth = 8.0f; m_ellipse1 = canew<caDraw::DrawableEllipse>(-32, -64, 256, 128); m_ellipse1->transform.position = { 64, 128 }; m_ellipse1->edgeColor = caDraw::Color::Yellow; m_ellipse1->fillColor = caDraw::Color::Magenta; m_ellipse1->edgeWidth = 2.0f; m_line1 = canew<caDraw::DrawableLine>(m_rect1->x, m_rect1->y, m_rect1->x + m_rect1->width, m_rect1->y + m_rect1->height); m_line1->color = caDraw::Color::Cyan; m_line1->thickness = 8.0f; m_desc = canew<caUI::Label>(); m_desc->setFont(m_font); m_desc->setText(L"Press W, S, A, D Key"); m_desc->setPosition({ 340, 32 }); m_desc->setSize({ 300, 48 }); m_desc->setBackColor(caDraw::Color::Transparent); m_progress = canew<caUI::ProgressBar>(); m_progress->setFont(smallFont); m_progress->setPosition({ 0, static_cast<f32>(winSize.height) - 32 }); m_progress->setSize({ static_cast<f32>(winSize.width), 32 }); m_progress->setBackColor(caDraw::Color::Gray); m_progress->setMinValue(0); m_progress->setMaxValue(100); m_progress->setValue(0); m_progress->setText("Move!"); m_progress->WhenMaxValue = [button = &m_buttonNext](const caUI::ValueFEventArgs& args) { (*button)->setVisible(true); }; m_progress->WhenMinValue = [button = &m_buttonNext](const caUI::ValueFEventArgs& args) { (*button)->setVisible(false); }; m_buttonNext = canew<caUI::Button>(); m_buttonNext->setFont(m_font); m_buttonNext->setText(L"Next page"); m_buttonNext->setBackColor(caDraw::Color::Gray); m_buttonNext->setPosition({ static_cast<f32>(winSize.width / 2 - 165), 600 }); m_buttonNext->setSize({ 330, 100 }); m_buttonNext->setVisible(false); m_buttonNext->WhenClick = [me = this, pool = m_pool](const caUI::EventArgs& args) { me->reserveNextScene<Demo2Scene>(pool); }; m_panel->addDrawable(m_rect1); m_panel->addDrawable(m_ellipse1); m_panel->addDrawable(m_line1); m_panel->addControl(m_desc); m_panel->addControl(m_progress); m_panel->addControl(m_buttonNext); addPanel(m_panel); }