All pastes #799951 Raw Edit

Garry's Mod i64 Winamp control

public lua v1 · immutable
#799951 ·published 2007-11-28 00:01 UTC
rendered paste body
if winamp == nil then	require( "WinAmp_Interface" ) //a little glitchy - requires you have BAD HAL's winamp gui open for it to init or something.end//Media player application - uses the winamp control module.local function getMediaParam()	iPlayMode = winamp.CurrentPlayMode()	if(iPlayMode == 0) then		iPlayModeStr = "[-]"		iPlayPauseToggle = "Play"		elseif(iPlayMode == 1) then			iPlayModeStr = "[>]"			iPlayPauseToggle = "Pause"		elseif(iPlayMode == 3) then			iPlayModeStr = "[||]"			iPlayPauseToggle = "Play"	end	iSong = winamp.GetCurrentTrack()	iTrackPercent = winamp.TrackPercent()	iSongTime = winamp.GetSongPosS()	iSongLength = winamp.GetSongLenS()	iBitRate = winamp.GetBitrate() .. ' kbps'	iSampleRate = winamp.GetSamplerate() .. ' khz'	iChannels = winamp.GetChannels()	if winamp.GetRepeatMode() == true then		lblRepeatMode = "Repeat [On]"	else		lblRepeatMode = "Repeat [Off]"	end	if winamp.GetShuffleMode() == true then		lblShuffleMode = "Shuffle [On]"	else		lblShuffleMode = "Stuffle [Off]"	end	iLastVolume = winamp.GetVolume()endcolorSchemes = {	{		ampBg = Color(64,64,64,255),		ampFg = Color(255,255,255,255),		ampProgressBg = Color(32,32,32,255),		ampProgressFg = Color(180,180,180,255)	},		{		ampBg = Color(180,64,0,255),		ampFg = Color(255,180,0,255),		ampProgressBg = Color(64,32,0,255),		ampProgressFg = Color(90,64,0,255)	},	{		ampBg = Color(64,90,180,180),		ampFg = Color(64,180,180,255),		ampProgressBg = Color(32,90,180,180),		ampProgressFg = Color(32,90,255,255)	},	{		ampBg = Color(32,180,32,180),		ampFg = Color(90,255,32,255),		ampProgressBg = Color(32,90,32,180),		ampProgressFg = Color(64,180,32,255)	}}local function changeColorScheme(scheme)	if scheme != nil then		colorScheme = colorSchemes[scheme]	else		local i = random(0,count(colorSchemes))		colorScheme = colorScheme[i]	endendchangeColorScheme(3) //default skin set here.concommand.Add("i64Amp_skin",changeColorScheme)local sliderVolume = { //this is outside of the draw function to allow moving of it without draw() moving it back every frame. If a button's variables aren't changed during draw time or use variables from the draw() function you can stick them here for neatness or whatever.	x = 54,	y = 92,	w = 22,	h = 16,	font = "Trebuchet18"}local buttonStop = {	x = 2,	y = 66,	h = 24,	font = "Trebuchet24",	label = "Stop"}local buttonRepeat = {	y = 66,	h = 24,	font = "Trebuchet18",}local buttonShuffle = {	y = 66,	h = 24,	font = "Trebuchet18",}local buttonPrev = {	x = 2,	h = 24,	font = "Trebuchet24",	label = '<<'}local buttonPlayPause = {	h = 24,	font = "Trebuchet24",}local buttonNext = {	h = 24,	font = "Trebuchet24",	label = '>>'}local buttonToggleInterface = {	y = 20,	w = 28,	h = 20,	font = "Trebuchet18",}local moreInfo = 0 //If set to 1 program will automatically open in 'extended' mode. (More options)	timer.Create( "updateMediaParam", 0.5, 0, getMediaParam )//Above for getting the media parameters. Relatively simple. Shows how you can use the i64 apps in conjunction with Lua modules and shizz, I suppose. Every half a second the media info is updated.app = {} //The app table is deleted later, so store data in app.app._ = {} instead. Not using the table app.app._ in specific will cause problems.app.folder = {"Media"} //This table should have one key and one value, key of one, value of a string. This is for FUTURE subfolder support.app.app = {	caption = "i64Amp",	options = {			close = true,			minimize = true,			resize = true		},	x = ScrW()*.5 - 128 + 256 + 16,	y = ScrH()*.5 - 64,	w = 200,	h = 72,	_ = {		num = nil,		cur = nil,		op = nil,	},	draw = function(self)		if not self.visible then			return		end		local s = hack.scheme		self:DrawWindowPre()				self:DrawRoundedRect(6,6,self.w-12,34,4,colorScheme.ampBg,true)		self:DrawText(iSong,"Trebuchet18",self.w-10,2,colorScheme.ampFg,2)		local iSongW, iSongH = surface.GetTextSize( iSong )		if iSongW > self.w-16 then			iSong = string.sub(iSong, 0, string.len(iSong)-4) .. '...' //for truncating the track title if it's too long for the window.		end				buttonToggleInterface.x = self.w-34		buttonToggleInterface.label = iPlayModeStr		local btnToggleInterface = self:DrawForm(buttonToggleInterface.label,"button",buttonToggleInterface)		if btnToggleInterface == -1 then			if moreInfo == 0 then moreInfo = 1 else moreInfo = 0 end		end				self:DrawRoundedRect(8,24,self.w-50,12,4,colorScheme.ampProgressBg,true)		if self.w*(iTrackPercent/100)-38 < 12 then			iTrackProgress = 12		else			iTrackProgress = self.w*(iTrackPercent/100)-34		end		self:DrawText('|',"Trebuchet24",iTrackProgress,16,colorScheme.ampProgressFg,2)		self:DrawText(iSongTime..' / '..iSongLength,"Trebuchet18",(self.w/2)+20,21,colorScheme.ampFg,2)				if moreInfo == 1 then						local maxMin = 0			function minAdd() //all this is for a swanky resizing effect.				if minH < 136 then minH = minH+2 end				if minW < 230 then minW = minW+2 end				if buttonY < 110 then buttonY = buttonY+2 end				maxMin = maxMin+1			end			if maxMin < 64 then minAdd() end						self:DrawRoundedRect(6,50,self.w-12,10,4,colorScheme.ampBg,true)			self:DrawText(iBitRate .. '|' .. iSampleRate,"Trebuchet18",8,46,colorScheme.ampFg,0)			self:DrawText(iChannels,"Trebuchet18",self.w-10,46,colorScheme.ampFg,2)						buttonStop.w = (self.w/3)-2			local btnStop = self:DrawForm(buttonStop.label,"button",buttonStop)						buttonRepeat.label = lblRepeatMode			buttonRepeat.x = (self.w/3)+2			buttonRepeat.w = (self.w/3)-2			local btnRepeat = self:DrawForm(buttonRepeat.label,"button",buttonRepeat)						buttonShuffle.label = lblShuffleMode			buttonShuffle.x = ((self.w/3)*2)+2			buttonShuffle.w = (self.w/3)-4			local btnShuffle = self:DrawForm(buttonShuffle.label,"button",buttonShuffle) //name your buttons like this so you can call them later on in an if conditional.						local sldrVolume = self:DrawForm(sliderVolume.label,"button",sliderVolume)			sliderVolume.x = self.w*(iLastVolume/100)-24 //this is probably wrong. I never listen in maths D:			sliderVolume.label = iLastVolume						self:DrawText("Volume","Trebuchet18",4,92,Color(255,255,255,255),0)						if btnStop == -1 then winamp.Stop() end //aforementioned conditional- when the button is clicked and not held, a button returns -1. 2 is for when you want the user to hold the button.			if btnRepeat == -1 then				if lblRepeatMode == "Repeat [Off]" then winamp.SetRepeatMode(true)				else winamp.SetRepeatMode(false) end			end			if btnShuffle == -1 then				if lblShuffleMode == "Shuffle [Off]" then winamp.SetShuffleMode(true) //something wrong in one of these lines of code? Shuffle will turn OFF but not ON. Odd.				else winamp.SetShuffleMode(false) end			end						if sliderVolume.x > self.w-24 then					sliderVolume.x = self.w-24			elseif sldrVolume == 2 then sliderVolume.x = self.mx-12 //my head hurts.			end			if sliderVolume.x < 54 then					sliderVolume.x = 54				elseif sldrVolume == 2 then sliderVolume.x = self.mx-12			end			if sldrVolume == -1 then				winamp.SetVolume( self.w*(sliderVolume.x/100)-12 ) //GAAH			end					else			minH = 72			minW = 164			buttonY = 46		end				if self.h != minH then //stop user from shrinking window too small.			self.h = minH		end				if self.w < minW then //ditto.			self.w = minW		end				buttonPrev.w = (self.w/3)-2		buttonPrev.y = buttonY		local btnPrev = self:DrawForm(buttonPrev.label,"button",buttonPrev)		if btnPrev == -1 then winamp.Previous() end				buttonPlayPause.label = iPlayPauseToggle		buttonPlayPause.x = (self.w/3)+2		buttonPlayPause.y = buttonY		buttonPlayPause.w = (self.w/3)-2		local btnPlayPause = self:DrawForm(buttonPlayPause.label,"button",buttonPlayPause)		if btnPlayPause == -1 then			if iPlayMode == 1 then winamp.Pause() else winamp.Play() end		end				buttonNext.x = ((self.w/3)*2)+2		buttonNext.y = buttonY		buttonNext.w = (self.w/3)-4		local btnNext = self:DrawForm(buttonNext.label,"button",buttonNext)		if btnNext == -1 then winamp.Next() end				self:DrawWindowPost()	end}