📄 dg_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: dg_player.cpp,v 1.32 2007/02/12 14:14:51 jackjansen Exp $ */ //#define AM_DBG#ifndef AM_DBG#define AM_DBG if(0)#endif#include "ambulant/gui/dg/dg_player.h"#include "ambulant/gui/dg/dg_viewport.h"#include "ambulant/gui/dg/dg_window.h"#include "ambulant/gui/dg/dg_wmuser.h"#include "ambulant/gui/dg/dg_rgn.h"#include "ambulant/gui/dg/dg_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/logger.h"#include "ambulant/lib/textptr.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/dg/dg_bgrenderer.h"#include "ambulant/gui/dg/dg_text.h"#include "ambulant/gui/dg/dg_img.h"#include "ambulant/gui/dg/dg_brush.h"// Playables#include "ambulant/gui/dg/dg_area.h"#include "ambulant/gui/dg/dg_audio.h"// Layout#include "ambulant/common/region.h"#include "ambulant/smil2/smil_layout.h"#include "ambulant/net/win32_datasource.h"using namespace ambulant;int gui::dg::dg_gui_region::s_counter = 0;gui::dg::dg_player::dg_player(dg_player_callbacks &hoster, const net::url& u) : m_hoster(hoster), m_timer(new timer_control_impl(realtime_timer_factory(), 1.0, false)), m_worker_processor(0), m_update_event(0), m_logger(lib::logger::get_logger()){ set_embedder(this); init_factories(); init_plugins(); // Parse the provided URL. AM_DBG m_logger->debug("Parsing: %s", u.get_url().c_str()); m_doc = lib::document::create_from_url(this, u); if(!m_doc) { m_logger->show("Failed to parse document %s", u.get_url().c_str()); return; } // 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); m_player->initialize(); // Create the worker processor m_worker_processor = event_processor_factory(m_timer);}gui::dg::dg_player::~dg_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; delete pf; stop(); delete m_player; } m_timer->pause(); if(m_worker_processor) m_worker_processor->cancel_all_events(); delete m_worker_processor; delete m_timer; assert(m_windows.empty()); if(dg_gui_region::s_counter != 0) m_logger->warn("Undeleted gui regions: %d", dg_gui_region::s_counter);}voidgui::dg::dg_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 dg_playable_factory(this, m_logger, this));}voidgui::dg::dg_player::init_window_factory(){ set_window_factory(this); }voidgui::dg::dg_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::dg::dg_player::init_parser_factory(){ set_parser_factory(lib::global_parser_factory::get_parser_factory());}#if 0void gui::dg::dg_player::start() { if(m_player) { m_timer->resume(); m_player->start(); std::map<std::string, wininfo*>::iterator it; for(it=m_windows.begin();it!=m_windows.end();it++) { dg_window *dgwin = (dg_window *)(*it).second->w; dgwin->need_redraw(); } }}void gui::dg::dg_player::stop() { if(m_player) { m_player->stop(); m_timer->pause(); on_done(); }}void gui::dg::dg_player::pause() { if(m_player) { if(m_player->is_playing()) { m_player->pause(); m_timer->pause(); } else if(m_player->is_pausing()) { m_player->resume(); m_timer->resume(); } }}void gui::dg::dg_player::resume() { if(m_player) { m_player->resume(); m_timer->resume(); }}#endifvoid gui::dg::dg_player::on_click(int x, int y, HWND hwnd) { if(!m_player) return; lib::point pt(x, y); dg_window *dgwin = (dg_window *) get_window(hwnd); if(!dgwin) return; region *r = dgwin->get_region(); if(r) r->user_event(pt, common::user_event_click);}int gui::dg::dg_player::get_cursor(int x, int y, HWND hwnd) { if(!m_player) return 0; lib::point pt(x, y); dg_window *dgwin = (dg_window *) get_window(hwnd); if(!dgwin) return 0; region *r = dgwin->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::dg::dg_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::dg::dg_player::on_char(int ch) { if(m_player) m_player->on_char(ch);}void gui::dg::dg_player::redraw(HWND hwnd, HDC hdc) { wininfo *wi = get_wininfo(hwnd); if(wi) wi->v->redraw(hdc);}void gui::dg::dg_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(); }}////////////////////// common::window_factory implementationcommon::gui_window *gui::dg::dg_player::new_window(const std::string &name, lib::size bounds, common::gui_events *src) { AM_DBG lib::logger::get_logger()->debug("dg_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 dg 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 dg_window(name, bounds, rgn, this, winfo->v); winfo->f = 0; // Store the wininfo struct m_windows[name] = winfo; AM_DBG m_logger->debug("windows: %d", m_windows.size()); // Return gui_window return winfo->w;}void gui::dg::dg_player::window_done(const std::string &name) { // called when the window is destructed (wi->w) std::map<std::string, wininfo*>::iterator it = m_windows.find(name); assert(it != m_windows.end()); wininfo *wi = (*it).second; m_windows.erase(it); wi->v->clear();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -