📄 guieditctrl.cc
字号:
{
(*k)->resize(Point2I((*k)->mBounds.point.x, curY), (*k)->mBounds.extent);
curY += space;
}
}
}
break;
case SPACING_LEFT:
case SPACING_RIGHT:
case SPACING_HAVERAGE:
{
Vector<GuiControl *> sortedList;
Vector<GuiControl *>::iterator k;
for(i = mSelectedControls.begin(); i != mSelectedControls.end(); i++)
{
for(k = sortedList.begin(); k != sortedList.end(); k++)
{
if ((*i)->mBounds.point.x < (*k)->mBounds.point.x)
break;
}
sortedList.insert(k, *i);
}
S32 space;
S32 curX = minX;
if(j == SPACING_VAVERAGE)
{
space = (deltaX - extentX) / (mSelectedControls.size() - 1);
for(k = sortedList.begin(); k != sortedList.end(); k++)
{
(*k)->resize(Point2I(curX, (*k)->mBounds.point.y), (*k)->mBounds.extent);
curX += (*k)->mBounds.extent.x + space;
}
}
else if(j == SPACING_RIGHT)
{
space = (rightDeltaY) / (mSelectedControls.size() - 1);
k = sortedList.begin();
curX += (*k)->mBounds.extent.x;
for(;k != sortedList.end() ;k++)
{
curX -= (*k)->mBounds.extent.x;
(*k)->resize(Point2I(curX, (*k)->mBounds.point.y), (*k)->mBounds.extent);
curX += (*k)->mBounds.extent.x + space;
}
}
else
{
space = (leftDeltaX) / (mSelectedControls.size() - 1);
for(k = sortedList.begin(); k != sortedList.end(); k++)
{
(*k)->resize(Point2I(curX, (*k)->mBounds.point.y), (*k)->mBounds.extent);
curX += space;
}
}
}
break;
case SPACING_VFOLLOW:
{
S32 curY = minY;
for(i = mSelectedControls.begin(); i != mSelectedControls.end(); i++)
{
(*i)->setTop(curY);
curY += (*i)->getHeight();
}
}
break;
case SPACING_HFOLLOW:
{
S32 curX = minX;
for(i = mSelectedControls.begin(); i != mSelectedControls.end(); i++)
{
(*i)->setLeft(curX);
curX += (*i)->getWidth();
}
}
break;
case SIZING_WIDTH:
{
i = mSelectedControls.begin();
U32 wInit = (*i)->mBounds.extent.x;
i++;
for(; i != mSelectedControls.end(); i++)
(*i)->setWidth(wInit);
}
break;
case SIZING_HEIGHT:
{
i = mSelectedControls.begin();
U32 hInit = (*i)->mBounds.extent.y;
i++;
for(; i != mSelectedControls.end(); i++)
(*i)->setHeight(hInit);
}
break;
case SIZING_WH:
{
i = mSelectedControls.begin();
Point2I sizeInit = (*i)->mBounds.extent;
i++;
for(; i != mSelectedControls.end(); i++)
(*i)->setExtent(sizeInit);
}
break;
#else
case JUSTIFY_CENTER:
for(i = mSelectedControls.begin(); i != mSelectedControls.end(); i++)
(*i)->resize(Point2I(minX + ((deltaX - (*i)->mBounds.extent.x) >> 1), (*i)->mBounds.point.y),
(*i)->mBounds.extent);
break;
case SPACING_VERTICAL:
{
Vector<GuiControl *> sortedList;
Vector<GuiControl *>::iterator k;
for(i = mSelectedControls.begin(); i != mSelectedControls.end(); i++)
{
for(k = sortedList.begin(); k != sortedList.end(); k++)
{
if ((*i)->mBounds.point.y < (*k)->mBounds.point.y)
break;
}
sortedList.insert(k, *i);
}
S32 space = (deltaY - extentY) / (mSelectedControls.size() - 1);
S32 curY = minY;
for(k = sortedList.begin(); k != sortedList.end(); k++)
{
(*k)->resize(Point2I((*k)->mBounds.point.x, curY), (*k)->mBounds.extent);
curY += (*k)->mBounds.extent.y + space;
}
}
break;
case SPACING_HORIZONTAL:
{
Vector<GuiControl *> sortedList;
Vector<GuiControl *>::iterator k;
for(i = mSelectedControls.begin(); i != mSelectedControls.end(); i++)
{
for(k = sortedList.begin(); k != sortedList.end(); k++)
{
if ((*i)->mBounds.point.x < (*k)->mBounds.point.x)
break;
}
sortedList.insert(k, *i);
}
S32 space = (deltaX - extentX) / (mSelectedControls.size() - 1);
S32 curX = minX;
for(k = sortedList.begin(); k != sortedList.end(); k++)
{
(*k)->resize(Point2I(curX, (*k)->mBounds.point.y), (*k)->mBounds.extent);
curX += (*k)->mBounds.extent.x + space;
}
}
break;
#endif
}
}
void GuiEditCtrl::deleteSelection(void)
{
Vector<GuiControl *>::iterator i;
for(i = mSelectedControls.begin(); i != mSelectedControls.end(); i++)
{
SimObject *obj = (*i);
if( obj )
obj->deleteObject();
}
mSelectedControls.clear();
}
void GuiEditCtrl::loadSelection(const char* filename)
{
if (! mCurrentAddSet)
mCurrentAddSet = mContentControl;
Con::executef(2, "exec", filename);
SimSet *set;
if(!Sim::findObject("guiClipboard", set))
return;
if(set->size())
{
Con::executef(this, 1, "onClearSelected");
mSelectedControls.clear();
for(U32 i = 0; i < set->size(); i++)
{
GuiControl *ctrl = dynamic_cast<GuiControl *>((*set)[i]);
if(ctrl)
{
mCurrentAddSet->addObject(ctrl);
mSelectedControls.push_back(ctrl);
Con::executef(this, 2, "onAddSelected", avar("%d", ctrl->getId()));
}
}
}
set->deleteObject();
}
void GuiEditCtrl::saveSelection(const char* filename)
{
// if there are no selected objects, then don't save
if (mSelectedControls.size() == 0)
return;
FileStream stream;
if(!ResourceManager->openFileForWrite(stream, filename))
return;
SimSet *clipboardSet = new SimSet;
clipboardSet->registerObject();
Sim::getRootGroup()->addObject(clipboardSet, "guiClipboard");
Vector<GuiControl *>::iterator i;
for(i = mSelectedControls.begin(); i != mSelectedControls.end(); i++)
clipboardSet->addObject(*i);
clipboardSet->write(stream, 0);
clipboardSet->deleteObject();
}
#ifdef TGE_RPG
void GuiEditCtrl::copySelection()
{
if (mSelectedControls.size() == 0)
return;
SimSet *clipboardSet;
clipboardSet = dynamic_cast<SimSet *>( Sim::getRootGroup()->findObject( "UIEditorClipboard"));
if(clipboardSet)
clipboardSet->deleteObject();
{
clipboardSet = new SimSet;
clipboardSet->registerObject();
Sim::getRootGroup()->addObject(clipboardSet, "UIEditorClipboard");
}
Vector<GuiControl *>::iterator i;
SimObject* pNew;
for(i = mSelectedControls.begin(); i != mSelectedControls.end(); i++)
{
pNew = (*i)->duplicate(true,false);
//缓存中数据不需要注册 registerObject
clipboardSet->addObject(pNew);
}
}
void GuiEditCtrl::parseSelection()
{
if (! mCurrentAddSet)
mCurrentAddSet = mContentControl;
SimSet *set;
set = dynamic_cast<SimSet *>( Sim::getRootGroup()->findObject( "UIEditorClipboard"));
if(set == NULL)
return;
if(set->size())
{
SimObject* pNew;
GuiControl* pCtrlNew;
Con::executef(this, 1, "onClearSelected");
mSelectedControls.clear();
for(U32 i = 0; i < set->size(); i++)
{
GuiControl *ctrl = dynamic_cast<GuiControl *>((*set)[i]);
if(ctrl)
{
pNew = ctrl->duplicate(true,true);
pCtrlNew = dynamic_cast<GuiControl *>(pNew);
if(pCtrlNew)
{
//pCtrlNew->registerObject();
mCurrentAddSet->addObject(pCtrlNew);
mSelectedControls.push_back(pCtrlNew);
Con::executef(this, 2, "onAddSelected", avar("%d", pCtrlNew->getId()));
}
else
{
pNew->deleteObject();
}
}
}
}
//set->deleteObject();
}
#endif
void GuiEditCtrl::selectAll()
{
GuiControl::iterator i;
if (!mCurrentAddSet)
return;
Con::executef(this, 1, "onClearSelected");
mSelectedControls.clear();
for(i = mCurrentAddSet->begin(); i != mCurrentAddSet->end(); i++)
{
GuiControl *ctrl = dynamic_cast<GuiControl *>(*i);
if (!(ctrl->isLocked())) {
mSelectedControls.push_back(ctrl);
Con::executef(this, 2, "onAddSelected", avar("%d", ctrl->getId()));
}
}
}
void GuiEditCtrl::bringToFront()
{
if (mSelectedControls.size() != 1)
return;
GuiControl *ctrl = *(mSelectedControls.begin());
mCurrentAddSet->pushObjectToBack(ctrl);
}
void GuiEditCtrl::pushToBack()
{
if (mSelectedControls.size() != 1)
return;
GuiControl *ctrl = *(mSelectedControls.begin());
mCurrentAddSet->bringObjectToFront(ctrl);
}
bool GuiEditCtrl::onKeyDown(const GuiEvent &event)
{
if (! mActive)
return Parent::onKeyDown(event);
if (!(event.modifier & SI_CTRL))
{
switch(event.keyCode)
{
case KEY_BACKSPACE:
case KEY_DELETE:
#ifdef TGE_RPG
deleteSelection();
Con::executef(this,1,"onDelete");
#else
Con::executef(this,1,"onDelete");
deleteSelection();
#endif
return true;
}
}
return false;
}
class GuiEditorRuler : public GuiControl {
StringTableEntry refCtrl;
typedef GuiControl Parent;
public:
void onPreRender()
{
setUpdate();
}
void onRender(Point2I offset, const RectI &updateRect)
{
dglDrawRectFill(updateRect, ColorF(1,1,1,1));
GuiScrollCtrl *ref;
SimObject *o = Sim::findObject(refCtrl);
//Sim::findObject(refCtrl, &ref);
ref = dynamic_cast<GuiScrollCtrl *>(o);
Point2I choffset(0,0);
if(ref)
choffset = ref->getChildPos();
if(mBounds.extent.x > mBounds.extent.y)
{
// it's horizontal.
for(U32 i = 0; i < mBounds.extent.x; i++)
{
S32 x = offset.x + i;
S32 pos = i - choffset.x;
if(!(pos % 10))
{
S32 start = 6;
if(!(pos %20))
start = 4;
if(!(pos % 100))
start = 1;
dglDrawLine(x, offset.y + start, x, offset.y + 10, ColorF(0,0,0,1));
}
}
}
else
{
// it's vertical.
for(U32 i = 0; i < mBounds.extent.y; i++)
{
S32 y = offset.y + i;
S32 pos = i - choffset.y;
if(!(pos % 10))
{
S32 start = 6;
if(!(pos %20))
start = 4;
if(!(pos % 100))
start = 1;
dglDrawLine(offset.x + start, y, offset.x + 10, y, ColorF(0,0,0,1));
}
}
}
}
static void initPersistFields()
{
Parent::initPersistFields();
addField("refCtrl", TypeString, Offset(refCtrl, GuiEditorRuler));
}
DECLARE_CONOBJECT(GuiEditorRuler);
};
IMPLEMENT_CONOBJECT(GuiEditorRuler);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -