bool PreflatePredictorState::createMatchHelper(
    MatchHelper& helper,
    const unsigned prevLen,
    const unsigned startPos,
    const bool veryFarMatches,
    const bool matchesToStart,
    const unsigned maxDepth) {
  helper.maxLen = std::min(totalInputSize() - startPos, (unsigned)PreflateConstants::MAX_MATCH);
  if (helper.maxLen < std::max<uint32_t>(prevLen + 1, PreflateConstants::MIN_MATCH)) {
    return false;
  }
  helper.startPos = startPos;
  unsigned maxDistToStart = startPos - (matchesToStart ? 0 : 1);
  if (veryFarMatches) {
    helper.curMaxDistHop1Plus
      = helper.curMaxDistHop0
      = std::min(maxDistToStart, windowSize());
  } else {
    unsigned maxDist = windowSize() - PreflateConstants::MIN_LOOKAHEAD;
    helper.curMaxDistHop0 = std::min(maxDistToStart, maxDist);
    helper.curMaxDistHop1Plus = std::min(maxDistToStart, maxDist - 1);
  }
  if (maxDepth > 0) {
    helper.maxChain = maxDepth;
    helper.niceLen = helper.maxLen;
  } else {
    helper.maxChain = maxChainLength();/* max hash chain length */
    helper.niceLen = std::min(niceMatchLength(), helper.maxLen);

    if (prevLen >= goodMatchLength()) {
      helper.maxChain >>= 2;
    }
  }
/******************************************************************************
* Renders the image in a rectangle given in viewport coordinates.
******************************************************************************/
void DefaultImagePrimitive::renderViewport(SceneRenderer* renderer, const Point2& pos, const Vector2& size)
{
	QSize imageSize = renderer->outputSize();
	Point2 windowPos((pos.x() + 1.0f) * imageSize.width() / 2, (-(pos.y() + size.y()) + 1.0) * imageSize.height() / 2);
	Vector2 windowSize(size.x() * imageSize.width() / 2, size.y() * imageSize.height() / 2);
	renderWindow(renderer, windowPos, windowSize);
}
void LayeredLayout::updateLayout(const MFUnrecComponentPtr* Components, const Component* ParentComponent) const
{
    Pnt2f windowTopLeft, windowBottomRight;
    dynamic_cast<const ComponentContainer*>(ParentComponent)->getInsideInsetsBounds(windowTopLeft, windowBottomRight);
    Vec2f windowSize(windowBottomRight-windowTopLeft);

    int maxX = 0;
    int maxY = 0;
    for(UInt32 i = 0; i < Components->size(); i++){
        (*Components)[i]->setSize(windowSize);
        if((*Components)[i]->getSize().x()>maxX)
            maxX = (*Components)[i]->getSize().x();
        if((*Components)[i]->getSize().y()>maxY)
            maxY = (*Components)[i]->getSize().y();
    }
    //overlay layout simply draws all the components on top of each other, with the reference point for all the components being the same
    /*for(UInt32 i = 0; i <Components->size(); i++){
    //(*Components)[i]->setSize((*Components)[i]->getPreferredSize());
    (*Components)[i]->setPosition(borderTopLeft + 
    Vec2f((maxX-(*Components)[i]->getSize().x())/2.0,
    (maxY-(*Components)[i]->getSize().y())/2.0));
    }*/
    for(UInt32 i = 0; i <Components->size(); i++){
        //(*Components)[i]->setSize((*Components)[i]->getPreferredSize());
        (*Components)[i]->setPosition(windowTopLeft);
    }
}
示例#4
0
		void CScrollHelper::UpdateScrollInfo()
		{
			if (m_attachWnd == nullptr)
				return;

			// Get the width/height of the attached wnd that includes the area
			// covered by the scrollbars (if any). The reason we need this is
			// because when scrollbars are present, both cx/cy and GetClientRect()
			// when accessed from OnSize() do not include the scrollbar covered
			// areas. In other words, their values are smaller than what you would
			// expect.
			CRect rect;
			GetClientRectSB(m_attachWnd, rect);
			CSize windowSize(rect.Width(), rect.Height());

			// Update horizontal scrollbar.
			CSize deltaPos(0, 0);
			UpdateScrollBar(SB_HORZ, windowSize.cx, m_displaySize.cx,
							m_pageSize.cx, m_scrollPos.cx, deltaPos.cx);

			// Update vertical scrollbar.
			UpdateScrollBar(SB_VERT, windowSize.cy, m_displaySize.cy,
							m_pageSize.cy, m_scrollPos.cy, deltaPos.cy);

			// See if we need to scroll the window back in place.
			// This is needed to handle the case where the scrollbar is
			// moved all the way to the right for example, and controls
			// at the left side disappear from the view. Then the user
			// resizes the window wider until scrollbars disappear. Without
			// this code below, the controls off the page will be gone forever.
			if (deltaPos.cx != 0 || deltaPos.cy != 0) {
				m_attachWnd->ScrollWindow(deltaPos.cx, deltaPos.cy);
			}
		}
示例#5
0
文件: run.cpp 项目: trtikm/E2
void run()
{
    TMPROF_BLOCK();

    int argc = 1;
    char* argv[] = { "" };
    QGuiApplication app(argc, argv);

    QScreen *screen = QGuiApplication::primaryScreen();
    QRect screenGeometry = screen->availableGeometry();
    QPoint center = QPoint(screenGeometry.center().x(), screenGeometry.top() + 80);
    QSize windowSize(400, 320);
    int delta = 40;

    QList<QWindow *> windows;
    xqtgl::window *windowA = new xqtgl::window(&init,&step,&draw,&fini);
    windowA->setGeometry(QRect(center, windowSize).translated(-windowSize.width() - delta / 2, 0));
    windowA->setTitle(QStringLiteral("Window"));
    windowA->setVisible(true);
    windows.prepend(windowA);

    app.exec();

    qDeleteAll(windows);

}
示例#6
0
void IrrWidget::createIrrlichtDevice(){
    dimension2d<u32> windowSize(this->geometry().width(), this->geometry().height());

    SIrrlichtCreationParameters createParams;
    createParams.WindowId = (void*)this->winId();
    createParams.WindowSize = windowSize;
    createParams.DriverType = EDT_OPENGL;
    createParams.Stencilbuffer = true;
    createParams.Vsync = false;

    m_pDevice = createDeviceEx(createParams);
    if(m_pDevice == NULL){
        qDebug() << "failed to create irrlicht device";
    }
    m_pDevice->setResizable(true);
    m_pScene = m_pDevice->getSceneManager();
    m_pDriver = m_pDevice->getVideoDriver();

    scene::IAnimatedMesh* mesh = m_pScene->getMesh("./media/sydney.md2");
    if(mesh == NULL){
        return;
    }
    scene::IAnimatedMeshSceneNode* node = m_pScene->addAnimatedMeshSceneNode(mesh);
    if(node !=NULL){
        node->setMaterialFlag(EMF_LIGHTING, false);
        node->setMD2Animation(scene::EMAT_STAND);
        node->setMaterialTexture(0, m_pDriver->getTexture("./media/sydney.bmp"));
    }
    m_pScene->addCameraSceneNode(0, vector3df(0,30,-40), vector3df(0,5,0));

}
示例#7
0
/* set up the plotter and the params */
plPlotter* setUp() {
	plPlotter* plotter;
	plPlotterParams* plotterParams;

	/* create a plotter parametric structure */
	plotterParams = pl_newplparams();
	pl_setplparam(plotterParams, "BITMAPSIZE", "750x750");
	pl_setplparam(plotterParams, "USE_DOUBLE_BUFFERING", "no");
	pl_setplparam(plotterParams, "BG_COLOR", "black");

	/* create the plotter device and open it */
	if((plotter = pl_newpl_r("X", stdin, stdout, stderr, plotterParams)) == NULL) {
		fprintf(stderr, "Couldn't create Xwindows plotter\n");
		exit(1);
	} else if(pl_openpl_r(plotter) < 0) {
		fprintf(stderr, "Couldn't open Xwindows plotter\n");
		exit(1);
	}

	/* set our coordinate space in the plotter window */
	double winSize = windowSize(PLANETS);
	pl_fspace_r(plotter, -winSize, -winSize, winSize, winSize);

	/* pick a type for the pen and the fill */
	pl_pentype_r(plotter, 1);
	pl_filltype_r(plotter, 1);

	return plotter;

}
示例#8
0
文件: ide.cpp 项目: kkodali/apkstudio
void Ide::onInit()
{
    auto p = Preferences::get();
    if (p->wasWindowMaximized())
    {
        showMaximized();
    }
    else
    {
        resize(p->windowSize());
    }
    addDockWidget(Qt::LeftDockWidgetArea, new ProjectDock(this));
    auto java = new JavaDock(this);
    addDockWidget(Qt::BottomDockWidgetArea, java);
    auto zipAlign = new ZipAlignDock(this);
    addDockWidget(Qt::BottomDockWidgetArea, zipAlign);
    tabifyDockWidget(java, zipAlign);
    auto jarSigner = new JarSignerDock(this);
    addDockWidget(Qt::BottomDockWidgetArea, jarSigner);
    tabifyDockWidget(zipAlign, jarSigner);
    auto adb = new AdbDock(this);
    addDockWidget(Qt::BottomDockWidgetArea, adb);
    tabifyDockWidget(jarSigner, adb);
    restoreState(p->docksState());
}
示例#9
0
Channels Frequency::split(Channel a,std::vector<float> cutoff,float width,bool fade)
{
	Channels target(cutoff.size()+1);
	unsigned i;
	for(i=0;i<cutoff.size();i++)
	{
		Channels temp=split(a,cutoff[i],width,false);
		target[i]=temp[0];
		a=temp[1];
		/*temp=split(a,cutoff[i]);
		for(unsigned j=0;j<a.size();j++)
			target[i][j]+=temp[0][j];
		a=temp[1];*/
		if(fade)
		{
			unsigned N=windowSize(a,cutoff[i],width);
			for(unsigned j=0;j<N*2 && j<target[i].size();j++)
			{
				double f=(double(j)-N)/N;
				if(f<0)
					f=0;

				target[i][j]*=f;
				target[i][target[i].size()-1-j]*=f;
			}
		}
	}
	target[i]=a;


	//Wave::save("bands.wav",target);

	return target;
}
PauseState::PauseState(StateStack& stack, Context context)
: State(stack, context)
, mBackgroundSprite()
, mPausedText()
, mGUIContainer()
{
	sf::Font& font = context.fonts->get(Fonts::Main);
	sf::Vector2f windowSize(context.window->getSize());

	mPausedText.setFont(font);
	mPausedText.setString("Game Paused");	
	mPausedText.setCharacterSize(70);
	centerOrigin(mPausedText);
	mPausedText.setPosition(0.5f * windowSize.x, 0.4f * windowSize.y);

	auto returnButton = std::make_shared<GUI::Button>(*context.fonts, *context.textures);
	returnButton->setPosition(0.5f * windowSize.x - 100, 0.4f * windowSize.y + 75);
	returnButton->setText("Return");
	returnButton->setCallback([this] ()
	{
		requestStackPop();
	});

	auto backToMenuButton = std::make_shared<GUI::Button>(*context.fonts, *context.textures);
	backToMenuButton->setPosition(0.5f * windowSize.x - 100, 0.4f * windowSize.y + 125);
	backToMenuButton->setText("Back to menu");
	backToMenuButton->setCallback([this] ()
	{
		requestStateClear();
		requestStackPush(States::Menu);
	});

	mGUIContainer.pack(returnButton);
	mGUIContainer.pack(backToMenuButton);
}
void TextAutosizer::updatePageInfo()
{
    if (m_updatePageInfoDeferred || !m_document->page() || !m_document->settings())
        return;

    PageInfo previousPageInfo(m_pageInfo);
    m_pageInfo.m_settingEnabled = m_document->settings()->textAutosizingEnabled();

    if (!m_pageInfo.m_settingEnabled || m_document->printing()) {
        m_pageInfo.m_pageNeedsAutosizing = false;
    } else {
        LayoutView* layoutView = m_document->layoutView();
        bool horizontalWritingMode = isHorizontalWritingMode(layoutView->style()->writingMode());

        // FIXME: With out-of-process iframes, the top frame can be remote and
        // doesn't have sizing information. Just return if this is the case.
        Frame* frame = m_document->frame()->tree().top();
        if (frame->isRemoteFrame())
            return;

        LocalFrame* mainFrame = toLocalFrame(frame);
        IntSize frameSize = m_document->settings()->textAutosizingWindowSizeOverride();
        if (frameSize.isEmpty())
            frameSize = windowSize();

        m_pageInfo.m_frameWidth = horizontalWritingMode ? frameSize.width() : frameSize.height();

        IntSize layoutSize = mainFrame->view()->layoutSize();
        m_pageInfo.m_layoutWidth = horizontalWritingMode ? layoutSize.width() : layoutSize.height();

        // Compute the base font scale multiplier based on device and accessibility settings.
        m_pageInfo.m_baseMultiplier = m_document->settings()->accessibilityFontScaleFactor();
        // If the page has a meta viewport or @viewport, don't apply the device scale adjustment.
        const ViewportDescription& viewportDescription = mainFrame->document()->viewportDescription();
        if (!viewportDescription.isSpecifiedByAuthor()) {
            float deviceScaleAdjustment = m_document->settings()->deviceScaleAdjustment();
            m_pageInfo.m_baseMultiplier *= deviceScaleAdjustment;
        }

        m_pageInfo.m_pageNeedsAutosizing = !!m_pageInfo.m_frameWidth
            && (m_pageInfo.m_baseMultiplier * (static_cast<float>(m_pageInfo.m_layoutWidth) / m_pageInfo.m_frameWidth) > 1.0f);
    }

    if (m_pageInfo.m_pageNeedsAutosizing) {
        // If page info has changed, multipliers may have changed. Force a layout to recompute them.
        if (m_pageInfo.m_frameWidth != previousPageInfo.m_frameWidth
            || m_pageInfo.m_layoutWidth != previousPageInfo.m_layoutWidth
            || m_pageInfo.m_baseMultiplier != previousPageInfo.m_baseMultiplier
            || m_pageInfo.m_settingEnabled != previousPageInfo.m_settingEnabled)
            setAllTextNeedsLayout();
    } else if (previousPageInfo.m_hasAutosized) {
        // If we are no longer autosizing the page, we won't do anything during the next layout.
        // Set all the multipliers back to 1 now.
        resetMultipliers();
        m_pageInfo.m_hasAutosized = false;
    }
}
示例#12
0
 void GLFW_App::init()
 {
     // Initialize GLFW
     if( !glfwInit() )
     {
         throw Exception("GLFW failed to initialize");
     }
     
     int num_color_bits = 8;
     
     //TODO: find out why this is necessary for smooth gradients
     glfwWindowHint(GLFW_RED_BITS, num_color_bits);
     glfwWindowHint(GLFW_GREEN_BITS, num_color_bits);
     glfwWindowHint(GLFW_BLUE_BITS, num_color_bits);
     
     // request an OpenGl 4.1 Context
     glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
     glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 1);
     glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
     glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
     glfwWindowHint(GLFW_SAMPLES, 4);
     
     // create the window
     addWindow(GLFW_Window::create(getWidth(), getHeight(), getName(), fullSceen()));
     gl::setWindowDimension(windowSize());
     
     // set graphical log stream
     Logger::get()->add_outstream(&m_outstream_gl);
     
     // version
     LOG_INFO<<"OpenGL: " << glGetString(GL_VERSION);
     LOG_INFO<<"GLSL: " << glGetString(GL_SHADING_LANGUAGE_VERSION);
     
     glfwSwapInterval(1);
     glClearColor(0, 0, 0, 1);
     
     // file search paths
     kinski::addSearchPath(".", true);
     kinski::addSearchPath("./res", true);
     kinski::addSearchPath("../Resources", true);
     
     //---------------------------------
     #ifdef KINSKI_MAC
     kinski::addSearchPath("/Library/Fonts");
     kinski::addSearchPath("~/Library/Fonts");
     #endif
     //---------------------------------
     
     // AntTweakbar
     TwInit(TW_OPENGL_CORE, NULL);
     TwWindowSize(getWidth(), getHeight());
     
     // call user defined setup callback
     setup();
 }
示例#13
0
void Purity::Engine::initializeWindow()
{
    Vector2i windowSize(Configuration::getInstance()->getInteger("window", "window_size_x", 800),
                        Configuration::getInstance()->getInteger("window", "window_size_y", 400));

#ifdef _WIN32
    mWindow = std::unique_ptr<Purity::Window>(new Purity::Win32Window(windowSize.x, windowSize.y, "Purity2D"));
#else
    mWindow = std::unique_ptr<Purity::Window>(new Purity::Window(windowSize.x, windowSize.y, "Purity2D"));
#endif
}
void PreflateCompLevelEstimatorState::recommend() {
  info.recommendedCompressionLevel = 9;
  info.veryFarMatches = !(info.longestDistAtHop0 <= windowSize() - PreflateConstants::MIN_LOOKAHEAD
                          && info.longestDistAtHop1Plus < windowSize() - PreflateConstants::MIN_LOOKAHEAD);
  info.farLen3Matches = info.longestLen3Dist > 4096;

  info.zlibCompatible = info.possibleCompressionLevels > 1
                        && !info.matchToStart
                        && !info.veryFarMatches
                        && (!info.farLen3Matches || (info.possibleCompressionLevels & 0xe) != 0);
  if (info.unfoundReferences) {
    return;
  }

  if (info.zlibCompatible && info.possibleCompressionLevels > 1) {
    unsigned l = info.possibleCompressionLevels >> 1;
    info.recommendedCompressionLevel = 1;
    while ((l & 1) == 0) {
      info.recommendedCompressionLevel++;
      l >>= 1;
    }
    return;
  }
示例#15
0
PlayState::PlayState(StateStack& stack, Context context) : State(stack, context), mGUIContainer() {
	sf::Texture& texture = context.textures->get(Textures::TitleScreen);
	mBackgroundSprite.setTexture(texture);
	sf::Vector2f windowSize(context.window->getSize());

	auto playButton = std::make_shared<GUI::Button>(context);
	playButton->setPosition(0.4f * windowSize.x, 0.3f * windowSize.y);
	playButton->setText("New Game");
	playButton->setCallback([this]() {
		requestStackPop();
		requestStackPush(States::Game);
	});

	auto LevelButton = std::make_shared<GUI::Button>(context);
	LevelButton->setPosition(0.4f * windowSize.x, 0.4f * windowSize.y);
	LevelButton->setText("Select Level");
	LevelButton->setCallback([this]() {
		requestStackPush(States::LevelSelect);
	});

	auto UpgradesButton = std::make_shared<GUI::Button>(context);
	UpgradesButton->setPosition(0.4f * windowSize.x, 0.5f * windowSize.y);
	UpgradesButton->setText("Ship Modifications");
	UpgradesButton->setCallback([this]() {
		requestStackPush(States::Upgrade);
	});

	auto LeaderBButton = std::make_shared<GUI::Button>(context);
	LeaderBButton->setPosition(0.4f * windowSize.x, 0.6f * windowSize.y);
	LeaderBButton->setText("Leaderboards");
	LeaderBButton->setCallback([this]() {
		requestStackPush(States::Leader);
	});


	auto backButton = std::make_shared<GUI::Button>(context);
	backButton->setPosition(0.4f * windowSize.x, 0.8f * windowSize.y);
	backButton->setText("Back");
	backButton->setCallback([this]() {
		requestStackPop();
		requestStackPush(States::Menu);
	});

	mGUIContainer.pack(playButton);
	mGUIContainer.pack(LevelButton);
	mGUIContainer.pack(UpgradesButton);
	mGUIContainer.pack(LeaderBButton);
	mGUIContainer.pack(backButton);
}
unsigned short PreflateCompLevelEstimatorState::matchDepth(
  const unsigned hashHead,
  const PreflateToken& targetReference,
  const PreflateHashChainExt& hash) {
  unsigned curPos = hash.input().pos();
  unsigned curMaxDist = std::min(curPos, windowSize());

  unsigned startDepth = hash.getNodeDepth(hashHead);
  PreflateHashIterator chainIt = hash.iterateFromPos(curPos - targetReference.dist, curPos, curMaxDist);
  if (!chainIt.curPos || targetReference.dist > curMaxDist) {
    return 0xffffu;
  }
  unsigned endDepth = chainIt.depth();
  return std::min(startDepth - endDepth, 0xffffu);
}
示例#17
0
void IrrWidget::createIrrlichtDevice(){
    dimension2d<u32> windowSize(this->geometry().width(), this->geometry().height());

    SIrrlichtCreationParameters createParams;
    createParams.WindowId = (void*)this->winId();
    createParams.WindowSize = windowSize;
    createParams.DriverType = EDT_OPENGL;
    createParams.Stencilbuffer = true;
    createParams.Vsync = false;

    m_pDevice = createDeviceEx(createParams);
    if(m_pDevice == NULL){
        qDebug() << "failed to create irrlicht device";
    }
    m_pDevice->setResizable(true);
    m_pScene = m_pDevice->getSceneManager();
    m_pDriver = m_pDevice->getVideoDriver();
    m_pGuiEnv = m_pDevice->getGUIEnvironment();

    m_pBufferList = m_pGuiEnv->addListBox(core::rect<int>(5,5,200, 400), 0, true, true);
        //gui::IGUITab* optTab = tabctrl->addTab(L"Demo");
        //gui::IGUITab* aboutTab = tabctrl->addTab(L"About");

        // add list box

        //gui::IGUIListBox* box = m_pGuiEnv->addListBox(core::rect<int>(10,10,220,120), optTab, 1);
        m_pBufferList->addItem(L"OpenGL 1.5");
        m_pBufferList->addItem(L"Direct3D 8.1");
        m_pBufferList->addItem(L"Direct3D 9.0c");
        m_pBufferList->addItem(L"Burning's Video 0.47");
        m_pBufferList->addItem(L"Irrlicht Software Renderer 1.0");
        m_pBufferList->setSelected(true);

    scene::IAnimatedMesh* mesh = m_pScene->getMesh("./media/sydney.md2");
    if(mesh == NULL){
        return;
    }
    scene::IAnimatedMeshSceneNode* node = m_pScene->addAnimatedMeshSceneNode(mesh);
    if(node !=NULL){
        node->setMaterialFlag(EMF_LIGHTING, false);
        node->setMD2Animation(scene::EMAT_STAND);
        node->setMaterialTexture(0, m_pDriver->getTexture("./media/sydney.bmp"));
    }
    m_pScene->addCameraSceneNode(0, vector3df(0,30,-40), vector3df(0,5,0));
    //m_pDevice->setEventReceiver(new IrrEventReciever());
}
示例#18
0
void
UiSettings::loadSettings()
{
    QSettings s( "CS224", "snow" );

    windowPosition() = s.value( "windowPosition", QPoint(0,0) ).toPoint();
    windowSize() = s.value( "windowSize", QSize(1000,800) ).toSize();

    fillNumParticles() = s.value( "fillNumParticles", 512*128 ).toInt();
    fillResolution() = s.value( "fillResolution", 0.05f ).toFloat();
    fillDensity() = s.value( "fillDensity", 150.f ).toFloat();

    exportDensity() = s.value("exportDensity", false).toBool();
    exportVelocity() = s.value("exportVelocity", false).toBool();

    exportFPS() = s.value("exportFPS", 24).toInt();
    maxTime() = s.value("maxTime", 3).toFloat();

    gridPosition() = vec3( s.value("gridPositionX", 0.f).toFloat(),
                           s.value("gridPositionY", 0.f).toFloat(),
                           s.value("gridPositionZ", 0.f).toFloat() );


    gridDimensions() = glm::ivec3( s.value("gridDimensionX", 128).toInt(),
                                   s.value("gridDimensionY", 128).toInt(),
                                   s.value("gridDimensionZ", 128).toInt() );

    gridResolution() = s.value( "gridResolution", 0.05f ).toFloat();

    timeStep() = s.value( "timeStep", 1e-5 ).toFloat();
    implicit() = s.value( "implicit", true ).toBool();
    materialPreset() = s.value( "materialPreset", MAT_DEFAULT).toInt();

    showContainers() = s.value( "showContainers", true ).toBool();
    showContainersMode() = s.value( "showContainersMode", WIREFRAME ).toInt();
    showColliders() = s.value( "showColliders", true ).toBool();
    showCollidersMode() = s.value( "showCollidersMode", SOLID ).toInt();
    showGrid() = s.value( "showGrid", false ).toBool();
    showGridMode() = s.value( "showGridMode", MIN_FACE_CELLS ).toInt();
    showGridData() = s.value( "showGridData", false ).toBool();
    showGridDataMode() = s.value( "showGridDataMode", NODE_DENSITY ).toInt();
    showParticles() = s.value( "showParticles", true ).toBool();
    showParticlesMode() = s.value( "showParticlesMode", PARTICLE_MASS ).toInt();

    selectionColor() = glm::vec4( 0.302f, 0.773f, 0.839f, 1.f );
}
示例#19
0
void LevelSelectState::buildLevelPanel(){

    sf::Vector2f windowSize(getContext().window->getSize());
    sf::Texture &bgPanelTexture = getContext().textureManager->get(TextureID::LevelSelectionPanel);
    mLevelPanel = sf::Sprite(bgPanelTexture);
    mLevelPanel.setOrigin(sf::Vector2f(
        mLevelPanel.getGlobalBounds().width / 2,
        mLevelPanel.getGlobalBounds().height / 2));
    mLevelPanel.setPosition(windowSize * 0.5f);
    mLevelPanel.setColor(sf::Color(255, 255, 255, 100));

    //Set a centered view for our level display panel to handle
    //overflowing levels and scrolling down
    sf::View levelPanelView;
    levelPanelView.setCenter(mLevelPanel.getPosition());
    levelPanelView.setSize(sf::Vector2f(
        static_cast<float>(bgPanelTexture.getSize().x),
        static_cast<float>(bgPanelTexture.getSize().y)));

    //Set viewport ratio according to the ratio of panel size
    //to window size, with a small amount of padding
    levelPanelView.setViewport(sf::FloatRect(
        (windowSize.x - bgPanelTexture.getSize().x) / 2.f / windowSize.x,
        ((windowSize.y - bgPanelTexture.getSize().y) / 2.f / windowSize.y) + 0.01f,
        bgPanelTexture.getSize().x / windowSize.x,
        bgPanelTexture.getSize().y / windowSize.y - 0.02f));

    mLevelContainer->setView(levelPanelView);

    SaveManager &saveManager = SaveManager::getInstance();
    int collectedGems = getCollectedGems();

    //Level selection buttons
    std::vector<std::string> lPaths = saveManager.getLevelPaths();
    LevelData data = saveManager.getLevelData(lPaths[0]);
    addLevel(data, lPaths[0], true);
    LevelData previousData;
    for (auto it = lPaths.begin() + 1; it != lPaths.end(); ++it){
        previousData = data;
        data = saveManager.getLevelData(*it);
        addLevel(data, (*it), (previousData.completed) && (collectedGems >= data.requiredGems));
    }
    
    mGUIContainer.add(mLevelContainer);
}
示例#20
0
GameOverState::GameOverState(trmb::StateStack& stack, trmb::State::Context context)
: trmb::State(stack, context)
, mGameOverText()
, mElapsedTime(sf::Time::Zero)
{
	sf::Font& font = context.fonts->get(Fonts::ID::Main);
	sf::Vector2f windowSize(context.window->getSize());

	mGameOverText.setFont(font);
	if (context.player->getMissionStatus() == Player::MissionStatus::MissionFailure)
		mGameOverText.setString("Mission failed!");
	else
		mGameOverText.setString("Mission successful!");

	mGameOverText.setCharacterSize(70);
	trmb::centerOrigin(mGameOverText);
	mGameOverText.setPosition(0.5f * windowSize.x, 0.4f * windowSize.y);
}
示例#21
0
void
UiSettings::saveSettings()
{
    QSettings s( "CS224", "snow" );

    s.setValue( "windowPosition", windowPosition() );
    s.setValue( "windowSize", windowSize() );

    s.setValue( "fillNumParticles", fillNumParticles() );
    s.setValue( "fillResolution", fillResolution() );
    s.setValue( "fillDensity", fillDensity() );

    s.setValue("exportDensity", exportDensity());
    s.setValue("exportVelocity",exportVelocity());
    s.setValue( "exportFPS", exportFPS());
    s.setValue( "maxTime", maxTime());

    s.setValue( "gridPositionX", gridPosition().x );
    s.setValue( "gridPositionY", gridPosition().y );
    s.setValue( "gridPositionZ", gridPosition().z );

    s.setValue( "gridDimensionX", gridDimensions().x );
    s.setValue( "gridDimensionY", gridDimensions().y );
    s.setValue( "gridDimensionZ", gridDimensions().z );

    s.setValue( "gridResolution", gridResolution() );

    s.setValue( "timeStep", timeStep() );
    s.setValue( "implicit", implicit() );
    s.setValue("materialPreset", materialPreset());

    s.setValue( "showContainers", showContainers() );
    s.setValue( "showContainersMode", showContainersMode() );
    s.setValue( "showColliders", showColliders() );
    s.setValue( "showCollidersMode", showCollidersMode() );
    s.setValue( "showGrid", showGrid() );
    s.setValue( "showGridMode", showGridMode() );
    s.setValue( "showGridData", showGridData() );
    s.setValue( "showGridDataMode", showGridDataMode() );
    s.setValue( "showParticles", showParticles() );
    s.setValue( "showParticlesMode", showParticlesMode() );
}
SettingsState::SettingsState(StateStack& stack, Context context) : State(stack, context), mGUIContainer() {
	mBackgroundSprite.setTexture(context.textures->get(Textures::TitleScreen));
	sf::Vector2f windowSize(context.window->getSize());
	// Labeling according to button
	addButtonLabel(Player::MoveLeft, 300.f, "Move Left", context);
	addButtonLabel(Player::MoveRight, 350.f, "Move Right", context);
	addButtonLabel(Player::MoveUp, 400.f, "Move Up", context);
	addButtonLabel(Player::MoveDown, 450.f, "Move Down", context);
	addButtonLabel(Player::Fire, 500.f, "Fire", context);
	addButtonLabel(Player::Special, 550.f, "Special", context);

	updateLabels();

	auto backButton = std::make_shared<GUI::Button>(context);
	backButton->setPosition(0.4f * windowSize.x, 0.8f * windowSize.y);
	backButton->setText("Back");
	backButton->setCallback(std::bind(&SettingsState::requestStackPop, this));

	mGUIContainer.pack(backButton);
}
/*!
* Returns Device's Display resolution
*/
QSize CxeViewfinderControlSymbian::deviceDisplayResolution() const
{
    TSize windowSize(640, 360); // magic: default size if mUiWindow is NULL

    if (mUiWindow) {
        windowSize = mUiWindow->Size();
    }

    QSize displaySize = QSize(windowSize.iWidth, windowSize.iHeight);

    if (displaySize.height() > displaySize.width()) {
        // Window server orientation might differ from the Orbit UI orientation.
        // Swap width and height if needed.
        displaySize.transpose();
    }

    CX_DEBUG(("deviceDisplayResolution returning %dx%d", displaySize.width(),
                                                         displaySize.height()));

    return displaySize;
}
示例#24
0
void MediaLayer::InitializeSDL()
{
    // Initialize all the SDL Subsytems you need.
    // Checkout https://wiki.libsdl.org/SDL_Init#Remarks for more subsystems.
    if (SDL_Init(SDL_INIT_VIDEO) != 0) {
        std::cerr << "ERROR: SDL Initialization failed." << std::endl;
        return;
    }

    // Create OpenGL Context with the set attributes. This tells SDL to create an OpenGL context
    // with the specifies properties.
    // More information can be found here: https://wiki.libsdl.org/SDL_GL_SetAttribute 
    // Note that these properties must be set before the window is created.
    SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
    SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
    SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
    SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8);
    SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
    SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);

    SDL_GL_SetAttribute( SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE ); 
    SDL_GL_SetAttribute( SDL_GL_CONTEXT_MAJOR_VERSION, 4);
    SDL_GL_SetAttribute( SDL_GL_CONTEXT_MINOR_VERSION, 1); 

    SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1);
    SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 16);

    glm::vec2 windowSize(app->GetWindowSize());
    sdlWindow = SDL_CreateWindow("CS148 Fall 2015-2016", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
        windowSize.x, windowSize.y, SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE);

    if (!sdlWindow) {
        std::cerr << "ERROR: SDL failed to create a window." << std::endl;
        return;
    }

    sdlInitialized = true;
}
GameOverState::GameOverState(StateStack& stack, Context context)
: State(stack, context)
, mGameOverText()
, mPointsDisplayText()
, mElapsedTime(sf::Time::Zero)
{
	sf::Font& font = context.fonts->get(Fonts::Main);
	sf::Vector2f windowSize(context.window->getSize());

	mGameOverText.setFont(font);
	if (context.player->getMissionStatus() == Player::MissionFailure)
		mGameOverText.setString("You Crash!");

	mGameOverText.setCharacterSize(70);
	centerOrigin(mGameOverText);
	mGameOverText.setPosition(0.5f * windowSize.x, 0.4f * windowSize.y);

	mPointsDisplayText.setFont(font);
	mPointsDisplayText.setCharacterSize(50);
	centerOrigin(mPointsDisplayText);
	mPointsDisplayText.setString("Points: " + toString(static_cast<int>(context.player->getPoints())));
	mPointsDisplayText.setPosition(0.38f * windowSize.x, 0.5f * windowSize.y);
}
示例#26
0
GameOverState::GameOverState(StateStack& stack, Context context)
: State(stack, context)
, mGameOverText()
, mElapsedTime(sf::Time::Zero)
, mStatus(context.player->getMissionStatus())
{
	sf::Font& font = context.fonts->get(Fonts::Main);
	sf::Vector2f windowSize(context.window->getSize());

	mGameOverText.setFont(font);
	if (mStatus == Player::MissionFailure)
		mGameOverText.setString("Mission failed!");	
	else if (mStatus == Player::MissionSuccess)
	{
		mGameOverText.setString("Mission successful!");
		context.player->setMissionStatus(Player::MissionRunning);
	}
	else
		mGameOverText.setString("You win!");

	mGameOverText.setCharacterSize(70);
	centerOrigin(mGameOverText);
	mGameOverText.setPosition(0.5f * windowSize.x, 0.4f * windowSize.y);
}
示例#27
0
void RendererImpl2dGdi::makeCurrentContext( bool force )
{
	if( mPaintEvents )
		mPaintDc = ::BeginPaint( mWnd, &mPaintStruct );
	else
		mPaintDc = ::GetDC( mWnd );
	
	if( mDoubleBuffer ) {
		::RECT clientRect;
		::GetClientRect( mWnd, &clientRect );
		ivec2 windowSize( clientRect.right - clientRect.left, clientRect.bottom - clientRect.top );

		mDoubleBufferDc = ::CreateCompatibleDC( mPaintDc );
		if(( mDoubleBufferBitmap == 0 ) || ( mDoubleBufferBitmapSize != windowSize )) {
			if( mDoubleBufferBitmap ) {
				::DeleteObject( mDoubleBufferBitmap );
			}
			
			mDoubleBufferBitmap = ::CreateCompatibleBitmap( mPaintDc, windowSize.x, windowSize.y );
			mDoubleBufferBitmapSize = windowSize;
		}
		mDoubleBufferOldBitmap = (::HBITMAP)::SelectObject( mDoubleBufferDc, mDoubleBufferBitmap );
	}
}
示例#28
0
OutputWindow::OutputWindow()
	: QGraphicsView(new QGraphicsScene())
	, m_url("")
	, m_pollDviz(false)
	, m_updateTime(1000)
	, m_isDataPoll(false)
	, m_slideId(-1)
	, m_slideName("")
	//, m_startStopButton(0)
        , m_countValue(0)
        , m_drw(0)
        , m_blinkCount(0)
{
	// Setup graphics view
	setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing | QPainter::SmoothPixmapTransform );
	setCacheMode(QGraphicsView::CacheBackground);
	setViewportUpdateMode(QGraphicsView::BoundingRectViewportUpdate);
	setOptimizationFlags(QGraphicsView::DontSavePainterState);
	setViewportUpdateMode(QGraphicsView::SmartViewportUpdate);
	setTransformationAnchor(AnchorUnderMouse);
	setResizeAnchor(AnchorViewCenter);
	setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
	setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
		
	// Add pixmap item for background
	QPixmap bluePixmap(32,23);
	bluePixmap.fill(Qt::blue);
	m_pixmap = scene()->addPixmap(bluePixmap);
	
	// Background behind text
	m_counterBgRect = scene()->addRect(0,0,100,60,QPen(), Qt::black);
	m_counterBgRect->setZValue(99);
	// Add text (for use with clock)
	QFont font("Monospace", 50, 600);
	m_counterText = new QGraphicsSimpleTextItem("0");
	m_counterText->setFont(font);
	m_counterText->setPen(QPen(Qt::black));
	m_counterText->setBrush(Qt::white);
	m_counterText->setPos(0, -13);
	m_counterText->setZValue(100);
	scene()->addItem(m_counterText);
	
	
	// Background behind text
	m_overlayBgRect = scene()->addRect(0,300,100,60,QPen(), Qt::black);
	m_overlayBgRect->setZValue(99);
	// Add text (for use with clock)
	//QFont font("Monospace", 50, 600);
	m_overlayText = new QGraphicsSimpleTextItem("Hello, World!");
	m_overlayText->setFont(font);
	m_overlayText->setPen(QPen(Qt::black));
	m_overlayText->setBrush(Qt::white);
	m_overlayText->setPos(0, 300-13);
	m_overlayText->setZValue(100);
	scene()->addItem(m_overlayText);
	
	m_blinkOverlay = false;
	connect(&m_blinkOverlayTimer, SIGNAL(timeout()), this, SLOT(blinkOverlaySlot()));
	
	GET_CONFIG();
	
	QPoint windowPos(1024,0);
	QPoint windowSize(1024,768);

	//QPoint windowPos(10,10);
	//QPoint windowSize = QPoint(640,480);
	QString windowGeomString = config.value("geom","1024,0,1024,768").toString();
	if(!windowGeomString.isEmpty())
	{
		QStringList list = windowGeomString.split(",");
		windowPos  = QPoint(list[0].toInt(), list[1].toInt());
		windowSize = QPoint(list[2].toInt(), list[3].toInt());
	}
	
	setWindowGeom(QRect(windowPos.x(),windowPos.y(),windowSize.x(),windowSize.y()));
	
	
	bool frameless = config.value("frameless","true").toString() == "true";
	if(frameless)
		setWindowFlags(Qt::FramelessWindowHint);// | Qt::ToolTip);

	connect(&m_pollDvizTimer, SIGNAL(timeout()), this, SLOT(initDvizPoll()));
	//connect(&m_pollImageTimer, SIGNAL(timeout()), this, SLOT(initImagePoll()));
	
	setUpdateTime(m_updateTime);
	
        //setUrl("http://10.10.9.90:8081/image");
        //setUrl("");
	//setPollDviz(true);
	
	setInputSource(config.value("source","dviz://192.168.0.10:8081/image").toString());
	
// 	m_startStopButton = new QPushButton("Start Counter");
// 	connect(m_startStopButton, SIGNAL(clicked()), this, SLOT(toggleCounter()));
 	connect(&m_counterTimer, SIGNAL(timeout()), this, SLOT(counterTick()));
 	m_counterTimer.setInterval(1000);
// 	
// 	m_startStopButton->show();

	//toggleCounter();
	setCounterActive(false);
		
	
	setBlinkOverlay(config.value("blink-overlay","false").toString() == "true", config.value("blink-speed", 333).toInt());
	//setOverlayVisible(config.value("overlay-visible", "true").toString() == "true");
	setCounterVisible(config.value("counter-visible", "true").toString() == "true");
	
	setCounterAlignment((Qt::Alignment)config.value("counter-alignment", (int)(Qt::AlignLeft | Qt::AlignTop)).toInt());
	setOverlayAlignment((Qt::Alignment)config.value("overlay-alignment", (int)(Qt::AlignCenter | Qt::AlignBottom)).toInt());
	
	setOverlayText(config.value("overlay-text").toString());
}
示例#29
0
void XInputMTInputDevice::start()
{
    Status status;
    SDLDisplayEngine * pEngine = Player::get()->getDisplayEngine();
    glm::vec2 size(pEngine->getSize());
    glm::vec2 windowSize(pEngine->getWindowSize());
    m_DisplayScale.x = size.x/windowSize.x;
    m_DisplayScale.y = size.y/windowSize.y;

    SDL_SysWMinfo info;
    SDL_VERSION(&info.version);
    int rc = SDL_GetWMInfo(&info);
    AVG_ASSERT(rc != -1);
    s_pDisplay = info.info.x11.display;
    m_SDLLockFunc = info.info.x11.lock_func;
    m_SDLUnlockFunc = info.info.x11.unlock_func;

    m_SDLLockFunc();
    // XInput Extension available?
    int event, error;
    bool bOk = XQueryExtension(s_pDisplay, "XInputExtension", &m_XIOpcode, 
            &event, &error);
    if (!bOk) {
        throw Exception(AVG_ERR_MT_INIT, 
                "XInput multitouch event source: X Input extension not available.");
    }

    // Which version of XI2? 
    int major;
    int minor;
    status = XIQueryVersion(s_pDisplay, &major, &minor);
    if (status == BadRequest) {
        throw Exception(AVG_ERR_MT_INIT, 
                "XInput 2.1 multitouch event source: Server does not support XI2");
    }
    if (major < 2 || minor < 1) {
        throw Exception(AVG_ERR_MT_INIT, 
                "XInput multitouch event source: Supported version is "
                +toString(major)+"."+toString(minor)+". At least 2.1 is needed.");
    }
    findMTDevice();

    // SDL grabs the pointer in full screen mode. This breaks touchscreen usage.
    // Can't use SDL_WM_GrabInput(SDL_GRAB_OFF) because it doesn't work in full
    // screen mode. Get the display connection and do it manually.
    XUngrabPointer(info.info.x11.display, CurrentTime);

    XIEventMask mask;
    mask.deviceid = m_DeviceID;
    mask.mask_len = XIMaskLen(XI_LASTEVENT);
    mask.mask = (unsigned char *)calloc(mask.mask_len, sizeof(char));
    memset(mask.mask, 0, mask.mask_len);
    XISetMask(mask.mask, XI_TouchBegin);
    XISetMask(mask.mask, XI_TouchUpdate);
    XISetMask(mask.mask, XI_TouchEnd);

    status = XISelectEvents(s_pDisplay, info.info.x11.window, &mask, 1);
    AVG_ASSERT(status == Success);

    m_SDLUnlockFunc();

    SDL_SetEventFilter(XInputMTInputDevice::filterEvent);
  
    
    XIDetachSlaveInfo detInfo;
    detInfo.type = XIDetachSlave;
    detInfo.deviceid = m_DeviceID;
    XIChangeHierarchy(s_pDisplay, (XIAnyHierarchyChangeInfo *)&detInfo, 1);

    pEngine->setXIMTInputDevice(this);
    MultitouchInputDevice::start();
    AVG_TRACE(Logger::category::CONFIG, Logger::severity::INFO,
            "XInput Multitouch event source created.");
}
示例#30
0
int main(int argc, char *argv[])
{
    QGuiApplication app(argc, argv);

    const bool multipleWindows = false;

    QScreen *screen = QGuiApplication::primaryScreen();

    QRect screenGeometry = screen->availableGeometry();

    QSurfaceFormat format;
    format.setDepthBufferSize(16);
    format.setSamples(4);

    QPoint center = QPoint(screenGeometry.center().x(), screenGeometry.top() + 80);
    QSize windowSize(400, 320);
    int delta = 40;

    QList<QWindow *> windows;
    QSharedPointer<Renderer> rendererA(new Renderer(format));

    HelloWindow *windowA = new HelloWindow(rendererA);
    windowA->setGeometry(QRect(center, windowSize).translated(-windowSize.width() - delta / 2, 0));
    windowA->setTitle(QStringLiteral("Thread A - Context A"));
    windowA->setVisible(true);
    windows.prepend(windowA);

    QList<QThread *> renderThreads;
    if (multipleWindows) {
        QSharedPointer<Renderer> rendererB(new Renderer(format, rendererA.data()));

        QThread *renderThread = new QThread;
        rendererB->moveToThread(renderThread);
        renderThreads << renderThread;

        HelloWindow *windowB = new HelloWindow(rendererA);
        windowB->setGeometry(QRect(center, windowSize).translated(delta / 2, 0));
        windowB->setTitle(QStringLiteral("Thread A - Context A"));
        windowB->setVisible(true);
        windows.prepend(windowB);

        HelloWindow *windowC = new HelloWindow(rendererB);
        windowC->setGeometry(QRect(center, windowSize).translated(-windowSize.width() / 2, windowSize.height() + delta));
        windowC->setTitle(QStringLiteral("Thread B - Context B"));
        windowC->setVisible(true);
        windows.prepend(windowC);

        for (int i = 1; i < QGuiApplication::screens().size(); ++i) {
            QScreen *screen = QGuiApplication::screens().at(i);
            QSharedPointer<Renderer> renderer(new Renderer(format, rendererA.data(), screen));

            renderThread = new QThread;
            renderer->moveToThread(renderThread);
            renderThreads.prepend(renderThread);

            QRect screenGeometry = screen->availableGeometry();
            QPoint center = screenGeometry.center();

            QSize windowSize = screenGeometry.size() * 0.8;

            HelloWindow *window = new HelloWindow(renderer);
            window->setScreen(screen);
            window->setGeometry(QRect(center, windowSize).translated(-windowSize.width() / 2, -windowSize.height() / 2));

            QChar id = QChar('B' + i);
            window->setTitle(QStringLiteral("Thread ") + id + QStringLiteral(" - Context ") + id);
            window->setVisible(true);
            windows.prepend(window);
        }
    }

    for (int i = 0; i < renderThreads.size(); ++i) {
        QObject::connect(qGuiApp, SIGNAL(lastWindowClosed()), renderThreads.at(i), SLOT(quit()));
        renderThreads.at(i)->start();
    }

    const int exitValue = app.exec();

    for (int i = 0; i < renderThreads.size(); ++i)
        renderThreads.at(i)->wait();

    qDeleteAll(windows);
    qDeleteAll(renderThreads);

    return exitValue;
}