Skip to content
Snippets Groups Projects
Commit b0accb87 authored by deuce's avatar deuce
Browse files

Fix error where SDL mode would not get button up events.

Add support for scroll "buttons" (buttons 4 and 5).
parent 9f8f328f
No related branches found
No related tags found
No related merge requests found
...@@ -568,6 +568,8 @@ CIOLIBEXPORT void CIOLIBCALL ansi_ciolib_setdoorway(int enable); ...@@ -568,6 +568,8 @@ CIOLIBEXPORT void CIOLIBCALL ansi_ciolib_setdoorway(int enable);
#define CIOLIB_BUTTON_1 1 #define CIOLIB_BUTTON_1 1
#define CIOLIB_BUTTON_2 2 #define CIOLIB_BUTTON_2 2
#define CIOLIB_BUTTON_3 4 #define CIOLIB_BUTTON_3 4
#define CIOLIB_BUTTON_4 8
#define CIOLIB_BUTTON_5 16
#define CIOLIB_BUTTON(x) (1<<(x-1)) #define CIOLIB_BUTTON(x) (1<<(x-1))
...@@ -599,7 +601,25 @@ enum { ...@@ -599,7 +601,25 @@ enum {
,CIOLIB_BUTTON_3_QUAD_CLICK ,CIOLIB_BUTTON_3_QUAD_CLICK
,CIOLIB_BUTTON_3_DRAG_START ,CIOLIB_BUTTON_3_DRAG_START
,CIOLIB_BUTTON_3_DRAG_MOVE ,CIOLIB_BUTTON_3_DRAG_MOVE
,CIOLIB_BUTTON_3_DRAG_END /* 27 */ ,CIOLIB_BUTTON_3_DRAG_END
,CIOLIB_BUTTON_4_PRESS
,CIOLIB_BUTTON_4_RELEASE
,CIOLIB_BUTTON_4_CLICK /* 30 */
,CIOLIB_BUTTON_4_DBL_CLICK
,CIOLIB_BUTTON_4_TRPL_CLICK
,CIOLIB_BUTTON_4_QUAD_CLICK
,CIOLIB_BUTTON_4_DRAG_START
,CIOLIB_BUTTON_4_DRAG_MOVE
,CIOLIB_BUTTON_4_DRAG_END
,CIOLIB_BUTTON_5_PRESS
,CIOLIB_BUTTON_5_RELEASE
,CIOLIB_BUTTON_5_CLICK
,CIOLIB_BUTTON_5_DBL_CLICK /* 40 */
,CIOLIB_BUTTON_5_TRPL_CLICK
,CIOLIB_BUTTON_5_QUAD_CLICK
,CIOLIB_BUTTON_5_DRAG_START
,CIOLIB_BUTTON_5_DRAG_MOVE
,CIOLIB_BUTTON_5_DRAG_END /* 45 */
}; };
#define CIOLIB_BUTTON_PRESS(x) ((x-1)*9+1) #define CIOLIB_BUTTON_PRESS(x) ((x-1)*9+1)
...@@ -628,11 +648,11 @@ CIOLIBEXPORT int CIOLIBCALL mouse_pending(void); ...@@ -628,11 +648,11 @@ CIOLIBEXPORT int CIOLIBCALL mouse_pending(void);
CIOLIBEXPORT int CIOLIBCALL ciolib_getmouse(struct mouse_event *mevent); CIOLIBEXPORT int CIOLIBCALL ciolib_getmouse(struct mouse_event *mevent);
CIOLIBEXPORT int CIOLIBCALL ciolib_ungetmouse(struct mouse_event *mevent); CIOLIBEXPORT int CIOLIBCALL ciolib_ungetmouse(struct mouse_event *mevent);
CIOLIBEXPORT void ciolib_mouse_thread(void *data); CIOLIBEXPORT void ciolib_mouse_thread(void *data);
CIOLIBEXPORT int CIOLIBCALL ciomouse_setevents(int events); CIOLIBEXPORT uint64_t CIOLIBCALL ciomouse_setevents(uint64_t events);
CIOLIBEXPORT int CIOLIBCALL ciomouse_addevents(int events); CIOLIBEXPORT uint64_t CIOLIBCALL ciomouse_addevents(uint64_t events);
CIOLIBEXPORT int CIOLIBCALL ciomouse_delevents(int events); CIOLIBEXPORT uint64_t CIOLIBCALL ciomouse_delevents(uint64_t events);
CIOLIBEXPORT int CIOLIBCALL ciomouse_addevent(int event); CIOLIBEXPORT uint64_t CIOLIBCALL ciomouse_addevent(uint64_t event);
CIOLIBEXPORT int CIOLIBCALL ciomouse_delevent(int event); CIOLIBEXPORT uint64_t CIOLIBCALL ciomouse_delevent(uint64_t event);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
......
...@@ -894,13 +894,19 @@ int curs_initciolib(long inmode) ...@@ -894,13 +894,19 @@ int curs_initciolib(long inmode)
} }
mode = inmode; mode = inmode;
#ifdef NCURSES_VERSION_MAJOR #ifdef NCURSES_VERSION_MAJOR
if(mousemask(BUTTON1_PRESSED|BUTTON1_RELEASED|BUTTON2_PRESSED|BUTTON2_RELEASED|BUTTON3_PRESSED|BUTTON3_RELEASED|REPORT_MOUSE_POSITION,NULL)==(BUTTON1_PRESSED|BUTTON1_RELEASED|BUTTON2_PRESSED|BUTTON2_RELEASED|BUTTON3_PRESSED|BUTTON3_RELEASED|REPORT_MOUSE_POSITION)) { {
mmask_t msk = BUTTON1_PRESSED|BUTTON1_RELEASED|BUTTON2_PRESSED|BUTTON2_RELEASED|BUTTON3_PRESSED|BUTTON3_RELEASED|REPORT_MOUSE_POSITION;
#ifdef BUTTON5_PRESSED
msk |= BUTTON4_PRESSED|BUTTON5_PRESSED;
#endif
if (mousemask(msk, NULL) == msk) {
mouseinterval(0); mouseinterval(0);
cio_api.mouse=1; cio_api.mouse=1;
} }
else { else {
mousemask(0,NULL); mousemask(0,NULL);
} }
}
#endif #endif
if (COLORS >= 16) if (COLORS >= 16)
...@@ -1139,6 +1145,14 @@ int curs_getch(void) ...@@ -1139,6 +1145,14 @@ int curs_getch(void)
case BUTTON3_RELEASED: case BUTTON3_RELEASED:
evnt=CIOLIB_BUTTON_3_RELEASE; evnt=CIOLIB_BUTTON_3_RELEASE;
break; break;
#ifdef BUTTON5_PRESSED
case BUTTON4_PRESSED:
evnt=CIOLIB_BUTTON_4_PRESS;
break;
case BUTTON5_PRESSED:
evnt=CIOLIB_BUTTON_5_PRESS;
break;
#endif
case REPORT_MOUSE_POSITION: case REPORT_MOUSE_POSITION:
evnt=CIOLIB_MOUSE_MOVE; evnt=CIOLIB_MOUSE_MOVE;
break; break;
......
...@@ -80,10 +80,10 @@ struct mouse_state { ...@@ -80,10 +80,10 @@ struct mouse_state {
int knownbuttonstatemask; /* Mask of buttons that have done something since int knownbuttonstatemask; /* Mask of buttons that have done something since
* We started watching... the rest are actually in * We started watching... the rest are actually in
* an unknown state */ * an unknown state */
int button_state[3]; /* Expanded state of each button */ int button_state[5]; /* Expanded state of each button */
int button_x[3]; /* Start X/Y position of the current state */ int button_x[5]; /* Start X/Y position of the current state */
int button_y[3]; int button_y[5];
clock_t timeout[3]; /* Button event timeouts (timespecs ie: time of expiry) */ clock_t timeout[5]; /* Button event timeouts (timespecs ie: time of expiry) */
int curx; /* Current X position */ int curx; /* Current X position */
int cury; /* Current Y position */ int cury; /* Current Y position */
int events; /* Currently enabled events */ int events; /* Currently enabled events */
...@@ -95,7 +95,7 @@ struct mouse_state { ...@@ -95,7 +95,7 @@ struct mouse_state {
}; };
struct mouse_state state; struct mouse_state state;
int mouse_events=0; uint64_t mouse_events=0;
int ciolib_mouse_initialized=0; int ciolib_mouse_initialized=0;
static int ungot=0; static int ungot=0;
pthread_mutex_t unget_mutex; pthread_mutex_t unget_mutex;
...@@ -111,33 +111,33 @@ void CIOLIBCALL init_mouse(void) ...@@ -111,33 +111,33 @@ void CIOLIBCALL init_mouse(void)
ciolib_mouse_initialized=1; ciolib_mouse_initialized=1;
} }
int CIOLIBCALL ciomouse_setevents(int events) uint64_t CIOLIBCALL ciomouse_setevents(uint64_t events)
{ {
mouse_events=events; mouse_events=events;
return mouse_events; return mouse_events;
} }
int CIOLIBCALL ciomouse_addevents(int events) uint64_t CIOLIBCALL ciomouse_addevents(uint64_t events)
{ {
mouse_events |= events; mouse_events |= events;
return mouse_events; return mouse_events;
} }
int CIOLIBCALL ciomouse_delevents(int events) uint64_t CIOLIBCALL ciomouse_delevents(uint64_t events)
{ {
mouse_events &= ~events; mouse_events &= ~events;
return mouse_events; return mouse_events;
} }
int CIOLIBCALL ciomouse_addevent(int event) uint64_t CIOLIBCALL ciomouse_addevent(uint64_t event)
{ {
mouse_events |= (1<<event); mouse_events |= (UINT64_C(1)<<event);
return mouse_events; return mouse_events;
} }
int CIOLIBCALL ciomouse_delevent(int event) uint64_t CIOLIBCALL ciomouse_delevent(uint64_t event)
{ {
mouse_events &= ~(1<<event); mouse_events &= ~(UINT64_C(1)<<event);
return mouse_events; return mouse_events;
} }
...@@ -164,7 +164,7 @@ void CIOLIBCALL add_outevent(int event, int x, int y) ...@@ -164,7 +164,7 @@ void CIOLIBCALL add_outevent(int event, int x, int y)
struct out_mouse_event *ome; struct out_mouse_event *ome;
int but; int but;
if(!(mouse_events & 1<<event)) if(!(mouse_events & UINT64_C(1)<<event))
return; return;
ome=(struct out_mouse_event *)malloc(sizeof(struct out_mouse_event)); ome=(struct out_mouse_event *)malloc(sizeof(struct out_mouse_event));
...@@ -187,19 +187,19 @@ int CIOLIBCALL more_multies(int button, int clicks) ...@@ -187,19 +187,19 @@ int CIOLIBCALL more_multies(int button, int clicks)
{ {
switch(clicks) { switch(clicks) {
case 0: case 0:
if(mouse_events & (1<<CIOLIB_BUTTON_CLICK(button))) if(mouse_events & (UINT64_C(1)<<CIOLIB_BUTTON_CLICK(button)))
return(1); return(1);
/* Fall-through */ /* Fall-through */
case 1: case 1:
if(mouse_events & (1<<CIOLIB_BUTTON_DBL_CLICK(button))) if(mouse_events & (UINT64_C(1)<<CIOLIB_BUTTON_DBL_CLICK(button)))
return(1); return(1);
/* Fall-through */ /* Fall-through */
case 2: case 2:
if(mouse_events & (1<<CIOLIB_BUTTON_TRPL_CLICK(button))) if(mouse_events & (UINT64_C(1)<<CIOLIB_BUTTON_TRPL_CLICK(button)))
return(1); return(1);
/* Fall-through */ /* Fall-through */
case 3: case 3:
if(mouse_events & (1<<CIOLIB_BUTTON_QUAD_CLICK(button))) if(mouse_events & (UINT64_C(1)<<CIOLIB_BUTTON_QUAD_CLICK(button)))
return(1); return(1);
/* Fall-through */ /* Fall-through */
} }
...@@ -280,13 +280,18 @@ void ciolib_mouse_thread(void *data) ...@@ -280,13 +280,18 @@ void ciolib_mouse_thread(void *data)
continue; continue;
} }
but=CIOLIB_BUTTON_NUMBER(in->event); but=CIOLIB_BUTTON_NUMBER(in->event);
if (in->x < 0)
in->x = state.curx;
if (in->y < 0)
in->y = state.curx;
switch(CIOLIB_BUTTON_BASE(in->event)) { switch(CIOLIB_BUTTON_BASE(in->event)) {
case CIOLIB_MOUSE_MOVE: case CIOLIB_MOUSE_MOVE:
if(in->x==state.curx if(in->x==state.curx
&& in->y==state.cury) && in->y==state.cury)
break; break;
add_outevent(CIOLIB_MOUSE_MOVE,in->x,in->y); add_outevent(CIOLIB_MOUSE_MOVE,in->x,in->y);
for(but=1;but<=3;but++) { for(but=1;but<=5;but++) {
switch(state.button_state[but-1]) { switch(state.button_state[but-1]) {
case MOUSE_NOSTATE: case MOUSE_NOSTATE:
if(state.buttonstate & CIOLIB_BUTTON(but)) { if(state.buttonstate & CIOLIB_BUTTON(but)) {
...@@ -354,6 +359,9 @@ void ciolib_mouse_thread(void *data) ...@@ -354,6 +359,9 @@ void ciolib_mouse_thread(void *data)
state.button_state[but-1]=MOUSE_NOSTATE; state.button_state[but-1]=MOUSE_NOSTATE;
state.timeout[but-1]=0; state.timeout[but-1]=0;
} }
// Scroll "buttons"...
if (but > 3)
state.button_state[but-1] = MOUSE_NOSTATE;
break; break;
case MOUSE_CLICKED: case MOUSE_CLICKED:
state.button_state[but-1]=MOUSE_DOUBLEPRESSED; state.button_state[but-1]=MOUSE_DOUBLEPRESSED;
...@@ -427,13 +435,13 @@ void ciolib_mouse_thread(void *data) ...@@ -427,13 +435,13 @@ void ciolib_mouse_thread(void *data)
} }
timeout_button=0; timeout_button=0;
for(but=1;but<=3;but++) { for(but=1;but<=5;but++) {
if(state.button_state[but-1]==MOUSE_DRAGSTARTED && if(state.button_state[but-1]==MOUSE_DRAGSTARTED &&
(mouse_events & ((1<<CIOLIB_BUTTON_DRAG_START(but)) | (1<<CIOLIB_BUTTON_DRAG_MOVE(but)) | (1<<CIOLIB_BUTTON_DRAG_END(but)))) == 0) (mouse_events & ((UINT64_C(1)<<CIOLIB_BUTTON_DRAG_START(but)) | (UINT64_C(1)<<CIOLIB_BUTTON_DRAG_MOVE(but)) | (UINT64_C(1)<<CIOLIB_BUTTON_DRAG_END(but)))) == 0)
state.button_state[but-1] = MOUSE_NOSTATE; state.button_state[but-1] = MOUSE_NOSTATE;
} }
for(but=1;but<=3;but++) { for(but=1;but<=5;but++) {
if(state.button_state[but-1]!=MOUSE_NOSTATE if(state.button_state[but-1]!=MOUSE_NOSTATE
&& state.button_state[but-1]!=MOUSE_DRAGSTARTED && state.button_state[but-1]!=MOUSE_DRAGSTARTED
&& state.timeout[but-1]!=0 && state.timeout[but-1]!=0
......
...@@ -863,6 +863,18 @@ void sdl_video_event_thread(void *data) ...@@ -863,6 +863,18 @@ void sdl_video_event_thread(void *data)
break; break;
} }
break; break;
case SDL_MOUSEWHEEL:
if (!ciolib_mouse_initialized)
break;
if (ev.wheel.y) {
if (ev.wheel.direction == SDL_MOUSEWHEEL_FLIPPED)
ev.wheel.y = 0 - ev.wheel.y;
if (ev.wheel.y > 0)
ciomouse_gotevent(CIOLIB_BUTTON_PRESS(4), -1, -1);
if (ev.wheel.y < 0)
ciomouse_gotevent(CIOLIB_BUTTON_PRESS(5), -1, -1);
}
break;
case SDL_MOUSEBUTTONUP: case SDL_MOUSEBUTTONUP:
if(!ciolib_mouse_initialized) if(!ciolib_mouse_initialized)
break; break;
......
...@@ -334,6 +334,7 @@ static int win32_keyboardio(int isgetch) ...@@ -334,6 +334,7 @@ static int win32_keyboardio(int isgetch)
LastY=input.Event.MouseEvent.dwMousePosition.Y+1; LastY=input.Event.MouseEvent.dwMousePosition.Y+1;
ciomouse_gotevent(CIOLIB_MOUSE_MOVE,LastX,LastY); ciomouse_gotevent(CIOLIB_MOUSE_MOVE,LastX,LastY);
} }
if (input.Event.MouseEvent.dwEventFlags == 0) {
if(last_state != input.Event.MouseEvent.dwButtonState) { if(last_state != input.Event.MouseEvent.dwButtonState) {
switch(input.Event.MouseEvent.dwButtonState ^ last_state) { switch(input.Event.MouseEvent.dwButtonState ^ last_state) {
case FROM_LEFT_1ST_BUTTON_PRESSED: case FROM_LEFT_1ST_BUTTON_PRESSED:
...@@ -358,6 +359,16 @@ static int win32_keyboardio(int isgetch) ...@@ -358,6 +359,16 @@ static int win32_keyboardio(int isgetch)
last_state=input.Event.MouseEvent.dwButtonState; last_state=input.Event.MouseEvent.dwButtonState;
} }
} }
else if (input.Event.MouseEvent.dwEventFlags == MOUSE_WHEELED) {
// If the high word of the dwButtonState member contains a positive value... ARGH!
if (input.Event.MouseEvent.dwButtonState & 0x80000000) {
ciomouse_gotevent(CIOLIB_BUTTON_5_PRESS,input.Event.MouseEvent.dwMousePosition.X+1,input.Event.MouseEvent.dwMousePosition.Y+1);
}
else {
ciomouse_gotevent(CIOLIB_BUTTON_4_PRESS,input.Event.MouseEvent.dwMousePosition.X+1,input.Event.MouseEvent.dwMousePosition.Y+1);
}
}
}
} }
} }
} }
......
...@@ -818,7 +818,7 @@ static int x11_event(XEvent *ev) ...@@ -818,7 +818,7 @@ static int x11_event(XEvent *ev)
be->x=x_cvstat.cols; be->x=x_cvstat.cols;
if(be->y>x_cvstat.rows+1) if(be->y>x_cvstat.rows+1)
be->y=x_cvstat.rows+1; be->y=x_cvstat.rows+1;
if (be->button <= 3) { if (be->button <= 5) {
ciomouse_gotevent(CIOLIB_BUTTON_PRESS(be->button),be->x,be->y); ciomouse_gotevent(CIOLIB_BUTTON_PRESS(be->button),be->x,be->y);
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment