home *** CD-ROM | disk | FTP | other *** search
- /*************************************
- * *
- * Menus v2.0 *
- * by Torsten Jürgeleit in 08/91 *
- * *
- * Test program *
- * *
- *************************************/
-
- /* Includes */
-
- #include <exec/types.h>
- #include <graphics/gfxbase.h>
- #include <graphics/text.h>
- #include <intuition/intuitionbase.h>
- #include <intuition/intuition.h>
- #include <functions.h>
- #include "/render/render.h"
- #include "/texts/texts.h"
- #include "menus.h"
-
- /* Defines */
-
- #define WINDOW_WIDTH 600
- #define WINDOW_HEIGHT 200
- #define WINDOW_TITLE (UBYTE *)" Menus test "
-
- #define RENDER_INFO_FLAGS (USHORT)(RENDER_INFO_FLAG_INNER_WINDOW | RENDER_INFO_FLAG_BACK_FILL)
- #define OPEN_WINDOW_FLAGS (USHORT)(OPEN_WINDOW_FLAG_CENTER_WINDOW | OPEN_WINDOW_FLAG_RENDER_PENS)
-
- #define MESSAGE1_TEXT "Select menu item"
- #define MESSAGE1_TOP_EDGE 60
- #define MESSAGE1_TEXT_ATTR &topaz60_attr
-
- #define MESSAGE2_TEXT "Menu no. %d menu item no. %d sub item no. %d selected"
- #define MESSAGE2_TOP_EDGE 120
- #define MESSAGE2_TEXT_ATTR &topaz80_attr
-
- /* Globals */
-
- struct IntuitionBase *IntuitionBase;
- struct GfxBase *GfxBase;
-
- /* Statics */
-
- STATIC struct NewWindow test_new_window = { 0, 0, WINDOW_WIDTH,
- WINDOW_HEIGHT, 0, 1, CLOSEWINDOW | MENUPICK, WINDOWCLOSE | WINDOWDRAG |
- WINDOWDEPTH | SMART_REFRESH | NOCAREREFRESH | ACTIVATE, NULL, NULL,
- WINDOW_TITLE, NULL, NULL, 0, 0, 0, 0, WBENCHSCREEN };
- STATIC struct TextAttr topaz80_attr = { (STRPTR)"topaz.font", TOPAZ_EIGHTY,
- FS_NORMAL, FPF_ROMFONT },
- topaz60_attr = { (STRPTR)"topaz.font", TOPAZ_SIXTY,
- FS_NORMAL, FPF_ROMFONT };
- /* Defines for test menus */
-
- #define TEST_MENU_TEXT_ATTR &topaz60_attr
-
- /* Statics for test menus */
-
- STATIC struct MenuData test_menu_data[] = {
- {
- MENU_DATA_TYPE_TITLE, 0, "Menu 0", NULL, 0
- }, {
- MENU_DATA_TYPE_ITEM, MENU_DATA_FLAG_ATTRIBUTE | MENU_DATA_FLAG_SELECTED, "Item 0.0", "0", ~(1L << 0)
- }, {
- MENU_DATA_TYPE_ITEM, MENU_DATA_FLAG_ATTRIBUTE, "Item 0.1", "1", ~(1L << 1)
- }, {
- MENU_DATA_TYPE_ITEM, MENU_DATA_FLAG_HIGH_BOX, "Item 0.2", NULL, 0
- }, {
- MENU_DATA_TYPE_SUBITEM, 0, "Item 0.2.0", "A", 0
- }, {
- MENU_DATA_TYPE_SUBITEM, 0, "Item 0.2.1", "B", 0
- }, {
- MENU_DATA_TYPE_ITEM, 0, "Item 0.3", NULL, 0
- }, {
- MENU_DATA_TYPE_TITLE, 0, "Menu 1", NULL, 0
- }, {
- MENU_DATA_TYPE_ITEM, MENU_DATA_FLAG_HIGH_BOX, "Item 1.0", "C", 0
- }, {
- MENU_DATA_TYPE_ITEM, MENU_DATA_FLAG_EMPTY_LINE, "Item 1.1", "D", 0
- }, {
- MENU_DATA_TYPE_ITEM, 0, "Item 1.2", NULL, 0
- }, {
- MENU_DATA_TYPE_SUBITEM, 0, "Item 1.2.0", "E", 0
- }, {
- MENU_DATA_TYPE_SUBITEM, 0, "Item 1.2.1", "F", 0
- }, {
- MENU_DATA_TYPE_ITEM, 0, "Item 1.3", NULL, 0
- }, {
- MENU_DATA_TYPE_SUBITEM, 0, "Item 1.3.0", "G", 0
- }, {
- MENU_DATA_TYPE_SUBITEM, MENU_DATA_FLAG_EMPTY_LINE, "Item 1.3.1", "H", 0
- }, {
- MENU_DATA_TYPE_ITEM, 0, "Item 1.4", "I", 0
- }, {
- INTUISUP_DATA_END /* mark end of menu data */
- }
- };
- /* Prototypes */
-
- VOID test_action(struct RenderInfo *ri, struct Window *win,
- struct MenuList *ml);
- /* Pragmas */
-
- #pragma regcall(test_action(a0,a1,a2))
-
- /* Menus test */
-
- LONG
- main(VOID)
- {
- struct RenderInfo *ri;
- struct Window *win;
- struct MenuList *ml;
-
- if (IntuitionBase = OpenLibrary("intuition.library", 0L)) {
- if (GfxBase = OpenLibrary("graphics.library", 0L)) {
- if (ri = get_render_info(NULL, RENDER_INFO_FLAGS)) {
- if (win = open_window(ri, &test_new_window, OPEN_WINDOW_FLAGS)) {
- print_text(ri, win, MESSAGE1_TEXT, 0, MESSAGE1_TOP_EDGE,
- TEXT_DATA_TYPE_TEXT, TEXT_DATA_FLAG_CENTER,
- MESSAGE2_TEXT_ATTR);
- if (ml = create_menu(ri, win, &test_menu_data[0],
- TEST_MENU_TEXT_ATTR)) {
- attach_menu(win, ml);
- test_action(ri, win, ml);
- remove_menu(ml);
- free_menu(ml);
- }
- CloseWindow(win);
- }
- free_render_info(ri);
- }
- CloseLibrary(GfxBase);
- }
- CloseLibrary(IntuitionBase);
- }
- return(0L);
- }
- /* Perform IDCMP action */
-
- VOID
- test_action(struct RenderInfo *ri, struct Window *win, struct MenuList *ml)
- {
- struct MsgPort *up = win->UserPort;
- struct IntuiMessage *msg;
- BYTE buffer[80];
- ULONG class;
- USHORT code;
- BOOL keepon = TRUE;
-
- do {
- WaitPort(up);
- while (msg = (struct IntuiMessage *)GetMsg(up)) {
- class = msg->Class;
- code = msg->Code;
- ReplyMsg((struct Message *)msg);
- switch (class) {
- case CLOSEWINDOW :
- keepon = FALSE;
- break;
-
- case MENUPICK :
- while (code != MENUNULL) {
- sprintf(&buffer[0], MESSAGE2_TEXT,
- (MENUNUM(code) != NOMENU ? MENUNUM(code) : 0),
- (ITEMNUM(code) != NOITEM ? ITEMNUM(code) : 0),
- (SUBNUM(code) != NOSUB ? SUBNUM(code) : 0));
- clear_render_window(ri, win, 0, MESSAGE2_TOP_EDGE,
- WINDOW_WIDTH, 10);
- print_text(ri, win, &buffer[0], 0, MESSAGE2_TOP_EDGE,
- TEXT_DATA_TYPE_TEXT, TEXT_DATA_FLAG_CENTER |
- TEXT_DATA_FLAG_COLOR2, MESSAGE2_TEXT_ATTR);
- code = menu_item_address(ml, code)->NextSelect;
- }
- break;
- }
- }
- } while (keepon == TRUE);
- }
-