@@ -630,20 +630,28 @@ void Pip::RendererGL::paintButton(
630630
631631auto Pip::RendererGL::ControlMeta (OverState control, int index)
632632-> Control {
633+ if (const auto result = FindControlMeta (control, index)) {
634+ return *result;
635+ }
636+ Unexpected (" Control value in Pip::RendererGL::ControlIndex." );
637+ }
638+
639+ auto Pip::Renderer::FindControlMeta (OverState control, int index)
640+ -> std::optional<Control> {
633641 Expects (index >= 0 );
634642
635643 switch (control) {
636- case OverState::Close: Assert (index < 1 ); return {
644+ case OverState::Close: Assert (index < 1 ); return Control {
637645 0 ,
638646 &st::pipCloseIcon,
639647 &st::pipCloseIconOver,
640648 };
641- case OverState::Enlarge: Assert (index < 1 ); return {
649+ case OverState::Enlarge: Assert (index < 1 ); return Control {
642650 1 ,
643651 &st::pipEnlargeIcon,
644652 &st::pipEnlargeIconOver,
645653 };
646- case OverState::VolumeToggle: Assert (index < 3 ); return {
654+ case OverState::VolumeToggle: Assert (index < 3 ); return Control {
647655 (2 + index),
648656 (index == 0
649657 ? &st::pipVolumeIcon0
@@ -656,13 +664,13 @@ auto Pip::RendererGL::ControlMeta(OverState control, int index)
656664 ? &st::pipVolumeIcon1Over
657665 : &st::pipVolumeIcon2Over),
658666 };
659- case OverState::Other: Assert (index < 2 ); return {
667+ case OverState::Other: Assert (index < 2 ); return Control {
660668 (5 + index),
661669 (index ? &st::pipPauseIcon : &st::pipPlayIcon),
662670 (index ? &st::pipPauseIconOver : &st::pipPlayIconOver),
663671 };
664672 }
665- Unexpected ( " Control value in Pip::RendererGL::ControlIndex. " ) ;
673+ return std:: nullopt ;
666674}
667675
668676void Pip::RendererGL::validateControls () {
@@ -678,6 +686,14 @@ void Pip::RendererGL::validateControls() {
678686 ControlMeta (OverState::Other),
679687 ControlMeta (OverState::Other, 1 ),
680688 };
689+ _controlsImage.setImage (
690+ PrepareControlsImage (metas, _controlsTextures, _ifactor));
691+ }
692+
693+ QImage Pip::Renderer::PrepareControlsImage (
694+ std::initializer_list<Control> metas,
695+ std::array<QRect, kControlsCount * 2 > &textures,
696+ int factor) {
681697 auto maxWidth = 0 ;
682698 auto fullHeight = 0 ;
683699 for (const auto &meta : metas) {
@@ -686,27 +702,27 @@ void Pip::RendererGL::validateControls() {
686702 fullHeight += 2 * meta.icon ->height ();
687703 }
688704 auto image = QImage (
689- QSize (maxWidth, fullHeight) * _ifactor ,
705+ QSize (maxWidth, fullHeight) * factor ,
690706 QImage::Format_ARGB32_Premultiplied);
691707 image.fill (Qt::transparent);
692- image.setDevicePixelRatio (_ifactor );
708+ image.setDevicePixelRatio (factor );
693709 {
694710 auto p = QPainter (&image);
695711 auto index = 0 ;
696712 auto height = 0 ;
697713 const auto paint = [&](not_null<const style::icon*> icon) {
698714 icon->paint (p, 0 , height, maxWidth);
699- _controlsTextures [index++] = QRect (
700- QPoint (0 , height) * _ifactor ,
701- icon->size () * _ifactor );
715+ textures [index++] = QRect (
716+ QPoint (0 , height) * factor ,
717+ icon->size () * factor );
702718 height += icon->height ();
703719 };
704720 for (const auto &meta : metas) {
705721 paint (meta.icon );
706722 paint (meta.iconOver );
707723 }
708724 }
709- _controlsImage. setImage ( std::move ( image)) ;
725+ return image;
710726}
711727
712728void Pip::RendererGL::invalidateControls () {
0 commit comments