Esempio n. 1
0
void Navigation::CreateUI()
{
    ResourceCache* cache = GetSubsystem<ResourceCache>();
    UI* ui = GetSubsystem<UI>();
    
    // Create a Cursor UI element because we want to be able to hide and show it at will. When hidden, the mouse cursor will
    // control the camera, and when visible, it will point the raycast target
    XMLFile* style = cache->GetResource<XMLFile>("UI/DefaultStyle.xml");
    SharedPtr<Cursor> cursor(new Cursor(context_));
    cursor->SetStyleAuto(style);
    ui->SetCursor(cursor);

    // Set starting position of the cursor at the rendering window center
    Graphics* graphics = GetSubsystem<Graphics>();
    cursor->SetPosition(graphics->GetWidth() / 2, graphics->GetHeight() / 2);
    
    // Construct new Text object, set string to display and font to use
    Text* instructionText = ui->GetRoot()->CreateChild<Text>();
    instructionText->SetText(
        "Use WASD keys to move, RMB to rotate view\n"
        "Shift+LMB to set path start, LMB to set path end\n"
        "MMB to add or remove obstacles\n"
        "Space to toggle debug geometry"
    );
    instructionText->SetFont(cache->GetResource<Font>("Fonts/Anonymous Pro.ttf"), 15);
    // The text has multiple rows. Center them in relation to each other
    instructionText->SetTextAlignment(HA_CENTER);
    
    // Position the text relative to the screen center
    instructionText->SetHorizontalAlignment(HA_CENTER);
    instructionText->SetVerticalAlignment(VA_CENTER);
    instructionText->SetPosition(0, ui->GetRoot()->GetHeight() / 4);
}
void Urho3DTemplate::CreateUI()
{
    ResourceCache* cache = GetSubsystem<ResourceCache>();
    UI* ui = GetSubsystem<UI>();

    //Create a Cursor UI element because we want to be able to hide and show it at will. When hidden, the mouse cursor will control the camera, and when visible it will point the raycast target
    XMLFile* style = cache->GetResource<XMLFile>("UI/Defaultstyle.xml");
    SharedPtr<Cursor> cursor(new Cursor(context_));
    cursor->SetStyleAuto(style);
    ui->SetCursor(cursor);

    //Set starting position of the cursor at the rendering window center
    Graphics* graphics = GetSubsystem<Graphics>();
    cursor->SetPosition(graphics->GetWidth()/2, graphics->GetHeight()/2);

    //Construct new Text object, set string to display and font to use
    Text* instructionText = ui->GetRoot()->CreateChild<Text>();
    instructionText->SetText(
                "Lorum ipsum, dolor set amet"
                );
    instructionText->SetFont(cache->GetResource<Font>("Fonts/Anonymous Pro.ttf"), 15);
    //The text has multiple rows. Center them in relation to each other
    instructionText->SetHorizontalAlignment(HA_CENTER);
    instructionText->SetVerticalAlignment(VA_CENTER);
    instructionText->SetPosition(0, ui->GetRoot()->GetHeight()/4);
}
Esempio n. 3
0
GetFileNameDlg::GetFileNameDlg(Window *parent, const Params &param)
    : Dialog(parent, 512, 460)
    , _changing(false)
{
    Text *t = Text::Create(this, GetWidth() / 2, 16, param.title, alignTextCT);
    t->SetFont("font_default");

    _folder = param.folder;
    _ext = param.extension;
    _files = DefaultListBox::Create(this);
    _files->Move(20, 56);
    _files->Resize(472, 300);
    std::set<string_t> files;
    _folder->EnumAllFiles(files, "*." + _ext);
    for( std::set<string_t>::iterator it = files.begin(); it != files.end(); ++it )
    {
        string_t tmp = *it;
        tmp.erase(it->length() - _ext.length() - 1); // cut out the file extension
        int index = _files->GetData()->AddItem(tmp);
    }
    _files->GetData()->Sort();
    _files->eventChangeCurSel.bind(&GetFileNameDlg::OnSelect, this);

    Text::Create(this, 16, 370, g_lang.get_file_name_title.Get(), alignTextLT);
    _fileName = Edit::Create(this, 20, 385, 472);
    _fileName->eventChange.bind(&GetFileNameDlg::OnChangeName, this);

    Button::Create(this, g_lang.common_ok.Get(), 290, 420)->eventClick = std::bind(&GetFileNameDlg::OnOK, this);
    Button::Create(this, g_lang.common_cancel.Get(), 400, 420)->eventClick = std::bind(&GetFileNameDlg::OnCancel, this);

    GetManager()->SetFocusWnd(_fileName);
}
Esempio n. 4
0
void VehicleDemo::CreateInstructions()
{
    ResourceCache* cache = GetSubsystem<ResourceCache>();
    UI* ui = GetSubsystem<UI>();
    
    // Construct new Text object, set string to display and font to use
    Text* instructionText = ui->GetRoot()->CreateChild<Text>();
    instructionText->SetText(
                             "Use WASD keys to drive, mouse/touch to rotate camera\n"
                             "F5 to save scene, F7 to load"
                             );
    instructionText->SetFont(cache->GetResource<Font>("Fonts/Anonymous Pro.ttf"), 15);
    // The text has multiple rows. Center them in relation to each other
    instructionText->SetTextAlignment(HA_CENTER);
    
    // Position the text relative to the screen center
    instructionText->SetHorizontalAlignment(HA_CENTER);
    instructionText->SetVerticalAlignment(VA_CENTER);
    instructionText->SetPosition(0, ui->GetRoot()->GetHeight() / 4);
    
    
    
    // insert speed
    Text* speedText = ui->GetRoot()->CreateChild<Text>("UITextSpeed");
    speedText->SetText("x km/h");
    speedText->SetFont(cache->GetResource<Font>("Fonts/Anonymous Pro.ttf"), 15);
    // The text has multiple rows. Center them in relation to each other
    speedText->SetTextAlignment(HA_CENTER);
    // Position the text relative to the screen center
    speedText->SetHorizontalAlignment(HA_CENTER);
    speedText->SetVerticalAlignment(VA_CENTER);
    speedText->SetPosition(ui->GetRoot()->GetWidth()/8, ui->GetRoot()->GetHeight() / 8);
    
    Text* gearText = ui->GetRoot()->CreateChild<Text>("UITextGear");
    gearText->SetText("x gear");
    gearText->SetFont(cache->GetResource<Font>("Fonts/Anonymous Pro.ttf"), 15);
    // The text has multiple rows. Center them in relation to each other
    gearText->SetTextAlignment(HA_CENTER);
    // Position the text relative to the screen center
    gearText->SetHorizontalAlignment(HA_CENTER);
    gearText->SetVerticalAlignment(VA_CENTER);
    gearText->SetPosition(ui->GetRoot()->GetWidth()/8, ui->GetRoot()->GetHeight() / 6);
    
    
}
Esempio n. 5
0
int ScriptBinding::text_setFont(lua_State * s)
{
	Text * text  = (Text*)lua_tointeger(s,1);
	const char * string = lua_tostring(s,2);

	text->SetFont(string);

	return 0;
}
Esempio n. 6
0
void Player::CreateGUI()
{
    UI* ui = GetSubsystem<UI>();
    Text* scoreText = ui->GetRoot()->CreateChild<Text>();
    scoreText->SetName("Score");
    scoreTextName_ = scoreText->GetName();
    scoreText->SetText(String(score_));
    scoreText->SetFont(masterControl_->cache_->GetResource<Font>("Resources/Fonts/skirmishergrad.ttf"), 32);
    scoreText->SetColor(Color(0.5f, 0.95f, 1.0f, 0.666f));
    scoreText->SetHorizontalAlignment(HA_CENTER);
    scoreText->SetVerticalAlignment(VA_CENTER);
    scoreText->SetPosition(0, ui->GetRoot()->GetHeight()/2.5f);

    //Setup 3D GUI elements
    guiNode_ = masterControl_->world.scene->CreateChild("GUI3D");
    healthBarNode_ = guiNode_->CreateChild("HealthBar");
    healthBarNode_->SetPosition(Vector3(0.0f, 1.0f, 21.0f));
    healthBarNode_->SetScale(Vector3(health_, 1.0f, 1.0f));
    healthBarModel_ = healthBarNode_->CreateComponent<StaticModel>();
    healthBarModel_->SetModel(masterControl_->cache_->GetResource<Model>("Resources/Models/Bar.mdl"));
    healthBarModel_->SetMaterial(masterControl_->cache_->GetTempResource<Material>("Resources/Materials/GreenGlowEnvmap.xml"));

    shieldBarNode_ = guiNode_->CreateChild("HealthBar");
    shieldBarNode_->SetPosition(Vector3(0.0f, 1.0f, 21.0f));
    shieldBarNode_->SetScale(Vector3(health_, 0.9f, 0.9f));
    shieldBarModel_ = shieldBarNode_->CreateComponent<StaticModel>();
    shieldBarModel_->SetModel(masterControl_->cache_->GetResource<Model>("Resources/Models/Bar.mdl"));
    shieldBarModel_->SetMaterial(masterControl_->cache_->GetResource<Material>("Resources/Materials/BlueGlowEnvmap.xml"));

    Node* healthBarHolderNode = guiNode_->CreateChild("HealthBarHolder");
    healthBarHolderNode->SetPosition(Vector3(0.0f, 1.0f, 21.0f));
    StaticModel* healthBarHolderModel = healthBarHolderNode->CreateComponent<StaticModel>();
    healthBarHolderModel->SetModel(masterControl_->cache_->GetResource<Model>("Resources/Models/BarHolder.mdl"));
    healthBarHolderModel->SetMaterial(masterControl_->cache_->GetResource<Material>("Resources/Materials/Metal.xml"));

    appleCounterRoot_ = guiNode_->CreateChild("AppleCounter");
    for (int a = 0; a < 5; a++){
        appleCounter_[a] = appleCounterRoot_->CreateChild();
        appleCounter_[a]->SetEnabled(false);
        appleCounter_[a]->SetPosition(Vector3(-(a + 8.0f), 1.0f, 21.0f));
        appleCounter_[a]->SetScale(0.333f);
        StaticModel* apple = appleCounter_[a]->CreateComponent<StaticModel>();
        apple->SetModel(masterControl_->cache_->GetResource<Model>("Resources/Models/Apple.mdl"));
        apple->SetMaterial(masterControl_->cache_->GetTempResource<Material>("Resources/Materials/GoldEnvmap.xml"));
    }

    heartCounterRoot_ = guiNode_->CreateChild("HeartCounter");
    for (int h = 0; h < 5; h++){
        heartCounter_[h] = heartCounterRoot_->CreateChild();
        heartCounter_[h]->SetEnabled(false);
        heartCounter_[h]->SetPosition(Vector3(h + 8.0f, 1.0f, 21.0f));
        heartCounter_[h]->SetScale(0.333f);
        StaticModel* heart = heartCounter_[h]->CreateComponent<StaticModel>();
        heart->SetModel(masterControl_->cache_->GetResource<Model>("Resources/Models/Heart.mdl"));
        heart->SetMaterial(masterControl_->cache_->GetTempResource<Material>("Resources/Materials/RedEnvmap.xml"));
    }
}
Esempio n. 7
0
void GameApplication::CreateUI()
{
	Input* input = GetSubsystem<Input>();
	input->SetMouseVisible(true);

    ResourceCache* cache = GetSubsystem<ResourceCache>();
    UI* ui = GetSubsystem<UI>();
    
    // Create a Cursor UI element because we want to be able to hide and show it at will. When hidden, the mouse cursor will
    // control the camera, and when visible, it will point the raycast target
    XMLFile* style = cache->GetResource<XMLFile>("UI/DefaultStyle.xml");
    SharedPtr<Cursor> cursor(new Cursor(context_));
    cursor->SetStyleAuto(style);
    ui->SetCursor(cursor);
    // Set starting position of the cursor at the rendering window center
    Graphics* graphics = GetSubsystem<Graphics>();
    cursor->SetPosition(graphics->GetWidth() / 2, graphics->GetHeight() / 2);
    
    // Construct new Text object, set string to display and font to use
    scoreText = ui->GetRoot()->CreateChild<Text>();
    scoreText->SetFont(cache->GetResource<Font>("Fonts/Anonymous Pro.ttf"), 15);
    // The text has multiple rows. Center them in relation to each other
    scoreText->SetTextAlignment(HA_CENTER);
	scoreText->SetColor(Color::BLUE);
	scoreText->SetTextEffect(TextEffect::TE_SHADOW);
    // Position the text relative to the screen center
    scoreText->SetHorizontalAlignment(HA_CENTER);
    scoreText->SetVerticalAlignment(VA_CENTER);
    scoreText->SetPosition(0, ui->GetRoot()->GetHeight() / 4 + 80);

	//开始按钮
	//UIButton* btnStart = new UIButton(context_);
	//btnStart->SetPosition(100,100);
	//btnStart->SetSize(120,50);

	//ui->GetRoot()->AddChild(btnStart);

	Button* btnStart = CreateButton(80,100,120,50,"Start");// ui->GetRoot()->CreateChild<Button>();
	btnStart->SetName("btnStart");
	btnStart->SetMinHeight(24);
	btnStart->SetStyleAuto();
	btnStart->SetPosition(100,100);
	btnStart->SetSize(120,50);

	Text* buttonText = btnStart->CreateChild<Text>();
	buttonText->SetAlignment(HA_CENTER, VA_CENTER);
	buttonText->SetColor(Color::BLUE);
	Font* font = cache->GetResource<Font>("Fonts/Anonymous Pro.ttf");
	buttonText->SetFont(font, 12);
	buttonText->SetText("Start");

	SubscribeToEvent(btnStart,E_PRESSED,HANDLER(GameApplication,OnButtonStartClick));

	UpdateScore();
}
Esempio n. 8
0
void TowerApp::CreateInstructions() {
    ResourceCache *cache = GetSubsystem<ResourceCache>();
    UI *ui = GetSubsystem<UI>();

    // Construct new Text object, set string to display and font to use
    Text *instructionText = ui->GetRoot()->CreateChild<Text>();
    instructionText->SetText("Use WASD keys to move, use PageUp PageDown keys to zoom.");
    instructionText->SetFont(cache->GetResource<Font>("Fonts/Anonymous Pro.ttf"), 15);

    // Position the text relative to the screen center
    instructionText->SetHorizontalAlignment(HA_CENTER);
    instructionText->SetVerticalAlignment(VA_CENTER);
    instructionText->SetPosition(0, ui->GetRoot()->GetHeight() / 4);
}
Esempio n. 9
0
void LightAnimation::CreateInstructions()
{
    ResourceCache* cache = GetSubsystem<ResourceCache>();
    UI* ui = GetSubsystem<UI>();

    // Construct new Text object, set string to display and font to use
    Text* instructionText = ui->GetRoot()->CreateChild<Text>();
    instructionText->SetText("Use WASD keys and mouse/touch to move");
    Font* font = cache->GetResource<Font>("Fonts/Anonymous Pro.ttf");
    instructionText->SetFont(font, 15);

    // Position the text relative to the screen center
    instructionText->SetHorizontalAlignment(HA_CENTER);
    instructionText->SetVerticalAlignment(VA_CENTER);
    instructionText->SetPosition(0, ui->GetRoot()->GetHeight() / 4);

    // Animating text
    Text* text = ui->GetRoot()->CreateChild<Text>("animatingText");
    text->SetFont(font, 15);
    text->SetHorizontalAlignment(HA_CENTER);
    text->SetVerticalAlignment(VA_CENTER);
    text->SetPosition(0, ui->GetRoot()->GetHeight() / 4 + 20);
}
void SignedDistanceFieldText::CreateInstructions()
{
    ResourceCache* cache = GetContext()->m_ResourceCache.get();
    UI* ui = GetContext()->m_UISystem.get();

    // Construct new Text object, set string to display and font to use
    Text* instructionText = ui->GetRoot()->CreateChild<Text>();
    instructionText->SetText("Use WASD keys and mouse/touch to move");
    instructionText->SetFont(cache->GetResource<Font>("Fonts/Anonymous Pro.ttf"), 15);

    // Position the text relative to the screen center
    instructionText->SetHorizontalAlignment(HA_CENTER);
    instructionText->SetVerticalAlignment(VA_CENTER);
    instructionText->SetPosition(0, ui->GetRoot()->GetHeight() / 4);
}
Esempio n. 11
0
void Urho2DConstraints::CreateInstructions()
{
    ResourceCache* cache = GetSubsystem<ResourceCache>();
    UI* ui = GetSubsystem<UI>();

    // Construct new Text object, set string to display and font to use
    Text* instructionText = ui->GetRoot()->CreateChild<Text>();
    instructionText->SetText("Use WASD keys and mouse to move, Use PageUp PageDown to zoom.\n Space to toggle debug geometry and joints - F5 to save the scene.");
    instructionText->SetFont(cache->GetResource<Font>("Fonts/Anonymous Pro.ttf"), 15);
    instructionText->SetTextAlignment(HA_CENTER); // Center rows in relation to each other

    // Position the text relative to the screen center
    instructionText->SetHorizontalAlignment(HA_CENTER);
    instructionText->SetVerticalAlignment(VA_CENTER);
    instructionText->SetPosition(0, ui->GetRoot()->GetHeight() / 4);
}
Esempio n. 12
0
Button* Chat::CreateButton(const String& text, int width)
{
    ResourceCache* cache = GetSubsystem<ResourceCache>();
    Font* font = cache->GetResource<Font>("Fonts/Anonymous Pro.ttf");
    
    Button* button = buttonContainer_->CreateChild<Button>();
    button->SetStyleAuto();
    button->SetFixedWidth(width);
    
    Text* buttonText = button->CreateChild<Text>();
    buttonText->SetFont(font, 12);
    buttonText->SetAlignment(HA_CENTER, VA_CENTER);
    buttonText->SetText(text);
    
    return button;
}
Esempio n. 13
0
void UIDrag::CreateInstructions()
{
    ResourceCache* cache = GetSubsystem<ResourceCache>();
    UI* ui = GetSubsystem<UI>();

    // Construct new Text object, set string to display and font to use
    Text* instructionText = ui->GetRoot()->CreateChild<Text>();
    instructionText->SetText("Drag on the buttons to move them around.\n"
                             "Touch input allows also multi-drag.\n"
                             "Press SPACE to show/hide tagged UI elements.");
    instructionText->SetFont(cache->GetResource<Font>("Fonts/Anonymous Pro.ttf"), 15);
    instructionText->SetTextAlignment(HA_CENTER);

    // Position the text relative to the screen center
    instructionText->SetHorizontalAlignment(HA_CENTER);
    instructionText->SetVerticalAlignment(VA_CENTER);
    instructionText->SetPosition(0, ui->GetRoot()->GetHeight() / 4);
}
Esempio n. 14
0
void SkeletalAnimation::CreateInstructions()
{
    ResourceCache* cache = GetSubsystem<ResourceCache>();
    UI* ui = GetSubsystem<UI>();
    
    // Construct new Text object, set string to display and font to use
    Text* instructionText = ui->GetRoot()->CreateChild<Text>();
    instructionText->SetText(
        "Use WASD keys and mouse to move\n"
        "Space to toggle debug geometry"
    );
    instructionText->SetFont(cache->GetResource<Font>("Fonts/Anonymous Pro.ttf"), 15);
    
    // Position the text relative to the screen center
    instructionText->SetHorizontalAlignment(HA_CENTER);
    instructionText->SetVerticalAlignment(VA_CENTER);
    instructionText->SetPosition(0, ui->GetRoot()->GetHeight() / 4);
}
Esempio n. 15
0
Button* SoundEffects::CreateButton(int x, int y, int xSize, int ySize, const String& text)
{
    UIElement* root = GetSubsystem<UI>()->GetRoot();
    ResourceCache* cache = GetSubsystem<ResourceCache>();
    Font* font = cache->GetResource<Font>("Fonts/Anonymous Pro.ttf");
    
    // Create the button and center the text onto it
    Button* button = root->CreateChild<Button>();
    button->SetStyleAuto();
    button->SetPosition(x, y);
    button->SetSize(xSize, ySize);
    
    Text* buttonText = button->CreateChild<Text>();
    buttonText->SetAlignment(HA_CENTER, VA_CENTER);
    buttonText->SetFont(font, 12);
    buttonText->SetText(text);
    
    return button;
}
Esempio n. 16
0
void MultipleViewports::CreateInstructions()
{
    ResourceCache* cache = GetSubsystem<ResourceCache>();
    UI* ui = GetSubsystem<UI>();
    
    // Construct new Text object, set string to display and font to use
    Text* instructionText = ui->GetRoot()->CreateChild<Text>();
    instructionText->SetText(
        "Use WASD keys and mouse/touch to move\n"
        "B to toggle bloom, F to toggle FXAA\n"
        "Space to toggle debug geometry\n"
    );
    instructionText->SetFont(cache->GetResource<Font>("Fonts/Anonymous Pro.ttf"), 15);
    // The text has multiple rows. Center them in relation to each other
    instructionText->SetTextAlignment(HA_CENTER);
    
    // Position the text relative to the screen center
    instructionText->SetHorizontalAlignment(HA_CENTER);
    instructionText->SetVerticalAlignment(VA_CENTER);
    instructionText->SetPosition(0, ui->GetRoot()->GetHeight() / 4);
}
Esempio n. 17
0
Slider* SoundEffects::CreateSlider(int x, int y, int xSize, int ySize, const String& text)
{
    UIElement* root = GetSubsystem<UI>()->GetRoot();
    ResourceCache* cache = GetSubsystem<ResourceCache>();
    Font* font = cache->GetResource<Font>("Fonts/Anonymous Pro.ttf");
    
    // Create text and slider below it
    Text* sliderText = root->CreateChild<Text>();
    sliderText->SetPosition(x, y);
    sliderText->SetFont(font, 12);
    sliderText->SetText(text);
    
    Slider* slider = root->CreateChild<Slider>();
    slider->SetStyleAuto();
    slider->SetPosition(x, y + 20);
    slider->SetSize(xSize, ySize);
    // Use 0-1 range for controlling sound/music master volume
    slider->SetRange(1.0f);
    
    return slider;
}
Esempio n. 18
0
void CharacterDemo::CreateInstructions()
{
    ResourceCache* cache = GetSubsystem<ResourceCache>();
    UI* ui = GetSubsystem<UI>();

    // Construct new Text object, set string to display and font to use
    Text* instructionText = ui->GetRoot()->CreateChild<Text>();
    instructionText->SetText(
        "Use WASD keys and mouse/touch to move\n"
        "Space to jump, F to toggle 1st/3rd person\n"
        "F5 to save scene, F7 to load"
    );
    instructionText->SetFont(cache->GetResource<Font>("Fonts/Anonymous Pro.ttf"), 15);
    // The text has multiple rows. Center them in relation to each other
    instructionText->SetTextAlignment(HA_CENTER);

    // Position the text relative to the screen center
    instructionText->SetHorizontalAlignment(HA_CENTER);
    instructionText->SetVerticalAlignment(VA_CENTER);
    instructionText->SetPosition(0, ui->GetRoot()->GetHeight() / 4);
}
Esempio n. 19
0
void PhysicsStressTest::CreateInstructions()
{
    ResourceCache* cache = GetSubsystem<ResourceCache>();
    UI* ui = GetSubsystem<UI>();
    
    // Construct new Text object, set string to display and font to use
    Text* instructionText = ui->GetRoot()->CreateChild<Text>();
    instructionText->SetText(
        "Use WASD keys and mouse to move\n"
        "LMB to spawn physics objects\n"
        "F5 to save scene, F7 to load\n"
        "Space to toggle physics debug geometry"
    );
    instructionText->SetFont(cache->GetResource<Font>("Fonts/Anonymous Pro.ttf"), 15);
    // The text has multiple rows. Center them in relation to each other
    instructionText->SetTextAlignment(HA_CENTER);
    
    // Position the text relative to the screen center
    instructionText->SetHorizontalAlignment(HA_CENTER);
    instructionText->SetVerticalAlignment(VA_CENTER);
    instructionText->SetPosition(0, ui->GetRoot()->GetHeight() / 4);
}
Esempio n. 20
0
void Text::RefreshSizeWrap()
{
	RemoveAllChildren();

	for( TextLines::const_iterator it = m_Lines.begin(), end = m_Lines.end(); it != end; ++it )
	{
		Text *t = *it;
		delete t, t = 0;
	}

	m_Lines.clear();

	std::vector<Gwen::UnicodeString> words;
	SplitWords( GetText().GetUnicode(), L' ', words );

	// Adding a bullshit word to the end simplifies the code below
	// which is anything but simple.
	words.push_back( L"" );

	if ( !GetFont() )
	{
		Debug::AssertCheck( 0, "Text::RefreshSize() - No Font!!\n" );
		return;
	}

	Point pFontSize = GetSkin()->GetRender()->MeasureText( GetFont(), L" " );

	int w = GetParent()->Width();
	int x = 0, y = 0;

	Gwen::UnicodeString strLine;

	std::vector<Gwen::UnicodeString>::iterator it = words.begin();
	for ( it; it != words.end(); ++it )
	{
		bool bFinishLine = false;
		bool bWrapped = false;

		// If this word is a newline - make a newline (we still add it to the text)
		if ( (*it).c_str()[0] == L'\n' ) bFinishLine = true;

		// Does adding this word drive us over the width?
		{
			strLine += (*it);
			Gwen::Point p = GetSkin()->GetRender()->MeasureText( GetFont(), strLine );
			if ( p.x > Width() ) { bFinishLine = true; bWrapped = true; }
		}

		// If this is the last word then finish the line
		if ( --words.end() == it )
		{
			bFinishLine = true;
		}

		if ( bFinishLine )
		{
			Text* t = new Text( this );
				t->SetFont( GetFont() );
				t->SetString( strLine.substr( 0, strLine.length() - (*it).length() ) );
				t->RefreshSize();
				t->SetPos( x, y );
			m_Lines.push_back( t );

			// newline should start with the word that was too big
			strLine = *it;

			// Position the newline
			y += pFontSize.y;
			x = 0;

			//if ( strLine[0] == L' ' ) x -= pFontSize.x;
		}

	}

	// Size to children height and parent width
	{
		Point childsize = ChildrenSize();
		SetSize( w, childsize.y );
	}

	InvalidateParent();
	Invalidate();
}
Esempio n. 21
0
void Text::RefreshSizeWrap()
{
	RemoveAllChildren();

	for ( TextLines::iterator it = m_Lines.begin(); it != m_Lines.end(); ++it )
	{
		delete *it;
	}

	m_Lines.clear();
	std::vector<Gwen::UnicodeString> words;
	SplitWords( GetText().GetUnicode(), words );
	// Adding a bullshit word to the end simplifies the code below
	// which is anything but simple.
	words.push_back( L"" );

	if ( !GetFont() )
	{
		Debug::AssertCheck( 0, "Text::RefreshSize() - No Font!!\n" );
		return;
	}

	Point pFontSize = GetSkin()->GetRender()->MeasureText( GetFont(), L" " );
	int w = GetParent()->Width() - GetParent()->GetPadding().left-GetParent()->GetPadding().right; 
	int x = 0, y = 0;
	Gwen::UnicodeString strLine;

	for ( std::vector<Gwen::UnicodeString>::iterator it = words.begin(); it != words.end(); ++it )
	{
		bool bFinishLine = false;
		bool bWrapped = false;

		// If this word is a newline - make a newline (we still add it to the text)
		if ( ( *it ).c_str() [0] == L'\n' ) { bFinishLine = true; }

		// Does adding this word drive us over the width?
		{
			strLine += ( *it );
			Gwen::Point p = GetSkin()->GetRender()->MeasureText( GetFont(), strLine );

			if ( p.x > w ) { bFinishLine = true; bWrapped = true; }
		}

		// If this is the last word then finish the line
		if ( --words.end() == it )
		{
			bFinishLine = true;
		}

		if ( bFinishLine )
		{
			Text* t = new Text( this );
			t->SetFont( GetFont() );
			t->SetTextColor( m_Color );
			if(bWrapped)
			{
				t->SetString( strLine.substr( 0, strLine.length() - (*it).length() ) );
				// newline should start with the word that was too big
				strLine = *it;
			}
			else
			{
				t->SetString( strLine.substr( 0, strLine.length()) );
				//new line is empty
				strLine.clear();
			} 
			t->RefreshSize();
			t->SetPos( x, y );
			m_Lines.push_back( t );

			// newline should start with the word that was too big
			// strLine = *it;

			// Position the newline
			y += pFontSize.y;
			x = 0;
			//if ( strLine[0] == L' ' ) x -= pFontSize.x;
		}
	}

	// Size to children height and parent width
	Point childsize = ChildrenSize();
	{
		SetSize( w, childsize.y );
	}

	// Align the text within the parent
	int y_offset = 0;
	for ( TextLines::iterator it = m_Lines.begin(); it != m_Lines.end(); ++it )
	{
		Text* text = *it;
		const Rect & bounds = GetInnerBounds();

		int x = 0;
		int y = 0;

		if ( m_iAlign & Pos::Left )		{ x = bounds.x; }
		if ( m_iAlign & Pos::Right )	{ x = bounds.x + ( bounds.w - text->Width() ); }
		if ( m_iAlign & Pos::CenterH )	{ x = bounds.x + ( bounds.w - text->Width() )  * 0.5; }
		if ( m_iAlign & Pos::Top )		{ y = bounds.y; }
		if ( m_iAlign & Pos::Bottom )	{ y = bounds.y + ( bounds.h - childsize.y ); }
		if ( m_iAlign & Pos::CenterV )	{ y = bounds.y + ( bounds.h - childsize.y )  * 0.5; }

		text->SetPos( x, y + y_offset );

		y_offset += text->Height();
	}

	InvalidateParent();
	Invalidate();
}
Esempio n. 22
0
void Text::RefreshSizeWrap()
{
    RemoveAllChildren();
    m_Lines.clear();

    stl::vector<Gwen::String> words;
    SplitWords( GetText().Get(), ' ', words );

    // Adding a bullshit word to the end simplifies the code below
    // which is anything but simple.
    words.push_back( "" );

    if ( !GetFont() )
    {
        Debug::AssertCheck( 0, "Text::RefreshSize() - No Font!!\n" );
        return;
    }

    Point pFontSize = GetSkin()->GetRender()->MeasureText( GetFont(), " " );

    int w = GetParent()->Width();
    int x = 0, y = 0;

    Gwen::String strLine;

    stl::vector<Gwen::String>::iterator it = words.begin();
    for (; it != words.end(); ++it )
    {
        bool bFinishLine = false;
        //bool bWrapped = false;

        // If this word is a newline - make a newline (we still add it to the text)
        if ( (*it).c_str()[0] == '\n' ) bFinishLine = true;

        // Does adding this word drive us over the width?
        {
            strLine += (*it);
            Gwen::Point p = GetSkin()->GetRender()->MeasureText( GetFont(), strLine );
            if ( p.x > Width() ) {
                bFinishLine = true; /*bWrapped = true;*/
            }
        }

        // If this is the last word then finish the line
        // if ( --words.end() == it )
        // NOTE: replaced above commented out 'if' statement with this to appease
        //       the GCC compiler that comes with Marmalade SDK 6.0
        stl::vector<Gwen::String>::iterator temp = words.end() - 1;
        if ( temp == it )
        {
            bFinishLine = true;
        }

        if ( bFinishLine )
        {
            Text* t = new Text( this );
            t->SetFont( GetFont() );
            t->SetString( strLine.substr( 0, strLine.length() - (*it).length() ) );
            t->RefreshSize();
            t->SetPos( x, y );
            m_Lines.push_back( t );

            // newline should start with the word that was too big
            strLine = *it;

            // Position the newline
            y += pFontSize.y;
            x = 0;

            //if ( strLine[0] == ' ' ) x -= pFontSize.x;
        }

    }

    // Size to children height and parent width
    {
        Point childsize = ChildrenSize();
        SetSize( w, childsize.y );
    }

    InvalidateParent();
    Invalidate();
}