New Dialog!

BlitzMax Forums/BlitzMax GUI Programming/New Dialog!

I have created a username and password dialog for MaxGUI. Let me know what you think. I am currently working on more. (Let me know of any you would like. I'd be happy to put something together!)

Seb/Mark Tiffany: Could this be a possible addition to the ProxyGadgets module?

Strict
Import maxgui.maxgui
'Import maxgui.win32maxguiex

'CREATED BY KEDRIC SIDDONS'
'COPYRIGHT 2008 KEDRIC SIDDONS'

Type TUserPassDialog
	Global _window:TGadget
	Global _usernamelab:TGadget
	Global _passwordlab:TGadget
	Global _usernamefield:TGadget
	Global _passwordfield:TGadget
	Global _okbutton:TGadget
	
	Global _username:String
	Global _password:String
	
	Function Create:String[](parent:TGadget,username:String="",password:String="")
		If parent=Null
			RuntimeError "TUserPassDialog: Need parent gadget!"
			End
		EndIf
		If GadgetClass(parent)<>GADGET_WINDOW
			RuntimeError "TUserPassDialog: Parent gadget must be a window!"
			End
		EndIf
		
		DisableGadget parent
		_window=CreateWindow(AppTitle,0,0,300,120,parent,WINDOW_TITLEBAR|WINDOW_CLIENTCOORDS|WINDOW_CENTER)
		_usernamelab=CreateLabel("Username:",10,14,80,20,_window)
		_usernamefield=CreateTextField(90,10,ClientWidth(_window)-(90+10),20,_window)
		_passwordlab=CreateLabel("Password:",10,44,80,20,_window)
		_passwordfield=CreateTextField(90,40,ClientWidth(_window)-(90+10),20,_window,TEXTFIELD_PASSWORD)
		_okbutton=CreateButton("Submit",ClientWidth(_window)-(70+10),ClientHeight(_window)-(24+10),70,24,_window)
		
		ActivateGadget _usernamefield
		
		SetGadgetText _usernamefield,username
		SetGadgetText _passwordfield,password
		
		Repeat
			WaitEvent()
			Select EventID()
				Case EVENT_WINDOWCLOSE
					Select EventSource()
						Case _window
							EnableGadget parent
							FreeGadget _window
							Return ["",""]
							Exit
					EndSelect
				
				Case EVENT_GADGETACTION
					Select EventSource()
						Case _okbutton
							_username=TextFieldText(_usernamefield)
							_password=TextFieldText(_passwordfield)
							
							If Len(_username)=0
								Notify "Username required!",True
							Else
								If Len(_password)=0
									Notify "Password required!",True
								Else
									EnableGadget parent
									FreeGadget _window
									Return [_username,_password]
									Exit
								EndIf
							EndIf
					EndSelect
			EndSelect
		Forever
	EndFunction
EndType

Rem
bbdoc: Creates a username and password dialog.
returns: A string array. Index 0 is username, index 1 is password
EndRem
Function RequestUsernamePassword:String[](parent:TGadget,username:String="",password:String="")
	Return TUserPassDialog.Create(parent,username,password)
EndFunction

Rem
'EXAMPLE'
Global window:tgadget=CreateWindow("Dialog Test",50,50,640,480,Desktop(),1+2)
Global button:tgadget=CreateButton("Dialog",10,10,80,24,window)

Repeat
	WaitEvent()
	Select EventID()
		Case event_windowclose
			Select EventSource()
				Case window
					End
			EndSelect
		
		Case event_gadgetaction
			Select EventSource()
				Case button
					Local info:String[]=RequestUsernamePassword(window)
					Local username:String=info[0]
					Local password:String=info[1]
					
					If username="" And password=""
						Notify "Dialog closed.",True
					Else
						Notify "USERNAME: "+username+"~nPASSWORD: "+password,False
					EndIf
			EndSelect
	EndSelect
Forever
EndRem


Here is a reminder dialog.

Strict
Import maxgui.maxgui
'Import maxgui.drivers

'CREATED BY KEDRIC SIDDONS'
'COPYRIGHT 2008 KEDRIC SIDDONS'

Type TReminderDialog
	Global _window:TGadget
	Global _imgpanel:TGadget
	Global _infolabel:TGadget
	Global _okbutton:TGadget
	
	Function Create(parent:TGadget,remindertxt:String,image:TPixmap=Null)
		If GadgetClass(parent)<>GADGET_WINDOW
			RuntimeError "TReminderDialog: Parent needs to be a window!"
			End
		EndIf
		
		DisableGadget parent
		_window=CreateWindow("Reminder",0,0,300,150,parent,WINDOW_TITLEBAR|WINDOW_CENTER|WINDOW_CLIENTCOORDS)
		_imgpanel=CreatePanel(10,10,64,64,_window)
		If image<>Null
			SetPanelPixmap _imgpanel,image,PANELPIXMAP_FIT
		EndIf
		_infolabel=CreateLabel(remindertxt,84,10,ClientWidth(_window)-(84+10),ClientHeight(_window)-(24+10+10),_window)
		_okbutton=CreateButton("OK",ClientWidth(_window)-(70+10),ClientHeight(_window)-(24+10),70,24,_window)
		
		Repeat
			WaitEvent()
			Select EventID()
				Case EVENT_WINDOWCLOSE
					Select EventSource()
						Case _window
							EnableGadget parent
							FreeGadget _window
							Exit
					EndSelect
					
				Case EVENT_GADGETACTION
					Select EventSource()
						Case _okbutton
							EnableGadget parent
							FreeGadget _window
							Exit
					EndSelect
			EndSelect
		Forever
	EndFunction
EndType

Rem
bbdoc: Creates a reminder dialog.
EndRem
Function Reminder(parent:TGadget,remindertxt:String,image:TPixmap=Null)
	TReminderDialog.Create(parent,remindertxt,image)
EndFunction

Rem
'EXAMPLE'
Local window:TGadget=CreateWindow("Dialog",50,50,640,480,Desktop(),1+2)
Local button:TGadget=CreateButton("Dialog",10,10,80,24,window)
Local image:TPixmap=LoadPixmap("F:\Blitzmax.png")

Repeat
	WaitEvent()
	Select EventID()
		Case event_windowclose
			Select EventSource()
				Case window
					End
			EndSelect
		
		Case event_gadgetaction
			Select EventSource()
				Case button
					Reminder(window,"Hey!~nThis is to remind you that this "+..
					"magnificent piece of work is fantastic and that you should "+..
					"always use it.~n~nThank you for your time.",image)
			EndSelect
	EndSelect
Forever
EndRem


Hey Kev,

Nice work ;-)

