Canvas + Menu o.o?

Blitz3D Forums/Blitz3D Beginners Area/Canvas + Menu o.o?

Apollonius(Posted 2003) [#1]
Invalide Menu Handle?
Any idea whats wrong with my code ?


window=CreateWindow( "Window",10,30,640,480,window,15)

canvas=CreateCanvas( 0,0,ClientWidth(window),ClientHeight(window),window )

SetGadgetLayout canvas, 1, 1, 1, 1
;------------------- MENU
game=CreateMenu( "File",0,window )
CreateMenu "New Game",1,game
CreateMenu "Load Game",2,game
CreateMenu "Save Game",3,game
CreateMenu "",0,game
CreateMenu "Exit",4,game
;------------------- IMAGES
ship=LoadImage("img\ship3.bmp")

SetBuffer CanvasBuffer(canvas)

timer=CreateTimer(60) ;for 60 FPS

While WaitEvent()

   Select EventID()

	

		Case $803
			
			End

		Case $4001
		
		;main() ** HERE YOU PUT YOUR MAIN LOOP **
		
		Cls
		DrawImage ship,300,200
		FlipCanvas canvas

	End Select

Wend



soja(Posted 2003) [#2]
See the docs for CreateMenu:

...
'Top level' window menus (for example, the 'File' and 'Edit' menus found in many applications, and the example below) should be attached to the menu returned by the WindowMenu command. Sub menu items are then attached to the menu handle returned by this command.
...

So, the line should be like this:
game=CreateMenu( "File",0,WindowMenu(window) )



Apollonius(Posted 2003) [#3]
Thanks!
it didnt work at first but i added
UpdateWindowMenu window
now it works ^^

how do I made it so that if they
click New Game... something happens

in the case thing

example:
if new_game
{ this happen }


soja(Posted 2003) [#4]
You need to add a menu event handler in your loop (see docs for WaitEvent)


Apollonius(Posted 2003) [#5]
Ok I looked at the manuel and ended up with this:

WaitEvent($1001)
If EventID()=1 Then
	; New Game is clicked?
	Endif

I don't think this is it but Im checking with u, is it?


Gabriel(Posted 2003) [#6]
That's it, but it looks neater if you write it like this :

Select EventID()
Case 1
      ; New Game is Clicked
Case 2
      ; Load Games is Clicked
Case 3
      ; Save Game is clicked

; AND SO ON

End Select



I would also use constants for the menu id's as suggested earlier so that you can make the code easier to read when you haven't looked at it for a few days/weeks.


Apollonius(Posted 2003) [#7]
Sybixsus, I was wondering in my code below you can see that theres already a Select EventID(), so if i add "Case 1" It will work right?

What do you mean by using constants for the menu ID?
(sorry me still stupid)
window=CreateWindow( "Window",10,30,750,550,window,15)

canvas=CreateCanvas( 0,0,ClientWidth(window),ClientHeight(window),window )

SetGadgetLayout canvas, 1, 1, 1, 1
;------ MENU -------
file=CreateMenu( "File",0,WindowMenu(window) )
CreateMenu "New Game",1,file
CreateMenu "",0,file
CreateMenu "     Exit",2,file
;-------------------
UpdateWindowMenu window
;-------------------

ship=LoadImage("img\ship3.bmp")

SetBuffer CanvasBuffer(canvas)

timer=CreateTimer(60) ;for 60 FPS

While WaitEvent()

   Select EventID()

	
		Case $803
			
			End

		Case $4001
		
		;main() ** HERE YOU PUT YOUR MAIN LOOP **
		
		Cls
		DrawImage ship,300,200
		FlipCanvas canvas

	End Select

Wend


Edited:
I tested it added:
Case 1
Notify "New Game"

Case 2
Notify "End"
It doesnt work :(