Drag and drop music?

BlitzMax Forums/BlitzMax Beginners Area/Drag and drop music?

Hi bookworm,

The reason why your code wasn't displaying properly on Windows was because your labels were drawn so big that they were drawn over your other gadgets. On Mac OS X, as labels are transparent, it didn't really matter, but labels on Windows are drawn opaque and as such hid your other gadgets.

From the looks of your gadget-code, it looks like you are having a hard time working out how to position your gadgets on the screen. Can I suggest you use a GUI Editor (such as LogicGUI [see Jsp's sig] or GUIde) which allows you to draw your control how you want and allows you to export the equivalent code?

If you are set on doing it yourself, then I suggest you make use of the WINDOW_CLIENTCOORDS flag when creating windows to ensure your window looks the same on all platforms...

I've quickly re-designed your interface if you are really stuck or are looking for some pointers:

'set appearance
Global Style:Int = WINDOW_TITLEBAR|WINDOW_STATUS|WINDOW_CLIENTCOORDS|WINDOW_ACCEPTFILES
Global version:String = "0.9.1" 

'music variables 
Global music:TSound 
Global channel:TChannel 
Global paused:Int = 0
channel = AllocChannel()  

Global mainWindow:TGadget = CreateWindow( "Bookworm's OGG Player - " + version, 200, 200, 549, 120, Null, Style )
	
	Global panelMusicFile:TGadget = CreatePanel( 10, 10, 430, 60, mainWindow, PANEL_GROUP, "Enter music file here: " )
		Global musicDropBox:TGadget = CreateTextField( 7, 4, 410, 24, panelMusicFile, 0 )
	
	'A few other controls you might want to use
	Global progressSong:TGadget = CreateProgBar( 10, 95, 430, 15, mainWindow, 0 )
	Global sliderSong:TGadget = CreateSlider( 10, 70, 430, 20, mainWindow, SLIDER_TRACKBAR|SLIDER_HORIZONTAL )
	
	'Buttons
	Global musicPlay:TGadget = CreateButton( "Play", 450, 10, 90, 30, mainWindow, BUTTON_PUSH )
	Global musicPause:TGadget = CreateButton( "Pause", 450, 44, 90, 30, mainWindow, BUTTON_PUSH )
	Global musicStop:TGadget = CreateButton( "Stop", 450, 78, 90, 30, mainWindow, BUTTON_PUSH )
	
'main loop
Repeat 
	WaitEvent()
	
	Select EventID()
		'so you want to end it all?
		Case EVENT_WINDOWCLOSE
			End
			
		Case EVENT_GADGETACTION 
			Select EventSource()
				Case musicDropBox 
					SetGadgetText musicFile,"Attempting to load..."
					SetGadgetText musicInfo,"Current File: "+TextFieldText(musicDropBox)
				'Case pReset
				'	SetGadgetText musicFile,"No music playing..."
				'	SetGadgetText musicDropBox,"" 
				'	SetGadgetText musicInfo,"Current File: "
				'	stopCurrent() 
				Case musicPlay 
					playCurrent() 
				Case musicPause
				 	pauseCurrent()
				Case musicStop 
					stopCurrent()	
			End Select 
		
		Case EVENT_WINDOWACCEPT
		
			SetGadgetText musicDropBox, EventText()
		
	End Select 
	
Forever 

Function playCurrent() 
	music = LoadSound(TextFieldText(musicDropBox))
	If music = Null
		SetGadgetText musicFile,"Error: File Not Found!" 
	Else 
		PlaySound music,channel 
		SetGadgetText musicFile,"Music Playing!" 
	EndIf 
EndFunction 

Function stopCurrent()
	StopChannel channel
	SetGadgetText musicFile,"Music Stopped"
	channel = AllocChannel()  
	If music = Null
		SetGadgetText musicFile,"Error: File Not Found!" 
	EndIf 
EndFunction 

Function pauseCurrent()
	If paused = 0  
		PauseChannel channel
		SetGadgetText musicPause,"Resume" 
		SetGadgetText musicFile,"Music Paused" 
		If music = Null
			SetGadgetText musicFile,"Error: File Not Found!" 
		EndIf 
		paused =1 
	ElseIf paused = 1 
		ResumeChannel channel  
		SetGadgetText musicPause,"Pause" 
		SetGadgetText musicFile,"Music Playing!" 
		If music = Null
			SetGadgetText musicFile,"Error: File Not Found!" 
		EndIf 
		paused =0 
		EndIf 
EndFunction


P.S. Oh, and I've also added some drag n' drop handling code as to me drag n' drop is more intuitive than typing in the file-path yourself... Still, each to their own I suppose.