当前位置: 首页>>代码示例>>C++>>正文


C++ RenderWindow::GetView方法代码示例

本文整理汇总了C++中sf::RenderWindow::GetView方法的典型用法代码示例。如果您正苦于以下问题:C++ RenderWindow::GetView方法的具体用法?C++ RenderWindow::GetView怎么用?C++ RenderWindow::GetView使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sf::RenderWindow的用法示例。


在下文中一共展示了RenderWindow::GetView方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: onDraw

void Container::onDraw(sf::RenderWindow& render)
{
    sf::View original = render.GetView();
    sf::View view = render.GetView();
    view.Move(-rect.Left,-rect.Top);
    render.SetView(view);
    for(std::list<Widget*>::iterator i = childs.begin(); i != childs.end() ; ++i)
    {
        (*i)->draw(render);
        render.SetView(layout->adjust(render.GetView(),**i));
    }
    render.SetView(original);
}
开发者ID:djabby,项目名称:Ithilion,代码行数:13,代码来源:Widget.cpp

示例2: PushOpenGLStates

void ParticleSystem::PushOpenGLStates(sf::RenderWindow& target) const
{
	// Switch to manual OpenGL handling, save SFML's state
	target.SaveGLStates();
	target.SetActive();

	// Switch blend mode, depending on glow effect	
	if (mGlow)
		glBlendFunc(GL_SRC_ALPHA, GL_ONE);
	else
		glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	glEnable(GL_BLEND);

	// Store attributes and assign them
	glPushAttrib(GL_DEPTH_BITS | GL_TEXTURE_BIT);
	glDisable(GL_DEPTH_TEST);
	glEnable(GL_TEXTURE_2D);
	glBindTexture(GL_TEXTURE_2D, mTexture->id);

	// Initialize projection matrix (2D view)
	glMatrixMode(GL_PROJECTION);
	glPushMatrix();
	detail::SetupOpenGL2DView(target.GetView());

	// Initialize modelview matrix (will be edited in Particle::Render())
	glMatrixMode(GL_MODELVIEW);
	glPushMatrix();
}
开发者ID:,项目名称:,代码行数:28,代码来源:

示例3: AddHelpText

void AddHelpText(sf::RenderWindow &App, sf::Font &f, GroupManager &gm)
{
    sf::View v = App.GetView();
    sf::Vector2f center = v.GetCenter(), half = v.GetHalfSize();

    string s;
    s = "Operations available:\n";
    s += "Move:              Left, Right, Up, Down\n";
    s += "Speed:             s (decrease), d (increase)\n";
    s += "Step size:         w (decrease), e (increase)\n";
    s += "Zoom:              z (in), x (out)\n";
    s += "Steps mode:        a (switch between modes)\n";
    s += "Quit:              Esc\n";
    sf::String text(s, f, 12);
    text.SetColor(sf::Color(128, 200, 40));
    text.Move(center.x - half.x + half.x/20, center.y - half.y + half.y/20);
    App.Draw(text);


    ostringstream step_per_second_str;
    step_per_second_str << "~" << step_per_second << "\n";
    ostringstream step_time_str;
    step_time_str << "~" << step_time << "\n";
    ostringstream framerate_str;
    framerate_str << 1.0/App.GetFrameTime() << "\n";
    ostringstream step_size_str;
    step_size_str << gm.GetStepSize() << "\n";

    s = "Steps per second: ";
    s += step_per_second_str.str() ;
    s += "Step time: ";
    s += step_time_str.str();
    s += "Framerate: ";
    s += framerate_str.str();
    s += "Step size: ";
    s += step_size_str.str();
    s += "Steps mode: ";
    switch (step_mode)
    {
        case SM_HARD_STEPS_CNT: s += "SM_HARD_STEPS_CNT\n"; break;
        case SM_FREE_STEPS_CNT: s += "SM_FREE_STEPS_CNT\n"; break;
        default: break;
    }

    sf::String inf(s.c_str(), f, 20);
    inf.SetColor(sf::Color(230, 200, 180));
    inf.Move(center.x - half.x + half.x/20, center.y + half.y - half.y/2);
    App.Draw(inf);
}
开发者ID:just-another-one-timmy,项目名称:mechanism-cpp,代码行数:49,代码来源:main.cpp

示例4: run

