Skip to content

Commit

Permalink
Merge pull request #45 from inc0der-forks/update-middle-mouse-event
Browse files Browse the repository at this point in the history
update mouse events now that we have middle mouse equivalent in haxe
  • Loading branch information
ianharrigan authored Sep 4, 2023
2 parents 6b846f0 + 9e27717 commit 073c03a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
10 changes: 6 additions & 4 deletions haxe/ui/backend/ComponentImpl.hx
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,8 @@ class ComponentImpl extends ComponentBase {
switch (type) {
case MouseEvent.MOUSE_MOVE | MouseEvent.MOUSE_OVER | MouseEvent.MOUSE_OUT |
MouseEvent.MOUSE_DOWN | MouseEvent.MOUSE_UP | MouseEvent.CLICK | MouseEvent.DBL_CLICK |
MouseEvent.RIGHT_MOUSE_DOWN | MouseEvent.RIGHT_MOUSE_UP:
MouseEvent.RIGHT_MOUSE_DOWN | MouseEvent.RIGHT_MOUSE_UP | MouseEvent.MIDDLE_MOUSE_DOWN |
MouseEvent.MIDDLE_MOUSE_UP:
if (_eventMap.exists(type) == false) {
_eventMap.set(type, listener);
if (type == MouseEvent.CLICK) {
Expand Down Expand Up @@ -495,7 +496,8 @@ class ComponentImpl extends ComponentBase {
switch (type) {
case MouseEvent.MOUSE_MOVE | MouseEvent.MOUSE_OVER | MouseEvent.MOUSE_OUT |
MouseEvent.MOUSE_DOWN | MouseEvent.MOUSE_UP | MouseEvent.CLICK | MouseEvent.DBL_CLICK |
MouseEvent.RIGHT_MOUSE_DOWN | MouseEvent.RIGHT_MOUSE_UP:
MouseEvent.RIGHT_MOUSE_DOWN | MouseEvent.RIGHT_MOUSE_UP | MouseEvent.MIDDLE_MOUSE_DOWN |
MouseEvent.MIDDLE_MOUSE_UP:
_eventMap.remove(type);
element.removeEventListener(EventMapper.HAXEUI_TO_DOM.get(type), __onMouseEvent);
if (type == MouseEvent.RIGHT_MOUSE_DOWN || type == MouseEvent.RIGHT_MOUSE_UP) {
Expand Down Expand Up @@ -619,13 +621,13 @@ class ComponentImpl extends ComponentBase {
if (event.type == "pointerdown") { // handle right button mouse events better
switch (which) {
case 1: type = MouseEvent.MOUSE_DOWN;
case 2: type = MouseEvent.MOUSE_DOWN; // should be mouse middle, but there is no haxe equiv (yet);
case 2: type = MouseEvent.MIDDLE_MOUSE_DOWN;
case 3: type = MouseEvent.RIGHT_MOUSE_DOWN;
}
} else if (event.type == "pointerup") { // handle right button mouse events better
switch (which) {
case 1: type = MouseEvent.MOUSE_UP;
case 2: type = MouseEvent.MOUSE_UP; // should be mouse middle, but there is no haxe equiv (yet);
case 2: type = MouseEvent.MIDDLE_MOUSE_UP;
case 3: type = MouseEvent.RIGHT_MOUSE_UP;
}
}
Expand Down
10 changes: 6 additions & 4 deletions haxe/ui/backend/ScreenImpl.hx
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,8 @@ class ScreenImpl extends ScreenBase {
switch (type) {
case MouseEvent.MOUSE_MOVE | MouseEvent.MOUSE_OVER | MouseEvent.MOUSE_OUT |
MouseEvent.MOUSE_DOWN | MouseEvent.MOUSE_UP | MouseEvent.CLICK | MouseEvent.DBL_CLICK |
MouseEvent.RIGHT_MOUSE_DOWN | MouseEvent.RIGHT_MOUSE_UP | MouseEvent.RIGHT_CLICK:
MouseEvent.RIGHT_MOUSE_DOWN | MouseEvent.RIGHT_MOUSE_UP | MouseEvent.RIGHT_CLICK |
MouseEvent.MIDDLE_MOUSE_DOWN | MouseEvent.MIDDLE_MOUSE_UP:

if (_mapping.exists(type) == false) {
_mapping.set(type, listener);
Expand Down Expand Up @@ -371,7 +372,8 @@ class ScreenImpl extends ScreenBase {
switch (type) {
case MouseEvent.MOUSE_MOVE | MouseEvent.MOUSE_OVER | MouseEvent.MOUSE_OUT |
MouseEvent.MOUSE_DOWN | MouseEvent.MOUSE_UP | MouseEvent.CLICK | MouseEvent.DBL_CLICK |
MouseEvent.RIGHT_MOUSE_DOWN | MouseEvent.RIGHT_MOUSE_UP | MouseEvent.RIGHT_CLICK:
MouseEvent.RIGHT_MOUSE_DOWN | MouseEvent.RIGHT_MOUSE_UP | MouseEvent.RIGHT_CLICK |
MouseEvent.MIDDLE_MOUSE_DOWN | MouseEvent.MIDDLE_MOUSE_UP:
_mapping.remove(type);
container.removeEventListener(EventMapper.HAXEUI_TO_DOM.get(type), __onMouseEvent);
if (type == MouseEvent.RIGHT_MOUSE_DOWN || type == MouseEvent.RIGHT_MOUSE_UP) {
Expand Down Expand Up @@ -426,13 +428,13 @@ class ScreenImpl extends ScreenBase {
if (event.type == "pointerdown") { // handle right button mouse events better
switch (which) {
case 1: type = MouseEvent.MOUSE_DOWN;
case 2: type = MouseEvent.MOUSE_DOWN; // should be mouse middle, but there is no haxe equiv (yet);
case 2: type = MouseEvent.MIDDLE_MOUSE_DOWN; // should be mouse middle, but there is no haxe equiv (yet);
case 3: type = MouseEvent.RIGHT_MOUSE_DOWN;
}
} else if (event.type == "pointerup") { // handle right button mouse events better
switch (which) {
case 1: type = MouseEvent.MOUSE_UP;
case 2: type = MouseEvent.MOUSE_UP; // should be mouse middle, but there is no haxe equiv (yet);
case 2: type = MouseEvent.MIDDLE_MOUSE_UP; // should be mouse middle, but there is no haxe equiv (yet);
case 3: type = MouseEvent.RIGHT_MOUSE_UP;
}
}
Expand Down
2 changes: 2 additions & 0 deletions haxe/ui/backend/html5/EventMapper.hx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ class EventMapper {
haxe.ui.events.MouseEvent.RIGHT_MOUSE_DOWN => "pointerdown",
haxe.ui.events.MouseEvent.RIGHT_MOUSE_UP => "pointerup",
haxe.ui.events.MouseEvent.RIGHT_CLICK => "contextmenu",
haxe.ui.events.MouseEvent.MIDDLE_MOUSE_DOWN => "pointerdown",
haxe.ui.events.MouseEvent.MIDDLE_MOUSE_UP => "pointerup",
haxe.ui.events.UIEvent.CHANGE => "change",
haxe.ui.events.KeyboardEvent.KEY_DOWN => "keydown",
haxe.ui.events.KeyboardEvent.KEY_UP => "keyup",
Expand Down

0 comments on commit 073c03a

Please sign in to comment.