public override void Update() { if (!active) { return; } Vector2 mpos = Input.GetMousePosition(); bool down = Input.GetMouseButton(PressAction.DOWN, MouseButton.LEFT); bool pressed = Input.GetMouseButton(PressAction.RELEASED, MouseButton.LEFT); bool hover = bounds.Inside(mpos); if (hover && pressed && pressAction != null) { pressAction(); } if (hover && down) { colour = downColour; } else if (hover) { colour = highlightColour; } else { colour = baseColour; } }
public override void Update() { mousePos = Input.GetMousePosition(); bounds = new AABB(position.X, position.Y, size.X, size.Y); if (Input.GetMouseButton(PressAction.PRESSED, MouseButton.LEFT)) { if (bounds.Inside(mousePos)) { if (!staticGrabbed) { staticGrabbed = true; grabbed = true; grabPoint = mousePos - position; } } } else if (Input.GetMouseButton(PressAction.RELEASED, MouseButton.LEFT)) { grabbed = staticGrabbed = false; grabPoint = Vector2.Zero; } if (grabbed) { if (axis == "x") { position.X = Math.Min(Math.Max(start - size.X / 2, mousePos.X - grabPoint.X), start + limit - size.X / 2); } else if (axis == "y") { position.Y = Math.Min(Math.Max(start - size.Y / 2, mousePos.Y - grabPoint.Y), start + limit - size.Y / 2); } } }
public bool Inside(Vector2 p) { return(aabb.Inside(p)); }