mirror of https://github.com/stella-emu/stella.git
apply screen scaling to lightgun controller
This commit is contained in:
parent
1295bd5cf6
commit
86e01bc8b9
|
@ -873,7 +873,7 @@ unique_ptr<Controller> Console::getControllerPort(const Controller::Type type,
|
|||
break;
|
||||
|
||||
case Controller::Type::Lightgun:
|
||||
controller = make_unique<Lightgun>(port, myEvent, *mySystem);
|
||||
controller = make_unique<Lightgun>(port, myEvent, *mySystem, myOSystem.frameBuffer());
|
||||
break;
|
||||
|
||||
default:
|
||||
|
|
|
@ -18,12 +18,14 @@
|
|||
|
||||
#include "TIA.hxx"
|
||||
#include "System.hxx"
|
||||
#include "FrameBuffer.hxx"
|
||||
|
||||
#include "Lightgun.hxx"
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
Lightgun::Lightgun(Jack jack, const Event& event, const System& system)
|
||||
: Controller(jack, event, system, Controller::Type::Lightgun)
|
||||
Lightgun::Lightgun(Jack jack, const Event& event, const System& system, const FrameBuffer& frameBuffer)
|
||||
: Controller(jack, event, system, Controller::Type::Lightgun),
|
||||
myFrameBuffer(frameBuffer)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -39,22 +41,16 @@ bool Lightgun::read(DigitalPin pin)
|
|||
// Pin 6: INPT4/5
|
||||
case DigitalPin::Six:
|
||||
{
|
||||
// TODO: scale correctly, current code assumes 2x zoom and no vertical scaling
|
||||
Int32 xpos = myMouseX / 4;
|
||||
Int32 ypos = myMouseY / 2;
|
||||
uInt32 ux;
|
||||
uInt32 uy;
|
||||
|
||||
mySystem.tia().electronBeamPos(ux, uy);
|
||||
const Common::Rect& rect = myFrameBuffer.imageRect();
|
||||
// scale mouse coordinates into TIA coordinates
|
||||
Int32 xpos = (myMouseX - rect.x()) * TIAConstants::H_PIXEL / rect.w();
|
||||
Int32 ypos = (myMouseY - rect.y()) * 210 / rect.h(); // TODO: replace "magic number"
|
||||
// get adjusted TIA coordinates
|
||||
Int32 x = mySystem.tia().clocksThisLine() - TIAConstants::H_BLANK_CLOCKS + X_OFS;
|
||||
Int32 y = mySystem.tia().scanlines() - mySystem.tia().startLine() + Y_OFS;
|
||||
|
||||
if (x < 0)
|
||||
x += TIAConstants::H_CLOCKS;
|
||||
Int32 y = uy + Y_OFS;
|
||||
|
||||
//cerr << "mouse:" << xpos << " " << ypos << endl;
|
||||
//cerr << " beam:" << x << " " << y << endl;
|
||||
|
||||
|
||||
bool enable = !((x - xpos) >= 0 && (x - xpos) < 15 && (y - ypos) >= 0);
|
||||
|
||||
|
|
|
@ -38,7 +38,7 @@ public:
|
|||
@param event The event object to use for events
|
||||
@param system The system using this controller
|
||||
*/
|
||||
Lightgun(Jack jack, const Event& event, const System& system);
|
||||
Lightgun(Jack jack, const Event& event, const System& system, const FrameBuffer& frameBuffer);
|
||||
virtual ~Lightgun() = default;
|
||||
|
||||
public:
|
||||
|
@ -69,10 +69,11 @@ public:
|
|||
bool isAnalog() const override { return true; }
|
||||
|
||||
private:
|
||||
const FrameBuffer& myFrameBuffer;
|
||||
Int32 myMouseX{0}, myMouseY{0};
|
||||
|
||||
static constexpr Int32 X_OFS = -21;
|
||||
static constexpr Int32 Y_OFS = 10;
|
||||
static constexpr Int32 Y_OFS = 5;
|
||||
|
||||
// Lookup table for associating paddle buttons with controller pins
|
||||
static const Controller::DigitalPin ourButtonPin;
|
||||
|
|
Loading…
Reference in New Issue