Gamestudio Links
Zorro Links
Newest Posts
Executing Trades on Next Bar Open
by vicknick. 06/13/24 08:51
Zorro Beta 2.61: PyTorch
by jcl. 06/10/24 14:42
New FXCM FIX Plugin
by flink. 06/04/24 07:30
AlpacaZorroPlugin v1.3.0 Released
by kzhao. 05/22/24 13:41
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
0 registered members (), 1,238 guests, and 3 spiders.
Key: Admin, Global Mod, Mod
Newest Members
AemStones, LucasJoshua, Baklazhan, Hanky27, firatv
19059 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Animated mouse pointers for beginners #100910
12/04/06 00:11
12/04/06 00:11
Joined: Aug 2005
Posts: 1,185
Ukraine
Lion_Ts Offline OP
Serious User
Lion_Ts  Offline OP
Serious User

Joined: Aug 2005
Posts: 1,185
Ukraine
Hi, 3dgs friends!
I made a break in my work. But best break for a programmer is to program something else
So, this is the small contribution - animated mouse pointers (I saw questions about this in "starting with 3dgs" and decide to do it as snippet).
Prepare big image with frames for your mouse pointer (like animated sprite). Make frames in this order: LeftClick, MiddleClick, RightClick, MouseMoving, MouseHolding.
This is thumbnail for my simple image, click on it to get real sized image (download and convert it to 32bit tga with alpha, i uploaded PNG because ImageCave rejected TGA):

Change script below to reflect your image settings (read comment in code to do this).
This script animates cursor 'forever'. If you want 'once' animation, like for a single click, you have to play with on_left,...on_right handlers.
This contribution is just an simple, may be errornous, example to show one way from many possible for beginners.
Code:

//LionTs: prepare big image (like for an animated sprite)
// with height = Height(Mouse_Map) and width = Width(Mouse_Map) * MouseMapFrames;
// place frames in order:
// LeftClick, MiddleClick, RightClick, MouseMoving, MouseHolding
BMAP MouseMap = "MouseMap.tga";
define MouseMapFrames, 25; //total number of frames in MouseMap image
//number of frames to animate in each 'mouse state'
define FramesInSeq, 5;
//delay between frames
define MouseAnimDelay, -0.1;
//just for us - readable constants
define stMouseLeft, 0;
define stMouseMiddle, 1;
define stMouseRight, 2;
define stMouseMoving, 3;
define stMouseHolding, 4;
//mouse states
var MouseState = stMouseHolding;
var MouseOldState = stMouseHolding;
var MouseMapsLoaded = Off;
BMAP* TmpMouseBmap; //temp bitmap
var MouseMaps[MouseMapFrames]; //frames array of mouse maps

function LoadMouse_startup //load mouse maps into array of frames
{
var f1;
var i = 0; var j = 0; var k; var n; var l;
var p; var a;
var MouseFrameWidth; var MouseFrameHeight;
MouseFrameHeight = Bmap_Height(MouseMap);
MouseFrameWidth = Bmap_Width(MouseMap) / MouseMapFrames;
f1 = bmap_lock(MouseMap, 0);
while (i < MouseMapFrames) {
TmpMouseBmap = bmap_createblack(MouseFrameWidth, MouseFrameHeight, f1);
bmap_preload(TmpMouseBmap);
MouseMaps[i] = handle(TmpMouseBmap);
f1 = bmap_lock(TmpMouseBmap, 0);
j = MouseFrameWidth * i;
l = MouseFrameWidth + j;
n = 0;
while (j < l) {
k = 0;
while (k < MouseFrameHeight) {
p = pixel_for_bmap(MouseMap, j, k);
pixel_to_bmap(TmpMouseBmap, n, k, p);
k += 1;
}
n += 1;
j += 1;
}
bmap_unlock(TmpMouseBmap);
i += 1;
}
bmap_unlock(MouseMap);
bmap_purge(MouseMap);
wait(1);
MouseMapsLoaded = On;
}

function AnimMouse_startup //animate mouse pointer
{
var MouseCurrentFrame;
var MouseStartingFrame;
var MouseEndingFrame;
MouseState = stMouseHolding;
MouseOldState = MouseState;
MouseCurrentFrame = MouseState * FramesInSeq;
Mouse_Map = curs_map;
while !(MouseMapsLoaded){
wait(1);
}
while(1) {
if (Mouse_Mode > 0) { //if mouse is visible
if MouseState != MouseOldState {
while (MouseCurrentFrame > MouseStartingFrame) {
Mouse_Map = ptr_for_handle(MouseMaps[MouseCurrentFrame]);
MouseCurrentFrame = max(MouseCurrentFrame - 1, MouseStartingFrame);
wait(MouseAnimDelay);
}
}else{
MouseStartingFrame = MouseState * FramesInSeq;
MouseEndingFrame = MouseStartingFrame + FramesInSeq;
Mouse_Map = ptr_for_handle(MouseMaps[MouseCurrentFrame]);
MouseCurrentFrame = cycle(MouseCurrentFrame + 1, MouseStartingFrame, MouseEndingFrame);
}
}
wait(MouseAnimDelay);
}
}

