当前位置: 首页>>代码示例>>C++>>正文


C++ Ptr::HandleEvent方法代码示例

本文整理汇总了C++中sfg::window::Ptr::HandleEvent方法的典型用法代码示例。如果您正苦于以下问题:C++ Ptr::HandleEvent方法的具体用法?C++ Ptr::HandleEvent怎么用?C++ Ptr::HandleEvent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sfg::window::Ptr的用法示例。


在下文中一共展示了Ptr::HandleEvent方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: Run

void Application::Run() {
	sf::RenderWindow app_window( sf::VideoMode( 800, 600 ), "SFGUI Button Example", sf::Style::Titlebar | sf::Style::Close );

	// We have to do this because we don't use SFML to draw.
	app_window.resetGLStates();

	window = sfg::Window::Create();
	window->SetTitle( "Title" );

	sfg::Box::Ptr box = sfg::Box::Create( sfg::Box::VERTICAL );
	window->Add( box );

	// Possibility 1, normal function
	sfg::Button::Ptr button1 = sfg::Button::Create();
	button1->SetLabel( "Clicky 1" );
	button1->OnLeftClick.Connect( &Foo );
	box->Pack( button1, false );

	// Possibility 2, this class
	sfg::Button::Ptr button2 = sfg::Button::Create();
	button2->SetLabel( "Clicky 2" );
	button2->OnLeftClick.Connect( &Application::Bar, this );
	box->Pack( button2, false );

	// Possibility 3, objects
	BazClass baz_array[3] = { BazClass( 1 ), BazClass( 2 ), BazClass( 3 ) };

	for( int i = 0; i < 3; i++ ) {
		std::stringstream sstr;
		sstr << "Clicky " << i + 3;
		sfg::Button::Ptr button = sfg::Button::Create();
		button->SetLabel( sstr.str() );
		// This is just a more complicated way of passing a pointer to a
		// BazClass to Connect() when the BazClass object is part of an array.
		// Passing normal pointers such as &baz1 would also work.
		button->OnLeftClick.Connect( &BazClass::Baz, &( baz_array[i] ) );
		box->Pack( button, false );
	}

	// Notice that with possibility 3 you can do very advanced things. The tricky
	// part of implementing it this way is that the method address has to be
	// known at compile time, which means that only the instanciated object itself
	// is able to pick how it will behave when that method is called on it. This
	// way you can also connect signals to dynamically determined behavior.

	// For further reading on this topic refer to Design Patterns and as
	// specialized cases similar to the one in this example the
	// Factory Method Pattern and Abstract Factory Pattern.

	while ( app_window.isOpen() ) {
		sf::Event event;

		while ( app_window.pollEvent( event ) ) {
			window->HandleEvent( event );

			if ( event.type == sf::Event::Closed ) {
				app_window.close();
			}
		}

		// Update the GUI, note that you shouldn't normally
		// pass 0 seconds to the update method.
		window->Update( 0.f );

		// Clear screen
		app_window.clear();

		// Draw the GUI
		m_sfgui.Display( app_window );

		// Update the window
		app_window.display();
	}

	// If you have any global or static widgets,
	// you need to reset their pointers before your
	// application exits.
	window.reset();
}
开发者ID:tobiasthanos,项目名称:SFML-testing,代码行数:79,代码来源:Signals.cpp

示例2: Run

void ButtonsExample::Run() {
	// Create the main SFML window
	sf::RenderWindow app_window( sf::VideoMode( 800, 600 ), "SFGUI Buttons Example", sf::Style::Titlebar | sf::Style::Close );

	// We have to do this because we don't use SFML to draw.
	app_window.resetGLStates();

	// Create our main SFGUI window
	m_window = sfg::Window::Create();
	m_window->SetTitle( "Title" );

	// Create a Box to contain all our fun buttons ;)
	sfg::Box::Ptr box = sfg::Box::Create( sfg::Box::VERTICAL, 5.f );

	// Create the Button itself.
	m_button = sfg::Button::Create( "Click me" );

	// Add the Button to the Box
	box->Pack( m_button );

	// So that our Button has a meaningful purpose
	// (besides just looking awesome :P) we need to tell it to connect
	// to a callback of our choosing to notify us when it is clicked.
	m_button->GetSignal( sfg::Widget::OnLeftClick ).Connect( &ButtonsExample::ButtonClick, this );

	// If attempting to connect to a class method you need to provide
	// a pointer to it as the second parameter after the function address.
	// Refer to the Signals example for more information.

	// Create the ToggleButton itself.
	m_toggle_button = sfg::ToggleButton::Create( "Toggle me" );

	// Connect the OnToggle signal to our handler.
	m_toggle_button->GetSignal( sfg::ToggleButton::OnToggle ).Connect( &ButtonsExample::ButtonToggle, this );

	// Add the ToggleButton to the Box
	box->Pack( m_toggle_button );

	// Create the CheckButton itself.
	m_check_button = sfg::CheckButton::Create( "Check me" );

	// Since a CheckButton is also a ToggleButton we can use
	// ToggleButton signals to handle events for CheckButtons.
	m_check_button->GetSignal( sfg::ToggleButton::OnToggle ).Connect( &ButtonsExample::ButtonCheck, this );

	// Add the CheckButton to the Box
	box->Pack( m_check_button );

	// Just to keep things tidy ;)
	box->Pack( sfg::Separator::Create() );

	// Create our RadioButtons.
	// RadioButtons each have a group they belong to. If not specified,
	// a new group is created by default for each RadioButton. You can
	// then use RadioButton::SetGroup() to set the group of a RadioButton
	// after you create them. If you already know which buttons will belong
	// to the same group you can just pass the group of the first button
	// to the following buttons when you construct them as we have done here.
	m_radio_button1 = sfg::RadioButton::Create( "Either this" );
	m_radio_button2 = sfg::RadioButton::Create( "Or this", m_radio_button1->GetGroup() );
	m_radio_button3 = sfg::RadioButton::Create( "Or maybe even this", m_radio_button1->GetGroup() );

	// Set the third RadioButton to be the active one.
	// By default none of the RadioButtons are active at start.
	m_radio_button3->SetActive( true );

	// Here we use the same handler for all three RadioButtons.
	// RadioButtons are CheckButtons and therefore also ToggleButtons,
	// hence we can use ToggleButton signals with RadioButtons as well.
	m_radio_button1->GetSignal( sfg::ToggleButton::OnToggle ).Connect( &ButtonsExample::ButtonSelect, this );
	m_radio_button2->GetSignal( sfg::ToggleButton::OnToggle ).Connect( &ButtonsExample::ButtonSelect, this );
	m_radio_button3->GetSignal( sfg::ToggleButton::OnToggle ).Connect( &ButtonsExample::ButtonSelect, this );

	// Add the RadioButtons to the Box
	box->Pack( m_radio_button1 );
	box->Pack( m_radio_button2 );
	box->Pack( m_radio_button3 );

	// Finally add the Box to the window.
	m_window->Add( box );

	// Start the game loop
	while ( app_window.isOpen() ) {
		// Process events
		sf::Event event;

		while ( app_window.pollEvent( event ) ) {
			// Handle events
			m_window->HandleEvent( event );

			// Close window : exit
			if ( event.type == sf::Event::Closed ) {
				app_window.close();
			}
		}

		// Update the GUI, note that you shouldn't normally
		// pass 0 seconds to the update method.
		m_window->Update( 0.f );

//.........这里部分代码省略.........
开发者ID:DrJonki,项目名称:I-want-it-back,代码行数:101,代码来源:Buttons.cpp


注:本文中的sfg::window::Ptr::HandleEvent方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。