VideoPage.xaml.cpp 38.6 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
/**************************************************************************
* Copyright (C) 2016 by Savoir-faire Linux                                *
* Author: Jger Nicolas <nicolas.jager@savoirfairelinux.com>              *
* Author: Traczyk Andreas <andreas.traczyk@savoirfairelinux.com>          *
*                                                                         *
* This program is free software; you can redistribute it and/or modify    *
* it under the terms of the GNU General Public License as published by    *
* the Free Software Foundation; either version 3 of the License, or       *
* (at your option) any later version.                                     *
*                                                                         *
* This program is distributed in the hope that it will be useful,         *
* but WITHOUT ANY WARRANTY; without even the implied warranty of          *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           *
* GNU General Public License for more details.                            *
*                                                                         *
* You should have received a copy of the GNU General Public License       *
* along with this program.  If not, see <http://www.gnu.org/licenses/>.   *
**************************************************************************/
Nicolas Jager's avatar
Nicolas Jager committed
19 20 21 22
#include "pch.h"

#include "VideoPage.xaml.h"

atraczyk's avatar
atraczyk committed
23 24
#include <MemoryBuffer.h>   // IMemoryBufferByteAccess

Nicolas Jager's avatar
Nicolas Jager committed
25
using namespace RingClientUWP::Views;
Nicolas Jager's avatar
Nicolas Jager committed
26
using namespace ViewModel;
atraczyk's avatar
atraczyk committed
27
using namespace Video;
Nicolas Jager's avatar
Nicolas Jager committed
28 29 30 31 32 33 34 35 36 37 38 39 40 41

using namespace Concurrency;
using namespace Platform;
using namespace Windows::Devices::Enumeration;
using namespace Windows::Foundation;
using namespace Windows::Foundation::Collections;
using namespace Windows::UI::Xaml;
using namespace Windows::UI::Xaml::Controls;
using namespace Windows::UI::Xaml::Controls::Primitives;
using namespace Windows::UI::Xaml::Data;
using namespace Windows::UI::Xaml::Input;
using namespace Windows::UI::Xaml::Media;
using namespace Windows::UI::Xaml::Navigation;
using namespace Windows::Media::Capture;
42 43
using namespace Windows::ApplicationModel::Core;
using namespace Windows::UI::Core;
44
using namespace Windows::UI;
Nicolas Jager's avatar
Nicolas Jager committed
45

atraczyk's avatar
atraczyk committed
46 47 48 49
using namespace Windows::Graphics::Display;
using namespace Windows::Graphics::Imaging;
using namespace Windows::Media;
using namespace Windows::UI::Xaml::Media::Imaging;
50 51
using namespace Windows::UI::Xaml::Media::Animation;
using namespace Windows::UI::Xaml::Shapes;
atraczyk's avatar
atraczyk committed
52 53
using namespace Windows::Devices::Sensors;

54 55
using namespace Windows::UI::Input;