function Mouse_startup //reflect mouse state for animation proc
{
while (1){
if (Mouse_Mode > 0) { //if mouse is visible
Mouse_Pos.X = Pointer.X; //move the pointer
Mouse_Pos.Y = Pointer.Y;
if Mouse_Left { //and reflect 'mouse state'
MouseOldState = MouseState;
MouseState = stMouseLeft;
} else {
if Mouse_Middle {
MouseOldState = MouseState;
MouseState = stMouseMiddle;
} else {
if Mouse_Right {
MouseOldState = MouseState;
MouseState = stMouseRight;
} else {
if Mouse_Moving {
MouseOldState = MouseState;
MouseState = stMouseMoving;
} else {
MouseOldState = MouseState;
MouseState = stMouseHolding;
}
}
}
}
}
wait(1);
}
}

function mouse_tgl //simple mouse toggler
{
if (Mouse_Mode == 0) {
Mouse_Mode = 2;
}else{
Mouse_Mode = 0;
}
}

on_space = mouse_tgl; //show the mouse pointer on space key

function main
{
max_loops = 200000; //don't forget to set maxloops!
.............


That's all. Have to go to drink some beer.
PS.
Without handle() and ptr_for_handle engine crashes sometimes. Works, but crashes, i don't know why.

Re: Animated mouse pointers for beginners [Re: Lion_Ts] #100911
12/04/06 19:05
12/04/06 19:05
Joined: Mar 2006
Posts: 752
Portugal
demiGod Offline
User
demiGod  Offline
User

Joined: Mar 2006
Posts: 752
Portugal
I had no time to use your code yet, but it seems to me a very nice contribution, and not only for beginners.
Thanks.

Re: Animated mouse pointers for beginners [Re: demiGod] #100912
12/04/06 19:13
12/04/06 19:13
Joined: Sep 2003
Posts: 733
Whitefish, Montana
JazzDude Offline
User
JazzDude  Offline
User

Joined: Sep 2003
Posts: 733
Whitefish, Montana
Very nice. Very nice, indeed. I tested it and it works great.
Thanks. I hope you take many more breaks from your regular coding job.

Re: Animated mouse pointers for beginners [Re: Lion_Ts] #100913
12/04/06 19:43
12/04/06 19:43
Joined: Mar 2006
Posts: 2,758
Antwerp,Belgium
frazzle Offline
Expert
frazzle  Offline
Expert

Joined: Mar 2006
Posts: 2,758
Antwerp,Belgium
Thxn for sharing this with us Loin_tTs, this is one nice contribution
One question, does it need the latest 3DGS version, just checking

Cheers

Frazzle


Antec® Case
Intel® X58 Chipset
Intel® i7 975 Quad Core
8 GB RAM DDR3
SSD OCZ®-VERTEX2 3.5 x4 ; HD 600 GB
NVIDIA® GeForce GTX 295 Memory 1795GB
Re: Animated mouse pointers for beginners [Re: frazzle] #100914
12/04/06 20:45
12/04/06 20:45
Joined: Aug 2005
Posts: 1,185
Ukraine
Lion_Ts Offline OP
Serious User
Lion_Ts  Offline OP
Serious User

Joined: Aug 2005
Posts: 1,185
Ukraine
No, seems, i didn't use any new command. it have to work in any 3dgs, i think.
PS.
look at my other contrib about mouse and buttons:
http://www.coniserver.net/ubbthreads/showflat.php/Cat/0/Number/709513/an/0/page/0#Post709513

Re: Animated mouse pointers for beginners [Re: Lion_Ts] #100915
12/05/06 20:00
12/05/06 20:00
Joined: Mar 2006
Posts: 2,758
Antwerp,Belgium
frazzle Offline
Expert
frazzle  Offline
Expert

Joined: Mar 2006
Posts: 2,758
Antwerp,Belgium
Quote:


No, seems, i didn't use any new command. it have to work in any 3dgs, i think.





Oke, thxn for the info

Cheers

Frazzle


Antec® Case
Intel® X58 Chipset
Intel® i7 975 Quad Core
8 GB RAM DDR3
SSD OCZ®-VERTEX2 3.5 x4 ; HD 600 GB
NVIDIA® GeForce GTX 295 Memory 1795GB

Moderated by  adoado, checkbutton, mk_1, Perro 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1