summaryrefslogtreecommitdiff
path: root/src/client
diff options
context:
space:
mode:
Diffstat (limited to 'src/client')
-rw-r--r--src/client/game.c3
-rw-r--r--src/client/interface.c7
-rw-r--r--src/client/mouse_buffer.c135
-rw-r--r--src/client/mouse_buffer.h20
4 files changed, 164 insertions, 1 deletions
diff --git a/src/client/game.c b/src/client/game.c
index 4ff8724..12dff3a 100644
--- a/src/client/game.c
+++ b/src/client/game.c
@@ -22,6 +22,7 @@
#include "settingKeys.h"
#include "panel.h"
#include "radar.h"
+#include "mouse_buffer.h"
#ifndef NO_SOUND
#include "audio.h"
@@ -45,6 +46,7 @@ static void initGame()
{
home_director_create();
+ mouse_buffer_init();
interface_init();
font_init();
layer_init();
@@ -76,6 +78,7 @@ static void initGame()
void game_quit()
{
+ mouse_buffer_quit();
interface_quit();
main_menu_quit();
diff --git a/src/client/interface.c b/src/client/interface.c
index e8f1971..9907862 100644
--- a/src/client/interface.c
+++ b/src/client/interface.c
@@ -7,7 +7,7 @@
#include "screen.h"
#include "keyboardBuffer.h"
#include "hotKey.h"
-
+#include "mouse_buffer.h"
static SDL_Surface *screen; /* window surface */
/*static SDL_Surface *my_surface;*/
@@ -278,6 +278,10 @@ int eventAction()
while (SDL_WaitEvent(&event)) {
switch (event.type) {
+ case SDL_MOUSEBUTTONDOWN:
+ mouse_buffer_event(&event.button);
+ break;
+
case SDL_KEYDOWN:
switch (event.key.keysym.sym) {
default:
@@ -300,6 +304,7 @@ int eventAction()
screen_event();
hot_key_event();
screen_switch();
+ mouse_buffer_clean();
break;
default:
diff --git a/src/client/mouse_buffer.c b/src/client/mouse_buffer.c
new file mode 100644
index 0000000..9888c44
--- /dev/null
+++ b/src/client/mouse_buffer.c
@@ -0,0 +1,135 @@
+#include <SDL.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <assert.h>
+
+#include "main.h"
+#include "list.h"
+#include "mouse_buffer.h"
+
+static list_t *list_event;
+
+typedef struct mouse_event_struct
+{
+ Uint8 button;
+ int x;
+ int y;
+} mouse_event_t;
+
+static mouse_event_t* mouse_event_new(int x, int y, Uint8 button)
+{
+ mouse_event_t *mouse_event;
+
+ mouse_event = malloc(sizeof(mouse_event_t));
+ mouse_event->x = x;
+ mouse_event->y = y;
+ mouse_event->button = button;
+
+ return mouse_event;
+}
+
+static void mouse_event_destroy(mouse_event_t *mouse_event)
+{
+ assert(mouse_event != NULL);
+ free(mouse_event);
+}
+
+int mouse_buffer_init()
+{
+ list_event = list_new();
+
+ return 0;
+}
+
+int mouse_buffer_event(SDL_MouseButtonEvent *button)
+{
+ assert(button != NULL);
+ assert(list_event != NULL);
+
+ switch(button->button) {
+ case SDL_BUTTON_LEFT:
+ case SDL_BUTTON_RIGHT:
+ //printf("mouse button - pos(%d,%d)\n", button->x, button->y);
+
+ list_add(list_event, mouse_event_new(button->x, button->y, button->button));
+
+ return 1;
+ break;
+
+ default:
+ break;
+ }
+
+ return 0;
+}
+
+int mouse_buffer_clean()
+{
+ assert(list_event != NULL);
+ list_do_empty(list_event);
+
+ return 0;
+}
+
+bool_t mouse_buffer_is_on_area(int x, int y, int w, int h, unsigned int flag)
+{
+ mouse_event_t *mouse_event;
+ int i;
+
+ assert(list_event != NULL);
+
+ if (flag & MOUSE_BUF_MOTION) {
+ int mouse_x, mouse_y;
+
+ SDL_GetMouseState(&mouse_x, &mouse_y);
+
+ if (mouse_x >= x && mouse_y >= y &&
+ mouse_x < x+w && mouse_y < y+h) {
+ return TRUE;
+ }
+ } else {
+ for (i = 0; i<list_event->count; i++) {
+ mouse_event = (mouse_event_t *)list_event->list[i];
+
+ if ((mouse_event->x >= x && mouse_event->y >= y && mouse_event->x < x+w && mouse_event->y < y+h) ||
+ (flag & MOUSE_BUF_AREA_NONE)) {
+ if (flag & MOUSE_BUF_CLICK_LEFT) {
+ if (mouse_event->button == SDL_BUTTON_LEFT) {
+ return TRUE;
+ } else {
+ return FALSE;
+ }
+ }
+
+ if (flag & MOUSE_BUF_CLICK_RIGHT) {
+ if (mouse_event->button == SDL_BUTTON_RIGHT) {
+ return TRUE;
+ } else {
+ return FALSE;
+ }
+ }
+
+ if (flag & MOUSE_BUF_CLICK) {
+ if (mouse_event->button == SDL_BUTTON_LEFT || mouse_event->button == SDL_BUTTON_RIGHT) {
+ return TRUE;
+ } else {
+ return FALSE;
+ }
+ }
+
+ return TRUE;
+ }
+ }
+ }
+
+ return FALSE;
+}
+
+int mouse_buffer_quit()
+{
+ assert(list_event != NULL);
+ list_destroy_item(list_event, mouse_event_destroy);
+
+ return 0;
+}
diff --git a/src/client/mouse_buffer.h b/src/client/mouse_buffer.h
new file mode 100644
index 0000000..75fe549
--- /dev/null
+++ b/src/client/mouse_buffer.h
@@ -0,0 +1,20 @@
+#ifndef MOUSE_EVENT_H
+#define MOUSE_EVENT_H
+
+#include <SDL.h>
+
+#define MOUSE_BUF_MOTION 1
+#define MOUSE_BUF_CLICK_LEFT 2
+#define MOUSE_BUF_CLICK_RIGHT 4
+#define MOUSE_BUF_CLICK 8
+#define MOUSE_BUF_AREA_NONE 16
+
+extern int mouse_buffer_init();
+extern int mouse_buffer_event(SDL_MouseButtonEvent *button);
+extern int mouse_buffer_clean();
+extern bool_t mouse_buffer_is_on_area(int x, int y, int w, int h, unsigned int flag);
+extern int mouse_buffer_quit();
+
+#endif
+
+