SDOM - Simple SDL Document Object Model
A lightweight, extensible Document Object Model for SDL-based applications.
Loading...
Searching...
No Matches
SDOM_SDL_Utils.hpp
Go to the documentation of this file.
1/*** SDOM_SDL_Utils.hpp ****************************
2 * ___ ___ ___ __ __ ___ ___ _ _ _ _ _ _ _
3 * / __| \ / _ \| \/ | / __| \| | | | | | |_(_) |___ | |_ _ __ _ __
4 * \__ \ |) | (_) | |\/| | \__ \ |) | |__ | |_| | _| | (_-<_| ' \| '_ \ '_ \
5 * |___/___/ \___/|_| |_|_|___/___/|____|_\___/ \__|_|_/__(_)_||_| .__/ .__/
6 * |___| |___| |_| |_|
7 *
8 * The SDOM_SDL_Utils class provides a collection of static utility functions to
9 * facilitate common SDL3 operations within the SDOM framework. It offers convenient
10 * methods for converting between SDL enumerations and their string representations,
11 * such as pixel formats, window flags, renderer presentation modes, and event types.
12 * Additionally, it includes helper functions for keycode-to-ASCII conversion and other
13 * SDL-specific tasks. By centralizing these utilities, SDL_Utils simplifies SDL
14 * integration, enhances code readability, and promotes consistency across the SDOM codebase.
15 *
16 *
17 * This software is provided 'as-is', without any express or implied
18 * warranty. In no event will the authors be held liable for any damages
19 * arising from the use of this software.
20 *
21 * Permission is granted to anyone to use this software for any purpose,
22 * including commercial applications, and to alter it and redistribute it
23 * freely, subject to the following restrictions:
24 *
25 * 1. The origin of this software must not be misrepresented; you must not
26 * claim that you wrote the original software. If you use this software
27 * in a product, an acknowledgment in the product documentation would be
28 * appreciated but is not required.
29 * 2. Altered source versions must be plainly marked as such, and must not be
30 * misrepresented as being the original software.
31 * 3. This notice may not be removed or altered from any source distribution.
32 *
33 * Released under the ZLIB License.
34 * Original Author: Jay Faries (warte67)
35 *
36 ******************/
37
38#ifndef __SDOM_SDL_UTILS_HPP__
39#define __SDOM_SDL_UTILS_HPP__
40
41#include <SDOM/SDOM.hpp>
42
43namespace SDOM
44{
45
47 {
48 public:
49 SDL_Utils() = default;
50 ~SDL_Utils() = default;
51
52 // Utility functions for SDL operations
53 static std::string pixelFormatToString(SDL_PixelFormat format);
54 static SDL_PixelFormat pixelFormatFromString(const std::string& str);
55
56 static std::string windowFlagsToString(Uint64 flags);
57 static Uint64 windowFlagsFromString(const std::string& str);
58
59 static std::string rendererLogicalPresentationToString(Uint32 flags);
60 static SDL_RendererLogicalPresentation rendererLogicalPresentationFromString(const std::string& str);
61
62 static std::string eventTypeToString(SDL_EventType type);
63 static SDL_EventType eventTypeFromString(const std::string& str);
64
65 static int keyToAscii(SDL_Keycode keycode, SDL_Keymod keymod);
66
67 static sol::table eventToLuaTable(const SDL_Event& event, sol::state_view lua);
68 static void registerLua(sol::state_view lua);
69
70 static SDL_FRect tableToFRect(const sol::table& t);
71 static SDL_Color colorFromSol(const sol::object& o);
72
73 static SDL_ScaleMode scaleModeFromSol(const sol::object& o);
74
75 };
76
77} // namespace SDOM
78
79#endif // __SDOM_SDL_UTILS_HPP__
Definition SDOM_SDL_Utils.hpp:47
static SDL_RendererLogicalPresentation rendererLogicalPresentationFromString(const std::string &str)
Definition SDOM_SDL_Utils.cpp:395
static SDL_EventType eventTypeFromString(const std::string &str)
Definition SDOM_SDL_Utils.cpp:523
static SDL_ScaleMode scaleModeFromSol(const sol::object &o)
Definition SDOM_SDL_Utils.cpp:1532
static SDL_FRect tableToFRect(const sol::table &t)
Definition SDOM_SDL_Utils.cpp:1465
static SDL_Color colorFromSol(const sol::object &o)
Definition SDOM_SDL_Utils.cpp:1514
static std::string rendererLogicalPresentationToString(Uint32 flags)
Definition SDOM_SDL_Utils.cpp:384
static sol::table eventToLuaTable(const SDL_Event &event, sol::state_view lua)
Definition SDOM_SDL_Utils.cpp:925
static std::string windowFlagsToString(Uint64 flags)
Definition SDOM_SDL_Utils.cpp:285
static void registerLua(sol::state_view lua)
Definition SDOM_SDL_Utils.cpp:44
static Uint64 windowFlagsFromString(const std::string &str)
Definition SDOM_SDL_Utils.cpp:335
~SDL_Utils()=default
SDL_Utils()=default
static std::string pixelFormatToString(SDL_PixelFormat format)
Definition SDOM_SDL_Utils.cpp:143
static int keyToAscii(SDL_Keycode keycode, SDL_Keymod keymod)
Definition SDOM_SDL_Utils.cpp:639
static std::string eventTypeToString(SDL_EventType type)
Definition SDOM_SDL_Utils.cpp:405
static SDL_PixelFormat pixelFormatFromString(const std::string &str)
Definition SDOM_SDL_Utils.cpp:215
Contains all core classes and utilities for the SDOM library.
Definition lua_BindHelpers.hpp:7