update Gui Module

update Gui Module

Added Style Feature to Button

#Rem monkeydoc Module maniac.maniacSimpleGUI
	Simple GUI - Version 0.1.5 (alpha)  ~n
	Copyright (C) 2015  Stephan Duckerschein~n

	Here You can find some GUI Elements to use for your App.
	They can be used 'ad-hoc'-like. the have to be managed by the Programmer.

#End

#rem
	Work On:
		DropDown,RadioGroup,FileExplorer,ListView for Version 0.1.6

		- need Color Scheme
		- need Graphics Update

		- Buglist:
			ManiacButton -> Rolling Animation is not Ready yet
	VERSION:~n
	0.1.5	- updated Textfield Class
				- now shows the Cursor, X-Alignment is available, set the Alpha, Wrap Textfield to Height of Text (Single Line Only at the Moment!!!!!)
				- Bugfixed some Update and Drawing Stuff.
				- changed Framethickness to 1 pxl ... now it looks much better
	0.1.4	- added: ManiacCheckBox,DropDown,ListView, Dialog
	0.1.3	- added a ImageGallery-Class >> ToDo: some imageLoading Bugfixes. UpdateEventAsync testing around ...

	0.1.2:	- bugfixes Frame
			- added some setter
			- added "doWobble","doRoll" (instantEffects)
			- added "startAnimDrop","startAnimSlide" and "startAnimCircle"
			- updated ManiacButton Class
			- added a Slider Class

	Wishlist:
		 x Simple Button
		 x Textfield
		 x Slider
		 x Checkbox
		 x GalleryViewer
		 x DropDown
		RadioBox
		Docker
		Tabs

	Implemented Feature: GUI
		- Button
		- Textfield
		- Slider
		- GalleryViewer
#end

Import maniacDebug

public
Const TEXTFIELD_STYLE_STD:Int 			= 0
Const TEXTFIELD_STYLE_WITHBUTTON:Int 	= 1

#Rem monkeydoc
	This Class is a Textfield Gui Element.
	Version 1.1

	Example:

		Global tf:ManiacSimpleTextfield = new ManiacSimpleTextfield(100,100,300,32)
		Function Main:Int()
			New Example
			Return 0
		End Function

#End
Class ManiacTextfield
	Private
	Field maniacID:Int
	Field ID:Int
	Field inputString:String = ""
	Field Caption:String = ""
	Field X:Int,Y:Int
	Field W:Int,H:int

	Field Style:Int

	Field bShowButton:Bool 	= False
	Field bShowCaption:Bool
	Field bWrapHeight:Bool = False
	Field bEditing:Bool = False
	Field bEndOnEnter:Bool = True

	Field Angle:Float = 0.0
	Field Alpha:Float 	= 1.0'Main Alpha Value.
	Field Focus:Int		'0 - Standard ohne gfx effects , 1 -

	Field ColorBackground:Int = 8'COLOR_WHITE
	Field AlphaCursor:Float
	Field TimeLastCursorChange:Int
	Field TimeCursorChange:Int = 510
	Field PosCursor:Float

	Field AlignmentCaption:Int

	Public
	Method New(_X:Float,_Y:Float,_Width:Float,_Height:Float,_Caption:String = "",_Style:Int = TEXTFIELD_STYLE_STD)
		If MANIAC_DEBUG = True
			Maniac_Debug.addStoredBools()
			Maniac_Debug.addStoredInts(8)
			maniacID = Maniac_Debug.getNumberOfRegisteredObjects()
			Maniac_Debug.addRegisteredObject()
		Endif

		X 		= _X
		Y 		= _Y
		W 		= _Width
		H 		= _Height
		Style 	= _Style
		Caption = _Caption
		Alpha = 1.0
		AlignmentCaption = ALIGNMENT_MIDDLE
	End Method

	Public
	Method Update:Int()
		If MANIAC_DEBUG = True
			Maniac_Debug.addTotCall()
		Endif

		'### Check for Wrapping ###
		If bWrapHeight = True
			H = 30
		Endif

		'### Check for Click
		If bShowButton = True
			If TouchHit()
				If MOBox(X,Y,(W*0.15),(H*1.0))
					If bEditing = True
						bEditing = False
						Return 99
					Else
						bEditing = True
						#If TARGET="android"
							EnableKeyboard()
						#Endif
					Endif
				Endif
			Endif

		Else
			If TouchHit()
				If MOBox(X,Y,(W),(H))
					If bEditing = True
						bEditing = False
					Else
						bEditing = True
						#If TARGET="android"
							EnableKeyboard()
						#Endif

					Endif
				Endif
			Endif
		Endif

		If bEditing = True
			'### Updating the Cursor Alpha
			If (Millisecs() - TimeLastCursorChange ) > TimeCursorChange
				TimeLastCursorChange = Millisecs()
				If AlphaCursor > 0.8
					AlphaCursor = 0.05
				Else
					AlphaCursor = 1.0
				Endif

			Endif
			'### Updating the KeyboardInput
			Repeat
				Local char=GetChar()
		        If Not char Exit

		        If char>=32
		            inputString+=String.FromChar( char )
		        Endif

		        If char = CHAR_ENTER
		        	#If TARGET="android"
						DisableKeyboard()
					#Endif
					If bEndOnEnter = True
						bEditing = False
					Endif
					Return 99
				Endif

		        If char = CHAR_BACKSPACE
					Local txtlength:Int = inputString.Length()
					Local txtchars:Int[] = inputString.ToChars
					inputString = ""
					For Local l:Int = 0 To txtlength-2
						inputString += String.FromChar(txtchars[l])
					Next
				Endif

			Forever
		Endif
	End Method

	Public
	Method Draw()
		If MANIAC_DEBUG = True
			Maniac_Debug.addTotCall()
			Maniac_Debug.addTotDraws(3)
		Endif

		'### Rotate The Matrix at the MidX/MidY Position around Angle
		If Angle <> 0.0
			RotateAt(X+W/2,Y+H/2, Angle)
		Endif

		'### Drawing Background ###
		SetAlpha Alpha
		Maniac_Color(ColorBackground)
		'SetColor 255,255,255
		DrawRect(X,Y,W,H)

		'### Drawing an Explaining Text to the Textfield ...
		'ToDo: - Alignment (Top,Bottom), Color
		SetColor 0,0,0
		MANIAC_FONT.Wrap(Caption,X,Y-(ManiacFont.getH()+5),W,H,Caption.Length())

		'### Drawing an "Fertig"-Button ... if pressed, its same like "I'm Done with text, it will disable the Keyboard (for Android)
		If bShowButton = True
			DrawImage MANIAC_IMG_EDITICON,X,Y,0,(W*0.15)/MANIAC_IMG_EDITICON.Width(),(H*1.0)/MANIAC_IMG_EDITICON.Height()
		Endif

		'### Drawing the Input Text String ###
		SetColor 0,0,0
		Local cursorPos:Float
		If bShowButton = True

			MANIAC_FONT.Wrap(inputString,X+W*0.15,Y+H/2-ManiacFont.getH()/2,W,H,inputString.Length())
		Else
			'MANIAC_FONT.Wrap(inputString,X,Y+H/2-ManiacFont.getH()/2,W,H,inputString.Length())
			cursorPos = Drw_ManiacText(inputString,X,Y,W,H,AlignmentCaption)
		Endif

		'### Drawing the Cursor ###
		If bEditing = True
			Local iw:Int = MANIAC_FONT.getW(inputString)
			SetAlpha AlphaCursor
			MANIAC_FONT.Wrap("|",cursorPos,Y+H/2-ManiacFont.getH()/2,W,H,2)
		Endif

		'### Draw the Frame around the Textfield
		SetAlpha Alpha
		If bEditing = True
			SetColor 0,255,0
		Else
			SetColor 75,75,75
		Endif
		Drw_Rect(X,Y,W,H,1)

		'### Reset The MAtrix
		If Angle <> 0.0
			ResetMatrix()
		Endif
	End Method

	#rem
		This Method is deprecatded.
		It will be deleted in ver 1.1
	#end
	Method drawFull()
		SetAlpha 1
		SetColor 255,255,255
		DrawRect(X+W*0.15,Y,W,H)

		If bEditing = True
			SetColor 0,255,0
		Else
			SetColor 255,0,0
		Endif

		DrawImage DUKE_IMG_EDITICON,X,Y,0,(W*0.15)/DUKE_IMG_EDITICON.Width(),(H*1.0)/DUKE_IMG_EDITICON.Height()

		SetColor 0,0,0
		DUKE_FONT.Wrap(inputString,X+W*0.15,Y,W,H,Duke_MessageCount)

		If bEditing = True
			SetColor 0,255,0
		Else
			SetColor 255,0,0
		Endif
		Duke_Drw_Rect(X,Y,W,H,3)
	End Method

	Method getText:String()
		Return inputString
	End Method

	Method setText(itext:String)
		inputString = itext
	End Method

	Method setAlpha(_Value:Float)
		Alpha = _Value
	End Method

	Method setWrapHeight(_Bool:Bool = True)
		bWrapHeight = _Bool
	End Method

	Method setBackgroundColor:Void(_Color:Int)
		ColorBackground = _Color
	End Method

	Method setCaption(_Text:String)
		Caption = _Text
	End Method
End Class

Const ALIGNMENT_LEFT:Int = 1
Const ALIGNMENT_MIDDLE:Int = 2
Const ALIGNMENT_RIGHT:Int = 3
Const ALIGNMENT_TOP:Int = 4
Const ALIGNMENT_MIDDLEY:int = 5
Const ALIGNMENT_BOTTOM:Int = 6

Const ANIM_DROP:Int 	= 1
Const ANIM_FADE:Int		= 2
Const ANIM_ROTATE:Int 	= 3
Const ANIM_ROLL:Int		= 4
Const ANIM_SLIDE:Int 	= 5
Const ANIM_CIRCLE:Int	= 6
Const ANIM_POPOUT:Int 	= 7

Const BUTTON_STYLE_RECTSTD:Int = 0
Const BUTTON_STYLE_RECT2:Int 	= 1
Const BUTTON_STYLE_ROUND1:Int 	= 2
Const BUTTON_STYLE_ROUND2:Int 	= 3
Const BUTTON_STYLE_ROUND3:Int 	= 3

#Rem monkeydoc
	This Class is a Button Gui Element.
	Version 0.2~n
		- added ButtonStyle

	Example:

		Global tB:ManiacButton = new ManiacButton(100,100,300,32)

		Function Main:Int()
			New Example
			Return 0
		End Function

