Esempio n. 1
0
// 设置选择的tab页
int CDuiTabCtrl::SetSelectItem(int nItem)
{
	int nOldDownItem = m_nDownItem;
	if(m_nDownItem != nItem && nItem >= 0 && nItem < (int)m_vecItemInfo.size())
	{
		TabItemInfo &itemInfo = m_vecItemInfo.at(nItem);
		if(itemInfo.bOutLink)	// 外部链接
		{
			m_nHoverItem = -1;
			SendMessage(MSG_BUTTON_DOWN, nItem, 0);
		}else
		{
			m_nOldItem = m_nDownItem;	// 保存切换前的页面索引,用于切换动画
			m_nDownItem = nItem;					
			m_nHoverItem = -1;

			SendMessage(MSG_BUTTON_DOWN, m_nDownItem, 0);

			// 只显示当前活动的tab页对应的Panel对象,其他页面的Panel对象都隐藏
			for(size_t i = 0; i < m_vecItemInfo.size(); i++)
			{
				TabItemInfo &itemInfo = m_vecItemInfo.at(i);
				if(itemInfo.pControl != NULL)
				{
					if(i == m_nDownItem)
					{
						itemInfo.pControl->SetVisible(TRUE);
						SetWindowFocus();
					}else
					{
						itemInfo.pControl->SetVisible(FALSE);
					}
				}
				// 如果启用了动画,则启动切换动画定时器
				if(m_bAnimateChangeTab)
				{
					m_nCurXPos = 0;
					m_bRunTime = true;
				}
			}
		}

		UpdateControl();
	}

	return nOldDownItem;
}
Esempio n. 2
0
// 鼠标右键按下事件处理
BOOL CDuiGridCtrl::OnControlRButtonDown(UINT nFlags, CPoint point)
{
	if(m_vecRowInfo.size() == 0)
	{
		return false;
	}

	// 设置窗口焦点,否则可能无法进行滚动事件的处理
	SetWindowFocus();

	if((m_nHoverRow >= 0) && (m_nHoverRow < (int)m_vecRowInfo.size()))
	{
		GridRowInfo &rowInfo = m_vecRowInfo.at(m_nHoverRow);
		if(PtInRow(point, rowInfo) && !PtInRowCheck(point, rowInfo))	// 检查框事件只在鼠标放开时候触发
		{
			rowInfo.nHoverItem = PtInRowItem(point, rowInfo);
			if(m_nDownRow != m_nHoverRow)
			{
				if(m_bEnableDownRow)
				{
					m_nDownRow = m_nHoverRow;
					m_nHoverRow = -1;
				}

				SendMessage(MSG_MOUSE_RDOWN, m_bEnableDownRow ? m_nDownRow : m_nHoverRow, rowInfo.nHoverItem);

				UpdateControl(TRUE);

				return true;
			}
		}	
	} else
	if((m_nDownRow >= 0) && (m_nDownRow < (int)m_vecRowInfo.size()))
	{
		// 如果点击的还是之前点击的行,也同样会发送鼠标点击事件
		GridRowInfo &rowInfo = m_vecRowInfo.at(m_nDownRow);
		if(PtInRow(point, rowInfo)&& !PtInRowCheck(point, rowInfo))	// 检查框事件只在鼠标放开时候触发
		{
			rowInfo.nHoverItem = PtInRowItem(point, rowInfo);
			SendMessage(MSG_MOUSE_RDOWN, m_nDownRow, rowInfo.nHoverItem);
			return true;
		}
	}
	
	return false;
}
Esempio n. 3
0
BOOL CDuiTabCtrl::OnControlLButtonDown(UINT nFlags, CPoint point)
{
	if(m_nHoverItem != -1)
	{
		TabItemInfo &itemInfo = m_vecItemInfo.at(m_nHoverItem);
		if(itemInfo.rc.PtInRect(point))
		{
			if(m_nDownItem != m_nHoverItem)
			{
				int nDownItem = m_nHoverItem;
				if(!itemInfo.strAction.IsEmpty())
				{
					// 如果action非空,则执行动作
					DuiSystem::AddDuiActionTask(GetID(), MSG_BUTTON_UP, nDownItem, 0, GetName(), itemInfo.strAction, GetParent());
				}

				if(itemInfo.bOutLink)	// 外部链接
				{
					m_nHoverItem = -1;
					SendMessage(MSG_BUTTON_DOWN, nDownItem, 0);
				}else
				{
					m_nOldItem = m_nDownItem;	// 保存切换前的页面索引,用于切换动画
					m_nDownItem = m_nHoverItem;					
					m_nHoverItem = -1;

					// 删除旧的Tooltip
					CDlgBase* pDlg = GetParentDialog();
					if(pDlg)
					{
						pDlg->ClearTooltip();
					}

					// 点击事件消息
					SendMessage(MSG_BUTTON_DOWN, m_nDownItem, 0);

					// 只显示当前活动的tab页对应的Panel对象,其他页面的Panel对象都隐藏
					for(size_t i = 0; i < m_vecItemInfo.size(); i++)
					{
						TabItemInfo &itemInfo = m_vecItemInfo.at(i);
						if(itemInfo.pControl != NULL)
						{
							if(i == m_nDownItem)
							{
								itemInfo.pControl->SetVisible(TRUE);
								SetWindowFocus();
							}else
							{
								itemInfo.pControl->SetVisible(FALSE);
							}
						}
						// 如果启用了动画,则启动切换动画定时器
						if(m_bAnimateChangeTab)
						{
							m_nCurXPos = 0;
							m_bRunTime = true;
						}
					}
				}

				UpdateControl();

				return true;
			}
		}		
	}	
	
	return false;
}
Esempio n. 4
0
// 刷新所有Tab页
void CDuiTabCtrl::RefreshItems()
{
	// 重新计算每个tab页的位置,并刷新界面
	int nXPos = m_rc.left;
	int nYPos = m_rc.top;

	for(size_t i = 0; i < m_vecItemInfo.size(); i++)
	{
		TabItemInfo &itemInfoTemp = m_vecItemInfo.at(i);
		if(!itemInfoTemp.bVisible)
		{
			// 隐藏的tab页坐标设置为0
			itemInfoTemp.rc.SetRect(0,0,0,0);
			if(i < m_vecRcSeperator.size())
			{
				CRect &rc = m_vecRcSeperator.at(i);
				rc.SetRect(0,0,0,0);
			}			
			continue;
		}

		int nItemWidth = itemInfoTemp.rc.Width();
		int nItemHeight = itemInfoTemp.sizeImage.cy;

		if(m_nTabItemWidth == 0)
		{
			// 如果tabctrl没有设置每个tab页的宽度,则以第一个tab页的图片宽度为准
			m_nTabItemWidth = nItemWidth;
		}
		if(m_nTabCtrlHeight == 0)
		{
			// 如果tabctrl没有设置高度,则以第一个tab页的图片高度为准
			m_nTabCtrlHeight = nItemHeight;
		}

		itemInfoTemp.rc.SetRect(nXPos, nYPos, nXPos + m_nTabItemWidth, nYPos + m_nTabCtrlHeight);

		nXPos += m_nTabItemWidth;

		if(i < m_vecItemInfo.size() - 1 && m_pImageSeperator != NULL)
		{
			CRect &rc = m_vecRcSeperator.at(i);
			rc.SetRect(nXPos, nYPos, nXPos + m_sizeSeperator.cx, nYPos + m_sizeSeperator.cy);
			nXPos += m_sizeSeperator.cx;
		}
	}

	// 如果删除了最后一个页面,需要重新计算当前页面的索引
	if(m_nDownItem >= (int)m_vecItemInfo.size())
	{
		m_nDownItem = -1;
		if(m_vecItemInfo.size() > 0)
		{
			for(size_t i = (int)m_vecItemInfo.size()-1; i >= 0; i--)
			{
				TabItemInfo &itemInfoTemp = m_vecItemInfo.at(i);
				if(itemInfoTemp.bVisible && !itemInfoTemp.bOutLink)
				{
					m_nDownItem = i;
					break;
				}
			}
		}
	}
	if(m_nHoverItem >= (int)m_vecItemInfo.size())
	{
		m_nHoverItem = -1;
	}

	// 刷新显示当前页
	for(size_t i = 0; i < m_vecItemInfo.size(); i++)
	{
		TabItemInfo &itemInfo = m_vecItemInfo.at(i);
		if(itemInfo.pControl != NULL)
		{
			if(i == m_nDownItem)
			{
				itemInfo.pControl->SetVisible(TRUE);
				SetWindowFocus();
			}else
			{
				itemInfo.pControl->SetVisible(FALSE);
			}
		}
	}

	UpdateControl(true);
}
Esempio n. 5
0
// 刷新所有Tab页
void CDuiTabCtrl::RefreshItems()
{
	// 重新计算每个tab页的位置,并刷新界面
	int nXPos = m_rc.left + m_nTabLeftPading;
	int nYPos = m_rc.top;

	for(size_t i = 0; i < m_vecItemInfo.size(); i++)
	{
		TabItemInfo &itemInfoTemp = m_vecItemInfo.at(i);
		if(!itemInfoTemp.bVisible)
		{
			// 隐藏的tab页坐标设置为0
			itemInfoTemp.rc.SetRect(0,0,0,0);
			if(i < m_vecRcSeperator.size())
			{
				CRect &rc = m_vecRcSeperator.at(i);
				rc.SetRect(0,0,0,0);
			}			
			continue;
		}

		int nItemWidth = itemInfoTemp.rc.Width();
		int nItemHeight = itemInfoTemp.sizeImage.cy;

		if(m_nTabItemWidth == 0)
		{
			// 如果tabctrl没有设置每个tab页的宽度,则以第一个tab页的图片宽度为准
			m_nTabItemWidth = nItemWidth;
		}
		if(m_nTabCtrlHeight == 0)
		{
			// 如果tabctrl没有设置高度,则以第一个tab页的图片高度为准
			m_nTabCtrlHeight = nItemHeight;
		}

		itemInfoTemp.rc.SetRect(nXPos, nYPos, nXPos + m_nTabItemWidth, nYPos + m_nTabCtrlHeight);

		nXPos += m_nTabItemWidth;

		if(i < m_vecItemInfo.size() - 1 && m_pImageSeperator != NULL)
		{
			CRect &rc = m_vecRcSeperator.at(i);
			rc.SetRect(nXPos, nYPos, nXPos + m_sizeSeperator.cx, nYPos + m_sizeSeperator.cy);
			nXPos += m_sizeSeperator.cx;
		}

		// 设置Tab页签按钮的位置
		if(m_pImageTabBtn != NULL)
		{
			int nLeft = m_nTabLeftPading + (m_nTabItemWidth * i);
			int nTop = 3;

			// 计算Tab页签按钮的显示位置
			if(m_posTabBtn.nCount >= 2)
			{
				// 使用设置的Tab页签按钮位置
				int nTabBtnX = PositionItem2Value(m_posTabBtn.Left, 0, m_nTabItemWidth);
				int nTabBtnY = PositionItem2Value(m_posTabBtn.Top, 0, m_nTabCtrlHeight);
				nLeft += nTabBtnX;
				nTop += nTabBtnY;
			}else
			{
				// 如果没有设置位置信息,则设置默认的位置为靠tab页签右上角
				nLeft += (m_nTabItemWidth - m_sizeTabBtn.cx - 3);
				nTop += 3;
			}

			itemInfoTemp.rcButton.SetRect(nLeft, nTop, nLeft + m_sizeTabBtn.cx, nTop + m_sizeTabBtn.cy);
		}
	}

	// 如果删除了最后一个页面,需要重新计算当前页面的索引
	if(m_nDownItem >= (int)m_vecItemInfo.size())
	{
		m_nDownItem = -1;
		if(m_vecItemInfo.size() > 0)
		{
			for(size_t i = (int)m_vecItemInfo.size()-1; i >= 0; i--)
			{
				TabItemInfo &itemInfoTemp = m_vecItemInfo.at(i);
				if(itemInfoTemp.bVisible && !itemInfoTemp.bOutLink)
				{
					m_nDownItem = i;
					break;
				}
			}
		}
	}
	if(m_nHoverItem >= (int)m_vecItemInfo.size())
	{
		m_nHoverItem = -1;
	}

	// 刷新显示当前页
	for(size_t i = 0; i < m_vecItemInfo.size(); i++)
	{
		TabItemInfo &itemInfo = m_vecItemInfo.at(i);
		if(itemInfo.pControl != NULL)
		{
			if(i == m_nDownItem)
			{
				itemInfo.pControl->SetVisible(TRUE);
				SetWindowFocus();
			}else
			{
				itemInfo.pControl->SetVisible(FALSE);
			}
		}
	}

	UpdateControl(true);
}
Esempio n. 6
0
void EngineApp::ResetMousePosition( void ) 
   {
   SetWindowFocus();
   SDL_WarpMouseInWindow( g_pApp->GetWindow(), g_pApp->GetScreenSize().GetX() / 2, g_pApp->GetScreenSize().GetY() / 2 );
   }
