Double-click GUI dilema

BlitzPlus Forums/BlitzPlus Beginners Area/Double-click GUI dilema

Siopses(Posted 2007) [#1]
I've been messing around with G.U.I coding lately, and I'm
curious on why I need to double-click to get anything to work.
The problem is, how can this work with menu's? Here is my
hub example:

menu=WindowMenu(window)
file=CreateMenu("FILE",1,menu)
finish=CreateMenu("EnD",2,file)
UpdateWindowMenu window
bank=CreateBank(20)
PokeInt bank,0,window
PokeInt bank,4,enter
PokeInt bank,8,texto
PokeInt bank,12,file
PokeInt bank,16,finish
.begin
Repeat
	ReturnText(bank)
	Menuz(bank)
Until WaitEvent()=$803
blah=Proceed("Are you sure"+Chr(10)+"you want to quit?")
	If blah=1 Then
		End
			Else
				If blah<>1 Then
					Goto begin
				EndIf
	EndIf
Function ReturnText(bank)
	enter=PeekInt(bank,4)
	texto=PeekInt(bank,8)
		Select WaitEvent()
			Case $401
				If EventSource()=enter Then
					Notify(TextAreaText(texto))
						If TextAreaText(texto)="" Then
							Notify("Write text first, then hit enter")
						EndIf
				EndIf
		End Select
End Function 
Function Menuz(bank)
	file=PeekInt(bank,12)
	finish=PeekInt(bank,16)
		Select WaitEvent()
			Case $1001
				If EventSource()=finish Then 
					Notify("Ta ta for now!")
					Delay 500
					End
				EndIf
		End Select
End Function 
		
							




CS_TBL(Posted 2007) [#2]
I've told you before.

Only 1 (one, een, uno, un, einz) WaitEvent() in your app's mainloop is enough. You currently have two extra, by means of functions.

Things like $803, $1001, $401 etc. are event ID's. So, every time you select on WaitEvents() you're doing it wrong.

If you have one WaitEvent() in your mainloop (between the Repeat - Until), then you don't need it anywhere else as global variables are filled whenever there's an event, and globals can be read everywhere.

If you want to check on events, then use "Select EventID()", not "Select WaitEvent()".


Siopses(Posted 2007) [#3]
Thank you, now just let me test it... with this code the one
click is now the default G.U.I sparker, however not for the
menus.

window=CreateWindow("GUI TEST",200,500,300,300,window,15)
enter=CreateButton("RETURN TEXT",200,200,75,100,window,1)
texto=CreateTextArea(100,50,60,20,window)
menu=WindowMenu(window)
file=CreateMenu("FILE",1,menu)
finish=CreateMenu("EnD",2,file)
UpdateWindowMenu window
bank=CreateBank(20)
PokeInt bank,0,window
PokeInt bank,4,enter
PokeInt bank,8,texto
PokeInt bank,12,file
PokeInt bank,16,finish
.begin
Repeat
	WaitEvent()
	ReturnText(bank)
	Menuz(bank)
Until WaitEvent()=$803
blah=Proceed("Are you sure"+Chr(10)+"you want to quit?")
	If blah=1 Then
		End
			Else
				If blah<>1 Then
					Goto begin
				EndIf
	EndIf
Function ReturnText(bank)
	enter=PeekInt(bank,4)
	texto=PeekInt(bank,8)
		Select EventID()
			Case $401
				If EventSource()=enter Then
					Notify(TextAreaText(texto))
						If TextAreaText(texto)="" Then
							Notify("Write text first, then hit enter")
						EndIf
				EndIf
		End Select
End Function 
Function Menuz(bank)
	file=PeekInt(bank,12)
	finish=PeekInt(bank,16)
		Select EventID()
			Case $1001
				If EventSource()=finish Then 
					Notify("Ta ta for now!")
					Delay 500
					End
				EndIf
		End Select
End Function 


{EDIT}
Actually not, infact nothing has changed.


CS_TBL(Posted 2007) [#4]
Repeat
	WaitEvent()
	ReturnText(bank)
	Menuz(bank)
Until WaitEvent()=$803   <---- so, what's this hm?



CS_TBL(Posted 2007) [#5]
and your indenting sux :P


Siopses(Posted 2007) [#6]
What're you talking about? What's wrong with my indenting?
THIS MENU PROBLEM IS SO FRUSTRATING!
IT SEEMS TO BE ADEQUATE CODE, WHY WON'T IT WORK!?
MY GOD!


CS_TBL(Posted 2007) [#7]
iirc I've seen you make the same mistake before, in another thread, and I told there exactly what to do. So, why are you doing the same mistakes twice?

	If blah=1 Then
		End
			Else ; <- wrong indent
				If blah<>1 Then ;<- and below: wrong indent + redundant
					Goto begin
				EndIf
	EndIf


Besides, "If blah<>1 Then", that's fairly obvious, if the first part of the IF is done when blah=1 then this ELSE part is done when blah<>1, no need to add an extra check.

Also, the Select - End Select lines themself in the functions don't need to be indented, only the scope of those commands, but not the commands themself.

$1001 for menu action is done using ID's in EventData(), EventSource isn't relevant here. The '2' from this line so to say: "finish=CreateMenu("EnD",2,file)"

Technically you also don't want gotos and labels btw. Whenever you move to Blitzmax, and you're working in strict or superstrict mode, goto isn't even supported yet. Goto is a thing from the past.


CS_TBL(Posted 2007) [#8]
6 days ago I said the same in the 'Stumped on this' thread.


CS_TBL(Posted 2007) [#9]
Here's the whole shebang, fixed, improved. Note how I reduced your quit/areyousure routine to one line. Also now how I indented and added whitelines.

window=CreateWindow("GUI TEST",200,500,300,300,window,15)
enter=CreateButton("RETURN TEXT",200,200,75,100,window,1)
texto=CreateTextArea(100,50,60,20,window)

menu=WindowMenu(window)
file=CreateMenu("FILE",1,menu)
finish=CreateMenu("EnD",2,file)
UpdateWindowMenu window

bank=CreateBank(20)
PokeInt bank,0,window
PokeInt bank,4,enter
PokeInt bank,8,texto
PokeInt bank,12,file
PokeInt bank,16,finish

Repeat
	WaitEvent()
	ReturnText bank
	Menuz bank
	
	If EventID()=$803
		If Proceed("Are you sure"+Chr(10)+"you want to quit?") End
	EndIf
	
Forever

Function ReturnText(bank)

	enter=PeekInt(bank,4)
	texto=PeekInt(bank,8)
	
	Select EventID()
		Case $401
			If EventSource()=enter Then
				Notify(TextAreaText(texto))
				If TextAreaText(texto)="" Then
					Notify("Write text first, then hit enter")
				EndIf
			EndIf
	End Select
	
End Function 

Function Menuz(bank)

	file=PeekInt(bank,12)
	
	Select EventID()
		Case $1001
			If EventData()=2 Then 
				Notify("Ta ta for now!")
				Delay 500
				End
			EndIf
	End Select
	
End Function 



Siopses(Posted 2007) [#10]
Exactly how does EventData() work?
P.S My indenting was the same as your's, pretty much.


CS_TBL(Posted 2007) [#11]
EventData is just a variable (or a function returning a variable, which to you won't make any difference)

Whenever there's an event occuring, some event values are filled. These are EventSource(), EventID(), EventData(), EventX(), EventY() and prolly one or some others, but these few are the most relevant. Sofar you've been working only with ID and Source, but several gadgets also use other variables. So, there's nothing scary about it. If you press a key on the keyboard, then apart from getting a key-related EventID(), the actual key is in EventData(). When you click with your mouse on a canvas, then EventX() and EventY() contain the x and y coord in the canvas where you clicked on.

Your indenting was not exactly the same as mine. See what I wrote about the Select indenting in the functions.


Siopses(Posted 2007) [#12]
I understand what you mean but, why did you PeekInt(bank,12) rather than
PeekInt(bank,16)
I see how you used finishes menu ID, which is 2... so I'm
assuming that if you peek the parent menu, then it's children
will be peeked as well?
{EDIT}
Also, I don't see what's wrong with my indenting... and I
don't understand the relevance of whitelines, or where I
need them.


CS_TBL(Posted 2007) [#13]
why did you PeekInt(bank,12) rather than
PeekInt(bank,16)


Delete that line, and it'll work. You don't need to store a menu item into a bank if you aren't going to change it (e.g. check/uncheck it, or add more submenus). The only thing you need is that '2', which you don't need to store anywhere as it's given by the event system (in EventData()).

I can't explain more on indenting than I already did, you indent the scope of a command, not the command itself.

The relevance of whitelines is to make it more readable, more comfortable to navigate at first sight, and to make it clear which instructions belong together.