如何制作GUI? [英] How do I make a GUI?

查看:236
本文介绍了如何制作GUI?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为任天堂DS创建了一个GUI系统的许多不同的独立部分,像按钮和文本框和选择框,但我需要一种方法在一个Gui类中包含这些类,所以我可以绘制一切到同时检查所有按钮,检查是否有任何按钮被按下。我的问题是什么是最好的方式组织所有的类(如按钮和文本框)到一个GUI类?

I've made many different seperate parts of a GUI system for the Nintendo DS, like buttons and textboxes and select boxes, but I need a way of containing these classes in one Gui class, so that I can draw everything to the screen all at once, and check all the buttons at once to check if any are being pressed. My question is what is the best way organize all the classes (such as buttons and textboxes) into one GUI class?

这是一种方式,我想,但它不似乎是正确的:

Here's one way I thought of but it doesn't seem right:

编辑:我正在使用C ++。

I'm using C++.

class Gui {
    public:
        void update_all();
        void draw_all() const;
        int add_button(Button *button); // Returns button id
        void remove_button(int button_id);
    private:
        Button *buttons[10];
        int num_buttons;
}

这段代码有几个问题,但我只是想给你一个想法

This code has a few problems, but I just wanted to give you an idea of what I want.

推荐答案

这个问题很像我要发布的,只有我的是索尼PSP编程

This question is very similar to one I was going to post, only mine is for Sony PSP programming.

我已经玩了一段时间了,我已经查阅了一些书, VTMs ,到目前为止,这是一个简单的ui系统的概念。

I've been toying with something for a while, I've consulted some books and VTMs, and so far this is a rough idea of a simple ui systems.

class uiElement()
{
    ...
    virtual void Update() = 0;
    virtual void Draw() = 0;
    ...
}

class uiButton() public : uiElement
{
    ...
    virtual void Update();
    virtual void Draw();
    ...
}

class uiTextbox() public : uiElement
{
    ...
    virtual void Update();
    virtual void Draw();
    ...
}

... // Other ui Elements

class uiWindow()
{
    ...
    void Update();
    void Draw();

    void AddElement(uiElement *Element);
    void RemoveElement(uiElement *Element);

    std::list <uiElement*> Elements;

    ...
}

void uiWindow::Update()
{
    ...
    for (list <uiElement*>::iterator it = Elements.begin(); it != Elements.end(); it++ )
        it->Update();
    ...
}

void uiWindow::Draw()
{
    ...
    for (list <uiElement*>::iterator it = Elements.begin(); it != Elements.end(); it++ )
        it->Draw();
    ...
}

原则是创建一个窗口和attact ui元素,并从相应的主函数调用绘制和更新方法。

The princple is to create a window and attact ui Elements to it, and call the draw and update methods from the respective main functions.

我没有什么工作,因为我有绘图代码的问题。在PC和PSP上使用不同的API,我正在查看OpenGL和psp gu的一些包装代码。

I don't have anything working yet, as I have issues with drawing code. With different APIs on the PC and PSP, I'm looking at some wrapper code for OpenGL and psp gu.

希望这有助。

thing2k

这篇关于如何制作GUI?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