Faceți căutări pe acest blog

joi, 12 mai 2022

Combine icons/static cursors into one animated cursor

Like icons or static cursors, animated cursors are containers.

The structure is relatively simple. Besides the contained icons, you must provide the default speed of animation, the order in which frames are displayed (first frame is frame number 0) and the time in 1/60 sec for each step to be displayed (speed of animation)

Just look at the next code.

FUNCTION ico2ani

*****************************************************************
* Convert Icons (ICO) and cursor (CUR) to animated cursor (ANI) *
*****************************************************************
* Version 2.0
*****************************************************************
* Parameters
* - lcAni String Name of the resulted file
* - laIcons array (referrence) array containing fully qualified source files (icons or cursors)
* - lnDelay integer the time in 1/60 sec each image is displayed (default speed of animation)
* - laSeq array (refference) 2 dimensional array of integers containing :
* - column 1: the order in which frames are displayed (first frame is frame number 0)
* - column 2: time in 1/60 sec each step is displayed (speed of animation)
******************************************************************

LPARAMETERS lcAni,laIcons,lnDelay,laSeq
LOCAL lcIco[ALEN(m.laIcons)], lnLen[ALEN(m.laIcons)], lnLenIco, lnSteps, lcSeq, lcRate, lnLenSeq, lnLenRate, lnbfAttr
IF PCOUNT() < 2
RETURN
ENDIF
IF PCOUNT() = 2
lnDelay = 10
ENDIF
STORE 0 TO lnLenSeq, lnLenRate
STORE '' TO lcRate, lcSeq
lnbfAttr = 1
IF PCOUNT() < 4
lnSteps = ALEN(laIcons,1)
ELSE
lnSteps = ALEN(laSeq,1)
lnbfAttr = 3
FOR lni = 1 TO ALEN(laSeq,1)
IF TYPE("m.laSeq[1,1]") = "N"
lcSeq = m.lcSeq + BINTOC(m.laSeq[m.lni,1], "4RS")
ENDIF
IF TYPE("m.laSeq[1,2]") = "N"
lcRate = m.lcRate + BINTOC(m.laSeq[m.lni,2], "4RS")
ENDIF
NEXT
IF !EMPTY(m.lcRate)
lcRate = "rate" + BINTOC(LEN(m.lcRate), "4RS") + m.lcRate
ENDIF
IF !EMPTY(m.lcSeq)
lcSeq = "seq " + BINTOC(LEN(m.lcSeq), "4RS") + m.lcSeq
ENDIF
lnLenSeq = LEN(m.lcSeq)
lnLenRate = LEN(m.lcRate)
ENDIF

lnLenIco = 0
FOR lni = 1 TO ALEN(m.laIcons)
lcIco[m.lni] = FILETOSTR(m.laIcons[m.lni])
lnLen[m.lni] = LEN(m.lcIco[m.lni])
lnLenIco = m.lnLenIco + 8 + lnLen[m.lni]
NEXT

lcResult = "RIFF" + BINTOC(12 + 36 + 8 + 4 + m.lnLenIco + m.lnLenSeq + m.lnLenRate, "4RS")

lcResult = m.lcResult + "ACONanih" + BINTOC(36, "4RS") + BINTOC(36, "4RS") + BINTOC(ALEN(m.laIcons,1), "4RS") + BINTOC(m.lnSteps, "4RS") + ;
REPLICATE(CHR(0),16) + BINTOC(m.lnDelay, "4RS") + BINTOC(m.lnbfAttr, "4RS") + m.lcSeq + m.lcRate
lcResult = m.lcResult + "LIST" + BINTOC(4 + m.lnLenIco, "4RS")
lcResult = m.lcResult + "fram"
FOR lni = 1 TO ALEN(m.laIcons)
lcResult = m.lcResult + "icon" + BINTOC(m.lnLen[m.lni], "4RS") + m.lcIco[m.lni]
NEXT

STRTOFILE(m.lcResult, FORCEEXT(m.lcAni,"ani"))
RETURN FORCEEXT(m.lcAni,"ani")

Two demos:

1) Using faces:

CLEAR RESOURCES
CLEAR ALL
LOCAL laIcons[5], laSeq[8,2]
SET SAFETY OFF

* List of images
laIcons[1] = HOME(4)+"Icons\Misc\FACE01.ICO"
laIcons[2] = HOME(4)+"Icons\Misc\FACE02.ICO"
laIcons[3] = HOME(4)+"Icons\Misc\FACE03.ICO"
laIcons[4] = HOME(4)+"Icons\Misc\FACE04.ICO"
laIcons[5] = HOME(4)+"Icons\Misc\FACE05.ICO"

* order of frames
laSeq[1,1] = 0
laSeq[2,1] = 1
laSeq[3,1] = 2
laSeq[4,1] = 4
laSeq[5,1] = 2
laSeq[6,1] = 1
laSeq[7,1] = 0
laSeq[8,1] = 3

* time (speed) of each frame
laSeq[1,2] = 10
laSeq[2,2] = 10
laSeq[3,2] = 10
laSeq[4,2] = 10
laSeq[5,2] = 10
laSeq[6,2] = 10
laSeq[7,2] = 10
laSeq[8,2] = 60

lcAni = ico2ani("ff.ani",@laIcons,15,@laSeq)

PUBLIC ofrm
ofrm = CREATEOBJECT("form")
ofrm.MousePointer = 99
ofrm.MouseIcon = m.lcAni

ofrm.show()


2. Two animated cursor in the same demo:
* Code for testing purpose
CLEAR RESOURCES
CLEAR ALL
LOCAL laIcons[8],laIcons2[4]
SET SAFETY OFF

* create an animated cursor from 8 ICONS and set this to the form
laIcons[1] = HOME(4)+"Icons\Elements\MOON01.ICO"
laIcons[2] = HOME(4)+"Icons\Elements\MOON02.ICO"
laIcons[3] = HOME(4)+"Icons\Elements\MOON03.ICO"
laIcons[4] = HOME(4)+"Icons\Elements\MOON04.ICO"
laIcons[5] = HOME(4)+"Icons\Elements\MOON05.ICO"
laIcons[6] = HOME(4)+"Icons\Elements\MOON06.ICO"
laIcons[7] = HOME(4)+"Icons\Elements\MOON07.ICO"
laIcons[8] = HOME(4)+"Icons\Elements\MOON08.ICO"

lcAni = ico2ani("mm.ani",@laIcons,15)

* Create another animated cursor from 4 static CURSORS and set this to the optiongroup
laIcons2[1] = HOME(4)+"Cursors\H_WE.CUR"
laIcons2[2] = HOME(4)+"Cursors\H_NW.CUR"
laIcons2[3] = HOME(4)+"Cursors\H_NS.CUR"
laIcons2[4] = HOME(4)+"Cursors\H_NW.CUR"

lcAni = ico2ani("hh.ani",@laIcons2,15)

* Create the demo form with a optiongroup
PUBLIC ofrm
ofrm = CREATEOBJECT("form")

ofrm.MousePointer = 99
ofrm.MouseIcon = "mm.ani"

ofrm.addobject("optiongroup1","optiongroup")
ofrm.optiongroup1.buttoncount = 3
ofrm.optiongroup1.autosize = .t.
ofrm.optiongroup1.visible = .T.
ofrm.optiongroup1.MousePointer = 99
ofrm.optiongroup1.MouseIcon = "hh.ani"
ofrm.optiongroup1.setall("MousePointer", 99)
ofrm.optiongroup1.setall("MouseIcon", "hh.ani")

ofrm.show()

Related links

Niciun comentariu:

Trimiteți un comentariu