mirror of
https://github.com/VARCem/PDCurses.git
synced 2026-09-24 07:45:21 +00:00
The rest of the ncurses mouse interface. Could use some tweaking, but
basically it works. Define NCURSES_MOUSE_VERSION (preferably to 2 or more) when compiling your program (not PDCurses) to use it. Otherwise, getmouse() is nc_getmouse(), and the BUTTON_ALT etc. labels are different. Apart from that, both interfaces are active all the time, and you can mix and match, although I don't recommend it.
This commit is contained in:
72
curses.h
72
curses.h
@@ -11,7 +11,7 @@
|
||||
* See the file maintain.er for details of the current maintainer. *
|
||||
************************************************************************/
|
||||
|
||||
/* $Id: curses.h,v 1.263 2006/12/25 14:12:18 wmcbrine Exp $ */
|
||||
/* $Id: curses.h,v 1.264 2006/12/28 01:02:02 wmcbrine Exp $ */
|
||||
|
||||
/*----------------------------------------------------------------------*
|
||||
* PDCurses *
|
||||
@@ -39,7 +39,7 @@ PDCurses portable platform definitions list:
|
||||
|
||||
**man-end****************************************************************/
|
||||
|
||||
#define PDC_BUILD 2825
|
||||
#define PDC_BUILD 2826
|
||||
#define PDCURSES 1 /* PDCurses-only routines */
|
||||
#define XOPEN 1 /* X/Open Curses routines */
|
||||
#define SYSVcurses 1 /* System V Curses routines */
|
||||
@@ -296,7 +296,6 @@ extern "C"
|
||||
# define OK 0 /* general OK flag */
|
||||
#endif
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------
|
||||
*
|
||||
* PDCurses Type Declarations
|
||||
@@ -335,7 +334,6 @@ typedef struct
|
||||
int changes; /* flags indicating what has changed with the mouse */
|
||||
} MOUSE_STATUS;
|
||||
|
||||
|
||||
#define BUTTON_RELEASED 0x0000
|
||||
#define BUTTON_PRESSED 0x0001
|
||||
#define BUTTON_CLICKED 0x0002
|
||||
@@ -345,13 +343,14 @@ typedef struct
|
||||
#define WHEEL_SCROLLED 0x0006 /* PDCurses */
|
||||
#define BUTTON_ACTION_MASK 0x0007 /* PDCurses */
|
||||
|
||||
#define BUTTON_SHIFT 0x0008 /* PDCurses */
|
||||
#define BUTTON_CONTROL 0x0010 /* PDCurses */
|
||||
#define BUTTON_ALT 0x0020 /* PDCurses */
|
||||
#define PDC_BUTTON_SHIFT 0x0008 /* PDCurses */
|
||||
#define PDC_BUTTON_CONTROL 0x0010 /* PDCurses */
|
||||
#define PDC_BUTTON_ALT 0x0020 /* PDCurses */
|
||||
#define BUTTON_MODIFIER_MASK 0x0038 /* PDCurses */
|
||||
|
||||
#define MOUSE_X_POS (Mouse_status.x)
|
||||
#define MOUSE_Y_POS (Mouse_status.y)
|
||||
|
||||
/*
|
||||
* Bits associated with the .changes field:
|
||||
* 3 2 1 0
|
||||
@@ -364,10 +363,12 @@ typedef struct
|
||||
* 100000 <- mouse wheel up
|
||||
* 1000000 <- mouse wheel down
|
||||
*/
|
||||
|
||||
#define PDC_MOUSE_MOVED 0x0008
|
||||
#define PDC_MOUSE_POSITION 0x0010
|
||||
#define PDC_MOUSE_WHEEL_UP 0x0020
|
||||
#define PDC_MOUSE_WHEEL_DOWN 0x0040
|
||||
|
||||
#define A_BUTTON_CHANGED (Mouse_status.changes & 7)
|
||||
#define MOUSE_MOVED (Mouse_status.changes & PDC_MOUSE_MOVED)
|
||||
#define MOUSE_POS_REPORT (Mouse_status.changes & PDC_MOUSE_POSITION)
|
||||
@@ -377,31 +378,74 @@ typedef struct
|
||||
#define MOUSE_WHEEL_DOWN (Mouse_status.changes & PDC_MOUSE_WHEEL_DOWN)
|
||||
|
||||
/* mouse bit-masks */
|
||||
|
||||
#define BUTTON1_RELEASED 0x00000001L
|
||||
#define BUTTON1_PRESSED 0x00000002L
|
||||
#define BUTTON1_CLICKED 0x00000004L
|
||||
#define BUTTON1_DOUBLE_CLICKED 0x00000008L
|
||||
#define BUTTON1_TRIPLE_CLICKED 0x00000010L
|
||||
#define BUTTON1_MOVED 0x00000010L /* PDCurses */
|
||||
|
||||
#define BUTTON2_RELEASED 0x00000020L
|
||||
#define BUTTON2_PRESSED 0x00000040L
|
||||
#define BUTTON2_CLICKED 0x00000080L
|
||||
#define BUTTON2_DOUBLE_CLICKED 0x00000100L
|
||||
#define BUTTON2_TRIPLE_CLICKED 0x00000200L
|
||||
#define BUTTON2_MOVED 0x00000200L /* PDCurses */
|
||||
|
||||
#define BUTTON3_RELEASED 0x00000400L
|
||||
#define BUTTON3_PRESSED 0x00000800L
|
||||
#define BUTTON3_CLICKED 0x00001000L
|
||||
#define BUTTON3_DOUBLE_CLICKED 0x00002000L
|
||||
#define BUTTON3_TRIPLE_CLICKED 0x00004000L
|
||||
#define BUTTON3_MOVED 0x00004000L /* PDCurses */
|
||||
|
||||
/* For the NCurses-compatible functions only, BUTTON4_PRESSED and
|
||||
BUTTON5_PRESSED are returned for mouse scroll wheel up and down;
|
||||
otherwise PDCurses doesn't support buttons 4 and 5 */
|
||||
|
||||
#define BUTTON4_RELEASED 0x00100000L
|
||||
#define BUTTON4_PRESSED 0x00200000L
|
||||
#define BUTTON4_CLICKED 0x00400000L
|
||||
#define BUTTON4_DOUBLE_CLICKED 0x00800000L
|
||||
#define BUTTON4_TRIPLE_CLICKED 0x01000000L
|
||||
|
||||
#define BUTTON5_RELEASED 0x02000000L
|
||||
#define BUTTON5_PRESSED 0x04000000L
|
||||
#define BUTTON5_CLICKED 0x08000000L
|
||||
#define BUTTON5_DOUBLE_CLICKED 0x10000000L
|
||||
#define BUTTON5_TRIPLE_CLICKED 0x20000000L
|
||||
|
||||
#define MOUSE_WHEEL_SCROLL 0x00008000L /* PDCurses */
|
||||
#define ALL_MOUSE_EVENTS 0x0000ffffL
|
||||
#define BUTTON_MODIFIER_SHIFT 0x00010000L /* PDCurses */
|
||||
#define BUTTON_MODIFIER_CONTROL 0x00020000L /* PDCurses */
|
||||
#define BUTTON_MODIFIER_ALT 0x00040000L /* PDCurses */
|
||||
#define ALL_MOUSE_EVENTS 0x0007ffffL
|
||||
#define REPORT_MOUSE_POSITION 0x00080000L
|
||||
|
||||
/* NCurses mouse interface */
|
||||
|
||||
typedef unsigned long mmask_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
short id; /* unused, always 0 */
|
||||
int x, y, z; /* x, y same as MOUSE_STATUS; z unused */
|
||||
mmask_t bstate; /* equivalent to changes + button[], but
|
||||
in the same format as used for mousemask() */
|
||||
} MEVENT;
|
||||
|
||||
#ifdef NCURSES_MOUSE_VERSION
|
||||
# define BUTTON_SHIFT BUTTON_MODIFIER_SHIFT
|
||||
# define BUTTON_CONTROL BUTTON_MODIFIER_CONTROL
|
||||
# define BUTTON_CTRL BUTTON_MODIFIER_CONTROL
|
||||
# define BUTTON_ALT BUTTON_MODIFIER_ALT
|
||||
#else
|
||||
# define BUTTON_SHIFT PDC_BUTTON_SHIFT
|
||||
# define BUTTON_CONTROL PDC_BUTTON_CONTROL
|
||||
# define BUTTON_ALT PDC_BUTTON_ALT
|
||||
#endif
|
||||
|
||||
/*----------------------------------------------------------------------
|
||||
*
|
||||
* PDCurses Structure Definitions
|
||||
@@ -436,8 +480,6 @@ typedef struct _win /* definition of a window */
|
||||
struct _win *_parent; /* subwin's pointer to parent win */
|
||||
} WINDOW;
|
||||
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------
|
||||
*
|
||||
* Private structures that are necessary for correct
|
||||
@@ -451,7 +493,6 @@ typedef struct /* structure for ripped off lines */
|
||||
int (*init)(WINDOW *, int);
|
||||
} RIPPEDOFFLINE;
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
bool alive; /* if initscr() called, and not endwin() */
|
||||
@@ -509,7 +550,6 @@ typedef struct
|
||||
short line_color; /* color of line attributes - default -1 */
|
||||
} SCREEN;
|
||||
|
||||
|
||||
/* external variables */
|
||||
|
||||
#ifdef PDC_DLL_BUILD
|
||||
@@ -1454,7 +1494,10 @@ int use_default_colors(void);
|
||||
int wresize(WINDOW *, int, int);
|
||||
|
||||
int mouseinterval(int);
|
||||
mmask_t mousemask(mmask_t, mmask_t *);
|
||||
bool mouse_trafo(int *, int *, bool);
|
||||
int nc_getmouse(MEVENT *);
|
||||
int ungetmouse(MEVENT *);
|
||||
bool wenclose(const WINDOW *, int, int);
|
||||
bool wmouse_trafo(const WINDOW *, int *, int *, bool);
|
||||
|
||||
@@ -1505,7 +1548,6 @@ unsigned long PDC_get_key_modifiers(void);
|
||||
int PDC_save_key_modifiers(bool);
|
||||
int PDC_return_key_modifiers(bool);
|
||||
|
||||
|
||||
/*** Functions defined as macros ***/
|
||||
|
||||
/* getch() and ungetch() conflict with some DOS libraries */
|
||||
@@ -1539,6 +1581,10 @@ int PDC_return_key_modifiers(bool);
|
||||
#define fixterm reset_prog_mode
|
||||
#define saveterm def_prog_mode
|
||||
|
||||
#ifdef NCURSES_MOUSE_VERSION
|
||||
# define getmouse(x) nc_getmouse(x)
|
||||
#endif
|
||||
|
||||
/* return codes from PDC_getclipboard() and PDC_setclipboard() calls */
|
||||
|
||||
#define PDC_CLIP_SUCCESS 0
|
||||
|
||||
132
pdcurses/mouse.c
132
pdcurses/mouse.c
@@ -14,7 +14,7 @@
|
||||
#include <curspriv.h>
|
||||
#include <string.h>
|
||||
|
||||
RCSID("$Id: mouse.c,v 1.36 2006/12/25 14:27:12 wmcbrine Exp $");
|
||||
RCSID("$Id: mouse.c,v 1.37 2006/12/28 01:02:03 wmcbrine Exp $");
|
||||
|
||||
/*man-start**************************************************************
|
||||
|
||||
@@ -35,6 +35,9 @@ RCSID("$Id: mouse.c,v 1.36 2006/12/25 14:27:12 wmcbrine Exp $");
|
||||
bool wenclose(const WINDOW *win, int y, int x);
|
||||
bool wmouse_trafo(const WINDOW *win, int *y, int *x, bool to_screen);
|
||||
bool mouse_trafo(int *y, int *x, bool to_screen);
|
||||
mmask_t mousemask(mmask_t mask, mmask_t *oldmask);
|
||||
int nc_getmouse(MEVENT *event);
|
||||
int ungetmouse(MEVENT *event);
|
||||
|
||||
PDCurses Description:
|
||||
Classic PDCurses mouse interface: mouse_set(), mouse_on(),
|
||||
@@ -116,6 +119,8 @@ RCSID("$Id: mouse.c,v 1.36 2006/12/25 14:27:12 wmcbrine Exp $");
|
||||
|
||||
**man-end****************************************************************/
|
||||
|
||||
static bool ungot = FALSE;
|
||||
|
||||
int mouse_set(unsigned long mbe)
|
||||
{
|
||||
PDC_LOG(("mouse_set() - called: event %x\n", mbe));
|
||||
@@ -261,3 +266,128 @@ bool mouse_trafo(int *y, int *x, bool to_screen)
|
||||
|
||||
return wmouse_trafo(stdscr, y, x, to_screen);
|
||||
}
|
||||
|
||||
mmask_t mousemask(mmask_t mask, mmask_t *oldmask)
|
||||
{
|
||||
PDC_LOG(("mousemask() - called\n"));
|
||||
|
||||
if (oldmask)
|
||||
*oldmask = SP->_trap_mbe;
|
||||
|
||||
mouse_set(mask);
|
||||
|
||||
return SP->_trap_mbe;
|
||||
}
|
||||
|
||||
int nc_getmouse(MEVENT *event)
|
||||
{
|
||||
int i;
|
||||
mmask_t bstate = 0;
|
||||
|
||||
PDC_LOG(("nc_getmouse() - called\n"));
|
||||
|
||||
if (!event)
|
||||
return ERR;
|
||||
|
||||
ungot = FALSE;
|
||||
|
||||
request_mouse_pos();
|
||||
|
||||
event->id = 0;
|
||||
|
||||
event->x = Mouse_status.x;
|
||||
event->y = Mouse_status.y;
|
||||
event->z = 0;
|
||||
|
||||
for (i = 0; i < 3; i++)
|
||||
{
|
||||
if (Mouse_status.changes & (1 << i))
|
||||
{
|
||||
int shf = i * 5;
|
||||
short button = Mouse_status.button[i] &
|
||||
BUTTON_ACTION_MASK;
|
||||
|
||||
if (button == BUTTON_RELEASED)
|
||||
bstate |= (BUTTON1_RELEASED << shf);
|
||||
else if (button == BUTTON_PRESSED)
|
||||
bstate |= (BUTTON1_PRESSED << shf);
|
||||
else if (button == BUTTON_CLICKED)
|
||||
bstate |= (BUTTON1_CLICKED << shf);
|
||||
else if (button == BUTTON_DOUBLE_CLICKED)
|
||||
bstate |= (BUTTON1_DOUBLE_CLICKED << shf);
|
||||
|
||||
button = Mouse_status.button[i] &
|
||||
BUTTON_MODIFIER_MASK;
|
||||
|
||||
if (button & PDC_BUTTON_SHIFT)
|
||||
bstate |= BUTTON_MODIFIER_SHIFT;
|
||||
if (button & PDC_BUTTON_CONTROL)
|
||||
bstate |= BUTTON_MODIFIER_CONTROL;
|
||||
if (button & PDC_BUTTON_ALT)
|
||||
bstate |= BUTTON_MODIFIER_ALT;
|
||||
}
|
||||
}
|
||||
|
||||
if (MOUSE_WHEEL_UP)
|
||||
bstate |= BUTTON4_PRESSED;
|
||||
else if (MOUSE_WHEEL_DOWN)
|
||||
bstate |= BUTTON5_PRESSED;
|
||||
|
||||
event->bstate = bstate;
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
int ungetmouse(MEVENT *event)
|
||||
{
|
||||
int i;
|
||||
unsigned long bstate;
|
||||
|
||||
PDC_LOG(("ungetmouse() - called\n"));
|
||||
|
||||
if (!event || ungot)
|
||||
return ERR;
|
||||
|
||||
ungot = TRUE;
|
||||
|
||||
pdc_mouse_status.x = event->x;
|
||||
pdc_mouse_status.y = event->y;
|
||||
|
||||
pdc_mouse_status.changes = 0;
|
||||
bstate = event->bstate;
|
||||
|
||||
for (i = 0; i < 3; i++)
|
||||
{
|
||||
int shf = i * 5;
|
||||
short button = 0;
|
||||
|
||||
if (bstate & ((BUTTON1_RELEASED | BUTTON1_PRESSED |
|
||||
BUTTON1_CLICKED | BUTTON1_DOUBLE_CLICKED) << shf))
|
||||
{
|
||||
pdc_mouse_status.changes |= 1 << i;
|
||||
|
||||
if (bstate & (BUTTON1_PRESSED << shf))
|
||||
button = BUTTON_PRESSED;
|
||||
if (bstate & (BUTTON1_CLICKED << shf))
|
||||
button = BUTTON_CLICKED;
|
||||
if (bstate & (BUTTON1_DOUBLE_CLICKED << shf))
|
||||
button = BUTTON_DOUBLE_CLICKED;
|
||||
|
||||
if (bstate & BUTTON_MODIFIER_SHIFT)
|
||||
button |= PDC_BUTTON_SHIFT;
|
||||
if (bstate & BUTTON_MODIFIER_CONTROL)
|
||||
button |= PDC_BUTTON_CONTROL;
|
||||
if (bstate & BUTTON_MODIFIER_ALT)
|
||||
button |= PDC_BUTTON_ALT;
|
||||
}
|
||||
|
||||
pdc_mouse_status.button[i] = button;
|
||||
}
|
||||
|
||||
if (bstate & BUTTON4_PRESSED)
|
||||
pdc_mouse_status.changes |= PDC_MOUSE_WHEEL_UP;
|
||||
else if (bstate & BUTTON5_PRESSED)
|
||||
pdc_mouse_status.changes |= PDC_MOUSE_WHEEL_DOWN;
|
||||
|
||||
return ungetch(KEY_MOUSE);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* $Id: ncurses_cfg.h,v 1.7 2006/12/27 20:15:35 wmcbrine Exp $
|
||||
/* $Id: ncurses_cfg.h,v 1.8 2006/12/28 01:02:03 wmcbrine Exp $
|
||||
*
|
||||
* This file is only used with the ncurses test programs.
|
||||
*
|
||||
@@ -13,6 +13,8 @@
|
||||
* Builds: bs gdc hanoi knight tclock ncurses
|
||||
*/
|
||||
|
||||
#define NCURSES_MOUSE_VERSION 2
|
||||
|
||||
#include "../config.h"
|
||||
#include <curses.h>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user