------------------------------------------------------------------------------ |-- Module : XMonad.Util.Image-- Copyright : (c) 2010 Alejandro Serrano-- License : BSD-style (see xmonad/LICENSE)---- Maintainer : trupill@gmail.com-- Stability : unstable-- Portability : unportable---- Utilities for manipulating [[Bool]] as images-------------------------------------------------------------------------------moduleXMonad.Util.Image(-- * Usage:-- $usagePlacement(..),iconPosition,drawIcon,)whereimportXMonadimportXMonad.Util.Font(stringToPixel,fi)-- | Placement of the icon in the title bardataPlacement=OffsetLeftIntInt-- ^ An exact amount of pixels from the upper left corner|OffsetRightIntInt-- ^ An exact amount of pixels from the right left corner|CenterLeftInt-- ^ Centered in the y-axis, an amount of pixels from the left|CenterRightInt-- ^ Centered in the y-axis, an amount of pixels from the rightderiving(Show,Read)-- $usage-- This module uses matrices of boolean values as images. When drawing them,-- a True value tells that we want the fore color, and a False value that we-- want the background color to be painted.-- In the module we suppose that those matrices are represented as [[Bool]],-- so the lengths of the inner lists must be the same.---- See "Xmonad.Layout.Decoration" for usage examples-- | Gets the ('width', 'height') of an imageimageDims::[[Bool]]->(Int,Int)imageDimsimg=(length(headimg),lengthimg)-- | Return the 'x' and 'y' positions inside a 'Rectangle' to start drawing-- the image given its 'Placement'iconPosition::Rectangle->Placement->[[Bool]]->(Position,Position)iconPosition(Rectangle____)(OffsetLeftxy)_=(fix,fiy)iconPosition(Rectangle__w_)(OffsetRightxy)icon=let(icon_w,_)=imageDimsiconin(fiw-fix-fiicon_w,fiy)iconPosition(Rectangle___h)(CenterLeftx)icon=let(_,icon_h)=imageDimsiconin(fix,fi(h`div`2)-fi(icon_h`div`2))iconPosition(Rectangle__wh)(CenterRightx)icon=let(icon_w,icon_h)=imageDimsiconin(fiw-fix-fiicon_w,fi(h`div`2)-fi(icon_h`div`2))-- | Converts an image represented as [[Bool]] to a series of points-- to be painted (the ones with True values)iconToPoints::[[Bool]]->[Point]iconToPointsicon=letlabels_inside=map(zip(iterate(1+)0))iconfiltered_inside=map(\l->[x|(x,t)<-l,t])labels_insidelabels_outside=zip(iterate(1+)0)filtered_insidein[Pointxy|(y,l)<-labels_outside,x<-l]-- | Displaces a point ('a', 'b') along a vector ('x', 'y')movePoint::Position->Position->Point->PointmovePointxy(Pointab)=Point(a+x)(b+y)-- | Displaces a list of points along a vector 'x', 'y'movePoints::Position->Position->[Point]->[Point]movePointsxypoints=map(movePointxy)points-- | Draw an image into a X surfacedrawIcon::(Functorm,MonadIOm)=>Display->Drawable->GC->String->String->Position->Position->[[Bool]]->m()drawIcondpydrwgcfcbcxyicon=dolet(i_w,i_h)=imageDimsiconfcolor<-stringToPixeldpyfcbcolor<-stringToPixeldpybcio$setForegrounddpygcbcolorio$fillRectangledpydrwgcxy(fii_w)(fii_h)io$setForegrounddpygcfcolorio$drawPointsdpydrwgc(movePointsxy(iconToPointsicon))coordModeOrigin