mirror of
https://github.com/KranX/Vangers.git
synced 2025-11-30 23:15:27 +07:00
Merge pull request #564 from caiiiycuk/patch-2
Dynamic aspect + window resize
This commit is contained in:
@@ -132,7 +132,7 @@ XGR_Screen::XGR_Screen(void)
|
||||
sdlTexture = NULL;
|
||||
}
|
||||
|
||||
int XGR_Screen::init(int x,int y,int flags_in)
|
||||
int XGR_Screen::init(int flags_in)
|
||||
{
|
||||
flags = flags_in;
|
||||
std::cout<<"XGR_Screen::init"<<std::endl;
|
||||
@@ -148,6 +148,24 @@ int XGR_Screen::init(int x,int y,int flags_in)
|
||||
SDL_DestroyRenderer(sdlRenderer);
|
||||
SDL_DestroyWindow(sdlWindow);
|
||||
}
|
||||
|
||||
SDL_DisplayMode displayMode;
|
||||
SDL_GetCurrentDisplayMode(0, &displayMode);
|
||||
int maxWidth = displayMode.w;
|
||||
int maxHeight = displayMode.h;
|
||||
|
||||
float aspect = (float) maxWidth / (float) maxHeight;
|
||||
if (aspect < 4/3.f) {
|
||||
aspect = 4/3.f;
|
||||
}
|
||||
|
||||
if (aspect > 13/6.f /* iPhone */) {
|
||||
aspect = 13/6.f;
|
||||
}
|
||||
|
||||
this->hdWidth = 1280;
|
||||
this->hdHeight = 1280 / aspect;
|
||||
|
||||
std::cout<<"SDL_CreateWindowAndRenderer"<<std::endl;
|
||||
if (XGR_FULL_SCREEN) {
|
||||
if (SDL_CreateWindowAndRenderer(0, 0, SDL_WINDOW_FULLSCREEN_DESKTOP, &sdlWindow, &sdlRenderer) < 0) {
|
||||
@@ -155,12 +173,12 @@ int XGR_Screen::init(int x,int y,int flags_in)
|
||||
ErrH.Abort(SDL_GetError(),XERR_USER, 0);
|
||||
}
|
||||
} else {
|
||||
if (SDL_CreateWindowAndRenderer(x, y, 0, &sdlWindow, &sdlRenderer) < 0) {
|
||||
if (SDL_CreateWindowAndRenderer(this->hdWidth, this->hdHeight, SDL_WINDOW_RESIZABLE | SDL_WINDOW_MAXIMIZED, &sdlWindow, &sdlRenderer) < 0) {
|
||||
std::cout<<"ERROR2"<<std::endl;
|
||||
ErrH.Abort(SDL_GetError(),XERR_USER, 0);
|
||||
}
|
||||
}
|
||||
std::cout<<"SDL_SetWindowTitle"<<std::endl;
|
||||
std::cout << "SDL_Window created: " << this->hdWidth << "x" << this->hdHeight << std::endl;
|
||||
SDL_SetWindowTitle(sdlWindow, "Vangers");
|
||||
|
||||
std::cout<<"Load and set icon"<<std::endl;
|
||||
@@ -185,7 +203,7 @@ int XGR_Screen::init(int x,int y,int flags_in)
|
||||
std::cout<<"SDL_SetHint"<<std::endl;
|
||||
SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "best"); // "linear" make the scaled rendering look smoother.
|
||||
|
||||
create_surfaces(x, y);
|
||||
create_surfaces(this->hdWidth, this->hdHeight);
|
||||
|
||||
std::cout<<"SDL_ShowCursor"<<std::endl;
|
||||
//SDL_SetRelativeMouseMode(SDL_TRUE);
|
||||
@@ -258,16 +276,7 @@ void XGR_Screen::create_surfaces(int width, int height) {
|
||||
}
|
||||
|
||||
void XGR_Screen::set_resolution(int width, int height){
|
||||
// TODO: do not change resolution, is new res is the same
|
||||
std::cout << "XGR_Screen::set_resolution: " << width << ", " << height << std::endl;
|
||||
if(width == ScreenX && height == ScreenY){
|
||||
std::cout << "Resolution didn't change" << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
destroy_surfaces();
|
||||
SDL_SetWindowSize(sdlWindow, width, height);
|
||||
create_surfaces(width, height);
|
||||
|
||||
if (width == 800 && height == 600) {
|
||||
// for comparison == 1
|
||||
@@ -277,6 +286,14 @@ void XGR_Screen::set_resolution(int width, int height){
|
||||
screen_scale_x = (float)width / 800;
|
||||
screen_scale_y = (float)height / 600;
|
||||
}
|
||||
|
||||
if(width == ScreenX && height == ScreenY){
|
||||
std::cout << "Resolution didn't change" << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
destroy_surfaces();
|
||||
create_surfaces(width, height);
|
||||
}
|
||||
|
||||
const float XGR_Screen::get_screen_scale_x() {
|
||||
@@ -955,7 +972,7 @@ void XGR_Screen::flip()
|
||||
.w = new_width,
|
||||
.h = xgrScreenSizeY,
|
||||
};
|
||||
XGR_RenderSides(sdlRenderer);
|
||||
XGR_RenderSides(sdlRenderer, new_width);
|
||||
SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, 0);
|
||||
SDL_RenderCopy(sdlRenderer, sdlTexture, &src_rect, &dst_rect);
|
||||
}else{
|
||||
|
||||
@@ -103,6 +103,9 @@ struct XGR_Screen
|
||||
{
|
||||
int flags;
|
||||
|
||||
int hdWidth;
|
||||
int hdHeight;
|
||||
|
||||
int ScreenX;
|
||||
int ScreenY;
|
||||
int RealX;
|
||||
@@ -144,7 +147,7 @@ struct XGR_Screen
|
||||
void line(int x1,int y1,int x2,int y2,int col);
|
||||
void lineto(int x,int y,int len,int dir,int col);
|
||||
|
||||
int init(int x,int y,int flags);
|
||||
int init(int flags);
|
||||
void close(void);
|
||||
void finit(void);
|
||||
|
||||
@@ -454,8 +457,7 @@ struct XGR_Mouse
|
||||
XGR_Mouse(void);
|
||||
};
|
||||
|
||||
#define XGR_Init(x,y,fl) XGR_Obj.init(x,y,fl)
|
||||
#define XGR_ReInit(x,y,fl) XGR_Obj.init(x,y,fl | XGR_REINIT)
|
||||
#define XGR_Init(fl) XGR_Obj.init(fl)
|
||||
#define XGR_Finit() XGR_Obj.finit()
|
||||
#define XGR_SetClip(left,top,right,bottom) XGR_Obj.set_clip(left,top,right,bottom)
|
||||
#define XGR_GetClip(left,top,right,bottom) XGR_Obj.get_clip(left,top,right,bottom)
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
//
|
||||
|
||||
#include "xbmp.h"
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
#include <utility>
|
||||
|
||||
@@ -20,6 +21,7 @@ SDL_Texture *HDRightSideTexture = nullptr;
|
||||
std::pair<const char *, const char *> activeSides = std::make_pair<>(nullptr, nullptr);
|
||||
int currentRto = 0;
|
||||
int currentIScreenId = 0;
|
||||
constexpr int contentWidth = 160;
|
||||
|
||||
std::pair<const char *, const char *> getSideNames() {
|
||||
int activeRtoId = getCurRtoId();
|
||||
@@ -82,7 +84,7 @@ std::pair<const char *, const char *> getSideNames() {
|
||||
}
|
||||
}
|
||||
|
||||
void XGR_RenderSides(SDL_Renderer *renderer) {
|
||||
void XGR_RenderSides(SDL_Renderer *renderer, int renderWidth) {
|
||||
auto sideNames = getSideNames();
|
||||
|
||||
if (sideNames.first != activeSides.first) {
|
||||
@@ -99,15 +101,17 @@ void XGR_RenderSides(SDL_Renderer *renderer) {
|
||||
activeSides.second = sideNames.second;
|
||||
}
|
||||
|
||||
int outWidth = (xgrScreenSizeX - renderWidth) / 2;
|
||||
SDL_Rect dst_rect{0, 0, 0, xgrScreenSizeY};
|
||||
if (HDLeftSideTexture != nullptr) {
|
||||
SDL_QueryTexture(HDLeftSideTexture, nullptr, nullptr, &dst_rect.w, nullptr);
|
||||
dst_rect.x = std::max<int>(0, outWidth - contentWidth);
|
||||
SDL_RenderCopy(renderer, HDLeftSideTexture, NULL, &dst_rect);
|
||||
}
|
||||
|
||||
if (HDRightSideTexture != nullptr) {
|
||||
SDL_QueryTexture(HDRightSideTexture, nullptr, nullptr, &dst_rect.w, nullptr);
|
||||
dst_rect.x = xgrScreenSizeX - dst_rect.w;
|
||||
dst_rect.x = xgrScreenSizeX - outWidth - (dst_rect.w - contentWidth);
|
||||
SDL_RenderCopy(renderer, HDRightSideTexture, NULL, &dst_rect);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,6 @@
|
||||
|
||||
#include <SDL.h>
|
||||
|
||||
void XGR_RenderSides(SDL_Renderer* renderer);
|
||||
void XGR_RenderSides(SDL_Renderer* renderer, int renderWidth);
|
||||
|
||||
#endif // VANGERS_XSIDE_H
|
||||
|
||||
@@ -657,7 +657,7 @@ void iSetResolution(int state) {
|
||||
XGR_Obj.set_resolution(800, 600);
|
||||
break;
|
||||
case 1:
|
||||
XGR_Obj.set_resolution(1280, 720);
|
||||
XGR_Obj.set_resolution(XGR_Obj.hdWidth, XGR_Obj.hdHeight);
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
42
src/road.cpp
42
src/road.cpp
@@ -265,7 +265,6 @@ int* CO;
|
||||
int zoom_delta;
|
||||
int zoom_threshold;
|
||||
|
||||
int videoMode = 1;
|
||||
int beebos;
|
||||
int idOS,inHighPriority;
|
||||
|
||||
@@ -463,32 +462,8 @@ int xtInitApplication(void) {
|
||||
emode = ExclusiveLog ? XGR_EXCLUSIVE : 0;
|
||||
//emode |= XGR_HICOLOR;
|
||||
|
||||
|
||||
if (!videoMode) {
|
||||
actintLowResFlag = 1;
|
||||
#ifdef ISCREEN
|
||||
videoMode = 2;
|
||||
#endif
|
||||
}
|
||||
videoMode = 1;
|
||||
float w = 800;
|
||||
float h = 600;
|
||||
|
||||
switch (videoMode) {
|
||||
case 1:
|
||||
w = 800;
|
||||
h = 600;
|
||||
break;
|
||||
case 2:
|
||||
w = 1024;
|
||||
h = 768;
|
||||
break;
|
||||
case 3:
|
||||
w = 1280;
|
||||
h = 720;
|
||||
}
|
||||
|
||||
if (XGR_Init(w, h, emode)) ErrH.Abort(ErrorVideoMss);
|
||||
actintLowResFlag = 1;
|
||||
if (XGR_Init(emode)) ErrH.Abort(ErrorVideoMss);
|
||||
|
||||
|
||||
//WORK sWinVideo::Init();
|
||||
@@ -1479,17 +1454,6 @@ void ComlineAnalyze(int argc,char** argv)
|
||||
case '&':
|
||||
if(argv[i][j + 2] == '^') SkipCD = 1;
|
||||
break;
|
||||
case '0':
|
||||
videoMode = 0;
|
||||
break;
|
||||
case '1':
|
||||
videoMode = 1;
|
||||
break;
|
||||
/* video 1024 not working correctly */
|
||||
case '2':
|
||||
videoMode = 2;
|
||||
break;
|
||||
/* */
|
||||
#ifdef _DEBUG
|
||||
case 'q':
|
||||
host_port = atoi(argv[i] + (j + 2));
|
||||
@@ -1820,7 +1784,7 @@ void iGameMap::reset(void)
|
||||
prmFlag = 0;
|
||||
SlopeAngle = 0;// -Pi/4;
|
||||
DepthShow = 0;
|
||||
camera_zmin = TurnSecX = xsize;
|
||||
camera_zmin = TurnSecX = xsize / XGR_Obj.get_screen_scale_x();
|
||||
TurnSecY = ysize;
|
||||
TurnSideX = TurnSecX >> 1;
|
||||
TurnSideY = TurnSecY >> 1;
|
||||
|
||||
@@ -141,7 +141,6 @@ int RestoreLog,CGenLog,BorderLog,MobilityLog,InitLog,SSSLog,ROLog,EncodeLog,Dire
|
||||
int ForcedCompressed,ForcedUncompressed;
|
||||
int ConvertLog;
|
||||
int WaterPrm = -1;
|
||||
int videoMode = 2;
|
||||
|
||||
const char* mapFName = "wrlds.dat";
|
||||
int ColorShow = 1;
|
||||
@@ -225,18 +224,7 @@ int xtInitApplication(void)
|
||||
sysfont.init(fo);
|
||||
|
||||
emode = ExclusiveLog ? XGR_EXCLUSIVE : 0;
|
||||
|
||||
switch(videoMode){
|
||||
case 0:
|
||||
if(XGR_Init(640,480,emode)) ErrH.Abort("Error video initialization");
|
||||
break;
|
||||
case 1:
|
||||
if(XGR_Init(800,600,emode)) ErrH.Abort("Error video initialization");
|
||||
break;
|
||||
case 2:
|
||||
if(XGR_Init(1280,720,emode)) ErrH.Abort("Error video initialization");
|
||||
break;
|
||||
}
|
||||
if(XGR_Init(emode)) ErrH.Abort("Error video initialization");
|
||||
|
||||
XSIDE = XGR_MAXX/2 - 4;
|
||||
YSIDE = (XGR_MAXY - 10 - 22 - 16)/2;
|
||||
@@ -454,12 +442,6 @@ void ComlineAnalyze(int argc,char** argv)
|
||||
case 'h':
|
||||
WHLog = 1;
|
||||
break;
|
||||
case '1':
|
||||
videoMode = 1;
|
||||
break;
|
||||
case '2':
|
||||
videoMode = 2;
|
||||
break;
|
||||
case '#':
|
||||
ConvertLog = 1;
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user