📄 dx_player.cpp
字号:
// This file is part of Ambulant Player, www.ambulantplayer.org.//// Copyright (C) 2003-2007 Stichting CWI, // Kruislaan 413, 1098 SJ Amsterdam, The Netherlands.//// Ambulant Player is free software; you can redistribute it and/or modify// it under the terms of the GNU Lesser General Public License as published by// the Free Software Foundation; either version 2.1 of the License, or// (at your option) any later version.//// Ambulant Player 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 Lesser General Public License for more details.//// You should have received a copy of the GNU Lesser General Public License// along with Ambulant Player; if not, write to the Free Software// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA/* * @$Id: dx_player.cpp,v 1.77 2007/02/12 14:14:56 jackjansen Exp $ */#include "ambulant/gui/dx/dx_player.h"#include "ambulant/gui/dx/dx_viewport.h"#include "ambulant/gui/dx/dx_window.h"#include "ambulant/gui/dx/dx_wmuser.h"#include "ambulant/gui/dx/dx_rgn.h"#include "ambulant/gui/dx/dx_transition.h"#include "ambulant/lib/event.h"#include "ambulant/lib/event_processor.h"#include "ambulant/lib/asb.h"#include "ambulant/lib/document.h"#include "ambulant/lib/textptr.h"#include "ambulant/lib/logger.h"#include "ambulant/lib/transition_info.h"//#include "ambulant/common/plugin_engine.h"#include "ambulant/smil2/transition.h"// Players#include "ambulant/smil2/smil_player.h"#include "ambulant/mms/mms_player.h"#include "ambulant/smil2/test_attrs.h"// Renderer playables#include "ambulant/gui/dx/html_bridge.h"#include "ambulant/gui/dx/dx_bgrenderer.h"#include "ambulant/gui/dx/dx_text.h"#include "ambulant/gui/dx/dx_html_renderer.h"#include "ambulant/gui/dx/dx_img.h"#include "ambulant/gui/dx/dx_audio.h"#include "ambulant/gui/dx/dx_video.h"#include "ambulant/gui/dx/dx_brush.h"// "Renderer" playables#include "ambulant/gui/dx/dx_audio.h"// Playables#include "ambulant/gui/dx/dx_area.h"// Layout#include "ambulant/common/region.h"#include "ambulant/smil2/smil_layout.h"// Xerces parser#ifdef WITH_XERCES_BUILTIN#include "ambulant/lib/xerces_parser.h"#endif// Datasources#include "ambulant/net/datasource.h"#include "ambulant/net/win32_datasource.h"//#define AM_DBG#ifndef AM_DBG#define AM_DBG if(0)#endifusing namespace ambulant;int gui::dx::dx_gui_region::s_counter = 0;gui::dx::dx_player::dx_player(dx_player_callbacks &hoster, common::player_feedback *feedback, const net::url& u) : m_hoster(hoster), m_update_event(0), m_logger(lib::logger::get_logger()){ set_embedder(this); // Fill the factory objects init_factories(); init_plugins(); // Parse the provided URL. AM_DBG m_logger->debug("Parsing: %s", u.get_url().c_str()); m_doc = create_document(u); if(!m_doc) { // message already logged return; } // If there's a fragment ID remember the node it points to, // and when we first start playback we'll go there. const std::string& idd = u.get_ref(); if (idd != "") { const lib::node *node = m_doc->get_node(idd); if (node) { goto_node(node); } else { m_logger->warn(gettext("%s: node ID not found"), idd.c_str()); } } // Create a player instance AM_DBG m_logger->debug("Creating player instance for: %s", u.get_url().c_str()); m_player = new smil2::smil_player(m_doc, this, m_embedder); if (feedback) m_player->set_feedback(feedback); m_player->initialize(); // Create a worker processor instance}gui::dx::dx_player::~dx_player() { if(m_player) stop(); delete m_player; while(!m_frames.empty()) { frame *pf = m_frames.top(); m_frames.pop(); m_windows = pf->windows; m_player = pf->player; m_doc = pf->doc; delete pf; stop(); delete m_player; } m_player = NULL; assert(m_windows.empty()); if(dx_gui_region::s_counter != 0) m_logger->warn("Undeleted gui regions: %d", dx_gui_region::s_counter);}voidgui::dx::dx_player::init_playable_factory(){ common::global_playable_factory *pf = common::get_global_playable_factory(); set_playable_factory(pf); // Add the playable factory pf->add_factory(new dx_playable_factory(this, m_logger, this));}voidgui::dx::dx_player::init_window_factory(){ set_window_factory(this); }voidgui::dx::dx_player::init_datasource_factory(){ net::datasource_factory *df = new net::datasource_factory(); set_datasource_factory(df); // Add the datasource factories. For now we only need a raw // datasource factory. df->add_raw_factory(net::get_win32_datasource_factory());}voidgui::dx::dx_player::init_parser_factory(){ lib::global_parser_factory *pf = lib::global_parser_factory::get_parser_factory(); set_parser_factory(pf); // Add the xerces parser, if available#ifdef WITH_XERCES_BUILTIN pf->add_factory(new lib::xerces_factory());#endif}void gui::dx::dx_player::play() { if(m_player) { common::gui_player::play(); std::map<std::string, wininfo*>::iterator it; for(it=m_windows.begin();it!=m_windows.end();it++) { dx_window *dxwin = (dx_window *)(*it).second->w; dxwin->need_redraw(); } }}void gui::dx::dx_player::stop() { if(m_player) { m_update_event = 0; clear_transitions(); common::gui_player::stop(); }}void gui::dx::dx_player::pause() { if(m_player) { common::gui_player::pause(); }}void gui::dx::dx_player::restart(bool reparse) { bool playing = is_play_active(); stop(); delete m_player; while(!m_frames.empty()) { frame *pf = m_frames.top(); m_frames.pop(); m_windows = pf->windows; m_player = pf->player; m_doc = pf->doc; delete pf; stop(); delete m_player; } m_player = 0; if (reparse) { m_doc = create_document(m_url); if(!m_doc) { m_logger->show("Failed to parse document %s", m_url.get_url().c_str()); return; } } AM_DBG m_logger->debug("Creating player instance for: %s", m_url.get_url().c_str()); m_player = new smil2::smil_player(m_doc, this, m_embedder); m_player->initialize(); if(playing) play(); }#if 0bool gui::dx::dx_player::is_playing() const { return (m_player && m_player->is_playing()) || !m_frames.empty();}bool gui::dx::dx_player::is_pausing() const { return m_player && m_player->is_pausing();}bool gui::dx::dx_player::is_done() const { return m_player && m_player->is_done() && m_frames.empty();}void gui::dx::dx_player::set_preferences(const std::string& url) { smil2::test_attrs::load_test_attrs(url); if(is_playing()) stop(); if(m_player) m_player->build_timegraph();}#endifvoid gui::dx::dx_player::on_click(int x, int y, HWND hwnd) { if(!m_player) return; lib::point pt(x, y); dx_window *dxwin = (dx_window *) get_window(hwnd); if(!dxwin) return; region *r = dxwin->get_region(); if(r) r->user_event(pt, common::user_event_click);}int gui::dx::dx_player::get_cursor(int x, int y, HWND hwnd) { if(!m_player) return 0; lib::point pt(x, y); dx_window *dxwin = (dx_window *) get_window(hwnd); if(!dxwin) return 0; region *r = dxwin->get_region(); m_player->before_mousemove(0); if(r) r->user_event(pt, common::user_event_mouse_over); return m_player->after_mousemove();}std::string gui::dx::dx_player::get_pointed_node_str() {#if 1 return "";#else if(!m_player || !is_playing()) return ""; return m_player->get_pointed_node_str();#endif}void gui::dx::dx_player::on_char(int ch) { if(m_player) m_player->on_char(ch);}void gui::dx::dx_player::redraw(HWND hwnd, HDC hdc) { wininfo *wi = get_wininfo(hwnd); if(wi) wi->v->redraw(hdc);}void gui::dx::dx_player::on_done() { std::map<std::string, wininfo*>::iterator it; for(it=m_windows.begin();it!=m_windows.end();it++) { (*it).second->v->clear(); (*it).second->v->redraw(); }}void gui::dx::dx_player::lock_redraw() { std::map<std::string, wininfo*>::iterator it; for(it=m_windows.begin();it!=m_windows.end();it++) { (*it).second->w->lock_redraw(); }}void gui::dx::dx_player::unlock_redraw() { std::map<std::string, wininfo*>::iterator it; for(it=m_windows.begin();it!=m_windows.end();it++) { (*it).second->w->unlock_redraw(); }}////////////////////// common::window_factory implementationcommon::gui_window *gui::dx::dx_player::new_window(const std::string &name, lib::size bounds, common::gui_events *src) { AM_DBG lib::logger::get_logger()->debug("dx_window_factory::new_window(%s): %s", name.c_str(), ::repr(bounds).c_str()); // wininfo struct that will hold the associated objects wininfo *winfo = new wininfo; // Create an os window winfo->h = m_hoster.new_os_window(); // Create the associated dx viewport winfo->v = create_viewport(bounds.w, bounds.h, winfo->h); // Region? region *rgn = (region *) src; // Clear the viewport const common::region_info *ri = rgn->get_info(); winfo->v->set_background(ri?ri->get_bgcolor():CLR_INVALID); winfo->v->clear(); // Create a concrete gui_window winfo->w = new dx_window(name, bounds, rgn, this, winfo->v);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -