mirror of https://github.com/axmolengine/axmol.git
commit some file for private use
This commit is contained in:
parent
987def2f47
commit
8dfa18efb9
|
@ -1,247 +0,0 @@
|
|||
/*
|
||||
* MyAudioOutListener.cpp
|
||||
*
|
||||
* Created on: 2011-1-21
|
||||
* Author: Administrator
|
||||
*/
|
||||
|
||||
#include "MyAudioOutListener.h"
|
||||
#include <stdio.h>
|
||||
#include "WavHead.h"
|
||||
|
||||
|
||||
using namespace Osp::Base;
|
||||
using namespace Osp::Base::Collection;
|
||||
using namespace Osp::Media;
|
||||
|
||||
#define MAX_BUFFER_SIZE 2520 // 840 byte
|
||||
|
||||
MyAudioOutEventListener::MyAudioOutEventListener()
|
||||
{
|
||||
__totalWriteBufferNum = 0;
|
||||
__playCount = 0;
|
||||
__pDataArray = null;
|
||||
__pAudioOut = null;
|
||||
__pPcmBuffer = null;
|
||||
__pcmLen = 0;
|
||||
}
|
||||
|
||||
MyAudioOutEventListener::~MyAudioOutEventListener()
|
||||
{
|
||||
AppLog("dealoc MyAudioOutEventListener");
|
||||
|
||||
if (__pDataArray != null)
|
||||
{
|
||||
__pDataArray->RemoveAll(true);
|
||||
delete __pDataArray;
|
||||
__pDataArray = null;
|
||||
}
|
||||
if (__pAudioOut != null)
|
||||
{
|
||||
__pAudioOut->Stop();
|
||||
__pAudioOut->Unprepare();
|
||||
delete __pAudioOut;
|
||||
__pAudioOut = null;
|
||||
}
|
||||
if (__pPcmBuffer != null)
|
||||
{
|
||||
delete[] __pPcmBuffer;
|
||||
__pPcmBuffer = null;
|
||||
}
|
||||
}
|
||||
|
||||
result MyAudioOutEventListener::Construct(const char* pszFilePath)
|
||||
{
|
||||
__pAudioOut = new AudioOut();
|
||||
__pAudioOut->Construct(*this);
|
||||
WAVE wavHead;
|
||||
FILE* fp = fopen(pszFilePath, "rb");
|
||||
if (fp != NULL)
|
||||
{
|
||||
if (GetWaveHeadInfo(fp, wavHead))
|
||||
{
|
||||
__pPcmBuffer = new char[wavHead.SubChunk2Size];
|
||||
__pcmLen = wavHead.SubChunk2Size;
|
||||
fread(__pPcmBuffer, __pcmLen, 1, fp);
|
||||
fclose(fp);
|
||||
}
|
||||
else
|
||||
{
|
||||
fclose(fp);
|
||||
return E_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
__pDataArray = new ArrayList();
|
||||
|
||||
// AudioOut Preparation
|
||||
AudioSampleType audioSampleType;
|
||||
AudioChannelType audioChannelType;
|
||||
int audioSampleRate = 0;
|
||||
|
||||
if (wavHead.BitsPerSample == 8)
|
||||
{
|
||||
audioSampleType = AUDIO_TYPE_PCM_U8;
|
||||
|
||||
}
|
||||
else if (wavHead.BitsPerSample == 16)
|
||||
{
|
||||
audioSampleType = AUDIO_TYPE_PCM_S16_LE;
|
||||
}
|
||||
else
|
||||
{
|
||||
audioSampleType = AUDIO_TYPE_NONE;
|
||||
}
|
||||
|
||||
if (wavHead.NumChannels == 1)
|
||||
{
|
||||
audioChannelType = AUDIO_CHANNEL_TYPE_MONO;
|
||||
}
|
||||
else if (wavHead.NumChannels == 2)
|
||||
{
|
||||
audioChannelType = AUDIO_CHANNEL_TYPE_STEREO;
|
||||
}
|
||||
else
|
||||
{
|
||||
audioChannelType = AUDIO_CHANNEL_TYPE_NONE;
|
||||
}
|
||||
|
||||
audioSampleRate = wavHead.SampleRate;
|
||||
|
||||
result r = __pAudioOut->Prepare(audioSampleType, audioChannelType, audioSampleRate);
|
||||
AppLog("The audio out prepare result is %s", GetErrorMessage(r));
|
||||
AppLogDebug("The audio out prepare result in ApplogDebug message");
|
||||
|
||||
ByteBuffer* pTotalData = null;
|
||||
pTotalData = new ByteBuffer();
|
||||
pTotalData->Construct(__pcmLen);
|
||||
pTotalData->SetArray((byte*)__pPcmBuffer, 0, __pcmLen);
|
||||
pTotalData->Flip();
|
||||
|
||||
int totalSize = pTotalData->GetLimit();
|
||||
int currentPosition = 0;
|
||||
ByteBuffer* pItem = null;
|
||||
byte givenByte;
|
||||
|
||||
// Binding data buffers into the array
|
||||
if(totalSize > MAX_BUFFER_SIZE)
|
||||
{
|
||||
do
|
||||
{
|
||||
pItem = new ByteBuffer();
|
||||
pItem->Construct(MAX_BUFFER_SIZE);
|
||||
|
||||
for(int i = 0; i < MAX_BUFFER_SIZE; i++)
|
||||
{
|
||||
// Read it per 1 byte
|
||||
pTotalData->GetByte(currentPosition++,givenByte);
|
||||
pItem->SetByte(givenByte);
|
||||
if(currentPosition == totalSize )
|
||||
break;
|
||||
}
|
||||
__pDataArray->Add(*pItem);
|
||||
|
||||
}while(currentPosition < totalSize);
|
||||
__totalWriteBufferNum = __pDataArray->GetCount();
|
||||
}
|
||||
else
|
||||
{
|
||||
pItem = new ByteBuffer();
|
||||
pItem->Construct(totalSize);
|
||||
for(int i = 0; i < totalSize; i++)
|
||||
{
|
||||
// Read it per 1 byte
|
||||
pTotalData->GetByte(i, givenByte);
|
||||
pItem->SetByte(givenByte);
|
||||
}
|
||||
__pDataArray->Add(*pItem);
|
||||
__totalWriteBufferNum = __pDataArray->GetCount();
|
||||
// non-case for now, may the size of test file is bigger than MAX size
|
||||
}
|
||||
delete pTotalData;
|
||||
pTotalData = null;
|
||||
|
||||
// Start playing until the end of the array
|
||||
// __pAudioOut->Start();
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
void MyAudioOutEventListener::play()
|
||||
{
|
||||
if (__pAudioOut->GetState() == AUDIOOUT_STATE_PLAYING)
|
||||
{
|
||||
__pAudioOut->Reset();
|
||||
}
|
||||
|
||||
ByteBuffer* pWriteBuffer = null;
|
||||
for (int i = 0; i < __totalWriteBufferNum; i++)
|
||||
{
|
||||
pWriteBuffer = static_cast<ByteBuffer*>(__pDataArray->GetAt(i));
|
||||
__pAudioOut->WriteBuffer(*pWriteBuffer);
|
||||
}
|
||||
__pAudioOut->Start();
|
||||
__playCount++;
|
||||
}
|
||||
|
||||
void MyAudioOutEventListener::stop()
|
||||
{
|
||||
__pAudioOut->Stop();
|
||||
}
|
||||
|
||||
void MyAudioOutEventListener::setVolume(int volume)
|
||||
{
|
||||
__pAudioOut->SetVolume(volume);
|
||||
}
|
||||
|
||||
/**
|
||||
* Notifies when the device has written a buffer completely.
|
||||
*
|
||||
* @param[in] src A pointer to the AudioOut instance that fired the event
|
||||
*/
|
||||
void MyAudioOutEventListener::OnAudioOutBufferEndReached(Osp::Media::AudioOut& src)
|
||||
{
|
||||
result r = E_SUCCESS;
|
||||
|
||||
if( __playCount == __totalWriteBufferNum)
|
||||
{
|
||||
// The End of array, it's time to finish
|
||||
//cjh r = src.Unprepare();
|
||||
|
||||
//Reset Variable
|
||||
__playCount = 0;
|
||||
//cjh __totalWriteBufferNum = 0;
|
||||
|
||||
}else
|
||||
{
|
||||
//Not yet reached the end of array
|
||||
//Write the next buffer
|
||||
__playCount++;
|
||||
// ByteBuffer* pWriteBuffer = static_cast<ByteBuffer*>(__pDataArray->GetAt(__playCount++));
|
||||
// r = src.WriteBuffer(*pWriteBuffer);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Notifies that the output device is being interrupted by a task of higher priority than AudioOut.
|
||||
*
|
||||
* @param[in] src A pointer to the AudioOut instance that fired the event
|
||||
*/
|
||||
void MyAudioOutEventListener::OnAudioOutInterrupted(Osp::Media::AudioOut& src)
|
||||
{
|
||||
AppLog("OnAudioOutInterrupted");
|
||||
if (__pAudioOut->GetState() == AUDIOOUT_STATE_PLAYING)
|
||||
{
|
||||
__pAudioOut->Stop();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Notifies that the interrupted output device has been released.
|
||||
*
|
||||
* @param[in] src A pointer to the AudioOut instance that fired the event
|
||||
*/
|
||||
void MyAudioOutEventListener::OnAudioOutReleased(Osp::Media::AudioOut& src)
|
||||
{
|
||||
AppLog("OnAudioOutReleased");
|
||||
}
|
|
@ -1,59 +0,0 @@
|
|||
/*
|
||||
* MyAudioOutListener.h
|
||||
*
|
||||
* Created on: 2011-1-21
|
||||
* Author: Administrator
|
||||
*/
|
||||
|
||||
#ifndef MYAUDIOOUTLISTENER_H_
|
||||
#define MYAUDIOOUTLISTENER_H_
|
||||
|
||||
#include <FBase.h>
|
||||
#include <FMedia.h>
|
||||
|
||||
|
||||
|
||||
class MyAudioOutEventListener :
|
||||
public Osp::Media::IAudioOutEventListener
|
||||
{
|
||||
|
||||
public:
|
||||
MyAudioOutEventListener();
|
||||
|
||||
virtual ~MyAudioOutEventListener();
|
||||
|
||||
result Construct(const char* pszFilePath);
|
||||
|
||||
void play();
|
||||
void stop();
|
||||
void setVolume(int volume);
|
||||
/**
|
||||
* Notifies when the device has written a buffer completely.
|
||||
*
|
||||
* @param[in] src A pointer to the AudioOut instance that fired the event
|
||||
*/
|
||||
virtual void OnAudioOutBufferEndReached(Osp::Media::AudioOut& src);
|
||||
/**
|
||||
* Notifies that the output device is being interrupted by a task of higher priority than AudioOut.
|
||||
*
|
||||
* @param[in] src A pointer to the AudioOut instance that fired the event
|
||||
*/
|
||||
virtual void OnAudioOutInterrupted(Osp::Media::AudioOut& src);
|
||||
|
||||
/**
|
||||
* Notifies that the interrupted output device has been released.
|
||||
*
|
||||
* @param[in] src A pointer to the AudioOut instance that fired the event
|
||||
*/
|
||||
virtual void OnAudioOutReleased(Osp::Media::AudioOut& src);
|
||||
|
||||
private:
|
||||
int __totalWriteBufferNum;
|
||||
int __playCount;
|
||||
Osp::Base::Collection::ArrayList* __pDataArray;
|
||||
Osp::Media::AudioOut* __pAudioOut;
|
||||
char* __pPcmBuffer;
|
||||
int __pcmLen;
|
||||
};
|
||||
|
||||
#endif /* MYAUDIOOUTLISTENER_H_ */
|
|
@ -1,6 +1,4 @@
|
|||
#include "SimpleAudioEngine.h"
|
||||
#include "MyAudioOutListener.h"
|
||||
|
||||
#include <FBase.h>
|
||||
#include <FMedia.h>
|
||||
#include <FSystem.h>
|
||||
|
@ -195,7 +193,7 @@ static bool openMediaPlayer(Player*& pPlayer, const char* pszFilePath, bool bLoo
|
|||
r = pPlayer->OpenFile(strFilePath.c_str(), false);
|
||||
if (IsFailed(r))
|
||||
{
|
||||
AppLog("Openfile fails\n");
|
||||
AppLog("Open (%s) fails\n", strFilePath.c_str());
|
||||
delete pPlayer;
|
||||
pPlayer = NULL;
|
||||
break;
|
||||
|
@ -357,6 +355,10 @@ void SimpleAudioEngine::setBackgroundMusicVolume(float volume)
|
|||
if (s_pBackPlayer)
|
||||
{
|
||||
s_pBackPlayer->SetVolume((int) (volume * 99));
|
||||
if (volume > 0.0f && s_pBackPlayer->GetVolume() == 0)
|
||||
{
|
||||
s_pBackPlayer->SetVolume(1);
|
||||
}
|
||||
}
|
||||
AppLog("volume = %f", volume);
|
||||
s_fBackgroundMusicVolume = volume;
|
||||
|
@ -394,6 +396,11 @@ unsigned int SimpleAudioEngine::playEffect(const char* pszFilePath, bool bLoop/*
|
|||
if (p != s_List.end())
|
||||
{
|
||||
p->second->SetVolume((int) (s_fEffectsVolume * 99));
|
||||
if (s_fEffectsVolume > 0.0f && p->second->GetVolume() == 0)
|
||||
{
|
||||
p->second->SetVolume(1);
|
||||
}
|
||||
|
||||
if (PLAYER_STATE_PLAYING == p->second->GetState())
|
||||
{
|
||||
r = p->second->Stop();
|
||||
|
|
|
@ -1,81 +0,0 @@
|
|||
/*
|
||||
* WaveHead.cpp
|
||||
*
|
||||
* Created on: 2011-1-21
|
||||
* Author: Administrator
|
||||
*/
|
||||
|
||||
#include "WavHead.h"
|
||||
#include <stdio.h>
|
||||
#include <FBaseSys.h>
|
||||
|
||||
bool GetWaveHeadInfo(FILE*stream, WAVE& outWavHead)
|
||||
{
|
||||
char szTmp[100] = {0};
|
||||
int i = 0;
|
||||
|
||||
// FILE *stream;
|
||||
|
||||
// if((stream = fopen(fileName,"rb"))==NULL)
|
||||
// {
|
||||
// AppLog("ERROR:can't open the file!");
|
||||
//
|
||||
// return false;
|
||||
// }
|
||||
/*
|
||||
|
||||
* 读wav文件的各个field
|
||||
|
||||
*/
|
||||
|
||||
fread(outWavHead.ChunkID, 4, 1, stream);
|
||||
|
||||
outWavHead.ChunkID[4] = (char)0;
|
||||
|
||||
fread(&(outWavHead.ChunkSize),4, 1, stream);
|
||||
|
||||
fread(outWavHead.Format, 4, 1, stream);
|
||||
|
||||
outWavHead.Format[4] = (char)0;
|
||||
|
||||
fread(outWavHead.SubChunk1ID, 4, 1, stream);
|
||||
|
||||
outWavHead.SubChunk1ID[4] = (char)0;
|
||||
|
||||
fread(&(outWavHead.SubChunk1Size), 4, 1, stream);
|
||||
|
||||
fread(&(outWavHead.AudioFormat), 2, 1, stream);
|
||||
|
||||
fread(&(outWavHead.NumChannels), 2, 1, stream);
|
||||
|
||||
fread(&(outWavHead.SampleRate), 4, 1, stream);
|
||||
|
||||
fread(&(outWavHead.ByteRate), 4, 1, stream);
|
||||
|
||||
fread(&(outWavHead.BlockAlign), 2, 1, stream);
|
||||
|
||||
fread(&(outWavHead.BitsPerSample), 2, 1, stream);
|
||||
|
||||
fseek(stream, 0, SEEK_SET);
|
||||
|
||||
|
||||
fread(szTmp, 64, 1, stream);
|
||||
|
||||
for (i = 0; i <= 60; i++)
|
||||
{
|
||||
if (szTmp[i] == 'd' && szTmp[i+1] == 'a' && szTmp[i+2] == 't' && szTmp[i+3] == 'a')
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
fseek(stream, i, SEEK_SET);
|
||||
|
||||
fread(outWavHead.SubChunk2ID, 4, 1, stream);
|
||||
|
||||
outWavHead.SubChunk2ID[4] = (char)0;
|
||||
|
||||
fread(&(outWavHead.SubChunk2Size), 4, 1, stream);
|
||||
|
||||
return true;
|
||||
}
|
|
@ -1,92 +0,0 @@
|
|||
/*
|
||||
* WavHead.h
|
||||
*
|
||||
* Created on: 2011-1-21
|
||||
* Author: Administrator
|
||||
*/
|
||||
|
||||
#ifndef WAVHEAD_H_
|
||||
#define WAVHEAD_H_
|
||||
|
||||
#include <stdio.h>
|
||||
/* WAVE文件头 */
|
||||
|
||||
typedef struct wave_tag
|
||||
|
||||
{
|
||||
|
||||
char ChunkID[5]; // "RIFF"标志
|
||||
|
||||
unsigned long int ChunkSize; // 文件长度(WAVE文件的大小, 不含前8个字节)
|
||||
|
||||
char Format[5]; // "WAVE"标志
|
||||
|
||||
|
||||
|
||||
char SubChunk1ID[5];// "fmt "标志
|
||||
|
||||
unsigned long int SubChunk1Size; /*
|
||||
|
||||
* 过渡字节(不定)
|
||||
|
||||
* 16 for PCM. This is the size of the rest of the
|
||||
|
||||
* Subchunk which follows this number.
|
||||
|
||||
*/
|
||||
|
||||
unsigned short int AudioFormat; /*
|
||||
|
||||
* 格式类别(10H为PCM格式的声音数据)
|
||||
|
||||
* PCM=1 (i.e. Linear quantization)
|
||||
|
||||
* Values other than 1 indicate some form of compression.
|
||||
|
||||
*/
|
||||
|
||||
unsigned short int NumChannels; // 通道数(单声道为1, 双声道为2)
|
||||
|
||||
//unsigned short int SampleRate; // 采样率(每秒样本数), 表示每个通道的播放速度
|
||||
|
||||
unsigned long int SampleRate; // 采样率(每秒样本数), 表示每个通道的播放速度
|
||||
|
||||
unsigned long int ByteRate; /*
|
||||
|
||||
* 波形音频数据传输速率, 其值为:通道数*每秒数据位数*每样本的数据位数/8
|
||||
|
||||
* 播放软件可以利用该值估计缓冲区大小
|
||||
|
||||
*/
|
||||
|
||||
unsigned short int BlockAlign; /*
|
||||
|
||||
* 每样本的数据位数(按字节算), 其值为:通道数*每样本的数据位值/8, 播放
|
||||
|
||||
* 软件需要一次处理多个该值大小的字节数据, 以便将其值用于缓冲区的调整
|
||||
|
||||
*/
|
||||
|
||||
unsigned short int BitsPerSample; /*
|
||||
|
||||
* 每样本的数据位数, 表示每个声道中各个样本的数据位数. 如果有多个声道,
|
||||
|
||||
* 对每个声道而言, 样本大小都一样
|
||||
|
||||
*/
|
||||
|
||||
|
||||
|
||||
char SubChunk2ID[5]; // 数据标记"data"
|
||||
|
||||
unsigned long int SubChunk2Size; // 语音数据的长度
|
||||
|
||||
} WAVE;
|
||||
|
||||
/*
|
||||
* pBuffer内部申请空间,需要由外部释放
|
||||
*/
|
||||
|
||||
bool GetWaveHeadInfo(FILE*stream, WAVE& outWavHead);
|
||||
|
||||
#endif /* WAVHEAD_H_ */
|
|
@ -78,9 +78,8 @@ public:
|
|||
/** end is key word of lua, use other name to export to lua. */
|
||||
inline void endToLua(){ end();};
|
||||
|
||||
/** ends grabbing*/
|
||||
// para bIsTOCacheTexture the parameter is only used for android to cache the texture
|
||||
void end(bool bIsTOCacheTexture = true);
|
||||
/** ends grabbing */
|
||||
void end();
|
||||
|
||||
/** clears the texture with a color */
|
||||
void clear(float r, float g, float b, float a);
|
||||
|
@ -92,8 +91,7 @@ public:
|
|||
// when nWidth = 0 and nHeight = 0, the image size to save equals to buffer texture size
|
||||
bool saveBuffer(const char *szFilePath, int x = 0, int y = 0, int nWidth = 0, int nHeight = 0);
|
||||
|
||||
/** saves the texture into a file. put format at the first argument, or ti will be overloaded with
|
||||
* saveBuffer(const char *szFilePath, int x = 0, int y = 0, int nWidth = 0, int nHeight = 0) */
|
||||
/** saves the texture into a file.
|
||||
// para name the file name to save
|
||||
// para format the image format to save, here it supports kCCImageFormatPNG and kCCImageFormatJPG */
|
||||
// para x,y the lower left corner coordinates of the buffer to save
|
||||
|
@ -114,9 +112,9 @@ public:
|
|||
protected:
|
||||
GLuint m_uFBO;
|
||||
GLint m_nOldFBO;
|
||||
CCTexture2D *m_pTexture;
|
||||
CCImage *m_pUITextureImage;
|
||||
GLenum m_ePixelFormat;
|
||||
CCTexture2D* m_pTexture;
|
||||
|
||||
GLenum m_ePixelFormat;
|
||||
};
|
||||
|
||||
} // namespace cocos2d
|
||||
|
|
|
@ -29,7 +29,6 @@ THE SOFTWARE.
|
|||
#include "platform/platform.h"
|
||||
#include "CCImage.h"
|
||||
#include "support/ccUtils.h"
|
||||
#include "CCTextureCache.h"
|
||||
#include "CCFileUtils.h"
|
||||
#include "CCGL.h"
|
||||
|
||||
|
@ -42,7 +41,6 @@ CCRenderTexture::CCRenderTexture()
|
|||
, m_nOldFBO(0)
|
||||
, m_pTexture(0)
|
||||
, m_ePixelFormat(kCCTexture2DPixelFormat_RGBA8888)
|
||||
, m_pUITextureImage(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -50,8 +48,6 @@ CCRenderTexture::~CCRenderTexture()
|
|||
{
|
||||
removeAllChildrenWithCleanup(true);
|
||||
ccglDeleteFramebuffers(1, &m_uFBO);
|
||||
|
||||
CC_SAFE_DELETE(m_pUITextureImage);
|
||||
}
|
||||
|
||||
CCSprite * CCRenderTexture::getSprite()
|
||||
|
@ -104,7 +100,7 @@ bool CCRenderTexture::initWithWidthAndHeight(int w, int h, CCTexture2DPixelForma
|
|||
w *= (int)CC_CONTENT_SCALE_FACTOR();
|
||||
h *= (int)CC_CONTENT_SCALE_FACTOR();
|
||||
|
||||
glGetIntegerv(CC_GL_FRAMEBUFFER_BINDING, &m_nOldFBO);
|
||||
glGetIntegerv(GL_FRAMEBUFFER_BINDING_OES, &m_nOldFBO);
|
||||
|
||||
// textures must be power of two squared
|
||||
unsigned int powW = ccNextPOT(w);
|
||||
|
@ -161,7 +157,7 @@ void CCRenderTexture::begin()
|
|||
// Save the current matrix
|
||||
glPushMatrix();
|
||||
|
||||
const CCSize& texSize = m_pTexture->getContentSizeInPixels();
|
||||
CCSize texSize = m_pTexture->getContentSizeInPixels();
|
||||
|
||||
// Calculate the adjustment ratios based on the old and new projections
|
||||
CCSize size = CCDirector::sharedDirector()->getDisplaySizeInPixels();
|
||||
|
@ -204,36 +200,15 @@ void CCRenderTexture::beginWithClear(float r, float g, float b, float a)
|
|||
glClearColor(clearColor[0], clearColor[1], clearColor[2], clearColor[3]);
|
||||
}
|
||||
|
||||
void CCRenderTexture::end(bool bIsTOCacheTexture)
|
||||
void CCRenderTexture::end()
|
||||
{
|
||||
ccglBindFramebuffer(CC_GL_FRAMEBUFFER, m_nOldFBO);
|
||||
// Restore the original matrix and viewport
|
||||
glPopMatrix();
|
||||
CCSize size = CCDirector::sharedDirector()->getDisplaySizeInPixels();
|
||||
// glViewport(0, 0, (GLsizei)size.width, (GLsizei)size.height);
|
||||
CCDirector::sharedDirector()->getOpenGLView()->setViewPortInPoints(0, 0, size.width, size.height);
|
||||
|
||||
#if CC_ENABLE_CACHE_TEXTTURE_DATA
|
||||
if (bIsTOCacheTexture)
|
||||
{
|
||||
CC_SAFE_DELETE(m_pUITextureImage);
|
||||
|
||||
// to get the rendered texture data
|
||||
const CCSize& s = m_pTexture->getContentSizeInPixels();
|
||||
int tx = (int)s.width;
|
||||
int ty = (int)s.height;
|
||||
m_pUITextureImage = new CCImage;
|
||||
if (true == getUIImageFromBuffer(m_pUITextureImage, 0, 0, tx, ty))
|
||||
{
|
||||
VolatileTexture::addDataTexture(m_pTexture, m_pUITextureImage->getData(), kTexture2DPixelFormat_RGBA8888, s);
|
||||
}
|
||||
else
|
||||
{
|
||||
CCLOG("Cache rendertexture failed!");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
// glViewport(0, 0, (GLsizei)size.width, (GLsizei)size.height);
|
||||
CCDirector::sharedDirector()->getOpenGLView()->setViewPortInPoints(0, 0, size.width, size.height);
|
||||
}
|
||||
|
||||
void CCRenderTexture::clear(float r, float g, float b, float a)
|
||||
{
|
||||
|
@ -264,6 +239,14 @@ bool CCRenderTexture::saveBuffer(int format, const char *fileName, int x, int y,
|
|||
if (pImage != NULL && getUIImageFromBuffer(pImage, x, y, nWidth, nHeight))
|
||||
{
|
||||
std::string fullpath = CCFileUtils::getWriteablePath() + fileName;
|
||||
if (kCCImageFormatPNG == format)
|
||||
{
|
||||
fullpath += ".png";
|
||||
}
|
||||
else
|
||||
{
|
||||
fullpath += ".jpg";
|
||||
}
|
||||
|
||||
bRet = pImage->saveToFile(fullpath.c_str());
|
||||
}
|
||||
|
@ -281,7 +264,7 @@ bool CCRenderTexture::getUIImageFromBuffer(CCImage *pImage, int x, int y, int nW
|
|||
return false;
|
||||
}
|
||||
|
||||
const CCSize& s = m_pTexture->getContentSizeInPixels();
|
||||
CCSize s = m_pTexture->getContentSizeInPixels();
|
||||
int tx = (int)s.width;
|
||||
int ty = (int)s.height;
|
||||
|
||||
|
@ -342,8 +325,8 @@ bool CCRenderTexture::getUIImageFromBuffer(CCImage *pImage, int x, int y, int nW
|
|||
this->begin();
|
||||
glPixelStorei(GL_PACK_ALIGNMENT, 1);
|
||||
glReadPixels(0,0,nReadBufferWidth,nReadBufferHeight,GL_RGBA,GL_UNSIGNED_BYTE, pTempData);
|
||||
this->end(false);
|
||||
|
||||
this->end();
|
||||
|
||||
// to get the actual texture data
|
||||
// #640 the image read from rendertexture is upseted
|
||||
for (int i = 0; i < nSavedBufferHeight; ++i)
|
||||
|
@ -380,7 +363,7 @@ CCData * CCRenderTexture::getUIImageAsDataFromBuffer(int format)
|
|||
//
|
||||
// CCAssert(m_ePixelFormat == kCCTexture2DPixelFormat_RGBA8888, "only RGBA8888 can be saved as image");
|
||||
//
|
||||
// const CCSize& s = m_pTexture->getContentSizeInPixels();
|
||||
// CCSize s = m_pTexture->getContentSizeInPixels();
|
||||
// int tx = s.width;
|
||||
// int ty = s.height;
|
||||
//
|
||||
|
|
|
@ -57,11 +57,9 @@ void CC_DLL CCMessageBox(const char * pszMsg, const char * pszTitle);
|
|||
typedef enum LanguageType
|
||||
{
|
||||
kLanguageEnglish = 0,
|
||||
kLanguageChinese,
|
||||
kLanguageFrench,
|
||||
kLanguageItalian,
|
||||
kLanguageGerman,
|
||||
kLanguageSpanish,
|
||||
kLanguageChinese_Simplified,
|
||||
kLanguageChinese_Traditional,
|
||||
kLanguageJapanese,
|
||||
} ccLanguageType;
|
||||
|
||||
NS_CC_END;
|
||||
|
|
|
@ -5,6 +5,7 @@ using namespace Osp::App;
|
|||
using namespace Osp::System;
|
||||
using namespace Osp::Base;
|
||||
using namespace Osp::Base::Runtime;
|
||||
using namespace Osp::Locales;
|
||||
|
||||
NS_CC_BEGIN;
|
||||
|
||||
|
@ -56,7 +57,27 @@ CCApplication& CCApplication::sharedApplication()
|
|||
|
||||
ccLanguageType CCApplication::getCurrentLanguage()
|
||||
{
|
||||
return kLanguageEnglish;
|
||||
ccLanguageType ret = kLanguageEnglish;
|
||||
do
|
||||
{
|
||||
result r = E_SUCCESS;
|
||||
String value;
|
||||
r = SettingInfo::GetValue(L"Language", value);
|
||||
if (value.Equals("ZHO", false))
|
||||
{
|
||||
r = SettingInfo::GetValue(L"Country", value);
|
||||
if (value.Equals("HK", false) || value.Equals("TW", false))
|
||||
{
|
||||
ret = kLanguageChinese_Traditional;
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = kLanguageChinese_Simplified;
|
||||
}
|
||||
}
|
||||
} while (0);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void CCApplication::setAnimationInterval(double interval)
|
||||
|
|
|
@ -315,6 +315,14 @@ void CCEGLView::setIMEKeyboardState(bool bOpen)
|
|||
{
|
||||
}
|
||||
|
||||
void CCEGLView::getScreenRectInView(CCRect& rect)
|
||||
{
|
||||
rect.origin.x = -m_rcViewPort.origin.x / m_fScreenScaleFactor;
|
||||
rect.origin.y = -m_rcViewPort.origin.y / m_fScreenScaleFactor;
|
||||
rect.size.width = m_sSizeInPixel.width / m_fScreenScaleFactor;
|
||||
rect.size.height = m_sSizeInPixel.height / m_fScreenScaleFactor;
|
||||
}
|
||||
|
||||
bool CCEGLView::Create(Osp::App::Application* pApp, int width, int height)
|
||||
{
|
||||
m_sSizeInPoint.width = MIN(width, height);
|
||||
|
|
|
@ -62,6 +62,9 @@ public:
|
|||
void setScissorInPoints(float x, float y, float w, float h);
|
||||
|
||||
void setIMEKeyboardState(bool bOpen);
|
||||
|
||||
void getScreenRectInView(CCRect& rect);
|
||||
|
||||
// static function
|
||||
/**
|
||||
@brief get the shared main open gl window
|
||||
|
|
|
@ -134,15 +134,32 @@ ccLanguageType CCApplication::getCurrentLanguage()
|
|||
LCID LanguageID = GetUserDefaultLCID();
|
||||
ccLanguageType ret = kLanguageEnglish;
|
||||
|
||||
int nCount = sizeof(arrayChineseCode) / sizeof(int);
|
||||
for (int i = 0; i < nCount; ++i)
|
||||
do
|
||||
{
|
||||
if (arrayChineseCode[i] == LanguageID)
|
||||
int nCount = sizeof(arrayChineseCode) / sizeof(int);
|
||||
for (int i = 0; i < nCount; ++i)
|
||||
{
|
||||
ret = kLanguageChinese;
|
||||
break;
|
||||
if (arrayChineseCode[i] == LanguageID)
|
||||
{
|
||||
if (LanguageID == 2052)
|
||||
{
|
||||
ret = kLanguageChinese_Simplified;
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = kLanguageChinese_Traditional;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CC_BREAK_IF(kLanguageEnglish != ret);
|
||||
|
||||
if (1041 == LanguageID)
|
||||
{
|
||||
ret = kLanguageJapanese;
|
||||
}
|
||||
} while (0);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
|
|
@ -34,7 +34,6 @@ THE SOFTWARE.
|
|||
#include "CCTouchDispatcher.h"
|
||||
#include "CCIMEDispatcher.h"
|
||||
#include "CCKeypadDispatcher.h"
|
||||
#include "CCApplication.h"
|
||||
|
||||
NS_CC_BEGIN;
|
||||
|
||||
|
@ -235,7 +234,7 @@ bool CCEGLView::Create(LPCTSTR pTitle, int w, int h)
|
|||
WS_EX_APPWINDOW | WS_EX_WINDOWEDGE, // Extended Style For The Window
|
||||
kWindowClassName, // Class Name
|
||||
pTitle, // Window Title
|
||||
WS_CAPTION | WS_POPUPWINDOW | WS_MINIMIZEBOX, // Defined Window Style
|
||||
WS_CAPTION | WS_POPUPWINDOW, // Defined Window Style
|
||||
0, 0, // Window Position
|
||||
0, // Window Width
|
||||
0, // Window Height
|
||||
|
@ -312,24 +311,7 @@ LRESULT CCEGLView::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
|
|||
m_bCaptured = false;
|
||||
}
|
||||
break;
|
||||
case WM_SIZE:
|
||||
switch (wParam)
|
||||
{
|
||||
case SIZE_RESTORED:
|
||||
CCApplication::sharedApplication().applicationWillEnterForeground();
|
||||
break;
|
||||
case SIZE_MINIMIZED:
|
||||
CCApplication::sharedApplication().applicationDidEnterBackground();
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case WM_KEYDOWN:
|
||||
if (wParam == VK_F1 || wParam == VK_F2)
|
||||
{
|
||||
if (GetKeyState(VK_LSHIFT) < 0 || GetKeyState(VK_RSHIFT) < 0 || GetKeyState(VK_SHIFT) < 0)
|
||||
CCKeypadDispatcher::sharedDispatcher()->dispatchKeypadMSG(wParam == VK_F1 ? kTypeBackClicked : kTypeMenuClicked);
|
||||
}
|
||||
break;
|
||||
|
||||
case WM_CHAR:
|
||||
{
|
||||
if (wParam < 0x20)
|
||||
|
@ -372,7 +354,8 @@ LRESULT CCEGLView::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
|
|||
break;
|
||||
|
||||
case WM_CLOSE:
|
||||
CCDirector::sharedDirector()->end();
|
||||
CCKeypadDispatcher::sharedDispatcher()->dispatchKeypadMSG(kTypeBackClicked);
|
||||
// CCDirector::sharedDirector()->end();
|
||||
break;
|
||||
|
||||
case WM_DESTROY:
|
||||
|
@ -479,6 +462,19 @@ void CCEGLView::setIMEKeyboardState(bool /*bOpen*/)
|
|||
{
|
||||
}
|
||||
|
||||
void CCEGLView::getScreenRectInView(CCRect& rect)
|
||||
{
|
||||
RECT rcClient;
|
||||
GetClientRect(m_hWnd, &rcClient);
|
||||
RECT rcScreenRectInView = {0};
|
||||
IntersectRect(&rcScreenRectInView, &rcClient, &m_rcViewPort);
|
||||
|
||||
rect.origin.x = float(- m_rcViewPort.left) / m_fScreenScaleFactor;
|
||||
rect.origin.y = float((m_rcViewPort.bottom - m_rcViewPort.top) - (rcScreenRectInView.bottom - m_rcViewPort.top)) / m_fScreenScaleFactor;
|
||||
rect.size.width = float(rcScreenRectInView.right - rcScreenRectInView.left) / m_fScreenScaleFactor;
|
||||
rect.size.height = float(rcScreenRectInView.bottom - rcScreenRectInView.top) / m_fScreenScaleFactor;
|
||||
}
|
||||
|
||||
HWND CCEGLView::getHWnd()
|
||||
{
|
||||
return m_hWnd;
|
||||
|
|
|
@ -62,6 +62,8 @@ public:
|
|||
|
||||
void setIMEKeyboardState(bool bOpen);
|
||||
|
||||
void getScreenRectInView(CCRect& rect);
|
||||
|
||||
// win32 platform function
|
||||
HWND getHWnd();
|
||||
void resize(int width, int height);
|
||||
|
|
Loading…
Reference in New Issue