#end
Class ManiacButton

	'Identificanitional Values
	Private
	Field ID:Int
	Field maniacID:Int
	Field MidX:Float,MidY:Float			'aktuelle Position des Buttons (Durch Animationen veränderbar
	Field oX:Float,oY:Float 		'Original X,Y << Das ist die Feste Position des Buttons
	Field Width:Float,Height:Float			'Breite und Höhe in Pxl

	'
	Field Caption:String		'Aufschrift
	Field CaptionColor:Int		'Color of the Caption
	Field Angle:Float 			'Winkel zur Horizontalen in °
	Field Alignment:Int			'ausrichtung des Textes (Left,Middle,Right)
	Field bTransparent:Bool = false
	Field bVisible:Bool 	= True

	'#### EFFECTS STUFF ####
	'Field

	'#### GLOW STUFF #####		Ready
	Field bGlow:Bool							'Wenn true, dann leuchtet der Button
	Field GlowHertz:Float 			= 0.5
	Field GlowAlpha:Float 						'Current Alpha for Glow Effect
	Field GlowAlphaFrom:Float		= 0.01		'Range for Alpha-Effekt.
	Field GlowAlphaTo:Float			= 0.3
	Field GlowStyle:Int				= 0			'0 - If Alpha reases max, it decreases from max ; 1 - if Alpha reaches max, it jumps to min
	Field bCurrGlowDirection:Bool 				'True - Raise, false - decrease
	Field GlowColor:Int
	Field GlowRangeRatioX:Float = 1.3
	Field GlowRangeRatioY:Float = 1.7

	'#### FRAME STUFF ######
	Field bFramed:Bool 		= True
	Field FrameColor:Int
	Field FrameType:Int 	= 0
	Field FrameThickness:Int = 1

	Field ButtonStyle:Int = 0
	Field Color:Int 							'Integerwert einer Farbe aus der Maniac_Color Funktion

	'#### BUTTON MOUSEOVER STUFF #####
	Field bMO:Bool = False
	Field bMOResize:Bool 		= false
	Field bMOBrighter:Bool 		= false
	Field bMOWobble:Bool		= false
	Field AddWidthByMO:Int 		= 0
	Field AddHeightByMO:Int		= 0

	'##### BUTTON INACTIVE-ANIMATIONS #######
	Field bInactiveAnim:Bool = False
	Field bInactiveTime:Int
	Field InactiveAnim:Int
	Field LastActiveTime:Int

	'##### WOBBLEEFFEKT STUFF #####
	Field lastWobble:Int

	'##### ANIMATION STUFF #####
	Field bRunningAnimation:Bool 	= False
	Field AnimStartTime:int
	Field AnimTime:int

	'Tweener for position Stuff
	Field tweenY:Tween
	Field tweenX:Tween
	Field tweenAngle:Tween

	'Booleans for Effect
	Field AnimEffect:Int

	Public
	Method New(_MidX:Float,_MidY:Float,_Width:Float,_Height:Float,_Caption:String = "",_Alignment:Int = ALIGNMENT_MIDDLE,_Color:Int = COLOR_BLUE,_Glow:Bool = True,_GlowHertz:Float = 1,_Angle:Float = 0.0)
		If MANIAC_DEBUG = True
			Maniac_Debug.addStoredBools(9)
			Maniac_Debug.addStoredInts(12)
			Maniac_Debug.addStoredFloats(13)
			ID 		= Maniac_Debug.getNumberOfRegisteredObjects()
			Maniac_Debug.addRegisteredObject()
		Endif
		oX 		= _MidX
		oY		= _MidY
		MidX 	= _MidX
		MidY 	= _MidY
		Width 	= _Width
		Height 	= _Height
		Alignment =_Alignment
		Caption =	_Caption
		CaptionColor = _Color +6
		Color		= _Color
		bGlow 		= _Glow
		GlowHertz	= _GlowHertz
		GlowColor = _Color
		Angle = _Angle
		FrameColor = _Color +6
	End Method

	Method Draw:int()
		If MANIAC_DEBUG = True
			Maniac_Debug.addRenderedObject()
		Endif

		If bVisible = False
			Return -1
		Endif
		If Angle <> 0.0
			RotateAt(MidX,MidY, Angle)
		Endif

		'##### GLOW EFFECT STUFF #####
		If bGlow = True
			Maniac_Color(GlowColor)
			SetAlpha GlowAlpha
			DrawImage MANIAC_IMG_FRAME_BLUR, MidX,MidY,0,Width*GlowRangeRatioX/MANIAC_IMG_FRAME_BLUR.Width(),Height*GlowRangeRatioY/MANIAC_IMG_FRAME_BLUR.Height()
			Maniac_Debug.addTotDraws(1)
		End If

		'##### BUTTON BACKGROUND #####
		Maniac_Color(Color)
		If bTransparent = True
			If bMO = True
				SetAlpha 1
				If bMOResize = True
					AddWidthByMO = 10
					AddHeightByMO = 10
				Else
					AddWidthByMO = 0
					AddHeightByMO = 0
				Endif
			Else
				AddWidthByMO = 0
				AddHeightByMO = 0
				SetAlpha 0.6
			Endif
		Else
			SetAlpha 1
			If bMO = True
				If bMOResize = True
					AddWidthByMO = 10
					AddHeightByMO = 10
				Else
					AddWidthByMO = 0
					AddHeightByMO = 0
				Endif
			Else
				AddWidthByMO = 0
				AddHeightByMO = 0
			Endif
		Endif
		'
		'Check for Button Style
		Select ButtonStyle
			Case BUTTON_STYLE_RECTSTD
				DrawRect(MidX- (Width +AddWidthByMO/2)/2,MidY-(Height+AddHeightByMO/2)/2,Width+AddWidthByMO,Height+AddHeightByMO)
			Case BUTTON_STYLE_RECT2
				'DrawImage MANIAC_IMG_BG_SMOOTHRECT, MidX,MidY,0,(Width+AddWidthByMO)/MANIAC_IMG_BG_SMOOTHRECT.Width(),(Height+AddHeightByMO)/MANIAC_IMG_BG_SMOOTHRECT.Height()
			Case BUTTON_STYLE_ROUND1
				DrawImage MANIAC_IMG_BG_ROUND1, MidX,MidY,0,(Width+AddWidthByMO)/MANIAC_IMG_BG_SMOOTHRECT.Width(),(Height+AddHeightByMO)/MANIAC_IMG_BG_SMOOTHRECT.Height()
			Case BUTTON_STYLE_ROUND2
				DrawImage MANIAC_IMG_BG_ROUND2, MidX,MidY,0,(Width+AddWidthByMO)/MANIAC_IMG_BG_SMOOTHRECT.Width(),(Height+AddHeightByMO)/MANIAC_IMG_BG_SMOOTHRECT.Height()
			Case BUTTON_STYLE_ROUND3
				DrawImage MANIAC_IMG_BG_ROUND3, MidX,MidY,0,(Width+AddWidthByMO)/MANIAC_IMG_BG_SMOOTHRECT.Width(),(Height+AddHeightByMO)/MANIAC_IMG_BG_SMOOTHRECT.Height()
		End Select
		'Maniac_Debug.addTotDraws(1)

		'###### BUTTON FRAME ########
		If bFramed = True
			Select ButtonStyle
				Case BUTTON_STYLE_RECTSTD
					Maniac_Color(FrameColor)
					Drw_Rect(MidX- (Width +AddWidthByMO/2)/2,MidY-(Height+AddHeightByMO/2)/2,Width+AddWidthByMO,Height+AddHeightByMO,3)
				Case BUTTON_STYLE_RECT2
					Maniac_Color(FrameColor)
					DrawImage MANIAC_IMG_FRAME_RECT2 , MidX,MidY,0,(Width+AddWidthByMO)/MANIAC_IMG_FRAME_RAW.Width(),(Height+AddHeightByMO)/MANIAC_IMG_FRAME_RAW.Height()
				Case BUTTON_STYLE_ROUND1
					Maniac_Color(FrameColor)
					DrawImage MANIAC_IMG_FRAME_ROUND1 , MidX,MidY,0,(Width+AddWidthByMO)/MANIAC_IMG_FRAME_RAW.Width(),(Height+AddHeightByMO)/MANIAC_IMG_FRAME_RAW.Height()
				Case BUTTON_STYLE_ROUND2
					Maniac_Color(FrameColor)
					DrawImage MANIAC_IMG_FRAME_ROUND2 , MidX,MidY,0,(Width+AddWidthByMO)/MANIAC_IMG_FRAME_RAW.Width(),(Height+AddHeightByMO)/MANIAC_IMG_FRAME_RAW.Height()
				Case BUTTON_STYLE_ROUND3
					Maniac_Color(FrameColor)
					DrawImage MANIAC_IMG_FRAME_ROUND3 , MidX,MidY,0,(Width+AddWidthByMO)/MANIAC_IMG_FRAME_RAW.Width(),(Height+AddHeightByMO)/MANIAC_IMG_FRAME_RAW.Height()

			End Select

		Else

		Endif

		'##### DRAWING THE CAPTION TO THE BUTTON #####
		SetAlpha 1
		Maniac_Color(CaptionColor)
		Select Alignment
			Case ALIGNMENT_LEFT
				MANIAC_FONT.Wrap(Caption,MidX-Width/2,MidY-Height/5,Width,Height,Caption.Length())
				ResetMatrix()
			Case ALIGNMENT_MIDDLE
				Local l:Int = MANIAC_FONT.getW(Caption)
				MANIAC_FONT.Wrap(Caption,MidX-l/2+1,MidY-Height/5,Width,Height,Caption.Length())
				ResetMatrix()
			Case ALIGNMENT_RIGHT
				Local l:Int = MANIAC_FONT.getW(Caption)
				MANIAC_FONT.Wrap(Caption,MidX+Width/2-l,MidY-Height/5,Width,Height,Caption.Length())
				ResetMatrix()
		End Select

		If bTransparent = False
			If bMO = True
				If bMOBrighter = True
					SetAlpha 0.2
					SetColor 255,255,255
					DrawRect(MidX- (Width +AddWidthByMO/2)/2,MidY-(Height+AddHeightByMO/2)/2,Width+AddWidthByMO,Height+AddHeightByMO)
					Maniac_Debug.addTotDraws(1)
				Endif
			Else
				'SetAlpha 0.6
			Endif

		Endif

		'### Reset The MAtrix
		If Angle <> 0.0
			ResetMatrix()
		Endif
	End Method

	Method Update:Int()
		If MANIAC_DEBUG = True
			'Maniac_Debug.addCalc()
			Maniac_Debug.addCall()
		Endif

		'### Updating Glow Effect ###
		'this will have effect to all Animation & Non Animation stuff.
		If bGlow = True
			If bCurrGlowDirection = True
				GlowAlpha += EqToFPS(GlowHertz)
				If GlowAlpha >= GlowAlphaTo
					bCurrGlowDirection = False
				Endif
			Else
				GlowAlpha -= EqToFPS(GlowHertz)
				If GlowAlpha <= GlowAlphaFrom
					bCurrGlowDirection = true
				Endif
			Endif
		Endif

		'### Animation Effects ###
		If bRunningAnimation = True

			'Check if AnimationTime is Over
			If Millisecs() - AnimStartTime > AnimTime
				bRunningAnimation = False
			Endif

			'If not, calculate the next Position Stuff
			Select AnimEffect
				Case ANIM_DROP
					tweenY.Update()
					MidY = tweenY.Value()
				Case ANIM_FADE
				Case ANIM_ROTATE
				Case ANIM_ROLL
					tweenX.Update()
					tweenAngle.Update()
					Angle = tweenAngle.Value()
					MidX = tweenX.Value()
				Case ANIM_SLIDE
					tweenX.Update()
					MidX = tweenX.Value()

				Case ANIM_CIRCLE
					tweenY.Update()
					tweenX.Update()

					MidX = tweenX.Value()
					MidY = tweenY.Value()
			End Select

		Endif

		'### User Input Stuff like MouseOver, ClickOn etc. ###
		If MOBox(MidX-Width/2	, MidY-Height/2, Width, Height)
			bMO = True
			If bMOWobble = True
				doWobble()
			Endif
			If TouchHit()
				Return 99
			Endif
			Return 101
		Else
			bMO = False
			If bRunningAnimation = False
				resetPosition()
			Endif
		Endif
	End Method

	Method startAnim(_AnimType:Int,  fromX:Float ,toX:Float ,_AnimTime:Int = 1000,ias:Float = 720,iae:Float = 0)

	End Method

	Method startAnimDrop(_fromY:Float,_AnimTime:Int = 1500,_Style:String = "Bounce",_Ease:String = "Out")

		tweenY = ll_Tween(_Style,_Ease,_fromY,oY,_AnimTime )
		tweenY.Start()
		bRunningAnimation = True
		AnimStartTime = Millisecs()
		AnimTime = _AnimTime
		AnimEffect = ANIM_DROP
	End Method

	Method startAnimRoll(_fromX:Float,_AnimTime:Int = 3000,_NumberRounds:Float = 10,_Style:String = "Bounce",_Ease:String = "Out")
		tweenX = ll_Tween(_Style,_Ease,_fromX,oX,_AnimTime )
		tweenX.Start()
		tweenAngle = ll_Tween(_Style,_Ease,_NumberRounds*(360),0,_AnimTime )
		tweenAngle.Start()
		bRunningAnimation = True
		AnimStartTime = Millisecs()
		AnimTime = _AnimTime
		AnimEffect = ANIM_ROLL
	End Method

	Method startAnimSlide(_fromX:Float,_AnimTime:Int = 1500,_Style:String = "Bounce",_Ease:String = "Out")
		tweenX = ll_Tween(_Style,_Ease,_fromX,oX,_AnimTime )
		tweenX.Start()
		bRunningAnimation = True
		AnimStartTime = Millisecs()
		AnimTime = _AnimTime
		AnimEffect = ANIM_SLIDE
	End Method

	Method startAnimCircle(_fromX:Float,_fromY:Float,_AnimTime:Int = 5000)
		tweenX = New Tween(Tween.Sine.EaseOut,_fromX,oX,_AnimTime)
		tweenX.Start()
		tweenY = New Tween(Tween.Sine.EaseInOut,_fromY,oY,_AnimTime)
		tweenY.Start()
		bRunningAnimation = True
		AnimStartTime = Millisecs()
		AnimTime = _AnimTime
		AnimEffect = ANIM_CIRCLE
	End Method

	Method startAnimPopOut()

	End Method
	Method setAlignment(_Alignment:Int)

		'Checking for using right Alignment Convention, else set to ALIGNMENT_MIDDLE
		Select _Alignment
			Case ALIGNMENT_LEFT
				Alignment = _Alignment
			Case ALIGNMENT_MIDDLE
				Alignment = _Alignment
			Case ALIGNMENT_RIGHT
				Alignment = _Alignment
			Default
				Print "Alignment doesnt exist, Set To Middle!!!"
				Alignment =	ALIGNMENT_MIDDLE
		End Select
	End Method

	Method setCaption(_Caption:String,_Color:int)
		Caption = _Caption
		CaptionColor = _Color
	End Method

	Method setPosition(_X:float,_Y:float)
		MidX = _X
		MidY = _Y
	End Method

	Method setSize(_Width:Float,_Height:Float)
		Width = _Width
		Height =_Height
	End Method

	Method setAngle:Void(_Angle:Float)
		Angle = _Angle
	End Method

	#Rem monkeydoc
		This Method sets the current Glow Effect.

		to switch Glow effect off, just call

		Example:

			'To Switch Off, just call within OnUpdate()
			 objName.setGlow(false)

			 'To Specify the Glow effect, use the params:~n
			 _isGlowing << true - glow is active, else it doesnt render glow effect ~n
			 _GlowColor << use one of the Maniac preset Color Ints.
			 _GlowHertz << 1.0 means it raises 100% Alpha within 1 Second ; 0.5 means it need 2 Seconds

			 _GlowStyle	<< at the Moment just Style 0 implemented (Standard)

	#End
	Method setGlow(_isGlowing:Bool = True ,_GlowColor:Int = COLOR_WHITE ,_GlowHertz:Float = 1.0,_GlowAlphaFrom:Float = 0.2,_GlowAlphaTo:Float = 0.7,_GlowStyle:Int = 0)
		bGlow 		= _isGlowing
		GlowHertz	= _GlowHertz
		GlowColor 	= _GlowColor
		GlowAlphaFrom 	= _GlowAlphaFrom
		GlowAlphaTo 	= _GlowAlphaTo
		GlowStyle = _GlowStyle
	End Method

	Method setFrame(_isFramed:Bool = True,_FrameColor:Int = 0,_FrameType:Int=0,_FrameThickness:Int =1)
		bFramed = _isFramed
		FrameColor = _FrameColor
		FrameType = _FrameType
		FrameThickness = _FrameThickness
	End Method

	Method setMouseOverEffects(_isResizing:Bool= True ,_isBrightening:Bool=False,_isWobbling:Bool = false )
		bMOResize		= _isResizing
		bMOBrighter		= _isBrightening
		bMOWobble		= _isWobbling
	End Method

	Method setInactiveAnim()

	End Method

	Method doWobble(_ShakeDistance:Float = 3.5,_Hertz:Float = 60,_Strength:Float = 0.9)
		If MANIAC_DEBUG = True
			'Maniac_Debug.addCalc()
			Maniac_Debug.addCall()
		Endif
		If Millisecs()-lastWobble >= (1000 / _Hertz)
			lastWobble = Millisecs()
			MidX += Rnd(-_Strength,_Strength)
			MidY += Rnd(-_Strength,_Strength)

			If MidX > (oX+_ShakeDistance)
				MidX = oX+_ShakeDistance
			Endif
			If MidX < (oX-_ShakeDistance)
				MidX = oX-_ShakeDistance
			Endif
			If MidY > (oY+_ShakeDistance)
				MidY = oY+_ShakeDistance
			Endif
			If MidY < (oY-_ShakeDistance)
				MidY = oY-_ShakeDistance
			Endif
		Endif

	End Method

	#rem
		### This Method is deprecated!!! Please don't use it in Future. Use startAnimRoll instead It's just for backward compatibatibility ####
	#end
	Method doRoll(_AngleSpeed:Float)
		If MANIAC_DEBUG = True
			'Maniac_Debug.addCalc()
			Maniac_Debug.addCall()
		Endif
		Angle += EqToFPS(_AngleSpeed)
	End Method

	Method doRotate(_AngleSpeed:Float)
		If MANIAC_DEBUG = True
			Maniac_Debug.addCall()
		Endif
		Angle += EqToFPS(_AngleSpeed)
	End Method

	Method resetPosition()
		If MANIAC_DEBUG = True
			'Maniac_Debug.addCalc()
			Maniac_Debug.addCall()
		Endif
		MidX = oX
		MidY = oY
		Angle = 0
	End Method

	Method setVisible(_Bool:Bool)
		bVisible = _Bool
	End Method

	#rem monkeydoc
		Style can be one of the following Const Int:~n
		const BUTTON_STYLE_RECTSTD:Int 	= 0~n
		Const BUTTON_STYLE_RECT2:Int 	= 1~n
		Const BUTTON_STYLE_ROUND1:Int 	= 2~n
		Const BUTTON_STYLE_ROUND2:Int 	= 3~n
		Const BUTTON_STYLE_ROUND3:int   = 4~n
	#end
	Method setStyle:Void(_Style:Int)
		ButtonStyle = _Style
	End Method
End Class

#Rem monkeydoc
	This Class is a Slider Gui Element.
	Version 1.0 (a) Stable but unhandy
	Example:

		'This Example Shows how to use the Slider
		Global slider:ManiacSlider

		'... OnCreate
		slider =  new ManiacSlider(100,100,300,32,25,75)

		'... OnUpdate()
		slider.Update()
		local val:float = slider.getValue()

		'...OnRender()
		slider.Draw()

#End
Class ManiacSlider
	Private
	Field maniacID:Int
	Field X:Float,Y:Float,Width:Float,Height:Float

	Field SliderX:Float

	Field Value:Float
	Field ValueFrom:Float
	Field ValueTo:Float
	Field ValueStep:Float

	Field HoldPicker:Bool = True

	Public
	#Rem monkeydoc
		This is the Constructor for the Slider
		_X & _Y are topleft-Corner Koordinates in Pxl~n
		_Width & _Height are the rectangular size of the Slider in Pxl~n
		_ValueFrom - sets the lowest Return-Value
		_ValueTo	- sets the Maximum Return Value
	#End
	Method New(_X:Float,_Y:Float,_Width:Float,_Height:Float,_ValueFrom:Float = 0,_ValueTo:Float = 100)
		Maniac_Debug.addStoredBools()
		Maniac_Debug.addStoredInts()
		Maniac_Debug.addStoredFloats(9)
		maniacID = Maniac_Debug.getNumberOfRegisteredObjects()
		Maniac_Debug.addRegisteredObject()

		X = _X
		Y = _Y
		Width = _Width
		Height= _Height
		ValueFrom = _ValueFrom
		ValueTo = _ValueTo
		SliderX = _X + _Width*0.5
	End Method

	#Rem monkeydoc
		This Method returns the Current Value of Slider.
	#End
	Method getValue:Float()
		Maniac_Debug.addTotCall()
		Maniac_Debug.addTotCalc(2)
		'Maniac_Debug.addTotDraws()
		Local p:Float = (SliderX - X) / (X+Width-X)
		Local val:Float =  ValueFrom + (ValueTo-ValueFrom)*p

		Return val
	End Method

	#Rem monkeydoc
		This Method Draws the whole Slider with Picker.
	#End
	Method Draw()
		Maniac_Debug.addTotCall()
		'Maniac_Debug.addTotCalc(2)
		Maniac_Debug.addTotDraws(2)
		SetAlpha 1
		SetColor 255,255,255
		DrawImage MANIAC_IMG_SLIDERLINE,X,Y,0,Width/MANIAC_IMG_SLIDERLINE.Width(),Height/MANIAC_IMG_SLIDERLINE.Height()

		If HoldPicker = True
			SetColor 0,255,0
			DrawText "Value: " + getValue(),X,Y+Height
		Endif
		DrawImage MANIAC_IMG_SLIDERPICKER,SliderX,Y+Height*0.5,0,(Width*0.1)/MANIAC_IMG_SLIDERPICKER.Width(),(Height*1.2)/MANIAC_IMG_SLIDERPICKER.Height()
	End Method

	#Rem monkeydoc
		This Method Updates the Slider. Especially the Picker and his X-Value.
		It checks for User-Slider for its own.
	#End
	Method Update()
		Maniac_Debug.addTotCall()
		HoldPicker = False
		If TouchDown()
			If MOBox( SliderX-(Width*0.1)/2,  Y,  (Width*0.1), (Height*1.2))
				HoldPicker = True
				SliderX = MouseX()
				If SliderX >= X+Width
					SliderX = X+Width
				Endif
				If SliderX <= X
					SliderX = X
				Endif
			Endif
		Endif
	End Method
End Class

#Rem monkeydoc
	This Class is a GalleryViewer Gui Element.
	Version 0.1
	Example:

		Global tB:ManiacButton = new ManiacButton(100,100,300,32)

		Function Main:Int()
			New Example
			Return 0
		End Function

#End
Class ManiacGallery	Implements IOnLoadImageComplete
	Global loadedImages:Int =	0
	Global l:Int = 0

	Field arrImg:Image[500]
	Field maniacID:Int
	Field X:Float,Y:Float,Width:Float,Height:Float
	Field ViewMode:Int = 1
	Field dist:Int = 10
	Field imgW:Float,imgH:Float

	Field BtnRight:ManiacButton
	Field BtnLeft:ManiacButton
	Field BtnSwitchViewStyle:ManiacButton

	Field ScrolledImages:Int = 0

	Field tp:Int	= 0
	Field lastSwitch:Int
	Field switchIntervall:Int = 500

	Field Alpha:float

	Method New(_X:Float,_Y:Float,_Width:Float,_Height:Float,_loadPath:String = "GFX/")
		'arrImg[
		X = _X
		Y = _Y
		Width =_Width
		Height = _Height
		loadFromPath(_loadPath)
		Local bW:Float = DW*0.15
		Local bH:Float = DH*0.07
		imgW = ll_Width(_Width,3,dist)
		imgH = (_Height-bH)/2.5

		BtnLeft 			=  New ManiacButton(_X + bW/2 + _Width*0.02 ,_Y+_Height-bH/2, bW,	bH," << ",ALIGNMENT_MIDDLE,COLOR_BLUE,True,1.5)
		BtnRight 			=  New ManiacButton(_X + _Width - bW/2 - _Width*0.02 ,_Y+_Height-bH/2, bW,	bH," >> ",ALIGNMENT_MIDDLE,COLOR_BLUE,True,1.5)
		BtnSwitchViewStyle 	=  New ManiacButton(_X + _Width*0.5 ,_Y+_Height-bH/2, bW,	bH," Switch ",ALIGNMENT_MIDDLE,COLOR_BLUE,True,1.5)

	End Method

	Method loadFromPath:Void(_Path:String="monkey://external/" )
		'Local stdPath:String
		#rem
		If _Path.Contains("monkey://external/")

		Elseif _Path.Contains("monkey://data/")
		Elseif _Path.Contains("monkey://internal/")
			stdPath = "monkey://internal/"
		Else
			stdPath = "monkey://external/"+_Path
		Endif
		#end
		Print "Get Folder"
		Local arrStr:String[] = GetFolderFiles(_Path)
		Print "Found: " + arrStr.Length() + " files"
		l = arrStr.Length()
		#rem
		If arrStr.Length() > 0
			For Local j:Int = 0 Until loadedImages'arrStr.Length()
				Print "Loading Image " + arrStr[j] + " to arrImg["+(j)+"]"
				arrImg[j] = LoadImage()
			Next
		Endif
		#end
		For Local ls:Int = 0 Until l
			Print "load " + ls
			LoadImageAsync(arrStr[ls], 1, 0, Self)
		Next
	End Method

	Method Draw()
		Drw_Rect(X,Y,Width,Height,3)
		SetColor 255,255,255
		SetAlpha 1
		Select ViewMode
			Case 0	'3x2 overview
				Local i:Int = 0
				For Local x:Int = 0 To 2
					For Local y:Int = 0 To 1
						Drw_Rect(X+dist+x*(imgW+dist)  , Y+dist+y*(imgH+dist), imgW,imgH,2)
						'Print "i: " + i
						if arrImg[i+ScrolledImages] = Null
							DrawText "No Image",X+dist+x*(imgW+dist)  , Y+dist+y*(imgH+dist)
						Else
							DrawImage ( arrImg[i+ScrolledImages] , X+dist+x*(imgW+dist)  , Y+dist+y*(imgH+dist),0, imgW/arrImg[i+ScrolledImages].Width(), imgH/arrImg[i+ScrolledImages].Height() )
						Endif
						i +=1
					Next
				Next

			Case 1
				If arrImg[tp] <> Null
					SetAlpha 1
					DrawImage arrImg[tp], X,Y,0,Width*1/arrImg[tp].Width(),Height*0.87/arrImg[tp].Height()
				Endif
				If arrImg[tp+1] <> Null
					SetAlpha Alpha
					DrawImage arrImg[tp+1], X,Y,0,Width*1/arrImg[tp+1].Width(),Height*0.87/arrImg[tp+1].Height()
				Endif
		End Select

		BtnLeft.Draw()
		BtnRight.Draw()
		BtnSwitchViewStyle.Draw()

		DrawText("Mode: " + ViewMode+ " | View: " + tp + "/"+loadedImages , X +Width*0.5,Y)
	End Method

	Method Update:Int()

		If BtnLeft.Update() = 101 And gl_mousereleased
			if ScrolledImages <= 0

			Else
				ScrolledImages -= 1
			Endif
		Endif

		If BtnRight.Update() = 101 And gl_mousereleased
			If (ScrolledImages + 6) >= loadedImages

			else
				ScrolledImages += 1
			Endif
		Endif

		If BtnSwitchViewStyle.Update() = 101 And gl_mousereleased
			If ViewMode = 0
				ViewMode = 1
			Else
				ViewMode = 0
			Endif
		Endif

		Select ViewMode
			Case 0
			Case 1
				If Millisecs() - lastSwitch >= switchIntervall
					If (tp + 1) >= loadedImages
						tp = 0
					else
						tp +=1
					Endif
					Alpha = 0
					lastSwitch = Millisecs()
				Endif

				Alpha += EqToFPS(1.0/(switchIntervall/1000.0))' 0.02
		End Select
	End Method

	Method OnLoadImageComplete:Void(_image:Image, path:String, source:IAsyncEventSource)
		If _image <> Null
			arrImg[loadedImages] = _image
			loadedImages += 1
		Else
			Print "no image : "+loadedImages
		Endif

		#rem
		arrImg[loadedImages] = _image
		Print "Loaded Image id: " + loadedImages
		If arrImg[loadedImages] = Null
			Print "no image : "+loadedImages
		Else
			Maniac_Debug.addRegisteredGraphics()
		Endif
		loadedImages += 1
		#end
	End

	Method getNumberOfLoadedImages:Int()

	End Method

	Method getImageByID:Image(_ID:Int)

	End Method

End class

#Rem monkeydoc
	This Class is a RadioGroup Gui Element.

	Example:

		Global tB:ManiacButton = new ManiacButton(100,100,300,32)

		Function Main:Int()
			New Example
			Return 0
		End Function

#End
Class ManiacRadioGroup
	Field X:Int,Y:Int,Width:Int,Height:Int
	Field bFramed:Bool = true
	Field listElements:List<RadioElement>
	Field dist:Float = 8
	Field ActiveElementID:Int
	Field Caption:String

	Method New(x:Int,y:Int,w:Int,h:Int,caption:String = "")
		X = x
		Y = y
		Width = w
		Height = h
		Caption = caption
		listElements = New List<RadioElement>
	End Method

	Method Draw()
    	For Local oRE:RadioElement = Eachin listElements
     		oRE.Draw()
    	Next
	End Method

	Method addChoice(_Caption:String,_Value:Int)
   		Local oRE:RadioElement = New RadioElement(_Caption,_Value)
    	oRE.ID = listElements.Count()
		listElements.AddLast(oRE)
		reOrder()
	End Method

	Method getActiveElementValue:Int()
	    For Local oRE:RadioElement = Eachin listElements
	      If oRE.isActive()
	        Return oRE.Value
	      Endif
	    Next
	End Method

	Method Update:Void()
	    Local newClickID:Int = 0
	    'Check for Clicking on a RadioElement
	    For Local oRE:RadioElement = Eachin listElements
	      If oRE.Update() <> -1
	        setActiveElement(oRE.ID)
	      Endif
	    Next
	End Method

	Method setActiveElement:Void(_ID:Int)
	    For Local oRE:RadioElement = Eachin listElements
	      If oRE.ID = _ID
	        oRE.setActive(True)
	      Else
	        oRE.setActive(False)
	      Endif
	    Next
	End Method

	Private
	Method reOrder()
	    Local eW:Float = ll_Width(Width,listElements.Count(),10)

	    Local i:Int = 0
	    For Local oRE:RadioElement = Eachin listElements
	    	oRE.setPosition(X + 10 + i*eW/2.0, Y + Height*0.5, eW/2,eW/2)
	    	i +=1
	    Next
	End Method
End Class

Private
Class RadioElement
  	Field ID:Int
	Field Caption:String
	Field Value:Int
	Field X:Float,Y:Float,Width:Float,Height:Float
	Field bActive:Bool

	Method New(_Caption:String,_Value:int)
		Caption =_Caption
		Value =_Value
	End Method

	Method Draw()
    	'Drawing the Selectable Circle
    	'Drw_Ellipsis( X, Y, Width, Height)
	End Method

	Method setPosition(_X:Float, _Y:Float, _Width:Float,_Height:Float)
	    X = _X
	    Y = _Y
	    Width  = _Width
	    Height = _Height
	End Method

	Method Update:Int()
    	If MOCircle(X,Y,Width)
     		If gl_mousereleased
        		Return ID
     		Endif
    	Endif
    	Return -1
	End Method

	Method setActive(_isActive:Bool = True)
   		bActive = _isActive
	End Method
End Class
public

#Rem monkeydoc
	This Class is a CheckBox Gui Element.
	Version 0.1
	Example:

		Global tB:ManiacButton = new ManiacButton(100,100,300,32)

		Function Main:Int()
			New Example
			Return 0
		End Function

#End
Class ManiacCheckBox
	Field maniacID:Int
	Field X:Float
	Field Y:Float
	Field Width:Float
	Field Height:Float
	Field bChecked:Bool
	Field Caption:String

	Method New(_X:Float,_Y:Float,_Width:Float,_Height:Float,_Caption:String="")
		Maniac_Debug.addStoredBools(1)
		Maniac_Debug.addStoredInts(1)
		Maniac_Debug.addStoredFloats(4)
		maniacID 		= Maniac_Debug.getNumberOfRegisteredObjects()
		Maniac_Debug.addRegisteredObject()
		X 		= _X
		Y		= _Y
		Width 	= _Width
		Height 	= _Height
		Caption =	_Caption
	End Method

	Method Draw()
		Drw_Rect(X,Y,Width,Height,2)

		If bChecked = True
			DrawImage MANIAC_IMG_CHECK ,X ,Y ,0 , Width/MANIAC_IMG_CHECK.Width() , Height/MANIAC_IMG_CHECK.Height()
		Endif
	End Method

	Method Update()
		If TouchHit()
		If MOBox(X,Y, Width, Height)
			If bChecked = True
				bChecked = False
			Else
				bChecked = True
			Endif
		Endif
		Endif
	End Method

	Method getChecked:Bool()
		Return bChecked
	End Method
End Class

Class ManiacFileExplorer

End Class

private
Class textElement
	Field Caption:String
	Field Line:Int

	Method New(_Caption:String="")
		Caption =_Caption
	End Method
	Method Draw(_X:Float,_Y:Float,_Width:Float,_Height:Float)
		MANIAC_FONT.Wrap(Caption,_X,_Y,_Width,_Height,Caption.Length())
	End Method
End Class

public
#Rem monkeydoc
	This Class is a DropDown Gui Element.
	Version 0.1

	Example:

		Global tf:ManiacSimpleTextfield = new ManiacSimpleTextfield(100,100,300,32)
		Function Main:Int()
			New Example
			Return 0
		End Function

#End
Class ManiacDropDown
	Field maniacID:Int
	Field X:Float
	Field Y:Float
	Field Width:Float
	Field Height:Float
	Field bOpened:Bool
	Field Caption:String

	Field showOpenHeader:Int	= 1		'0 - Always Show Caption, 1 - Show MouseOver Elements , 2 - Show Selected Element
	Field showCloseHeader:Int 	= 2
	Field bCloseOnSelected:Bool = True

	Field ShowLines:Int 	= 4
	Field ScrolledLines:Int = 0
	Field listTextElements:List<textElement>
	Field MOElement:Int
	Field SelectedElement:Int = 0

	Field tweenY:Tween

	Method New(_X:Float,_Y:Float,_Width:Float,_Height:Float,_Caption:String="")
		Maniac_Debug.addStoredBools(1)
		Maniac_Debug.addStoredInts(1)
		Maniac_Debug.addStoredFloats(4)
		maniacID 		= Maniac_Debug.getNumberOfRegisteredObjects()
		Maniac_Debug.addRegisteredObject()
		X 		= _X
		Y		= _Y
		Width 	= _Width
		Height 	= _Height
		Caption =	_Caption
		listTextElements = New List<textElement>
	End Method

	Method addLine(_Caption:String)
		Local oL:textElement = New textElement(_Caption)
		oL.Line = listTextElements.Count()

		listTextElements.AddLast(oL)

	End Method

	Method DrawText()
		For Local oL:textElement = Eachin listTextElements
			oL.Draw(X+5,Y+Height+oL.Line*(27+5),200,100)
		Next
	End Method

	Method animOpen()
		tweenY = ll_Tween(_Style,_Ease,_fromY,oY,_AnimTime )
		tweenY.Start()
	End Method

	Method animClose()

	End Method

	Method Draw()

		If bOpened = True
			Drw_Rect(X,Y,Width,Height,2)
			Drw_Rect(X,Y+Height,Width,Height+ShowLines*(MANIAC_FONT.getH()+5),1)
			DrawText()

			Select showOpenHeader
				Case 0
					MANIAC_FONT.Wrap(Caption,X,Y,Width,Height,Caption.Length())
				Case 1
					MANIAC_FONT.Wrap(getTextByID(MOElement),X,Y,Width,Height,Caption.Length())
				Case 2
					MANIAC_FONT.Wrap(getTextByID(SelectedElement),X,Y,Width,Height,Caption.Length())
			End Select

			DrawImage MANIAC_IMG_DROPDOWN , X+Width*0.9,Y, 0 , (Width*0.1)/MANIAC_IMG_DROPDOWN.Width(),Height/MANIAC_IMG_DROPDOWN.Height()
		Else
			Drw_Rect(X,Y,Width,Height,2)

			Select showCloseHeader
				Case 0
					MANIAC_FONT.Wrap(Caption,X,Y,Width,Height,Caption.Length())
				Case 1
					MANIAC_FONT.Wrap(getTextByID(MOElement),X,Y,Width,Height,Caption.Length())
				Case 2
					MANIAC_FONT.Wrap(getTextByID(SelectedElement),X,Y,Width,Height,Caption.Length())
			End Select

			DrawImage MANIAC_IMG_DROPDOWN , X+Width*0.9,Y, 0 , (Width*0.1)/MANIAC_IMG_DROPDOWN.Width(),Height/MANIAC_IMG_DROPDOWN.Height()
		Endif
	End Method

	Method Update()
		If TouchHit()
		If MOBox(X+Width*0.9,Y, Width*0.1, Height)
			If bOpened = True
				bOpened = False
			Else
				bOpened = True
			Endif
		Endif
		Endif
		MOElement = -1
		If bOpened
			For Local i:Int = 0 Until ShowLines
				If MOBox(X,Y+Height+i*(27+5),Width,27)
					MOElement = i
					If TouchHit()
						SelectedElement = i
						If bCloseOnSelected = True
							bOpened = False
						Endif
					Endif
				Endif
			Next
		Endif
	End Method

	Method getTextByID:String(_ID:Int)
		Local i:Int = 0
		For Local oL:textElement = Eachin listTextElements
			If i = _ID
				Return oL.Caption
			Endif
			i +=1
		Next
	End Method

	Method getSelectedText:String()
		Local i:Int = 0
		For Local oL:textElement = Eachin listTextElements
			If i = SelectedElement
				Return oL.Caption
			Endif
			i +=1
		Next
	End Method

End Class

#Rem monkeydoc
	This Class is a ListView Gui Element.
	You can Add Lines of Strings and Scroll them within this View.
	Version 0.1

	Example:

		Global tf:ManiacSimpleTextfield = new ManiacSimpleTextfield(100,100,300,32)
		Function Main:Int()
			New Example
			Return 0
		End Function

#End
Class ManiacListView
	Field maniacID:Int
	Field X:Float,Y:Float,Width:Float,Height:Float
	Field listText:List<textElement>

	Field nrLines:Int
	Field ScrolledLine:Int = 0

	Method New(_X:Float,_Y:Float,_Width:Float,_Height:Float)
		nrLines = _Height/32
		X = _X
		Y = _Y
		Width =_Width
		Height = _Height
		listText = New List<textElement>
	End Method

	Method Draw()
		Drw_Rect(X,Y,Width,Height,2)

		For Local i:Int = 0 Until nrLines
			MANIAC_FONT.Wrap(getText(i+ScrolledLine),X+5,Y+5+i*(27+5),Width,Height,40)
		Next

		SetAlpha 1
		DrawImage MANIAC_IMG_ARROWDOWN,X,Y+Height+5,0,Width/MANIAC_IMG_ARROWDOWN.Width(),48.0/MANIAC_IMG_ARROWDOWN.Height()
	End Method

	Method Update()
		If TouchHit()
			If MOBox(X,Y+Height+5,Width,48)
				ScrolledLine +=1
			Endif
		Endif
	End Method

	Method addLine(_Line:String)
		Local oL:textElement = New textElement(_Line)
		listText.AddLast(oL)
	End Method

	Private
	Method getText:String(_ID:Int)
		Local i:Int = 0
		For Local oL:textElement = Eachin listText
			If i = _ID
				Return oL.Caption
			Endif
			i +=1
		Next
	End Method
End Class

Class ManiacDialog
	Field X:Float,Y:Float,Width:Float,Height:Float
	Field Question:String
	Field Alpha:Float = 0.8
	Field bVisible:Bool = True

	Field Btn_Ja:ManiacButton
	Field Btn_Nein:ManiacButton

	Method New(_X:Float,_Y:Float,_Width:Float,_Height:Float,_Question:String ="")
		X = _X
		Y = _Y
		Width =_Width
		Height = _Height
		Question = _Question

		Btn_Ja = New ManiacButton(X+_Width*0.75,Y+_Height*0.8,_Width*0.4,	_Height*0.25,"Ja",ALIGNMENT_MIDDLE,COLOR_BLUE,True,0.2)
		Btn_Nein = New ManiacButton(X+_Width*0.25,Y+_Height*0.8,_Width*0.4,	_Height*0.25,"Nein",ALIGNMENT_MIDDLE,COLOR_BLUE,True,0.2)
	End Method

	Method Draw()
		If bVisible = True
			SetColor 0,0,0
			SetAlpha Alpha
			DrawRect(X,Y,Width,Height)

			SetAlpha 1
			SetColor 255,255,255
			MANIAC_FONT.Wrap(Question,X+Width*0.05,Y+15,Width*0.9,Height,350)

			Btn_Ja.Draw()
			Btn_Nein.Draw()
		Endif
	End Method

	Method Update:Int()
		If Btn_Ja.Update() = 101
			Return 2
		Elseif Btn_Nein.Update() = 101
			Return 1
		Else
			Return 0
		Endif
	End Method

	Method setVisible(_bVisible:Bool = True)
		bVisible = _bVisible
	End Method
End Class

private
Class ManiacAnimRect
	'Identificanitional Values
	Field ID:Int
	Field maniacID:Int
	Field MidX:Float,MidY:Float			'aktuelle Position des Buttons (Durch Animationen veränderbar
	Field oX:Float,oY:Float 		'Original X,Y << Das ist die Feste Position des Buttons
	Field Width:Float,Height:Float			'Breite und Höhe in Pxl
	Field oWidth:Float,oHeight:Float

	'
	Field Caption:String		'Aufschrift
	Field Angle:Float 			'Winkel zur Horizontalen in °
	Field AlignX:Int			'ausrichtung des Textes (Left,Middle,Right)
	Field AlignY:int

	Method setPosition(_X:float,_Y:float)
		MidX = _X
		MidY = _Y
	End Method

	Method setSize(_Width:Float,_Height:Float)
		Width = _Width
		Height =_Height
	End Method

	Method reSize(_Scale:Float = 1.0)
		ScaleAt(MidX,MidY, _Scale, _Scale)
	End Method

End Class
Class ManiacSimpleTextfield
	Private
	Field ID:Int
	Field inputString:String = ""
	Field X:Int,Y:Int
	Field W:Int,H:int

	Field Style:Int
	Field Focus:Int		'0 - Standard ohne gfx effects , 1 -

	Field bEditing:Bool = False

	Public
	Method New(_X:Float,_Y:Float,_Width:Float,_Height:Float,istyle:Int = TEXTFIELD_STYLE_STD)
		ID 		= Maniac_Debug.getNumberOfRegisteredObjects()
		X 		= _X
		Y 		= _Y
		W 		= _Width
		H 		= _Height
		Style 	= istyle
		Maniac_Debug.addRegisteredObject()
	End Method

	Public
	Method update:Int()
		If bFull = True
			If TouchHit()
				If MOBox(X,Y,(W*0.15),(H*1.0))
					If bEditing = True
						bEditing = False
					Else
						bEditing = True
					Endif
				Endif
			Endif
		Endif

		If bEditing = True
			Repeat
				Local char=GetChar()
		        If Not char Exit

		        If char>=32
		            inputString+=String.FromChar( char )
		        Endif

		        If char = CHAR_ENTER
					DisableKeyboard()
					Return 99
				Endif

		        If char = CHAR_BACKSPACE
					Local txtlength:Int = inputString.Length()
					Local txtchars:Int[] = inputString.ToChars
					inputString = ""
					For Local l:Int = 0 To txtlength-2
						inputString += String.FromChar(txtchars[l])
					Next
				Endif

			Forever
		Endif
	End Method

	Public
	Method draw()
		DrawText inputString,X,Y
	End Method

	Method getText:String()
		Return inputString
	End Method

	Method setText(itext:String)
		inputString = itext
	End Method
End Class

#Rem monkeydoc Module maniac.maniacSimpleGUI
	Simple GUI - Version 0.1.5 (alpha)  ~n
	Copyright (C) 2015  Stephan Duckerschein~n

	Here You can find some GUI Elements to use for your App.
	They can be used 'ad-hoc'-like. the have to be managed by the Programmer.

#End

#rem
	Work On:
		DropDown,RadioGroup,FileExplorer,ListView for Version 0.1.6

		- need Color Scheme
		- need Graphics Update

		- Buglist:
			ManiacButton -> Rolling Animation is not Ready yet
	VERSION:~n
	0.1.5	- updated Textfield Class
				- now shows the Cursor, X-Alignment is available, set the Alpha, Wrap Textfield to Height of Text (Single Line Only at the Moment!!!!!)
				- Bugfixed some Update and Drawing Stuff.
				- changed Framethickness to 1 pxl ... now it looks much better
	0.1.4	- added: ManiacCheckBox,DropDown,ListView, Dialog
	0.1.3	- added a ImageGallery-Class >> ToDo: some imageLoading Bugfixes. UpdateEventAsync testing around ...

	0.1.2:	- bugfixes Frame
			- added some setter
			- added "doWobble","doRoll" (instantEffects)
			- added "startAnimDrop","startAnimSlide" and "startAnimCircle"
			- updated ManiacButton Class
			- added a Slider Class

	Wishlist:
		 x Simple Button
		 x Textfield
		 x Slider
		 x Checkbox
		 x GalleryViewer
		 x DropDown
		RadioBox
		Docker
		Tabs

	Implemented Feature: GUI
		- Button
		- Textfield
		- Slider
		- GalleryViewer
#end

Import maniacDebug

public
Const TEXTFIELD_STYLE_STD:Int 			= 0
Const TEXTFIELD_STYLE_WITHBUTTON:Int 	= 1

#Rem monkeydoc
	This Class is a Textfield Gui Element.
	Version 1.1

	Example:

		Global tf:ManiacSimpleTextfield = new ManiacSimpleTextfield(100,100,300,32)
		Function Main:Int()
			New Example
			Return 0
		End Function

#End
Class ManiacTextfield
	Private
	Field maniacID:Int
	Field ID:Int
	Field inputString:String = ""
	Field Caption:String = ""
	Field X:Int,Y:Int
	Field W:Int,H:int

	Field Style:Int

	Field bShowButton:Bool 	= False
	Field bShowCaption:Bool
	Field bWrapHeight:Bool = False
	Field bEditing:Bool = False
	Field bEndOnEnter:Bool = True

	Field Angle:Float = 0.0
	Field Alpha:Float 	= 1.0'Main Alpha Value.
	Field Focus:Int		'0 - Standard ohne gfx effects , 1 -

	Field ColorBackground:Int = 8'COLOR_WHITE
	Field AlphaCursor:Float
	Field TimeLastCursorChange:Int
	Field TimeCursorChange:Int = 510
	Field PosCursor:Float

	Field AlignmentCaption:Int

	Public
	Method New(_X:Float,_Y:Float,_Width:Float,_Height:Float,_Caption:String = "",_Style:Int = TEXTFIELD_STYLE_STD)
		If MANIAC_DEBUG = True
			Maniac_Debug.addStoredBools()
			Maniac_Debug.addStoredInts(8)
			maniacID = Maniac_Debug.getNumberOfRegisteredObjects()
			Maniac_Debug.addRegisteredObject()
		Endif

		X 		= _X
		Y 		= _Y
		W 		= _Width
		H 		= _Height
		Style 	= _Style
		Caption = _Caption
		Alpha = 1.0
		AlignmentCaption = ALIGNMENT_MIDDLE
	End Method

	Public
	Method Update:Int()
		If MANIAC_DEBUG = True
			Maniac_Debug.addTotCall()
		Endif

		'### Check for Wrapping ###
		If bWrapHeight = True
			H = 30
		Endif

		'### Check for Click
		If bShowButton = True
			If TouchHit()
				If MOBox(X,Y,(W*0.15),(H*1.0))
					If bEditing = True
						bEditing = False
						Return 99
					Else
						bEditing = True
						#If TARGET="android"
							EnableKeyboard()
						#Endif
					Endif
				Endif
			Endif

		Else
			If TouchHit()
				If MOBox(X,Y,(W),(H))
					If bEditing = True
						bEditing = False
					Else
						bEditing = True
						#If TARGET="android"
							EnableKeyboard()
						#Endif

					Endif
				Endif
			Endif
		Endif

		If bEditing = True
			'### Updating the Cursor Alpha
			If (Millisecs() - TimeLastCursorChange ) > TimeCursorChange
				TimeLastCursorChange = Millisecs()
				If AlphaCursor > 0.8
					AlphaCursor = 0.05
				Else
					AlphaCursor = 1.0
				Endif

			Endif
			'### Updating the KeyboardInput
			Repeat
				Local char=GetChar()
		        If Not char Exit

		        If char>=32
		            inputString+=String.FromChar( char )
		        Endif

		        If char = CHAR_ENTER
		        	#If TARGET="android"
						DisableKeyboard()
					#Endif
					If bEndOnEnter = True
						bEditing = False
					Endif
					Return 99
				Endif

		        If char = CHAR_BACKSPACE
					Local txtlength:Int = inputString.Length()
					Local txtchars:Int[] = inputString.ToChars
					inputString = ""
					For Local l:Int = 0 To txtlength-2
						inputString += String.FromChar(txtchars[l])
					Next
				Endif

			Forever
		Endif
	End Method

	Public
	Method Draw()
		If MANIAC_DEBUG = True
			Maniac_Debug.addTotCall()
			Maniac_Debug.addTotDraws(3)
		Endif

		'### Rotate The Matrix at the MidX/MidY Position around Angle
		If Angle <> 0.0
			RotateAt(X+W/2,Y+H/2, Angle)
		Endif

		'### Drawing Background ###
		SetAlpha Alpha
		Maniac_Color(ColorBackground)
		'SetColor 255,255,255
		DrawRect(X,Y,W,H)

		'### Drawing an Explaining Text to the Textfield ...
		'ToDo: - Alignment (Top,Bottom), Color
		SetColor 0,0,0
		MANIAC_FONT.Wrap(Caption,X,Y-(ManiacFont.getH()+5),W,H,Caption.Length())

		'### Drawing an "Fertig"-Button ... if pressed, its same like "I'm Done with text, it will disable the Keyboard (for Android)
		If bShowButton = True
			DrawImage MANIAC_IMG_EDITICON,X,Y,0,(W*0.15)/MANIAC_IMG_EDITICON.Width(),(H*1.0)/MANIAC_IMG_EDITICON.Height()
		Endif

		'### Drawing the Input Text String ###
		SetColor 0,0,0
		Local cursorPos:Float
		If bShowButton = True

			MANIAC_FONT.Wrap(inputString,X+W*0.15,Y+H/2-ManiacFont.getH()/2,W,H,inputString.Length())
		Else
			'MANIAC_FONT.Wrap(inputString,X,Y+H/2-ManiacFont.getH()/2,W,H,inputString.Length())
			cursorPos = Drw_ManiacText(inputString,X,Y,W,H,AlignmentCaption)
		Endif

		'### Drawing the Cursor ###
		If bEditing = True
			Local iw:Int = MANIAC_FONT.getW(inputString)
			SetAlpha AlphaCursor
			MANIAC_FONT.Wrap("|",cursorPos,Y+H/2-ManiacFont.getH()/2,W,H,2)
		Endif

		'### Draw the Frame around the Textfield
		SetAlpha Alpha
		If bEditing = True
			SetColor 0,255,0
		Else
			SetColor 75,75,75
		Endif
		Drw_Rect(X,Y,W,H,1)

		'### Reset The MAtrix
		If Angle <> 0.0
			ResetMatrix()
		Endif
	End Method

	#rem
		This Method is deprecatded.
		It will be deleted in ver 1.1
	#end
	Method drawFull()
		SetAlpha 1
		SetColor 255,255,255
		DrawRect(X+W*0.15,Y,W,H)

		If bEditing = True
			SetColor 0,255,0
		Else
			SetColor 255,0,0
		Endif

		DrawImage DUKE_IMG_EDITICON,X,Y,0,(W*0.15)/DUKE_IMG_EDITICON.Width(),(H*1.0)/DUKE_IMG_EDITICON.Height()

		SetColor 0,0,0
		DUKE_FONT.Wrap(inputString,X+W*0.15,Y,W,H,Duke_MessageCount)

		If bEditing = True
			SetColor 0,255,0
		Else
			SetColor 255,0,0
		Endif
		Duke_Drw_Rect(X,Y,W,H,3)
	End Method

	Method getText:String()
		Return inputString
	End Method

	Method setText(itext:String)
		inputString = itext
	End Method

	Method setAlpha(_Value:Float)
		Alpha = _Value
	End Method

	Method setWrapHeight(_Bool:Bool = True)
		bWrapHeight = _Bool
	End Method

	Method setBackgroundColor:Void(_Color:Int)
		ColorBackground = _Color
	End Method

	Method setCaption(_Text:String)
		Caption = _Text
	End Method
End Class

Const ALIGNMENT_LEFT:Int = 1
Const ALIGNMENT_MIDDLE:Int = 2
Const ALIGNMENT_RIGHT:Int = 3
Const ALIGNMENT_TOP:Int = 4
Const ALIGNMENT_MIDDLEY:int = 5
Const ALIGNMENT_BOTTOM:Int = 6

Const ANIM_DROP:Int 	= 1
Const ANIM_FADE:Int		= 2
Const ANIM_ROTATE:Int 	= 3
Const ANIM_ROLL:Int		= 4
Const ANIM_SLIDE:Int 	= 5
Const ANIM_CIRCLE:Int	= 6
Const ANIM_POPOUT:Int 	= 7

#Rem monkeydoc
	This Class is a Button Gui Element.
	Version 0.1
	Example:

		Global tB:ManiacButton = new ManiacButton(100,100,300,32)

		Function Main:Int()
			New Example
			Return 0
		End Function

