Finding the RGB values of a field.

BlitzMax Forums/MaxGUI Module/Finding the RGB values of a field.

Ryan Burnside(Posted 2007) [#1]
Are there any ways to find the value of a panel object?

I'm making a paint program so it's very important. I have a list of panels as palette buttons and the user can ofcourse set the colors via a palette picker but I have no way to find what color they have chosen. I'd rather not create a whole new matching list to hold color objects if possible.





degac(Posted 2007) [#2]
RequestColor(r,g,b)?

Or you could use a Canvas and read the pixel's colour [edit: I found my little error Local x !=ax for the color box loop)


SuperStrict

Local MyWindow:TGadget=CreateWindow("Canvas Example", 200,200,320,240)
Local MyCanvas:TGadget=CreateCanvas(10,10,16*16,140,MyWindow)

Local x:Int=0
Local y:Int = 0
Local r:Int , g:Int , b:Int
local ax:int

ActivateGadget MyCanvas
Local rr:Int=0
Repeat
  WaitEvent()
  Select EventID()
  Case EVENT_WINDOWCLOSE
     End
  Case EVENT_MOUSEMOVE
     x=EventX()
     y=EventY()
     RedrawGadget(MyCanvas)
  Case EVENT_GADGETPAINT
    SetGraphics CanvasGraphics (MyCanvas)
 	rr=0
	For ax = 0 To ClientWidth(MyCanvas) / 16	
	SetColor rr , 0 , 0
	rr:+16
	DrawRect ax*15 , 0 , 15,ClientHeight(mycanvas)
	Next

	GetPixel(x,y,r,g,b)
	Print "R G B "+r+" "+g+" "+b+" XY "+x+" "+y
    Flip
 End Select
Until False

Function GetPixel(x:Int, y:Int, r:Int Var, g:Int Var, b:Int Var)
   Local TempPixmap:TPixmap = GrabPixmap(x,y,1,1)
   Local TempPtr:Byte Ptr = TempPixmap.PixelPtr(0,0)
   r = TempPtr[2]
   g = TempPtr[1]
   b = TempPtr[0]
End Function



Brucey(Posted 2007) [#3]
but I have no way to find what color they have chosen

Wouldn't it be better to keep an array of the colours, and then map that array to the panels ?

It's a wee bit more logical than driving the colours from the UI components.