Esempio n. 7
0
void EngineApp::MsgProc( void )
   {
   SDL_Event event;
   HumanView*  pHumanView;
   if( SDL_PollEvent( &event ) )
      {
      if( event.type == m_ShutDownEventType )
         {
         pHumanView = GetHumanView();
         if( pHumanView && pHumanView->HasModalWindow() )
            {
            // force the dialog to exit
            ENG_ASSERT( PushUserEvent( pHumanView->GetModalEventType(), g_QuitNoPrompt ) >= 0 );
            // force next dialog( if it exists ) to exit
            ENG_ASSERT( PushUserEvent( m_ShutDownEventType, 0 ) >= 0 );
            }
         else // this is triggered by last dialog event
            {
            OnClose();
            }
         return;
         }
      switch( event.type )
         {
         case SDL_WINDOWEVENT:
            break;
         case SDL_QUIT: // this case is triggered by hitting 'x' at the window
            if( m_bQuitRequested )
               {
               return;
               }

            m_bQuitRequested = true;
            pHumanView = GetHumanView();
            // remenber to process additional messagebox
            if ( pHumanView )
				   {
               if( pHumanView->Ask( QUESTION_QUIT_GAME ) == IDNO )
                  {
                  // We've cleared the dialog, Reset quit requested flag
					   m_bQuitRequested = false;
					   return; 
                  }
               else
                  {
                  PushUserEvent( m_ShutDownEventType, 0 );
                  }
			      }
            m_bQuitting = true;
            break;
         case SDL_DROPFILE:
            SetWindowFocus();
            m_pEngineLogic->VOnFileDrop( event.drop.file, GetMousePosition() );
            SDL_free( event.drop.file );    // Free dropped_filedir memory
            break;
         case SDL_MOUSEBUTTONDOWN:
         case SDL_KEYDOWN:
         case SDL_KEYUP:
         case SDL_TEXTEDITING:
         case SDL_TEXTINPUT:
         case SDL_KEYMAPCHANGED:
         case SDL_MOUSEMOTION:
         case SDL_MOUSEBUTTONUP:
         case SDL_MOUSEWHEEL:
         case SDL_JOYAXISMOTION:
         case SDL_JOYBALLMOTION:
         case SDL_JOYHATMOTION:
         case SDL_JOYBUTTONDOWN:
         case SDL_JOYBUTTONUP:
         case SDL_JOYDEVICEADDED:
         case SDL_JOYDEVICEREMOVED:
         case SDL_CONTROLLERAXISMOTION:
         case SDL_CONTROLLERBUTTONDOWN:
         case SDL_CONTROLLERBUTTONUP:
         case SDL_CONTROLLERDEVICEADDED:
         case SDL_CONTROLLERDEVICEREMOVED:
         case SDL_CONTROLLERDEVICEREMAPPED:
         m_pEngineLogic->VOnMsgProc( event );
         }
      
      }// If poll event exist
   }// Function MsgProc