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

📄 guiwindowctrl.cc

📁 五行MMORPG引擎系统V1.0
💻 CC
📖 第 1 页 / 共 3 页
字号:

	S32 nNum		= mProfile->constructBitmapArray();  

   RectI destRect(0,0,0,0);
	RectI stretchRect(0,0,0,0);


	//////////////////////////////////
	//填充背景

   winRect.point.x += mBitmapBounds[BorderLeft].extent.x;
   winRect.point.y += mBitmapBounds[topBase + 2].extent.y;

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

	//设有填充背景,则Tile背景图案
	if(nNum >= NumBitmaps)
	{
		dglClearBitmapModulation();

		stretchRect = mBitmapBounds[BmpFill];
		stretchRect.inset(1,1);
		//dglDrawBitmapTile(mTextureHandle, destRect, stretchRect);
		dglDrawBitmapTile(mTextureHandle, winRect, stretchRect);
	}
	else
	{
		dglDrawRectFill(winRect, mProfile->mFillColor);
		dglClearBitmapModulation();
	}


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

	////////////////////
	//上边框 Tile
   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[topBase + 1].extent.x;
   destRect.extent.y = mBitmapBounds[topBase + 2].extent.y;
   stretchRect = mBitmapBounds[topBase + 2];
   stretchRect.inset(1,0);
   dglDrawBitmapTile(mTextureHandle, destRect, stretchRect);

	/////////////////////
	//左边框 Tile
   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);
   dglDrawBitmapTile(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[topBase + 1].extent.y;
   destRect.extent.y = mBounds.extent.y - mBitmapBounds[topBase + 1].extent.y - mBitmapBounds[BorderBottomRight].extent.y;

   stretchRect = mBitmapBounds[BorderRight];
   stretchRect.inset(0,1);
   dglDrawBitmapTile(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]);

	////////////////////////////////
	//底边框 Tile
   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);

   dglDrawBitmapTile(mTextureHandle, destRect, stretchRect);


#else

	//填充背景色
   winRect.point.x += mBitmapBounds[BorderLeft].extent.x;
   winRect.point.y += mBitmapBounds[topBase + 2].extent.y;

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

   dglDrawRectFill(winRect, mProfile->mFillColor);

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

	//上边框
   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[topBase + 1].extent.x;
   destRect.extent.y = mBitmapBounds[topBase + 2].extent.y;
   RectI stretchRect = mBitmapBounds[topBase + 2];
   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[topBase + 1].extent.y;
   destRect.extent.y = mBounds.extent.y - mBitmapBounds[topBase + 1].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);

#endif

   //draw the title
   // dhc addition: copied/modded from renderJustifiedText, since we enforce a
   // different color usage here. NOTE: it currently CAN overdraw the controls
   // if mis-positioned or 'scrunched' in a small width.
   dglSetBitmapModulation(mProfile->mFontColor);
   S32 fontHeight = mFont->getHeight();
   S32 textWidth = mProfile->mFont->getStrWidth((const UTF8 *)mText);
   Point2I start(0,0);
   // align the horizontal
   if ( mProfile->mAlignment == GuiControlProfile::RightJustify )
      start.set( winRect.extent.x - textWidth, 0 );
   else if ( mProfile->mAlignment == GuiControlProfile::CenterJustify )
      start.set( ( winRect.extent.x - textWidth) / 2, 0 );
   else // GuiControlProfile::LeftJustify or garbage... ;)
      start.set( 0, 0 );
   // If the text is longer then the box size, (it'll get clipped) so force Left Justify
   if( textWidth > winRect.extent.x ) start.set( 0, 0 );
   // center the vertical
