Mouse (Chili Framework)

From Chilipedia
Revision as of 18:53, 15 May 2017 by Chili (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
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
	}
}

Members

Buttons

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

Get the current state of the mouse buttons.

Position

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()).

Read

Event Mouse::Read()

Pull an Event object out of the queue.

Flush

void Mouse::Flush()

Clear the event queue.

IsEmpty

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

IsInWindow

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

Event

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.

Buttons

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

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

Position

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
}

Type

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

GetType

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

Returns the type of the event.

IsValid

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