[Super-tux-commit] supertux/src gameloop.cpp,1.34,1.35 globals.cpp,1.6,1.7 globals.h,1.19,1.20 level
Brought to you by:
wkendrick
From: Tobias Gl??er <to...@us...> - 2004-03-28 01:11:29
|
Update of /cvsroot/super-tux/supertux/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23846/src Modified Files: gameloop.cpp globals.cpp globals.h leveleditor.cpp menu.cpp menu.h mousecursor.cpp mousecursor.h setup.cpp tile.h title.cpp Log Message: We have our own mouse-cursor now! (graphics by Settra Gaia) Index: tile.h =================================================================== RCS file: /cvsroot/super-tux/supertux/src/tile.h,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- tile.h 25 Mar 2004 10:26:07 -0000 1.3 +++ tile.h 28 Mar 2004 01:00:16 -0000 1.4 @@ -55,6 +55,7 @@ unsigned char alpha; }; + class TileManager { private: @@ -80,4 +81,6 @@ } }; + + #endif Index: mousecursor.h =================================================================== RCS file: /cvsroot/super-tux/supertux/src/mousecursor.h,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- mousecursor.h 26 Mar 2004 23:54:47 -0000 1.1 +++ mousecursor.h 28 Mar 2004 01:00:16 -0000 1.2 @@ -33,9 +33,10 @@ ~MouseCursor(); int state(); void set_state(int nstate); - void draw(int x, int y); + void draw(); private: + int state_before_click; int cur_state; int cur_frame, tot_frames; texture_type cursor; Index: globals.h =================================================================== RCS file: /cvsroot/super-tux/supertux/src/globals.h,v retrieving revision 1.19 retrieving revision 1.20 diff -u -d -r1.19 -r1.20 --- globals.h 24 Mar 2004 14:35:11 -0000 1.19 +++ globals.h 28 Mar 2004 01:00:16 -0000 1.20 @@ -18,12 +18,15 @@ #include <SDL.h> #include "text.h" #include "menu.h" +#include "mousecursor.h" extern std::string datadir; extern SDL_Surface * screen; extern text_type black_text, gold_text, white_text, white_small_text, white_big_text, blue_text, red_text, yellow_nums; +extern MouseCursor * mouse_cursor; + extern bool use_gl; extern bool use_joystick; extern bool use_fullscreen; Index: gameloop.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/gameloop.cpp,v retrieving revision 1.34 retrieving revision 1.35 diff -u -d -r1.34 -r1.35 --- gameloop.cpp 27 Mar 2004 17:24:14 -0000 1.34 +++ gameloop.cpp 28 Mar 2004 01:00:16 -0000 1.35 @@ -570,7 +570,10 @@ } if(show_menu) + { menu_process_current(); + mouse_cursor->draw(); + } /* (Update it all!) */ updatescreen(); Index: menu.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/menu.cpp,v retrieving revision 1.19 retrieving revision 1.20 diff -u -d -r1.19 -r1.20 --- menu.cpp 27 Mar 2004 17:24:14 -0000 1.19 +++ menu.cpp 28 Mar 2004 01:00:16 -0000 1.20 @@ -456,16 +456,11 @@ } } -/* Draw the current menu. */ -void -Menu::draw() +int Menu::width() { - int menu_height; - int menu_width; - /* The width of the menu has to be more than the width of the text with the most characters */ - menu_width = 0; + int menu_width = 0; for(int i = 0; i < num_items; ++i) { int w = strlen(item[i].text) + (item[i].input ? strlen(item[i].input) + 1 : 0) + strlen(string_list_active(item[i].list)); @@ -477,8 +472,20 @@ } } - menu_width = menu_width * 16 + 48; - menu_height = (num_items) * 24; + return (menu_width * 16 + 48); +} + +int Menu::height() +{ + return ((num_items) * 24); +} + +/* Draw the current menu. */ +void +Menu::draw() +{ + int menu_height = height(); + int menu_width = width(); /* Draw a transparent background */ fillrect(pos_x - menu_width/2, @@ -524,11 +531,12 @@ SDLKey key; switch(event.type) { - case SDL_KEYDOWN: + case SDL_KEYDOWN: key = event.key.keysym.sym; SDLMod keymod; char ch[2]; keymod = SDL_GetModState(); + int x,y; /* If the current unicode character is an ASCII character, assign it to ch. */ @@ -604,18 +612,37 @@ case SDL_JOYBUTTONDOWN: menuaction = MENU_ACTION_HIT; break; + case SDL_MOUSEBUTTONDOWN: + x = event.motion.x; + y = event.motion.y; + if(x > current_menu->pos_x - current_menu->width()/2 && + x < current_menu->pos_x + current_menu->width()/2 && + y > current_menu->pos_y - current_menu->height()/2 && + y < current_menu->pos_y + current_menu->height()/2) + { + menuaction = MENU_ACTION_HIT; + } + break; + case SDL_MOUSEMOTION: + x = event.motion.x; + y = event.motion.y; + if(x > current_menu->pos_x - current_menu->width()/2 && + x < current_menu->pos_x + current_menu->width()/2 && + y > current_menu->pos_y - current_menu->height()/2 && + y < current_menu->pos_y + current_menu->height()/2) + { + current_menu->active_item = (y - (current_menu->pos_y - current_menu->height()/2)) / 24; + menu_change = true; + mouse_cursor->set_state(MC_LINK); + } + else + { + mouse_cursor->set_state(MC_NORMAL); + } + break; default: break; } - /* FIXME: NO JOYSTICK SUPPORT */ - /*#ifdef JOY_YES - else if (event.type == SDL_JOYBUTTONDOWN) - { - Joystick button: Continue: - - done = 1; - } - #endif*/ } Index: setup.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/setup.cpp,v retrieving revision 1.20 retrieving revision 1.21 diff -u -d -r1.20 -r1.21 --- setup.cpp 27 Mar 2004 17:24:14 -0000 1.20 +++ setup.cpp 28 Mar 2004 01:00:16 -0000 1.21 @@ -545,6 +545,9 @@ texture_load(&arrow_left, datadir + "/images/icons/left.png", USE_ALPHA); texture_load(&arrow_right, datadir + "/images/icons/right.png", USE_ALPHA); + /* Load the mouse-cursor */ + mouse_cursor = new MouseCursor( datadir + "/images/status/mousecursor.png",1); + } void st_general_free(void) @@ -567,6 +570,9 @@ texture_free(&arrow_left); texture_free(&arrow_right); + /* Free mouse-cursor */ + delete mouse_cursor; + /* Free menus */ delete main_menu; delete game_menu; Index: menu.h =================================================================== RCS file: /cvsroot/super-tux/supertux/src/menu.h,v retrieving revision 1.22 retrieving revision 1.23 diff -u -d -r1.22 -r1.23 --- menu.h 27 Mar 2004 17:24:14 -0000 1.22 +++ menu.h 28 Mar 2004 01:00:16 -0000 1.23 @@ -17,6 +17,7 @@ #include "texture.h" #include "timer.h" #include "type.h" +#include "mousecursor.h" /* Kinds of menu items */ enum MenuItemKind { @@ -51,6 +52,8 @@ class Menu { +friend void menu_event(SDL_Event& event); + private: // position of the menu (ie. center of the menu, not top/left) int pos_x; @@ -58,6 +61,8 @@ int num_items; Menu* last_menu; + int width(); + int height(); public: timer_type effect; Index: globals.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/globals.cpp,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- globals.cpp 22 Mar 2004 15:47:31 -0000 1.6 +++ globals.cpp 28 Mar 2004 01:00:16 -0000 1.7 @@ -18,6 +18,8 @@ SDL_Surface * screen; text_type black_text, gold_text, blue_text, red_text, yellow_nums, white_text, white_small_text, white_big_text; +MouseCursor * mouse_cursor; + bool use_gl; bool use_joystick; bool use_fullscreen; Index: leveleditor.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/leveleditor.cpp,v retrieving revision 1.22 retrieving revision 1.23 diff -u -d -r1.22 -r1.23 --- leveleditor.cpp 27 Mar 2004 17:24:14 -0000 1.22 +++ leveleditor.cpp 28 Mar 2004 01:00:16 -0000 1.23 @@ -275,6 +275,7 @@ break; } } + mouse_cursor->draw(); } if(done) @@ -849,18 +850,19 @@ while(SDL_PollEvent(&event)) { + if(show_menu) + menu_event(event); + /* testing SDL_KEYDOWN, SDL_KEYUP and SDL_QUIT events*/ if(event.type == SDL_KEYDOWN || ((event.type == SDL_MOUSEBUTTONDOWN || SDL_MOUSEMOTION) && (event.motion.x > 0 && event.motion.x < screen->w - 64 && event.motion.y > 0 && event.motion.y < screen->h))) { - switch(event.type) { case SDL_KEYDOWN: // key pressed key = event.key.keysym.sym; if(show_menu) { - menu_event(event); if(key == SDLK_ESCAPE) { show_menu = false; Index: mousecursor.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/mousecursor.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- mousecursor.cpp 26 Mar 2004 23:54:47 -0000 1.1 +++ mousecursor.cpp 28 Mar 2004 01:00:16 -0000 1.2 @@ -15,16 +15,16 @@ MouseCursor::MouseCursor(std::string cursor_file, int frames) { -texture_load(&cursor,cursor_file.c_str(),USE_ALPHA); + texture_load(&cursor,cursor_file.c_str(),USE_ALPHA); -cur_state = MC_NORMAL; -cur_frame = 0; -tot_frames = frames; + cur_state = MC_NORMAL; + cur_frame = 0; + tot_frames = frames; -timer_init(&timer, false); -timer_start(&timer,MC_FRAME_PERIOD); + timer_init(&timer, false); + timer_start(&timer,MC_FRAME_PERIOD); -SDL_ShowCursor(SDL_DISABLE); + SDL_ShowCursor(SDL_DISABLE); } MouseCursor::~MouseCursor() @@ -36,28 +36,42 @@ int MouseCursor::state() { -return cur_state; + return cur_state; } void MouseCursor::set_state(int nstate) { -cur_state = nstate; + cur_state = nstate; } -void MouseCursor::draw(int x, int y) +void MouseCursor::draw() { -int w,h; -w = cursor.w / tot_frames; -h = cursor.h / MC_STATES_NB; + int x,y,w,h; + Uint8 ispressed = SDL_GetMouseState(&x,&y); + w = cursor.w / tot_frames; + h = cursor.h / MC_STATES_NB; + if(ispressed &SDL_BUTTON(1) || ispressed &SDL_BUTTON(2)) + { + if(cur_state != MC_CLICK) + { + state_before_click = cur_state; + cur_state = MC_CLICK; + } + } + else + { + if(cur_state == MC_CLICK) + cur_state = state_before_click; + } -if(timer_get_left(&timer) < 0 && tot_frames > 1) - { - cur_frame++; - if(cur_frame++ >= tot_frames) - cur_frame = 0; + if(timer_get_left(&timer) < 0 && tot_frames > 1) + { + cur_frame++; + if(cur_frame++ >= tot_frames) + cur_frame = 0; - timer_start(&timer,MC_FRAME_PERIOD); - } + timer_start(&timer,MC_FRAME_PERIOD); + } -texture_draw_part(&cursor, w*cur_frame, h*cur_state , x, y, w, h); + texture_draw_part(&cursor, w*cur_frame, h*cur_state , x, y, w, h); } Index: title.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/title.cpp,v retrieving revision 1.14 retrieving revision 1.15 diff -u -d -r1.14 -r1.15 --- title.cpp 27 Mar 2004 17:24:14 -0000 1.14 +++ title.cpp 28 Mar 2004 01:00:16 -0000 1.15 @@ -326,6 +326,8 @@ process_save_load_game_menu(false); } + mouse_cursor->draw(); + flipscreen(); /* Set the time of the last update and the time of the current update */ @@ -461,7 +463,7 @@ texture_draw_part(&bkg_title, 0, 0, 0, 0, 640, 130); - + flipscreen(); if(60+screen->h+(n*18)+(d*18)-scroll < 0 && 20+60+screen->h+(n*18)+(d*18)-scroll < 0) |