//   start.y = ( winRect.extent.y - ( font->getHeight() - 2 ) ) / 2;
   dglDrawText(mFont, start + offset + mProfile->mTextOffset, mText);

   // deal with rendering the titlebar controls
   AssertFatal(root, "Unable to get the root Canvas.");
   Point2I localPoint = globalToLocalCoord(root->getCursorPos());

   //draw the close button
   Point2I tempUL;
   Point2I tempLR;
   S32 bmp = BmpStates * BmpClose;

   if( mCanClose ) 
	{
#ifdef TGE_RPG_UI /// TGE_RPG_UI
      if( mCloseButton.pointInRect( localPoint ))
		{
			if(mPressClose)
				bmp += BmpDepress;
			else
				bmp += BmpHilite;
				//offset2.y --;
		}
#else
      if( mCloseButton.pointInRect( localPoint ) && mPressClose )
         bmp += BmpHilite;
#endif

      dglClearBitmapModulation();
      dglDrawBitmapSR(mTextureHandle, offset + mCloseButton.point, mBitmapBounds[bmp]);
   }

   //draw the maximize button
   if( mMaximized )
      bmp = BmpStates * BmpNormal;
   else
      bmp = BmpStates * BmpMaximize;

   if( mCanMaximize ) 
	{
#ifdef TGE_RPG_UI /// TGE_RPG_UI
      if( mMaximizeButton.pointInRect( localPoint ))
		{
			if( mPressMaximize )
				bmp += BmpDepress;
			else
			  bmp += BmpHilite;
		}
#else
      if( mMaximizeButton.pointInRect( localPoint ) && mPressMaximize )
         bmp += BmpHilite;
#endif

      dglClearBitmapModulation();
      dglDrawBitmapSR( mTextureHandle, offset + mMaximizeButton.point, mBitmapBounds[bmp] );
   }

   //draw the minimize button
   if( mMinimized )
      bmp = BmpStates * BmpNormal;
   else
      bmp = BmpStates * BmpMinimize;

   if( mCanMinimize ) {
#ifdef TGE_RPG_UI /// TGE_RPG_UI
      if( mMinimizeButton.pointInRect( localPoint ) )
		{ 
			if(mPressMinimize )
				bmp += BmpDepress;
			else
				bmp += BmpHilite;
	}
#else
      if( mMinimizeButton.pointInRect( localPoint ) && mPressMinimize )
         bmp += BmpHilite;
#endif

      dglClearBitmapModulation();
      dglDrawBitmapSR( mTextureHandle, offset + mMinimizeButton.point, mBitmapBounds[bmp] );
   }

   if( !mMinimized )
   {
      //render the children
      renderChildControls( offset, updateRect );
   }
}

bool GuiWindowCtrl::initCursors()
{
   if ( mUpDownCursor == NULL || mLeftRightCursor == NULL || mDefaultCursor == NULL || mNWSECursor == NULL || mNESWCursor == NULL )
   {
      SimObject *obj;
      obj = Sim::findObject("UpDownCursor");
      mUpDownCursor = dynamic_cast<GuiCursor*>(obj);
      obj = Sim::findObject("LeftRightCursor");
      mLeftRightCursor = dynamic_cast<GuiCursor*>(obj);
      obj = Sim::findObject("DefaultCursor");
      mDefaultCursor = dynamic_cast<GuiCursor*>(obj);
      obj = Sim::findObject("NESWCursor");
      mNESWCursor = dynamic_cast<GuiCursor*>(obj);
      obj = Sim::findObject("NWSECursor");
      mNWSECursor = dynamic_cast<GuiCursor*>(obj);

      return( mUpDownCursor != NULL && mLeftRightCursor != NULL && mDefaultCursor != NULL && mNWSECursor != NULL && mNESWCursor != NULL );
   }
   else
      return(true);
}


void GuiWindowCtrl::getCursor(GuiCursor *&cursor, bool &showCursor, const GuiEvent &lastGuiEvent)
{
   showCursor = true;

   if( initCursors() )
   {
      Point2I mousePos  = lastGuiEvent.mousePoint;
      RectI winRect   = mBounds;
      RectI rightRect = RectI( ( ( winRect.extent.x + winRect.point.x ) - mResizeRightWidth), winRect.point.y, mResizeRightWidth, winRect.extent.y );
      RectI bottomRect = RectI( winRect.point.x, ( ( winRect.point.y + winRect.extent.y ) - mResizeBottomHeight), winRect.extent.x , mResizeBottomHeight );

      bool resizeRight = rightRect.pointInRect( mousePos );
      bool resizeBottom = bottomRect.pointInRect( mousePos );

      if ( resizeRight && resizeBottom && mResizeHeight && mResizeWidth )
         cursor = mNWSECursor;
      else if ( resizeBottom && mResizeHeight )
         cursor = mUpDownCursor;
      else if ( resizeRight && mResizeWidth )
         cursor = mLeftRightCursor;
      else
         cursor = NULL;
   }
}


void GuiWindowCtrl::autoSizeToContent()
{
	if(!mBitmapBounds)
		return;

	if(m_bAutoSize)
	{
		m_marginTopLeft.set(mBitmapBounds[BorderLeft].extent.x,mBitmapBounds[BorderTopKey].extent.y);
		m_marginBottomRight	= Point2I(mBitmapBounds[BorderRight].extent.x,mBitmapBounds[BorderBottom].extent.y);
	}
	Parent::autoSizeToContent();

	//m_boundBak = mBounds.extent;
}



⌨️ 快捷键说明

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