Ejemplo n.º 1
0
bool CGame::input_gameSystem(sf::Event* pEvent)
{
	// user is not looking at game
	if (pEvent->type == sf::Event::LostFocus)
	{
		isPaused = true;
		return true;
	}

	// user is looking at the game now
	if (pEvent->type == sf::Event::GainedFocus)
	{
		isPaused = false;
		return true;
	}

	// user changed the window size
	if (pEvent->type == sf::Event::Resized)
	{
		sf::FloatRect visibleArea(0, 0, pEvent->size.width, pEvent->size.height);
		m_pWindow->setView(sf::View(visibleArea));

		return true;
	}

	return false;
}
Ejemplo n.º 2
0
hdMultiPosRect hdDrawingView::getVisibleArea()
{
    int x, y, w, h;
    GetViewStart(&x, &y);
    GetClientSize(&w, &h);
    hdMultiPosRect visibleArea(x, y, w, h);
    return visibleArea;
}
Ejemplo n.º 3
0
int Frigid::init() {
	//Load stuff

	//TODO: Change to the refresh rate of the monitor.
	//mWindow.setFramerateLimit(30);

	//Get the user folder path.
	char path[MAX_PATH];
	if (SHGetFolderPathA(NULL, CSIDL_PROFILE, NULL, 0, path) != S_OK) {
		_error("Could not get the user path")
	}

	mPrefs = Preferences::instance();
	mPrefs->setHomeDir(path);
	mPrefs->setConfigDir(String(path) + "/Documents/_quark");

	BindingManager::instance()->setDefaultBindings();

	loadConfig();

	uint32 w = mPrefs->getStartingWindowWidth();
	uint32 h = mPrefs->getStartingWindowHeight();
	bool m = mPrefs->getStartMaximized();

	if (w == 0 || h == 0) {
		m = true;
		w = 1024;
		h = 600;
	}

	mWindow = new RenderWindow(VideoMode(w, h, 32, m), "Quark");

	mMainPanel = Panel();

	tempHelpText = Text("Press control + ? for help.", *mPrefs->getFont(), 12);

	getPreferences();

	CodeEditor *editor = new CodeEditor();
	mMainPanel.setWidget(editor);

	Input::initInput();

	WindowEvent e;
	e.type = WindowEvent::Resized;
	e.size.width = mWindow->getWidth();
	e.size.height = mWindow->getHeight();
	Rectf visibleArea(0, 0, staticCastf(e.size.width), staticCastf(e.size.height));
	mWindow->setView(View(visibleArea));
	mMainPanel.resizeEvent(e);

	update();
	quit();
	return 0;
}
Ejemplo n.º 4
0
        Frame::Frame(sf::RenderWindow& window,const ActionMap<int>& map) : Container(nullptr), ActionTarget(map), _window(window), _view(_window.getDefaultView())
        {
            ActionTarget::bind(Action(sf::Event::Resized),[this](const sf::Event& event){

                sf::FloatRect visibleArea(0, 0, event.size.width, event.size.height);
                this->_view = sf::View(visibleArea);

                if(Layout* layout = getLayout())
                    layout->updateShape();
           });
        }
