📄 guitextlistctrl.cc
字号:
dglSetClipRect(clipRect);
}
}
#ifdef TGE_RPG_UI ///TGE_RPG_UI 文字内容V居中
pos.y += yOffset;
#endif
dglDrawTextN(mFont, pos, text, slen, mProfile->mFontColors);
if(clipped)
dglSetClipRect(saveClipRect);
}
if(!nextCol)
break;
text = nextCol+1;
}
}
U32 GuiTextListCtrl::getRowWidth(Entry *row)
{
U32 width = 1;
const char *text = row->text;
for(U32 index = 0; index < mColumnOffsets.size(); index++)
{
const char *nextCol = dStrchr(text, '\t');
U32 textWidth;
if(nextCol)
textWidth = mFont->getStrNWidth((const UTF8*)text, nextCol - text);
else
textWidth = mFont->getStrWidth((const UTF8*)text);
if(mColumnOffsets[index] >= 0)
width = getMax(width, mColumnOffsets[index] + textWidth);
if(!nextCol)
break;
text = nextCol+1;
}
return width;
}
void GuiTextListCtrl::insertEntry(U32 id, const char *text, S32 index)
{
Entry e;
e.text = dStrdup(text);
e.id = id;
e.active = true;
if(!mList.size())
mList.push_back(e);
else
{
if(index > mList.size())
index = mList.size();
mList.insert(&mList[index],e);
}
setSize(Point2I(1, mList.size()));
}
void GuiTextListCtrl::addEntry(U32 id, const char *text)
{
Entry e;
e.text = dStrdup(text);
e.id = id;
e.active = true;
mList.push_back(e);
setSize(Point2I(1, mList.size()));
}
void GuiTextListCtrl::setEntry(U32 id, const char *text)
{
S32 e = findEntryById(id);
if(e == -1)
addEntry(id, text);
else
{
dFree(mList[e].text);
mList[e].text = dStrdup(text);
// Still have to call this to make sure cells are wide enough for new values:
setSize( Point2I( 1, mList.size() ) );
}
setUpdate();
}
void GuiTextListCtrl::setEntryActive(U32 id, bool active)
{
S32 index = findEntryById( id );
if ( index == -1 )
return;
if ( mList[index].active != active )
{
mList[index].active = active;
// You can't have an inactive entry selected...
if ( !active && mSelectedCell.y >= 0 && mSelectedCell.y < mList.size()
&& mList[mSelectedCell.y].id == id )
setSelectedCell( Point2I( -1, -1 ) );
setUpdate();
}
}
S32 GuiTextListCtrl::findEntryById(U32 id)
{
for(U32 i = 0; i < mList.size(); i++)
if(mList[i].id == id)
return i;
return -1;
}
S32 GuiTextListCtrl::findEntryByText(const char *text)
{
for(U32 i = 0; i < mList.size(); i++)
if(!dStricmp(mList[i].text, text))
return i;
return -1;
}
bool GuiTextListCtrl::isEntryActive(U32 id)
{
S32 index = findEntryById( id );
if ( index == -1 )
return( false );
return( mList[index].active );
}
void GuiTextListCtrl::setSize(Point2I newSize)
{
mSize = newSize;
if ( bool( mFont ) )
{
if ( mSize.x == 1 && mFitParentWidth )
{
GuiScrollCtrl* parent = dynamic_cast<GuiScrollCtrl *>(getParent());
if ( parent )
mCellSize.x = parent->getContentExtent().x;
}
else
{
// Find the maximum width cell:
S32 maxWidth = 1;
for ( U32 i = 0; i < mList.size(); i++ )
{
U32 rWidth = getRowWidth( &mList[i] );
if ( rWidth > maxWidth )
maxWidth = rWidth;
}
mCellSize.x = maxWidth + 8;
}
#ifdef TGE_RPG ///TGE_RPG
mCellSize.y = mFont->getHeight() + 6;
#else
mCellSize.y = mFont->getHeight() + 2;
#endif
}
Point2I newExtent( newSize.x * mCellSize.x + mHeaderDim.x, newSize.y * mCellSize.y + mHeaderDim.y );
resize( mBounds.point, newExtent );
}
void GuiTextListCtrl::clear()
{
while (mList.size())
removeEntry(mList[0].id);
mMouseOverCell.set( -1, -1 );
setSelectedCell(Point2I(-1, -1));
}
void GuiTextListCtrl::sort(U32 column, bool increasing)
{
if (getNumEntries() < 2)
return;
sortColumn = column;
sIncreasing = increasing;
dQsort((void *)&(mList[0]), mList.size(), sizeof(Entry), textCompare);
}
void GuiTextListCtrl::sortNumerical( U32 column, bool increasing )
{
if ( getNumEntries() < 2 )
return;
sortColumn = column;
sIncreasing = increasing;
dQsort( (void*) &( mList[0] ), mList.size(), sizeof( Entry ), numCompare );
}
void GuiTextListCtrl::onRemove()
{
clear();
Parent::onRemove();
}
U32 GuiTextListCtrl::getNumEntries()
{
return mList.size();
}
void GuiTextListCtrl::removeEntryByIndex(S32 index)
{
if(index < 0 || index >= mList.size())
return;
dFree(mList[index].text);
mList.erase(index);
setSize(Point2I( 1, mList.size()));
setSelectedCell(Point2I(-1, -1));
}
void GuiTextListCtrl::removeEntry(U32 id)
{
S32 index = findEntryById(id);
removeEntryByIndex(index);
}
const char *GuiTextListCtrl::getSelectedText()
{
if (mSelectedCell.y == -1)
return NULL;
return mList[mSelectedCell.y].text;
}
const char *GuiTextListCtrl::getScriptValue()
{
return getSelectedText();
}
void GuiTextListCtrl::setScriptValue(const char *val)
{
S32 e = findEntryByText(val);
if(e == -1)
setSelectedCell(Point2I(-1, -1));
else
setSelectedCell(Point2I(0, e));
}
bool GuiTextListCtrl::onKeyDown( const GuiEvent &event )
{
//if this control is a dead end, make sure the event stops here
if ( !mVisible || !mActive || !mAwake )
return true;
S32 yDelta = 0;
switch( event.keyCode )
{
case KEY_RETURN:
if ( mAltConsoleCommand[0] )
Con::evaluate( mAltConsoleCommand, false );
break;
case KEY_LEFT:
case KEY_UP:
if ( mSelectedCell.y > 0 )
{
mSelectedCell.y--;
yDelta = -mCellSize.y;
}
break;
case KEY_DOWN:
case KEY_RIGHT:
if ( mSelectedCell.y < ( mList.size() - 1 ) )
{
mSelectedCell.y++;
yDelta = mCellSize.y;
}
break;
case KEY_HOME:
if ( mList.size() )
{
mSelectedCell.y = 0;
yDelta = -(mCellSize.y * mList.size() + 1 );
}
break;
case KEY_END:
if ( mList.size() )
{
mSelectedCell.y = mList.size() - 1;
yDelta = (mCellSize.y * mList.size() + 1 );
}
break;
case KEY_DELETE:
if ( mSelectedCell.y >= 0 && mSelectedCell.y < mList.size() )
Con::executef( this, 2, "onDeleteKey", Con::getIntArg( mList[mSelectedCell.y].id ) );
break;
default:
return( Parent::onKeyDown( event ) );
break;
};
GuiScrollCtrl* parent = dynamic_cast<GuiScrollCtrl *>(getParent());
if ( parent )
parent->scrollDelta( 0, yDelta );
return ( true );
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -