8. Mouse support

Display and hide the mouse cursor

By default, the mouse cursor in visible in windowed mode, hidden in fullscreen mode. You can change it with:

static void TCODMouse::showCursor (bool visible)

void TCOD_mouse_show_cursor (bool visible)

mouse_show_cursor (visible)

void TCODMouse::showCursor(bool visible)

visibleIf true, this function turns the mouse cursor on. Else it turns the mouse cursor off.

Getting the cursor status

You can get the current cursor status (hidden or visible) with:

static bool TCODMouse::isCursorVisible (void)

bool TCOD_mouse_is_cursor_visible (void)

mouse_is_cursor_visible ()

bool TCODMouse::isCursorVisible()

Setting the mouse cursor's position

You can set the cursor position (in pixel coordinates, where [0,0] is the window's top left corner) with:

static void TCODMouse::move (int x, int y)

void TCOD_mouse_move (int x, int y)

mouse_move (x, y)

void TCODMouse::moveMouse(int x, int y)

x,yNew coordinates of the mouse cursor in pixels.

Getting the mouse status

You can read the current mouse status with this function. Note that this function does not update the mouse status. You have to call either TCODSystem::checkForEvent or TCODSystem::waitForEvent for the mouse status to be updated.

typedef struct {
int x,y;
int dx,dy;
int cx,cy;
int dcx,dcy;
bool lbutton;
bool rbutton;
bool mbutton;
bool lbutton_pressed;
bool rbutton_pressed;
bool mbutton_pressed;
bool wheel_up;
bool wheel_down;
} TCOD_mouse_t;

static TCOD_mouse_t TCODMouse::getStatus (void)

TCOD_mouse_t TCOD_mouse_get_status (void)

mouse_get_status ()

TCODMouseData TCODMouse::getStatus()

x,y Absolute position of the mouse cursor in pixels relative to the window top-left corner.
dx,dy Movement of the mouse cursor since the last call in pixels.
cx,cy Coordinates of the console cell under the mouse cursor (pixel coordinates divided by the font size).
dcx,dcy Movement of the mouse since the last call in console cells (pixel coordinates divided by the font size).
lbuttontrue if the left button is pressed.
rbuttontrue if the right button is pressed.
mbuttontrue if the middle button (or the wheel) is pressed.
lbutton_pressedtrue if the left button was pressed and released.
rbutton_pressedtrue if the right button was pressed and released.
mbutton_pressedtrue if the middle button was pressed and released.
wheel_uptrue if the wheel was rolled up.
wheel_downtrue if the wheel was rolled down.