| 624 | } |
| 625 | |
| 626 | void ColorPicker::OnColorSpectrumControlGotFocus(const IInspectable &, const wux::RoutedEventArgs &) |
| 627 | { |
| 628 | Windows::UI::Color rgbColor = m_ColorSpectrumControl.Color(); |
| 629 | |
| 630 | /* If this control has a color that is currently empty (#00000000), |
| 631 | * selecting a new color directly in the spectrum will fail. This is |
| 632 | * a bug in the color spectrum. Selecting a new color in the spectrum will |
| 633 | * keep zero for all channels (including alpha and the third dimension). |
| 634 | * |
| 635 | * In practice this means a new color cannot be selected using the spectrum |
| 636 | * until both the alpha and third dimension slider are raised above zero. |
| 637 | * This is extremely user unfriendly and must be corrected as best as possible. |
| 638 | * |
| 639 | * In order to work around this, detect when the color spectrum has selected |
| 640 | * a new color and then automatically set the alpha and third dimension |
| 641 | * channel to maximum. However, the color spectrum has a second bug, the |
| 642 | * ColorChanged event is never raised if the color is empty. This prevents |
| 643 | * automatically setting the other channels where it normally should be done |
| 644 | * (in the ColorChanged event). |
| 645 | * |
| 646 | * In order to work around this second bug, the GotFocus event is used |
| 647 | * to detect when the spectrum is engaged by the user. It's somewhat equivalent |
| 648 | * to ColorChanged for this purpose. Then when the GotFocus event is fired |
| 649 | * set the alpha and third channel values to maximum. The problem here is that |
| 650 | * the GotFocus event does not have access to the new color that was selected |
| 651 | * in the spectrum. It is not available due to the afore mentioned bug or due to |
| 652 | * timing. This means the best that can be done is to just set a 'neutral' |
| 653 | * color such as white. |
| 654 | * |
| 655 | * There is still a small usability issue with this as it requires two |
| 656 | * presses to set a color. That's far better than having to slide up both |
| 657 | * sliders though. |
| 658 | * |
| 659 | * 1. If the color is empty, the first press on the spectrum will set white |
| 660 | * and ignore the pressed color on the spectrum |
| 661 | * 2. The second press on the spectrum will be correctly handled. |
| 662 | * |
| 663 | */ |
| 664 | |
| 665 | if (rgbColor == Windows::UI::Color { }) |
| 666 | { |
| 667 | ScheduleColorUpdate({ 0xFF, 0xFF, 0xFF, 0xFF }); |
| 668 | } |
| 669 | else if (rgbColor.A == 0x00) |
| 670 | { |
| 671 | // As an additional usability improvement, reset alpha to maximum when the spectrum is used. |
| 672 | // The color spectrum has no alpha channel and it is much more intuitive to do this for the user |
| 673 | // especially if the picker was initially set with Colors.Transparent. |
| 674 | rgbColor.A = 0xFF; |
| 675 | ScheduleColorUpdate(rgbColor); |
| 676 | } |
| 677 | } |
| 678 | |
| 679 | template<txmp::ColorRepresentation representation> |
| 680 | void ColorPicker::OnColorRepresentationToggleButtonCheckedChanged(const IInspectable &, const wux::RoutedEventArgs &) |