%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \begin{code} module TexEditor.SignalActions ( drawEditorTexture, applyChanges, previewChanges, selectDialogTab , changeTextureType, selectComboPos, refreshTexType , menuNewFileAction, menuOpenFileAction, menuExitAction ) where \end{code} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \begin{code} import Graphics.UI.Gtk( mainQuit, widgetSetSensitive, widgetHide ) import Graphics.UI.Gtk.Display.Image( Image ) import Graphics.UI.Gtk.ModelView ( TreeView, treeStoreSetValue, treeStoreGetTree, treeViewGetCursor , treeStoreClear, treeStoreInsert ) import Graphics.UI.Gtk.MenuComboToolbar.ComboBox ( ComboBox, comboBoxGetActive, comboBoxSetActive ) import Graphics.UI.Gtk.Layout.Notebook( Notebook, notebookSetCurrentPage ) import Graphics.UI.Gtk.Buttons.Button( Button ) import Graphics.UI.Gtk.Windows.Dialog( dialogRun, ResponseId(..) ) import Graphics.UI.Gtk.Selectors.FileChooser( fileChooserGetFilename ) import Graphics.UI.Gtk.Selectors.FileChooserDialog( FileChooserDialog ) import Data.Tree( Tree(..) ) import Control.Monad( when ) import Graphics.HDemo.TexGen ( TextureTree(..), ChannelTree(..), generateTexture ) import Graphics.HDemo.Files( readGTB ) import TexEditor.Data ( MainData, EdChannelTree, EditorData(..), TreeModelRow(..) , getChannelTree, numChilds, defaultTextureTreeNode ) import TexEditor.Dialogs( ApplyAction, PreviewAction, UpdateAction ) import TexEditor.Utils ( getCurrentTreeNode, fixSubTree, putTexture, getTexture ) import TexEditor.Data( EdNodeType(..) ) \end{code} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \begin{code} drawEditorTexture :: Image -> EditorData -> IO () drawEditorTexture preview (ED red green blue) = do putStr "Generating texture..." texture <- getTexture red green blue putTexture preview texture putStrLn "done" \end{code} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \begin{code} applyChanges :: MainData -> [ApplyAction] -> IO () applyChanges (combo, channels, ed) funs = do comboPos <- comboBoxGetActive combo when (comboPos /= -1) $ do (pg, path) <- getCurrentTreeNode channels newnode <- (funs !! comboPos) let store = getChannelTree (toEnum pg) ed treeStoreSetValue store path newnode \end{code} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \begin{code} previewChanges :: MainData -> Image -> [PreviewAction] -> IO () previewChanges (combo, channels, ed) image funs = do comboPos <- comboBoxGetActive combo when (comboPos /= -1) $ do (pg, path) <- getCurrentTreeNode channels let store = getChannelTree (toEnum pg) ed Node _ xs <- treeStoreGetTree store path (funs !! comboPos) xs image (toEnum pg) \end{code} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \begin{code} selectDialogTab :: Notebook -> ComboBox -> IO () selectDialogTab dialogs combo = do comboPos <- comboBoxGetActive combo notebookSetCurrentPage dialogs comboPos \end{code} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \begin{code} changeTextureType :: MainData -> Button -> IO () changeTextureType (combo, channels, ed) button = do (pg, path) <- getCurrentTreeNode channels let store = getChannelTree (toEnum pg) ed Node t xs <- treeStoreGetTree store path comboPos <- comboBoxGetActive combo when (comboPos /= -1) $ do let newType = toEnum comboPos when (newType /= tmType t) $ do treeStoreSetValue store path $ defaultTextureTreeNode newType fixSubTree store path (numChilds newType) (length xs) widgetSetSensitive button True \end{code} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \begin{code} selectComboPos :: MainData -> [UpdateAction] -> Int -> IO () selectComboPos (combo, channels, ed) funs _ = do (pg, path) <- getCurrentTreeNode channels when (not $ null path) $ do let store = getChannelTree (toEnum pg) ed Node t _ <- treeStoreGetTree store path let comboPos = fromEnum . tmType $ t comboBoxSetActive combo comboPos (funs !! comboPos) t \end{code} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \begin{code} refreshTexType :: ComboBox -> TreeView -> EdChannelTree -> [UpdateAction] -> IO () refreshTexType combo tree store funs = do cursor <- treeViewGetCursor tree if null $ fst cursor then do widgetSetSensitive combo False comboBoxSetActive combo (-1) else do widgetSetSensitive combo True Node t _ <- treeStoreGetTree store $ fst cursor let comboPos = fromEnum . tmType $ t comboBoxSetActive combo comboPos (funs !! comboPos) t \end{code} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \begin{code} menuNewFileAction :: EditorData -> ComboBox -> Image -> IO () menuNewFileAction (ED red green blue) combo preview = do treeStoreClear red treeStoreInsert red [] 0 $ defaultTextureTreeNode ENT_COLOR treeStoreClear green treeStoreInsert green [] 0 $ defaultTextureTreeNode ENT_COLOR treeStoreClear blue treeStoreInsert blue [] 0 $ defaultTextureTreeNode ENT_COLOR putTexture preview $ generateTexture (TexTree 256 256 [] (COLOR 0) (COLOR 0) (COLOR 0)) widgetSetSensitive combo False comboBoxSetActive combo (-1) \end{code} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \begin{code} menuOpenFileAction :: FileChooserDialog -> IO () menuOpenFileAction dialog = do response <- dialogRun dialog case response of ResponseOk -> do file <- fileChooserGetFilename dialog case file of Just fpath -> putStrLn ("You selected: " ++ fpath) Nothing -> putStrLn "Nothing" _ -> return () widgetHide dialog \end{code} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \begin{code} menuExitAction :: IO () menuExitAction = mainQuit \end{code} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%