CUR / ANI file loader - Printable Version +- QB64 Phoenix Edition (https://staging.qb64phoenix.com) +-- Forum: QB64 Rising (https://staging.qb64phoenix.com/forumdisplay.php?fid=1) +--- Forum: Prolific Programmers (https://staging.qb64phoenix.com/forumdisplay.php?fid=26) +---- Forum: Petr (https://staging.qb64phoenix.com/forumdisplay.php?fid=52) +---- Thread: CUR / ANI file loader (/showthread.php?tid=1524) |
CUR / ANI file loader - Petr - 03-05-2023 Hey guys. I found in the depths of the hard disk my older thing, which has only one task - to allow you to use mouse cursors in a way other than the built-in function such as _MOUSESHOW "LINK" and the like. The ANI files have the same format (or very similar), so I included them in the library as well, under the same command. command: handle = LOADCURSOR (path\file.cur) or handle = LOADCURSOR (path\file.ani) Function to the variable handle returns a positive number of the cursor or animation in the case of ani file. Then there is the command PUTCURSOR (handle, positionX, positionY) - this command, like the _PUTIMAGE command, places the cursor image on the screen. It is intended for the graphics screen loop when the screen background is refreshed on each cycle. I could, if there was interest, make the modification to a hardware image, then you won't have to monitor the screen refresh, but the _Display command will be necessary. _Putimage will never work with the handle returned by the LOADCURSOR function! PUTCURSOR is also a common command and places animations loaded from ANI files in the same way. Then we have the FREECURSOR command, it releases the loaded images of cursors or animations from memory. Usage: FREECURSOR (handle) I've gone so far as to allow the decomposition of animation from ANI files into individual frames. For this you need the following 2 functions: LENCURSOR - works only with ANI files - returns the number of ANI animation frames. Usage: Frames = LENCURSOR (handle) And the second function - it will allow you to get a handle from the animation compatible with the _PUTIMAGE command of each frame in the animation. Example for getting the third image in the animation: Pic3 = DECOMPOSECURSOR (handle, 3) This is an older program (I had to patch it a lot to get it to work in PE) and I have a feeling that someone on Linux once reported something to me about display issues. If this happens, please go to the cursor.bm file, subroutine PUTCUR, disable all the lines related to the mouse (110, 111, 112), I have a note that this should be the source of the problem at the time. Finally, I would like to mention the so-called field within a field, I see on the forum that you deal with something like that. I use something like this in this program. So let's break down the cursor.bi file: TYPE Cursors_internal StartOffset AS LONG 'use ANI EndOffset AS LONG X_reduction AS INTEGER ' CUR X coordinate reduction read from file Y_reduction AS INTEGER ' CUR Y coordinate reduction read from file Image AS LONG ' own CUR image is saved here Flag AS LONG '1 for ANI, 2 for CUR END TYPE DIM SHARED ACTIVE_MOUSE_CURSOR ' variable, which memorize new mouse cursor usage. Used in PutCur SUB REDIM SHARED Internal_Recorded(0) AS Cursors_internal REDIM SHARED Internal_Recorded_ANIs(0) AS LONG 'frames array StartOffset. What is it? That's exactly it. A field within a field. This value indicates the starting index number in the Internal_Recorded_ANIs field. This is because an animation in an ANI file can have many frames. So how to write them in one field? You just add an auxiliary field and that is the Internal_Recorded_ANIs field. EndOffset This is the index value of the Internal_Recorded_ANIs field, it indicates the last index value that belongs to that one particular ANI file. See how easy it is now to add more and more ANI images? X_reduction AS INTEGER ' CUR X coordinate reduction read from file Y_reduction AS INTEGER ' CUR Y coordinate reduction read from file these values are contained in the CUR and ANI files and specify the number of pixels to shift the display so that the mouse points where the image Image AS LONG 'own CUR image is saved here exactly as the comment says. When you load a CUR file, you get them as one image. This can be added directly to the main field, it's one record for one item, no problem with that. Flag AS LONG '1 for ANI, 2 for CUR this is just a note that is written here by LOADCURSOR, according to which the program knows whether it should take the image from the main or from the auxiliary field Finally own field REDIM SHARED Internal_Recorded(0) AS Cursors_internal As you can see above: You call the file via its handle, which is the index number of the Internal_Recorder field. From this you will immediately know if it is a CUR or ANI file. For ANI, the first two records will tell you about the images that belong to that particular ANI. Next, learn about display corrections. So you have everything you need BI, BM, ANI and CUR files in attachment (zip format) Code: (Select All) '$include:'cursors.bi' RE: CUR / ANI file loader - mnrvovrfc - 03-05-2023 Let's see if it could help get out of painful boredom with the obsession with (lib)Adwaita on GNOME, or those Babylon cuneiform arrowhead-looking cursors of limited adjustment on KDE and XFCE. Even if only inside a QB64 program window. :/ sdlBasic had a trick like this I think but that mouse cursor didn't work reliably. Too bad the Italian author didn't have many contributors to go further with games and other things to take advantage of the capability. |