FB II Compiler

PG PRO

Debugging

Memory

System

Mathematics

Resources

Disk I/O

Windows

Controls

Menus

Mouse

Keyboard

Text

Fonts

Drawing

Sound

Clipboard

Printing

Communication

ASM

Made with FB

MATHEMATICS

Detect if a point is inside a triangle


'This function draws a shape or outline shape during a window refresh
'and sets up a set of regions for use in quick rebuilds and mouse actions
' sorry about the variables saying "poly" but then doing region things...
'global variables are prefixed by g
LOCAL FN drawregion(start)             ' start is the point in my X,Y array to start a shape
  DIM poly&,t,poly2&
  t=start
  INC(gorder)                          'index to array of regions
  LONG IF gd(gset,start+1)=_polymarker'gd holds a marker to say solid shape or line
    LONG IF gregion&(gorder)=0         'region already built?
      poly&=FN NEWRGN                  'no - build a new one
      LONG IF poly&
        CALL OPENRGN
        INC(t)
        DO
          FN oldplot(t,0,0)            'Calls to LINETO and FN myarc
          INC(t)
        UNTIL (gX(gset,t)=_marker OR t>gmaxindex(gset)-1)
        CALL LINETO(FN zoomx(gx(gset,start+1)),FN zoomy(gy(gset,start+1)))
        ' last line to close region
        CALL CLOSERGN(poly&)
        CALL PAINTRGN(poly&)
        CALL DISPOSERGN(poly&)
        poly&=0
        gregion&(gorder)=poly&
      XELSE
        gOSerr%=2                      'this global is picked up in the calling FN
      END IF
    XELSE
      CALL PAINTRGN(gregion&(gorder))  'region already built - just draw
    END IF
  XELSE                                'This is the code for a outline shape only
    LONG IF gregion&(gorder)=0
      poly&=FN NEWRGN                  'this is similar to above
      LONG IF poly&
        CALL OPENRGN
        INC(t)
        DO
          FN oldplot(t,0,0)
          INC(t)
        UNTIL (gX(gset,t)=_marker OR t>gmaxindex(gset)-1)
        CALL LINETO(FN zoomx(gx(gset,start+1)),FN zoomy(gy(gset,start+1)))
        CALL CLOSERGN(poly&)
        CALL FRAMERGN(poly&)

        poly2&=FN NEWRGN               'this is new bit to determine just the outline region
        LONG IF poly2&
          CALL COPYRGN(poly&,poly2&)   'copy
          CALL INSETRGN(poly2&,1,1)    'make region 2 bigger
          CALL INSETRGN(poly&,-1,-1)   'shrink region 1
          CALL XORRGN(poly&,poly2&,poly&)'subtract regions
          CALL DISPOSERGN(poly2&)      'forget about region 2
        XELSE
          gOSerr%=2
        END IF
        gregion&(gorder)=poly&
      XELSE
        gOSerr%=2
      END IF
    XELSE
      CALL FRAMERGN(poly&)
    END IF
  END IF
END IF
END FN

'In MOUSE actions check for mouse point-in-region using the gregion& array and react
'accordingly - I change the cursor type when over a region and change to edit mode
'when the region is clicked.
Andy