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

📄 guitoolwindowctrl.cc

📁 五行MMORPG引擎系统V1.0
💻 CC
📖 第 1 页 / 共 3 页
字号:
//-----------------------------------------------------------------------------
// Torque Game Engine
// Copyright (C) GarageGames.com, Inc.
//-----------------------------------------------------------------------------

#include "console/consoleTypes.h"
#include "console/console.h"
#include "dgl/dgl.h"
#include "gui/core/guiCanvas.h"
#include "gui/containers/guiToolWindowCtrl.h"
#include "gui/core/guiDefaultControlRender.h"

GuiToolWindowCtrl* GuiToolWindowCtrl::ms_pAutoExpandTool = NULL;



IMPLEMENT_CONOBJECT(GuiToolWindowCtrl);

GuiToolWindowCtrl::GuiToolWindowCtrl(void)
{
	mBitmapBounds = NULL;
	m_bEditorMode	= false;
	m_bCanVerticalBar	= true;
	m_bMouseEnter	= false;
	m_nExpandExpire= 0;
	m_nExpandTimer	= 0;
	m_bVerticalBar	= false;
	//m_bMiniMode		= false;
	m_bAlwaysShow	= true;
   mResizeWidth	= true;
   mResizeHeight	= true;
   mCanMove			= true;
   mCanClose		= true;
   mCanMinimize	= true;
   //mCanMaximize = true;
   mTitleHeight	= 20;
   mResizeRightWidth = 10;
   mResizeBottomHeight = 10;

   mCloseCommand = StringTable->insert("");

   mMinimized = false;
   //mMaximized = false;
   mMouseMovingWin = false;
   mMouseResizeWidth = false;
   mMouseResizeHeight = false;
   mBounds.extent.set(100, 200);
   mMinSize.set(50, 50);
   mMinimizeIndex = -1;
   mTabIndex = -1;

   RectI closeRect(80, 2, 16, 16);
   mCloseButton = closeRect;
   closeRect.point.x -= 18;
   //mMaximizeButton = closeRect;
   closeRect.point.x -= 18;
   //mMinimizeButton = closeRect;

   //other defaults
   mActive = true;
   mPressClose = false;
	m_boundOrigin.set(0,0);
   //mPressMaximize = false;
   //mPressMinimize = false;

//#ifdef TGE_RPG_UI /// TGE_RPG_UI
//		m_bOverClose		= false;
//		m_bOverMinimize		= false;
//		m_bOverMaximize		= false;
//#endif

   //mDefaultCursor    = NULL;
   //mNWSECursor       = NULL;
   //mNESWCursor       = NULL;
   //mUpDownCursor     = NULL;
   //mLeftRightCursor  = NULL;

}

void GuiToolWindowCtrl::initPersistFields()
{
   Parent::initPersistFields();

   addField("expandExpire",		TypeS32,         Offset(m_nExpandExpire, GuiToolWindowCtrl));
   addField("resizeWidth",       TypeBool,         Offset(mResizeWidth, GuiToolWindowCtrl));
   addField("resizeHeight",      TypeBool,         Offset(mResizeHeight, GuiToolWindowCtrl));
   addField("canVertical",       TypeBool,         Offset(m_bCanVerticalBar, GuiToolWindowCtrl));
   addField("editorMode",        TypeBool,         Offset(m_bEditorMode, GuiToolWindowCtrl));
   addField("canMove",           TypeBool,         Offset(mCanMove, GuiToolWindowCtrl));
   addField("canClose",          TypeBool,         Offset(mCanClose, GuiToolWindowCtrl));
   addField("canMinimize",       TypeBool,         Offset(mCanMinimize, GuiToolWindowCtrl));
   addField("vertDraw",  		   TypeBool,         Offset(m_bVerticalBar, GuiToolWindowCtrl));
   addField("alwaysShow", 		   TypeBool,         Offset(m_bAlwaysShow, GuiToolWindowCtrl));
   //addField("canMaximize",       TypeBool,         Offset(mCanMaximize, GuiToolWindowCtrl));
   addField("minSize",           TypePoint2I,      Offset(mMinSize, GuiToolWindowCtrl));
   addField("closeCommand",      TypeString,       Offset(mCloseCommand, GuiToolWindowCtrl));
}

bool GuiToolWindowCtrl::isMinimized(S32 &index)
{
   index = mMinimizeIndex;
   return mMinimized && mVisible;
}

// helper fn so button positioning shares code...
void GuiToolWindowCtrl::PositionButtons(void)
{
   S32 buttonWidth = mBitmapBounds[BmpStates * BmpClose].extent.x;
   S32 buttonHeight = mBitmapBounds[BmpStates * BmpClose].extent.y;
   Point2I mainOff = mProfile->mTextOffset;


	
	S32 tileBarHeight;
   int closeLeft;
	int closeTop;
	int closeOff;

	if(!m_bVerticalBar)
	{
		tileBarHeight = mBitmapBounds[BorderTopKey].extent.y;
		closeLeft		= mainOff.x;
		closeTop		= mainOff.y - ((buttonHeight - mProfile->mFont->getHeight()) >> 1);
		closeOff		= buttonWidth ;

		if ( mProfile->mAlignment != GuiControlProfile::RightJustify )
		{
			closeOff = -closeOff;
			closeLeft = mBounds.extent.x - (buttonWidth + /*mainOff.x*/ mBitmapBounds[BorderTopRightKey].extent.x );
		}


		RectI closeRect(closeLeft, closeTop, buttonHeight, buttonWidth);
		mCloseButton = closeRect;

		// Always put Minimize on left side of Maximize.
		//closeRect.point.x += closeOff;
		//mMinimizeButton	= closeRect;
	}
	else
	{
		tileBarHeight	= mBitmapBounds[VBorderLeftKey].extent.y;
		closeLeft		= mainOff.x - ((buttonWidth - mProfile->mFont->getHeight()) >> 1);
		closeTop			= mainOff.y;
		closeOff			= buttonHeight;

		if ( mProfile->mAlignment == GuiControlProfile::RightJustify )
		{
			closeOff = -closeOff;
			closeTop = mBounds.extent.y - (buttonHeight + mBitmapBounds[VBorderTopLeftKey].extent.y/*mainOff.y*/ );
		}


		RectI closeRect(closeLeft, closeTop, buttonHeight, buttonWidth);
		mCloseButton = closeRect;

		// Always put Minimize on left side of Maximize.
		//closeRect.point.y += closeOff;
		//mMinimizeButton = closeRect;
	}

}


bool GuiToolWindowCtrl::onWake()
{
	if(m_boundOrigin.isZero())
		m_boundOrigin = mBounds.extent;
   if (! Parent::onWake())
      return false;

   //get the texture for the close, minimize, and maximize buttons
	/// TGE_Theme bug fix
   //mTextureHandle = mProfile->mTextureHandle;
   //bool result = mProfile->constructBitmapArray() >= NumBitmaps;
   bool result = mProfile->constructBitmapArray() >= NumBitmaps;

	if(!bool(mTextureHandle))
		mTextureHandle = mProfile->mTextureHandle;

   AssertFatal(result, "Failed to create the bitmap array");
   if(!result)
      return false;

   mBitmapBounds = mProfile->mBitmapArrayRects.address();
   S32 buttonWidth = mBitmapBounds[BmpStates * BmpClose].extent.x;
   S32 buttonHeight = mBitmapBounds[BmpStates * BmpClose].extent.y;


	if(!m_bVerticalBar)
		mTitleHeight			= mBitmapBounds[BorderTopKey].extent.y;
	else
		mTitleHeight			= mBitmapBounds[VBorderLeftKey].extent.x;

   mResizeRightWidth		= mTitleHeight / 2;
   mResizeBottomHeight	= mTitleHeight / 2;

   //set the button coords
   //PositionButtons(); GuiEditCtrl
	//if(m_bEditorMode || (!m_bEditorMode && !GuiControl::smDesignTime) )
	if(m_bAutoSize)
		autoSizeToContent();
	else
		PositionButtons();


   //set the tab index
   mTabIndex = -1;
   GuiControl *parent = getParent();
   if (parent && mFirstResponder)
   {
      mTabIndex = 0;

      //count the number of windows preceeding this one
      iterator i;
      for (i = parent->begin(); i != parent->end(); i++)
      {
         GuiToolWindowCtrl *ctrl = dynamic_cast<GuiToolWindowCtrl *>(*i);
         if (ctrl)
         {
            if (ctrl == this) break;
            else if (ctrl->mFirstResponder) mTabIndex++;
         }
      }
   }



	m_boundBak = mBounds.extent;
	if(m_boundBak.x < mTitleHeight*2)
		m_boundBak.x = m_boundOrigin.x;
	if(m_boundBak.y < mTitleHeight*2)
		m_boundBak.y = m_boundOrigin.y;

	if(mCloseCommand == 0 || mCloseCommand[0] == 0)
	{
		mCloseCommand = StringTable->insert("$ThisControl.visible=0;");
	}
	
	mMinExtent.x	= mTitleHeight;
	mMinExtent.y	= mTitleHeight;

	if(mCanMinimize && !m_bAlwaysShow)
	{	
		ToggleMiniMode(true);
	}



   return true;
}

