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

📄 guiwindowctrl.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/guiWindowCtrl.h"
#include "gui/core/guiDefaultControlRender.h"

IMPLEMENT_CONOBJECT(GuiWindowCtrl);

GuiWindowCtrl::GuiWindowCtrl(void)
{
	mBitmapBounds = NULL;

   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;
   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 GuiWindowCtrl::initPersistFields()
{
   Parent::initPersistFields();

   addField("resizeWidth",       TypeBool,         Offset(mResizeWidth, GuiWindowCtrl));
   addField("resizeHeight",      TypeBool,         Offset(mResizeHeight, GuiWindowCtrl));
   addField("canMove",           TypeBool,         Offset(mCanMove, GuiWindowCtrl));
   addField("canClose",          TypeBool,         Offset(mCanClose, GuiWindowCtrl));
   addField("canMinimize",       TypeBool,         Offset(mCanMinimize, GuiWindowCtrl));
   addField("canMaximize",       TypeBool,         Offset(mCanMaximize, GuiWindowCtrl));
   addField("minSize",           TypePoint2I,      Offset(mMinSize, GuiWindowCtrl));
   addField("closeCommand",      TypeString,       Offset(mCloseCommand, GuiWindowCtrl));
}

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

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

   // until a pref, if alignment is LEFT, put buttons RIGHT justified.
   // ELSE, put buttons LEFT justified.
#ifdef TGE_RPG_UI /// TGE_RPG_UI
   S32 tileBarHeight = mBitmapBounds[BorderTopKey].extent.y;
   int closeLeft		= mainOff.x;
	int closeTop		= mainOff.y - ((buttonHeight - mProfile->mFont->getHeight()) >> 1);//(tileBarHeight - buttonHeight) >> 1;
	int closeOff		= buttonWidth + 2;

   if ( mProfile->mAlignment != GuiControlProfile::RightJustify )
   {
      closeOff = -closeOff;
      closeLeft = mBounds.extent.x - (buttonWidth + mainOff.x /*+ mBitmapBounds[BorderRight].extent.x*/);
   }
#else
   int closeLeft = mainOff.x, closeTop = mainOff.y, closeOff = buttonWidth + 2;
   if ( mProfile->mAlignment == GuiControlProfile::LeftJustify )
   {
      closeOff = -closeOff;
      closeLeft = mBounds.extent.x - buttonWidth - mainOff.x;
   }
#endif

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

   // Always put Minimize on left side of Maximize.
   closeRect.point.x += closeOff;
   if (closeOff>0)
   {
      mMinimizeButton = closeRect;
      closeRect.point.x += closeOff;
      mMaximizeButton = closeRect;
   }
   else
   {
      mMaximizeButton = closeRect;
      closeRect.point.x += closeOff;
      mMinimizeButton = closeRect;
   }
}

bool GuiWindowCtrl::onWake()
{
   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;
#ifdef TGE_RPG_UI
   bool result = mProfile->constructBitmapArray() >= BmpFill;
#else
   bool result = mProfile->constructBitmapArray() >= NumBitmaps;
#endif

	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;


#ifdef TGE_RPG_UI

	if(mCloseCommand == 0 || mCloseCommand[0] == 0)
	{
		mCloseCommand = StringTable->insert("$ThisControl.visible=0;");//avar("%d.visible=0;",getId()));
	}

	//if( !GuiControl::smDesignTime )
	if(m_bAutoSize)
		autoSizeToContent();


   mTitleHeight			= mBitmapBounds[BorderTopKey].extent.y;
#else
   mTitleHeight			= buttonHeight + 4;
#endif
   mResizeRightWidth		= mTitleHeight / 2;
   mResizeBottomHeight	= mTitleHeight / 2;

   //set the button coords
   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++)
      {
         GuiWindowCtrl *ctrl = dynamic_cast<GuiWindowCtrl *>(*i);
         if (ctrl)
         {
            if (ctrl == this) break;
            else if (ctrl->mFirstResponder) mTabIndex++;
         }
      }
   }

   return true;
}

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

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

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

   //set the button coords
   PositionButtons();
}
//
//#ifdef TGE_RPG_UI /// TGE_RPG_UI
//void GuiWindowCtrl::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 GuiWindowCtrl::onMouseDown(const GuiEvent &event)
{
   setUpdate();

   mOrigBounds = mBounds;

   mMouseDownPosition = event.mousePoint;
   Point2I localPoint = globalToLocalCoord(event.mousePoint);

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

   //if we clicked within the title bar
   if (localPoint.y < mTitleHeight)
   {
      //if we clicked on the close button
      if (mCanClose && mCloseButton.pointInRect(localPoint))
      {
         mPressClose = mCanClose;
      }
      else if (mCanMaximize && mMaximizeButton.pointInRect(localPoint))
      {
         mPressMaximize = mCanMaximize;
      }
      else if (mCanMinimize && mMinimizeButton.pointInRect(localPoint))
      {
         mPressMinimize = mCanMinimize;
      }

      //else we clicked within the title
      else
      {
         mMouseMovingWin = mCanMove;
         mMouseResizeWidth = false;
         mMouseResizeHeight = false;
      }
   }
   else
   {
      mMouseMovingWin = false;

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

      //see if we clicked on the bottom edge (as well)
      if (mResizeHeight && (localPoint.y > mBounds.extent.y - mResizeBottomHeight))
      {
         mMouseResizeHeight = true;
      }
   }


   if (mMouseMovingWin || mMouseResizeWidth || mMouseResizeHeight ||
         mPressClose || mPressMaximize || mPressMinimize)
   {
      mouseLock();
   }
   else
   {

      GuiControl *ctrl = findHitControl(localPoint);
      if (ctrl && ctrl != this)
         ctrl->onMouseDown(event);

   }
}

⌨️ 快捷键说明

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