void MainMenuHandler::run(sf::RenderWindow& window) {
	ImageCache mainMenuImages;
	const sf::Image& logoImage = mainMenuImages.get(Path::findDataPath("graphics/logo.png"));

	// Entering main menu, no game should be running.
	GameHandler::instance.reset();

	// Make view that is as close to 640x480 as possible and centered.
	view = window.GetDefaultView();
	view.Zoom(std::min(view.GetRect().GetWidth() / 640, view.GetRect().GetHeight() / 480));
	view.SetCenter(view.GetHalfSize());
	window.SetView(view);

	window.SetFramerateLimit(30);

	// Position at the top of the window.
	sf::Sprite logoSprite(logoImage);
	logoSprite.SetCenter(logoImage.GetWidth() / 2, 0);
	logoSprite.SetPosition(window.GetView().GetRect().GetWidth() / 2, 1);

	// Build the main menu GUI.
	GUI::Container gui;
	gui.insert(boost::shared_ptr<GUI::Object>(new GUI::Button("New game", 200, 100, 240, 50, boost::bind(&MainMenuHandler::startGame, this))));
	gui.insert(boost::shared_ptr<GUI::Object>(new GUI::Button("Exit", 250, 170, 140, 50, boost::bind(&sf::RenderWindow::Close, boost::ref(window)))));

	menuClosed = false;
	while (window.IsOpened() && !menuClosed) {
		sf::Event e;
		if (window.GetEvent(e)) {
			if (gui.handleEvent(e, window)) {
				continue;
			}
			if (e.Type == sf::Event::Closed || (e.Type == sf::Event::KeyPressed && e.Key.Code == sf::Key::Escape)) {
				window.Close();
				continue;
			}
		} else {
			window.Clear(sf::Color(0xcc, 0x66, 0x33));
			window.Draw(logoSprite);
			gui.draw(window);
			window.Display();
		}
	}
}
开发者ID:Pumpuli,项目名称:PutkaRTS,代码行数:44,代码来源:MainMenuHandler.cpp

示例5: Run

