Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I make a 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:

Edit: 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.

like image 763
Paige Ruten Avatar asked Aug 11 '08 02:08

Paige Ruten


People also ask

Is it easy to make a GUI?

Creating a simple graphical user interface (GUI) that works across multiple platforms can be complicated. But it doesn't have to be that way. You can use Python and the PySimpleGUI package to create nice-looking user interfaces that you and your users will enjoy!

How do I make a GUI in Python?

Tkinter is a Python Package for creating GUI applications. Python has a lot of GUI frameworks, but Tkinter is the only framework that's built into the Python standard library. Tkinter has several strengths; it's cross-platform, so the same code works on Windows, macOS, and Linux.

What programming language is used for GUI?

Java GUI. Since one of Java's focuses is to be cross-platform, the GUI packages available work on most Java-enabled devices. The two main packages available for Java GUI applications are AWT (now depreciated/not-recommended), and Swing.

Can you make GUI with C++?

To develop C++ GUI or C++ graphical user interface application, you need an IDE that supports the C++ GUI application. To create the GUI app, you must use Visual Studio 2019 because it is better suited for the C++ GUI application.


1 Answers

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

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();
    ...
}

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.

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.

Hope this helps.

thing2k

like image 113
thing2k Avatar answered Oct 06 '22 19:10

thing2k