<commit_before>module Main (main) where

import Game.Halma.Board
import Game.Halma.Board.Draw
import Graphics.UI.Gtk
import Diagrams.Prelude
import Diagrams.Backend.Gtk
import Data.AffineSpace.Point
import Control.Monad.Trans (liftIO)

main :: IO ()
main = do
  _ <- initGUI
  window <- windowNew
  canvas <- drawingAreaNew
  let renderFigure = do
        --liftIO $ defaultRender canvas (toGtkCoords figure)
        win <- eventWindow
        liftIO $ renderToGtk win figure
        return True
  --button <- buttonNew
  _ <- canvas `on` sizeRequest $ return (Requisition 400 400)
  set window [ containerBorderWidth := 10, containerChild := canvas ]
  _ <- canvas `on` exposeEvent $ renderFigure
  --set button [ buttonLabel := "Hello World" ]
  --onClicked button (putStrLn "Hello World")
  _ <- onDestroy window mainQuit
  canvas `on` buttonPressEvent $ tryEvent $ do
    click <- eventClick
    (x,y) <- eventCoordinates
    let result = runQuery (query $ toGtkCoords figure) (P (r2 (x, y)))
    liftIO $ print result
  widgetShowAll window
  mainGUI
  where
    board  = initialBoard SmallGrid twoPlayers
    figure = toGtkCoords $ scale 20 $ drawBoard board defaultTeamColours<commit_msg>Resize and center halma board<commit_after>{-# LANGUAGE TypeFamilies #-}

module Main (main) where

import Game.Halma.Board
import Game.Halma.Board.Draw
import Graphics.UI.Gtk
import Diagrams.Prelude
import Diagrams.TwoD.Size (requiredScale)
import Diagrams.Backend.Gtk
import Data.AffineSpace.Point
import Control.Monad.Trans (liftIO)

sizedCentered :: (Transformable a, Enveloped a, V a ~ R2) => SizeSpec2D -> a -> a
sizedCentered spec d = transform adjustT d
  where
    size = size2D d
    s    = requiredScale spec size
    finalSz = case spec of
      Dims w h -> (w,h)
      _        -> scale s size
    tr = (0.5 *. p2 finalSz) .-. (s *. center2D d)
    adjustT = translation tr <> scaling s

main :: IO ()
main = do
  _ <- initGUI
  window <- windowNew
  canvas <- drawingAreaNew
  let board = initialBoard SmallGrid twoPlayers
      resizedFigure = do
        let figure = toGtkCoords $ drawBoard board defaultTeamColours # pad 1.05
        drawWin <- widgetGetDrawWindow canvas
        (w,h) <- drawableGetSize drawWin
        return $ sizedCentered (Dims (fromIntegral w) (fromIntegral h)) figure
      renderFigure = do
        win <- eventWindow
        liftIO $ resizedFigure >>= renderToGtk win
        return True
  _ <- canvas `on` sizeRequest $ return (Requisition 400 400)
  set window [ containerBorderWidth := 10, containerChild := canvas ]
  _ <- canvas `on` exposeEvent $ renderFigure
  _ <- onDestroy window mainQuit
  _ <- canvas `on` buttonPressEvent $ tryEvent $ do
    _click <- eventClick
    (x,y) <- eventCoordinates
    figure <- liftIO resizedFigure
    let result = runQuery (query figure) (P (r2 (x, y)))
    liftIO $ print result
  widgetShowAll window
  mainGUI
{'fraction_non_alphanumeric': 0.09087767795438839, 'fraction_numerical': 0.010366275051831375, 'mean_word_length': 3.123931623931624, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6040595', 'n_tokens_mistral': 942, 'n_tokens_neox': 885, 'n_words': 284}