Nicolas Jager's avatar
Nicolas Jager committed
56 57 58 59
VideoPage::VideoPage()
{
    InitializeComponent();

60 61
    barFading = true;

atraczyk's avatar
atraczyk committed
62 63 64 65 66
    Page::NavigationCacheMode = Navigation::NavigationCacheMode::Required;

    VideoManager::instance->rendererManager()->writeVideoFrame +=
        ref new WriteVideoFrame([this](String^ id, uint8_t* buf, int width, int height)
    {
67
        CoreApplication::MainView->CoreWindow->Dispatcher->RunAsync(CoreDispatcherPriority::High,
atraczyk's avatar
atraczyk committed
68 69
        ref new DispatchedHandler([=]() {
            try {
70 71
                currentRendererWrapper = VideoManager::instance->rendererManager()->renderer(id);
                if (!currentRendererWrapper) {
atraczyk's avatar
atraczyk committed
72
                    return;
73 74
                }
                else {
75
                    currentRendererWrapper->isRendering = true;
76 77 78 79 80 81
                    create_task(WriteFrameAsSoftwareBitmapAsync(id, buf, width, height))
                    .then([=](task<void> previousTask) {
                        try {
                            previousTask.get();
                        }
                        catch (Platform::Exception^ e) {
82
                            EXC_(e);
83 84 85
                        }
                    });
                }
atraczyk's avatar
atraczyk committed
86 87
            }
            catch(Platform::COMException^ e) {
88
                EXC_(e);
atraczyk's avatar
atraczyk committed
89 90 91 92 93 94 95
            }
        }));
    });

    VideoManager::instance->captureManager()->startPreviewing +=
        ref new StartPreviewing([this]()
    {
96 97 98
        _PreviewImage_->Visibility = Windows::UI::Xaml::Visibility::Visible;
        _PreviewImageResizer_->Visibility = Windows::UI::Xaml::Visibility::Visible;
        _PreviewImage_->FlowDirection = VideoManager::instance->captureManager()->mirroringPreview ?
99 100
                                      Windows::UI::Xaml::FlowDirection::RightToLeft :
                                      Windows::UI::Xaml::FlowDirection::LeftToRight;
101 102 103 104 105 106 107

        double aspectRatio = VideoManager::instance->captureManager()->aspectRatio();

        _PreviewImage_->Height = ( _videoContent_->ActualHeight / 4 );
        _PreviewImage_->Width = _PreviewImage_->Height * aspectRatio;
        _PreviewImageRect_->Width = _PreviewImage_->Width;
        _PreviewImageRect_->Height = _PreviewImage_->Height;
atraczyk's avatar
atraczyk committed
108 109 110 111 112
    });

    VideoManager::instance->captureManager()->stopPreviewing +=
        ref new StopPreviewing([this]()
    {
113 114 115
        _PreviewImage_->Source = nullptr;
        _PreviewImage_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
        _PreviewImageResizer_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
atraczyk's avatar
atraczyk committed
116 117 118 119 120
    });

    VideoManager::instance->captureManager()->getSink +=
        ref new GetSink([this]()
    {
121
        return _PreviewImage_;
atraczyk's avatar
atraczyk committed
122 123 124 125 126
    });

    VideoManager::instance->rendererManager()->clearRenderTarget +=
        ref new ClearRenderTarget([this]()
    {
127 128 129 130
        _IncomingVideoImage_->Source = nullptr;
    });

    RingD::instance->windowResized +=
131
        ref new WindowResized([=](float width, float height)
132
    {
atraczyk's avatar
atraczyk committed
133 134 135 136 137 138 139 140
    });

    RingD::instance->incomingAccountMessage +=
        ref new IncomingAccountMessage([&](String^ accountId, String^ from, String^ payload)
    {
        scrollDown();
    });

141 142 143 144 145 146 147 148
    RingD::instance->vCardUpdated += ref new VCardUpdated([&](Contact^ contact)
    {
        Utils::runOnUIThread([this, contact]() {
            SmartPanelItemsViewModel::instance->update({ "_bestName2", "_avatarImage" });
            updatePageContent();
        });
    });

atraczyk's avatar
atraczyk committed
149 150 151
    RingD::instance->stateChange +=
        ref new StateChange([&](String^ callId, CallStatus state, int code)
    {
152 153 154 155 156 157 158 159
        switch (state) {
        case CallStatus::IN_PROGRESS:
        {
            for (auto it : SmartPanelItemsViewModel::instance->itemsList)
                if (it->_callStatus != CallStatus::IN_PROGRESS && it->_callId != callId)
                    RingD::instance->pauseCall(Utils::toString(it->_callId));

            _callPaused_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
160
            _IncomingVideoImage_->Visibility = Windows::UI::Xaml::Visibility::Visible;
161 162 163 164 165 166 167 168

            callTimerUpdater->Start();
            updateCallTimer(nullptr, nullptr);

            RingD::instance->startSmartInfo(500);
            videoPage_InputHandlerToken = Window::Current->CoreWindow->KeyDown +=
                ref new TypedEventHandler<CoreWindow^, KeyEventArgs^>(this, &VideoPage::_corewindow__KeyDown);

169 170 171
            break;
        }
        case CallStatus::ENDED:
172
        {
atraczyk's avatar
atraczyk committed
173
            Video::VideoManager::instance->rendererManager()->raiseClearRenderTarget();
Nicolas Jager's avatar
Nicolas Jager committed
174

175 176
            if (RingD::instance->isFullScreen)
                RingD::instance->setWindowedMode();
177

Nicolas Jager's avatar
Nicolas Jager committed
178
            /* "close" the chat panel */
179 180 181 182 183 184 185
            closeChatPanel();

            callTimerUpdater->Stop();

            //RingD::instance->stopSmartInfo();
            Window::Current->CoreWindow->KeyDown -= videoPage_InputHandlerToken;
            _smartInfoBorder_->Visibility = VIS::Collapsed;
Nicolas Jager's avatar
Nicolas Jager committed
186

187
            break;
188
        }
189 190 191
        case CallStatus::PEER_PAUSED:
        case CallStatus::PAUSED:
            _callPaused_->Visibility = Windows::UI::Xaml::Visibility::Visible;
192
            _IncomingVideoImage_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
193
            break;
atraczyk's avatar
atraczyk committed
194 195 196
        }
    });

197 198 199 200
    RingD::instance->messageDataLoaded += ref new MessageDataLoaded([&]() { scrollDown(); });

    RingD::instance->updateSmartInfo += ref new RingClientUWP::UpdateSmartInfo(this, &RingClientUWP::Views::VideoPage::OnsmartInfoUpdated);

201
    RingD::instance->incomingMessage += ref new RingClientUWP::IncomingMessage(this, &RingClientUWP::Views::VideoPage::OnincomingMessage);
202
    RingD::instance->incomingVideoMuted += ref new RingClientUWP::IncomingVideoMuted(this, &RingClientUWP::Views::VideoPage::OnincomingVideoMuted);
203 204
    VideoManager::instance->captureManager()->startPreviewing += ref new RingClientUWP::StartPreviewing(this, &RingClientUWP::Views::VideoPage::OnstartPreviewing);
    VideoManager::instance->captureManager()->stopPreviewing += ref new RingClientUWP::StopPreviewing(this, &RingClientUWP::Views::VideoPage::OnstopPreviewing);
205
    RingD::instance->audioMuted += ref new RingClientUWP::AudioMuted(this, &RingClientUWP::Views::VideoPage::OnaudioMuted);
206
    RingD::instance->videoMuted += ref new RingClientUWP::VideoMuted(this, &RingClientUWP::Views::VideoPage::OnvideoMuted);
207 208 209 210 211

    InitManipulationTransforms();

    _PreviewImage_->ManipulationDelta += ref new ManipulationDeltaEventHandler(this, &VideoPage::PreviewImage_ManipulationDelta);
    _PreviewImage_->ManipulationCompleted += ref new ManipulationCompletedEventHandler(this, &VideoPage::PreviewImage_ManipulationCompleted);
212 213 214
    _PreviewImage_->ManipulationMode =
        ManipulationModes::TranslateX |
        ManipulationModes::TranslateY;
215 216 217

    _PreviewImageResizer_->ManipulationDelta += ref new ManipulationDeltaEventHandler(this, &VideoPage::PreviewImageResizer_ManipulationDelta);
    _PreviewImageResizer_->ManipulationCompleted += ref new ManipulationCompletedEventHandler(this, &VideoPage::PreviewImageResizer_ManipulationCompleted);
218
    _PreviewImageResizer_->ManipulationMode = ManipulationModes::TranslateY;
219

220 221 222
    _chatPanelResizeBarGrid_->ManipulationDelta += ref new ManipulationDeltaEventHandler(this, &VideoPage::_chatPanelResizeBarGrid__ManipulationDelta);
    _chatPanelResizeBarGrid_->ManipulationCompleted += ref new ManipulationCompletedEventHandler(this, &VideoPage::_chatPanelResizeBarGrid__ManipulationCompleted);
    _chatPanelResizeBarGrid_->ManipulationMode =
223 224 225
        ManipulationModes::TranslateX |
        ManipulationModes::TranslateY;

226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272
    TimeSpan timeSpan;
    timeSpan.Duration = static_cast<long long>(1e7);
    callTimerUpdater = ref new DispatcherTimer;
    callTimerUpdater->Interval = timeSpan;
    callTimerUpdater->Tick += ref new Windows::Foundation::EventHandler<Object^>(this, &VideoPage::updateCallTimer);

    showSmartInfo = false;
}

void
VideoPage::OnsmartInfoUpdated(const std::map<std::string, std::string>& info)
{
    auto smartInfo = Utils::convertMap(info);

    if (auto selectedItem = SmartPanelItemsViewModel::instance->_selectedItem)
        _si_CallId_->Text = "CallID: " + selectedItem->_callId;

    if (smartInfo->HasKey("local FPS"))
        _si_fps1_->Text = smartInfo->Lookup("local FPS");
    if (smartInfo->HasKey("local video codec"))
        _si_vc1_->Text = smartInfo->Lookup("local video codec");
    if (smartInfo->HasKey("local audio codec"))
        _si_ac1_->Text = smartInfo->Lookup("local audio codec");

    auto localResolution = VideoManager::instance->captureManager()->activeDevice->currentResolution();
    _si_res1_->Text = localResolution->getFriendlyName();

    if (smartInfo->HasKey("remote FPS"))
        _si_fps2_->Text = smartInfo->Lookup("remote FPS") ;
    if (smartInfo->HasKey("remote video codec"))
        _si_vc2_->Text = smartInfo->Lookup("remote video codec");
    if (smartInfo->HasKey("remote audio codec"))
        _si_ac2_->Text = smartInfo->Lookup("remote audio codec");

    if (currentRendererWrapper) {
        auto remoteResolution = currentRendererWrapper->renderer->width.ToString() +
                                "x" +
                                currentRendererWrapper->renderer->height.ToString();
        _si_res2_->Text = remoteResolution;
    }
}

void
VideoPage::updateCallTimer(Object^ sender, Object^ e)
{
    if(auto item = SmartPanelItemsViewModel::instance->_selectedItem)
        _callTime_->Text = item->_callTime;
atraczyk's avatar
atraczyk committed
273
}
274

atraczyk's avatar
atraczyk committed
275
void
276
VideoPage::OnNavigatedTo(Windows::UI::Xaml::Navigation::NavigationEventArgs^ e)
atraczyk's avatar
atraczyk committed
277
{
278
    updatePageContent();
279
    closeChatPanel();
280
}
Nicolas Jager's avatar
Nicolas Jager committed
281

282 283
void RingClientUWP::Views::VideoPage::updatePageContent()
{
Nicolas Jager's avatar
Nicolas Jager committed
284 285 286
    auto item = SmartPanelItemsViewModel::instance->_selectedItem;
    auto contact = (item) ? item->_contact : nullptr;

287 288 289
    if (!contact)
        return;

290 291 292 293 294 295 296 297 298 299 300 301 302 303 304
    _contactName_->Text = contact->_bestName;

    //_contactBarAvatar_->ImageSource = RingClientUWP::ResourceMananger::instance->imageFromRelativePath(contact->_avatarImage);
    if (contact->_avatarImage != " ") {
        auto avatarImageUri = ref new Windows::Foundation::Uri(contact->_avatarImage);
        _contactBarAvatar_->ImageSource = ref new BitmapImage(avatarImageUri);
        _defaultContactBarAvatarGrid_->Visibility = VIS::Collapsed;
        _contactBarAvatarGrid_->Visibility = VIS::Visible;
    }
    else {
        _defaultContactBarAvatarGrid_->Visibility = VIS::Visible;
        _contactBarAvatarGrid_->Visibility = VIS::Collapsed;
        _defaultAvatar_->Fill = contact->_avatarColorBrush;
        _defaultAvatarInitial_->Text = Utils::getUpperInitial(contact->_bestName2);
    }
305 306 307 308 309 310

    _messagesList_->ItemsSource = contact->_conversation->_messages;

    scrollDown();
}

311 312 313 314 315 316 317 318 319
void
VideoPage::updatePreviewFrameDimensions()
{
    double aspectRatio = VideoManager::instance->captureManager()->aspectRatio();

    TransformGroup^ transforms = ref new TransformGroup();

    double scaleValue = 1 + userPreviewHeightModifier / _PreviewImage_->Height;

320
    scaleValue = std::max(std::min(1.75, scaleValue), 0.5);
321 322 323 324 325 326 327 328 329 330

    userPreviewHeightModifier = _PreviewImage_->Height * (scaleValue - 1);

    ScaleTransform^ scale = ref new ScaleTransform();
    scale->ScaleX = scaleValue;
    scale->ScaleY = scaleValue;

    TranslateTransform^ translate = ref new TranslateTransform();
    switch (quadrant)
    {
331
    case Quadrant::SE:
332 333 334
        translate->Y = -userPreviewHeightModifier;
        translate->X = translate->Y * aspectRatio;
        break;
335
    case Quadrant::SW:
336 337 338
        translate->Y = -userPreviewHeightModifier;
        translate->X = 0;
        break;
339
    case Quadrant::NW:
340 341 342
        translate->Y = 0;
        translate->X = 0;
        break;
343
    case Quadrant::NE:
344 345 346
        translate->Y = 0;
        translate->X = -userPreviewHeightModifier * aspectRatio;
        break;
347
    default:
348 349 350 351 352 353 354 355 356 357 358 359 360
        break;
    }

    transforms->Children->Append(scale);
    transforms->Children->Append(translate);

    _PreviewImage_->RenderTransform = transforms;

    _PreviewImageResizer_->RenderTransform = translate;

    arrangeResizer();
}

361 362 363 364 365 366
void RingClientUWP::Views::VideoPage::scrollDown()
{
    _scrollView_->UpdateLayout();
    _scrollView_->ScrollToVerticalOffset(_scrollView_->ScrollableHeight);
}

367 368 369 370 371
void RingClientUWP::Views::VideoPage::screenVideo(bool state)
{
    if (state) {
        Video::VideoManager::instance->rendererManager()->raiseClearRenderTarget();
        _callPaused_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
372 373 374
        _IncomingVideoImage_->Visibility = Windows::UI::Xaml::Visibility::Visible;
        _PreviewImage_->Visibility = Windows::UI::Xaml::Visibility::Visible;
        _PreviewImageResizer_->Visibility = Windows::UI::Xaml::Visibility::Visible;
375 376
    } else {
        _callPaused_->Visibility = Windows::UI::Xaml::Visibility::Visible;
377 378 379
        _IncomingVideoImage_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
        _PreviewImage_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
        _PreviewImageResizer_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
380 381 382
    }
}

383 384 385 386 387 388 389 390 391
void
RingClientUWP::Views::VideoPage::_sendBtn__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
    sendMessage();
}

void
RingClientUWP::Views::VideoPage::sendMessage()
{
392 393
    if (auto item = SmartPanelItemsViewModel::instance->_selectedItem) {
        auto contact = item->_contact;
Nicolas Jager's avatar
Nicolas Jager committed
394

395
        auto txt = _messageTextBox_->Text;
396

397 398
        /* empty the textbox */
        _messageTextBox_->Text = "";
399

400 401
        if (!contact || txt->IsEmpty())
            return;
402

403 404 405
        RingD::instance->sendSIPTextMessage(txt);
        scrollDown();
    }
406
}
Nicolas Jager's avatar
Nicolas Jager committed
407 408 409 410 411 412 413 414 415 416 417 418

void RingClientUWP::Views::VideoPage::Button_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
}


void RingClientUWP::Views::VideoPage::_btnCancel__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
}

void RingClientUWP::Views::VideoPage::_btnHangUp__Tapped(Platform::Object^ sender, Windows::UI::Xaml::Input::TappedRoutedEventArgs^ e)
{
419
    if (auto item = SmartPanelItemsViewModel::instance->_selectedItem) {
420 421
        _PreviewImage_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
        _PreviewImageResizer_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
422 423 424 425 426
        RingD::instance->hangUpCall2(item->_callId);
        pressHangUpCall();
    }
    else
        WNG_("item not found, cannot hang up");
Nicolas Jager's avatar
Nicolas Jager committed
427 428 429 430 431
}


void RingClientUWP::Views::VideoPage::_btnPause__Tapped(Platform::Object^ sender, Windows::UI::Xaml::Input::TappedRoutedEventArgs^ e)
{
432
    auto item = SmartPanelItemsViewModel::instance->_selectedItem;
433
    if (item->_callStatus == CallStatus::IN_PROGRESS)
434
        RingD::instance->pauseCall(Utils::toString(item->_callId));
435
    else if (item->_callStatus == CallStatus::PAUSED)
436
        RingD::instance->unPauseCall(Utils::toString(item->_callId));
437

Nicolas Jager's avatar
Nicolas Jager committed
438 439 440 441 442 443
    pauseCall();
}


void RingClientUWP::Views::VideoPage::_btnChat__Tapped(Platform::Object^ sender, Windows::UI::Xaml::Input::TappedRoutedEventArgs^ e)
{
444 445
    if (!isChatPanelOpen) {
        openChatPanel();
446 447
    }
    else {
448
        closeChatPanel();
Nicolas Jager's avatar
Nicolas Jager committed
449
    }
Nicolas Jager's avatar
Nicolas Jager committed
450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467
}


void RingClientUWP::Views::VideoPage::_btnAddFriend__Tapped(Platform::Object^ sender, Windows::UI::Xaml::Input::TappedRoutedEventArgs^ e)
{
    addContactCall();
}


void RingClientUWP::Views::VideoPage::_btnSwitch__Tapped(Platform::Object^ sender, Windows::UI::Xaml::Input::TappedRoutedEventArgs^ e)
{
    transferCall();
}


void RingClientUWP::Views::VideoPage::_btnMicrophone__Tapped(Platform::Object^ sender, Windows::UI::Xaml::Input::TappedRoutedEventArgs^ e)
{
    switchMicrophoneStateCall();
468 469 470 471 472 473 474
    auto item = SmartPanelItemsViewModel::instance->_selectedItem;

    auto state = !item->_audioMuted;
    item->_audioMuted = state;

    // refacto : compare how video and audios are muted, then decide which solution is best.
    RingD::instance->muteAudio(Utils::toString(item->_callId), state); // nb : muteAudio == setMuteAudio
Nicolas Jager's avatar
Nicolas Jager committed
475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498
}


void RingClientUWP::Views::VideoPage::_btnMemo__Tapped(Platform::Object^ sender, Windows::UI::Xaml::Input::TappedRoutedEventArgs^ e)
{
    reccordVideoCall();
}


void RingClientUWP::Views::VideoPage::_btnHQ__Tapped(Platform::Object^ sender, Windows::UI::Xaml::Input::TappedRoutedEventArgs^ e)
{
    qualityVideoLevelCall();
}


void RingClientUWP::Views::VideoPage::_btnVideo__Tapped(Platform::Object^ sender, Windows::UI::Xaml::Input::TappedRoutedEventArgs^ e)
{
    switchVideoStateCall();
}


void RingClientUWP::Views::VideoPage::_videoControl__PointerMoved(Platform::Object^ sender, Windows::UI::Xaml::Input::PointerRoutedEventArgs^ e)
{
    if (barFading)
499
        fadeVideoControlsStoryboard->Begin();
Nicolas Jager's avatar
Nicolas Jager committed
500 501 502 503 504
}


void RingClientUWP::Views::VideoPage::btnAny_entered(Platform::Object^ sender, Windows::UI::Xaml::Input::PointerRoutedEventArgs^ e)
{
505 506
    barFading = false;
    fadeVideoControlsStoryboard->Stop();
Nicolas Jager's avatar
Nicolas Jager committed
507 508 509 510 511
}


