REM > JLibraries:Draw.2
REM © James Bursa, 1997

REM JB  05 Dec 1997     created


DEF PROCDraw_Init
cm = 18141.73228 :REM 46080 / 2.54
ENDPROC

REM ˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜

DEF PROCDraw_InitFile(Word%, Name$, Crea$, Font$(), Land%, Mult%, Divi%)
LOCAL Draw%, Size%, Loop%, Obje%

cm = 46080 / 2.54

Size% = SUMLEN Font$() + 2 * (DIM(Font$(), 1) + 1)
Size% = ((Size% - 1) AND NOT(3)) + 4

IF NOT FNHeap_Grab(4+40+8+Size%, Word%, Name$) THEN ERROR Erro_Memo%, ""
Draw% = FNHeap_Find(Word%, Name$)
Draw%!00 = 40+8+Size%           :REM file length

$(Draw% + 04) = "Draw"          :REM file header
Draw%!08 = 201
Draw%!12 = 0
$(Draw% + 16) = LEFT$(Crea$ + "            ", 12)
Draw%!28 = 0
Draw%!32 = 0
Draw%!36 = 0
Draw%!40 = 0

Obje% = Draw% + 44
Obje%!00 = 0                    :REM font table object
Obje%!04 = Size% + 8
Obje% += 8
 FOR Loop% = 0 TO DIM(Font$(), 1)
  Obje%?00 = Loop% + 1
  $(Obje% + 01) = Font$(Loop%)
  Obje%?(1 + LEN Font$(Loop%)) = 0
  Obje% += 2 + LEN Font$(Loop%)
 NEXT
 WHILE (Obje% MOD 4)
  ?Obje% = 0
  Obje% += 1
 ENDWHILE

Obje% = FNDraw_Object(Word%, Name$, 64, 11, 0, 0, 0, 0)
Obje%!00 = &500
 IF Land% THEN
  Obje%!04 = %100010001
 ELSE
  Obje%!04 = %100000001
 ENDIF
Obje%!08 = &3FF00000
Obje%!12 = 0
Obje%!16 = 2
Obje%!20 = 0
Obje%!24 = 1
Obje%!28 = 0
Obje%!32 = 0
Obje%!36 = 1
Obje%!40 = Mult%
Obje%!44 = Divi%
Obje%!48 = 0
Obje%!52 = 1
Obje%!56 = 1<<7
Obje%!60 = 0
ENDPROC

REM ˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜

DEF FNDraw_Object(Word%, Name$, Size%, Type%, MinX%, MinY%, MaxX%, MaxY%)
LOCAL Draw%, Obje%
Draw% = FNHeap_Find(Word%, Name$)
IF NOT FNHeap_ReAlloc(Draw%, 4 + !Draw% + 24 + Size%) THEN ERROR Erro_Memo%, ""
Draw% = FNHeap_Find(Word%, Name$)
Obje% = 4 + Draw% + !Draw%
!Draw% += 24 + Size%
Obje%!00 = Type%
Obje%!04 = 24 + Size%
Obje%!08 = MinX%
Obje%!12 = MinY%
Obje%!16 = MaxX%
Obje%!20 = MaxY%
=Obje% + 24

REM ˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜

DEF PROCDraw_Text(Word%, Name$, Font%, Font$, Text$, Xpts, Ypts, XPos%, YPos%, XJus%, YJus%, FCol%, BCol%, Mat1%, Mat2%, Mat3%, Mat4%)
LOCAL Hand%, Wide, High, Obje%, Size%, MinX%, MinY%, MaxX%, MaxY%

B%!400 = 0
B%!404 = 0
B%!408 = 0
B%!412 = 0
B%!416 = -1

B%!440 = Mat1%
B%!444 = Mat2%
B%!448 = Mat3%
B%!452 = Mat4%
B%!456 = 0
B%!460 = 0

SYS"Font_FindFont",, Font$, Xpts * 16, Ypts * 16 TO Hand%
SYS"Font_ScanString", Hand%, Text$, %1000000001001100000, &FFFFFFFF, &FFFFFFFF, B% + 400, B% + 440
SYS"Font_LoseFont", Hand%

MinX% = B%!420 / 1.5625
MinY% = B%!424 / 1.5625
MaxX% = B%!428 / 1.5625
MaxY% = B%!432 / 1.5625
REMPROCBUG("MinX% = "+STR$MinX%+", MinY% = "+STR$MinY%)
Wide = MaxX% - MinX%
High = MaxY% - MinY%
REMPROCBUG("Wide = "+STR$Wide+", High = "+STR$High)
XPos% -= MinX%
IF XJus% = 2 THEN XPos% -= Wide / 2
IF XJus% = 3 THEN XPos% -= Wide
YPos% -= MinY%
IF YJus% = 2 THEN YPos% -= High / 2
IF YJus% = 3 THEN YPos% -= High
REMPROCBUG("XPos% = "+STR$XPos%+", YPos% = "+STR$YPos%)

Size% = ((LEN Text$) AND NOT(3)) + 4
Obje% = FNDraw_Object(Word%, Name$, 56 + Size%, 12, XPos%, YPos%, XPos% + Wide, YPos% + High)

Obje%!00 = Mat1%
Obje%!04 = Mat2%
Obje%!08 = Mat3%
Obje%!12 = Mat4%
Obje%!16 = 0
Obje%!20 = 0
Obje%!24 = 1

Obje%!28 = FCol%
Obje%!32 = BCol%
Obje%!36 = Font%
Obje%!40 = Xpts * 640
Obje%!44 = Ypts * 640
Obje%!48 = XPos%
Obje%!52 = YPos%
$(Obje% + 56) = Text$
Obje%?(56 + LENText$) = 0

ENDPROC

REM ˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜

DEF PROCDraw_Sector(Word%, Name$, XPos%, YPos%, Radi%, SAng, EAng, FCol%, OCol%, Wide%)
LOCAL Path%, Arcs%, Loop%, LAng

PROCDraw_PathStart(Word%, Name$, XPos%, YPos%, XPos% + Radi%, YPos% + Radi%, FCol%, OCol%, Wide%)
PROCDraw_PathLine(Word%, Name$, XPos% + Radi% * SIN(RAD(SAng)), YPos% + Radi% * COS(RAD(SAng)))

LAng = EAng - SAng
Arcs% = INT(LAng / 90) + 1
 FOR Loop% = 1 TO Arcs%
  PROCDraw_PathArc(Word%, Name$, XPos%, YPos%, Radi%, SAng + (LAng / Arcs%) * (Loop% - 1), SAng + (LAng / Arcs%) * Loop%)
 NEXT

PROCDraw_PathLine(Word%, Name$, XPos%, YPos%)
PROCDraw_PathClose(Word%, Name$)
ENDPROC

REM ˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜

DEF PROCDraw_PathStart(Word%, Name$, XPos%, YPos%, MaxX%, MaxY%, FCol%, OCol%, Wide%)
LOCAL Draw%, Obje%
Obje% = FNDraw_Object(Word%, Name$, 28, 2, XPos%, YPos%, MaxX%, MaxY%)
Draw% = FNHeap_Find(Word%, Name$)
_Draw_Path% = (Obje% - 24) - Draw%
Obje%!00 = FCol%
Obje%!04 = OCol%
Obje%!08 = Wide%
Obje%!12 = 0
Obje%!16 = 2
Obje%!20 = XPos%
Obje%!24 = YPos%
ENDPROC

REM ˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜

DEF PROCDraw_PathLine(Word%, Name$, XPos%, YPos%)
LOCAL Draw%, Obje%
Draw% = FNHeap_Find(Word%, Name$)
IF NOT FNHeap_ReAlloc(Draw%, 4 + !Draw% + 12) THEN ERROR Erro_Memo%, ""
Draw% = FNHeap_Find(Word%, Name$)
Obje% = 4 + Draw% + !Draw%
!Draw% += 12
Obje%!00 = 8
Obje%!04 = XPos%
Obje%!08 = YPos%
ENDPROC

