change sfw namespace to sb

This commit is contained in:
frank 2021-09-02 18:23:48 -04:00
parent c8bc86cab7
commit ada139c26f
13 changed files with 73 additions and 73 deletions

View File

@ -159,7 +159,7 @@ void CollisionTest::update()
} }
screen_subsection_pixels.apply(); screen_subsection_pixels.apply();
SDL_SetRenderTarget(get_renderer(), nullptr); SDL_SetRenderTarget(get_renderer(), nullptr);
Box canvas_box = sfw::get_texture_box(canvas); Box canvas_box = sb::get_texture_box(canvas);
canvas_box.nw({340, 200}); canvas_box.nw({340, 200});
SDL_RenderCopyF(get_renderer(), canvas, nullptr, &canvas_box); SDL_RenderCopyF(get_renderer(), canvas, nullptr, &canvas_box);
} }

View File

@ -208,7 +208,7 @@ void Cube::load_gl_context()
SDL_Log("tile.png bytes per pixel %i", surface->format->BytesPerPixel); SDL_Log("tile.png bytes per pixel %i", surface->format->BytesPerPixel);
space_texture_id = get_gl_texture_from_surface(surface, GL_LINEAR, true); space_texture_id = get_gl_texture_from_surface(surface, GL_LINEAR, true);
SDL_FreeSurface(surface); SDL_FreeSurface(surface);
// std::vector<fs::path> paths = sfw::glob("/home/frank/projects/public/games/buddi/local/face03/[0-9]+\\-.+\\.png"); // std::vector<fs::path> paths = sb::glob("/home/frank/projects/public/games/buddi/local/face03/[0-9]+\\-.+\\.png");
// for (fs::path path : paths) // for (fs::path path : paths)
// { // {
// surface = zoomSurface(rotateSurface90Degrees(IMG_Load(path.c_str()), 2), -1, 1, SMOOTHING_OFF); // surface = zoomSurface(rotateSurface90Degrees(IMG_Load(path.c_str()), 2), -1, 1, SMOOTHING_OFF);

View File

