// UILayoutEditorDoc.cpp : UILayoutEditorDoc 类的实现
//
#include "stdafx.h"
#include "MainFrm.h"
#include "UILayoutEditor.h"
#include "UILayoutEditorDoc.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// UILayoutEditorDoc
IMPLEMENT_DYNCREATE(UILayoutEditorDoc, CDocument)
BEGIN_MESSAGE_MAP(UILayoutEditorDoc, CDocument)
END_MESSAGE_MAP()
#define NULL_WINDOW_MSG _T("Window may not be NULL here!")
#define DELETE_ROOT_WARNING _T("You can't delete the 'root' window.")
#define NO_BACKGROUND_WARNING _T("There is currently no mapping loaded for a StaticImage. Therefore it is not possible to set a background image.")
#define ADD_WINDOW_HELPER 4
// UILayoutEditorDoc 构造/析构
UILayoutEditorDoc::UILayoutEditorDoc()
{
d_background = NULL;
d_rootLayout = NULL;
d_hoveredWindow = NULL;
d_commandProcessor = NULL;
}
UILayoutEditorDoc::~UILayoutEditorDoc()
{
}
Selection* UILayoutEditorDoc::GetSelection()
{
return &d_selection;
}
CopiedSelection* UILayoutEditorDoc::GetCopiedSelection()
{
return &d_copyselection;
}
void UILayoutEditorDoc::SelectionCut()
{
SelectionCopy();
SelectionDelete();
}
void UILayoutEditorDoc::SelectionCopy()
{
d_copyselection.Reset();
for (Selection::Boxes::iterator boxIt = d_selection.GetAllBoxes().begin(); boxIt != d_selection.GetAllBoxes().end(); ++boxIt)
{
d_copyselection.Copy(boxIt->GetWindow());
}
}
void UILayoutEditorDoc::SelectionPaste()
{
if (d_selection.Size())
{
d_copyselection.Paste(d_selection.GetAllBoxes().begin()->GetWindow());
}
else
{
d_copyselection.Paste(d_rootLayout);
}
for (size_t i = 0; i < observers.size(); ++i)
{
observers [i]->WindowAdded(NULL);
}
}
void UILayoutEditorDoc::SelectionDelete()
{
while (d_selection.Size() > 0)
{
if (!RemoveWindow(d_selection.GetAllBoxes().begin()->GetWindow(), d_selection.Size() == 1))
{
break;
}
}
if (d_rootLayout)
{
SelectWindow(d_rootLayout);
}
}
CEGUI::Window* UILayoutEditorDoc::AddWindow(CEGUI::Window* pParentWindow, CEGUI::String strType, CEGUI::String strName)
{
if (!pParentWindow) return NULL;
if(strName.empty() )
{
strName = strType.substr(strType.find_last_of("/") + 1);
}
int nCounter = 1;
CEGUI::String newName = strName;
while (CEGUI::WindowManager::getSingleton().isWindowPresent(newName))
{
char szBuf[32];
sprintf_s(szBuf, _T("%06d"), nCounter++);
CEGUI::String tmp(szBuf);
newName = strName + tmp;
}
try
{
CEGUI::Window *newWindow = AddNewWindow(pParentWindow, strType, newName);
//aParentWindow->addChildWindow (newWindow);
for (size_t i = 0; i < observers.size(); ++i)
{
observers [i]->WindowAdded(newWindow);
}
SelectWindow (newWindow);
Modify(true);
return newWindow;
}
catch (...)
{
return NULL;
}
}
bool UILayoutEditorDoc::RemoveWindow(CEGUI::Window* aWindow, bool notifyListeners)
{
if (aWindow == d_rootLayout)
{
AfxMessageBox("不能删除根窗口!");
return false;
}
if(d_hoveredWindow == aWindow) d_hoveredWindow = NULL;
d_selection.Unselect(aWindow);
CEGUI::WindowManager::getSingletonPtr()->destroyWindow(aWindow);
if (notifyListeners)
{
for (size_t i = 0; i < observers.size(); ++i)
{
observers [i]->WindowsRemoved();
}
}
Modify(true);
return true;
}
void UILayoutEditorDoc::SelectWindow(CEGUI::Window* aWindow, bool resetSelection)
{
ASSERT(aWindow != NULL);
if (d_selection.IsSelected(aWindow) && resetSelection) return;
if (resetSelection)
{
d_selection.ClearSelection();
}
CEGUI::Window* newSelectedWindow = NULL;
if (d_selection.Select(aWindow))
{
newSelectedWindow = aWindow;
if (RequiresLock(aWindow))
{
d_selection.FindBoxFor(aWindow)->Lock();
}
}
else
{
if (d_selection.Size() > 0)
{
newSelectedWindow = d_selection.GetAllBoxes().begin()->GetWindow();
}
}
for (size_t i = 0; i < observers.size() && newSelectedWindow != NULL; ++i)
{
observers [i]->WindowSelected (newSelectedWindow);
}
if (newSelectedWindow != NULL && !newSelectedWindow->isVisible ())
{
CEGUI::Window* currWindow = newSelectedWindow;
while (currWindow && !currWindow->isVisible())
{
if (currWindow->getParent() && currWindow->getParent()->getName().find((CEGUI::utf8*)"__auto_TabPane__") != CEGUI::String::npos)
{
CEGUI::Window *newWin = 0;
unsigned int size = currWindow->getParent()->getChildCount();
for (size_t i = 0; i < size; i++)
{
currWindow->getParent()->getChildAtIdx(i)->setVisible(false);
}
size = currWindow->getChildCount();
for (size_t i = 0; i < size; i++)
{
currWindow->getChildAtIdx(i)->setVisible(true);
}
}
currWindow->setVisible(true);
currWindow = currWindow->getParent();
}
}
theApp.d_pMainFrame->Refresh();
}
bool UILayoutEditorDoc::RequiresLock(CEGUI::Window* aWindow)
{
return (aWindow->testClassName("MenuItem") || aWindow == d_rootLayout && (aWindow->testClassName((CEGUI::utf8*)"DefaultWindow")) || (aWindow->testClassName((CEGUI::utf8*)"DefaultWindow") && aWindow->getParent() && aWindow->getParent()->getType().find("TabContentPane") != CEGUI::String::npos));
}
CEGUI::Window* UILayoutEditorDoc:: AddNewWindow(CEGUI::Window* aParentWindow, CEGUI::String aType, CEGUI::String aName)
{
CEGUI::Window *newWindow = CEGUI::WindowManager::getSingleton().createWindow(aType, aName);
if (newWindow->testClassName("TabControl"))
{
InitTabControl(newWindow);
}
else if (newWindow->testClassName("Menubar"))
{
InitMenubar(newWindow);
}
else if(newWindow->testClassName("DragContainerSlot") || newWindow->testClassName("DragMovingAnchor"))
{
((CEGUI::PropertySet*)newWindow)->setProperty("BackgroundEnabled","True");
((CEGUI::PropertySet*)newWindow)->setProperty("FrameEnabled","True");
}
if (newWindow->testClassName("MenuItem"))
{
newWindow->setText("MenuItem");
if (aParentWindow->testClassName("MenuItem"))
{
CEGUI::PopupMenu* popup = NULL;
if (!((CEGUI::MenuItem*)aParentWindow)->getPopupMenu())
{
CEGUI::String look = newWindow->getLookNFeel().substr(0, newWindow->getLookNFeel().find_first_of("/"));
popup = (CEGUI::PopupMenu*)CEGUI::WindowManager::getSingleton().createWindow(look + CEGUI::String("/PopupMenu"), aParentWindow->getName() + "/AutoPopup");
((CEGUI::MenuItem*)aParentWindow)->setPopupMenu(popup);
}
else
{
popup = ((CEGUI::MenuItem*)aParentWindow)->getPopupMenu();
}
popup->addChildWindow(newWindow);
}
else
{
aParentWindow->addChildWindow (newWindow);
}
}
else
{
aParentWindow->addChildWindow (newWindow);
}
if (newWindow->testClassName("Menubar"))
{
newWindow->setPosition(CEGUI::UVector2(CEGUI::UDim(0.0f, 0.0), CEGUI::UDim(0.12f, 0.0)));
newWindow->setSize(CEGUI::UVector2(CEGUI::UDim(1.0f, 0.0), CEGUI::UDim(0.1f, 0.0)));
}
else if (newWindow->testClassName("DefaultWindow") && aParentWindow->testClassName("TabControl"))
{
newWindow->setText("Tab");
newWindow->setSize(CEGUI::UVector2(CEGUI::UDim(1.0f, 0.0), CEGUI::UDim(1.0f, 0.0)));
}
else if (!newWindow->testClassName("MenuItem"))
{
float newStartXY = 0.2 + ((aParentWindow->getChildCount() ? aParentWindow->getChildCount() : 1) % ADD_WINDOW_HELPER) * 0.1f;
newWindow->setPosition(CEGUI::UVector2(CEGUI::UDim(newStartXY, 0.0), CEGUI::UDim(newStartXY, 0.0)));
newWindow->setSize(CEGUI::UVector2(CEGUI::UDim(1.0f / ADD_WINDOW_HELPER, 0.0), CEGUI::UDim(1.0f / ADD_WINDOW_HELPER, 0.0)));
}
CString defaultFont = Options::GetInstancePtr()->GetDefaultFont();
if (defaultFont != _T(""))
{
newWindow->setProperty((CEGUI::utf8*)"Font", defaultFont.GetString());
if (newWindow->isPropertyPresent((CEGUI::utf8*)"TitlebarFont"))
{
newWindow->setProperty((CEGUI::utf8*)"TitlebarFont", defaultFon
没有合适的资源?快使用搜索试试~ 我知道了~
MFC重写的CEGUI界面编辑器
共52个文件
h:24个
cpp:20个
ico:2个
4星 · 超过85%的资源 需积分: 17 213 下载量 114 浏览量
2014-11-29
00:33:20
上传
评论 3
收藏 101KB ZIP 举报
温馨提示
博文http://blog.csdn.net/ljxfblog/article/details/41580251配套代码,用MFC重写的CEGUI界面编辑器,现在开源。
资源推荐
资源详情
资源评论
收起资源包目录
UILayoutEditor.zip (52个子文件)
UILayoutEditor
UILayoutEditor
CommandAddWindow.cpp 4KB
stdafx.cpp 147B
WindowContext.cpp 3KB
Selection.cpp 6KB
EditorCanvas.cpp 13KB
WindowContext.h 4KB
EditorCanvas.h 2KB
res
UILayoutEditor.rc2 370B
Toolbar.bmp 2KB
smallicon.bmp 2KB
UILayoutEditor.ico 9KB
UILayoutEditorDoc.ico 1KB
stdafx.h 2KB
UILayoutEditor.rc 32KB
CopiedSelection.h 5KB
IDocumentObserver.h 3KB
Selection.h 5KB
UILayoutEditor.cpp 5KB
CommandAddWindow.h 4KB
Resource.H 3KB
CommandProcessor.h 3KB
targetver.h 234B
INIFile.cpp 13KB
WindowBox.h 6KB
Options.cpp 10KB
ImageSelectDlg.cpp 6KB
UILayoutEditor.h 717B
UILayoutEditorView.cpp 4KB
GirdDialog.cpp 2KB
UILayoutEditorDoc.cpp 30KB
CreateWndView.h 2KB
ImageSelectDlg.h 799B
UILayoutEditorDoc.h 4KB
Options.h 10KB
UILayoutEditorView.h 1KB
CreateWndView.cpp 12KB
MainFrm.cpp 23KB
INIFile.h 8KB
MainFrm.h 3KB
SelectionMover.h 3KB
GirdDialog.h 523B
SelectionMover.cpp 11KB
MainInfoView.cpp 24KB
StringConv.h 211B
FontDialog.cpp 1KB
CopiedSelection.cpp 10KB
WindowBox.cpp 8KB
FontDialog.h 795B
MainInfoView.h 4KB
StringConv.cpp 508B
Build
UILayoutEditor.vcxproj 12KB
UILayoutEditor.vcxproj.filters 6KB
共 52 条
- 1
帘卷西风
- 粉丝: 443
- 资源: 58
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
前往页