Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added fullscreen support to the camera stream view on macOS #3974

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions resources/images/fullscreen.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
66 changes: 66 additions & 0 deletions resources/images/fullscreen_selected.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions src/slic3r/GUI/MediaPlayCtrl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -853,6 +853,11 @@ bool MediaPlayCtrl::get_stream_url(std::string *url)

void wxMediaCtrl2::DoSetSize(int x, int y, int width, int height, int sizeFlags)
{
// Ignore resize calls while in fullscreen mode
if (IsFullScreen())
{
return;
}
#ifdef __WXMAC__
wxWindow::DoSetSize(x, y, width, height, sizeFlags);
#else
Expand Down
5 changes: 5 additions & 0 deletions src/slic3r/GUI/wxMediaCtrl2.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,11 @@ class wxMediaCtrl2 : public wxWindow

void NotifyStopped();

bool IsFullScreen() const;

private:
void create_player();
void toggle_fullscreen();
void * m_player = nullptr;
wxMediaState m_state = wxMEDIASTATE_STOPPED;
int m_error = 0;
Expand Down Expand Up @@ -77,6 +80,8 @@ class wxMediaCtrl2 : public wxMediaCtrl

void DoSetSize(int x, int y, int width, int height, int sizeFlags) override;

bool IsFullScreen() const { return false; }

#ifdef __WIN32__
WXLRESULT MSWWindowProc(WXUINT nMsg,
WXWPARAM wParam,
Expand Down
64 changes: 64 additions & 0 deletions src/slic3r/GUI/wxMediaCtrl2.mm
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
#include <stdlib.h>
#include <dlfcn.h>

#include <wx/button.h>
#include <wx/bmpbuttn.h>
#include "BitmapCache.hpp"

wxDEFINE_EVENT(EVT_MEDIA_CTRL_STAT, wxCommandEvent);

#define BAMBU_DYNAMIC
Expand Down Expand Up @@ -56,6 +60,45 @@
CGColorRelease(color);
imageView.wantsLayer = YES;
create_player();

auto key_down = [this](wxKeyEvent& event)
{
if (event.m_keyCode == WXK_ESCAPE)
toggle_fullscreen();
};
Bind(wxEVT_KEY_DOWN, key_down);

wxBitmap bmp = *Slic3r::GUI::BitmapCache().load_svg("fullscreen", 0, 0);
bmp = bmp.ConvertToImage();

wxBitmap bmp_selected = *Slic3r::GUI::BitmapCache().load_svg("fullscreen_selected", 0, 0);
bmp_selected = bmp_selected.ConvertToImage();

wxBitmapButton * fullscreen_button = new wxBitmapButton(this, wxID_HIGHEST + 1, bmp,
wxDefaultPosition,
wxSize(32, 32),
wxBORDER_NONE);
fullscreen_button->SetBitmapSelected(bmp_selected);
auto fullscreen_button_clicked = [this](wxEvent &e) {
toggle_fullscreen();
};
fullscreen_button->Bind(wxEVT_COMMAND_BUTTON_CLICKED, fullscreen_button_clicked);

auto double_click = [this](wxMouseEvent& e) {
toggle_fullscreen();
};
Bind(wxEVT_LEFT_DCLICK, double_click);

wxSizer * hsizer = new wxBoxSizer(wxHORIZONTAL);
hsizer->AddStretchSpacer();
hsizer->Add(fullscreen_button);

wxSizer * sizer = new wxBoxSizer(wxVERTICAL);
sizer->AddStretchSpacer();
sizer->Add(hsizer, 0, wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALL);

SetSizer(sizer);
SetAutoLayout(true);
}

wxMediaCtrl2::~wxMediaCtrl2()
Expand Down Expand Up @@ -168,3 +211,24 @@
return {0, 0};
}
}

bool wxMediaCtrl2::IsFullScreen() const
{
NSView * imageView = (NSView *) GetHandle();
return (bool) [imageView isInFullScreenMode];
}

void wxMediaCtrl2::toggle_fullscreen()
{
NSView * imageView = (NSView *) GetHandle();
if ([imageView isInFullScreenMode])
{
[imageView exitFullScreenModeWithOptions:nil];
}
else
{
NSDictionary * fullScreenOptions = [NSDictionary dictionaryWithObjectsAndKeys: [NSNumber numberWithBool: NO], NSFullScreenModeAllScreens, nil];
[imageView enterFullScreenMode:imageView.window.screen withOptions:fullScreenOptions];
}
Layout();
}