-- | Main module for playing Chu Shogi interactively -- Copyright 2009 Colin Adams -- -- This file is part of chu-shogi. -- -- Chu-shogi is free software: you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation, either version 3 of the License, or -- (at your option) any later version. -- Chu-shogi 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 General Public License for more details. -- You should have received a copy of the GNU General Public License -- along with chu-shogi. If not, see . module Main where import Data.IORef import Graphics.UI.Gtk hiding (function) import SVG import UI import Menu import Game_state hiding (pieces) main :: IO () main = do rotate_ior <- newIORef False game_state_ior <- newIORef new_game_state pieces <- new_pieces unsafeInitGUIForThreadedRTS window <- windowNew window `onDestroy` mainQuit set window [ windowTitle := "Chu Shogi 3" , windowResizable := True ] outer_box <- vBoxNew False 0 board_pixbuf <- pixbufNewFromFile "images/board.gif" ctxt <- cairoCreateContext Nothing text_layout <- layoutEmpty ctxt width <- pixbufGetWidth board_pixbuf height <- pixbufGetHeight board_pixbuf canvas <- drawingAreaNew onSizeRequest canvas $ return (Requisition width height) widgetSetCanFocus canvas True on canvas keyPressEvent $ handle_key_press canvas game_state_ior cid1 <- on canvas exposeEvent $ update_canvas pieces board_pixbuf game_state_ior text_layout rotate_ior cid2 <- on canvas exposeEvent $ update_canvas_second_move pieces board_pixbuf game_state_ior text_layout rotate_ior cid3 <- on canvas buttonPressEvent $ handle_mouse_press canvas board_pixbuf game_state_ior rotate_ior cid4 <- on canvas buttonPressEvent $ handle_mouse_press_second_move canvas board_pixbuf game_state_ior rotate_ior cid5 <- on canvas buttonReleaseEvent $ handle_mouse_release canvas game_state_ior cid6 <- on canvas buttonReleaseEvent handle_mouse_release_second_move let function = save_signals (Just cid1, Just cid2, Just cid3, Just cid4, Just cid5, Just cid6) modifyIORef game_state_ior function signalBlock cid2 signalBlock cid4 signalBlock cid6 (menu_bar, tool_bar) <- make_menu_bar game_state_ior rotate_ior canvas function status_bar <- statusbarNew -- Assemble the widgets boxPackStart outer_box menu_bar PackNatural 0 boxPackStart outer_box tool_bar PackNatural 0 boxPackStart outer_box canvas PackGrow 0 boxPackStart outer_box status_bar PackNatural 0 set window [ containerChild := outer_box ] widgetShowAll window mainGUI