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

📄 gameswf_button.cpp

📁 一个开源的Flash 播放器,可以在Windows/Linux 上运行
💻 CPP
📖 第 1 页 / 共 2 页
字号:
							{								s->stop_sound(bs.m_sam->m_sound_handler_id);							}							else							{								s->play_sound(bs.m_sam->m_sound_handler_id, bs.m_sound_style.m_loop_count);							}						}					}				}			}			// @@ eh, should just be a lookup table.			int	c = 0;			if (event.m_id == event_id::ROLL_OVER) c |= (button_action::IDLE_TO_OVER_UP);			else if (event.m_id == event_id::ROLL_OUT) c |= (button_action::OVER_UP_TO_IDLE);			else if (event.m_id == event_id::PRESS) c |= (button_action::OVER_UP_TO_OVER_DOWN);			else if (event.m_id == event_id::RELEASE) c |= (button_action::OVER_DOWN_TO_OVER_UP);			else if (event.m_id == event_id::DRAG_OUT) c |= (button_action::OVER_DOWN_TO_OUT_DOWN);			else if (event.m_id == event_id::DRAG_OVER) c |= (button_action::OUT_DOWN_TO_OVER_DOWN);			else if (event.m_id == event_id::RELEASE_OUTSIDE) c |= (button_action::OUT_DOWN_TO_IDLE);		        //IDLE_TO_OVER_DOWN = 1 << 7,			//OVER_DOWN_TO_IDLE = 1 << 8,			// restart the characters of the new state.			restart_characters(c);			// 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]);					}				}			}}			// Call conventional attached method.			// @@ TODO		}		void restart_characters(int condition)		{			// Restart our relevant characters			for (int i = 0; i < m_def->m_button_records.size(); i++)			{				bool	restart = false;				button_record* rec = &m_def->m_button_records[i];				switch (m_mouse_state)				{				case OVER:				{					if ((rec->m_over) && (condition & button_action::IDLE_TO_OVER_UP))					{						restart = true;					}					break;				}				// @@ Hm, are there other cases where we restart stuff?				default:				{					break;				}				}				if (restart == true)				{					m_record_character[i]->restart();				}			}		}		virtual void	get_mouse_state(int* x, int* y, int* buttons)		{			get_parent()->get_mouse_state(x, y, buttons);		}		//		// ActionScript overrides		//		virtual void	set_member(const tu_stringi& name, const as_value& val)		{			// TODO: pull these up into a base class, to			// share as much as possible with sprite_instance.			as_standard_member	std_member = get_standard_member(name);			switch (std_member)			{			default:			case M_INVALID_MEMBER:				break;			case M_VISIBLE:  // _visible			{				m_visible = val.to_bool();				return;			}			case M_ALPHA:  // _alpha			{				// Set alpha modulate, in percent.				cxform	cx = get_cxform();				cx.m_[3][0] = float(val.to_number()) / 100.f;				set_cxform(cx);				//m_accept_anim_moves = false;				return;			}			case M_X:  // _x			{				matrix	m = get_matrix();	// @@ get_world_matrix()???				m.m_[0][2] = float(PIXELS_TO_TWIPS(val.to_number()));				this->set_matrix(m);				return;			}			case M_Y:  // _y			{				matrix	m = get_matrix();	// @@ get_world_matrix()???				m.m_[1][2] = float(PIXELS_TO_TWIPS(val.to_number()));				this->set_matrix(m);				return;			}// evan : need set_width and set_height function for struct character#if 0			case M_WIDTH:  // _width			{				for (int i = 0; i < m_def->m_button_records.size(); i++)				{					button_record&	rec = m_def->m_button_records[i];					if (m_record_character[i] == NULL)					{						continue;					}					if ((m_mouse_state == UP && rec.m_up)					    || (m_mouse_state == DOWN && rec.m_down)					    || (m_mouse_state == OVER && rec.m_over))					{						m_record_character[i]->set_width(val.to_number);						// @@ evan: should we return here?						return;					}				}				return;			}			case M_HEIGHT:  // _height			{				for (int i = 0; i < m_def->m_button_records.size(); i++)				{					button_record&	rec = m_def->m_button_records[i];					if (m_record_character[i] == NULL)					{						continue;					}					if ((m_mouse_state == UP && rec.m_up)					    || (m_mouse_state == DOWN && rec.m_down)					    || (m_mouse_state == OVER && rec.m_over))					{						m_record_character[i]->set_height(val.to_number);						// @@ evan: should we return here?						return;					}				}				return;			}#endif			}			log_error("error: button_character_instance::set_member('%s', '%s') not implemented yet\n",					  name.c_str(),					  val.to_string());		}		virtual bool	get_member(const tu_stringi& name, as_value* val)		{			// TODO: pull these up into a base class, to			// share as much as possible with sprite_instance.			as_standard_member	std_member = get_standard_member(name);			switch (std_member)			{			default:			case M_INVALID_MEMBER:				break;			case M_VISIBLE:  // _visible			{				val->set_bool(this->get_visible());				return true;			}			case M_ALPHA:  // _alpha			{				// @@ TODO this should be generic to struct character!				// Alpha units are in percent.				val->set_double(get_cxform().m_[3][0] * 100.f);				return true;			}			case M_X:  // _x			{				matrix	m = get_matrix();	// @@ get_world_matrix()???				val->set_double(TWIPS_TO_PIXELS(m.m_[0][2]));				return true;			}			case M_Y:  // _y			{				matrix	m = get_matrix();	// @@ get_world_matrix()???				val->set_double(TWIPS_TO_PIXELS(m.m_[1][2]));				return true;			}			case M_WIDTH:  // _width			{				for (int i = 0; i < m_def->m_button_records.size(); i++)				{					button_record&	rec = m_def->m_button_records[i];					if (m_record_character[i] == NULL)					{						continue;					}					if ((m_mouse_state == UP && rec.m_up)					    || (m_mouse_state == DOWN && rec.m_down)					    || (m_mouse_state == OVER && rec.m_over))					{						val->set_double(TWIPS_TO_PIXELS(m_record_character[i]->get_width()));						// @@ evan: should we return here?						return true;					}				}				// from the experiments with macromedia flash player				val->set_double(0);				return true;			}			case M_HEIGHT:  // _height			{				for (int i = 0; i < m_def->m_button_records.size(); i++)				{					button_record&	rec = m_def->m_button_records[i];					if (m_record_character[i] == NULL)					{						continue;					}					if ((m_mouse_state == UP && rec.m_up)					    || (m_mouse_state == DOWN && rec.m_down)					    || (m_mouse_state == OVER && rec.m_over))					{						val->set_double(TWIPS_TO_PIXELS(m_record_character[i]->get_height()));						// @@ evan: should we return here?						return true;					}				}				// from the experiments with macromedia flash player				val->set_double(0);				return true;			}			}			return false;		}		// not sure if we need to override this one.		//virtual const char*	get_text_value() const { return NULL; }	// edit_text_character overrides this	};	//	// button_record	//	bool	button_record::read(stream* in, int tag_type, movie_definition_sub* m)	// Return true if we read a record; false if this is a null record.	{		int	flags = in->read_u8();		if (flags == 0)		{			return false;		}		m_hit_test = flags & 8 ? true : false;		m_down = flags & 4 ? true : false;		m_over = flags & 2 ? true : false;		m_up = flags & 1 ? true : false;		m_character_id = in->read_u16();		m_character_def = NULL;		m_button_layer = in->read_u16(); 		m_button_matrix.read(in);		if (tag_type == 34)		{			m_button_cxform.read_rgba(in);		}		return true;	}	//	// button_action	//	button_action::~button_action()	{		for (int i = 0, n = m_actions.size(); i < n; i++)		{			delete m_actions[i];		}		m_actions.resize(0);	}	void	button_action::read(stream* in, int tag_type)	{		// Read condition flags.		if (tag_type == 7)		{			m_conditions = OVER_DOWN_TO_OVER_UP;		}		else		{			assert(tag_type == 34);			m_conditions = in->read_u16();		}		// Read actions.		IF_VERBOSE_ACTION(log_msg("-- actions in button\n")); // @@ need more info about which actions		action_buffer*	a = new action_buffer;		a->read(in);		m_actions.push_back(a);	}	//	// button_character_definition	//	button_character_definition::button_character_definition()		:		m_sound(NULL)	// Constructor.	{	}	button_character_definition::~button_character_definition()	{		delete m_sound;	}	void button_character_definition::sound_info::read(stream* in)	{		m_in_point = m_out_point = m_loop_count = 0;		in->read_uint(2);	// skip reserved bits.		m_stop_playback = in->read_uint(1) ? true : false;		m_no_multiple = in->read_uint(1) ? true : false;		m_has_envelope = in->read_uint(1) ? true : false;		m_has_loops = in->read_uint(1) ? true : false;		m_has_out_point = in->read_uint(1) ? true : false;		m_has_in_point = in->read_uint(1) ? true : false;		if (m_has_in_point) m_in_point = in->read_u32();		if (m_has_out_point) m_out_point = in->read_u32();		if (m_has_loops) m_loop_count = in->read_u16();		if (m_has_envelope)		{			int nPoints = in->read_u8();			m_envelopes.resize(nPoints);			for (int i=0; i < nPoints; i++)			{				m_envelopes[i].m_mark44 = in->read_u32();				m_envelopes[i].m_level0 = in->read_u16();				m_envelopes[i].m_level1 = in->read_u16();			}		}		else		{			m_envelopes.resize(0);		}		IF_VERBOSE_PARSE(			log_msg("	has_envelope = %d\n", m_has_envelope);			log_msg("	has_loops = %d\n", m_has_loops);			log_msg("	has_out_point = %d\n", m_has_out_point);			log_msg("	has_in_point = %d\n", m_has_in_point);			log_msg("	in_point = %d\n", m_in_point);			log_msg("	out_point = %d\n", m_out_point);			log_msg("	loop_count = %d\n", m_loop_count);			log_msg("	envelope size = %d\n", m_envelopes.size());		);	}	void	button_character_definition::read(stream* in, int tag_type, movie_definition_sub* m)	// Initialize from the given stream.	{		assert(tag_type == 7 || tag_type == 17 || tag_type == 34);		if (tag_type == 7)		{			// Old button tag.							// Read button character records.			for (;;)			{				button_record	r;				if (r.read(in, tag_type, m) == false)				{					// Null record; marks the end of button records.					break;				}				m_button_records.push_back(r);			}			// Read actions.			m_button_actions.resize(m_button_actions.size() + 1);			m_button_actions.back().read(in, tag_type);		}		else if (tag_type == 17)		{			assert(m_sound == NULL);	// redefinition button sound is error			m_sound = new button_sound_def();			IF_VERBOSE_PARSE(log_msg("button sound options:\n"));			for (int i = 0; i < 4; i++)			{				button_sound_info& bs = m_sound->m_button_sounds[i];				bs.m_sound_id = in->read_u16();				if (bs.m_sound_id > 0)				{					bs.m_sam = (sound_sample_impl*) m->get_sound_sample(bs.m_sound_id);					if (bs.m_sam == NULL)					{//						printf("sound tag not found, sound_id=%d, button state #=%i", bs.sound_id, i);					}					IF_VERBOSE_PARSE(log_msg("\n	sound_id = %d\n", bs.m_sound_id));					bs.m_sound_style.read(in);				}			}		}		else if (tag_type == 34)		{			// Read the menu flag.			m_menu = in->read_u8() != 0;			int	button_2_action_offset = in->read_u16();			int	next_action_pos = in->get_position() + button_2_action_offset - 2;			// Read button records.			for (;;)			{				button_record	r;				if (r.read(in, tag_type, m) == false)				{					// Null record; marks the end of button records.					break;				}				m_button_records.push_back(r);			}			if (button_2_action_offset > 0)			{				in->set_position(next_action_pos);				// Read Button2ActionConditions				for (;;)				{					int	next_action_offset = in->read_u16();					next_action_pos = in->get_position() + next_action_offset - 2;					m_button_actions.resize(m_button_actions.size() + 1);					m_button_actions.back().read(in, tag_type);					if (next_action_offset == 0					    || in->get_position() >= in->get_tag_end_position())					{						// done.						break;					}					// seek to next action.					in->set_position(next_action_pos);				}			}		}	}	character*	button_character_definition::create_character_instance(movie* parent, int id)	// Create a mutable instance of our definition.	{		character*	ch = new button_character_instance(this, parent, id);		return ch;	}};// 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 + -