Exemple #1
0
void ComboBox::HandleStateChange( State old_state ) {
	Bin::HandleStateChange( old_state );

	if( GetState() == ACTIVE ) {
		SetZOrder( 1 );

		GrabModal();

		m_start_entry = 0;

		float padding( Context::Get().GetEngine().GetProperty<float>( "ItemPadding", shared_from_this() ) );
		const std::string& font_name( Context::Get().GetEngine().GetProperty<std::string>( "FontName", shared_from_this() ) );
		unsigned int font_size( Context::Get().GetEngine().GetProperty<unsigned int>( "FontSize", shared_from_this() ) );
		const sf::Font& font( *Context::Get().GetEngine().GetResourceManager().GetFont( font_name ) );
		const float line_height( Context::Get().GetEngine().GetFontLineHeight( font, font_size ) );

		if( ( GetDisplayedItems() > 2 ) && ( GetDisplayedItems() < GetItemCount() ) ) {
			float border_width( Context::Get().GetEngine().GetProperty<float>( "BorderWidth", shared_from_this() ) );


			const sf::Vector2f item_size(
				GetAllocation().width - 2 * border_width,
				line_height + 2 * padding
			);

			m_scrollbar = Scrollbar::Create( Scrollbar::VERTICAL );

			float offset = ( GetState() == ACTIVE ? border_width : 0.f ) + GetAllocation().width - padding - line_height;

			m_scrollbar->SetPosition( sf::Vector2f( offset, GetAllocation().height + border_width ) );
			m_scrollbar->SetRequisition( sf::Vector2f( GetAllocation().width - offset, static_cast<float>( GetDisplayedItems() ) * item_size.y - 2.f * border_width ) );

			m_scrollbar->GetAdjustment()->SetPageSize( static_cast<float>( GetDisplayedItems() ) );
			m_scrollbar->GetAdjustment()->SetLower( 0.f );
			m_scrollbar->GetAdjustment()->SetUpper( static_cast<float>( GetItemCount() ) );
			m_scrollbar->GetAdjustment()->SetMinorStep( 1.f );
			m_scrollbar->GetAdjustment()->SetMajorStep( 1.f );

			m_scrollbar->GetAdjustment()->GetSignal( Adjustment::OnChange ).Connect( &ComboBox::ChangeStartEntry, this );

			m_scrollbar->SetZOrder( 2 );

			Add( m_scrollbar );
		}
	}
	else {
		SetZOrder( 0 );

		if( m_scrollbar ) {
			Remove( m_scrollbar );

			m_scrollbar.reset();
		}
	}
}
void UCanvasPanelSlot::SynchronizeProperties()
{
	SetOffsets(LayoutData.Offsets);
	SetAnchors(LayoutData.Anchors);
	SetAlignment(LayoutData.Alignment);
	SetAutoSize(bAutoSize);
	SetZOrder(ZOrder);
}
Background::Background(const BackgroundResource& res)
   : mXScreen(SDL_GetVideoSurface()->w)
   , mYScreen(SDL_GetVideoSurface()->h)
{
   SetResourceId(res.GetId());
   SetSize(res.GetSize());
   SetZOrder(ZOrder::zo_Background);

   // TODO: Background must have a "buttom" coordinate.
}
			void Execute()
			{
				auto projectile = mWeapon->GetProjectile()->Clone();
				projectile->SetPosition(mPosition);
				projectile->SetVelocity(sf::Vector2f(projectile->GetSpeed(), 0.0f));
				projectile->SetRotation(0.0f);
				projectile->SetZOrder(50);
				projectile->SetCurrentAimpoint(mCurrAim);
				projectile->SetFinalAimpoint(mFinalAim);
				projectile->Fire();
				mDrawNode->Add(projectile);
			}
			shared_ptr<Projectile> Clone()
			{
				auto clone = make_shared<Projectile>(mId, mName, mFilename, mRef, mWpnId, mSpeed, mAimpointUpdateDelayMs, mCurrentAimpoint, mFinalAimpoint);
				clone->SetPosition(this->GetPosition());
				clone->SetVelocity(this->GetVelocity());
				clone->SetAlive(this->IsAlive());
				clone->SetColor(this->GetColor());
				clone->SetOrigin(this->GetOrigin());
				clone->SetRotation(this->GetRotation());
				clone->SetScale(this->GetScale().x, this->GetScale().y);
				clone->SetZOrder(this->GetZOrder());
				return clone;
			}