void RingClientUWP::Views::VideoPage::btnAny_exited(Platform::Object^ sender, Windows::UI::Xaml::Input::PointerRoutedEventArgs^ e)
{
512
    barFading = true;
atraczyk's avatar
atraczyk committed
513 514
}

515 516
void
VideoPage::SetBuffer(uint8_t* buf, int width, int height)
atraczyk's avatar
atraczyk committed
517
{
518 519
    videoFrame = ref new VideoFrame(BitmapPixelFormat::Bgra8, width, height);
    softwareBitmap = videoFrame->SoftwareBitmap;
atraczyk's avatar
atraczyk committed
520

521 522
    BitmapBuffer^ bitmapBuffer = softwareBitmap->LockBuffer(BitmapBufferAccessMode::Write);
    IMemoryBufferReference^ memoryBufferReference = bitmapBuffer->CreateReference();
atraczyk's avatar
atraczyk committed
523 524

    Microsoft::WRL::ComPtr<IMemoryBufferByteAccess> byteAccess;
525
    if (SUCCEEDED(reinterpret_cast<IUnknown*>(memoryBufferReference)->QueryInterface(IID_PPV_ARGS(&byteAccess))))
atraczyk's avatar
atraczyk committed
526 527 528 529
    {
        byte* data;
        unsigned capacity;
        byteAccess->GetBuffer(&data, &capacity);
530
        std::memcpy(data, buf, static_cast<size_t>(capacity));
atraczyk's avatar
atraczyk committed
531
    }
532 533 534 535 536 537 538 539 540
    delete memoryBufferReference;
    delete bitmapBuffer;
}


task<void>
VideoPage::WriteFrameAsSoftwareBitmapAsync(String^ id, uint8_t* buf, int width, int height)
{
    SetBuffer(buf, width, height);
atraczyk's avatar
atraczyk committed
541 542 543 544

    VideoManager::instance->rendererManager()->renderer(id)->isRendering = false;

    auto sbSource = ref new Media::Imaging::SoftwareBitmapSource();
545
    return create_task(sbSource->SetBitmapAsync(softwareBitmap))
546
           .then([this, sbSource]()
atraczyk's avatar
atraczyk committed
547 548
    {
        try {
549
            _IncomingVideoImage_->Source = sbSource;
atraczyk's avatar
atraczyk committed
550 551
        }
        catch (Exception^ e) {
552
            EXC_(e);
atraczyk's avatar
atraczyk committed
553 554 555
        }
    });
}
556 557


558
void RingClientUWP::Views::VideoPage::OnincomingMessage(Platform::String ^callId, Platform::String ^payload)
559
{
560
    openChatPanel();
561 562
    scrollDown();
}
563 564 565 566 567 568 569 570 571 572 573 574


void RingClientUWP::Views::VideoPage::_btnVideo__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
    auto item = SmartPanelItemsViewModel::instance->_selectedItem;

    item->muteVideo(!item->_videoMuted);
}


void RingClientUWP::Views::VideoPage::OnincomingVideoMuted(Platform::String ^callId, bool state)
{
575
    /*_callPaused_->Visibility = (state)
576 577 578
                                   ? Windows::UI::Xaml::Visibility::Visible
                                   : Windows::UI::Xaml::Visibility::Collapsed;*/

579
    _IncomingVideoImage_->Visibility = (state)
580 581 582
                                     ? Windows::UI::Xaml::Visibility::Collapsed
                                     : Windows::UI::Xaml::Visibility::Visible;
}
583 584 585 586


void RingClientUWP::Views::VideoPage::OnstartPreviewing()
{
587 588
    _PreviewImage_->Visibility = Windows::UI::Xaml::Visibility::Visible;
    _PreviewImageResizer_->Visibility = Windows::UI::Xaml::Visibility::Visible;
589 590 591 592 593
}


void RingClientUWP::Views::VideoPage::OnstopPreviewing()
{
594 595
    _PreviewImage_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
    _PreviewImageResizer_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
596
}
597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616


void RingClientUWP::Views::VideoPage::_btnMicrophone__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
    switchMicrophoneStateCall();
    auto item = SmartPanelItemsViewModel::instance->_selectedItem;

    auto state = !item->_audioMuted;
    item->_audioMuted = state;

    // refacto : compare how video and audios are muted, then decide which solution is best.
    RingD::instance->muteAudio(Utils::toString(item->_callId), state); // nb : muteAudio == setMuteAudio
}


void RingClientUWP::Views::VideoPage::OnaudioMuted(const std::string &callId, bool state)
{
    _txbkMicrophoneMuted_->Visibility = (state) ? Windows::UI::Xaml::Visibility::Visible
                                        : Windows::UI::Xaml::Visibility::Collapsed;
}
617 618 619 620 621 622 623


void RingClientUWP::Views::VideoPage::OnvideoMuted(const std::string &callId, bool state)
{
    _txbkVideoMuted_->Visibility = (state) ? Windows::UI::Xaml::Visibility::Visible
                                   : Windows::UI::Xaml::Visibility::Collapsed;
}
624 625 626

void RingClientUWP::Views::VideoPage::IncomingVideoImage_DoubleTapped(Platform::Object^ sender, Windows::UI::Xaml::Input::DoubleTappedRoutedEventArgs^ e)
{
627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645
    RingD::instance->toggleFullScreen();
    anchorPreview();
}

void RingClientUWP::Views::VideoPage::InitManipulationTransforms()
{
    PreviewImage_transforms = ref new TransformGroup();
    PreviewImage_previousTransform = ref new MatrixTransform();
    PreviewImage_previousTransform->Matrix = Matrix::Identity;
    PreviewImage_deltaTransform = ref new CompositeTransform();

    PreviewImage_transforms->Children->Append(PreviewImage_previousTransform);
    PreviewImage_transforms->Children->Append(PreviewImage_deltaTransform);

    _PreviewImageRect_->RenderTransform = PreviewImage_transforms;
}

