kobodl/graphics/sofont.h
Ville Lindholm 762b095462
WIP: delete glSDL shim, replace with sdl_compat.h
Step 1+2 of the SDL 3 migration. The 2300-line graphics/glSDL.{c,h}
OpenGL-on-top-of-SDL-1.2 shim is obsolete under SDL 3 (SDL_Renderer
does what glSDL did natively), and its #define overrides of SDL
surface APIs collided directly with SDL 3's SDL_oldnames.h.

- Add graphics/sdl_compat.h: a one-line umbrella that just pulls in
  <SDL3/SDL.h>.
- Replace every #include "glSDL.h" with #include "sdl_compat.h" (15
  files across the tree).
- Delete graphics/glSDL.c, graphics/glSDL.h.
- Drop glSDL.c from graphics/CMakeLists.txt.
- Remove GFX_DRIVER_GLSDL from the gfx_drivers_t enum and from all
  switches/conditions in gfxengine.cpp.
- Drop the glSDL_VSync() call site (will be re-introduced as
  SDL_SetRenderVSync once gfxengine is ported to SDL_Renderer).
- Drop the two glSDL_Invalidate() calls in window.cpp (texture
  re-upload hints with no equivalent in a pure-surface compositor).
- options.cpp: remove the now-empty "OpenGL/glSDL" menu item; force
  videodriver to GFX_DRIVER_SDL2D.
- prefs.cpp: collapse legacy GLSDL setting onto SDL2D on load.

After this commit the macro-collision wall is gone (renamed_-token
errors drop from many to zero). The build still fails on the next
layer of work: SDL 1.2 surface APIs that no longer exist
(SDL_FreeSurface, SDL_SetAlpha, SDL_CreateRGBSurface, SDL_DisplayFormat,
SDL_PixelFormat struct member access, SDL audio callback API, etc.).

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2026-05-28 21:37:01 +03:00

104 lines
3.5 KiB
C++
Raw Permalink Blame History

/*
SoFont - SDL Object Font Library
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Originally from C Library:
Karl Bartel
* SFONT - SDL Font Library by Karl Bartel <karlb@gmx.net> *
* *
* All functions are explained below. There are two versions of each *
* funtction. The first is the normal one, the function with the *
* 2 at the end can be used when you want to handle more than one font *
* in your program. *
* *
Copied into a C++ object to allow multiple fonts by:
Luc-Olivier de Charriere
David Olofson <david@olofson.net>:
* Strings changed to 'const char *'
* Cursor tests first check if '|' is present.
* Shadowed variables fixed.
* Garbage data in spacing table fixed. (Thanks to
Andreas Sp<53>ngberg for discovering this one!)
* Added ExtraSpace(). (Scaling support hack...)
* Disabled colorkeying. (Ruins some RGBA fonts!)
*/
#ifndef __SOFONT_H
#define __SOFONT_H
#include "sdl_compat.h"
class SoFont
{
public:
SoFont();
~SoFont();
bool load(SDL_Surface *FontSurface);
// Blits a string to a surface
// Destination: the suface you want to blit to
// text: a string containing the text you want to blit.
void PutString(SDL_Surface *Surface, int x, int y, const char *text, SDL_Rect *clip=NULL);
void PutStringWithCursor(SDL_Surface *Surface, int x, int y, const char *text, int cursPos, SDL_Rect *clip=NULL, bool showCurs=true);
// Returns the width of "text" in pixels
int TextWidth(const char *text, int min=0, int max=255);
int FontHeight() { return height; }
// Blits a string to with centered x position
void XCenteredString(SDL_Surface *Surface, int y, const char *text, SDL_Rect* clip=NULL);
// Blits a string to with centered x & y position
void CenteredString(SDL_Surface *Surface, const char *text, SDL_Rect* clip=NULL);
// Blits a string to with centered around x & y positions
void CenteredString(SDL_Surface *Surface, int x, int y, const char *text, SDL_Rect* clip=NULL);
// This was specially developped for GUI
void PutStringCleverCursor(SDL_Surface *Surface, const char *text, int cursPos, SDL_Rect *r, SDL_Rect* clip=NULL, bool showCurs=true);
// Gives the cursor position given a x-axix point in the text
int TextCursorAt(const char *text, int px);
int CleverTextCursorAt(const char *text, int px, int cursPos, SDL_Rect *r);
# define START_CHAR 33
int getMinChar(){return START_CHAR;}
int getMaxChar(){return max_i;}
void ExtraSpace(int xs)
{
xspace = xs;
}
protected:
int height;
SDL_Surface *picture;
int *CharPos;
int *CharOffset;
int *Spacing;
int xspace;
int max_i, spacew, cursShift;
Uint32 background;
bool DoStartNewChar(Sint32 x);
void CleanSurface();
};
#endif