Color of a screen pixel: Difference between revisions

Content added Content deleted
Line 679: Line 679:


=={{header|FutureBasic}}==
=={{header|FutureBasic}}==
Tracks color information of the pixel under the current mouse coordinates.
Tracks color information of the pixel under the current mouse x/y coordinates.
<syntaxhighlight lang="futurebasic">
<syntaxhighlight lang="futurebasic">
_window = 1
_window = 1
begin enum 1
begin enum 1
_view
_view
_colorWell
_colorWell
_imageView
_imageView
end enum
end enum


void local fn BuildWindow
void local fn BuildWindow
window _window, @"ColorUnderMouse", (0,0,500,400), NSWindowStyleMaskTitled + NSWindowStyleMaskClosable
'~'1
view subclass _view, (0,0,500,300)
window _window, @"ColorUnderMouse", (0,0,500,400), NSWindowStyleMaskTitled + NSWindowStyleMaskClosable
colorwell _colorWell, YES, fn ColorWhite, ( 410, 310, 70, 70 ), NO, _window
view subclass _view, (0,0,500,300)
colorwell _colorWell, YES, fn ColorWhite, ( 410, 310, 70, 70 ), NO, _window
end fn
end fn


void local fn DrawRect
void local fn DrawRect
CFArrayRef array = @[fn ColorRed, fn ColorOrange, fn ColorYellow, fn ColorGreen, fn ColorBlue, fn ColorWithRGB(0,0.29,0.51,1), fn ColorWithRGB(0.58,0.0,0.83,1)]
'~'1
GradientRef grad = fn GradientWithColors( array )
CFArrayRef array = @[fn ColorRed, fn ColorOrange, fn ColorYellow, fn ColorGreen, fn ColorBlue, fn ColorWithRGB(0,0.29,0.51,1), fn ColorWithRGB(0.58,0.0,0.83,1)]
GradientDrawInRect( grad, fn ViewFrame(_view), 0 )
GradientRef grad = fn GradientWithColors( array )
GradientDrawInRect( grad, fn ViewFrame(_view), 0 )
end fn
end fn




void local fn DoMouse( tag as NSInteger )
void local fn DoMouse( tag as NSInteger )
CGPoint pt = fn EventLocationInView( tag )
'~'1
CGPoint pt = fn EventLocationInView( tag )
ColorRef color = fn ViewColorAtPoint( tag, pt )
ColorRef color = fn ViewColorAtPoint( tag, pt )
ColorWellSetColor( _colorWell, color )

ColorWellSetColor( _colorWell, color )
cls : printf @"%.0fx, %.0fy, %@", pt.x, pt.y, color

cls : printf @"%.0fx, %.0fy, %@", pt.x, pt.y, color
end fn
end fn


void local fn DoDialog( ev as long, tag as long )
void local fn DoDialog( ev as long, tag as long )
select ( tag )
'~'1
case _view
select ( tag )
select ( ev )
case _view
case _viewDrawRect : fn DrawRect
select ( ev )
case _viewMouseDown : fn DoMouse( tag )
case _viewDrawRect : fn DrawRect
case _viewMouseDown : fn DoMouse( tag )
case _viewMouseDragged : fn DoMouse( tag )
end select
case _viewMouseDragged : fn DoMouse( tag )
end select
end select
end select
select ( ev )

case _windowWillClose : end
select ( ev )
end select
case _windowWillClose : end
end select
end fn
end fn