void RingClientUWP::Views::VideoPage::PreviewImage_ManipulationDelta(Platform::Object^ sender, ManipulationDeltaRoutedEventArgs^ e)
{
646 647 648
    if (!isMovingPreview)
        isMovingPreview = true;

649 650 651 652 653 654 655 656 657 658 659 660 661 662
    _PreviewImageRect_->RenderTransform = PreviewImage_transforms;

    PreviewImage_previousTransform->Matrix = PreviewImage_transforms->Value;

    PreviewImage_deltaTransform->TranslateX = e->Delta.Translation.X;
    PreviewImage_deltaTransform->TranslateY = e->Delta.Translation.Y;

    computeQuadrant();
}

void
RingClientUWP::Views::VideoPage::computeQuadrant()
{
    // Compute center coordinate of _videoContent_
663 664
    Point centerOfVideoFrame = Point(   static_cast<float>(_videoContent_->ActualWidth - _colChatBx_->ActualWidth) / 2,
                                        static_cast<float>(_videoContent_->ActualHeight - _rowChatBx_->ActualHeight) / 2  );
665 666 667 668 669 670 671 672 673 674 675 676 677 678 679

    // Compute the center coordinate of _PreviewImage_ relative to _videoContent_
    Point centerOfPreview = Point( static_cast<float>(_PreviewImage_->ActualWidth) / 2,
                                   static_cast<float>(_PreviewImage_->ActualHeight) / 2 );
    UIElement^ container = dynamic_cast<UIElement^>(VisualTreeHelper::GetParent(_videoContent_));
    GeneralTransform^ transform = _PreviewImage_->TransformToVisual(container);
    Point relativeCenterOfPreview = transform->TransformPoint(centerOfPreview);

    // Compute the difference between the center of _videoContent_
    // and the relative scaled center of _PreviewImageRect_
    Point diff = Point( centerOfVideoFrame.X - relativeCenterOfPreview.X,
                        centerOfVideoFrame.Y - relativeCenterOfPreview.Y    );

    lastQuadrant = quadrant;
    if (diff.X > 0)
680
        quadrant = diff.Y > 0 ? Quadrant::NW : Quadrant::SW;
681
    else
682
        quadrant = diff.Y > 0 ? Quadrant::NE : Quadrant::SE;
683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700

    if (lastQuadrant != quadrant) {
        arrangeResizer();
    }
}

void
RingClientUWP::Views::VideoPage::arrangeResizer()
{
    double scaleValue = (userPreviewHeightModifier + _PreviewImage_->Height) / _PreviewImage_->Height;
    float scaledWidth = static_cast<float>(scaleValue * _PreviewImage_->ActualWidth);
    float scaledHeight = static_cast<float>(scaleValue * _PreviewImage_->ActualHeight);

    float rSize = 20; // the size of the square UIElement used to resize the preview
    float xOffset, yOffset;
    PointCollection^ resizeTrianglePoints = ref new PointCollection();
    switch (quadrant)
    {
701
    case Quadrant::SE:
702 703 704 705 706 707
        xOffset = 0;
        yOffset = 0;
        resizeTrianglePoints->Append(Point(xOffset,         yOffset));
        resizeTrianglePoints->Append(Point(xOffset + rSize, yOffset));
        resizeTrianglePoints->Append(Point(xOffset,         yOffset + rSize));
        break;
708
    case Quadrant::SW:
709 710 711 712 713 714
        xOffset = scaledWidth - rSize;
        yOffset = 0;
        resizeTrianglePoints->Append(Point(xOffset,         yOffset));
        resizeTrianglePoints->Append(Point(xOffset + rSize, yOffset));
        resizeTrianglePoints->Append(Point(xOffset + rSize, yOffset + rSize));
        break;
715
    case Quadrant::NW:
716 717 718 719 720 721
        xOffset = scaledWidth - rSize;
        yOffset = scaledHeight - rSize;
        resizeTrianglePoints->Append(Point(xOffset + rSize, yOffset));
        resizeTrianglePoints->Append(Point(xOffset + rSize, yOffset + rSize));
        resizeTrianglePoints->Append(Point(xOffset,         yOffset + rSize));
        break;
722
    case Quadrant::NE:
723 724 725 726 727 728
        xOffset = 0;
        yOffset = scaledHeight - rSize;
        resizeTrianglePoints->Append(Point(xOffset,         yOffset + rSize));
        resizeTrianglePoints->Append(Point(xOffset + rSize, yOffset + rSize));
        resizeTrianglePoints->Append(Point(xOffset,         yOffset));
        break;
729
    default:
730 731 732 733 734 735 736
        break;
    }
    _PreviewImageResizer_->Points = resizeTrianglePoints;
}

void RingClientUWP::Views::VideoPage::PreviewImage_ManipulationCompleted(Platform::Object^ sender, ManipulationCompletedRoutedEventArgs^ e)
{
737
    isMovingPreview = false;
738 739 740 741
    anchorPreview();
    updatePreviewFrameDimensions();
}

742 743 744 745 746 747 748
void
VideoPage::PreviewImageResizer_Pressed(Object^ sender, PointerRoutedEventArgs^ e)
{
    isResizingPreview = true;
    lastUserPreviewHeightModifier = userPreviewHeightModifier;
}

749 750 751 752 753 754 755
void RingClientUWP::Views::VideoPage::anchorPreview()
{
    PreviewImage_previousTransform->Matrix = Matrix::Identity;
    _PreviewImageRect_->RenderTransform =  nullptr;

    switch (quadrant)
    {
756
    case Quadrant::SE:
757 758 759
        _PreviewImageRect_->HorizontalAlignment = Windows::UI::Xaml::HorizontalAlignment::Right;
        _PreviewImageRect_->VerticalAlignment = Windows::UI::Xaml::VerticalAlignment::Bottom;
        break;
760
    case Quadrant::SW:
761 762 763
        _PreviewImageRect_->HorizontalAlignment = Windows::UI::Xaml::HorizontalAlignment::Left;
        _PreviewImageRect_->VerticalAlignment = Windows::UI::Xaml::VerticalAlignment::Bottom;
        break;
764
    case Quadrant::NW:
765 766 767
        _PreviewImageRect_->HorizontalAlignment = Windows::UI::Xaml::HorizontalAlignment::Left;
        _PreviewImageRect_->VerticalAlignment = Windows::UI::Xaml::VerticalAlignment::Top;
        break;
768
    case Quadrant::NE:
769 770 771
        _PreviewImageRect_->HorizontalAlignment = Windows::UI::Xaml::HorizontalAlignment::Right;
        _PreviewImageRect_->VerticalAlignment = Windows::UI::Xaml::VerticalAlignment::Top;
        break;
772
    default:
773 774 775 776 777 778 779
        break;
    };
}

