1   module Init 
    2 
    3 
    4 
    5 
    6         (       initialiseMouse,initialiseScreen,
    7                 labelButtons,clearRender,clearTree,clearText,
    8                 toNoTextRegion,toTextRegion,
    9                 toMouseRegion,
   10                 indicate,labelClassify,labelDefinePoly,
   11                 unlabelButtons,mark,reset)
   12 
   13   where
   14   import Params (Command(..),Button(..),delimiter,renderHeight,windowWidth,
   15                  windowHeight,renderLeft,buttons,mouseCaptionAcross,
   16                  mouseCaptionDown,button1TextOrigin,button,button1Box,
   17                  button2Box,button3Box,mouseBox,
   18                  button2TextOrigin,button3TextOrigin,gap,renderRegion,
   19                  treeRegion,windowRegion,noTextRegion,textRegion,mouseRegion,
   20                  textIn,textDown,buttonIndent,buttonWidth,buttonHeight)
   21   import Stdlib (map2,mapcat,seQuence)
   22   import MGRlib (setEvent, setMode, setCursor, textReset, clear,
   23                  line, movePrintTo, printOver, setTextRegion, writeVert)
   24 
   25 
   26 
   27 
   28 
   29 
   30 
   31 
   32 
   33   initialiseMouse :: String
   34   initialiseMouse = seQuence [  setEvent 1 "%p\n",
   35                                 setEvent 2 (delimiter++"\n")]
   36 
   37 
   38 
   39 
   40 
   41 
   42 
   43 
   44 
   45 
   46   initialiseScreen :: String
   47   initialiseScreen =    seQuence [      setMode 7,
   48                                         setCursor 5, 
   49                                         textReset, 
   50                                         clear,
   51                                         drawScreen,
   52                                         toNoTextRegion]
   53 
   54 
   55 
   56 
   57 
   58 
   59 
   60 
   61 
   62 
   63 
   64   drawScreen :: String
   65   drawScreen =  seQuence [      line [0,renderHeight+1,windowWidth,renderHeight+1],
   66                                 line [renderLeft-1,0,renderLeft-1,windowHeight],
   67                                 drawButtons buttons,
   68                                 drawMouse]
   69 
   70 
   71 
   72 
   73 
   74 
   75 
   76 
   77 
   78 
   79   drawMouse :: String
   80   drawMouse = seQuence [        movePrintTo mouseCaptionAcross mouseCaptionDown "Mouse", 
   81                                 drawBox mouseBox,
   82                                 drawBox button1Box,
   83                                 drawBox button2Box,
   84                                 drawBox button3Box,
   85                                 writeVert button1TextOrigin (map2 spacer "RESERVED" "SYSTEM !"),
   86                                 labelButtons ("BUTTON   ","DISABLED ") ("SELECT   ","OPERATION")]
   87 
   88 
   89 
   90 
   91 
   92 
   93   labelButtons :: (String,String) -> (String,String) -> String
   94   labelButtons (label2_1,label2_2) (label3_1,label3_2)
   95                         = seQuence [    toMouseRegion,
   96                                         writeVert button2TextOrigin (map2 spacer label2_1 label2_2),
   97                                         writeVert button3TextOrigin (map2 spacer label3_1 label3_2),
   98                                         toNoTextRegion]
   99 
  100   spacer :: Char -> Char -> String
  101   spacer x y = x:gap:[y]
  102 
  103 
  104 
  105 
  106 
  107   clearRender :: String
  108   clearRender = clearRegion renderRegion
  109 
  110 
  111 
  112 
  113   clearTree :: String
  114   clearTree = clearRegion treeRegion
  115 
  116 
  117 
  118 
  119   clearButton :: Button -> String
  120   clearButton (_,d,_) = clearRegion (button d)
  121 
  122   clearRegion :: [Int] -> String
  123   clearRegion region = seQuence [setTextRegion (inside region), clear, toNoTextRegion]
  124 
  125   clearText :: String
  126   clearText = clear
  127 
  128   inside :: [Int] -> [Int]
  129   inside [top,left,width,height] = [top+1,left+1,width-2,height-2]
  130 
  131 
  132 
  133   toScreenRegion :: String
  134   toScreenRegion = setTextRegion windowRegion
  135 
  136 
  137 
  138 
  139   toNoTextRegion :: String
  140   toNoTextRegion = setTextRegion noTextRegion
  141 
  142 
  143 
  144 
  145   toTextRegion :: String
  146   toTextRegion = setTextRegion textRegion
  147 
  148 
  149 
  150 
  151   toMouseRegion :: String
  152   toMouseRegion = setTextRegion mouseRegion
  153 
  154 
  155 
  156 
  157 
  158   drawButtons :: [Button] -> String
  159   drawButtons = mapcat drawButton
  160 
  161 
  162 
  163 
  164 
  165 
  166 
  167 
  168   drawButton :: Button -> String
  169   drawButton (_,d,name) = seQuence [    printOver textIn (d+textDown) name,
  170                                         drawBox [buttonIndent,d,buttonWidth,buttonHeight]  ]
  171 
  172 
  173 
  174 
  175 
  176 
  177   mark :: Command -> String
  178   mark cmd = seQuence [ toScreenRegion,
  179                         mapcatButton clearButton cmd buttons,
  180                         toNoTextRegion]
  181 
  182 
  183 
  184   noMark :: Command -> String
  185   noMark cmd = seQuence [       toScreenRegion, 
  186                         mapcatButton title cmd buttons, 
  187                         toNoTextRegion]
  188                 where   
  189                 title (_,d,str) = movePrintTo textIn (d+textDown) str 
  190 
  191 
  192 
  193 
  194 
  195 
  196   mapcatButton :: (Button->String) -> Command -> [Button] -> String
  197   mapcatButton f cmd [] = []
  198   mapcatButton f cmd (butt@(cmd',_,_):butts) 
  199                                 | cmd==cmd' = mapcat f butts
  200                                 | otherwise = f butt ++ mapcatButton f cmd butts
  201 
  202 
  203 
  204 
  205 
  206 
  207   drawBox :: [Int] -> String
  208   drawBox [x,y,width,height] = seQuence [       line [x,y,x,y+height],
  209                                                 line [x,y+height,x+width,y+height],
  210                                                 line [x+width,y+height,x+width,y],
  211                                                 line [x+width,y,x,y]]
  212 
  213 
  214 
  215 
  216 
  217 
  218   reset :: String
  219   reset = seQuence [mark Quit, textReset, setCursor 0]
  220 
  221 
  222 
  223 
  224 
  225   indicate :: Command -> [String] -> String
  226   indicate Null _ = ""
  227   indicate cmd str = mark cmd ++ seQuence str ++ noMark cmd
  228 
  229 
  230 
  231 
  232 
  233   unlabelButtons = labelButtons ("BUTTON   ","DISABLED ")
  234                                  ("SELECT   ","OPERATION")
  235 
  236   labelDefinePoly = labelButtons ("COMPLETE ","POLYGON  ")
  237                                    ("DEFINE   ","VERTEX   ")
  238 
  239   labelClassify = labelButtons ("FINISH   ","CLASSIFY ")
  240                                 ("CLASSIFY ","POINT    ")
  241 
  242