*Fixed compile error
*Converted every 4 spaces to a tab to make the source consistent on those
This commit is contained in:
parent
8a21f92f0b
commit
973d8b2005
16
HBC/META.XML
16
HBC/META.XML
|
@ -2,14 +2,14 @@
|
|||
<app version="1">
|
||||
<name> USB Loader GX</name>
|
||||
<coder>USB Loader GX Team</coder>
|
||||
<version>2.2 r1103</version>
|
||||
<release_date>201107241629</release_date>
|
||||
<!-- // remove this line to enable arguments
|
||||
<arguments>
|
||||
<arg>--ios=250</arg>
|
||||
<arg>--usbport=0</arg>
|
||||
</arguments>
|
||||
// remove this line to enable arguments -->
|
||||
<version>2.2 r1105</version>
|
||||
<release_date>201107252212</release_date>
|
||||
<!-- // remove this line to enable arguments
|
||||
<arguments>
|
||||
<arg>--ios=250</arg>
|
||||
<arg>--usbport=0</arg>
|
||||
</arguments>
|
||||
// remove this line to enable arguments -->
|
||||
<no_ios_reload/>
|
||||
<short_description>Loads games from USB-devices</short_description>
|
||||
<long_description>USB Loader GX is a libwiigui based USB iso loader with a wii-like GUI. You can install games to your HDDs and boot them with shorter loading times.
|
||||
|
|
20
filelist.sh
20
filelist.sh
|
@ -9,8 +9,8 @@ count_old=$(cat $outFile 2>/dev/null | tr -d '\n\n' | sed 's/[^0-9]*\([0-9]*\).*
|
|||
count=0
|
||||
for i in $(find ./data/images/ ./data/sounds/ ./data/fonts/ -maxdepth 1 -type f \( ! -printf "%f\n" \))
|
||||
do
|
||||
files[count]=$i
|
||||
count=$((count+1))
|
||||
files[count]=$i
|
||||
count=$((count+1))
|
||||
done
|
||||
|
||||
if [ "$count_old" != "$count" ] || [ ! -f $outFile ]
|
||||
|
@ -35,11 +35,11 @@ EOF
|
|||
|
||||
for i in ${files[@]}
|
||||
do
|
||||
filename=${i%.*}
|
||||
extension=${i##*.}
|
||||
echo 'extern const u8 '$filename'_'$extension'[];' >> $outFile
|
||||
echo 'extern const u32 '$filename'_'$extension'_size;' >> $outFile
|
||||
echo '' >> $outFile
|
||||
filename=${i%.*}
|
||||
extension=${i##*.}
|
||||
echo 'extern const u8 '$filename'_'$extension'[];' >> $outFile
|
||||
echo 'extern const u32 '$filename'_'$extension'_size;' >> $outFile
|
||||
echo '' >> $outFile
|
||||
done
|
||||
|
||||
echo 'RecourceFile Resources::RecourceFiles[] =' >> $outFile
|
||||
|
@ -47,9 +47,9 @@ echo '{' >> $outFile
|
|||
|
||||
for i in ${files[@]}
|
||||
do
|
||||
filename=${i%.*}
|
||||
extension=${i##*.}
|
||||
echo -e '\t{"'$i'", '$filename'_'$extension', '$filename'_'$extension'_size, NULL, 0},' >> $outFile
|
||||
filename=${i%.*}
|
||||
extension=${i##*.}
|
||||
echo -e '\t{"'$i'", '$filename'_'$extension', '$filename'_'$extension'_size, NULL, 0},' >> $outFile
|
||||
done
|
||||
|
||||
echo -e '\t{NULL, NULL, 0, NULL, 0}' >> $outFile
|
||||
|
|
|
@ -29,361 +29,361 @@
|
|||
extern GuiImageData * pointer[4];
|
||||
|
||||
BoxCover::BoxCover(GuiImageData * img, bool flat)
|
||||
: GuiImage(img),
|
||||
boxBorder(Resources::GetFile("boxBorder.png"), Resources::GetFileSize("boxBorder.png")),
|
||||
defaultBox(NULL)
|
||||
: GuiImage(img),
|
||||
boxBorder(Resources::GetFile("boxBorder.png"), Resources::GetFileSize("boxBorder.png")),
|
||||
defaultBox(NULL)
|
||||
{
|
||||
flatCover = flat;
|
||||
Zoomable = false;
|
||||
moveChan = -1;
|
||||
moveStartPosX = 0;
|
||||
moveStartPosY = 0;
|
||||
movePosX = 0.0f;
|
||||
movePosY = 0.0f;
|
||||
RotX = 0.0f;
|
||||
RotY = 0.0f;
|
||||
RotZ = 0.0f;
|
||||
PosX = 0.0f;
|
||||
PosY = 0.0f;
|
||||
PosZ = -27.f;
|
||||
AnimRotate = 0.0f;
|
||||
last_manual_move_frame = 0;
|
||||
guVector camera = (guVector) {0.0F, 0.0F, 0.0F};
|
||||
guVector up = (guVector) {0.0F, 1.0F, 0.0F};
|
||||
guVector look = (guVector) {0.0F, 0.0F, -1.0F};
|
||||
boxColor = (GXColor) {233, 233, 233, 255};
|
||||
flatCover = flat;
|
||||
Zoomable = false;
|
||||
moveChan = -1;
|
||||
moveStartPosX = 0;
|
||||
moveStartPosY = 0;
|
||||
movePosX = 0.0f;
|
||||
movePosY = 0.0f;
|
||||
RotX = 0.0f;
|
||||
RotY = 0.0f;
|
||||
RotZ = 0.0f;
|
||||
PosX = 0.0f;
|
||||
PosY = 0.0f;
|
||||
PosZ = -27.f;
|
||||
AnimRotate = 0.0f;
|
||||
last_manual_move_frame = 0;
|
||||
guVector camera = (guVector) {0.0F, 0.0F, 0.0F};
|
||||
guVector up = (guVector) {0.0F, 1.0F, 0.0F};
|
||||
guVector look = (guVector) {0.0F, 0.0F, -1.0F};
|
||||
boxColor = (GXColor) {233, 233, 233, 255};
|
||||
|
||||
guLookAt(view, &camera, &up, &look);
|
||||
guPerspective(projection, 8, 640.f/480.f, 1.0f, 300.0F);
|
||||
guLookAt(view, &camera, &up, &look);
|
||||
guPerspective(projection, 8, 640.f/480.f, 1.0f, 300.0F);
|
||||
|
||||
//! Remove me later
|
||||
for(int i = 0; i < 4; ++i)
|
||||
{
|
||||
char name[50];
|
||||
snprintf(name, sizeof(name), "player%i_grab.png", i+1);
|
||||
GrabPointers[i] = Resources::GetImageData(name);
|
||||
NormalPointers[i] = pointer[i];
|
||||
}
|
||||
//! Remove me later
|
||||
for(int i = 0; i < 4; ++i)
|
||||
{
|
||||
char name[50];
|
||||
snprintf(name, sizeof(name), "player%i_grab.png", i+1);
|
||||
GrabPointers[i] = Resources::GetImageData(name);
|
||||
NormalPointers[i] = pointer[i];
|
||||
}
|
||||
|
||||
if(flatCover || !image)
|
||||
{
|
||||
defaultBox = Resources::GetImageData("nocoverFull.png");
|
||||
GX_InitTexObj(&defaultBoxTex, defaultBox->GetImage(), defaultBox->GetWidth(), defaultBox->GetHeight(), defaultBox->GetTextureFormat(),GX_CLAMP, GX_CLAMP,GX_FALSE);
|
||||
}
|
||||
if(flatCover || !image)
|
||||
{
|
||||
defaultBox = Resources::GetImageData("nocoverFull.png");
|
||||
GX_InitTexObj(&defaultBoxTex, defaultBox->GetImage(), defaultBox->GetWidth(), defaultBox->GetHeight(), defaultBox->GetTextureFormat(),GX_CLAMP, GX_CLAMP,GX_FALSE);
|
||||
}
|
||||
|
||||
if(!image)
|
||||
{
|
||||
GX_InitTexObj(&coverTex, defaultBox->GetImage(), defaultBox->GetWidth(), defaultBox->GetHeight(), defaultBox->GetTextureFormat(),GX_CLAMP, GX_CLAMP,GX_FALSE);
|
||||
flatCover = false;
|
||||
}
|
||||
else
|
||||
GX_InitTexObj(&coverTex, image, width,height, GX_TF_RGBA8,GX_CLAMP, GX_CLAMP,GX_FALSE);
|
||||
if(!image)
|
||||
{
|
||||
GX_InitTexObj(&coverTex, defaultBox->GetImage(), defaultBox->GetWidth(), defaultBox->GetHeight(), defaultBox->GetTextureFormat(),GX_CLAMP, GX_CLAMP,GX_FALSE);
|
||||
flatCover = false;
|
||||
}
|
||||
else
|
||||
GX_InitTexObj(&coverTex, image, width,height, GX_TF_RGBA8,GX_CLAMP, GX_CLAMP,GX_FALSE);
|
||||
|
||||
GX_InitTexObj(&boxBorderTex, boxBorder.GetImage(), boxBorder.GetWidth(), boxBorder.GetHeight(), boxBorder.GetTextureFormat(),GX_CLAMP, GX_CLAMP,GX_FALSE);
|
||||
GX_InitTexObj(&boxBorderTex, boxBorder.GetImage(), boxBorder.GetWidth(), boxBorder.GetHeight(), boxBorder.GetTextureFormat(),GX_CLAMP, GX_CLAMP,GX_FALSE);
|
||||
}
|
||||
|
||||
BoxCover::~BoxCover()
|
||||
{
|
||||
delete defaultBox;
|
||||
for(int i = 0; i < 4; ++i)
|
||||
{
|
||||
pointer[i] = NormalPointers[i];
|
||||
delete GrabPointers[i];
|
||||
}
|
||||
delete defaultBox;
|
||||
for(int i = 0; i < 4; ++i)
|
||||
{
|
||||
pointer[i] = NormalPointers[i];
|
||||
delete GrabPointers[i];
|
||||
}
|
||||
}
|
||||
|
||||
//! Remove me later
|
||||
void BoxCover::WiiPADControl(GuiTrigger *t)
|
||||
{
|
||||
if(t->wpad.btns_d & WPAD_BUTTON_A)
|
||||
{
|
||||
if(t->wpad.ir.valid)
|
||||
{
|
||||
moveChan = t->chan;
|
||||
moveStartPosX = t->wpad.ir.x;
|
||||
moveStartPosY = t->wpad.ir.y;
|
||||
PosX += movePosX;
|
||||
PosY += movePosY;
|
||||
movePosX = 0.0f;
|
||||
movePosY = 0.0f;
|
||||
for(int i = 0; i < 4; ++i)
|
||||
pointer[i] = GrabPointers[i];
|
||||
}
|
||||
else
|
||||
moveChan = -1;
|
||||
}
|
||||
else if((t->wpad.btns_h & WPAD_BUTTON_A) && moveChan == t->chan && t->wpad.ir.valid && !effects)
|
||||
{
|
||||
movePosX = (t->wpad.ir.x-moveStartPosX) * fabs(PosZ)/3400.f;
|
||||
movePosY = (moveStartPosY-t->wpad.ir.y) * fabs(PosZ)/3400.f;
|
||||
last_manual_move_frame = frameCount;
|
||||
}
|
||||
else if(!(t->wpad.btns_h & WPAD_BUTTON_A) && moveChan == t->chan)
|
||||
{
|
||||
for(int i = 0; i < 4; ++i)
|
||||
pointer[i] = NormalPointers[i];
|
||||
}
|
||||
if(t->wpad.btns_d & WPAD_BUTTON_A)
|
||||
{
|
||||
if(t->wpad.ir.valid)
|
||||
{
|
||||
moveChan = t->chan;
|
||||
moveStartPosX = t->wpad.ir.x;
|
||||
moveStartPosY = t->wpad.ir.y;
|
||||
PosX += movePosX;
|
||||
PosY += movePosY;
|
||||
movePosX = 0.0f;
|
||||
movePosY = 0.0f;
|
||||
for(int i = 0; i < 4; ++i)
|
||||
pointer[i] = GrabPointers[i];
|
||||
}
|
||||
else
|
||||
moveChan = -1;
|
||||
}
|
||||
else if((t->wpad.btns_h & WPAD_BUTTON_A) && moveChan == t->chan && t->wpad.ir.valid && !effects)
|
||||
{
|
||||
movePosX = (t->wpad.ir.x-moveStartPosX) * fabs(PosZ)/3400.f;
|
||||
movePosY = (moveStartPosY-t->wpad.ir.y) * fabs(PosZ)/3400.f;
|
||||
last_manual_move_frame = frameCount;
|
||||
}
|
||||
else if(!(t->wpad.btns_h & WPAD_BUTTON_A) && moveChan == t->chan)
|
||||
{
|
||||
for(int i = 0; i < 4; ++i)
|
||||
pointer[i] = NormalPointers[i];
|
||||
}
|
||||
|
||||
if(t->wpad.btns_h & WPAD_BUTTON_UP)
|
||||
{
|
||||
RotX -= 2.0f;
|
||||
last_manual_move_frame = frameCount;
|
||||
}
|
||||
if(t->wpad.btns_h & WPAD_BUTTON_DOWN)
|
||||
{
|
||||
RotX += 2.0f;
|
||||
last_manual_move_frame = frameCount;
|
||||
}
|
||||
if(t->wpad.btns_h & WPAD_BUTTON_LEFT)
|
||||
{
|
||||
RotY -= 2.0f;
|
||||
last_manual_move_frame = frameCount;
|
||||
}
|
||||
if(t->wpad.btns_h & WPAD_BUTTON_RIGHT)
|
||||
{
|
||||
RotY += 2.0f;
|
||||
last_manual_move_frame = frameCount;
|
||||
}
|
||||
if(t->wpad.btns_d & WPAD_BUTTON_2)
|
||||
{
|
||||
if(RotY < 180.0f)
|
||||
SetEffect(EFFECT_BOX_ROTATE_X, 10, 180);
|
||||
else
|
||||
SetEffect(EFFECT_BOX_ROTATE_X, -10, -180);
|
||||
last_manual_move_frame = frameCount;
|
||||
}
|
||||
if(t->wpad.btns_h & WPAD_BUTTON_PLUS)
|
||||
{
|
||||
if(PosZ < -2.8f)
|
||||
PosZ += 0.4f*fabs(PosZ)/19.f;
|
||||
}
|
||||
if(t->wpad.btns_h & WPAD_BUTTON_MINUS)
|
||||
{
|
||||
if(PosZ > -43.0f)
|
||||
PosZ -= 0.4f*fabs(PosZ)/19.f;
|
||||
}
|
||||
if(t->wpad.btns_h & WPAD_BUTTON_UP)
|
||||
{
|
||||
RotX -= 2.0f;
|
||||
last_manual_move_frame = frameCount;
|
||||
}
|
||||
if(t->wpad.btns_h & WPAD_BUTTON_DOWN)
|
||||
{
|
||||
RotX += 2.0f;
|
||||
last_manual_move_frame = frameCount;
|
||||
}
|
||||
if(t->wpad.btns_h & WPAD_BUTTON_LEFT)
|
||||
{
|
||||
RotY -= 2.0f;
|
||||
last_manual_move_frame = frameCount;
|
||||
}
|
||||
if(t->wpad.btns_h & WPAD_BUTTON_RIGHT)
|
||||
{
|
||||
RotY += 2.0f;
|
||||
last_manual_move_frame = frameCount;
|
||||
}
|
||||
if(t->wpad.btns_d & WPAD_BUTTON_2)
|
||||
{
|
||||
if(RotY < 180.0f)
|
||||
SetEffect(EFFECT_BOX_ROTATE_X, 10, 180);
|
||||
else
|
||||
SetEffect(EFFECT_BOX_ROTATE_X, -10, -180);
|
||||
last_manual_move_frame = frameCount;
|
||||
}
|
||||
if(t->wpad.btns_h & WPAD_BUTTON_PLUS)
|
||||
{
|
||||
if(PosZ < -2.8f)
|
||||
PosZ += 0.4f*fabs(PosZ)/19.f;
|
||||
}
|
||||
if(t->wpad.btns_h & WPAD_BUTTON_MINUS)
|
||||
{
|
||||
if(PosZ > -43.0f)
|
||||
PosZ -= 0.4f*fabs(PosZ)/19.f;
|
||||
}
|
||||
}
|
||||
|
||||
void BoxCover::Update(GuiTrigger * t)
|
||||
{
|
||||
s8 movY = t->WPAD_Stick(0, 0) ;
|
||||
s8 movX = t->WPAD_Stick(0, 1);
|
||||
//! Drop nunchuck moves of less than 5 because of sensitivity
|
||||
if(fabs(movY) < 5.0f) movY = 0;
|
||||
if(fabs(movX) < 5.0f) movX = 0;
|
||||
s8 movY = t->WPAD_Stick(0, 0) ;
|
||||
s8 movX = t->WPAD_Stick(0, 1);
|
||||
//! Drop nunchuck moves of less than 5 because of sensitivity
|
||||
if(fabs(movY) < 5.0f) movY = 0;
|
||||
if(fabs(movX) < 5.0f) movX = 0;
|
||||
|
||||
if(movY != 0 || movX != 0)
|
||||
last_manual_move_frame = frameCount;
|
||||
if(movY != 0 || movX != 0)
|
||||
last_manual_move_frame = frameCount;
|
||||
|
||||
RotY += (f32) movY / 50.0f;
|
||||
RotX -= (f32) movX / 50.0f;
|
||||
RotY += (f32) movY / 50.0f;
|
||||
RotX -= (f32) movX / 50.0f;
|
||||
|
||||
if(Zoomable)
|
||||
WiiPADControl(t);
|
||||
if(Zoomable)
|
||||
WiiPADControl(t);
|
||||
|
||||
//! Stop movement for about 5 sec after manual move
|
||||
if(frameCount-last_manual_move_frame < 250)
|
||||
return;
|
||||
//! Stop movement for about 5 sec after manual move
|
||||
if(frameCount-last_manual_move_frame < 250)
|
||||
return;
|
||||
|
||||
Animation = sin(DegToRad(AnimRotate))*2.0f;
|
||||
Animation2 = cos(DegToRad(AnimRotate))*5.0f;
|
||||
AnimRotate += 0.1f;
|
||||
if(AnimRotate > 360.0f)
|
||||
AnimRotate = 0.0f;
|
||||
Animation = sin(DegToRad(AnimRotate))*2.0f;
|
||||
Animation2 = cos(DegToRad(AnimRotate))*5.0f;
|
||||
AnimRotate += 0.1f;
|
||||
if(AnimRotate > 360.0f)
|
||||
AnimRotate = 0.0f;
|
||||
}
|
||||
|
||||
void BoxCover::Draw()
|
||||
{
|
||||
u8 BoxAlpha = (int) (alpha+alphaDyn) & 0xFF;
|
||||
u8 BoxAlpha = (int) (alpha+alphaDyn) & 0xFF;
|
||||
|
||||
GX_LoadProjectionMtx(projection, GX_PERSPECTIVE);
|
||||
GX_LoadProjectionMtx(projection, GX_PERSPECTIVE);
|
||||
|
||||
GX_SetVtxDesc(GX_VA_POS, GX_INDEX8);
|
||||
GX_SetVtxDesc(GX_VA_CLR0, GX_DIRECT);
|
||||
GX_SetVtxDesc(GX_VA_TEX0, GX_INDEX8);
|
||||
GX_SetVtxDesc(GX_VA_POS, GX_INDEX8);
|
||||
GX_SetVtxDesc(GX_VA_CLR0, GX_DIRECT);
|
||||
GX_SetVtxDesc(GX_VA_TEX0, GX_INDEX8);
|
||||
|
||||
Mtx modelView;
|
||||
Mtx modelView2;
|
||||
Mtx modelView3;
|
||||
Mtx modelView;
|
||||
Mtx modelView2;
|
||||
Mtx modelView3;
|
||||
|
||||
guVector cubeAxis = {0,0,1};
|
||||
guVector cubeAxis2 = {0,1,0};
|
||||
guVector cubeAxis3 = {1,0,0};
|
||||
guMtxIdentity(modelView);
|
||||
guMtxRotAxisDeg(modelView3, &cubeAxis3, RotX-Animation2);
|
||||
guMtxRotAxisDeg(modelView2, &cubeAxis2, RotY+Animation2+xoffsetDyn/2.0f);
|
||||
guMtxRotAxisDeg(modelView, &cubeAxis, RotZ-Animation);
|
||||
guMtxConcat(modelView3, modelView2, modelView2);
|
||||
guMtxConcat(modelView2, modelView, modelView);
|
||||
if(Settings.widescreen)
|
||||
guMtxScaleApply(modelView, modelView, Settings.WSFactor, 1.0f, 1.0f);
|
||||
guMtxTransApply(modelView, modelView, PosX+xoffsetDyn/680.0f+movePosX, PosY+yoffsetDyn/680.0f+movePosY, PosZ);
|
||||
guMtxConcat(view,modelView,modelView);
|
||||
guVector cubeAxis = {0,0,1};
|
||||
guVector cubeAxis2 = {0,1,0};
|
||||
guVector cubeAxis3 = {1,0,0};
|
||||
guMtxIdentity(modelView);
|
||||
guMtxRotAxisDeg(modelView3, &cubeAxis3, RotX-Animation2);
|
||||
guMtxRotAxisDeg(modelView2, &cubeAxis2, RotY+Animation2+xoffsetDyn/2.0f);
|
||||
guMtxRotAxisDeg(modelView, &cubeAxis, RotZ-Animation);
|
||||
guMtxConcat(modelView3, modelView2, modelView2);
|
||||
guMtxConcat(modelView2, modelView, modelView);
|
||||
if(Settings.widescreen)
|
||||
guMtxScaleApply(modelView, modelView, Settings.WSFactor, 1.0f, 1.0f);
|
||||
guMtxTransApply(modelView, modelView, PosX+xoffsetDyn/680.0f+movePosX, PosY+yoffsetDyn/680.0f+movePosY, PosZ);
|
||||
guMtxConcat(view,modelView,modelView);
|
||||
|
||||
GX_LoadPosMtxImm(modelView, GX_PNMTX0);
|
||||
GX_LoadPosMtxImm(modelView, GX_PNMTX0);
|
||||
|
||||
//! Border quads
|
||||
GX_LoadTexObj(&boxBorderTex, GX_TEXMAP0);
|
||||
GX_InvalidateTexAll();
|
||||
//! Border quads
|
||||
GX_LoadTexObj(&boxBorderTex, GX_TEXMAP0);
|
||||
GX_InvalidateTexAll();
|
||||
|
||||
GX_SetArray(GX_VA_POS, (void *) &g_boxMeshQ[0].pos, sizeof(g_boxMeshQ[0]));
|
||||
GX_SetArray(GX_VA_TEX0, (void *) &g_boxMeshQ[0].texCoord, sizeof(g_boxMeshQ[0]));
|
||||
GX_SetArray(GX_VA_POS, (void *) &g_boxMeshQ[0].pos, sizeof(g_boxMeshQ[0]));
|
||||
GX_SetArray(GX_VA_TEX0, (void *) &g_boxMeshQ[0].texCoord, sizeof(g_boxMeshQ[0]));
|
||||
|
||||
GX_Begin(GX_QUADS, GX_VTXFMT0, g_boxMeshQSize);
|
||||
for (u32 j = 0; j < g_boxMeshQSize; ++j)
|
||||
{
|
||||
GX_Position1x8(j);
|
||||
GX_Color4u8(boxColor.r, boxColor.g, boxColor.b, BoxAlpha);
|
||||
GX_TexCoord1x8(j);
|
||||
}
|
||||
GX_End();
|
||||
GX_Begin(GX_QUADS, GX_VTXFMT0, g_boxMeshQSize);
|
||||
for (u32 j = 0; j < g_boxMeshQSize; ++j)
|
||||
{
|
||||
GX_Position1x8(j);
|
||||
GX_Color4u8(boxColor.r, boxColor.g, boxColor.b, BoxAlpha);
|
||||
GX_TexCoord1x8(j);
|
||||
}
|
||||
GX_End();
|
||||
|
||||
//! Border triangles
|
||||
GX_SetArray(GX_VA_POS, (void *) &g_boxMeshT[0].pos, sizeof(g_boxMeshT[0]));
|
||||
GX_SetArray(GX_VA_TEX0, (void *) &g_boxMeshT[0].texCoord, sizeof(g_boxMeshT[0]));
|
||||
//! Border triangles
|
||||
GX_SetArray(GX_VA_POS, (void *) &g_boxMeshT[0].pos, sizeof(g_boxMeshT[0]));
|
||||
GX_SetArray(GX_VA_TEX0, (void *) &g_boxMeshT[0].texCoord, sizeof(g_boxMeshT[0]));
|
||||
|
||||
GX_Begin(GX_TRIANGLES, GX_VTXFMT0, g_boxMeshTSize);
|
||||
for (u32 j = 0; j < g_boxMeshTSize; ++j)
|
||||
{
|
||||
GX_Position1x8(j);
|
||||
GX_Color4u8(boxColor.r, boxColor.g, boxColor.b, BoxAlpha);
|
||||
GX_TexCoord1x8(j);
|
||||
}
|
||||
GX_End();
|
||||
GX_Begin(GX_TRIANGLES, GX_VTXFMT0, g_boxMeshTSize);
|
||||
for (u32 j = 0; j < g_boxMeshTSize; ++j)
|
||||
{
|
||||
GX_Position1x8(j);
|
||||
GX_Color4u8(boxColor.r, boxColor.g, boxColor.b, BoxAlpha);
|
||||
GX_TexCoord1x8(j);
|
||||
}
|
||||
GX_End();
|
||||
|
||||
//! Back Cover (Might be flat)
|
||||
GX_LoadTexObj(flatCover ? &defaultBoxTex : &coverTex, GX_TEXMAP0);
|
||||
GX_InvalidateTexAll();
|
||||
//! Back Cover (Might be flat)
|
||||
GX_LoadTexObj(flatCover ? &defaultBoxTex : &coverTex, GX_TEXMAP0);
|
||||
GX_InvalidateTexAll();
|
||||
|
||||
GX_SetArray(GX_VA_POS, (void *) &g_boxBackCoverMesh[0].pos, sizeof(g_boxBackCoverMesh[0]));
|
||||
GX_SetArray(GX_VA_TEX0, (void *) &g_boxBackCoverMesh[0].texCoord, sizeof(g_boxBackCoverMesh[0]));
|
||||
GX_SetArray(GX_VA_POS, (void *) &g_boxBackCoverMesh[0].pos, sizeof(g_boxBackCoverMesh[0]));
|
||||
GX_SetArray(GX_VA_TEX0, (void *) &g_boxBackCoverMesh[0].texCoord, sizeof(g_boxBackCoverMesh[0]));
|
||||
|
||||
GX_Begin(GX_QUADS, GX_VTXFMT0, g_boxBackCoverMeshSize);
|
||||
for (u32 j = 0; j < g_boxBackCoverMeshSize; ++j)
|
||||
{
|
||||
GX_Position1x8(j);
|
||||
if(flatCover)
|
||||
GX_Color4u8(boxColor.r, boxColor.g, boxColor.b, BoxAlpha);
|
||||
else
|
||||
GX_Color4u8(0xff, 0xff, 0xff, BoxAlpha);
|
||||
GX_TexCoord1x8(j);
|
||||
}
|
||||
GX_End();
|
||||
GX_Begin(GX_QUADS, GX_VTXFMT0, g_boxBackCoverMeshSize);
|
||||
for (u32 j = 0; j < g_boxBackCoverMeshSize; ++j)
|
||||
{
|
||||
GX_Position1x8(j);
|
||||
if(flatCover)
|
||||
GX_Color4u8(boxColor.r, boxColor.g, boxColor.b, BoxAlpha);
|
||||
else
|
||||
GX_Color4u8(0xff, 0xff, 0xff, BoxAlpha);
|
||||
GX_TexCoord1x8(j);
|
||||
}
|
||||
GX_End();
|
||||
|
||||
if(flatCover)
|
||||
{
|
||||
//! Front Flat Cover
|
||||
GX_LoadTexObj(&coverTex, GX_TEXMAP0);
|
||||
GX_InvalidateTexAll();
|
||||
if(flatCover)
|
||||
{
|
||||
//! Front Flat Cover
|
||||
GX_LoadTexObj(&coverTex, GX_TEXMAP0);
|
||||
GX_InvalidateTexAll();
|
||||
|
||||
GX_SetArray(GX_VA_POS, (void *) &g_flatCoverMesh[0].pos, sizeof(g_flatCoverMesh[0]));
|
||||
GX_SetArray(GX_VA_TEX0, (void *) &g_flatCoverMesh[0].texCoord, sizeof(g_flatCoverMesh[0]));
|
||||
GX_SetArray(GX_VA_POS, (void *) &g_flatCoverMesh[0].pos, sizeof(g_flatCoverMesh[0]));
|
||||
GX_SetArray(GX_VA_TEX0, (void *) &g_flatCoverMesh[0].texCoord, sizeof(g_flatCoverMesh[0]));
|
||||
|
||||
GX_Begin(GX_QUADS, GX_VTXFMT0, g_flatCoverMeshSize);
|
||||
for (u32 j = 0; j < g_flatCoverMeshSize; ++j)
|
||||
{
|
||||
GX_Position1x8(j);
|
||||
GX_Color4u8(0xff, 0xff, 0xff, 0xff);
|
||||
GX_TexCoord1x8(j);
|
||||
}
|
||||
GX_End();
|
||||
}
|
||||
else
|
||||
{
|
||||
//! Front Cover
|
||||
GX_SetArray(GX_VA_POS, (void *) &g_boxCoverMesh[0].pos, sizeof(g_boxCoverMesh[0]));
|
||||
GX_SetArray(GX_VA_TEX0, (void *) &g_boxCoverMesh[0].texCoord, sizeof(g_boxCoverMesh[0]));
|
||||
GX_Begin(GX_QUADS, GX_VTXFMT0, g_flatCoverMeshSize);
|
||||
for (u32 j = 0; j < g_flatCoverMeshSize; ++j)
|
||||
{
|
||||
GX_Position1x8(j);
|
||||
GX_Color4u8(0xff, 0xff, 0xff, 0xff);
|
||||
GX_TexCoord1x8(j);
|
||||
}
|
||||
GX_End();
|
||||
}
|
||||
else
|
||||
{
|
||||
//! Front Cover
|
||||
GX_SetArray(GX_VA_POS, (void *) &g_boxCoverMesh[0].pos, sizeof(g_boxCoverMesh[0]));
|
||||
GX_SetArray(GX_VA_TEX0, (void *) &g_boxCoverMesh[0].texCoord, sizeof(g_boxCoverMesh[0]));
|
||||
|
||||
GX_Begin(GX_QUADS, GX_VTXFMT0, g_boxCoverMeshSize);
|
||||
for (u32 j = 0; j < g_boxCoverMeshSize; ++j)
|
||||
{
|
||||
GX_Position1x8(j);
|
||||
GX_Color4u8(0xff, 0xff, 0xff, BoxAlpha);
|
||||
GX_TexCoord1x8(j);
|
||||
}
|
||||
GX_End();
|
||||
}
|
||||
GX_Begin(GX_QUADS, GX_VTXFMT0, g_boxCoverMeshSize);
|
||||
for (u32 j = 0; j < g_boxCoverMeshSize; ++j)
|
||||
{
|
||||
GX_Position1x8(j);
|
||||
GX_Color4u8(0xff, 0xff, 0xff, BoxAlpha);
|
||||
GX_TexCoord1x8(j);
|
||||
}
|
||||
GX_End();
|
||||
}
|
||||
|
||||
UpdateEffects();
|
||||
UpdateEffects();
|
||||
}
|
||||
|
||||
void BoxCover::SetEffect(int eff, int amount, int target)
|
||||
{
|
||||
GuiImage::SetEffect(eff, amount, target);
|
||||
GuiImage::SetEffect(eff, amount, target);
|
||||
}
|
||||
|
||||
void BoxCover::UpdateEffects()
|
||||
{
|
||||
GuiImage::UpdateEffects();
|
||||
GuiImage::UpdateEffects();
|
||||
|
||||
if(effects & EFFECT_BOX_FLY_CENTRE)
|
||||
{
|
||||
if(PosX > 0.1f)
|
||||
PosX -= effectAmount/1200.f;
|
||||
if(PosY > 0.1f)
|
||||
PosY -= effectAmount/1200.f;
|
||||
if(PosX < -0.1f)
|
||||
PosX += effectAmount/1200.f;
|
||||
if(PosY < -0.1f)
|
||||
PosY += effectAmount/1200.f;
|
||||
if(effects & EFFECT_BOX_FLY_CENTRE)
|
||||
{
|
||||
if(PosX > 0.1f)
|
||||
PosX -= effectAmount/1200.f;
|
||||
if(PosY > 0.1f)
|
||||
PosY -= effectAmount/1200.f;
|
||||
if(PosX < -0.1f)
|
||||
PosX += effectAmount/1200.f;
|
||||
if(PosY < -0.1f)
|
||||
PosY += effectAmount/1200.f;
|
||||
|
||||
movePosX = 0.0f;
|
||||
movePosY = 0.0f;
|
||||
PosZ += 0.4f;
|
||||
RotY += effectAmount/4.9f;
|
||||
movePosX = 0.0f;
|
||||
movePosY = 0.0f;
|
||||
PosZ += 0.4f;
|
||||
RotY += effectAmount/4.9f;
|
||||
|
||||
if(fabs(PosX) < 0.1f && fabs(PosY) < 0.1f)
|
||||
{
|
||||
PosX = 0.0f;
|
||||
PosY = 0.0f;
|
||||
effects = 0;
|
||||
effectAmount = 0;
|
||||
}
|
||||
}
|
||||
else if(effects & EFFECT_BOX_FLY_BACK)
|
||||
{
|
||||
if(PosX > PosXOrig+0.1f)
|
||||
PosX -= effectAmount/1200.f;
|
||||
if(PosY > PosYOrig+0.1f)
|
||||
PosY -= effectAmount/1200.f;
|
||||
if(PosX < PosXOrig-0.1f)
|
||||
PosX += effectAmount/1200.f;
|
||||
if(PosY < PosYOrig-0.1f)
|
||||
PosY += effectAmount/1200.f;
|
||||
if(fabs(PosX) < 0.1f && fabs(PosY) < 0.1f)
|
||||
{
|
||||
PosX = 0.0f;
|
||||
PosY = 0.0f;
|
||||
effects = 0;
|
||||
effectAmount = 0;
|
||||
}
|
||||
}
|
||||
else if(effects & EFFECT_BOX_FLY_BACK)
|
||||
{
|
||||
if(PosX > PosXOrig+0.1f)
|
||||
PosX -= effectAmount/1200.f;
|
||||
if(PosY > PosYOrig+0.1f)
|
||||
PosY -= effectAmount/1200.f;
|
||||
if(PosX < PosXOrig-0.1f)
|
||||
PosX += effectAmount/1200.f;
|
||||
if(PosY < PosYOrig-0.1f)
|
||||
PosY += effectAmount/1200.f;
|
||||
|
||||
PosZ -= 0.4f;
|
||||
RotY -= effectAmount/4.9f;
|
||||
PosZ -= 0.4f;
|
||||
RotY -= effectAmount/4.9f;
|
||||
|
||||
if(movePosX > 0.1f)
|
||||
movePosX -= 0.1f;
|
||||
else if(movePosX < 0.1f)
|
||||
movePosX += 0.1f;
|
||||
if(movePosY > 0.1f)
|
||||
movePosY -= 0.1f;
|
||||
else if(movePosY < 0.1f)
|
||||
movePosY += 0.1f;
|
||||
if(movePosX > 0.1f)
|
||||
movePosX -= 0.1f;
|
||||
else if(movePosX < 0.1f)
|
||||
movePosX += 0.1f;
|
||||
if(movePosY > 0.1f)
|
||||
movePosY -= 0.1f;
|
||||
else if(movePosY < 0.1f)
|
||||
movePosY += 0.1f;
|
||||
|
||||
if(fabs(PosXOrig-PosX) < 0.1f && fabs(PosYOrig-PosY) < 0.1f)
|
||||
{
|
||||
movePosX = 0.0f;
|
||||
movePosY = 0.0f;
|
||||
PosX = PosXOrig;
|
||||
PosY = PosYOrig;
|
||||
PosZ = PosZOrig;
|
||||
effects = 0;
|
||||
effectAmount = 0;
|
||||
}
|
||||
}
|
||||
else if(effects & EFFECT_BOX_ROTATE_X)
|
||||
{
|
||||
RotY += effectAmount;
|
||||
effectTarget -= effectAmount;
|
||||
if(fabs(PosXOrig-PosX) < 0.1f && fabs(PosYOrig-PosY) < 0.1f)
|
||||
{
|
||||
movePosX = 0.0f;
|
||||
movePosY = 0.0f;
|
||||
PosX = PosXOrig;
|
||||
PosY = PosYOrig;
|
||||
PosZ = PosZOrig;
|
||||
effects = 0;
|
||||
effectAmount = 0;
|
||||
}
|
||||
}
|
||||
else if(effects & EFFECT_BOX_ROTATE_X)
|
||||
{
|
||||
RotY += effectAmount;
|
||||
effectTarget -= effectAmount;
|
||||
|
||||
if(fabs(effectTarget) < fabs(effectAmount))
|
||||
{
|
||||
effects = 0;
|
||||
effectAmount = 0;
|
||||
effectTarget = 0;
|
||||
}
|
||||
}
|
||||
if(fabs(effectTarget) < fabs(effectAmount))
|
||||
{
|
||||
effects = 0;
|
||||
effectAmount = 0;
|
||||
effectTarget = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,58 +27,58 @@
|
|||
#include "GUI/gui.h"
|
||||
|
||||
#define EFFECT_BOX_FLY_CENTRE 0x2000000
|
||||
#define EFFECT_BOX_FLY_BACK 0x4000000
|
||||
#define EFFECT_BOX_ROTATE_X 0x8000000
|
||||
#define EFFECT_BOX_FLY_BACK 0x4000000
|
||||
#define EFFECT_BOX_ROTATE_X 0x8000000
|
||||
|
||||
class BoxCover : public GuiImage
|
||||
{
|
||||
public:
|
||||
BoxCover(GuiImageData * img, bool flat = false);
|
||||
virtual ~BoxCover();
|
||||
//! Colors:
|
||||
//! Gray Box (Default): r:233 g:233 b:233
|
||||
//! Red Box (NSMB): r:198 g:34 b:4
|
||||
void SetBoxColor(GXColor c) { LOCK(this); boxColor = c; };
|
||||
void SetPosition(f32 x, f32 y, f32 z) { LOCK(this); PosXOrig = PosX = x; PosYOrig = PosY = y; PosZOrig = PosZ = z; };
|
||||
void SetEffect(int eff, int amount, int target = 0);
|
||||
void SetImage(GuiImageData *img); //forbid this call
|
||||
void SetZoomable(bool z) { LOCK(this); Zoomable = z; };
|
||||
void Draw();
|
||||
void Update(GuiTrigger * t);
|
||||
void UpdateEffects();
|
||||
private:
|
||||
void WiiPADControl(GuiTrigger *t);
|
||||
public:
|
||||
BoxCover(GuiImageData * img, bool flat = false);
|
||||
virtual ~BoxCover();
|
||||
//! Colors:
|
||||
//! Gray Box (Default): r:233 g:233 b:233
|
||||
//! Red Box (NSMB): r:198 g:34 b:4
|
||||
void SetBoxColor(GXColor c) { LOCK(this); boxColor = c; };
|
||||
void SetPosition(f32 x, f32 y, f32 z) { LOCK(this); PosXOrig = PosX = x; PosYOrig = PosY = y; PosZOrig = PosZ = z; };
|
||||
void SetEffect(int eff, int amount, int target = 0);
|
||||
void SetImage(GuiImageData *img); //forbid this call
|
||||
void SetZoomable(bool z) { LOCK(this); Zoomable = z; };
|
||||
void Draw();
|
||||
void Update(GuiTrigger * t);
|
||||
void UpdateEffects();
|
||||
private:
|
||||
void WiiPADControl(GuiTrigger *t);
|
||||
|
||||
f32 RotX;
|
||||
f32 RotY;
|
||||
f32 RotZ;
|
||||
f32 PosX;
|
||||
f32 PosY;
|
||||
f32 PosZ;
|
||||
f32 PosXOrig;
|
||||
f32 PosYOrig;
|
||||
f32 PosZOrig;
|
||||
f32 AnimRotate;
|
||||
f32 Animation;
|
||||
f32 Animation2;
|
||||
u32 last_manual_move_frame;
|
||||
int moveStartPosX;
|
||||
int moveStartPosY;
|
||||
f32 movePosX;
|
||||
f32 movePosY;
|
||||
int moveChan;
|
||||
bool flatCover;
|
||||
bool Zoomable;
|
||||
Mtx44 projection;
|
||||
GuiImageData boxBorder;
|
||||
GuiImageData *defaultBox;
|
||||
GuiImageData *NormalPointers[4];
|
||||
GuiImageData *GrabPointers[4];
|
||||
Mtx view;
|
||||
GXTexObj coverTex;
|
||||
GXTexObj boxBorderTex;
|
||||
GXTexObj defaultBoxTex;
|
||||
GXColor boxColor;
|
||||
f32 RotX;
|
||||
f32 RotY;
|
||||
f32 RotZ;
|
||||
f32 PosX;
|
||||
f32 PosY;
|
||||
f32 PosZ;
|
||||
f32 PosXOrig;
|
||||
f32 PosYOrig;
|
||||
f32 PosZOrig;
|
||||
f32 AnimRotate;
|
||||
f32 Animation;
|
||||
f32 Animation2;
|
||||
u32 last_manual_move_frame;
|
||||
int moveStartPosX;
|
||||
int moveStartPosY;
|
||||
f32 movePosX;
|
||||
f32 movePosY;
|
||||
int moveChan;
|
||||
bool flatCover;
|
||||
bool Zoomable;
|
||||
Mtx44 projection;
|
||||
GuiImageData boxBorder;
|
||||
GuiImageData *defaultBox;
|
||||
GuiImageData *NormalPointers[4];
|
||||
GuiImageData *GrabPointers[4];
|
||||
Mtx view;
|
||||
GXTexObj coverTex;
|
||||
GXTexObj boxBorderTex;
|
||||
GXTexObj defaultBoxTex;
|
||||
GXColor boxColor;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -40,7 +40,7 @@ DeviceHandler * DeviceHandler::instance = NULL;
|
|||
|
||||
DeviceHandler::~DeviceHandler()
|
||||
{
|
||||
UnMountAll();
|
||||
UnMountAll();
|
||||
}
|
||||
|
||||
DeviceHandler * DeviceHandler::Instance()
|
||||
|
@ -54,295 +54,295 @@ DeviceHandler * DeviceHandler::Instance()
|
|||
|
||||
void DeviceHandler::DestroyInstance()
|
||||
{
|
||||
if(instance)
|
||||
{
|
||||
delete instance;
|
||||
}
|
||||
instance = NULL;
|
||||
if(instance)
|
||||
{
|
||||
delete instance;
|
||||
}
|
||||
instance = NULL;
|
||||
}
|
||||
|
||||
bool DeviceHandler::MountAll()
|
||||
{
|
||||
bool result = false;
|
||||
bool result = false;
|
||||
|
||||
for(u32 i = SD; i < MAXDEVICES; i++)
|
||||
{
|
||||
if(Mount(i))
|
||||
result = true;
|
||||
}
|
||||
for(u32 i = SD; i < MAXDEVICES; i++)
|
||||
{
|
||||
if(Mount(i))
|
||||
result = true;
|
||||
}
|
||||
|
||||
return result;
|
||||
return result;
|
||||
}
|
||||
|
||||
void DeviceHandler::UnMountAll()
|
||||
{
|
||||
for(u32 i = SD; i < MAXDEVICES; i++)
|
||||
UnMount(i);
|
||||
for(u32 i = SD; i < MAXDEVICES; i++)
|
||||
UnMount(i);
|
||||
|
||||
if(sd)
|
||||
delete sd;
|
||||
if(usb0)
|
||||
delete usb0;
|
||||
if(usb1)
|
||||
delete usb1;
|
||||
if(sd)
|
||||
delete sd;
|
||||
if(usb0)
|
||||
delete usb0;
|
||||
if(usb1)
|
||||
delete usb1;
|
||||
|
||||
sd = NULL;
|
||||
usb0 = NULL;
|
||||
usb1 = NULL;
|
||||
sd = NULL;
|
||||
usb0 = NULL;
|
||||
usb1 = NULL;
|
||||
}
|
||||
|
||||
bool DeviceHandler::Mount(int dev)
|
||||
{
|
||||
if(dev == SD)
|
||||
return MountSD();
|
||||
if(dev == SD)
|
||||
return MountSD();
|
||||
|
||||
else if(dev >= USB1 && dev <= USB8)
|
||||
return MountUSB(dev-USB1);
|
||||
else if(dev >= USB1 && dev <= USB8)
|
||||
return MountUSB(dev-USB1);
|
||||
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool DeviceHandler::IsInserted(int dev)
|
||||
{
|
||||
if(dev == SD)
|
||||
return SD_Inserted() && sd->IsMounted(0);
|
||||
if(dev == SD)
|
||||
return SD_Inserted() && sd->IsMounted(0);
|
||||
|
||||
else if(dev >= USB1 && dev <= USB8)
|
||||
{
|
||||
int portPart = PartitionToPortPartition(dev-USB1);
|
||||
PartitionHandle *usb = instance->GetUSBHandleFromPartition(dev-USB1);
|
||||
if(usb)
|
||||
return usb->IsMounted(portPart);
|
||||
}
|
||||
else if(dev >= USB1 && dev <= USB8)
|
||||
{
|
||||
int portPart = PartitionToPortPartition(dev-USB1);
|
||||
PartitionHandle *usb = instance->GetUSBHandleFromPartition(dev-USB1);
|
||||
if(usb)
|
||||
return usb->IsMounted(portPart);
|
||||
}
|
||||
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
void DeviceHandler::UnMount(int dev)
|
||||
{
|
||||
if(dev == SD)
|
||||
UnMountSD();
|
||||
if(dev == SD)
|
||||
UnMountSD();
|
||||
|
||||
else if(dev >= USB1 && dev <= USB8)
|
||||
UnMountUSB(dev-USB1);
|
||||
else if(dev >= USB1 && dev <= USB8)
|
||||
UnMountUSB(dev-USB1);
|
||||
}
|
||||
|
||||
bool DeviceHandler::MountSD()
|
||||
{
|
||||
if(!sd)
|
||||
sd = new PartitionHandle(&__io_wiisd);
|
||||
if(!sd)
|
||||
sd = new PartitionHandle(&__io_wiisd);
|
||||
|
||||
if(sd->GetPartitionCount() < 1)
|
||||
{
|
||||
delete sd;
|
||||
sd = NULL;
|
||||
return false;
|
||||
}
|
||||
if(sd->GetPartitionCount() < 1)
|
||||
{
|
||||
delete sd;
|
||||
sd = NULL;
|
||||
return false;
|
||||
}
|
||||
|
||||
//! Mount only one SD Partition
|
||||
return sd->Mount(0, DeviceName[SD], true);
|
||||
//! Mount only one SD Partition
|
||||
return sd->Mount(0, DeviceName[SD], true);
|
||||
}
|
||||
|
||||
static inline bool USBSpinUp()
|
||||
{
|
||||
bool started0 = true;
|
||||
bool started1 = true;
|
||||
int retries = 400;
|
||||
bool started0 = true;
|
||||
bool started1 = true;
|
||||
int retries = 400;
|
||||
|
||||
const DISC_INTERFACE * handle0 = NULL;
|
||||
const DISC_INTERFACE * handle1 = NULL;
|
||||
if(Settings.USBPort == 0 || Settings.USBPort == 2)
|
||||
handle0 = DeviceHandler::GetUSB0Interface();
|
||||
if(Settings.USBPort == 1 || Settings.USBPort == 2)
|
||||
handle1 = DeviceHandler::GetUSB1Interface();
|
||||
const DISC_INTERFACE * handle0 = NULL;
|
||||
const DISC_INTERFACE * handle1 = NULL;
|
||||
if(Settings.USBPort == 0 || Settings.USBPort == 2)
|
||||
handle0 = DeviceHandler::GetUSB0Interface();
|
||||
if(Settings.USBPort == 1 || Settings.USBPort == 2)
|
||||
handle1 = DeviceHandler::GetUSB1Interface();
|
||||
|
||||
// wait 20 sec for the USB to spin up...stupid slow ass HDD
|
||||
do
|
||||
{
|
||||
if(handle0)
|
||||
started0 = (handle0->startup() && handle0->isInserted());
|
||||
// wait 20 sec for the USB to spin up...stupid slow ass HDD
|
||||
do
|
||||
{
|
||||
if(handle0)
|
||||
started0 = (handle0->startup() && handle0->isInserted());
|
||||
|
||||
if(handle1)
|
||||
started1 = (handle1->startup() && handle1->isInserted());
|
||||
if(handle1)
|
||||
started1 = (handle1->startup() && handle1->isInserted());
|
||||
|
||||
if(started0 && started1) break;
|
||||
usleep(50000);
|
||||
}
|
||||
while(--retries > 0);
|
||||
if(started0 && started1) break;
|
||||
usleep(50000);
|
||||
}
|
||||
while(--retries > 0);
|
||||
|
||||
return (started0 && started1);
|
||||
return (started0 && started1);
|
||||
}
|
||||
|
||||
bool DeviceHandler::MountUSB(int pos)
|
||||
{
|
||||
if(!usb0 && !usb1)
|
||||
return false;
|
||||
if(!usb0 && !usb1)
|
||||
return false;
|
||||
|
||||
if(pos >= GetUSBPartitionCount())
|
||||
return false;
|
||||
if(pos >= GetUSBPartitionCount())
|
||||
return false;
|
||||
|
||||
int portPart = PartitionToPortPartition(pos);
|
||||
int portPart = PartitionToPortPartition(pos);
|
||||
|
||||
if(PartitionToUSBPort(pos) == 0 && usb0)
|
||||
return usb0->Mount(portPart, DeviceName[USB1+pos]);
|
||||
else if(usb1)
|
||||
return usb1->Mount(portPart, DeviceName[USB1+pos]);
|
||||
if(PartitionToUSBPort(pos) == 0 && usb0)
|
||||
return usb0->Mount(portPart, DeviceName[USB1+pos]);
|
||||
else if(usb1)
|
||||
return usb1->Mount(portPart, DeviceName[USB1+pos]);
|
||||
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool DeviceHandler::MountAllUSB(bool spinup)
|
||||
{
|
||||
if(spinup && !USBSpinUp())
|
||||
return false;
|
||||
if(spinup && !USBSpinUp())
|
||||
return false;
|
||||
|
||||
if(!usb0 && (Settings.USBPort == 0 || Settings.USBPort == 2))
|
||||
usb0 = new PartitionHandle(GetUSB0Interface());
|
||||
if(!usb1 && (Settings.USBPort == 1 || Settings.USBPort == 2))
|
||||
usb1 = new PartitionHandle(GetUSB1Interface());
|
||||
if(!usb0 && (Settings.USBPort == 0 || Settings.USBPort == 2))
|
||||
usb0 = new PartitionHandle(GetUSB0Interface());
|
||||
if(!usb1 && (Settings.USBPort == 1 || Settings.USBPort == 2))
|
||||
usb1 = new PartitionHandle(GetUSB1Interface());
|
||||
|
||||
if(usb0 && usb0->GetPartitionCount() < 1)
|
||||
{
|
||||
delete usb0;
|
||||
usb0 = NULL;
|
||||
}
|
||||
if(usb1 && usb1->GetPartitionCount() < 1)
|
||||
{
|
||||
delete usb1;
|
||||
usb1 = NULL;
|
||||
}
|
||||
if(usb0 && usb0->GetPartitionCount() < 1)
|
||||
{
|
||||
delete usb0;
|
||||
usb0 = NULL;
|
||||
}
|
||||
if(usb1 && usb1->GetPartitionCount() < 1)
|
||||
{
|
||||
delete usb1;
|
||||
usb1 = NULL;
|
||||
}
|
||||
|
||||
bool result = false;
|
||||
int partCount = GetUSBPartitionCount();
|
||||
bool result = false;
|
||||
int partCount = GetUSBPartitionCount();
|
||||
|
||||
for(int i = 0; i < partCount; i++)
|
||||
{
|
||||
if(MountUSB(i))
|
||||
result = true;
|
||||
}
|
||||
for(int i = 0; i < partCount; i++)
|
||||
{
|
||||
if(MountUSB(i))
|
||||
result = true;
|
||||
}
|
||||
|
||||
return result;
|
||||
return result;
|
||||
}
|
||||
|
||||
bool DeviceHandler::MountUSBPort1(bool spinup)
|
||||
{
|
||||
if(spinup && !USBSpinUp())
|
||||
return false;
|
||||
if(spinup && !USBSpinUp())
|
||||
return false;
|
||||
|
||||
if(!usb1 && (Settings.USBPort == 1 || Settings.USBPort == 2))
|
||||
usb1 = new PartitionHandle(GetUSB1Interface());
|
||||
if(!usb1 && (Settings.USBPort == 1 || Settings.USBPort == 2))
|
||||
usb1 = new PartitionHandle(GetUSB1Interface());
|
||||
|
||||
if(usb1 && usb1->GetPartitionCount() < 1)
|
||||
{
|
||||
delete usb1;
|
||||
usb1 = NULL;
|
||||
return false;
|
||||
}
|
||||
if(usb1 && usb1->GetPartitionCount() < 1)
|
||||
{
|
||||
delete usb1;
|
||||
usb1 = NULL;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool result = false;
|
||||
int partCount = GetUSBPartitionCount();
|
||||
int partCount0 = 0;
|
||||
if(usb0)
|
||||
partCount0 = usb0->GetPartitionCount();
|
||||
bool result = false;
|
||||
int partCount = GetUSBPartitionCount();
|
||||
int partCount0 = 0;
|
||||
if(usb0)
|
||||
partCount0 = usb0->GetPartitionCount();
|
||||
|
||||
for(int i = partCount0; i < partCount; i++)
|
||||
{
|
||||
if(MountUSB(i))
|
||||
result = true;
|
||||
}
|
||||
for(int i = partCount0; i < partCount; i++)
|
||||
{
|
||||
if(MountUSB(i))
|
||||
result = true;
|
||||
}
|
||||
|
||||
return result;
|
||||
return result;
|
||||
}
|
||||
|
||||
void DeviceHandler::UnMountUSB(int pos)
|
||||
{
|
||||
if(pos >= GetUSBPartitionCount())
|
||||
return;
|
||||
if(pos >= GetUSBPartitionCount())
|
||||
return;
|
||||
|
||||
int portPart = PartitionToPortPartition(pos);
|
||||
int portPart = PartitionToPortPartition(pos);
|
||||
|
||||
if(PartitionToUSBPort(pos) == 0 && usb0)
|
||||
return usb0->UnMount(portPart);
|
||||
else if(usb1)
|
||||
return usb1->UnMount(portPart);
|
||||
if(PartitionToUSBPort(pos) == 0 && usb0)
|
||||
return usb0->UnMount(portPart);
|
||||
else if(usb1)
|
||||
return usb1->UnMount(portPart);
|
||||
}
|
||||
|
||||
void DeviceHandler::UnMountAllUSB()
|
||||
{
|
||||
int partCount = GetUSBPartitionCount();
|
||||
int partCount = GetUSBPartitionCount();
|
||||
|
||||
for(int i = 0; i < partCount; i++)
|
||||
UnMountUSB(i);
|
||||
for(int i = 0; i < partCount; i++)
|
||||
UnMountUSB(i);
|
||||
|
||||
delete usb0;
|
||||
usb0 = NULL;
|
||||
delete usb1;
|
||||
usb1 = NULL;
|
||||
delete usb0;
|
||||
usb0 = NULL;
|
||||
delete usb1;
|
||||
usb1 = NULL;
|
||||
}
|
||||
|
||||
int DeviceHandler::PathToDriveType(const char * path)
|
||||
{
|
||||
if(!path)
|
||||
return -1;
|
||||
if(!path)
|
||||
return -1;
|
||||
|
||||
for(int i = SD; i < MAXDEVICES; i++)
|
||||
{
|
||||
if(strncmp(path, DeviceName[i], strlen(DeviceName[i])) == 0)
|
||||
return i;
|
||||
}
|
||||
for(int i = SD; i < MAXDEVICES; i++)
|
||||
{
|
||||
if(strncmp(path, DeviceName[i], strlen(DeviceName[i])) == 0)
|
||||
return i;
|
||||
}
|
||||
|
||||
return -1;
|
||||
return -1;
|
||||
}
|
||||
|
||||
const char * DeviceHandler::GetFSName(int dev)
|
||||
{
|
||||
if(dev == SD && DeviceHandler::instance->sd)
|
||||
{
|
||||
return DeviceHandler::instance->sd->GetFSName(0);
|
||||
}
|
||||
else if(dev >= USB1 && dev <= USB8)
|
||||
{
|
||||
int partCount0 = 0;
|
||||
int partCount1 = 0;
|
||||
if(DeviceHandler::instance->usb0)
|
||||
partCount0 += DeviceHandler::instance->usb0->GetPartitionCount();
|
||||
if(DeviceHandler::instance->usb1)
|
||||
partCount1 += DeviceHandler::instance->usb1->GetPartitionCount();
|
||||
if(dev == SD && DeviceHandler::instance->sd)
|
||||
{
|
||||
return DeviceHandler::instance->sd->GetFSName(0);
|
||||
}
|
||||
else if(dev >= USB1 && dev <= USB8)
|
||||
{
|
||||
int partCount0 = 0;
|
||||
int partCount1 = 0;
|
||||
if(DeviceHandler::instance->usb0)
|
||||
partCount0 += DeviceHandler::instance->usb0->GetPartitionCount();
|
||||
if(DeviceHandler::instance->usb1)
|
||||
partCount1 += DeviceHandler::instance->usb1->GetPartitionCount();
|
||||
|
||||
if(dev-USB1 > partCount0 && DeviceHandler::instance->usb0)
|
||||
return DeviceHandler::instance->usb0->GetFSName(dev-USB1);
|
||||
else if(DeviceHandler::instance->usb1)
|
||||
return DeviceHandler::instance->usb1->GetFSName(dev-USB1-partCount0);
|
||||
}
|
||||
if(dev-USB1 > partCount0 && DeviceHandler::instance->usb0)
|
||||
return DeviceHandler::instance->usb0->GetFSName(dev-USB1);
|
||||
else if(DeviceHandler::instance->usb1)
|
||||
return DeviceHandler::instance->usb1->GetFSName(dev-USB1-partCount0);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int DeviceHandler::GetUSBFilesystemType(int partition)
|
||||
{
|
||||
if(!instance)
|
||||
return -1;
|
||||
if(!instance)
|
||||
return -1;
|
||||
|
||||
const char *FSName = GetUSBFSName(partition);
|
||||
if(!FSName) return -1;
|
||||
const char *FSName = GetUSBFSName(partition);
|
||||
if(!FSName) return -1;
|
||||
|
||||
if(strncmp(FSName, "WBFS", 4) == 0)
|
||||
return PART_FS_WBFS;
|
||||
else if(strncmp(FSName, "FAT", 3) == 0)
|
||||
return PART_FS_FAT;
|
||||
else if(strncmp(FSName, "NTFS", 4) == 0)
|
||||
return PART_FS_NTFS;
|
||||
else if(strncmp(FSName, "LINUX", 4) == 0)
|
||||
return PART_FS_EXT;
|
||||
if(strncmp(FSName, "WBFS", 4) == 0)
|
||||
return PART_FS_WBFS;
|
||||
else if(strncmp(FSName, "FAT", 3) == 0)
|
||||
return PART_FS_FAT;
|
||||
else if(strncmp(FSName, "NTFS", 4) == 0)
|
||||
return PART_FS_NTFS;
|
||||
else if(strncmp(FSName, "LINUX", 4) == 0)
|
||||
return PART_FS_EXT;
|
||||
|
||||
return -1;
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
u16 DeviceHandler::GetUSBPartitionCount()
|
||||
{
|
||||
if(!instance)
|
||||
return 0;
|
||||
if(!instance)
|
||||
return 0;
|
||||
|
||||
u16 partCount0 = 0;
|
||||
u16 partCount1 = 0;
|
||||
|
@ -351,37 +351,37 @@ u16 DeviceHandler::GetUSBPartitionCount()
|
|||
if(instance->usb1)
|
||||
partCount1 = instance->usb1->GetPartitionCount();
|
||||
|
||||
return partCount0+partCount1;
|
||||
return partCount0+partCount1;
|
||||
}
|
||||
|
||||
int DeviceHandler::PartitionToUSBPort(int part)
|
||||
{
|
||||
if(!DeviceHandler::instance)
|
||||
return 0;
|
||||
if(!DeviceHandler::instance)
|
||||
return 0;
|
||||
|
||||
u16 partCount0 = 0;
|
||||
if(DeviceHandler::instance->usb0)
|
||||
partCount0 = instance->usb0->GetPartitionCount();
|
||||
|
||||
if(!instance->usb0 || part >= partCount0)
|
||||
return 1;
|
||||
else
|
||||
return 0;
|
||||
if(!instance->usb0 || part >= partCount0)
|
||||
return 1;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
int DeviceHandler::PartitionToPortPartition(int part)
|
||||
{
|
||||
if(!DeviceHandler::instance)
|
||||
return 0;
|
||||
if(!DeviceHandler::instance)
|
||||
return 0;
|
||||
|
||||
u16 partCount0 = 0;
|
||||
if(instance->usb0)
|
||||
partCount0 = instance->usb0->GetPartitionCount();
|
||||
|
||||
if(!instance->usb0 || part >= partCount0)
|
||||
return part-partCount0;
|
||||
else
|
||||
return part;
|
||||
if(!instance->usb0 || part >= partCount0)
|
||||
return part-partCount0;
|
||||
else
|
||||
return part;
|
||||
}
|
||||
|
||||
const char *DeviceHandler::GetUSBFSName(int partition)
|
||||
|
@ -389,19 +389,19 @@ const char *DeviceHandler::GetUSBFSName(int partition)
|
|||
if(!instance)
|
||||
return NULL;
|
||||
|
||||
const char * FSName = NULL;
|
||||
PartitionHandle *handle = instance->GetUSBHandleFromPartition(partition);
|
||||
const char * FSName = NULL;
|
||||
PartitionHandle *handle = instance->GetUSBHandleFromPartition(partition);
|
||||
|
||||
if(handle)
|
||||
FSName = handle->GetFSName(PartitionToPortPartition(partition));
|
||||
|
||||
return FSName;
|
||||
return FSName;
|
||||
}
|
||||
|
||||
PartitionHandle *DeviceHandler::GetUSBHandleFromPartition(int part) const
|
||||
{
|
||||
if(PartitionToUSBPort(part) == 0)
|
||||
return usb0;
|
||||
else
|
||||
return usb1;
|
||||
if(PartitionToUSBPort(part) == 0)
|
||||
return usb0;
|
||||
else
|
||||
return usb1;
|
||||
}
|
||||
|
|
|
@ -31,44 +31,44 @@
|
|||
|
||||
enum
|
||||
{
|
||||
SD = 0,
|
||||
USB1,
|
||||
USB2,
|
||||
USB3,
|
||||
USB4,
|
||||
USB5,
|
||||
USB6,
|
||||
USB7,
|
||||
USB8,
|
||||
MAXDEVICES
|
||||
SD = 0,
|
||||
USB1,
|
||||
USB2,
|
||||
USB3,
|
||||
USB4,
|
||||
USB5,
|
||||
USB6,
|
||||
USB7,
|
||||
USB8,
|
||||
MAXDEVICES
|
||||
};
|
||||
|
||||
const char DeviceName[MAXDEVICES][6] =
|
||||
{
|
||||
"sd",
|
||||
"usb1",
|
||||
"usb2",
|
||||
"usb3",
|
||||
"usb4",
|
||||
"usb5",
|
||||
"usb6",
|
||||
"usb7",
|
||||
"usb8",
|
||||
"sd",
|
||||
"usb1",
|
||||
"usb2",
|
||||
"usb3",
|
||||
"usb4",
|
||||
"usb5",
|
||||
"usb6",
|
||||
"usb7",
|
||||
"usb8",
|
||||
};
|
||||
|
||||
class DeviceHandler
|
||||
{
|
||||
public:
|
||||
public:
|
||||
static DeviceHandler * Instance();
|
||||
static void DestroyInstance();
|
||||
|
||||
bool MountAll();
|
||||
void UnMountAll();
|
||||
bool Mount(int dev);
|
||||
bool IsInserted(int dev);
|
||||
void UnMount(int dev);
|
||||
bool MountAll();
|
||||
void UnMountAll();
|
||||
bool Mount(int dev);
|
||||
bool IsInserted(int dev);
|
||||
void UnMount(int dev);
|
||||
|
||||
//! Individual Mounts/UnMounts...
|
||||
//! Individual Mounts/UnMounts...
|
||||
bool MountSD();
|
||||
bool MountAllUSB(bool spinUp = true);
|
||||
bool MountUSBPort1(bool spinUp = true);
|
||||
|
@ -86,24 +86,24 @@ class DeviceHandler
|
|||
static const DISC_INTERFACE *GetUSB1Interface() { return &__io_usbstorage2_port1; }
|
||||
static int GetUSBFilesystemType(int part);
|
||||
static int PathToDriveType(const char * path);
|
||||
static const char * GetFSName(int dev);
|
||||
static const char * PathToFSName(const char * path) { return GetFSName(PathToDriveType(path)); };
|
||||
static int PartitionToUSBPort(int part);
|
||||
static u16 GetUSBPartitionCount();
|
||||
static int PartitionToPortPartition(int part);
|
||||
static const char *GetUSBFSName(int partition);
|
||||
private:
|
||||
DeviceHandler() : sd(0), gca(0), gcb(0), usb0(0), usb1(0) { };
|
||||
~DeviceHandler();
|
||||
static const char * GetFSName(int dev);
|
||||
static const char * PathToFSName(const char * path) { return GetFSName(PathToDriveType(path)); };
|
||||
static int PartitionToUSBPort(int part);
|
||||
static u16 GetUSBPartitionCount();
|
||||
static int PartitionToPortPartition(int part);
|
||||
static const char *GetUSBFSName(int partition);
|
||||
private:
|
||||
DeviceHandler() : sd(0), gca(0), gcb(0), usb0(0), usb1(0) { };
|
||||
~DeviceHandler();
|
||||
bool MountUSB(int part);
|
||||
|
||||
static DeviceHandler *instance;
|
||||
|
||||
PartitionHandle * sd;
|
||||
PartitionHandle * gca;
|
||||
PartitionHandle * gcb;
|
||||
PartitionHandle * usb0;
|
||||
PartitionHandle * usb1;
|
||||
PartitionHandle * sd;
|
||||
PartitionHandle * gca;
|
||||
PartitionHandle * gcb;
|
||||
PartitionHandle * usb0;
|
||||
PartitionHandle * usb1;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -34,8 +34,8 @@
|
|||
#include "utils/uncompress.h"
|
||||
#include "PartitionHandle.h"
|
||||
|
||||
#define PARTITION_TYPE_DOS33_EXTENDED 0x05 /* DOS 3.3+ extended partition */
|
||||
#define PARTITION_TYPE_WIN95_EXTENDED 0x0F /* Windows 95 extended partition */
|
||||
#define PARTITION_TYPE_DOS33_EXTENDED 0x05 /* DOS 3.3+ extended partition */
|
||||
#define PARTITION_TYPE_WIN95_EXTENDED 0x0F /* Windows 95 extended partition */
|
||||
|
||||
#define CACHE 32
|
||||
#define SECTORS 64
|
||||
|
@ -67,221 +67,221 @@ static inline const char * PartFromType(int type)
|
|||
}
|
||||
|
||||
PartitionHandle::PartitionHandle(const DISC_INTERFACE *discio)
|
||||
: interface(discio)
|
||||
: interface(discio)
|
||||
{
|
||||
// Sanity check
|
||||
if (!interface)
|
||||
return;
|
||||
// Sanity check
|
||||
if (!interface)
|
||||
return;
|
||||
|
||||
// Start the device and check that it is inserted
|
||||
if (!interface->startup())
|
||||
return;
|
||||
// Start the device and check that it is inserted
|
||||
if (!interface->startup())
|
||||
return;
|
||||
|
||||
if (!interface->isInserted())
|
||||
return;
|
||||
if (!interface->isInserted())
|
||||
return;
|
||||
|
||||
FindPartitions();
|
||||
FindPartitions();
|
||||
}
|
||||
|
||||
PartitionHandle::~PartitionHandle()
|
||||
{
|
||||
UnMountAll();
|
||||
UnMountAll();
|
||||
|
||||
//shutdown device
|
||||
interface->shutdown();
|
||||
//shutdown device
|
||||
interface->shutdown();
|
||||
}
|
||||
|
||||
bool PartitionHandle::IsMounted(int pos)
|
||||
{
|
||||
if(pos < 0 || pos >= (int) MountNameList.size())
|
||||
return false;
|
||||
if(pos < 0 || pos >= (int) MountNameList.size())
|
||||
return false;
|
||||
|
||||
if(MountNameList[pos].size() == 0)
|
||||
return false;
|
||||
if(MountNameList[pos].size() == 0)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool PartitionHandle::Mount(int pos, const char * name, bool forceFAT)
|
||||
{
|
||||
if(!valid(pos))
|
||||
return false;
|
||||
if(!valid(pos))
|
||||
return false;
|
||||
|
||||
if(!name)
|
||||
return false;
|
||||
if(!name)
|
||||
return false;
|
||||
|
||||
UnMount(pos);
|
||||
UnMount(pos);
|
||||
|
||||
if(pos >= (int) MountNameList.size())
|
||||
MountNameList.resize(pos+1);
|
||||
if(pos >= (int) MountNameList.size())
|
||||
MountNameList.resize(pos+1);
|
||||
|
||||
MountNameList[pos] = name;
|
||||
MountNameList[pos] = name;
|
||||
|
||||
//! Some stupid partition manager think they don't need to edit the freaken MBR.
|
||||
//! So we need to check the first 64 sectors and see if some partition is there.
|
||||
//! libfat does that by default so let's use it.
|
||||
//! We do that only on sd not on usb.
|
||||
if(forceFAT && (!GetFSName(pos) || strcmp(GetFSName(pos), "Unknown") == 0))
|
||||
{
|
||||
if (fatMount(MountNameList[pos].c_str(), interface, 0, CACHE, SECTORS))
|
||||
{
|
||||
extern sec_t _FAT_startSector;
|
||||
AddPartition("FAT", _FAT_startSector, 0xdeadbeaf, true, 0x0c, 0);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
//! Some stupid partition manager think they don't need to edit the freaken MBR.
|
||||
//! So we need to check the first 64 sectors and see if some partition is there.
|
||||
//! libfat does that by default so let's use it.
|
||||
//! We do that only on sd not on usb.
|
||||
if(forceFAT && (!GetFSName(pos) || strcmp(GetFSName(pos), "Unknown") == 0))
|
||||
{
|
||||
if (fatMount(MountNameList[pos].c_str(), interface, 0, CACHE, SECTORS))
|
||||
{
|
||||
extern sec_t _FAT_startSector;
|
||||
AddPartition("FAT", _FAT_startSector, 0xdeadbeaf, true, 0x0c, 0);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if(strncmp(GetFSName(pos), "FAT", 3) == 0 || strcmp(GetFSName(pos), "GUID-Entry") == 0)
|
||||
{
|
||||
if (fatMount(MountNameList[pos].c_str(), interface, GetLBAStart(pos), CACHE, SECTORS))
|
||||
{
|
||||
if(strcmp(GetFSName(pos), "GUID-Entry") == 0)
|
||||
PartitionList[pos].FSName = "FAT";
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if(strncmp(GetFSName(pos), "FAT", 3) == 0 || strcmp(GetFSName(pos), "GUID-Entry") == 0)
|
||||
{
|
||||
if (fatMount(MountNameList[pos].c_str(), interface, GetLBAStart(pos), CACHE, SECTORS))
|
||||
{
|
||||
if(strcmp(GetFSName(pos), "GUID-Entry") == 0)
|
||||
PartitionList[pos].FSName = "FAT";
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if(strncmp(GetFSName(pos), "NTFS", 4) == 0 || strcmp(GetFSName(pos), "GUID-Entry") == 0)
|
||||
{
|
||||
if(ntfsMount(MountNameList[pos].c_str(), interface, GetLBAStart(pos), CACHE, SECTORS, NTFS_SHOW_HIDDEN_FILES | NTFS_RECOVER))
|
||||
{
|
||||
PartitionList[pos].FSName = "NTFS";
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if(strncmp(GetFSName(pos), "NTFS", 4) == 0 || strcmp(GetFSName(pos), "GUID-Entry") == 0)
|
||||
{
|
||||
if(ntfsMount(MountNameList[pos].c_str(), interface, GetLBAStart(pos), CACHE, SECTORS, NTFS_SHOW_HIDDEN_FILES | NTFS_RECOVER))
|
||||
{
|
||||
PartitionList[pos].FSName = "NTFS";
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if(strncmp(GetFSName(pos), "LINUX", 5) == 0 || strcmp(GetFSName(pos), "GUID-Entry") == 0)
|
||||
{
|
||||
if(ext2Mount(MountNameList[pos].c_str(), interface, GetLBAStart(pos), CACHE, SECTORS, EXT2_FLAG_DEFAULT))
|
||||
{
|
||||
PartitionList[pos].FSName = "LINUX";
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if(strncmp(GetFSName(pos), "LINUX", 5) == 0 || strcmp(GetFSName(pos), "GUID-Entry") == 0)
|
||||
{
|
||||
if(ext2Mount(MountNameList[pos].c_str(), interface, GetLBAStart(pos), CACHE, SECTORS, EXT2_FLAG_DEFAULT))
|
||||
{
|
||||
PartitionList[pos].FSName = "LINUX";
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
MountNameList[pos].clear();
|
||||
MountNameList[pos].clear();
|
||||
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
void PartitionHandle::UnMount(int pos)
|
||||
{
|
||||
if(!interface)
|
||||
return;
|
||||
if(!interface)
|
||||
return;
|
||||
|
||||
if(pos >= (int) MountNameList.size())
|
||||
return;
|
||||
if(pos >= (int) MountNameList.size())
|
||||
return;
|
||||
|
||||
if(MountNameList[pos].size() == 0)
|
||||
return;
|
||||
if(MountNameList[pos].size() == 0)
|
||||
return;
|
||||
|
||||
char DeviceSyn[20];
|
||||
snprintf(DeviceSyn, sizeof(DeviceSyn), "%s:", MountNameList[pos].c_str());
|
||||
char DeviceSyn[20];
|
||||
snprintf(DeviceSyn, sizeof(DeviceSyn), "%s:", MountNameList[pos].c_str());
|
||||
|
||||
//closing all open Files write back the cache
|
||||
fatUnmount(DeviceSyn);
|
||||
//closing all open Files write back the cache
|
||||
ntfsUnmount(DeviceSyn, true);
|
||||
//closing all open Files write back the cache
|
||||
ext2Unmount(DeviceSyn);
|
||||
//Remove name from list
|
||||
MountNameList[pos].clear();
|
||||
//closing all open Files write back the cache
|
||||
fatUnmount(DeviceSyn);
|
||||
//closing all open Files write back the cache
|
||||
ntfsUnmount(DeviceSyn, true);
|
||||
//closing all open Files write back the cache
|
||||
ext2Unmount(DeviceSyn);
|
||||
//Remove name from list
|
||||
MountNameList[pos].clear();
|
||||
}
|
||||
|
||||
bool PartitionHandle::IsExisting(u64 lba)
|
||||
{
|
||||
for(u32 i = 0; i < PartitionList.size(); ++i)
|
||||
{
|
||||
if(PartitionList[i].LBA_Start == lba)
|
||||
return true;
|
||||
}
|
||||
for(u32 i = 0; i < PartitionList.size(); ++i)
|
||||
{
|
||||
if(PartitionList[i].LBA_Start == lba)
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
int PartitionHandle::FindPartitions()
|
||||
{
|
||||
MASTER_BOOT_RECORD *mbr = (MASTER_BOOT_RECORD *) malloc(MAX_BYTES_PER_SECTOR);
|
||||
if(!mbr) return -1;
|
||||
MASTER_BOOT_RECORD *mbr = (MASTER_BOOT_RECORD *) malloc(MAX_BYTES_PER_SECTOR);
|
||||
if(!mbr) return -1;
|
||||
|
||||
// Read the first sector on the device
|
||||
if (!interface->readSectors(0, 1, mbr))
|
||||
{
|
||||
free(mbr);
|
||||
return -1;
|
||||
}
|
||||
// Read the first sector on the device
|
||||
if (!interface->readSectors(0, 1, mbr))
|
||||
{
|
||||
free(mbr);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// If this is the devices master boot record
|
||||
if (mbr->signature != MBR_SIGNATURE)
|
||||
{
|
||||
free(mbr);
|
||||
return -1;
|
||||
}
|
||||
// If this is the devices master boot record
|
||||
if (mbr->signature != MBR_SIGNATURE)
|
||||
{
|
||||
free(mbr);
|
||||
return -1;
|
||||
}
|
||||
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
PARTITION_RECORD * partition = (PARTITION_RECORD *) &mbr->partitions[i];
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
PARTITION_RECORD * partition = (PARTITION_RECORD *) &mbr->partitions[i];
|
||||
|
||||
if(partition->type == PARTITION_TYPE_GPT)
|
||||
{
|
||||
int ret = CheckGPT(i);
|
||||
if(ret == 0) // if it's a GPT we don't need to go on looking through the mbr anymore
|
||||
return ret;
|
||||
}
|
||||
if(partition->type == PARTITION_TYPE_GPT)
|
||||
{
|
||||
int ret = CheckGPT(i);
|
||||
if(ret == 0) // if it's a GPT we don't need to go on looking through the mbr anymore
|
||||
return ret;
|
||||
}
|
||||
|
||||
if(partition->type == PARTITION_TYPE_DOS33_EXTENDED || partition->type == PARTITION_TYPE_WIN95_EXTENDED)
|
||||
{
|
||||
if(partition->type == PARTITION_TYPE_DOS33_EXTENDED || partition->type == PARTITION_TYPE_WIN95_EXTENDED)
|
||||
{
|
||||
CheckEBR(i, le32(partition->lba_start));
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if(le32(partition->block_count) > 0 && !IsExisting(le32(partition->lba_start)))
|
||||
{
|
||||
AddPartition(PartFromType(partition->type), le32(partition->lba_start),
|
||||
le32(partition->block_count), (partition->status == PARTITION_BOOTABLE),
|
||||
partition->type, i);
|
||||
}
|
||||
}
|
||||
if(le32(partition->block_count) > 0 && !IsExisting(le32(partition->lba_start)))
|
||||
{
|
||||
AddPartition(PartFromType(partition->type), le32(partition->lba_start),
|
||||
le32(partition->block_count), (partition->status == PARTITION_BOOTABLE),
|
||||
partition->type, i);
|
||||
}
|
||||
}
|
||||
|
||||
free(mbr);
|
||||
free(mbr);
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void PartitionHandle::CheckEBR(u8 PartNum, sec_t ebr_lba)
|
||||
{
|
||||
EXTENDED_BOOT_RECORD *ebr = (EXTENDED_BOOT_RECORD *) malloc(MAX_BYTES_PER_SECTOR);
|
||||
if(!ebr) return;
|
||||
sec_t next_erb_lba = 0;
|
||||
EXTENDED_BOOT_RECORD *ebr = (EXTENDED_BOOT_RECORD *) malloc(MAX_BYTES_PER_SECTOR);
|
||||
if(!ebr) return;
|
||||
sec_t next_erb_lba = 0;
|
||||
|
||||
do
|
||||
{
|
||||
// Read and validate the extended boot record
|
||||
if (!interface->readSectors(ebr_lba + next_erb_lba, 1, ebr))
|
||||
{
|
||||
free(ebr);
|
||||
return;
|
||||
}
|
||||
do
|
||||
{
|
||||
// Read and validate the extended boot record
|
||||
if (!interface->readSectors(ebr_lba + next_erb_lba, 1, ebr))
|
||||
{
|
||||
free(ebr);
|
||||
return;
|
||||
}
|
||||
|
||||
if (ebr->signature != EBR_SIGNATURE)
|
||||
{
|
||||
free(ebr);
|
||||
return;
|
||||
}
|
||||
if (ebr->signature != EBR_SIGNATURE)
|
||||
{
|
||||
free(ebr);
|
||||
return;
|
||||
}
|
||||
|
||||
if(le32(ebr->partition.block_count) > 0 && !IsExisting(ebr_lba + next_erb_lba + le32(ebr->partition.lba_start)))
|
||||
{
|
||||
AddPartition(PartFromType(ebr->partition.type), ebr_lba + next_erb_lba + le32(ebr->partition.lba_start),
|
||||
le32(ebr->partition.block_count), (ebr->partition.status == PARTITION_BOOTABLE),
|
||||
ebr->partition.type, PartNum);
|
||||
}
|
||||
// Get the start sector of the current partition
|
||||
// and the next extended boot record in the chain
|
||||
next_erb_lba = le32(ebr->next_ebr.lba_start);
|
||||
}
|
||||
while(next_erb_lba > 0);
|
||||
if(le32(ebr->partition.block_count) > 0 && !IsExisting(ebr_lba + next_erb_lba + le32(ebr->partition.lba_start)))
|
||||
{
|
||||
AddPartition(PartFromType(ebr->partition.type), ebr_lba + next_erb_lba + le32(ebr->partition.lba_start),
|
||||
le32(ebr->partition.block_count), (ebr->partition.status == PARTITION_BOOTABLE),
|
||||
ebr->partition.type, PartNum);
|
||||
}
|
||||
// Get the start sector of the current partition
|
||||
// and the next extended boot record in the chain
|
||||
next_erb_lba = le32(ebr->next_ebr.lba_start);
|
||||
}
|
||||
while(next_erb_lba > 0);
|
||||
|
||||
free(ebr);
|
||||
free(ebr);
|
||||
}
|
||||
|
||||
static const u8 TYPE_UNUSED[16] = { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 };
|
||||
|
@ -290,105 +290,105 @@ static const u8 TYPE_LINUX_MS_BASIC_DATA[16] = { 0xA2,0xA0,0xD0,0xEB,0xE5,0xB9,0
|
|||
|
||||
int PartitionHandle::CheckGPT(u8 PartNum)
|
||||
{
|
||||
GPT_HEADER *gpt_header = (GPT_HEADER *) malloc(MAX_BYTES_PER_SECTOR);
|
||||
if(!gpt_header) return -1;
|
||||
GPT_HEADER *gpt_header = (GPT_HEADER *) malloc(MAX_BYTES_PER_SECTOR);
|
||||
if(!gpt_header) return -1;
|
||||
|
||||
// Read and validate the extended boot record
|
||||
if (!interface->readSectors(1, 1, gpt_header))
|
||||
{
|
||||
free(gpt_header);
|
||||
return -1;
|
||||
}
|
||||
// Read and validate the extended boot record
|
||||
if (!interface->readSectors(1, 1, gpt_header))
|
||||
{
|
||||
free(gpt_header);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(strncmp(gpt_header->magic, "EFI PART", 8) != 0)
|
||||
{
|
||||
free(gpt_header);
|
||||
return -1;
|
||||
}
|
||||
if(strncmp(gpt_header->magic, "EFI PART", 8) != 0)
|
||||
{
|
||||
free(gpt_header);
|
||||
return -1;
|
||||
}
|
||||
|
||||
gpt_header->part_table_lba = le64(gpt_header->part_table_lba);
|
||||
gpt_header->part_entries = le32(gpt_header->part_entries);
|
||||
gpt_header->part_entry_size = le32(gpt_header->part_entry_size);
|
||||
gpt_header->part_entry_checksum = le32(gpt_header->part_entry_checksum);
|
||||
gpt_header->part_table_lba = le64(gpt_header->part_table_lba);
|
||||
gpt_header->part_entries = le32(gpt_header->part_entries);
|
||||
gpt_header->part_entry_size = le32(gpt_header->part_entry_size);
|
||||
gpt_header->part_entry_checksum = le32(gpt_header->part_entry_checksum);
|
||||
|
||||
u8 * sector_buf = new u8[MAX_BYTES_PER_SECTOR];
|
||||
u8 * sector_buf = new u8[MAX_BYTES_PER_SECTOR];
|
||||
|
||||
u64 next_lba = gpt_header->part_table_lba;
|
||||
u64 next_lba = gpt_header->part_table_lba;
|
||||
|
||||
for(u32 i = 0; i < gpt_header->part_entries; ++i)
|
||||
{
|
||||
if (!interface->readSectors(next_lba, 1, sector_buf))
|
||||
break;
|
||||
for(u32 i = 0; i < gpt_header->part_entries; ++i)
|
||||
{
|
||||
if (!interface->readSectors(next_lba, 1, sector_buf))
|
||||
break;
|
||||
|
||||
for(u32 n = 0; n < BYTES_PER_SECTOR/gpt_header->part_entry_size; ++n, ++i)
|
||||
{
|
||||
GUID_PART_ENTRY * part_entry = (GUID_PART_ENTRY *) (sector_buf+gpt_header->part_entry_size*n);
|
||||
for(u32 n = 0; n < BYTES_PER_SECTOR/gpt_header->part_entry_size; ++n, ++i)
|
||||
{
|
||||
GUID_PART_ENTRY * part_entry = (GUID_PART_ENTRY *) (sector_buf+gpt_header->part_entry_size*n);
|
||||
|
||||
if(memcmp(part_entry->part_type_guid, TYPE_UNUSED, 16) == 0)
|
||||
continue;
|
||||
if(memcmp(part_entry->part_type_guid, TYPE_UNUSED, 16) == 0)
|
||||
continue;
|
||||
|
||||
if(IsExisting(le64(part_entry->part_first_lba)))
|
||||
continue;
|
||||
if(IsExisting(le64(part_entry->part_first_lba)))
|
||||
continue;
|
||||
|
||||
bool bootable = (memcmp(part_entry->part_type_guid, TYPE_BIOS, 16) == 0);
|
||||
bool bootable = (memcmp(part_entry->part_type_guid, TYPE_BIOS, 16) == 0);
|
||||
|
||||
AddPartition("GUID-Entry", le64(part_entry->part_first_lba), le64(part_entry->part_last_lba), bootable, PARTITION_TYPE_GPT, PartNum);
|
||||
}
|
||||
AddPartition("GUID-Entry", le64(part_entry->part_first_lba), le64(part_entry->part_last_lba), bootable, PARTITION_TYPE_GPT, PartNum);
|
||||
}
|
||||
|
||||
next_lba++;
|
||||
}
|
||||
next_lba++;
|
||||
}
|
||||
|
||||
delete [] sector_buf;
|
||||
free(gpt_header);
|
||||
delete [] sector_buf;
|
||||
free(gpt_header);
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void PartitionHandle::AddPartition(const char * name, u64 lba_start, u64 sec_count, bool bootable, u8 part_type, u8 part_num)
|
||||
{
|
||||
char *buffer = (char *) malloc(MAX_BYTES_PER_SECTOR);
|
||||
char *buffer = (char *) malloc(MAX_BYTES_PER_SECTOR);
|
||||
|
||||
if (!interface->readSectors(lba_start, 1, buffer))
|
||||
{
|
||||
free(buffer);
|
||||
return;
|
||||
}
|
||||
if (!interface->readSectors(lba_start, 1, buffer))
|
||||
{
|
||||
free(buffer);
|
||||
return;
|
||||
}
|
||||
|
||||
wbfs_head_t *head = (wbfs_head_t *) buffer;
|
||||
wbfs_head_t *head = (wbfs_head_t *) buffer;
|
||||
|
||||
if (head->magic == wbfs_htonl(WBFS_MAGIC))
|
||||
{
|
||||
name = "WBFS";
|
||||
part_type = 0xBF; //Override partition type on WBFS
|
||||
//! correct sector size in physical sectors (512 bytes per sector)
|
||||
sec_count = (u64) head->n_hd_sec * (u64) (1 << head->hd_sec_sz_s) / (u64) BYTES_PER_SECTOR;
|
||||
if (head->magic == wbfs_htonl(WBFS_MAGIC))
|
||||
{
|
||||
name = "WBFS";
|
||||
part_type = 0xBF; //Override partition type on WBFS
|
||||
//! correct sector size in physical sectors (512 bytes per sector)
|
||||
sec_count = (u64) head->n_hd_sec * (u64) (1 << head->hd_sec_sz_s) / (u64) BYTES_PER_SECTOR;
|
||||
|
||||
}
|
||||
else if(*((u16 *) (buffer + 0x1FE)) == 0x55AA)
|
||||
{
|
||||
//! Partition typ can be missleading the correct partition format. Stupid lazy ass Partition Editors.
|
||||
if((memcmp(buffer + 0x36, "FAT", 3) == 0 || memcmp(buffer + 0x52, "FAT", 3) == 0) &&
|
||||
strncmp(PartFromType(part_type), "FAT", 3) != 0)
|
||||
{
|
||||
name = "FAT32";
|
||||
part_type = 0x0c;
|
||||
}
|
||||
if (memcmp(buffer + 0x03, "NTFS", 4) == 0)
|
||||
{
|
||||
name = "NTFS";
|
||||
part_type = 0x07;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(*((u16 *) (buffer + 0x1FE)) == 0x55AA)
|
||||
{
|
||||
//! Partition typ can be missleading the correct partition format. Stupid lazy ass Partition Editors.
|
||||
if((memcmp(buffer + 0x36, "FAT", 3) == 0 || memcmp(buffer + 0x52, "FAT", 3) == 0) &&
|
||||
strncmp(PartFromType(part_type), "FAT", 3) != 0)
|
||||
{
|
||||
name = "FAT32";
|
||||
part_type = 0x0c;
|
||||
}
|
||||
if (memcmp(buffer + 0x03, "NTFS", 4) == 0)
|
||||
{
|
||||
name = "NTFS";
|
||||
part_type = 0x07;
|
||||
}
|
||||
}
|
||||
|
||||
PartitionFS PartitionEntrie;
|
||||
PartitionEntrie.FSName = name;
|
||||
PartitionEntrie.LBA_Start = lba_start;
|
||||
PartitionEntrie.SecCount = sec_count;
|
||||
PartitionEntrie.Bootable = bootable;
|
||||
PartitionEntrie.PartitionType = part_type;
|
||||
PartitionEntrie.PartitionNum = part_num;
|
||||
PartitionFS PartitionEntrie;
|
||||
PartitionEntrie.FSName = name;
|
||||
PartitionEntrie.LBA_Start = lba_start;
|
||||
PartitionEntrie.SecCount = sec_count;
|
||||
PartitionEntrie.Bootable = bootable;
|
||||
PartitionEntrie.PartitionType = part_type;
|
||||
PartitionEntrie.PartitionNum = part_num;
|
||||
|
||||
PartitionList.push_back(PartitionEntrie);
|
||||
PartitionList.push_back(PartitionEntrie);
|
||||
|
||||
free(buffer);
|
||||
free(buffer);
|
||||
}
|
||||
|
|
|
@ -30,139 +30,139 @@
|
|||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
#define MAX_PARTITIONS 32 /* Maximum number of partitions that can be found */
|
||||
#define MAX_MOUNTS 10 /* Maximum number of mounts available at one time */
|
||||
#define MAX_SYMLINK_DEPTH 10 /* Maximum search depth when resolving symbolic links */
|
||||
#define MAX_PARTITIONS 32 /* Maximum number of partitions that can be found */
|
||||
#define MAX_MOUNTS 10 /* Maximum number of mounts available at one time */
|
||||
#define MAX_SYMLINK_DEPTH 10 /* Maximum search depth when resolving symbolic links */
|
||||
|
||||
#define MBR_SIGNATURE 0x55AA
|
||||
#define EBR_SIGNATURE MBR_SIGNATURE
|
||||
#define MBR_SIGNATURE 0x55AA
|
||||
#define EBR_SIGNATURE MBR_SIGNATURE
|
||||
|
||||
#define PARTITION_BOOTABLE 0x80 /* Bootable (active) */
|
||||
#define PARTITION_BOOTABLE 0x80 /* Bootable (active) */
|
||||
#define PARTITION_NONBOOTABLE 0x00 /* Non-bootable */
|
||||
#define PARTITION_TYPE_GPT 0xEE /* Indicates that a GPT header is available */
|
||||
#define PARTITION_TYPE_GPT 0xEE /* Indicates that a GPT header is available */
|
||||
|
||||
#define GUID_SYSTEM_PARTITION 0x0000000000000001LL /* System partition (disk partitioning utilities must reserve the partition as is) */
|
||||
#define GUID_READ_ONLY_PARTITION 0x0800000000000000LL /* Read-only partition */
|
||||
#define GUID_HIDDEN_PARTITION 0x2000000000000000LL /* Hidden partition */
|
||||
#define GUID_NO_AUTOMOUNT_PARTITION 0x4000000000000000LL /* Do not automount (e.g., do not assign drive letter) */
|
||||
#define GUID_SYSTEM_PARTITION 0x0000000000000001LL /* System partition (disk partitioning utilities must reserve the partition as is) */
|
||||
#define GUID_READ_ONLY_PARTITION 0x0800000000000000LL /* Read-only partition */
|
||||
#define GUID_HIDDEN_PARTITION 0x2000000000000000LL /* Hidden partition */
|
||||
#define GUID_NO_AUTOMOUNT_PARTITION 0x4000000000000000LL /* Do not automount (e.g., do not assign drive letter) */
|
||||
|
||||
#define BYTES_PER_SECTOR 512 /* Default in libogc */
|
||||
#define MAX_BYTES_PER_SECTOR 4096 /* Max bytes per sector */
|
||||
#define BYTES_PER_SECTOR 512 /* Default in libogc */
|
||||
#define MAX_BYTES_PER_SECTOR 4096 /* Max bytes per sector */
|
||||
|
||||
typedef struct _PARTITION_RECORD {
|
||||
u8 status; /* Partition status; see above */
|
||||
u8 chs_start[3]; /* Cylinder-head-sector address to first block of partition */
|
||||
u8 type; /* Partition type; see above */
|
||||
u8 chs_end[3]; /* Cylinder-head-sector address to last block of partition */
|
||||
u32 lba_start; /* Local block address to first sector of partition */
|
||||
u32 block_count; /* Number of blocks in partition */
|
||||
u8 status; /* Partition status; see above */
|
||||
u8 chs_start[3]; /* Cylinder-head-sector address to first block of partition */
|
||||
u8 type; /* Partition type; see above */
|
||||
u8 chs_end[3]; /* Cylinder-head-sector address to last block of partition */
|
||||
u32 lba_start; /* Local block address to first sector of partition */
|
||||
u32 block_count; /* Number of blocks in partition */
|
||||
} __attribute__((__packed__)) PARTITION_RECORD;
|
||||
|
||||
|
||||
typedef struct _MASTER_BOOT_RECORD {
|
||||
u8 code_area[446]; /* Code area; normally empty */
|
||||
PARTITION_RECORD partitions[4]; /* 4 primary partitions */
|
||||
u16 signature; /* MBR signature; 0xAA55 */
|
||||
u8 code_area[446]; /* Code area; normally empty */
|
||||
PARTITION_RECORD partitions[4]; /* 4 primary partitions */
|
||||
u16 signature; /* MBR signature; 0xAA55 */
|
||||
} __attribute__((__packed__)) MASTER_BOOT_RECORD;
|
||||
|
||||
typedef struct _EXTENDED_BOOT_RECORD {
|
||||
u8 code_area[446]; /* Code area; normally empty */
|
||||
PARTITION_RECORD partition; /* Primary partition */
|
||||
PARTITION_RECORD next_ebr; /* Next extended boot record in the chain */
|
||||
u8 reserved[32]; /* Normally empty */
|
||||
u16 signature; /* EBR signature; 0xAA55 */
|
||||
u8 code_area[446]; /* Code area; normally empty */
|
||||
PARTITION_RECORD partition; /* Primary partition */
|
||||
PARTITION_RECORD next_ebr; /* Next extended boot record in the chain */
|
||||
u8 reserved[32]; /* Normally empty */
|
||||
u16 signature; /* EBR signature; 0xAA55 */
|
||||
} __attribute__((__packed__)) EXTENDED_BOOT_RECORD;
|
||||
|
||||
typedef struct _GPT_HEADER
|
||||
{
|
||||
char magic[8]; /* "EFI PART" */
|
||||
u32 revision; /* For version 1.0 */
|
||||
u32 header_size; /* Header size in bytes */
|
||||
u32 checksum; /* CRC32 of header (0 to header size), with this field zeroed during calculation */
|
||||
u32 reserved; /* must be 0 */
|
||||
u64 header_lba; /* Current LBA (location of this header copy) */
|
||||
u64 backup_lba; /* Backup LBA (location of the other header copy) */
|
||||
u64 first_part_lba; /* First usable LBA for partitions (primary partition table last LBA + 1) */
|
||||
u64 last_part_lba; /* Last usable LBA (secondary partition table first LBA - 1) */
|
||||
u8 disk_guid[16]; /* Disk GUID (also referred as UUID on UNIXes) */
|
||||
u64 part_table_lba; /* Partition entries starting LBA (always 2 in primary copy) */
|
||||
u32 part_entries; /* Number of partition entries */
|
||||
u32 part_entry_size; /* Size of a partition entry (usually 128) */
|
||||
u32 part_entry_checksum; /* CRC32 of partition array */
|
||||
u8 zeros[420];
|
||||
char magic[8]; /* "EFI PART" */
|
||||
u32 revision; /* For version 1.0 */
|
||||
u32 header_size; /* Header size in bytes */
|
||||
u32 checksum; /* CRC32 of header (0 to header size), with this field zeroed during calculation */
|
||||
u32 reserved; /* must be 0 */
|
||||
u64 header_lba; /* Current LBA (location of this header copy) */
|
||||
u64 backup_lba; /* Backup LBA (location of the other header copy) */
|
||||
u64 first_part_lba; /* First usable LBA for partitions (primary partition table last LBA + 1) */
|
||||
u64 last_part_lba; /* Last usable LBA (secondary partition table first LBA - 1) */
|
||||
u8 disk_guid[16]; /* Disk GUID (also referred as UUID on UNIXes) */
|
||||
u64 part_table_lba; /* Partition entries starting LBA (always 2 in primary copy) */
|
||||
u32 part_entries; /* Number of partition entries */
|
||||
u32 part_entry_size; /* Size of a partition entry (usually 128) */
|
||||
u32 part_entry_checksum; /* CRC32 of partition array */
|
||||
u8 zeros[420];
|
||||
} __attribute__((__packed__)) GPT_HEADER;
|
||||
|
||||
typedef struct _GUID_PART_ENTRY
|
||||
{
|
||||
u8 part_type_guid[16]; /* Partition type GUID */
|
||||
u8 uniq_part_guid[16]; /* Unique partition GUID */
|
||||
u64 part_first_lba; /* First LBA (little-endian) */
|
||||
u64 part_last_lba; /* Last LBA (inclusive, usually odd) */
|
||||
u64 attribute_flags; /* GUID Attribute flags (e.g. bit 60 denotes read-only) */
|
||||
char partition_name[72]; /* Partition name (36 UTF-16LE code units) */
|
||||
u8 part_type_guid[16]; /* Partition type GUID */
|
||||
u8 uniq_part_guid[16]; /* Unique partition GUID */
|
||||
u64 part_first_lba; /* First LBA (little-endian) */
|
||||
u64 part_last_lba; /* Last LBA (inclusive, usually odd) */
|
||||
u64 attribute_flags; /* GUID Attribute flags (e.g. bit 60 denotes read-only) */
|
||||
char partition_name[72]; /* Partition name (36 UTF-16LE code units) */
|
||||
} __attribute__((__packed__)) GUID_PART_ENTRY;
|
||||
|
||||
typedef struct _PartitionFS
|
||||
{
|
||||
const char * FSName;
|
||||
u64 LBA_Start;
|
||||
u64 SecCount;
|
||||
bool Bootable;
|
||||
u8 PartitionType;
|
||||
u8 PartitionNum;
|
||||
const char * FSName;
|
||||
u64 LBA_Start;
|
||||
u64 SecCount;
|
||||
bool Bootable;
|
||||
u8 PartitionType;
|
||||
u8 PartitionNum;
|
||||
} __attribute__((__packed__)) PartitionFS;
|
||||
|
||||
|
||||
class PartitionHandle
|
||||
{
|
||||
public:
|
||||
//! Constructor reads the MBR and all EBRs and lists up the Partitions
|
||||
PartitionHandle(const DISC_INTERFACE *discio);
|
||||
//! Destructor unmounts drives
|
||||
~PartitionHandle();
|
||||
//! Is Drive inserted
|
||||
bool IsInserted() { if(!interface) return false; else return interface->isInserted(); };
|
||||
//! Is the partition Mounted
|
||||
bool IsMounted(int pos);
|
||||
//! Mount a specific Partition
|
||||
bool Mount(int pos, const char * name, bool forceFAT = false);
|
||||
//! UnMount a specific Partition
|
||||
void UnMount(int pos);
|
||||
//! UnMount all Partition
|
||||
void UnMountAll() { for(u32 i = 0; i < PartitionList.size(); ++i) UnMount(i); };
|
||||
//! Get the Mountname
|
||||
const char * MountName(int pos) { if(pos < 0 || pos >= (int) MountNameList.size() || !MountNameList[pos].size()) return NULL; else return MountNameList[pos].c_str(); };
|
||||
//! Get the Name of the FileSystem e.g. "FAT32"
|
||||
const char * GetFSName(int pos) { if(valid(pos)) return PartitionList[pos].FSName; else return NULL; };
|
||||
//! Get the LBA where the partition is located
|
||||
u32 GetLBAStart(int pos) { if(valid(pos)) return PartitionList[pos].LBA_Start; else return 0; };
|
||||
//! Get the partition size in sectors of this partition
|
||||
u32 GetSecCount(int pos) { if(valid(pos)) return PartitionList[pos].SecCount; else return 0; };
|
||||
//! Check if the partition is Active or NonBootable
|
||||
bool IsActive(int pos) { if(valid(pos)) return PartitionList[pos].Bootable; else return false; };
|
||||
//! Get the partition type
|
||||
int GetPartitionType(int pos) { if(valid(pos)) return PartitionList[pos].PartitionType; else return -1; };
|
||||
//! Get the entrie number in MBR of this partition
|
||||
int GetPartitionNum(int pos) { if(valid(pos)) return PartitionList[pos].PartitionNum; else return -1; };
|
||||
//! Get the count of found partitions
|
||||
int GetPartitionCount() const { return PartitionList.size(); };
|
||||
//! Get the partition size in bytes
|
||||
u64 GetSize(int pos) { if(valid(pos)) return (u64) PartitionList[pos].SecCount*BYTES_PER_SECTOR; else return 0; };
|
||||
//! Get the whole partition record struct
|
||||
PartitionFS * GetPartitionRecord(int pos) { if(valid(pos)) return &PartitionList[pos]; else return NULL; };
|
||||
//! Get the disc interface of this handle
|
||||
const DISC_INTERFACE * GetDiscInterface() { return interface; };
|
||||
protected:
|
||||
bool valid(int pos) { return (pos >= 0 && pos < (int) PartitionList.size()); }
|
||||
void AddPartition(const char * name, u64 lba_start, u64 sec_count, bool bootable, u8 part_type, u8 part_num);
|
||||
bool IsExisting(u64 lba);
|
||||
int FindPartitions();
|
||||
void CheckEBR(u8 PartNum, sec_t ebr_lba);
|
||||
int CheckGPT(u8 PartNum);
|
||||
public:
|
||||
//! Constructor reads the MBR and all EBRs and lists up the Partitions
|
||||
PartitionHandle(const DISC_INTERFACE *discio);
|
||||
//! Destructor unmounts drives
|
||||
~PartitionHandle();
|
||||
//! Is Drive inserted
|
||||
bool IsInserted() { if(!interface) return false; else return interface->isInserted(); };
|
||||
//! Is the partition Mounted
|
||||
bool IsMounted(int pos);
|
||||
//! Mount a specific Partition
|
||||
bool Mount(int pos, const char * name, bool forceFAT = false);
|
||||
//! UnMount a specific Partition
|
||||
void UnMount(int pos);
|
||||
//! UnMount all Partition
|
||||
void UnMountAll() { for(u32 i = 0; i < PartitionList.size(); ++i) UnMount(i); };
|
||||
//! Get the Mountname
|
||||
const char * MountName(int pos) { if(pos < 0 || pos >= (int) MountNameList.size() || !MountNameList[pos].size()) return NULL; else return MountNameList[pos].c_str(); };
|
||||
//! Get the Name of the FileSystem e.g. "FAT32"
|
||||
const char * GetFSName(int pos) { if(valid(pos)) return PartitionList[pos].FSName; else return NULL; };
|
||||
//! Get the LBA where the partition is located
|
||||
u32 GetLBAStart(int pos) { if(valid(pos)) return PartitionList[pos].LBA_Start; else return 0; };
|
||||
//! Get the partition size in sectors of this partition
|
||||
u32 GetSecCount(int pos) { if(valid(pos)) return PartitionList[pos].SecCount; else return 0; };
|
||||
//! Check if the partition is Active or NonBootable
|
||||
bool IsActive(int pos) { if(valid(pos)) return PartitionList[pos].Bootable; else return false; };
|
||||
//! Get the partition type
|
||||
int GetPartitionType(int pos) { if(valid(pos)) return PartitionList[pos].PartitionType; else return -1; };
|
||||
//! Get the entrie number in MBR of this partition
|
||||
int GetPartitionNum(int pos) { if(valid(pos)) return PartitionList[pos].PartitionNum; else return -1; };
|
||||
//! Get the count of found partitions
|
||||
int GetPartitionCount() const { return PartitionList.size(); };
|
||||
//! Get the partition size in bytes
|
||||
u64 GetSize(int pos) { if(valid(pos)) return (u64) PartitionList[pos].SecCount*BYTES_PER_SECTOR; else return 0; };
|
||||
//! Get the whole partition record struct
|
||||
PartitionFS * GetPartitionRecord(int pos) { if(valid(pos)) return &PartitionList[pos]; else return NULL; };
|
||||
//! Get the disc interface of this handle
|
||||
const DISC_INTERFACE * GetDiscInterface() { return interface; };
|
||||
protected:
|
||||
bool valid(int pos) { return (pos >= 0 && pos < (int) PartitionList.size()); }
|
||||
void AddPartition(const char * name, u64 lba_start, u64 sec_count, bool bootable, u8 part_type, u8 part_num);
|
||||
bool IsExisting(u64 lba);
|
||||
int FindPartitions();
|
||||
void CheckEBR(u8 PartNum, sec_t ebr_lba);
|
||||
int CheckGPT(u8 PartNum);
|
||||
|
||||
const DISC_INTERFACE *interface;
|
||||
std::vector<PartitionFS> PartitionList;
|
||||
std::vector<std::string> MountNameList;
|
||||
const DISC_INTERFACE *interface;
|
||||
std::vector<PartitionFS> PartitionList;
|
||||
std::vector<std::string> MountNameList;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -39,143 +39,143 @@
|
|||
|
||||
DirList::DirList(const char * path, const char *filter, u32 flags)
|
||||
{
|
||||
this->LoadPath(path, filter, flags);
|
||||
this->SortList();
|
||||
this->LoadPath(path, filter, flags);
|
||||
this->SortList();
|
||||
}
|
||||
|
||||
DirList::~DirList()
|
||||
{
|
||||
ClearList();
|
||||
ClearList();
|
||||
}
|
||||
|
||||
bool DirList::LoadPath(const char * folder, const char *filter, u32 flags)
|
||||
{
|
||||
if(!folder) return false;
|
||||
if(!folder) return false;
|
||||
|
||||
std::string folderpath(folder);
|
||||
std::string folderpath(folder);
|
||||
|
||||
return LoadPath(folderpath, filter, flags);
|
||||
return LoadPath(folderpath, filter, flags);
|
||||
}
|
||||
|
||||
bool DirList::LoadPath(std::string &folderpath, const char *filter, u32 flags)
|
||||
{
|
||||
if(folderpath.size() < 3)
|
||||
return false;
|
||||
if(folderpath.size() < 3)
|
||||
return false;
|
||||
|
||||
struct dirent *dirent = NULL;
|
||||
DIR *dir = NULL;
|
||||
struct dirent *dirent = NULL;
|
||||
DIR *dir = NULL;
|
||||
|
||||
if(folderpath[folderpath.size()-1] == '/')
|
||||
folderpath.erase(folderpath.size()-1);
|
||||
folderpath.erase(folderpath.size()-1);
|
||||
|
||||
bool isRoot = (folderpath.find('/') == std::string::npos);
|
||||
if(isRoot)
|
||||
folderpath += '/';
|
||||
folderpath += '/';
|
||||
|
||||
dir = opendir(folderpath.c_str());
|
||||
if (dir == NULL)
|
||||
return false;
|
||||
dir = opendir(folderpath.c_str());
|
||||
if (dir == NULL)
|
||||
return false;
|
||||
|
||||
char * filename = new (std::nothrow) char[MAXPATHLEN];
|
||||
struct stat *st = new (std::nothrow) struct stat;
|
||||
if(!filename || !st)
|
||||
{
|
||||
delete [] filename;
|
||||
delete st;
|
||||
closedir(dir);
|
||||
return false;
|
||||
}
|
||||
char * filename = new (std::nothrow) char[MAXPATHLEN];
|
||||
struct stat *st = new (std::nothrow) struct stat;
|
||||
if(!filename || !st)
|
||||
{
|
||||
delete [] filename;
|
||||
delete st;
|
||||
closedir(dir);
|
||||
return false;
|
||||
}
|
||||
|
||||
while ((dirent = readdir(dir)) != 0)
|
||||
{
|
||||
if(!dirent->d_name)
|
||||
continue;
|
||||
while ((dirent = readdir(dir)) != 0)
|
||||
{
|
||||
if(!dirent->d_name)
|
||||
continue;
|
||||
|
||||
snprintf(filename, MAXPATHLEN, "%s/%s", folderpath.c_str(), dirent->d_name);
|
||||
snprintf(filename, MAXPATHLEN, "%s/%s", folderpath.c_str(), dirent->d_name);
|
||||
|
||||
if(stat(filename, st) != 0)
|
||||
continue;
|
||||
if(stat(filename, st) != 0)
|
||||
continue;
|
||||
|
||||
snprintf(filename, MAXPATHLEN, dirent->d_name);
|
||||
snprintf(filename, MAXPATHLEN, dirent->d_name);
|
||||
|
||||
if(st->st_mode & S_IFDIR)
|
||||
{
|
||||
if(!(flags & Dirs))
|
||||
continue;
|
||||
if(st->st_mode & S_IFDIR)
|
||||
{
|
||||
if(!(flags & Dirs))
|
||||
continue;
|
||||
|
||||
if(strcmp(filename,".") == 0 || strcmp(filename,"..") == 0)
|
||||
continue;
|
||||
if(strcmp(filename,".") == 0 || strcmp(filename,"..") == 0)
|
||||
continue;
|
||||
|
||||
if(flags & CheckSubfolders)
|
||||
{
|
||||
int length = folderpath.size();
|
||||
if(!isRoot) folderpath += '/';
|
||||
folderpath += filename;
|
||||
LoadPath(folderpath, filter, flags);
|
||||
folderpath.erase(length);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(!(flags & Files))
|
||||
continue;
|
||||
}
|
||||
if(flags & CheckSubfolders)
|
||||
{
|
||||
int length = folderpath.size();
|
||||
if(!isRoot) folderpath += '/';
|
||||
folderpath += filename;
|
||||
LoadPath(folderpath, filter, flags);
|
||||
folderpath.erase(length);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(!(flags & Files))
|
||||
continue;
|
||||
}
|
||||
|
||||
if(filter)
|
||||
{
|
||||
char * fileext = strrchr(filename, '.');
|
||||
if(!fileext)
|
||||
continue;
|
||||
if(filter)
|
||||
{
|
||||
char * fileext = strrchr(filename, '.');
|
||||
if(!fileext)
|
||||
continue;
|
||||
|
||||
if(strtokcmp(fileext, filter, ",") == 0)
|
||||
AddEntrie(folderpath.c_str(), filename, st->st_size, (st->st_mode & S_IFDIR) ? true : false);
|
||||
}
|
||||
else
|
||||
{
|
||||
AddEntrie(folderpath.c_str(), filename, st->st_size, (st->st_mode & S_IFDIR) ? true : false);
|
||||
}
|
||||
}
|
||||
closedir(dir);
|
||||
delete [] filename;
|
||||
delete st;
|
||||
if(strtokcmp(fileext, filter, ",") == 0)
|
||||
AddEntrie(folderpath.c_str(), filename, st->st_size, (st->st_mode & S_IFDIR) ? true : false);
|
||||
}
|
||||
else
|
||||
{
|
||||
AddEntrie(folderpath.c_str(), filename, st->st_size, (st->st_mode & S_IFDIR) ? true : false);
|
||||
}
|
||||
}
|
||||
closedir(dir);
|
||||
delete [] filename;
|
||||
delete st;
|
||||
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
void DirList::AddEntrie(const char * folderpath, const char * filename, u64 filesize, bool isDir)
|
||||
{
|
||||
if(!folderpath || !filename)
|
||||
return;
|
||||
if(!folderpath || !filename)
|
||||
return;
|
||||
|
||||
int pos = FileInfo.size();
|
||||
int pos = FileInfo.size();
|
||||
|
||||
FileInfo.resize(pos+1);
|
||||
FileInfo.resize(pos+1);
|
||||
|
||||
FileInfo[pos].FilePath = new (std::nothrow) char[strlen(folderpath)+strlen(filename)+2];
|
||||
if(FileInfo[pos].FilePath)
|
||||
sprintf(FileInfo[pos].FilePath, "%s/%s", folderpath, filename);
|
||||
FileInfo[pos].FileSize = filesize;
|
||||
FileInfo[pos].isDir = isDir;
|
||||
FileInfo[pos].FilePath = new (std::nothrow) char[strlen(folderpath)+strlen(filename)+2];
|
||||
if(FileInfo[pos].FilePath)
|
||||
sprintf(FileInfo[pos].FilePath, "%s/%s", folderpath, filename);
|
||||
FileInfo[pos].FileSize = filesize;
|
||||
FileInfo[pos].isDir = isDir;
|
||||
}
|
||||
|
||||
void DirList::ClearList()
|
||||
{
|
||||
for(u32 i = 0; i < FileInfo.size(); ++i)
|
||||
{
|
||||
if(FileInfo[i].FilePath)
|
||||
delete [] FileInfo[i].FilePath;
|
||||
}
|
||||
for(u32 i = 0; i < FileInfo.size(); ++i)
|
||||
{
|
||||
if(FileInfo[i].FilePath)
|
||||
delete [] FileInfo[i].FilePath;
|
||||
}
|
||||
|
||||
FileInfo.clear();
|
||||
std::vector<FileInfos>().swap(FileInfo);
|
||||
FileInfo.clear();
|
||||
std::vector<FileInfos>().swap(FileInfo);
|
||||
}
|
||||
|
||||
const char * DirList::GetFilename(int ind)
|
||||
{
|
||||
if (!valid(ind))
|
||||
return NULL;
|
||||
if (!valid(ind))
|
||||
return NULL;
|
||||
|
||||
return FullpathToFilename(FileInfo[ind].FilePath);
|
||||
return FullpathToFilename(FileInfo[ind].FilePath);
|
||||
}
|
||||
|
||||
static bool SortCallback(const FileInfos & f1, const FileInfos & f2)
|
||||
|
@ -186,28 +186,28 @@ static bool SortCallback(const FileInfos & f1, const FileInfos & f2)
|
|||
if(f1.FilePath && !f2.FilePath) return true;
|
||||
if(!f1.FilePath) return false;
|
||||
|
||||
if(strcasecmp(f1.FilePath, f2.FilePath) > 0)
|
||||
return false;
|
||||
if(strcasecmp(f1.FilePath, f2.FilePath) > 0)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
void DirList::SortList()
|
||||
{
|
||||
if(FileInfo.size() > 1)
|
||||
std::sort(FileInfo.begin(), FileInfo.end(), SortCallback);
|
||||
if(FileInfo.size() > 1)
|
||||
std::sort(FileInfo.begin(), FileInfo.end(), SortCallback);
|
||||
}
|
||||
|
||||
void DirList::SortList(bool (*SortFunc)(const FileInfos &a, const FileInfos &b))
|
||||
{
|
||||
if(FileInfo.size() > 1)
|
||||
std::sort(FileInfo.begin(), FileInfo.end(), SortFunc);
|
||||
if(FileInfo.size() > 1)
|
||||
std::sort(FileInfo.begin(), FileInfo.end(), SortFunc);
|
||||
}
|
||||
|
||||
int DirList::GetFileIndex(const char *filename)
|
||||
{
|
||||
if(!filename)
|
||||
return -1;
|
||||
if(!filename)
|
||||
return -1;
|
||||
|
||||
for (u32 i = 0; i < FileInfo.size(); ++i)
|
||||
{
|
||||
|
|
|
@ -33,60 +33,60 @@
|
|||
|
||||
typedef struct
|
||||
{
|
||||
char * FilePath;
|
||||
u64 FileSize;
|
||||
bool isDir;
|
||||
char * FilePath;
|
||||
u64 FileSize;
|
||||
bool isDir;
|
||||
} FileInfos;
|
||||
|
||||
class DirList
|
||||
{
|
||||
public:
|
||||
//!Constructor
|
||||
//!\param path Path from where to load the filelist of all files
|
||||
//!\param filter A fileext that needs to be filtered
|
||||
//!\param flags search/filter flags from the enum
|
||||
DirList(const char * path, const char *filter = NULL, u32 flags = Files | Dirs);
|
||||
//!Destructor
|
||||
~DirList();
|
||||
//! Load all the files from a directory
|
||||
bool LoadPath(const char * path, const char *filter = NULL, u32 flags = Files | Dirs);
|
||||
bool LoadPath(std::string &path, const char *filter = NULL, u32 flags = Files | Dirs);
|
||||
//! Get a filename of the list
|
||||
//!\param list index
|
||||
const char * GetFilename(int index);
|
||||
//! Get the a filepath of the list
|
||||
//!\param list index
|
||||
const char * GetFilepath(int index) { if(!valid(index)) return NULL; return FileInfo[index].FilePath; };
|
||||
//! Get the a filesize of the list
|
||||
//!\param list index
|
||||
u64 GetFilesize(int index) { if(!valid(index)) return 0; return FileInfo[index].FileSize; };
|
||||
//! Is index a dir or a file
|
||||
//!\param list index
|
||||
bool IsDir(int index) { if(!valid(index)) return 0; return FileInfo[index].isDir; };
|
||||
//! Get the filecount of the whole list
|
||||
int GetFilecount() { return FileInfo.size(); };
|
||||
//! Sort list by filepath
|
||||
void SortList();
|
||||
//! Custom sort command for custom sort functions definitions
|
||||
void SortList(bool (*SortFunc)(const FileInfos &a, const FileInfos &b));
|
||||
public:
|
||||
//!Constructor
|
||||
//!\param path Path from where to load the filelist of all files
|
||||
//!\param filter A fileext that needs to be filtered
|
||||
//!\param flags search/filter flags from the enum
|
||||
DirList(const char * path, const char *filter = NULL, u32 flags = Files | Dirs);
|
||||
//!Destructor
|
||||
~DirList();
|
||||
//! Load all the files from a directory
|
||||
bool LoadPath(const char * path, const char *filter = NULL, u32 flags = Files | Dirs);
|
||||
bool LoadPath(std::string &path, const char *filter = NULL, u32 flags = Files | Dirs);
|
||||
//! Get a filename of the list
|
||||
//!\param list index
|
||||
const char * GetFilename(int index);
|
||||
//! Get the a filepath of the list
|
||||
//!\param list index
|
||||
const char * GetFilepath(int index) { if(!valid(index)) return NULL; return FileInfo[index].FilePath; };
|
||||
//! Get the a filesize of the list
|
||||
//!\param list index
|
||||
u64 GetFilesize(int index) { if(!valid(index)) return 0; return FileInfo[index].FileSize; };
|
||||
//! Is index a dir or a file
|
||||
//!\param list index
|
||||
bool IsDir(int index) { if(!valid(index)) return 0; return FileInfo[index].isDir; };
|
||||
//! Get the filecount of the whole list
|
||||
int GetFilecount() { return FileInfo.size(); };
|
||||
//! Sort list by filepath
|
||||
void SortList();
|
||||
//! Custom sort command for custom sort functions definitions
|
||||
void SortList(bool (*SortFunc)(const FileInfos &a, const FileInfos &b));
|
||||
//! Get the index of the specified filename
|
||||
int GetFileIndex(const char *filename);
|
||||
//! Enum for search/filter flags
|
||||
enum
|
||||
{
|
||||
Files = 0x01,
|
||||
Dirs = 0x02,
|
||||
CheckSubfolders = 0x08,
|
||||
Files = 0x01,
|
||||
Dirs = 0x02,
|
||||
CheckSubfolders = 0x08,
|
||||
};
|
||||
protected:
|
||||
//!Add a list entrie
|
||||
void AddEntrie(const char * folderpath, const char * filename, u64 filesize, bool isDir);
|
||||
//! Clear the list
|
||||
void ClearList();
|
||||
//! Check if valid pos is requested
|
||||
inline bool valid(int pos) { return (pos >= 0 && pos < (int) FileInfo.size()); };
|
||||
protected:
|
||||
//!Add a list entrie
|
||||
void AddEntrie(const char * folderpath, const char * filename, u64 filesize, bool isDir);
|
||||
//! Clear the list
|
||||
void ClearList();
|
||||
//! Check if valid pos is requested
|
||||
inline bool valid(int pos) { return (pos >= 0 && pos < (int) FileInfo.size()); };
|
||||
|
||||
std::vector<FileInfos> FileInfo;
|
||||
std::vector<FileInfos> FileInfo;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -3,139 +3,139 @@
|
|||
|
||||
CFile::CFile()
|
||||
{
|
||||
file_fd = NULL;
|
||||
mem_file = NULL;
|
||||
filesize = 0;
|
||||
Pos = 0;
|
||||
file_fd = NULL;
|
||||
mem_file = NULL;
|
||||
filesize = 0;
|
||||
Pos = 0;
|
||||
}
|
||||
|
||||
CFile::CFile(const char * filepath, const char * mode)
|
||||
{
|
||||
file_fd = NULL;
|
||||
open(filepath, mode);
|
||||
file_fd = NULL;
|
||||
open(filepath, mode);
|
||||
}
|
||||
|
||||
CFile::CFile(const u8 * mem, int size)
|
||||
{
|
||||
file_fd = NULL;
|
||||
open(mem, size);
|
||||
file_fd = NULL;
|
||||
open(mem, size);
|
||||
}
|
||||
|
||||
CFile::~CFile()
|
||||
{
|
||||
close();
|
||||
close();
|
||||
}
|
||||
|
||||
int CFile::open(const char * filepath, const char * mode)
|
||||
{
|
||||
close();
|
||||
close();
|
||||
|
||||
file_fd = fopen(filepath, mode);
|
||||
if(!file_fd)
|
||||
return -1;
|
||||
file_fd = fopen(filepath, mode);
|
||||
if(!file_fd)
|
||||
return -1;
|
||||
|
||||
fseek(file_fd, 0, SEEK_END);
|
||||
filesize = ftell(file_fd);
|
||||
rewind();
|
||||
fseek(file_fd, 0, SEEK_END);
|
||||
filesize = ftell(file_fd);
|
||||
rewind();
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CFile::open(const u8 * mem, int size)
|
||||
{
|
||||
close();
|
||||
close();
|
||||
|
||||
mem_file = mem;
|
||||
filesize = size;
|
||||
mem_file = mem;
|
||||
filesize = size;
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void CFile::close()
|
||||
{
|
||||
if(file_fd)
|
||||
fclose(file_fd);
|
||||
if(file_fd)
|
||||
fclose(file_fd);
|
||||
|
||||
file_fd = NULL;
|
||||
mem_file = NULL;
|
||||
filesize = 0;
|
||||
Pos = 0;
|
||||
file_fd = NULL;
|
||||
mem_file = NULL;
|
||||
filesize = 0;
|
||||
Pos = 0;
|
||||
}
|
||||
|
||||
int CFile::read(u8 * ptr, size_t size)
|
||||
{
|
||||
if(file_fd)
|
||||
{
|
||||
int ret = fread(ptr, 1, size, file_fd);
|
||||
if(ret > 0)
|
||||
Pos += ret;
|
||||
return ret;
|
||||
}
|
||||
if(file_fd)
|
||||
{
|
||||
int ret = fread(ptr, 1, size, file_fd);
|
||||
if(ret > 0)
|
||||
Pos += ret;
|
||||
return ret;
|
||||
}
|
||||
|
||||
int readsize = size;
|
||||
int readsize = size;
|
||||
|
||||
if(readsize > (long int) filesize-Pos)
|
||||
readsize = filesize-Pos;
|
||||
if(readsize > (long int) filesize-Pos)
|
||||
readsize = filesize-Pos;
|
||||
|
||||
if(readsize <= 0)
|
||||
return readsize;
|
||||
if(readsize <= 0)
|
||||
return readsize;
|
||||
|
||||
if(mem_file != NULL)
|
||||
{
|
||||
memcpy(ptr, mem_file+Pos, readsize);
|
||||
Pos += readsize;
|
||||
return readsize;
|
||||
}
|
||||
if(mem_file != NULL)
|
||||
{
|
||||
memcpy(ptr, mem_file+Pos, readsize);
|
||||
Pos += readsize;
|
||||
return readsize;
|
||||
}
|
||||
|
||||
return -1;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int CFile::write(const u8 * ptr, size_t size)
|
||||
{
|
||||
if(file_fd)
|
||||
{
|
||||
int ret = fwrite(ptr, 1, size, file_fd);
|
||||
if(ret > 0)
|
||||
Pos += ret;
|
||||
return ret;
|
||||
}
|
||||
if(file_fd)
|
||||
{
|
||||
int ret = fwrite(ptr, 1, size, file_fd);
|
||||
if(ret > 0)
|
||||
Pos += ret;
|
||||
return ret;
|
||||
}
|
||||
|
||||
return -1;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int CFile::seek(long int offset, int origin)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
if(origin == SEEK_SET)
|
||||
{
|
||||
Pos = offset;
|
||||
}
|
||||
else if(origin == SEEK_CUR)
|
||||
{
|
||||
Pos += offset;
|
||||
}
|
||||
else if(origin == SEEK_END)
|
||||
{
|
||||
Pos = filesize+offset;
|
||||
}
|
||||
if(Pos < 0)
|
||||
{
|
||||
Pos = 0;
|
||||
return -1;
|
||||
}
|
||||
if(origin == SEEK_SET)
|
||||
{
|
||||
Pos = offset;
|
||||
}
|
||||
else if(origin == SEEK_CUR)
|
||||
{
|
||||
Pos += offset;
|
||||
}
|
||||
else if(origin == SEEK_END)
|
||||
{
|
||||
Pos = filesize+offset;
|
||||
}
|
||||
if(Pos < 0)
|
||||
{
|
||||
Pos = 0;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(file_fd)
|
||||
ret = fseek(file_fd, Pos, SEEK_SET);
|
||||
if(file_fd)
|
||||
ret = fseek(file_fd, Pos, SEEK_SET);
|
||||
|
||||
if(mem_file != NULL)
|
||||
{
|
||||
if(Pos > (long int) filesize)
|
||||
{
|
||||
Pos = filesize;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
if(mem_file != NULL)
|
||||
{
|
||||
if(Pos > (long int) filesize)
|
||||
{
|
||||
Pos = filesize;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
|
|
@ -6,25 +6,25 @@
|
|||
|
||||
class CFile
|
||||
{
|
||||
public:
|
||||
CFile();
|
||||
CFile(const char * filepath, const char * mode);
|
||||
CFile(const u8 * memory, int memsize);
|
||||
~CFile();
|
||||
int open(const char * filepath, const char * mode);
|
||||
int open(const u8 * memory, int memsize);
|
||||
void close();
|
||||
int read(u8 * ptr, size_t size);
|
||||
int write(const u8 * ptr, size_t size);
|
||||
int seek(long int offset, int origin);
|
||||
long int tell() { return Pos; };
|
||||
long int size() { return filesize; };
|
||||
void rewind() { seek(0, SEEK_SET); };
|
||||
protected:
|
||||
FILE * file_fd;
|
||||
const u8 * mem_file;
|
||||
u64 filesize;
|
||||
long int Pos;
|
||||
public:
|
||||
CFile();
|
||||
CFile(const char * filepath, const char * mode);
|
||||
CFile(const u8 * memory, int memsize);
|
||||
~CFile();
|
||||
int open(const char * filepath, const char * mode);
|
||||
int open(const u8 * memory, int memsize);
|
||||
void close();
|
||||
int read(u8 * ptr, size_t size);
|
||||
int write(const u8 * ptr, size_t size);
|
||||
int seek(long int offset, int origin);
|
||||
long int tell() { return Pos; };
|
||||
long int size() { return filesize; };
|
||||
void rewind() { seek(0, SEEK_SET); };
|
||||
protected:
|
||||
FILE * file_fd;
|
||||
const u8 * mem_file;
|
||||
u64 filesize;
|
||||
long int Pos;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -37,7 +37,7 @@
|
|||
|
||||
#include "fileops.h"
|
||||
|
||||
#define BLOCKSIZE 70*1024 //70KB
|
||||
#define BLOCKSIZE 70*1024 //70KB
|
||||
#define VectorResize(List) if(List.capacity()-List.size() == 0) List.reserve(List.size()+100)
|
||||
|
||||
|
||||
|
@ -50,27 +50,27 @@ static bool actioncanceled = false;
|
|||
***************************************************************************/
|
||||
extern "C" bool CheckFile(const char * filepath)
|
||||
{
|
||||
if(!filepath)
|
||||
return false;
|
||||
if(!filepath)
|
||||
return false;
|
||||
|
||||
struct stat filestat;
|
||||
struct stat filestat;
|
||||
|
||||
char dirnoslash[strlen(filepath)+2];
|
||||
snprintf(dirnoslash, sizeof(dirnoslash), "%s", filepath);
|
||||
char dirnoslash[strlen(filepath)+2];
|
||||
snprintf(dirnoslash, sizeof(dirnoslash), "%s", filepath);
|
||||
|
||||
while(dirnoslash[strlen(dirnoslash)-1] == '/')
|
||||
dirnoslash[strlen(dirnoslash)-1] = '\0';
|
||||
while(dirnoslash[strlen(dirnoslash)-1] == '/')
|
||||
dirnoslash[strlen(dirnoslash)-1] = '\0';
|
||||
|
||||
char * notRoot = strrchr(dirnoslash, '/');
|
||||
if(!notRoot)
|
||||
{
|
||||
strcat(dirnoslash, "/");
|
||||
strcat(dirnoslash, "/");
|
||||
}
|
||||
|
||||
if (stat(dirnoslash, &filestat) == 0)
|
||||
return true;
|
||||
if (stat(dirnoslash, &filestat) == 0)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
|
@ -83,7 +83,7 @@ extern "C" u64 FileSize(const char * filepath)
|
|||
struct stat filestat;
|
||||
|
||||
if (stat(filepath, &filestat) != 0)
|
||||
return 0;
|
||||
return 0;
|
||||
|
||||
return filestat.st_size;
|
||||
}
|
||||
|
@ -95,72 +95,72 @@ extern "C" u64 FileSize(const char * filepath)
|
|||
***************************************************************************/
|
||||
extern "C" int LoadFileToMem(const char *filepath, u8 **inbuffer, u64 *size)
|
||||
{
|
||||
int ret = -1;
|
||||
u64 filesize = FileSize(filepath);
|
||||
int ret = -1;
|
||||
u64 filesize = FileSize(filepath);
|
||||
char * filename = strrchr(filepath, '/');
|
||||
if(filename)
|
||||
filename++;
|
||||
filename++;
|
||||
|
||||
*inbuffer = NULL;
|
||||
*size = 0;
|
||||
*inbuffer = NULL;
|
||||
*size = 0;
|
||||
|
||||
FILE *file = fopen(filepath, "rb");
|
||||
FILE *file = fopen(filepath, "rb");
|
||||
|
||||
if (file == NULL)
|
||||
return -1;
|
||||
if (file == NULL)
|
||||
return -1;
|
||||
|
||||
u8 *buffer = (u8 *) malloc(filesize);
|
||||
if (buffer == NULL)
|
||||
{
|
||||
fclose(file);
|
||||
return -2;
|
||||
}
|
||||
u8 *buffer = (u8 *) malloc(filesize);
|
||||
if (buffer == NULL)
|
||||
{
|
||||
fclose(file);
|
||||
return -2;
|
||||
}
|
||||
|
||||
u64 done = 0;
|
||||
u32 blocksize = BLOCKSIZE;
|
||||
u64 done = 0;
|
||||
u32 blocksize = BLOCKSIZE;
|
||||
|
||||
do
|
||||
{
|
||||
if(actioncanceled)
|
||||
{
|
||||
free(buffer);
|
||||
fclose(file);
|
||||
return -10;
|
||||
}
|
||||
do
|
||||
{
|
||||
if(actioncanceled)
|
||||
{
|
||||
free(buffer);
|
||||
fclose(file);
|
||||
return -10;
|
||||
}
|
||||
|
||||
if(blocksize > filesize-done)
|
||||
blocksize = filesize-done;
|
||||
if(blocksize > filesize-done)
|
||||
blocksize = filesize-done;
|
||||
|
||||
ret = fread(buffer+done, 1, blocksize, file);
|
||||
if(ret < 0)
|
||||
{
|
||||
free(buffer);
|
||||
fclose(file);
|
||||
return -3;
|
||||
}
|
||||
else if(ret == 0)
|
||||
{
|
||||
//we are done
|
||||
break;
|
||||
}
|
||||
ret = fread(buffer+done, 1, blocksize, file);
|
||||
if(ret < 0)
|
||||
{
|
||||
free(buffer);
|
||||
fclose(file);
|
||||
return -3;
|
||||
}
|
||||
else if(ret == 0)
|
||||
{
|
||||
//we are done
|
||||
break;
|
||||
}
|
||||
|
||||
done += ret;
|
||||
done += ret;
|
||||
|
||||
}
|
||||
while(done < filesize);
|
||||
}
|
||||
while(done < filesize);
|
||||
|
||||
fclose(file);
|
||||
fclose(file);
|
||||
|
||||
if (done != filesize)
|
||||
{
|
||||
free(buffer);
|
||||
return -3;
|
||||
}
|
||||
if (done != filesize)
|
||||
{
|
||||
free(buffer);
|
||||
return -3;
|
||||
}
|
||||
|
||||
*inbuffer = buffer;
|
||||
*size = filesize;
|
||||
*inbuffer = buffer;
|
||||
*size = filesize;
|
||||
|
||||
return 1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
|
@ -171,7 +171,7 @@ extern "C" int LoadFileToMem(const char *filepath, u8 **inbuffer, u64 *size)
|
|||
extern "C" int LoadFileToMemWithProgress(const char *progressText, const char *filepath, u8 **inbuffer, u64 *size)
|
||||
{
|
||||
|
||||
int ret = LoadFileToMem(filepath, inbuffer, size);
|
||||
int ret = LoadFileToMem(filepath, inbuffer, size);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
@ -183,57 +183,57 @@ extern "C" int LoadFileToMemWithProgress(const char *progressText, const char *f
|
|||
***************************************************************************/
|
||||
extern "C" bool CreateSubfolder(const char * fullpath)
|
||||
{
|
||||
if(!fullpath)
|
||||
return false;
|
||||
if(!fullpath)
|
||||
return false;
|
||||
|
||||
bool result = false;
|
||||
bool result = false;
|
||||
|
||||
char dirnoslash[strlen(fullpath)+1];
|
||||
strcpy(dirnoslash, fullpath);
|
||||
char dirnoslash[strlen(fullpath)+1];
|
||||
strcpy(dirnoslash, fullpath);
|
||||
|
||||
int pos = strlen(dirnoslash)-1;
|
||||
while(dirnoslash[pos] == '/')
|
||||
{
|
||||
dirnoslash[pos] = '\0';
|
||||
pos--;
|
||||
}
|
||||
int pos = strlen(dirnoslash)-1;
|
||||
while(dirnoslash[pos] == '/')
|
||||
{
|
||||
dirnoslash[pos] = '\0';
|
||||
pos--;
|
||||
}
|
||||
|
||||
if(CheckFile(dirnoslash))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
char parentpath[strlen(dirnoslash)+2];
|
||||
strcpy(parentpath, dirnoslash);
|
||||
char * ptr = strrchr(parentpath, '/');
|
||||
if(CheckFile(dirnoslash))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
char parentpath[strlen(dirnoslash)+2];
|
||||
strcpy(parentpath, dirnoslash);
|
||||
char * ptr = strrchr(parentpath, '/');
|
||||
|
||||
if(!ptr)
|
||||
{
|
||||
//!Device root directory (must be with '/')
|
||||
strcat(parentpath, "/");
|
||||
struct stat filestat;
|
||||
if (stat(parentpath, &filestat) == 0)
|
||||
return true;
|
||||
if(!ptr)
|
||||
{
|
||||
//!Device root directory (must be with '/')
|
||||
strcat(parentpath, "/");
|
||||
struct stat filestat;
|
||||
if (stat(parentpath, &filestat) == 0)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
ptr++;
|
||||
ptr[0] = '\0';
|
||||
ptr++;
|
||||
ptr[0] = '\0';
|
||||
|
||||
result = CreateSubfolder(parentpath);
|
||||
}
|
||||
result = CreateSubfolder(parentpath);
|
||||
}
|
||||
|
||||
if(!result)
|
||||
return false;
|
||||
if(!result)
|
||||
return false;
|
||||
|
||||
if (mkdir(dirnoslash, 0777) == -1)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (mkdir(dirnoslash, 0777) == -1)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
|
@ -243,14 +243,14 @@ extern "C" bool CreateSubfolder(const char * fullpath)
|
|||
***************************************************************************/
|
||||
static bool CompareDevices(const char *src, const char *dest)
|
||||
{
|
||||
if(!src || !dest)
|
||||
return false;
|
||||
if(!src || !dest)
|
||||
return false;
|
||||
|
||||
char *device1 = strchr(src, ':');
|
||||
char *device2 = strchr(dest, ':');
|
||||
char *device1 = strchr(src, ':');
|
||||
char *device2 = strchr(dest, ':');
|
||||
|
||||
if(!device1 || !device2)
|
||||
return false;
|
||||
return false;
|
||||
|
||||
int position1 = device1-src+1;
|
||||
int position2 = device2-dest+1;
|
||||
|
@ -261,10 +261,10 @@ static bool CompareDevices(const char *src, const char *dest)
|
|||
snprintf(temp1, position1, "%s", src);
|
||||
snprintf(temp2, position2, "%s", dest);
|
||||
|
||||
if(strcasecmp(temp1, temp2) == 0)
|
||||
return true;
|
||||
if(strcasecmp(temp1, temp2) == 0)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
|
@ -279,83 +279,83 @@ extern "C" int CopyFile(const char * src, const char * dest)
|
|||
|
||||
char * filename = strrchr(src, '/');
|
||||
if(filename)
|
||||
filename++;
|
||||
else
|
||||
return -1;
|
||||
filename++;
|
||||
else
|
||||
return -1;
|
||||
|
||||
u64 sizesrc = FileSize(src);
|
||||
u64 sizesrc = FileSize(src);
|
||||
|
||||
FILE * source = fopen(src, "rb");
|
||||
|
||||
if(!source)
|
||||
return -2;
|
||||
|
||||
u32 blksize = BLOCKSIZE;
|
||||
u32 blksize = BLOCKSIZE;
|
||||
|
||||
u8 * buffer = (u8 *) malloc(blksize);
|
||||
|
||||
if(buffer == NULL){
|
||||
//no memory
|
||||
fclose(source);
|
||||
//no memory
|
||||
fclose(source);
|
||||
return -1;
|
||||
}
|
||||
|
||||
FILE * destination = fopen(dest, "wb");
|
||||
|
||||
if(destination == NULL)
|
||||
{
|
||||
free(buffer);
|
||||
fclose(source);
|
||||
return -3;
|
||||
}
|
||||
if(destination == NULL)
|
||||
{
|
||||
free(buffer);
|
||||
fclose(source);
|
||||
return -3;
|
||||
}
|
||||
|
||||
u64 done = 0;
|
||||
u64 done = 0;
|
||||
|
||||
do
|
||||
{
|
||||
if(actioncanceled)
|
||||
{
|
||||
fclose(source);
|
||||
fclose(destination);
|
||||
free(buffer);
|
||||
RemoveFile((char *) dest);
|
||||
return -10;
|
||||
}
|
||||
do
|
||||
{
|
||||
if(actioncanceled)
|
||||
{
|
||||
fclose(source);
|
||||
fclose(destination);
|
||||
free(buffer);
|
||||
RemoveFile((char *) dest);
|
||||
return -10;
|
||||
}
|
||||
|
||||
if(blksize > sizesrc - done)
|
||||
blksize = sizesrc - done;
|
||||
if(blksize > sizesrc - done)
|
||||
blksize = sizesrc - done;
|
||||
|
||||
//Display progress
|
||||
read = fread(buffer, 1, blksize, source);
|
||||
if(read < 0)
|
||||
{
|
||||
fclose(source);
|
||||
fclose(destination);
|
||||
free(buffer);
|
||||
RemoveFile((char *) dest);
|
||||
return -3;
|
||||
}
|
||||
//Display progress
|
||||
read = fread(buffer, 1, blksize, source);
|
||||
if(read < 0)
|
||||
{
|
||||
fclose(source);
|
||||
fclose(destination);
|
||||
free(buffer);
|
||||
RemoveFile((char *) dest);
|
||||
return -3;
|
||||
}
|
||||
|
||||
wrote = fwrite(buffer, 1, read, destination);
|
||||
if(wrote < 0)
|
||||
{
|
||||
fclose(source);
|
||||
fclose(destination);
|
||||
free(buffer);
|
||||
RemoveFile((char *) dest);
|
||||
return -3;
|
||||
}
|
||||
wrote = fwrite(buffer, 1, read, destination);
|
||||
if(wrote < 0)
|
||||
{
|
||||
fclose(source);
|
||||
fclose(destination);
|
||||
free(buffer);
|
||||
RemoveFile((char *) dest);
|
||||
return -3;
|
||||
}
|
||||
|
||||
done += wrote;
|
||||
}
|
||||
while (read > 0);
|
||||
done += wrote;
|
||||
}
|
||||
while (read > 0);
|
||||
|
||||
free(buffer);
|
||||
fclose(source);
|
||||
fclose(destination);
|
||||
free(buffer);
|
||||
fclose(source);
|
||||
fclose(destination);
|
||||
|
||||
if(sizesrc != done)
|
||||
return -4;
|
||||
if(sizesrc != done)
|
||||
return -4;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
@ -367,22 +367,22 @@ extern "C" int CopyFile(const char * src, const char * dest)
|
|||
***************************************************************************/
|
||||
extern "C" int MoveFile(const char *srcpath, char *destdir)
|
||||
{
|
||||
if(CompareDevices(srcpath, destdir))
|
||||
{
|
||||
if(RenameFile(srcpath, destdir))
|
||||
return 1;
|
||||
else
|
||||
return -1;
|
||||
}
|
||||
if(CompareDevices(srcpath, destdir))
|
||||
{
|
||||
if(RenameFile(srcpath, destdir))
|
||||
return 1;
|
||||
else
|
||||
return -1;
|
||||
}
|
||||
|
||||
int res = CopyFile(srcpath, destdir);
|
||||
if(res < 0)
|
||||
return -1;
|
||||
int res = CopyFile(srcpath, destdir);
|
||||
if(res < 0)
|
||||
return -1;
|
||||
|
||||
if(RemoveFile(srcpath))
|
||||
return 1;
|
||||
if(RemoveFile(srcpath))
|
||||
return 1;
|
||||
|
||||
return -1;
|
||||
return -1;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
|
@ -392,7 +392,7 @@ extern "C" int MoveFile(const char *srcpath, char *destdir)
|
|||
***************************************************************************/
|
||||
extern "C" bool RemoveFile(const char * filepath)
|
||||
{
|
||||
return (remove(filepath) == 0);
|
||||
return (remove(filepath) == 0);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
|
@ -402,5 +402,5 @@ extern "C" bool RemoveFile(const char * filepath)
|
|||
***************************************************************************/
|
||||
extern "C" bool RenameFile(const char * srcpath, const char * destpath)
|
||||
{
|
||||
return (rename(srcpath, destpath) == 0);
|
||||
return (rename(srcpath, destpath) == 0);
|
||||
}
|
||||
|
|
|
@ -41,23 +41,23 @@ using namespace std;
|
|||
|
||||
wchar_t* charToWideChar(const char* strChar)
|
||||
{
|
||||
if (!strChar) return NULL;
|
||||
if (!strChar) return NULL;
|
||||
|
||||
wchar_t *strWChar = new (std::nothrow) wchar_t[strlen(strChar) + 1];
|
||||
if (!strWChar) return NULL;
|
||||
wchar_t *strWChar = new (std::nothrow) wchar_t[strlen(strChar) + 1];
|
||||
if (!strWChar) return NULL;
|
||||
|
||||
int bt = mbstowcs(strWChar, strChar, strlen(strChar));
|
||||
if (bt > 0)
|
||||
{
|
||||
strWChar[bt] = 0;
|
||||
return strWChar;
|
||||
}
|
||||
int bt = mbstowcs(strWChar, strChar, strlen(strChar));
|
||||
if (bt > 0)
|
||||
{
|
||||
strWChar[bt] = 0;
|
||||
return strWChar;
|
||||
}
|
||||
|
||||
wchar_t *tempDest = strWChar;
|
||||
while ((*tempDest++ = *strChar++))
|
||||
;
|
||||
wchar_t *tempDest = strWChar;
|
||||
while ((*tempDest++ = *strChar++))
|
||||
;
|
||||
|
||||
return strWChar;
|
||||
return strWChar;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -66,20 +66,20 @@ wchar_t* charToWideChar(const char* strChar)
|
|||
FreeTypeGX::FreeTypeGX(const uint8_t* fontBuffer, FT_Long bufferSize, bool lastFace)
|
||||
{
|
||||
int faceIndex = 0;
|
||||
ftPointSize = 0;
|
||||
ftPointSize = 0;
|
||||
|
||||
FT_Init_FreeType(&ftLibrary);
|
||||
if(lastFace)
|
||||
{
|
||||
FT_Init_FreeType(&ftLibrary);
|
||||
if(lastFace)
|
||||
{
|
||||
FT_New_Memory_Face(ftLibrary, (FT_Byte *)fontBuffer, bufferSize, -1, &ftFace);
|
||||
faceIndex = ftFace->num_faces - 1; // Use the last face
|
||||
FT_Done_Face(ftFace);
|
||||
ftFace = NULL;
|
||||
}
|
||||
FT_New_Memory_Face(ftLibrary, (FT_Byte *) fontBuffer, bufferSize, faceIndex, &ftFace);
|
||||
}
|
||||
FT_New_Memory_Face(ftLibrary, (FT_Byte *) fontBuffer, bufferSize, faceIndex, &ftFace);
|
||||
|
||||
setVertexFormat(GX_VTXFMT1);
|
||||
ftKerningEnabled = false;//FT_HAS_KERNING(ftFace);
|
||||
setVertexFormat(GX_VTXFMT1);
|
||||
ftKerningEnabled = false;//FT_HAS_KERNING(ftFace);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -87,9 +87,9 @@ FreeTypeGX::FreeTypeGX(const uint8_t* fontBuffer, FT_Long bufferSize, bool lastF
|
|||
*/
|
||||
FreeTypeGX::~FreeTypeGX()
|
||||
{
|
||||
unloadFont();
|
||||
FT_Done_Face(ftFace);
|
||||
FT_Done_FreeType(ftLibrary);
|
||||
unloadFont();
|
||||
FT_Done_Face(ftFace);
|
||||
FT_Done_FreeType(ftLibrary);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -103,10 +103,10 @@ FreeTypeGX::~FreeTypeGX()
|
|||
*/
|
||||
void FreeTypeGX::setVertexFormat(uint8_t vertexInd)
|
||||
{
|
||||
vertexIndex = vertexInd;
|
||||
GX_SetVtxAttrFmt(vertexIndex, GX_VA_POS, GX_POS_XYZ, GX_S16, 0);
|
||||
GX_SetVtxAttrFmt(vertexIndex, GX_VA_TEX0, GX_TEX_ST, GX_F32, 0);
|
||||
GX_SetVtxAttrFmt(vertexIndex, GX_VA_CLR0, GX_CLR_RGBA, GX_RGBA8, 0);
|
||||
vertexIndex = vertexInd;
|
||||
GX_SetVtxAttrFmt(vertexIndex, GX_VA_POS, GX_POS_XYZ, GX_S16, 0);
|
||||
GX_SetVtxAttrFmt(vertexIndex, GX_VA_TEX0, GX_TEX_ST, GX_F32, 0);
|
||||
GX_SetVtxAttrFmt(vertexIndex, GX_VA_CLR0, GX_CLR_RGBA, GX_RGBA8, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -116,21 +116,21 @@ void FreeTypeGX::setVertexFormat(uint8_t vertexInd)
|
|||
*/
|
||||
void FreeTypeGX::unloadFont()
|
||||
{
|
||||
if (this->fontData.size() == 0) return;
|
||||
if (this->fontData.size() == 0) return;
|
||||
|
||||
map<int16_t, map<wchar_t, ftgxCharData> >::iterator itr;
|
||||
map<wchar_t, ftgxCharData>::iterator itr2;
|
||||
map<int16_t, map<wchar_t, ftgxCharData> >::iterator itr;
|
||||
map<wchar_t, ftgxCharData>::iterator itr2;
|
||||
|
||||
for (itr = fontData.begin(); itr != fontData.end(); itr++)
|
||||
{
|
||||
for (itr2 = itr->second.begin(); itr2 != itr->second.end(); itr2++)
|
||||
free(itr2->second.glyphDataTexture);
|
||||
for (itr = fontData.begin(); itr != fontData.end(); itr++)
|
||||
{
|
||||
for (itr2 = itr->second.begin(); itr2 != itr->second.end(); itr2++)
|
||||
free(itr2->second.glyphDataTexture);
|
||||
|
||||
itr->second.clear();
|
||||
}
|
||||
itr->second.clear();
|
||||
}
|
||||
|
||||
fontData.clear();
|
||||
ftgxAlign.clear();
|
||||
fontData.clear();
|
||||
ftgxAlign.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -144,65 +144,65 @@ void FreeTypeGX::unloadFont()
|
|||
*/
|
||||
ftgxCharData * FreeTypeGX::cacheGlyphData(wchar_t charCode, int16_t pixelSize)
|
||||
{
|
||||
map<int16_t, map<wchar_t, ftgxCharData> >::iterator itr = fontData.find(pixelSize);
|
||||
if (itr != fontData.end())
|
||||
{
|
||||
map<wchar_t, ftgxCharData>::iterator itr2 = itr->second.find(charCode);
|
||||
if (itr2 != itr->second.end())
|
||||
{
|
||||
return &itr2->second;
|
||||
}
|
||||
}
|
||||
map<int16_t, map<wchar_t, ftgxCharData> >::iterator itr = fontData.find(pixelSize);
|
||||
if (itr != fontData.end())
|
||||
{
|
||||
map<wchar_t, ftgxCharData>::iterator itr2 = itr->second.find(charCode);
|
||||
if (itr2 != itr->second.end())
|
||||
{
|
||||
return &itr2->second;
|
||||
}
|
||||
}
|
||||
|
||||
FT_UInt gIndex;
|
||||
uint16_t textureWidth = 0, textureHeight = 0;
|
||||
FT_UInt gIndex;
|
||||
uint16_t textureWidth = 0, textureHeight = 0;
|
||||
|
||||
if (ftPointSize != pixelSize)
|
||||
{
|
||||
ftPointSize = pixelSize;
|
||||
FT_Set_Pixel_Sizes(ftFace, 0, ftPointSize);
|
||||
if (ftPointSize != pixelSize)
|
||||
{
|
||||
ftPointSize = pixelSize;
|
||||
FT_Set_Pixel_Sizes(ftFace, 0, ftPointSize);
|
||||
|
||||
//!Cache ascender and decender as well
|
||||
map<int16_t, ftgxDataOffset>::iterator itrAlign = ftgxAlign.find(ftPointSize);
|
||||
if (itrAlign == ftgxAlign.end())
|
||||
{
|
||||
ftgxAlign[ftPointSize].ascender = (int16_t) ftFace->size->metrics.ascender >> 6;
|
||||
ftgxAlign[ftPointSize].descender = (int16_t) ftFace->size->metrics.descender >> 6;
|
||||
ftgxAlign[ftPointSize].max = 0;
|
||||
ftgxAlign[ftPointSize].min = 0;
|
||||
}
|
||||
}
|
||||
//!Cache ascender and decender as well
|
||||
map<int16_t, ftgxDataOffset>::iterator itrAlign = ftgxAlign.find(ftPointSize);
|
||||
if (itrAlign == ftgxAlign.end())
|
||||
{
|
||||
ftgxAlign[ftPointSize].ascender = (int16_t) ftFace->size->metrics.ascender >> 6;
|
||||
ftgxAlign[ftPointSize].descender = (int16_t) ftFace->size->metrics.descender >> 6;
|
||||
ftgxAlign[ftPointSize].max = 0;
|
||||
ftgxAlign[ftPointSize].min = 0;
|
||||
}
|
||||
}
|
||||
|
||||
gIndex = FT_Get_Char_Index(ftFace, (FT_ULong) charCode);
|
||||
if (gIndex != 0 && FT_Load_Glyph(ftFace, gIndex, FT_LOAD_DEFAULT | FT_LOAD_RENDER) == 0)
|
||||
{
|
||||
if (ftFace->glyph->format == FT_GLYPH_FORMAT_BITMAP)
|
||||
{
|
||||
FT_Bitmap *glyphBitmap = &ftFace->glyph->bitmap;
|
||||
gIndex = FT_Get_Char_Index(ftFace, (FT_ULong) charCode);
|
||||
if (gIndex != 0 && FT_Load_Glyph(ftFace, gIndex, FT_LOAD_DEFAULT | FT_LOAD_RENDER) == 0)
|
||||
{
|
||||
if (ftFace->glyph->format == FT_GLYPH_FORMAT_BITMAP)
|
||||
{
|
||||
FT_Bitmap *glyphBitmap = &ftFace->glyph->bitmap;
|
||||
|
||||
textureWidth = ALIGN8(glyphBitmap->width);
|
||||
textureHeight = ALIGN8(glyphBitmap->rows);
|
||||
if(textureWidth == 0)
|
||||
textureWidth = 8;
|
||||
if(textureHeight == 0)
|
||||
textureHeight = 8;
|
||||
textureWidth = ALIGN8(glyphBitmap->width);
|
||||
textureHeight = ALIGN8(glyphBitmap->rows);
|
||||
if(textureWidth == 0)
|
||||
textureWidth = 8;
|
||||
if(textureHeight == 0)
|
||||
textureHeight = 8;
|
||||
|
||||
fontData[pixelSize][charCode].renderOffsetX = (int16_t) ftFace->glyph->bitmap_left;
|
||||
fontData[pixelSize][charCode].glyphAdvanceX = (uint16_t) (ftFace->glyph->advance.x >> 6);
|
||||
fontData[pixelSize][charCode].glyphIndex = (uint32_t) gIndex;
|
||||
fontData[pixelSize][charCode].textureWidth = (uint16_t) textureWidth;
|
||||
fontData[pixelSize][charCode].textureHeight = (uint16_t) textureHeight;
|
||||
fontData[pixelSize][charCode].renderOffsetY = (int16_t) ftFace->glyph->bitmap_top;
|
||||
fontData[pixelSize][charCode].renderOffsetMax = (int16_t) ftFace->glyph->bitmap_top;
|
||||
fontData[pixelSize][charCode].renderOffsetMin = (int16_t) glyphBitmap->rows - ftFace->glyph->bitmap_top;
|
||||
fontData[pixelSize][charCode].glyphDataTexture = NULL;
|
||||
fontData[pixelSize][charCode].renderOffsetX = (int16_t) ftFace->glyph->bitmap_left;
|
||||
fontData[pixelSize][charCode].glyphAdvanceX = (uint16_t) (ftFace->glyph->advance.x >> 6);
|
||||
fontData[pixelSize][charCode].glyphIndex = (uint32_t) gIndex;
|
||||
fontData[pixelSize][charCode].textureWidth = (uint16_t) textureWidth;
|
||||
fontData[pixelSize][charCode].textureHeight = (uint16_t) textureHeight;
|
||||
fontData[pixelSize][charCode].renderOffsetY = (int16_t) ftFace->glyph->bitmap_top;
|
||||
fontData[pixelSize][charCode].renderOffsetMax = (int16_t) ftFace->glyph->bitmap_top;
|
||||
fontData[pixelSize][charCode].renderOffsetMin = (int16_t) glyphBitmap->rows - ftFace->glyph->bitmap_top;
|
||||
fontData[pixelSize][charCode].glyphDataTexture = NULL;
|
||||
|
||||
loadGlyphData(glyphBitmap, &fontData[pixelSize][charCode]);
|
||||
loadGlyphData(glyphBitmap, &fontData[pixelSize][charCode]);
|
||||
|
||||
return &fontData[pixelSize][charCode];
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
return &fontData[pixelSize][charCode];
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -213,16 +213,16 @@ ftgxCharData * FreeTypeGX::cacheGlyphData(wchar_t charCode, int16_t pixelSize)
|
|||
*/
|
||||
uint16_t FreeTypeGX::cacheGlyphDataComplete(int16_t pixelSize)
|
||||
{
|
||||
uint32_t i = 0;
|
||||
FT_UInt gIndex;
|
||||
uint32_t i = 0;
|
||||
FT_UInt gIndex;
|
||||
|
||||
FT_ULong charCode = FT_Get_First_Char(ftFace, &gIndex);
|
||||
while (gIndex != 0)
|
||||
{
|
||||
if (cacheGlyphData(charCode, pixelSize) != NULL) ++i;
|
||||
charCode = FT_Get_Next_Char(ftFace, charCode, &gIndex);
|
||||
}
|
||||
return (uint16_t) (i);
|
||||
FT_ULong charCode = FT_Get_First_Char(ftFace, &gIndex);
|
||||
while (gIndex != 0)
|
||||
{
|
||||
if (cacheGlyphData(charCode, pixelSize) != NULL) ++i;
|
||||
charCode = FT_Get_Next_Char(ftFace, charCode, &gIndex);
|
||||
}
|
||||
return (uint16_t) (i);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -237,7 +237,7 @@ uint16_t FreeTypeGX::cacheGlyphDataComplete(int16_t pixelSize)
|
|||
|
||||
void FreeTypeGX::loadGlyphData(FT_Bitmap *bmp, ftgxCharData *charData)
|
||||
{
|
||||
uint32_t *glyphData = (uint32_t *) memalign(32, charData->textureWidth * charData->textureHeight * 4);
|
||||
uint32_t *glyphData = (uint32_t *) memalign(32, charData->textureWidth * charData->textureHeight * 4);
|
||||
memset(glyphData, 0x00, charData->textureWidth * charData->textureHeight * 4);
|
||||
|
||||
uint8_t *bmsrc = (uint8_t *)bmp->buffer;
|
||||
|
@ -278,7 +278,7 @@ void FreeTypeGX::loadGlyphData(FT_Bitmap *bmp, ftgxCharData *charData)
|
|||
DCFlushRange(dataBufferIA4, bufferSize);
|
||||
free(glyphData);
|
||||
|
||||
charData->glyphDataTexture = (uint8_t *) dataBufferIA4;
|
||||
charData->glyphDataTexture = (uint8_t *) dataBufferIA4;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -287,16 +287,16 @@ void FreeTypeGX::loadGlyphData(FT_Bitmap *bmp, ftgxCharData *charData)
|
|||
* This routine calculates the x offset of the rendered string based off of a supplied positional format parameter.
|
||||
*
|
||||
* @param width Current pixel width of the string.
|
||||
* @param format Positional format of the string.
|
||||
* @param format Positional format of the string.
|
||||
*/
|
||||
int16_t FreeTypeGX::getStyleOffsetWidth(uint16_t width, uint16_t format)
|
||||
{
|
||||
if (format & FTGX_JUSTIFY_LEFT)
|
||||
return 0;
|
||||
else if (format & FTGX_JUSTIFY_CENTER)
|
||||
return -(width >> 1);
|
||||
else if (format & FTGX_JUSTIFY_RIGHT) return -width;
|
||||
return 0;
|
||||
if (format & FTGX_JUSTIFY_LEFT)
|
||||
return 0;
|
||||
else if (format & FTGX_JUSTIFY_CENTER)
|
||||
return -(width >> 1);
|
||||
else if (format & FTGX_JUSTIFY_RIGHT) return -width;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -304,39 +304,39 @@ int16_t FreeTypeGX::getStyleOffsetWidth(uint16_t width, uint16_t format)
|
|||
*
|
||||
* This routine calculates the y offset of the rendered string based off of a supplied positional format parameter.
|
||||
*
|
||||
* @param offset Current pixel offset data of the string.
|
||||
* @param format Positional format of the string.
|
||||
* @param offset Current pixel offset data of the string.
|
||||
* @param format Positional format of the string.
|
||||
*/
|
||||
int16_t FreeTypeGX::getStyleOffsetHeight(int16_t format, uint16_t pixelSize)
|
||||
{
|
||||
map<int16_t, ftgxDataOffset>::iterator itrAlign = ftgxAlign.find(pixelSize);
|
||||
if (itrAlign == ftgxAlign.end()) return 0;
|
||||
map<int16_t, ftgxDataOffset>::iterator itrAlign = ftgxAlign.find(pixelSize);
|
||||
if (itrAlign == ftgxAlign.end()) return 0;
|
||||
|
||||
switch (format & FTGX_ALIGN_MASK)
|
||||
{
|
||||
case FTGX_ALIGN_TOP:
|
||||
return itrAlign->second.ascender;
|
||||
switch (format & FTGX_ALIGN_MASK)
|
||||
{
|
||||
case FTGX_ALIGN_TOP:
|
||||
return itrAlign->second.ascender;
|
||||
|
||||
case FTGX_ALIGN_MIDDLE:
|
||||
default:
|
||||
return (itrAlign->second.ascender + itrAlign->second.descender + 1) >> 1;
|
||||
case FTGX_ALIGN_MIDDLE:
|
||||
default:
|
||||
return (itrAlign->second.ascender + itrAlign->second.descender + 1) >> 1;
|
||||
|
||||
case FTGX_ALIGN_BOTTOM:
|
||||
return itrAlign->second.descender;
|
||||
case FTGX_ALIGN_BOTTOM:
|
||||
return itrAlign->second.descender;
|
||||
|
||||
case FTGX_ALIGN_BASELINE:
|
||||
return 0;
|
||||
case FTGX_ALIGN_BASELINE:
|
||||
return 0;
|
||||
|
||||
case FTGX_ALIGN_GLYPH_TOP:
|
||||
return itrAlign->second.max;
|
||||
case FTGX_ALIGN_GLYPH_TOP:
|
||||
return itrAlign->second.max;
|
||||
|
||||
case FTGX_ALIGN_GLYPH_MIDDLE:
|
||||
return (itrAlign->second.max + itrAlign->second.min + 1) >> 1;
|
||||
case FTGX_ALIGN_GLYPH_MIDDLE:
|
||||
return (itrAlign->second.max + itrAlign->second.min + 1) >> 1;
|
||||
|
||||
case FTGX_ALIGN_GLYPH_BOTTOM:
|
||||
return itrAlign->second.min;
|
||||
}
|
||||
return 0;
|
||||
case FTGX_ALIGN_GLYPH_BOTTOM:
|
||||
return itrAlign->second.min;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -354,69 +354,69 @@ int16_t FreeTypeGX::getStyleOffsetHeight(int16_t format, uint16_t pixelSize)
|
|||
*/
|
||||
|
||||
uint16_t FreeTypeGX::drawText(int16_t x, int16_t y, int16_t z, const wchar_t *text, int16_t pixelSize, GXColor color,
|
||||
uint16_t textStyle, uint16_t textWidth, uint16_t widthLimit)
|
||||
uint16_t textStyle, uint16_t textWidth, uint16_t widthLimit)
|
||||
{
|
||||
if (!text) return 0;
|
||||
if (!text) return 0;
|
||||
|
||||
uint16_t fullTextWidth = textWidth > 0 ? textWidth : getWidth(text, pixelSize);
|
||||
uint16_t x_pos = x, printed = 0;
|
||||
uint16_t x_offset = 0, y_offset = 0;
|
||||
GXTexObj glyphTexture;
|
||||
FT_Vector pairDelta;
|
||||
uint16_t fullTextWidth = textWidth > 0 ? textWidth : getWidth(text, pixelSize);
|
||||
uint16_t x_pos = x, printed = 0;
|
||||
uint16_t x_offset = 0, y_offset = 0;
|
||||
GXTexObj glyphTexture;
|
||||
FT_Vector pairDelta;
|
||||
|
||||
if (textStyle & FTGX_JUSTIFY_MASK)
|
||||
{
|
||||
x_offset = getStyleOffsetWidth(fullTextWidth, textStyle);
|
||||
}
|
||||
if (textStyle & FTGX_ALIGN_MASK)
|
||||
{
|
||||
y_offset = getStyleOffsetHeight(textStyle, pixelSize);
|
||||
}
|
||||
if (textStyle & FTGX_JUSTIFY_MASK)
|
||||
{
|
||||
x_offset = getStyleOffsetWidth(fullTextWidth, textStyle);
|
||||
}
|
||||
if (textStyle & FTGX_ALIGN_MASK)
|
||||
{
|
||||
y_offset = getStyleOffsetHeight(textStyle, pixelSize);
|
||||
}
|
||||
|
||||
int i = 0;
|
||||
int i = 0;
|
||||
|
||||
while (text[i])
|
||||
{
|
||||
if (widthLimit > 0 && (x_pos - x) > widthLimit) break;
|
||||
while (text[i])
|
||||
{
|
||||
if (widthLimit > 0 && (x_pos - x) > widthLimit) break;
|
||||
|
||||
ftgxCharData* glyphData = cacheGlyphData(text[i], pixelSize);
|
||||
ftgxCharData* glyphData = cacheGlyphData(text[i], pixelSize);
|
||||
|
||||
if (glyphData != NULL)
|
||||
{
|
||||
if (ftKerningEnabled && i > 0)
|
||||
{
|
||||
FT_Get_Kerning(ftFace, fontData[pixelSize][text[i - 1]].glyphIndex, glyphData->glyphIndex, FT_KERNING_DEFAULT, &pairDelta);
|
||||
x_pos += pairDelta.x >> 6;
|
||||
}
|
||||
if (glyphData != NULL)
|
||||
{
|
||||
if (ftKerningEnabled && i > 0)
|
||||
{
|
||||
FT_Get_Kerning(ftFace, fontData[pixelSize][text[i - 1]].glyphIndex, glyphData->glyphIndex, FT_KERNING_DEFAULT, &pairDelta);
|
||||
x_pos += pairDelta.x >> 6;
|
||||
}
|
||||
|
||||
GX_InitTexObj(&glyphTexture, glyphData->glyphDataTexture, glyphData->textureWidth, glyphData->textureHeight, GX_TF_IA4, GX_CLAMP, GX_CLAMP, GX_FALSE);
|
||||
copyTextureToFramebuffer(&glyphTexture, glyphData->textureWidth, glyphData->textureHeight, x_pos + glyphData->renderOffsetX + x_offset, y - glyphData->renderOffsetY + y_offset, z, color);
|
||||
GX_InitTexObj(&glyphTexture, glyphData->glyphDataTexture, glyphData->textureWidth, glyphData->textureHeight, GX_TF_IA4, GX_CLAMP, GX_CLAMP, GX_FALSE);
|
||||
copyTextureToFramebuffer(&glyphTexture, glyphData->textureWidth, glyphData->textureHeight, x_pos + glyphData->renderOffsetX + x_offset, y - glyphData->renderOffsetY + y_offset, z, color);
|
||||
|
||||
x_pos += glyphData->glyphAdvanceX;
|
||||
++printed;
|
||||
}
|
||||
++i;
|
||||
}
|
||||
x_pos += glyphData->glyphAdvanceX;
|
||||
++printed;
|
||||
}
|
||||
++i;
|
||||
}
|
||||
|
||||
if (textStyle & FTGX_STYLE_MASK)
|
||||
{
|
||||
getOffset(text, pixelSize, widthLimit);
|
||||
drawTextFeature(x + x_offset, y + y_offset, z, pixelSize, fullTextWidth, &ftgxAlign[pixelSize], textStyle,
|
||||
color);
|
||||
}
|
||||
if (textStyle & FTGX_STYLE_MASK)
|
||||
{
|
||||
getOffset(text, pixelSize, widthLimit);
|
||||
drawTextFeature(x + x_offset, y + y_offset, z, pixelSize, fullTextWidth, &ftgxAlign[pixelSize], textStyle,
|
||||
color);
|
||||
}
|
||||
|
||||
return printed;
|
||||
return printed;
|
||||
}
|
||||
|
||||
void FreeTypeGX::drawTextFeature(int16_t x, int16_t y, int16_t z, int16_t pixelSize, uint16_t width,
|
||||
ftgxDataOffset *offsetData, uint16_t format, GXColor color)
|
||||
ftgxDataOffset *offsetData, uint16_t format, GXColor color)
|
||||
{
|
||||
uint16_t featureHeight = pixelSize >> 4 > 0 ? pixelSize >> 4 : 1;
|
||||
uint16_t featureHeight = pixelSize >> 4 > 0 ? pixelSize >> 4 : 1;
|
||||
|
||||
if (format & FTGX_STYLE_UNDERLINE) this->copyFeatureToFramebuffer(width, featureHeight, x, y + 1, z, color);
|
||||
if (format & FTGX_STYLE_UNDERLINE) this->copyFeatureToFramebuffer(width, featureHeight, x, y + 1, z, color);
|
||||
|
||||
if (format & FTGX_STYLE_STRIKE) this->copyFeatureToFramebuffer(width, featureHeight, x, y
|
||||
- ((offsetData->max) >> 1), z, color);
|
||||
if (format & FTGX_STYLE_STRIKE) this->copyFeatureToFramebuffer(width, featureHeight, x, y
|
||||
- ((offsetData->max) >> 1), z, color);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -430,30 +430,30 @@ void FreeTypeGX::drawTextFeature(int16_t x, int16_t y, int16_t z, int16_t pixelS
|
|||
*/
|
||||
uint16_t FreeTypeGX::getWidth(const wchar_t *text, int16_t pixelSize)
|
||||
{
|
||||
if (!text) return 0;
|
||||
if (!text) return 0;
|
||||
|
||||
uint16_t strWidth = 0;
|
||||
FT_Vector pairDelta;
|
||||
uint16_t strWidth = 0;
|
||||
FT_Vector pairDelta;
|
||||
|
||||
int i = 0;
|
||||
while (text[i])
|
||||
{
|
||||
ftgxCharData* glyphData = cacheGlyphData(text[i], pixelSize);
|
||||
int i = 0;
|
||||
while (text[i])
|
||||
{
|
||||
ftgxCharData* glyphData = cacheGlyphData(text[i], pixelSize);
|
||||
|
||||
if (glyphData != NULL)
|
||||
{
|
||||
if (ftKerningEnabled && (i > 0))
|
||||
{
|
||||
FT_Get_Kerning(ftFace, fontData[pixelSize][text[i - 1]].glyphIndex, glyphData->glyphIndex,
|
||||
FT_KERNING_DEFAULT, &pairDelta);
|
||||
strWidth += pairDelta.x >> 6;
|
||||
}
|
||||
if (glyphData != NULL)
|
||||
{
|
||||
if (ftKerningEnabled && (i > 0))
|
||||
{
|
||||
FT_Get_Kerning(ftFace, fontData[pixelSize][text[i - 1]].glyphIndex, glyphData->glyphIndex,
|
||||
FT_KERNING_DEFAULT, &pairDelta);
|
||||
strWidth += pairDelta.x >> 6;
|
||||
}
|
||||
|
||||
strWidth += glyphData->glyphAdvanceX;
|
||||
}
|
||||
++i;
|
||||
}
|
||||
return strWidth;
|
||||
strWidth += glyphData->glyphAdvanceX;
|
||||
}
|
||||
++i;
|
||||
}
|
||||
return strWidth;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -461,22 +461,22 @@ uint16_t FreeTypeGX::getWidth(const wchar_t *text, int16_t pixelSize)
|
|||
*/
|
||||
uint16_t FreeTypeGX::getCharWidth(const wchar_t wChar, int16_t pixelSize, const wchar_t prevChar)
|
||||
{
|
||||
uint16_t strWidth = 0;
|
||||
ftgxCharData * glyphData = cacheGlyphData(wChar, pixelSize);
|
||||
uint16_t strWidth = 0;
|
||||
ftgxCharData * glyphData = cacheGlyphData(wChar, pixelSize);
|
||||
|
||||
if (glyphData != NULL)
|
||||
{
|
||||
if (ftKerningEnabled && prevChar != 0x0000)
|
||||
{
|
||||
FT_Vector pairDelta;
|
||||
FT_Get_Kerning(ftFace, fontData[pixelSize][prevChar].glyphIndex, glyphData->glyphIndex, FT_KERNING_DEFAULT,
|
||||
&pairDelta);
|
||||
strWidth += pairDelta.x >> 6;
|
||||
}
|
||||
strWidth += glyphData->glyphAdvanceX;
|
||||
}
|
||||
if (glyphData != NULL)
|
||||
{
|
||||
if (ftKerningEnabled && prevChar != 0x0000)
|
||||
{
|
||||
FT_Vector pairDelta;
|
||||
FT_Get_Kerning(ftFace, fontData[pixelSize][prevChar].glyphIndex, glyphData->glyphIndex, FT_KERNING_DEFAULT,
|
||||
&pairDelta);
|
||||
strWidth += pairDelta.x >> 6;
|
||||
}
|
||||
strWidth += glyphData->glyphAdvanceX;
|
||||
}
|
||||
|
||||
return strWidth;
|
||||
return strWidth;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -490,9 +490,9 @@ uint16_t FreeTypeGX::getCharWidth(const wchar_t wChar, int16_t pixelSize, const
|
|||
*/
|
||||
uint16_t FreeTypeGX::getHeight(const wchar_t *text, int16_t pixelSize)
|
||||
{
|
||||
getOffset(text, pixelSize);
|
||||
getOffset(text, pixelSize);
|
||||
|
||||
return ftgxAlign[pixelSize].max - ftgxAlign[pixelSize].min;
|
||||
return ftgxAlign[pixelSize].max - ftgxAlign[pixelSize].min;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -507,39 +507,39 @@ uint16_t FreeTypeGX::getHeight(const wchar_t *text, int16_t pixelSize)
|
|||
*/
|
||||
void FreeTypeGX::getOffset(const wchar_t *text, int16_t pixelSize, uint16_t widthLimit)
|
||||
{
|
||||
if (ftgxAlign.find(pixelSize) != ftgxAlign.end()) return;
|
||||
if (ftgxAlign.find(pixelSize) != ftgxAlign.end()) return;
|
||||
|
||||
int16_t strMax = 0, strMin = 9999;
|
||||
uint16_t currWidth = 0;
|
||||
int16_t strMax = 0, strMin = 9999;
|
||||
uint16_t currWidth = 0;
|
||||
|
||||
int i = 0;
|
||||
int i = 0;
|
||||
|
||||
while (text[i])
|
||||
{
|
||||
if (widthLimit > 0 && currWidth >= widthLimit) break;
|
||||
while (text[i])
|
||||
{
|
||||
if (widthLimit > 0 && currWidth >= widthLimit) break;
|
||||
|
||||
ftgxCharData* glyphData = cacheGlyphData(text[i], pixelSize);
|
||||
ftgxCharData* glyphData = cacheGlyphData(text[i], pixelSize);
|
||||
|
||||
if (glyphData != NULL)
|
||||
{
|
||||
strMax = glyphData->renderOffsetMax > strMax ? glyphData->renderOffsetMax : strMax;
|
||||
strMin = glyphData->renderOffsetMin < strMin ? glyphData->renderOffsetMin : strMin;
|
||||
currWidth += glyphData->glyphAdvanceX;
|
||||
}
|
||||
if (glyphData != NULL)
|
||||
{
|
||||
strMax = glyphData->renderOffsetMax > strMax ? glyphData->renderOffsetMax : strMax;
|
||||
strMin = glyphData->renderOffsetMin < strMin ? glyphData->renderOffsetMin : strMin;
|
||||
currWidth += glyphData->glyphAdvanceX;
|
||||
}
|
||||
|
||||
++i;
|
||||
}
|
||||
++i;
|
||||
}
|
||||
|
||||
if (ftPointSize != pixelSize)
|
||||
{
|
||||
ftPointSize = pixelSize;
|
||||
FT_Set_Pixel_Sizes(ftFace, 0, ftPointSize);
|
||||
}
|
||||
if (ftPointSize != pixelSize)
|
||||
{
|
||||
ftPointSize = pixelSize;
|
||||
FT_Set_Pixel_Sizes(ftFace, 0, ftPointSize);
|
||||
}
|
||||
|
||||
ftgxAlign[pixelSize].ascender = ftFace->size->metrics.ascender >> 6;
|
||||
ftgxAlign[pixelSize].descender = ftFace->size->metrics.descender >> 6;
|
||||
ftgxAlign[pixelSize].max = strMax;
|
||||
ftgxAlign[pixelSize].min = strMin;
|
||||
ftgxAlign[pixelSize].ascender = ftFace->size->metrics.ascender >> 6;
|
||||
ftgxAlign[pixelSize].descender = ftFace->size->metrics.descender >> 6;
|
||||
ftgxAlign[pixelSize].max = strMax;
|
||||
ftgxAlign[pixelSize].min = strMin;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -547,7 +547,7 @@ void FreeTypeGX::getOffset(const wchar_t *text, int16_t pixelSize, uint16_t widt
|
|||
*
|
||||
* This routine uses the in-built GX quad builder functions to define the texture bounds and location on the EFB target.
|
||||
*
|
||||
* @param texObj A pointer to the glyph's initialized texture object.
|
||||
* @param texObj A pointer to the glyph's initialized texture object.
|
||||
* @param texWidth The pixel width of the texture object.
|
||||
* @param texHeight The pixel height of the texture object.
|
||||
* @param screenX The screen X coordinate at which to output the rendered texture.
|
||||
|
@ -555,32 +555,32 @@ void FreeTypeGX::getOffset(const wchar_t *text, int16_t pixelSize, uint16_t widt
|
|||
* @param color Color to apply to the texture.
|
||||
*/
|
||||
void FreeTypeGX::copyTextureToFramebuffer(GXTexObj *texObj, f32 texWidth, f32 texHeight, int16_t screenX,
|
||||
int16_t screenY, int16_t screenZ, GXColor color)
|
||||
int16_t screenY, int16_t screenZ, GXColor color)
|
||||
{
|
||||
GX_LoadTexObj(texObj, GX_TEXMAP0);
|
||||
GX_InvalidateTexAll();
|
||||
GX_LoadTexObj(texObj, GX_TEXMAP0);
|
||||
GX_InvalidateTexAll();
|
||||
|
||||
GX_SetVtxDesc(GX_VA_POS, GX_DIRECT);
|
||||
GX_SetVtxDesc(GX_VA_TEX0, GX_DIRECT);
|
||||
GX_SetVtxDesc(GX_VA_CLR0, GX_DIRECT);
|
||||
GX_SetVtxDesc(GX_VA_POS, GX_DIRECT);
|
||||
GX_SetVtxDesc(GX_VA_TEX0, GX_DIRECT);
|
||||
GX_SetVtxDesc(GX_VA_CLR0, GX_DIRECT);
|
||||
|
||||
GX_Begin(GX_QUADS, this->vertexIndex, 4);
|
||||
GX_Position3s16(screenX, screenY, screenZ);
|
||||
GX_Color4u8(color.r, color.g, color.b, color.a);
|
||||
GX_TexCoord2f32(0.0f, 0.0f);
|
||||
GX_Begin(GX_QUADS, this->vertexIndex, 4);
|
||||
GX_Position3s16(screenX, screenY, screenZ);
|
||||
GX_Color4u8(color.r, color.g, color.b, color.a);
|
||||
GX_TexCoord2f32(0.0f, 0.0f);
|
||||
|
||||
GX_Position3s16(texWidth + screenX, screenY, screenZ);
|
||||
GX_Color4u8(color.r, color.g, color.b, color.a);
|
||||
GX_TexCoord2f32(1.0f, 0.0f);
|
||||
GX_Position3s16(texWidth + screenX, screenY, screenZ);
|
||||
GX_Color4u8(color.r, color.g, color.b, color.a);
|
||||
GX_TexCoord2f32(1.0f, 0.0f);
|
||||
|
||||
GX_Position3s16(texWidth + screenX, texHeight + screenY, screenZ);
|
||||
GX_Color4u8(color.r, color.g, color.b, color.a);
|
||||
GX_TexCoord2f32(1.0f, 1.0f);
|
||||
GX_Position3s16(texWidth + screenX, texHeight + screenY, screenZ);
|
||||
GX_Color4u8(color.r, color.g, color.b, color.a);
|
||||
GX_TexCoord2f32(1.0f, 1.0f);
|
||||
|
||||
GX_Position3s16(screenX, texHeight + screenY, screenZ);
|
||||
GX_Color4u8(color.r, color.g, color.b, color.a);
|
||||
GX_TexCoord2f32(0.0f, 1.0f);
|
||||
GX_End();
|
||||
GX_Position3s16(screenX, texHeight + screenY, screenZ);
|
||||
GX_Color4u8(color.r, color.g, color.b, color.a);
|
||||
GX_TexCoord2f32(0.0f, 1.0f);
|
||||
GX_End();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -595,26 +595,26 @@ void FreeTypeGX::copyTextureToFramebuffer(GXTexObj *texObj, f32 texWidth, f32 te
|
|||
* @param color Color to apply to the texture.
|
||||
*/
|
||||
void FreeTypeGX::copyFeatureToFramebuffer(f32 featureWidth, f32 featureHeight, int16_t screenX, int16_t screenY,
|
||||
int16_t screenZ, GXColor color)
|
||||
int16_t screenZ, GXColor color)
|
||||
{
|
||||
GX_SetTevOp(GX_TEVSTAGE0, GX_PASSCLR);
|
||||
GX_SetVtxDesc(GX_VA_POS, GX_DIRECT);
|
||||
GX_SetVtxDesc(GX_VA_CLR0, GX_DIRECT);
|
||||
GX_SetVtxDesc(GX_VA_TEX0, GX_NONE);
|
||||
GX_SetTevOp(GX_TEVSTAGE0, GX_PASSCLR);
|
||||
GX_SetVtxDesc(GX_VA_POS, GX_DIRECT);
|
||||
GX_SetVtxDesc(GX_VA_CLR0, GX_DIRECT);
|
||||
GX_SetVtxDesc(GX_VA_TEX0, GX_NONE);
|
||||
|
||||
GX_Begin(GX_QUADS, this->vertexIndex, 4);
|
||||
GX_Position3s16(screenX, screenY, screenZ);
|
||||
GX_Color4u8(color.r, color.g, color.b, color.a);
|
||||
GX_Begin(GX_QUADS, this->vertexIndex, 4);
|
||||
GX_Position3s16(screenX, screenY, screenZ);
|
||||
GX_Color4u8(color.r, color.g, color.b, color.a);
|
||||
|
||||
GX_Position3s16(featureWidth + screenX, screenY, screenZ);
|
||||
GX_Color4u8(color.r, color.g, color.b, color.a);
|
||||
GX_Position3s16(featureWidth + screenX, screenY, screenZ);
|
||||
GX_Color4u8(color.r, color.g, color.b, color.a);
|
||||
|
||||
GX_Position3s16(featureWidth + screenX, featureHeight + screenY, screenZ);
|
||||
GX_Color4u8(color.r, color.g, color.b, color.a);
|
||||
GX_Position3s16(featureWidth + screenX, featureHeight + screenY, screenZ);
|
||||
GX_Color4u8(color.r, color.g, color.b, color.a);
|
||||
|
||||
GX_Position3s16(screenX, featureHeight + screenY, screenZ);
|
||||
GX_Color4u8(color.r, color.g, color.b, color.a);
|
||||
GX_End();
|
||||
GX_Position3s16(screenX, featureHeight + screenY, screenZ);
|
||||
GX_Color4u8(color.r, color.g, color.b, color.a);
|
||||
GX_End();
|
||||
|
||||
GX_SetTevOp(GX_TEVSTAGE0, GX_MODULATE);
|
||||
GX_SetTevOp(GX_TEVSTAGE0, GX_MODULATE);
|
||||
}
|
||||
|
|
|
@ -39,18 +39,18 @@
|
|||
*/
|
||||
typedef struct ftgxCharData_
|
||||
{
|
||||
int16_t renderOffsetX; /**< Texture X axis bearing offset. */
|
||||
uint16_t glyphAdvanceX; /**< Character glyph X coordinate advance in pixels. */
|
||||
uint32_t glyphIndex; /**< Charachter glyph index in the font face. */
|
||||
int16_t renderOffsetX; /**< Texture X axis bearing offset. */
|
||||
uint16_t glyphAdvanceX; /**< Character glyph X coordinate advance in pixels. */
|
||||
uint32_t glyphIndex; /**< Charachter glyph index in the font face. */
|
||||
|
||||
uint16_t textureWidth; /**< Texture width in pixels/bytes. */
|
||||
uint16_t textureHeight; /**< Texture glyph height in pixels/bytes. */
|
||||
uint16_t textureWidth; /**< Texture width in pixels/bytes. */
|
||||
uint16_t textureHeight; /**< Texture glyph height in pixels/bytes. */
|
||||
|
||||
int16_t renderOffsetY; /**< Texture Y axis bearing offset. */
|
||||
int16_t renderOffsetMax; /**< Texture Y axis bearing maximum value. */
|
||||
int16_t renderOffsetMin; /**< Texture Y axis bearing minimum value. */
|
||||
int16_t renderOffsetY; /**< Texture Y axis bearing offset. */
|
||||
int16_t renderOffsetMax; /**< Texture Y axis bearing maximum value. */
|
||||
int16_t renderOffsetMin; /**< Texture Y axis bearing minimum value. */
|
||||
|
||||
uint8_t* glyphDataTexture; /**< Glyph texture bitmap data buffer. */
|
||||
uint8_t* glyphDataTexture; /**< Glyph texture bitmap data buffer. */
|
||||
} ftgxCharData;
|
||||
|
||||
/*! \struct ftgxDataOffset_
|
||||
|
@ -59,10 +59,10 @@ typedef struct ftgxCharData_
|
|||
*/
|
||||
typedef struct ftgxDataOffset_
|
||||
{
|
||||
int16_t ascender; /**< Maximum data offset. */
|
||||
int16_t descender; /**< Minimum data offset. */
|
||||
int16_t max; /**< Maximum data offset. */
|
||||
int16_t min; /**< Minimum data offset. */
|
||||
int16_t ascender; /**< Maximum data offset. */
|
||||
int16_t descender; /**< Minimum data offset. */
|
||||
int16_t max; /**< Maximum data offset. */
|
||||
int16_t min; /**< Minimum data offset. */
|
||||
} ftgxDataOffset;
|
||||
|
||||
typedef struct ftgxCharData_ ftgxCharData;
|
||||
|
@ -70,24 +70,24 @@ typedef struct ftgxDataOffset_ ftgxDataOffset;
|
|||
|
||||
#define _TEXT(t) L ## t /**< Unicode helper macro. */
|
||||
|
||||
#define FTGX_NULL 0x0000
|
||||
#define FTGX_JUSTIFY_LEFT 0x0001
|
||||
#define FTGX_JUSTIFY_CENTER 0x0002
|
||||
#define FTGX_JUSTIFY_RIGHT 0x0004
|
||||
#define FTGX_JUSTIFY_MASK 0x000f
|
||||
#define FTGX_NULL 0x0000
|
||||
#define FTGX_JUSTIFY_LEFT 0x0001
|
||||
#define FTGX_JUSTIFY_CENTER 0x0002
|
||||
#define FTGX_JUSTIFY_RIGHT 0x0004
|
||||
#define FTGX_JUSTIFY_MASK 0x000f
|
||||
|
||||
#define FTGX_ALIGN_TOP 0x0010
|
||||
#define FTGX_ALIGN_MIDDLE 0x0020
|
||||
#define FTGX_ALIGN_BOTTOM 0x0040
|
||||
#define FTGX_ALIGN_BASELINE 0x0080
|
||||
#define FTGX_ALIGN_GLYPH_TOP 0x0100
|
||||
#define FTGX_ALIGN_TOP 0x0010
|
||||
#define FTGX_ALIGN_MIDDLE 0x0020
|
||||
#define FTGX_ALIGN_BOTTOM 0x0040
|
||||
#define FTGX_ALIGN_BASELINE 0x0080
|
||||
#define FTGX_ALIGN_GLYPH_TOP 0x0100
|
||||
#define FTGX_ALIGN_GLYPH_MIDDLE 0x0200
|
||||
#define FTGX_ALIGN_GLYPH_BOTTOM 0x0400
|
||||
#define FTGX_ALIGN_MASK 0x0ff0
|
||||
#define FTGX_ALIGN_MASK 0x0ff0
|
||||
|
||||
#define FTGX_STYLE_UNDERLINE 0x1000
|
||||
#define FTGX_STYLE_STRIKE 0x2000
|
||||
#define FTGX_STYLE_MASK 0xf000
|
||||
#define FTGX_STYLE_UNDERLINE 0x1000
|
||||
#define FTGX_STYLE_STRIKE 0x2000
|
||||
#define FTGX_STYLE_MASK 0xf000
|
||||
|
||||
const GXColor ftgxWhite = ( GXColor )
|
||||
{ 0xff, 0xff, 0xff, 0xff}; /**< Constant color value used only to sanitize Doxygen documentation. */
|
||||
|
@ -105,45 +105,45 @@ wchar_t* charToWideChar(const char* p);
|
|||
*/
|
||||
class FreeTypeGX
|
||||
{
|
||||
private:
|
||||
FT_Library ftLibrary; /**< FreeType FT_Library instance. */
|
||||
FT_Face ftFace; /**< FreeType reusable FT_Face typographic object. */
|
||||
int16_t ftPointSize; /**< Current set size of the rendered font. */
|
||||
bool ftKerningEnabled; /**< Flag indicating the availability of font kerning data. */
|
||||
uint8_t vertexIndex; /**< Vertex format descriptor index. */
|
||||
std::map<int16_t, std::map<wchar_t, ftgxCharData> > fontData; /**< Map which holds the glyph data structures for the corresponding characters in one size. */
|
||||
std::map<int16_t, ftgxDataOffset> ftgxAlign; /**< Map which holds the ascender and decender for different sizes. */
|
||||
private:
|
||||
FT_Library ftLibrary; /**< FreeType FT_Library instance. */
|
||||
FT_Face ftFace; /**< FreeType reusable FT_Face typographic object. */
|
||||
int16_t ftPointSize; /**< Current set size of the rendered font. */
|
||||
bool ftKerningEnabled; /**< Flag indicating the availability of font kerning data. */
|
||||
uint8_t vertexIndex; /**< Vertex format descriptor index. */
|
||||
std::map<int16_t, std::map<wchar_t, ftgxCharData> > fontData; /**< Map which holds the glyph data structures for the corresponding characters in one size. */
|
||||
std::map<int16_t, ftgxDataOffset> ftgxAlign; /**< Map which holds the ascender and decender for different sizes. */
|
||||
|
||||
int16_t getStyleOffsetWidth(uint16_t width, uint16_t format);
|
||||
int16_t getStyleOffsetHeight(int16_t format, uint16_t pixelSize);
|
||||
int16_t getStyleOffsetWidth(uint16_t width, uint16_t format);
|
||||
int16_t getStyleOffsetHeight(int16_t format, uint16_t pixelSize);
|
||||
|
||||
void unloadFont();
|
||||
ftgxCharData *cacheGlyphData(wchar_t charCode, int16_t pixelSize);
|
||||
uint16_t cacheGlyphDataComplete(int16_t pixelSize);
|
||||
void loadGlyphData(FT_Bitmap *bmp, ftgxCharData *charData);
|
||||
void unloadFont();
|
||||
ftgxCharData *cacheGlyphData(wchar_t charCode, int16_t pixelSize);
|
||||
uint16_t cacheGlyphDataComplete(int16_t pixelSize);
|
||||
void loadGlyphData(FT_Bitmap *bmp, ftgxCharData *charData);
|
||||
|
||||
void setDefaultMode();
|
||||
void setDefaultMode();
|
||||
|
||||
void drawTextFeature(int16_t x, int16_t y, int16_t z, int16_t pixelSize, uint16_t width,
|
||||
ftgxDataOffset *offsetData, uint16_t format, GXColor color);
|
||||
void copyTextureToFramebuffer(GXTexObj *texObj, f32 texWidth, f32 texHeight, int16_t screenX, int16_t screenY,
|
||||
int16_t screenZ, GXColor color);
|
||||
void copyFeatureToFramebuffer(f32 featureWidth, f32 featureHeight, int16_t screenX, int16_t screenY,
|
||||
int16_t screenZ, GXColor color);
|
||||
void drawTextFeature(int16_t x, int16_t y, int16_t z, int16_t pixelSize, uint16_t width,
|
||||
ftgxDataOffset *offsetData, uint16_t format, GXColor color);
|
||||
void copyTextureToFramebuffer(GXTexObj *texObj, f32 texWidth, f32 texHeight, int16_t screenX, int16_t screenY,
|
||||
int16_t screenZ, GXColor color);
|
||||
void copyFeatureToFramebuffer(f32 featureWidth, f32 featureHeight, int16_t screenX, int16_t screenY,
|
||||
int16_t screenZ, GXColor color);
|
||||
|
||||
public:
|
||||
FreeTypeGX(const uint8_t* fontBuffer, FT_Long bufferSize, bool lastFace = false);
|
||||
~FreeTypeGX();
|
||||
public:
|
||||
FreeTypeGX(const uint8_t* fontBuffer, FT_Long bufferSize, bool lastFace = false);
|
||||
~FreeTypeGX();
|
||||
|
||||
void setVertexFormat(uint8_t vertexIndex);
|
||||
void setVertexFormat(uint8_t vertexIndex);
|
||||
|
||||
uint16_t drawText(int16_t x, int16_t y, int16_t z, const wchar_t *text, int16_t pixelSize, GXColor color =
|
||||
ftgxWhite, uint16_t textStyling = FTGX_NULL, uint16_t textWidth = 0, uint16_t widthLimit = 0);
|
||||
uint16_t drawText(int16_t x, int16_t y, int16_t z, const wchar_t *text, int16_t pixelSize, GXColor color =
|
||||
ftgxWhite, uint16_t textStyling = FTGX_NULL, uint16_t textWidth = 0, uint16_t widthLimit = 0);
|
||||
|
||||
uint16_t getWidth(const wchar_t *text, int16_t pixelSize);
|
||||
uint16_t getCharWidth(const wchar_t wChar, int16_t pixelSize, const wchar_t prevChar = 0x0000);
|
||||
uint16_t getHeight(const wchar_t *text, int16_t pixelSize);
|
||||
void getOffset(const wchar_t *text, int16_t pixelSize, uint16_t widthLimit = 0);
|
||||
uint16_t getWidth(const wchar_t *text, int16_t pixelSize);
|
||||
uint16_t getCharWidth(const wchar_t wChar, int16_t pixelSize, const wchar_t prevChar = 0x0000);
|
||||
uint16_t getHeight(const wchar_t *text, int16_t pixelSize);
|
||||
void getOffset(const wchar_t *text, int16_t pixelSize, uint16_t widthLimit = 0);
|
||||
};
|
||||
|
||||
#endif /* FREETYPEGX_H_ */
|
||||
|
|
|
@ -9,57 +9,57 @@
|
|||
***************************************************************************/
|
||||
GuiImageData *LoadCoverImage(struct discHdr *header, bool Prefere3D, bool noCover)
|
||||
{
|
||||
if (!header) return NULL;
|
||||
GuiImageData *Cover = NULL;
|
||||
char ID3[4];
|
||||
char IDfull[7];
|
||||
char Path[255];
|
||||
bool flag = Prefere3D;
|
||||
if (!header) return NULL;
|
||||
GuiImageData *Cover = NULL;
|
||||
char ID3[4];
|
||||
char IDfull[7];
|
||||
char Path[255];
|
||||
bool flag = Prefere3D;
|
||||
|
||||
snprintf(ID3, sizeof(ID3), "%s", (char *) header->id);
|
||||
snprintf(IDfull, sizeof(IDfull), "%s", (char *) header->id);
|
||||
snprintf(ID3, sizeof(ID3), "%s", (char *) header->id);
|
||||
snprintf(IDfull, sizeof(IDfull), "%s", (char *) header->id);
|
||||
|
||||
for (int i = 0; i < 2; ++i)
|
||||
{
|
||||
char *coverPath = flag ? Settings.covers_path : Settings.covers2d_path;
|
||||
flag = !flag;
|
||||
//Load full id image
|
||||
snprintf(Path, sizeof(Path), "%s%s.png", coverPath, IDfull);
|
||||
for (int i = 0; i < 2; ++i)
|
||||
{
|
||||
char *coverPath = flag ? Settings.covers_path : Settings.covers2d_path;
|
||||
flag = !flag;
|
||||
//Load full id image
|
||||
snprintf(Path, sizeof(Path), "%s%s.png", coverPath, IDfull);
|
||||
|
||||
if(!CheckFile(Path))
|
||||
{
|
||||
snprintf(Path, sizeof(Path), "%s%s.png", coverPath, ID3);
|
||||
if(!CheckFile(Path))
|
||||
continue;
|
||||
}
|
||||
if(!CheckFile(Path))
|
||||
{
|
||||
snprintf(Path, sizeof(Path), "%s%s.png", coverPath, ID3);
|
||||
if(!CheckFile(Path))
|
||||
continue;
|
||||
}
|
||||
|
||||
delete Cover;
|
||||
Cover = new (std::nothrow) GuiImageData(Path);
|
||||
//Load short id image
|
||||
if (!Cover || !Cover->GetImage())
|
||||
{
|
||||
snprintf(Path, sizeof(Path), "%s%s.png", coverPath, ID3);
|
||||
delete Cover;
|
||||
Cover = new (std::nothrow) GuiImageData(Path);
|
||||
}
|
||||
if (Cover && Cover->GetImage()) break;
|
||||
}
|
||||
//Load no image
|
||||
if (noCover && (!Cover || !Cover->GetImage()))
|
||||
{
|
||||
flag = Prefere3D;
|
||||
for (int i = 0; i < 2; ++i)
|
||||
{
|
||||
delete Cover;
|
||||
Cover = Resources::GetImageData(flag ? "nocover.png" : "nocoverFlat.png");
|
||||
if (Cover && Cover->GetImage()) break;
|
||||
flag = !flag;
|
||||
}
|
||||
}
|
||||
if (Cover && !Cover->GetImage())
|
||||
{
|
||||
delete Cover;
|
||||
Cover = NULL;
|
||||
}
|
||||
return Cover;
|
||||
delete Cover;
|
||||
Cover = new (std::nothrow) GuiImageData(Path);
|
||||
//Load short id image
|
||||
if (!Cover || !Cover->GetImage())
|
||||
{
|
||||
snprintf(Path, sizeof(Path), "%s%s.png", coverPath, ID3);
|
||||
delete Cover;
|
||||
Cover = new (std::nothrow) GuiImageData(Path);
|
||||
}
|
||||
if (Cover && Cover->GetImage()) break;
|
||||
}
|
||||
//Load no image
|
||||
if (noCover && (!Cover || !Cover->GetImage()))
|
||||
{
|
||||
flag = Prefere3D;
|
||||
for (int i = 0; i < 2; ++i)
|
||||
{
|
||||
delete Cover;
|
||||
Cover = Resources::GetImageData(flag ? "nocover.png" : "nocoverFlat.png");
|
||||
if (Cover && Cover->GetImage()) break;
|
||||
flag = !flag;
|
||||
}
|
||||
}
|
||||
if (Cover && !Cover->GetImage())
|
||||
{
|
||||
delete Cover;
|
||||
Cover = NULL;
|
||||
}
|
||||
return Cover;
|
||||
}
|
||||
|
|
|
@ -36,55 +36,55 @@ OptionList::OptionList()
|
|||
|
||||
OptionList::~OptionList()
|
||||
{
|
||||
ClearList();
|
||||
ClearList();
|
||||
}
|
||||
|
||||
void OptionList::SetName(int i, const char *format, ...)
|
||||
{
|
||||
if(i < (int) name.size())
|
||||
name[i].clear();
|
||||
if(i < (int) name.size())
|
||||
name[i].clear();
|
||||
|
||||
if(!format)
|
||||
return;
|
||||
if(!format)
|
||||
return;
|
||||
|
||||
char *tmp=0;
|
||||
va_list va;
|
||||
va_start(va, format);
|
||||
if((vasprintf(&tmp, format, va)>=0) && tmp)
|
||||
{
|
||||
if(i >= (int) name.size())
|
||||
{
|
||||
Resize(i+1);
|
||||
}
|
||||
if(i >= (int) name.size())
|
||||
{
|
||||
Resize(i+1);
|
||||
}
|
||||
|
||||
name[i].assign(tmp);
|
||||
|
||||
listChanged = true;
|
||||
listChanged = true;
|
||||
}
|
||||
va_end(va);
|
||||
|
||||
if(tmp)
|
||||
free(tmp);
|
||||
free(tmp);
|
||||
}
|
||||
|
||||
void OptionList::SetValue(int i, const char *format, ...)
|
||||
{
|
||||
if(i < (int) value.size())
|
||||
value[i].clear();
|
||||
if(i < (int) value.size())
|
||||
value[i].clear();
|
||||
|
||||
char *tmp=0;
|
||||
va_list va;
|
||||
va_start(va, format);
|
||||
if((vasprintf(&tmp, format, va)>=0) && tmp)
|
||||
{
|
||||
if(i >= (int) value.size())
|
||||
{
|
||||
Resize(i+1);
|
||||
}
|
||||
if(i >= (int) value.size())
|
||||
{
|
||||
Resize(i+1);
|
||||
}
|
||||
|
||||
value[i].assign(tmp);
|
||||
|
||||
listChanged = true;
|
||||
listChanged = true;
|
||||
}
|
||||
va_end(va);
|
||||
|
||||
|
@ -94,35 +94,35 @@ void OptionList::SetValue(int i, const char *format, ...)
|
|||
|
||||
const char * OptionList::GetName(int i)
|
||||
{
|
||||
if(i < 0 || i >= (int) name.size())
|
||||
return NULL;
|
||||
if(i < 0 || i >= (int) name.size())
|
||||
return NULL;
|
||||
|
||||
return name.at(i).c_str();
|
||||
return name.at(i).c_str();
|
||||
}
|
||||
|
||||
const char * OptionList::GetValue(int i)
|
||||
{
|
||||
if(i < 0 || i >= (int) value.size())
|
||||
return NULL;
|
||||
if(i < 0 || i >= (int) value.size())
|
||||
return NULL;
|
||||
|
||||
return value.at(i).c_str();
|
||||
return value.at(i).c_str();
|
||||
}
|
||||
|
||||
void OptionList::Resize(int size)
|
||||
{
|
||||
name.resize(size);
|
||||
value.resize(size);
|
||||
listChanged = true;
|
||||
name.resize(size);
|
||||
value.resize(size);
|
||||
listChanged = true;
|
||||
}
|
||||
|
||||
void OptionList::RemoveOption(int i)
|
||||
{
|
||||
if(i < 0 || i >= (int) name.size())
|
||||
return;
|
||||
if(i < 0 || i >= (int) name.size())
|
||||
return;
|
||||
|
||||
name.erase(name.begin()+i);
|
||||
value.erase(value.begin()+i);
|
||||
listChanged = true;
|
||||
name.erase(name.begin()+i);
|
||||
value.erase(value.begin()+i);
|
||||
listChanged = true;
|
||||
}
|
||||
|
||||
void OptionList::ClearList()
|
||||
|
@ -131,5 +131,5 @@ void OptionList::ClearList()
|
|||
value.clear();
|
||||
std::vector<std::string>().swap(name);
|
||||
std::vector<std::string>().swap(value);
|
||||
listChanged = true;
|
||||
listChanged = true;
|
||||
}
|
||||
|
|
|
@ -36,9 +36,9 @@ class OptionList
|
|||
~OptionList();
|
||||
void SetName(int i, const char *format, ...) __attribute__((format (printf, 3, 4)));
|
||||
void SetValue(int i, const char *format, ...) __attribute__((format (printf, 3, 4)));
|
||||
const char * GetName(int i);
|
||||
const char * GetName(int i);
|
||||
const char * GetValue(int i);
|
||||
void Resize(int size);
|
||||
void Resize(int size);
|
||||
int GetLength() { return name.size(); }
|
||||
bool IsChanged() { bool ret = listChanged; listChanged = false; return ret;}
|
||||
void RemoveOption(int i);
|
||||
|
|
|
@ -3,329 +3,329 @@
|
|||
#include "Text.hpp"
|
||||
|
||||
Text::Text(const char * t, int s, GXColor c) :
|
||||
GuiText(t, s, c)
|
||||
GuiText(t, s, c)
|
||||
{
|
||||
maxWidth = 400;
|
||||
linestodraw = 9;
|
||||
curLineStart = 0;
|
||||
FirstLineOffset = 0;
|
||||
wText = NULL;
|
||||
maxWidth = 400;
|
||||
linestodraw = 9;
|
||||
curLineStart = 0;
|
||||
FirstLineOffset = 0;
|
||||
wText = NULL;
|
||||
|
||||
if (!text) return;
|
||||
if (!text) return;
|
||||
|
||||
wText = new (std::nothrow) wString(text);
|
||||
if (!wText)
|
||||
{
|
||||
return;
|
||||
}
|
||||
wText = new (std::nothrow) wString(text);
|
||||
if (!wText)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (wText->size() == 0)
|
||||
{
|
||||
wText->push_back(L' ');
|
||||
wText->push_back(0);
|
||||
}
|
||||
if (wText->size() == 0)
|
||||
{
|
||||
wText->push_back(L' ');
|
||||
wText->push_back(0);
|
||||
}
|
||||
|
||||
textWidth = (font ? font : fontSystem)->getWidth(wText->data(), currentSize);
|
||||
delete[] text;
|
||||
text = NULL;
|
||||
textWidth = (font ? font : fontSystem)->getWidth(wText->data(), currentSize);
|
||||
delete[] text;
|
||||
text = NULL;
|
||||
|
||||
SetMaxWidth(maxWidth);
|
||||
SetMaxWidth(maxWidth);
|
||||
}
|
||||
|
||||
Text::Text(const wchar_t * t, int s, GXColor c) :
|
||||
GuiText((wchar_t *) NULL, s, c)
|
||||
GuiText((wchar_t *) NULL, s, c)
|
||||
{
|
||||
maxWidth = 400;
|
||||
linestodraw = 9;
|
||||
curLineStart = 0;
|
||||
FirstLineOffset = 0;
|
||||
wText = NULL;
|
||||
maxWidth = 400;
|
||||
linestodraw = 9;
|
||||
curLineStart = 0;
|
||||
FirstLineOffset = 0;
|
||||
wText = NULL;
|
||||
|
||||
if (!t) return;
|
||||
if (!t) return;
|
||||
|
||||
wText = new (std::nothrow) wString(t);
|
||||
if (!wText)
|
||||
{
|
||||
return;
|
||||
}
|
||||
wText = new (std::nothrow) wString(t);
|
||||
if (!wText)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (wText->size() == 0)
|
||||
{
|
||||
wText->push_back(L' ');
|
||||
wText->push_back(0);
|
||||
}
|
||||
if (wText->size() == 0)
|
||||
{
|
||||
wText->push_back(L' ');
|
||||
wText->push_back(0);
|
||||
}
|
||||
|
||||
textWidth = (font ? font : fontSystem)->getWidth(wText->data(), currentSize);
|
||||
textWidth = (font ? font : fontSystem)->getWidth(wText->data(), currentSize);
|
||||
|
||||
SetMaxWidth(maxWidth);
|
||||
SetMaxWidth(maxWidth);
|
||||
}
|
||||
|
||||
Text::~Text()
|
||||
{
|
||||
if (wText) delete wText;
|
||||
wText = NULL;
|
||||
if (wText) delete wText;
|
||||
wText = NULL;
|
||||
|
||||
TextLines.clear();
|
||||
ClearDynamicText();
|
||||
TextLines.clear();
|
||||
ClearDynamicText();
|
||||
}
|
||||
|
||||
void Text::SetText(const char * t)
|
||||
{
|
||||
wchar_t * tmp = charToWideChar(t);
|
||||
if (!tmp) return;
|
||||
wchar_t * tmp = charToWideChar(t);
|
||||
if (!tmp) return;
|
||||
|
||||
if (wText) delete wText;
|
||||
if (wText) delete wText;
|
||||
|
||||
wText = new (std::nothrow) wString(tmp);
|
||||
if (!wText)
|
||||
{
|
||||
return;
|
||||
}
|
||||
wText = new (std::nothrow) wString(tmp);
|
||||
if (!wText)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (wText->size() == 0)
|
||||
{
|
||||
wText->push_back(L' ');
|
||||
wText->push_back(0);
|
||||
}
|
||||
if (wText->size() == 0)
|
||||
{
|
||||
wText->push_back(L' ');
|
||||
wText->push_back(0);
|
||||
}
|
||||
|
||||
textWidth = (font ? font : fontSystem)->getWidth(wText->data(), currentSize);
|
||||
textWidth = (font ? font : fontSystem)->getWidth(wText->data(), currentSize);
|
||||
|
||||
delete[] tmp;
|
||||
delete[] tmp;
|
||||
|
||||
ClearDynamicText();
|
||||
CalcLineOffsets();
|
||||
ClearDynamicText();
|
||||
CalcLineOffsets();
|
||||
}
|
||||
|
||||
void Text::SetText(const wchar_t * t)
|
||||
{
|
||||
if (!t) return;
|
||||
if (!t) return;
|
||||
|
||||
if (wText) delete wText;
|
||||
if (wText) delete wText;
|
||||
|
||||
wText = new wString(t);
|
||||
textWidth = (font ? font : fontSystem)->getWidth(wText->data(), currentSize);
|
||||
CalcLineOffsets();
|
||||
wText = new wString(t);
|
||||
textWidth = (font ? font : fontSystem)->getWidth(wText->data(), currentSize);
|
||||
CalcLineOffsets();
|
||||
}
|
||||
|
||||
void Text::SetMaxWidth(int w)
|
||||
{
|
||||
maxWidth = w;
|
||||
curLineStart = 0;
|
||||
Refresh();
|
||||
maxWidth = w;
|
||||
curLineStart = 0;
|
||||
Refresh();
|
||||
}
|
||||
|
||||
void Text::SetTextLine(int line)
|
||||
{
|
||||
if (line < 0)
|
||||
line = 0;
|
||||
else if (line > (int) TextLines.size() - 1) line = TextLines.size() - 1;
|
||||
if (line < 0)
|
||||
line = 0;
|
||||
else if (line > (int) TextLines.size() - 1) line = TextLines.size() - 1;
|
||||
|
||||
curLineStart = line;
|
||||
curLineStart = line;
|
||||
|
||||
FillRows();
|
||||
FillRows();
|
||||
|
||||
while ((int) textDyn.size() < linestodraw && curLineStart > 0)
|
||||
{
|
||||
PreviousLine();
|
||||
}
|
||||
while ((int) textDyn.size() < linestodraw && curLineStart > 0)
|
||||
{
|
||||
PreviousLine();
|
||||
}
|
||||
}
|
||||
|
||||
void Text::SetTextPos(int pos)
|
||||
{
|
||||
if (!wText) return;
|
||||
if (!wText) return;
|
||||
|
||||
int diff = 10000;
|
||||
int diff = 10000;
|
||||
|
||||
for (u32 i = 0; i < TextLines.size(); i++)
|
||||
{
|
||||
int curDiff = abs(TextLines[i].LineOffset - pos);
|
||||
if (curDiff < diff)
|
||||
{
|
||||
diff = curDiff;
|
||||
curLineStart = i;
|
||||
}
|
||||
}
|
||||
for (u32 i = 0; i < TextLines.size(); i++)
|
||||
{
|
||||
int curDiff = abs(TextLines[i].LineOffset - pos);
|
||||
if (curDiff < diff)
|
||||
{
|
||||
diff = curDiff;
|
||||
curLineStart = i;
|
||||
}
|
||||
}
|
||||
|
||||
FillRows();
|
||||
FillRows();
|
||||
|
||||
while ((int) textDyn.size() < linestodraw && curLineStart > 0)
|
||||
{
|
||||
PreviousLine();
|
||||
}
|
||||
while ((int) textDyn.size() < linestodraw && curLineStart > 0)
|
||||
{
|
||||
PreviousLine();
|
||||
}
|
||||
}
|
||||
|
||||
const wchar_t * Text::GetText()
|
||||
{
|
||||
return wText->c_str();
|
||||
return wText->c_str();
|
||||
}
|
||||
|
||||
std::string Text::GetUTF8String(void) const
|
||||
{
|
||||
return wText->toUTF8();
|
||||
return wText->toUTF8();
|
||||
}
|
||||
|
||||
int Text::GetLineOffset(int ind)
|
||||
{
|
||||
if (TextLines.size() == 0) return 0;
|
||||
if (TextLines.size() == 0) return 0;
|
||||
|
||||
if (ind < 0) return TextLines[0].LineOffset;
|
||||
if (ind < 0) return TextLines[0].LineOffset;
|
||||
|
||||
if (ind >= (int) TextLines.size() - 1) return TextLines[TextLines.size() - 1].LineOffset;
|
||||
if (ind >= (int) TextLines.size() - 1) return TextLines[TextLines.size() - 1].LineOffset;
|
||||
|
||||
return TextLines[ind].LineOffset;
|
||||
return TextLines[ind].LineOffset;
|
||||
}
|
||||
|
||||
const wchar_t * Text::GetTextLine(int ind)
|
||||
{
|
||||
if (filling || textDyn.size() == 0) return NULL;
|
||||
if (filling || textDyn.size() == 0) return NULL;
|
||||
|
||||
if (ind < 0) return textDyn[0];
|
||||
if (ind < 0) return textDyn[0];
|
||||
|
||||
if (ind >= (int) textDyn.size()) return textDyn[textDyn.size() - 1];
|
||||
if (ind >= (int) textDyn.size()) return textDyn[textDyn.size() - 1];
|
||||
|
||||
return textDyn[ind];
|
||||
return textDyn[ind];
|
||||
}
|
||||
|
||||
void Text::Refresh()
|
||||
{
|
||||
CalcLineOffsets();
|
||||
FillRows();
|
||||
CalcLineOffsets();
|
||||
FillRows();
|
||||
}
|
||||
|
||||
void Text::NextLine()
|
||||
{
|
||||
if (!wText || (curLineStart + 1 > ((int) TextLines.size() - linestodraw))) return;
|
||||
if (!wText || (curLineStart + 1 > ((int) TextLines.size() - linestodraw))) return;
|
||||
|
||||
++curLineStart;
|
||||
++curLineStart;
|
||||
|
||||
FillRows();
|
||||
FillRows();
|
||||
}
|
||||
|
||||
void Text::PreviousLine()
|
||||
{
|
||||
if (!wText || curLineStart - 1 < 0) return;
|
||||
if (!wText || curLineStart - 1 < 0) return;
|
||||
|
||||
--curLineStart;
|
||||
--curLineStart;
|
||||
|
||||
FillRows();
|
||||
FillRows();
|
||||
}
|
||||
|
||||
void Text::FillRows()
|
||||
{
|
||||
if (!wText) return;
|
||||
if (!wText) return;
|
||||
|
||||
filling = true;
|
||||
filling = true;
|
||||
|
||||
ClearDynamicText();
|
||||
ClearDynamicText();
|
||||
|
||||
for (int i = 0; i < linestodraw && curLineStart+i < (int) TextLines.size(); i++)
|
||||
{
|
||||
if (i >= (int) textDyn.size())
|
||||
{
|
||||
textDyn.resize(i + 1);
|
||||
textDyn[i] = new wchar_t[maxWidth];
|
||||
}
|
||||
int offset = TextLines[curLineStart + i].LineOffset;
|
||||
int count = TextLines[curLineStart + i].CharCount + 1;
|
||||
for (int i = 0; i < linestodraw && curLineStart+i < (int) TextLines.size(); i++)
|
||||
{
|
||||
if (i >= (int) textDyn.size())
|
||||
{
|
||||
textDyn.resize(i + 1);
|
||||
textDyn[i] = new wchar_t[maxWidth];
|
||||
}
|
||||
int offset = TextLines[curLineStart + i].LineOffset;
|
||||
int count = TextLines[curLineStart + i].CharCount + 1;
|
||||
|
||||
for (int n = 0; n < count && offset + n < (int) wText->size(); n++)
|
||||
textDyn[i][n] = wText->at(offset + n);
|
||||
for (int n = 0; n < count && offset + n < (int) wText->size(); n++)
|
||||
textDyn[i][n] = wText->at(offset + n);
|
||||
|
||||
textDyn[i][count] = 0;
|
||||
}
|
||||
textDyn[i][count] = 0;
|
||||
}
|
||||
|
||||
filling = false;
|
||||
filling = false;
|
||||
|
||||
return;
|
||||
return;
|
||||
}
|
||||
|
||||
void Text::CalcLineOffsets()
|
||||
{
|
||||
if (!wText) return;
|
||||
if (!wText) return;
|
||||
|
||||
TextLines.clear();
|
||||
TextLines.clear();
|
||||
|
||||
TextLine TmpLine;
|
||||
TmpLine.CharCount = 0;
|
||||
TmpLine.LineOffset = 0;
|
||||
TmpLine.width = 0;
|
||||
TextLine TmpLine;
|
||||
TmpLine.CharCount = 0;
|
||||
TmpLine.LineOffset = 0;
|
||||
TmpLine.width = 0;
|
||||
|
||||
const wchar_t * origTxt = wText->c_str();
|
||||
int ch = 0;
|
||||
int lastSpace = -1;
|
||||
int currWidth = 0;
|
||||
int i = 0;
|
||||
const wchar_t * origTxt = wText->c_str();
|
||||
int ch = 0;
|
||||
int lastSpace = -1;
|
||||
int currWidth = 0;
|
||||
int i = 0;
|
||||
|
||||
while (origTxt[ch])
|
||||
{
|
||||
currWidth += fontSystem->getCharWidth(origTxt[ch], currentSize, ch > 0 ? origTxt[ch - 1] : 0x0000);
|
||||
while (origTxt[ch])
|
||||
{
|
||||
currWidth += fontSystem->getCharWidth(origTxt[ch], currentSize, ch > 0 ? origTxt[ch - 1] : 0x0000);
|
||||
|
||||
if (currWidth >= maxWidth)
|
||||
{
|
||||
if (lastSpace > 0)
|
||||
{
|
||||
ch = lastSpace;
|
||||
}
|
||||
TmpLine.CharCount = ch - TmpLine.LineOffset;
|
||||
TmpLine.width = currWidth;
|
||||
TextLines.push_back(TmpLine);
|
||||
currWidth = 0;
|
||||
lastSpace = -1;
|
||||
i = -1;
|
||||
TmpLine.LineOffset = ch + 1;
|
||||
}
|
||||
else if (origTxt[ch] == '\n')
|
||||
{
|
||||
TmpLine.CharCount = ch - TmpLine.LineOffset;
|
||||
TmpLine.width = currWidth;
|
||||
TextLines.push_back(TmpLine);
|
||||
currWidth = 0;
|
||||
lastSpace = -1;
|
||||
i = -1;
|
||||
TmpLine.LineOffset = ch + 1;
|
||||
}
|
||||
else if (origTxt[ch] == ' ')
|
||||
{
|
||||
lastSpace = ch;
|
||||
}
|
||||
if (currWidth >= maxWidth)
|
||||
{
|
||||
if (lastSpace > 0)
|
||||
{
|
||||
ch = lastSpace;
|
||||
}
|
||||
TmpLine.CharCount = ch - TmpLine.LineOffset;
|
||||
TmpLine.width = currWidth;
|
||||
TextLines.push_back(TmpLine);
|
||||
currWidth = 0;
|
||||
lastSpace = -1;
|
||||
i = -1;
|
||||
TmpLine.LineOffset = ch + 1;
|
||||
}
|
||||
else if (origTxt[ch] == '\n')
|
||||
{
|
||||
TmpLine.CharCount = ch - TmpLine.LineOffset;
|
||||
TmpLine.width = currWidth;
|
||||
TextLines.push_back(TmpLine);
|
||||
currWidth = 0;
|
||||
lastSpace = -1;
|
||||
i = -1;
|
||||
TmpLine.LineOffset = ch + 1;
|
||||
}
|
||||
else if (origTxt[ch] == ' ')
|
||||
{
|
||||
lastSpace = ch;
|
||||
}
|
||||
|
||||
ch++;
|
||||
i++;
|
||||
}
|
||||
ch++;
|
||||
i++;
|
||||
}
|
||||
|
||||
TmpLine.CharCount = ch - TmpLine.LineOffset;
|
||||
TmpLine.width = currWidth;
|
||||
TmpLine.CharCount = ch - TmpLine.LineOffset;
|
||||
TmpLine.width = currWidth;
|
||||
|
||||
if (TmpLine.CharCount-1 > 0)
|
||||
{
|
||||
TmpLine.CharCount -= 1;
|
||||
TextLines.push_back(TmpLine);
|
||||
}
|
||||
if (TmpLine.CharCount-1 > 0)
|
||||
{
|
||||
TmpLine.CharCount -= 1;
|
||||
TextLines.push_back(TmpLine);
|
||||
}
|
||||
}
|
||||
|
||||
void Text::Draw()
|
||||
{
|
||||
if (textDyn.size() == 0) return;
|
||||
if (textDyn.size() == 0) return;
|
||||
|
||||
if (!this->IsVisible()) return;
|
||||
if (!this->IsVisible()) return;
|
||||
|
||||
GXColor c = color;
|
||||
c.a = this->GetAlpha();
|
||||
GXColor c = color;
|
||||
c.a = this->GetAlpha();
|
||||
|
||||
int newSize = (int) (size * GetScale());
|
||||
int newSize = (int) (size * GetScale());
|
||||
|
||||
if (newSize != currentSize)
|
||||
{
|
||||
currentSize = LIMIT(newSize, 1, 100);
|
||||
if (newSize != currentSize)
|
||||
{
|
||||
currentSize = LIMIT(newSize, 1, 100);
|
||||
|
||||
if (wText) textWidth = (font ? font : fontSystem)->getWidth(wText->data(), currentSize);
|
||||
}
|
||||
if (wText) textWidth = (font ? font : fontSystem)->getWidth(wText->data(), currentSize);
|
||||
}
|
||||
|
||||
u16 lineheight = newSize + 6;
|
||||
u16 lineheight = newSize + 6;
|
||||
|
||||
for (u32 i = 0; i < textDyn.size(); i++)
|
||||
{
|
||||
if (!filling) (font ? font : fontSystem)->drawText(this->GetLeft(), this->GetTop() + i * lineheight, 0,
|
||||
textDyn[i], currentSize, c, style, 0, maxWidth);
|
||||
}
|
||||
for (u32 i = 0; i < textDyn.size(); i++)
|
||||
{
|
||||
if (!filling) (font ? font : fontSystem)->drawText(this->GetLeft(), this->GetTop() + i * lineheight, 0,
|
||||
textDyn[i], currentSize, c, style, 0, maxWidth);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,64 +6,64 @@
|
|||
|
||||
typedef struct
|
||||
{
|
||||
int LineOffset;
|
||||
int CharCount;
|
||||
int width;
|
||||
int LineOffset;
|
||||
int CharCount;
|
||||
int width;
|
||||
} TextLine;
|
||||
|
||||
class Text: public GuiText
|
||||
{
|
||||
public:
|
||||
//!Constructor
|
||||
//!\param t Text
|
||||
//!\param s Font size
|
||||
//!\param c Font color
|
||||
Text(const char * t, int s, GXColor c);
|
||||
Text(const wchar_t * t, int s, GXColor c);
|
||||
virtual ~Text();
|
||||
//!Sets the text of the GuiText element
|
||||
//!\param t Text
|
||||
void SetText(const char * t);
|
||||
void SetText(const wchar_t * t);
|
||||
//!Set the max texwidth
|
||||
void SetMaxWidth(int width);
|
||||
//!Go to next line
|
||||
void NextLine();
|
||||
//!Go to previous line
|
||||
void PreviousLine();
|
||||
//!Refresh the rows to draw
|
||||
void Refresh();
|
||||
//!Set the text line
|
||||
void SetTextLine(int line);
|
||||
//!Set to the char pos in text
|
||||
void SetTextPos(int pos);
|
||||
//!Refresh the rows to draw
|
||||
int GetCurrPos() { return curLineStart; };
|
||||
//!Get the count of loaded lines
|
||||
int GetLinesCount() { return textDyn.size(); };
|
||||
//!Get the total count of lines
|
||||
int GetTotalLinesCount() { return TextLines.size(); };
|
||||
//!Get the original full Text
|
||||
const wchar_t * GetText();
|
||||
//!Get the original full Text as wString
|
||||
wString * GetwString() { return wText; };
|
||||
//!Get the original Text as a UTF-8 text
|
||||
std::string GetUTF8String() const;
|
||||
//!Get a Textline
|
||||
const wchar_t * GetTextLine(int ind);
|
||||
//!Get the offset in the text of a drawn Line
|
||||
int GetLineOffset(int ind);
|
||||
//!Constantly called to draw the text
|
||||
void Draw();
|
||||
protected:
|
||||
void CalcLineOffsets();
|
||||
void FillRows();
|
||||
public:
|
||||
//!Constructor
|
||||
//!\param t Text
|
||||
//!\param s Font size
|
||||
//!\param c Font color
|
||||
Text(const char * t, int s, GXColor c);
|
||||
Text(const wchar_t * t, int s, GXColor c);
|
||||
virtual ~Text();
|
||||
//!Sets the text of the GuiText element
|
||||
//!\param t Text
|
||||
void SetText(const char * t);
|
||||
void SetText(const wchar_t * t);
|
||||
//!Set the max texwidth
|
||||
void SetMaxWidth(int width);
|
||||
//!Go to next line
|
||||
void NextLine();
|
||||
//!Go to previous line
|
||||
void PreviousLine();
|
||||
//!Refresh the rows to draw
|
||||
void Refresh();
|
||||
//!Set the text line
|
||||
void SetTextLine(int line);
|
||||
//!Set to the char pos in text
|
||||
void SetTextPos(int pos);
|
||||
//!Refresh the rows to draw
|
||||
int GetCurrPos() { return curLineStart; };
|
||||
//!Get the count of loaded lines
|
||||
int GetLinesCount() { return textDyn.size(); };
|
||||
//!Get the total count of lines
|
||||
int GetTotalLinesCount() { return TextLines.size(); };
|
||||
//!Get the original full Text
|
||||
const wchar_t * GetText();
|
||||
//!Get the original full Text as wString
|
||||
wString * GetwString() { return wText; };
|
||||
//!Get the original Text as a UTF-8 text
|
||||
std::string GetUTF8String() const;
|
||||
//!Get a Textline
|
||||
const wchar_t * GetTextLine(int ind);
|
||||
//!Get the offset in the text of a drawn Line
|
||||
int GetLineOffset(int ind);
|
||||
//!Constantly called to draw the text
|
||||
void Draw();
|
||||
protected:
|
||||
void CalcLineOffsets();
|
||||
void FillRows();
|
||||
|
||||
wString * wText;
|
||||
std::vector<TextLine> TextLines;
|
||||
int curLineStart;
|
||||
int FirstLineOffset;
|
||||
bool filling;
|
||||
wString * wText;
|
||||
std::vector<TextLine> TextLines;
|
||||
int curLineStart;
|
||||
int FirstLineOffset;
|
||||
bool filling;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
1652
source/GUI/gui.h
1652
source/GUI/gui.h
File diff suppressed because it is too large
Load Diff
|
@ -25,25 +25,25 @@
|
|||
|
||||
void GuiBox::Draw()
|
||||
{
|
||||
GX_SetTevOp(GX_TEVSTAGE0, GX_PASSCLR);
|
||||
GX_SetVtxDesc(GX_VA_POS, GX_DIRECT);
|
||||
GX_SetVtxDesc(GX_VA_CLR0, GX_DIRECT);
|
||||
GX_SetVtxDesc(GX_VA_TEX0, GX_NONE);
|
||||
u32 n = filled ? 4 : 5;
|
||||
f32 x = GetLeft();
|
||||
f32 y = GetTop();
|
||||
f32 x2 = x + width;
|
||||
f32 y2 = y + height;
|
||||
guVector v[] = { { x, y, 0.0f }, { x2, y, 0.0f }, { x2, y2, 0.0f }, { x, y2, 0.0f }, { x, y, 0.0f } };
|
||||
GX_SetTevOp(GX_TEVSTAGE0, GX_PASSCLR);
|
||||
GX_SetVtxDesc(GX_VA_POS, GX_DIRECT);
|
||||
GX_SetVtxDesc(GX_VA_CLR0, GX_DIRECT);
|
||||
GX_SetVtxDesc(GX_VA_TEX0, GX_NONE);
|
||||
u32 n = filled ? 4 : 5;
|
||||
f32 x = GetLeft();
|
||||
f32 y = GetTop();
|
||||
f32 x2 = x + width;
|
||||
f32 y2 = y + height;
|
||||
guVector v[] = { { x, y, 0.0f }, { x2, y, 0.0f }, { x2, y2, 0.0f }, { x, y2, 0.0f }, { x, y, 0.0f } };
|
||||
|
||||
int alpha = GetAlpha();
|
||||
int alpha = GetAlpha();
|
||||
|
||||
GX_Begin(filled ? GX_TRIANGLEFAN : GX_LINESTRIP, GX_VTXFMT0, n);
|
||||
for (u32 i = 0; i < n; i++)
|
||||
{
|
||||
GX_Position3f32(v[i].x, v[i].y, v[i].z);
|
||||
GX_Color4u8(color[i].r, color[i].g, color[i].b, alpha);
|
||||
}
|
||||
GX_End();
|
||||
GX_SetTevOp(GX_TEVSTAGE0, GX_MODULATE);
|
||||
GX_Begin(filled ? GX_TRIANGLEFAN : GX_LINESTRIP, GX_VTXFMT0, n);
|
||||
for (u32 i = 0; i < n; i++)
|
||||
{
|
||||
GX_Position3f32(v[i].x, v[i].y, v[i].z);
|
||||
GX_Color4u8(color[i].r, color[i].g, color[i].b, alpha);
|
||||
}
|
||||
GX_End();
|
||||
GX_SetTevOp(GX_TEVSTAGE0, GX_MODULATE);
|
||||
}
|
||||
|
|
|
@ -28,20 +28,20 @@
|
|||
|
||||
class GuiBox : public GuiElement
|
||||
{
|
||||
public:
|
||||
GuiBox() : filled(true) { SetColor((GXColor) {255, 255, 255, 255}); }
|
||||
GuiBox(int w, int h) : filled(true) { width = w; height = h; SetColor((GXColor) {255, 255, 255, 255}); }
|
||||
//! Set one color for the whole square
|
||||
void SetColor(const GXColor c) { LOCK(this); for(int i = 0; i < 4; ++i) color[i] = c; }
|
||||
//! Set Color for each corner having a nice fluent flow into the color of the other corners
|
||||
//! 0 = up/left, 1 = up/right, 2 = buttom/left, 3 = buttom/right
|
||||
void SetColor(int i, const GXColor c) { LOCK(this); if(i < 4) color[i] = c; }
|
||||
void SetSize(int w, int h) { LOCK(this); width = w; height = h; }
|
||||
void SetFilled(bool f) { LOCK(this); filled = f; }
|
||||
void Draw();
|
||||
protected:
|
||||
GXColor color[4];
|
||||
bool filled;
|
||||
public:
|
||||
GuiBox() : filled(true) { SetColor((GXColor) {255, 255, 255, 255}); }
|
||||
GuiBox(int w, int h) : filled(true) { width = w; height = h; SetColor((GXColor) {255, 255, 255, 255}); }
|
||||
//! Set one color for the whole square
|
||||
void SetColor(const GXColor c) { LOCK(this); for(int i = 0; i < 4; ++i) color[i] = c; }
|
||||
//! Set Color for each corner having a nice fluent flow into the color of the other corners
|
||||
//! 0 = up/left, 1 = up/right, 2 = buttom/left, 3 = buttom/right
|
||||
void SetColor(int i, const GXColor c) { LOCK(this); if(i < 4) color[i] = c; }
|
||||
void SetSize(int w, int h) { LOCK(this); width = w; height = h; }
|
||||
void SetFilled(bool f) { LOCK(this); filled = f; }
|
||||
void Draw();
|
||||
protected:
|
||||
GXColor color[4];
|
||||
bool filled;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -18,135 +18,135 @@ static int scrollison = 0;
|
|||
|
||||
GuiButton::GuiButton(int w, int h)
|
||||
{
|
||||
width = w;
|
||||
height = h;
|
||||
image = NULL;
|
||||
imageOver = NULL;
|
||||
imageHold = NULL;
|
||||
imageClick = NULL;
|
||||
icon = NULL;
|
||||
iconOver = NULL;
|
||||
iconHold = NULL;
|
||||
iconClick = NULL;
|
||||
toolTip = NULL;
|
||||
width = w;
|
||||
height = h;
|
||||
image = NULL;
|
||||
imageOver = NULL;
|
||||
imageHold = NULL;
|
||||
imageClick = NULL;
|
||||
icon = NULL;
|
||||
iconOver = NULL;
|
||||
iconHold = NULL;
|
||||
iconClick = NULL;
|
||||
toolTip = NULL;
|
||||
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
label[i] = NULL;
|
||||
labelOver[i] = NULL;
|
||||
labelHold[i] = NULL;
|
||||
labelClick[i] = NULL;
|
||||
}
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
label[i] = NULL;
|
||||
labelOver[i] = NULL;
|
||||
labelHold[i] = NULL;
|
||||
labelClick[i] = NULL;
|
||||
}
|
||||
|
||||
soundOver = NULL;
|
||||
soundHold = NULL;
|
||||
soundClick = NULL;
|
||||
selectable = true;
|
||||
holdable = false;
|
||||
clickable = true;
|
||||
soundOver = NULL;
|
||||
soundHold = NULL;
|
||||
soundClick = NULL;
|
||||
selectable = true;
|
||||
holdable = false;
|
||||
clickable = true;
|
||||
|
||||
time1 = time2 = 0;
|
||||
time1 = time2 = 0;
|
||||
}
|
||||
|
||||
GuiButton::GuiButton(GuiImage* img, GuiImage* imgOver, int hor, int vert, int x, int y, GuiTrigger* trig,
|
||||
GuiSound* sndOver, GuiSound* sndClick, u8 grow)
|
||||
GuiSound* sndOver, GuiSound* sndClick, u8 grow)
|
||||
{
|
||||
width = img ? img->GetWidth() : 0;
|
||||
height = img ? img->GetHeight() : 0;
|
||||
image = img;
|
||||
if(image) image->SetParent(this);
|
||||
imageOver = imgOver;
|
||||
if (imageOver) imageOver->SetParent(this);
|
||||
imageHold = NULL;
|
||||
imageClick = NULL;
|
||||
icon = NULL;
|
||||
iconOver = NULL;
|
||||
iconHold = NULL;
|
||||
iconClick = NULL;
|
||||
toolTip = NULL;
|
||||
alignmentHor = hor;
|
||||
alignmentVert = vert;
|
||||
xoffset = x;
|
||||
yoffset = y;
|
||||
trigger[0] = trig;
|
||||
width = img ? img->GetWidth() : 0;
|
||||
height = img ? img->GetHeight() : 0;
|
||||
image = img;
|
||||
if(image) image->SetParent(this);
|
||||
imageOver = imgOver;
|
||||
if (imageOver) imageOver->SetParent(this);
|
||||
imageHold = NULL;
|
||||
imageClick = NULL;
|
||||
icon = NULL;
|
||||
iconOver = NULL;
|
||||
iconHold = NULL;
|
||||
iconClick = NULL;
|
||||
toolTip = NULL;
|
||||
alignmentHor = hor;
|
||||
alignmentVert = vert;
|
||||
xoffset = x;
|
||||
yoffset = y;
|
||||
trigger[0] = trig;
|
||||
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
label[i] = NULL;
|
||||
labelOver[i] = NULL;
|
||||
labelHold[i] = NULL;
|
||||
labelClick[i] = NULL;
|
||||
}
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
label[i] = NULL;
|
||||
labelOver[i] = NULL;
|
||||
labelHold[i] = NULL;
|
||||
labelClick[i] = NULL;
|
||||
}
|
||||
|
||||
soundOver = sndOver;
|
||||
soundHold = NULL;
|
||||
soundClick = sndClick;
|
||||
selectable = true;
|
||||
holdable = false;
|
||||
clickable = true;
|
||||
soundOver = sndOver;
|
||||
soundHold = NULL;
|
||||
soundClick = sndClick;
|
||||
selectable = true;
|
||||
holdable = false;
|
||||
clickable = true;
|
||||
|
||||
if (grow == 1)
|
||||
{
|
||||
effectsOver |= EFFECT_SCALE;
|
||||
effectAmountOver = 4;
|
||||
effectTargetOver = 110;
|
||||
}
|
||||
time1 = time2 = 0;
|
||||
if (grow == 1)
|
||||
{
|
||||
effectsOver |= EFFECT_SCALE;
|
||||
effectAmountOver = 4;
|
||||
effectTargetOver = 110;
|
||||
}
|
||||
time1 = time2 = 0;
|
||||
}
|
||||
|
||||
GuiButton::GuiButton(GuiImage* img, GuiImage* imgOver, int hor, int vert, int x, int y, GuiTrigger* trig,
|
||||
GuiSound* sndOver, GuiSound* sndClick, u8 grow, GuiTooltip* tt, int ttx, int tty, int h_align, int v_align)
|
||||
GuiSound* sndOver, GuiSound* sndClick, u8 grow, GuiTooltip* tt, int ttx, int tty, int h_align, int v_align)
|
||||
{
|
||||
width = img ? img->GetWidth() : 0;
|
||||
height = img ? img->GetHeight() : 0;
|
||||
image = img;
|
||||
if(image) image->SetParent(this);
|
||||
imageOver = imgOver;
|
||||
if (imageOver) imageOver->SetParent(this);
|
||||
imageHold = NULL;
|
||||
imageClick = NULL;
|
||||
icon = NULL;
|
||||
iconOver = NULL;
|
||||
iconHold = NULL;
|
||||
iconClick = NULL;
|
||||
toolTip = NULL;
|
||||
alignmentHor = hor;
|
||||
alignmentVert = vert;
|
||||
xoffset = x;
|
||||
yoffset = y;
|
||||
trigger[0] = trig;
|
||||
width = img ? img->GetWidth() : 0;
|
||||
height = img ? img->GetHeight() : 0;
|
||||
image = img;
|
||||
if(image) image->SetParent(this);
|
||||
imageOver = imgOver;
|
||||
if (imageOver) imageOver->SetParent(this);
|
||||
imageHold = NULL;
|
||||
imageClick = NULL;
|
||||
icon = NULL;
|
||||
iconOver = NULL;
|
||||
iconHold = NULL;
|
||||
iconClick = NULL;
|
||||
toolTip = NULL;
|
||||
alignmentHor = hor;
|
||||
alignmentVert = vert;
|
||||
xoffset = x;
|
||||
yoffset = y;
|
||||
trigger[0] = trig;
|
||||
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
label[i] = NULL;
|
||||
labelOver[i] = NULL;
|
||||
labelHold[i] = NULL;
|
||||
labelClick[i] = NULL;
|
||||
}
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
label[i] = NULL;
|
||||
labelOver[i] = NULL;
|
||||
labelHold[i] = NULL;
|
||||
labelClick[i] = NULL;
|
||||
}
|
||||
|
||||
soundOver = sndOver;
|
||||
soundHold = NULL;
|
||||
soundClick = sndClick;
|
||||
selectable = true;
|
||||
holdable = false;
|
||||
clickable = true;
|
||||
soundOver = sndOver;
|
||||
soundHold = NULL;
|
||||
soundClick = sndClick;
|
||||
selectable = true;
|
||||
holdable = false;
|
||||
clickable = true;
|
||||
|
||||
if (grow == 1)
|
||||
{
|
||||
effectsOver |= EFFECT_SCALE;
|
||||
effectAmountOver = 4;
|
||||
effectTargetOver = 110;
|
||||
}
|
||||
if (grow == 1)
|
||||
{
|
||||
effectsOver |= EFFECT_SCALE;
|
||||
effectAmountOver = 4;
|
||||
effectTargetOver = 110;
|
||||
}
|
||||
|
||||
toolTip = tt;
|
||||
if(toolTip)
|
||||
{
|
||||
toolTip->SetParent(this);
|
||||
toolTip->SetAlignment(h_align, v_align);
|
||||
toolTip->SetPosition(ttx, tty);
|
||||
}
|
||||
toolTip = tt;
|
||||
if(toolTip)
|
||||
{
|
||||
toolTip->SetParent(this);
|
||||
toolTip->SetAlignment(h_align, v_align);
|
||||
toolTip->SetPosition(ttx, tty);
|
||||
}
|
||||
|
||||
time1 = time2 = 0;
|
||||
time1 = time2 = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -158,157 +158,157 @@ GuiButton::~GuiButton()
|
|||
|
||||
void GuiButton::SetImage(GuiImage* img)
|
||||
{
|
||||
LOCK( this );
|
||||
image = img;
|
||||
if (img) img->SetParent(this);
|
||||
LOCK( this );
|
||||
image = img;
|
||||
if (img) img->SetParent(this);
|
||||
}
|
||||
void GuiButton::SetImageOver(GuiImage* img)
|
||||
{
|
||||
LOCK( this );
|
||||
imageOver = img;
|
||||
if (img) img->SetParent(this);
|
||||
LOCK( this );
|
||||
imageOver = img;
|
||||
if (img) img->SetParent(this);
|
||||
}
|
||||
void GuiButton::SetImageHold(GuiImage* img)
|
||||
{
|
||||
LOCK( this );
|
||||
imageHold = img;
|
||||
if (img) img->SetParent(this);
|
||||
LOCK( this );
|
||||
imageHold = img;
|
||||
if (img) img->SetParent(this);
|
||||
}
|
||||
void GuiButton::SetImageClick(GuiImage* img)
|
||||
{
|
||||
LOCK( this );
|
||||
imageClick = img;
|
||||
if (img) img->SetParent(this);
|
||||
LOCK( this );
|
||||
imageClick = img;
|
||||
if (img) img->SetParent(this);
|
||||
}
|
||||
void GuiButton::SetIcon(GuiImage* img)
|
||||
{
|
||||
LOCK( this );
|
||||
icon = img;
|
||||
if (img) img->SetParent(this);
|
||||
LOCK( this );
|
||||
icon = img;
|
||||
if (img) img->SetParent(this);
|
||||
}
|
||||
void GuiButton::SetIconOver(GuiImage* img)
|
||||
{
|
||||
LOCK( this );
|
||||
iconOver = img;
|
||||
if (img) img->SetParent(this);
|
||||
LOCK( this );
|
||||
iconOver = img;
|
||||
if (img) img->SetParent(this);
|
||||
}
|
||||
void GuiButton::SetIconHold(GuiImage* img)
|
||||
{
|
||||
LOCK( this );
|
||||
iconHold = img;
|
||||
if (img) img->SetParent(this);
|
||||
LOCK( this );
|
||||
iconHold = img;
|
||||
if (img) img->SetParent(this);
|
||||
}
|
||||
void GuiButton::SetIconClick(GuiImage* img)
|
||||
{
|
||||
LOCK( this );
|
||||
iconClick = img;
|
||||
if (img) img->SetParent(this);
|
||||
LOCK( this );
|
||||
iconClick = img;
|
||||
if (img) img->SetParent(this);
|
||||
}
|
||||
void GuiButton::SetLabel(GuiText* txt, int n)
|
||||
{
|
||||
LOCK( this );
|
||||
label[n] = txt;
|
||||
if (txt) txt->SetParent(this);
|
||||
LOCK( this );
|
||||
label[n] = txt;
|
||||
if (txt) txt->SetParent(this);
|
||||
}
|
||||
void GuiButton::SetLabelOver(GuiText* txt, int n)
|
||||
{
|
||||
LOCK( this );
|
||||
labelOver[n] = txt;
|
||||
if (txt) txt->SetParent(this);
|
||||
LOCK( this );
|
||||
labelOver[n] = txt;
|
||||
if (txt) txt->SetParent(this);
|
||||
}
|
||||
void GuiButton::SetLabelHold(GuiText* txt, int n)
|
||||
{
|
||||
LOCK( this );
|
||||
labelHold[n] = txt;
|
||||
if (txt) txt->SetParent(this);
|
||||
LOCK( this );
|
||||
labelHold[n] = txt;
|
||||
if (txt) txt->SetParent(this);
|
||||
}
|
||||
void GuiButton::SetLabelClick(GuiText* txt, int n)
|
||||
{
|
||||
LOCK( this );
|
||||
labelClick[n] = txt;
|
||||
if (txt) txt->SetParent(this);
|
||||
LOCK( this );
|
||||
labelClick[n] = txt;
|
||||
if (txt) txt->SetParent(this);
|
||||
}
|
||||
void GuiButton::SetSoundOver(GuiSound * snd)
|
||||
{
|
||||
LOCK( this );
|
||||
soundOver = snd;
|
||||
LOCK( this );
|
||||
soundOver = snd;
|
||||
}
|
||||
void GuiButton::SetSoundHold(GuiSound * snd)
|
||||
{
|
||||
LOCK( this );
|
||||
soundHold = snd;
|
||||
LOCK( this );
|
||||
soundHold = snd;
|
||||
}
|
||||
void GuiButton::SetSoundClick(GuiSound * snd)
|
||||
{
|
||||
LOCK( this );
|
||||
soundClick = snd;
|
||||
LOCK( this );
|
||||
soundClick = snd;
|
||||
}
|
||||
|
||||
void GuiButton::SetToolTip(GuiTooltip* tt, int x, int y, int h_align, int v_align)
|
||||
{
|
||||
LOCK( this );
|
||||
if (tt)
|
||||
{
|
||||
toolTip = tt;
|
||||
toolTip->SetParent(this);
|
||||
toolTip->SetAlignment(h_align, v_align);
|
||||
toolTip->SetPosition(x, y);
|
||||
LOCK( this );
|
||||
if (tt)
|
||||
{
|
||||
toolTip = tt;
|
||||
toolTip->SetParent(this);
|
||||
toolTip->SetAlignment(h_align, v_align);
|
||||
toolTip->SetPosition(x, y);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GuiButton::RemoveToolTip()
|
||||
{
|
||||
LOCK( this );
|
||||
toolTip = NULL;
|
||||
LOCK( this );
|
||||
toolTip = NULL;
|
||||
}
|
||||
|
||||
void GuiButton::RemoveSoundOver()
|
||||
{
|
||||
LOCK( this );
|
||||
soundOver = NULL;
|
||||
LOCK( this );
|
||||
soundOver = NULL;
|
||||
}
|
||||
void GuiButton::RemoveSoundClick()
|
||||
{
|
||||
LOCK( this );
|
||||
soundClick = NULL;
|
||||
LOCK( this );
|
||||
soundClick = NULL;
|
||||
}
|
||||
void GuiButton::SetSkew(int XX1, int YY1, int XX2, int YY2, int XX3, int YY3, int XX4, int YY4)
|
||||
{
|
||||
if (image)
|
||||
{
|
||||
image->xx1 = XX1;
|
||||
image->yy1 = YY1;
|
||||
image->xx2 = XX2;
|
||||
image->yy2 = YY2;
|
||||
image->xx3 = XX3;
|
||||
image->yy3 = YY3;
|
||||
image->xx4 = XX4;
|
||||
image->yy4 = YY4;
|
||||
}
|
||||
if (image)
|
||||
{
|
||||
image->xx1 = XX1;
|
||||
image->yy1 = YY1;
|
||||
image->xx2 = XX2;
|
||||
image->yy2 = YY2;
|
||||
image->xx3 = XX3;
|
||||
image->yy3 = YY3;
|
||||
image->xx4 = XX4;
|
||||
image->yy4 = YY4;
|
||||
}
|
||||
}
|
||||
|
||||
void GuiButton::SetSkew(int *skew)
|
||||
{
|
||||
if (image) image->SetSkew(skew);
|
||||
if (image) image->SetSkew(skew);
|
||||
}
|
||||
|
||||
void GuiButton::SetState(int s, int c)
|
||||
{
|
||||
GuiElement::SetState(s, c);
|
||||
GuiElement::SetState(s, c);
|
||||
|
||||
if(c < 0 || c > 3)
|
||||
return;
|
||||
return;
|
||||
|
||||
if (s == STATE_CLICKED)
|
||||
{
|
||||
POINT p = {0, 0};
|
||||
{
|
||||
POINT p = {0, 0};
|
||||
|
||||
if (userInput[c].wpad.ir.valid)
|
||||
{
|
||||
p.x = userInput[c].wpad.ir.x;
|
||||
p.y = userInput[c].wpad.ir.y;
|
||||
}
|
||||
if (userInput[c].wpad.ir.valid)
|
||||
{
|
||||
p.x = userInput[c].wpad.ir.x;
|
||||
p.y = userInput[c].wpad.ir.y;
|
||||
}
|
||||
Clicked(this, c, p);
|
||||
}
|
||||
}
|
||||
|
@ -318,225 +318,225 @@ void GuiButton::SetState(int s, int c)
|
|||
*/
|
||||
void GuiButton::Draw()
|
||||
{
|
||||
LOCK( this );
|
||||
if (!this->IsVisible()) return;
|
||||
LOCK( this );
|
||||
if (!this->IsVisible()) return;
|
||||
|
||||
// draw image
|
||||
if ((state == STATE_SELECTED || state == STATE_HELD) && imageOver)
|
||||
imageOver->Draw();
|
||||
else if (image) image->Draw();
|
||||
// draw icon
|
||||
if ((state == STATE_SELECTED || state == STATE_HELD) && iconOver)
|
||||
iconOver->Draw();
|
||||
else if (icon) icon->Draw();
|
||||
// draw text
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
if ((state == STATE_SELECTED || state == STATE_HELD) && labelOver[i])
|
||||
labelOver[i]->Draw();
|
||||
else if (label[i]) label[i]->Draw();
|
||||
}
|
||||
// draw image
|
||||
if ((state == STATE_SELECTED || state == STATE_HELD) && imageOver)
|
||||
imageOver->Draw();
|
||||
else if (image) image->Draw();
|
||||
// draw icon
|
||||
if ((state == STATE_SELECTED || state == STATE_HELD) && iconOver)
|
||||
iconOver->Draw();
|
||||
else if (icon) icon->Draw();
|
||||
// draw text
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
if ((state == STATE_SELECTED || state == STATE_HELD) && labelOver[i])
|
||||
labelOver[i]->Draw();
|
||||
else if (label[i]) label[i]->Draw();
|
||||
}
|
||||
|
||||
this->UpdateEffects();
|
||||
this->UpdateEffects();
|
||||
}
|
||||
void GuiButton::DrawTooltip()
|
||||
{
|
||||
LOCK( this );
|
||||
if (this->IsVisible() && state == STATE_SELECTED && toolTip)
|
||||
{
|
||||
if (time2 == 0)
|
||||
{
|
||||
time(&time1);
|
||||
time2 = time1;
|
||||
}
|
||||
if (time1 != 0) // timer läuft
|
||||
time(&time1);
|
||||
LOCK( this );
|
||||
if (this->IsVisible() && state == STATE_SELECTED && toolTip)
|
||||
{
|
||||
if (time2 == 0)
|
||||
{
|
||||
time(&time1);
|
||||
time2 = time1;
|
||||
}
|
||||
if (time1 != 0) // timer läuft
|
||||
time(&time1);
|
||||
|
||||
if (time1 == 0 || difftime(time1, time2) >= 2)
|
||||
{
|
||||
if (time1 != 0) // timer gerade abgelaufen
|
||||
toolTip->SetEffect(EFFECT_FADE, 20);
|
||||
time1 = 0;
|
||||
toolTip->Draw();
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (time2 != 0 && time1 == 0) // timer abgelaufen, gerade DESELECT
|
||||
if (toolTip) toolTip->SetEffect(EFFECT_FADE, -20);
|
||||
time2 = 0;
|
||||
}
|
||||
if (toolTip && toolTip->GetEffect()) toolTip->Draw();
|
||||
if (time1 == 0 || difftime(time1, time2) >= 2)
|
||||
{
|
||||
if (time1 != 0) // timer gerade abgelaufen
|
||||
toolTip->SetEffect(EFFECT_FADE, 20);
|
||||
time1 = 0;
|
||||
toolTip->Draw();
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (time2 != 0 && time1 == 0) // timer abgelaufen, gerade DESELECT
|
||||
if (toolTip) toolTip->SetEffect(EFFECT_FADE, -20);
|
||||
time2 = 0;
|
||||
}
|
||||
if (toolTip && toolTip->GetEffect()) toolTip->Draw();
|
||||
}
|
||||
void GuiButton::ScrollIsOn(int f)
|
||||
{
|
||||
scrollison = f;
|
||||
scrollison = f;
|
||||
}
|
||||
|
||||
void GuiButton::Update(GuiTrigger * t)
|
||||
{
|
||||
LOCK( this );
|
||||
if (!this->IsVisible() || state == STATE_CLICKED || state == STATE_DISABLED || !t)
|
||||
return;
|
||||
else if (parentElement && parentElement->GetState() == STATE_DISABLED) return;
|
||||
LOCK( this );
|
||||
if (!this->IsVisible() || state == STATE_CLICKED || state == STATE_DISABLED || !t)
|
||||
return;
|
||||
else if (parentElement && parentElement->GetState() == STATE_DISABLED) return;
|
||||
|
||||
#ifdef HW_RVL
|
||||
// cursor
|
||||
if ( t->wpad.ir.valid )
|
||||
{
|
||||
if ( this->IsInside( t->wpad.ir.x, t->wpad.ir.y ) )
|
||||
{
|
||||
if ( state == STATE_DEFAULT ) // we weren't on the button before!
|
||||
// cursor
|
||||
if ( t->wpad.ir.valid )
|
||||
{
|
||||
if ( this->IsInside( t->wpad.ir.x, t->wpad.ir.y ) )
|
||||
{
|
||||
if ( state == STATE_DEFAULT ) // we weren't on the button before!
|
||||
|
||||
{
|
||||
if ( scrollison == 0 )
|
||||
{
|
||||
this->SetState( STATE_SELECTED, t->chan );
|
||||
}
|
||||
{
|
||||
if ( scrollison == 0 )
|
||||
{
|
||||
this->SetState( STATE_SELECTED, t->chan );
|
||||
}
|
||||
|
||||
if ( this->Rumble() && scrollison == 0 )
|
||||
rumbleRequest[t->chan] = 1;
|
||||
if ( this->Rumble() && scrollison == 0 )
|
||||
rumbleRequest[t->chan] = 1;
|
||||
|
||||
if ( soundOver && scrollison == 0 )
|
||||
soundOver->Play();
|
||||
if ( soundOver && scrollison == 0 )
|
||||
soundOver->Play();
|
||||
|
||||
if ( effectsOver && !effects && scrollison == 0 )
|
||||
{
|
||||
// initiate effects
|
||||
effects = effectsOver;
|
||||
effectAmount = effectAmountOver;
|
||||
effectTarget = effectTargetOver;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( state == STATE_SELECTED && ( stateChan == t->chan || stateChan == -1 ) )
|
||||
this->ResetState();
|
||||
if ( effectsOver && !effects && scrollison == 0 )
|
||||
{
|
||||
// initiate effects
|
||||
effects = effectsOver;
|
||||
effectAmount = effectAmountOver;
|
||||
effectTarget = effectTargetOver;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( state == STATE_SELECTED && ( stateChan == t->chan || stateChan == -1 ) )
|
||||
this->ResetState();
|
||||
|
||||
if ( effectTarget == effectTargetOver && effectAmount == effectAmountOver )
|
||||
{
|
||||
// initiate effects (in reverse)
|
||||
effects = effectsOver;
|
||||
effectAmount = -effectAmountOver;
|
||||
effectTarget = 100;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ( effectTarget == effectTargetOver && effectAmount == effectAmountOver )
|
||||
{
|
||||
// initiate effects (in reverse)
|
||||
effects = effectsOver;
|
||||
effectAmount = -effectAmountOver;
|
||||
effectTarget = 100;
|
||||
}
|
||||
}
|
||||
}
|
||||
#else
|
||||
|
||||
if (state == STATE_SELECTED && (stateChan == t->chan || stateChan == -1)) this->ResetState();
|
||||
if (state == STATE_SELECTED && (stateChan == t->chan || stateChan == -1)) this->ResetState();
|
||||
|
||||
if (effectTarget == effectTargetOver && effectAmount == effectAmountOver)
|
||||
{
|
||||
// initiate effects (in reverse)
|
||||
effects = effectsOver;
|
||||
effectAmount = -effectAmountOver;
|
||||
effectTarget = 100;
|
||||
}
|
||||
if (effectTarget == effectTargetOver && effectAmount == effectAmountOver)
|
||||
{
|
||||
// initiate effects (in reverse)
|
||||
effects = effectsOver;
|
||||
effectAmount = -effectAmountOver;
|
||||
effectTarget = 100;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
// button triggers
|
||||
if (this->IsClickable() && scrollison == 0)
|
||||
{
|
||||
s32 wm_btns, wm_btns_trig, cc_btns, cc_btns_trig;
|
||||
for (int i = 0; i < 6; i++)
|
||||
{
|
||||
if (trigger[i] && (trigger[i]->chan == -1 || trigger[i]->chan == t->chan))
|
||||
{
|
||||
// higher 16 bits only (wiimote)
|
||||
wm_btns = t->wpad.btns_d << 16;
|
||||
wm_btns_trig = trigger[i]->wpad.btns_d << 16;
|
||||
// button triggers
|
||||
if (this->IsClickable() && scrollison == 0)
|
||||
{
|
||||
s32 wm_btns, wm_btns_trig, cc_btns, cc_btns_trig;
|
||||
for (int i = 0; i < 6; i++)
|
||||
{
|
||||
if (trigger[i] && (trigger[i]->chan == -1 || trigger[i]->chan == t->chan))
|
||||
{
|
||||
// higher 16 bits only (wiimote)
|
||||
wm_btns = t->wpad.btns_d << 16;
|
||||
wm_btns_trig = trigger[i]->wpad.btns_d << 16;
|
||||
|
||||
// lower 16 bits only (classic controller)
|
||||
cc_btns = t->wpad.btns_d >> 16;
|
||||
cc_btns_trig = trigger[i]->wpad.btns_d >> 16;
|
||||
// lower 16 bits only (classic controller)
|
||||
cc_btns = t->wpad.btns_d >> 16;
|
||||
cc_btns_trig = trigger[i]->wpad.btns_d >> 16;
|
||||
|
||||
if (((t->wpad.btns_d > 0 && wm_btns == wm_btns_trig) || (cc_btns == cc_btns_trig && t->wpad.exp.type
|
||||
== EXP_CLASSIC)) || (t->pad.btns_d == trigger[i]->pad.btns_d && t->pad.btns_d > 0))
|
||||
{
|
||||
if (t->chan == stateChan || stateChan == -1)
|
||||
{
|
||||
if (state == STATE_SELECTED)
|
||||
{
|
||||
this->SetState(STATE_CLICKED, t->chan);
|
||||
if (((t->wpad.btns_d > 0 && wm_btns == wm_btns_trig) || (cc_btns == cc_btns_trig && t->wpad.exp.type
|
||||
== EXP_CLASSIC)) || (t->pad.btns_d == trigger[i]->pad.btns_d && t->pad.btns_d > 0))
|
||||
{
|
||||
if (t->chan == stateChan || stateChan == -1)
|
||||
{
|
||||
if (state == STATE_SELECTED)
|
||||
{
|
||||
this->SetState(STATE_CLICKED, t->chan);
|
||||
|
||||
if (soundClick) soundClick->Play();
|
||||
}
|
||||
else if (trigger[i]->type == TRIGGER_BUTTON_ONLY)
|
||||
{
|
||||
this->SetState(STATE_CLICKED, t->chan);
|
||||
if (soundClick) soundClick->Play();
|
||||
}
|
||||
else if (trigger[i]->type == TRIGGER_BUTTON_ONLY_IN_FOCUS && parentElement->IsFocused())
|
||||
{
|
||||
this->SetState(STATE_CLICKED, t->chan);
|
||||
if (soundClick) soundClick->Play();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (soundClick) soundClick->Play();
|
||||
}
|
||||
else if (trigger[i]->type == TRIGGER_BUTTON_ONLY)
|
||||
{
|
||||
this->SetState(STATE_CLICKED, t->chan);
|
||||
if (soundClick) soundClick->Play();
|
||||
}
|
||||
else if (trigger[i]->type == TRIGGER_BUTTON_ONLY_IN_FOCUS && parentElement->IsFocused())
|
||||
{
|
||||
this->SetState(STATE_CLICKED, t->chan);
|
||||
if (soundClick) soundClick->Play();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (this->IsHoldable())
|
||||
{
|
||||
bool held = false;
|
||||
s32 wm_btns, wm_btns_h, wm_btns_trig, cc_btns, cc_btns_h, cc_btns_trig;
|
||||
if (this->IsHoldable())
|
||||
{
|
||||
bool held = false;
|
||||
s32 wm_btns, wm_btns_h, wm_btns_trig, cc_btns, cc_btns_h, cc_btns_trig;
|
||||
|
||||
for (int i = 0; i < 6; i++)
|
||||
{
|
||||
if (trigger[i] && (trigger[i]->chan == -1 || trigger[i]->chan == t->chan))
|
||||
{
|
||||
// higher 16 bits only (wiimote)
|
||||
wm_btns = t->wpad.btns_d << 16;
|
||||
wm_btns_h = t->wpad.btns_h << 16;
|
||||
wm_btns_trig = trigger[i]->wpad.btns_h << 16;
|
||||
for (int i = 0; i < 6; i++)
|
||||
{
|
||||
if (trigger[i] && (trigger[i]->chan == -1 || trigger[i]->chan == t->chan))
|
||||
{
|
||||
// higher 16 bits only (wiimote)
|
||||
wm_btns = t->wpad.btns_d << 16;
|
||||
wm_btns_h = t->wpad.btns_h << 16;
|
||||
wm_btns_trig = trigger[i]->wpad.btns_h << 16;
|
||||
|
||||
// lower 16 bits only (classic controller)
|
||||
cc_btns = t->wpad.btns_d >> 16;
|
||||
cc_btns_h = t->wpad.btns_h >> 16;
|
||||
cc_btns_trig = trigger[i]->wpad.btns_h >> 16;
|
||||
// lower 16 bits only (classic controller)
|
||||
cc_btns = t->wpad.btns_d >> 16;
|
||||
cc_btns_h = t->wpad.btns_h >> 16;
|
||||
cc_btns_trig = trigger[i]->wpad.btns_h >> 16;
|
||||
|
||||
if (((t->wpad.btns_d > 0 && wm_btns == wm_btns_trig) || (cc_btns == cc_btns_trig && t->wpad.exp.type
|
||||
== EXP_CLASSIC)) || (t->pad.btns_d == trigger[i]->pad.btns_h && t->pad.btns_d > 0))
|
||||
{
|
||||
if (trigger[i]->type == TRIGGER_HELD && state == STATE_SELECTED && (t->chan == stateChan
|
||||
|| stateChan == -1)) this->SetState(STATE_CLICKED, t->chan);
|
||||
}
|
||||
if (((t->wpad.btns_d > 0 && wm_btns == wm_btns_trig) || (cc_btns == cc_btns_trig && t->wpad.exp.type
|
||||
== EXP_CLASSIC)) || (t->pad.btns_d == trigger[i]->pad.btns_h && t->pad.btns_d > 0))
|
||||
{
|
||||
if (trigger[i]->type == TRIGGER_HELD && state == STATE_SELECTED && (t->chan == stateChan
|
||||
|| stateChan == -1)) this->SetState(STATE_CLICKED, t->chan);
|
||||
}
|
||||
|
||||
if (((t->wpad.btns_h > 0 && wm_btns_h == wm_btns_trig) || (cc_btns_h == cc_btns_trig
|
||||
&& t->wpad.exp.type == EXP_CLASSIC)) || (t->pad.btns_h == trigger[i]->pad.btns_h
|
||||
&& t->pad.btns_h > 0))
|
||||
{
|
||||
if (trigger[i]->type == TRIGGER_HELD) held = true;
|
||||
}
|
||||
if (((t->wpad.btns_h > 0 && wm_btns_h == wm_btns_trig) || (cc_btns_h == cc_btns_trig
|
||||
&& t->wpad.exp.type == EXP_CLASSIC)) || (t->pad.btns_h == trigger[i]->pad.btns_h
|
||||
&& t->pad.btns_h > 0))
|
||||
{
|
||||
if (trigger[i]->type == TRIGGER_HELD) held = true;
|
||||
}
|
||||
|
||||
if (!held && state == STATE_HELD && stateChan == t->chan)
|
||||
{
|
||||
this->ResetState();
|
||||
}
|
||||
else if (held && state == STATE_CLICKED && stateChan == t->chan)
|
||||
{
|
||||
this->SetState(STATE_HELD, t->chan);
|
||||
}
|
||||
else if (held && state == STATE_HELD && Held.connected())
|
||||
{
|
||||
POINT p = {0, 0};
|
||||
if (!held && state == STATE_HELD && stateChan == t->chan)
|
||||
{
|
||||
this->ResetState();
|
||||
}
|
||||
else if (held && state == STATE_CLICKED && stateChan == t->chan)
|
||||
{
|
||||
this->SetState(STATE_HELD, t->chan);
|
||||
}
|
||||
else if (held && state == STATE_HELD && Held.connected())
|
||||
{
|
||||
POINT p = {0, 0};
|
||||
|
||||
if (userInput[t->chan].wpad.ir.valid)
|
||||
{
|
||||
p.x = userInput[t->chan].wpad.ir.x;
|
||||
p.y = userInput[t->chan].wpad.ir.y;
|
||||
}
|
||||
Held(this, t->chan, p);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (userInput[t->chan].wpad.ir.valid)
|
||||
{
|
||||
p.x = userInput[t->chan].wpad.ir.x;
|
||||
p.y = userInput[t->chan].wpad.ir.y;
|
||||
}
|
||||
Held(this, t->chan, p);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (updateCB) updateCB(this);
|
||||
if (updateCB) updateCB(this);
|
||||
}
|
||||
|
||||
|
|
|
@ -26,115 +26,115 @@
|
|||
#define WHITEBOX_RED_SIZE 4
|
||||
|
||||
GuiCheckbox::GuiCheckbox(int s)
|
||||
: GuiButton(30, 30), Checked(false)
|
||||
: GuiButton(30, 30), Checked(false)
|
||||
{
|
||||
style = s;
|
||||
Checksign.SetParent(this);
|
||||
Cross.SetParent(this);
|
||||
Blackbox.SetParent(this);
|
||||
Whitebox.SetParent(this);
|
||||
Checksign.SetColor((GXColor) {0, 0, 0, 255});
|
||||
Cross.SetColor((GXColor) {0, 0, 0, 255});
|
||||
Blackbox.SetColor((GXColor) {0, 0, 0, 255});
|
||||
Whitebox.SetColor((GXColor) {255, 255, 255, 255});
|
||||
Checksign.SetParent(this);
|
||||
Cross.SetParent(this);
|
||||
Blackbox.SetParent(this);
|
||||
Whitebox.SetParent(this);
|
||||
Checksign.SetColor((GXColor) {0, 0, 0, 255});
|
||||
Cross.SetColor((GXColor) {0, 0, 0, 255});
|
||||
Blackbox.SetColor((GXColor) {0, 0, 0, 255});
|
||||
Whitebox.SetColor((GXColor) {255, 255, 255, 255});
|
||||
|
||||
SetSize(30, 30);
|
||||
SetSize(30, 30);
|
||||
}
|
||||
|
||||
GuiCheckbox::GuiCheckbox(int w, int h, int s)
|
||||
: GuiButton(w, h), Checked(false)
|
||||
: GuiButton(w, h), Checked(false)
|
||||
{
|
||||
style = s;
|
||||
Checksign.SetParent(this);
|
||||
Cross.SetParent(this);
|
||||
Blackbox.SetParent(this);
|
||||
Whitebox.SetParent(this);
|
||||
Checksign.SetColor((GXColor) {0, 0, 0, 255});
|
||||
Cross.SetColor((GXColor) {0, 0, 0, 255});
|
||||
Blackbox.SetColor((GXColor) {0, 0, 0, 255});
|
||||
Whitebox.SetColor((GXColor) {255, 255, 255, 255});
|
||||
Checksign.SetParent(this);
|
||||
Cross.SetParent(this);
|
||||
Blackbox.SetParent(this);
|
||||
Whitebox.SetParent(this);
|
||||
Checksign.SetColor((GXColor) {0, 0, 0, 255});
|
||||
Cross.SetColor((GXColor) {0, 0, 0, 255});
|
||||
Blackbox.SetColor((GXColor) {0, 0, 0, 255});
|
||||
Whitebox.SetColor((GXColor) {255, 255, 255, 255});
|
||||
|
||||
SetSize(w, h);
|
||||
SetSize(w, h);
|
||||
}
|
||||
|
||||
void GuiCheckbox::SetSize(int w, int h)
|
||||
{
|
||||
width = w;
|
||||
height = h;
|
||||
Checksign.SetSize(w-WHITEBOX_RED_SIZE, h-WHITEBOX_RED_SIZE);
|
||||
Checksign.SetPosition(WHITEBOX_RED_SIZE/2, WHITEBOX_RED_SIZE/2);
|
||||
Cross.SetSize(w-WHITEBOX_RED_SIZE, h-WHITEBOX_RED_SIZE);
|
||||
Cross.SetPosition(WHITEBOX_RED_SIZE/2, WHITEBOX_RED_SIZE/2);
|
||||
Blackbox.SetSize(w, h);
|
||||
Whitebox.SetSize(w-WHITEBOX_RED_SIZE, h-WHITEBOX_RED_SIZE);
|
||||
Whitebox.SetPosition(WHITEBOX_RED_SIZE/2, WHITEBOX_RED_SIZE/2);
|
||||
SetAlignment(alignmentHor, alignmentVert);
|
||||
width = w;
|
||||
height = h;
|
||||
Checksign.SetSize(w-WHITEBOX_RED_SIZE, h-WHITEBOX_RED_SIZE);
|
||||
Checksign.SetPosition(WHITEBOX_RED_SIZE/2, WHITEBOX_RED_SIZE/2);
|
||||
Cross.SetSize(w-WHITEBOX_RED_SIZE, h-WHITEBOX_RED_SIZE);
|
||||
Cross.SetPosition(WHITEBOX_RED_SIZE/2, WHITEBOX_RED_SIZE/2);
|
||||
Blackbox.SetSize(w, h);
|
||||
Whitebox.SetSize(w-WHITEBOX_RED_SIZE, h-WHITEBOX_RED_SIZE);
|
||||
Whitebox.SetPosition(WHITEBOX_RED_SIZE/2, WHITEBOX_RED_SIZE/2);
|
||||
SetAlignment(alignmentHor, alignmentVert);
|
||||
}
|
||||
|
||||
void GuiCheckbox::SetClickSize(int w, int h)
|
||||
{
|
||||
width = w;
|
||||
height = h;
|
||||
width = w;
|
||||
height = h;
|
||||
}
|
||||
|
||||
void GuiCheckbox::SetTransparent(bool b)
|
||||
{
|
||||
Blackbox.SetFilled(b);
|
||||
Whitebox.SetFilled(b);
|
||||
Blackbox.SetFilled(b);
|
||||
Whitebox.SetFilled(b);
|
||||
}
|
||||
|
||||
void GuiCheckbox::SetState(int s, int c)
|
||||
{
|
||||
if(s == STATE_CLICKED)
|
||||
Checked = !Checked;
|
||||
if(s == STATE_CLICKED)
|
||||
Checked = !Checked;
|
||||
|
||||
GuiButton::SetState(s, c);
|
||||
GuiButton::SetState(s, c);
|
||||
}
|
||||
|
||||
void GuiCheckbox::SetAlignment(int h, int v)
|
||||
{
|
||||
GuiButton::SetAlignment(h, v);
|
||||
Checksign.SetAlignment(h, v);
|
||||
Cross.SetAlignment(h, v);
|
||||
Blackbox.SetAlignment(h, v);
|
||||
Whitebox.SetAlignment(h, v);
|
||||
GuiButton::SetAlignment(h, v);
|
||||
Checksign.SetAlignment(h, v);
|
||||
Cross.SetAlignment(h, v);
|
||||
Blackbox.SetAlignment(h, v);
|
||||
Whitebox.SetAlignment(h, v);
|
||||
|
||||
if(h == ALIGN_RIGHT)
|
||||
{
|
||||
Checksign.SetPosition(-WHITEBOX_RED_SIZE/2, Checksign.GetTopPos());
|
||||
Cross.SetPosition(-WHITEBOX_RED_SIZE/2, Cross.GetTopPos());
|
||||
Whitebox.SetPosition(-WHITEBOX_RED_SIZE/2, Whitebox.GetTopPos());
|
||||
}
|
||||
else if(h == ALIGN_CENTER)
|
||||
{
|
||||
Checksign.SetPosition(0, Checksign.GetTopPos());
|
||||
Cross.SetPosition(0, Cross.GetTopPos());
|
||||
Whitebox.SetPosition(0, Whitebox.GetTopPos());
|
||||
}
|
||||
if(v == ALIGN_BOTTOM)
|
||||
{
|
||||
Checksign.SetPosition(Checksign.GetLeftPos(), -WHITEBOX_RED_SIZE/2);
|
||||
Cross.SetPosition(Cross.GetLeftPos(), -WHITEBOX_RED_SIZE/2);
|
||||
Whitebox.SetPosition(Whitebox.GetLeftPos(), -WHITEBOX_RED_SIZE/2);
|
||||
}
|
||||
else if(v == ALIGN_MIDDLE)
|
||||
{
|
||||
Checksign.SetPosition(Checksign.GetLeftPos(), 0);
|
||||
Cross.SetPosition(Cross.GetLeftPos(), 0);
|
||||
Whitebox.SetPosition(Whitebox.GetLeftPos(), 0);
|
||||
}
|
||||
if(h == ALIGN_RIGHT)
|
||||
{
|
||||
Checksign.SetPosition(-WHITEBOX_RED_SIZE/2, Checksign.GetTopPos());
|
||||
Cross.SetPosition(-WHITEBOX_RED_SIZE/2, Cross.GetTopPos());
|
||||
Whitebox.SetPosition(-WHITEBOX_RED_SIZE/2, Whitebox.GetTopPos());
|
||||
}
|
||||
else if(h == ALIGN_CENTER)
|
||||
{
|
||||
Checksign.SetPosition(0, Checksign.GetTopPos());
|
||||
Cross.SetPosition(0, Cross.GetTopPos());
|
||||
Whitebox.SetPosition(0, Whitebox.GetTopPos());
|
||||
}
|
||||
if(v == ALIGN_BOTTOM)
|
||||
{
|
||||
Checksign.SetPosition(Checksign.GetLeftPos(), -WHITEBOX_RED_SIZE/2);
|
||||
Cross.SetPosition(Cross.GetLeftPos(), -WHITEBOX_RED_SIZE/2);
|
||||
Whitebox.SetPosition(Whitebox.GetLeftPos(), -WHITEBOX_RED_SIZE/2);
|
||||
}
|
||||
else if(v == ALIGN_MIDDLE)
|
||||
{
|
||||
Checksign.SetPosition(Checksign.GetLeftPos(), 0);
|
||||
Cross.SetPosition(Cross.GetLeftPos(), 0);
|
||||
Whitebox.SetPosition(Whitebox.GetLeftPos(), 0);
|
||||
}
|
||||
}
|
||||
|
||||
void GuiCheckbox::Draw()
|
||||
{
|
||||
GuiButton::Draw();
|
||||
Blackbox.Draw();
|
||||
Whitebox.Draw();
|
||||
if(Checked)
|
||||
{
|
||||
if(style == CHECKSIGN)
|
||||
Checksign.Draw();
|
||||
else
|
||||
Cross.Draw();
|
||||
}
|
||||
GuiButton::Draw();
|
||||
Blackbox.Draw();
|
||||
Whitebox.Draw();
|
||||
if(Checked)
|
||||
{
|
||||
if(style == CHECKSIGN)
|
||||
Checksign.Draw();
|
||||
else
|
||||
Cross.Draw();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,29 +31,29 @@
|
|||
|
||||
class GuiCheckbox : public GuiButton
|
||||
{
|
||||
public:
|
||||
GuiCheckbox(int style = CHECKSIGN);
|
||||
GuiCheckbox(int w, int h, int style = CHECKSIGN);
|
||||
void SetTransparent(bool b);
|
||||
void SetSize(int w, int h);
|
||||
void SetClickSize(int w, int h);
|
||||
void SetAlignment(int h, int v);
|
||||
void SetChecked(bool c) { LOCK(this); Checked = c; }
|
||||
bool IsChecked() const { return Checked; }
|
||||
virtual void SetState(int s, int c = -1);
|
||||
virtual void Draw();
|
||||
enum
|
||||
{
|
||||
CHECKSIGN,
|
||||
CROSS,
|
||||
};
|
||||
protected:
|
||||
GuiChecksign Checksign;
|
||||
GuiCross Cross;
|
||||
GuiBox Blackbox;
|
||||
GuiBox Whitebox;
|
||||
int style;
|
||||
bool Checked;
|
||||
public:
|
||||
GuiCheckbox(int style = CHECKSIGN);
|
||||
GuiCheckbox(int w, int h, int style = CHECKSIGN);
|
||||
void SetTransparent(bool b);
|
||||
void SetSize(int w, int h);
|
||||
void SetClickSize(int w, int h);
|
||||
void SetAlignment(int h, int v);
|
||||
void SetChecked(bool c) { LOCK(this); Checked = c; }
|
||||
bool IsChecked() const { return Checked; }
|
||||
virtual void SetState(int s, int c = -1);
|
||||
virtual void Draw();
|
||||
enum
|
||||
{
|
||||
CHECKSIGN,
|
||||
CROSS,
|
||||
};
|
||||
protected:
|
||||
GuiChecksign Checksign;
|
||||
GuiCross Cross;
|
||||
GuiBox Blackbox;
|
||||
GuiBox Whitebox;
|
||||
int style;
|
||||
bool Checked;
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -28,104 +28,104 @@
|
|||
|
||||
|
||||
GuiCheckboxBrowser::GuiCheckboxBrowser(int w, int h, int s)
|
||||
: scrollBar(h-10)
|
||||
: scrollBar(h-10)
|
||||
{
|
||||
width = w;
|
||||
height = h;
|
||||
backgroundImg = NULL;
|
||||
selectedItem = 0;
|
||||
pageIndex = 0;
|
||||
pressedChan = -1;
|
||||
maxSize = s;
|
||||
scrollBar.SetParent(this);
|
||||
scrollBar.SetAlignment(thAlign("right - checkbox browser scrollbar align hor"), thAlign("top - checkbox browser scrollbar align ver"));
|
||||
scrollBar.SetPosition(thInt("0 - checkbox browser scrollbar pos x"), thInt("5 - checkbox browser scrollbar pos y"));
|
||||
scrollBar.SetButtonScroll(WPAD_BUTTON_B | WPAD_CLASSIC_BUTTON_B);
|
||||
scrollBar.listChanged.connect(this, &GuiCheckboxBrowser::onListChange);
|
||||
trigA.SetSimpleTrigger(-1, WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A, PAD_BUTTON_A);
|
||||
markImgData = Resources::GetImageData("checkBoxSelection.png");
|
||||
markImg = new GuiImage(markImgData);
|
||||
markImg->SetParent(this);
|
||||
width = w;
|
||||
height = h;
|
||||
backgroundImg = NULL;
|
||||
selectedItem = 0;
|
||||
pageIndex = 0;
|
||||
pressedChan = -1;
|
||||
maxSize = s;
|
||||
scrollBar.SetParent(this);
|
||||
scrollBar.SetAlignment(thAlign("right - checkbox browser scrollbar align hor"), thAlign("top - checkbox browser scrollbar align ver"));
|
||||
scrollBar.SetPosition(thInt("0 - checkbox browser scrollbar pos x"), thInt("5 - checkbox browser scrollbar pos y"));
|
||||
scrollBar.SetButtonScroll(WPAD_BUTTON_B | WPAD_CLASSIC_BUTTON_B);
|
||||
scrollBar.listChanged.connect(this, &GuiCheckboxBrowser::onListChange);
|
||||
trigA.SetSimpleTrigger(-1, WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A, PAD_BUTTON_A);
|
||||
markImgData = Resources::GetImageData("checkBoxSelection.png");
|
||||
markImg = new GuiImage(markImgData);
|
||||
markImg->SetParent(this);
|
||||
}
|
||||
|
||||
GuiCheckboxBrowser::~GuiCheckboxBrowser()
|
||||
{
|
||||
Clear();
|
||||
Clear();
|
||||
|
||||
delete markImg;
|
||||
delete markImgData;
|
||||
delete markImg;
|
||||
delete markImgData;
|
||||
}
|
||||
|
||||
void GuiCheckboxBrowser::SetImage(GuiImage *Img)
|
||||
{
|
||||
LOCK(this);
|
||||
backgroundImg = Img;
|
||||
if(backgroundImg)
|
||||
backgroundImg->SetParent(this);
|
||||
LOCK(this);
|
||||
backgroundImg = Img;
|
||||
if(backgroundImg)
|
||||
backgroundImg->SetParent(this);
|
||||
}
|
||||
|
||||
void GuiCheckboxBrowser::Clear()
|
||||
{
|
||||
LOCK(this);
|
||||
checkBoxDrawn.clear();
|
||||
textLineDrawn.clear();
|
||||
LOCK(this);
|
||||
checkBoxDrawn.clear();
|
||||
textLineDrawn.clear();
|
||||
|
||||
for(u32 i = 0; i < checkBoxList.size(); ++i)
|
||||
{
|
||||
delete textLineList[i];
|
||||
delete checkBoxList[i];
|
||||
}
|
||||
for(u32 i = 0; i < checkBoxList.size(); ++i)
|
||||
{
|
||||
delete textLineList[i];
|
||||
delete checkBoxList[i];
|
||||
}
|
||||
|
||||
textLineList.clear();
|
||||
checkBoxList.clear();
|
||||
textLineList.clear();
|
||||
checkBoxList.clear();
|
||||
}
|
||||
|
||||
bool GuiCheckboxBrowser::AddEntrie(const string &text, bool checked)
|
||||
{
|
||||
LOCK(this);
|
||||
int currentSize = checkBoxList.size();
|
||||
textLineList.resize(currentSize+1);
|
||||
checkBoxList.resize(currentSize+1);
|
||||
LOCK(this);
|
||||
int currentSize = checkBoxList.size();
|
||||
textLineList.resize(currentSize+1);
|
||||
checkBoxList.resize(currentSize+1);
|
||||
|
||||
checkBoxList[currentSize] = new GuiCheckbox(30, 30);
|
||||
checkBoxList[currentSize]->SetParent(this);
|
||||
checkBoxList[currentSize]->SetChecked(checked);
|
||||
checkBoxList[currentSize]->SetAlignment(ALIGN_RIGHT, ALIGN_TOP);
|
||||
checkBoxList[currentSize]->SetTrigger(&trigA);
|
||||
checkBoxList[currentSize]->SetClickSize(width-30-scrollBar.GetWidth(), 30);
|
||||
checkBoxList[currentSize]->Clicked.connect(this, &GuiCheckboxBrowser::OnCheckboxClick);
|
||||
checkBoxList[currentSize] = new GuiCheckbox(30, 30);
|
||||
checkBoxList[currentSize]->SetParent(this);
|
||||
checkBoxList[currentSize]->SetChecked(checked);
|
||||
checkBoxList[currentSize]->SetAlignment(ALIGN_RIGHT, ALIGN_TOP);
|
||||
checkBoxList[currentSize]->SetTrigger(&trigA);
|
||||
checkBoxList[currentSize]->SetClickSize(width-30-scrollBar.GetWidth(), 30);
|
||||
checkBoxList[currentSize]->Clicked.connect(this, &GuiCheckboxBrowser::OnCheckboxClick);
|
||||
|
||||
textLineList[currentSize] = new GuiText(text.c_str(), 18, thColor("r=0 g=0 b=0 a=255 - checkbox browser text color"));
|
||||
textLineList[currentSize]->SetParent(this);
|
||||
textLineList[currentSize]->SetAlignment(ALIGN_LEFT, ALIGN_TOP);
|
||||
textLineList[currentSize] = new GuiText(text.c_str(), 18, thColor("r=0 g=0 b=0 a=255 - checkbox browser text color"));
|
||||
textLineList[currentSize]->SetParent(this);
|
||||
textLineList[currentSize]->SetAlignment(ALIGN_LEFT, ALIGN_TOP);
|
||||
|
||||
if(textLineDrawn.size() < (u32) maxSize)
|
||||
{
|
||||
textLineDrawn.push_back(textLineList[currentSize]);
|
||||
checkBoxDrawn.push_back(checkBoxList[currentSize]);
|
||||
}
|
||||
if(textLineDrawn.size() < (u32) maxSize)
|
||||
{
|
||||
textLineDrawn.push_back(textLineList[currentSize]);
|
||||
checkBoxDrawn.push_back(checkBoxList[currentSize]);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void GuiCheckboxBrowser::OnCheckboxClick(GuiButton *sender, int chan, const POINT &pointer)
|
||||
{
|
||||
LOCK(this);
|
||||
sender->ResetState();
|
||||
LOCK(this);
|
||||
sender->ResetState();
|
||||
|
||||
for(u32 i = 0; i < checkBoxDrawn.size(); ++i)
|
||||
{
|
||||
if(sender == checkBoxDrawn[i])
|
||||
{
|
||||
checkBoxClicked(checkBoxDrawn[i], pageIndex+i);
|
||||
return;
|
||||
}
|
||||
}
|
||||
for(u32 i = 0; i < checkBoxDrawn.size(); ++i)
|
||||
{
|
||||
if(sender == checkBoxDrawn[i])
|
||||
{
|
||||
checkBoxClicked(checkBoxDrawn[i], pageIndex+i);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GuiCheckboxBrowser::onListChange(int SelItem, int SelInd)
|
||||
{
|
||||
LOCK(this);
|
||||
LOCK(this);
|
||||
selectedItem = SelItem;
|
||||
pageIndex = SelInd;
|
||||
RefreshList();
|
||||
|
@ -133,43 +133,43 @@ void GuiCheckboxBrowser::onListChange(int SelItem, int SelInd)
|
|||
|
||||
void GuiCheckboxBrowser::RefreshList()
|
||||
{
|
||||
LOCK(this);
|
||||
while(pageIndex+checkBoxDrawn.size() > checkBoxList.size())
|
||||
--pageIndex;
|
||||
LOCK(this);
|
||||
while(pageIndex+checkBoxDrawn.size() > checkBoxList.size())
|
||||
--pageIndex;
|
||||
|
||||
if(checkBoxDrawn.size() == 0)
|
||||
selectedItem = 0;
|
||||
else if(selectedItem >= (int) checkBoxDrawn.size())
|
||||
selectedItem = checkBoxDrawn.size()-1;
|
||||
if(checkBoxDrawn.size() == 0)
|
||||
selectedItem = 0;
|
||||
else if(selectedItem >= (int) checkBoxDrawn.size())
|
||||
selectedItem = checkBoxDrawn.size()-1;
|
||||
|
||||
for(u32 i = 0; i < checkBoxDrawn.size(); i++)
|
||||
{
|
||||
checkBoxDrawn[i] = checkBoxList[pageIndex+i];
|
||||
checkBoxDrawn[i]->SetPosition(-scrollBar.GetWidth()-10, 15+i*(checkBoxDrawn[i]->GetHeight()+6));
|
||||
checkBoxDrawn[i] = checkBoxList[pageIndex+i];
|
||||
checkBoxDrawn[i]->SetPosition(-scrollBar.GetWidth()-10, 15+i*(checkBoxDrawn[i]->GetHeight()+6));
|
||||
|
||||
textLineDrawn[i] = textLineList[pageIndex+i];
|
||||
textLineDrawn[i]->SetPosition(25, 15+i*(checkBoxDrawn[i]->GetHeight()+6)+(checkBoxDrawn[i]->GetHeight()-textLineDrawn[i]->GetFontSize())/2+2);
|
||||
textLineDrawn[i] = textLineList[pageIndex+i];
|
||||
textLineDrawn[i]->SetPosition(25, 15+i*(checkBoxDrawn[i]->GetHeight()+6)+(checkBoxDrawn[i]->GetHeight()-textLineDrawn[i]->GetFontSize())/2+2);
|
||||
}
|
||||
scrollBar.SetSelectedItem(selectedItem);
|
||||
scrollBar.SetSelectedIndex(pageIndex);
|
||||
scrollBar.SetSelectedItem(selectedItem);
|
||||
scrollBar.SetSelectedIndex(pageIndex);
|
||||
}
|
||||
|
||||
void GuiCheckboxBrowser::Draw()
|
||||
{
|
||||
LOCK(this);
|
||||
if(backgroundImg)
|
||||
backgroundImg->Draw();
|
||||
LOCK(this);
|
||||
if(backgroundImg)
|
||||
backgroundImg->Draw();
|
||||
|
||||
for(u32 i = 0; i < checkBoxDrawn.size(); ++i)
|
||||
{
|
||||
textLineDrawn[i]->Draw();
|
||||
checkBoxDrawn[i]->Draw();
|
||||
}
|
||||
for(u32 i = 0; i < checkBoxDrawn.size(); ++i)
|
||||
{
|
||||
textLineDrawn[i]->Draw();
|
||||
checkBoxDrawn[i]->Draw();
|
||||
}
|
||||
|
||||
markImg->Draw();
|
||||
markImg->Draw();
|
||||
|
||||
if(checkBoxList.size() >= (u32) maxSize)
|
||||
scrollBar.Draw();
|
||||
if(checkBoxList.size() >= (u32) maxSize)
|
||||
scrollBar.Draw();
|
||||
}
|
||||
|
||||
void GuiCheckboxBrowser::Update(GuiTrigger *t)
|
||||
|
@ -177,39 +177,39 @@ void GuiCheckboxBrowser::Update(GuiTrigger *t)
|
|||
if(state == STATE_DISABLED || !t)
|
||||
return;
|
||||
|
||||
LOCK(this);
|
||||
if(checkBoxList.size() >= maxSize)
|
||||
scrollBar.Update(t);
|
||||
LOCK(this);
|
||||
if(checkBoxList.size() >= maxSize)
|
||||
scrollBar.Update(t);
|
||||
|
||||
if((t->wpad.btns_d & (WPAD_BUTTON_B | WPAD_BUTTON_DOWN | WPAD_BUTTON_UP | WPAD_BUTTON_LEFT | WPAD_BUTTON_RIGHT |
|
||||
WPAD_CLASSIC_BUTTON_B | WPAD_CLASSIC_BUTTON_UP | WPAD_CLASSIC_BUTTON_DOWN | WPAD_CLASSIC_BUTTON_LEFT | WPAD_CLASSIC_BUTTON_RIGHT)) ||
|
||||
(t->pad.btns_d & (PAD_BUTTON_UP | PAD_BUTTON_DOWN)))
|
||||
pressedChan = t->chan;
|
||||
if((t->wpad.btns_d & (WPAD_BUTTON_B | WPAD_BUTTON_DOWN | WPAD_BUTTON_UP | WPAD_BUTTON_LEFT | WPAD_BUTTON_RIGHT |
|
||||
WPAD_CLASSIC_BUTTON_B | WPAD_CLASSIC_BUTTON_UP | WPAD_CLASSIC_BUTTON_DOWN | WPAD_CLASSIC_BUTTON_LEFT | WPAD_CLASSIC_BUTTON_RIGHT)) ||
|
||||
(t->pad.btns_d & (PAD_BUTTON_UP | PAD_BUTTON_DOWN)))
|
||||
pressedChan = t->chan;
|
||||
|
||||
for(u32 i = 0; i < checkBoxDrawn.size(); i++)
|
||||
{
|
||||
if(pressedChan == -1 || (!t->wpad.btns_h && !t->pad.btns_h))
|
||||
{
|
||||
if(i != (u32) selectedItem && checkBoxDrawn[i]->GetState() == STATE_SELECTED)
|
||||
checkBoxDrawn[i]->ResetState();
|
||||
else if(i == (u32) selectedItem && checkBoxDrawn[i]->GetState() == STATE_DEFAULT)
|
||||
checkBoxDrawn[selectedItem]->SetState(STATE_SELECTED, -1);
|
||||
if(pressedChan == -1 || (!t->wpad.btns_h && !t->pad.btns_h))
|
||||
{
|
||||
if(i != (u32) selectedItem && checkBoxDrawn[i]->GetState() == STATE_SELECTED)
|
||||
checkBoxDrawn[i]->ResetState();
|
||||
else if(i == (u32) selectedItem && checkBoxDrawn[i]->GetState() == STATE_DEFAULT)
|
||||
checkBoxDrawn[selectedItem]->SetState(STATE_SELECTED, -1);
|
||||
|
||||
checkBoxDrawn[i]->Update(t);
|
||||
checkBoxDrawn[i]->Update(t);
|
||||
|
||||
if(checkBoxDrawn[i]->GetState() == STATE_SELECTED)
|
||||
selectedItem = i;
|
||||
}
|
||||
if(checkBoxDrawn[i]->GetState() == STATE_SELECTED)
|
||||
selectedItem = i;
|
||||
}
|
||||
|
||||
if(i == (u32) selectedItem)
|
||||
markImg->SetPosition(5, 15+i*(checkBoxDrawn[i]->GetHeight()+6)+(checkBoxDrawn[i]->GetHeight()-markImg->GetHeight())/2);
|
||||
markImg->SetPosition(5, 15+i*(checkBoxDrawn[i]->GetHeight()+6)+(checkBoxDrawn[i]->GetHeight()-markImg->GetHeight())/2);
|
||||
}
|
||||
|
||||
if(pressedChan == t->chan && !t->wpad.btns_d && !t->wpad.btns_h)
|
||||
pressedChan = -1;
|
||||
if(pressedChan == t->chan && !t->wpad.btns_d && !t->wpad.btns_h)
|
||||
pressedChan = -1;
|
||||
|
||||
scrollBar.SetPageSize(checkBoxDrawn.size());
|
||||
scrollBar.SetSelectedItem(selectedItem);
|
||||
scrollBar.SetSelectedIndex(pageIndex);
|
||||
scrollBar.SetEntrieCount(checkBoxList.size());
|
||||
scrollBar.SetPageSize(checkBoxDrawn.size());
|
||||
scrollBar.SetSelectedItem(selectedItem);
|
||||
scrollBar.SetSelectedIndex(pageIndex);
|
||||
scrollBar.SetEntrieCount(checkBoxList.size());
|
||||
}
|
||||
|
|
|
@ -33,35 +33,35 @@ using namespace std;
|
|||
|
||||
class GuiCheckboxBrowser : public GuiElement, public sigslot::has_slots<>
|
||||
{
|
||||
public:
|
||||
GuiCheckboxBrowser(int w, int h, int maxSize = 7);
|
||||
virtual ~GuiCheckboxBrowser();
|
||||
bool AddEntrie(const string &text, bool checked = false);
|
||||
int GetSelected() const { return pageIndex+selectedItem; };
|
||||
void SetImage(GuiImage *Img);
|
||||
void RefreshList();
|
||||
void Clear();
|
||||
void Draw();
|
||||
void Update(GuiTrigger *t);
|
||||
public:
|
||||
GuiCheckboxBrowser(int w, int h, int maxSize = 7);
|
||||
virtual ~GuiCheckboxBrowser();
|
||||
bool AddEntrie(const string &text, bool checked = false);
|
||||
int GetSelected() const { return pageIndex+selectedItem; };
|
||||
void SetImage(GuiImage *Img);
|
||||
void RefreshList();
|
||||
void Clear();
|
||||
void Draw();
|
||||
void Update(GuiTrigger *t);
|
||||
sigslot::signal2<GuiCheckbox *, int> checkBoxClicked;
|
||||
private:
|
||||
void onListChange(int SelItem, int SelInd);
|
||||
void OnCheckboxClick(GuiButton *sender, int chan, const POINT &pointer);
|
||||
u16 maxSize;
|
||||
int selectedItem;
|
||||
int pageIndex;
|
||||
int pressedChan;
|
||||
bool blocked;
|
||||
private:
|
||||
void onListChange(int SelItem, int SelInd);
|
||||
void OnCheckboxClick(GuiButton *sender, int chan, const POINT &pointer);
|
||||
u16 maxSize;
|
||||
int selectedItem;
|
||||
int pageIndex;
|
||||
int pressedChan;
|
||||
bool blocked;
|
||||
|
||||
GuiScrollbar scrollBar;
|
||||
GuiTrigger trigA;
|
||||
GuiImage *backgroundImg;
|
||||
GuiImageData *markImgData;
|
||||
GuiImage *markImg;
|
||||
vector<GuiText *> textLineDrawn;
|
||||
vector<GuiCheckbox *> checkBoxDrawn;
|
||||
vector<GuiText *> textLineList;
|
||||
vector<GuiCheckbox *> checkBoxList;
|
||||
GuiScrollbar scrollBar;
|
||||
GuiTrigger trigA;
|
||||
GuiImage *backgroundImg;
|
||||
GuiImageData *markImgData;
|
||||
GuiImage *markImg;
|
||||
vector<GuiText *> textLineDrawn;
|
||||
vector<GuiCheckbox *> checkBoxDrawn;
|
||||
vector<GuiText *> textLineList;
|
||||
vector<GuiCheckbox *> checkBoxList;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -25,32 +25,32 @@
|
|||
|
||||
void GuiChecksign::Draw()
|
||||
{
|
||||
GX_SetTevOp(GX_TEVSTAGE0, GX_PASSCLR);
|
||||
GX_SetVtxDesc(GX_VA_POS, GX_DIRECT);
|
||||
GX_SetVtxDesc(GX_VA_CLR0, GX_DIRECT);
|
||||
GX_SetVtxDesc(GX_VA_TEX0, GX_NONE);
|
||||
GX_SetTevOp(GX_TEVSTAGE0, GX_PASSCLR);
|
||||
GX_SetVtxDesc(GX_VA_POS, GX_DIRECT);
|
||||
GX_SetVtxDesc(GX_VA_CLR0, GX_DIRECT);
|
||||
GX_SetVtxDesc(GX_VA_TEX0, GX_NONE);
|
||||
|
||||
f32 x1Line1 = (float) GetLeft() + width*0.1f;
|
||||
f32 y1Line1 = (float) GetTop() + height*0.65f;
|
||||
f32 x2Line1 = GetLeft() + width*0.3f;
|
||||
f32 y2Line1 = (float) GetTop() + (float) height - height*0.1f;
|
||||
f32 x1Line1 = (float) GetLeft() + width*0.1f;
|
||||
f32 y1Line1 = (float) GetTop() + height*0.65f;
|
||||
f32 x2Line1 = GetLeft() + width*0.3f;
|
||||
f32 y2Line1 = (float) GetTop() + (float) height - height*0.1f;
|
||||
|
||||
f32 x1Line2 = x2Line1;
|
||||
f32 y1Line2 = y2Line1;
|
||||
f32 x2Line2 = (float) GetLeft() + (float) width - width*0.1f;
|
||||
f32 y2Line2 = (float) GetTop() + height*0.1f;
|
||||
f32 x1Line2 = x2Line1;
|
||||
f32 y1Line2 = y2Line1;
|
||||
f32 x2Line2 = (float) GetLeft() + (float) width - width*0.1f;
|
||||
f32 y2Line2 = (float) GetTop() + height*0.1f;
|
||||
|
||||
int alpha = GetAlpha();
|
||||
int alpha = GetAlpha();
|
||||
|
||||
GX_Begin(GX_LINES, GX_VTXFMT0, 4);
|
||||
GX_Position3f32(x1Line1, y1Line1, 0.0f);
|
||||
GX_Color4u8(color.r, color.g, color.b, alpha);
|
||||
GX_Position3f32(x2Line1, y2Line1, 0.0f);
|
||||
GX_Color4u8(color.r, color.g, color.b, alpha);
|
||||
GX_Position3f32(x1Line2, y1Line2, 0.0f);
|
||||
GX_Color4u8(color.r, color.g, color.b, alpha);
|
||||
GX_Position3f32(x2Line2, y2Line2, 0.0f);
|
||||
GX_Color4u8(color.r, color.g, color.b, alpha);
|
||||
GX_End();
|
||||
GX_SetTevOp(GX_TEVSTAGE0, GX_MODULATE);
|
||||
GX_Begin(GX_LINES, GX_VTXFMT0, 4);
|
||||
GX_Position3f32(x1Line1, y1Line1, 0.0f);
|
||||
GX_Color4u8(color.r, color.g, color.b, alpha);
|
||||
GX_Position3f32(x2Line1, y2Line1, 0.0f);
|
||||
GX_Color4u8(color.r, color.g, color.b, alpha);
|
||||
GX_Position3f32(x1Line2, y1Line2, 0.0f);
|
||||
GX_Color4u8(color.r, color.g, color.b, alpha);
|
||||
GX_Position3f32(x2Line2, y2Line2, 0.0f);
|
||||
GX_Color4u8(color.r, color.g, color.b, alpha);
|
||||
GX_End();
|
||||
GX_SetTevOp(GX_TEVSTAGE0, GX_MODULATE);
|
||||
}
|
||||
|
|
|
@ -28,16 +28,16 @@
|
|||
|
||||
class GuiChecksign : public GuiElement
|
||||
{
|
||||
public:
|
||||
GuiChecksign() : Linewidth(2.0f) { color = (GXColor) {0, 0, 0, 255}; GX_SetLineWidth((u8) (Linewidth*6.0f), 0); }
|
||||
//! Max line width is 42.5 pixel
|
||||
void SetLinewidth(float w) { LOCK(this); Linewidth = w; GX_SetLineWidth((u8) (Linewidth*6.0f), 0); }
|
||||
void SetColor(const GXColor c) { LOCK(this); color = c; }
|
||||
void SetSize(int w, int h) { LOCK(this); width = w; height = h; }
|
||||
void Draw();
|
||||
protected:
|
||||
GXColor color;
|
||||
float Linewidth;
|
||||
public:
|
||||
GuiChecksign() : Linewidth(2.0f) { color = (GXColor) {0, 0, 0, 255}; GX_SetLineWidth((u8) (Linewidth*6.0f), 0); }
|
||||
//! Max line width is 42.5 pixel
|
||||
void SetLinewidth(float w) { LOCK(this); Linewidth = w; GX_SetLineWidth((u8) (Linewidth*6.0f), 0); }
|
||||
void SetColor(const GXColor c) { LOCK(this); color = c; }
|
||||
void SetSize(int w, int h) { LOCK(this); width = w; height = h; }
|
||||
void Draw();
|
||||
protected:
|
||||
GXColor color;
|
||||
float Linewidth;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -24,46 +24,46 @@
|
|||
#include "gui_circle.hpp"
|
||||
|
||||
GuiCircle::GuiCircle()
|
||||
: radius(100.0f), filled(true), accuracy(36)
|
||||
: radius(100.0f), filled(true), accuracy(36)
|
||||
{
|
||||
|
||||
color = (GXColor) {0, 0, 0, 255};
|
||||
SetLinewidth(1.0f);
|
||||
color = (GXColor) {0, 0, 0, 255};
|
||||
SetLinewidth(1.0f);
|
||||
}
|
||||
|
||||
GuiCircle::GuiCircle(float r)
|
||||
: radius(r), filled(true), accuracy(36)
|
||||
: radius(r), filled(true), accuracy(36)
|
||||
{
|
||||
color = (GXColor) {0, 0, 0, 255};
|
||||
SetLinewidth(1.0f);
|
||||
color = (GXColor) {0, 0, 0, 255};
|
||||
SetLinewidth(1.0f);
|
||||
}
|
||||
|
||||
void GuiCircle::SetLinewidth(float s)
|
||||
{
|
||||
LOCK(this);
|
||||
Linewidth = s;
|
||||
GX_SetLineWidth((u8) (s*6.0f), 0);
|
||||
LOCK(this);
|
||||
Linewidth = s;
|
||||
GX_SetLineWidth((u8) (s*6.0f), 0);
|
||||
}
|
||||
|
||||
void GuiCircle::Draw()
|
||||
{
|
||||
GX_SetTevOp(GX_TEVSTAGE0, GX_PASSCLR);
|
||||
GX_SetVtxDesc(GX_VA_POS, GX_DIRECT);
|
||||
GX_SetVtxDesc(GX_VA_CLR0, GX_DIRECT);
|
||||
GX_SetVtxDesc(GX_VA_TEX0, GX_NONE);
|
||||
GX_SetTevOp(GX_TEVSTAGE0, GX_PASSCLR);
|
||||
GX_SetVtxDesc(GX_VA_POS, GX_DIRECT);
|
||||
GX_SetVtxDesc(GX_VA_CLR0, GX_DIRECT);
|
||||
GX_SetVtxDesc(GX_VA_TEX0, GX_NONE);
|
||||
|
||||
int loopAmount = filled ? accuracy : accuracy+1;
|
||||
int loopAmount = filled ? accuracy : accuracy+1;
|
||||
|
||||
GX_Begin(filled ? GX_TRIANGLEFAN : GX_LINESTRIP, GX_VTXFMT0, loopAmount);
|
||||
for(int i = 0; i < loopAmount; ++i)
|
||||
{
|
||||
f32 rad = (f32) i / (f32) accuracy * 360.0f;
|
||||
f32 x = cos(DegToRad(rad)) * radius + GetLeft();
|
||||
f32 y = sin(DegToRad(rad)) * radius + GetTop();
|
||||
GX_Begin(filled ? GX_TRIANGLEFAN : GX_LINESTRIP, GX_VTXFMT0, loopAmount);
|
||||
for(int i = 0; i < loopAmount; ++i)
|
||||
{
|
||||
f32 rad = (f32) i / (f32) accuracy * 360.0f;
|
||||
f32 x = cos(DegToRad(rad)) * radius + GetLeft();
|
||||
f32 y = sin(DegToRad(rad)) * radius + GetTop();
|
||||
|
||||
GX_Position3f32(x, y, 0.0f);
|
||||
GX_Color4u8(color.r, color.g, color.b, color.a);
|
||||
}
|
||||
GX_End();
|
||||
GX_SetTevOp(GX_TEVSTAGE0, GX_MODULATE);
|
||||
GX_Position3f32(x, y, 0.0f);
|
||||
GX_Color4u8(color.r, color.g, color.b, color.a);
|
||||
}
|
||||
GX_End();
|
||||
GX_SetTevOp(GX_TEVSTAGE0, GX_MODULATE);
|
||||
}
|
||||
|
|
|
@ -28,22 +28,22 @@
|
|||
|
||||
class GuiCircle : public GuiElement
|
||||
{
|
||||
public:
|
||||
GuiCircle();
|
||||
GuiCircle(float radius);
|
||||
void SetRadius(float r) { LOCK(this); radius = r; }
|
||||
void SetInnerRadius(float r) { SetLinewidth((radius-r)*2.0f); }
|
||||
void SetColor(const GXColor c) { LOCK(this); color = c; }
|
||||
void SetAccuracy(int a) { LOCK(this); accuracy = a; }
|
||||
void SetFilled(bool f) { LOCK(this); filled = f; }
|
||||
void SetLinewidth(float s);
|
||||
void Draw();
|
||||
protected:
|
||||
GXColor color;
|
||||
float radius;
|
||||
float Linewidth;
|
||||
bool filled;
|
||||
int accuracy;
|
||||
public:
|
||||
GuiCircle();
|
||||
GuiCircle(float radius);
|
||||
void SetRadius(float r) { LOCK(this); radius = r; }
|
||||
void SetInnerRadius(float r) { SetLinewidth((radius-r)*2.0f); }
|
||||
void SetColor(const GXColor c) { LOCK(this); color = c; }
|
||||
void SetAccuracy(int a) { LOCK(this); accuracy = a; }
|
||||
void SetFilled(bool f) { LOCK(this); filled = f; }
|
||||
void SetLinewidth(float s);
|
||||
void Draw();
|
||||
protected:
|
||||
GXColor color;
|
||||
float radius;
|
||||
float Linewidth;
|
||||
bool filled;
|
||||
int accuracy;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -25,27 +25,27 @@
|
|||
|
||||
void GuiCross::Draw()
|
||||
{
|
||||
GX_SetTevOp(GX_TEVSTAGE0, GX_PASSCLR);
|
||||
GX_SetVtxDesc(GX_VA_POS, GX_DIRECT);
|
||||
GX_SetVtxDesc(GX_VA_CLR0, GX_DIRECT);
|
||||
GX_SetVtxDesc(GX_VA_TEX0, GX_NONE);
|
||||
GX_SetTevOp(GX_TEVSTAGE0, GX_PASSCLR);
|
||||
GX_SetVtxDesc(GX_VA_POS, GX_DIRECT);
|
||||
GX_SetVtxDesc(GX_VA_CLR0, GX_DIRECT);
|
||||
GX_SetVtxDesc(GX_VA_TEX0, GX_NONE);
|
||||
|
||||
f32 x1 = GetLeft();
|
||||
f32 x2 = x1 + width;
|
||||
f32 y1 = GetTop();
|
||||
f32 y2 = y1 + height;
|
||||
f32 x1 = GetLeft();
|
||||
f32 x2 = x1 + width;
|
||||
f32 y1 = GetTop();
|
||||
f32 y2 = y1 + height;
|
||||
|
||||
int alpha = GetAlpha();
|
||||
int alpha = GetAlpha();
|
||||
|
||||
GX_Begin(GX_LINES, GX_VTXFMT0, 4);
|
||||
GX_Position3f32(x1, y1, 0.0f);
|
||||
GX_Color4u8(color.r, color.g, color.b, alpha);
|
||||
GX_Position3f32(x2, y2, 0.0f);
|
||||
GX_Color4u8(color.r, color.g, color.b, alpha);
|
||||
GX_Position3f32(x2, y1, 0.0f);
|
||||
GX_Color4u8(color.r, color.g, color.b, alpha);
|
||||
GX_Position3f32(x1, y2, 0.0f);
|
||||
GX_Color4u8(color.r, color.g, color.b, alpha);
|
||||
GX_End();
|
||||
GX_SetTevOp(GX_TEVSTAGE0, GX_MODULATE);
|
||||
GX_Begin(GX_LINES, GX_VTXFMT0, 4);
|
||||
GX_Position3f32(x1, y1, 0.0f);
|
||||
GX_Color4u8(color.r, color.g, color.b, alpha);
|
||||
GX_Position3f32(x2, y2, 0.0f);
|
||||
GX_Color4u8(color.r, color.g, color.b, alpha);
|
||||
GX_Position3f32(x2, y1, 0.0f);
|
||||
GX_Color4u8(color.r, color.g, color.b, alpha);
|
||||
GX_Position3f32(x1, y2, 0.0f);
|
||||
GX_Color4u8(color.r, color.g, color.b, alpha);
|
||||
GX_End();
|
||||
GX_SetTevOp(GX_TEVSTAGE0, GX_MODULATE);
|
||||
}
|
||||
|
|
|
@ -28,16 +28,16 @@
|
|||
|
||||
class GuiCross : public GuiElement
|
||||
{
|
||||
public:
|
||||
GuiCross() : Linewidth(2.0f) { color = (GXColor) {0, 0, 0, 255}; GX_SetLineWidth((u8) (Linewidth*6.0f), 0); }
|
||||
//! Max line width is 42.5 pixel
|
||||
void SetLinewidth(float w) { LOCK(this); Linewidth = w; GX_SetLineWidth((u8) (Linewidth*6.0f), 0); }
|
||||
void SetColor(const GXColor c) { LOCK(this); color = c; }
|
||||
void SetSize(int w, int h) { LOCK(this); width = w; height = h; }
|
||||
void Draw();
|
||||
protected:
|
||||
GXColor color;
|
||||
float Linewidth;
|
||||
public:
|
||||
GuiCross() : Linewidth(2.0f) { color = (GXColor) {0, 0, 0, 255}; GX_SetLineWidth((u8) (Linewidth*6.0f), 0); }
|
||||
//! Max line width is 42.5 pixel
|
||||
void SetLinewidth(float w) { LOCK(this); Linewidth = w; GX_SetLineWidth((u8) (Linewidth*6.0f), 0); }
|
||||
void SetColor(const GXColor c) { LOCK(this); color = c; }
|
||||
void SetSize(int w, int h) { LOCK(this); width = w; height = h; }
|
||||
void Draw();
|
||||
protected:
|
||||
GXColor color;
|
||||
float Linewidth;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -3,26 +3,26 @@
|
|||
|
||||
GuiDiskCover::GuiDiskCover()
|
||||
{
|
||||
PosZ = 50;
|
||||
Distance = 55;
|
||||
OldDegBeta = 0.0;
|
||||
deg_beta = 0.0;
|
||||
eff_step = 0;
|
||||
// spin_angle = 0;
|
||||
spin_speedup = 1.0;
|
||||
spin_up = false;
|
||||
PosZ = 50;
|
||||
Distance = 55;
|
||||
OldDegBeta = 0.0;
|
||||
deg_beta = 0.0;
|
||||
eff_step = 0;
|
||||
// spin_angle = 0;
|
||||
spin_speedup = 1.0;
|
||||
spin_up = false;
|
||||
}
|
||||
GuiDiskCover::GuiDiskCover(GuiImageData *Disk) :
|
||||
GuiImage(Disk)
|
||||
GuiImage(Disk)
|
||||
{
|
||||
PosZ = 50;
|
||||
Distance = 55;
|
||||
OldDegBeta = 0.0;
|
||||
deg_beta = 0.0;
|
||||
eff_step = 0;
|
||||
// spin_angle = 0;
|
||||
spin_speedup = 1.0;
|
||||
spin_up = false;
|
||||
PosZ = 50;
|
||||
Distance = 55;
|
||||
OldDegBeta = 0.0;
|
||||
deg_beta = 0.0;
|
||||
eff_step = 0;
|
||||
// spin_angle = 0;
|
||||
spin_speedup = 1.0;
|
||||
spin_up = false;
|
||||
}
|
||||
GuiDiskCover::~GuiDiskCover()
|
||||
{
|
||||
|
@ -30,74 +30,74 @@ GuiDiskCover::~GuiDiskCover()
|
|||
|
||||
void GuiDiskCover::SetBeta(f32 beta)
|
||||
{
|
||||
deg_beta = beta;
|
||||
deg_beta = beta;
|
||||
}
|
||||
void GuiDiskCover::SetBetaRotateEffect(f32 beta, u16 step)
|
||||
{
|
||||
eff_beta = beta / (f32) step;
|
||||
eff_step = step;
|
||||
eff_beta = beta / (f32) step;
|
||||
eff_step = step;
|
||||
}
|
||||
bool GuiDiskCover::GetBetaRotateEffect()
|
||||
{
|
||||
return eff_step != 0;
|
||||
return eff_step != 0;
|
||||
}
|
||||
|
||||
void GuiDiskCover::SetSpin(bool Up)
|
||||
{
|
||||
spin_up = Up;
|
||||
spin_up = Up;
|
||||
}
|
||||
|
||||
void GuiDiskCover::SetState(int s, int c)
|
||||
{
|
||||
if(state == STATE_DEFAULT && s == STATE_DISABLED)
|
||||
{
|
||||
PosZ = 0;
|
||||
Distance = 0;
|
||||
OldDegBeta = deg_beta;
|
||||
deg_beta = 0.0f;
|
||||
}
|
||||
else if(state == STATE_DISABLED && s == STATE_DEFAULT)
|
||||
{
|
||||
PosZ = 50;
|
||||
Distance = 55;
|
||||
deg_beta = OldDegBeta;
|
||||
}
|
||||
if(state == STATE_DEFAULT && s == STATE_DISABLED)
|
||||
{
|
||||
PosZ = 0;
|
||||
Distance = 0;
|
||||
OldDegBeta = deg_beta;
|
||||
deg_beta = 0.0f;
|
||||
}
|
||||
else if(state == STATE_DISABLED && s == STATE_DEFAULT)
|
||||
{
|
||||
PosZ = 50;
|
||||
Distance = 55;
|
||||
deg_beta = OldDegBeta;
|
||||
}
|
||||
|
||||
GuiImage::SetState(s, c);
|
||||
GuiImage::SetState(s, c);
|
||||
}
|
||||
|
||||
void Menu_DrawDiskCover(f32 xpos, f32 ypos, f32 zpos, u16 width, u16 height, u16 distance, u8 data[], f32 deg_alpha,
|
||||
f32 deg_beta, f32 scaleX, f32 scaleY, u8 alpha, bool shadow);
|
||||
f32 deg_beta, f32 scaleX, f32 scaleY, u8 alpha, bool shadow);
|
||||
|
||||
void GuiDiskCover::Draw()
|
||||
{
|
||||
LOCK( this );
|
||||
if (!image || !this->IsVisible()) return;
|
||||
float currScale = this->GetScale();
|
||||
LOCK( this );
|
||||
if (!image || !this->IsVisible()) return;
|
||||
float currScale = this->GetScale();
|
||||
|
||||
Menu_DrawDiskCover(this->GetLeft(), this->GetTop(), PosZ, width, height, Distance, image, imageangle, deg_beta,
|
||||
widescreen ? currScale * Settings.WSFactor : currScale, currScale, 64, true);
|
||||
Menu_DrawDiskCover(this->GetLeft(), this->GetTop(), PosZ, width, height, Distance, image, imageangle, deg_beta,
|
||||
widescreen ? currScale * Settings.WSFactor : currScale, currScale, this->GetAlpha(), false);
|
||||
Menu_DrawDiskCover(this->GetLeft(), this->GetTop(), PosZ, width, height, Distance, image, imageangle, deg_beta,
|
||||
widescreen ? currScale * Settings.WSFactor : currScale, currScale, 64, true);
|
||||
Menu_DrawDiskCover(this->GetLeft(), this->GetTop(), PosZ, width, height, Distance, image, imageangle, deg_beta,
|
||||
widescreen ? currScale * Settings.WSFactor : currScale, currScale, this->GetAlpha(), false);
|
||||
|
||||
if (eff_step)
|
||||
{
|
||||
deg_beta += eff_beta;
|
||||
eff_step--;
|
||||
}
|
||||
GuiImage::imageangle += spin_speedup;
|
||||
while (GuiImage::imageangle >= 360.0)
|
||||
GuiImage::imageangle -= 360.0;
|
||||
if (eff_step)
|
||||
{
|
||||
deg_beta += eff_beta;
|
||||
eff_step--;
|
||||
}
|
||||
GuiImage::imageangle += spin_speedup;
|
||||
while (GuiImage::imageangle >= 360.0)
|
||||
GuiImage::imageangle -= 360.0;
|
||||
|
||||
if (spin_up)
|
||||
{
|
||||
if (spin_speedup < 11) // speed up
|
||||
spin_speedup += 0.20;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (spin_speedup > 1) spin_speedup -= 0.05; //slow down
|
||||
}
|
||||
if (spin_up)
|
||||
{
|
||||
if (spin_speedup < 11) // speed up
|
||||
spin_speedup += 0.20;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (spin_speedup > 1) spin_speedup -= 0.05; //slow down
|
||||
}
|
||||
|
||||
this->UpdateEffects();
|
||||
this->UpdateEffects();
|
||||
}
|
||||
|
|
|
@ -5,28 +5,28 @@
|
|||
|
||||
class GuiDiskCover: public GuiImage
|
||||
{
|
||||
public:
|
||||
GuiDiskCover();
|
||||
GuiDiskCover(GuiImageData * img);
|
||||
virtual ~GuiDiskCover();
|
||||
void SetBeta(f32 beta);
|
||||
void SetBetaRotateEffect(f32 beta, u16 Step);
|
||||
bool GetBetaRotateEffect();
|
||||
public:
|
||||
GuiDiskCover();
|
||||
GuiDiskCover(GuiImageData * img);
|
||||
virtual ~GuiDiskCover();
|
||||
void SetBeta(f32 beta);
|
||||
void SetBetaRotateEffect(f32 beta, u16 Step);
|
||||
bool GetBetaRotateEffect();
|
||||
|
||||
void SetSpin(bool Up);
|
||||
void SetState(int s, int c = -1);
|
||||
void Draw();
|
||||
private:
|
||||
f32 deg_beta;
|
||||
f32 eff_beta;
|
||||
u16 eff_step;
|
||||
void SetSpin(bool Up);
|
||||
void SetState(int s, int c = -1);
|
||||
void Draw();
|
||||
private:
|
||||
f32 deg_beta;
|
||||
f32 eff_beta;
|
||||
u16 eff_step;
|
||||
|
||||
// f32 spin_angle;
|
||||
f32 spin_speedup;
|
||||
int PosZ;
|
||||
int Distance;
|
||||
f32 OldDegBeta;
|
||||
bool spin_up;
|
||||
// f32 spin_angle;
|
||||
f32 spin_speedup;
|
||||
int PosZ;
|
||||
int Distance;
|
||||
f32 OldDegBeta;
|
||||
bool spin_up;
|
||||
};
|
||||
|
||||
#endif /* _GUIDISCCOVER_H_ */
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -17,56 +17,56 @@
|
|||
* Constructor for the GuiFileBrowser class.
|
||||
*/
|
||||
GuiFileBrowser::GuiFileBrowser(int w, int h)
|
||||
: scrollBar(h-10)
|
||||
: scrollBar(h-10)
|
||||
{
|
||||
width = w;
|
||||
height = h;
|
||||
selectedItem = 0;
|
||||
selectable = true;
|
||||
triggerdisabled = false; // trigger disable
|
||||
focus = 0; // allow focus
|
||||
width = w;
|
||||
height = h;
|
||||
selectedItem = 0;
|
||||
selectable = true;
|
||||
triggerdisabled = false; // trigger disable
|
||||
focus = 0; // allow focus
|
||||
|
||||
trigA = new GuiTrigger;
|
||||
trigA->SetSimpleTrigger(-1, WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A, PAD_BUTTON_A);
|
||||
trigA = new GuiTrigger;
|
||||
trigA->SetSimpleTrigger(-1, WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A, PAD_BUTTON_A);
|
||||
|
||||
bgFileSelection = new GuiImageData(Resources::GetFile("bg_browser.png"), Resources::GetFileSize("bg_browser.png"));
|
||||
bgFileSelectionImg = new GuiImage(bgFileSelection);
|
||||
bgFileSelectionImg->SetParent(this);
|
||||
bgFileSelectionImg->SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE);
|
||||
bgFileSelection = new GuiImageData(Resources::GetFile("bg_browser.png"), Resources::GetFileSize("bg_browser.png"));
|
||||
bgFileSelectionImg = new GuiImage(bgFileSelection);
|
||||
bgFileSelectionImg->SetParent(this);
|
||||
bgFileSelectionImg->SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE);
|
||||
|
||||
bgFileSelectionEntry = Resources::GetImageData("bg_browser_selection.png");
|
||||
bgFileSelectionEntry = Resources::GetImageData("bg_browser_selection.png");
|
||||
|
||||
fileFolder = Resources::GetImageData("icon_folder.png");
|
||||
fileFolder = Resources::GetImageData("icon_folder.png");
|
||||
|
||||
scrollBar.SetParent(this);
|
||||
scrollBar.SetAlignment(ALIGN_RIGHT, ALIGN_TOP);
|
||||
scrollBar.SetPosition(0, 5);
|
||||
scrollBar.listChanged.connect(this, &GuiFileBrowser::onListChange);
|
||||
scrollBar.SetParent(this);
|
||||
scrollBar.SetAlignment(ALIGN_RIGHT, ALIGN_TOP);
|
||||
scrollBar.SetPosition(0, 5);
|
||||
scrollBar.listChanged.connect(this, &GuiFileBrowser::onListChange);
|
||||
|
||||
for (int i = 0; i < FILEBROWSERSIZE; i++)
|
||||
{
|
||||
fileListText[i] = new GuiText((char *) NULL, 20, ( GXColor ) {0, 0, 0, 0xff});
|
||||
fileListText[i]->SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE);
|
||||
fileListText[i]->SetPosition(5, 0);
|
||||
fileListText[i]->SetMaxWidth(bgFileSelectionImg->GetWidth() - (scrollBar.GetWidth() + 40), DOTTED);
|
||||
for (int i = 0; i < FILEBROWSERSIZE; i++)
|
||||
{
|
||||
fileListText[i] = new GuiText((char *) NULL, 20, ( GXColor ) {0, 0, 0, 0xff});
|
||||
fileListText[i]->SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE);
|
||||
fileListText[i]->SetPosition(5, 0);
|
||||
fileListText[i]->SetMaxWidth(bgFileSelectionImg->GetWidth() - (scrollBar.GetWidth() + 40), DOTTED);
|
||||
|
||||
fileListTextOver[i] = new GuiText((char *) NULL, 20, ( GXColor ) {0, 0, 0, 0xff});
|
||||
fileListTextOver[i]->SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE);
|
||||
fileListTextOver[i]->SetPosition(5, 0);
|
||||
fileListTextOver[i]->SetMaxWidth(bgFileSelectionImg->GetWidth() - (scrollBar.GetWidth() + 40), SCROLL_HORIZONTAL);
|
||||
fileListTextOver[i] = new GuiText((char *) NULL, 20, ( GXColor ) {0, 0, 0, 0xff});
|
||||
fileListTextOver[i]->SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE);
|
||||
fileListTextOver[i]->SetPosition(5, 0);
|
||||
fileListTextOver[i]->SetMaxWidth(bgFileSelectionImg->GetWidth() - (scrollBar.GetWidth() + 40), SCROLL_HORIZONTAL);
|
||||
|
||||
fileListBg[i] = new GuiImage(bgFileSelectionEntry);
|
||||
fileListFolder[i] = new GuiImage(fileFolder);
|
||||
fileList[i] = new GuiButton(350, 30);
|
||||
fileList[i]->SetParent(this);
|
||||
fileList[i]->SetLabel(fileListText[i]);
|
||||
fileList[i]->SetLabelOver(fileListTextOver[i]);
|
||||
fileList[i]->SetImageOver(fileListBg[i]);
|
||||
fileList[i]->SetPosition(2, 30 * i + 3);
|
||||
fileList[i]->SetTrigger(trigA);
|
||||
fileList[i]->SetRumble(false);
|
||||
fileList[i]->SetSoundClick(btnSoundClick);
|
||||
}
|
||||
fileListBg[i] = new GuiImage(bgFileSelectionEntry);
|
||||
fileListFolder[i] = new GuiImage(fileFolder);
|
||||
fileList[i] = new GuiButton(350, 30);
|
||||
fileList[i]->SetParent(this);
|
||||
fileList[i]->SetLabel(fileListText[i]);
|
||||
fileList[i]->SetLabelOver(fileListTextOver[i]);
|
||||
fileList[i]->SetImageOver(fileListBg[i]);
|
||||
fileList[i]->SetPosition(2, 30 * i + 3);
|
||||
fileList[i]->SetTrigger(trigA);
|
||||
fileList[i]->SetRumble(false);
|
||||
fileList[i]->SetSoundClick(btnSoundClick);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -74,64 +74,64 @@ GuiFileBrowser::GuiFileBrowser(int w, int h)
|
|||
*/
|
||||
GuiFileBrowser::~GuiFileBrowser()
|
||||
{
|
||||
delete bgFileSelectionImg;
|
||||
delete bgFileSelectionImg;
|
||||
|
||||
delete bgFileSelection;
|
||||
delete bgFileSelectionEntry;
|
||||
delete fileFolder;
|
||||
delete bgFileSelection;
|
||||
delete bgFileSelectionEntry;
|
||||
delete fileFolder;
|
||||
|
||||
delete trigA;
|
||||
delete trigA;
|
||||
|
||||
for (int i = 0; i < FILEBROWSERSIZE; i++)
|
||||
{
|
||||
delete fileListText[i];
|
||||
delete fileListTextOver[i];
|
||||
delete fileList[i];
|
||||
delete fileListBg[i];
|
||||
delete fileListFolder[i];
|
||||
}
|
||||
for (int i = 0; i < FILEBROWSERSIZE; i++)
|
||||
{
|
||||
delete fileListText[i];
|
||||
delete fileListTextOver[i];
|
||||
delete fileList[i];
|
||||
delete fileListBg[i];
|
||||
delete fileListFolder[i];
|
||||
}
|
||||
}
|
||||
|
||||
void GuiFileBrowser::SetFocus(int f)
|
||||
{
|
||||
LOCK( this );
|
||||
focus = f;
|
||||
LOCK( this );
|
||||
focus = f;
|
||||
|
||||
for (int i = 0; i < FILEBROWSERSIZE; i++)
|
||||
fileList[i]->ResetState();
|
||||
for (int i = 0; i < FILEBROWSERSIZE; i++)
|
||||
fileList[i]->ResetState();
|
||||
|
||||
if (f == 1)
|
||||
fileList[selectedItem]->SetState(STATE_SELECTED);
|
||||
if (f == 1)
|
||||
fileList[selectedItem]->SetState(STATE_SELECTED);
|
||||
}
|
||||
|
||||
void GuiFileBrowser::DisableTriggerUpdate(bool set)
|
||||
{
|
||||
LOCK( this );
|
||||
triggerdisabled = set;
|
||||
LOCK( this );
|
||||
triggerdisabled = set;
|
||||
}
|
||||
|
||||
void GuiFileBrowser::ResetState()
|
||||
{
|
||||
LOCK( this );
|
||||
state = STATE_DEFAULT;
|
||||
stateChan = -1;
|
||||
selectedItem = 0;
|
||||
LOCK( this );
|
||||
state = STATE_DEFAULT;
|
||||
stateChan = -1;
|
||||
selectedItem = 0;
|
||||
|
||||
for (int i = 0; i < FILEBROWSERSIZE; i++)
|
||||
{
|
||||
fileList[i]->ResetState();
|
||||
}
|
||||
for (int i = 0; i < FILEBROWSERSIZE; i++)
|
||||
{
|
||||
fileList[i]->ResetState();
|
||||
}
|
||||
}
|
||||
|
||||
void GuiFileBrowser::UpdateList()
|
||||
{
|
||||
LOCK( this );
|
||||
LOCK( this );
|
||||
for (int i = 0; i < FILEBROWSERSIZE; i++)
|
||||
{
|
||||
if (browser->pageIndex + i < (int) browser->browserList.size())
|
||||
{
|
||||
if (fileList[i]->GetState() == STATE_DISABLED)
|
||||
fileList[i]->SetState(STATE_DEFAULT);
|
||||
fileList[i]->SetState(STATE_DEFAULT);
|
||||
|
||||
fileList[i]->SetVisible(true);
|
||||
|
||||
|
@ -161,9 +161,9 @@ void GuiFileBrowser::UpdateList()
|
|||
|
||||
void GuiFileBrowser::onListChange(int SelItem, int SelInd)
|
||||
{
|
||||
selectedItem = SelItem;
|
||||
browser->pageIndex = SelInd;
|
||||
UpdateList();
|
||||
selectedItem = SelItem;
|
||||
browser->pageIndex = SelInd;
|
||||
UpdateList();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -171,60 +171,60 @@ void GuiFileBrowser::onListChange(int SelItem, int SelInd)
|
|||
*/
|
||||
void GuiFileBrowser::Draw()
|
||||
{
|
||||
LOCK( this );
|
||||
if (!this->IsVisible()) return;
|
||||
LOCK( this );
|
||||
if (!this->IsVisible()) return;
|
||||
|
||||
bgFileSelectionImg->Draw();
|
||||
bgFileSelectionImg->Draw();
|
||||
|
||||
for (int i = 0; i < FILEBROWSERSIZE; i++)
|
||||
{
|
||||
fileList[i]->Draw();
|
||||
}
|
||||
for (int i = 0; i < FILEBROWSERSIZE; i++)
|
||||
{
|
||||
fileList[i]->Draw();
|
||||
}
|
||||
|
||||
if(browser->browserList.size() > FILEBROWSERSIZE)
|
||||
scrollBar.Draw();
|
||||
if(browser->browserList.size() > FILEBROWSERSIZE)
|
||||
scrollBar.Draw();
|
||||
|
||||
this->UpdateEffects();
|
||||
this->UpdateEffects();
|
||||
}
|
||||
|
||||
void GuiFileBrowser::Update(GuiTrigger * t)
|
||||
{
|
||||
LOCK( this );
|
||||
if (state == STATE_DISABLED || !t || triggerdisabled)
|
||||
return;
|
||||
LOCK( this );
|
||||
if (state == STATE_DISABLED || !t || triggerdisabled)
|
||||
return;
|
||||
|
||||
static int pressedChan = -1;
|
||||
static int pressedChan = -1;
|
||||
|
||||
if((t->wpad.btns_d & (WPAD_BUTTON_B | WPAD_BUTTON_DOWN | WPAD_BUTTON_UP | WPAD_BUTTON_LEFT | WPAD_BUTTON_RIGHT |
|
||||
WPAD_CLASSIC_BUTTON_B | WPAD_CLASSIC_BUTTON_UP | WPAD_CLASSIC_BUTTON_DOWN | WPAD_CLASSIC_BUTTON_LEFT | WPAD_CLASSIC_BUTTON_RIGHT)) ||
|
||||
(t->pad.btns_d & (PAD_BUTTON_UP | PAD_BUTTON_DOWN)))
|
||||
pressedChan = t->chan;
|
||||
if((t->wpad.btns_d & (WPAD_BUTTON_B | WPAD_BUTTON_DOWN | WPAD_BUTTON_UP | WPAD_BUTTON_LEFT | WPAD_BUTTON_RIGHT |
|
||||
WPAD_CLASSIC_BUTTON_B | WPAD_CLASSIC_BUTTON_UP | WPAD_CLASSIC_BUTTON_DOWN | WPAD_CLASSIC_BUTTON_LEFT | WPAD_CLASSIC_BUTTON_RIGHT)) ||
|
||||
(t->pad.btns_d & (PAD_BUTTON_UP | PAD_BUTTON_DOWN)))
|
||||
pressedChan = t->chan;
|
||||
|
||||
if(browser->browserList.size() > FILEBROWSERSIZE)
|
||||
scrollBar.Update(t);
|
||||
if(browser->browserList.size() > FILEBROWSERSIZE)
|
||||
scrollBar.Update(t);
|
||||
|
||||
if(pressedChan == -1 || (!t->wpad.btns_h && !t->pad.btns_h))
|
||||
{
|
||||
for (int i = 0; i < FILEBROWSERSIZE; i++)
|
||||
{
|
||||
if (i != selectedItem && fileList[i]->GetState() == STATE_SELECTED)
|
||||
fileList[i]->ResetState();
|
||||
else if (i == selectedItem && fileList[i]->GetState() == STATE_DEFAULT)
|
||||
fileList[selectedItem]->SetState(STATE_SELECTED, -1);
|
||||
if(pressedChan == -1 || (!t->wpad.btns_h && !t->pad.btns_h))
|
||||
{
|
||||
for (int i = 0; i < FILEBROWSERSIZE; i++)
|
||||
{
|
||||
if (i != selectedItem && fileList[i]->GetState() == STATE_SELECTED)
|
||||
fileList[i]->ResetState();
|
||||
else if (i == selectedItem && fileList[i]->GetState() == STATE_DEFAULT)
|
||||
fileList[selectedItem]->SetState(STATE_SELECTED, -1);
|
||||
|
||||
fileList[i]->Update(t);
|
||||
fileList[i]->Update(t);
|
||||
|
||||
if (fileList[i]->GetState() == STATE_SELECTED)
|
||||
selectedItem = i;
|
||||
}
|
||||
}
|
||||
if (fileList[i]->GetState() == STATE_SELECTED)
|
||||
selectedItem = i;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(pressedChan == t->chan && !t->wpad.btns_d && !t->wpad.btns_h)
|
||||
pressedChan = -1;
|
||||
if(pressedChan == t->chan && !t->wpad.btns_d && !t->wpad.btns_h)
|
||||
pressedChan = -1;
|
||||
|
||||
scrollBar.SetPageSize(FILEBROWSERSIZE);
|
||||
scrollBar.SetSelectedItem(selectedItem);
|
||||
scrollBar.SetSelectedIndex(browser->pageIndex);
|
||||
scrollBar.SetEntrieCount(browser->browserList.size());
|
||||
scrollBar.SetPageSize(FILEBROWSERSIZE);
|
||||
scrollBar.SetSelectedItem(selectedItem);
|
||||
scrollBar.SetSelectedIndex(browser->pageIndex);
|
||||
scrollBar.SetEntrieCount(browser->browserList.size());
|
||||
}
|
||||
|
|
|
@ -7,34 +7,34 @@
|
|||
//!Display a list of files
|
||||
class GuiFileBrowser: public GuiElement, public sigslot::has_slots<>
|
||||
{
|
||||
public:
|
||||
GuiFileBrowser(int w, int h);
|
||||
virtual ~GuiFileBrowser();
|
||||
void DisableTriggerUpdate(bool set);
|
||||
void ResetState();
|
||||
void SetFocus(int f);
|
||||
void Draw();
|
||||
void UpdateList();
|
||||
void Update(GuiTrigger * t);
|
||||
GuiButton * fileList[PAGESIZE];
|
||||
protected:
|
||||
void onListChange(int SelItem, int SelInd);
|
||||
int selectedItem;
|
||||
bool triggerdisabled;
|
||||
public:
|
||||
GuiFileBrowser(int w, int h);
|
||||
virtual ~GuiFileBrowser();
|
||||
void DisableTriggerUpdate(bool set);
|
||||
void ResetState();
|
||||
void SetFocus(int f);
|
||||
void Draw();
|
||||
void UpdateList();
|
||||
void Update(GuiTrigger * t);
|
||||
GuiButton * fileList[PAGESIZE];
|
||||
protected:
|
||||
void onListChange(int SelItem, int SelInd);
|
||||
int selectedItem;
|
||||
bool triggerdisabled;
|
||||
|
||||
GuiText * fileListText[PAGESIZE];
|
||||
GuiText * fileListTextOver[PAGESIZE];
|
||||
GuiImage * fileListBg[PAGESIZE];
|
||||
GuiImage * fileListFolder[PAGESIZE];
|
||||
GuiText * fileListText[PAGESIZE];
|
||||
GuiText * fileListTextOver[PAGESIZE];
|
||||
GuiImage * fileListBg[PAGESIZE];
|
||||
GuiImage * fileListFolder[PAGESIZE];
|
||||
|
||||
GuiImage * bgFileSelectionImg;
|
||||
GuiImage * bgFileSelectionImg;
|
||||
|
||||
GuiImageData * bgFileSelection;
|
||||
GuiImageData * bgFileSelectionEntry;
|
||||
GuiImageData * fileFolder;
|
||||
GuiImageData * bgFileSelection;
|
||||
GuiImageData * bgFileSelectionEntry;
|
||||
GuiImageData * fileFolder;
|
||||
|
||||
GuiTrigger * trigA;
|
||||
GuiScrollbar scrollBar;
|
||||
GuiTrigger * trigA;
|
||||
GuiScrollbar scrollBar;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -25,93 +25,93 @@
|
|||
#include <math.h>
|
||||
#include <sstream>
|
||||
|
||||
#define SCALE 0.8f
|
||||
#define SCALE 0.8f
|
||||
#define DEG_OFFSET 7
|
||||
#define RADIUS 780
|
||||
#define IN_SPEED 175
|
||||
#define RADIUS 780
|
||||
#define IN_SPEED 175
|
||||
#define SHIFT_SPEED 75
|
||||
#define SPEED_STEP 4
|
||||
#define SPEED_LIMIT 250
|
||||
|
||||
static inline int OFFSETLIMIT(int Offset, int gameCnt)
|
||||
{
|
||||
while (Offset < 0)
|
||||
Offset += gameCnt;
|
||||
return Offset % gameCnt;
|
||||
while (Offset < 0)
|
||||
Offset += gameCnt;
|
||||
return Offset % gameCnt;
|
||||
}
|
||||
#define GetGameIndex(pageEntry, listOffset, gameCnt) OFFSETLIMIT(listOffset+pageEntry, gameCnt)
|
||||
static GuiImageData *GameCarouselLoadCoverImage(void * Arg)
|
||||
{
|
||||
return LoadCoverImage((struct discHdr *) Arg, true, false);
|
||||
return LoadCoverImage((struct discHdr *) Arg, true, false);
|
||||
}
|
||||
/**
|
||||
* Constructor for the GuiGameCarousel class.
|
||||
*/
|
||||
GuiGameCarousel::GuiGameCarousel(int w, int h, const char *themePath, int offset) :
|
||||
noCover(Resources::GetFile("nocover.png"), Resources::GetFileSize("nocover.png"))
|
||||
noCover(Resources::GetFile("nocover.png"), Resources::GetFileSize("nocover.png"))
|
||||
{
|
||||
width = w;
|
||||
height = h;
|
||||
pagesize = (gameList.size() < 11) ? gameList.size() : 11;
|
||||
listOffset = (gameList.size() < 11) ? LIMIT(offset, 0, MAX(0, gameList.size()-1)) : LIMIT(offset, 0, MAX(0, gameList.size()-1))-2;
|
||||
selectable = true;
|
||||
selectedItem = -1;
|
||||
focus = 1; // allow focus
|
||||
clickedItem = -1;
|
||||
width = w;
|
||||
height = h;
|
||||
pagesize = (gameList.size() < 11) ? gameList.size() : 11;
|
||||
listOffset = (gameList.size() < 11) ? LIMIT(offset, 0, MAX(0, gameList.size()-1)) : LIMIT(offset, 0, MAX(0, gameList.size()-1))-2;
|
||||
selectable = true;
|
||||
selectedItem = -1;
|
||||
focus = 1; // allow focus
|
||||
clickedItem = -1;
|
||||
|
||||
speed = 0;
|
||||
speed = 0;
|
||||
|
||||
trigA = new GuiTrigger;
|
||||
trigA->SetSimpleTrigger(-1, WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A, PAD_BUTTON_A);
|
||||
trigL = new GuiTrigger;
|
||||
trigL->SetButtonOnlyTrigger(-1, WPAD_BUTTON_LEFT | WPAD_CLASSIC_BUTTON_LEFT, PAD_BUTTON_LEFT);
|
||||
trigR = new GuiTrigger;
|
||||
trigR->SetButtonOnlyTrigger(-1, WPAD_BUTTON_RIGHT | WPAD_CLASSIC_BUTTON_RIGHT, PAD_BUTTON_RIGHT);
|
||||
trigPlus = new GuiTrigger;
|
||||
trigPlus->SetButtonOnlyTrigger(-1, WPAD_BUTTON_PLUS | WPAD_CLASSIC_BUTTON_PLUS, 0);
|
||||
trigMinus = new GuiTrigger;
|
||||
trigMinus->SetButtonOnlyTrigger(-1, WPAD_BUTTON_MINUS | WPAD_CLASSIC_BUTTON_MINUS, 0);
|
||||
trigA = new GuiTrigger;
|
||||
trigA->SetSimpleTrigger(-1, WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A, PAD_BUTTON_A);
|
||||
trigL = new GuiTrigger;
|
||||
trigL->SetButtonOnlyTrigger(-1, WPAD_BUTTON_LEFT | WPAD_CLASSIC_BUTTON_LEFT, PAD_BUTTON_LEFT);
|
||||
trigR = new GuiTrigger;
|
||||
trigR->SetButtonOnlyTrigger(-1, WPAD_BUTTON_RIGHT | WPAD_CLASSIC_BUTTON_RIGHT, PAD_BUTTON_RIGHT);
|
||||
trigPlus = new GuiTrigger;
|
||||
trigPlus->SetButtonOnlyTrigger(-1, WPAD_BUTTON_PLUS | WPAD_CLASSIC_BUTTON_PLUS, 0);
|
||||
trigMinus = new GuiTrigger;
|
||||
trigMinus->SetButtonOnlyTrigger(-1, WPAD_BUTTON_MINUS | WPAD_CLASSIC_BUTTON_MINUS, 0);
|
||||
|
||||
imgLeft = Resources::GetImageData("startgame_arrow_left.png");
|
||||
imgRight = Resources::GetImageData("startgame_arrow_right.png");
|
||||
imgLeft = Resources::GetImageData("startgame_arrow_left.png");
|
||||
imgRight = Resources::GetImageData("startgame_arrow_right.png");
|
||||
|
||||
btnLeftImg = new GuiImage(imgLeft);
|
||||
if (Settings.wsprompt == ON) btnLeftImg->SetWidescreen(Settings.widescreen);
|
||||
btnLeft = new GuiButton(imgLeft->GetWidth(), imgLeft->GetHeight());
|
||||
btnLeft->SetAlignment(thAlign("left - carousel layout left arrow align hor"), thAlign("top - carousel layout left arrow align ver"));
|
||||
btnLeft->SetPosition(thInt("20 - carousel layout left arrow pos x"), thInt("65 - carousel layout left arrow pos y"));
|
||||
btnLeft->SetParent(this);
|
||||
btnLeft->SetImage(btnLeftImg);
|
||||
btnLeft->SetSoundOver(btnSoundOver);
|
||||
btnLeft->SetTrigger(trigA);
|
||||
btnLeft->SetTrigger(trigL);
|
||||
btnLeft->SetTrigger(trigMinus);
|
||||
btnLeft->SetEffectGrow();
|
||||
btnLeftImg = new GuiImage(imgLeft);
|
||||
if (Settings.wsprompt == ON) btnLeftImg->SetWidescreen(Settings.widescreen);
|
||||
btnLeft = new GuiButton(imgLeft->GetWidth(), imgLeft->GetHeight());
|
||||
btnLeft->SetAlignment(thAlign("left - carousel layout left arrow align hor"), thAlign("top - carousel layout left arrow align ver"));
|
||||
btnLeft->SetPosition(thInt("20 - carousel layout left arrow pos x"), thInt("65 - carousel layout left arrow pos y"));
|
||||
btnLeft->SetParent(this);
|
||||
btnLeft->SetImage(btnLeftImg);
|
||||
btnLeft->SetSoundOver(btnSoundOver);
|
||||
btnLeft->SetTrigger(trigA);
|
||||
btnLeft->SetTrigger(trigL);
|
||||
btnLeft->SetTrigger(trigMinus);
|
||||
btnLeft->SetEffectGrow();
|
||||
|
||||
btnRightImg = new GuiImage(imgRight);
|
||||
if (Settings.wsprompt == ON) btnRightImg->SetWidescreen(Settings.widescreen);
|
||||
btnRight = new GuiButton(imgRight->GetWidth(), imgRight->GetHeight());
|
||||
btnRight->SetParent(this);
|
||||
btnRight->SetAlignment(thAlign("right - carousel layout right arrow align hor"), thAlign("top - carousel layout right arrow align ver"));
|
||||
btnRight->SetPosition(thInt("-20 - carousel layout right arrow pos x"), thInt("65 - carousel layout right arrow pos y"));
|
||||
btnRight->SetImage(btnRightImg);
|
||||
btnRight->SetSoundOver(btnSoundOver);
|
||||
btnRight->SetTrigger(trigA);
|
||||
btnRight->SetTrigger(trigR);
|
||||
btnRight->SetTrigger(trigPlus);
|
||||
btnRight->SetEffectGrow();
|
||||
btnRightImg = new GuiImage(imgRight);
|
||||
if (Settings.wsprompt == ON) btnRightImg->SetWidescreen(Settings.widescreen);
|
||||
btnRight = new GuiButton(imgRight->GetWidth(), imgRight->GetHeight());
|
||||
btnRight->SetParent(this);
|
||||
btnRight->SetAlignment(thAlign("right - carousel layout right arrow align hor"), thAlign("top - carousel layout right arrow align ver"));
|
||||
btnRight->SetPosition(thInt("-20 - carousel layout right arrow pos x"), thInt("65 - carousel layout right arrow pos y"));
|
||||
btnRight->SetImage(btnRightImg);
|
||||
btnRight->SetSoundOver(btnSoundOver);
|
||||
btnRight->SetTrigger(trigA);
|
||||
btnRight->SetTrigger(trigR);
|
||||
btnRight->SetTrigger(trigPlus);
|
||||
btnRight->SetEffectGrow();
|
||||
|
||||
gamename = new GuiText(" ", 18, thColor("r=55 g=190 b=237 a=255 - carousel game name text color"));
|
||||
gamename->SetParent(this);
|
||||
gamename->SetAlignment(ALIGN_CENTRE, ALIGN_TOP);
|
||||
gamename->SetPosition(0, 330);
|
||||
gamename->SetMaxWidth(280, DOTTED);
|
||||
gamename = new GuiText(" ", 18, thColor("r=55 g=190 b=237 a=255 - carousel game name text color"));
|
||||
gamename->SetParent(this);
|
||||
gamename->SetAlignment(ALIGN_CENTRE, ALIGN_TOP);
|
||||
gamename->SetPosition(0, 330);
|
||||
gamename->SetMaxWidth(280, DOTTED);
|
||||
|
||||
gameIndex = new int[pagesize];
|
||||
game.resize(pagesize);
|
||||
coverImg.resize(pagesize);
|
||||
gameIndex = new int[pagesize];
|
||||
game.resize(pagesize);
|
||||
coverImg.resize(pagesize);
|
||||
|
||||
Refresh();
|
||||
Refresh();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -119,34 +119,34 @@ GuiGameCarousel::GuiGameCarousel(int w, int h, const char *themePath, int offset
|
|||
*/
|
||||
GuiGameCarousel::~GuiGameCarousel()
|
||||
{
|
||||
delete imgRight;
|
||||
delete imgLeft;
|
||||
delete btnLeftImg;
|
||||
delete btnRightImg;
|
||||
delete btnRight;
|
||||
delete btnLeft;
|
||||
delete imgRight;
|
||||
delete imgLeft;
|
||||
delete btnLeftImg;
|
||||
delete btnRightImg;
|
||||
delete btnRight;
|
||||
delete btnLeft;
|
||||
|
||||
delete trigA;
|
||||
delete trigL;
|
||||
delete trigR;
|
||||
delete trigPlus;
|
||||
delete trigMinus;
|
||||
delete gamename;
|
||||
delete trigA;
|
||||
delete trigL;
|
||||
delete trigR;
|
||||
delete trigPlus;
|
||||
delete trigMinus;
|
||||
delete gamename;
|
||||
|
||||
GuiImageAsync::ClearQueue();
|
||||
GuiImageAsync::ClearQueue();
|
||||
|
||||
for (u32 i = 0; i < game.size(); ++i)
|
||||
delete coverImg[i];
|
||||
for (u32 i = 0; i < game.size(); ++i)
|
||||
delete game[i];
|
||||
for (u32 i = 0; i < game.size(); ++i)
|
||||
delete coverImg[i];
|
||||
for (u32 i = 0; i < game.size(); ++i)
|
||||
delete game[i];
|
||||
|
||||
delete[] gameIndex;
|
||||
delete[] gameIndex;
|
||||
|
||||
}
|
||||
|
||||
void GuiGameCarousel::setListOffset(int off)
|
||||
{
|
||||
LOCK( this );
|
||||
LOCK( this );
|
||||
if(gameList.size() < 11)
|
||||
listOffset = MIN(off, gameList.size()-1);
|
||||
else
|
||||
|
@ -171,96 +171,96 @@ void GuiGameCarousel::SetSelectedOption(int ind)
|
|||
|
||||
void GuiGameCarousel::Refresh()
|
||||
{
|
||||
for (int i = 0; i < pagesize; i++)
|
||||
{
|
||||
//------------------------
|
||||
// Index
|
||||
//------------------------
|
||||
gameIndex[i] = GetGameIndex( i, listOffset, gameList.size() );
|
||||
for (int i = 0; i < pagesize; i++)
|
||||
{
|
||||
//------------------------
|
||||
// Index
|
||||
//------------------------
|
||||
gameIndex[i] = GetGameIndex( i, listOffset, gameList.size() );
|
||||
|
||||
//------------------------
|
||||
// Image
|
||||
//------------------------
|
||||
delete coverImg[i];
|
||||
coverImg[i] = new (std::nothrow) GuiImageAsync(GameCarouselLoadCoverImage, gameList[gameIndex[i]], sizeof(struct discHdr), &noCover);
|
||||
if (coverImg[i]) coverImg[i]->SetWidescreen(Settings.widescreen);
|
||||
//------------------------
|
||||
// Image
|
||||
//------------------------
|
||||
delete coverImg[i];
|
||||
coverImg[i] = new (std::nothrow) GuiImageAsync(GameCarouselLoadCoverImage, gameList[gameIndex[i]], sizeof(struct discHdr), &noCover);
|
||||
if (coverImg[i]) coverImg[i]->SetWidescreen(Settings.widescreen);
|
||||
|
||||
//------------------------
|
||||
// GameButton
|
||||
//------------------------
|
||||
delete game[i];
|
||||
game[i] = new GuiButton(122, 244);
|
||||
game[i]->SetParent(this);
|
||||
game[i]->SetAlignment(ALIGN_CENTRE, ALIGN_MIDDLE);
|
||||
game[i]->SetPosition(0, 740);
|
||||
game[i]->SetImage(coverImg[i]);
|
||||
game[i]->SetScale(SCALE);
|
||||
game[i]->SetRumble(false);
|
||||
game[i]->SetTrigger(trigA);
|
||||
game[i]->SetSoundClick(btnSoundClick);
|
||||
game[i]->SetClickable(true);
|
||||
game[i]->SetEffect(EFFECT_GOROUND, IN_SPEED, 90 - (pagesize - 2 * i - 1) * DEG_OFFSET / 2, RADIUS, 180, 1, 0, RADIUS);
|
||||
}
|
||||
//------------------------
|
||||
// GameButton
|
||||
//------------------------
|
||||
delete game[i];
|
||||
game[i] = new GuiButton(122, 244);
|
||||
game[i]->SetParent(this);
|
||||
game[i]->SetAlignment(ALIGN_CENTRE, ALIGN_MIDDLE);
|
||||
game[i]->SetPosition(0, 740);
|
||||
game[i]->SetImage(coverImg[i]);
|
||||
game[i]->SetScale(SCALE);
|
||||
game[i]->SetRumble(false);
|
||||
game[i]->SetTrigger(trigA);
|
||||
game[i]->SetSoundClick(btnSoundClick);
|
||||
game[i]->SetClickable(true);
|
||||
game[i]->SetEffect(EFFECT_GOROUND, IN_SPEED, 90 - (pagesize - 2 * i - 1) * DEG_OFFSET / 2, RADIUS, 180, 1, 0, RADIUS);
|
||||
}
|
||||
}
|
||||
|
||||
void GuiGameCarousel::SetFocus(int f)
|
||||
{
|
||||
LOCK( this );
|
||||
if (!gameList.size()) return;
|
||||
LOCK( this );
|
||||
if (!gameList.size()) return;
|
||||
|
||||
focus = f;
|
||||
focus = f;
|
||||
|
||||
for (int i = 0; i < pagesize; i++)
|
||||
game[i]->ResetState();
|
||||
for (int i = 0; i < pagesize; i++)
|
||||
game[i]->ResetState();
|
||||
|
||||
if (f == 1 && selectedItem >= 0) game[selectedItem]->SetState(STATE_SELECTED);
|
||||
if (f == 1 && selectedItem >= 0) game[selectedItem]->SetState(STATE_SELECTED);
|
||||
}
|
||||
|
||||
void GuiGameCarousel::ResetState()
|
||||
{
|
||||
LOCK( this );
|
||||
if (state != STATE_DISABLED)
|
||||
{
|
||||
state = STATE_DEFAULT;
|
||||
stateChan = -1;
|
||||
}
|
||||
LOCK( this );
|
||||
if (state != STATE_DISABLED)
|
||||
{
|
||||
state = STATE_DEFAULT;
|
||||
stateChan = -1;
|
||||
}
|
||||
|
||||
for (int i = 0; i < pagesize; i++)
|
||||
{
|
||||
game[i]->ResetState();
|
||||
}
|
||||
for (int i = 0; i < pagesize; i++)
|
||||
{
|
||||
game[i]->ResetState();
|
||||
}
|
||||
}
|
||||
|
||||
int GuiGameCarousel::GetClickedOption()
|
||||
{
|
||||
LOCK( this );
|
||||
int found = -1;
|
||||
if (clickedItem >= 0)
|
||||
{
|
||||
for (int i = pagesize - 1; i >= 0; i--)
|
||||
game[i]->ResetState();
|
||||
LOCK( this );
|
||||
int found = -1;
|
||||
if (clickedItem >= 0)
|
||||
{
|
||||
for (int i = pagesize - 1; i >= 0; i--)
|
||||
game[i]->ResetState();
|
||||
|
||||
game[clickedItem]->SetState(STATE_SELECTED);
|
||||
found = gameIndex[clickedItem];
|
||||
clickedItem = -1;
|
||||
}
|
||||
return found;
|
||||
game[clickedItem]->SetState(STATE_SELECTED);
|
||||
found = gameIndex[clickedItem];
|
||||
clickedItem = -1;
|
||||
}
|
||||
return found;
|
||||
}
|
||||
|
||||
int GuiGameCarousel::GetSelectedOption()
|
||||
{
|
||||
LOCK( this );
|
||||
int found = -1;
|
||||
for (int i = 0; i < pagesize; i++)
|
||||
{
|
||||
if (game[i]->GetState() == STATE_SELECTED)
|
||||
{
|
||||
game[i]->SetState(STATE_SELECTED);
|
||||
found = gameIndex[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
return found;
|
||||
LOCK( this );
|
||||
int found = -1;
|
||||
for (int i = 0; i < pagesize; i++)
|
||||
{
|
||||
if (game[i]->GetState() == STATE_SELECTED)
|
||||
{
|
||||
game[i]->SetState(STATE_SELECTED);
|
||||
found = gameIndex[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
return found;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -268,194 +268,194 @@ int GuiGameCarousel::GetSelectedOption()
|
|||
*/
|
||||
void GuiGameCarousel::Draw()
|
||||
{
|
||||
LOCK( this );
|
||||
if (!this->IsVisible() || !gameList.size()) return;
|
||||
LOCK( this );
|
||||
if (!this->IsVisible() || !gameList.size()) return;
|
||||
|
||||
for (int i = 0; i < pagesize; i++)
|
||||
game[i]->Draw();
|
||||
for (int i = 0; i < pagesize; i++)
|
||||
game[i]->Draw();
|
||||
|
||||
gamename->Draw();
|
||||
gamename->Draw();
|
||||
|
||||
if (gameList.size() > 6)
|
||||
{
|
||||
btnRight->Draw();
|
||||
btnLeft->Draw();
|
||||
}
|
||||
if (gameList.size() > 6)
|
||||
{
|
||||
btnRight->Draw();
|
||||
btnLeft->Draw();
|
||||
}
|
||||
|
||||
//!Draw tooltip after the Images to have it on top
|
||||
if (focus && Settings.tooltips == ON) for (int i = 0; i < pagesize; i++)
|
||||
game[i]->DrawTooltip();
|
||||
//!Draw tooltip after the Images to have it on top
|
||||
if (focus && Settings.tooltips == ON) for (int i = 0; i < pagesize; i++)
|
||||
game[i]->DrawTooltip();
|
||||
|
||||
this->UpdateEffects();
|
||||
this->UpdateEffects();
|
||||
}
|
||||
|
||||
void GuiGameCarousel::Update(GuiTrigger * t)
|
||||
{
|
||||
LOCK( this );
|
||||
if (state == STATE_DISABLED || !t || !gameList.size() || !pagesize) return;
|
||||
LOCK( this );
|
||||
if (state == STATE_DISABLED || !t || !gameList.size() || !pagesize) return;
|
||||
|
||||
btnRight->Update(t);
|
||||
btnLeft->Update(t);
|
||||
btnRight->Update(t);
|
||||
btnLeft->Update(t);
|
||||
|
||||
if ((game[0]->GetEffect() & EFFECT_GOROUND) || (game[pagesize - 1]->GetEffect() & EFFECT_GOROUND))
|
||||
{
|
||||
return; // skip when rotate
|
||||
}
|
||||
if ((game[0]->GetEffect() & EFFECT_GOROUND) || (game[pagesize - 1]->GetEffect() & EFFECT_GOROUND))
|
||||
{
|
||||
return; // skip when rotate
|
||||
}
|
||||
|
||||
// find selected + clicked
|
||||
int selectedItem_old = selectedItem;
|
||||
selectedItem = -1;
|
||||
clickedItem = -1;
|
||||
for (int i = pagesize - 1; i >= 0; i--)
|
||||
{
|
||||
game[i]->Update(t);
|
||||
if (game[i]->GetState() == STATE_SELECTED)
|
||||
{
|
||||
selectedItem = i;
|
||||
}
|
||||
if (game[i]->GetState() == STATE_CLICKED)
|
||||
{
|
||||
clickedItem = i;
|
||||
}
|
||||
// find selected + clicked
|
||||
int selectedItem_old = selectedItem;
|
||||
selectedItem = -1;
|
||||
clickedItem = -1;
|
||||
for (int i = pagesize - 1; i >= 0; i--)
|
||||
{
|
||||
game[i]->Update(t);
|
||||
if (game[i]->GetState() == STATE_SELECTED)
|
||||
{
|
||||
selectedItem = i;
|
||||
}
|
||||
if (game[i]->GetState() == STATE_CLICKED)
|
||||
{
|
||||
clickedItem = i;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/// OnOver-Effect + GameText + Tooltop
|
||||
if (selectedItem_old != selectedItem)
|
||||
{
|
||||
if (selectedItem >= 0)
|
||||
{
|
||||
game[selectedItem]->SetEffect(EFFECT_SCALE, 1, 130);
|
||||
gamename->SetText(GameTitles.GetTitle(gameList[gameIndex[selectedItem]]));
|
||||
}
|
||||
else gamename->SetText((char*) NULL);
|
||||
if (selectedItem_old >= 0) game[selectedItem_old]->SetEffect(EFFECT_SCALE, -1, 100);
|
||||
}
|
||||
// navigation
|
||||
if (focus && gameList.size() > 6)
|
||||
{
|
||||
/// OnOver-Effect + GameText + Tooltop
|
||||
if (selectedItem_old != selectedItem)
|
||||
{
|
||||
if (selectedItem >= 0)
|
||||
{
|
||||
game[selectedItem]->SetEffect(EFFECT_SCALE, 1, 130);
|
||||
gamename->SetText(GameTitles.GetTitle(gameList[gameIndex[selectedItem]]));
|
||||
}
|
||||
else gamename->SetText((char*) NULL);
|
||||
if (selectedItem_old >= 0) game[selectedItem_old]->SetEffect(EFFECT_SCALE, -1, 100);
|
||||
}
|
||||
// navigation
|
||||
if (focus && gameList.size() > 6)
|
||||
{
|
||||
|
||||
int newspeed = 0;
|
||||
// Left/Right Navigation
|
||||
if (btnLeft->GetState() == STATE_CLICKED)
|
||||
{
|
||||
WPAD_ScanPads();
|
||||
u16 buttons = 0;
|
||||
for (int i = 0; i < 4; i++)
|
||||
buttons |= WPAD_ButtonsHeld(i);
|
||||
if (!((buttons & WPAD_BUTTON_A) || (buttons & WPAD_BUTTON_MINUS) || t->Left()))
|
||||
{
|
||||
btnLeft->ResetState();
|
||||
return;
|
||||
}
|
||||
int newspeed = 0;
|
||||
// Left/Right Navigation
|
||||
if (btnLeft->GetState() == STATE_CLICKED)
|
||||
{
|
||||
WPAD_ScanPads();
|
||||
u16 buttons = 0;
|
||||
for (int i = 0; i < 4; i++)
|
||||
buttons |= WPAD_ButtonsHeld(i);
|
||||
if (!((buttons & WPAD_BUTTON_A) || (buttons & WPAD_BUTTON_MINUS) || t->Left()))
|
||||
{
|
||||
btnLeft->ResetState();
|
||||
return;
|
||||
}
|
||||
|
||||
if (Settings.xflip == XFLIP_SYSMENU || Settings.xflip == XFLIP_YES || Settings.xflip == XFLIP_DISK3D)
|
||||
newspeed = SHIFT_SPEED;
|
||||
else newspeed = -SHIFT_SPEED;
|
||||
}
|
||||
else if (btnRight->GetState() == STATE_CLICKED)
|
||||
{
|
||||
WPAD_ScanPads();
|
||||
u16 buttons = 0;
|
||||
for (int i = 0; i < 4; i++)
|
||||
buttons |= WPAD_ButtonsHeld(i);
|
||||
if (!((buttons & WPAD_BUTTON_A) || (buttons & WPAD_BUTTON_PLUS) || t->Right()))
|
||||
{
|
||||
btnRight->ResetState();
|
||||
return;
|
||||
}
|
||||
if (Settings.xflip == XFLIP_SYSMENU || Settings.xflip == XFLIP_YES || Settings.xflip == XFLIP_DISK3D)
|
||||
newspeed = -SHIFT_SPEED;
|
||||
else newspeed = SHIFT_SPEED;
|
||||
}
|
||||
if (newspeed)
|
||||
{
|
||||
if (speed == 0)
|
||||
speed = newspeed;
|
||||
else if (speed > 0)
|
||||
{
|
||||
if ((speed += SPEED_STEP) > SPEED_LIMIT) speed = SPEED_LIMIT;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((speed -= SPEED_STEP) < -SPEED_LIMIT) speed = -SPEED_LIMIT;
|
||||
}
|
||||
}
|
||||
else speed = 0;
|
||||
if (Settings.xflip == XFLIP_SYSMENU || Settings.xflip == XFLIP_YES || Settings.xflip == XFLIP_DISK3D)
|
||||
newspeed = SHIFT_SPEED;
|
||||
else newspeed = -SHIFT_SPEED;
|
||||
}
|
||||
else if (btnRight->GetState() == STATE_CLICKED)
|
||||
{
|
||||
WPAD_ScanPads();
|
||||
u16 buttons = 0;
|
||||
for (int i = 0; i < 4; i++)
|
||||
buttons |= WPAD_ButtonsHeld(i);
|
||||
if (!((buttons & WPAD_BUTTON_A) || (buttons & WPAD_BUTTON_PLUS) || t->Right()))
|
||||
{
|
||||
btnRight->ResetState();
|
||||
return;
|
||||
}
|
||||
if (Settings.xflip == XFLIP_SYSMENU || Settings.xflip == XFLIP_YES || Settings.xflip == XFLIP_DISK3D)
|
||||
newspeed = -SHIFT_SPEED;
|
||||
else newspeed = SHIFT_SPEED;
|
||||
}
|
||||
if (newspeed)
|
||||
{
|
||||
if (speed == 0)
|
||||
speed = newspeed;
|
||||
else if (speed > 0)
|
||||
{
|
||||
if ((speed += SPEED_STEP) > SPEED_LIMIT) speed = SPEED_LIMIT;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((speed -= SPEED_STEP) < -SPEED_LIMIT) speed = -SPEED_LIMIT;
|
||||
}
|
||||
}
|
||||
else speed = 0;
|
||||
|
||||
if (speed > 0) // rotate right
|
||||
{
|
||||
GuiButton *tmpButton;
|
||||
listOffset = OFFSETLIMIT(listOffset - 1, gameList.size()); // set the new listOffset
|
||||
// Save right Button + TollTip and destroy right Image + Image-Data
|
||||
delete coverImg[pagesize - 1];
|
||||
coverImg[pagesize - 1] = NULL;
|
||||
game[pagesize - 1]->SetImage(NULL);
|
||||
tmpButton = game[pagesize - 1];
|
||||
if (speed > 0) // rotate right
|
||||
{
|
||||
GuiButton *tmpButton;
|
||||
listOffset = OFFSETLIMIT(listOffset - 1, gameList.size()); // set the new listOffset
|
||||
// Save right Button + TollTip and destroy right Image + Image-Data
|
||||
delete coverImg[pagesize - 1];
|
||||
coverImg[pagesize - 1] = NULL;
|
||||
game[pagesize - 1]->SetImage(NULL);
|
||||
tmpButton = game[pagesize - 1];
|
||||
|
||||
// Move all Page-Entries one step right
|
||||
for (int i = pagesize - 1; i >= 1; i--)
|
||||
{
|
||||
coverImg[i] = coverImg[i - 1];
|
||||
game[i] = game[i - 1];
|
||||
gameIndex[i] = gameIndex[i - 1];
|
||||
}
|
||||
// set saved Button & gameIndex to right
|
||||
gameIndex[0] = listOffset;
|
||||
coverImg[0] = new GuiImageAsync(GameCarouselLoadCoverImage, gameList[gameIndex[0]], sizeof(struct discHdr),
|
||||
&noCover);
|
||||
coverImg[0] ->SetWidescreen(Settings.widescreen);
|
||||
// Move all Page-Entries one step right
|
||||
for (int i = pagesize - 1; i >= 1; i--)
|
||||
{
|
||||
coverImg[i] = coverImg[i - 1];
|
||||
game[i] = game[i - 1];
|
||||
gameIndex[i] = gameIndex[i - 1];
|
||||
}
|
||||
// set saved Button & gameIndex to right
|
||||
gameIndex[0] = listOffset;
|
||||
coverImg[0] = new GuiImageAsync(GameCarouselLoadCoverImage, gameList[gameIndex[0]], sizeof(struct discHdr),
|
||||
&noCover);
|
||||
coverImg[0] ->SetWidescreen(Settings.widescreen);
|
||||
|
||||
game[0] = tmpButton;
|
||||
game[0] ->SetImage(coverImg[0]);
|
||||
game[0] = tmpButton;
|
||||
game[0] ->SetImage(coverImg[0]);
|
||||
|
||||
for (int i = 0; i < pagesize; i++)
|
||||
{
|
||||
game[i]->StopEffect();
|
||||
game[i]->ResetState();
|
||||
game[i]->SetEffect(EFFECT_GOROUND, speed, DEG_OFFSET, RADIUS, 270 - (pagesize - 2 * i + 1) * DEG_OFFSET
|
||||
/ 2, 1, 0, RADIUS);
|
||||
game[i]->UpdateEffects(); // rotate one step for liquid scrolling
|
||||
}
|
||||
}
|
||||
else if (speed < 0) // rotate left
|
||||
{
|
||||
GuiButton *tmpButton;
|
||||
listOffset = OFFSETLIMIT(listOffset + 1, gameList.size()); // set the new listOffset
|
||||
// Save left Button + TollTip and destroy left Image + Image-Data
|
||||
delete coverImg[0];
|
||||
coverImg[0] = NULL;
|
||||
game[0]->SetImage(NULL);
|
||||
tmpButton = game[0];
|
||||
for (int i = 0; i < pagesize; i++)
|
||||
{
|
||||
game[i]->StopEffect();
|
||||
game[i]->ResetState();
|
||||
game[i]->SetEffect(EFFECT_GOROUND, speed, DEG_OFFSET, RADIUS, 270 - (pagesize - 2 * i + 1) * DEG_OFFSET
|
||||
/ 2, 1, 0, RADIUS);
|
||||
game[i]->UpdateEffects(); // rotate one step for liquid scrolling
|
||||
}
|
||||
}
|
||||
else if (speed < 0) // rotate left
|
||||
{
|
||||
GuiButton *tmpButton;
|
||||
listOffset = OFFSETLIMIT(listOffset + 1, gameList.size()); // set the new listOffset
|
||||
// Save left Button + TollTip and destroy left Image + Image-Data
|
||||
delete coverImg[0];
|
||||
coverImg[0] = NULL;
|
||||
game[0]->SetImage(NULL);
|
||||
tmpButton = game[0];
|
||||
|
||||
// Move all Page-Entries one step left
|
||||
for (int i = 0; i < (pagesize - 1); i++)
|
||||
{
|
||||
coverImg[i] = coverImg[i + 1];
|
||||
game[i] = game[i + 1];
|
||||
gameIndex[i] = gameIndex[i + 1];
|
||||
}
|
||||
// set saved Button & gameIndex to right
|
||||
int ii = pagesize - 1;
|
||||
gameIndex[ii] = OFFSETLIMIT(listOffset + ii, gameList.size());
|
||||
coverImg[ii] = new GuiImageAsync(GameCarouselLoadCoverImage, gameList[gameIndex[ii]],
|
||||
sizeof(struct discHdr), &noCover);
|
||||
coverImg[ii] ->SetWidescreen(Settings.widescreen);
|
||||
// Move all Page-Entries one step left
|
||||
for (int i = 0; i < (pagesize - 1); i++)
|
||||
{
|
||||
coverImg[i] = coverImg[i + 1];
|
||||
game[i] = game[i + 1];
|
||||
gameIndex[i] = gameIndex[i + 1];
|
||||
}
|
||||
// set saved Button & gameIndex to right
|
||||
int ii = pagesize - 1;
|
||||
gameIndex[ii] = OFFSETLIMIT(listOffset + ii, gameList.size());
|
||||
coverImg[ii] = new GuiImageAsync(GameCarouselLoadCoverImage, gameList[gameIndex[ii]],
|
||||
sizeof(struct discHdr), &noCover);
|
||||
coverImg[ii] ->SetWidescreen(Settings.widescreen);
|
||||
|
||||
game[ii] = tmpButton;
|
||||
game[ii] ->SetImage(coverImg[ii]);
|
||||
game[ii] = tmpButton;
|
||||
game[ii] ->SetImage(coverImg[ii]);
|
||||
|
||||
for (int i = 0; i < pagesize; i++)
|
||||
{
|
||||
game[i]->StopEffect();
|
||||
game[i]->ResetState();
|
||||
game[i]->SetEffect(EFFECT_GOROUND, speed, DEG_OFFSET, RADIUS, 270 - (pagesize - 2 * i - 3) * DEG_OFFSET
|
||||
/ 2, 1, 0, RADIUS);
|
||||
game[i]->UpdateEffects(); // rotate one step for liquid scrolling
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < pagesize; i++)
|
||||
{
|
||||
game[i]->StopEffect();
|
||||
game[i]->ResetState();
|
||||
game[i]->SetEffect(EFFECT_GOROUND, speed, DEG_OFFSET, RADIUS, 270 - (pagesize - 2 * i - 3) * DEG_OFFSET
|
||||
/ 2, 1, 0, RADIUS);
|
||||
game[i]->UpdateEffects(); // rotate one step for liquid scrolling
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
if (updateCB) updateCB(this);
|
||||
}
|
||||
if (updateCB) updateCB(this);
|
||||
}
|
||||
|
||||
|
|
|
@ -8,48 +8,48 @@
|
|||
|
||||
class GuiGameCarousel : public GuiGameBrowser
|
||||
{
|
||||
public:
|
||||
GuiGameCarousel(int w, int h, const char *themePath, int listOffset = 0);
|
||||
virtual ~GuiGameCarousel();
|
||||
int FindMenuItem(int c, int d);
|
||||
int GetClickedOption();
|
||||
int GetSelectedOption();
|
||||
void SetSelectedOption(int ind);
|
||||
void setListOffset(int off);
|
||||
int getListOffset() const;
|
||||
void Refresh();
|
||||
void ResetState();
|
||||
void SetFocus(int f);
|
||||
void Draw();
|
||||
void Update(GuiTrigger * t);
|
||||
protected:
|
||||
GuiImageData noCover;
|
||||
int selectedItem;
|
||||
int listOffset;
|
||||
int scrollbaron;
|
||||
int pagesize;
|
||||
int speed;
|
||||
int clickedItem;
|
||||
public:
|
||||
GuiGameCarousel(int w, int h, const char *themePath, int listOffset = 0);
|
||||
virtual ~GuiGameCarousel();
|
||||
int FindMenuItem(int c, int d);
|
||||
int GetClickedOption();
|
||||
int GetSelectedOption();
|
||||
void SetSelectedOption(int ind);
|
||||
void setListOffset(int off);
|
||||
int getListOffset() const;
|
||||
void Refresh();
|
||||
void ResetState();
|
||||
void SetFocus(int f);
|
||||
void Draw();
|
||||
void Update(GuiTrigger * t);
|
||||
protected:
|
||||
GuiImageData noCover;
|
||||
int selectedItem;
|
||||
int listOffset;
|
||||
int scrollbaron;
|
||||
int pagesize;
|
||||
int speed;
|
||||
int clickedItem;
|
||||
|
||||
int * gameIndex;
|
||||
std::vector<GuiButton *> game;
|
||||
std::vector<GuiImageAsync *> coverImg;
|
||||
int * gameIndex;
|
||||
std::vector<GuiButton *> game;
|
||||
std::vector<GuiImageAsync *> coverImg;
|
||||
|
||||
GuiText * gamename;
|
||||
GuiText * gamename;
|
||||
|
||||
GuiButton * btnRight;
|
||||
GuiButton * btnLeft;
|
||||
GuiButton * btnRight;
|
||||
GuiButton * btnLeft;
|
||||
|
||||
GuiImage * btnLeftImg;
|
||||
GuiImage * btnRightImg;
|
||||
GuiImage * btnLeftImg;
|
||||
GuiImage * btnRightImg;
|
||||
|
||||
GuiImageData * imgLeft;
|
||||
GuiImageData * imgRight;
|
||||
GuiImageData * imgLeft;
|
||||
GuiImageData * imgRight;
|
||||
|
||||
GuiTrigger * trigA;
|
||||
GuiTrigger * trigL;
|
||||
GuiTrigger * trigR;
|
||||
GuiTrigger * trigPlus;
|
||||
GuiTrigger * trigMinus;
|
||||
GuiTrigger * trigA;
|
||||
GuiTrigger * trigL;
|
||||
GuiTrigger * trigR;
|
||||
GuiTrigger * trigPlus;
|
||||
GuiTrigger * trigMinus;
|
||||
};
|
||||
#endif
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -8,55 +8,55 @@
|
|||
|
||||
class GuiGameGrid : public GuiGameBrowser
|
||||
{
|
||||
public:
|
||||
GuiGameGrid(int w, int h, const char *themePath, int selectedGame = 0);
|
||||
virtual ~GuiGameGrid();
|
||||
int FindMenuItem(int c, int d);
|
||||
int GetClickedOption();
|
||||
int GetSelectedOption();
|
||||
void SetSelectedOption(int ind);
|
||||
public:
|
||||
GuiGameGrid(int w, int h, const char *themePath, int selectedGame = 0);
|
||||
virtual ~GuiGameGrid();
|
||||
int FindMenuItem(int c, int d);
|
||||
int GetClickedOption();
|
||||
int GetSelectedOption();
|
||||
void SetSelectedOption(int ind);
|
||||
void setListOffset(int off) { listOffset = off; Reload(rows, listOffset); }
|
||||
int getListOffset() const { return listOffset; }
|
||||
void ResetState();
|
||||
void SetFocus(int f);
|
||||
void Draw();
|
||||
void Update(GuiTrigger * t);
|
||||
void Reload(int Rows, int ListOffset);
|
||||
void ChangeRows(int n);
|
||||
protected:
|
||||
GuiImageData noCover;
|
||||
int selectedItem;
|
||||
int listOffset;
|
||||
int pagesize;
|
||||
int clickedItem;
|
||||
int rows;
|
||||
int goLeft;
|
||||
int goRight;
|
||||
int theme_posX;
|
||||
int theme_posY;
|
||||
void ResetState();
|
||||
void SetFocus(int f);
|
||||
void Draw();
|
||||
void Update(GuiTrigger * t);
|
||||
void Reload(int Rows, int ListOffset);
|
||||
void ChangeRows(int n);
|
||||
protected:
|
||||
GuiImageData noCover;
|
||||
int selectedItem;
|
||||
int listOffset;
|
||||
int pagesize;
|
||||
int clickedItem;
|
||||
int rows;
|
||||
int goLeft;
|
||||
int goRight;
|
||||
int theme_posX;
|
||||
int theme_posY;
|
||||
|
||||
std::vector<int> gameIndex;
|
||||
std::vector<GuiButton *> game;
|
||||
std::vector<GuiTooltip *> titleTT;
|
||||
std::vector<GuiImageAsync *> coverImg;
|
||||
std::vector<int> gameIndex;
|
||||
std::vector<GuiButton *> game;
|
||||
std::vector<GuiTooltip *> titleTT;
|
||||
std::vector<GuiImageAsync *> coverImg;
|
||||
|
||||
GuiButton * btnRight;
|
||||
GuiButton * btnLeft;
|
||||
GuiButton * btnRowUp;
|
||||
GuiButton * btnRowDown;
|
||||
GuiButton * btnRight;
|
||||
GuiButton * btnLeft;
|
||||
GuiButton * btnRowUp;
|
||||
GuiButton * btnRowDown;
|
||||
|
||||
GuiImage * btnLeftImg;
|
||||
GuiImage * btnRightImg;
|
||||
GuiImage * btnLeftImg;
|
||||
GuiImage * btnRightImg;
|
||||
|
||||
GuiImageData * imgLeft;
|
||||
GuiImageData * imgRight;
|
||||
GuiImageData * imgLeft;
|
||||
GuiImageData * imgRight;
|
||||
|
||||
GuiTrigger * trigA;
|
||||
GuiTrigger * trigL;
|
||||
GuiTrigger * trigR;
|
||||
GuiTrigger * trigPlus;
|
||||
GuiTrigger * trigMinus;
|
||||
GuiTrigger * trig1;
|
||||
GuiTrigger * trig2;
|
||||
GuiTrigger * trigA;
|
||||
GuiTrigger * trigL;
|
||||
GuiTrigger * trigR;
|
||||
GuiTrigger * trigPlus;
|
||||
GuiTrigger * trigMinus;
|
||||
GuiTrigger * trig1;
|
||||
GuiTrigger * trig2;
|
||||
};
|
||||
#endif
|
||||
|
|
|
@ -23,85 +23,85 @@
|
|||
#include <string.h>
|
||||
#include <sstream>
|
||||
|
||||
#define GAMESELECTSIZE 30
|
||||
#define GAMESELECTSIZE 30
|
||||
|
||||
/**
|
||||
* Constructor for the GuiGameList class.
|
||||
*/
|
||||
GuiGameList::GuiGameList(int w, int h, int offset)
|
||||
: scrollBar(h-10)
|
||||
: scrollBar(h-10)
|
||||
{
|
||||
width = w;
|
||||
height = h;
|
||||
pagesize = thInt("9 - game list browser page size");
|
||||
scrollbaron = (gameList.size() > pagesize) ? 1 : 0;
|
||||
selectable = true;
|
||||
listOffset = LIMIT(offset, 0, MAX(0, gameList.size()-pagesize));
|
||||
selectedItem = 0;
|
||||
focus = 1; // allow focus
|
||||
width = w;
|
||||
height = h;
|
||||
pagesize = thInt("9 - game list browser page size");
|
||||
scrollbaron = (gameList.size() > pagesize) ? 1 : 0;
|
||||
selectable = true;
|
||||
listOffset = LIMIT(offset, 0, MAX(0, gameList.size()-pagesize));
|
||||
selectedItem = 0;
|
||||
focus = 1; // allow focus
|
||||
|
||||
trigA = new GuiTrigger;
|
||||
trigA->SetSimpleTrigger(-1, WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A, PAD_BUTTON_A);
|
||||
trigA = new GuiTrigger;
|
||||
trigA->SetSimpleTrigger(-1, WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A, PAD_BUTTON_A);
|
||||
|
||||
bgGames = Resources::GetImageData("bg_options.png");
|
||||
newGames = Resources::GetImageData("new.png");
|
||||
bgGames = Resources::GetImageData("bg_options.png");
|
||||
newGames = Resources::GetImageData("new.png");
|
||||
|
||||
scrollBar.SetParent(this);
|
||||
scrollBar.SetAlignment(thAlign("right - game browser scrollbar align hor"), thAlign("top - game browser scrollbar align ver"));
|
||||
scrollBar.SetPosition(thInt("0 - game browser scrollbar pos x"), thInt("5 - game browser scrollbar pos y"));
|
||||
scrollBar.SetButtonScroll(WPAD_BUTTON_B | WPAD_CLASSIC_BUTTON_B);
|
||||
scrollBar.SetPageSize(pagesize);
|
||||
scrollBar.SetSelectedItem(selectedItem);
|
||||
scrollBar.SetSelectedIndex(listOffset);
|
||||
scrollBar.SetEntrieCount(gameList.size());
|
||||
scrollBar.listChanged.connect(this, &GuiGameList::onListChange);
|
||||
scrollBar.SetParent(this);
|
||||
scrollBar.SetAlignment(thAlign("right - game browser scrollbar align hor"), thAlign("top - game browser scrollbar align ver"));
|
||||
scrollBar.SetPosition(thInt("0 - game browser scrollbar pos x"), thInt("5 - game browser scrollbar pos y"));
|
||||
scrollBar.SetButtonScroll(WPAD_BUTTON_B | WPAD_CLASSIC_BUTTON_B);
|
||||
scrollBar.SetPageSize(pagesize);
|
||||
scrollBar.SetSelectedItem(selectedItem);
|
||||
scrollBar.SetSelectedIndex(listOffset);
|
||||
scrollBar.SetEntrieCount(gameList.size());
|
||||
scrollBar.listChanged.connect(this, &GuiGameList::onListChange);
|
||||
|
||||
bgGameImg = new GuiImage(bgGames);
|
||||
bgGameImg->SetParent(this);
|
||||
bgGameImg->SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE);
|
||||
bgGameImg = new GuiImage(bgGames);
|
||||
bgGameImg->SetParent(this);
|
||||
bgGameImg->SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE);
|
||||
|
||||
bgGamesEntry = Resources::GetImageData("bg_options_entry.png");
|
||||
bgGamesEntry = Resources::GetImageData("bg_options_entry.png");
|
||||
|
||||
maxTextWidth = bgGameImg->GetWidth() - scrollBar.GetWidth() - 38;
|
||||
maxTextWidth = bgGameImg->GetWidth() - scrollBar.GetWidth() - 38;
|
||||
|
||||
game = new GuiButton *[pagesize];
|
||||
gameTxt = new GuiText *[pagesize];
|
||||
gameTxtOver = new GuiText *[pagesize];
|
||||
gameBg = new GuiImage *[pagesize];
|
||||
newImg = new GuiImage *[pagesize];
|
||||
game = new GuiButton *[pagesize];
|
||||
gameTxt = new GuiText *[pagesize];
|
||||
gameTxtOver = new GuiText *[pagesize];
|
||||
gameBg = new GuiImage *[pagesize];
|
||||
newImg = new GuiImage *[pagesize];
|
||||
|
||||
for (int i = 0; i < pagesize; ++i)
|
||||
{
|
||||
gameTxt[i] = new GuiText((char *) NULL, 20, thColor("r=0 g=0 b=0 a=255 - game browser list text color"));
|
||||
gameTxt[i]->SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE);
|
||||
gameTxt[i]->SetPosition(24, 0);
|
||||
gameTxt[i]->SetMaxWidth(maxTextWidth, DOTTED);
|
||||
for (int i = 0; i < pagesize; ++i)
|
||||
{
|
||||
gameTxt[i] = new GuiText((char *) NULL, 20, thColor("r=0 g=0 b=0 a=255 - game browser list text color"));
|
||||
gameTxt[i]->SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE);
|
||||
gameTxt[i]->SetPosition(24, 0);
|
||||
gameTxt[i]->SetMaxWidth(maxTextWidth, DOTTED);
|
||||
|
||||
gameTxtOver[i] = new GuiText((char *) NULL, 20, thColor("r=0 g=0 b=0 a=255 - game browser list text color over"));
|
||||
gameTxtOver[i]->SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE);
|
||||
gameTxtOver[i]->SetPosition(24, 0);
|
||||
gameTxtOver[i]->SetMaxWidth(maxTextWidth, SCROLL_HORIZONTAL);
|
||||
gameTxtOver[i] = new GuiText((char *) NULL, 20, thColor("r=0 g=0 b=0 a=255 - game browser list text color over"));
|
||||
gameTxtOver[i]->SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE);
|
||||
gameTxtOver[i]->SetPosition(24, 0);
|
||||
gameTxtOver[i]->SetMaxWidth(maxTextWidth, SCROLL_HORIZONTAL);
|
||||
|
||||
gameBg[i] = new GuiImage(bgGamesEntry);
|
||||
gameBg[i] = new GuiImage(bgGamesEntry);
|
||||
|
||||
newImg[i] = new GuiImage(newGames);
|
||||
newImg[i]->SetAlignment(ALIGN_RIGHT, ALIGN_MIDDLE);
|
||||
newImg[i]->SetVisible(false);
|
||||
newImg[i] = new GuiImage(newGames);
|
||||
newImg[i]->SetAlignment(ALIGN_RIGHT, ALIGN_MIDDLE);
|
||||
newImg[i]->SetVisible(false);
|
||||
|
||||
game[i] = new GuiButton(width - scrollBar.GetWidth(), GAMESELECTSIZE);
|
||||
game[i]->SetParent(this);
|
||||
game[i]->SetLabel(gameTxt[i]);
|
||||
game[i]->SetLabelOver(gameTxtOver[i]);
|
||||
game[i]->SetIcon(newImg[i]);
|
||||
game[i]->SetImageOver(gameBg[i]);
|
||||
game[i]->SetPosition(5, GAMESELECTSIZE * i + 4);
|
||||
game[i]->SetRumble(false);
|
||||
game[i]->SetTrigger(trigA);
|
||||
game[i]->SetSoundClick(btnSoundClick);
|
||||
game[i]->SetVisible(false);
|
||||
game[i]->SetState(STATE_DISABLED);
|
||||
}
|
||||
UpdateListEntries();
|
||||
game[i] = new GuiButton(width - scrollBar.GetWidth(), GAMESELECTSIZE);
|
||||
game[i]->SetParent(this);
|
||||
game[i]->SetLabel(gameTxt[i]);
|
||||
game[i]->SetLabelOver(gameTxtOver[i]);
|
||||
game[i]->SetIcon(newImg[i]);
|
||||
game[i]->SetImageOver(gameBg[i]);
|
||||
game[i]->SetPosition(5, GAMESELECTSIZE * i + 4);
|
||||
game[i]->SetRumble(false);
|
||||
game[i]->SetTrigger(trigA);
|
||||
game[i]->SetSoundClick(btnSoundClick);
|
||||
game[i]->SetVisible(false);
|
||||
game[i]->SetState(STATE_DISABLED);
|
||||
}
|
||||
UpdateListEntries();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -109,75 +109,75 @@ GuiGameList::GuiGameList(int w, int h, int offset)
|
|||
*/
|
||||
GuiGameList::~GuiGameList()
|
||||
{
|
||||
delete bgGameImg;
|
||||
delete bgGames;
|
||||
delete bgGamesEntry;
|
||||
delete newGames;
|
||||
delete bgGameImg;
|
||||
delete bgGames;
|
||||
delete bgGamesEntry;
|
||||
delete newGames;
|
||||
|
||||
delete trigA;
|
||||
delete trigA;
|
||||
|
||||
for (int i = 0; i < pagesize; ++i)
|
||||
{
|
||||
delete gameTxt[i];
|
||||
delete gameTxtOver[i];
|
||||
delete gameBg[i];
|
||||
delete game[i];
|
||||
delete newImg[i];
|
||||
}
|
||||
delete[] game;
|
||||
delete[] gameTxt;
|
||||
delete[] gameTxtOver;
|
||||
delete[] gameBg;
|
||||
for (int i = 0; i < pagesize; ++i)
|
||||
{
|
||||
delete gameTxt[i];
|
||||
delete gameTxtOver[i];
|
||||
delete gameBg[i];
|
||||
delete game[i];
|
||||
delete newImg[i];
|
||||
}
|
||||
delete[] game;
|
||||
delete[] gameTxt;
|
||||
delete[] gameTxtOver;
|
||||
delete[] gameBg;
|
||||
}
|
||||
|
||||
void GuiGameList::SetFocus(int f)
|
||||
{
|
||||
LOCK( this );
|
||||
if (!gameList.size()) return;
|
||||
LOCK( this );
|
||||
if (!gameList.size()) return;
|
||||
|
||||
focus = f;
|
||||
focus = f;
|
||||
|
||||
for (int i = 0; i < pagesize; ++i)
|
||||
game[i]->ResetState();
|
||||
for (int i = 0; i < pagesize; ++i)
|
||||
game[i]->ResetState();
|
||||
|
||||
if (f == 1) game[selectedItem]->SetState(STATE_SELECTED);
|
||||
if (f == 1) game[selectedItem]->SetState(STATE_SELECTED);
|
||||
}
|
||||
|
||||
void GuiGameList::ResetState()
|
||||
{
|
||||
LOCK( this );
|
||||
if (state != STATE_DISABLED)
|
||||
{
|
||||
state = STATE_DEFAULT;
|
||||
stateChan = -1;
|
||||
}
|
||||
LOCK( this );
|
||||
if (state != STATE_DISABLED)
|
||||
{
|
||||
state = STATE_DEFAULT;
|
||||
stateChan = -1;
|
||||
}
|
||||
|
||||
for (int i = 0; i < pagesize; ++i)
|
||||
{
|
||||
game[i]->ResetState();
|
||||
}
|
||||
for (int i = 0; i < pagesize; ++i)
|
||||
{
|
||||
game[i]->ResetState();
|
||||
}
|
||||
}
|
||||
|
||||
int GuiGameList::GetClickedOption()
|
||||
{
|
||||
int found = -1;
|
||||
for (int i = 0; i < pagesize; ++i)
|
||||
{
|
||||
if (game[i]->GetState() == STATE_CLICKED)
|
||||
{
|
||||
game[i]->SetState(STATE_SELECTED);
|
||||
found = listOffset + i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return found;
|
||||
int found = -1;
|
||||
for (int i = 0; i < pagesize; ++i)
|
||||
{
|
||||
if (game[i]->GetState() == STATE_CLICKED)
|
||||
{
|
||||
game[i]->SetState(STATE_SELECTED);
|
||||
found = listOffset + i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return found;
|
||||
}
|
||||
|
||||
void GuiGameList::onListChange(int SelItem, int SelInd)
|
||||
{
|
||||
selectedItem = SelItem;
|
||||
listOffset = SelInd;
|
||||
UpdateListEntries();
|
||||
selectedItem = SelItem;
|
||||
listOffset = SelInd;
|
||||
UpdateListEntries();
|
||||
}
|
||||
|
||||
void GuiGameList::setListOffset(int off)
|
||||
|
@ -197,85 +197,85 @@ void GuiGameList::SetSelectedOption(int ind)
|
|||
*/
|
||||
void GuiGameList::Draw()
|
||||
{
|
||||
LOCK( this );
|
||||
if (!this->IsVisible() || !gameList.size()) return;
|
||||
LOCK( this );
|
||||
if (!this->IsVisible() || !gameList.size()) return;
|
||||
|
||||
bgGameImg->Draw();
|
||||
bgGameImg->Draw();
|
||||
|
||||
for (int i = 0, next = listOffset; i < pagesize; ++i, ++next)
|
||||
{
|
||||
if (next < gameList.size())
|
||||
game[i]->Draw();
|
||||
}
|
||||
for (int i = 0, next = listOffset; i < pagesize; ++i, ++next)
|
||||
{
|
||||
if (next < gameList.size())
|
||||
game[i]->Draw();
|
||||
}
|
||||
|
||||
if (scrollbaron == 1)
|
||||
scrollBar.Draw();
|
||||
if (scrollbaron == 1)
|
||||
scrollBar.Draw();
|
||||
|
||||
this->UpdateEffects();
|
||||
this->UpdateEffects();
|
||||
}
|
||||
|
||||
void GuiGameList::UpdateListEntries()
|
||||
{
|
||||
for (int i = 0, next = listOffset; i < pagesize; ++i, ++next)
|
||||
{
|
||||
if (next < gameList.size())
|
||||
{
|
||||
if (game[i]->GetState() == STATE_DISABLED)
|
||||
{
|
||||
game[i]->SetVisible(true);
|
||||
game[i]->SetState(STATE_DEFAULT);
|
||||
}
|
||||
gameTxt[i]->SetText(GameTitles.GetTitle(gameList[next]));
|
||||
gameTxt[i]->SetPosition(24, 0);
|
||||
gameTxtOver[i]->SetText(GameTitles.GetTitle(gameList[next]));
|
||||
gameTxtOver[i]->SetPosition(24, 0);
|
||||
for (int i = 0, next = listOffset; i < pagesize; ++i, ++next)
|
||||
{
|
||||
if (next < gameList.size())
|
||||
{
|
||||
if (game[i]->GetState() == STATE_DISABLED)
|
||||
{
|
||||
game[i]->SetVisible(true);
|
||||
game[i]->SetState(STATE_DEFAULT);
|
||||
}
|
||||
gameTxt[i]->SetText(GameTitles.GetTitle(gameList[next]));
|
||||
gameTxt[i]->SetPosition(24, 0);
|
||||
gameTxtOver[i]->SetText(GameTitles.GetTitle(gameList[next]));
|
||||
gameTxtOver[i]->SetPosition(24, 0);
|
||||
|
||||
if (Settings.marknewtitles)
|
||||
{
|
||||
bool isNew = NewTitles::Instance()->IsNew(gameList[next]->id);
|
||||
if (isNew)
|
||||
{
|
||||
gameTxt[i]->SetMaxWidth(maxTextWidth - (newGames->GetWidth() + 1), DOTTED);
|
||||
gameTxtOver[i]->SetMaxWidth(maxTextWidth - (newGames->GetWidth() + 1), SCROLL_HORIZONTAL);
|
||||
}
|
||||
else
|
||||
{
|
||||
gameTxt[i]->SetMaxWidth(maxTextWidth, DOTTED);
|
||||
gameTxtOver[i]->SetMaxWidth(maxTextWidth, SCROLL_HORIZONTAL);
|
||||
}
|
||||
newImg[i]->SetVisible(isNew);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
game[i]->SetVisible(false);
|
||||
game[i]->SetState(STATE_DISABLED);
|
||||
}
|
||||
}
|
||||
if (Settings.marknewtitles)
|
||||
{
|
||||
bool isNew = NewTitles::Instance()->IsNew(gameList[next]->id);
|
||||
if (isNew)
|
||||
{
|
||||
gameTxt[i]->SetMaxWidth(maxTextWidth - (newGames->GetWidth() + 1), DOTTED);
|
||||
gameTxtOver[i]->SetMaxWidth(maxTextWidth - (newGames->GetWidth() + 1), SCROLL_HORIZONTAL);
|
||||
}
|
||||
else
|
||||
{
|
||||
gameTxt[i]->SetMaxWidth(maxTextWidth, DOTTED);
|
||||
gameTxtOver[i]->SetMaxWidth(maxTextWidth, SCROLL_HORIZONTAL);
|
||||
}
|
||||
newImg[i]->SetVisible(isNew);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
game[i]->SetVisible(false);
|
||||
game[i]->SetState(STATE_DISABLED);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GuiGameList::Update(GuiTrigger * t)
|
||||
{
|
||||
LOCK( this );
|
||||
if (state == STATE_DISABLED || !t || !gameList.size()) return;
|
||||
LOCK( this );
|
||||
if (state == STATE_DISABLED || !t || !gameList.size()) return;
|
||||
|
||||
static int pressedChan = -1;
|
||||
static int pressedChan = -1;
|
||||
|
||||
if((t->wpad.btns_d & (WPAD_BUTTON_B | WPAD_BUTTON_DOWN | WPAD_BUTTON_UP | WPAD_BUTTON_LEFT | WPAD_BUTTON_RIGHT |
|
||||
WPAD_CLASSIC_BUTTON_B | WPAD_CLASSIC_BUTTON_UP | WPAD_CLASSIC_BUTTON_DOWN | WPAD_CLASSIC_BUTTON_LEFT | WPAD_CLASSIC_BUTTON_RIGHT)) ||
|
||||
(t->pad.btns_d & (PAD_BUTTON_UP | PAD_BUTTON_DOWN)))
|
||||
pressedChan = t->chan;
|
||||
if((t->wpad.btns_d & (WPAD_BUTTON_B | WPAD_BUTTON_DOWN | WPAD_BUTTON_UP | WPAD_BUTTON_LEFT | WPAD_BUTTON_RIGHT |
|
||||
WPAD_CLASSIC_BUTTON_B | WPAD_CLASSIC_BUTTON_UP | WPAD_CLASSIC_BUTTON_DOWN | WPAD_CLASSIC_BUTTON_LEFT | WPAD_CLASSIC_BUTTON_RIGHT)) ||
|
||||
(t->pad.btns_d & (PAD_BUTTON_UP | PAD_BUTTON_DOWN)))
|
||||
pressedChan = t->chan;
|
||||
|
||||
if (scrollbaron == 1)
|
||||
// update the location of the scroll box based on the position in the option list
|
||||
scrollBar.Update(t);
|
||||
if (scrollbaron == 1)
|
||||
// update the location of the scroll box based on the position in the option list
|
||||
scrollBar.Update(t);
|
||||
|
||||
if(pressedChan == -1 || (!t->wpad.btns_h && !t->pad.btns_h))
|
||||
{
|
||||
for (int i = 0, next = listOffset; i < pagesize; ++i, ++next)
|
||||
{
|
||||
if (next >= gameList.size())
|
||||
break;
|
||||
if(pressedChan == -1 || (!t->wpad.btns_h && !t->pad.btns_h))
|
||||
{
|
||||
for (int i = 0, next = listOffset; i < pagesize; ++i, ++next)
|
||||
{
|
||||
if (next >= gameList.size())
|
||||
break;
|
||||
|
||||
if (i != selectedItem && game[i]->GetState() == STATE_SELECTED)
|
||||
game[i]->ResetState();
|
||||
|
@ -286,17 +286,17 @@ void GuiGameList::Update(GuiTrigger * t)
|
|||
|
||||
if (game[i]->GetState() == STATE_SELECTED)
|
||||
selectedItem = i;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(pressedChan == t->chan && !t->wpad.btns_d && !t->wpad.btns_h)
|
||||
pressedChan = -1;
|
||||
if(pressedChan == t->chan && !t->wpad.btns_d && !t->wpad.btns_h)
|
||||
pressedChan = -1;
|
||||
|
||||
scrollBar.SetPageSize(pagesize);
|
||||
scrollBar.SetSelectedItem(selectedItem);
|
||||
scrollBar.SetSelectedIndex(listOffset);
|
||||
scrollBar.SetEntrieCount(gameList.size());
|
||||
scrollBar.SetPageSize(pagesize);
|
||||
scrollBar.SetSelectedItem(selectedItem);
|
||||
scrollBar.SetSelectedIndex(listOffset);
|
||||
scrollBar.SetEntrieCount(gameList.size());
|
||||
|
||||
if (updateCB) updateCB(this);
|
||||
if (updateCB) updateCB(this);
|
||||
}
|
||||
|
||||
|
|
|
@ -7,41 +7,41 @@
|
|||
|
||||
class GuiGameList : public GuiGameBrowser, public sigslot::has_slots<>
|
||||
{
|
||||
public:
|
||||
GuiGameList(int w, int h, int listOffset = 0);
|
||||
virtual ~GuiGameList();
|
||||
int GetClickedOption();
|
||||
int GetSelectedOption() { return listOffset+selectedItem; }
|
||||
void SetSelectedOption(int ind);
|
||||
public:
|
||||
GuiGameList(int w, int h, int listOffset = 0);
|
||||
virtual ~GuiGameList();
|
||||
int GetClickedOption();
|
||||
int GetSelectedOption() { return listOffset+selectedItem; }
|
||||
void SetSelectedOption(int ind);
|
||||
void setListOffset(int off);
|
||||
int getListOffset() const { return listOffset; }
|
||||
void ResetState();
|
||||
void SetFocus(int f);
|
||||
void Draw();
|
||||
void Update(GuiTrigger * t);
|
||||
protected:
|
||||
void onListChange(int SelItem, int SelInd);
|
||||
void UpdateListEntries();
|
||||
int selectedItem;
|
||||
int listOffset;
|
||||
int scrollbaron;
|
||||
int pagesize;
|
||||
int maxTextWidth;
|
||||
void ResetState();
|
||||
void SetFocus(int f);
|
||||
void Draw();
|
||||
void Update(GuiTrigger * t);
|
||||
protected:
|
||||
void onListChange(int SelItem, int SelInd);
|
||||
void UpdateListEntries();
|
||||
int selectedItem;
|
||||
int listOffset;
|
||||
int scrollbaron;
|
||||
int pagesize;
|
||||
int maxTextWidth;
|
||||
|
||||
GuiButton ** game;
|
||||
GuiText ** gameTxt;
|
||||
GuiText ** gameTxtOver;
|
||||
GuiImage ** gameBg;
|
||||
GuiImage ** newImg;
|
||||
GuiButton ** game;
|
||||
GuiText ** gameTxt;
|
||||
GuiText ** gameTxtOver;
|
||||
GuiImage ** gameBg;
|
||||
GuiImage ** newImg;
|
||||
|
||||
GuiImage * bgGameImg;
|
||||
GuiImage * bgGameImg;
|
||||
|
||||
GuiImageData * bgGames;
|
||||
GuiImageData * bgGamesEntry;
|
||||
GuiImageData * newGames;
|
||||
GuiImageData * bgGames;
|
||||
GuiImageData * bgGamesEntry;
|
||||
GuiImageData * newGames;
|
||||
|
||||
GuiTrigger * trigA;
|
||||
GuiTrigger * trigA;
|
||||
|
||||
GuiScrollbar scrollBar;
|
||||
GuiScrollbar scrollBar;
|
||||
};
|
||||
#endif
|
||||
|
|
|
@ -15,200 +15,200 @@
|
|||
*/
|
||||
GuiImage::GuiImage()
|
||||
{
|
||||
image = NULL;
|
||||
width = 0;
|
||||
height = 0;
|
||||
imageangle = 0;
|
||||
tileHorizontal = -1;
|
||||
tileVertical = -1;
|
||||
stripe = 0;
|
||||
widescreen = 0;
|
||||
xx1 = 0;
|
||||
yy1 = 0;
|
||||
xx2 = 0;
|
||||
yy2 = 0;
|
||||
xx3 = 0;
|
||||
yy3 = 0;
|
||||
xx4 = 0;
|
||||
yy4 = 0;
|
||||
imgType = IMAGE_DATA;
|
||||
image = NULL;
|
||||
width = 0;
|
||||
height = 0;
|
||||
imageangle = 0;
|
||||
tileHorizontal = -1;
|
||||
tileVertical = -1;
|
||||
stripe = 0;
|
||||
widescreen = 0;
|
||||
xx1 = 0;
|
||||
yy1 = 0;
|
||||
xx2 = 0;
|
||||
yy2 = 0;
|
||||
xx3 = 0;
|
||||
yy3 = 0;
|
||||
xx4 = 0;
|
||||
yy4 = 0;
|
||||
imgType = IMAGE_DATA;
|
||||
}
|
||||
|
||||
GuiImage::GuiImage(GuiImageData * img)
|
||||
{
|
||||
if (img)
|
||||
{
|
||||
image = img->GetImage();
|
||||
width = img->GetWidth();
|
||||
height = img->GetHeight();
|
||||
}
|
||||
else
|
||||
{
|
||||
image = NULL;
|
||||
width = 0;
|
||||
height = 0;
|
||||
}
|
||||
imageangle = 0;
|
||||
tileHorizontal = -1;
|
||||
tileVertical = -1;
|
||||
stripe = 0;
|
||||
widescreen = 0;
|
||||
parentangle = true;
|
||||
xx1 = 0;
|
||||
yy1 = 0;
|
||||
xx2 = 0;
|
||||
yy2 = 0;
|
||||
xx3 = 0;
|
||||
yy3 = 0;
|
||||
xx4 = 0;
|
||||
yy4 = 0;
|
||||
imgType = IMAGE_DATA;
|
||||
if (img)
|
||||
{
|
||||
image = img->GetImage();
|
||||
width = img->GetWidth();
|
||||
height = img->GetHeight();
|
||||
}
|
||||
else
|
||||
{
|
||||
image = NULL;
|
||||
width = 0;
|
||||
height = 0;
|
||||
}
|
||||
imageangle = 0;
|
||||
tileHorizontal = -1;
|
||||
tileVertical = -1;
|
||||
stripe = 0;
|
||||
widescreen = 0;
|
||||
parentangle = true;
|
||||
xx1 = 0;
|
||||
yy1 = 0;
|
||||
xx2 = 0;
|
||||
yy2 = 0;
|
||||
xx3 = 0;
|
||||
yy3 = 0;
|
||||
xx4 = 0;
|
||||
yy4 = 0;
|
||||
imgType = IMAGE_DATA;
|
||||
}
|
||||
|
||||
GuiImage::GuiImage(u8 * img, int w, int h)
|
||||
{
|
||||
image = img;
|
||||
width = w;
|
||||
height = h;
|
||||
imageangle = 0;
|
||||
tileHorizontal = -1;
|
||||
tileVertical = -1;
|
||||
stripe = 0;
|
||||
widescreen = 0;
|
||||
parentangle = true;
|
||||
xx1 = 0;
|
||||
yy1 = 0;
|
||||
xx2 = 0;
|
||||
yy2 = 0;
|
||||
xx3 = 0;
|
||||
yy3 = 0;
|
||||
xx4 = 0;
|
||||
yy4 = 0;
|
||||
imgType = IMAGE_TEXTURE;
|
||||
image = img;
|
||||
width = w;
|
||||
height = h;
|
||||
imageangle = 0;
|
||||
tileHorizontal = -1;
|
||||
tileVertical = -1;
|
||||
stripe = 0;
|
||||
widescreen = 0;
|
||||
parentangle = true;
|
||||
xx1 = 0;
|
||||
yy1 = 0;
|
||||
xx2 = 0;
|
||||
yy2 = 0;
|
||||
xx3 = 0;
|
||||
yy3 = 0;
|
||||
xx4 = 0;
|
||||
yy4 = 0;
|
||||
imgType = IMAGE_TEXTURE;
|
||||
}
|
||||
|
||||
GuiImage::GuiImage(int w, int h, GXColor c)
|
||||
{
|
||||
image = (u8 *) memalign(32, w * h * 4);
|
||||
width = w;
|
||||
height = h;
|
||||
imageangle = 0;
|
||||
tileHorizontal = -1;
|
||||
tileVertical = -1;
|
||||
stripe = 0;
|
||||
widescreen = 0;
|
||||
parentangle = true;
|
||||
xx1 = 0;
|
||||
yy1 = 0;
|
||||
xx2 = 0;
|
||||
yy2 = 0;
|
||||
xx3 = 0;
|
||||
yy3 = 0;
|
||||
xx4 = 0;
|
||||
yy4 = 0;
|
||||
imgType = IMAGE_COLOR;
|
||||
image = (u8 *) memalign(32, w * h * 4);
|
||||
width = w;
|
||||
height = h;
|
||||
imageangle = 0;
|
||||
tileHorizontal = -1;
|
||||
tileVertical = -1;
|
||||
stripe = 0;
|
||||
widescreen = 0;
|
||||
parentangle = true;
|
||||
xx1 = 0;
|
||||
yy1 = 0;
|
||||
xx2 = 0;
|
||||
yy2 = 0;
|
||||
xx3 = 0;
|
||||
yy3 = 0;
|
||||
xx4 = 0;
|
||||
yy4 = 0;
|
||||
imgType = IMAGE_COLOR;
|
||||
|
||||
if (!image) return;
|
||||
if (!image) return;
|
||||
|
||||
int x, y;
|
||||
int x, y;
|
||||
|
||||
for (y = 0; y < h; y++)
|
||||
{
|
||||
for (x = 0; x < w; x++)
|
||||
{
|
||||
this->SetPixel(x, y, c);
|
||||
}
|
||||
}
|
||||
int len = w * h * 4;
|
||||
if (len % 32) len += (32 - len % 32);
|
||||
DCFlushRange(image, len);
|
||||
for (y = 0; y < h; y++)
|
||||
{
|
||||
for (x = 0; x < w; x++)
|
||||
{
|
||||
this->SetPixel(x, y, c);
|
||||
}
|
||||
}
|
||||
int len = w * h * 4;
|
||||
if (len % 32) len += (32 - len % 32);
|
||||
DCFlushRange(image, len);
|
||||
}
|
||||
|
||||
GuiImage::GuiImage(GuiImage &srcimage) :
|
||||
GuiElement()
|
||||
GuiElement()
|
||||
{
|
||||
width = srcimage.GetWidth();
|
||||
height = srcimage.GetHeight();
|
||||
int len = width * height * 4;
|
||||
if (len % 32) len += (32 - len % 32);
|
||||
image = (u8 *) memalign(32, len);
|
||||
memcpy(image, srcimage.GetImage(), len);
|
||||
DCFlushRange(image, len);
|
||||
imageangle = srcimage.GetAngle();
|
||||
tileHorizontal = -1;
|
||||
tileVertical = -1;
|
||||
stripe = 0;
|
||||
widescreen = 0;
|
||||
parentangle = true;
|
||||
xx1 = 0;
|
||||
yy1 = 0;
|
||||
xx2 = 0;
|
||||
yy2 = 0;
|
||||
xx3 = 0;
|
||||
yy3 = 0;
|
||||
xx4 = 0;
|
||||
yy4 = 0;
|
||||
imgType = IMAGE_COPY;
|
||||
width = srcimage.GetWidth();
|
||||
height = srcimage.GetHeight();
|
||||
int len = width * height * 4;
|
||||
if (len % 32) len += (32 - len % 32);
|
||||
image = (u8 *) memalign(32, len);
|
||||
memcpy(image, srcimage.GetImage(), len);
|
||||
DCFlushRange(image, len);
|
||||
imageangle = srcimage.GetAngle();
|
||||
tileHorizontal = -1;
|
||||
tileVertical = -1;
|
||||
stripe = 0;
|
||||
widescreen = 0;
|
||||
parentangle = true;
|
||||
xx1 = 0;
|
||||
yy1 = 0;
|
||||
xx2 = 0;
|
||||
yy2 = 0;
|
||||
xx3 = 0;
|
||||
yy3 = 0;
|
||||
xx4 = 0;
|
||||
yy4 = 0;
|
||||
imgType = IMAGE_COPY;
|
||||
}
|
||||
|
||||
GuiImage::GuiImage(GuiImage *srcimage) :
|
||||
GuiElement()
|
||||
GuiElement()
|
||||
{
|
||||
width = srcimage->GetWidth();
|
||||
height = srcimage->GetHeight();
|
||||
int len = width * height * 4;
|
||||
if (len % 32) len += (32 - len % 32);
|
||||
image = (u8 *) memalign(32, len);
|
||||
memcpy(image, srcimage->GetImage(), len);
|
||||
DCFlushRange(image, len);
|
||||
imageangle = srcimage->GetAngle();
|
||||
tileHorizontal = -1;
|
||||
tileVertical = -1;
|
||||
stripe = 0;
|
||||
widescreen = 0;
|
||||
parentangle = true;
|
||||
xx1 = 0;
|
||||
yy1 = 0;
|
||||
xx2 = 0;
|
||||
yy2 = 0;
|
||||
xx3 = 0;
|
||||
yy3 = 0;
|
||||
xx4 = 0;
|
||||
yy4 = 0;
|
||||
imgType = IMAGE_COPY;
|
||||
width = srcimage->GetWidth();
|
||||
height = srcimage->GetHeight();
|
||||
int len = width * height * 4;
|
||||
if (len % 32) len += (32 - len % 32);
|
||||
image = (u8 *) memalign(32, len);
|
||||
memcpy(image, srcimage->GetImage(), len);
|
||||
DCFlushRange(image, len);
|
||||
imageangle = srcimage->GetAngle();
|
||||
tileHorizontal = -1;
|
||||
tileVertical = -1;
|
||||
stripe = 0;
|
||||
widescreen = 0;
|
||||
parentangle = true;
|
||||
xx1 = 0;
|
||||
yy1 = 0;
|
||||
xx2 = 0;
|
||||
yy2 = 0;
|
||||
xx3 = 0;
|
||||
yy3 = 0;
|
||||
xx4 = 0;
|
||||
yy4 = 0;
|
||||
imgType = IMAGE_COPY;
|
||||
}
|
||||
|
||||
GuiImage &GuiImage::operator=(GuiImage & srcimage)
|
||||
{
|
||||
if ((imgType == IMAGE_COLOR || imgType == IMAGE_COPY) && image)
|
||||
{
|
||||
free(image);
|
||||
image = NULL;
|
||||
}
|
||||
if ((imgType == IMAGE_COLOR || imgType == IMAGE_COPY) && image)
|
||||
{
|
||||
free(image);
|
||||
image = NULL;
|
||||
}
|
||||
|
||||
width = srcimage.GetWidth();
|
||||
height = srcimage.GetHeight();
|
||||
int len = width * height * 4;
|
||||
if (len % 32) len += (32 - len % 32);
|
||||
image = (u8 *) memalign(32, len);
|
||||
memcpy(image, srcimage.GetImage(), len);
|
||||
DCFlushRange(image, len);
|
||||
imageangle = srcimage.GetAngle();
|
||||
tileHorizontal = -1;
|
||||
tileVertical = -1;
|
||||
stripe = 0;
|
||||
widescreen = 0;
|
||||
parentangle = true;
|
||||
xx1 = 0;
|
||||
yy1 = 0;
|
||||
xx2 = 0;
|
||||
yy2 = 0;
|
||||
xx3 = 0;
|
||||
yy3 = 0;
|
||||
xx4 = 0;
|
||||
yy4 = 0;
|
||||
imgType = IMAGE_COPY;
|
||||
return *this;
|
||||
width = srcimage.GetWidth();
|
||||
height = srcimage.GetHeight();
|
||||
int len = width * height * 4;
|
||||
if (len % 32) len += (32 - len % 32);
|
||||
image = (u8 *) memalign(32, len);
|
||||
memcpy(image, srcimage.GetImage(), len);
|
||||
DCFlushRange(image, len);
|
||||
imageangle = srcimage.GetAngle();
|
||||
tileHorizontal = -1;
|
||||
tileVertical = -1;
|
||||
stripe = 0;
|
||||
widescreen = 0;
|
||||
parentangle = true;
|
||||
xx1 = 0;
|
||||
yy1 = 0;
|
||||
xx2 = 0;
|
||||
yy2 = 0;
|
||||
xx3 = 0;
|
||||
yy3 = 0;
|
||||
xx4 = 0;
|
||||
yy4 = 0;
|
||||
imgType = IMAGE_COPY;
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -216,222 +216,222 @@ GuiImage &GuiImage::operator=(GuiImage & srcimage)
|
|||
*/
|
||||
GuiImage::~GuiImage()
|
||||
{
|
||||
if ((imgType == IMAGE_COLOR || imgType == IMAGE_COPY) && image)
|
||||
{
|
||||
free(image);
|
||||
image = NULL;
|
||||
}
|
||||
if ((imgType == IMAGE_COLOR || imgType == IMAGE_COPY) && image)
|
||||
{
|
||||
free(image);
|
||||
image = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
u8 * GuiImage::GetImage()
|
||||
{
|
||||
return image;
|
||||
return image;
|
||||
}
|
||||
|
||||
void GuiImage::SetImage(GuiImageData * img)
|
||||
{
|
||||
LOCK( this );
|
||||
if ((imgType == IMAGE_COLOR || imgType == IMAGE_COPY) && image)
|
||||
{
|
||||
free(image);
|
||||
image = NULL;
|
||||
}
|
||||
LOCK( this );
|
||||
if ((imgType == IMAGE_COLOR || imgType == IMAGE_COPY) && image)
|
||||
{
|
||||
free(image);
|
||||
image = NULL;
|
||||
}
|
||||
|
||||
image = NULL;
|
||||
width = 0;
|
||||
height = 0;
|
||||
imgType = IMAGE_DATA;
|
||||
image = NULL;
|
||||
width = 0;
|
||||
height = 0;
|
||||
imgType = IMAGE_DATA;
|
||||
|
||||
if(img)
|
||||
{
|
||||
image = img->GetImage();
|
||||
width = img->GetWidth();
|
||||
height = img->GetHeight();
|
||||
}
|
||||
if(img)
|
||||
{
|
||||
image = img->GetImage();
|
||||
width = img->GetWidth();
|
||||
height = img->GetHeight();
|
||||
}
|
||||
}
|
||||
|
||||
void GuiImage::SetImage(u8 * img, int w, int h)
|
||||
{
|
||||
LOCK( this );
|
||||
if ((imgType == IMAGE_COLOR || imgType == IMAGE_COPY) && image)
|
||||
{
|
||||
free(image);
|
||||
image = NULL;
|
||||
}
|
||||
image = img;
|
||||
width = w;
|
||||
height = h;
|
||||
imgType = IMAGE_TEXTURE;
|
||||
LOCK( this );
|
||||
if ((imgType == IMAGE_COLOR || imgType == IMAGE_COPY) && image)
|
||||
{
|
||||
free(image);
|
||||
image = NULL;
|
||||
}
|
||||
image = img;
|
||||
width = w;
|
||||
height = h;
|
||||
imgType = IMAGE_TEXTURE;
|
||||
}
|
||||
|
||||
void GuiImage::SetAngle(float a)
|
||||
{
|
||||
LOCK( this );
|
||||
imageangle = a;
|
||||
LOCK( this );
|
||||
imageangle = a;
|
||||
}
|
||||
float GuiImage::GetAngle()
|
||||
{
|
||||
return imageangle;
|
||||
return imageangle;
|
||||
}
|
||||
|
||||
void GuiImage::SetTileHorizontal(int t)
|
||||
{
|
||||
LOCK( this );
|
||||
tileHorizontal = t;
|
||||
LOCK( this );
|
||||
tileHorizontal = t;
|
||||
}
|
||||
|
||||
void GuiImage::SetTileVertical(int t)
|
||||
{
|
||||
LOCK( this );
|
||||
tileVertical = t;
|
||||
LOCK( this );
|
||||
tileVertical = t;
|
||||
}
|
||||
|
||||
void GuiImage::SetWidescreen(bool w)
|
||||
{
|
||||
LOCK( this );
|
||||
widescreen = w;
|
||||
LOCK( this );
|
||||
widescreen = w;
|
||||
}
|
||||
void GuiImage::SetParentAngle(bool a)
|
||||
{
|
||||
LOCK( this );
|
||||
parentangle = a;
|
||||
LOCK( this );
|
||||
parentangle = a;
|
||||
}
|
||||
|
||||
GXColor GuiImage::GetPixel(int x, int y)
|
||||
{
|
||||
if (!image || this->GetWidth() <= 0 || x < 0 || y < 0) return ( GXColor )
|
||||
{ 0, 0, 0, 0};
|
||||
if (!image || this->GetWidth() <= 0 || x < 0 || y < 0) return ( GXColor )
|
||||
{ 0, 0, 0, 0};
|
||||
|
||||
u32 offset = (((y >> 2) << 4) * this->GetWidth()) + ((x >> 2) << 6) + (((y % 4 << 2) + x % 4) << 1);
|
||||
GXColor color;
|
||||
color.a = *(image + offset);
|
||||
color.r = *(image + offset + 1);
|
||||
color.g = *(image + offset + 32);
|
||||
color.b = *(image + offset + 33);
|
||||
return color;
|
||||
u32 offset = (((y >> 2) << 4) * this->GetWidth()) + ((x >> 2) << 6) + (((y % 4 << 2) + x % 4) << 1);
|
||||
GXColor color;
|
||||
color.a = *(image + offset);
|
||||
color.r = *(image + offset + 1);
|
||||
color.g = *(image + offset + 32);
|
||||
color.b = *(image + offset + 33);
|
||||
return color;
|
||||
}
|
||||
|
||||
void GuiImage::SetPixel(int x, int y, GXColor color)
|
||||
{
|
||||
LOCK( this );
|
||||
if (!image || this->GetWidth() <= 0 || x < 0 || y < 0) return;
|
||||
LOCK( this );
|
||||
if (!image || this->GetWidth() <= 0 || x < 0 || y < 0) return;
|
||||
|
||||
u32 offset = (((y >> 2) << 4) * this->GetWidth()) + ((x >> 2) << 6) + (((y % 4 << 2) + x % 4) << 1);
|
||||
*(image + offset) = color.a;
|
||||
*(image + offset + 1) = color.r;
|
||||
*(image + offset + 32) = color.g;
|
||||
*(image + offset + 33) = color.b;
|
||||
u32 offset = (((y >> 2) << 4) * this->GetWidth()) + ((x >> 2) << 6) + (((y % 4 << 2) + x % 4) << 1);
|
||||
*(image + offset) = color.a;
|
||||
*(image + offset + 1) = color.r;
|
||||
*(image + offset + 32) = color.g;
|
||||
*(image + offset + 33) = color.b;
|
||||
}
|
||||
|
||||
void GuiImage::SetGrayscale(void)
|
||||
{
|
||||
LOCK( this );
|
||||
GXColor color;
|
||||
u32 offset, gray;
|
||||
LOCK( this );
|
||||
GXColor color;
|
||||
u32 offset, gray;
|
||||
|
||||
for (int x = 0; x < width; x++)
|
||||
{
|
||||
for (int y = 0; y < height; y++)
|
||||
{
|
||||
offset = (((y >> 2) << 4) * width) + ((x >> 2) << 6) + (((y % 4 << 2) + x % 4) << 1);
|
||||
color.r = *(image + offset + 1);
|
||||
color.g = *(image + offset + 32);
|
||||
color.b = *(image + offset + 33);
|
||||
for (int x = 0; x < width; x++)
|
||||
{
|
||||
for (int y = 0; y < height; y++)
|
||||
{
|
||||
offset = (((y >> 2) << 4) * width) + ((x >> 2) << 6) + (((y % 4 << 2) + x % 4) << 1);
|
||||
color.r = *(image + offset + 1);
|
||||
color.g = *(image + offset + 32);
|
||||
color.b = *(image + offset + 33);
|
||||
|
||||
gray = (77 * color.r + 150 * color.g + 28 * color.b) / 255;
|
||||
gray = (77 * color.r + 150 * color.g + 28 * color.b) / 255;
|
||||
|
||||
*(image + offset + 1) = gray;
|
||||
*(image + offset + 32) = gray;
|
||||
*(image + offset + 33) = gray;
|
||||
}
|
||||
}
|
||||
*(image + offset + 1) = gray;
|
||||
*(image + offset + 32) = gray;
|
||||
*(image + offset + 33) = gray;
|
||||
}
|
||||
}
|
||||
|
||||
int len = width * height * 4;
|
||||
if (len % 32) len += (32 - len % 32);
|
||||
DCFlushRange(image, len);
|
||||
int len = width * height * 4;
|
||||
if (len % 32) len += (32 - len % 32);
|
||||
DCFlushRange(image, len);
|
||||
}
|
||||
|
||||
void GuiImage::SetStripe(int s)
|
||||
{
|
||||
LOCK( this );
|
||||
stripe = s;
|
||||
LOCK( this );
|
||||
stripe = s;
|
||||
}
|
||||
|
||||
void GuiImage::SetSkew(int XX1, int YY1, int XX2, int YY2, int XX3, int YY3, int XX4, int YY4)
|
||||
{
|
||||
|
||||
xx1 = XX1;
|
||||
yy1 = YY1;
|
||||
xx2 = XX2;
|
||||
yy2 = YY2;
|
||||
xx3 = XX3;
|
||||
yy3 = YY3;
|
||||
xx4 = XX4;
|
||||
yy4 = YY4;
|
||||
xx1 = XX1;
|
||||
yy1 = YY1;
|
||||
xx2 = XX2;
|
||||
yy2 = YY2;
|
||||
xx3 = XX3;
|
||||
yy3 = YY3;
|
||||
xx4 = XX4;
|
||||
yy4 = YY4;
|
||||
}
|
||||
void GuiImage::SetSkew(int *skew)
|
||||
{
|
||||
|
||||
xx1 = *skew++;
|
||||
yy1 = *skew++;
|
||||
xx2 = *skew++;
|
||||
yy2 = *skew++;
|
||||
xx3 = *skew++;
|
||||
yy3 = *skew++;
|
||||
xx4 = *skew++;
|
||||
yy4 = *skew;
|
||||
xx1 = *skew++;
|
||||
yy1 = *skew++;
|
||||
xx2 = *skew++;
|
||||
yy2 = *skew++;
|
||||
xx3 = *skew++;
|
||||
yy3 = *skew++;
|
||||
xx4 = *skew++;
|
||||
yy4 = *skew;
|
||||
}
|
||||
|
||||
void GuiImage::ColorStripe(int shift)
|
||||
{
|
||||
LOCK( this );
|
||||
int x, y;
|
||||
GXColor color;
|
||||
int alt = 0;
|
||||
LOCK( this );
|
||||
int x, y;
|
||||
GXColor color;
|
||||
int alt = 0;
|
||||
|
||||
for (y = 0; y < this->GetHeight(); y++)
|
||||
{
|
||||
if (y % 3 == 0) alt ^= 1;
|
||||
for (y = 0; y < this->GetHeight(); y++)
|
||||
{
|
||||
if (y % 3 == 0) alt ^= 1;
|
||||
|
||||
for (x = 0; x < this->GetWidth(); x++)
|
||||
{
|
||||
color = GetPixel(x, y);
|
||||
for (x = 0; x < this->GetWidth(); x++)
|
||||
{
|
||||
color = GetPixel(x, y);
|
||||
|
||||
if (alt)
|
||||
{
|
||||
if (color.r < 255 - shift)
|
||||
color.r += shift;
|
||||
else color.r = 255;
|
||||
if (color.g < 255 - shift)
|
||||
color.g += shift;
|
||||
else color.g = 255;
|
||||
if (color.b < 255 - shift)
|
||||
color.b += shift;
|
||||
else color.b = 255;
|
||||
if (alt)
|
||||
{
|
||||
if (color.r < 255 - shift)
|
||||
color.r += shift;
|
||||
else color.r = 255;
|
||||
if (color.g < 255 - shift)
|
||||
color.g += shift;
|
||||
else color.g = 255;
|
||||
if (color.b < 255 - shift)
|
||||
color.b += shift;
|
||||
else color.b = 255;
|
||||
|
||||
color.a = 255;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (color.r > shift)
|
||||
color.r -= shift;
|
||||
else color.r = 0;
|
||||
if (color.g > shift)
|
||||
color.g -= shift;
|
||||
else color.g = 0;
|
||||
if (color.b > shift)
|
||||
color.b -= shift;
|
||||
else color.b = 0;
|
||||
color.a = 255;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (color.r > shift)
|
||||
color.r -= shift;
|
||||
else color.r = 0;
|
||||
if (color.g > shift)
|
||||
color.g -= shift;
|
||||
else color.g = 0;
|
||||
if (color.b > shift)
|
||||
color.b -= shift;
|
||||
else color.b = 0;
|
||||
|
||||
color.a = 255;
|
||||
}
|
||||
SetPixel(x, y, color);
|
||||
}
|
||||
}
|
||||
color.a = 255;
|
||||
}
|
||||
SetPixel(x, y, color);
|
||||
}
|
||||
}
|
||||
|
||||
int len = width * height * 4;
|
||||
if (len % 32) len += (32 - len % 32);
|
||||
DCFlushRange(image, len);
|
||||
int len = width * height * 4;
|
||||
if (len % 32) len += (32 - len % 32);
|
||||
DCFlushRange(image, len);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -440,42 +440,42 @@ void GuiImage::ColorStripe(int shift)
|
|||
|
||||
void GuiImage::Draw()
|
||||
{
|
||||
LOCK( this );
|
||||
if (!image || !this->IsVisible() || tileHorizontal == 0) return;
|
||||
LOCK( this );
|
||||
if (!image || !this->IsVisible() || tileHorizontal == 0) return;
|
||||
|
||||
float currScale = this->GetScale();
|
||||
int currLeft = this->GetLeft();
|
||||
float currScale = this->GetScale();
|
||||
int currLeft = this->GetLeft();
|
||||
|
||||
float currAngleDyn = this->GetAngleDyn();
|
||||
float currAngleDyn = this->GetAngleDyn();
|
||||
|
||||
if (currAngleDyn && parentangle) imageangle = currAngleDyn;
|
||||
if (currAngleDyn && parentangle) imageangle = currAngleDyn;
|
||||
|
||||
if (tileHorizontal > 0)
|
||||
{
|
||||
for (int i = 0; i < tileHorizontal; i++)
|
||||
Menu_DrawImg(currLeft + width * i, this->GetTop(), zoffset, width, height, image, imageangle,
|
||||
widescreen ? currScale * Settings.WSFactor : currScale, currScale, this->GetAlpha(), xx1,
|
||||
if (tileHorizontal > 0)
|
||||
{
|
||||
for (int i = 0; i < tileHorizontal; i++)
|
||||
Menu_DrawImg(currLeft + width * i, this->GetTop(), zoffset, width, height, image, imageangle,
|
||||
widescreen ? currScale * Settings.WSFactor : currScale, currScale, this->GetAlpha(), xx1,
|
||||
yy1, xx2, yy2, xx3, yy3, xx4, yy4);
|
||||
}
|
||||
else if(tileVertical > 0)
|
||||
{
|
||||
for (int i = 0; i < tileVertical; i++)
|
||||
Menu_DrawImg(currLeft, this->GetTop() + height * i, zoffset, width, height, image, imageangle,
|
||||
widescreen ? currScale * Settings.WSFactor : currScale, currScale, this->GetAlpha(), xx1,
|
||||
}
|
||||
else if(tileVertical > 0)
|
||||
{
|
||||
for (int i = 0; i < tileVertical; i++)
|
||||
Menu_DrawImg(currLeft, this->GetTop() + height * i, zoffset, width, height, image, imageangle,
|
||||
widescreen ? currScale * Settings.WSFactor : currScale, currScale, this->GetAlpha(), xx1,
|
||||
yy1, xx2, yy2, xx3, yy3, xx4, yy4);
|
||||
}
|
||||
else
|
||||
{
|
||||
// temporary (maybe), used to correct offset for scaled images
|
||||
if (scale != 1) currLeft = currLeft - width / 2 + (width * scale) / 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
// temporary (maybe), used to correct offset for scaled images
|
||||
if (scale != 1) currLeft = currLeft - width / 2 + (width * scale) / 2;
|
||||
|
||||
Menu_DrawImg(currLeft, this->GetTop(), zoffset, width, height, image, imageangle, widescreen ? currScale * Settings.WSFactor
|
||||
: currScale, currScale, this->GetAlpha(), xx1, yy1, xx2, yy2, xx3, yy3, xx4, yy4);
|
||||
}
|
||||
Menu_DrawImg(currLeft, this->GetTop(), zoffset, width, height, image, imageangle, widescreen ? currScale * Settings.WSFactor
|
||||
: currScale, currScale, this->GetAlpha(), xx1, yy1, xx2, yy2, xx3, yy3, xx4, yy4);
|
||||
}
|
||||
|
||||
if (stripe > 0) for (int y = 0; y < this->GetHeight(); y += 6)
|
||||
Menu_DrawRectangle(currLeft, this->GetTop() + y, this->GetWidth(), 3, ( GXColor )
|
||||
{ 0, 0, 0, stripe}, 1);
|
||||
if (stripe > 0) for (int y = 0; y < this->GetHeight(); y += 6)
|
||||
Menu_DrawRectangle(currLeft, this->GetTop() + y, this->GetWidth(), 3, ( GXColor )
|
||||
{ 0, 0, 0, stripe}, 1);
|
||||
|
||||
this->UpdateEffects();
|
||||
this->UpdateEffects();
|
||||
}
|
||||
|
|
|
@ -16,134 +16,134 @@ bool GuiImageAsync::CloseThread = false;
|
|||
|
||||
static inline void * memdup(const void* src, size_t len)
|
||||
{
|
||||
if(!src) return NULL;
|
||||
if(!src) return NULL;
|
||||
|
||||
void *dst = malloc(len);
|
||||
if (dst) memcpy(dst, src, len);
|
||||
return dst;
|
||||
void *dst = malloc(len);
|
||||
if (dst) memcpy(dst, src, len);
|
||||
return dst;
|
||||
}
|
||||
|
||||
static GuiImageData * StdImageLoaderCallback(void *arg)
|
||||
{
|
||||
return new GuiImageData((char *) arg);
|
||||
return new GuiImageData((char *) arg);
|
||||
}
|
||||
|
||||
GuiImageAsync::GuiImageAsync(const char *Filename, GuiImageData * PreloadImg) :
|
||||
GuiImage(PreloadImg), imgData(NULL), callback(StdImageLoaderCallback), arg(strdup(Filename))
|
||||
GuiImage(PreloadImg), imgData(NULL), callback(StdImageLoaderCallback), arg(strdup(Filename))
|
||||
{
|
||||
ThreadInit();
|
||||
ThreadAddImage(this);
|
||||
ThreadInit();
|
||||
ThreadAddImage(this);
|
||||
}
|
||||
|
||||
GuiImageAsync::GuiImageAsync(ImageLoaderCallback Callback, const void * Arg, int ArgLen, GuiImageData * PreloadImg) :
|
||||
GuiImage(PreloadImg), imgData(NULL), callback(Callback), arg(memdup(Arg, ArgLen))
|
||||
GuiImage(PreloadImg), imgData(NULL), callback(Callback), arg(memdup(Arg, ArgLen))
|
||||
{
|
||||
ThreadInit();
|
||||
ThreadAddImage(this);
|
||||
ThreadInit();
|
||||
ThreadAddImage(this);
|
||||
}
|
||||
|
||||
GuiImageAsync::~GuiImageAsync()
|
||||
{
|
||||
ThreadRemoveImage(this);
|
||||
ThreadExit();
|
||||
while(InUse == this) usleep(100);
|
||||
if (imgData) delete imgData;
|
||||
if (arg) free(arg);
|
||||
ThreadRemoveImage(this);
|
||||
ThreadExit();
|
||||
while(InUse == this) usleep(100);
|
||||
if (imgData) delete imgData;
|
||||
if (arg) free(arg);
|
||||
}
|
||||
|
||||
void GuiImageAsync::ThreadAddImage(GuiImageAsync *Image)
|
||||
{
|
||||
LWP_MutexLock(ListLock);
|
||||
List.push_back(Image);
|
||||
LWP_MutexUnlock(ListLock);
|
||||
ThreadSleep = false;
|
||||
LWP_ResumeThread(Thread);
|
||||
LWP_MutexLock(ListLock);
|
||||
List.push_back(Image);
|
||||
LWP_MutexUnlock(ListLock);
|
||||
ThreadSleep = false;
|
||||
LWP_ResumeThread(Thread);
|
||||
}
|
||||
|
||||
void GuiImageAsync::ThreadRemoveImage(GuiImageAsync *Image)
|
||||
{
|
||||
for(u32 i = 0; i < List.size(); ++i)
|
||||
{
|
||||
if(List[i] == Image)
|
||||
{
|
||||
LWP_MutexLock(ListLock);
|
||||
List.erase(List.begin()+i);
|
||||
LWP_MutexUnlock(ListLock);
|
||||
break;
|
||||
}
|
||||
}
|
||||
for(u32 i = 0; i < List.size(); ++i)
|
||||
{
|
||||
if(List[i] == Image)
|
||||
{
|
||||
LWP_MutexLock(ListLock);
|
||||
List.erase(List.begin()+i);
|
||||
LWP_MutexUnlock(ListLock);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GuiImageAsync::ClearQueue()
|
||||
{
|
||||
LWP_MutexLock(ListLock);
|
||||
List.clear();
|
||||
LWP_MutexUnlock(ListLock);
|
||||
LWP_MutexLock(ListLock);
|
||||
List.clear();
|
||||
LWP_MutexUnlock(ListLock);
|
||||
}
|
||||
|
||||
void * GuiImageAsync::GuiImageAsyncThread(void *arg)
|
||||
{
|
||||
while(!CloseThread)
|
||||
{
|
||||
if(ThreadSleep)
|
||||
LWP_SuspendThread(Thread);
|
||||
while(!CloseThread)
|
||||
{
|
||||
if(ThreadSleep)
|
||||
LWP_SuspendThread(Thread);
|
||||
|
||||
while(!List.empty() && !CloseThread)
|
||||
{
|
||||
LWP_MutexLock(ListLock);
|
||||
InUse = List.front();
|
||||
List.erase(List.begin());
|
||||
LWP_MutexUnlock(ListLock);
|
||||
while(!List.empty() && !CloseThread)
|
||||
{
|
||||
LWP_MutexLock(ListLock);
|
||||
InUse = List.front();
|
||||
List.erase(List.begin());
|
||||
LWP_MutexUnlock(ListLock);
|
||||
|
||||
if (!InUse)
|
||||
continue;
|
||||
if (!InUse)
|
||||
continue;
|
||||
|
||||
InUse->imgData = InUse->callback(InUse->arg);
|
||||
InUse->imgData = InUse->callback(InUse->arg);
|
||||
|
||||
if (InUse->imgData && InUse->imgData->GetImage())
|
||||
{
|
||||
InUse->width = InUse->imgData->GetWidth();
|
||||
InUse->height = InUse->imgData->GetHeight();
|
||||
InUse->image = InUse->imgData->GetImage();
|
||||
}
|
||||
if (InUse->imgData && InUse->imgData->GetImage())
|
||||
{
|
||||
InUse->width = InUse->imgData->GetWidth();
|
||||
InUse->height = InUse->imgData->GetHeight();
|
||||
InUse->image = InUse->imgData->GetImage();
|
||||
}
|
||||
|
||||
InUse = NULL;
|
||||
}
|
||||
InUse = NULL;
|
||||
}
|
||||
|
||||
ThreadSleep = true;
|
||||
}
|
||||
ThreadSleep = true;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
u32 GuiImageAsync::ThreadInit()
|
||||
{
|
||||
if (Thread == LWP_THREAD_NULL)
|
||||
{
|
||||
LWP_MutexInit(&ListLock, false);
|
||||
LWP_CreateThread(&Thread, GuiImageAsyncThread, NULL, NULL, 32768, 80);
|
||||
}
|
||||
return ++ThreadCount;
|
||||
if (Thread == LWP_THREAD_NULL)
|
||||
{
|
||||
LWP_MutexInit(&ListLock, false);
|
||||
LWP_CreateThread(&Thread, GuiImageAsyncThread, NULL, NULL, 32768, 80);
|
||||
}
|
||||
return ++ThreadCount;
|
||||
}
|
||||
|
||||
u32 GuiImageAsync::ThreadExit()
|
||||
{
|
||||
//! We don't need to always shutdown and startup the thread, especially
|
||||
//! since this is a nested startup/shutdown from the gui thread.
|
||||
//! It's fine with being put to suspended only.
|
||||
/*
|
||||
if (--ThreadCount == 0)
|
||||
{
|
||||
CloseThread = true;
|
||||
LWP_ResumeThread(Thread);
|
||||
LWP_JoinThread(Thread, NULL);
|
||||
LWP_MutexUnlock(ListLock);
|
||||
LWP_MutexDestroy(ListLock);
|
||||
Thread = LWP_THREAD_NULL;
|
||||
ListLock = LWP_MUTEX_NULL;
|
||||
ListLock = LWP_MUTEX_NULL;
|
||||
}
|
||||
*/
|
||||
return --ThreadCount;
|
||||
//! We don't need to always shutdown and startup the thread, especially
|
||||
//! since this is a nested startup/shutdown from the gui thread.
|
||||
//! It's fine with being put to suspended only.
|
||||
/*
|
||||
if (--ThreadCount == 0)
|
||||
{
|
||||
CloseThread = true;
|
||||
LWP_ResumeThread(Thread);
|
||||
LWP_JoinThread(Thread, NULL);
|
||||
LWP_MutexUnlock(ListLock);
|
||||
LWP_MutexDestroy(ListLock);
|
||||
Thread = LWP_THREAD_NULL;
|
||||
ListLock = LWP_MUTEX_NULL;
|
||||
ListLock = LWP_MUTEX_NULL;
|
||||
}
|
||||
*/
|
||||
return --ThreadCount;
|
||||
}
|
||||
|
||||
|
|
|
@ -8,30 +8,30 @@ typedef GuiImageData * (*ImageLoaderCallback)(void *arg);
|
|||
|
||||
class GuiImageAsync: public GuiImage
|
||||
{
|
||||
public:
|
||||
GuiImageAsync(const char *Filename, GuiImageData * PreloadImg);
|
||||
GuiImageAsync(ImageLoaderCallback Callback, const void *Arg, int ArgLen, GuiImageData * PreloadImg);
|
||||
virtual ~GuiImageAsync();
|
||||
public:
|
||||
GuiImageAsync(const char *Filename, GuiImageData * PreloadImg);
|
||||
GuiImageAsync(ImageLoaderCallback Callback, const void *Arg, int ArgLen, GuiImageData * PreloadImg);
|
||||
virtual ~GuiImageAsync();
|
||||
|
||||
static void ClearQueue();
|
||||
private:
|
||||
GuiImageData *imgData;
|
||||
ImageLoaderCallback callback;
|
||||
void *arg;
|
||||
static void ClearQueue();
|
||||
private:
|
||||
GuiImageData *imgData;
|
||||
ImageLoaderCallback callback;
|
||||
void *arg;
|
||||
|
||||
static void * GuiImageAsyncThread(void *arg);
|
||||
static void ThreadAddImage(GuiImageAsync* Image);
|
||||
static void ThreadRemoveImage(GuiImageAsync* Image);
|
||||
static u32 ThreadInit();
|
||||
static u32 ThreadExit();
|
||||
static void * GuiImageAsyncThread(void *arg);
|
||||
static void ThreadAddImage(GuiImageAsync* Image);
|
||||
static void ThreadRemoveImage(GuiImageAsync* Image);
|
||||
static u32 ThreadInit();
|
||||
static u32 ThreadExit();
|
||||
|
||||
static std::vector<GuiImageAsync *> List;
|
||||
static lwp_t Thread;
|
||||
static mutex_t ListLock;
|
||||
static GuiImageAsync * InUse;
|
||||
static u32 ThreadCount;
|
||||
static bool ThreadSleep;
|
||||
static bool CloseThread;
|
||||
static std::vector<GuiImageAsync *> List;
|
||||
static lwp_t Thread;
|
||||
static mutex_t ListLock;
|
||||
static GuiImageAsync * InUse;
|
||||
static u32 ThreadCount;
|
||||
static bool ThreadSleep;
|
||||
static bool CloseThread;
|
||||
};
|
||||
|
||||
#endif /*_GUIIMAGEASYNC_H_*/
|
||||
|
|
|
@ -41,16 +41,16 @@ GuiImageData::GuiImageData(const char * filepath)
|
|||
height = 0;
|
||||
format = GX_TF_RGBA8;
|
||||
|
||||
u8 *buffer = NULL;
|
||||
u64 size = 0;
|
||||
u8 *buffer = NULL;
|
||||
u64 size = 0;
|
||||
|
||||
if(LoadFileToMem(filepath, &buffer, &size) < 0)
|
||||
return;
|
||||
if(LoadFileToMem(filepath, &buffer, &size) < 0)
|
||||
return;
|
||||
|
||||
LoadImage(buffer, size);
|
||||
LoadImage(buffer, size);
|
||||
|
||||
if(buffer)
|
||||
free(buffer);
|
||||
if(buffer)
|
||||
free(buffer);
|
||||
}
|
||||
|
||||
GuiImageData::GuiImageData(const u8 * img, int imgSize, bool cache)
|
||||
|
@ -60,30 +60,30 @@ GuiImageData::GuiImageData(const u8 * img, int imgSize, bool cache)
|
|||
height = 0;
|
||||
format = GX_TF_RGBA8;
|
||||
|
||||
if(cache)
|
||||
{
|
||||
ImageData * Image = ResourceManager::GetImageData(img);
|
||||
if(Image != NULL && Image->data != NULL)
|
||||
{
|
||||
data = Image->data;
|
||||
width = Image->width;
|
||||
height = Image->height;
|
||||
format = Image->format;
|
||||
return;
|
||||
}
|
||||
}
|
||||
if(cache)
|
||||
{
|
||||
ImageData * Image = ResourceManager::GetImageData(img);
|
||||
if(Image != NULL && Image->data != NULL)
|
||||
{
|
||||
data = Image->data;
|
||||
width = Image->width;
|
||||
height = Image->height;
|
||||
format = Image->format;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
LoadImage(img, imgSize);
|
||||
LoadImage(img, imgSize);
|
||||
|
||||
if(data && cache)
|
||||
{
|
||||
ImageData NewImage;
|
||||
NewImage.data = data;
|
||||
NewImage.width = width;
|
||||
NewImage.height = height;
|
||||
NewImage.format = format;
|
||||
ResourceManager::AddImageData(img, NewImage);
|
||||
}
|
||||
if(data && cache)
|
||||
{
|
||||
ImageData NewImage;
|
||||
NewImage.data = data;
|
||||
NewImage.width = width;
|
||||
NewImage.height = height;
|
||||
NewImage.format = format;
|
||||
ResourceManager::AddImageData(img, NewImage);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -91,105 +91,105 @@ GuiImageData::GuiImageData(const u8 * img, int imgSize, bool cache)
|
|||
*/
|
||||
GuiImageData::~GuiImageData()
|
||||
{
|
||||
if(data)
|
||||
ResourceManager::Remove(data);
|
||||
if(data)
|
||||
ResourceManager::Remove(data);
|
||||
}
|
||||
|
||||
void GuiImageData::LoadImage(const u8 * img, int imgSize)
|
||||
{
|
||||
if(!img)
|
||||
return;
|
||||
return;
|
||||
|
||||
else if (imgSize < 8)
|
||||
{
|
||||
return;
|
||||
}
|
||||
else if (img[0] == 0x89 && img[1] == 'P' && img[2] == 'N' && img[3] == 'G')
|
||||
{
|
||||
// IMAGE_PNG
|
||||
LoadPNG(img, imgSize);
|
||||
}
|
||||
else if (img[0] == 0xFF && img[1] == 0xD8)
|
||||
{
|
||||
// IMAGE_JPEG
|
||||
LoadJpeg(img, imgSize);
|
||||
}
|
||||
else if (img[0] == 'B' && img[1] == 'M')
|
||||
{
|
||||
// IMAGE_BMP
|
||||
LoadBMP(img, imgSize);
|
||||
}
|
||||
else if (img[0] == 'G' && img[1] == 'I' && img[2] == 'F')
|
||||
{
|
||||
// IMAGE_GIF
|
||||
LoadGIF(img, imgSize);
|
||||
}
|
||||
else if (img[0] == 0x00 && img[1] == 0x20 && img[2] == 0xAF && img[3] == 0x30)
|
||||
{
|
||||
// IMAGE_TPL
|
||||
LoadTPL(img, imgSize);
|
||||
}
|
||||
else if (imgSize < 8)
|
||||
{
|
||||
return;
|
||||
}
|
||||
else if (img[0] == 0x89 && img[1] == 'P' && img[2] == 'N' && img[3] == 'G')
|
||||
{
|
||||
// IMAGE_PNG
|
||||
LoadPNG(img, imgSize);
|
||||
}
|
||||
else if (img[0] == 0xFF && img[1] == 0xD8)
|
||||
{
|
||||
// IMAGE_JPEG
|
||||
LoadJpeg(img, imgSize);
|
||||
}
|
||||
else if (img[0] == 'B' && img[1] == 'M')
|
||||
{
|
||||
// IMAGE_BMP
|
||||
LoadBMP(img, imgSize);
|
||||
}
|
||||
else if (img[0] == 'G' && img[1] == 'I' && img[2] == 'F')
|
||||
{
|
||||
// IMAGE_GIF
|
||||
LoadGIF(img, imgSize);
|
||||
}
|
||||
else if (img[0] == 0x00 && img[1] == 0x20 && img[2] == 0xAF && img[3] == 0x30)
|
||||
{
|
||||
// IMAGE_TPL
|
||||
LoadTPL(img, imgSize);
|
||||
}
|
||||
}
|
||||
|
||||
void GuiImageData::LoadPNG(const u8 *img, int imgSize)
|
||||
{
|
||||
gdImagePtr gdImg = gdImageCreateFromPngPtr(imgSize, (u8*) img);
|
||||
if(gdImg == 0)
|
||||
return;
|
||||
gdImagePtr gdImg = gdImageCreateFromPngPtr(imgSize, (u8*) img);
|
||||
if(gdImg == 0)
|
||||
return;
|
||||
|
||||
data = GDImageToRGBA8(&gdImg, &width, &height);
|
||||
gdImageDestroy(gdImg);
|
||||
data = GDImageToRGBA8(&gdImg, &width, &height);
|
||||
gdImageDestroy(gdImg);
|
||||
}
|
||||
|
||||
void GuiImageData::LoadJpeg(const u8 *img, int imgSize)
|
||||
{
|
||||
gdImagePtr gdImg = gdImageCreateFromJpegPtr(imgSize, (u8*) img);
|
||||
if(gdImg == 0)
|
||||
return;
|
||||
gdImagePtr gdImg = gdImageCreateFromJpegPtr(imgSize, (u8*) img);
|
||||
if(gdImg == 0)
|
||||
return;
|
||||
|
||||
data = GDImageToRGBA8(&gdImg, &width, &height);
|
||||
gdImageDestroy(gdImg);
|
||||
data = GDImageToRGBA8(&gdImg, &width, &height);
|
||||
gdImageDestroy(gdImg);
|
||||
}
|
||||
|
||||
void GuiImageData::LoadGIF(const u8 *img, int imgSize)
|
||||
{
|
||||
gdImagePtr gdImg = gdImageCreateFromGifPtr(imgSize, (u8*) img);
|
||||
if(gdImg == 0)
|
||||
return;
|
||||
gdImagePtr gdImg = gdImageCreateFromGifPtr(imgSize, (u8*) img);
|
||||
if(gdImg == 0)
|
||||
return;
|
||||
|
||||
data = GDImageToRGBA8(&gdImg, &width, &height);
|
||||
gdImageDestroy(gdImg);
|
||||
data = GDImageToRGBA8(&gdImg, &width, &height);
|
||||
gdImageDestroy(gdImg);
|
||||
}
|
||||
|
||||
void GuiImageData::LoadBMP(const u8 *img, int imgSize)
|
||||
{
|
||||
gdImagePtr gdImg = gdImageCreateFromBmpPtr(imgSize, (u8*) img);
|
||||
if(gdImg == 0)
|
||||
return;
|
||||
gdImagePtr gdImg = gdImageCreateFromBmpPtr(imgSize, (u8*) img);
|
||||
if(gdImg == 0)
|
||||
return;
|
||||
|
||||
data = GDImageToRGBA8(&gdImg, &width, &height);
|
||||
gdImageDestroy(gdImg);
|
||||
data = GDImageToRGBA8(&gdImg, &width, &height);
|
||||
gdImageDestroy(gdImg);
|
||||
}
|
||||
|
||||
void GuiImageData::LoadTPL(const u8 *img, int imgSize)
|
||||
{
|
||||
TplImage TplFile(img, imgSize);
|
||||
TplImage TplFile(img, imgSize);
|
||||
|
||||
width = TplFile.GetWidth(0);
|
||||
height = TplFile.GetHeight(0);
|
||||
format = (u8) TplFile.GetFormat(0);
|
||||
width = TplFile.GetWidth(0);
|
||||
height = TplFile.GetHeight(0);
|
||||
format = (u8) TplFile.GetFormat(0);
|
||||
|
||||
const u8 * ImgPtr = TplFile.GetTextureBuffer(0);
|
||||
const u8 * ImgPtr = TplFile.GetTextureBuffer(0);
|
||||
|
||||
if(ImgPtr)
|
||||
{
|
||||
int len = ALIGN32(TplFile.GetTextureSize(0));
|
||||
if(ImgPtr)
|
||||
{
|
||||
int len = ALIGN32(TplFile.GetTextureSize(0));
|
||||
|
||||
data = (u8 *) memalign(32, len);
|
||||
if(!data)
|
||||
return;
|
||||
data = (u8 *) memalign(32, len);
|
||||
if(!data)
|
||||
return;
|
||||
|
||||
memcpy(data, ImgPtr, len);
|
||||
DCFlushRange(data, len);
|
||||
}
|
||||
memcpy(data, ImgPtr, len);
|
||||
DCFlushRange(data, len);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,7 +38,7 @@ class GuiImageData
|
|||
//!\param cache True if the resource manager should cache that address
|
||||
GuiImageData(const u8 * img, int imgSize, bool cache = true);
|
||||
//!Overload
|
||||
GuiImageData(const char * filepath);
|
||||
GuiImageData(const char * filepath);
|
||||
//!Destructor
|
||||
~GuiImageData();
|
||||
//!Gets a pointer to the image data
|
||||
|
@ -53,7 +53,7 @@ class GuiImageData
|
|||
//!Gets the texture format
|
||||
u8 GetTextureFormat() { return format; };
|
||||
protected:
|
||||
void LoadImage(const u8 * img, int imgSize);
|
||||
void LoadImage(const u8 * img, int imgSize);
|
||||
void LoadPNG(const u8 *img, int imgSize);
|
||||
void LoadBMP(const u8 *img, int imgSize);
|
||||
void LoadJpeg(const u8 *img, int imgSize);
|
||||
|
|
|
@ -22,26 +22,26 @@ unsigned int m;
|
|||
//const Key thekeys;
|
||||
GuiKeyboard::GuiKeyboard(char * t, u32 max, int min, int lang)
|
||||
{
|
||||
width = 540;
|
||||
height = 400;
|
||||
shift = 0;
|
||||
caps = 0;
|
||||
alt = 0;
|
||||
alt2 = 0;
|
||||
m = min;
|
||||
int mode = lang;
|
||||
selectable = true;
|
||||
focus = 0; // allow focus
|
||||
alignmentHor = ALIGN_CENTRE;
|
||||
alignmentVert = ALIGN_MIDDLE;
|
||||
kbtextmaxlen = max > sizeof(kbtextstr) ? sizeof(kbtextstr) : max; // limit max up to sizeof(kbtextstr)
|
||||
// strlcpy(kbtextstr, t, kbtextmaxlen);
|
||||
strncpy(kbtextstr, t, kbtextmaxlen); // strncpy is needed to fill the rest with \0
|
||||
kbtextstr[sizeof(kbtextstr) - 1] = 0; // terminate with \0
|
||||
//QWERTY//
|
||||
if (mode == 0)
|
||||
{
|
||||
Key thekeys[4][11] = {
|
||||
width = 540;
|
||||
height = 400;
|
||||
shift = 0;
|
||||
caps = 0;
|
||||
alt = 0;
|
||||
alt2 = 0;
|
||||
m = min;
|
||||
int mode = lang;
|
||||
selectable = true;
|
||||
focus = 0; // allow focus
|
||||
alignmentHor = ALIGN_CENTRE;
|
||||
alignmentVert = ALIGN_MIDDLE;
|
||||
kbtextmaxlen = max > sizeof(kbtextstr) ? sizeof(kbtextstr) : max; // limit max up to sizeof(kbtextstr)
|
||||
// strlcpy(kbtextstr, t, kbtextmaxlen);
|
||||
strncpy(kbtextstr, t, kbtextmaxlen); // strncpy is needed to fill the rest with \0
|
||||
kbtextstr[sizeof(kbtextstr) - 1] = 0; // terminate with \0
|
||||
//QWERTY//
|
||||
if (mode == 0)
|
||||
{
|
||||
Key thekeys[4][11] = {
|
||||
{
|
||||
{ '1', '!', '\0', '\0' },
|
||||
{ '2', '@', '\0', '\0' },
|
||||
|
@ -89,19 +89,19 @@ GuiKeyboard::GuiKeyboard(char * t, u32 max, int min, int lang)
|
|||
{ 'b', 'B', '\0', '\0' },
|
||||
{ 'n', 'N', '\0', '\0' },
|
||||
{ 'm', 'M', '\0', '\0' },
|
||||
{ ',', '<', '\0', '\0' },
|
||||
{ ',', '<', '\0', '\0' },
|
||||
{ '.', '>', '\0', '\0' },
|
||||
{ '/', '?', '\0', '\0' },
|
||||
{ '\0', '\0', '\0', '\0' }
|
||||
}
|
||||
};
|
||||
|
||||
memcpy(keys, thekeys, sizeof(thekeys));
|
||||
}
|
||||
//DVORAK//
|
||||
if (mode == 1)
|
||||
{
|
||||
Key thekeys[4][11] = {
|
||||
memcpy(keys, thekeys, sizeof(thekeys));
|
||||
}
|
||||
//DVORAK//
|
||||
if (mode == 1)
|
||||
{
|
||||
Key thekeys[4][11] = {
|
||||
{
|
||||
{ '1', '!', '\0', '\0' },
|
||||
{ '2', '@', '\0', '\0' },
|
||||
|
@ -155,263 +155,263 @@ GuiKeyboard::GuiKeyboard(char * t, u32 max, int min, int lang)
|
|||
{ '\0', '\0', '\0', '\0' }
|
||||
}
|
||||
};
|
||||
memcpy(keys, thekeys, sizeof(thekeys));
|
||||
}
|
||||
//QWETRZ//
|
||||
if (mode == 2)
|
||||
{
|
||||
Key thekeys[4][11] = { { { '1', '!', '^', 'À' }, { '2', '"', '²', 'à' }, { '3', '#', '³', 'È' }, { '4', '$',
|
||||
'«', 'è' }, { '5', '%', '»', 'Ì' }, { '6', '&', '„', 'ì' }, { '7', '/', '”', 'Ò' }, { '8', '(', '[',
|
||||
'ò' }, { '9', ')', ']', 'Ù' }, { '0', '=', '§', 'ù' }, { 'ß', '?', '\'', 'Ý' } }, { { 'q', 'Q', '@',
|
||||
'Á' }, { 'w', 'W', '\0', 'á' }, { 'e', 'E', '€', 'É' }, { 'r', 'R', '\0', 'é' },
|
||||
{ 't', 'T', '\0', 'Í' }, { 'z', 'Z', '\0', 'í' }, { 'u', 'U', '\0', 'Ó' }, { 'i', 'I', '\0', 'ó' }, {
|
||||
'o', 'O', '\0', 'Ú' }, { 'p', 'P', '\0', 'ú' }, { 'ü', 'Ü', '\0', 'ý' } }, { { 'a', 'A', '\0',
|
||||
'Â' }, { 's', 'S', '\0', 'â' }, { 'd', 'D', '\0', 'Ê' }, { 'f', 'F', '\0', 'ê' },
|
||||
{ 'g', 'G', '\0', 'Î' }, { 'h', 'H', '\0', 'î' }, { 'j', 'J', '\0', 'Ô' }, { 'k', 'K', '\0', 'ô' }, {
|
||||
'l', 'L', '\0', 'Û' }, { 'ö', 'Ö', '\0', 'û' }, { 'ä', 'Ä', '\0', 'Ÿ' } }, { { '<', '>', '|',
|
||||
'Ã' }, { 'y', 'Y', '\0', 'ã' }, { 'x', 'X', '\0', 'Ñ' }, { 'c', 'C', 'ç', 'ñ' },
|
||||
{ 'v', 'V', '©', 'Ï' }, { 'b', 'B', '\0', 'ï' }, { 'n', 'N', '\0', 'Õ' }, { 'm', 'M', 'µ', 'õ' }, {
|
||||
',', ';', '\0', 'ÿ' }, { '.', ':', '\0', '\0' }, { '-', '_', '\0', '\0' } } };
|
||||
memcpy(keys, thekeys, sizeof(thekeys));
|
||||
}
|
||||
//AZERTY//
|
||||
if (mode == 3)
|
||||
{
|
||||
Key thekeys[4][11] = { { { '1', '&', '²', 'À' }, { '2', '~', '³', 'é' }, { '3', '"', '#', 'È' }, { '4', '`',
|
||||
'«', 'ù' }, { '5', '(', '[', 'Ì' }, { '6', '-', '|', 'ì' }, { '7', 'µ', '»', 'è' }, { '8', '_', '\'',
|
||||
'ò' }, { '9', '+', '^', 'ç' }, { '0', '=', '@', 'à' }, { '°', ')', ']', 'Ý' } }, {
|
||||
{ 'a', 'A', 'Æ', 'Á' }, { 'z', 'Z', 'Œ', 'á' }, { 'e', 'E', '€', 'É' }, { 'r', 'R', '®', 'ë' }, { 't',
|
||||
'T', '†', 'Í' }, { 'y', 'Y', 'ÿ', 'í' }, { 'u', 'U', 'Õ', 'Ó' }, { 'i', 'I', 'õ', 'Ò' }, { 'o',
|
||||
'O', 'Ø', 'Ú' }, { 'p', 'P', 'ø', 'ú' }, { '$', '£', '¤', 'ý' } }, { { 'q', 'Q', 'æ', 'Â' }, {
|
||||
's', 'S', 'œ', 'â' }, { 'd', 'D', '\0', 'Ê' }, { 'f', 'F', 'ß', 'ê' }, { 'g', 'G', '\0', 'Î' }, { 'h',
|
||||
'H', '\0', 'î' }, { 'j', 'J', '\0', 'Ô' }, { 'k', 'K', '\0', 'ô' }, { 'l', 'L', '\0', 'Û' }, { 'm',
|
||||
'M', '\0', 'û' }, { '*', '%', '¬', 'Ù' } }, { { '<', '>', '\0', 'Ã' }, { 'w', 'W', '\0', 'Ä' }, { 'x',
|
||||
'X', '\0', 'Ë' }, { 'c', 'C', '©', 'Ç' }, { 'v', 'V', '“', 'Ï' }, { 'b', 'B', '”', 'ï' }, { 'n', 'N',
|
||||
'\0', 'Ñ' }, { '?', ',', '?', 'ñ' }, { '.', ';', '.', 'ó' }, { '/', ':', '/', 'ö' }, { '§', '!', '!',
|
||||
'Ö' } } };
|
||||
memcpy(keys, thekeys, sizeof(thekeys));
|
||||
}
|
||||
//QWERTY 2//
|
||||
if (mode == 4)
|
||||
{
|
||||
Key thekeys[4][11] = { { { '1', '!', '|', 'Á' }, { '2', '"', '@', 'á' }, { '3', '·', '#', 'À' }, { '4', '$',
|
||||
'£', 'à' }, { '5', '%', '~', 'É' }, { '6', '&', '¬', 'é' }, { '7', '/', '\'', 'È' }, { '8', '(', '[',
|
||||
'è' }, { '9', ')', ']', 'Í' }, { '0', '=', '¤', 'í' }, { '¡', '?', '¿', 'Ï' } }, { { 'q', 'Q', '\0',
|
||||
'ï' }, { 'w', 'W', '\0', 'Ó' }, { 'e', 'E', '€', 'ó' }, { 'r', 'R', '®', 'Ò' }, { 't', 'T', '†', 'ò' },
|
||||
{ 'y', 'Y', 'ÿ', 'Ú' }, { 'u', 'U', '“', 'ú' }, { 'i', 'I', '”', 'Ü' }, { 'o', 'O', 'Ø', 'ü' }, { 'p',
|
||||
'P', 'ø', 'Ù' }, { '+', '*', '\0', 'ù' } }, { { 'a', 'A', '^', 'Ã' }, { 's', 'S', '²', 'ã' }, {
|
||||
'd', 'D', '³', 'Õ' }, { 'f', 'F', '«', 'õ' }, { 'g', 'G', '»', 'Ñ' }, { 'h', 'H', '§', 'ñ' }, { 'j',
|
||||
'J', 'µ', 'Ç' }, { 'k', 'K', '¤', 'ç' }, { 'l', 'L', '„', '\0' }, { 'ñ', 'Ñ', '+', '\0' }, { 'ç', 'Ç',
|
||||
'°', '\0' } }, { { '<', '>', '\0', 'Ä' }, { 'z', 'Z', '\0', 'ä' }, { 'x', 'X', '\0', 'Â' }, { 'c', 'C',
|
||||
'©', 'â' }, { 'v', 'V', '\0', 'å' }, { 'b', 'B', 'ß', 'Ë' }, { 'n', 'N', '\0', 'ë' }, { 'm', 'M', '\0',
|
||||
'Ê' }, { ',', ';', '\0', 'ê' }, { '.', ':', '\0', '\0' }, { '-', '_', '\0', '\0' } } };
|
||||
memcpy(keys, thekeys, sizeof(thekeys));
|
||||
}
|
||||
memcpy(keys, thekeys, sizeof(thekeys));
|
||||
}
|
||||
//QWETRZ//
|
||||
if (mode == 2)
|
||||
{
|
||||
Key thekeys[4][11] = { { { '1', '!', '^', 'À' }, { '2', '"', '²', 'à' }, { '3', '#', '³', 'È' }, { '4', '$',
|
||||
'«', 'è' }, { '5', '%', '»', 'Ì' }, { '6', '&', '„', 'ì' }, { '7', '/', '”', 'Ò' }, { '8', '(', '[',
|
||||
'ò' }, { '9', ')', ']', 'Ù' }, { '0', '=', '§', 'ù' }, { 'ß', '?', '\'', 'Ý' } }, { { 'q', 'Q', '@',
|
||||
'Á' }, { 'w', 'W', '\0', 'á' }, { 'e', 'E', '€', 'É' }, { 'r', 'R', '\0', 'é' },
|
||||
{ 't', 'T', '\0', 'Í' }, { 'z', 'Z', '\0', 'í' }, { 'u', 'U', '\0', 'Ó' }, { 'i', 'I', '\0', 'ó' }, {
|
||||
'o', 'O', '\0', 'Ú' }, { 'p', 'P', '\0', 'ú' }, { 'ü', 'Ü', '\0', 'ý' } }, { { 'a', 'A', '\0',
|
||||
'Â' }, { 's', 'S', '\0', 'â' }, { 'd', 'D', '\0', 'Ê' }, { 'f', 'F', '\0', 'ê' },
|
||||
{ 'g', 'G', '\0', 'Î' }, { 'h', 'H', '\0', 'î' }, { 'j', 'J', '\0', 'Ô' }, { 'k', 'K', '\0', 'ô' }, {
|
||||
'l', 'L', '\0', 'Û' }, { 'ö', 'Ö', '\0', 'û' }, { 'ä', 'Ä', '\0', 'Ÿ' } }, { { '<', '>', '|',
|
||||
'Ã' }, { 'y', 'Y', '\0', 'ã' }, { 'x', 'X', '\0', 'Ñ' }, { 'c', 'C', 'ç', 'ñ' },
|
||||
{ 'v', 'V', '©', 'Ï' }, { 'b', 'B', '\0', 'ï' }, { 'n', 'N', '\0', 'Õ' }, { 'm', 'M', 'µ', 'õ' }, {
|
||||
',', ';', '\0', 'ÿ' }, { '.', ':', '\0', '\0' }, { '-', '_', '\0', '\0' } } };
|
||||
memcpy(keys, thekeys, sizeof(thekeys));
|
||||
}
|
||||
//AZERTY//
|
||||
if (mode == 3)
|
||||
{
|
||||
Key thekeys[4][11] = { { { '1', '&', '²', 'À' }, { '2', '~', '³', 'é' }, { '3', '"', '#', 'È' }, { '4', '`',
|
||||
'«', 'ù' }, { '5', '(', '[', 'Ì' }, { '6', '-', '|', 'ì' }, { '7', 'µ', '»', 'è' }, { '8', '_', '\'',
|
||||
'ò' }, { '9', '+', '^', 'ç' }, { '0', '=', '@', 'à' }, { '°', ')', ']', 'Ý' } }, {
|
||||
{ 'a', 'A', 'Æ', 'Á' }, { 'z', 'Z', 'Œ', 'á' }, { 'e', 'E', '€', 'É' }, { 'r', 'R', '®', 'ë' }, { 't',
|
||||
'T', '†', 'Í' }, { 'y', 'Y', 'ÿ', 'í' }, { 'u', 'U', 'Õ', 'Ó' }, { 'i', 'I', 'õ', 'Ò' }, { 'o',
|
||||
'O', 'Ø', 'Ú' }, { 'p', 'P', 'ø', 'ú' }, { '$', '£', '¤', 'ý' } }, { { 'q', 'Q', 'æ', 'Â' }, {
|
||||
's', 'S', 'œ', 'â' }, { 'd', 'D', '\0', 'Ê' }, { 'f', 'F', 'ß', 'ê' }, { 'g', 'G', '\0', 'Î' }, { 'h',
|
||||
'H', '\0', 'î' }, { 'j', 'J', '\0', 'Ô' }, { 'k', 'K', '\0', 'ô' }, { 'l', 'L', '\0', 'Û' }, { 'm',
|
||||
'M', '\0', 'û' }, { '*', '%', '¬', 'Ù' } }, { { '<', '>', '\0', 'Ã' }, { 'w', 'W', '\0', 'Ä' }, { 'x',
|
||||
'X', '\0', 'Ë' }, { 'c', 'C', '©', 'Ç' }, { 'v', 'V', '“', 'Ï' }, { 'b', 'B', '”', 'ï' }, { 'n', 'N',
|
||||
'\0', 'Ñ' }, { '?', ',', '?', 'ñ' }, { '.', ';', '.', 'ó' }, { '/', ':', '/', 'ö' }, { '§', '!', '!',
|
||||
'Ö' } } };
|
||||
memcpy(keys, thekeys, sizeof(thekeys));
|
||||
}
|
||||
//QWERTY 2//
|
||||
if (mode == 4)
|
||||
{
|
||||
Key thekeys[4][11] = { { { '1', '!', '|', 'Á' }, { '2', '"', '@', 'á' }, { '3', '·', '#', 'À' }, { '4', '$',
|
||||
'£', 'à' }, { '5', '%', '~', 'É' }, { '6', '&', '¬', 'é' }, { '7', '/', '\'', 'È' }, { '8', '(', '[',
|
||||
'è' }, { '9', ')', ']', 'Í' }, { '0', '=', '¤', 'í' }, { '¡', '?', '¿', 'Ï' } }, { { 'q', 'Q', '\0',
|
||||
'ï' }, { 'w', 'W', '\0', 'Ó' }, { 'e', 'E', '€', 'ó' }, { 'r', 'R', '®', 'Ò' }, { 't', 'T', '†', 'ò' },
|
||||
{ 'y', 'Y', 'ÿ', 'Ú' }, { 'u', 'U', '“', 'ú' }, { 'i', 'I', '”', 'Ü' }, { 'o', 'O', 'Ø', 'ü' }, { 'p',
|
||||
'P', 'ø', 'Ù' }, { '+', '*', '\0', 'ù' } }, { { 'a', 'A', '^', 'Ã' }, { 's', 'S', '²', 'ã' }, {
|
||||
'd', 'D', '³', 'Õ' }, { 'f', 'F', '«', 'õ' }, { 'g', 'G', '»', 'Ñ' }, { 'h', 'H', '§', 'ñ' }, { 'j',
|
||||
'J', 'µ', 'Ç' }, { 'k', 'K', '¤', 'ç' }, { 'l', 'L', '„', '\0' }, { 'ñ', 'Ñ', '+', '\0' }, { 'ç', 'Ç',
|
||||
'°', '\0' } }, { { '<', '>', '\0', 'Ä' }, { 'z', 'Z', '\0', 'ä' }, { 'x', 'X', '\0', 'Â' }, { 'c', 'C',
|
||||
'©', 'â' }, { 'v', 'V', '\0', 'å' }, { 'b', 'B', 'ß', 'Ë' }, { 'n', 'N', '\0', 'ë' }, { 'm', 'M', '\0',
|
||||
'Ê' }, { ',', ';', '\0', 'ê' }, { '.', ':', '\0', '\0' }, { '-', '_', '\0', '\0' } } };
|
||||
memcpy(keys, thekeys, sizeof(thekeys));
|
||||
}
|
||||
|
||||
keyTextbox = Resources::GetImageData("keyboard_textbox.png");
|
||||
keyTextboxImg = new GuiImage(keyTextbox);
|
||||
keyTextboxImg->SetAlignment(ALIGN_CENTRE, ALIGN_TOP);
|
||||
keyTextboxImg->SetPosition(0, 40);//(0,0);
|
||||
this->Append(keyTextboxImg);
|
||||
keyTextbox = Resources::GetImageData("keyboard_textbox.png");
|
||||
keyTextboxImg = new GuiImage(keyTextbox);
|
||||
keyTextboxImg->SetAlignment(ALIGN_CENTRE, ALIGN_TOP);
|
||||
keyTextboxImg->SetPosition(0, 40);//(0,0);
|
||||
this->Append(keyTextboxImg);
|
||||
|
||||
kbText = new GuiText(kbtextstr, 20, ( GXColor )
|
||||
{ 0, 0, 0, 0xff});
|
||||
kbText->SetAlignment(ALIGN_CENTRE, ALIGN_TOP);
|
||||
kbText->SetPosition(0, 53);//(0, 13);
|
||||
this->Append(kbText);
|
||||
kbText = new GuiText(kbtextstr, 20, ( GXColor )
|
||||
{ 0, 0, 0, 0xff});
|
||||
kbText->SetAlignment(ALIGN_CENTRE, ALIGN_TOP);
|
||||
kbText->SetPosition(0, 53);//(0, 13);
|
||||
this->Append(kbText);
|
||||
|
||||
key = Resources::GetImageData("keyboard_key.png");
|
||||
keyOver = Resources::GetImageData("keyboard_key_over.png");
|
||||
keyMedium = Resources::GetImageData("keyboard_mediumkey_over.png");
|
||||
keyLarge = Resources::GetImageData("keyboard_largekey_over.png");
|
||||
key = Resources::GetImageData("keyboard_key.png");
|
||||
keyOver = Resources::GetImageData("keyboard_key_over.png");
|
||||
keyMedium = Resources::GetImageData("keyboard_mediumkey_over.png");
|
||||
keyLarge = Resources::GetImageData("keyboard_largekey_over.png");
|
||||
|
||||
trigA = new GuiTrigger;
|
||||
trigA->SetSimpleTrigger(-1, WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A, PAD_BUTTON_A);
|
||||
trigB = new GuiTrigger;
|
||||
trigB->SetButtonOnlyTrigger(-1, WPAD_BUTTON_B | WPAD_CLASSIC_BUTTON_B, PAD_BUTTON_B);
|
||||
trigA = new GuiTrigger;
|
||||
trigA->SetSimpleTrigger(-1, WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A, PAD_BUTTON_A);
|
||||
trigB = new GuiTrigger;
|
||||
trigB->SetButtonOnlyTrigger(-1, WPAD_BUTTON_B | WPAD_CLASSIC_BUTTON_B, PAD_BUTTON_B);
|
||||
|
||||
int eurocheck = 0;
|
||||
if (mode > 1)
|
||||
{
|
||||
eurocheck = -20;
|
||||
}
|
||||
int eurocheck = 0;
|
||||
if (mode > 1)
|
||||
{
|
||||
eurocheck = -20;
|
||||
}
|
||||
|
||||
keyBackImg = new GuiImage(keyMedium);
|
||||
keyBackOverImg = new GuiImage(keyMedium);
|
||||
if (mode == 3)
|
||||
{
|
||||
keyBackText = new GuiText("Retour", 20, ( GXColor )
|
||||
{ 0, 0, 0, 0xff});
|
||||
}
|
||||
else
|
||||
{
|
||||
keyBackText = new GuiText("Back", 20, ( GXColor )
|
||||
{ 0, 0, 0, 0xff});
|
||||
}
|
||||
//keyBack = new GuiButton(keyMedium->GetWidth(), keyMedium->GetHeight());
|
||||
keyBack = new GuiButton(keyBackImg, keyBackOverImg, 0, 3, 11 * 42 + 40 + eurocheck, 0 * 42 + 120, trigA,
|
||||
btnSoundOver, btnSoundClick, 1);
|
||||
//keyBack->SetImage(keyBackImg);
|
||||
//keyBack->SetImageOver(keyBackOverImg);
|
||||
keyBack->SetLabel(keyBackText);
|
||||
//keyBack->SetSoundOver(btnSoundOver);
|
||||
//keyBack->SetSoundClick(btnSoundClick);
|
||||
//keyBack->SetTrigger(trigA);
|
||||
keyBack->SetTrigger(trigB);
|
||||
if (mode > 1)
|
||||
{
|
||||
keyBack->SetPosition(11 * 42 + 40 + eurocheck, 0 * 42 + 120);
|
||||
}
|
||||
else
|
||||
{
|
||||
keyBack->SetPosition(10 * 42 + 40 + eurocheck, 0 * 42 + 120);
|
||||
}//(10*42+40, 0*42+80);
|
||||
//keyBack->SetEffectGrow();
|
||||
this->Append(keyBack);
|
||||
keyBackImg = new GuiImage(keyMedium);
|
||||
keyBackOverImg = new GuiImage(keyMedium);
|
||||
if (mode == 3)
|
||||
{
|
||||
keyBackText = new GuiText("Retour", 20, ( GXColor )
|
||||
{ 0, 0, 0, 0xff});
|
||||
}
|
||||
else
|
||||
{
|
||||
keyBackText = new GuiText("Back", 20, ( GXColor )
|
||||
{ 0, 0, 0, 0xff});
|
||||
}
|
||||
//keyBack = new GuiButton(keyMedium->GetWidth(), keyMedium->GetHeight());
|
||||
keyBack = new GuiButton(keyBackImg, keyBackOverImg, 0, 3, 11 * 42 + 40 + eurocheck, 0 * 42 + 120, trigA,
|
||||
btnSoundOver, btnSoundClick, 1);
|
||||
//keyBack->SetImage(keyBackImg);
|
||||
//keyBack->SetImageOver(keyBackOverImg);
|
||||
keyBack->SetLabel(keyBackText);
|
||||
//keyBack->SetSoundOver(btnSoundOver);
|
||||
//keyBack->SetSoundClick(btnSoundClick);
|
||||
//keyBack->SetTrigger(trigA);
|
||||
keyBack->SetTrigger(trigB);
|
||||
if (mode > 1)
|
||||
{
|
||||
keyBack->SetPosition(11 * 42 + 40 + eurocheck, 0 * 42 + 120);
|
||||
}
|
||||
else
|
||||
{
|
||||
keyBack->SetPosition(10 * 42 + 40 + eurocheck, 0 * 42 + 120);
|
||||
}//(10*42+40, 0*42+80);
|
||||
//keyBack->SetEffectGrow();
|
||||
this->Append(keyBack);
|
||||
|
||||
keyClearImg = new GuiImage(keyMedium);
|
||||
keyClearOverImg = new GuiImage(keyMedium);
|
||||
if (mode == 3)
|
||||
{
|
||||
keyClearText = new GuiText("Effacer", 20, ( GXColor )
|
||||
{ 0, 0, 0, 0xff});
|
||||
}
|
||||
else
|
||||
{
|
||||
keyClearText = new GuiText("Clear", 20, ( GXColor )
|
||||
{ 0, 0, 0, 0xff});
|
||||
}
|
||||
keyClear = new GuiButton(keyClearImg, keyClearOverImg, 0, 3, (10 * 42 + 40) + eurocheck, 4 * 42 + 120, trigA,
|
||||
btnSoundOver, btnSoundClick, 1);
|
||||
//keyClear = new GuiButton(keyMedium->GetWidth(), keyMedium->GetHeight());
|
||||
//keyClear->SetImage(keyClearImg);
|
||||
//keyClear->SetImageOver(keyClearOverImg);
|
||||
keyClear->SetLabel(keyClearText);
|
||||
//keyClear->SetSoundOver(btnSoundOver);
|
||||
//keyClear->SetSoundClick(btnSoundClick);
|
||||
//keyClear->SetTrigger(trigA);
|
||||
//keyClear->SetPosition((10*42+40)+eurocheck, 4*42+120);//(10*42+40, 0*42+80);
|
||||
//keyClear->SetEffectGrow();
|
||||
this->Append(keyClear);
|
||||
keyClearImg = new GuiImage(keyMedium);
|
||||
keyClearOverImg = new GuiImage(keyMedium);
|
||||
if (mode == 3)
|
||||
{
|
||||
keyClearText = new GuiText("Effacer", 20, ( GXColor )
|
||||
{ 0, 0, 0, 0xff});
|
||||
}
|
||||
else
|
||||
{
|
||||
keyClearText = new GuiText("Clear", 20, ( GXColor )
|
||||
{ 0, 0, 0, 0xff});
|
||||
}
|
||||
keyClear = new GuiButton(keyClearImg, keyClearOverImg, 0, 3, (10 * 42 + 40) + eurocheck, 4 * 42 + 120, trigA,
|
||||
btnSoundOver, btnSoundClick, 1);
|
||||
//keyClear = new GuiButton(keyMedium->GetWidth(), keyMedium->GetHeight());
|
||||
//keyClear->SetImage(keyClearImg);
|
||||
//keyClear->SetImageOver(keyClearOverImg);
|
||||
keyClear->SetLabel(keyClearText);
|
||||
//keyClear->SetSoundOver(btnSoundOver);
|
||||
//keyClear->SetSoundClick(btnSoundClick);
|
||||
//keyClear->SetTrigger(trigA);
|
||||
//keyClear->SetPosition((10*42+40)+eurocheck, 4*42+120);//(10*42+40, 0*42+80);
|
||||
//keyClear->SetEffectGrow();
|
||||
this->Append(keyClear);
|
||||
|
||||
keyAltImg = new GuiImage(keyMedium);
|
||||
keyAltOverImg = new GuiImage(keyMedium);
|
||||
keyAltText = new GuiText("Alt Gr", 20, ( GXColor )
|
||||
{ 0, 0, 0, 0xff});
|
||||
keyAlt = new GuiButton(keyAltImg, keyAltOverImg, 0, 3, 84 + eurocheck, 4 * 42 + 120, trigA, btnSoundOver,
|
||||
btnSoundClick, 1);
|
||||
//keyAlt = new GuiButton(keyMedium->GetWidth(), keyMedium->GetHeight());
|
||||
//keyAlt->SetImage(keyAltImg);
|
||||
//keyAlt->SetImageOver(keyAltOverImg);
|
||||
keyAlt->SetLabel(keyAltText);
|
||||
//keyAlt->SetSoundOver(btnSoundOver);
|
||||
//keyAlt->SetSoundClick(btnSoundClick);
|
||||
//keyAlt->SetTrigger(trigA);
|
||||
//keyAlt->SetPosition(84+eurocheck, 4*42+120);//(10*42+40, 4*42+120);
|
||||
//keyAlt->SetEffectGrow();
|
||||
if (mode > 1)
|
||||
{
|
||||
this->Append(keyAlt);
|
||||
}
|
||||
keyAltImg = new GuiImage(keyMedium);
|
||||
keyAltOverImg = new GuiImage(keyMedium);
|
||||
keyAltText = new GuiText("Alt Gr", 20, ( GXColor )
|
||||
{ 0, 0, 0, 0xff});
|
||||
keyAlt = new GuiButton(keyAltImg, keyAltOverImg, 0, 3, 84 + eurocheck, 4 * 42 + 120, trigA, btnSoundOver,
|
||||
btnSoundClick, 1);
|
||||
//keyAlt = new GuiButton(keyMedium->GetWidth(), keyMedium->GetHeight());
|
||||
//keyAlt->SetImage(keyAltImg);
|
||||
//keyAlt->SetImageOver(keyAltOverImg);
|
||||
keyAlt->SetLabel(keyAltText);
|
||||
//keyAlt->SetSoundOver(btnSoundOver);
|
||||
//keyAlt->SetSoundClick(btnSoundClick);
|
||||
//keyAlt->SetTrigger(trigA);
|
||||
//keyAlt->SetPosition(84+eurocheck, 4*42+120);//(10*42+40, 4*42+120);
|
||||
//keyAlt->SetEffectGrow();
|
||||
if (mode > 1)
|
||||
{
|
||||
this->Append(keyAlt);
|
||||
}
|
||||
|
||||
keyAlt2Img = new GuiImage(keyMedium);
|
||||
keyAlt2OverImg = new GuiImage(keyMedium);
|
||||
keyAlt2Text = new GuiText("Accent", 20, ( GXColor )
|
||||
{ 0, 0, 0, 0xff});
|
||||
keyAlt2 = new GuiButton(keyAlt2Img, keyAlt2OverImg, 0, 3, (8 * 42 + 40) + eurocheck, 4 * 42 + 120, trigA,
|
||||
btnSoundOver, btnSoundClick, 1);
|
||||
//keyAlt2 = new GuiButton(keyMedium->GetWidth(), keyMedium->GetHeight());
|
||||
//keyAlt2->SetImage(keyAlt2Img);
|
||||
//keyAlt2->SetImageOver(keyAlt2OverImg);
|
||||
keyAlt2->SetLabel(keyAlt2Text);
|
||||
//keyAlt2->SetSoundOver(btnSoundOver);
|
||||
//keyAlt2->SetSoundClick(btnSoundClick);
|
||||
//keyAlt2->SetTrigger(trigA);
|
||||
//keyAlt2->SetPosition((8*42+40)+eurocheck, 4*42+120);//(10*42+40, 4*42+120);
|
||||
//keyAlt2->SetEffectGrow();
|
||||
if (mode > 1)
|
||||
{
|
||||
this->Append(keyAlt2);
|
||||
}
|
||||
keyAlt2Img = new GuiImage(keyMedium);
|
||||
keyAlt2OverImg = new GuiImage(keyMedium);
|
||||
keyAlt2Text = new GuiText("Accent", 20, ( GXColor )
|
||||
{ 0, 0, 0, 0xff});
|
||||
keyAlt2 = new GuiButton(keyAlt2Img, keyAlt2OverImg, 0, 3, (8 * 42 + 40) + eurocheck, 4 * 42 + 120, trigA,
|
||||
btnSoundOver, btnSoundClick, 1);
|
||||
//keyAlt2 = new GuiButton(keyMedium->GetWidth(), keyMedium->GetHeight());
|
||||
//keyAlt2->SetImage(keyAlt2Img);
|
||||
//keyAlt2->SetImageOver(keyAlt2OverImg);
|
||||
keyAlt2->SetLabel(keyAlt2Text);
|
||||
//keyAlt2->SetSoundOver(btnSoundOver);
|
||||
//keyAlt2->SetSoundClick(btnSoundClick);
|
||||
//keyAlt2->SetTrigger(trigA);
|
||||
//keyAlt2->SetPosition((8*42+40)+eurocheck, 4*42+120);//(10*42+40, 4*42+120);
|
||||
//keyAlt2->SetEffectGrow();
|
||||
if (mode > 1)
|
||||
{
|
||||
this->Append(keyAlt2);
|
||||
}
|
||||
|
||||
keyCapsImg = new GuiImage(keyMedium);
|
||||
keyCapsOverImg = new GuiImage(keyMedium);
|
||||
keyCapsText = new GuiText("Caps", 20, ( GXColor )
|
||||
{ 0, 0, 0, 0xff});
|
||||
keyCaps = new GuiButton(keyCapsImg, keyCapsOverImg, 0, 3, 0 + eurocheck, 2 * 42 + 120, trigA, btnSoundOver,
|
||||
btnSoundClick, 1);
|
||||
//keyCaps = new GuiButton(keyMedium->GetWidth(), keyMedium->GetHeight());
|
||||
//keyCaps->SetImage(keyCapsImg);
|
||||
//keyCaps->SetImageOver(keyCapsOverImg);
|
||||
keyCaps->SetLabel(keyCapsText);
|
||||
//keyCaps->SetSoundOver(btnSoundOver);
|
||||
//keyCaps->SetSoundClick(btnSoundClick);
|
||||
//keyCaps->SetTrigger(trigA);
|
||||
//keyCaps->SetPosition(0+eurocheck, 2*42+120);//(0, 2*42+80);
|
||||
//keyCaps->SetEffectGrow();
|
||||
this->Append(keyCaps);
|
||||
keyCapsImg = new GuiImage(keyMedium);
|
||||
keyCapsOverImg = new GuiImage(keyMedium);
|
||||
keyCapsText = new GuiText("Caps", 20, ( GXColor )
|
||||
{ 0, 0, 0, 0xff});
|
||||
keyCaps = new GuiButton(keyCapsImg, keyCapsOverImg, 0, 3, 0 + eurocheck, 2 * 42 + 120, trigA, btnSoundOver,
|
||||
btnSoundClick, 1);
|
||||
//keyCaps = new GuiButton(keyMedium->GetWidth(), keyMedium->GetHeight());
|
||||
//keyCaps->SetImage(keyCapsImg);
|
||||
//keyCaps->SetImageOver(keyCapsOverImg);
|
||||
keyCaps->SetLabel(keyCapsText);
|
||||
//keyCaps->SetSoundOver(btnSoundOver);
|
||||
//keyCaps->SetSoundClick(btnSoundClick);
|
||||
//keyCaps->SetTrigger(trigA);
|
||||
//keyCaps->SetPosition(0+eurocheck, 2*42+120);//(0, 2*42+80);
|
||||
//keyCaps->SetEffectGrow();
|
||||
this->Append(keyCaps);
|
||||
|
||||
keyShiftImg = new GuiImage(keyMedium);
|
||||
keyShiftOverImg = new GuiImage(keyMedium);
|
||||
keyShiftText = new GuiText("Shift", 20, ( GXColor )
|
||||
{ 0, 0, 0, 0xff});
|
||||
keyShift = new GuiButton(keyShiftImg, keyShiftOverImg, 0, 3, 21 + eurocheck, 3 * 42 + 120, trigA, btnSoundOver,
|
||||
btnSoundClick, 1);
|
||||
//keyShift = new GuiButton(keyMedium->GetWidth(), keyMedium->GetHeight());
|
||||
//keyShift->SetImage(keyShiftImg);
|
||||
//keyShift->SetImageOver(keyShiftOverImg);
|
||||
keyShift->SetLabel(keyShiftText);
|
||||
//keyShift->SetSoundOver(btnSoundOver);
|
||||
//keyShift->SetSoundClick(btnSoundClick);
|
||||
//keyShift->SetTrigger(trigA);
|
||||
//keyShift->SetPosition(21+eurocheck, 3*42+120);//(21, 3*42+80);
|
||||
//keyShift->SetEffectGrow();
|
||||
this->Append(keyShift);
|
||||
keyShiftImg = new GuiImage(keyMedium);
|
||||
keyShiftOverImg = new GuiImage(keyMedium);
|
||||
keyShiftText = new GuiText("Shift", 20, ( GXColor )
|
||||
{ 0, 0, 0, 0xff});
|
||||
keyShift = new GuiButton(keyShiftImg, keyShiftOverImg, 0, 3, 21 + eurocheck, 3 * 42 + 120, trigA, btnSoundOver,
|
||||
btnSoundClick, 1);
|
||||
//keyShift = new GuiButton(keyMedium->GetWidth(), keyMedium->GetHeight());
|
||||
//keyShift->SetImage(keyShiftImg);
|
||||
//keyShift->SetImageOver(keyShiftOverImg);
|
||||
keyShift->SetLabel(keyShiftText);
|
||||
//keyShift->SetSoundOver(btnSoundOver);
|
||||
//keyShift->SetSoundClick(btnSoundClick);
|
||||
//keyShift->SetTrigger(trigA);
|
||||
//keyShift->SetPosition(21+eurocheck, 3*42+120);//(21, 3*42+80);
|
||||
//keyShift->SetEffectGrow();
|
||||
this->Append(keyShift);
|
||||
|
||||
keySpaceImg = new GuiImage(keyLarge);
|
||||
keySpaceOverImg = new GuiImage(keyLarge);
|
||||
keySpace = new GuiButton(keySpaceImg, keySpaceOverImg, 2, 3, 0 + eurocheck, 4 * 42 + 120, trigA, btnSoundOver,
|
||||
btnSoundClick, 1);
|
||||
//keySpace = new GuiButton(keyLarge->GetWidth(), keyLarge->GetHeight());
|
||||
//keySpace->SetImage(keySpaceImg);
|
||||
//keySpace->SetImageOver(keySpaceOverImg);
|
||||
//keySpace->SetSoundOver(btnSoundOver);
|
||||
//keySpace->SetSoundClick(btnSoundClick);
|
||||
//keySpace->SetTrigger(trigA);
|
||||
//keySpace->SetPosition(0+eurocheck, 4*42+120);//(0, 4*42+80);
|
||||
//keySpace->SetAlignment(ALIGN_CENTRE, ALIGN_TOP);
|
||||
//keySpace->SetEffectGrow();
|
||||
this->Append(keySpace);
|
||||
keySpaceImg = new GuiImage(keyLarge);
|
||||
keySpaceOverImg = new GuiImage(keyLarge);
|
||||
keySpace = new GuiButton(keySpaceImg, keySpaceOverImg, 2, 3, 0 + eurocheck, 4 * 42 + 120, trigA, btnSoundOver,
|
||||
btnSoundClick, 1);
|
||||
//keySpace = new GuiButton(keyLarge->GetWidth(), keyLarge->GetHeight());
|
||||
//keySpace->SetImage(keySpaceImg);
|
||||
//keySpace->SetImageOver(keySpaceOverImg);
|
||||
//keySpace->SetSoundOver(btnSoundOver);
|
||||
//keySpace->SetSoundClick(btnSoundClick);
|
||||
//keySpace->SetTrigger(trigA);
|
||||
//keySpace->SetPosition(0+eurocheck, 4*42+120);//(0, 4*42+80);
|
||||
//keySpace->SetAlignment(ALIGN_CENTRE, ALIGN_TOP);
|
||||
//keySpace->SetEffectGrow();
|
||||
this->Append(keySpace);
|
||||
|
||||
char txt[2] = { 0, 0 };
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
for (int j = 0; j < 11; j++)
|
||||
{
|
||||
if (keys[i][j].ch != '\0')
|
||||
{
|
||||
keyImg[i][j] = new GuiImage(key);
|
||||
keyImgOver[i][j] = new GuiImage(keyOver);
|
||||
txt[0] = keys[i][j].ch;
|
||||
keyTxt[i][j] = new GuiText(txt, 20, ( GXColor )
|
||||
{ 0, 0, 0, 0xff});
|
||||
keyTxt[i][j]->SetAlignment(ALIGN_CENTRE, ALIGN_BOTTOM);
|
||||
keyTxt[i][j]->SetPosition(0, -10);
|
||||
keyBtn[i][j] = new GuiButton(keyImg[i][j], keyImgOver[i][j], 0, 3, (j * 42 + 21 * i + 40) + eurocheck,
|
||||
i * 42 + 120, trigA, btnSoundOver, btnSoundClick, 1);
|
||||
//keyBtn[i][j] = new GuiButton(key->GetWidth(), key->GetHeight());
|
||||
//keyBtn[i][j]->SetImage(keyImg[i][j]);
|
||||
//keyBtn[i][j]->SetImageOver(keyImgOver[i][j]);
|
||||
//keyBtn[i][j]->SetSoundOver(btnSoundOver);
|
||||
//keyBtn[i][j]->SetSoundClick(btnSoundClick);
|
||||
//keyBtn[i][j]->SetTrigger(trigA);
|
||||
keyBtn[i][j]->SetLabel(keyTxt[i][j]);
|
||||
//keyBtn[i][j]->SetPosition((j*42+21*i+40)+eurocheck, i*42+120);//SetPosition(j*42+21*i+40, i*42+80);
|
||||
//keyBtn[i][j]->SetEffectGrow();
|
||||
this->Append(keyBtn[i][j]);
|
||||
}
|
||||
}
|
||||
}
|
||||
char txt[2] = { 0, 0 };
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
for (int j = 0; j < 11; j++)
|
||||
{
|
||||
if (keys[i][j].ch != '\0')
|
||||
{
|
||||
keyImg[i][j] = new GuiImage(key);
|
||||
keyImgOver[i][j] = new GuiImage(keyOver);
|
||||
txt[0] = keys[i][j].ch;
|
||||
keyTxt[i][j] = new GuiText(txt, 20, ( GXColor )
|
||||
{ 0, 0, 0, 0xff});
|
||||
keyTxt[i][j]->SetAlignment(ALIGN_CENTRE, ALIGN_BOTTOM);
|
||||
keyTxt[i][j]->SetPosition(0, -10);
|
||||
keyBtn[i][j] = new GuiButton(keyImg[i][j], keyImgOver[i][j], 0, 3, (j * 42 + 21 * i + 40) + eurocheck,
|
||||
i * 42 + 120, trigA, btnSoundOver, btnSoundClick, 1);
|
||||
//keyBtn[i][j] = new GuiButton(key->GetWidth(), key->GetHeight());
|
||||
//keyBtn[i][j]->SetImage(keyImg[i][j]);
|
||||
//keyBtn[i][j]->SetImageOver(keyImgOver[i][j]);
|
||||
//keyBtn[i][j]->SetSoundOver(btnSoundOver);
|
||||
//keyBtn[i][j]->SetSoundClick(btnSoundClick);
|
||||
//keyBtn[i][j]->SetTrigger(trigA);
|
||||
keyBtn[i][j]->SetLabel(keyTxt[i][j]);
|
||||
//keyBtn[i][j]->SetPosition((j*42+21*i+40)+eurocheck, i*42+120);//SetPosition(j*42+21*i+40, i*42+80);
|
||||
//keyBtn[i][j]->SetEffectGrow();
|
||||
this->Append(keyBtn[i][j]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -419,190 +419,190 @@ GuiKeyboard::GuiKeyboard(char * t, u32 max, int min, int lang)
|
|||
*/
|
||||
GuiKeyboard::~GuiKeyboard()
|
||||
{
|
||||
delete kbText;
|
||||
delete keyTextbox;
|
||||
delete keyTextboxImg;
|
||||
delete keyCapsText;
|
||||
delete keyCapsImg;
|
||||
delete keyCapsOverImg;
|
||||
delete keyCaps;
|
||||
delete keyShiftText;
|
||||
delete keyShiftImg;
|
||||
delete keyShiftOverImg;
|
||||
delete keyShift;
|
||||
if (keyAlt)
|
||||
{
|
||||
delete keyAlt;
|
||||
}
|
||||
if (keyAlt2)
|
||||
{
|
||||
delete keyAlt2;
|
||||
}
|
||||
delete keyBackText;
|
||||
delete keyBackImg;
|
||||
delete keyBackOverImg;
|
||||
delete keyBack;
|
||||
delete keySpaceImg;
|
||||
delete keySpaceOverImg;
|
||||
delete keySpace;
|
||||
delete key;
|
||||
delete keyOver;
|
||||
delete keyMedium;
|
||||
delete keyLarge;
|
||||
delete trigA;
|
||||
delete trigB;
|
||||
delete kbText;
|
||||
delete keyTextbox;
|
||||
delete keyTextboxImg;
|
||||
delete keyCapsText;
|
||||
delete keyCapsImg;
|
||||
delete keyCapsOverImg;
|
||||
delete keyCaps;
|
||||
delete keyShiftText;
|
||||
delete keyShiftImg;
|
||||
delete keyShiftOverImg;
|
||||
delete keyShift;
|
||||
if (keyAlt)
|
||||
{
|
||||
delete keyAlt;
|
||||
}
|
||||
if (keyAlt2)
|
||||
{
|
||||
delete keyAlt2;
|
||||
}
|
||||
delete keyBackText;
|
||||
delete keyBackImg;
|
||||
delete keyBackOverImg;
|
||||
delete keyBack;
|
||||
delete keySpaceImg;
|
||||
delete keySpaceOverImg;
|
||||
delete keySpace;
|
||||
delete key;
|
||||
delete keyOver;
|
||||
delete keyMedium;
|
||||
delete keyLarge;
|
||||
delete trigA;
|
||||
delete trigB;
|
||||
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
for (int j = 0; j < 11; j++)
|
||||
{
|
||||
if (keys[i][j].ch != '\0')
|
||||
{
|
||||
delete keyImg[i][j];
|
||||
delete keyImgOver[i][j];
|
||||
delete keyTxt[i][j];
|
||||
delete keyBtn[i][j];
|
||||
}
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
for (int j = 0; j < 11; j++)
|
||||
{
|
||||
if (keys[i][j].ch != '\0')
|
||||
{
|
||||
delete keyImg[i][j];
|
||||
delete keyImgOver[i][j];
|
||||
delete keyTxt[i][j];
|
||||
delete keyBtn[i][j];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GuiKeyboard::Update(GuiTrigger * t)
|
||||
{
|
||||
LOCK( this );
|
||||
if (_elements.size() == 0 || (state == STATE_DISABLED && parentElement)) return;
|
||||
LOCK( this );
|
||||
if (_elements.size() == 0 || (state == STATE_DISABLED && parentElement)) return;
|
||||
|
||||
for (u8 i = 0; i < _elements.size(); i++)
|
||||
{
|
||||
try
|
||||
{
|
||||
_elements.at(i)->Update(t);
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
}
|
||||
}
|
||||
for (u8 i = 0; i < _elements.size(); i++)
|
||||
{
|
||||
try
|
||||
{
|
||||
_elements.at(i)->Update(t);
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
bool changedShiftKey = false;
|
||||
bool changedShiftKey = false;
|
||||
|
||||
if (keySpace->GetState() == STATE_CLICKED)
|
||||
{
|
||||
if (strlen(kbtextstr) < kbtextmaxlen - 1) // -1 --> kbtextmaxlen means with terminating '\0'
|
||||
{
|
||||
kbtextstr[strlen(kbtextstr)] = ' ';
|
||||
kbText->SetText(kbtextstr);
|
||||
}
|
||||
keySpace->SetState(STATE_SELECTED, t->chan);
|
||||
}
|
||||
else if (keyBack->GetState() == STATE_CLICKED)
|
||||
{
|
||||
if (strlen(kbtextstr) > (m))
|
||||
{
|
||||
kbtextstr[strlen(kbtextstr) - 1] = 0;
|
||||
kbText->SetText(kbtextstr);
|
||||
}
|
||||
keyBack->SetState(STATE_SELECTED, t->chan);
|
||||
}
|
||||
else if (keyClear->GetState() == STATE_CLICKED)
|
||||
{
|
||||
while (strlen(kbtextstr) > (m))
|
||||
{
|
||||
kbtextstr[strlen(kbtextstr) - 1] = 0;
|
||||
kbText->SetText(kbtextstr);
|
||||
}
|
||||
keyClear->SetState(STATE_SELECTED, t->chan);
|
||||
}
|
||||
else if (keyShift->GetState() == STATE_CLICKED)
|
||||
{
|
||||
changedShiftKey = true;
|
||||
shift ^= 1;
|
||||
if (alt) alt ^= 1;
|
||||
if (alt2) alt2 ^= 1;
|
||||
keyShift->SetState(STATE_SELECTED, t->chan);
|
||||
}
|
||||
else if (keyAlt->GetState() == STATE_CLICKED)
|
||||
{
|
||||
changedShiftKey = true;
|
||||
alt ^= 1;
|
||||
if (shift) shift ^= 1;
|
||||
if (alt2) alt2 ^= 1;
|
||||
keyAlt->SetState(STATE_SELECTED, t->chan);
|
||||
}
|
||||
else if (keyAlt2->GetState() == STATE_CLICKED)
|
||||
{
|
||||
changedShiftKey = true;
|
||||
alt2 ^= 1;
|
||||
if (shift) shift ^= 1;
|
||||
if (alt) alt ^= 1;
|
||||
keyAlt2->SetState(STATE_SELECTED, t->chan);
|
||||
}
|
||||
else if (keyCaps->GetState() == STATE_CLICKED)
|
||||
{
|
||||
changedShiftKey = true;
|
||||
caps ^= 1;
|
||||
keyCaps->SetState(STATE_SELECTED, t->chan);
|
||||
}
|
||||
if (keySpace->GetState() == STATE_CLICKED)
|
||||
{
|
||||
if (strlen(kbtextstr) < kbtextmaxlen - 1) // -1 --> kbtextmaxlen means with terminating '\0'
|
||||
{
|
||||
kbtextstr[strlen(kbtextstr)] = ' ';
|
||||
kbText->SetText(kbtextstr);
|
||||
}
|
||||
keySpace->SetState(STATE_SELECTED, t->chan);
|
||||
}
|
||||
else if (keyBack->GetState() == STATE_CLICKED)
|
||||
{
|
||||
if (strlen(kbtextstr) > (m))
|
||||
{
|
||||
kbtextstr[strlen(kbtextstr) - 1] = 0;
|
||||
kbText->SetText(kbtextstr);
|
||||
}
|
||||
keyBack->SetState(STATE_SELECTED, t->chan);
|
||||
}
|
||||
else if (keyClear->GetState() == STATE_CLICKED)
|
||||
{
|
||||
while (strlen(kbtextstr) > (m))
|
||||
{
|
||||
kbtextstr[strlen(kbtextstr) - 1] = 0;
|
||||
kbText->SetText(kbtextstr);
|
||||
}
|
||||
keyClear->SetState(STATE_SELECTED, t->chan);
|
||||
}
|
||||
else if (keyShift->GetState() == STATE_CLICKED)
|
||||
{
|
||||
changedShiftKey = true;
|
||||
shift ^= 1;
|
||||
if (alt) alt ^= 1;
|
||||
if (alt2) alt2 ^= 1;
|
||||
keyShift->SetState(STATE_SELECTED, t->chan);
|
||||
}
|
||||
else if (keyAlt->GetState() == STATE_CLICKED)
|
||||
{
|
||||
changedShiftKey = true;
|
||||
alt ^= 1;
|
||||
if (shift) shift ^= 1;
|
||||
if (alt2) alt2 ^= 1;
|
||||
keyAlt->SetState(STATE_SELECTED, t->chan);
|
||||
}
|
||||
else if (keyAlt2->GetState() == STATE_CLICKED)
|
||||
{
|
||||
changedShiftKey = true;
|
||||
alt2 ^= 1;
|
||||
if (shift) shift ^= 1;
|
||||
if (alt) alt ^= 1;
|
||||
keyAlt2->SetState(STATE_SELECTED, t->chan);
|
||||
}
|
||||
else if (keyCaps->GetState() == STATE_CLICKED)
|
||||
{
|
||||
changedShiftKey = true;
|
||||
caps ^= 1;
|
||||
keyCaps->SetState(STATE_SELECTED, t->chan);
|
||||
}
|
||||
|
||||
bool update = false;
|
||||
bool update = false;
|
||||
|
||||
char txt[2] = { 0, 0 };
|
||||
char txt[2] = { 0, 0 };
|
||||
|
||||
do
|
||||
{
|
||||
update = false;
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
for (int j = 0; j < 11; j++)
|
||||
{
|
||||
if (keys[i][j].ch != '\0')
|
||||
{
|
||||
if (shift || caps)
|
||||
txt[0] = keys[i][j].chShift;
|
||||
else if (alt)
|
||||
txt[0] = keys[i][j].chalt;
|
||||
else if (alt2)
|
||||
txt[0] = keys[i][j].chalt2;
|
||||
else txt[0] = keys[i][j].ch;
|
||||
do
|
||||
{
|
||||
update = false;
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
for (int j = 0; j < 11; j++)
|
||||
{
|
||||
if (keys[i][j].ch != '\0')
|
||||
{
|
||||
if (shift || caps)
|
||||
txt[0] = keys[i][j].chShift;
|
||||
else if (alt)
|
||||
txt[0] = keys[i][j].chalt;
|
||||
else if (alt2)
|
||||
txt[0] = keys[i][j].chalt2;
|
||||
else txt[0] = keys[i][j].ch;
|
||||
|
||||
if (changedShiftKey) // change text only if needed
|
||||
keyTxt[i][j]->SetText(txt);
|
||||
if (changedShiftKey) // change text only if needed
|
||||
keyTxt[i][j]->SetText(txt);
|
||||
|
||||
if (keyBtn[i][j]->GetState() == STATE_CLICKED)
|
||||
{
|
||||
if (strlen(kbtextstr) < kbtextmaxlen - 1) // -1 --> kbtextmaxlen means with term. '\0'
|
||||
{
|
||||
kbtextstr[strlen(kbtextstr)] = txt[0];
|
||||
kbText->SetText(kbtextstr);
|
||||
}
|
||||
keyBtn[i][j]->SetState(STATE_SELECTED, t->chan);
|
||||
if (keyBtn[i][j]->GetState() == STATE_CLICKED)
|
||||
{
|
||||
if (strlen(kbtextstr) < kbtextmaxlen - 1) // -1 --> kbtextmaxlen means with term. '\0'
|
||||
{
|
||||
kbtextstr[strlen(kbtextstr)] = txt[0];
|
||||
kbText->SetText(kbtextstr);
|
||||
}
|
||||
keyBtn[i][j]->SetState(STATE_SELECTED, t->chan);
|
||||
|
||||
if (shift || alt || alt2)
|
||||
{
|
||||
if (shift) shift ^= 1;
|
||||
if (alt) alt ^= 1;
|
||||
if (alt2) alt2 ^= 1;
|
||||
update = true;
|
||||
changedShiftKey = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} while (update);
|
||||
if (shift || alt || alt2)
|
||||
{
|
||||
if (shift) shift ^= 1;
|
||||
if (alt) alt ^= 1;
|
||||
if (alt2) alt2 ^= 1;
|
||||
update = true;
|
||||
changedShiftKey = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} while (update);
|
||||
|
||||
kbText->SetPosition(0, 53);
|
||||
kbText->SetPosition(0, 53);
|
||||
|
||||
this->ToggleFocus(t);
|
||||
this->ToggleFocus(t);
|
||||
|
||||
if (focus) // only send actions to this window if it's in focus
|
||||
{
|
||||
// pad/joystick navigation
|
||||
if (t->Right())
|
||||
this->MoveSelectionHor(1);
|
||||
else if (t->Left())
|
||||
this->MoveSelectionHor(-1);
|
||||
else if (t->Down())
|
||||
this->MoveSelectionVert(1);
|
||||
else if (t->Up()) this->MoveSelectionVert(-1);
|
||||
}
|
||||
if (focus) // only send actions to this window if it's in focus
|
||||
{
|
||||
// pad/joystick navigation
|
||||
if (t->Right())
|
||||
this->MoveSelectionHor(1);
|
||||
else if (t->Left())
|
||||
this->MoveSelectionHor(-1);
|
||||
else if (t->Down())
|
||||
this->MoveSelectionVert(1);
|
||||
else if (t->Up()) this->MoveSelectionVert(-1);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,80 +19,80 @@
|
|||
|
||||
GuiNumpad::GuiNumpad(char * t, u32 max)
|
||||
{
|
||||
width = 400;
|
||||
height = 370;
|
||||
selectable = true;
|
||||
focus = 0; // allow focus
|
||||
alignmentHor = ALIGN_CENTRE;
|
||||
alignmentVert = ALIGN_MIDDLE;
|
||||
kbtextmaxlen = max > sizeof(kbtextstr) ? sizeof(kbtextstr) : max; // limit max up to sizeof(kbtextstr)
|
||||
// strlcpy(kbtextstr, t, kbtextmaxlen);
|
||||
strncpy(kbtextstr, t, kbtextmaxlen); // strncpy is needed to fill the rest with \0
|
||||
kbtextstr[sizeof(kbtextstr) - 1] = 0; // terminate with \0
|
||||
width = 400;
|
||||
height = 370;
|
||||
selectable = true;
|
||||
focus = 0; // allow focus
|
||||
alignmentHor = ALIGN_CENTRE;
|
||||
alignmentVert = ALIGN_MIDDLE;
|
||||
kbtextmaxlen = max > sizeof(kbtextstr) ? sizeof(kbtextstr) : max; // limit max up to sizeof(kbtextstr)
|
||||
// strlcpy(kbtextstr, t, kbtextmaxlen);
|
||||
strncpy(kbtextstr, t, kbtextmaxlen); // strncpy is needed to fill the rest with \0
|
||||
kbtextstr[sizeof(kbtextstr) - 1] = 0; // terminate with \0
|
||||
|
||||
char thekeys[11] = { '1', '2', '3', '4', '5', '6', '7', '8', '9', '\0', '0' };
|
||||
memcpy(keys, thekeys, sizeof(thekeys));
|
||||
char thekeys[11] = { '1', '2', '3', '4', '5', '6', '7', '8', '9', '\0', '0' };
|
||||
memcpy(keys, thekeys, sizeof(thekeys));
|
||||
|
||||
keyTextbox = new GuiImageData("keyboard_textbox.png");
|
||||
keyTextboxImg = new GuiImage(keyTextbox);
|
||||
keyTextboxImg->SetAlignment(ALIGN_CENTRE, ALIGN_TOP);
|
||||
keyTextboxImg->SetPosition(0, 40);//(0,0);
|
||||
this->Append(keyTextboxImg);
|
||||
keyTextbox = new GuiImageData("keyboard_textbox.png");
|
||||
keyTextboxImg = new GuiImage(keyTextbox);
|
||||
keyTextboxImg->SetAlignment(ALIGN_CENTRE, ALIGN_TOP);
|
||||
keyTextboxImg->SetPosition(0, 40);//(0,0);
|
||||
this->Append(keyTextboxImg);
|
||||
|
||||
kbText = new GuiText(kbtextstr, 20, ( GXColor )
|
||||
{ 0, 0, 0, 0xff});
|
||||
kbText->SetAlignment(ALIGN_CENTRE, ALIGN_TOP);
|
||||
kbText->SetPosition(0, 53);//(0, 13);
|
||||
kbText->SetPassChar('*');
|
||||
this->Append(kbText);
|
||||
kbText = new GuiText(kbtextstr, 20, ( GXColor )
|
||||
{ 0, 0, 0, 0xff});
|
||||
kbText->SetAlignment(ALIGN_CENTRE, ALIGN_TOP);
|
||||
kbText->SetPosition(0, 53);//(0, 13);
|
||||
kbText->SetPassChar('*');
|
||||
this->Append(kbText);
|
||||
|
||||
keyMedium = new GuiImageData("keyboard_mediumkey_over.png");
|
||||
keyMedium = new GuiImageData("keyboard_mediumkey_over.png");
|
||||
|
||||
trigA = new GuiTrigger;
|
||||
trigA->SetSimpleTrigger(-1, WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A, PAD_BUTTON_A);
|
||||
trigB = new GuiTrigger;
|
||||
trigB->SetButtonOnlyTrigger(-1, WPAD_BUTTON_B | WPAD_CLASSIC_BUTTON_B, PAD_BUTTON_B);
|
||||
trigA = new GuiTrigger;
|
||||
trigA->SetSimpleTrigger(-1, WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A, PAD_BUTTON_A);
|
||||
trigB = new GuiTrigger;
|
||||
trigB->SetButtonOnlyTrigger(-1, WPAD_BUTTON_B | WPAD_CLASSIC_BUTTON_B, PAD_BUTTON_B);
|
||||
|
||||
keyBackImg = new GuiImage(keyMedium);
|
||||
keyBackOverImg = new GuiImage(keyMedium);
|
||||
keyBackText = new GuiText("Back", 20, ( GXColor )
|
||||
{ 0, 0, 0, 0xff});
|
||||
keyBackImg = new GuiImage(keyMedium);
|
||||
keyBackOverImg = new GuiImage(keyMedium);
|
||||
keyBackText = new GuiText("Back", 20, ( GXColor )
|
||||
{ 0, 0, 0, 0xff});
|
||||
|
||||
keyBack = new GuiButton(keyBackImg, keyBackOverImg, ALIGN_CENTRE, ALIGN_MIDDLE, 90, 80, trigA, btnSoundOver, btnSoundClick, 1);
|
||||
keyBack->SetLabel(keyBackText);
|
||||
keyBack->SetTrigger(trigB);
|
||||
this->Append(keyBack);
|
||||
keyBack = new GuiButton(keyBackImg, keyBackOverImg, ALIGN_CENTRE, ALIGN_MIDDLE, 90, 80, trigA, btnSoundOver, btnSoundClick, 1);
|
||||
keyBack->SetLabel(keyBackText);
|
||||
keyBack->SetTrigger(trigB);
|
||||
this->Append(keyBack);
|
||||
|
||||
keyClearImg = new GuiImage(keyMedium);
|
||||
keyClearOverImg = new GuiImage(keyMedium);
|
||||
keyClearText = new GuiText("Clear", 20, ( GXColor )
|
||||
{ 0, 0, 0, 0xff});
|
||||
keyClear = new GuiButton(keyClearImg, keyClearOverImg, ALIGN_CENTRE, ALIGN_MIDDLE, -90, 80, trigA, btnSoundOver, btnSoundClick, 1);
|
||||
keyClear->SetLabel(keyClearText);
|
||||
this->Append(keyClear);
|
||||
keyClearImg = new GuiImage(keyMedium);
|
||||
keyClearOverImg = new GuiImage(keyMedium);
|
||||
keyClearText = new GuiText("Clear", 20, ( GXColor )
|
||||
{ 0, 0, 0, 0xff});
|
||||
keyClear = new GuiButton(keyClearImg, keyClearOverImg, ALIGN_CENTRE, ALIGN_MIDDLE, -90, 80, trigA, btnSoundOver, btnSoundClick, 1);
|
||||
keyClear->SetLabel(keyClearText);
|
||||
this->Append(keyClear);
|
||||
|
||||
char txt[2] = { 0, 0 };
|
||||
for (int i = 0; i < 11; i++)
|
||||
{
|
||||
if (keys[i] != '\0')
|
||||
{
|
||||
int col = i % 3;
|
||||
int row = i / 3;
|
||||
char txt[2] = { 0, 0 };
|
||||
for (int i = 0; i < 11; i++)
|
||||
{
|
||||
if (keys[i] != '\0')
|
||||
{
|
||||
int col = i % 3;
|
||||
int row = i / 3;
|
||||
|
||||
keyImg[i] = new GuiImage(keyMedium);
|
||||
keyImgOver[i] = new GuiImage(keyMedium);
|
||||
txt[0] = keys[i];
|
||||
keyTxt[i] = new GuiText(txt, 20, ( GXColor )
|
||||
{ 0, 0, 0, 0xff});
|
||||
keyTxt[i]->SetAlignment(ALIGN_CENTRE, ALIGN_BOTTOM);
|
||||
keyTxt[i]->SetPosition(0, -10);
|
||||
keyBtn[i] = new GuiButton(keyImg[i], keyImgOver[i], ALIGN_CENTRE, ALIGN_MIDDLE, -90 + 90 * col, -70 + 50
|
||||
* row, trigA, btnSoundOver, btnSoundClick, 1);
|
||||
keyBtn[i]->SetLabel(keyTxt[i]);
|
||||
keyImg[i] = new GuiImage(keyMedium);
|
||||
keyImgOver[i] = new GuiImage(keyMedium);
|
||||
txt[0] = keys[i];
|
||||
keyTxt[i] = new GuiText(txt, 20, ( GXColor )
|
||||
{ 0, 0, 0, 0xff});
|
||||
keyTxt[i]->SetAlignment(ALIGN_CENTRE, ALIGN_BOTTOM);
|
||||
keyTxt[i]->SetPosition(0, -10);
|
||||
keyBtn[i] = new GuiButton(keyImg[i], keyImgOver[i], ALIGN_CENTRE, ALIGN_MIDDLE, -90 + 90 * col, -70 + 50
|
||||
* row, trigA, btnSoundOver, btnSoundClick, 1);
|
||||
keyBtn[i]->SetLabel(keyTxt[i]);
|
||||
|
||||
this->Append(keyBtn[i]);
|
||||
}
|
||||
}
|
||||
this->Append(keyBtn[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -100,96 +100,96 @@ GuiNumpad::GuiNumpad(char * t, u32 max)
|
|||
*/
|
||||
GuiNumpad::~GuiNumpad()
|
||||
{
|
||||
delete kbText;
|
||||
delete keyTextbox;
|
||||
delete keyTextboxImg;
|
||||
delete keyBackText;
|
||||
delete keyBackImg;
|
||||
delete keyBackOverImg;
|
||||
delete keyBack;
|
||||
delete keyClear;
|
||||
delete keyClearImg;
|
||||
delete keyClearOverImg;
|
||||
delete keyClearText;
|
||||
delete keyMedium;
|
||||
delete trigA;
|
||||
delete trigB;
|
||||
delete kbText;
|
||||
delete keyTextbox;
|
||||
delete keyTextboxImg;
|
||||
delete keyBackText;
|
||||
delete keyBackImg;
|
||||
delete keyBackOverImg;
|
||||
delete keyBack;
|
||||
delete keyClear;
|
||||
delete keyClearImg;
|
||||
delete keyClearOverImg;
|
||||
delete keyClearText;
|
||||
delete keyMedium;
|
||||
delete trigA;
|
||||
delete trigB;
|
||||
|
||||
for (int i = 0; i < 11; i++)
|
||||
{
|
||||
if (keys[i] != '\0')
|
||||
{
|
||||
delete keyImg[i];
|
||||
delete keyImgOver[i];
|
||||
delete keyTxt[i];
|
||||
delete keyBtn[i];
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < 11; i++)
|
||||
{
|
||||
if (keys[i] != '\0')
|
||||
{
|
||||
delete keyImg[i];
|
||||
delete keyImgOver[i];
|
||||
delete keyTxt[i];
|
||||
delete keyBtn[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GuiNumpad::Update(GuiTrigger * t)
|
||||
{
|
||||
LOCK( this );
|
||||
if (_elements.size() == 0 || (state == STATE_DISABLED && parentElement)) return;
|
||||
LOCK( this );
|
||||
if (_elements.size() == 0 || (state == STATE_DISABLED && parentElement)) return;
|
||||
|
||||
for (u8 i = 0; i < _elements.size(); i++)
|
||||
{
|
||||
try
|
||||
{
|
||||
_elements.at(i)->Update(t);
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
}
|
||||
}
|
||||
for (u8 i = 0; i < _elements.size(); i++)
|
||||
{
|
||||
try
|
||||
{
|
||||
_elements.at(i)->Update(t);
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
if (keyBack->GetState() == STATE_CLICKED)
|
||||
{
|
||||
if (strlen(kbtextstr) > 0)
|
||||
{
|
||||
kbtextstr[strlen(kbtextstr) - 1] = 0;
|
||||
kbText->SetText(kbtextstr);
|
||||
}
|
||||
keyBack->SetState(STATE_SELECTED, t->chan);
|
||||
}
|
||||
else if (keyClear->GetState() == STATE_CLICKED)
|
||||
{
|
||||
memset(kbtextstr, 0, sizeof(kbtextstr));
|
||||
kbText->SetText(kbtextstr);
|
||||
keyClear->SetState(STATE_SELECTED, t->chan);
|
||||
}
|
||||
if (keyBack->GetState() == STATE_CLICKED)
|
||||
{
|
||||
if (strlen(kbtextstr) > 0)
|
||||
{
|
||||
kbtextstr[strlen(kbtextstr) - 1] = 0;
|
||||
kbText->SetText(kbtextstr);
|
||||
}
|
||||
keyBack->SetState(STATE_SELECTED, t->chan);
|
||||
}
|
||||
else if (keyClear->GetState() == STATE_CLICKED)
|
||||
{
|
||||
memset(kbtextstr, 0, sizeof(kbtextstr));
|
||||
kbText->SetText(kbtextstr);
|
||||
keyClear->SetState(STATE_SELECTED, t->chan);
|
||||
}
|
||||
|
||||
char txt[2] = { 0, 0 };
|
||||
for (int i = 0; i < 11; i++)
|
||||
{
|
||||
if (keys[i] != '\0')
|
||||
{
|
||||
if (keyBtn[i]->GetState() == STATE_CLICKED)
|
||||
{
|
||||
txt[0] = keys[i];
|
||||
if (strlen(kbtextstr) < kbtextmaxlen - 1) // -1 --> kbtextmaxlen means with term. '\0'
|
||||
{
|
||||
kbtextstr[strlen(kbtextstr)] = txt[0];
|
||||
kbText->SetText(kbtextstr);
|
||||
}
|
||||
keyBtn[i]->SetState(STATE_SELECTED, t->chan);
|
||||
}
|
||||
}
|
||||
}
|
||||
char txt[2] = { 0, 0 };
|
||||
for (int i = 0; i < 11; i++)
|
||||
{
|
||||
if (keys[i] != '\0')
|
||||
{
|
||||
if (keyBtn[i]->GetState() == STATE_CLICKED)
|
||||
{
|
||||
txt[0] = keys[i];
|
||||
if (strlen(kbtextstr) < kbtextmaxlen - 1) // -1 --> kbtextmaxlen means with term. '\0'
|
||||
{
|
||||
kbtextstr[strlen(kbtextstr)] = txt[0];
|
||||
kbText->SetText(kbtextstr);
|
||||
}
|
||||
keyBtn[i]->SetState(STATE_SELECTED, t->chan);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
kbText->SetPosition(0, 53);
|
||||
kbText->SetPosition(0, 53);
|
||||
|
||||
this->ToggleFocus(t);
|
||||
this->ToggleFocus(t);
|
||||
|
||||
if (focus) // only send actions to this window if it's in focus
|
||||
{
|
||||
// pad/joystick navigation
|
||||
if (t->Right())
|
||||
this->MoveSelectionHor(1);
|
||||
else if (t->Left())
|
||||
this->MoveSelectionHor(-1);
|
||||
else if (t->Down())
|
||||
this->MoveSelectionVert(1);
|
||||
else if (t->Up()) this->MoveSelectionVert(-1);
|
||||
}
|
||||
if (focus) // only send actions to this window if it's in focus
|
||||
{
|
||||
// pad/joystick navigation
|
||||
if (t->Right())
|
||||
this->MoveSelectionHor(1);
|
||||
else if (t->Left())
|
||||
this->MoveSelectionHor(-1);
|
||||
else if (t->Down())
|
||||
this->MoveSelectionVert(1);
|
||||
else if (t->Up()) this->MoveSelectionVert(-1);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,67 +18,67 @@
|
|||
|
||||
#include <unistd.h>
|
||||
|
||||
#define GAMESELECTSIZE 30
|
||||
#define GAMESELECTSIZE 30
|
||||
|
||||
/**
|
||||
GuiOptionBrowser * Constructor for the GuiOptionBrowser class.
|
||||
*/
|
||||
GuiOptionBrowser::GuiOptionBrowser(int w, int h, OptionList * l, const char * custombg)
|
||||
: scrollBar(h-10)
|
||||
: scrollBar(h-10)
|
||||
{
|
||||
width = w;
|
||||
height = h;
|
||||
options = l;
|
||||
selectable = true;
|
||||
selectedItem = 0;
|
||||
focus = 1; // allow focus
|
||||
coL2 = 50;
|
||||
scrollbaron = false;
|
||||
listChanged = true;
|
||||
listOffset = 0;
|
||||
width = w;
|
||||
height = h;
|
||||
options = l;
|
||||
selectable = true;
|
||||
selectedItem = 0;
|
||||
focus = 1; // allow focus
|
||||
coL2 = 50;
|
||||
scrollbaron = false;
|
||||
listChanged = true;
|
||||
listOffset = 0;
|
||||
|
||||
trigA = new GuiTrigger;
|
||||
trigA->SetSimpleTrigger(-1, WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A, PAD_BUTTON_A);
|
||||
trigA = new GuiTrigger;
|
||||
trigA->SetSimpleTrigger(-1, WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A, PAD_BUTTON_A);
|
||||
|
||||
bgOptions = Resources::GetImageData(custombg);
|
||||
bgOptions = Resources::GetImageData(custombg);
|
||||
|
||||
bgOptionsImg = new GuiImage(bgOptions);
|
||||
bgOptionsImg->SetParent(this);
|
||||
bgOptionsImg->SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE);
|
||||
bgOptionsImg = new GuiImage(bgOptions);
|
||||
bgOptionsImg->SetParent(this);
|
||||
bgOptionsImg->SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE);
|
||||
|
||||
bgOptionsEntry = Resources::GetImageData("bg_options_entry.png");
|
||||
bgOptionsEntry = Resources::GetImageData("bg_options_entry.png");
|
||||
|
||||
scrollBar.SetParent(this);
|
||||
scrollBar.SetAlignment(thAlign("right - options browser scrollbar align hor"), thAlign("top - options browser scrollbar align ver"));
|
||||
scrollBar.SetPosition(thInt("0 - options browser scrollbar pos x"), thInt("5 - options browser scrollbar pos y"));
|
||||
scrollBar.listChanged.connect(this, &GuiOptionBrowser::onListChange);
|
||||
scrollBar.SetParent(this);
|
||||
scrollBar.SetAlignment(thAlign("right - options browser scrollbar align hor"), thAlign("top - options browser scrollbar align ver"));
|
||||
scrollBar.SetPosition(thInt("0 - options browser scrollbar pos x"), thInt("5 - options browser scrollbar pos y"));
|
||||
scrollBar.listChanged.connect(this, &GuiOptionBrowser::onListChange);
|
||||
|
||||
for (int i = 0; i < PAGESIZE; i++)
|
||||
{
|
||||
optionTxt[i] = new GuiText((wchar_t *) NULL, 20, thColor("r=0 g=0 b=0 a=255 - settings text color"));
|
||||
optionTxt[i]->SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE);
|
||||
optionTxt[i]->SetPosition(24, 0);
|
||||
optionTxt[i]->SetMaxWidth(bgOptionsImg->GetWidth()-scrollBar.GetWidth()-40, DOTTED);
|
||||
for (int i = 0; i < PAGESIZE; i++)
|
||||
{
|
||||
optionTxt[i] = new GuiText((wchar_t *) NULL, 20, thColor("r=0 g=0 b=0 a=255 - settings text color"));
|
||||
optionTxt[i]->SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE);
|
||||
optionTxt[i]->SetPosition(24, 0);
|
||||
optionTxt[i]->SetMaxWidth(bgOptionsImg->GetWidth()-scrollBar.GetWidth()-40, DOTTED);
|
||||
|
||||
optionBg[i] = new GuiImage(bgOptionsEntry);
|
||||
optionBg[i] = new GuiImage(bgOptionsEntry);
|
||||
|
||||
optionVal[i] = new GuiText((wchar_t *) NULL, 20, thColor("r=0 g=0 b=0 a=255 - settings text color"));
|
||||
optionVal[i]->SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE);
|
||||
optionVal[i] = new GuiText((wchar_t *) NULL, 20, thColor("r=0 g=0 b=0 a=255 - settings text color"));
|
||||
optionVal[i]->SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE);
|
||||
|
||||
optionValOver[i] = new GuiText((wchar_t *) NULL, 20, thColor("r=0 g=0 b=0 a=255 - settings text color"));
|
||||
optionValOver[i]->SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE);
|
||||
optionValOver[i] = new GuiText((wchar_t *) NULL, 20, thColor("r=0 g=0 b=0 a=255 - settings text color"));
|
||||
optionValOver[i]->SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE);
|
||||
|
||||
optionBtn[i] = new GuiButton(width - scrollBar.GetWidth(), GAMESELECTSIZE);
|
||||
optionBtn[i]->SetParent(this);
|
||||
optionBtn[i]->SetLabel(optionTxt[i], 0);
|
||||
optionBtn[i]->SetLabel(optionVal[i], 1);
|
||||
optionBtn[i]->SetLabelOver(optionValOver[i], 1);
|
||||
optionBtn[i]->SetImageOver(optionBg[i]);
|
||||
optionBtn[i]->SetPosition(10, GAMESELECTSIZE * i + 4);
|
||||
optionBtn[i]->SetRumble(false);
|
||||
optionBtn[i]->SetTrigger(trigA);
|
||||
optionBtn[i]->SetSoundClick(btnSoundClick);
|
||||
}
|
||||
optionBtn[i] = new GuiButton(width - scrollBar.GetWidth(), GAMESELECTSIZE);
|
||||
optionBtn[i]->SetParent(this);
|
||||
optionBtn[i]->SetLabel(optionTxt[i], 0);
|
||||
optionBtn[i]->SetLabel(optionVal[i], 1);
|
||||
optionBtn[i]->SetLabelOver(optionValOver[i], 1);
|
||||
optionBtn[i]->SetImageOver(optionBg[i]);
|
||||
optionBtn[i]->SetPosition(10, GAMESELECTSIZE * i + 4);
|
||||
optionBtn[i]->SetRumble(false);
|
||||
optionBtn[i]->SetTrigger(trigA);
|
||||
optionBtn[i]->SetSoundClick(btnSoundClick);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -86,91 +86,91 @@ GuiOptionBrowser::GuiOptionBrowser(int w, int h, OptionList * l, const char * cu
|
|||
*/
|
||||
GuiOptionBrowser::~GuiOptionBrowser()
|
||||
{
|
||||
delete bgOptionsImg;
|
||||
delete bgOptions;
|
||||
delete bgOptionsEntry;
|
||||
delete bgOptionsImg;
|
||||
delete bgOptions;
|
||||
delete bgOptionsEntry;
|
||||
|
||||
delete trigA;
|
||||
delete trigA;
|
||||
|
||||
for (int i = 0; i < PAGESIZE; i++)
|
||||
{
|
||||
delete optionTxt[i];
|
||||
delete optionVal[i];
|
||||
delete optionValOver[i];
|
||||
delete optionBg[i];
|
||||
delete optionBtn[i];
|
||||
}
|
||||
for (int i = 0; i < PAGESIZE; i++)
|
||||
{
|
||||
delete optionTxt[i];
|
||||
delete optionVal[i];
|
||||
delete optionValOver[i];
|
||||
delete optionBg[i];
|
||||
delete optionBtn[i];
|
||||
}
|
||||
}
|
||||
|
||||
void GuiOptionBrowser::SetFocus(int f)
|
||||
{
|
||||
focus = f;
|
||||
focus = f;
|
||||
|
||||
for (int i = 0; i < PAGESIZE; i++)
|
||||
optionBtn[i]->ResetState();
|
||||
for (int i = 0; i < PAGESIZE; i++)
|
||||
optionBtn[i]->ResetState();
|
||||
|
||||
if (f == 1) optionBtn[selectedItem]->SetState(STATE_SELECTED);
|
||||
if (f == 1) optionBtn[selectedItem]->SetState(STATE_SELECTED);
|
||||
}
|
||||
|
||||
void GuiOptionBrowser::ResetState()
|
||||
{
|
||||
if (state != STATE_DISABLED)
|
||||
{
|
||||
state = STATE_DEFAULT;
|
||||
stateChan = -1;
|
||||
}
|
||||
if (state != STATE_DISABLED)
|
||||
{
|
||||
state = STATE_DEFAULT;
|
||||
stateChan = -1;
|
||||
}
|
||||
|
||||
for (int i = 0; i < PAGESIZE; i++)
|
||||
{
|
||||
optionBtn[i]->ResetState();
|
||||
}
|
||||
for (int i = 0; i < PAGESIZE; i++)
|
||||
{
|
||||
optionBtn[i]->ResetState();
|
||||
}
|
||||
}
|
||||
|
||||
int GuiOptionBrowser::GetClickedOption()
|
||||
{
|
||||
for (int i = 0; i < PAGESIZE; i++)
|
||||
{
|
||||
if (optionBtn[i]->GetState() == STATE_CLICKED)
|
||||
{
|
||||
optionBtn[i]->SetState(STATE_SELECTED);
|
||||
return optionIndex[i];
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < PAGESIZE; i++)
|
||||
{
|
||||
if (optionBtn[i]->GetState() == STATE_CLICKED)
|
||||
{
|
||||
optionBtn[i]->SetState(STATE_SELECTED);
|
||||
return optionIndex[i];
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int GuiOptionBrowser::GetSelectedOption()
|
||||
{
|
||||
for (int i = 0; i < PAGESIZE; i++)
|
||||
{
|
||||
if (optionBtn[i]->GetState() == STATE_SELECTED)
|
||||
{
|
||||
return optionIndex[i];
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
for (int i = 0; i < PAGESIZE; i++)
|
||||
{
|
||||
if (optionBtn[i]->GetState() == STATE_SELECTED)
|
||||
{
|
||||
return optionIndex[i];
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
void GuiOptionBrowser::SetClickable(bool enable)
|
||||
{
|
||||
for (int i = 0; i < PAGESIZE; i++)
|
||||
{
|
||||
optionBtn[i]->SetClickable(enable);
|
||||
}
|
||||
for (int i = 0; i < PAGESIZE; i++)
|
||||
{
|
||||
optionBtn[i]->SetClickable(enable);
|
||||
}
|
||||
}
|
||||
|
||||
void GuiOptionBrowser::SetOffset(int optionnumber)
|
||||
{
|
||||
listOffset = optionnumber;
|
||||
selectedItem = optionnumber;
|
||||
listOffset = optionnumber;
|
||||
selectedItem = optionnumber;
|
||||
}
|
||||
|
||||
void GuiOptionBrowser::onListChange(int SelItem, int SelInd)
|
||||
{
|
||||
selectedItem = SelItem;
|
||||
listOffset = SelInd;
|
||||
UpdateListEntries();
|
||||
selectedItem = SelItem;
|
||||
listOffset = SelInd;
|
||||
UpdateListEntries();
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
|
@ -181,14 +181,14 @@ void GuiOptionBrowser::onListChange(int SelItem, int SelInd)
|
|||
|
||||
int GuiOptionBrowser::FindMenuItem(int currentItem, int direction)
|
||||
{
|
||||
int nextItem = currentItem + direction;
|
||||
int nextItem = currentItem + direction;
|
||||
|
||||
if (nextItem < 0 || nextItem >= options->GetLength()) return -1;
|
||||
if (nextItem < 0 || nextItem >= options->GetLength()) return -1;
|
||||
|
||||
if (strlen(options->GetName(nextItem)) > 0)
|
||||
return nextItem;
|
||||
if (strlen(options->GetName(nextItem)) > 0)
|
||||
return nextItem;
|
||||
|
||||
return FindMenuItem(nextItem, direction);
|
||||
return FindMenuItem(nextItem, direction);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -196,129 +196,129 @@ int GuiOptionBrowser::FindMenuItem(int currentItem, int direction)
|
|||
*/
|
||||
void GuiOptionBrowser::Draw()
|
||||
{
|
||||
if (!this->IsVisible()) return;
|
||||
if (!this->IsVisible()) return;
|
||||
|
||||
bgOptionsImg->Draw();
|
||||
bgOptionsImg->Draw();
|
||||
|
||||
int next = listOffset;
|
||||
int next = listOffset;
|
||||
|
||||
for (int i = 0; i < PAGESIZE; i++)
|
||||
{
|
||||
if (next >= 0)
|
||||
{
|
||||
optionBtn[i]->Draw();
|
||||
next = this->FindMenuItem(next, 1);
|
||||
}
|
||||
else break;
|
||||
}
|
||||
for (int i = 0; i < PAGESIZE; i++)
|
||||
{
|
||||
if (next >= 0)
|
||||
{
|
||||
optionBtn[i]->Draw();
|
||||
next = this->FindMenuItem(next, 1);
|
||||
}
|
||||
else break;
|
||||
}
|
||||
|
||||
if (scrollbaron)
|
||||
scrollBar.Draw();
|
||||
if (scrollbaron)
|
||||
scrollBar.Draw();
|
||||
|
||||
this->UpdateEffects();
|
||||
this->UpdateEffects();
|
||||
}
|
||||
|
||||
void GuiOptionBrowser::UpdateListEntries()
|
||||
{
|
||||
LOCK(this);
|
||||
scrollbaron = options->GetLength() > PAGESIZE;
|
||||
if (listOffset < 0) listOffset = this->FindMenuItem(-1, 1);
|
||||
int next = listOffset;
|
||||
LOCK(this);
|
||||
scrollbaron = options->GetLength() > PAGESIZE;
|
||||
if (listOffset < 0) listOffset = this->FindMenuItem(-1, 1);
|
||||
int next = listOffset;
|
||||
|
||||
int maxNameWidth = 0;
|
||||
for (int i = 0; i < PAGESIZE; i++)
|
||||
{
|
||||
if (next >= 0)
|
||||
{
|
||||
if (optionBtn[i]->GetState() == STATE_DISABLED)
|
||||
{
|
||||
optionBtn[i]->SetVisible(true);
|
||||
optionBtn[i]->SetState(STATE_DEFAULT);
|
||||
}
|
||||
int maxNameWidth = 0;
|
||||
for (int i = 0; i < PAGESIZE; i++)
|
||||
{
|
||||
if (next >= 0)
|
||||
{
|
||||
if (optionBtn[i]->GetState() == STATE_DISABLED)
|
||||
{
|
||||
optionBtn[i]->SetVisible(true);
|
||||
optionBtn[i]->SetState(STATE_DEFAULT);
|
||||
}
|
||||
|
||||
optionTxt[i]->SetText(options->GetName(next));
|
||||
if (maxNameWidth < optionTxt[i]->GetTextWidth()) maxNameWidth = optionTxt[i]->GetTextWidth();
|
||||
optionVal[i]->SetText(options->GetValue(next));
|
||||
optionValOver[i]->SetText(options->GetValue(next));
|
||||
optionTxt[i]->SetText(options->GetName(next));
|
||||
if (maxNameWidth < optionTxt[i]->GetTextWidth()) maxNameWidth = optionTxt[i]->GetTextWidth();
|
||||
optionVal[i]->SetText(options->GetValue(next));
|
||||
optionValOver[i]->SetText(options->GetValue(next));
|
||||
|
||||
optionIndex[i] = next;
|
||||
next = this->FindMenuItem(next, 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
optionBtn[i]->SetVisible(false);
|
||||
optionBtn[i]->SetState(STATE_DISABLED);
|
||||
}
|
||||
}
|
||||
optionIndex[i] = next;
|
||||
next = this->FindMenuItem(next, 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
optionBtn[i]->SetVisible(false);
|
||||
optionBtn[i]->SetState(STATE_DISABLED);
|
||||
}
|
||||
}
|
||||
|
||||
if (coL2 < (24 + maxNameWidth + 16))
|
||||
coL2 = 24 + maxNameWidth + 16;
|
||||
if (coL2 < (24 + maxNameWidth + 16))
|
||||
coL2 = 24 + maxNameWidth + 16;
|
||||
|
||||
for (int i = 0; i < PAGESIZE; i++)
|
||||
{
|
||||
if (optionBtn[i]->GetState() != STATE_DISABLED)
|
||||
{
|
||||
optionVal[i]->SetPosition(coL2, 0);
|
||||
optionVal[i]->SetMaxWidth(bgOptionsImg->GetWidth() - (coL2 + scrollBar.GetWidth()+10), DOTTED);
|
||||
for (int i = 0; i < PAGESIZE; i++)
|
||||
{
|
||||
if (optionBtn[i]->GetState() != STATE_DISABLED)
|
||||
{
|
||||
optionVal[i]->SetPosition(coL2, 0);
|
||||
optionVal[i]->SetMaxWidth(bgOptionsImg->GetWidth() - (coL2 + scrollBar.GetWidth()+10), DOTTED);
|
||||
|
||||
optionValOver[i]->SetPosition(coL2, 0);
|
||||
optionValOver[i]->SetMaxWidth(bgOptionsImg->GetWidth() - (coL2 + scrollBar.GetWidth()+10), SCROLL_HORIZONTAL);
|
||||
}
|
||||
}
|
||||
optionValOver[i]->SetPosition(coL2, 0);
|
||||
optionValOver[i]->SetMaxWidth(bgOptionsImg->GetWidth() - (coL2 + scrollBar.GetWidth()+10), SCROLL_HORIZONTAL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GuiOptionBrowser::Update(GuiTrigger * t)
|
||||
{
|
||||
if (state == STATE_DISABLED || !t) return;
|
||||
if (state == STATE_DISABLED || !t) return;
|
||||
|
||||
static int pressedChan = -1;
|
||||
static int pressedChan = -1;
|
||||
|
||||
if((t->wpad.btns_d & (WPAD_BUTTON_B | WPAD_BUTTON_DOWN | WPAD_BUTTON_UP | WPAD_BUTTON_LEFT | WPAD_BUTTON_RIGHT |
|
||||
WPAD_CLASSIC_BUTTON_B | WPAD_CLASSIC_BUTTON_UP | WPAD_CLASSIC_BUTTON_DOWN | WPAD_CLASSIC_BUTTON_LEFT | WPAD_CLASSIC_BUTTON_RIGHT)) ||
|
||||
(t->pad.btns_d & (PAD_BUTTON_UP | PAD_BUTTON_DOWN)))
|
||||
pressedChan = t->chan;
|
||||
if((t->wpad.btns_d & (WPAD_BUTTON_B | WPAD_BUTTON_DOWN | WPAD_BUTTON_UP | WPAD_BUTTON_LEFT | WPAD_BUTTON_RIGHT |
|
||||
WPAD_CLASSIC_BUTTON_B | WPAD_CLASSIC_BUTTON_UP | WPAD_CLASSIC_BUTTON_DOWN | WPAD_CLASSIC_BUTTON_LEFT | WPAD_CLASSIC_BUTTON_RIGHT)) ||
|
||||
(t->pad.btns_d & (PAD_BUTTON_UP | PAD_BUTTON_DOWN)))
|
||||
pressedChan = t->chan;
|
||||
|
||||
if (scrollbaron)
|
||||
// update the location of the scroll box based on the position in the option list
|
||||
scrollBar.Update(t);
|
||||
if (scrollbaron)
|
||||
// update the location of the scroll box based on the position in the option list
|
||||
scrollBar.Update(t);
|
||||
|
||||
int next = listOffset;
|
||||
int next = listOffset;
|
||||
|
||||
if(pressedChan == -1 || (!t->wpad.btns_h && !t->pad.btns_h))
|
||||
{
|
||||
for(int i = 0; i < PAGESIZE; i++)
|
||||
{
|
||||
if (next >= 0) next = this->FindMenuItem(next, 1);
|
||||
if(pressedChan == -1 || (!t->wpad.btns_h && !t->pad.btns_h))
|
||||
{
|
||||
for(int i = 0; i < PAGESIZE; i++)
|
||||
{
|
||||
if (next >= 0) next = this->FindMenuItem(next, 1);
|
||||
|
||||
if (i != selectedItem && optionBtn[i]->GetState() == STATE_SELECTED)
|
||||
{
|
||||
optionBtn[i]->ResetState();
|
||||
}
|
||||
else if (i == selectedItem && optionBtn[i]->GetState() == STATE_DEFAULT)
|
||||
{
|
||||
optionBtn[selectedItem]->SetState(STATE_SELECTED);
|
||||
}
|
||||
if (i != selectedItem && optionBtn[i]->GetState() == STATE_SELECTED)
|
||||
{
|
||||
optionBtn[i]->ResetState();
|
||||
}
|
||||
else if (i == selectedItem && optionBtn[i]->GetState() == STATE_DEFAULT)
|
||||
{
|
||||
optionBtn[selectedItem]->SetState(STATE_SELECTED);
|
||||
}
|
||||
|
||||
optionBtn[i]->Update(t);
|
||||
optionBtn[i]->Update(t);
|
||||
|
||||
if (optionBtn[i]->GetState() == STATE_SELECTED)
|
||||
selectedItem = i;
|
||||
}
|
||||
}
|
||||
if (optionBtn[i]->GetState() == STATE_SELECTED)
|
||||
selectedItem = i;
|
||||
}
|
||||
}
|
||||
|
||||
if(pressedChan == t->chan && !t->wpad.btns_d && !t->wpad.btns_h)
|
||||
pressedChan = -1;
|
||||
if(pressedChan == t->chan && !t->wpad.btns_d && !t->wpad.btns_h)
|
||||
pressedChan = -1;
|
||||
|
||||
scrollBar.SetPageSize(PAGESIZE);
|
||||
scrollBar.SetSelectedItem(selectedItem);
|
||||
scrollBar.SetSelectedIndex(listOffset);
|
||||
scrollBar.SetEntrieCount(options->GetLength());
|
||||
scrollBar.SetPageSize(PAGESIZE);
|
||||
scrollBar.SetSelectedItem(selectedItem);
|
||||
scrollBar.SetSelectedIndex(listOffset);
|
||||
scrollBar.SetEntrieCount(options->GetLength());
|
||||
|
||||
if (options->IsChanged())
|
||||
{
|
||||
UpdateListEntries();
|
||||
listChanged = false;
|
||||
}
|
||||
if (options->IsChanged())
|
||||
{
|
||||
UpdateListEntries();
|
||||
listChanged = false;
|
||||
}
|
||||
|
||||
if (updateCB) updateCB(this);
|
||||
if (updateCB) updateCB(this);
|
||||
}
|
||||
|
|
|
@ -8,42 +8,42 @@
|
|||
//!Display a list of menu options
|
||||
class GuiOptionBrowser: public GuiElement, public sigslot::has_slots<>
|
||||
{
|
||||
public:
|
||||
GuiOptionBrowser(int w, int h, OptionList * l, const char * background);
|
||||
virtual ~GuiOptionBrowser();
|
||||
int FindMenuItem(int c, int d);
|
||||
int GetClickedOption();
|
||||
int GetSelectedOption();
|
||||
void SetClickable(bool enable);
|
||||
void SetOffset(int optionnumber);
|
||||
void ResetState();
|
||||
void SetFocus(int f);
|
||||
void Draw();
|
||||
void Update(GuiTrigger * t);
|
||||
protected:
|
||||
void onListChange(int SelItem, int SelInd);
|
||||
void UpdateListEntries();
|
||||
int selectedItem;
|
||||
int listOffset;
|
||||
int coL2;
|
||||
bool scrollbaron;
|
||||
bool listChanged;
|
||||
public:
|
||||
GuiOptionBrowser(int w, int h, OptionList * l, const char * background);
|
||||
virtual ~GuiOptionBrowser();
|
||||
int FindMenuItem(int c, int d);
|
||||
int GetClickedOption();
|
||||
int GetSelectedOption();
|
||||
void SetClickable(bool enable);
|
||||
void SetOffset(int optionnumber);
|
||||
void ResetState();
|
||||
void SetFocus(int f);
|
||||
void Draw();
|
||||
void Update(GuiTrigger * t);
|
||||
protected:
|
||||
void onListChange(int SelItem, int SelInd);
|
||||
void UpdateListEntries();
|
||||
int selectedItem;
|
||||
int listOffset;
|
||||
int coL2;
|
||||
bool scrollbaron;
|
||||
bool listChanged;
|
||||
|
||||
OptionList * options;
|
||||
int optionIndex[PAGESIZE];
|
||||
GuiButton * optionBtn[PAGESIZE];
|
||||
GuiText * optionTxt[PAGESIZE];
|
||||
GuiText * optionVal[PAGESIZE];
|
||||
GuiText * optionValOver[PAGESIZE];
|
||||
GuiImage * optionBg[PAGESIZE];
|
||||
OptionList * options;
|
||||
int optionIndex[PAGESIZE];
|
||||
GuiButton * optionBtn[PAGESIZE];
|
||||
GuiText * optionTxt[PAGESIZE];
|
||||
GuiText * optionVal[PAGESIZE];
|
||||
GuiText * optionValOver[PAGESIZE];
|
||||
GuiImage * optionBg[PAGESIZE];
|
||||
|
||||
GuiImage * bgOptionsImg;
|
||||
GuiImage * bgOptionsImg;
|
||||
|
||||
GuiImageData * bgOptions;
|
||||
GuiImageData * bgOptionsEntry;
|
||||
GuiImageData * bgOptions;
|
||||
GuiImageData * bgOptionsEntry;
|
||||
|
||||
GuiTrigger * trigA;
|
||||
GuiScrollbar scrollBar;
|
||||
GuiTrigger * trigA;
|
||||
GuiScrollbar scrollBar;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -28,23 +28,23 @@
|
|||
|
||||
GuiScrollbar::GuiScrollbar(int h, u8 m)
|
||||
{
|
||||
SelItem = 0;
|
||||
SelInd = 0;
|
||||
RowSize = 0;
|
||||
PageSize = 0;
|
||||
EntrieCount = 0;
|
||||
ScrollSpeed = 15;
|
||||
ButtonScroll = 0;
|
||||
ButtonScrollSpeed = 20;
|
||||
ScrollState = 0;
|
||||
pressedChan = -1;
|
||||
AllowDPad = true;
|
||||
Mode = m;
|
||||
listChanged.connect(this, &GuiScrollbar::setScrollboxPosition);
|
||||
SelItem = 0;
|
||||
SelInd = 0;
|
||||
RowSize = 0;
|
||||
PageSize = 0;
|
||||
EntrieCount = 0;
|
||||
ScrollSpeed = 15;
|
||||
ButtonScroll = 0;
|
||||
ButtonScrollSpeed = 20;
|
||||
ScrollState = 0;
|
||||
pressedChan = -1;
|
||||
AllowDPad = true;
|
||||
Mode = m;
|
||||
listChanged.connect(this, &GuiScrollbar::setScrollboxPosition);
|
||||
|
||||
scrollbarTop = Resources::GetImageData("scrollBarTop.png");
|
||||
scrollbarBottom = Resources::GetImageData("scrollBarBottom.png");
|
||||
scrollbarTile = Resources::GetImageData("scrollBarTile.png");
|
||||
scrollbarTop = Resources::GetImageData("scrollBarTop.png");
|
||||
scrollbarBottom = Resources::GetImageData("scrollBarBottom.png");
|
||||
scrollbarTile = Resources::GetImageData("scrollBarTile.png");
|
||||
arrowDown = Resources::GetImageData("scrollbar_arrowdown.png");
|
||||
arrowDownOver = Resources::GetImageData("scrollbar_arrowdown.png");
|
||||
arrowUp = Resources::GetImageData("scrollbar_arrowup.png");
|
||||
|
@ -53,20 +53,20 @@ GuiScrollbar::GuiScrollbar(int h, u8 m)
|
|||
scrollbarBoxOver = Resources::GetImageData("scrollbar_box.png");
|
||||
oneButtonScrollImgData = Resources::GetImageData("oneButtonScroll.png");
|
||||
|
||||
height = h;
|
||||
width = MAX(scrollbarBox->GetWidth(), scrollbarTile->GetWidth());
|
||||
height = h;
|
||||
width = MAX(scrollbarBox->GetWidth(), scrollbarTile->GetWidth());
|
||||
|
||||
MinHeight = arrowUp->GetHeight();
|
||||
MaxHeight = height-scrollbarBox->GetHeight()-arrowDown->GetHeight();
|
||||
MinHeight = arrowUp->GetHeight();
|
||||
MaxHeight = height-scrollbarBox->GetHeight()-arrowDown->GetHeight();
|
||||
|
||||
trigHeldA = new GuiTrigger;
|
||||
trigHeldA->SetHeldTrigger(-1, WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A, PAD_BUTTON_A);
|
||||
|
||||
int Tiles = (height-scrollbarTop->GetHeight()-scrollbarBottom->GetHeight())/4;
|
||||
int PositionY = 0;
|
||||
ButtonPositionX = 0;
|
||||
int Tiles = (height-scrollbarTop->GetHeight()-scrollbarBottom->GetHeight())/4;
|
||||
int PositionY = 0;
|
||||
ButtonPositionX = 0;
|
||||
|
||||
oneButtonScrollImg = new GuiImage(oneButtonScrollImgData);
|
||||
oneButtonScrollImg = new GuiImage(oneButtonScrollImgData);
|
||||
|
||||
scrollbarTopImg = new GuiImage(scrollbarTop);
|
||||
scrollbarTopImg->SetParent(this);
|
||||
|
@ -103,7 +103,7 @@ GuiScrollbar::GuiScrollbar(int h, u8 m)
|
|||
arrowUpBtn->SetTrigger(trigHeldA);
|
||||
arrowUpBtn->SetSoundOver(btnSoundOver);
|
||||
arrowUpBtn->SetSoundClick(btnSoundClick);
|
||||
arrowUpBtn->Held.connect(this, &GuiScrollbar::OnUpButtonHold);
|
||||
arrowUpBtn->Held.connect(this, &GuiScrollbar::OnUpButtonHold);
|
||||
|
||||
arrowDownBtn = new GuiButton(arrowDownImg->GetWidth(), arrowDownImg->GetHeight());
|
||||
arrowDownBtn->SetParent(this);
|
||||
|
@ -115,7 +115,7 @@ GuiScrollbar::GuiScrollbar(int h, u8 m)
|
|||
arrowDownBtn->SetTrigger(trigHeldA);
|
||||
arrowDownBtn->SetSoundOver(btnSoundOver);
|
||||
arrowDownBtn->SetSoundClick(btnSoundClick);
|
||||
arrowDownBtn->Held.connect(this, &GuiScrollbar::OnDownButtonHold);
|
||||
arrowDownBtn->Held.connect(this, &GuiScrollbar::OnDownButtonHold);
|
||||
|
||||
scrollbarBoxBtn = new GuiButton(scrollbarBoxImg->GetWidth(), scrollbarBoxImg->GetHeight());
|
||||
scrollbarBoxBtn->SetParent(this);
|
||||
|
@ -127,7 +127,7 @@ GuiScrollbar::GuiScrollbar(int h, u8 m)
|
|||
scrollbarBoxBtn->SetMaxY(MaxHeight);
|
||||
scrollbarBoxBtn->SetHoldable(true);
|
||||
scrollbarBoxBtn->SetTrigger(trigHeldA);
|
||||
scrollbarBoxBtn->Held.connect(this, &GuiScrollbar::OnBoxButtonHold);
|
||||
scrollbarBoxBtn->Held.connect(this, &GuiScrollbar::OnBoxButtonHold);
|
||||
}
|
||||
|
||||
GuiScrollbar::~GuiScrollbar()
|
||||
|
@ -163,22 +163,22 @@ GuiScrollbar::~GuiScrollbar()
|
|||
|
||||
void GuiScrollbar::ScrollOneUp()
|
||||
{
|
||||
if(Mode == ICONMODE)
|
||||
{
|
||||
if(SelInd+SelItem-RowSize >= 0)
|
||||
{
|
||||
SelItem = SelItem-RowSize;
|
||||
if(SelItem < 0)
|
||||
{
|
||||
// move list up by 1
|
||||
SelInd = SelInd-RowSize;
|
||||
SelItem = SelItem+RowSize;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(Mode == LISTMODE)
|
||||
{
|
||||
if(SelItem == 0 && SelInd > 0)
|
||||
if(Mode == ICONMODE)
|
||||
{
|
||||
if(SelInd+SelItem-RowSize >= 0)
|
||||
{
|
||||
SelItem = SelItem-RowSize;
|
||||
if(SelItem < 0)
|
||||
{
|
||||
// move list up by 1
|
||||
SelInd = SelInd-RowSize;
|
||||
SelItem = SelItem+RowSize;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(Mode == LISTMODE)
|
||||
{
|
||||
if(SelItem == 0 && SelInd > 0)
|
||||
{
|
||||
// move list up by 1
|
||||
--SelInd;
|
||||
|
@ -187,32 +187,32 @@ void GuiScrollbar::ScrollOneUp()
|
|||
{
|
||||
--SelItem;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GuiScrollbar::ScrollOneDown()
|
||||
{
|
||||
if(Mode == ICONMODE)
|
||||
{
|
||||
int i = RowSize;
|
||||
while(SelInd+SelItem+RowSize >= EntrieCount && i > 0 && SelItem > 0 && RowSize < EntrieCount)
|
||||
{
|
||||
--i;
|
||||
--SelItem;
|
||||
}
|
||||
if(Mode == ICONMODE)
|
||||
{
|
||||
int i = RowSize;
|
||||
while(SelInd+SelItem+RowSize >= EntrieCount && i > 0 && SelItem > 0 && RowSize < EntrieCount)
|
||||
{
|
||||
--i;
|
||||
--SelItem;
|
||||
}
|
||||
if(SelInd+SelItem+RowSize < EntrieCount)
|
||||
{
|
||||
SelItem = SelItem+RowSize;
|
||||
SelItem = SelItem+RowSize;
|
||||
if(SelItem >= PageSize)
|
||||
{
|
||||
// move list down by 1
|
||||
SelInd += RowSize;
|
||||
SelItem = SelItem-RowSize;
|
||||
SelItem = SelItem-RowSize;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(Mode == LISTMODE)
|
||||
{
|
||||
}
|
||||
else if(Mode == LISTMODE)
|
||||
{
|
||||
if(SelInd+SelItem + 1 < EntrieCount)
|
||||
{
|
||||
if(SelItem == PageSize-1)
|
||||
|
@ -225,232 +225,232 @@ void GuiScrollbar::ScrollOneDown()
|
|||
SelItem++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GuiScrollbar::OnUpButtonHold(GuiButton *sender, int pointer, const POINT &p)
|
||||
{
|
||||
if(ScrollState < ScrollSpeed)
|
||||
return;
|
||||
if(ScrollState < ScrollSpeed)
|
||||
return;
|
||||
|
||||
ScrollOneUp();
|
||||
ScrollOneUp();
|
||||
|
||||
ScrollState = 0;
|
||||
listChanged(SelItem, SelInd);
|
||||
ScrollState = 0;
|
||||
listChanged(SelItem, SelInd);
|
||||
}
|
||||
|
||||
void GuiScrollbar::OnDownButtonHold(GuiButton *sender, int pointer, const POINT &p)
|
||||
{
|
||||
if(ScrollState < ScrollSpeed)
|
||||
return;
|
||||
if(ScrollState < ScrollSpeed)
|
||||
return;
|
||||
|
||||
ScrollOneDown();
|
||||
ScrollOneDown();
|
||||
|
||||
ScrollState = 0;
|
||||
listChanged(SelItem, SelInd);
|
||||
ScrollState = 0;
|
||||
listChanged(SelItem, SelInd);
|
||||
}
|
||||
|
||||
void GuiScrollbar::OnBoxButtonHold(GuiButton *sender, int pointer, const POINT &p)
|
||||
{
|
||||
if(ScrollState < ScrollSpeed)
|
||||
return;
|
||||
if(ScrollState < ScrollSpeed)
|
||||
return;
|
||||
|
||||
if(!userInput[pointer].wpad.ir.valid)
|
||||
return;
|
||||
if(!userInput[pointer].wpad.ir.valid)
|
||||
return;
|
||||
|
||||
int y = p.y-this->GetTop()-scrollbarBox->GetHeight()/2;
|
||||
int y = p.y-this->GetTop()-scrollbarBox->GetHeight()/2;
|
||||
|
||||
int positionWiimote = LIMIT(y-MinHeight, 0, MaxHeight-MinHeight);
|
||||
int positionWiimote = LIMIT(y-MinHeight, 0, MaxHeight-MinHeight);
|
||||
|
||||
int newSelected = (int) ((float) positionWiimote / (float) (MaxHeight-MinHeight) * (float) (EntrieCount-1));
|
||||
int newSelected = (int) ((float) positionWiimote / (float) (MaxHeight-MinHeight) * (float) (EntrieCount-1));
|
||||
|
||||
if(Mode == ICONMODE)
|
||||
{
|
||||
int rows = (int) floor(((float) (newSelected-SelInd-SelItem)) / ((float) RowSize));
|
||||
if(Mode == ICONMODE)
|
||||
{
|
||||
int rows = (int) floor(((float) (newSelected-SelInd-SelItem)) / ((float) RowSize));
|
||||
|
||||
while(SelInd+rows*RowSize >= EntrieCount-PageSize+RowSize)
|
||||
rows--;
|
||||
while(SelInd+rows*RowSize >= EntrieCount-PageSize+RowSize)
|
||||
rows--;
|
||||
|
||||
int pageIndex = LIMIT(SelInd+rows*RowSize, 0, EntrieCount-1-RowSize);
|
||||
int pageIndex = LIMIT(SelInd+rows*RowSize, 0, EntrieCount-1-RowSize);
|
||||
|
||||
if(newSelected <= 0)
|
||||
SelItem = 0;
|
||||
else if(newSelected >= EntrieCount-1)
|
||||
SelItem = EntrieCount-1-pageIndex;
|
||||
if(newSelected <= 0)
|
||||
SelItem = 0;
|
||||
else if(newSelected >= EntrieCount-1)
|
||||
SelItem = EntrieCount-1-pageIndex;
|
||||
|
||||
SelInd = pageIndex;
|
||||
}
|
||||
else if(Mode == LISTMODE)
|
||||
{
|
||||
int diff = newSelected-SelInd-SelItem;
|
||||
SelInd = pageIndex;
|
||||
}
|
||||
else if(Mode == LISTMODE)
|
||||
{
|
||||
int diff = newSelected-SelInd-SelItem;
|
||||
|
||||
if(newSelected <= 0)
|
||||
{
|
||||
SelItem = 0;
|
||||
SelInd = 0;
|
||||
}
|
||||
else if(newSelected >= EntrieCount-1)
|
||||
{
|
||||
SelItem = (PageSize-1 < EntrieCount-1) ? PageSize-1 : EntrieCount-1;
|
||||
SelInd = EntrieCount-PageSize;
|
||||
}
|
||||
else if(newSelected < PageSize && SelInd == 0 && diff < 0)
|
||||
{
|
||||
SelItem = MAX(SelItem+diff, 0);
|
||||
}
|
||||
else if(EntrieCount-newSelected < PageSize && SelInd == EntrieCount-PageSize && diff > 0)
|
||||
{
|
||||
SelItem = MIN(SelItem+diff, PageSize-1);
|
||||
}
|
||||
else
|
||||
{
|
||||
SelInd = LIMIT(SelInd+diff, 0, ((EntrieCount-PageSize < 0) ? 0 : EntrieCount-PageSize));
|
||||
}
|
||||
}
|
||||
if(newSelected <= 0)
|
||||
{
|
||||
SelItem = 0;
|
||||
SelInd = 0;
|
||||
}
|
||||
else if(newSelected >= EntrieCount-1)
|
||||
{
|
||||
SelItem = (PageSize-1 < EntrieCount-1) ? PageSize-1 : EntrieCount-1;
|
||||
SelInd = EntrieCount-PageSize;
|
||||
}
|
||||
else if(newSelected < PageSize && SelInd == 0 && diff < 0)
|
||||
{
|
||||
SelItem = MAX(SelItem+diff, 0);
|
||||
}
|
||||
else if(EntrieCount-newSelected < PageSize && SelInd == EntrieCount-PageSize && diff > 0)
|
||||
{
|
||||
SelItem = MIN(SelItem+diff, PageSize-1);
|
||||
}
|
||||
else
|
||||
{
|
||||
SelInd = LIMIT(SelInd+diff, 0, ((EntrieCount-PageSize < 0) ? 0 : EntrieCount-PageSize));
|
||||
}
|
||||
}
|
||||
|
||||
ScrollState = 0;
|
||||
listChanged(SelItem, SelInd);
|
||||
ScrollState = 0;
|
||||
listChanged(SelItem, SelInd);
|
||||
}
|
||||
|
||||
void GuiScrollbar::SetPageSize(int size)
|
||||
{
|
||||
if(PageSize == size)
|
||||
return;
|
||||
if(PageSize == size)
|
||||
return;
|
||||
|
||||
PageSize = size;
|
||||
PageSize = size;
|
||||
listChanged(SelItem, SelInd);
|
||||
}
|
||||
|
||||
void GuiScrollbar::SetRowSize(int size)
|
||||
{
|
||||
if(RowSize == size)
|
||||
return;
|
||||
if(RowSize == size)
|
||||
return;
|
||||
|
||||
RowSize = size;
|
||||
RowSize = size;
|
||||
listChanged(SelItem, SelInd);
|
||||
}
|
||||
|
||||
void GuiScrollbar::SetSelectedItem(int pos)
|
||||
{
|
||||
if(SelItem == pos)
|
||||
return;
|
||||
if(SelItem == pos)
|
||||
return;
|
||||
|
||||
SelItem = pos;
|
||||
SelItem = pos;
|
||||
listChanged(SelItem, SelInd);
|
||||
}
|
||||
|
||||
void GuiScrollbar::SetSelectedIndex(int pos)
|
||||
{
|
||||
if(SelInd == pos)
|
||||
return;
|
||||
if(SelInd == pos)
|
||||
return;
|
||||
|
||||
SelInd = pos;
|
||||
SelInd = pos;
|
||||
listChanged(SelItem, SelInd);
|
||||
}
|
||||
|
||||
void GuiScrollbar::SetEntrieCount(int cnt)
|
||||
{
|
||||
if(EntrieCount == cnt)
|
||||
return;
|
||||
if(EntrieCount == cnt)
|
||||
return;
|
||||
|
||||
EntrieCount = cnt;
|
||||
EntrieCount = cnt;
|
||||
listChanged(SelItem, SelInd);
|
||||
}
|
||||
|
||||
void GuiScrollbar::setScrollboxPosition(int SelItem, int SelInd)
|
||||
{
|
||||
if(Mode == ICONMODE)
|
||||
{
|
||||
u8 row = (u8) floor((float) SelItem / (float) RowSize);
|
||||
if(Mode == ICONMODE)
|
||||
{
|
||||
u8 row = (u8) floor((float) SelItem / (float) RowSize);
|
||||
|
||||
int position = MinHeight+(MaxHeight-MinHeight)*(SelInd+row*RowSize)/(EntrieCount-1);
|
||||
int position = MinHeight+(MaxHeight-MinHeight)*(SelInd+row*RowSize)/(EntrieCount-1);
|
||||
|
||||
if(position < MinHeight)
|
||||
position = MinHeight;
|
||||
else if(position > MaxHeight || ((SelInd+PageSize >= (EntrieCount-1)) && row > 1))
|
||||
position = MaxHeight;
|
||||
if(position < MinHeight)
|
||||
position = MinHeight;
|
||||
else if(position > MaxHeight || ((SelInd+PageSize >= (EntrieCount-1)) && row > 1))
|
||||
position = MaxHeight;
|
||||
|
||||
scrollbarBoxBtn->SetPosition(ButtonPositionX, position);
|
||||
}
|
||||
else if(Mode == LISTMODE)
|
||||
{
|
||||
int position = MinHeight+(MaxHeight-MinHeight)*(SelInd+SelItem)/(EntrieCount-1);
|
||||
scrollbarBoxBtn->SetPosition(ButtonPositionX, position);
|
||||
}
|
||||
else if(Mode == LISTMODE)
|
||||
{
|
||||
int position = MinHeight+(MaxHeight-MinHeight)*(SelInd+SelItem)/(EntrieCount-1);
|
||||
|
||||
if(position < MinHeight)
|
||||
position = MinHeight;
|
||||
else if(position > MaxHeight || (SelInd+SelItem >= EntrieCount-1))
|
||||
position = MaxHeight;
|
||||
if(position < MinHeight)
|
||||
position = MinHeight;
|
||||
else if(position > MaxHeight || (SelInd+SelItem >= EntrieCount-1))
|
||||
position = MaxHeight;
|
||||
|
||||
scrollbarBoxBtn->SetPosition(ButtonPositionX, position);
|
||||
}
|
||||
scrollbarBoxBtn->SetPosition(ButtonPositionX, position);
|
||||
}
|
||||
}
|
||||
|
||||
void GuiScrollbar::CheckDPadControls(GuiTrigger *t)
|
||||
{
|
||||
if(t->Up())
|
||||
{
|
||||
ScrollOneUp();
|
||||
listChanged(SelItem, SelInd);
|
||||
ScrollOneUp();
|
||||
listChanged(SelItem, SelInd);
|
||||
}
|
||||
else if(t->Down())
|
||||
{
|
||||
ScrollOneDown();
|
||||
listChanged(SelItem, SelInd);
|
||||
ScrollOneDown();
|
||||
listChanged(SelItem, SelInd);
|
||||
}
|
||||
|
||||
else if(t->Left() && Mode == LISTMODE)
|
||||
{
|
||||
SelInd -= PageSize;
|
||||
if(SelInd < 0)
|
||||
{
|
||||
SelInd = 0;
|
||||
SelItem = 0;
|
||||
}
|
||||
listChanged(SelItem, SelInd);
|
||||
SelInd -= PageSize;
|
||||
if(SelInd < 0)
|
||||
{
|
||||
SelInd = 0;
|
||||
SelItem = 0;
|
||||
}
|
||||
listChanged(SelItem, SelInd);
|
||||
}
|
||||
else if(t->Right() && Mode == LISTMODE)
|
||||
{
|
||||
SelInd += PageSize;
|
||||
if(SelInd+PageSize >= EntrieCount)
|
||||
{
|
||||
SelInd = EntrieCount-PageSize;
|
||||
SelItem = PageSize-1;
|
||||
}
|
||||
listChanged(SelItem, SelInd);
|
||||
SelInd += PageSize;
|
||||
if(SelInd+PageSize >= EntrieCount)
|
||||
{
|
||||
SelInd = EntrieCount-PageSize;
|
||||
SelItem = PageSize-1;
|
||||
}
|
||||
listChanged(SelItem, SelInd);
|
||||
}
|
||||
}
|
||||
|
||||
void GuiScrollbar::ScrollByButton(GuiTrigger *t)
|
||||
{
|
||||
static int pressedPosition = -1;
|
||||
static int pressedPosition = -1;
|
||||
|
||||
if(!t->wpad.ir.valid || ScrollState < ButtonScrollSpeed-ButtonScrollSpeed*fabs(pressedPosition-t->wpad.ir.y)/250.f)
|
||||
return;
|
||||
if(!t->wpad.ir.valid || ScrollState < ButtonScrollSpeed-ButtonScrollSpeed*fabs(pressedPosition-t->wpad.ir.y)/250.f)
|
||||
return;
|
||||
|
||||
if(pressedChan == -1 && (t->wpad.btns_d & ButtonScroll) &&
|
||||
parentElement && parentElement->IsInside(t->wpad.ir.x, t->wpad.ir.y))
|
||||
{
|
||||
pressedPosition = t->wpad.ir.y;
|
||||
pressedChan = t->chan;
|
||||
oneButtonScrollImg->SetPosition(t->wpad.ir.x-oneButtonScrollImg->GetWidth()/2, t->wpad.ir.y-oneButtonScrollImg->GetHeight()/2);
|
||||
}
|
||||
if(pressedChan == -1 && (t->wpad.btns_d & ButtonScroll) &&
|
||||
parentElement && parentElement->IsInside(t->wpad.ir.x, t->wpad.ir.y))
|
||||
{
|
||||
pressedPosition = t->wpad.ir.y;
|
||||
pressedChan = t->chan;
|
||||
oneButtonScrollImg->SetPosition(t->wpad.ir.x-oneButtonScrollImg->GetWidth()/2, t->wpad.ir.y-oneButtonScrollImg->GetHeight()/2);
|
||||
}
|
||||
|
||||
if(pressedChan == t->chan && (t->wpad.btns_h & ButtonScroll))
|
||||
{
|
||||
if(pressedPosition-oneButtonScrollImg->GetHeight()/2 > t->wpad.ir.y)
|
||||
ScrollOneUp();
|
||||
else if(pressedPosition+oneButtonScrollImg->GetHeight()/2 < t->wpad.ir.y)
|
||||
ScrollOneDown();
|
||||
if(pressedChan == t->chan && (t->wpad.btns_h & ButtonScroll))
|
||||
{
|
||||
if(pressedPosition-oneButtonScrollImg->GetHeight()/2 > t->wpad.ir.y)
|
||||
ScrollOneUp();
|
||||
else if(pressedPosition+oneButtonScrollImg->GetHeight()/2 < t->wpad.ir.y)
|
||||
ScrollOneDown();
|
||||
|
||||
ScrollState = 0;
|
||||
listChanged(SelItem, SelInd);
|
||||
}
|
||||
ScrollState = 0;
|
||||
listChanged(SelItem, SelInd);
|
||||
}
|
||||
|
||||
if(pressedChan == t->chan && !t->wpad.btns_d && !t->wpad.btns_h)
|
||||
{
|
||||
pressedChan = -1;
|
||||
pressedPosition = -1;
|
||||
}
|
||||
if(pressedChan == t->chan && !t->wpad.btns_d && !t->wpad.btns_h)
|
||||
{
|
||||
pressedChan = -1;
|
||||
pressedPosition = -1;
|
||||
}
|
||||
}
|
||||
|
||||
void GuiScrollbar::Draw()
|
||||
|
@ -462,7 +462,7 @@ void GuiScrollbar::Draw()
|
|||
arrowDownBtn->Draw();
|
||||
scrollbarBoxBtn->Draw();
|
||||
if(pressedChan >= 0 && userInput[pressedChan].wpad.ir.valid)
|
||||
oneButtonScrollImg->Draw();
|
||||
oneButtonScrollImg->Draw();
|
||||
|
||||
UpdateEffects();
|
||||
}
|
||||
|
@ -472,10 +472,10 @@ void GuiScrollbar::Update(GuiTrigger * t)
|
|||
arrowUpBtn->Update(t);
|
||||
arrowDownBtn->Update(t);
|
||||
scrollbarBoxBtn->Update(t);
|
||||
if(AllowDPad)
|
||||
CheckDPadControls(t);
|
||||
if(ButtonScroll)
|
||||
ScrollByButton(t);
|
||||
if(AllowDPad)
|
||||
CheckDPadControls(t);
|
||||
if(ButtonScroll)
|
||||
ScrollByButton(t);
|
||||
|
||||
++ScrollState;
|
||||
++ScrollState;
|
||||
}
|
||||
|
|
|
@ -28,57 +28,57 @@
|
|||
|
||||
class GuiScrollbar : public GuiElement, public sigslot::has_slots<>
|
||||
{
|
||||
public:
|
||||
GuiScrollbar(int height, u8 mode = LISTMODE);
|
||||
virtual ~GuiScrollbar();
|
||||
void SetDPadControl(bool a) { AllowDPad = a; }
|
||||
void SetButtonScroll(u32 button) { ButtonScroll = button; }
|
||||
void ScrollOneUp();
|
||||
void ScrollOneDown();
|
||||
int GetSelectedItem() { return SelItem; };
|
||||
int GetSelectedIndex() { return SelInd; };
|
||||
void SetScrollSpeed(u16 speed) { ScrollSpeed = speed; };
|
||||
void SetButtonScrollSpeed(u16 speed) { ButtonScrollSpeed = speed; };
|
||||
void Draw();
|
||||
void Update(GuiTrigger * t);
|
||||
enum
|
||||
{
|
||||
ICONMODE = 0,
|
||||
LISTMODE,
|
||||
};
|
||||
//! Signals
|
||||
public:
|
||||
GuiScrollbar(int height, u8 mode = LISTMODE);
|
||||
virtual ~GuiScrollbar();
|
||||
void SetDPadControl(bool a) { AllowDPad = a; }
|
||||
void SetButtonScroll(u32 button) { ButtonScroll = button; }
|
||||
void ScrollOneUp();
|
||||
void ScrollOneDown();
|
||||
int GetSelectedItem() { return SelItem; };
|
||||
int GetSelectedIndex() { return SelInd; };
|
||||
void SetScrollSpeed(u16 speed) { ScrollSpeed = speed; };
|
||||
void SetButtonScrollSpeed(u16 speed) { ButtonScrollSpeed = speed; };
|
||||
void Draw();
|
||||
void Update(GuiTrigger * t);
|
||||
enum
|
||||
{
|
||||
ICONMODE = 0,
|
||||
LISTMODE,
|
||||
};
|
||||
//! Signals
|
||||
sigslot::signal2<int, int> listChanged;
|
||||
//! Slots
|
||||
void SetPageSize(int size);
|
||||
void SetRowSize(int size);
|
||||
void SetSelectedItem(int pos);
|
||||
void SetSelectedIndex(int pos);
|
||||
void SetEntrieCount(int cnt);
|
||||
protected:
|
||||
void setScrollboxPosition(int SelItem, int SelInd);
|
||||
void OnUpButtonHold(GuiButton *sender, int pointer, const POINT &p);
|
||||
void OnDownButtonHold(GuiButton *sender, int pointer, const POINT &p);
|
||||
void OnBoxButtonHold(GuiButton *sender, int pointer, const POINT &p);
|
||||
void CheckDPadControls(GuiTrigger *t);
|
||||
void ScrollByButton(GuiTrigger *t);
|
||||
void SetPageSize(int size);
|
||||
void SetRowSize(int size);
|
||||
void SetSelectedItem(int pos);
|
||||
void SetSelectedIndex(int pos);
|
||||
void SetEntrieCount(int cnt);
|
||||
protected:
|
||||
void setScrollboxPosition(int SelItem, int SelInd);
|
||||
void OnUpButtonHold(GuiButton *sender, int pointer, const POINT &p);
|
||||
void OnDownButtonHold(GuiButton *sender, int pointer, const POINT &p);
|
||||
void OnBoxButtonHold(GuiButton *sender, int pointer, const POINT &p);
|
||||
void CheckDPadControls(GuiTrigger *t);
|
||||
void ScrollByButton(GuiTrigger *t);
|
||||
|
||||
u8 Mode;
|
||||
u32 ScrollState;
|
||||
u16 ScrollSpeed;
|
||||
u16 ButtonScrollSpeed;
|
||||
u32 ButtonScroll;
|
||||
bool AllowDPad;
|
||||
u8 Mode;
|
||||
u32 ScrollState;
|
||||
u16 ScrollSpeed;
|
||||
u16 ButtonScrollSpeed;
|
||||
u32 ButtonScroll;
|
||||
bool AllowDPad;
|
||||
|
||||
int MinHeight;
|
||||
int MaxHeight;
|
||||
int SelItem;
|
||||
int SelInd;
|
||||
int RowSize;
|
||||
int PageSize;
|
||||
int EntrieCount;
|
||||
int ButtonPositionX;
|
||||
int pressedChan;
|
||||
bool listchanged;
|
||||
int MinHeight;
|
||||
int MaxHeight;
|
||||
int SelItem;
|
||||
int SelInd;
|
||||
int RowSize;
|
||||
int PageSize;
|
||||
int EntrieCount;
|
||||
int ButtonPositionX;
|
||||
int pressedChan;
|
||||
bool listchanged;
|
||||
|
||||
GuiButton * arrowUpBtn;
|
||||
GuiButton * arrowDownBtn;
|
||||
|
|
|
@ -11,157 +11,157 @@ extern GuiWindow * mainWindow;
|
|||
|
||||
class cSearchButton
|
||||
{
|
||||
public:
|
||||
cSearchButton(wchar_t *Char, GuiImageData *keyImageData, GuiImageData *keyOverImageData, int x, int y,
|
||||
GuiTrigger* trig, GuiSound* sndOver, GuiSound* sndClick) :
|
||||
wchar(*Char), image(keyImageData), imageOver(keyOverImageData), text((char *) NULL, 20, ( GXColor )
|
||||
{ 0, 0, 0, 0xff}), button(&image, &imageOver, ALIGN_LEFT, ALIGN_TOP, x, y, trig, sndOver, sndClick, 1)
|
||||
{
|
||||
text.SetText(Char);
|
||||
button.SetLabel(&text);
|
||||
}
|
||||
wchar_t wchar;
|
||||
GuiImage image;
|
||||
GuiImage imageOver;
|
||||
GuiText text;
|
||||
GuiButton button;
|
||||
private:
|
||||
public:
|
||||
cSearchButton(wchar_t *Char, GuiImageData *keyImageData, GuiImageData *keyOverImageData, int x, int y,
|
||||
GuiTrigger* trig, GuiSound* sndOver, GuiSound* sndClick) :
|
||||
wchar(*Char), image(keyImageData), imageOver(keyOverImageData), text((char *) NULL, 20, ( GXColor )
|
||||
{ 0, 0, 0, 0xff}), button(&image, &imageOver, ALIGN_LEFT, ALIGN_TOP, x, y, trig, sndOver, sndClick, 1)
|
||||
{
|
||||
text.SetText(Char);
|
||||
button.SetLabel(&text);
|
||||
}
|
||||
wchar_t wchar;
|
||||
GuiImage image;
|
||||
GuiImage imageOver;
|
||||
GuiText text;
|
||||
GuiButton button;
|
||||
private:
|
||||
|
||||
};
|
||||
|
||||
GuiSearchBar::GuiSearchBar(const wchar_t *SearchChars) :
|
||||
inSide(0), text((char *) NULL, 22, ( GXColor )
|
||||
{ 0, 0, 0, 255}), buttons(0),
|
||||
inSide(0), text((char *) NULL, 22, ( GXColor )
|
||||
{ 0, 0, 0, 255}), buttons(0),
|
||||
keyImageData(Resources::GetFile("keyboard_key.png"), Resources::GetFileSize("keyboard_key.png")),
|
||||
keyOverImageData(Resources::GetFile("keyboard_key_over.png"), Resources::GetFileSize("keyboard_key_over.png"))
|
||||
{
|
||||
trig.SetSimpleTrigger(-1, WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A, PAD_BUTTON_A);
|
||||
trigB.SetButtonOnlyTrigger(-1, WPAD_BUTTON_B | WPAD_CLASSIC_BUTTON_B, PAD_BUTTON_B);
|
||||
SetAlignment(ALIGN_CENTRE, ALIGN_MIDDLE);
|
||||
trig.SetSimpleTrigger(-1, WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A, PAD_BUTTON_A);
|
||||
trigB.SetButtonOnlyTrigger(-1, WPAD_BUTTON_B | WPAD_CLASSIC_BUTTON_B, PAD_BUTTON_B);
|
||||
SetAlignment(ALIGN_CENTRE, ALIGN_MIDDLE);
|
||||
|
||||
cnt = wcslen(SearchChars);
|
||||
buttons = new cSearchButton*[cnt];
|
||||
cnt = wcslen(SearchChars);
|
||||
buttons = new cSearchButton*[cnt];
|
||||
|
||||
wchar_t charstr[2] = { 0, 0 };
|
||||
int lines = (cnt + 9) / 10;
|
||||
int buttonsPerLine = (cnt + lines - 1) / lines;
|
||||
width = 10 + buttonsPerLine * 42 + 10;
|
||||
int x_start = 10, x = 0, y_start = 10 + 42, y = 0;
|
||||
if (width < 200)
|
||||
{
|
||||
x_start += (200 - width) >> 1;
|
||||
width = 200;
|
||||
}
|
||||
for (int i = 0; i < cnt; i++, x++)
|
||||
{
|
||||
if (x >= buttonsPerLine) x = 0;
|
||||
if (x == 0) y++;
|
||||
charstr[0] = SearchChars[i];
|
||||
buttons[i] = new cSearchButton(charstr, &keyImageData, &keyOverImageData, x_start + x * 42, y_start - 42 + y
|
||||
* 42, &trig, btnSoundOver, btnSoundClick);
|
||||
this->Append(&(buttons[i]->button));
|
||||
}
|
||||
height = 10 + 42 + y * 42 + 10;
|
||||
wchar_t charstr[2] = { 0, 0 };
|
||||
int lines = (cnt + 9) / 10;
|
||||
int buttonsPerLine = (cnt + lines - 1) / lines;
|
||||
width = 10 + buttonsPerLine * 42 + 10;
|
||||
int x_start = 10, x = 0, y_start = 10 + 42, y = 0;
|
||||
if (width < 200)
|
||||
{
|
||||
x_start += (200 - width) >> 1;
|
||||
width = 200;
|
||||
}
|
||||
for (int i = 0; i < cnt; i++, x++)
|
||||
{
|
||||
if (x >= buttonsPerLine) x = 0;
|
||||
if (x == 0) y++;
|
||||
charstr[0] = SearchChars[i];
|
||||
buttons[i] = new cSearchButton(charstr, &keyImageData, &keyOverImageData, x_start + x * 42, y_start - 42 + y
|
||||
* 42, &trig, btnSoundOver, btnSoundClick);
|
||||
this->Append(&(buttons[i]->button));
|
||||
}
|
||||
height = 10 + 42 + y * 42 + 10;
|
||||
|
||||
text.SetText(gameList.GetCurrentFilter());
|
||||
text.SetPosition(10, 15);
|
||||
text.SetAlignment(ALIGN_LEFT, ALIGN_TOP);
|
||||
text.SetWidescreen(Settings.widescreen);
|
||||
text.SetMaxWidth(width - (10 + 2 * 42 + 10), SCROLL_HORIZONTAL);
|
||||
this->Append(&text);
|
||||
text.SetText(gameList.GetCurrentFilter());
|
||||
text.SetPosition(10, 15);
|
||||
text.SetAlignment(ALIGN_LEFT, ALIGN_TOP);
|
||||
text.SetWidescreen(Settings.widescreen);
|
||||
text.SetMaxWidth(width - (10 + 2 * 42 + 10), SCROLL_HORIZONTAL);
|
||||
this->Append(&text);
|
||||
|
||||
imgBacspaceBtn = Resources::GetImageData("keyboard_backspace_over.png");
|
||||
BacspaceBtnImg_Over = new GuiImage(imgBacspaceBtn);
|
||||
BacspaceBtnImg = new GuiImage(BacspaceBtnImg_Over);
|
||||
BacspaceBtnImg->SetGrayscale();
|
||||
BacspaceBtn = new GuiButton(BacspaceBtnImg, BacspaceBtnImg_Over, ALIGN_RIGHT, ALIGN_TOP, -52, 10, &trig, btnSoundOver, btnSoundClick, 1);
|
||||
this->Append(BacspaceBtn);
|
||||
imgBacspaceBtn = Resources::GetImageData("keyboard_backspace_over.png");
|
||||
BacspaceBtnImg_Over = new GuiImage(imgBacspaceBtn);
|
||||
BacspaceBtnImg = new GuiImage(BacspaceBtnImg_Over);
|
||||
BacspaceBtnImg->SetGrayscale();
|
||||
BacspaceBtn = new GuiButton(BacspaceBtnImg, BacspaceBtnImg_Over, ALIGN_RIGHT, ALIGN_TOP, -52, 10, &trig, btnSoundOver, btnSoundClick, 1);
|
||||
this->Append(BacspaceBtn);
|
||||
|
||||
imgClearBtn = Resources::GetImageData("keyboard_clear_over.png");
|
||||
ClearBtnImg_Over = new GuiImage(imgClearBtn);
|
||||
ClearBtnImg = new GuiImage(ClearBtnImg_Over);
|
||||
ClearBtnImg->SetGrayscale();
|
||||
ClearBtn = new GuiButton(ClearBtnImg, ClearBtnImg_Over, ALIGN_RIGHT, ALIGN_TOP, -10, 10, &trig, btnSoundOver, btnSoundClick, 1);
|
||||
this->Append(ClearBtn);
|
||||
imgClearBtn = Resources::GetImageData("keyboard_clear_over.png");
|
||||
ClearBtnImg_Over = new GuiImage(imgClearBtn);
|
||||
ClearBtnImg = new GuiImage(ClearBtnImg_Over);
|
||||
ClearBtnImg->SetGrayscale();
|
||||
ClearBtn = new GuiButton(ClearBtnImg, ClearBtnImg_Over, ALIGN_RIGHT, ALIGN_TOP, -10, 10, &trig, btnSoundOver, btnSoundClick, 1);
|
||||
this->Append(ClearBtn);
|
||||
|
||||
CloseBtn = new GuiButton(0, 0);
|
||||
CloseBtn->SetTrigger(&trigB);
|
||||
this->Append(CloseBtn);
|
||||
CloseBtn = new GuiButton(0, 0);
|
||||
CloseBtn->SetTrigger(&trigB);
|
||||
this->Append(CloseBtn);
|
||||
|
||||
// SetPosition(100,100);
|
||||
// SetPosition(100,100);
|
||||
|
||||
}
|
||||
GuiSearchBar::~GuiSearchBar()
|
||||
{
|
||||
if (buttons)
|
||||
{
|
||||
for (int i = 0; i < cnt; i++)
|
||||
delete buttons[i];
|
||||
delete[] buttons;
|
||||
}
|
||||
delete ClearBtn;
|
||||
delete ClearBtnImg;
|
||||
delete ClearBtnImg_Over;
|
||||
delete imgClearBtn;
|
||||
if (buttons)
|
||||
{
|
||||
for (int i = 0; i < cnt; i++)
|
||||
delete buttons[i];
|
||||
delete[] buttons;
|
||||
}
|
||||
delete ClearBtn;
|
||||
delete ClearBtnImg;
|
||||
delete ClearBtnImg_Over;
|
||||
delete imgClearBtn;
|
||||
|
||||
delete CloseBtn;
|
||||
delete CloseBtn;
|
||||
|
||||
delete BacspaceBtn;
|
||||
delete BacspaceBtnImg;
|
||||
delete BacspaceBtnImg_Over;
|
||||
delete imgBacspaceBtn;
|
||||
if (inSide) mainWindow->SetState(STATE_DEFAULT);
|
||||
delete BacspaceBtn;
|
||||
delete BacspaceBtnImg;
|
||||
delete BacspaceBtnImg_Over;
|
||||
delete imgBacspaceBtn;
|
||||
if (inSide) mainWindow->SetState(STATE_DEFAULT);
|
||||
}
|
||||
void GuiSearchBar::Draw()
|
||||
{
|
||||
Menu_DrawRectangle(this->GetLeft(), this->GetTop(), width, height, ( GXColor )
|
||||
{ 0, 0, 0, 0xa0}, 1);
|
||||
Menu_DrawRectangle(this->GetLeft() + 10, this->GetTop() + 15, width - (10 + 2 * 42 + 10), 22, ( GXColor )
|
||||
{ 255, 255, 255, 255}, 1);
|
||||
GuiWindow::Draw();
|
||||
Menu_DrawRectangle(this->GetLeft(), this->GetTop(), width, height, ( GXColor )
|
||||
{ 0, 0, 0, 0xa0}, 1);
|
||||
Menu_DrawRectangle(this->GetLeft() + 10, this->GetTop() + 15, width - (10 + 2 * 42 + 10), 22, ( GXColor )
|
||||
{ 255, 255, 255, 255}, 1);
|
||||
GuiWindow::Draw();
|
||||
}
|
||||
void GuiSearchBar::Update(GuiTrigger * t)
|
||||
{
|
||||
LOCK( this );
|
||||
if (_elements.size() == 0 || (state == STATE_DISABLED && parentElement)) return;
|
||||
// cursor
|
||||
if (t->wpad.ir.valid && state != STATE_DISABLED)
|
||||
{
|
||||
if (this->IsInside(t->wpad.ir.x, t->wpad.ir.y))
|
||||
{
|
||||
if (inSide == 0)
|
||||
{
|
||||
mainWindow->SetState(STATE_DISABLED);
|
||||
this->SetState(STATE_DEFAULT);
|
||||
}
|
||||
inSide |= 1 << t->chan;
|
||||
}
|
||||
else if (inSide)
|
||||
{
|
||||
inSide &= ~(1 << t->chan);
|
||||
if (inSide == 0) mainWindow->SetState(STATE_DEFAULT);
|
||||
}
|
||||
}
|
||||
GuiWindow::Update(t);
|
||||
LOCK( this );
|
||||
if (_elements.size() == 0 || (state == STATE_DISABLED && parentElement)) return;
|
||||
// cursor
|
||||
if (t->wpad.ir.valid && state != STATE_DISABLED)
|
||||
{
|
||||
if (this->IsInside(t->wpad.ir.x, t->wpad.ir.y))
|
||||
{
|
||||
if (inSide == 0)
|
||||
{
|
||||
mainWindow->SetState(STATE_DISABLED);
|
||||
this->SetState(STATE_DEFAULT);
|
||||
}
|
||||
inSide |= 1 << t->chan;
|
||||
}
|
||||
else if (inSide)
|
||||
{
|
||||
inSide &= ~(1 << t->chan);
|
||||
if (inSide == 0) mainWindow->SetState(STATE_DEFAULT);
|
||||
}
|
||||
}
|
||||
GuiWindow::Update(t);
|
||||
}
|
||||
wchar_t GuiSearchBar::GetClicked()
|
||||
{
|
||||
if (buttons)
|
||||
{
|
||||
for (int i = 0; i < cnt; i++)
|
||||
{
|
||||
if (buttons[i]->button.GetState() == STATE_CLICKED)
|
||||
{
|
||||
buttons[i]->button.ResetState();
|
||||
return buttons[i]->wchar;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (BacspaceBtn->GetState() == STATE_CLICKED) return 8;
|
||||
else if (ClearBtn->GetState() == STATE_CLICKED) return 7;
|
||||
else if (CloseBtn->GetState() == STATE_CLICKED) return 27;
|
||||
if (buttons)
|
||||
{
|
||||
for (int i = 0; i < cnt; i++)
|
||||
{
|
||||
if (buttons[i]->button.GetState() == STATE_CLICKED)
|
||||
{
|
||||
buttons[i]->button.ResetState();
|
||||
return buttons[i]->wchar;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (BacspaceBtn->GetState() == STATE_CLICKED) return 8;
|
||||
else if (ClearBtn->GetState() == STATE_CLICKED) return 7;
|
||||
else if (CloseBtn->GetState() == STATE_CLICKED) return 27;
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -6,35 +6,35 @@ class cSearchButton;
|
|||
|
||||
class GuiSearchBar: public GuiWindow
|
||||
{
|
||||
public:
|
||||
GuiSearchBar(const wchar_t *SearchChars);
|
||||
virtual ~GuiSearchBar();
|
||||
void Draw();
|
||||
void Update(GuiTrigger * t);
|
||||
wchar_t GetClicked();
|
||||
private:
|
||||
u16 inSide;
|
||||
public:
|
||||
GuiSearchBar(const wchar_t *SearchChars);
|
||||
virtual ~GuiSearchBar();
|
||||
void Draw();
|
||||
void Update(GuiTrigger * t);
|
||||
wchar_t GetClicked();
|
||||
private:
|
||||
u16 inSide;
|
||||
|
||||
GuiText text;
|
||||
GuiText text;
|
||||
|
||||
GuiImageData* imgBacspaceBtn;
|
||||
GuiImage* BacspaceBtnImg;
|
||||
GuiImage* BacspaceBtnImg_Over;
|
||||
GuiButton* BacspaceBtn;
|
||||
GuiImageData* imgBacspaceBtn;
|
||||
GuiImage* BacspaceBtnImg;
|
||||
GuiImage* BacspaceBtnImg_Over;
|
||||
GuiButton* BacspaceBtn;
|
||||
|
||||
GuiImageData* imgClearBtn;
|
||||
GuiImage* ClearBtnImg;
|
||||
GuiImage* ClearBtnImg_Over;
|
||||
GuiButton* ClearBtn;
|
||||
GuiImageData* imgClearBtn;
|
||||
GuiImage* ClearBtnImg;
|
||||
GuiImage* ClearBtnImg_Over;
|
||||
GuiButton* ClearBtn;
|
||||
|
||||
GuiButton* CloseBtn;
|
||||
GuiButton* CloseBtn;
|
||||
|
||||
cSearchButton **buttons;
|
||||
int cnt;
|
||||
GuiImageData keyImageData;
|
||||
GuiImageData keyOverImageData;
|
||||
GuiTrigger trig;
|
||||
GuiTrigger trigB;
|
||||
cSearchButton **buttons;
|
||||
int cnt;
|
||||
GuiImageData keyImageData;
|
||||
GuiImageData keyOverImageData;
|
||||
GuiTrigger trig;
|
||||
GuiTrigger trigB;
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@ static int presetAlignmentVert = 0;
|
|||
static u16 presetStyle = 0;
|
||||
static GXColor presetColor = (GXColor) {255, 255, 255, 255};
|
||||
|
||||
#define TEXT_SCROLL_DELAY 5
|
||||
#define TEXT_SCROLL_DELAY 5
|
||||
#define TEXT_SCROLL_INITIAL_DELAY 8
|
||||
|
||||
/**
|
||||
|
@ -31,62 +31,62 @@ static GXColor presetColor = (GXColor) {255, 255, 255, 255};
|
|||
|
||||
GuiText::GuiText(const char * t, int s, GXColor c)
|
||||
{
|
||||
text = NULL;
|
||||
size = (int) (s * Settings.FontScaleFactor);
|
||||
currentSize = size;
|
||||
color = c;
|
||||
alpha = c.a;
|
||||
style = FTGX_JUSTIFY_CENTER | FTGX_ALIGN_MIDDLE;
|
||||
maxWidth = 0;
|
||||
wrapMode = 0;
|
||||
passChar = 0;
|
||||
font = NULL;
|
||||
linestodraw = MAX_LINES_TO_DRAW;
|
||||
textScrollPos = 0;
|
||||
textScrollInitialDelay = TEXT_SCROLL_INITIAL_DELAY;
|
||||
textScrollDelay = TEXT_SCROLL_DELAY;
|
||||
text = NULL;
|
||||
size = (int) (s * Settings.FontScaleFactor);
|
||||
currentSize = size;
|
||||
color = c;
|
||||
alpha = c.a;
|
||||
style = FTGX_JUSTIFY_CENTER | FTGX_ALIGN_MIDDLE;
|
||||
maxWidth = 0;
|
||||
wrapMode = 0;
|
||||
passChar = 0;
|
||||
font = NULL;
|
||||
linestodraw = MAX_LINES_TO_DRAW;
|
||||
textScrollPos = 0;
|
||||
textScrollInitialDelay = TEXT_SCROLL_INITIAL_DELAY;
|
||||
textScrollDelay = TEXT_SCROLL_DELAY;
|
||||
|
||||
alignmentHor = ALIGN_CENTRE;
|
||||
alignmentVert = ALIGN_MIDDLE;
|
||||
alignmentHor = ALIGN_CENTRE;
|
||||
alignmentVert = ALIGN_MIDDLE;
|
||||
|
||||
if (t)
|
||||
{
|
||||
text = charToWideChar(t);
|
||||
if (!text) return;
|
||||
if (t)
|
||||
{
|
||||
text = charToWideChar(t);
|
||||
if (!text) return;
|
||||
|
||||
textWidth = fontSystem->getWidth(text, currentSize);
|
||||
}
|
||||
textWidth = fontSystem->getWidth(text, currentSize);
|
||||
}
|
||||
}
|
||||
|
||||
GuiText::GuiText(const wchar_t * t, int s, GXColor c)
|
||||
{
|
||||
text = NULL;
|
||||
size = (int) (s * Settings.FontScaleFactor);
|
||||
currentSize = size;
|
||||
color = c;
|
||||
alpha = c.a;
|
||||
style = FTGX_JUSTIFY_CENTER | FTGX_ALIGN_MIDDLE;
|
||||
maxWidth = 0;
|
||||
wrapMode = 0;
|
||||
passChar = 0;
|
||||
font = NULL;
|
||||
linestodraw = MAX_LINES_TO_DRAW;
|
||||
textScrollPos = 0;
|
||||
textScrollInitialDelay = TEXT_SCROLL_INITIAL_DELAY;
|
||||
textScrollDelay = TEXT_SCROLL_DELAY;
|
||||
text = NULL;
|
||||
size = (int) (s * Settings.FontScaleFactor);
|
||||
currentSize = size;
|
||||
color = c;
|
||||
alpha = c.a;
|
||||
style = FTGX_JUSTIFY_CENTER | FTGX_ALIGN_MIDDLE;
|
||||
maxWidth = 0;
|
||||
wrapMode = 0;
|
||||
passChar = 0;
|
||||
font = NULL;
|
||||
linestodraw = MAX_LINES_TO_DRAW;
|
||||
textScrollPos = 0;
|
||||
textScrollInitialDelay = TEXT_SCROLL_INITIAL_DELAY;
|
||||
textScrollDelay = TEXT_SCROLL_DELAY;
|
||||
|
||||
alignmentHor = ALIGN_CENTRE;
|
||||
alignmentVert = ALIGN_MIDDLE;
|
||||
alignmentHor = ALIGN_CENTRE;
|
||||
alignmentVert = ALIGN_MIDDLE;
|
||||
|
||||
if (t)
|
||||
{
|
||||
text = new (std::nothrow) wchar_t[wcslen(t) + 1];
|
||||
if (!text) return;
|
||||
if (t)
|
||||
{
|
||||
text = new (std::nothrow) wchar_t[wcslen(t) + 1];
|
||||
if (!text) return;
|
||||
|
||||
wcscpy(text, t);
|
||||
wcscpy(text, t);
|
||||
|
||||
textWidth = fontSystem->getWidth(text, currentSize);
|
||||
}
|
||||
textWidth = fontSystem->getWidth(text, currentSize);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -94,31 +94,31 @@ GuiText::GuiText(const wchar_t * t, int s, GXColor c)
|
|||
*/
|
||||
GuiText::GuiText(const char * t)
|
||||
{
|
||||
text = NULL;
|
||||
size = (int) (presetSize * Settings.FontScaleFactor);
|
||||
currentSize = size;
|
||||
color = presetColor;
|
||||
alpha = presetColor.a;
|
||||
style = presetStyle;
|
||||
maxWidth = presetMaxWidth;
|
||||
wrapMode = 0;
|
||||
passChar = 0;
|
||||
font = NULL;
|
||||
linestodraw = MAX_LINES_TO_DRAW;
|
||||
textScrollPos = 0;
|
||||
textScrollInitialDelay = TEXT_SCROLL_INITIAL_DELAY;
|
||||
textScrollDelay = TEXT_SCROLL_DELAY;
|
||||
text = NULL;
|
||||
size = (int) (presetSize * Settings.FontScaleFactor);
|
||||
currentSize = size;
|
||||
color = presetColor;
|
||||
alpha = presetColor.a;
|
||||
style = presetStyle;
|
||||
maxWidth = presetMaxWidth;
|
||||
wrapMode = 0;
|
||||
passChar = 0;
|
||||
font = NULL;
|
||||
linestodraw = MAX_LINES_TO_DRAW;
|
||||
textScrollPos = 0;
|
||||
textScrollInitialDelay = TEXT_SCROLL_INITIAL_DELAY;
|
||||
textScrollDelay = TEXT_SCROLL_DELAY;
|
||||
|
||||
alignmentHor = presetAlignmentHor;
|
||||
alignmentVert = presetAlignmentVert;
|
||||
alignmentHor = presetAlignmentHor;
|
||||
alignmentVert = presetAlignmentVert;
|
||||
|
||||
if (t)
|
||||
{
|
||||
text = charToWideChar(t);
|
||||
if (!text) return;
|
||||
if (t)
|
||||
{
|
||||
text = charToWideChar(t);
|
||||
if (!text) return;
|
||||
|
||||
textWidth = fontSystem->getWidth(text, currentSize);
|
||||
}
|
||||
textWidth = fontSystem->getWidth(text, currentSize);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -126,222 +126,222 @@ GuiText::GuiText(const char * t)
|
|||
*/
|
||||
GuiText::~GuiText()
|
||||
{
|
||||
if (text) delete[] text;
|
||||
text = NULL;
|
||||
if (text) delete[] text;
|
||||
text = NULL;
|
||||
|
||||
if (font)
|
||||
{
|
||||
delete font;
|
||||
font = NULL;
|
||||
}
|
||||
if (font)
|
||||
{
|
||||
delete font;
|
||||
font = NULL;
|
||||
}
|
||||
|
||||
ClearDynamicText();
|
||||
ClearDynamicText();
|
||||
}
|
||||
|
||||
void GuiText::SetText(const char * t)
|
||||
{
|
||||
LOCK( this );
|
||||
LOCK( this );
|
||||
|
||||
if (text) delete[] text;
|
||||
text = NULL;
|
||||
if (text) delete[] text;
|
||||
text = NULL;
|
||||
|
||||
ClearDynamicText();
|
||||
ClearDynamicText();
|
||||
|
||||
textScrollPos = 0;
|
||||
textScrollInitialDelay = TEXT_SCROLL_INITIAL_DELAY;
|
||||
textScrollPos = 0;
|
||||
textScrollInitialDelay = TEXT_SCROLL_INITIAL_DELAY;
|
||||
|
||||
if (t)
|
||||
{
|
||||
text = charToWideChar(t);
|
||||
if (!text) return;
|
||||
if (t)
|
||||
{
|
||||
text = charToWideChar(t);
|
||||
if (!text) return;
|
||||
|
||||
if (passChar != 0)
|
||||
{
|
||||
for (u8 i = 0; i < wcslen(text); i++)
|
||||
text[i] = passChar;
|
||||
}
|
||||
if (passChar != 0)
|
||||
{
|
||||
for (u8 i = 0; i < wcslen(text); i++)
|
||||
text[i] = passChar;
|
||||
}
|
||||
|
||||
textWidth = fontSystem->getWidth(text, currentSize);
|
||||
}
|
||||
textWidth = fontSystem->getWidth(text, currentSize);
|
||||
}
|
||||
}
|
||||
|
||||
void GuiText::SetTextf(const char *format, ...)
|
||||
{
|
||||
if (!format) SetText((char *) NULL);
|
||||
if (!format) SetText((char *) NULL);
|
||||
|
||||
char *tmp = 0;
|
||||
va_list va;
|
||||
va_start( va, format );
|
||||
if ((vasprintf(&tmp, format, va) >= 0) && tmp)
|
||||
{
|
||||
SetText(tmp);
|
||||
}
|
||||
va_end( va );
|
||||
char *tmp = 0;
|
||||
va_list va;
|
||||
va_start( va, format );
|
||||
if ((vasprintf(&tmp, format, va) >= 0) && tmp)
|
||||
{
|
||||
SetText(tmp);
|
||||
}
|
||||
va_end( va );
|
||||
|
||||
if (tmp) free(tmp);
|
||||
if (tmp) free(tmp);
|
||||
}
|
||||
|
||||
void GuiText::SetText(const wchar_t * t)
|
||||
{
|
||||
LOCK( this );
|
||||
LOCK( this );
|
||||
|
||||
if (text)
|
||||
delete [] text;
|
||||
text = NULL;
|
||||
if (text)
|
||||
delete [] text;
|
||||
text = NULL;
|
||||
|
||||
ClearDynamicText();
|
||||
ClearDynamicText();
|
||||
|
||||
textScrollPos = 0;
|
||||
textScrollInitialDelay = TEXT_SCROLL_INITIAL_DELAY;
|
||||
textScrollPos = 0;
|
||||
textScrollInitialDelay = TEXT_SCROLL_INITIAL_DELAY;
|
||||
|
||||
if (t)
|
||||
{
|
||||
text = new (std::nothrow) wchar_t[wcslen(t) + 1];
|
||||
if (!text) return;
|
||||
if (t)
|
||||
{
|
||||
text = new (std::nothrow) wchar_t[wcslen(t) + 1];
|
||||
if (!text) return;
|
||||
|
||||
wcscpy(text, t);
|
||||
wcscpy(text, t);
|
||||
|
||||
if (passChar != 0)
|
||||
{
|
||||
for (u8 i = 0; i < wcslen(text); i++)
|
||||
text[i] = passChar;
|
||||
}
|
||||
if (passChar != 0)
|
||||
{
|
||||
for (u8 i = 0; i < wcslen(text); i++)
|
||||
text[i] = passChar;
|
||||
}
|
||||
|
||||
textWidth = fontSystem->getWidth(text, currentSize);
|
||||
}
|
||||
textWidth = fontSystem->getWidth(text, currentSize);
|
||||
}
|
||||
}
|
||||
|
||||
void GuiText::ClearDynamicText()
|
||||
{
|
||||
for (u32 i = 0; i < textDyn.size(); i++)
|
||||
{
|
||||
if (textDyn[i])
|
||||
delete [] textDyn[i];
|
||||
}
|
||||
textDyn.clear();
|
||||
for (u32 i = 0; i < textDyn.size(); i++)
|
||||
{
|
||||
if (textDyn[i])
|
||||
delete [] textDyn[i];
|
||||
}
|
||||
textDyn.clear();
|
||||
}
|
||||
|
||||
void GuiText::SetPresets(int sz, GXColor c, int w, u16 s, int h, int v)
|
||||
{
|
||||
presetSize = sz;
|
||||
presetColor = c;
|
||||
presetStyle = s;
|
||||
presetMaxWidth = w;
|
||||
presetAlignmentHor = h;
|
||||
presetAlignmentVert = v;
|
||||
presetSize = sz;
|
||||
presetColor = c;
|
||||
presetStyle = s;
|
||||
presetMaxWidth = w;
|
||||
presetAlignmentHor = h;
|
||||
presetAlignmentVert = v;
|
||||
}
|
||||
|
||||
void GuiText::SetFontSize(int s)
|
||||
{
|
||||
LOCK( this );
|
||||
LOCK( this );
|
||||
|
||||
size = s;
|
||||
size = s;
|
||||
}
|
||||
|
||||
void GuiText::SetMaxWidth(int width, int w)
|
||||
{
|
||||
LOCK( this );
|
||||
LOCK( this );
|
||||
|
||||
maxWidth = width;
|
||||
wrapMode = w;
|
||||
maxWidth = width;
|
||||
wrapMode = w;
|
||||
|
||||
if (w == SCROLL_HORIZONTAL)
|
||||
{
|
||||
textScrollPos = 0;
|
||||
textScrollInitialDelay = TEXT_SCROLL_INITIAL_DELAY;
|
||||
textScrollDelay = TEXT_SCROLL_DELAY;
|
||||
}
|
||||
if (w == SCROLL_HORIZONTAL)
|
||||
{
|
||||
textScrollPos = 0;
|
||||
textScrollInitialDelay = TEXT_SCROLL_INITIAL_DELAY;
|
||||
textScrollDelay = TEXT_SCROLL_DELAY;
|
||||
}
|
||||
|
||||
ClearDynamicText();
|
||||
ClearDynamicText();
|
||||
}
|
||||
|
||||
void GuiText::SetPassChar(wchar_t p)
|
||||
{
|
||||
LOCK( this );
|
||||
passChar = p;
|
||||
LOCK( this );
|
||||
passChar = p;
|
||||
}
|
||||
|
||||
void GuiText::SetColor(GXColor c)
|
||||
{
|
||||
LOCK( this );
|
||||
color = c;
|
||||
alpha = c.a;
|
||||
LOCK( this );
|
||||
color = c;
|
||||
alpha = c.a;
|
||||
}
|
||||
|
||||
void GuiText::SetStyle(u16 s)
|
||||
{
|
||||
LOCK( this );
|
||||
style = s;
|
||||
LOCK( this );
|
||||
style = s;
|
||||
}
|
||||
|
||||
void GuiText::SetAlignment(int hor, int vert)
|
||||
{
|
||||
LOCK( this );
|
||||
style = 0;
|
||||
LOCK( this );
|
||||
style = 0;
|
||||
|
||||
switch (hor)
|
||||
{
|
||||
case ALIGN_LEFT:
|
||||
style |= FTGX_JUSTIFY_LEFT;
|
||||
break;
|
||||
case ALIGN_RIGHT:
|
||||
style |= FTGX_JUSTIFY_RIGHT;
|
||||
break;
|
||||
default:
|
||||
style |= FTGX_JUSTIFY_CENTER;
|
||||
break;
|
||||
}
|
||||
switch (vert)
|
||||
{
|
||||
case ALIGN_TOP:
|
||||
style |= FTGX_ALIGN_TOP;
|
||||
break;
|
||||
case ALIGN_BOTTOM:
|
||||
style |= FTGX_ALIGN_BOTTOM;
|
||||
break;
|
||||
default:
|
||||
style |= FTGX_ALIGN_MIDDLE;
|
||||
break;
|
||||
}
|
||||
switch (hor)
|
||||
{
|
||||
case ALIGN_LEFT:
|
||||
style |= FTGX_JUSTIFY_LEFT;
|
||||
break;
|
||||
case ALIGN_RIGHT:
|
||||
style |= FTGX_JUSTIFY_RIGHT;
|
||||
break;
|
||||
default:
|
||||
style |= FTGX_JUSTIFY_CENTER;
|
||||
break;
|
||||
}
|
||||
switch (vert)
|
||||
{
|
||||
case ALIGN_TOP:
|
||||
style |= FTGX_ALIGN_TOP;
|
||||
break;
|
||||
case ALIGN_BOTTOM:
|
||||
style |= FTGX_ALIGN_BOTTOM;
|
||||
break;
|
||||
default:
|
||||
style |= FTGX_ALIGN_MIDDLE;
|
||||
break;
|
||||
}
|
||||
|
||||
alignmentHor = hor;
|
||||
alignmentVert = vert;
|
||||
alignmentHor = hor;
|
||||
alignmentVert = vert;
|
||||
}
|
||||
|
||||
void GuiText::SetLinesToDraw(int l)
|
||||
{
|
||||
linestodraw = l;
|
||||
linestodraw = l;
|
||||
}
|
||||
|
||||
int GuiText::GetTextWidth()
|
||||
{
|
||||
if (!text) return 0;
|
||||
if (!text) return 0;
|
||||
|
||||
return fontSystem->getWidth(text, currentSize);
|
||||
return fontSystem->getWidth(text, currentSize);
|
||||
}
|
||||
|
||||
int GuiText::GetTextWidth(int ind)
|
||||
{
|
||||
if (ind < 0 || ind >= (int) textDyn.size()) return this->GetTextWidth();
|
||||
if (ind < 0 || ind >= (int) textDyn.size()) return this->GetTextWidth();
|
||||
|
||||
return fontSystem->getWidth(textDyn[ind], currentSize);
|
||||
return fontSystem->getWidth(textDyn[ind], currentSize);
|
||||
}
|
||||
|
||||
int GuiText::GetTextMaxWidth()
|
||||
{
|
||||
return maxWidth;
|
||||
return maxWidth;
|
||||
}
|
||||
|
||||
const wchar_t * GuiText::GetDynText(int ind)
|
||||
{
|
||||
if (ind < 0 || ind >= (int) textDyn.size()) return text;
|
||||
if (ind < 0 || ind >= (int) textDyn.size()) return text;
|
||||
|
||||
return textDyn[ind];
|
||||
return textDyn[ind];
|
||||
}
|
||||
|
||||
const wchar_t * GuiText::GetText()
|
||||
{
|
||||
return text;
|
||||
return text;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -349,174 +349,174 @@ const wchar_t * GuiText::GetText()
|
|||
*/
|
||||
bool GuiText::SetFont(const u8 *fontbuffer, const u32 filesize)
|
||||
{
|
||||
if (!fontbuffer || !filesize) return false;
|
||||
LOCK( this );
|
||||
if (font)
|
||||
{
|
||||
delete font;
|
||||
font = NULL;
|
||||
}
|
||||
font = new FreeTypeGX(fontbuffer, filesize);
|
||||
textWidth = font->getWidth(text, currentSize);
|
||||
if (!fontbuffer || !filesize) return false;
|
||||
LOCK( this );
|
||||
if (font)
|
||||
{
|
||||
delete font;
|
||||
font = NULL;
|
||||
}
|
||||
font = new FreeTypeGX(fontbuffer, filesize);
|
||||
textWidth = font->getWidth(text, currentSize);
|
||||
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
void GuiText::MakeDottedText()
|
||||
{
|
||||
int pos = textDyn.size();
|
||||
textDyn.resize(pos + 1);
|
||||
int pos = textDyn.size();
|
||||
textDyn.resize(pos + 1);
|
||||
|
||||
int i = 0, currentWidth = 0;
|
||||
textDyn[pos] = new wchar_t[maxWidth];
|
||||
int i = 0, currentWidth = 0;
|
||||
textDyn[pos] = new wchar_t[maxWidth];
|
||||
|
||||
while (text[i])
|
||||
{
|
||||
currentWidth += (font ? font : fontSystem)->getCharWidth(text[i], currentSize, i > 0 ? text[i - 1] : 0);
|
||||
if (currentWidth >= maxWidth && i > 2)
|
||||
{
|
||||
textDyn[pos][i - 2] = '.';
|
||||
textDyn[pos][i - 1] = '.';
|
||||
textDyn[pos][i] = '.';
|
||||
i++;
|
||||
break;
|
||||
}
|
||||
while (text[i])
|
||||
{
|
||||
currentWidth += (font ? font : fontSystem)->getCharWidth(text[i], currentSize, i > 0 ? text[i - 1] : 0);
|
||||
if (currentWidth >= maxWidth && i > 2)
|
||||
{
|
||||
textDyn[pos][i - 2] = '.';
|
||||
textDyn[pos][i - 1] = '.';
|
||||
textDyn[pos][i] = '.';
|
||||
i++;
|
||||
break;
|
||||
}
|
||||
|
||||
textDyn[pos][i] = text[i];
|
||||
textDyn[pos][i] = text[i];
|
||||
|
||||
i++;
|
||||
}
|
||||
textDyn[pos][i] = 0;
|
||||
i++;
|
||||
}
|
||||
textDyn[pos][i] = 0;
|
||||
}
|
||||
|
||||
void GuiText::ScrollText()
|
||||
{
|
||||
if (textDyn.size() == 0)
|
||||
{
|
||||
int pos = textDyn.size();
|
||||
int i = 0, currentWidth = 0;
|
||||
textDyn.resize(pos + 1);
|
||||
if (textDyn.size() == 0)
|
||||
{
|
||||
int pos = textDyn.size();
|
||||
int i = 0, currentWidth = 0;
|
||||
textDyn.resize(pos + 1);
|
||||
|
||||
textDyn[pos] = new wchar_t[maxWidth];
|
||||
textDyn[pos] = new wchar_t[maxWidth];
|
||||
|
||||
while (text[i] && currentWidth < maxWidth)
|
||||
{
|
||||
textDyn[pos][i] = text[i];
|
||||
while (text[i] && currentWidth < maxWidth)
|
||||
{
|
||||
textDyn[pos][i] = text[i];
|
||||
|
||||
currentWidth += (font ? font : fontSystem)->getCharWidth(text[i], currentSize, i > 0 ? text[i - 1] : 0);
|
||||
currentWidth += (font ? font : fontSystem)->getCharWidth(text[i], currentSize, i > 0 ? text[i - 1] : 0);
|
||||
|
||||
++i;
|
||||
}
|
||||
textDyn[pos][i] = 0;
|
||||
++i;
|
||||
}
|
||||
textDyn[pos][i] = 0;
|
||||
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (frameCount % textScrollDelay != 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (frameCount % textScrollDelay != 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (textScrollInitialDelay)
|
||||
{
|
||||
--textScrollInitialDelay;
|
||||
return;
|
||||
}
|
||||
if (textScrollInitialDelay)
|
||||
{
|
||||
--textScrollInitialDelay;
|
||||
return;
|
||||
}
|
||||
|
||||
int stringlen = wcslen(text);
|
||||
int stringlen = wcslen(text);
|
||||
|
||||
++textScrollPos;
|
||||
if (textScrollPos > stringlen)
|
||||
{
|
||||
textScrollPos = 0;
|
||||
textScrollInitialDelay = TEXT_SCROLL_INITIAL_DELAY;
|
||||
}
|
||||
++textScrollPos;
|
||||
if (textScrollPos > stringlen)
|
||||
{
|
||||
textScrollPos = 0;
|
||||
textScrollInitialDelay = TEXT_SCROLL_INITIAL_DELAY;
|
||||
}
|
||||
|
||||
int ch = textScrollPos;
|
||||
int pos = textDyn.size() - 1;
|
||||
int ch = textScrollPos;
|
||||
int pos = textDyn.size() - 1;
|
||||
|
||||
if (!textDyn[pos]) new wchar_t[maxWidth];
|
||||
if (!textDyn[pos]) new wchar_t[maxWidth];
|
||||
|
||||
int i = 0, currentWidth = 0;
|
||||
int i = 0, currentWidth = 0;
|
||||
|
||||
while (currentWidth < maxWidth)
|
||||
{
|
||||
if (ch > stringlen - 1)
|
||||
{
|
||||
textDyn[pos][i++] = ' ';
|
||||
currentWidth += (font ? font : fontSystem)->getCharWidth(L' ', currentSize, ch > 0 ? text[ch - 1] : 0);
|
||||
textDyn[pos][i++] = ' ';
|
||||
currentWidth += (font ? font : fontSystem)->getCharWidth(L' ', currentSize, L' ');
|
||||
textDyn[pos][i++] = ' ';
|
||||
currentWidth += (font ? font : fontSystem)->getCharWidth(L' ', currentSize, L' ');
|
||||
ch = 0;
|
||||
while (currentWidth < maxWidth)
|
||||
{
|
||||
if (ch > stringlen - 1)
|
||||
{
|
||||
textDyn[pos][i++] = ' ';
|
||||
currentWidth += (font ? font : fontSystem)->getCharWidth(L' ', currentSize, ch > 0 ? text[ch - 1] : 0);
|
||||
textDyn[pos][i++] = ' ';
|
||||
currentWidth += (font ? font : fontSystem)->getCharWidth(L' ', currentSize, L' ');
|
||||
textDyn[pos][i++] = ' ';
|
||||
currentWidth += (font ? font : fontSystem)->getCharWidth(L' ', currentSize, L' ');
|
||||
ch = 0;
|
||||
|
||||
if(currentWidth >= maxWidth)
|
||||
break;
|
||||
}
|
||||
if(currentWidth >= maxWidth)
|
||||
break;
|
||||
}
|
||||
|
||||
textDyn[pos][i] = text[ch];
|
||||
currentWidth += (font ? font : fontSystem)->getCharWidth(text[ch], currentSize, ch > 0 ? text[ch - 1] : 0);
|
||||
++ch;
|
||||
++i;
|
||||
}
|
||||
textDyn[pos][i] = 0;
|
||||
textDyn[pos][i] = text[ch];
|
||||
currentWidth += (font ? font : fontSystem)->getCharWidth(text[ch], currentSize, ch > 0 ? text[ch - 1] : 0);
|
||||
++ch;
|
||||
++i;
|
||||
}
|
||||
textDyn[pos][i] = 0;
|
||||
}
|
||||
|
||||
void GuiText::WrapText()
|
||||
{
|
||||
if (textDyn.size() > 0) return;
|
||||
if (textDyn.size() > 0) return;
|
||||
|
||||
int i = 0;
|
||||
int ch = 0;
|
||||
int linenum = 0;
|
||||
int lastSpace = -1;
|
||||
int lastSpaceIndex = -1;
|
||||
int currentWidth = 0;
|
||||
int i = 0;
|
||||
int ch = 0;
|
||||
int linenum = 0;
|
||||
int lastSpace = -1;
|
||||
int lastSpaceIndex = -1;
|
||||
int currentWidth = 0;
|
||||
|
||||
while (text[ch] && linenum < linestodraw)
|
||||
{
|
||||
if (linenum >= (int) textDyn.size())
|
||||
{
|
||||
textDyn.resize(linenum + 1);
|
||||
textDyn[linenum] = new wchar_t[maxWidth];
|
||||
}
|
||||
while (text[ch] && linenum < linestodraw)
|
||||
{
|
||||
if (linenum >= (int) textDyn.size())
|
||||
{
|
||||
textDyn.resize(linenum + 1);
|
||||
textDyn[linenum] = new wchar_t[maxWidth];
|
||||
}
|
||||
|
||||
textDyn[linenum][i] = text[ch];
|
||||
textDyn[linenum][i + 1] = 0;
|
||||
textDyn[linenum][i] = text[ch];
|
||||
textDyn[linenum][i + 1] = 0;
|
||||
|
||||
currentWidth += (font ? font : fontSystem)->getCharWidth(text[ch], currentSize, ch > 0 ? text[ch - 1] : 0x0000);
|
||||
currentWidth += (font ? font : fontSystem)->getCharWidth(text[ch], currentSize, ch > 0 ? text[ch - 1] : 0x0000);
|
||||
|
||||
if (currentWidth >= maxWidth)
|
||||
{
|
||||
if (lastSpace >= 0)
|
||||
{
|
||||
textDyn[linenum][lastSpaceIndex] = 0; // discard space, and everything after
|
||||
ch = lastSpace; // go backwards to the last space
|
||||
lastSpace = -1; // we have used this space
|
||||
lastSpaceIndex = -1;
|
||||
}
|
||||
if (currentWidth >= maxWidth)
|
||||
{
|
||||
if (lastSpace >= 0)
|
||||
{
|
||||
textDyn[linenum][lastSpaceIndex] = 0; // discard space, and everything after
|
||||
ch = lastSpace; // go backwards to the last space
|
||||
lastSpace = -1; // we have used this space
|
||||
lastSpaceIndex = -1;
|
||||
}
|
||||
|
||||
if (linenum + 1 == linestodraw && text[ch + 1] != 0x0000)
|
||||
{
|
||||
textDyn[linenum][i - 2] = '.';
|
||||
textDyn[linenum][i - 1] = '.';
|
||||
textDyn[linenum][i] = '.';
|
||||
textDyn[linenum][i + 1] = 0;
|
||||
}
|
||||
if (linenum + 1 == linestodraw && text[ch + 1] != 0x0000)
|
||||
{
|
||||
textDyn[linenum][i - 2] = '.';
|
||||
textDyn[linenum][i - 1] = '.';
|
||||
textDyn[linenum][i] = '.';
|
||||
textDyn[linenum][i + 1] = 0;
|
||||
}
|
||||
|
||||
currentWidth = 0;
|
||||
++linenum;
|
||||
i = -1;
|
||||
}
|
||||
if (text[ch] == ' ' && i >= 0)
|
||||
{
|
||||
lastSpace = ch;
|
||||
lastSpaceIndex = i;
|
||||
}
|
||||
++ch;
|
||||
++i;
|
||||
}
|
||||
currentWidth = 0;
|
||||
++linenum;
|
||||
i = -1;
|
||||
}
|
||||
if (text[ch] == ' ' && i >= 0)
|
||||
{
|
||||
lastSpace = ch;
|
||||
lastSpaceIndex = i;
|
||||
}
|
||||
++ch;
|
||||
++i;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -524,57 +524,57 @@ void GuiText::WrapText()
|
|||
*/
|
||||
void GuiText::Draw()
|
||||
{
|
||||
if (!text) return;
|
||||
if (!text) return;
|
||||
|
||||
if (!IsVisible()) return;
|
||||
if (!IsVisible()) return;
|
||||
|
||||
GXColor c = color;
|
||||
c.a = GetAlpha();
|
||||
GXColor c = color;
|
||||
c.a = GetAlpha();
|
||||
|
||||
int newSize = (int) (size * GetScale());
|
||||
int newSize = (int) (size * GetScale());
|
||||
|
||||
if (newSize != currentSize)
|
||||
{
|
||||
currentSize = LIMIT(newSize, 1, 100);
|
||||
if (newSize != currentSize)
|
||||
{
|
||||
currentSize = LIMIT(newSize, 1, 100);
|
||||
|
||||
if (text) textWidth = (font ? font : fontSystem)->getWidth(text, currentSize);
|
||||
}
|
||||
if (text) textWidth = (font ? font : fontSystem)->getWidth(text, currentSize);
|
||||
}
|
||||
|
||||
if (maxWidth > 0 && maxWidth <= textWidth)
|
||||
{
|
||||
if (wrapMode == DOTTED) // text dotted
|
||||
{
|
||||
if (textDyn.size() == 0)
|
||||
MakeDottedText();
|
||||
if (maxWidth > 0 && maxWidth <= textWidth)
|
||||
{
|
||||
if (wrapMode == DOTTED) // text dotted
|
||||
{
|
||||
if (textDyn.size() == 0)
|
||||
MakeDottedText();
|
||||
|
||||
if (textDyn.size() > 0)
|
||||
(font ? font : fontSystem)->drawText(this->GetLeft(), this->GetTop(), 0, textDyn[textDyn.size() - 1], currentSize, c, style);
|
||||
}
|
||||
if (textDyn.size() > 0)
|
||||
(font ? font : fontSystem)->drawText(this->GetLeft(), this->GetTop(), 0, textDyn[textDyn.size() - 1], currentSize, c, style);
|
||||
}
|
||||
|
||||
else if (wrapMode == SCROLL_HORIZONTAL)
|
||||
{
|
||||
ScrollText();
|
||||
else if (wrapMode == SCROLL_HORIZONTAL)
|
||||
{
|
||||
ScrollText();
|
||||
|
||||
if (textDyn.size() > 0)
|
||||
(font ? font : fontSystem)->drawText(this->GetLeft(), this->GetTop(), 0, textDyn[textDyn.size() - 1], currentSize, c, style);
|
||||
}
|
||||
else if (wrapMode == WRAP)
|
||||
{
|
||||
int lineheight = currentSize + 6;
|
||||
int voffset = 0;
|
||||
if (alignmentVert == ALIGN_MIDDLE) voffset = -(lineheight * textDyn.size()) / 2 + lineheight / 2;
|
||||
if (textDyn.size() > 0)
|
||||
(font ? font : fontSystem)->drawText(this->GetLeft(), this->GetTop(), 0, textDyn[textDyn.size() - 1], currentSize, c, style);
|
||||
}
|
||||
else if (wrapMode == WRAP)
|
||||
{
|
||||
int lineheight = currentSize + 6;
|
||||
int voffset = 0;
|
||||
if (alignmentVert == ALIGN_MIDDLE) voffset = -(lineheight * textDyn.size()) / 2 + lineheight / 2;
|
||||
|
||||
if (textDyn.size() == 0) WrapText();
|
||||
if (textDyn.size() == 0) WrapText();
|
||||
|
||||
for (u32 i = 0; i < textDyn.size(); i++)
|
||||
{
|
||||
(font ? font : fontSystem)->drawText(this->GetLeft(), this->GetTop() + voffset + i * lineheight, 0, textDyn[i], currentSize, c, style);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
(font ? font : fontSystem)->drawText(this->GetLeft(), this->GetTop(), 0, text, currentSize, c, style, textWidth);
|
||||
}
|
||||
this->UpdateEffects();
|
||||
for (u32 i = 0; i < textDyn.size(); i++)
|
||||
{
|
||||
(font ? font : fontSystem)->drawText(this->GetLeft(), this->GetTop() + voffset + i * lineheight, 0, textDyn[i], currentSize, c, style);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
(font ? font : fontSystem)->drawText(this->GetLeft(), this->GetTop(), 0, text, currentSize, c, style, textWidth);
|
||||
}
|
||||
this->UpdateEffects();
|
||||
}
|
||||
|
|
|
@ -15,22 +15,22 @@
|
|||
*/
|
||||
GuiTooltip::GuiTooltip(const char *t, int Alpha/*=255*/)
|
||||
{
|
||||
tooltipLeft = Resources::GetImageData("tooltip_left.png");
|
||||
tooltipTile = Resources::GetImageData("tooltip_tile.png");
|
||||
tooltipRight = Resources::GetImageData("tooltip_right.png");
|
||||
leftImage = new GuiImage(tooltipLeft);
|
||||
tileImage = new GuiImage(tooltipTile);
|
||||
rightImage = new GuiImage(tooltipRight);
|
||||
text = NULL;
|
||||
height = leftImage->GetHeight();
|
||||
leftImage->SetParent(this);
|
||||
tileImage->SetParent(this);
|
||||
rightImage->SetParent(this);
|
||||
leftImage->SetParentAngle(false);
|
||||
tileImage->SetParentAngle(false);
|
||||
rightImage->SetParentAngle(false);
|
||||
SetText(t);
|
||||
SetAlpha(Alpha);
|
||||
tooltipLeft = Resources::GetImageData("tooltip_left.png");
|
||||
tooltipTile = Resources::GetImageData("tooltip_tile.png");
|
||||
tooltipRight = Resources::GetImageData("tooltip_right.png");
|
||||
leftImage = new GuiImage(tooltipLeft);
|
||||
tileImage = new GuiImage(tooltipTile);
|
||||
rightImage = new GuiImage(tooltipRight);
|
||||
text = NULL;
|
||||
height = leftImage->GetHeight();
|
||||
leftImage->SetParent(this);
|
||||
tileImage->SetParent(this);
|
||||
rightImage->SetParent(this);
|
||||
leftImage->SetParentAngle(false);
|
||||
tileImage->SetParentAngle(false);
|
||||
rightImage->SetParentAngle(false);
|
||||
SetText(t);
|
||||
SetAlpha(Alpha);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -38,21 +38,21 @@ GuiTooltip::GuiTooltip(const char *t, int Alpha/*=255*/)
|
|||
*/
|
||||
GuiTooltip::~GuiTooltip()
|
||||
{
|
||||
if (text) delete text;
|
||||
if (text) delete text;
|
||||
|
||||
delete tooltipLeft;
|
||||
delete tooltipTile;
|
||||
delete tooltipRight;
|
||||
delete leftImage;
|
||||
delete tileImage;
|
||||
delete rightImage;
|
||||
delete tooltipLeft;
|
||||
delete tooltipTile;
|
||||
delete tooltipRight;
|
||||
delete leftImage;
|
||||
delete tileImage;
|
||||
delete rightImage;
|
||||
}
|
||||
|
||||
float GuiTooltip::GetScale()
|
||||
{
|
||||
float s = scale * scaleDyn;
|
||||
float s = scale * scaleDyn;
|
||||
|
||||
return s;
|
||||
return s;
|
||||
}
|
||||
|
||||
/* !Sets the text of the GuiTooltip element
|
||||
|
@ -60,24 +60,24 @@ float GuiTooltip::GetScale()
|
|||
*/
|
||||
void GuiTooltip::SetText(const char * t)
|
||||
{
|
||||
LOCK( this );
|
||||
if (text)
|
||||
{
|
||||
delete text;
|
||||
text = NULL;
|
||||
}
|
||||
int tile_cnt = 0;
|
||||
if (t && (text = new GuiText(t, 22, ( GXColor )
|
||||
{ 0, 0, 0, 255})))
|
||||
{
|
||||
text->SetParent(this);
|
||||
tile_cnt = (text->GetTextWidth() - 12) / tileImage->GetWidth();
|
||||
if (tile_cnt < 0) tile_cnt = 0;
|
||||
}
|
||||
tileImage->SetPosition(leftImage->GetWidth(), 0);
|
||||
tileImage->SetTileHorizontal(tile_cnt);
|
||||
rightImage->SetPosition(leftImage->GetWidth() + tile_cnt * tileImage->GetWidth(), 0);
|
||||
width = leftImage->GetWidth() + tile_cnt * tileImage->GetWidth() + rightImage->GetWidth();
|
||||
LOCK( this );
|
||||
if (text)
|
||||
{
|
||||
delete text;
|
||||
text = NULL;
|
||||
}
|
||||
int tile_cnt = 0;
|
||||
if (t && (text = new GuiText(t, 22, ( GXColor )
|
||||
{ 0, 0, 0, 255})))
|
||||
{
|
||||
text->SetParent(this);
|
||||
tile_cnt = (text->GetTextWidth() - 12) / tileImage->GetWidth();
|
||||
if (tile_cnt < 0) tile_cnt = 0;
|
||||
}
|
||||
tileImage->SetPosition(leftImage->GetWidth(), 0);
|
||||
tileImage->SetTileHorizontal(tile_cnt);
|
||||
rightImage->SetPosition(leftImage->GetWidth() + tile_cnt * tileImage->GetWidth(), 0);
|
||||
width = leftImage->GetWidth() + tile_cnt * tileImage->GetWidth() + rightImage->GetWidth();
|
||||
}
|
||||
|
||||
void GuiTooltip::SetWidescreen(bool )
|
||||
|
@ -88,13 +88,13 @@ void GuiTooltip::SetWidescreen(bool )
|
|||
*/
|
||||
void GuiTooltip::Draw()
|
||||
{
|
||||
LOCK( this );
|
||||
if (!this->IsVisible()) return;
|
||||
LOCK( this );
|
||||
if (!this->IsVisible()) return;
|
||||
|
||||
leftImage->Draw();
|
||||
tileImage->Draw();
|
||||
rightImage->Draw();
|
||||
if (text) text->Draw();
|
||||
leftImage->Draw();
|
||||
tileImage->Draw();
|
||||
rightImage->Draw();
|
||||
if (text) text->Draw();
|
||||
|
||||
this->UpdateEffects();
|
||||
this->UpdateEffects();
|
||||
}
|
||||
|
|
|
@ -17,9 +17,9 @@ static int scrollDelay = 0;
|
|||
*/
|
||||
GuiTrigger::GuiTrigger()
|
||||
{
|
||||
chan = -1;
|
||||
memset(&wpad, 0, sizeof(WPADData));
|
||||
memset(&pad, 0, sizeof(PADData));
|
||||
chan = -1;
|
||||
memset(&wpad, 0, sizeof(WPADData));
|
||||
memset(&pad, 0, sizeof(PADData));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -36,10 +36,10 @@ GuiTrigger::~GuiTrigger()
|
|||
*/
|
||||
void GuiTrigger::SetSimpleTrigger(s32 ch, u32 wiibtns, u16 gcbtns)
|
||||
{
|
||||
type = TRIGGER_SIMPLE;
|
||||
chan = ch;
|
||||
wpad.btns_d = wiibtns;
|
||||
pad.btns_d = gcbtns;
|
||||
type = TRIGGER_SIMPLE;
|
||||
chan = ch;
|
||||
wpad.btns_d = wiibtns;
|
||||
pad.btns_d = gcbtns;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -49,10 +49,10 @@ void GuiTrigger::SetSimpleTrigger(s32 ch, u32 wiibtns, u16 gcbtns)
|
|||
*/
|
||||
void GuiTrigger::SetHeldTrigger(s32 ch, u32 wiibtns, u16 gcbtns)
|
||||
{
|
||||
type = TRIGGER_HELD;
|
||||
chan = ch;
|
||||
wpad.btns_h = wiibtns;
|
||||
pad.btns_h = gcbtns;
|
||||
type = TRIGGER_HELD;
|
||||
chan = ch;
|
||||
wpad.btns_h = wiibtns;
|
||||
pad.btns_h = gcbtns;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -61,10 +61,10 @@ void GuiTrigger::SetHeldTrigger(s32 ch, u32 wiibtns, u16 gcbtns)
|
|||
*/
|
||||
void GuiTrigger::SetButtonOnlyTrigger(s32 ch, u32 wiibtns, u16 gcbtns)
|
||||
{
|
||||
type = TRIGGER_BUTTON_ONLY;
|
||||
chan = ch;
|
||||
wpad.btns_d = wiibtns;
|
||||
pad.btns_d = gcbtns;
|
||||
type = TRIGGER_BUTTON_ONLY;
|
||||
chan = ch;
|
||||
wpad.btns_d = wiibtns;
|
||||
pad.btns_d = gcbtns;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -74,10 +74,10 @@ void GuiTrigger::SetButtonOnlyTrigger(s32 ch, u32 wiibtns, u16 gcbtns)
|
|||
*/
|
||||
void GuiTrigger::SetButtonOnlyInFocusTrigger(s32 ch, u32 wiibtns, u16 gcbtns)
|
||||
{
|
||||
type = TRIGGER_BUTTON_ONLY_IN_FOCUS;
|
||||
chan = ch;
|
||||
wpad.btns_d = wiibtns;
|
||||
pad.btns_d = gcbtns;
|
||||
type = TRIGGER_BUTTON_ONLY_IN_FOCUS;
|
||||
chan = ch;
|
||||
wpad.btns_d = wiibtns;
|
||||
pad.btns_d = gcbtns;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
|
@ -90,158 +90,158 @@ s8 GuiTrigger::WPAD_Stick(u8 right, int axis)
|
|||
{
|
||||
#ifdef HW_RVL
|
||||
|
||||
float mag = 0.0;
|
||||
float ang = 0.0;
|
||||
float mag = 0.0;
|
||||
float ang = 0.0;
|
||||
|
||||
switch ( wpad.exp.type )
|
||||
{
|
||||
case WPAD_EXP_NUNCHUK:
|
||||
case WPAD_EXP_GUITARHERO3:
|
||||
if ( right == 0 )
|
||||
{
|
||||
mag = wpad.exp.nunchuk.js.mag;
|
||||
ang = wpad.exp.nunchuk.js.ang;
|
||||
}
|
||||
break;
|
||||
switch ( wpad.exp.type )
|
||||
{
|
||||
case WPAD_EXP_NUNCHUK:
|
||||
case WPAD_EXP_GUITARHERO3:
|
||||
if ( right == 0 )
|
||||
{
|
||||
mag = wpad.exp.nunchuk.js.mag;
|
||||
ang = wpad.exp.nunchuk.js.ang;
|
||||
}
|
||||
break;
|
||||
|
||||
case WPAD_EXP_CLASSIC:
|
||||
if ( right == 0 )
|
||||
{
|
||||
mag = wpad.exp.classic.ljs.mag;
|
||||
ang = wpad.exp.classic.ljs.ang;
|
||||
}
|
||||
else
|
||||
{
|
||||
mag = wpad.exp.classic.rjs.mag;
|
||||
ang = wpad.exp.classic.rjs.ang;
|
||||
}
|
||||
break;
|
||||
case WPAD_EXP_CLASSIC:
|
||||
if ( right == 0 )
|
||||
{
|
||||
mag = wpad.exp.classic.ljs.mag;
|
||||
ang = wpad.exp.classic.ljs.ang;
|
||||
}
|
||||
else
|
||||
{
|
||||
mag = wpad.exp.classic.rjs.mag;
|
||||
ang = wpad.exp.classic.rjs.ang;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
/* calculate x/y value (angle need to be converted into radian) */
|
||||
if ( mag > 1.0 ) mag = 1.0;
|
||||
else if ( mag < -1.0 ) mag = -1.0;
|
||||
double val;
|
||||
/* calculate x/y value (angle need to be converted into radian) */
|
||||
if ( mag > 1.0 ) mag = 1.0;
|
||||
else if ( mag < -1.0 ) mag = -1.0;
|
||||
double val;
|
||||
|
||||
if ( axis == 0 ) // x-axis
|
||||
val = mag * sin( ( PI * ang ) / 180.0f );
|
||||
else // y-axis
|
||||
val = mag * cos( ( PI * ang ) / 180.0f );
|
||||
if ( axis == 0 ) // x-axis
|
||||
val = mag * sin( ( PI * ang ) / 180.0f );
|
||||
else // y-axis
|
||||
val = mag * cos( ( PI * ang ) / 180.0f );
|
||||
|
||||
return ( s8 )( val * 128.0f );
|
||||
return ( s8 )( val * 128.0f );
|
||||
|
||||
#else
|
||||
return 0;
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool GuiTrigger::Left()
|
||||
{
|
||||
u32 wiibtn = WPAD_BUTTON_LEFT;
|
||||
if(wpad.exp.type == WPAD_EXP_CLASSIC)
|
||||
wiibtn = WPAD_CLASSIC_BUTTON_LEFT;
|
||||
u32 wiibtn = WPAD_BUTTON_LEFT;
|
||||
if(wpad.exp.type == WPAD_EXP_CLASSIC)
|
||||
wiibtn = WPAD_CLASSIC_BUTTON_LEFT;
|
||||
|
||||
if (((wpad.btns_d | wpad.btns_h) & wiibtn) || ((pad.btns_d | pad.btns_h)
|
||||
& PAD_BUTTON_LEFT) || pad.stickX < -PADCAL || WPAD_Stick(0, 0) < -PADCAL)
|
||||
{
|
||||
if ((wpad.btns_d & wiibtn) || (pad.btns_d & PAD_BUTTON_LEFT))
|
||||
{
|
||||
scrollDelay = SCROLL_INITIAL_DELAY; // reset scroll delay.
|
||||
return true;
|
||||
}
|
||||
else if (scrollDelay == 0)
|
||||
{
|
||||
scrollDelay = SCROLL_LOOP_DELAY;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (scrollDelay > 0) scrollDelay--;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
if (((wpad.btns_d | wpad.btns_h) & wiibtn) || ((pad.btns_d | pad.btns_h)
|
||||
& PAD_BUTTON_LEFT) || pad.stickX < -PADCAL || WPAD_Stick(0, 0) < -PADCAL)
|
||||
{
|
||||
if ((wpad.btns_d & wiibtn) || (pad.btns_d & PAD_BUTTON_LEFT))
|
||||
{
|
||||
scrollDelay = SCROLL_INITIAL_DELAY; // reset scroll delay.
|
||||
return true;
|
||||
}
|
||||
else if (scrollDelay == 0)
|
||||
{
|
||||
scrollDelay = SCROLL_LOOP_DELAY;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (scrollDelay > 0) scrollDelay--;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool GuiTrigger::Right()
|
||||
{
|
||||
u32 wiibtn = WPAD_BUTTON_RIGHT;
|
||||
if(wpad.exp.type == WPAD_EXP_CLASSIC)
|
||||
wiibtn = WPAD_CLASSIC_BUTTON_RIGHT;
|
||||
u32 wiibtn = WPAD_BUTTON_RIGHT;
|
||||
if(wpad.exp.type == WPAD_EXP_CLASSIC)
|
||||
wiibtn = WPAD_CLASSIC_BUTTON_RIGHT;
|
||||
|
||||
if (((wpad.btns_d | wpad.btns_h) & wiibtn) || ((pad.btns_d | pad.btns_h)
|
||||
& PAD_BUTTON_RIGHT) || pad.stickX > PADCAL || WPAD_Stick(0, 0) > PADCAL)
|
||||
{
|
||||
if ((wpad.btns_d & wiibtn) || (pad.btns_d & PAD_BUTTON_RIGHT))
|
||||
{
|
||||
scrollDelay = SCROLL_INITIAL_DELAY; // reset scroll delay.
|
||||
return true;
|
||||
}
|
||||
else if (scrollDelay == 0)
|
||||
{
|
||||
scrollDelay = SCROLL_LOOP_DELAY;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (scrollDelay > 0) scrollDelay--;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
if (((wpad.btns_d | wpad.btns_h) & wiibtn) || ((pad.btns_d | pad.btns_h)
|
||||
& PAD_BUTTON_RIGHT) || pad.stickX > PADCAL || WPAD_Stick(0, 0) > PADCAL)
|
||||
{
|
||||
if ((wpad.btns_d & wiibtn) || (pad.btns_d & PAD_BUTTON_RIGHT))
|
||||
{
|
||||
scrollDelay = SCROLL_INITIAL_DELAY; // reset scroll delay.
|
||||
return true;
|
||||
}
|
||||
else if (scrollDelay == 0)
|
||||
{
|
||||
scrollDelay = SCROLL_LOOP_DELAY;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (scrollDelay > 0) scrollDelay--;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool GuiTrigger::Up()
|
||||
{
|
||||
u32 wiibtn = WPAD_BUTTON_UP;
|
||||
if(wpad.exp.type == WPAD_EXP_CLASSIC)
|
||||
wiibtn = WPAD_CLASSIC_BUTTON_UP;
|
||||
u32 wiibtn = WPAD_BUTTON_UP;
|
||||
if(wpad.exp.type == WPAD_EXP_CLASSIC)
|
||||
wiibtn = WPAD_CLASSIC_BUTTON_UP;
|
||||
|
||||
if (((wpad.btns_d | wpad.btns_h) & wiibtn) || ((pad.btns_d | pad.btns_h) & PAD_BUTTON_UP)
|
||||
|| pad.stickY > PADCAL || WPAD_Stick(0, 1) > PADCAL)
|
||||
{
|
||||
if ((wpad.btns_d & wiibtn) || (pad.btns_d & PAD_BUTTON_UP))
|
||||
{
|
||||
scrollDelay = SCROLL_INITIAL_DELAY; // reset scroll delay.
|
||||
return true;
|
||||
}
|
||||
else if (scrollDelay == 0)
|
||||
{
|
||||
scrollDelay = SCROLL_LOOP_DELAY;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (scrollDelay > 0) scrollDelay--;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
if (((wpad.btns_d | wpad.btns_h) & wiibtn) || ((pad.btns_d | pad.btns_h) & PAD_BUTTON_UP)
|
||||
|| pad.stickY > PADCAL || WPAD_Stick(0, 1) > PADCAL)
|
||||
{
|
||||
if ((wpad.btns_d & wiibtn) || (pad.btns_d & PAD_BUTTON_UP))
|
||||
{
|
||||
scrollDelay = SCROLL_INITIAL_DELAY; // reset scroll delay.
|
||||
return true;
|
||||
}
|
||||
else if (scrollDelay == 0)
|
||||
{
|
||||
scrollDelay = SCROLL_LOOP_DELAY;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (scrollDelay > 0) scrollDelay--;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool GuiTrigger::Down()
|
||||
{
|
||||
u32 wiibtn = WPAD_BUTTON_DOWN;
|
||||
if(wpad.exp.type == WPAD_EXP_CLASSIC)
|
||||
wiibtn = WPAD_CLASSIC_BUTTON_DOWN;
|
||||
u32 wiibtn = WPAD_BUTTON_DOWN;
|
||||
if(wpad.exp.type == WPAD_EXP_CLASSIC)
|
||||
wiibtn = WPAD_CLASSIC_BUTTON_DOWN;
|
||||
|
||||
if (((wpad.btns_d | wpad.btns_h) & wiibtn) || ((pad.btns_d | pad.btns_h)
|
||||
& PAD_BUTTON_DOWN) || pad.stickY < -PADCAL || WPAD_Stick(0, 1) < -PADCAL)
|
||||
{
|
||||
if ((wpad.btns_d & wiibtn) || (pad.btns_d & PAD_BUTTON_DOWN))
|
||||
{
|
||||
scrollDelay = SCROLL_INITIAL_DELAY; // reset scroll delay.
|
||||
return true;
|
||||
}
|
||||
else if (scrollDelay == 0)
|
||||
{
|
||||
scrollDelay = SCROLL_LOOP_DELAY;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (scrollDelay > 0) scrollDelay--;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
if (((wpad.btns_d | wpad.btns_h) & wiibtn) || ((pad.btns_d | pad.btns_h)
|
||||
& PAD_BUTTON_DOWN) || pad.stickY < -PADCAL || WPAD_Stick(0, 1) < -PADCAL)
|
||||
{
|
||||
if ((wpad.btns_d & wiibtn) || (pad.btns_d & PAD_BUTTON_DOWN))
|
||||
{
|
||||
scrollDelay = SCROLL_INITIAL_DELAY; // reset scroll delay.
|
||||
return true;
|
||||
}
|
||||
else if (scrollDelay == 0)
|
||||
{
|
||||
scrollDelay = SCROLL_LOOP_DELAY;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (scrollDelay > 0) scrollDelay--;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -12,20 +12,20 @@
|
|||
|
||||
GuiWindow::GuiWindow()
|
||||
{
|
||||
width = 0;
|
||||
height = 0;
|
||||
forceDim = false;
|
||||
allowDim = true;
|
||||
focus = 0; // allow focus
|
||||
width = 0;
|
||||
height = 0;
|
||||
forceDim = false;
|
||||
allowDim = true;
|
||||
focus = 0; // allow focus
|
||||
}
|
||||
|
||||
GuiWindow::GuiWindow(int w, int h)
|
||||
{
|
||||
width = w;
|
||||
height = h;
|
||||
forceDim = false;
|
||||
allowDim = true;
|
||||
focus = 0; // allow focus
|
||||
width = w;
|
||||
height = h;
|
||||
forceDim = false;
|
||||
allowDim = true;
|
||||
focus = 0; // allow focus
|
||||
}
|
||||
|
||||
GuiWindow::~GuiWindow()
|
||||
|
@ -34,419 +34,419 @@ GuiWindow::~GuiWindow()
|
|||
|
||||
void GuiWindow::Append(GuiElement* e)
|
||||
{
|
||||
LOCK( this );
|
||||
if (e == NULL) return;
|
||||
LOCK( this );
|
||||
if (e == NULL) return;
|
||||
|
||||
Remove(e);
|
||||
_elements.push_back(e);
|
||||
e->SetParent(this);
|
||||
Remove(e);
|
||||
_elements.push_back(e);
|
||||
e->SetParent(this);
|
||||
}
|
||||
|
||||
void GuiWindow::Insert(GuiElement* e, u32 index)
|
||||
{
|
||||
LOCK( this );
|
||||
if (e == NULL || index > (_elements.size() - 1)) return;
|
||||
LOCK( this );
|
||||
if (e == NULL || index > (_elements.size() - 1)) return;
|
||||
|
||||
Remove(e);
|
||||
_elements.insert(_elements.begin() + index, e);
|
||||
e->SetParent(this);
|
||||
Remove(e);
|
||||
_elements.insert(_elements.begin() + index, e);
|
||||
e->SetParent(this);
|
||||
}
|
||||
|
||||
void GuiWindow::Remove(GuiElement* e)
|
||||
{
|
||||
LOCK( this );
|
||||
if (e == NULL) return;
|
||||
LOCK( this );
|
||||
if (e == NULL) return;
|
||||
|
||||
for (u8 i = 0; i < _elements.size(); i++)
|
||||
{
|
||||
if (e == _elements.at(i))
|
||||
{
|
||||
_elements.erase(_elements.begin() + i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
for (u8 i = 0; i < _elements.size(); i++)
|
||||
{
|
||||
if (e == _elements.at(i))
|
||||
{
|
||||
_elements.erase(_elements.begin() + i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GuiWindow::RemoveAll()
|
||||
{
|
||||
LOCK( this );
|
||||
_elements.clear();
|
||||
LOCK( this );
|
||||
_elements.clear();
|
||||
}
|
||||
|
||||
GuiElement* GuiWindow::GetGuiElementAt(u32 index) const
|
||||
{
|
||||
if (index >= _elements.size()) return NULL;
|
||||
return _elements.at(index);
|
||||
if (index >= _elements.size()) return NULL;
|
||||
return _elements.at(index);
|
||||
}
|
||||
|
||||
u32 GuiWindow::GetSize()
|
||||
{
|
||||
return _elements.size();
|
||||
return _elements.size();
|
||||
}
|
||||
|
||||
void GuiWindow::Draw()
|
||||
{
|
||||
LOCK( this );
|
||||
if (_elements.size() == 0 || !this->IsVisible()) return;
|
||||
LOCK( this );
|
||||
if (_elements.size() == 0 || !this->IsVisible()) return;
|
||||
|
||||
for (u8 i = 0; i < _elements.size(); i++)
|
||||
{
|
||||
try
|
||||
{
|
||||
_elements.at(i)->Draw();
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
}
|
||||
}
|
||||
for (u8 i = 0; i < _elements.size(); i++)
|
||||
{
|
||||
try
|
||||
{
|
||||
_elements.at(i)->Draw();
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
this->UpdateEffects();
|
||||
this->UpdateEffects();
|
||||
|
||||
if ((parentElement && state == STATE_DISABLED && allowDim) || forceDim)
|
||||
Menu_DrawRectangle(0, 0, screenwidth, screenheight, (GXColor) {0, 0, 0, 0x70}, 1);
|
||||
if ((parentElement && state == STATE_DISABLED && allowDim) || forceDim)
|
||||
Menu_DrawRectangle(0, 0, screenwidth, screenheight, (GXColor) {0, 0, 0, 0x70}, 1);
|
||||
}
|
||||
void GuiWindow::DrawTooltip()
|
||||
{
|
||||
LOCK( this );
|
||||
if (_elements.size() == 0 || !this->IsVisible()) return;
|
||||
LOCK( this );
|
||||
if (_elements.size() == 0 || !this->IsVisible()) return;
|
||||
|
||||
for (u8 i = 0; i < _elements.size(); i++)
|
||||
{
|
||||
try
|
||||
{
|
||||
_elements.at(i)->DrawTooltip();
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
}
|
||||
}
|
||||
for (u8 i = 0; i < _elements.size(); i++)
|
||||
{
|
||||
try
|
||||
{
|
||||
_elements.at(i)->DrawTooltip();
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
void GuiWindow::ResetState()
|
||||
{
|
||||
LOCK( this );
|
||||
if (state != STATE_DISABLED) state = STATE_DEFAULT;
|
||||
LOCK( this );
|
||||
if (state != STATE_DISABLED) state = STATE_DEFAULT;
|
||||
|
||||
for (u8 i = 0; i < _elements.size(); i++)
|
||||
{
|
||||
try
|
||||
{
|
||||
_elements.at(i)->ResetState();
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
}
|
||||
}
|
||||
for (u8 i = 0; i < _elements.size(); i++)
|
||||
{
|
||||
try
|
||||
{
|
||||
_elements.at(i)->ResetState();
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GuiWindow::SetState(int s)
|
||||
{
|
||||
LOCK( this );
|
||||
state = s;
|
||||
LOCK( this );
|
||||
state = s;
|
||||
|
||||
for (u8 i = 0; i < _elements.size(); i++)
|
||||
{
|
||||
try
|
||||
{
|
||||
_elements.at(i)->SetState(s);
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
}
|
||||
}
|
||||
for (u8 i = 0; i < _elements.size(); i++)
|
||||
{
|
||||
try
|
||||
{
|
||||
_elements.at(i)->SetState(s);
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GuiWindow::SetVisible(bool v)
|
||||
{
|
||||
LOCK( this );
|
||||
visible = v;
|
||||
LOCK( this );
|
||||
visible = v;
|
||||
|
||||
for (u8 i = 0; i < _elements.size(); i++)
|
||||
{
|
||||
try
|
||||
{
|
||||
_elements.at(i)->SetVisible(v);
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
}
|
||||
}
|
||||
for (u8 i = 0; i < _elements.size(); i++)
|
||||
{
|
||||
try
|
||||
{
|
||||
_elements.at(i)->SetVisible(v);
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GuiWindow::SetFocus(int f)
|
||||
{
|
||||
LOCK( this );
|
||||
focus = f;
|
||||
LOCK( this );
|
||||
focus = f;
|
||||
|
||||
if (f == 1)
|
||||
this->MoveSelectionVert(1);
|
||||
else this->ResetState();
|
||||
if (f == 1)
|
||||
this->MoveSelectionVert(1);
|
||||
else this->ResetState();
|
||||
}
|
||||
|
||||
void GuiWindow::ChangeFocus(GuiElement* e)
|
||||
{
|
||||
LOCK( this );
|
||||
if (parentElement) return; // this is only intended for the main window
|
||||
LOCK( this );
|
||||
if (parentElement) return; // this is only intended for the main window
|
||||
|
||||
for (u8 i = 0; i < _elements.size(); i++)
|
||||
{
|
||||
if (e == _elements.at(i))
|
||||
_elements.at(i)->SetFocus(1);
|
||||
else if (_elements.at(i)->IsFocused() == 1) _elements.at(i)->SetFocus(0);
|
||||
}
|
||||
for (u8 i = 0; i < _elements.size(); i++)
|
||||
{
|
||||
if (e == _elements.at(i))
|
||||
_elements.at(i)->SetFocus(1);
|
||||
else if (_elements.at(i)->IsFocused() == 1) _elements.at(i)->SetFocus(0);
|
||||
}
|
||||
}
|
||||
|
||||
void GuiWindow::ToggleFocus(GuiTrigger * t)
|
||||
{
|
||||
LOCK( this );
|
||||
if (parentElement) return; // this is only intended for the main window
|
||||
LOCK( this );
|
||||
if (parentElement) return; // this is only intended for the main window
|
||||
|
||||
int found = -1;
|
||||
int newfocus = -1;
|
||||
u8 i;
|
||||
int found = -1;
|
||||
int newfocus = -1;
|
||||
u8 i;
|
||||
|
||||
// look for currently in focus element
|
||||
for (i = 0; i < _elements.size(); i++)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (_elements.at(i)->IsFocused() == 1)
|
||||
{
|
||||
found = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
}
|
||||
}
|
||||
// look for currently in focus element
|
||||
for (i = 0; i < _elements.size(); i++)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (_elements.at(i)->IsFocused() == 1)
|
||||
{
|
||||
found = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
// element with focus not found, try to give focus
|
||||
if (found == -1)
|
||||
{
|
||||
for (i = 0; i < _elements.size(); i++)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (_elements.at(i)->IsFocused() == 0 && _elements.at(i)->GetState() != STATE_DISABLED) // focus is possible (but not set)
|
||||
{
|
||||
_elements.at(i)->SetFocus(1); // give this element focus
|
||||
break;
|
||||
}
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
// change focus
|
||||
else if ((t->wpad.btns_d & (WPAD_BUTTON_1 | WPAD_BUTTON_1 | WPAD_CLASSIC_BUTTON_PLUS)) || (t->pad.btns_d & PAD_BUTTON_B))
|
||||
{
|
||||
for (i = found; i < _elements.size(); i++)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (_elements.at(i)->IsFocused() == 0 && _elements.at(i)->GetState() != STATE_DISABLED) // focus is possible (but not set)
|
||||
{
|
||||
newfocus = i;
|
||||
_elements.at(i)->SetFocus(1); // give this element focus
|
||||
_elements.at(found)->SetFocus(0); // disable focus on other element
|
||||
break;
|
||||
}
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
}
|
||||
}
|
||||
// element with focus not found, try to give focus
|
||||
if (found == -1)
|
||||
{
|
||||
for (i = 0; i < _elements.size(); i++)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (_elements.at(i)->IsFocused() == 0 && _elements.at(i)->GetState() != STATE_DISABLED) // focus is possible (but not set)
|
||||
{
|
||||
_elements.at(i)->SetFocus(1); // give this element focus
|
||||
break;
|
||||
}
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
// change focus
|
||||
else if ((t->wpad.btns_d & (WPAD_BUTTON_1 | WPAD_BUTTON_1 | WPAD_CLASSIC_BUTTON_PLUS)) || (t->pad.btns_d & PAD_BUTTON_B))
|
||||
{
|
||||
for (i = found; i < _elements.size(); i++)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (_elements.at(i)->IsFocused() == 0 && _elements.at(i)->GetState() != STATE_DISABLED) // focus is possible (but not set)
|
||||
{
|
||||
newfocus = i;
|
||||
_elements.at(i)->SetFocus(1); // give this element focus
|
||||
_elements.at(found)->SetFocus(0); // disable focus on other element
|
||||
break;
|
||||
}
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
if (newfocus == -1)
|
||||
{
|
||||
for (i = 0; i < found; i++)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (_elements.at(i)->IsFocused() == 0 && _elements.at(i)->GetState() != STATE_DISABLED) // focus is possible (but not set)
|
||||
{
|
||||
_elements.at(i)->SetFocus(1); // give this element focus
|
||||
_elements.at(found)->SetFocus(0); // disable focus on other element
|
||||
break;
|
||||
}
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (newfocus == -1)
|
||||
{
|
||||
for (i = 0; i < found; i++)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (_elements.at(i)->IsFocused() == 0 && _elements.at(i)->GetState() != STATE_DISABLED) // focus is possible (but not set)
|
||||
{
|
||||
_elements.at(i)->SetFocus(1); // give this element focus
|
||||
_elements.at(found)->SetFocus(0); // disable focus on other element
|
||||
break;
|
||||
}
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int GuiWindow::GetSelected()
|
||||
{
|
||||
// find selected element
|
||||
int found = -1;
|
||||
for (u8 i = 0; i < _elements.size(); i++)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (_elements.at(i)->GetState() == STATE_SELECTED)
|
||||
{
|
||||
found = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
}
|
||||
}
|
||||
return found;
|
||||
// find selected element
|
||||
int found = -1;
|
||||
for (u8 i = 0; i < _elements.size(); i++)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (_elements.at(i)->GetState() == STATE_SELECTED)
|
||||
{
|
||||
found = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
}
|
||||
}
|
||||
return found;
|
||||
}
|
||||
|
||||
// set element to left/right as selected
|
||||
// there's probably a more clever way to do this, but this way works
|
||||
void GuiWindow::MoveSelectionHor(int dir)
|
||||
{
|
||||
LOCK( this );
|
||||
int found = -1;
|
||||
u16 left = 0;
|
||||
u16 top = 0;
|
||||
u8 i = 0;
|
||||
LOCK( this );
|
||||
int found = -1;
|
||||
u16 left = 0;
|
||||
u16 top = 0;
|
||||
u8 i = 0;
|
||||
|
||||
int selected = this->GetSelected();
|
||||
int selected = this->GetSelected();
|
||||
|
||||
if (selected >= 0)
|
||||
{
|
||||
left = _elements.at(selected)->GetLeft();
|
||||
top = _elements.at(selected)->GetTop();
|
||||
}
|
||||
if (selected >= 0)
|
||||
{
|
||||
left = _elements.at(selected)->GetLeft();
|
||||
top = _elements.at(selected)->GetTop();
|
||||
}
|
||||
|
||||
// look for a button on the same row, to the left/right
|
||||
for (i = 0; i < _elements.size(); i++)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (_elements.at(i)->IsSelectable())
|
||||
{
|
||||
if (_elements.at(i)->GetLeft() * dir > left * dir && _elements.at(i)->GetTop() == top)
|
||||
{
|
||||
if (found == -1)
|
||||
found = i;
|
||||
else if (_elements.at(i)->GetLeft() * dir < _elements.at(found)->GetLeft() * dir) found = i; // this is a better match
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
}
|
||||
}
|
||||
if (found >= 0) goto matchfound;
|
||||
// look for a button on the same row, to the left/right
|
||||
for (i = 0; i < _elements.size(); i++)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (_elements.at(i)->IsSelectable())
|
||||
{
|
||||
if (_elements.at(i)->GetLeft() * dir > left * dir && _elements.at(i)->GetTop() == top)
|
||||
{
|
||||
if (found == -1)
|
||||
found = i;
|
||||
else if (_elements.at(i)->GetLeft() * dir < _elements.at(found)->GetLeft() * dir) found = i; // this is a better match
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
}
|
||||
}
|
||||
if (found >= 0) goto matchfound;
|
||||
|
||||
// match still not found, let's try the first button in the next row
|
||||
for (i = 0; i < _elements.size(); i++)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (_elements.at(i)->IsSelectable())
|
||||
{
|
||||
if (_elements.at(i)->GetTop() * dir > top * dir)
|
||||
{
|
||||
if (found == -1)
|
||||
found = i;
|
||||
else if (_elements.at(i)->GetTop() * dir < _elements.at(found)->GetTop() * dir)
|
||||
found = i; // this is a better match
|
||||
else if (_elements.at(i)->GetTop() * dir == _elements.at(found)->GetTop() * dir
|
||||
&& _elements.at(i)->GetLeft() * dir < _elements.at(found)->GetLeft() * dir) found = i; // this is a better match
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
}
|
||||
}
|
||||
// match still not found, let's try the first button in the next row
|
||||
for (i = 0; i < _elements.size(); i++)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (_elements.at(i)->IsSelectable())
|
||||
{
|
||||
if (_elements.at(i)->GetTop() * dir > top * dir)
|
||||
{
|
||||
if (found == -1)
|
||||
found = i;
|
||||
else if (_elements.at(i)->GetTop() * dir < _elements.at(found)->GetTop() * dir)
|
||||
found = i; // this is a better match
|
||||
else if (_elements.at(i)->GetTop() * dir == _elements.at(found)->GetTop() * dir
|
||||
&& _elements.at(i)->GetLeft() * dir < _elements.at(found)->GetLeft() * dir) found = i; // this is a better match
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
// match found
|
||||
matchfound: if (found >= 0)
|
||||
{
|
||||
_elements.at(found)->SetState(STATE_SELECTED);
|
||||
if (selected >= 0) _elements.at(selected)->ResetState();
|
||||
}
|
||||
// match found
|
||||
matchfound: if (found >= 0)
|
||||
{
|
||||
_elements.at(found)->SetState(STATE_SELECTED);
|
||||
if (selected >= 0) _elements.at(selected)->ResetState();
|
||||
}
|
||||
}
|
||||
|
||||
void GuiWindow::MoveSelectionVert(int dir)
|
||||
{
|
||||
LOCK( this );
|
||||
int found = -1;
|
||||
u16 left = 0;
|
||||
u16 top = 0;
|
||||
u8 i = 0;
|
||||
LOCK( this );
|
||||
int found = -1;
|
||||
u16 left = 0;
|
||||
u16 top = 0;
|
||||
u8 i = 0;
|
||||
|
||||
int selected = this->GetSelected();
|
||||
int selected = this->GetSelected();
|
||||
|
||||
if (selected >= 0)
|
||||
{
|
||||
left = _elements.at(selected)->GetLeft();
|
||||
top = _elements.at(selected)->GetTop();
|
||||
}
|
||||
if (selected >= 0)
|
||||
{
|
||||
left = _elements.at(selected)->GetLeft();
|
||||
top = _elements.at(selected)->GetTop();
|
||||
}
|
||||
|
||||
// look for a button above/below, with the least horizontal difference
|
||||
for (i = 0; i < _elements.size(); i++)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (_elements.at(i)->IsSelectable())
|
||||
{
|
||||
if (_elements.at(i)->GetTop() * dir > top * dir)
|
||||
{
|
||||
if (found == -1)
|
||||
found = i;
|
||||
else if (_elements.at(i)->GetTop() * dir < _elements.at(found)->GetTop() * dir)
|
||||
found = i; // this is a better match
|
||||
else if (_elements.at(i)->GetTop() * dir == _elements.at(found)->GetTop() * dir && abs(
|
||||
_elements.at(i)->GetLeft() - left) < abs(_elements.at(found)->GetLeft() - left)) found = i;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
}
|
||||
}
|
||||
if (found >= 0) goto matchfound;
|
||||
// look for a button above/below, with the least horizontal difference
|
||||
for (i = 0; i < _elements.size(); i++)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (_elements.at(i)->IsSelectable())
|
||||
{
|
||||
if (_elements.at(i)->GetTop() * dir > top * dir)
|
||||
{
|
||||
if (found == -1)
|
||||
found = i;
|
||||
else if (_elements.at(i)->GetTop() * dir < _elements.at(found)->GetTop() * dir)
|
||||
found = i; // this is a better match
|
||||
else if (_elements.at(i)->GetTop() * dir == _elements.at(found)->GetTop() * dir && abs(
|
||||
_elements.at(i)->GetLeft() - left) < abs(_elements.at(found)->GetLeft() - left)) found = i;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
}
|
||||
}
|
||||
if (found >= 0) goto matchfound;
|
||||
|
||||
// match found
|
||||
matchfound: if (found >= 0)
|
||||
{
|
||||
_elements.at(found)->SetState(STATE_SELECTED);
|
||||
if (selected >= 0) _elements.at(selected)->ResetState();
|
||||
}
|
||||
// match found
|
||||
matchfound: if (found >= 0)
|
||||
{
|
||||
_elements.at(found)->SetState(STATE_SELECTED);
|
||||
if (selected >= 0) _elements.at(selected)->ResetState();
|
||||
}
|
||||
}
|
||||
|
||||
void GuiWindow::Update(GuiTrigger * t)
|
||||
{
|
||||
LOCK( this );
|
||||
if (_elements.size() == 0 || (state == STATE_DISABLED && parentElement)) return;
|
||||
LOCK( this );
|
||||
if (_elements.size() == 0 || (state == STATE_DISABLED && parentElement)) return;
|
||||
|
||||
for (u8 i = 0; i < _elements.size(); i++)
|
||||
{
|
||||
try
|
||||
{
|
||||
_elements.at(i)->Update(t);
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
}
|
||||
}
|
||||
for (u8 i = 0; i < _elements.size(); i++)
|
||||
{
|
||||
try
|
||||
{
|
||||
_elements.at(i)->Update(t);
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
this->ToggleFocus(t);
|
||||
this->ToggleFocus(t);
|
||||
|
||||
if (focus) // only send actions to this window if it's in focus
|
||||
{
|
||||
// pad/joystick navigation
|
||||
if (t->Right())
|
||||
this->MoveSelectionHor(1);
|
||||
else if (t->Left())
|
||||
this->MoveSelectionHor(-1);
|
||||
else if (t->Down())
|
||||
this->MoveSelectionVert(1);
|
||||
else if (t->Up()) this->MoveSelectionVert(-1);
|
||||
}
|
||||
if (focus) // only send actions to this window if it's in focus
|
||||
{
|
||||
// pad/joystick navigation
|
||||
if (t->Right())
|
||||
this->MoveSelectionHor(1);
|
||||
else if (t->Left())
|
||||
this->MoveSelectionHor(-1);
|
||||
else if (t->Down())
|
||||
this->MoveSelectionVert(1);
|
||||
else if (t->Up()) this->MoveSelectionVert(-1);
|
||||
}
|
||||
|
||||
if (updateCB) updateCB(this);
|
||||
if (updateCB) updateCB(this);
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
// Written by Sarah Thompson (sarah@telergy.com) 2002.
|
||||
//
|
||||
// License: Public domain. You are free to use this code however you like, with the proviso that
|
||||
// the author takes on no responsibility or liability for any use.
|
||||
// the author takes on no responsibility or liability for any use.
|
||||
//
|
||||
// QUICK DOCUMENTATION
|
||||
//
|
||||
|
@ -288,8 +288,8 @@ namespace sigslot {
|
|||
public:
|
||||
multi_threaded_global()
|
||||
{
|
||||
if(g_mutex == LWP_MUTEX_NULL)
|
||||
LWP_MutexInit(&g_mutex, NULL);
|
||||
if(g_mutex == LWP_MUTEX_NULL)
|
||||
LWP_MutexInit(&g_mutex, NULL);
|
||||
}
|
||||
|
||||
multi_threaded_global(const multi_threaded_global&)
|
||||
|
@ -318,12 +318,12 @@ namespace sigslot {
|
|||
public:
|
||||
multi_threaded_local()
|
||||
{
|
||||
;
|
||||
;
|
||||
}
|
||||
|
||||
multi_threaded_local(const multi_threaded_local&)
|
||||
{
|
||||
;
|
||||
;
|
||||
}
|
||||
|
||||
virtual ~multi_threaded_local()
|
||||
|
@ -796,8 +796,8 @@ namespace sigslot {
|
|||
public:
|
||||
typedef typename std::list<_connection_base2<arg1_type, arg2_type, mt_policy> *>
|
||||
connections_list;
|
||||
typedef typename connections_list::const_iterator const_iterator;
|
||||
typedef typename connections_list::iterator iterator;
|
||||
typedef typename connections_list::const_iterator const_iterator;
|
||||
typedef typename connections_list::iterator iterator;
|
||||
|
||||
_signal_base2()
|
||||
{
|
||||
|
@ -917,8 +917,8 @@ namespace sigslot {
|
|||
typedef std::list<_connection_base3<arg1_type, arg2_type, arg3_type, mt_policy> *>
|
||||
connections_list;
|
||||
|
||||
typedef typename connections_list::const_iterator const_iterator;
|
||||
typedef typename connections_list::iterator iterator;
|
||||
typedef typename connections_list::const_iterator const_iterator;
|
||||
typedef typename connections_list::iterator iterator;
|
||||
_signal_base3()
|
||||
{
|
||||
;
|
||||
|
@ -1036,8 +1036,8 @@ namespace sigslot {
|
|||
public:
|
||||
typedef std::list<_connection_base4<arg1_type, arg2_type, arg3_type,
|
||||
arg4_type, mt_policy> *> connections_list;
|
||||
typedef typename connections_list::const_iterator const_iterator;
|
||||
typedef typename connections_list::iterator iterator;
|
||||
typedef typename connections_list::const_iterator const_iterator;
|
||||
typedef typename connections_list::iterator iterator;
|
||||
|
||||
_signal_base4()
|
||||
{
|
||||
|
@ -1157,8 +1157,8 @@ namespace sigslot {
|
|||
public:
|
||||
typedef std::list<_connection_base5<arg1_type, arg2_type, arg3_type,
|
||||
arg4_type, arg5_type, mt_policy> *> connections_list;
|
||||
typedef typename connections_list::const_iterator const_iterator;
|
||||
typedef typename connections_list::iterator iterator;
|
||||
typedef typename connections_list::const_iterator const_iterator;
|
||||
typedef typename connections_list::iterator iterator;
|
||||
|
||||
_signal_base5()
|
||||
{
|
||||
|
@ -1279,8 +1279,8 @@ namespace sigslot {
|
|||
public:
|
||||
typedef std::list<_connection_base6<arg1_type, arg2_type, arg3_type,
|
||||
arg4_type, arg5_type, arg6_type, mt_policy> *> connections_list;
|
||||
typedef typename connections_list::const_iterator const_iterator;
|
||||
typedef typename connections_list::iterator iterator;
|
||||
typedef typename connections_list::const_iterator const_iterator;
|
||||
typedef typename connections_list::iterator iterator;
|
||||
|
||||
_signal_base6()
|
||||
{
|
||||
|
@ -1401,8 +1401,8 @@ namespace sigslot {
|
|||
public:
|
||||
typedef std::list<_connection_base7<arg1_type, arg2_type, arg3_type,
|
||||
arg4_type, arg5_type, arg6_type, arg7_type, mt_policy> *> connections_list;
|
||||
typedef typename connections_list::const_iterator const_iterator;
|
||||
typedef typename connections_list::iterator iterator;
|
||||
typedef typename connections_list::const_iterator const_iterator;
|
||||
typedef typename connections_list::iterator iterator;
|
||||
|
||||
_signal_base7()
|
||||
{
|
||||
|
@ -1524,8 +1524,8 @@ namespace sigslot {
|
|||
typedef std::list<_connection_base8<arg1_type, arg2_type, arg3_type,
|
||||
arg4_type, arg5_type, arg6_type, arg7_type, arg8_type, mt_policy> *>
|
||||
connections_list;
|
||||
typedef typename connections_list::const_iterator const_iterator;
|
||||
typedef typename connections_list::iterator iterator;
|
||||
typedef typename connections_list::const_iterator const_iterator;
|
||||
typedef typename connections_list::iterator iterator;
|
||||
|
||||
_signal_base8()
|
||||
{
|
||||
|
@ -1797,10 +1797,10 @@ namespace sigslot {
|
|||
m_pmemfun = pmemfun;
|
||||
}
|
||||
|
||||
virtual ~_connection3()
|
||||
{
|
||||
;
|
||||
}
|
||||
virtual ~_connection3()
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
|
||||
virtual _connection_base3<arg1_type, arg2_type, arg3_type, mt_policy>* clone()
|
||||
|
@ -1847,10 +1847,10 @@ namespace sigslot {
|
|||
m_pmemfun = pmemfun;
|
||||
}
|
||||
|
||||
virtual ~_connection4()
|
||||
{
|
||||
;
|
||||
}
|
||||
virtual ~_connection4()
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
virtual _connection_base4<arg1_type, arg2_type, arg3_type, arg4_type, mt_policy>* clone()
|
||||
{
|
||||
|
@ -1898,10 +1898,10 @@ namespace sigslot {
|
|||
m_pmemfun = pmemfun;
|
||||
}
|
||||
|
||||
virtual ~_connection5()
|
||||
{
|
||||
;
|
||||
}
|
||||
virtual ~_connection5()
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
virtual _connection_base5<arg1_type, arg2_type, arg3_type, arg4_type,
|
||||
arg5_type, mt_policy>* clone()
|
||||
|
@ -1953,10 +1953,10 @@ namespace sigslot {
|
|||
m_pmemfun = pmemfun;
|
||||
}
|
||||
|
||||
virtual ~_connection6()
|
||||
{
|
||||
;
|
||||
}
|
||||
virtual ~_connection6()
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
virtual _connection_base6<arg1_type, arg2_type, arg3_type, arg4_type,
|
||||
arg5_type, arg6_type, mt_policy>* clone()
|
||||
|
@ -2008,10 +2008,10 @@ namespace sigslot {
|
|||
m_pmemfun = pmemfun;
|
||||
}
|
||||
|
||||
virtual ~_connection7()
|
||||
{
|
||||
;
|
||||
}
|
||||
virtual ~_connection7()
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
virtual _connection_base7<arg1_type, arg2_type, arg3_type, arg4_type,
|
||||
arg5_type, arg6_type, arg7_type, mt_policy>* clone()
|
||||
|
@ -2065,10 +2065,10 @@ namespace sigslot {
|
|||
m_pmemfun = pmemfun;
|
||||
}
|
||||
|
||||
virtual ~_connection8()
|
||||
{
|
||||
;
|
||||
}
|
||||
virtual ~_connection8()
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
virtual _connection_base8<arg1_type, arg2_type, arg3_type, arg4_type,
|
||||
arg5_type, arg6_type, arg7_type, arg8_type, mt_policy>* clone()
|
||||
|
@ -2105,7 +2105,7 @@ namespace sigslot {
|
|||
class signal0 : public _signal_base0<mt_policy>
|
||||
{
|
||||
public:
|
||||
typedef typename _signal_base0<mt_policy>::connections_list::const_iterator const_iterator;
|
||||
typedef typename _signal_base0<mt_policy>::connections_list::const_iterator const_iterator;
|
||||
signal0()
|
||||
{
|
||||
;
|
||||
|
@ -2171,7 +2171,7 @@ namespace sigslot {
|
|||
class signal1 : public _signal_base1<arg1_type, mt_policy>
|
||||
{
|
||||
public:
|
||||
typedef typename _signal_base1<arg1_type, mt_policy>::connections_list::const_iterator const_iterator;
|
||||
typedef typename _signal_base1<arg1_type, mt_policy>::connections_list::const_iterator const_iterator;
|
||||
signal1()
|
||||
{
|
||||
;
|
||||
|
@ -2237,7 +2237,7 @@ namespace sigslot {
|
|||
class signal2 : public _signal_base2<arg1_type, arg2_type, mt_policy>
|
||||
{
|
||||
public:
|
||||
typedef typename _signal_base2<arg1_type, arg2_type, mt_policy>::connections_list::const_iterator const_iterator;
|
||||
typedef typename _signal_base2<arg1_type, arg2_type, mt_policy>::connections_list::const_iterator const_iterator;
|
||||
signal2()
|
||||
{
|
||||
;
|
||||
|
@ -2304,7 +2304,7 @@ namespace sigslot {
|
|||
class signal3 : public _signal_base3<arg1_type, arg2_type, arg3_type, mt_policy>
|
||||
{
|
||||
public:
|
||||
typedef typename _signal_base3<arg1_type, arg2_type, arg3_type, mt_policy>::connections_list::const_iterator const_iterator;
|
||||
typedef typename _signal_base3<arg1_type, arg2_type, arg3_type, mt_policy>::connections_list::const_iterator const_iterator;
|
||||
signal3()
|
||||
{
|
||||
;
|
||||
|
@ -2373,7 +2373,7 @@ namespace sigslot {
|
|||
arg4_type, mt_policy>
|
||||
{
|
||||
public:
|
||||
typedef typename _signal_base4<arg1_type, arg2_type, arg3_type, arg4_type, mt_policy>::connections_list::const_iterator const_iterator;
|
||||
typedef typename _signal_base4<arg1_type, arg2_type, arg3_type, arg4_type, mt_policy>::connections_list::const_iterator const_iterator;
|
||||
signal4()
|
||||
{
|
||||
;
|
||||
|
@ -2443,7 +2443,7 @@ namespace sigslot {
|
|||
arg4_type, arg5_type, mt_policy>
|
||||
{
|
||||
public:
|
||||
typedef typename _signal_base5<arg1_type, arg2_type, arg3_type, arg4_type, arg5_type, mt_policy>::connections_list::const_iterator const_iterator;
|
||||
typedef typename _signal_base5<arg1_type, arg2_type, arg3_type, arg4_type, arg5_type, mt_policy>::connections_list::const_iterator const_iterator;
|
||||
signal5()
|
||||
{
|
||||
;
|
||||
|
@ -2518,7 +2518,7 @@ namespace sigslot {
|
|||
arg4_type, arg5_type, arg6_type, mt_policy>
|
||||
{
|
||||
public:
|
||||
typedef typename _signal_base6<arg1_type, arg2_type, arg3_type,
|
||||
typedef typename _signal_base6<arg1_type, arg2_type, arg3_type,
|
||||
arg4_type, arg5_type, arg6_type, mt_policy>::connections_list::const_iterator const_iterator;
|
||||
signal6()
|
||||
{
|
||||
|
@ -2594,7 +2594,7 @@ namespace sigslot {
|
|||
arg4_type, arg5_type, arg6_type, arg7_type, mt_policy>
|
||||
{
|
||||
public:
|
||||
typedef typename _signal_base7<arg1_type, arg2_type, arg3_type,
|
||||
typedef typename _signal_base7<arg1_type, arg2_type, arg3_type,
|
||||
arg4_type, arg5_type, arg6_type, arg7_type, mt_policy>::connections_list::const_iterator const_iterator;
|
||||
signal7()
|
||||
{
|
||||
|
@ -2671,7 +2671,7 @@ namespace sigslot {
|
|||
arg4_type, arg5_type, arg6_type, arg7_type, arg8_type, mt_policy>
|
||||
{
|
||||
public:
|
||||
typedef typename _signal_base8<arg1_type, arg2_type, arg3_type,
|
||||
typedef typename _signal_base8<arg1_type, arg2_type, arg3_type,
|
||||
arg4_type, arg5_type, arg6_type, arg7_type, arg8_type, mt_policy>::connections_list::const_iterator const_iterator;
|
||||
signal8()
|
||||
{
|
||||
|
|
|
@ -68,14 +68,14 @@ bool I4ToGD(const u8 * buffer, u32 width, u32 height, gdImagePtr * im)
|
|||
u32 iv;
|
||||
|
||||
if(!buffer)
|
||||
return false;
|
||||
return false;
|
||||
|
||||
*im = gdImageCreateTrueColor(width, height);
|
||||
if(*im == 0)
|
||||
return false;
|
||||
|
||||
gdImageAlphaBlending(*im, 0);
|
||||
gdImageSaveAlpha(*im, 1);
|
||||
gdImageAlphaBlending(*im, 0);
|
||||
gdImageSaveAlpha(*im, 1);
|
||||
|
||||
for(iv = 0, y1 = 0; y1 < height; y1 += 8)
|
||||
{
|
||||
|
@ -116,14 +116,14 @@ bool IA4ToGD(const u8 * buffer, u32 width, u32 height, gdImagePtr * im)
|
|||
u32 iv;
|
||||
|
||||
if(!buffer)
|
||||
return false;
|
||||
return false;
|
||||
|
||||
*im = gdImageCreateTrueColor(width, height);
|
||||
if(*im == 0)
|
||||
return false;
|
||||
|
||||
gdImageAlphaBlending(*im, 0);
|
||||
gdImageSaveAlpha(*im, 1);
|
||||
gdImageAlphaBlending(*im, 0);
|
||||
gdImageSaveAlpha(*im, 1);
|
||||
|
||||
for(iv = 0, y1 = 0; y1 < height; y1 += 4)
|
||||
{
|
||||
|
@ -143,7 +143,7 @@ bool IA4ToGD(const u8 * buffer, u32 width, u32 height, gdImagePtr * im)
|
|||
u8 g = ((oldpixel & 0xF) * 255) / 15;
|
||||
u8 b = ((oldpixel & 0xF) * 255) / 15;
|
||||
u8 a = ((oldpixel >> 4) * 255) / 15;
|
||||
a = 127-127*a/255;
|
||||
a = 127-127*a/255;
|
||||
|
||||
gdImageSetPixel(*im, x+1, y, gdTrueColorAlpha(r, g, b, a));
|
||||
}
|
||||
|
@ -160,14 +160,14 @@ bool I8ToGD(const u8 * buffer, u32 width, u32 height, gdImagePtr * im)
|
|||
u32 iv;
|
||||
|
||||
if(!buffer)
|
||||
return false;
|
||||
return false;
|
||||
|
||||
*im = gdImageCreateTrueColor(width, height);
|
||||
if(*im == 0)
|
||||
return false;
|
||||
|
||||
gdImageAlphaBlending(*im, 0);
|
||||
gdImageSaveAlpha(*im, 1);
|
||||
gdImageAlphaBlending(*im, 0);
|
||||
gdImageSaveAlpha(*im, 1);
|
||||
|
||||
for(iv = 0, y1 = 0; y1 < height; y1 += 4)
|
||||
{
|
||||
|
@ -202,14 +202,14 @@ bool IA8ToGD(const u8 * buffer, u32 width, u32 height, gdImagePtr * im)
|
|||
u32 iv;
|
||||
|
||||
if(!buffer)
|
||||
return false;
|
||||
return false;
|
||||
|
||||
*im = gdImageCreateTrueColor(width, height);
|
||||
if(*im == 0)
|
||||
return false;
|
||||
|
||||
gdImageAlphaBlending(*im, 0);
|
||||
gdImageSaveAlpha(*im, 1);
|
||||
gdImageAlphaBlending(*im, 0);
|
||||
gdImageSaveAlpha(*im, 1);
|
||||
|
||||
for(iv = 0, y1 = 0; y1 < height; y1 += 4)
|
||||
{
|
||||
|
@ -228,7 +228,7 @@ bool IA8ToGD(const u8 * buffer, u32 width, u32 height, gdImagePtr * im)
|
|||
u8 g = oldpixel >> 8;
|
||||
u8 b = oldpixel >> 8;
|
||||
u8 a = oldpixel & 0xFF;
|
||||
a = 127-127*a/255;
|
||||
a = 127-127*a/255;
|
||||
|
||||
gdImageSetPixel(*im, x+1, y, gdTrueColorAlpha(r, g, b, a));
|
||||
}
|
||||
|
@ -241,23 +241,23 @@ bool IA8ToGD(const u8 * buffer, u32 width, u32 height, gdImagePtr * im)
|
|||
bool CMPToGD(const u8* buffer, u32 width, u32 height, gdImagePtr * im)
|
||||
{
|
||||
u32 x, y;
|
||||
u8 r, g, b, a;
|
||||
u16 raw;
|
||||
u16 c[4];
|
||||
int x0, x1, x2, y0, y1, y2, off;
|
||||
int ww = (-(-(width) & -(8)));
|
||||
int ix;
|
||||
u32 px;
|
||||
u8 r, g, b, a;
|
||||
u16 raw;
|
||||
u16 c[4];
|
||||
int x0, x1, x2, y0, y1, y2, off;
|
||||
int ww = (-(-(width) & -(8)));
|
||||
int ix;
|
||||
u32 px;
|
||||
|
||||
if(!buffer)
|
||||
return false;
|
||||
return false;
|
||||
|
||||
*im = gdImageCreateTrueColor(width, height);
|
||||
if(*im == 0)
|
||||
return false;
|
||||
|
||||
gdImageAlphaBlending(*im, 0);
|
||||
gdImageSaveAlpha(*im, 1);
|
||||
gdImageAlphaBlending(*im, 0);
|
||||
gdImageSaveAlpha(*im, 1);
|
||||
|
||||
for (y = 0; y < height; y++)
|
||||
{
|
||||
|
@ -290,7 +290,7 @@ bool CMPToGD(const u8* buffer, u32 width, u32 height, gdImagePtr * im)
|
|||
b = (raw << 3) & 0xf8;
|
||||
a = gdAlphaOpaque;
|
||||
|
||||
gdImageSetPixel(*im, x, y, gdTrueColorAlpha(r, g, b, a));
|
||||
gdImageSetPixel(*im, x, y, gdTrueColorAlpha(r, g, b, a));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -304,14 +304,14 @@ bool RGB565ToGD(const u8* buffer, u32 width, u32 height, gdImagePtr * im)
|
|||
u32 iv;
|
||||
|
||||
if(!buffer)
|
||||
return false;
|
||||
return false;
|
||||
|
||||
*im = gdImageCreateTrueColor(width, height);
|
||||
if(*im == 0)
|
||||
return false;
|
||||
|
||||
gdImageAlphaBlending(*im, 0);
|
||||
gdImageSaveAlpha(*im, 1);
|
||||
gdImageAlphaBlending(*im, 0);
|
||||
gdImageSaveAlpha(*im, 1);
|
||||
|
||||
for(iv = 0, y1 = 0; y1 < height; y1 += 4)
|
||||
{
|
||||
|
@ -331,7 +331,7 @@ bool RGB565ToGD(const u8* buffer, u32 width, u32 height, gdImagePtr * im)
|
|||
u8 b = ((pixel >> 0) & 0x1F) << 3;
|
||||
u8 a = gdAlphaOpaque;
|
||||
|
||||
gdImageSetPixel(*im, x, y, gdTrueColorAlpha(r, g, b, a));
|
||||
gdImageSetPixel(*im, x, y, gdTrueColorAlpha(r, g, b, a));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -346,14 +346,14 @@ bool RGB565A3ToGD(const u8* buffer, u32 width, u32 height, gdImagePtr * im)
|
|||
u32 iv;
|
||||
|
||||
if(!buffer)
|
||||
return false;
|
||||
return false;
|
||||
|
||||
*im = gdImageCreateTrueColor(width, height);
|
||||
if(*im == 0)
|
||||
return false;
|
||||
|
||||
gdImageAlphaBlending(*im, 0);
|
||||
gdImageSaveAlpha(*im, 1);
|
||||
gdImageAlphaBlending(*im, 0);
|
||||
gdImageSaveAlpha(*im, 1);
|
||||
|
||||
for(iv = 0, y1 = 0; y1 < height; y1 += 4)
|
||||
{
|
||||
|
@ -375,7 +375,7 @@ bool RGB565A3ToGD(const u8* buffer, u32 width, u32 height, gdImagePtr * im)
|
|||
u8 b = (((pixel >> 0) & 0x1F) * 255) / 31;
|
||||
u8 a = gdAlphaOpaque;
|
||||
|
||||
gdImageSetPixel(*im, x, y, gdTrueColorAlpha(r, g, b, a));
|
||||
gdImageSetPixel(*im, x, y, gdTrueColorAlpha(r, g, b, a));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -384,9 +384,9 @@ bool RGB565A3ToGD(const u8* buffer, u32 width, u32 height, gdImagePtr * im)
|
|||
u8 g = (((pixel >> 8) & 0xF) * 255) / 15;
|
||||
u8 b = (((pixel >> 4) & 0xF) * 255) / 15;
|
||||
u8 a = (((pixel >> 0) & 0x7) * 64) / 7;
|
||||
a = 127-127*a/255;
|
||||
a = 127-127*a/255;
|
||||
|
||||
gdImageSetPixel(*im, x, y, gdTrueColorAlpha(r, g, b, a));
|
||||
gdImageSetPixel(*im, x, y, gdTrueColorAlpha(r, g, b, a));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -402,28 +402,28 @@ bool RGBA8ToGD(const u8* buffer, u32 width, u32 height, gdImagePtr * im)
|
|||
u8 r, g, b, a;
|
||||
|
||||
if(!buffer)
|
||||
return false;
|
||||
return false;
|
||||
|
||||
*im = gdImageCreateTrueColor(width, height);
|
||||
if(*im == 0)
|
||||
return false;
|
||||
|
||||
gdImageAlphaBlending(*im, 0);
|
||||
gdImageSaveAlpha(*im, 1);
|
||||
gdImageAlphaBlending(*im, 0);
|
||||
gdImageSaveAlpha(*im, 1);
|
||||
|
||||
for(y = 0; y < height; y++)
|
||||
{
|
||||
for(x = 0; x < width; x++)
|
||||
{
|
||||
offset = coordsRGBA8(x, y, width);
|
||||
a = *(buffer+offset);
|
||||
r = *(buffer+offset+1);
|
||||
g = *(buffer+offset+32);
|
||||
b = *(buffer+offset+33);
|
||||
offset = coordsRGBA8(x, y, width);
|
||||
a = *(buffer+offset);
|
||||
r = *(buffer+offset+1);
|
||||
g = *(buffer+offset+32);
|
||||
b = *(buffer+offset+33);
|
||||
|
||||
a = 127-127*a/255;
|
||||
a = 127-127*a/255;
|
||||
|
||||
gdImageSetPixel(*im, x, y, gdTrueColorAlpha(r, g, b, a));
|
||||
gdImageSetPixel(*im, x, y, gdTrueColorAlpha(r, g, b, a));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -433,185 +433,185 @@ bool RGBA8ToGD(const u8* buffer, u32 width, u32 height, gdImagePtr * im)
|
|||
bool YCbYCrToGD(const u8* buffer, u32 width, u32 height, gdImagePtr * im)
|
||||
{
|
||||
u32 x, y, x1, YCbYCr;
|
||||
int r, g, b;
|
||||
u8 r1, g1, b1;
|
||||
int r, g, b;
|
||||
u8 r1, g1, b1;
|
||||
|
||||
if(!buffer)
|
||||
return false;
|
||||
return false;
|
||||
|
||||
*im = gdImageCreateTrueColor(width, height);
|
||||
if(*im == 0)
|
||||
return false;
|
||||
|
||||
gdImageAlphaBlending(*im, 0);
|
||||
gdImageSaveAlpha(*im, 1);
|
||||
gdImageAlphaBlending(*im, 0);
|
||||
gdImageSaveAlpha(*im, 1);
|
||||
|
||||
for(y = 0; y < height; y++)
|
||||
{
|
||||
for (x = 0, x1 = 0; x < (width / 2); x++, x1++)
|
||||
{
|
||||
YCbYCr = ((u32 *) buffer)[y*width/2+x];
|
||||
for(y = 0; y < height; y++)
|
||||
{
|
||||
for (x = 0, x1 = 0; x < (width / 2); x++, x1++)
|
||||
{
|
||||
YCbYCr = ((u32 *) buffer)[y*width/2+x];
|
||||
|
||||
u8 * val = (u8 *) &YCbYCr;
|
||||
u8 * val = (u8 *) &YCbYCr;
|
||||
|
||||
r = (int) (1.371f * (val[3] - 128));
|
||||
g = (int) (- 0.698f * (val[3] - 128) - 0.336f * (val[1] - 128));
|
||||
b = (int) (1.732f * (val[1] - 128));
|
||||
r = (int) (1.371f * (val[3] - 128));
|
||||
g = (int) (- 0.698f * (val[3] - 128) - 0.336f * (val[1] - 128));
|
||||
b = (int) (1.732f * (val[1] - 128));
|
||||
|
||||
r1 = cut_bounds(val[0] + r, 0, 255);
|
||||
g1 = cut_bounds(val[0] + g, 0, 255);
|
||||
b1 = cut_bounds(val[0] + b, 0, 255);
|
||||
r1 = cut_bounds(val[0] + r, 0, 255);
|
||||
g1 = cut_bounds(val[0] + g, 0, 255);
|
||||
b1 = cut_bounds(val[0] + b, 0, 255);
|
||||
|
||||
gdImageSetPixel(*im, x1, y, gdTrueColorAlpha(r1, g1, b1, gdAlphaOpaque));
|
||||
x1++;
|
||||
gdImageSetPixel(*im, x1, y, gdTrueColorAlpha(r1, g1, b1, gdAlphaOpaque));
|
||||
x1++;
|
||||
|
||||
r1 = cut_bounds(val[2] + r, 0, 255);
|
||||
g1 = cut_bounds(val[2] + g, 0, 255);
|
||||
b1 = cut_bounds(val[2] + b, 0, 255);
|
||||
gdImageSetPixel(*im, x1, y, gdTrueColorAlpha(r1, g1, b1, gdAlphaOpaque));
|
||||
}
|
||||
}
|
||||
r1 = cut_bounds(val[2] + r, 0, 255);
|
||||
g1 = cut_bounds(val[2] + g, 0, 255);
|
||||
b1 = cut_bounds(val[2] + b, 0, 255);
|
||||
gdImageSetPixel(*im, x1, y, gdTrueColorAlpha(r1, g1, b1, gdAlphaOpaque));
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
u8 * GDImageToRGBA8(gdImagePtr * gdImg, int * w, int * h)
|
||||
{
|
||||
int width = gdImageSX(*gdImg);
|
||||
int height = gdImageSY(*gdImg);
|
||||
float scale = 1.0f;
|
||||
int retries = 100; //shouldn't need that long but to be sure
|
||||
float scale = 1.0f;
|
||||
int retries = 100; //shouldn't need that long but to be sure
|
||||
|
||||
gdImageAlphaBlending(*gdImg, 0);
|
||||
gdImageSaveAlpha(*gdImg, 1);
|
||||
gdImageAlphaBlending(*gdImg, 0);
|
||||
gdImageSaveAlpha(*gdImg, 1);
|
||||
|
||||
while(width*scale > MAXWIDTH || height*scale > MAXHEIGHT)
|
||||
{
|
||||
if(width*scale > MAXWIDTH)
|
||||
scale = MAXWIDTH/width;
|
||||
if(height*scale > MAXHEIGHT)
|
||||
scale = MAXHEIGHT/height;
|
||||
while(width*scale > MAXWIDTH || height*scale > MAXHEIGHT)
|
||||
{
|
||||
if(width*scale > MAXWIDTH)
|
||||
scale = MAXWIDTH/width;
|
||||
if(height*scale > MAXHEIGHT)
|
||||
scale = MAXHEIGHT/height;
|
||||
|
||||
retries--;
|
||||
retries--;
|
||||
|
||||
if(!retries)
|
||||
{
|
||||
while(width*scale > MAXWIDTH || height*scale > MAXHEIGHT)
|
||||
scale -= 0.02;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(!retries)
|
||||
{
|
||||
while(width*scale > MAXWIDTH || height*scale > MAXHEIGHT)
|
||||
scale -= 0.02;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
width = ALIGN((int) (width * scale));
|
||||
height = ALIGN((int) (height * scale));
|
||||
width = ALIGN((int) (width * scale));
|
||||
height = ALIGN((int) (height * scale));
|
||||
|
||||
if(width != gdImageSX(*gdImg) || height != gdImageSY(*gdImg))
|
||||
{
|
||||
gdImagePtr dst = gdImageCreateTrueColor(width, height);
|
||||
gdImageAlphaBlending(dst, 0);
|
||||
gdImageSaveAlpha(dst, 1);
|
||||
gdImageCopyResized(dst, *gdImg, 0, 0, 0, 0, width, height, gdImageSX(*gdImg), gdImageSY(*gdImg));
|
||||
if(width != gdImageSX(*gdImg) || height != gdImageSY(*gdImg))
|
||||
{
|
||||
gdImagePtr dst = gdImageCreateTrueColor(width, height);
|
||||
gdImageAlphaBlending(dst, 0);
|
||||
gdImageSaveAlpha(dst, 1);
|
||||
gdImageCopyResized(dst, *gdImg, 0, 0, 0, 0, width, height, gdImageSX(*gdImg), gdImageSY(*gdImg));
|
||||
|
||||
gdImageDestroy(*gdImg);
|
||||
*gdImg = dst;
|
||||
gdImageDestroy(*gdImg);
|
||||
*gdImg = dst;
|
||||
|
||||
width = gdImageSX(*gdImg);
|
||||
height = gdImageSY(*gdImg);
|
||||
}
|
||||
width = gdImageSX(*gdImg);
|
||||
height = gdImageSY(*gdImg);
|
||||
}
|
||||
|
||||
int len = datasizeRGBA8(width, height);
|
||||
int len = datasizeRGBA8(width, height);
|
||||
|
||||
u8 * data = (u8 *) memalign(32, len);
|
||||
if(!data)
|
||||
return NULL;
|
||||
u8 * data = (u8 *) memalign(32, len);
|
||||
if(!data)
|
||||
return NULL;
|
||||
|
||||
u8 a;
|
||||
int x, y;
|
||||
int x, y;
|
||||
u32 pixel, offset;
|
||||
|
||||
for(y = 0; y < height; ++y)
|
||||
{
|
||||
for(x = 0; x < width; ++x)
|
||||
{
|
||||
pixel = gdImageGetPixel(*gdImg, x, y);
|
||||
for(y = 0; y < height; ++y)
|
||||
{
|
||||
for(x = 0; x < width; ++x)
|
||||
{
|
||||
pixel = gdImageGetPixel(*gdImg, x, y);
|
||||
|
||||
a = 254 - 2*((u8)gdImageAlpha(*gdImg, pixel));
|
||||
if(a == 254) a++;
|
||||
a = 254 - 2*((u8)gdImageAlpha(*gdImg, pixel));
|
||||
if(a == 254) a++;
|
||||
|
||||
offset = coordsRGBA8(x, y, width);
|
||||
data[offset] = a;
|
||||
data[offset+1] = (u8)gdImageRed(*gdImg, pixel);
|
||||
data[offset+32] = (u8)gdImageGreen(*gdImg, pixel);
|
||||
data[offset+33] = (u8)gdImageBlue(*gdImg, pixel);
|
||||
}
|
||||
}
|
||||
offset = coordsRGBA8(x, y, width);
|
||||
data[offset] = a;
|
||||
data[offset+1] = (u8)gdImageRed(*gdImg, pixel);
|
||||
data[offset+32] = (u8)gdImageGreen(*gdImg, pixel);
|
||||
data[offset+33] = (u8)gdImageBlue(*gdImg, pixel);
|
||||
}
|
||||
}
|
||||
|
||||
DCFlushRange(data, len);
|
||||
DCFlushRange(data, len);
|
||||
|
||||
if(w)
|
||||
*w = width;
|
||||
if(h)
|
||||
*h = height;
|
||||
if(w)
|
||||
*w = width;
|
||||
if(h)
|
||||
*h = height;
|
||||
|
||||
return data;
|
||||
return data;
|
||||
}
|
||||
|
||||
u8 * FlipRGBAImage(const u8 *src, u32 width, u32 height)
|
||||
{
|
||||
u32 x, y;
|
||||
u32 x, y;
|
||||
|
||||
int len = datasizeRGBA8(width, height);
|
||||
int len = datasizeRGBA8(width, height);
|
||||
|
||||
u8 * data = memalign(32, len);
|
||||
if(!data)
|
||||
return NULL;
|
||||
u8 * data = memalign(32, len);
|
||||
if(!data)
|
||||
return NULL;
|
||||
|
||||
for (y = 0; y < height; y++)
|
||||
{
|
||||
for (x = 0; x < width; x++)
|
||||
{
|
||||
u32 offset = coordsRGBA8(x, y, width);
|
||||
u8 a = src[offset];
|
||||
u8 r = src[offset+1];
|
||||
u8 g = src[offset+32];
|
||||
u8 b = src[offset+33];
|
||||
for (y = 0; y < height; y++)
|
||||
{
|
||||
for (x = 0; x < width; x++)
|
||||
{
|
||||
u32 offset = coordsRGBA8(x, y, width);
|
||||
u8 a = src[offset];
|
||||
u8 r = src[offset+1];
|
||||
u8 g = src[offset+32];
|
||||
u8 b = src[offset+33];
|
||||
|
||||
u32 offset2 = coordsRGBA8((width-x-1), (height-y-1), width);
|
||||
data[offset2] = a;
|
||||
data[offset2+1] = r;
|
||||
data[offset2+32] = g;
|
||||
data[offset2+33] = b;
|
||||
}
|
||||
}
|
||||
u32 offset2 = coordsRGBA8((width-x-1), (height-y-1), width);
|
||||
data[offset2] = a;
|
||||
data[offset2+1] = r;
|
||||
data[offset2+32] = g;
|
||||
data[offset2+33] = b;
|
||||
}
|
||||
}
|
||||
|
||||
DCFlushRange(data, len);
|
||||
DCFlushRange(data, len);
|
||||
|
||||
return data;
|
||||
return data;
|
||||
}
|
||||
|
||||
u8 * RGB8ToRGBA8(const u8 *src, u32 width, u32 height)
|
||||
{
|
||||
u32 x, y, offset;
|
||||
u32 x, y, offset;
|
||||
|
||||
int len = datasizeRGBA8(width, height);
|
||||
int len = datasizeRGBA8(width, height);
|
||||
|
||||
u8 * dst = (u8 *) memalign(32, len);
|
||||
if(!dst)
|
||||
return NULL;
|
||||
u8 * dst = (u8 *) memalign(32, len);
|
||||
if(!dst)
|
||||
return NULL;
|
||||
|
||||
for (y = 0; y < height; ++y)
|
||||
{
|
||||
for (x = 0; x < width; ++x)
|
||||
{
|
||||
offset = coordsRGBA8(x, y, width);
|
||||
dst[offset] = 0xFF;
|
||||
dst[offset+1] = src[(y*width+x)*3];
|
||||
dst[offset+32] = src[(y*width+x)*3+1];
|
||||
dst[offset+33] = src[(y*width+x)*3+2];
|
||||
}
|
||||
}
|
||||
for (y = 0; y < height; ++y)
|
||||
{
|
||||
for (x = 0; x < width; ++x)
|
||||
{
|
||||
offset = coordsRGBA8(x, y, width);
|
||||
dst[offset] = 0xFF;
|
||||
dst[offset+1] = src[(y*width+x)*3];
|
||||
dst[offset+32] = src[(y*width+x)*3+1];
|
||||
dst[offset+33] = src[(y*width+x)*3+2];
|
||||
}
|
||||
}
|
||||
|
||||
DCFlushRange(dst, len);
|
||||
DCFlushRange(dst, len);
|
||||
|
||||
return dst;
|
||||
return dst;
|
||||
}
|
||||
|
|
|
@ -34,211 +34,211 @@
|
|||
|
||||
TplImage::TplImage(const char * filepath)
|
||||
{
|
||||
TPLBuffer = NULL;
|
||||
TPLSize = 0;
|
||||
TPLBuffer = NULL;
|
||||
TPLSize = 0;
|
||||
|
||||
u8 * buffer = NULL;
|
||||
u64 filesize = 0;
|
||||
LoadFileToMem(filepath, &buffer, &filesize);
|
||||
u8 * buffer = NULL;
|
||||
u64 filesize = 0;
|
||||
LoadFileToMem(filepath, &buffer, &filesize);
|
||||
|
||||
if(buffer)
|
||||
{
|
||||
LoadImage(buffer, filesize);
|
||||
free(buffer);
|
||||
}
|
||||
if(buffer)
|
||||
{
|
||||
LoadImage(buffer, filesize);
|
||||
free(buffer);
|
||||
}
|
||||
}
|
||||
|
||||
TplImage::TplImage(const u8 * imgBuffer, u32 imgSize)
|
||||
{
|
||||
TPLBuffer = NULL;
|
||||
TPLSize = 0;
|
||||
TPLBuffer = NULL;
|
||||
TPLSize = 0;
|
||||
|
||||
if(imgBuffer)
|
||||
{
|
||||
LoadImage(imgBuffer, imgSize);
|
||||
}
|
||||
if(imgBuffer)
|
||||
{
|
||||
LoadImage(imgBuffer, imgSize);
|
||||
}
|
||||
}
|
||||
|
||||
TplImage::~TplImage()
|
||||
{
|
||||
if(TPLBuffer)
|
||||
free(TPLBuffer);
|
||||
if(TPLBuffer)
|
||||
free(TPLBuffer);
|
||||
|
||||
Texture.clear();
|
||||
TextureHeader.clear();
|
||||
TplTextureBuffer.clear();
|
||||
Texture.clear();
|
||||
TextureHeader.clear();
|
||||
TplTextureBuffer.clear();
|
||||
}
|
||||
|
||||
bool TplImage::LoadImage(const u8 * imgBuffer, u32 imgSize)
|
||||
{
|
||||
if(TPLBuffer)
|
||||
free(TPLBuffer);
|
||||
if(TPLBuffer)
|
||||
free(TPLBuffer);
|
||||
|
||||
TPLBuffer = NULL;
|
||||
TPLSize = 0;
|
||||
TPLBuffer = NULL;
|
||||
TPLSize = 0;
|
||||
|
||||
if(!imgBuffer)
|
||||
return false;
|
||||
if(!imgBuffer)
|
||||
return false;
|
||||
|
||||
TPLBuffer = (u8 *) malloc(imgSize);
|
||||
if(!TPLBuffer)
|
||||
return false;
|
||||
TPLBuffer = (u8 *) malloc(imgSize);
|
||||
if(!TPLBuffer)
|
||||
return false;
|
||||
|
||||
TPLSize = imgSize;
|
||||
TPLSize = imgSize;
|
||||
|
||||
memcpy(TPLBuffer, imgBuffer, imgSize);
|
||||
memcpy(TPLBuffer, imgBuffer, imgSize);
|
||||
|
||||
return ParseTplFile();
|
||||
return ParseTplFile();
|
||||
}
|
||||
|
||||
bool TplImage::ParseTplFile()
|
||||
{
|
||||
if(!TPLBuffer)
|
||||
return false;
|
||||
if(!TPLBuffer)
|
||||
return false;
|
||||
|
||||
TPLHeader = (const TPL_Header *) TPLBuffer;
|
||||
TPLHeader = (const TPL_Header *) TPLBuffer;
|
||||
|
||||
if(TPLHeader->magic != 0x0020AF30)
|
||||
return false;
|
||||
if(TPLHeader->magic != 0x0020AF30)
|
||||
return false;
|
||||
|
||||
if(TPLHeader->head_size != 12)
|
||||
return false;
|
||||
if(TPLHeader->head_size != 12)
|
||||
return false;
|
||||
|
||||
const TPL_Texture * curTexture = (const TPL_Texture *) (TPLHeader+1);
|
||||
const TPL_Texture * curTexture = (const TPL_Texture *) (TPLHeader+1);
|
||||
|
||||
for(u32 i = 0; i < TPLHeader->num_textures; i++)
|
||||
{
|
||||
Texture.resize(i+1);
|
||||
TextureHeader.resize(i+1);
|
||||
TplTextureBuffer.resize(i+1);
|
||||
for(u32 i = 0; i < TPLHeader->num_textures; i++)
|
||||
{
|
||||
Texture.resize(i+1);
|
||||
TextureHeader.resize(i+1);
|
||||
TplTextureBuffer.resize(i+1);
|
||||
|
||||
Texture[i] = curTexture;
|
||||
Texture[i] = curTexture;
|
||||
|
||||
TextureHeader[i] = (const TPL_Texture_Header *) ((const u8 *) TPLBuffer+Texture[i]->text_header_offset);
|
||||
TextureHeader[i] = (const TPL_Texture_Header *) ((const u8 *) TPLBuffer+Texture[i]->text_header_offset);
|
||||
|
||||
TplTextureBuffer[i] = TPLBuffer + TextureHeader[i]->offset;
|
||||
TplTextureBuffer[i] = TPLBuffer + TextureHeader[i]->offset;
|
||||
|
||||
curTexture++;
|
||||
}
|
||||
curTexture++;
|
||||
}
|
||||
|
||||
return true;
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
int TplImage::GetWidth(int pos)
|
||||
{
|
||||
if(pos < 0 || pos >= (int) Texture.size())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
if(pos < 0 || pos >= (int) Texture.size())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return TextureHeader[pos]->width;
|
||||
return TextureHeader[pos]->width;
|
||||
}
|
||||
|
||||
int TplImage::GetHeight(int pos)
|
||||
{
|
||||
if(pos < 0 || pos >= (int) TextureHeader.size())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
if(pos < 0 || pos >= (int) TextureHeader.size())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return TextureHeader[pos]->height;
|
||||
return TextureHeader[pos]->height;
|
||||
}
|
||||
|
||||
u32 TplImage::GetFormat(int pos)
|
||||
{
|
||||
if(pos < 0 || pos >= (int) TextureHeader.size())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
if(pos < 0 || pos >= (int) TextureHeader.size())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return TextureHeader[pos]->format;
|
||||
return TextureHeader[pos]->format;
|
||||
}
|
||||
|
||||
const u8 * TplImage::GetTextureBuffer(int pos)
|
||||
{
|
||||
if(pos < 0 || pos >= (int) TplTextureBuffer.size())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
if(pos < 0 || pos >= (int) TplTextureBuffer.size())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return TplTextureBuffer[pos];
|
||||
return TplTextureBuffer[pos];
|
||||
}
|
||||
|
||||
int TplImage::GetTextureSize(int pos)
|
||||
{
|
||||
int width = GetWidth(pos);
|
||||
int height = GetHeight(pos);
|
||||
int len = 0;
|
||||
int width = GetWidth(pos);
|
||||
int height = GetHeight(pos);
|
||||
int len = 0;
|
||||
|
||||
switch(GetFormat(pos))
|
||||
{
|
||||
case GX_TF_I4:
|
||||
case GX_TF_CI4:
|
||||
case GX_TF_CMPR:
|
||||
len = ((width+7)>>3)*((height+7)>>3)*32;
|
||||
break;
|
||||
case GX_TF_I8:
|
||||
case GX_TF_IA4:
|
||||
case GX_TF_CI8:
|
||||
len = ((width+7)>>3)*((height+7)>>2)*32;
|
||||
break;
|
||||
case GX_TF_IA8:
|
||||
case GX_TF_CI14:
|
||||
case GX_TF_RGB565:
|
||||
case GX_TF_RGB5A3:
|
||||
len = ((width+3)>>2)*((height+3)>>2)*32;
|
||||
break;
|
||||
case GX_TF_RGBA8:
|
||||
len = ((width+3)>>2)*((height+3)>>2)*32*2;
|
||||
break;
|
||||
default:
|
||||
len = ((width+3)>>2)*((height+3)>>2)*32*2;
|
||||
break;
|
||||
}
|
||||
switch(GetFormat(pos))
|
||||
{
|
||||
case GX_TF_I4:
|
||||
case GX_TF_CI4:
|
||||
case GX_TF_CMPR:
|
||||
len = ((width+7)>>3)*((height+7)>>3)*32;
|
||||
break;
|
||||
case GX_TF_I8:
|
||||
case GX_TF_IA4:
|
||||
case GX_TF_CI8:
|
||||
len = ((width+7)>>3)*((height+7)>>2)*32;
|
||||
break;
|
||||
case GX_TF_IA8:
|
||||
case GX_TF_CI14:
|
||||
case GX_TF_RGB565:
|
||||
case GX_TF_RGB5A3:
|
||||
len = ((width+3)>>2)*((height+3)>>2)*32;
|
||||
break;
|
||||
case GX_TF_RGBA8:
|
||||
len = ((width+3)>>2)*((height+3)>>2)*32*2;
|
||||
break;
|
||||
default:
|
||||
len = ((width+3)>>2)*((height+3)>>2)*32*2;
|
||||
break;
|
||||
}
|
||||
|
||||
return len;
|
||||
return len;
|
||||
}
|
||||
|
||||
gdImagePtr TplImage::ConvertToGD(int pos)
|
||||
{
|
||||
if(pos < 0 || pos >= (int) Texture.size())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
if(pos < 0 || pos >= (int) Texture.size())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
gdImagePtr gdImg = 0;
|
||||
gdImagePtr gdImg = 0;
|
||||
|
||||
switch(TextureHeader[pos]->format)
|
||||
{
|
||||
case GX_TF_RGB565:
|
||||
RGB565ToGD(TplTextureBuffer[pos], TextureHeader[pos]->width, TextureHeader[pos]->height, &gdImg);
|
||||
break;
|
||||
case GX_TF_RGB5A3:
|
||||
RGB565A3ToGD(TplTextureBuffer[pos], TextureHeader[pos]->width, TextureHeader[pos]->height, &gdImg);
|
||||
break;
|
||||
case GX_TF_RGBA8:
|
||||
RGBA8ToGD(TplTextureBuffer[pos], TextureHeader[pos]->width, TextureHeader[pos]->height, &gdImg);
|
||||
break;
|
||||
case GX_TF_I4:
|
||||
I4ToGD(TplTextureBuffer[pos], TextureHeader[pos]->width, TextureHeader[pos]->height, &gdImg);
|
||||
break;
|
||||
case GX_TF_I8:
|
||||
I8ToGD(TplTextureBuffer[pos], TextureHeader[pos]->width, TextureHeader[pos]->height, &gdImg);
|
||||
break;
|
||||
case GX_TF_IA4:
|
||||
IA4ToGD(TplTextureBuffer[pos], TextureHeader[pos]->width, TextureHeader[pos]->height, &gdImg);
|
||||
break;
|
||||
case GX_TF_IA8:
|
||||
IA8ToGD(TplTextureBuffer[pos], TextureHeader[pos]->width, TextureHeader[pos]->height, &gdImg);
|
||||
break;
|
||||
case GX_TF_CMPR:
|
||||
CMPToGD(TplTextureBuffer[pos], TextureHeader[pos]->width, TextureHeader[pos]->height, &gdImg);
|
||||
break;
|
||||
default:
|
||||
gdImg = 0;
|
||||
break;
|
||||
}
|
||||
switch(TextureHeader[pos]->format)
|
||||
{
|
||||
case GX_TF_RGB565:
|
||||
RGB565ToGD(TplTextureBuffer[pos], TextureHeader[pos]->width, TextureHeader[pos]->height, &gdImg);
|
||||
break;
|
||||
case GX_TF_RGB5A3:
|
||||
RGB565A3ToGD(TplTextureBuffer[pos], TextureHeader[pos]->width, TextureHeader[pos]->height, &gdImg);
|
||||
break;
|
||||
case GX_TF_RGBA8:
|
||||
RGBA8ToGD(TplTextureBuffer[pos], TextureHeader[pos]->width, TextureHeader[pos]->height, &gdImg);
|
||||
break;
|
||||
case GX_TF_I4:
|
||||
I4ToGD(TplTextureBuffer[pos], TextureHeader[pos]->width, TextureHeader[pos]->height, &gdImg);
|
||||
break;
|
||||
case GX_TF_I8:
|
||||
I8ToGD(TplTextureBuffer[pos], TextureHeader[pos]->width, TextureHeader[pos]->height, &gdImg);
|
||||
break;
|
||||
case GX_TF_IA4:
|
||||
IA4ToGD(TplTextureBuffer[pos], TextureHeader[pos]->width, TextureHeader[pos]->height, &gdImg);
|
||||
break;
|
||||
case GX_TF_IA8:
|
||||
IA8ToGD(TplTextureBuffer[pos], TextureHeader[pos]->width, TextureHeader[pos]->height, &gdImg);
|
||||
break;
|
||||
case GX_TF_CMPR:
|
||||
CMPToGD(TplTextureBuffer[pos], TextureHeader[pos]->width, TextureHeader[pos]->height, &gdImg);
|
||||
break;
|
||||
default:
|
||||
gdImg = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
return gdImg;
|
||||
return gdImg;
|
||||
}
|
||||
|
|
|
@ -34,15 +34,15 @@
|
|||
|
||||
typedef struct
|
||||
{
|
||||
u32 magic;
|
||||
u32 num_textures;
|
||||
u32 head_size;
|
||||
u32 magic;
|
||||
u32 num_textures;
|
||||
u32 head_size;
|
||||
} TPL_Header;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
u32 text_header_offset;
|
||||
u32 text_palette_offset;
|
||||
u32 text_header_offset;
|
||||
u32 text_palette_offset;
|
||||
} TPL_Texture;
|
||||
|
||||
typedef struct
|
||||
|
@ -73,26 +73,26 @@ typedef struct
|
|||
|
||||
class TplImage
|
||||
{
|
||||
public:
|
||||
TplImage(const char * filepath);
|
||||
TplImage(const u8 * imgBuffer, u32 imgSize);
|
||||
~TplImage();
|
||||
bool LoadImage(const u8 * imgBuffer, u32 imgSize);
|
||||
int GetWidth(int Texture);
|
||||
int GetHeight(int Texture);
|
||||
u32 GetFormat(int Texture);
|
||||
const u8 * GetTextureBuffer(int Texture);
|
||||
int GetTextureSize(int Texture);
|
||||
gdImagePtr ConvertToGD(int Texture);
|
||||
private:
|
||||
bool ParseTplFile();
|
||||
public:
|
||||
TplImage(const char * filepath);
|
||||
TplImage(const u8 * imgBuffer, u32 imgSize);
|
||||
~TplImage();
|
||||
bool LoadImage(const u8 * imgBuffer, u32 imgSize);
|
||||
int GetWidth(int Texture);
|
||||
int GetHeight(int Texture);
|
||||
u32 GetFormat(int Texture);
|
||||
const u8 * GetTextureBuffer(int Texture);
|
||||
int GetTextureSize(int Texture);
|
||||
gdImagePtr ConvertToGD(int Texture);
|
||||
private:
|
||||
bool ParseTplFile();
|
||||
|
||||
u8 * TPLBuffer;
|
||||
u32 TPLSize;
|
||||
const TPL_Header * TPLHeader;
|
||||
std::vector<const TPL_Texture *> Texture;
|
||||
std::vector<const TPL_Texture_Header *> TextureHeader;
|
||||
std::vector<const u8 *> TplTextureBuffer;
|
||||
u8 * TPLBuffer;
|
||||
u32 TPLSize;
|
||||
const TPL_Header * TPLHeader;
|
||||
std::vector<const TPL_Texture *> Texture;
|
||||
std::vector<const TPL_Texture_Header *> TextureHeader;
|
||||
std::vector<const u8 *> TplTextureBuffer;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -51,64 +51,64 @@ typedef struct
|
|||
# define HUGE_VAL HUGE
|
||||
#endif
|
||||
|
||||
# define UnsignedToFloat(u) (((double)((long)(u - 2147483647L - 1))) + 2147483648.0)
|
||||
# define UnsignedToFloat(u) (((double)((long)(u - 2147483647L - 1))) + 2147483648.0)
|
||||
|
||||
static double ConvertFromIeeeExtended(const unsigned char* bytes)
|
||||
{
|
||||
double f;
|
||||
int expon;
|
||||
unsigned long hiMant, loMant;
|
||||
double f;
|
||||
int expon;
|
||||
unsigned long hiMant, loMant;
|
||||
|
||||
expon = ((bytes[0] & 0x7F) << 8) | (bytes[1] & 0xFF);
|
||||
hiMant = ((unsigned long)(bytes[2] & 0xFF) << 24)
|
||||
| ((unsigned long)(bytes[3] & 0xFF) << 16)
|
||||
| ((unsigned long)(bytes[4] & 0xFF) << 8)
|
||||
| ((unsigned long)(bytes[5] & 0xFF));
|
||||
loMant = ((unsigned long)(bytes[6] & 0xFF) << 24)
|
||||
| ((unsigned long)(bytes[7] & 0xFF) << 16)
|
||||
| ((unsigned long)(bytes[8] & 0xFF) << 8)
|
||||
| ((unsigned long)(bytes[9] & 0xFF));
|
||||
expon = ((bytes[0] & 0x7F) << 8) | (bytes[1] & 0xFF);
|
||||
hiMant = ((unsigned long)(bytes[2] & 0xFF) << 24)
|
||||
| ((unsigned long)(bytes[3] & 0xFF) << 16)
|
||||
| ((unsigned long)(bytes[4] & 0xFF) << 8)
|
||||
| ((unsigned long)(bytes[5] & 0xFF));
|
||||
loMant = ((unsigned long)(bytes[6] & 0xFF) << 24)
|
||||
| ((unsigned long)(bytes[7] & 0xFF) << 16)
|
||||
| ((unsigned long)(bytes[8] & 0xFF) << 8)
|
||||
| ((unsigned long)(bytes[9] & 0xFF));
|
||||
|
||||
if (expon == 0 && hiMant == 0 && loMant == 0) {
|
||||
f = 0;
|
||||
}
|
||||
else {
|
||||
if (expon == 0x7FFF) {
|
||||
f = HUGE_VAL;
|
||||
}
|
||||
else {
|
||||
expon -= 16383;
|
||||
f = ldexp(UnsignedToFloat(hiMant), expon-=31);
|
||||
f += ldexp(UnsignedToFloat(loMant), expon-=32);
|
||||
}
|
||||
}
|
||||
if (expon == 0 && hiMant == 0 && loMant == 0) {
|
||||
f = 0;
|
||||
}
|
||||
else {
|
||||
if (expon == 0x7FFF) {
|
||||
f = HUGE_VAL;
|
||||
}
|
||||
else {
|
||||
expon -= 16383;
|
||||
f = ldexp(UnsignedToFloat(hiMant), expon-=31);
|
||||
f += ldexp(UnsignedToFloat(loMant), expon-=32);
|
||||
}
|
||||
}
|
||||
|
||||
if (bytes[0] & 0x80)
|
||||
return -f;
|
||||
else
|
||||
return f;
|
||||
if (bytes[0] & 0x80)
|
||||
return -f;
|
||||
else
|
||||
return f;
|
||||
}
|
||||
|
||||
AifDecoder::AifDecoder(const char * filepath)
|
||||
: SoundDecoder(filepath)
|
||||
: SoundDecoder(filepath)
|
||||
{
|
||||
SoundType = SOUND_AIF;
|
||||
SoundType = SOUND_AIF;
|
||||
|
||||
if(!file_fd)
|
||||
return;
|
||||
if(!file_fd)
|
||||
return;
|
||||
|
||||
OpenFile();
|
||||
OpenFile();
|
||||
}
|
||||
|
||||
AifDecoder::AifDecoder(const u8 * snd, int len)
|
||||
: SoundDecoder(snd, len)
|
||||
: SoundDecoder(snd, len)
|
||||
{
|
||||
SoundType = SOUND_AIF;
|
||||
SoundType = SOUND_AIF;
|
||||
|
||||
if(!file_fd)
|
||||
return;
|
||||
if(!file_fd)
|
||||
return;
|
||||
|
||||
OpenFile();
|
||||
OpenFile();
|
||||
}
|
||||
|
||||
AifDecoder::~AifDecoder()
|
||||
|
@ -117,8 +117,8 @@ AifDecoder::~AifDecoder()
|
|||
|
||||
void AifDecoder::OpenFile()
|
||||
{
|
||||
SWaveHdr Header;
|
||||
file_fd->read((u8 *) &Header, sizeof(SWaveHdr));
|
||||
SWaveHdr Header;
|
||||
file_fd->read((u8 *) &Header, sizeof(SWaveHdr));
|
||||
|
||||
if (Header.magicRIFF != 'FORM')
|
||||
{
|
||||
|
@ -134,20 +134,20 @@ void AifDecoder::OpenFile()
|
|||
SWaveChunk WaveChunk;
|
||||
do
|
||||
{
|
||||
int ret = file_fd->read((u8 *) &WaveChunk, sizeof(SWaveChunk));
|
||||
if(ret <= 0)
|
||||
{
|
||||
CloseFile();
|
||||
return;
|
||||
}
|
||||
int ret = file_fd->read((u8 *) &WaveChunk, sizeof(SWaveChunk));
|
||||
if(ret <= 0)
|
||||
{
|
||||
CloseFile();
|
||||
return;
|
||||
}
|
||||
}
|
||||
while(WaveChunk.magicDATA != 'COMM');
|
||||
|
||||
DataOffset = file_fd->tell()+WaveChunk.size;
|
||||
DataOffset = file_fd->tell()+WaveChunk.size;
|
||||
|
||||
SAIFFCommChunk CommHdr;
|
||||
file_fd->seek(file_fd->tell()-sizeof(SWaveChunk), SEEK_SET);
|
||||
file_fd->read((u8 *) &CommHdr, sizeof(SAIFFCommChunk));
|
||||
SAIFFCommChunk CommHdr;
|
||||
file_fd->seek(file_fd->tell()-sizeof(SWaveChunk), SEEK_SET);
|
||||
file_fd->read((u8 *) &CommHdr, sizeof(SAIFFCommChunk));
|
||||
|
||||
if(CommHdr.fccCOMM != 'COMM')
|
||||
{
|
||||
|
@ -155,12 +155,12 @@ void AifDecoder::OpenFile()
|
|||
return;
|
||||
}
|
||||
|
||||
file_fd->seek(DataOffset, SEEK_SET);
|
||||
file_fd->seek(DataOffset, SEEK_SET);
|
||||
|
||||
SAIFFSSndChunk SSndChunk;
|
||||
file_fd->read((u8 *) &SSndChunk, sizeof(SAIFFSSndChunk));
|
||||
SAIFFSSndChunk SSndChunk;
|
||||
file_fd->read((u8 *) &SSndChunk, sizeof(SAIFFSSndChunk));
|
||||
|
||||
if(SSndChunk.fccSSND != 'SSND')
|
||||
if(SSndChunk.fccSSND != 'SSND')
|
||||
{
|
||||
CloseFile();
|
||||
return;
|
||||
|
@ -169,7 +169,7 @@ void AifDecoder::OpenFile()
|
|||
DataOffset += sizeof(SAIFFSSndChunk);
|
||||
DataSize = SSndChunk.size-8;
|
||||
SampleRate = (u32) ConvertFromIeeeExtended(CommHdr.freq);
|
||||
Format = VOICE_STEREO_16BIT;
|
||||
Format = VOICE_STEREO_16BIT;
|
||||
|
||||
if(CommHdr.channels == 1 && CommHdr.bps == 8)
|
||||
Format = VOICE_MONO_8BIT;
|
||||
|
@ -180,35 +180,35 @@ void AifDecoder::OpenFile()
|
|||
else if (CommHdr.channels == 2 && CommHdr.bps == 16)
|
||||
Format = VOICE_STEREO_16BIT;
|
||||
|
||||
Decode();
|
||||
Decode();
|
||||
}
|
||||
|
||||
void AifDecoder::CloseFile()
|
||||
{
|
||||
if(file_fd)
|
||||
delete file_fd;
|
||||
if(file_fd)
|
||||
delete file_fd;
|
||||
|
||||
file_fd = NULL;
|
||||
file_fd = NULL;
|
||||
}
|
||||
|
||||
int AifDecoder::Read(u8 * buffer, int buffer_size, int pos)
|
||||
{
|
||||
if(!file_fd)
|
||||
return -1;
|
||||
if(!file_fd)
|
||||
return -1;
|
||||
|
||||
if(CurPos >= (int) DataSize)
|
||||
return 0;
|
||||
if(CurPos >= (int) DataSize)
|
||||
return 0;
|
||||
|
||||
file_fd->seek(DataOffset+CurPos, SEEK_SET);
|
||||
file_fd->seek(DataOffset+CurPos, SEEK_SET);
|
||||
|
||||
if(buffer_size > (int) DataSize-CurPos)
|
||||
buffer_size = DataSize-CurPos;
|
||||
if(buffer_size > (int) DataSize-CurPos)
|
||||
buffer_size = DataSize-CurPos;
|
||||
|
||||
int read = file_fd->read(buffer, buffer_size);
|
||||
if(read > 0)
|
||||
{
|
||||
CurPos += read;
|
||||
}
|
||||
int read = file_fd->read(buffer, buffer_size);
|
||||
if(read > 0)
|
||||
{
|
||||
CurPos += read;
|
||||
}
|
||||
|
||||
return read;
|
||||
return read;
|
||||
}
|
||||
|
|
|
@ -31,20 +31,20 @@
|
|||
|
||||
class AifDecoder : public SoundDecoder
|
||||
{
|
||||
public:
|
||||
AifDecoder(const char * filepath);
|
||||
AifDecoder(const u8 * snd, int len);
|
||||
virtual ~AifDecoder();
|
||||
int GetFormat() { return Format; };
|
||||
int GetSampleRate() { return SampleRate; };
|
||||
int Read(u8 * buffer, int buffer_size, int pos);
|
||||
protected:
|
||||
void OpenFile();
|
||||
void CloseFile();
|
||||
u32 DataOffset;
|
||||
u32 DataSize;
|
||||
u32 SampleRate;
|
||||
u8 Format;
|
||||
public:
|
||||
AifDecoder(const char * filepath);
|
||||
AifDecoder(const u8 * snd, int len);
|
||||
virtual ~AifDecoder();
|
||||
int GetFormat() { return Format; };
|
||||
int GetSampleRate() { return SampleRate; };
|
||||
int Read(u8 * buffer, int buffer_size, int pos);
|
||||
protected:
|
||||
void OpenFile();
|
||||
void CloseFile();
|
||||
u32 DataOffset;
|
||||
u32 DataSize;
|
||||
u32 SampleRate;
|
||||
u8 Format;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -32,112 +32,112 @@
|
|||
SoundBlock DecodefromBNS(const u8 *buffer, u32 size);
|
||||
|
||||
BNSDecoder::BNSDecoder(const char * filepath)
|
||||
: SoundDecoder(filepath)
|
||||
: SoundDecoder(filepath)
|
||||
{
|
||||
SoundType = SOUND_BNS;
|
||||
memset(&SoundData, 0, sizeof(SoundBlock));
|
||||
SoundType = SOUND_BNS;
|
||||
memset(&SoundData, 0, sizeof(SoundBlock));
|
||||
|
||||
if(!file_fd)
|
||||
return;
|
||||
if(!file_fd)
|
||||
return;
|
||||
|
||||
OpenFile();
|
||||
OpenFile();
|
||||
}
|
||||
|
||||
BNSDecoder::BNSDecoder(const u8 * snd, int len)
|
||||
: SoundDecoder(snd, len)
|
||||
: SoundDecoder(snd, len)
|
||||
{
|
||||
SoundType = SOUND_BNS;
|
||||
memset(&SoundData, 0, sizeof(SoundBlock));
|
||||
SoundType = SOUND_BNS;
|
||||
memset(&SoundData, 0, sizeof(SoundBlock));
|
||||
|
||||
if(!file_fd)
|
||||
return;
|
||||
if(!file_fd)
|
||||
return;
|
||||
|
||||
OpenFile();
|
||||
OpenFile();
|
||||
}
|
||||
|
||||
BNSDecoder::~BNSDecoder()
|
||||
{
|
||||
ExitRequested = true;
|
||||
while(Decoding)
|
||||
usleep(100);
|
||||
ExitRequested = true;
|
||||
while(Decoding)
|
||||
usleep(100);
|
||||
|
||||
if(SoundData.buffer != NULL)
|
||||
free(SoundData.buffer);
|
||||
if(SoundData.buffer != NULL)
|
||||
free(SoundData.buffer);
|
||||
|
||||
SoundData.buffer = NULL;
|
||||
SoundData.buffer = NULL;
|
||||
}
|
||||
|
||||
void BNSDecoder::OpenFile()
|
||||
{
|
||||
u8 * tempbuff = new (std::nothrow) u8[file_fd->size()];
|
||||
if(!tempbuff)
|
||||
{
|
||||
CloseFile();
|
||||
return;
|
||||
}
|
||||
u8 * tempbuff = new (std::nothrow) u8[file_fd->size()];
|
||||
if(!tempbuff)
|
||||
{
|
||||
CloseFile();
|
||||
return;
|
||||
}
|
||||
|
||||
int done = 0;
|
||||
int done = 0;
|
||||
|
||||
while(done < file_fd->size())
|
||||
{
|
||||
int read = file_fd->read(tempbuff, file_fd->size());
|
||||
if(read > 0)
|
||||
done += read;
|
||||
else
|
||||
{
|
||||
CloseFile();
|
||||
return;
|
||||
}
|
||||
}
|
||||
while(done < file_fd->size())
|
||||
{
|
||||
int read = file_fd->read(tempbuff, file_fd->size());
|
||||
if(read > 0)
|
||||
done += read;
|
||||
else
|
||||
{
|
||||
CloseFile();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
SoundData = DecodefromBNS(tempbuff, done);
|
||||
if(SoundData.buffer == NULL)
|
||||
{
|
||||
CloseFile();
|
||||
return;
|
||||
}
|
||||
SoundData = DecodefromBNS(tempbuff, done);
|
||||
if(SoundData.buffer == NULL)
|
||||
{
|
||||
CloseFile();
|
||||
return;
|
||||
}
|
||||
|
||||
delete [] tempbuff;
|
||||
tempbuff = NULL;
|
||||
delete [] tempbuff;
|
||||
tempbuff = NULL;
|
||||
|
||||
Decode();
|
||||
Decode();
|
||||
}
|
||||
|
||||
void BNSDecoder::CloseFile()
|
||||
{
|
||||
if(file_fd)
|
||||
delete file_fd;
|
||||
if(file_fd)
|
||||
delete file_fd;
|
||||
|
||||
file_fd = NULL;
|
||||
file_fd = NULL;
|
||||
}
|
||||
|
||||
int BNSDecoder::Read(u8 * buffer, int buffer_size, int pos)
|
||||
{
|
||||
if(!SoundData.buffer)
|
||||
return -1;
|
||||
if(!SoundData.buffer)
|
||||
return -1;
|
||||
|
||||
if(SoundData.loopFlag)
|
||||
{
|
||||
int factor = SoundData.format == VOICE_STEREO_16BIT ? 4 : 2;
|
||||
if(CurPos >= (int) SoundData.loopEnd*factor)
|
||||
CurPos = SoundData.loopStart*factor;
|
||||
if(SoundData.loopFlag)
|
||||
{
|
||||
int factor = SoundData.format == VOICE_STEREO_16BIT ? 4 : 2;
|
||||
if(CurPos >= (int) SoundData.loopEnd*factor)
|
||||
CurPos = SoundData.loopStart*factor;
|
||||
|
||||
if(buffer_size > (int) SoundData.loopEnd*factor-CurPos)
|
||||
buffer_size = SoundData.loopEnd*factor-CurPos;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(CurPos >= (int) SoundData.size)
|
||||
return 0;
|
||||
if(buffer_size > (int) SoundData.loopEnd*factor-CurPos)
|
||||
buffer_size = SoundData.loopEnd*factor-CurPos;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(CurPos >= (int) SoundData.size)
|
||||
return 0;
|
||||
|
||||
if(buffer_size > (int) SoundData.size-CurPos)
|
||||
buffer_size = SoundData.size-CurPos;
|
||||
}
|
||||
if(buffer_size > (int) SoundData.size-CurPos)
|
||||
buffer_size = SoundData.size-CurPos;
|
||||
}
|
||||
|
||||
memcpy(buffer, SoundData.buffer+CurPos, buffer_size);
|
||||
CurPos += buffer_size;
|
||||
memcpy(buffer, SoundData.buffer+CurPos, buffer_size);
|
||||
CurPos += buffer_size;
|
||||
|
||||
return buffer_size;
|
||||
return buffer_size;
|
||||
}
|
||||
|
||||
struct BNSHeader
|
||||
|
@ -309,8 +309,8 @@ static u8 * decodeBNS(u32 &size, const BNSInfo &bnsInfo, const BNSData &bnsData)
|
|||
|
||||
SoundBlock DecodefromBNS(const u8 *buffer, u32 size)
|
||||
{
|
||||
SoundBlock OutBlock;
|
||||
memset(&OutBlock, 0, sizeof(SoundBlock));
|
||||
SoundBlock OutBlock;
|
||||
memset(&OutBlock, 0, sizeof(SoundBlock));
|
||||
|
||||
const BNSHeader &hdr = *(BNSHeader *)buffer;
|
||||
if (size < sizeof hdr)
|
||||
|
|
|
@ -41,17 +41,17 @@ typedef struct _SoundBlock
|
|||
|
||||
class BNSDecoder : public SoundDecoder
|
||||
{
|
||||
public:
|
||||
BNSDecoder(const char * filepath);
|
||||
BNSDecoder(const u8 * snd, int len);
|
||||
virtual ~BNSDecoder();
|
||||
int GetFormat() { return SoundData.format; };
|
||||
int GetSampleRate() { return SoundData.frequency; };
|
||||
int Read(u8 * buffer, int buffer_size, int pos);
|
||||
protected:
|
||||
void OpenFile();
|
||||
void CloseFile();
|
||||
SoundBlock SoundData;
|
||||
public:
|
||||
BNSDecoder(const char * filepath);
|
||||
BNSDecoder(const u8 * snd, int len);
|
||||
virtual ~BNSDecoder();
|
||||
int GetFormat() { return SoundData.format; };
|
||||
int GetSampleRate() { return SoundData.frequency; };
|
||||
int Read(u8 * buffer, int buffer_size, int pos);
|
||||
protected:
|
||||
void OpenFile();
|
||||
void CloseFile();
|
||||
SoundBlock SoundData;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -30,115 +30,115 @@
|
|||
|
||||
BufferCircle::BufferCircle()
|
||||
{
|
||||
which = 0;
|
||||
BufferBlockSize = 0;
|
||||
which = 0;
|
||||
BufferBlockSize = 0;
|
||||
}
|
||||
|
||||
BufferCircle::~BufferCircle()
|
||||
{
|
||||
FreeBuffer();
|
||||
SoundBuffer.clear();
|
||||
BufferSize.clear();
|
||||
BufferReady.clear();
|
||||
FreeBuffer();
|
||||
SoundBuffer.clear();
|
||||
BufferSize.clear();
|
||||
BufferReady.clear();
|
||||
}
|
||||
|
||||
void BufferCircle::SetBufferBlockSize(int size)
|
||||
{
|
||||
if(size < 0)
|
||||
return;
|
||||
if(size < 0)
|
||||
return;
|
||||
|
||||
BufferBlockSize = size;
|
||||
BufferBlockSize = size;
|
||||
|
||||
for(int i = 0; i < Size(); i++)
|
||||
{
|
||||
if(SoundBuffer[i] != NULL)
|
||||
free(SoundBuffer[i]);
|
||||
for(int i = 0; i < Size(); i++)
|
||||
{
|
||||
if(SoundBuffer[i] != NULL)
|
||||
free(SoundBuffer[i]);
|
||||
|
||||
SoundBuffer[i] = (u8 *) memalign(32, ALIGN32(BufferBlockSize));
|
||||
BufferSize[i] = 0;
|
||||
BufferReady[i] = false;
|
||||
}
|
||||
SoundBuffer[i] = (u8 *) memalign(32, ALIGN32(BufferBlockSize));
|
||||
BufferSize[i] = 0;
|
||||
BufferReady[i] = false;
|
||||
}
|
||||
}
|
||||
|
||||
void BufferCircle::Resize(int size)
|
||||
{
|
||||
while(size < Size())
|
||||
RemoveBuffer(Size()-1);
|
||||
while(size < Size())
|
||||
RemoveBuffer(Size()-1);
|
||||
|
||||
int oldSize = Size();
|
||||
int oldSize = Size();
|
||||
|
||||
SoundBuffer.resize(size);
|
||||
BufferSize.resize(size);
|
||||
BufferReady.resize(size);
|
||||
SoundBuffer.resize(size);
|
||||
BufferSize.resize(size);
|
||||
BufferReady.resize(size);
|
||||
|
||||
for(int i = oldSize; i < Size(); i++)
|
||||
{
|
||||
if(BufferBlockSize > 0)
|
||||
SoundBuffer[i] = (u8 *) memalign(32, ALIGN32(BufferBlockSize));
|
||||
else
|
||||
SoundBuffer[i] = NULL;
|
||||
BufferSize[i] = 0;
|
||||
BufferReady[i] = false;
|
||||
}
|
||||
for(int i = oldSize; i < Size(); i++)
|
||||
{
|
||||
if(BufferBlockSize > 0)
|
||||
SoundBuffer[i] = (u8 *) memalign(32, ALIGN32(BufferBlockSize));
|
||||
else
|
||||
SoundBuffer[i] = NULL;
|
||||
BufferSize[i] = 0;
|
||||
BufferReady[i] = false;
|
||||
}
|
||||
}
|
||||
|
||||
void BufferCircle::RemoveBuffer(int pos)
|
||||
{
|
||||
if(!Valid(pos))
|
||||
return;
|
||||
if(!Valid(pos))
|
||||
return;
|
||||
|
||||
if(SoundBuffer[pos] != NULL)
|
||||
free(SoundBuffer[pos]);
|
||||
if(SoundBuffer[pos] != NULL)
|
||||
free(SoundBuffer[pos]);
|
||||
|
||||
SoundBuffer.erase(SoundBuffer.begin()+pos);
|
||||
BufferSize.erase(BufferSize.begin()+pos);
|
||||
BufferReady.erase(BufferReady.begin()+pos);
|
||||
SoundBuffer.erase(SoundBuffer.begin()+pos);
|
||||
BufferSize.erase(BufferSize.begin()+pos);
|
||||
BufferReady.erase(BufferReady.begin()+pos);
|
||||
}
|
||||
|
||||
void BufferCircle::ClearBuffer()
|
||||
{
|
||||
for(int i = 0; i < Size(); i++)
|
||||
{
|
||||
BufferSize[i] = 0;
|
||||
BufferReady[i] = false;
|
||||
}
|
||||
which = 0;
|
||||
for(int i = 0; i < Size(); i++)
|
||||
{
|
||||
BufferSize[i] = 0;
|
||||
BufferReady[i] = false;
|
||||
}
|
||||
which = 0;
|
||||
}
|
||||
|
||||
void BufferCircle::FreeBuffer()
|
||||
{
|
||||
for(int i = 0; i < Size(); i++)
|
||||
{
|
||||
if(SoundBuffer[i] != NULL)
|
||||
free(SoundBuffer[i]);
|
||||
for(int i = 0; i < Size(); i++)
|
||||
{
|
||||
if(SoundBuffer[i] != NULL)
|
||||
free(SoundBuffer[i]);
|
||||
|
||||
SoundBuffer[i] = NULL;
|
||||
BufferSize[i] = 0;
|
||||
BufferReady[i] = false;
|
||||
}
|
||||
SoundBuffer[i] = NULL;
|
||||
BufferSize[i] = 0;
|
||||
BufferReady[i] = false;
|
||||
}
|
||||
}
|
||||
|
||||
void BufferCircle::LoadNext()
|
||||
{
|
||||
int pos = (which+Size()-1) % Size();
|
||||
BufferReady[pos] = false;
|
||||
BufferSize[pos] = 0;
|
||||
int pos = (which+Size()-1) % Size();
|
||||
BufferReady[pos] = false;
|
||||
BufferSize[pos] = 0;
|
||||
|
||||
which = (which+1) % Size();
|
||||
which = (which+1) % Size();
|
||||
}
|
||||
|
||||
void BufferCircle::SetBufferReady(int pos, bool state)
|
||||
{
|
||||
if(!Valid(pos))
|
||||
return;
|
||||
if(!Valid(pos))
|
||||
return;
|
||||
|
||||
BufferReady[pos] = state;
|
||||
BufferReady[pos] = state;
|
||||
}
|
||||
|
||||
void BufferCircle::SetBufferSize(int pos, int size)
|
||||
{
|
||||
if(!Valid(pos))
|
||||
return;
|
||||
if(!Valid(pos))
|
||||
return;
|
||||
|
||||
BufferSize[pos] = size;
|
||||
BufferSize[pos] = size;
|
||||
}
|
||||
|
|
|
@ -31,62 +31,62 @@
|
|||
|
||||
class BufferCircle
|
||||
{
|
||||
public:
|
||||
//!> Constructor
|
||||
BufferCircle();
|
||||
//!> Destructor
|
||||
~BufferCircle();
|
||||
//!> Set circle size
|
||||
void Resize(int size);
|
||||
//!> Get the circle size
|
||||
int Size() { return SoundBuffer.size(); };
|
||||
//!> Set/resize the buffer size
|
||||
void SetBufferBlockSize(int size);
|
||||
//!> Remove a buffer
|
||||
void RemoveBuffer(int pos);
|
||||
//!> Set all buffers clear
|
||||
void ClearBuffer();
|
||||
//!> Free all buffers
|
||||
void FreeBuffer();
|
||||
//!> Switch to next buffer
|
||||
void LoadNext();
|
||||
//!> Get the current buffer
|
||||
u8 * GetBuffer() { if(!Valid(which)) return 0; return SoundBuffer[which]; };
|
||||
//!> Get a buffer at a position
|
||||
u8 * GetBuffer(int pos) { if(!Valid(pos)) return NULL; else return SoundBuffer[pos]; };
|
||||
//!> Get next buffer
|
||||
u8 * GetNextBuffer() { if(Size() <= 0) return 0; else return SoundBuffer[(which+1) % Size()]; };
|
||||
//!> Get previous buffer
|
||||
u8 * GetLastBuffer() { if(Size() <= 0) return 0; else return SoundBuffer[(which+Size()-1) % Size()]; };
|
||||
//!> Get current buffer size
|
||||
u32 GetBufferSize() { if(!Valid(which)) return 0; else return BufferSize[which]; };
|
||||
//!> Get buffer size at position
|
||||
u32 GetBufferSize(int pos) { if(!Valid(pos)) return 0; else return BufferSize[pos]; };
|
||||
//!> Get previous buffer size
|
||||
u32 GetLastBufferSize() { if(Size() <= 0) return 0; else return BufferSize[(which+Size()-1) % Size()]; };
|
||||
//!> Is current buffer ready
|
||||
bool IsBufferReady() { if(!Valid(which)) return false; else return BufferReady[which]; };
|
||||
//!> Is a buffer at a position ready
|
||||
bool IsBufferReady(int pos) { if(!Valid(pos)) return false; else return BufferReady[pos]; };
|
||||
//!> Is next buffer ready
|
||||
bool IsNextBufferReady() { if(Size() <= 0) return false; else return BufferReady[(which+1) % Size()]; };
|
||||
//!> Is last buffer ready
|
||||
bool IsLastBufferReady() { if(Size() <= 0) return false; else return BufferReady[(which+Size()-1) % Size()]; };
|
||||
//!> Set a buffer at a position to a ready state
|
||||
void SetBufferReady(int pos, bool st);
|
||||
//!> Set the buffersize at a position
|
||||
void SetBufferSize(int pos, int size);
|
||||
//!> Get the current position in the circle
|
||||
u16 Which() { return which; };
|
||||
protected:
|
||||
//!> Check if the position is a valid position in the vector
|
||||
bool Valid(int pos) { return !(pos < 0 || pos >= Size()); };
|
||||
public:
|
||||
//!> Constructor
|
||||
BufferCircle();
|
||||
//!> Destructor
|
||||
~BufferCircle();
|
||||
//!> Set circle size
|
||||
void Resize(int size);
|
||||
//!> Get the circle size
|
||||
int Size() { return SoundBuffer.size(); };
|
||||
//!> Set/resize the buffer size
|
||||
void SetBufferBlockSize(int size);
|
||||
//!> Remove a buffer
|
||||
void RemoveBuffer(int pos);
|
||||
//!> Set all buffers clear
|
||||
void ClearBuffer();
|
||||
//!> Free all buffers
|
||||
void FreeBuffer();
|
||||
//!> Switch to next buffer
|
||||
void LoadNext();
|
||||
//!> Get the current buffer
|
||||
u8 * GetBuffer() { if(!Valid(which)) return 0; return SoundBuffer[which]; };
|
||||
//!> Get a buffer at a position
|
||||
u8 * GetBuffer(int pos) { if(!Valid(pos)) return NULL; else return SoundBuffer[pos]; };
|
||||
//!> Get next buffer
|
||||
u8 * GetNextBuffer() { if(Size() <= 0) return 0; else return SoundBuffer[(which+1) % Size()]; };
|
||||
//!> Get previous buffer
|
||||
u8 * GetLastBuffer() { if(Size() <= 0) return 0; else return SoundBuffer[(which+Size()-1) % Size()]; };
|
||||
//!> Get current buffer size
|
||||
u32 GetBufferSize() { if(!Valid(which)) return 0; else return BufferSize[which]; };
|
||||
//!> Get buffer size at position
|
||||
u32 GetBufferSize(int pos) { if(!Valid(pos)) return 0; else return BufferSize[pos]; };
|
||||
//!> Get previous buffer size
|
||||
u32 GetLastBufferSize() { if(Size() <= 0) return 0; else return BufferSize[(which+Size()-1) % Size()]; };
|
||||
//!> Is current buffer ready
|
||||
bool IsBufferReady() { if(!Valid(which)) return false; else return BufferReady[which]; };
|
||||
//!> Is a buffer at a position ready
|
||||
bool IsBufferReady(int pos) { if(!Valid(pos)) return false; else return BufferReady[pos]; };
|
||||
//!> Is next buffer ready
|
||||
bool IsNextBufferReady() { if(Size() <= 0) return false; else return BufferReady[(which+1) % Size()]; };
|
||||
//!> Is last buffer ready
|
||||
bool IsLastBufferReady() { if(Size() <= 0) return false; else return BufferReady[(which+Size()-1) % Size()]; };
|
||||
//!> Set a buffer at a position to a ready state
|
||||
void SetBufferReady(int pos, bool st);
|
||||
//!> Set the buffersize at a position
|
||||
void SetBufferSize(int pos, int size);
|
||||
//!> Get the current position in the circle
|
||||
u16 Which() { return which; };
|
||||
protected:
|
||||
//!> Check if the position is a valid position in the vector
|
||||
bool Valid(int pos) { return !(pos < 0 || pos >= Size()); };
|
||||
|
||||
u16 which;
|
||||
u32 BufferBlockSize;
|
||||
std::vector<u8 *> SoundBuffer;
|
||||
std::vector<u32> BufferSize;
|
||||
std::vector<bool> BufferReady;
|
||||
u16 which;
|
||||
u32 BufferBlockSize;
|
||||
std::vector<u8 *> SoundBuffer;
|
||||
std::vector<u32> BufferSize;
|
||||
std::vector<bool> BufferReady;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -32,96 +32,96 @@
|
|||
#include "Mp3Decoder.hpp"
|
||||
|
||||
Mp3Decoder::Mp3Decoder(const char * filepath)
|
||||
: SoundDecoder(filepath)
|
||||
: SoundDecoder(filepath)
|
||||
{
|
||||
SoundType = SOUND_MP3;
|
||||
SoundType = SOUND_MP3;
|
||||
ReadBuffer = NULL;
|
||||
mad_timer_reset(&Timer);
|
||||
mad_timer_reset(&Timer);
|
||||
mad_stream_init(&Stream);
|
||||
mad_frame_init(&Frame);
|
||||
mad_synth_init(&Synth);
|
||||
|
||||
if(!file_fd)
|
||||
return;
|
||||
return;
|
||||
|
||||
OpenFile();
|
||||
OpenFile();
|
||||
}
|
||||
|
||||
Mp3Decoder::Mp3Decoder(const u8 * snd, int len)
|
||||
: SoundDecoder(snd, len)
|
||||
: SoundDecoder(snd, len)
|
||||
{
|
||||
SoundType = SOUND_MP3;
|
||||
SoundType = SOUND_MP3;
|
||||
ReadBuffer = NULL;
|
||||
mad_timer_reset(&Timer);
|
||||
mad_timer_reset(&Timer);
|
||||
mad_stream_init(&Stream);
|
||||
mad_frame_init(&Frame);
|
||||
mad_synth_init(&Synth);
|
||||
|
||||
if(!file_fd)
|
||||
return;
|
||||
return;
|
||||
|
||||
OpenFile();
|
||||
OpenFile();
|
||||
}
|
||||
|
||||
Mp3Decoder::~Mp3Decoder()
|
||||
{
|
||||
ExitRequested = true;
|
||||
while(Decoding)
|
||||
usleep(100);
|
||||
ExitRequested = true;
|
||||
while(Decoding)
|
||||
usleep(100);
|
||||
|
||||
mad_synth_finish(&Synth);
|
||||
mad_frame_finish(&Frame);
|
||||
mad_stream_finish(&Stream);
|
||||
mad_synth_finish(&Synth);
|
||||
mad_frame_finish(&Frame);
|
||||
mad_stream_finish(&Stream);
|
||||
|
||||
if(ReadBuffer)
|
||||
free(ReadBuffer);
|
||||
ReadBuffer = NULL;
|
||||
if(ReadBuffer)
|
||||
free(ReadBuffer);
|
||||
ReadBuffer = NULL;
|
||||
}
|
||||
|
||||
void Mp3Decoder::OpenFile()
|
||||
{
|
||||
GuardPtr = NULL;
|
||||
ReadBuffer = (u8 *) memalign(32, SoundBlockSize*SoundBlocks);
|
||||
if(!ReadBuffer)
|
||||
{
|
||||
if(file_fd)
|
||||
delete file_fd;
|
||||
file_fd = NULL;
|
||||
return;
|
||||
}
|
||||
GuardPtr = NULL;
|
||||
ReadBuffer = (u8 *) memalign(32, SoundBlockSize*SoundBlocks);
|
||||
if(!ReadBuffer)
|
||||
{
|
||||
if(file_fd)
|
||||
delete file_fd;
|
||||
file_fd = NULL;
|
||||
return;
|
||||
}
|
||||
|
||||
u8 dummybuff[4096];
|
||||
int ret = Read(dummybuff, 4096, 0);
|
||||
if(ret <= 0)
|
||||
{
|
||||
if(file_fd)
|
||||
delete file_fd;
|
||||
file_fd = NULL;
|
||||
return;
|
||||
}
|
||||
u8 dummybuff[4096];
|
||||
int ret = Read(dummybuff, 4096, 0);
|
||||
if(ret <= 0)
|
||||
{
|
||||
if(file_fd)
|
||||
delete file_fd;
|
||||
file_fd = NULL;
|
||||
return;
|
||||
}
|
||||
|
||||
SampleRate = (u32) Frame.header.samplerate;
|
||||
Format = ((MAD_NCHANNELS(&Frame.header) == 2) ? VOICE_STEREO_16BIT : VOICE_MONO_16BIT);
|
||||
Rewind();
|
||||
Decode();
|
||||
SampleRate = (u32) Frame.header.samplerate;
|
||||
Format = ((MAD_NCHANNELS(&Frame.header) == 2) ? VOICE_STEREO_16BIT : VOICE_MONO_16BIT);
|
||||
Rewind();
|
||||
Decode();
|
||||
}
|
||||
|
||||
int Mp3Decoder::Rewind()
|
||||
{
|
||||
mad_synth_finish(&Synth);
|
||||
mad_frame_finish(&Frame);
|
||||
mad_stream_finish(&Stream);
|
||||
mad_timer_reset(&Timer);
|
||||
mad_synth_finish(&Synth);
|
||||
mad_frame_finish(&Frame);
|
||||
mad_stream_finish(&Stream);
|
||||
mad_timer_reset(&Timer);
|
||||
mad_stream_init(&Stream);
|
||||
mad_frame_init(&Frame);
|
||||
mad_synth_init(&Synth);
|
||||
SynthPos = 0;
|
||||
GuardPtr = NULL;
|
||||
SynthPos = 0;
|
||||
GuardPtr = NULL;
|
||||
|
||||
if(!file_fd)
|
||||
return -1;
|
||||
return -1;
|
||||
|
||||
return SoundDecoder::Rewind();
|
||||
return SoundDecoder::Rewind();
|
||||
}
|
||||
|
||||
static inline s16 FixedToShort(mad_fixed_t Fixed)
|
||||
|
@ -138,37 +138,37 @@ static inline s16 FixedToShort(mad_fixed_t Fixed)
|
|||
|
||||
int Mp3Decoder::Read(u8 * buffer, int buffer_size, int pos)
|
||||
{
|
||||
if(!file_fd)
|
||||
return -1;
|
||||
if(!file_fd)
|
||||
return -1;
|
||||
|
||||
if(Format == VOICE_STEREO_16BIT)
|
||||
buffer_size &= ~0x0003;
|
||||
else
|
||||
buffer_size &= ~0x0001;
|
||||
if(Format == VOICE_STEREO_16BIT)
|
||||
buffer_size &= ~0x0003;
|
||||
else
|
||||
buffer_size &= ~0x0001;
|
||||
|
||||
u8 * write_pos = buffer;
|
||||
u8 * write_end = buffer+buffer_size;
|
||||
u8 * write_pos = buffer;
|
||||
u8 * write_end = buffer+buffer_size;
|
||||
|
||||
while(1)
|
||||
{
|
||||
while(SynthPos < Synth.pcm.length)
|
||||
{
|
||||
if(write_pos >= write_end)
|
||||
return write_pos-buffer;
|
||||
while(1)
|
||||
{
|
||||
while(SynthPos < Synth.pcm.length)
|
||||
{
|
||||
if(write_pos >= write_end)
|
||||
return write_pos-buffer;
|
||||
|
||||
*((s16 *) write_pos) = FixedToShort(Synth.pcm.samples[0][SynthPos]);
|
||||
write_pos += 2;
|
||||
*((s16 *) write_pos) = FixedToShort(Synth.pcm.samples[0][SynthPos]);
|
||||
write_pos += 2;
|
||||
|
||||
if(MAD_NCHANNELS(&Frame.header) == 2)
|
||||
{
|
||||
*((s16 *) write_pos) = FixedToShort(Synth.pcm.samples[1][SynthPos]);
|
||||
write_pos += 2;
|
||||
}
|
||||
SynthPos++;
|
||||
}
|
||||
if(MAD_NCHANNELS(&Frame.header) == 2)
|
||||
{
|
||||
*((s16 *) write_pos) = FixedToShort(Synth.pcm.samples[1][SynthPos]);
|
||||
write_pos += 2;
|
||||
}
|
||||
SynthPos++;
|
||||
}
|
||||
|
||||
if(Stream.buffer == NULL || Stream.error == MAD_ERROR_BUFLEN)
|
||||
{
|
||||
if(Stream.buffer == NULL || Stream.error == MAD_ERROR_BUFLEN)
|
||||
{
|
||||
u8 * ReadStart = ReadBuffer;
|
||||
int ReadSize = SoundBlockSize*SoundBlocks;
|
||||
int Remaining = 0;
|
||||
|
@ -182,14 +182,14 @@ int Mp3Decoder::Read(u8 * buffer, int buffer_size, int pos)
|
|||
}
|
||||
|
||||
ReadSize = file_fd->read(ReadStart, ReadSize);
|
||||
if(ReadSize <= 0)
|
||||
{
|
||||
if(ReadSize <= 0)
|
||||
{
|
||||
GuardPtr = ReadStart;
|
||||
memset(GuardPtr, 0, MAD_BUFFER_GUARD);
|
||||
ReadSize = MAD_BUFFER_GUARD;
|
||||
}
|
||||
}
|
||||
|
||||
CurPos += ReadSize;
|
||||
CurPos += ReadSize;
|
||||
mad_stream_buffer(&Stream, ReadBuffer, Remaining+ReadSize);
|
||||
}
|
||||
|
||||
|
@ -198,21 +198,21 @@ int Mp3Decoder::Read(u8 * buffer, int buffer_size, int pos)
|
|||
if(MAD_RECOVERABLE(Stream.error))
|
||||
{
|
||||
if(Stream.error != MAD_ERROR_LOSTSYNC || !GuardPtr)
|
||||
continue;
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(Stream.error != MAD_ERROR_BUFLEN)
|
||||
return -1;
|
||||
else if(Stream.error == MAD_ERROR_BUFLEN && GuardPtr)
|
||||
return -1;
|
||||
return -1;
|
||||
else if(Stream.error == MAD_ERROR_BUFLEN && GuardPtr)
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
mad_timer_add(&Timer,Frame.header.duration);
|
||||
mad_synth_frame(&Synth,&Frame);
|
||||
SynthPos = 0;
|
||||
}
|
||||
mad_timer_add(&Timer,Frame.header.duration);
|
||||
mad_synth_frame(&Synth,&Frame);
|
||||
SynthPos = 0;
|
||||
}
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -29,23 +29,23 @@
|
|||
|
||||
class Mp3Decoder : public SoundDecoder
|
||||
{
|
||||
public:
|
||||
Mp3Decoder(const char * filepath);
|
||||
Mp3Decoder(const u8 * sound, int len);
|
||||
virtual ~Mp3Decoder();
|
||||
int GetFormat() { return Format; };
|
||||
int GetSampleRate() { return SampleRate; };
|
||||
int Rewind();
|
||||
int Read(u8 * buffer, int buffer_size, int pos);
|
||||
protected:
|
||||
void OpenFile();
|
||||
struct mad_stream Stream;
|
||||
struct mad_frame Frame;
|
||||
struct mad_synth Synth;
|
||||
mad_timer_t Timer;
|
||||
u8 * GuardPtr;
|
||||
u8 * ReadBuffer;
|
||||
u8 Format;
|
||||
u32 SampleRate;
|
||||
u32 SynthPos;
|
||||
public:
|
||||
Mp3Decoder(const char * filepath);
|
||||
Mp3Decoder(const u8 * sound, int len);
|
||||
virtual ~Mp3Decoder();
|
||||
int GetFormat() { return Format; };
|
||||
int GetSampleRate() { return SampleRate; };
|
||||
int Rewind();
|
||||
int Read(u8 * buffer, int buffer_size, int pos);
|
||||
protected:
|
||||
void OpenFile();
|
||||
struct mad_stream Stream;
|
||||
struct mad_frame Frame;
|
||||
struct mad_synth Synth;
|
||||
mad_timer_t Timer;
|
||||
u8 * GuardPtr;
|
||||
u8 * ReadBuffer;
|
||||
u8 Format;
|
||||
u32 SampleRate;
|
||||
u32 SynthPos;
|
||||
};
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
|
||||
extern "C" int ogg_read(void * punt, int bytes, int blocks, int *f)
|
||||
{
|
||||
return ((CFile *) f)->read((u8 *) punt, bytes*blocks);
|
||||
return ((CFile *) f)->read((u8 *) punt, bytes*blocks);
|
||||
}
|
||||
|
||||
extern "C" int ogg_seek(int *f, ogg_int64_t offset, int mode)
|
||||
|
@ -39,7 +39,7 @@ extern "C" int ogg_seek(int *f, ogg_int64_t offset, int mode)
|
|||
|
||||
extern "C" int ogg_close(int *f)
|
||||
{
|
||||
((CFile *) f)->close();
|
||||
((CFile *) f)->close();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -50,95 +50,95 @@ extern "C" long ogg_tell(int *f)
|
|||
|
||||
static ov_callbacks callbacks = {
|
||||
(size_t (*)(void *, size_t, size_t, void *)) ogg_read,
|
||||
(int (*)(void *, ogg_int64_t, int)) ogg_seek,
|
||||
(int (*)(void *)) ogg_close,
|
||||
(long (*)(void *)) ogg_tell
|
||||
(int (*)(void *, ogg_int64_t, int)) ogg_seek,
|
||||
(int (*)(void *)) ogg_close,
|
||||
(long (*)(void *)) ogg_tell
|
||||
};
|
||||
|
||||
OggDecoder::OggDecoder(const char * filepath)
|
||||
: SoundDecoder(filepath)
|
||||
: SoundDecoder(filepath)
|
||||
{
|
||||
SoundType = SOUND_OGG;
|
||||
SoundType = SOUND_OGG;
|
||||
|
||||
if(!file_fd)
|
||||
return;
|
||||
if(!file_fd)
|
||||
return;
|
||||
|
||||
OpenFile();
|
||||
OpenFile();
|
||||
}
|
||||
|
||||
OggDecoder::OggDecoder(const u8 * snd, int len)
|
||||
: SoundDecoder(snd, len)
|
||||
: SoundDecoder(snd, len)
|
||||
{
|
||||
SoundType = SOUND_OGG;
|
||||
SoundType = SOUND_OGG;
|
||||
|
||||
if(!file_fd)
|
||||
return;
|
||||
if(!file_fd)
|
||||
return;
|
||||
|
||||
OpenFile();
|
||||
OpenFile();
|
||||
}
|
||||
|
||||
OggDecoder::~OggDecoder()
|
||||
{
|
||||
ExitRequested = true;
|
||||
while(Decoding)
|
||||
usleep(100);
|
||||
ExitRequested = true;
|
||||
while(Decoding)
|
||||
usleep(100);
|
||||
|
||||
if(file_fd)
|
||||
ov_clear(&ogg_file);
|
||||
if(file_fd)
|
||||
ov_clear(&ogg_file);
|
||||
}
|
||||
|
||||
void OggDecoder::OpenFile()
|
||||
{
|
||||
if (ov_open_callbacks(file_fd, &ogg_file, NULL, 0, callbacks) < 0)
|
||||
{
|
||||
delete file_fd;
|
||||
file_fd = NULL;
|
||||
return;
|
||||
}
|
||||
if (ov_open_callbacks(file_fd, &ogg_file, NULL, 0, callbacks) < 0)
|
||||
{
|
||||
delete file_fd;
|
||||
file_fd = NULL;
|
||||
return;
|
||||
}
|
||||
|
||||
ogg_info = ov_info(&ogg_file, -1);
|
||||
Decode();
|
||||
ogg_info = ov_info(&ogg_file, -1);
|
||||
Decode();
|
||||
}
|
||||
|
||||
int OggDecoder::GetFormat()
|
||||
{
|
||||
if(!file_fd)
|
||||
return VOICE_STEREO_16BIT;
|
||||
if(!file_fd)
|
||||
return VOICE_STEREO_16BIT;
|
||||
|
||||
return ((ogg_info->channels == 2) ? VOICE_STEREO_16BIT : VOICE_MONO_16BIT);
|
||||
return ((ogg_info->channels == 2) ? VOICE_STEREO_16BIT : VOICE_MONO_16BIT);
|
||||
}
|
||||
|
||||
int OggDecoder::GetSampleRate()
|
||||
{
|
||||
if(!file_fd)
|
||||
return 0;
|
||||
if(!file_fd)
|
||||
return 0;
|
||||
|
||||
return (int) ogg_info->rate;
|
||||
return (int) ogg_info->rate;
|
||||
}
|
||||
|
||||
int OggDecoder::Rewind()
|
||||
{
|
||||
if(!file_fd)
|
||||
return -1;
|
||||
if(!file_fd)
|
||||
return -1;
|
||||
|
||||
int ret = ov_time_seek(&ogg_file, 0);
|
||||
CurPos = 0;
|
||||
EndOfFile = false;
|
||||
int ret = ov_time_seek(&ogg_file, 0);
|
||||
CurPos = 0;
|
||||
EndOfFile = false;
|
||||
|
||||
return ret;
|
||||
return ret;
|
||||
}
|
||||
|
||||
int OggDecoder::Read(u8 * buffer, int buffer_size, int pos)
|
||||
{
|
||||
if(!file_fd)
|
||||
return -1;
|
||||
if(!file_fd)
|
||||
return -1;
|
||||
|
||||
int bitstream = 0;
|
||||
int bitstream = 0;
|
||||
|
||||
int read = ov_read(&ogg_file, (char *) buffer, buffer_size, &bitstream);
|
||||
int read = ov_read(&ogg_file, (char *) buffer, buffer_size, &bitstream);
|
||||
|
||||
if(read > 0)
|
||||
CurPos += read;
|
||||
if(read > 0)
|
||||
CurPos += read;
|
||||
|
||||
return read;
|
||||
return read;
|
||||
}
|
||||
|
|
|
@ -30,16 +30,16 @@
|
|||
|
||||
class OggDecoder : public SoundDecoder
|
||||
{
|
||||
public:
|
||||
OggDecoder(const char * filepath);
|
||||
OggDecoder(const u8 * snd, int len);
|
||||
virtual ~OggDecoder();
|
||||
int GetFormat();
|
||||
int GetSampleRate();
|
||||
int Rewind();
|
||||
int Read(u8 * buffer, int buffer_size, int pos);
|
||||
protected:
|
||||
void OpenFile();
|
||||
OggVorbis_File ogg_file;
|
||||
vorbis_info *ogg_info;
|
||||
public:
|
||||
OggDecoder(const char * filepath);
|
||||
OggDecoder(const u8 * snd, int len);
|
||||
virtual ~OggDecoder();
|
||||
int GetFormat();
|
||||
int GetSampleRate();
|
||||
int Rewind();
|
||||
int Read(u8 * buffer, int buffer_size, int pos);
|
||||
protected:
|
||||
void OpenFile();
|
||||
OggVorbis_File ogg_file;
|
||||
vorbis_info *ogg_info;
|
||||
};
|
||||
|
|
|
@ -34,123 +34,123 @@
|
|||
|
||||
SoundDecoder::SoundDecoder()
|
||||
{
|
||||
file_fd = NULL;
|
||||
Init();
|
||||
file_fd = NULL;
|
||||
Init();
|
||||
}
|
||||
|
||||
SoundDecoder::SoundDecoder(const char * filepath)
|
||||
{
|
||||
file_fd = new CFile(filepath, "rb");
|
||||
Init();
|
||||
file_fd = new CFile(filepath, "rb");
|
||||
Init();
|
||||
}
|
||||
|
||||
SoundDecoder::SoundDecoder(const u8 * buffer, int size)
|
||||
{
|
||||
file_fd = new CFile(buffer, size);
|
||||
Init();
|
||||
file_fd = new CFile(buffer, size);
|
||||
Init();
|
||||
}
|
||||
|
||||
SoundDecoder::~SoundDecoder()
|
||||
{
|
||||
ExitRequested = true;
|
||||
while(Decoding)
|
||||
usleep(100);
|
||||
ExitRequested = true;
|
||||
while(Decoding)
|
||||
usleep(100);
|
||||
|
||||
if(file_fd)
|
||||
delete file_fd;
|
||||
file_fd = NULL;
|
||||
if(file_fd)
|
||||
delete file_fd;
|
||||
file_fd = NULL;
|
||||
}
|
||||
|
||||
void SoundDecoder::Init()
|
||||
{
|
||||
SoundType = SOUND_RAW;
|
||||
SoundBlocks = 8;
|
||||
SoundBlockSize = 8192;
|
||||
CurPos = 0;
|
||||
Loop = false;
|
||||
EndOfFile = false;
|
||||
Decoding = false;
|
||||
ExitRequested = false;
|
||||
SoundBuffer.SetBufferBlockSize(SoundBlockSize);
|
||||
SoundBuffer.Resize(SoundBlocks);
|
||||
SoundType = SOUND_RAW;
|
||||
SoundBlocks = 8;
|
||||
SoundBlockSize = 8192;
|
||||
CurPos = 0;
|
||||
Loop = false;
|
||||
EndOfFile = false;
|
||||
Decoding = false;
|
||||
ExitRequested = false;
|
||||
SoundBuffer.SetBufferBlockSize(SoundBlockSize);
|
||||
SoundBuffer.Resize(SoundBlocks);
|
||||
}
|
||||
|
||||
int SoundDecoder::Rewind()
|
||||
{
|
||||
CurPos = 0;
|
||||
EndOfFile = false;
|
||||
file_fd->rewind();
|
||||
CurPos = 0;
|
||||
EndOfFile = false;
|
||||
file_fd->rewind();
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int SoundDecoder::Read(u8 * buffer, int buffer_size, int pos)
|
||||
{
|
||||
int ret = file_fd->read(buffer, buffer_size);
|
||||
CurPos += ret;
|
||||
int ret = file_fd->read(buffer, buffer_size);
|
||||
CurPos += ret;
|
||||
|
||||
return ret;
|
||||
return ret;
|
||||
}
|
||||
|
||||
void SoundDecoder::Decode()
|
||||
{
|
||||
if(!file_fd || ExitRequested || EndOfFile)
|
||||
return;
|
||||
if(!file_fd || ExitRequested || EndOfFile)
|
||||
return;
|
||||
|
||||
u16 newWhich = SoundBuffer.Which();
|
||||
u16 i = 0;
|
||||
for (i = 0; i < SoundBuffer.Size()-2; i++)
|
||||
{
|
||||
if(!SoundBuffer.IsBufferReady(newWhich))
|
||||
break;
|
||||
u16 newWhich = SoundBuffer.Which();
|
||||
u16 i = 0;
|
||||
for (i = 0; i < SoundBuffer.Size()-2; i++)
|
||||
{
|
||||
if(!SoundBuffer.IsBufferReady(newWhich))
|
||||
break;
|
||||
|
||||
newWhich = (newWhich+1) % SoundBuffer.Size();
|
||||
}
|
||||
newWhich = (newWhich+1) % SoundBuffer.Size();
|
||||
}
|
||||
|
||||
if(i == SoundBuffer.Size()-2)
|
||||
return;
|
||||
if(i == SoundBuffer.Size()-2)
|
||||
return;
|
||||
|
||||
Decoding = true;
|
||||
Decoding = true;
|
||||
|
||||
int done = 0;
|
||||
u8 * write_buf = SoundBuffer.GetBuffer(newWhich);
|
||||
if(!write_buf)
|
||||
{
|
||||
ExitRequested = true;
|
||||
Decoding = false;
|
||||
return;
|
||||
}
|
||||
int done = 0;
|
||||
u8 * write_buf = SoundBuffer.GetBuffer(newWhich);
|
||||
if(!write_buf)
|
||||
{
|
||||
ExitRequested = true;
|
||||
Decoding = false;
|
||||
return;
|
||||
}
|
||||
|
||||
while(done < SoundBlockSize)
|
||||
{
|
||||
int ret = Read(&write_buf[done], SoundBlockSize-done, Tell());
|
||||
while(done < SoundBlockSize)
|
||||
{
|
||||
int ret = Read(&write_buf[done], SoundBlockSize-done, Tell());
|
||||
|
||||
if(ret <= 0)
|
||||
{
|
||||
if(Loop)
|
||||
{
|
||||
Rewind();
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
EndOfFile = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(ret <= 0)
|
||||
{
|
||||
if(Loop)
|
||||
{
|
||||
Rewind();
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
EndOfFile = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
done += ret;
|
||||
}
|
||||
done += ret;
|
||||
}
|
||||
|
||||
if(done > 0)
|
||||
{
|
||||
SoundBuffer.SetBufferSize(newWhich, done);
|
||||
SoundBuffer.SetBufferReady(newWhich, true);
|
||||
}
|
||||
if(done > 0)
|
||||
{
|
||||
SoundBuffer.SetBufferSize(newWhich, done);
|
||||
SoundBuffer.SetBufferReady(newWhich, true);
|
||||
}
|
||||
|
||||
if(!SoundBuffer.IsBufferReady((newWhich+1) % SoundBuffer.Size()))
|
||||
Decode();
|
||||
Decode();
|
||||
|
||||
Decoding = false;
|
||||
Decoding = false;
|
||||
}
|
||||
|
||||
|
|
|
@ -45,45 +45,45 @@ enum
|
|||
|
||||
class SoundDecoder
|
||||
{
|
||||
public:
|
||||
SoundDecoder();
|
||||
SoundDecoder(const char * filepath);
|
||||
SoundDecoder(const u8 * buffer, int size);
|
||||
virtual ~SoundDecoder();
|
||||
virtual int Read(u8 * buffer, int buffer_size, int pos);
|
||||
virtual int Tell() { return CurPos; };
|
||||
virtual int Seek(int pos) { CurPos = pos; return file_fd->seek(CurPos, SEEK_SET); };
|
||||
virtual int Rewind();
|
||||
virtual int GetFormat() { return VOICE_STEREO_16BIT; };
|
||||
virtual int GetSampleRate() { return 48000; };
|
||||
virtual void Decode();
|
||||
virtual u32 GetBufferSize() { return SoundBuffer.GetBufferSize(); };
|
||||
virtual u8 * GetBuffer() { return SoundBuffer.GetBuffer(); };
|
||||
virtual u8 * GetNextBuffer() { return SoundBuffer.GetNextBuffer(); };
|
||||
virtual u8 * GetLastBuffer() { return SoundBuffer.GetLastBuffer(); };
|
||||
virtual void LoadNext() { SoundBuffer.LoadNext(); };
|
||||
virtual bool IsBufferReady() { return SoundBuffer.IsBufferReady(); };
|
||||
virtual bool IsNextBufferReady() { return SoundBuffer.IsNextBufferReady(); };
|
||||
virtual bool IsLastBufferReady() { return SoundBuffer.IsLastBufferReady(); };
|
||||
virtual bool IsEOF() { return EndOfFile; };
|
||||
virtual void SetLoop(bool l) { Loop = l; };
|
||||
virtual u8 GetSoundType() { return SoundType; };
|
||||
virtual void ClearBuffer() { SoundBuffer.ClearBuffer(); };
|
||||
virtual bool IsStereo() { return (GetFormat() == VOICE_STEREO_16BIT || GetFormat() == VOICE_STEREO_8BIT); };
|
||||
virtual bool Is16Bit() { return (GetFormat() == VOICE_STEREO_16BIT || GetFormat() == VOICE_MONO_16BIT); };
|
||||
protected:
|
||||
void Init();
|
||||
public:
|
||||
SoundDecoder();
|
||||
SoundDecoder(const char * filepath);
|
||||
SoundDecoder(const u8 * buffer, int size);
|
||||
virtual ~SoundDecoder();
|
||||
virtual int Read(u8 * buffer, int buffer_size, int pos);
|
||||
virtual int Tell() { return CurPos; };
|
||||
virtual int Seek(int pos) { CurPos = pos; return file_fd->seek(CurPos, SEEK_SET); };
|
||||
virtual int Rewind();
|
||||
virtual int GetFormat() { return VOICE_STEREO_16BIT; };
|
||||
virtual int GetSampleRate() { return 48000; };
|
||||
virtual void Decode();
|
||||
virtual u32 GetBufferSize() { return SoundBuffer.GetBufferSize(); };
|
||||
virtual u8 * GetBuffer() { return SoundBuffer.GetBuffer(); };
|
||||
virtual u8 * GetNextBuffer() { return SoundBuffer.GetNextBuffer(); };
|
||||
virtual u8 * GetLastBuffer() { return SoundBuffer.GetLastBuffer(); };
|
||||
virtual void LoadNext() { SoundBuffer.LoadNext(); };
|
||||
virtual bool IsBufferReady() { return SoundBuffer.IsBufferReady(); };
|
||||
virtual bool IsNextBufferReady() { return SoundBuffer.IsNextBufferReady(); };
|
||||
virtual bool IsLastBufferReady() { return SoundBuffer.IsLastBufferReady(); };
|
||||
virtual bool IsEOF() { return EndOfFile; };
|
||||
virtual void SetLoop(bool l) { Loop = l; };
|
||||
virtual u8 GetSoundType() { return SoundType; };
|
||||
virtual void ClearBuffer() { SoundBuffer.ClearBuffer(); };
|
||||
virtual bool IsStereo() { return (GetFormat() == VOICE_STEREO_16BIT || GetFormat() == VOICE_STEREO_8BIT); };
|
||||
virtual bool Is16Bit() { return (GetFormat() == VOICE_STEREO_16BIT || GetFormat() == VOICE_MONO_16BIT); };
|
||||
protected:
|
||||
void Init();
|
||||
|
||||
CFile * file_fd;
|
||||
BufferCircle SoundBuffer;
|
||||
u8 SoundType;
|
||||
u16 SoundBlocks;
|
||||
int SoundBlockSize;
|
||||
int CurPos;
|
||||
bool Loop;
|
||||
bool EndOfFile;
|
||||
bool Decoding;
|
||||
bool ExitRequested;
|
||||
CFile * file_fd;
|
||||
BufferCircle SoundBuffer;
|
||||
u8 SoundType;
|
||||
u16 SoundBlocks;
|
||||
int SoundBlockSize;
|
||||
int CurPos;
|
||||
bool Loop;
|
||||
bool EndOfFile;
|
||||
bool Decoding;
|
||||
bool ExitRequested;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -36,14 +36,14 @@ SoundHandler * SoundHandler::instance = NULL;
|
|||
|
||||
SoundHandler::SoundHandler()
|
||||
{
|
||||
Decoding = false;
|
||||
ExitRequested = false;
|
||||
Decoding = false;
|
||||
ExitRequested = false;
|
||||
for(u32 i = 0; i < MAX_DECODERS; ++i)
|
||||
DecoderList[i] = NULL;
|
||||
DecoderList[i] = NULL;
|
||||
|
||||
ThreadStack = (u8 *) memalign(32, 32768);
|
||||
ThreadStack = (u8 *) memalign(32, 32768);
|
||||
if(!ThreadStack)
|
||||
return;
|
||||
return;
|
||||
|
||||
LWP_CreateThread(&SoundThread, UpdateThread, this, ThreadStack, 32768, 80);
|
||||
}
|
||||
|
@ -55,7 +55,7 @@ SoundHandler::~SoundHandler()
|
|||
LWP_JoinThread(SoundThread, NULL);
|
||||
SoundThread = LWP_THREAD_NULL;
|
||||
if(ThreadStack)
|
||||
free(ThreadStack);
|
||||
free(ThreadStack);
|
||||
|
||||
ClearDecoderList();
|
||||
}
|
||||
|
@ -71,168 +71,168 @@ SoundHandler * SoundHandler::Instance()
|
|||
|
||||
void SoundHandler::DestroyInstance()
|
||||
{
|
||||
if(instance)
|
||||
{
|
||||
delete instance;
|
||||
}
|
||||
instance = NULL;
|
||||
if(instance)
|
||||
{
|
||||
delete instance;
|
||||
}
|
||||
instance = NULL;
|
||||
}
|
||||
|
||||
void SoundHandler::AddDecoder(int voice, const char * filepath)
|
||||
{
|
||||
if(voice < 0 || voice >= MAX_DECODERS)
|
||||
return;
|
||||
if(voice < 0 || voice >= MAX_DECODERS)
|
||||
return;
|
||||
|
||||
if(DecoderList[voice] != NULL)
|
||||
RemoveDecoder(voice);
|
||||
if(DecoderList[voice] != NULL)
|
||||
RemoveDecoder(voice);
|
||||
|
||||
DecoderList[voice] = GetSoundDecoder(filepath);
|
||||
DecoderList[voice] = GetSoundDecoder(filepath);
|
||||
}
|
||||
|
||||
void SoundHandler::AddDecoder(int voice, const u8 * snd, int len)
|
||||
{
|
||||
if(voice < 0 || voice >= MAX_DECODERS)
|
||||
return;
|
||||
if(voice < 0 || voice >= MAX_DECODERS)
|
||||
return;
|
||||
|
||||
if(DecoderList[voice] != NULL)
|
||||
RemoveDecoder(voice);
|
||||
if(DecoderList[voice] != NULL)
|
||||
RemoveDecoder(voice);
|
||||
|
||||
DecoderList[voice] = GetSoundDecoder(snd, len);
|
||||
DecoderList[voice] = GetSoundDecoder(snd, len);
|
||||
}
|
||||
|
||||
void SoundHandler::RemoveDecoder(int voice)
|
||||
{
|
||||
if(voice < 0 || voice >= MAX_DECODERS)
|
||||
return;
|
||||
if(voice < 0 || voice >= MAX_DECODERS)
|
||||
return;
|
||||
|
||||
if(DecoderList[voice] != NULL)
|
||||
delete DecoderList[voice];
|
||||
if(DecoderList[voice] != NULL)
|
||||
delete DecoderList[voice];
|
||||
|
||||
DecoderList[voice] = NULL;
|
||||
DecoderList[voice] = NULL;
|
||||
}
|
||||
|
||||
void SoundHandler::ClearDecoderList()
|
||||
{
|
||||
for(u32 i = 0; i < MAX_DECODERS; ++i)
|
||||
RemoveDecoder(i);
|
||||
for(u32 i = 0; i < MAX_DECODERS; ++i)
|
||||
RemoveDecoder(i);
|
||||
}
|
||||
|
||||
static inline bool CheckMP3Signature(const u8 * buffer)
|
||||
{
|
||||
const char MP3_Magic[][3] =
|
||||
{
|
||||
{'I', 'D', '3'}, //'ID3'
|
||||
{0xff, 0xfe}, //'MPEG ADTS, layer III, v1.0 [protected]', 'mp3', 'audio/mpeg'),
|
||||
{0xff, 0xff}, //'MPEG ADTS, layer III, v1.0', 'mp3', 'audio/mpeg'),
|
||||
{0xff, 0xfa}, //'MPEG ADTS, layer III, v1.0 [protected]', 'mp3', 'audio/mpeg'),
|
||||
{0xff, 0xfb}, //'MPEG ADTS, layer III, v1.0', 'mp3', 'audio/mpeg'),
|
||||
{0xff, 0xf2}, //'MPEG ADTS, layer III, v2.0 [protected]', 'mp3', 'audio/mpeg'),
|
||||
{0xff, 0xf3}, //'MPEG ADTS, layer III, v2.0', 'mp3', 'audio/mpeg'),
|
||||
{0xff, 0xf4}, //'MPEG ADTS, layer III, v2.0 [protected]', 'mp3', 'audio/mpeg'),
|
||||
{0xff, 0xf5}, //'MPEG ADTS, layer III, v2.0', 'mp3', 'audio/mpeg'),
|
||||
{0xff, 0xf6}, //'MPEG ADTS, layer III, v2.0 [protected]', 'mp3', 'audio/mpeg'),
|
||||
{0xff, 0xf7}, //'MPEG ADTS, layer III, v2.0', 'mp3', 'audio/mpeg'),
|
||||
{0xff, 0xe2}, //'MPEG ADTS, layer III, v2.5 [protected]', 'mp3', 'audio/mpeg'),
|
||||
{0xff, 0xe3}, //'MPEG ADTS, layer III, v2.5', 'mp3', 'audio/mpeg'),
|
||||
};
|
||||
const char MP3_Magic[][3] =
|
||||
{
|
||||
{'I', 'D', '3'}, //'ID3'
|
||||
{0xff, 0xfe}, //'MPEG ADTS, layer III, v1.0 [protected]', 'mp3', 'audio/mpeg'),
|
||||
{0xff, 0xff}, //'MPEG ADTS, layer III, v1.0', 'mp3', 'audio/mpeg'),
|
||||
{0xff, 0xfa}, //'MPEG ADTS, layer III, v1.0 [protected]', 'mp3', 'audio/mpeg'),
|
||||
{0xff, 0xfb}, //'MPEG ADTS, layer III, v1.0', 'mp3', 'audio/mpeg'),
|
||||
{0xff, 0xf2}, //'MPEG ADTS, layer III, v2.0 [protected]', 'mp3', 'audio/mpeg'),
|
||||
{0xff, 0xf3}, //'MPEG ADTS, layer III, v2.0', 'mp3', 'audio/mpeg'),
|
||||
{0xff, 0xf4}, //'MPEG ADTS, layer III, v2.0 [protected]', 'mp3', 'audio/mpeg'),
|
||||
{0xff, 0xf5}, //'MPEG ADTS, layer III, v2.0', 'mp3', 'audio/mpeg'),
|
||||
{0xff, 0xf6}, //'MPEG ADTS, layer III, v2.0 [protected]', 'mp3', 'audio/mpeg'),
|
||||
{0xff, 0xf7}, //'MPEG ADTS, layer III, v2.0', 'mp3', 'audio/mpeg'),
|
||||
{0xff, 0xe2}, //'MPEG ADTS, layer III, v2.5 [protected]', 'mp3', 'audio/mpeg'),
|
||||
{0xff, 0xe3}, //'MPEG ADTS, layer III, v2.5', 'mp3', 'audio/mpeg'),
|
||||
};
|
||||
|
||||
if(buffer[0] == MP3_Magic[0][0] && buffer[1] == MP3_Magic[0][1] &&
|
||||
buffer[2] == MP3_Magic[0][2])
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if(buffer[0] == MP3_Magic[0][0] && buffer[1] == MP3_Magic[0][1] &&
|
||||
buffer[2] == MP3_Magic[0][2])
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
for(int i = 1; i < 13; i++)
|
||||
{
|
||||
if(buffer[0] == MP3_Magic[i][0] && buffer[1] == MP3_Magic[i][1])
|
||||
return true;
|
||||
}
|
||||
for(int i = 1; i < 13; i++)
|
||||
{
|
||||
if(buffer[0] == MP3_Magic[i][0] && buffer[1] == MP3_Magic[i][1])
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
SoundDecoder * SoundHandler::GetSoundDecoder(const char * filepath)
|
||||
{
|
||||
u32 magic;
|
||||
CFile f(filepath, "rb");
|
||||
if(f.size() == 0)
|
||||
return NULL;
|
||||
u32 magic;
|
||||
CFile f(filepath, "rb");
|
||||
if(f.size() == 0)
|
||||
return NULL;
|
||||
|
||||
do
|
||||
{
|
||||
f.read((u8 *) &magic, 1);
|
||||
}
|
||||
while(((u8 *) &magic)[0] == 0 && f.tell() < f.size());
|
||||
do
|
||||
{
|
||||
f.read((u8 *) &magic, 1);
|
||||
}
|
||||
while(((u8 *) &magic)[0] == 0 && f.tell() < f.size());
|
||||
|
||||
if(f.tell() == f.size())
|
||||
return NULL;
|
||||
if(f.tell() == f.size())
|
||||
return NULL;
|
||||
|
||||
f.seek(f.tell()-1, SEEK_SET);
|
||||
f.read((u8 *) &magic, 4);
|
||||
f.close();
|
||||
f.seek(f.tell()-1, SEEK_SET);
|
||||
f.read((u8 *) &magic, 4);
|
||||
f.close();
|
||||
|
||||
if(magic == 'OggS')
|
||||
{
|
||||
return new OggDecoder(filepath);
|
||||
}
|
||||
else if(magic == 'RIFF')
|
||||
{
|
||||
return new WavDecoder(filepath);
|
||||
}
|
||||
else if(magic == 'BNS ')
|
||||
{
|
||||
return new BNSDecoder(filepath);
|
||||
}
|
||||
else if(magic == 'FORM')
|
||||
{
|
||||
return new AifDecoder(filepath);
|
||||
}
|
||||
else if(CheckMP3Signature((u8 *) &magic) == true)
|
||||
{
|
||||
return new Mp3Decoder(filepath);
|
||||
}
|
||||
if(magic == 'OggS')
|
||||
{
|
||||
return new OggDecoder(filepath);
|
||||
}
|
||||
else if(magic == 'RIFF')
|
||||
{
|
||||
return new WavDecoder(filepath);
|
||||
}
|
||||
else if(magic == 'BNS ')
|
||||
{
|
||||
return new BNSDecoder(filepath);
|
||||
}
|
||||
else if(magic == 'FORM')
|
||||
{
|
||||
return new AifDecoder(filepath);
|
||||
}
|
||||
else if(CheckMP3Signature((u8 *) &magic) == true)
|
||||
{
|
||||
return new Mp3Decoder(filepath);
|
||||
}
|
||||
|
||||
return new SoundDecoder(filepath);
|
||||
return new SoundDecoder(filepath);
|
||||
}
|
||||
|
||||
SoundDecoder * SoundHandler::GetSoundDecoder(const u8 * sound, int length)
|
||||
{
|
||||
const u8 * check = sound;
|
||||
int counter = 0;
|
||||
const u8 * check = sound;
|
||||
int counter = 0;
|
||||
|
||||
while(check[0] == 0 && counter < length)
|
||||
{
|
||||
check++;
|
||||
counter++;
|
||||
}
|
||||
while(check[0] == 0 && counter < length)
|
||||
{
|
||||
check++;
|
||||
counter++;
|
||||
}
|
||||
|
||||
if(counter >= length)
|
||||
return NULL;
|
||||
if(counter >= length)
|
||||
return NULL;
|
||||
|
||||
u32 * magic = (u32 *) check;
|
||||
u32 * magic = (u32 *) check;
|
||||
|
||||
if(magic[0] == 'OggS')
|
||||
{
|
||||
return new OggDecoder(sound, length);
|
||||
}
|
||||
else if(magic[0] == 'RIFF')
|
||||
{
|
||||
return new WavDecoder(sound, length);
|
||||
}
|
||||
else if(magic[0] == 'BNS ')
|
||||
{
|
||||
return new BNSDecoder(sound, length);
|
||||
}
|
||||
else if(magic[0] == 'FORM')
|
||||
{
|
||||
return new AifDecoder(sound, length);
|
||||
}
|
||||
else if(CheckMP3Signature(check) == true)
|
||||
{
|
||||
return new Mp3Decoder(sound, length);
|
||||
}
|
||||
if(magic[0] == 'OggS')
|
||||
{
|
||||
return new OggDecoder(sound, length);
|
||||
}
|
||||
else if(magic[0] == 'RIFF')
|
||||
{
|
||||
return new WavDecoder(sound, length);
|
||||
}
|
||||
else if(magic[0] == 'BNS ')
|
||||
{
|
||||
return new BNSDecoder(sound, length);
|
||||
}
|
||||
else if(magic[0] == 'FORM')
|
||||
{
|
||||
return new AifDecoder(sound, length);
|
||||
}
|
||||
else if(CheckMP3Signature(check) == true)
|
||||
{
|
||||
return new Mp3Decoder(sound, length);
|
||||
}
|
||||
|
||||
return new SoundDecoder(sound, length);
|
||||
return new SoundDecoder(sound, length);
|
||||
}
|
||||
|
||||
void * SoundHandler::UpdateThread(void *arg)
|
||||
|
@ -243,22 +243,22 @@ void * SoundHandler::UpdateThread(void *arg)
|
|||
|
||||
void SoundHandler::InternalSoundUpdates()
|
||||
{
|
||||
u16 i = 0;
|
||||
u16 i = 0;
|
||||
LWP_InitQueue(&ThreadQueue);
|
||||
while (!ExitRequested)
|
||||
{
|
||||
LWP_ThreadSleep(ThreadQueue);
|
||||
LWP_ThreadSleep(ThreadQueue);
|
||||
|
||||
for(i = 0; i < MAX_DECODERS; ++i)
|
||||
{
|
||||
if(DecoderList[i] == NULL)
|
||||
continue;
|
||||
for(i = 0; i < MAX_DECODERS; ++i)
|
||||
{
|
||||
if(DecoderList[i] == NULL)
|
||||
continue;
|
||||
|
||||
Decoding = true;
|
||||
DecoderList[i]->Decode();
|
||||
}
|
||||
Decoding = false;
|
||||
Decoding = true;
|
||||
DecoderList[i]->Decode();
|
||||
}
|
||||
Decoding = false;
|
||||
}
|
||||
LWP_CloseQueue(ThreadQueue);
|
||||
ThreadQueue = LWP_TQUEUE_NULL;
|
||||
LWP_CloseQueue(ThreadQueue);
|
||||
ThreadQueue = LWP_TQUEUE_NULL;
|
||||
}
|
||||
|
|
|
@ -30,11 +30,11 @@
|
|||
#include <gccore.h>
|
||||
#include "SoundDecoder.hpp"
|
||||
|
||||
#define MAX_DECODERS 16
|
||||
#define MAX_DECODERS 16
|
||||
|
||||
class SoundHandler
|
||||
{
|
||||
public:
|
||||
public:
|
||||
static SoundHandler * Instance();
|
||||
static void DestroyInstance();
|
||||
|
||||
|
@ -43,8 +43,8 @@ class SoundHandler
|
|||
void RemoveDecoder(int voice);
|
||||
void DestroyDecoder(SoundDecoder * decoder);
|
||||
|
||||
SoundDecoder * Decoder(int i) { return ((i < 0 || i >= MAX_DECODERS) ? NULL : DecoderList[i]); };
|
||||
void ThreadSignal() { LWP_ThreadSignal(ThreadQueue); };
|
||||
SoundDecoder * Decoder(int i) { return ((i < 0 || i >= MAX_DECODERS) ? NULL : DecoderList[i]); };
|
||||
void ThreadSignal() { LWP_ThreadSignal(ThreadQueue); };
|
||||
bool IsDecoding() { return Decoding; };
|
||||
protected:
|
||||
SoundHandler();
|
||||
|
@ -52,13 +52,13 @@ class SoundHandler
|
|||
static void * UpdateThread(void *arg);
|
||||
void InternalSoundUpdates();
|
||||
void ClearDecoderList();
|
||||
SoundDecoder * GetSoundDecoder(const char * filepath);
|
||||
SoundDecoder * GetSoundDecoder(const u8 * sound, int length);
|
||||
SoundDecoder * GetSoundDecoder(const char * filepath);
|
||||
SoundDecoder * GetSoundDecoder(const u8 * sound, int length);
|
||||
|
||||
static SoundHandler * instance;
|
||||
u8 * ThreadStack;
|
||||
lwp_t SoundThread;
|
||||
lwpq_t ThreadQueue;
|
||||
lwpq_t ThreadQueue;
|
||||
bool Decoding;
|
||||
bool ExitRequested;
|
||||
|
||||
|
|
|
@ -28,29 +28,29 @@
|
|||
#include "utils/uncompress.h"
|
||||
|
||||
WavDecoder::WavDecoder(const char * filepath)
|
||||
: SoundDecoder(filepath)
|
||||
: SoundDecoder(filepath)
|
||||
{
|
||||
SoundType = SOUND_WAV;
|
||||
SampleRate = 48000;
|
||||
Format = VOICE_STEREO_16BIT;
|
||||
SoundType = SOUND_WAV;
|
||||
SampleRate = 48000;
|
||||
Format = VOICE_STEREO_16BIT;
|
||||
|
||||
if(!file_fd)
|
||||
return;
|
||||
if(!file_fd)
|
||||
return;
|
||||
|
||||
OpenFile();
|
||||
OpenFile();
|
||||
}
|
||||
|
||||
WavDecoder::WavDecoder(const u8 * snd, int len)
|
||||
: SoundDecoder(snd, len)
|
||||
: SoundDecoder(snd, len)
|
||||
{
|
||||
SoundType = SOUND_WAV;
|
||||
SampleRate = 48000;
|
||||
Format = VOICE_STEREO_16BIT;
|
||||
SoundType = SOUND_WAV;
|
||||
SampleRate = 48000;
|
||||
Format = VOICE_STEREO_16BIT;
|
||||
|
||||
if(!file_fd)
|
||||
return;
|
||||
if(!file_fd)
|
||||
return;
|
||||
|
||||
OpenFile();
|
||||
OpenFile();
|
||||
}
|
||||
|
||||
WavDecoder::~WavDecoder()
|
||||
|
@ -59,13 +59,13 @@ WavDecoder::~WavDecoder()
|
|||
|
||||
void WavDecoder::OpenFile()
|
||||
{
|
||||
SWaveHdr Header;
|
||||
SWaveFmtChunk FmtChunk;
|
||||
memset(&Header, 0, sizeof(SWaveHdr));
|
||||
memset(&FmtChunk, 0, sizeof(SWaveFmtChunk));
|
||||
SWaveHdr Header;
|
||||
SWaveFmtChunk FmtChunk;
|
||||
memset(&Header, 0, sizeof(SWaveHdr));
|
||||
memset(&FmtChunk, 0, sizeof(SWaveFmtChunk));
|
||||
|
||||
file_fd->read((u8 *) &Header, sizeof(SWaveHdr));
|
||||
file_fd->read((u8 *) &FmtChunk, sizeof(SWaveFmtChunk));
|
||||
file_fd->read((u8 *) &Header, sizeof(SWaveHdr));
|
||||
file_fd->read((u8 *) &FmtChunk, sizeof(SWaveFmtChunk));
|
||||
|
||||
if (Header.magicRIFF != 'RIFF')
|
||||
{
|
||||
|
@ -83,27 +83,27 @@ void WavDecoder::OpenFile()
|
|||
return;
|
||||
}
|
||||
|
||||
DataOffset = sizeof(SWaveHdr)+le32(FmtChunk.size)+8;
|
||||
file_fd->seek(DataOffset, SEEK_SET);
|
||||
SWaveChunk DataChunk;
|
||||
file_fd->read((u8 *) &DataChunk, sizeof(SWaveChunk));
|
||||
DataOffset = sizeof(SWaveHdr)+le32(FmtChunk.size)+8;
|
||||
file_fd->seek(DataOffset, SEEK_SET);
|
||||
SWaveChunk DataChunk;
|
||||
file_fd->read((u8 *) &DataChunk, sizeof(SWaveChunk));
|
||||
|
||||
if(DataChunk.magicDATA == 'fact')
|
||||
{
|
||||
DataOffset += 8+le32(DataChunk.size);
|
||||
file_fd->seek(DataOffset, SEEK_SET);
|
||||
file_fd->read((u8 *) &DataChunk, sizeof(SWaveChunk));
|
||||
}
|
||||
if(DataChunk.magicDATA != 'data')
|
||||
{
|
||||
if(DataChunk.magicDATA == 'fact')
|
||||
{
|
||||
DataOffset += 8+le32(DataChunk.size);
|
||||
file_fd->seek(DataOffset, SEEK_SET);
|
||||
file_fd->read((u8 *) &DataChunk, sizeof(SWaveChunk));
|
||||
}
|
||||
if(DataChunk.magicDATA != 'data')
|
||||
{
|
||||
CloseFile();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
DataOffset += 8;
|
||||
DataSize = le32(DataChunk.size);
|
||||
Is16Bit = (le16(FmtChunk.bps) == 16);
|
||||
SampleRate = le32(FmtChunk.freq);
|
||||
DataOffset += 8;
|
||||
DataSize = le32(DataChunk.size);
|
||||
Is16Bit = (le16(FmtChunk.bps) == 16);
|
||||
SampleRate = le32(FmtChunk.freq);
|
||||
|
||||
if (le16(FmtChunk.channels) == 1 && le16(FmtChunk.bps) == 8 && le16(FmtChunk.alignment) <= 1)
|
||||
Format = VOICE_MONO_8BIT;
|
||||
|
@ -114,42 +114,42 @@ void WavDecoder::OpenFile()
|
|||
else if (le16(FmtChunk.channels) == 2 && le16(FmtChunk.bps) == 16 && le16(FmtChunk.alignment) <= 4)
|
||||
Format = VOICE_STEREO_16BIT;
|
||||
|
||||
Decode();
|
||||
Decode();
|
||||
}
|
||||
|
||||
void WavDecoder::CloseFile()
|
||||
{
|
||||
if(file_fd)
|
||||
delete file_fd;
|
||||
if(file_fd)
|
||||
delete file_fd;
|
||||
|
||||
file_fd = NULL;
|
||||
file_fd = NULL;
|
||||
}
|
||||
|
||||
int WavDecoder::Read(u8 * buffer, int buffer_size, int pos)
|
||||
{
|
||||
if(!file_fd)
|
||||
return -1;
|
||||
if(!file_fd)
|
||||
return -1;
|
||||
|
||||
if(CurPos >= (int) DataSize)
|
||||
return 0;
|
||||
if(CurPos >= (int) DataSize)
|
||||
return 0;
|
||||
|
||||
file_fd->seek(DataOffset+CurPos, SEEK_SET);
|
||||
file_fd->seek(DataOffset+CurPos, SEEK_SET);
|
||||
|
||||
if(buffer_size > (int) DataSize-CurPos)
|
||||
buffer_size = DataSize-CurPos;
|
||||
if(buffer_size > (int) DataSize-CurPos)
|
||||
buffer_size = DataSize-CurPos;
|
||||
|
||||
int read = file_fd->read(buffer, buffer_size);
|
||||
if(read > 0)
|
||||
{
|
||||
if (Is16Bit)
|
||||
{
|
||||
read &= ~0x0001;
|
||||
int read = file_fd->read(buffer, buffer_size);
|
||||
if(read > 0)
|
||||
{
|
||||
if (Is16Bit)
|
||||
{
|
||||
read &= ~0x0001;
|
||||
|
||||
for (u32 i = 0; i < (u32) (read / sizeof (u16)); ++i)
|
||||
((u16 *) buffer)[i] = le16(((u16 *) buffer)[i]);
|
||||
}
|
||||
CurPos += read;
|
||||
}
|
||||
for (u32 i = 0; i < (u32) (read / sizeof (u16)); ++i)
|
||||
((u16 *) buffer)[i] = le16(((u16 *) buffer)[i]);
|
||||
}
|
||||
CurPos += read;
|
||||
}
|
||||
|
||||
return read;
|
||||
return read;
|
||||
}
|
||||
|
|
|
@ -55,21 +55,21 @@ typedef struct
|
|||
|
||||
class WavDecoder : public SoundDecoder
|
||||
{
|
||||
public:
|
||||
WavDecoder(const char * filepath);
|
||||
WavDecoder(const u8 * snd, int len);
|
||||
virtual ~WavDecoder();
|
||||
int GetFormat() { return Format; };
|
||||
int GetSampleRate() { return SampleRate; };
|
||||
int Read(u8 * buffer, int buffer_size, int pos);
|
||||
protected:
|
||||
void OpenFile();
|
||||
void CloseFile();
|
||||
u32 DataOffset;
|
||||
u32 DataSize;
|
||||
u32 SampleRate;
|
||||
u8 Format;
|
||||
bool Is16Bit;
|
||||
public:
|
||||
WavDecoder(const char * filepath);
|
||||
WavDecoder(const u8 * snd, int len);
|
||||
virtual ~WavDecoder();
|
||||
int GetFormat() { return Format; };
|
||||
int GetSampleRate() { return SampleRate; };
|
||||
int Read(u8 * buffer, int buffer_size, int pos);
|
||||
protected:
|
||||
void OpenFile();
|
||||
void CloseFile();
|
||||
u32 DataOffset;
|
||||
u32 DataSize;
|
||||
u32 SampleRate;
|
||||
u8 Format;
|
||||
bool Is16Bit;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -10,209 +10,209 @@
|
|||
#include "menu.h"
|
||||
|
||||
GuiBGM::GuiBGM(const u8 *s, int l, int v) :
|
||||
GuiSound(s, l, v, false, 0)
|
||||
GuiSound(s, l, v, false, 0)
|
||||
{
|
||||
currentPath = NULL;
|
||||
currentPlaying = 0;
|
||||
voice = 0;
|
||||
currentPath = NULL;
|
||||
currentPlaying = 0;
|
||||
voice = 0;
|
||||
}
|
||||
|
||||
GuiBGM::~GuiBGM()
|
||||
{
|
||||
if (currentPath) delete[] currentPath;
|
||||
if (currentPath) delete[] currentPath;
|
||||
|
||||
ClearList();
|
||||
ClearList();
|
||||
}
|
||||
|
||||
bool GuiBGM::Load(const char *path)
|
||||
{
|
||||
if (!path)
|
||||
{
|
||||
LoadStandard();
|
||||
return false;
|
||||
}
|
||||
if (strcmp(path, "") == 0)
|
||||
{
|
||||
LoadStandard();
|
||||
return false;
|
||||
}
|
||||
if (!path)
|
||||
{
|
||||
LoadStandard();
|
||||
return false;
|
||||
}
|
||||
if (strcmp(path, "") == 0)
|
||||
{
|
||||
LoadStandard();
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!GuiSound::Load(path))
|
||||
{
|
||||
LoadStandard();
|
||||
return false;
|
||||
}
|
||||
if (!GuiSound::Load(path))
|
||||
{
|
||||
LoadStandard();
|
||||
return false;
|
||||
}
|
||||
|
||||
return ParsePath(path);
|
||||
return ParsePath(path);
|
||||
}
|
||||
|
||||
bool GuiBGM::LoadStandard()
|
||||
{
|
||||
ClearList();
|
||||
if (currentPath)
|
||||
{
|
||||
delete[] currentPath;
|
||||
currentPath = NULL;
|
||||
}
|
||||
ClearList();
|
||||
if (currentPath)
|
||||
{
|
||||
delete[] currentPath;
|
||||
currentPath = NULL;
|
||||
}
|
||||
|
||||
strcpy(Settings.ogg_path, "");
|
||||
strcpy(Settings.ogg_path, "");
|
||||
|
||||
bool ret = GuiSound::Load(Resources::GetFile("bg_music.ogg"), Resources::GetFileSize("bg_music.ogg"), false);
|
||||
bool ret = GuiSound::Load(Resources::GetFile("bg_music.ogg"), Resources::GetFileSize("bg_music.ogg"), false);
|
||||
|
||||
if (ret) Play();
|
||||
if (ret) Play();
|
||||
|
||||
return ret;
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool GuiBGM::ParsePath(const char * folderpath)
|
||||
{
|
||||
ClearList();
|
||||
ClearList();
|
||||
|
||||
if (currentPath) delete[] currentPath;
|
||||
if (currentPath) delete[] currentPath;
|
||||
|
||||
currentPath = new char[strlen(folderpath) + 1];
|
||||
sprintf(currentPath, "%s", folderpath);
|
||||
currentPath = new char[strlen(folderpath) + 1];
|
||||
sprintf(currentPath, "%s", folderpath);
|
||||
|
||||
char * isdirpath = strrchr(folderpath, '.');
|
||||
if (isdirpath)
|
||||
{
|
||||
char * pathptr = strrchr(currentPath, '/');
|
||||
if (pathptr)
|
||||
{
|
||||
pathptr++;
|
||||
pathptr[0] = 0;
|
||||
}
|
||||
}
|
||||
char * isdirpath = strrchr(folderpath, '.');
|
||||
if (isdirpath)
|
||||
{
|
||||
char * pathptr = strrchr(currentPath, '/');
|
||||
if (pathptr)
|
||||
{
|
||||
pathptr++;
|
||||
pathptr[0] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
char * LoadedFilename = strrchr(folderpath, '/') + 1;
|
||||
char * LoadedFilename = strrchr(folderpath, '/') + 1;
|
||||
|
||||
char filename[1024];
|
||||
char filename[1024];
|
||||
struct dirent * dirent = NULL;
|
||||
|
||||
DIR * dir = opendir(currentPath);
|
||||
if (dir == NULL)
|
||||
{
|
||||
LoadStandard();
|
||||
return false;
|
||||
}
|
||||
u32 counter = 0;
|
||||
DIR * dir = opendir(currentPath);
|
||||
if (dir == NULL)
|
||||
{
|
||||
LoadStandard();
|
||||
return false;
|
||||
}
|
||||
u32 counter = 0;
|
||||
|
||||
while ((dirent = readdir(dir)) != 0)
|
||||
{
|
||||
snprintf(filename, sizeof(filename), dirent->d_name);
|
||||
while ((dirent = readdir(dir)) != 0)
|
||||
{
|
||||
snprintf(filename, sizeof(filename), dirent->d_name);
|
||||
|
||||
char * fileext = strrchr(filename, '.');
|
||||
if (!fileext)
|
||||
continue;
|
||||
char * fileext = strrchr(filename, '.');
|
||||
if (!fileext)
|
||||
continue;
|
||||
|
||||
if (strcasecmp(fileext, ".mp3") == 0 || strcasecmp(fileext, ".ogg") == 0 ||
|
||||
strcasecmp(fileext, ".wav") == 0 || strcasecmp(fileext, ".aif") == 0)
|
||||
{
|
||||
AddEntrie(filename);
|
||||
if (strcasecmp(fileext, ".mp3") == 0 || strcasecmp(fileext, ".ogg") == 0 ||
|
||||
strcasecmp(fileext, ".wav") == 0 || strcasecmp(fileext, ".aif") == 0)
|
||||
{
|
||||
AddEntrie(filename);
|
||||
|
||||
if (strcmp(LoadedFilename, filename) == 0) currentPlaying = counter;
|
||||
if (strcmp(LoadedFilename, filename) == 0) currentPlaying = counter;
|
||||
|
||||
counter++;
|
||||
}
|
||||
counter++;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
closedir(dir);
|
||||
closedir(dir);
|
||||
|
||||
snprintf(Settings.ogg_path, sizeof(Settings.ogg_path), "%s", folderpath);
|
||||
snprintf(Settings.ogg_path, sizeof(Settings.ogg_path), "%s", folderpath);
|
||||
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
void GuiBGM::AddEntrie(const char * filename)
|
||||
{
|
||||
if (!filename) return;
|
||||
if (!filename) return;
|
||||
|
||||
char * NewEntrie = new char[strlen(filename) + 1];
|
||||
sprintf(NewEntrie, "%s", filename);
|
||||
char * NewEntrie = new char[strlen(filename) + 1];
|
||||
sprintf(NewEntrie, "%s", filename);
|
||||
|
||||
PlayList.push_back(NewEntrie);
|
||||
PlayList.push_back(NewEntrie);
|
||||
}
|
||||
|
||||
void GuiBGM::ClearList()
|
||||
{
|
||||
for (u32 i = 0; i < PlayList.size(); i++)
|
||||
{
|
||||
if (PlayList.at(i) != NULL)
|
||||
{
|
||||
delete[] PlayList.at(i);
|
||||
PlayList.at(i) = NULL;
|
||||
}
|
||||
}
|
||||
for (u32 i = 0; i < PlayList.size(); i++)
|
||||
{
|
||||
if (PlayList.at(i) != NULL)
|
||||
{
|
||||
delete[] PlayList.at(i);
|
||||
PlayList.at(i) = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
PlayList.clear();
|
||||
PlayList.clear();
|
||||
}
|
||||
|
||||
bool GuiBGM::PlayNext()
|
||||
{
|
||||
if (!currentPath) return false;
|
||||
if (!currentPath) return false;
|
||||
|
||||
currentPlaying++;
|
||||
if (currentPlaying >= (int) PlayList.size()) currentPlaying = 0;
|
||||
currentPlaying++;
|
||||
if (currentPlaying >= (int) PlayList.size()) currentPlaying = 0;
|
||||
|
||||
snprintf(Settings.ogg_path, sizeof(Settings.ogg_path), "%s%s", currentPath, PlayList.at(currentPlaying));
|
||||
snprintf(Settings.ogg_path, sizeof(Settings.ogg_path), "%s%s", currentPath, PlayList.at(currentPlaying));
|
||||
|
||||
if (!GuiSound::Load(Settings.ogg_path)) return false;
|
||||
if (!GuiSound::Load(Settings.ogg_path)) return false;
|
||||
|
||||
Play();
|
||||
Play();
|
||||
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool GuiBGM::PlayPrevious()
|
||||
{
|
||||
if (!currentPath) return false;
|
||||
if (!currentPath) return false;
|
||||
|
||||
currentPlaying--;
|
||||
if (currentPlaying < 0) currentPlaying = PlayList.size() - 1;
|
||||
currentPlaying--;
|
||||
if (currentPlaying < 0) currentPlaying = PlayList.size() - 1;
|
||||
|
||||
snprintf(Settings.ogg_path, sizeof(Settings.ogg_path), "%s%s", currentPath, PlayList.at(currentPlaying));
|
||||
snprintf(Settings.ogg_path, sizeof(Settings.ogg_path), "%s%s", currentPath, PlayList.at(currentPlaying));
|
||||
|
||||
if (!GuiSound::Load(Settings.ogg_path)) return false;
|
||||
if (!GuiSound::Load(Settings.ogg_path)) return false;
|
||||
|
||||
Play();
|
||||
Play();
|
||||
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool GuiBGM::PlayRandom()
|
||||
{
|
||||
if (!currentPath) return false;
|
||||
if (!currentPath) return false;
|
||||
|
||||
srand(time(NULL));
|
||||
srand(time(NULL));
|
||||
|
||||
currentPlaying = rand() % PlayList.size();
|
||||
currentPlaying = rand() % PlayList.size();
|
||||
|
||||
//just in case
|
||||
if (currentPlaying < 0)
|
||||
currentPlaying = PlayList.size() - 1;
|
||||
else if (currentPlaying >= (int) PlayList.size()) currentPlaying = 0;
|
||||
//just in case
|
||||
if (currentPlaying < 0)
|
||||
currentPlaying = PlayList.size() - 1;
|
||||
else if (currentPlaying >= (int) PlayList.size()) currentPlaying = 0;
|
||||
|
||||
snprintf(Settings.ogg_path, sizeof(Settings.ogg_path), "%s%s", currentPath, PlayList.at(currentPlaying));
|
||||
snprintf(Settings.ogg_path, sizeof(Settings.ogg_path), "%s%s", currentPath, PlayList.at(currentPlaying));
|
||||
|
||||
if (!GuiSound::Load(Settings.ogg_path)) return false;
|
||||
if (!GuiSound::Load(Settings.ogg_path)) return false;
|
||||
|
||||
Play();
|
||||
Play();
|
||||
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
void GuiBGM::UpdateState()
|
||||
{
|
||||
if (!IsPlaying())
|
||||
{
|
||||
if (loop == DIR_LOOP)
|
||||
{
|
||||
PlayNext();
|
||||
}
|
||||
else if (loop == RANDOM_BGM)
|
||||
{
|
||||
PlayRandom();
|
||||
}
|
||||
}
|
||||
if (!IsPlaying())
|
||||
{
|
||||
if (loop == DIR_LOOP)
|
||||
{
|
||||
PlayNext();
|
||||
}
|
||||
else if (loop == RANDOM_BGM)
|
||||
{
|
||||
PlayRandom();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,28 +13,28 @@
|
|||
|
||||
enum
|
||||
{
|
||||
ONCE = 0, LOOP, RANDOM_BGM, DIR_LOOP
|
||||
ONCE = 0, LOOP, RANDOM_BGM, DIR_LOOP
|
||||
};
|
||||
|
||||
class GuiBGM: public GuiSound
|
||||
{
|
||||
public:
|
||||
GuiBGM(const u8 *s, int l, int v);
|
||||
virtual ~GuiBGM();
|
||||
bool Load(const char *path);
|
||||
bool LoadStandard();
|
||||
bool ParsePath(const char * folderpath);
|
||||
bool PlayNext();
|
||||
bool PlayPrevious();
|
||||
bool PlayRandom();
|
||||
void UpdateState();
|
||||
protected:
|
||||
void AddEntrie(const char * filename);
|
||||
void ClearList();
|
||||
public:
|
||||
GuiBGM(const u8 *s, int l, int v);
|
||||
virtual ~GuiBGM();
|
||||
bool Load(const char *path);
|
||||
bool LoadStandard();
|
||||
bool ParsePath(const char * folderpath);
|
||||
bool PlayNext();
|
||||
bool PlayPrevious();
|
||||
bool PlayRandom();
|
||||
void UpdateState();
|
||||
protected:
|
||||
void AddEntrie(const char * filename);
|
||||
void ClearList();
|
||||
|
||||
int currentPlaying;
|
||||
char * currentPath;
|
||||
std::vector<char *> PlayList;
|
||||
int currentPlaying;
|
||||
char * currentPath;
|
||||
std::vector<char *> PlayList;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -30,61 +30,61 @@
|
|||
#include "SoundHandler.hpp"
|
||||
#include "WavDecoder.hpp"
|
||||
|
||||
#define MAX_SND_VOICES 16
|
||||
#define MAX_SND_VOICES 16
|
||||
|
||||
static bool VoiceUsed[MAX_SND_VOICES] =
|
||||
{
|
||||
true, false, false, false, false, false,
|
||||
false, false, false, false, false, false,
|
||||
false, false, false, false
|
||||
true, false, false, false, false, false,
|
||||
false, false, false, false, false, false,
|
||||
false, false, false, false
|
||||
};
|
||||
|
||||
static inline int GetFirstUnusedVoice()
|
||||
{
|
||||
for(int i = 1; i < MAX_SND_VOICES; i++)
|
||||
{
|
||||
if(VoiceUsed[i] == false)
|
||||
return i;
|
||||
}
|
||||
for(int i = 1; i < MAX_SND_VOICES; i++)
|
||||
{
|
||||
if(VoiceUsed[i] == false)
|
||||
return i;
|
||||
}
|
||||
|
||||
return -1;
|
||||
return -1;
|
||||
}
|
||||
|
||||
extern "C" void SoundCallback(s32 voice)
|
||||
{
|
||||
SoundDecoder * decoder = SoundHandler::Instance()->Decoder(voice);
|
||||
if(!decoder)
|
||||
return;
|
||||
SoundDecoder * decoder = SoundHandler::Instance()->Decoder(voice);
|
||||
if(!decoder)
|
||||
return;
|
||||
|
||||
if(decoder->IsBufferReady())
|
||||
{
|
||||
if(ASND_AddVoice(voice, decoder->GetBuffer(), decoder->GetBufferSize()) == SND_OK)
|
||||
{
|
||||
decoder->LoadNext();
|
||||
SoundHandler::Instance()->ThreadSignal();
|
||||
}
|
||||
}
|
||||
else if(decoder->IsEOF())
|
||||
{
|
||||
ASND_StopVoice(voice);
|
||||
//if(voice == 0)
|
||||
//MusicPlayer::Instance()->SetPlaybackFinished(true); //see if next music must be played
|
||||
}
|
||||
else
|
||||
{
|
||||
SoundHandler::Instance()->ThreadSignal();
|
||||
}
|
||||
if(decoder->IsBufferReady())
|
||||
{
|
||||
if(ASND_AddVoice(voice, decoder->GetBuffer(), decoder->GetBufferSize()) == SND_OK)
|
||||
{
|
||||
decoder->LoadNext();
|
||||
SoundHandler::Instance()->ThreadSignal();
|
||||
}
|
||||
}
|
||||
else if(decoder->IsEOF())
|
||||
{
|
||||
ASND_StopVoice(voice);
|
||||
//if(voice == 0)
|
||||
//MusicPlayer::Instance()->SetPlaybackFinished(true); //see if next music must be played
|
||||
}
|
||||
else
|
||||
{
|
||||
SoundHandler::Instance()->ThreadSignal();
|
||||
}
|
||||
}
|
||||
|
||||
GuiSound::GuiSound(const char * filepath)
|
||||
{
|
||||
sound = NULL;
|
||||
sound = NULL;
|
||||
length = 0;
|
||||
voice = GetFirstUnusedVoice();
|
||||
if(voice > 0)
|
||||
VoiceUsed[voice] = true;
|
||||
voice = GetFirstUnusedVoice();
|
||||
if(voice > 0)
|
||||
VoiceUsed[voice] = true;
|
||||
|
||||
volume = 255;
|
||||
volume = 255;
|
||||
SoundEffectLength = 0;
|
||||
loop = 0;
|
||||
allocated = false;
|
||||
|
@ -93,17 +93,17 @@ GuiSound::GuiSound(const char * filepath)
|
|||
|
||||
GuiSound::GuiSound(const u8 * snd, s32 len, int vol, bool isallocated, int v)
|
||||
{
|
||||
sound = NULL;
|
||||
sound = NULL;
|
||||
length = 0;
|
||||
if(v < 0)
|
||||
voice = GetFirstUnusedVoice();
|
||||
else
|
||||
voice = v;
|
||||
voice = GetFirstUnusedVoice();
|
||||
else
|
||||
voice = v;
|
||||
|
||||
if(voice > 0)
|
||||
VoiceUsed[voice] = true;
|
||||
if(voice > 0)
|
||||
VoiceUsed[voice] = true;
|
||||
|
||||
volume = vol;
|
||||
volume = vol;
|
||||
SoundEffectLength = 0;
|
||||
loop = 0;
|
||||
allocated = false;
|
||||
|
@ -114,173 +114,173 @@ GuiSound::~GuiSound()
|
|||
{
|
||||
FreeMemory();
|
||||
if(voice > 0)
|
||||
VoiceUsed[voice] = false;
|
||||
VoiceUsed[voice] = false;
|
||||
}
|
||||
|
||||
void GuiSound::FreeMemory()
|
||||
{
|
||||
this->Stop();
|
||||
|
||||
SoundHandler::Instance()->RemoveDecoder(voice);
|
||||
SoundHandler::Instance()->RemoveDecoder(voice);
|
||||
|
||||
if(allocated && sound != NULL)
|
||||
{
|
||||
free(sound);
|
||||
sound = NULL;
|
||||
allocated = false;
|
||||
}
|
||||
if(allocated && sound != NULL)
|
||||
{
|
||||
free(sound);
|
||||
sound = NULL;
|
||||
allocated = false;
|
||||
}
|
||||
|
||||
SoundEffectLength = 0;
|
||||
SoundEffectLength = 0;
|
||||
}
|
||||
|
||||
bool GuiSound::Load(const char * filepath)
|
||||
{
|
||||
FreeMemory();
|
||||
FreeMemory();
|
||||
|
||||
if(!filepath)
|
||||
return false;
|
||||
return false;
|
||||
|
||||
u32 magic;
|
||||
FILE * f = fopen(filepath, "rb");
|
||||
if(!f)
|
||||
return false;
|
||||
u32 magic;
|
||||
FILE * f = fopen(filepath, "rb");
|
||||
if(!f)
|
||||
return false;
|
||||
|
||||
fread(&magic, 1, 4, f);
|
||||
fclose(f);
|
||||
fread(&magic, 1, 4, f);
|
||||
fclose(f);
|
||||
|
||||
if(magic == 'IMD5')
|
||||
{
|
||||
u8 * snd = NULL;
|
||||
u64 filesize = 0;
|
||||
LoadFileToMem(filepath, &snd, &filesize);
|
||||
return Load(snd, filesize, true);
|
||||
}
|
||||
if(magic == 'IMD5')
|
||||
{
|
||||
u8 * snd = NULL;
|
||||
u64 filesize = 0;
|
||||
LoadFileToMem(filepath, &snd, &filesize);
|
||||
return Load(snd, filesize, true);
|
||||
}
|
||||
|
||||
SoundHandler::Instance()->AddDecoder(voice, filepath);
|
||||
SoundHandler::Instance()->AddDecoder(voice, filepath);
|
||||
|
||||
SoundDecoder * decoder = SoundHandler::Instance()->Decoder(voice);
|
||||
if(!decoder)
|
||||
return false;
|
||||
SoundDecoder * decoder = SoundHandler::Instance()->Decoder(voice);
|
||||
if(!decoder)
|
||||
return false;
|
||||
|
||||
if(!decoder->IsBufferReady())
|
||||
{
|
||||
SoundHandler::Instance()->RemoveDecoder(voice);
|
||||
return false;
|
||||
}
|
||||
if(!decoder->IsBufferReady())
|
||||
{
|
||||
SoundHandler::Instance()->RemoveDecoder(voice);
|
||||
return false;
|
||||
}
|
||||
|
||||
SetLoop(loop);
|
||||
SetLoop(loop);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool GuiSound::Load(const u8 * snd, s32 len, bool isallocated)
|
||||
{
|
||||
FreeMemory();
|
||||
FreeMemory();
|
||||
|
||||
if(!snd)
|
||||
return false;
|
||||
if(!snd)
|
||||
return false;
|
||||
|
||||
if(!isallocated && *((u32 *) snd) == 'RIFF')
|
||||
{
|
||||
return LoadSoundEffect(snd, len);
|
||||
}
|
||||
if(!isallocated && *((u32 *) snd) == 'RIFF')
|
||||
{
|
||||
return LoadSoundEffect(snd, len);
|
||||
}
|
||||
|
||||
if(*((u32 *) snd) == 'IMD5')
|
||||
{
|
||||
UncompressSoundbin(snd, len, isallocated);
|
||||
}
|
||||
else
|
||||
{
|
||||
sound = (u8 *) snd;
|
||||
length = len;
|
||||
allocated = isallocated;
|
||||
}
|
||||
if(*((u32 *) snd) == 'IMD5')
|
||||
{
|
||||
UncompressSoundbin(snd, len, isallocated);
|
||||
}
|
||||
else
|
||||
{
|
||||
sound = (u8 *) snd;
|
||||
length = len;
|
||||
allocated = isallocated;
|
||||
}
|
||||
|
||||
SoundHandler::Instance()->AddDecoder(voice, sound, length);
|
||||
SoundHandler::Instance()->AddDecoder(voice, sound, length);
|
||||
|
||||
SoundDecoder * decoder = SoundHandler::Instance()->Decoder(voice);
|
||||
if(!decoder)
|
||||
return false;
|
||||
SoundDecoder * decoder = SoundHandler::Instance()->Decoder(voice);
|
||||
if(!decoder)
|
||||
return false;
|
||||
|
||||
if(!decoder->IsBufferReady())
|
||||
{
|
||||
SoundHandler::Instance()->RemoveDecoder(voice);
|
||||
return false;
|
||||
}
|
||||
if(!decoder->IsBufferReady())
|
||||
{
|
||||
SoundHandler::Instance()->RemoveDecoder(voice);
|
||||
return false;
|
||||
}
|
||||
|
||||
SetLoop(loop);
|
||||
SetLoop(loop);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool GuiSound::LoadSoundEffect(const u8 * snd, s32 len)
|
||||
{
|
||||
WavDecoder decoder(snd, len);
|
||||
decoder.Rewind();
|
||||
WavDecoder decoder(snd, len);
|
||||
decoder.Rewind();
|
||||
|
||||
u32 done = 0;
|
||||
sound = (u8 *) malloc(4096);
|
||||
memset(sound, 0, 4096);
|
||||
u32 done = 0;
|
||||
sound = (u8 *) malloc(4096);
|
||||
memset(sound, 0, 4096);
|
||||
|
||||
while(1)
|
||||
{
|
||||
u8 * tmpsnd = (u8 *) realloc(sound, done+4096);
|
||||
if(!tmpsnd)
|
||||
{
|
||||
free(sound);
|
||||
sound = NULL;
|
||||
return false;
|
||||
}
|
||||
while(1)
|
||||
{
|
||||
u8 * tmpsnd = (u8 *) realloc(sound, done+4096);
|
||||
if(!tmpsnd)
|
||||
{
|
||||
free(sound);
|
||||
sound = NULL;
|
||||
return false;
|
||||
}
|
||||
|
||||
sound = tmpsnd;
|
||||
sound = tmpsnd;
|
||||
|
||||
int read = decoder.Read(sound+done, 4096, done);
|
||||
if(read <= 0)
|
||||
break;
|
||||
int read = decoder.Read(sound+done, 4096, done);
|
||||
if(read <= 0)
|
||||
break;
|
||||
|
||||
done += read;
|
||||
}
|
||||
done += read;
|
||||
}
|
||||
|
||||
sound = (u8 *) realloc(sound, done);
|
||||
SoundEffectLength = done;
|
||||
allocated = true;
|
||||
sound = (u8 *) realloc(sound, done);
|
||||
SoundEffectLength = done;
|
||||
allocated = true;
|
||||
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
void GuiSound::Play()
|
||||
{
|
||||
if(SoundEffectLength > 0)
|
||||
{
|
||||
ASND_StopVoice(voice);
|
||||
ASND_SetVoice(voice, VOICE_STEREO_16BIT, 32000, 0, sound, SoundEffectLength, volume, volume, NULL);
|
||||
return;
|
||||
}
|
||||
if(SoundEffectLength > 0)
|
||||
{
|
||||
ASND_StopVoice(voice);
|
||||
ASND_SetVoice(voice, VOICE_STEREO_16BIT, 32000, 0, sound, SoundEffectLength, volume, volume, NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
if(IsPlaying())
|
||||
return;
|
||||
if(IsPlaying())
|
||||
return;
|
||||
|
||||
if(voice < 0 || voice >= 16)
|
||||
return;
|
||||
|
||||
SoundDecoder * decoder = SoundHandler::Instance()->Decoder(voice);
|
||||
if(!decoder)
|
||||
return;
|
||||
SoundDecoder * decoder = SoundHandler::Instance()->Decoder(voice);
|
||||
if(!decoder)
|
||||
return;
|
||||
|
||||
if(decoder->IsEOF())
|
||||
{
|
||||
ASND_StopVoice(voice);
|
||||
decoder->ClearBuffer();
|
||||
decoder->Rewind();
|
||||
decoder->Decode();
|
||||
}
|
||||
if(decoder->IsEOF())
|
||||
{
|
||||
ASND_StopVoice(voice);
|
||||
decoder->ClearBuffer();
|
||||
decoder->Rewind();
|
||||
decoder->Decode();
|
||||
}
|
||||
|
||||
u8 * curbuffer = decoder->GetBuffer();
|
||||
int bufsize = decoder->GetBufferSize();
|
||||
decoder->LoadNext();
|
||||
SoundHandler::Instance()->ThreadSignal();
|
||||
u8 * curbuffer = decoder->GetBuffer();
|
||||
int bufsize = decoder->GetBufferSize();
|
||||
decoder->LoadNext();
|
||||
SoundHandler::Instance()->ThreadSignal();
|
||||
|
||||
ASND_SetVoice(voice, decoder->GetFormat(), decoder->GetSampleRate(), 0, curbuffer, bufsize, volume, volume, SoundCallback);
|
||||
ASND_SetVoice(voice, decoder->GetFormat(), decoder->GetSampleRate(), 0, curbuffer, bufsize, volume, volume, SoundCallback);
|
||||
}
|
||||
|
||||
void GuiSound::Stop()
|
||||
|
@ -290,13 +290,13 @@ void GuiSound::Stop()
|
|||
|
||||
ASND_StopVoice(voice);
|
||||
|
||||
SoundDecoder * decoder = SoundHandler::Instance()->Decoder(voice);
|
||||
if(!decoder)
|
||||
return;
|
||||
SoundDecoder * decoder = SoundHandler::Instance()->Decoder(voice);
|
||||
if(!decoder)
|
||||
return;
|
||||
|
||||
decoder->ClearBuffer();
|
||||
Rewind();
|
||||
SoundHandler::Instance()->ThreadSignal();
|
||||
decoder->ClearBuffer();
|
||||
Rewind();
|
||||
SoundHandler::Instance()->ThreadSignal();
|
||||
}
|
||||
|
||||
void GuiSound::Pause()
|
||||
|
@ -304,12 +304,12 @@ void GuiSound::Pause()
|
|||
if(voice < 0 || voice >= 16)
|
||||
return;
|
||||
|
||||
ASND_StopVoice(voice);
|
||||
ASND_StopVoice(voice);
|
||||
}
|
||||
|
||||
void GuiSound::Resume()
|
||||
{
|
||||
Play();
|
||||
Play();
|
||||
}
|
||||
|
||||
bool GuiSound::IsPlaying()
|
||||
|
@ -317,7 +317,7 @@ bool GuiSound::IsPlaying()
|
|||
if(voice < 0 || voice >= 16)
|
||||
return false;
|
||||
|
||||
int result = ASND_StatusVoice(voice);
|
||||
int result = ASND_StatusVoice(voice);
|
||||
|
||||
if(result == SND_WORKING || result == SND_WAITING)
|
||||
return true;
|
||||
|
@ -333,48 +333,48 @@ void GuiSound::SetVolume(int vol)
|
|||
if(vol < 0)
|
||||
return;
|
||||
|
||||
volume = 255*(vol/100.0);
|
||||
ASND_ChangeVolumeVoice(voice, volume, volume);
|
||||
volume = 255*(vol/100.0);
|
||||
ASND_ChangeVolumeVoice(voice, volume, volume);
|
||||
}
|
||||
|
||||
void GuiSound::SetLoop(u8 l)
|
||||
{
|
||||
loop = l;
|
||||
|
||||
SoundDecoder * decoder = SoundHandler::Instance()->Decoder(voice);
|
||||
if(!decoder)
|
||||
return;
|
||||
SoundDecoder * decoder = SoundHandler::Instance()->Decoder(voice);
|
||||
if(!decoder)
|
||||
return;
|
||||
|
||||
decoder->SetLoop(l == 1);
|
||||
decoder->SetLoop(l == 1);
|
||||
}
|
||||
|
||||
void GuiSound::Rewind()
|
||||
{
|
||||
SoundDecoder * decoder = SoundHandler::Instance()->Decoder(voice);
|
||||
if(!decoder)
|
||||
return;
|
||||
SoundDecoder * decoder = SoundHandler::Instance()->Decoder(voice);
|
||||
if(!decoder)
|
||||
return;
|
||||
|
||||
decoder->Rewind();
|
||||
decoder->Rewind();
|
||||
}
|
||||
|
||||
void GuiSound::UncompressSoundbin(const u8 * snd, int len, bool isallocated)
|
||||
{
|
||||
const u8 * file = snd+32;
|
||||
if(*((u32 *) file) == 'LZ77')
|
||||
{
|
||||
u32 size = 0;
|
||||
sound = uncompressLZ77(file, len-32, &size);
|
||||
length = size;
|
||||
}
|
||||
else
|
||||
{
|
||||
length = len-32;
|
||||
sound = (u8 *) malloc(length);
|
||||
memcpy(sound, file, length);
|
||||
}
|
||||
const u8 * file = snd+32;
|
||||
if(*((u32 *) file) == 'LZ77')
|
||||
{
|
||||
u32 size = 0;
|
||||
sound = uncompressLZ77(file, len-32, &size);
|
||||
length = size;
|
||||
}
|
||||
else
|
||||
{
|
||||
length = len-32;
|
||||
sound = (u8 *) malloc(length);
|
||||
memcpy(sound, file, length);
|
||||
}
|
||||
|
||||
if(isallocated)
|
||||
free((u8 *) snd);
|
||||
if(isallocated)
|
||||
free((u8 *) snd);
|
||||
|
||||
allocated = true;
|
||||
allocated = true;
|
||||
}
|
||||
|
|
|
@ -35,7 +35,7 @@ class GuiSound
|
|||
//!Constructor
|
||||
//!\param sound Pointer to the sound data
|
||||
//!\param filesize Length of sound data
|
||||
GuiSound(const char * filepath);
|
||||
GuiSound(const char * filepath);
|
||||
GuiSound(const u8 * sound, int filesize, int volume, bool allocated = false, int voice = -1);
|
||||
//!Destructor
|
||||
virtual ~GuiSound();
|
||||
|
@ -64,10 +64,10 @@ class GuiSound
|
|||
//!\param l Loop (true to loop)
|
||||
virtual void SetLoop(u8 l);
|
||||
//!Special sound case for sound.bin
|
||||
void UncompressSoundbin(const u8 * snd, int len, bool isallocated);
|
||||
void UncompressSoundbin(const u8 * snd, int len, bool isallocated);
|
||||
protected:
|
||||
//!Stops sound and frees all memory/closes files
|
||||
void FreeMemory();
|
||||
//!Stops sound and frees all memory/closes files
|
||||
void FreeMemory();
|
||||
u8 * sound; //!< Pointer to the sound data
|
||||
int length; //!< Length of sound data
|
||||
s32 voice; //!< Currently assigned ASND voice channel
|
||||
|
|
|
@ -23,84 +23,84 @@
|
|||
|
||||
StartUpProcess::StartUpProcess()
|
||||
{
|
||||
//! Load default font for the next text outputs
|
||||
Theme::LoadFont("");
|
||||
//! Load default font for the next text outputs
|
||||
Theme::LoadFont("");
|
||||
|
||||
background = new GuiImage(screenwidth, screenheight, (GXColor) {0, 0, 0, 255});
|
||||
background = new GuiImage(screenwidth, screenheight, (GXColor) {0, 0, 0, 255});
|
||||
|
||||
GXImageData = Resources::GetImageData("gxlogo.png");
|
||||
GXImage = new GuiImage(GXImageData);
|
||||
GXImage->SetAlignment(ALIGN_CENTER, ALIGN_MIDDLE);
|
||||
GXImage->SetPosition(screenwidth/2, screenheight/2-50);
|
||||
GXImageData = Resources::GetImageData("gxlogo.png");
|
||||
GXImage = new GuiImage(GXImageData);
|
||||
GXImage->SetAlignment(ALIGN_CENTER, ALIGN_MIDDLE);
|
||||
GXImage->SetPosition(screenwidth/2, screenheight/2-50);
|
||||
|
||||
titleTxt = new GuiText("Loading...", 24, (GXColor) {255, 255, 255, 255});
|
||||
titleTxt->SetAlignment(ALIGN_CENTER, ALIGN_MIDDLE);
|
||||
titleTxt->SetPosition(screenwidth/2, screenheight/2+30);
|
||||
titleTxt = new GuiText("Loading...", 24, (GXColor) {255, 255, 255, 255});
|
||||
titleTxt->SetAlignment(ALIGN_CENTER, ALIGN_MIDDLE);
|
||||
titleTxt->SetPosition(screenwidth/2, screenheight/2+30);
|
||||
|
||||
messageTxt = new GuiText(" ", 22, (GXColor) {255, 255, 255, 255});
|
||||
messageTxt->SetAlignment(ALIGN_CENTER, ALIGN_MIDDLE);
|
||||
messageTxt->SetPosition(screenwidth/2, screenheight/2+60);
|
||||
messageTxt = new GuiText(" ", 22, (GXColor) {255, 255, 255, 255});
|
||||
messageTxt->SetAlignment(ALIGN_CENTER, ALIGN_MIDDLE);
|
||||
messageTxt->SetPosition(screenwidth/2, screenheight/2+60);
|
||||
}
|
||||
|
||||
StartUpProcess::~StartUpProcess()
|
||||
{
|
||||
delete background;
|
||||
delete GXImageData;
|
||||
delete GXImage;
|
||||
delete titleTxt;
|
||||
delete messageTxt;
|
||||
delete background;
|
||||
delete GXImageData;
|
||||
delete GXImage;
|
||||
delete titleTxt;
|
||||
delete messageTxt;
|
||||
}
|
||||
|
||||
int StartUpProcess::ParseArguments(int argc, char *argv[])
|
||||
{
|
||||
int quickBoot = -1;
|
||||
int quickBoot = -1;
|
||||
|
||||
//! The arguments override
|
||||
for(int i = 0; i < argc; ++i)
|
||||
{
|
||||
if(!argv[i]) continue;
|
||||
//! The arguments override
|
||||
for(int i = 0; i < argc; ++i)
|
||||
{
|
||||
if(!argv[i]) continue;
|
||||
|
||||
gprintf("Boot argument %i: %s\n", i+1, argv[i]);
|
||||
gprintf("Boot argument %i: %s\n", i+1, argv[i]);
|
||||
|
||||
char *ptr = strcasestr(argv[i], "-ios=");
|
||||
if(ptr)
|
||||
Settings.cios = LIMIT(atoi(ptr+strlen("-ios=")), 200, 255);
|
||||
char *ptr = strcasestr(argv[i], "-ios=");
|
||||
if(ptr)
|
||||
Settings.cios = LIMIT(atoi(ptr+strlen("-ios=")), 200, 255);
|
||||
|
||||
ptr = strcasestr(argv[i], "-usbport=");
|
||||
if(ptr)
|
||||
{
|
||||
Settings.USBPort = LIMIT(atoi(ptr+strlen("-usbport=")), 0, 2);
|
||||
}
|
||||
ptr = strcasestr(argv[i], "-usbport=");
|
||||
if(ptr)
|
||||
{
|
||||
Settings.USBPort = LIMIT(atoi(ptr+strlen("-usbport=")), 0, 2);
|
||||
}
|
||||
|
||||
if(strlen(argv[i]) == 6 && strchr(argv[i], '=') == 0 && strchr(argv[i], '-') == 0)
|
||||
quickBoot = i;
|
||||
}
|
||||
if(strlen(argv[i]) == 6 && strchr(argv[i], '=') == 0 && strchr(argv[i], '-') == 0)
|
||||
quickBoot = i;
|
||||
}
|
||||
|
||||
return quickBoot;
|
||||
return quickBoot;
|
||||
}
|
||||
|
||||
void StartUpProcess::TextFade(int direction)
|
||||
{
|
||||
if(direction > 0)
|
||||
{
|
||||
for(int i = 0; i < 255; i += direction)
|
||||
{
|
||||
messageTxt->SetAlpha(i);
|
||||
Draw();
|
||||
}
|
||||
messageTxt->SetAlpha(255);
|
||||
Draw();
|
||||
}
|
||||
else if(direction < 0)
|
||||
{
|
||||
for(int i = 255; i > 0; i += direction)
|
||||
{
|
||||
messageTxt->SetAlpha(i);
|
||||
Draw();
|
||||
}
|
||||
messageTxt->SetAlpha(0);
|
||||
Draw();
|
||||
}
|
||||
if(direction > 0)
|
||||
{
|
||||
for(int i = 0; i < 255; i += direction)
|
||||
{
|
||||
messageTxt->SetAlpha(i);
|
||||
Draw();
|
||||
}
|
||||
messageTxt->SetAlpha(255);
|
||||
Draw();
|
||||
}
|
||||
else if(direction < 0)
|
||||
{
|
||||
for(int i = 255; i > 0; i += direction)
|
||||
{
|
||||
messageTxt->SetAlpha(i);
|
||||
Draw();
|
||||
}
|
||||
messageTxt->SetAlpha(0);
|
||||
Draw();
|
||||
}
|
||||
}
|
||||
|
||||
void StartUpProcess::SetTextf(const char * format, ...)
|
||||
|
@ -109,150 +109,150 @@ void StartUpProcess::SetTextf(const char * format, ...)
|
|||
va_list va;
|
||||
va_start(va, format);
|
||||
if((vasprintf(&tmp, format, va) >= 0) && tmp)
|
||||
{
|
||||
TextFade(-40);
|
||||
gprintf(tmp);
|
||||
messageTxt->SetText(tmp);
|
||||
TextFade(40);
|
||||
{
|
||||
TextFade(-40);
|
||||
gprintf(tmp);
|
||||
messageTxt->SetText(tmp);
|
||||
TextFade(40);
|
||||
}
|
||||
va_end(va);
|
||||
|
||||
if(tmp)
|
||||
free(tmp);
|
||||
free(tmp);
|
||||
}
|
||||
|
||||
bool StartUpProcess::USBSpinUp()
|
||||
{
|
||||
bool started = false;
|
||||
const DISC_INTERFACE * handle = Settings.USBPort == 1 ? DeviceHandler::GetUSB1Interface() : DeviceHandler::GetUSB0Interface();
|
||||
Timer countDown;
|
||||
// wait 10 sec for the USB to spin up...stupid slow ass HDD
|
||||
do
|
||||
{
|
||||
started = (handle->startup() && handle->isInserted());
|
||||
if(started)
|
||||
break;
|
||||
bool started = false;
|
||||
const DISC_INTERFACE * handle = Settings.USBPort == 1 ? DeviceHandler::GetUSB1Interface() : DeviceHandler::GetUSB0Interface();
|
||||
Timer countDown;
|
||||
// wait 10 sec for the USB to spin up...stupid slow ass HDD
|
||||
do
|
||||
{
|
||||
started = (handle->startup() && handle->isInserted());
|
||||
if(started)
|
||||
break;
|
||||
|
||||
messageTxt->SetTextf("Waiting for HDD: %i sec left\n", 20-(int)countDown.elapsed());
|
||||
Draw();
|
||||
usleep(50000);
|
||||
}
|
||||
while(countDown.elapsed() < 20.f);
|
||||
messageTxt->SetTextf("Waiting for HDD: %i sec left\n", 20-(int)countDown.elapsed());
|
||||
Draw();
|
||||
usleep(50000);
|
||||
}
|
||||
while(countDown.elapsed() < 20.f);
|
||||
|
||||
return started;
|
||||
return started;
|
||||
}
|
||||
|
||||
int StartUpProcess::Run(int argc, char *argv[])
|
||||
{
|
||||
int quickGameBoot = ParseArguments(argc, argv);
|
||||
int quickGameBoot = ParseArguments(argc, argv);
|
||||
|
||||
StartUpProcess Process;
|
||||
StartUpProcess Process;
|
||||
|
||||
int ret = Process.Execute();
|
||||
int ret = Process.Execute();
|
||||
|
||||
if(quickGameBoot != -1)
|
||||
return QuickGameBoot(argv[quickGameBoot]);
|
||||
if(quickGameBoot != -1)
|
||||
return QuickGameBoot(argv[quickGameBoot]);
|
||||
|
||||
return ret;
|
||||
return ret;
|
||||
}
|
||||
|
||||
int StartUpProcess::Execute()
|
||||
{
|
||||
Settings.EntryIOS = IOS_GetVersion();
|
||||
SetTextf("Start up\n");
|
||||
SetTextf("Start up\n");
|
||||
|
||||
if(IosLoader::LoadAppCios() < 0)
|
||||
{
|
||||
SetTextf("Failed loading any cIOS. USB Loader GX requires at least cIOS 222 or 245-250. Exiting...\n");
|
||||
sleep(5);
|
||||
Sys_BackToLoader();
|
||||
}
|
||||
if(IosLoader::LoadAppCios() < 0)
|
||||
{
|
||||
SetTextf("Failed loading any cIOS. USB Loader GX requires at least cIOS 222 or 245-250. Exiting...\n");
|
||||
sleep(5);
|
||||
Sys_BackToLoader();
|
||||
}
|
||||
|
||||
SetTextf("Initialize sd card\n");
|
||||
DeviceHandler::Instance()->MountSD();
|
||||
SetTextf("Initialize sd card\n");
|
||||
DeviceHandler::Instance()->MountSD();
|
||||
|
||||
SetTextf("Initialize usb device\n");
|
||||
USBSpinUp();
|
||||
DeviceHandler::Instance()->MountAllUSB(false);
|
||||
SetTextf("Initialize usb device\n");
|
||||
USBSpinUp();
|
||||
DeviceHandler::Instance()->MountAllUSB(false);
|
||||
|
||||
SetTextf("Loading config files");
|
||||
gprintf("\tLoading config...%s\n", Settings.Load() ? "done" : "failed");
|
||||
gprintf("\tLoading language...%s\n", Settings.LoadLanguage(Settings.language_path, CONSOLE_DEFAULT) ? "done" : "failed");
|
||||
gprintf("\tLoading game settings...%s\n", GameSettings.Load(Settings.ConfigPath) ? "done" : "failed");
|
||||
gprintf("\tLoading game statistics...%s\n", GameStatistics.Load(Settings.ConfigPath) ? "done" : "failed");
|
||||
SetTextf("Loading config files");
|
||||
gprintf("\tLoading config...%s\n", Settings.Load() ? "done" : "failed");
|
||||
gprintf("\tLoading language...%s\n", Settings.LoadLanguage(Settings.language_path, CONSOLE_DEFAULT) ? "done" : "failed");
|
||||
gprintf("\tLoading game settings...%s\n", GameSettings.Load(Settings.ConfigPath) ? "done" : "failed");
|
||||
gprintf("\tLoading game statistics...%s\n", GameStatistics.Load(Settings.ConfigPath) ? "done" : "failed");
|
||||
|
||||
if(Settings.cios != IOS_GetVersion())
|
||||
{
|
||||
SetTextf("Loading cIOS %i\n", Settings.cios);
|
||||
if(Settings.cios != IOS_GetVersion())
|
||||
{
|
||||
SetTextf("Loading cIOS %i\n", Settings.cios);
|
||||
|
||||
DeviceHandler::DestroyInstance();
|
||||
USBStorage2_Deinit();
|
||||
DeviceHandler::DestroyInstance();
|
||||
USBStorage2_Deinit();
|
||||
|
||||
// Loading now the cios setup in the settings
|
||||
IosLoader::LoadAppCios();
|
||||
// Loading now the cios setup in the settings
|
||||
IosLoader::LoadAppCios();
|
||||
|
||||
SetTextf("Reloading into cIOS %i R%i\n", IOS_GetVersion(), IOS_GetRevision());
|
||||
SetTextf("Reloading into cIOS %i R%i\n", IOS_GetVersion(), IOS_GetRevision());
|
||||
|
||||
DeviceHandler::Instance()->MountSD();
|
||||
USBSpinUp();
|
||||
DeviceHandler::Instance()->MountAllUSB(false);
|
||||
}
|
||||
DeviceHandler::Instance()->MountSD();
|
||||
USBSpinUp();
|
||||
DeviceHandler::Instance()->MountAllUSB(false);
|
||||
}
|
||||
|
||||
if(!IosLoader::IsHermesIOS())
|
||||
{
|
||||
Settings.USBPort = 0;
|
||||
}
|
||||
else if(Settings.USBPort == 1 && USBStorage2_GetPort() != Settings.USBPort)
|
||||
{
|
||||
SetTextf("Changing USB Port to %i\n", Settings.USBPort);
|
||||
DeviceHandler::Instance()->UnMountAllUSB();
|
||||
DeviceHandler::Instance()->MountAllUSB();
|
||||
}
|
||||
else if(Settings.USBPort == 2)
|
||||
{
|
||||
SetTextf("Mounting USB Port to 1\n");
|
||||
DeviceHandler::Instance()->MountUSBPort1();
|
||||
}
|
||||
if(!IosLoader::IsHermesIOS())
|
||||
{
|
||||
Settings.USBPort = 0;
|
||||
}
|
||||
else if(Settings.USBPort == 1 && USBStorage2_GetPort() != Settings.USBPort)
|
||||
{
|
||||
SetTextf("Changing USB Port to %i\n", Settings.USBPort);
|
||||
DeviceHandler::Instance()->UnMountAllUSB();
|
||||
DeviceHandler::Instance()->MountAllUSB();
|
||||
}
|
||||
else if(Settings.USBPort == 2)
|
||||
{
|
||||
SetTextf("Mounting USB Port to 1\n");
|
||||
DeviceHandler::Instance()->MountUSBPort1();
|
||||
}
|
||||
|
||||
gprintf("\tLoading game categories...%s\n", GameCategories.Load(Settings.ConfigPath) ? "done" : "failed");
|
||||
gprintf("\tLoading font...%s\n", Theme::LoadFont(Settings.ConfigPath) ? "done" : "failed (using default)");
|
||||
gprintf("\tLoading theme...%s\n", Theme::Load(Settings.theme) ? "done" : "failed (using default)");
|
||||
gprintf("\tLoading game categories...%s\n", GameCategories.Load(Settings.ConfigPath) ? "done" : "failed");
|
||||
gprintf("\tLoading font...%s\n", Theme::LoadFont(Settings.ConfigPath) ? "done" : "failed (using default)");
|
||||
gprintf("\tLoading theme...%s\n", Theme::Load(Settings.theme) ? "done" : "failed (using default)");
|
||||
|
||||
//! Init the rest of the System
|
||||
Sys_Init();
|
||||
SetupPads();
|
||||
InitAudio();
|
||||
setlocale(LC_CTYPE, "C-UTF-8");
|
||||
setlocale(LC_MESSAGES, "C-UTF-8");
|
||||
//! Init the rest of the System
|
||||
Sys_Init();
|
||||
SetupPads();
|
||||
InitAudio();
|
||||
setlocale(LC_CTYPE, "C-UTF-8");
|
||||
setlocale(LC_MESSAGES, "C-UTF-8");
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void StartUpProcess::Draw()
|
||||
{
|
||||
background->Draw();
|
||||
GXImage->Draw();
|
||||
titleTxt->Draw();
|
||||
messageTxt->Draw();
|
||||
Menu_Render();
|
||||
background->Draw();
|
||||
GXImage->Draw();
|
||||
titleTxt->Draw();
|
||||
messageTxt->Draw();
|
||||
Menu_Render();
|
||||
}
|
||||
|
||||
int StartUpProcess::QuickGameBoot(const char * gameID)
|
||||
{
|
||||
MountGamePartition(false);
|
||||
MountGamePartition(false);
|
||||
|
||||
struct discHdr *header = NULL;
|
||||
for(int i = 0; i < gameList.size(); ++i)
|
||||
{
|
||||
if(strncasecmp((char *) gameList[i]->id, gameID, 6) == 0)
|
||||
header = gameList[i];
|
||||
}
|
||||
struct discHdr *header = NULL;
|
||||
for(int i = 0; i < gameList.size(); ++i)
|
||||
{
|
||||
if(strncasecmp((char *) gameList[i]->id, gameID, 6) == 0)
|
||||
header = gameList[i];
|
||||
}
|
||||
|
||||
if(!header)
|
||||
return -1;
|
||||
if(!header)
|
||||
return -1;
|
||||
|
||||
GameStatistics.SetPlayCount(header->id, GameStatistics.GetPlayCount(header->id)+1);
|
||||
GameStatistics.Save();
|
||||
GameStatistics.SetPlayCount(header->id, GameStatistics.GetPlayCount(header->id)+1);
|
||||
GameStatistics.Save();
|
||||
|
||||
return GameBooter::BootGame(gameID);
|
||||
return GameBooter::BootGame(gameID);
|
||||
}
|
||||
|
|
|
@ -5,24 +5,24 @@
|
|||
|
||||
class StartUpProcess
|
||||
{
|
||||
public:
|
||||
static int Run(int argc, char *argv[]);
|
||||
private:
|
||||
StartUpProcess();
|
||||
~StartUpProcess();
|
||||
int Execute();
|
||||
bool USBSpinUp();
|
||||
void TextFade(int direction);
|
||||
void SetTextf(const char * format, ...);
|
||||
void Draw();
|
||||
static int ParseArguments(int argc, char *argv[]);
|
||||
static int QuickGameBoot(const char * gameID);
|
||||
public:
|
||||
static int Run(int argc, char *argv[]);
|
||||
private:
|
||||
StartUpProcess();
|
||||
~StartUpProcess();
|
||||
int Execute();
|
||||
bool USBSpinUp();
|
||||
void TextFade(int direction);
|
||||
void SetTextf(const char * format, ...);
|
||||
void Draw();
|
||||
static int ParseArguments(int argc, char *argv[]);
|
||||
static int QuickGameBoot(const char * gameID);
|
||||
|
||||
GuiImageData * GXImageData;
|
||||
GuiImage * background;
|
||||
GuiImage * GXImage;
|
||||
GuiText * titleTxt;
|
||||
GuiText * messageTxt;
|
||||
GuiImageData * GXImageData;
|
||||
GuiImage * background;
|
||||
GuiImage * GXImage;
|
||||
GuiText * titleTxt;
|
||||
GuiText * messageTxt;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -41,144 +41,144 @@
|
|||
|
||||
ZipFile::ZipFile(const char *filepath)
|
||||
{
|
||||
File = unzOpen(filepath);
|
||||
if (File) this->LoadList();
|
||||
File = unzOpen(filepath);
|
||||
if (File) this->LoadList();
|
||||
}
|
||||
|
||||
ZipFile::~ZipFile()
|
||||
{
|
||||
unzClose(File);
|
||||
unzClose(File);
|
||||
}
|
||||
|
||||
bool ZipFile::LoadList()
|
||||
{
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ZipFile::FindFile(const char *file)
|
||||
{
|
||||
if (!File) return false;
|
||||
if (!File) return false;
|
||||
|
||||
char filename[MAXPATHLEN];
|
||||
char filename[MAXPATHLEN];
|
||||
|
||||
int ret = unzGoToFirstFile(File);
|
||||
if (ret != UNZ_OK) return false;
|
||||
int ret = unzGoToFirstFile(File);
|
||||
if (ret != UNZ_OK) return false;
|
||||
|
||||
do
|
||||
{
|
||||
if(unzGetCurrentFileInfo(File, &cur_file_info, filename, sizeof(filename), NULL, 0, NULL, 0) != UNZ_OK)
|
||||
continue;
|
||||
do
|
||||
{
|
||||
if(unzGetCurrentFileInfo(File, &cur_file_info, filename, sizeof(filename), NULL, 0, NULL, 0) != UNZ_OK)
|
||||
continue;
|
||||
|
||||
const char *realfilename = strrchr(filename, '/');
|
||||
if(!realfilename || strlen(realfilename) == 0)
|
||||
realfilename = filename;
|
||||
const char *realfilename = strrchr(filename, '/');
|
||||
if(!realfilename || strlen(realfilename) == 0)
|
||||
realfilename = filename;
|
||||
|
||||
if(strcasecmp(realfilename, file) == 0)
|
||||
return true;
|
||||
}
|
||||
while(unzGoToNextFile(File) == UNZ_OK);
|
||||
if(strcasecmp(realfilename, file) == 0)
|
||||
return true;
|
||||
}
|
||||
while(unzGoToNextFile(File) == UNZ_OK);
|
||||
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ZipFile::FindFilePart(const char *partfilename, std::string &realname)
|
||||
{
|
||||
if (!File) return false;
|
||||
if (!File) return false;
|
||||
|
||||
char filename[MAXPATHLEN];
|
||||
char filename[MAXPATHLEN];
|
||||
|
||||
int ret = unzGoToFirstFile(File);
|
||||
if (ret != UNZ_OK) return false;
|
||||
int ret = unzGoToFirstFile(File);
|
||||
if (ret != UNZ_OK) return false;
|
||||
|
||||
do
|
||||
{
|
||||
if(unzGetCurrentFileInfo(File, &cur_file_info, filename, sizeof(filename), NULL, 0, NULL, 0) != UNZ_OK)
|
||||
continue;
|
||||
do
|
||||
{
|
||||
if(unzGetCurrentFileInfo(File, &cur_file_info, filename, sizeof(filename), NULL, 0, NULL, 0) != UNZ_OK)
|
||||
continue;
|
||||
|
||||
if(strcasestr(filename, partfilename) != 0)
|
||||
{
|
||||
realname = filename;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
while(unzGoToNextFile(File) == UNZ_OK);
|
||||
if(strcasestr(filename, partfilename) != 0)
|
||||
{
|
||||
realname = filename;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
while(unzGoToNextFile(File) == UNZ_OK);
|
||||
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ZipFile::ExtractAll(const char *dest)
|
||||
{
|
||||
if (!File) return false;
|
||||
if (!File) return false;
|
||||
|
||||
bool Stop = false;
|
||||
bool Stop = false;
|
||||
|
||||
u32 blocksize = 1024 * 50;
|
||||
u8 *buffer = new u8[blocksize];
|
||||
u32 blocksize = 1024 * 50;
|
||||
u8 *buffer = new u8[blocksize];
|
||||
|
||||
if (!buffer) return false;
|
||||
if (!buffer) return false;
|
||||
|
||||
char writepath[MAXPATHLEN];
|
||||
char filename[MAXPATHLEN];
|
||||
memset(filename, 0, sizeof(filename));
|
||||
char writepath[MAXPATHLEN];
|
||||
char filename[MAXPATHLEN];
|
||||
memset(filename, 0, sizeof(filename));
|
||||
|
||||
int ret = unzGoToFirstFile(File);
|
||||
if (ret != UNZ_OK) Stop = true;
|
||||
int ret = unzGoToFirstFile(File);
|
||||
if (ret != UNZ_OK) Stop = true;
|
||||
|
||||
while (!Stop)
|
||||
{
|
||||
if (unzGetCurrentFileInfo(File, &cur_file_info, filename, sizeof(filename), NULL, 0, NULL, 0) != UNZ_OK) Stop
|
||||
= true;
|
||||
while (!Stop)
|
||||
{
|
||||
if (unzGetCurrentFileInfo(File, &cur_file_info, filename, sizeof(filename), NULL, 0, NULL, 0) != UNZ_OK) Stop
|
||||
= true;
|
||||
|
||||
if (!Stop && filename[strlen(filename) - 1] != '/')
|
||||
{
|
||||
u32 uncompressed_size = cur_file_info.uncompressed_size;
|
||||
if (!Stop && filename[strlen(filename) - 1] != '/')
|
||||
{
|
||||
u32 uncompressed_size = cur_file_info.uncompressed_size;
|
||||
|
||||
u32 done = 0;
|
||||
char *pointer = NULL;
|
||||
u32 done = 0;
|
||||
char *pointer = NULL;
|
||||
|
||||
ret = unzOpenCurrentFile(File);
|
||||
ret = unzOpenCurrentFile(File);
|
||||
|
||||
snprintf(writepath, sizeof(writepath), "%s/%s", dest, filename);
|
||||
snprintf(writepath, sizeof(writepath), "%s/%s", dest, filename);
|
||||
|
||||
pointer = strrchr(writepath, '/');
|
||||
int position = pointer - writepath + 2;
|
||||
pointer = strrchr(writepath, '/');
|
||||
int position = pointer - writepath + 2;
|
||||
|
||||
char temppath[strlen(writepath)];
|
||||
snprintf(temppath, position, "%s", writepath);
|
||||
char temppath[strlen(writepath)];
|
||||
snprintf(temppath, position, "%s", writepath);
|
||||
|
||||
CreateSubfolder(temppath);
|
||||
CreateSubfolder(temppath);
|
||||
|
||||
if (ret == UNZ_OK)
|
||||
{
|
||||
FILE *pfile = fopen(writepath, "wb");
|
||||
if (ret == UNZ_OK)
|
||||
{
|
||||
FILE *pfile = fopen(writepath, "wb");
|
||||
|
||||
do
|
||||
{
|
||||
ShowProgress(tr( "Extracting files..." ), 0, pointer + 1, done, uncompressed_size, true);
|
||||
do
|
||||
{
|
||||
ShowProgress(tr( "Extracting files..." ), 0, pointer + 1, done, uncompressed_size, true);
|
||||
|
||||
if (uncompressed_size - done < blocksize) blocksize = uncompressed_size - done;
|
||||
if (uncompressed_size - done < blocksize) blocksize = uncompressed_size - done;
|
||||
|
||||
ret = unzReadCurrentFile(File, buffer, blocksize);
|
||||
ret = unzReadCurrentFile(File, buffer, blocksize);
|
||||
|
||||
if (ret == 0) break;
|
||||
if (ret == 0) break;
|
||||
|
||||
fwrite(buffer, 1, blocksize, pfile);
|
||||
fwrite(buffer, 1, blocksize, pfile);
|
||||
|
||||
done += ret;
|
||||
done += ret;
|
||||
|
||||
} while (done < uncompressed_size);
|
||||
} while (done < uncompressed_size);
|
||||
|
||||
fclose(pfile);
|
||||
unzCloseCurrentFile(File);
|
||||
}
|
||||
}
|
||||
if (unzGoToNextFile(File) != UNZ_OK) Stop = true;
|
||||
}
|
||||
fclose(pfile);
|
||||
unzCloseCurrentFile(File);
|
||||
}
|
||||
}
|
||||
if (unzGoToNextFile(File) != UNZ_OK) Stop = true;
|
||||
}
|
||||
|
||||
delete[] buffer;
|
||||
buffer = NULL;
|
||||
delete[] buffer;
|
||||
buffer = NULL;
|
||||
|
||||
ProgressStop();
|
||||
ProgressStop();
|
||||
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -33,31 +33,31 @@
|
|||
|
||||
typedef struct
|
||||
{
|
||||
u64 offset; // ZipFile offset
|
||||
u64 length; // uncompressed file length in 64 bits for sizes higher than 4GB
|
||||
bool isdir; // 0 - file, 1 - directory
|
||||
char filename[256]; // full filename
|
||||
u64 offset; // ZipFile offset
|
||||
u64 length; // uncompressed file length in 64 bits for sizes higher than 4GB
|
||||
bool isdir; // 0 - file, 1 - directory
|
||||
char filename[256]; // full filename
|
||||
} FileStructure;
|
||||
|
||||
class ZipFile
|
||||
{
|
||||
public:
|
||||
//!Constructor
|
||||
ZipFile(const char *filepath);
|
||||
//!Destructor
|
||||
~ZipFile();
|
||||
//!Extract all files from a zip file to a directory
|
||||
//!\param dest Destination path to where to extract
|
||||
bool ExtractAll(const char *dest);
|
||||
//!Find a file inside the zip and return if it is existent or not
|
||||
bool FindFile(const char *filename);
|
||||
//!Only needed a part of a filename to find the real one
|
||||
bool FindFilePart(const char *partfilename, std::string &realname);
|
||||
protected:
|
||||
bool LoadList();
|
||||
unzFile File;
|
||||
unz_file_info cur_file_info;
|
||||
FileStructure *FileList;
|
||||
public:
|
||||
//!Constructor
|
||||
ZipFile(const char *filepath);
|
||||
//!Destructor
|
||||
~ZipFile();
|
||||
//!Extract all files from a zip file to a directory
|
||||
//!\param dest Destination path to where to extract
|
||||
bool ExtractAll(const char *dest);
|
||||
//!Find a file inside the zip and return if it is existent or not
|
||||
bool FindFile(const char *filename);
|
||||
//!Only needed a part of a filename to find the real one
|
||||
bool FindFilePart(const char *partfilename, std::string &realname);
|
||||
protected:
|
||||
bool LoadList();
|
||||
unzFile File;
|
||||
unz_file_info cur_file_info;
|
||||
FileStructure *FileList;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -17,9 +17,9 @@
|
|||
***************************************************************************/
|
||||
void InitAudio()
|
||||
{
|
||||
AUDIO_Init(NULL);
|
||||
ASND_Init();
|
||||
ASND_Pause(0);
|
||||
AUDIO_Init(NULL);
|
||||
ASND_Init();
|
||||
ASND_Pause(0);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
|
@ -30,6 +30,6 @@ void InitAudio()
|
|||
***************************************************************************/
|
||||
void ShutdownAudio()
|
||||
{
|
||||
ASND_Pause(1);
|
||||
ASND_End();
|
||||
ASND_Pause(1);
|
||||
ASND_End();
|
||||
}
|
||||
|
|
|
@ -8,114 +8,114 @@
|
|||
BNRInstance * BNRInstance::instance = NULL;
|
||||
|
||||
OpeningBNR::OpeningBNR()
|
||||
: imetHdr(0)
|
||||
: imetHdr(0)
|
||||
{
|
||||
memset(gameID, 0, sizeof(gameID));
|
||||
}
|
||||
|
||||
OpeningBNR::~OpeningBNR()
|
||||
{
|
||||
if(imetHdr)
|
||||
free(imetHdr);
|
||||
if(imetHdr)
|
||||
free(imetHdr);
|
||||
}
|
||||
|
||||
bool OpeningBNR::Load(const u8 * discid)
|
||||
{
|
||||
if(!discid)
|
||||
return false;
|
||||
if(!discid)
|
||||
return false;
|
||||
|
||||
if(memcmp(gameID, discid, 6) == 0)
|
||||
return true;
|
||||
if(memcmp(gameID, discid, 6) == 0)
|
||||
return true;
|
||||
|
||||
if(imetHdr)
|
||||
free(imetHdr);
|
||||
imetHdr = NULL;
|
||||
snprintf(gameID, sizeof(gameID), (const char *) discid);
|
||||
if(imetHdr)
|
||||
free(imetHdr);
|
||||
imetHdr = NULL;
|
||||
snprintf(gameID, sizeof(gameID), (const char *) discid);
|
||||
|
||||
wbfs_disc_t *disc = WBFS_OpenDisc((u8 *) gameID);
|
||||
if (!disc)
|
||||
return false;
|
||||
wbfs_disc_t *disc = WBFS_OpenDisc((u8 *) gameID);
|
||||
if (!disc)
|
||||
return false;
|
||||
|
||||
wiidisc_t *wdisc = wd_open_disc((int(*)(void *, u32, u32, void *)) wbfs_disc_read, disc);
|
||||
if (!wdisc)
|
||||
{
|
||||
WBFS_CloseDisc(disc);
|
||||
return false;
|
||||
}
|
||||
wiidisc_t *wdisc = wd_open_disc((int(*)(void *, u32, u32, void *)) wbfs_disc_read, disc);
|
||||
if (!wdisc)
|
||||
{
|
||||
WBFS_CloseDisc(disc);
|
||||
return false;
|
||||
}
|
||||
|
||||
imetHdr = (IMETHeader*) wd_extract_file(wdisc, ALL_PARTITIONS, (char *) "opening.bnr");
|
||||
imetHdr = (IMETHeader*) wd_extract_file(wdisc, ALL_PARTITIONS, (char *) "opening.bnr");
|
||||
|
||||
wd_close_disc(wdisc);
|
||||
WBFS_CloseDisc(disc);
|
||||
wd_close_disc(wdisc);
|
||||
WBFS_CloseDisc(disc);
|
||||
|
||||
if(!imetHdr)
|
||||
return false;
|
||||
if(!imetHdr)
|
||||
return false;
|
||||
|
||||
if (imetHdr->fcc != 'IMET')
|
||||
{
|
||||
free(imetHdr);
|
||||
imetHdr = NULL;
|
||||
return false;
|
||||
}
|
||||
if (imetHdr->fcc != 'IMET')
|
||||
{
|
||||
free(imetHdr);
|
||||
imetHdr = NULL;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
const u16 * OpeningBNR::GetIMETTitle(int lang)
|
||||
{
|
||||
if(!imetHdr || lang < 0 || lang >= 10)
|
||||
return NULL;
|
||||
if(!imetHdr || lang < 0 || lang >= 10)
|
||||
return NULL;
|
||||
|
||||
if(imetHdr->names[lang][0] == 0)
|
||||
lang = CONF_LANG_ENGLISH;
|
||||
if(imetHdr->names[lang][0] == 0)
|
||||
lang = CONF_LANG_ENGLISH;
|
||||
|
||||
return imetHdr->names[lang];
|
||||
return imetHdr->names[lang];
|
||||
}
|
||||
|
||||
const u8 * OpeningBNR::GetBannerSound(u32 * size)
|
||||
{
|
||||
if(!imetHdr)
|
||||
return NULL;
|
||||
if(!imetHdr)
|
||||
return NULL;
|
||||
|
||||
const U8Header *bnrArcHdr = (U8Header *) (imetHdr + 1);
|
||||
const U8Entry *fst = (const U8Entry *) (((const u8 *) bnrArcHdr) + bnrArcHdr->rootNodeOffset);
|
||||
const U8Header *bnrArcHdr = (U8Header *) (imetHdr + 1);
|
||||
const U8Entry *fst = (const U8Entry *) (((const u8 *) bnrArcHdr) + bnrArcHdr->rootNodeOffset);
|
||||
|
||||
u32 i;
|
||||
for (i = 1; i < fst[0].numEntries; ++i)
|
||||
if (fst[i].fileType == 0 && strcasecmp(u8Filename(fst, i), "sound.bin") == 0) break;
|
||||
u32 i;
|
||||
for (i = 1; i < fst[0].numEntries; ++i)
|
||||
if (fst[i].fileType == 0 && strcasecmp(u8Filename(fst, i), "sound.bin") == 0) break;
|
||||
|
||||
if (i >= fst[0].numEntries)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
if (i >= fst[0].numEntries)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const u8 *sound_bin = ((const u8 *) bnrArcHdr) + fst[i].fileOffset;
|
||||
if (((IMD5Header *) sound_bin)->fcc != 'IMD5')
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
const u8 *soundChunk = sound_bin + sizeof(IMD5Header);
|
||||
u32 soundChunkSize = fst[i].fileLength - sizeof(IMD5Header);
|
||||
const u8 *sound_bin = ((const u8 *) bnrArcHdr) + fst[i].fileOffset;
|
||||
if (((IMD5Header *) sound_bin)->fcc != 'IMD5')
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
const u8 *soundChunk = sound_bin + sizeof(IMD5Header);
|
||||
u32 soundChunkSize = fst[i].fileLength - sizeof(IMD5Header);
|
||||
|
||||
if (*((u32*) soundChunk) == 'LZ77')
|
||||
{
|
||||
u32 uncSize = 0;
|
||||
u8 * uncompressed_data = uncompressLZ77(soundChunk, soundChunkSize, &uncSize);
|
||||
if (!uncompressed_data)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
if (size) *size = uncSize;
|
||||
if (*((u32*) soundChunk) == 'LZ77')
|
||||
{
|
||||
u32 uncSize = 0;
|
||||
u8 * uncompressed_data = uncompressLZ77(soundChunk, soundChunkSize, &uncSize);
|
||||
if (!uncompressed_data)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
if (size) *size = uncSize;
|
||||
|
||||
return uncompressed_data;
|
||||
}
|
||||
return uncompressed_data;
|
||||
}
|
||||
|
||||
u8 *out = (u8 *) malloc(soundChunkSize);
|
||||
if (out)
|
||||
{
|
||||
memcpy(out, soundChunk, soundChunkSize);
|
||||
if (size) *size = soundChunkSize;
|
||||
}
|
||||
u8 *out = (u8 *) malloc(soundChunkSize);
|
||||
if (out)
|
||||
{
|
||||
memcpy(out, soundChunk, soundChunkSize);
|
||||
if (size) *size = soundChunkSize;
|
||||
}
|
||||
|
||||
return out;
|
||||
return out;
|
||||
}
|
||||
|
|
|
@ -5,80 +5,80 @@
|
|||
|
||||
typedef struct _IMETHeader
|
||||
{
|
||||
u8 zeroes[64];
|
||||
u32 fcc;
|
||||
u8 unk[8];
|
||||
u32 iconSize;
|
||||
u32 bannerSize;
|
||||
u32 soundSize;
|
||||
u32 flag1;
|
||||
u16 names[10][42]; // 10 languages (thanks dkosmari for the info)
|
||||
u16 zeroes_2[7*42]; // padding for 7 more languages (thanks dkosmari for the info)
|
||||
u8 crypto[16];
|
||||
u8 zeroes[64];
|
||||
u32 fcc;
|
||||
u8 unk[8];
|
||||
u32 iconSize;
|
||||
u32 bannerSize;
|
||||
u32 soundSize;
|
||||
u32 flag1;
|
||||
u16 names[10][42]; // 10 languages (thanks dkosmari for the info)
|
||||
u16 zeroes_2[7*42]; // padding for 7 more languages (thanks dkosmari for the info)
|
||||
u8 crypto[16];
|
||||
} __attribute__((packed)) IMETHeader;
|
||||
|
||||
typedef struct _IMD5Header
|
||||
{
|
||||
u32 fcc;
|
||||
u32 filesize;
|
||||
u8 zeroes[8];
|
||||
u8 crypto[16];
|
||||
u32 fcc;
|
||||
u32 filesize;
|
||||
u8 zeroes[8];
|
||||
u8 crypto[16];
|
||||
} __attribute__((packed)) IMD5Header;
|
||||
|
||||
typedef struct _U8Header
|
||||
{
|
||||
u32 fcc;
|
||||
u32 rootNodeOffset;
|
||||
u32 headerSize;
|
||||
u32 dataOffset;
|
||||
u8 zeroes[16];
|
||||
u32 fcc;
|
||||
u32 rootNodeOffset;
|
||||
u32 headerSize;
|
||||
u32 dataOffset;
|
||||
u8 zeroes[16];
|
||||
} __attribute__((packed)) U8Header;
|
||||
|
||||
typedef struct _U8Entry
|
||||
{
|
||||
struct
|
||||
{
|
||||
u32 fileType :8;
|
||||
u32 nameOffset :24;
|
||||
};
|
||||
u32 fileOffset;
|
||||
union
|
||||
{
|
||||
u32 fileLength;
|
||||
u32 numEntries;
|
||||
};
|
||||
struct
|
||||
{
|
||||
u32 fileType :8;
|
||||
u32 nameOffset :24;
|
||||
};
|
||||
u32 fileOffset;
|
||||
union
|
||||
{
|
||||
u32 fileLength;
|
||||
u32 numEntries;
|
||||
};
|
||||
} __attribute__( ( packed ) ) U8Entry;
|
||||
|
||||
|
||||
static inline const char * u8Filename(const U8Entry *fst, int i)
|
||||
{
|
||||
return (char *) (fst + fst[0].numEntries) + fst[i].nameOffset;
|
||||
return (char *) (fst + fst[0].numEntries) + fst[i].nameOffset;
|
||||
}
|
||||
|
||||
class OpeningBNR
|
||||
{
|
||||
public:
|
||||
OpeningBNR();
|
||||
~OpeningBNR();
|
||||
bool Load(const u8 * gameID);
|
||||
const u16 * GetIMETTitle(int lang);
|
||||
const u16 * GetIMETTitle(const u8 * gameID, int lang) { Load(gameID); return GetIMETTitle(lang); };
|
||||
const u8 * GetBannerSound(u32 * size);
|
||||
const u8 * GetBannerSound(const u8 * gameID, u32 * size) { Load(gameID); return GetBannerSound(size); };
|
||||
private:
|
||||
IMETHeader *imetHdr;
|
||||
char gameID[7];
|
||||
public:
|
||||
OpeningBNR();
|
||||
~OpeningBNR();
|
||||
bool Load(const u8 * gameID);
|
||||
const u16 * GetIMETTitle(int lang);
|
||||
const u16 * GetIMETTitle(const u8 * gameID, int lang) { Load(gameID); return GetIMETTitle(lang); };
|
||||
const u8 * GetBannerSound(u32 * size);
|
||||
const u8 * GetBannerSound(const u8 * gameID, u32 * size) { Load(gameID); return GetBannerSound(size); };
|
||||
private:
|
||||
IMETHeader *imetHdr;
|
||||
char gameID[7];
|
||||
};
|
||||
|
||||
class BNRInstance : public OpeningBNR
|
||||
{
|
||||
public:
|
||||
public:
|
||||
static BNRInstance * Instance() { if(!instance) instance = new BNRInstance; return instance; };
|
||||
static void DestroyInstance() { delete instance; instance = NULL; };
|
||||
private:
|
||||
BNRInstance() { };
|
||||
~BNRInstance() { };
|
||||
static BNRInstance * instance;
|
||||
private:
|
||||
BNRInstance() { };
|
||||
~BNRInstance() { };
|
||||
static BNRInstance * instance;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -16,151 +16,151 @@
|
|||
***************************************************************************/
|
||||
int CheatMenu(const char * gameID)
|
||||
{
|
||||
int choice = 0;
|
||||
bool exit = false;
|
||||
int ret = 1;
|
||||
int choice = 0;
|
||||
bool exit = false;
|
||||
int ret = 1;
|
||||
|
||||
GuiImageData btnOutline(Resources::GetFile("button_dialogue_box.png"), Resources::GetFileSize("button_dialogue_box.png"));
|
||||
GuiImageData settingsbg(Resources::GetFile("settings_background.png"), Resources::GetFileSize("settings_background.png"));
|
||||
GuiImage settingsbackground(&settingsbg);
|
||||
GuiImageData btnOutline(Resources::GetFile("button_dialogue_box.png"), Resources::GetFileSize("button_dialogue_box.png"));
|
||||
GuiImageData settingsbg(Resources::GetFile("settings_background.png"), Resources::GetFileSize("settings_background.png"));
|
||||
GuiImage settingsbackground(&settingsbg);
|
||||
|
||||
GuiTrigger trigA;
|
||||
trigA.SetSimpleTrigger(-1, WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A, PAD_BUTTON_A);
|
||||
GuiTrigger trigB;
|
||||
trigB.SetButtonOnlyTrigger(-1, WPAD_BUTTON_B | WPAD_CLASSIC_BUTTON_B, PAD_BUTTON_B);
|
||||
GuiTrigger trigA;
|
||||
trigA.SetSimpleTrigger(-1, WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A, PAD_BUTTON_A);
|
||||
GuiTrigger trigB;
|
||||
trigB.SetButtonOnlyTrigger(-1, WPAD_BUTTON_B | WPAD_CLASSIC_BUTTON_B, PAD_BUTTON_B);
|
||||
|
||||
GuiText backBtnTxt(tr( "Back" ), 22, thColor("r=0 g=0 b=0 a=255 - prompt windows button text color"));
|
||||
backBtnTxt.SetMaxWidth(btnOutline.GetWidth() - 30);
|
||||
GuiImage backBtnImg(&btnOutline);
|
||||
GuiButton backBtn(&backBtnImg, &backBtnImg, 2, 3, -140, 400, &trigA, NULL, btnSoundClick2, 1);
|
||||
backBtn.SetLabel(&backBtnTxt);
|
||||
backBtn.SetTrigger(&trigB);
|
||||
GuiText backBtnTxt(tr( "Back" ), 22, thColor("r=0 g=0 b=0 a=255 - prompt windows button text color"));
|
||||
backBtnTxt.SetMaxWidth(btnOutline.GetWidth() - 30);
|
||||
GuiImage backBtnImg(&btnOutline);
|
||||
GuiButton backBtn(&backBtnImg, &backBtnImg, 2, 3, -140, 400, &trigA, NULL, btnSoundClick2, 1);
|
||||
backBtn.SetLabel(&backBtnTxt);
|
||||
backBtn.SetTrigger(&trigB);
|
||||
|
||||
GuiText createBtnTxt(tr( "Create" ), 22, thColor("r=0 g=0 b=0 a=255 - prompt windows button text color"));
|
||||
createBtnTxt.SetMaxWidth(btnOutline.GetWidth() - 30);
|
||||
GuiImage createBtnImg(&btnOutline);
|
||||
GuiButton createBtn(&createBtnImg, &createBtnImg, 2, 3, 160, 400, &trigA, NULL, btnSoundClick2, 1);
|
||||
createBtn.SetLabel(&createBtnTxt);
|
||||
GuiText createBtnTxt(tr( "Create" ), 22, thColor("r=0 g=0 b=0 a=255 - prompt windows button text color"));
|
||||
createBtnTxt.SetMaxWidth(btnOutline.GetWidth() - 30);
|
||||
GuiImage createBtnImg(&btnOutline);
|
||||
GuiButton createBtn(&createBtnImg, &createBtnImg, 2, 3, 160, 400, &trigA, NULL, btnSoundClick2, 1);
|
||||
createBtn.SetLabel(&createBtnTxt);
|
||||
|
||||
char txtfilename[55];
|
||||
snprintf(txtfilename, sizeof(txtfilename), "%s%s.txt", Settings.TxtCheatcodespath, gameID);
|
||||
char txtfilename[55];
|
||||
snprintf(txtfilename, sizeof(txtfilename), "%s%s.txt", Settings.TxtCheatcodespath, gameID);
|
||||
|
||||
GCTCheats c;
|
||||
int check = c.openTxtfile(txtfilename);
|
||||
GCTCheats c;
|
||||
int check = c.openTxtfile(txtfilename);
|
||||
|
||||
int download = 0;
|
||||
int download = 0;
|
||||
|
||||
switch (check)
|
||||
{
|
||||
case -1:
|
||||
WindowPrompt(tr( "Error" ), tr( "Cheatfile is blank" ), tr( "OK" ));
|
||||
break;
|
||||
case 0:
|
||||
download = WindowPrompt(tr( "Error" ), tr( "No Cheatfile found" ), tr( "Download Now" ), tr( "Cancel" ));
|
||||
if (download == 1)
|
||||
{
|
||||
download = CodeDownload(gameID);
|
||||
if (download < 0 || c.openTxtfile(txtfilename) != 1)
|
||||
break;
|
||||
}
|
||||
else
|
||||
break;
|
||||
case 1:
|
||||
int cntcheats = c.getCnt();
|
||||
OptionList cheatslst;
|
||||
GuiOptionBrowser chtBrowser(400, 280, &cheatslst, "bg_options_settings.png");
|
||||
chtBrowser.SetPosition(0, 90);
|
||||
chtBrowser.SetAlignment(ALIGN_CENTRE, ALIGN_TOP);
|
||||
chtBrowser.SetClickable(true);
|
||||
switch (check)
|
||||
{
|
||||
case -1:
|
||||
WindowPrompt(tr( "Error" ), tr( "Cheatfile is blank" ), tr( "OK" ));
|
||||
break;
|
||||
case 0:
|
||||
download = WindowPrompt(tr( "Error" ), tr( "No Cheatfile found" ), tr( "Download Now" ), tr( "Cancel" ));
|
||||
if (download == 1)
|
||||
{
|
||||
download = CodeDownload(gameID);
|
||||
if (download < 0 || c.openTxtfile(txtfilename) != 1)
|
||||
break;
|
||||
}
|
||||
else
|
||||
break;
|
||||
case 1:
|
||||
int cntcheats = c.getCnt();
|
||||
OptionList cheatslst;
|
||||
GuiOptionBrowser chtBrowser(400, 280, &cheatslst, "bg_options_settings.png");
|
||||
chtBrowser.SetPosition(0, 90);
|
||||
chtBrowser.SetAlignment(ALIGN_CENTRE, ALIGN_TOP);
|
||||
chtBrowser.SetClickable(true);
|
||||
|
||||
GuiText titleTxt(c.getGameName().c_str(), 28, ( GXColor ) {0, 0, 0, 255});
|
||||
titleTxt.SetAlignment(ALIGN_CENTRE, ALIGN_TOP);
|
||||
titleTxt.SetMaxWidth(350, SCROLL_HORIZONTAL);
|
||||
titleTxt.SetPosition(12, 40);
|
||||
GuiText titleTxt(c.getGameName().c_str(), 28, ( GXColor ) {0, 0, 0, 255});
|
||||
titleTxt.SetAlignment(ALIGN_CENTRE, ALIGN_TOP);
|
||||
titleTxt.SetMaxWidth(350, SCROLL_HORIZONTAL);
|
||||
titleTxt.SetPosition(12, 40);
|
||||
|
||||
for (int i = 0; i < cntcheats; i++)
|
||||
{
|
||||
cheatslst.SetValue(i, "%s", c.getCheatName(i).c_str());
|
||||
cheatslst.SetName(i, "OFF");
|
||||
}
|
||||
for (int i = 0; i < cntcheats; i++)
|
||||
{
|
||||
cheatslst.SetValue(i, "%s", c.getCheatName(i).c_str());
|
||||
cheatslst.SetName(i, "OFF");
|
||||
}
|
||||
|
||||
HaltGui();
|
||||
GuiWindow w(screenwidth, screenheight);
|
||||
w.Append(&settingsbackground);
|
||||
w.Append(&titleTxt);
|
||||
w.Append(&backBtn);
|
||||
w.Append(&createBtn);
|
||||
w.Append(&chtBrowser);
|
||||
mainWindow->SetState(STATE_DISABLED);
|
||||
mainWindow->ChangeFocus(&w);
|
||||
mainWindow->Append(&w);
|
||||
ResumeGui();
|
||||
HaltGui();
|
||||
GuiWindow w(screenwidth, screenheight);
|
||||
w.Append(&settingsbackground);
|
||||
w.Append(&titleTxt);
|
||||
w.Append(&backBtn);
|
||||
w.Append(&createBtn);
|
||||
w.Append(&chtBrowser);
|
||||
mainWindow->SetState(STATE_DISABLED);
|
||||
mainWindow->ChangeFocus(&w);
|
||||
mainWindow->Append(&w);
|
||||
ResumeGui();
|
||||
|
||||
while (!exit)
|
||||
{
|
||||
VIDEO_WaitVSync();
|
||||
while (!exit)
|
||||
{
|
||||
VIDEO_WaitVSync();
|
||||
|
||||
ret = chtBrowser.GetClickedOption();
|
||||
if (ret != -1)
|
||||
{
|
||||
const char *strCheck = cheatslst.GetName(ret);
|
||||
if (strncmp(strCheck, "ON", 2) == 0)
|
||||
{
|
||||
cheatslst.SetName(ret, "%s", "OFF");
|
||||
}
|
||||
else if (strncmp(strCheck, "OFF", 3) == 0)
|
||||
{
|
||||
cheatslst.SetName(ret, "%s", "ON");
|
||||
}
|
||||
}
|
||||
ret = chtBrowser.GetClickedOption();
|
||||
if (ret != -1)
|
||||
{
|
||||
const char *strCheck = cheatslst.GetName(ret);
|
||||
if (strncmp(strCheck, "ON", 2) == 0)
|
||||
{
|
||||
cheatslst.SetName(ret, "%s", "OFF");
|
||||
}
|
||||
else if (strncmp(strCheck, "OFF", 3) == 0)
|
||||
{
|
||||
cheatslst.SetName(ret, "%s", "ON");
|
||||
}
|
||||
}
|
||||
|
||||
if (createBtn.GetState() == STATE_CLICKED)
|
||||
{
|
||||
createBtn.ResetState();
|
||||
if (cntcheats > 0)
|
||||
{
|
||||
int selectednrs[30];
|
||||
int x = 0;
|
||||
for (int i = 0; i < cntcheats; i++)
|
||||
{
|
||||
const char *strCheck = cheatslst.GetName(i);
|
||||
if (strncmp(strCheck, "ON", 2) == 0)
|
||||
{
|
||||
selectednrs[x] = i;
|
||||
x++;
|
||||
}
|
||||
}
|
||||
if (x == 0)
|
||||
{
|
||||
WindowPrompt(tr( "Error" ), tr( "No cheats were selected" ), tr( "OK" ));
|
||||
}
|
||||
else
|
||||
{
|
||||
CreateSubfolder(Settings.Cheatcodespath);
|
||||
string chtpath = Settings.Cheatcodespath;
|
||||
string gctfname = chtpath + c.getGameID() + ".gct";
|
||||
c.createGCT(selectednrs, x, gctfname.c_str());
|
||||
WindowPrompt(tr( "GCT File created" ), NULL, tr( "OK" ));
|
||||
exit = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else WindowPrompt(tr( "Error" ), tr( "Could not create GCT file" ), tr( "OK" ));
|
||||
}
|
||||
if (createBtn.GetState() == STATE_CLICKED)
|
||||
{
|
||||
createBtn.ResetState();
|
||||
if (cntcheats > 0)
|
||||
{
|
||||
int selectednrs[30];
|
||||
int x = 0;
|
||||
for (int i = 0; i < cntcheats; i++)
|
||||
{
|
||||
const char *strCheck = cheatslst.GetName(i);
|
||||
if (strncmp(strCheck, "ON", 2) == 0)
|
||||
{
|
||||
selectednrs[x] = i;
|
||||
x++;
|
||||
}
|
||||
}
|
||||
if (x == 0)
|
||||
{
|
||||
WindowPrompt(tr( "Error" ), tr( "No cheats were selected" ), tr( "OK" ));
|
||||
}
|
||||
else
|
||||
{
|
||||
CreateSubfolder(Settings.Cheatcodespath);
|
||||
string chtpath = Settings.Cheatcodespath;
|
||||
string gctfname = chtpath + c.getGameID() + ".gct";
|
||||
c.createGCT(selectednrs, x, gctfname.c_str());
|
||||
WindowPrompt(tr( "GCT File created" ), NULL, tr( "OK" ));
|
||||
exit = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else WindowPrompt(tr( "Error" ), tr( "Could not create GCT file" ), tr( "OK" ));
|
||||
}
|
||||
|
||||
if (backBtn.GetState() == STATE_CLICKED)
|
||||
{
|
||||
backBtn.ResetState();
|
||||
exit = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
HaltGui();
|
||||
mainWindow->SetState(STATE_DEFAULT);
|
||||
mainWindow->Remove(&w);
|
||||
ResumeGui();
|
||||
break;
|
||||
}
|
||||
if (backBtn.GetState() == STATE_CLICKED)
|
||||
{
|
||||
backBtn.ResetState();
|
||||
exit = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
HaltGui();
|
||||
mainWindow->SetState(STATE_DEFAULT);
|
||||
mainWindow->Remove(&w);
|
||||
ResumeGui();
|
||||
break;
|
||||
}
|
||||
|
||||
return choice;
|
||||
return choice;
|
||||
}
|
||||
|
|
|
@ -14,267 +14,267 @@
|
|||
|
||||
GCTCheats::GCTCheats(void)
|
||||
{
|
||||
iCntCheats = 0;
|
||||
iCntCheats = 0;
|
||||
}
|
||||
|
||||
GCTCheats::~GCTCheats(void)
|
||||
{
|
||||
|
||||
string sGameID = "";
|
||||
string sGameTitle = "";
|
||||
/*string sCheatName[MAXCHEATS];
|
||||
string sCheats[MAXCHEATS];
|
||||
string sCheatComment[MAXCHEATS];*/
|
||||
string sGameID = "";
|
||||
string sGameTitle = "";
|
||||
/*string sCheatName[MAXCHEATS];
|
||||
string sCheats[MAXCHEATS];
|
||||
string sCheatComment[MAXCHEATS];*/
|
||||
}
|
||||
|
||||
int GCTCheats::getCnt()
|
||||
{
|
||||
return iCntCheats;
|
||||
return iCntCheats;
|
||||
}
|
||||
|
||||
string GCTCheats::getGameName(void)
|
||||
{
|
||||
return sGameTitle;
|
||||
return sGameTitle;
|
||||
}
|
||||
|
||||
string GCTCheats::getGameID(void)
|
||||
{
|
||||
return sGameID;
|
||||
return sGameID;
|
||||
}
|
||||
|
||||
string GCTCheats::getCheat(int nr)
|
||||
{
|
||||
if (nr <= (iCntCheats - 1))
|
||||
{
|
||||
return sCheats[nr];
|
||||
}
|
||||
else
|
||||
{
|
||||
return ERRORRANGE;
|
||||
}
|
||||
if (nr <= (iCntCheats - 1))
|
||||
{
|
||||
return sCheats[nr];
|
||||
}
|
||||
else
|
||||
{
|
||||
return ERRORRANGE;
|
||||
}
|
||||
}
|
||||
|
||||
string GCTCheats::getCheatName(int nr)
|
||||
{
|
||||
if (nr <= (iCntCheats - 1))
|
||||
{
|
||||
return sCheatName[nr];
|
||||
}
|
||||
else
|
||||
{
|
||||
return ERRORRANGE;
|
||||
}
|
||||
if (nr <= (iCntCheats - 1))
|
||||
{
|
||||
return sCheatName[nr];
|
||||
}
|
||||
else
|
||||
{
|
||||
return ERRORRANGE;
|
||||
}
|
||||
}
|
||||
|
||||
string GCTCheats::getCheatComment(int nr)
|
||||
{
|
||||
if (nr <= (iCntCheats - 1))
|
||||
{
|
||||
return sCheatComment[nr];
|
||||
}
|
||||
else
|
||||
{
|
||||
return ERRORRANGE;
|
||||
}
|
||||
if (nr <= (iCntCheats - 1))
|
||||
{
|
||||
return sCheatComment[nr];
|
||||
}
|
||||
else
|
||||
{
|
||||
return ERRORRANGE;
|
||||
}
|
||||
}
|
||||
|
||||
int GCTCheats::createGCT(int nr, const char * filename)
|
||||
{
|
||||
|
||||
if (nr == 0) return 0;
|
||||
if (nr == 0) return 0;
|
||||
|
||||
ofstream filestr;
|
||||
filestr.open(filename);
|
||||
ofstream filestr;
|
||||
filestr.open(filename);
|
||||
|
||||
if (filestr.fail()) return 0;
|
||||
if (filestr.fail()) return 0;
|
||||
|
||||
//Header and Footer
|
||||
char header[] = { 0x00, 0xd0, 0xc0, 0xde, 0x00, 0xd0, 0xc0, 0xde };
|
||||
char footer[] = { 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
||||
//Header and Footer
|
||||
char header[] = { 0x00, 0xd0, 0xc0, 0xde, 0x00, 0xd0, 0xc0, 0xde };
|
||||
char footer[] = { 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
||||
|
||||
string buf = getCheat(nr);
|
||||
filestr.write(header, sizeof(header));
|
||||
string buf = getCheat(nr);
|
||||
filestr.write(header, sizeof(header));
|
||||
|
||||
int x = 0;
|
||||
long int li;
|
||||
int len = buf.size();
|
||||
int x = 0;
|
||||
long int li;
|
||||
int len = buf.size();
|
||||
|
||||
while (x < len)
|
||||
{
|
||||
string temp = buf.substr(x, 2);
|
||||
li = strtol(temp.c_str(), NULL, 16);
|
||||
temp = li;
|
||||
filestr.write(temp.c_str(), 1);
|
||||
x += 2;
|
||||
}
|
||||
filestr.write(footer, sizeof(footer));
|
||||
while (x < len)
|
||||
{
|
||||
string temp = buf.substr(x, 2);
|
||||
li = strtol(temp.c_str(), NULL, 16);
|
||||
temp = li;
|
||||
filestr.write(temp.c_str(), 1);
|
||||
x += 2;
|
||||
}
|
||||
filestr.write(footer, sizeof(footer));
|
||||
|
||||
filestr.close();
|
||||
return 1;
|
||||
filestr.close();
|
||||
return 1;
|
||||
}
|
||||
|
||||
int GCTCheats::createGCT(const char * chtbuffer, const char * filename)
|
||||
{
|
||||
|
||||
ofstream filestr;
|
||||
filestr.open(filename);
|
||||
ofstream filestr;
|
||||
filestr.open(filename);
|
||||
|
||||
if (filestr.fail()) return 0;
|
||||
if (filestr.fail()) return 0;
|
||||
|
||||
//Header and Footer
|
||||
char header[] = { 0x00, 0xd0, 0xc0, 0xde, 0x00, 0xd0, 0xc0, 0xde };
|
||||
char footer[] = { 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
||||
//Header and Footer
|
||||
char header[] = { 0x00, 0xd0, 0xc0, 0xde, 0x00, 0xd0, 0xc0, 0xde };
|
||||
char footer[] = { 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
||||
|
||||
string buf = chtbuffer;
|
||||
filestr.write(header, sizeof(header));
|
||||
string buf = chtbuffer;
|
||||
filestr.write(header, sizeof(header));
|
||||
|
||||
int x = 0;
|
||||
long int li;
|
||||
int len = buf.size();
|
||||
int x = 0;
|
||||
long int li;
|
||||
int len = buf.size();
|
||||
|
||||
while (x < len)
|
||||
{
|
||||
string temp = buf.substr(x, 2);
|
||||
li = strtol(temp.c_str(), NULL, 16);
|
||||
temp = li;
|
||||
filestr.write(temp.c_str(), 1);
|
||||
x += 2;
|
||||
}
|
||||
while (x < len)
|
||||
{
|
||||
string temp = buf.substr(x, 2);
|
||||
li = strtol(temp.c_str(), NULL, 16);
|
||||
temp = li;
|
||||
filestr.write(temp.c_str(), 1);
|
||||
x += 2;
|
||||
}
|
||||
|
||||
filestr.write(footer, sizeof(footer));
|
||||
filestr.write(footer, sizeof(footer));
|
||||
|
||||
filestr.close();
|
||||
filestr.close();
|
||||
|
||||
return 1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int GCTCheats::createGCT(int nr[], int cnt, const char * filename)
|
||||
{
|
||||
|
||||
if (cnt == 0) return 0;
|
||||
if (cnt == 0) return 0;
|
||||
|
||||
ofstream filestr;
|
||||
filestr.open(filename);
|
||||
ofstream filestr;
|
||||
filestr.open(filename);
|
||||
|
||||
if (filestr.fail()) return 0;
|
||||
if (filestr.fail()) return 0;
|
||||
|
||||
//Header and Footer
|
||||
char header[] = { 0x00, 0xd0, 0xc0, 0xde, 0x00, 0xd0, 0xc0, 0xde };
|
||||
char footer[] = { 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
||||
//Header and Footer
|
||||
char header[] = { 0x00, 0xd0, 0xc0, 0xde, 0x00, 0xd0, 0xc0, 0xde };
|
||||
char footer[] = { 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
||||
|
||||
filestr.write(header, sizeof(header));
|
||||
filestr.write(header, sizeof(header));
|
||||
|
||||
int c = 0;
|
||||
while (c != cnt)
|
||||
{
|
||||
int actnr = nr[c];
|
||||
string buf = getCheat(actnr);
|
||||
long int li;
|
||||
int len = buf.size();
|
||||
int x = 0;
|
||||
int c = 0;
|
||||
while (c != cnt)
|
||||
{
|
||||
int actnr = nr[c];
|
||||
string buf = getCheat(actnr);
|
||||
long int li;
|
||||
int len = buf.size();
|
||||
int x = 0;
|
||||
|
||||
while (x < len)
|
||||
{
|
||||
string temp = buf.substr(x, 2);
|
||||
li = strtol(temp.c_str(), NULL, 16);
|
||||
temp = li;
|
||||
filestr.write(temp.c_str(), 1);
|
||||
x += 2;
|
||||
}
|
||||
c++;
|
||||
}
|
||||
while (x < len)
|
||||
{
|
||||
string temp = buf.substr(x, 2);
|
||||
li = strtol(temp.c_str(), NULL, 16);
|
||||
temp = li;
|
||||
filestr.write(temp.c_str(), 1);
|
||||
x += 2;
|
||||
}
|
||||
c++;
|
||||
}
|
||||
|
||||
filestr.write(footer, sizeof(footer));
|
||||
filestr.close();
|
||||
return 1;
|
||||
filestr.write(footer, sizeof(footer));
|
||||
filestr.close();
|
||||
return 1;
|
||||
}
|
||||
|
||||
int GCTCheats::openTxtfile(const char * filename)
|
||||
{
|
||||
ifstream filestr;
|
||||
int i = 0;
|
||||
string str;
|
||||
filestr.open(filename);
|
||||
ifstream filestr;
|
||||
int i = 0;
|
||||
string str;
|
||||
filestr.open(filename);
|
||||
|
||||
if (filestr.fail()) return 0;
|
||||
if (filestr.fail()) return 0;
|
||||
|
||||
filestr.seekg(0, ios_base::end);
|
||||
int size = filestr.tellg();
|
||||
if (size <= 0) return -1;
|
||||
filestr.seekg(0, ios_base::beg);
|
||||
filestr.seekg(0, ios_base::end);
|
||||
int size = filestr.tellg();
|
||||
if (size <= 0) return -1;
|
||||
filestr.seekg(0, ios_base::beg);
|
||||
|
||||
getline(filestr, sGameID);
|
||||
if (sGameID[sGameID.length() - 1] == '\r') sGameID.erase(sGameID.length() - 1);
|
||||
getline(filestr, sGameID);
|
||||
if (sGameID[sGameID.length() - 1] == '\r') sGameID.erase(sGameID.length() - 1);
|
||||
|
||||
getline(filestr, sGameTitle);
|
||||
if (sGameTitle[sGameTitle.length() - 1] == '\r') sGameTitle.erase(sGameTitle.length() - 1);
|
||||
getline(filestr, sGameTitle);
|
||||
if (sGameTitle[sGameTitle.length() - 1] == '\r') sGameTitle.erase(sGameTitle.length() - 1);
|
||||
|
||||
getline(filestr, sCheatName[i]); // skip first line if file uses CRLF
|
||||
if (!sGameTitle[sGameTitle.length() - 1] == '\r') filestr.seekg(0, ios_base::beg);
|
||||
getline(filestr, sCheatName[i]); // skip first line if file uses CRLF
|
||||
if (!sGameTitle[sGameTitle.length() - 1] == '\r') filestr.seekg(0, ios_base::beg);
|
||||
|
||||
while (!filestr.eof())
|
||||
{
|
||||
getline(filestr, sCheatName[i]); // '\n' delimiter by default
|
||||
if (sCheatName[i][sCheatName[i].length() - 1] == '\r') sCheatName[i].erase(sCheatName[i].length() - 1);
|
||||
while (!filestr.eof())
|
||||
{
|
||||
getline(filestr, sCheatName[i]); // '\n' delimiter by default
|
||||
if (sCheatName[i][sCheatName[i].length() - 1] == '\r') sCheatName[i].erase(sCheatName[i].length() - 1);
|
||||
|
||||
string cheatdata;
|
||||
bool emptyline = false;
|
||||
string cheatdata;
|
||||
bool emptyline = false;
|
||||
|
||||
do
|
||||
{
|
||||
getline(filestr, str);
|
||||
if (str[str.length() - 1] == '\r') str.erase(str.length() - 1);
|
||||
do
|
||||
{
|
||||
getline(filestr, str);
|
||||
if (str[str.length() - 1] == '\r') str.erase(str.length() - 1);
|
||||
|
||||
if (str == "" || str[0] == '\r' || str[0] == '\n')
|
||||
{
|
||||
emptyline = true;
|
||||
break;
|
||||
}
|
||||
if (str == "" || str[0] == '\r' || str[0] == '\n')
|
||||
{
|
||||
emptyline = true;
|
||||
break;
|
||||
}
|
||||
|
||||
if (IsCode(str))
|
||||
{
|
||||
// remove any garbage (comment) after code
|
||||
while (str.size() > 17)
|
||||
{
|
||||
str.erase(str.length() - 1);
|
||||
}
|
||||
cheatdata.append(str);
|
||||
size_t found = cheatdata.find(' ');
|
||||
cheatdata.replace(found, 1, "");
|
||||
}
|
||||
else
|
||||
{
|
||||
//printf("%i",str.size());
|
||||
sCheatComment[i] = str;
|
||||
}
|
||||
if (filestr.eof()) break;
|
||||
if (IsCode(str))
|
||||
{
|
||||
// remove any garbage (comment) after code
|
||||
while (str.size() > 17)
|
||||
{
|
||||
str.erase(str.length() - 1);
|
||||
}
|
||||
cheatdata.append(str);
|
||||
size_t found = cheatdata.find(' ');
|
||||
cheatdata.replace(found, 1, "");
|
||||
}
|
||||
else
|
||||
{
|
||||
//printf("%i",str.size());
|
||||
sCheatComment[i] = str;
|
||||
}
|
||||
if (filestr.eof()) break;
|
||||
|
||||
} while (!emptyline);
|
||||
} while (!emptyline);
|
||||
|
||||
sCheats[i] = cheatdata;
|
||||
i++;
|
||||
if (i == MAXCHEATS) break;
|
||||
}
|
||||
iCntCheats = i;
|
||||
filestr.close();
|
||||
return 1;
|
||||
sCheats[i] = cheatdata;
|
||||
i++;
|
||||
if (i == MAXCHEATS) break;
|
||||
}
|
||||
iCntCheats = i;
|
||||
filestr.close();
|
||||
return 1;
|
||||
}
|
||||
|
||||
bool GCTCheats::IsCode(const std::string& str)
|
||||
{
|
||||
if (str[8] == ' ' && str.size() >= 17)
|
||||
{
|
||||
// accept strings longer than 17 in case there is a comment on the same line as the code
|
||||
char part1[9];
|
||||
char part2[9];
|
||||
snprintf(part1, sizeof(part1), "%c%c%c%c%c%c%c%c", str[0], str[1], str[2], str[3], str[4], str[5], str[6],
|
||||
str[7]);
|
||||
snprintf(part2, sizeof(part2), "%c%c%c%c%c%c%c%c", str[9], str[10], str[11], str[12], str[13], str[14],
|
||||
str[15], str[16]);
|
||||
if ((strtok(part1, "0123456789ABCDEFabcdef") == NULL) && (strtok(part2, "0123456789ABCDEFabcdef") == NULL))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
if (str[8] == ' ' && str.size() >= 17)
|
||||
{
|
||||
// accept strings longer than 17 in case there is a comment on the same line as the code
|
||||
char part1[9];
|
||||
char part2[9];
|
||||
snprintf(part1, sizeof(part1), "%c%c%c%c%c%c%c%c", str[0], str[1], str[2], str[3], str[4], str[5], str[6],
|
||||
str[7]);
|
||||
snprintf(part2, sizeof(part2), "%c%c%c%c%c%c%c%c", str[9], str[10], str[11], str[12], str[13], str[14],
|
||||
str[15], str[16]);
|
||||
if ((strtok(part1, "0123456789ABCDEFabcdef") == NULL) && (strtok(part2, "0123456789ABCDEFabcdef") == NULL))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -16,60 +16,60 @@ using namespace std;
|
|||
//!Handles Ocarina TXT Cheatfiles
|
||||
class GCTCheats
|
||||
{
|
||||
private:
|
||||
string sGameID;
|
||||
string sGameTitle;
|
||||
string sCheatName[MAXCHEATS];
|
||||
string sCheats[MAXCHEATS];
|
||||
string sCheatComment[MAXCHEATS];
|
||||
int iCntCheats;
|
||||
private:
|
||||
string sGameID;
|
||||
string sGameTitle;
|
||||
string sCheatName[MAXCHEATS];
|
||||
string sCheats[MAXCHEATS];
|
||||
string sCheatComment[MAXCHEATS];
|
||||
int iCntCheats;
|
||||
|
||||
public:
|
||||
//!Constructor
|
||||
GCTCheats(void);
|
||||
//!Destructor
|
||||
~GCTCheats(void);
|
||||
//!Open txt file with cheats
|
||||
//!\param filename name of TXT file
|
||||
//!\return error code
|
||||
int openTxtfile(const char * filename);
|
||||
//!Creates GCT file for one cheat
|
||||
//!\param nr selected Cheat Numbers
|
||||
//!\param filename name of GCT file
|
||||
//!\return error code
|
||||
int createGCT(int nr, const char * filename);
|
||||
//!Creates GCT file from a buffer
|
||||
//!\param chtbuffer buffer that holds the cheat data
|
||||
//!\param filename name of GCT file
|
||||
//!\return error code
|
||||
int createGCT(const char * chtbuffer, const char * filename);
|
||||
//!Creates GCT file
|
||||
//!\param nr[] array of selected Cheat Numbers
|
||||
//!\param cnt size of array
|
||||
//!\param filename name of GCT file
|
||||
//!\return error code
|
||||
int createGCT(int nr[], int cnt, const char * filename);
|
||||
//!Gets Count cheats
|
||||
//!\return Count cheats
|
||||
int getCnt();
|
||||
//!Gets Game Name
|
||||
//!\return Game Name
|
||||
string getGameName(void);
|
||||
//!Gets GameID
|
||||
//!\return GameID
|
||||
string getGameID(void);
|
||||
//!Gets cheat data
|
||||
//!\return cheat data
|
||||
string getCheat(int nr);
|
||||
//!Gets Cheat Name
|
||||
//!\return Cheat Name
|
||||
string getCheatName(int nr);
|
||||
//!Gets Cheat Comment
|
||||
//!\return Cheat Comment
|
||||
string getCheatComment(int nr);
|
||||
//!Check if string is a code
|
||||
//!\return true/false
|
||||
bool IsCode(const std::string& s);
|
||||
public:
|
||||
//!Constructor
|
||||
GCTCheats(void);
|
||||
//!Destructor
|
||||
~GCTCheats(void);
|
||||
//!Open txt file with cheats
|
||||
//!\param filename name of TXT file
|
||||
//!\return error code
|
||||
int openTxtfile(const char * filename);
|
||||
//!Creates GCT file for one cheat
|
||||
//!\param nr selected Cheat Numbers
|
||||
//!\param filename name of GCT file
|
||||
//!\return error code
|
||||
int createGCT(int nr, const char * filename);
|
||||
//!Creates GCT file from a buffer
|
||||
//!\param chtbuffer buffer that holds the cheat data
|
||||
//!\param filename name of GCT file
|
||||
//!\return error code
|
||||
int createGCT(const char * chtbuffer, const char * filename);
|
||||
//!Creates GCT file
|
||||
//!\param nr[] array of selected Cheat Numbers
|
||||
//!\param cnt size of array
|
||||
//!\param filename name of GCT file
|
||||
//!\return error code
|
||||
int createGCT(int nr[], int cnt, const char * filename);
|
||||
//!Gets Count cheats
|
||||
//!\return Count cheats
|
||||
int getCnt();
|
||||
//!Gets Game Name
|
||||
//!\return Game Name
|
||||
string getGameName(void);
|
||||
//!Gets GameID
|
||||
//!\return GameID
|
||||
string getGameID(void);
|
||||
//!Gets cheat data
|
||||
//!\return cheat data
|
||||
string getCheat(int nr);
|
||||
//!Gets Cheat Name
|
||||
//!\return Cheat Name
|
||||
string getCheatName(int nr);
|
||||
//!Gets Cheat Comment
|
||||
//!\return Cheat Comment
|
||||
string getCheatComment(int nr);
|
||||
//!Check if string is a code
|
||||
//!\return true/false
|
||||
bool IsCode(const std::string& s);
|
||||
};
|
||||
|
||||
#endif /* _GCT_H */
|
||||
|
|
|
@ -13,78 +13,78 @@ static bool geckoinit = false;
|
|||
void gprintf(const char *format, ...)
|
||||
{
|
||||
if (!geckoinit)
|
||||
return;
|
||||
return;
|
||||
|
||||
char * tmp = NULL;
|
||||
va_list va;
|
||||
va_start(va, format);
|
||||
if((vasprintf(&tmp, format, va) >= 0) && tmp)
|
||||
{
|
||||
usb_sendbuffer(1, tmp, strlen(tmp));
|
||||
#ifdef DEBUG_TO_FILE
|
||||
FILE *debugF = fopen("sd:/debug.txt", "a");
|
||||
if(!debugF)
|
||||
debugF = fopen("sd:/debug.txt", "w");
|
||||
if(debugF)
|
||||
fprintf(debugF, tmp);
|
||||
fclose(debugF);
|
||||
#endif
|
||||
usb_sendbuffer(1, tmp, strlen(tmp));
|
||||
#ifdef DEBUG_TO_FILE
|
||||
FILE *debugF = fopen("sd:/debug.txt", "a");
|
||||
if(!debugF)
|
||||
debugF = fopen("sd:/debug.txt", "w");
|
||||
if(debugF)
|
||||
fprintf(debugF, tmp);
|
||||
fclose(debugF);
|
||||
#endif
|
||||
}
|
||||
va_end(va);
|
||||
|
||||
if(tmp)
|
||||
free(tmp);
|
||||
free(tmp);
|
||||
}
|
||||
|
||||
bool InitGecko()
|
||||
{
|
||||
u32 geckoattached = usb_isgeckoalive(EXI_CHANNEL_1);
|
||||
if (geckoattached)
|
||||
{
|
||||
usb_flush(EXI_CHANNEL_1);
|
||||
geckoinit = true;
|
||||
return true;
|
||||
}
|
||||
u32 geckoattached = usb_isgeckoalive(EXI_CHANNEL_1);
|
||||
if (geckoattached)
|
||||
{
|
||||
usb_flush(EXI_CHANNEL_1);
|
||||
geckoinit = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
char ascii(char s)
|
||||
{
|
||||
if (s < 0x20) return '.';
|
||||
if (s > 0x7E) return '.';
|
||||
return s;
|
||||
if (s < 0x20) return '.';
|
||||
if (s > 0x7E) return '.';
|
||||
return s;
|
||||
}
|
||||
|
||||
void hexdump(void *d, int len)
|
||||
{
|
||||
u8 *data;
|
||||
int i, off;
|
||||
data = (u8*) d;
|
||||
u8 *data;
|
||||
int i, off;
|
||||
data = (u8*) d;
|
||||
|
||||
gprintf("\n 0 1 2 3 4 5 6 7 8 9 A B C D E F 0123456789ABCDEF");
|
||||
gprintf("\n==== =============================================== ================\n");
|
||||
gprintf("\n 0 1 2 3 4 5 6 7 8 9 A B C D E F 0123456789ABCDEF");
|
||||
gprintf("\n==== =============================================== ================\n");
|
||||
|
||||
for (off = 0; off < len; off += 16)
|
||||
{
|
||||
gprintf("%04x ", off);
|
||||
for (i = 0; i < 16; i++)
|
||||
if ((i + off) >= len)
|
||||
gprintf(" ");
|
||||
else gprintf("%02x ", data[off + i]);
|
||||
for (off = 0; off < len; off += 16)
|
||||
{
|
||||
gprintf("%04x ", off);
|
||||
for (i = 0; i < 16; i++)
|
||||
if ((i + off) >= len)
|
||||
gprintf(" ");
|
||||
else gprintf("%02x ", data[off + i]);
|
||||
|
||||
gprintf(" ");
|
||||
for (i = 0; i < 16; i++)
|
||||
if ((i + off) >= len)
|
||||
gprintf(" ");
|
||||
else gprintf("%c", ascii(data[off + i]));
|
||||
gprintf("\n");
|
||||
}
|
||||
gprintf(" ");
|
||||
for (i = 0; i < 16; i++)
|
||||
if ((i + off) >= len)
|
||||
gprintf(" ");
|
||||
else gprintf("%c", ascii(data[off + i]));
|
||||
gprintf("\n");
|
||||
}
|
||||
}
|
||||
|
||||
static ssize_t __out_write(struct _reent *r, int fd, const char *ptr, size_t len)
|
||||
{
|
||||
gprintf(ptr);
|
||||
gprintf(ptr);
|
||||
|
||||
return len;
|
||||
}
|
||||
|
|
|
@ -7,17 +7,17 @@ extern "C"
|
|||
{
|
||||
#endif
|
||||
|
||||
char ascii(char s);
|
||||
char ascii(char s);
|
||||
|
||||
#ifndef NO_DEBUG
|
||||
//use this just like printf();
|
||||
void gprintf(const char *str, ...);
|
||||
bool InitGecko();
|
||||
void hexdump(void *d, int len);
|
||||
void USBGeckoOutput();
|
||||
//use this just like printf();
|
||||
void gprintf(const char *str, ...);
|
||||
bool InitGecko();
|
||||
void hexdump(void *d, int len);
|
||||
void USBGeckoOutput();
|
||||
#else
|
||||
#define gprintf(...)
|
||||
#define InitGecko() false
|
||||
#define InitGecko() false
|
||||
#define hexdump( x, y )
|
||||
#endif /* NO_DEBUG */
|
||||
|
||||
|
|
|
@ -30,84 +30,84 @@ static std::vector<std::string> Arguments;
|
|||
|
||||
void AddBootArgument(const char * argv)
|
||||
{
|
||||
std::string arg(argv);
|
||||
Arguments.push_back(arg);
|
||||
std::string arg(argv);
|
||||
Arguments.push_back(arg);
|
||||
}
|
||||
|
||||
int CopyHomebrewMemory(u8 *temp, u32 pos, u32 len)
|
||||
{
|
||||
homebrewsize += len;
|
||||
memcpy((homebrewbuffer) + pos, temp, len);
|
||||
homebrewsize += len;
|
||||
memcpy((homebrewbuffer) + pos, temp, len);
|
||||
|
||||
return 1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
void FreeHomebrewBuffer()
|
||||
{
|
||||
homebrewbuffer = EXECUTE_ADDR;
|
||||
homebrewsize = 0;
|
||||
homebrewbuffer = EXECUTE_ADDR;
|
||||
homebrewsize = 0;
|
||||
|
||||
Arguments.clear();
|
||||
Arguments.clear();
|
||||
}
|
||||
|
||||
static int SetupARGV(struct __argv * args)
|
||||
{
|
||||
if (!args) return -1;
|
||||
if (!args) return -1;
|
||||
|
||||
bzero(args, sizeof(struct __argv));
|
||||
args->argvMagic = ARGV_MAGIC;
|
||||
bzero(args, sizeof(struct __argv));
|
||||
args->argvMagic = ARGV_MAGIC;
|
||||
|
||||
u32 argc = 0;
|
||||
u32 position = 0;
|
||||
u32 stringlength = 1;
|
||||
u32 argc = 0;
|
||||
u32 position = 0;
|
||||
u32 stringlength = 1;
|
||||
|
||||
/** Append Arguments **/
|
||||
for (u32 i = 0; i < Arguments.size(); i++)
|
||||
{
|
||||
stringlength += Arguments[i].size() + 1;
|
||||
}
|
||||
/** Append Arguments **/
|
||||
for (u32 i = 0; i < Arguments.size(); i++)
|
||||
{
|
||||
stringlength += Arguments[i].size() + 1;
|
||||
}
|
||||
|
||||
args->length = stringlength;
|
||||
args->length = stringlength;
|
||||
//! Put the argument into mem2 too, to avoid overwriting it
|
||||
args.commandLine = (char *) ARGS_ADDR + sizeof(struct __argv);
|
||||
args->commandLine = (char *) ARGS_ADDR + sizeof(struct __argv);
|
||||
|
||||
/** Append Arguments **/
|
||||
for (u32 i = 0; i < Arguments.size(); i++)
|
||||
{
|
||||
strcpy(&args->commandLine[position], Arguments[i].c_str());
|
||||
position += Arguments[i].size() + 1;
|
||||
argc++;
|
||||
}
|
||||
/** Append Arguments **/
|
||||
for (u32 i = 0; i < Arguments.size(); i++)
|
||||
{
|
||||
strcpy(&args->commandLine[position], Arguments[i].c_str());
|
||||
position += Arguments[i].size() + 1;
|
||||
argc++;
|
||||
}
|
||||
|
||||
args->argc = argc;
|
||||
args->argc = argc;
|
||||
|
||||
args->commandLine[args->length - 1] = '\0';
|
||||
args->argv = &args->commandLine;
|
||||
args->endARGV = args->argv + 1;
|
||||
args->commandLine[args->length - 1] = '\0';
|
||||
args->argv = &args->commandLine;
|
||||
args->endARGV = args->argv + 1;
|
||||
|
||||
Arguments.clear();
|
||||
Arguments.clear();
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int RunAppbooter()
|
||||
{
|
||||
if (homebrewsize == 0) return -1;
|
||||
if (homebrewsize == 0) return -1;
|
||||
|
||||
ExitApp();
|
||||
ExitApp();
|
||||
|
||||
if(Settings.EntryIOS != IOS_GetVersion())
|
||||
IOS_ReloadIOS(Settings.EntryIOS);
|
||||
IOS_ReloadIOS(Settings.EntryIOS);
|
||||
|
||||
struct __argv args;
|
||||
SetupARGV(&args);
|
||||
struct __argv args;
|
||||
SetupARGV(&args);
|
||||
|
||||
u32 cpu_isr;
|
||||
u32 cpu_isr;
|
||||
|
||||
memcpy(BOOTER_ADDR, app_booter_bin, app_booter_bin_size);
|
||||
DCFlushRange(BOOTER_ADDR, app_booter_bin_size);
|
||||
|
||||
entrypoint entry = (entrypoint) BOOTER_ADDR;
|
||||
entrypoint entry = (entrypoint) BOOTER_ADDR;
|
||||
|
||||
if (args.argvMagic == ARGV_MAGIC)
|
||||
{
|
||||
|
@ -115,66 +115,66 @@ static int RunAppbooter()
|
|||
DCFlushRange(ARGS_ADDR, sizeof(args) + args.length);
|
||||
}
|
||||
|
||||
u64 currentStub = getStubDest();
|
||||
loadStub();
|
||||
u64 currentStub = getStubDest();
|
||||
loadStub();
|
||||
|
||||
if (Set_Stub_Split(0x00010001, "UNEO") < 0)
|
||||
{
|
||||
if (Set_Stub_Split(0x00010001, "ULNR") < 0)
|
||||
{
|
||||
if (!currentStub) currentStub = 0x100000002ULL;
|
||||
if (Set_Stub_Split(0x00010001, "UNEO") < 0)
|
||||
{
|
||||
if (Set_Stub_Split(0x00010001, "ULNR") < 0)
|
||||
{
|
||||
if (!currentStub) currentStub = 0x100000002ULL;
|
||||
|
||||
Set_Stub(currentStub);
|
||||
}
|
||||
}
|
||||
Set_Stub(currentStub);
|
||||
}
|
||||
}
|
||||
|
||||
SYS_ResetSystem(SYS_SHUTDOWN, 0, 0);
|
||||
_CPU_ISR_Disable( cpu_isr );
|
||||
__exception_closeall();
|
||||
entry();
|
||||
_CPU_ISR_Restore( cpu_isr );
|
||||
SYS_ResetSystem(SYS_SHUTDOWN, 0, 0);
|
||||
_CPU_ISR_Disable( cpu_isr );
|
||||
__exception_closeall();
|
||||
entry();
|
||||
_CPU_ISR_Restore( cpu_isr );
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int BootHomebrew(const char * filepath)
|
||||
{
|
||||
void *buffer = NULL;
|
||||
u32 filesize = 0;
|
||||
void *buffer = NULL;
|
||||
u32 filesize = 0;
|
||||
|
||||
FILE *file = fopen(filepath, "rb");
|
||||
FILE *file = fopen(filepath, "rb");
|
||||
|
||||
if (!file) return -1;
|
||||
if (!file) return -1;
|
||||
|
||||
fseek(file, 0, SEEK_END);
|
||||
filesize = ftell(file);
|
||||
rewind(file);
|
||||
fseek(file, 0, SEEK_END);
|
||||
filesize = ftell(file);
|
||||
rewind(file);
|
||||
|
||||
buffer = malloc(filesize);
|
||||
buffer = malloc(filesize);
|
||||
|
||||
if (fread(buffer, 1, filesize, file) != filesize)
|
||||
{
|
||||
fclose(file);
|
||||
free(buffer);
|
||||
DeviceHandler::DestroyInstance();
|
||||
Sys_BackToLoader();
|
||||
}
|
||||
if (fread(buffer, 1, filesize, file) != filesize)
|
||||
{
|
||||
fclose(file);
|
||||
free(buffer);
|
||||
DeviceHandler::DestroyInstance();
|
||||
Sys_BackToLoader();
|
||||
}
|
||||
|
||||
fclose(file);
|
||||
fclose(file);
|
||||
|
||||
CopyHomebrewMemory((u8*) buffer, 0, filesize);
|
||||
CopyHomebrewMemory((u8*) buffer, 0, filesize);
|
||||
|
||||
if (buffer)
|
||||
{
|
||||
free(buffer);
|
||||
buffer = NULL;
|
||||
}
|
||||
if (buffer)
|
||||
{
|
||||
free(buffer);
|
||||
buffer = NULL;
|
||||
}
|
||||
|
||||
AddBootArgument(filepath);
|
||||
return RunAppbooter();
|
||||
AddBootArgument(filepath);
|
||||
return RunAppbooter();
|
||||
}
|
||||
|
||||
int BootHomebrewFromMem()
|
||||
{
|
||||
return RunAppbooter();
|
||||
return RunAppbooter();
|
||||
}
|
||||
|
|
|
@ -42,423 +42,423 @@ extern char wiiloadVersion[2];
|
|||
extern int connection;
|
||||
|
||||
HomebrewBrowser::HomebrewBrowser()
|
||||
: FlyingButtonsMenu(tr( "Homebrew Launcher" ))
|
||||
: FlyingButtonsMenu(tr( "Homebrew Launcher" ))
|
||||
{
|
||||
HomebrewList = new DirList(Settings.homebrewapps_path, ".dol,.elf", DirList::Files | DirList::Dirs | DirList::CheckSubfolders);
|
||||
HomebrewList = new DirList(Settings.homebrewapps_path, ".dol,.elf", DirList::Files | DirList::Dirs | DirList::CheckSubfolders);
|
||||
|
||||
if (IsNetworkInit())
|
||||
ResumeNetworkWait();
|
||||
if (IsNetworkInit())
|
||||
ResumeNetworkWait();
|
||||
|
||||
wifiNotSet = true;
|
||||
wifiImgData = Resources::GetImageData("wifi_btn.png");
|
||||
wifiToolTip = new GuiTooltip(" ");
|
||||
wifiImg = new GuiImage(wifiImgData);
|
||||
wifiBtn = new GuiButton(wifiImgData->GetWidth(), wifiImgData->GetHeight());
|
||||
wifiBtn->SetImage(wifiImg);
|
||||
wifiBtn->SetPosition(300, 400);
|
||||
wifiBtn->SetSoundOver(btnSoundOver);
|
||||
wifiBtn->SetSoundClick(btnSoundClick);
|
||||
wifiBtn->SetEffectGrow();
|
||||
wifiBtn->SetAlpha(80);
|
||||
wifiBtn->SetTrigger(trigA);
|
||||
Append(wifiBtn);
|
||||
wifiNotSet = true;
|
||||
wifiImgData = Resources::GetImageData("wifi_btn.png");
|
||||
wifiToolTip = new GuiTooltip(" ");
|
||||
wifiImg = new GuiImage(wifiImgData);
|
||||
wifiBtn = new GuiButton(wifiImgData->GetWidth(), wifiImgData->GetHeight());
|
||||
wifiBtn->SetImage(wifiImg);
|
||||
wifiBtn->SetPosition(300, 400);
|
||||
wifiBtn->SetSoundOver(btnSoundOver);
|
||||
wifiBtn->SetSoundClick(btnSoundClick);
|
||||
wifiBtn->SetEffectGrow();
|
||||
wifiBtn->SetAlpha(80);
|
||||
wifiBtn->SetTrigger(trigA);
|
||||
Append(wifiBtn);
|
||||
|
||||
channelImgData = Resources::GetImageData("channel_btn.png");
|
||||
channelBtnImg = new GuiImage(channelImgData);
|
||||
channelBtnImg->SetWidescreen(Settings.widescreen);
|
||||
channelBtn = new GuiButton(channelBtnImg->GetWidth(), channelBtnImg->GetHeight());
|
||||
channelBtn->SetPosition(240, 400);
|
||||
channelBtn->SetImage(channelBtnImg);
|
||||
channelBtn->SetSoundOver(btnSoundOver);
|
||||
channelBtn->SetSoundClick(btnSoundClick2);
|
||||
channelBtn->SetEffectGrow();
|
||||
channelBtn->SetTrigger(trigA);
|
||||
if (Settings.godmode || !(Settings.ParentalBlocks & BLOCK_TITLE_LAUNCHER_MENU))
|
||||
Append(channelBtn);
|
||||
channelImgData = Resources::GetImageData("channel_btn.png");
|
||||
channelBtnImg = new GuiImage(channelImgData);
|
||||
channelBtnImg->SetWidescreen(Settings.widescreen);
|
||||
channelBtn = new GuiButton(channelBtnImg->GetWidth(), channelBtnImg->GetHeight());
|
||||
channelBtn->SetPosition(240, 400);
|
||||
channelBtn->SetImage(channelBtnImg);
|
||||
channelBtn->SetSoundOver(btnSoundOver);
|
||||
channelBtn->SetSoundClick(btnSoundClick2);
|
||||
channelBtn->SetEffectGrow();
|
||||
channelBtn->SetTrigger(trigA);
|
||||
if (Settings.godmode || !(Settings.ParentalBlocks & BLOCK_TITLE_LAUNCHER_MENU))
|
||||
Append(channelBtn);
|
||||
|
||||
MainButtonDesc.resize(HomebrewList->GetFilecount());
|
||||
MainButtonDescOver.resize(HomebrewList->GetFilecount());
|
||||
MainButtonDesc.resize(HomebrewList->GetFilecount());
|
||||
MainButtonDescOver.resize(HomebrewList->GetFilecount());
|
||||
|
||||
for(u32 i = 0; i < 4; ++i)
|
||||
{
|
||||
IconImgData[i] = NULL;
|
||||
IconImg[i] = NULL;
|
||||
}
|
||||
for(u32 i = 0; i < 4; ++i)
|
||||
{
|
||||
IconImgData[i] = NULL;
|
||||
IconImg[i] = NULL;
|
||||
}
|
||||
|
||||
for(int i = 0; i < HomebrewList->GetFilecount(); ++i)
|
||||
{
|
||||
MainButtonDesc[i] = new GuiText((char *) NULL, 18, (GXColor) {0, 0, 0, 255});
|
||||
MainButtonDesc[i]->SetMaxWidth(MainButtonImgData->GetWidth() - 150, DOTTED);
|
||||
MainButtonDesc[i]->SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE);
|
||||
MainButtonDesc[i]->SetPosition(148, 15);
|
||||
for(int i = 0; i < HomebrewList->GetFilecount(); ++i)
|
||||
{
|
||||
MainButtonDesc[i] = new GuiText((char *) NULL, 18, (GXColor) {0, 0, 0, 255});
|
||||
MainButtonDesc[i]->SetMaxWidth(MainButtonImgData->GetWidth() - 150, DOTTED);
|
||||
MainButtonDesc[i]->SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE);
|
||||
MainButtonDesc[i]->SetPosition(148, 15);
|
||||
|
||||
MainButtonDescOver[i] = new GuiText((char *) NULL, 18, (GXColor) {0, 0, 0, 255});
|
||||
MainButtonDescOver[i]->SetMaxWidth(MainButtonImgData->GetWidth() - 150, SCROLL_HORIZONTAL);
|
||||
MainButtonDescOver[i]->SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE);
|
||||
MainButtonDescOver[i]->SetPosition(148, 15);
|
||||
}
|
||||
MainButtonDescOver[i] = new GuiText((char *) NULL, 18, (GXColor) {0, 0, 0, 255});
|
||||
MainButtonDescOver[i]->SetMaxWidth(MainButtonImgData->GetWidth() - 150, SCROLL_HORIZONTAL);
|
||||
MainButtonDescOver[i]->SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE);
|
||||
MainButtonDescOver[i]->SetPosition(148, 15);
|
||||
}
|
||||
}
|
||||
|
||||
HomebrewBrowser::~HomebrewBrowser()
|
||||
{
|
||||
HaltGui();
|
||||
delete HomebrewList;
|
||||
HaltGui();
|
||||
delete HomebrewList;
|
||||
|
||||
Remove(wifiBtn);
|
||||
delete wifiImgData;
|
||||
delete wifiImg;
|
||||
delete wifiToolTip;
|
||||
delete wifiBtn;
|
||||
Remove(wifiBtn);
|
||||
delete wifiImgData;
|
||||
delete wifiImg;
|
||||
delete wifiToolTip;
|
||||
delete wifiBtn;
|
||||
|
||||
Remove(channelBtn);
|
||||
delete channelImgData;
|
||||
delete channelBtnImg;
|
||||
delete channelBtn;
|
||||
Remove(channelBtn);
|
||||
delete channelImgData;
|
||||
delete channelBtnImg;
|
||||
delete channelBtn;
|
||||
|
||||
for(u32 i = 0; i < MainButtonDesc.size(); ++i)
|
||||
{
|
||||
delete MainButtonDesc[i];
|
||||
delete MainButtonDescOver[i];
|
||||
MainButton[i]->SetLabel(NULL, 1);
|
||||
MainButton[i]->SetLabelOver(NULL, 1);
|
||||
}
|
||||
for(u32 i = 0; i < MainButtonDesc.size(); ++i)
|
||||
{
|
||||
delete MainButtonDesc[i];
|
||||
delete MainButtonDescOver[i];
|
||||
MainButton[i]->SetLabel(NULL, 1);
|
||||
MainButton[i]->SetLabelOver(NULL, 1);
|
||||
}
|
||||
|
||||
if (IsNetworkInit())
|
||||
HaltNetworkThread();
|
||||
if (IsNetworkInit())
|
||||
HaltNetworkThread();
|
||||
}
|
||||
|
||||
int HomebrewBrowser::Execute()
|
||||
{
|
||||
HomebrewBrowser * Menu = new HomebrewBrowser();
|
||||
mainWindow->Append(Menu);
|
||||
HomebrewBrowser * Menu = new HomebrewBrowser();
|
||||
mainWindow->Append(Menu);
|
||||
|
||||
Menu->ShowMenu();
|
||||
Menu->ShowMenu();
|
||||
|
||||
int returnMenu = MENU_NONE;
|
||||
int returnMenu = MENU_NONE;
|
||||
|
||||
while((returnMenu = Menu->MainLoop()) == MENU_NONE);
|
||||
while((returnMenu = Menu->MainLoop()) == MENU_NONE);
|
||||
|
||||
delete Menu;
|
||||
delete Menu;
|
||||
|
||||
return returnMenu;
|
||||
return returnMenu;
|
||||
}
|
||||
|
||||
void HomebrewBrowser::AddMainButtons()
|
||||
{
|
||||
HaltGui();
|
||||
HaltGui();
|
||||
|
||||
for(u32 i = 0; i < 4; ++i)
|
||||
{
|
||||
if(IconImgData[i])
|
||||
delete IconImgData[i];
|
||||
if(IconImg[i])
|
||||
delete IconImg[i];
|
||||
IconImgData[i] = NULL;
|
||||
IconImg[i] = NULL;
|
||||
}
|
||||
for(u32 i = 0; i < 4; ++i)
|
||||
{
|
||||
if(IconImgData[i])
|
||||
delete IconImgData[i];
|
||||
if(IconImg[i])
|
||||
delete IconImg[i];
|
||||
IconImgData[i] = NULL;
|
||||
IconImg[i] = NULL;
|
||||
}
|
||||
|
||||
for(u32 i = 0; i < MainButton.size(); ++i)
|
||||
MainButton[i]->SetIcon(NULL);
|
||||
for(u32 i = 0; i < MainButton.size(); ++i)
|
||||
MainButton[i]->SetIcon(NULL);
|
||||
|
||||
int FirstItem = currentPage*DISPLAY_BUTTONS;
|
||||
int FirstItem = currentPage*DISPLAY_BUTTONS;
|
||||
|
||||
for(int i = FirstItem, n = 0; i < (int) MainButton.size() && i < FirstItem+DISPLAY_BUTTONS; ++i, ++n)
|
||||
{
|
||||
std::string iconpath = HomebrewList->GetFilepath(i);
|
||||
size_t pos = iconpath.rfind('/');
|
||||
if(pos != std::string::npos && pos < iconpath.size()-1)
|
||||
iconpath.erase(pos+1);
|
||||
iconpath += "icon.png";
|
||||
for(int i = FirstItem, n = 0; i < (int) MainButton.size() && i < FirstItem+DISPLAY_BUTTONS; ++i, ++n)
|
||||
{
|
||||
std::string iconpath = HomebrewList->GetFilepath(i);
|
||||
size_t pos = iconpath.rfind('/');
|
||||
if(pos != std::string::npos && pos < iconpath.size()-1)
|
||||
iconpath.erase(pos+1);
|
||||
iconpath += "icon.png";
|
||||
|
||||
IconImgData[n] = new GuiImageData(iconpath.c_str());
|
||||
IconImg[n] = new GuiImage(IconImgData[n]);
|
||||
IconImg[n]->SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE);
|
||||
IconImg[n]->SetPosition(12, 0);
|
||||
IconImg[n]->SetScale(0.95);
|
||||
MainButton[i]->SetIcon(IconImg[n]);
|
||||
}
|
||||
IconImgData[n] = new GuiImageData(iconpath.c_str());
|
||||
IconImg[n] = new GuiImage(IconImgData[n]);
|
||||
IconImg[n]->SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE);
|
||||
IconImg[n]->SetPosition(12, 0);
|
||||
IconImg[n]->SetScale(0.95);
|
||||
MainButton[i]->SetIcon(IconImg[n]);
|
||||
}
|
||||
|
||||
FlyingButtonsMenu::AddMainButtons();
|
||||
FlyingButtonsMenu::AddMainButtons();
|
||||
}
|
||||
|
||||
void HomebrewBrowser::SetupMainButtons()
|
||||
{
|
||||
HomebrewXML MetaXML;
|
||||
HomebrewXML MetaXML;
|
||||
|
||||
for(int i = 0; i < HomebrewList->GetFilecount(); ++i)
|
||||
{
|
||||
const char * HomebrewName = NULL;
|
||||
std::string metapath = HomebrewList->GetFilepath(i);
|
||||
size_t pos = metapath.rfind('/');
|
||||
if(pos != std::string::npos && pos < metapath.size()-1)
|
||||
metapath.erase(pos+1);
|
||||
metapath += "meta.xml";
|
||||
for(int i = 0; i < HomebrewList->GetFilecount(); ++i)
|
||||
{
|
||||
const char * HomebrewName = NULL;
|
||||
std::string metapath = HomebrewList->GetFilepath(i);
|
||||
size_t pos = metapath.rfind('/');
|
||||
if(pos != std::string::npos && pos < metapath.size()-1)
|
||||
metapath.erase(pos+1);
|
||||
metapath += "meta.xml";
|
||||
|
||||
if (MetaXML.LoadHomebrewXMLData(metapath.c_str()) > 0)
|
||||
{
|
||||
HomebrewName = MetaXML.GetName();
|
||||
MainButtonDesc[i]->SetText(MetaXML.GetShortDescription());
|
||||
MainButtonDescOver[i]->SetText(MetaXML.GetShortDescription());
|
||||
}
|
||||
else
|
||||
{
|
||||
const char * shortpath = HomebrewList->GetFilepath(i);
|
||||
const char * ptr = shortpath;
|
||||
const char * ptr2 = NULL;
|
||||
while(*ptr != '\0')
|
||||
{
|
||||
if(*ptr == '/')
|
||||
{
|
||||
shortpath = ptr2;
|
||||
ptr2 = ptr;
|
||||
}
|
||||
if (MetaXML.LoadHomebrewXMLData(metapath.c_str()) > 0)
|
||||
{
|
||||
HomebrewName = MetaXML.GetName();
|
||||
MainButtonDesc[i]->SetText(MetaXML.GetShortDescription());
|
||||
MainButtonDescOver[i]->SetText(MetaXML.GetShortDescription());
|
||||
}
|
||||
else
|
||||
{
|
||||
const char * shortpath = HomebrewList->GetFilepath(i);
|
||||
const char * ptr = shortpath;
|
||||
const char * ptr2 = NULL;
|
||||
while(*ptr != '\0')
|
||||
{
|
||||
if(*ptr == '/')
|
||||
{
|
||||
shortpath = ptr2;
|
||||
ptr2 = ptr;
|
||||
}
|
||||
|
||||
++ptr;
|
||||
}
|
||||
if(!shortpath && ptr2)
|
||||
shortpath = ptr2;
|
||||
else if(!shortpath)
|
||||
shortpath = HomebrewList->GetFilename(i);
|
||||
++ptr;
|
||||
}
|
||||
if(!shortpath && ptr2)
|
||||
shortpath = ptr2;
|
||||
else if(!shortpath)
|
||||
shortpath = HomebrewList->GetFilename(i);
|
||||
|
||||
HomebrewName = shortpath;
|
||||
MainButtonDesc[i]->SetText(" ");
|
||||
MainButtonDescOver[i]->SetText(" ");
|
||||
}
|
||||
HomebrewName = shortpath;
|
||||
MainButtonDesc[i]->SetText(" ");
|
||||
MainButtonDescOver[i]->SetText(" ");
|
||||
}
|
||||
|
||||
SetMainButton(i, HomebrewName, MainButtonImgData, MainButtonImgOverData);
|
||||
SetMainButton(i, HomebrewName, MainButtonImgData, MainButtonImgOverData);
|
||||
|
||||
MainButtonTxt[i]->SetFontSize(18);
|
||||
MainButtonTxt[i]->SetMaxWidth(MainButtonImgData->GetWidth() - 150, DOTTED);
|
||||
MainButtonTxt[i]->SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE);
|
||||
MainButtonTxt[i]->SetPosition(148, -12);
|
||||
MainButton[i]->SetLabel(MainButtonDesc[i], 1);
|
||||
MainButton[i]->SetLabelOver(MainButtonDescOver[i], 1);
|
||||
}
|
||||
MainButtonTxt[i]->SetFontSize(18);
|
||||
MainButtonTxt[i]->SetMaxWidth(MainButtonImgData->GetWidth() - 150, DOTTED);
|
||||
MainButtonTxt[i]->SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE);
|
||||
MainButtonTxt[i]->SetPosition(148, -12);
|
||||
MainButton[i]->SetLabel(MainButtonDesc[i], 1);
|
||||
MainButton[i]->SetLabelOver(MainButtonDescOver[i], 1);
|
||||
}
|
||||
}
|
||||
|
||||
int HomebrewBrowser::MainLoop()
|
||||
{
|
||||
if (IsNetworkInit() && wifiNotSet)
|
||||
{
|
||||
wifiToolTip->SetText(GetNetworkIP());
|
||||
wifiBtn->SetAlpha(255);
|
||||
wifiBtn->SetToolTip(wifiToolTip, 0, -50, 0, 5);
|
||||
wifiNotSet = false;
|
||||
}
|
||||
if (IsNetworkInit() && wifiNotSet)
|
||||
{
|
||||
wifiToolTip->SetText(GetNetworkIP());
|
||||
wifiBtn->SetAlpha(255);
|
||||
wifiBtn->SetToolTip(wifiToolTip, 0, -50, 0, 5);
|
||||
wifiNotSet = false;
|
||||
}
|
||||
|
||||
if(wifiBtn->GetState() == STATE_CLICKED)
|
||||
{
|
||||
ResumeNetworkWait();
|
||||
wifiBtn->ResetState();
|
||||
}
|
||||
else if(channelBtn->GetState() == STATE_CLICKED)
|
||||
{
|
||||
SetState(STATE_DISABLED);
|
||||
TitleBrowser();
|
||||
SetState(STATE_DEFAULT);
|
||||
channelBtn->ResetState();
|
||||
}
|
||||
else if (infilesize > 0)
|
||||
{
|
||||
int menu = ReceiveFile();
|
||||
if(menu != MENU_NONE)
|
||||
return menu;
|
||||
CloseConnection();
|
||||
ResumeNetworkWait();
|
||||
}
|
||||
if(wifiBtn->GetState() == STATE_CLICKED)
|
||||
{
|
||||
ResumeNetworkWait();
|
||||
wifiBtn->ResetState();
|
||||
}
|
||||
else if(channelBtn->GetState() == STATE_CLICKED)
|
||||
{
|
||||
SetState(STATE_DISABLED);
|
||||
TitleBrowser();
|
||||
SetState(STATE_DEFAULT);
|
||||
channelBtn->ResetState();
|
||||
}
|
||||
else if (infilesize > 0)
|
||||
{
|
||||
int menu = ReceiveFile();
|
||||
if(menu != MENU_NONE)
|
||||
return menu;
|
||||
CloseConnection();
|
||||
ResumeNetworkWait();
|
||||
}
|
||||
|
||||
return FlyingButtonsMenu::MainLoop();
|
||||
return FlyingButtonsMenu::MainLoop();
|
||||
}
|
||||
|
||||
//! Callback for MainButton clicked
|
||||
void HomebrewBrowser::MainButtonClicked(int button)
|
||||
{
|
||||
HomebrewXML MetaXML;
|
||||
std::string metapath = HomebrewList->GetFilepath(button);
|
||||
size_t pos = metapath.rfind('/');
|
||||
if(pos != std::string::npos && pos < metapath.size()-1)
|
||||
metapath.erase(pos+1);
|
||||
metapath += "meta.xml";
|
||||
MetaXML.LoadHomebrewXMLData(metapath.c_str());
|
||||
HomebrewXML MetaXML;
|
||||
std::string metapath = HomebrewList->GetFilepath(button);
|
||||
size_t pos = metapath.rfind('/');
|
||||
if(pos != std::string::npos && pos < metapath.size()-1)
|
||||
metapath.erase(pos+1);
|
||||
metapath += "meta.xml";
|
||||
MetaXML.LoadHomebrewXMLData(metapath.c_str());
|
||||
|
||||
u64 filesize = HomebrewList->GetFilesize(button);
|
||||
u64 filesize = HomebrewList->GetFilesize(button);
|
||||
|
||||
wString HomebrewName(MainButtonTxt[button]->GetText());
|
||||
wString HomebrewName(MainButtonTxt[button]->GetText());
|
||||
|
||||
HomebrewPrompt *HBCWindowPrompt = new HomebrewPrompt(HomebrewName.toUTF8().c_str(), MetaXML.GetCoder(), MetaXML.GetVersion(),
|
||||
MetaXML.GetReleasedate(), MetaXML.GetLongDescription(), IconImgData[button % 4], filesize);
|
||||
HomebrewPrompt *HBCWindowPrompt = new HomebrewPrompt(HomebrewName.toUTF8().c_str(), MetaXML.GetCoder(), MetaXML.GetVersion(),
|
||||
MetaXML.GetReleasedate(), MetaXML.GetLongDescription(), IconImgData[button % 4], filesize);
|
||||
|
||||
mainWindow->SetState(STATE_DISABLED);
|
||||
mainWindow->Append(HBCWindowPrompt);
|
||||
mainWindow->SetState(STATE_DISABLED);
|
||||
mainWindow->Append(HBCWindowPrompt);
|
||||
|
||||
int choice = HBCWindowPrompt->MainLoop();
|
||||
int choice = HBCWindowPrompt->MainLoop();
|
||||
|
||||
delete HBCWindowPrompt;
|
||||
delete HBCWindowPrompt;
|
||||
|
||||
mainWindow->SetState(STATE_DEFAULT);
|
||||
mainWindow->SetState(STATE_DEFAULT);
|
||||
|
||||
if (choice == 1)
|
||||
{
|
||||
u8 *buffer = NULL;
|
||||
u64 filesize = 0;
|
||||
LoadFileToMem(HomebrewList->GetFilepath(button), &buffer, &filesize);
|
||||
if(!buffer)
|
||||
{
|
||||
WindowPrompt(tr("Error"), tr("Not enough memory."), tr("OK"));
|
||||
return;
|
||||
}
|
||||
FreeHomebrewBuffer();
|
||||
CopyHomebrewMemory(buffer, 0, filesize);
|
||||
if (choice == 1)
|
||||
{
|
||||
u8 *buffer = NULL;
|
||||
u64 filesize = 0;
|
||||
LoadFileToMem(HomebrewList->GetFilepath(button), &buffer, &filesize);
|
||||
if(!buffer)
|
||||
{
|
||||
WindowPrompt(tr("Error"), tr("Not enough memory."), tr("OK"));
|
||||
return;
|
||||
}
|
||||
FreeHomebrewBuffer();
|
||||
CopyHomebrewMemory(buffer, 0, filesize);
|
||||
|
||||
AddBootArgument(HomebrewList->GetFilepath(button));
|
||||
AddBootArgument(HomebrewList->GetFilepath(button));
|
||||
|
||||
for(u32 i = 0; i < MetaXML.GetArguments().size(); ++i)
|
||||
{
|
||||
AddBootArgument(MetaXML.GetArguments().at(i).c_str());
|
||||
}
|
||||
for(u32 i = 0; i < MetaXML.GetArguments().size(); ++i)
|
||||
{
|
||||
AddBootArgument(MetaXML.GetArguments().at(i).c_str());
|
||||
}
|
||||
|
||||
BootHomebrewFromMem();
|
||||
}
|
||||
BootHomebrewFromMem();
|
||||
}
|
||||
}
|
||||
|
||||
int HomebrewBrowser::ReceiveFile()
|
||||
{
|
||||
char filesizetxt[50];
|
||||
char temp[50];
|
||||
u32 filesize = 0;
|
||||
char filesizetxt[50];
|
||||
char temp[50];
|
||||
u32 filesize = 0;
|
||||
|
||||
if (infilesize < MB_SIZE)
|
||||
snprintf(filesizetxt, sizeof(filesizetxt), tr( "Incoming file %0.2fKB" ), infilesize / KB_SIZE);
|
||||
else snprintf(filesizetxt, sizeof(filesizetxt), tr( "Incoming file %0.2fMB" ), infilesize / MB_SIZE);
|
||||
if (infilesize < MB_SIZE)
|
||||
snprintf(filesizetxt, sizeof(filesizetxt), tr( "Incoming file %0.2fKB" ), infilesize / KB_SIZE);
|
||||
else snprintf(filesizetxt, sizeof(filesizetxt), tr( "Incoming file %0.2fMB" ), infilesize / MB_SIZE);
|
||||
|
||||
snprintf(temp, sizeof(temp), tr( "Load file from: %s ?" ), GetIncommingIP());
|
||||
snprintf(temp, sizeof(temp), tr( "Load file from: %s ?" ), GetIncommingIP());
|
||||
|
||||
int choice = WindowPrompt(filesizetxt, temp, tr( "OK" ), tr( "Cancel" ));
|
||||
int choice = WindowPrompt(filesizetxt, temp, tr( "OK" ), tr( "Cancel" ));
|
||||
|
||||
if (choice == 0)
|
||||
return MENU_NONE;
|
||||
if (choice == 0)
|
||||
return MENU_NONE;
|
||||
|
||||
u32 read = 0;
|
||||
int len = NETWORKBLOCKSIZE;
|
||||
filesize = infilesize;
|
||||
u8 * buffer = (u8 *) malloc(infilesize);
|
||||
if(!buffer)
|
||||
{
|
||||
WindowPrompt(tr( "Not enough memory." ), 0, tr( "OK" ));
|
||||
return MENU_NONE;
|
||||
}
|
||||
u32 read = 0;
|
||||
int len = NETWORKBLOCKSIZE;
|
||||
filesize = infilesize;
|
||||
u8 * buffer = (u8 *) malloc(infilesize);
|
||||
if(!buffer)
|
||||
{
|
||||
WindowPrompt(tr( "Not enough memory." ), 0, tr( "OK" ));
|
||||
return MENU_NONE;
|
||||
}
|
||||
|
||||
int error = 0;
|
||||
int error = 0;
|
||||
|
||||
while (read < infilesize)
|
||||
{
|
||||
ShowProgress(tr( "Receiving file from:" ), GetIncommingIP(), NULL, read, infilesize, true);
|
||||
while (read < infilesize)
|
||||
{
|
||||
ShowProgress(tr( "Receiving file from:" ), GetIncommingIP(), NULL, read, infilesize, true);
|
||||
|
||||
if (infilesize - read < (u32) len)
|
||||
len = infilesize - read;
|
||||
else len = NETWORKBLOCKSIZE;
|
||||
if (infilesize - read < (u32) len)
|
||||
len = infilesize - read;
|
||||
else len = NETWORKBLOCKSIZE;
|
||||
|
||||
int result = network_read(connection, buffer+read, len);
|
||||
int result = network_read(connection, buffer+read, len);
|
||||
|
||||
if (result < 0)
|
||||
{
|
||||
WindowPrompt(tr( "Error while transfering data." ), 0, tr( "OK" ));
|
||||
free(buffer);
|
||||
return MENU_NONE;
|
||||
}
|
||||
if (!result)
|
||||
{
|
||||
break;
|
||||
}
|
||||
if (result < 0)
|
||||
{
|
||||
WindowPrompt(tr( "Error while transfering data." ), 0, tr( "OK" ));
|
||||
free(buffer);
|
||||
return MENU_NONE;
|
||||
}
|
||||
if (!result)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
read += result;
|
||||
}
|
||||
read += result;
|
||||
}
|
||||
|
||||
char filename[101];
|
||||
memset(filename, 0, sizeof(filename));
|
||||
char filename[101];
|
||||
memset(filename, 0, sizeof(filename));
|
||||
|
||||
network_read(connection, (u8*) filename, 100);
|
||||
network_read(connection, (u8*) filename, 100);
|
||||
|
||||
// Do we need to unzip this thing?
|
||||
if (wiiloadVersion[0] > 0 || wiiloadVersion[1] > 4)
|
||||
{
|
||||
// We need to unzip...
|
||||
if (buffer[0] == 'P' && buffer[1] == 'K' && buffer[2] == 0x03 && buffer[3] == 0x04)
|
||||
{
|
||||
// It's a zip file, unzip to the apps directory
|
||||
// Zip archive, ask for permission to install the zip
|
||||
char zippath[255];
|
||||
sprintf(zippath, "%s%s", Settings.homebrewapps_path, filename);
|
||||
// Do we need to unzip this thing?
|
||||
if (wiiloadVersion[0] > 0 || wiiloadVersion[1] > 4)
|
||||
{
|
||||
// We need to unzip...
|
||||
if (buffer[0] == 'P' && buffer[1] == 'K' && buffer[2] == 0x03 && buffer[3] == 0x04)
|
||||
{
|
||||
// It's a zip file, unzip to the apps directory
|
||||
// Zip archive, ask for permission to install the zip
|
||||
char zippath[255];
|
||||
sprintf(zippath, "%s%s", Settings.homebrewapps_path, filename);
|
||||
|
||||
FILE *fp = fopen(zippath, "wb");
|
||||
if (!fp)
|
||||
{
|
||||
WindowPrompt(tr( "Error writing the data." ), 0, tr( "OK" ));
|
||||
return MENU_NONE;
|
||||
}
|
||||
FILE *fp = fopen(zippath, "wb");
|
||||
if (!fp)
|
||||
{
|
||||
WindowPrompt(tr( "Error writing the data." ), 0, tr( "OK" ));
|
||||
return MENU_NONE;
|
||||
}
|
||||
|
||||
fwrite(buffer, 1, infilesize, fp);
|
||||
fclose(fp);
|
||||
fwrite(buffer, 1, infilesize, fp);
|
||||
fclose(fp);
|
||||
|
||||
free(buffer);
|
||||
buffer = NULL;
|
||||
free(buffer);
|
||||
buffer = NULL;
|
||||
|
||||
// Now unzip the zip file...
|
||||
unzFile uf = unzOpen(zippath);
|
||||
if (uf == NULL)
|
||||
{
|
||||
WindowPrompt(tr( "Error while opening the zip." ), 0, tr( "OK" ));
|
||||
return MENU_NONE;
|
||||
}
|
||||
// Now unzip the zip file...
|
||||
unzFile uf = unzOpen(zippath);
|
||||
if (uf == NULL)
|
||||
{
|
||||
WindowPrompt(tr( "Error while opening the zip." ), 0, tr( "OK" ));
|
||||
return MENU_NONE;
|
||||
}
|
||||
|
||||
extractZip(uf, 0, 1, 0, Settings.homebrewapps_path);
|
||||
unzCloseCurrentFile(uf);
|
||||
extractZip(uf, 0, 1, 0, Settings.homebrewapps_path);
|
||||
unzCloseCurrentFile(uf);
|
||||
|
||||
remove(zippath);
|
||||
remove(zippath);
|
||||
|
||||
WindowPrompt(tr( "Success:" ),
|
||||
tr( "Uploaded ZIP file installed to homebrew directory." ), tr( "OK" ));
|
||||
WindowPrompt(tr( "Success:" ),
|
||||
tr( "Uploaded ZIP file installed to homebrew directory." ), tr( "OK" ));
|
||||
|
||||
// Reload this menu here...
|
||||
return MENU_HOMEBREWBROWSE;
|
||||
}
|
||||
else if (uncfilesize != 0) // if uncfilesize == 0, it's not compressed
|
||||
{
|
||||
// It's compressed, uncompress
|
||||
u8 *unc = (u8 *) malloc(uncfilesize);
|
||||
if(!unc)
|
||||
{
|
||||
ProgressStop();
|
||||
free(buffer);
|
||||
CloseConnection();
|
||||
WindowPrompt(tr( "Not enough memory." ), 0, tr( "OK" ));
|
||||
return MENU_NONE;
|
||||
}
|
||||
uLongf f = uncfilesize;
|
||||
error = uncompress(unc, &f, buffer, infilesize) != Z_OK;
|
||||
uncfilesize = f;
|
||||
filesize = uncfilesize;
|
||||
// Reload this menu here...
|
||||
return MENU_HOMEBREWBROWSE;
|
||||
}
|
||||
else if (uncfilesize != 0) // if uncfilesize == 0, it's not compressed
|
||||
{
|
||||
// It's compressed, uncompress
|
||||
u8 *unc = (u8 *) malloc(uncfilesize);
|
||||
if(!unc)
|
||||
{
|
||||
ProgressStop();
|
||||
free(buffer);
|
||||
CloseConnection();
|
||||
WindowPrompt(tr( "Not enough memory." ), 0, tr( "OK" ));
|
||||
return MENU_NONE;
|
||||
}
|
||||
uLongf f = uncfilesize;
|
||||
error = uncompress(unc, &f, buffer, infilesize) != Z_OK;
|
||||
uncfilesize = f;
|
||||
filesize = uncfilesize;
|
||||
|
||||
free(buffer);
|
||||
buffer = unc;
|
||||
}
|
||||
}
|
||||
free(buffer);
|
||||
buffer = unc;
|
||||
}
|
||||
}
|
||||
|
||||
CopyHomebrewMemory(buffer, 0, filesize);
|
||||
free(buffer);
|
||||
CopyHomebrewMemory(buffer, 0, filesize);
|
||||
free(buffer);
|
||||
|
||||
ProgressStop();
|
||||
ProgressStop();
|
||||
|
||||
if (error || read != infilesize || (strcasestr(filename, ".dol") == 0 && strcasestr(filename, ".elf") == 0))
|
||||
{
|
||||
WindowPrompt(tr( "Error:" ), tr( "No data could be read." ), tr( "OK" ));
|
||||
FreeHomebrewBuffer();
|
||||
return MENU_NONE;
|
||||
}
|
||||
if (error || read != infilesize || (strcasestr(filename, ".dol") == 0 && strcasestr(filename, ".elf") == 0))
|
||||
{
|
||||
WindowPrompt(tr( "Error:" ), tr( "No data could be read." ), tr( "OK" ));
|
||||
FreeHomebrewBuffer();
|
||||
return MENU_NONE;
|
||||
}
|
||||
|
||||
CloseConnection();
|
||||
CloseConnection();
|
||||
|
||||
AddBootArgument(filename);
|
||||
AddBootArgument(filename);
|
||||
|
||||
return BootHomebrewFromMem();
|
||||
return BootHomebrewFromMem();
|
||||
}
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue