r670 - trunk/game
black at icculus.org
black at icculus.org
Sun Mar 12 17:07:57 EST 2006
Author: black
Date: 2006-03-12 17:07:57 -0500 (Sun, 12 Mar 2006)
New Revision: 670
Modified:
trunk/game/m_menucore.c
trunk/game/m_menucore.h
Log:
Only a few very small changes to the menucore code.
Modified: trunk/game/m_menucore.c
===================================================================
--- trunk/game/m_menucore.c 2006-03-12 22:02:12 UTC (rev 669)
+++ trunk/game/m_menucore.c 2006-03-12 22:07:57 UTC (rev 670)
@@ -12,56 +12,89 @@
#define MOUSE1 (SDLK_LAST + 1)
+/*
+-make every item have a parent
+-make it more strict and error out earlier
+*/
+
void Menu_FinishMenu(Menu_SubMenu *menu);
+// if the item has no parent, it doesn't do anything
void Menu_RemoveFromParent(Menu_Item *item)
{
- Menu_Item *ref;
if (item->parent)
{
+ if (item->parent->selecteditem == item)
+ item->parent->selecteditem = NULL;
+
if (item->parent->subitems == NULL)
{
+ // FIXME: error condition
}
else if (item->parent->subitems == item)
item->parent->subitems = item->parent->subitems->next;
else
{
- for (ref = item->parent->subitems; ref->next; ref = ref->next)
+ Menu_Item *node;
+ for (node = item->parent->subitems; node->next; node = node->next)
{
- if (ref->next == item)
+ if (node->next == item)
{
- ref->next = ref->next->next;
- item->next = NULL;
+ node->next = item->next;
break;
}
}
+ if( node->next == NULL ) {
+ // FIXME: error condition
+ }
}
item->next = NULL;
item->parent = NULL;
}
}
-void Menu_AddAtFront(Menu_SubMenu *parent, Menu_SubMenu *menu)
+
+void Menu_AddAtFront(Menu_SubMenu *parent, Menu_Item *item)
{
- Menu_Item *p;
- menu->super.parent = parent;
- if (!parent)
- return;
+ assert( item != NULL );
+ assert( parent != NULL );
+ assert( item->parent == NULL );
+
+ item->parent = parent;
+
if (!parent->subitems)
- parent->subitems = &menu->super;
+ parent->subitems = item;
else
{
- for (p = parent->subitems; p->next; p = p->next)
+ Menu_Item *node;
+ for (node = parent->subitems; node->next; node = node->next)
;
- p->next = &menu->super;
+ node->next = item;
}
}
+
+void Menu_AddToBack(Menu_SubMenu *parent, Menu_Item *item )
+{
+ assert( item != NULL );
+ assert( parent != NULL );
+ assert( item->parent == NULL );
+
+ item->parent = parent;
+ item->next = parent->subitems;
+ parent->subitems = item;
+}
+
void Menu_BringToFront(Menu_SubMenu *menu)
{
- Menu_SubMenu *p = menu->super.parent;
+ Menu_SubMenu *parent = menu->super.parent;
+ // FIXME: fix this
+ if( !parent ) {
+ return;
+ }
Menu_RemoveFromParent(&menu->super);
- Menu_AddAtFront(p, menu);
+ Menu_AddAtFront(parent, &menu->super);
}
+// TODO: add fully qualified names with a scope operator (:: or.?)
void *Menu_GetItem(Menu_SubMenu *parent, char *name)
{
Menu_Item *sub;
@@ -78,6 +111,7 @@
void Menu_MoveToCenter(Menu_SubMenu *menu)
{
+ // TODO: make it move to the center of the parent
menu->super.pos[0] = (Video.width - menu->super.size[0])/2;
menu->super.pos[1] = (Video.height - menu->super.size[1])/2;
menu->subwindow.pos[0] = menu->super.pos[0];
@@ -91,25 +125,25 @@
for (j = 0; j < 2; j++)
{
- if (Input.mouse[j] < item->pos[j]+inh->addpos[j] || Input.mouse[j] > item->pos[j]+inh->addpos[j] + item->size[j])
+ if (Input.mouse[j] < item->pos[j]+inh->addpos[j] || item->pos[j]+inh->addpos[j] + item->size[j] < Input.mouse[j] )
return;
}
if (item->parent->selecteditem != item)
item->parent->selecteditem = item; //mouse is in us.
}
+
void Menu_Generic_MouseMoveNonSelectable(UNUSED void *item, UNUSED Menu_Inheritance *inh)
{
}
+
Nbool Menu_Generic_KeyPressIgnore (UNUSED void *item, UNUSED NUint mod, UNUSED NUint sym, UNUSED NUint character, UNUSED Nbool downevent)
{
return false;
}
+
void Menu_Generic_Destroy(Menu_Item *item)
{
- if (item->parent)
- if (item->parent->selecteditem == item)
- item->parent->selecteditem = NULL;
Menu_RemoveFromParent(item);
if (Menu.grabs == item)
@@ -117,26 +151,25 @@
Mem_Free(&item);
}
-Menu_Item *Menu_CreateGenericItem(Menu_SubMenu *parent, NSint x, NSint y, NSint bytes)
+
+Menu_Item *Menu_CreateGenericItem(Menu_SubMenu *parent, NSint x, NSint y, NUint bytes)
{
- Menu_Item *it;
- it = Mem_Alloc(Menu.menu_zone, bytes);
+ Menu_Item *item;
+ item = Mem_Alloc(Menu.menu_zone, bytes);
- it->MouseMove = Menu_Generic_MouseMoveNonSelectable;
- it->KeyEvent = Menu_Generic_KeyPressIgnore;
- it->Destroy = Menu_Generic_Destroy;
+ item->MouseMove = Menu_Generic_MouseMoveNonSelectable;
+ item->KeyEvent = Menu_Generic_KeyPressIgnore;
+ item->Destroy = Menu_Generic_Destroy;
- it->pos[0] = x;
- it->pos[1] = y;
+ item->pos[0] = x;
+ item->pos[1] = y;
- it->parent = parent;
- if (parent)
+ if (parent)
{
- it->next = parent->subitems;
- parent->subitems = it;
+ Menu_AddToBack(parent, item);
}
- return it; //heh, cool :D
+ return item;
}
@@ -154,7 +187,7 @@
}
void Menu_Text_DefaultUse (struct Menu_TextItem *item)
{
- Shell_ExecuteScript("console", item->command);
+ Shell_ExecuteScript("menu text use", item->command);
}
Nbool Menu_Text_KeyPress (Menu_TextItem *item, UNUSED NUint mod, NUint sym, UNUSED NUint character, Nbool downevent)
{
@@ -842,16 +875,12 @@
{
Menu_SubMenu *menu;
- Menu.rootmenu.super.size[0] = Video.width;
- Menu.rootmenu.super.size[1] = Video.height;
- Menu.rootmenu.subwindow.size[0] = Video.width;
- Menu.rootmenu.subwindow.size[1] = Video.height;
+ menu = (Menu_SubMenu*) Menu_CreateGenericItem(NULL, 0, 0, sizeof(Menu_SubMenu));
- menu = (Menu_SubMenu*)Menu_CreateGenericItem(NULL, 0, 0, sizeof(Menu_SubMenu));
+ if( parent ) {
+ Menu_AddAtFront(parent, &menu->super);
+ }
- Menu_AddAtFront(parent, menu);
-
-
menu->super.MouseMove = Menu_MouseMoveSubMenu;
menu->super.DrawMenu = Menu_DrawSubMenu;
menu->super.KeyEvent = Menu_KeyEventSubMenu;
@@ -861,12 +890,13 @@
return menu;
}
+
void Menu_FinishMenu(Menu_SubMenu *menu)
{
Menu_Item *subitem;
NSint maxpos[2];
- if (!menu)
- return;
+
+ assert( menu != NULL );
maxpos[0] = 0;
maxpos[1] = 0;
@@ -891,7 +921,7 @@
Menu_Item *sitem;
NSint axis, otheraxis;
NSint val = 0;
- NSint maxval=0;
+ NSint maxval = 0;
//axis is usually the 'vertical' axis, where each field is spaced with padding
//otheraxis is the axis on which we align stuff (rather than just space it)
@@ -1143,7 +1173,13 @@
Shell_Register(&Menu_Menu_Quit_Decl, NULL);
Shell_Register(&Menu_Menu_Close_Decl, NULL);
+ // init the root menu
Menu.rootmenu.super.MouseMove = Menu_MouseMoveSubMenu;
Menu.rootmenu.super.DrawMenu = Menu_DrawSubMenu;
Menu.rootmenu.super.KeyEvent = Menu_KeyEventSubMenu;
+
+ Menu.rootmenu.super.size[0] = Video.width;
+ Menu.rootmenu.super.size[1] = Video.height;
+ Menu.rootmenu.subwindow.size[0] = Video.width;
+ Menu.rootmenu.subwindow.size[1] = Video.height;
}
Modified: trunk/game/m_menucore.h
===================================================================
--- trunk/game/m_menucore.h 2006-03-12 22:02:12 UTC (rev 669)
+++ trunk/game/m_menucore.h 2006-03-12 22:07:57 UTC (rev 670)
@@ -5,7 +5,7 @@
typedef struct Menu_Rect
{
NSint32 pos[2];
- NSint32 size[2];
+ NUint32 size[2];
}
Menu_Rect;
@@ -27,8 +27,9 @@
NSint32 pos[2];
NSint32 size[2];
+ struct Menu_SubMenu *parent;
+ // this actually belongs to Menu_SubMenu and is managed by it
struct Menu_Item *next;
- struct Menu_SubMenu *parent;
}
Menu_Item;
More information about the neither-commits
mailing list