#include <BGE/All>
using namespace bge;
Window* createButton(const std::string& name,const String& text)
{
Button* button = new Button(0,text);
button->setName(name);
button->setSize(Vector2f(92,42));
return button;
}
int main(int argc, char* argv[])
{
FileSystem::instance().initial(argv[0]);
FileSystem::instance().setResourcePackage("data.zip");
WindowManager::instance().initialize("simkai.ttf",false);
Device* device = Device::create();
device->initial();
device->createWindow(640,480,bge::String("BGE Window"));
Panel* panel = new Panel(FloatRect(30,30,192,180),0);
GridLayout* layout = new GridLayout();
panel->setLayout(layout);
std::vector<float> widths;
widths.push_back(0.0f);
layout->setColumnWidths(widths);
std::vector<float> heights;
for(int k = 0; k < 3; ++k)
heights.push_back(48.0f);
heights.push_back(0.0f);
layout->setRowHeights(heights);
GridCellInfo info;
info.columnIndex_ = 0; info.rowIndex_ = 0; layout->addWindow(createButton("button1",L"按键"),info);
info.columnIndex_ = 1; info.rowIndex_ = 0; layout->addWindow(createButton("button2",L"按键"),info);
info.columnIndex_ = 0; info.rowIndex_ = 1; layout->addWindow(createButton("button3",L"按键"),info);
info.columnIndex_ = 1; info.rowIndex_ = 1; layout->addWindow(createButton("button4",L"按键"),info);
info.columnIndex_ = 0;
info.rowIndex_ = 2;
info.horizontalSpan_ = 2;
Window* edit = new EditField(NULL,L"Edit Text");
edit->setSize(Vector2f(196,36));
layout->addWindow(edit,info);
info.columnIndex_ = 0;
info.rowIndex_ = 3;
info.horizontalSpan_ = 3;
layout->arrangeWithin();
FrameWindow* window = new FrameWindow();
window->enableMovement();
window->setText(L"BGE窗体");
window->setClientPanel(panel);
WindowManager::instance().addWindow(window);
while(device->isRunning())
{
device->preRender();
WindowManager::instance().update();
device->swapBuffers();
device->pollEvents();
}
WindowManager::instance().terminate();
device->closeWindow();
device->terminate();
device->deleteLater();
return 0;
}
using namespace bge;
Window* createButton(const std::string& name,const String& text)
{
Button* button = new Button(0,text);
button->setName(name);
button->setSize(Vector2f(92,42));
return button;
}
int main(int argc, char* argv[])
{
FileSystem::instance().initial(argv[0]);
FileSystem::instance().setResourcePackage("data.zip");
WindowManager::instance().initialize("simkai.ttf",false);
Device* device = Device::create();
device->initial();
device->createWindow(640,480,bge::String("BGE Window"));
Panel* panel = new Panel(FloatRect(30,30,192,180),0);
GridLayout* layout = new GridLayout();
panel->setLayout(layout);
std::vector<float> widths;
widths.push_back(0.0f);
layout->setColumnWidths(widths);
std::vector<float> heights;
for(int k = 0; k < 3; ++k)
heights.push_back(48.0f);
heights.push_back(0.0f);
layout->setRowHeights(heights);
GridCellInfo info;
info.columnIndex_ = 0; info.rowIndex_ = 0; layout->addWindow(createButton("button1",L"按键"),info);
info.columnIndex_ = 1; info.rowIndex_ = 0; layout->addWindow(createButton("button2",L"按键"),info);
info.columnIndex_ = 0; info.rowIndex_ = 1; layout->addWindow(createButton("button3",L"按键"),info);
info.columnIndex_ = 1; info.rowIndex_ = 1; layout->addWindow(createButton("button4",L"按键"),info);
info.columnIndex_ = 0;
info.rowIndex_ = 2;
info.horizontalSpan_ = 2;
Window* edit = new EditField(NULL,L"Edit Text");
edit->setSize(Vector2f(196,36));
layout->addWindow(edit,info);
info.columnIndex_ = 0;
info.rowIndex_ = 3;
info.horizontalSpan_ = 3;
layout->arrangeWithin();
FrameWindow* window = new FrameWindow();
window->enableMovement();
window->setText(L"BGE窗体");
window->setClientPanel(panel);
WindowManager::instance().addWindow(window);
while(device->isRunning())
{
device->preRender();
WindowManager::instance().update();
device->swapBuffers();
device->pollEvents();
}
WindowManager::instance().terminate();
device->closeWindow();
device->terminate();
device->deleteLater();
return 0;
}
显示如下:
在开发上参考了Qt等软件,支持常见控件,控件序列化,整体换肤,控件换肤
以上代码写的相当啰嗦 其实可以这样写:
int main(int argc, char* argv[])
{
FileSystem::instance().initial(argv[0]);
FileSystem::instance().setResourcePackage("data.zip");
WindowManager::instance().initialize("simkai.ttf",false);
Device* device = Device::create();
device->initial();
device->createWindow(640,480,bge::String("BGE Window"));
Window* window = WindowManager::instance().createWindow("ui.xml");
if(window)
WindowManager::instance().addWindow(window);
while(device->isRunning())
{
device->preRender();
WindowManager::instance().update();
device->swapBuffers();
device->pollEvents();
}
WindowManager::instance().terminate();
device->closeWindow();
device->terminate();
device->deleteLater();
return 0;
}
{
FileSystem::instance().initial(argv[0]);
FileSystem::instance().setResourcePackage("data.zip");
WindowManager::instance().initialize("simkai.ttf",false);
Device* device = Device::create();
device->initial();
device->createWindow(640,480,bge::String("BGE Window"));
Window* window = WindowManager::instance().createWindow("ui.xml");
if(window)
WindowManager::instance().addWindow(window);
while(device->isRunning())
{
device->preRender();
WindowManager::instance().update();
device->swapBuffers();
device->pollEvents();
}
WindowManager::instance().terminate();
device->closeWindow();
device->terminate();
device->deleteLater();
return 0;
}
做这个不为别的就是想做
现在有点小问题,修改好了我会上源码
欢饮指点~