{-# LANGUAGE ScopedTypeVariables #-}{-# LINE 2 "./Graphics/UI/Gtk/Gdk/Region.chs" #-}-- -*-haskell-*--- GIMP Toolkit (GTK) Region---- Author : Axel Simon---- Created: 22 September 2002---- Copyright (C) 2002-2005 Axel Simon---- 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.---- TODO---- The Span functions and callbacks are not implemented since retrieving-- a set of rectangles and working on them within Haskell seems to be easier.---- |-- Maintainer : gtk2hs-users@lists.sourceforge.net-- Stability : provisional-- Portability : portable (depends on GHC)---- A set of rectangles describing areas to be redrawn.---- * Regions consist of a set of non-overlapping rectangles. They are used to-- specify the area of a window which needs updating.--moduleGraphics.UI.Gtk.Gdk.Region(makeNewRegion,Region(Region),regionNew,FillRule(..),regionPolygon,regionCopy,regionRectangle,regionGetClipbox,regionGetRectangles,regionEmpty,regionEqual,regionPointIn,OverlapType(..),regionRectIn,regionOffset,regionShrink,regionUnionWithRect,regionIntersect,regionUnion,regionSubtract,regionXor)whereimportControl.Monad(liftM)importSystem.Glib.FFIimportGraphics.UI.Gtk.General.Structs(Point,Rectangle(..)){-# LINE 65 "./Graphics/UI/Gtk/Gdk/Region.chs" #-}newtypeRegion=Region(ForeignPtr(Region)){-# LINE 67 "./Graphics/UI/Gtk/Gdk/Region.chs" #-}instanceShowRegionwhereshowr=show(unsafePerformIO(regionGetRectanglesr))-- Construct a region from a pointer.--makeNewRegion::PtrRegion->IORegionmakeNewRegionrPtr=doregion<-newForeignPtrrPtrregion_destroyreturn(Regionregion)foreignimportccallunsafe"&gdk_region_destroy"region_destroy::FinalizerPtrRegion-- | Specify how to interpret a polygon.---- * The flag determines what happens if a polygon has overlapping areas.--dataFillRule=EvenOddRule|WindingRulederiving(Enum){-# LINE 86 "./Graphics/UI/Gtk/Gdk/Region.chs" #-}-- | How a rectangle is contained in a 'Region'.--dataOverlapType=OverlapRectangleIn|OverlapRectangleOut|OverlapRectanglePartderiving(Enum){-# LINE 90 "./Graphics/UI/Gtk/Gdk/Region.chs" #-}-- | Create an empty region.--regionNew::IORegionregionNew=dorPtr<-gdk_region_new{-# LINE 96 "./Graphics/UI/Gtk/Gdk/Region.chs" #-}makeNewRegionrPtr-- | Convert a polygon into a 'Region'.--regionPolygon::[Point]->FillRule->IORegionregionPolygonpointsrule=withArray(concatMap(\(x,y)->[fromIntegralx,fromIntegraly])points)$\(aPtr::Ptr(CInt))->dorPtr<-gdk_region_polygon(castPtraPtr)(fromIntegral(lengthpoints))((fromIntegral.fromEnum)rule)makeNewRegionrPtr-- | Copy a 'Region'.--regionCopy::Region->IORegionregionCopyr=dorPtr<-(\(Regionarg1)->withForeignPtrarg1$\argPtr1->gdk_region_copyargPtr1)rmakeNewRegionrPtr-- | Convert a rectangle to a 'Region'.--regionRectangle::Rectangle->IORegionregionRectanglerect=withrect$\rectPtr->doregPtr<-gdk_region_rectangle(castPtrrectPtr)makeNewRegionregPtr-- | Smallest rectangle including the-- 'Region'.--regionGetClipbox::Region->IORectangleregionGetClipboxr=alloca$\rPtr->do(\(Regionarg1)arg2->withForeignPtrarg1$\argPtr1->gdk_region_get_clipboxargPtr1arg2)r(castPtrrPtr)peekrPtr-- | Turn the 'Region' into its rectangles.---- A 'Region' is a set of horizontal bands. Each band consists of one or more-- rectangles of the same height. No rectangles in a band touch.--regionGetRectangles::Region->IO[Rectangle]regionGetRectanglesregion=alloca$\(rectPtrPtr::Ptr(PtrRectangle))->alloca$\(iPtr::Ptr(CInt))->do(\(Regionarg1)arg2arg3->withForeignPtrarg1$\argPtr1->gdk_region_get_rectanglesargPtr1arg2arg3)region(castPtrrectPtrPtr)iPtrsize<-peekiPtrrectPtr<-peekrectPtrPtrrects<-peekArray(fromIntegralsize)rectPtrg_free(castPtrrectPtr)returnrects-- | Test if a 'Region' is empty.--regionEmpty::Region->IOBoolregionEmptyr=liftMtoBool$(\(Regionarg1)->withForeignPtrarg1$\argPtr1->gdk_region_emptyargPtr1)r-- | Compares two 'Region's for equality.--regionEqual::Region->Region->IOBoolregionEqualr1r2=liftMtoBool$(\(Regionarg1)(Regionarg2)->withForeignPtrarg1$\argPtr1->withForeignPtrarg2$\argPtr2->gdk_region_equalargPtr1argPtr2)r1r2-- | Checks if a point it is within a region.--regionPointIn::Region->Point->IOBoolregionPointInr(x,y)=liftMtoBool$(\(Regionarg1)arg2arg3->withForeignPtrarg1$\argPtr1->gdk_region_point_inargPtr1arg2arg3)r(fromIntegralx)(fromIntegraly)-- | Check if a rectangle is within a region.--regionRectIn::Region->Rectangle->IOOverlapTyperegionRectInregrect=liftM(toEnum.fromIntegral)$withrect$\rPtr->(\(Regionarg1)arg2->withForeignPtrarg1$\argPtr1->gdk_region_rect_inargPtr1arg2)reg(castPtrrPtr)-- | Move a region.--regionOffset::Region->Int->Int->IO()regionOffsetrdxdy=(\(Regionarg1)arg2arg3->withForeignPtrarg1$\argPtr1->gdk_region_offsetargPtr1arg2arg3)r(fromIntegraldx)(fromIntegraldy)-- | Move a region.---- * Positive values shrink the region, negative values expand it.--regionShrink::Region->Int->Int->IO()regionShrinkrdxdy=(\(Regionarg1)arg2arg3->withForeignPtrarg1$\argPtr1->gdk_region_shrinkargPtr1arg2arg3)r(fromIntegraldx)(fromIntegraldy)-- | Updates the region to include the rectangle.--regionUnionWithRect::Region->Rectangle->IO()regionUnionWithRectregrect=withrect$\rPtr->(\(Regionarg1)arg2->withForeignPtrarg1$\argPtr1->gdk_region_union_with_rectargPtr1arg2)reg(castPtrrPtr)-- | Intersects one region with another.---- * Changes @reg1@ to include the common areas of @reg1@-- and @reg2@.--regionIntersect::Region->Region->IO()regionIntersectreg1reg2=(\(Regionarg1)(Regionarg2)->withForeignPtrarg1$\argPtr1->withForeignPtrarg2$\argPtr2->gdk_region_intersectargPtr1argPtr2)reg1reg2-- | Unions one region with another.---- * Changes @reg1@ to include @reg1@ and @reg2@.--regionUnion::Region->Region->IO()regionUnionreg1reg2=(\(Regionarg1)(Regionarg2)->withForeignPtrarg1$\argPtr1->withForeignPtrarg2$\argPtr2->gdk_region_unionargPtr1argPtr2)reg1reg2-- | Removes pars of a 'Region'.---- * Reduces the region @reg1@ so that is does not include any areas-- of @reg2@.--regionSubtract::Region->Region->IO()regionSubtractreg1reg2=(\(Regionarg1)(Regionarg2)->withForeignPtrarg1$\argPtr1->withForeignPtrarg2$\argPtr2->gdk_region_subtractargPtr1argPtr2)reg1reg2-- | XORs two 'Region's.---- * The exclusive or of two regions contains all areas which were not-- overlapping. In other words, it is the union of the regions minus-- their intersections.--regionXor::Region->Region->IO()regionXorreg1reg2=(\(Regionarg1)(Regionarg2)->withForeignPtrarg1$\argPtr1->withForeignPtrarg2$\argPtr2->gdk_region_xorargPtr1argPtr2)reg1reg2foreignimportccallunsafe"gdk_region_new"gdk_region_new::(IO(PtrRegion))foreignimportccallunsafe"gdk_region_polygon"gdk_region_polygon::((Ptr())->(CInt->(CInt->(IO(PtrRegion)))))foreignimportccallunsafe"gdk_region_copy"gdk_region_copy::((PtrRegion)->(IO(PtrRegion)))foreignimportccallunsafe"gdk_region_rectangle"gdk_region_rectangle::((Ptr())->(IO(PtrRegion)))foreignimportccallunsafe"gdk_region_get_clipbox"gdk_region_get_clipbox::((PtrRegion)->((Ptr())->(IO())))foreignimportccallunsafe"gdk_region_get_rectangles"gdk_region_get_rectangles::((PtrRegion)->((Ptr(Ptr()))->((PtrCInt)->(IO()))))foreignimportccallunsafe"g_free"g_free::((Ptr())->(IO()))foreignimportccallunsafe"gdk_region_empty"gdk_region_empty::((PtrRegion)->(IOCInt))foreignimportccallunsafe"gdk_region_equal"gdk_region_equal::((PtrRegion)->((PtrRegion)->(IOCInt)))foreignimportccallunsafe"gdk_region_point_in"gdk_region_point_in::((PtrRegion)->(CInt->(CInt->(IOCInt))))foreignimportccallunsafe"gdk_region_rect_in"gdk_region_rect_in::((PtrRegion)->((Ptr())->(IOCInt)))foreignimportccallunsafe"gdk_region_offset"gdk_region_offset::((PtrRegion)->(CInt->(CInt->(IO()))))foreignimportccallunsafe"gdk_region_shrink"gdk_region_shrink::((PtrRegion)->(CInt->(CInt->(IO()))))foreignimportccallunsafe"gdk_region_union_with_rect"gdk_region_union_with_rect::((PtrRegion)->((Ptr())->(IO())))foreignimportccallunsafe"gdk_region_intersect"gdk_region_intersect::((PtrRegion)->((PtrRegion)->(IO())))foreignimportccallunsafe"gdk_region_union"gdk_region_union::((PtrRegion)->((PtrRegion)->(IO())))foreignimportccallunsafe"gdk_region_subtract"gdk_region_subtract::((PtrRegion)->((PtrRegion)->(IO())))foreignimportccallunsafe"gdk_region_xor"gdk_region_xor::((PtrRegion)->((PtrRegion)->(IO())))