From fd43a6ef017a088c3efad896d888cf7b22e469af Mon Sep 17 00:00:00 2001 From: Mathieu Schroeter Date: Fri, 6 Oct 2017 18:23:07 +0200 Subject: WIP: add landscape support --- src/pixmap.cxx | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'src/pixmap.cxx') diff --git a/src/pixmap.cxx b/src/pixmap.cxx index 23c6c1c..ae9f029 100644 --- a/src/pixmap.cxx +++ b/src/pixmap.cxx @@ -497,8 +497,16 @@ CPixmap::DrawImage (Sint32 chDst, size_t channel, Rect rect) if (m_SDLTextureInfo.find (channel) == m_SDLTextureInfo.end ()) return false; - dst.x = rect.left; - dst.y = rect.top; + if (channel == CHBACK) + { + dst.x = (LXIMAGE - LXLOGIC) / 2; + dst.y = (LYIMAGE - LYLOGIC) / 2; + } + else + { + dst.x = rect.left; + dst.y = rect.top; + } res = BltFast (chDst, channel, dst, rect); -- cgit v1.2.3 From dcbfd5cc35f9e767ae29b3f77e42df7b5b5c05bb Mon Sep 17 00:00:00 2001 From: Mathieu Schroeter Date: Tue, 10 Oct 2017 18:28:09 +0200 Subject: Add a method to create an empty texture --- src/pixmap.cxx | 47 +++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 45 insertions(+), 2 deletions(-) (limited to 'src/pixmap.cxx') diff --git a/src/pixmap.cxx b/src/pixmap.cxx index ae9f029..3f01276 100644 --- a/src/pixmap.cxx +++ b/src/pixmap.cxx @@ -212,14 +212,57 @@ CPixmap::ReloadTargetTextures () if (!tex.second.target) continue; - if (!Cache ( - tex.first, tex.second.file, tex.second.dimTotal, tex.second.dimIcon)) + if (tex.second.file.empty ()) + { + if (!Cache (tex.first, tex.second.dimTotal)) + return false; + } + else if (!Cache ( + tex.first, tex.second.file, tex.second.dimTotal, + tex.second.dimIcon)) return false; } return true; } +bool +CPixmap::Cache (size_t channel, Point totalDim) +{ + if (m_SDLTextureInfo.find (channel) == m_SDLTextureInfo.end ()) + { + m_SDLTextureInfo[channel].texture = SDL_CreateTexture ( + g_renderer, SDL_PIXELFORMAT_RGBA32, SDL_TEXTUREACCESS_TARGET, totalDim.x, + totalDim.y); + + if (!m_SDLTextureInfo[channel].texture) + { + SDL_LogError ( + SDL_LOG_CATEGORY_APPLICATION, "Couldn't create texture: %s", + SDL_GetError ()); + return false; + } + + SDL_SetTextureBlendMode ( + m_SDLTextureInfo[channel].texture, SDL_BLENDMODE_BLEND); + } + else + { + SDL_SetRenderTarget (g_renderer, m_SDLTextureInfo[channel].texture); + SDL_SetRenderDrawColor (g_renderer, 0, 0, 0, 0); + SDL_RenderClear (g_renderer); + SDL_SetRenderTarget (g_renderer, nullptr); + } + + m_SDLTextureInfo[channel].texMask = nullptr; + m_SDLTextureInfo[channel].target = true; + m_SDLTextureInfo[channel].dimIcon = Point{0, 0}; + m_SDLTextureInfo[channel].dimTotal = totalDim; + m_SDLTextureInfo[channel].file = ""; + + return true; +} + // Cache une image contenant des ic�nes. bool -- cgit v1.2.3 From f7640e92ce748aff027357dc3b4239284eabdf0a Mon Sep 17 00:00:00 2001 From: Mathieu Schroeter Date: Sun, 15 Oct 2017 11:23:02 +0200 Subject: WIP: add an expanded mode for the backgrounds It's just partially working. --- src/pixmap.cxx | 68 ++++++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 54 insertions(+), 14 deletions(-) (limited to 'src/pixmap.cxx') diff --git a/src/pixmap.cxx b/src/pixmap.cxx index 6382002..a3de686 100644 --- a/src/pixmap.cxx +++ b/src/pixmap.cxx @@ -267,7 +267,8 @@ CPixmap::Cache (size_t channel, Point totalDim) bool CPixmap::Cache ( - size_t channel, const std::string & pFilename, Point totalDim, Point iconDim) + size_t channel, const std::string & pFilename, Point totalDim, Point iconDim, + Mode mode) { std::string file = GetBaseDir () + pFilename; SDL_Surface * surface = IMG_Load (file.c_str ()); @@ -277,8 +278,19 @@ CPixmap::Cache ( SDL_Texture * texture = SDL_CreateTextureFromSurface (g_renderer, surface); Uint32 format; - Sint32 access, w, h; - SDL_QueryTexture (texture, &format, &access, &w, &h); + Sint32 access, ow, w, oh, h; + SDL_QueryTexture (texture, &format, &access, &ow, &oh); + + if (mode == EXPAND || channel == CHBACK) + { + w = LXIMAGE; + h = LYIMAGE; + } + else + { + w = ow; + h = oh; + } if (m_SDLTextureInfo.find (channel) == m_SDLTextureInfo.end ()) { @@ -311,7 +323,43 @@ CPixmap::Cache ( m_SDLTextureInfo[channel].file = pFilename; SDL_SetRenderTarget (g_renderer, m_SDLTextureInfo[channel].texture); - SDL_RenderCopy (g_renderer, texture, nullptr, nullptr); + + switch (mode) + { + case FIX: + { + if (channel == CHBACK) + { + SDL_Rect dst; + dst.x = (LXIMAGE - ow) / 2; + dst.y = 0; + dst.w = ow; + dst.h = oh; + SDL_RenderCopy (g_renderer, texture, nullptr, &dst); + } + else + SDL_RenderCopy (g_renderer, texture, nullptr, nullptr); + break; + } + + case EXPAND: + { + SDL_Rect src, dst; + src.x = 0; + src.y = 0; + src.w = POSDRAWX - 1; + src.h = LYIMAGE; + dst = src; + SDL_RenderCopy (g_renderer, texture, &src, &dst); + src.x = ow - 15; + src.w = 15; + dst.x = LXIMAGE - 15; + dst.w = src.w; + SDL_RenderCopy (g_renderer, texture, &src, &dst); + break; + } + } + SDL_SetRenderTarget (g_renderer, nullptr); if (!m_SDLTextureInfo[channel].texMask) @@ -540,16 +588,8 @@ CPixmap::DrawImage (Sint32 chDst, size_t channel, Rect rect) if (m_SDLTextureInfo.find (channel) == m_SDLTextureInfo.end ()) return false; - if (channel == CHBACK) - { - dst.x = (LXIMAGE - LXLOGIC) / 2; - dst.y = (LYIMAGE - LYLOGIC) / 2; - } - else - { - dst.x = rect.left; - dst.y = rect.top; - } + dst.x = rect.left; + dst.y = rect.top; res = BltFast (chDst, channel, dst, rect); -- cgit v1.2.3 From f65fb90fe531f32d9cea1710c0b6f91d27587899 Mon Sep 17 00:00:00 2001 From: Mathieu Schroeter Date: Sun, 15 Oct 2017 11:23:38 +0200 Subject: Cosmetics --- src/pixmap.cxx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/pixmap.cxx') diff --git a/src/pixmap.cxx b/src/pixmap.cxx index a3de686..c7d2af6 100644 --- a/src/pixmap.cxx +++ b/src/pixmap.cxx @@ -881,13 +881,13 @@ on the endianness (byte order) of the machine */ for (int i = SPRITE_BEGIN; i <= SPRITE_END; ++i) { - MouseSprites sprite = static_cast (i); + MouseSprites sprite = static_cast (i); if (m_lpSDLCursors[sprite - 1]) SDL_FreeCursor (m_lpSDLCursors[sprite - 1]); - SDL_Point hotspot = this->GetCursorHotSpot (sprite); - SDL_Rect rect = this->GetCursorRect (sprite); + SDL_Point hotspot = this->GetCursorHotSpot (sprite); + SDL_Rect rect = this->GetCursorRect (sprite); SDL_Surface * surface = SDL_CreateRGBSurface ( 0, rect.w * scale, rect.h * scale, 32, rmask, gmask, bmask, amask); -- cgit v1.2.3 From 62717b4e1a6077b55fb9b210c8003ce898466bb2 Mon Sep 17 00:00:00 2001 From: Mathieu Schroeter Date: Sun, 15 Oct 2017 22:08:22 +0200 Subject: Finish expand mode for playing backgrounds --- src/pixmap.cxx | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'src/pixmap.cxx') diff --git a/src/pixmap.cxx b/src/pixmap.cxx index c7d2af6..803b8d7 100644 --- a/src/pixmap.cxx +++ b/src/pixmap.cxx @@ -351,11 +351,16 @@ CPixmap::Cache ( src.h = LYIMAGE; dst = src; SDL_RenderCopy (g_renderer, texture, &src, &dst); - src.x = ow - 15; - src.w = 15; - dst.x = LXIMAGE - 15; + src.x = ow - 16; + src.w = 16; + dst.x = LXIMAGE - 16; dst.w = src.w; SDL_RenderCopy (g_renderer, texture, &src, &dst); + src.x = POSDRAWX - 1; + src.w = ow - src.x - 16; + dst.x = src.x; + dst.w = DIMDRAWX + 1; + SDL_RenderCopy (g_renderer, texture, &src, &dst); break; } } -- cgit v1.2.3 From dfe3647a74734d1ae0d36f54b00f03fc7d6d6b99 Mon Sep 17 00:00:00 2001 From: Mathieu Schroeter Date: Sat, 21 Oct 2017 15:30:37 +0200 Subject: Add a BltFast function with src and dst rect --- src/pixmap.cxx | 71 +++++++++++++++++++++++++++++++--------------------------- 1 file changed, 38 insertions(+), 33 deletions(-) (limited to 'src/pixmap.cxx') diff --git a/src/pixmap.cxx b/src/pixmap.cxx index 349f466..64d70be 100644 --- a/src/pixmap.cxx +++ b/src/pixmap.cxx @@ -101,13 +101,44 @@ CPixmap::Create (Point dim) return true; } +Sint32 +CPixmap::BltFast (Sint32 dstCh, size_t srcCh, Rect dstR, Rect srcR) +{ + Sint32 res; + + SDL_Rect srcRect, dstRect; + srcRect.x = srcR.left; + srcRect.y = srcR.top; + srcRect.w = srcR.right - srcR.left; + srcRect.h = srcR.bottom - srcR.top; + dstRect.x = dstR.left; + dstRect.y = dstR.top; + dstRect.w = dstR.right - dstR.left; + dstRect.h = dstR.bottom - dstR.top; + + if (dstCh < 0) + { + res = SDL_RenderCopy ( + g_renderer, m_SDLTextureInfo[srcCh].texture, &srcRect, &dstRect); + } + else + { + SDL_SetRenderTarget (g_renderer, m_SDLTextureInfo[dstCh].texture); + res = SDL_RenderCopy ( + g_renderer, m_SDLTextureInfo[srcCh].texture, &srcRect, &dstRect); + SDL_SetRenderTarget (g_renderer, nullptr); + } + + return res; +} + // Effectue un appel BltFast. // Les modes sont 0=transparent, 1=opaque. Sint32 CPixmap::BltFast (Sint32 chDst, size_t channel, Point dst, Rect rcRect) { - Sint32 res, limit; + Sint32 limit; // Effectue un peu de clipping. if (dst.x < m_clipRect.left) @@ -130,38 +161,12 @@ CPixmap::BltFast (Sint32 chDst, size_t channel, Point dst, Rect rcRect) if (rcRect.left >= rcRect.right || rcRect.top >= rcRect.bottom) return 0; - if (chDst < 0) - { - SDL_Rect srcRect, dstRect; - srcRect.x = rcRect.left; - srcRect.y = rcRect.top; - srcRect.w = rcRect.right - rcRect.left; - srcRect.h = rcRect.bottom - rcRect.top; - dstRect = srcRect; - dstRect.x = dst.x; - dstRect.y = dst.y; - - res = SDL_RenderCopy ( - g_renderer, m_SDLTextureInfo[channel].texture, &srcRect, &dstRect); - } - else - { - SDL_Rect srcRect, dstRect; - srcRect.x = rcRect.left; - srcRect.y = rcRect.top; - srcRect.w = rcRect.right - rcRect.left; - srcRect.h = rcRect.bottom - rcRect.top; - dstRect = srcRect; - dstRect.x = dst.x; - dstRect.y = dst.y; - - SDL_SetRenderTarget (g_renderer, m_SDLTextureInfo[chDst].texture); - res = SDL_RenderCopy ( - g_renderer, m_SDLTextureInfo[channel].texture, &srcRect, &dstRect); - SDL_SetRenderTarget (g_renderer, nullptr); - } - - return res; + Rect dstRect; + dstRect.left = dst.x; + dstRect.top = dst.y; + dstRect.right = dstRect.left + rcRect.right - rcRect.left; + dstRect.bottom = dstRect.top + rcRect.bottom - rcRect.top; + return this->BltFast (chDst, channel, dstRect, rcRect); } // Effectue un appel BltFast. -- cgit v1.2.3 From 108c577b85eb6370b2496cf93569e4565219caea Mon Sep 17 00:00:00 2001 From: Mathieu Schroeter Date: Sat, 21 Oct 2017 15:31:38 +0200 Subject: Use the back-build image as stretched background for wide screen Concerns only screens provided with the map builder. --- src/pixmap.cxx | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'src/pixmap.cxx') diff --git a/src/pixmap.cxx b/src/pixmap.cxx index 64d70be..fe41df9 100644 --- a/src/pixmap.cxx +++ b/src/pixmap.cxx @@ -273,7 +273,7 @@ CPixmap::Cache (size_t channel, Point totalDim) bool CPixmap::Cache ( size_t channel, const std::string & pFilename, Point totalDim, Point iconDim, - Mode mode) + Mode mode, size_t chBackWide) { std::string file = GetBaseDir () + pFilename; SDL_Surface * surface = IMG_Load (file.c_str ()); @@ -335,6 +335,16 @@ CPixmap::Cache ( { if (channel == CHBACK) { + if (chBackWide > 0) + { + Rect srcRect; + srcRect.left = 0; + srcRect.right = LXIMAGE; + srcRect.top = 0; + srcRect.bottom = LYIMAGE; + this->DrawImage (-1, chBackWide, srcRect); + } + SDL_Rect dst; dst.x = (LXIMAGE - ow) / 2; dst.y = 0; -- cgit v1.2.3 From bf7857d61ac127f95ea5e3787263e5fe0ae1ad33 Mon Sep 17 00:00:00 2001 From: Mathieu Schroeter Date: Sat, 21 Oct 2017 15:59:18 +0200 Subject: Use the widescreen background only with widescreens --- src/pixmap.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/pixmap.cxx') diff --git a/src/pixmap.cxx b/src/pixmap.cxx index fe41df9..eb5f902 100644 --- a/src/pixmap.cxx +++ b/src/pixmap.cxx @@ -333,7 +333,7 @@ CPixmap::Cache ( { case FIX: { - if (channel == CHBACK) + if (channel == CHBACK && (ow < LXIMAGE || oh < LYIMAGE)) { if (chBackWide > 0) { -- cgit v1.2.3 From 34869f1736acb578e04c2d2a96d5c326e7b1837f Mon Sep 17 00:00:00 2001 From: Mathieu Schroeter Date: Mon, 11 Jun 2018 18:18:07 +0200 Subject: Fix black backgrounds with opengles2 --- src/pixmap.cxx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/pixmap.cxx') diff --git a/src/pixmap.cxx b/src/pixmap.cxx index d23181c..58a766a 100644 --- a/src/pixmap.cxx +++ b/src/pixmap.cxx @@ -254,8 +254,9 @@ CPixmap::Cache ( return false; } - SDL_SetTextureBlendMode ( - m_SDLTextureInfo[channel].texture, SDL_BLENDMODE_BLEND); + if (channel != CHBACK) + SDL_SetTextureBlendMode ( + m_SDLTextureInfo[channel].texture, SDL_BLENDMODE_BLEND); } SDL_SetRenderTarget (g_renderer, m_SDLTextureInfo[channel].texture); -- cgit v1.2.3 From daf70260de42e98956d4ee3fea3f55b81fdd0fc0 Mon Sep 17 00:00:00 2001 From: Mathieu Schroeter Date: Wed, 13 Jun 2018 23:10:24 +0200 Subject: Pass the event manager to pixmap --- src/pixmap.cxx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/pixmap.cxx') diff --git a/src/pixmap.cxx b/src/pixmap.cxx index 58a766a..fea7c0d 100644 --- a/src/pixmap.cxx +++ b/src/pixmap.cxx @@ -33,6 +33,7 @@ #include "blupi.h" #include "def.h" +#include "event.h" #include "misc.h" #include "pixmap.h" @@ -40,7 +41,7 @@ // Constructeur. -CPixmap::CPixmap () +CPixmap::CPixmap (CEvent * event) { Sint32 i; @@ -56,6 +57,7 @@ CPixmap::CPixmap () m_lpSDLCursors[i] = nullptr; m_lpCurrentCursor = nullptr; + this->event = event; } // Destructeur. -- cgit v1.2.3 From 0289b0224ba4820cf07115aa7b8fb9a4a653d024 Mon Sep 17 00:00:00 2001 From: Mathieu Schroeter Date: Wed, 13 Jun 2018 23:15:23 +0200 Subject: WIP: add handling support for desktop fullscreen mode --- src/pixmap.cxx | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'src/pixmap.cxx') diff --git a/src/pixmap.cxx b/src/pixmap.cxx index fea7c0d..9d1be99 100644 --- a/src/pixmap.cxx +++ b/src/pixmap.cxx @@ -57,6 +57,7 @@ CPixmap::CPixmap (CEvent * event) m_lpSDLCursors[i] = nullptr; m_lpCurrentCursor = nullptr; + this->mainTexture = nullptr; this->event = event; } @@ -85,6 +86,9 @@ CPixmap::~CPixmap () if (m_lpSDLBlupi) SDL_FreeSurface (m_lpSDLBlupi); + + if (this->mainTexture) + SDL_DestroyTexture (this->mainTexture); } // Cr�e l'objet DirectDraw principal. @@ -143,8 +147,24 @@ CPixmap::BltFast (Sint32 chDst, size_t channel, Point dst, Rect rcRect) dstRect.x = dst.x; dstRect.y = dst.y; + if (!this->mainTexture && g_bFullScreen && g_zoom == 1) + { + SDL_SetHint (SDL_HINT_RENDER_SCALE_QUALITY, "best"); + this->mainTexture = SDL_CreateTexture ( + g_renderer, SDL_PIXELFORMAT_RGBA32, SDL_TEXTUREACCESS_TARGET, LXIMAGE, + LYIMAGE); + SDL_SetHint (SDL_HINT_RENDER_SCALE_QUALITY, "nearest"); + } + else if (this->mainTexture && !(g_bFullScreen && g_zoom == 1)) + { + SDL_DestroyTexture (this->mainTexture); + this->mainTexture = nullptr; + } + + SDL_SetRenderTarget (g_renderer, this->mainTexture); res = SDL_RenderCopy ( g_renderer, m_SDLTextureInfo[channel].texture, &srcRect, &dstRect); + SDL_SetRenderTarget (g_renderer, nullptr); } else { @@ -602,6 +622,10 @@ bool CPixmap::Display () { m_bBackDisplayed = true; + + if (this->mainTexture) + SDL_RenderCopy (g_renderer, this->mainTexture, nullptr, nullptr); + SDL_RenderPresent (g_renderer); return true; } -- cgit v1.2.3 From b3c6b536934b92b1d98f16335acb3e43441b0586 Mon Sep 17 00:00:00 2001 From: Mathieu Schroeter Date: Wed, 13 Jun 2018 23:16:59 +0200 Subject: WIP: add impl. of fullscreen desktop It's possible to switch between both mode (fullscreen 640x480 and fullscreen desktop). The zoom option is used for this switch in fullscreen. The textes must be adapted in this case. --- src/pixmap.cxx | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 58 insertions(+), 1 deletion(-) (limited to 'src/pixmap.cxx') diff --git a/src/pixmap.cxx b/src/pixmap.cxx index 9d1be99..6fdef85 100644 --- a/src/pixmap.cxx +++ b/src/pixmap.cxx @@ -796,7 +796,7 @@ CPixmap::GetCursorRect (MouseSprites sprite) } void -CPixmap::LoadCursors (Uint8 scale) +CPixmap::LoadCursors () { Uint32 rmask, gmask, bmask, amask; @@ -814,6 +814,8 @@ on the endianness (byte order) of the machine */ amask = 0xff000000; #endif + auto scale = this->GetDisplayScale (); + for (int i = SPRITE_BEGIN; i <= SPRITE_END; ++i) { MouseSprites sprite = static_cast (i); @@ -844,3 +846,58 @@ CPixmap::ChangeSprite (MouseSprites sprite) SDL_SetCursor (m_lpSDLCursors[sprite - 1]); m_lpCurrentCursor = m_lpSDLCursors[sprite - 1]; } + +double +CPixmap::GetDisplayScale () +{ + // SDL_DisplayMode displayMode; + // SDL_GetWindowDisplayMode (g_window, &displayMode); + Sint32 w, h; + SDL_GetWindowSize (g_window, &w, &h); + return static_cast (h / LYIMAGE); +} + +void +CPixmap::FromDisplayToGame (Sint32 & x, Sint32 & y) +{ + if (this->event->IsDemoPlaying ()) + return; + + SDL_DisplayMode displayMode; + SDL_GetWindowDisplayMode (g_window, &displayMode); + + if ( + static_cast (displayMode.w) / displayMode.h == + static_cast (SCRNUM) / SCRDEN) + return; + + double w = displayMode.w, h = displayMode.h; + double ratio = w * SCRDEN / SCRNUM; + + x = (x - (w - ratio) / 2) / (ratio / LXIMAGE); + y = y / (h / LYIMAGE); +} + +void +CPixmap::FromGameToDisplay (Sint32 & x, Sint32 & y) +{ + Sint32 w, h; + SDL_GetWindowSize (g_window, &w, &h); + + double factor = 1; + + if (!g_bFullScreen) + factor = g_zoom; + + x *= factor; + y *= factor; + + if (static_cast (w) / h == static_cast (SCRNUM) / SCRDEN) + return; + + double _w = w, _h = h; + double ratio = w * SCRDEN / SCRNUM; + + x = x * ratio / LXIMAGE + (_w - ratio) / 2; + y = y * _h / LYIMAGE; +} -- cgit v1.2.3 From 17e9f1e3e4b8928d95c5bd2c6c3ac0ff6968f888 Mon Sep 17 00:00:00 2001 From: Mathieu Schroeter Date: Thu, 14 Jun 2018 23:51:05 +0200 Subject: Fix use of mainTexture with landscape fullscreen --- src/pixmap.cxx | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'src/pixmap.cxx') diff --git a/src/pixmap.cxx b/src/pixmap.cxx index 2bd2aa4..f8fa31f 100644 --- a/src/pixmap.cxx +++ b/src/pixmap.cxx @@ -122,9 +122,10 @@ CPixmap::BltFast (Sint32 dstCh, size_t srcCh, Rect dstR, Rect srcR) dstRect.w = dstR.right - dstR.left; dstRect.h = dstR.bottom - dstR.top; + auto target = SDL_GetRenderTarget (g_renderer); + if (dstCh < 0) { - if (!this->mainTexture && g_bFullScreen && g_zoom == 1) { SDL_SetHint (SDL_HINT_RENDER_SCALE_QUALITY, "best"); @@ -139,17 +140,19 @@ CPixmap::BltFast (Sint32 dstCh, size_t srcCh, Rect dstR, Rect srcR) this->mainTexture = nullptr; } - SDL_SetRenderTarget (g_renderer, this->mainTexture); + if (this->mainTexture) + SDL_SetRenderTarget (g_renderer, target ? target : this->mainTexture); res = SDL_RenderCopy ( g_renderer, m_SDLTextureInfo[srcCh].texture, &srcRect, &dstRect); - SDL_SetRenderTarget (g_renderer, nullptr); + if (this->mainTexture) + SDL_SetRenderTarget (g_renderer, target); } else { SDL_SetRenderTarget (g_renderer, m_SDLTextureInfo[dstCh].texture); res = SDL_RenderCopy ( g_renderer, m_SDLTextureInfo[srcCh].texture, &srcRect, &dstRect); - SDL_SetRenderTarget (g_renderer, nullptr); + SDL_SetRenderTarget (g_renderer, target); } return res; -- cgit v1.2.3 From c2b4bee30f99d87fb4ab5e7d19e4d3eec263bd4f Mon Sep 17 00:00:00 2001 From: Mathieu Schroeter Date: Thu, 14 Jun 2018 23:51:22 +0200 Subject: Ensure to destroy the main texture on reload --- src/pixmap.cxx | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/pixmap.cxx') diff --git a/src/pixmap.cxx b/src/pixmap.cxx index f8fa31f..163db6e 100644 --- a/src/pixmap.cxx +++ b/src/pixmap.cxx @@ -238,6 +238,12 @@ CPixmap::BltFast ( bool CPixmap::ReloadTargetTextures () { + if (this->mainTexture) + { + SDL_DestroyTexture (this->mainTexture); + this->mainTexture = nullptr; + } + for (auto & tex : m_SDLTextureInfo) { if (!tex.second.target) -- cgit v1.2.3 From 3834861c1e46bc2f178cb11474158860c32d727e Mon Sep 17 00:00:00 2001 From: Mathieu Schroeter Date: Mon, 25 Jun 2018 17:43:49 +0200 Subject: Fix mouse wrap in fullscreen (desktop) --- src/pixmap.cxx | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'src/pixmap.cxx') diff --git a/src/pixmap.cxx b/src/pixmap.cxx index 163db6e..606782c 100644 --- a/src/pixmap.cxx +++ b/src/pixmap.cxx @@ -1013,12 +1013,11 @@ CPixmap::FromGameToDisplay (Sint32 & x, Sint32 & y) x *= factor; y *= factor; - if (static_cast (w) / h == static_cast (SCRNUM) / SCRDEN) + if (!g_bFullScreen) return; double _w = w, _h = h; - double ratio = w * SCRDEN / SCRNUM; - x = x * ratio / LXIMAGE + (_w - ratio) / 2; + x = x * _w / LXIMAGE; y = y * _h / LYIMAGE; } -- cgit v1.2.3 From 375388b22f74707a0588de098d847bbf9959344f Mon Sep 17 00:00:00 2001 From: Mathieu Schroeter Date: Mon, 25 Jun 2018 22:17:39 +0200 Subject: Fix mouse position when changing zoom and fullscreen --- src/pixmap.cxx | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'src/pixmap.cxx') diff --git a/src/pixmap.cxx b/src/pixmap.cxx index 606782c..87177b6 100644 --- a/src/pixmap.cxx +++ b/src/pixmap.cxx @@ -979,24 +979,24 @@ CPixmap::GetDisplayScale () } void -CPixmap::FromDisplayToGame (Sint32 & x, Sint32 & y) +CPixmap::FromDisplayToGame (Sint32 & x, Sint32 & y, double prevScale) { if (this->event->IsDemoPlaying ()) return; - SDL_DisplayMode displayMode; - SDL_GetWindowDisplayMode (g_window, &displayMode); + Sint32 w, h; + SDL_GetWindowSize (g_window, &w, &h); - if ( - static_cast (displayMode.w) / displayMode.h == - static_cast (SCRNUM) / SCRDEN) - return; + double factor = 1; - double w = displayMode.w, h = displayMode.h; - double ratio = w * SCRDEN / SCRNUM; + if (!g_bFullScreen) + factor = prevScale; + + x /= factor; + y /= factor; - x = (x - (w - ratio) / 2) / (ratio / LXIMAGE); - y = y / (h / LYIMAGE); + if (!g_bFullScreen) + return; } void -- cgit v1.2.3 From bf31378ffc39eb825d5cccb701c0c3b86ee0793f Mon Sep 17 00:00:00 2001 From: Mathieu Schroeter Date: Tue, 26 Jun 2018 19:11:49 +0200 Subject: Cosmetics --- src/pixmap.cxx | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) (limited to 'src/pixmap.cxx') diff --git a/src/pixmap.cxx b/src/pixmap.cxx index 87177b6..b950340 100644 --- a/src/pixmap.cxx +++ b/src/pixmap.cxx @@ -322,16 +322,9 @@ CPixmap::Cache ( Sint32 access, ow, w, oh, h; SDL_QueryTexture (texture, &format, &access, &ow, &oh); - if (mode == EXPAND || channel == CHBACK) - { - w = LXIMAGE; - h = LYIMAGE; - } - else - { - w = ow; - h = oh; - } + auto m = mode == EXPAND || channel == CHBACK; + w = m ? LXIMAGE : ow; + h = m ? LYIMAGE : oh; if (m_SDLTextureInfo.find (channel) == m_SDLTextureInfo.end ()) { -- cgit v1.2.3 From 93f5389132affcbb7340ef181ff8fe5c244cb9ef Mon Sep 17 00:00:00 2001 From: Mathieu Schroeter Date: Tue, 26 Jun 2018 19:14:55 +0200 Subject: Cosmetics --- src/pixmap.cxx | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'src/pixmap.cxx') diff --git a/src/pixmap.cxx b/src/pixmap.cxx index b950340..7b51528 100644 --- a/src/pixmap.cxx +++ b/src/pixmap.cxx @@ -914,19 +914,20 @@ CPixmap::LoadCursors () { Uint32 rmask, gmask, bmask, amask; -/* SDL interprets each pixel as a 32-bit number, so our masks must depend -on the endianness (byte order) of the machine */ + /* SDL interprets each pixel as a 32-bit number, so our masks must depend + * on the endianness (byte order) of the machine + */ #if SDL_BYTEORDER == SDL_BIG_ENDIAN rmask = 0xff000000; gmask = 0x00ff0000; bmask = 0x0000ff00; amask = 0x000000ff; -#else +#else /* SDL_BYTEORDER == SDL_BIG_ENDIAN */ rmask = 0x000000ff; gmask = 0x0000ff00; bmask = 0x00ff0000; amask = 0xff000000; -#endif +#endif /* SDL_BYTEORDER != SDL_BIG_ENDIAN */ auto scale = this->GetDisplayScale (); -- cgit v1.2.3 From 988962d74a8747751e022e0b478d82ef46b784c8 Mon Sep 17 00:00:00 2001 From: Mathieu Schroeter Date: Wed, 27 Jun 2018 17:31:59 +0200 Subject: Retrieve the right ratio accordingly to the current display It's no longer forced to 16:9. --- src/pixmap.cxx | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'src/pixmap.cxx') diff --git a/src/pixmap.cxx b/src/pixmap.cxx index 7b51528..207a5ac 100644 --- a/src/pixmap.cxx +++ b/src/pixmap.cxx @@ -130,8 +130,8 @@ CPixmap::BltFast (Sint32 dstCh, size_t srcCh, Rect dstR, Rect srcR) { SDL_SetHint (SDL_HINT_RENDER_SCALE_QUALITY, "best"); this->mainTexture = SDL_CreateTexture ( - g_renderer, SDL_PIXELFORMAT_RGBA32, SDL_TEXTUREACCESS_TARGET, LXIMAGE, - LYIMAGE); + g_renderer, SDL_PIXELFORMAT_RGBA32, SDL_TEXTUREACCESS_TARGET, + LXIMAGE (), LYIMAGE ()); SDL_SetHint (SDL_HINT_RENDER_SCALE_QUALITY, "nearest"); } else if (this->mainTexture && !(g_bFullScreen && g_zoom == 1)) @@ -323,8 +323,8 @@ CPixmap::Cache ( SDL_QueryTexture (texture, &format, &access, &ow, &oh); auto m = mode == EXPAND || channel == CHBACK; - w = m ? LXIMAGE : ow; - h = m ? LYIMAGE : oh; + w = m ? LXIMAGE () : ow; + h = m ? LYIMAGE () : oh; if (m_SDLTextureInfo.find (channel) == m_SDLTextureInfo.end ()) { @@ -361,20 +361,20 @@ CPixmap::Cache ( { case FIX: { - if (channel == CHBACK && (ow < LXIMAGE || oh < LYIMAGE)) + if (channel == CHBACK && (ow < LXIMAGE () || oh < LYIMAGE ())) { if (chBackWide > 0) { Rect srcRect; srcRect.left = 0; - srcRect.right = LXIMAGE; + srcRect.right = LXIMAGE (); srcRect.top = 0; - srcRect.bottom = LYIMAGE; + srcRect.bottom = LYIMAGE (); this->DrawImage (-1, chBackWide, srcRect); } SDL_Rect dst; - dst.x = (LXIMAGE - ow) / 2; + dst.x = (LXIMAGE () - ow) / 2; dst.y = 0; dst.w = ow; dst.h = oh; @@ -391,12 +391,12 @@ CPixmap::Cache ( src.x = 0; src.y = 0; src.w = POSDRAWX - 1; - src.h = LYIMAGE; + src.h = LYIMAGE (); dst = src; SDL_RenderCopy (g_renderer, texture, &src, &dst); src.x = ow - 16; src.w = 16; - dst.x = LXIMAGE - 16; + dst.x = LXIMAGE () - 16; dst.w = src.w; SDL_RenderCopy (g_renderer, texture, &src, &dst); src.x = POSDRAWX - 1; @@ -969,7 +969,7 @@ CPixmap::GetDisplayScale () // SDL_GetWindowDisplayMode (g_window, &displayMode); Sint32 w, h; SDL_GetWindowSize (g_window, &w, &h); - return static_cast (h / LYIMAGE); + return static_cast (h / LYIMAGE ()); } void @@ -1012,6 +1012,6 @@ CPixmap::FromGameToDisplay (Sint32 & x, Sint32 & y) double _w = w, _h = h; - x = x * _w / LXIMAGE; - y = y * _h / LYIMAGE; + x = x * _w / LXIMAGE (); + y = y * _h / LYIMAGE (); } -- cgit v1.2.3 From 94996ef4d77359da7483f355f1c177a748c86e25 Mon Sep 17 00:00:00 2001 From: Mathieu Schroeter Date: Wed, 27 Jun 2018 17:32:41 +0200 Subject: Cosmetic: fix format --- src/pixmap.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/pixmap.cxx') diff --git a/src/pixmap.cxx b/src/pixmap.cxx index 207a5ac..2ca13b4 100644 --- a/src/pixmap.cxx +++ b/src/pixmap.cxx @@ -922,7 +922,7 @@ CPixmap::LoadCursors () gmask = 0x00ff0000; bmask = 0x0000ff00; amask = 0x000000ff; -#else /* SDL_BYTEORDER == SDL_BIG_ENDIAN */ +#else /* SDL_BYTEORDER == SDL_BIG_ENDIAN */ rmask = 0x000000ff; gmask = 0x0000ff00; bmask = 0x00ff0000; -- cgit v1.2.3 From e03a539744edeedba288c74fdb6222422b179f60 Mon Sep 17 00:00:00 2001 From: Mathieu Schroeter Date: Wed, 27 Jun 2018 18:17:44 +0200 Subject: Cosmetic: remove dead code --- src/pixmap.cxx | 6 ------ 1 file changed, 6 deletions(-) (limited to 'src/pixmap.cxx') diff --git a/src/pixmap.cxx b/src/pixmap.cxx index 2ca13b4..9c80361 100644 --- a/src/pixmap.cxx +++ b/src/pixmap.cxx @@ -978,9 +978,6 @@ CPixmap::FromDisplayToGame (Sint32 & x, Sint32 & y, double prevScale) if (this->event->IsDemoPlaying ()) return; - Sint32 w, h; - SDL_GetWindowSize (g_window, &w, &h); - double factor = 1; if (!g_bFullScreen) @@ -988,9 +985,6 @@ CPixmap::FromDisplayToGame (Sint32 & x, Sint32 & y, double prevScale) x /= factor; y /= factor; - - if (!g_bFullScreen) - return; } void -- cgit v1.2.3 From 190147015d8f9bf3678041c2991ab00f27d74eb9 Mon Sep 17 00:00:00 2001 From: Mathieu Schroeter Date: Wed, 27 Jun 2018 18:19:38 +0200 Subject: Get size only when necessary --- src/pixmap.cxx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/pixmap.cxx') diff --git a/src/pixmap.cxx b/src/pixmap.cxx index 9c80361..d2ed5c0 100644 --- a/src/pixmap.cxx +++ b/src/pixmap.cxx @@ -990,9 +990,6 @@ CPixmap::FromDisplayToGame (Sint32 & x, Sint32 & y, double prevScale) void CPixmap::FromGameToDisplay (Sint32 & x, Sint32 & y) { - Sint32 w, h; - SDL_GetWindowSize (g_window, &w, &h); - double factor = 1; if (!g_bFullScreen) @@ -1004,6 +1001,9 @@ CPixmap::FromGameToDisplay (Sint32 & x, Sint32 & y) if (!g_bFullScreen) return; + Sint32 w, h; + SDL_GetWindowSize (g_window, &w, &h); + double _w = w, _h = h; x = x * _w / LXIMAGE (); -- cgit v1.2.3 From bc0a7cbc76333b6dfda197fa03a1aa5da8a20ce9 Mon Sep 17 00:00:00 2001 From: Mathieu Schroeter Date: Tue, 17 Jul 2018 18:13:08 +0200 Subject: Do not prepend SDL headers by SDL2/ It's not always the case. --- src/pixmap.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/pixmap.cxx') diff --git a/src/pixmap.cxx b/src/pixmap.cxx index d2ed5c0..a143abc 100644 --- a/src/pixmap.cxx +++ b/src/pixmap.cxx @@ -29,7 +29,7 @@ #include #endif /* !_WIN32 */ -#include +#include #include "blupi.h" #include "def.h" -- cgit v1.2.3 From b321d915d3eeaa8f36ab5834e7b25e1a866249f5 Mon Sep 17 00:00:00 2001 From: Mathieu Schroeter Date: Tue, 24 Jul 2018 23:59:52 +0200 Subject: Add a getter ofr retrieving a texture --- src/pixmap.cxx | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src/pixmap.cxx') diff --git a/src/pixmap.cxx b/src/pixmap.cxx index a143abc..409d29f 100644 --- a/src/pixmap.cxx +++ b/src/pixmap.cxx @@ -455,6 +455,16 @@ CPixmap::Cache (size_t channel, SDL_Surface * surface, Point totalDim) return true; } +SDL_Texture * +CPixmap::getTexture (size_t channel) +{ + auto it = this->m_SDLTextureInfo.find (channel); + if (it == this->m_SDLTextureInfo.end ()) + return nullptr; + + return it->second.texture; +} + // Modifie la r�gion de clipping. void -- cgit v1.2.3 From 39a2cf926bbbcdd1cd013a53459e168db172e9ba Mon Sep 17 00:00:00 2001 From: Mathieu Schroeter Date: Mon, 30 Jul 2018 18:38:41 +0200 Subject: Optimize the wide background stuff by loading only on demand It uses less memory. --- src/pixmap.cxx | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'src/pixmap.cxx') diff --git a/src/pixmap.cxx b/src/pixmap.cxx index 409d29f..69c2ea0 100644 --- a/src/pixmap.cxx +++ b/src/pixmap.cxx @@ -305,7 +305,7 @@ CPixmap::Cache (size_t channel, Point totalDim) bool CPixmap::Cache ( size_t channel, const std::string & pFilename, Point totalDim, Point iconDim, - Mode mode, size_t chBackWide) + Mode mode, std::string wideName) { std::string file = GetBaseDir () + pFilename; SDL_Surface * surface = IMG_Load (file.c_str ()); @@ -363,14 +363,15 @@ CPixmap::Cache ( { if (channel == CHBACK && (ow < LXIMAGE () || oh < LYIMAGE ())) { - if (chBackWide > 0) + if (!wideName.empty ()) { - Rect srcRect; - srcRect.left = 0; - srcRect.right = LXIMAGE (); - srcRect.top = 0; - srcRect.bottom = LYIMAGE (); - this->DrawImage (-1, chBackWide, srcRect); + std::string file = GetBaseDir () + wideName; + SDL_Surface * surface = IMG_Load (file.c_str ()); + SDL_Texture * texture = + SDL_CreateTextureFromSurface (g_renderer, surface); + SDL_FreeSurface (surface); + SDL_RenderCopy (g_renderer, texture, nullptr, nullptr); + SDL_DestroyTexture (texture); } SDL_Rect dst; -- cgit v1.2.3 From 494b7ae6538b698a67ab461f122c16c3229577d2 Mon Sep 17 00:00:00 2001 From: Mathieu Schroeter Date: Tue, 31 Jul 2018 17:31:24 +0200 Subject: Fix texture reload --- src/pixmap.cxx | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src/pixmap.cxx') diff --git a/src/pixmap.cxx b/src/pixmap.cxx index 69c2ea0..0401c6e 100644 --- a/src/pixmap.cxx +++ b/src/pixmap.cxx @@ -256,7 +256,7 @@ CPixmap::ReloadTargetTextures () } else if (!Cache ( tex.first, tex.second.file, tex.second.dimTotal, - tex.second.dimIcon)) + tex.second.dimIcon, Mode::FIX, tex.second.wideName)) return false; } @@ -296,6 +296,7 @@ CPixmap::Cache (size_t channel, Point totalDim) m_SDLTextureInfo[channel].dimIcon = Point{0, 0}; m_SDLTextureInfo[channel].dimTotal = totalDim; m_SDLTextureInfo[channel].file = ""; + m_SDLTextureInfo[channel].wideName = ""; return true; } @@ -354,6 +355,7 @@ CPixmap::Cache ( m_SDLTextureInfo[channel].dimIcon = iconDim; m_SDLTextureInfo[channel].dimTotal = totalDim; m_SDLTextureInfo[channel].file = pFilename; + m_SDLTextureInfo[channel].wideName = wideName; SDL_SetRenderTarget (g_renderer, m_SDLTextureInfo[channel].texture); @@ -365,7 +367,7 @@ CPixmap::Cache ( { if (!wideName.empty ()) { - std::string file = GetBaseDir () + wideName; + std::string file = GetBaseDir () + m_SDLTextureInfo[channel].wideName; SDL_Surface * surface = IMG_Load (file.c_str ()); SDL_Texture * texture = SDL_CreateTextureFromSurface (g_renderer, surface); -- cgit v1.2.3 From d43bbb9784d632136fddb313c2e577d15a502ad2 Mon Sep 17 00:00:00 2001 From: Mathieu Schroeter Date: Fri, 3 Aug 2018 12:20:15 +0200 Subject: Update copyrights where appropriate --- src/pixmap.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/pixmap.cxx') diff --git a/src/pixmap.cxx b/src/pixmap.cxx index 0401c6e..87e99bf 100644 --- a/src/pixmap.cxx +++ b/src/pixmap.cxx @@ -1,7 +1,7 @@ /* * This file is part of the planetblupi source code * Copyright (C) 1997, Daniel Roux & EPSITEC SA - * Copyright (C) 2017, Mathieu Schroeter + * Copyright (C) 2017-2018, Mathieu Schroeter * http://epsitec.ch; http://www.blupi.org; http://github.com/blupi-games * * This program is free software: you can redistribute it and/or modify -- cgit v1.2.3 From 8b7142a084405b7575babcb2a2d914c479171363 Mon Sep 17 00:00:00 2001 From: Mathieu Schroeter Date: Mon, 6 Aug 2018 07:20:23 +0200 Subject: Add the option for chaning the render quality It toggles between 'nearest' (faster) and 'best' (slower but more prettier). It's enabled only when the game runs in fullscreen. The option can be passed by command line argument `--render-quality on`, by settings.json file with a `"renderquality": true` entry or simply with the main settings screen in the game. --- src/pixmap.cxx | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'src/pixmap.cxx') diff --git a/src/pixmap.cxx b/src/pixmap.cxx index 87e99bf..3089d32 100644 --- a/src/pixmap.cxx +++ b/src/pixmap.cxx @@ -107,6 +107,22 @@ CPixmap::Create (Point dim) return true; } +void +CPixmap::CreateMainTexture () +{ + if (!this->mainTexture) + return; + + SDL_DestroyTexture (this->mainTexture); + SDL_SetHint ( + SDL_HINT_RENDER_SCALE_QUALITY, + g_bFullScreen && g_renderQuality ? "best" : "nearest"); + this->mainTexture = SDL_CreateTexture ( + g_renderer, SDL_PIXELFORMAT_RGBA32, SDL_TEXTUREACCESS_TARGET, LXIMAGE (), + LYIMAGE ()); + SDL_SetHint (SDL_HINT_RENDER_SCALE_QUALITY, "nearest"); +} + Sint32 CPixmap::BltFast (Sint32 dstCh, size_t srcCh, Rect dstR, Rect srcR) { @@ -128,7 +144,8 @@ CPixmap::BltFast (Sint32 dstCh, size_t srcCh, Rect dstR, Rect srcR) { if (!this->mainTexture && g_bFullScreen && g_zoom == 1) { - SDL_SetHint (SDL_HINT_RENDER_SCALE_QUALITY, "best"); + SDL_SetHint ( + SDL_HINT_RENDER_SCALE_QUALITY, g_renderQuality ? "best" : "nearest"); this->mainTexture = SDL_CreateTexture ( g_renderer, SDL_PIXELFORMAT_RGBA32, SDL_TEXTUREACCESS_TARGET, LXIMAGE (), LYIMAGE ()); -- cgit v1.2.3 From 4ae17f69a3f9bc98194bd4d5c7635468268bc5a1 Mon Sep 17 00:00:00 2001 From: Mathieu Schroeter Date: Thu, 9 Aug 2018 00:05:55 +0200 Subject: Remove dead code --- src/pixmap.cxx | 2 -- 1 file changed, 2 deletions(-) (limited to 'src/pixmap.cxx') diff --git a/src/pixmap.cxx b/src/pixmap.cxx index 3089d32..0fcf6d2 100644 --- a/src/pixmap.cxx +++ b/src/pixmap.cxx @@ -995,8 +995,6 @@ CPixmap::ChangeSprite (MouseSprites sprite) double CPixmap::GetDisplayScale () { - // SDL_DisplayMode displayMode; - // SDL_GetWindowDisplayMode (g_window, &displayMode); Sint32 w, h; SDL_GetWindowSize (g_window, &w, &h); return static_cast (h / LYIMAGE ()); -- cgit v1.2.3