int Screen_Select::Run (sf::RenderWindow &App, Model* _model, Controleur* _controleur)
{
    sf::Event Event;
    bool Running = true;
    sf::Image Image;
    sf::Sprite Sprite;
    int alpha = 0;
    sf::Font Font;
	sf::String Menu0;
    sf::String Menu1;
    sf::String Menu2;
    sf::String Menu3;
    sf::String Menu4;
    int menu = 2;
	std::string ip = "";
	
	sf::SoundBuffer Buffer;
	if (!Buffer.LoadFromFile("../../Images/theme.wav"))
	{
		std::cout << "Musique pas trouvée" << std::endl;
	}
	
	sf::Sound Sound;
	Sound.SetBuffer(Buffer); // Buffer est un sfSoundBuffer
	
    if (!Image.LoadFromFile("../../Images/bf2.jpg"))
    {
        std::cerr << "Error loading bf2.jpg" << std::endl;
        return (-1);
    }
	
	Sprite.SetScale((App.GetView().GetRect().GetWidth() / 500), (App.GetView().GetRect().GetHeight() / 375));
    Sprite.SetImage(Image);
	Sprite.SetPosition(-1,-1);
	
	if (!Font.LoadFromFile("../../Images/GUNPLA3D.ttf"))
    {
        std::cerr << "Error loading font" << std::endl;
    }
	
    Menu0.SetFont(Font);
    Menu0.SetSize(25);
    Menu0.SetText("Pour jouer en Client, tapez l'ip en remplacant les . de l'adresse par des ;");
    Menu0.SetX(30);
    Menu0.SetY(App.GetView().GetRect().GetHeight() / 2 - 120);
    Menu1.SetFont(Font);
    Menu1.SetSize(25);
    Menu1.SetText("Client");
    Menu1.SetX(App.GetView().GetRect().GetWidth() / 2 - 30);
    Menu1.SetY(App.GetView().GetRect().GetHeight() / 2 - 42);
    Menu2.SetFont(Font);
    Menu2.SetSize(25);
    Menu2.SetText("Serveur");
    Menu2.SetX(App.GetView().GetRect().GetWidth() / 2 - 30);
    Menu2.SetY(App.GetView().GetRect().GetHeight() / 2);
    Menu3.SetFont(Font);
    Menu3.SetSize(25);
    Menu3.SetText("Retour");
    Menu3.SetX(App.GetView().GetRect().GetWidth() / 2 - 30);
    Menu3.SetY(App.GetView().GetRect().GetHeight() / 2 + 100);
	Menu4.SetFont(Font);
    Menu4.SetSize(25);
    Menu4.SetText(ip);
    Menu4.SetX(App.GetView().GetRect().GetWidth() / 2 - 30);
    Menu4.SetY(App.GetView().GetRect().GetHeight() / 2 + 50);
	
	App.Clear();
	
    if (playing)
    {
        alpha = alpha_max;
    }
	
	Sound.Play();
	Sound.SetLoop(true);
	
    while (Running)
    {
		
        //Verifying events
        while (App.GetEvent(Event))
        {
            // Window closed
            if (Event.Type == sf::Event::Closed)
            {
                return (-1);
            }
            //Key pressed
            if (Event.Type == sf::Event::KeyPressed)
            {
                switch (Event.Key.Code)
                {
                    case sf::Key::Up:
						if(menu == 1)
							menu++;
						if(menu == 0)
							menu++;
                        break;
                    case sf::Key::Down:
						if(menu == 1)
//.........这里部分代码省略.........
开发者ID:Samcpa,项目名称:bomber-pack,代码行数:101,代码来源:Screen_Select.cpp

示例6: ProcessAppEvents

void ProcessAppEvents(sf::RenderWindow &App, sf::View &v, GroupManager &gm)
{
    sf::Event Event;
    while (App.GetEvent(Event))
    {
        switch (Event.Type)
        {
            case sf::Event::Closed: App.Close(); break;
            case sf::Event::KeyPressed:
            {
                switch (Event.Key.Code)
                {
                    case sf::Key::Escape: App.Close(); break;
                    case sf::Key::Right:
                    case sf::Key::Left:
                    case sf::Key::Up:
                    case sf::Key::Down:
                    {
                        const int step = 5;
                        v = App.GetView();
                        int hor = 0, ver = 0;
                        if (Event.Key.Code == sf::Key::Left)
                            hor+=step;
                        if (Event.Key.Code == sf::Key::Right)
                            hor-=step;
                        if (Event.Key.Code == sf::Key::Up)
                            ver+=step;
                        if (Event.Key.Code == sf::Key::Down)
                            ver-=step;
                        v.Move(hor, ver);
                        App.SetView(v);
                        break;
                    }
                    case sf::Key::S:
                    case sf::Key::D:
                    {
                        //if (Event.Key.Code == sf::Key::S)
                        //    wanna_step_per_second-= wanna_step_per_second/10 - 1;
                        //if (Event.Key.Code == sf::Key::D)
                        //    wanna_step_per_second+= wanna_step_per_second/10 + 1;
                        //if (wanna_step_per_second <= 0)
                        //    step_per_second = 1;
                        //if (wanna_step_per_second >= 250)
                        //    step_per_second = 250;
                        //step_time = 1.0/wanna_step_per_second;
                        break;
                    }
                    case sf::Key::W:
                    case sf::Key::E:
                    {
                        if (Event.Key.Code == sf::Key::E)
                            gm.SetStepSize(gm.GetStepSize() + 0.005);
                        if (Event.Key.Code == sf::Key::W)
                            gm.SetStepSize(gm.GetStepSize() - 0.005);
                        break;
                    }
                    case sf::Key::Z:
                    case sf::Key::X:
                    {
                        if (Event.Key.Code == sf::Key::Z)
                            v.Zoom(1.01);
                        if (Event.Key.Code == sf::Key::X)
                            v.Zoom(1.0/1.01);
                        break;
                    }
                    case sf::Key::A:
                    {
                        step_mode = (STEP_MODE) ((int)SM_HARD_STEPS_CNT + (int)SM_FREE_STEPS_CNT - step_mode);
                        break;
                    }
                    default: break;
                }
                break;
            }
            case sf::Event::Resized:
            {
                int h = Event.Size.Height;
                int w = Event.Size.Width;
                v.SetHalfSize(w/2, h/2);
                break;
            }
            default: break;
        }
    }
}
开发者ID:just-another-one-timmy,项目名称:mechanism-cpp,代码行数:85,代码来源:main.cpp


注:本文中的sf::RenderWindow::GetView方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。