[Super-tux-commit] supertux/lib/gui button.h,1.2,1.3 menu.cpp,1.1,1.2 menu.h,1.1,1.2 mousecursor.cpp
Brought to you by:
wkendrick
From: Tobias G. <to...@us...> - 2004-07-21 16:52:01
|
Update of /cvsroot/super-tux/supertux/lib/gui In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32238/lib/gui Modified Files: button.h menu.cpp menu.h mousecursor.cpp mousecursor.h Log Message: The SuperTux library features a SuperTux namespace now. + minor Bugfixes and cleanups Index: mousecursor.h =================================================================== RCS file: /cvsroot/super-tux/supertux/lib/gui/mousecursor.h,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- mousecursor.h 20 Jul 2004 19:41:29 -0000 1.2 +++ mousecursor.h 21 Jul 2004 16:51:51 -0000 1.3 @@ -25,54 +25,62 @@ #include "special/timer.h" #include "video/surface.h" -#define MC_FRAME_PERIOD 800 // in ms +namespace SuperTux + { -#define MC_STATES_NB 3 -enum { - MC_NORMAL, - MC_CLICK, - MC_LINK, - MC_HIDE -}; + #define MC_FRAME_PERIOD 800 // in ms -/// Mouse cursor. -/** Used to create mouse cursors. - The mouse cursors can be animated - and can be used in four different states. - (MC_NORMAL, MC_CLICK, MC_LINK or MC_HIDE) */ -class MouseCursor -{ -public: - /// Constructor of MouseCursor. - /** Expects an imagefile for the cursor and the number of animation frames it contains. */ - MouseCursor(std::string cursor_file, int frames); - ~MouseCursor(); - /// Get MouseCursor state. - /** (MC_NORMAL, MC_CLICK, MC_LINK or MC_HIDE) */ - int state(); - /// Set MouseCursor state. - /** (MC_NORMAL, MC_CLICK, MC_LINK or MC_HIDE) */ - void set_state(int nstate); - /// Define the middle of a MouseCursor. - /** Useful for cross mouse cursor images in example. */ - void set_mid(int x, int y); - - /// Draw MouseCursor on screen. - void draw(DrawingContext& context); - - /// Return the current cursor. - static MouseCursor* current() { return current_; }; - /// Set current cursor. - static void set_current(MouseCursor* pcursor) { current_ = pcursor; }; - -private: - int mid_x, mid_y; - static MouseCursor* current_; - int state_before_click; - int cur_state; - int cur_frame, tot_frames; - Surface* cursor; - Timer timer; -}; + #define MC_STATES_NB 3 + + enum { + MC_NORMAL, + MC_CLICK, + MC_LINK, + MC_HIDE + }; + + /// Mouse cursor. + /** Used to create mouse cursors. + The mouse cursors can be animated + and can be used in four different states. + (MC_NORMAL, MC_CLICK, MC_LINK or MC_HIDE) */ + class MouseCursor + { + public: + /// Constructor of MouseCursor. + /** Expects an imagefile for the cursor and the number of animation frames it contains. */ + MouseCursor(std::string cursor_file, int frames); + ~MouseCursor(); + /// Get MouseCursor state. + /** (MC_NORMAL, MC_CLICK, MC_LINK or MC_HIDE) */ + int state(); + /// Set MouseCursor state. + /** (MC_NORMAL, MC_CLICK, MC_LINK or MC_HIDE) */ + void set_state(int nstate); + /// Define the middle of a MouseCursor. + /** Useful for cross mouse cursor images in example. */ + void set_mid(int x, int y); + + /// Draw MouseCursor on screen. + void draw(DrawingContext& context); + + /// Return the current cursor. + static MouseCursor* current() + { return current_; }; + /// Set current cursor. + static void set_current(MouseCursor* pcursor) + { current_ = pcursor; }; + + private: + int mid_x, mid_y; + static MouseCursor* current_; + int state_before_click; + int cur_state; + int cur_frame, tot_frames; + Surface* cursor; + Timer timer; + }; + +} // namespace SuperTux #endif /*SUPERTUX_MOUSECURSOR_H*/ Index: mousecursor.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/lib/gui/mousecursor.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- mousecursor.cpp 20 Jul 2004 17:51:35 -0000 1.1 +++ mousecursor.cpp 21 Jul 2004 16:51:51 -0000 1.2 @@ -20,6 +20,8 @@ #include "video/drawing_context.h" #include "gui/mousecursor.h" +using namespace SuperTux; + MouseCursor* MouseCursor::current_ = 0; MouseCursor::MouseCursor(std::string cursor_file, int frames) : mid_x(0), mid_y(0) Index: menu.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/lib/gui/menu.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- menu.cpp 20 Jul 2004 17:51:35 -0000 1.1 +++ menu.cpp 21 Jul 2004 16:51:51 -0000 1.2 @@ -37,31 +37,23 @@ #include "audio/sound.h" #include "special/timer.h" #include "app/gettext.h" +#include "math/vector.h" -#define FLICK_CURSOR_TIME 500 +using namespace SuperTux; -Surface* checkbox; -Surface* checkbox_checked; -Surface* back; -Surface* arrow_left; -Surface* arrow_right; +#define FLICK_CURSOR_TIME 500 -Menu* main_menu = 0; -Menu* game_menu = 0; -Menu* options_menu = 0; -Menu* options_keys_menu = 0; -Menu* options_joystick_menu = 0; -Menu* highscore_menu = 0; -Menu* load_game_menu = 0; -Menu* save_game_menu = 0; -Menu* contrib_menu = 0; -Menu* contrib_subset_menu = 0; +Surface* SuperTux::checkbox; +Surface* SuperTux::checkbox_checked; +Surface* SuperTux::back; +Surface* SuperTux::arrow_left; +Surface* SuperTux::arrow_right; std::vector<Menu*> Menu::last_menus; Menu* Menu::current_ = 0; /* just displays a Yes/No text that can be used to confirm stuff */ -bool confirm_dialog(Surface *background, std::string text) +bool SuperTux::confirm_dialog(Surface *background, std::string text) { //Surface* cap_screen = Surface::CaptureScreen(); Index: menu.h =================================================================== RCS file: /cvsroot/super-tux/supertux/lib/gui/menu.h,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- menu.h 20 Jul 2004 17:51:35 -0000 1.1 +++ menu.h 21 Jul 2004 16:51:51 -0000 1.2 @@ -30,162 +30,161 @@ #include "special/stringlist.h" #include "gui/mousecursor.h" +namespace SuperTux + { -/* Joystick menu delay */ + /* Joystick menu delay */ #define JOYSTICK_MENU_DELAY 500 -/* IDs for menus */ + /* IDs for menus */ -bool confirm_dialog(Surface* background, std::string text); + bool confirm_dialog(Surface* background, std::string text); -/* Kinds of menu items */ -enum MenuItemKind { - MN_ACTION, - MN_GOTO, - MN_TOGGLE, - MN_BACK, - MN_DEACTIVE, - MN_TEXTFIELD, - MN_NUMFIELD, - MN_CONTROLFIELD_KB, - MN_CONTROLFIELD_JS, - MN_STRINGSELECT, - MN_LABEL, - MN_HL, /* horizontal line */ -}; + /* Kinds of menu items */ + enum MenuItemKind { + MN_ACTION, + MN_GOTO, + MN_TOGGLE, + MN_BACK, + MN_DEACTIVE, + MN_TEXTFIELD, + MN_NUMFIELD, + MN_CONTROLFIELD_KB, + MN_CONTROLFIELD_JS, + MN_STRINGSELECT, + MN_LABEL, + MN_HL, /* horizontal line */ + }; -class Menu; + class Menu; -class MenuItem -{ -public: - MenuItemKind kind; - int toggled; - char *text; - char *input; - int *int_p; // used for setting keys (can be used for more stuff...) - int id; // item id - string_list_type* list; - Menu* target_menu; + class MenuItem + { + public: + MenuItemKind kind; + int toggled; + char *text; + char *input; + int *int_p; // used for setting keys (can be used for more stuff...) + int id; // item id + string_list_type* list; + Menu* target_menu; - void change_text (const char *text); - void change_input(const char *text); + void change_text (const char *text); + void change_input(const char *text); - static MenuItem* create(MenuItemKind kind, const char *text, int init_toggle, Menu* target_menu, int id, int* int_p); + static MenuItem* create(MenuItemKind kind, const char *text, int init_toggle, Menu* target_menu, int id, int* int_p); - std::string get_input_with_symbol(bool active_item); // returns the text with an input symbol -private: - bool input_flickering; - Timer input_flickering_timer; -}; + std::string get_input_with_symbol(bool active_item); // returns the text with an input symbol + private: + bool input_flickering; + Timer input_flickering_timer; + }; -class Menu -{ -private: - static std::vector<Menu*> last_menus; - static Menu* current_; + class Menu + { + private: + static std::vector<Menu*> last_menus; + static Menu* current_; - static void push_current(Menu* pmenu); - static void pop_current(); + static void push_current(Menu* pmenu); + static void pop_current(); -public: - /** Set the current menu, if pmenu is NULL, hide the current menu */ - static void set_current(Menu* pmenu); + public: + /** Set the current menu, if pmenu is NULL, hide the current menu */ + static void set_current(Menu* pmenu); - /** Return the current active menu or NULL if none is active */ - static Menu* current() { return current_; } + /** Return the current active menu or NULL if none is active */ + static Menu* current() + { + return current_; + } -private: - /* Action done on the menu */ - enum MenuAction { - MENU_ACTION_NONE = -1, - MENU_ACTION_UP, - MENU_ACTION_DOWN, - MENU_ACTION_LEFT, - MENU_ACTION_RIGHT, - MENU_ACTION_HIT, - MENU_ACTION_INPUT, - MENU_ACTION_REMOVE - }; + private: + /* Action done on the menu */ + enum MenuAction { + MENU_ACTION_NONE = -1, + MENU_ACTION_UP, + MENU_ACTION_DOWN, + MENU_ACTION_LEFT, + MENU_ACTION_RIGHT, + MENU_ACTION_HIT, + MENU_ACTION_INPUT, + MENU_ACTION_REMOVE + }; - /** Number of the item that got 'hit' (ie. pressed) in the last - event()/action() call, -1 if none */ - int hit_item; + /** Number of the item that got 'hit' (ie. pressed) in the last + event()/action() call, -1 if none */ + int hit_item; - // position of the menu (ie. center of the menu, not top/left) - int pos_x; - int pos_y; + // position of the menu (ie. center of the menu, not top/left) + int pos_x; + int pos_y; - /** input event for the menu (up, down, left, right, etc.) */ - MenuAction menuaction; + /** input event for the menu (up, down, left, right, etc.) */ + MenuAction menuaction; - /* input implementation variables */ - int delete_character; - char mn_input_char; - Timer joystick_timer; - -public: - Timer effect; - int arrange_left; - int active_item; + /* input implementation variables */ + int delete_character; + char mn_input_char; + Timer joystick_timer; - std::vector<MenuItem> item; + public: + Timer effect; + int arrange_left; + int active_item; - Menu(); - ~Menu(); + std::vector<MenuItem> item; - void additem(MenuItem* pmenu_item); - void additem(MenuItemKind kind, const std::string& text, int init_toggle, Menu* target_menu, int id = -1, int *int_p = NULL); - - void action (); - - /** Remove all entries from the menu */ - void clear(); + Menu(); + ~Menu(); - /** Return the index of the menu item that was 'hit' (ie. the user - clicked on it) in the last event() call */ - int check (); + void additem(MenuItem* pmenu_item); + void additem(MenuItemKind kind, const std::string& text, int init_toggle, Menu* target_menu, int id = -1, int *int_p = NULL); - MenuItem& get_item(int index) { return item[index]; } - MenuItem& get_item_by_id(int id); + void action (); - int get_active_item_id(); + /** Remove all entries from the menu */ + void clear(); - bool isToggled(int id); + /** Return the index of the menu item that was 'hit' (ie. the user + clicked on it) in the last event() call */ + int check (); - void Menu::get_controlfield_key_into_input(MenuItem *item); - void Menu::get_controlfield_js_into_input(MenuItem *item); + MenuItem& get_item(int index) + { + return item[index]; + } + MenuItem& get_item_by_id(int id); - void draw(DrawingContext& context); - void draw_item(DrawingContext& context, - int index, int menu_width, int menu_height); - void set_pos(int x, int y, float rw = 0, float rh = 0); + int get_active_item_id(); - /** translate a SDL_Event into a menu_action */ - void event(SDL_Event& event); + bool isToggled(int id); - int get_width() const; - int get_height() const; + void Menu::get_controlfield_key_into_input(MenuItem *item); + void Menu::get_controlfield_js_into_input(MenuItem *item); - bool is_toggled(int id) const; -}; + void draw(DrawingContext& context); + void draw_item(DrawingContext& context, + int index, int menu_width, int menu_height); + void set_pos(int x, int y, float rw = 0, float rh = 0); -extern Surface* checkbox; -extern Surface* checkbox_checked; -extern Surface* back; -extern Surface* arrow_left; -extern Surface* arrow_right; + /** translate a SDL_Event into a menu_action */ + void event(SDL_Event& event); -extern Menu* contrib_menu; -extern Menu* contrib_subset_menu; -extern Menu* main_menu; -extern Menu* game_menu; -extern Menu* options_menu; -extern Menu* options_keys_menu; -extern Menu* options_joystick_menu; -extern Menu* highscore_menu; -extern Menu* load_game_menu; -extern Menu* save_game_menu; + int get_width() const; + int get_height() const; + + bool is_toggled(int id) const; + }; + + extern Surface* checkbox; + extern Surface* checkbox_checked; + extern Surface* back; + extern Surface* arrow_left; + extern Surface* arrow_right; + +} //namespace SuperTux #endif /*SUPERTUX_MENU_H*/ Index: button.h =================================================================== RCS file: /cvsroot/super-tux/supertux/lib/gui/button.h,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- button.h 21 Jul 2004 11:56:48 -0000 1.2 +++ button.h 21 Jul 2004 16:51:51 -0000 1.3 @@ -114,7 +114,7 @@ /// Dispatch button events. Button* event(SDL_Event &event); /// Add a button to the panel. - /** @Param tag: Can be used to identify a button. */ + /** @param tag: Can be used to identify a button. */ void additem(Button* pbutton, int tag); /// Set the default size of contained buttons. void set_button_size(int w, int h); |