31.01.2014 Views

Version 5.0 The LEDA User Manual

Version 5.0 The LEDA User Manual

Version 5.0 The LEDA User Manual

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

3.5 Input<br />

<strong>The</strong> main input operation for reading positions, mouse clicks, and buttons from a window<br />

W is the operation W .read mouse(). This operation is blocking, i.e., waits for a button to<br />

be pressed which is either a “real” button on the mouse device pressed inside the drawing<br />

area of W or a button in the panel section of W . In both cases, the number of the selected<br />

button is returned. Mouse buttons have pre-defined numbers MOUSE BUTTON(1) for<br />

the left button, MOUSE BUTTON(2) for the middle button, and MOUSE BUTTON(3)<br />

for the right button. <strong>The</strong> numbers of the panel buttons can be defined by the user. If the<br />

selected button has an associated action function or sub-window this function/window is<br />

executed/opened (cf. 17.2 for details).<br />

<strong>The</strong>re is also a non-blocking version W .get mouse() which returns the constant<br />

NO BUTTON if no button was pressed.<br />

<strong>The</strong> window data type also provides two more general input operations W .read event()<br />

and W .get event() for reading events. <strong>The</strong>y return the event type (enumeration in<br />

), the value of the event, the position of the event in<br />

the drawing section, and a time stamp of the event.<br />

3.5.1 Read Mouse<br />

int W.read mouse( ) waits until a mouse button is pressed inside of the drawing<br />

area or until a button of the panel section is selected. In<br />

both cases, the number n of the button is returned which<br />

is one of the predefined constants MOUSE BUTTON(i)<br />

with i ∈ {1, 2, 3} for mouse buttons and a user defined<br />

value (defined when adding the button with W .button())<br />

for panel buttons. If the button has an associated action<br />

function this function is called with parameter n. If<br />

the button has an associated window M it is opened and<br />

M.read mouse() is returned.<br />

int W.read mouse(double& x, double& y)<br />

int W.read mouse(point& p)<br />

If a button is pressed inside the drawing area the current<br />

position of the cursor is assigned to (x, y). <strong>The</strong> operation<br />

returns the number of the pressed button (see<br />

W .read mouse().)<br />

as above, the current position is assigned to point p.<br />

int W.read mouse seg(double x 0 , double y 0 , double& x, double& y)<br />

displays a line segment from (x 0 , y 0 ) to the current cursor<br />

position until a mouse button is pressed inside the drawing<br />

section of W . When a button is pressed the current position<br />

is assigned to (x, y) and the number of the pressed<br />

button is returned.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!