📄 guicontrol.cc
字号:
return;
//pass the event to the parent
GuiControl *parent = getParent();
if ( parent )
parent->onMouseMove( event );
}
void GuiControl::onMouseDragged(const GuiEvent &event)
{
}
void GuiControl::onMouseEnter(const GuiEvent &)
{
}
void GuiControl::onMouseLeave(const GuiEvent &)
{
}
bool GuiControl::onMouseWheelUp( const GuiEvent &event )
{
//if this control is a dead end, make sure the event stops here
if ( !mVisible || !mAwake )
return true;
//pass the event to the parent
GuiControl *parent = getParent();
if ( parent )
return parent->onMouseWheelUp( event );
else
return false;
}
bool GuiControl::onMouseWheelDown( const GuiEvent &event )
{
//if this control is a dead end, make sure the event stops here
if ( !mVisible || !mAwake )
return true;
//pass the event to the parent
GuiControl *parent = getParent();
if ( parent )
return parent->onMouseWheelDown( event );
else
return false;
}
void GuiControl::onRightMouseDown(const GuiEvent &)
{
}
void GuiControl::onRightMouseUp(const GuiEvent &)
{
}
void GuiControl::onRightMouseDragged(const GuiEvent &)
{
}
void GuiControl::onMiddleMouseDown(const GuiEvent &)
{
}
void GuiControl::onMiddleMouseUp(const GuiEvent &)
{
}
void GuiControl::onMiddleMouseDragged(const GuiEvent &)
{
}
// JDD : Editor Mouse events
void GuiControl::onMouseDownEditor(const GuiEvent &event, Point2I offset)
{
}
void GuiControl::onRightMouseDownEditor(const GuiEvent &event, Point2I offset)
{
}
GuiControl* GuiControl::findFirstTabable()
{
GuiControl *tabCtrl = NULL;
iterator i;
for (i = begin(); i != end(); i++)
{
GuiControl *ctrl = static_cast<GuiControl *>(*i);
tabCtrl = ctrl->findFirstTabable();
if (tabCtrl)
{
mFirstResponder = tabCtrl;
return tabCtrl;
}
}
//nothing was found, therefore, see if this ctrl is tabable
return ( mProfile != NULL ) ? ( ( mProfile->mTabable && mAwake && mVisible ) ? this : NULL ) : NULL;
}
GuiControl* GuiControl::findLastTabable(bool firstCall)
{
//if this is the first call, clear the global
if (firstCall)
smPrevResponder = NULL;
//if this control is tabable, set the global
if (mProfile->mTabable)
smPrevResponder = this;
iterator i;
for (i = begin(); i != end(); i++)
{
GuiControl *ctrl = static_cast<GuiControl *>(*i);
ctrl->findLastTabable(false);
}
//after the entire tree has been traversed, return the last responder found
mFirstResponder = smPrevResponder;
return smPrevResponder;
}
GuiControl *GuiControl::findNextTabable(GuiControl *curResponder, bool firstCall)
{
//if this is the first call, clear the global
if (firstCall)
smCurResponder = NULL;
//first find the current responder
if (curResponder == this)
smCurResponder = this;
//if the first responder has been found, return the very next *tabable* control
else if ( smCurResponder && mProfile->mTabable && mAwake && mVisible && mActive )
return( this );
//loop through, checking each child to see if it is the one that follows the firstResponder
GuiControl *tabCtrl = NULL;
iterator i;
for (i = begin(); i != end(); i++)
{
GuiControl *ctrl = static_cast<GuiControl *>(*i);
tabCtrl = ctrl->findNextTabable(curResponder, false);
if (tabCtrl) break;
}
mFirstResponder = tabCtrl;
return tabCtrl;
}
GuiControl *GuiControl::findPrevTabable(GuiControl *curResponder, bool firstCall)
{
if (firstCall)
smPrevResponder = NULL;
//if this is the current reponder, return the previous one
if (curResponder == this)
return smPrevResponder;
//else if this is a responder, store it in case the next found is the current responder
else if ( mProfile->mTabable && mAwake && mVisible && mActive )
smPrevResponder = this;
//loop through, checking each child to see if it is the one that follows the firstResponder
GuiControl *tabCtrl = NULL;
iterator i;
for (i = begin(); i != end(); i++)
{
GuiControl *ctrl = static_cast<GuiControl *>(*i);
tabCtrl = ctrl->findPrevTabable(curResponder, false);
if (tabCtrl) break;
}
mFirstResponder = tabCtrl;
return tabCtrl;
}
void GuiControl::onLoseFirstResponder()
{
// Since many controls have visual cues when they are the firstResponder...
setUpdate();
}
bool GuiControl::ControlIsChild(GuiControl *child)
{
//function returns true if this control, or one of it's children is the child control
if (child == this)
return true;
//loop through, checking each child to see if it is ,or contains, the firstResponder
iterator i;
for (i = begin(); i != end(); i++)
{
GuiControl *ctrl = static_cast<GuiControl *>(*i);
if (ctrl->ControlIsChild(child)) return true;
}
//not found, therefore false
return false;
}
bool GuiControl::isFirstResponder()
{
GuiCanvas *root = getRoot();
return root && root->getFirstResponder() == this;
}
void GuiControl::setFirstResponder( GuiControl* firstResponder )
{
if ( firstResponder && firstResponder->mProfile->mCanKeyFocus )
mFirstResponder = firstResponder;
GuiControl *parent = getParent();
if ( parent )
parent->setFirstResponder( firstResponder );
}
void GuiControl::setFirstResponder()
{
if ( mAwake && mVisible )
{
GuiControl *parent = getParent();
if (mProfile->mCanKeyFocus && parent)
parent->setFirstResponder(this);
// Since many controls have visual cues when they are the firstResponder...
setUpdate();
}
}
void GuiControl::clearFirstResponder()
{
GuiControl *parent = this;
while((parent = parent->getParent()) != NULL)
{
if(parent->mFirstResponder == this)
parent->mFirstResponder = NULL;
else
break;
}
}
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- //
void GuiControl::buildAcceleratorMap()
{
//add my own accel key
addAcceleratorKey();
//add all my childrens keys
iterator i;
for(i = begin(); i != end(); i++)
{
GuiControl *ctrl = static_cast<GuiControl *>(*i);
ctrl->buildAcceleratorMap();
}
}
void GuiControl::addAcceleratorKey()
{
//see if we have an accelerator
if (mAcceleratorKey == StringTable->insert(""))
return;
EventDescriptor accelEvent;
ActionMap::createEventDescriptor(mAcceleratorKey, &accelEvent);
//now we have a modifier, and a key, add them to the canvas
GuiCanvas *root = getRoot();
if (root)
root->addAcceleratorKey(this, 0, accelEvent.eventCode, accelEvent.flags);
}
void GuiControl::acceleratorKeyPress(U32 index)
{
index;
onAction();
}
void GuiControl::acceleratorKeyRelease(U32 index)
{
index;
//do nothing
}
bool GuiControl::onKeyDown(const GuiEvent &event)
{
//pass the event to the parent
GuiControl *parent = getParent();
if (parent)
return parent->onKeyDown(event);
else
return false;
}
bool GuiControl::onKeyRepeat(const GuiEvent &event)
{
// default to just another key down.
return onKeyDown(event);
}
bool GuiControl::onKeyUp(const GuiEvent &event)
{
//pass the event to the parent
GuiControl *parent = getParent();
if (parent)
return parent->onKeyUp(event);
else
return false;
}
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- //
void GuiControl::onAction()
{
if (! mActive)
return;
//execute the console command
if (mConsoleCommand[0])
{
char buf[16];
dSprintf(buf, sizeof(buf), "%d", getId());
Con::setVariable("$ThisControl", buf);
Con::evaluate(mConsoleCommand, false);
}
else
Con::executef(this, 1, "onAction");
}
void GuiControl::onMessage(GuiControl *sender, S32 msg)
{
sender;
msg;
}
void GuiControl::messageSiblings(S32 message)
{
GuiControl *parent = getParent();
if (! parent) return;
GuiControl::iterator i;
for(i = parent->begin(); i != parent->end(); i++)
{
GuiControl *ctrl = dynamic_cast<GuiControl *>(*i);
if (ctrl != this)
ctrl->onMessage(this, message);
}
}
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- //
void GuiControl::onDialogPush()
{
}
void GuiControl::onDialogPop()
{
}
#ifdef TGE_RPG_UI
Point2I GuiControl::getGlobalPos()
{
GuiControl* pParent;
pParent = getParent();
if(pParent)
return pParent->localToGlobalCoord(mBounds.point);
return mBounds.point;
}
#endif
#ifdef TGE_RPG_UI
void GuiControl::ToggleVH(bool bVertical,GuiControl *pDispatch)
{
//bool bVertical
//if(bWH)
{
S32 cx = mBounds.extent.x;
mBounds.extent.x = mBounds.extent.y;
mBounds.extent.y = cx;
}
//if(bPos)
if(pDispatch != this)
{
S32 x = mBounds.point.x;
mBounds.point.x = mBounds.point.y;
mBounds.point.y = x;
}
}
void GuiControl::autoSizeToContent()
{
//return;
//Point2I m_marginTopLeft;
//Point2I m_marginBottomRight;
//Point2I topLeft(mBitmapBounds[BorderLeft].extent.x,mBitmapBounds[BorderTopKey].extent.y);
U32 n;
GuiControl* pCtrl;
//RectI rectMax(0,0,0,0);
//Point2I topLeft(mBitmapBounds[BorderLeft].extent.x,mBitmapBounds[BorderTopKey].extent.y);
Point2I offset(m_marginTopLeft*2);
Point2I areaSize(0,0);
//计算超越上界、左界的最大值,然后所有控件一同移动此偏移量
for(n=0; n< Parent::size(); n++)
{
pCtrl = dynamic_cast<GuiControl*>(operator [](n));
if(pCtrl == NULL || !pCtrl->isVisible())
continue;
if(pCtrl->getLeft() < offset.x)
offset.x = pCtrl->getLeft();
if(pCtrl->getTop() < offset.y)
offset.y = pCtrl->getTop();
}
offset = m_marginTopLeft - offset;
if(!offset.isZero())
{
for(n=0; n< Parent::size(); n++)
{
pCtrl = dynamic_cast<GuiControl*>(operator [](n));
if(pCtrl == NULL || !pCtrl->isVisible())
continue;
pCtrl->setPosition(pCtrl->getPosition() + offset);
}
}
/////////////////////////////////////////////////
//计算客户区域大小
for(n=0; n< Parent::size(); n++)
{
pCtrl = dynamic_cast<GuiControl*>(operator [](n));
if(pCtrl == NULL || !pCtrl->isVisible())
continue;
//if(pCtrl->getLeft() < rectMax.point.x)
// rectMax.point.x = pCtrl->getLeft();
//if(pCtrl->getTop() < rectMax.point.y)
// rectMax.point.y = pCtrl->getTop();
if(pCtrl->getLeft() + pCtrl->getWidth() >= areaSize.x)
areaSize.x = pCtrl->getLeft() + pCtrl->getWidth();
if(pCtrl->getTop() + pCtrl->getHeight() >= areaSize.y)
areaSize.y = pCtrl->getTop() + pCtrl->getHeight();
}
areaSize += m_marginBottomRight;
if(areaSize.x > Canvas->getWidth() - (m_marginTopLeft.x + m_marginBottomRight.x))
areaSize.x = Canvas->getWidth() - (m_marginTopLeft.x + m_marginBottomRight.x);
if(areaSize.y > Canvas->getHeight() - (m_marginTopLeft.y + m_marginBottomRight.y))
areaSize.y = Canvas->getHeight() - (m_marginTopLeft.y + m_marginBottomRight.y);
setExtent(areaSize);
//m_boundBak = mBounds.extent;
}
#endif
//------------------------------------------------------------------------------
void GuiControl::setVisible(bool value)
{
mVisible = value;
iterator i;
setUpdate();
for(i = begin(); i != end(); i++)
{
GuiControl *ctrl = static_cast<GuiControl *>(*i);
ctrl->clearFirstResponder();
}
GuiControl *parent = getParent();
if (parent)
parent->childResized(this);
}
void GuiControl::makeFirstResponder(bool value)
{
if ( value )
//setFirstResponder(this);
setFirstResponder();
else
clearFirstResponder();
}
void GuiControl::setActive( bool value )
{
mActive = value;
if ( !mActive )
clearFirstResponder();
if ( mVisible && mAwake )
setUpdate();
}
void GuiControl::getScrollLineSizes(U32 *rowHeight, U32 *columnWidth)
{
// default to 10 pixels in y, 30 pixels in x
*columnWidth = 30;
*rowHeight = 10;
}
void GuiControl::renderJustifiedText(Point2I offset, Point2I extent, const char *text)
{
GFont *font = mProfile->mFont;
S32 textWidth = font->getStrWidth((const UTF8*)text);
Point2I start;
// align the horizontal
switch( mProfile->mAlignment )
{
case GuiControlProfile::RightJustify:
start.set( extent.x - textWidth, 0 );
break;
case GuiControlProfile::CenterJustify:
start.set( ( extent.x - textWidth) / 2, 0 );
break;
default:
// GuiControlProfile::LeftJustify
start.set( 0, 0 );
break;
}
// If the text is longer then the box size, (it'll get clipped) so
// force Left Justify
if( textWidth > extent.x )
start.set( 0, 0 );
// center the vertical
if(font->getHeight() > extent.y)
start.y = 0 - ((font->getHeight() - extent.y) / 2) ;
else
start.y = ( extent.y - font->getHeight() ) / 2;
dglDrawText( font, start + offset, text, mProfile->mFontColors );
}
void GuiControl::getCursor(GuiCursor *&cursor, bool &showCursor, const GuiEvent &lastGuiEvent)
{
lastGuiEvent;
cursor = NULL;
showCursor = true;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -