The OpenD Programming Language

MouseEvent

Listen for this on your event listeners if you are interested in mouse action.

Note that button is used on mouse press and release events. If you are curious about which button is being held in during motion, use modifierState and check the bitmask for ModifierState.leftButtonDown, etc.

Members

Properties

buttonLinear
ubyte buttonLinear [@property getter]

Returns a linear representation of mouse button, for use with static arrays. Guaranteed to be >= 0 && <= 15

Static functions

equStr
bool equStr(MouseEvent event, const(char)[] str)

can contain emacs-like modifier prefix case-insensitive names: lmbX/leftX rmbX/rightX mmbX/middleX wheelX motion (no prefix allowed) 'X' is either "up" or "down" (or "-up"/"-down"); if omited, means "down"

Variables

button
MouseButton button;

See MouseButton

doubleClick
bool doubleClick;

was it a double click? Only set on type == MouseEventType.buttonPressed

dx
int dx;

Change in X position since last report

dy
int dy;

Change in Y position since last report

modifierState
int modifierState;

See ModifierState

type
MouseEventType type;

movement, press, release, double click. See MouseEventType

window
SimpleWindow window;

The window in which the event happened.

x
int x;

Current X position of the cursor when the event fired, relative to the upper-left corner of the window, reported in pixels. (0, 0) is the upper left, (window.width - 1, window.height - 1) is the lower right corner of the window.

y
int y;

Current Y position of the cursor when the event fired.

Examples

This will draw boxes on the window with the mouse as you hold the left button.

import arsd.simpledisplay;

void main() {
	auto window = new SimpleWindow();

	window.eventLoop(0,
		(MouseEvent ev) {
			if(ev.modifierState & ModifierState.leftButtonDown) {
				auto painter = window.draw();
				painter.fillColor = Color.red;
				painter.outlineColor = Color.black;
				painter.drawRectangle(Point(ev.x / 16 * 16, ev.y / 16 * 16), 16, 16);
			}
		}
	);
}

Meta