Example #1
0
void DlgMatchResult::updateControls()
{
  // is a third game necessary?
  bool game3Necessary = isGame3Necessary();

  // enable or disable the widget for the 3rd game
  ui->game3Widget->setEnabled(game3Necessary);

  // is the currently selected result valid?
  bool validResult = hasValidResult();

  // enable or disable the okay-button
  ui->btnOkay->setEnabled(validResult);

  // hide the winner / loser / draw labels if we have no valid result
  if (!validResult)
  {
    ui->laWinnerName->setVisible(false);
    ui->laLoserName->setVisible(false);
    ui->laDraw->setVisible(false);
  } else {
    auto sc1 = ui->game1Widget->getScore();
    auto sc2 = ui->game2Widget->getScore();
    assert(sc1 != nullptr);
    assert(sc2 != nullptr);

    // switch the "draw" label on or off
    bool isDraw = (!game3Necessary && (sc1->getWinner() != sc2->getWinner()));
    ui->laDraw->setVisible(isDraw);

    // switch / set the winner label
    auto matchScore = getMatchScore();
    assert(matchScore != nullptr);
    QString winnerLabel;
    QString loserLabel;
    if (matchScore->getWinner() == 1)
    {
      winnerLabel = ma.getPlayerPair1().getDisplayName();
      loserLabel = ma.getPlayerPair2().getDisplayName();
    } else {
      winnerLabel = ma.getPlayerPair2().getDisplayName();
      loserLabel = ma.getPlayerPair1().getDisplayName();
    }
    if (!isDraw)
    {
      ui->laWinnerName->setVisible(true);
      ui->laWinnerName->setText(tr("Winner: ") + winnerLabel);
      ui->laLoserName->setVisible(true);
      ui->laLoserName->setText(tr("Loser: ") + loserLabel);
    } else {
      ui->laWinnerName->setVisible(false);
      ui->laLoserName->setVisible(false);
    }
  }

}
void mexFunction( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[] )
{
    enum{indH, valH, X}; // Input
    enum{MatchScore}; // Output
    
    int* pIndH;
    double* pValH;
    double* pX;
    
    int size = mxGetM(prhs[0]);
    pIndH = (int*)mxGetPr(prhs[indH]);
    pValH = mxGetPr(prhs[valH]);
    pX = mxGetPr(prhs[X]);
    
    plhs[MatchScore] = mxCreateDoubleScalar(mxREAL);
    double* pMatchScore = mxGetPr(plhs[MatchScore]);
    
    getMatchScore(pIndH, pValH, size, pX, pMatchScore);
}