1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276
|
-- -*-haskell-*-
-- GIMP Toolkit (GTK) Widget ColorSelection
--
-- Author : Duncan Coutts
--
-- Created: 2 August 2004
--
-- Copyright (C) 2004-2005 Duncan Coutts
--
-- This library is free software; you can redistribute it and/or
-- modify it under the terms of the GNU Lesser General Public
-- License as published by the Free Software Foundation; either
-- version 2.1 of the License, or (at your option) any later version.
--
-- This library is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-- Lesser General Public License for more details.
--
-- |
-- Maintainer : gtk2hs-users@lists.sourceforge.net
-- Stability : provisional
-- Portability : portable (depends on GHC)
--
-- A widget used to select a color
--
module Graphics.UI.Gtk.Selectors.ColorSelection (
-- * Detail
--
-- | The 'ColorSelection' is a widget that is used to select a color. It
-- consists of a color wheel and number of sliders and entry boxes for color
-- parameters such as hue, saturation, value, red, green, blue, and opacity. It
-- is found on the standard color selection dialog box 'ColorSelectionDialog'.
-- * Class Hierarchy
-- |
-- @
-- | 'GObject'
-- | +----'Object'
-- | +----'Widget'
-- | +----'Container'
-- | +----'Box'
-- | +----'VBox'
-- | +----ColorSelection
-- @
-- * Types
ColorSelection,
ColorSelectionClass,
castToColorSelection, gTypeColorSelection,
toColorSelection,
-- * Constructors
colorSelectionNew,
-- * Methods
colorSelectionGetCurrentAlpha,
colorSelectionSetCurrentAlpha,
colorSelectionGetCurrentColor,
colorSelectionSetCurrentColor,
colorSelectionGetHasOpacityControl,
colorSelectionSetHasOpacityControl,
colorSelectionGetHasPalette,
colorSelectionSetHasPalette,
colorSelectionGetPreviousAlpha,
colorSelectionSetPreviousAlpha,
colorSelectionGetPreviousColor,
colorSelectionSetPreviousColor,
colorSelectionIsAdjusting,
-- * Attributes
colorSelectionHasOpacityControl,
colorSelectionHasPalette,
colorSelectionCurrentAlpha,
colorSelectionPreviousAlpha,
) where
import Control.Monad (liftM)
import System.Glib.FFI
import System.Glib.Attributes
import Graphics.UI.Gtk.Abstract.Object (makeNewObject)
{#import Graphics.UI.Gtk.Types#}
import Graphics.UI.Gtk.General.Structs (Color)
{# context lib="gtk" prefix="gtk" #}
--------------------
-- Constructors
-- | Creates a new 'ColorSelection'.
--
colorSelectionNew :: IO ColorSelection
colorSelectionNew =
makeNewObject mkColorSelection $
liftM (castPtr :: Ptr Widget -> Ptr ColorSelection) $
{# call unsafe color_selection_new #}
--------------------
-- Methods
-- | Returns the current alpha value.
--
colorSelectionGetCurrentAlpha :: ColorSelectionClass self => self
-> IO Int -- ^ returns an integer between 0 and 65535.
colorSelectionGetCurrentAlpha self =
liftM fromIntegral $
{# call unsafe color_selection_get_current_alpha #}
(toColorSelection self)
-- | Sets the current opacity to be @alpha@. The first time this is called, it
-- will also set the original opacity to be @alpha@ too.
--
colorSelectionSetCurrentAlpha :: ColorSelectionClass self => self
-> Int -- ^ @alpha@ - an integer between 0 and 65535.
-> IO ()
colorSelectionSetCurrentAlpha self alpha =
{# call color_selection_set_current_alpha #}
(toColorSelection self)
(fromIntegral alpha)
-- | Gets the current color in the 'ColorSelection' widget.
--
colorSelectionGetCurrentColor :: ColorSelectionClass self => self -> IO Color
colorSelectionGetCurrentColor self =
alloca $ \colorPtr -> do
{# call unsafe color_selection_get_current_color #}
(toColorSelection self)
(castPtr colorPtr)
peek colorPtr
-- | Sets the current color to be @color@. The first time this is called, it
-- will also set the original color to be @color@ too.
--
colorSelectionSetCurrentColor :: ColorSelectionClass self => self
-> Color -- ^ @color@ - A 'Color' to set the current color with.
-> IO ()
colorSelectionSetCurrentColor self color =
with color $ \colorPtr ->
{# call color_selection_set_current_color #}
(toColorSelection self)
(castPtr colorPtr)
-- | Determines whether the 'ColorSelection' widget has an opacity control.
--
colorSelectionGetHasOpacityControl :: ColorSelectionClass self => self
-> IO Bool -- ^ returns @True@ if the color selector has an opacity control.
-- @False@ if it does't.
colorSelectionGetHasOpacityControl self =
liftM toBool $
{# call unsafe color_selection_get_has_opacity_control #}
(toColorSelection self)
-- | Sets the 'ColorSelection' widget to use or not use opacity.
--
colorSelectionSetHasOpacityControl :: ColorSelectionClass self => self
-> Bool -- ^ @hasOpacity@ - @True@ if color selector can set the opacity,
-- @False@ otherwise.
-> IO ()
colorSelectionSetHasOpacityControl self hasOpacity =
{# call color_selection_set_has_opacity_control #}
(toColorSelection self)
(fromBool hasOpacity)
-- | Determines whether the color selector has a color palette.
--
colorSelectionGetHasPalette :: ColorSelectionClass self => self
-> IO Bool -- ^ returns @True@ if the selector has a palette. @False@ if it
-- hasn't.
colorSelectionGetHasPalette self =
liftM toBool $
{# call unsafe color_selection_get_has_palette #}
(toColorSelection self)
-- | Sets whether to show or hide the palette.
--
colorSelectionSetHasPalette :: ColorSelectionClass self => self
-> Bool -- ^ @hasPalette@ - @True@ if palette is to be visible, @False@
-- otherwise.
-> IO ()
colorSelectionSetHasPalette self hasPalette =
{# call color_selection_set_has_palette #}
(toColorSelection self)
(fromBool hasPalette)
-- | Returns the previous alpha value.
--
colorSelectionGetPreviousAlpha :: ColorSelectionClass self => self
-> IO Int -- ^ returns an integer between 0 and 65535.
colorSelectionGetPreviousAlpha self =
liftM fromIntegral $
{# call unsafe color_selection_get_previous_alpha #}
(toColorSelection self)
-- | Sets the \'previous\' alpha to be @alpha@. This function should be called
-- with some hesitations, as it might seem confusing to have that alpha change.
--
colorSelectionSetPreviousAlpha :: ColorSelectionClass self => self
-> Int -- ^ @alpha@ - an integer between 0 and 65535.
-> IO ()
colorSelectionSetPreviousAlpha self alpha =
{# call color_selection_set_previous_alpha #}
(toColorSelection self)
(fromIntegral alpha)
-- | Returns the original color value.
--
colorSelectionGetPreviousColor :: ColorSelectionClass self => self -> IO Color
colorSelectionGetPreviousColor self =
alloca $ \colorPtr -> do
{# call unsafe color_selection_get_previous_color #}
(toColorSelection self)
(castPtr colorPtr)
peek colorPtr
-- | Sets the \'previous\' color to be @color@. This function should be called
-- with some hesitations, as it might seem confusing to have that color change.
-- Calling 'colorSelectionSetCurrentColor' will also set this color the first
-- time it is called.
--
colorSelectionSetPreviousColor :: ColorSelectionClass self => self
-> Color -> IO ()
colorSelectionSetPreviousColor self color =
with color $ \colorPtr ->
{# call color_selection_set_previous_color #}
(toColorSelection self)
(castPtr colorPtr)
-- | Gets the current state of the widget. Returns True if the user is currently
-- dragging a color around, and False if the selection has stopped.
--
colorSelectionIsAdjusting :: ColorSelectionClass self => self -> IO Bool
colorSelectionIsAdjusting self =
liftM toBool $
{# call unsafe color_selection_is_adjusting #}
(toColorSelection self)
--------------------
-- Attributes
-- | Whether the color selector should allow setting opacity.
--
-- Default value: @False@
--
colorSelectionHasOpacityControl :: ColorSelectionClass self => Attr self Bool
colorSelectionHasOpacityControl = newAttr
colorSelectionGetHasOpacityControl
colorSelectionSetHasOpacityControl
-- | Whether a palette should be used.
--
-- Default value: @False@
--
colorSelectionHasPalette :: ColorSelectionClass self => Attr self Bool
colorSelectionHasPalette = newAttr
colorSelectionGetHasPalette
colorSelectionSetHasPalette
-- | The current opacity value (0 fully transparent, 65535 fully opaque).
--
-- Allowed values: \<= 65535
--
-- Default value: 65535
--
colorSelectionCurrentAlpha :: ColorSelectionClass self => Attr self Int
colorSelectionCurrentAlpha = newAttr
colorSelectionGetCurrentAlpha
colorSelectionSetCurrentAlpha
-- | \'previousAlpha\' property. See 'colorSelectionGetPreviousAlpha' and
-- 'colorSelectionSetPreviousAlpha'
--
colorSelectionPreviousAlpha :: ColorSelectionClass self => Attr self Int
colorSelectionPreviousAlpha = newAttr
colorSelectionGetPreviousAlpha
colorSelectionSetPreviousAlpha
|