mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-08-05 13:04:03 -06:00
Add the full source of BambuStudio
using version 1.0.10
This commit is contained in:
parent
30bcadab3e
commit
1555904bef
3771 changed files with 1251328 additions and 0 deletions
112
src/slic3r/GUI/wxMediaCtrl2.mm
Normal file
112
src/slic3r/GUI/wxMediaCtrl2.mm
Normal file
|
@ -0,0 +1,112 @@
|
|||
//
|
||||
// wxMediaCtrl2.m
|
||||
// BambuStudio
|
||||
//
|
||||
// Created by cmguo on 2021/12/7.
|
||||
//
|
||||
|
||||
#import "wxMediaCtrl2.h"
|
||||
#import "wx/mediactrl.h"
|
||||
#include <boost/log/trivial.hpp>
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "BambuPlayer/BambuPlayer.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <dlfcn.h>
|
||||
|
||||
#define BAMBU_DYNAMIC
|
||||
|
||||
static void bambu_log(void const * ctx, int level, char const * msg)
|
||||
{
|
||||
if (level == 1) {
|
||||
wxString msg2(msg);
|
||||
if (msg2.EndsWith("]")) {
|
||||
int n = msg2.find_last_of('[');
|
||||
if (n != wxString::npos) {
|
||||
long val = 0;
|
||||
int * error = (int *) ctx;
|
||||
if (msg2.SubString(n + 1, msg2.Length() - 2).ToLong(&val))
|
||||
*error = (int) val;
|
||||
}
|
||||
}
|
||||
}
|
||||
BOOST_LOG_TRIVIAL(info) << msg;
|
||||
}
|
||||
|
||||
wxMediaCtrl2::wxMediaCtrl2(wxWindow * parent)
|
||||
: wxWindow(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize)
|
||||
{
|
||||
NSView * imageView = (NSView *) GetHandle();
|
||||
imageView.layer = [[CALayer alloc] init];
|
||||
CGColorRef color = CGColorCreateGenericRGB(0, 0, 0, 1.0f);
|
||||
imageView.layer.backgroundColor = color;
|
||||
CGColorRelease(color);
|
||||
imageView.wantsLayer = YES;
|
||||
auto module = dlopen("libBambuSource.dylib", RTLD_LAZY);
|
||||
Class cls = (__bridge Class) dlsym(module, "OBJC_CLASS_$_BambuPlayer");
|
||||
if (cls == nullptr) {
|
||||
m_error = -2;
|
||||
return;
|
||||
}
|
||||
BambuPlayer * player = [cls alloc];
|
||||
[player initWithImageView: imageView];
|
||||
[player setLogger: bambu_log withContext: &m_error];
|
||||
m_player = player;
|
||||
}
|
||||
|
||||
void wxMediaCtrl2::Load(wxURI url)
|
||||
{
|
||||
BambuPlayer * player = (BambuPlayer *) m_player;
|
||||
if (player) {
|
||||
[player close];
|
||||
[player open: url.BuildURI().ToUTF8()];
|
||||
m_error = 0;
|
||||
}
|
||||
wxMediaEvent event(wxEVT_MEDIA_STATECHANGED);
|
||||
event.SetId(GetId());
|
||||
event.SetEventObject(this);
|
||||
wxPostEvent(this, event);
|
||||
}
|
||||
|
||||
void wxMediaCtrl2::Play()
|
||||
{
|
||||
BambuPlayer * player2 = (BambuPlayer *) m_player;
|
||||
[player2 play];
|
||||
if (m_state != wxMEDIASTATE_PLAYING) {
|
||||
m_state = wxMEDIASTATE_PLAYING;
|
||||
wxMediaEvent event(wxEVT_MEDIA_STATECHANGED);
|
||||
event.SetId(GetId());
|
||||
event.SetEventObject(this);
|
||||
wxPostEvent(this, event);
|
||||
}
|
||||
}
|
||||
|
||||
void wxMediaCtrl2::Stop()
|
||||
{
|
||||
BambuPlayer * player2 = (BambuPlayer *) m_player;
|
||||
[player2 close];
|
||||
if (m_state != wxMEDIASTATE_STOPPED) {
|
||||
m_state = wxMEDIASTATE_STOPPED;
|
||||
wxMediaEvent event(wxEVT_MEDIA_STATECHANGED);
|
||||
event.SetId(GetId());
|
||||
event.SetEventObject(this);
|
||||
wxPostEvent(this, event);
|
||||
}
|
||||
}
|
||||
|
||||
wxMediaState wxMediaCtrl2::GetState() const
|
||||
{
|
||||
return m_state;
|
||||
}
|
||||
|
||||
wxSize wxMediaCtrl2::GetVideoSize() const
|
||||
{
|
||||
BambuPlayer * player2 = (BambuPlayer *) m_player;
|
||||
if (player2) {
|
||||
NSSize size = [player2 videoSize];
|
||||
return {(int) size.width, (int) size.height};
|
||||
} else {
|
||||
return {0, 0};
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue