Giter VIP home page Giter VIP logo

termin8or's Issues

Add mouse support.

There are three separate solutions for MacOS, Linux and Windows respectively. I have working code for MacOS for starters (from ChatGPT):

#include <iostream>
#include <ApplicationServices/ApplicationServices.h>

using namespace std;

// Global cursor position
int cursor_x = 40;
int cursor_y = 12;

// Callback function to handle mouse events
CGEventRef eventCallback(CGEventTapProxy proxy, CGEventType type, CGEventRef event, void* refcon) {
    if (type == kCGEventMouseMoved || type == kCGEventLeftMouseDragged || type == kCGEventRightMouseDragged) {
        CGPoint location = CGEventGetLocation(event);
        cursor_x = static_cast<int>(location.x);
        cursor_y = static_cast<int>(location.y);

        std::cout << "(x, y) = (" << cursor_x << ", " << cursor_y << ")\n";
    }
    return event;
}

int main() {
    // Create an event tap
    CGEventMask eventMask = (1 << kCGEventMouseMoved) | (1 << kCGEventLeftMouseDragged) | (1 << kCGEventRightMouseDragged);
    CFMachPortRef eventTap = CGEventTapCreate(kCGHIDEventTap, kCGHeadInsertEventTap, 0, eventMask, eventCallback, nullptr);

    if (!eventTap) {
        cerr << "Failed to create event tap" << endl;
        return -1;
    }

    // Create a run loop source and add it to the current run loop
    CFRunLoopSourceRef runLoopSource = CFMachPortCreateRunLoopSource(kCFAllocatorDefault, eventTap, 0);
    CFRunLoopAddSource(CFRunLoopGetCurrent(), runLoopSource, kCFRunLoopCommonModes);

    // Enable the event tap
    CGEventTapEnable(eventTap, true);

    // Run the loop to start receiving events
    CFRunLoopRun();

    // Cleanup
    CFRelease(eventTap);
    CFRelease(runLoopSource);

    return 0;
}

This is built using:

g++ -o mouse_test mouse_test.cpp -framework ApplicationServices

Still problems with frame refresh on WSL Ubuntu

Image

Here you can see that:

  1. The terminal is not properly cleared.
  2. The final row gets duplicated below it.

I don't know the reason for the second issue, so therefore it is not so easy to fix, but the first issue can be solved by adding the following code in the init() function of GameEngine:

#ifndef __APPLE__
#ifndef __WIN32
std::system("clear");
#endif
#endif

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.