#end
Class ManiacButton

	'Identificanitional Values
	Private
	Field ID:Int
	Field maniacID:Int
	Field MidX:Float,MidY:Float			'aktuelle Position des Buttons (Durch Animationen veränderbar
	Field oX:Float,oY:Float 		'Original X,Y << Das ist die Feste Position des Buttons
	Field Width:Float,Height:Float			'Breite und Höhe in Pxl

	'
	Field Caption:String		'Aufschrift
	Field CaptionColor:Int		'Color of the Caption
	Field Angle:Float 			'Winkel zur Horizontalen in °
	Field Alignment:Int			'ausrichtung des Textes (Left,Middle,Right)
	Field bTransparent:Bool = false
	Field bVisible:Bool 	= True

	'#### EFFECTS STUFF ####
	'Field

	'#### GLOW STUFF #####		Ready
	Field bGlow:Bool							'Wenn true, dann leuchtet der Button
	Field GlowHertz:Float 			= 0.5
	Field GlowAlpha:Float 						'Current Alpha for Glow Effect
	Field GlowAlphaFrom:Float		= 0.01		'Range for Alpha-Effekt.
	Field GlowAlphaTo:Float			= 0.3
	Field GlowStyle:Int				= 0			'0 - If Alpha reases max, it decreases from max ; 1 - if Alpha reaches max, it jumps to min
	Field bCurrGlowDirection:Bool 				'True - Raise, false - decrease
	Field GlowColor:Int
	Field GlowRangeRatioX:Float = 1.3
	Field GlowRangeRatioY:Float = 1.7

	'#### FRAME STUFF ######
	Field bFramed:Bool 		= True
	Field FrameColor:Int
	Field FrameType:Int 	= 0
	Field FrameThickness:Int = 1

	Field Color:Int 							'Integerwert einer Farbe aus der Maniac_Color Funktion

	'#### BUTTON MOUSEOVER STUFF #####
	Field bMO:Bool = False
	Field bMOResize:Bool 		= false
	Field bMOBrighter:Bool 		= false
	Field bMOWobble:Bool		= false
	Field AddWidthByMO:Int 		= 0
	Field AddHeightByMO:Int		= 0

	'##### BUTTON INACTIVE-ANIMATIONS #######
	Field bInactiveAnim:Bool = False
	Field bInactiveTime:Int
	Field InactiveAnim:Int
	Field LastActiveTime:Int

	'##### WOBBLEEFFEKT STUFF #####
	Field lastWobble:Int

	'##### ANIMATION STUFF #####
	Field bRunningAnimation:Bool 	= False
	Field AnimStartTime:int
	Field AnimTime:int

	'Tweener for position Stuff
	Field tweenY:Tween
	Field tweenX:Tween
	Field tweenAngle:Tween

	'Booleans for Effect
	Field AnimEffect:Int

	Public
	Method New(_MidX:Float,_MidY:Float,_Width:Float,_Height:Float,_Caption:String = "",_Alignment:Int = ALIGNMENT_MIDDLE,_Color:Int = COLOR_BLUE,_Glow:Bool = True,_GlowHertz:Float = 1,_Angle:Float = 0.0)
		If MANIAC_DEBUG = True
			Maniac_Debug.addStoredBools(9)
			Maniac_Debug.addStoredInts(12)
			Maniac_Debug.addStoredFloats(13)
			ID 		= Maniac_Debug.getNumberOfRegisteredObjects()
			Maniac_Debug.addRegisteredObject()
		Endif
		oX 		= _MidX
		oY		= _MidY
		MidX 	= _MidX
		MidY 	= _MidY
		Width 	= _Width
		Height 	= _Height
		Alignment =_Alignment
		Caption =	_Caption
		CaptionColor = _Color +6
		Color		= _Color
		bGlow 		= _Glow
		GlowHertz	= _GlowHertz
		GlowColor = _Color
		Angle = _Angle
		FrameColor = _Color +6
	End Method

	Method Draw:int()
		If MANIAC_DEBUG = True
			Maniac_Debug.addRenderedObject()
		Endif

		If bVisible = False
			Return -1
		Endif
		If Angle <> 0.0
			RotateAt(MidX,MidY, Angle)
		Endif

		'##### GLOW EFFECT STUFF #####
		If bGlow = True
			Maniac_Color(GlowColor)
			SetAlpha GlowAlpha
			DrawImage MANIAC_IMG_FRAME_BLUR, MidX,MidY,0,Width*GlowRangeRatioX/MANIAC_IMG_FRAME_BLUR.Width(),Height*GlowRangeRatioY/MANIAC_IMG_FRAME_BLUR.Height()
			Maniac_Debug.addTotDraws(1)
		End If

		'##### BUTTON BACKGROUND #####
		Maniac_Color(Color)
		If bTransparent = True
			If bMO = True
				SetAlpha 1
				If bMOResize = True
					AddWidthByMO = 10
					AddHeightByMO = 10
				Else
					AddWidthByMO = 0
					AddHeightByMO = 0
				Endif
			Else
				AddWidthByMO = 0
				AddHeightByMO = 0
				SetAlpha 0.6
			Endif
		Else
			SetAlpha 1
			If bMO = True
				If bMOResize = True
					AddWidthByMO = 10
					AddHeightByMO = 10
				Else
					AddWidthByMO = 0
					AddHeightByMO = 0
				Endif
			Else
				AddWidthByMO = 0
				AddHeightByMO = 0
			Endif
		Endif
		DrawRect(MidX- (Width +AddWidthByMO/2)/2,MidY-(Height+AddHeightByMO/2)/2,Width+AddWidthByMO,Height+AddHeightByMO)
		Maniac_Debug.addTotDraws(1)

		'###### BUTTON FRAME ########
		If bFramed = True
			If FrameType = 0
				Maniac_Color(FrameColor)
				DrawImage MANIAC_IMG_FRAME_RAW , MidX,MidY,0,(Width+AddWidthByMO)/MANIAC_IMG_FRAME_RAW.Width(),(Height+AddHeightByMO)/MANIAC_IMG_FRAME_RAW.Height()
				Maniac_Debug.addTotDraws(1)
			Elseif FrameType = 1
				Maniac_Color(FrameColor)
				Drw_Rect(MidX-Width/2+AddWidthByMO,MidY-Height/2,Width,Height,FrameThickness)
			Endif
		Else

		Endif

		'##### DRAWING THE CAPTION TO THE BUTTON #####
		SetAlpha 1
		Maniac_Color(CaptionColor)
		Select Alignment
			Case ALIGNMENT_LEFT
				MANIAC_FONT.Wrap(Caption,MidX-Width/2,MidY-Height/5,Width,Height,Caption.Length())
				ResetMatrix()
			Case ALIGNMENT_MIDDLE
				Local l:Int = MANIAC_FONT.getW(Caption)
				MANIAC_FONT.Wrap(Caption,MidX-l/2+1,MidY-Height/5,Width,Height,Caption.Length())
				ResetMatrix()
			Case ALIGNMENT_RIGHT
				Local l:Int = MANIAC_FONT.getW(Caption)
				MANIAC_FONT.Wrap(Caption,MidX+Width/2-l,MidY-Height/5,Width,Height,Caption.Length())
				ResetMatrix()
		End Select

		If bTransparent = False
			If bMO = True
				If bMOBrighter = True
					SetAlpha 0.2
					SetColor 255,255,255
					DrawRect(MidX- (Width +AddWidthByMO/2)/2,MidY-(Height+AddHeightByMO/2)/2,Width+AddWidthByMO,Height+AddHeightByMO)
					Maniac_Debug.addTotDraws(1)
				Endif
			Else
				'SetAlpha 0.6
			Endif

		Endif

		'### Reset The MAtrix
		If Angle <> 0.0
			ResetMatrix()
		Endif
	End Method

	Method Update:Int()
		If MANIAC_DEBUG = True
			'Maniac_Debug.addCalc()
			Maniac_Debug.addCall()
		Endif

		'### Updating Glow Effect ###
		'this will have effect to all Animation & Non Animation stuff.
		If bGlow = True
			If bCurrGlowDirection = True
				GlowAlpha += EqToFPS(GlowHertz)
				If GlowAlpha >= GlowAlphaTo
					bCurrGlowDirection = False
				Endif
			Else
				GlowAlpha -= EqToFPS(GlowHertz)
				If GlowAlpha <= GlowAlphaFrom
					bCurrGlowDirection = true
				Endif
			Endif
		Endif

		'### Animation Effects ###
		If bRunningAnimation = True

			'Check if AnimationTime is Over
			If Millisecs() - AnimStartTime > AnimTime
				bRunningAnimation = False
			Endif

			'If not, calculate the next Position Stuff
			Select AnimEffect
				Case ANIM_DROP
					tweenY.Update()
					MidY = tweenY.Value()
				Case ANIM_FADE
				Case ANIM_ROTATE
				Case ANIM_ROLL
					tweenX.Update()
					tweenAngle.Update()
					Angle = tweenAngle.Value()
					MidX = tweenX.Value()
				Case ANIM_SLIDE
					tweenX.Update()
					MidX = tweenX.Value()

				Case ANIM_CIRCLE
					tweenY.Update()
					tweenX.Update()

					MidX = tweenX.Value()
					MidY = tweenY.Value()
			End Select

		Endif

		'### User Input Stuff like MouseOver, ClickOn etc. ###
		If MOBox(MidX-Width/2	, MidY-Height/2, Width, Height)
			bMO = True
			If bMOWobble = True
				doWobble()
			Endif
			If TouchHit()
				Return 99
			Endif
			Return 101
		Else
			bMO = False
			If bRunningAnimation = False
				resetPosition()
			Endif
		Endif
	End Method

	Method startAnim(_AnimType:Int,  fromX:Float ,toX:Float ,_AnimTime:Int = 1000,ias:Float = 720,iae:Float = 0)

	End Method

	Method startAnimDrop(_fromY:Float,_AnimTime:Int = 1500,_Style:String = "Bounce",_Ease:String = "Out")

		tweenY = ll_Tween(_Style,_Ease,_fromY,oY,_AnimTime )
		tweenY.Start()
		bRunningAnimation = True
		AnimStartTime = Millisecs()
		AnimTime = _AnimTime
		AnimEffect = ANIM_DROP
	End Method

	Method startAnimRoll(_fromX:Float,_AnimTime:Int = 3000,_NumberRounds:Float = 10,_Style:String = "Bounce",_Ease:String = "Out")
		tweenX = ll_Tween(_Style,_Ease,_fromX,oX,_AnimTime )
		tweenX.Start()
		tweenAngle = ll_Tween(_Style,_Ease,_NumberRounds*(360),0,_AnimTime )
		tweenAngle.Start()
		bRunningAnimation = True
		AnimStartTime = Millisecs()
		AnimTime = _AnimTime
		AnimEffect = ANIM_ROLL
	End Method

	Method startAnimSlide(_fromX:Float,_AnimTime:Int = 1500,_Style:String = "Bounce",_Ease:String = "Out")
		tweenX = ll_Tween(_Style,_Ease,_fromX,oX,_AnimTime )
		tweenX.Start()
		bRunningAnimation = True
		AnimStartTime = Millisecs()
		AnimTime = _AnimTime
		AnimEffect = ANIM_SLIDE
	End Method

	Method startAnimCircle(_fromX:Float,_fromY:Float,_AnimTime:Int = 5000)
		tweenX = New Tween(Tween.Sine.EaseOut,_fromX,oX,_AnimTime)
		tweenX.Start()
		tweenY = New Tween(Tween.Sine.EaseInOut,_fromY,oY,_AnimTime)
		tweenY.Start()
		bRunningAnimation = True
		AnimStartTime = Millisecs()
		AnimTime = _AnimTime
		AnimEffect = ANIM_CIRCLE
	End Method

	Method startAnimPopOut()

	End Method
	Method setAlignment(_Alignment:Int)

		'Checking for using right Alignment Convention, else set to ALIGNMENT_MIDDLE
		Select _Alignment
			Case ALIGNMENT_LEFT
				Alignment = _Alignment
			Case ALIGNMENT_MIDDLE
				Alignment = _Alignment
			Case ALIGNMENT_RIGHT
				Alignment = _Alignment
			Default
				Print "Alignment doesnt exist, Set To Middle!!!"
				Alignment =	ALIGNMENT_MIDDLE
		End Select
	End Method

	Method setCaption(_Caption:String,_Color:int)
		Caption = _Caption
		CaptionColor = _Color
	End Method

	Method setPosition(_X:float,_Y:float)
		MidX = _X
		MidY = _Y
	End Method

	Method setSize(_Width:Float,_Height:Float)
		Width = _Width
		Height =_Height
	End Method

	Method setAngle:Void(_Angle:Float)
		Angle = _Angle
	End Method

	#Rem monkeydoc
		This Method sets the current Glow Effect.

		to switch Glow effect off, just call

		Example:

			'To Switch Off, just call within OnUpdate()
			 objName.setGlow(false)

			 'To Specify the Glow effect, use the params:~n
			 _isGlowing << true - glow is active, else it doesnt render glow effect ~n
			 _GlowColor << use one of the Maniac preset Color Ints.
			 _GlowHertz << 1.0 means it raises 100% Alpha within 1 Second ; 0.5 means it need 2 Seconds

			 _GlowStyle	<< at the Moment just Style 0 implemented (Standard)

	#End
	Method setGlow(_isGlowing:Bool = True ,_GlowColor:Int = COLOR_WHITE ,_GlowHertz:Float = 1.0,_GlowAlphaFrom:Float = 0.2,_GlowAlphaTo:Float = 0.7,_GlowStyle:Int = 0)
		bGlow 		= _isGlowing
		GlowHertz	= _GlowHertz
		GlowColor 	= _GlowColor
		GlowAlphaFrom 	= _GlowAlphaFrom
		GlowAlphaTo 	= _GlowAlphaTo
		GlowStyle = _GlowStyle
	End Method

	Method setFrame(_isFramed:Bool = True,_FrameColor:Int = 0,_FrameType:Int=0,_FrameThickness:Int =1)
		bFramed = _isFramed
		FrameColor = _FrameColor
		FrameType = _FrameType
		FrameThickness = _FrameThickness
	End Method

	Method setMouseOverEffects(_isResizing:Bool= True ,_isBrightening:Bool=False,_isWobbling:Bool = false )
		bMOResize		= _isResizing
		bMOBrighter		= _isBrightening
		bMOWobble		= _isWobbling
	End Method

	Method setInactiveAnim()

	End Method

	Method doWobble(_ShakeDistance:Float = 3.5,_Hertz:Float = 60,_Strength:Float = 0.9)
		If MANIAC_DEBUG = True
			'Maniac_Debug.addCalc()
			Maniac_Debug.addCall()
		Endif
		If Millisecs()-lastWobble >= (1000 / _Hertz)
			lastWobble = Millisecs()
			MidX += Rnd(-_Strength,_Strength)
			MidY += Rnd(-_Strength,_Strength)

			If MidX > (oX+_ShakeDistance)
				MidX = oX+_ShakeDistance
			Endif
			If MidX < (oX-_ShakeDistance)
				MidX = oX-_ShakeDistance
			Endif
			If MidY > (oY+_ShakeDistance)
				MidY = oY+_ShakeDistance
			Endif
			If MidY < (oY-_ShakeDistance)
				MidY = oY-_ShakeDistance
			Endif
		Endif

	End Method

	#rem
		### This Method is deprecated!!! Please don't use it in Future. Use startAnimRoll instead It's just for backward compatibatibility ####
	#end
	Method doRoll(_AngleSpeed:Float)
		If MANIAC_DEBUG = True
			'Maniac_Debug.addCalc()
			Maniac_Debug.addCall()
		Endif
		Angle += EqToFPS(_AngleSpeed)
	End Method

	Method doRotate(_AngleSpeed:Float)
		If MANIAC_DEBUG = True
			Maniac_Debug.addCall()
		Endif
		Angle += EqToFPS(_AngleSpeed)
	End Method

	Method resetPosition()
		If MANIAC_DEBUG = True
			'Maniac_Debug.addCalc()
			Maniac_Debug.addCall()
		Endif
		MidX = oX
		MidY = oY
		Angle = 0
	End Method

	Method setVisible(_Bool:Bool)
		bVisible = _Bool
	End Method
End Class

#Rem monkeydoc
	This Class is a Slider Gui Element.
	Version 1.0 (a) Stable but unhandy
	Example:

		'This Example Shows how to use the Slider
		Global slider:ManiacSlider

		'... OnCreate
		slider =  new ManiacSlider(100,100,300,32,25,75)

		'... OnUpdate()
		slider.Update()
		local val:float = slider.getValue()

		'...OnRender()
		slider.Draw()

#End
Class ManiacSlider
	Private
	Field maniacID:Int
	Field X:Float,Y:Float,Width:Float,Height:Float

	Field SliderX:Float

	Field Value:Float
	Field ValueFrom:Float
	Field ValueTo:Float
	Field ValueStep:Float

	Field HoldPicker:Bool = True

	Public
	#Rem monkeydoc
		This is the Constructor for the Slider
		_X & _Y are topleft-Corner Koordinates in Pxl~n
		_Width & _Height are the rectangular size of the Slider in Pxl~n
		_ValueFrom - sets the lowest Return-Value
		_ValueTo	- sets the Maximum Return Value
	#End
	Method New(_X:Float,_Y:Float,_Width:Float,_Height:Float,_ValueFrom:Float = 0,_ValueTo:Float = 100)
		Maniac_Debug.addStoredBools()
		Maniac_Debug.addStoredInts()
		Maniac_Debug.addStoredFloats(9)
		maniacID = Maniac_Debug.getNumberOfRegisteredObjects()
		Maniac_Debug.addRegisteredObject()

		X = _X
		Y = _Y
		Width = _Width
		Height= _Height
		ValueFrom = _ValueFrom
		ValueTo = _ValueTo
		SliderX = _X + _Width*0.5
	End Method

	#Rem monkeydoc
		This Method returns the Current Value of Slider.
	#End
	Method getValue:Float()
		Maniac_Debug.addTotCall()
		Maniac_Debug.addTotCalc(2)
		'Maniac_Debug.addTotDraws()
		Local p:Float = (SliderX - X) / (X+Width-X)
		Local val:Float =  ValueFrom + (ValueTo-ValueFrom)*p

		Return val
	End Method

	#Rem monkeydoc
		This Method Draws the whole Slider with Picker.
	#End
	Method Draw()
		Maniac_Debug.addTotCall()
		'Maniac_Debug.addTotCalc(2)
		Maniac_Debug.addTotDraws(2)
		SetAlpha 1
		SetColor 255,255,255
		DrawImage MANIAC_IMG_SLIDERLINE,X,Y,0,Width/MANIAC_IMG_SLIDERLINE.Width(),Height/MANIAC_IMG_SLIDERLINE.Height()

		If HoldPicker = True
			SetColor 0,255,0
			DrawText "Value: " + getValue(),X,Y+Height
		Endif
		DrawImage MANIAC_IMG_SLIDERPICKER,SliderX,Y+Height*0.5,0,(Width*0.1)/MANIAC_IMG_SLIDERPICKER.Width(),(Height*1.2)/MANIAC_IMG_SLIDERPICKER.Height()
	End Method

	#Rem monkeydoc
		This Method Updates the Slider. Especially the Picker and his X-Value.
		It checks for User-Slider for its own.
	#End
	Method Update()
		Maniac_Debug.addTotCall()
		HoldPicker = False
		If TouchDown()
			If MOBox( SliderX-(Width*0.1)/2,  Y,  (Width*0.1), (Height*1.2))
				HoldPicker = True
				SliderX = MouseX()
				If SliderX >= X+Width
					SliderX = X+Width
				Endif
				If SliderX <= X
					SliderX = X
				Endif
			Endif
		Endif
	End Method
End Class

#Rem monkeydoc
	This Class is a GalleryViewer Gui Element.
	Version 0.1
	Example:

		Global tB:ManiacButton = new ManiacButton(100,100,300,32)

		Function Main:Int()
			New Example
			Return 0
		End Function

