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

📄 gameswf.h

📁 一个开源的嵌入式flash播放器 具体看文档和例子就可
💻 H
📖 第 1 页 / 共 2 页
字号:
	// The "library" is used when importing symbols from external	// movies, so this call might be useful if you want to	// explicitly load a movie that you know exports symbols	// (e.g. fonts) to other movies as well.	//	// @@ this explanation/functionality could be clearer!	//	// This calls add_ref() on the newly created definition; call	// drop_ref() when you're done with it.	// Or use smart_ptr<T> from base/smart_ptr.h if you want.	movie_definition*	create_library_movie(const char* filename);		// Helper to pregenerate cached data (basically, shape	// tesselations).  Does this by running through each frame of	// the movie and displaying the shapes with a null renderer.	// The pregenerated data is stored in the movie_definition	// object itself, and is included with the cached data written	// by movie_definition::output_cached_data().	//	// Note that this tesselates shapes to the resolution they	// explicitly appear in the linear frames of the movie.  Does	// not try very hard to run your ActionScript to account for	// dynamic scaling (that's more or less futile anyway due to	// the halting problem).	void	precompute_cached_data(movie_definition* movie_def);	// Maximum release of resources.  Calls clear_library() and	// fontlib::clear(), and also clears some extra internal stuff	// that may have been allocated (e.g. global ActionScript	// objects).  This should get all gameswf structures off the	// heap, with the exception of any objects that are still	// referenced by the host program and haven't had drop_ref()	// called on them.	void	clear();	//	// Library management	//		// Release any library movies we've cached.  Do this when you want	// maximum cleanup.	void	clear_library();		//	// Font library control.  gameswf is able to substitute fonts	// from the font library, in case a movie lacks glyphs for a	// declared font.  This would come into play since in recent	// versions of SWF, the movie is allowed to use "system	// fonts".  E.g. it can declare a font named "Arial", but not	// provide glyphs for it, and then the OS is expected to	// provide the font or a suitable replacement.	//	// gameswf does not try to handle this automatically; if your	// host program wants to emulate this behavior, it needs to	// load a movie that includes glyph info for the standard	// fonts you want, and then explicitly pull those fonts out of	// the movie_def and add them to fontlib.	//	// @@ TODO: not all public APIs to enable this are in place	// yet!  Need md::get_font_count()/get_font(), and	// fontlib::add_font().	//	// Otherwise, text written in a font with no glyphs just	// doesn't render at all.  (@@ Hm, should probably render it	// as boxes or something?)	struct font;	namespace fontlib	{		// Controls how large to render textured glyphs.		// Applies to fonts processed *after* this call only.		// The "nominal" size is perhaps around twice the		// average glyph height.		void	set_nominal_glyph_pixel_size(int pixel_size);		// For accessing the fonts in the library.		void	clear();		int	get_font_count();		font*	get_font(int index);		font*	get_font(const char* name);		const char*	get_font_name(const font* f);				// @@ also need to add color controls (or just set the diffuse color		// in the API?), perhaps matrix xform, and maybe spacing, etc.		//		// // For direct text rendering from the host app.		void	draw_string(const font* f, float x, float y, float size, const char* text);		// void	draw_string(const font* f, float x, float y, float size, const wchar_t* text);	// wide-char version	}			//	// Sound callback handler.	//		// You may define a subclass of this, and pass an instance to	// set_sound_handler().	struct sound_handler	{		enum format_type		{			FORMAT_RAW = 0,		// unspecified format.  Useful for 8-bit sounds???			FORMAT_ADPCM = 1,	// gameswf doesn't pass this through; it uncompresses and sends FORMAT_NATIVE16			FORMAT_MP3 = 2,			FORMAT_UNCOMPRESSED = 3,	// 16 bits/sample, little-endian			FORMAT_NELLYMOSER = 6,	// Mystery proprietary format; see nellymoser.com							// gameswf tries to convert data to this format when possible:			FORMAT_NATIVE16 = 7	// gameswf extension: 16 bits/sample, native-endian		};		// If stereo is true, samples are interleaved w/ left sample first.				// gameswf calls at load-time with sound data, to be		// played later.  You should create a sample with the		// data, and return a handle that can be used to play		// it later.  If the data is in a format you can't		// deal with, then you can return 0 (for example), and		// then ignore 0's in play_sound() and delete_sound().		//		// Assign handles however you like.		virtual int	create_sound(			void*		data,			int		data_bytes,			int		sample_count,			format_type	format,			int		sample_rate,	/* one of 5512, 11025, 22050, 44100 */			bool		stereo			) = 0;				// gameswf calls this when it wants you to play the defined sound.		//		// loop_count == 0 means play the sound once (1 means play it twice, etc)		virtual void	play_sound(int sound_handle, int loop_count /* , volume, pan, etc? */) = 0;				// Stop the specified sound if it's playing.		// (Normally a full-featured sound API would take a		// handle specifying the *instance* of a playing		// sample, but SWF is not expressive that way.)		virtual void	stop_sound(int sound_handle) = 0;				// gameswf calls this when it's done with a particular sound.		virtual void	delete_sound(int sound_handle) = 0;				virtual ~sound_handler() {};	};		//	// matrix type, used by render handler	//	struct point;	struct matrix	{		float	m_[2][3];		static matrix	identity;		matrix();		bool	is_valid() const;		void	set_identity();		void	concatenate(const matrix& m);		void	concatenate_translation(float tx, float ty);		void	concatenate_scale(float s);		void	set_lerp(const matrix& m1, const matrix& m2, float t);		void	set_scale_rotation(float x_scale, float y_scale, float rotation);		void	read(stream* in);		void	print() const;		void	transform(point* result, const point& p) const;		void	transform_vector(point* result, const point& p) const;		void	transform_by_inverse(point* result, const point& p) const;		void	set_inverse(const matrix& m);		bool	does_flip() const;	// return true if we flip handedness		float	get_determinant() const;	// determinant of the 2x2 rotation/scale part only		float	get_max_scale() const;	// return the maximum scale factor that this transform applies		float	get_x_scale() const;	// return the magnitude scale of our x coord output		float	get_y_scale() const;	// return the magnitude scale of our y coord output		float	get_rotation() const;	// return our rotation component (in radians)	};	//	// point: used by rect which is used by render_handler (otherwise would be in internal gameswf_types.h)	//	struct point	{		float	m_x, m_y;		point() : m_x(0), m_y(0) {}		point(float x, float y) : m_x(x), m_y(y) {}		void	set_lerp(const point& a, const point& b, float t)		// Set to a + (b - a) * t		{			m_x = a.m_x + (b.m_x - a.m_x) * t;			m_y = a.m_y + (b.m_y - a.m_y) * t;		}		bool operator==(const point& p) const { return m_x == p.m_x && m_y == p.m_y; }		bool	bitwise_equal(const point& p) const;	};	//	// rect: rectangle type, used by render handler	//	struct rect	{		float	m_x_min, m_x_max, m_y_min, m_y_max;		void	read(stream* in);		void	print() const;		bool	point_test(float x, float y) const;		void	expand_to_point(float x, float y);		float	width() const { return m_x_max-m_x_min; }		float	height() const { return m_y_max-m_y_min; }		point	get_corner(int i) const;		void	enclose_transformed_rect(const matrix& m, const rect& r);		void	set_lerp(const rect& a, const rect& b, float t);	};	//	// cxform: color transform type, used by render handler	//	struct cxform	{		float	m_[4][2];	// [RGBA][mult, add]		cxform();		void	concatenate(const cxform& c);		rgba	transform(const rgba in) const;		void	read_rgb(stream* in);		void	read_rgba(stream* in);		void	clamp();  // Force component values to be in range.		void	print() const;		static cxform	identity;	};	//	// texture and render callback handler.	//	// Your render_handler creates bitmap_info's for gameswf.  You	// need to subclass bitmap_info in order to add the	// information and functionality your app needs to render	// using textures.	struct bitmap_info : public ref_counted	{		unsigned int	m_texture_id;		// nuke?		int		m_original_width;	// nuke?		int		m_original_height;	// nuke?				bitmap_info()			:			m_texture_id(0),			m_original_width(0),			m_original_height(0)		{		}	};		// You must define a subclass of render_handler, and pass an	// instance to set_render_handler().	struct render_handler	{		virtual ~render_handler() {}		// Your handler should return these with a ref-count of 0.  (@@ is that the right policy?)		virtual bitmap_info*	create_bitmap_info_empty() = 0;	// used when DO_NOT_LOAD_BITMAPS is set		virtual bitmap_info*	create_bitmap_info_alpha(int w, int h, unsigned char* data) = 0;		virtual bitmap_info*	create_bitmap_info_rgb(image::rgb* im) = 0;		virtual bitmap_info*	create_bitmap_info_rgba(image::rgba* im) = 0;		virtual void	delete_bitmap_info(bitmap_info* bi) = 0;				// Bracket the displaying of a frame from a movie.		// Fill the background color, and set up default		// transforms, etc.		virtual void	begin_display(			rgba background_color,			int viewport_x0, int viewport_y0,			int viewport_width, int viewport_height,			float x0, float x1, float y0, float y1) = 0;		virtual void	end_display() = 0;				// Geometric and color transforms for mesh and line_strip rendering.		virtual void	set_matrix(const matrix& m) = 0;		virtual void	set_cxform(const cxform& cx) = 0;				// Draw triangles using the current fill-style 0.		// Clears the style list after rendering.		//		// coords is a list of (x,y) coordinate pairs, in		// triangle-strip order.  The type of the array should		// be Sint16[vertex_count*2]		virtual void	draw_mesh_strip(const void* coords, int vertex_count) = 0;				// Draw a line-strip using the current line style.		// Clear the style list after rendering.		//		// Coords is a list of (x,y) coordinate pairs, in		// sequence.  Each coord is a 16-bit signed integer.		virtual void	draw_line_strip(const void* coords, int vertex_count) = 0;				// Set line and fill styles for mesh & line_strip		// rendering.		enum bitmap_wrap_mode		{			WRAP_REPEAT,			WRAP_CLAMP		};		virtual void	fill_style_disable(int fill_side) = 0;		virtual void	fill_style_color(int fill_side, rgba color) = 0;		virtual void	fill_style_bitmap(int fill_side, const bitmap_info* bi, const matrix& m, bitmap_wrap_mode wm) = 0;				virtual void	line_style_disable() = 0;		virtual void	line_style_color(rgba color) = 0;		virtual void	line_style_width(float width) = 0;				// Special function to draw a rectangular bitmap;		// intended for textured glyph rendering.  Ignores		// current transforms.		virtual void	draw_bitmap(			const matrix&		m,			const bitmap_info*	bi,			const rect&		coords,			const rect&		uv_coords,			rgba			color) = 0;				virtual void	set_antialiased(bool enable) = 0;				virtual void begin_submit_mask() = 0;		virtual void end_submit_mask() = 0;		virtual void disable_mask() = 0;	};		// Keyboard handling	namespace key {		enum code		{			INVALID = 0,			A = 65,			B,			C,			D,			E,			F,			G,			H,			I,			J,			K,			L,			M,			N,			O,			P,			Q,			R,			S,			T,			U,			V,			W,			X,			Y,			Z,			_0 = 48,			_1,			_2,			_3,			_4,			_5,			_6,			_7,			_8,			_9,			KP_0 = 96,			KP_1,			KP_2,			KP_3,			KP_4,			KP_5,			KP_6,			KP_7,			KP_8,			KP_9,			KP_MULTIPLY,			KP_ADD,			KP_ENTER,			KP_SUBTRACT,			KP_DECIMAL,			KP_DIVIDE,			F1 = 112,			F2,			F3,			F4,			F5,			F6,			F7,			F8,			F9,			F10,			F11,			F12,			F13,			F14,			F15,			BACKSPACE = 8,			TAB,			CLEAR = 12,			ENTER,			SHIFT = 16,			CONTROL,			ALT,			CAPSLOCK = 20,			ESCAPE = 27,			SPACE = 32,			PGDN,			PGUP,			END = 35,			HOME,			LEFT,			UP,			RIGHT,			DOWN,			INSERT = 45,			DELETEKEY,			HELP,			NUM_LOCK = 144,			SEMICOLON = 186,			EQUALS = 187,			MINUS = 189,			SLASH = 191,			BACKTICK = 192,			LEFT_BRACKET = 219,			BACKSLASH = 220,			RIGHT_BRACKET = 221,			QUOTE = 222,			KEYCOUNT		};	}	// end namespace key	// Key events are global throughout gameswf.	// @@ Maybe someday make these local to the movie_interface?	void	notify_key_event(key::code k, bool down);	// Some optional helpers.	namespace tools	{		struct process_options		{			bool	m_zip_whole_file;	// @@ not implemented yet (low priority?)			bool	m_remove_image_data;	// removes existing image data; leaves minimal placeholder tags			bool	m_remove_font_glyph_shapes;			process_options()				:				m_zip_whole_file(false),				m_remove_image_data(false),				m_remove_font_glyph_shapes(false)			{			}		};		// Copy tags from *in to *out, applying the given		// options.  *in should be a SWF-format stream.  The		// output will be a SWF-format stream.		//		// Returns 0 on success, or a non-zero error-code on		// failure.		int	process_swf(tu_file* swf_out, tu_file* swf_in, const process_options& options);	}}	// namespace gameswf#endif // GAMESWF_H// Local Variables:// mode: C++// c-basic-offset: 8 // tab-width: 8// indent-tabs-mode: t// End:

⌨️ 快捷键说明

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