void imguiEndScrollArea()
{
	// Disable scissoring.
	AddGfxCmdScissor(-1, -1, -1, -1);

	// Draw scroll bar
	int x = g_scrollRight + SCROLL_AREA_PADDING / 2;
	int y = g_scrollBottom;
	int w = SCROLL_AREA_PADDING * 2;
	int h = g_scrollTop - g_scrollBottom;

	int stop = g_scrollAreaTop;
	int sbot = s_state.widgetY;
	int sh = stop - sbot; // The scrollable area height.

	float barHeight = (float)h / (float)sh;

	if (barHeight < 1)
	{
		float barY = (float)(y - sbot) / (float)sh;
		if (barY < 0) barY = 0;
		if (barY > 1) barY = 1;

		// Handle scroll bar logic.
		unsigned int hid = g_scrollId;
		int hx = x;
		int hy = y + (int)(barY*h);
		int hw = w;
		int hh = (int)(barHeight*h);

		const int range = h - (hh - 1);
		bool over = inRect(hx, hy, hw, hh);
		buttonLogic(hid, over);
		if (isActive(hid))
		{
			float u = (float)(hy - y) / (float)range;
			if (s_state.wentActive)
			{
				s_state.dragY = s_state.my;
				s_state.dragOrig = u;
			}
			if (s_state.dragY != s_state.my)
			{
				u = s_state.dragOrig + (s_state.my - s_state.dragY) / (float)range;
				if (u < 0) u = 0;
				if (u > 1) u = 1;
				*g_scrollVal = (int)((1 - u) * (sh - h));
			}
		}

		// BG
		AddGfxCmdRoundedRect((float)x, (float)y, (float)w, (float)h, (float)w / 2 - 1, SetRGBA(0, 0, 0, 196));
		// Bar
		if (isActive(hid))
			AddGfxCmdRoundedRect((float)hx, (float)hy, (float)hw, (float)hh, (float)w / 2 - 1, SetRGBA(255, 196, 0, 196));
		else
			AddGfxCmdRoundedRect((float)hx, (float)hy, (float)hw, (float)hh, (float)w / 2 - 1, isHot(hid) ? SetRGBA(255, 196, 0, 96) : SetRGBA(255, 255, 255, 64));

		// Handle mouse scrolling.
		if (g_insideScrollArea) // && !anyActive())
		{
			if (s_state.scroll)
			{
				*g_scrollVal += 20 * s_state.scroll;
				if (*g_scrollVal < 0) *g_scrollVal = 0;
				if (*g_scrollVal >(sh - h)) *g_scrollVal = (sh - h);
			}
		}
	}
	s_state.insideCurrentScroll = false;
}
void QgsDataDefinedButton::aboutToShowMenu()
{
  mDefineMenu->clear();

  bool hasExp = !getExpression().isEmpty();
  bool hasField = !getField().isEmpty();
  QString ddTitle = tr( "Data defined override" );

  QAction* ddTitleAct = mDefineMenu->addAction( ddTitle );
  QFont titlefont = ddTitleAct->font();
  titlefont.setItalic( true );
  ddTitleAct->setFont( titlefont );
  ddTitleAct->setEnabled( false );

  bool addActiveAction = false;
  if ( useExpression() && hasExp )
  {
    QgsExpression exp( getExpression() );
    // whether expression is parse-able
    addActiveAction = !exp.hasParserError();
  }
  else if ( !useExpression() && hasField )
  {
    // whether field exists
    addActiveAction = mFieldNameList.contains( getField() );
  }

  if ( addActiveAction )
  {
    ddTitleAct->setText( ddTitle + " (" + ( useExpression() ? tr( "expression" ) : tr( "field" ) ) + ")" );
    mDefineMenu->addAction( mActionActive );
    mActionActive->setText( isActive() ? tr( "Deactivate" ) : tr( "Activate" ) );
    mActionActive->setData( QVariant( isActive() ? false : true ) );
  }

  if ( !mFullDescription.isEmpty() )
  {
    mDefineMenu->addAction( mActionDescription );
  }

  mDefineMenu->addSeparator();

  bool fieldActive = false;
  if ( !mDataTypesString.isEmpty() )
  {
    QAction* fieldTitleAct = mDefineMenu->addAction( tr( "Attribute field" ) );
    fieldTitleAct->setFont( titlefont );
    fieldTitleAct->setEnabled( false );

    mDefineMenu->addAction( mActionDataTypes );

    mFieldsMenu->clear();

    if ( mFieldNameList.size() > 0 )
    {

      for ( int j = 0; j < mFieldNameList.count(); ++j )
      {
        QString fldname = mFieldNameList.at( j );
        QAction* act = mFieldsMenu->addAction( fldname + "    (" + mFieldTypeList.at( j ) + ")" );
        act->setData( QVariant( fldname ) );
        if ( getField() == fldname )
        {
          act->setCheckable( true );
          act->setChecked( !useExpression() );
          fieldActive = !useExpression();
        }
      }
    }
    else
    {
      QAction* act = mFieldsMenu->addAction( tr( "No matching field types found" ) );
      act->setEnabled( false );
    }

    mDefineMenu->addSeparator();
  }

  mFieldsMenu->menuAction()->setCheckable( true );
  mFieldsMenu->menuAction()->setChecked( fieldActive );

  QAction* exprTitleAct = mDefineMenu->addAction( tr( "Expression" ) );
  exprTitleAct->setFont( titlefont );
  exprTitleAct->setEnabled( false );

  if ( hasExp )
  {
    QString expString = getExpression();
    if ( expString.length() > 35 )
    {
      expString.truncate( 35 );
      expString.append( "..." );
    }

    expString.prepend( tr( "Current: " ) );

    if ( !mActionExpression )
    {
      mActionExpression = new QAction( expString, this );
      mActionExpression->setCheckable( true );
    }
    else
    {
      mActionExpression->setText( expString );
    }
    mDefineMenu->addAction( mActionExpression );
    mActionExpression->setChecked( useExpression() );

    mDefineMenu->addAction( mActionExpDialog );
    mDefineMenu->addAction( mActionCopyExpr );
    mDefineMenu->addAction( mActionPasteExpr );
    mDefineMenu->addAction( mActionClearExpr );
  }
  else
  {
    mDefineMenu->addAction( mActionExpDialog );
    mDefineMenu->addAction( mActionPasteExpr );
  }

  if ( mAssistant.data() )
  {
    mDefineMenu->addSeparator();
    mDefineMenu->addAction( mActionAssistant );
  }
}
void QgsDataDefinedButton::updateGui()
{
  QString oldDef = mCurrentDefinition;
  QString newDef( "" );
  bool hasExp = !getExpression().isEmpty();
  bool hasField = !getField().isEmpty();

  if ( useExpression() && !hasExp )
  {
    setActive( false );
    setUseExpression( false );
  }
  else if ( !useExpression() && !hasField )
  {
    setActive( false );
  }

  QIcon icon = mIconDataDefine;
  QString deftip = tr( "undefined" );
  if ( useExpression() && hasExp )
  {
    icon = isActive() ? mIconDataDefineExpressionOn : mIconDataDefineExpression;
    newDef = deftip = getExpression();

    QgsExpression exp( getExpression() );
    if ( exp.hasParserError() )
    {
      setActive( false );
      icon = mIconDataDefineExpressionError;
      deftip = tr( "Parse error: %1" ).arg( exp.parserErrorString() );
      newDef = "";
    }
  }
  else if ( !useExpression() && hasField )
  {
    icon = isActive() ? mIconDataDefineOn : mIconDataDefine;
    newDef = deftip = getField();

    if ( !mFieldNameList.contains( getField() ) )
    {
      setActive( false );
      icon = mIconDataDefineError;
      deftip = tr( "'%1' field missing" ).arg( getField() );
      newDef = "";
    }
  }

  setIcon( icon );

  // update and emit current definition
  if ( newDef != oldDef )
  {
    mCurrentDefinition = newDef;
    emit dataDefinedChanged( mCurrentDefinition );
  }

  // build full description for tool tip and popup dialog
  mFullDescription = tr( "<b><u>Data defined override</u></b><br>" );

  mFullDescription += tr( "<b>Active: </b>%1&nbsp;&nbsp;&nbsp;<i>(ctrl|right-click toggles)</i><br>" ).arg( isActive() ? tr( "yes" ) : tr( "no" ) );

  if ( !mUsageInfo.isEmpty() )
  {
    mFullDescription += tr( "<b>Usage:</b><br>%1<br>" ).arg( mUsageInfo );
  }

  if ( !mInputDescription.isEmpty() )
  {
    mFullDescription += tr( "<b>Expected input:</b><br>%1<br>" ).arg( mInputDescription );
  }

  if ( !mDataTypesString.isEmpty() )
  {
    mFullDescription += tr( "<b>Valid input types:</b><br>%1<br>" ).arg( mDataTypesString );
  }

  QString deftype( "" );
  if ( deftip != tr( "undefined" ) )
  {
    deftype = QString( " (%1)" ).arg( useExpression() ? tr( "expression" ) : tr( "field" ) );
  }

  // truncate long expressions, or tool tip may be too wide for screen
  if ( deftip.length() > 75 )
  {
    deftip.truncate( 75 );
    deftip.append( "..." );
  }

  mFullDescription += tr( "<b>Current definition %1:</b><br>%2" ).arg( deftype ).arg( deftip );

  setToolTip( mFullDescription );

}
Beispiel #4
0
// Called within Model::simulate call, below.
void SkeletonModel::updateRig(float deltaTime, glm::mat4 parentTransform) {
    Head* head = _owningAvatar->getHead();
    if (_owningAvatar->isMyAvatar()) {
        MyAvatar* myAvatar = static_cast<MyAvatar*>(_owningAvatar);
        const FBXGeometry& geometry = _geometry->getFBXGeometry();

        Rig::HeadParameters headParams;
        headParams.enableLean = qApp->getAvatarUpdater()->isHMDMode();
        headParams.leanSideways = head->getFinalLeanSideways();
        headParams.leanForward = head->getFinalLeanForward();
        headParams.torsoTwist = head->getTorsoTwist();

        if (qApp->getAvatarUpdater()->isHMDMode()) {
            headParams.isInHMD = true;

            // get HMD position from sensor space into world space, and back into rig space
            glm::mat4 worldHMDMat = myAvatar->getSensorToWorldMatrix() * myAvatar->getHMDSensorMatrix();
            glm::mat4 rigToWorld = createMatFromQuatAndPos(getRotation(), getTranslation());
            glm::mat4 worldToRig = glm::inverse(rigToWorld);
            glm::mat4 rigHMDMat = worldToRig * worldHMDMat;

            headParams.rigHeadPosition = extractTranslation(rigHMDMat);
            headParams.rigHeadOrientation = extractRotation(rigHMDMat);
            headParams.worldHeadOrientation = extractRotation(worldHMDMat);
        } else {
            headParams.isInHMD = false;

            // We don't have a valid localHeadPosition.
            headParams.rigHeadOrientation = Quaternions::Y_180 * head->getFinalOrientationInLocalFrame();
            headParams.worldHeadOrientation = head->getFinalOrientationInWorldFrame();
        }

        headParams.leanJointIndex = geometry.leanJointIndex;
        headParams.neckJointIndex = geometry.neckJointIndex;
        headParams.isTalking = head->getTimeWithoutTalking() <= 1.5f;

        _rig->updateFromHeadParameters(headParams, deltaTime);

        Rig::HandParameters handParams;

        auto leftPalm = myAvatar->getHand()->getCopyOfPalmData(HandData::LeftHand);
        if (leftPalm.isValid() && leftPalm.isActive()) {
            handParams.isLeftEnabled = true;
            handParams.leftPosition = Quaternions::Y_180 * leftPalm.getRawPosition();
            handParams.leftOrientation = Quaternions::Y_180 * leftPalm.getRawRotation();
            handParams.leftTrigger = leftPalm.getTrigger();
        } else {
            handParams.isLeftEnabled = false;
        }

        auto rightPalm = myAvatar->getHand()->getCopyOfPalmData(HandData::RightHand);
        if (rightPalm.isValid() && rightPalm.isActive()) {
            handParams.isRightEnabled = true;
            handParams.rightPosition = Quaternions::Y_180 * rightPalm.getRawPosition();
            handParams.rightOrientation = Quaternions::Y_180 * rightPalm.getRawRotation();
            handParams.rightTrigger = rightPalm.getTrigger();
        } else {
            handParams.isRightEnabled = false;
        }

        _rig->updateFromHandParameters(handParams, deltaTime);

        _rig->computeMotionAnimationState(deltaTime, _owningAvatar->getPosition(), _owningAvatar->getVelocity(), _owningAvatar->getOrientation());

        // evaluate AnimGraph animation and update jointStates.
        Model::updateRig(deltaTime, parentTransform);

        Rig::EyeParameters eyeParams;
        eyeParams.worldHeadOrientation = headParams.worldHeadOrientation;
        eyeParams.eyeLookAt = head->getLookAtPosition();
        eyeParams.eyeSaccade = head->getSaccade();
        eyeParams.modelRotation = getRotation();
        eyeParams.modelTranslation = getTranslation();
        eyeParams.leftEyeJointIndex = geometry.leftEyeJointIndex;
        eyeParams.rightEyeJointIndex = geometry.rightEyeJointIndex;

        _rig->updateFromEyeParameters(eyeParams);

    } else {

        Model::updateRig(deltaTime, parentTransform);

        // This is a little more work than we really want.
        //
        // Other avatars joint, including their eyes, should already be set just like any other joints
        // from the wire data. But when looking at me, we want the eyes to use the corrected lookAt.
        //
        // Thus this should really only be ... else if (_owningAvatar->getHead()->isLookingAtMe()) {...
        // However, in the !isLookingAtMe case, the eyes aren't rotating the way they should right now.
        // We will revisit that as priorities allow, and particularly after the new rig/animation/joints.
        const FBXGeometry& geometry = _geometry->getFBXGeometry();

        // If the head is not positioned, updateEyeJoints won't get the math right
        glm::quat headOrientation;
        _rig->getJointRotation(geometry.headJointIndex, headOrientation);
        glm::vec3 eulers = safeEulerAngles(headOrientation);
        head->setBasePitch(glm::degrees(-eulers.x));
        head->setBaseYaw(glm::degrees(eulers.y));
        head->setBaseRoll(glm::degrees(-eulers.z));

        Rig::EyeParameters eyeParams;
        eyeParams.worldHeadOrientation = head->getFinalOrientationInWorldFrame();
        eyeParams.eyeLookAt = head->getCorrectedLookAtPosition();
        eyeParams.eyeSaccade = glm::vec3();
        eyeParams.modelRotation = getRotation();
        eyeParams.modelTranslation = getTranslation();
        eyeParams.leftEyeJointIndex = geometry.leftEyeJointIndex;
        eyeParams.rightEyeJointIndex = geometry.rightEyeJointIndex;

        _rig->updateFromEyeParameters(eyeParams);
     }
}
	void Dropdown::draw(void) {

		ofSetColor(colors["edge"]);
		ofRect(boundingBox);

		if (isEnabled()) {
			ofSetColor(colors["background"]);
		} else {
			ofSetColor(colors["disabled"]);
		}
		ofRect(boundingBox.x + edgeWidth, boundingBox.y + edgeWidth, boundingBox.width - (edgeWidth * 2), boundingBox.height - (edgeWidth * 2));

		if (isActive()) {

			ofSetColor(colors["edge"]);
			ofRect(_dropdownBoxPosition);
			ofSetColor(colors["background"]);
			ofRect(_dropdownBoxPosition.x + edgeWidth, _dropdownBoxPosition.y + edgeWidth,
				   _dropdownBoxPosition.width - (edgeWidth * 2), _dropdownBoxPosition.height - (edgeWidth * 2)
				   );


			//Draw the highlight.
			if (_highlightedSelectionIndex != NOTHING_SELECTED) {
				ofSetColor(colors["hovered"]);
				ofRect(_dropdownBoxPosition.x + edgeWidth,
					   _dropdownBoxPosition.y + edgeWidth + (_highlightedSelectionIndex * _selectionLineHeight),
					   _dropdownBoxPosition.width - (edgeWidth * 2),
					   _selectionLineHeight
					   );
			}

			//Draw each selection in the dropdown
			ofSetColor(colors["text"]);
			for (int i = 0; i < _selectionOptions.size(); ++i) {
				this->drawString(_selectionOptions.at(i).label,
								 _dropdownBoxPosition.x + edgeWidth + TEXT_HORIZ_SPACING,
								 _dropdownBoxPosition.y + ((i + 1) * _selectionLineHeight)
								 );
			}

		} else {
			//Draw the text that is shown in the dropdown box.
			ofSetColor(colors["text"]);
			this->drawString(_displayedText,
							 boundingBox.x + edgeWidth + TEXT_HORIZ_SPACING,
							 boundingBox.y + _selectionLineHeight*.8
							 );
		}

		ofSetColor(colors["edge"]);
		ofRect(_dropdownArrowPosition);

		if (isHovered()) {
			ofSetColor(colors["hovered"]);
		} else {
			ofSetColor(colors["edge"]);
		}
		ofRect(_dropdownArrowPosition.x + edgeWidth, _dropdownArrowPosition.y + edgeWidth,
			   _dropdownArrowPosition.width - (2 * edgeWidth), _dropdownArrowPosition.height - (2 * edgeWidth));

		ofSetLineWidth(1);
		ofSetColor(colors["background"]);
		ofPoint arrowCenter = _dropdownArrowPosition.getCenter();
		ofLine(arrowCenter.x, arrowCenter.y + 2, arrowCenter.x - 5, arrowCenter.y - 3);
		ofLine(arrowCenter.x, arrowCenter.y + 2, arrowCenter.x + 5, arrowCenter.y - 3);

	}
