From 9a7ffb887f34f3ea8ccbce0e100768428c02fba2 Mon Sep 17 00:00:00 2001 From: Mathieu Schroeter Date: Wed, 27 Jun 2018 07:01:37 +0200 Subject: [PATCH] Move display stuff in a dedicated source file The display ratio is computed with the user's screen. It's no longer a static value. It must be improved in order to fix the ratio according to screen changes. --- src/def.h | 11 ++------ src/display.cxx | 71 +++++++++++++++++++++++++++++++++++++++++++++++++ src/display.h | 31 +++++++++++++++++++++ 3 files changed, 104 insertions(+), 9 deletions(-) create mode 100644 src/display.cxx create mode 100644 src/display.h diff --git a/src/def.h b/src/def.h index e988620..b26793f 100644 --- a/src/def.h +++ b/src/def.h @@ -22,18 +22,11 @@ #include +#include "display.h" + // clang-format off #define _INTRO true // true for init screen -#define SCRNUM 16 -#define SCRDEN 9 -#define SCRFACTOR SCRNUM / SCRDEN -#define LXLOGIC 640 -#define LYLOGIC 480 -#define LXIMAGE (LYLOGIC * SCRFACTOR + (LYLOGIC * SCRFACTOR) % 2) // window size -#define LYIMAGE LYLOGIC -#define LXOFFSET ((LXIMAGE - LXLOGIC) / 2) - #define POSDRAWX 144 // draw surface #define POSDRAWY 15 #define DIMDRAWX (LXIMAGE - (LXLOGIC - LYLOGIC)) diff --git a/src/display.cxx b/src/display.cxx new file mode 100644 index 0000000..5d98c16 --- /dev/null +++ b/src/display.cxx @@ -0,0 +1,71 @@ + +#include + +#include "blupi.h" +#include "display.h" + +#define SCRNUM 16 +#define SCRDEN 9 +#define SCRFACTOR SCRNUM / SCRDEN + +Display::Display () +{ + this->width = 0; + this->height = 0; +} + +void +Display::readDisplaySize () +{ + SDL_DisplayMode displayMode; + SDL_GetWindowDisplayMode (g_window, &displayMode); + this->width = displayMode.w; + this->height = displayMode.h; +} + +Display & +Display::getDisplay () +{ + static bool init = false; + static Display display; + + if (!init) + { + display.readDisplaySize (); + init = true; + } + + return display; +} + +double +Display::getRatio () +{ + return this->width / this->height; +} + +Sint32 +Display::getWidth () +{ + return ( + this->getLogicHeight () * SCRFACTOR + + (this->getLogicHeight () * SCRFACTOR) % 2); +} + +Sint32 +Display::getHeight () +{ + return this->getLogicHeight (); +} + +Sint32 +Display::getLogicWidth () +{ + return 640; +} + +Sint32 +Display::getLogicHeight () +{ + return 480; +} diff --git a/src/display.h b/src/display.h new file mode 100644 index 0000000..c9fd417 --- /dev/null +++ b/src/display.h @@ -0,0 +1,31 @@ + +#pragma once + +#include "SDL2/SDL_stdinc.h" + +class Display +{ +private: + Sint32 width; + Sint32 height; + +private: + Display (); + + void readDisplaySize (); + +public: + static Display & getDisplay (); + + double getRatio (); + Sint32 getWidth (); + Sint32 getHeight (); + Sint32 getLogicWidth (); + Sint32 getLogicHeight (); +}; + +#define LXLOGIC (Display::getDisplay ().getLogicWidth ()) +#define LYLOGIC (Display::getDisplay ().getLogicHeight ()) +#define LXIMAGE (Display::getDisplay ().getWidth ()) +#define LYIMAGE (Display::getDisplay ().getHeight ()) +#define LXOFFSET ((LXIMAGE - LXLOGIC) / 2)