mirror of
https://github.com/blupi-games/planetblupi
synced 2024-12-30 10:15:36 +01:00
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.
This commit is contained in:
parent
e70873a7b8
commit
9a7ffb887f
11
src/def.h
11
src/def.h
@ -22,18 +22,11 @@
|
|||||||
|
|
||||||
#include <SDL2/SDL_stdinc.h>
|
#include <SDL2/SDL_stdinc.h>
|
||||||
|
|
||||||
|
#include "display.h"
|
||||||
|
|
||||||
// clang-format off
|
// clang-format off
|
||||||
#define _INTRO true // true for init screen
|
#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 POSDRAWX 144 // draw surface
|
||||||
#define POSDRAWY 15
|
#define POSDRAWY 15
|
||||||
#define DIMDRAWX (LXIMAGE - (LXLOGIC - LYLOGIC))
|
#define DIMDRAWX (LXIMAGE - (LXLOGIC - LYLOGIC))
|
||||||
|
71
src/display.cxx
Normal file
71
src/display.cxx
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
|
||||||
|
#include <SDL2/SDL_video.h>
|
||||||
|
|
||||||
|
#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;
|
||||||
|
}
|
31
src/display.h
Normal file
31
src/display.h
Normal file
@ -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)
|
Loading…
x
Reference in New Issue
Block a user