⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wxosmo4.cpp

📁 一个用于智能手机的多媒体库适合S60 WinCE的跨平台开发库
💻 CPP
📖 第 1 页 / 共 5 页
字号:
	}}static wxString format_time(u32 duration, u32 timescale){	u32 h, m, s;	Float time = duration;	time /= timescale;	time *= 1000;	h = (u32) (time / 1000 / 3600);	m = (u32) (time / 1000 / 60 - h*60);	s = (u32) (time / 1000 - h*3600 - m*60);	return wxString::Format(wxT("%02d:%02d:%02d"), h, m, s);}void wxOsmo4Frame::SetStatus(wxString str){	//m_pStatusbar->SetStatusText(str, 2); 	m_LastStatusTime = gf_sys_clock();}#define RTI_REFRESH_MS		500void wxOsmo4Frame::OnRTI(wxCommandEvent & event){	m_bViewRTI = event.IsChecked();	if (m_bViewRTI) {		if (!m_pTimer->IsRunning()) m_pTimer->Start(RTI_REFRESH_MS, 0);	} else if (!m_connected && m_pTimer->IsRunning()) {		m_LastStatusTime = 0;		m_pStatusbar->SetStatusText(wxT("Ready"), 2); 		m_pTimer->Stop();	}}void wxOsmo4Frame::OnTimer(wxTimerEvent& WXUNUSED(event)){	wxString str;	u32 now;	if (m_LastStatusTime) {		now = gf_sys_clock();		if (now > 1000+m_LastStatusTime) {			m_LastStatusTime = 0;			m_pStatusbar->SetStatusText(wxT("Ready"), 2); 		}	}	if (m_bViewRTI) {		GF_SystemRTInfo rti;		if (!gf_sys_get_rti(RTI_REFRESH_MS, &rti, 0)) return;		if (rti.gpac_memory) rti.process_memory = rti.gpac_memory;		str = wxString::Format(wxT("CPU %02d (%02d) - Mem %d kB" ), 						rti.total_cpu_usage, rti.process_cpu_usage, rti.gpac_memory/1024);		m_pStatusbar->SetStatusText(str, 2); 	}	if (!m_connected) return;	now = gf_term_get_time_in_ms(m_term);	if (!now) return;	if (!m_duration) {		str = format_time(now, 1000);		m_pStatusbar->SetStatusText(str);		str = wxString::Format(wxT("FPS %.2f"), gf_term_get_framerate(m_term, 0));		m_pStatusbar->SetStatusText(str, 1);		return;	}#ifdef __WXGTK__	if (m_bGrabbed) {	  u32 now = gf_sys_clock() - m_last_grab_time;	  if (now>200) {	    m_bGrabbed = 0;	    Double res = (Double) m_last_grab_pos;	    res /= 1000;	    res *= m_duration;	    if (gf_term_get_option(m_term, GF_OPT_PLAY_STATE)==GF_STATE_PAUSED) {			gf_term_set_option(m_term, GF_OPT_PLAY_STATE, GF_STATE_PLAYING);			m_bToReset = 0;	    }	    gf_term_play_from_time(m_term, (u32) res, 0);	    return;	  }	}#endif	if (!m_bGrabbed) {		if ((now >= m_duration + 500) && gf_term_get_option(m_term, GF_OPT_IS_FINISHED)) {			m_pPlayList->PlayNext();		} else {			Double val = now * 1000;			val /= m_duration;			m_pProg->SetValue((val<=1000) ? (u32) val : 1000);			if (0) {				str = format_time(m_duration-now, 1000);			} else {				str = format_time(now, 1000);			}			m_pStatusbar->SetStatusText(str);			str = wxString::Format(wxT("FPS %.2f"), gf_term_get_framerate(m_term, 0));			m_pStatusbar->SetStatusText(str, 1);		}	}}void wxOsmo4Frame::ConnectAcknowledged(Bool bOk) {	if (bOk) {		m_pTimer->Start(RTI_REFRESH_MS, 0);		m_connected = 1;		m_bToReset = 0;		UpdatePlay();		BuildChapterList(0);	} else {		BuildChapterList(1);		if (!m_connected) {			UpdatePlay();			m_pTimer->Stop();			//m_pProg->Enable(0);		}	}}void wxOsmo4Frame::OnFilePlay(wxCommandEvent & WXUNUSED(event)){	wxCommandEvent evt;	if (m_connected) {		if (gf_term_get_option(m_term, GF_OPT_PLAY_STATE)==GF_STATE_PAUSED) {			gf_term_set_option(m_term, GF_OPT_PLAY_STATE, GF_STATE_PLAYING);			if (m_bToReset) {				m_pTimer->Start(100, 0);				gf_term_play_from_time(m_term, 0, 0);			}			m_bToReset = 0;			UpdatePlay();		} else {			gf_term_set_option(m_term, GF_OPT_PLAY_STATE, GF_STATE_PAUSED);			UpdatePlay();		}	} else {		m_pPlayList->Play();	}}void wxOsmo4Frame::OnFileStep(wxCommandEvent & WXUNUSED(event)){	wxCommandEvent evt;	gf_term_set_option(m_term, GF_OPT_PLAY_STATE, GF_STATE_STEP_PAUSE);	UpdatePlay();}void wxOsmo4Frame::OnFileStop(wxCommandEvent &WXUNUSED(event)){	Stop();}void wxOsmo4Frame::Stop(){	if (gf_term_get_option(m_term, GF_OPT_PLAY_STATE)==GF_STATE_PLAYING) {		gf_term_set_option(m_term, GF_OPT_PLAY_STATE, GF_STATE_PAUSED);	}	m_bToReset = 1;	m_pTimer->Stop();	m_pProg->SetValue(0);	UpdatePlay();}void wxOsmo4Frame::OnSlide(wxScrollEvent &event){	if (!m_duration) return;	/*wxSlider on GTK is buggy, so track a release timeout*/#ifdef __WXGTK__	m_last_grab_time = gf_sys_clock();	m_bGrabbed = 1;	m_last_grab_pos = event.GetPosition();	Double now = (Double) m_last_grab_pos;	now /= 1000;	now *= m_duration;	wxString str = format_time((u32) (now), 1000);	m_pStatusbar->SetStatusText(str);	if (!m_pTimer->IsRunning()) m_pTimer->Start(100, 0);#else	s32 type = event.GetEventType();	if (type == wxEVT_SCROLL_THUMBTRACK) {	  m_bGrabbed = 1;	  Double now = (Double) event.GetPosition();	  now /= 1000;	  now *= m_duration;	  wxString str = format_time((u32) (now), 1000);	  m_pStatusbar->SetStatusText(str);	} 	else if (m_bGrabbed){	    m_bGrabbed = 0;	    Double res = (Double) m_pProg->GetValue();	    res /= 1000;	    res *= m_duration;	    if (gf_term_get_option(m_term, GF_OPT_PLAY_STATE)==GF_STATE_PAUSED) {			gf_term_set_option(m_term, GF_OPT_PLAY_STATE, GF_STATE_PLAYING);			m_bToReset = 0;			if (!m_pTimer->IsRunning()) m_pTimer->Start(100, 0);	    }	    gf_term_play_from_time(m_term, (u32) res, 0);	}#endif}void wxOsmo4Frame::ReloadTerminal(){	Bool reconnect = (m_connected && !m_bStartupFile) ? 1 : 0;	::wxLogMessage(wxT("Reloading GPAC Terminal"));	u32 reconnect_time = 0;	if (m_duration) reconnect_time = gf_term_get_time_in_ms(m_term);	gf_term_del(m_term);	/*SET IT TO NULL to make sure we don't process callbacks during setup!!!*/	m_term = NULL;	CheckVideoOut();	m_term = gf_term_new(&m_user);	if (!m_term) {		wxMessageDialog(this, wxT("Fatal Error !!"), wxT("Couldn't change renderer"), wxOK);		Destroy();		return;	}	if (reconnect) {		if (reconnect_time) {			gf_term_connect_from_time(m_term, m_pPlayList->GetURL().mb_str(wxConvUTF8), reconnect_time, 0);		} else {			gf_term_connect(m_term, m_pPlayList->GetURL().mb_str(wxConvUTF8));		}	} else if (m_bStartupFile) {		gf_term_connect(m_term, gf_cfg_get_key(m_user.config, "General", "StartupFile") );	}	::wxLogMessage(wxT("GPAC Terminal reloaded"));	UpdateRenderSwitch();}void wxOsmo4Frame::BuildViewList(){	if (!vp_list || !m_connected) return;	while (vp_list->GetMenuItemCount()) {		wxMenuItem* it = vp_list->FindItemByPosition(0);		vp_list->Delete(it);	}	s32 id = ID_VIEWPOINT_FIRST;	nb_viewpoints = 0;	while (1) {		const char *szName;		Bool bound;		GF_Err e = gf_term_get_viewpoint(m_term, nb_viewpoints+1, &szName, &bound);		if (e) break;		if (szName) {			vp_list->AppendCheckItem(id+nb_viewpoints, wxString(szName, wxConvUTF8) );		} else {			vp_list->AppendCheckItem(id+nb_viewpoints, wxString::Format(wxT("Viewpoint #%d"), nb_viewpoints+1) );		}		nb_viewpoints++;	}}void wxOsmo4Frame::OnViewport(wxCommandEvent & event){	u32 ID = event.GetId() - ID_VIEWPOINT_FIRST;	gf_term_set_viewpoint(m_term, ID+1, NULL);}void wxOsmo4Frame::OnUpdateViewport(wxUpdateUIEvent & event){	u32 ID = event.GetId() - ID_VIEWPOINT_FIRST;	const char *szName;	Bool bound;	gf_term_get_viewpoint(m_term, ID+1, &szName, &bound);	event.Enable(1);	if (bound) event.Check(1);}void wxOsmo4Frame::OnNavigate(wxCommandEvent & event){	switch (event.GetId()) {	case ID_NAVIGATE_NONE: gf_term_set_option(m_term, GF_OPT_NAVIGATION, GF_NAVIGATE_NONE); break;	case ID_NAVIGATE_WALK: gf_term_set_option(m_term, GF_OPT_NAVIGATION, GF_NAVIGATE_WALK); break;	case ID_NAVIGATE_FLY: gf_term_set_option(m_term, GF_OPT_NAVIGATION, GF_NAVIGATE_FLY); break;	case ID_NAVIGATE_EXAMINE: gf_term_set_option(m_term, GF_OPT_NAVIGATION, GF_NAVIGATE_EXAMINE); break;	case ID_NAVIGATE_PAN: gf_term_set_option(m_term, GF_OPT_NAVIGATION, GF_NAVIGATE_PAN); break;	case ID_NAVIGATE_SLIDE: gf_term_set_option(m_term, GF_OPT_NAVIGATION, GF_NAVIGATE_SLIDE); break;	case ID_NAVIGATE_ORBIT: gf_term_set_option(m_term, GF_OPT_NAVIGATION, GF_NAVIGATE_ORBIT); break;	case ID_NAVIGATE_GAME: gf_term_set_option(m_term, GF_OPT_NAVIGATION, GF_NAVIGATE_GAME); break;	}}void wxOsmo4Frame::OnNavigateReset(wxCommandEvent & WXUNUSED(event)){	gf_term_set_option(m_term, GF_OPT_NAVIGATION_TYPE, 0);}void wxOsmo4Frame::OnUpdateNavigation(wxUpdateUIEvent & event){	u32 ID = event.GetId();	event.Enable(0);	if (!m_connected) return;	u32 type = gf_term_get_option(m_term, GF_OPT_NAVIGATION_TYPE);	bool enable = type ? 1 : 0;	u32 mode = gf_term_get_option(m_term, GF_OPT_NAVIGATION);	/*common 2D/3D modes*/	if (ID==ID_NAVIGATE_NONE) { event.Enable(enable); event.Check(mode ? 0 : 1); }	else if (ID==ID_NAVIGATE_EXAMINE) { event.Enable(enable); event.Check((mode==GF_NAVIGATE_EXAMINE) ? 1 : 0); }	else if (ID==ID_NAVIGATE_SLIDE) { event.Enable(enable); event.Check((mode==GF_NAVIGATE_SLIDE) ? 1 : 0); }	if (type==GF_NAVIGATE_TYPE_2D) return;	event.Enable(enable); 		if (ID==ID_NAVIGATE_WALK) event.Check((mode==GF_NAVIGATE_WALK) ? 1 : 0);	else if (ID==ID_NAVIGATE_FLY) event.Check((mode==GF_NAVIGATE_FLY) ? 1 : 0);	else if (ID==ID_NAVIGATE_PAN) event.Check((mode==GF_NAVIGATE_PAN) ? 1 : 0);	else if (ID==ID_NAVIGATE_ORBIT) event.Check((mode==GF_NAVIGATE_ORBIT) ? 1 : 0);	else if (ID==ID_NAVIGATE_GAME) event.Check((mode==GF_NAVIGATE_GAME) ? 1 : 0);}void wxOsmo4Frame::OnRenderSwitch(wxCommandEvent &WXUNUSED(event)){	const char *opt = gf_cfg_get_key(m_user.config, "Rendering", "RendererName");	if (!stricmp(opt, "GPAC 2D Renderer"))		gf_cfg_set_key(m_user.config, "Rendering", "RendererName", "GPAC 3D Renderer");	else		gf_cfg_set_key(m_user.config, "Rendering", "RendererName", "GPAC 2D Renderer");	ReloadTerminal();}void wxOsmo4Frame::UpdateRenderSwitch(){	const char *opt = gf_cfg_get_key(m_user.config, "Rendering", "RendererName");	m_pToolBar->RemoveTool(SWITCH_RENDER);	if (!stricmp(opt, "GPAC 3D Renderer")) 		m_pToolBar->InsertTool(12, SWITCH_RENDER, *m_pSW3D, wxNullBitmap, FALSE, NULL, wxT("Switch to 2D Renderer"));	else		m_pToolBar->InsertTool(12, SWITCH_RENDER, *m_pSW2D, wxNullBitmap, FALSE, NULL, wxT("Switch to 3D Renderer"));#ifdef WIN32	/*there's a display bug with the menubtn, remove and reinsert*/	m_pToolBar->RemoveTool(FILE_PREV);	m_pToolBar->RemoveTool(FILE_NEXT);	m_pToolBar->InsertControl(2, m_pPrevBut);	m_pToolBar->InsertControl(3, m_pNextBut);#endif	m_pToolBar->Realize();}void wxOsmo4Frame::OnTermReload(wxCommandEvent &WXUNUSED(event)){	ReloadTerminal();}void wxOsmo4Frame::UpdatePlay(){	m_pToolBar->RemoveTool(FILE_PLAY);	if (m_connected) {		if (gf_term_get_option(m_term, GF_OPT_PLAY_STATE)==GF_STATE_PAUSED)			m_pToolBar->InsertTool(5, FILE_PLAY, *m_pPlay, wxNullBitmap, FALSE, NULL, wxT("Pause File"));		else			m_pToolBar->InsertTool(5, FILE_PLAY, *m_pPause, wxNullBitmap, FALSE, NULL, wxT("Play File"));	} else {		m_pToolBar->InsertTool(5, FILE_PLAY, *m_pPlay, wxNullBitmap, FALSE, NULL, wxT("Pause File"));	}#ifdef WIN32	/*there's a display bug with the menubtn, remove and reinsert*/	m_pToolBar->RemoveTool(FILE_PREV);	m_pToolBar->RemoveTool(FILE_NEXT);	m_pToolBar->InsertControl(2, m_pPrevBut);	m_pToolBar->InsertControl(3, m_pNextBut);#endif	m_pToolBar->Realize();}void wxOsmo4Frame::OnCollide(wxCommandEvent & event){	u32 ID = event.GetId();	if (ID==ID_COLLIDE_NONE) gf_term_set_option(m_term, GF_OPT_COLLISION, GF_COLLISION_NONE);	else if (ID==ID_COLLIDE_REG) gf_term_set_option(m_term, GF_OPT_COLLISION, GF_COLLISION_NORMAL);	else if (ID==ID_COLLIDE_DISP) gf_term_set_option(m_term, GF_OPT_COLLISION, GF_COLLISION_DISPLACEMENT);}void wxOsmo4Frame::OnUpdateCollide(wxUpdateUIEvent & event){	u32 ID = event.GetId();	event.Enable(0);	if (!m_connected) return;	event.Enable(1);	u32 mode = gf_term_get_option(m_term, GF_OPT_COLLISION);	if (ID==ID_COLLIDE_NONE) { event.Check((mode==GF_COLLISION_NONE) ? 1 : 0); }	else if (ID==ID_COLLIDE_REG) { event.Check((mode==GF_COLLISION_NORMAL) ? 1 : 0); }	else if (ID==ID_COLLIDE_DISP) { event.Check((mode==GF_COLLISION_DISPLACEMENT) ? 1 : 0); }}void wxOsmo4Frame::OnHeadlight(wxCommandEvent &WXUNUSED(event)){	Bool val = !gf_term_get_option(m_term, GF_OPT_HEADLIGHT);	gf_term_set_option(m_term, GF_OPT_HEADLIGHT, val);}void wxOsmo4Frame::OnUpdateHeadlight(wxUpdateUIEvent & eve

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -