GLBasic forum

Main forum => GLBasic - en => Topic started by: Jonás Perusquía on 2013-Mar-28

Title: Button pressed, then released
Post by: Jonás Perusquía on 2013-Mar-28
Hello my friends, i come here to ask you if there is any way to change the value of a variable but after releasing the pressed button

Code (glbasic) Select
a=0
WHILE TRUE
MOUSESTATE mx,my,b1,b2
IF b1= TRUE THEN a=1
SHOWSCREEN
WEND

using this will change the value at pressing, but how to change value after releasing?


thank you in advance
Title: Re: Button pressed, then released
Post by: Ruidesco on 2013-Mar-28
Quick hack:
Code (glbasic) Select
a = 0
last_b1 = FALSE
WHILE TRUE
    MOUSESTATE mx, my, b1, b2
    IF b1 = TRUE THEN a = 1
    IF b1 = FALSE AND last_b1 = TRUE THEN a = "just released!"
    last_b1 = b1
    SHOWSCREEN
WEND
Title: Re: Button pressed, then released
Post by: Jonás Perusquía on 2013-Mar-28
thank you for your valuable help! , i have written the next based on your code:

Code (glbasic) Select
GLOBAL a,mx,my,b1,b2,last_b1

a = 0

TYPE click
last_b1

FUNCTION call:
self.last_b1 = FALSE
ENDFUNCTION

FUNCTION released:
self.last_b1 = b1
ENDFUNCTION
ENDTYPE

GLOBAL rel AS click

WHILE TRUE
MOUSESTATE mx, my, b1, b2
IF b1 = FALSE AND rel.last_b1 = TRUE THEN a = a+1
rel.released();
PRINT a,200,200,TRUE
SHOWSCREEN
WEND


WORKS TERRIFICALLY WELL :)
Title: Re: Button pressed, then released
Post by: matchy on 2013-Mar-28
Here is my updated mouse function:
Code (glbasic) Select

// matchy's mouse lib - Mar/Apr 2013
TYPE _point
x
y
last_x
last_y
ENDTYPE

TYPE _mouse
zorder
id
ver AS _point
b1
b2
last_b1
last_b2
last_x_down
last_y_down
joy_x
joy_y
joy_z
last_joy_x
last_joy_y
last_joy_z
toggle_x
toggle_y
toggle_z
toggle_last_x
toggle_last_y
toggle_last_z
axis_x
axis_y
state_b1
state_b2
state_off = 0
state_down = 1
state_on = 2
state_up = 3
state_move = 4
anim_b1
anim_b2

FUNCTION Update:
// self.id = self_id
SETACTIVEMOUSE self.id
self.ver.last_x = self.ver.x
self.ver.last_y = self.ver.y
self.last_b1 = self.b1
self.last_b2 = self.b2
self.last_joy_x = self.joy_x
self.last_joy_y = self.joy_y
self.last_joy_z = self.joy_z
self.axis_x = 0
self.axis_y = 0
MOUSESTATE self.ver.x, self.ver.y, self.b1, self.b2
SELECT self.b1
CASE 0
SELECT self.last_b1
CASE 0
self.state_b1 = self.state_off
self.anim_b1 = 0
CASE 1
self.state_b1 = self.state_up
self.anim_b1 = 0
ENDSELECT
CASE 1
SELECT self.last_b1
CASE 0
IF self.anim_b1 = 0
self.state_b1 = self.state_down
self.last_x_down = self.ver.x
self.last_y_down = self.ver.y
ELSE
self.anim_b1 = 0
ENDIF
CASE 1
self.state_b1 = self.state_on
INC self.anim_b1
IF self.ver.x <> self.ver.last_x AND self.ver.y <> self.ver.last_y
self.state_b1 = self.state_move
ENDIF
self.axis_x = self.last_x_down - self.ver.x
self.axis_y = self.last_y_down - self.ver.y
ENDSELECT
ENDSELECT
IF self.id = 0
SELECT self.b2
CASE 0
SELECT self.last_b2
CASE 0
self.state_b2 = self.state_off
self.anim_b2 = 0
CASE 1
self.state_b2 = self.state_up
self.anim_b2 = 0
ENDSELECT
CASE 1
SELECT self.last_b2
CASE 0
self.state_b2 = self.state_down
self.anim_b2 = 0
CASE 1
self.state_b2 = self.state_on
INC self.anim_b2
ENDSELECT
ENDSELECT
self.joy_x = GETJOYX(self.id)
self.joy_y = GETJOYY(self.id)
self.joy_z = GETJOYZ(self.id)
ENDIF
ENDFUNCTION
ENDTYPE

GLOBAL mse AS _mouse
GLOBAL ver AS _point

loop()

FUNCTION loop:
SYSTEMPOINTER TRUE
WHILE TRUE
mse.Update()
IF mse.state_b1 = mse.state_move
DRAWLINE 0, 0, mse.ver.x, mse.ver.y, RGB(255 - RND(64), 255 - RND(64), 255 - RND(64))
ENDIF
SHOWSCREEN
WEND
ENDFUNCTION

Title: Re: Button pressed, then released
Post by: Jonás Perusquía on 2013-Apr-02
thank you matchy for sharing your code with me and with the others, can you explain me how to put it to work? thanks in advance
Title: Re: Button pressed, then released
Post by: Jonás Perusquía on 2013-Apr-02
Ruidesco, i had some issues with your code but everything should be working now :)

the reworked code is now like this:
Code (glbasic) Select
GLOBAL a,mx,my,b1,b2
a = 0
TYPE click
last_b1

FUNCTION released:
self.last_b1 = b1
ENDFUNCTION
ENDTYPE

GLOBAL rel AS click

SYSTEMPOINTER TRUE

WHILE TRUE
rel.released();
MOUSESTATE mx, my, b1, b2
IF b1 = FALSE AND rel.last_b1 = TRUE THEN a = a+1
PRINT a,200,200,TRUE
rel.released();
SHOWSCREEN
WEND
Title: Re: Button pressed, then released
Post by: matchy on 2013-Apr-03
jonaspm, I've updated the code for cut and paste sample. A mse[] array can also be created for multitouch.  :good:
Title: Re: Button pressed, then released
Post by: mentalthink on 2013-Apr-03
I do something like this:

Code (glbasic) Select
if b1 and RR=0 then lock_Release=true

if lock_Release
I do want I want to do
endif


If you want unrelease, then you have to search some process when you want desactivate...


RR usually I use a simple CONSTANT   constant RR = false or ' 0 '
Title: Re: Button pressed, then released
Post by: MrTAToad on 2013-Apr-03
Could try something like the following :

previous mouse info = current mouse info
get current mouse info
if previous mouse button = 1 and current mouse button = 0 then deal with button pressed and then released
Title: Re: Button pressed, then released
Post by: Hark0 on 2013-Apr-04
Hi!

@jonaspm, you can download my "skeleton" project file (in my blog)... you can see how I declare and use buttons made by me... very easy.

;)
Title: Re: Button pressed, then released
Post by: Jonás Perusquía on 2013-Apr-04
Thank you all, you too matchy and Hark0 :)