Cpper
C/C++高级工程师 Android高级软件工程师 IT集成工程师 音频工程师 熟悉c,c++,java,c#,py,js,asp等多种语言 程序猿
主要解决了很多故障,增加了一点功能
API上参考了Qt
  1. 支持png格式
  2. 支持控件序列化,反序列化
  3. 支持换肤
  4. 代码整洁,风格良好
  5. 提供StackLayout,BoxLayout,GridLayout,FlowLayout
  6. 提供CheckBox,Panel,StaticText,ImageBox,ProgressBar,TableWidget,Slider,EditFiled,Combox等常用控件

截图如下:


例子1

#include <BGE/All>

using namespace bge;

class Dispatcher : public SlotHolder
{
public:
    Dispatcher(ImageBox
* image,Button* button)
    {
        image_ 
= image;
        button_ 
= button;
        count_ 
= 1;
    }

    
void click()
    {
        std::
string file = ":box/side";
        file 
+= toString(count_);
        file 
+= ".png";
        image_
->setImage(file);
        count_ 
++;
        
if(count_ == 7)
            count_ 
= 1;
    }
private:
    ImageBox
* image_;
    Button
* button_;
    
int count_;
};

int main(int argc,char* argv[])
{
    FileSystem::instance().initial(argv[
0]);
    FileSystem::instance().setResourcePackage(
"data.zip");
    WindowManager::instance().initialize(
":accid.ttf",false);

    Device
* device = Device::create();
    device
->initial();
    device
->createWindow(640,480,String("BGE Window"));

    Panel
* panel = new Panel();
    panel
->setPosition(Vector2f(20,20));
    panel
->setSize(Vector2f(128,128+24));

    ImageBox
* image = new ImageBox();
    image
->setImage(":box/side6.png");
    image
->setPosition(Vector2f(0,0));
    image
->setSize(Vector2f(128,128));

    Button
* button = new Button();
    button
->loadAppearance(":buttonskin1.xml");
    button
->setSize(Vector2f(128,24));
    button
->setText(L"Click");

    Dispatcher dispacher(image,button);
    button
->clicked.connect(&dispacher,&Dispatcher::click);

    BoxLayout
* layout = new BoxLayout();
    layout
->setSpacing(.0f);
    panel
->setLayout(layout);
    layout
->setJustification(Orientation_vertical);
    layout
->addWindow(image);
    layout
->addWindow(button);

    panel
->adjust();

    WindowManager::instance().addWindow(panel);

    
while(device->isRunning())
    {
        device
->preRender();

        WindowManager::instance().update();

        device
->swapBuffers();
        device
->pollEvents();
    }

    WindowManager::instance().terminate();
    device
->closeWindow();
    device
->terminate();
    device
->deleteLater();
    
return 0;
}
例子2
#include <BGE/All>

using namespace bge;

class Dispatcher : public SlotHolder
{
public:
    Dispatcher(StackLayout
* layout,Button* button)
    {
        layout_ 
= layout;
        button_ 
= button;
        count_ 
= 0;
    }

    
void click()
    {
        layout_
->setCurrentIndex(count_);
        count_ 
++;
        
if(count_ > 5)
            count_ 
= 0;
    }
private:
    StackLayout
* layout_;
    Button
* button_;
    
int count_;
};

int main(int argc,char* argv[])
{
    FileSystem::instance().initial(argv[
0]);
    FileSystem::instance().setResourcePackage(
"data.zip");
    WindowManager::instance().initialize(
":accid.ttf",false);

    Device
* device = Device::create();
    device
->initial();
    device
->createWindow(640,480,String("BGE Window"));

    Panel
* panel = new Panel();
    panel
->setPosition(Vector2f(20,20));
    panel
->setSize(Vector2f(128,128+24));

    Panel
* stackPanel = new Panel();
    stackPanel
->setSize(Vector2f(128,128));

    StackLayout
* stackLayout = new StackLayout();
    stackPanel
->setLayout(stackLayout);
    stackLayout
->setSpacing(.0f);
    
for(int i=1;i<7;i++)
    {
        ImageBox
* image = new ImageBox();
        std::
string file = ":box/side";
        file 
+= toString(i);
        file 
+= ".png";
        image
->setImage(file);
        image
->setPosition(Vector2f(0,0));
        image
->setSize(Vector2f(128,128));
        stackLayout
->insertWindow(i,image);
    }

    Button
* button = new Button();
    button
->loadAppearance(":buttonskin1.xml");
    button
->setSize(Vector2f(128,24));
    button
->setText(L"Click");

    Dispatcher dispacher(stackLayout,button);
    button
->clicked.connect(&dispacher,&Dispatcher::click);

    BoxLayout
* layout = new BoxLayout();
    layout
->setSpacing(.0f);
    panel
->setLayout(layout);
    layout
->setJustification(Orientation_vertical);
    layout
->addWindow(stackPanel);
    layout
->addWindow(button);

    panel
->adjust();

    WindowManager::instance().addWindow(panel);

    
while(device->isRunning())
    {
        device
->preRender();

        WindowManager::instance().update();

        device
->swapBuffers();
        device
->pollEvents();
    }

    WindowManager::instance().terminate();
    device
->closeWindow();
    device
->terminate();
    device
->deleteLater();
    
return 0;
}
这2个显示效果完全一样
欢迎下载







在这里下载:
http://download.csdn.net/detail/ccsdu2004/9464121

代码有点大 这里放不下

posted on 2016-03-17 11:13 ccsdu2009 阅读(1725) 评论(1)  编辑 收藏 引用 所属分类: Game引擎编程基础
Comments
  • # re: BGE GUI升级
    zhouxiang
    Posted @ 2016-04-14 10:36
    小弟也准备开发gui库,可以苦于没有例子,希望给封源码学习学习。

    better@geekzhou.uu.me  回复  更多评论   

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理