Difference between revisions of "Mouse (Chili Framework)"
(21 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
− | With <code>Mouse</code>, you can get the current state of the mouse keys and the pointer position, and you can pop mouse events out of an <code>Event</code> queue contained in <code>Mouse</code>. You can also check whether the mouse is in the window client region. Whopee. (''Note: lives in ''<code>MainWindow</code>'''s belly.'') | + | With <code>Mouse</code>, you can get the current state of the mouse keys and the pointer position, and you can pop mouse events out of an <code>Event</code> queue contained in <code>Mouse</code>. You can also check whether the mouse is in the window client region. Whopee. (''Note: lives in ''<code>[[MainWindow (Chili Framework)|MainWindow]]</code>'''s belly.'') |
+ | |||
+ | == Examples of Use == | ||
+ | |||
+ | The following code checks to see if the left mouse button is currently depressed, and if so, initializes a <code>Vec2</code> with the current pointer position. | ||
+ | |||
+ | <syntaxhighlight lang="cpp" line="1" > | ||
+ | if( wnd.mouse.LeftIsPressed() ) | ||
+ | { | ||
+ | const Vec2 pointerPos( float( wnd.mouse.GetPosX() ),float( wnd.mouse.GetPosY() ) ); | ||
+ | // do awesome stuff here | ||
+ | } | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | The following code reads mouse events from the queue and processes any left button presses. | ||
+ | |||
+ | <syntaxhighlight lang="cpp" line="1" > | ||
+ | while( !wnd.mouse.IsEmpty() ) | ||
+ | { | ||
+ | const Mouse::Event e = wnd.mouse.Read(); | ||
+ | if( e.GetType() == Mouse::Event::Type::LPress ) | ||
+ | { | ||
+ | // respond to left mouse click event | ||
+ | } | ||
+ | } | ||
+ | </syntaxhighlight> | ||
== Members == | == Members == | ||
− | |||
− | |||
− | |||
− | === | + | === Buttons === |
− | <code> | + | <code>bool Mouse::LeftIsPressed() const</code><br /> |
− | + | <code>bool Mouse::RightIsPressed() const</code><br /> | |
− | + | Get the current state of the mouse buttons. | |
− | + | ||
− | + | ||
− | === | + | === Position === |
− | <code> | + | <code>std::pair<int,int> Mouse::GetPos() const</code><br /> |
− | + | <code>int Mouse::GetPosX() const</code><br /> | |
+ | <code>int Mouse::GetPosY() const</code><br /> | ||
− | + | 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 <code>std::pair</code> (see example for [[#Event|Mouse::Event::GetPos()]]). | |
− | <code> | + | |
− | + | ||
− | === | + | === Read === |
− | <code> | + | <code>Event Mouse::Read()</code><br /> |
− | + | ||
− | + | ||
− | + | ||
− | === | + | Pull an <code>[[#Event|Event]]</code> object out of the queue. |
− | <code>void | + | |
− | <code> | + | === Flush === |
− | <code>bool | + | <code>void Mouse::Flush()</code><br /> |
− | + | ||
+ | Clear the event queue. | ||
+ | |||
+ | === IsEmpty === | ||
+ | <code>bool Mouse::IsEmpty() const</code><br /> | ||
+ | Returns <code>true</code> if the event queue is empty. | ||
+ | |||
+ | === IsInWindow === | ||
+ | <code>bool Mouse::IsInWindow() const</code><br /> | ||
+ | Returns <code>true</code> if the mouse pointer is in the client area of the window. Probably not that useful, but hey. | ||
== Event == | == Event == | ||
<code>class Mouse::Event</code><br /> | <code>class Mouse::Event</code><br /> | ||
− | Mouse click, wheel, and move events are held in a queue in <code>Mouse</code> 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 <code>Mouse::Read()</code>. | + | Mouse click, wheel, and move events are held in a queue in <code>Mouse</code> in the order they occurred. These events are modeled with their own <code>class</code> 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 <code>Mouse::Read()</code>. One at a time, like a string of anal beads. |
+ | |||
+ | === Buttons === | ||
+ | <code>bool Mouse::Event::LeftIsPressed() const</code><br /> | ||
+ | <code>bool Mouse::Event::RightIsPressed() const</code><br /> | ||
+ | |||
+ | Get the state of the mouse buttons at the time of the event. | ||
+ | |||
+ | === Position === | ||
+ | <code>std::pair<int,int> Mouse::Event::GetPos() const</code><br /> | ||
+ | <code>int Mouse::Event::GetPosX() const</code><br /> | ||
+ | <code>int Mouse::Event::GetPosY() const</code><br /> | ||
+ | |||
+ | 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 <code>std::pair</code> (see example below). | ||
+ | |||
+ | <syntaxhighlight lang="cpp" line="1" > | ||
+ | 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 | ||
+ | } | ||
+ | </syntaxhighlight> | ||
=== Type === | === Type === | ||
− | <code>enum Mouse::Event::Type</code><br /> | + | <code>enum class Mouse::Event::Type</code><br /> |
This represents the different types of events that can be recorded. The options are: | This represents the different types of events that can be recorded. The options are: | ||
Line 53: | Line 99: | ||
=== GetType === | === GetType === | ||
− | <code>Type Mouse::Event::GetType() const</code><br /> | + | <code>Mouse::Event::Type Mouse::Event::GetType() const</code><br /> |
− | Returns the type of the | + | Returns the type of the event. |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
=== IsValid === | === IsValid === | ||
− | <code>bool | + | <code>bool Mouse::Event::IsValid() const</code><br /> |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | Returns <code>true</code> if the event is a valid event (reading from an empty queue will return an invalid event object). | |
== See also == | == See also == | ||
* The [[Chili Framework]] | * The [[Chili Framework]] |
Latest revision as of 18:53, 15 May 2017
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.)
Contents
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
- The Chili Framework