From 4c774ca9ec89ab3f59e0dfc629d06fe823647ebe Mon Sep 17 00:00:00 2001 From: kiritow <1362050620@qq.com> Date: Sun, 18 Jun 2017 20:37:17 +0800 Subject: [PATCH] Move Enum out to single files. --- SDLWrapper/_BlendMode.h | 8 ++ SDLWrapper/_FlipMode.h | 7 ++ SDLWrapper/_FontHint.h | 9 ++ SDLWrapper/_FontStyle.h | 9 ++ SDLWrapper/_MessageBoxType.h | 7 ++ SDLWrapper/_Platform.h | 10 ++ SDLWrapper/_PowerState.h | 9 ++ SDLWrapper/_RendererType.h | 8 ++ SDLWrapper/_SystemCursorType.h | 8 ++ SDLWrapper/_WindowType.h | 10 ++ SDLWrapper/_caster.cpp | 219 +++++++++++++++++++++++++++++++++ SDLWrapper/_caster.h | 22 ++++ 12 files changed, 326 insertions(+) create mode 100644 SDLWrapper/_BlendMode.h create mode 100644 SDLWrapper/_FlipMode.h create mode 100644 SDLWrapper/_FontHint.h create mode 100644 SDLWrapper/_FontStyle.h create mode 100644 SDLWrapper/_MessageBoxType.h create mode 100644 SDLWrapper/_Platform.h create mode 100644 SDLWrapper/_PowerState.h create mode 100644 SDLWrapper/_RendererType.h create mode 100644 SDLWrapper/_SystemCursorType.h create mode 100644 SDLWrapper/_WindowType.h create mode 100644 SDLWrapper/_caster.cpp create mode 100644 SDLWrapper/_caster.h diff --git a/SDLWrapper/_BlendMode.h b/SDLWrapper/_BlendMode.h new file mode 100644 index 0000000..a79d1da --- /dev/null +++ b/SDLWrapper/_BlendMode.h @@ -0,0 +1,8 @@ +#pragma once +enum class BlendMode +{ + None, + Blend, + Add, + Mod +}; diff --git a/SDLWrapper/_FlipMode.h b/SDLWrapper/_FlipMode.h new file mode 100644 index 0000000..6eee691 --- /dev/null +++ b/SDLWrapper/_FlipMode.h @@ -0,0 +1,7 @@ +#pragma once +enum class FlipMode +{ + None, + Horizontal, + Vertical +}; diff --git a/SDLWrapper/_FontHint.h b/SDLWrapper/_FontHint.h new file mode 100644 index 0000000..7cb8f9b --- /dev/null +++ b/SDLWrapper/_FontHint.h @@ -0,0 +1,9 @@ +#pragma once +enum class FontHint +{ + Normal, + Light, + Mono, + None, + Error +}; diff --git a/SDLWrapper/_FontStyle.h b/SDLWrapper/_FontStyle.h new file mode 100644 index 0000000..26d748b --- /dev/null +++ b/SDLWrapper/_FontStyle.h @@ -0,0 +1,9 @@ +#pragma once +enum class FontStyle +{ + Normal, + Bold, + Italic, + UnderLine, + StrikeThrough +}; diff --git a/SDLWrapper/_MessageBoxType.h b/SDLWrapper/_MessageBoxType.h new file mode 100644 index 0000000..12876aa --- /dev/null +++ b/SDLWrapper/_MessageBoxType.h @@ -0,0 +1,7 @@ +#pragma once +enum class MessageBoxType +{ + Error, + Warning, + Information +}; diff --git a/SDLWrapper/_Platform.h b/SDLWrapper/_Platform.h new file mode 100644 index 0000000..fce1f2c --- /dev/null +++ b/SDLWrapper/_Platform.h @@ -0,0 +1,10 @@ +#pragma once +enum class Platform +{ + Unknown, + Windows, + MacOS, + Linux, + iOS, + Android +}; diff --git a/SDLWrapper/_PowerState.h b/SDLWrapper/_PowerState.h new file mode 100644 index 0000000..7aaca83 --- /dev/null +++ b/SDLWrapper/_PowerState.h @@ -0,0 +1,9 @@ +#pragma once +enum class PowerState +{ + Unknown, + OnBattery, + NoBattery, + Charging, + Charged +}; diff --git a/SDLWrapper/_RendererType.h b/SDLWrapper/_RendererType.h new file mode 100644 index 0000000..7bdbd17 --- /dev/null +++ b/SDLWrapper/_RendererType.h @@ -0,0 +1,8 @@ +#pragma once +enum class RendererType +{ + Software, + Accelerated, + PresentSync, + TargetTexture +}; diff --git a/SDLWrapper/_SystemCursorType.h b/SDLWrapper/_SystemCursorType.h new file mode 100644 index 0000000..fd5ccf4 --- /dev/null +++ b/SDLWrapper/_SystemCursorType.h @@ -0,0 +1,8 @@ +#pragma once +enum class SystemCursorType +{ + Arrow, Ibeam, CrossHair, + Wait, WaitArrow, + SizeNWSE, SizeNESW, SizeWE, SizeNS, SizeAll, + No, Hand +}; diff --git a/SDLWrapper/_WindowType.h b/SDLWrapper/_WindowType.h new file mode 100644 index 0000000..0002026 --- /dev/null +++ b/SDLWrapper/_WindowType.h @@ -0,0 +1,10 @@ +#pragma once +enum class WindowType +{ + FullScreen, OpenGL, Shown, Hidden, + Borderless, Resizable, Minimized, Maximized, + InputGrabbed, InputFocus, MouseFocus, + FullScreenDesktop, Foreign, AllowHighDPI, + MouseCapture, AlwaysOnTop, SkipTaskBar, + Utility, ToolTip, PopUpMenu +}; diff --git a/SDLWrapper/_caster.cpp b/SDLWrapper/_caster.cpp new file mode 100644 index 0000000..df00204 --- /dev/null +++ b/SDLWrapper/_caster.cpp @@ -0,0 +1,219 @@ +#include "_caster.h" +#include "begin_code.h" +namespace _internal +{ +BlendMode getBlendModeFromSDLBlendMode(SDL_BlendMode mode) +{ + switch(mode) + { + case SDL_BLENDMODE_ADD: + return BlendMode::Add; + case SDL_BLENDMODE_BLEND: + return BlendMode::Blend; + case SDL_BLENDMODE_MOD: + return BlendMode::Mod; + case SDL_BLENDMODE_NONE: + default:/// return BlendMode::None on default. + return BlendMode::None; + } +} + +SDL_BlendMode getSDLBlendModeFromBlendMode(BlendMode mode) +{ + switch(mode) + { + case BlendMode::Add: + return SDL_BLENDMODE_ADD; + case BlendMode::Blend: + return SDL_BLENDMODE_BLEND; + case BlendMode::Mod: + return SDL_BLENDMODE_MOD; + case BlendMode::None: + default:/// return SDL_BLENDMODE_NONE on default. + return SDL_BLENDMODE_NONE; + } +} + +/// FIXME: return SDL_WindowFlags or Uint32 ? +Uint32 getSDLWindowFlagsFromWindowType(WindowType type) +{ + switch(type) + { + case WindowType::FullScreen: + return SDL_WINDOW_FULLSCREEN; + case WindowType::OpenGL: + return SDL_WINDOW_OPENGL; + case WindowType::Shown: + return SDL_WINDOW_SHOWN; + case WindowType::Hidden: + return SDL_WINDOW_HIDDEN; + case WindowType::Borderless: + return SDL_WINDOW_BORDERLESS; + case WindowType::Resizable: + return SDL_WINDOW_RESIZABLE; + case WindowType::Minimized: + return SDL_WINDOW_MINIMIZED; + case WindowType::Maximized: + return SDL_WINDOW_MAXIMIZED; + case WindowType::InputGrabbed: + return SDL_WINDOW_INPUT_GRABBED; + case WindowType::InputFocus: + return SDL_WINDOW_INPUT_FOCUS; + case WindowType::MouseFocus: + return SDL_WINDOW_MOUSE_FOCUS; + case WindowType::FullScreenDesktop: + return SDL_WINDOW_FULLSCREEN_DESKTOP; + case WindowType::Foreign: + return SDL_WINDOW_FOREIGN; + case WindowType::AllowHighDPI: + return SDL_WINDOW_ALLOW_HIGHDPI; + case WindowType::MouseCapture: + return SDL_WINDOW_MOUSE_CAPTURE; + +#if _MINIENGINE_SDL_VERSION_ATLEAST(2,0,5) /// SDL 2.0.5 Required + case WindowType::AlwaysOnTop: + return SDL_WINDOW_ALWAYS_ON_TOP; + case WindowType::SkipTaskBar: + return SDL_WINDOW_SKIP_TASKBAR; + case WindowType::Utility: + return SDL_WINDOW_UTILITY; + case WindowType::ToolTip: + return SDL_WINDOW_TOOLTIP; + case WindowType::PopUpMenu: + return SDL_WINDOW_POPUP_MENU; +#endif // End of SDL2.0.5 Require + + default: + return 0;/// Return 0 on default. + } +} + +SystemCursorType getCursorTypeFromSDLSystemCursor(SDL_SystemCursor id) +{ + switch(id) + { + case SDL_SYSTEM_CURSOR_ARROW: + return SystemCursorType::Arrow; + case SDL_SYSTEM_CURSOR_CROSSHAIR: + return SystemCursorType::CrossHair; + case SDL_SYSTEM_CURSOR_HAND: + return SystemCursorType::Hand; + case SDL_SYSTEM_CURSOR_IBEAM: + return SystemCursorType::Ibeam; + case SDL_SYSTEM_CURSOR_NO: + return SystemCursorType::No; + case SDL_SYSTEM_CURSOR_SIZEALL: + return SystemCursorType::SizeAll; + case SDL_SYSTEM_CURSOR_SIZENESW: + return SystemCursorType::SizeNESW; + case SDL_SYSTEM_CURSOR_SIZENS: + return SystemCursorType::SizeNS; + case SDL_SYSTEM_CURSOR_SIZENWSE: + return SystemCursorType::SizeNWSE; + case SDL_SYSTEM_CURSOR_SIZEWE: + return SystemCursorType::SizeWE; + case SDL_SYSTEM_CURSOR_WAIT: + return SystemCursorType::Wait; + case SDL_SYSTEM_CURSOR_WAITARROW: + return SystemCursorType::WaitArrow; + default:/// return SystemCursorType::Arrow on default. + return SystemCursorType::Arrow; + } +} + +SDL_SystemCursor getSDLSystemCursorFromSystemCursorType(SystemCursorType type) +{ + switch(type) + { + case SystemCursorType::Arrow: + return SDL_SYSTEM_CURSOR_ARROW; + case SystemCursorType::CrossHair: + return SDL_SYSTEM_CURSOR_CROSSHAIR; + case SystemCursorType::Hand: + return SDL_SYSTEM_CURSOR_HAND; + case SystemCursorType::Ibeam: + return SDL_SYSTEM_CURSOR_IBEAM; + case SystemCursorType::No: + return SDL_SYSTEM_CURSOR_NO; + case SystemCursorType::SizeAll: + return SDL_SYSTEM_CURSOR_SIZEALL; + case SystemCursorType::SizeNESW: + return SDL_SYSTEM_CURSOR_SIZENESW; + case SystemCursorType::SizeNS: + return SDL_SYSTEM_CURSOR_SIZENS; + case SystemCursorType::SizeNWSE: + return SDL_SYSTEM_CURSOR_SIZENWSE; + case SystemCursorType::SizeWE: + return SDL_SYSTEM_CURSOR_SIZEWE; + case SystemCursorType::Wait: + return SDL_SYSTEM_CURSOR_WAIT; + case SystemCursorType::WaitArrow: + return SDL_SYSTEM_CURSOR_WAITARROW; + default:/// return SDL_SYSTEM_CURSOR_ARROW on default. + return SDL_SYSTEM_CURSOR_ARROW; + } +} + +int getTTFFontStyleFromFontStyle(FontStyle style) +{ + switch(style) + { + case FontStyle::Bold: + return TTF_STYLE_BOLD; + case FontStyle::Italic: + return TTF_STYLE_ITALIC; + case FontStyle::Normal: + return TTF_STYLE_NORMAL; + case FontStyle::StrikeThrough: + return TTF_STYLE_STRIKETHROUGH; + case FontStyle::UnderLine: + return TTF_STYLE_UNDERLINE; + default: + return TTF_STYLE_NORMAL; + } +} + +std::vector getFontStyleVecFromMixedTTFFontStyle(int Mixed_TTF_Font_Style) +{ + std::vector vec; + if(Mixed_TTF_Font_Style&TTF_STYLE_BOLD) + { + vec.push_back(FontStyle::Bold); + } + if(Mixed_TTF_Font_Style&TTF_STYLE_ITALIC) + { + vec.push_back(FontStyle::Italic); + } + if(Mixed_TTF_Font_Style&TTF_STYLE_STRIKETHROUGH) + { + vec.push_back(FontStyle::StrikeThrough); + } + if(Mixed_TTF_Font_Style&TTF_STYLE_UNDERLINE) + { + vec.push_back(FontStyle::UnderLine); + } + if(vec.empty()) + { + vec.push_back(FontStyle::Normal); + } + + return vec; +} + +SDL_RendererFlip getSDLRendererFlipFromFlipMode(FlipMode mode) +{ + switch(mode) + { + case FlipMode::None: + return SDL_FLIP_NONE; + case FlipMode::Horizontal: + return SDL_FLIP_HORIZONTAL; + case FlipMode::Vertical: + return SDL_FLIP_VERTICAL; + default: + /// return non-flip mode on default. + return SDL_FLIP_NONE; + } +} +}/// End of namespace _internal +#include "end_code.h" diff --git a/SDLWrapper/_caster.h b/SDLWrapper/_caster.h new file mode 100644 index 0000000..646fa35 --- /dev/null +++ b/SDLWrapper/_caster.h @@ -0,0 +1,22 @@ +#pragma once +#include "include.h" +#include "_BlendMode.h" +#include "_WindowType.h" +#include "_SystemCursorType.h" +#include "_FontStyle.h" +#include "_FlipMode.h" +#include +#include "begin_code.h" +namespace _internal +{ +BlendMode getBlendModeFromSDLBlendMode(SDL_BlendMode mode); +SDL_BlendMode getSDLBlendModeFromBlendMode(BlendMode mode); +/// FIXME: return SDL_WindowFlags or Uint32 ? +Uint32 getSDLWindowFlagsFromWindowType(WindowType type); +SystemCursorType getCursorTypeFromSDLSystemCursor(SDL_SystemCursor id); +SDL_SystemCursor getSDLSystemCursorFromSystemCursorType(SystemCursorType type); +int getTTFFontStyleFromFontStyle(FontStyle style); +std::vector getFontStyleVecFromMixedTTFFontStyle(int Mixed_TTF_Font_Style); +SDL_RendererFlip getSDLRendererFlipFromFlipMode(FlipMode mode); +}/// End of namespace _internal +#include "end_code.h"