Files
EVEngine/src/modules/mouse/Mouse.cpp
T
西风逍遥游 2ab09dcf68 feat(script): bind Image decode, Joystick Pad axes/buttons, Mouse relative mode
- Image: expose newImageData(newImageDataFromFile)/newEmptyImageData/isCompressed and a
  full ImageData script class (getWidth/Height/Format/Size, pixel get/set, paste, clone,
  rotate). ImageData is now registered once by the Image module; drop the duplicate
  minimal registrations in Font and Model3D that could overwrite each other.
- Joystick: expose getJoystick/getJoystickFromID/getIndex/addJoystick/removeJoystick and a
  Pad class with raw axes/buttons/hats, GameController axis/button names, device info,
  and vibration. Pads stay owned by the module (non-owning script handles).
- Mouse: expose setRelativeMode/getRelativeMode plus setVisible/setPosition/setX/setY/
  setGrabbed/isGrabbed (SDL backend already implemented them).
- Tests: add image.nut/image_script.cpp and joystick.nut/joystick_script.cpp script tests,
  extend mouse.nut with relative-mode/visibility checks, wire into test CMake and the nut
  embed template.
- Docs: update image/joystick/mouse user chapters, MODULES.md and the REVIEW log.
2026-08-20 12:31:11 +08:00

39 lines
1.4 KiB
C++

#include "mouse/Mouse.h"
#include "mouse/sdl/Mouse.h"
#include <simplesquirrel/simplesquirrel.hpp>
#include <vector>
namespace eve::mouse {
Module_IMPL(Mouse, new sdl::Mouse());
Mouse::~Mouse() {}
void Mouse::expose(ssq::Table& table) {
auto cls = table.addClass(name, Mouse::create, false);
expose(cls);
}
void Mouse::expose(ssq::Class& cls) {
cls.addFunc("getName", &Mouse::getName);
// Bind as float: SSQ/Squirrel treat C++ double as userdata, which breaks script arith.
cls.addFunc("getX", [](Mouse *m) -> float { return m ? float(m->getX()) : 0.f; });
cls.addFunc("getY", [](Mouse *m) -> float { return m ? float(m->getY()) : 0.f; });
cls.addFunc("setX", [](Mouse *m, float x) { if (m) m->setX(x); });
cls.addFunc("setY", [](Mouse *m, float y) { if (m) m->setY(y); });
cls.addFunc("setPosition", [](Mouse *m, float x, float y) { if (m) m->setPosition(x, y); });
cls.addFunc("isDown", [](Mouse *m, int button) -> bool {
if (!m) return false;
return m->isDown(std::vector<int>{button});
});
cls.addFunc("setVisible", &Mouse::setVisible);
cls.addFunc("isVisible", &Mouse::isVisible);
cls.addFunc("setGrabbed", &Mouse::setGrabbed);
cls.addFunc("isGrabbed", &Mouse::isGrabbed);
cls.addFunc("setRelativeMode", &Mouse::setRelativeMode);
cls.addFunc("getRelativeMode", &Mouse::getRelativeMode);
}
} // namespace eve::mouse