Exemple #6
0
	//--------------------------------------------------------------------------------------------------------------
	//向用户界面对象发送消息
	LONG_PTR GuiTrackBar::SendMsg( LONG_PTR nGM, LONG_PTR nGMA, LONG_PTR nGMB )
	{
		switch (nGM)
		{
			case GM_Enable:
				Enable( ( nGMA == 1 ) ? true : false );
				return TRUE;
			case GM_Show:
				Show( ( nGMA == 1 ) ? true : false );
				return TRUE;
			case GM_Focus:
				Focus( ( nGMA == 1 ) ? true : false );
				return TRUE;
			case GM_MouseMove:
				MouseMove( (InputSystem*)nGMA );
				return TRUE;
			case GM_SetPos:
				SetPos( nGMA, nGMB );
				return TRUE;
			case GM_MovePos:
				SetPos( mLoca.X + nGMA, mLoca.Y + nGMB );
				return TRUE;
			case GM_SetZOrder:
				SetZOrder( (ZOrderType)nGMA, (OverlaySurface*)nGMB );
				return TRUE;
			case GM_GetZOrder:
				return (LONG_PTR)GetZOrder( (ZOrderType)nGMA );
			case GM_LDown:
				LDown( (InputSystem*)nGMA );
				return TRUE;
			case GM_LUp:
				LUp( (InputSystem*)nGMA );
				return TRUE;
		}

		return FALSE;
	}
bool CCWidget::Event(CCEvent* pEvent){
	if(m_bVisible==false) return false;

	sRect r = GetRect();
	r.x = r.y = 0;

	if(pEvent->iMessage==CCWM_LBUTTONDOWN)
		int k=0;

	CCEvent LocalEvent;
	MakeLocalEvent(&LocalEvent, pEvent);

	if(m_iDebugType==2){
		if(pEvent->iMessage==CCWM_LBUTTONDOWN )
			int k=0;
	}

	if(r.InPoint(LocalEvent.sPos)==true && (CCWidget::m_pCapturedWidget==NULL || CCWidget::m_pCapturedWidget==this) && IsVisible()==true){
		if(m_pCursor!=NULL) CCCursorSystem::Set(m_pCursor);
		else CCCursorSystem::Set(CCCURSOR_ARROW);	

		if(m_pToolTip!=NULL){
			SetZOrder(CC_TOP);
			m_pToolTip->Show(true);
		}
	}
	else{
		if(m_pToolTip!=NULL){
			m_pToolTip->Show(false);
		}
	}

	if(m_bEnable==false) return false;

	if(GetLatestExclusive()!=NULL){
		if(GetLatestExclusive()->Event(pEvent)==true) return true;
		if(GetLatestExclusive()!=NULL) return false;
	}

	if(pEvent->iMessage==CCWM_LBUTTONDOWN){
		if ( r.InPoint(LocalEvent.sPos)==true){
			SetFocus();
 			if((m_bFocusEnable)&&(m_bZOrderChangable==true)) SetZOrder(CC_TOP);
		}
		else	// ReleaseFocus
		{
//			ReleaseFocus();
//			OnReleaseFocus();
//			ReleaseCapture();
		}
	}

	if(GetLatestExclusive()==NULL){
		for(int i=m_Children.GetCount()-1; i>=0; i--){
			CCWidget* pCurWnd = m_Children.Get(i);
			if(pCurWnd->Event(pEvent)==true) {
				return true;
			}
		}
	}

	if(EventResize(pEvent)==true) return true;

	if(pEvent->iMessage==CCWM_HOTKEY){
		if(OnHotKey(pEvent->uKey)==true) return true;
	}

	if(pEvent->iMessage==CCWM_CHAR || pEvent->iMessage==CCWM_KEYDOWN || pEvent->iMessage==CCWM_IMECOMPOSE ||
		pEvent->iMessage==CCWM_ACTIONKEYDOWN || pEvent->iMessage==CCWM_ACTIONKEYUP || pEvent->iMessage==CCWM_ACTIONPRESSED || pEvent->iMessage==CCWM_ACTIONRELEASED){
		if (IsFocus()) {
			if(OnEvent(&LocalEvent, GetListener())==true) 
				return true;

			// Tab Key
			if(pEvent->iMessage==CCWM_KEYDOWN && pEvent->uKey==VK_TAB){
				if(OnTab(!pEvent->GetShiftState())==true) 
					return true;
			}
		}
	}
	else{
		if((CCWidget::m_pCapturedWidget==NULL || CCWidget::m_pCapturedWidget==this))
			if(OnEvent(&LocalEvent, GetListener())==true) 
				return true;
	}

	if(pEvent->iMessage==CCWM_LBUTTONUP) ReleaseCapture();

	return false;
}