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

📄 guibuttonctrl.cc

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

#include "console/console.h"
#include "dgl/dgl.h"
#include "console/consoleTypes.h"
#include "platform/platformAudio.h"
#include "gui/core/guiCanvas.h"
#include "gui/controls/guiButtonCtrl.h"
#include "gui/core/guiDefaultControlRender.h"

IMPLEMENT_CONOBJECT(GuiButtonCtrl);


GuiButtonCtrl::GuiButtonCtrl()
{
#ifdef TGE_RPG_UI /// TGE_RPG_UI
   //m_pBitmapName = StringTable->insert("");
	mBitmapBounds = 0;
#endif
   mBounds.extent.set(140, 30);
   mButtonText = StringTable->insert("Button");
}



#ifdef TGE_RPG_UI /// TGE_RPG_UI


//-------------------------------------
bool GuiButtonCtrl::onWake()
{
   if (! Parent::onWake())
      return false;
   setActive(true);

	if(!bool(mProfile->mTextureHandle))
		return true;

	bool result = mProfile->constructBitmapArray() >= BtnBmpNum;

	AssertWarn(result, "Failed to create the bitmap array");
	if(result)
	{	
		mTextureHandle = mProfile->mTextureHandle;
		mBitmapBounds = mProfile->mBitmapArrayRects.address();
	}
	else
		mTextureHandle = NULL;


   return true;
}





//-------------------------------------
void GuiButtonCtrl::inspectPostApply()
{
   // if the extent is set to (0,0) in the gui editor and appy hit, this control will
   // set it's extent to be exactly the size of the normal bitmap (if present)
   Parent::inspectPostApply();

   //if ((mBounds.extent.x == 0) && (mBounds.extent.y == 0) && mTextureHandle)
   //{
   //   TextureObject *texture = (TextureObject *) mTextureHandle;
   //   mBounds.extent.x = texture->bitmapWidth;
   //   mBounds.extent.y = texture->bitmapHeight;
   //}
}


#endif


//--------------------------------------------------------------------------

void GuiButtonCtrl::onRender(Point2I      offset,
                             const RectI& updateRect)
{
   bool highlight = mMouseOver;
   bool depressed = mDepressed;

	ColorI fontColor   = mActive ? (highlight ? mProfile->mFontColorHL : mProfile->mFontColor) : mProfile->mFontColorNA;


#ifdef TGE_RPG_UI /// TGE_RPG_UI
	bool result = mProfile->constructBitmapArray() == BtnBmpNum;
	if(result)
	{
		mTextureHandle = mProfile->mTextureHandle;
		mBitmapBounds = mProfile->mBitmapArrayRects.address();

	   U32 topBase = BtnNormal; /*|| mDepressed*/
		if(!mActive)
			topBase = BtnDisabled;
		else if(mStateOn || mDepressed)
			topBase = BtnPress;
		else if(mMouseOver)
			topBase = BtnOver;

		topBase *= BtnIndexMax;

	
      U32	BorderTop		= topBase+BtnTop, 
				BorderTopRight	= topBase+BtnRightTop,
				BorderLeft		= topBase+BtnLeft,
				BorderRight		= topBase+BtnRight,
	         BorderBottomLeft		= topBase+BtnLeftBottom,
		      BorderBottom		= topBase+BtnBottom,
			   BorderBottomRight		= topBase+BtnRightBottom;

	//draw the outline
		RectI winRect;
		winRect.point = offset;
		winRect.extent = mBounds.extent;

			/// TGE_Theme
		bool result = mProfile->constructBitmapArray() >= BtnBmpNum;  
		mTextureHandle = mProfile->mTextureHandle;


		dglClearBitmapModulation();

		//填充中间区域
		winRect.point.x += mBitmapBounds[topBase].extent.x;
		winRect.point.y += mBitmapBounds[topBase].extent.y;

		winRect.extent.x -= mBitmapBounds[topBase].extent.x + mBitmapBounds[BorderRight].extent.x;
		winRect.extent.y -= mBitmapBounds[topBase].extent.y + mBitmapBounds[BorderBottom].extent.y;

		//dglDrawRectFill(winRect, mProfile->mFillColor);
		RectI stretchRect2 = mBitmapBounds[topBase + BtnMiddle];
		stretchRect2.inset(1,1);
		dglDrawBitmapStretchSR(mTextureHandle, winRect, stretchRect2);


		//左上
		dglDrawBitmapSR(mTextureHandle, offset, mBitmapBounds[topBase]);
		//右上
		dglDrawBitmapSR(mTextureHandle, Point2I(offset.x + mBounds.extent.x - mBitmapBounds[BorderTopRight].extent.x, offset.y),
							mBitmapBounds[BorderTopRight]);

		//上边框
		RectI destRect;
		destRect.point.x = offset.x + mBitmapBounds[topBase].extent.x;
		destRect.point.y = offset.y;
		destRect.extent.x = mBounds.extent.x - mBitmapBounds[topBase].extent.x - mBitmapBounds[BorderTopRight].extent.x;
		destRect.extent.y = mBitmapBounds[BorderTop].extent.y;
		RectI stretchRect = mBitmapBounds[BorderTop];
		stretchRect.inset(1,0);
		dglDrawBitmapStretchSR(mTextureHandle, destRect, stretchRect);

		//左边框
		destRect.point.x = offset.x;
		destRect.point.y = offset.y + mBitmapBounds[topBase].extent.y;
		destRect.extent.x = mBitmapBounds[BorderLeft].extent.x;
		destRect.extent.y = mBounds.extent.y - mBitmapBounds[topBase].extent.y - mBitmapBounds[BorderBottomLeft].extent.y;
		stretchRect = mBitmapBounds[BorderLeft];
		stretchRect.inset(0,1);
		dglDrawBitmapStretchSR(mTextureHandle, destRect, stretchRect);

		//右边框
		destRect.point.x = offset.x + mBounds.extent.x - mBitmapBounds[BorderRight].extent.x;
		destRect.extent.x = mBitmapBounds[BorderRight].extent.x;
		destRect.point.y = offset.y + mBitmapBounds[BorderTopRight].extent.y;
		destRect.extent.y = mBounds.extent.y - mBitmapBounds[BorderTopRight].extent.y - mBitmapBounds[BorderBottomRight].extent.y;
		stretchRect = mBitmapBounds[BorderRight];
		stretchRect.inset(0,1);
		dglDrawBitmapStretchSR(mTextureHandle, destRect, stretchRect);

		//左下
		dglDrawBitmapSR(mTextureHandle, offset + Point2I(0, mBounds.extent.y - mBitmapBounds[BorderBottomLeft].extent.y), mBitmapBounds[BorderBottomLeft]);
		//右下
		dglDrawBitmapSR(mTextureHandle, offset + mBounds.extent - mBitmapBounds[BorderBottomRight].extent, mBitmapBounds[BorderBottomRight]);

		//下边框
		destRect.point.x = offset.x + mBitmapBounds[BorderBottomLeft].extent.x;
		destRect.extent.x = mBounds.extent.x - mBitmapBounds[BorderBottomLeft].extent.x - mBitmapBounds[BorderBottomRight].extent.x;

		destRect.point.y = offset.y + mBounds.extent.y - mBitmapBounds[BorderBottom].extent.y;
		destRect.extent.y = mBitmapBounds[BorderBottom].extent.y;
		stretchRect = mBitmapBounds[BorderBottom];
		stretchRect.inset(1,0);

		dglDrawBitmapStretchSR(mTextureHandle, destRect, stretchRect);


	}
	else
	{
		ColorI backColor   = mActive ? mProfile->mFillColor : mProfile->mFillColorNA;
		ColorI borderColor = mActive ? mProfile->mBorderColor : mProfile->mBorderColorNA;

	   RectI boundsRect(offset, mBounds.extent);
#endif
		if( mProfile->mBorder != 0 )
		{
			if (mDepressed || mStateOn)
				renderFilledBorder( boundsRect, mProfile->mBorderColorHL, mProfile->mFillColorHL );
			else
				renderFilledBorder( boundsRect, mProfile->mBorderColor, mProfile->mFillColor );
		}
#ifdef TGE_RPG_UI /// TGE_RPG_UI
	}
#endif

   Point2I textPos = offset;
   if(depressed)
      textPos += Point2I(1,1);

   dglSetBitmapModulation( fontColor );
   renderJustifiedText(textPos, mBounds.extent, mButtonText);

   //render the children
   renderChildControls( offset, updateRect);
}





⌨️ 快捷键说明

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