MouseHit
This function can be used to tell if a mouse button has been pressed since the last time it was tested.
Syntax
- bool MouseHit(const int button=1)
Parameters
- button: the mouse button to test. This can be one of the following values:
- 1: the left mouse button.
- 2: the right mouse button.
- 3: the middle mouse button (mouse wheel).
Returns
Returns true if the specified mouse button has been pressed, otherwise false is returned.
Example
#include "Leadwerks.h"
using namespace Leadwerks;
Model* model = NULL;
int mousehits=0;
int main(int argc, const char *argv[])
{
Leadwerks::Window* window = Leadwerks::Window::Create();
Context* context = Context::Create(window);
World* world = World::Create();
Camera* camera = Camera::Create();
camera->Move(0,0,-3);
Light* light = DirectionalLight::Create();
light->SetRotation(35,35,0);
//Create a model
model = Model::Box();
model->SetColor(0.0,0.0,1.0);
while (true)
{
if (window->Closed() || window->KeyDown(Key::Escape)) return false;
model->Turn(0,Leadwerks::Time::GetSpeed(),0);
Leadwerks::Time::Update();
world->Update();
world->Render();
//Press the left mouse button to see the result
if (window->MouseHit(1)) mousehits++;
context->SetBlendMode(Blend::Alpha);
context->DrawText("Mouse hits: "+String(mousehits),2,2);
context->SetBlendMode(Blend::Solid);
context->Sync(false);
}
return 0;
}