{-# LINE 2 "./Graphics/UI/Gtk/Misc/GLArea.chs" #-}
-- -*-haskell-*-
-- GIMP Toolkit (GTK) Widget GLArea
--
-- Author : Chris Mennie
--
-- Created: 23 April 2016
--
-- Copyright (C) 2016 Chis Mennie
--
-- 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.
--
-- |
-- Maintainer : gtk2hs-users@lists.sourceforge.net
-- Stability : provisional
-- Portability : portable (depends on GHC)
--
-- A widget for custom drawing with OpenGL
--
module Graphics.UI.Gtk.Misc.GLArea (
-- * Detail
--
-- | The 'GLArea' is a widget that allows drawing with OpenGL.
--
-- GLArea sets up its own 'Graphics.UI.Gtk.Gdk.GLContext.GLContext' for the window it creates, and creates a
-- custom GL framebuffer that the widget will do GL rendering onto. It also
-- ensures that this framebuffer is the default GL rendering target when
-- rendering.
--
-- In order to draw, you have to connect to the 'glAreaRender' signal.
--
-- The GLArea widget ensures that the 'Graphics.UI.Gtk.Gdk.GLContext.GLContext' is associated with the
-- widget's drawing area, and it is kept updated when the size and position
-- of the drawing area changes.
--
-- If you need to initialize OpenGL state, e.g. buffer objects or shaders,
-- you should use the 'Graphics.UI.Gtk.Abstract.Widget.realize' signal; you can use the 'Graphics.UI.Gtk.Abstract.Widget.unrealize' signal
-- to clean up.
--
-- To receive mouse events on a drawing area, you will need to enable them
-- with 'Graphics.UI.Gtk.Abstract.Widget.widgetAddEvents'. To receive keyboard events, you will need to set the
-- 'Graphics.UI.Gtk.Abstract.Widget.widgetCanFocus' attribute on the drawing area.

-- * Class Hierarchy
-- |
-- @
-- | 'GObject'
-- | +----'Object'
-- | +----'Widget'
-- | +----GLArea
-- @

-- * Types

  GLArea,
  GLAreaClass,
  castToGLArea, gTypeGLArea,
  toGLArea,


-- * Constructors

  glAreaNew,


-- * Methods

  glAreaGetContext,
  glAreaMakeCurrent,
  glAreaQueueRender,
  glAreaAttachBuffers,
  glAreaSetAutoRender,
  glAreaGetAutoRender,
  glAreaSetHasAlpha,
  glAreaGetHasAlpha,
  glAreaSetHasDepthBuffer,
  glAreaGetHasDepthBuffer,
  glAreaSetHasStencilBuffer,
  glAreaGetHasStencilBuffer,
  glAreaGetRequiredVersion,
  glAreaSetRequiredVersion,
  glAreaGetError,


-- * Attributes

  glAreaAutoRender,
  glAreaContext,
  glAreaHasAlpha,
  glAreaHasDepthBuffer,
  glAreaHasStencilBuffer,


-- * Signals

  glAreaResize,
  glAreaRender


  ) where

import Control.Monad (liftM)
import Control.Monad.Trans ( liftIO )
import System.Glib.FFI
import System.Glib.UTFString
import System.Glib.Attributes
import System.Glib.Properties
import System.Glib.GError
import Graphics.UI.Gtk.Abstract.Object (makeNewObject)
import Graphics.UI.Gtk.Gdk.GLContext
import Graphics.UI.Gtk.Types
{-# LINE 120 "./Graphics/UI/Gtk/Misc/GLArea.chs" #-}
import Graphics.UI.Gtk.Signals
{-# LINE 121 "./Graphics/UI/Gtk/Misc/GLArea.chs" #-}


{-# LINE 123 "./Graphics/UI/Gtk/Misc/GLArea.chs" #-}

--------------------
-- Constructors


-- | Creates a new GLArea widget.
--
glAreaNew :: IO GLArea
glAreaNew :: IO GLArea
glAreaNew =
  (ForeignPtr GLArea -> GLArea, FinalizerPtr GLArea)
-> IO (Ptr GLArea) -> IO GLArea
forall obj.
GObjectClass obj =>
(ForeignPtr obj -> obj, FinalizerPtr obj) -> IO (Ptr obj) -> IO obj
makeNewObject (ForeignPtr GLArea -> GLArea, FinalizerPtr GLArea)
forall {a}. (ForeignPtr GLArea -> GLArea, FinalizerPtr a)
mkGLArea (IO (Ptr GLArea) -> IO GLArea) -> IO (Ptr GLArea) -> IO GLArea
forall a b. (a -> b) -> a -> b
$
  (Ptr Widget -> Ptr GLArea) -> IO (Ptr Widget) -> IO (Ptr GLArea)
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM (Ptr Widget -> Ptr GLArea
forall a b. Ptr a -> Ptr b
castPtr :: Ptr Widget -> Ptr GLArea) (IO (Ptr Widget) -> IO (Ptr GLArea))
-> IO (Ptr Widget) -> IO (Ptr GLArea)
forall a b. (a -> b) -> a -> b
$
  IO (Ptr Widget)
gtk_gl_area_new
{-# LINE 135 "./Graphics/UI/Gtk/Misc/GLArea.chs" #-}



--------------------
-- Methods



-- | Retrieves the 'Graphics.UI.Gtk.Gdk.GLContext.GLContext' used by area.
--
glAreaGetContext :: GLAreaClass self => self
    -> IO (Maybe GLContext)
glAreaGetContext :: forall self. GLAreaClass self => self -> IO (Maybe GLContext)
glAreaGetContext self
self = do
    (IO (Ptr GLContext) -> IO GLContext)
-> IO (Ptr GLContext) -> IO (Maybe GLContext)
forall a. (IO (Ptr a) -> IO a) -> IO (Ptr a) -> IO (Maybe a)
maybeNull ((ForeignPtr GLContext -> GLContext, FinalizerPtr GLContext)
-> IO (Ptr GLContext) -> IO GLContext
forall obj.
GObjectClass obj =>
(ForeignPtr obj -> obj, FinalizerPtr obj) -> IO (Ptr obj) -> IO obj
wrapNewGObject (ForeignPtr GLContext -> GLContext, FinalizerPtr GLContext)
forall {a}. (ForeignPtr GLContext -> GLContext, FinalizerPtr a)
mkGLContext) (IO (Ptr GLContext) -> IO (Maybe GLContext))
-> IO (Ptr GLContext) -> IO (Maybe GLContext)
forall a b. (a -> b) -> a -> b
$
        (\(GLArea ForeignPtr GLArea
arg1) -> ForeignPtr GLArea
-> (Ptr GLArea -> IO (Ptr GLContext)) -> IO (Ptr GLContext)
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr ForeignPtr GLArea
arg1 ((Ptr GLArea -> IO (Ptr GLContext)) -> IO (Ptr GLContext))
-> (Ptr GLArea -> IO (Ptr GLContext)) -> IO (Ptr GLContext)
forall a b. (a -> b) -> a -> b
$ \Ptr GLArea
argPtr1 ->Ptr GLArea -> IO (Ptr GLContext)
gtk_gl_area_get_context Ptr GLArea
argPtr1) (self -> GLArea
forall o. GLAreaClass o => o -> GLArea
toGLArea self
self)


-- | Ensures that the 'Graphics.UI.Gtk.Gdk.GLContext.GLContext' used by area is associated with the GLArea.
--
-- This function is automatically called before emitting the 'glAreaRender' signal,
-- and doesn't normally need to be called by application code.
--
glAreaMakeCurrent :: GLAreaClass self => self -> IO ()
glAreaMakeCurrent :: forall self. GLAreaClass self => self -> IO ()
glAreaMakeCurrent self
self =
    (\(GLArea ForeignPtr GLArea
arg1) -> ForeignPtr GLArea -> (Ptr GLArea -> IO ()) -> IO ()
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr ForeignPtr GLArea
arg1 ((Ptr GLArea -> IO ()) -> IO ()) -> (Ptr GLArea -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \Ptr GLArea
argPtr1 ->Ptr GLArea -> IO ()
gtk_gl_area_make_current Ptr GLArea
argPtr1) (self -> GLArea
forall o. GLAreaClass o => o -> GLArea
toGLArea self
self)


-- | Marks the currently rendered data (if any) as invalid, and queues a redraw
-- of the widget, ensuring that the 'glAreaRender' signal is emitted during the draw.
--
-- This is only needed when 'glAreaSetAutoRender' has been called with a False
-- value. The default behaviour is to emit 'glAreaRender' on each draw.
--
glAreaQueueRender :: GLAreaClass self => self -> IO ()
glAreaQueueRender :: forall self. GLAreaClass self => self -> IO ()
glAreaQueueRender self
self =
    (\(GLArea ForeignPtr GLArea
arg1) -> ForeignPtr GLArea -> (Ptr GLArea -> IO ()) -> IO ()
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr ForeignPtr GLArea
arg1 ((Ptr GLArea -> IO ()) -> IO ()) -> (Ptr GLArea -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \Ptr GLArea
argPtr1 ->Ptr GLArea -> IO ()
gtk_gl_area_queue_render Ptr GLArea
argPtr1) (self -> GLArea
forall o. GLAreaClass o => o -> GLArea
toGLArea self
self)


-- | Ensures that the area framebuffer object is made the current draw and read
-- target, and that all the required buffers for the area are created and
-- bound to the framebuffer.
--
-- This function is automatically called before emitting the 'glAreaRender' signal,
-- and doesn't normally need to be called by application code.
--
glAreaAttachBuffers :: GLAreaClass self => self -> IO ()
glAreaAttachBuffers :: forall self. GLAreaClass self => self -> IO ()
glAreaAttachBuffers self
self =
    (\(GLArea ForeignPtr GLArea
arg1) -> ForeignPtr GLArea -> (Ptr GLArea -> IO ()) -> IO ()
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr ForeignPtr GLArea
arg1 ((Ptr GLArea -> IO ()) -> IO ()) -> (Ptr GLArea -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \Ptr GLArea
argPtr1 ->Ptr GLArea -> IO ()
gtk_gl_area_attach_buffers Ptr GLArea
argPtr1) (self -> GLArea
forall o. GLAreaClass o => o -> GLArea
toGLArea self
self)


-- | Gets the current error set on the area.
--
glAreaGetError :: GLAreaClass self => self -> IO (Maybe GError)
glAreaGetError :: forall self. GLAreaClass self => self -> IO (Maybe GError)
glAreaGetError self
self = do
    Ptr ()
err <- (\(GLArea ForeignPtr GLArea
arg1) -> ForeignPtr GLArea -> (Ptr GLArea -> IO (Ptr ())) -> IO (Ptr ())
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr ForeignPtr GLArea
arg1 ((Ptr GLArea -> IO (Ptr ())) -> IO (Ptr ()))
-> (Ptr GLArea -> IO (Ptr ())) -> IO (Ptr ())
forall a b. (a -> b) -> a -> b
$ \Ptr GLArea
argPtr1 ->Ptr GLArea -> IO (Ptr ())
gtk_gl_area_get_error Ptr GLArea
argPtr1) (self -> GLArea
forall o. GLAreaClass o => o -> GLArea
toGLArea self
self)
    if Ptr ()
err Ptr () -> Ptr () -> Bool
forall a. Eq a => a -> a -> Bool
== Ptr ()
forall a. Ptr a
nullPtr
        then Maybe GError -> IO (Maybe GError)
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe GError
forall a. Maybe a
Nothing
        else (GError -> Maybe GError) -> IO GError -> IO (Maybe GError)
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM GError -> Maybe GError
forall a. a -> Maybe a
Just (Ptr GError -> IO GError
forall a. Storable a => Ptr a -> IO a
peek (Ptr GError -> IO GError) -> Ptr GError -> IO GError
forall a b. (a -> b) -> a -> b
$ Ptr () -> Ptr GError
forall a b. Ptr a -> Ptr b
castPtr Ptr ()
err)


-- | If hasAlpha is True the buffer allocated by the widget will have an alpha channel component,
-- and when rendering to the window the result will be composited over whatever is below the
-- widget.
--
-- If hasAlpha is False there will be no alpha channel, and the buffer will fully replace anything
-- below the widget.
--
glAreaSetHasAlpha :: GLAreaClass self => self -> Bool -> IO ()
glAreaSetHasAlpha :: forall self. GLAreaClass self => self -> Bool -> IO ()
glAreaSetHasAlpha self
self Bool
hasAlpha =
  (\(GLArea ForeignPtr GLArea
arg1) CInt
arg2 -> ForeignPtr GLArea -> (Ptr GLArea -> IO ()) -> IO ()
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr ForeignPtr GLArea
arg1 ((Ptr GLArea -> IO ()) -> IO ()) -> (Ptr GLArea -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \Ptr GLArea
argPtr1 ->Ptr GLArea -> CInt -> IO ()
gtk_gl_area_set_has_alpha Ptr GLArea
argPtr1 CInt
arg2)
{-# LINE 205 "./Graphics/UI/Gtk/Misc/GLArea.chs" #-}
    (toGLArea self)
    (Bool -> CInt
forall a. Num a => Bool -> a
fromBool Bool
hasAlpha)


-- | Returns whether the area has an alpha component.
--
glAreaGetHasAlpha :: GLAreaClass self => self -> IO Bool
glAreaGetHasAlpha :: forall self. GLAreaClass self => self -> IO Bool
glAreaGetHasAlpha self
self =
  (CInt -> Bool) -> IO CInt -> IO Bool
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM CInt -> Bool
forall a. (Eq a, Num a) => a -> Bool
toBool (IO CInt -> IO Bool) -> IO CInt -> IO Bool
forall a b. (a -> b) -> a -> b
$
    (\(GLArea ForeignPtr GLArea
arg1) -> ForeignPtr GLArea -> (Ptr GLArea -> IO CInt) -> IO CInt
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr ForeignPtr GLArea
arg1 ((Ptr GLArea -> IO CInt) -> IO CInt)
-> (Ptr GLArea -> IO CInt) -> IO CInt
forall a b. (a -> b) -> a -> b
$ \Ptr GLArea
argPtr1 ->Ptr GLArea -> IO CInt
gtk_gl_area_get_has_alpha Ptr GLArea
argPtr1) (self -> GLArea
forall o. GLAreaClass o => o -> GLArea
toGLArea self
self)


-- | If hasDepthBuffer is True the widget will allocate and enable a depth buffer for the target
-- framebuffer. Otherwise there will be none.
--
glAreaSetHasDepthBuffer :: GLAreaClass self => self -> Bool -> IO ()
glAreaSetHasDepthBuffer :: forall self. GLAreaClass self => self -> Bool -> IO ()
glAreaSetHasDepthBuffer self
self Bool
hasDepthBuffer =
  (\(GLArea ForeignPtr GLArea
arg1) CInt
arg2 -> ForeignPtr GLArea -> (Ptr GLArea -> IO ()) -> IO ()
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr ForeignPtr GLArea
arg1 ((Ptr GLArea -> IO ()) -> IO ()) -> (Ptr GLArea -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \Ptr GLArea
argPtr1 ->Ptr GLArea -> CInt -> IO ()
gtk_gl_area_set_has_depth_buffer Ptr GLArea
argPtr1 CInt
arg2)
{-# LINE 223 "./Graphics/UI/Gtk/Misc/GLArea.chs" #-}
    (toGLArea self)
    (Bool -> CInt
forall a. Num a => Bool -> a
fromBool Bool
hasDepthBuffer)


-- | Returns whether the area has a depth buffer.
--
glAreaGetHasDepthBuffer :: GLAreaClass self => self -> IO Bool
glAreaGetHasDepthBuffer :: forall self. GLAreaClass self => self -> IO Bool
glAreaGetHasDepthBuffer self
self =
  (CInt -> Bool) -> IO CInt -> IO Bool
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM CInt -> Bool
forall a. (Eq a, Num a) => a -> Bool
toBool (IO CInt -> IO Bool) -> IO CInt -> IO Bool
forall a b. (a -> b) -> a -> b
$
    (\(GLArea ForeignPtr GLArea
arg1) -> ForeignPtr GLArea -> (Ptr GLArea -> IO CInt) -> IO CInt
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr ForeignPtr GLArea
arg1 ((Ptr GLArea -> IO CInt) -> IO CInt)
-> (Ptr GLArea -> IO CInt) -> IO CInt
forall a b. (a -> b) -> a -> b
$ \Ptr GLArea
argPtr1 ->Ptr GLArea -> IO CInt
gtk_gl_area_get_has_depth_buffer Ptr GLArea
argPtr1) (self -> GLArea
forall o. GLAreaClass o => o -> GLArea
toGLArea self
self)


-- | If hasStencilBuffer is True the widget will allocate and enable a stencil buffer for the target
-- framebuffer. Otherwise there will be none.
--
glAreaSetHasStencilBuffer :: GLAreaClass self => self -> Bool -> IO ()
glAreaSetHasStencilBuffer :: forall self. GLAreaClass self => self -> Bool -> IO ()
glAreaSetHasStencilBuffer self
self Bool
hasStencilBuffer =
  (\(GLArea ForeignPtr GLArea
arg1) CInt
arg2 -> ForeignPtr GLArea -> (Ptr GLArea -> IO ()) -> IO ()
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr ForeignPtr GLArea
arg1 ((Ptr GLArea -> IO ()) -> IO ()) -> (Ptr GLArea -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \Ptr GLArea
argPtr1 ->Ptr GLArea -> CInt -> IO ()
gtk_gl_area_set_has_stencil_buffer Ptr GLArea
argPtr1 CInt
arg2)
{-# LINE 241 "./Graphics/UI/Gtk/Misc/GLArea.chs" #-}
    (toGLArea self)
    (Bool -> CInt
forall a. Num a => Bool -> a
fromBool Bool
hasStencilBuffer)


-- | Returns whether the area has a stencil buffer.
--
glAreaGetHasStencilBuffer :: GLAreaClass self => self -> IO Bool
glAreaGetHasStencilBuffer :: forall self. GLAreaClass self => self -> IO Bool
glAreaGetHasStencilBuffer self
self =
  (CInt -> Bool) -> IO CInt -> IO Bool
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM CInt -> Bool
forall a. (Eq a, Num a) => a -> Bool
toBool (IO CInt -> IO Bool) -> IO CInt -> IO Bool
forall a b. (a -> b) -> a -> b
$
    (\(GLArea ForeignPtr GLArea
arg1) -> ForeignPtr GLArea -> (Ptr GLArea -> IO CInt) -> IO CInt
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr ForeignPtr GLArea
arg1 ((Ptr GLArea -> IO CInt) -> IO CInt)
-> (Ptr GLArea -> IO CInt) -> IO CInt
forall a b. (a -> b) -> a -> b
$ \Ptr GLArea
argPtr1 ->Ptr GLArea -> IO CInt
gtk_gl_area_get_has_stencil_buffer Ptr GLArea
argPtr1) (self -> GLArea
forall o. GLAreaClass o => o -> GLArea
toGLArea self
self)


-- | If autoRender is True the 'glAreaRender' signal will be emitted every time the widget draws. This is
-- the default and is useful if drawing the widget is faster.
--
-- If autoRender is False the data from previous rendering is kept around and will be used for
-- drawing the widget the next time, unless the window is resized. In order to force a rendering
-- 'glAreaQueueRender' must be called. This mode is useful when the scene changes seldomly, but takes
-- a long time to redraw.
--
glAreaSetAutoRender :: GLAreaClass self => self -> Bool -> IO ()
glAreaSetAutoRender :: forall self. GLAreaClass self => self -> Bool -> IO ()
glAreaSetAutoRender self
self Bool
autoRender =
  (\(GLArea ForeignPtr GLArea
arg1) CInt
arg2 -> ForeignPtr GLArea -> (Ptr GLArea -> IO ()) -> IO ()
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr ForeignPtr GLArea
arg1 ((Ptr GLArea -> IO ()) -> IO ()) -> (Ptr GLArea -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \Ptr GLArea
argPtr1 ->Ptr GLArea -> CInt -> IO ()
gtk_gl_area_set_auto_render Ptr GLArea
argPtr1 CInt
arg2)
{-# LINE 264 "./Graphics/UI/Gtk/Misc/GLArea.chs" #-}
    (toGLArea self)
    (Bool -> CInt
forall a. Num a => Bool -> a
fromBool Bool
autoRender)

-- | Returns whether the area is in auto render mode or not.
--
glAreaGetAutoRender :: GLAreaClass self => self -> IO Bool
glAreaGetAutoRender :: forall self. GLAreaClass self => self -> IO Bool
glAreaGetAutoRender self
self =
  (CInt -> Bool) -> IO CInt -> IO Bool
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM CInt -> Bool
forall a. (Eq a, Num a) => a -> Bool
toBool (IO CInt -> IO Bool) -> IO CInt -> IO Bool
forall a b. (a -> b) -> a -> b
$
  (\(GLArea ForeignPtr GLArea
arg1) -> ForeignPtr GLArea -> (Ptr GLArea -> IO CInt) -> IO CInt
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr ForeignPtr GLArea
arg1 ((Ptr GLArea -> IO CInt) -> IO CInt)
-> (Ptr GLArea -> IO CInt) -> IO CInt
forall a b. (a -> b) -> a -> b
$ \Ptr GLArea
argPtr1 ->Ptr GLArea -> IO CInt
gtk_gl_area_get_auto_render Ptr GLArea
argPtr1)
{-# LINE 273 "./Graphics/UI/Gtk/Misc/GLArea.chs" #-}
    (toGLArea self)


-- | Retrieves the required version of OpenGL set using 'glAreaSetRequiredVersion'.
--
glAreaGetRequiredVersion :: GLAreaClass self => self -> IO (Int, Int)
glAreaGetRequiredVersion :: forall self. GLAreaClass self => self -> IO (Int, Int)
glAreaGetRequiredVersion self
self = do
    (Ptr CInt -> IO (Int, Int)) -> IO (Int, Int)
forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca ((Ptr CInt -> IO (Int, Int)) -> IO (Int, Int))
-> (Ptr CInt -> IO (Int, Int)) -> IO (Int, Int)
forall a b. (a -> b) -> a -> b
$ \Ptr CInt
majorPtr -> (Ptr CInt -> IO (Int, Int)) -> IO (Int, Int)
forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca ((Ptr CInt -> IO (Int, Int)) -> IO (Int, Int))
-> (Ptr CInt -> IO (Int, Int)) -> IO (Int, Int)
forall a b. (a -> b) -> a -> b
$ \Ptr CInt
minorPtr -> do
        (\(GLArea ForeignPtr GLArea
arg1) Ptr CInt
arg2 Ptr CInt
arg3 -> ForeignPtr GLArea -> (Ptr GLArea -> IO ()) -> IO ()
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr ForeignPtr GLArea
arg1 ((Ptr GLArea -> IO ()) -> IO ()) -> (Ptr GLArea -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \Ptr GLArea
argPtr1 ->Ptr GLArea -> Ptr CInt -> Ptr CInt -> IO ()
gtk_gl_area_get_required_version Ptr GLArea
argPtr1 Ptr CInt
arg2 Ptr CInt
arg3) (self -> GLArea
forall o. GLAreaClass o => o -> GLArea
toGLArea self
self) Ptr CInt
majorPtr Ptr CInt
minorPtr
        CInt
major <- Ptr CInt -> IO CInt
forall a. Storable a => Ptr a -> IO a
peek Ptr CInt
majorPtr
        CInt
minor <- Ptr CInt -> IO CInt
forall a. Storable a => Ptr a -> IO a
peek Ptr CInt
minorPtr
        (Int, Int) -> IO (Int, Int)
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (CInt -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral CInt
major, CInt -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral CInt
minor)


-- | Sets the required version of OpenGL to be used when creating the context for the widget.
--
-- This function must be called before the area has been realized.
--
glAreaSetRequiredVersion :: GLAreaClass self => self -> Int -> Int -> IO ()
glAreaSetRequiredVersion :: forall self. GLAreaClass self => self -> Int -> Int -> IO ()
glAreaSetRequiredVersion self
self Int
major Int
minor =
    (\(GLArea ForeignPtr GLArea
arg1) CInt
arg2 CInt
arg3 -> ForeignPtr GLArea -> (Ptr GLArea -> IO ()) -> IO ()
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr ForeignPtr GLArea
arg1 ((Ptr GLArea -> IO ()) -> IO ()) -> (Ptr GLArea -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \Ptr GLArea
argPtr1 ->Ptr GLArea -> CInt -> CInt -> IO ()
gtk_gl_area_set_required_version Ptr GLArea
argPtr1 CInt
arg2 CInt
arg3)
{-# LINE 294 "./Graphics/UI/Gtk/Misc/GLArea.chs" #-}
        (self -> GLArea
forall o. GLAreaClass o => o -> GLArea
toGLArea self
self) (Int -> CInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
major) (Int -> CInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
minor)



--------------------
-- Attributes



-- | If set to True the 'glAreaRender' signal will be emitted every time the widget draws. This is the
-- default and is useful if drawing the widget is faster.
--
-- If set to False the data from previous rendering is kept around and will be used for drawing the
-- widget the next time, unless the window is resized. In order to force a rendering
-- 'glAreaQueueRender' must be called. This mode is useful when the scene changes seldomly, but
-- takes a long time to redraw.
--
-- Default value: True
--
glAreaAutoRender :: GLAreaClass self => Attr self Bool
glAreaAutoRender :: forall self. GLAreaClass self => Attr self Bool
glAreaAutoRender = (self -> IO Bool)
-> (self -> Bool -> IO ()) -> ReadWriteAttr self Bool Bool
forall o a b.
(o -> IO a) -> (o -> b -> IO ()) -> ReadWriteAttr o a b
newAttr
  self -> IO Bool
forall self. GLAreaClass self => self -> IO Bool
glAreaGetAutoRender
  self -> Bool -> IO ()
forall self. GLAreaClass self => self -> Bool -> IO ()
glAreaSetAutoRender


-- | The 'Graphics.UI.Gtk.Gdk.GLContext.GLContext' used by the GLArea widget.
--
-- The GLArea widget is responsible for creating the 'Graphics.UI.Gtk.Gdk.GLContext.GLContext' instance. If you need to render with
-- other kinds of buffers (stencil, depth, etc), use render buffers.
--
glAreaContext :: GLAreaClass self => ReadAttr self (Maybe GLContext)
glAreaContext :: forall self. GLAreaClass self => ReadAttr self (Maybe GLContext)
glAreaContext = (self -> IO (Maybe GLContext)) -> ReadAttr self (Maybe GLContext)
forall o a. (o -> IO a) -> ReadAttr o a
readAttr self -> IO (Maybe GLContext)
forall self. GLAreaClass self => self -> IO (Maybe GLContext)
glAreaGetContext


-- | If set to True the buffer allocated by the widget will have an alpha channel component, and
-- when rendering to the window the result will be composited over whatever is below the widget.
--
-- If set to False there will be no alpha channel, and the buffer will fully replace anything below
-- the widget.
--
-- Default value: False
--
glAreaHasAlpha :: GLAreaClass self => Attr self Bool
glAreaHasAlpha :: forall self. GLAreaClass self => Attr self Bool
glAreaHasAlpha = (self -> IO Bool)
-> (self -> Bool -> IO ()) -> ReadWriteAttr self Bool Bool
forall o a b.
(o -> IO a) -> (o -> b -> IO ()) -> ReadWriteAttr o a b
newAttr
  self -> IO Bool
forall self. GLAreaClass self => self -> IO Bool
glAreaGetHasAlpha
  self -> Bool -> IO ()
forall self. GLAreaClass self => self -> Bool -> IO ()
glAreaSetHasAlpha


-- | If set to True the widget will allocate and enable a depth buffer for the target framebuffer.
--
-- Default value: False
--
glAreaHasDepthBuffer :: GLAreaClass self => Attr self Bool
glAreaHasDepthBuffer :: forall self. GLAreaClass self => Attr self Bool
glAreaHasDepthBuffer = (self -> IO Bool)
-> (self -> Bool -> IO ()) -> ReadWriteAttr self Bool Bool
forall o a b.
(o -> IO a) -> (o -> b -> IO ()) -> ReadWriteAttr o a b
newAttr
  self -> IO Bool
forall self. GLAreaClass self => self -> IO Bool
glAreaGetHasDepthBuffer
  self -> Bool -> IO ()
forall self. GLAreaClass self => self -> Bool -> IO ()
glAreaSetHasDepthBuffer


-- | If set to True the widget will allocate and enable a stencil buffer for the target framebuffer.
--
-- Default value: False
--
glAreaHasStencilBuffer :: GLAreaClass self => Attr self Bool
glAreaHasStencilBuffer :: forall self. GLAreaClass self => Attr self Bool
glAreaHasStencilBuffer = (self -> IO Bool)
-> (self -> Bool -> IO ()) -> ReadWriteAttr self Bool Bool
forall o a b.
(o -> IO a) -> (o -> b -> IO ()) -> ReadWriteAttr o a b
newAttr
  self -> IO Bool
forall self. GLAreaClass self => self -> IO Bool
glAreaGetHasStencilBuffer
  self -> Bool -> IO ()
forall self. GLAreaClass self => self -> Bool -> IO ()
glAreaSetHasStencilBuffer



--------------------
-- Signals



-- | The glAreaResize signal is emitted once when the widget is realized, and then each time the widget
-- is changed while realized. This is useful in order to keep GL state up to date with the widget
-- size, like for instance camera properties which may depend on the width/height ratio.
--
-- The GL context for the area is guaranteed to be current when this signal is emitted.
--
-- The default handler sets up the GL viewport.
--
glAreaResize :: GLAreaClass glac => Signal glac (Int -> Int -> IO ())
glAreaResize :: forall glac. GLAreaClass glac => Signal glac (Int -> Int -> IO ())
glAreaResize = (Bool -> glac -> (Int -> Int -> IO ()) -> IO (ConnectId glac))
-> Signal glac (Int -> Int -> IO ())
forall object handler.
(Bool -> object -> handler -> IO (ConnectId object))
-> Signal object handler
Signal (SignalName
-> Bool -> glac -> (Int -> Int -> IO ()) -> IO (ConnectId glac)
forall obj.
GObjectClass obj =>
SignalName
-> Bool -> obj -> (Int -> Int -> IO ()) -> IO (ConnectId obj)
connect_INT_INT__NONE SignalName
"resize")


-- | The glAreaRender signal is emitted every time the contents of the GLArea should be redrawn.
--
-- The context is bound to the area prior to emitting this function, and the buffers are painted
-- to the window once the emission terminates.
--
glAreaRender :: GLAreaClass glac => Signal glac (Maybe GLContext -> IO (Bool))
glAreaRender :: forall glac.
GLAreaClass glac =>
Signal glac (Maybe GLContext -> IO Bool)
glAreaRender = (Bool
 -> glac -> (Maybe GLContext -> IO Bool) -> IO (ConnectId glac))
-> Signal glac (Maybe GLContext -> IO Bool)
forall object handler.
(Bool -> object -> handler -> IO (ConnectId object))
-> Signal object handler
Signal (SignalName
-> (Ptr GLContext -> IO (Maybe GLContext))
-> Bool
-> glac
-> (Maybe GLContext -> IO Bool)
-> IO (ConnectId glac)
forall obj a' a.
GObjectClass obj =>
SignalName
-> (Ptr a' -> IO a)
-> Bool
-> obj
-> (a -> IO Bool)
-> IO (ConnectId obj)
connect_BOXED__BOOL SignalName
"render" Ptr GLContext -> IO (Maybe GLContext)
unwrapGLContextPtr)


unwrapGLContextPtr :: Ptr GLContext -> IO (Maybe GLContext)
unwrapGLContextPtr :: Ptr GLContext -> IO (Maybe GLContext)
unwrapGLContextPtr Ptr GLContext
ptr = do
    (IO (Ptr GLContext) -> IO GLContext)
-> IO (Ptr GLContext) -> IO (Maybe GLContext)
forall a. (IO (Ptr a) -> IO a) -> IO (Ptr a) -> IO (Maybe a)
maybeNull ((ForeignPtr GLContext -> GLContext, FinalizerPtr GLContext)
-> IO (Ptr GLContext) -> IO GLContext
forall obj.
GObjectClass obj =>
(ForeignPtr obj -> obj, FinalizerPtr obj) -> IO (Ptr obj) -> IO obj
makeNewGObject (ForeignPtr GLContext -> GLContext, FinalizerPtr GLContext)
forall {a}. (ForeignPtr GLContext -> GLContext, FinalizerPtr a)
mkGLContext) (Ptr GLContext -> IO (Ptr GLContext)
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Ptr GLContext
ptr)

foreign import ccall unsafe "gtk_gl_area_new"
  gtk_gl_area_new :: (IO (Ptr Widget))

foreign import ccall safe "gtk_gl_area_get_context"
  gtk_gl_area_get_context :: ((Ptr GLArea) -> (IO (Ptr GLContext)))

foreign import ccall safe "gtk_gl_area_make_current"
  gtk_gl_area_make_current :: ((Ptr GLArea) -> (IO ()))

foreign import ccall safe "gtk_gl_area_queue_render"
  gtk_gl_area_queue_render :: ((Ptr GLArea) -> (IO ()))

foreign import ccall safe "gtk_gl_area_attach_buffers"
  gtk_gl_area_attach_buffers :: ((Ptr GLArea) -> (IO ()))

foreign import ccall safe "gtk_gl_area_get_error"
  gtk_gl_area_get_error :: ((Ptr GLArea) -> (IO (Ptr ())))

foreign import ccall safe "gtk_gl_area_set_has_alpha"
  gtk_gl_area_set_has_alpha :: ((Ptr GLArea) -> (CInt -> (IO ())))

foreign import ccall unsafe "gtk_gl_area_get_has_alpha"
  gtk_gl_area_get_has_alpha :: ((Ptr GLArea) -> (IO CInt))

foreign import ccall safe "gtk_gl_area_set_has_depth_buffer"
  gtk_gl_area_set_has_depth_buffer :: ((Ptr GLArea) -> (CInt -> (IO ())))

foreign import ccall unsafe "gtk_gl_area_get_has_depth_buffer"
  gtk_gl_area_get_has_depth_buffer :: ((Ptr GLArea) -> (IO CInt))

foreign import ccall safe "gtk_gl_area_set_has_stencil_buffer"
  gtk_gl_area_set_has_stencil_buffer :: ((Ptr GLArea) -> (CInt -> (IO ())))

foreign import ccall unsafe "gtk_gl_area_get_has_stencil_buffer"
  gtk_gl_area_get_has_stencil_buffer :: ((Ptr GLArea) -> (IO CInt))

foreign import ccall safe "gtk_gl_area_set_auto_render"
  gtk_gl_area_set_auto_render :: ((Ptr GLArea) -> (CInt -> (IO ())))

foreign import ccall unsafe "gtk_gl_area_get_auto_render"
  gtk_gl_area_get_auto_render :: ((Ptr GLArea) -> (IO CInt))

foreign import ccall safe "gtk_gl_area_get_required_version"
  gtk_gl_area_get_required_version :: ((Ptr GLArea) -> ((Ptr CInt) -> ((Ptr CInt) -> (IO ()))))

foreign import ccall safe "gtk_gl_area_set_required_version"
  gtk_gl_area_set_required_version :: ((Ptr GLArea) -> (CInt -> (CInt -> (IO ()))))