| 1623 | } |
| 1624 | |
| 1625 | void |
| 1626 | OfxChoiceInstance::setOption(int num) |
| 1627 | { |
| 1628 | DYNAMIC_PROPERTY_CHECK(); |
| 1629 | |
| 1630 | /* |
| 1631 | This function can serve 3 type of behaviours depending on num: |
| 1632 | - 0: meaning resetOptions |
| 1633 | - num == nDim - 1: meaning appendOption |
| 1634 | - num == nDim: meaning setOptions |
| 1635 | */ |
| 1636 | int dim = getProperties().getDimension(kOfxParamPropChoiceOption); |
| 1637 | KnobChoicePtr knob = _knob.lock(); |
| 1638 | if (dim == 0) { |
| 1639 | knob->resetChoices(); |
| 1640 | return; |
| 1641 | } |
| 1642 | |
| 1643 | assert(num == dim - 1 || num == dim); |
| 1644 | |
| 1645 | if ( num == (dim - 1) ) { |
| 1646 | ChoiceOption option; |
| 1647 | option.id = getProperties().getStringProperty(kOfxParamPropChoiceOption, num); |
| 1648 | option.label = option.id; |
| 1649 | int labelOptionDim = getProperties().getDimension(kOfxParamPropChoiceLabelOption); |
| 1650 | int optionIDDim = getProperties().getDimension(kOfxParamPropChoiceEnum); |
| 1651 | if (num < optionIDDim) { |
| 1652 | option.id = getProperties().getStringProperty(kOfxParamPropChoiceEnum, num); |
| 1653 | } |
| 1654 | if (num < labelOptionDim) { |
| 1655 | option.tooltip = getProperties().getStringProperty(kOfxParamPropChoiceLabelOption, num); |
| 1656 | } |
| 1657 | knob->appendChoice(option); |
| 1658 | } else if (num == dim) { |
| 1659 | |
| 1660 | int labelOptionDim = getProperties().getDimension(kOfxParamPropChoiceLabelOption); |
| 1661 | assert(labelOptionDim == 0 || labelOptionDim == dim); |
| 1662 | int optionIDDim = getProperties().getDimension(kOfxParamPropChoiceEnum); |
| 1663 | assert(optionIDDim == 0 || optionIDDim == dim); |
| 1664 | std::vector<ChoiceOption> entries(dim); |
| 1665 | for (std::size_t i = 0; i < entries.size(); ++i) { |
| 1666 | entries[i].id = getProperties().getStringProperty(kOfxParamPropChoiceOption, i); |
| 1667 | entries[i].label = entries[i].id; |
| 1668 | if ( (int)i < optionIDDim ) { |
| 1669 | entries[i].id = getProperties().getStringProperty(kOfxParamPropChoiceEnum, i); |
| 1670 | } |
| 1671 | if ( (int)i < labelOptionDim ) { |
| 1672 | entries[i].tooltip = getProperties().getStringProperty(kOfxParamPropChoiceLabelOption, i); |
| 1673 | } |
| 1674 | } |
| 1675 | knob->populateChoices(entries); |
| 1676 | } |
| 1677 | } |
| 1678 | |
| 1679 | KnobIPtr |
| 1680 | OfxChoiceInstance::getKnob() const |
no test coverage detected