Menu using Mouse Bad

BlitzPlus Forums/BlitzPlus Programming/Menu using Mouse Bad

starsoft(Posted 2002) [#1]
I can't find out why the Menu below won't work using mouse
commands. It works gret using keyboard comands. I tried to use GetKey in both selections but the first choice would run rite thru the second choice. Can anbody help me?
Repeat
X=MouseX()
Y=MouseY()
If MouseDown(1) Then Exit
No%=GetKey()
Num$=Upper$(Chr$(No))
Until Num$>"A" And Num$<"U"

Color 255,255,255

SelectMenu(Num$,X,Y)

FlushKeys
Itm=0
Repeat
If MouseDown(1)
X=MouseX()
Y=MouseY()
SelectItem(Num$,Itm)
Itm=99
EndIf
Itm=WaitKey(); if iuse Getkey here program does not work at all
Until Itm>0 And Itm<9 Or Itm=99
If Itm=99 Then Goto Line1
SelectItem(Num$,Itm)
Goto Line1
End ; Rem End PROGRAM

Function SelectMenu(Num$,X,Y)
If Asc(Num$)=0
If X>1 And X<90
Num$="R"
EndIf
If X>96 And X<160
Num$="S"
EndIf
If X>160 And X<227
Num$="C"
EndIf
If X>232 And X<366
Num$="P"
EndIf
If X>374 And X<479
Num$="T"
EndIf
If X>481 And X<558
Num$="Q"
EndIf
If X>561 And X<640
Num$="B"
EndIf
If X>641 And X<700
Num$="H"
EndIf
EndIf

Select Num$
Case "R" : DrawImage Menu2,1,43
Case "S" : DrawImage Menu3,98,43
Case "C" : DrawImage Menu4,168,43
Case "P" : DrawImage Menu5,234,43
Case "T" : DrawImage Menu6,376,43
Case "Q" : DrawImage Menu7,484,43
Case "B" : DrawImage Menu8,564,43
Case "H" : DrawImage Menu9,644,43
Default
Num$="Q"
End Select
Return Num$
End Function

Function SelectItem(Num$,Itm)
If Itm=0
Select Y
Case 43,44,45,46,47,48,49,50,51,52,53 : Itm=49
Case 58,59,60,61,62,63,64,65,66,67,68 : Itm=50
Case 73,74,75,76,77,78,79,80,81,82,83 : Itm=51
Case 98,99,100,101,102,103,104,105,106,107,108 : Itm=52
Case 103,104,105,106,107,108,109,110,111,112,113 : Itm=53
Case 118,119,120,121,122,123,124,125,126,127,128 : Itm=54
Case 133,134,135,136,137,138,139,140,141,142,143 : Itm=55
Case 148,149,150,151,152,153,154,19,193,194,195 : Itm=59
Default
End Select
EndIf
If Num="R"
Select Itm
Case 49
Case 50
Case 51
Case 52
Case 53
Case 54 : Locate 500,400 : Print "INSIDE Itm="+Itm
Case 55 : End
Default
End Select
EndIf
If Num="S"
Select Itm
Case 49
Case 50
Case 51
Case 52 : Locate 500,400 : Print "INSIDE Itm="+Itm
Default
End Select
EndIf
If Num="C"
Select Itm
Case 49
Case 50
Case 51
Case 52
Case 53
Case 54
Case 55 : Text 140,490,"Picked Catagory Codes"
Case 56 : Locate 500,400 : Print "INSIDE Itm="+Itm
Default
End Select
EndIf
If Num="P"
Select Itm
Case 49
Case 50
Case 51
Case 52
Case 53
Case 54
Case 55
Case 56 : Locate 500,400 : Print "INSIDE Itm="+Itm
Default
End Select
EndIf
If Num="T"
Select Itm
Case 49
Case 50
Case 51
Case 52 : Locate 500,400 : Print "INSIDE Itm="+Itm
Default
End Select
EndIf
If Num="Q"
Select Itm
Case 49
Case 50
Case 51
Case 52
Case 53
Case 54
Case 55
Case 56 : Locate 500,400 : Print "INSIDE Itm="+Itm
Default
End Select
EndIf
If Num="B"
Select Itm
Case 49
Case 50
Case 51
Case 52
Case 53
Case 54
Case 55: Locate 500,400 : Print "INSIDE Itm="+Itm
Default
End Select
EndIf
If Num="H"
Select Itm
Case 49
Case 50 : Locate 500,400 : Print "INSIDE Itm="+Itm
Default
End Select
EndIf
WaitKey ;< This command here temporarily To show selected Item
End Function


Tiger(Posted 2002) [#2]
Hello, Try to do Num$ Global.
or change the line:
SelectMenu(Num$,X,Y)

To:
Num$=SelectMenu(Num$,X,Y)

I don't know if it's the problem, but you can try.


Tiger(Posted 2002) [#3]
Here is a fix:

Global Num$
Global EndIt=False

Repeat

Num$=""

Repeat

If MouseDown(1) Then Exit
No%=GetKey()
Num$=Upper$(Chr$(No))

If KeyHit(1) Then EndIt=True:Exit;Esc end it all

Until Num$>"A" And Num$<"U"

Color 255,255,255

SelectMenu()
Delay 200

FlushKeys:FlushMouse

Itm=0

Repeat
If MouseDown(1)

SelectItem()
Exit
Else
Itm=GetKey()
If (Itm>49 And Itm<59)
Itm=SelectItem(Itm)
Exit
End If
End If
If KeyHit(1) Then Endit=True

Until Endit

Until Endit

End ; Rem End PROGRAM

Function SelectMenu()

If Num$=""

X=MouseX()


If X>1 And X<90
Num$="R"
EndIf
If X>96 And X<160
Num$="S"
EndIf
If X>160 And X<227
Num$="C"
EndIf
If X>232 And X<366
Num$="P"
EndIf
If X>374 And X<479
Num$="T"
EndIf
If X>481 And X<558
Num$="Q"
EndIf
If X>561 And X<640
Num$="B"
EndIf
If X>641 And X<700
Num$="H"
EndIf
EndIf

Select Num$
Case "R" : DrawImage Menu2,1,43
Case "S" : DrawImage Menu3,98,43
Case "C" : DrawImage Menu4,168,43
Case "P" : DrawImage Menu5,234,43
Case "T" : DrawImage Menu6,376,43
Case "Q" : DrawImage Menu7,484,43
Case "B" : DrawImage Menu8,564,43
Case "H" : DrawImage Menu9,644,43
Default
Num$="Q"
End Select


End Function

Function SelectItem(Itm=0)

If Itm=0


Y=MouseY()

Select Y

Case 43,44,45,46,47,48,49,50,51,52,53 : Itm=49
Case 58,59,60,61,62,63,64,65,66,67,68 : Itm=50
Case 73,74,75,76,77,78,79,80,81,82,83 : Itm=51
Case 98,99,100,101,102,103,104,105,106,107,108 : Itm=52
Case 103,104,105,106,107,108,109,110,111,112,113 : Itm=53
Case 118,119,120,121,122,123,124,125,126,127,128 : Itm=54
Case 133,134,135,136,137,138,139,140,141,142,143 : Itm=55
Case 148,149,150,151,152,153,154,19,193,194,195 : Itm=59
End Select

EndIf

If Num$="R"
Select Itm
Case 49
Print "First Itm."
Case 50
Case 51
Case 52
Case 53
Case 54
Case 55 : End
Default
End Select
EndIf

If Num$="S"
Select Itm
Case 49
Case 50
Case 51
Case 52
Default
End Select
EndIf

If Num$="C"
Select Itm
Case 49
Case 50
Case 51
Case 52
Case 53
Case 54
Case 55
Print "Picked Catagory Codes"
Case 56
Print "INSIDE Itm="+Itm
Default
End Select
EndIf


If Num$="P"
Select Itm
Case 49
Case 50
Case 51
Case 52
Case 53
Case 54
Case 55
Case 56
Default
End Select
EndIf

If Num$="T"
Select Itm
Case 49
Case 50
Case 51
Case 52

Default
End Select
EndIf


If Num$="Q"
Select Itm
Case 49
Case 50
Case 51
Case 52
Case 53
Case 54
Case 55
Case 56
DebugLog "INSIDE Itm="+Itm

End Select
EndIf


If Num$="B"
Select Itm
Case 49
Case 50
Case 51
Case 52
Case 53
Case 54
Case 55

Default
End Select
EndIf
If Num$="H"
Select Itm
Case 49
Case 50

Default
End Select
EndIf

Return Itm

End Function


Bye.


starsoft(Posted 2002) [#4]
Thanx Tiger

I compiled my program 2 ways. With debug enabled and with debug diabled. It didn't show a mouse cursor! Do I have to create a cursor or use showpointer or whut do I need to do to show a mouse cursor after compiling?


Tiger(Posted 2002) [#5]
Hello.
If you are using full screen mode, the mouse pointer will not show.
You must create it your self.
And its easy:

Xpoint=MouseX()
Ypoint=MouseY()
DrawImage My_Point,Xpoint,Ypoint

If you want to centre the pointer from the begining.
You can do this for a 640x480 screen:

MoveMouse 640/2,480/2


Happy New Year, from a chilly Sweden.
Bye.


starsoft(Posted 2002) [#6]
Thanx for the Tiger in my Tank!!!!
Have a Good New Year via starsoft in Southern Illinois USA!!


starsoft(Posted 2002) [#7]
Please don't laugh at me. I hate it when people laugh at me. I tried that and of course it didn,t work. I think because I have to make an Image called My_Point! How can I make an Image of just an Arrow? Images co-ordinates are rectangular in size.

Xpoint=MouseX()
Ypoint=MouseY()
DrawImage My_Point Xpoint,Ypoint
WaitKey()


Perturbatio(Posted 2002) [#8]
you need to use maskimage on the image, make the area that you don't want to show something that you won't use in the image itself (magenta is a popular one) which is the red and blue values set to full (255) and no green, when masking, you can do:
MaskImage my_pointer,255,0,255
and it will then display every pixel that is NOT magenta when drawing it.


starsoft(Posted 2002) [#9]
Thank You Perturbatio!
You've made my Day(er Nite)!! I'm not really a newbie I just think like one. You are a gentleman and a scholar!


Perturbatio(Posted 2003) [#10]

You are a gentleman and a scholar!



That's slander that is!

Last edited 2010


gnipper(Posted 2003) [#11]
Hi there - im strugglin with something similar - i can get the mousepointer on the screen but it leaves a trail behind itself which would eventually cover the screen - how do i clear the image once its moved leaving the background intact?


Valgar(Posted 2003) [#12]
May i see your code to see if i fix it?


gnipper(Posted 2003) [#13]
ok. here it is - ive done a "patchy" fix which works but there must be a better way - basically what I am doing is continuously re-displaying the menupicture!

Function mainmenu()
SetBuffer BackBuffer()
menupic = LoadImage ("C:\Documents and Settings\Lee\My Documents\BB Games\Odds On\MainMenu copy.jpg")
pointer = LoadImage ("C:\Documents and Settings\Lee\My Documents\BB Games\Odds On\horsep.bmp")
DrawImage menupic,0,0
MaskImage pointer,255,255,255
DrawImage pointer,MouseX(),MouseY()

Repeat
DrawImage menupic,0,0
DrawImage pointer,MouseX(),MouseY()
Flip
SetBuffer BackBuffer() : Cls
Until KeyHit(1)

End Function


Valgar(Posted 2003) [#14]
I suppose that at the beginning of your code there's a line like this:
graphics 640,480,16,2 (or something similar)
try to cancel the setbuffer backbuffer() in your function and place the command immediately under the graphics declaration.
then at the beginning of your main loop you put the "cls" command
Something like this:

Graphics 640,480,32,2
setbuffer backbuffer()
;MAIN
repeat
cls
drawimage menupic,0,0
drawimage pointer,mousex(),mousey()
flip
until keyhit(1)
Ha....remember of loading your image first of your main loop and not into the main,because if u do so you continue to load the graphics and the frame-rate drops to 0 -_-


gnipper(Posted 2003) [#15]
Brilliant - it works thanks. Maybe you can help me a little more!! Im being greedy ;-)

Im drawing multiple sprites on a screen and moving them along - is there a command to clear the last image pasted for a particular sprite (i.e. so they appear to move along the screen without leaving a trail)?


Valgar(Posted 2003) [#16]
If your problem is only the trail the resolution is simple i think...
The error is the position of the cls command.
CLS must be at the beginning of the main(and must be IN the main not outside)
This passage in the code:
"setbuffer backbuffer()"
"CLS"
"flip"
is called for setting all the drawing operation in the back buffer (that remain invisible to the user) then flip the front buffer and the backbuffer so you can see the drawing

Doing this in the main loop constantly do this page flipping type of animation.


gnipper(Posted 2003) [#17]
yes this will work however what i need is to only clear a small area of the screen as i dont want to lose the positions of my other sprites!

Image 10 horses running across the screen - this is what I am trying to achieve!!


Valgar(Posted 2003) [#18]
Look at this code,i have commented the CLS in the main and placed it outside the main:

Graphics 640,480,32,2
SetBuffer BackBuffer()
Cls ;not here!!!
Global menupic = LoadImage ("C:\button1.bmp") ;change this with your image
Global pointer = LoadImage ("C:\button2.bmp") ;change this with your image



;MAIN
While Not KeyHit(1)
;Cls
mainmenu()
Flip
Wend
End
;END MAIN





Function mainmenu()
DrawImage menupic,MouseX()+110,MouseY()+110
MaskImage pointer,255,255,255
DrawImage pointer,MouseX(),MouseY()
End Function



And look at this:

Graphics 640,480,32,2
SetBuffer BackBuffer()
Global menupic = LoadImage ("C:\button1.bmp") ;change this with your image
Global pointer = LoadImage ("C:\button2.bmp") ;change this with your image



;MAIN
While Not KeyHit(1)
Cls
mainmenu()
Flip
Wend
End
;END MAIN





Function mainmenu()
DrawImage menupic,MouseX()+110,MouseY()+110
MaskImage pointer,255,255,255
DrawImage pointer,MouseX(),MouseY()
End Function


The second is the right version :)


Valgar(Posted 2003) [#19]
If you want not to clear the other sprites on the back do you repeat it's drawing.
Maibe if i can see the code....if you want to email me i can post my email.


gnipper(Posted 2003) [#20]
you are a star!

Sometimes i cant see the wood for the trees - a simple for-next loop to redraw sprites sorted it!!

Brilliant, cheers mate


Valgar(Posted 2003) [#21]
Try this code,i think it would be of help (sorry for the bad grammar hehe)

Graphics 640,480,32,2
SetBuffer BackBuffer()

Global image1=LoadImage("c:\button1.bmp")
Global image2=LoadImage("c:\button2.bmp")
Global image3=LoadImage("c:\button3.bmp")

Global posx1=100
Global posx2=100
Global posx3=100
Global posy1=100
Global posy2=100
Global posy3=100

Global speed1=1 ;speed of the movement 1
Global speed2=2 ;speed of movement 2
Global speed3=4 ;speed of movement 3
;MAIN
While Not KeyHit(1)
Cls
move_one()
move_two()
move_three()
Flip
Wend

;END MAIN


Function move_one()
DrawImage image1,posx1,posy1
posx1=posx1+speed1
If posx1 => 300
posx1=posx1-speed1 ;i change the direction with this :)
speed1=-1
EndIf

If posx1 =< 100
posx1=posx1+speed1
speed1=+1 ;this return the direction at the beginning and start over again :)
EndIf
End Function

Function move_two()
DrawImage image2,posx2,posy2
posy2=posy2+speed2
If posy2 => 300
posy2=posy2-speed2
speed2=-2 ;change of direction
EndIf

If posy2 =< 100
posy2=posy2+speed2
speed2=+2 ;return at the original direction
EndIf
End Function

Function move_three()
DrawImage image3,posx3,posy3
posy3=posy3+speed3
posx3=posx3+speed3
If posy3 => 300
posy3=posy3-speed3
speed2=-4 ;same change of dir
EndIf

If posy3 =< 100
posy3=posy3+speed3
speed3=+3 ;same return at the same dir
EndIf

If posx3 => 300
posx3=posx3-speed3
speed3=-4 ;change of dir
EndIf

If posx3 =< 100
posx3=posx3+speed3
speed3=+4 ;return at the origin
EndIf
End Function



have fun :P