[Scummvm-cvs-logs] SF.net SVN: scummvm: [22757] scummvm/trunk/engines/agi

wjpalenstijn at users.sourceforge.net wjpalenstijn at users.sourceforge.net
Mon May 29 14:32:01 CEST 2006


Revision: 22757
Author:   wjpalenstijn
Date:     2006-05-29 14:30:48 -0700 (Mon, 29 May 2006)
ViewCVS:  http://svn.sourceforge.net/scummvm/?rev=22757&view=rev

Log Message:
-----------
objectify AGI menu.h/cpp

Modified Paths:
--------------
    scummvm/trunk/engines/agi/agi.cpp
    scummvm/trunk/engines/agi/cycle.cpp
    scummvm/trunk/engines/agi/menu.cpp
    scummvm/trunk/engines/agi/menu.h
    scummvm/trunk/engines/agi/op_cmd.cpp
    scummvm/trunk/engines/agi/savegame.cpp
Modified: scummvm/trunk/engines/agi/agi.cpp
===================================================================
--- scummvm/trunk/engines/agi/agi.cpp	2006-05-29 20:23:08 UTC (rev 22756)
+++ scummvm/trunk/engines/agi/agi.cpp	2006-05-29 21:30:48 UTC (rev 22757)
@@ -314,7 +314,7 @@
 
 	init_words();
 
-	menu_init();
+	menu = new Menu();
 	init_pri_table();
 
 	/* clear string buffer */

Modified: scummvm/trunk/engines/agi/cycle.cpp
===================================================================
--- scummvm/trunk/engines/agi/cycle.cpp	2006-05-29 20:23:08 UTC (rev 22756)
+++ scummvm/trunk/engines/agi/cycle.cpp	2006-05-29 21:30:48 UTC (rev 22757)
@@ -273,7 +273,7 @@
 		setvar(V_key, 0);	/* clear ENTER key */
 		break;
 	case INPUT_MENU:
-		menu_keyhandler(key);
+		menu->keyhandler(key);
 		do_update();
 		return false;
 	case INPUT_NONE:
@@ -391,7 +391,8 @@
 		agi_deinit();
 	} while (ec == err_RestartGame);
 
-	menu_deinit();
+	delete menu;
+	menu = 0;
 
 	release_image_stack();
 