#End
Class ManiacGallery	Implements IOnLoadImageComplete
	Global loadedImages:Int =	0
	Global l:Int = 0

	Field arrImg:Image[500]
	Field maniacID:Int
	Field X:Float,Y:Float,Width:Float,Height:Float
	Field ViewMode:Int = 1
	Field dist:Int = 10
	Field imgW:Float,imgH:Float

	Field BtnRight:ManiacButton
	Field BtnLeft:ManiacButton
	Field BtnSwitchViewStyle:ManiacButton

	Field ScrolledImages:Int = 0

	Field tp:Int	= 0
	Field lastSwitch:Int
	Field switchIntervall:Int = 500

	Field Alpha:float

	Method New(_X:Float,_Y:Float,_Width:Float,_Height:Float,_loadPath:String = "GFX/")
		'arrImg[
		X = _X
		Y = _Y
		Width =_Width
		Height = _Height
		loadFromPath(_loadPath)
		Local bW:Float = DW*0.15
		Local bH:Float = DH*0.07
		imgW = ll_Width(_Width,3,dist)
		imgH = (_Height-bH)/2.5

		BtnLeft 			=  New ManiacButton(_X + bW/2 + _Width*0.02 ,_Y+_Height-bH/2, bW,	bH," << ",ALIGNMENT_MIDDLE,COLOR_BLUE,True,1.5)
		BtnRight 			=  New ManiacButton(_X + _Width - bW/2 - _Width*0.02 ,_Y+_Height-bH/2, bW,	bH," >> ",ALIGNMENT_MIDDLE,COLOR_BLUE,True,1.5)
		BtnSwitchViewStyle 	=  New ManiacButton(_X + _Width*0.5 ,_Y+_Height-bH/2, bW,	bH," Switch ",ALIGNMENT_MIDDLE,COLOR_BLUE,True,1.5)

	End Method

	Method loadFromPath:Void(_Path:String="monkey://external/" )
		'Local stdPath:String
		#rem
		If _Path.Contains("monkey://external/")

		Elseif _Path.Contains("monkey://data/")
		Elseif _Path.Contains("monkey://internal/")
			stdPath = "monkey://internal/"
		Else
			stdPath = "monkey://external/"+_Path
		Endif
		#end
		Print "Get Folder"
		Local arrStr:String[] = GetFolderFiles(_Path)
		Print "Found: " + arrStr.Length() + " files"
		l = arrStr.Length()
		#rem
		If arrStr.Length() > 0
			For Local j:Int = 0 Until loadedImages'arrStr.Length()
				Print "Loading Image " + arrStr[j] + " to arrImg["+(j)+"]"
				arrImg[j] = LoadImage()
			Next
		Endif
		#end
		For Local ls:Int = 0 Until l
			Print "load " + ls
			LoadImageAsync(arrStr[ls], 1, 0, Self)
		Next
	End Method

	Method Draw()
		Drw_Rect(X,Y,Width,Height,3)
		SetColor 255,255,255
		SetAlpha 1
		Select ViewMode
			Case 0	'3x2 overview
				Local i:Int = 0
				For Local x:Int = 0 To 2
					For Local y:Int = 0 To 1
						Drw_Rect(X+dist+x*(imgW+dist)  , Y+dist+y*(imgH+dist), imgW,imgH,2)
						'Print "i: " + i
						if arrImg[i+ScrolledImages] = Null
							DrawText "No Image",X+dist+x*(imgW+dist)  , Y+dist+y*(imgH+dist)
						Else
							DrawImage ( arrImg[i+ScrolledImages] , X+dist+x*(imgW+dist)  , Y+dist+y*(imgH+dist),0, imgW/arrImg[i+ScrolledImages].Width(), imgH/arrImg[i+ScrolledImages].Height() )
						Endif
						i +=1
					Next
				Next

			Case 1
				If arrImg[tp] <> Null
					SetAlpha 1
					DrawImage arrImg[tp], X,Y,0,Width*1/arrImg[tp].Width(),Height*0.87/arrImg[tp].Height()
				Endif
				If arrImg[tp+1] <> Null
					SetAlpha Alpha
					DrawImage arrImg[tp+1], X,Y,0,Width*1/arrImg[tp+1].Width(),Height*0.87/arrImg[tp+1].Height()
				Endif
		End Select

		BtnLeft.Draw()
		BtnRight.Draw()
		BtnSwitchViewStyle.Draw()

		DrawText("Mode: " + ViewMode+ " | View: " + tp + "/"+loadedImages , X +Width*0.5,Y)
	End Method

	Method Update:Int()

		If BtnLeft.Update() = 101 And gl_mousereleased
			if ScrolledImages <= 0

			Else
				ScrolledImages -= 1
			Endif
		Endif

		If BtnRight.Update() = 101 And gl_mousereleased
			If (ScrolledImages + 6) >= loadedImages

			else
				ScrolledImages += 1
			Endif
		Endif

		If BtnSwitchViewStyle.Update() = 101 And gl_mousereleased
			If ViewMode = 0
				ViewMode = 1
			Else
				ViewMode = 0
			Endif
		Endif

		Select ViewMode
			Case 0
			Case 1
				If Millisecs() - lastSwitch >= switchIntervall
					If (tp + 1) >= loadedImages
						tp = 0
					else
						tp +=1
					Endif
					Alpha = 0
					lastSwitch = Millisecs()
				Endif

				Alpha += EqToFPS(1.0/(switchIntervall/1000.0))' 0.02
		End Select
	End Method

	Method OnLoadImageComplete:Void(_image:Image, path:String, source:IAsyncEventSource)
		If _image <> Null
			arrImg[loadedImages] = _image
			loadedImages += 1
		Else
			Print "no image : "+loadedImages
		Endif

		#rem
		arrImg[loadedImages] = _image
		Print "Loaded Image id: " + loadedImages
		If arrImg[loadedImages] = Null
			Print "no image : "+loadedImages
		Else
			Maniac_Debug.addRegisteredGraphics()
		Endif
		loadedImages += 1
		#end
	End

	Method getNumberOfLoadedImages:Int()

	End Method

	Method getImageByID:Image(_ID:Int)

	End Method

End class

#Rem monkeydoc
	This Class is a RadioGroup Gui Element.

	Example:

		Global tB:ManiacButton = new ManiacButton(100,100,300,32)

		Function Main:Int()
			New Example
			Return 0
		End Function

#End
Class ManiacRadioGroup
	Field X:Int,Y:Int,Width:Int,Height:Int
	Field bFramed:Bool = true
	Field listElements:List<RadioElement>
	Field dist:Float = 8
	Field ActiveElementID:Int
	Field Caption:String

	Method New(x:Int,y:Int,w:Int,h:Int,caption:String = "")
		X = x
		Y = y
		Width = w
		Height = h
		Caption = caption
		listElements = New List<RadioElement>
	End Method

	Method Draw()
    For Local oRE:RadioElement = Eachin listElements
      oRE.Draw()
    Next
	End Method

	Method addChoice(_Caption:String,_Value:Int)
   		Local oRE:RadioElement = New RadioElement(_Caption,_Value)
    	oRE.ID = listElements.Count()
		listElements.AddLast(oRE)
		reOrder()
	End Method

	Method getActiveElementValue:Int()
	    For Local oRE:RadioElement = Eachin listElements
	      If oRE.isActive()
	        Return oRE.Value
	      Endif
	    Next
	End Method

	Method Update:Void()
	    Local newClickID:Int = 0
	    'Check for Clicking on a RadioElement
	    For Local oRE:RadioElement = Eachin listElements
	      If oRE.Update() <> -1
	        setActiveElement(oRE.ID)
	      Endif
	    Next
	End Method

	Method setActiveElement:Void(_ID:Int)
	    For Local oRE:RadioElement = Eachin listElements
	      If oRE.ID = _ID
	        oRE.setActive(True)
	      Else
	        oRE.setActive(False)
	      Endif
	    Next
	End Method

	Private
	Method reOrder()
	    Local eW:Float = ll_Width(Width,listElements.Count(),10)

	    Local i:Int = 0
	    For Local oRE:RadioElement = Eachin listElements
	    	oRE.setPosition(X + 10 + i*eW/2.0, Y + Height*0.5, eW/2,eW/2)
	    	i +=1
	    Next
	End Method
End Class

Private
Class RadioElement
  	Field ID:Int
	Field Caption:String
	Field Value:Int
	Field X:Float,Y:Float,Width:Float,Height:Float
	Field bActive:Bool

	Method New(_Caption:String,_Value:int)
		Caption =_Caption
		Value =_Value
	End Method

	Method Draw()
    	'Drawing the Selectable Circle
    	Drw_Ellipsis( X, Y, Width, Height)
	End Method

	Method setPosition(_X:Float, _Y:Float, _Width:Float,_Height:Float)
	    X = _X
	    Y = _Y
	    Width  = _Width
	    Height = _Height
	End Method

	Method Update:Int()
    	If MOCircle(X,Y,Width)
     		If gl_mousereleased
        		Return ID
     		Endif
    	Endif
    	Return -1
	End Method

	Method setActive(_isActive:Bool = True)
   		bActive = _isActive
	End Method
End Class
public

#Rem monkeydoc
	This Class is a CheckBox Gui Element.
	Version 0.1
	Example:

		Global tB:ManiacButton = new ManiacButton(100,100,300,32)

		Function Main:Int()
			New Example
			Return 0
		End Function

#End
Class ManiacCheckBox
	Field maniacID:Int
	Field X:Float
	Field Y:Float
	Field Width:Float
	Field Height:Float
	Field bChecked:Bool
	Field Caption:String

	Method New(_X:Float,_Y:Float,_Width:Float,_Height:Float,_Caption:String="")
		Maniac_Debug.addStoredBools(1)
		Maniac_Debug.addStoredInts(1)
		Maniac_Debug.addStoredFloats(4)
		maniacID 		= Maniac_Debug.getNumberOfRegisteredObjects()
		Maniac_Debug.addRegisteredObject()
		X 		= _X
		Y		= _Y
		Width 	= _Width
		Height 	= _Height
		Caption =	_Caption
	End Method

	Method Draw()
		Drw_Rect(X,Y,Width,Height,2)

		If bChecked = True
			DrawImage MANIAC_IMG_CHECK ,X ,Y ,0 , Width/MANIAC_IMG_CHECK.Width() , Height/MANIAC_IMG_CHECK.Height()
		Endif
	End Method

	Method Update()
		If TouchHit()
		If MOBox(X,Y, Width, Height)
			If bChecked = True
				bChecked = False
			Else
				bChecked = True
			Endif
		Endif
		Endif
	End Method

	Method getChecked:Bool()
		Return bChecked
	End Method
End Class

Class ManiacFileExplorer

End Class

private
Class textElement
	Field Caption:String
	Field Line:Int

	Method New(_Caption:String="")
		Caption =_Caption
	End Method
	Method Draw(_X:Float,_Y:Float,_Width:Float,_Height:Float)
		MANIAC_FONT.Wrap(Caption,_X,_Y,_Width,_Height,Caption.Length())
	End Method
End Class

public
#Rem monkeydoc
	This Class is a DropDown Gui Element.
	Version 0.1

	Example:

		Global tf:ManiacSimpleTextfield = new ManiacSimpleTextfield(100,100,300,32)
		Function Main:Int()
			New Example
			Return 0
		End Function

#End
Class ManiacDropDown
	Field maniacID:Int
	Field X:Float
	Field Y:Float
	Field Width:Float
	Field Height:Float
	Field bOpened:Bool
	Field Caption:String

	Field showOpenHeader:Int	= 1		'0 - Always Show Caption, 1 - Show MouseOver Elements , 2 - Show Selected Element
	Field showCloseHeader:Int 	= 2
	Field bCloseOnSelected:Bool = True

	Field ShowLines:Int 	= 4
	Field ScrolledLines:Int = 0
	Field listTextElements:List<textElement>
	Field MOElement:Int
	Field SelectedElement:Int = 0

	Field tweenY:Tween

	Method New(_X:Float,_Y:Float,_Width:Float,_Height:Float,_Caption:String="")
		Maniac_Debug.addStoredBools(1)
		Maniac_Debug.addStoredInts(1)
		Maniac_Debug.addStoredFloats(4)
		maniacID 		= Maniac_Debug.getNumberOfRegisteredObjects()
		Maniac_Debug.addRegisteredObject()
		X 		= _X
		Y		= _Y
		Width 	= _Width
		Height 	= _Height
		Caption =	_Caption
		listTextElements = New List<textElement>
	End Method

	Method addLine(_Caption:String)
		Local oL:textElement = New textElement(_Caption)
		oL.Line = listTextElements.Count()

		listTextElements.AddLast(oL)

	End Method

	Method DrawText()
		For Local oL:textElement = Eachin listTextElements
			oL.Draw(X+5,Y+Height+oL.Line*(27+5),200,100)
		Next
	End Method

	Method animOpen()
		tweenY = ll_Tween(_Style,_Ease,_fromY,oY,_AnimTime )
		tweenY.Start()
	End Method

	Method animClose()

	End Method

	Method Draw()

		If bOpened = True
			Drw_Rect(X,Y,Width,Height,2)
			Drw_Rect(X,Y+Height,Width,Height+ShowLines*(MANIAC_FONT.getH()+5),1)
			DrawText()

			Select showOpenHeader
				Case 0
					MANIAC_FONT.Wrap(Caption,X,Y,Width,Height,Caption.Length())
				Case 1
					MANIAC_FONT.Wrap(getTextByID(MOElement),X,Y,Width,Height,Caption.Length())
				Case 2
					MANIAC_FONT.Wrap(getTextByID(SelectedElement),X,Y,Width,Height,Caption.Length())
			End Select

			DrawImage MANIAC_IMG_DROPDOWN , X+Width*0.9,Y, 0 , (Width*0.1)/MANIAC_IMG_DROPDOWN.Width(),Height/MANIAC_IMG_DROPDOWN.Height()
		Else
			Drw_Rect(X,Y,Width,Height,2)

			Select showCloseHeader
				Case 0
					MANIAC_FONT.Wrap(Caption,X,Y,Width,Height,Caption.Length())
				Case 1
					MANIAC_FONT.Wrap(getTextByID(MOElement),X,Y,Width,Height,Caption.Length())
				Case 2
					MANIAC_FONT.Wrap(getTextByID(SelectedElement),X,Y,Width,Height,Caption.Length())
			End Select

			DrawImage MANIAC_IMG_DROPDOWN , X+Width*0.9,Y, 0 , (Width*0.1)/MANIAC_IMG_DROPDOWN.Width(),Height/MANIAC_IMG_DROPDOWN.Height()
		Endif
	End Method

	Method Update()
		If TouchHit()
		If MOBox(X+Width*0.9,Y, Width*0.1, Height)
			If bOpened = True
				bOpened = False
			Else
				bOpened = True
			Endif
		Endif
		Endif
		MOElement = -1
		If bOpened
			For Local i:Int = 0 Until ShowLines
				If MOBox(X,Y+Height+i*(27+5),Width,27)
					MOElement = i
					If TouchHit()
						SelectedElement = i
						If bCloseOnSelected = True
							bOpened = False
						Endif
					Endif
				Endif
			Next
		Endif
	End Method

	Method getTextByID:String(_ID:Int)
		Local i:Int = 0
		For Local oL:textElement = Eachin listTextElements
			If i = _ID
				Return oL.Caption
			Endif
			i +=1
		Next
	End Method

	Method getSelectedText:String()
		Local i:Int = 0
		For Local oL:textElement = Eachin listTextElements
			If i = SelectedElement
				Return oL.Caption
			Endif
			i +=1
		Next
	End Method

End Class

#Rem monkeydoc
	This Class is a ListView Gui Element.
	You can Add Lines of Strings and Scroll them within this View.
	Version 0.1

	Example:

		Global tf:ManiacSimpleTextfield = new ManiacSimpleTextfield(100,100,300,32)
		Function Main:Int()
			New Example
			Return 0
		End Function

#End
Class ManiacListView
	Field maniacID:Int
	Field X:Float,Y:Float,Width:Float,Height:Float
	Field listText:List<textElement>

	Field nrLines:Int
	Field ScrolledLine:Int = 0

	Method New(_X:Float,_Y:Float,_Width:Float,_Height:Float)
		nrLines = _Height/32
		X = _X
		Y = _Y
		Width =_Width
		Height = _Height
		listText = New List<textElement>
	End Method

	Method Draw()
		Drw_Rect(X,Y,Width,Height,2)

		For Local i:Int = 0 Until nrLines
			MANIAC_FONT.Wrap(getText(i+ScrolledLine),X+5,Y+5+i*(27+5),Width,Height,40)
		Next

		SetAlpha 1
		DrawImage MANIAC_IMG_ARROWDOWN,X,Y+Height+5,0,Width/MANIAC_IMG_ARROWDOWN.Width(),48.0/MANIAC_IMG_ARROWDOWN.Height()
	End Method

	Method Update()
		If TouchHit()
			If MOBox(X,Y+Height+5,Width,48)
				ScrolledLine +=1
			Endif
		Endif
	End Method

	Method addLine(_Line:String)
		Local oL:textElement = New textElement(_Line)
		listText.AddLast(oL)
	End Method

	Private
	Method getText:String(_ID:Int)
		Local i:Int = 0
		For Local oL:textElement = Eachin listText
			If i = _ID
				Return oL.Caption
			Endif
			i +=1
		Next
	End Method
