Пример #1
0
void WVuMeter::paintEvent(QPaintEvent *) {
    ScopedTimer t("WVuMeter::paintEvent");

    QStyleOption option;
    option.initFrom(this);
    QStylePainter p(this);
    p.drawPrimitive(QStyle::PE_Widget, option);

    if (!m_pPixmapBack.isNull() && !m_pPixmapBack->isNull()) {
        // Draw background.
        m_pPixmapBack->draw(0, 0, &p);
    }

    if (!m_pPixmapVu.isNull() && !m_pPixmapVu->isNull()) {
        int idx = static_cast<int>(getControlParameterDisplay() * m_iNoPos);

        // Range check
        if (idx > m_iNoPos)
            idx = m_iNoPos;
        else if (idx < 0)
            idx = 0;


        // Draw (part of) vu
        if (m_bHorizontal) {
            // This is a hack to fix something weird with horizontal VU meters:
            if (idx == 0)
                idx = 1;

            QPointF targetPoint(0, 0);
            QRectF sourceRect(0, 0, idx, m_pPixmapVu->height());
            m_pPixmapVu->draw(targetPoint, &p, sourceRect);

            if(m_iPeakHoldSize > 0 && m_iPeakPos > 0) {
                targetPoint = QPointF(m_iPeakPos - m_iPeakHoldSize, 0);
                sourceRect = QRectF(m_iPeakPos - m_iPeakHoldSize, 0,
                                    m_iPeakHoldSize, m_pPixmapVu->height());
                m_pPixmapVu->draw(targetPoint, &p, sourceRect);
            }
        } else {
            QPointF targetPoint(0, m_iNoPos - idx);
            QRectF sourceRect(0, m_iNoPos - idx, m_pPixmapVu->width(), idx);
            m_pPixmapVu->draw(targetPoint, &p, sourceRect);

            if (m_iPeakHoldSize > 0 && m_iPeakPos > 0) {
                targetPoint = QPointF(0, m_pPixmapVu->height() - m_iPeakPos);
                sourceRect = QRectF(0, m_pPixmapVu->height() - m_iPeakPos,
                                    m_pPixmapVu->width(), m_iPeakHoldSize);
                m_pPixmapVu->draw(targetPoint, &p, sourceRect);
            }
        }
    }
}
Пример #2
0
void WVuMeter::paintEvent(QPaintEvent *) {
    ScopedTimer t("WVuMeter::paintEvent");

    QStyleOption option;
    option.initFrom(this);
    QStylePainter p(this);
    p.drawPrimitive(QStyle::PE_Widget, option);

    if (!m_pPixmapBack.isNull() && !m_pPixmapBack->isNull()) {
        // Draw background.
        m_pPixmapBack->draw(0, 0, &p);
    }

    if (!m_pPixmapVu.isNull() && !m_pPixmapVu->isNull()) {
        // Draw (part of) vu
        if (m_bHorizontal) {
            // This is a hack to fix something weird with horizontal VU meters:
            if (m_iPos == 0)
                m_iPos = 1;

            QPointF targetPoint(0, 0);
            QRectF sourceRect(0, 0, m_iPos, m_pPixmapVu->height());
            m_pPixmapVu->draw(targetPoint, &p, sourceRect);

            if(m_iPeakHoldSize > 0 && m_iPeakPos > 0) {
                targetPoint = QPointF(m_iPeakPos - m_iPeakHoldSize, 0);
                sourceRect = QRectF(m_iPeakPos - m_iPeakHoldSize, 0,
                                    m_iPeakHoldSize, m_pPixmapVu->height());
                m_pPixmapVu->draw(targetPoint, &p, sourceRect);
            }
        } else {
            QPointF targetPoint(0, m_iNoPos - m_iPos);
            QRectF sourceRect(0, m_iNoPos - m_iPos, m_pPixmapVu->width(), m_iPos);
            m_pPixmapVu->draw(targetPoint, &p, sourceRect);

            if (m_iPeakHoldSize > 0 && m_iPeakPos > 0) {
                targetPoint = QPointF(0, m_pPixmapVu->height() - m_iPeakPos);
                sourceRect = QRectF(0, m_pPixmapVu->height() - m_iPeakPos,
                                    m_pPixmapVu->width(), m_iPeakHoldSize);
                m_pPixmapVu->draw(targetPoint, &p, sourceRect);
            }
        }
    }
    m_iLastPos = m_iPos;
    m_iLastPeakPos = m_iPeakPos;
}
Пример #3
0
void PlayerUIDialog::ExecuteMoveOrMeleeAttack(RPG_Character* characterEntity)
{
  VASSERT(characterEntity);

#if defined (SUPPORTS_MULTITOUCH) && (HAVOK_VISION_RESTRUCTURING) && !defined(_VISION_ANDROID)

  // Wait 0.1 seconds in case player uses multi touch 
  if (m_wasPressedTime < 0.f)
  {
    m_wasPressedTime = Vision::GetTimer()->GetTime();
    return;
  }
  else if (Vision::GetTimer()->GetTime() - m_wasPressedTime < 0.1f)
  {
    return;
  }

#endif

//#ifdef _DEBUG
//  const VString msg = "Execute Primary Action.";
//  //Vision::Error.SystemMessage(msg.AsChar());
//  Vision::Message.Add(1, msg.AsChar());
//#endif

  const bool inputEdge = !m_wasDown_PlayerMoveOrMelee; // if primary action input is activated now, and wasn't previously, this is a press event.

  // Get the location of the player input and information about any hit object
  RPG_DamageableEntity* attackableEntity = NULL;
  hkvVec3 targetPoint(0.0f, 0.0f, 0.0f);
  GetFirstAttackableEntityUnderCursor(attackableEntity, targetPoint, characterEntity);

  if(attackableEntity)
  {
    // Hit an object
    if (inputEdge || attackableEntity != m_lastTargetEntity)
    {
      // Initial press event, or a continued press that slipped from one entity to another
      TryMeleeAttack(characterEntity, attackableEntity);
    }
    else
    {
      // Continued hold
      ContinueMeleeAttack(characterEntity, attackableEntity);
    }
  }
  else
  {
    // No object hit
    if (!characterEntity->IsAttacking())  // don't terminate an attack mid-swing
    {
      RequestMove(characterEntity, inputEdge);
    }
  }
  m_lastTargetEntity = attackableEntity;
  m_lastTargetPoint = targetPoint;
  m_wasDown_PlayerMoveOrMelee = true;
}
Пример #4
0
void SceneService::updateCamera()
{
    gameplay::Vector3 targetPoint(0.0f, 0.0f, 0.0f);

    //if (_vehicleCollision)
    //    targetPoint = _vehicleCollision->getBBox().getCenter();

    gameplay::Vector3 translate(sinf(_cameraPhi) * cosf(_cameraTheta), sinf(_cameraTheta), cosf(_cameraPhi) * cosf(_cameraTheta));
    translate *= _cameraDistance;
    translate += targetPoint;

    gameplay::Matrix transform;
    gameplay::Matrix::createLookAt(translate, targetPoint, gameplay::Vector3::unitY(), &transform);

    gameplay::Quaternion rotation;
    transform.decompose(NULL, &rotation, NULL);
    _camera->getNode()->set(gameplay::Vector3::one(), rotation, translate);
}
Пример #5
0
void PlayerUIDialog::ExecutePowerAttack(RPG_Character* characterEntity)
{
  VASSERT(characterEntity);

  if (!characterEntity->IsDoingSpecialAttack())
  {
  if (TrySpendMana(characterEntity, characterEntity->GetCharacterActionData().GetPowerAttackManaCost())) // @todo: data-drive action mana costs
  {
    RPG_DamageableEntity* attackableEntity = NULL;
    hkvVec3 targetPoint(0.0f, 0.0f, 0.0f);
    if(GetFirstAttackableEntityUnderCursor(attackableEntity, targetPoint, characterEntity))
    {
      characterEntity->GetActionHandler().PerformAction(AT_PowerAttack, true, attackableEntity, targetPoint);
    }
    else
    {
      characterEntity->GetActionHandler().PerformAction(AT_PowerAttack, true, NULL, m_lastTargetPoint);
    }
    m_lastTargetEntity = attackableEntity;
    m_lastTargetPoint = targetPoint;
  }
  }
}
Пример #6
0
void PlayerUIDialog::ExecuteOrContinueRangedAttack(RPG_Character* characterEntity)
{
#ifdef _DEBUG
  const VString msg = "Execute or Continue Ranged Attack.";
  //Vision::Error.SystemMessage(msg.AsChar());
  Vision::Message.Add(1, msg.AsChar());
#endif

  const bool inputEdge = !m_wasDown_PlayerRangedAttack; // if ranged attack input is activated now, and wasn't previously, this is a press event.

  RPG_DamageableEntity* attackableEntity = NULL;
  hkvVec3 targetPoint(0.0f, 0.0f, 0.0f);
  GetFirstAttackableEntityUnderCursor(attackableEntity, targetPoint, characterEntity);
  // TODO - intersect ray with horizontal plane at characterEntity's root node if this returns false
  // TODO - modify static mesh target height based on normal of interaction point

  if(inputEdge)
  {
    // Initial press event, or a continued press that slipped from one entity to another
    ExecuteRangedAttack(characterEntity, attackableEntity, targetPoint);
  }
  else
  {
    if(attackableEntity != m_lastTargetEntity ||
       !targetPoint.isIdentical(m_lastTargetPoint))
    {
      // updates interaction data for currently active ranged attack action
      ExecuteRangedAttack(characterEntity, attackableEntity, targetPoint);
    }

    // continued hold
    ContinueRangedAttack(characterEntity);
  }
  m_lastTargetEntity = attackableEntity;
  m_lastTargetPoint = targetPoint;
  m_wasDown_PlayerRangedAttack = true;
}
Пример #7
0
QScriptValue MainWindow::sendEvent(QScriptContext *context, QScriptEngine *interpreter)
{
    if (context->argumentCount() == 0)
        return QScriptValue::UndefinedValue;

    QScriptValue argPoint = context->argument(0);
    QScriptValue argEvt = context->argument(1);
    QScriptValue argKey = context->argument(2);

    if (!argPoint.isObject())
        return QScriptValue::UndefinedValue;


    // 构造事件触发位置默认值
    int x = 0;
    int y = 0;
    if (argPoint.property("x").isNumber())
        x = argPoint.property("x").toString().toInt();
    if (argPoint.property("y").isNumber())
        y = argPoint.property("y").toString().toInt();

    QPoint targetPoint(x, y);

    // 构造默认值鼠标事件类型默认值
    QMap<QString, QEvent::Type> mouseEventTypeMap;
    mouseEventTypeMap.insert("mousedown", QMouseEvent::MouseButtonPress);
    mouseEventTypeMap.insert("mouseup", QMouseEvent::MouseButtonRelease);
    mouseEventTypeMap.insert("mousemove", QMouseEvent::MouseMove);

    QMouseEvent::Type mouseEvtType = QMouseEvent::MouseButtonRelease;
    QString mouseEvtTypeStr = (!argEvt.isString()) ? "click"
                                                   : argEvt.toString().toLower();
    if (mouseEventTypeMap.contains(mouseEvtTypeStr))
        mouseEvtType = mouseEventTypeMap[mouseEvtTypeStr];

    // 构造辅助按键默认值
    QMap<QString, Qt::KeyboardModifier> keyTypeMap;
    keyTypeMap.insert("shift", Qt::ShiftModifier);
    keyTypeMap.insert("ctrl", Qt::ShiftModifier);
    keyTypeMap.insert("alt", Qt::ShiftModifier);

    Qt::KeyboardModifier keyType = Qt::NoModifier;
    QString keyTypeStr = argKey.toString().toLower();
    if (keyTypeMap.contains(keyTypeStr))
        keyType = keyTypeMap[keyTypeStr];

    // 修复鼠标移动事件的按键值,API原文说明:
    // If the event type is MouseMove,
    // the appropriate button for this event is Qt::NoButton.
    QMouseEvent* event;
    if (mouseEvtType == QMouseEvent::MouseMove) {
        event = new QMouseEvent(mouseEvtType, targetPoint,
                                Qt::NoButton, Qt::NoButton, keyType);
    } else {
        event = new QMouseEvent(mouseEvtType, targetPoint,
                                Qt::LeftButton, Qt::LeftButton, keyType);
    }

    // 对click操作做特殊处理,他是mousdown与mouseup操作的结合体
    if (mouseEvtTypeStr == "click") {
        QMouseEvent* clickEvt1 = new QMouseEvent(QMouseEvent::MouseButtonPress, targetPoint,
                                Qt::LeftButton, Qt::LeftButton, keyType);
        QMouseEvent* clickEvt2 = new QMouseEvent(QMouseEvent::MouseButtonRelease, targetPoint,
                                Qt::LeftButton, Qt::LeftButton, keyType);
        bool b = QApplication::sendEvent(webView, clickEvt1) &&
                 QApplication::sendEvent(webView, clickEvt2);

        delete clickEvt1;
        delete clickEvt2;
        return b;
    }

    bool b = QApplication::sendEvent(webView, event);
    delete event;
    return b;
}
Пример #8
0
void MyGame3DDevice::InitSceneEffectShader()
{
    // load shader
    HRSRC hResource = ::FindResource( NULL, MAKEINTRESOURCE(IDR_PIXEL_SHADER2), RT_RCDATA );
    HGLOBAL hResourceData = ::LoadResource( NULL, hResource );
    LPVOID pData = ::LockResource( hResourceData );

    ID3DXBuffer* errorBuffer = 0;
    HR( D3DXCreateEffect( pD3D9InstanceDevice,
                          pData,
                          ::SizeofResource( NULL, hResource ),
                          0,
                          0,
                          0,
                          0,
                          &mFX,
                          &errorBuffer ) );
    if( errorBuffer )
    {
        MyGameMessage( (char*)errorBuffer->GetBufferPointer() );
        errorBuffer->Release();
        return;
    }

    //initialize matrix in shader

    D3DXMATRIX worldMatrix;

    D3DXMatrixTranslation( &worldMatrix, -512.0f, -384.0f, 0 );

    D3DXVECTOR3 position( 0.0f, 0.0f, 20.0f );
    D3DXVECTOR3 targetPoint( 0.0f, 0.0f ,0.0f );
    D3DXVECTOR3 upVector( 0.0f, -1.0f, 0.0f );

    D3DXMATRIX	viewMatrix;

    D3DXMatrixLookAtLH( &viewMatrix, &position, &targetPoint, &upVector );

    D3DXMATRIX  projMatrix;

    D3DXMatrixOrthoLH( &projMatrix, 1024.0f, 768.0f, -1009.0f, 5000.0f );

    D3DXMatrixTranslation( &uiMoveMatrix, 0.0f, 0.0f, 0 );

    mhUIWorldMatHandle	= mFX->GetParameterByName( 0, worldMatName );
    mhUIViewMatHandle	= mFX->GetParameterByName( 0, viewMatName );
    mhUIProjMatHandle	= mFX->GetParameterByName( 0, projMatName );
    mhUIMoveMatHandle	= mFX->GetParameterByName( 0, moveMatName );
    mhAlphaEnabled		= mFX->GetParameterByName( 0, "alphaEnable" );
    D3DXHANDLE mhTech	= mFX->GetTechniqueByName( techniqueName );

    mhTex = mFX->GetParameterByName( 0, "gTex" );

    mFX->SetMatrix( mhUIWorldMatHandle, &worldMatrix );
    mFX->SetMatrix( mhUIViewMatHandle, &viewMatrix );
    mFX->SetMatrix( mhUIProjMatHandle, &projMatrix );
    mFX->SetMatrix( mhUIMoveMatHandle, &uiMoveMatrix );

    mFX->SetTechnique( mhTech );

    HR(mFX->SetBool( mhAlphaEnabled, FALSE ));

    return;
}