RequestColor open 2 Times

BlitzMax Forums/BlitzMax GUI Programming/RequestColor open 2 Times

Hello,

i have some troubles with choosing colors from the RequestColor dialog. When i click on a Panel the ColorRequest opens 2 times.

Any hints?


SuperStrict
Import maxgui.drivers
Global ColorArray:Int[] = [$0000FF, $80FF00, $00FF00, $888888, $AAAAAA, $DDDDDD, $EEEEEE, $FFFFFF]
Local P:tPalette = New tPalette.Create(ColorArray)

While True
	WaitEvent
Wend

Type tPalette
	Global Win:tgadget
	Field Color:Int[]
	
	Method New()
		If Not Win Then
			Win = CreateWindow("Palette", 20, 20, 400, 80, Null, WINDOW_TOOL | WINDOW_TITLEBAR | WINDOW_STATUS)
		End If
		AddHook EmitEventHook, eventhook, Self
	End Method
	
	Function Create:tPalette(colors:Int[])
		Local P:tPalette = New tPalette
		p.Color = colors
		Local x:Int
		For Local C:Int = EachIn p.Color
			Local Pan:TGadget = CreatePanel(5 + x, 5, 20, 20, p.Win, PANEL_BORDER | PANEL_ACTIVE)
			x:+25
			Local RGB:Byte[] = Int2RGB(C)
			SetPanelColor(pan, rgb[0], rgb[1], rgb[2])
			SetGadgetExtra(pan, String(c))
			
			DebugLog rgb[0] + " " + rgb[1] + " " + rgb[2]
		Next
		Return P
	End Function
	
	
	Function eventhook:Object(iId:Int, TData:Object, tContext:Object)
		Local event:TEvent = TEvent(TData)
		Local Ob:tPalette = Self(tcontext)
		
		
		Select Event.id
			Case EVENT_WINDOWCLOSE
				'HideGadget(Self.Win)
				End
			Case EVENT_GADGETACTION
				Select Event.Source
				End Select
			Case EVENT_MOUSEMOVE
				'Farbe des Panels ausfindig machen
				Local p:TGadget = TGadget(event.source)
				SetStatusText(Self.Win, String(GadgetExtra(p)))
				
			Case EVENT_MOUSEDOWN
				DebugLog "Hier"
				Local red:Int
				Local green:Int
				Local blue:Int
				If RequestColor(red, green, blue)
					red = RequestedRed()
					green = RequestedGreen()
					blue = RequestedBlue()
					SetPanelColor TGadget(event.source), red, green, blue
				EndIf
			
		End Select
		Return event
	End Function
End Type

Function RGB2Int:Int(r:Int, g:Int, b:Int)
	Local RGB:Int = (R Shl 16) Or (G Shl 8) Or B
	Return RGB
End Function

Function Int2RGB:Byte[] (IntColor:Int)
	Local RGB:Byte[3]
	RGB[0] = (IntColor Shr 16)' And 255
	RGB[1] = (IntColor Shr 8) 'And 255
	RGB[2] = (IntColor) 'And 255
	Return RGB
End Function


Change this line:
Local P:tPalette = New tPalette.Create(ColorArray)
..to..
Local P:tPalette = tPalette.Create(ColorArray)

All your events were firing twice, not just the MOUSEDOWN one.

Hi Beaker,

many Thanks.

1. It Works
2. Many Troubles in my Main Programm are now = NULL

:-)