23#ifndef CORSIX_TH_TH_GFX_SDL_H_
24#define CORSIX_TH_TH_GFX_SDL_H_
119 return static_cast<uint8_t
>((
iColour >> 0) & 0xFF);
128 return static_cast<uint8_t
>((
iColour >> 8) & 0xFF);
137 return static_cast<uint8_t
>((
iColour >> 16) & 0xFF);
146 return static_cast<uint8_t
>((
iColour >> 24) & 0xFF);
153 const std::array<argb_colour, color_count>&
get_argb_data()
const;
166 std::array<argb_colour, color_count> colour_index_to_argb_map{};
197 virtual void store_argb(uint32_t
pixel) = 0;
208 inline void push_pixel(uint32_t
iValue) {
217 throw std::logic_error(
"Attempt to push_pixel past the end of the image");
227 void store_argb(uint32_t
pixel)
override;
230 uint32_t* destination;
238 void store_argb(uint32_t
pixel)
override;
384 const uint32_t*
pPixels)
const;
405 double draw_scale()
const;
407 void destroy_intermediate_textures();
412 std::unique_ptr<scoped_target_texture> zoom_buffer;
414 bool blue_filter_active{
false};
415 cursor* game_cursor{
nullptr};
416 double bitmap_scale_factor{1.0};
417 double global_scale_factor{1.0};
423 std::stack<SDL_Rect> clip_rects;
427 std::vector<SDL_Texture*> intermediate_textures;
429 bool scale_bitmaps{
false};
430 bool supports_target_textures{};
435 bool apply_opengl_clip_fix{};
491 const ::palette* bitmap_palette{
nullptr};
617 int scale_factor = 1);
655 const uint8_t* alt_palette_map;
658 uint32_t sprite_flags;
668 const ::palette*
palette{
nullptr};
674 size_t sprite_count{};
680 void _freeSingleSprite(
size_t iNumber);
735 enum class line_command : uint32_t { move = 0,
line = 1 };
741 line_element(line_command type,
double x,
double y)
742 : type(type), x(x), y(y) {}
745 std::vector<line_element> line_elements;
747 uint8_t red{0}, green{0}, blue{0}, alpha{255};
Definition th_gfx_sdl.h:694
void draw(render_target *pCanvas, int iX, int iY)
Definition th_gfx_sdl.cpp:1637
~cursor()
Definition th_gfx_sdl.cpp:1593
bool create_from_sprite(sprite_sheet *pSheet, size_t iSprite, int iHotspotX=0, int iHotspotY=0)
Definition th_gfx_sdl.cpp:1598
static bool set_position(render_target *pTarget, int iX, int iY)
Definition th_gfx_sdl.cpp:1628
void use(render_target *pTarget)
Definition th_gfx_sdl.cpp:1617
Definition th_gfx_sdl.h:172
virtual ~full_colour_renderer()=default
void decode_image(const uint8_t *pImg, const ::palette *pPalette, uint32_t iSpriteFlags)
Decode a 32bpp image, and push it to the storage backend.
Definition th_gfx_sdl.cpp:260
Definition th_gfx_sdl.h:222
Definition th_gfx_sdl.h:715
line_sequence()
Definition th_gfx_sdl.cpp:1646
void depersist(lua_persist_reader *pReader)
Definition th_gfx_sdl.cpp:1686
void line_to(double fX, double fY)
Definition th_gfx_sdl.cpp:1652
void draw(render_target *pCanvas, int iX, int iY)
Definition th_gfx_sdl.cpp:1665
void set_colour(uint8_t iR, uint8_t iG, uint8_t iB, uint8_t iA=255)
Definition th_gfx_sdl.cpp:1658
void move_to(double fX, double fY)
Definition th_gfx_sdl.cpp:1648
void set_width(double lineWidth)
Definition th_gfx_sdl.cpp:1656
void persist(lua_persist_writer *pWriter) const
Definition th_gfx_sdl.cpp:1669
Interface used for depersisting Lua objects.
Definition persist_lua.h:107
Interface used for persisting Lua objects.
Definition persist_lua.h:44
8bpp palette class.
Definition th_gfx_sdl.h:68
static constexpr uint8_t get_blue(argb_colour iColour)
Get the blue component of a colour.
Definition th_gfx_sdl.h:136
static constexpr uint8_t get_green(argb_colour iColour)
Get the green component of a colour.
Definition th_gfx_sdl.h:127
void set_argb(int iEntry, uint32_t iVal)
Set an entry of the palette.
Definition th_gfx_sdl.h:160
static constexpr uint8_t get_red(argb_colour iColour)
Get the red component of a colour.
Definition th_gfx_sdl.h:118
bool set_entry(int iEntry, uint8_t iR, uint8_t iG, uint8_t iB)
Set an entry of the palette.
Definition th_gfx_sdl.cpp:245
palette()=default
Create an empty palette. All entries are black and fully opaque.
static constexpr uint8_t get_alpha(argb_colour iColour)
Get the opacity component of a colour.
Definition th_gfx_sdl.h:145
const std::array< argb_colour, color_count > & get_argb_data() const
Get the internal palette data for fast (read-only) access.
Definition th_gfx_sdl.cpp:255
static constexpr argb_colour pack_argb(uint8_t iA, uint8_t iR, uint8_t iG, uint8_t iB)
Convert A, R, G, B values to a 32bpp colour.
Definition th_gfx_sdl.h:105
static constexpr int color_count
Number of colours in the palette.
Definition th_gfx_sdl.h:71
Stored image.
Definition th_gfx_sdl.h:440
void load_from_th_file(const uint8_t *pPixelData, size_t iPixelDataLength, int iWidth, render_target *pEventualCanvas, uint32_t spriteFlags)
Load the image from the supplied pixel data.
Definition th_gfx_sdl.cpp:1017
~raw_bitmap()
Definition th_gfx_sdl.cpp:1007
void draw(render_target *pCanvas, int iX, int iY)
Draw the image at a given position at the given canvas.
Definition th_gfx_sdl.cpp:1101
void set_palette(const ::palette *pPalette)
Set the palette of the image.
Definition th_gfx_sdl.cpp:1013
Definition th_gfx_sdl.h:345
virtual ~scoped_buffer()=default
Definition th_gfx_sdl.h:287
~scoped_clip()
Definition th_gfx_sdl.cpp:655
Definition th_gfx_sdl.h:350
scoped_target_texture(scoped_target_texture &)=delete
scoped_target_texture & operator=(scoped_target_texture &)=delete
~scoped_target_texture() override
Definition th_gfx_sdl.cpp:415
void offset(SDL_FRect &targetRect) const
Definition th_gfx_sdl.cpp:404
double scale_factor() const
Definition th_gfx_sdl.cpp:409
bool is_target() const
Definition th_gfx_sdl.cpp:413
Definition th_gfx_sdl.h:247
const char * get_renderer_details() const
Get any user-displayable information to describe the renderer path used.
Definition th_gfx_sdl.cpp:574
void set_caption(const char *sCaption)
Set the window caption.
Definition th_gfx_sdl.cpp:570
render_target(const render_target &other)=delete
const char * get_last_error()
Get the reason for the last operation failing.
Definition th_gfx_sdl.cpp:580
void draw(SDL_Texture *pTexture, const SDL_Rect *prcSrcRect, const SDL_Rect *prcDstRect, int iFlags)
Definition th_gfx_sdl.cpp:934
bool fill_colour(uint32_t colour)
Paint the entire render target with a solid colour.
Definition th_gfx_sdl.cpp:616
bool update(const render_target_creation_params ¶ms)
Update the parameters for the render target.
Definition th_gfx_sdl.cpp:489
bool set_scale_factor(double fScale, scaled_items eWhatToScale)
Set the amount by which future draw operations are scaled.
Definition th_gfx_sdl.cpp:521
SDL_Renderer * get_renderer() const
Definition th_gfx_sdl.h:369
SDL_Texture * create_palettized_texture(int iWidth, int iHeight, const uint8_t *pPixels, const ::palette *pPalette, uint32_t iSpriteFlags) const
Definition th_gfx_sdl.cpp:882
bool fill_rect(uint32_t iColour, int iX, int iY, int iW, int iH)
Fill a rectangle of the render target with a solid colour.
Definition th_gfx_sdl.cpp:634
~render_target()
Definition th_gfx_sdl.cpp:469
int get_height() const
Get the height of the render target (in pixels)
Definition th_gfx_sdl.cpp:701
int set_minimum_size(int width, int height)
Sets a minimum size for the render target.
bool start_frame()
Begin rendering a new frame.
Definition th_gfx_sdl.cpp:582
SDL_Texture * create_texture(int iWidth, int iHeight, const uint32_t *pPixels) const
Definition th_gfx_sdl.cpp:899
bool end_frame()
Finish rendering the current frame and present it.
Definition th_gfx_sdl.cpp:590
bool should_scale_bitmaps(double *pFactor)
Should bitmaps be scaled?
Definition th_gfx_sdl.cpp:837
static constexpr uint32_t map_colour(uint8_t iR, uint8_t iG, uint8_t iB)
Encode an RGB triplet for fillRect()
Definition th_gfx_sdl.h:255
int get_width() const
Get the width of the render target (in pixels)
Definition th_gfx_sdl.cpp:695
render_target & operator=(const render_target &other)=delete
void set_cursor_position(int iX, int iY)
Update the cursor position (if the cursor is being simulated)
Definition th_gfx_sdl.cpp:717
void pop_clip_rect()
Restore the previous clip rectangle.
Definition th_gfx_sdl.cpp:686
void push_clip_rect(const clip_rect *pRect)
Push a new clip rectangle.
Definition th_gfx_sdl.cpp:657
bool fill_black()
Paint the entire render target black.
Definition th_gfx_sdl.cpp:609
void start_nonoverlapping_draws()
Enable optimisations for non-overlapping draws.
Definition th_gfx_sdl.cpp:707
void set_blue_filter_active(bool bActivate)
Sets a blue filter on the current surface.
Definition th_gfx_sdl.cpp:625
std::unique_ptr< scoped_buffer > begin_intermediate_drawing(int iX, int iY, int iWidth, int iHeight)
Definition th_gfx_sdl.cpp:986
void draw_line(line_sequence *pLine, int iX, int iY)
Definition th_gfx_sdl.cpp:961
void finish_nonoverlapping_draws()
Disable optimisations for non-overlapping draws.
Definition th_gfx_sdl.cpp:711
void set_window_grab(bool bActivate)
Toggle mouse capture on the window.
Definition th_gfx_sdl.cpp:630
friend class scoped_target_texture
Definition th_gfx_sdl.h:403
bool take_screenshot(const char *file_path) const
Take a screenshot and save it as a PNG file.
Definition th_gfx_sdl.cpp:800
void set_cursor(cursor *pCursor)
Set the cursor to be used.
Definition th_gfx_sdl.cpp:715
Sheet of sprites.
Definition th_gfx_sdl.h:504
bool hit_test_sprite(size_t iSprite, int iX, int iY, uint32_t iFlags) const
Test whether a sprite was hit.
Definition th_gfx_sdl.cpp:1577
bool set_sprite_data(size_t iSprite, const uint8_t *pData, bool bTakeData, size_t iDataLength, int iWidth, int iHeight)
Set the data of a sprite.
Definition th_gfx_sdl.cpp:1242
bool get_sprite_size(size_t iSprite, int *pWidth, int *pHeight) const
Get size of a sprite.
Definition th_gfx_sdl.cpp:1287
bool get_sprite_average_colour(size_t iSprite, argb_colour *pColour) const
Get the best colour to represent the sprite.
Definition th_gfx_sdl.cpp:1301
bool load_from_th_file(const uint8_t *pTableData, size_t iTableDataLength, const uint8_t *pChunkData, size_t iChunkDataLength, bool bComplexChunks, render_target *pEventualCanvas)
Definition th_gfx_sdl.cpp:1201
void set_sprite_alt_palette_map(size_t iSprite, const uint8_t *pMap, uint32_t iAlt32)
Supply a new mapped palette to a sprite.
Definition th_gfx_sdl.cpp:1269
~sprite_sheet()
Definition th_gfx_sdl.cpp:1121
bool is_sprite_visible(size_t iSprite) const
Return whether the given sprite show any pixel when displayed.
Definition th_gfx_sdl.cpp:1344
void draw_sprite(render_target *pCanvas, size_t iSprite, int iX, int iY, uint32_t iFlags, size_t effect_ticks=0u, animation_effect effect=animation_effect::none, int scale_factor=1)
Draw a sprite onto the canvas.
Definition th_gfx_sdl.cpp:1356
void get_sprite_size_unchecked(size_t iSprite, int *pWidth, int *pHeight) const
Get size of a sprite, assuming all input is correctly supplied.
Definition th_gfx_sdl.cpp:1295
bool set_sprite_count(size_t iCount, render_target *pCanvas)
Set the number of sprites in the sheet.
Definition th_gfx_sdl.cpp:1152
void set_palette(const ::palette *pPalette)
Set the palette to use for the sprites in the sheet.
Definition th_gfx_sdl.cpp:1148
void wx_draw_sprite(size_t iSprite, uint8_t *pRGBData, uint8_t *pAData)
Draw a sprite into wxImage data arrays (for the Map Editor)
Definition th_gfx_sdl.cpp:1439
size_t get_sprite_count() const
Get the number of sprites at the sheet.
Definition th_gfx_sdl.cpp:1285
Definition th_gfx_sdl.h:233
Definition th_gfx_sdl.h:43
Uint16 w_h_type
Definition th_gfx_sdl.h:45
Sint16 x_y_type
Definition th_gfx_sdl.h:44
Definition th_gfx_sdl.h:49
int bpp
Expected colour depth of the render target.
Definition th_gfx_sdl.h:52
int width
Expected width of the render target.
Definition th_gfx_sdl.h:50
int min_width
Minimum width of the render target.
Definition th_gfx_sdl.h:58
bool direct_zoom
Definition th_gfx_sdl.h:56
bool fullscreen
Run full-screen.
Definition th_gfx_sdl.h:53
bool present_immediate
Definition th_gfx_sdl.h:54
int height
Expected height of the render target.
Definition th_gfx_sdl.h:51
int min_height
Minimum height of the render target.
Definition th_gfx_sdl.h:59
scaled_items
Definition th_gfx.h:45
animation_effect
Animation Effect for drawing a sprite with a special effect applied.
Definition th_gfx_common.h:30
#define SDL_FRect
Definition th_gfx_sdl.cpp:61
uint32_t argb_colour
32bpp ARGB colour. See palette::pack_argb
Definition th_gfx_sdl.h:65