Giter Club home page Giter Club logo

picobook's People

Contributors

txori avatar

Watchers

 avatar

picobook's Issues

Mouse cursor can get out of Picotron

There are two 40 black pixels at the top and bottom of the screen. The mouse cursor can go there.
I tried to restrain the mouse cursor to the Picotron without success, using cpp ClipCursor:

#include <iostream>
#include <windows.h>

// Screen resolution of the Chuwi Minibook X
constexpr int SCREEN_WIDTH = 1440;
constexpr int SCREEN_HEIGHT = 900;

// Screen resolution of the Picotron 480x270 (x3)
constexpr int PICOTRON_WIDTH = 1440;
constexpr int PICOTRON_HEIGHT = 810;

// Function prototypes
bool ChangeResolution(int width, int height);
void RestoreResolution();
void ClipMouseToRect(RECT rect);

int main() {
    // Change the screen resolution
    if (!ChangeResolution(SCREEN_WIDTH, SCREEN_HEIGHT)) {
        std::cerr << "Failed to change screen resolution." << std::endl;
        return 1; // Exit if resolution change failed
    }

    // Calculate the rectangle to clip the mouse cursor
    RECT clipRect;
    clipRect.left = 0;
    clipRect.top = (SCREEN_HEIGHT - PICOTRON_HEIGHT) / 2; // Adjust to center vertically
    clipRect.right = PICOTRON_WIDTH;
    clipRect.bottom = clipRect.top + PICOTRON_HEIGHT;

    // Clip the mouse cursor to the specified rectangle
    ClipMouseToRect(clipRect);

    // Run the program
    if (system("picotron.exe") != 0) {
        std::cerr << "Failed to execute picotron.exe." << std::endl;
        RestoreResolution(); // Restore resolution before exiting
        return 1;
    }

    // Restore the original screen resolution
    RestoreResolution();

    // Release the mouse cursor from the clipped rectangle
    ClipCursor(NULL);

    return 0;
}

// Function to change the screen resolution
bool ChangeResolution(int width, int height) {
    DEVMODE devMode = {};
    devMode.dmSize = sizeof(DEVMODE);
    devMode.dmPelsWidth = width;
    devMode.dmPelsHeight = height;
    devMode.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT;

    return ChangeDisplaySettings(&devMode, CDS_FULLSCREEN) == DISP_CHANGE_SUCCESSFUL;
}

// Function to restore the original screen resolution
void RestoreResolution() {
    ChangeDisplaySettings(NULL, 0);
}

// Function to clip the mouse cursor to a specified rectangle
void ClipMouseToRect(RECT rect) {
    ClipCursor(&rect);
}

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.