本文整理汇总了C++中Input::GetMousePosition方法的典型用法代码示例。如果您正苦于以下问题:C++ Input::GetMousePosition方法的具体用法?C++ Input::GetMousePosition怎么用?C++ Input::GetMousePosition使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Input
的用法示例。
在下文中一共展示了Input::GetMousePosition方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: HandleMouseWheel
void UI::HandleMouseWheel(StringHash eventType, VariantMap& eventData)
{
if (inputDisabled_ || consoleVisible_)
return;
using namespace MouseWheel;
int delta = eventData[P_WHEEL].GetInt();
Input* input = GetSubsystem<Input>();
rootWidget_->InvokeWheel(input->GetMousePosition().x_, input->GetMousePosition().y_, 0, -delta, tb::TB_MODIFIER_NONE);
}
示例2: HandleMouseButtonUp
void UI::HandleMouseButtonUp(StringHash eventType, VariantMap& eventData)
{
if (inputDisabled_ || consoleVisible_)
return;
using namespace MouseButtonUp;
unsigned button = eventData[P_BUTTON].GetUInt();
IntVector2 pos;
Input* input = GetSubsystem<Input>();
pos = input->GetMousePosition();
int qualifiers = input->GetQualifiers();
#ifdef ATOMIC_PLATFORM_WINDOWS
bool superdown = input->GetKeyDown(KEY_LCTRL) || input->GetKeyDown(KEY_RCTRL);
#else
bool superdown = input->GetKeyDown(KEY_LGUI) || input->GetKeyDown(KEY_RGUI);
#endif
MODIFIER_KEYS mod = GetModifierKeys(qualifiers, superdown);
if (button == MOUSEB_RIGHT)
rootWidget_->InvokeRightPointerUp(pos.x_, pos.y_, mod);
else
rootWidget_->InvokePointerUp(pos.x_, pos.y_, mod, false);
}
示例3:
Vector2 Urho2DConstraints::GetMousePositionXY()
{
Input* input = GetSubsystem<Input>();
Graphics* graphics = GetSubsystem<Graphics>();
Vector3 screenPoint = Vector3((float)input->GetMousePosition().x_ / graphics->GetWidth(), (float)input->GetMousePosition().y_ / graphics->GetHeight(), 0.0f);
Vector3 worldPoint = camera_->ScreenToWorldPoint(screenPoint);
return Vector2(worldPoint.x_, worldPoint.y_);
}
示例4: ProcessInput
void ProcessInput(const Input& input)
{
if (input.IsKeyPressed(Key::ESCAPE))
{
input.SetCursorVisible(true);
m_isMouseGrabbed = false;
}
if (input.IsKeyDown(Key::W))
{
m_cameraTransform->position += m_cameraTransform->GetForward() * m_speed;
}
if (input.IsKeyDown(Key::S))
{
m_cameraTransform->position += m_cameraTransform->GetBack() * m_speed;
}
if (input.IsKeyDown(Key::A))
{
m_cameraTransform->position += m_cameraTransform->GetLeft() * m_speed;
}
if (input.IsKeyDown(Key::D))
{
m_cameraTransform->position += m_cameraTransform->GetRight() * m_speed;
}
if (m_isMouseGrabbed)
{
glm::vec2 deltaPos = input.GetMousePosition() - m_centerPosition;
bool rotY = deltaPos.x != 0;
bool rotX = deltaPos.y != 0;
if (rotY)
{
m_cameraTransform->rotation *= glm::normalize(glm::angleAxis(glm::radians(deltaPos.x * m_sensitivity), m_cameraTransform->GetUp()));
}
if (rotX)
{
m_cameraTransform->rotation *= glm::normalize(glm::angleAxis(glm::radians(deltaPos.y * m_sensitivity), m_cameraTransform->GetRight()));
}
if (rotY || rotX)
{
input.SetMousePosition(m_centerPosition);
}
}
if (input.IsMouseButtonPressed(Mouse::BUTTON_LEFT))
{
input.SetCursorVisible(false);
input.SetMousePosition(m_centerPosition);
m_isMouseGrabbed = true;
}
}
示例5: GetWidgetDelegate
bool SceneView3D::MouseInView()
{
Input* input = GetSubsystem<Input>();
IntVector2 pos = input->GetMousePosition();
TBRect rect = GetWidgetDelegate()->GetRect();
GetWidgetDelegate()->ConvertToRoot(rect.x, rect.y);
return rect.Contains(TBPoint(pos.x_, pos.y_));
}
示例6: HandleUIUpdate
void UISelectList::HandleUIUpdate(StringHash eventType, VariantMap& eventData)
{
if (!widget_)
return;
// if we have a drag and drop item, auto scroll if top/bottom
UIDragDrop* dragDrop = GetSubsystem<UIDragDrop>();
if (dragDrop->GetDraggingObject())
{
TBSelectList* select = (TBSelectList*) widget_;
Input* input = GetSubsystem<Input>();
IntVector2 pos = input->GetMousePosition();
select->ConvertFromRoot(pos.x_, pos.y_);
if ((select->GetHitStatus(pos.x_, pos.y_) != WIDGET_HIT_STATUS_NO_HIT))
{
// Adjust speed based on pixel distance from top and bottom
int value = pos.y_;
if (value > 16)
value = select->GetRect().h - pos.y_;
if (value > 16)
return;
int speed = 0;
if (value <= 16)
speed = -2;
if (value < 8)
speed = -4;
if (pos.y_ > 16)
speed = -speed;
if (speed)
select->GetScrollContainer()->ScrollBy(0, speed);
}
}
}
示例7: HandleMouseDown
void UIDragDrop::HandleMouseDown(StringHash eventType, VariantMap& eventData)
{
using namespace MouseButtonDown;
Input* input = GetSubsystem<Input>();
if (!input->IsMouseVisible())
return;
if ((eventData[P_BUTTONS].GetUInt() & MOUSEB_LEFT) && TBWidget::hovered_widget)
{
// see if we have a widget with a drag object
TBWidget* tbw = TBWidget::hovered_widget;
UIWidget* widget = nullptr;
while(tbw)
{
if (tbw->GetDelegate())
{
widget = (UIWidget*) tbw->GetDelegate();
if (widget->GetDragObject())
{
// TODO: check if we're in widget bounds
// this is going to need to be updated for drag/drop multiselect
break;
}
widget = nullptr;
}
tbw = tbw->GetParent();
}
if (!widget)
return;
currentTargetWidget_ = widget;
dragSourceWidget_ = widget;
mouseDownPosition_ = input->GetMousePosition();
}
}
示例8: HandleUpdate
void UI::HandleUpdate(StringHash eventType, VariantMap& eventData)
{
if (exitRequested_) {
SendEvent(E_EXITREQUESTED);
exitRequested_ = false;
return;
}
tooltipHoverTime_ += eventData[Update::P_TIMESTEP].GetFloat();
if (tooltipHoverTime_ >= 0.5f)
{
UIWidget* hoveredWidget = GetHoveredWidget();
if (hoveredWidget && !tooltip_ && (hoveredWidget->GetShortened() || hoveredWidget->GetTooltip().Length() > 0))
{
tooltip_ = new UIPopupWindow(context_, true, hoveredWidget, "tooltip");
UILayout* tooltipLayout = new UILayout(context_, UI_AXIS_Y, true);
if (hoveredWidget->GetShortened())
{
UITextField* fullTextField = new UITextField(context_, true);
fullTextField->SetText(hoveredWidget->GetText());
tooltipLayout->AddChild(fullTextField);
}
if (hoveredWidget->GetTooltip().Length() > 0)
{
UITextField* tooltipTextField = new UITextField(context_, true);
tooltipTextField->SetText(hoveredWidget->GetTooltip());
tooltipLayout->AddChild(tooltipTextField);
}
Input* input = GetSubsystem<Input>();
IntVector2 mousePosition = input->GetMousePosition();
tooltip_->AddChild(tooltipLayout);
tooltip_->Show(mousePosition.x_ + 8, mousePosition.y_ + 8);
}
}
else
{
if (tooltip_) tooltip_->Close();
}
SendEvent(E_UIUPDATE);
TBMessageHandler::ProcessMessages();
}
示例9: GetRect
bool SceneView3D::MouseInView()
{
if (!GetInternalWidget())
return false;
if (!TBWidget::hovered_widget || TBWidget::hovered_widget->GetDelegate() != this)
return false;
Input* input = GetSubsystem<Input>();
IntVector2 pos = input->GetMousePosition();
IntRect rect = GetRect();
GetInternalWidget()->ConvertToRoot(rect.left_, rect.top_);
GetInternalWidget()->ConvertToRoot(rect.right_, rect.bottom_);
return rect.IsInside(pos);
}
示例10: SubscribeToEvent
void Urho2DConstraints::HandleMouseButtonDown(StringHash eventType, VariantMap& eventData)
{
Input* input = GetSubsystem<Input>();
PhysicsWorld2D* physicsWorld = scene_->GetComponent<PhysicsWorld2D>();
RigidBody2D* rigidBody = physicsWorld->GetRigidBody(input->GetMousePosition().x_, input->GetMousePosition().y_, M_MAX_UNSIGNED, camera_); // Raycast for RigidBody2Ds to pick
if (rigidBody)
{
pickedNode = rigidBody->GetNode();
//log.Info(pickedNode.name);
StaticSprite2D* staticSprite = pickedNode->GetComponent<StaticSprite2D>();
staticSprite->SetColor(Color(1.0f, 0.0f, 0.0f, 1.0f)); // Temporary modify color of the picked sprite
// Create a ConstraintMouse2D - Temporary apply this constraint to the pickedNode to allow grasping and moving with the mouse
ConstraintMouse2D* constraintMouse = pickedNode->CreateComponent<ConstraintMouse2D>();
constraintMouse->SetTarget(GetMousePositionXY());
constraintMouse->SetMaxForce(1000 * rigidBody->GetMass());
constraintMouse->SetCollideConnected(true);
constraintMouse->SetOtherBody(dummyBody); // Use dummy body instead of rigidBody. It's better to create a dummy body automatically in ConstraintMouse2D
constraintMouse->SetDampingRatio(0.0f);
}
SubscribeToEvent(E_MOUSEMOVE, HANDLER(Urho2DConstraints, HandleMouseMove));
SubscribeToEvent(E_MOUSEBUTTONUP, HANDLER(Urho2DConstraints, HandleMouseButtonUp));
}
示例11: ProcessInput
void FreeLook::ProcessInput(const Input& input, float delta)
{
if(input.GetKey(m_unlockMouseKey))
{
input.SetCursor(true);
m_mouseLocked = false;
}
if(m_mouseLocked)
{
Vector2f deltaPos = input.GetMousePosition() - m_windowCenter;
bool rotY = deltaPos.GetX() != 0;
bool rotX = deltaPos.GetY() != 0;
if(rotY)
{
GetTransform()->Rotate(Vector3f(0,1,0), ToRadians(deltaPos.GetX() * m_sensitivity));
}
if(rotX)
{
GetTransform()->Rotate(GetTransform()->GetRot()->GetRight(), ToRadians(deltaPos.GetY() * m_sensitivity));
}
if(rotY || rotX)
{
input.SetMousePosition(m_windowCenter);
}
}
if(input.GetMouseDown(Input::MOUSE_LEFT_BUTTON))
{
input.SetCursor(false);
input.SetMousePosition(m_windowCenter);
m_mouseLocked = true;
}
}
示例12: if
void SceneView3D::HandleDragEnterWidget(StringHash eventType, VariantMap& eventData)
{
using namespace DragEnterWidget;
UIWidget* widget = static_cast<UIWidget*>(eventData[P_WIDGET].GetPtr());
if (widget != this)
return;
UIDragObject* dragObject = static_cast<UIDragObject*>(eventData[P_DRAGOBJECT].GetPtr());
Object* object = dragObject->GetObject();
if (!object)
return;
if (object->GetType() == Asset::GetTypeStatic())
{
Asset* asset = (Asset*) object;
AssetImporter* importer = asset->GetImporter();
if (!importer)
return;
StringHash importerType = importer->GetType();
if (importerType == PrefabImporter::GetTypeStatic())
{
dragNode_ = scene_->CreateChild(asset->GetName());
PrefabComponent* pc = dragNode_->CreateComponent<PrefabComponent>();
pc->SetPrefabGUID(asset->GetGUID());
}
else if (importerType == ModelImporter::GetTypeNameStatic())
{
dragNode_ = scene_->CreateChild();
SharedPtr<File> file(new File(context_, asset->GetCachePath()));
SharedPtr<XMLFile> xml(new XMLFile(context_));
if (!xml->Load(*file))
return;
dragNode_->LoadXML(xml->GetRoot());
dragNode_->SetName(asset->GetName());
}
else if (importerType == SpriterImporter::GetTypeNameStatic())
{
AnimationSet2D* animationSet = GetSubsystem<ResourceCache>()->GetResource<AnimationSet2D>(asset->GetPath());
String animationName;
if (animationSet && animationSet->GetNumAnimations())
{
animationName = animationSet->GetAnimation(0)->GetName();
}
dragNode_ = scene_->CreateChild(asset->GetName());
AnimatedSprite2D* sprite = dragNode_->CreateComponent<AnimatedSprite2D>();
if (!animationName.Length())
sprite->SetAnimationSet(animationSet);
else
sprite->SetAnimation(animationSet, animationName);
}
else if (importerType == TextureImporter::GetTypeNameStatic())
{
dragNode_ = scene_->CreateChild(asset->GetName());
Sprite2D* spriteGraphic = GetSubsystem<ResourceCache>()->GetResource<Sprite2D>(asset->GetPath());
StaticSprite2D* sprite = dragNode_->CreateComponent<StaticSprite2D>();
sprite->SetSprite(spriteGraphic);
}
if (dragNode_.NotNull())
{
Input* input = GetSubsystem<Input>();
IntVector2 pos = input->GetMousePosition();
UpdateDragNode(pos.x_, pos.y_);
}
//LOGINFOF("Dropped %s : %s on SceneView3D", asset->GetPath().CString(), asset->GetGUID().CString());
}
}