}
if(show_menu)
+ {
menu_process_current();
+ mouse_cursor->draw();
+ }
/* (Update it all!) */
updatescreen();
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;
#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;
break;
}
}
+ mouse_cursor->draw();
}
if(done)
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;
}
}
-/* 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));
}
}
- 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,
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. */
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*/
}
#include "texture.h"
#include "timer.h"
#include "type.h"
+#include "mousecursor.h"
/* Kinds of menu items */
enum MenuItemKind {
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;
int num_items;
Menu* last_menu;
+ int width();
+ int height();
public:
timer_type effect;
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()
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);
}
~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;
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)
texture_free(&arrow_left);
texture_free(&arrow_right);
+ /* Free mouse-cursor */
+ delete mouse_cursor;
+
/* Free menus */
delete main_menu;
delete game_menu;
unsigned char alpha;
};
+
class TileManager
{
private:
}
};
+
+
#endif
process_save_load_game_menu(false);
}
+ mouse_cursor->draw();
+
flipscreen();
/* Set the time of the last update and the time of the current update */
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)