📄 guitabbookctrl.cc
字号:
RectI GuiTabBookCtrl::getPageRectChild()
{
RectI Result;
switch( mTabPosition )
{
case AlignTop:
Result.point.x = 0;
Result.extent.x = mBounds.extent.x;
Result.point.y = mTabHeight;
Result.extent.y = mBounds.extent.y - mTabHeight;
break;
case AlignBottom:
Result.point.x = 0;
Result.extent.x = mBounds.extent.x;
Result.point.y = 0;
Result.extent.y = mBounds.extent.y - mTabHeight;
break;
case AlignLeft:
Result.point.x = mTabHeight;
Result.extent.x = mBounds.extent.x - mTabHeight;
Result.point.y = 0;
Result.extent.y = mBounds.extent.y;
break;
case AlignRight:
Result.point.x = 0;
Result.extent.x = mBounds.extent.x - mTabHeight;
Result.point.y = 0;
Result.extent.y = mBounds.extent.y;
break;
}
return Result;
}
void GuiTabBookCtrl::onPreRender()
{
// sometimes we need to resize because of a changed persistent field
// that's what this does
solveDirty();
}
void GuiTabBookCtrl::solveDirty()
{
bool dirty = false;
if( mTabPosition != mLastTabPosition )
{
mLastTabPosition = mTabPosition;
dirty = true;
}
if( mTabHeight != mLastTabHeight )
{
mLastTabHeight = mTabHeight;
dirty = true;
}
if( mTabWidth != mLastTabWidth )
{
mLastTabWidth = mTabWidth;
dirty = true;
}
if( dirty )
resize( mBounds.point, mBounds.extent );
}
void GuiTabBookCtrl::onRender(Point2I offset, const RectI &updateRect)
{
RectI tabRect = getTabBaseRect( offset );
RectI pageRect = getPageRect( tabRect, offset );
// We're so nice we'll store the old modulation before we clear it for our rendering! :)
ColorI oldModulation;
dglGetBitmapModulation( &oldModulation );
// Wipe it out
dglClearBitmapModulation();
// Render our tabs
renderTabs( tabRect );
// This is ideal, we know what our active tab is, so we only render it
if( mActivePage != NULL )
{
mActivePage->onRender( pageRect.point, pageRect );
}
else
{
// Render only the active page
if( ! mPages.empty() )
{
GuiTabPageCtrl* tab = reinterpret_cast<GuiTabPageCtrl*>(*mPages.begin());
tab->onRender( pageRect.point, pageRect );
mActivePage = tab;
}
else
{
// if we have no active page, render a filled rect only
dglDrawRectFill( pageRect, mProfile->mFillColor );
}
}
// Restore old modulation
dglSetBitmapModulation( oldModulation );
}
void GuiTabBookCtrl::renderTabs( const RectI &bounds )
{
RectI oldClip = dglGetClipRect();
dglSetClipRect( bounds );
S32 fitTabs = 0; // How many tabs can we fit in the book?
S32 extentY,extentX;
switch( mTabPosition )
{
case AlignTop:
case AlignBottom:
fitTabs = (S32)mCeil( (F32)bounds.extent.x / (F32)mTabWidth );
extentX = mTabWidth;
extentY = mTabHeight;
break;
case AlignLeft:
case AlignRight:
fitTabs = (S32)mCeil( (F32)bounds.extent.y / (F32)mTabWidth );
extentY = mTabWidth;
extentX = mTabHeight;
break;
};
Vector<GuiTabPageCtrl*>::iterator i = mPages.begin();
for( S32 j=0 ; ( i != mPages.end() && j < fitTabs ) ; i++, j++)
{
RectI tabBounds = RectI( bounds.point.x, bounds.point.y, extentX, extentY );
switch( mTabPosition )
{
case AlignTop:
case AlignBottom:
tabBounds.point.x = bounds.point.x + ( j * mTabWidth );
break;
case AlignLeft:
case AlignRight:
tabBounds.point.y = bounds.point.y + ( j * mTabWidth );
break;
};
GuiTabPageCtrl *tab = reinterpret_cast<GuiTabPageCtrl*>(*i);
renderTab( tabBounds, tab );
}
dglSetClipRect( oldClip );
}
void GuiTabBookCtrl::renderTab( RectI tabRect, GuiTabPageCtrl *tab )
{
StringTableEntry text = tab->getText();
ColorI oldColor;
dglGetBitmapModulation( &oldColor );
#ifdef TGE_RPG_UI/// TGE_Theme
mHasTexture = mProfile->constructBitmapArray() == NumBitmaps;
if(mHasTexture)
#else
// Is this a skinned control?
if( mHasTexture && mProfile->mBitmapArrayRects.size() == NumBitmaps)
#endif
{
S32 tabTextureIndex = 0;
RectI stretchRect;
if ( mActivePage == tab )
stretchRect = mBitmapBounds[ TabSelected ];
else if( mHoverTab == tab )
stretchRect = mBitmapBounds[ TabHover ];
else
stretchRect = mBitmapBounds[ TabNormal ];
dglDrawBitmapStretchSR(mProfile->mTextureHandle,tabRect,stretchRect, (mTabPosition == AlignBottom) ? /* Render texture upside down */ GFlip_Y : 0 );
}
else
{
// If this isn't a skinned control or the bitmap is simply missing, handle it WELL
if ( mActivePage == tab )
dglDrawRectFill(tabRect, mProfile->mFillColor);
else if( mHoverTab == tab )
dglDrawRectFill(tabRect, mProfile->mFillColorHL);
else
dglDrawRectFill(tabRect, mProfile->mFillColorNA);
}
dglSetBitmapModulation(mProfile->mFontColor);
renderJustifiedText( tabRect.point, tabRect.extent, text );
dglSetBitmapModulation( oldColor);
}
void GuiTabBookCtrl::selectPage( S32 index )
{
if( mPages.size() < index )
return;
// Select the page
selectPage( mPages[ index ] );
}
void GuiTabBookCtrl::selectPage( GuiTabPageCtrl *page )
{
Vector<GuiTabPageCtrl*>::iterator i = mPages.begin();
for( ; i != mPages.end() ; i++ )
{
GuiTabPageCtrl *tab = reinterpret_cast<GuiTabPageCtrl*>(*i);
if( page == tab )
{
mActivePage = tab;
tab->setVisible( true );
// Notify User
char *retBuffer = Con::getReturnBuffer( 512 );
dStrcpy( retBuffer, tab->getText() );
Con::executef( this, 2, "onTabSelected", retBuffer );
}
else
tab->setVisible( false );
}
}
void GuiTabBookCtrl::onMouseDown(const GuiEvent &event)
{
RectI TabBase = getHitRect();
if( TabBase.pointInRect( event.mousePoint ) )
{
GuiTabPageCtrl *tab = findHitTab( event.mousePoint );
if( tab != NULL )
selectPage( tab );
}
}
void GuiTabBookCtrl::onRightMouseDown(const GuiEvent &event)
{
if (! mActive)
{
Parent::onRightMouseDown(event);
return;
}
setFirstResponder();
//search for the control hit in any layer below the edit layer
GuiControl *hitCtrl = findHitControl(globalToLocalCoord(event.mousePoint), mLayer - 1);
if (hitCtrl != this)
{
Con::executef(this, 1, "onClearSelected");
}
}
void GuiTabBookCtrl::onMouseMove(const GuiEvent &event)
{
RectI TabBase = getHitRect();
if( TabBase.pointInRect( event.mousePoint ) )
{
GuiTabPageCtrl *tab = findHitTab( event.mousePoint );
if( tab != NULL && mHoverTab != tab )
mHoverTab = tab;
else if ( !tab )
mHoverTab = NULL;
}
Parent::onMouseMove( event );
}
void GuiTabBookCtrl::onMouseLeave( const GuiEvent &event )
{
mHoverTab = NULL;
}
void GuiTabBookCtrl::onMouseDownEditor(const GuiEvent &event, Point2I offset)
{
RectI TabBase = getHitRect( offset );
if( TabBase.pointInRect( event.mousePoint ) )
{
GuiTabPageCtrl *tab = findHitTab( event.mousePoint + offset );
if( tab != NULL )
selectPage( tab );
}
// This shouldn't be called if it's not design time, but check just incase
if ( GuiControl::smDesignTime )
{
// If we clicked in the editor and our addset is the tab book
// ctrl, select the child ctrl so we can edit it's properties
GuiEditCtrl* edit = GuiControl::smEditorHandle;
if( edit && ( edit->getAddSet() == this ) && mActivePage != NULL )
edit->select( mActivePage );
}
}
void GuiTabBookCtrl::onRightMouseDownEditor(const GuiEvent &event, Point2I offset)
{
//////GuiPopUpTextListCtrl
//GuiPopUpMenuCtrl * menu = new GuiPopUpMenuCtrl();
//menu->setField("profile", "GuiPopUpMenuProfile");
//menu->setField("text", "Duh");
////now add the entries
//menu->addEntry("Test",1);
//menu->onAction();
//menu->registerObject();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -