(C++) implementing a subdevidable tiling interface like Blender's

so, im thincking about implementing a ‘blender like’ tiling window manager.

when started there would be a single tile, which can be sub divided eather horizontally or vertically. creating two tiles, these tiles can then be subdivided into 2 and so on.

I’m having trouble thinking of a way to implement this, currently my only idea is to create a class which contains two tiles, one of which can be hidden if the window isn’t subdivided, and having an instance of that same class within itself, this , however doesn’t seam to be passable.

You might look at how Blender does it. I assume its probably done in C, but its probably quite readable.

My initial thought is a Manager scheme:

You have a master class, the ‘Tile Manager’ which holds pointers to all the tiles (you’ll probably use a vector or array for this, though some other mapping may be suitable as well). Its the ‘top level’ view element. You then have a separate tile class that’s responsible for whatever goes on inside a tile.

More in detail:

The Tile Manager is responsible for drawing borders around tiles. It intercepts all events destined for tiles. For Example, if it detects a click (or whatever you so choose) on a boundary it enters a resize state, detects which of the tiles need updating and puts them in a resize state. The user can then resize by moving the mouse, etc. When the mouse is clicked again, the appropriate tiles exit the resize state and the tile manager exits the resize state. You’ll have to decide what to do at corners.

On a draw update, you just redraw borders (you probably don’t really need to do this unless in a resize state or for some reason borders change), and then tell each tile to redraw itself. The main data that will be passed between the manager and a tile are bound/coordinate information and interface/control events. They shouldn’t be concerned with what each other is drawing.

It’ll need more finessing than that, but a lot of what actually needs to happen and what tools you’re using will determine where exactly to delegate certain things. In principle its just designing a FSM really (like most programming things are).

Do you plan on using OpenGL to draw, or devising some other method? If OpenGL, you’ll want to look into how to handle multiple viewports and also consider what’s going to handle border drawing, etc.

Unless use of C++ is mandatory to meet the project specifications, I would use Python / wxPython.

It comes with a nice browseable set of demos. The Demo More Windows/Controls -> DynamicSashWindow already does what you want.

If you are the only person working on this project, then you need to code fast rather than fast code.

And if you are still not convinced, just use C++ and wxWindows. After all, wxWindows is a C++ library and wxPython is just a Python binding for it. :wink:

Attachments


You might look at how Blender does it. I assume its probably done in C, but its probably quite readable.

good idea, dose anyone here know what source file the tiling code is in?
Im not intending to use OpenGL, just X11, and even that will be kept to a minimum. graphicly im not aiming for anything more advanced than DWM, without the bar at the top;)

Unless use of C++ is mandatory to meet the project specifications, I would use Python / wxPython.

It comes with a nice browseable set of demos. The Demo More Windows/Controls -> DynamicSashWindow already does what you want.

If you are the only person working on this project, then you need to code fast rather than fast code.

And if you are still not convinced, just use C++ and wxWindows. After all, wxWindows is a C++ library and wxPython is just a Python binding for it.

you may have miss understood what im trying to do. Im not trying to Wright an app that tiles its interface. What im trying to program is a X11 tiling window manager, the program that controls how the windows of running applications are displayed. unless WX is able to output coordinates for the x/y location and width/height of each tile, it wouldn’t be much use.

Im aiming for something simmaler to DWM, i.e. as minimal as possible, but that lets you divide up the interface manually like Blender. the reason for choosing C/C++ is because I already have a working knowledge of it, learning how window managers work is a large enough task on its own, without the added problem of learning a new programming language :slight_smile:

#include<cstdio>
#include<iostream>

using namespace std;

struct vector2d
{
    int x;
    int y;
};

class tile
{
    int     sub_1_width;
    int     sub_1_height;

    int     sub_2_width;
    int     sub_2_height;

    bool    direction;

    tile     *tile_1;
    tile     *tile_2;
    tile     *parent;
public:
    tile()
    {
        tile_1 = NULL;
        tile_2 = NULL;

        sub_1_width = 7;
    }

    tile(tile *parent_tile)
    {
        parent = parent_tile;
    }
// end of constructors

    tile *get_parent()
    {
        return parent;
    }

// get
    vector2d get_size(int subtile) 
    {
        vector2d size;

        if(subtile == 0)
        {
            size.x = sub_1_width;
            size.y = sub_1_height;
        }
        else
        {
            size.x = sub_2_width;
            size.y = sub_2_height;
        }
        return size;
    }
};

int main()
{
    tile *tile_list;
    tile_list = new tile(tile_list);
        
    tile dd = tile_list -> get_parent();
    cout<<dd. get_size(0).x<<endl;
}

Ive created this code for starting to implement the interface as a linked list, what it should do is create an instance of the tile class, and set the parent pointer to point to the same instance of the class(so when I add more elements to the list, I can easily pass them a pointer to there parent object). Then it should set ‘dd’ to be an copy of the first class, and return the x size of the first subtle, using the parent pointer, which should be 7, however it prints ‘65535’, any help would be appreciated.

there are already such things.
for example: http://modeemi.fi/~tuomov/ion/

.b

I know there are already window managers which behave like that. This is more of a learning exsasize to improve my knowledge of programming.
Anyone know what im doing wrong with the pointers in the above code? thanks.

You do see that get_parent() is returning a pointer. Right now, you’re assigning it as a tile object, not as a pointer to a tile object. Try fixing that and seeing if anything weird comes out…

now its returning ‘-1076779032’
only thing I can think of is if the ‘parent’ pointer isn’t actually getting set to point to the same object its contained in, but some other memory location.

int main()
{
    tile *tile_list;// (1)
    tile_list = new tile(tile_list); //the tile_list as argument doesn't point to anything good (2)
   //Furthermore why should a tile be its parent? Why should a tile list be a parent of a tile_list?
        
    //tile dd = tile_list -> get_parent(); //wrong invalid conversion from type tile* to tile.
    tile dd = *( tile_list -> get_parent() );
    cout<<dd.get_size(0).x<<endl;
}

‘dd’ is the copy of the memory block at the adress pointed by tile_list at (1). That memory is probably uninitialised and can possibly be out of the memory allocated to your program. In the best case, an operation on dd will give undefined behaviour (65535) at worst you’ll get a segfault.
In your code, you’ll have a leak since there’s no deleting of the tile allocated in (2), except when the program finishes, but if you’re programming a window manager, you’ll probably want to adress that.

int main()
{
    tile base_tile();
    tile tile_list(&base_tile);
    tile dd = *( tile_list.get_parent() );
    cout<<dd.get_size(0).x<<endl;
}

Dani