void
VideoPage::PreviewImageResizer_ManipulationDelta(Platform::Object^ sender, ManipulationDeltaRoutedEventArgs^ e)
{
780 781 782 783 784 785 786 787 788
    if (!isResizingPreview)
        isResizingPreview = true;

    if (quadrant == Quadrant::NW || quadrant == Quadrant::NE) {
        userPreviewHeightModifier = lastUserPreviewHeightModifier + e->Cumulative.Translation.Y;
    }
    else {
        userPreviewHeightModifier = lastUserPreviewHeightModifier - (e->Cumulative.Translation.Y);
    }
789 790 791 792 793 794 795 796

    updatePreviewFrameDimensions();
}

void
VideoPage::PreviewImageResizer_ManipulationCompleted(Platform::Object^ sender, ManipulationCompletedRoutedEventArgs^ e)
{
    isResizingPreview = false;
797 798 799
    if (!isHoveringOnResizer) {
        CoreApplication::MainView->CoreWindow->PointerCursor = ref new Windows::UI::Core::CoreCursor(Windows::UI::Core::CoreCursorType::Arrow, 0);
    }
800 801 802 803 804
}

void
VideoPage::PreviewImage_PointerReleased(Platform::Object^ sender, Windows::UI::Xaml::Input::PointerRoutedEventArgs^ e)
{
805
    // For some reason, PreviewImage_ManipulationCompleted doesn't always fired when the mouse is released
806 807 808 809 810 811 812
    anchorPreview();
    updatePreviewFrameDimensions();
}

void
VideoPage::PreviewImageResizer_PointerEntered(Platform::Object^ sender, Windows::UI::Xaml::Input::PointerRoutedEventArgs^ e)
{
813 814 815 816 817 818 819 820 821 822 823 824 825 826 827
    isHoveringOnResizer = true;
    if (!isMovingPreview) {
        switch (quadrant)
        {
        case Quadrant::SE:
        case Quadrant::NW:
            CoreApplication::MainView->CoreWindow->PointerCursor = ref new Windows::UI::Core::CoreCursor(Windows::UI::Core::CoreCursorType::SizeNorthwestSoutheast, 0);
            break;
        case Quadrant::SW:
        case Quadrant::NE:
            CoreApplication::MainView->CoreWindow->PointerCursor = ref new Windows::UI::Core::CoreCursor(Windows::UI::Core::CoreCursorType::SizeNortheastSouthwest, 0);
            break;
        default:
            break;
        }
828 829 830 831 832 833
    }
}

void
VideoPage::PreviewImageResizer_PointerExited(Platform::Object^ sender, Windows::UI::Xaml::Input::PointerRoutedEventArgs^ e)
{
834
    isHoveringOnResizer = false;
835 836 837 838
    if (!isResizingPreview) {
        CoreApplication::MainView->CoreWindow->PointerCursor = ref new Windows::UI::Core::CoreCursor(Windows::UI::Core::CoreCursorType::Arrow, 0);
    }
}
839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031

void
VideoPage::PreviewImageResizer_PointerReleased(Platform::Object^ sender, Windows::UI::Xaml::Input::PointerRoutedEventArgs^ e)
{
    if (!isHoveringOnResizer) {
        CoreApplication::MainView->CoreWindow->PointerCursor = ref new Windows::UI::Core::CoreCursor(Windows::UI::Core::CoreCursorType::Arrow, 0);
    }
}

void
VideoPage::_chatPanelResizeBarGrid__PointerEntered(Platform::Object^ sender, Windows::UI::Xaml::Input::PointerRoutedEventArgs^ e)
{
    if (chtBoxOrientation == Orientation::Horizontal) {
        CoreApplication::MainView->CoreWindow->PointerCursor = ref new Windows::UI::Core::CoreCursor(Windows::UI::Core::CoreCursorType::SizeWestEast, 0);
    }
    else {
        CoreApplication::MainView->CoreWindow->PointerCursor = ref new Windows::UI::Core::CoreCursor(Windows::UI::Core::CoreCursorType::SizeNorthSouth, 0);
    }
}

void
VideoPage::_chatPanelResizeBarGrid__PointerExited(Platform::Object^ sender, Windows::UI::Xaml::Input::PointerRoutedEventArgs^ e)
{
    if (!isResizingChatPanel) {
        CoreApplication::MainView->CoreWindow->PointerCursor = ref new Windows::UI::Core::CoreCursor(Windows::UI::Core::CoreCursorType::Arrow, 0);
    }
}

void
VideoPage::_chatPanelResizeBarGrid__PointerPressed(Platform::Object^ sender, Windows::UI::Xaml::Input::PointerRoutedEventArgs^ e)
{
    isResizingChatPanel = true;
    lastchatPanelSize = chatPanelSize;
}

void
VideoPage::_chatPanelResizeBarGrid__PointerReleased(Platform::Object^ sender, Windows::UI::Xaml::Input::PointerRoutedEventArgs^ e)
{
    isResizingChatPanel = false;
}

void
VideoPage::_chatPanelResizeBarGrid__ManipulationDelta(Platform::Object^ sender, ManipulationDeltaRoutedEventArgs^ e)
{
    if (chtBoxOrientation == Orientation::Horizontal) {
        chatPanelSize = lastchatPanelSize - e->Cumulative.Translation.X;
    }
    else {
        chatPanelSize = lastchatPanelSize - e->Cumulative.Translation.Y;
    }
    resizeChatPanel();
}

