we can haz GUI?

we can.
This commit is contained in:
Stefan Dresselhaus
2014-04-05 23:09:57 +02:00
parent a24b562a88
commit 26903deb19
4 changed files with 63 additions and 8 deletions

View File

@ -6,6 +6,14 @@ import Control.Monad.Trans (liftIO)
import Types
import UI.UITypes
import qualified Graphics.Rendering.OpenGL.GL as GL
import Control.Lens ((^.), (.~), (%~))
import Render.Misc (genColorData)
import Foreign.Marshal.Array (pokeArray)
import Foreign.Marshal.Alloc (allocaBytes)
import Control.Monad.RWS.Strict (get, liftIO, modify)
data Pixel = Pixel Int Int
getGUI :: [GUIAny]
@ -47,12 +55,48 @@ alternateClickHandler :: Pixel -> Pioneers ()
alternateClickHandler (Pixel x y) = liftIO $ putStrLn $ unwords ["alternate press on (",show x,",",show y,")"]
-- | informs the GUI to prepare a blitting of state ^. gl.hudTexture
-- | informs the GUI to prepare a blitting of state ^. gl.glHud.hudTexture
--
--TODO: should be done asynchronously at one point.
-- -> can't. if 2 Threads bind Textures its not sure
-- on which one the GPU will work.
-- "GL.textureBinding GL.Texture2D" is a State set
-- to the texture all following works on.
--
-- https://www.opengl.org/wiki/GLAPI/glTexSubImage2D for copy
prepareGUI :: Pioneers ()
prepareGUI = do
return ()
state <- get
let tex = (state ^. gl.glHud.hudTexture)
liftIO $ do
-- bind texture - all later calls work on this one.
GL.textureBinding GL.Texture2D GL.$= Just tex
mapM_ (copyGUI tex) getGUI
modify $ ui.uiHasChanged .~ False
--TODO: Perform border-checking ... is xoff + width and yoff+height inside the screen-coordinates..
copyGUI :: GL.TextureObject -> GUIAny -> IO ()
copyGUI tex widget = do
let (xoff, yoff, width, height) = getBoundary widget
int = fromInteger.toInteger --conversion between Int8, GLInt, Int, ...
--temporary color here. lateron better some getData-function to
--get a list of pixel-data or a texture.
color = case widget of
(GUIAnyC _) -> [255,0,0,128]
(GUIAnyB _ _) -> [255,255,0,255]
(GUIAnyP _) -> [128,128,128,255]
_ -> [255,0,255,255]
allocaBytes (width*height*4) $ \ptr -> do
--copy data into C-Array
pokeArray ptr (genColorData (width*height) color)
GL.texSubImage2D
GL.Texture2D
0
(GL.TexturePosition2D (int xoff) (int yoff))
(GL.TextureSize2D (int width) (int height))
(GL.PixelData GL.RGBA GL.UnsignedByte ptr)
mapM_ (copyGUI tex) (getChildren widget)
copyGUI _ _ = return ()
--TODO: Add scroll-Handler, return (Pioneers Bool) to indicate event-bubbling etc.
--TODO: Maybe queues are better?