1.怎么用html5的移动源码移动源码canvas实现箭头随着鼠标移动和旋转
2.Visual Studio Code怎样用鼠标编辑文本 用鼠标编辑文本方法介绍
3.在VB或C++中,如何记录鼠标的鼠标鼠标设置移动轨迹?
怎么用html5的canvas实现箭头随着鼠标移动和旋转
下面是源码主文件
test.htm
<!doctype html>
<html>
<head>
<mata charset="utf-8">
<title></title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<canvas id="canvas" width="" height="">
<p> :( 抱歉~ <br> 您的浏览器貌似不支持HTML5的标签"canvas"的说,试试更换成
Chrome,移动源码移动源码FireFox,IE9...</p>
</canvas>
<script src="arrow.js"></script>
<script src="utils.js"></script>
<script>
window.onload=function(){
var canvas=document.getElementById("canvas"),
context=canvas.getContext('2d'),
mouse=utils.captureMouse(canvas),
arrow=new Arrow();
arrow.x=canvas.width/2;
arrow.y=canvas.height/2;
if (!window.requestAnimationFrame) {
window.requestAnimationFrame = (window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame ||
window.oRequestAnimationFrame ||
window.msRequestAnimationFrame ||
function (callback) {
return window.setTimeout(callback, /);
});
}
(function drawFrame(){
window.requestAnimationFrame(drawFrame,canvas);
context.clearRect(0,0,canvas.width,canvas.height);
var dx=mouse.x-arrow.x;
var dy=mouse.y-arrow.y;
arrow.rotation=Math.atan2(dy,dx);
arrow.draw(context);
}());
};
</script>
</body>
</html>
var canvas=document.getElementById(“canvas”)
//即将变量 canvas 作为对 html5 canvas标签id为’canvas’ 的引用
context=canvas.getContext(‘2d’)
//获取canvas该对象后,可在其上进行图形绘制
window.requestAnimationFrame
为了便于JavaScript进行图形的鼠标鼠标设置重绘,各大浏览器厂商都提供了各自的移动源码移动源码API给开发者进行调用,由于各大厂商的鼠标鼠标设置联想内核源码下载对HTML5的支持不同,所以API没有统一,移动源码移动源码但使用厂商各自的鼠标鼠标设置API则在该API在对应浏览器上为最有效率的方式运行。代码中对
用户浏览器做判断,移动源码移动源码实例化能被成功引用的鼠标鼠标设置API接口。如果用户的移动源码移动源码浏览器没有提供该API,则使用JS的setTimeout。其特性类似于AS的鼠标鼠标设置 ENTER_FRAME 事件。
需要用到的移动源码移动源码2个JS文件
utils.js 可根据传入的对象判断,鼠标所在对象的鼠标鼠标设置相对于左上角的坐标值
unction utils(){ };utils.captureMouse=function(element){
var mouse={ x:0,y:0};
element.addEventListener('mousemove',function(event){
var x,y;
if(event.pageX || event.pageY){
x=event.pageX;
y=event.pageY;
}else{
x=event.clientX+document.body.scrollLeft+
document.documentElement.scrollLeft;
y=event.clientY+document.body.scrollTop+
document.documentElement.scrollTop;
}
x -= element.offsetLeft;
y -= element.offsetTop;
mouse.x=x;
mouse.y=y;
},false);
return mouse;
};
计算mouse相对于容器的x,y坐标偏移,本质是移动源码移动源码量能起爆源码附图判断鼠标在浏览器中的鼠标偏移,之后对浏览器中容器宽度和高度进行再次偏移。
arrow.js
绘制一个箭头的js
function Arrow(){ this.x=0; this.y=0; this.color="#ffff"; this.rotation=0;}Arrow.prototype.draw=function(context){ context.save(); context.translate(this.x,this.y); context.rotate(this.rotation); context.lineWidth=2; context.fillStyle=this.color; context.beginPath(); context.moveTo(-,-); context.lineTo(0,-); context.lineTo(0,-); context.lineTo(,0); context.lineTo(0,); context.lineTo(0,); context.lineTo(-,); context.lineTo(-,-); context.closePath(); context.stroke(); context.restore(); };
熟悉AS的Graphics 的coder一定很快能熟悉使用JS的绘图API
style.css
用到的样式表
body{
background-color:#bbb;
}
#canvas{
background-color:#fff;
}
区分canvas 内外的颜色。
Visual Studio Code怎样用鼠标编辑文本 用鼠标编辑文本方法介绍
Visual Studio Code怎样用鼠标编辑文本?VisualStudioCode是一个跨平台源代码编辑器,用于编写现代Web和云应用程序。它有JavaScript、TypeScript和TypeScript。今天小编为大家带来了鼠标编辑文本的怎么抓取html源码方法,一起来看看吧。例如,在今天的示例代码中,我们选择了bar函数,然后将鼠标移动到选定的代码上,并按下鼠标左键,以免松开。道游牛牛源码这时,你可以看到鼠标指针已经从垂直线变成了箭头。这时,如果我们移动鼠标,我们可以把这段文本拖到我们想要的位置。
在移动过程中,我们可以在编辑器中看到一个由虚线组成的彩票快3源码光标。当我们松开鼠标左键时,这段文本将被移动到虚拟光标的位置。
在上面的动画中,我们将bar函数从文档的末尾移动到第四行。这个功能相当于用键盘剪切+粘贴。
那能不能用鼠标来复制+粘贴呢?不用担心,VSCode肯定也会考虑到这一点,所以答案是:一定要能。
如果我们在拖拽本文的同时按下Option键(Ctrl键在Windows上),鼠标指针上会增加一个加号,然后我们将鼠标或虚拟光标移动到我们想要的位置,然后当我们松开鼠标左键时,本文将被复制粘贴到虚拟光标的位置,即我们设定的目标位置。
您看,在移动鼠标的过程中,多按一个Option键(Ctrl键在Windows上),操作结果由原来的剪切+粘贴改为复制+粘贴。
Visual Studio Code怎样用鼠标编辑文本的方法已经为大家带来了,希望能帮助到大家。深空游戏还有许多软件操作方法和测评信息,快来关注我们吧,精彩不容错过。
在VB或C++中,如何记录鼠标的移动轨迹?
VB绘制鼠标移动轨迹
主要代码及注释如下:
Public Class Form1Class Form1
Dim PtStart As Point '记录绘制直线的起始点
Dim PtEnd As Point '记录绘制直线的终点
Dim ShouldDrawLine As Boolean '是否绘制直线
'记录鼠标左键点击的位置,第二次点击后开始绘制直线
Private Sub Pic1_MouseDown()Sub Pic1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Pic1.MouseDown
If e.Button = Windows.Forms.MouseButtons.Left Then
If Not ShouldDrawLine Then
PtStart = New Point(e.X, e.Y)
ShouldDrawLine = True
Else
PtEnd = New Point(e.X, e.Y)
'下面两句根据需要进行取舍
'Call DrawLine(PtStart, PtEnd) '绘制一条直线
Call DrawLines(PtStart, PtEnd) '绘制多条直线
ShouldDrawLine = False
End If
End If
End Sub
'绘制鼠标的移动轨迹(仅在鼠标第一次点击后开始绘制轨迹)
Private Sub Pic1_MouseMove()Sub Pic1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Pic1.MouseMove
Static pt As Point
If ShouldDrawLine Then
'鼠标第一次点击的位置(需转化为屏幕坐标)
Dim p As Point = Pic1.PointToScreen(PtStart)
'清除原先绘制的鼠标移动轨迹
If pt <> Nothing Then ControlPaint.DrawReversibleLine(p, pt, Color.Red)
'绘制鼠标移动后新的轨迹
pt = Pic1.PointToScreen(New Point(e.X, e.Y))
ControlPaint.DrawReversibleLine(p, pt, Color.Red)
Else
pt = Nothing '清除鼠标原位置
End If
End Sub
'绘制鼠标两次点击位置之间的直线
Private Sub DrawLine()Sub DrawLine(ByVal mPoint1 As Point, ByVal mPoint2 As Point)
Pic1.Refresh() '用于刷新Picturebox表面
Pic1.CreateGraphics.DrawLine(Pens.Blue, mPoint1, mPoint2) '绘制两点间的直线
End Sub
'绘制多条直线,每两次鼠标点击确定一条线
Private Sub DrawLines()Sub DrawLines(ByVal mPoint1 As Point, ByVal mPoint2 As Point)
'此句不可删除,用于清除鼠标点击前的轨迹
ControlPaint.DrawReversibleLine(Pic1.PointToScreen(mPoint1), Pic1.PointToScreen(mPoint2), Color.Red)
Pic1.CreateGraphics.DrawLine(Pens.Blue, mPoint1, mPoint2) '绘制两点间的直线
End Sub
Private Sub Form1_Load()Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Me.SetStyle(ControlStyles.AllPaintingInWmPaint Or ControlStyles.OptimizedDoubleBuffer Or ControlStyles.UserPaint, True)
End Sub
End Class
注:此代码运行需要一个Form,Form上存在一个Pic1的Picturebox控件。
举一反三,附另外一段代码:
如何在窗体上随鼠标的移动快速绘制十字形轨迹源码
Public Class Form2Class Form2
Dim OldPoint As Point
Private Sub Form2_Load()Sub Form2_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Me.SetStyle(ControlStyles.AllPaintingInWmPaint Or ControlStyles.OptimizedDoubleBuffer Or ControlStyles.UserPaint, True)
End Sub
Private Sub Form1_MouseMove()Sub Form1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove
Dim p1, p2, p3, p4 As Point
If OldPoint <> Nothing Then
p1 = PointToScreen(New Point(OldPoint.X, 0))
p2 = PointToScreen(New Point(OldPoint.X, Me.ClientSize.Height))
p3 = PointToScreen(New Point(0, OldPoint.Y))
p4 = PointToScreen(New Point(Me.ClientSize.Width, OldPoint.Y))
ControlPaint.DrawReversibleLine(p1, p2, Color.Cyan)
ControlPaint.DrawReversibleLine(p3, p4, Color.Cyan)
End If
p1 = PointToScreen(New Point(e.X, 0))
p2 = PointToScreen(New Point(e.X, Me.ClientSize.Height))
p3 = PointToScreen(New Point(0, e.Y))
p4 = PointToScreen(New Point(Me.ClientSize.Width, e.Y))
ControlPaint.DrawReversibleLine(p1, p2, Color.Cyan)
ControlPaint.DrawReversibleLine(p3, p4, Color.Cyan)
OldPoint = New Point(e.X, e.Y)
End Sub
End Class
再附一段代码,在picturebox上实时绘制鼠标选中的矩形框
Public Class Form2Class Form2
Dim PtStart, pt As Point
Dim RectSize As Size
Private Sub Pic1_MouseDown()Sub Pic1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Pic1.MouseDown
If e.Button = Windows.Forms.MouseButtons.Left Then PtStart = New Point(e.X, e.Y)
End Sub
Private Sub Pic1_MouseMove()Sub Pic1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Pic1.MouseMove
If e.Button = Windows.Forms.MouseButtons.Left Then
Dim p As Point = PointToScreen(PtStart) : p.Offset(Pic1.Location)
If pt <> Nothing Then ControlPaint.DrawReversibleFrame(New Rectangle(p.X, p.Y, pt.X - p.X, pt.Y - p.Y), Color.Red, FrameStyle.Dashed)
pt = PointToScreen(New Point(e.X, e.Y)) : pt.Offset(Pic1.Location)
ControlPaint.DrawReversibleFrame(New Rectangle(p.X, p.Y, pt.X - p.X, pt.Y - p.Y), Color.Red, FrameStyle.Dashed)
End If
End Sub
Private Sub DrawRect()Sub DrawRect(ByVal mPoint1 As Point, ByVal mPoint2 As Point)
Pic1.Refresh()
If mPoint2.X > mPoint1.X And mPoint2.Y > mPoint1.Y Then
PtStart = New Point(mPoint1.X, mPoint1.Y) : RectSize = New Size(mPoint2.X - mPoint1.X, mPoint2.Y - mPoint1.Y)
ElseIf mPoint2.X > mPoint1.X And mPoint2.Y < mPoint1.Y Then
PtStart = New Point(mPoint1.X, mPoint2.Y) : RectSize = New Size(mPoint2.X - mPoint1.X, mPoint1.Y - mPoint2.Y)
ElseIf mPoint2.X < mPoint1.X And mPoint2.Y > mPoint1.Y Then
PtStart = New Point(mPoint2.X, mPoint1.Y) : RectSize = New Size(mPoint1.X - mPoint2.X, mPoint2.Y - mPoint1.Y)
ElseIf mPoint2.X < mPoint1.X And mPoint2.Y < mPoint1.Y Then
PtStart = New Point(mPoint2.X, mPoint2.Y) : RectSize = New Size(mPoint1.X - mPoint2.X, mPoint1.Y - mPoint2.Y)
End If
Pic1.CreateGraphics.DrawRectangle(Pens.Blue, New Rectangle(PtStart, RectSize))
MsgBox(String.Format("左上角坐标{ 0}" + vbCrLf + "矩形大小{ 1}", PtStart.ToString, RectSize.ToString), MsgBoxStyle.Information, "Info")
End Sub
Private Sub Form1_Load()Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Me.SetStyle(ControlStyles.AllPaintingInWmPaint Or ControlStyles.OptimizedDoubleBuffer Or ControlStyles.UserPaint, True)
End Sub
Private Sub Pic1_MouseUp()Sub Pic1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Pic1.MouseUp
If e.Button = Windows.Forms.MouseButtons.Left Then
Dim p As Point = PointToScreen(PtStart) : p.Offset(Pic1.Location)
ControlPaint.DrawReversibleFrame(New Rectangle(p.X, p.Y, pt.X - p.X, pt.Y - p.Y), Color.Red, FrameStyle.Dashed)
Call DrawRect(PtStart, New Point(e.X, e.Y))
pt = Nothing
End If
End Sub
End Class