From: Duncan C. <dun...@us...> - 2005-01-08 15:18:11
|
Update of /cvsroot/gtk2hs/gtk2hs/gtk/Graphics/UI/Gtk/Gdk In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32047/gtk/Graphics/UI/Gtk/Gdk Added Files: Keys.chs Gdk.chs GC.chs Enums.chs Log Message: hierarchical namespace conversion --- NEW FILE: GC.chs --- -- -*-haskell-*- -- GIMP Toolkit (GTK) GC -- -- Author : Axel Simon -- Created: 28 September 2002 -- -- Version $Revision: 1.1 $ from $Date: 2005/01/08 15:18:00 $ -- -- Copyright (c) 2002 Axel Simon -- -- This library is free software; you can redistribute it and/or -- modify it under the terms of the GNU Library General Public -- License as published by the Free Software Foundation; either -- version 2 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 -- Library General Public License for more details. -- -- | -- -- Graphics contexts. -- -- * This module Graphics.UI.Gtk.Gdk.supplies graphics contexts (GCs) which are a convenient way -- to pass attributes to drawing functions. -- module Graphics.UI.Gtk.Gdk.GC ( GC, GCClass, castToGC, gcNew, GCValues(GCValues), newGCValues, Color(..), foreground, background, Function(..), function, Fill(..), fill, tile, stipple, clipMask, SubwindowMode(..), subwindowMode, tsXOrigin, tsYOrigin, clipXOrigin, clipYOrigin, graphicsExposure, lineWidth, LineStyle(..), lineStyle, CapStyle(..), capStyle, JoinStyle(..), joinStyle, gcNewWithValues, gcSetValues, gcGetValues, gcSetClipRectangle, gcSetClipRegion, gcSetDashes) where import Monad (liftM, when) import Maybe (fromJust, isJust) import Control.Exception (handle) import System.Glib.FFI import System.Glib.GObject (makeNewGObject) {#import Graphics.UI.Gtk.Types#} import Graphics.UI.Gtk.General.Structs import Graphics.UI.Gtk.General.Enums (Function(..), Fill(..), SubwindowMode(..), LineStyle(..), CapStyle(..), JoinStyle(..)) {#import Graphics.UI.Gtk.Gdk.Region#} (Region(Region)) {# context lib="gtk" prefix="gdk" #} -- | Create an empty graphics context. -- gcNew :: DrawableClass d => d -> IO GC gcNew d = do gcPtr <- {#call unsafe gc_new#} (toDrawable d) if (gcPtr==nullPtr) then return (error "gcNew: null graphics context.") else makeNewGObject mkGC (return gcPtr) -- | Creates a graphics context with specific values. -- gcNewWithValues :: DrawableClass d => d -> GCValues -> IO GC gcNewWithValues d gcv = allocaBytes (sizeOf gcv) $ \vPtr -> do mask <- pokeGCValues vPtr gcv gc <- makeNewGObject mkGC $ {#call unsafe gc_new_with_values#} (toDrawable d) (castPtr vPtr) mask handle (const $ return ()) $ when (isJust (tile gcv)) $ touchForeignPtr ((unPixmap.fromJust.tile) gcv) handle (const $ return ()) $ when (isJust (stipple gcv)) $ touchForeignPtr ((unPixmap.fromJust.stipple) gcv) handle (const $ return ()) $ when (isJust (clipMask gcv)) $ touchForeignPtr ((unPixmap.fromJust.clipMask) gcv) return gc -- | Change some of the values of a graphics context. -- gcSetValues :: GC -> GCValues -> IO () gcSetValues gc gcv = allocaBytes (sizeOf gcv) $ \vPtr -> do mask <- pokeGCValues vPtr gcv gc <- {#call unsafe gc_set_values#} gc (castPtr vPtr) mask handle (const $ return ()) $ when (isJust (tile gcv)) $ touchForeignPtr ((unPixmap.fromJust.tile) gcv) handle (const $ return ()) $ when (isJust (stipple gcv)) $ touchForeignPtr ((unPixmap.fromJust.stipple) gcv) handle (const $ return ()) $ when (isJust (clipMask gcv)) $ touchForeignPtr ((unPixmap.fromJust.clipMask) gcv) return gc -- | Retrieve the values in a graphics context. -- gcGetValues :: GC -> IO GCValues gcGetValues gc = alloca $ \vPtr -> do {#call unsafe gc_get_values#} gc (castPtr vPtr) peek vPtr -- | Set a clipping rectangle. -- -- * All drawing operations are restricted to this rectangle. This rectangle -- is interpreted relative to the clip origin. -- gcSetClipRectangle :: GC -> Rectangle -> IO () gcSetClipRectangle gc r = withObject r $ \rPtr -> {#call unsafe gc_set_clip_rectangle#} gc (castPtr rPtr) -- | Set a clipping region. -- -- * All drawing operations are restricted to this region. This region -- is interpreted relative to the clip origin. -- gcSetClipRegion :: GC -> Region -> IO () gcSetClipRegion = {#call unsafe gc_set_clip_region#} -- | Specify the pattern with which lines are drawn. -- -- * Every tuple in the list contains an even and an odd segment. Even -- segments are drawn normally, whereby the 'lineStyle' -- member of the graphics context defines if odd segements are drawn -- or not. A @phase@ argument greater than 0 will drop -- @phase@ pixels before starting to draw. -- gcSetDashes :: GC -> Int -> [(Int,Int)] -> IO () gcSetDashes gc phase onOffList = do let onOff :: [{#type gint8#}] onOff = concatMap (\(on,off) -> [fromIntegral on, fromIntegral off]) onOffList withArray onOff $ \aPtr -> {#call unsafe gc_set_dashes#} gc (fromIntegral phase) aPtr (fromIntegral (length onOff)) --- NEW FILE: Enums.chs --- -- -*-haskell-*- -- GIMP Toolkit (GTK) Enumerations -- -- Author : Manuel M. T. Chakravarty, Axel Simon -- Created: 13 Januar 1999 -- -- Version $Revision: 1.1 $ from $Date: 2005/01/08 15:18:00 $ -- -- Copyright (c) [1999..2001] Manuel M. T. Chakravarty -- -- This library is free software; you can redistribute it and/or -- modify it under the terms of the GNU Library General Public -- License as published by the Free Software Foundation; either -- version 2 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 -- Library General Public License for more details. -- -- | -- -- General enumeration types. -- module Graphics.UI.Gtk.Gdk.Enums ( CapStyle(..), CrossingMode(..), Dither(..), EventMask(..), ExtensionMode(..), Fill(..), FillRule(..), Function(..), InputCondition(..), JoinStyle(..), LineStyle(..), NotifyType(..), OverlapType(..), ScrollDirection(..), SubwindowMode(..), VisibilityState(..), WindowState(..), Flags(fromFlags,toFlags) ) where import Data.Bits ((.|.)) class (Enum a, Bounded a) => Flags a where fromFlags :: [a] -> Int toFlags :: Int -> [a] fromFlags is = orNum 0 is where orNum n [] = n orNum n (i:is) = orNum (n .|. fromEnum i) is toFlags n = andNum n minBound where andNum n (m::a) = (if (n .|. fromEnum m) == n then (m:) else id) (if fromEnum m==fromEnum (maxBound::a) then [] else andNum n (succ m)) {#context lib="libgdk" prefix ="gdk"#} -- | Specify the how the ends of a line is drawn. -- {#enum CapStyle {underscoreToCase}#} -- | provide additionl information if cursor crosses a -- window -- {#enum CrossingMode {underscoreToCase}#} -- | Specify how to dither colors onto the screen. -- {#enum RgbDither as Dither {underscoreToCase}#} -- | specify which events a widget will emit signals on -- {#enum EventMask {underscoreToCase} deriving (Bounded)#} instance Flags EventMask -- | specify which input extension a widget desires -- {#enum ExtensionMode {underscoreToCase} deriving(Bounded)#} instance Flags ExtensionMode -- | How objects are filled. -- {#enum Fill {underscoreToCase}#} -- | Determine how bitmap operations are carried out. -- {#enum Function {underscoreToCase}#} -- | Specify how to interpret a polygon. -- -- * The flag determines what happens if a polygon has overlapping areas. -- {#enum FillRule {underscoreToCase}#} -- | Specify on what file condition a callback should be -- done. -- {#enum InputCondition {underscoreToCase} deriving(Bounded) #} instance Flags InputCondition -- | Determines how adjacent line ends are drawn. -- {#enum JoinStyle {underscoreToCase}#} -- | Determines if a line is solid or dashed. -- {#enum LineStyle {underscoreToCase}#} -- dunno -- {#enum NotifyType {underscoreToCase}#} -- | How a rectangle is contained in a 'Region'. -- {#enum OverlapType {underscoreToCase}#} -- | in which direction was scrolled? -- {#enum ScrollDirection {underscoreToCase}#} -- | Determine if child widget may be overdrawn. -- {#enum SubwindowMode {underscoreToCase}#} -- | visibility of a window -- {#enum VisibilityState {underscoreToCase, VISIBILITY_PARTIAL as VisibilityPartialObscured}#} -- | the state a GDK window is in -- {#enum WindowState {underscoreToCase} deriving (Bounded)#} instance Flags WindowState --- NEW FILE: Keys.chs --- -- -*-haskell-*- -- GIMP Toolkit (GTK) Keys -- -- Author : Jens Petersen -- Created: 24 May 2002 -- -- Version $Revision: 1.1 $ from $Date: 2005/01/08 15:18:00 $ -- -- Copyright (c) 2002 Jens Petersen -- -- This library is free software; you can redistribute it and/or -- modify it under the terms of the GNU Library General Public -- License as published by the Free Software Foundation; either -- version 2 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 -- Library General Public License for more details. -- -- | -- -- Gdk keyval functions. -- -- TODO -- -- * Documentation -- module Graphics.UI.Gtk.Gdk.Keys ( keyvalName, keyvalFromName ) where import System.Glib.FFI {#context lib="libgdk" prefix ="gdk"#} {#fun pure keyval_name as ^ {fromIntegral `Integer'} -> `Maybe String' maybePeekUTFString#} where maybePeekUTFString = unsafePerformIO . (maybePeek peekCString) -- maybePeekUTFString = maybePeek peekCString {#fun pure keyval_from_name as ^ {`String'} -> `Integer' fromIntegral#} --- NEW FILE: Gdk.chs --- -- -*-haskell-*- -- GIMP Toolkit (GTK) Gdk -- -- Author : Jens Petersen <pet...@ha...> -- Created: 2003-06-06 -- -- Version $Revision: 1.1 $ from $Date: 2005/01/08 15:18:00 $ -- -- Copyright (c) 2003 Jens-Ulrik Holger Petersen -- -- This library is free software; you can redistribute it and/or -- modify it under the terms of the GNU Library General Public -- License as published by the Free Software Foundation; either -- version 2 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 -- Library General Public License for more details. -- -- | -- -- Gdk general functions. -- -- TODO -- -- * Documentation -- module Graphics.UI.Gtk.Gdk.Gdk (beep) where {#context lib="libgdk" prefix ="gdk"#} beep :: IO () beep = {#call beep#} |