void
VideoPage::_chatPanelResizeBarGrid__ManipulationCompleted(Platform::Object^ sender, ManipulationCompletedRoutedEventArgs^ e)
{
    isResizingChatPanel = false;
    CoreApplication::MainView->CoreWindow->PointerCursor = ref new Windows::UI::Core::CoreCursor(Windows::UI::Core::CoreCursorType::Arrow, 0);
}

void
VideoPage::openChatPanel()
{
    resizeChatPanel();
    isChatPanelOpen = true;
    SmartPanelItemsViewModel::instance->_selectedItem->_contact->_unreadMessages = 0;
}
void
VideoPage::closeChatPanel()
{
    _colChatBx_->Width = 0;
    _rowChatBx_->Height = 0;
    isChatPanelOpen = false;
}

void
VideoPage::resizeChatPanel()
{
    // clamp chatPanelSize
    double minChatPanelSize = 176;
    double maxChatPanelSize = chtBoxOrientation == Orientation::Horizontal ?
        _videoContent_->ActualWidth * .5 :
        _videoContent_->ActualHeight * .5;
    chatPanelSize = std::max(minChatPanelSize, std::min(chatPanelSize, maxChatPanelSize));

    if (chtBoxOrientation == Orientation::Horizontal) {
        _colChatBx_->Width = GridLength(chatPanelSize, GridUnitType::Pixel);
        _rowChatBx_->Height = 0;
    }
    else {
        _colChatBx_->Width = 0;
        _rowChatBx_->Height = GridLength(chatPanelSize, GridUnitType::Pixel);
    }
}

void
VideoPage::_btnToggleOrientation__Tapped(Platform::Object^ sender, Windows::UI::Xaml::Input::TappedRoutedEventArgs^ e)
{
    bool wasChatPanelOpen = isChatPanelOpen;
    closeChatPanel();

    if (chtBoxOrientation == Orientation::Horizontal) {
        chtBoxOrientation = Orientation::Vertical;
        _btnToggleOrientation_->Content = L"\uE90D";

        _chatPanelResizeBarGrid_->HorizontalAlignment = Windows::UI::Xaml::HorizontalAlignment::Stretch;
        _chatPanelResizeBarGrid_->VerticalAlignment = Windows::UI::Xaml::VerticalAlignment::Top;
        _chatPanelResizeBarGrid_->Width = std::numeric_limits<double>::quiet_NaN();
        _chatPanelResizeBarGrid_->Height = 4;

        Grid::SetColumn(_chatPanelGrid_, 0);
        Grid::SetRow(_chatPanelGrid_, 2);
    }
    else {
        chtBoxOrientation = Orientation::Horizontal;
        _btnToggleOrientation_->Content = L"\uE90E";

        _chatPanelResizeBarGrid_->HorizontalAlignment = Windows::UI::Xaml::HorizontalAlignment::Left;
        _chatPanelResizeBarGrid_->VerticalAlignment = Windows::UI::Xaml::VerticalAlignment::Stretch;
        _chatPanelResizeBarGrid_->Width = 4;
        _chatPanelResizeBarGrid_->Height = std::numeric_limits<double>::quiet_NaN();

        Grid::SetColumn(_chatPanelGrid_, 2);
        Grid::SetRow(_chatPanelGrid_, 0);
    }

    if (wasChatPanelOpen)
        openChatPanel();
}

void
VideoPage::_videoContent__SizeChanged(Platform::Object^ sender, Windows::UI::Xaml::SizeChangedEventArgs^ e)
{
    if (isChatPanelOpen)
        resizeChatPanel();
}

void
VideoPage::_messageTextBox__TextChanged(Platform::Object^ sender, TextChangedEventArgs^ e)
{
    bool carriageReturnPressed = false;
    if (_messageTextBox_->Text->Length() == (lastMessageText->Length() + 1) &&
        _messageTextBox_->Text != "\r") {
        unsigned cursorPos = 0;
        auto strMessage = Utils::toString(_messageTextBox_->Text);
        auto strLastMessage = Utils::toString(lastMessageText);
        for (std::string::size_type i = 0; i < strLastMessage.size(); ++i) {
            if (strMessage[i] != strLastMessage[i]) {
                auto changed = strMessage.substr(i, 1);
                if (changed == "\r") {
                    carriageReturnPressed = true;
                    MSG_("CR inside");
                }
                break;
            }
        }

        if (strMessage.substr(strMessage.length() - 1) == "\r") {
            if (lastMessageText->Length() != 0) {
                carriageReturnPressed = true;
                MSG_("CR at end");
            }
        }
    }

    if (carriageReturnPressed && !(RingD::instance->isCtrlPressed || RingD::instance->isShiftPressed)) {
        _messageTextBox_->Text = lastMessageText;
        sendMessage();
        lastMessageText = "";
    }

    DependencyObject^ child = VisualTreeHelper::GetChild(_messageTextBox_, 0);
    auto sendBtnElement = Utils::xaml::FindVisualChildByName(child, "_sendBtn_");
    auto sendBtn = dynamic_cast<Button^>(sendBtnElement);
    if (_messageTextBox_->Text != "") {
        sendBtn->IsEnabled = true;
    }
    else {
        sendBtn->IsEnabled = false;
    }

    lastMessageText = _messageTextBox_->Text;
}

void
VideoPage::_corewindow__KeyDown(CoreWindow^ sender, KeyEventArgs^ e)
{
    auto ctrlState = CoreWindow::GetForCurrentThread()->GetKeyState(VirtualKey::Control);
    auto isCtrlDown = ctrlState != CoreVirtualKeyStates::None;
    if (isCtrlDown && e->VirtualKey == Windows::System::VirtualKey::I) {
        _smartInfoBorder_->Visibility = _smartInfoBorder_->Visibility == VIS::Collapsed ? VIS::Visible : VIS::Collapsed;
    }
}