Implementation

This page describes the implementation of the main menus and the toolbox in Blender. Both menu systems have in common that they are build using the Blender button widgets and ui blocks.

Main menus

The main menu system is created in the file header_buttons.c.
The menu bar is created in the routine void info_buttons() which creates the main menu bar items as part of the info buttons usually located at the top of the main window of Blender.

For example, this is how the file menu item is created inside the void info_buttons() routine:

but=uiDefBut(block, BLOCK, B_NOP, "File", xco, 3, 40, 15, NULL, 0.0, 0.0, 0, 0, "");
but->blockfunc= info_filemenu;

A button of BLOCK type is created with the info_filemenu block routine. This routine creates the file menu by creating a new ui block with menu items as buttons:

uiBlock *info_filemenu()
{
uiBlock *block;
int xco=0;

block= uiNewBlock(&curarea->uiblocks, "filemenu", UI_EMBOSSP, UI_HELV, 0x808080, curarea->headwin);
block->func= do_info_filemenu;

uiDefBut(block, BUTM, 1, "New|Ctrl X", 0, xco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "");
uiDefBut(block, BUTM, 1, "Open|F1", 0, xco-=20, 160, 19, NULL, 0.0, 0.0, 1, 1, "");
uiDefBut(block, BUTM, 1, "Reopen Last|Ctrl O", 0, xco-=20, 160, 19, NULL, 0.0, 0.0, 1, 2, "");
uiDefBut(block, BUTM, 1, "Append|Shift F1", 0, xco-=20, 160, 19, NULL, 0.0, 0.0, 1, 3, "");
uiDefBut(block, SEPR, 0, "", 0, xco-=6, 160, 6, NULL, 0.0, 0.0, 0, 0, "");
uiDefBut(block, BUTM, 1, "Save As|F2", 0, xco-=20, 160, 19, NULL, 0.0, 0.0, 1, 4, "");
uiDefBut(block, BUTM, 1, "Save|Ctrl W", 0, xco-=20, 160, 19, NULL, 0.0, 0.0, 1, 5, "");
uiDefBut(block, SEPR, 0, "", 0, xco-=6, 160, 6, NULL, 0.0, 0.0, 0, 0, "");
uiDefBut(block, BUTM, 1, "Save Image|F3", 0, xco-=20, 160, 19, NULL, 0.0, 0.0, 1, 6, "");
uiDefBut(block, BUTM, 1, "Save VRML|Ctrl F2", 0, xco-=20, 160, 19, NULL, 0.0, 0.0, 1, 7, "");
uiDefBut(block, BUTM, 1, "Save DXF|Shift F2", 0, xco-=20, 160, 19, NULL, 0.0, 0.0, 1, 8, "");
uiDefBut(block, BUTM, 1, "Save VideoScape|Alt W", 0, xco-=20, 160, 19, NULL, 0.0, 0.0, 1, 9, "");
uiDefBut(block, SEPR, 0, "", 0, xco-=6, 160, 6, NULL, 0.0, 0.0, 1, 0, "");
uiDefBut(block, BUTM, 1, "Quit | Q", 0, xco-=20, 160, 19, NULL, 0.0, 0.0, 1, 10, "");

block->direction= UI_DOWN;

return block;
}

 

Toolbox