Skip to content

Commit

Permalink
Engine: Implemented on_mouse_move callback
Browse files Browse the repository at this point in the history
This adds on_mouse_move, a non-blocking function in a similar vein to
repeatedly_execute_always that runs when the mouse has moved and
*before* the cursor gets rendered.
  • Loading branch information
gurok committed Nov 1, 2014
1 parent 913f303 commit 1bb68aa
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 4 deletions.
10 changes: 6 additions & 4 deletions Engine/ac/draw.cpp
Expand Up @@ -58,6 +58,7 @@
#include "gfx/ali3dexception.h"
#include "gfx/blender.h"
#include "main/graphics_mode.h"
#include "script/script.h"

using namespace AGS::Common;
using namespace AGS::Engine;
Expand Down Expand Up @@ -2376,9 +2377,12 @@ void update_screen() {
gfxDriver->DrawSprite(AGSE_POSTSCREENDRAW, 0, NULL);
Bitmap *ds = GetVirtualScreen();

domouse (DOMOUSE_NOCURSOR);
if ((mousex != lastmx) || (mousey != lastmy)) {
run_function_on_non_blocking_thread(&mouseMoveFunc);
}
// update animating mouse cursor
if (game.mcurs[cur_cursor].view>=0) {
domouse (DOMOUSE_NOCURSOR);
// only on mousemove, and it's not moving
if (((game.mcurs[cur_cursor].flags & MCF_ANIMMOVE)!=0) &&
(mousex==lastmx) && (mousey==lastmy)) ;
Expand All @@ -2402,8 +2406,8 @@ void update_screen() {
mouse_delay = views[viewnum].loops[loopnum].frames[mouse_frame].speed + 5;
CheckViewFrame (viewnum, loopnum, mouse_frame);
}
lastmx=mousex; lastmy=mousey;
}
lastmx=mousex; lastmy=mousey;

// draw the debug console, if appropriate
if ((play.debug_mode > 0) && (display_console != 0))
Expand Down Expand Up @@ -2439,8 +2443,6 @@ void update_screen() {
invalidate_sprite(0, 0, debugConsole);
}

domouse(DOMOUSE_NOCURSOR);

if (!play.mouse_cursor_hidden)
{
gfxDriver->DrawSprite(mousex - hotx, mousey - hoty, mouseCursor);
Expand Down
1 change: 1 addition & 0 deletions Engine/ac/game.cpp
Expand Up @@ -586,6 +586,7 @@ void unload_game_file() {
renderDialogOptionsFunc.moduleHasFunction.resize(0);
getDialogOptionUnderCursorFunc.moduleHasFunction.resize(0);
runDialogOptionMouseClickHandlerFunc.moduleHasFunction.resize(0);
mouseMoveFunc.moduleHasFunction.resize(0);
numScriptModules = 0;

if (game.audioClipCount > 0)
Expand Down
1 change: 1 addition & 0 deletions Engine/main/game_file.cpp
Expand Up @@ -200,6 +200,7 @@ void game_file_read_script_modules(Stream *in)
renderDialogOptionsFunc.moduleHasFunction.resize(numScriptModules, true);
getDialogOptionUnderCursorFunc.moduleHasFunction.resize(numScriptModules, true);
runDialogOptionMouseClickHandlerFunc.moduleHasFunction.resize(numScriptModules, true);
mouseMoveFunc.moduleHasFunction.resize(numScriptModules, true);
for (int bb = 0; bb < numScriptModules; bb++) {
scriptModules[bb] = ccScript::CreateFromStream(in);
if (scriptModules[bb] == NULL)
Expand Down
1 change: 1 addition & 0 deletions Engine/script/script.cpp
Expand Up @@ -74,6 +74,7 @@ NonBlockingScriptFunction getDialogOptionsDimensionsFunc("dialog_options_get_dim
NonBlockingScriptFunction renderDialogOptionsFunc("dialog_options_render", 1);
NonBlockingScriptFunction getDialogOptionUnderCursorFunc("dialog_options_get_active", 1);
NonBlockingScriptFunction runDialogOptionMouseClickHandlerFunc("dialog_options_mouse_click", 2);
NonBlockingScriptFunction mouseMoveFunc("on_mouse_move", 0);

ScriptSystem scsystem;

Expand Down
1 change: 1 addition & 0 deletions Engine/script/script.h
Expand Up @@ -68,6 +68,7 @@ extern NonBlockingScriptFunction getDialogOptionsDimensionsFunc;
extern NonBlockingScriptFunction renderDialogOptionsFunc;
extern NonBlockingScriptFunction getDialogOptionUnderCursorFunc;
extern NonBlockingScriptFunction runDialogOptionMouseClickHandlerFunc;
extern NonBlockingScriptFunction mouseMoveFunc;

extern ScriptSystem scsystem;

Expand Down

0 comments on commit 1bb68aa

Please sign in to comment.