Rebol Programming/request-color

From Wikibooks, open books for an open world
Jump to navigation Jump to search

USAGE:[edit | edit source]

REQUEST-COLOR /color clr /offset xy 

DESCRIPTION:[edit | edit source]

Requests a color value.

REQUEST-COLOR is a function value.

REFINEMENTS[edit | edit source]

  • /color
    • clr -- (Type: any)
  • /offset
    • xy -- (Type: any)

SOURCE CODE[edit | edit source]

request-color: func [
    "Requests a color value." 
    /color clr /offset xy /local result
][
    if none? :color-lay [
        color-lay: layout [
            across origin 5x4 space 8x2 
            x: box 80x30 ibevel return 
            t: field center middle 80 font-size 10 return 
            pad 8 
            r: slider 16x278 gray red effect [gradient 0x1 255.0.0 0.0.0] [setc 1 r/data] 
            g: slider 16x278 gray green effect [gradient 0x1 0.255.0 0.0.0] [setc 2 g/data] 
            b: slider 16x278 gray blue effect [gradient 0x1 0.0.255 0.0.0] [setc 3 b/data] 
            return 
            pad 8 btn-enter "OK" 64 [result: x/color hide-popup] 
            return 
            pad 8 btn-cancel "None" escape 64 [hide-popup]
        ]
    ] 
    x/color: either tuple? clr [clr] [0.0.0] 
    r/data: 1 - (x/color/1 / 255) 
    g/data: 1 - (x/color/2 / 255) 
    b/data: 1 - (x/color/3 / 255) 
    refresh 
    either offset [inform/offset color-lay xy] [inform color-lay] 
    result
]