Beispiel #1
0
	virtual void readyToStart()
	{
		MeshViewerApp::instance = this;
		viewerWindow = std::shared_ptr<MeshViewerWindow>(new MeshViewerWindow());
		registerWindow(viewerWindow.get());
		setMainWindow(viewerWindow.get());
		viewerWindow->setVisible(true);
	}
Beispiel #2
0
static bool registerDummyWindow() {
	static bool window_registered = false;
	if (!window_registered) {
		if (!registerWindow(dummyWindowProc, _CONTEXT_PRIVATE_CLASS_NAME)) {
			return false;
		}
		window_registered = true;
	}
	return true;
}
Beispiel #3
0
Label::Label(HINSTANCE hI, UI* ui) : UI(hI, ui) 
{
	handler = CreateWindow("STATIC", "Default text", 
        WS_CHILD | WS_VISIBLE | SS_LEFT, 
        0, 0, 1, 1, *parent, (HMENU)id, 
        hI, NULL);
	
	if (!handler) throw WindowCreateException();
	registerWindow();
};
Beispiel #4
0
pxError pxWindow::init(int left, int top, int width, int height)
{
    Window rootwin;

    int scr;
    Display* dpy = mDisplayRef.getDisplay();

    scr = DefaultScreen(dpy);
    rootwin = RootWindow(dpy, scr);
    
    win=XCreateSimpleWindow(dpy, rootwin, left, top, width, height, 0, 
                            BlackPixel(dpy, scr), BlackPixel(dpy, scr));

    if (win)
    {
	XSizeHints      size_hints ;
    
	size_hints.flags = PPosition ;
	size_hints.x = left ;
	size_hints.y = top ;
	XSetNormalHints( dpy, win, &size_hints) ; 
    
	XWindowAttributes attr;
	XGetWindowAttributes(dpy, win, &attr);

	this->onSize(attr.width, attr.height);
    
	XSelectInput(dpy, win, 
                 PointerMotionMask|
                 ExposureMask|
                 ButtonPressMask|ButtonReleaseMask|
                 KeyPressMask|KeyReleaseMask |
                 StructureNotifyMask | LeaveWindowMask
	    );
	
	registerWindow(win, this);
    
	XSetWindowBackgroundPixmap(dpy, win, None);
    
	closeatom = XInternAtom(dpy, 
				"WM_DELETE_WINDOW", 
				false);
    
	XSetWMProtocols(dpy, 
			win, 
			&closeatom, 
			1);
    
	this->onCreate();
    }
    
    return win?PX_OK:PX_FAIL;
}
Beispiel #5
0
/*
	Name		WINAPI WinMain
	Syntax		WINAPI WinMain(HINSTANCE hInstance, HINSTANCE prevInstance, 
							   PSTR cmdLine, int showCmd)
	Param		HINSTANCE hInstance - Handle to an intance
	Param		HINSTANCE prevInstance - No longer used (always 0)
	Param		PSTR cmdLine - command-line arguments as a Unicode string
	Param		int showCmd -  Flag to indicate if the window will be minimized, 
							   maximized, or shown normally
	Return		int - Not used
	Brief		Entry point of programme
*/
int WINAPI WinMain(	HINSTANCE hInstance,
					HINSTANCE prevInstance, 
					PSTR cmdLine,
					int showCmd)
{
	MSG msg;
	
	registerWindow(hInstance);

   	if (!initialiseWindow(hInstance, showCmd))
		return false;

	
	
	App->initialise();

	while(running) 
	{
		if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
		{
		    if (msg.message == WM_QUIT)
			{
				running = false;
			}
			if (msg.message == WM_CLOSE)
			{
				running = false;
			}
			TranslateMessage (&msg);							
			DispatchMessage (&msg);
		}
		else
		{
			running = App->runFrame();
		}		
    }

	App->deinitialise();

	return msg.wParam;	
}
Beispiel #6
0
int Window::handleMessage( uint32_t code, void* data, size_t size ) {
    switch (code) {
        case Y_WINDOW_SHOW :
            registerWindow();
            break;

        case Y_WINDOW_HIDE :
            unregisterWindow();
            break;

        case Y_WINDOW_DO_RESIZE :
            resize(reinterpret_cast<WinResize*>(data)->m_size);
            break;

        case Y_WINDOW_DO_MOVETO :
            moveTo(reinterpret_cast<WinMoveTo*>(data)->m_position);
            break;

        case Y_WINDOW_RENDER : {
            if (!m_rendering) {
                m_renderContext.init(m_bitmap);
                m_rendering = true;
            }

            bool renderingFinished = handleRender(
                reinterpret_cast<uint8_t*>(data) + sizeof(WinHeader),
                size - sizeof(WinHeader)
            );

            if (renderingFinished) {
                m_renderContext.finish();
                m_rendering = false;
            }

            break;
        }
    }

    return 0;
}
Beispiel #7
0
Window::Window(QApplication *app, const int &x, const int &y, const int &width, const int &height) {
	_hwnd =
		CreateWindow(
		registerWindow().c_str(),
		NULL,
		static_cast<DWORD>(Style::BorderLess),
		x, y, width, height,
		0, 0,
		(HINSTANCE)GetModuleHandle(0),
		NULL);
	if (!_hwnd) throw std::runtime_error("Failed To Create Window");

	SetWindowLongPtr(_hwnd, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(this));

	SetWindowPos(_hwnd, NULL, 0, 0, 0, 0, SWP_FRAMECHANGED | SWP_NOMOVE | SWP_NOSIZE);

	_app = app;

	setNcHeight(36);
	removeBorder();
	show();
}
Beispiel #8
0
ShellWindow::ShellWindow(QWaylandSurface *surface, QObject *parent)
    : QObject(parent)
    , m_role(UnknownRole)
    , m_flags(0)
    , m_compositor(static_cast<Compositor *>(surface->compositor()))
    , m_surface(surface)
{
    qRegisterMetaType<ShellWindow *>("ShellWindow*");

    // Identifier
    m_id++;

    // Create view
    m_view = new QWaylandSurfaceItem(static_cast<QWaylandQuickSurface *>(surface));

    // Connect to surface signals
    connect(surface, &QWaylandSurface::mapped, [=] {
        registerWindow();
    });
    connect(surface, &QWaylandSurface::unmapped, [=] {
        unregisterWindow(false);
    });
}
Beispiel #9
0
//private
void MyFirstState::setup()
{
    auto& mb = xy::App::getActiveInstance()->getMessageBus();

    m_scene.addSystem<xy::ParticleSystem>(mb);
    m_scene.addSystem<xy::CallbackSystem>(mb);
    m_scene.addSystem<xy::RenderSystem>(mb);

    auto entity = m_scene.createEntity();
    entity.addComponent<xy::Transform>().setPosition(xy::DefaultSceneSize / 2.f);
    entity.getComponent<xy::Transform>().move(100.f, 0.f);
    entity.addComponent<xy::ParticleEmitter>().start();
    m_emitterSettings = &entity.getComponent<xy::ParticleEmitter>().settings;
    entity.addComponent<sf::Vector2f>() = {0.707f, 0.707f};
    entity.addComponent<xy::Callback>().function = 
        [](xy::Entity e, float dt)
    {
        const float Speed = 400.f;
        auto vel = e.getComponent<sf::Vector2f>();
        auto& tx = e.getComponent<xy::Transform>();
        tx.move(vel * Speed * dt);

        auto pos = tx.getPosition();
        if (pos.x > xy::DefaultSceneSize.x)
        {
            vel = xy::Util::Vector::reflect(vel, { -1.f, 0.f });
            e.getComponent<sf::Vector2f>() = vel;
            pos.x = xy::DefaultSceneSize.x;
            tx.setPosition(pos);
            tx.setRotation(xy::Util::Vector::rotation(vel));
        }
        else if (pos.x < 0.f)
        {
            vel = xy::Util::Vector::reflect(vel, { 1.f, 0.f });
            e.getComponent<sf::Vector2f>() = vel;
            pos.x = 0.f;
            tx.setPosition(pos);
            tx.setRotation(xy::Util::Vector::rotation(vel));
        }

        if (pos.y < 0.f)
        {
            vel = xy::Util::Vector::reflect(vel, { 0.f, 1.f });
            e.getComponent<sf::Vector2f>() = vel;
            pos.y = 0.f;
            tx.setPosition(pos);
            tx.setRotation(xy::Util::Vector::rotation(vel));
        }
        else if (pos.y > xy::DefaultSceneSize.y)
        {
            vel = xy::Util::Vector::reflect(vel, { 0.f, -1.f });
            e.getComponent<sf::Vector2f>() = vel;
            pos.y = xy::DefaultSceneSize.y;
            tx.setPosition(pos);
            tx.setRotation(xy::Util::Vector::rotation(vel));
        }
    };

    auto& verts = entity.addComponent<xy::Drawable>().getVertices();
    verts.emplace_back(sf::Vector2f(0.f, -12.f), sf::Color::Green);
    verts.emplace_back(sf::Vector2f(12.f, 0.f), sf::Color::Green);
    verts.emplace_back(sf::Vector2f(0.f, 12.f), sf::Color::Green);
    entity.getComponent<xy::Drawable>().setPrimitiveType(sf::LineStrip);
    entity.getComponent<xy::Drawable>().updateLocalBounds();

    auto windowFunc = [&, entity]() mutable
    {
        xy::Nim::setNextWindowSize(WindowWidth, WindowHeight);
        xy::Nim::setNextWindowConstraints(WindowWidth, WindowHeight, WindowWidth, WindowHeight);
        xy::Nim::begin("Emitter Settings");

        bool load = false;
        bool save = false;

        if (xy::Nim::beginMenuBar())
        {
            if (xy::Nim::beginMenu("File"))
            {
                xy::Nim::menuItem("Load", load);
                xy::Nim::menuItem("Save", save);

                xy::Nim::endMenu();
            }

            xy::Nim::endMenuBar();
        }

        xy::Nim::text(m_workingDirectory);
        if (xy::Nim::button("Browse Path"))
        {
            auto path = xy::FileSystem::openFolderDialogue();
            if (!path.empty())
            {
                m_workingDirectory = path;

                //try trimming the loaded texture path
                if (!m_emitterSettings->texturePath.empty())
                {
                    if (m_emitterSettings->texturePath.find(path) != std::string::npos)
                    {
                        m_emitterSettings->texturePath = m_emitterSettings->texturePath.substr(path.size());
                    }
                }
            }
        }
        xy::Nim::sameLine(); xy::Nim::showToolTip("Current working directory. Set this to your project directory and textures will be loaded and saved in a path relative to this");
        xy::Nim::separator();

        xy::Nim::slider("Gravity X", m_emitterSettings->gravity.x, -1000.f, 1000.f, ItemWidth);
        xy::Nim::sameLine(); xy::Nim::showToolTip("Gravitational force applied to the velocity");
        xy::Nim::slider("Gravity Y", m_emitterSettings->gravity.y, -1000.f, 1000.f, ItemWidth);
        
        xy::Nim::slider("Velocity X", m_emitterSettings->initialVelocity.x, -1000.f, 1000.f, ItemWidth);
        xy::Nim::sameLine(); xy::Nim::showToolTip("Initial velocity of the particle");
        xy::Nim::slider("Velocity Y", m_emitterSettings->initialVelocity.y, -1000.f, 1000.f, ItemWidth);

        xy::Nim::slider("Spread", m_emitterSettings->spread, 0.f, 360.f, ItemWidth);
        xy::Nim::sameLine(); xy::Nim::showToolTip("Spead, in degrees, applied to the inital velocity");
        xy::Nim::slider("Lifetime", m_emitterSettings->lifetime, 0.1f, 10.f, ItemWidth);
        xy::Nim::sameLine(); xy::Nim::showToolTip("Lifetime of a particle in seconds");
        xy::Nim::slider("Lifetime Variance", m_emitterSettings->lifetimeVariance, 0.f, 10.f, ItemWidth);
        xy::Nim::sameLine(); xy::Nim::showToolTip("Amount of random variation added to the lifetime of a particle, in seconds");

        xy::Nim::slider("Rotation Speed", m_emitterSettings->rotationSpeed, 0.f, 15.f, ItemWidth);
        xy::Nim::sameLine(); xy::Nim::showToolTip("Rotation in degrees per second - textured particles only");
        xy::Nim::slider("Scale Affector", m_emitterSettings->scaleModifier, -5.f, 5.f, ItemWidth);
        xy::Nim::sameLine(); xy::Nim::showToolTip("How rapidly a particle is scaled in size over its lifetime");
        xy::Nim::slider("Size", m_emitterSettings->size, 0.1f, 100.f, ItemWidth);
        xy::Nim::sameLine(); xy::Nim::showToolTip("Initial size of a particle");

        xy::Nim::slider("Emit Rate", m_emitterSettings->emitRate, 0.f, 150.f, ItemWidth);
        xy::Nim::sameLine(); xy::Nim::showToolTip("Number of particles emitted per second");
        std::int32_t count = m_emitterSettings->emitCount;
        xy::Nim::input("Emit Count", count, ItemWidth);
        xy::Nim::sameLine(); xy::Nim::showToolTip("Number of particles emitted simultaneously");
        count = std::max(count, 0);
        m_emitterSettings->emitCount = count;

        xy::Nim::slider("Spawn Radius", m_emitterSettings->spawnRadius, 0.f, 500.f, ItemWidth);
        xy::Nim::sameLine(); xy::Nim::showToolTip("Radius around the emitter position in which particles are spawned");
        xy::Nim::slider("Spawn Offset X", m_emitterSettings->spawnOffset.x, 0.f, 500.f, ItemWidth);
        xy::Nim::sameLine(); xy::Nim::showToolTip("Offsets the particle spawn position from the emitter position in world units");
        xy::Nim::slider("Spawn Offset Y", m_emitterSettings->spawnOffset.y, 0.f, 500.f, ItemWidth);

        count = m_emitterSettings->releaseCount;
        xy::Nim::input("Release Count", count, ItemWidth);
        xy::Nim::sameLine(); xy::Nim::showToolTip("Total number of particles to release before automatically stopping the emitter. 0 emits indefinitely, restart the emitter for updated values to take effect");
        count = std::max(count, 0);
        m_emitterSettings->releaseCount = count;

        xy::Nim::checkbox("Random Initial Rotation", &m_emitterSettings->randomInitialRotation);
        xy::Nim::sameLine(); xy::Nim::showToolTip("Applies a random initial rotation to spawned particles. Textured particles only");
        
        bool oldState = entity.getComponent<xy::Callback>().active;
        bool newState = oldState;
        xy::Nim::checkbox("Animate Movement", &newState);
        xy::Nim::sameLine(); xy::Nim::showToolTip("Enable emitter movement");

        if (oldState != newState)
        {
            entity.getComponent<xy::Callback>().active = newState;
            float rotation = newState ? xy::Util::Vector::rotation(entity.getComponent<sf::Vector2f>()) : 0.f;
            entity.getComponent<xy::Transform>().setRotation(rotation);
        }

        xy::Nim::colourPicker("Colour", m_emitterSettings->colour);

        xy::Nim::separator();

        //blendmode drop down
        std::int32_t idx = m_selectedBlendMode;
        xy::Nim::simpleCombo("Blend Mode", idx, "Alpha\0Add\0Multiply\0\0", ItemWidth);
        if (idx != m_selectedBlendMode)
        {
            m_selectedBlendMode = idx;
            switch (idx)
            {
            case 0:
                m_emitterSettings->blendmode = sf::BlendAlpha;
                break;
            case 1:
                m_emitterSettings->blendmode = sf::BlendAdd;
                break;
            case 2:
                m_emitterSettings->blendmode = sf::BlendMultiply;
            }
        }
        if (m_emitterSettings->texturePath.empty())
        {
            xy::Nim::text("No texture loaded");
        }
        else
        {
            xy::Nim::text(m_emitterSettings->texturePath);
        }

        if (xy::Nim::button("Browse Texture"))
        {
            auto path = xy::FileSystem::openFileDialogue("png,jpg,bmp");
            if (!path.empty())
            {
                m_emitterSettings->texture = &m_textures.get(path);

                //try correcting with current working directory
                if (!m_workingDirectory.empty())
                {
                    if (path.find(m_workingDirectory) != std::string::npos)
                    {
                        path = path.substr(m_workingDirectory.size());
                    }
                }
                m_emitterSettings->texturePath = path;
            }
        }
        xy::Nim::sameLine(); xy::Nim::showToolTip("For a relative path to a texture set the working directory, above");

        xy::Nim::separator();

        if (xy::Nim::button("Start"))
        {
            entity.getComponent<xy::ParticleEmitter>().start();
        }
        xy::Nim::sameLine();
        if (xy::Nim::button("Stop"))
        {
            entity.getComponent<xy::ParticleEmitter>().stop();
        }
        xy::Nim::sameLine();
        if (xy::Nim::button("Reset"))
        {
            entity.getComponent<xy::ParticleEmitter>().settings = xy::EmitterSettings();
            entity.getComponent<xy::Callback>().active = false;
            entity.getComponent<xy::Transform>().setPosition(xy::DefaultSceneSize / 2.f);
            entity.getComponent<xy::Transform>().setRotation(0.f);
        }
        xy::Nim::sameLine(); xy::Nim::showToolTip("Reset the properties to their default values");

        xy::Nim::separator();

        //load button
        //save button
        if (load)
        {
            auto path = xy::FileSystem::openFileDialogue("xyp");
            if (!path.empty())
            {
                entity.getComponent<xy::ParticleEmitter>().settings = xy::EmitterSettings();
                m_textures.setFallbackColour(sf::Color::White);
                m_emitterSettings->loadFromFile(path, m_textures);
                {
                    if (m_workingDirectory.empty())
                    {
                        xy::Logger::log("Working directory not set, textures may not be loaded");
                    }
                    else if(!m_emitterSettings->texturePath.empty())
                    {
                        xy::Logger::log("Trying to correct for texture path...");
                        auto texPath = m_workingDirectory;
                        std::replace(texPath.begin(), texPath.end(), '\\', '/');
                        if (texPath.back() != '/')
                        {
                            texPath += "/";
                        }
                        texPath += m_emitterSettings->texturePath;
                        m_emitterSettings->texture = &m_textures.get(texPath);
                    }
                }
                entity.getComponent<xy::ParticleEmitter>().stop();
            }
        }

        if (save)
        {
            auto path = xy::FileSystem::saveFileDialogue("xyp");
            if (!path.empty())
            {
                if (xy::FileSystem::getFileExtension(path) != ".xyp")
                {
                    path += ".xyp";
                }
                m_emitterSettings->saveToFile(path);
            }
        }

        xy::Nim::end();
    };
    registerWindow(windowFunc);
}