r700 - trunk/game

black at icculus.org black at icculus.org
Tue Apr 18 06:27:01 EDT 2006


Author: black
Date: 2006-04-18 06:27:00 -0400 (Tue, 18 Apr 2006)
New Revision: 700

Modified:
   trunk/game/m_menucore.c
   trunk/game/m_menucore.h
Log:
Fix a bug, add a type member to Menu_Item and move a few comments around, too.


Modified: trunk/game/m_menucore.c
===================================================================
--- trunk/game/m_menucore.c	2006-04-10 00:28:18 UTC (rev 699)
+++ trunk/game/m_menucore.c	2006-04-18 10:27:00 UTC (rev 700)
@@ -87,7 +87,7 @@
 	parent->subitems = item;
 }
 
-void Menu_SubMenu_BringToFront(Menu_Item *item)
+void Menu_SubMenu_BringToFocus(Menu_Item *item)
 {
 	Menu_SubMenu *parent = item->parent;
 	// FIXME: fix this
@@ -95,6 +95,7 @@
 		return;
 	Menu_Item_RemoveFromParent(item);
 	Menu_SubMenu_AddAtFront(parent, item);
+	parent->selecteditem = item;
 }
 
 // TODO: use NString for everything
@@ -126,12 +127,11 @@
 				break;
 			}
 		}
-		if (item == NULL) 
+		if (item == NULL || item->type != MENU_ITEMTYPE_SUBMENU) 
 		{
 			break;
 		}
 		name_start = name_end + 1;
-		// FIXME: we don't really know whether item is really a submenu...
 		current_parent = (Menu_SubMenu*) item;
 	}
 	return item;
@@ -189,7 +189,7 @@
 	Mem_Free(&item);
 }
 
-Menu_Item *Menu_Generic_Create(Menu_SubMenu *parent, NSint x, NSint y, NUint bytes)
+Menu_Item *Menu_Generic_Create(Menu_SubMenu *parent, Menu_ItemType type, NSint x, NSint y, NUint bytes)
 {
 	Menu_Item *item;
 	assert( bytes >= sizeof(Menu_Item) );
@@ -201,6 +201,8 @@
 	item->KeyEvent = Menu_Generic_KeyPressIgnore;
 	item->Destroy = Menu_Generic_Destroy;
 
+	item->type = type;
+
 	item->pos[0] = x;
 	item->pos[1] = y;
 
@@ -240,13 +242,13 @@
 	}
 	return false;
 }
