From: Magicloud M. <mag...@gm...> - 2009-09-11 06:29:05
|
If I change draw3's content to this, then everything is pretty good. moveTo 0 0 lineTo (-0.3 * (sin (-hour * 30 / 180 * pi))) (-0.3 * (cos (-hour * 30 / 180 * pi))) setSourceRGBA 1 0 0 0.75 stroke moveTo 0 0 lineTo (-0.4 * (sin (-minute * 6 / 180 * pi))) (-0.4 * (cos (-minute * 6 / 180 * pi))) setSourceRGBA 0 1 0 0.75 stroke moveTo 0 0 lineTo (-0.5 * (sin (-second * 6 / 180 * pi))) (-0.5 * (cos (-second * 6 / 180 * pi))) setSourceRGBA 0 0 1 0.75 stroke On Fri, Sep 11, 2009 at 2:26 PM, Magicloud Magiclouds <mag...@gm...> wrote: > Thank you for the reply. > Normally, I should do the things you said. But this window, I set some > attributes for it, so redraw or exposeEvent is not necessary. > But also, there might be some extra actions I need to do if I set > these attributes. Without any clue, I am just trying.... > > On Fri, Sep 11, 2009 at 2:16 PM, Axel Simon <Axe...@en...> wrote: >> Hi Magicloud, >> >> from what I can see: you lack a 'paint' after drawing the text, you >> shouldn't install a handler in the handler that redraws the widget. You must >> redraw the widget in the 'expose' handler; the 'realize' handler is meant to >> initialized the widgets resources when it is created. The timeout handler >> needs to force the widget to redraw itself using e.g. widgetQueueRedraw. If >> you want to periodically change the content of the widget, use an IORef or >> MVar to store the data that changes, add a timeout handler that changes this >> IORef and calls widgetQueueRedraw. Finally, in the 'expose' event, read the >> IORef and draw whatever content you want. See the demo's, e.g. demo/graphic >> for the basic setup. >> >> Cheers, >> Axel. >> >> On Sep 11, 2009, at 8:03, Magicloud Magiclouds wrote: >> >>> Hi, >>> I have a code like following. If I drew some lines in draw3 >>> function, everything was fine. Now I use pango to draw some text, >>> nothing happen. I do not know if any actions of Render effect this. >>> >>> import Graphics.UI.Gtk >>> import Control.Monad.Trans >>> import Graphics.Rendering.Cairo >>> import Data.Time >>> import System.Locale >>> import Gtk_X11 >>> import Graphics.X11.Xlib.Extras >>> import Graphics.X11.Xlib.Misc >>> import Graphics.X11.Types >>> >>> main = do >>> initGUI >>> win <- windowNew >>> windowSetKeepAbove win True >>> screen <- windowGetScreen win >>> Just cm <- screenGetRGBAColormap screen >>> set win [ windowDecorated := False >>> , windowWindowPosition := WinPosCenterAlways >>> , widgetColormap := cm ] >>> win `on` realize $ winRealize win >>> win `on` destroyEvent $ liftIO $ do >>> mainQuit >>> return False >>> widgetShowAll win >>> mainGUI >>> >>> winRealize widget = do >>> d <- widgetGetDrawWindow widget >>> xid <- drawableGetXID d >>> display <- widgetGetDisplay widget >>> xDisplay <- displayGetXDisplay display >>> allocaSetWindowAttributes $ \wa -> do >>> set_override_redirect wa True >>> changeWindowAttributes xDisplay xid cWOverrideRedirect wa >>> (width, height) <- drawableGetSize d >>> renderWithDrawable d $ do >>> save >>> setOperator OperatorSource >>> setSourceRGBA 0 0 0 0 >>> paint >>> restore >>> timeoutAdd (do >>> ZonedTime (LocalTime _ time) _ <- getZonedTime >>> renderWithDrawable d $ do >>> let second = fromRational $ toRational $ todSec time >>> let minute = (fromIntegral $ todMin time) + second / 60 >>> let hour = (fromIntegral $ todHour time) + minute / 60 >>> save >>> setOperator OperatorSource >>> setSourceRGBA 0 0 0 0 >>> paint >>> scale (fromIntegral $ min width height) (fromIntegral >>> $ min width height) >>> translate 0.5 0.5 >>> setLineWidth Main.lineWidth >>> draw3 hour minute second >>> restore >>> return True >>> ) 100 >>> region <- regionNew >>> drawWindowInputShapeCombineRegion d region 0 0 >>> return () >>> >>> draw3 hour minute second = do >>> drawChar 'Y' (45 / 180 * pi) 0.5 >>> >>> drawChar char angle radious = do >>> save >>> setSourceRGBA 1 1 1 1 >>> rotate angle >>> lay <- liftIO $ do >>> ctxt <- cairoCreateContext Nothing >>> lay <- layoutText ctxt [char] >>> return lay >>> showLayout lay >>> restore >>> >>> lineWidth = 0.01 >>> >>> -- >>> 竹密岂妨流水过 >>> 山高哪阻野云飞 >>> >>> >>> ------------------------------------------------------------------------------ >>> Let Crystal Reports handle the reporting - Free Crystal Reports 2008 >>> 30-Day >>> trial. Simplify your report design, integration and deployment - and focus >>> on >>> what you do best, core application coding. Discover what's new with >>> Crystal Reports now. http://p.sf.net/sfu/bobj-july >>> _______________________________________________ >>> Gtk2hs-users mailing list >>> Gtk...@li... >>> https://lists.sourceforge.net/lists/listinfo/gtk2hs-users >> >> > > > > -- > 竹密岂妨流水过 > 山高哪阻野云飞 > -- 竹密岂妨流水过 山高哪阻野云飞 |