void GuiToolWindowCtrl::onSleep()
{
   //mTextureHandle = NULL;
   Parent::onSleep();
}

GuiControl* GuiToolWindowCtrl::findHitControl(const Point2I &pt, S32 initialLayer)
{
   if (! mMinimized)
      return Parent::findHitControl(pt, initialLayer);
   else
      return this;
}

void GuiToolWindowCtrl::resize(const Point2I &newPosition, const Point2I &newExtent)
{
   Parent::resize(newPosition, newExtent);

   //set the button coords
   PositionButtons();

}

//
//#ifdef TGE_RPG_UI /// TGE_RPG_UI
//void GuiToolWindowCtrl::onMouseMove(const GuiEvent &event)
//{
//   //setUpdate();
//
//
//   Point2I localPoint = globalToLocalCoord(event.mousePoint);
//
//
//	m_bOverClose		= false;
//	m_bOverMinimize		= false;
//	m_bOverMaximize		= false;
//
//   //if we clicked within the title bar
//   if (localPoint.y < mTitleHeight)
//   {
//      //if we clicked on the close button
//      if (mCanClose) && mCloseButton.pointInRect(localPoint))
//      {
//         m_bOverClose = true;
//      }
//      else if (mCanMaximize && mMaximizeButton.pointInRect(localPoint))
//      {
//			m_bOverMaximize		= true;
//      }
//      else if (mCanMinimize && mMinimizeButton.pointInRect(localPoint))
//      {
// 			m_bOverMinimize		= true;
//      }
//
//   }
//}
//#endif


void GuiToolWindowCtrl::onMouseEnter(const GuiEvent &event)
{
	m_bMouseEnter = true;
	//if(mMinimized && m_nExpandExpire)
	//{
	//	ToggleMiniMode(false);
	//	m_nExpandTimer = -1;
	//}

}

void GuiToolWindowCtrl::onMouseLeave(const GuiEvent &event)
{
	m_bMouseEnter = false;
	//if(m_nExpandTimer == -1)
	//	m_nExpandTimer = Platform::getRealMilliseconds();
	//else
	//	m_nExpandTimer = 0;
}


void GuiToolWindowCtrl::onMouseDown(const GuiEvent &event)
{

	if(!mMinimized && ms_pAutoExpandTool == NULL)
		ms_pAutoExpandTool = this;

   setUpdate();

	if(event.mouseClickCount == 2)
	{
		setAlwaysShow();
		return;
		//ToggleMiniMode(mMinimized);
	}


   mOrigBounds				= mBounds;
   mMouseDownPosition	= event.mousePoint;
   Point2I	localPoint	= globalToLocalCoord(event.mousePoint);
	//bool		bTitleBar	= false;

   //select this window - move it to the front, and set the first responder
   selectWindow();



	//if(!	m_bVerticalBar && localPoint.y < mTitleHeight || 
	//		m_bVerticalBar && localPoint.x < mTitleHeight)
	//		bTitleBar = true;
	
   //if we clicked within the title bar
   //if (bTitleBar)
   {
      //if we clicked on the close button
      if (mCanClose && mCloseButton.pointInRect(localPoint))
      {
         mPressClose = mCanClose;
      }
      //else if (mCanMinimize && mMinimizeButton.pointInRect(localPoint))
      //{
      //   mPressMinimize = mCanMinimize;
      //}
		else
      {
         mMouseMovingWin		= mCanMove;
         mMouseResizeWidth		= false;
         mMouseResizeHeight	= false;
      }

      //see if we clicked on the right edge
      if (mResizeWidth && (localPoint.x > mBounds.extent.x - mResizeRightWidth))
      {
         mMouseResizeWidth = true;
			mMouseMovingWin = false;
      }

⌨️ 快捷键说明

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