Ejemplo n.º 5
0
void TerrariumEditor::resize(Vec2i delta, sf::RenderWindow& window)
{
    blueprint.width += delta.x;
    blueprint.height += delta.y;

    int winW = blueprint.width * blueprint.tileSize;
    int winH = blueprint.height * blueprint.tileSize;

    background.setSize(winW, winH);

    sf::FloatRect visibleArea(0, 0, winW, winH);
    window.setView(sf::View(visibleArea));
    window.setSize(sf::Vector2u(winW, winH));
}
int main()
{
	sf::RenderWindow window(sf::VideoMode(600, 600), "SFML WORK!");

	sf::Sprite background;

	sf::Texture texture;

	if (!texture.loadFromFile("Vertex Example.png"))
	{
		std::cout << "ERROR" << std::endl;
	}

	background.setTexture(texture);

	while (window.isOpen())
	{
		sf::Event event;

		while (window.pollEvent(event))
		{
			switch (event.type)
			{
			case sf::Event::Closed:
				window.close();

				break;

			case sf::Event::Resized:
				sf::FloatRect visibleArea(0, 0, event.size.width, event.size.height);
				window.setView(sf::View(visibleArea));

				break;

			}
		}

		window.clear();

		window.draw(background);

		window.display();
	}
}
Ejemplo n.º 7
0
void Frigid::getPreferences() {
	if (!mFirstTimePrefsSet && false) {
		uint32 ow = mPrefs->getOldStartingWindowWidth();
		uint32 oh = mPrefs->getOldStartingWindowHeight();

		uint32 w = mPrefs->getStartingWindowWidth();
		uint32 h = mPrefs->getStartingWindowHeight();
		bool m = mPrefs->getStartMaximized();

		if (ow != w || oh != h) {
			std::cerr << "killing window sparing childeren\n";

			if (w == 0 || h == 0) {
				m = true;
				w = 1024;
				h = 600;
			}

			delete mWindow;
			mWindow = new RenderWindow(VideoMode(w, h, 32, m), "Quark");

			WindowEvent e;
			e.type = WindowEvent::Resized;
			e.size.width = mWindow->getWidth();
			e.size.height = mWindow->getHeight();
			Rectf visibleArea(0, 0, staticCastf(e.size.width), staticCastf(e.size.height));
			mWindow->setView(View(visibleArea));
			mMainPanel.resizeEvent(e);
		}
	}

	mFirstTimePrefsSet = false;

	mClearColor = mPrefs->getTheme().clearColor;
	mWindow->setOpacity(mPrefs->getWindowOpacity());
	mWindow->setFramerateLimit(mPrefs->getFrameRate());
	mMainPanel.getPreferences();

	tempHelpText.setColor(mPrefs->getTheme().textColor);
	tempHelpText.setFont(*mPrefs->getFont());
}
Ejemplo n.º 8
0
int main(int, char const**) {
	// Create the main window
	sf::RenderWindow window(sf::VideoMode(800, 600), "SFML window");
	window.setFramerateLimit(60);
	
	ServerCommunicator serverCommunicator;
	ClientServerCommunicator offlineCommunicator;
	CommunicatorPair pair;
	pair.offlineCommunicator = &offlineCommunicator;
	pair.serverCommunicator = &serverCommunicator;
	std::thread mainServerThread(startMainServer, &pair);
	std::thread tcpServerThread;
	bool didLaunchTcpThread = true;
	if(sf::IpAddress::getLocalAddress().toString() == "0.0.0.0")
		didLaunchTcpThread = false;
	else
		tcpServerThread = std::thread(startTcpServer, &serverCommunicator);
	
	// sleep for 10 ms to give the server time to set up
	std::this_thread::sleep_for(std::chrono::nanoseconds(10000000));
	
	Client client(window, serverCommunicator, offlineCommunicator);
	
	bool shouldProgramContinue = client.start();
	
	// Start the game loop
	while (window.isOpen()) {
		// Process events
		sf::Event event;
		while(window.pollEvent(event)) {
			// Close window: exit
			if (event.type == sf::Event::Closed)
				shouldProgramContinue = false;
			else if(event.type == sf::Event::KeyPressed)
				shouldProgramContinue = shouldProgramContinue && client.keyPressed(event.key.code);
			else if(event.type == sf::Event::KeyReleased)
				shouldProgramContinue = shouldProgramContinue && client.keyReleased(event.key.code);
			else if(event.type == sf::Event::TextEntered)
				shouldProgramContinue = shouldProgramContinue && client.textEntered(event.text.unicode);
			else if(event.type == sf::Event::MouseMoved)
				shouldProgramContinue = shouldProgramContinue && client.mouseMoved(event.mouseMove.x, event.mouseMove.y);
			else if(event.type == sf::Event::MouseButtonPressed)
				shouldProgramContinue = shouldProgramContinue && client.mousePressed(event.mouseButton.button, event.mouseButton.x, event.mouseButton.y);
			else if(event.type == sf::Event::MouseButtonReleased)
				shouldProgramContinue = shouldProgramContinue && client.mouseReleased(event.mouseButton.button, event.mouseButton.x, event.mouseButton.y);
			else if(event.type == sf::Event::MouseWheelMoved)
				shouldProgramContinue = shouldProgramContinue && client.mouseWheeled(event.mouseWheel.delta, event.mouseButton.x, event.mouseButton.y);
			else if(event.type == sf::Event::Resized) {
				sf::FloatRect visibleArea(0, 0, event.size.width, event.size.height);
				window.setView(sf::View(visibleArea));
				shouldProgramContinue = shouldProgramContinue && client.resized(event.size.width, event.size.height);
			}
			else
				shouldProgramContinue = shouldProgramContinue && client.otherEvent(event);
		}
		
		client.networkUpdate();
		
		shouldProgramContinue = shouldProgramContinue && client.update();
		
		client.networkUpdate();
		
		// We draw once
		window.clear();
		shouldProgramContinue = shouldProgramContinue && client.draw();
		// Update the window
		window.display();
		
		client.networkUpdate();
		
		if(!shouldProgramContinue) {
			serverCommunicator.setShouldServersContinue(false);
			client.applicationIsClosing();
			mainServerThread.join();
			if(didLaunchTcpThread)
				tcpServerThread.join();
			window.close();
		}
	}

	return EXIT_SUCCESS;
}
Ejemplo n.º 9
0
void Application::handleEvents()
{
    // check all the windows events
    sf::Event event;
    while (m_window.pollEvent(event))
    {
        // "close requested" event: we close the window
        if (event.type == sf::Event::Closed)
            m_window.close();

        else if (event.type == sf::Event::GainedFocus)
            m_hasFocus = true;

        else if (event.type == sf::Event::LostFocus)
            m_hasFocus = false;

        else if (event.type == sf::Event::Resized)
        {
            // update the view to the new size of the window
            sf::FloatRect visibleArea(0.f, 0.f, event.size.width, event.size.height);
            m_window.setView(sf::View(visibleArea));
        }

        else if (event.type == sf::Event::KeyReleased) {
            // close if escape key was pressed
            if (event.key.code == sf::Keyboard::Escape) {
                m_window.close();
            }

            // play the sound if space was released
            else if (event.key.code == sf::Keyboard::Space)
            {
                if (m_sound.getStatus() == sf::Sound::Playing)
                    m_sound.pause();
                else
                    m_sound.play();

                updatePlayProgressBar();
            }

            else if (event.key.code == sf::Keyboard::L)
            {
                SettingsParser settings;
                if (settings.loadFromFile("settings.txt"))
                {
                    std::string filename;
                    settings.get("filename", filename);

                    int newFFTSize = -1;
                    settings.get("FFTSize", newFFTSize);

                    if (!filename.empty())
                    {
                        if (isPowerOf2(newFFTSize))
                        {
                            m_FFTSize = newFFTSize;
                        }
                        else
                        {
                            std::cout << "The FFTSize has to be a power of 2." << std::endl;
                        }

                        // try to load the new sound
                        if (m_soundBuffer.loadFromFile(filename))
                        {
                            m_spectrogram = std::unique_ptr<Spectrogram>(new Spectrogram(m_soundBuffer, m_FFTSize));
                            m_spectrogram->setPosition(100.f, 100.f);
                            m_spectrogram->generate();
                        }
                        else
                        {
                            std::cout << "Could not load soundfile with name: " << filename << std::endl;
                            // maybe throw exeption
                        }
                    }
                    else
                    {
                        std::cout << "There was no filename specified in the settings file!" << std::endl;
                    }
                }
                else
                {
                    std::cout << "Could not load settings file!" << std::endl;
                }
            }
        }

        else if (event.type == sf::Event::MouseWheelScrolled)
        {
            // "centered" zooming
            if (event.mouseWheelScroll.wheel == sf::Mouse::VerticalWheel)
            {
                // calculate the distance between the mouse and the left border of the spectrogram
                const sf::Vector2f mousePosition = m_window.mapPixelToCoords(sf::Mouse::getPosition(m_window));
                sf::FloatRect spectrogramRect = m_spectrogram->getLocalBounds();
                float distance = mousePosition.x - m_spectrogram->getPosition().x;
                // calculate the ration between the mouse and the width of the spectrogram
                float ratio = distance / spectrogramRect.width;

                // scale the spectrogram
                m_spectrogram->scale(1.f + 0.5f * event.mouseWheelScroll.delta, 1.f);

                // position spectrogram so that the ratio between the mouse and the width
                // of the spectrogram is the same as it was before scrolling
                float newDistance = m_spectrogram->getLocalBounds().width * ratio;
                m_spectrogram->setPosition(mousePosition.x - newDistance, m_spectrogram->getPosition().y);

                updatePlayProgressBar();
            }
        }
    }
}
Ejemplo n.º 10
0
void Frigid::update() {
	while (mWindow->isOpen()) {
		WindowEvent e;

		Input::updateInput();

		while (mWindow->pollEvent(e)) {
			switch (e.type) {
				case WindowEvent::Closed: {
					mWindow->close();
				} break;

				case WindowEvent::Resized: {
					Rectf visibleArea(0, 0, staticCastf(e.size.width), staticCastf(e.size.height));
					mWindow->setView(View(visibleArea));
					mMainPanel.resizeEvent(e);
				} break;

				case WindowEvent::TextEntered: {
					//TODO: Create proper filter.
					if (e.text.unicode >= 32 && e.text.unicode <= 126) {
						mMainPanel.enterText(e.text.unicode);
					}
				} break;

				case WindowEvent::KeyPressed: {
					Input::Key k = e.key.code;

					checkBindings();

					mMainPanel.keyPressed(e);
				} break;

				case WindowEvent::MouseWheelMoved: {
					mMainPanel.mouseWheelMoved(e);
				} break;

				//TODO!: Come up with a GUI system!
				case WindowEvent::GainedFocus: {
					mMainPanel.setHasFocus(true);
				} break;

				case WindowEvent::LostFocus: {
					mMainPanel.setHasFocus(false);
				} break;

				case WindowEvent::MouseButtonPressed: {
					mMainPanel.mouseButtonPressed(e);
				} break;
			}
		}
		
		lua_State *L = mPrefs->getLuaState();
		if (L) {
			lua_getglobal(L, "update");
			if (lua_isfunction(L, -1)) {
				lua_pcall(L, 0, 0, 0);
			} else {
				lua_pop(L, 1);
			}
		}

		uint32 w = tempHelpText.getLocalBounds().width;
		tempHelpText.setPosition((mWindow->getWidth() / 2) - (w / 2), 2);

		mWindow->clear(mClearColor);

		mMainPanel.update(mWindow);

		mWindow->draw(tempHelpText);

		mWindow->display(/*mWindow.hasFocus()*/);
	}

	lua_close(mPrefs->getLuaState());
}
Ejemplo n.º 11
0
int BaseInfo::run(sf::RenderWindow &window) {
	int i=1;
	const std::string fontfile = "DejaVuSans.ttf";
	sf::Font font;
	if (!font.loadFromFile(fontfile)) {
		std::cerr << "could not load font: " << fontfile << std::endl;
		return -1;
	}
	sf::Texture texture;
    if (!texture.loadFromFile("speech_bubble_r.png"))
        return -1;
    sf::Sprite sprite(texture);
	sf::Text text;
	text.setFont(font);
	text.setString(L"Что случилось?");
	text.setCharacterSize(48);
	text.setColor(sf::Color(112,146,190,255));	
	text.setPosition(deltaX,deltaY);
	sprite.setPosition(100,100);
	text.setPosition(100+deltaX,100+deltaY);
	
	sf::Clock clock;
	float elapsedSeconds = 0.0f;
	while (window.isOpen()) {
		if (elapsedSeconds >= 20) {
			return GAME_PLAY_SCENE;
		}
		sf::Event event;
		while (window.pollEvent(event)) {
			if (event.type == sf::Event::Closed) {
				return -1;
			} else if (event.type == sf::Event::Resized) {
				sf::FloatRect visibleArea(0, 0, event.size.width, event.size.height);
				window.setView(sf::View(visibleArea));
			} else if (event.type == sf::Event::KeyReleased) {
				switch (event.key.code) {
					case sf::Keyboard::Space:
						return GAME_PLAY_SCENE;
						break;
				}
			}
		}

		elapsedSeconds = clock.getElapsedTime().asSeconds();
		if (elapsedSeconds>3 && i==1){
			text.setString(L"Кто здесь?");
			sprite.setPosition(130,150);
			text.setPosition(130+deltaX,150+deltaY);
			i++;
		}
		if (elapsedSeconds>6 && i==2){
			text.setString(L"Я...я... кто я?");
			sprite.setPosition(80,180);
			text.setPosition(80+deltaX,180+deltaY);
			i++;
		}
		if (elapsedSeconds>9 && i==3){
			text.setString(L"Я ничего не помню");
			sprite.setPosition(130,80);
			text.setPosition(130+deltaX,80+deltaY);
			i++;
		}
		if (elapsedSeconds>12 && i==4){
			text.setString(L"Где мы? Что произошло?");
			sprite.setScale(1.5,1);
			sprite.setPosition(50,220);
			text.setPosition(50+deltaX,220+deltaY);
			i++;
		}
		if (elapsedSeconds>15 && i==5){
			sprite.setScale(1,1);
			text.setString(L"Ничего не вижу");
			sprite.setPosition(130,250);
			text.setPosition(130+deltaX,250+deltaY);
			i++;
		}
		if (elapsedSeconds>18 && i==6){
			sprite.setScale(1.5,1);
			text.setString(L"Кто-нибудь, включите свет!");
			sprite.setPosition(20,150);
			text.setPosition(20+deltaX,150+deltaY);
			i++;
		}

		window.clear();
		window.draw(sprite);
		window.draw(text);
		window.display();
	}

	return -1;
}