-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e55c3fc
commit 6f0192f
Showing
10 changed files
with
231 additions
and
176 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
#if defined(TILES) | ||
#include "sdl_geometry.h" | ||
#include "debug.h" | ||
|
||
void GeometryRenderer::horizontal_line( const SDL_Renderer_Ptr &renderer, const point &pos, int x2, | ||
int thickness, const SDL_Color &color ) const | ||
{ | ||
SDL_Rect rect { pos.x, pos.y, x2 - pos.x, thickness }; | ||
this->rect( renderer, rect, color ); | ||
} | ||
|
||
void GeometryRenderer::vertical_line( const SDL_Renderer_Ptr &renderer, const point &pos, int y2, | ||
int thickness, const SDL_Color &color ) const | ||
{ | ||
SDL_Rect rect { pos.x, pos.y, thickness, y2 - pos.y }; | ||
this->rect( renderer, rect, color ); | ||
} | ||
|
||
void GeometryRenderer::rect( const SDL_Renderer_Ptr &renderer, const point &pos, int width, | ||
int height, const SDL_Color &color ) const | ||
{ | ||
SDL_Rect rect { pos.x, pos.y, width, height }; | ||
this->rect( renderer, rect, color ); | ||
} | ||
|
||
|
||
void DefaultGeometryRenderer::rect( const SDL_Renderer_Ptr &renderer, const SDL_Rect &rect, | ||
const SDL_Color &color ) const | ||
{ | ||
SetRenderDrawColor( renderer, color.r, color.g, color.b, color.a ); | ||
RenderFillRect( renderer, &rect ); | ||
} | ||
|
||
ColorModulatedGeometryRenderer::ColorModulatedGeometryRenderer( const SDL_Renderer_Ptr &renderer ) | ||
{ | ||
#if SDL_BYTEORDER == SDL_BIG_ENDIAN | ||
static const Uint32 rmask = 0xff000000; | ||
static const Uint32 gmask = 0x00ff0000; | ||
static const Uint32 bmask = 0x0000ff00; | ||
static const Uint32 amask = 0x000000ff; | ||
#else | ||
static const Uint32 rmask = 0x000000ff; | ||
static const Uint32 gmask = 0x0000ff00; | ||
static const Uint32 bmask = 0x00ff0000; | ||
static const Uint32 amask = 0xff000000; | ||
#endif | ||
SDL_Surface_Ptr alt_surf( SDL_CreateRGBSurface( 0, 1, 1, 32, rmask, gmask, bmask, amask ) ); | ||
if( alt_surf ) { | ||
FillRect( alt_surf, nullptr, SDL_MapRGB( alt_surf->format, 255, 255, 255 ) ); | ||
|
||
tex.reset( SDL_CreateTextureFromSurface( renderer.get(), alt_surf.get() ) ); | ||
alt_surf.reset(); | ||
|
||
// Test to make sure color modulation is supported by renderer | ||
bool tex_enable = !SetTextureColorMod( tex, 0, 0, 0 ); | ||
if( !tex_enable ) { | ||
tex.reset(); | ||
} | ||
DebugLog( D_INFO, DC_ALL ) << "ColorModulatedGeometryRenderer constructor() = " << | ||
( tex_enable ? "FAIL" : "SUCCESS" ) << ". tex_enable = " << tex_enable; | ||
} else { | ||
DebugLog( D_ERROR, DC_ALL ) << "CreateRGBSurface failed: " << SDL_GetError(); | ||
} | ||
} | ||
|
||
void ColorModulatedGeometryRenderer::rect( const SDL_Renderer_Ptr &renderer, const SDL_Rect &rect, | ||
const SDL_Color &color ) const | ||
{ | ||
if( tex ) { | ||
SetTextureColorMod( tex, color.r, color.g, color.b ); | ||
RenderCopy( renderer, tex, nullptr, &rect ); | ||
} else { | ||
DefaultGeometryRenderer::rect( renderer, rect, color ); | ||
} | ||
} | ||
|
||
#endif // TILES |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
#pragma once | ||
#ifndef CATA_SRC_SDL_GEOMETRY_H | ||
#define CATA_SRC_SDL_GEOMETRY_H | ||
|
||
#if defined(TILES) | ||
#include <memory> | ||
|
||
#include "sdl_wrappers.h" | ||
#include "point.h" | ||
|
||
/// Interface to render geometry with SDL_Renderer. | ||
class GeometryRenderer | ||
{ | ||
public: | ||
virtual ~GeometryRenderer() = default; | ||
|
||
/// Renders a SDL rectangle with given color. | ||
virtual void rect( const SDL_Renderer_Ptr &renderer, const SDL_Rect &rect, | ||
const SDL_Color &color ) const = 0; | ||
|
||
/// Renders a point+width+height defined rectangle with given color. | ||
void rect( const SDL_Renderer_Ptr &renderer, const point &pos, int width, int height, | ||
const SDL_Color &color ) const; | ||
|
||
/// Renders a straight horizontal line with given thickness and color. | ||
void horizontal_line( const SDL_Renderer_Ptr &renderer, const point &pos, int x2, int thickness, | ||
const SDL_Color &color ) const; | ||
|
||
/// Renders a straight vertical line with given thickness and color. | ||
void vertical_line( const SDL_Renderer_Ptr &renderer, const point &pos, int y2, int thickness, | ||
const SDL_Color &color ) const; | ||
}; | ||
using GeometryRenderer_Ptr = std::unique_ptr<GeometryRenderer>; | ||
|
||
/// Implementation of a GeometryRenderer using default RenderFillRect. | ||
class DefaultGeometryRenderer : public GeometryRenderer | ||
{ | ||
public: | ||
void rect( const SDL_Renderer_Ptr &renderer, const SDL_Rect &rect, | ||
const SDL_Color &color ) const override; | ||
}; | ||
|
||
/// Implementation of a GeometryRenderer using color modulated textures if | ||
/// possible, falling back to DefaultGeometryRenderer otherwise. | ||
class ColorModulatedGeometryRenderer: public DefaultGeometryRenderer | ||
{ | ||
public: | ||
ColorModulatedGeometryRenderer( const SDL_Renderer_Ptr &renderer ); | ||
|
||
void rect( const SDL_Renderer_Ptr &renderer, const SDL_Rect &rect, | ||
const SDL_Color &color ) const override; | ||
private: | ||
SDL_Texture_Ptr tex; | ||
}; | ||
|
||
#endif // TILES | ||
|
||
#endif // CATA_SRC_SDL_GEOMETRY_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.