diff --git a/CG2.cabal b/CG2.cabal index 3ace93b..6d99a34 100644 --- a/CG2.cabal +++ b/CG2.cabal @@ -60,7 +60,7 @@ executable CG2 -- other-extensions: -- Other library packages from which modules are imported. - build-depends: base >=4.7 && <4.8, diagrams-lib >=1.2 && <1.3, diagrams-cairo >=1.2 && <1.3, transformers >=0.4 && <0.5, gtk >=0.12 && <0.13, directory >=1.2 && <1.3 + build-depends: base >=4.7 && <4.8, diagrams-lib >=1.2 && <1.3, diagrams-cairo >=1.2 && <1.3, transformers >=0.4 && <0.5, glade >=0.12 && <0.13, gtk >=0.12 && <0.13, directory >=1.2 && <1.3 -- Directories containing source files. -- hs-source-dirs: diff --git a/Gtk.hs b/Gtk.hs index caf72c0..dd7af85 100644 --- a/Gtk.hs +++ b/Gtk.hs @@ -6,11 +6,15 @@ import Diagrams.Prelude import Diagrams.Backend.Cairo import Diagrams.Backend.Cairo.Internal import Graphics.UI.Gtk +import Graphics.UI.Gtk.Glade import Graphics.UI.Gtk.Windows.MessageDialog import System.Directory import Util +gladeFile :: FilePath +gladeFile = "gtk2.glade" + -- |Handle the whole GTK gui. makeGUI :: FilePath -> IO () makeGUI startFile = do @@ -19,46 +23,20 @@ makeGUI startFile = do -- init gui _ <- initGUI - -- create window and widgets - window <- windowNew - da <- drawingAreaNew - fileButton <- fileChooserButtonNew "Select mesh" - FileChooserActionOpen - drawButton <- buttonNew - saveButton <- buttonNew - quitButton <- buttonNew - box1 <- vBoxNew False 0 - box2 <- hButtonBoxNew - box3 <- hBoxNew False 0 - hscale <- hScaleNewWithRange 0.1 10 0.5 - drawButtonLabel <- labelNew $ Just "Draw" - saveButtonLabel <- labelNew $ Just "Save" - quitButtonLabel <- labelNew $ Just "Quit" - - -- containers and boxing - containerAdd drawButton drawButtonLabel - containerAdd saveButton saveButtonLabel - containerAdd quitButton quitButtonLabel - containerAdd window box1 - boxPackStart box1 da PackGrow 0 - boxPackStart box1 box2 PackNatural 0 - boxPackStart box1 box3 PackNatural 0 - boxPackStart box2 drawButton PackNatural 0 - boxPackStart box2 saveButton PackNatural 0 - boxPackStart box2 quitButton PackNatural 0 - boxPackStart box3 fileButton PackGrow 5 - boxPackStart box3 hscale PackGrow 5 + -- load glade file + Just xml <- xmlNew gladeFile + window <- xmlGetWidget xml castToWindow "window1" + drawButton <- xmlGetWidget xml castToButton "drawButton" + saveButton <- xmlGetWidget xml castToButton "saveButton" + quitButton <- xmlGetWidget xml castToButton "quitButton" + fileButton <- xmlGetWidget xml castToFileChooserButton + "filechooserButton" + da <- xmlGetWidget xml castToDrawingArea "drawingarea" + hscale <- xmlGetWidget xml castToHScale "hscale" -- adjust properties - set window [windowDefaultWidth := 600, windowDefaultHeight := 700, - windowTitle := "Computergrafik"] - set box2 [buttonBoxLayoutStyle := ButtonboxCenter] - containerSetBorderWidth box2 10 - _ <- windowSetTypeHint window WindowTypeHintDialog _ <- fileChooserSetCurrentFolder fileButton homedir _ <- fileChooserSetFilename fileButton startFile - adjustment <- rangeGetAdjustment hscale - _ <- adjustmentSetValue adjustment 2 -- callbacks _ <- onDestroy window mainQuit diff --git a/gtk2.glade b/gtk2.glade new file mode 100644 index 0000000..30b09ff --- /dev/null +++ b/gtk2.glade @@ -0,0 +1,117 @@ + + + + + + 600 + 700 + False + dialog + + + True + False + + + 600 + 600 + True + False + + + True + True + 0 + + + + + True + False + + + Draw + True + True + True + + + True + True + 0 + + + + + Save + True + True + True + + + True + True + 1 + + + + + Quit + True + True + True + + + True + True + 2 + + + + + False + False + 1 + + + + + True + False + + + True + False + False + + + True + True + 0 + + + + + True + True + 1 0.10000000000000001 10 0.5 0.5 0 + 1 + left + + + True + True + 1 + + + + + False + False + 2 + + + + + +