Modified: scummvm/trunk/engines/agi/menu.cpp
===================================================================
--- scummvm/trunk/engines/agi/menu.cpp	2006-05-29 20:23:08 UTC (rev 22756)
+++ scummvm/trunk/engines/agi/menu.cpp	2006-05-29 21:30:48 UTC (rev 22757)
@@ -34,6 +34,10 @@
 
 namespace Agi {
 
+Menu* menu;
+
+// TODO: add constructor/destructor for agi_menu, agi_menu_option
+
 struct agi_menu_option {
 	int enabled;			/**< option is enabled or disabled */
 	int event;			/**< menu event */
@@ -41,8 +45,6 @@
 	char *text;			/**< text of menu option */
 };
 
-typedef Common::List<agi_menu_option*> MenuOptionList;
-	
 struct agi_menu {
 	MenuOptionList down;		/**< list head for menu options */
 	int index;			/**< number of menu in menubar */
@@ -53,14 +55,7 @@
 	char *text;			/**< menu name */
 };
 
-typedef Common::List<agi_menu*> MenuList;
-
-static MenuList menubar;
-
-static int h_cur_menu;
-static int v_cur_menu;
-
-static agi_menu *get_menu(int i) {
+agi_menu *Menu::get_menu(int i) {
 	MenuList::iterator iter;
 	for (iter = menubar.begin(); iter != menubar.end(); ++iter) {
 		agi_menu *m = *iter;
@@ -70,7 +65,7 @@
 	return NULL;
 }
 
-static agi_menu_option *get_menu_option(int i, int j) {
+agi_menu_option *Menu::get_menu_option(int i, int j) {
 	agi_menu *m = get_menu(i);
 	MenuOptionList::iterator iter;
 	for (iter = m->down.begin(); iter != m->down.end(); ++iter) {	
@@ -82,7 +77,7 @@
 	return NULL;
 }
 
-static void draw_menu_bar() {
+void Menu::draw_menu_bar() {
 	clear_lines(0, 0, MENU_BG);
 	flush_lines(0, 0);
 
@@ -94,7 +89,7 @@
 
 }
 
-static void draw_menu_hilite(int cur_menu) {
+void Menu::draw_menu_hilite(int cur_menu) {
 	agi_menu *m = get_menu(cur_menu);
 	debugC(6, kDebugLevelMenu, "[%s]", m->text);
 	print_text(m->text, 0, m->col, 0, 40, MENU_BG, MENU_FG);
@@ -102,7 +97,7 @@
 }
 
 /* draw box and pulldowns. */
-static void draw_menu_option(int h_menu) {
+void Menu::draw_menu_option(int h_menu) {
 	/* find which vertical menu it is */
 	agi_menu *m = get_menu(h_menu);
 
@@ -117,7 +112,7 @@
 	}
 }
 
-static void draw_menu_option_hilite(int h_menu, int v_menu) {
+void Menu::draw_menu_option_hilite(int h_menu, int v_menu) {
 	agi_menu *m = get_menu(h_menu);
 	agi_menu_option *d = get_menu_option(h_menu, v_menu);
 
@@ -125,14 +120,14 @@
 			MENU_BG, d->enabled ? MENU_FG : MENU_DISABLED);
 }
 
-static void new_menu_selected(int i) {
+void Menu::new_menu_selected(int i) {
 	show_pic();
 	draw_menu_bar();
 	draw_menu_hilite(i);
 	draw_menu_option(i);
 }
 
-static int mouse_over_text(unsigned int line, unsigned int col, char *s) {
+bool Menu::mouse_over_text(unsigned int line, unsigned int col, char *s) {
 	if (mouse.x < col * CHAR_COLS)
 		return false;
 
@@ -148,12 +143,6 @@
 	return true;
 }
 
-static int h_index;
-static int v_index;
-static int h_col;
-static int h_max_menu;
-static int v_max_menu[10];
-
 #if 0
 static void add_about_option() {
 	const char *text = "About AGI engine";
@@ -176,14 +165,14 @@
  * Public functions
  */
 
-void menu_init() {
+Menu::Menu() {
 	h_index = 0;
 	h_col = 1;
 	h_cur_menu = 0;
 	v_cur_menu = 0;
 }
 
-void menu_deinit() {
+Menu::~Menu() {
 	MenuList::iterator iterh;
 	for (iterh = menubar.reverse_begin(); iterh != menubar.end(); ) {
 		agi_menu *m = *iterh;
@@ -202,7 +191,7 @@
 	}
 }
 
-void menu_add(char *s) {
+void Menu::add(char *s) {
 	agi_menu *m = new agi_menu;
 	m->text = strdup(s);
 	while (m->text[strlen(m->text) - 1] == ' ')
@@ -221,7 +210,7 @@
 	menubar.push_back(m);
 }
 
-void menu_add_item(char *s, int code) {
+void Menu::add_item(char *s, int code) {
 	int l;
 
 	agi_menu_option* d = new agi_menu_option;
@@ -249,7 +238,7 @@
 	m->down.push_back(d);
 }
 
-void menu_submit() {
+void Menu::submit() {
 	debugC(3, kDebugLevelMenu, "Submitting menu");
 
 	/* add_about_option (); */
@@ -269,7 +258,7 @@
 	}
 }
 
-int menu_keyhandler(int key) {
+bool Menu::keyhandler(int key) {
 	static int clock_val;
 	static int menu_active = false;
 	static int button_used = 0;
@@ -435,7 +424,7 @@
 	return true;
 }
 
-void menu_set_item(int event, int state) {
+void Menu::set_item(int event, int state) {
 	/* scan all menus for event number # */
 
 	debugC(6, kDebugLevelMenu, "event = %d, state = %d", event, state);
@@ -453,7 +442,7 @@
 	}
 }
 
-void menu_enable_all() {
+void Menu::enable_all() {
 	MenuList::iterator iterh;
 	for (iterh = menubar.begin(); iterh != menubar.end(); ++iterh) {
 		agi_menu *m = *iterh;

Modified: scummvm/trunk/engines/agi/menu.h
===================================================================
--- scummvm/trunk/engines/agi/menu.h	2006-05-29 20:23:08 UTC (rev 22756)
+++ scummvm/trunk/engines/agi/menu.h	2006-05-29 21:30:48 UTC (rev 22757)
@@ -25,6 +25,8 @@
 #ifndef AGI_MENU_H
 #define AGI_MENU_H
 
+#include "common/list.h"
+
 namespace Agi {
 
 #define MENU_BG		0x0f	/* White */
@@ -33,15 +35,48 @@
 #define MENU_FG		0x00	/* Black */
 #define MENU_LINE	0x00	/* Black */
 
-void menu_init(void);
-void menu_deinit(void);
-void menu_add(char *);
-void menu_add_item(char *, int);
-void menu_submit(void);
-void menu_set_item(int, int);
-int menu_keyhandler(int);
-void menu_enable_all(void);
+struct agi_menu;	
+struct agi_menu_option;
+typedef Common::List<agi_menu*> MenuList;
+typedef Common::List<agi_menu_option*> MenuOptionList;
 
+class Menu {
+public:
+	Menu();
+	~Menu();
+
+	void add(char *s);
+	void add_item(char *s, int code);
+	void submit();
+	void set_item(int event, int state);
+	bool keyhandler(int key);
+	void enable_all();
+
+private:
+	MenuList menubar;
+
+	int h_cur_menu;
+	int v_cur_menu;
+
+	int h_index;
+	int v_index;
+	int h_col;
+	int h_max_menu;
+	int v_max_menu[10];
+
+	agi_menu* get_menu(int i);
+	agi_menu_option *get_menu_option(int i, int j);
+	void draw_menu_bar();
+	void draw_menu_hilite(int cur_menu);
+	void draw_menu_option(int h_menu);
+	void draw_menu_option_hilite(int h_menu, int v_menu);
+	void new_menu_selected(int i);
+	bool mouse_over_text(unsigned int line, unsigned int col, char *s);
+	
+};
+
+extern Menu* menu;
+
 }                             // End of namespace Agi
 
 #endif				/* AGI_MENU_H */

Modified: scummvm/trunk/engines/agi/op_cmd.cpp
===================================================================
--- scummvm/trunk/engines/agi/op_cmd.cpp	2006-05-29 20:23:08 UTC (rev 22756)
+++ scummvm/trunk/engines/agi/op_cmd.cpp	2006-05-29 21:30:48 UTC (rev 22757)
@@ -420,15 +420,15 @@
 }
 
 cmd(enable_item) {
-	menu_set_item(p0, true);
+	menu->set_item(p0, true);
 }
 
 cmd(disable_item) {
-	menu_set_item(p0, false);
+	menu->set_item(p0, false);
 }
 
 cmd(submit_menu) {
-	menu_submit();
+	menu->submit();
 }
 
 cmd(set_scan_start) {
@@ -874,13 +874,13 @@
 cmd(set_menu) {
 	debugC(4, kDebugLevelScripts, "text %02x of %02x", p0, cur_logic->num_texts);
 	if (cur_logic->texts != NULL && p0 < cur_logic->num_texts)
-		menu_add(cur_logic->texts[p0 - 1]);
+		menu->add(cur_logic->texts[p0 - 1]);
 }
 
 cmd(set_menu_item) {
 	debugC(4, kDebugLevelScripts, "text %02x of %02x", p0, cur_logic->num_texts);
 	if (cur_logic->texts != NULL && p0 <= cur_logic->num_texts)
-		menu_add_item(cur_logic->texts[p0 - 1], p1);
+		menu->add_item(cur_logic->texts[p0 - 1], p1);
 }
 
 cmd(version) {
@@ -980,7 +980,7 @@
 	if (sel == 0) {
 		game.quit_prog_now = 0xff;
 		setflag(F_restart_game, true);
-		menu_enable_all();
+		menu->enable_all();
 	}
 }
 

Modified: scummvm/trunk/engines/agi/savegame.cpp
===================================================================
--- scummvm/trunk/engines/agi/savegame.cpp	2006-05-29 20:23:08 UTC (rev 22756)
+++ scummvm/trunk/engines/agi/savegame.cpp	2006-05-29 21:30:48 UTC (rev 22757)
@@ -732,7 +732,7 @@
 	if ((rc = load_game(path)) == err_OK) {
 		message_box("Game restored.");
 		game.exit_all_logics = 1;
-		menu_enable_all();
+		menu->enable_all();
 	} else {
 		message_box("Error restoring game.");
 	}
@@ -775,7 +775,7 @@
 	if ((rc = load_game(path)) == err_OK) {
 		message_box("Game restored.");
 		game.exit_all_logics = 1;
-		menu_enable_all();
+		menu->enable_all();
 	} else {
 		message_box("Error restoring game.");
 	}


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.





More information about the Scummvm-git-logs mailing list