锘??xml version="1.0" encoding="utf-8" standalone="yes"?>
//Long Fei ( lf426 ), E-mail: zbln426@163.com
//Laboratory of ZaiBieLiunNian
//http://m.shnenglu.com/lf426/
//FileName: MixSoundClass.hpp
#ifndef MIX_SOUND_CLASS_HPP
#define MIX_SOUND_CLASS_HPP
#include <iostream>
#include <string>
#include "SDL/SDL.h"
#include "SDL/SDL_mixer.h"
class BaseMixSound
{
private:
static int MixNUM;
protected:
BaseMixSound();
public:
virtual ~BaseMixSound();
};
class EffectSound: public BaseMixSound
{
private:
Mix_Chunk* sound;
public:
EffectSound(const std::string& sound_fileName);
~EffectSound();
void play() const;
};
class MusicSound: public BaseMixSound
{
private:
Mix_Music* music;
public:
MusicSound(const std::string& music_fileName);
~MusicSound();
void play() const;
void stop() const;
};
#endif
//Long Fei ( lf426 ), E-mail: zbln426@163.com
//Laboratory of ZaiBieLiunNian
//http://m.shnenglu.com/lf426/
#include "MixSoundClass.hpp"
//*******************************
//class BaseMixSound
int BaseMixSound::MixNUM = 0;
BaseMixSound::BaseMixSound()
{
if ( MixNUM == 0 ){
if( Mix_OpenAudio( 22050, MIX_DEFAULT_FORMAT, 2, 4096 ) == -1 ){
std::cerr << "Mix_Open ERROR" << std::endl;
exit(-1);
}
}
MixNUM++;
}
BaseMixSound::~BaseMixSound()
{
MixNUM--;
if ( MixNUM == 0 ){
Mix_CloseAudio();
}
}
//*******************************
//*******************************
//class EffectSound
EffectSound::EffectSound(const std::string& sound_fileName)
{
sound = Mix_LoadWAV(sound_fileName.c_str());
if ( sound == 0 ){
std::cerr << sound_fileName << " : load failed!" << std::endl;
}
}
EffectSound::~EffectSound()
{
Mix_FreeChunk(sound);
}
void EffectSound::play() const
{
if( Mix_PlayChannel(-1, sound, 0) == -1 ){
std::cerr << "Mix_PlayChannel() ERROR" << std::endl;
}
}
//*******************************
//*******************************
//class MusicSound
MusicSound::MusicSound(const std::string& music_fileName)
{
music = Mix_LoadMUS(music_fileName.c_str());
if ( music == 0 ){
std::cerr << music_fileName << " : load failed!" << std::endl;
}
}
MusicSound::~MusicSound()
{
Mix_FreeMusic(music);
}
void MusicSound::play() const
{
if( Mix_PlayingMusic() == false ){
if( Mix_PlayMusic( music, -1 ) == -1 ){
std::cerr << "Mix_PlayMusic() ERROR" << std::endl;
}
} else {
if( Mix_PausedMusic() == 1) {
Mix_ResumeMusic();
}
else {
Mix_PauseMusic();
}
}
}
void MusicSound::stop() const
{
Mix_HaltMusic();
}
//***************************************
lib: SDL.lib, SDLmain.lib
SDL_mixer.lib
dll: SDL.dll
libogg-0.dll, libvorbis-0.dll, libvorbisfile-3.dll, SDL_mixer.dll, smpeg.dll
last update: 2008-04-20
]]>
]]>
#define STRING_DATA_HPP
#include <clocale>
#include <string>
#include <vector>
#include "GNU/libintl.h"
class StringData
{
private:
std::vector<std::string> data;
public:
StringData(const std::string& type);
std::string operator [](const unsigned int& n) const;
};
#endif
StringData::StringData(const std::string& type)
{
setlocale(LC_ALL, "");
bindtextdomain("StringData", "./po");
textdomain("StringData");
if ( type == "type1" ){
//0,
data.push_back(gettext(" "));
//1
data.push_back(gettext(" "));
//
}
else if ( type == "type2" ){
//0, other
data.push_back(gettext(" "));
//1
data.push_back(gettext(" "));
//
}
else if ( type == "type3" ){
//0
data.push_back(gettext(" "));
//1
data.push_back(gettext(" "));
//
else {
//0
data.push_back(gettext("NULL"));
}
}
std::string StringData::operator [](const unsigned int& n) const
{
if ( n >= data.size() )
return 0;
return data[n];
}
lib: libintl.lib
dll: libiconv2.dll, libintl3.dll
last update: 2008-04-14
]]>
]]>
//Long Fei ( lf426 ), E-mail: zbln426@163.com
//Laboratory of ZaiBieLiunNian
//http://m.shnenglu.com/lf426/
//FileName: SDL_render_Chinese.h
//For Windows only
#ifndef RENDER_CHINESE_H
#define RENDER_CHINESE_H
#include "gb2312_to_Unicode.h"
#include "SDL/SDL_ttf.h"
SDL_Surface* myTTF_RenderString_Blended(TTF_Font* font, const std::string& str, SDL_Color fg);
SDL_Surface* myTTF_RenderString_Solid(TTF_Font* font, const std::string& str, SDL_Color fg);
SDL_Surface* myTTF_RenderString_Shaded(TTF_Font* font, const std::string& str, SDL_Color fg, SDL_Color bg);
#endif
//Long Fei ( lf426 ), E-mail: zbln426@163.com
//Laboratory of ZaiBieLiunNian
//http://m.shnenglu.com/lf426/
//FileName: SDL_render_Chinese.cpp
//For Windows only
#include "SDL_render_Chinese.h"
SDL_Surface* myTTF_RenderString_Blended(TTF_Font* font, const std::string& str, SDL_Color fg)
{
SDL_Surface* textbuf;
//Get Unicode
std::vector<Uint16> unicodeUnit;
if ( getUnicode(str, unicodeUnit) == false )
return 0;
int arraySize = unicodeUnit.size();
Uint16* perOne = new Uint16[arraySize+1];
for ( int i = 0; i < arraySize; i++ )
perOne[i] = unicodeUnit[i];
perOne[arraySize] = 0;
//Render the new text
textbuf = TTF_RenderUNICODE_Blended(font, perOne, fg);
//Free the text buffer and return
delete [] perOne;
return textbuf;
}
SDL_Surface* myTTF_RenderString_Solid(TTF_Font* font, const std::string& str, SDL_Color fg)
{
SDL_Surface* textbuf;
//Get Unicode
std::vector<Uint16> unicodeUnit;
if ( getUnicode(str, unicodeUnit) == false )
return 0;
int arraySize = unicodeUnit.size();
Uint16* perOne = new Uint16[arraySize+1];
for ( int i = 0; i < arraySize; i++ )
perOne[i] = unicodeUnit[i];
perOne[arraySize] = 0;
//Render the new text
textbuf = TTF_RenderUNICODE_Solid(font, perOne, fg);
//Free the text buffer and return
delete [] perOne;
return textbuf;
}
SDL_Surface* myTTF_RenderString_Shaded(TTF_Font* font, const std::string& str, SDL_Color fg, SDL_Color bg)
{
SDL_Surface* textbuf;
//Get Unicode
std::vector<Uint16> unicodeUnit;
if ( getUnicode(str, unicodeUnit) == false )
return 0;
int arraySize = unicodeUnit.size();
Uint16* perOne = new Uint16[arraySize+1];
for ( int i = 0; i < arraySize; i++ )
perOne[i] = unicodeUnit[i];
perOne[arraySize] = 0;
//Render the new text
textbuf = TTF_RenderUNICODE_Shaded(font, perOne, fg, bg);
//Free the text buffer and return
delete [] perOne;
return textbuf;
}
lib: iconv.lib
SDL_ttf.lib
SDL.lib, SDLmain.lib
dll: iconv.dll
SDL_ttf.dll, libfreetype-6.dll, zlib1.dll
SDL.dll
last update: 2008-05-12
]]>
//Long Fei ( lf426 ), E-mail: zbln426@163.com
//Laboratory of ZaiBieLiunNian
//http://m.shnenglu.com/lf426/
//FileName: gb2312_to_Unicode.h
//For Windows only
#ifndef GB2312_TO_UNICODE_H_
#define GB2312_TO_UNICODE_H_
#include <iostream>
#include <vector>
#include "GNU/iconv.h"
//if not include "SDL/SDL.h"
#ifndef _SDL_H
typedef unsigned short int Uint16;
#endif
bool getUnicode(const std::string& str, std::vector<Uint16>& unicodeVectorArray);
#endif
//Long Fei ( lf426 ), E-mail: zbln426@163.com
//Laboratory of ZaiBieLiunNian
//http://m.shnenglu.com/lf426/
//FileName: gb2312_to_Unicode.cpp
//For Windows only
#include "gb2312_to_Unicode.h"
int myUTF8_to_UNICODE(Uint16* unicode, unsigned char* utf8, int len);
bool getUnicode(const std::string& str, std::vector<Uint16>& unicodeVectorArray)
{
const int CHAR_SIZE = 256;
//GB2312 src
const unsigned char* src = (const unsigned char*)(str.c_str());
size_t src_len = strlen((char*)src);
//Unicode dst to get
unsigned char dst[CHAR_SIZE] = {0};
size_t dst_len = sizeof(dst);
//iconv arg
const unsigned char* in = src;
unsigned char* out = dst;
iconv_t cd;
//GB2312 to UTF-8
cd = iconv_open("UTF-8", "GB2312");
if ((iconv_t)-1 == cd){
return false;
}
//conversion
iconv(cd, (const char**)&in, &src_len, (char**)&out, &dst_len);
//UTF-8 to Unicode
int utf8Len = strlen((char*)dst);
Uint16 unicodeData[CHAR_SIZE] = {0};
int unicodeLen = myUTF8_to_UNICODE(unicodeData, dst, utf8Len);
for (int i = 0; i < unicodeLen; i++) {
unicodeVectorArray.push_back(unicodeData[i]);
}
iconv_close(cd);
return true;
}
int myUTF8_to_UNICODE(Uint16* unicode, unsigned char* utf8, int len)
{
int length;
unsigned char* t = utf8;
length = 0;
while (utf8 - t < len){
//one byte.ASCII as a, b, c, 1, 2, 3
ect
if ( *(unsigned char *) utf8 <= 0x7f ) {
//expand with 0s.
*unicode++ = *utf8++;
}
//2 byte.
else if ( *(unsigned char *) utf8 <= 0xdf ) {
*unicode++ = ((*(unsigned char *) utf8 & 0x1f) << 6) + ((*(unsigned char *) (utf8 + 1)) & 0x3f);
utf8 += 2;
}
//3 byte.Chinese may use 3 byte.
else {
*unicode++ = ((int) (*(unsigned char *) utf8 & 0x0f) << 12) +
((*(unsigned char *) (utf8 + 1) & 0x3f) << 6) +
(*(unsigned char *) (utf8 + 2) & 0x3f);
utf8 += 3;
}
length++;
}
*unicode = 0;
return (length);
}
lib: iconv.lib
dll: iconv.dll
last update: 2008-05-12
]]>