If you are serious about wanting them to be added to MaxGUI.ProxyGadgets, we first need to make sure that they behave as expected on all platforms. We also need to establish some sort of convention of ProxyGadget requesters, but I'm sure it will pay off as many people will find these things really useful to have quick access to.

I was thinking along the lines of TRequester from maxide.bmx. This is the base type from which all of MaxIDE's Find/Find & Replace/IDE Options/Command Line/Goto windows extend. As you can see it has an InitRequester() method that initializes the window in a standardized way, according to the style parameters specified in flags. This allows the control to be much more flexible - the user can quickly specify which button(s) they want on the requester, the text of the OK button, as well as things like whether we have a divider line, and whether it appears as a tool window.

Have you any thoughts?

Hey Kev,

Ked. :)

Nice work ;-)

Thanks.

If you are serious about wanting them to be added to MaxGUI.ProxyGadgets, we first need to make sure that they behave as expected on all platforms.

Agreed.

We also need to establish some sort of convention of ProxyGadget requesters, but I'm sure it will pay off as many people will find these things really useful to have quick access to.

I also agree.

I was thinking along the lines of TRequester from maxide.bmx. This is the base type from which all of MaxIDE's Find/Find & Replace/IDE Options/Command Line/Goto windows extend. As you can see it has an InitRequester() method that initializes the window in a standardized way, according to the style parameters specified in flags. This allows the control to be much more flexible - the user can quickly specify which button(s) they want on the requester, the text of the OK button, as well as things like whether we have a divider line, and whether it appears as a tool window.

