Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions loader/include/Geode/cocos/platform/mac/EAGLView.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ THE SOFTWARE.
NSRect originalWinRect_; // Original size and position

float frameZoomFactor_;
// @note RobTop Addition
float _backingScaleFactor;
// @note RobTop Addition
float _mouseX;
// @note RobTop Addition
float _mouseY;
}

@property (nonatomic, readwrite, assign) id<MacEventDelegate> eventDelegate;
Expand Down Expand Up @@ -114,6 +120,11 @@ THE SOFTWARE.

-(void) setFullScreen:(BOOL)fullscreen;

// @note RobTop Addition
- (float)getBackingFactor;
// @note RobTop Addition
- (float)setBackingScaleFactor:(float)scaleFactor;

@end
#endif // __EAGLVIEW_MAC_H__

Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ typedef enum
KEY_LeftShift = 0xA0,
KEY_RightShift = 0xA1,
KEY_LeftControl = 0xA2,
KEY_RightContol = 0xA3,
KEY_RightContol = 0xA3, // typo from original cocos
KEY_RightControl = 0xA3,
KEY_LeftMenu = 0xA4,
KEY_RightMenu = 0xA5,
KEY_BrowserBack = 0xA6,
Expand Down
89 changes: 89 additions & 0 deletions loader/include/Geode/utils/Keyboard.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
#pragma once
#include <Geode/cocos/robtop/keyboard_dispatcher/CCKeyboardDelegate.h>
#include <Geode/loader/Event.hpp>

namespace geode {
struct KeyboardInputEvent final : Event {
enum class Action : uint8_t {
Press,
Release,
Repeat
};

enum Modifiers : uint8_t {
Mods_None = 0,

Mods_Shift = 1 << 0,
Mods_Control = 1 << 1,
Mods_Alt = 1 << 2,
Mods_Super = 1 << 3,
};

struct Native final {
uint64_t code; // Windows: vKey
uint64_t extra; // Windows: scancode
};

Native native;
double timestamp;
cocos2d::enumKeyCodes key;
Action action;
Modifiers modifiers = Mods_None;

KeyboardInputEvent(cocos2d::enumKeyCodes key, Action action, Native native, double timestamp, Modifiers mods) noexcept
: native(native), timestamp(timestamp), key(key), action(action), modifiers(mods) {}
};

constexpr KeyboardInputEvent::Modifiers operator|(KeyboardInputEvent::Modifiers a, KeyboardInputEvent::Modifiers b) {
return static_cast<KeyboardInputEvent::Modifiers>(static_cast<uint8_t>(a) | static_cast<uint8_t>(b));
}

constexpr KeyboardInputEvent::Modifiers operator&(KeyboardInputEvent::Modifiers a, KeyboardInputEvent::Modifiers b) {
return static_cast<KeyboardInputEvent::Modifiers>(static_cast<uint8_t>(a) & static_cast<uint8_t>(b));
}

constexpr KeyboardInputEvent::Modifiers& operator|=(KeyboardInputEvent::Modifiers& a, KeyboardInputEvent::Modifiers b) {
a = a | b;
return a;
}

constexpr KeyboardInputEvent::Modifiers& operator&=(KeyboardInputEvent::Modifiers& a, KeyboardInputEvent::Modifiers b) {
a = a & b;
return a;
}

constexpr KeyboardInputEvent::Modifiers operator~(KeyboardInputEvent::Modifiers a) {
return static_cast<KeyboardInputEvent::Modifiers>(~static_cast<uint8_t>(a));
}

struct MouseInputEvent final : Event {
enum class Action {
Press,
Release
};

enum class Button {
Left,
Right,
Middle,
Button4,
Button5
};

Button button;
Action action;
double timestamp;

MouseInputEvent(Button button, Action action, double timestamp) noexcept
: button(button), action(action), timestamp(timestamp) {}
};

struct MouseMoveEvent final : Event {
int32_t x;
int32_t y;

MouseMoveEvent(int32_t x, int32_t y) noexcept : x(x), y(y) {}
};

// TODO: Add controller/touch input events?
}
159 changes: 1 addition & 158 deletions loader/src/hooks/AddExtraKeys.cpp
Original file line number Diff line number Diff line change
@@ -1,165 +1,10 @@
#include <Geode/DefaultInclude.hpp>

#ifdef GEODE_IS_WINDOWS
// GLEW needs to be included before GL but GLFW3 doesn't do that so this is
// just to make sure all of the GL-related headers are in order
#include <Geode/cocos/include/cocos2d.h>
#include <Geode/cocos/robtop/glfw/glfw3.h>
#include <Geode/cocos/robtop/keyboard_dispatcher/CCKeyboardDispatcher.h>
#include <Geode/cocos/robtop/keyboard_dispatcher/CCKeyboardDelegate.h>
#include <Geode/cocos/text_input_node/CCIMEDispatcher.h>
#include <Geode/modify/Modify.hpp>
#include <Geode/modify/CCEGLView.hpp>
#include <Geode/modify/CCKeyboardDispatcher.hpp>

using namespace geode::prelude;

class $modify(GeodeCCEGLView, CCEGLView) {
void onGLFWKeyCallback(GLFWwindow* window, int key, int scancode, int action, int mods) {
bool extraKey = isExtraKey(key);
bool numpad = isKeyNumpad(key);
if (!extraKey && !numpad) {
return CCEGLView::onGLFWKeyCallback(window, key, scancode, action, mods);
}
if (CCIMEDispatcher::sharedDispatcher()->hasDelegate()) {
return CCEGLView::onGLFWKeyCallback(window, key, scancode, action, mods);
}
bool down = action == 1 || action == 2;
bool repeat = action == 2;
enumKeyCodes keyCode = enumKeyCodes::KEY_Unknown;
if (extraKey) {
keyCode = this->extraKeyToKeyCode(key);
}
if (numpad) {
keyCode = this->numpadToKeyCode(key);
}
// TODO: v5 i added 0.0 as the new param but idk what the hell it does please someone fix
CCKeyboardDispatcher::get()->dispatchKeyboardMSG(keyCode, down, repeat, 0.0);
}

void onGLFWMouseCallBack(GLFWwindow* window, int button, int action, int mods) {
if (!isExtraMouseButton(button)) {
return CCEGLView::onGLFWMouseCallBack(window, button, action, mods);
}
bool down = action == 1;
// mouse buttons never repeat
bool repeat = false;
enumKeyCodes keyCode = this->mouseButtonToKeyCode(button);
CCKeyboardDispatcher::get()->dispatchKeyboardMSG(keyCode, down, repeat, 0.0);
}

bool isExtraMouseButton(int code) {
return code > GLFW_MOUSE_BUTTON_3;
}

enumKeyCodes mouseButtonToKeyCode(int button) {
switch (button) {
case GLFW_MOUSE_BUTTON_4:
return enumKeyCodes::MOUSE_4;
case GLFW_MOUSE_BUTTON_5:
return enumKeyCodes::MOUSE_5;
case GLFW_MOUSE_BUTTON_6:
return enumKeyCodes::MOUSE_6;
case GLFW_MOUSE_BUTTON_7:
return enumKeyCodes::MOUSE_7;
case GLFW_MOUSE_BUTTON_8:
return enumKeyCodes::MOUSE_8;
default:
return enumKeyCodes::KEY_Unknown;
}
}

bool isExtraKey(int code) {
switch (code) {
case GLFW_KEY_WORLD_1:
case GLFW_KEY_WORLD_2:
case GLFW_KEY_SEMICOLON:
case GLFW_KEY_APOSTROPHE:
case GLFW_KEY_SLASH:
case GLFW_KEY_EQUAL:
case GLFW_KEY_LEFT_BRACKET:
case GLFW_KEY_BACKSLASH:
case GLFW_KEY_RIGHT_BRACKET:
case GLFW_KEY_GRAVE_ACCENT:
return true;
default:
return false;
}
}

enumKeyCodes extraKeyToKeyCode(int key) {
switch (key) {
case GLFW_KEY_SEMICOLON:
return enumKeyCodes::KEY_Semicolon;
case GLFW_KEY_APOSTROPHE:
return enumKeyCodes::KEY_Apostrophe;
case GLFW_KEY_SLASH:
return enumKeyCodes::KEY_Slash;
case GLFW_KEY_EQUAL:
return enumKeyCodes::KEY_OEMEqual;
case GLFW_KEY_LEFT_BRACKET:
return enumKeyCodes::KEY_LeftBracket;
case GLFW_KEY_BACKSLASH:
return enumKeyCodes::KEY_Backslash;
case GLFW_KEY_RIGHT_BRACKET:
return enumKeyCodes::KEY_RightBracket;
case GLFW_KEY_GRAVE_ACCENT:
return enumKeyCodes::KEY_GraveAccent;
case GLFW_KEY_WORLD_1:
return enumKeyCodes::KEY_World1;
case GLFW_KEY_WORLD_2:
return enumKeyCodes::KEY_World2;
default:
return enumKeyCodes::KEY_Unknown;
}
}

bool isKeyNumpad(int code) {
return code >= GLFW_KEY_KP_0 && code <= GLFW_KEY_KP_EQUAL;
}

enumKeyCodes numpadToKeyCode(int key) {
switch (key) {
case GLFW_KEY_KP_0:
return enumKeyCodes::KEY_NumPad0;
case GLFW_KEY_KP_1:
return enumKeyCodes::KEY_NumPad1;
case GLFW_KEY_KP_2:
return enumKeyCodes::KEY_NumPad2;
case GLFW_KEY_KP_3:
return enumKeyCodes::KEY_NumPad3;
case GLFW_KEY_KP_4:
return enumKeyCodes::KEY_NumPad4;
case GLFW_KEY_KP_5:
return enumKeyCodes::KEY_NumPad5;
case GLFW_KEY_KP_6:
return enumKeyCodes::KEY_NumPad6;
case GLFW_KEY_KP_7:
return enumKeyCodes::KEY_NumPad7;
case GLFW_KEY_KP_8:
return enumKeyCodes::KEY_NumPad8;
case GLFW_KEY_KP_9:
return enumKeyCodes::KEY_NumPad9;
case GLFW_KEY_KP_DECIMAL:
return enumKeyCodes::KEY_Decimal;
case GLFW_KEY_KP_DIVIDE:
return enumKeyCodes::KEY_Divide;
case GLFW_KEY_KP_MULTIPLY:
return enumKeyCodes::KEY_Multiply;
case GLFW_KEY_KP_SUBTRACT:
return enumKeyCodes::KEY_Subtract;
case GLFW_KEY_KP_ADD:
return enumKeyCodes::KEY_Add;
case GLFW_KEY_KP_ENTER:
return enumKeyCodes::KEY_NumEnter;
case GLFW_KEY_KP_EQUAL:
return enumKeyCodes::KEY_Equal;
default:
return enumKeyCodes::KEY_Unknown;
}
}
};

class $modify(CCKeyboardDispatcher) {
GEODE_FORWARD_COMPAT_DISABLE_HOOKS("CCKeyboardDispatcher new keys")

Expand Down Expand Up @@ -205,6 +50,4 @@ class $modify(CCKeyboardDispatcher) {
return CCKeyboardDispatcher::keyToString(KEY_Unknown);
}
}
};

#endif
};
Loading
Loading