-Menu_TextItem *Menu_Text_Create(Menu_SubMenu *parent, NSint x, NSint y, char *text, void *command, void (*UseItem) (struct Menu_TextItem *item, void *cookie))
+Menu_TextItem *Menu_Text_Create(Menu_SubMenu *parent, NSint x, NSint y, char *text, void *cookie, void (*UseItem) (struct Menu_TextItem *item, void *cookie))
 {
 	Menu_TextItem *it;
-	it = (Menu_TextItem*)Menu_Generic_Create(parent, x, y, sizeof(Menu_TextItem));
+	it = (Menu_TextItem*)Menu_Generic_Create(parent, MENU_ITEMTYPE_TEXT, x, y, sizeof(Menu_TextItem));
 
 	it->super.Draw = Menu_Text_Draw;
-	if (command != NULL)
+	if (cookie != NULL)
 	{
 		it->super.MouseMove = Menu_Generic_MouseMoveSelectable;
 		it->super.KeyEvent = Menu_Text_KeyPress;
@@ -255,9 +257,9 @@
 	it->super.size[1] = 8;
 
 	it->text = text;
-	it->cookie = command;
+	it->cookie = cookie;
 
-	if (UseItem == NULL && command)
+	if (UseItem == NULL && cookie)
 		UseItem = Menu_Text_DefaultUse;
 
 	it->UseItem = UseItem;
@@ -352,7 +354,7 @@
 Menu_EditItem *Menu_Edit_Create(Menu_SubMenu *parent, NSint x, NSint y, char *text)
 {
 	Menu_EditItem *it;
-	it = (Menu_EditItem*)Menu_Generic_Create(parent, x, y, sizeof(Menu_EditItem));
+	it = (Menu_EditItem*)Menu_Generic_Create(parent, MENU_ITEMTYPE_EDIT, x, y, sizeof(Menu_EditItem));
 
 	it->super.Draw = Menu_Edit_Draw;
 	it->super.MouseMove = Menu_Generic_MouseMoveSelectable;
@@ -439,7 +441,7 @@
 		NUint i;
 
 		item->popup = Menu_SubMenu_Create(&Menu.rootmenu);
-		Menu_SubMenu_BringToFront(&item->popup->super);
+		Menu_SubMenu_BringToFocus(&item->popup->super);
 		interior = Menu_SubMenu_Create(item->popup);
 		interior->allowclose = false;
 		Menu.grabs = &item->popup->super;
@@ -477,7 +479,7 @@
 {
 	//list is pipe-seperated
 	Menu_ComboItem *it;
-	it = (Menu_ComboItem*)Menu_Generic_Create(parent, x, y, sizeof(Menu_ComboItem));
+	it = (Menu_ComboItem*)Menu_Generic_Create(parent, MENU_ITEMTYPE_COMBO, x, y, sizeof(Menu_ComboItem));
 
 	it->super.super.Draw = Menu_Combo_Draw;
 	it->super.super.MouseMove = Menu_Generic_MouseMoveSelectable;
@@ -554,7 +556,7 @@
 Menu_PictureItem *Menu_Picture_Create(Menu_SubMenu *parent, NSint x, NSint y, NUint w, NUint h, char *imagename, void *command, void (*UseItem) (struct Menu_PictureItem *item, void *cookie))
 {
 	Menu_PictureItem *it;
-	it = (Menu_PictureItem*)Menu_Generic_Create(parent, x, y, sizeof(Menu_PictureItem));
+	it = (Menu_PictureItem*)Menu_Generic_Create(parent, MENU_ITEMTYPE_PICTURE, x, y, sizeof(Menu_PictureItem));
 
 	it->super.Draw = Menu_Picture_Draw;
 	if (command != NULL)
@@ -584,15 +586,8 @@
 
 
 //sliderh items
-void Menu_Slider_Draw(Menu_SliderItem *item, Menu_Inheritance *inh)
+void Menu_Slider_Frame(Menu_SliderItem *item, Menu_Inheritance *inh)
 {
-	Nfloat frac;
-
-//	R_SetBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
-//	R_SetColor(1, 1, 1, 1);
-//	R_SetTexture(Resource_IndexForName(item->imagename, RESOURCETYPE_TEXTURE, 0, 0));
-//	R_DrawPic(item->super.pos[0] + inh->origin[0], item->super.pos[1] + inh->origin[1], item->super.size[0], item->super.size[1]);
-
 	if (Menu.grabs == &item->super)
 	{
 		{
@@ -609,7 +604,17 @@
 			item->SliderChanged(item, item->cookie);
 		}
 	}
+}
 
+void Menu_Slider_Draw(Menu_SliderItem *item, Menu_Inheritance *inh)
+{
+	Nfloat frac;
+
+//	R_SetBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+//	R_SetColor(1, 1, 1, 1);
+//	R_SetTexture(Resource_IndexForName(item->imagename, RESOURCETYPE_TEXTURE, 0, 0));
+//	R_DrawPic(item->super.pos[0] + inh->origin[0], item->super.pos[1] + inh->origin[1], item->super.size[0], item->super.size[1]);
+
 	if (item->SliderUpdate)
 		item->SliderUpdate(item, item->cookie);
 
@@ -664,7 +669,7 @@
 Menu_SliderItem *Menu_Slider_Create(Menu_SubMenu *parent, NUint axis, NSint x, NSint y, NUint w, NUint h, Nfloat minv, Nfloat maxv, Nfloat defaultv, void (*ChangeNotification)(Menu_SliderItem *item, void *cookie), void (*UpdateSlider)(Menu_SliderItem *item, void *cookie), void *cookie)
 {
 	Menu_SliderItem *it;
-	it = (Menu_SliderItem*)Menu_Generic_Create(parent, x, y, sizeof(Menu_SliderItem));
+	it = (Menu_SliderItem*)Menu_Generic_Create(parent, MENU_ITEMTYPE_SLIDER, x, y, sizeof(Menu_SliderItem));
 
 	it->super.Draw = Menu_Slider_Draw;
 	it->super.MouseMove = Menu_Generic_MouseMoveSelectable;
@@ -768,24 +773,23 @@
 
 	for (subitem = menu->subitems; subitem; subitem = next)
 	{
-		next = subitem->next;//this funkyness is so that we can unlink and kill things in the draw function (if the need arises).
+		// this funkyness is so that we can unlink and kill things in the draw function (if the need arises).
+		next = subitem->next;
 		subitem->Frame(subitem, &ninh, elapsedtime);
 	}
 }
 
 void Menu_SubMenu_Draw(Menu_SubMenu *menu, Menu_Inheritance *inh)
 {
-	Menu_Item *subitem, *next;
+	Menu_Item *subitem;
 	Menu_Inheritance ninh;
 
 	Menu_SubMenu_SetupInheritance(menu, inh, &ninh);
 
 	R_SetScissor(ninh.window.pos[0], ninh.window.pos[1], ninh.window.size[0], ninh.window.size[1]);
 
-	for (subitem = menu->subitems; subitem; subitem = next)
+	for (subitem = menu->subitems; subitem; subitem = subitem->next)
 	{
-		// TODO: remove this since we only accept Frame to delete items, Draw should just draw them and don't do any management work like deleting our beloved items
-		next = subitem->next;//this funkyness is so that we can unlink and kill things in the draw function (if the need arises).
 		subitem->Draw(subitem, &ninh);
 	}
 
@@ -795,7 +799,7 @@
 {
 	Menu_Item *subitem;
 
-	Menu_SubMenu_BringToFront(&item->super);
+	Menu_SubMenu_BringToFocus(&item->super);
 
 	subitem = item->selecteditem;
 	if (item->selecteditem)
@@ -867,7 +871,7 @@
 {
 	Menu_SubMenu *menu;
 
-	menu = (Menu_SubMenu*) Menu_Generic_Create(NULL, 0, 0, sizeof(Menu_SubMenu));
+	menu = (Menu_SubMenu*) Menu_Generic_Create(NULL, MENU_ITEMTYPE_SUBMENU, 0, 0, sizeof(Menu_SubMenu));
 
 	if( parent ) {
 		Menu_SubMenu_AddAtFront(parent, &menu->super);

Modified: trunk/game/m_menucore.h
===================================================================
--- trunk/game/m_menucore.h	2006-04-10 00:28:18 UTC (rev 699)
+++ trunk/game/m_menucore.h	2006-04-18 10:27:00 UTC (rev 700)
@@ -17,6 +17,19 @@
 }
 Menu_Inheritance;
 
+typedef enum Menu_ItemType
+{
+	// use unknown to mark uninitialized type fields
+	MENU_ITEMTYPE_UNKNOWN = 0,
+	MENU_ITEMTYPE_SUBMENU,
+	MENU_ITEMTYPE_SLIDER,
+	MENU_ITEMTYPE_EDIT,
+	MENU_ITEMTYPE_COMBO,
+	MENU_ITEMTYPE_TEXT,
+	MENU_ITEMTYPE_PICTURE,
+}
+Menu_ItemType;
+
 typedef struct Menu_Item
 {
 	// pass an elapsedtime parameter to make animation-speed changes, etc. possible
@@ -25,6 +38,8 @@
 	Nbool (*KeyEvent) (void *item, NUint mod, NUint sym, NUint character, Nbool downevent);
 	void (*MouseMove) (void *item, Menu_Inheritance *inheritance);
 	void (*Destroy) (void *item);
+
+    Menu_ItemType type;
 	char name[64];
 	NSint32 pos[2];
 	NSint32 size[2];
@@ -115,7 +130,7 @@
 	Menu_Item super;
 
 	char *imagename;
-	// console command when clicked
+	// default: console command when clicked
 	void *cookie;
 
 	// called when the user uses (clicks) this item
@@ -163,6 +178,13 @@
 }
 Menu_ArrangeStyle;
 
+typedef enum Menu_Axis
+{
+	MENU_AXIS_HORIZONAL,
+	MENU_AXIS_VERTICAL
+}
+Menu_Axis;
+
 typedef struct MenuState
 {
 	Menu_SubMenu rootmenu;
@@ -186,11 +208,19 @@
 
 // entry points for using the menu in other systems
 Menu_SubMenu *Menu_SubMenu_Create(Menu_SubMenu *parent);
-Menu_SliderItem *Menu_VSlider_Create(Menu_SubMenu *parent, NSint x, NSint y, NUint w, NUint h, Nfloat minv, Nfloat maxv, Nfloat defaultv, void (*ChangeNotification)(Menu_SliderItem *item, void *cookie), void (*UpdateSlider)(Menu_SliderItem *item, void *cookie), void *cookie);//vertical scrolling bar
-Menu_SliderItem *Menu_HSlider_Create(Menu_SubMenu *parent, NSint x, NSint y, NUint w, NUint h, Nfloat minv, Nfloat maxv, Nfloat defaultv, void (*ChangeNotification)(Menu_SliderItem *item, void *cookie), void (*UpdateSlider)(Menu_SliderItem *item, void *cookie), void *cookie);//horizontal scrolling bar
-Menu_TextItem *Menu_Text_Create(Menu_SubMenu *parent, NSint x, NSint y, char *text, void *command, void (*UseItem) (struct Menu_TextItem *item, void *cookie)); //if usetextitem == null, interpret as a console command. if not null, command can be used as a magic cookie. If both null, item is non-selectable.
-Menu_EditItem *Menu_Edit_Create(Menu_SubMenu *parent, NSint x, NSint y, char *text); //an item for editing text (fixme: needs callbacks and stuff)
-Menu_ComboItem *Menu_Combo_Create(Menu_SubMenu *parent, NSint x, NSint y, NUint w, char *defalt, char *list);//a list of multiple choices.
-Menu_PictureItem *Menu_Picture_Create(Menu_SubMenu *parent, NSint x, NSint y, NUint w, NUint h, char *imagename, void *command, void (*UseItem) (struct Menu_PictureItem *item, void *cookie)); //just a simple picture. clicking it can give a console command
+// vertical scrolling bar
+Menu_SliderItem *Menu_VSlider_Create(Menu_SubMenu *parent, NSint x, NSint y, NUint w, NUint h, Nfloat minv, Nfloat maxv, Nfloat defaultv, void (*ChangeNotification)(Menu_SliderItem *item, void *cookie), void (*UpdateSlider)(Menu_SliderItem *item, void *cookie), void *cookie);
+// horizontal scrolling bar
+Menu_SliderItem *Menu_HSlider_Create(Menu_SubMenu *parent, NSint x, NSint y, NUint w, NUint h, Nfloat minv, Nfloat maxv, Nfloat defaultv, void (*ChangeNotification)(Menu_SliderItem *item, void *cookie), void (*UpdateSlider)(Menu_SliderItem *item, void *cookie), void *cookie);
+// if usetextitem == null, cookie is interpreted as a console command. if not null, command can be used 
+// as a magic cookie. If both null, item is non-selectable.
+Menu_TextItem *Menu_Text_Create(Menu_SubMenu *parent, NSint x, NSint y, char *text, void *cookie, void (*UseItem) (struct Menu_TextItem *item, void *cookie));
+// an item for editing text
+// FIXME: needs callbacks and stuff
+Menu_EditItem *Menu_Edit_Create(Menu_SubMenu *parent, NSint x, NSint y, char *text);
+// a list of multiple choices.
+Menu_ComboItem *Menu_Combo_Create(Menu_SubMenu *parent, NSint x, NSint y, NUint w, char *defalt, char *list);
+// just a simple picture. clicking it can give a console command
+Menu_PictureItem *Menu_Picture_Create(Menu_SubMenu *parent, NSint x, NSint y, NUint w, NUint h, char *imagename, void *command, void (*UseItem) (struct Menu_PictureItem *item, void *cookie));
 
 #endif




More information about the neither-commits mailing list