From 9af346cb820b7f0376c005b05f47ba37c4fcf4a9 Mon Sep 17 00:00:00 2001 From: Alexander Guryanov Date: Wed, 4 May 2022 14:19:26 +0700 Subject: [PATCH] Dynamic aspect --- lib/xgraph/xgraph.cpp | 45 ++++++++++++++++++++++++++++------------- lib/xgraph/xgraph.h | 8 +++++--- lib/xgraph/xside.cpp | 8 ++++++-- lib/xgraph/xside.h | 2 +- src/iscreen/iextern.cpp | 2 +- src/road.cpp | 42 +++----------------------------------- surmap/surmap.cpp | 20 +----------------- 7 files changed, 48 insertions(+), 79 deletions(-) diff --git a/lib/xgraph/xgraph.cpp b/lib/xgraph/xgraph.cpp index 1e5fdf1f..f52ec5e9 100644 --- a/lib/xgraph/xgraph.cpp +++ b/lib/xgraph/xgraph.cpp @@ -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"< 13/6.f /* iPhone */) { + aspect = 13/6.f; + } + + this->hdWidth = 1280; + this->hdHeight = 1280 / aspect; + std::cout<<"SDL_CreateWindowAndRenderer"<hdWidth, this->hdHeight, SDL_WINDOW_RESIZABLE | SDL_WINDOW_MAXIMIZED, &sdlWindow, &sdlRenderer) < 0) { std::cout<<"ERROR2"<hdWidth << "x" << this->hdHeight << std::endl; SDL_SetWindowTitle(sdlWindow, "Vangers"); std::cout<<"Load and set icon"<hdWidth, this->hdHeight); std::cout<<"SDL_ShowCursor"< #include #include @@ -20,6 +21,7 @@ SDL_Texture *HDRightSideTexture = nullptr; std::pair activeSides = std::make_pair<>(nullptr, nullptr); int currentRto = 0; int currentIScreenId = 0; +constexpr int contentWidth = 160; std::pair getSideNames() { int activeRtoId = getCurRtoId(); @@ -82,7 +84,7 @@ std::pair 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(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); } } diff --git a/lib/xgraph/xside.h b/lib/xgraph/xside.h index f6d67a06..b6e59fe1 100644 --- a/lib/xgraph/xside.h +++ b/lib/xgraph/xside.h @@ -7,6 +7,6 @@ #include -void XGR_RenderSides(SDL_Renderer* renderer); +void XGR_RenderSides(SDL_Renderer* renderer, int renderWidth); #endif // VANGERS_XSIDE_H diff --git a/src/iscreen/iextern.cpp b/src/iscreen/iextern.cpp index d886ac80..29485527 100644 --- a/src/iscreen/iextern.cpp +++ b/src/iscreen/iextern.cpp @@ -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; } diff --git a/src/road.cpp b/src/road.cpp index 8e0cb137..66085772 100644 --- a/src/road.cpp +++ b/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; diff --git a/surmap/surmap.cpp b/surmap/surmap.cpp index 2792dfef..6f7db444 100644 --- a/surmap/surmap.cpp +++ b/surmap/surmap.cpp @@ -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;