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

📄 gameswf_movie.cpp

📁 一个开源的嵌入式flash播放器 具体看文档和例子就可
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// gameswf_xml.h      -- Rob Savoye <rob@welcomehome.org> 2005// This source code has been donated to the Public Domain.  Do// whatever you want with it.#include "base/tu_config.h"#include <sys/types.h>#include <sys/stat.h>#ifdef HAVE_LIBXML// TODO: http and sockets and such ought to be factored out into an// abstract driver, like we do for file access.#include <libxml/nanohttp.h>#ifdef HAVE_WINSOCK# include <windows.h># include <sys/stat.h># include <io.h>#else# include <unistd.h># include <fcntl.h>#endif#endif#include "gameswf_movie.h"#include "gameswf_log.h"#include "base/tu_file.h"#include "base/image.h"#include "gameswf_render.h"#include "gameswf_impl.h"namespace gameswf{    MovieClipLoader::MovieClipLoader()      // :     character(0, 0){  log_msg("%s: \n", __FUNCTION__);  _mcl.bytes_loaded = 0;  _mcl.bytes_total = 0;  }MovieClipLoader::~MovieClipLoader(){  log_msg("%s: \n", __FUNCTION__);}voidMovieClipLoader::load(const tu_string& filespec){  log_msg("%s: \n", __FUNCTION__);}// progress of the downloaded file(s).struct mcl *MovieClipLoader::getProgress(as_object *ao){  //log_msg("%s: \n", __FUNCTION__);  return &_mcl;}boolMovieClipLoader::loadClip(const tu_string& str, void *){  log_msg("%s: \n", __FUNCTION__);  return false;}voidMovieClipLoader::unloadClip(void *){  log_msg("%s: \n", __FUNCTION__);}voidMovieClipLoader::addListener(void *){  log_msg("%s: \n", __FUNCTION__);}voidMovieClipLoader::removeListener(void *){  log_msg("%s: \n", __FUNCTION__);}  // CallbacksvoidMovieClipLoader::onLoadStart(void *){  log_msg("%s: \n", __FUNCTION__);}voidMovieClipLoader::onLoadProgress(void *){  log_msg("%s: \n", __FUNCTION__);}voidMovieClipLoader::onLoadInit(void *){  log_msg("%s: \n", __FUNCTION__);}voidMovieClipLoader::onLoadComplete(void *){  log_msg("%s: \n", __FUNCTION__);}voidMovieClipLoader::onLoadError(void *){  log_msg("%s: \n", __FUNCTION__);}voidMovieClipLoader::on_button_event(event_id event){  log_msg("%s: \n", __FUNCTION__);    // Set our mouse state (so we know how to render).  switch (event.m_id)    {    case event_id::ROLL_OUT:    case event_id::RELEASE_OUTSIDE:      _mouse_state = MOUSE_UP;      break;          case event_id::RELEASE:    case event_id::ROLL_OVER:    case event_id::DRAG_OUT:      _mouse_state = MOUSE_OVER;      break;          case event_id::PRESS:    case event_id::DRAG_OVER:      _mouse_state = MOUSE_DOWN;      break;          default:      assert(0);	// missed a case?      break;    };    // @@ eh, should just be a lookup table.#if 0  // Add appropriate actions to the movie's execute list...  for (int i = 0; i < m_def->m_button_actions.size(); i++) {    if (m_def->m_button_actions[i].m_conditions & c) {      // Matching action.      for (int j = 0; j < m_def->m_button_actions[i].m_actions.size(); j++) {        get_parent()->add_action_buffer(m_def->m_button_actions[i].m_actions[j]);      }    }  }#endif  // Call conventional attached method.  // @@ TODO}void moviecliploader_loadclip(const fn_call& fn){#ifdef HAVE_LIBXML  //as_value* result = fn.result;  //as_object_interface* this_ptr = fn.this_ptr;  //int nargs = fn.nargs;  //int first_arg = fn.first_arg_bottom_index;  //as_environment* env = fn.env;  as_value	val, method;  struct stat   stats;  int           fd;  fn.result->set(true);         // FIXME:  log_msg("%s: FIXME: this function disabled for memory leak testing.\n", __FUNCTION__);  return;                       // FIXME:    log_msg("%s: nargs = %d\n", __FUNCTION__, fn.nargs);  moviecliploader_as_object*	ptr = (moviecliploader_as_object*) (as_object*) fn.this_ptr;    tu_string url = fn.env->bottom(fn.first_arg_bottom_index).to_string();    as_object *target = (as_object *)fn.env->bottom(fn.first_arg_bottom_index-1).to_object();  log_msg("load clip: %s, target is: %p\n", url.c_str(), target);  xmlNanoHTTPInit();            // This doesn't do much for now, but in the                                // future it might, so here it is...    if (url.utf8_substring(0, 4) == "file") {    url = url.utf8_substring(19, url.length());    // If the file doesn't exist, don't try to do anything.    if (stat(url.c_str(), &stats) < 0) {      fprintf(stderr, "ERROR: doesn't exist: %s\n", url.c_str());      fn.result->set(false);      return;    }  }    if (target == NULL) {    //log_error("target doesn't exist:\n");      fn.result->set(false);      return;      }    // Grab the filename off the end of the URL, and use the same name  // as the disk file when something is fetched. Store files in /tmp/.  // If the file exists, libxml properly replaces it.  char *filename = strrchr(url.c_str(), '/');  tu_string filespec = "/tmp";  filespec += filename;       // fetch resource from URL  xmlNanoHTTPFetch(url.c_str(), filespec.c_str(), NULL);    // Call the callback since we've started loading the file  if (fn.this_ptr->get_member("onLoadStart", &method)) {    //log_msg("FIXME: Found onLoadStart!\n");    as_c_function_ptr	func = method.to_c_function();    fn.env->set_variable("success", true, 0);    if (func)      {        // It's a C function.  Call it.        //log_msg("Calling C function for onLoadStart\n");        (*func)(fn_call(&val, fn.this_ptr, fn.env, 0, 0));      }    else if (as_as_function* as_func = method.to_as_function())      {        // It's an ActionScript function.  Call it.        //log_msg("Calling ActionScript function for onLoadStart\n");        (*as_func)(fn_call(&val, fn.this_ptr, fn.env, 0, 0));      }    else      {        log_error("error in call_method(): method is not a function\n");      }      } else {    log_error("Couldn't find onLoadStart!\n");  }  xmlNanoHTTPCleanup();  // See if the file exists  if (stat(filespec.c_str(), &stats) < 0) {    log_error("Clip doesn't exist: %s\n", filespec.c_str());    fn.result->set(false);    return;  }  tu_string suffix = filespec.utf8_substring(filespec.length() - 4, filespec.length());  //log_msg("File suffix to load is: %s\n", suffix.c_str());  if (suffix == ".swf") {    movie_definition_sub*	md = create_library_movie_sub(filespec.c_str());    if (md == NULL) {      log_error("can't create movie_definition_sub for %s\n", filespec.c_str());      return;    }    gameswf::movie_interface* extern_movie;    extern_movie = md->create_instance();    if (extern_movie == NULL) {      log_error("can't create extern movie_interface for %s\n", filespec.c_str());      return;    }      save_extern_movie(extern_movie);        character* tar = (character*)target;    const char* name = tar->get_name();    Uint16 depth = tar->get_depth();    bool use_cxform = false;    cxform color_transform =  tar->get_cxform();    bool use_matrix = false;    matrix mat = tar->get_matrix();    float ratio = tar->get_ratio();    Uint16 clip_depth = tar->get_clip_depth();        movie* parent = tar->get_parent();    movie* new_movie = static_cast<movie*>(extern_movie)->get_root_movie();        assert(parent != NULL);        ((character*)new_movie)->set_parent(parent);        parent->replace_display_object((character*) new_movie,                                   name,                                   depth,                                   use_cxform,                                   color_transform,                                   use_matrix,                                   mat,                                   ratio,                                   clip_depth);  } else if (suffix == ".jpg") {    // Just case the filespec suffix claims it's a jpeg, we have to check,    // since when grabbing an image from a web server that doesn't exist,    // we don't get an error, we get a short HTML page containing a 404.

⌨️ 快捷键说明

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