REM ˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜

DEF PROCDraw_PathClose(Word%, Name$)
LOCAL Draw%, Obje%
Draw% = FNHeap_Find(Word%, Name$)
IF NOT FNHeap_ReAlloc(Draw%, 4 + !Draw% + 8) THEN ERROR Erro_Memo%, ""
Draw% = FNHeap_Find(Word%, Name$)
Obje% = 4 + Draw% + !Draw%
!Draw% += 8
Obje%!00 = 5
Obje%!04 = 0
!(Draw% + _Draw_Path% + 4) = Obje% + 8 - (Draw% + _Draw_Path%)
ENDPROC

REM ˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜

DEF PROCDraw_PathArc(Word%, Name$, XPos%, YPos%, Radi%, SAn1, EAn1)
LOCAL Ang1, Ang2, x0, y0, x1, y1, x2, y2, x3, y3, SAng, EAng
LOCAL Draw%, Obje%

SAng  = RAD(SAn1)
EAng  = RAD(EAn1)
Radi  = Radi% / 256
Ang1  = SAng + (EAng - SAng) / 3
Ang2  = SAng + (EAng - SAng) / 1.5
x0    = Radi * SIN(SAng)
y0    = Radi * COS(SAng)
x1    = Radi * SIN(Ang1)
y1    = Radi * COS(Ang1)
x2    = Radi * SIN(Ang2)
y2    = Radi * COS(Ang2)
x3    = Radi * SIN(EAng)
y3    = Radi * COS(EAng)

Draw% = FNHeap_Find(Word%, Name$)
IF NOT FNHeap_ReAlloc(Draw%, 4 + !Draw% + 28) THEN ERROR Erro_Memo%, ""
Draw% = FNHeap_Find(Word%, Name$)
Obje% = 4 + Draw% + !Draw%
!Draw% += 28
Obje%!00 = 6
Obje%!04 = XPos% + 256 * (-5 * x0 / 6 - 1.5 * x2 + 3 * x1 + x3 / 3)
Obje%!08 = YPos% + 256 * (-5 * y0 / 6 - 1.5 * y2 + 3 * y1 + y3 / 3)
Obje%!12 = XPos% + 256 * (-5 * x3 / 6 - 1.5 * x1 + 3 * x2 + x0 / 3)
Obje%!16 = YPos% + 256 * (-5 * y3 / 6 - 1.5 * y1 + 3 * y2 + y0 / 3)
Obje%!20 = XPos% + Radi% * SIN(RAD(EAn1))
Obje%!24 = YPos% + Radi% * COS(RAD(EAn1))
ENDPROC

REM ˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜

DEF PROCDraw_Box(Word%, Name$, XPos%, YPos%, Wide%, High%, FCol%, OCol%, LWid%)
PROCDraw_PathStart(Word%, Name$, XPos%, YPos%, XPos% + Wide%, YPos% + High%, FCol%, OCol%, LWid%)
PROCDraw_PathLine(Word%, Name$, XPos%, YPos%)
PROCDraw_PathLine(Word%, Name$, XPos% + Wide%, YPos%)
PROCDraw_PathLine(Word%, Name$, XPos% + Wide%, YPos% + High%)
PROCDraw_PathLine(Word%, Name$, XPos%, YPos% + High%)
PROCDraw_PathLine(Word%, Name$, XPos%, YPos%)
PROCDraw_PathClose(Word%, Name$)
ENDPROC

REM ˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜

DEF PROCDraw_Line(Word%, Name$, x1%, y1%, x2%, y2%, OCol%, LWid%)
PROCDraw_PathStart(Word%, Name$, x1%, y1%, x2%, y2%, -1, OCol%, LWid%)
PROCDraw_PathLine(Word%, Name$, x2%, y2%)
PROCDraw_PathClose(Word%, Name$)
ENDPROC
