From: Andy S. <And...@co...> - 2010-04-03 06:20:49
|
Sat Apr 3 02:19:49 EDT 2010 Andy Stewart <laz...@gm...> * Add miscellaneous Gdk moudles, and fix some functions. Ignore-this: 18d0b99b5af657eaf226ab00ace57ff3 hunk ./ApiUpdateTodoList.txt 28 -*** TODO Border.chs +*** DONE Border.chs hunk ./ApiUpdateTodoList.txt 30 -*** TODO Builder.chs +*** DONE Builder.chs hunk ./ApiUpdateTodoList.txt 36 -*** TODO Color.chs -*** TODO Colormap.chs +*** DONE Color.chs +*** DONE Colormap.chs hunk ./ApiUpdateTodoList.txt 43 -*** TODO Device.chs +*** DONE Device.chs hunk ./ApiUpdateTodoList.txt 46 -*** TODO DragContext.chs +*** DONE DragContext.chs hunk ./ApiUpdateTodoList.txt 49 -*** TODO Drop.chs +*** DONE Drop.chs hunk ./ApiUpdateTodoList.txt 51 -*** TODO Error.chs -*** TODO Event.chs +*** DONE Error.chs +*** DONE Event.chs hunk ./ApiUpdateTodoList.txt 59 -*** TODO Global.chs +*** DONE Global.chs hunk ./ApiUpdateTodoList.txt 77 -*** TODO Keyboard.chs +*** DONE Keyboard.chs hunk ./ApiUpdateTodoList.txt 79 -*** TODO Keymap.chs +*** DONE Keymap.chs hunk ./ApiUpdateTodoList.txt 86 -*** TODO Notify.chs -*** TODO Offscreen.chs +*** DONE Notify.chs +*** DONE Offscreen.chs hunk ./ApiUpdateTodoList.txt 107 -*** TODO Pointer.chs +*** DONE Pointer.chs hunk ./ApiUpdateTodoList.txt 122 -*** TODO Property.chs -*** TODO Query.chs +*** DONE Property.chs +*** DONE Query.chs hunk ./ApiUpdateTodoList.txt 138 -*** TODO Rgb.chs +*** DONE Rgb.chs hunk ./ApiUpdateTodoList.txt 150 -*** TODO Spawn.chs +*** DONE Spawn.chs hunk ./ApiUpdateTodoList.txt 158 -*** TODO Threads.chs +*** DONE Threads.chs hunk ./Makefile.am 813 + gtk/Graphics/UI/Gtk/Gdk/Rgb.chs.pp \ + gtk/Graphics/UI/Gtk/Gdk/Colormap.chs.pp \ + gtk/Graphics/UI/Gtk/Gdk/Color.chs.pp \ + gtk/Graphics/UI/Gtk/Gdk/Device.chs.pp \ hunk ./gtk/Graphics/UI/Gtk.hs.pp 52 - module Graphics.UI.Gtk.Gdk.Keys, hunk ./gtk/Graphics/UI/Gtk.hs.pp 59 + module Graphics.UI.Gtk.Gdk.Keys, hunk ./gtk/Graphics/UI/Gtk.hs.pp 77 + module Graphics.UI.Gtk.Gdk.Rgb, + module Graphics.UI.Gtk.Gdk.Colormap, + module Graphics.UI.Gtk.Gdk.Color, + module Graphics.UI.Gtk.Gdk.Device, hunk ./gtk/Graphics/UI/Gtk.hs.pp 308 -import Graphics.UI.Gtk.Gdk.Keys hunk ./gtk/Graphics/UI/Gtk.hs.pp 316 +import Graphics.UI.Gtk.Gdk.Keys hunk ./gtk/Graphics/UI/Gtk.hs.pp 329 +import Graphics.UI.Gtk.Gdk.Rgb +import Graphics.UI.Gtk.Gdk.Colormap +import Graphics.UI.Gtk.Gdk.Color +import Graphics.UI.Gtk.Gdk.Device addfile ./gtk/Graphics/UI/Gtk/Gdk/Color.chs.pp hunk ./gtk/Graphics/UI/Gtk/Gdk/Color.chs.pp 1 +-- -*-haskell-*- +-- GIMP Toolkit (GTK) Widget Color +-- +-- Author : Andy Stewart +-- +-- Created: 2 Apr 2010 +-- +-- Copyright (C) 2010 Andy Stewart +-- +-- 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 : gtk...@li... +-- Stability : provisional +-- Portability : portable (depends on GHC) +-- +module Graphics.UI.Gtk.Gdk.Color ( +-- * Methods [_$_] + colorEqual, + colorHash, + colorToString, + ) where + +import Control.Monad (liftM) + +import System.Glib.FFI +import System.Glib.UTFString +import System.Glib.GObject (constructNewGObject, makeNewGObject) +{#import Graphics.UI.Gtk.Types#} +import Graphics.UI.Gtk.General.Structs (Color) + +{# context lib="gdk" prefix="gdk" #} + +-- | Compares two colors. +colorEqual :: Color -> Color -> IO Bool +colorEqual color1 color2 = + liftM toBool $ + with color1 $ \ color1Ptr -> [_$_] + with color2 $ \ color2Ptr -> [_$_] + {#call color_equal#} + (castPtr color1Ptr) + (castPtr color2Ptr) + +-- | A hash function suitable for using for a hash table that stores 'Color''s. +colorHash :: Color -> IO Int +colorHash color = + liftM fromIntegral $ [_$_] + with color $ \ colorPtr -> {#call color_hash#} (castPtr colorPtr) + +-- | Returns a textual specification of color in the hexadecimal form #rrrrggggbbbb, where r, g and b are +-- hex digits representing the red, green and blue components respectively. +colorToString :: Color -> IO String +colorToString color = + with color $ \ colorPtr -> [_$_] + {#call color_to_string#} (castPtr colorPtr) + >>= peekUTFString addfile ./gtk/Graphics/UI/Gtk/Gdk/Colormap.chs.pp hunk ./gtk/Graphics/UI/Gtk/Gdk/Colormap.chs.pp 1 +-- -*-haskell-*- +-- GIMP Toolkit (GTK) Widget Colormap +-- +-- Author : Andy Stewart +-- +-- Created: 2 Apr 2010 +-- +-- Copyright (C) 2010 Andy Stewart +-- +-- 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 : gtk...@li... +-- Stability : provisional +-- Portability : portable (depends on GHC) +-- +-- The following funtion not useful or just internal, don't bind: +-- gdk_colormap_ref [_$_] +-- gdk_colormap_unref +-- gdk_colormap_alloc_colors +-- gdk_colormap_alloc_color +-- gdk_colormap_free_colors +-- gdk_colormap_query_color +-- +module Graphics.UI.Gtk.Gdk.Colormap ( + +-- * Types + Colormap, + ColormapClass, + castToColormap, + toColormap, + +-- * Constructors + colormapNew, + +-- * Methods + colormapGetScreen, + colormapGetSystem, + colormapGetVisual, + ) where + +import Control.Monad (liftM) + +import System.Glib.FFI +import System.Glib.UTFString +import System.Glib.GObject (constructNewGObject, makeNewGObject) +{#import Graphics.UI.Gtk.Types#} + +{# context lib="gdk" prefix="gdk" #} + +-------------------- +-- Constructors + +-- | Creates a new colormap for the given visual. +colormapNew :: VisualClass visual => visual -> Bool -> IO Colormap +colormapNew visual allocate = + constructNewGObject mkColormap $ + {# call gdk_colormap_new #} + (toVisual visual) + (fromBool allocate) + +-------------------- +-- Methods +-- | Gets the screen for which this colormap was created. +colormapGetScreen :: Colormap -> IO Screen +colormapGetScreen self = + makeNewGObject mkScreen $ + {# call gdk_colormap_get_screen #} + self + +-- | Gets the system's default colormap for the default screen. (See +-- 'colormapGetSystemForScreen' +colormapGetSystem :: IO Colormap +colormapGetSystem = + makeNewGObject mkColormap $ + {# call gdk_colormap_get_system #} + +-- | Returns the visual for which a given colormap was created. +colormapGetVisual :: Colormap -> IO Visual +colormapGetVisual self = + makeNewGObject mkVisual $ + {# call gdk_colormap_get_visual #} + self addfile ./gtk/Graphics/UI/Gtk/Gdk/Device.chs.pp hunk ./gtk/Graphics/UI/Gtk/Gdk/Device.chs.pp 1 +-- -*-haskell-*- +-- GIMP Toolkit (GTK) Widget Device +-- +-- Author : Andy Stewart +-- +-- Created: 2 Apr 2010 +-- +-- Copyright (C) 2010 Andy Stewart +-- +-- 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 : gtk...@li... +-- Stability : provisional +-- Portability : portable (depends on GHC) +-- +-- +module Graphics.UI.Gtk.Gdk.Device ( + +-- * Details +-- | In addition to the normal keyboard and mouse input devices, GTK+ also contains support for extended +-- input devices. In particular, this support is targeted at graphics tablets. Graphics tablets +-- typically return sub-pixel positioning information and possibly information about the pressure and +-- tilt of the stylus. Under X, the support for extended devices is done through the XInput extension. +-- [_$_] +-- Because handling extended input devices may involve considerable overhead, they need to be turned on +-- for each 'Window' individually using 'inputSetExtensionEvents'. (Or, more typically, for +-- 'Widgets', using 'widgetSetExtensionEvents'. As an additional complication, depending on +-- the support from the windowing system, its possible that a normal mouse cursor will not be displayed +-- for a particular extension device. If an application does not want to deal with displaying a cursor +-- itself, it can ask only to get extension events from devices that will display a cursor, by passing +-- the 'ExtensionEventsCursor' value to 'inputSetExtensionEvents'. Otherwise, the +-- application must retrieve the device information using 'devicesList', check the @hasCursor@ +-- field, and, if it is 'False', draw a cursor itself when it receives motion events. +-- [_$_] +-- Each pointing device is assigned a unique integer ID; events from a particular device can be +-- identified by the deviceid field in the event structure. The events generated by pointer devices +-- have also been extended to contain pressure, xtilt and ytilt fields which contain the extended +-- information reported as additional valuators from the device. The pressure field is a a double value +-- ranging from 0.0 to 1.0, while the tilt fields are double values ranging from -1.0 to 1.0. (With +-- -1.0 representing the maximum tilt to the left or up, and 1.0 representing the maximum tilt to the +-- right or down.) +-- [_$_] +-- One additional field in each event is the source field, which contains an enumeration value +-- describing the type of device; this currently can be one of 'SourceMouse', 'SourcePen', +-- 'SourceEraser', or 'SourceCursor'. This field is present to allow simple applications to (for +-- instance) delete when they detect eraser devices without having to keep track of complicated +-- per-device settings. +-- [_$_] +-- Various aspects of each device may be configured. The configuration of devices is queried using +-- 'devicesList', which also controls +-- whether the device's range is mapped to the entire screen or to a single window. The mapping of the +-- valuators of the device onto the predefined valuator types is set using +-- 'deviceSetAxisUse'. And the source type for each device can be set with +-- 'deviceSetSource'. +-- [_$_] +-- Devices may also have associated keys or macro buttons. Such keys can be globally set to map into +-- normal X keyboard events. The mapping is set using 'deviceSetKey'. +-- [_$_] +-- The interfaces in this section will most likely be considerably modified in the future to accomodate +-- devices that may have different sets of additional valuators than the pressure xtilt and ytilt. + +-- * Types + Device, + DeviceClass, + castToDevice, + toDevice, + TimeCoord, + +-- * Methods + devicesList, + deviceFreeHistory, + deviceGetAxis, + deviceGetCorePointer, + deviceGetHistory, + deviceGetState, + deviceSetAxisUse, + deviceSetKey, + deviceSetMode, + deviceSetSource, + inputSetExtensionEvents, + ) where + +import Control.Monad (liftM) + +import System.Glib.FFI +import System.Glib.GList +import System.Glib.Flags +import System.Glib.UTFString +import System.Glib.GObject (constructNewGObject, makeNewGObject) +import Graphics.UI.Gtk.Gdk.Enums (InputSource(..), InputMode(..), ExtensionMode(..), AxisUse(..), Modifier(..)) +{#import Graphics.UI.Gtk.Types#} + +{# context lib="gdk" prefix="gdk" #} + +-------------------- +-- types +-- | The 'TimeCoord' structure stores a single event in a motion history. It contains the following +-- fields: +{#pointer *TimeCoord newtype#} + +-------------------- +-- Methods + +-- | Returns the list of available input devices for the default display. The list is statically +-- allocated and should not be freed. +devicesList :: IO [Device] +devicesList = do + glist <- {#call devices_list#} + mapM (makeNewGObject mkDevice . return) =<< fromGList glist + +-- | Frees an array of 'TimeCoord' that was returned by 'deviceGetHistory'. +-- [_$_] +-- Frees an array of 'TimeCoord' that was returned by 'deviceGetHistory'. +deviceFreeHistory :: [TimeCoord] -> Int -> IO () +deviceFreeHistory events nEvents = + withArray (map (\(TimeCoord x) -> x) events) $ \eventsPtr -> + {# call gdk_device_free_history #} + (castPtr eventsPtr) + (fromIntegral nEvents) + +-- | Interprets an array of double as axis values for a given device, and locates the value in the array +-- for a given axis use. +deviceGetAxis :: DeviceClass self => self -> AxisUse -> IO (Maybe (Double, Double)) +deviceGetAxis self use = + alloca $ \axesPtr -> + alloca $ \valuePtr -> do + success <- liftM toBool $ + {# call gdk_device_get_axis #} + (toDevice self) + axesPtr + ((fromIntegral . fromEnum) use) + valuePtr + if success [_$_] + then do + axes <- peek axesPtr + value <- peek valuePtr + return (Just (realToFrac axes, realToFrac value)) + else return Nothing + +-- | Returns the core pointer device for the default display. +deviceGetCorePointer :: IO Device +deviceGetCorePointer = + makeNewGObject mkDevice $ + {# call gdk_device_get_core_pointer #} + +-- | Obtains the motion history for a device; given a starting and ending timestamp, return all events in +-- the motion history for the device in the given range of time. Some windowing systems do not support +-- motion history, in which case, 'False' will be returned. (This is not distinguishable from the case +-- where motion history is supported and no events were found.) +deviceGetHistory :: DeviceClass self => self -> DrawWindow -> Word32 -> Word32 -> IO (Maybe ([TimeCoord], Int)) +deviceGetHistory self window start stop = + allocaArray 0 $ \ eventsPtr -> [_$_] + alloca $ \nEventsPtr -> do + success <- liftM toBool $ + {# call gdk_device_get_history #} + (toDevice self) + window + (fromIntegral start) + (fromIntegral stop) + eventsPtr + nEventsPtr + if success [_$_] + then do + events_ <- peekArray 0 eventsPtr + let events = map TimeCoord events_ + nEvents <- peek nEventsPtr + return (Just (events, fromIntegral nEvents)) + else return Nothing + +-- | Gets the current state of a device. +deviceGetState :: DeviceClass self => self -> DrawWindow -> IO ([Double], Modifier) +deviceGetState self window = + allocaArray 0 $ \axesPtr -> + alloca $ \modifierPtr -> do + {# call gdk_device_get_state #} + (toDevice self) + window + axesPtr + modifierPtr + axes <- peekArray 0 axesPtr + modifier <- peek modifierPtr + return ((map realToFrac axes), (toEnum (fromIntegral modifier))) + +-- | Specifies how an axis of a device is used. +deviceSetAxisUse :: DeviceClass self => self -> Int -> AxisUse -> IO () +deviceSetAxisUse self index use = + {# call gdk_device_set_axis_use #} + (toDevice self) + (fromIntegral index) + ((fromIntegral . fromEnum) use) + +-- | Specifies the X key event to generate when a macro button of a device is pressed. +deviceSetKey :: DeviceClass self => self -> Int -> Int -> [Modifier] -> IO () +deviceSetKey self index keyval modifiers = + {# call gdk_device_set_key #} + (toDevice self) + (fromIntegral index) + (fromIntegral keyval) + ((fromIntegral . fromFlags) modifiers) + +-- | Sets a the mode of an input device. The mode controls if the device is active and whether the +-- device's range is mapped to the entire screen or to a single window. +deviceSetMode :: DeviceClass self => self -> InputMode -> IO Bool +deviceSetMode self mode = + liftM toBool $ + {# call gdk_device_set_mode #} + (toDevice self) + ((fromIntegral . fromEnum) mode) + +-- | Sets the source type for an input device. +deviceSetSource :: DeviceClass self => self -> InputSource -> IO () +deviceSetSource self source = + {# call gdk_device_set_source #} + (toDevice self) + ((fromIntegral . fromEnum) source) + +-- | Turns extension events on or off for a particular window, and specifies the event mask for extension +-- events. +inputSetExtensionEvents :: DrawWindow -> Int -> ExtensionMode -> IO () +inputSetExtensionEvents window mask mode = + {#call input_set_extension_events#} + window + (fromIntegral mask) + ((fromIntegral . fromEnum) mode) + hunk ./gtk/Graphics/UI/Gtk/Gdk/Enums.chs.pp 57 + InputSource(..), + InputMode(..), + AxisUse(..), hunk ./gtk/Graphics/UI/Gtk/Gdk/Enums.chs.pp 292 + +-- | An enumeration describing the type of an input device in general terms. +{#enum InputSource {underscoreToCase} deriving (Bounded,Eq,Show)#} + +-- | An enumeration that describes the mode of an input device. +{#enum InputMode {underscoreToCase} deriving (Bounded,Eq,Show)#} + +-- | An enumeration describing the way in which a device axis (valuator) maps onto the predefined +-- valuator types that GTK+ understands. +{#enum AxisUse {underscoreToCase} deriving (Bounded,Eq,Show)#} addfile ./gtk/Graphics/UI/Gtk/Gdk/Rgb.chs.pp hunk ./gtk/Graphics/UI/Gtk/Gdk/Rgb.chs.pp 1 +-- -*-haskell-*- +-- GIMP Toolkit (GTK) Widget Rgb +-- +-- Author : Andy Stewart +-- +-- Created: 2 Apr 2010 +-- +-- Copyright (C) 2010 Andy Stewart +-- +-- 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 : gtk...@li... +-- Stability : provisional +-- Portability : portable (depends on GHC) +-- +-- +module Graphics.UI.Gtk.Gdk.Rgb ( +-- * Types + RgbCmap, + +-- * Methods + rgbCmapNew, + drawRgbImage, + drawRgbImageDithalign, + drawIndexedImage, + drawGrayImage, + drawRgb32Image, + drawRgb32ImageDithalign, + rgbColormapDitherable, + rgbDitherable, + rgbFindColor, + rgbGetColormap, + rgbGetVisual, + rgbSetInstall, + rgbSetMinColors, + rgbSetVerbose, + ) where + +import Control.Monad (when, liftM) + +import System.Glib.FFI +import System.Glib.UTFString +import System.Glib.GObject (constructNewGObject) +{#import Graphics.UI.Gtk.Types#} +import Graphics.UI.Gtk.General.Structs +import Graphics.UI.Gtk.General.Enums + +{# context lib="gdk" prefix="gdk" #} + +-------------------- +-- Types +{#pointer *RgbCmap newtype#} + +-------------------- +-- Methods + +-- | Draws an RGB image in the drawable. This is the core 'RGB' function, and likely the only one you +-- will need to use. +-- [_$_] +-- The rowstride parameter allows for lines to be aligned more flexibly. For example, lines may be +-- allocated to begin on 32-bit boundaries, even if the width of the rectangle is odd. Rowstride is +-- also useful when drawing a subrectangle of a larger image in memory. Finally, to replicate the same +-- line a number of times, the trick of setting rowstride to 0 is allowed. +-- [_$_] +-- In general, for 0 <= i < width and 0 <= j < height, the pixel (x + i, y + j) is colored with red +-- value @rgbBuf@[j * rowstride + i * 3], green value @rgbBuf@[j * rowstride + i * 3 + 1], and blue value +-- @rgbBuf@[j * rowstride + i * 3 + 2]. +drawRgbImage :: DrawableClass drawable => drawable -> GC -> Int -> Int -> Int -> Int -> Dither -> String -> Int -> IO () +drawRgbImage drawable gc x y width height dith buf rowstride = + withUTFString buf $ \ bufPtr -> [_$_] + {#call draw_rgb_image#} + (toDrawable drawable) + gc + (fromIntegral x) + (fromIntegral y) + (fromIntegral width) + (fromIntegral height) + ((fromIntegral . fromEnum) dith) + (castPtr bufPtr) + (fromIntegral rowstride) + +-- | Draws an RGB image in the drawable, with an adjustment for dither alignment. +-- [_$_] +-- This function is useful when drawing dithered images into a window that may be scrolled. Pixel (x, +-- y) will be drawn dithered as if its actual location is (x + xdith, y + ydith). Thus, if you draw an +-- image into a window using zero dither alignment, then scroll up one pixel, subsequent draws to the +-- window should have ydith = 1. +-- [_$_] +-- Setting the dither alignment correctly allows updating of small parts of the screen while avoiding +-- visible "seams" between the different dither textures. +drawRgbImageDithalign :: DrawableClass drawable => drawable -> GC -> Int -> Int -> Int -> Int -> Dither -> String -> Int -> Int -> Int -> IO () +drawRgbImageDithalign drawable gc x y width height dith buf rowstride xdith ydith = + withUTFString buf $ \ bufPtr -> [_$_] + {#call draw_rgb_image_dithalign#} + (toDrawable drawable) + gc + (fromIntegral x) + (fromIntegral y) + (fromIntegral width) + (fromIntegral height) + ((fromIntegral . fromEnum) dith) + (castPtr bufPtr) + (fromIntegral rowstride) + (fromIntegral xdith) + (fromIntegral ydith) + +-- | Draws an indexed image in the drawable, using a 'RgbCmap' to assign actual colors to the color +-- indices. +drawIndexedImage :: DrawableClass drawable => drawable -> GC -> Int -> Int -> Int -> Int -> Dither -> String -> Int -> RgbCmap -> IO () +drawIndexedImage drawable gc x y width height dith buf rowstride cmap = + withUTFString buf $ \ bufPtr -> [_$_] + {#call draw_indexed_image#} + (toDrawable drawable) + gc + (fromIntegral x) + (fromIntegral y) + (fromIntegral width) + (fromIntegral height) + ((fromIntegral . fromEnum) dith) + (castPtr bufPtr) + (fromIntegral rowstride) + cmap + +-- | Draws a grayscale image in the drawable. +drawGrayImage :: DrawableClass drawable => drawable -> GC -> Int -> Int -> Int -> Int -> Dither -> String -> Int -> IO () +drawGrayImage drawable gc x y width height dith buf rowstride = + withUTFString buf $ \ bufPtr -> [_$_] + {#call draw_gray_image#} + (toDrawable drawable) + gc + (fromIntegral x) + (fromIntegral y) + (fromIntegral width) + (fromIntegral height) + ((fromIntegral . fromEnum) dith) + (castPtr bufPtr) + (fromIntegral rowstride) + +-- | Draws a padded RGB image in the drawable. The image is stored as one pixel per 32-bit word. It is +-- laid out as a red byte, a green byte, a blue byte, and a padding byte. +-- [_$_] +-- It's unlikely that this function will give significant performance gains in practice. In my +-- experience, the performance gain from having pixels aligned to 32-bit boundaries is cancelled out by +-- the increased memory bandwidth. +drawRgb32Image :: DrawableClass drawable => drawable -> GC -> Int -> Int -> Int -> Int -> Dither -> String -> Int -> IO () +drawRgb32Image drawable gc x y width height dith buf rowstride = + withUTFString buf $ \ bufPtr -> [_$_] + {#call draw_rgb_32_image#} + (toDrawable drawable) + gc + (fromIntegral x) + (fromIntegral y) + (fromIntegral width) + (fromIntegral height) + ((fromIntegral . fromEnum) dith) + (castPtr bufPtr) + (fromIntegral rowstride) + +-- | Like @gdkDrawRgb@_32_image(), but allows you to specify the dither offsets. See +-- 'drawRgbImageDithalign' for more details. +drawRgb32ImageDithalign :: DrawableClass drawable => drawable -> GC -> Int -> Int -> Int -> Int -> Dither -> String -> Int -> Int -> Int -> IO () +drawRgb32ImageDithalign drawable gc x y width height dith buf rowstride xdith ydith = + withUTFString buf $ \ bufPtr -> [_$_] + {#call draw_rgb_32_image_dithalign#} + (toDrawable drawable) + gc + (fromIntegral x) + (fromIntegral y) + (fromIntegral width) + (fromIntegral height) + ((fromIntegral . fromEnum) dith) + (castPtr bufPtr) + (fromIntegral rowstride) + (fromIntegral xdith) + (fromIntegral ydith) + +-- | Creates a new 'RgbCmap' structure. The cmap maps color indexes to RGB colors. If @nColors@ is less +-- than 256, then images containing color values greater than or equal to @nColors@ will produce +-- undefined results, including possibly segfaults. +rgbCmapNew :: [Word32] -> Int -> IO RgbCmap +rgbCmapNew colors nColors = + liftM RgbCmap $ + withArray colors $ \ colorsPtr -> [_$_] + {#call rgb_cmap_new#} [_$_] + (castPtr colorsPtr) + (fromIntegral nColors) + +-- | Determines whether the visual associated with cmap is ditherable. This function may be useful for +-- presenting a user interface choice to the user about which dither mode is desired; if the display is +-- not ditherable, it may make sense to gray out or hide the corresponding UI widget. +rgbColormapDitherable :: Colormap -> IO Bool +rgbColormapDitherable cmap = + liftM toBool $ + {# call rgb_colormap_ditherable #} + cmap + +-- | Determines whether the preferred visual is ditherable. This function may be useful for presenting a +-- user interface choice to the user about which dither mode is desired; if the display is not +-- ditherable, it may make sense to gray out or hide the corresponding UI widget. +rgbDitherable :: IO Bool +rgbDitherable = + liftM toBool $ + {# call rgb_ditherable #} + +-- | colormap should be the colormap for the graphics context and drawable you're using to draw. If +-- you're drawing to a 'Widget', call 'widgetGetColormap'. +-- [_$_] +-- color should have its red, green, and blue fields initialized; 'rgbFindColor' will fill in the +-- pixel field with the best matching pixel from a color cube. The color is then ready to be used for +-- drawing, e.g. you can call 'gcSetForeground' which expects pixel to be initialized. +-- [_$_] +-- In many cases, you can avoid this whole issue by calling 'gcSetRgbFgColor' or +-- 'gcSetRgbBgColor', which do not expect pixel to be initialized in advance. If you use those +-- functions, there's no need for 'rgbFindColor'. +rgbFindColor :: Colormap -> IO Color +rgbFindColor colormap = + alloca $ \colorPtr -> do + {# call rgb_find_color #} + colormap + (castPtr colorPtr) + >> peek colorPtr >>= \color -> + return color + +-- | Get the preferred colormap for rendering image data. Not a very useful function; historically, GDK +-- could only render RGB image data to one colormap and visual, but in the current version it can +-- render to any colormap and visual. So there's no need to call this function. +rgbGetColormap :: IO Colormap +rgbGetColormap = + makeNewGObject mkColormap $ + {# call rgb_get_colormap #} + +-- | Gets a "preferred visual" chosen by 'RGB' for rendering image data on the default screen. In +-- previous versions of GDK, this was the only visual 'RGB' could use for rendering. In current +-- versions, it's simply the visual 'RGB' would have chosen as the optimal one in those previous +-- versions. 'RGB' can now render to drawables with any visual. +rgbGetVisual :: IO Visual +rgbGetVisual = + makeNewGObject mkVisual $ + {# call rgb_get_visual #} + +-- | If install is 'True', directs 'RGB' to always install a new "private" colormap rather than trying to +-- find a best fit with the colors already allocated. Ordinarily, 'RGB' will install a colormap only +-- if a sufficient cube cannot be allocated. +-- [_$_] +-- A private colormap has more colors, leading to better quality display, but also leads to the dreaded +-- "colormap flashing" effect. +rgbSetInstall :: Bool -> IO () +rgbSetInstall install = + {# call rgb_set_install #} + (fromBool install) + +-- | Sets the minimum number of colors for the color cube. Generally, 'RGB' tries to allocate the +-- largest color cube it can. If it can't allocate a color cube at least as large as @minColors@, it +-- installs a private colormap. +rgbSetMinColors :: Int -> IO () +rgbSetMinColors minColors = + {# call rgb_set_min_colors #} + (fromIntegral minColors) + +-- | Sets the "verbose" flag. This is generally only useful for debugging. +rgbSetVerbose :: Bool -> IO () +rgbSetVerbose verbose = + {# call rgb_set_verbose #} + (fromBool verbose) |