@ -10,7 +10,7 @@
# #
# [ Makefile for squircle demo ] # [ Makefile for squircle demo ]
# #
# This should build the squircle for Linux. Compilation to other platforms hasn't been # This should build the squircle demo for Linux. Compilation to other platforms hasn't been
# attempted yet. # attempted yet.
# #
# Edit the parameters as necessary and run `make linux` in the current directory. # Edit the parameters as necessary and run `make linux` in the current directory.
@ -20,7 +20,7 @@
# Location parameters # # Location parameters #
####################### #######################
# Location of source files for the demo # Location of project specific source files
SRC_DIR := ./ SRC_DIR := ./
# Locations of [SPACE BOX] source and dependencies required to be compiled from source. These # Locations of [SPACE BOX] source and dependencies required to be compiled from source. These
@ -54,9 +54,9 @@ SB_O_FILES := $(filter-out $(addprefix $(SB_SRC_DIR),filesystem.o),$(SB_H_FILES:
SRC_H_FILES := $(wildcard $(addprefix $(SRC_DIR),*.hpp)) SRC_H_FILES := $(wildcard $(addprefix $(SRC_DIR),*.hpp))
SRC_O_FILES := $(SRC_H_FILES:.hpp=.o) SRC_O_FILES := $(SRC_H_FILES:.hpp=.o)
################################################################## #####################################################################
# Targets for building [SPACE BOX], dependencies and demo source # # Targets for building [SPACE BOX], dependencies and project source #
################################################################## #####################################################################
$(SDLGFX2_DIR)%.o: $(SDLGFX2_DIR)%.c $(SDLGFX2_DIR)%.h $(SDLGFX2_DIR)%.o: $(SDLGFX2_DIR)%.c $(SDLGFX2_DIR)%.h
$(GLEW_DIR)%.o: $(GLEW_DIR)%.c $(GLEW_DIR)%.h $(GLEW_DIR)%.o: $(GLEW_DIR)%.c $(GLEW_DIR)%.h

View File

@ -41,7 +41,7 @@ void Squircle::load_gl_context()
{-1.0f, 1.0f}, {1.0f, 1.0f}, {-1.0f, -1.0f}, {-1.0f, 1.0f}, {1.0f, 1.0f}, {-1.0f, -1.0f},
{1.0f, 1.0f}, {1.0f, -1.0f}, {-1.0f, -1.0f} {1.0f, 1.0f}, {1.0f, -1.0f}, {-1.0f, -1.0f}
}}; }};
std::vector<glm::vec2> circle_vertices = sfw::points_on_circle(get_configuration()["circle-resolution"]); std::vector<glm::vec2> circle_vertices = sb::points_on_circle(get_configuration()["circle-resolution"]);
circle_vertices.insert(circle_vertices.begin(), {0.0f, 0.0f}); circle_vertices.insert(circle_vertices.begin(), {0.0f, 0.0f});
circle_vertices.insert(circle_vertices.end(), circle_vertices[1]); circle_vertices.insert(circle_vertices.end(), circle_vertices[1]);
circle_vertices_count = circle_vertices.size(); circle_vertices_count = circle_vertices.size();
@ -103,7 +103,7 @@ GLuint Squircle::load_file_into_texture(fs::path path) const
void Squircle::load_image_index(int index) void Squircle::load_image_index(int index)
{ {
std::vector<fs::path> paths = sfw::glob("images/.*"); std::vector<fs::path> paths = sb::glob("images/.*");
fs::path path = paths[index % paths.size()]; fs::path path = paths[index % paths.size()];
std::ostringstream message; std::ostringstream message;
message << "loading " << path; message << "loading " << path;

View File

@ -69,7 +69,7 @@ struct Audio : Node
SDL_Log("looking for audio files in %s", root.c_str()); SDL_Log("looking for audio files in %s", root.c_str());
if (fs::exists(root)) if (fs::exists(root))
{ {
for (const fs::path& path : sfw::glob(root / ".*")) for (const fs::path& path : sb::glob(root / ".*"))
{ {
std::regex pattern("([^.]+).*$"); std::regex pattern("([^.]+).*$");
std::smatch match; std::smatch match;

View File

@ -16,7 +16,7 @@ void FramerateIndicator::respond(SDL_Event& event)
SDL_Surface* FramerateIndicator::get_surface() SDL_Surface* FramerateIndicator::get_surface()
{ {
std::string padded = sfw::pad(get_root()->frame_count_this_second, 2); std::string padded = sb::pad(get_root()->frame_count_this_second, 2);
SDL_Surface* shaded = TTF_RenderText_Shaded( SDL_Surface* shaded = TTF_RenderText_Shaded(
get_root()->bp_mono_font, padded.c_str(), {0, 0, 0, 255}, {255, 255, 255, 255}); get_root()->bp_mono_font, padded.c_str(), {0, 0, 0, 255}, {255, 255, 255, 255});
if (!shaded) if (!shaded)
@ -286,12 +286,12 @@ void Game::sdl_log_override(void* userdata, int category, SDL_LogPriority priori
void Game::print_error(const std::string& message) void Game::print_error(const std::string& message)
{ {
sfw::print_error(message); sb::print_error(message);
} }
void Game::print_sdl_error(const std::string& message) void Game::print_sdl_error(const std::string& message)
{ {
sfw::print_sdl_error(message); sb::print_sdl_error(message);
} }
void Game::print_frame_length_history() void Game::print_frame_length_history()
@ -309,7 +309,7 @@ GLuint Game::load_shader(const fs::path& path, GLenum type) const
GLuint shader = glCreateShader(type); GLuint shader = glCreateShader(type);
std::fstream file = std::fstream(path); std::fstream file = std::fstream(path);
std::ostringstream message; std::ostringstream message;
std::string contents = sfw::file_to_string(path); std::string contents = sb::file_to_string(path);
glShaderSource(shader, 1, reinterpret_cast<const GLchar**>(&contents), 0); glShaderSource(shader, 1, reinterpret_cast<const GLchar**>(&contents), 0);
// glShaderSource(shader, 1, const_cast<const GLchar**>(&buf), 0); // glShaderSource(shader, 1, const_cast<const GLchar**>(&buf), 0);
glCompileShader(shader); glCompileShader(shader);

View File

@ -98,8 +98,8 @@ void Input::respond(SDL_Event &event)
(!combination.alt || alt)) (!combination.alt || alt))
{ {
post_command(combination.command, cancel); post_command(combination.command, cancel);
if (!sfw::is_in_container(system_any_key_ignore, combination.command) && !found_command && if (!sb::is_in_container(system_any_key_ignore, combination.command) && !found_command &&
!sfw::is_in_container(any_key_ignore, combination.command) && !suppress_any_key) !sb::is_in_container(any_key_ignore, combination.command) && !suppress_any_key)
{ {
post_command(any, cancel); post_command(any, cancel);
} }

View File

@ -11,11 +11,11 @@ Pixels::Pixels(SDL_Renderer* renderer, SDL_Texture* texture, const Box& box) :
SDL_DisplayMode display_mode; SDL_DisplayMode display_mode;
if (SDL_GetCurrentDisplayMode(0, &display_mode) < 0) if (SDL_GetCurrentDisplayMode(0, &display_mode) < 0)
{ {
sfw::print_sdl_error("could not get current display mode"); sb::print_sdl_error("could not get current display mode");
} }
if (SDL_GetRendererOutputSize(renderer, &w, &h) < 0) if (SDL_GetRendererOutputSize(renderer, &w, &h) < 0)
{ {
sfw::print_sdl_error("could not get renderer output size"); sb::print_sdl_error("could not get renderer output size");
} }
format_enum = display_mode.format; format_enum = display_mode.format;
texture_access = TEXTURE_ACCESS_SCREEN; texture_access = TEXTURE_ACCESS_SCREEN;
@ -45,7 +45,7 @@ Pixels::Pixels(SDL_Renderer* renderer, SDL_Texture* texture, const Box& box) :
} }
else if (texture_access == SDL_TEXTUREACCESS_STATIC) else if (texture_access == SDL_TEXTUREACCESS_STATIC)
{ {
base = sfw::duplicate_texture(renderer, texture); base = sb::duplicate_texture(renderer, texture);
is_duplicate = true; is_duplicate = true;
} }
else else
@ -57,7 +57,7 @@ Pixels::Pixels(SDL_Renderer* renderer, SDL_Texture* texture, const Box& box) :
source = operator new(bytes_total); source = operator new(bytes_total);
if (SDL_RenderReadPixels(renderer, &rect, format->format, source, format->BytesPerPixel * rect.w) < 0) if (SDL_RenderReadPixels(renderer, &rect, format->format, source, format->BytesPerPixel * rect.w) < 0)
{ {
sfw::print_sdl_error("could not read pixels"); sb::print_sdl_error("could not read pixels");
operator delete(source); operator delete(source);
} }
else else
@ -74,16 +74,16 @@ Pixels::Pixels(SDL_Renderer* renderer, SDL_Texture* texture, const Box& box) :
int pitch; int pitch;
if (SDL_LockTexture(texture, &rect, &source, &pitch) < 0) if (SDL_LockTexture(texture, &rect, &source, &pitch) < 0)
{ {
sfw::print_sdl_error("could not lock texture"); sb::print_sdl_error("could not lock texture");
} }
} }
else else
{ {
sfw::print_error("unknown texture format for loading pixels"); sb::print_error("unknown texture format for loading pixels");
} }
} }
Pixels::Pixels(SDL_Renderer* renderer, SDL_Texture* texture) : Pixels(renderer, texture, sfw::get_texture_box(texture)) {} Pixels::Pixels(SDL_Renderer* renderer, SDL_Texture* texture) : Pixels(renderer, texture, sb::get_texture_box(texture)) {}
int Pixels::get_bytes_per_row() const int Pixels::get_bytes_per_row() const
{ {

View File

@ -37,11 +37,11 @@ struct Pixels
std::uint8_t* access = static_cast<std::uint8_t*>(source); std::uint8_t* access = static_cast<std::uint8_t*>(source);
if (x < 0 || x >= rect.w) if (x < 0 || x >= rect.w)
{ {
x = sfw::mod(x, static_cast<int>(rect.w)); x = sb::mod(x, static_cast<int>(rect.w));
} }
if (y < 0 || y >= rect.y) if (y < 0 || y >= rect.y)
{ {
y = sfw::mod(y, static_cast<int>(rect.h)); y = sb::mod(y, static_cast<int>(rect.h));
} }
return reinterpret_cast<T>(access + y * get_bytes_per_row() + x * format->BytesPerPixel); return reinterpret_cast<T>(access + y * get_bytes_per_row() + x * format->BytesPerPixel);
} }

View File

@ -69,7 +69,7 @@ void Recorder::capture_screen()
std::string prefix = config["recording"]["screenshot-prefix"].get<std::string>(); std::string prefix = config["recording"]["screenshot-prefix"].get<std::string>();
std::string extension = config["recording"]["screenshot-extension"].get<std::string>(); std::string extension = config["recording"]["screenshot-extension"].get<std::string>();
int zfill = config["recording"]["screenshot-zfill"]; int zfill = config["recording"]["screenshot-zfill"];
fs::path path = sfw::get_next_file_name(directory, zfill, prefix, extension); fs::path path = sb::get_next_file_name(directory, zfill, prefix, extension);
IMG_SavePNG(surface, path.c_str()); IMG_SavePNG(surface, path.c_str());
SDL_FreeSurface(surface); SDL_FreeSurface(surface);
std::ostringstream message; std::ostringstream message;
@ -180,7 +180,7 @@ void Recorder::add_frame()
// SDL_Surface* frame = get_display().screen_surface_from_pixels( // SDL_Surface* frame = get_display().screen_surface_from_pixels(
// pixel_buffers[ii - frame_offset], flipped[ii - frame_offset]); // pixel_buffers[ii - frame_offset], flipped[ii - frame_offset]);
// std::stringstream name; // std::stringstream name;
// name << sfw::pad(ii, 5) << ".png"; // name << sb::pad(ii, 5) << ".png";
// fs::path path = current_video_directory / name.str(); // fs::path path = current_video_directory / name.str();
// SDL_Log("%s (%i, %i) (%i, %i, %i, %i)", path.c_str(), frame->w, frame->h, // SDL_Log("%s (%i, %i) (%i, %i, %i, %i)", path.c_str(), frame->w, frame->h,
// ((unsigned char*) frame->pixels)[0], ((unsigned char*) frame->pixels)[1], // ((unsigned char*) frame->pixels)[0], ((unsigned char*) frame->pixels)[1],
@ -232,7 +232,7 @@ void Recorder::make_directory()
nlohmann::json config = get_configuration(); nlohmann::json config = get_configuration();
fs::path root = config["recording"]["video-directory"]; fs::path root = config["recording"]["video-directory"];
fs::create_directories(root); fs::create_directories(root);
fs::path directory = sfw::get_next_file_name(root, 5, "video-"); fs::path directory = sb::get_next_file_name(root, 5, "video-");
fs::create_directories(directory); fs::create_directories(directory);
current_video_directory = directory; current_video_directory = directory;
} }
@ -243,7 +243,7 @@ void Recorder::write_stash_frames(Stash* stash)
SDL_Surface* frame; SDL_Surface* frame;
GifWriter gif_writer; GifWriter gif_writer;
int gif_frame_length = get_configuration()["recording"]["gif-frame-length"]; int gif_frame_length = get_configuration()["recording"]["gif-frame-length"];
fs::path gif_path = sfw::get_next_file_name( fs::path gif_path = sb::get_next_file_name(
current_video_directory, 3, "gif-", ".gif"); current_video_directory, 3, "gif-", ".gif");
float elapsed = 0, last_gif_write = 0, gif_write_overflow = 0; float elapsed = 0, last_gif_write = 0, gif_write_overflow = 0;
for (int ii = stash->frame_offset; not stash->pixel_buffers.empty(); ii++) for (int ii = stash->frame_offset; not stash->pixel_buffers.empty(); ii++)
@ -251,7 +251,7 @@ void Recorder::write_stash_frames(Stash* stash)
frame = get_display().screen_surface_from_pixels( frame = get_display().screen_surface_from_pixels(
stash->pixel_buffers.front(), stash->flipped.front()); stash->pixel_buffers.front(), stash->flipped.front());
std::stringstream name; std::stringstream name;
name << sfw::pad(ii, 5) << ".png"; name << sb::pad(ii, 5) << ".png";
fs::path path = current_video_directory / name.str(); fs::path path = current_video_directory / name.str();
IMG_SavePNG(frame, path.string().c_str()); IMG_SavePNG(frame, path.string().c_str());
if (ii == stash->frame_offset or if (ii == stash->frame_offset or

View File

@ -74,7 +74,7 @@ void Sprite::load_file(fs::path path)
SDL_Texture *base = IMG_LoadTexture(game->renderer, path.string().c_str()), *texture; SDL_Texture *base = IMG_LoadTexture(game->renderer, path.string().c_str()), *texture;
if (texture_access == SDL_TEXTUREACCESS_TARGET) if (texture_access == SDL_TEXTUREACCESS_TARGET)
{ {
texture = sfw::duplicate_texture(get_renderer(), base); texture = sb::duplicate_texture(get_renderer(), base);
SDL_DestroyTexture(base); SDL_DestroyTexture(base);
} }
else else
@ -498,7 +498,7 @@ void Sprite::add_hue_shift_frames(int count)
SDL_Texture* base = get_current_frame(); SDL_Texture* base = get_current_frame();
for (float offset = step; offset <= 359.9; offset += step) for (float offset = step; offset <= 359.9; offset += step)
{ {
add_frames(sfw::get_hue_shifted_texture(get_renderer(), base, offset)); add_frames(sb::get_hue_shifted_texture(get_renderer(), base, offset));
} }
} }
@ -625,7 +625,7 @@ bool Sprite::collide(const Box& box, bool precise, Box* overlap, bool all, SDL_T
} }
else else
{ {
collision_check_frame = sfw::duplicate_texture( collision_check_frame = sb::duplicate_texture(
const_cast<SDL_Renderer*>(get_renderer()), get_current_frame(), get_box(ii).size()); const_cast<SDL_Renderer*>(get_renderer()), get_current_frame(), get_box(ii).size());
} }
Pixels region_pixels = Pixels( Pixels region_pixels = Pixels(
@ -710,7 +710,7 @@ bool Sprite::collide(const Sprite& sprite, bool precise, Box* overlap, bool all,
} }
else else
{ {
other_sprite_collision_check_texture = sfw::duplicate_texture( other_sprite_collision_check_texture = sb::duplicate_texture(
const_cast<SDL_Renderer*>(get_renderer()), sprite.get_current_frame(), sprite.get_box(ii).size()); const_cast<SDL_Renderer*>(get_renderer()), sprite.get_current_frame(), sprite.get_box(ii).size());
} }
} }
@ -734,7 +734,7 @@ bool Sprite::collide(const Sprite& sprite, Box& overlap, bool precise, bool all,
void Sprite::wipe(float delay) void Sprite::wipe(float delay)
{ {
wipe_blinds = sfw::get_blinds_boxes(get_size()); wipe_blinds = sb::get_blinds_boxes(get_size());
if (wipe_increment < 0) if (wipe_increment < 0)
{ {
wipe_index = static_cast<int>(wipe_blinds.size() - 1); wipe_index = static_cast<int>(wipe_blinds.size() - 1);

View File

@ -2,25 +2,25 @@
#include "extension.hpp" #include "extension.hpp"
/* Edit a vector in place, giving it the specified magnitude while maintaining the direction */ /* Edit a vector in place, giving it the specified magnitude while maintaining the direction */
void sfw::set_magnitude(glm::vec2& vector, float magnitude) void sb::set_magnitude(glm::vec2& vector, float magnitude)
{ {
vector = glm::normalize(vector) * magnitude; vector = glm::normalize(vector) * magnitude;
} }
/* Return coordinates of a point x, y at specified angle on a circle described by center and radius */ /* Return coordinates of a point x, y at specified angle on a circle described by center and radius */
glm::vec2 sfw::point_on_circle(const glm::vec2& center, float radius, float angle) glm::vec2 sb::point_on_circle(const glm::vec2& center, float radius, float angle)
{ {
return {center.x + std::sin(angle) * radius, center.y - std::cos(angle) * radius}; return {center.x + std::sin(angle) * radius, center.y - std::cos(angle) * radius};
} }
/* Return a point x, y at specified angle on a circle at the origin with specified radius (default 1) */ /* Return a point x, y at specified angle on a circle at the origin with specified radius (default 1) */
glm::vec2 sfw::point_on_circle(float angle, float radius) glm::vec2 sb::point_on_circle(float angle, float radius)
{ {
return point_on_circle({0, 0}, radius, angle); return point_on_circle({0, 0}, radius, angle);
} }
/* Fill a pre-initialized vector with points evenly spaced around a circle starting at the angle offset (defaults to 0) */ /* Fill a pre-initialized vector with points evenly spaced around a circle starting at the angle offset (defaults to 0) */
void sfw::points_on_circle(std::vector<glm::vec2>& points, int count, float radius, const glm::vec2& center, float offset) void sb::points_on_circle(std::vector<glm::vec2>& points, int count, float radius, const glm::vec2& center, float offset)
{ {
float step = glm::two_pi<float>() / count; float step = glm::two_pi<float>() / count;
for (int ii = 0; ii < count; ii++) for (int ii = 0; ii < count; ii++)
@ -30,7 +30,7 @@ void sfw::points_on_circle(std::vector<glm::vec2>& points, int count, float radi
} }
/* Return a vector of count number of points evenly spaced around a circle starting at the angle offset (defaults to 0) */ /* Return a vector of count number of points evenly spaced around a circle starting at the angle offset (defaults to 0) */
std::vector<glm::vec2> sfw::points_on_circle(int count, float radius, const glm::vec2& center, float offset) std::vector<glm::vec2> sb::points_on_circle(int count, float radius, const glm::vec2& center, float offset)
{ {
std::vector<glm::vec2> points; std::vector<glm::vec2> points;
points.reserve(count); points.reserve(count);
@ -38,14 +38,14 @@ std::vector<glm::vec2> sfw::points_on_circle(int count, float radius, const glm:
return points; return points;
} }
Box sfw::get_texture_box(SDL_Texture* texture) Box sb::get_texture_box(SDL_Texture* texture)
{ {
int width, height; int width, height;
SDL_QueryTexture(texture, nullptr, nullptr, &width, &height); SDL_QueryTexture(texture, nullptr, nullptr, &width, &height);
return Box(glm::vec2(0, 0), glm::vec2(width, height)); return Box(glm::vec2(0, 0), glm::vec2(width, height));
} }
glm::vec2 sfw::fit_and_preserve_aspect(const glm::vec2& inner, const glm::vec2& outer) glm::vec2 sb::fit_and_preserve_aspect(const glm::vec2& inner, const glm::vec2& outer)
{ {
glm::vec2 delta = inner - outer; glm::vec2 delta = inner - outer;
float aspect = inner.x / inner.y; float aspect = inner.x / inner.y;
@ -63,7 +63,7 @@ glm::vec2 sfw::fit_and_preserve_aspect(const glm::vec2& inner, const glm::vec2&
return fit; return fit;
} }
std::vector<std::vector<Box>> sfw::get_blinds_boxes(glm::vec2 size, float step, int count) std::vector<std::vector<Box>> sb::get_blinds_boxes(glm::vec2 size, float step, int count)
{ {
std::vector<Box> blinds; std::vector<Box> blinds;
float blind_height = size.y / count; float blind_height = size.y / count;
@ -88,12 +88,12 @@ std::vector<std::vector<Box>> sfw::get_blinds_boxes(glm::vec2 size, float step,
return frames; return frames;
} }
void sfw::populate_pixel_2d_array(SDL_Renderer* renderer, SDL_Texture* texture, std::vector<std::vector<SDL_Color>>& pixels) void sb::populate_pixel_2d_array(SDL_Renderer* renderer, SDL_Texture* texture, std::vector<std::vector<SDL_Color>>& pixels)
{ {
populate_pixel_2d_array(renderer, texture, pixels, get_texture_box(texture)); populate_pixel_2d_array(renderer, texture, pixels, get_texture_box(texture));
} }
void sfw::populate_pixel_2d_array( void sb::populate_pixel_2d_array(
SDL_Renderer* renderer, SDL_Texture* texture, std::vector<std::vector<SDL_Color>>& pixels, const Box& region) SDL_Renderer* renderer, SDL_Texture* texture, std::vector<std::vector<SDL_Color>>& pixels, const Box& region)
{ {
int access; int access;
@ -145,7 +145,7 @@ void sfw::populate_pixel_2d_array(
} }
} }
std::vector<SDL_Texture*> sfw::get_halo_frames( std::vector<SDL_Texture*> sb::get_halo_frames(
SDL_Renderer* renderer, float radius, int segment_count, const std::vector<Color>& colors, float min_radius, bool fade) SDL_Renderer* renderer, float radius, int segment_count, const std::vector<Color>& colors, float min_radius, bool fade)
{ {
std::vector<SDL_Texture*> frames; std::vector<SDL_Texture*> frames;
@ -161,7 +161,7 @@ std::vector<SDL_Texture*> sfw::get_halo_frames(
{ {
alpha = alpha_step; alpha = alpha_step;
} }
frame = sfw::get_filled_texture(renderer, {2 * radius, 2 * radius}, {0, 0, 0, 0}); frame = get_filled_texture(renderer, {2 * radius, 2 * radius}, {0, 0, 0, 0});
SDL_SetTextureBlendMode(frame, SDL_BLENDMODE_BLEND); SDL_SetTextureBlendMode(frame, SDL_BLENDMODE_BLEND);
SDL_SetRenderTarget(renderer, frame); SDL_SetRenderTarget(renderer, frame);
for (int segment_ii = 0; segment_ii < segment_count; segment_ii++) for (int segment_ii = 0; segment_ii < segment_count; segment_ii++)
@ -181,7 +181,7 @@ std::vector<SDL_Texture*> sfw::get_halo_frames(
return frames; return frames;
} }
std::vector<SDL_Texture*> sfw::get_portal_frames( std::vector<SDL_Texture*> sb::get_portal_frames(
SDL_Renderer* renderer, glm::vec2 size, float hue_start, float hue_end, int dy, int count) SDL_Renderer* renderer, glm::vec2 size, float hue_start, float hue_end, int dy, int count)
{ {
std::vector<SDL_Texture*> frames; std::vector<SDL_Texture*> frames;
@ -193,7 +193,7 @@ std::vector<SDL_Texture*> sfw::get_portal_frames(
Color color; Color color;
for (int frame_ii = 0; frame_ii < count; frame_ii++) for (int frame_ii = 0; frame_ii < count; frame_ii++)
{ {
frame = sfw::get_filled_texture(renderer, size, {255, 255, 255, 0}); frame = get_filled_texture(renderer, size, {255, 255, 255, 0});
SDL_SetRenderTarget(renderer, frame); SDL_SetRenderTarget(renderer, frame);
SDL_SetTextureBlendMode(frame, SDL_BLENDMODE_BLEND); SDL_SetTextureBlendMode(frame, SDL_BLENDMODE_BLEND);
for (int ellipse_ii = 0, y = max_y; y > y_margin - 3; ellipse_ii++, y -= dy) for (int ellipse_ii = 0, y = max_y; y > y_margin - 3; ellipse_ii++, y -= dy)
@ -207,7 +207,7 @@ std::vector<SDL_Texture*> sfw::get_portal_frames(
return frames; return frames;
} }
void sfw::fill_texture(SDL_Renderer* renderer, SDL_Texture* texture, const SDL_Color& color, const Box& box) void sb::fill_texture(SDL_Renderer* renderer, SDL_Texture* texture, const SDL_Color& color, const Box& box)
{ {
SDL_SetRenderTarget(renderer, texture); SDL_SetRenderTarget(renderer, texture);
SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_NONE); SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_NONE);
@ -215,12 +215,12 @@ void sfw::fill_texture(SDL_Renderer* renderer, SDL_Texture* texture, const SDL_C
SDL_RenderFillRectF(renderer, &box); SDL_RenderFillRectF(renderer, &box);
} }
void sfw::fill_texture(SDL_Renderer* renderer, SDL_Texture* texture, const SDL_Color& color) void sb::fill_texture(SDL_Renderer* renderer, SDL_Texture* texture, const SDL_Color& color)
{ {
fill_texture(renderer, texture, color, get_texture_box(texture)); fill_texture(renderer, texture, color, get_texture_box(texture));
} }
void sfw::fill_texture(SDL_Renderer* renderer, SDL_Texture* texture, SDL_Texture* tile, const Box& box) void sb::fill_texture(SDL_Renderer* renderer, SDL_Texture* texture, SDL_Texture* tile, const Box& box)
{ {
Box texture_box = get_texture_box(texture), tile_box = get_texture_box(tile); Box texture_box = get_texture_box(texture), tile_box = get_texture_box(tile);
SDL_FRect draw_rect; SDL_FRect draw_rect;
@ -250,12 +250,12 @@ void sfw::fill_texture(SDL_Renderer* renderer, SDL_Texture* texture, SDL_Texture
} }
} }
void sfw::fill_texture(SDL_Renderer* renderer, SDL_Texture* texture, SDL_Texture* tile) void sb::fill_texture(SDL_Renderer* renderer, SDL_Texture* texture, SDL_Texture* tile)
{ {
fill_texture(renderer, texture, tile, get_texture_box(texture)); fill_texture(renderer, texture, tile, get_texture_box(texture));
} }
SDL_Texture* sfw::get_filled_texture(SDL_Renderer* renderer, glm::vec2 size, const SDL_Color& color, Uint32 format) SDL_Texture* sb::get_filled_texture(SDL_Renderer* renderer, glm::vec2 size, const SDL_Color& color, Uint32 format)
{ {
SDL_Texture* texture; SDL_Texture* texture;
if ((texture = SDL_CreateTexture(renderer, format, SDL_TEXTUREACCESS_TARGET, size.x, size.y)) == nullptr) if ((texture = SDL_CreateTexture(renderer, format, SDL_TEXTUREACCESS_TARGET, size.x, size.y)) == nullptr)
@ -264,12 +264,12 @@ SDL_Texture* sfw::get_filled_texture(SDL_Renderer* renderer, glm::vec2 size, con
} }
else else
{ {
sfw::fill_texture(renderer, texture, color); fill_texture(renderer, texture, color);
} }
return texture; return texture;
} }
SDL_Texture* sfw::get_filled_texture(SDL_Renderer* renderer, glm::vec2 size, SDL_Texture* tile, Uint32 format) SDL_Texture* sb::get_filled_texture(SDL_Renderer* renderer, glm::vec2 size, SDL_Texture* tile, Uint32 format)
{ {
SDL_Texture* texture; SDL_Texture* texture;
if ((texture = SDL_CreateTexture(renderer, format, SDL_TEXTUREACCESS_TARGET, size.x, size.y)) == nullptr) if ((texture = SDL_CreateTexture(renderer, format, SDL_TEXTUREACCESS_TARGET, size.x, size.y)) == nullptr)
@ -278,14 +278,14 @@ SDL_Texture* sfw::get_filled_texture(SDL_Renderer* renderer, glm::vec2 size, SDL
} }
else else
{ {
sfw::fill_texture(renderer, texture, tile); fill_texture(renderer, texture, tile);
} }
return texture; return texture;
} }
SDL_Texture* sfw::get_hue_shifted_texture(SDL_Renderer* renderer, SDL_Texture* base, float offset) SDL_Texture* sb::get_hue_shifted_texture(SDL_Renderer* renderer, SDL_Texture* base, float offset)
{ {
SDL_Texture* hue_shifted_texture = sfw::duplicate_texture(renderer, base); SDL_Texture* hue_shifted_texture = duplicate_texture(renderer, base);
Uint32 pixel_format; Uint32 pixel_format;
int w, h; int w, h;
if (SDL_QueryTexture(hue_shifted_texture, &pixel_format, nullptr, &w, &h) < 0) if (SDL_QueryTexture(hue_shifted_texture, &pixel_format, nullptr, &w, &h) < 0)
@ -326,13 +326,13 @@ SDL_Texture* sfw::get_hue_shifted_texture(SDL_Renderer* renderer, SDL_Texture* b
return hue_shifted_texture; return hue_shifted_texture;
} }
SDL_Texture* sfw::duplicate_texture(SDL_Renderer* renderer, SDL_Texture* base) SDL_Texture* sb::duplicate_texture(SDL_Renderer* renderer, SDL_Texture* base)
{ {
Box box = get_texture_box(base); Box box = get_texture_box(base);
return duplicate_texture(renderer, base, box.size()); return duplicate_texture(renderer, base, box.size());
} }
SDL_Texture* sfw::duplicate_texture(SDL_Renderer* renderer, SDL_Texture* base, const glm::vec2& size) SDL_Texture* sb::duplicate_texture(SDL_Renderer* renderer, SDL_Texture* base, const glm::vec2& size)
{ {
SDL_BlendMode original_blend_mode; SDL_BlendMode original_blend_mode;
SDL_GetTextureBlendMode(base, &original_blend_mode); SDL_GetTextureBlendMode(base, &original_blend_mode);
@ -361,7 +361,7 @@ SDL_Texture* sfw::duplicate_texture(SDL_Renderer* renderer, SDL_Texture* base, c
return duplicate; return duplicate;
} }
SDL_Texture* sfw::get_remapped_texture( SDL_Texture* sb::get_remapped_texture(
SDL_Renderer* renderer, SDL_Texture* base, const std::map<Color, Color>& map) SDL_Renderer* renderer, SDL_Texture* base, const std::map<Color, Color>& map)
{ {
SDL_Texture* remapped = duplicate_texture(renderer, base); SDL_Texture* remapped = duplicate_texture(renderer, base);
@ -393,7 +393,7 @@ SDL_Texture* sfw::get_remapped_texture(
return remapped; return remapped;
} }
SDL_Texture* sfw::get_remapped_texture( SDL_Texture* sb::get_remapped_texture(
SDL_Renderer* renderer, const std::string& path, const std::map<Color, Color>& map) SDL_Renderer* renderer, const std::string& path, const std::map<Color, Color>& map)
{ {
SDL_Texture* base = IMG_LoadTexture(renderer, path.c_str()); SDL_Texture* base = IMG_LoadTexture(renderer, path.c_str());
@ -418,7 +418,7 @@ SDL_Texture* sfw::get_remapped_texture(
- Base texture must be set to SDL_TEXTUREACCESS_TARGET - Base texture must be set to SDL_TEXTUREACCESS_TARGET
- Scale2x implementation based on http://www.scale2x.it/algorithm.html - Scale2x implementation based on http://www.scale2x.it/algorithm.html
*/ */
SDL_Texture* sfw::get_pixel_scaled_texture(SDL_Renderer* renderer, SDL_Texture* base, int count, int version) SDL_Texture* sb::get_pixel_scaled_texture(SDL_Renderer* renderer, SDL_Texture* base, int count, int version)
{ {
if ((SDL_SetRenderTarget(renderer, base)) < 0) if ((SDL_SetRenderTarget(renderer, base)) < 0)
{ {
@ -529,7 +529,7 @@ SDL_Texture* sfw::get_pixel_scaled_texture(SDL_Renderer* renderer, SDL_Texture*
return scaled; return scaled;
} }
std::vector<fs::path> sfw::glob(fs::path query) std::vector<fs::path> sb::glob(fs::path query)
{ {
fs::path basename = query.parent_path(); fs::path basename = query.parent_path();
if (basename == "") if (basename == "")
@ -549,7 +549,7 @@ std::vector<fs::path> sfw::glob(fs::path query)
return files; return files;
} }
SDL_Surface* sfw::get_surface_from_pixels(Pixels& pixels) SDL_Surface* sb::get_surface_from_pixels(Pixels& pixels)
{ {
SDL_Surface* surface = SDL_CreateRGBSurfaceFrom( SDL_Surface* surface = SDL_CreateRGBSurfaceFrom(
pixels.source, pixels.rect.w, pixels.rect.h, pixels.format->BitsPerPixel, pixels.source, pixels.rect.w, pixels.rect.h, pixels.format->BitsPerPixel,
@ -566,12 +566,12 @@ SDL_Surface* sfw::get_surface_from_pixels(Pixels& pixels)
return nullptr; return nullptr;
} }
fs::path sfw::get_next_file_name(fs::path directory, int zfill, std::string prefix, std::string extension) fs::path sb::get_next_file_name(fs::path directory, int zfill, std::string prefix, std::string extension)
{ {
std::stringstream file_pattern; std::stringstream file_pattern;
file_pattern << prefix << "([0-9]+)" << extension; file_pattern << prefix << "([0-9]+)" << extension;
fs::path query = directory / file_pattern.str(); fs::path query = directory / file_pattern.str();
std::vector<fs::path> files = sfw::glob(query); std::vector<fs::path> files = glob(query);
int index = 1; int index = 1;
if (files.size()) if (files.size())
{ {
@ -584,7 +584,7 @@ fs::path sfw::get_next_file_name(fs::path directory, int zfill, std::string pref
fs::path path; fs::path path;
do do
{ {
filename << prefix << sfw::pad(index++, zfill) << extension; filename << prefix << pad(index++, zfill) << extension;
path = directory / filename.str(); path = directory / filename.str();
filename.str(""); filename.str("");
filename.clear(); filename.clear();
@ -594,7 +594,7 @@ fs::path sfw::get_next_file_name(fs::path directory, int zfill, std::string pref
} }
/* Read the file at path into a string and return the string */ /* Read the file at path into a string and return the string */
std::string sfw::file_to_string(const fs::path& path) std::string sb::file_to_string(const fs::path& path)
{ {
std::fstream file; std::fstream file;
file.open(path); file.open(path);
@ -624,12 +624,12 @@ std::string sfw::file_to_string(const fs::path& path)
} }
} }
void sfw::print_error(const std::string& message) void sb::print_error(const std::string& message)
{ {
std::cerr << message << std::endl; std::cerr << message << std::endl;
} }
void sfw::print_sdl_error(const std::string& message) void sb::print_sdl_error(const std::string& message)
{ {
std::cerr << message << " " << SDL_GetError() << std::endl; std::cerr << message << " " << SDL_GetError() << std::endl;
} }

View File

@ -30,7 +30,7 @@
struct Pixels; struct Pixels;
namespace sfw namespace sb
{ {
enum scaler {scale2x, xbr}; enum scaler {scale2x, xbr};