/
Timer.chs
170 lines (162 loc) · 8.05 KB
/
Timer.chs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
{-# LANGUAGE CPP, ExistentialQuantification, TypeSynonymInstances, FlexibleInstances, MultiParamTypeClasses, FlexibleContexts, ScopedTypeVariables #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}
module Graphics.UI.FLTK.LowLevel.Timer
(
-- * Constructor
timerNew,
timerCustom,
-- * Hierarchy
--
-- $hierarchy
valueTimerNew,
hiddenTimerNew
-- * Functions
--
-- $functions
)
where
#include "Fl_ExportMacros.h"
#include "Fl_Types.h"
#include "Fl_TimerC.h"
import C2HS hiding (cFromEnum, cFromBool, cToBool,cToEnum)
import Graphics.UI.FLTK.LowLevel.Widget
import Graphics.UI.FLTK.LowLevel.Fl_Enumerations
import Graphics.UI.FLTK.LowLevel.Fl_Types
import Graphics.UI.FLTK.LowLevel.Utils
import Graphics.UI.FLTK.LowLevel.Hierarchy
import Graphics.UI.FLTK.LowLevel.Dispatch
import qualified Data.Text as T
{# fun Fl_OverriddenTimer_New_WithLabel as overriddenWidgetNewWithLabel' { `Int',`Int',`Int',`Int', unsafeToCString `T.Text', id `Ptr ()'} -> `Ptr ()' id #}
{# fun Fl_OverriddenTimer_New as overriddenWidgetNew' { `Int',`Int',`Int',`Int', id `Ptr ()'} -> `Ptr ()' id #}
timerCustom ::
Rectangle -- ^ The bounds of this Timer
-> T.Text -- ^ The Timer label
-> Maybe (Ref Timer -> IO ()) -- ^ Optional custom drawing function
-> Maybe (CustomWidgetFuncs Timer) -- ^ Optional custom widget functions
-> IO (Ref Timer)
timerCustom rectangle l' draw' funcs' =
widgetMaker
rectangle
(Just l')
draw'
funcs'
overriddenWidgetNew'
overriddenWidgetNewWithLabel'
{# fun Fl_Timer_New as timerNewWithLabel' { `Int',`Int',`Int',`Int', unsafeToCString `T.Text'} -> `Ptr ()' id #}
timerNew :: Rectangle -> T.Text -> IO (Ref Timer)
timerNew rectangle l'=
let (x_pos, y_pos, width, height) = fromRectangle rectangle
in timerNewWithLabel' x_pos y_pos width height l' >>= toRef
{# fun Fl_Value_Timer_New as valueTimerNewWithLabel' { `Int',`Int',`Int',`Int', unsafeToCString `T.Text'} -> `Ptr ()' id #}
valueTimerNew :: Rectangle -> T.Text -> IO (Ref ValueTimer)
valueTimerNew rectangle l'=
let (x_pos, y_pos, width, height) = fromRectangle rectangle
in
valueTimerNewWithLabel' x_pos y_pos width height l' >>= toRef
{# fun Fl_Hidden_Timer_New as hiddenTimerNewWithLabel' { `Int',`Int',`Int',`Int', unsafeToCString `T.Text'} -> `Ptr ()' id #}
hiddenTimerNew :: Rectangle -> T.Text -> IO (Ref HiddenTimer)
hiddenTimerNew rectangle l'=
let (x_pos, y_pos, width, height) = fromRectangle rectangle
in
hiddenTimerNewWithLabel' x_pos y_pos width height l' >>= toRef
{# fun Fl_Timer_Destroy as timerDestroy' { id `Ptr ()' } -> `()' supressWarningAboutRes #}
instance (impl ~ (IO ())) => Op (Destroy ()) Timer orig impl where
runOp _ _ win = swapRef win $ \winPtr -> do
timerDestroy' winPtr
return nullPtr
{# fun Fl_Timer_direction as direction' { id `Ptr ()' } -> `CChar' id #}
instance (impl ~ ( IO (CountDirection))) => Op (GetDirection ()) Timer orig impl where
runOp _ _ adjuster = withRef adjuster $ \adjusterPtr -> direction' adjusterPtr >>= return . ccharToCountDirection
{# fun Fl_Timer_set_direction as setDirection' { id `Ptr ()',id `CChar' } -> `()' #}
instance (impl ~ (CountDirection -> IO ())) => Op (SetDirection ()) Timer orig impl where
runOp _ _ adjuster d = withRef adjuster $ \adjusterPtr -> setDirection' adjusterPtr (countDirectionToCChar d)
{# fun Fl_Timer_value as value' { id `Ptr ()' } -> `Double' #}
instance (impl ~ ( IO (Double))) => Op (GetValue ()) Timer orig impl where
runOp _ _ adjuster = withRef adjuster $ \adjusterPtr -> value' adjusterPtr
{# fun Fl_Timer_set_value as setValue' { id `Ptr ()',`Double' } -> `()' #}
instance (impl ~ (Double -> IO ())) => Op (SetValue ()) Timer orig impl where
runOp _ _ adjuster value = withRef adjuster $ \adjusterPtr -> setValue' adjusterPtr value
{# fun Fl_Timer_suspended as suspended' { id `Ptr ()' } -> `Bool' cToBool #}
instance (impl ~ ( IO (Bool))) => Op (GetSuspended ()) Timer orig impl where
runOp _ _ adjuster = withRef adjuster $ \adjusterPtr -> suspended' adjusterPtr
{# fun Fl_Timer_set_suspended as setSuspended' { id `Ptr ()', cFromBool `Bool' } -> `()' #}
instance (impl ~ (Bool -> IO ())) => Op (SetSuspended ()) Timer orig impl where
runOp _ _ adjuster s = withRef adjuster $ \adjusterPtr -> setSuspended' adjusterPtr s
{# fun Fl_Timer_draw as draw'' { id `Ptr ()' } -> `()' #}
instance (impl ~ ( IO ())) => Op (Draw ()) Timer orig impl where
runOp _ _ timer = withRef timer $ \timerPtr -> draw'' timerPtr
{# fun Fl_Timer_draw_super as drawSuper' { id `Ptr ()' } -> `()' supressWarningAboutRes #}
instance (impl ~ ( IO ())) => Op (DrawSuper ()) Timer orig impl where
runOp _ _ timer = withRef timer $ \timerPtr -> drawSuper' timerPtr
{#fun Fl_Timer_handle as timerHandle' { id `Ptr ()', id `CInt' } -> `Int' #}
instance (impl ~ (Event -> IO (Either UnknownEvent ()))) => Op (Handle ()) Timer orig impl where
runOp _ _ timer event = withRef timer (\p -> timerHandle' p (fromIntegral . fromEnum $ event)) >>= return . successOrUnknownEvent
{# fun Fl_Timer_handle_super as handleSuper' { id `Ptr ()',`Int' } -> `Int' #}
instance (impl ~ (Event -> IO (Either UnknownEvent ()))) => Op (HandleSuper ()) Timer orig impl where
runOp _ _ timer event = withRef timer $ \timerPtr -> handleSuper' timerPtr (fromIntegral (fromEnum event)) >>= return . successOrUnknownEvent
{# fun Fl_Timer_resize as resize' { id `Ptr ()',`Int',`Int',`Int',`Int' } -> `()' supressWarningAboutRes #}
instance (impl ~ (Rectangle -> IO ())) => Op (Resize ()) Timer orig impl where
runOp _ _ timer rectangle = withRef timer $ \timerPtr -> do
let (x_pos,y_pos,w_pos,h_pos) = fromRectangle rectangle
resize' timerPtr x_pos y_pos w_pos h_pos
{# fun Fl_Timer_resize_super as resizeSuper' { id `Ptr ()',`Int',`Int',`Int',`Int' } -> `()' supressWarningAboutRes #}
instance (impl ~ (Rectangle -> IO ())) => Op (ResizeSuper ()) Timer orig impl where
runOp _ _ timer rectangle =
let (x_pos, y_pos, width, height) = fromRectangle rectangle
in withRef timer $ \timerPtr -> resizeSuper' timerPtr x_pos y_pos width height
{# fun Fl_Timer_hide as hide' { id `Ptr ()' } -> `()' #}
instance (impl ~ ( IO ())) => Op (Hide ()) Timer orig impl where
runOp _ _ timer = withRef timer $ \timerPtr -> hide' timerPtr
{# fun Fl_Timer_hide_super as hideSuper' { id `Ptr ()' } -> `()' supressWarningAboutRes #}
instance (impl ~ ( IO ())) => Op (HideSuper ()) Timer orig impl where
runOp _ _ timer = withRef timer $ \timerPtr -> hideSuper' timerPtr
{# fun Fl_Timer_show as show' { id `Ptr ()' } -> `()' #}
instance (impl ~ ( IO ())) => Op (ShowWidget ()) Timer orig impl where
runOp _ _ timer = withRef timer $ \timerPtr -> show' timerPtr
{# fun Fl_Timer_show_super as showSuper' { id `Ptr ()' } -> `()' supressWarningAboutRes #}
instance (impl ~ ( IO ())) => Op (ShowWidgetSuper ()) Timer orig impl where
runOp _ _ timer = withRef timer $ \timerPtr -> showSuper' timerPtr
-- $functions
-- @
--
-- destroy :: 'Ref' 'Timer' -> 'IO' ()
--
-- draw :: 'Ref' 'Timer' -> 'IO' ()
--
-- drawSuper :: 'Ref' 'Timer' -> 'IO' ()
--
-- getDirection :: 'Ref' 'Timer' -> 'IO' ('CountDirection')
--
-- getSuspended :: 'Ref' 'Timer' -> 'IO' ('Bool')
--
-- getValue :: 'Ref' 'Timer' -> 'IO' ('Double')
--
-- handle :: 'Ref' 'Timer' -> 'Event' -> 'IO' ('Either' 'UnknownEvent' ())
--
-- handleSuper :: 'Ref' 'Timer' -> 'Event' -> 'IO' ('Either' 'UnknownEvent' ())
--
-- hide :: 'Ref' 'Timer' -> 'IO' ()
--
-- hideSuper :: 'Ref' 'Timer' -> 'IO' ()
--
-- resize :: 'Ref' 'Timer' -> 'Rectangle' -> 'IO' ()
--
-- resizeSuper :: 'Ref' 'Timer' -> 'Rectangle' -> 'IO' ()
--
-- setDirection :: 'Ref' 'Timer' -> 'CountDirection' -> 'IO' ()
--
-- setSuspended :: 'Ref' 'Timer' -> 'Bool' -> 'IO' ()
--
-- setValue :: 'Ref' 'Timer' -> 'Double' -> 'IO' ()
--
-- showWidget :: 'Ref' 'Timer' -> 'IO' ()
--
-- showWidgetSuper :: 'Ref' 'Timer' -> 'IO' ()
-- @
-- $hierarchy
-- @
-- "Graphics.UI.FLTK.LowLevel.Widget"
-- |
-- v
-- "Graphics.UI.FLTK.LowLevel.Timer"
-- @