End Class

Class ManiacDialog
	Field X:Float,Y:Float,Width:Float,Height:Float
	Field Question:String
	Field Alpha:Float = 0.8
	Field bVisible:Bool = True

	Field Btn_Ja:ManiacButton
	Field Btn_Nein:ManiacButton

	Method New(_X:Float,_Y:Float,_Width:Float,_Height:Float,_Question:String ="")
		X = _X
		Y = _Y
		Width =_Width
		Height = _Height
		Question = _Question

		Btn_Ja = New ManiacButton(X+_Width*0.75,Y+_Height*0.8,_Width*0.4,	_Height*0.25,"Ja",ALIGNMENT_MIDDLE,COLOR_BLUE,True,0.2)
		Btn_Nein = New ManiacButton(X+_Width*0.25,Y+_Height*0.8,_Width*0.4,	_Height*0.25,"Nein",ALIGNMENT_MIDDLE,COLOR_BLUE,True,0.2)
	End Method

	Method Draw()
		If bVisible = True
			SetColor 0,0,0
			SetAlpha Alpha
			DrawRect(X,Y,Width,Height)

			SetAlpha 1
			SetColor 255,255,255
			MANIAC_FONT.Wrap(Question,X+Width*0.05,Y+15,Width*0.9,Height,350)

			Btn_Ja.Draw()
			Btn_Nein.Draw()
		Endif
	End Method

	Method Update:Int()
		If Btn_Ja.Update() = 101
			Return 2
		Elseif Btn_Nein.Update() = 101
			Return 1
		Else
			Return 0
		Endif
	End Method

	Method setVisible(_bVisible:Bool = True)
		bVisible = _bVisible
	End Method
End Class

private
Class ManiacAnimRect
	'Identificanitional Values
	Field ID:Int
	Field maniacID:Int
	Field MidX:Float,MidY:Float			'aktuelle Position des Buttons (Durch Animationen veränderbar
	Field oX:Float,oY:Float 		'Original X,Y << Das ist die Feste Position des Buttons
	Field Width:Float,Height:Float			'Breite und Höhe in Pxl
	Field oWidth:Float,oHeight:Float

	'
	Field Caption:String		'Aufschrift
	Field Angle:Float 			'Winkel zur Horizontalen in °
	Field AlignX:Int			'ausrichtung des Textes (Left,Middle,Right)
	Field AlignY:int

	Method setPosition(_X:float,_Y:float)
		MidX = _X
		MidY = _Y
	End Method

	Method setSize(_Width:Float,_Height:Float)
		Width = _Width
		Height =_Height
	End Method

	Method reSize(_Scale:Float = 1.0)
		ScaleAt(MidX,MidY, _Scale, _Scale)
	End Method

End Class
Class ManiacSimpleTextfield
	Private
	Field ID:Int
	Field inputString:String = ""
	Field X:Int,Y:Int
	Field W:Int,H:int

	Field Style:Int
	Field Focus:Int		'0 - Standard ohne gfx effects , 1 -

	Field bEditing:Bool = False

	Public
	Method New(_X:Float,_Y:Float,_Width:Float,_Height:Float,istyle:Int = TEXTFIELD_STYLE_STD)
		ID 		= Maniac_Debug.getNumberOfRegisteredObjects()
		X 		= _X
		Y 		= _Y
		W 		= _Width
		H 		= _Height
		Style 	= istyle
		Maniac_Debug.addRegisteredObject()
	End Method

	Public
	Method update:Int()
		If bFull = True
			If TouchHit()
				If MOBox(X,Y,(W*0.15),(H*1.0))
					If bEditing = True
						bEditing = False
					Else
						bEditing = True
					Endif
				Endif
			Endif
		Endif

		If bEditing = True
			Repeat
				Local char=GetChar()
		        If Not char Exit

		        If char>=32
		            inputString+=String.FromChar( char )
		        Endif

		        If char = CHAR_ENTER
					DisableKeyboard()
					Return 99
				Endif

		        If char = CHAR_BACKSPACE
					Local txtlength:Int = inputString.Length()
					Local txtchars:Int[] = inputString.ToChars
					inputString = ""
					For Local l:Int = 0 To txtlength-2
						inputString += String.FromChar(txtchars[l])
					Next
				Endif

			Forever
		Endif
	End Method

	Public
	Method draw()
		DrawText inputString,X,Y
	End Method

	Method getText:String()
		Return inputString
	End Method

	Method setText(itext:String)
		inputString = itext
	End Method
End Class


Unused variable removed

Unused variable removed

Strict

Private

Import bono.kernel
Import bono.graphics
Import bono.utils
Import carousel
Import carouselhandler
Import carouselrenderer
Import mojo

Public

Class CarouselRendererSimple Implements CarouselRenderer, TouchObserver
    Private

    Field touched:Bool
    Field offset:Vector2D = New Vector2D()
    Field carousel:Carousel
    Field lastItemPixelX:Float
    Field momentumX:Float
    Field touchMovement:Float
    Field touchTime:Int
    Field offsetMaxX:Float
    Field firstItem:Int
    Field lastItem:Int

    Public

    Field padding:Vector2D = New Vector2D()
    Field maxMoveDistanceForClicks:Float = 3
    Field frictionCoefficient:Float = 0.8

    Method SetCarousel:Void(carousel:Carousel)
        Self.carousel = carousel
    End

    Method Recalculate:Void()
        Local nextPos:Vector2D = carousel.GetPosition().Copy()
        nextPos.Add(padding)

        For Local item:BaseDisplayObject = EachIn carousel.GetItems()
            Local oldHeight:Float = item.GetSize().y
            item.GetSize().y = carousel.GetSize().y - (padding.y * 2)

            Local heightScaleFactor:Float = item.GetSize().y / oldHeight
            item.GetSize().x = item.GetSize().x * heightScaleFactor

            item.SetPosition(nextPos.Copy())
            nextPos.x += item.GetSize().x
            nextPos.x += padding.x
        End

        lastItemPixelX = carousel.GetItems().Last().GetPosition().x
        lastItemPixelX += carousel.GetItems().Last().GetSize().x

        offsetMaxX = carousel.GetPosition().x + carousel.GetSize().x
        offsetMaxX -= lastItemPixelX
        offsetMaxX -= padding.x
    End

    Method GetPosition:Float()
        If firstItem = 1 Then Return 0.0

        Local totalItems:Int = carousel.GetItems().Count()
        If lastItem = totalItems Then Return 1.0

        Local currentItem:Float = firstItem + ((lastItem - firstItem) / 2.0)
        Return currentItem / totalItems
    End

    Method OnRender:Void()
        ApplyMomentum()

        Local pos:Vector2D = carousel.GetPosition()
        Local size:Vector2D = carousel.GetSize()

        Local oldScissor:Float[] = GetScissor()
        MatrixHelper.SetScissorRelative(pos, size)

        firstItem = carousel.GetItems().Count()
        lastItem = 0

        PushMatrix()
            Translate(offset.x, offset.y)

            Local counter:Int = 0
            For Local item:BaseDisplayObject = EachIn carousel.GetItems()
                counter += 1

                Local itemPosX:Float = item.GetPosition().x
                itemPosX += offset.x

                If itemPosX > pos.x + size.x Then Continue
                If itemPosX + item.GetSize().x < pos.x Then Continue

                item.OnRender()
                firstItem = Min(firstItem, counter)
                lastItem = Max(lastItem, counter)
            End
        PopMatrix()

        SetScissor(oldScissor[0], oldScissor[1], oldScissor[2], oldScissor[3])
    End

    Method OnTouchDown:Void(event:TouchEvent)
        touched = True
        momentumX = 0
        touchMovement = 0
    End

    Method OnTouchMove:Void(event:TouchEvent)
        If Not touched Then Return
        offset.x += event.prevDelta.x
        CheckOffsetBoundaries()

        If event.positions.Count() = 0 Then Return
        If event.prevDelta.x = 0 Then Return

        touchMovement += event.prevDelta.x
        touchTime = event.endTime
    End

    Method OnTouchUp:Void(event:TouchEvent)
        If Not touched Then Return
        touched = False

        If event.startDelta.Length() < maxMoveDistanceForClicks
            Local item:BaseDisplayObject = GetTouchedItem(event)
            If Not item Then Return

            Local handler:CarouselHandler = CarouselHandler(item)
            If Not handler Then Return

            handler.OnCarouselSelect()
        Else
            If (Millisecs() - touchTime) < 50 And Abs(touchMovement) > 10
                Local duration:Float = event.endTime - event.startTime
                Local distance:Float = event.startDelta.x
                momentumX = distance / duration * 30
            End
        End
    End

    Private

    Method ApplyMomentum:Void()
        If Abs(momentumX) = 0 Then Return

        offset.x += momentumX
        CheckOffsetBoundaries()

        momentumX *= frictionCoefficient
        If Abs(momentumX) <= 0.05 Then momentumX = 0
    End

    Method CheckOffsetBoundaries:Void()
        offset.x = Min(0.0, offset.x)
        offset.x = Max(offsetMaxX, offset.x)
    End

    Method GetTouchedItem:BaseDisplayObject(event:TouchEvent)
        ' Offset is negative and we need to use Sub() here instead of Add()
        Local checkPos:Vector2D = event.pos.Copy().Sub(offset)

        For Local item:BaseDisplayObject = EachIn carousel.GetItems()
            If item.Collide(checkPos) Then Return item
        End

        Return Null
    End
End

Strict

Private

Import bono.kernel
Import bono.graphics
Import bono.utils
Import carousel
Import carouselhandler
Import carouselrenderer
Import mojo

Public

Class CarouselRendererSimple Implements CarouselRenderer, TouchObserver
    Private

    Field touched:Bool
    Field offset:Vector2D = New Vector2D()
    Field carousel:Carousel
    Field lastItemPixelX:Float
    Field momentumX:Float
    Field touchMovement:Float
    Field touchTime:Int
    Field offsetMaxX:Float
    Field firstItem:Int
    Field lastItem:Int

    Public

    Field padding:Vector2D = New Vector2D()
    Field maxMoveDistanceForClicks:Float = 3
    Field frictionCoefficient:Float = 0.8

    Method SetCarousel:Void(carousel:Carousel)
        Self.carousel = carousel
    End

    Method Recalculate:Void()
        Local nextPos:Vector2D = carousel.GetPosition().Copy()
        nextPos.Add(padding)

        For Local item:BaseDisplayObject = EachIn carousel.GetItems()
            Local oldHeight:Float = item.GetSize().y
            item.GetSize().y = carousel.GetSize().y - (padding.y * 2)

            Local heightScaleFactor:Float = item.GetSize().y / oldHeight
            item.GetSize().x = item.GetSize().x * heightScaleFactor

            item.SetPosition(nextPos.Copy())
            nextPos.x += item.GetSize().x
            nextPos.x += padding.x
        End

        lastItemPixelX = carousel.GetItems().Last().GetPosition().x
        lastItemPixelX += carousel.GetItems().Last().GetSize().x

        offsetMaxX = carousel.GetPosition().x + carousel.GetSize().x
        offsetMaxX -= lastItemPixelX
        offsetMaxX -= padding.x
    End

    Method GetPosition:Float()
        If firstItem = 1 Then Return 0.0

        Local totalItems:Int = carousel.GetItems().Count()
        If lastItem = totalItems Then Return 1.0

        Local currentItem:Float = firstItem + ((lastItem - firstItem) / 2.0)
        Return currentItem / totalItems
    End

    Method OnRender:Void()
        ApplyMomentum()

        Local pos:Vector2D = carousel.GetPosition()
        Local size:Vector2D = carousel.GetSize()

        Local oldScissor:Float[] = GetScissor()
        MatrixHelper.SetScissorRelative(pos, size)

        firstItem = carousel.GetItems().Count()
        lastItem = 0

        PushMatrix()
            Translate(offset.x, offset.y)

            Local counter:Int = 0
            For Local item:BaseDisplayObject = EachIn carousel.GetItems()
                counter += 1

                Local itemPosX:Float = item.GetPosition().x
                itemPosX += offset.x

                If itemPosX > pos.x + size.x Then Continue
                If itemPosX + item.GetSize().x < pos.x Then Continue

                item.OnRender()
                firstItem = Min(firstItem, counter)
                lastItem = Max(lastItem, counter)
            End
        PopMatrix()

        SetScissor(oldScissor[0], oldScissor[1], oldScissor[2], oldScissor[3])
    End

    Method OnTouchDown:Void(event:TouchEvent)
        touched = True
        momentumX = 0
        touchMovement = 0
    End

    Method OnTouchMove:Void(event:TouchEvent)
        If Not touched Then Return
        offset.x += event.prevDelta.x
        CheckOffsetBoundaries()

        If event.positions.Count() = 0 Then Return
        If event.prevDelta.x = 0 Then Return

        touchMovement += event.prevDelta.x
        touchTime = event.endTime
    End

    Method OnTouchUp:Void(event:TouchEvent)
        If Not touched Then Return
        touched = False

        If event.startDelta.Length() < maxMoveDistanceForClicks
            Local item:BaseDisplayObject = GetTouchedItem(event)
            If Not item Then Return

            Local handler:CarouselHandler = CarouselHandler(item)
            If Not handler Then Return

            handler.OnCarouselSelect()
        Else
            If (Millisecs() - touchTime) < 50 And Abs(touchMovement) > 10
                Local duration:Float = event.endTime - event.startTime
                Local distance:Float = event.startDelta.x
                momentumX = distance / duration * 30
            End
        End
    End

    Private

    Method ApplyMomentum:Void()
        If Abs(momentumX) = 0 Then Return

        offset.x += momentumX
        CheckOffsetBoundaries()

        momentumX *= frictionCoefficient
        If Abs(momentumX) <= 0.05 Then momentumX = 0
    End

    Method CheckOffsetBoundaries:Void()
        offset.x = Min(0.0, offset.x)
        offset.x = Max(offsetMaxX, offset.x)
    End

    Method GetTouchedItem:BaseDisplayObject(event:TouchEvent)
        Local result:BaseDisplayObject
        ' Offset is negative and we need to use Sub() here instead of Add()
        Local checkPos:Vector2D = event.pos.Copy().Sub(offset)

        For Local item:BaseDisplayObject = EachIn carousel.GetItems()
            If item.Collide(checkPos) Then Return item
        End

        Return Null
    End
End


monkey v66b fixes

monkey v66b fixes

Strict

Private

Import "native/objecthelper.${LANG}"

Extern

Class ObjectHelper Abstract
    Function Compare:Int(left:Object, right:Object)="ObjectHelper::Compare"
End

Strict

Private

Import "native/objecthelper.${LANG}"

Extern

Class ObjectHelper="ObjectHelper"
    Function Compare:Int(left:Object, right:Object)
End