Skip to content

Commit

Permalink
Begin work to use SDL_ttf
Browse files Browse the repository at this point in the history
  • Loading branch information
Skywalker13 committed Jul 8, 2022
1 parent 0631474 commit f1bff6a
Show file tree
Hide file tree
Showing 6 changed files with 390 additions and 137 deletions.
3 changes: 3 additions & 0 deletions src/blupi.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
#include "platform.h"
#include "progress.h"
#include "sound.h"
#include "text.h"

// Global variables

Expand Down Expand Up @@ -807,6 +808,8 @@ DoInit (int argc, char * argv[], bool & exit)
return EXIT_FAILURE;
}

FontsInit();

if (!(g_settingsOverload & SETTING_LEGACY))
Display::getDisplay ().readDisplaySize ();

Expand Down
3 changes: 2 additions & 1 deletion src/event.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ class CEvent

static void PushUserEvent (Sint32 code, void * data = nullptr);

Language GetLanguage ();

protected:
void DrawTextCenter (const char * text, Sint32 x, Sint32 y, Sint32 font = 0);
bool CreateButtons (Sint32 phase);
Expand All @@ -170,7 +172,6 @@ class CEvent
bool PlayUp (Point pos);

Language GetStartLanguage ();
Language GetLanguage ();
void SetLanguage (Language lang = Language::undef);
void SetWindowSize (double prevScale, double newScale);

Expand Down
44 changes: 44 additions & 0 deletions src/pixmap.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,50 @@ CPixmap::CreateMainTexture ()
SDL_SetHint (SDL_HINT_RENDER_SCALE_QUALITY, "nearest");
}

Sint32
CPixmap::Blit (
Sint32 dstCh, SDL_Texture * src, const SDL_Rect & dstRect, double angle, SDL_RendererFlip flip)
{
Sint32 res;
auto target = SDL_GetRenderTarget (g_renderer);

if (dstCh < 0)
{
if (!this->mainTexture && g_bFullScreen && g_zoom == 1)
{
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 ());
SDL_SetHint (SDL_HINT_RENDER_SCALE_QUALITY, "nearest");
}
else if (this->mainTexture && !(g_bFullScreen && g_zoom == 1))
{
SDL_DestroyTexture (this->mainTexture);
this->mainTexture = nullptr;
}

if (this->mainTexture)
SDL_SetRenderTarget (g_renderer, target ? target : this->mainTexture);
res = SDL_RenderCopyEx (
g_renderer, src, nullptr, &dstRect, angle,
nullptr, flip);
if (this->mainTexture)
SDL_SetRenderTarget (g_renderer, target);
}
else
{
SDL_SetRenderTarget (g_renderer, m_SDLTextureInfo[dstCh].texture);
res = SDL_RenderCopyEx (
g_renderer, src, nullptr, &dstRect, angle,
nullptr, flip);
SDL_SetRenderTarget (g_renderer, target);
}

return res;
}

Sint32
CPixmap::BltFast (
Sint32 dstCh, size_t srcCh, Rect dstR, Rect srcR, SDL_RendererFlip flip)
Expand Down
4 changes: 4 additions & 0 deletions src/pixmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ class CPixmap
void FromDisplayToGame (Sint32 & x, Sint32 & y, double prevScale = 1);
void FromGameToDisplay (Sint32 & x, Sint32 & y);

Sint32 Blit (
Sint32 dstCh, SDL_Texture * src, const SDL_Rect & dstRect, double angle, SDL_RendererFlip flip);
protected:
Sint32 BltFast (
Sint32 dstCh, size_t srcCh, Rect dstR, Rect srcR,
Expand Down Expand Up @@ -134,6 +136,8 @@ class CPixmap
SDL_Cursor * m_lpCurrentCursor;
SDL_Cursor * m_lpSDLCursors[MAXCURSORS];
SDL_Surface * m_lpSDLBlupi;
public:
SDL_Texture * mainTexture;
protected:
std::unordered_map<size_t, TextureInfo> m_SDLTextureInfo;
};
Loading

0 comments on commit f1bff6a

Please sign in to comment.