home *** CD-ROM | disk | FTP | other *** search
-
- { text cursor simulator. This unit simulates a flashing text cursor in}
- { graphics mode. Released to public domain 3/15/89 by author Michael Day}
- {for mouse support, enable the mouse unit in th euses statement and}
- {uncomment the HideMouse and ShowMouse procedures in this unit.}
-
- Unit GwCurse;
- interface
-
- uses Gstart,graph,AreaWr{,Mouse};
-
- const GCputStyle : integer = NotPut;
-
- HiddenGcursor = 0; {cursor styles}
- NormalGcursor = 1;
- FatGcursor = 2;
- BlockGcursor = 3;
-
- GCFlashOn = 6; {cursor on time - in sys clock ticks - 0=always off}
- GCFlashOff = 1; {cursor off time - in sys clock ticks - 0=always on}
-
- procedure GcursorOn;
- procedure GcursorOff;
- procedure GcursorFlash;
- procedure GcursorType(style:word);
- procedure SetGcursorPos(Area:rect;
- Wide,CPos:word;
- Color:ColorRec;
- var Len:integer);
-
-
- implementation
-
- type Grect = record Xmin,Ymin,Xmax,Ymax:integer; end;
-
- const
- FlashCnt : word = 0;
- GcursorS : boolean = false; {true = visible cursor}
- GCStyle : integer = 0; {0=off, 1=small, 2=half, 3=full}
- GcX : integer = 0; {graphic cursor X position}
- GcY : integer = 0; {graphic cursor Y position}
-
- GCBimage : pointer = nil; {pointer to background save}
- GCBsize : word = 0; {size of the image in bytes}
-
- var SysClk : word absolute $40:$6C;
- OldSysClk : word;
- GCArea : Grect;
-
-
- {---------------------}
- procedure SetGcursorPos(Area:rect;
- Wide,CPos:word;
- Color:ColorRec;
- var Len:integer);
- begin
- AreaWritePos(Area,Color.WritePos,CPos,Wide,GcX,GcY,Len);
- end;
-
- {---------------------}
- procedure GcursorType(style:word);
- begin
- GCstyle := style;
- end;
-
- {----------------------}
- procedure GcursorOn;
- begin
- If (GCstyle = HiddenGCursor) or GcursorS then Exit;
- with GCArea do
- begin
- Xmin := GcX;
- Ymin := GcY;
- Xmax := GcX+pred(BoxTextWidth);
- Ymax := GcY+pred(BoxTextHeight);
- case GCStyle of
- {1} NormalGcursor : Ymin := Ymax-pred(BoxTextHeight shr 2); {small line}
- {2} FatGcursor : Ymin := Ymax-(BoxTextHeight shr 1); {half size}
- {3} end; {else - BlockGcursor: - full size}
-
- GCBsize := ImageSize(Xmin,Ymin,Xmax,Ymax);
- if MaxAvail > longint(GCBsize) then
- begin
- GetMem(GCBimage,GCBsize);
- { HideMouse; }
- GetImage(Xmin,Ymin,Xmax,Ymax,GCBimage^);
-
- PutImage(Xmin,Ymin,GCBimage^,GCputStyle);
- { ShowMouse; }
- GcursorS := true;
- end
- else
- begin
- GcursorS := false;
- end;
- end;
- end;
-
- {----------------------}
- procedure GcursorOff;
- begin
- if not(GcursorS) then Exit;
- GcursorS := false;
- If not(GraphOn) then Exit;
- { HideMouse; }
- PutImage(GCArea.Xmin,GCArea.Ymin,GCBimage^,NormalPut);
- FreeMem(GCBimage,GCBsize);
- { ShowMouse; }
- end;
-
- {---------------------}
- procedure GcursorFlash;
- var NewSysClk : word;
- begin
- If not(GraphOn) or (GCstyle = HiddenGCursor) then Exit;
-
- if (FlashCnt = 1) then
- begin
- GcursorOn;
- end
- else
- begin
- if FlashCnt = GCFlashOn then
- begin
- GcursorOff;
- end
- else
- begin
- if FlashCnt > (GCFlashOn+GCFlashOff) then
- begin
- FlashCnt := 0;
- end;
- end;
- end;
-
- NewSysClk := SysClk;
- if NewSysClk <> OldSysClk then
- begin
- inc(FlashCnt);
- end;
- OldSysClk := NewSysClk;
- end;
-
- {---------------------}
- begin
- OldSysClk := SysClk;
- end.
-