Skip to content

Commit

Permalink
Changed mouse cursor translation to take into account extra border sp…
Browse files Browse the repository at this point in the history
…ace used in when forced aspect is enabled.

Removed handling of WM_SETFOCUS that moves the mouse cursor to the upper left hand corner of the window
Switched to using GET_X_LPARAM and GET_Y_LPARAM from Windowsx.h as recommended by MS docs.
  • Loading branch information
ChetSimpson committed Oct 21, 2022
1 parent 1d9eb42 commit 71628d7
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 57 deletions.
26 changes: 18 additions & 8 deletions DirectDrawInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ static unsigned char ForceAspect=1;
static char StatusText[255]="";
static unsigned int Color=0;
static POINT RememberWinSize;
static POINT ForcedAspectBorderPadding;

//Function Prototypes for this module
extern LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); //Callback for the main window
Expand Down Expand Up @@ -268,8 +269,10 @@ void DisplayFlip(SystemState *DFState) // Double buffering flip
static RECT Temp;
static POINT p;

ForcedAspectBorderPadding = { 0,0 };

if (DFState->FullScreen) // if we're windowed do the blit, else just Flip
hr = g_pDDS->Flip(NULL,DDFLIP_NOVSYNC |DDFLIP_DONOTWAIT ); //DDFLIP_WAIT
hr = g_pDDS->Flip(NULL, DDFLIP_NOVSYNC | DDFLIP_DONOTWAIT); //DDFLIP_WAIT
else
{
p.x = 0; p.y = 0;
Expand Down Expand Up @@ -327,6 +330,8 @@ void DisplayFlip(SystemState *DFState) // Double buffering flip

static POINT pDstLeftTop;
pDstLeftTop.x = (long)dstX; pDstLeftTop.y = (long)dstY;
ForcedAspectBorderPadding = pDstLeftTop;

::ClientToScreen(DFState->WindowHandle, &pDstLeftTop);

static POINT pDstRightBottom;
Expand Down Expand Up @@ -447,12 +452,6 @@ void SetStatusBarText( char *TextBuffer,SystemState *STState)
return;
}

int GetMainWindowStatusBarHeight()
{
return StatusBarHeight;
}


void Cls(unsigned int ClsColor,SystemState *CLState)
{
CLState->ResetPending=3; //Tell Main loop to hold Emu
Expand Down Expand Up @@ -599,4 +598,15 @@ float Static(SystemState *STState)
}
POINT GetCurWindowSize() {
return (RememberWinSize);
}
}

int GetRenderWindowStatusBarHeight()
{
return StatusBarHeight;
}


POINT GetForcedAspectBorderPadding()
{
return ForcedAspectBorderPadding;
}
3 changes: 2 additions & 1 deletion DirectDrawInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ BOOL InitDrawSurface(bool );
void UnlockScreen(SystemState *);
unsigned char LockScreen(SystemState *);
void SetStatusBarText( char *,SystemState *);
int GetMainWindowStatusBarHeight();
int GetRenderWindowStatusBarHeight();
bool CreateDDWindow(SystemState *);
void Cls(unsigned int,SystemState *);
void DoCls(SystemState *);
Expand All @@ -33,6 +33,7 @@ unsigned char SetAspect (unsigned char);
float Static(SystemState *);
POINT GetCurWindowSize();
void DisplayFlip(SystemState *);
POINT GetForcedAspectBorderPadding();


#define MAX_LOADSTRING 100
Expand Down
54 changes: 24 additions & 30 deletions Vcc.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ This file is part of VCC (Virtual Color Computer).
#define TH_WAITING 2

#include <objbase.h>
#include <windows.h>
#include <windowsx.h>
#include <process.h>
#include <commdlg.h>
#include <stdio.h>
Expand Down Expand Up @@ -67,10 +67,6 @@ This file is part of VCC (Virtual Color Computer).
#include "Breakpoints.h"
#include "MMUMonitor.h"

#undef min
#undef max


static HANDLE hout=NULL;

SystemState EmuState;
Expand Down Expand Up @@ -408,17 +404,6 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
}
break;

case WM_SETFOCUS:
RECT scr;
POINT loc;
GetWindowRect(EmuState.WindowHandle,&scr);
GetCursorPos(&loc);
if ((loc.x > scr.right) | (loc.x < scr.left) |
(loc.y > scr.bottom) | ( loc.y < scr.top))
SetCursorPos(scr.left+20,scr.top+10);
// Set8BitPalette();
break;

case WM_KILLFOCUS:
// Force keys up if main widow keyboard focus is lost. Otherwise
// down keys will cause issues with OS-9 on return
Expand Down Expand Up @@ -582,20 +567,29 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
// Get the dimensions of the usable client area (i.e. sans status bar)
RECT clientRect;
GetClientRect(EmuState.WindowHandle, &clientRect);
clientRect.bottom -= GetMainWindowStatusBarHeight();

const auto displayDetails(GetDisplayDetails(clientRect.right, clientRect.bottom));
const int maxHorizontalPosition = clientRect.right - (displayDetails.leftBorderColumns + displayDetails.rightBorderColumns);
const int maxVerticalPosition = clientRect.bottom - (displayDetails.topBorderRows + displayDetails.bottomBorderRows);

int mouseXPosition = std::min(
std::max(0, LOWORD(lParam) - displayDetails.leftBorderColumns),
maxHorizontalPosition);
int mouseYPosition = std::min(
std::max(0, HIWORD(lParam) - displayDetails.topBorderRows),
maxVerticalPosition);

// Convert coordinates to mouseXPosition,mouseYPosition values with range 0-3fff (0-16383).
clientRect.bottom -= GetRenderWindowStatusBarHeight();

int mouseXPosition = GET_X_LPARAM(lParam);
int mouseYPosition = GET_Y_LPARAM(lParam);
int maxHorizontalPosition = clientRect.right;
int maxVerticalPosition = clientRect.bottom;

if (!EmuState.FullScreen)
{
const DisplayDetails displayDetails(GetDisplayDetails(clientRect.right, clientRect.bottom));

maxHorizontalPosition -= (displayDetails.leftBorderColumns + displayDetails.rightBorderColumns);
maxVerticalPosition -= (displayDetails.topBorderRows + displayDetails.bottomBorderRows);

mouseXPosition = min(
max(0, mouseXPosition - displayDetails.leftBorderColumns),
maxHorizontalPosition);
mouseYPosition = min(
max(0, mouseYPosition - displayDetails.topBorderRows),
maxVerticalPosition);
}

// Convert coordinates to mouseXPosition,mouseYPosition values with range 0-3fff (0-16383).
mouseXPosition = static_cast<int>(mouseXPosition * (MAX_AXIS_VALUE / maxHorizontalPosition));
mouseYPosition = static_cast<int>(mouseYPosition * (MAX_AXIS_VALUE / maxVerticalPosition));

Expand Down
24 changes: 10 additions & 14 deletions coco3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,29 +219,25 @@ void SetLinesperScreen (unsigned char Lines)
}



DisplayDetails GetDisplayDetails(const int clientWidth, const int clientHeight)
{
static const float VIRTUAL_DISPLAY_HEIGHT = 250.0f;
// FIXME: This is wrong. It should reflect the actual resolution scaled based on the clientWidth (will not be correct on 640x???)
// and changes are the display width is going to match the value we load into pixelsPerLine so horizontal scaling may not be
// necessary, at least in the end.
static const float VIRTUAL_DISPLAY_WIDTH = 320.f;
const int short pixelsPerLine = GetDisplayedPixelsPerLine();
const int horizontalBorderSize = GetHorizontalBorderSize();
const float pixelsPerLine = GetDisplayedPixelsPerLine();
const float horizontalBorderSize = GetHorizontalBorderSize();
const float activeLines = 250.0f; // FIXME: Needs a symbolic

DisplayDetails details;

const auto horizontalScale(clientWidth / VIRTUAL_DISPLAY_WIDTH);
const auto verticalScale(clientHeight / VIRTUAL_DISPLAY_HEIGHT);
const auto horizontalScale(clientWidth / pixelsPerLine);
const auto verticalScale(clientHeight / activeLines);
const auto extraBorderPadding = GetForcedAspectBorderPadding();

details.contentRows = static_cast<int>(LinesperScreen * verticalScale);
details.topBorderRows = static_cast<int>(TopBoarder * verticalScale);
details.bottomBorderRows = static_cast<int>(BottomBoarder * verticalScale);
details.topBorderRows = static_cast<int>(TopBoarder * verticalScale) + extraBorderPadding.y;
details.bottomBorderRows = static_cast<int>(BottomBoarder * verticalScale) + extraBorderPadding.y;

details.contentColumns = static_cast<int>(pixelsPerLine * horizontalScale);
details.leftBorderColumns = static_cast<int>(horizontalBorderSize * horizontalScale);
details.rightBorderColumns = static_cast<int>(horizontalBorderSize * horizontalScale);
details.leftBorderColumns = static_cast<int>(horizontalBorderSize * horizontalScale) + extraBorderPadding.x;
details.rightBorderColumns = static_cast<int>(horizontalBorderSize * horizontalScale) + extraBorderPadding.x;

return details;
}
Expand Down
4 changes: 2 additions & 2 deletions tcc1014graphics.c
Original file line number Diff line number Diff line change
Expand Up @@ -9966,12 +9966,12 @@ int GetBytesPerRow() {
return BytesperRow;
}

int GetHorizontalBorderSize()
unsigned char GetHorizontalBorderSize()
{
return HorzCenter / 2;
}

int GetDisplayedPixelsPerLine()
unsigned short GetDisplayedPixelsPerLine()
{
return PixelsperLine;
}
Expand Down
4 changes: 2 additions & 2 deletions tcc1014graphics.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ void SetVideoBank(unsigned char);
unsigned char SetMonitorType(unsigned char );
void SetBoarderChange (unsigned char);
int GetBytesPerRow(void);
int GetHorizontalBorderSize();
int GetDisplayedPixelsPerLine();
unsigned char GetHorizontalBorderSize();
unsigned short GetDisplayedPixelsPerLine();
unsigned int GetStartOfVidram();
int GetGraphicsMode();

Expand Down

0 comments on commit 71628d7

Please sign in to comment.