Allegro.cc - Online Community

Allegro.cc Forums » Allegro Development » Simple Mouse API feature request

This thread is locked; no one can reply to it. rss feed Print
Simple Mouse API feature request
Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Currently, users drawing a mouse pointer themselves using draw_sprite in a windowed mode have no way to detect when the mouse moves off of the window. This means that users have no choice but to keep drawing their pointer stuck inside the edge of their program even while the OS mouse is being displayed out side of the window.

Allegro uses two int variables called mon and _mouse_on to track whether the mouse is on-screen, but both are local to mouse.c so they can't currently be read.

An easy fix would be to add an int mouse_on_screen(); function that returns the value of _mouse_on. This way users who draw the mouse themselves who wish to hide the mouse when it is off of the window can do so by using :

if(mouse_on_screen()) {display_mouse();}

So my humble request is that these be added to allegro if it is deemed to be proper :

mouse.h

//
AL_FUNC(int, mouse_on_screen , (void));
//

mouse.c

//
int mouse_on_screen() {
  return _mouse_on;
}
//

docs :
int mouse_on_screen();

Returns true if the mouse is currently on screen. This can be useful when drawing your own mouse pointers manually in a buffered windowed mode to let you know when to stop drawing your pointer on the buffer. This way you can prevent your pointer from being displayed on your window at the same time as an OS pointer is being displayed outside the window.

OnlineCop
Member #7,919
October 2006
avatar

Even if it doesn't get added to the main allegro distribution, this is something I'm adding to my own local copy.

Thanks, Edgar, for finding that and posting the "patch" so I can drop it into my own code. You rock!

EDIT:
Edgar, you may want to change your if(MouseOnScreen()) {display_mouse();} to:
if(mouse_on_screen()) {display_mouse();}
to match the example in your mouse.(c|h) suggestions. :)

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Yeah, I knew about the inconsistent naming, but thanks for pointing it out anyway. MouseOnScreen() is the way I would name it myself, but mouse_on_screen() fits the allegro naming conventions so I put up that up for the request part. I changed the post so it is consistent now.

Please take note that I haven't tested the addition yet.

Update
I've been trying to test my addition but I can't get rid of an undefined reference error to mouse_on_screen. I made the above changes to mouse.c and mouse.h, ran make clean in my modified allegro directory and ran mingw32-make DEBUGMODE=1. Everything compiled and linked fine. I've got the alld42.dll it created and the liballd.a archive as well. My test program compiles okay, which means it found the altered header but it fails to link even when I explicitly specify the linker search directory with -Lc:\mingw\allegro422modify\lib\mingw32 and -lalld. Here's a quick transcript :

//
c:\ctwoplus\progcode\allegro\GUI_Allegro>mingw32-g++ -Wall -ggdb -c -Ic:\mingw\allegro422modify\include MouseTest.cpp
MouseTest.cpp: In function `int _mangled_main()':
MouseTest.cpp:33: warning: unused variable 'mxo'
MouseTest.cpp:34: warning: unused variable 'myo'

c:\ctwoplus\progcode\allegro\GUI_Allegro>mingw32-g++ -Wall -ggdb -o MouseTest.exe MouseTest.o -Lc:\mingw\allegro422modify\lib\mingw32 -lalld -Wl,-subsystem,windows
MouseTest.o: In function `Z13_mangled_mainv':
c:\ctwoplus\progcode\allegro\GUI_Allegro/MouseTest.cpp:47: undefined reference to `mouse_on_screen'

c:\ctwoplus\progcode\allegro\GUI_Allegro>
//

Even if I use unix fileslashes in the path it doesn't work. It seems the linker found liballd.a, but it must be the wrong one or the mouse.o module (and therefore the library) didn't get compiled properly.

Any clues?

torhu
Member #2,727
September 2002
avatar

I don't have access to my own PC now, but you probably need to add the symbol to the .def file somehow, to get it added as an export in the DLL.

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Quote:

I don't have access to my own PC now, but you probably need to add the symbol to the .def file somehow, to get it added as an export in the DLL.

I've been searching around and it looks like I need to use the fixdll script - I found fixdll.bat but it says to use fixdll.sh instead.

fixdll.bat said:

echo *** Warning !!!
echo Using this script to generate the DLL export definition files may break
echo binary compatibility with the latest release. Use misc/fixdll.sh instead.
echo ***

// .....

Should I run fixdll.sh through MSYS and then build allegro normally? Or can I use fixdll.bat to make a temporary test?

torhu
Member #2,727
September 2002
avatar

For testing this you can probably just add the new symbol at the end of the .def file manually. Then it won't break binary compatibility either.

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Update
I added the mouse_on_screen function to lib\mingw32\allegro.def manually at the end :

...
    position_mouse_w @1404
    mouse_on_screen @1405

I recompiled the dll and archives and the program links properly now. Here's a working example of the program in a zip file of the source, win32 exe, and modified allegro dll.

Quote:

For testing this you can probably just add the new symbol at the end of the .def file manually. Then it won't break binary compatibility either.

Okay, I'll try that. I tried to use MSYS but it seems an AV program is interfering somehow. Description below.

I tried to start MSYS but now it doesn't work anymore. I had a working installation and now it opens a couple console windows and closes them immediately. I uninstalled it and reinstalled MSYS and now I get this error in the installation :

Quote:

C:\msys\1.0\postinstall>PATH ..\bin;C:\Windows\system32;C:\Windows;C:\Windows\Sy
stem32\Wbem;C:\Program Files\ATI Technologies\ATI.ACE\Core-Static

C:\msys\1.0\postinstall>..\bin\sh.exe pi.sh
AllocationBase 0x0, BaseAddress 0x715B0000, RegionSize 0x150000, State 0x10000
C:\msys\1.0\bin\sh.exe: *** Couldn't reserve space for cygwin's heap, Win32 erro
r 0

C:\msys\1.0\postinstall>pause
Press any key to continue . . .

I already disabled any AV stuff that I was running and it just doesn't work. I've been googling around and it seems it is related to AV programs so I'm trying a few different things...

Go to: