November 30, 2020, 01:13:56 AM

Author Topic: [bb] Mouse Include by Curtastic [ 1+ years ago ]  (Read 601 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
[bb] Mouse Include by Curtastic [ 1+ years ago ]
« on: June 29, 2017, 12:28:41 AM »
Title : Mouse Include
Author : Curtastic
Posted : 1+ years ago

Description : Stores mousespeed, mousehit, mousedown, mousex
Tells if the user doubleclicked. Tells if a button was released this loop.
Each button also remembers where it was when the click started.

Just include it, and in your loop call mouseupdate()

I am using this for my RTS and my GUI.
Here is an example
Code: [Select]
;Mouse Example
;doubleclick to exit
;right click and drag to make lines


Include "mouseinclude.bb"

Graphics 800,600,0,2
SetBuffer BackBuffer()

mousecontrolled=1
HidePointer

;background image
image=CreateImage(800,600)

;main loop
Repeat
mouseupdate()

;right click to make lines
If mousereleased Then
SetBuffer ImageBuffer(image)
Line mousex,mousey,mouserstartx,mouserstarty
SetBuffer BackBuffer()
EndIf

DrawBlock image,0,0


If mouserdown Then
Text 1,1,"right button is down"
EndIf


;double click test
If mouselhitdouble Then
End
EndIf

;right click and drag shows the line
If mouserdown Then
Line mousex,mousey,mouserstartx,mouserstarty
EndIf


;draw mouse cursor
Rect mousex,mousey,5,5

Flip


If KeyHit(1) Then End
Forever


.
.
.
.
Here is the include file: [/i]

Code :
Code: BlitzBasic
  1. ;do not use Mouse_Speed(). Use mouseuttonspeed
  2. ;do not use MouseHit(). Use mouseuttonhit
  3. ;if mousecrontrolled then
  4.         ;do not use MouseX() Or MouseY(). Use mousex and mousey
  5.         ;do not use MoveMouse(). use mousex=
  6.  
  7.  
  8. Type Mouse
  9.         ;button left
  10.         Field bl.mousebutton
  11.         ;button right
  12.         Field br.mousebutton
  13.         ;button middle
  14.         Field bm.mousebutton
  15.         ;the position of the mouse
  16.         Field x,y
  17.         ;stores mousexspeed(),mouseyspeed()
  18.         Field speedx,speedy,speedz
  19.         ;this tells if the mouse pointer is hidden and kept at the center and you draw your own pointer
  20.         Field controlled
  21.         ;how many millisecs are allowed for a double click
  22.         Field hitdoublespeed
  23. End Type
  24. Global mouse.mouse=New mouse
  25.  
  26. mousehitdoublespeed=300
  27.  
  28.  
  29. mousel=New mousebutton
  30. mouselindex=1
  31. mouser=New mousebutton
  32. mouserindex=2
  33. mousem=New mousebutton
  34. mousemindex=3
  35.  
  36.  
  37. Type MouseButton
  38.         ;what number blitz uses for this button
  39.         Field index
  40.        
  41.         ;where the mouse was when the click started
  42.         Field startx,starty
  43.         ;if the button whas hit this loop
  44.         Field hit
  45.         ;tells if the button was let go this loop
  46.         Field released
  47.         ;tells if the button is down this loop
  48.         Field down
  49.         ;tells if the button was doubleclicked this loop
  50.         Field hitdouble
  51.         ;when it was let go
  52.         Field releasedtime
  53.         ;internal: makes sure no clicks were missed
  54.         Field hitcheck
  55. End Type
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  67. ;
  68. Function MouseUpdate()
  69.         Local b.mousebutton
  70.        
  71.  
  72.         mousespeedz=MouseZSpeed()
  73.         mousespeedx=MouseXSpeed()
  74.         mousespeedy=MouseYSpeed()
  75.         If mousecontrolled Then
  76.                 mousex=mousex+mousespeedx
  77.                 mousey=mousey+mousespeedy
  78.                 MoveMouse GraphicsWidth()/2,GraphicsHeight()/2
  79.        
  80.                 ;done after movemouse to fix mouse problems on some computers
  81.                 MouseXSpeed()
  82.                 MouseYSpeed()
  83.        
  84.                 mousex=keepin(mousex,0,GraphicsWidth()-1)
  85.                 mousey=keepin(mousey,0,GraphicsHeight()-1)
  86.  
  87.         Else
  88.                 mousex=MouseX()
  89.                 mousey=MouseY()
  90.         EndIf
  91.  
  92.  
  93.         For b=Each mousebutton
  94.                 b
  95. eleased=0
  96.                 bhitdouble=0
  97.  
  98.                 bhit=MouseHit(bindex)>0
  99.                 bdown=MouseDown(bindex)
  100.  
  101.                 If bhitcheck=0 Then bhitcheck=bhit
  102.                 If bhitcheck=1 And bdown=0 Then
  103.                         b
  104. eleased=1
  105.                         bhitcheck=0
  106.                 EndIf
  107.        
  108.                 If bhit=1 Then
  109.                         bstartx=mousex
  110.                         bstarty=mousey
  111.  
  112.                         If MilliSecs()-b
  113. eleasedtime<mousehitdoublespeed Then
  114.                                 bhitdouble=1
  115.                         EndIf
  116.                         b
  117. eleasedtime=MilliSecs()
  118.                 EndIf
  119.         Next
  120.  
  121. End Function
  122.  
  123.  
  124. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  125. ;pass Null if you want to flush all buttons
  126. Function MouseFlush(mb.mousebutton,speeds=1)
  127.         Local mb2.mousebutton
  128.  
  129.  
  130.         For mb2=Each mousebutton
  131.                 If mb2=mb Or mb=Null Then
  132.  
  133.                         mb2hit=0
  134.                         mb2startx=0
  135.                         mb2starty=0
  136.                         MouseHit(mb2index)
  137.                         mb2hitcheck=0
  138.  
  139.                 EndIf
  140.         Next
  141.  
  142.         If speeds=1 Then
  143.                 MouseZSpeed()
  144.                 MouseXSpeed()
  145.                 MouseYSpeed()
  146.                 mousespeedz=0
  147.                 mousespeedx=0
  148.                 mousespeedy=0
  149.         EndIf
  150. End Function
  151.  
  152.  
  153.  
  154. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  155. ;keeps num in bounds
  156. ;returns the same number if its already in bounds.
  157. Function KeepIn#(num#,min#,max#)
  158.         If num<min Then
  159.                 Return min
  160.         ElseIf num>max
  161.                 Return max
  162.         EndIf
  163.         Return num
  164. End Function


Comments :


churchaxe(Posted 1+ years ago)

 wow, this is exactly what I needed for my GUI, cool stuff!


 

SimplePortal 2.3.6 © 2008-2014, SimplePortal