mirror of
https://github.com/Kiritow/MiniEngine.git
synced 2024-03-22 13:11:22 +08:00
Move SDL,IMG,Mix,TTF Init to SDLSystem
This commit is contained in:
parent
b6f7e70cdd
commit
5eb66f6d0d
|
@ -1,69 +1,73 @@
|
|||
#include "SDLSystem.h"
|
||||
#include "_caster.h"
|
||||
#include "begin_code.h"
|
||||
//static
|
||||
int SDLSystem::SDLInit()
|
||||
SDLSystem::SDLSystem(const std::initializer_list<SDLInitFlag>& flag_sdl,
|
||||
const std::initializer_list<IMGInitFlag>& flag_img,
|
||||
const std::initializer_list<MixInitFlag>& flag_mix,
|
||||
bool init_ttf ) throw (ErrorViewer)
|
||||
{
|
||||
return SDL_Init(SDL_INIT_EVERYTHING);
|
||||
Uint32 sdl_flag=0;
|
||||
for(auto& v:flag_sdl)
|
||||
{
|
||||
sdl_flag |= _internal::getUint32FromSDLInitFlag(v);
|
||||
}
|
||||
int img_flag=0;
|
||||
for(auto& v:flag_img)
|
||||
{
|
||||
img_flag |= _internal::getIntFromIMGInitFlag(v);
|
||||
}
|
||||
int mix_flag=0;
|
||||
for(auto& v:flag_mix)
|
||||
{
|
||||
mix_flag |= _internal::getIntFromMixInitFlag(v);
|
||||
}
|
||||
|
||||
//static
|
||||
void SDLSystem::SDLQuit()
|
||||
int ret=SDL_Init(sdl_flag);
|
||||
if(ret!=0)
|
||||
{
|
||||
SDL_Quit();
|
||||
ErrorViewer e;
|
||||
e.fetch();
|
||||
throw e;
|
||||
}
|
||||
|
||||
//static
|
||||
int SDLSystem::IMGInit()
|
||||
ret=IMG_Init(img_flag);
|
||||
if(ret!=0)
|
||||
{
|
||||
return IMG_Init(IMG_INIT_JPG | IMG_INIT_PNG);
|
||||
ErrorViewer e;
|
||||
e.fetch();
|
||||
throw e;
|
||||
}
|
||||
|
||||
//static
|
||||
void SDLSystem::IMGQuit()
|
||||
ret=Mix_Init(mix_flag);
|
||||
if(ret!=0)
|
||||
{
|
||||
IMG_Quit();
|
||||
ErrorViewer e;
|
||||
e.fetch();
|
||||
throw e;
|
||||
}
|
||||
|
||||
//static
|
||||
int SDLSystem::TTFInit()
|
||||
if(init_ttf)
|
||||
{
|
||||
return TTF_Init();
|
||||
ret=TTF_Init();
|
||||
if(ret!=0)
|
||||
{
|
||||
ErrorViewer e;
|
||||
e.fetch();
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//static
|
||||
void SDLSystem::TTFQuit()
|
||||
SDLSystem::~SDLSystem()
|
||||
{
|
||||
if(TTF_WasInit())
|
||||
{
|
||||
TTF_Quit();
|
||||
}
|
||||
|
||||
//static
|
||||
int SDLSystem::MixInit()
|
||||
{
|
||||
return Mix_Init(MIX_INIT_MP3);
|
||||
}
|
||||
|
||||
//static
|
||||
void SDLSystem::MixQuit()
|
||||
{
|
||||
Mix_Quit();
|
||||
}
|
||||
|
||||
//static
|
||||
void SDLSystem::Init()
|
||||
{
|
||||
SDLInit();
|
||||
IMGInit();
|
||||
TTFInit();
|
||||
MixInit();
|
||||
}
|
||||
|
||||
//static
|
||||
void SDLSystem::Quit()
|
||||
{
|
||||
MixQuit();
|
||||
TTFQuit();
|
||||
IMGQuit();
|
||||
SDLQuit();
|
||||
IMG_Quit();
|
||||
SDL_Quit();
|
||||
}
|
||||
|
||||
//static
|
||||
|
|
|
@ -2,23 +2,24 @@
|
|||
#include "include.h"
|
||||
#include "_PowerState.h"
|
||||
#include "_Platform.h"
|
||||
#include "_SDLInitFlag.h"
|
||||
#include "_IMGInitFlag.h"
|
||||
#include "_MixInitFlag.h"
|
||||
#include "__Noncopyable.h"
|
||||
#include "__Nonmoveable.h"
|
||||
#include "ErrorViewer.h"
|
||||
#include <tuple>
|
||||
#include <string>
|
||||
#include "begin_code.h"
|
||||
class SDLSystem
|
||||
|
||||
class SDLSystem : public NonCopyable, public NonMoveable
|
||||
{
|
||||
public:
|
||||
static int SDLInit();
|
||||
static void SDLQuit();
|
||||
static int IMGInit();
|
||||
static void IMGQuit();
|
||||
static int TTFInit();
|
||||
static void TTFQuit();
|
||||
static int MixInit();
|
||||
static void MixQuit();
|
||||
|
||||
static void Init();
|
||||
static void Quit();
|
||||
SDLSystem(const std::initializer_list<SDLInitFlag>& flag_sdl = {SDLInitFlag::All} ,
|
||||
const std::initializer_list<IMGInitFlag>& flag_img = {IMGInitFlag::JPG,IMGInitFlag::PNG} ,
|
||||
const std::initializer_list<MixInitFlag>& flag_mix = {MixInitFlag::MP3} ,
|
||||
bool init_ttf = true ) throw (ErrorViewer);
|
||||
~SDLSystem();
|
||||
|
||||
static void Delay(int ms);
|
||||
|
||||
|
|
11
SDLWrapper/_IMGInitFlag.h
Normal file
11
SDLWrapper/_IMGInitFlag.h
Normal file
|
@ -0,0 +1,11 @@
|
|||
#pragma once
|
||||
#include "begin_code.h"
|
||||
enum class IMGInitFlag
|
||||
{
|
||||
JPG,
|
||||
PNG,
|
||||
TIF,
|
||||
WEBP,
|
||||
ALL
|
||||
};
|
||||
#include "end_code.h"
|
12
SDLWrapper/_MixInitFlag.h
Normal file
12
SDLWrapper/_MixInitFlag.h
Normal file
|
@ -0,0 +1,12 @@
|
|||
#pragma once
|
||||
#include "begin_code.h"
|
||||
enum class MixInitFlag
|
||||
{
|
||||
FLAC,
|
||||
MOD,
|
||||
MODPLUG,
|
||||
MP3,
|
||||
OGG,
|
||||
FLUIDSYNTH
|
||||
};
|
||||
#include "end_code.h"
|
14
SDLWrapper/_SDLInitFlag.h
Normal file
14
SDLWrapper/_SDLInitFlag.h
Normal file
|
@ -0,0 +1,14 @@
|
|||
#pragma once
|
||||
#include "begin_code.h"
|
||||
enum class SDLInitFlag
|
||||
{
|
||||
Timer,
|
||||
Audio,
|
||||
Video, /**< SDL_INIT_VIDEO implies SDL_INIT_EVENTS */
|
||||
Joystick, /**< SDL_INIT_JOYSTICK implies SDL_INIT_EVENTS */
|
||||
Haptic,
|
||||
GameController, /**< SDL_INIT_GAMECONTROLLER implies SDL_INIT_JOYSTICK */
|
||||
Events,
|
||||
All
|
||||
};
|
||||
#include "end_code.h"
|
|
@ -3,6 +3,8 @@
|
|||
class NonMoveable
|
||||
{
|
||||
public:
|
||||
NonMoveable()=default;
|
||||
~NonMoveable()=default;
|
||||
NonMoveable(NonMoveable&&) =delete;
|
||||
NonMoveable& operator = (NonMoveable&&)=delete;
|
||||
};
|
||||
|
|
|
@ -215,5 +215,66 @@ SDL_RendererFlip getSDLRendererFlipFromFlipMode(FlipMode mode)
|
|||
return SDL_FLIP_NONE;
|
||||
}
|
||||
}
|
||||
|
||||
Uint32 getUint32FromSDLInitFlag(SDLInitFlag flag)
|
||||
{
|
||||
switch(flag)
|
||||
{
|
||||
case SDLInitFlag::Timer:
|
||||
return SDL_INIT_TIMER;
|
||||
case SDLInitFlag::Audio:
|
||||
return SDL_INIT_AUDIO;
|
||||
case SDLInitFlag::Video:
|
||||
return SDL_INIT_VIDEO;
|
||||
case SDLInitFlag::Joystick:
|
||||
return SDL_INIT_JOYSTICK;
|
||||
case SDLInitFlag::Haptic:
|
||||
return SDL_INIT_HAPTIC;
|
||||
case SDLInitFlag::GameController:
|
||||
return SDL_INIT_GAMECONTROLLER;
|
||||
case SDLInitFlag::Events:
|
||||
return SDL_INIT_EVENTS;
|
||||
case SDLInitFlag::All:
|
||||
return SDL_INIT_EVERYTHING;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int getIntFromIMGInitFlag(IMGInitFlag flag)
|
||||
{
|
||||
switch(flag)
|
||||
{
|
||||
case IMGInitFlag::JPG:
|
||||
return IMG_INIT_JPG;
|
||||
case IMGInitFlag::PNG:
|
||||
return IMG_INIT_PNG;
|
||||
case IMGInitFlag::TIF:
|
||||
return IMG_INIT_TIF;
|
||||
case IMGInitFlag::WEBP:
|
||||
return IMG_INIT_WEBP;
|
||||
case IMGInitFlag::ALL:
|
||||
return ( IMG_INIT_JPG | IMG_INIT_PNG | IMG_INIT_TIF | IMG_INIT_WEBP );
|
||||
}
|
||||
}
|
||||
|
||||
int getIntFromMixInitFlag(MixInitFlag flag)
|
||||
{
|
||||
switch(flag)
|
||||
{
|
||||
case MixInitFlag::FLAC:
|
||||
return MIX_INIT_FLAC;
|
||||
case MixInitFlag::MOD:
|
||||
return MIX_INIT_MOD;
|
||||
case MixInitFlag::MODPLUG:
|
||||
return MIX_INIT_MODPLUG;
|
||||
case MixInitFlag::MP3:
|
||||
return MIX_INIT_MP3;
|
||||
case MixInitFlag::OGG:
|
||||
return MIX_INIT_OGG;
|
||||
case MixInitFlag::FLUIDSYNTH:
|
||||
return MIX_INIT_FLUIDSYNTH;
|
||||
}
|
||||
}
|
||||
|
||||
}/// End of namespace _internal
|
||||
#include "end_code.h"
|
||||
|
|
|
@ -5,6 +5,9 @@
|
|||
#include "_SystemCursorType.h"
|
||||
#include "_FontStyle.h"
|
||||
#include "_FlipMode.h"
|
||||
#include "_SDLInitFlag.h"
|
||||
#include "_IMGInitFlag.h"
|
||||
#include "_MixInitFlag.h"
|
||||
#include <vector>
|
||||
#include "begin_code.h"
|
||||
namespace _internal
|
||||
|
@ -18,5 +21,8 @@ SDL_SystemCursor getSDLSystemCursorFromSystemCursorType(SystemCursorType type);
|
|||
int getTTFFontStyleFromFontStyle(FontStyle style);
|
||||
std::vector<FontStyle> getFontStyleVecFromMixedTTFFontStyle(int Mixed_TTF_Font_Style);
|
||||
SDL_RendererFlip getSDLRendererFlipFromFlipMode(FlipMode mode);
|
||||
Uint32 getUint32FromSDLInitFlag(SDLInitFlag flag);
|
||||
int getIntFromIMGInitFlag(IMGInitFlag flag);
|
||||
int getIntFromMixInitFlag(MixInitFlag flag);
|
||||
}/// End of namespace _internal
|
||||
#include "end_code.h"
|
||||
|
|
Loading…
Reference in New Issue
Block a user