Skip to content

Commit 159966d

Browse files
Merge pull request livecode#5981 from livecodeian/bugfix-16709
[[ Bug 16709 ]] Implement 'the mouse' in HTML5
2 parents 7bce4da + 3518638 commit 159966d

File tree

4 files changed

+46
-2
lines changed

4 files changed

+46
-2
lines changed

docs/notes/bugfix-16709.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Fix the mouse function always returning false

engine/src/em-dc.cpp

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,20 @@ MCEmscriptenGetCurrentStack()
5151
return t_dc->GetCurrentStack();
5252
}
5353

54+
MC_DLLEXPORT_DEF
55+
bool MCEmscriptenHandleMousePress(MCStack *p_stack, uint32_t p_time, uint32_t p_modifiers, MCMousePressState p_state, int32_t p_button)
56+
{
57+
if (MCnoui) return false;
58+
59+
MCScreenDC *t_dc = static_cast<MCScreenDC *>(MCscreen);
60+
61+
t_dc->handle_mouse_press(p_stack, p_time, p_modifiers, p_state, p_button);
62+
63+
return true;
64+
}
65+
5466
MCScreenDC::MCScreenDC()
55-
: m_main_window(nil)
67+
: m_main_window(nil), m_mouse_button_state(0)
5668
{
5769
}
5870

@@ -335,6 +347,32 @@ MCScreenDC::popupaskdialog(uint32_t p_type, MCStringRef p_title, MCStringRef p_m
335347
}
336348

337349

350+
void
351+
MCScreenDC::handle_mouse_press(MCStack *p_stack, uint32_t p_time, uint32_t p_modifiers, MCMousePressState p_state, int32_t p_button)
352+
{
353+
// track mouse button pressed state
354+
/* NOTE - assumes there are no more than 32 mouse buttons */
355+
if (p_button < 32)
356+
{
357+
if (p_state == kMCMousePressStateDown)
358+
m_mouse_button_state |= 1UL << p_button;
359+
else if (p_state == kMCMousePressStateUp)
360+
m_mouse_button_state &= ~(1UL << p_button);
361+
}
362+
363+
MCEventQueuePostMousePress(p_stack, p_time, p_modifiers, p_state, p_button);
364+
}
365+
366+
Boolean
367+
MCScreenDC::getmouse(uint2 p_button, Boolean& r_abort)
368+
{
369+
// return recorded mouse button state
370+
if (p_button < 32)
371+
return (m_mouse_button_state & (1 << p_button)) != 0;
372+
373+
return false;
374+
}
375+
338376
void
339377
MCScreenDC::platform_querymouse(int16_t& r_x, int16_t& r_y)
340378
{

engine/src/em-dc.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,12 @@ along with LiveCode. If not see <http://www.gnu.org/licenses/>. */
2727
#include "sysdefs.h"
2828
#include "stack.h"
2929
#include "uidc.h"
30+
#include "eventqueue.h"
3031

3132
MCUIDC *MCCreateScreenDC(void);
3233

3334
extern "C" MCStack *MCEmscriptenGetCurrentStack(void);
35+
extern "C" bool MCEmscriptenHandleMousePress(MCStack *p_stack, uint32_t p_time, uint32_t p_modifiers, MCMousePressState p_state, int32_t p_button);
3436

3537
/* ---------------------------------------------------------------- */
3638

@@ -65,6 +67,8 @@ class MCScreenDC: public MCUIDC
6567
virtual bool popupaskdialog(uint32_t p_type, MCStringRef p_title, MCStringRef p_message, MCStringRef p_initial, bool p_hint, MCStringRef& r_result);
6668

6769
/* Mouse management */
70+
void handle_mouse_press(MCStack *p_stack, uint32_t p_time, uint32_t p_modifiers, MCMousePressState p_state, int32_t p_button);
71+
virtual Boolean getmouse(uint2 button, Boolean& r_abort);
6872
virtual void platform_querymouse(int16_t& r_x, int16_t& r_y);
6973

7074
protected:
@@ -73,6 +77,7 @@ class MCScreenDC: public MCUIDC
7377

7478
private:
7579
Window m_main_window;
80+
uint32_t m_mouse_button_state;
7681
};
7782

7883
#endif /* ! __MC_EMSCRIPTEN_DC_H__ */

engine/src/em-event.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -634,7 +634,7 @@ mergeInto(LibraryManager.library, {
634634
// Wrapper for MCEventQueuePostMousePress
635635
_postMousePress: function(stack, time, modifiers, state, button)
636636
{
637-
Module.ccall('MCEventQueuePostMousePress',
637+
Module.ccall('MCEmscriptenHandleMousePress',
638638
'number', /* bool */
639639
['number', /* MCStack *stack */
640640
'number', /* uint32_t time */

0 commit comments

Comments
 (0)