BasicsTutorial/Mouse input and manipulation

Last-modified: 2008-03-10 (月) 15:04:14

Mouse input and manipulation

マウス入力と操作

Well we can have keyboard input now, but the mouse is also a really useful tool in any application or game.
よく、我々は現在キーボード入力をすることができる、しかし、マウスはどんなアプリケーションまたはゲームの本当に役に立つツールでもある。
So far all the mouse cursor has done is sit there on the screen doing pretty much nothing.
これまで、マウスカーソルがした全ては、ほとんど何もしていないスクリーンに表示されるだけ。
We want to use it to do stuff.
我々は、ものをするためにそれを使いたい。
Now that you know how the keyboard input works, the mouse will be a breeze.
あなたがキーボード入力がどのように働くかについてわかっている今、マウスは微風である。

How do we get where on the screen the mouse is?
どのように、我々はマウスがスクリーンでいるところを得るか?
Use MOUSEX() and MOUSEY().
MOUSEX()と MOUSEY()を使う。

`Data for boxes (4 sides)
data 100,100,200,200
data 300,150,400,250
data 200,300,400,400
dim boxes(3,4)
`Read in data
for x=1 to 3
  for y=1 to 4
     read boxes(x,y)
  next x
next x
do
  `Get mouse position
  mousePosX=mousex()
  mousePosY=mousey()
  `Loop through boxes
  for x=1 to 3
     `If mouse is inside the box draw it red, else draw it white
     if mousePosX>boxes(x,1) and mousePosX<boxes(x,3) and mousePosY>boxes(x,2) and mousePosY<boxes(x,4)
        ink rgb(255,0,0),0
     else
        ink rgb(255,255,255),0
     endif
     `Draw box
     box boxes(x,1),boxes(x,2),boxes(x,3),boxes(x,4)
  next x
loop

MOUSEX() and MOUSEY() get the x and y coordinates of the tip of the mouse cursor on the screen.
MOUSEX()と MOUSEY()を得なさい、そして、Xとyはスクリーンでマウスカーソルの先端の座標です。
Remember the default screen resolution is 640x480 pixels.
デフォルト画面解像度が640x480ピクセルであるのを思い出しなさい。

First of all we read the four sides, or two opposite corners of the boxes in, then in the loop we get the mouse position and store it in two variables.
まず第一に、我々は4つの側または箱の2つの反対側の角を読み取った、そして、ループでは、我々はマウス位置を得て、それを2つの変数に保管する。
We do this since we use both values more than once, so storing them in variables is faster than calling them again.
我々が一度ならず両方の値を使う時から、我々はこうするので、それらを変数に保管することは再びそれらを呼ぶことより速い。

Then we loop though all our boxes and test if the mouse is inside the box.
それから、たとえ全ての我々の箱とテストとしても、マウスがボックスにいるならば、我々は孤を描く。
We test this by saying “If the mouse x is more than the left side, and the mouse x is less than the right side, and the mouse y is more than the top side and the mouse y is less than the bottom side, then do stuff”.
我々は、「マウスxが左側以上であるならば、そして、マウスxは右側より少ない、そして、yが底面より少なくある一番上の側とマウスがそれからものをするより、マウスyは多くである」言うことによって、これをテストする。
So if the mouse is in-between the left and right sides and in-between the top and bottom sides, then it is obviously going to be in the box.
それで、マウスが左右が並ぶ中間とトップと底が並ぶ中間であるならば、それは明らかに、ボックスにありそうである。
This is a handy method that is used a lot and you should remember it.
これはたいへん使われる便利な方法である、そして、あなたはそれを覚えていなければならない。

We then set the colour according to whether it’s in or out of the square and draw the box.
我々は、それからそれが正方形で、または、の外にあるかどうかによって、色をセットして、箱を描く。

What if we wanted to draw the square a different colour when the left mouse button (LMB) was clicked, and then a different colour again if the right mouse button (RMB) was clicked, and then another if both were at the same 14:29:56
我々が再び正方形に 左マウスボタン(LMB)がクリックされた異なる色、それから、異なる色を描きたくて両者とも同じ時間にいるならば右のマウスボタン(RMB)がクリックされて、それから、また別であるならば?
Use MOUSECLICK().
MOUSECLICK()を使う。

     `If mouse is inside the box draw it a colour, else draw it white
     if mousePosX>boxes(x,1) and mousePosX<boxes(x,3) and mousePosY>boxes(x,2) and mousePosY<boxes(x,4)
        `If no mouse button is pressed
        if mouseclick()=0
           ink rgb(255,0,0),0
        else
           `If the LMB is pressed
           if mouseclick()=1
              ink rgb(255,255,0),0
           else
              `If the RMB is pressed
              if mouseclick()=2
                 ink rgb(0,255,0),0
              `If both are pressed
              else
                 ink rgb(100,100,255),0
              endif
           endif
        endif
     else
        ink rgb(255,255,255),0
     endif

Update this part of the code with the above code.
上記のコードでコードのこの部分を更新しなさい。
MOUSECLICK() returns different values depending on what is pressed.
MOUSECLICK()、押されることに従い、異なる値を返す。

Nothing = 0
LMB = 1
RMB = 2
Both = 3

Simple as that, need I say more?
それとして単純な?(私がより言う必要)

Now that we have got values of the mouse, what if we wanted to set the values of the mouse, like the cursor position?
我々がマウスの値を持っている今、我々がマウス(カーソル位置のような)の値をセットしたいならば、どうですか?

do
  `Get mouse position from user
  input "Choose mouse x position: ",xPos
  input "Choose mouse y position: ",yPos
  `Position mouse cursor and draw circle around cursor
  position mouse xPos,yPos
  circle xPos,yPos,20
  wait key
  cls
loop

POSITION MOUSE positions the mouse at the x and y coordinates specified.
POSITION MOUSEは、マウスを指定されるxとy座標に置く。

You can also hide and show the mouse, here’s how.
あなたは隠すこともできる、そして、マウスを表示することも、方法はここにある。

print "Mouse visible"
do
  `If 'h' is pressed hide mouse
  if inkey$()="h"
     hide mouse
     cls
     print "Mouse hidden"
  endif
  `If 's' is pressed show mouse
  if inkey$()="s"
     show mouse
     cls
     print "Mouse visible"
  endif
loop

All you need to do is HIDE MOUSE and SHOW MOUSE to hide and show the cursor.
あなたがする必要がある全ては、HIDE MOUSE と SHOW MOUSE、マウスがカーソルを隠して、示すことである。
The mouse cursor will still move around when hidden if you move the mouse, just without you seeing.
あなたがマウスを動かすならば隠されるとき、カーソルがまだ回るマウス(ちょうどわかっているあなたのない)。

To find how much the mouse has been moved between now and the last loop we could use some code like this…
マウスが今と最後のループの間でどんなに動かされたかについて突き止めるために、我々はこのようないくらかのコードを使用することができた

do
  `Get mouse pos
  mousePosX=mousex()
  mousePosY=mousey()
  `Get mouse movement
  moveX=mousePosX-lastMouseX
  moveY=mousePosY-lastMouseY
  `Store mouse pos for next time
  lastMouseX=mousePosX
  lastMouseY=mousePosY
  `I mouse is moved print values
  if moveX<>0 or moveY<>0
     print "Mouse movement x: ",moveX
     print "Mouse movement y: ",moveY
  endif
loop

It stores the last mouse position and finds out the difference between that and this mouse position (the mouse movement value).
それは最後のマウス位置を保存して、それと このマウス位置(マウス運動値)の違いを発見する。
But there is a much simpler way using 2 other commands.
しかし、2つの他のコマンドを使用している非常により単純な方法がある。

do
  `Get mouse movement
  moveX=mousemovex()
  moveY=mousemovey()
  `I mouse is moved print values
  if moveX<>0 or moveY<>0
     print "Mouse movement x: ",moveX
     print "Mouse movement y: ",moveY
  endif
loop

MOUSEMOVEX() and MOUSEMOVEY() just return the distance the mouse cursor has moved between the last time the commands were used and now.
MOUSEMOVEX()と MOUSEMOVEY()、ちょっとマウスカーソルが命令が使われたことを時の最後の間で、そして、今は動かした距離を返しなさい。
For this reason it is best to only use them when you are calling them every loop, or even call them every loop even if you aren’t using them.
この理由のために、あなたがそれらをあらゆるループと呼んでいるか、たとえあなたがそれらを使っていないとしてもそれらをあらゆるループと呼びさえするとき、それらを使うだけであることは最良である。

The last thing we are going to cover is the scroll wheel or button that you sometimes find in the middle of your mouse.
我々がカバーへ行っているという最後のことは、あなたが時々あなたのマウスの中央で見つけるスクロール車輪またはボタンである。
The way to call the position of this is using MOUSEZ().
これの位置を呼ぶ方法は、MOUSEZ()を使っている。
The value of MOUSEZ() is 0 at the beginning.
MOUSEZ()の値、0は始めである。

do
  cls
  mousePosZ=mousez()
  ink rgb(mousePosZ/60.0,0,0),0
  box 200,200,400,400
  ink rgb(255,255,255),0
  print mousePosZ
loop

Scroll the wheel to change the colour of the box.
箱の色を変えるために、車輪をスクロールしなさい。
My wheel increases/decreases by 120 each turn, but other wheels may vary.
120による私の車輪増加/減少は各々回る、しかし、他の車輪は異なるかもしれない。

You may have noticed the CLS at the top of the loop.
あなたは、ループの最上位で CLSに気がついたかもしれない。
Putting it there makes the screen clear but you can still see the things drawn on the screen.
それをそこに置くことはスクリーンをきれいにする、しかし、あなたはものがスクリーンに描くのをまだ見ることができる。
Put it at the bottom and the screen clears so that you can’t see anything.
それを底に置きなさい、そして、あなたが何も見ることができないように、スクリーンはクリアになる。
This feature is called the back buffer and we will go over it in more detail later.
この特徴はバックバッファと呼ばれている、そして、我々は更に詳細に後でそれを調べる。

MOUSEMOVEZ() measures the movement of the scroll wheel, I wont give an example since it is the same principle as the other commands.
MOUSEMOVEZ()スクロール車輪の動きを測る、それが他の命令と同じ原則である時から、i習慣は例を挙げる。

Summary of Commands

命令の概要

· MOUSEX(), MOUSEY() - Returns the position of the mouse in 2D values.
MOUSEX()、MOUSEY()- 2D値でマウスの位置を返す。

· MOUSEZ() - Returns the value of the mouse scroll wheel/button that you sometimes find in the middle of mice.
MOUSEZ()- あなたが時々マウスの中央で見つけるマウス・スクロール車輪/ボタンの値を返す。

· MOUSEMOVEX(), MOUSEMOVEY(), MOUSEMOVEZ() - Returns the movement of the mouse cursor / mouse scroll wheel between the last call of the command and this call.
MOUSEMOVEX()、MOUSEMOVEY()、MOUSEMOVEZ()- 命令の最後の呼び出しの間のマウスカーソル/マウス・スクロール車輪の動きとこれが呼ぶRETURN。

· POSITION MOUSE x,y - Positions the mouse cursor at the specified coordinates.
POSITION MOUSE x,y - マウスカーソルを指定された座標に置く。

· HIDE MOUSE - Hides the mouse cursor.
HIDE MOUSE - マウスカーソルを隠す。

· SHOW MOUSE - Shows mouse cursor.
SHOW MOUSE - マウスカーソルを示す。

End of Section Tasks

セクション終わりの作業

l Make a program that allows you to click and hold boxes and drag them around the screen.
クリックして、箱を持って、スクリーンのまわりにそれらをドラッグすることができるプログラムを行いなさい。
If you want try and make it so they have a hierarchy system, where if a box is covering another box, the underneath one is not moved.
あなたが必要とするならば、それには階層システムがあるように、たどり着くよう努めなさい、そこで、箱がもう一つの箱をカバーしているならば、下になっているものは動かされない。