\ graphics 05.1.23 NAB

module graphics

public:

: line ( y2 x2 y1 x1 --)  WinDrawLine ;
: point ( y x -- )  2dup WinDrawLine ;

private:

variable cx  variable cy
: rpoint ( y x --)
  cx @ +  swap  cy @ + swap point ;
: point2 ( y x -- y x)
  2dup 2dup swap rpoint rpoint ;
: point4 ( y x -- y -x)
  point2  negate  point2 ;
: point8 ( y x --)
  point4  swap negate swap  point4
  2drop ;

public:

: circle ( radius cy cx --)
  cx !  cy !
  dup negate >r 0 swap
  begin
    2dup > invert while
      2dup point8
      over 2* 1+  r> + >r
      r@ 0 > if  1-  r> over 2* - >r  then
      swap 1+ swap
  repeat  2drop  r> drop ;

: rounded-rectangle
  ( height width y x corner-radius --)
  >r sp@ r> rot rot
  WinDrawRectangle
  2drop 2drop ;

: rectangle ( height width y x --)
  0 rounded-rectangle ;

: erase-rounded-rectangle
( height width y x corner-radius -- )
  >r sp@ r> rot rot
  WinEraseRectangle  2drop 2drop ;

: erase-rectangle
( height width y x --)
  0 erase-rounded-rectangle ;

private:

create fb  4 cells allot

public:

: frame
  ( height width y x frame-type --)
  >r fb !  fb cell+ !  fb 2 cells + !
  fb  3 cells + !  fb >abs
  r> WinDrawRectangleFrame ;

: at ( y x --)  currentx !  currenty ! ;

: cursor-position ( -- y x )
  currenty @  currentx @ ;

end-module
