Commit f1d8584c authored by Gerhard Stein's avatar Gerhard Stein Committed by Gerhard Stein

Aspect ratio fixes and mouse input recognitions

parent a3075010
......@@ -602,8 +602,10 @@ void CInput::transMouseRelCoord(Vector2D<float> &Pos,
const SDL_MouseMotionEvent motion,
const GsRect<Uint16> &activeArea)
{
Pos.x = ( static_cast<float>(motion.x-activeArea.x)/static_cast<float>(activeArea.w) );
Pos.y = ( static_cast<float>(motion.y-activeArea.y)/static_cast<float>(activeArea.h) );
Pos.x = ( static_cast<float>(motion.x-activeArea.x)/
static_cast<float>(activeArea.w) );
Pos.y = ( static_cast<float>(motion.y-activeArea.y)/
static_cast<float>(activeArea.h) );
}
......@@ -652,30 +654,15 @@ void CInput::pollEvents()
// TODO: It seems that Win32 Build get different coordinates. I still don't know why...
// Maybe I'm doing something wrong here!
/*
#ifdef WIN32
//if( !gVideoDriver.isOpenGL() )
{
activeArea.x = 0;
activeArea.y = 0;
}
#endif
#if SDL_VERSION_ATLEAST(2, 0, 0)
if( !gVideoDriver.isOpenGL() )
{
activeArea.x = 0;
activeArea.y = 0;
}
#else
//if( !gVideoDriver.isOpenGL() )
/*{
activeArea.x = 0;
activeArea.y = 0;
}*/
#endif
*/
// While there's an event to handle
while( SDL_PollEvent( &Event ) )
......@@ -725,7 +712,7 @@ void CInput::pollEvents()
{
gVideoDriver.mpVideoEngine->resizeDisplayScreen(
GsRect<Uint16>(Event.window.data1,
Event.window.data2) );
Event.window.data2) );
dispRect.w = Event.window.data1;
dispRect.h = Event.window.data2;
}
......
......@@ -43,7 +43,7 @@ bool COpenGL::resizeDisplayScreen(const GsRect<Uint16>& newDim)
#if SDL_VERSION_ATLEAST(2, 0, 0)
updateAspectRect(newDim, w, h);
updateActiveArea(newDim, w, h);
setUpViewPort(mActiveAreaRect);
......@@ -56,7 +56,7 @@ bool COpenGL::resizeDisplayScreen(const GsRect<Uint16>& newDim)
return false;
}
updateAspectRect(newDim, w, h);
updateActiveArea(newDim, w, h);
setUpViewPort(mActiceAreaRect);
......
......@@ -36,9 +36,6 @@ bool CSDLVideo::init()
SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "0");
}
const int aspW = m_VidConfig.mAspectCorrection.w;
const int aspH = m_VidConfig.mAspectCorrection.h;
if(window)
{
SDL_DestroyWindow(window);
......@@ -81,7 +78,10 @@ bool CSDLVideo::init()
SDL_RenderClear(renderer);
SDL_RenderPresent(renderer);
updateAspectRect(m_VidConfig.mDisplayRect, aspW, aspH);
const int aspW = m_VidConfig.mAspectCorrection.w;
const int aspH = m_VidConfig.mAspectCorrection.h;
updateActiveArea(m_VidConfig.mDisplayRect, aspW, aspH);
resizeDisplayScreen(m_VidConfig.mDisplayRect);
......@@ -108,7 +108,7 @@ bool CSDLVideo::resizeDisplayScreen(const GsRect<Uint16>& newDim)
const int w = m_VidConfig.mAspectCorrection.w;
const int h = m_VidConfig.mAspectCorrection.h;
updateAspectRect(newDim, w, h);
updateActiveArea(newDim, w, h);
#if SDL_VERSION_ATLEAST(2, 0, 0)
if(renderer != nullptr)
......@@ -217,10 +217,8 @@ void CSDLVideo::transformScreenToDisplay()
const bool tiltVideo = m_VidConfig.mTiltedScreen;
const auto &finalWindowSize = m_VidConfig.mDisplayRect;
mpScreenSfc->lock();
SDL_UpdateTexture(mpSDLScreenTexture.get(),
SDL_UpdateTexture(mpMainScreenTexture.get(),
nullptr,
mpScreenSfc->getSDLSurface()->pixels,
mpScreenSfc->width() * sizeof (Uint32));
......@@ -261,7 +259,17 @@ void CSDLVideo::transformScreenToDisplay()
SDL_RenderClear(renderer);
RenderCopy(renderer, mpSDLScreenTexture.get(), nullptr, nullptr);
SDL_Rect mainDstrect;
mainDstrect.x = mActiveAreaRect.x;
mainDstrect.y = mActiveAreaRect.y;
//mainDstrect.w = m_VidConfig.mDisplayRect.w*m_VidConfig.m_ScaleXFilter;
//mainDstrect.h = m_VidConfig.mDisplayRect.h*m_VidConfig.m_ScaleXFilter;
mainDstrect.w = mActiveAreaRect.w;
mainDstrect.h = mActiveAreaRect.h;
RenderCopy(renderer, mpMainScreenTexture.get(), nullptr, &mainDstrect);
// Now render the textures which additionally sent over...
......
......@@ -58,8 +58,8 @@ void CVidConfig::reset()
mOpengl = false; // Must stay optional for better compatibility
#endif
mAspectCorrection.w=4;
mAspectCorrection.h=3;
mAspectCorrection.w = 4;
mAspectCorrection.h = 3;
m_CameraBounds.reset();
mGameRect.x = 0;
......
......@@ -201,7 +201,8 @@ void CVideoDriver::verifyResolution(GsRect<Uint16>& resolution,
#endif
}
void CVideoDriver::setVidConfig(const CVidConfig& VidConf) {
void CVideoDriver::setVidConfig(const CVidConfig& VidConf)
{
mVidConfig = VidConf;
setMode(mVidConfig.mDisplayRect);
}
......
......@@ -150,8 +150,8 @@ bool CVideoEngine::init()
return true;
}
void CVideoEngine::updateAspectRect(const GsRect<Uint16>& displayRes,
const int aspWidth, const int aspHeight)
void CVideoEngine::updateActiveArea(const GsRect<Uint16>& displayRes,
const int aspWidth, const int aspHeight)
{
if (aspWidth == 0 || aspHeight == 0)
{
......@@ -241,7 +241,7 @@ bool CVideoEngine::createSurfaces(const GsRect<Uint16> &gamerect)
initOverlaySurface(blit->w, blit->h);
#if SDL_VERSION_ATLEAST(2, 0, 0)
mpSDLScreenTexture.reset( SDL_CreateTexture(renderer,
mpMainScreenTexture.reset( SDL_CreateTexture(renderer,
SDL_PIXELFORMAT_ARGB8888,
SDL_TEXTUREACCESS_STREAMING,
gamerect.w*m_VidConfig.m_ScaleXFilter,
......
......@@ -70,12 +70,12 @@ public:
/**
* @brief updateAspectRect Updates the mActiveAreaRect which is used when rendering the screen
* @brief updateActiveArea Updates the mActiveAreaRect which is used when rendering the screen
* @param displayRes The dimension of the window or resolution of the display when in Fullscreen
* @param aspWidth wished aspect width
* @param aspHeight wished aspect height
*/
void updateAspectRect(const GsRect<Uint16>& displayRes, const int aspWidth, const int aspHeight);
void updateActiveArea(const GsRect<Uint16>& displayRes, const int aspWidth, const int aspHeight);
virtual void transformScreenToDisplay() = 0;
virtual void shutdown();
......@@ -146,7 +146,7 @@ protected:
#if SDL_VERSION_ATLEAST(2, 0, 0)
std::unique_ptr<SDL_Texture, SDL_Texture_Deleter> mpSDLScreenTexture;
std::unique_ptr<SDL_Texture, SDL_Texture_Deleter> mpMainScreenTexture;
#else
// it is what you see on your monitor in the end in your window or on fullscreen
......
......@@ -237,42 +237,45 @@ void GsFont::tintColor( const Uint32 fgColor )
void GsFont::setupColor( const Uint32 fgColor )
{
// Here comes the main part. We have to manipulate the Surface the way it gets
// the given color
// Here comes the main part. We have to manipulate the Surface the way it gets
// the given color
std::array<SDL_Color, 16> color;
for(auto &pFontSurface : mpFontSurface)
{
auto palette = pFontSurface->getSDLSurface()->format->palette;
memcpy( color.data(), palette->colors, 16*sizeof(SDL_Color) );
SDL_PixelFormat *pPixelformat = gVideoDriver.getBlitSurface()->format;
SDL_GetRGB(fgColor, pPixelformat, &color[15].r, &color[15].g, &color[15].b);
if(palette)
{
memcpy( color.data(), palette->colors, 16*sizeof(SDL_Color) );
SDL_GetRGB(fgColor, pPixelformat, &color[15].r, &color[15].g, &color[15].b);
// Change palette colors to the one requested
pFontSurface->setPaletteColors(color.data());
pFontSurface->setColorKey(COLORKEY_4BIT);
// Change palette colors to the one requested
pFontSurface->setPaletteColors(color.data());
pFontSurface->setColorKey(COLORKEY_4BIT);
}
}
}
Uint32 GsFont::getFGColor()
{
// Here comes the main part. We have to manipulate the Surface the way it gets
// the given color
// Here comes the main part. We have to manipulate the Surface the way it gets
// the given color
std::array<SDL_Color, 16> color;
auto fontSfc = mpFontSurface[0]->getSDLSurface();
auto palette = fontSfc->format->palette;
auto palette = fontSfc->format->palette;
SDL_PixelFormat *pPixelformat = gVideoDriver.getBlitSurface()->format;
if(palette)
{
memcpy( color.data(), palette->colors, color.size()*sizeof(SDL_Color) );
memcpy( color.data(), palette->colors, color.size()*sizeof(SDL_Color) );
// Change palette colors to the desired one
return SDL_MapRGB(pPixelformat, color[15].r, color[15].g, color[15].b);
// Change palette colors to the desired one
return SDL_MapRGB(pPixelformat, color[15].r, color[15].g, color[15].b);
}
else
{
......
......@@ -81,7 +81,7 @@ GameMenu(GsRect<float>(0.15f, 0.20f, 0.65f, 0.55f), style )
void CVideoSettings::refresh()
{
mUserVidConf = gVideoDriver.getVidConfig();
mUsersConf = gVideoDriver.getVidConfig();
// Load the config into the GUI
// TODO: Temporary. This must become a float later...
......@@ -89,24 +89,24 @@ void CVideoSettings::refresh()
mpFPSSelection->setSelection( iFPS );
mpFrameSkip->enable( (iFPS> 0.0) ? true : false );
mpShowCursorSwitch->enable( mUserVidConf.mShowCursor );
mpTiltScreenSwitch->enable( mUserVidConf.mTiltedScreen );
mpShowCursorSwitch->enable( mUsersConf.mShowCursor );
mpTiltScreenSwitch->enable( mUsersConf.mTiltedScreen );
mpVPadSwitch->enable( mUserVidConf.mVPad );
mpVPadSwitch->enable( mUsersConf.mVPad );
// TODO: find a way to indicate a color
mpBorderColorSwitch->enable( mUserVidConf.mBorderColorsEnabled );
mpBorderColorSwitch->enable( mUsersConf.mBorderColorsEnabled );
mpHorizBordersSelection->setSelection( mUserVidConf.mHorizBorders );
mpHorizBordersSelection->setSelection( mUsersConf.mHorizBorders );
#if !defined(EMBEDDED)
mpGameResSelection->setList( GamesResList, NUM_GAME_RESOLUTIONS );
std::string resStr;
resStr = itoa(mUserVidConf.mGameRect.w);
resStr = itoa(mUsersConf.mGameRect.w);
resStr += "x";
resStr += itoa(mUserVidConf.mGameRect.h);
resStr += itoa(mUsersConf.mGameRect.h);
mpGameResSelection->setSelection(resStr);
#endif
......@@ -117,8 +117,8 @@ void CVideoSettings::refresh()
void CVideoSettings::release()
{
// Save up the changed stuff
mUserVidConf.mShowCursor = mpShowCursorSwitch->isEnabled();
mUserVidConf.mTiltedScreen = mpTiltScreenSwitch->isEnabled();
mUsersConf.mShowCursor = mpShowCursorSwitch->isEnabled();
mUsersConf.mTiltedScreen = mpTiltScreenSwitch->isEnabled();
gTimer.setFPS( mpFPSSelection->getSelection() );
......@@ -127,51 +127,51 @@ void CVideoSettings::release()
gTimer.setFPS( 0.0 );
}
mUserVidConf.mVPad = mpVPadSwitch->isEnabled();
mUsersConf.mVPad = mpVPadSwitch->isEnabled();
mUserVidConf.mHorizBorders = mpHorizBordersSelection->getSelection();
mUsersConf.mHorizBorders = mpHorizBordersSelection->getSelection();
mUserVidConf.mBorderColorsEnabled = mpBorderColorSwitch->isEnabled();
mUsersConf.mBorderColorsEnabled = mpBorderColorSwitch->isEnabled();
#if !defined(EMBEDDED)
mUserVidConf.mVPad = mpVPadSwitch->isEnabled();
mUsersConf.mVPad = mpVPadSwitch->isEnabled();
// Disable OpenGL when using Virtual GL
if(mUserVidConf.mVPad)
if(mUsersConf.mVPad)
{
mUserVidConf.mOpengl = false;
mUsersConf.mOpengl = false;
}
const std::string GameResStr = mpGameResSelection->getSelection();
sscanf( GameResStr.c_str(), "%hux%hux", &mUserVidConf.mGameRect.w, &mUserVidConf.mGameRect.h );
sscanf( GameResStr.c_str(), "%hux%hux", &mUsersConf.mGameRect.w, &mUsersConf.mGameRect.h );
#endif
#if defined(CAANOO) || defined(WIZ) || defined(DINGOO) || defined(NANONOTE) || defined(ANDROID)
mUserVidConf.mDisplayRect.w = 320;
mUserVidConf.mDisplayRect.h = 200;
mUsersConf.mDisplayRect.w = 320;
mUsersConf.mDisplayRect.h = 200;
#endif
// TODO: Find a better way to setup colors in the menu
if(mpBorderColorSwitch->isEnabled())
{
mUserVidConf.mBorderColors.r = 0x00;
mUserVidConf.mBorderColors.g = 0xAA;
mUserVidConf.mBorderColors.b = 0xAA;
mUsersConf.mBorderColors.r = 0x00;
mUsersConf.mBorderColors.g = 0xAA;
mUsersConf.mBorderColors.b = 0xAA;
}
mUserVidConf.mBorderColorsEnabled = mpBorderColorSwitch->isEnabled();
mUsersConf.mBorderColorsEnabled = mpBorderColorSwitch->isEnabled();
mUserVidConf.mHorizBorders = mpHorizBordersSelection->getSelection();
mUsersConf.mHorizBorders = mpHorizBordersSelection->getSelection();
// In case the user changed something in the camera settings, reload that.
mUserVidConf.m_CameraBounds = gVideoDriver.getCameraBounds();
mUsersConf.m_CameraBounds = gVideoDriver.getCameraBounds();
CVidConfig oldVidConf = gVideoDriver.getVidConfig();
gVideoDriver.setVidConfig(mUserVidConf);
gVideoDriver.setVidConfig(mUsersConf);
// At this point we also must apply and save the settings
if( !gVideoDriver.applyMode() )
......
......@@ -31,7 +31,7 @@ public:
void release();
CVidConfig mUserVidConf;
CVidConfig mUsersConf;
private:
......
/*
* Display.cpp
*
* Created on: 09.01.2018
* Author: gerstrong
*/
#include <base/CInput.h>
#include <base/GsTimer.h>
#include <base/video/resolutionlist.h>
#include <base/video/CVideoDriver.h>
#include <base/utils/StringUtils.h>
#include <widgets/GsMenuController.h>
#include "engine/core/CBehaviorEngine.h"
#include "CameraSettings.h"
#include "CVideoSettings.h"
#include <base/utils/Utils.h>
#include "widgets/NumberControl.h"
#include "widgets/ComboSelection.h"
#include "engine/core/CSettings.h"
#include "engine/core/videoAspect.h"
#include "DisplaySettings.h"
class toggleFullscreenFunctor : public InvokeFunctorEvent
{
public:
toggleFullscreenFunctor( DisplaySettings& DispSettings ) :
mDispSettings(DispSettings) {}
private:
void operator()() const
{
mDispSettings.mUsersConf.mFullscreen = !mDispSettings.mUsersConf.mFullscreen;
mDispSettings.release();
}
DisplaySettings& mDispSettings;
};
DisplaySettings::DisplaySettings(const GsControl::Style style) :
#if defined(EMBEDDED)
GameMenu(GsRect<float>(0.15f, 0.20f, 0.65f, 0.25f), style )
#else
GameMenu(GsRect<float>(0.15f, 0.20f, 0.65f, 0.55f), style )
#endif
{
#if !defined(EMBEDDED)
mpAspectSelection = new ComboSelection( "Aspect",
filledStrList(1, "disabled"),
style );
mpMenuDialog->addControl( mpAspectSelection );
mpFilterSelection =
new ComboSelection( "Filter",
filledStrList( 4,
"none",
"scale2x",
"scale3x",
"scale4x" ),
style );
mpMenuDialog->addControl( mpFilterSelection );
mpVSyncSwitch = new Switch( "VSync", style );
mpMenuDialog->addControl( mpVSyncSwitch );
mpResolutionSelection = new ComboSelection( "Size",
filledStrList(1, "?x?"),
style);
mpMenuDialog->addControl( mpResolutionSelection );
mpFullScreenSwitch = new GameButton( "Unknown mode",
new toggleFullscreenFunctor(*this),
style);
mpMenuDialog->addControl( mpFullScreenSwitch );
#endif
#if defined(USE_OPENGL)
mpOpenGLSwitch = new Switch( "OpenGL", style );
mpMenuDialog->addControl( mpOpenGLSwitch );
mpRenderScaleQualitySel = new ComboSelection( "Quality",
filledStrList( 2,
"nearest",
"linear" ),
style);
#else
mpRenderScaleQualitySel = new ComboSelection( "Quality",
filledStrList( 3,
"nearest",
"linear",
"best" ),
style);
#endif
mpMenuDialog->addControl( mpRenderScaleQualitySel );
setMenuLabel("OPTIONSMENULABEL");
refresh();
}
void DisplaySettings::refresh()
{
mUsersConf = gVideoDriver.getVidConfig();
#if defined(USE_OPENGL)
mpOpenGLSwitch->enable( mUsersConf.mOpengl );
#endif
mpRenderScaleQualitySel->setSelection(mUsersConf.mRenderScQuality);
#if !defined(EMBEDDED)
mpAspectSelection->setList( aspectList, NUM_ASPECTS );
std::string arcStr;
arcStr = itoa(mUsersConf.mAspectCorrection.w);
arcStr += ":";
arcStr += itoa(mUsersConf.mAspectCorrection.h);
if( arcStr == "0:0")
arcStr = "disabled";
mpAspectSelection->setSelection(arcStr);
mpFilterSelection->setSelection( mUsersConf.m_ScaleXFilter==1 ? "none" : (mUsersConf.m_normal_scale ? "normal" : "scale") + itoa(mUsersConf.m_ScaleXFilter) + "x" );
mpVSyncSwitch->enable( mUsersConf.mVSync );
mpFullScreenSwitch->setText( mUsersConf.mFullscreen ? "Go Windowed" : "Go Fullscreen" );
mpResolutionSelection->setList( ResolutionsList, NUM_MAIN_RESOLUTIONS );
std::string resStr;
resStr = itoa(mUsersConf.mDisplayRect.w);
resStr += "x";
resStr += itoa(mUsersConf.mDisplayRect.h);
mpResolutionSelection->setSelection(resStr);
#endif
}
void DisplaySettings::release()
{
// Read Aspect correction string
{
const std::string arcStr = mpAspectSelection->getSelection();
const int numRead = sscanf(arcStr.c_str(),"%i:%i",
&mUsersConf.mAspectCorrection.w,
&mUsersConf.mAspectCorrection.h);
if(numRead < 2)
{
mUsersConf.mAspectCorrection.w = mUsersConf.mAspectCorrection.h = 0;
}
}
// In case the user changed something in the camera settings, reload that.
mUsersConf.m_CameraBounds = gVideoDriver.getCameraBounds();
CVidConfig oldVidConf = gVideoDriver.getVidConfig();
gVideoDriver.setVidConfig(mUsersConf);
// At this point we also must apply and save the settings
if( !gVideoDriver.applyMode() )
{
gSettings.loadDrvCfg(); // If it fails load the old settings
return;
}
if( !gVideoDriver.start() ) // Here the same situation
{
gVideoDriver.setVidConfig(oldVidConf);
gVideoDriver.start();
}
gSettings.saveDrvCfg();
gMenuController.updateGraphics();
}
/*
* DisplaySettings.h
*
* Created on: 09.01.2018
* Author: gerstrong
*/
#ifndef DISPLAYSETTINGS_H_INCLUDED
#define DISPLAYSETTINGS_H_INCLUDED
#include <SDL.h>
#include <string>
#include <widgets/GsBaseMenu.h>
#include "widgets/ComboSelection.h"
#include "widgets/Switch.h"
#include "widgets/NumberControl.h"
#include "widgets/Button.h"
#include "GameMenu.h"
#include <base/video/CVidConfig.h>
class DisplaySettings : public GameMenu
{
public:
DisplaySettings(const GsControl::Style style);
void refresh();
void release();
CVidConfig mUsersConf;
private:
#if defined(USE_OPENGL)
Switch *mpOpenGLSwitch = nullptr;
#endif
ComboSelection *mpRenderScaleQualitySel = nullptr;
ComboSelection *mpFilterSelection = nullptr;
ComboSelection *mpAspectSelection = nullptr;
Switch *mpVSyncSwitch = nullptr;
ComboSelection *mpResolutionSelection = nullptr;
GameButton *mpFullScreenSwitch = nullptr;
};
#endif /* DISPLAYSETTINGS_H_INCLUDED */
......@@ -58,13 +58,13 @@ GameMenu( GsRect<float>(0.25f, 0.24f, 0.5f, 0.40f),
style) ),
style ) );
#endif
/*
#if !defined(EMBEDDED)
mpMenuDialog->addControl( new GameButton( "Camera",
new OpenMenuEvent( new CCameraSettings(style) ),
style ) );
#endif
*/
mpMenuDialog->addControl(new GameButton( "Cheats",
new OpenMenuEvent( new CheatsMenu(style) ),
style ) );
......
......@@ -52,34 +52,18 @@ void Switch::drawNoStyle(SDL_Rect& lRect)
return;
}
ComboSelection::drawNoStyle(lRect);
/*
SDL_Surface *blitsfc = gVideoDriver.getBlitSurface();
// Now lets draw the text of the list control
GsFont &Font = gGraphics.getFont(0);
Font.drawFont( blitsfc, mText, lRect.x+24, lRect.y, false );
Font.drawFont( blitsfc, ":", lRect.x+24+mText.size()*8, lRect.y, false );
std::string text;
if( (*mOLCurrent) == "off" )
{
text = "\24\25\26\27";
}
else
{
text = "\34\35\36\37";
}
std::string text = mText + ": " + (*mOLCurrent);
Font.drawFont( blitsfc, text, lRect.x+40, lRect.y, false );
Font.drawFont( blitsfc, text,
lRect.x+24+(mText.size()+2)*8,
lRect.y, false );*/
drawTwirl(lRect);
}
void Switch::processRender(const GsRect<float> &RectDispCoordFloat)
{
if(mStyle == Style::GALAXY)
......
......@@ -94,7 +94,16 @@ void ComboSelection::processRender(const GsRect<float> &RectDispCoordFloat)
}
else
{
drawNoStyle(lRect);
if(!mEnabled)
return;
// Now lets draw the text of the list control
GsFont &Font = gGraphics.getFont(mFontID);
Font.drawFont( blitsfc.getSDLSurface(), mText, lRect.x+24, lRect.y, false );
Font.drawFont( blitsfc.getSDLSurface(), ":", lRect.x+24+mText.size()*8, lRect.y, false );
const std::string text = (*mOLCurrent);
Font.drawFont( blitsfc.getSDLSurface(), text, lRect.x+24+(mText.size()+2)*8, lRect.y, false );
}
}
......