Have you any thoughts?

I will definitely have a good look at the TRequester from the MaxIDE.

Oooo... I don't know. I really don't know how to do OOP like that.

EDIT: But I'll try anyway! :P

I was looking at the TRequester from MaxIDE and it's not what I'm trying to make. I'm trying to do stuff like Notify, Confirm, Proceed, RequestColor, RequestDir, and RequestFile.

Ked, great work.
I just changed your Reminder to manage better the text height (on MacOS the last line in your original example is cut off).


Strict
'Import maxgui.maxgui
Import maxgui.drivers

'CREATED BY KEDRIC SIDDONS'
'COPYRIGHT 2008 KEDRIC SIDDONS'

Type TReminderDialog
	Global _window:TGadget
	Global _imgpanel:TGadget
	Global _infolabel:TGadget
	Global _okbutton:TGadget
	
	Function Create(parent:TGadget,remindertxt:String,image:TPixmap=Null)
		If GadgetClass(parent)<>GADGET_WINDOW
			RuntimeError "TReminderDialog: Parent needs to be a window!"
			End
		EndIf
		
		
		Local hpa:Int=150
		Local ac$
		
		For Local c:Int=0 Until Len(remindertxt)
			ac=remindertxt[c]
	
			If ac=10 Or ac=13 hpa:+10			
		Next
		
		
		DisableGadget parent
		_window=CreateWindow("Reminder",0,0,300,hpa,parent,WINDOW_TITLEBAR|WINDOW_CENTER|WINDOW_CLIENTCOORDS)
		_imgpanel=CreatePanel(10,10,64,64,_window)
		If image<>Null
			SetPanelPixmap _imgpanel,image,PANELPIXMAP_FIT
		EndIf
		_infolabel=CreateLabel(remindertxt,84,10,ClientWidth(_window)-(84+10),ClientHeight(_window)-(24+10+10),_window)
		_okbutton=CreateButton("OK",ClientWidth(_window)-(70+10),ClientHeight(_window)-(24+10),70,24,_window)
		
		Repeat
			WaitEvent()
			Select EventID()
				Case EVENT_WINDOWCLOSE
					Select EventSource()
						Case _window
							EnableGadget parent
							FreeGadget _window
							Exit
					EndSelect
					
				Case EVENT_GADGETACTION
					Select EventSource()
						Case _okbutton
							EnableGadget parent
							FreeGadget _window
							Exit
					EndSelect
			EndSelect
		Forever
	EndFunction
EndType

Rem
bbdoc: Creates a reminder dialog.
EndRem
Function Reminder(parent:TGadget,remindertxt:String,image:TPixmap=Null)
	TReminderDialog.Create(parent,remindertxt,image)
EndFunction

'EXAMPLE'
Local window:TGadget=CreateWindow("Dialog",50,50,640,480,Desktop(),1+2)
Local button:TGadget=CreateButton("Dialog",10,10,80,24,window)
Local image:TPixmap=LoadPixmap("F:\Blitzmax.png")

Repeat
	WaitEvent()
	Select EventID()
		Case event_windowclose
			Select EventSource()
				Case window
					End
			EndSelect
		
		Case event_gadgetaction
			Select EventSource()
				Case button
					Reminder(window,"Hey!~nThis is to remind you that this "+..
					"magnificent piece of work is fantastic and that you should "+..
					"always use it.~n~nThank you for your time.",image)
			EndSelect
	EndSelect
Forever


OK, cool. Thanks, degac.