Beispiel #6
0
void UITextEdit::drawSelf(Fw::DrawPane drawPane)
{
    if((drawPane & Fw::ForegroundPane) == 0)
        return;

    drawBackground(m_rect);
    drawBorder(m_rect);
    drawImage(m_rect);
    drawIcon(m_rect);

    //TODO: text rendering could be much optimized by using vertex buffer or caching the render into a texture

    int textLength = m_text.length();
    const TexturePtr& texture = m_font->getTexture();
    if(!texture)
        return;

    if(hasSelection()) {
        if(m_color != Color::alpha) {
            g_painter->setColor(m_color);
            for(int i=0;i<m_selectionStart;++i)
                g_painter->drawTexturedRect(m_glyphsCoords[i], texture, m_glyphsTexCoords[i]);
        }

        for(int i=m_selectionStart;i<m_selectionEnd;++i) {
            g_painter->setColor(m_selectionBackgroundColor);
            g_painter->drawFilledRect(m_glyphsCoords[i]);
            g_painter->setColor(m_selectionColor);
            g_painter->drawTexturedRect(m_glyphsCoords[i], texture, m_glyphsTexCoords[i]);
        }

        if(m_color != Color::alpha) {
            g_painter->setColor(m_color);
            for(int i=m_selectionEnd;i<textLength;++i)
                g_painter->drawTexturedRect(m_glyphsCoords[i], texture, m_glyphsTexCoords[i]);
        }
    } else if(m_color != Color::alpha) {
        g_painter->setColor(m_color);
        for(int i=0;i<textLength;++i)
            g_painter->drawTexturedRect(m_glyphsCoords[i], texture, m_glyphsTexCoords[i]);
    }


    // render cursor
    if(isExplicitlyEnabled() && m_cursorVisible && m_cursorInRange && isActive() && m_cursorPos >= 0) {
        assert(m_cursorPos <= textLength);
        // draw every 333ms
        const int delay = 333;
        int elapsed = g_clock.millis() - m_cursorTicks;
        if(elapsed <= delay) {
            Rect cursorRect;
            // when cursor is at 0
            if(m_cursorPos == 0)
                cursorRect = Rect(m_rect.left()+m_padding.left, m_rect.top()+m_padding.top, 1, m_font->getGlyphHeight());
            else
                cursorRect = Rect(m_glyphsCoords[m_cursorPos-1].right(), m_glyphsCoords[m_cursorPos-1].top(), 1, m_font->getGlyphHeight());

            if(hasSelection() && m_cursorPos >= m_selectionStart && m_cursorPos <= m_selectionEnd)
                g_painter->setColor(m_selectionColor);
            else
                g_painter->setColor(m_color);

            g_painter->drawFilledRect(cursorRect);
        } else if(elapsed >= 2*delay) {
            m_cursorTicks = g_clock.millis();
        }
    }

    g_painter->resetColor();
}
Beispiel #7
0
bool SkeletonModel::getLocalNeckPosition(glm::vec3& neckPosition) const {
    return isActive() && getJointPosition(_geometry->getFBXGeometry().neckJointIndex, neckPosition);
}
/*!
    Stops Bluetooth device discovery.  The cancel() signal is emitted once the
    device discovery is canceled.  start() maybe called before the cancel signal is
    received.  Once start() has been called the cancel signal from the prior
    discovery will be discarded.
*/
void QBluetoothDeviceDiscoveryAgent::stop()
{
    Q_D(QBluetoothDeviceDiscoveryAgent);
    if (isActive() && d->lastError != InvalidBluetoothAdapterError)
        d->stop();
}
bool SuspendableTimer::hasPendingActivity() const
{
    return isActive();
}
void QgsPropertyOverrideButton::menuActionTriggered( QAction *action )
{
  if ( action == mActionActive )
  {
    setActivePrivate( mActionActive->data().toBool() );
    updateGui();
    emit changed();
  }
  else if ( action == mActionDescription )
  {
    showDescriptionDialog();
  }
  else if ( action == mActionExpDialog )
  {
    showExpressionDialog();
  }
  else if ( action == mActionExpression )
  {
    mProperty.setExpressionString( mExpressionString );
    mProperty.setTransformer( nullptr );
    setActivePrivate( true );
    updateSiblingWidgets( isActive() );
    updateGui();
    emit changed();
  }
  else if ( action == mActionCopyExpr )
  {
    QApplication::clipboard()->setText( mExpressionString );
  }
  else if ( action == mActionPasteExpr )
  {
    QString exprString = QApplication::clipboard()->text();
    if ( !exprString.isEmpty() )
    {
      mExpressionString = exprString;
      mProperty.setExpressionString( mExpressionString );
      mProperty.setTransformer( nullptr );
      setActivePrivate( true );
      updateSiblingWidgets( isActive() );
      updateGui();
      emit changed();
    }
  }
  else if ( action == mActionClearExpr )
  {
    setActivePrivate( false );
    mProperty.setStaticValue( QVariant() );
    mProperty.setTransformer( nullptr );
    mExpressionString.clear();
    updateSiblingWidgets( isActive() );
    updateGui();
    emit changed();
  }
  else if ( action == mActionAssistant )
  {
    showAssistant();
  }
  else if ( action == mActionCreateAuxiliaryField )
  {
    emit createAuxiliaryField();
  }
  else if ( mFieldsMenu->actions().contains( action ) )  // a field name clicked
  {
    if ( action->isEnabled() )
    {
      if ( mFieldName != action->text() )
      {
        mFieldName = action->data().toString();
      }
      mProperty.setField( mFieldName );
      mProperty.setTransformer( nullptr );
      setActivePrivate( true );
      updateSiblingWidgets( isActive() );
      updateGui();
      emit changed();
    }
  }
  else if ( mVariablesMenu->actions().contains( action ) )  // a variable name clicked
  {
    if ( mExpressionString != action->text().prepend( "@" ) )
    {
      mExpressionString = action->data().toString().prepend( "@" );
    }
    mProperty.setExpressionString( mExpressionString );
    mProperty.setTransformer( nullptr );
    setActivePrivate( true );
    updateSiblingWidgets( isActive() );
    updateGui();
    emit changed();
  }
  else if ( mColorsMenu->actions().contains( action ) )  // a color name clicked
  {
    if ( mExpressionString != QStringLiteral( "project_color('%1')" ).arg( action->text() ) )
    {
      mExpressionString = QStringLiteral( "project_color('%1')" ).arg( action->text() );
    }
    mProperty.setExpressionString( mExpressionString );
    mProperty.setTransformer( nullptr );
    setActivePrivate( true );
    updateSiblingWidgets( isActive() );
    updateGui();
    emit changed();
  }
}
void FramerateEqualizer::notifyUpdatePre( Compound* compound, 
                                          const uint32_t frameNumber )
{
    _init();

    // find starting point of contiguous block
    const ssize_t size = static_cast< ssize_t >( _times.size( ));
    ssize_t       from = 0;
    if( size > 0 )
    {
        for( ssize_t i = size-1; i >= 0; --i )
        {
            if( _times[i].second != 0.f )
                continue;

            from = i;
            break;
        }
    }

    // find max / avg time in block
    size_t nSamples = 0;
#ifdef USE_AVERAGE
    float sumTime = 0.f;
#else
    float maxTime  = 0.f;
#endif

    for( ++from; from < size && nSamples < _nSamples; ++from )
    {
        const FrameTime& time = _times[from];
        EQASSERT( time.first > 0 );
        EQASSERT( time.second != 0.f );

        ++nSamples;
#ifdef USE_AVERAGE
        sumTime += time.second;
#else
        maxTime = EQ_MAX( maxTime, time.second );
#endif
        EQLOG( LOG_LB2 ) << "Using " << time.first << ", " << time.second
                         << "ms" << std::endl;
    }

    if( nSamples == _nSamples )       // If we have a full set
        while( from < static_cast< ssize_t >( _times.size( )))
            _times.pop_back();            //  delete all older samples

    if( isFrozen() || !compound->isRunning() || !isActive( ))
    {
        // always execute code above to not leak memory
        compound->setMaxFPS( std::numeric_limits< float >::max( ));
        return;
    }

    if( nSamples > 0 )
    {
        //TODO: totalTime *= 1.f - damping;
#ifdef USE_AVERAGE
        const float time = (sumTime / nSamples) * SLOWDOWN;
#else
        const float time = maxTime * SLOWDOWN;
#endif

        const float fps = 1000.f / time;
#ifdef VSYNC_CAP
        if( fps > VSYNC_CAP )
            compound->setMaxFPS( std::numeric_limits< float >::max( ));
        else
#endif
            compound->setMaxFPS( fps );

        EQLOG( LOG_LB2 ) << fps << " Hz from " << nSamples << "/" 
                        << _times.size() << " samples, " << time << "ms" 
                        << std::endl;
    }

    _times.push_front( FrameTime( frameNumber, 0.f ));
    EQASSERT( _times.size() < 210 );
}
bool imguiSlider(const char* text, int* val, int vmin, int vmax, int vinc, bool enabled)
{
	s_state.widgetId++;
	unsigned int id = (s_state.areaId << 16) | s_state.widgetId;

	int x = s_state.widgetX;
	int y = s_state.widgetY - BUTTON_HEIGHT;
	int w = s_state.widgetW;
	int h = SLIDER_HEIGHT;
	s_state.widgetY -= SLIDER_HEIGHT + DEFAULT_SPACING;

	AddGfxCmdRoundedRect((float)x, (float)y, (float)w, (float)h, 4.0f, SetRGBA(0, 0, 0, 128));

	const int range = w - SLIDER_MARKER_WIDTH;

	float u = (*val - vmin) / float(vmax - vmin);
	if (u < 0) u = 0;
	if (u > 1) u = 1;
	int m = (int)(u * range);

	bool over = enabled && inRect(x + m, y, SLIDER_MARKER_WIDTH, SLIDER_HEIGHT);
	bool res = buttonLogic(id, over);
	bool valChanged = false;

	if (isActive(id))
	{
		if (s_state.wentActive)
		{
			s_state.dragX = s_state.mx;
			s_state.dragOrig = u;
		}
		if (s_state.dragX != s_state.mx)
		{
			u = s_state.dragOrig + (float)(s_state.mx - s_state.dragX) / (float)range;
			if (u < 0) u = 0;
			if (u > 1) u = 1;
			*val = int(vmin + u*(vmax - vmin));
			*val = int(floorf(*val / float(vinc) + 0.5f))*vinc; // Snap to vinc
			m = (int)(u * range);
			valChanged = true;
		}
	}

	if (isActive(id))
		AddGfxCmdRoundedRect((float)(x + m), (float)y, (float)SLIDER_MARKER_WIDTH, (float)SLIDER_HEIGHT, 4.0f, SetRGBA(255, 255, 255, 255));
	else
		AddGfxCmdRoundedRect((float)(x + m), (float)y, (float)SLIDER_MARKER_WIDTH, (float)SLIDER_HEIGHT, 4.0f, isHot(id) ? SetRGBA(255, 196, 0, 128) : SetRGBA(255, 255, 255, 64));

	char msg[128];
	snprintf(msg, 128, "%d", *val);

	if (enabled)
	{
		AddGfxCmdText(x + SLIDER_HEIGHT / 2, y + SLIDER_HEIGHT / 2 - TEXT_HEIGHT / 2, TEXT_ALIGN_LEFT, text, isHot(id) ? SetRGBA(255, 196, 0, 255) : SetRGBA(255, 255, 255, 200));
		AddGfxCmdText(x + w - SLIDER_HEIGHT / 2, y + SLIDER_HEIGHT / 2 - TEXT_HEIGHT / 2, TEXT_ALIGN_RIGHT, msg, isHot(id) ? SetRGBA(255, 196, 0, 255) : SetRGBA(255, 255, 255, 200));
	}
	else
	{
		AddGfxCmdText(x + SLIDER_HEIGHT / 2, y + SLIDER_HEIGHT / 2 - TEXT_HEIGHT / 2, TEXT_ALIGN_LEFT, text, SetRGBA(128, 128, 128, 200));
		AddGfxCmdText(x + w - SLIDER_HEIGHT / 2, y + SLIDER_HEIGHT / 2 - TEXT_HEIGHT / 2, TEXT_ALIGN_RIGHT, msg, SetRGBA(128, 128, 128, 200));
	}

	return res || valChanged;
}
bool imguiCheck(const char* text, bool checked, bool enabled)
{
	s_state.widgetId++;
	unsigned int id = (s_state.areaId << 16) | s_state.widgetId;

	int x = s_state.widgetX;
	int y = s_state.widgetY - BUTTON_HEIGHT;
	int w = s_state.widgetW;
	int h = BUTTON_HEIGHT;
	s_state.widgetY -= BUTTON_HEIGHT + DEFAULT_SPACING;

	bool over = enabled && inRect(x, y, w, h);
	bool res = buttonLogic(id, over);

	const int cx = x + BUTTON_HEIGHT / 2 - CHECK_SIZE / 2;
	const int cy = y + BUTTON_HEIGHT / 2 - CHECK_SIZE / 2;
	AddGfxCmdRoundedRect((float)cx - 3, (float)cy - 3, (float)CHECK_SIZE + 6, (float)CHECK_SIZE + 6, 4, SetRGBA(128, 128, 128, isActive(id) ? 196 : 96));
	if (checked)
	{
		if (enabled)
			AddGfxCmdRoundedRect((float)cx, (float)cy, (float)CHECK_SIZE, (float)CHECK_SIZE, (float)CHECK_SIZE / 2 - 1, SetRGBA(255, 255, 255, isActive(id) ? 255 : 200));
		else
			AddGfxCmdRoundedRect((float)cx, (float)cy, (float)CHECK_SIZE, (float)CHECK_SIZE, (float)CHECK_SIZE / 2 - 1, SetRGBA(128, 128, 128, 200));
	}

	if (enabled)
		AddGfxCmdText(x + BUTTON_HEIGHT, y + BUTTON_HEIGHT / 2 - TEXT_HEIGHT / 2, TEXT_ALIGN_LEFT, text, isHot(id) ? SetRGBA(255, 196, 0, 255) : SetRGBA(255, 255, 255, 200));
	else
		AddGfxCmdText(x + BUTTON_HEIGHT, y + BUTTON_HEIGHT / 2 - TEXT_HEIGHT / 2, TEXT_ALIGN_LEFT, text, SetRGBA(128, 128, 128, 200));

	return res;
}
bool imguiItem(const char* text, bool enabled)
{
	s_state.widgetId++;
	unsigned int id = (s_state.areaId << 16) | s_state.widgetId;

	int x = s_state.widgetX;
	int y = s_state.widgetY - BUTTON_HEIGHT;
	int w = s_state.widgetW;
	int h = BUTTON_HEIGHT;
	s_state.widgetY -= BUTTON_HEIGHT + DEFAULT_SPACING;

	bool over = enabled && inRect(x, y, w, h);
	bool res = buttonLogic(id, over);

	if (isHot(id))
		AddGfxCmdRoundedRect((float)x, (float)y, (float)w, (float)h, 2.0f, SetRGBA(255, 196, 0, isActive(id) ? 196 : 96));

	if (enabled)
		AddGfxCmdText(x + BUTTON_HEIGHT / 2, y + BUTTON_HEIGHT / 2 - TEXT_HEIGHT / 2, TEXT_ALIGN_LEFT, text, SetRGBA(255, 255, 255, 200));
	else
		AddGfxCmdText(x + BUTTON_HEIGHT / 2, y + BUTTON_HEIGHT / 2 - TEXT_HEIGHT / 2, TEXT_ALIGN_LEFT, text, SetRGBA(128, 128, 128, 200));

	return res;
}
Beispiel #15
0
/*!
  Returns the size of the result (number of rows returned), or -1 if
  the size cannot be determined or if the database does not support
  reporting information about query sizes. Note that for non-\c SELECT
  statements (isSelect() returns \c false), size() will return -1. If the
  query is not active (isActive() returns \c false), -1 is returned.

  To determine the number of rows affected by a non-\c SELECT
  statement, use numRowsAffected().

  \sa isActive(), numRowsAffected(), QSqlDriver::hasFeature()
*/
int QSqlQuery::size() const
{
    if (isActive() && d->sqlResult->driver()->hasFeature(QSqlDriver::QuerySize))
        return d->sqlResult->size();
    return -1;
}
Beispiel #16
0
int CrFbDisplayWindow::windowDimensionsSync(bool fForceCleanup)
{
    int rc = VINF_SUCCESS;

    if (!mpWindow)
        return VINF_SUCCESS;

    //HCR_FRAMEBUFFER hFb = getFramebuffer();
    if (!fForceCleanup && isActive())
    {
        const RTRECT* pRect = getRect();

        if (mpWindow->GetParentId() != mParentId)
        {
            rc = mpWindow->Reparent(mParentId);
            if (!RT_SUCCESS(rc))
            {
                WARN(("err"));
                return rc;
            }
        }

        rc = mpWindow->SetPosition(pRect->xLeft - mViewportRect.xLeft, pRect->yTop - mViewportRect.yTop);
        if (!RT_SUCCESS(rc))
        {
            WARN(("err"));
            return rc;
        }

        setRegionsChanged();

        rc = mpWindow->SetSize((uint32_t)(pRect->xRight - pRect->xLeft), (uint32_t)(pRect->yBottom - pRect->yTop));
        if (!RT_SUCCESS(rc))
        {
            WARN(("err"));
            return rc;
        }

        rc = mpWindow->SetVisible(!g_CrPresenter.fWindowsForceHidden);
        if (!RT_SUCCESS(rc))
        {
            WARN(("err"));
            return rc;
        }
    }
    else
    {
        rc = mpWindow->SetVisible(false);
        if (!RT_SUCCESS(rc))
        {
            WARN(("err"));
            return rc;
        }
#if 0
        rc = mpWindow->Reparent(mDefaultParentId);
        if (!RT_SUCCESS(rc))
        {
            WARN(("err"));
            return rc;
        }
#endif
    }

    return rc;
}
Beispiel #17
0
int QSqlQuery::numRowsAffected() const
{
    if (isActive())
        return d->sqlResult->numRowsAffected();
    return -1;
}
void MouseDialogNavigationTool::frame(void)
	{
	/* Update the current mouse position: */
	currentPos=calcScreenPos();
	
	/* Act depending on this tool's current state: */
	if(isActive())
		{
		if(spinning)
			{
			/* Calculate incremental rotation: */
			rotation.leftMultiply(NavTrackerState::rotate(NavTrackerState::Rotation::rotateScaledAxis(spinAngularVelocity*getFrameTime())));
			
			NavTrackerState t=preScale;
			t*=rotation;
			t*=postScale;
			setNavigationTransformation(t);
			}
		else
			{
			switch(navigationMode)
				{
				case ROTATING:
					{
					/* Calculate the rotation position: */
					Vector offset=(lastRotationPos-screenCenter)+rotateOffset;
					
					/* Calculate mouse displacement vector: */
					Point rotationPos=currentPos;
					Vector delta=rotationPos-lastRotationPos;
					lastRotationPos=rotationPos;
					
					/* Calculate incremental rotation: */
					Vector axis=Geometry::cross(offset,delta);
					Scalar angle=Geometry::mag(delta)/factory->rotateFactor;
					if(angle!=Scalar(0))
						rotation.leftMultiply(NavTrackerState::rotate(NavTrackerState::Rotation::rotateAxis(axis,angle)));
					
					NavTrackerState t=preScale;
					t*=rotation;
					t*=postScale;
					setNavigationTransformation(t);
					break;
					}
				
				case PANNING:
					{
					/* Update the navigation transformation: */
					NavTrackerState t=NavTrackerState::translate(currentPos-motionStart);
					t*=preScale;
					setNavigationTransformation(t);
					break;
					}
				
				case DOLLYING:
					{
					/* Calculate the current dollying direction: */
					Vector dollyingDirection;
					if(mouseAdapter!=0)
						dollyingDirection=mouseAdapter->getWindow()->getVRScreen()->getScreenTransformation().transform(factory->screenDollyingDirection);
					else
						dollyingDirection=getMainScreen()->getScreenTransformation().transform(factory->screenDollyingDirection);
					
					/* Update the navigation transformation: */
					Scalar dollyDist=((currentPos-motionStart)*dollyingDirection)/factory->dollyFactor;
					NavTrackerState t=NavTrackerState::translate(dollyDirection*dollyDist);
					t*=preScale;
					setNavigationTransformation(t);
					break;
					}
				
				case SCALING:
					{
					/* Calculate the current scaling direction: */
					Vector scalingDirection;
					if(mouseAdapter!=0)
						scalingDirection=mouseAdapter->getWindow()->getVRScreen()->getScreenTransformation().transform(factory->screenScalingDirection);
					else
						scalingDirection=getMainScreen()->getScreenTransformation().transform(factory->screenScalingDirection);
					
					/* Update the navigation transformation: */
					Scalar scale=((currentPos-motionStart)*scalingDirection)/factory->scaleFactor;
					NavTrackerState t=preScale;
					t*=NavTrackerState::scale(Math::exp(scale));
					t*=postScale;
					setNavigationTransformation(t);
					break;
					}
				}
			}
		}
	}
