'CUR file reader for read and draw cursor images from /windows/cursors dir. First version.
'Writed wihtout format knowledge just only on base from https://en.wikipedia.org/wiki/ICO_(file_format)
'can you find, how are writed some "unsupported" files? Upgraded (type 16 supported uncorrectly), type 0, 2 already supported
'known bug is bad draw Pen big xl. Repaired
'is added LINUX SUPPORT. (tested in Linux MINT)...
'known bug: Can not correctly draw structure color palette type 16. Its set to optimal output, but picture, as is set in file is then returned in different width and height image. (help_il.cur, help_im.cur)
'Retested in Windows, repaired under Linux.
'writed for fun by Petr
DIM SHARED ACTIVE
' variable, which memorize new mouse cursor usage. Used in ViewCursor SUB
Mask$ = "*.cur"
MakeCursorsList Path$, Mask$, CursorsList$() ' show all cursors on screen
Cursor$
= ENVIRON$("systemroot") + "\cursors\wait_m.cur" ' Windows - read cursors from Your Windows path\Cursors\ Img& = LoadCursor&(Cursor$, x, y)
Img& = LoadCursor&("wait_m.cur", x, y) ' Linux - read cursors from program directory
' PRINT Img&: SLEEP
ShowUsableCursors CursorsList$(), my&
ViewCursor Img&, x, y 'in LINUX is here something wrong. Program then show not new mouse cursor and gets stuck. WHY?
X = 100: y = 100
i& = LoadCursor&(Cursors(L), A, b)
Lp
= LastPos
(Cursors
(L
), CHR$(92))
fname$
= MID$(Cursors
(L
), Lp
) P$ = ""
Unsupported:
P$ = ""
' IF not win THEN PRINT "Error: MakeCursosList SUB is designed for Windows only.": SLEEP 1: END 'now supported.
' CHDIR Path$
IF WIN
THEN commandd$
= "DIR " + Path$
+ Mask$
+ " /B >CursorsList.txt" ELSE commandd$
= "ls " + Mask$
+ "> CursorsList.txt"
ToArray$
(i
) = Path$
+ LEFT$(crs$
, 20)
i = i + 1
PRINT "Error (Sub MakeCursorList): Specified path not exists.":
SLEEP 1
IF WIN
THEN _MOUSEHIDE ' this create program working fail. Program not respond and can not be killed in LINUX - but is called in my loop and there works under Linux... ???? IF ACTIVE
= 0 AND WIN
THEN ACTIVE
= 1:
_MOUSEMOVE _MOUSEX, _MOUSEY ' because without mouse moving is not _MOUSEHIDE accepted after call _MOUSEHIDE. If is call in Linux, nothing is viewed, but program can be killed.
' IF LoadCursor& THEN _FREEIMAGE LoadCursor& 'This.... in linux it kill cursor image. In windows it KILL NOT cursor image (image in end)
'returns: 1: File not exists, 2: Unsupported format, Value < 0 - valid cursor image
Image_Type
AS INTEGER ' 1 = ICO format, 2 = CUR format, others are invalid Number_images
AS INTEGER ' number images in file
Image_Color_Palette
AS _BYTE '_UNSIGNED _BYTE Horizontal
AS INTEGER ' In ICO format: Specifies color planes. Should be 0 or 1. ' In CUR format: Specifies the horizontal coordinates of the hotspot in number of pixels from the left.
Vertical
AS INTEGER ' In ICO format: Specifies bits per pixel. ' In CUR format: Specifies the vertical coordinates of the hotspot in number of pixels from the top.
TYPE ClrMask
' Thanks to LINUX i see difference. THIS area is not mentoied in my source materials...
ERc = 0
DIM CUR
AS CUR
, Structure
AS Structure
PRINT "First 2 bytes (always 0):"; CUR.Reserved
PRINT "Image type (1 = ICO, 2 = CUR):"; CUR.Image_Type
PRINT "Number images in file:"; CUR.Number_images
re:
PRINT "======================================="; R
PRINT "File: "; Cursor$; po
- 2 PRINT "Image width:"; Structure.Image_Width
PRINT "Image height:"; Structure.Image_Height
PRINT "Image color palette: (0 = LONG truecolor, 2 = _UNSIGNED _BYTE?)"; Structure.Image_Color_Palette
PRINT "Reserved (always zero):"; Structure.Reserved
PRINT "Number image points from left:"; Structure.Horizontal
PRINT "Number image points from top: "; Structure.Vertical
PRINT "Size of image data: "; Structure.Size_of_image_data
PRINT "Start offset: "; Structure.Offset_from_begin
PRINT " Palette:"; Structure.Image_Color_Palette
FOR all_images
= 1 TO CUR.Number_images
PRINT "Image: "; all_images
PRINT "Color mask - foreground: "; Mask.Rf; Mask.Gf; Mask.Bf
PRINT "Color mask - background: "; Mask.Rb; Mask.Gb; Mask.Bb
XReturned = Structure.Horizontal
YReturned = Structure.Vertical
A$
= SPACE$(Structure.Size_of_image_data
) posice = Structure.Offset_from_begin + 1
IF Structure.Image_Width
> 1 AND Structure.Image_Height
> 1 THEN SELECT CASE Structure.Image_Color_Palette
' In file is writed 0, but it is 4 byte long depth. Interresting... SEEK #1, Structure.Offset_from_begin
+ 1 posice = Structure.Offset_from_begin - 1
IF Structure.Size_of_image_data
< (Structure.Image_Width
* Structure.Image_Height
) THEN ClrDepth
= 256 ELSE ClrDepth
= 32 LoadCursor&
= _NEWIMAGE(Structure.Image_Width
+ 1, Structure.Image_Height
+ 1, ClrDepth
)
IF drawy
= 0 THEN drawy
= Structure.Image_Height
DO WHILE drawy
<> 0 AND drawx
<> Structure.Image_Width
posice = posice + 4
PSET (drawx
, drawy
), Bod&
drawx = drawx + 1
IF drawx
= Structure.Image_Width
AND drawx
MOD 4 = 0 THEN drawx
= 0: drawy
= drawy
- 1 'upgrade
SEEK #1, Structure.Offset_from_begin
drawy = -2
LoadCursor&
= _NEWIMAGE(Structure.Image_Width
+ 1, Structure.Image_Height
+ 1, 256) ' 2 bit color drawx = -8: drawy = -6
bod
= ASC(A$
, CursorDraw
) Bin$ = DECtoBIN$(bod)
comand$
= MID$(Bin$
, drr
, 1)
IF drawy
> -2 THEN PSET (drawx
, (Structure.Image_Height
- 1) - drawy
), clr
drawx
= drawx
+ 1:
IF drawx
>= Structure.Image_Width
AND drawx
MOD 32 = 0 THEN drawx
= 0: drawy
= drawy
+ 1
SEEK #1, Structure.Offset_from_begin
+ 45 LoadCursor&
= _NEWIMAGE(Structure.Image_Width
, Structure.Image_Height
, 256) ' 2 bit colored. My lovely. :-D
drawx = 0: drawy = 0
bod
= ASC(A$
, CursorDraw
) Bin$ = DECtoBIN$(bod)
comand$
= MID$(Bin$
, drr
, 1) PSET (drawx
, Structure.Image_Height
- drawy
), clr
drawx
= drawx
+ 1:
IF drawx
> Structure.Image_Width
- 1 AND drawx
MOD 32 = 0 THEN drawx
= 0: drawy
= drawy
+ 1
SEEK #1, Structure.Offset_from_begin
+ 817 'i have none informations about file area between color palette record and image data record...
A$
= LEFT$(A$
, Structure.Image_Width
* Structure.Image_Height
) LoadCursor&
= _NEWIMAGE(Structure.Image_Width
+ 12, Structure.Image_Height
+ 5, 256) '
drawx = -3: drawy = -4 'Structure.Vertical
bod
= ASC(A$
, CursorDraw
) Bin$ = DECtoBIN$(bod)
comand$
= MID$(Bin$
, drr
, 1) PSET (drawx
, Structure.Image_Height
- drawy
), clr
drawx
= drawx
+ 1:
IF drawx
> Structure.Image_Width
AND drawx
MOD 32 = 0 THEN drawx
= 0: drawy
= drawy
+ 1 NEXT ' color palette settings
IF vstup
AND 2 ^ rj
THEN DECtoBIN$
= DECtoBIN$
+ "1" ELSE DECtoBIN$
= DECtoBIN$
+ "0"
BINtoDEC = BINtoDEC + (c * 2 ^ Sj)