Mouse (Chili Framework)

From Chilipedia
Jump to: navigation, search

With Mouse, you can get the current state of the mouse keys and the pointer position, and you can pop mouse events out of an Event queue contained in Mouse. You can also check whether the mouse is in the window client region. Whopee. (Note: lives in MainWindow's belly.)

Examples of Use

The following code checks to see if the left mouse button is currently depressed, and if so, initializes a Vec2 with the current pointer position.

if( wnd.mouse.LeftIsPressed() )
	const Vec2 pointerPos( float( wnd.mouse.GetPosX() ),float( wnd.mouse.GetPosY() ) );
	// do awesome stuff here

The following code reads mouse events from the queue and processes any left button presses.

while( !wnd.mouse.IsEmpty() )
	const Mouse::Event e = wnd.mouse.Read();
	if( e.GetType() == Mouse::Event::Type::LPress )
		// respond to left mouse click event



bool Mouse::LeftIsPressed() const
bool Mouse::RightIsPressed() const

Get the current state of the mouse buttons.


std::pair<int,int> Mouse::GetPos() const
int Mouse::GetPosX() const
int Mouse::GetPosY() const

Get the current x and y coordinates of the pointer. You can get them separately or as a sexy double date in the form of std::pair (see example for Mouse::Event::GetPos()).


Event Mouse::Read()

Pull an Event object out of the queue.


void Mouse::Flush()

Clear the event queue.


bool Mouse::IsEmpty() const
Returns true if the event queue is empty.


bool Mouse::IsInWindow() const
Returns true if the mouse pointer is in the client area of the window. Probably not that useful, but hey.


class Mouse::Event

Mouse click, wheel, and move events are held in a queue in Mouse in the order they occurred. These events are modeled with their own class because they're precious fucking little snowflakes. They store the type of event and the state of the mouse after the event occurred. You pull them out of the buffer with Mouse::Read(). One at a time, like a string of anal beads.


bool Mouse::Event::LeftIsPressed() const
bool Mouse::Event::RightIsPressed() const

Get the state of the mouse buttons at the time of the event.


std::pair<int,int> Mouse::Event::GetPos() const
int Mouse::Event::GetPosX() const
int Mouse::Event::GetPosY() const

Get the x and y coordinates at the time of the event. You can get them separately or as a sexy double date in the form of std::pair (see example below).

const std::pair<int,int> p = e.GetPos();
if( p.first > 100 && p.second > 100 )
	// do something if x and y coords are above 100


enum class Mouse::Event::Type

This represents the different types of events that can be recorded. The options are:

  • LPress
  • LRelease
  • RPress
  • RRelease
  • WheelUp
  • WheelDown
  • Move
  • Invalid


Mouse::Event::Type Mouse::Event::GetType() const

Returns the type of the event.


bool Mouse::Event::IsValid() const

Returns true if the event is a valid event (reading from an empty queue will return an invalid event object).

See also