Beispiel #19
0
bool SkeletonModel::getHeadPosition(glm::vec3& headPosition) const {
    return isActive() && getJointPositionInWorldFrame(_geometry->getFBXGeometry().headJointIndex, headPosition);
}
void QgsMapRendererCustomPainterJob::start()
{
  if ( isActive() )
    return;

  mRenderingStart.start();

  mActive = true;

  mErrors.clear();

  QgsDebugMsg( "QPAINTER run!" );

  QgsDebugMsg( "Preparing list of layer jobs for rendering" );
  QTime prepareTime;
  prepareTime.start();

  // clear the background
  mPainter->fillRect( 0, 0, mSettings.outputSize().width(), mSettings.outputSize().height(), mSettings.backgroundColor() );

  mPainter->setRenderHint( QPainter::Antialiasing, mSettings.testFlag( QgsMapSettings::Antialiasing ) );

#ifndef QT_NO_DEBUG
  QPaintDevice* thePaintDevice = mPainter->device();
  QString errMsg = QString( "pre-set DPI not equal to painter's DPI (%1 vs %2)" ).arg( thePaintDevice->logicalDpiX() ).arg( mSettings.outputDpi() );
  Q_ASSERT_X( qgsDoubleNear( thePaintDevice->logicalDpiX(), mSettings.outputDpi() ), "Job::startRender()", errMsg.toAscii().data() );
#endif

  delete mLabelingEngine;
  mLabelingEngine = nullptr;

  delete mLabelingEngineV2;
  mLabelingEngineV2 = nullptr;

  if ( mSettings.testFlag( QgsMapSettings::DrawLabeling ) )
  {
#ifdef LABELING_V2
    mLabelingEngineV2 = new QgsLabelingEngineV2();
    mLabelingEngineV2->readSettingsFromProject();
    mLabelingEngineV2->setMapSettings( mSettings );
#else
    mLabelingEngine = new QgsPalLabeling;
    mLabelingEngine->loadEngineSettings();
    mLabelingEngine->init( mSettings );
#endif
  }

  mLayerJobs = prepareJobs( mPainter, mLabelingEngine, mLabelingEngineV2 );
  // prepareJobs calls mapLayer->createMapRenderer may involve cloning a RasterDataProvider,
  // whose constructor may need to download some data (i.e. WMS, AMS) and doing so runs a
  // QEventLoop waiting for the network request to complete. If unluckily someone calls
  // mapCanvas->refresh() while this is happening, QgsMapRendererCustomPainterJob::cancel is
  // called, deleting the QgsMapRendererCustomPainterJob while this function is running.
  // Hence we need to check whether the job is still active before proceeding
  if ( !isActive() )
    return;

  QgsDebugMsg( "Rendering prepared in (seconds): " + QString( "%1" ).arg( prepareTime.elapsed() / 1000.0 ) );

  if ( mRenderSynchronously )
  {
    // do the rendering right now!
    doRender();
    return;
  }

  // now we are ready to start rendering!
  connect( &mFutureWatcher, SIGNAL( finished() ), SLOT( futureFinished() ) );

  mFuture = QtConcurrent::run( staticRender, this );
  mFutureWatcher.setFuture( mFuture );
}
Beispiel #21
0
bool SkeletonModel::hasSkeleton() {
    return isActive() ? _geometry->getFBXGeometry().rootJointIndex != -1 : false;
}
Beispiel #22
0
QSqlRecord SQLiteResult::record() const
{
    if (!isActive() || !isSelect())
        return QSqlRecord();
    return d->rInf;
}
Beispiel #23
0
void		HorDash::check()
{
  if (_player(Event::WALL) && !isActive())
    _open = 1;
}
Beispiel #24
0
bool HashTable<HashObj> :: contains( const HashObj & x) const{
        return isActive( findPos( x ));
}
BaseDelegate::~BaseDelegate()
{
    Q_ASSERT(!isActive());
}
Beispiel #26
0
/*!
  \since 4.4

  Discards the current result set and navigates to the next if available.

  Some databases are capable of returning multiple result sets for
  stored procedures or SQL batches (a query strings that contains
  multiple statements). If multiple result sets are available after
  executing a query this function can be used to navigate to the next
  result set(s).

  If a new result set is available this function will return true.
  The query will be repositioned on an \e invalid record in the new
  result set and must be navigated to a valid record before data
  values can be retrieved. If a new result set isn't available the
  function returns \c false and the query is set to inactive. In any
  case the old result set will be discarded.

  When one of the statements is a non-select statement a count of
  affected rows may be available instead of a result set.

  Note that some databases, i.e. Microsoft SQL Server, requires
  non-scrollable cursors when working with multiple result sets.  Some
  databases may execute all statements at once while others may delay
  the execution until the result set is actually accessed, and some
  databases may have restrictions on which statements are allowed to
  be used in a SQL batch.

  \sa QSqlDriver::hasFeature(), setForwardOnly(), next(), isSelect(),
      numRowsAffected(), isActive(), lastError()
*/
bool QSqlQuery::nextResult()
{
    if (isActive())
        return d->sqlResult->nextResult();
    return false;
}
void QgsDataDefinedButton::menuActionTriggered( QAction* action )
{
  if ( action == mActionActive )
  {
    setActive( mActionActive->data().toBool() );
    updateGui();
  }
  else if ( action == mActionDescription )
  {
    showDescriptionDialog();
  }
  else if ( action == mActionExpDialog )
  {
    showExpressionDialog();
  }
  else if ( action == mActionExpression )
  {
    setUseExpression( true );
    setActive( true );
    updateGui();
  }
  else if ( action == mActionCopyExpr )
  {
    QApplication::clipboard()->setText( getExpression() );
  }
  else if ( action == mActionPasteExpr )
  {
    QString exprString = QApplication::clipboard()->text();
    if ( !exprString.isEmpty() )
    {
      setExpression( exprString );
      setUseExpression( true );
      setActive( true );
      updateGui();
    }
  }
  else if ( action == mActionClearExpr )
  {
    // only deactivate if defined expression is being used
    if ( isActive() && useExpression() )
    {
      setUseExpression( false );
      setActive( false );
    }
    setExpression( QString( "" ) );
    updateGui();
  }
  else if ( action == mActionAssistant )
  {
    showAssistant();
  }
  else if ( mFieldsMenu->actions().contains( action ) )  // a field name clicked
  {
    if ( action->isEnabled() )
    {
      if ( getField() != action->text() )
      {
        setField( action->data().toString() );
      }
      setUseExpression( false );
      setActive( true );
      updateGui();
    }
  }
}
Beispiel #28
0
/*!
  Retrieves the record at position \a index, if available, and
  positions the query on the retrieved record. The first record is at
  position 0. Note that the query must be in an \l{isActive()}
  {active} state and isSelect() must return true before calling this
  function.

  If \a relative is false (the default), the following rules apply:

  \list

  \li If \a index is negative, the result is positioned before the
  first record and false is returned.

  \li Otherwise, an attempt is made to move to the record at position
  \a index. If the record at position \a index could not be retrieved,
  the result is positioned after the last record and false is
  returned. If the record is successfully retrieved, true is returned.

  \endlist

  If \a relative is true, the following rules apply:

  \list

  \li If the result is currently positioned before the first record and:
  \list
  \li \a index is negative or zero, there is no change, and false is
  returned.
  \li \a index is positive, an attempt is made to position the result
  at absolute position \a index - 1, following the sames rule for non
  relative seek, above.
  \endlist

  \li If the result is currently positioned after the last record and:
  \list
  \li \a index is positive or zero, there is no change, and false is
  returned.
  \li \a index is negative, an attempt is made to position the result
  at \a index + 1 relative position from last record, following the
  rule below.
  \endlist

  \li If the result is currently located somewhere in the middle, and
  the relative offset \a index moves the result below zero, the result
  is positioned before the first record and false is returned.

  \li Otherwise, an attempt is made to move to the record \a index
  records ahead of the current record (or \a index records behind the
  current record if \a index is negative). If the record at offset \a
  index could not be retrieved, the result is positioned after the
  last record if \a index >= 0, (or before the first record if \a
  index is negative), and false is returned. If the record is
  successfully retrieved, true is returned.

  \endlist

  \sa next(), previous(), first(), last(), at(), isActive(), isValid()
*/
bool QSqlQuery::seek(int index, bool relative)
{
    if (!isSelect() || !isActive())
        return false;
    int actualIdx;
    if (!relative) { // arbitrary seek
        if (index < 0) {
            d->sqlResult->setAt(QSql::BeforeFirstRow);
            return false;
        }
        actualIdx = index;
    } else {
        switch (at()) { // relative seek
        case QSql::BeforeFirstRow:
            if (index > 0)
                actualIdx = index - 1;
            else {
                return false;
            }
            break;
        case QSql::AfterLastRow:
            if (index < 0) {
                d->sqlResult->fetchLast();
                actualIdx = at() + index + 1;
            } else {
                return false;
            }
            break;
        default:
            if ((at() + index) < 0) {
                d->sqlResult->setAt(QSql::BeforeFirstRow);
                return false;
            }
            actualIdx = at() + index;
            break;
        }
    }
    // let drivers optimize
    if (isForwardOnly() && actualIdx < at()) {
        qWarning("QSqlQuery::seek: cannot seek backwards in a forward only query");
        return false;
    }
    if (actualIdx == (at() + 1) && at() != QSql::BeforeFirstRow) {
        if (!d->sqlResult->fetchNext()) {
            d->sqlResult->setAt(QSql::AfterLastRow);
            return false;
        }
        return true;
    }
    if (actualIdx == (at() - 1)) {
        if (!d->sqlResult->fetchPrevious()) {
            d->sqlResult->setAt(QSql::BeforeFirstRow);
            return false;
        }
        return true;
    }
    if (!d->sqlResult->fetch(actualIdx)) {
        d->sqlResult->setAt(QSql::AfterLastRow);
        return false;
    }
    return true;
}
Beispiel #29
0
bool Q3TitleBar::usesActiveColor() const
{
    return (isActive() && isActiveWindow()) ||
        (!window() && QWidget::window()->isActiveWindow());
}
Beispiel #30
0
void QgsMapTool::setCursor( const QCursor &cursor )
{
  mCursor = cursor;
  if ( isActive() )
    mCanvas->setCursor( mCursor );
}