*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">
|
<app version="1">
|
||||||
<name> USB Loader GX</name>
|
<name> USB Loader GX</name>
|
||||||
<coder>USB Loader GX Team</coder>
|
<coder>USB Loader GX Team</coder>
|
||||||
<version>2.2 r1103</version>
|
<version>2.2 r1105</version>
|
||||||
<release_date>201107241629</release_date>
|
<release_date>201107252212</release_date>
|
||||||
<!-- // remove this line to enable arguments
|
<!-- // remove this line to enable arguments
|
||||||
<arguments>
|
<arguments>
|
||||||
<arg>--ios=250</arg>
|
<arg>--ios=250</arg>
|
||||||
<arg>--usbport=0</arg>
|
<arg>--usbport=0</arg>
|
||||||
</arguments>
|
</arguments>
|
||||||
// remove this line to enable arguments -->
|
// remove this line to enable arguments -->
|
||||||
<no_ios_reload/>
|
<no_ios_reload/>
|
||||||
<short_description>Loads games from USB-devices</short_description>
|
<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.
|
<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
|
count=0
|
||||||
for i in $(find ./data/images/ ./data/sounds/ ./data/fonts/ -maxdepth 1 -type f \( ! -printf "%f\n" \))
|
for i in $(find ./data/images/ ./data/sounds/ ./data/fonts/ -maxdepth 1 -type f \( ! -printf "%f\n" \))
|
||||||
do
|
do
|
||||||
files[count]=$i
|
files[count]=$i
|
||||||
count=$((count+1))
|
count=$((count+1))
|
||||||
done
|
done
|
||||||
|
|
||||||
if [ "$count_old" != "$count" ] || [ ! -f $outFile ]
|
if [ "$count_old" != "$count" ] || [ ! -f $outFile ]
|
||||||
|
@ -35,11 +35,11 @@ EOF
|
||||||
|
|
||||||
for i in ${files[@]}
|
for i in ${files[@]}
|
||||||
do
|
do
|
||||||
filename=${i%.*}
|
filename=${i%.*}
|
||||||
extension=${i##*.}
|
extension=${i##*.}
|
||||||
echo 'extern const u8 '$filename'_'$extension'[];' >> $outFile
|
echo 'extern const u8 '$filename'_'$extension'[];' >> $outFile
|
||||||
echo 'extern const u32 '$filename'_'$extension'_size;' >> $outFile
|
echo 'extern const u32 '$filename'_'$extension'_size;' >> $outFile
|
||||||
echo '' >> $outFile
|
echo '' >> $outFile
|
||||||
done
|
done
|
||||||
|
|
||||||
echo 'RecourceFile Resources::RecourceFiles[] =' >> $outFile
|
echo 'RecourceFile Resources::RecourceFiles[] =' >> $outFile
|
||||||
|
@ -47,9 +47,9 @@ echo '{' >> $outFile
|
||||||
|
|
||||||
for i in ${files[@]}
|
for i in ${files[@]}
|
||||||
do
|
do
|
||||||
filename=${i%.*}
|
filename=${i%.*}
|
||||||
extension=${i##*.}
|
extension=${i##*.}
|
||||||
echo -e '\t{"'$i'", '$filename'_'$extension', '$filename'_'$extension'_size, NULL, 0},' >> $outFile
|
echo -e '\t{"'$i'", '$filename'_'$extension', '$filename'_'$extension'_size, NULL, 0},' >> $outFile
|
||||||
done
|
done
|
||||||
|
|
||||||
echo -e '\t{NULL, NULL, 0, NULL, 0}' >> $outFile
|
echo -e '\t{NULL, NULL, 0, NULL, 0}' >> $outFile
|
||||||
|
|
|
@ -29,361 +29,361 @@
|
||||||
extern GuiImageData * pointer[4];
|
extern GuiImageData * pointer[4];
|
||||||
|
|
||||||
BoxCover::BoxCover(GuiImageData * img, bool flat)
|
BoxCover::BoxCover(GuiImageData * img, bool flat)
|
||||||
: GuiImage(img),
|
: GuiImage(img),
|
||||||
boxBorder(Resources::GetFile("boxBorder.png"), Resources::GetFileSize("boxBorder.png")),
|
boxBorder(Resources::GetFile("boxBorder.png"), Resources::GetFileSize("boxBorder.png")),
|
||||||
defaultBox(NULL)
|
defaultBox(NULL)
|
||||||
{
|
{
|
||||||
flatCover = flat;
|
flatCover = flat;
|
||||||
Zoomable = false;
|
Zoomable = false;
|
||||||
moveChan = -1;
|
moveChan = -1;
|
||||||
moveStartPosX = 0;
|
moveStartPosX = 0;
|
||||||
moveStartPosY = 0;
|
moveStartPosY = 0;
|
||||||
movePosX = 0.0f;
|
movePosX = 0.0f;
|
||||||
movePosY = 0.0f;
|
movePosY = 0.0f;
|
||||||
RotX = 0.0f;
|
RotX = 0.0f;
|
||||||
RotY = 0.0f;
|
RotY = 0.0f;
|
||||||
RotZ = 0.0f;
|
RotZ = 0.0f;
|
||||||
PosX = 0.0f;
|
PosX = 0.0f;
|
||||||
PosY = 0.0f;
|
PosY = 0.0f;
|
||||||
PosZ = -27.f;
|
PosZ = -27.f;
|
||||||
AnimRotate = 0.0f;
|
AnimRotate = 0.0f;
|
||||||
last_manual_move_frame = 0;
|
last_manual_move_frame = 0;
|
||||||
guVector camera = (guVector) {0.0F, 0.0F, 0.0F};
|
guVector camera = (guVector) {0.0F, 0.0F, 0.0F};
|
||||||
guVector up = (guVector) {0.0F, 1.0F, 0.0F};
|
guVector up = (guVector) {0.0F, 1.0F, 0.0F};
|
||||||
guVector look = (guVector) {0.0F, 0.0F, -1.0F};
|
guVector look = (guVector) {0.0F, 0.0F, -1.0F};
|
||||||
boxColor = (GXColor) {233, 233, 233, 255};
|
boxColor = (GXColor) {233, 233, 233, 255};
|
||||||
|
|
||||||
guLookAt(view, &camera, &up, &look);
|
guLookAt(view, &camera, &up, &look);
|
||||||
guPerspective(projection, 8, 640.f/480.f, 1.0f, 300.0F);
|
guPerspective(projection, 8, 640.f/480.f, 1.0f, 300.0F);
|
||||||
|
|
||||||
//! Remove me later
|
//! Remove me later
|
||||||
for(int i = 0; i < 4; ++i)
|
for(int i = 0; i < 4; ++i)
|
||||||
{
|
{
|
||||||
char name[50];
|
char name[50];
|
||||||
snprintf(name, sizeof(name), "player%i_grab.png", i+1);
|
snprintf(name, sizeof(name), "player%i_grab.png", i+1);
|
||||||
GrabPointers[i] = Resources::GetImageData(name);
|
GrabPointers[i] = Resources::GetImageData(name);
|
||||||
NormalPointers[i] = pointer[i];
|
NormalPointers[i] = pointer[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
if(flatCover || !image)
|
if(flatCover || !image)
|
||||||
{
|
{
|
||||||
defaultBox = Resources::GetImageData("nocoverFull.png");
|
defaultBox = Resources::GetImageData("nocoverFull.png");
|
||||||
GX_InitTexObj(&defaultBoxTex, defaultBox->GetImage(), defaultBox->GetWidth(), defaultBox->GetHeight(), defaultBox->GetTextureFormat(),GX_CLAMP, GX_CLAMP,GX_FALSE);
|
GX_InitTexObj(&defaultBoxTex, defaultBox->GetImage(), defaultBox->GetWidth(), defaultBox->GetHeight(), defaultBox->GetTextureFormat(),GX_CLAMP, GX_CLAMP,GX_FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!image)
|
if(!image)
|
||||||
{
|
{
|
||||||
GX_InitTexObj(&coverTex, defaultBox->GetImage(), defaultBox->GetWidth(), defaultBox->GetHeight(), defaultBox->GetTextureFormat(),GX_CLAMP, GX_CLAMP,GX_FALSE);
|
GX_InitTexObj(&coverTex, defaultBox->GetImage(), defaultBox->GetWidth(), defaultBox->GetHeight(), defaultBox->GetTextureFormat(),GX_CLAMP, GX_CLAMP,GX_FALSE);
|
||||||
flatCover = false;
|
flatCover = false;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
GX_InitTexObj(&coverTex, image, width,height, GX_TF_RGBA8,GX_CLAMP, GX_CLAMP,GX_FALSE);
|
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()
|
BoxCover::~BoxCover()
|
||||||
{
|
{
|
||||||
delete defaultBox;
|
delete defaultBox;
|
||||||
for(int i = 0; i < 4; ++i)
|
for(int i = 0; i < 4; ++i)
|
||||||
{
|
{
|
||||||
pointer[i] = NormalPointers[i];
|
pointer[i] = NormalPointers[i];
|
||||||
delete GrabPointers[i];
|
delete GrabPointers[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//! Remove me later
|
//! Remove me later
|
||||||
void BoxCover::WiiPADControl(GuiTrigger *t)
|
void BoxCover::WiiPADControl(GuiTrigger *t)
|
||||||
{
|
{
|
||||||
if(t->wpad.btns_d & WPAD_BUTTON_A)
|
if(t->wpad.btns_d & WPAD_BUTTON_A)
|
||||||
{
|
{
|
||||||
if(t->wpad.ir.valid)
|
if(t->wpad.ir.valid)
|
||||||
{
|
{
|
||||||
moveChan = t->chan;
|
moveChan = t->chan;
|
||||||
moveStartPosX = t->wpad.ir.x;
|
moveStartPosX = t->wpad.ir.x;
|
||||||
moveStartPosY = t->wpad.ir.y;
|
moveStartPosY = t->wpad.ir.y;
|
||||||
PosX += movePosX;
|
PosX += movePosX;
|
||||||
PosY += movePosY;
|
PosY += movePosY;
|
||||||
movePosX = 0.0f;
|
movePosX = 0.0f;
|
||||||
movePosY = 0.0f;
|
movePosY = 0.0f;
|
||||||
for(int i = 0; i < 4; ++i)
|
for(int i = 0; i < 4; ++i)
|
||||||
pointer[i] = GrabPointers[i];
|
pointer[i] = GrabPointers[i];
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
moveChan = -1;
|
moveChan = -1;
|
||||||
}
|
}
|
||||||
else if((t->wpad.btns_h & WPAD_BUTTON_A) && moveChan == t->chan && t->wpad.ir.valid && !effects)
|
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;
|
movePosX = (t->wpad.ir.x-moveStartPosX) * fabs(PosZ)/3400.f;
|
||||||
movePosY = (moveStartPosY-t->wpad.ir.y) * fabs(PosZ)/3400.f;
|
movePosY = (moveStartPosY-t->wpad.ir.y) * fabs(PosZ)/3400.f;
|
||||||
last_manual_move_frame = frameCount;
|
last_manual_move_frame = frameCount;
|
||||||
}
|
}
|
||||||
else if(!(t->wpad.btns_h & WPAD_BUTTON_A) && moveChan == t->chan)
|
else if(!(t->wpad.btns_h & WPAD_BUTTON_A) && moveChan == t->chan)
|
||||||
{
|
{
|
||||||
for(int i = 0; i < 4; ++i)
|
for(int i = 0; i < 4; ++i)
|
||||||
pointer[i] = NormalPointers[i];
|
pointer[i] = NormalPointers[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
if(t->wpad.btns_h & WPAD_BUTTON_UP)
|
if(t->wpad.btns_h & WPAD_BUTTON_UP)
|
||||||
{
|
{
|
||||||
RotX -= 2.0f;
|
RotX -= 2.0f;
|
||||||
last_manual_move_frame = frameCount;
|
last_manual_move_frame = frameCount;
|
||||||
}
|
}
|
||||||
if(t->wpad.btns_h & WPAD_BUTTON_DOWN)
|
if(t->wpad.btns_h & WPAD_BUTTON_DOWN)
|
||||||
{
|
{
|
||||||
RotX += 2.0f;
|
RotX += 2.0f;
|
||||||
last_manual_move_frame = frameCount;
|
last_manual_move_frame = frameCount;
|
||||||
}
|
}
|
||||||
if(t->wpad.btns_h & WPAD_BUTTON_LEFT)
|
if(t->wpad.btns_h & WPAD_BUTTON_LEFT)
|
||||||
{
|
{
|
||||||
RotY -= 2.0f;
|
RotY -= 2.0f;
|
||||||
last_manual_move_frame = frameCount;
|
last_manual_move_frame = frameCount;
|
||||||
}
|
}
|
||||||
if(t->wpad.btns_h & WPAD_BUTTON_RIGHT)
|
if(t->wpad.btns_h & WPAD_BUTTON_RIGHT)
|
||||||
{
|
{
|
||||||
RotY += 2.0f;
|
RotY += 2.0f;
|
||||||
last_manual_move_frame = frameCount;
|
last_manual_move_frame = frameCount;
|
||||||
}
|
}
|
||||||
if(t->wpad.btns_d & WPAD_BUTTON_2)
|
if(t->wpad.btns_d & WPAD_BUTTON_2)
|
||||||
{
|
{
|
||||||
if(RotY < 180.0f)
|
if(RotY < 180.0f)
|
||||||
SetEffect(EFFECT_BOX_ROTATE_X, 10, 180);
|
SetEffect(EFFECT_BOX_ROTATE_X, 10, 180);
|
||||||
else
|
else
|
||||||
SetEffect(EFFECT_BOX_ROTATE_X, -10, -180);
|
SetEffect(EFFECT_BOX_ROTATE_X, -10, -180);
|
||||||
last_manual_move_frame = frameCount;
|
last_manual_move_frame = frameCount;
|
||||||
}
|
}
|
||||||
if(t->wpad.btns_h & WPAD_BUTTON_PLUS)
|
if(t->wpad.btns_h & WPAD_BUTTON_PLUS)
|
||||||
{
|
{
|
||||||
if(PosZ < -2.8f)
|
if(PosZ < -2.8f)
|
||||||
PosZ += 0.4f*fabs(PosZ)/19.f;
|
PosZ += 0.4f*fabs(PosZ)/19.f;
|
||||||
}
|
}
|
||||||
if(t->wpad.btns_h & WPAD_BUTTON_MINUS)
|
if(t->wpad.btns_h & WPAD_BUTTON_MINUS)
|
||||||
{
|
{
|
||||||
if(PosZ > -43.0f)
|
if(PosZ > -43.0f)
|
||||||
PosZ -= 0.4f*fabs(PosZ)/19.f;
|
PosZ -= 0.4f*fabs(PosZ)/19.f;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void BoxCover::Update(GuiTrigger * t)
|
void BoxCover::Update(GuiTrigger * t)
|
||||||
{
|
{
|
||||||
s8 movY = t->WPAD_Stick(0, 0) ;
|
s8 movY = t->WPAD_Stick(0, 0) ;
|
||||||
s8 movX = t->WPAD_Stick(0, 1);
|
s8 movX = t->WPAD_Stick(0, 1);
|
||||||
//! Drop nunchuck moves of less than 5 because of sensitivity
|
//! Drop nunchuck moves of less than 5 because of sensitivity
|
||||||
if(fabs(movY) < 5.0f) movY = 0;
|
if(fabs(movY) < 5.0f) movY = 0;
|
||||||
if(fabs(movX) < 5.0f) movX = 0;
|
if(fabs(movX) < 5.0f) movX = 0;
|
||||||
|
|
||||||
if(movY != 0 || movX != 0)
|
if(movY != 0 || movX != 0)
|
||||||
last_manual_move_frame = frameCount;
|
last_manual_move_frame = frameCount;
|
||||||
|
|
||||||
RotY += (f32) movY / 50.0f;
|
RotY += (f32) movY / 50.0f;
|
||||||
RotX -= (f32) movX / 50.0f;
|
RotX -= (f32) movX / 50.0f;
|
||||||
|
|
||||||
if(Zoomable)
|
if(Zoomable)
|
||||||
WiiPADControl(t);
|
WiiPADControl(t);
|
||||||
|
|
||||||
//! Stop movement for about 5 sec after manual move
|
//! Stop movement for about 5 sec after manual move
|
||||||
if(frameCount-last_manual_move_frame < 250)
|
if(frameCount-last_manual_move_frame < 250)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Animation = sin(DegToRad(AnimRotate))*2.0f;
|
Animation = sin(DegToRad(AnimRotate))*2.0f;
|
||||||
Animation2 = cos(DegToRad(AnimRotate))*5.0f;
|
Animation2 = cos(DegToRad(AnimRotate))*5.0f;
|
||||||
AnimRotate += 0.1f;
|
AnimRotate += 0.1f;
|
||||||
if(AnimRotate > 360.0f)
|
if(AnimRotate > 360.0f)
|
||||||
AnimRotate = 0.0f;
|
AnimRotate = 0.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BoxCover::Draw()
|
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_POS, GX_INDEX8);
|
||||||
GX_SetVtxDesc(GX_VA_CLR0, GX_DIRECT);
|
GX_SetVtxDesc(GX_VA_CLR0, GX_DIRECT);
|
||||||
GX_SetVtxDesc(GX_VA_TEX0, GX_INDEX8);
|
GX_SetVtxDesc(GX_VA_TEX0, GX_INDEX8);
|
||||||
|
|
||||||
Mtx modelView;
|
Mtx modelView;
|
||||||
Mtx modelView2;
|
Mtx modelView2;
|
||||||
Mtx modelView3;
|
Mtx modelView3;
|
||||||
|
|
||||||
guVector cubeAxis = {0,0,1};
|
guVector cubeAxis = {0,0,1};
|
||||||
guVector cubeAxis2 = {0,1,0};
|
guVector cubeAxis2 = {0,1,0};
|
||||||
guVector cubeAxis3 = {1,0,0};
|
guVector cubeAxis3 = {1,0,0};
|
||||||
guMtxIdentity(modelView);
|
guMtxIdentity(modelView);
|
||||||
guMtxRotAxisDeg(modelView3, &cubeAxis3, RotX-Animation2);
|
guMtxRotAxisDeg(modelView3, &cubeAxis3, RotX-Animation2);
|
||||||
guMtxRotAxisDeg(modelView2, &cubeAxis2, RotY+Animation2+xoffsetDyn/2.0f);
|
guMtxRotAxisDeg(modelView2, &cubeAxis2, RotY+Animation2+xoffsetDyn/2.0f);
|
||||||
guMtxRotAxisDeg(modelView, &cubeAxis, RotZ-Animation);
|
guMtxRotAxisDeg(modelView, &cubeAxis, RotZ-Animation);
|
||||||
guMtxConcat(modelView3, modelView2, modelView2);
|
guMtxConcat(modelView3, modelView2, modelView2);
|
||||||
guMtxConcat(modelView2, modelView, modelView);
|
guMtxConcat(modelView2, modelView, modelView);
|
||||||
if(Settings.widescreen)
|
if(Settings.widescreen)
|
||||||
guMtxScaleApply(modelView, modelView, Settings.WSFactor, 1.0f, 1.0f);
|
guMtxScaleApply(modelView, modelView, Settings.WSFactor, 1.0f, 1.0f);
|
||||||
guMtxTransApply(modelView, modelView, PosX+xoffsetDyn/680.0f+movePosX, PosY+yoffsetDyn/680.0f+movePosY, PosZ);
|
guMtxTransApply(modelView, modelView, PosX+xoffsetDyn/680.0f+movePosX, PosY+yoffsetDyn/680.0f+movePosY, PosZ);
|
||||||
guMtxConcat(view,modelView,modelView);
|
guMtxConcat(view,modelView,modelView);
|
||||||
|
|
||||||
GX_LoadPosMtxImm(modelView, GX_PNMTX0);
|
GX_LoadPosMtxImm(modelView, GX_PNMTX0);
|
||||||
|
|
||||||
//! Border quads
|
//! Border quads
|
||||||
GX_LoadTexObj(&boxBorderTex, GX_TEXMAP0);
|
GX_LoadTexObj(&boxBorderTex, GX_TEXMAP0);
|
||||||
GX_InvalidateTexAll();
|
GX_InvalidateTexAll();
|
||||||
|
|
||||||
GX_SetArray(GX_VA_POS, (void *) &g_boxMeshQ[0].pos, 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_SetArray(GX_VA_TEX0, (void *) &g_boxMeshQ[0].texCoord, sizeof(g_boxMeshQ[0]));
|
||||||
|
|
||||||
GX_Begin(GX_QUADS, GX_VTXFMT0, g_boxMeshQSize);
|
GX_Begin(GX_QUADS, GX_VTXFMT0, g_boxMeshQSize);
|
||||||
for (u32 j = 0; j < g_boxMeshQSize; ++j)
|
for (u32 j = 0; j < g_boxMeshQSize; ++j)
|
||||||
{
|
{
|
||||||
GX_Position1x8(j);
|
GX_Position1x8(j);
|
||||||
GX_Color4u8(boxColor.r, boxColor.g, boxColor.b, BoxAlpha);
|
GX_Color4u8(boxColor.r, boxColor.g, boxColor.b, BoxAlpha);
|
||||||
GX_TexCoord1x8(j);
|
GX_TexCoord1x8(j);
|
||||||
}
|
}
|
||||||
GX_End();
|
GX_End();
|
||||||
|
|
||||||
//! Border triangles
|
//! Border triangles
|
||||||
GX_SetArray(GX_VA_POS, (void *) &g_boxMeshT[0].pos, sizeof(g_boxMeshT[0]));
|
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_SetArray(GX_VA_TEX0, (void *) &g_boxMeshT[0].texCoord, sizeof(g_boxMeshT[0]));
|
||||||
|
|
||||||
GX_Begin(GX_TRIANGLES, GX_VTXFMT0, g_boxMeshTSize);
|
GX_Begin(GX_TRIANGLES, GX_VTXFMT0, g_boxMeshTSize);
|
||||||
for (u32 j = 0; j < g_boxMeshTSize; ++j)
|
for (u32 j = 0; j < g_boxMeshTSize; ++j)
|
||||||
{
|
{
|
||||||
GX_Position1x8(j);
|
GX_Position1x8(j);
|
||||||
GX_Color4u8(boxColor.r, boxColor.g, boxColor.b, BoxAlpha);
|
GX_Color4u8(boxColor.r, boxColor.g, boxColor.b, BoxAlpha);
|
||||||
GX_TexCoord1x8(j);
|
GX_TexCoord1x8(j);
|
||||||
}
|
}
|
||||||
GX_End();
|
GX_End();
|
||||||
|
|
||||||
//! Back Cover (Might be flat)
|
//! Back Cover (Might be flat)
|
||||||
GX_LoadTexObj(flatCover ? &defaultBoxTex : &coverTex, GX_TEXMAP0);
|
GX_LoadTexObj(flatCover ? &defaultBoxTex : &coverTex, GX_TEXMAP0);
|
||||||
GX_InvalidateTexAll();
|
GX_InvalidateTexAll();
|
||||||
|
|
||||||
GX_SetArray(GX_VA_POS, (void *) &g_boxBackCoverMesh[0].pos, 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_SetArray(GX_VA_TEX0, (void *) &g_boxBackCoverMesh[0].texCoord, sizeof(g_boxBackCoverMesh[0]));
|
||||||
|
|
||||||
GX_Begin(GX_QUADS, GX_VTXFMT0, g_boxBackCoverMeshSize);
|
GX_Begin(GX_QUADS, GX_VTXFMT0, g_boxBackCoverMeshSize);
|
||||||
for (u32 j = 0; j < g_boxBackCoverMeshSize; ++j)
|
for (u32 j = 0; j < g_boxBackCoverMeshSize; ++j)
|
||||||
{
|
{
|
||||||
GX_Position1x8(j);
|
GX_Position1x8(j);
|
||||||
if(flatCover)
|
if(flatCover)
|
||||||
GX_Color4u8(boxColor.r, boxColor.g, boxColor.b, BoxAlpha);
|
GX_Color4u8(boxColor.r, boxColor.g, boxColor.b, BoxAlpha);
|
||||||
else
|
else
|
||||||
GX_Color4u8(0xff, 0xff, 0xff, BoxAlpha);
|
GX_Color4u8(0xff, 0xff, 0xff, BoxAlpha);
|
||||||
GX_TexCoord1x8(j);
|
GX_TexCoord1x8(j);
|
||||||
}
|
}
|
||||||
GX_End();
|
GX_End();
|
||||||
|
|
||||||
if(flatCover)
|
if(flatCover)
|
||||||
{
|
{
|
||||||
//! Front Flat Cover
|
//! Front Flat Cover
|
||||||
GX_LoadTexObj(&coverTex, GX_TEXMAP0);
|
GX_LoadTexObj(&coverTex, GX_TEXMAP0);
|
||||||
GX_InvalidateTexAll();
|
GX_InvalidateTexAll();
|
||||||
|
|
||||||
GX_SetArray(GX_VA_POS, (void *) &g_flatCoverMesh[0].pos, 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_SetArray(GX_VA_TEX0, (void *) &g_flatCoverMesh[0].texCoord, sizeof(g_flatCoverMesh[0]));
|
||||||
|
|
||||||
GX_Begin(GX_QUADS, GX_VTXFMT0, g_flatCoverMeshSize);
|
GX_Begin(GX_QUADS, GX_VTXFMT0, g_flatCoverMeshSize);
|
||||||
for (u32 j = 0; j < g_flatCoverMeshSize; ++j)
|
for (u32 j = 0; j < g_flatCoverMeshSize; ++j)
|
||||||
{
|
{
|
||||||
GX_Position1x8(j);
|
GX_Position1x8(j);
|
||||||
GX_Color4u8(0xff, 0xff, 0xff, 0xff);
|
GX_Color4u8(0xff, 0xff, 0xff, 0xff);
|
||||||
GX_TexCoord1x8(j);
|
GX_TexCoord1x8(j);
|
||||||
}
|
}
|
||||||
GX_End();
|
GX_End();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
//! Front Cover
|
//! Front Cover
|
||||||
GX_SetArray(GX_VA_POS, (void *) &g_boxCoverMesh[0].pos, sizeof(g_boxCoverMesh[0]));
|
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_SetArray(GX_VA_TEX0, (void *) &g_boxCoverMesh[0].texCoord, sizeof(g_boxCoverMesh[0]));
|
||||||
|
|
||||||
GX_Begin(GX_QUADS, GX_VTXFMT0, g_boxCoverMeshSize);
|
GX_Begin(GX_QUADS, GX_VTXFMT0, g_boxCoverMeshSize);
|
||||||
for (u32 j = 0; j < g_boxCoverMeshSize; ++j)
|
for (u32 j = 0; j < g_boxCoverMeshSize; ++j)
|
||||||
{
|
{
|
||||||
GX_Position1x8(j);
|
GX_Position1x8(j);
|
||||||
GX_Color4u8(0xff, 0xff, 0xff, BoxAlpha);
|
GX_Color4u8(0xff, 0xff, 0xff, BoxAlpha);
|
||||||
GX_TexCoord1x8(j);
|
GX_TexCoord1x8(j);
|
||||||
}
|
}
|
||||||
GX_End();
|
GX_End();
|
||||||
}
|
}
|
||||||
|
|
||||||
UpdateEffects();
|
UpdateEffects();
|
||||||
}
|
}
|
||||||
|
|
||||||
void BoxCover::SetEffect(int eff, int amount, int target)
|
void BoxCover::SetEffect(int eff, int amount, int target)
|
||||||
{
|
{
|
||||||
GuiImage::SetEffect(eff, amount, target);
|
GuiImage::SetEffect(eff, amount, target);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BoxCover::UpdateEffects()
|
void BoxCover::UpdateEffects()
|
||||||
{
|
{
|
||||||
GuiImage::UpdateEffects();
|
GuiImage::UpdateEffects();
|
||||||
|
|
||||||
if(effects & EFFECT_BOX_FLY_CENTRE)
|
if(effects & EFFECT_BOX_FLY_CENTRE)
|
||||||
{
|
{
|
||||||
if(PosX > 0.1f)
|
if(PosX > 0.1f)
|
||||||
PosX -= effectAmount/1200.f;
|
PosX -= effectAmount/1200.f;
|
||||||
if(PosY > 0.1f)
|
if(PosY > 0.1f)
|
||||||
PosY -= effectAmount/1200.f;
|
PosY -= effectAmount/1200.f;
|
||||||
if(PosX < -0.1f)
|
if(PosX < -0.1f)
|
||||||
PosX += effectAmount/1200.f;
|
PosX += effectAmount/1200.f;
|
||||||
if(PosY < -0.1f)
|
if(PosY < -0.1f)
|
||||||
PosY += effectAmount/1200.f;
|
PosY += effectAmount/1200.f;
|
||||||
|
|
||||||
movePosX = 0.0f;
|
movePosX = 0.0f;
|
||||||
movePosY = 0.0f;
|
movePosY = 0.0f;
|
||||||
PosZ += 0.4f;
|
PosZ += 0.4f;
|
||||||
RotY += effectAmount/4.9f;
|
RotY += effectAmount/4.9f;
|
||||||
|
|
||||||
if(fabs(PosX) < 0.1f && fabs(PosY) < 0.1f)
|
if(fabs(PosX) < 0.1f && fabs(PosY) < 0.1f)
|
||||||
{
|
{
|
||||||
PosX = 0.0f;
|
PosX = 0.0f;
|
||||||
PosY = 0.0f;
|
PosY = 0.0f;
|
||||||
effects = 0;
|
effects = 0;
|
||||||
effectAmount = 0;
|
effectAmount = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(effects & EFFECT_BOX_FLY_BACK)
|
else if(effects & EFFECT_BOX_FLY_BACK)
|
||||||
{
|
{
|
||||||
if(PosX > PosXOrig+0.1f)
|
if(PosX > PosXOrig+0.1f)
|
||||||
PosX -= effectAmount/1200.f;
|
PosX -= effectAmount/1200.f;
|
||||||
if(PosY > PosYOrig+0.1f)
|
if(PosY > PosYOrig+0.1f)
|
||||||
PosY -= effectAmount/1200.f;
|
PosY -= effectAmount/1200.f;
|
||||||
if(PosX < PosXOrig-0.1f)
|
if(PosX < PosXOrig-0.1f)
|
||||||
PosX += effectAmount/1200.f;
|
PosX += effectAmount/1200.f;
|
||||||
if(PosY < PosYOrig-0.1f)
|
if(PosY < PosYOrig-0.1f)
|
||||||
PosY += effectAmount/1200.f;
|
PosY += effectAmount/1200.f;
|
||||||
|
|
||||||
PosZ -= 0.4f;
|
PosZ -= 0.4f;
|
||||||
RotY -= effectAmount/4.9f;
|
RotY -= effectAmount/4.9f;
|
||||||
|
|
||||||
if(movePosX > 0.1f)
|
if(movePosX > 0.1f)
|
||||||
movePosX -= 0.1f;
|
movePosX -= 0.1f;
|
||||||
else if(movePosX < 0.1f)
|
else if(movePosX < 0.1f)
|
||||||
movePosX += 0.1f;
|
movePosX += 0.1f;
|
||||||
if(movePosY > 0.1f)
|
if(movePosY > 0.1f)
|
||||||
movePosY -= 0.1f;
|
movePosY -= 0.1f;
|
||||||
else if(movePosY < 0.1f)
|
else if(movePosY < 0.1f)
|
||||||
movePosY += 0.1f;
|
movePosY += 0.1f;
|
||||||
|
|
||||||
if(fabs(PosXOrig-PosX) < 0.1f && fabs(PosYOrig-PosY) < 0.1f)
|
if(fabs(PosXOrig-PosX) < 0.1f && fabs(PosYOrig-PosY) < 0.1f)
|
||||||
{
|
{
|
||||||
movePosX = 0.0f;
|
movePosX = 0.0f;
|
||||||
movePosY = 0.0f;
|
movePosY = 0.0f;
|
||||||
PosX = PosXOrig;
|
PosX = PosXOrig;
|
||||||
PosY = PosYOrig;
|
PosY = PosYOrig;
|
||||||
PosZ = PosZOrig;
|
PosZ = PosZOrig;
|
||||||
effects = 0;
|
effects = 0;
|
||||||
effectAmount = 0;
|
effectAmount = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(effects & EFFECT_BOX_ROTATE_X)
|
else if(effects & EFFECT_BOX_ROTATE_X)
|
||||||
{
|
{
|
||||||
RotY += effectAmount;
|
RotY += effectAmount;
|
||||||
effectTarget -= effectAmount;
|
effectTarget -= effectAmount;
|
||||||
|
|
||||||
if(fabs(effectTarget) < fabs(effectAmount))
|
if(fabs(effectTarget) < fabs(effectAmount))
|
||||||
{
|
{
|
||||||
effects = 0;
|
effects = 0;
|
||||||
effectAmount = 0;
|
effectAmount = 0;
|
||||||
effectTarget = 0;
|
effectTarget = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,58 +27,58 @@
|
||||||
#include "GUI/gui.h"
|
#include "GUI/gui.h"
|
||||||
|
|
||||||
#define EFFECT_BOX_FLY_CENTRE 0x2000000
|
#define EFFECT_BOX_FLY_CENTRE 0x2000000
|
||||||
#define EFFECT_BOX_FLY_BACK 0x4000000
|
#define EFFECT_BOX_FLY_BACK 0x4000000
|
||||||
#define EFFECT_BOX_ROTATE_X 0x8000000
|
#define EFFECT_BOX_ROTATE_X 0x8000000
|
||||||
|
|
||||||
class BoxCover : public GuiImage
|
class BoxCover : public GuiImage
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
BoxCover(GuiImageData * img, bool flat = false);
|
BoxCover(GuiImageData * img, bool flat = false);
|
||||||
virtual ~BoxCover();
|
virtual ~BoxCover();
|
||||||
//! Colors:
|
//! Colors:
|
||||||
//! Gray Box (Default): r:233 g:233 b:233
|
//! Gray Box (Default): r:233 g:233 b:233
|
||||||
//! Red Box (NSMB): r:198 g:34 b:4
|
//! Red Box (NSMB): r:198 g:34 b:4
|
||||||
void SetBoxColor(GXColor c) { LOCK(this); boxColor = c; };
|
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 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 SetEffect(int eff, int amount, int target = 0);
|
||||||
void SetImage(GuiImageData *img); //forbid this call
|
void SetImage(GuiImageData *img); //forbid this call
|
||||||
void SetZoomable(bool z) { LOCK(this); Zoomable = z; };
|
void SetZoomable(bool z) { LOCK(this); Zoomable = z; };
|
||||||
void Draw();
|
void Draw();
|
||||||
void Update(GuiTrigger * t);
|
void Update(GuiTrigger * t);
|
||||||
void UpdateEffects();
|
void UpdateEffects();
|
||||||
private:
|
private:
|
||||||
void WiiPADControl(GuiTrigger *t);
|
void WiiPADControl(GuiTrigger *t);
|
||||||
|
|
||||||
f32 RotX;
|
f32 RotX;
|
||||||
f32 RotY;
|
f32 RotY;
|
||||||
f32 RotZ;
|
f32 RotZ;
|
||||||
f32 PosX;
|
f32 PosX;
|
||||||
f32 PosY;
|
f32 PosY;
|
||||||
f32 PosZ;
|
f32 PosZ;
|
||||||
f32 PosXOrig;
|
f32 PosXOrig;
|
||||||
f32 PosYOrig;
|
f32 PosYOrig;
|
||||||
f32 PosZOrig;
|
f32 PosZOrig;
|
||||||
f32 AnimRotate;
|
f32 AnimRotate;
|
||||||
f32 Animation;
|
f32 Animation;
|
||||||
f32 Animation2;
|
f32 Animation2;
|
||||||
u32 last_manual_move_frame;
|
u32 last_manual_move_frame;
|
||||||
int moveStartPosX;
|
int moveStartPosX;
|
||||||
int moveStartPosY;
|
int moveStartPosY;
|
||||||
f32 movePosX;
|
f32 movePosX;
|
||||||
f32 movePosY;
|
f32 movePosY;
|
||||||
int moveChan;
|
int moveChan;
|
||||||
bool flatCover;
|
bool flatCover;
|
||||||
bool Zoomable;
|
bool Zoomable;
|
||||||
Mtx44 projection;
|
Mtx44 projection;
|
||||||
GuiImageData boxBorder;
|
GuiImageData boxBorder;
|
||||||
GuiImageData *defaultBox;
|
GuiImageData *defaultBox;
|
||||||
GuiImageData *NormalPointers[4];
|
GuiImageData *NormalPointers[4];
|
||||||
GuiImageData *GrabPointers[4];
|
GuiImageData *GrabPointers[4];
|
||||||
Mtx view;
|
Mtx view;
|
||||||
GXTexObj coverTex;
|
GXTexObj coverTex;
|
||||||
GXTexObj boxBorderTex;
|
GXTexObj boxBorderTex;
|
||||||
GXTexObj defaultBoxTex;
|
GXTexObj defaultBoxTex;
|
||||||
GXColor boxColor;
|
GXColor boxColor;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -40,7 +40,7 @@ DeviceHandler * DeviceHandler::instance = NULL;
|
||||||
|
|
||||||
DeviceHandler::~DeviceHandler()
|
DeviceHandler::~DeviceHandler()
|
||||||
{
|
{
|
||||||
UnMountAll();
|
UnMountAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
DeviceHandler * DeviceHandler::Instance()
|
DeviceHandler * DeviceHandler::Instance()
|
||||||
|
@ -54,295 +54,295 @@ DeviceHandler * DeviceHandler::Instance()
|
||||||
|
|
||||||
void DeviceHandler::DestroyInstance()
|
void DeviceHandler::DestroyInstance()
|
||||||
{
|
{
|
||||||
if(instance)
|
if(instance)
|
||||||
{
|
{
|
||||||
delete instance;
|
delete instance;
|
||||||
}
|
}
|
||||||
instance = NULL;
|
instance = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DeviceHandler::MountAll()
|
bool DeviceHandler::MountAll()
|
||||||
{
|
{
|
||||||
bool result = false;
|
bool result = false;
|
||||||
|
|
||||||
for(u32 i = SD; i < MAXDEVICES; i++)
|
for(u32 i = SD; i < MAXDEVICES; i++)
|
||||||
{
|
{
|
||||||
if(Mount(i))
|
if(Mount(i))
|
||||||
result = true;
|
result = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeviceHandler::UnMountAll()
|
void DeviceHandler::UnMountAll()
|
||||||
{
|
{
|
||||||
for(u32 i = SD; i < MAXDEVICES; i++)
|
for(u32 i = SD; i < MAXDEVICES; i++)
|
||||||
UnMount(i);
|
UnMount(i);
|
||||||
|
|
||||||
if(sd)
|
if(sd)
|
||||||
delete sd;
|
delete sd;
|
||||||
if(usb0)
|
if(usb0)
|
||||||
delete usb0;
|
delete usb0;
|
||||||
if(usb1)
|
if(usb1)
|
||||||
delete usb1;
|
delete usb1;
|
||||||
|
|
||||||
sd = NULL;
|
sd = NULL;
|
||||||
usb0 = NULL;
|
usb0 = NULL;
|
||||||
usb1 = NULL;
|
usb1 = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DeviceHandler::Mount(int dev)
|
bool DeviceHandler::Mount(int dev)
|
||||||
{
|
{
|
||||||
if(dev == SD)
|
if(dev == SD)
|
||||||
return MountSD();
|
return MountSD();
|
||||||
|
|
||||||
else if(dev >= USB1 && dev <= USB8)
|
else if(dev >= USB1 && dev <= USB8)
|
||||||
return MountUSB(dev-USB1);
|
return MountUSB(dev-USB1);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DeviceHandler::IsInserted(int dev)
|
bool DeviceHandler::IsInserted(int dev)
|
||||||
{
|
{
|
||||||
if(dev == SD)
|
if(dev == SD)
|
||||||
return SD_Inserted() && sd->IsMounted(0);
|
return SD_Inserted() && sd->IsMounted(0);
|
||||||
|
|
||||||
else if(dev >= USB1 && dev <= USB8)
|
else if(dev >= USB1 && dev <= USB8)
|
||||||
{
|
{
|
||||||
int portPart = PartitionToPortPartition(dev-USB1);
|
int portPart = PartitionToPortPartition(dev-USB1);
|
||||||
PartitionHandle *usb = instance->GetUSBHandleFromPartition(dev-USB1);
|
PartitionHandle *usb = instance->GetUSBHandleFromPartition(dev-USB1);
|
||||||
if(usb)
|
if(usb)
|
||||||
return usb->IsMounted(portPart);
|
return usb->IsMounted(portPart);
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeviceHandler::UnMount(int dev)
|
void DeviceHandler::UnMount(int dev)
|
||||||
{
|
{
|
||||||
if(dev == SD)
|
if(dev == SD)
|
||||||
UnMountSD();
|
UnMountSD();
|
||||||
|
|
||||||
else if(dev >= USB1 && dev <= USB8)
|
else if(dev >= USB1 && dev <= USB8)
|
||||||
UnMountUSB(dev-USB1);
|
UnMountUSB(dev-USB1);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DeviceHandler::MountSD()
|
bool DeviceHandler::MountSD()
|
||||||
{
|
{
|
||||||
if(!sd)
|
if(!sd)
|
||||||
sd = new PartitionHandle(&__io_wiisd);
|
sd = new PartitionHandle(&__io_wiisd);
|
||||||
|
|
||||||
if(sd->GetPartitionCount() < 1)
|
if(sd->GetPartitionCount() < 1)
|
||||||
{
|
{
|
||||||
delete sd;
|
delete sd;
|
||||||
sd = NULL;
|
sd = NULL;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
//! Mount only one SD Partition
|
//! Mount only one SD Partition
|
||||||
return sd->Mount(0, DeviceName[SD], true);
|
return sd->Mount(0, DeviceName[SD], true);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline bool USBSpinUp()
|
static inline bool USBSpinUp()
|
||||||
{
|
{
|
||||||
bool started0 = true;
|
bool started0 = true;
|
||||||
bool started1 = true;
|
bool started1 = true;
|
||||||
int retries = 400;
|
int retries = 400;
|
||||||
|
|
||||||
const DISC_INTERFACE * handle0 = NULL;
|
const DISC_INTERFACE * handle0 = NULL;
|
||||||
const DISC_INTERFACE * handle1 = NULL;
|
const DISC_INTERFACE * handle1 = NULL;
|
||||||
if(Settings.USBPort == 0 || Settings.USBPort == 2)
|
if(Settings.USBPort == 0 || Settings.USBPort == 2)
|
||||||
handle0 = DeviceHandler::GetUSB0Interface();
|
handle0 = DeviceHandler::GetUSB0Interface();
|
||||||
if(Settings.USBPort == 1 || Settings.USBPort == 2)
|
if(Settings.USBPort == 1 || Settings.USBPort == 2)
|
||||||
handle1 = DeviceHandler::GetUSB1Interface();
|
handle1 = DeviceHandler::GetUSB1Interface();
|
||||||
|
|
||||||
// wait 20 sec for the USB to spin up...stupid slow ass HDD
|
// wait 20 sec for the USB to spin up...stupid slow ass HDD
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
if(handle0)
|
if(handle0)
|
||||||
started0 = (handle0->startup() && handle0->isInserted());
|
started0 = (handle0->startup() && handle0->isInserted());
|
||||||
|
|
||||||
if(handle1)
|
if(handle1)
|
||||||
started1 = (handle1->startup() && handle1->isInserted());
|
started1 = (handle1->startup() && handle1->isInserted());
|
||||||
|
|
||||||
if(started0 && started1) break;
|
if(started0 && started1) break;
|
||||||
usleep(50000);
|
usleep(50000);
|
||||||
}
|
}
|
||||||
while(--retries > 0);
|
while(--retries > 0);
|
||||||
|
|
||||||
return (started0 && started1);
|
return (started0 && started1);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DeviceHandler::MountUSB(int pos)
|
bool DeviceHandler::MountUSB(int pos)
|
||||||
{
|
{
|
||||||
if(!usb0 && !usb1)
|
if(!usb0 && !usb1)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if(pos >= GetUSBPartitionCount())
|
if(pos >= GetUSBPartitionCount())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
int portPart = PartitionToPortPartition(pos);
|
int portPart = PartitionToPortPartition(pos);
|
||||||
|
|
||||||
if(PartitionToUSBPort(pos) == 0 && usb0)
|
if(PartitionToUSBPort(pos) == 0 && usb0)
|
||||||
return usb0->Mount(portPart, DeviceName[USB1+pos]);
|
return usb0->Mount(portPart, DeviceName[USB1+pos]);
|
||||||
else if(usb1)
|
else if(usb1)
|
||||||
return usb1->Mount(portPart, DeviceName[USB1+pos]);
|
return usb1->Mount(portPart, DeviceName[USB1+pos]);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DeviceHandler::MountAllUSB(bool spinup)
|
bool DeviceHandler::MountAllUSB(bool spinup)
|
||||||
{
|
{
|
||||||
if(spinup && !USBSpinUp())
|
if(spinup && !USBSpinUp())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if(!usb0 && (Settings.USBPort == 0 || Settings.USBPort == 2))
|
if(!usb0 && (Settings.USBPort == 0 || Settings.USBPort == 2))
|
||||||
usb0 = new PartitionHandle(GetUSB0Interface());
|
usb0 = new PartitionHandle(GetUSB0Interface());
|
||||||
if(!usb1 && (Settings.USBPort == 1 || Settings.USBPort == 2))
|
if(!usb1 && (Settings.USBPort == 1 || Settings.USBPort == 2))
|
||||||
usb1 = new PartitionHandle(GetUSB1Interface());
|
usb1 = new PartitionHandle(GetUSB1Interface());
|
||||||
|
|
||||||
if(usb0 && usb0->GetPartitionCount() < 1)
|
if(usb0 && usb0->GetPartitionCount() < 1)
|
||||||
{
|
{
|
||||||
delete usb0;
|
delete usb0;
|
||||||
usb0 = NULL;
|
usb0 = NULL;
|
||||||
}
|
}
|
||||||
if(usb1 && usb1->GetPartitionCount() < 1)
|
if(usb1 && usb1->GetPartitionCount() < 1)
|
||||||
{
|
{
|
||||||
delete usb1;
|
delete usb1;
|
||||||
usb1 = NULL;
|
usb1 = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool result = false;
|
bool result = false;
|
||||||
int partCount = GetUSBPartitionCount();
|
int partCount = GetUSBPartitionCount();
|
||||||
|
|
||||||
for(int i = 0; i < partCount; i++)
|
for(int i = 0; i < partCount; i++)
|
||||||
{
|
{
|
||||||
if(MountUSB(i))
|
if(MountUSB(i))
|
||||||
result = true;
|
result = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DeviceHandler::MountUSBPort1(bool spinup)
|
bool DeviceHandler::MountUSBPort1(bool spinup)
|
||||||
{
|
{
|
||||||
if(spinup && !USBSpinUp())
|
if(spinup && !USBSpinUp())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if(!usb1 && (Settings.USBPort == 1 || Settings.USBPort == 2))
|
if(!usb1 && (Settings.USBPort == 1 || Settings.USBPort == 2))
|
||||||
usb1 = new PartitionHandle(GetUSB1Interface());
|
usb1 = new PartitionHandle(GetUSB1Interface());
|
||||||
|
|
||||||
if(usb1 && usb1->GetPartitionCount() < 1)
|
if(usb1 && usb1->GetPartitionCount() < 1)
|
||||||
{
|
{
|
||||||
delete usb1;
|
delete usb1;
|
||||||
usb1 = NULL;
|
usb1 = NULL;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool result = false;
|
bool result = false;
|
||||||
int partCount = GetUSBPartitionCount();
|
int partCount = GetUSBPartitionCount();
|
||||||
int partCount0 = 0;
|
int partCount0 = 0;
|
||||||
if(usb0)
|
if(usb0)
|
||||||
partCount0 = usb0->GetPartitionCount();
|
partCount0 = usb0->GetPartitionCount();
|
||||||
|
|
||||||
for(int i = partCount0; i < partCount; i++)
|
for(int i = partCount0; i < partCount; i++)
|
||||||
{
|
{
|
||||||
if(MountUSB(i))
|
if(MountUSB(i))
|
||||||
result = true;
|
result = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeviceHandler::UnMountUSB(int pos)
|
void DeviceHandler::UnMountUSB(int pos)
|
||||||
{
|
{
|
||||||
if(pos >= GetUSBPartitionCount())
|
if(pos >= GetUSBPartitionCount())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
int portPart = PartitionToPortPartition(pos);
|
int portPart = PartitionToPortPartition(pos);
|
||||||
|
|
||||||
if(PartitionToUSBPort(pos) == 0 && usb0)
|
if(PartitionToUSBPort(pos) == 0 && usb0)
|
||||||
return usb0->UnMount(portPart);
|
return usb0->UnMount(portPart);
|
||||||
else if(usb1)
|
else if(usb1)
|
||||||
return usb1->UnMount(portPart);
|
return usb1->UnMount(portPart);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeviceHandler::UnMountAllUSB()
|
void DeviceHandler::UnMountAllUSB()
|
||||||
{
|
{
|
||||||
int partCount = GetUSBPartitionCount();
|
int partCount = GetUSBPartitionCount();
|
||||||
|
|
||||||
for(int i = 0; i < partCount; i++)
|
for(int i = 0; i < partCount; i++)
|
||||||
UnMountUSB(i);
|
UnMountUSB(i);
|
||||||
|
|
||||||
delete usb0;
|
delete usb0;
|
||||||
usb0 = NULL;
|
usb0 = NULL;
|
||||||
delete usb1;
|
delete usb1;
|
||||||
usb1 = NULL;
|
usb1 = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
int DeviceHandler::PathToDriveType(const char * path)
|
int DeviceHandler::PathToDriveType(const char * path)
|
||||||
{
|
{
|
||||||
if(!path)
|
if(!path)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
for(int i = SD; i < MAXDEVICES; i++)
|
for(int i = SD; i < MAXDEVICES; i++)
|
||||||
{
|
{
|
||||||
if(strncmp(path, DeviceName[i], strlen(DeviceName[i])) == 0)
|
if(strncmp(path, DeviceName[i], strlen(DeviceName[i])) == 0)
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char * DeviceHandler::GetFSName(int dev)
|
const char * DeviceHandler::GetFSName(int dev)
|
||||||
{
|
{
|
||||||
if(dev == SD && DeviceHandler::instance->sd)
|
if(dev == SD && DeviceHandler::instance->sd)
|
||||||
{
|
{
|
||||||
return DeviceHandler::instance->sd->GetFSName(0);
|
return DeviceHandler::instance->sd->GetFSName(0);
|
||||||
}
|
}
|
||||||
else if(dev >= USB1 && dev <= USB8)
|
else if(dev >= USB1 && dev <= USB8)
|
||||||
{
|
{
|
||||||
int partCount0 = 0;
|
int partCount0 = 0;
|
||||||
int partCount1 = 0;
|
int partCount1 = 0;
|
||||||
if(DeviceHandler::instance->usb0)
|
if(DeviceHandler::instance->usb0)
|
||||||
partCount0 += DeviceHandler::instance->usb0->GetPartitionCount();
|
partCount0 += DeviceHandler::instance->usb0->GetPartitionCount();
|
||||||
if(DeviceHandler::instance->usb1)
|
if(DeviceHandler::instance->usb1)
|
||||||
partCount1 += DeviceHandler::instance->usb1->GetPartitionCount();
|
partCount1 += DeviceHandler::instance->usb1->GetPartitionCount();
|
||||||
|
|
||||||
if(dev-USB1 > partCount0 && DeviceHandler::instance->usb0)
|
if(dev-USB1 > partCount0 && DeviceHandler::instance->usb0)
|
||||||
return DeviceHandler::instance->usb0->GetFSName(dev-USB1);
|
return DeviceHandler::instance->usb0->GetFSName(dev-USB1);
|
||||||
else if(DeviceHandler::instance->usb1)
|
else if(DeviceHandler::instance->usb1)
|
||||||
return DeviceHandler::instance->usb1->GetFSName(dev-USB1-partCount0);
|
return DeviceHandler::instance->usb1->GetFSName(dev-USB1-partCount0);
|
||||||
}
|
}
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
int DeviceHandler::GetUSBFilesystemType(int partition)
|
int DeviceHandler::GetUSBFilesystemType(int partition)
|
||||||
{
|
{
|
||||||
if(!instance)
|
if(!instance)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
const char *FSName = GetUSBFSName(partition);
|
const char *FSName = GetUSBFSName(partition);
|
||||||
if(!FSName) return -1;
|
if(!FSName) return -1;
|
||||||
|
|
||||||
if(strncmp(FSName, "WBFS", 4) == 0)
|
if(strncmp(FSName, "WBFS", 4) == 0)
|
||||||
return PART_FS_WBFS;
|
return PART_FS_WBFS;
|
||||||
else if(strncmp(FSName, "FAT", 3) == 0)
|
else if(strncmp(FSName, "FAT", 3) == 0)
|
||||||
return PART_FS_FAT;
|
return PART_FS_FAT;
|
||||||
else if(strncmp(FSName, "NTFS", 4) == 0)
|
else if(strncmp(FSName, "NTFS", 4) == 0)
|
||||||
return PART_FS_NTFS;
|
return PART_FS_NTFS;
|
||||||
else if(strncmp(FSName, "LINUX", 4) == 0)
|
else if(strncmp(FSName, "LINUX", 4) == 0)
|
||||||
return PART_FS_EXT;
|
return PART_FS_EXT;
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
u16 DeviceHandler::GetUSBPartitionCount()
|
u16 DeviceHandler::GetUSBPartitionCount()
|
||||||
{
|
{
|
||||||
if(!instance)
|
if(!instance)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
u16 partCount0 = 0;
|
u16 partCount0 = 0;
|
||||||
u16 partCount1 = 0;
|
u16 partCount1 = 0;
|
||||||
|
@ -351,37 +351,37 @@ u16 DeviceHandler::GetUSBPartitionCount()
|
||||||
if(instance->usb1)
|
if(instance->usb1)
|
||||||
partCount1 = instance->usb1->GetPartitionCount();
|
partCount1 = instance->usb1->GetPartitionCount();
|
||||||
|
|
||||||
return partCount0+partCount1;
|
return partCount0+partCount1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int DeviceHandler::PartitionToUSBPort(int part)
|
int DeviceHandler::PartitionToUSBPort(int part)
|
||||||
{
|
{
|
||||||
if(!DeviceHandler::instance)
|
if(!DeviceHandler::instance)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
u16 partCount0 = 0;
|
u16 partCount0 = 0;
|
||||||
if(DeviceHandler::instance->usb0)
|
if(DeviceHandler::instance->usb0)
|
||||||
partCount0 = instance->usb0->GetPartitionCount();
|
partCount0 = instance->usb0->GetPartitionCount();
|
||||||
|
|
||||||
if(!instance->usb0 || part >= partCount0)
|
if(!instance->usb0 || part >= partCount0)
|
||||||
return 1;
|
return 1;
|
||||||
else
|
else
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int DeviceHandler::PartitionToPortPartition(int part)
|
int DeviceHandler::PartitionToPortPartition(int part)
|
||||||
{
|
{
|
||||||
if(!DeviceHandler::instance)
|
if(!DeviceHandler::instance)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
u16 partCount0 = 0;
|
u16 partCount0 = 0;
|
||||||
if(instance->usb0)
|
if(instance->usb0)
|
||||||
partCount0 = instance->usb0->GetPartitionCount();
|
partCount0 = instance->usb0->GetPartitionCount();
|
||||||
|
|
||||||
if(!instance->usb0 || part >= partCount0)
|
if(!instance->usb0 || part >= partCount0)
|
||||||
return part-partCount0;
|
return part-partCount0;
|
||||||
else
|
else
|
||||||
return part;
|
return part;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *DeviceHandler::GetUSBFSName(int partition)
|
const char *DeviceHandler::GetUSBFSName(int partition)
|
||||||
|
@ -389,19 +389,19 @@ const char *DeviceHandler::GetUSBFSName(int partition)
|
||||||
if(!instance)
|
if(!instance)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
const char * FSName = NULL;
|
const char * FSName = NULL;
|
||||||
PartitionHandle *handle = instance->GetUSBHandleFromPartition(partition);
|
PartitionHandle *handle = instance->GetUSBHandleFromPartition(partition);
|
||||||
|
|
||||||
if(handle)
|
if(handle)
|
||||||
FSName = handle->GetFSName(PartitionToPortPartition(partition));
|
FSName = handle->GetFSName(PartitionToPortPartition(partition));
|
||||||
|
|
||||||
return FSName;
|
return FSName;
|
||||||
}
|
}
|
||||||
|
|
||||||
PartitionHandle *DeviceHandler::GetUSBHandleFromPartition(int part) const
|
PartitionHandle *DeviceHandler::GetUSBHandleFromPartition(int part) const
|
||||||
{
|
{
|
||||||
if(PartitionToUSBPort(part) == 0)
|
if(PartitionToUSBPort(part) == 0)
|
||||||
return usb0;
|
return usb0;
|
||||||
else
|
else
|
||||||
return usb1;
|
return usb1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,44 +31,44 @@
|
||||||
|
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
SD = 0,
|
SD = 0,
|
||||||
USB1,
|
USB1,
|
||||||
USB2,
|
USB2,
|
||||||
USB3,
|
USB3,
|
||||||
USB4,
|
USB4,
|
||||||
USB5,
|
USB5,
|
||||||
USB6,
|
USB6,
|
||||||
USB7,
|
USB7,
|
||||||
USB8,
|
USB8,
|
||||||
MAXDEVICES
|
MAXDEVICES
|
||||||
};
|
};
|
||||||
|
|
||||||
const char DeviceName[MAXDEVICES][6] =
|
const char DeviceName[MAXDEVICES][6] =
|
||||||
{
|
{
|
||||||
"sd",
|
"sd",
|
||||||
"usb1",
|
"usb1",
|
||||||
"usb2",
|
"usb2",
|
||||||
"usb3",
|
"usb3",
|
||||||
"usb4",
|
"usb4",
|
||||||
"usb5",
|
"usb5",
|
||||||
"usb6",
|
"usb6",
|
||||||
"usb7",
|
"usb7",
|
||||||
"usb8",
|
"usb8",
|
||||||
};
|
};
|
||||||
|
|
||||||
class DeviceHandler
|
class DeviceHandler
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static DeviceHandler * Instance();
|
static DeviceHandler * Instance();
|
||||||
static void DestroyInstance();
|
static void DestroyInstance();
|
||||||
|
|
||||||
bool MountAll();
|
bool MountAll();
|
||||||
void UnMountAll();
|
void UnMountAll();
|
||||||
bool Mount(int dev);
|
bool Mount(int dev);
|
||||||
bool IsInserted(int dev);
|
bool IsInserted(int dev);
|
||||||
void UnMount(int dev);
|
void UnMount(int dev);
|
||||||
|
|
||||||
//! Individual Mounts/UnMounts...
|
//! Individual Mounts/UnMounts...
|
||||||
bool MountSD();
|
bool MountSD();
|
||||||
bool MountAllUSB(bool spinUp = true);
|
bool MountAllUSB(bool spinUp = true);
|
||||||
bool MountUSBPort1(bool spinUp = true);
|
bool MountUSBPort1(bool spinUp = true);
|
||||||
|
@ -86,24 +86,24 @@ class DeviceHandler
|
||||||
static const DISC_INTERFACE *GetUSB1Interface() { return &__io_usbstorage2_port1; }
|
static const DISC_INTERFACE *GetUSB1Interface() { return &__io_usbstorage2_port1; }
|
||||||
static int GetUSBFilesystemType(int part);
|
static int GetUSBFilesystemType(int part);
|
||||||
static int PathToDriveType(const char * path);
|
static int PathToDriveType(const char * path);
|
||||||
static const char * GetFSName(int dev);
|
static const char * GetFSName(int dev);
|
||||||
static const char * PathToFSName(const char * path) { return GetFSName(PathToDriveType(path)); };
|
static const char * PathToFSName(const char * path) { return GetFSName(PathToDriveType(path)); };
|
||||||
static int PartitionToUSBPort(int part);
|
static int PartitionToUSBPort(int part);
|
||||||
static u16 GetUSBPartitionCount();
|
static u16 GetUSBPartitionCount();
|
||||||
static int PartitionToPortPartition(int part);
|
static int PartitionToPortPartition(int part);
|
||||||
static const char *GetUSBFSName(int partition);
|
static const char *GetUSBFSName(int partition);
|
||||||
private:
|
private:
|
||||||
DeviceHandler() : sd(0), gca(0), gcb(0), usb0(0), usb1(0) { };
|
DeviceHandler() : sd(0), gca(0), gcb(0), usb0(0), usb1(0) { };
|
||||||
~DeviceHandler();
|
~DeviceHandler();
|
||||||
bool MountUSB(int part);
|
bool MountUSB(int part);
|
||||||
|
|
||||||
static DeviceHandler *instance;
|
static DeviceHandler *instance;
|
||||||
|
|
||||||
PartitionHandle * sd;
|
PartitionHandle * sd;
|
||||||
PartitionHandle * gca;
|
PartitionHandle * gca;
|
||||||
PartitionHandle * gcb;
|
PartitionHandle * gcb;
|
||||||
PartitionHandle * usb0;
|
PartitionHandle * usb0;
|
||||||
PartitionHandle * usb1;
|
PartitionHandle * usb1;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -34,8 +34,8 @@
|
||||||
#include "utils/uncompress.h"
|
#include "utils/uncompress.h"
|
||||||
#include "PartitionHandle.h"
|
#include "PartitionHandle.h"
|
||||||
|
|
||||||
#define PARTITION_TYPE_DOS33_EXTENDED 0x05 /* DOS 3.3+ extended partition */
|
#define PARTITION_TYPE_DOS33_EXTENDED 0x05 /* DOS 3.3+ extended partition */
|
||||||
#define PARTITION_TYPE_WIN95_EXTENDED 0x0F /* Windows 95 extended partition */
|
#define PARTITION_TYPE_WIN95_EXTENDED 0x0F /* Windows 95 extended partition */
|
||||||
|
|
||||||
#define CACHE 32
|
#define CACHE 32
|
||||||
#define SECTORS 64
|
#define SECTORS 64
|
||||||
|
@ -67,221 +67,221 @@ static inline const char * PartFromType(int type)
|
||||||
}
|
}
|
||||||
|
|
||||||
PartitionHandle::PartitionHandle(const DISC_INTERFACE *discio)
|
PartitionHandle::PartitionHandle(const DISC_INTERFACE *discio)
|
||||||
: interface(discio)
|
: interface(discio)
|
||||||
{
|
{
|
||||||
// Sanity check
|
// Sanity check
|
||||||
if (!interface)
|
if (!interface)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Start the device and check that it is inserted
|
// Start the device and check that it is inserted
|
||||||
if (!interface->startup())
|
if (!interface->startup())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!interface->isInserted())
|
if (!interface->isInserted())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
FindPartitions();
|
FindPartitions();
|
||||||
}
|
}
|
||||||
|
|
||||||
PartitionHandle::~PartitionHandle()
|
PartitionHandle::~PartitionHandle()
|
||||||
{
|
{
|
||||||
UnMountAll();
|
UnMountAll();
|
||||||
|
|
||||||
//shutdown device
|
//shutdown device
|
||||||
interface->shutdown();
|
interface->shutdown();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PartitionHandle::IsMounted(int pos)
|
bool PartitionHandle::IsMounted(int pos)
|
||||||
{
|
{
|
||||||
if(pos < 0 || pos >= (int) MountNameList.size())
|
if(pos < 0 || pos >= (int) MountNameList.size())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if(MountNameList[pos].size() == 0)
|
if(MountNameList[pos].size() == 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PartitionHandle::Mount(int pos, const char * name, bool forceFAT)
|
bool PartitionHandle::Mount(int pos, const char * name, bool forceFAT)
|
||||||
{
|
{
|
||||||
if(!valid(pos))
|
if(!valid(pos))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if(!name)
|
if(!name)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
UnMount(pos);
|
UnMount(pos);
|
||||||
|
|
||||||
if(pos >= (int) MountNameList.size())
|
if(pos >= (int) MountNameList.size())
|
||||||
MountNameList.resize(pos+1);
|
MountNameList.resize(pos+1);
|
||||||
|
|
||||||
MountNameList[pos] = name;
|
MountNameList[pos] = name;
|
||||||
|
|
||||||
//! Some stupid partition manager think they don't need to edit the freaken MBR.
|
//! 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.
|
//! 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.
|
//! libfat does that by default so let's use it.
|
||||||
//! We do that only on sd not on usb.
|
//! We do that only on sd not on usb.
|
||||||
if(forceFAT && (!GetFSName(pos) || strcmp(GetFSName(pos), "Unknown") == 0))
|
if(forceFAT && (!GetFSName(pos) || strcmp(GetFSName(pos), "Unknown") == 0))
|
||||||
{
|
{
|
||||||
if (fatMount(MountNameList[pos].c_str(), interface, 0, CACHE, SECTORS))
|
if (fatMount(MountNameList[pos].c_str(), interface, 0, CACHE, SECTORS))
|
||||||
{
|
{
|
||||||
extern sec_t _FAT_startSector;
|
extern sec_t _FAT_startSector;
|
||||||
AddPartition("FAT", _FAT_startSector, 0xdeadbeaf, true, 0x0c, 0);
|
AddPartition("FAT", _FAT_startSector, 0xdeadbeaf, true, 0x0c, 0);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(strncmp(GetFSName(pos), "FAT", 3) == 0 || strcmp(GetFSName(pos), "GUID-Entry") == 0)
|
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 (fatMount(MountNameList[pos].c_str(), interface, GetLBAStart(pos), CACHE, SECTORS))
|
||||||
{
|
{
|
||||||
if(strcmp(GetFSName(pos), "GUID-Entry") == 0)
|
if(strcmp(GetFSName(pos), "GUID-Entry") == 0)
|
||||||
PartitionList[pos].FSName = "FAT";
|
PartitionList[pos].FSName = "FAT";
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(strncmp(GetFSName(pos), "NTFS", 4) == 0 || strcmp(GetFSName(pos), "GUID-Entry") == 0)
|
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))
|
if(ntfsMount(MountNameList[pos].c_str(), interface, GetLBAStart(pos), CACHE, SECTORS, NTFS_SHOW_HIDDEN_FILES | NTFS_RECOVER))
|
||||||
{
|
{
|
||||||
PartitionList[pos].FSName = "NTFS";
|
PartitionList[pos].FSName = "NTFS";
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(strncmp(GetFSName(pos), "LINUX", 5) == 0 || strcmp(GetFSName(pos), "GUID-Entry") == 0)
|
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))
|
if(ext2Mount(MountNameList[pos].c_str(), interface, GetLBAStart(pos), CACHE, SECTORS, EXT2_FLAG_DEFAULT))
|
||||||
{
|
{
|
||||||
PartitionList[pos].FSName = "LINUX";
|
PartitionList[pos].FSName = "LINUX";
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MountNameList[pos].clear();
|
MountNameList[pos].clear();
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PartitionHandle::UnMount(int pos)
|
void PartitionHandle::UnMount(int pos)
|
||||||
{
|
{
|
||||||
if(!interface)
|
if(!interface)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if(pos >= (int) MountNameList.size())
|
if(pos >= (int) MountNameList.size())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if(MountNameList[pos].size() == 0)
|
if(MountNameList[pos].size() == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
char DeviceSyn[20];
|
char DeviceSyn[20];
|
||||||
snprintf(DeviceSyn, sizeof(DeviceSyn), "%s:", MountNameList[pos].c_str());
|
snprintf(DeviceSyn, sizeof(DeviceSyn), "%s:", MountNameList[pos].c_str());
|
||||||
|
|
||||||
//closing all open Files write back the cache
|
//closing all open Files write back the cache
|
||||||
fatUnmount(DeviceSyn);
|
fatUnmount(DeviceSyn);
|
||||||
//closing all open Files write back the cache
|
//closing all open Files write back the cache
|
||||||
ntfsUnmount(DeviceSyn, true);
|
ntfsUnmount(DeviceSyn, true);
|
||||||
//closing all open Files write back the cache
|
//closing all open Files write back the cache
|
||||||
ext2Unmount(DeviceSyn);
|
ext2Unmount(DeviceSyn);
|
||||||
//Remove name from list
|
//Remove name from list
|
||||||
MountNameList[pos].clear();
|
MountNameList[pos].clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PartitionHandle::IsExisting(u64 lba)
|
bool PartitionHandle::IsExisting(u64 lba)
|
||||||
{
|
{
|
||||||
for(u32 i = 0; i < PartitionList.size(); ++i)
|
for(u32 i = 0; i < PartitionList.size(); ++i)
|
||||||
{
|
{
|
||||||
if(PartitionList[i].LBA_Start == lba)
|
if(PartitionList[i].LBA_Start == lba)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int PartitionHandle::FindPartitions()
|
int PartitionHandle::FindPartitions()
|
||||||
{
|
{
|
||||||
MASTER_BOOT_RECORD *mbr = (MASTER_BOOT_RECORD *) malloc(MAX_BYTES_PER_SECTOR);
|
MASTER_BOOT_RECORD *mbr = (MASTER_BOOT_RECORD *) malloc(MAX_BYTES_PER_SECTOR);
|
||||||
if(!mbr) return -1;
|
if(!mbr) return -1;
|
||||||
|
|
||||||
// Read the first sector on the device
|
// Read the first sector on the device
|
||||||
if (!interface->readSectors(0, 1, mbr))
|
if (!interface->readSectors(0, 1, mbr))
|
||||||
{
|
{
|
||||||
free(mbr);
|
free(mbr);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If this is the devices master boot record
|
// If this is the devices master boot record
|
||||||
if (mbr->signature != MBR_SIGNATURE)
|
if (mbr->signature != MBR_SIGNATURE)
|
||||||
{
|
{
|
||||||
free(mbr);
|
free(mbr);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < 4; i++)
|
for (int i = 0; i < 4; i++)
|
||||||
{
|
{
|
||||||
PARTITION_RECORD * partition = (PARTITION_RECORD *) &mbr->partitions[i];
|
PARTITION_RECORD * partition = (PARTITION_RECORD *) &mbr->partitions[i];
|
||||||
|
|
||||||
if(partition->type == PARTITION_TYPE_GPT)
|
if(partition->type == PARTITION_TYPE_GPT)
|
||||||
{
|
{
|
||||||
int ret = CheckGPT(i);
|
int ret = CheckGPT(i);
|
||||||
if(ret == 0) // if it's a GPT we don't need to go on looking through the mbr anymore
|
if(ret == 0) // if it's a GPT we don't need to go on looking through the mbr anymore
|
||||||
return ret;
|
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));
|
CheckEBR(i, le32(partition->lba_start));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(le32(partition->block_count) > 0 && !IsExisting(le32(partition->lba_start)))
|
if(le32(partition->block_count) > 0 && !IsExisting(le32(partition->lba_start)))
|
||||||
{
|
{
|
||||||
AddPartition(PartFromType(partition->type), le32(partition->lba_start),
|
AddPartition(PartFromType(partition->type), le32(partition->lba_start),
|
||||||
le32(partition->block_count), (partition->status == PARTITION_BOOTABLE),
|
le32(partition->block_count), (partition->status == PARTITION_BOOTABLE),
|
||||||
partition->type, i);
|
partition->type, i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
free(mbr);
|
free(mbr);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PartitionHandle::CheckEBR(u8 PartNum, sec_t ebr_lba)
|
void PartitionHandle::CheckEBR(u8 PartNum, sec_t ebr_lba)
|
||||||
{
|
{
|
||||||
EXTENDED_BOOT_RECORD *ebr = (EXTENDED_BOOT_RECORD *) malloc(MAX_BYTES_PER_SECTOR);
|
EXTENDED_BOOT_RECORD *ebr = (EXTENDED_BOOT_RECORD *) malloc(MAX_BYTES_PER_SECTOR);
|
||||||
if(!ebr) return;
|
if(!ebr) return;
|
||||||
sec_t next_erb_lba = 0;
|
sec_t next_erb_lba = 0;
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
// Read and validate the extended boot record
|
// Read and validate the extended boot record
|
||||||
if (!interface->readSectors(ebr_lba + next_erb_lba, 1, ebr))
|
if (!interface->readSectors(ebr_lba + next_erb_lba, 1, ebr))
|
||||||
{
|
{
|
||||||
free(ebr);
|
free(ebr);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ebr->signature != EBR_SIGNATURE)
|
if (ebr->signature != EBR_SIGNATURE)
|
||||||
{
|
{
|
||||||
free(ebr);
|
free(ebr);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(le32(ebr->partition.block_count) > 0 && !IsExisting(ebr_lba + next_erb_lba + le32(ebr->partition.lba_start)))
|
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),
|
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),
|
le32(ebr->partition.block_count), (ebr->partition.status == PARTITION_BOOTABLE),
|
||||||
ebr->partition.type, PartNum);
|
ebr->partition.type, PartNum);
|
||||||
}
|
}
|
||||||
// Get the start sector of the current partition
|
// Get the start sector of the current partition
|
||||||
// and the next extended boot record in the chain
|
// and the next extended boot record in the chain
|
||||||
next_erb_lba = le32(ebr->next_ebr.lba_start);
|
next_erb_lba = le32(ebr->next_ebr.lba_start);
|
||||||
}
|
}
|
||||||
while(next_erb_lba > 0);
|
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 };
|
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)
|
int PartitionHandle::CheckGPT(u8 PartNum)
|
||||||
{
|
{
|
||||||
GPT_HEADER *gpt_header = (GPT_HEADER *) malloc(MAX_BYTES_PER_SECTOR);
|
GPT_HEADER *gpt_header = (GPT_HEADER *) malloc(MAX_BYTES_PER_SECTOR);
|
||||||
if(!gpt_header) return -1;
|
if(!gpt_header) return -1;
|
||||||
|
|
||||||
// Read and validate the extended boot record
|
// Read and validate the extended boot record
|
||||||
if (!interface->readSectors(1, 1, gpt_header))
|
if (!interface->readSectors(1, 1, gpt_header))
|
||||||
{
|
{
|
||||||
free(gpt_header);
|
free(gpt_header);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(strncmp(gpt_header->magic, "EFI PART", 8) != 0)
|
if(strncmp(gpt_header->magic, "EFI PART", 8) != 0)
|
||||||
{
|
{
|
||||||
free(gpt_header);
|
free(gpt_header);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
gpt_header->part_table_lba = le64(gpt_header->part_table_lba);
|
gpt_header->part_table_lba = le64(gpt_header->part_table_lba);
|
||||||
gpt_header->part_entries = le32(gpt_header->part_entries);
|
gpt_header->part_entries = le32(gpt_header->part_entries);
|
||||||
gpt_header->part_entry_size = le32(gpt_header->part_entry_size);
|
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_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)
|
for(u32 i = 0; i < gpt_header->part_entries; ++i)
|
||||||
{
|
{
|
||||||
if (!interface->readSectors(next_lba, 1, sector_buf))
|
if (!interface->readSectors(next_lba, 1, sector_buf))
|
||||||
break;
|
break;
|
||||||
|
|
||||||
for(u32 n = 0; n < BYTES_PER_SECTOR/gpt_header->part_entry_size; ++n, ++i)
|
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);
|
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)
|
if(memcmp(part_entry->part_type_guid, TYPE_UNUSED, 16) == 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if(IsExisting(le64(part_entry->part_first_lba)))
|
if(IsExisting(le64(part_entry->part_first_lba)))
|
||||||
continue;
|
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;
|
delete [] sector_buf;
|
||||||
free(gpt_header);
|
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)
|
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))
|
if (!interface->readSectors(lba_start, 1, buffer))
|
||||||
{
|
{
|
||||||
free(buffer);
|
free(buffer);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
wbfs_head_t *head = (wbfs_head_t *) buffer;
|
wbfs_head_t *head = (wbfs_head_t *) buffer;
|
||||||
|
|
||||||
if (head->magic == wbfs_htonl(WBFS_MAGIC))
|
if (head->magic == wbfs_htonl(WBFS_MAGIC))
|
||||||
{
|
{
|
||||||
name = "WBFS";
|
name = "WBFS";
|
||||||
part_type = 0xBF; //Override partition type on WBFS
|
part_type = 0xBF; //Override partition type on WBFS
|
||||||
//! correct sector size in physical sectors (512 bytes per sector)
|
//! 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;
|
sec_count = (u64) head->n_hd_sec * (u64) (1 << head->hd_sec_sz_s) / (u64) BYTES_PER_SECTOR;
|
||||||
|
|
||||||
}
|
}
|
||||||
else if(*((u16 *) (buffer + 0x1FE)) == 0x55AA)
|
else if(*((u16 *) (buffer + 0x1FE)) == 0x55AA)
|
||||||
{
|
{
|
||||||
//! Partition typ can be missleading the correct partition format. Stupid lazy ass Partition Editors.
|
//! 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) &&
|
if((memcmp(buffer + 0x36, "FAT", 3) == 0 || memcmp(buffer + 0x52, "FAT", 3) == 0) &&
|
||||||
strncmp(PartFromType(part_type), "FAT", 3) != 0)
|
strncmp(PartFromType(part_type), "FAT", 3) != 0)
|
||||||
{
|
{
|
||||||
name = "FAT32";
|
name = "FAT32";
|
||||||
part_type = 0x0c;
|
part_type = 0x0c;
|
||||||
}
|
}
|
||||||
if (memcmp(buffer + 0x03, "NTFS", 4) == 0)
|
if (memcmp(buffer + 0x03, "NTFS", 4) == 0)
|
||||||
{
|
{
|
||||||
name = "NTFS";
|
name = "NTFS";
|
||||||
part_type = 0x07;
|
part_type = 0x07;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
PartitionFS PartitionEntrie;
|
PartitionFS PartitionEntrie;
|
||||||
PartitionEntrie.FSName = name;
|
PartitionEntrie.FSName = name;
|
||||||
PartitionEntrie.LBA_Start = lba_start;
|
PartitionEntrie.LBA_Start = lba_start;
|
||||||
PartitionEntrie.SecCount = sec_count;
|
PartitionEntrie.SecCount = sec_count;
|
||||||
PartitionEntrie.Bootable = bootable;
|
PartitionEntrie.Bootable = bootable;
|
||||||
PartitionEntrie.PartitionType = part_type;
|
PartitionEntrie.PartitionType = part_type;
|
||||||
PartitionEntrie.PartitionNum = part_num;
|
PartitionEntrie.PartitionNum = part_num;
|
||||||
|
|
||||||
PartitionList.push_back(PartitionEntrie);
|
PartitionList.push_back(PartitionEntrie);
|
||||||
|
|
||||||
free(buffer);
|
free(buffer);
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,139 +30,139 @@
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#define MAX_PARTITIONS 32 /* Maximum number of partitions that can be found */
|
#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_MOUNTS 10 /* Maximum number of mounts available at one time */
|
||||||
#define MAX_SYMLINK_DEPTH 10 /* Maximum search depth when resolving symbolic links */
|
#define MAX_SYMLINK_DEPTH 10 /* Maximum search depth when resolving symbolic links */
|
||||||
|
|
||||||
#define MBR_SIGNATURE 0x55AA
|
#define MBR_SIGNATURE 0x55AA
|
||||||
#define EBR_SIGNATURE MBR_SIGNATURE
|
#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_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_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_READ_ONLY_PARTITION 0x0800000000000000LL /* Read-only partition */
|
||||||
#define GUID_HIDDEN_PARTITION 0x2000000000000000LL /* Hidden 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_NO_AUTOMOUNT_PARTITION 0x4000000000000000LL /* Do not automount (e.g., do not assign drive letter) */
|
||||||
|
|
||||||
#define BYTES_PER_SECTOR 512 /* Default in libogc */
|
#define BYTES_PER_SECTOR 512 /* Default in libogc */
|
||||||
#define MAX_BYTES_PER_SECTOR 4096 /* Max bytes per sector */
|
#define MAX_BYTES_PER_SECTOR 4096 /* Max bytes per sector */
|
||||||
|
|
||||||
typedef struct _PARTITION_RECORD {
|
typedef struct _PARTITION_RECORD {
|
||||||
u8 status; /* Partition status; see above */
|
u8 status; /* Partition status; see above */
|
||||||
u8 chs_start[3]; /* Cylinder-head-sector address to first block of partition */
|
u8 chs_start[3]; /* Cylinder-head-sector address to first block of partition */
|
||||||
u8 type; /* Partition type; see above */
|
u8 type; /* Partition type; see above */
|
||||||
u8 chs_end[3]; /* Cylinder-head-sector address to last block of partition */
|
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 lba_start; /* Local block address to first sector of partition */
|
||||||
u32 block_count; /* Number of blocks in partition */
|
u32 block_count; /* Number of blocks in partition */
|
||||||
} __attribute__((__packed__)) PARTITION_RECORD;
|
} __attribute__((__packed__)) PARTITION_RECORD;
|
||||||
|
|
||||||
|
|
||||||
typedef struct _MASTER_BOOT_RECORD {
|
typedef struct _MASTER_BOOT_RECORD {
|
||||||
u8 code_area[446]; /* Code area; normally empty */
|
u8 code_area[446]; /* Code area; normally empty */
|
||||||
PARTITION_RECORD partitions[4]; /* 4 primary partitions */
|
PARTITION_RECORD partitions[4]; /* 4 primary partitions */
|
||||||
u16 signature; /* MBR signature; 0xAA55 */
|
u16 signature; /* MBR signature; 0xAA55 */
|
||||||
} __attribute__((__packed__)) MASTER_BOOT_RECORD;
|
} __attribute__((__packed__)) MASTER_BOOT_RECORD;
|
||||||
|
|
||||||
typedef struct _EXTENDED_BOOT_RECORD {
|
typedef struct _EXTENDED_BOOT_RECORD {
|
||||||
u8 code_area[446]; /* Code area; normally empty */
|
u8 code_area[446]; /* Code area; normally empty */
|
||||||
PARTITION_RECORD partition; /* Primary partition */
|
PARTITION_RECORD partition; /* Primary partition */
|
||||||
PARTITION_RECORD next_ebr; /* Next extended boot record in the chain */
|
PARTITION_RECORD next_ebr; /* Next extended boot record in the chain */
|
||||||
u8 reserved[32]; /* Normally empty */
|
u8 reserved[32]; /* Normally empty */
|
||||||
u16 signature; /* EBR signature; 0xAA55 */
|
u16 signature; /* EBR signature; 0xAA55 */
|
||||||
} __attribute__((__packed__)) EXTENDED_BOOT_RECORD;
|
} __attribute__((__packed__)) EXTENDED_BOOT_RECORD;
|
||||||
|
|
||||||
typedef struct _GPT_HEADER
|
typedef struct _GPT_HEADER
|
||||||
{
|
{
|
||||||
char magic[8]; /* "EFI PART" */
|
char magic[8]; /* "EFI PART" */
|
||||||
u32 revision; /* For version 1.0 */
|
u32 revision; /* For version 1.0 */
|
||||||
u32 header_size; /* Header size in bytes */
|
u32 header_size; /* Header size in bytes */
|
||||||
u32 checksum; /* CRC32 of header (0 to header size), with this field zeroed during calculation */
|
u32 checksum; /* CRC32 of header (0 to header size), with this field zeroed during calculation */
|
||||||
u32 reserved; /* must be 0 */
|
u32 reserved; /* must be 0 */
|
||||||
u64 header_lba; /* Current LBA (location of this header copy) */
|
u64 header_lba; /* Current LBA (location of this header copy) */
|
||||||
u64 backup_lba; /* Backup LBA (location of the other 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 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) */
|
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) */
|
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) */
|
u64 part_table_lba; /* Partition entries starting LBA (always 2 in primary copy) */
|
||||||
u32 part_entries; /* Number of partition entries */
|
u32 part_entries; /* Number of partition entries */
|
||||||
u32 part_entry_size; /* Size of a partition entry (usually 128) */
|
u32 part_entry_size; /* Size of a partition entry (usually 128) */
|
||||||
u32 part_entry_checksum; /* CRC32 of partition array */
|
u32 part_entry_checksum; /* CRC32 of partition array */
|
||||||
u8 zeros[420];
|
u8 zeros[420];
|
||||||
} __attribute__((__packed__)) GPT_HEADER;
|
} __attribute__((__packed__)) GPT_HEADER;
|
||||||
|
|
||||||
typedef struct _GUID_PART_ENTRY
|
typedef struct _GUID_PART_ENTRY
|
||||||
{
|
{
|
||||||
u8 part_type_guid[16]; /* Partition type GUID */
|
u8 part_type_guid[16]; /* Partition type GUID */
|
||||||
u8 uniq_part_guid[16]; /* Unique partition GUID */
|
u8 uniq_part_guid[16]; /* Unique partition GUID */
|
||||||
u64 part_first_lba; /* First LBA (little-endian) */
|
u64 part_first_lba; /* First LBA (little-endian) */
|
||||||
u64 part_last_lba; /* Last LBA (inclusive, usually odd) */
|
u64 part_last_lba; /* Last LBA (inclusive, usually odd) */
|
||||||
u64 attribute_flags; /* GUID Attribute flags (e.g. bit 60 denotes read-only) */
|
u64 attribute_flags; /* GUID Attribute flags (e.g. bit 60 denotes read-only) */
|
||||||
char partition_name[72]; /* Partition name (36 UTF-16LE code units) */
|
char partition_name[72]; /* Partition name (36 UTF-16LE code units) */
|
||||||
} __attribute__((__packed__)) GUID_PART_ENTRY;
|
} __attribute__((__packed__)) GUID_PART_ENTRY;
|
||||||
|
|
||||||
typedef struct _PartitionFS
|
typedef struct _PartitionFS
|
||||||
{
|
{
|
||||||
const char * FSName;
|
const char * FSName;
|
||||||
u64 LBA_Start;
|
u64 LBA_Start;
|
||||||
u64 SecCount;
|
u64 SecCount;
|
||||||
bool Bootable;
|
bool Bootable;
|
||||||
u8 PartitionType;
|
u8 PartitionType;
|
||||||
u8 PartitionNum;
|
u8 PartitionNum;
|
||||||
} __attribute__((__packed__)) PartitionFS;
|
} __attribute__((__packed__)) PartitionFS;
|
||||||
|
|
||||||
|
|
||||||
class PartitionHandle
|
class PartitionHandle
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
//! Constructor reads the MBR and all EBRs and lists up the Partitions
|
//! Constructor reads the MBR and all EBRs and lists up the Partitions
|
||||||
PartitionHandle(const DISC_INTERFACE *discio);
|
PartitionHandle(const DISC_INTERFACE *discio);
|
||||||
//! Destructor unmounts drives
|
//! Destructor unmounts drives
|
||||||
~PartitionHandle();
|
~PartitionHandle();
|
||||||
//! Is Drive inserted
|
//! Is Drive inserted
|
||||||
bool IsInserted() { if(!interface) return false; else return interface->isInserted(); };
|
bool IsInserted() { if(!interface) return false; else return interface->isInserted(); };
|
||||||
//! Is the partition Mounted
|
//! Is the partition Mounted
|
||||||
bool IsMounted(int pos);
|
bool IsMounted(int pos);
|
||||||
//! Mount a specific Partition
|
//! Mount a specific Partition
|
||||||
bool Mount(int pos, const char * name, bool forceFAT = false);
|
bool Mount(int pos, const char * name, bool forceFAT = false);
|
||||||
//! UnMount a specific Partition
|
//! UnMount a specific Partition
|
||||||
void UnMount(int pos);
|
void UnMount(int pos);
|
||||||
//! UnMount all Partition
|
//! UnMount all Partition
|
||||||
void UnMountAll() { for(u32 i = 0; i < PartitionList.size(); ++i) UnMount(i); };
|
void UnMountAll() { for(u32 i = 0; i < PartitionList.size(); ++i) UnMount(i); };
|
||||||
//! Get the Mountname
|
//! 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(); };
|
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"
|
//! Get the Name of the FileSystem e.g. "FAT32"
|
||||||
const char * GetFSName(int pos) { if(valid(pos)) return PartitionList[pos].FSName; else return NULL; };
|
const char * GetFSName(int pos) { if(valid(pos)) return PartitionList[pos].FSName; else return NULL; };
|
||||||
//! Get the LBA where the partition is located
|
//! Get the LBA where the partition is located
|
||||||
u32 GetLBAStart(int pos) { if(valid(pos)) return PartitionList[pos].LBA_Start; else return 0; };
|
u32 GetLBAStart(int pos) { if(valid(pos)) return PartitionList[pos].LBA_Start; else return 0; };
|
||||||
//! Get the partition size in sectors of this partition
|
//! Get the partition size in sectors of this partition
|
||||||
u32 GetSecCount(int pos) { if(valid(pos)) return PartitionList[pos].SecCount; else return 0; };
|
u32 GetSecCount(int pos) { if(valid(pos)) return PartitionList[pos].SecCount; else return 0; };
|
||||||
//! Check if the partition is Active or NonBootable
|
//! Check if the partition is Active or NonBootable
|
||||||
bool IsActive(int pos) { if(valid(pos)) return PartitionList[pos].Bootable; else return false; };
|
bool IsActive(int pos) { if(valid(pos)) return PartitionList[pos].Bootable; else return false; };
|
||||||
//! Get the partition type
|
//! Get the partition type
|
||||||
int GetPartitionType(int pos) { if(valid(pos)) return PartitionList[pos].PartitionType; else return -1; };
|
int GetPartitionType(int pos) { if(valid(pos)) return PartitionList[pos].PartitionType; else return -1; };
|
||||||
//! Get the entrie number in MBR of this partition
|
//! Get the entrie number in MBR of this partition
|
||||||
int GetPartitionNum(int pos) { if(valid(pos)) return PartitionList[pos].PartitionNum; else return -1; };
|
int GetPartitionNum(int pos) { if(valid(pos)) return PartitionList[pos].PartitionNum; else return -1; };
|
||||||
//! Get the count of found partitions
|
//! Get the count of found partitions
|
||||||
int GetPartitionCount() const { return PartitionList.size(); };
|
int GetPartitionCount() const { return PartitionList.size(); };
|
||||||
//! Get the partition size in bytes
|
//! Get the partition size in bytes
|
||||||
u64 GetSize(int pos) { if(valid(pos)) return (u64) PartitionList[pos].SecCount*BYTES_PER_SECTOR; else return 0; };
|
u64 GetSize(int pos) { if(valid(pos)) return (u64) PartitionList[pos].SecCount*BYTES_PER_SECTOR; else return 0; };
|
||||||
//! Get the whole partition record struct
|
//! Get the whole partition record struct
|
||||||
PartitionFS * GetPartitionRecord(int pos) { if(valid(pos)) return &PartitionList[pos]; else return NULL; };
|
PartitionFS * GetPartitionRecord(int pos) { if(valid(pos)) return &PartitionList[pos]; else return NULL; };
|
||||||
//! Get the disc interface of this handle
|
//! Get the disc interface of this handle
|
||||||
const DISC_INTERFACE * GetDiscInterface() { return interface; };
|
const DISC_INTERFACE * GetDiscInterface() { return interface; };
|
||||||
protected:
|
protected:
|
||||||
bool valid(int pos) { return (pos >= 0 && pos < (int) PartitionList.size()); }
|
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);
|
void AddPartition(const char * name, u64 lba_start, u64 sec_count, bool bootable, u8 part_type, u8 part_num);
|
||||||
bool IsExisting(u64 lba);
|
bool IsExisting(u64 lba);
|
||||||
int FindPartitions();
|
int FindPartitions();
|
||||||
void CheckEBR(u8 PartNum, sec_t ebr_lba);
|
void CheckEBR(u8 PartNum, sec_t ebr_lba);
|
||||||
int CheckGPT(u8 PartNum);
|
int CheckGPT(u8 PartNum);
|
||||||
|
|
||||||
const DISC_INTERFACE *interface;
|
const DISC_INTERFACE *interface;
|
||||||
std::vector<PartitionFS> PartitionList;
|
std::vector<PartitionFS> PartitionList;
|
||||||
std::vector<std::string> MountNameList;
|
std::vector<std::string> MountNameList;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -39,143 +39,143 @@
|
||||||
|
|
||||||
DirList::DirList(const char * path, const char *filter, u32 flags)
|
DirList::DirList(const char * path, const char *filter, u32 flags)
|
||||||
{
|
{
|
||||||
this->LoadPath(path, filter, flags);
|
this->LoadPath(path, filter, flags);
|
||||||
this->SortList();
|
this->SortList();
|
||||||
}
|
}
|
||||||
|
|
||||||
DirList::~DirList()
|
DirList::~DirList()
|
||||||
{
|
{
|
||||||
ClearList();
|
ClearList();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DirList::LoadPath(const char * folder, const char *filter, u32 flags)
|
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)
|
bool DirList::LoadPath(std::string &folderpath, const char *filter, u32 flags)
|
||||||
{
|
{
|
||||||
if(folderpath.size() < 3)
|
if(folderpath.size() < 3)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
struct dirent *dirent = NULL;
|
struct dirent *dirent = NULL;
|
||||||
DIR *dir = NULL;
|
DIR *dir = NULL;
|
||||||
|
|
||||||
if(folderpath[folderpath.size()-1] == '/')
|
if(folderpath[folderpath.size()-1] == '/')
|
||||||
folderpath.erase(folderpath.size()-1);
|
folderpath.erase(folderpath.size()-1);
|
||||||
|
|
||||||
bool isRoot = (folderpath.find('/') == std::string::npos);
|
bool isRoot = (folderpath.find('/') == std::string::npos);
|
||||||
if(isRoot)
|
if(isRoot)
|
||||||
folderpath += '/';
|
folderpath += '/';
|
||||||
|
|
||||||
dir = opendir(folderpath.c_str());
|
dir = opendir(folderpath.c_str());
|
||||||
if (dir == NULL)
|
if (dir == NULL)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
char * filename = new (std::nothrow) char[MAXPATHLEN];
|
char * filename = new (std::nothrow) char[MAXPATHLEN];
|
||||||
struct stat *st = new (std::nothrow) struct stat;
|
struct stat *st = new (std::nothrow) struct stat;
|
||||||
if(!filename || !st)
|
if(!filename || !st)
|
||||||
{
|
{
|
||||||
delete [] filename;
|
delete [] filename;
|
||||||
delete st;
|
delete st;
|
||||||
closedir(dir);
|
closedir(dir);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
while ((dirent = readdir(dir)) != 0)
|
while ((dirent = readdir(dir)) != 0)
|
||||||
{
|
{
|
||||||
if(!dirent->d_name)
|
if(!dirent->d_name)
|
||||||
continue;
|
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)
|
if(stat(filename, st) != 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
snprintf(filename, MAXPATHLEN, dirent->d_name);
|
snprintf(filename, MAXPATHLEN, dirent->d_name);
|
||||||
|
|
||||||
if(st->st_mode & S_IFDIR)
|
if(st->st_mode & S_IFDIR)
|
||||||
{
|
{
|
||||||
if(!(flags & Dirs))
|
if(!(flags & Dirs))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if(strcmp(filename,".") == 0 || strcmp(filename,"..") == 0)
|
if(strcmp(filename,".") == 0 || strcmp(filename,"..") == 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if(flags & CheckSubfolders)
|
if(flags & CheckSubfolders)
|
||||||
{
|
{
|
||||||
int length = folderpath.size();
|
int length = folderpath.size();
|
||||||
if(!isRoot) folderpath += '/';
|
if(!isRoot) folderpath += '/';
|
||||||
folderpath += filename;
|
folderpath += filename;
|
||||||
LoadPath(folderpath, filter, flags);
|
LoadPath(folderpath, filter, flags);
|
||||||
folderpath.erase(length);
|
folderpath.erase(length);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if(!(flags & Files))
|
if(!(flags & Files))
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(filter)
|
if(filter)
|
||||||
{
|
{
|
||||||
char * fileext = strrchr(filename, '.');
|
char * fileext = strrchr(filename, '.');
|
||||||
if(!fileext)
|
if(!fileext)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if(strtokcmp(fileext, filter, ",") == 0)
|
if(strtokcmp(fileext, filter, ",") == 0)
|
||||||
AddEntrie(folderpath.c_str(), filename, st->st_size, (st->st_mode & S_IFDIR) ? true : false);
|
AddEntrie(folderpath.c_str(), filename, st->st_size, (st->st_mode & S_IFDIR) ? true : false);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
AddEntrie(folderpath.c_str(), filename, st->st_size, (st->st_mode & S_IFDIR) ? true : false);
|
AddEntrie(folderpath.c_str(), filename, st->st_size, (st->st_mode & S_IFDIR) ? true : false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
closedir(dir);
|
closedir(dir);
|
||||||
delete [] filename;
|
delete [] filename;
|
||||||
delete st;
|
delete st;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DirList::AddEntrie(const char * folderpath, const char * filename, u64 filesize, bool isDir)
|
void DirList::AddEntrie(const char * folderpath, const char * filename, u64 filesize, bool isDir)
|
||||||
{
|
{
|
||||||
if(!folderpath || !filename)
|
if(!folderpath || !filename)
|
||||||
return;
|
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];
|
FileInfo[pos].FilePath = new (std::nothrow) char[strlen(folderpath)+strlen(filename)+2];
|
||||||
if(FileInfo[pos].FilePath)
|
if(FileInfo[pos].FilePath)
|
||||||
sprintf(FileInfo[pos].FilePath, "%s/%s", folderpath, filename);
|
sprintf(FileInfo[pos].FilePath, "%s/%s", folderpath, filename);
|
||||||
FileInfo[pos].FileSize = filesize;
|
FileInfo[pos].FileSize = filesize;
|
||||||
FileInfo[pos].isDir = isDir;
|
FileInfo[pos].isDir = isDir;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DirList::ClearList()
|
void DirList::ClearList()
|
||||||
{
|
{
|
||||||
for(u32 i = 0; i < FileInfo.size(); ++i)
|
for(u32 i = 0; i < FileInfo.size(); ++i)
|
||||||
{
|
{
|
||||||
if(FileInfo[i].FilePath)
|
if(FileInfo[i].FilePath)
|
||||||
delete [] FileInfo[i].FilePath;
|
delete [] FileInfo[i].FilePath;
|
||||||
}
|
}
|
||||||
|
|
||||||
FileInfo.clear();
|
FileInfo.clear();
|
||||||
std::vector<FileInfos>().swap(FileInfo);
|
std::vector<FileInfos>().swap(FileInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
const char * DirList::GetFilename(int ind)
|
const char * DirList::GetFilename(int ind)
|
||||||
{
|
{
|
||||||
if (!valid(ind))
|
if (!valid(ind))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
return FullpathToFilename(FileInfo[ind].FilePath);
|
return FullpathToFilename(FileInfo[ind].FilePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool SortCallback(const FileInfos & f1, const FileInfos & f2)
|
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 && !f2.FilePath) return true;
|
||||||
if(!f1.FilePath) return false;
|
if(!f1.FilePath) return false;
|
||||||
|
|
||||||
if(strcasecmp(f1.FilePath, f2.FilePath) > 0)
|
if(strcasecmp(f1.FilePath, f2.FilePath) > 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DirList::SortList()
|
void DirList::SortList()
|
||||||
{
|
{
|
||||||
if(FileInfo.size() > 1)
|
if(FileInfo.size() > 1)
|
||||||
std::sort(FileInfo.begin(), FileInfo.end(), SortCallback);
|
std::sort(FileInfo.begin(), FileInfo.end(), SortCallback);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DirList::SortList(bool (*SortFunc)(const FileInfos &a, const FileInfos &b))
|
void DirList::SortList(bool (*SortFunc)(const FileInfos &a, const FileInfos &b))
|
||||||
{
|
{
|
||||||
if(FileInfo.size() > 1)
|
if(FileInfo.size() > 1)
|
||||||
std::sort(FileInfo.begin(), FileInfo.end(), SortFunc);
|
std::sort(FileInfo.begin(), FileInfo.end(), SortFunc);
|
||||||
}
|
}
|
||||||
|
|
||||||
int DirList::GetFileIndex(const char *filename)
|
int DirList::GetFileIndex(const char *filename)
|
||||||
{
|
{
|
||||||
if(!filename)
|
if(!filename)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
for (u32 i = 0; i < FileInfo.size(); ++i)
|
for (u32 i = 0; i < FileInfo.size(); ++i)
|
||||||
{
|
{
|
||||||
|
|
|
@ -33,60 +33,60 @@
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
char * FilePath;
|
char * FilePath;
|
||||||
u64 FileSize;
|
u64 FileSize;
|
||||||
bool isDir;
|
bool isDir;
|
||||||
} FileInfos;
|
} FileInfos;
|
||||||
|
|
||||||
class DirList
|
class DirList
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
//!Constructor
|
//!Constructor
|
||||||
//!\param path Path from where to load the filelist of all files
|
//!\param path Path from where to load the filelist of all files
|
||||||
//!\param filter A fileext that needs to be filtered
|
//!\param filter A fileext that needs to be filtered
|
||||||
//!\param flags search/filter flags from the enum
|
//!\param flags search/filter flags from the enum
|
||||||
DirList(const char * path, const char *filter = NULL, u32 flags = Files | Dirs);
|
DirList(const char * path, const char *filter = NULL, u32 flags = Files | Dirs);
|
||||||
//!Destructor
|
//!Destructor
|
||||||
~DirList();
|
~DirList();
|
||||||
//! Load all the files from a directory
|
//! Load all the files from a directory
|
||||||
bool LoadPath(const char * path, const char *filter = NULL, u32 flags = Files | Dirs);
|
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);
|
bool LoadPath(std::string &path, const char *filter = NULL, u32 flags = Files | Dirs);
|
||||||
//! Get a filename of the list
|
//! Get a filename of the list
|
||||||
//!\param list index
|
//!\param list index
|
||||||
const char * GetFilename(int index);
|
const char * GetFilename(int index);
|
||||||
//! Get the a filepath of the list
|
//! Get the a filepath of the list
|
||||||
//!\param list index
|
//!\param list index
|
||||||
const char * GetFilepath(int index) { if(!valid(index)) return NULL; return FileInfo[index].FilePath; };
|
const char * GetFilepath(int index) { if(!valid(index)) return NULL; return FileInfo[index].FilePath; };
|
||||||
//! Get the a filesize of the list
|
//! Get the a filesize of the list
|
||||||
//!\param list index
|
//!\param list index
|
||||||
u64 GetFilesize(int index) { if(!valid(index)) return 0; return FileInfo[index].FileSize; };
|
u64 GetFilesize(int index) { if(!valid(index)) return 0; return FileInfo[index].FileSize; };
|
||||||
//! Is index a dir or a file
|
//! Is index a dir or a file
|
||||||
//!\param list index
|
//!\param list index
|
||||||
bool IsDir(int index) { if(!valid(index)) return 0; return FileInfo[index].isDir; };
|
bool IsDir(int index) { if(!valid(index)) return 0; return FileInfo[index].isDir; };
|
||||||
//! Get the filecount of the whole list
|
//! Get the filecount of the whole list
|
||||||
int GetFilecount() { return FileInfo.size(); };
|
int GetFilecount() { return FileInfo.size(); };
|
||||||
//! Sort list by filepath
|
//! Sort list by filepath
|
||||||
void SortList();
|
void SortList();
|
||||||
//! Custom sort command for custom sort functions definitions
|
//! Custom sort command for custom sort functions definitions
|
||||||
void SortList(bool (*SortFunc)(const FileInfos &a, const FileInfos &b));
|
void SortList(bool (*SortFunc)(const FileInfos &a, const FileInfos &b));
|
||||||
//! Get the index of the specified filename
|
//! Get the index of the specified filename
|
||||||
int GetFileIndex(const char *filename);
|
int GetFileIndex(const char *filename);
|
||||||
//! Enum for search/filter flags
|
//! Enum for search/filter flags
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
Files = 0x01,
|
Files = 0x01,
|
||||||
Dirs = 0x02,
|
Dirs = 0x02,
|
||||||
CheckSubfolders = 0x08,
|
CheckSubfolders = 0x08,
|
||||||
};
|
};
|
||||||
protected:
|
protected:
|
||||||
//!Add a list entrie
|
//!Add a list entrie
|
||||||
void AddEntrie(const char * folderpath, const char * filename, u64 filesize, bool isDir);
|
void AddEntrie(const char * folderpath, const char * filename, u64 filesize, bool isDir);
|
||||||
//! Clear the list
|
//! Clear the list
|
||||||
void ClearList();
|
void ClearList();
|
||||||
//! Check if valid pos is requested
|
//! Check if valid pos is requested
|
||||||
inline bool valid(int pos) { return (pos >= 0 && pos < (int) FileInfo.size()); };
|
inline bool valid(int pos) { return (pos >= 0 && pos < (int) FileInfo.size()); };
|
||||||
|
|
||||||
std::vector<FileInfos> FileInfo;
|
std::vector<FileInfos> FileInfo;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -3,139 +3,139 @@
|
||||||
|
|
||||||
CFile::CFile()
|
CFile::CFile()
|
||||||
{
|
{
|
||||||
file_fd = NULL;
|
file_fd = NULL;
|
||||||
mem_file = NULL;
|
mem_file = NULL;
|
||||||
filesize = 0;
|
filesize = 0;
|
||||||
Pos = 0;
|
Pos = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
CFile::CFile(const char * filepath, const char * mode)
|
CFile::CFile(const char * filepath, const char * mode)
|
||||||
{
|
{
|
||||||
file_fd = NULL;
|
file_fd = NULL;
|
||||||
open(filepath, mode);
|
open(filepath, mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
CFile::CFile(const u8 * mem, int size)
|
CFile::CFile(const u8 * mem, int size)
|
||||||
{
|
{
|
||||||
file_fd = NULL;
|
file_fd = NULL;
|
||||||
open(mem, size);
|
open(mem, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
CFile::~CFile()
|
CFile::~CFile()
|
||||||
{
|
{
|
||||||
close();
|
close();
|
||||||
}
|
}
|
||||||
|
|
||||||
int CFile::open(const char * filepath, const char * mode)
|
int CFile::open(const char * filepath, const char * mode)
|
||||||
{
|
{
|
||||||
close();
|
close();
|
||||||
|
|
||||||
file_fd = fopen(filepath, mode);
|
file_fd = fopen(filepath, mode);
|
||||||
if(!file_fd)
|
if(!file_fd)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
fseek(file_fd, 0, SEEK_END);
|
fseek(file_fd, 0, SEEK_END);
|
||||||
filesize = ftell(file_fd);
|
filesize = ftell(file_fd);
|
||||||
rewind();
|
rewind();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int CFile::open(const u8 * mem, int size)
|
int CFile::open(const u8 * mem, int size)
|
||||||
{
|
{
|
||||||
close();
|
close();
|
||||||
|
|
||||||
mem_file = mem;
|
mem_file = mem;
|
||||||
filesize = size;
|
filesize = size;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CFile::close()
|
void CFile::close()
|
||||||
{
|
{
|
||||||
if(file_fd)
|
if(file_fd)
|
||||||
fclose(file_fd);
|
fclose(file_fd);
|
||||||
|
|
||||||
file_fd = NULL;
|
file_fd = NULL;
|
||||||
mem_file = NULL;
|
mem_file = NULL;
|
||||||
filesize = 0;
|
filesize = 0;
|
||||||
Pos = 0;
|
Pos = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int CFile::read(u8 * ptr, size_t size)
|
int CFile::read(u8 * ptr, size_t size)
|
||||||
{
|
{
|
||||||
if(file_fd)
|
if(file_fd)
|
||||||
{
|
{
|
||||||
int ret = fread(ptr, 1, size, file_fd);
|
int ret = fread(ptr, 1, size, file_fd);
|
||||||
if(ret > 0)
|
if(ret > 0)
|
||||||
Pos += ret;
|
Pos += ret;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int readsize = size;
|
int readsize = size;
|
||||||
|
|
||||||
if(readsize > (long int) filesize-Pos)
|
if(readsize > (long int) filesize-Pos)
|
||||||
readsize = filesize-Pos;
|
readsize = filesize-Pos;
|
||||||
|
|
||||||
if(readsize <= 0)
|
if(readsize <= 0)
|
||||||
return readsize;
|
return readsize;
|
||||||
|
|
||||||
if(mem_file != NULL)
|
if(mem_file != NULL)
|
||||||
{
|
{
|
||||||
memcpy(ptr, mem_file+Pos, readsize);
|
memcpy(ptr, mem_file+Pos, readsize);
|
||||||
Pos += readsize;
|
Pos += readsize;
|
||||||
return readsize;
|
return readsize;
|
||||||
}
|
}
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int CFile::write(const u8 * ptr, size_t size)
|
int CFile::write(const u8 * ptr, size_t size)
|
||||||
{
|
{
|
||||||
if(file_fd)
|
if(file_fd)
|
||||||
{
|
{
|
||||||
int ret = fwrite(ptr, 1, size, file_fd);
|
int ret = fwrite(ptr, 1, size, file_fd);
|
||||||
if(ret > 0)
|
if(ret > 0)
|
||||||
Pos += ret;
|
Pos += ret;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int CFile::seek(long int offset, int origin)
|
int CFile::seek(long int offset, int origin)
|
||||||
{
|
{
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
|
||||||
if(origin == SEEK_SET)
|
if(origin == SEEK_SET)
|
||||||
{
|
{
|
||||||
Pos = offset;
|
Pos = offset;
|
||||||
}
|
}
|
||||||
else if(origin == SEEK_CUR)
|
else if(origin == SEEK_CUR)
|
||||||
{
|
{
|
||||||
Pos += offset;
|
Pos += offset;
|
||||||
}
|
}
|
||||||
else if(origin == SEEK_END)
|
else if(origin == SEEK_END)
|
||||||
{
|
{
|
||||||
Pos = filesize+offset;
|
Pos = filesize+offset;
|
||||||
}
|
}
|
||||||
if(Pos < 0)
|
if(Pos < 0)
|
||||||
{
|
{
|
||||||
Pos = 0;
|
Pos = 0;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(file_fd)
|
if(file_fd)
|
||||||
ret = fseek(file_fd, Pos, SEEK_SET);
|
ret = fseek(file_fd, Pos, SEEK_SET);
|
||||||
|
|
||||||
if(mem_file != NULL)
|
if(mem_file != NULL)
|
||||||
{
|
{
|
||||||
if(Pos > (long int) filesize)
|
if(Pos > (long int) filesize)
|
||||||
{
|
{
|
||||||
Pos = filesize;
|
Pos = filesize;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,25 +6,25 @@
|
||||||
|
|
||||||
class CFile
|
class CFile
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CFile();
|
CFile();
|
||||||
CFile(const char * filepath, const char * mode);
|
CFile(const char * filepath, const char * mode);
|
||||||
CFile(const u8 * memory, int memsize);
|
CFile(const u8 * memory, int memsize);
|
||||||
~CFile();
|
~CFile();
|
||||||
int open(const char * filepath, const char * mode);
|
int open(const char * filepath, const char * mode);
|
||||||
int open(const u8 * memory, int memsize);
|
int open(const u8 * memory, int memsize);
|
||||||
void close();
|
void close();
|
||||||
int read(u8 * ptr, size_t size);
|
int read(u8 * ptr, size_t size);
|
||||||
int write(const u8 * ptr, size_t size);
|
int write(const u8 * ptr, size_t size);
|
||||||
int seek(long int offset, int origin);
|
int seek(long int offset, int origin);
|
||||||
long int tell() { return Pos; };
|
long int tell() { return Pos; };
|
||||||
long int size() { return filesize; };
|
long int size() { return filesize; };
|
||||||
void rewind() { seek(0, SEEK_SET); };
|
void rewind() { seek(0, SEEK_SET); };
|
||||||
protected:
|
protected:
|
||||||
FILE * file_fd;
|
FILE * file_fd;
|
||||||
const u8 * mem_file;
|
const u8 * mem_file;
|
||||||
u64 filesize;
|
u64 filesize;
|
||||||
long int Pos;
|
long int Pos;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -37,7 +37,7 @@
|
||||||
|
|
||||||
#include "fileops.h"
|
#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)
|
#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)
|
extern "C" bool CheckFile(const char * filepath)
|
||||||
{
|
{
|
||||||
if(!filepath)
|
if(!filepath)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
struct stat filestat;
|
struct stat filestat;
|
||||||
|
|
||||||
char dirnoslash[strlen(filepath)+2];
|
char dirnoslash[strlen(filepath)+2];
|
||||||
snprintf(dirnoslash, sizeof(dirnoslash), "%s", filepath);
|
snprintf(dirnoslash, sizeof(dirnoslash), "%s", filepath);
|
||||||
|
|
||||||
while(dirnoslash[strlen(dirnoslash)-1] == '/')
|
while(dirnoslash[strlen(dirnoslash)-1] == '/')
|
||||||
dirnoslash[strlen(dirnoslash)-1] = '\0';
|
dirnoslash[strlen(dirnoslash)-1] = '\0';
|
||||||
|
|
||||||
char * notRoot = strrchr(dirnoslash, '/');
|
char * notRoot = strrchr(dirnoslash, '/');
|
||||||
if(!notRoot)
|
if(!notRoot)
|
||||||
{
|
{
|
||||||
strcat(dirnoslash, "/");
|
strcat(dirnoslash, "/");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (stat(dirnoslash, &filestat) == 0)
|
if (stat(dirnoslash, &filestat) == 0)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
|
@ -83,7 +83,7 @@ extern "C" u64 FileSize(const char * filepath)
|
||||||
struct stat filestat;
|
struct stat filestat;
|
||||||
|
|
||||||
if (stat(filepath, &filestat) != 0)
|
if (stat(filepath, &filestat) != 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
return filestat.st_size;
|
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)
|
extern "C" int LoadFileToMem(const char *filepath, u8 **inbuffer, u64 *size)
|
||||||
{
|
{
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
u64 filesize = FileSize(filepath);
|
u64 filesize = FileSize(filepath);
|
||||||
char * filename = strrchr(filepath, '/');
|
char * filename = strrchr(filepath, '/');
|
||||||
if(filename)
|
if(filename)
|
||||||
filename++;
|
filename++;
|
||||||
|
|
||||||
*inbuffer = NULL;
|
*inbuffer = NULL;
|
||||||
*size = 0;
|
*size = 0;
|
||||||
|
|
||||||
FILE *file = fopen(filepath, "rb");
|
FILE *file = fopen(filepath, "rb");
|
||||||
|
|
||||||
if (file == NULL)
|
if (file == NULL)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
u8 *buffer = (u8 *) malloc(filesize);
|
u8 *buffer = (u8 *) malloc(filesize);
|
||||||
if (buffer == NULL)
|
if (buffer == NULL)
|
||||||
{
|
{
|
||||||
fclose(file);
|
fclose(file);
|
||||||
return -2;
|
return -2;
|
||||||
}
|
}
|
||||||
|
|
||||||
u64 done = 0;
|
u64 done = 0;
|
||||||
u32 blocksize = BLOCKSIZE;
|
u32 blocksize = BLOCKSIZE;
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
if(actioncanceled)
|
if(actioncanceled)
|
||||||
{
|
{
|
||||||
free(buffer);
|
free(buffer);
|
||||||
fclose(file);
|
fclose(file);
|
||||||
return -10;
|
return -10;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(blocksize > filesize-done)
|
if(blocksize > filesize-done)
|
||||||
blocksize = filesize-done;
|
blocksize = filesize-done;
|
||||||
|
|
||||||
ret = fread(buffer+done, 1, blocksize, file);
|
ret = fread(buffer+done, 1, blocksize, file);
|
||||||
if(ret < 0)
|
if(ret < 0)
|
||||||
{
|
{
|
||||||
free(buffer);
|
free(buffer);
|
||||||
fclose(file);
|
fclose(file);
|
||||||
return -3;
|
return -3;
|
||||||
}
|
}
|
||||||
else if(ret == 0)
|
else if(ret == 0)
|
||||||
{
|
{
|
||||||
//we are done
|
//we are done
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
done += ret;
|
done += ret;
|
||||||
|
|
||||||
}
|
}
|
||||||
while(done < filesize);
|
while(done < filesize);
|
||||||
|
|
||||||
fclose(file);
|
fclose(file);
|
||||||
|
|
||||||
if (done != filesize)
|
if (done != filesize)
|
||||||
{
|
{
|
||||||
free(buffer);
|
free(buffer);
|
||||||
return -3;
|
return -3;
|
||||||
}
|
}
|
||||||
|
|
||||||
*inbuffer = buffer;
|
*inbuffer = buffer;
|
||||||
*size = filesize;
|
*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)
|
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;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -183,57 +183,57 @@ extern "C" int LoadFileToMemWithProgress(const char *progressText, const char *f
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
extern "C" bool CreateSubfolder(const char * fullpath)
|
extern "C" bool CreateSubfolder(const char * fullpath)
|
||||||
{
|
{
|
||||||
if(!fullpath)
|
if(!fullpath)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
bool result = false;
|
bool result = false;
|
||||||
|
|
||||||
char dirnoslash[strlen(fullpath)+1];
|
char dirnoslash[strlen(fullpath)+1];
|
||||||
strcpy(dirnoslash, fullpath);
|
strcpy(dirnoslash, fullpath);
|
||||||
|
|
||||||
int pos = strlen(dirnoslash)-1;
|
int pos = strlen(dirnoslash)-1;
|
||||||
while(dirnoslash[pos] == '/')
|
while(dirnoslash[pos] == '/')
|
||||||
{
|
{
|
||||||
dirnoslash[pos] = '\0';
|
dirnoslash[pos] = '\0';
|
||||||
pos--;
|
pos--;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(CheckFile(dirnoslash))
|
if(CheckFile(dirnoslash))
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
char parentpath[strlen(dirnoslash)+2];
|
char parentpath[strlen(dirnoslash)+2];
|
||||||
strcpy(parentpath, dirnoslash);
|
strcpy(parentpath, dirnoslash);
|
||||||
char * ptr = strrchr(parentpath, '/');
|
char * ptr = strrchr(parentpath, '/');
|
||||||
|
|
||||||
if(!ptr)
|
if(!ptr)
|
||||||
{
|
{
|
||||||
//!Device root directory (must be with '/')
|
//!Device root directory (must be with '/')
|
||||||
strcat(parentpath, "/");
|
strcat(parentpath, "/");
|
||||||
struct stat filestat;
|
struct stat filestat;
|
||||||
if (stat(parentpath, &filestat) == 0)
|
if (stat(parentpath, &filestat) == 0)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
ptr++;
|
ptr++;
|
||||||
ptr[0] = '\0';
|
ptr[0] = '\0';
|
||||||
|
|
||||||
result = CreateSubfolder(parentpath);
|
result = CreateSubfolder(parentpath);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!result)
|
if(!result)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (mkdir(dirnoslash, 0777) == -1)
|
if (mkdir(dirnoslash, 0777) == -1)
|
||||||
{
|
{
|
||||||
return false;
|
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)
|
static bool CompareDevices(const char *src, const char *dest)
|
||||||
{
|
{
|
||||||
if(!src || !dest)
|
if(!src || !dest)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
char *device1 = strchr(src, ':');
|
char *device1 = strchr(src, ':');
|
||||||
char *device2 = strchr(dest, ':');
|
char *device2 = strchr(dest, ':');
|
||||||
|
|
||||||
if(!device1 || !device2)
|
if(!device1 || !device2)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
int position1 = device1-src+1;
|
int position1 = device1-src+1;
|
||||||
int position2 = device2-dest+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(temp1, position1, "%s", src);
|
||||||
snprintf(temp2, position2, "%s", dest);
|
snprintf(temp2, position2, "%s", dest);
|
||||||
|
|
||||||
if(strcasecmp(temp1, temp2) == 0)
|
if(strcasecmp(temp1, temp2) == 0)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
|
@ -279,83 +279,83 @@ extern "C" int CopyFile(const char * src, const char * dest)
|
||||||
|
|
||||||
char * filename = strrchr(src, '/');
|
char * filename = strrchr(src, '/');
|
||||||
if(filename)
|
if(filename)
|
||||||
filename++;
|
filename++;
|
||||||
else
|
else
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
u64 sizesrc = FileSize(src);
|
u64 sizesrc = FileSize(src);
|
||||||
|
|
||||||
FILE * source = fopen(src, "rb");
|
FILE * source = fopen(src, "rb");
|
||||||
|
|
||||||
if(!source)
|
if(!source)
|
||||||
return -2;
|
return -2;
|
||||||
|
|
||||||
u32 blksize = BLOCKSIZE;
|
u32 blksize = BLOCKSIZE;
|
||||||
|
|
||||||
u8 * buffer = (u8 *) malloc(blksize);
|
u8 * buffer = (u8 *) malloc(blksize);
|
||||||
|
|
||||||
if(buffer == NULL){
|
if(buffer == NULL){
|
||||||
//no memory
|
//no memory
|
||||||
fclose(source);
|
fclose(source);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
FILE * destination = fopen(dest, "wb");
|
FILE * destination = fopen(dest, "wb");
|
||||||
|
|
||||||
if(destination == NULL)
|
if(destination == NULL)
|
||||||
{
|
{
|
||||||
free(buffer);
|
free(buffer);
|
||||||
fclose(source);
|
fclose(source);
|
||||||
return -3;
|
return -3;
|
||||||
}
|
}
|
||||||
|
|
||||||
u64 done = 0;
|
u64 done = 0;
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
if(actioncanceled)
|
if(actioncanceled)
|
||||||
{
|
{
|
||||||
fclose(source);
|
fclose(source);
|
||||||
fclose(destination);
|
fclose(destination);
|
||||||
free(buffer);
|
free(buffer);
|
||||||
RemoveFile((char *) dest);
|
RemoveFile((char *) dest);
|
||||||
return -10;
|
return -10;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(blksize > sizesrc - done)
|
if(blksize > sizesrc - done)
|
||||||
blksize = sizesrc - done;
|
blksize = sizesrc - done;
|
||||||
|
|
||||||
//Display progress
|
//Display progress
|
||||||
read = fread(buffer, 1, blksize, source);
|
read = fread(buffer, 1, blksize, source);
|
||||||
if(read < 0)
|
if(read < 0)
|
||||||
{
|
{
|
||||||
fclose(source);
|
fclose(source);
|
||||||
fclose(destination);
|
fclose(destination);
|
||||||
free(buffer);
|
free(buffer);
|
||||||
RemoveFile((char *) dest);
|
RemoveFile((char *) dest);
|
||||||
return -3;
|
return -3;
|
||||||
}
|
}
|
||||||
|
|
||||||
wrote = fwrite(buffer, 1, read, destination);
|
wrote = fwrite(buffer, 1, read, destination);
|
||||||
if(wrote < 0)
|
if(wrote < 0)
|
||||||
{
|
{
|
||||||
fclose(source);
|
fclose(source);
|
||||||
fclose(destination);
|
fclose(destination);
|
||||||
free(buffer);
|
free(buffer);
|
||||||
RemoveFile((char *) dest);
|
RemoveFile((char *) dest);
|
||||||
return -3;
|
return -3;
|
||||||
}
|
}
|
||||||
|
|
||||||
done += wrote;
|
done += wrote;
|
||||||
}
|
}
|
||||||
while (read > 0);
|
while (read > 0);
|
||||||
|
|
||||||
free(buffer);
|
free(buffer);
|
||||||
fclose(source);
|
fclose(source);
|
||||||
fclose(destination);
|
fclose(destination);
|
||||||
|
|
||||||
if(sizesrc != done)
|
if(sizesrc != done)
|
||||||
return -4;
|
return -4;
|
||||||
|
|
||||||
return 1;
|
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)
|
extern "C" int MoveFile(const char *srcpath, char *destdir)
|
||||||
{
|
{
|
||||||
if(CompareDevices(srcpath, destdir))
|
if(CompareDevices(srcpath, destdir))
|
||||||
{
|
{
|
||||||
if(RenameFile(srcpath, destdir))
|
if(RenameFile(srcpath, destdir))
|
||||||
return 1;
|
return 1;
|
||||||
else
|
else
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int res = CopyFile(srcpath, destdir);
|
int res = CopyFile(srcpath, destdir);
|
||||||
if(res < 0)
|
if(res < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if(RemoveFile(srcpath))
|
if(RemoveFile(srcpath))
|
||||||
return 1;
|
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)
|
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)
|
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)
|
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];
|
wchar_t *strWChar = new (std::nothrow) wchar_t[strlen(strChar) + 1];
|
||||||
if (!strWChar) return NULL;
|
if (!strWChar) return NULL;
|
||||||
|
|
||||||
int bt = mbstowcs(strWChar, strChar, strlen(strChar));
|
int bt = mbstowcs(strWChar, strChar, strlen(strChar));
|
||||||
if (bt > 0)
|
if (bt > 0)
|
||||||
{
|
{
|
||||||
strWChar[bt] = 0;
|
strWChar[bt] = 0;
|
||||||
return strWChar;
|
return strWChar;
|
||||||
}
|
}
|
||||||
|
|
||||||
wchar_t *tempDest = strWChar;
|
wchar_t *tempDest = strWChar;
|
||||||
while ((*tempDest++ = *strChar++))
|
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)
|
FreeTypeGX::FreeTypeGX(const uint8_t* fontBuffer, FT_Long bufferSize, bool lastFace)
|
||||||
{
|
{
|
||||||
int faceIndex = 0;
|
int faceIndex = 0;
|
||||||
ftPointSize = 0;
|
ftPointSize = 0;
|
||||||
|
|
||||||
FT_Init_FreeType(&ftLibrary);
|
FT_Init_FreeType(&ftLibrary);
|
||||||
if(lastFace)
|
if(lastFace)
|
||||||
{
|
{
|
||||||
FT_New_Memory_Face(ftLibrary, (FT_Byte *)fontBuffer, bufferSize, -1, &ftFace);
|
FT_New_Memory_Face(ftLibrary, (FT_Byte *)fontBuffer, bufferSize, -1, &ftFace);
|
||||||
faceIndex = ftFace->num_faces - 1; // Use the last face
|
faceIndex = ftFace->num_faces - 1; // Use the last face
|
||||||
FT_Done_Face(ftFace);
|
FT_Done_Face(ftFace);
|
||||||
ftFace = NULL;
|
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);
|
setVertexFormat(GX_VTXFMT1);
|
||||||
ftKerningEnabled = false;//FT_HAS_KERNING(ftFace);
|
ftKerningEnabled = false;//FT_HAS_KERNING(ftFace);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -87,9 +87,9 @@ FreeTypeGX::FreeTypeGX(const uint8_t* fontBuffer, FT_Long bufferSize, bool lastF
|
||||||
*/
|
*/
|
||||||
FreeTypeGX::~FreeTypeGX()
|
FreeTypeGX::~FreeTypeGX()
|
||||||
{
|
{
|
||||||
unloadFont();
|
unloadFont();
|
||||||
FT_Done_Face(ftFace);
|
FT_Done_Face(ftFace);
|
||||||
FT_Done_FreeType(ftLibrary);
|
FT_Done_FreeType(ftLibrary);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -103,10 +103,10 @@ FreeTypeGX::~FreeTypeGX()
|
||||||
*/
|
*/
|
||||||
void FreeTypeGX::setVertexFormat(uint8_t vertexInd)
|
void FreeTypeGX::setVertexFormat(uint8_t vertexInd)
|
||||||
{
|
{
|
||||||
vertexIndex = vertexInd;
|
vertexIndex = vertexInd;
|
||||||
GX_SetVtxAttrFmt(vertexIndex, GX_VA_POS, GX_POS_XYZ, GX_S16, 0);
|
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_TEX0, GX_TEX_ST, GX_F32, 0);
|
||||||
GX_SetVtxAttrFmt(vertexIndex, GX_VA_CLR0, GX_CLR_RGBA, GX_RGBA8, 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()
|
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<int16_t, map<wchar_t, ftgxCharData> >::iterator itr;
|
||||||
map<wchar_t, ftgxCharData>::iterator itr2;
|
map<wchar_t, ftgxCharData>::iterator itr2;
|
||||||
|
|
||||||
for (itr = fontData.begin(); itr != fontData.end(); itr++)
|
for (itr = fontData.begin(); itr != fontData.end(); itr++)
|
||||||
{
|
{
|
||||||
for (itr2 = itr->second.begin(); itr2 != itr->second.end(); itr2++)
|
for (itr2 = itr->second.begin(); itr2 != itr->second.end(); itr2++)
|
||||||
free(itr2->second.glyphDataTexture);
|
free(itr2->second.glyphDataTexture);
|
||||||
|
|
||||||
itr->second.clear();
|
itr->second.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
fontData.clear();
|
fontData.clear();
|
||||||
ftgxAlign.clear();
|
ftgxAlign.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -144,65 +144,65 @@ void FreeTypeGX::unloadFont()
|
||||||
*/
|
*/
|
||||||
ftgxCharData * FreeTypeGX::cacheGlyphData(wchar_t charCode, int16_t pixelSize)
|
ftgxCharData * FreeTypeGX::cacheGlyphData(wchar_t charCode, int16_t pixelSize)
|
||||||
{
|
{
|
||||||
map<int16_t, map<wchar_t, ftgxCharData> >::iterator itr = fontData.find(pixelSize);
|
map<int16_t, map<wchar_t, ftgxCharData> >::iterator itr = fontData.find(pixelSize);
|
||||||
if (itr != fontData.end())
|
if (itr != fontData.end())
|
||||||
{
|
{
|
||||||
map<wchar_t, ftgxCharData>::iterator itr2 = itr->second.find(charCode);
|
map<wchar_t, ftgxCharData>::iterator itr2 = itr->second.find(charCode);
|
||||||
if (itr2 != itr->second.end())
|
if (itr2 != itr->second.end())
|
||||||
{
|
{
|
||||||
return &itr2->second;
|
return &itr2->second;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
FT_UInt gIndex;
|
FT_UInt gIndex;
|
||||||
uint16_t textureWidth = 0, textureHeight = 0;
|
uint16_t textureWidth = 0, textureHeight = 0;
|
||||||
|
|
||||||
if (ftPointSize != pixelSize)
|
if (ftPointSize != pixelSize)
|
||||||
{
|
{
|
||||||
ftPointSize = pixelSize;
|
ftPointSize = pixelSize;
|
||||||
FT_Set_Pixel_Sizes(ftFace, 0, ftPointSize);
|
FT_Set_Pixel_Sizes(ftFace, 0, ftPointSize);
|
||||||
|
|
||||||
//!Cache ascender and decender as well
|
//!Cache ascender and decender as well
|
||||||
map<int16_t, ftgxDataOffset>::iterator itrAlign = ftgxAlign.find(ftPointSize);
|
map<int16_t, ftgxDataOffset>::iterator itrAlign = ftgxAlign.find(ftPointSize);
|
||||||
if (itrAlign == ftgxAlign.end())
|
if (itrAlign == ftgxAlign.end())
|
||||||
{
|
{
|
||||||
ftgxAlign[ftPointSize].ascender = (int16_t) ftFace->size->metrics.ascender >> 6;
|
ftgxAlign[ftPointSize].ascender = (int16_t) ftFace->size->metrics.ascender >> 6;
|
||||||
ftgxAlign[ftPointSize].descender = (int16_t) ftFace->size->metrics.descender >> 6;
|
ftgxAlign[ftPointSize].descender = (int16_t) ftFace->size->metrics.descender >> 6;
|
||||||
ftgxAlign[ftPointSize].max = 0;
|
ftgxAlign[ftPointSize].max = 0;
|
||||||
ftgxAlign[ftPointSize].min = 0;
|
ftgxAlign[ftPointSize].min = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
gIndex = FT_Get_Char_Index(ftFace, (FT_ULong) charCode);
|
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 (gIndex != 0 && FT_Load_Glyph(ftFace, gIndex, FT_LOAD_DEFAULT | FT_LOAD_RENDER) == 0)
|
||||||
{
|
{
|
||||||
if (ftFace->glyph->format == FT_GLYPH_FORMAT_BITMAP)
|
if (ftFace->glyph->format == FT_GLYPH_FORMAT_BITMAP)
|
||||||
{
|
{
|
||||||
FT_Bitmap *glyphBitmap = &ftFace->glyph->bitmap;
|
FT_Bitmap *glyphBitmap = &ftFace->glyph->bitmap;
|
||||||
|
|
||||||
textureWidth = ALIGN8(glyphBitmap->width);
|
textureWidth = ALIGN8(glyphBitmap->width);
|
||||||
textureHeight = ALIGN8(glyphBitmap->rows);
|
textureHeight = ALIGN8(glyphBitmap->rows);
|
||||||
if(textureWidth == 0)
|
if(textureWidth == 0)
|
||||||
textureWidth = 8;
|
textureWidth = 8;
|
||||||
if(textureHeight == 0)
|
if(textureHeight == 0)
|
||||||
textureHeight = 8;
|
textureHeight = 8;
|
||||||
|
|
||||||
fontData[pixelSize][charCode].renderOffsetX = (int16_t) ftFace->glyph->bitmap_left;
|
fontData[pixelSize][charCode].renderOffsetX = (int16_t) ftFace->glyph->bitmap_left;
|
||||||
fontData[pixelSize][charCode].glyphAdvanceX = (uint16_t) (ftFace->glyph->advance.x >> 6);
|
fontData[pixelSize][charCode].glyphAdvanceX = (uint16_t) (ftFace->glyph->advance.x >> 6);
|
||||||
fontData[pixelSize][charCode].glyphIndex = (uint32_t) gIndex;
|
fontData[pixelSize][charCode].glyphIndex = (uint32_t) gIndex;
|
||||||
fontData[pixelSize][charCode].textureWidth = (uint16_t) textureWidth;
|
fontData[pixelSize][charCode].textureWidth = (uint16_t) textureWidth;
|
||||||
fontData[pixelSize][charCode].textureHeight = (uint16_t) textureHeight;
|
fontData[pixelSize][charCode].textureHeight = (uint16_t) textureHeight;
|
||||||
fontData[pixelSize][charCode].renderOffsetY = (int16_t) ftFace->glyph->bitmap_top;
|
fontData[pixelSize][charCode].renderOffsetY = (int16_t) ftFace->glyph->bitmap_top;
|
||||||
fontData[pixelSize][charCode].renderOffsetMax = (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].renderOffsetMin = (int16_t) glyphBitmap->rows - ftFace->glyph->bitmap_top;
|
||||||
fontData[pixelSize][charCode].glyphDataTexture = NULL;
|
fontData[pixelSize][charCode].glyphDataTexture = NULL;
|
||||||
|
|
||||||
loadGlyphData(glyphBitmap, &fontData[pixelSize][charCode]);
|
loadGlyphData(glyphBitmap, &fontData[pixelSize][charCode]);
|
||||||
|
|
||||||
return &fontData[pixelSize][charCode];
|
return &fontData[pixelSize][charCode];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -213,16 +213,16 @@ ftgxCharData * FreeTypeGX::cacheGlyphData(wchar_t charCode, int16_t pixelSize)
|
||||||
*/
|
*/
|
||||||
uint16_t FreeTypeGX::cacheGlyphDataComplete(int16_t pixelSize)
|
uint16_t FreeTypeGX::cacheGlyphDataComplete(int16_t pixelSize)
|
||||||
{
|
{
|
||||||
uint32_t i = 0;
|
uint32_t i = 0;
|
||||||
FT_UInt gIndex;
|
FT_UInt gIndex;
|
||||||
|
|
||||||
FT_ULong charCode = FT_Get_First_Char(ftFace, &gIndex);
|
FT_ULong charCode = FT_Get_First_Char(ftFace, &gIndex);
|
||||||
while (gIndex != 0)
|
while (gIndex != 0)
|
||||||
{
|
{
|
||||||
if (cacheGlyphData(charCode, pixelSize) != NULL) ++i;
|
if (cacheGlyphData(charCode, pixelSize) != NULL) ++i;
|
||||||
charCode = FT_Get_Next_Char(ftFace, charCode, &gIndex);
|
charCode = FT_Get_Next_Char(ftFace, charCode, &gIndex);
|
||||||
}
|
}
|
||||||
return (uint16_t) (i);
|
return (uint16_t) (i);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -237,7 +237,7 @@ uint16_t FreeTypeGX::cacheGlyphDataComplete(int16_t pixelSize)
|
||||||
|
|
||||||
void FreeTypeGX::loadGlyphData(FT_Bitmap *bmp, ftgxCharData *charData)
|
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);
|
memset(glyphData, 0x00, charData->textureWidth * charData->textureHeight * 4);
|
||||||
|
|
||||||
uint8_t *bmsrc = (uint8_t *)bmp->buffer;
|
uint8_t *bmsrc = (uint8_t *)bmp->buffer;
|
||||||
|
@ -278,7 +278,7 @@ void FreeTypeGX::loadGlyphData(FT_Bitmap *bmp, ftgxCharData *charData)
|
||||||
DCFlushRange(dataBufferIA4, bufferSize);
|
DCFlushRange(dataBufferIA4, bufferSize);
|
||||||
free(glyphData);
|
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.
|
* 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 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)
|
int16_t FreeTypeGX::getStyleOffsetWidth(uint16_t width, uint16_t format)
|
||||||
{
|
{
|
||||||
if (format & FTGX_JUSTIFY_LEFT)
|
if (format & FTGX_JUSTIFY_LEFT)
|
||||||
return 0;
|
return 0;
|
||||||
else if (format & FTGX_JUSTIFY_CENTER)
|
else if (format & FTGX_JUSTIFY_CENTER)
|
||||||
return -(width >> 1);
|
return -(width >> 1);
|
||||||
else if (format & FTGX_JUSTIFY_RIGHT) return -width;
|
else if (format & FTGX_JUSTIFY_RIGHT) return -width;
|
||||||
return 0;
|
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.
|
* 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 offset Current pixel offset data of the string.
|
||||||
* @param format Positional format of the string.
|
* @param format Positional format of the string.
|
||||||
*/
|
*/
|
||||||
int16_t FreeTypeGX::getStyleOffsetHeight(int16_t format, uint16_t pixelSize)
|
int16_t FreeTypeGX::getStyleOffsetHeight(int16_t format, uint16_t pixelSize)
|
||||||
{
|
{
|
||||||
map<int16_t, ftgxDataOffset>::iterator itrAlign = ftgxAlign.find(pixelSize);
|
map<int16_t, ftgxDataOffset>::iterator itrAlign = ftgxAlign.find(pixelSize);
|
||||||
if (itrAlign == ftgxAlign.end()) return 0;
|
if (itrAlign == ftgxAlign.end()) return 0;
|
||||||
|
|
||||||
switch (format & FTGX_ALIGN_MASK)
|
switch (format & FTGX_ALIGN_MASK)
|
||||||
{
|
{
|
||||||
case FTGX_ALIGN_TOP:
|
case FTGX_ALIGN_TOP:
|
||||||
return itrAlign->second.ascender;
|
return itrAlign->second.ascender;
|
||||||
|
|
||||||
case FTGX_ALIGN_MIDDLE:
|
case FTGX_ALIGN_MIDDLE:
|
||||||
default:
|
default:
|
||||||
return (itrAlign->second.ascender + itrAlign->second.descender + 1) >> 1;
|
return (itrAlign->second.ascender + itrAlign->second.descender + 1) >> 1;
|
||||||
|
|
||||||
case FTGX_ALIGN_BOTTOM:
|
case FTGX_ALIGN_BOTTOM:
|
||||||
return itrAlign->second.descender;
|
return itrAlign->second.descender;
|
||||||
|
|
||||||
case FTGX_ALIGN_BASELINE:
|
case FTGX_ALIGN_BASELINE:
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
case FTGX_ALIGN_GLYPH_TOP:
|
case FTGX_ALIGN_GLYPH_TOP:
|
||||||
return itrAlign->second.max;
|
return itrAlign->second.max;
|
||||||
|
|
||||||
case FTGX_ALIGN_GLYPH_MIDDLE:
|
case FTGX_ALIGN_GLYPH_MIDDLE:
|
||||||
return (itrAlign->second.max + itrAlign->second.min + 1) >> 1;
|
return (itrAlign->second.max + itrAlign->second.min + 1) >> 1;
|
||||||
|
|
||||||
case FTGX_ALIGN_GLYPH_BOTTOM:
|
case FTGX_ALIGN_GLYPH_BOTTOM:
|
||||||
return itrAlign->second.min;
|
return itrAlign->second.min;
|
||||||
}
|
}
|
||||||
return 0;
|
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 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 fullTextWidth = textWidth > 0 ? textWidth : getWidth(text, pixelSize);
|
||||||
uint16_t x_pos = x, printed = 0;
|
uint16_t x_pos = x, printed = 0;
|
||||||
uint16_t x_offset = 0, y_offset = 0;
|
uint16_t x_offset = 0, y_offset = 0;
|
||||||
GXTexObj glyphTexture;
|
GXTexObj glyphTexture;
|
||||||
FT_Vector pairDelta;
|
FT_Vector pairDelta;
|
||||||
|
|
||||||
if (textStyle & FTGX_JUSTIFY_MASK)
|
if (textStyle & FTGX_JUSTIFY_MASK)
|
||||||
{
|
{
|
||||||
x_offset = getStyleOffsetWidth(fullTextWidth, textStyle);
|
x_offset = getStyleOffsetWidth(fullTextWidth, textStyle);
|
||||||
}
|
}
|
||||||
if (textStyle & FTGX_ALIGN_MASK)
|
if (textStyle & FTGX_ALIGN_MASK)
|
||||||
{
|
{
|
||||||
y_offset = getStyleOffsetHeight(textStyle, pixelSize);
|
y_offset = getStyleOffsetHeight(textStyle, pixelSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
||||||
while (text[i])
|
while (text[i])
|
||||||
{
|
{
|
||||||
if (widthLimit > 0 && (x_pos - x) > widthLimit) break;
|
if (widthLimit > 0 && (x_pos - x) > widthLimit) break;
|
||||||
|
|
||||||
ftgxCharData* glyphData = cacheGlyphData(text[i], pixelSize);
|
ftgxCharData* glyphData = cacheGlyphData(text[i], pixelSize);
|
||||||
|
|
||||||
if (glyphData != NULL)
|
if (glyphData != NULL)
|
||||||
{
|
{
|
||||||
if (ftKerningEnabled && i > 0)
|
if (ftKerningEnabled && i > 0)
|
||||||
{
|
{
|
||||||
FT_Get_Kerning(ftFace, fontData[pixelSize][text[i - 1]].glyphIndex, glyphData->glyphIndex, FT_KERNING_DEFAULT, &pairDelta);
|
FT_Get_Kerning(ftFace, fontData[pixelSize][text[i - 1]].glyphIndex, glyphData->glyphIndex, FT_KERNING_DEFAULT, &pairDelta);
|
||||||
x_pos += pairDelta.x >> 6;
|
x_pos += pairDelta.x >> 6;
|
||||||
}
|
}
|
||||||
|
|
||||||
GX_InitTexObj(&glyphTexture, glyphData->glyphDataTexture, glyphData->textureWidth, glyphData->textureHeight, GX_TF_IA4, GX_CLAMP, GX_CLAMP, GX_FALSE);
|
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);
|
copyTextureToFramebuffer(&glyphTexture, glyphData->textureWidth, glyphData->textureHeight, x_pos + glyphData->renderOffsetX + x_offset, y - glyphData->renderOffsetY + y_offset, z, color);
|
||||||
|
|
||||||
x_pos += glyphData->glyphAdvanceX;
|
x_pos += glyphData->glyphAdvanceX;
|
||||||
++printed;
|
++printed;
|
||||||
}
|
}
|
||||||
++i;
|
++i;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (textStyle & FTGX_STYLE_MASK)
|
if (textStyle & FTGX_STYLE_MASK)
|
||||||
{
|
{
|
||||||
getOffset(text, pixelSize, widthLimit);
|
getOffset(text, pixelSize, widthLimit);
|
||||||
drawTextFeature(x + x_offset, y + y_offset, z, pixelSize, fullTextWidth, &ftgxAlign[pixelSize], textStyle,
|
drawTextFeature(x + x_offset, y + y_offset, z, pixelSize, fullTextWidth, &ftgxAlign[pixelSize], textStyle,
|
||||||
color);
|
color);
|
||||||
}
|
}
|
||||||
|
|
||||||
return printed;
|
return printed;
|
||||||
}
|
}
|
||||||
|
|
||||||
void FreeTypeGX::drawTextFeature(int16_t x, int16_t y, int16_t z, int16_t pixelSize, uint16_t width,
|
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
|
if (format & FTGX_STYLE_STRIKE) this->copyFeatureToFramebuffer(width, featureHeight, x, y
|
||||||
- ((offsetData->max) >> 1), z, color);
|
- ((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)
|
uint16_t FreeTypeGX::getWidth(const wchar_t *text, int16_t pixelSize)
|
||||||
{
|
{
|
||||||
if (!text) return 0;
|
if (!text) return 0;
|
||||||
|
|
||||||
uint16_t strWidth = 0;
|
uint16_t strWidth = 0;
|
||||||
FT_Vector pairDelta;
|
FT_Vector pairDelta;
|
||||||
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
while (text[i])
|
while (text[i])
|
||||||
{
|
{
|
||||||
ftgxCharData* glyphData = cacheGlyphData(text[i], pixelSize);
|
ftgxCharData* glyphData = cacheGlyphData(text[i], pixelSize);
|
||||||
|
|
||||||
if (glyphData != NULL)
|
if (glyphData != NULL)
|
||||||
{
|
{
|
||||||
if (ftKerningEnabled && (i > 0))
|
if (ftKerningEnabled && (i > 0))
|
||||||
{
|
{
|
||||||
FT_Get_Kerning(ftFace, fontData[pixelSize][text[i - 1]].glyphIndex, glyphData->glyphIndex,
|
FT_Get_Kerning(ftFace, fontData[pixelSize][text[i - 1]].glyphIndex, glyphData->glyphIndex,
|
||||||
FT_KERNING_DEFAULT, &pairDelta);
|
FT_KERNING_DEFAULT, &pairDelta);
|
||||||
strWidth += pairDelta.x >> 6;
|
strWidth += pairDelta.x >> 6;
|
||||||
}
|
}
|
||||||
|
|
||||||
strWidth += glyphData->glyphAdvanceX;
|
strWidth += glyphData->glyphAdvanceX;
|
||||||
}
|
}
|
||||||
++i;
|
++i;
|
||||||
}
|
}
|
||||||
return strWidth;
|
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 FreeTypeGX::getCharWidth(const wchar_t wChar, int16_t pixelSize, const wchar_t prevChar)
|
||||||
{
|
{
|
||||||
uint16_t strWidth = 0;
|
uint16_t strWidth = 0;
|
||||||
ftgxCharData * glyphData = cacheGlyphData(wChar, pixelSize);
|
ftgxCharData * glyphData = cacheGlyphData(wChar, pixelSize);
|
||||||
|
|
||||||
if (glyphData != NULL)
|
if (glyphData != NULL)
|
||||||
{
|
{
|
||||||
if (ftKerningEnabled && prevChar != 0x0000)
|
if (ftKerningEnabled && prevChar != 0x0000)
|
||||||
{
|
{
|
||||||
FT_Vector pairDelta;
|
FT_Vector pairDelta;
|
||||||
FT_Get_Kerning(ftFace, fontData[pixelSize][prevChar].glyphIndex, glyphData->glyphIndex, FT_KERNING_DEFAULT,
|
FT_Get_Kerning(ftFace, fontData[pixelSize][prevChar].glyphIndex, glyphData->glyphIndex, FT_KERNING_DEFAULT,
|
||||||
&pairDelta);
|
&pairDelta);
|
||||||
strWidth += pairDelta.x >> 6;
|
strWidth += pairDelta.x >> 6;
|
||||||
}
|
}
|
||||||
strWidth += glyphData->glyphAdvanceX;
|
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)
|
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)
|
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;
|
int16_t strMax = 0, strMin = 9999;
|
||||||
uint16_t currWidth = 0;
|
uint16_t currWidth = 0;
|
||||||
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
||||||
while (text[i])
|
while (text[i])
|
||||||
{
|
{
|
||||||
if (widthLimit > 0 && currWidth >= widthLimit) break;
|
if (widthLimit > 0 && currWidth >= widthLimit) break;
|
||||||
|
|
||||||
ftgxCharData* glyphData = cacheGlyphData(text[i], pixelSize);
|
ftgxCharData* glyphData = cacheGlyphData(text[i], pixelSize);
|
||||||
|
|
||||||
if (glyphData != NULL)
|
if (glyphData != NULL)
|
||||||
{
|
{
|
||||||
strMax = glyphData->renderOffsetMax > strMax ? glyphData->renderOffsetMax : strMax;
|
strMax = glyphData->renderOffsetMax > strMax ? glyphData->renderOffsetMax : strMax;
|
||||||
strMin = glyphData->renderOffsetMin < strMin ? glyphData->renderOffsetMin : strMin;
|
strMin = glyphData->renderOffsetMin < strMin ? glyphData->renderOffsetMin : strMin;
|
||||||
currWidth += glyphData->glyphAdvanceX;
|
currWidth += glyphData->glyphAdvanceX;
|
||||||
}
|
}
|
||||||
|
|
||||||
++i;
|
++i;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ftPointSize != pixelSize)
|
if (ftPointSize != pixelSize)
|
||||||
{
|
{
|
||||||
ftPointSize = pixelSize;
|
ftPointSize = pixelSize;
|
||||||
FT_Set_Pixel_Sizes(ftFace, 0, ftPointSize);
|
FT_Set_Pixel_Sizes(ftFace, 0, ftPointSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
ftgxAlign[pixelSize].ascender = ftFace->size->metrics.ascender >> 6;
|
ftgxAlign[pixelSize].ascender = ftFace->size->metrics.ascender >> 6;
|
||||||
ftgxAlign[pixelSize].descender = ftFace->size->metrics.descender >> 6;
|
ftgxAlign[pixelSize].descender = ftFace->size->metrics.descender >> 6;
|
||||||
ftgxAlign[pixelSize].max = strMax;
|
ftgxAlign[pixelSize].max = strMax;
|
||||||
ftgxAlign[pixelSize].min = strMin;
|
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.
|
* 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 texWidth The pixel width of the texture object.
|
||||||
* @param texHeight The pixel height 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.
|
* @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.
|
* @param color Color to apply to the texture.
|
||||||
*/
|
*/
|
||||||
void FreeTypeGX::copyTextureToFramebuffer(GXTexObj *texObj, f32 texWidth, f32 texHeight, int16_t screenX,
|
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_LoadTexObj(texObj, GX_TEXMAP0);
|
||||||
GX_InvalidateTexAll();
|
GX_InvalidateTexAll();
|
||||||
|
|
||||||
GX_SetVtxDesc(GX_VA_POS, GX_DIRECT);
|
GX_SetVtxDesc(GX_VA_POS, GX_DIRECT);
|
||||||
GX_SetVtxDesc(GX_VA_TEX0, GX_DIRECT);
|
GX_SetVtxDesc(GX_VA_TEX0, GX_DIRECT);
|
||||||
GX_SetVtxDesc(GX_VA_CLR0, GX_DIRECT);
|
GX_SetVtxDesc(GX_VA_CLR0, GX_DIRECT);
|
||||||
|
|
||||||
GX_Begin(GX_QUADS, this->vertexIndex, 4);
|
GX_Begin(GX_QUADS, this->vertexIndex, 4);
|
||||||
GX_Position3s16(screenX, screenY, screenZ);
|
GX_Position3s16(screenX, screenY, screenZ);
|
||||||
GX_Color4u8(color.r, color.g, color.b, color.a);
|
GX_Color4u8(color.r, color.g, color.b, color.a);
|
||||||
GX_TexCoord2f32(0.0f, 0.0f);
|
GX_TexCoord2f32(0.0f, 0.0f);
|
||||||
|
|
||||||
GX_Position3s16(texWidth + screenX, screenY, screenZ);
|
GX_Position3s16(texWidth + screenX, screenY, screenZ);
|
||||||
GX_Color4u8(color.r, color.g, color.b, color.a);
|
GX_Color4u8(color.r, color.g, color.b, color.a);
|
||||||
GX_TexCoord2f32(1.0f, 0.0f);
|
GX_TexCoord2f32(1.0f, 0.0f);
|
||||||
|
|
||||||
GX_Position3s16(texWidth + screenX, texHeight + screenY, screenZ);
|
GX_Position3s16(texWidth + screenX, texHeight + screenY, screenZ);
|
||||||
GX_Color4u8(color.r, color.g, color.b, color.a);
|
GX_Color4u8(color.r, color.g, color.b, color.a);
|
||||||
GX_TexCoord2f32(1.0f, 1.0f);
|
GX_TexCoord2f32(1.0f, 1.0f);
|
||||||
|
|
||||||
GX_Position3s16(screenX, texHeight + screenY, screenZ);
|
GX_Position3s16(screenX, texHeight + screenY, screenZ);
|
||||||
GX_Color4u8(color.r, color.g, color.b, color.a);
|
GX_Color4u8(color.r, color.g, color.b, color.a);
|
||||||
GX_TexCoord2f32(0.0f, 1.0f);
|
GX_TexCoord2f32(0.0f, 1.0f);
|
||||||
GX_End();
|
GX_End();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -595,26 +595,26 @@ void FreeTypeGX::copyTextureToFramebuffer(GXTexObj *texObj, f32 texWidth, f32 te
|
||||||
* @param color Color to apply to the texture.
|
* @param color Color to apply to the texture.
|
||||||
*/
|
*/
|
||||||
void FreeTypeGX::copyFeatureToFramebuffer(f32 featureWidth, f32 featureHeight, int16_t screenX, int16_t screenY,
|
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_SetTevOp(GX_TEVSTAGE0, GX_PASSCLR);
|
||||||
GX_SetVtxDesc(GX_VA_POS, GX_DIRECT);
|
GX_SetVtxDesc(GX_VA_POS, GX_DIRECT);
|
||||||
GX_SetVtxDesc(GX_VA_CLR0, GX_DIRECT);
|
GX_SetVtxDesc(GX_VA_CLR0, GX_DIRECT);
|
||||||
GX_SetVtxDesc(GX_VA_TEX0, GX_NONE);
|
GX_SetVtxDesc(GX_VA_TEX0, GX_NONE);
|
||||||
|
|
||||||
GX_Begin(GX_QUADS, this->vertexIndex, 4);
|
GX_Begin(GX_QUADS, this->vertexIndex, 4);
|
||||||
GX_Position3s16(screenX, screenY, screenZ);
|
GX_Position3s16(screenX, screenY, screenZ);
|
||||||
GX_Color4u8(color.r, color.g, color.b, color.a);
|
GX_Color4u8(color.r, color.g, color.b, color.a);
|
||||||
|
|
||||||
GX_Position3s16(featureWidth + screenX, screenY, screenZ);
|
GX_Position3s16(featureWidth + screenX, screenY, screenZ);
|
||||||
GX_Color4u8(color.r, color.g, color.b, color.a);
|
GX_Color4u8(color.r, color.g, color.b, color.a);
|
||||||
|
|
||||||
GX_Position3s16(featureWidth + screenX, featureHeight + screenY, screenZ);
|
GX_Position3s16(featureWidth + screenX, featureHeight + screenY, screenZ);
|
||||||
GX_Color4u8(color.r, color.g, color.b, color.a);
|
GX_Color4u8(color.r, color.g, color.b, color.a);
|
||||||
|
|
||||||
GX_Position3s16(screenX, featureHeight + screenY, screenZ);
|
GX_Position3s16(screenX, featureHeight + screenY, screenZ);
|
||||||
GX_Color4u8(color.r, color.g, color.b, color.a);
|
GX_Color4u8(color.r, color.g, color.b, color.a);
|
||||||
GX_End();
|
GX_End();
|
||||||
|
|
||||||
GX_SetTevOp(GX_TEVSTAGE0, GX_MODULATE);
|
GX_SetTevOp(GX_TEVSTAGE0, GX_MODULATE);
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,18 +39,18 @@
|
||||||
*/
|
*/
|
||||||
typedef struct ftgxCharData_
|
typedef struct ftgxCharData_
|
||||||
{
|
{
|
||||||
int16_t renderOffsetX; /**< Texture X axis bearing offset. */
|
int16_t renderOffsetX; /**< Texture X axis bearing offset. */
|
||||||
uint16_t glyphAdvanceX; /**< Character glyph X coordinate advance in pixels. */
|
uint16_t glyphAdvanceX; /**< Character glyph X coordinate advance in pixels. */
|
||||||
uint32_t glyphIndex; /**< Charachter glyph index in the font face. */
|
uint32_t glyphIndex; /**< Charachter glyph index in the font face. */
|
||||||
|
|
||||||
uint16_t textureWidth; /**< Texture width in pixels/bytes. */
|
uint16_t textureWidth; /**< Texture width in pixels/bytes. */
|
||||||
uint16_t textureHeight; /**< Texture glyph height in pixels/bytes. */
|
uint16_t textureHeight; /**< Texture glyph height in pixels/bytes. */
|
||||||
|
|
||||||
int16_t renderOffsetY; /**< Texture Y axis bearing offset. */
|
int16_t renderOffsetY; /**< Texture Y axis bearing offset. */
|
||||||
int16_t renderOffsetMax; /**< Texture Y axis bearing maximum value. */
|
int16_t renderOffsetMax; /**< Texture Y axis bearing maximum value. */
|
||||||
int16_t renderOffsetMin; /**< Texture Y axis bearing minimum 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;
|
} ftgxCharData;
|
||||||
|
|
||||||
/*! \struct ftgxDataOffset_
|
/*! \struct ftgxDataOffset_
|
||||||
|
@ -59,10 +59,10 @@ typedef struct ftgxCharData_
|
||||||
*/
|
*/
|
||||||
typedef struct ftgxDataOffset_
|
typedef struct ftgxDataOffset_
|
||||||
{
|
{
|
||||||
int16_t ascender; /**< Maximum data offset. */
|
int16_t ascender; /**< Maximum data offset. */
|
||||||
int16_t descender; /**< Minimum data offset. */
|
int16_t descender; /**< Minimum data offset. */
|
||||||
int16_t max; /**< Maximum data offset. */
|
int16_t max; /**< Maximum data offset. */
|
||||||
int16_t min; /**< Minimum data offset. */
|
int16_t min; /**< Minimum data offset. */
|
||||||
} ftgxDataOffset;
|
} ftgxDataOffset;
|
||||||
|
|
||||||
typedef struct ftgxCharData_ ftgxCharData;
|
typedef struct ftgxCharData_ ftgxCharData;
|
||||||
|
@ -70,24 +70,24 @@ typedef struct ftgxDataOffset_ ftgxDataOffset;
|
||||||
|
|
||||||
#define _TEXT(t) L ## t /**< Unicode helper macro. */
|
#define _TEXT(t) L ## t /**< Unicode helper macro. */
|
||||||
|
|
||||||
#define FTGX_NULL 0x0000
|
#define FTGX_NULL 0x0000
|
||||||
#define FTGX_JUSTIFY_LEFT 0x0001
|
#define FTGX_JUSTIFY_LEFT 0x0001
|
||||||
#define FTGX_JUSTIFY_CENTER 0x0002
|
#define FTGX_JUSTIFY_CENTER 0x0002
|
||||||
#define FTGX_JUSTIFY_RIGHT 0x0004
|
#define FTGX_JUSTIFY_RIGHT 0x0004
|
||||||
#define FTGX_JUSTIFY_MASK 0x000f
|
#define FTGX_JUSTIFY_MASK 0x000f
|
||||||
|
|
||||||
#define FTGX_ALIGN_TOP 0x0010
|
#define FTGX_ALIGN_TOP 0x0010
|
||||||
#define FTGX_ALIGN_MIDDLE 0x0020
|
#define FTGX_ALIGN_MIDDLE 0x0020
|
||||||
#define FTGX_ALIGN_BOTTOM 0x0040
|
#define FTGX_ALIGN_BOTTOM 0x0040
|
||||||
#define FTGX_ALIGN_BASELINE 0x0080
|
#define FTGX_ALIGN_BASELINE 0x0080
|
||||||
#define FTGX_ALIGN_GLYPH_TOP 0x0100
|
#define FTGX_ALIGN_GLYPH_TOP 0x0100
|
||||||
#define FTGX_ALIGN_GLYPH_MIDDLE 0x0200
|
#define FTGX_ALIGN_GLYPH_MIDDLE 0x0200
|
||||||
#define FTGX_ALIGN_GLYPH_BOTTOM 0x0400
|
#define FTGX_ALIGN_GLYPH_BOTTOM 0x0400
|
||||||
#define FTGX_ALIGN_MASK 0x0ff0
|
#define FTGX_ALIGN_MASK 0x0ff0
|
||||||
|
|
||||||
#define FTGX_STYLE_UNDERLINE 0x1000
|
#define FTGX_STYLE_UNDERLINE 0x1000
|
||||||
#define FTGX_STYLE_STRIKE 0x2000
|
#define FTGX_STYLE_STRIKE 0x2000
|
||||||
#define FTGX_STYLE_MASK 0xf000
|
#define FTGX_STYLE_MASK 0xf000
|
||||||
|
|
||||||
const GXColor ftgxWhite = ( GXColor )
|
const GXColor ftgxWhite = ( GXColor )
|
||||||
{ 0xff, 0xff, 0xff, 0xff}; /**< Constant color value used only to sanitize Doxygen documentation. */
|
{ 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
|
class FreeTypeGX
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
FT_Library ftLibrary; /**< FreeType FT_Library instance. */
|
FT_Library ftLibrary; /**< FreeType FT_Library instance. */
|
||||||
FT_Face ftFace; /**< FreeType reusable FT_Face typographic object. */
|
FT_Face ftFace; /**< FreeType reusable FT_Face typographic object. */
|
||||||
int16_t ftPointSize; /**< Current set size of the rendered font. */
|
int16_t ftPointSize; /**< Current set size of the rendered font. */
|
||||||
bool ftKerningEnabled; /**< Flag indicating the availability of font kerning data. */
|
bool ftKerningEnabled; /**< Flag indicating the availability of font kerning data. */
|
||||||
uint8_t vertexIndex; /**< Vertex format descriptor index. */
|
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, 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. */
|
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 getStyleOffsetWidth(uint16_t width, uint16_t format);
|
||||||
int16_t getStyleOffsetHeight(int16_t format, uint16_t pixelSize);
|
int16_t getStyleOffsetHeight(int16_t format, uint16_t pixelSize);
|
||||||
|
|
||||||
void unloadFont();
|
void unloadFont();
|
||||||
ftgxCharData *cacheGlyphData(wchar_t charCode, int16_t pixelSize);
|
ftgxCharData *cacheGlyphData(wchar_t charCode, int16_t pixelSize);
|
||||||
uint16_t cacheGlyphDataComplete(int16_t pixelSize);
|
uint16_t cacheGlyphDataComplete(int16_t pixelSize);
|
||||||
void loadGlyphData(FT_Bitmap *bmp, ftgxCharData *charData);
|
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,
|
void 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);
|
||||||
void copyTextureToFramebuffer(GXTexObj *texObj, f32 texWidth, f32 texHeight, int16_t screenX, int16_t screenY,
|
void copyTextureToFramebuffer(GXTexObj *texObj, f32 texWidth, f32 texHeight, int16_t screenX, int16_t screenY,
|
||||||
int16_t screenZ, GXColor color);
|
int16_t screenZ, GXColor color);
|
||||||
void copyFeatureToFramebuffer(f32 featureWidth, f32 featureHeight, int16_t screenX, int16_t screenY,
|
void copyFeatureToFramebuffer(f32 featureWidth, f32 featureHeight, int16_t screenX, int16_t screenY,
|
||||||
int16_t screenZ, GXColor color);
|
int16_t screenZ, GXColor color);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
FreeTypeGX(const uint8_t* fontBuffer, FT_Long bufferSize, bool lastFace = false);
|
FreeTypeGX(const uint8_t* fontBuffer, FT_Long bufferSize, bool lastFace = false);
|
||||||
~FreeTypeGX();
|
~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 =
|
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);
|
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 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 getCharWidth(const wchar_t wChar, int16_t pixelSize, const wchar_t prevChar = 0x0000);
|
||||||
uint16_t getHeight(const wchar_t *text, int16_t pixelSize);
|
uint16_t getHeight(const wchar_t *text, int16_t pixelSize);
|
||||||
void getOffset(const wchar_t *text, int16_t pixelSize, uint16_t widthLimit = 0);
|
void getOffset(const wchar_t *text, int16_t pixelSize, uint16_t widthLimit = 0);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* FREETYPEGX_H_ */
|
#endif /* FREETYPEGX_H_ */
|
||||||
|
|
|
@ -9,57 +9,57 @@
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
GuiImageData *LoadCoverImage(struct discHdr *header, bool Prefere3D, bool noCover)
|
GuiImageData *LoadCoverImage(struct discHdr *header, bool Prefere3D, bool noCover)
|
||||||
{
|
{
|
||||||
if (!header) return NULL;
|
if (!header) return NULL;
|
||||||
GuiImageData *Cover = NULL;
|
GuiImageData *Cover = NULL;
|
||||||
char ID3[4];
|
char ID3[4];
|
||||||
char IDfull[7];
|
char IDfull[7];
|
||||||
char Path[255];
|
char Path[255];
|
||||||
bool flag = Prefere3D;
|
bool flag = Prefere3D;
|
||||||
|
|
||||||
snprintf(ID3, sizeof(ID3), "%s", (char *) header->id);
|
snprintf(ID3, sizeof(ID3), "%s", (char *) header->id);
|
||||||
snprintf(IDfull, sizeof(IDfull), "%s", (char *) header->id);
|
snprintf(IDfull, sizeof(IDfull), "%s", (char *) header->id);
|
||||||
|
|
||||||
for (int i = 0; i < 2; ++i)
|
for (int i = 0; i < 2; ++i)
|
||||||
{
|
{
|
||||||
char *coverPath = flag ? Settings.covers_path : Settings.covers2d_path;
|
char *coverPath = flag ? Settings.covers_path : Settings.covers2d_path;
|
||||||
flag = !flag;
|
flag = !flag;
|
||||||
//Load full id image
|
//Load full id image
|
||||||
snprintf(Path, sizeof(Path), "%s%s.png", coverPath, IDfull);
|
snprintf(Path, sizeof(Path), "%s%s.png", coverPath, IDfull);
|
||||||
|
|
||||||
if(!CheckFile(Path))
|
if(!CheckFile(Path))
|
||||||
{
|
{
|
||||||
snprintf(Path, sizeof(Path), "%s%s.png", coverPath, ID3);
|
snprintf(Path, sizeof(Path), "%s%s.png", coverPath, ID3);
|
||||||
if(!CheckFile(Path))
|
if(!CheckFile(Path))
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
delete Cover;
|
delete Cover;
|
||||||
Cover = new (std::nothrow) GuiImageData(Path);
|
Cover = new (std::nothrow) GuiImageData(Path);
|
||||||
//Load short id image
|
//Load short id image
|
||||||
if (!Cover || !Cover->GetImage())
|
if (!Cover || !Cover->GetImage())
|
||||||
{
|
{
|
||||||
snprintf(Path, sizeof(Path), "%s%s.png", coverPath, ID3);
|
snprintf(Path, sizeof(Path), "%s%s.png", coverPath, ID3);
|
||||||
delete Cover;
|
delete Cover;
|
||||||
Cover = new (std::nothrow) GuiImageData(Path);
|
Cover = new (std::nothrow) GuiImageData(Path);
|
||||||
}
|
}
|
||||||
if (Cover && Cover->GetImage()) break;
|
if (Cover && Cover->GetImage()) break;
|
||||||
}
|
}
|
||||||
//Load no image
|
//Load no image
|
||||||
if (noCover && (!Cover || !Cover->GetImage()))
|
if (noCover && (!Cover || !Cover->GetImage()))
|
||||||
{
|
{
|
||||||
flag = Prefere3D;
|
flag = Prefere3D;
|
||||||
for (int i = 0; i < 2; ++i)
|
for (int i = 0; i < 2; ++i)
|
||||||
{
|
{
|
||||||
delete Cover;
|
delete Cover;
|
||||||
Cover = Resources::GetImageData(flag ? "nocover.png" : "nocoverFlat.png");
|
Cover = Resources::GetImageData(flag ? "nocover.png" : "nocoverFlat.png");
|
||||||
if (Cover && Cover->GetImage()) break;
|
if (Cover && Cover->GetImage()) break;
|
||||||
flag = !flag;
|
flag = !flag;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (Cover && !Cover->GetImage())
|
if (Cover && !Cover->GetImage())
|
||||||
{
|
{
|
||||||
delete Cover;
|
delete Cover;
|
||||||
Cover = NULL;
|
Cover = NULL;
|
||||||
}
|
}
|
||||||
return Cover;
|
return Cover;
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,55 +36,55 @@ OptionList::OptionList()
|
||||||
|
|
||||||
OptionList::~OptionList()
|
OptionList::~OptionList()
|
||||||
{
|
{
|
||||||
ClearList();
|
ClearList();
|
||||||
}
|
}
|
||||||
|
|
||||||
void OptionList::SetName(int i, const char *format, ...)
|
void OptionList::SetName(int i, const char *format, ...)
|
||||||
{
|
{
|
||||||
if(i < (int) name.size())
|
if(i < (int) name.size())
|
||||||
name[i].clear();
|
name[i].clear();
|
||||||
|
|
||||||
if(!format)
|
if(!format)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
char *tmp=0;
|
char *tmp=0;
|
||||||
va_list va;
|
va_list va;
|
||||||
va_start(va, format);
|
va_start(va, format);
|
||||||
if((vasprintf(&tmp, format, va)>=0) && tmp)
|
if((vasprintf(&tmp, format, va)>=0) && tmp)
|
||||||
{
|
{
|
||||||
if(i >= (int) name.size())
|
if(i >= (int) name.size())
|
||||||
{
|
{
|
||||||
Resize(i+1);
|
Resize(i+1);
|
||||||
}
|
}
|
||||||
|
|
||||||
name[i].assign(tmp);
|
name[i].assign(tmp);
|
||||||
|
|
||||||
listChanged = true;
|
listChanged = true;
|
||||||
}
|
}
|
||||||
va_end(va);
|
va_end(va);
|
||||||
|
|
||||||
if(tmp)
|
if(tmp)
|
||||||
free(tmp);
|
free(tmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
void OptionList::SetValue(int i, const char *format, ...)
|
void OptionList::SetValue(int i, const char *format, ...)
|
||||||
{
|
{
|
||||||
if(i < (int) value.size())
|
if(i < (int) value.size())
|
||||||
value[i].clear();
|
value[i].clear();
|
||||||
|
|
||||||
char *tmp=0;
|
char *tmp=0;
|
||||||
va_list va;
|
va_list va;
|
||||||
va_start(va, format);
|
va_start(va, format);
|
||||||
if((vasprintf(&tmp, format, va)>=0) && tmp)
|
if((vasprintf(&tmp, format, va)>=0) && tmp)
|
||||||
{
|
{
|
||||||
if(i >= (int) value.size())
|
if(i >= (int) value.size())
|
||||||
{
|
{
|
||||||
Resize(i+1);
|
Resize(i+1);
|
||||||
}
|
}
|
||||||
|
|
||||||
value[i].assign(tmp);
|
value[i].assign(tmp);
|
||||||
|
|
||||||
listChanged = true;
|
listChanged = true;
|
||||||
}
|
}
|
||||||
va_end(va);
|
va_end(va);
|
||||||
|
|
||||||
|
@ -94,35 +94,35 @@ void OptionList::SetValue(int i, const char *format, ...)
|
||||||
|
|
||||||
const char * OptionList::GetName(int i)
|
const char * OptionList::GetName(int i)
|
||||||
{
|
{
|
||||||
if(i < 0 || i >= (int) name.size())
|
if(i < 0 || i >= (int) name.size())
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
return name.at(i).c_str();
|
return name.at(i).c_str();
|
||||||
}
|
}
|
||||||
|
|
||||||
const char * OptionList::GetValue(int i)
|
const char * OptionList::GetValue(int i)
|
||||||
{
|
{
|
||||||
if(i < 0 || i >= (int) value.size())
|
if(i < 0 || i >= (int) value.size())
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
return value.at(i).c_str();
|
return value.at(i).c_str();
|
||||||
}
|
}
|
||||||
|
|
||||||
void OptionList::Resize(int size)
|
void OptionList::Resize(int size)
|
||||||
{
|
{
|
||||||
name.resize(size);
|
name.resize(size);
|
||||||
value.resize(size);
|
value.resize(size);
|
||||||
listChanged = true;
|
listChanged = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void OptionList::RemoveOption(int i)
|
void OptionList::RemoveOption(int i)
|
||||||
{
|
{
|
||||||
if(i < 0 || i >= (int) name.size())
|
if(i < 0 || i >= (int) name.size())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
name.erase(name.begin()+i);
|
name.erase(name.begin()+i);
|
||||||
value.erase(value.begin()+i);
|
value.erase(value.begin()+i);
|
||||||
listChanged = true;
|
listChanged = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void OptionList::ClearList()
|
void OptionList::ClearList()
|
||||||
|
@ -131,5 +131,5 @@ void OptionList::ClearList()
|
||||||
value.clear();
|
value.clear();
|
||||||
std::vector<std::string>().swap(name);
|
std::vector<std::string>().swap(name);
|
||||||
std::vector<std::string>().swap(value);
|
std::vector<std::string>().swap(value);
|
||||||
listChanged = true;
|
listChanged = true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,9 +36,9 @@ class OptionList
|
||||||
~OptionList();
|
~OptionList();
|
||||||
void SetName(int i, const char *format, ...) __attribute__((format (printf, 3, 4)));
|
void SetName(int i, const char *format, ...) __attribute__((format (printf, 3, 4)));
|
||||||
void SetValue(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);
|
const char * GetValue(int i);
|
||||||
void Resize(int size);
|
void Resize(int size);
|
||||||
int GetLength() { return name.size(); }
|
int GetLength() { return name.size(); }
|
||||||
bool IsChanged() { bool ret = listChanged; listChanged = false; return ret;}
|
bool IsChanged() { bool ret = listChanged; listChanged = false; return ret;}
|
||||||
void RemoveOption(int i);
|
void RemoveOption(int i);
|
||||||
|
|
|
@ -3,329 +3,329 @@
|
||||||
#include "Text.hpp"
|
#include "Text.hpp"
|
||||||
|
|
||||||
Text::Text(const char * t, int s, GXColor c) :
|
Text::Text(const char * t, int s, GXColor c) :
|
||||||
GuiText(t, s, c)
|
GuiText(t, s, c)
|
||||||
{
|
{
|
||||||
maxWidth = 400;
|
maxWidth = 400;
|
||||||
linestodraw = 9;
|
linestodraw = 9;
|
||||||
curLineStart = 0;
|
curLineStart = 0;
|
||||||
FirstLineOffset = 0;
|
FirstLineOffset = 0;
|
||||||
wText = NULL;
|
wText = NULL;
|
||||||
|
|
||||||
if (!text) return;
|
if (!text) return;
|
||||||
|
|
||||||
wText = new (std::nothrow) wString(text);
|
wText = new (std::nothrow) wString(text);
|
||||||
if (!wText)
|
if (!wText)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (wText->size() == 0)
|
if (wText->size() == 0)
|
||||||
{
|
{
|
||||||
wText->push_back(L' ');
|
wText->push_back(L' ');
|
||||||
wText->push_back(0);
|
wText->push_back(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
textWidth = (font ? font : fontSystem)->getWidth(wText->data(), currentSize);
|
textWidth = (font ? font : fontSystem)->getWidth(wText->data(), currentSize);
|
||||||
delete[] text;
|
delete[] text;
|
||||||
text = NULL;
|
text = NULL;
|
||||||
|
|
||||||
SetMaxWidth(maxWidth);
|
SetMaxWidth(maxWidth);
|
||||||
}
|
}
|
||||||
|
|
||||||
Text::Text(const wchar_t * t, int s, GXColor c) :
|
Text::Text(const wchar_t * t, int s, GXColor c) :
|
||||||
GuiText((wchar_t *) NULL, s, c)
|
GuiText((wchar_t *) NULL, s, c)
|
||||||
{
|
{
|
||||||
maxWidth = 400;
|
maxWidth = 400;
|
||||||
linestodraw = 9;
|
linestodraw = 9;
|
||||||
curLineStart = 0;
|
curLineStart = 0;
|
||||||
FirstLineOffset = 0;
|
FirstLineOffset = 0;
|
||||||
wText = NULL;
|
wText = NULL;
|
||||||
|
|
||||||
if (!t) return;
|
if (!t) return;
|
||||||
|
|
||||||
wText = new (std::nothrow) wString(t);
|
wText = new (std::nothrow) wString(t);
|
||||||
if (!wText)
|
if (!wText)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (wText->size() == 0)
|
if (wText->size() == 0)
|
||||||
{
|
{
|
||||||
wText->push_back(L' ');
|
wText->push_back(L' ');
|
||||||
wText->push_back(0);
|
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()
|
Text::~Text()
|
||||||
{
|
{
|
||||||
if (wText) delete wText;
|
if (wText) delete wText;
|
||||||
wText = NULL;
|
wText = NULL;
|
||||||
|
|
||||||
TextLines.clear();
|
TextLines.clear();
|
||||||
ClearDynamicText();
|
ClearDynamicText();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Text::SetText(const char * t)
|
void Text::SetText(const char * t)
|
||||||
{
|
{
|
||||||
wchar_t * tmp = charToWideChar(t);
|
wchar_t * tmp = charToWideChar(t);
|
||||||
if (!tmp) return;
|
if (!tmp) return;
|
||||||
|
|
||||||
if (wText) delete wText;
|
if (wText) delete wText;
|
||||||
|
|
||||||
wText = new (std::nothrow) wString(tmp);
|
wText = new (std::nothrow) wString(tmp);
|
||||||
if (!wText)
|
if (!wText)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (wText->size() == 0)
|
if (wText->size() == 0)
|
||||||
{
|
{
|
||||||
wText->push_back(L' ');
|
wText->push_back(L' ');
|
||||||
wText->push_back(0);
|
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();
|
ClearDynamicText();
|
||||||
CalcLineOffsets();
|
CalcLineOffsets();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Text::SetText(const wchar_t * t)
|
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);
|
wText = new wString(t);
|
||||||
textWidth = (font ? font : fontSystem)->getWidth(wText->data(), currentSize);
|
textWidth = (font ? font : fontSystem)->getWidth(wText->data(), currentSize);
|
||||||
CalcLineOffsets();
|
CalcLineOffsets();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Text::SetMaxWidth(int w)
|
void Text::SetMaxWidth(int w)
|
||||||
{
|
{
|
||||||
maxWidth = w;
|
maxWidth = w;
|
||||||
curLineStart = 0;
|
curLineStart = 0;
|
||||||
Refresh();
|
Refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Text::SetTextLine(int line)
|
void Text::SetTextLine(int line)
|
||||||
{
|
{
|
||||||
if (line < 0)
|
if (line < 0)
|
||||||
line = 0;
|
line = 0;
|
||||||
else if (line > (int) TextLines.size() - 1) line = TextLines.size() - 1;
|
else if (line > (int) TextLines.size() - 1) line = TextLines.size() - 1;
|
||||||
|
|
||||||
curLineStart = line;
|
curLineStart = line;
|
||||||
|
|
||||||
FillRows();
|
FillRows();
|
||||||
|
|
||||||
while ((int) textDyn.size() < linestodraw && curLineStart > 0)
|
while ((int) textDyn.size() < linestodraw && curLineStart > 0)
|
||||||
{
|
{
|
||||||
PreviousLine();
|
PreviousLine();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Text::SetTextPos(int pos)
|
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++)
|
for (u32 i = 0; i < TextLines.size(); i++)
|
||||||
{
|
{
|
||||||
int curDiff = abs(TextLines[i].LineOffset - pos);
|
int curDiff = abs(TextLines[i].LineOffset - pos);
|
||||||
if (curDiff < diff)
|
if (curDiff < diff)
|
||||||
{
|
{
|
||||||
diff = curDiff;
|
diff = curDiff;
|
||||||
curLineStart = i;
|
curLineStart = i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
FillRows();
|
FillRows();
|
||||||
|
|
||||||
while ((int) textDyn.size() < linestodraw && curLineStart > 0)
|
while ((int) textDyn.size() < linestodraw && curLineStart > 0)
|
||||||
{
|
{
|
||||||
PreviousLine();
|
PreviousLine();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const wchar_t * Text::GetText()
|
const wchar_t * Text::GetText()
|
||||||
{
|
{
|
||||||
return wText->c_str();
|
return wText->c_str();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string Text::GetUTF8String(void) const
|
std::string Text::GetUTF8String(void) const
|
||||||
{
|
{
|
||||||
return wText->toUTF8();
|
return wText->toUTF8();
|
||||||
}
|
}
|
||||||
|
|
||||||
int Text::GetLineOffset(int ind)
|
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)
|
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()
|
void Text::Refresh()
|
||||||
{
|
{
|
||||||
CalcLineOffsets();
|
CalcLineOffsets();
|
||||||
FillRows();
|
FillRows();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Text::NextLine()
|
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()
|
void Text::PreviousLine()
|
||||||
{
|
{
|
||||||
if (!wText || curLineStart - 1 < 0) return;
|
if (!wText || curLineStart - 1 < 0) return;
|
||||||
|
|
||||||
--curLineStart;
|
--curLineStart;
|
||||||
|
|
||||||
FillRows();
|
FillRows();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Text::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++)
|
for (int i = 0; i < linestodraw && curLineStart+i < (int) TextLines.size(); i++)
|
||||||
{
|
{
|
||||||
if (i >= (int) textDyn.size())
|
if (i >= (int) textDyn.size())
|
||||||
{
|
{
|
||||||
textDyn.resize(i + 1);
|
textDyn.resize(i + 1);
|
||||||
textDyn[i] = new wchar_t[maxWidth];
|
textDyn[i] = new wchar_t[maxWidth];
|
||||||
}
|
}
|
||||||
int offset = TextLines[curLineStart + i].LineOffset;
|
int offset = TextLines[curLineStart + i].LineOffset;
|
||||||
int count = TextLines[curLineStart + i].CharCount + 1;
|
int count = TextLines[curLineStart + i].CharCount + 1;
|
||||||
|
|
||||||
for (int n = 0; n < count && offset + n < (int) wText->size(); n++)
|
for (int n = 0; n < count && offset + n < (int) wText->size(); n++)
|
||||||
textDyn[i][n] = wText->at(offset + 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()
|
void Text::CalcLineOffsets()
|
||||||
{
|
{
|
||||||
if (!wText) return;
|
if (!wText) return;
|
||||||
|
|
||||||
TextLines.clear();
|
TextLines.clear();
|
||||||
|
|
||||||
TextLine TmpLine;
|
TextLine TmpLine;
|
||||||
TmpLine.CharCount = 0;
|
TmpLine.CharCount = 0;
|
||||||
TmpLine.LineOffset = 0;
|
TmpLine.LineOffset = 0;
|
||||||
TmpLine.width = 0;
|
TmpLine.width = 0;
|
||||||
|
|
||||||
const wchar_t * origTxt = wText->c_str();
|
const wchar_t * origTxt = wText->c_str();
|
||||||
int ch = 0;
|
int ch = 0;
|
||||||
int lastSpace = -1;
|
int lastSpace = -1;
|
||||||
int currWidth = 0;
|
int currWidth = 0;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
||||||
while (origTxt[ch])
|
while (origTxt[ch])
|
||||||
{
|
{
|
||||||
currWidth += fontSystem->getCharWidth(origTxt[ch], currentSize, ch > 0 ? origTxt[ch - 1] : 0x0000);
|
currWidth += fontSystem->getCharWidth(origTxt[ch], currentSize, ch > 0 ? origTxt[ch - 1] : 0x0000);
|
||||||
|
|
||||||
if (currWidth >= maxWidth)
|
if (currWidth >= maxWidth)
|
||||||
{
|
{
|
||||||
if (lastSpace > 0)
|
if (lastSpace > 0)
|
||||||
{
|
{
|
||||||
ch = lastSpace;
|
ch = lastSpace;
|
||||||
}
|
}
|
||||||
TmpLine.CharCount = ch - TmpLine.LineOffset;
|
TmpLine.CharCount = ch - TmpLine.LineOffset;
|
||||||
TmpLine.width = currWidth;
|
TmpLine.width = currWidth;
|
||||||
TextLines.push_back(TmpLine);
|
TextLines.push_back(TmpLine);
|
||||||
currWidth = 0;
|
currWidth = 0;
|
||||||
lastSpace = -1;
|
lastSpace = -1;
|
||||||
i = -1;
|
i = -1;
|
||||||
TmpLine.LineOffset = ch + 1;
|
TmpLine.LineOffset = ch + 1;
|
||||||
}
|
}
|
||||||
else if (origTxt[ch] == '\n')
|
else if (origTxt[ch] == '\n')
|
||||||
{
|
{
|
||||||
TmpLine.CharCount = ch - TmpLine.LineOffset;
|
TmpLine.CharCount = ch - TmpLine.LineOffset;
|
||||||
TmpLine.width = currWidth;
|
TmpLine.width = currWidth;
|
||||||
TextLines.push_back(TmpLine);
|
TextLines.push_back(TmpLine);
|
||||||
currWidth = 0;
|
currWidth = 0;
|
||||||
lastSpace = -1;
|
lastSpace = -1;
|
||||||
i = -1;
|
i = -1;
|
||||||
TmpLine.LineOffset = ch + 1;
|
TmpLine.LineOffset = ch + 1;
|
||||||
}
|
}
|
||||||
else if (origTxt[ch] == ' ')
|
else if (origTxt[ch] == ' ')
|
||||||
{
|
{
|
||||||
lastSpace = ch;
|
lastSpace = ch;
|
||||||
}
|
}
|
||||||
|
|
||||||
ch++;
|
ch++;
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
TmpLine.CharCount = ch - TmpLine.LineOffset;
|
TmpLine.CharCount = ch - TmpLine.LineOffset;
|
||||||
TmpLine.width = currWidth;
|
TmpLine.width = currWidth;
|
||||||
|
|
||||||
if (TmpLine.CharCount-1 > 0)
|
if (TmpLine.CharCount-1 > 0)
|
||||||
{
|
{
|
||||||
TmpLine.CharCount -= 1;
|
TmpLine.CharCount -= 1;
|
||||||
TextLines.push_back(TmpLine);
|
TextLines.push_back(TmpLine);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Text::Draw()
|
void Text::Draw()
|
||||||
{
|
{
|
||||||
if (textDyn.size() == 0) return;
|
if (textDyn.size() == 0) return;
|
||||||
|
|
||||||
if (!this->IsVisible()) return;
|
if (!this->IsVisible()) return;
|
||||||
|
|
||||||
GXColor c = color;
|
GXColor c = color;
|
||||||
c.a = this->GetAlpha();
|
c.a = this->GetAlpha();
|
||||||
|
|
||||||
int newSize = (int) (size * GetScale());
|
int newSize = (int) (size * GetScale());
|
||||||
|
|
||||||
if (newSize != currentSize)
|
if (newSize != currentSize)
|
||||||
{
|
{
|
||||||
currentSize = LIMIT(newSize, 1, 100);
|
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++)
|
for (u32 i = 0; i < textDyn.size(); i++)
|
||||||
{
|
{
|
||||||
if (!filling) (font ? font : fontSystem)->drawText(this->GetLeft(), this->GetTop() + i * lineheight, 0,
|
if (!filling) (font ? font : fontSystem)->drawText(this->GetLeft(), this->GetTop() + i * lineheight, 0,
|
||||||
textDyn[i], currentSize, c, style, 0, maxWidth);
|
textDyn[i], currentSize, c, style, 0, maxWidth);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,64 +6,64 @@
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
int LineOffset;
|
int LineOffset;
|
||||||
int CharCount;
|
int CharCount;
|
||||||
int width;
|
int width;
|
||||||
} TextLine;
|
} TextLine;
|
||||||
|
|
||||||
class Text: public GuiText
|
class Text: public GuiText
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
//!Constructor
|
//!Constructor
|
||||||
//!\param t Text
|
//!\param t Text
|
||||||
//!\param s Font size
|
//!\param s Font size
|
||||||
//!\param c Font color
|
//!\param c Font color
|
||||||
Text(const char * t, int s, GXColor c);
|
Text(const char * t, int s, GXColor c);
|
||||||
Text(const wchar_t * t, int s, GXColor c);
|
Text(const wchar_t * t, int s, GXColor c);
|
||||||
virtual ~Text();
|
virtual ~Text();
|
||||||
//!Sets the text of the GuiText element
|
//!Sets the text of the GuiText element
|
||||||
//!\param t Text
|
//!\param t Text
|
||||||
void SetText(const char * t);
|
void SetText(const char * t);
|
||||||
void SetText(const wchar_t * t);
|
void SetText(const wchar_t * t);
|
||||||
//!Set the max texwidth
|
//!Set the max texwidth
|
||||||
void SetMaxWidth(int width);
|
void SetMaxWidth(int width);
|
||||||
//!Go to next line
|
//!Go to next line
|
||||||
void NextLine();
|
void NextLine();
|
||||||
//!Go to previous line
|
//!Go to previous line
|
||||||
void PreviousLine();
|
void PreviousLine();
|
||||||
//!Refresh the rows to draw
|
//!Refresh the rows to draw
|
||||||
void Refresh();
|
void Refresh();
|
||||||
//!Set the text line
|
//!Set the text line
|
||||||
void SetTextLine(int line);
|
void SetTextLine(int line);
|
||||||
//!Set to the char pos in text
|
//!Set to the char pos in text
|
||||||
void SetTextPos(int pos);
|
void SetTextPos(int pos);
|
||||||
//!Refresh the rows to draw
|
//!Refresh the rows to draw
|
||||||
int GetCurrPos() { return curLineStart; };
|
int GetCurrPos() { return curLineStart; };
|
||||||
//!Get the count of loaded lines
|
//!Get the count of loaded lines
|
||||||
int GetLinesCount() { return textDyn.size(); };
|
int GetLinesCount() { return textDyn.size(); };
|
||||||
//!Get the total count of lines
|
//!Get the total count of lines
|
||||||
int GetTotalLinesCount() { return TextLines.size(); };
|
int GetTotalLinesCount() { return TextLines.size(); };
|
||||||
//!Get the original full Text
|
//!Get the original full Text
|
||||||
const wchar_t * GetText();
|
const wchar_t * GetText();
|
||||||
//!Get the original full Text as wString
|
//!Get the original full Text as wString
|
||||||
wString * GetwString() { return wText; };
|
wString * GetwString() { return wText; };
|
||||||
//!Get the original Text as a UTF-8 text
|
//!Get the original Text as a UTF-8 text
|
||||||
std::string GetUTF8String() const;
|
std::string GetUTF8String() const;
|
||||||
//!Get a Textline
|
//!Get a Textline
|
||||||
const wchar_t * GetTextLine(int ind);
|
const wchar_t * GetTextLine(int ind);
|
||||||
//!Get the offset in the text of a drawn Line
|
//!Get the offset in the text of a drawn Line
|
||||||
int GetLineOffset(int ind);
|
int GetLineOffset(int ind);
|
||||||
//!Constantly called to draw the text
|
//!Constantly called to draw the text
|
||||||
void Draw();
|
void Draw();
|
||||||
protected:
|
protected:
|
||||||
void CalcLineOffsets();
|
void CalcLineOffsets();
|
||||||
void FillRows();
|
void FillRows();
|
||||||
|
|
||||||
wString * wText;
|
wString * wText;
|
||||||
std::vector<TextLine> TextLines;
|
std::vector<TextLine> TextLines;
|
||||||
int curLineStart;
|
int curLineStart;
|
||||||
int FirstLineOffset;
|
int FirstLineOffset;
|
||||||
bool filling;
|
bool filling;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#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()
|
void GuiBox::Draw()
|
||||||
{
|
{
|
||||||
GX_SetTevOp(GX_TEVSTAGE0, GX_PASSCLR);
|
GX_SetTevOp(GX_TEVSTAGE0, GX_PASSCLR);
|
||||||
GX_SetVtxDesc(GX_VA_POS, GX_DIRECT);
|
GX_SetVtxDesc(GX_VA_POS, GX_DIRECT);
|
||||||
GX_SetVtxDesc(GX_VA_CLR0, GX_DIRECT);
|
GX_SetVtxDesc(GX_VA_CLR0, GX_DIRECT);
|
||||||
GX_SetVtxDesc(GX_VA_TEX0, GX_NONE);
|
GX_SetVtxDesc(GX_VA_TEX0, GX_NONE);
|
||||||
u32 n = filled ? 4 : 5;
|
u32 n = filled ? 4 : 5;
|
||||||
f32 x = GetLeft();
|
f32 x = GetLeft();
|
||||||
f32 y = GetTop();
|
f32 y = GetTop();
|
||||||
f32 x2 = x + width;
|
f32 x2 = x + width;
|
||||||
f32 y2 = y + height;
|
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 } };
|
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);
|
GX_Begin(filled ? GX_TRIANGLEFAN : GX_LINESTRIP, GX_VTXFMT0, n);
|
||||||
for (u32 i = 0; i < n; i++)
|
for (u32 i = 0; i < n; i++)
|
||||||
{
|
{
|
||||||
GX_Position3f32(v[i].x, v[i].y, v[i].z);
|
GX_Position3f32(v[i].x, v[i].y, v[i].z);
|
||||||
GX_Color4u8(color[i].r, color[i].g, color[i].b, alpha);
|
GX_Color4u8(color[i].r, color[i].g, color[i].b, alpha);
|
||||||
}
|
}
|
||||||
GX_End();
|
GX_End();
|
||||||
GX_SetTevOp(GX_TEVSTAGE0, GX_MODULATE);
|
GX_SetTevOp(GX_TEVSTAGE0, GX_MODULATE);
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,20 +28,20 @@
|
||||||
|
|
||||||
class GuiBox : public GuiElement
|
class GuiBox : public GuiElement
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
GuiBox() : filled(true) { SetColor((GXColor) {255, 255, 255, 255}); }
|
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}); }
|
GuiBox(int w, int h) : filled(true) { width = w; height = h; SetColor((GXColor) {255, 255, 255, 255}); }
|
||||||
//! Set one color for the whole square
|
//! Set one color for the whole square
|
||||||
void SetColor(const GXColor c) { LOCK(this); for(int i = 0; i < 4; ++i) color[i] = c; }
|
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
|
//! 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
|
//! 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 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 SetSize(int w, int h) { LOCK(this); width = w; height = h; }
|
||||||
void SetFilled(bool f) { LOCK(this); filled = f; }
|
void SetFilled(bool f) { LOCK(this); filled = f; }
|
||||||
void Draw();
|
void Draw();
|
||||||
protected:
|
protected:
|
||||||
GXColor color[4];
|
GXColor color[4];
|
||||||
bool filled;
|
bool filled;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -18,135 +18,135 @@ static int scrollison = 0;
|
||||||
|
|
||||||
GuiButton::GuiButton(int w, int h)
|
GuiButton::GuiButton(int w, int h)
|
||||||
{
|
{
|
||||||
width = w;
|
width = w;
|
||||||
height = h;
|
height = h;
|
||||||
image = NULL;
|
image = NULL;
|
||||||
imageOver = NULL;
|
imageOver = NULL;
|
||||||
imageHold = NULL;
|
imageHold = NULL;
|
||||||
imageClick = NULL;
|
imageClick = NULL;
|
||||||
icon = NULL;
|
icon = NULL;
|
||||||
iconOver = NULL;
|
iconOver = NULL;
|
||||||
iconHold = NULL;
|
iconHold = NULL;
|
||||||
iconClick = NULL;
|
iconClick = NULL;
|
||||||
toolTip = NULL;
|
toolTip = NULL;
|
||||||
|
|
||||||
for (int i = 0; i < 3; i++)
|
for (int i = 0; i < 3; i++)
|
||||||
{
|
{
|
||||||
label[i] = NULL;
|
label[i] = NULL;
|
||||||
labelOver[i] = NULL;
|
labelOver[i] = NULL;
|
||||||
labelHold[i] = NULL;
|
labelHold[i] = NULL;
|
||||||
labelClick[i] = NULL;
|
labelClick[i] = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
soundOver = NULL;
|
soundOver = NULL;
|
||||||
soundHold = NULL;
|
soundHold = NULL;
|
||||||
soundClick = NULL;
|
soundClick = NULL;
|
||||||
selectable = true;
|
selectable = true;
|
||||||
holdable = false;
|
holdable = false;
|
||||||
clickable = true;
|
clickable = true;
|
||||||
|
|
||||||
time1 = time2 = 0;
|
time1 = time2 = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
GuiButton::GuiButton(GuiImage* img, GuiImage* imgOver, int hor, int vert, int x, int y, GuiTrigger* trig,
|
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;
|
width = img ? img->GetWidth() : 0;
|
||||||
height = img ? img->GetHeight() : 0;
|
height = img ? img->GetHeight() : 0;
|
||||||
image = img;
|
image = img;
|
||||||
if(image) image->SetParent(this);
|
if(image) image->SetParent(this);
|
||||||
imageOver = imgOver;
|
imageOver = imgOver;
|
||||||
if (imageOver) imageOver->SetParent(this);
|
if (imageOver) imageOver->SetParent(this);
|
||||||
imageHold = NULL;
|
imageHold = NULL;
|
||||||
imageClick = NULL;
|
imageClick = NULL;
|
||||||
icon = NULL;
|
icon = NULL;
|
||||||
iconOver = NULL;
|
iconOver = NULL;
|
||||||
iconHold = NULL;
|
iconHold = NULL;
|
||||||
iconClick = NULL;
|
iconClick = NULL;
|
||||||
toolTip = NULL;
|
toolTip = NULL;
|
||||||
alignmentHor = hor;
|
alignmentHor = hor;
|
||||||
alignmentVert = vert;
|
alignmentVert = vert;
|
||||||
xoffset = x;
|
xoffset = x;
|
||||||
yoffset = y;
|
yoffset = y;
|
||||||
trigger[0] = trig;
|
trigger[0] = trig;
|
||||||
|
|
||||||
for (int i = 0; i < 3; i++)
|
for (int i = 0; i < 3; i++)
|
||||||
{
|
{
|
||||||
label[i] = NULL;
|
label[i] = NULL;
|
||||||
labelOver[i] = NULL;
|
labelOver[i] = NULL;
|
||||||
labelHold[i] = NULL;
|
labelHold[i] = NULL;
|
||||||
labelClick[i] = NULL;
|
labelClick[i] = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
soundOver = sndOver;
|
soundOver = sndOver;
|
||||||
soundHold = NULL;
|
soundHold = NULL;
|
||||||
soundClick = sndClick;
|
soundClick = sndClick;
|
||||||
selectable = true;
|
selectable = true;
|
||||||
holdable = false;
|
holdable = false;
|
||||||
clickable = true;
|
clickable = true;
|
||||||
|
|
||||||
if (grow == 1)
|
if (grow == 1)
|
||||||
{
|
{
|
||||||
effectsOver |= EFFECT_SCALE;
|
effectsOver |= EFFECT_SCALE;
|
||||||
effectAmountOver = 4;
|
effectAmountOver = 4;
|
||||||
effectTargetOver = 110;
|
effectTargetOver = 110;
|
||||||
}
|
}
|
||||||
time1 = time2 = 0;
|
time1 = time2 = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
GuiButton::GuiButton(GuiImage* img, GuiImage* imgOver, int hor, int vert, int x, int y, GuiTrigger* trig,
|
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;
|
width = img ? img->GetWidth() : 0;
|
||||||
height = img ? img->GetHeight() : 0;
|
height = img ? img->GetHeight() : 0;
|
||||||
image = img;
|
image = img;
|
||||||
if(image) image->SetParent(this);
|
if(image) image->SetParent(this);
|
||||||
imageOver = imgOver;
|
imageOver = imgOver;
|
||||||
if (imageOver) imageOver->SetParent(this);
|
if (imageOver) imageOver->SetParent(this);
|
||||||
imageHold = NULL;
|
imageHold = NULL;
|
||||||
imageClick = NULL;
|
imageClick = NULL;
|
||||||
icon = NULL;
|
icon = NULL;
|
||||||
iconOver = NULL;
|
iconOver = NULL;
|
||||||
iconHold = NULL;
|
iconHold = NULL;
|
||||||
iconClick = NULL;
|
iconClick = NULL;
|
||||||
toolTip = NULL;
|
toolTip = NULL;
|
||||||
alignmentHor = hor;
|
alignmentHor = hor;
|
||||||
alignmentVert = vert;
|
alignmentVert = vert;
|
||||||
xoffset = x;
|
xoffset = x;
|
||||||
yoffset = y;
|
yoffset = y;
|
||||||
trigger[0] = trig;
|
trigger[0] = trig;
|
||||||
|
|
||||||
for (int i = 0; i < 3; i++)
|
for (int i = 0; i < 3; i++)
|
||||||
{
|
{
|
||||||
label[i] = NULL;
|
label[i] = NULL;
|
||||||
labelOver[i] = NULL;
|
labelOver[i] = NULL;
|
||||||
labelHold[i] = NULL;
|
labelHold[i] = NULL;
|
||||||
labelClick[i] = NULL;
|
labelClick[i] = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
soundOver = sndOver;
|
soundOver = sndOver;
|
||||||
soundHold = NULL;
|
soundHold = NULL;
|
||||||
soundClick = sndClick;
|
soundClick = sndClick;
|
||||||
selectable = true;
|
selectable = true;
|
||||||
holdable = false;
|
holdable = false;
|
||||||
clickable = true;
|
clickable = true;
|
||||||
|
|
||||||
if (grow == 1)
|
if (grow == 1)
|
||||||
{
|
{
|
||||||
effectsOver |= EFFECT_SCALE;
|
effectsOver |= EFFECT_SCALE;
|
||||||
effectAmountOver = 4;
|
effectAmountOver = 4;
|
||||||
effectTargetOver = 110;
|
effectTargetOver = 110;
|
||||||
}
|
}
|
||||||
|
|
||||||
toolTip = tt;
|
toolTip = tt;
|
||||||
if(toolTip)
|
if(toolTip)
|
||||||
{
|
{
|
||||||
toolTip->SetParent(this);
|
toolTip->SetParent(this);
|
||||||
toolTip->SetAlignment(h_align, v_align);
|
toolTip->SetAlignment(h_align, v_align);
|
||||||
toolTip->SetPosition(ttx, tty);
|
toolTip->SetPosition(ttx, tty);
|
||||||
}
|
}
|
||||||
|
|
||||||
time1 = time2 = 0;
|
time1 = time2 = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -158,157 +158,157 @@ GuiButton::~GuiButton()
|
||||||
|
|
||||||
void GuiButton::SetImage(GuiImage* img)
|
void GuiButton::SetImage(GuiImage* img)
|
||||||
{
|
{
|
||||||
LOCK( this );
|
LOCK( this );
|
||||||
image = img;
|
image = img;
|
||||||
if (img) img->SetParent(this);
|
if (img) img->SetParent(this);
|
||||||
}
|
}
|
||||||
void GuiButton::SetImageOver(GuiImage* img)
|
void GuiButton::SetImageOver(GuiImage* img)
|
||||||
{
|
{
|
||||||
LOCK( this );
|
LOCK( this );
|
||||||
imageOver = img;
|
imageOver = img;
|
||||||
if (img) img->SetParent(this);
|
if (img) img->SetParent(this);
|
||||||
}
|
}
|
||||||
void GuiButton::SetImageHold(GuiImage* img)
|
void GuiButton::SetImageHold(GuiImage* img)
|
||||||
{
|
{
|
||||||
LOCK( this );
|
LOCK( this );
|
||||||
imageHold = img;
|
imageHold = img;
|
||||||
if (img) img->SetParent(this);
|
if (img) img->SetParent(this);
|
||||||
}
|
}
|
||||||
void GuiButton::SetImageClick(GuiImage* img)
|
void GuiButton::SetImageClick(GuiImage* img)
|
||||||
{
|
{
|
||||||
LOCK( this );
|
LOCK( this );
|
||||||
imageClick = img;
|
imageClick = img;
|
||||||
if (img) img->SetParent(this);
|
if (img) img->SetParent(this);
|
||||||
}
|
}
|
||||||
void GuiButton::SetIcon(GuiImage* img)
|
void GuiButton::SetIcon(GuiImage* img)
|
||||||
{
|
{
|
||||||
LOCK( this );
|
LOCK( this );
|
||||||
icon = img;
|
icon = img;
|
||||||
if (img) img->SetParent(this);
|
if (img) img->SetParent(this);
|
||||||
}
|
}
|
||||||
void GuiButton::SetIconOver(GuiImage* img)
|
void GuiButton::SetIconOver(GuiImage* img)
|
||||||
{
|
{
|
||||||
LOCK( this );
|
LOCK( this );
|
||||||
iconOver = img;
|
iconOver = img;
|
||||||
if (img) img->SetParent(this);
|
if (img) img->SetParent(this);
|
||||||
}
|
}
|
||||||
void GuiButton::SetIconHold(GuiImage* img)
|
void GuiButton::SetIconHold(GuiImage* img)
|
||||||
{
|
{
|
||||||
LOCK( this );
|
LOCK( this );
|
||||||
iconHold = img;
|
iconHold = img;
|
||||||
if (img) img->SetParent(this);
|
if (img) img->SetParent(this);
|
||||||
}
|
}
|
||||||
void GuiButton::SetIconClick(GuiImage* img)
|
void GuiButton::SetIconClick(GuiImage* img)
|
||||||
{
|
{
|
||||||
LOCK( this );
|
LOCK( this );
|
||||||
iconClick = img;
|
iconClick = img;
|
||||||
if (img) img->SetParent(this);
|
if (img) img->SetParent(this);
|
||||||
}
|
}
|
||||||
void GuiButton::SetLabel(GuiText* txt, int n)
|
void GuiButton::SetLabel(GuiText* txt, int n)
|
||||||
{
|
{
|
||||||
LOCK( this );
|
LOCK( this );
|
||||||
label[n] = txt;
|
label[n] = txt;
|
||||||
if (txt) txt->SetParent(this);
|
if (txt) txt->SetParent(this);
|
||||||
}
|
}
|
||||||
void GuiButton::SetLabelOver(GuiText* txt, int n)
|
void GuiButton::SetLabelOver(GuiText* txt, int n)
|
||||||
{
|
{
|
||||||
LOCK( this );
|
LOCK( this );
|
||||||
labelOver[n] = txt;
|
labelOver[n] = txt;
|
||||||
if (txt) txt->SetParent(this);
|
if (txt) txt->SetParent(this);
|
||||||
}
|
}
|
||||||
void GuiButton::SetLabelHold(GuiText* txt, int n)
|
void GuiButton::SetLabelHold(GuiText* txt, int n)
|
||||||
{
|
{
|
||||||
LOCK( this );
|
LOCK( this );
|
||||||
labelHold[n] = txt;
|
labelHold[n] = txt;
|
||||||
if (txt) txt->SetParent(this);
|
if (txt) txt->SetParent(this);
|
||||||
}
|
}
|
||||||
void GuiButton::SetLabelClick(GuiText* txt, int n)
|
void GuiButton::SetLabelClick(GuiText* txt, int n)
|
||||||
{
|
{
|
||||||
LOCK( this );
|
LOCK( this );
|
||||||
labelClick[n] = txt;
|
labelClick[n] = txt;
|
||||||
if (txt) txt->SetParent(this);
|
if (txt) txt->SetParent(this);
|
||||||
}
|
}
|
||||||
void GuiButton::SetSoundOver(GuiSound * snd)
|
void GuiButton::SetSoundOver(GuiSound * snd)
|
||||||
{
|
{
|
||||||
LOCK( this );
|
LOCK( this );
|
||||||
soundOver = snd;
|
soundOver = snd;
|
||||||
}
|
}
|
||||||
void GuiButton::SetSoundHold(GuiSound * snd)
|
void GuiButton::SetSoundHold(GuiSound * snd)
|
||||||
{
|
{
|
||||||
LOCK( this );
|
LOCK( this );
|
||||||
soundHold = snd;
|
soundHold = snd;
|
||||||
}
|
}
|
||||||
void GuiButton::SetSoundClick(GuiSound * snd)
|
void GuiButton::SetSoundClick(GuiSound * snd)
|
||||||
{
|
{
|
||||||
LOCK( this );
|
LOCK( this );
|
||||||
soundClick = snd;
|
soundClick = snd;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuiButton::SetToolTip(GuiTooltip* tt, int x, int y, int h_align, int v_align)
|
void GuiButton::SetToolTip(GuiTooltip* tt, int x, int y, int h_align, int v_align)
|
||||||
{
|
{
|
||||||
LOCK( this );
|
LOCK( this );
|
||||||
if (tt)
|
if (tt)
|
||||||
{
|
{
|
||||||
toolTip = tt;
|
toolTip = tt;
|
||||||
toolTip->SetParent(this);
|
toolTip->SetParent(this);
|
||||||
toolTip->SetAlignment(h_align, v_align);
|
toolTip->SetAlignment(h_align, v_align);
|
||||||
toolTip->SetPosition(x, y);
|
toolTip->SetPosition(x, y);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuiButton::RemoveToolTip()
|
void GuiButton::RemoveToolTip()
|
||||||
{
|
{
|
||||||
LOCK( this );
|
LOCK( this );
|
||||||
toolTip = NULL;
|
toolTip = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuiButton::RemoveSoundOver()
|
void GuiButton::RemoveSoundOver()
|
||||||
{
|
{
|
||||||
LOCK( this );
|
LOCK( this );
|
||||||
soundOver = NULL;
|
soundOver = NULL;
|
||||||
}
|
}
|
||||||
void GuiButton::RemoveSoundClick()
|
void GuiButton::RemoveSoundClick()
|
||||||
{
|
{
|
||||||
LOCK( this );
|
LOCK( this );
|
||||||
soundClick = NULL;
|
soundClick = NULL;
|
||||||
}
|
}
|
||||||
void GuiButton::SetSkew(int XX1, int YY1, int XX2, int YY2, int XX3, int YY3, int XX4, int YY4)
|
void GuiButton::SetSkew(int XX1, int YY1, int XX2, int YY2, int XX3, int YY3, int XX4, int YY4)
|
||||||
{
|
{
|
||||||
if (image)
|
if (image)
|
||||||
{
|
{
|
||||||
image->xx1 = XX1;
|
image->xx1 = XX1;
|
||||||
image->yy1 = YY1;
|
image->yy1 = YY1;
|
||||||
image->xx2 = XX2;
|
image->xx2 = XX2;
|
||||||
image->yy2 = YY2;
|
image->yy2 = YY2;
|
||||||
image->xx3 = XX3;
|
image->xx3 = XX3;
|
||||||
image->yy3 = YY3;
|
image->yy3 = YY3;
|
||||||
image->xx4 = XX4;
|
image->xx4 = XX4;
|
||||||
image->yy4 = YY4;
|
image->yy4 = YY4;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuiButton::SetSkew(int *skew)
|
void GuiButton::SetSkew(int *skew)
|
||||||
{
|
{
|
||||||
if (image) image->SetSkew(skew);
|
if (image) image->SetSkew(skew);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuiButton::SetState(int s, int c)
|
void GuiButton::SetState(int s, int c)
|
||||||
{
|
{
|
||||||
GuiElement::SetState(s, c);
|
GuiElement::SetState(s, c);
|
||||||
|
|
||||||
if(c < 0 || c > 3)
|
if(c < 0 || c > 3)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (s == STATE_CLICKED)
|
if (s == STATE_CLICKED)
|
||||||
{
|
{
|
||||||
POINT p = {0, 0};
|
POINT p = {0, 0};
|
||||||
|
|
||||||
if (userInput[c].wpad.ir.valid)
|
if (userInput[c].wpad.ir.valid)
|
||||||
{
|
{
|
||||||
p.x = userInput[c].wpad.ir.x;
|
p.x = userInput[c].wpad.ir.x;
|
||||||
p.y = userInput[c].wpad.ir.y;
|
p.y = userInput[c].wpad.ir.y;
|
||||||
}
|
}
|
||||||
Clicked(this, c, p);
|
Clicked(this, c, p);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -318,225 +318,225 @@ void GuiButton::SetState(int s, int c)
|
||||||
*/
|
*/
|
||||||
void GuiButton::Draw()
|
void GuiButton::Draw()
|
||||||
{
|
{
|
||||||
LOCK( this );
|
LOCK( this );
|
||||||
if (!this->IsVisible()) return;
|
if (!this->IsVisible()) return;
|
||||||
|
|
||||||
// draw image
|
// draw image
|
||||||
if ((state == STATE_SELECTED || state == STATE_HELD) && imageOver)
|
if ((state == STATE_SELECTED || state == STATE_HELD) && imageOver)
|
||||||
imageOver->Draw();
|
imageOver->Draw();
|
||||||
else if (image) image->Draw();
|
else if (image) image->Draw();
|
||||||
// draw icon
|
// draw icon
|
||||||
if ((state == STATE_SELECTED || state == STATE_HELD) && iconOver)
|
if ((state == STATE_SELECTED || state == STATE_HELD) && iconOver)
|
||||||
iconOver->Draw();
|
iconOver->Draw();
|
||||||
else if (icon) icon->Draw();
|
else if (icon) icon->Draw();
|
||||||
// draw text
|
// draw text
|
||||||
for (int i = 0; i < 3; i++)
|
for (int i = 0; i < 3; i++)
|
||||||
{
|
{
|
||||||
if ((state == STATE_SELECTED || state == STATE_HELD) && labelOver[i])
|
if ((state == STATE_SELECTED || state == STATE_HELD) && labelOver[i])
|
||||||
labelOver[i]->Draw();
|
labelOver[i]->Draw();
|
||||||
else if (label[i]) label[i]->Draw();
|
else if (label[i]) label[i]->Draw();
|
||||||
}
|
}
|
||||||
|
|
||||||
this->UpdateEffects();
|
this->UpdateEffects();
|
||||||
}
|
}
|
||||||
void GuiButton::DrawTooltip()
|
void GuiButton::DrawTooltip()
|
||||||
{
|
{
|
||||||
LOCK( this );
|
LOCK( this );
|
||||||
if (this->IsVisible() && state == STATE_SELECTED && toolTip)
|
if (this->IsVisible() && state == STATE_SELECTED && toolTip)
|
||||||
{
|
{
|
||||||
if (time2 == 0)
|
if (time2 == 0)
|
||||||
{
|
{
|
||||||
time(&time1);
|
time(&time1);
|
||||||
time2 = time1;
|
time2 = time1;
|
||||||
}
|
}
|
||||||
if (time1 != 0) // timer läuft
|
if (time1 != 0) // timer läuft
|
||||||
time(&time1);
|
time(&time1);
|
||||||
|
|
||||||
if (time1 == 0 || difftime(time1, time2) >= 2)
|
if (time1 == 0 || difftime(time1, time2) >= 2)
|
||||||
{
|
{
|
||||||
if (time1 != 0) // timer gerade abgelaufen
|
if (time1 != 0) // timer gerade abgelaufen
|
||||||
toolTip->SetEffect(EFFECT_FADE, 20);
|
toolTip->SetEffect(EFFECT_FADE, 20);
|
||||||
time1 = 0;
|
time1 = 0;
|
||||||
toolTip->Draw();
|
toolTip->Draw();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (time2 != 0 && time1 == 0) // timer abgelaufen, gerade DESELECT
|
if (time2 != 0 && time1 == 0) // timer abgelaufen, gerade DESELECT
|
||||||
if (toolTip) toolTip->SetEffect(EFFECT_FADE, -20);
|
if (toolTip) toolTip->SetEffect(EFFECT_FADE, -20);
|
||||||
time2 = 0;
|
time2 = 0;
|
||||||
}
|
}
|
||||||
if (toolTip && toolTip->GetEffect()) toolTip->Draw();
|
if (toolTip && toolTip->GetEffect()) toolTip->Draw();
|
||||||
}
|
}
|
||||||
void GuiButton::ScrollIsOn(int f)
|
void GuiButton::ScrollIsOn(int f)
|
||||||
{
|
{
|
||||||
scrollison = f;
|
scrollison = f;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuiButton::Update(GuiTrigger * t)
|
void GuiButton::Update(GuiTrigger * t)
|
||||||
{
|
{
|
||||||
LOCK( this );
|
LOCK( this );
|
||||||
if (!this->IsVisible() || state == STATE_CLICKED || state == STATE_DISABLED || !t)
|
if (!this->IsVisible() || state == STATE_CLICKED || state == STATE_DISABLED || !t)
|
||||||
return;
|
return;
|
||||||
else if (parentElement && parentElement->GetState() == STATE_DISABLED) return;
|
else if (parentElement && parentElement->GetState() == STATE_DISABLED) return;
|
||||||
|
|
||||||
#ifdef HW_RVL
|
#ifdef HW_RVL
|
||||||
// cursor
|
// cursor
|
||||||
if ( t->wpad.ir.valid )
|
if ( t->wpad.ir.valid )
|
||||||
{
|
{
|
||||||
if ( this->IsInside( t->wpad.ir.x, t->wpad.ir.y ) )
|
if ( this->IsInside( t->wpad.ir.x, t->wpad.ir.y ) )
|
||||||
{
|
{
|
||||||
if ( state == STATE_DEFAULT ) // we weren't on the button before!
|
if ( state == STATE_DEFAULT ) // we weren't on the button before!
|
||||||
|
|
||||||
{
|
{
|
||||||
if ( scrollison == 0 )
|
if ( scrollison == 0 )
|
||||||
{
|
{
|
||||||
this->SetState( STATE_SELECTED, t->chan );
|
this->SetState( STATE_SELECTED, t->chan );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( this->Rumble() && scrollison == 0 )
|
if ( this->Rumble() && scrollison == 0 )
|
||||||
rumbleRequest[t->chan] = 1;
|
rumbleRequest[t->chan] = 1;
|
||||||
|
|
||||||
if ( soundOver && scrollison == 0 )
|
if ( soundOver && scrollison == 0 )
|
||||||
soundOver->Play();
|
soundOver->Play();
|
||||||
|
|
||||||
if ( effectsOver && !effects && scrollison == 0 )
|
if ( effectsOver && !effects && scrollison == 0 )
|
||||||
{
|
{
|
||||||
// initiate effects
|
// initiate effects
|
||||||
effects = effectsOver;
|
effects = effectsOver;
|
||||||
effectAmount = effectAmountOver;
|
effectAmount = effectAmountOver;
|
||||||
effectTarget = effectTargetOver;
|
effectTarget = effectTargetOver;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if ( state == STATE_SELECTED && ( stateChan == t->chan || stateChan == -1 ) )
|
if ( state == STATE_SELECTED && ( stateChan == t->chan || stateChan == -1 ) )
|
||||||
this->ResetState();
|
this->ResetState();
|
||||||
|
|
||||||
if ( effectTarget == effectTargetOver && effectAmount == effectAmountOver )
|
if ( effectTarget == effectTargetOver && effectAmount == effectAmountOver )
|
||||||
{
|
{
|
||||||
// initiate effects (in reverse)
|
// initiate effects (in reverse)
|
||||||
effects = effectsOver;
|
effects = effectsOver;
|
||||||
effectAmount = -effectAmountOver;
|
effectAmount = -effectAmountOver;
|
||||||
effectTarget = 100;
|
effectTarget = 100;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#else
|
#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)
|
if (effectTarget == effectTargetOver && effectAmount == effectAmountOver)
|
||||||
{
|
{
|
||||||
// initiate effects (in reverse)
|
// initiate effects (in reverse)
|
||||||
effects = effectsOver;
|
effects = effectsOver;
|
||||||
effectAmount = -effectAmountOver;
|
effectAmount = -effectAmountOver;
|
||||||
effectTarget = 100;
|
effectTarget = 100;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// button triggers
|
// button triggers
|
||||||
if (this->IsClickable() && scrollison == 0)
|
if (this->IsClickable() && scrollison == 0)
|
||||||
{
|
{
|
||||||
s32 wm_btns, wm_btns_trig, cc_btns, cc_btns_trig;
|
s32 wm_btns, wm_btns_trig, cc_btns, cc_btns_trig;
|
||||||
for (int i = 0; i < 6; i++)
|
for (int i = 0; i < 6; i++)
|
||||||
{
|
{
|
||||||
if (trigger[i] && (trigger[i]->chan == -1 || trigger[i]->chan == t->chan))
|
if (trigger[i] && (trigger[i]->chan == -1 || trigger[i]->chan == t->chan))
|
||||||
{
|
{
|
||||||
// higher 16 bits only (wiimote)
|
// higher 16 bits only (wiimote)
|
||||||
wm_btns = t->wpad.btns_d << 16;
|
wm_btns = t->wpad.btns_d << 16;
|
||||||
wm_btns_trig = trigger[i]->wpad.btns_d << 16;
|
wm_btns_trig = trigger[i]->wpad.btns_d << 16;
|
||||||
|
|
||||||
// lower 16 bits only (classic controller)
|
// lower 16 bits only (classic controller)
|
||||||
cc_btns = t->wpad.btns_d >> 16;
|
cc_btns = t->wpad.btns_d >> 16;
|
||||||
cc_btns_trig = trigger[i]->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
|
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))
|
== EXP_CLASSIC)) || (t->pad.btns_d == trigger[i]->pad.btns_d && t->pad.btns_d > 0))
|
||||||
{
|
{
|
||||||
if (t->chan == stateChan || stateChan == -1)
|
if (t->chan == stateChan || stateChan == -1)
|
||||||
{
|
{
|
||||||
if (state == STATE_SELECTED)
|
if (state == STATE_SELECTED)
|
||||||
{
|
{
|
||||||
this->SetState(STATE_CLICKED, t->chan);
|
this->SetState(STATE_CLICKED, t->chan);
|
||||||
|
|
||||||
if (soundClick) soundClick->Play();
|
if (soundClick) soundClick->Play();
|
||||||
}
|
}
|
||||||
else if (trigger[i]->type == TRIGGER_BUTTON_ONLY)
|
else if (trigger[i]->type == TRIGGER_BUTTON_ONLY)
|
||||||
{
|
{
|
||||||
this->SetState(STATE_CLICKED, t->chan);
|
this->SetState(STATE_CLICKED, t->chan);
|
||||||
if (soundClick) soundClick->Play();
|
if (soundClick) soundClick->Play();
|
||||||
}
|
}
|
||||||
else if (trigger[i]->type == TRIGGER_BUTTON_ONLY_IN_FOCUS && parentElement->IsFocused())
|
else if (trigger[i]->type == TRIGGER_BUTTON_ONLY_IN_FOCUS && parentElement->IsFocused())
|
||||||
{
|
{
|
||||||
this->SetState(STATE_CLICKED, t->chan);
|
this->SetState(STATE_CLICKED, t->chan);
|
||||||
if (soundClick) soundClick->Play();
|
if (soundClick) soundClick->Play();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this->IsHoldable())
|
if (this->IsHoldable())
|
||||||
{
|
{
|
||||||
bool held = false;
|
bool held = false;
|
||||||
s32 wm_btns, wm_btns_h, wm_btns_trig, cc_btns, cc_btns_h, cc_btns_trig;
|
s32 wm_btns, wm_btns_h, wm_btns_trig, cc_btns, cc_btns_h, cc_btns_trig;
|
||||||
|
|
||||||
for (int i = 0; i < 6; i++)
|
for (int i = 0; i < 6; i++)
|
||||||
{
|
{
|
||||||
if (trigger[i] && (trigger[i]->chan == -1 || trigger[i]->chan == t->chan))
|
if (trigger[i] && (trigger[i]->chan == -1 || trigger[i]->chan == t->chan))
|
||||||
{
|
{
|
||||||
// higher 16 bits only (wiimote)
|
// higher 16 bits only (wiimote)
|
||||||
wm_btns = t->wpad.btns_d << 16;
|
wm_btns = t->wpad.btns_d << 16;
|
||||||
wm_btns_h = t->wpad.btns_h << 16;
|
wm_btns_h = t->wpad.btns_h << 16;
|
||||||
wm_btns_trig = trigger[i]->wpad.btns_h << 16;
|
wm_btns_trig = trigger[i]->wpad.btns_h << 16;
|
||||||
|
|
||||||
// lower 16 bits only (classic controller)
|
// lower 16 bits only (classic controller)
|
||||||
cc_btns = t->wpad.btns_d >> 16;
|
cc_btns = t->wpad.btns_d >> 16;
|
||||||
cc_btns_h = t->wpad.btns_h >> 16;
|
cc_btns_h = t->wpad.btns_h >> 16;
|
||||||
cc_btns_trig = trigger[i]->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
|
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))
|
== 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
|
if (trigger[i]->type == TRIGGER_HELD && state == STATE_SELECTED && (t->chan == stateChan
|
||||||
|| stateChan == -1)) this->SetState(STATE_CLICKED, t->chan);
|
|| 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
|
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->wpad.exp.type == EXP_CLASSIC)) || (t->pad.btns_h == trigger[i]->pad.btns_h
|
||||||
&& t->pad.btns_h > 0))
|
&& t->pad.btns_h > 0))
|
||||||
{
|
{
|
||||||
if (trigger[i]->type == TRIGGER_HELD) held = true;
|
if (trigger[i]->type == TRIGGER_HELD) held = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!held && state == STATE_HELD && stateChan == t->chan)
|
if (!held && state == STATE_HELD && stateChan == t->chan)
|
||||||
{
|
{
|
||||||
this->ResetState();
|
this->ResetState();
|
||||||
}
|
}
|
||||||
else if (held && state == STATE_CLICKED && stateChan == t->chan)
|
else if (held && state == STATE_CLICKED && stateChan == t->chan)
|
||||||
{
|
{
|
||||||
this->SetState(STATE_HELD, t->chan);
|
this->SetState(STATE_HELD, t->chan);
|
||||||
}
|
}
|
||||||
else if (held && state == STATE_HELD && Held.connected())
|
else if (held && state == STATE_HELD && Held.connected())
|
||||||
{
|
{
|
||||||
POINT p = {0, 0};
|
POINT p = {0, 0};
|
||||||
|
|
||||||
if (userInput[t->chan].wpad.ir.valid)
|
if (userInput[t->chan].wpad.ir.valid)
|
||||||
{
|
{
|
||||||
p.x = userInput[t->chan].wpad.ir.x;
|
p.x = userInput[t->chan].wpad.ir.x;
|
||||||
p.y = userInput[t->chan].wpad.ir.y;
|
p.y = userInput[t->chan].wpad.ir.y;
|
||||||
}
|
}
|
||||||
Held(this, t->chan, p);
|
Held(this, t->chan, p);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (updateCB) updateCB(this);
|
if (updateCB) updateCB(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,115 +26,115 @@
|
||||||
#define WHITEBOX_RED_SIZE 4
|
#define WHITEBOX_RED_SIZE 4
|
||||||
|
|
||||||
GuiCheckbox::GuiCheckbox(int s)
|
GuiCheckbox::GuiCheckbox(int s)
|
||||||
: GuiButton(30, 30), Checked(false)
|
: GuiButton(30, 30), Checked(false)
|
||||||
{
|
{
|
||||||
style = s;
|
style = s;
|
||||||
Checksign.SetParent(this);
|
Checksign.SetParent(this);
|
||||||
Cross.SetParent(this);
|
Cross.SetParent(this);
|
||||||
Blackbox.SetParent(this);
|
Blackbox.SetParent(this);
|
||||||
Whitebox.SetParent(this);
|
Whitebox.SetParent(this);
|
||||||
Checksign.SetColor((GXColor) {0, 0, 0, 255});
|
Checksign.SetColor((GXColor) {0, 0, 0, 255});
|
||||||
Cross.SetColor((GXColor) {0, 0, 0, 255});
|
Cross.SetColor((GXColor) {0, 0, 0, 255});
|
||||||
Blackbox.SetColor((GXColor) {0, 0, 0, 255});
|
Blackbox.SetColor((GXColor) {0, 0, 0, 255});
|
||||||
Whitebox.SetColor((GXColor) {255, 255, 255, 255});
|
Whitebox.SetColor((GXColor) {255, 255, 255, 255});
|
||||||
|
|
||||||
SetSize(30, 30);
|
SetSize(30, 30);
|
||||||
}
|
}
|
||||||
|
|
||||||
GuiCheckbox::GuiCheckbox(int w, int h, int s)
|
GuiCheckbox::GuiCheckbox(int w, int h, int s)
|
||||||
: GuiButton(w, h), Checked(false)
|
: GuiButton(w, h), Checked(false)
|
||||||
{
|
{
|
||||||
style = s;
|
style = s;
|
||||||
Checksign.SetParent(this);
|
Checksign.SetParent(this);
|
||||||
Cross.SetParent(this);
|
Cross.SetParent(this);
|
||||||
Blackbox.SetParent(this);
|
Blackbox.SetParent(this);
|
||||||
Whitebox.SetParent(this);
|
Whitebox.SetParent(this);
|
||||||
Checksign.SetColor((GXColor) {0, 0, 0, 255});
|
Checksign.SetColor((GXColor) {0, 0, 0, 255});
|
||||||
Cross.SetColor((GXColor) {0, 0, 0, 255});
|
Cross.SetColor((GXColor) {0, 0, 0, 255});
|
||||||
Blackbox.SetColor((GXColor) {0, 0, 0, 255});
|
Blackbox.SetColor((GXColor) {0, 0, 0, 255});
|
||||||
Whitebox.SetColor((GXColor) {255, 255, 255, 255});
|
Whitebox.SetColor((GXColor) {255, 255, 255, 255});
|
||||||
|
|
||||||
SetSize(w, h);
|
SetSize(w, h);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuiCheckbox::SetSize(int w, int h)
|
void GuiCheckbox::SetSize(int w, int h)
|
||||||
{
|
{
|
||||||
width = w;
|
width = w;
|
||||||
height = h;
|
height = h;
|
||||||
Checksign.SetSize(w-WHITEBOX_RED_SIZE, h-WHITEBOX_RED_SIZE);
|
Checksign.SetSize(w-WHITEBOX_RED_SIZE, h-WHITEBOX_RED_SIZE);
|
||||||
Checksign.SetPosition(WHITEBOX_RED_SIZE/2, WHITEBOX_RED_SIZE/2);
|
Checksign.SetPosition(WHITEBOX_RED_SIZE/2, WHITEBOX_RED_SIZE/2);
|
||||||
Cross.SetSize(w-WHITEBOX_RED_SIZE, h-WHITEBOX_RED_SIZE);
|
Cross.SetSize(w-WHITEBOX_RED_SIZE, h-WHITEBOX_RED_SIZE);
|
||||||
Cross.SetPosition(WHITEBOX_RED_SIZE/2, WHITEBOX_RED_SIZE/2);
|
Cross.SetPosition(WHITEBOX_RED_SIZE/2, WHITEBOX_RED_SIZE/2);
|
||||||
Blackbox.SetSize(w, h);
|
Blackbox.SetSize(w, h);
|
||||||
Whitebox.SetSize(w-WHITEBOX_RED_SIZE, h-WHITEBOX_RED_SIZE);
|
Whitebox.SetSize(w-WHITEBOX_RED_SIZE, h-WHITEBOX_RED_SIZE);
|
||||||
Whitebox.SetPosition(WHITEBOX_RED_SIZE/2, WHITEBOX_RED_SIZE/2);
|
Whitebox.SetPosition(WHITEBOX_RED_SIZE/2, WHITEBOX_RED_SIZE/2);
|
||||||
SetAlignment(alignmentHor, alignmentVert);
|
SetAlignment(alignmentHor, alignmentVert);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuiCheckbox::SetClickSize(int w, int h)
|
void GuiCheckbox::SetClickSize(int w, int h)
|
||||||
{
|
{
|
||||||
width = w;
|
width = w;
|
||||||
height = h;
|
height = h;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuiCheckbox::SetTransparent(bool b)
|
void GuiCheckbox::SetTransparent(bool b)
|
||||||
{
|
{
|
||||||
Blackbox.SetFilled(b);
|
Blackbox.SetFilled(b);
|
||||||
Whitebox.SetFilled(b);
|
Whitebox.SetFilled(b);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuiCheckbox::SetState(int s, int c)
|
void GuiCheckbox::SetState(int s, int c)
|
||||||
{
|
{
|
||||||
if(s == STATE_CLICKED)
|
if(s == STATE_CLICKED)
|
||||||
Checked = !Checked;
|
Checked = !Checked;
|
||||||
|
|
||||||
GuiButton::SetState(s, c);
|
GuiButton::SetState(s, c);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuiCheckbox::SetAlignment(int h, int v)
|
void GuiCheckbox::SetAlignment(int h, int v)
|
||||||
{
|
{
|
||||||
GuiButton::SetAlignment(h, v);
|
GuiButton::SetAlignment(h, v);
|
||||||
Checksign.SetAlignment(h, v);
|
Checksign.SetAlignment(h, v);
|
||||||
Cross.SetAlignment(h, v);
|
Cross.SetAlignment(h, v);
|
||||||
Blackbox.SetAlignment(h, v);
|
Blackbox.SetAlignment(h, v);
|
||||||
Whitebox.SetAlignment(h, v);
|
Whitebox.SetAlignment(h, v);
|
||||||
|
|
||||||
if(h == ALIGN_RIGHT)
|
if(h == ALIGN_RIGHT)
|
||||||
{
|
{
|
||||||
Checksign.SetPosition(-WHITEBOX_RED_SIZE/2, Checksign.GetTopPos());
|
Checksign.SetPosition(-WHITEBOX_RED_SIZE/2, Checksign.GetTopPos());
|
||||||
Cross.SetPosition(-WHITEBOX_RED_SIZE/2, Cross.GetTopPos());
|
Cross.SetPosition(-WHITEBOX_RED_SIZE/2, Cross.GetTopPos());
|
||||||
Whitebox.SetPosition(-WHITEBOX_RED_SIZE/2, Whitebox.GetTopPos());
|
Whitebox.SetPosition(-WHITEBOX_RED_SIZE/2, Whitebox.GetTopPos());
|
||||||
}
|
}
|
||||||
else if(h == ALIGN_CENTER)
|
else if(h == ALIGN_CENTER)
|
||||||
{
|
{
|
||||||
Checksign.SetPosition(0, Checksign.GetTopPos());
|
Checksign.SetPosition(0, Checksign.GetTopPos());
|
||||||
Cross.SetPosition(0, Cross.GetTopPos());
|
Cross.SetPosition(0, Cross.GetTopPos());
|
||||||
Whitebox.SetPosition(0, Whitebox.GetTopPos());
|
Whitebox.SetPosition(0, Whitebox.GetTopPos());
|
||||||
}
|
}
|
||||||
if(v == ALIGN_BOTTOM)
|
if(v == ALIGN_BOTTOM)
|
||||||
{
|
{
|
||||||
Checksign.SetPosition(Checksign.GetLeftPos(), -WHITEBOX_RED_SIZE/2);
|
Checksign.SetPosition(Checksign.GetLeftPos(), -WHITEBOX_RED_SIZE/2);
|
||||||
Cross.SetPosition(Cross.GetLeftPos(), -WHITEBOX_RED_SIZE/2);
|
Cross.SetPosition(Cross.GetLeftPos(), -WHITEBOX_RED_SIZE/2);
|
||||||
Whitebox.SetPosition(Whitebox.GetLeftPos(), -WHITEBOX_RED_SIZE/2);
|
Whitebox.SetPosition(Whitebox.GetLeftPos(), -WHITEBOX_RED_SIZE/2);
|
||||||
}
|
}
|
||||||
else if(v == ALIGN_MIDDLE)
|
else if(v == ALIGN_MIDDLE)
|
||||||
{
|
{
|
||||||
Checksign.SetPosition(Checksign.GetLeftPos(), 0);
|
Checksign.SetPosition(Checksign.GetLeftPos(), 0);
|
||||||
Cross.SetPosition(Cross.GetLeftPos(), 0);
|
Cross.SetPosition(Cross.GetLeftPos(), 0);
|
||||||
Whitebox.SetPosition(Whitebox.GetLeftPos(), 0);
|
Whitebox.SetPosition(Whitebox.GetLeftPos(), 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuiCheckbox::Draw()
|
void GuiCheckbox::Draw()
|
||||||
{
|
{
|
||||||
GuiButton::Draw();
|
GuiButton::Draw();
|
||||||
Blackbox.Draw();
|
Blackbox.Draw();
|
||||||
Whitebox.Draw();
|
Whitebox.Draw();
|
||||||
if(Checked)
|
if(Checked)
|
||||||
{
|
{
|
||||||
if(style == CHECKSIGN)
|
if(style == CHECKSIGN)
|
||||||
Checksign.Draw();
|
Checksign.Draw();
|
||||||
else
|
else
|
||||||
Cross.Draw();
|
Cross.Draw();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,29 +31,29 @@
|
||||||
|
|
||||||
class GuiCheckbox : public GuiButton
|
class GuiCheckbox : public GuiButton
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
GuiCheckbox(int style = CHECKSIGN);
|
GuiCheckbox(int style = CHECKSIGN);
|
||||||
GuiCheckbox(int w, int h, int style = CHECKSIGN);
|
GuiCheckbox(int w, int h, int style = CHECKSIGN);
|
||||||
void SetTransparent(bool b);
|
void SetTransparent(bool b);
|
||||||
void SetSize(int w, int h);
|
void SetSize(int w, int h);
|
||||||
void SetClickSize(int w, int h);
|
void SetClickSize(int w, int h);
|
||||||
void SetAlignment(int h, int v);
|
void SetAlignment(int h, int v);
|
||||||
void SetChecked(bool c) { LOCK(this); Checked = c; }
|
void SetChecked(bool c) { LOCK(this); Checked = c; }
|
||||||
bool IsChecked() const { return Checked; }
|
bool IsChecked() const { return Checked; }
|
||||||
virtual void SetState(int s, int c = -1);
|
virtual void SetState(int s, int c = -1);
|
||||||
virtual void Draw();
|
virtual void Draw();
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
CHECKSIGN,
|
CHECKSIGN,
|
||||||
CROSS,
|
CROSS,
|
||||||
};
|
};
|
||||||
protected:
|
protected:
|
||||||
GuiChecksign Checksign;
|
GuiChecksign Checksign;
|
||||||
GuiCross Cross;
|
GuiCross Cross;
|
||||||
GuiBox Blackbox;
|
GuiBox Blackbox;
|
||||||
GuiBox Whitebox;
|
GuiBox Whitebox;
|
||||||
int style;
|
int style;
|
||||||
bool Checked;
|
bool Checked;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -28,104 +28,104 @@
|
||||||
|
|
||||||
|
|
||||||
GuiCheckboxBrowser::GuiCheckboxBrowser(int w, int h, int s)
|
GuiCheckboxBrowser::GuiCheckboxBrowser(int w, int h, int s)
|
||||||
: scrollBar(h-10)
|
: scrollBar(h-10)
|
||||||
{
|
{
|
||||||
width = w;
|
width = w;
|
||||||
height = h;
|
height = h;
|
||||||
backgroundImg = NULL;
|
backgroundImg = NULL;
|
||||||
selectedItem = 0;
|
selectedItem = 0;
|
||||||
pageIndex = 0;
|
pageIndex = 0;
|
||||||
pressedChan = -1;
|
pressedChan = -1;
|
||||||
maxSize = s;
|
maxSize = s;
|
||||||
scrollBar.SetParent(this);
|
scrollBar.SetParent(this);
|
||||||
scrollBar.SetAlignment(thAlign("right - checkbox browser scrollbar align hor"), thAlign("top - checkbox browser scrollbar align ver"));
|
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.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.SetButtonScroll(WPAD_BUTTON_B | WPAD_CLASSIC_BUTTON_B);
|
||||||
scrollBar.listChanged.connect(this, &GuiCheckboxBrowser::onListChange);
|
scrollBar.listChanged.connect(this, &GuiCheckboxBrowser::onListChange);
|
||||||
trigA.SetSimpleTrigger(-1, WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A, PAD_BUTTON_A);
|
trigA.SetSimpleTrigger(-1, WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A, PAD_BUTTON_A);
|
||||||
markImgData = Resources::GetImageData("checkBoxSelection.png");
|
markImgData = Resources::GetImageData("checkBoxSelection.png");
|
||||||
markImg = new GuiImage(markImgData);
|
markImg = new GuiImage(markImgData);
|
||||||
markImg->SetParent(this);
|
markImg->SetParent(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
GuiCheckboxBrowser::~GuiCheckboxBrowser()
|
GuiCheckboxBrowser::~GuiCheckboxBrowser()
|
||||||
{
|
{
|
||||||
Clear();
|
Clear();
|
||||||
|
|
||||||
delete markImg;
|
delete markImg;
|
||||||
delete markImgData;
|
delete markImgData;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuiCheckboxBrowser::SetImage(GuiImage *Img)
|
void GuiCheckboxBrowser::SetImage(GuiImage *Img)
|
||||||
{
|
{
|
||||||
LOCK(this);
|
LOCK(this);
|
||||||
backgroundImg = Img;
|
backgroundImg = Img;
|
||||||
if(backgroundImg)
|
if(backgroundImg)
|
||||||
backgroundImg->SetParent(this);
|
backgroundImg->SetParent(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuiCheckboxBrowser::Clear()
|
void GuiCheckboxBrowser::Clear()
|
||||||
{
|
{
|
||||||
LOCK(this);
|
LOCK(this);
|
||||||
checkBoxDrawn.clear();
|
checkBoxDrawn.clear();
|
||||||
textLineDrawn.clear();
|
textLineDrawn.clear();
|
||||||
|
|
||||||
for(u32 i = 0; i < checkBoxList.size(); ++i)
|
for(u32 i = 0; i < checkBoxList.size(); ++i)
|
||||||
{
|
{
|
||||||
delete textLineList[i];
|
delete textLineList[i];
|
||||||
delete checkBoxList[i];
|
delete checkBoxList[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
textLineList.clear();
|
textLineList.clear();
|
||||||
checkBoxList.clear();
|
checkBoxList.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GuiCheckboxBrowser::AddEntrie(const string &text, bool checked)
|
bool GuiCheckboxBrowser::AddEntrie(const string &text, bool checked)
|
||||||
{
|
{
|
||||||
LOCK(this);
|
LOCK(this);
|
||||||
int currentSize = checkBoxList.size();
|
int currentSize = checkBoxList.size();
|
||||||
textLineList.resize(currentSize+1);
|
textLineList.resize(currentSize+1);
|
||||||
checkBoxList.resize(currentSize+1);
|
checkBoxList.resize(currentSize+1);
|
||||||
|
|
||||||
checkBoxList[currentSize] = new GuiCheckbox(30, 30);
|
checkBoxList[currentSize] = new GuiCheckbox(30, 30);
|
||||||
checkBoxList[currentSize]->SetParent(this);
|
checkBoxList[currentSize]->SetParent(this);
|
||||||
checkBoxList[currentSize]->SetChecked(checked);
|
checkBoxList[currentSize]->SetChecked(checked);
|
||||||
checkBoxList[currentSize]->SetAlignment(ALIGN_RIGHT, ALIGN_TOP);
|
checkBoxList[currentSize]->SetAlignment(ALIGN_RIGHT, ALIGN_TOP);
|
||||||
checkBoxList[currentSize]->SetTrigger(&trigA);
|
checkBoxList[currentSize]->SetTrigger(&trigA);
|
||||||
checkBoxList[currentSize]->SetClickSize(width-30-scrollBar.GetWidth(), 30);
|
checkBoxList[currentSize]->SetClickSize(width-30-scrollBar.GetWidth(), 30);
|
||||||
checkBoxList[currentSize]->Clicked.connect(this, &GuiCheckboxBrowser::OnCheckboxClick);
|
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] = 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]->SetParent(this);
|
||||||
textLineList[currentSize]->SetAlignment(ALIGN_LEFT, ALIGN_TOP);
|
textLineList[currentSize]->SetAlignment(ALIGN_LEFT, ALIGN_TOP);
|
||||||
|
|
||||||
if(textLineDrawn.size() < (u32) maxSize)
|
if(textLineDrawn.size() < (u32) maxSize)
|
||||||
{
|
{
|
||||||
textLineDrawn.push_back(textLineList[currentSize]);
|
textLineDrawn.push_back(textLineList[currentSize]);
|
||||||
checkBoxDrawn.push_back(checkBoxList[currentSize]);
|
checkBoxDrawn.push_back(checkBoxList[currentSize]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuiCheckboxBrowser::OnCheckboxClick(GuiButton *sender, int chan, const POINT &pointer)
|
void GuiCheckboxBrowser::OnCheckboxClick(GuiButton *sender, int chan, const POINT &pointer)
|
||||||
{
|
{
|
||||||
LOCK(this);
|
LOCK(this);
|
||||||
sender->ResetState();
|
sender->ResetState();
|
||||||
|
|
||||||
for(u32 i = 0; i < checkBoxDrawn.size(); ++i)
|
for(u32 i = 0; i < checkBoxDrawn.size(); ++i)
|
||||||
{
|
{
|
||||||
if(sender == checkBoxDrawn[i])
|
if(sender == checkBoxDrawn[i])
|
||||||
{
|
{
|
||||||
checkBoxClicked(checkBoxDrawn[i], pageIndex+i);
|
checkBoxClicked(checkBoxDrawn[i], pageIndex+i);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuiCheckboxBrowser::onListChange(int SelItem, int SelInd)
|
void GuiCheckboxBrowser::onListChange(int SelItem, int SelInd)
|
||||||
{
|
{
|
||||||
LOCK(this);
|
LOCK(this);
|
||||||
selectedItem = SelItem;
|
selectedItem = SelItem;
|
||||||
pageIndex = SelInd;
|
pageIndex = SelInd;
|
||||||
RefreshList();
|
RefreshList();
|
||||||
|
@ -133,43 +133,43 @@ void GuiCheckboxBrowser::onListChange(int SelItem, int SelInd)
|
||||||
|
|
||||||
void GuiCheckboxBrowser::RefreshList()
|
void GuiCheckboxBrowser::RefreshList()
|
||||||
{
|
{
|
||||||
LOCK(this);
|
LOCK(this);
|
||||||
while(pageIndex+checkBoxDrawn.size() > checkBoxList.size())
|
while(pageIndex+checkBoxDrawn.size() > checkBoxList.size())
|
||||||
--pageIndex;
|
--pageIndex;
|
||||||
|
|
||||||
if(checkBoxDrawn.size() == 0)
|
if(checkBoxDrawn.size() == 0)
|
||||||
selectedItem = 0;
|
selectedItem = 0;
|
||||||
else if(selectedItem >= (int) checkBoxDrawn.size())
|
else if(selectedItem >= (int) checkBoxDrawn.size())
|
||||||
selectedItem = checkBoxDrawn.size()-1;
|
selectedItem = checkBoxDrawn.size()-1;
|
||||||
|
|
||||||
for(u32 i = 0; i < checkBoxDrawn.size(); i++)
|
for(u32 i = 0; i < checkBoxDrawn.size(); i++)
|
||||||
{
|
{
|
||||||
checkBoxDrawn[i] = checkBoxList[pageIndex+i];
|
checkBoxDrawn[i] = checkBoxList[pageIndex+i];
|
||||||
checkBoxDrawn[i]->SetPosition(-scrollBar.GetWidth()-10, 15+i*(checkBoxDrawn[i]->GetHeight()+6));
|
checkBoxDrawn[i]->SetPosition(-scrollBar.GetWidth()-10, 15+i*(checkBoxDrawn[i]->GetHeight()+6));
|
||||||
|
|
||||||
textLineDrawn[i] = textLineList[pageIndex+i];
|
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]->SetPosition(25, 15+i*(checkBoxDrawn[i]->GetHeight()+6)+(checkBoxDrawn[i]->GetHeight()-textLineDrawn[i]->GetFontSize())/2+2);
|
||||||
}
|
}
|
||||||
scrollBar.SetSelectedItem(selectedItem);
|
scrollBar.SetSelectedItem(selectedItem);
|
||||||
scrollBar.SetSelectedIndex(pageIndex);
|
scrollBar.SetSelectedIndex(pageIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuiCheckboxBrowser::Draw()
|
void GuiCheckboxBrowser::Draw()
|
||||||
{
|
{
|
||||||
LOCK(this);
|
LOCK(this);
|
||||||
if(backgroundImg)
|
if(backgroundImg)
|
||||||
backgroundImg->Draw();
|
backgroundImg->Draw();
|
||||||
|
|
||||||
for(u32 i = 0; i < checkBoxDrawn.size(); ++i)
|
for(u32 i = 0; i < checkBoxDrawn.size(); ++i)
|
||||||
{
|
{
|
||||||
textLineDrawn[i]->Draw();
|
textLineDrawn[i]->Draw();
|
||||||
checkBoxDrawn[i]->Draw();
|
checkBoxDrawn[i]->Draw();
|
||||||
}
|
}
|
||||||
|
|
||||||
markImg->Draw();
|
markImg->Draw();
|
||||||
|
|
||||||
if(checkBoxList.size() >= (u32) maxSize)
|
if(checkBoxList.size() >= (u32) maxSize)
|
||||||
scrollBar.Draw();
|
scrollBar.Draw();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuiCheckboxBrowser::Update(GuiTrigger *t)
|
void GuiCheckboxBrowser::Update(GuiTrigger *t)
|
||||||
|
@ -177,39 +177,39 @@ void GuiCheckboxBrowser::Update(GuiTrigger *t)
|
||||||
if(state == STATE_DISABLED || !t)
|
if(state == STATE_DISABLED || !t)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
LOCK(this);
|
LOCK(this);
|
||||||
if(checkBoxList.size() >= maxSize)
|
if(checkBoxList.size() >= maxSize)
|
||||||
scrollBar.Update(t);
|
scrollBar.Update(t);
|
||||||
|
|
||||||
if((t->wpad.btns_d & (WPAD_BUTTON_B | WPAD_BUTTON_DOWN | WPAD_BUTTON_UP | WPAD_BUTTON_LEFT | WPAD_BUTTON_RIGHT |
|
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)) ||
|
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)))
|
(t->pad.btns_d & (PAD_BUTTON_UP | PAD_BUTTON_DOWN)))
|
||||||
pressedChan = t->chan;
|
pressedChan = t->chan;
|
||||||
|
|
||||||
for(u32 i = 0; i < checkBoxDrawn.size(); i++)
|
for(u32 i = 0; i < checkBoxDrawn.size(); i++)
|
||||||
{
|
{
|
||||||
if(pressedChan == -1 || (!t->wpad.btns_h && !t->pad.btns_h))
|
if(pressedChan == -1 || (!t->wpad.btns_h && !t->pad.btns_h))
|
||||||
{
|
{
|
||||||
if(i != (u32) selectedItem && checkBoxDrawn[i]->GetState() == STATE_SELECTED)
|
if(i != (u32) selectedItem && checkBoxDrawn[i]->GetState() == STATE_SELECTED)
|
||||||
checkBoxDrawn[i]->ResetState();
|
checkBoxDrawn[i]->ResetState();
|
||||||
else if(i == (u32) selectedItem && checkBoxDrawn[i]->GetState() == STATE_DEFAULT)
|
else if(i == (u32) selectedItem && checkBoxDrawn[i]->GetState() == STATE_DEFAULT)
|
||||||
checkBoxDrawn[selectedItem]->SetState(STATE_SELECTED, -1);
|
checkBoxDrawn[selectedItem]->SetState(STATE_SELECTED, -1);
|
||||||
|
|
||||||
checkBoxDrawn[i]->Update(t);
|
checkBoxDrawn[i]->Update(t);
|
||||||
|
|
||||||
if(checkBoxDrawn[i]->GetState() == STATE_SELECTED)
|
if(checkBoxDrawn[i]->GetState() == STATE_SELECTED)
|
||||||
selectedItem = i;
|
selectedItem = i;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(i == (u32) selectedItem)
|
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)
|
if(pressedChan == t->chan && !t->wpad.btns_d && !t->wpad.btns_h)
|
||||||
pressedChan = -1;
|
pressedChan = -1;
|
||||||
|
|
||||||
scrollBar.SetPageSize(checkBoxDrawn.size());
|
scrollBar.SetPageSize(checkBoxDrawn.size());
|
||||||
scrollBar.SetSelectedItem(selectedItem);
|
scrollBar.SetSelectedItem(selectedItem);
|
||||||
scrollBar.SetSelectedIndex(pageIndex);
|
scrollBar.SetSelectedIndex(pageIndex);
|
||||||
scrollBar.SetEntrieCount(checkBoxList.size());
|
scrollBar.SetEntrieCount(checkBoxList.size());
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,35 +33,35 @@ using namespace std;
|
||||||
|
|
||||||
class GuiCheckboxBrowser : public GuiElement, public sigslot::has_slots<>
|
class GuiCheckboxBrowser : public GuiElement, public sigslot::has_slots<>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
GuiCheckboxBrowser(int w, int h, int maxSize = 7);
|
GuiCheckboxBrowser(int w, int h, int maxSize = 7);
|
||||||
virtual ~GuiCheckboxBrowser();
|
virtual ~GuiCheckboxBrowser();
|
||||||
bool AddEntrie(const string &text, bool checked = false);
|
bool AddEntrie(const string &text, bool checked = false);
|
||||||
int GetSelected() const { return pageIndex+selectedItem; };
|
int GetSelected() const { return pageIndex+selectedItem; };
|
||||||
void SetImage(GuiImage *Img);
|
void SetImage(GuiImage *Img);
|
||||||
void RefreshList();
|
void RefreshList();
|
||||||
void Clear();
|
void Clear();
|
||||||
void Draw();
|
void Draw();
|
||||||
void Update(GuiTrigger *t);
|
void Update(GuiTrigger *t);
|
||||||
sigslot::signal2<GuiCheckbox *, int> checkBoxClicked;
|
sigslot::signal2<GuiCheckbox *, int> checkBoxClicked;
|
||||||
private:
|
private:
|
||||||
void onListChange(int SelItem, int SelInd);
|
void onListChange(int SelItem, int SelInd);
|
||||||
void OnCheckboxClick(GuiButton *sender, int chan, const POINT &pointer);
|
void OnCheckboxClick(GuiButton *sender, int chan, const POINT &pointer);
|
||||||
u16 maxSize;
|
u16 maxSize;
|
||||||
int selectedItem;
|
int selectedItem;
|
||||||
int pageIndex;
|
int pageIndex;
|
||||||
int pressedChan;
|
int pressedChan;
|
||||||
bool blocked;
|
bool blocked;
|
||||||
|
|
||||||
GuiScrollbar scrollBar;
|
GuiScrollbar scrollBar;
|
||||||
GuiTrigger trigA;
|
GuiTrigger trigA;
|
||||||
GuiImage *backgroundImg;
|
GuiImage *backgroundImg;
|
||||||
GuiImageData *markImgData;
|
GuiImageData *markImgData;
|
||||||
GuiImage *markImg;
|
GuiImage *markImg;
|
||||||
vector<GuiText *> textLineDrawn;
|
vector<GuiText *> textLineDrawn;
|
||||||
vector<GuiCheckbox *> checkBoxDrawn;
|
vector<GuiCheckbox *> checkBoxDrawn;
|
||||||
vector<GuiText *> textLineList;
|
vector<GuiText *> textLineList;
|
||||||
vector<GuiCheckbox *> checkBoxList;
|
vector<GuiCheckbox *> checkBoxList;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -25,32 +25,32 @@
|
||||||
|
|
||||||
void GuiChecksign::Draw()
|
void GuiChecksign::Draw()
|
||||||
{
|
{
|
||||||
GX_SetTevOp(GX_TEVSTAGE0, GX_PASSCLR);
|
GX_SetTevOp(GX_TEVSTAGE0, GX_PASSCLR);
|
||||||
GX_SetVtxDesc(GX_VA_POS, GX_DIRECT);
|
GX_SetVtxDesc(GX_VA_POS, GX_DIRECT);
|
||||||
GX_SetVtxDesc(GX_VA_CLR0, GX_DIRECT);
|
GX_SetVtxDesc(GX_VA_CLR0, GX_DIRECT);
|
||||||
GX_SetVtxDesc(GX_VA_TEX0, GX_NONE);
|
GX_SetVtxDesc(GX_VA_TEX0, GX_NONE);
|
||||||
|
|
||||||
f32 x1Line1 = (float) GetLeft() + width*0.1f;
|
f32 x1Line1 = (float) GetLeft() + width*0.1f;
|
||||||
f32 y1Line1 = (float) GetTop() + height*0.65f;
|
f32 y1Line1 = (float) GetTop() + height*0.65f;
|
||||||
f32 x2Line1 = GetLeft() + width*0.3f;
|
f32 x2Line1 = GetLeft() + width*0.3f;
|
||||||
f32 y2Line1 = (float) GetTop() + (float) height - height*0.1f;
|
f32 y2Line1 = (float) GetTop() + (float) height - height*0.1f;
|
||||||
|
|
||||||
f32 x1Line2 = x2Line1;
|
f32 x1Line2 = x2Line1;
|
||||||
f32 y1Line2 = y2Line1;
|
f32 y1Line2 = y2Line1;
|
||||||
f32 x2Line2 = (float) GetLeft() + (float) width - width*0.1f;
|
f32 x2Line2 = (float) GetLeft() + (float) width - width*0.1f;
|
||||||
f32 y2Line2 = (float) GetTop() + height*0.1f;
|
f32 y2Line2 = (float) GetTop() + height*0.1f;
|
||||||
|
|
||||||
int alpha = GetAlpha();
|
int alpha = GetAlpha();
|
||||||
|
|
||||||
GX_Begin(GX_LINES, GX_VTXFMT0, 4);
|
GX_Begin(GX_LINES, GX_VTXFMT0, 4);
|
||||||
GX_Position3f32(x1Line1, y1Line1, 0.0f);
|
GX_Position3f32(x1Line1, y1Line1, 0.0f);
|
||||||
GX_Color4u8(color.r, color.g, color.b, alpha);
|
GX_Color4u8(color.r, color.g, color.b, alpha);
|
||||||
GX_Position3f32(x2Line1, y2Line1, 0.0f);
|
GX_Position3f32(x2Line1, y2Line1, 0.0f);
|
||||||
GX_Color4u8(color.r, color.g, color.b, alpha);
|
GX_Color4u8(color.r, color.g, color.b, alpha);
|
||||||
GX_Position3f32(x1Line2, y1Line2, 0.0f);
|
GX_Position3f32(x1Line2, y1Line2, 0.0f);
|
||||||
GX_Color4u8(color.r, color.g, color.b, alpha);
|
GX_Color4u8(color.r, color.g, color.b, alpha);
|
||||||
GX_Position3f32(x2Line2, y2Line2, 0.0f);
|
GX_Position3f32(x2Line2, y2Line2, 0.0f);
|
||||||
GX_Color4u8(color.r, color.g, color.b, alpha);
|
GX_Color4u8(color.r, color.g, color.b, alpha);
|
||||||
GX_End();
|
GX_End();
|
||||||
GX_SetTevOp(GX_TEVSTAGE0, GX_MODULATE);
|
GX_SetTevOp(GX_TEVSTAGE0, GX_MODULATE);
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,16 +28,16 @@
|
||||||
|
|
||||||
class GuiChecksign : public GuiElement
|
class GuiChecksign : public GuiElement
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
GuiChecksign() : Linewidth(2.0f) { color = (GXColor) {0, 0, 0, 255}; GX_SetLineWidth((u8) (Linewidth*6.0f), 0); }
|
GuiChecksign() : Linewidth(2.0f) { color = (GXColor) {0, 0, 0, 255}; GX_SetLineWidth((u8) (Linewidth*6.0f), 0); }
|
||||||
//! Max line width is 42.5 pixel
|
//! Max line width is 42.5 pixel
|
||||||
void SetLinewidth(float w) { LOCK(this); Linewidth = w; GX_SetLineWidth((u8) (Linewidth*6.0f), 0); }
|
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 SetColor(const GXColor c) { LOCK(this); color = c; }
|
||||||
void SetSize(int w, int h) { LOCK(this); width = w; height = h; }
|
void SetSize(int w, int h) { LOCK(this); width = w; height = h; }
|
||||||
void Draw();
|
void Draw();
|
||||||
protected:
|
protected:
|
||||||
GXColor color;
|
GXColor color;
|
||||||
float Linewidth;
|
float Linewidth;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -24,46 +24,46 @@
|
||||||
#include "gui_circle.hpp"
|
#include "gui_circle.hpp"
|
||||||
|
|
||||||
GuiCircle::GuiCircle()
|
GuiCircle::GuiCircle()
|
||||||
: radius(100.0f), filled(true), accuracy(36)
|
: radius(100.0f), filled(true), accuracy(36)
|
||||||
{
|
{
|
||||||
|
|
||||||
color = (GXColor) {0, 0, 0, 255};
|
color = (GXColor) {0, 0, 0, 255};
|
||||||
SetLinewidth(1.0f);
|
SetLinewidth(1.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
GuiCircle::GuiCircle(float r)
|
GuiCircle::GuiCircle(float r)
|
||||||
: radius(r), filled(true), accuracy(36)
|
: radius(r), filled(true), accuracy(36)
|
||||||
{
|
{
|
||||||
color = (GXColor) {0, 0, 0, 255};
|
color = (GXColor) {0, 0, 0, 255};
|
||||||
SetLinewidth(1.0f);
|
SetLinewidth(1.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuiCircle::SetLinewidth(float s)
|
void GuiCircle::SetLinewidth(float s)
|
||||||
{
|
{
|
||||||
LOCK(this);
|
LOCK(this);
|
||||||
Linewidth = s;
|
Linewidth = s;
|
||||||
GX_SetLineWidth((u8) (s*6.0f), 0);
|
GX_SetLineWidth((u8) (s*6.0f), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuiCircle::Draw()
|
void GuiCircle::Draw()
|
||||||
{
|
{
|
||||||
GX_SetTevOp(GX_TEVSTAGE0, GX_PASSCLR);
|
GX_SetTevOp(GX_TEVSTAGE0, GX_PASSCLR);
|
||||||
GX_SetVtxDesc(GX_VA_POS, GX_DIRECT);
|
GX_SetVtxDesc(GX_VA_POS, GX_DIRECT);
|
||||||
GX_SetVtxDesc(GX_VA_CLR0, GX_DIRECT);
|
GX_SetVtxDesc(GX_VA_CLR0, GX_DIRECT);
|
||||||
GX_SetVtxDesc(GX_VA_TEX0, GX_NONE);
|
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);
|
GX_Begin(filled ? GX_TRIANGLEFAN : GX_LINESTRIP, GX_VTXFMT0, loopAmount);
|
||||||
for(int i = 0; i < loopAmount; ++i)
|
for(int i = 0; i < loopAmount; ++i)
|
||||||
{
|
{
|
||||||
f32 rad = (f32) i / (f32) accuracy * 360.0f;
|
f32 rad = (f32) i / (f32) accuracy * 360.0f;
|
||||||
f32 x = cos(DegToRad(rad)) * radius + GetLeft();
|
f32 x = cos(DegToRad(rad)) * radius + GetLeft();
|
||||||
f32 y = sin(DegToRad(rad)) * radius + GetTop();
|
f32 y = sin(DegToRad(rad)) * radius + GetTop();
|
||||||
|
|
||||||
GX_Position3f32(x, y, 0.0f);
|
GX_Position3f32(x, y, 0.0f);
|
||||||
GX_Color4u8(color.r, color.g, color.b, color.a);
|
GX_Color4u8(color.r, color.g, color.b, color.a);
|
||||||
}
|
}
|
||||||
GX_End();
|
GX_End();
|
||||||
GX_SetTevOp(GX_TEVSTAGE0, GX_MODULATE);
|
GX_SetTevOp(GX_TEVSTAGE0, GX_MODULATE);
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,22 +28,22 @@
|
||||||
|
|
||||||
class GuiCircle : public GuiElement
|
class GuiCircle : public GuiElement
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
GuiCircle();
|
GuiCircle();
|
||||||
GuiCircle(float radius);
|
GuiCircle(float radius);
|
||||||
void SetRadius(float r) { LOCK(this); radius = r; }
|
void SetRadius(float r) { LOCK(this); radius = r; }
|
||||||
void SetInnerRadius(float r) { SetLinewidth((radius-r)*2.0f); }
|
void SetInnerRadius(float r) { SetLinewidth((radius-r)*2.0f); }
|
||||||
void SetColor(const GXColor c) { LOCK(this); color = c; }
|
void SetColor(const GXColor c) { LOCK(this); color = c; }
|
||||||
void SetAccuracy(int a) { LOCK(this); accuracy = a; }
|
void SetAccuracy(int a) { LOCK(this); accuracy = a; }
|
||||||
void SetFilled(bool f) { LOCK(this); filled = f; }
|
void SetFilled(bool f) { LOCK(this); filled = f; }
|
||||||
void SetLinewidth(float s);
|
void SetLinewidth(float s);
|
||||||
void Draw();
|
void Draw();
|
||||||
protected:
|
protected:
|
||||||
GXColor color;
|
GXColor color;
|
||||||
float radius;
|
float radius;
|
||||||
float Linewidth;
|
float Linewidth;
|
||||||
bool filled;
|
bool filled;
|
||||||
int accuracy;
|
int accuracy;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -25,27 +25,27 @@
|
||||||
|
|
||||||
void GuiCross::Draw()
|
void GuiCross::Draw()
|
||||||
{
|
{
|
||||||
GX_SetTevOp(GX_TEVSTAGE0, GX_PASSCLR);
|
GX_SetTevOp(GX_TEVSTAGE0, GX_PASSCLR);
|
||||||
GX_SetVtxDesc(GX_VA_POS, GX_DIRECT);
|
GX_SetVtxDesc(GX_VA_POS, GX_DIRECT);
|
||||||
GX_SetVtxDesc(GX_VA_CLR0, GX_DIRECT);
|
GX_SetVtxDesc(GX_VA_CLR0, GX_DIRECT);
|
||||||
GX_SetVtxDesc(GX_VA_TEX0, GX_NONE);
|
GX_SetVtxDesc(GX_VA_TEX0, GX_NONE);
|
||||||
|
|
||||||
f32 x1 = GetLeft();
|
f32 x1 = GetLeft();
|
||||||
f32 x2 = x1 + width;
|
f32 x2 = x1 + width;
|
||||||
f32 y1 = GetTop();
|
f32 y1 = GetTop();
|
||||||
f32 y2 = y1 + height;
|
f32 y2 = y1 + height;
|
||||||
|
|
||||||
int alpha = GetAlpha();
|
int alpha = GetAlpha();
|
||||||
|
|
||||||
GX_Begin(GX_LINES, GX_VTXFMT0, 4);
|
GX_Begin(GX_LINES, GX_VTXFMT0, 4);
|
||||||
GX_Position3f32(x1, y1, 0.0f);
|
GX_Position3f32(x1, y1, 0.0f);
|
||||||
GX_Color4u8(color.r, color.g, color.b, alpha);
|
GX_Color4u8(color.r, color.g, color.b, alpha);
|
||||||
GX_Position3f32(x2, y2, 0.0f);
|
GX_Position3f32(x2, y2, 0.0f);
|
||||||
GX_Color4u8(color.r, color.g, color.b, alpha);
|
GX_Color4u8(color.r, color.g, color.b, alpha);
|
||||||
GX_Position3f32(x2, y1, 0.0f);
|
GX_Position3f32(x2, y1, 0.0f);
|
||||||
GX_Color4u8(color.r, color.g, color.b, alpha);
|
GX_Color4u8(color.r, color.g, color.b, alpha);
|
||||||
GX_Position3f32(x1, y2, 0.0f);
|
GX_Position3f32(x1, y2, 0.0f);
|
||||||
GX_Color4u8(color.r, color.g, color.b, alpha);
|
GX_Color4u8(color.r, color.g, color.b, alpha);
|
||||||
GX_End();
|
GX_End();
|
||||||
GX_SetTevOp(GX_TEVSTAGE0, GX_MODULATE);
|
GX_SetTevOp(GX_TEVSTAGE0, GX_MODULATE);
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,16 +28,16 @@
|
||||||
|
|
||||||
class GuiCross : public GuiElement
|
class GuiCross : public GuiElement
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
GuiCross() : Linewidth(2.0f) { color = (GXColor) {0, 0, 0, 255}; GX_SetLineWidth((u8) (Linewidth*6.0f), 0); }
|
GuiCross() : Linewidth(2.0f) { color = (GXColor) {0, 0, 0, 255}; GX_SetLineWidth((u8) (Linewidth*6.0f), 0); }
|
||||||
//! Max line width is 42.5 pixel
|
//! Max line width is 42.5 pixel
|
||||||
void SetLinewidth(float w) { LOCK(this); Linewidth = w; GX_SetLineWidth((u8) (Linewidth*6.0f), 0); }
|
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 SetColor(const GXColor c) { LOCK(this); color = c; }
|
||||||
void SetSize(int w, int h) { LOCK(this); width = w; height = h; }
|
void SetSize(int w, int h) { LOCK(this); width = w; height = h; }
|
||||||
void Draw();
|
void Draw();
|
||||||
protected:
|
protected:
|
||||||
GXColor color;
|
GXColor color;
|
||||||
float Linewidth;
|
float Linewidth;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -3,26 +3,26 @@
|
||||||
|
|
||||||
GuiDiskCover::GuiDiskCover()
|
GuiDiskCover::GuiDiskCover()
|
||||||
{
|
{
|
||||||
PosZ = 50;
|
PosZ = 50;
|
||||||
Distance = 55;
|
Distance = 55;
|
||||||
OldDegBeta = 0.0;
|
OldDegBeta = 0.0;
|
||||||
deg_beta = 0.0;
|
deg_beta = 0.0;
|
||||||
eff_step = 0;
|
eff_step = 0;
|
||||||
// spin_angle = 0;
|
// spin_angle = 0;
|
||||||
spin_speedup = 1.0;
|
spin_speedup = 1.0;
|
||||||
spin_up = false;
|
spin_up = false;
|
||||||
}
|
}
|
||||||
GuiDiskCover::GuiDiskCover(GuiImageData *Disk) :
|
GuiDiskCover::GuiDiskCover(GuiImageData *Disk) :
|
||||||
GuiImage(Disk)
|
GuiImage(Disk)
|
||||||
{
|
{
|
||||||
PosZ = 50;
|
PosZ = 50;
|
||||||
Distance = 55;
|
Distance = 55;
|
||||||
OldDegBeta = 0.0;
|
OldDegBeta = 0.0;
|
||||||
deg_beta = 0.0;
|
deg_beta = 0.0;
|
||||||
eff_step = 0;
|
eff_step = 0;
|
||||||
// spin_angle = 0;
|
// spin_angle = 0;
|
||||||
spin_speedup = 1.0;
|
spin_speedup = 1.0;
|
||||||
spin_up = false;
|
spin_up = false;
|
||||||
}
|
}
|
||||||
GuiDiskCover::~GuiDiskCover()
|
GuiDiskCover::~GuiDiskCover()
|
||||||
{
|
{
|
||||||
|
@ -30,74 +30,74 @@ GuiDiskCover::~GuiDiskCover()
|
||||||
|
|
||||||
void GuiDiskCover::SetBeta(f32 beta)
|
void GuiDiskCover::SetBeta(f32 beta)
|
||||||
{
|
{
|
||||||
deg_beta = beta;
|
deg_beta = beta;
|
||||||
}
|
}
|
||||||
void GuiDiskCover::SetBetaRotateEffect(f32 beta, u16 step)
|
void GuiDiskCover::SetBetaRotateEffect(f32 beta, u16 step)
|
||||||
{
|
{
|
||||||
eff_beta = beta / (f32) step;
|
eff_beta = beta / (f32) step;
|
||||||
eff_step = step;
|
eff_step = step;
|
||||||
}
|
}
|
||||||
bool GuiDiskCover::GetBetaRotateEffect()
|
bool GuiDiskCover::GetBetaRotateEffect()
|
||||||
{
|
{
|
||||||
return eff_step != 0;
|
return eff_step != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuiDiskCover::SetSpin(bool Up)
|
void GuiDiskCover::SetSpin(bool Up)
|
||||||
{
|
{
|
||||||
spin_up = Up;
|
spin_up = Up;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuiDiskCover::SetState(int s, int c)
|
void GuiDiskCover::SetState(int s, int c)
|
||||||
{
|
{
|
||||||
if(state == STATE_DEFAULT && s == STATE_DISABLED)
|
if(state == STATE_DEFAULT && s == STATE_DISABLED)
|
||||||
{
|
{
|
||||||
PosZ = 0;
|
PosZ = 0;
|
||||||
Distance = 0;
|
Distance = 0;
|
||||||
OldDegBeta = deg_beta;
|
OldDegBeta = deg_beta;
|
||||||
deg_beta = 0.0f;
|
deg_beta = 0.0f;
|
||||||
}
|
}
|
||||||
else if(state == STATE_DISABLED && s == STATE_DEFAULT)
|
else if(state == STATE_DISABLED && s == STATE_DEFAULT)
|
||||||
{
|
{
|
||||||
PosZ = 50;
|
PosZ = 50;
|
||||||
Distance = 55;
|
Distance = 55;
|
||||||
deg_beta = OldDegBeta;
|
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,
|
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()
|
void GuiDiskCover::Draw()
|
||||||
{
|
{
|
||||||
LOCK( this );
|
LOCK( this );
|
||||||
if (!image || !this->IsVisible()) return;
|
if (!image || !this->IsVisible()) return;
|
||||||
float currScale = this->GetScale();
|
float currScale = this->GetScale();
|
||||||
|
|
||||||
Menu_DrawDiskCover(this->GetLeft(), this->GetTop(), PosZ, width, height, Distance, image, imageangle, deg_beta,
|
Menu_DrawDiskCover(this->GetLeft(), this->GetTop(), PosZ, width, height, Distance, image, imageangle, deg_beta,
|
||||||
widescreen ? currScale * Settings.WSFactor : currScale, currScale, 64, true);
|
widescreen ? currScale * Settings.WSFactor : currScale, currScale, 64, true);
|
||||||
Menu_DrawDiskCover(this->GetLeft(), this->GetTop(), PosZ, width, height, Distance, image, imageangle, deg_beta,
|
Menu_DrawDiskCover(this->GetLeft(), this->GetTop(), PosZ, width, height, Distance, image, imageangle, deg_beta,
|
||||||
widescreen ? currScale * Settings.WSFactor : currScale, currScale, this->GetAlpha(), false);
|
widescreen ? currScale * Settings.WSFactor : currScale, currScale, this->GetAlpha(), false);
|
||||||
|
|
||||||
if (eff_step)
|
if (eff_step)
|
||||||
{
|
{
|
||||||
deg_beta += eff_beta;
|
deg_beta += eff_beta;
|
||||||
eff_step--;
|
eff_step--;
|
||||||
}
|
}
|
||||||
GuiImage::imageangle += spin_speedup;
|
GuiImage::imageangle += spin_speedup;
|
||||||
while (GuiImage::imageangle >= 360.0)
|
while (GuiImage::imageangle >= 360.0)
|
||||||
GuiImage::imageangle -= 360.0;
|
GuiImage::imageangle -= 360.0;
|
||||||
|
|
||||||
if (spin_up)
|
if (spin_up)
|
||||||
{
|
{
|
||||||
if (spin_speedup < 11) // speed up
|
if (spin_speedup < 11) // speed up
|
||||||
spin_speedup += 0.20;
|
spin_speedup += 0.20;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (spin_speedup > 1) spin_speedup -= 0.05; //slow down
|
if (spin_speedup > 1) spin_speedup -= 0.05; //slow down
|
||||||
}
|
}
|
||||||
|
|
||||||
this->UpdateEffects();
|
this->UpdateEffects();
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,28 +5,28 @@
|
||||||
|
|
||||||
class GuiDiskCover: public GuiImage
|
class GuiDiskCover: public GuiImage
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
GuiDiskCover();
|
GuiDiskCover();
|
||||||
GuiDiskCover(GuiImageData * img);
|
GuiDiskCover(GuiImageData * img);
|
||||||
virtual ~GuiDiskCover();
|
virtual ~GuiDiskCover();
|
||||||
void SetBeta(f32 beta);
|
void SetBeta(f32 beta);
|
||||||
void SetBetaRotateEffect(f32 beta, u16 Step);
|
void SetBetaRotateEffect(f32 beta, u16 Step);
|
||||||
bool GetBetaRotateEffect();
|
bool GetBetaRotateEffect();
|
||||||
|
|
||||||
void SetSpin(bool Up);
|
void SetSpin(bool Up);
|
||||||
void SetState(int s, int c = -1);
|
void SetState(int s, int c = -1);
|
||||||
void Draw();
|
void Draw();
|
||||||
private:
|
private:
|
||||||
f32 deg_beta;
|
f32 deg_beta;
|
||||||
f32 eff_beta;
|
f32 eff_beta;
|
||||||
u16 eff_step;
|
u16 eff_step;
|
||||||
|
|
||||||
// f32 spin_angle;
|
// f32 spin_angle;
|
||||||
f32 spin_speedup;
|
f32 spin_speedup;
|
||||||
int PosZ;
|
int PosZ;
|
||||||
int Distance;
|
int Distance;
|
||||||
f32 OldDegBeta;
|
f32 OldDegBeta;
|
||||||
bool spin_up;
|
bool spin_up;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* _GUIDISCCOVER_H_ */
|
#endif /* _GUIDISCCOVER_H_ */
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -17,56 +17,56 @@
|
||||||
* Constructor for the GuiFileBrowser class.
|
* Constructor for the GuiFileBrowser class.
|
||||||
*/
|
*/
|
||||||
GuiFileBrowser::GuiFileBrowser(int w, int h)
|
GuiFileBrowser::GuiFileBrowser(int w, int h)
|
||||||
: scrollBar(h-10)
|
: scrollBar(h-10)
|
||||||
{
|
{
|
||||||
width = w;
|
width = w;
|
||||||
height = h;
|
height = h;
|
||||||
selectedItem = 0;
|
selectedItem = 0;
|
||||||
selectable = true;
|
selectable = true;
|
||||||
triggerdisabled = false; // trigger disable
|
triggerdisabled = false; // trigger disable
|
||||||
focus = 0; // allow focus
|
focus = 0; // allow focus
|
||||||
|
|
||||||
trigA = new GuiTrigger;
|
trigA = new GuiTrigger;
|
||||||
trigA->SetSimpleTrigger(-1, WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A, PAD_BUTTON_A);
|
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"));
|
bgFileSelection = new GuiImageData(Resources::GetFile("bg_browser.png"), Resources::GetFileSize("bg_browser.png"));
|
||||||
bgFileSelectionImg = new GuiImage(bgFileSelection);
|
bgFileSelectionImg = new GuiImage(bgFileSelection);
|
||||||
bgFileSelectionImg->SetParent(this);
|
bgFileSelectionImg->SetParent(this);
|
||||||
bgFileSelectionImg->SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE);
|
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.SetParent(this);
|
||||||
scrollBar.SetAlignment(ALIGN_RIGHT, ALIGN_TOP);
|
scrollBar.SetAlignment(ALIGN_RIGHT, ALIGN_TOP);
|
||||||
scrollBar.SetPosition(0, 5);
|
scrollBar.SetPosition(0, 5);
|
||||||
scrollBar.listChanged.connect(this, &GuiFileBrowser::onListChange);
|
scrollBar.listChanged.connect(this, &GuiFileBrowser::onListChange);
|
||||||
|
|
||||||
for (int i = 0; i < FILEBROWSERSIZE; i++)
|
for (int i = 0; i < FILEBROWSERSIZE; i++)
|
||||||
{
|
{
|
||||||
fileListText[i] = new GuiText((char *) NULL, 20, ( GXColor ) {0, 0, 0, 0xff});
|
fileListText[i] = new GuiText((char *) NULL, 20, ( GXColor ) {0, 0, 0, 0xff});
|
||||||
fileListText[i]->SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE);
|
fileListText[i]->SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE);
|
||||||
fileListText[i]->SetPosition(5, 0);
|
fileListText[i]->SetPosition(5, 0);
|
||||||
fileListText[i]->SetMaxWidth(bgFileSelectionImg->GetWidth() - (scrollBar.GetWidth() + 40), DOTTED);
|
fileListText[i]->SetMaxWidth(bgFileSelectionImg->GetWidth() - (scrollBar.GetWidth() + 40), DOTTED);
|
||||||
|
|
||||||
fileListTextOver[i] = new GuiText((char *) NULL, 20, ( GXColor ) {0, 0, 0, 0xff});
|
fileListTextOver[i] = new GuiText((char *) NULL, 20, ( GXColor ) {0, 0, 0, 0xff});
|
||||||
fileListTextOver[i]->SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE);
|
fileListTextOver[i]->SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE);
|
||||||
fileListTextOver[i]->SetPosition(5, 0);
|
fileListTextOver[i]->SetPosition(5, 0);
|
||||||
fileListTextOver[i]->SetMaxWidth(bgFileSelectionImg->GetWidth() - (scrollBar.GetWidth() + 40), SCROLL_HORIZONTAL);
|
fileListTextOver[i]->SetMaxWidth(bgFileSelectionImg->GetWidth() - (scrollBar.GetWidth() + 40), SCROLL_HORIZONTAL);
|
||||||
|
|
||||||
fileListBg[i] = new GuiImage(bgFileSelectionEntry);
|
fileListBg[i] = new GuiImage(bgFileSelectionEntry);
|
||||||
fileListFolder[i] = new GuiImage(fileFolder);
|
fileListFolder[i] = new GuiImage(fileFolder);
|
||||||
fileList[i] = new GuiButton(350, 30);
|
fileList[i] = new GuiButton(350, 30);
|
||||||
fileList[i]->SetParent(this);
|
fileList[i]->SetParent(this);
|
||||||
fileList[i]->SetLabel(fileListText[i]);
|
fileList[i]->SetLabel(fileListText[i]);
|
||||||
fileList[i]->SetLabelOver(fileListTextOver[i]);
|
fileList[i]->SetLabelOver(fileListTextOver[i]);
|
||||||
fileList[i]->SetImageOver(fileListBg[i]);
|
fileList[i]->SetImageOver(fileListBg[i]);
|
||||||
fileList[i]->SetPosition(2, 30 * i + 3);
|
fileList[i]->SetPosition(2, 30 * i + 3);
|
||||||
fileList[i]->SetTrigger(trigA);
|
fileList[i]->SetTrigger(trigA);
|
||||||
fileList[i]->SetRumble(false);
|
fileList[i]->SetRumble(false);
|
||||||
fileList[i]->SetSoundClick(btnSoundClick);
|
fileList[i]->SetSoundClick(btnSoundClick);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -74,64 +74,64 @@ GuiFileBrowser::GuiFileBrowser(int w, int h)
|
||||||
*/
|
*/
|
||||||
GuiFileBrowser::~GuiFileBrowser()
|
GuiFileBrowser::~GuiFileBrowser()
|
||||||
{
|
{
|
||||||
delete bgFileSelectionImg;
|
delete bgFileSelectionImg;
|
||||||
|
|
||||||
delete bgFileSelection;
|
delete bgFileSelection;
|
||||||
delete bgFileSelectionEntry;
|
delete bgFileSelectionEntry;
|
||||||
delete fileFolder;
|
delete fileFolder;
|
||||||
|
|
||||||
delete trigA;
|
delete trigA;
|
||||||
|
|
||||||
for (int i = 0; i < FILEBROWSERSIZE; i++)
|
for (int i = 0; i < FILEBROWSERSIZE; i++)
|
||||||
{
|
{
|
||||||
delete fileListText[i];
|
delete fileListText[i];
|
||||||
delete fileListTextOver[i];
|
delete fileListTextOver[i];
|
||||||
delete fileList[i];
|
delete fileList[i];
|
||||||
delete fileListBg[i];
|
delete fileListBg[i];
|
||||||
delete fileListFolder[i];
|
delete fileListFolder[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuiFileBrowser::SetFocus(int f)
|
void GuiFileBrowser::SetFocus(int f)
|
||||||
{
|
{
|
||||||
LOCK( this );
|
LOCK( this );
|
||||||
focus = f;
|
focus = f;
|
||||||
|
|
||||||
for (int i = 0; i < FILEBROWSERSIZE; i++)
|
for (int i = 0; i < FILEBROWSERSIZE; i++)
|
||||||
fileList[i]->ResetState();
|
fileList[i]->ResetState();
|
||||||
|
|
||||||
if (f == 1)
|
if (f == 1)
|
||||||
fileList[selectedItem]->SetState(STATE_SELECTED);
|
fileList[selectedItem]->SetState(STATE_SELECTED);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuiFileBrowser::DisableTriggerUpdate(bool set)
|
void GuiFileBrowser::DisableTriggerUpdate(bool set)
|
||||||
{
|
{
|
||||||
LOCK( this );
|
LOCK( this );
|
||||||
triggerdisabled = set;
|
triggerdisabled = set;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuiFileBrowser::ResetState()
|
void GuiFileBrowser::ResetState()
|
||||||
{
|
{
|
||||||
LOCK( this );
|
LOCK( this );
|
||||||
state = STATE_DEFAULT;
|
state = STATE_DEFAULT;
|
||||||
stateChan = -1;
|
stateChan = -1;
|
||||||
selectedItem = 0;
|
selectedItem = 0;
|
||||||
|
|
||||||
for (int i = 0; i < FILEBROWSERSIZE; i++)
|
for (int i = 0; i < FILEBROWSERSIZE; i++)
|
||||||
{
|
{
|
||||||
fileList[i]->ResetState();
|
fileList[i]->ResetState();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuiFileBrowser::UpdateList()
|
void GuiFileBrowser::UpdateList()
|
||||||
{
|
{
|
||||||
LOCK( this );
|
LOCK( this );
|
||||||
for (int i = 0; i < FILEBROWSERSIZE; i++)
|
for (int i = 0; i < FILEBROWSERSIZE; i++)
|
||||||
{
|
{
|
||||||
if (browser->pageIndex + i < (int) browser->browserList.size())
|
if (browser->pageIndex + i < (int) browser->browserList.size())
|
||||||
{
|
{
|
||||||
if (fileList[i]->GetState() == STATE_DISABLED)
|
if (fileList[i]->GetState() == STATE_DISABLED)
|
||||||
fileList[i]->SetState(STATE_DEFAULT);
|
fileList[i]->SetState(STATE_DEFAULT);
|
||||||
|
|
||||||
fileList[i]->SetVisible(true);
|
fileList[i]->SetVisible(true);
|
||||||
|
|
||||||
|
@ -161,9 +161,9 @@ void GuiFileBrowser::UpdateList()
|
||||||
|
|
||||||
void GuiFileBrowser::onListChange(int SelItem, int SelInd)
|
void GuiFileBrowser::onListChange(int SelItem, int SelInd)
|
||||||
{
|
{
|
||||||
selectedItem = SelItem;
|
selectedItem = SelItem;
|
||||||
browser->pageIndex = SelInd;
|
browser->pageIndex = SelInd;
|
||||||
UpdateList();
|
UpdateList();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -171,60 +171,60 @@ void GuiFileBrowser::onListChange(int SelItem, int SelInd)
|
||||||
*/
|
*/
|
||||||
void GuiFileBrowser::Draw()
|
void GuiFileBrowser::Draw()
|
||||||
{
|
{
|
||||||
LOCK( this );
|
LOCK( this );
|
||||||
if (!this->IsVisible()) return;
|
if (!this->IsVisible()) return;
|
||||||
|
|
||||||
bgFileSelectionImg->Draw();
|
bgFileSelectionImg->Draw();
|
||||||
|
|
||||||
for (int i = 0; i < FILEBROWSERSIZE; i++)
|
for (int i = 0; i < FILEBROWSERSIZE; i++)
|
||||||
{
|
{
|
||||||
fileList[i]->Draw();
|
fileList[i]->Draw();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(browser->browserList.size() > FILEBROWSERSIZE)
|
if(browser->browserList.size() > FILEBROWSERSIZE)
|
||||||
scrollBar.Draw();
|
scrollBar.Draw();
|
||||||
|
|
||||||
this->UpdateEffects();
|
this->UpdateEffects();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuiFileBrowser::Update(GuiTrigger * t)
|
void GuiFileBrowser::Update(GuiTrigger * t)
|
||||||
{
|
{
|
||||||
LOCK( this );
|
LOCK( this );
|
||||||
if (state == STATE_DISABLED || !t || triggerdisabled)
|
if (state == STATE_DISABLED || !t || triggerdisabled)
|
||||||
return;
|
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 |
|
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)) ||
|
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)))
|
(t->pad.btns_d & (PAD_BUTTON_UP | PAD_BUTTON_DOWN)))
|
||||||
pressedChan = t->chan;
|
pressedChan = t->chan;
|
||||||
|
|
||||||
if(browser->browserList.size() > FILEBROWSERSIZE)
|
if(browser->browserList.size() > FILEBROWSERSIZE)
|
||||||
scrollBar.Update(t);
|
scrollBar.Update(t);
|
||||||
|
|
||||||
if(pressedChan == -1 || (!t->wpad.btns_h && !t->pad.btns_h))
|
if(pressedChan == -1 || (!t->wpad.btns_h && !t->pad.btns_h))
|
||||||
{
|
{
|
||||||
for (int i = 0; i < FILEBROWSERSIZE; i++)
|
for (int i = 0; i < FILEBROWSERSIZE; i++)
|
||||||
{
|
{
|
||||||
if (i != selectedItem && fileList[i]->GetState() == STATE_SELECTED)
|
if (i != selectedItem && fileList[i]->GetState() == STATE_SELECTED)
|
||||||
fileList[i]->ResetState();
|
fileList[i]->ResetState();
|
||||||
else if (i == selectedItem && fileList[i]->GetState() == STATE_DEFAULT)
|
else if (i == selectedItem && fileList[i]->GetState() == STATE_DEFAULT)
|
||||||
fileList[selectedItem]->SetState(STATE_SELECTED, -1);
|
fileList[selectedItem]->SetState(STATE_SELECTED, -1);
|
||||||
|
|
||||||
fileList[i]->Update(t);
|
fileList[i]->Update(t);
|
||||||
|
|
||||||
if (fileList[i]->GetState() == STATE_SELECTED)
|
if (fileList[i]->GetState() == STATE_SELECTED)
|
||||||
selectedItem = i;
|
selectedItem = i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if(pressedChan == t->chan && !t->wpad.btns_d && !t->wpad.btns_h)
|
if(pressedChan == t->chan && !t->wpad.btns_d && !t->wpad.btns_h)
|
||||||
pressedChan = -1;
|
pressedChan = -1;
|
||||||
|
|
||||||
scrollBar.SetPageSize(FILEBROWSERSIZE);
|
scrollBar.SetPageSize(FILEBROWSERSIZE);
|
||||||
scrollBar.SetSelectedItem(selectedItem);
|
scrollBar.SetSelectedItem(selectedItem);
|
||||||
scrollBar.SetSelectedIndex(browser->pageIndex);
|
scrollBar.SetSelectedIndex(browser->pageIndex);
|
||||||
scrollBar.SetEntrieCount(browser->browserList.size());
|
scrollBar.SetEntrieCount(browser->browserList.size());
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,34 +7,34 @@
|
||||||
//!Display a list of files
|
//!Display a list of files
|
||||||
class GuiFileBrowser: public GuiElement, public sigslot::has_slots<>
|
class GuiFileBrowser: public GuiElement, public sigslot::has_slots<>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
GuiFileBrowser(int w, int h);
|
GuiFileBrowser(int w, int h);
|
||||||
virtual ~GuiFileBrowser();
|
virtual ~GuiFileBrowser();
|
||||||
void DisableTriggerUpdate(bool set);
|
void DisableTriggerUpdate(bool set);
|
||||||
void ResetState();
|
void ResetState();
|
||||||
void SetFocus(int f);
|
void SetFocus(int f);
|
||||||
void Draw();
|
void Draw();
|
||||||
void UpdateList();
|
void UpdateList();
|
||||||
void Update(GuiTrigger * t);
|
void Update(GuiTrigger * t);
|
||||||
GuiButton * fileList[PAGESIZE];
|
GuiButton * fileList[PAGESIZE];
|
||||||
protected:
|
protected:
|
||||||
void onListChange(int SelItem, int SelInd);
|
void onListChange(int SelItem, int SelInd);
|
||||||
int selectedItem;
|
int selectedItem;
|
||||||
bool triggerdisabled;
|
bool triggerdisabled;
|
||||||
|
|
||||||
GuiText * fileListText[PAGESIZE];
|
GuiText * fileListText[PAGESIZE];
|
||||||
GuiText * fileListTextOver[PAGESIZE];
|
GuiText * fileListTextOver[PAGESIZE];
|
||||||
GuiImage * fileListBg[PAGESIZE];
|
GuiImage * fileListBg[PAGESIZE];
|
||||||
GuiImage * fileListFolder[PAGESIZE];
|
GuiImage * fileListFolder[PAGESIZE];
|
||||||
|
|
||||||
GuiImage * bgFileSelectionImg;
|
GuiImage * bgFileSelectionImg;
|
||||||
|
|
||||||
GuiImageData * bgFileSelection;
|
GuiImageData * bgFileSelection;
|
||||||
GuiImageData * bgFileSelectionEntry;
|
GuiImageData * bgFileSelectionEntry;
|
||||||
GuiImageData * fileFolder;
|
GuiImageData * fileFolder;
|
||||||
|
|
||||||
GuiTrigger * trigA;
|
GuiTrigger * trigA;
|
||||||
GuiScrollbar scrollBar;
|
GuiScrollbar scrollBar;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -25,93 +25,93 @@
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
#define SCALE 0.8f
|
#define SCALE 0.8f
|
||||||
#define DEG_OFFSET 7
|
#define DEG_OFFSET 7
|
||||||
#define RADIUS 780
|
#define RADIUS 780
|
||||||
#define IN_SPEED 175
|
#define IN_SPEED 175
|
||||||
#define SHIFT_SPEED 75
|
#define SHIFT_SPEED 75
|
||||||
#define SPEED_STEP 4
|
#define SPEED_STEP 4
|
||||||
#define SPEED_LIMIT 250
|
#define SPEED_LIMIT 250
|
||||||
|
|
||||||
static inline int OFFSETLIMIT(int Offset, int gameCnt)
|
static inline int OFFSETLIMIT(int Offset, int gameCnt)
|
||||||
{
|
{
|
||||||
while (Offset < 0)
|
while (Offset < 0)
|
||||||
Offset += gameCnt;
|
Offset += gameCnt;
|
||||||
return Offset % gameCnt;
|
return Offset % gameCnt;
|
||||||
}
|
}
|
||||||
#define GetGameIndex(pageEntry, listOffset, gameCnt) OFFSETLIMIT(listOffset+pageEntry, gameCnt)
|
#define GetGameIndex(pageEntry, listOffset, gameCnt) OFFSETLIMIT(listOffset+pageEntry, gameCnt)
|
||||||
static GuiImageData *GameCarouselLoadCoverImage(void * Arg)
|
static GuiImageData *GameCarouselLoadCoverImage(void * Arg)
|
||||||
{
|
{
|
||||||
return LoadCoverImage((struct discHdr *) Arg, true, false);
|
return LoadCoverImage((struct discHdr *) Arg, true, false);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Constructor for the GuiGameCarousel class.
|
* Constructor for the GuiGameCarousel class.
|
||||||
*/
|
*/
|
||||||
GuiGameCarousel::GuiGameCarousel(int w, int h, const char *themePath, int offset) :
|
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;
|
width = w;
|
||||||
height = h;
|
height = h;
|
||||||
pagesize = (gameList.size() < 11) ? gameList.size() : 11;
|
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;
|
listOffset = (gameList.size() < 11) ? LIMIT(offset, 0, MAX(0, gameList.size()-1)) : LIMIT(offset, 0, MAX(0, gameList.size()-1))-2;
|
||||||
selectable = true;
|
selectable = true;
|
||||||
selectedItem = -1;
|
selectedItem = -1;
|
||||||
focus = 1; // allow focus
|
focus = 1; // allow focus
|
||||||
clickedItem = -1;
|
clickedItem = -1;
|
||||||
|
|
||||||
speed = 0;
|
speed = 0;
|
||||||
|
|
||||||
trigA = new GuiTrigger;
|
trigA = new GuiTrigger;
|
||||||
trigA->SetSimpleTrigger(-1, WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A, PAD_BUTTON_A);
|
trigA->SetSimpleTrigger(-1, WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A, PAD_BUTTON_A);
|
||||||
trigL = new GuiTrigger;
|
trigL = new GuiTrigger;
|
||||||
trigL->SetButtonOnlyTrigger(-1, WPAD_BUTTON_LEFT | WPAD_CLASSIC_BUTTON_LEFT, PAD_BUTTON_LEFT);
|
trigL->SetButtonOnlyTrigger(-1, WPAD_BUTTON_LEFT | WPAD_CLASSIC_BUTTON_LEFT, PAD_BUTTON_LEFT);
|
||||||
trigR = new GuiTrigger;
|
trigR = new GuiTrigger;
|
||||||
trigR->SetButtonOnlyTrigger(-1, WPAD_BUTTON_RIGHT | WPAD_CLASSIC_BUTTON_RIGHT, PAD_BUTTON_RIGHT);
|
trigR->SetButtonOnlyTrigger(-1, WPAD_BUTTON_RIGHT | WPAD_CLASSIC_BUTTON_RIGHT, PAD_BUTTON_RIGHT);
|
||||||
trigPlus = new GuiTrigger;
|
trigPlus = new GuiTrigger;
|
||||||
trigPlus->SetButtonOnlyTrigger(-1, WPAD_BUTTON_PLUS | WPAD_CLASSIC_BUTTON_PLUS, 0);
|
trigPlus->SetButtonOnlyTrigger(-1, WPAD_BUTTON_PLUS | WPAD_CLASSIC_BUTTON_PLUS, 0);
|
||||||
trigMinus = new GuiTrigger;
|
trigMinus = new GuiTrigger;
|
||||||
trigMinus->SetButtonOnlyTrigger(-1, WPAD_BUTTON_MINUS | WPAD_CLASSIC_BUTTON_MINUS, 0);
|
trigMinus->SetButtonOnlyTrigger(-1, WPAD_BUTTON_MINUS | WPAD_CLASSIC_BUTTON_MINUS, 0);
|
||||||
|
|
||||||
imgLeft = Resources::GetImageData("startgame_arrow_left.png");
|
imgLeft = Resources::GetImageData("startgame_arrow_left.png");
|
||||||
imgRight = Resources::GetImageData("startgame_arrow_right.png");
|
imgRight = Resources::GetImageData("startgame_arrow_right.png");
|
||||||
|
|
||||||
btnLeftImg = new GuiImage(imgLeft);
|
btnLeftImg = new GuiImage(imgLeft);
|
||||||
if (Settings.wsprompt == ON) btnLeftImg->SetWidescreen(Settings.widescreen);
|
if (Settings.wsprompt == ON) btnLeftImg->SetWidescreen(Settings.widescreen);
|
||||||
btnLeft = new GuiButton(imgLeft->GetWidth(), imgLeft->GetHeight());
|
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->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->SetPosition(thInt("20 - carousel layout left arrow pos x"), thInt("65 - carousel layout left arrow pos y"));
|
||||||
btnLeft->SetParent(this);
|
btnLeft->SetParent(this);
|
||||||
btnLeft->SetImage(btnLeftImg);
|
btnLeft->SetImage(btnLeftImg);
|
||||||
btnLeft->SetSoundOver(btnSoundOver);
|
btnLeft->SetSoundOver(btnSoundOver);
|
||||||
btnLeft->SetTrigger(trigA);
|
btnLeft->SetTrigger(trigA);
|
||||||
btnLeft->SetTrigger(trigL);
|
btnLeft->SetTrigger(trigL);
|
||||||
btnLeft->SetTrigger(trigMinus);
|
btnLeft->SetTrigger(trigMinus);
|
||||||
btnLeft->SetEffectGrow();
|
btnLeft->SetEffectGrow();
|
||||||
|
|
||||||
btnRightImg = new GuiImage(imgRight);
|
btnRightImg = new GuiImage(imgRight);
|
||||||
if (Settings.wsprompt == ON) btnRightImg->SetWidescreen(Settings.widescreen);
|
if (Settings.wsprompt == ON) btnRightImg->SetWidescreen(Settings.widescreen);
|
||||||
btnRight = new GuiButton(imgRight->GetWidth(), imgRight->GetHeight());
|
btnRight = new GuiButton(imgRight->GetWidth(), imgRight->GetHeight());
|
||||||
btnRight->SetParent(this);
|
btnRight->SetParent(this);
|
||||||
btnRight->SetAlignment(thAlign("right - carousel layout right arrow align hor"), thAlign("top - carousel layout right arrow align ver"));
|
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->SetPosition(thInt("-20 - carousel layout right arrow pos x"), thInt("65 - carousel layout right arrow pos y"));
|
||||||
btnRight->SetImage(btnRightImg);
|
btnRight->SetImage(btnRightImg);
|
||||||
btnRight->SetSoundOver(btnSoundOver);
|
btnRight->SetSoundOver(btnSoundOver);
|
||||||
btnRight->SetTrigger(trigA);
|
btnRight->SetTrigger(trigA);
|
||||||
btnRight->SetTrigger(trigR);
|
btnRight->SetTrigger(trigR);
|
||||||
btnRight->SetTrigger(trigPlus);
|
btnRight->SetTrigger(trigPlus);
|
||||||
btnRight->SetEffectGrow();
|
btnRight->SetEffectGrow();
|
||||||
|
|
||||||
gamename = new GuiText(" ", 18, thColor("r=55 g=190 b=237 a=255 - carousel game name text color"));
|
gamename = new GuiText(" ", 18, thColor("r=55 g=190 b=237 a=255 - carousel game name text color"));
|
||||||
gamename->SetParent(this);
|
gamename->SetParent(this);
|
||||||
gamename->SetAlignment(ALIGN_CENTRE, ALIGN_TOP);
|
gamename->SetAlignment(ALIGN_CENTRE, ALIGN_TOP);
|
||||||
gamename->SetPosition(0, 330);
|
gamename->SetPosition(0, 330);
|
||||||
gamename->SetMaxWidth(280, DOTTED);
|
gamename->SetMaxWidth(280, DOTTED);
|
||||||
|
|
||||||
gameIndex = new int[pagesize];
|
gameIndex = new int[pagesize];
|
||||||
game.resize(pagesize);
|
game.resize(pagesize);
|
||||||
coverImg.resize(pagesize);
|
coverImg.resize(pagesize);
|
||||||
|
|
||||||
Refresh();
|
Refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -119,34 +119,34 @@ GuiGameCarousel::GuiGameCarousel(int w, int h, const char *themePath, int offset
|
||||||
*/
|
*/
|
||||||
GuiGameCarousel::~GuiGameCarousel()
|
GuiGameCarousel::~GuiGameCarousel()
|
||||||
{
|
{
|
||||||
delete imgRight;
|
delete imgRight;
|
||||||
delete imgLeft;
|
delete imgLeft;
|
||||||
delete btnLeftImg;
|
delete btnLeftImg;
|
||||||
delete btnRightImg;
|
delete btnRightImg;
|
||||||
delete btnRight;
|
delete btnRight;
|
||||||
delete btnLeft;
|
delete btnLeft;
|
||||||
|
|
||||||
delete trigA;
|
delete trigA;
|
||||||
delete trigL;
|
delete trigL;
|
||||||
delete trigR;
|
delete trigR;
|
||||||
delete trigPlus;
|
delete trigPlus;
|
||||||
delete trigMinus;
|
delete trigMinus;
|
||||||
delete gamename;
|
delete gamename;
|
||||||
|
|
||||||
GuiImageAsync::ClearQueue();
|
GuiImageAsync::ClearQueue();
|
||||||
|
|
||||||
for (u32 i = 0; i < game.size(); ++i)
|
for (u32 i = 0; i < game.size(); ++i)
|
||||||
delete coverImg[i];
|
delete coverImg[i];
|
||||||
for (u32 i = 0; i < game.size(); ++i)
|
for (u32 i = 0; i < game.size(); ++i)
|
||||||
delete game[i];
|
delete game[i];
|
||||||
|
|
||||||
delete[] gameIndex;
|
delete[] gameIndex;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuiGameCarousel::setListOffset(int off)
|
void GuiGameCarousel::setListOffset(int off)
|
||||||
{
|
{
|
||||||
LOCK( this );
|
LOCK( this );
|
||||||
if(gameList.size() < 11)
|
if(gameList.size() < 11)
|
||||||
listOffset = MIN(off, gameList.size()-1);
|
listOffset = MIN(off, gameList.size()-1);
|
||||||
else
|
else
|
||||||
|
@ -171,96 +171,96 @@ void GuiGameCarousel::SetSelectedOption(int ind)
|
||||||
|
|
||||||
void GuiGameCarousel::Refresh()
|
void GuiGameCarousel::Refresh()
|
||||||
{
|
{
|
||||||
for (int i = 0; i < pagesize; i++)
|
for (int i = 0; i < pagesize; i++)
|
||||||
{
|
{
|
||||||
//------------------------
|
//------------------------
|
||||||
// Index
|
// Index
|
||||||
//------------------------
|
//------------------------
|
||||||
gameIndex[i] = GetGameIndex( i, listOffset, gameList.size() );
|
gameIndex[i] = GetGameIndex( i, listOffset, gameList.size() );
|
||||||
|
|
||||||
//------------------------
|
//------------------------
|
||||||
// Image
|
// Image
|
||||||
//------------------------
|
//------------------------
|
||||||
delete coverImg[i];
|
delete coverImg[i];
|
||||||
coverImg[i] = new (std::nothrow) GuiImageAsync(GameCarouselLoadCoverImage, gameList[gameIndex[i]], sizeof(struct discHdr), &noCover);
|
coverImg[i] = new (std::nothrow) GuiImageAsync(GameCarouselLoadCoverImage, gameList[gameIndex[i]], sizeof(struct discHdr), &noCover);
|
||||||
if (coverImg[i]) coverImg[i]->SetWidescreen(Settings.widescreen);
|
if (coverImg[i]) coverImg[i]->SetWidescreen(Settings.widescreen);
|
||||||
|
|
||||||
//------------------------
|
//------------------------
|
||||||
// GameButton
|
// GameButton
|
||||||
//------------------------
|
//------------------------
|
||||||
delete game[i];
|
delete game[i];
|
||||||
game[i] = new GuiButton(122, 244);
|
game[i] = new GuiButton(122, 244);
|
||||||
game[i]->SetParent(this);
|
game[i]->SetParent(this);
|
||||||
game[i]->SetAlignment(ALIGN_CENTRE, ALIGN_MIDDLE);
|
game[i]->SetAlignment(ALIGN_CENTRE, ALIGN_MIDDLE);
|
||||||
game[i]->SetPosition(0, 740);
|
game[i]->SetPosition(0, 740);
|
||||||
game[i]->SetImage(coverImg[i]);
|
game[i]->SetImage(coverImg[i]);
|
||||||
game[i]->SetScale(SCALE);
|
game[i]->SetScale(SCALE);
|
||||||
game[i]->SetRumble(false);
|
game[i]->SetRumble(false);
|
||||||
game[i]->SetTrigger(trigA);
|
game[i]->SetTrigger(trigA);
|
||||||
game[i]->SetSoundClick(btnSoundClick);
|
game[i]->SetSoundClick(btnSoundClick);
|
||||||
game[i]->SetClickable(true);
|
game[i]->SetClickable(true);
|
||||||
game[i]->SetEffect(EFFECT_GOROUND, IN_SPEED, 90 - (pagesize - 2 * i - 1) * DEG_OFFSET / 2, RADIUS, 180, 1, 0, RADIUS);
|
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)
|
void GuiGameCarousel::SetFocus(int f)
|
||||||
{
|
{
|
||||||
LOCK( this );
|
LOCK( this );
|
||||||
if (!gameList.size()) return;
|
if (!gameList.size()) return;
|
||||||
|
|
||||||
focus = f;
|
focus = f;
|
||||||
|
|
||||||
for (int i = 0; i < pagesize; i++)
|
for (int i = 0; i < pagesize; i++)
|
||||||
game[i]->ResetState();
|
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()
|
void GuiGameCarousel::ResetState()
|
||||||
{
|
{
|
||||||
LOCK( this );
|
LOCK( this );
|
||||||
if (state != STATE_DISABLED)
|
if (state != STATE_DISABLED)
|
||||||
{
|
{
|
||||||
state = STATE_DEFAULT;
|
state = STATE_DEFAULT;
|
||||||
stateChan = -1;
|
stateChan = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < pagesize; i++)
|
for (int i = 0; i < pagesize; i++)
|
||||||
{
|
{
|
||||||
game[i]->ResetState();
|
game[i]->ResetState();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int GuiGameCarousel::GetClickedOption()
|
int GuiGameCarousel::GetClickedOption()
|
||||||
{
|
{
|
||||||
LOCK( this );
|
LOCK( this );
|
||||||
int found = -1;
|
int found = -1;
|
||||||
if (clickedItem >= 0)
|
if (clickedItem >= 0)
|
||||||
{
|
{
|
||||||
for (int i = pagesize - 1; i >= 0; i--)
|
for (int i = pagesize - 1; i >= 0; i--)
|
||||||
game[i]->ResetState();
|
game[i]->ResetState();
|
||||||
|
|
||||||
game[clickedItem]->SetState(STATE_SELECTED);
|
game[clickedItem]->SetState(STATE_SELECTED);
|
||||||
found = gameIndex[clickedItem];
|
found = gameIndex[clickedItem];
|
||||||
clickedItem = -1;
|
clickedItem = -1;
|
||||||
}
|
}
|
||||||
return found;
|
return found;
|
||||||
}
|
}
|
||||||
|
|
||||||
int GuiGameCarousel::GetSelectedOption()
|
int GuiGameCarousel::GetSelectedOption()
|
||||||
{
|
{
|
||||||
LOCK( this );
|
LOCK( this );
|
||||||
int found = -1;
|
int found = -1;
|
||||||
for (int i = 0; i < pagesize; i++)
|
for (int i = 0; i < pagesize; i++)
|
||||||
{
|
{
|
||||||
if (game[i]->GetState() == STATE_SELECTED)
|
if (game[i]->GetState() == STATE_SELECTED)
|
||||||
{
|
{
|
||||||
game[i]->SetState(STATE_SELECTED);
|
game[i]->SetState(STATE_SELECTED);
|
||||||
found = gameIndex[i];
|
found = gameIndex[i];
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return found;
|
return found;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -268,194 +268,194 @@ int GuiGameCarousel::GetSelectedOption()
|
||||||
*/
|
*/
|
||||||
void GuiGameCarousel::Draw()
|
void GuiGameCarousel::Draw()
|
||||||
{
|
{
|
||||||
LOCK( this );
|
LOCK( this );
|
||||||
if (!this->IsVisible() || !gameList.size()) return;
|
if (!this->IsVisible() || !gameList.size()) return;
|
||||||
|
|
||||||
for (int i = 0; i < pagesize; i++)
|
for (int i = 0; i < pagesize; i++)
|
||||||
game[i]->Draw();
|
game[i]->Draw();
|
||||||
|
|
||||||
gamename->Draw();
|
gamename->Draw();
|
||||||
|
|
||||||
if (gameList.size() > 6)
|
if (gameList.size() > 6)
|
||||||
{
|
{
|
||||||
btnRight->Draw();
|
btnRight->Draw();
|
||||||
btnLeft->Draw();
|
btnLeft->Draw();
|
||||||
}
|
}
|
||||||
|
|
||||||
//!Draw tooltip after the Images to have it on top
|
//!Draw tooltip after the Images to have it on top
|
||||||
if (focus && Settings.tooltips == ON) for (int i = 0; i < pagesize; i++)
|
if (focus && Settings.tooltips == ON) for (int i = 0; i < pagesize; i++)
|
||||||
game[i]->DrawTooltip();
|
game[i]->DrawTooltip();
|
||||||
|
|
||||||
this->UpdateEffects();
|
this->UpdateEffects();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuiGameCarousel::Update(GuiTrigger * t)
|
void GuiGameCarousel::Update(GuiTrigger * t)
|
||||||
{
|
{
|
||||||
LOCK( this );
|
LOCK( this );
|
||||||
if (state == STATE_DISABLED || !t || !gameList.size() || !pagesize) return;
|
if (state == STATE_DISABLED || !t || !gameList.size() || !pagesize) return;
|
||||||
|
|
||||||
btnRight->Update(t);
|
btnRight->Update(t);
|
||||||
btnLeft->Update(t);
|
btnLeft->Update(t);
|
||||||
|
|
||||||
if ((game[0]->GetEffect() & EFFECT_GOROUND) || (game[pagesize - 1]->GetEffect() & EFFECT_GOROUND))
|
if ((game[0]->GetEffect() & EFFECT_GOROUND) || (game[pagesize - 1]->GetEffect() & EFFECT_GOROUND))
|
||||||
{
|
{
|
||||||
return; // skip when rotate
|
return; // skip when rotate
|
||||||
}
|
}
|
||||||
|
|
||||||
// find selected + clicked
|
// find selected + clicked
|
||||||
int selectedItem_old = selectedItem;
|
int selectedItem_old = selectedItem;
|
||||||
selectedItem = -1;
|
selectedItem = -1;
|
||||||
clickedItem = -1;
|
clickedItem = -1;
|
||||||
for (int i = pagesize - 1; i >= 0; i--)
|
for (int i = pagesize - 1; i >= 0; i--)
|
||||||
{
|
{
|
||||||
game[i]->Update(t);
|
game[i]->Update(t);
|
||||||
if (game[i]->GetState() == STATE_SELECTED)
|
if (game[i]->GetState() == STATE_SELECTED)
|
||||||
{
|
{
|
||||||
selectedItem = i;
|
selectedItem = i;
|
||||||
}
|
}
|
||||||
if (game[i]->GetState() == STATE_CLICKED)
|
if (game[i]->GetState() == STATE_CLICKED)
|
||||||
{
|
{
|
||||||
clickedItem = i;
|
clickedItem = i;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// OnOver-Effect + GameText + Tooltop
|
/// OnOver-Effect + GameText + Tooltop
|
||||||
if (selectedItem_old != selectedItem)
|
if (selectedItem_old != selectedItem)
|
||||||
{
|
{
|
||||||
if (selectedItem >= 0)
|
if (selectedItem >= 0)
|
||||||
{
|
{
|
||||||
game[selectedItem]->SetEffect(EFFECT_SCALE, 1, 130);
|
game[selectedItem]->SetEffect(EFFECT_SCALE, 1, 130);
|
||||||
gamename->SetText(GameTitles.GetTitle(gameList[gameIndex[selectedItem]]));
|
gamename->SetText(GameTitles.GetTitle(gameList[gameIndex[selectedItem]]));
|
||||||
}
|
}
|
||||||
else gamename->SetText((char*) NULL);
|
else gamename->SetText((char*) NULL);
|
||||||
if (selectedItem_old >= 0) game[selectedItem_old]->SetEffect(EFFECT_SCALE, -1, 100);
|
if (selectedItem_old >= 0) game[selectedItem_old]->SetEffect(EFFECT_SCALE, -1, 100);
|
||||||
}
|
}
|
||||||
// navigation
|
// navigation
|
||||||
if (focus && gameList.size() > 6)
|
if (focus && gameList.size() > 6)
|
||||||
{
|
{
|
||||||
|
|
||||||
int newspeed = 0;
|
int newspeed = 0;
|
||||||
// Left/Right Navigation
|
// Left/Right Navigation
|
||||||
if (btnLeft->GetState() == STATE_CLICKED)
|
if (btnLeft->GetState() == STATE_CLICKED)
|
||||||
{
|
{
|
||||||
WPAD_ScanPads();
|
WPAD_ScanPads();
|
||||||
u16 buttons = 0;
|
u16 buttons = 0;
|
||||||
for (int i = 0; i < 4; i++)
|
for (int i = 0; i < 4; i++)
|
||||||
buttons |= WPAD_ButtonsHeld(i);
|
buttons |= WPAD_ButtonsHeld(i);
|
||||||
if (!((buttons & WPAD_BUTTON_A) || (buttons & WPAD_BUTTON_MINUS) || t->Left()))
|
if (!((buttons & WPAD_BUTTON_A) || (buttons & WPAD_BUTTON_MINUS) || t->Left()))
|
||||||
{
|
{
|
||||||
btnLeft->ResetState();
|
btnLeft->ResetState();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Settings.xflip == XFLIP_SYSMENU || Settings.xflip == XFLIP_YES || Settings.xflip == XFLIP_DISK3D)
|
if (Settings.xflip == XFLIP_SYSMENU || Settings.xflip == XFLIP_YES || Settings.xflip == XFLIP_DISK3D)
|
||||||
newspeed = SHIFT_SPEED;
|
newspeed = SHIFT_SPEED;
|
||||||
else newspeed = -SHIFT_SPEED;
|
else newspeed = -SHIFT_SPEED;
|
||||||
}
|
}
|
||||||
else if (btnRight->GetState() == STATE_CLICKED)
|
else if (btnRight->GetState() == STATE_CLICKED)
|
||||||
{
|
{
|
||||||
WPAD_ScanPads();
|
WPAD_ScanPads();
|
||||||
u16 buttons = 0;
|
u16 buttons = 0;
|
||||||
for (int i = 0; i < 4; i++)
|
for (int i = 0; i < 4; i++)
|
||||||
buttons |= WPAD_ButtonsHeld(i);
|
buttons |= WPAD_ButtonsHeld(i);
|
||||||
if (!((buttons & WPAD_BUTTON_A) || (buttons & WPAD_BUTTON_PLUS) || t->Right()))
|
if (!((buttons & WPAD_BUTTON_A) || (buttons & WPAD_BUTTON_PLUS) || t->Right()))
|
||||||
{
|
{
|
||||||
btnRight->ResetState();
|
btnRight->ResetState();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (Settings.xflip == XFLIP_SYSMENU || Settings.xflip == XFLIP_YES || Settings.xflip == XFLIP_DISK3D)
|
if (Settings.xflip == XFLIP_SYSMENU || Settings.xflip == XFLIP_YES || Settings.xflip == XFLIP_DISK3D)
|
||||||
newspeed = -SHIFT_SPEED;
|
newspeed = -SHIFT_SPEED;
|
||||||
else newspeed = SHIFT_SPEED;
|
else newspeed = SHIFT_SPEED;
|
||||||
}
|
}
|
||||||
if (newspeed)
|
if (newspeed)
|
||||||
{
|
{
|
||||||
if (speed == 0)
|
if (speed == 0)
|
||||||
speed = newspeed;
|
speed = newspeed;
|
||||||
else if (speed > 0)
|
else if (speed > 0)
|
||||||
{
|
{
|
||||||
if ((speed += SPEED_STEP) > SPEED_LIMIT) speed = SPEED_LIMIT;
|
if ((speed += SPEED_STEP) > SPEED_LIMIT) speed = SPEED_LIMIT;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if ((speed -= SPEED_STEP) < -SPEED_LIMIT) speed = -SPEED_LIMIT;
|
if ((speed -= SPEED_STEP) < -SPEED_LIMIT) speed = -SPEED_LIMIT;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else speed = 0;
|
else speed = 0;
|
||||||
|
|
||||||
if (speed > 0) // rotate right
|
if (speed > 0) // rotate right
|
||||||
{
|
{
|
||||||
GuiButton *tmpButton;
|
GuiButton *tmpButton;
|
||||||
listOffset = OFFSETLIMIT(listOffset - 1, gameList.size()); // set the new listOffset
|
listOffset = OFFSETLIMIT(listOffset - 1, gameList.size()); // set the new listOffset
|
||||||
// Save right Button + TollTip and destroy right Image + Image-Data
|
// Save right Button + TollTip and destroy right Image + Image-Data
|
||||||
delete coverImg[pagesize - 1];
|
delete coverImg[pagesize - 1];
|
||||||
coverImg[pagesize - 1] = NULL;
|
coverImg[pagesize - 1] = NULL;
|
||||||
game[pagesize - 1]->SetImage(NULL);
|
game[pagesize - 1]->SetImage(NULL);
|
||||||
tmpButton = game[pagesize - 1];
|
tmpButton = game[pagesize - 1];
|
||||||
|
|
||||||
// Move all Page-Entries one step right
|
// Move all Page-Entries one step right
|
||||||
for (int i = pagesize - 1; i >= 1; i--)
|
for (int i = pagesize - 1; i >= 1; i--)
|
||||||
{
|
{
|
||||||
coverImg[i] = coverImg[i - 1];
|
coverImg[i] = coverImg[i - 1];
|
||||||
game[i] = game[i - 1];
|
game[i] = game[i - 1];
|
||||||
gameIndex[i] = gameIndex[i - 1];
|
gameIndex[i] = gameIndex[i - 1];
|
||||||
}
|
}
|
||||||
// set saved Button & gameIndex to right
|
// set saved Button & gameIndex to right
|
||||||
gameIndex[0] = listOffset;
|
gameIndex[0] = listOffset;
|
||||||
coverImg[0] = new GuiImageAsync(GameCarouselLoadCoverImage, gameList[gameIndex[0]], sizeof(struct discHdr),
|
coverImg[0] = new GuiImageAsync(GameCarouselLoadCoverImage, gameList[gameIndex[0]], sizeof(struct discHdr),
|
||||||
&noCover);
|
&noCover);
|
||||||
coverImg[0] ->SetWidescreen(Settings.widescreen);
|
coverImg[0] ->SetWidescreen(Settings.widescreen);
|
||||||
|
|
||||||
game[0] = tmpButton;
|
game[0] = tmpButton;
|
||||||
game[0] ->SetImage(coverImg[0]);
|
game[0] ->SetImage(coverImg[0]);
|
||||||
|
|
||||||
for (int i = 0; i < pagesize; i++)
|
for (int i = 0; i < pagesize; i++)
|
||||||
{
|
{
|
||||||
game[i]->StopEffect();
|
game[i]->StopEffect();
|
||||||
game[i]->ResetState();
|
game[i]->ResetState();
|
||||||
game[i]->SetEffect(EFFECT_GOROUND, speed, DEG_OFFSET, RADIUS, 270 - (pagesize - 2 * i + 1) * DEG_OFFSET
|
game[i]->SetEffect(EFFECT_GOROUND, speed, DEG_OFFSET, RADIUS, 270 - (pagesize - 2 * i + 1) * DEG_OFFSET
|
||||||
/ 2, 1, 0, RADIUS);
|
/ 2, 1, 0, RADIUS);
|
||||||
game[i]->UpdateEffects(); // rotate one step for liquid scrolling
|
game[i]->UpdateEffects(); // rotate one step for liquid scrolling
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (speed < 0) // rotate left
|
else if (speed < 0) // rotate left
|
||||||
{
|
{
|
||||||
GuiButton *tmpButton;
|
GuiButton *tmpButton;
|
||||||
listOffset = OFFSETLIMIT(listOffset + 1, gameList.size()); // set the new listOffset
|
listOffset = OFFSETLIMIT(listOffset + 1, gameList.size()); // set the new listOffset
|
||||||
// Save left Button + TollTip and destroy left Image + Image-Data
|
// Save left Button + TollTip and destroy left Image + Image-Data
|
||||||
delete coverImg[0];
|
delete coverImg[0];
|
||||||
coverImg[0] = NULL;
|
coverImg[0] = NULL;
|
||||||
game[0]->SetImage(NULL);
|
game[0]->SetImage(NULL);
|
||||||
tmpButton = game[0];
|
tmpButton = game[0];
|
||||||
|
|
||||||
// Move all Page-Entries one step left
|
// Move all Page-Entries one step left
|
||||||
for (int i = 0; i < (pagesize - 1); i++)
|
for (int i = 0; i < (pagesize - 1); i++)
|
||||||
{
|
{
|
||||||
coverImg[i] = coverImg[i + 1];
|
coverImg[i] = coverImg[i + 1];
|
||||||
game[i] = game[i + 1];
|
game[i] = game[i + 1];
|
||||||
gameIndex[i] = gameIndex[i + 1];
|
gameIndex[i] = gameIndex[i + 1];
|
||||||
}
|
}
|
||||||
// set saved Button & gameIndex to right
|
// set saved Button & gameIndex to right
|
||||||
int ii = pagesize - 1;
|
int ii = pagesize - 1;
|
||||||
gameIndex[ii] = OFFSETLIMIT(listOffset + ii, gameList.size());
|
gameIndex[ii] = OFFSETLIMIT(listOffset + ii, gameList.size());
|
||||||
coverImg[ii] = new GuiImageAsync(GameCarouselLoadCoverImage, gameList[gameIndex[ii]],
|
coverImg[ii] = new GuiImageAsync(GameCarouselLoadCoverImage, gameList[gameIndex[ii]],
|
||||||
sizeof(struct discHdr), &noCover);
|
sizeof(struct discHdr), &noCover);
|
||||||
coverImg[ii] ->SetWidescreen(Settings.widescreen);
|
coverImg[ii] ->SetWidescreen(Settings.widescreen);
|
||||||
|
|
||||||
game[ii] = tmpButton;
|
game[ii] = tmpButton;
|
||||||
game[ii] ->SetImage(coverImg[ii]);
|
game[ii] ->SetImage(coverImg[ii]);
|
||||||
|
|
||||||
for (int i = 0; i < pagesize; i++)
|
for (int i = 0; i < pagesize; i++)
|
||||||
{
|
{
|
||||||
game[i]->StopEffect();
|
game[i]->StopEffect();
|
||||||
game[i]->ResetState();
|
game[i]->ResetState();
|
||||||
game[i]->SetEffect(EFFECT_GOROUND, speed, DEG_OFFSET, RADIUS, 270 - (pagesize - 2 * i - 3) * DEG_OFFSET
|
game[i]->SetEffect(EFFECT_GOROUND, speed, DEG_OFFSET, RADIUS, 270 - (pagesize - 2 * i - 3) * DEG_OFFSET
|
||||||
/ 2, 1, 0, RADIUS);
|
/ 2, 1, 0, RADIUS);
|
||||||
game[i]->UpdateEffects(); // rotate one step for liquid scrolling
|
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
|
class GuiGameCarousel : public GuiGameBrowser
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
GuiGameCarousel(int w, int h, const char *themePath, int listOffset = 0);
|
GuiGameCarousel(int w, int h, const char *themePath, int listOffset = 0);
|
||||||
virtual ~GuiGameCarousel();
|
virtual ~GuiGameCarousel();
|
||||||
int FindMenuItem(int c, int d);
|
int FindMenuItem(int c, int d);
|
||||||
int GetClickedOption();
|
int GetClickedOption();
|
||||||
int GetSelectedOption();
|
int GetSelectedOption();
|
||||||
void SetSelectedOption(int ind);
|
void SetSelectedOption(int ind);
|
||||||
void setListOffset(int off);
|
void setListOffset(int off);
|
||||||
int getListOffset() const;
|
int getListOffset() const;
|
||||||
void Refresh();
|
void Refresh();
|
||||||
void ResetState();
|
void ResetState();
|
||||||
void SetFocus(int f);
|
void SetFocus(int f);
|
||||||
void Draw();
|
void Draw();
|
||||||
void Update(GuiTrigger * t);
|
void Update(GuiTrigger * t);
|
||||||
protected:
|
protected:
|
||||||
GuiImageData noCover;
|
GuiImageData noCover;
|
||||||
int selectedItem;
|
int selectedItem;
|
||||||
int listOffset;
|
int listOffset;
|
||||||
int scrollbaron;
|
int scrollbaron;
|
||||||
int pagesize;
|
int pagesize;
|
||||||
int speed;
|
int speed;
|
||||||
int clickedItem;
|
int clickedItem;
|
||||||
|
|
||||||
int * gameIndex;
|
int * gameIndex;
|
||||||
std::vector<GuiButton *> game;
|
std::vector<GuiButton *> game;
|
||||||
std::vector<GuiImageAsync *> coverImg;
|
std::vector<GuiImageAsync *> coverImg;
|
||||||
|
|
||||||
GuiText * gamename;
|
GuiText * gamename;
|
||||||
|
|
||||||
GuiButton * btnRight;
|
GuiButton * btnRight;
|
||||||
GuiButton * btnLeft;
|
GuiButton * btnLeft;
|
||||||
|
|
||||||
GuiImage * btnLeftImg;
|
GuiImage * btnLeftImg;
|
||||||
GuiImage * btnRightImg;
|
GuiImage * btnRightImg;
|
||||||
|
|
||||||
GuiImageData * imgLeft;
|
GuiImageData * imgLeft;
|
||||||
GuiImageData * imgRight;
|
GuiImageData * imgRight;
|
||||||
|
|
||||||
GuiTrigger * trigA;
|
GuiTrigger * trigA;
|
||||||
GuiTrigger * trigL;
|
GuiTrigger * trigL;
|
||||||
GuiTrigger * trigR;
|
GuiTrigger * trigR;
|
||||||
GuiTrigger * trigPlus;
|
GuiTrigger * trigPlus;
|
||||||
GuiTrigger * trigMinus;
|
GuiTrigger * trigMinus;
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -8,55 +8,55 @@
|
||||||
|
|
||||||
class GuiGameGrid : public GuiGameBrowser
|
class GuiGameGrid : public GuiGameBrowser
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
GuiGameGrid(int w, int h, const char *themePath, int selectedGame = 0);
|
GuiGameGrid(int w, int h, const char *themePath, int selectedGame = 0);
|
||||||
virtual ~GuiGameGrid();
|
virtual ~GuiGameGrid();
|
||||||
int FindMenuItem(int c, int d);
|
int FindMenuItem(int c, int d);
|
||||||
int GetClickedOption();
|
int GetClickedOption();
|
||||||
int GetSelectedOption();
|
int GetSelectedOption();
|
||||||
void SetSelectedOption(int ind);
|
void SetSelectedOption(int ind);
|
||||||
void setListOffset(int off) { listOffset = off; Reload(rows, listOffset); }
|
void setListOffset(int off) { listOffset = off; Reload(rows, listOffset); }
|
||||||
int getListOffset() const { return listOffset; }
|
int getListOffset() const { return listOffset; }
|
||||||
void ResetState();
|
void ResetState();
|
||||||
void SetFocus(int f);
|
void SetFocus(int f);
|
||||||
void Draw();
|
void Draw();
|
||||||
void Update(GuiTrigger * t);
|
void Update(GuiTrigger * t);
|
||||||
void Reload(int Rows, int ListOffset);
|
void Reload(int Rows, int ListOffset);
|
||||||
void ChangeRows(int n);
|
void ChangeRows(int n);
|
||||||
protected:
|
protected:
|
||||||
GuiImageData noCover;
|
GuiImageData noCover;
|
||||||
int selectedItem;
|
int selectedItem;
|
||||||
int listOffset;
|
int listOffset;
|
||||||
int pagesize;
|
int pagesize;
|
||||||
int clickedItem;
|
int clickedItem;
|
||||||
int rows;
|
int rows;
|
||||||
int goLeft;
|
int goLeft;
|
||||||
int goRight;
|
int goRight;
|
||||||
int theme_posX;
|
int theme_posX;
|
||||||
int theme_posY;
|
int theme_posY;
|
||||||
|
|
||||||
std::vector<int> gameIndex;
|
std::vector<int> gameIndex;
|
||||||
std::vector<GuiButton *> game;
|
std::vector<GuiButton *> game;
|
||||||
std::vector<GuiTooltip *> titleTT;
|
std::vector<GuiTooltip *> titleTT;
|
||||||
std::vector<GuiImageAsync *> coverImg;
|
std::vector<GuiImageAsync *> coverImg;
|
||||||
|
|
||||||
GuiButton * btnRight;
|
GuiButton * btnRight;
|
||||||
GuiButton * btnLeft;
|
GuiButton * btnLeft;
|
||||||
GuiButton * btnRowUp;
|
GuiButton * btnRowUp;
|
||||||
GuiButton * btnRowDown;
|
GuiButton * btnRowDown;
|
||||||
|
|
||||||
GuiImage * btnLeftImg;
|
GuiImage * btnLeftImg;
|
||||||
GuiImage * btnRightImg;
|
GuiImage * btnRightImg;
|
||||||
|
|
||||||
GuiImageData * imgLeft;
|
GuiImageData * imgLeft;
|
||||||
GuiImageData * imgRight;
|
GuiImageData * imgRight;
|
||||||
|
|
||||||
GuiTrigger * trigA;
|
GuiTrigger * trigA;
|
||||||
GuiTrigger * trigL;
|
GuiTrigger * trigL;
|
||||||
GuiTrigger * trigR;
|
GuiTrigger * trigR;
|
||||||
GuiTrigger * trigPlus;
|
GuiTrigger * trigPlus;
|
||||||
GuiTrigger * trigMinus;
|
GuiTrigger * trigMinus;
|
||||||
GuiTrigger * trig1;
|
GuiTrigger * trig1;
|
||||||
GuiTrigger * trig2;
|
GuiTrigger * trig2;
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -23,85 +23,85 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
#define GAMESELECTSIZE 30
|
#define GAMESELECTSIZE 30
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor for the GuiGameList class.
|
* Constructor for the GuiGameList class.
|
||||||
*/
|
*/
|
||||||
GuiGameList::GuiGameList(int w, int h, int offset)
|
GuiGameList::GuiGameList(int w, int h, int offset)
|
||||||
: scrollBar(h-10)
|
: scrollBar(h-10)
|
||||||
{
|
{
|
||||||
width = w;
|
width = w;
|
||||||
height = h;
|
height = h;
|
||||||
pagesize = thInt("9 - game list browser page size");
|
pagesize = thInt("9 - game list browser page size");
|
||||||
scrollbaron = (gameList.size() > pagesize) ? 1 : 0;
|
scrollbaron = (gameList.size() > pagesize) ? 1 : 0;
|
||||||
selectable = true;
|
selectable = true;
|
||||||
listOffset = LIMIT(offset, 0, MAX(0, gameList.size()-pagesize));
|
listOffset = LIMIT(offset, 0, MAX(0, gameList.size()-pagesize));
|
||||||
selectedItem = 0;
|
selectedItem = 0;
|
||||||
focus = 1; // allow focus
|
focus = 1; // allow focus
|
||||||
|
|
||||||
trigA = new GuiTrigger;
|
trigA = new GuiTrigger;
|
||||||
trigA->SetSimpleTrigger(-1, WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A, PAD_BUTTON_A);
|
trigA->SetSimpleTrigger(-1, WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A, PAD_BUTTON_A);
|
||||||
|
|
||||||
bgGames = Resources::GetImageData("bg_options.png");
|
bgGames = Resources::GetImageData("bg_options.png");
|
||||||
newGames = Resources::GetImageData("new.png");
|
newGames = Resources::GetImageData("new.png");
|
||||||
|
|
||||||
scrollBar.SetParent(this);
|
scrollBar.SetParent(this);
|
||||||
scrollBar.SetAlignment(thAlign("right - game browser scrollbar align hor"), thAlign("top - game browser scrollbar align ver"));
|
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.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.SetButtonScroll(WPAD_BUTTON_B | WPAD_CLASSIC_BUTTON_B);
|
||||||
scrollBar.SetPageSize(pagesize);
|
scrollBar.SetPageSize(pagesize);
|
||||||
scrollBar.SetSelectedItem(selectedItem);
|
scrollBar.SetSelectedItem(selectedItem);
|
||||||
scrollBar.SetSelectedIndex(listOffset);
|
scrollBar.SetSelectedIndex(listOffset);
|
||||||
scrollBar.SetEntrieCount(gameList.size());
|
scrollBar.SetEntrieCount(gameList.size());
|
||||||
scrollBar.listChanged.connect(this, &GuiGameList::onListChange);
|
scrollBar.listChanged.connect(this, &GuiGameList::onListChange);
|
||||||
|
|
||||||
bgGameImg = new GuiImage(bgGames);
|
bgGameImg = new GuiImage(bgGames);
|
||||||
bgGameImg->SetParent(this);
|
bgGameImg->SetParent(this);
|
||||||
bgGameImg->SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE);
|
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];
|
game = new GuiButton *[pagesize];
|
||||||
gameTxt = new GuiText *[pagesize];
|
gameTxt = new GuiText *[pagesize];
|
||||||
gameTxtOver = new GuiText *[pagesize];
|
gameTxtOver = new GuiText *[pagesize];
|
||||||
gameBg = new GuiImage *[pagesize];
|
gameBg = new GuiImage *[pagesize];
|
||||||
newImg = new GuiImage *[pagesize];
|
newImg = new GuiImage *[pagesize];
|
||||||
|
|
||||||
for (int i = 0; i < pagesize; ++i)
|
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] = 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]->SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE);
|
||||||
gameTxt[i]->SetPosition(24, 0);
|
gameTxt[i]->SetPosition(24, 0);
|
||||||
gameTxt[i]->SetMaxWidth(maxTextWidth, DOTTED);
|
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] = 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]->SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE);
|
||||||
gameTxtOver[i]->SetPosition(24, 0);
|
gameTxtOver[i]->SetPosition(24, 0);
|
||||||
gameTxtOver[i]->SetMaxWidth(maxTextWidth, SCROLL_HORIZONTAL);
|
gameTxtOver[i]->SetMaxWidth(maxTextWidth, SCROLL_HORIZONTAL);
|
||||||
|
|
||||||
gameBg[i] = new GuiImage(bgGamesEntry);
|
gameBg[i] = new GuiImage(bgGamesEntry);
|
||||||
|
|
||||||
newImg[i] = new GuiImage(newGames);
|
newImg[i] = new GuiImage(newGames);
|
||||||
newImg[i]->SetAlignment(ALIGN_RIGHT, ALIGN_MIDDLE);
|
newImg[i]->SetAlignment(ALIGN_RIGHT, ALIGN_MIDDLE);
|
||||||
newImg[i]->SetVisible(false);
|
newImg[i]->SetVisible(false);
|
||||||
|
|
||||||
game[i] = new GuiButton(width - scrollBar.GetWidth(), GAMESELECTSIZE);
|
game[i] = new GuiButton(width - scrollBar.GetWidth(), GAMESELECTSIZE);
|
||||||
game[i]->SetParent(this);
|
game[i]->SetParent(this);
|
||||||
game[i]->SetLabel(gameTxt[i]);
|
game[i]->SetLabel(gameTxt[i]);
|
||||||
game[i]->SetLabelOver(gameTxtOver[i]);
|
game[i]->SetLabelOver(gameTxtOver[i]);
|
||||||
game[i]->SetIcon(newImg[i]);
|
game[i]->SetIcon(newImg[i]);
|
||||||
game[i]->SetImageOver(gameBg[i]);
|
game[i]->SetImageOver(gameBg[i]);
|
||||||
game[i]->SetPosition(5, GAMESELECTSIZE * i + 4);
|
game[i]->SetPosition(5, GAMESELECTSIZE * i + 4);
|
||||||
game[i]->SetRumble(false);
|
game[i]->SetRumble(false);
|
||||||
game[i]->SetTrigger(trigA);
|
game[i]->SetTrigger(trigA);
|
||||||
game[i]->SetSoundClick(btnSoundClick);
|
game[i]->SetSoundClick(btnSoundClick);
|
||||||
game[i]->SetVisible(false);
|
game[i]->SetVisible(false);
|
||||||
game[i]->SetState(STATE_DISABLED);
|
game[i]->SetState(STATE_DISABLED);
|
||||||
}
|
}
|
||||||
UpdateListEntries();
|
UpdateListEntries();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -109,75 +109,75 @@ GuiGameList::GuiGameList(int w, int h, int offset)
|
||||||
*/
|
*/
|
||||||
GuiGameList::~GuiGameList()
|
GuiGameList::~GuiGameList()
|
||||||
{
|
{
|
||||||
delete bgGameImg;
|
delete bgGameImg;
|
||||||
delete bgGames;
|
delete bgGames;
|
||||||
delete bgGamesEntry;
|
delete bgGamesEntry;
|
||||||
delete newGames;
|
delete newGames;
|
||||||
|
|
||||||
delete trigA;
|
delete trigA;
|
||||||
|
|
||||||
for (int i = 0; i < pagesize; ++i)
|
for (int i = 0; i < pagesize; ++i)
|
||||||
{
|
{
|
||||||
delete gameTxt[i];
|
delete gameTxt[i];
|
||||||
delete gameTxtOver[i];
|
delete gameTxtOver[i];
|
||||||
delete gameBg[i];
|
delete gameBg[i];
|
||||||
delete game[i];
|
delete game[i];
|
||||||
delete newImg[i];
|
delete newImg[i];
|
||||||
}
|
}
|
||||||
delete[] game;
|
delete[] game;
|
||||||
delete[] gameTxt;
|
delete[] gameTxt;
|
||||||
delete[] gameTxtOver;
|
delete[] gameTxtOver;
|
||||||
delete[] gameBg;
|
delete[] gameBg;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuiGameList::SetFocus(int f)
|
void GuiGameList::SetFocus(int f)
|
||||||
{
|
{
|
||||||
LOCK( this );
|
LOCK( this );
|
||||||
if (!gameList.size()) return;
|
if (!gameList.size()) return;
|
||||||
|
|
||||||
focus = f;
|
focus = f;
|
||||||
|
|
||||||
for (int i = 0; i < pagesize; ++i)
|
for (int i = 0; i < pagesize; ++i)
|
||||||
game[i]->ResetState();
|
game[i]->ResetState();
|
||||||
|
|
||||||
if (f == 1) game[selectedItem]->SetState(STATE_SELECTED);
|
if (f == 1) game[selectedItem]->SetState(STATE_SELECTED);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuiGameList::ResetState()
|
void GuiGameList::ResetState()
|
||||||
{
|
{
|
||||||
LOCK( this );
|
LOCK( this );
|
||||||
if (state != STATE_DISABLED)
|
if (state != STATE_DISABLED)
|
||||||
{
|
{
|
||||||
state = STATE_DEFAULT;
|
state = STATE_DEFAULT;
|
||||||
stateChan = -1;
|
stateChan = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < pagesize; ++i)
|
for (int i = 0; i < pagesize; ++i)
|
||||||
{
|
{
|
||||||
game[i]->ResetState();
|
game[i]->ResetState();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int GuiGameList::GetClickedOption()
|
int GuiGameList::GetClickedOption()
|
||||||
{
|
{
|
||||||
int found = -1;
|
int found = -1;
|
||||||
for (int i = 0; i < pagesize; ++i)
|
for (int i = 0; i < pagesize; ++i)
|
||||||
{
|
{
|
||||||
if (game[i]->GetState() == STATE_CLICKED)
|
if (game[i]->GetState() == STATE_CLICKED)
|
||||||
{
|
{
|
||||||
game[i]->SetState(STATE_SELECTED);
|
game[i]->SetState(STATE_SELECTED);
|
||||||
found = listOffset + i;
|
found = listOffset + i;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return found;
|
return found;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuiGameList::onListChange(int SelItem, int SelInd)
|
void GuiGameList::onListChange(int SelItem, int SelInd)
|
||||||
{
|
{
|
||||||
selectedItem = SelItem;
|
selectedItem = SelItem;
|
||||||
listOffset = SelInd;
|
listOffset = SelInd;
|
||||||
UpdateListEntries();
|
UpdateListEntries();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuiGameList::setListOffset(int off)
|
void GuiGameList::setListOffset(int off)
|
||||||
|
@ -197,85 +197,85 @@ void GuiGameList::SetSelectedOption(int ind)
|
||||||
*/
|
*/
|
||||||
void GuiGameList::Draw()
|
void GuiGameList::Draw()
|
||||||
{
|
{
|
||||||
LOCK( this );
|
LOCK( this );
|
||||||
if (!this->IsVisible() || !gameList.size()) return;
|
if (!this->IsVisible() || !gameList.size()) return;
|
||||||
|
|
||||||
bgGameImg->Draw();
|
bgGameImg->Draw();
|
||||||
|
|
||||||
for (int i = 0, next = listOffset; i < pagesize; ++i, ++next)
|
for (int i = 0, next = listOffset; i < pagesize; ++i, ++next)
|
||||||
{
|
{
|
||||||
if (next < gameList.size())
|
if (next < gameList.size())
|
||||||
game[i]->Draw();
|
game[i]->Draw();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (scrollbaron == 1)
|
if (scrollbaron == 1)
|
||||||
scrollBar.Draw();
|
scrollBar.Draw();
|
||||||
|
|
||||||
this->UpdateEffects();
|
this->UpdateEffects();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuiGameList::UpdateListEntries()
|
void GuiGameList::UpdateListEntries()
|
||||||
{
|
{
|
||||||
for (int i = 0, next = listOffset; i < pagesize; ++i, ++next)
|
for (int i = 0, next = listOffset; i < pagesize; ++i, ++next)
|
||||||
{
|
{
|
||||||
if (next < gameList.size())
|
if (next < gameList.size())
|
||||||
{
|
{
|
||||||
if (game[i]->GetState() == STATE_DISABLED)
|
if (game[i]->GetState() == STATE_DISABLED)
|
||||||
{
|
{
|
||||||
game[i]->SetVisible(true);
|
game[i]->SetVisible(true);
|
||||||
game[i]->SetState(STATE_DEFAULT);
|
game[i]->SetState(STATE_DEFAULT);
|
||||||
}
|
}
|
||||||
gameTxt[i]->SetText(GameTitles.GetTitle(gameList[next]));
|
gameTxt[i]->SetText(GameTitles.GetTitle(gameList[next]));
|
||||||
gameTxt[i]->SetPosition(24, 0);
|
gameTxt[i]->SetPosition(24, 0);
|
||||||
gameTxtOver[i]->SetText(GameTitles.GetTitle(gameList[next]));
|
gameTxtOver[i]->SetText(GameTitles.GetTitle(gameList[next]));
|
||||||
gameTxtOver[i]->SetPosition(24, 0);
|
gameTxtOver[i]->SetPosition(24, 0);
|
||||||
|
|
||||||
if (Settings.marknewtitles)
|
if (Settings.marknewtitles)
|
||||||
{
|
{
|
||||||
bool isNew = NewTitles::Instance()->IsNew(gameList[next]->id);
|
bool isNew = NewTitles::Instance()->IsNew(gameList[next]->id);
|
||||||
if (isNew)
|
if (isNew)
|
||||||
{
|
{
|
||||||
gameTxt[i]->SetMaxWidth(maxTextWidth - (newGames->GetWidth() + 1), DOTTED);
|
gameTxt[i]->SetMaxWidth(maxTextWidth - (newGames->GetWidth() + 1), DOTTED);
|
||||||
gameTxtOver[i]->SetMaxWidth(maxTextWidth - (newGames->GetWidth() + 1), SCROLL_HORIZONTAL);
|
gameTxtOver[i]->SetMaxWidth(maxTextWidth - (newGames->GetWidth() + 1), SCROLL_HORIZONTAL);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
gameTxt[i]->SetMaxWidth(maxTextWidth, DOTTED);
|
gameTxt[i]->SetMaxWidth(maxTextWidth, DOTTED);
|
||||||
gameTxtOver[i]->SetMaxWidth(maxTextWidth, SCROLL_HORIZONTAL);
|
gameTxtOver[i]->SetMaxWidth(maxTextWidth, SCROLL_HORIZONTAL);
|
||||||
}
|
}
|
||||||
newImg[i]->SetVisible(isNew);
|
newImg[i]->SetVisible(isNew);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
game[i]->SetVisible(false);
|
game[i]->SetVisible(false);
|
||||||
game[i]->SetState(STATE_DISABLED);
|
game[i]->SetState(STATE_DISABLED);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuiGameList::Update(GuiTrigger * t)
|
void GuiGameList::Update(GuiTrigger * t)
|
||||||
{
|
{
|
||||||
LOCK( this );
|
LOCK( this );
|
||||||
if (state == STATE_DISABLED || !t || !gameList.size()) return;
|
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 |
|
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)) ||
|
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)))
|
(t->pad.btns_d & (PAD_BUTTON_UP | PAD_BUTTON_DOWN)))
|
||||||
pressedChan = t->chan;
|
pressedChan = t->chan;
|
||||||
|
|
||||||
if (scrollbaron == 1)
|
if (scrollbaron == 1)
|
||||||
// update the location of the scroll box based on the position in the option list
|
// update the location of the scroll box based on the position in the option list
|
||||||
scrollBar.Update(t);
|
scrollBar.Update(t);
|
||||||
|
|
||||||
if(pressedChan == -1 || (!t->wpad.btns_h && !t->pad.btns_h))
|
if(pressedChan == -1 || (!t->wpad.btns_h && !t->pad.btns_h))
|
||||||
{
|
{
|
||||||
for (int i = 0, next = listOffset; i < pagesize; ++i, ++next)
|
for (int i = 0, next = listOffset; i < pagesize; ++i, ++next)
|
||||||
{
|
{
|
||||||
if (next >= gameList.size())
|
if (next >= gameList.size())
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if (i != selectedItem && game[i]->GetState() == STATE_SELECTED)
|
if (i != selectedItem && game[i]->GetState() == STATE_SELECTED)
|
||||||
game[i]->ResetState();
|
game[i]->ResetState();
|
||||||
|
@ -286,17 +286,17 @@ void GuiGameList::Update(GuiTrigger * t)
|
||||||
|
|
||||||
if (game[i]->GetState() == STATE_SELECTED)
|
if (game[i]->GetState() == STATE_SELECTED)
|
||||||
selectedItem = i;
|
selectedItem = i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(pressedChan == t->chan && !t->wpad.btns_d && !t->wpad.btns_h)
|
if(pressedChan == t->chan && !t->wpad.btns_d && !t->wpad.btns_h)
|
||||||
pressedChan = -1;
|
pressedChan = -1;
|
||||||
|
|
||||||
scrollBar.SetPageSize(pagesize);
|
scrollBar.SetPageSize(pagesize);
|
||||||
scrollBar.SetSelectedItem(selectedItem);
|
scrollBar.SetSelectedItem(selectedItem);
|
||||||
scrollBar.SetSelectedIndex(listOffset);
|
scrollBar.SetSelectedIndex(listOffset);
|
||||||
scrollBar.SetEntrieCount(gameList.size());
|
scrollBar.SetEntrieCount(gameList.size());
|
||||||
|
|
||||||
if (updateCB) updateCB(this);
|
if (updateCB) updateCB(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,41 +7,41 @@
|
||||||
|
|
||||||
class GuiGameList : public GuiGameBrowser, public sigslot::has_slots<>
|
class GuiGameList : public GuiGameBrowser, public sigslot::has_slots<>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
GuiGameList(int w, int h, int listOffset = 0);
|
GuiGameList(int w, int h, int listOffset = 0);
|
||||||
virtual ~GuiGameList();
|
virtual ~GuiGameList();
|
||||||
int GetClickedOption();
|
int GetClickedOption();
|
||||||
int GetSelectedOption() { return listOffset+selectedItem; }
|
int GetSelectedOption() { return listOffset+selectedItem; }
|
||||||
void SetSelectedOption(int ind);
|
void SetSelectedOption(int ind);
|
||||||
void setListOffset(int off);
|
void setListOffset(int off);
|
||||||
int getListOffset() const { return listOffset; }
|
int getListOffset() const { return listOffset; }
|
||||||
void ResetState();
|
void ResetState();
|
||||||
void SetFocus(int f);
|
void SetFocus(int f);
|
||||||
void Draw();
|
void Draw();
|
||||||
void Update(GuiTrigger * t);
|
void Update(GuiTrigger * t);
|
||||||
protected:
|
protected:
|
||||||
void onListChange(int SelItem, int SelInd);
|
void onListChange(int SelItem, int SelInd);
|
||||||
void UpdateListEntries();
|
void UpdateListEntries();
|
||||||
int selectedItem;
|
int selectedItem;
|
||||||
int listOffset;
|
int listOffset;
|
||||||
int scrollbaron;
|
int scrollbaron;
|
||||||
int pagesize;
|
int pagesize;
|
||||||
int maxTextWidth;
|
int maxTextWidth;
|
||||||
|
|
||||||
GuiButton ** game;
|
GuiButton ** game;
|
||||||
GuiText ** gameTxt;
|
GuiText ** gameTxt;
|
||||||
GuiText ** gameTxtOver;
|
GuiText ** gameTxtOver;
|
||||||
GuiImage ** gameBg;
|
GuiImage ** gameBg;
|
||||||
GuiImage ** newImg;
|
GuiImage ** newImg;
|
||||||
|
|
||||||
GuiImage * bgGameImg;
|
GuiImage * bgGameImg;
|
||||||
|
|
||||||
GuiImageData * bgGames;
|
GuiImageData * bgGames;
|
||||||
GuiImageData * bgGamesEntry;
|
GuiImageData * bgGamesEntry;
|
||||||
GuiImageData * newGames;
|
GuiImageData * newGames;
|
||||||
|
|
||||||
GuiTrigger * trigA;
|
GuiTrigger * trigA;
|
||||||
|
|
||||||
GuiScrollbar scrollBar;
|
GuiScrollbar scrollBar;
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -15,200 +15,200 @@
|
||||||
*/
|
*/
|
||||||
GuiImage::GuiImage()
|
GuiImage::GuiImage()
|
||||||
{
|
{
|
||||||
image = NULL;
|
image = NULL;
|
||||||
width = 0;
|
width = 0;
|
||||||
height = 0;
|
height = 0;
|
||||||
imageangle = 0;
|
imageangle = 0;
|
||||||
tileHorizontal = -1;
|
tileHorizontal = -1;
|
||||||
tileVertical = -1;
|
tileVertical = -1;
|
||||||
stripe = 0;
|
stripe = 0;
|
||||||
widescreen = 0;
|
widescreen = 0;
|
||||||
xx1 = 0;
|
xx1 = 0;
|
||||||
yy1 = 0;
|
yy1 = 0;
|
||||||
xx2 = 0;
|
xx2 = 0;
|
||||||
yy2 = 0;
|
yy2 = 0;
|
||||||
xx3 = 0;
|
xx3 = 0;
|
||||||
yy3 = 0;
|
yy3 = 0;
|
||||||
xx4 = 0;
|
xx4 = 0;
|
||||||
yy4 = 0;
|
yy4 = 0;
|
||||||
imgType = IMAGE_DATA;
|
imgType = IMAGE_DATA;
|
||||||
}
|
}
|
||||||
|
|
||||||
GuiImage::GuiImage(GuiImageData * img)
|
GuiImage::GuiImage(GuiImageData * img)
|
||||||
{
|
{
|
||||||
if (img)
|
if (img)
|
||||||
{
|
{
|
||||||
image = img->GetImage();
|
image = img->GetImage();
|
||||||
width = img->GetWidth();
|
width = img->GetWidth();
|
||||||
height = img->GetHeight();
|
height = img->GetHeight();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
image = NULL;
|
image = NULL;
|
||||||
width = 0;
|
width = 0;
|
||||||
height = 0;
|
height = 0;
|
||||||
}
|
}
|
||||||
imageangle = 0;
|
imageangle = 0;
|
||||||
tileHorizontal = -1;
|
tileHorizontal = -1;
|
||||||
tileVertical = -1;
|
tileVertical = -1;
|
||||||
stripe = 0;
|
stripe = 0;
|
||||||
widescreen = 0;
|
widescreen = 0;
|
||||||
parentangle = true;
|
parentangle = true;
|
||||||
xx1 = 0;
|
xx1 = 0;
|
||||||
yy1 = 0;
|
yy1 = 0;
|
||||||
xx2 = 0;
|
xx2 = 0;
|
||||||
yy2 = 0;
|
yy2 = 0;
|
||||||
xx3 = 0;
|
xx3 = 0;
|
||||||
yy3 = 0;
|
yy3 = 0;
|
||||||
xx4 = 0;
|
xx4 = 0;
|
||||||
yy4 = 0;
|
yy4 = 0;
|
||||||
imgType = IMAGE_DATA;
|
imgType = IMAGE_DATA;
|
||||||
}
|
}
|
||||||
|
|
||||||
GuiImage::GuiImage(u8 * img, int w, int h)
|
GuiImage::GuiImage(u8 * img, int w, int h)
|
||||||
{
|
{
|
||||||
image = img;
|
image = img;
|
||||||
width = w;
|
width = w;
|
||||||
height = h;
|
height = h;
|
||||||
imageangle = 0;
|
imageangle = 0;
|
||||||
tileHorizontal = -1;
|
tileHorizontal = -1;
|
||||||
tileVertical = -1;
|
tileVertical = -1;
|
||||||
stripe = 0;
|
stripe = 0;
|
||||||
widescreen = 0;
|
widescreen = 0;
|
||||||
parentangle = true;
|
parentangle = true;
|
||||||
xx1 = 0;
|
xx1 = 0;
|
||||||
yy1 = 0;
|
yy1 = 0;
|
||||||
xx2 = 0;
|
xx2 = 0;
|
||||||
yy2 = 0;
|
yy2 = 0;
|
||||||
xx3 = 0;
|
xx3 = 0;
|
||||||
yy3 = 0;
|
yy3 = 0;
|
||||||
xx4 = 0;
|
xx4 = 0;
|
||||||
yy4 = 0;
|
yy4 = 0;
|
||||||
imgType = IMAGE_TEXTURE;
|
imgType = IMAGE_TEXTURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
GuiImage::GuiImage(int w, int h, GXColor c)
|
GuiImage::GuiImage(int w, int h, GXColor c)
|
||||||
{
|
{
|
||||||
image = (u8 *) memalign(32, w * h * 4);
|
image = (u8 *) memalign(32, w * h * 4);
|
||||||
width = w;
|
width = w;
|
||||||
height = h;
|
height = h;
|
||||||
imageangle = 0;
|
imageangle = 0;
|
||||||
tileHorizontal = -1;
|
tileHorizontal = -1;
|
||||||
tileVertical = -1;
|
tileVertical = -1;
|
||||||
stripe = 0;
|
stripe = 0;
|
||||||
widescreen = 0;
|
widescreen = 0;
|
||||||
parentangle = true;
|
parentangle = true;
|
||||||
xx1 = 0;
|
xx1 = 0;
|
||||||
yy1 = 0;
|
yy1 = 0;
|
||||||
xx2 = 0;
|
xx2 = 0;
|
||||||
yy2 = 0;
|
yy2 = 0;
|
||||||
xx3 = 0;
|
xx3 = 0;
|
||||||
yy3 = 0;
|
yy3 = 0;
|
||||||
xx4 = 0;
|
xx4 = 0;
|
||||||
yy4 = 0;
|
yy4 = 0;
|
||||||
imgType = IMAGE_COLOR;
|
imgType = IMAGE_COLOR;
|
||||||
|
|
||||||
if (!image) return;
|
if (!image) return;
|
||||||
|
|
||||||
int x, y;
|
int x, y;
|
||||||
|
|
||||||
for (y = 0; y < h; y++)
|
for (y = 0; y < h; y++)
|
||||||
{
|
{
|
||||||
for (x = 0; x < w; x++)
|
for (x = 0; x < w; x++)
|
||||||
{
|
{
|
||||||
this->SetPixel(x, y, c);
|
this->SetPixel(x, y, c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
int len = w * h * 4;
|
int len = w * h * 4;
|
||||||
if (len % 32) len += (32 - len % 32);
|
if (len % 32) len += (32 - len % 32);
|
||||||
DCFlushRange(image, len);
|
DCFlushRange(image, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
GuiImage::GuiImage(GuiImage &srcimage) :
|
GuiImage::GuiImage(GuiImage &srcimage) :
|
||||||
GuiElement()
|
GuiElement()
|
||||||
{
|
{
|
||||||
width = srcimage.GetWidth();
|
width = srcimage.GetWidth();
|
||||||
height = srcimage.GetHeight();
|
height = srcimage.GetHeight();
|
||||||
int len = width * height * 4;
|
int len = width * height * 4;
|
||||||
if (len % 32) len += (32 - len % 32);
|
if (len % 32) len += (32 - len % 32);
|
||||||
image = (u8 *) memalign(32, len);
|
image = (u8 *) memalign(32, len);
|
||||||
memcpy(image, srcimage.GetImage(), len);
|
memcpy(image, srcimage.GetImage(), len);
|
||||||
DCFlushRange(image, len);
|
DCFlushRange(image, len);
|
||||||
imageangle = srcimage.GetAngle();
|
imageangle = srcimage.GetAngle();
|
||||||
tileHorizontal = -1;
|
tileHorizontal = -1;
|
||||||
tileVertical = -1;
|
tileVertical = -1;
|
||||||
stripe = 0;
|
stripe = 0;
|
||||||
widescreen = 0;
|
widescreen = 0;
|
||||||
parentangle = true;
|
parentangle = true;
|
||||||
xx1 = 0;
|
xx1 = 0;
|
||||||
yy1 = 0;
|
yy1 = 0;
|
||||||
xx2 = 0;
|
xx2 = 0;
|
||||||
yy2 = 0;
|
yy2 = 0;
|
||||||
xx3 = 0;
|
xx3 = 0;
|
||||||
yy3 = 0;
|
yy3 = 0;
|
||||||
xx4 = 0;
|
xx4 = 0;
|
||||||
yy4 = 0;
|
yy4 = 0;
|
||||||
imgType = IMAGE_COPY;
|
imgType = IMAGE_COPY;
|
||||||
}
|
}
|
||||||
|
|
||||||
GuiImage::GuiImage(GuiImage *srcimage) :
|
GuiImage::GuiImage(GuiImage *srcimage) :
|
||||||
GuiElement()
|
GuiElement()
|
||||||
{
|
{
|
||||||
width = srcimage->GetWidth();
|
width = srcimage->GetWidth();
|
||||||
height = srcimage->GetHeight();
|
height = srcimage->GetHeight();
|
||||||
int len = width * height * 4;
|
int len = width * height * 4;
|
||||||
if (len % 32) len += (32 - len % 32);
|
if (len % 32) len += (32 - len % 32);
|
||||||
image = (u8 *) memalign(32, len);
|
image = (u8 *) memalign(32, len);
|
||||||
memcpy(image, srcimage->GetImage(), len);
|
memcpy(image, srcimage->GetImage(), len);
|
||||||
DCFlushRange(image, len);
|
DCFlushRange(image, len);
|
||||||
imageangle = srcimage->GetAngle();
|
imageangle = srcimage->GetAngle();
|
||||||
tileHorizontal = -1;
|
tileHorizontal = -1;
|
||||||
tileVertical = -1;
|
tileVertical = -1;
|
||||||
stripe = 0;
|
stripe = 0;
|
||||||
widescreen = 0;
|
widescreen = 0;
|
||||||
parentangle = true;
|
parentangle = true;
|
||||||
xx1 = 0;
|
xx1 = 0;
|
||||||
yy1 = 0;
|
yy1 = 0;
|
||||||
xx2 = 0;
|
xx2 = 0;
|
||||||
yy2 = 0;
|
yy2 = 0;
|
||||||
xx3 = 0;
|
xx3 = 0;
|
||||||
yy3 = 0;
|
yy3 = 0;
|
||||||
xx4 = 0;
|
xx4 = 0;
|
||||||
yy4 = 0;
|
yy4 = 0;
|
||||||
imgType = IMAGE_COPY;
|
imgType = IMAGE_COPY;
|
||||||
}
|
}
|
||||||
|
|
||||||
GuiImage &GuiImage::operator=(GuiImage & srcimage)
|
GuiImage &GuiImage::operator=(GuiImage & srcimage)
|
||||||
{
|
{
|
||||||
if ((imgType == IMAGE_COLOR || imgType == IMAGE_COPY) && image)
|
if ((imgType == IMAGE_COLOR || imgType == IMAGE_COPY) && image)
|
||||||
{
|
{
|
||||||
free(image);
|
free(image);
|
||||||
image = NULL;
|
image = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
width = srcimage.GetWidth();
|
width = srcimage.GetWidth();
|
||||||
height = srcimage.GetHeight();
|
height = srcimage.GetHeight();
|
||||||
int len = width * height * 4;
|
int len = width * height * 4;
|
||||||
if (len % 32) len += (32 - len % 32);
|
if (len % 32) len += (32 - len % 32);
|
||||||
image = (u8 *) memalign(32, len);
|
image = (u8 *) memalign(32, len);
|
||||||
memcpy(image, srcimage.GetImage(), len);
|
memcpy(image, srcimage.GetImage(), len);
|
||||||
DCFlushRange(image, len);
|
DCFlushRange(image, len);
|
||||||
imageangle = srcimage.GetAngle();
|
imageangle = srcimage.GetAngle();
|
||||||
tileHorizontal = -1;
|
tileHorizontal = -1;
|
||||||
tileVertical = -1;
|
tileVertical = -1;
|
||||||
stripe = 0;
|
stripe = 0;
|
||||||
widescreen = 0;
|
widescreen = 0;
|
||||||
parentangle = true;
|
parentangle = true;
|
||||||
xx1 = 0;
|
xx1 = 0;
|
||||||
yy1 = 0;
|
yy1 = 0;
|
||||||
xx2 = 0;
|
xx2 = 0;
|
||||||
yy2 = 0;
|
yy2 = 0;
|
||||||
xx3 = 0;
|
xx3 = 0;
|
||||||
yy3 = 0;
|
yy3 = 0;
|
||||||
xx4 = 0;
|
xx4 = 0;
|
||||||
yy4 = 0;
|
yy4 = 0;
|
||||||
imgType = IMAGE_COPY;
|
imgType = IMAGE_COPY;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -216,222 +216,222 @@ GuiImage &GuiImage::operator=(GuiImage & srcimage)
|
||||||
*/
|
*/
|
||||||
GuiImage::~GuiImage()
|
GuiImage::~GuiImage()
|
||||||
{
|
{
|
||||||
if ((imgType == IMAGE_COLOR || imgType == IMAGE_COPY) && image)
|
if ((imgType == IMAGE_COLOR || imgType == IMAGE_COPY) && image)
|
||||||
{
|
{
|
||||||
free(image);
|
free(image);
|
||||||
image = NULL;
|
image = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
u8 * GuiImage::GetImage()
|
u8 * GuiImage::GetImage()
|
||||||
{
|
{
|
||||||
return image;
|
return image;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuiImage::SetImage(GuiImageData * img)
|
void GuiImage::SetImage(GuiImageData * img)
|
||||||
{
|
{
|
||||||
LOCK( this );
|
LOCK( this );
|
||||||
if ((imgType == IMAGE_COLOR || imgType == IMAGE_COPY) && image)
|
if ((imgType == IMAGE_COLOR || imgType == IMAGE_COPY) && image)
|
||||||
{
|
{
|
||||||
free(image);
|
free(image);
|
||||||
image = NULL;
|
image = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
image = NULL;
|
image = NULL;
|
||||||
width = 0;
|
width = 0;
|
||||||
height = 0;
|
height = 0;
|
||||||
imgType = IMAGE_DATA;
|
imgType = IMAGE_DATA;
|
||||||
|
|
||||||
if(img)
|
if(img)
|
||||||
{
|
{
|
||||||
image = img->GetImage();
|
image = img->GetImage();
|
||||||
width = img->GetWidth();
|
width = img->GetWidth();
|
||||||
height = img->GetHeight();
|
height = img->GetHeight();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuiImage::SetImage(u8 * img, int w, int h)
|
void GuiImage::SetImage(u8 * img, int w, int h)
|
||||||
{
|
{
|
||||||
LOCK( this );
|
LOCK( this );
|
||||||
if ((imgType == IMAGE_COLOR || imgType == IMAGE_COPY) && image)
|
if ((imgType == IMAGE_COLOR || imgType == IMAGE_COPY) && image)
|
||||||
{
|
{
|
||||||
free(image);
|
free(image);
|
||||||
image = NULL;
|
image = NULL;
|
||||||
}
|
}
|
||||||
image = img;
|
image = img;
|
||||||
width = w;
|
width = w;
|
||||||
height = h;
|
height = h;
|
||||||
imgType = IMAGE_TEXTURE;
|
imgType = IMAGE_TEXTURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuiImage::SetAngle(float a)
|
void GuiImage::SetAngle(float a)
|
||||||
{
|
{
|
||||||
LOCK( this );
|
LOCK( this );
|
||||||
imageangle = a;
|
imageangle = a;
|
||||||
}
|
}
|
||||||
float GuiImage::GetAngle()
|
float GuiImage::GetAngle()
|
||||||
{
|
{
|
||||||
return imageangle;
|
return imageangle;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuiImage::SetTileHorizontal(int t)
|
void GuiImage::SetTileHorizontal(int t)
|
||||||
{
|
{
|
||||||
LOCK( this );
|
LOCK( this );
|
||||||
tileHorizontal = t;
|
tileHorizontal = t;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuiImage::SetTileVertical(int t)
|
void GuiImage::SetTileVertical(int t)
|
||||||
{
|
{
|
||||||
LOCK( this );
|
LOCK( this );
|
||||||
tileVertical = t;
|
tileVertical = t;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuiImage::SetWidescreen(bool w)
|
void GuiImage::SetWidescreen(bool w)
|
||||||
{
|
{
|
||||||
LOCK( this );
|
LOCK( this );
|
||||||
widescreen = w;
|
widescreen = w;
|
||||||
}
|
}
|
||||||
void GuiImage::SetParentAngle(bool a)
|
void GuiImage::SetParentAngle(bool a)
|
||||||
{
|
{
|
||||||
LOCK( this );
|
LOCK( this );
|
||||||
parentangle = a;
|
parentangle = a;
|
||||||
}
|
}
|
||||||
|
|
||||||
GXColor GuiImage::GetPixel(int x, int y)
|
GXColor GuiImage::GetPixel(int x, int y)
|
||||||
{
|
{
|
||||||
if (!image || this->GetWidth() <= 0 || x < 0 || y < 0) return ( GXColor )
|
if (!image || this->GetWidth() <= 0 || x < 0 || y < 0) return ( GXColor )
|
||||||
{ 0, 0, 0, 0};
|
{ 0, 0, 0, 0};
|
||||||
|
|
||||||
u32 offset = (((y >> 2) << 4) * this->GetWidth()) + ((x >> 2) << 6) + (((y % 4 << 2) + x % 4) << 1);
|
u32 offset = (((y >> 2) << 4) * this->GetWidth()) + ((x >> 2) << 6) + (((y % 4 << 2) + x % 4) << 1);
|
||||||
GXColor color;
|
GXColor color;
|
||||||
color.a = *(image + offset);
|
color.a = *(image + offset);
|
||||||
color.r = *(image + offset + 1);
|
color.r = *(image + offset + 1);
|
||||||
color.g = *(image + offset + 32);
|
color.g = *(image + offset + 32);
|
||||||
color.b = *(image + offset + 33);
|
color.b = *(image + offset + 33);
|
||||||
return color;
|
return color;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuiImage::SetPixel(int x, int y, GXColor color)
|
void GuiImage::SetPixel(int x, int y, GXColor color)
|
||||||
{
|
{
|
||||||
LOCK( this );
|
LOCK( this );
|
||||||
if (!image || this->GetWidth() <= 0 || x < 0 || y < 0) return;
|
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);
|
u32 offset = (((y >> 2) << 4) * this->GetWidth()) + ((x >> 2) << 6) + (((y % 4 << 2) + x % 4) << 1);
|
||||||
*(image + offset) = color.a;
|
*(image + offset) = color.a;
|
||||||
*(image + offset + 1) = color.r;
|
*(image + offset + 1) = color.r;
|
||||||
*(image + offset + 32) = color.g;
|
*(image + offset + 32) = color.g;
|
||||||
*(image + offset + 33) = color.b;
|
*(image + offset + 33) = color.b;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuiImage::SetGrayscale(void)
|
void GuiImage::SetGrayscale(void)
|
||||||
{
|
{
|
||||||
LOCK( this );
|
LOCK( this );
|
||||||
GXColor color;
|
GXColor color;
|
||||||
u32 offset, gray;
|
u32 offset, gray;
|
||||||
|
|
||||||
for (int x = 0; x < width; x++)
|
for (int x = 0; x < width; x++)
|
||||||
{
|
{
|
||||||
for (int y = 0; y < height; y++)
|
for (int y = 0; y < height; y++)
|
||||||
{
|
{
|
||||||
offset = (((y >> 2) << 4) * width) + ((x >> 2) << 6) + (((y % 4 << 2) + x % 4) << 1);
|
offset = (((y >> 2) << 4) * width) + ((x >> 2) << 6) + (((y % 4 << 2) + x % 4) << 1);
|
||||||
color.r = *(image + offset + 1);
|
color.r = *(image + offset + 1);
|
||||||
color.g = *(image + offset + 32);
|
color.g = *(image + offset + 32);
|
||||||
color.b = *(image + offset + 33);
|
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 + 1) = gray;
|
||||||
*(image + offset + 32) = gray;
|
*(image + offset + 32) = gray;
|
||||||
*(image + offset + 33) = gray;
|
*(image + offset + 33) = gray;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int len = width * height * 4;
|
int len = width * height * 4;
|
||||||
if (len % 32) len += (32 - len % 32);
|
if (len % 32) len += (32 - len % 32);
|
||||||
DCFlushRange(image, len);
|
DCFlushRange(image, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuiImage::SetStripe(int s)
|
void GuiImage::SetStripe(int s)
|
||||||
{
|
{
|
||||||
LOCK( this );
|
LOCK( this );
|
||||||
stripe = s;
|
stripe = s;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuiImage::SetSkew(int XX1, int YY1, int XX2, int YY2, int XX3, int YY3, int XX4, int YY4)
|
void GuiImage::SetSkew(int XX1, int YY1, int XX2, int YY2, int XX3, int YY3, int XX4, int YY4)
|
||||||
{
|
{
|
||||||
|
|
||||||
xx1 = XX1;
|
xx1 = XX1;
|
||||||
yy1 = YY1;
|
yy1 = YY1;
|
||||||
xx2 = XX2;
|
xx2 = XX2;
|
||||||
yy2 = YY2;
|
yy2 = YY2;
|
||||||
xx3 = XX3;
|
xx3 = XX3;
|
||||||
yy3 = YY3;
|
yy3 = YY3;
|
||||||
xx4 = XX4;
|
xx4 = XX4;
|
||||||
yy4 = YY4;
|
yy4 = YY4;
|
||||||
}
|
}
|
||||||
void GuiImage::SetSkew(int *skew)
|
void GuiImage::SetSkew(int *skew)
|
||||||
{
|
{
|
||||||
|
|
||||||
xx1 = *skew++;
|
xx1 = *skew++;
|
||||||
yy1 = *skew++;
|
yy1 = *skew++;
|
||||||
xx2 = *skew++;
|
xx2 = *skew++;
|
||||||
yy2 = *skew++;
|
yy2 = *skew++;
|
||||||
xx3 = *skew++;
|
xx3 = *skew++;
|
||||||
yy3 = *skew++;
|
yy3 = *skew++;
|
||||||
xx4 = *skew++;
|
xx4 = *skew++;
|
||||||
yy4 = *skew;
|
yy4 = *skew;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuiImage::ColorStripe(int shift)
|
void GuiImage::ColorStripe(int shift)
|
||||||
{
|
{
|
||||||
LOCK( this );
|
LOCK( this );
|
||||||
int x, y;
|
int x, y;
|
||||||
GXColor color;
|
GXColor color;
|
||||||
int alt = 0;
|
int alt = 0;
|
||||||
|
|
||||||
for (y = 0; y < this->GetHeight(); y++)
|
for (y = 0; y < this->GetHeight(); y++)
|
||||||
{
|
{
|
||||||
if (y % 3 == 0) alt ^= 1;
|
if (y % 3 == 0) alt ^= 1;
|
||||||
|
|
||||||
for (x = 0; x < this->GetWidth(); x++)
|
for (x = 0; x < this->GetWidth(); x++)
|
||||||
{
|
{
|
||||||
color = GetPixel(x, y);
|
color = GetPixel(x, y);
|
||||||
|
|
||||||
if (alt)
|
if (alt)
|
||||||
{
|
{
|
||||||
if (color.r < 255 - shift)
|
if (color.r < 255 - shift)
|
||||||
color.r += shift;
|
color.r += shift;
|
||||||
else color.r = 255;
|
else color.r = 255;
|
||||||
if (color.g < 255 - shift)
|
if (color.g < 255 - shift)
|
||||||
color.g += shift;
|
color.g += shift;
|
||||||
else color.g = 255;
|
else color.g = 255;
|
||||||
if (color.b < 255 - shift)
|
if (color.b < 255 - shift)
|
||||||
color.b += shift;
|
color.b += shift;
|
||||||
else color.b = 255;
|
else color.b = 255;
|
||||||
|
|
||||||
color.a = 255;
|
color.a = 255;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (color.r > shift)
|
if (color.r > shift)
|
||||||
color.r -= shift;
|
color.r -= shift;
|
||||||
else color.r = 0;
|
else color.r = 0;
|
||||||
if (color.g > shift)
|
if (color.g > shift)
|
||||||
color.g -= shift;
|
color.g -= shift;
|
||||||
else color.g = 0;
|
else color.g = 0;
|
||||||
if (color.b > shift)
|
if (color.b > shift)
|
||||||
color.b -= shift;
|
color.b -= shift;
|
||||||
else color.b = 0;
|
else color.b = 0;
|
||||||
|
|
||||||
color.a = 255;
|
color.a = 255;
|
||||||
}
|
}
|
||||||
SetPixel(x, y, color);
|
SetPixel(x, y, color);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int len = width * height * 4;
|
int len = width * height * 4;
|
||||||
if (len % 32) len += (32 - len % 32);
|
if (len % 32) len += (32 - len % 32);
|
||||||
DCFlushRange(image, len);
|
DCFlushRange(image, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -440,42 +440,42 @@ void GuiImage::ColorStripe(int shift)
|
||||||
|
|
||||||
void GuiImage::Draw()
|
void GuiImage::Draw()
|
||||||
{
|
{
|
||||||
LOCK( this );
|
LOCK( this );
|
||||||
if (!image || !this->IsVisible() || tileHorizontal == 0) return;
|
if (!image || !this->IsVisible() || tileHorizontal == 0) return;
|
||||||
|
|
||||||
float currScale = this->GetScale();
|
float currScale = this->GetScale();
|
||||||
int currLeft = this->GetLeft();
|
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)
|
if (tileHorizontal > 0)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < tileHorizontal; i++)
|
for (int i = 0; i < tileHorizontal; i++)
|
||||||
Menu_DrawImg(currLeft + width * i, this->GetTop(), zoffset, width, height, image, imageangle,
|
Menu_DrawImg(currLeft + width * i, this->GetTop(), zoffset, width, height, image, imageangle,
|
||||||
widescreen ? currScale * Settings.WSFactor : currScale, currScale, this->GetAlpha(), xx1,
|
widescreen ? currScale * Settings.WSFactor : currScale, currScale, this->GetAlpha(), xx1,
|
||||||
yy1, xx2, yy2, xx3, yy3, xx4, yy4);
|
yy1, xx2, yy2, xx3, yy3, xx4, yy4);
|
||||||
}
|
}
|
||||||
else if(tileVertical > 0)
|
else if(tileVertical > 0)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < tileVertical; i++)
|
for (int i = 0; i < tileVertical; i++)
|
||||||
Menu_DrawImg(currLeft, this->GetTop() + height * i, zoffset, width, height, image, imageangle,
|
Menu_DrawImg(currLeft, this->GetTop() + height * i, zoffset, width, height, image, imageangle,
|
||||||
widescreen ? currScale * Settings.WSFactor : currScale, currScale, this->GetAlpha(), xx1,
|
widescreen ? currScale * Settings.WSFactor : currScale, currScale, this->GetAlpha(), xx1,
|
||||||
yy1, xx2, yy2, xx3, yy3, xx4, yy4);
|
yy1, xx2, yy2, xx3, yy3, xx4, yy4);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// temporary (maybe), used to correct offset for scaled images
|
// temporary (maybe), used to correct offset for scaled images
|
||||||
if (scale != 1) currLeft = currLeft - width / 2 + (width * scale) / 2;
|
if (scale != 1) currLeft = currLeft - width / 2 + (width * scale) / 2;
|
||||||
|
|
||||||
Menu_DrawImg(currLeft, this->GetTop(), zoffset, width, height, image, imageangle, widescreen ? currScale * Settings.WSFactor
|
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);
|
: currScale, currScale, this->GetAlpha(), xx1, yy1, xx2, yy2, xx3, yy3, xx4, yy4);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (stripe > 0) for (int y = 0; y < this->GetHeight(); y += 6)
|
if (stripe > 0) for (int y = 0; y < this->GetHeight(); y += 6)
|
||||||
Menu_DrawRectangle(currLeft, this->GetTop() + y, this->GetWidth(), 3, ( GXColor )
|
Menu_DrawRectangle(currLeft, this->GetTop() + y, this->GetWidth(), 3, ( GXColor )
|
||||||
{ 0, 0, 0, stripe}, 1);
|
{ 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)
|
static inline void * memdup(const void* src, size_t len)
|
||||||
{
|
{
|
||||||
if(!src) return NULL;
|
if(!src) return NULL;
|
||||||
|
|
||||||
void *dst = malloc(len);
|
void *dst = malloc(len);
|
||||||
if (dst) memcpy(dst, src, len);
|
if (dst) memcpy(dst, src, len);
|
||||||
return dst;
|
return dst;
|
||||||
}
|
}
|
||||||
|
|
||||||
static GuiImageData * StdImageLoaderCallback(void *arg)
|
static GuiImageData * StdImageLoaderCallback(void *arg)
|
||||||
{
|
{
|
||||||
return new GuiImageData((char *) arg);
|
return new GuiImageData((char *) arg);
|
||||||
}
|
}
|
||||||
|
|
||||||
GuiImageAsync::GuiImageAsync(const char *Filename, GuiImageData * PreloadImg) :
|
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();
|
ThreadInit();
|
||||||
ThreadAddImage(this);
|
ThreadAddImage(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
GuiImageAsync::GuiImageAsync(ImageLoaderCallback Callback, const void * Arg, int ArgLen, GuiImageData * PreloadImg) :
|
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();
|
ThreadInit();
|
||||||
ThreadAddImage(this);
|
ThreadAddImage(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
GuiImageAsync::~GuiImageAsync()
|
GuiImageAsync::~GuiImageAsync()
|
||||||
{
|
{
|
||||||
ThreadRemoveImage(this);
|
ThreadRemoveImage(this);
|
||||||
ThreadExit();
|
ThreadExit();
|
||||||
while(InUse == this) usleep(100);
|
while(InUse == this) usleep(100);
|
||||||
if (imgData) delete imgData;
|
if (imgData) delete imgData;
|
||||||
if (arg) free(arg);
|
if (arg) free(arg);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuiImageAsync::ThreadAddImage(GuiImageAsync *Image)
|
void GuiImageAsync::ThreadAddImage(GuiImageAsync *Image)
|
||||||
{
|
{
|
||||||
LWP_MutexLock(ListLock);
|
LWP_MutexLock(ListLock);
|
||||||
List.push_back(Image);
|
List.push_back(Image);
|
||||||
LWP_MutexUnlock(ListLock);
|
LWP_MutexUnlock(ListLock);
|
||||||
ThreadSleep = false;
|
ThreadSleep = false;
|
||||||
LWP_ResumeThread(Thread);
|
LWP_ResumeThread(Thread);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuiImageAsync::ThreadRemoveImage(GuiImageAsync *Image)
|
void GuiImageAsync::ThreadRemoveImage(GuiImageAsync *Image)
|
||||||
{
|
{
|
||||||
for(u32 i = 0; i < List.size(); ++i)
|
for(u32 i = 0; i < List.size(); ++i)
|
||||||
{
|
{
|
||||||
if(List[i] == Image)
|
if(List[i] == Image)
|
||||||
{
|
{
|
||||||
LWP_MutexLock(ListLock);
|
LWP_MutexLock(ListLock);
|
||||||
List.erase(List.begin()+i);
|
List.erase(List.begin()+i);
|
||||||
LWP_MutexUnlock(ListLock);
|
LWP_MutexUnlock(ListLock);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuiImageAsync::ClearQueue()
|
void GuiImageAsync::ClearQueue()
|
||||||
{
|
{
|
||||||
LWP_MutexLock(ListLock);
|
LWP_MutexLock(ListLock);
|
||||||
List.clear();
|
List.clear();
|
||||||
LWP_MutexUnlock(ListLock);
|
LWP_MutexUnlock(ListLock);
|
||||||
}
|
}
|
||||||
|
|
||||||
void * GuiImageAsync::GuiImageAsyncThread(void *arg)
|
void * GuiImageAsync::GuiImageAsyncThread(void *arg)
|
||||||
{
|
{
|
||||||
while(!CloseThread)
|
while(!CloseThread)
|
||||||
{
|
{
|
||||||
if(ThreadSleep)
|
if(ThreadSleep)
|
||||||
LWP_SuspendThread(Thread);
|
LWP_SuspendThread(Thread);
|
||||||
|
|
||||||
while(!List.empty() && !CloseThread)
|
while(!List.empty() && !CloseThread)
|
||||||
{
|
{
|
||||||
LWP_MutexLock(ListLock);
|
LWP_MutexLock(ListLock);
|
||||||
InUse = List.front();
|
InUse = List.front();
|
||||||
List.erase(List.begin());
|
List.erase(List.begin());
|
||||||
LWP_MutexUnlock(ListLock);
|
LWP_MutexUnlock(ListLock);
|
||||||
|
|
||||||
if (!InUse)
|
if (!InUse)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
InUse->imgData = InUse->callback(InUse->arg);
|
InUse->imgData = InUse->callback(InUse->arg);
|
||||||
|
|
||||||
if (InUse->imgData && InUse->imgData->GetImage())
|
if (InUse->imgData && InUse->imgData->GetImage())
|
||||||
{
|
{
|
||||||
InUse->width = InUse->imgData->GetWidth();
|
InUse->width = InUse->imgData->GetWidth();
|
||||||
InUse->height = InUse->imgData->GetHeight();
|
InUse->height = InUse->imgData->GetHeight();
|
||||||
InUse->image = InUse->imgData->GetImage();
|
InUse->image = InUse->imgData->GetImage();
|
||||||
}
|
}
|
||||||
|
|
||||||
InUse = NULL;
|
InUse = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
ThreadSleep = true;
|
ThreadSleep = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
u32 GuiImageAsync::ThreadInit()
|
u32 GuiImageAsync::ThreadInit()
|
||||||
{
|
{
|
||||||
if (Thread == LWP_THREAD_NULL)
|
if (Thread == LWP_THREAD_NULL)
|
||||||
{
|
{
|
||||||
LWP_MutexInit(&ListLock, false);
|
LWP_MutexInit(&ListLock, false);
|
||||||
LWP_CreateThread(&Thread, GuiImageAsyncThread, NULL, NULL, 32768, 80);
|
LWP_CreateThread(&Thread, GuiImageAsyncThread, NULL, NULL, 32768, 80);
|
||||||
}
|
}
|
||||||
return ++ThreadCount;
|
return ++ThreadCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
u32 GuiImageAsync::ThreadExit()
|
u32 GuiImageAsync::ThreadExit()
|
||||||
{
|
{
|
||||||
//! We don't need to always shutdown and startup the thread, especially
|
//! We don't need to always shutdown and startup the thread, especially
|
||||||
//! since this is a nested startup/shutdown from the gui thread.
|
//! since this is a nested startup/shutdown from the gui thread.
|
||||||
//! It's fine with being put to suspended only.
|
//! It's fine with being put to suspended only.
|
||||||
/*
|
/*
|
||||||
if (--ThreadCount == 0)
|
if (--ThreadCount == 0)
|
||||||
{
|
{
|
||||||
CloseThread = true;
|
CloseThread = true;
|
||||||
LWP_ResumeThread(Thread);
|
LWP_ResumeThread(Thread);
|
||||||
LWP_JoinThread(Thread, NULL);
|
LWP_JoinThread(Thread, NULL);
|
||||||
LWP_MutexUnlock(ListLock);
|
LWP_MutexUnlock(ListLock);
|
||||||
LWP_MutexDestroy(ListLock);
|
LWP_MutexDestroy(ListLock);
|
||||||
Thread = LWP_THREAD_NULL;
|
Thread = LWP_THREAD_NULL;
|
||||||
ListLock = LWP_MUTEX_NULL;
|
ListLock = LWP_MUTEX_NULL;
|
||||||
ListLock = LWP_MUTEX_NULL;
|
ListLock = LWP_MUTEX_NULL;
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
return --ThreadCount;
|
return --ThreadCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,30 +8,30 @@ typedef GuiImageData * (*ImageLoaderCallback)(void *arg);
|
||||||
|
|
||||||
class GuiImageAsync: public GuiImage
|
class GuiImageAsync: public GuiImage
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
GuiImageAsync(const char *Filename, GuiImageData * PreloadImg);
|
GuiImageAsync(const char *Filename, GuiImageData * PreloadImg);
|
||||||
GuiImageAsync(ImageLoaderCallback Callback, const void *Arg, int ArgLen, GuiImageData * PreloadImg);
|
GuiImageAsync(ImageLoaderCallback Callback, const void *Arg, int ArgLen, GuiImageData * PreloadImg);
|
||||||
virtual ~GuiImageAsync();
|
virtual ~GuiImageAsync();
|
||||||
|
|
||||||
static void ClearQueue();
|
static void ClearQueue();
|
||||||
private:
|
private:
|
||||||
GuiImageData *imgData;
|
GuiImageData *imgData;
|
||||||
ImageLoaderCallback callback;
|
ImageLoaderCallback callback;
|
||||||
void *arg;
|
void *arg;
|
||||||
|
|
||||||
static void * GuiImageAsyncThread(void *arg);
|
static void * GuiImageAsyncThread(void *arg);
|
||||||
static void ThreadAddImage(GuiImageAsync* Image);
|
static void ThreadAddImage(GuiImageAsync* Image);
|
||||||
static void ThreadRemoveImage(GuiImageAsync* Image);
|
static void ThreadRemoveImage(GuiImageAsync* Image);
|
||||||
static u32 ThreadInit();
|
static u32 ThreadInit();
|
||||||
static u32 ThreadExit();
|
static u32 ThreadExit();
|
||||||
|
|
||||||
static std::vector<GuiImageAsync *> List;
|
static std::vector<GuiImageAsync *> List;
|
||||||
static lwp_t Thread;
|
static lwp_t Thread;
|
||||||
static mutex_t ListLock;
|
static mutex_t ListLock;
|
||||||
static GuiImageAsync * InUse;
|
static GuiImageAsync * InUse;
|
||||||
static u32 ThreadCount;
|
static u32 ThreadCount;
|
||||||
static bool ThreadSleep;
|
static bool ThreadSleep;
|
||||||
static bool CloseThread;
|
static bool CloseThread;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /*_GUIIMAGEASYNC_H_*/
|
#endif /*_GUIIMAGEASYNC_H_*/
|
||||||
|
|
|
@ -41,16 +41,16 @@ GuiImageData::GuiImageData(const char * filepath)
|
||||||
height = 0;
|
height = 0;
|
||||||
format = GX_TF_RGBA8;
|
format = GX_TF_RGBA8;
|
||||||
|
|
||||||
u8 *buffer = NULL;
|
u8 *buffer = NULL;
|
||||||
u64 size = 0;
|
u64 size = 0;
|
||||||
|
|
||||||
if(LoadFileToMem(filepath, &buffer, &size) < 0)
|
if(LoadFileToMem(filepath, &buffer, &size) < 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
LoadImage(buffer, size);
|
LoadImage(buffer, size);
|
||||||
|
|
||||||
if(buffer)
|
if(buffer)
|
||||||
free(buffer);
|
free(buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
GuiImageData::GuiImageData(const u8 * img, int imgSize, bool cache)
|
GuiImageData::GuiImageData(const u8 * img, int imgSize, bool cache)
|
||||||
|
@ -60,30 +60,30 @@ GuiImageData::GuiImageData(const u8 * img, int imgSize, bool cache)
|
||||||
height = 0;
|
height = 0;
|
||||||
format = GX_TF_RGBA8;
|
format = GX_TF_RGBA8;
|
||||||
|
|
||||||
if(cache)
|
if(cache)
|
||||||
{
|
{
|
||||||
ImageData * Image = ResourceManager::GetImageData(img);
|
ImageData * Image = ResourceManager::GetImageData(img);
|
||||||
if(Image != NULL && Image->data != NULL)
|
if(Image != NULL && Image->data != NULL)
|
||||||
{
|
{
|
||||||
data = Image->data;
|
data = Image->data;
|
||||||
width = Image->width;
|
width = Image->width;
|
||||||
height = Image->height;
|
height = Image->height;
|
||||||
format = Image->format;
|
format = Image->format;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
LoadImage(img, imgSize);
|
LoadImage(img, imgSize);
|
||||||
|
|
||||||
if(data && cache)
|
if(data && cache)
|
||||||
{
|
{
|
||||||
ImageData NewImage;
|
ImageData NewImage;
|
||||||
NewImage.data = data;
|
NewImage.data = data;
|
||||||
NewImage.width = width;
|
NewImage.width = width;
|
||||||
NewImage.height = height;
|
NewImage.height = height;
|
||||||
NewImage.format = format;
|
NewImage.format = format;
|
||||||
ResourceManager::AddImageData(img, NewImage);
|
ResourceManager::AddImageData(img, NewImage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -91,105 +91,105 @@ GuiImageData::GuiImageData(const u8 * img, int imgSize, bool cache)
|
||||||
*/
|
*/
|
||||||
GuiImageData::~GuiImageData()
|
GuiImageData::~GuiImageData()
|
||||||
{
|
{
|
||||||
if(data)
|
if(data)
|
||||||
ResourceManager::Remove(data);
|
ResourceManager::Remove(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuiImageData::LoadImage(const u8 * img, int imgSize)
|
void GuiImageData::LoadImage(const u8 * img, int imgSize)
|
||||||
{
|
{
|
||||||
if(!img)
|
if(!img)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
else if (imgSize < 8)
|
else if (imgSize < 8)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else if (img[0] == 0x89 && img[1] == 'P' && img[2] == 'N' && img[3] == 'G')
|
else if (img[0] == 0x89 && img[1] == 'P' && img[2] == 'N' && img[3] == 'G')
|
||||||
{
|
{
|
||||||
// IMAGE_PNG
|
// IMAGE_PNG
|
||||||
LoadPNG(img, imgSize);
|
LoadPNG(img, imgSize);
|
||||||
}
|
}
|
||||||
else if (img[0] == 0xFF && img[1] == 0xD8)
|
else if (img[0] == 0xFF && img[1] == 0xD8)
|
||||||
{
|
{
|
||||||
// IMAGE_JPEG
|
// IMAGE_JPEG
|
||||||
LoadJpeg(img, imgSize);
|
LoadJpeg(img, imgSize);
|
||||||
}
|
}
|
||||||
else if (img[0] == 'B' && img[1] == 'M')
|
else if (img[0] == 'B' && img[1] == 'M')
|
||||||
{
|
{
|
||||||
// IMAGE_BMP
|
// IMAGE_BMP
|
||||||
LoadBMP(img, imgSize);
|
LoadBMP(img, imgSize);
|
||||||
}
|
}
|
||||||
else if (img[0] == 'G' && img[1] == 'I' && img[2] == 'F')
|
else if (img[0] == 'G' && img[1] == 'I' && img[2] == 'F')
|
||||||
{
|
{
|
||||||
// IMAGE_GIF
|
// IMAGE_GIF
|
||||||
LoadGIF(img, imgSize);
|
LoadGIF(img, imgSize);
|
||||||
}
|
}
|
||||||
else if (img[0] == 0x00 && img[1] == 0x20 && img[2] == 0xAF && img[3] == 0x30)
|
else if (img[0] == 0x00 && img[1] == 0x20 && img[2] == 0xAF && img[3] == 0x30)
|
||||||
{
|
{
|
||||||
// IMAGE_TPL
|
// IMAGE_TPL
|
||||||
LoadTPL(img, imgSize);
|
LoadTPL(img, imgSize);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuiImageData::LoadPNG(const u8 *img, int imgSize)
|
void GuiImageData::LoadPNG(const u8 *img, int imgSize)
|
||||||
{
|
{
|
||||||
gdImagePtr gdImg = gdImageCreateFromPngPtr(imgSize, (u8*) img);
|
gdImagePtr gdImg = gdImageCreateFromPngPtr(imgSize, (u8*) img);
|
||||||
if(gdImg == 0)
|
if(gdImg == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
data = GDImageToRGBA8(&gdImg, &width, &height);
|
data = GDImageToRGBA8(&gdImg, &width, &height);
|
||||||
gdImageDestroy(gdImg);
|
gdImageDestroy(gdImg);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuiImageData::LoadJpeg(const u8 *img, int imgSize)
|
void GuiImageData::LoadJpeg(const u8 *img, int imgSize)
|
||||||
{
|
{
|
||||||
gdImagePtr gdImg = gdImageCreateFromJpegPtr(imgSize, (u8*) img);
|
gdImagePtr gdImg = gdImageCreateFromJpegPtr(imgSize, (u8*) img);
|
||||||
if(gdImg == 0)
|
if(gdImg == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
data = GDImageToRGBA8(&gdImg, &width, &height);
|
data = GDImageToRGBA8(&gdImg, &width, &height);
|
||||||
gdImageDestroy(gdImg);
|
gdImageDestroy(gdImg);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuiImageData::LoadGIF(const u8 *img, int imgSize)
|
void GuiImageData::LoadGIF(const u8 *img, int imgSize)
|
||||||
{
|
{
|
||||||
gdImagePtr gdImg = gdImageCreateFromGifPtr(imgSize, (u8*) img);
|
gdImagePtr gdImg = gdImageCreateFromGifPtr(imgSize, (u8*) img);
|
||||||
if(gdImg == 0)
|
if(gdImg == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
data = GDImageToRGBA8(&gdImg, &width, &height);
|
data = GDImageToRGBA8(&gdImg, &width, &height);
|
||||||
gdImageDestroy(gdImg);
|
gdImageDestroy(gdImg);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuiImageData::LoadBMP(const u8 *img, int imgSize)
|
void GuiImageData::LoadBMP(const u8 *img, int imgSize)
|
||||||
{
|
{
|
||||||
gdImagePtr gdImg = gdImageCreateFromBmpPtr(imgSize, (u8*) img);
|
gdImagePtr gdImg = gdImageCreateFromBmpPtr(imgSize, (u8*) img);
|
||||||
if(gdImg == 0)
|
if(gdImg == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
data = GDImageToRGBA8(&gdImg, &width, &height);
|
data = GDImageToRGBA8(&gdImg, &width, &height);
|
||||||
gdImageDestroy(gdImg);
|
gdImageDestroy(gdImg);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuiImageData::LoadTPL(const u8 *img, int imgSize)
|
void GuiImageData::LoadTPL(const u8 *img, int imgSize)
|
||||||
{
|
{
|
||||||
TplImage TplFile(img, imgSize);
|
TplImage TplFile(img, imgSize);
|
||||||
|
|
||||||
width = TplFile.GetWidth(0);
|
width = TplFile.GetWidth(0);
|
||||||
height = TplFile.GetHeight(0);
|
height = TplFile.GetHeight(0);
|
||||||
format = (u8) TplFile.GetFormat(0);
|
format = (u8) TplFile.GetFormat(0);
|
||||||
|
|
||||||
const u8 * ImgPtr = TplFile.GetTextureBuffer(0);
|
const u8 * ImgPtr = TplFile.GetTextureBuffer(0);
|
||||||
|
|
||||||
if(ImgPtr)
|
if(ImgPtr)
|
||||||
{
|
{
|
||||||
int len = ALIGN32(TplFile.GetTextureSize(0));
|
int len = ALIGN32(TplFile.GetTextureSize(0));
|
||||||
|
|
||||||
data = (u8 *) memalign(32, len);
|
data = (u8 *) memalign(32, len);
|
||||||
if(!data)
|
if(!data)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
memcpy(data, ImgPtr, len);
|
memcpy(data, ImgPtr, len);
|
||||||
DCFlushRange(data, len);
|
DCFlushRange(data, len);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,7 +38,7 @@ class GuiImageData
|
||||||
//!\param cache True if the resource manager should cache that address
|
//!\param cache True if the resource manager should cache that address
|
||||||
GuiImageData(const u8 * img, int imgSize, bool cache = true);
|
GuiImageData(const u8 * img, int imgSize, bool cache = true);
|
||||||
//!Overload
|
//!Overload
|
||||||
GuiImageData(const char * filepath);
|
GuiImageData(const char * filepath);
|
||||||
//!Destructor
|
//!Destructor
|
||||||
~GuiImageData();
|
~GuiImageData();
|
||||||
//!Gets a pointer to the image data
|
//!Gets a pointer to the image data
|
||||||
|
@ -53,7 +53,7 @@ class GuiImageData
|
||||||
//!Gets the texture format
|
//!Gets the texture format
|
||||||
u8 GetTextureFormat() { return format; };
|
u8 GetTextureFormat() { return format; };
|
||||||
protected:
|
protected:
|
||||||
void LoadImage(const u8 * img, int imgSize);
|
void LoadImage(const u8 * img, int imgSize);
|
||||||
void LoadPNG(const u8 *img, int imgSize);
|
void LoadPNG(const u8 *img, int imgSize);
|
||||||
void LoadBMP(const u8 *img, int imgSize);
|
void LoadBMP(const u8 *img, int imgSize);
|
||||||
void LoadJpeg(const u8 *img, int imgSize);
|
void LoadJpeg(const u8 *img, int imgSize);
|
||||||
|
|
|
@ -22,26 +22,26 @@ unsigned int m;
|
||||||
//const Key thekeys;
|
//const Key thekeys;
|
||||||
GuiKeyboard::GuiKeyboard(char * t, u32 max, int min, int lang)
|
GuiKeyboard::GuiKeyboard(char * t, u32 max, int min, int lang)
|
||||||
{
|
{
|
||||||
width = 540;
|
width = 540;
|
||||||
height = 400;
|
height = 400;
|
||||||
shift = 0;
|
shift = 0;
|
||||||
caps = 0;
|
caps = 0;
|
||||||
alt = 0;
|
alt = 0;
|
||||||
alt2 = 0;
|
alt2 = 0;
|
||||||
m = min;
|
m = min;
|
||||||
int mode = lang;
|
int mode = lang;
|
||||||
selectable = true;
|
selectable = true;
|
||||||
focus = 0; // allow focus
|
focus = 0; // allow focus
|
||||||
alignmentHor = ALIGN_CENTRE;
|
alignmentHor = ALIGN_CENTRE;
|
||||||
alignmentVert = ALIGN_MIDDLE;
|
alignmentVert = ALIGN_MIDDLE;
|
||||||
kbtextmaxlen = max > sizeof(kbtextstr) ? sizeof(kbtextstr) : max; // limit max up to sizeof(kbtextstr)
|
kbtextmaxlen = max > sizeof(kbtextstr) ? sizeof(kbtextstr) : max; // limit max up to sizeof(kbtextstr)
|
||||||
// strlcpy(kbtextstr, t, kbtextmaxlen);
|
// strlcpy(kbtextstr, t, kbtextmaxlen);
|
||||||
strncpy(kbtextstr, t, kbtextmaxlen); // strncpy is needed to fill the rest with \0
|
strncpy(kbtextstr, t, kbtextmaxlen); // strncpy is needed to fill the rest with \0
|
||||||
kbtextstr[sizeof(kbtextstr) - 1] = 0; // terminate with \0
|
kbtextstr[sizeof(kbtextstr) - 1] = 0; // terminate with \0
|
||||||
//QWERTY//
|
//QWERTY//
|
||||||
if (mode == 0)
|
if (mode == 0)
|
||||||
{
|
{
|
||||||
Key thekeys[4][11] = {
|
Key thekeys[4][11] = {
|
||||||
{
|
{
|
||||||
{ '1', '!', '\0', '\0' },
|
{ '1', '!', '\0', '\0' },
|
||||||
{ '2', '@', '\0', '\0' },
|
{ '2', '@', '\0', '\0' },
|
||||||
|
@ -89,19 +89,19 @@ GuiKeyboard::GuiKeyboard(char * t, u32 max, int min, int lang)
|
||||||
{ 'b', 'B', '\0', '\0' },
|
{ 'b', 'B', '\0', '\0' },
|
||||||
{ 'n', 'N', '\0', '\0' },
|
{ 'n', 'N', '\0', '\0' },
|
||||||
{ 'm', 'M', '\0', '\0' },
|
{ 'm', 'M', '\0', '\0' },
|
||||||
{ ',', '<', '\0', '\0' },
|
{ ',', '<', '\0', '\0' },
|
||||||
{ '.', '>', '\0', '\0' },
|
{ '.', '>', '\0', '\0' },
|
||||||
{ '/', '?', '\0', '\0' },
|
{ '/', '?', '\0', '\0' },
|
||||||
{ '\0', '\0', '\0', '\0' }
|
{ '\0', '\0', '\0', '\0' }
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
memcpy(keys, thekeys, sizeof(thekeys));
|
memcpy(keys, thekeys, sizeof(thekeys));
|
||||||
}
|
}
|
||||||
//DVORAK//
|
//DVORAK//
|
||||||
if (mode == 1)
|
if (mode == 1)
|
||||||
{
|
{
|
||||||
Key thekeys[4][11] = {
|
Key thekeys[4][11] = {
|
||||||
{
|
{
|
||||||
{ '1', '!', '\0', '\0' },
|
{ '1', '!', '\0', '\0' },
|
||||||
{ '2', '@', '\0', '\0' },
|
{ '2', '@', '\0', '\0' },
|
||||||
|
@ -155,263 +155,263 @@ GuiKeyboard::GuiKeyboard(char * t, u32 max, int min, int lang)
|
||||||
{ '\0', '\0', '\0', '\0' }
|
{ '\0', '\0', '\0', '\0' }
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
memcpy(keys, thekeys, sizeof(thekeys));
|
memcpy(keys, thekeys, sizeof(thekeys));
|
||||||
}
|
}
|
||||||
//QWETRZ//
|
//QWETRZ//
|
||||||
if (mode == 2)
|
if (mode == 2)
|
||||||
{
|
{
|
||||||
Key thekeys[4][11] = { { { '1', '!', '^', 'À' }, { '2', '"', '²', 'à' }, { '3', '#', '³', 'È' }, { '4', '$',
|
Key thekeys[4][11] = { { { '1', '!', '^', 'À' }, { '2', '"', '²', 'à' }, { '3', '#', '³', 'È' }, { '4', '$',
|
||||||
'«', 'è' }, { '5', '%', '»', 'Ì' }, { '6', '&', '„', 'ì' }, { '7', '/', '”', 'Ò' }, { '8', '(', '[',
|
'«', 'è' }, { '5', '%', '»', 'Ì' }, { '6', '&', '„', 'ì' }, { '7', '/', '”', 'Ò' }, { '8', '(', '[',
|
||||||
'ò' }, { '9', ')', ']', 'Ù' }, { '0', '=', '§', 'ù' }, { 'ß', '?', '\'', 'Ý' } }, { { 'q', 'Q', '@',
|
'ò' }, { '9', ')', ']', 'Ù' }, { '0', '=', '§', 'ù' }, { 'ß', '?', '\'', 'Ý' } }, { { 'q', 'Q', '@',
|
||||||
'Á' }, { 'w', 'W', '\0', 'á' }, { 'e', 'E', '€', 'É' }, { 'r', 'R', '\0', 'é' },
|
'Á' }, { 'w', 'W', '\0', 'á' }, { 'e', 'E', '€', 'É' }, { 'r', 'R', '\0', 'é' },
|
||||||
{ 't', 'T', '\0', 'Í' }, { 'z', 'Z', '\0', 'í' }, { 'u', 'U', '\0', 'Ó' }, { 'i', 'I', '\0', 'ó' }, {
|
{ 't', 'T', '\0', 'Í' }, { 'z', 'Z', '\0', 'í' }, { 'u', 'U', '\0', 'Ó' }, { 'i', 'I', '\0', 'ó' }, {
|
||||||
'o', 'O', '\0', 'Ú' }, { 'p', 'P', '\0', 'ú' }, { 'ü', 'Ü', '\0', 'ý' } }, { { 'a', 'A', '\0',
|
'o', 'O', '\0', 'Ú' }, { 'p', 'P', '\0', 'ú' }, { 'ü', 'Ü', '\0', 'ý' } }, { { 'a', 'A', '\0',
|
||||||
'Â' }, { 's', 'S', '\0', 'â' }, { 'd', 'D', '\0', 'Ê' }, { 'f', 'F', '\0', 'ê' },
|
'Â' }, { 's', 'S', '\0', 'â' }, { 'd', 'D', '\0', 'Ê' }, { 'f', 'F', '\0', 'ê' },
|
||||||
{ 'g', 'G', '\0', 'Î' }, { 'h', 'H', '\0', 'î' }, { 'j', 'J', '\0', 'Ô' }, { 'k', 'K', '\0', 'ô' }, {
|
{ 'g', 'G', '\0', 'Î' }, { 'h', 'H', '\0', 'î' }, { 'j', 'J', '\0', 'Ô' }, { 'k', 'K', '\0', 'ô' }, {
|
||||||
'l', 'L', '\0', 'Û' }, { 'ö', 'Ö', '\0', 'û' }, { 'ä', 'Ä', '\0', 'Ÿ' } }, { { '<', '>', '|',
|
'l', 'L', '\0', 'Û' }, { 'ö', 'Ö', '\0', 'û' }, { 'ä', 'Ä', '\0', 'Ÿ' } }, { { '<', '>', '|',
|
||||||
'Ã' }, { 'y', 'Y', '\0', 'ã' }, { 'x', 'X', '\0', 'Ñ' }, { 'c', 'C', 'ç', 'ñ' },
|
'Ã' }, { 'y', 'Y', '\0', 'ã' }, { 'x', 'X', '\0', 'Ñ' }, { 'c', 'C', 'ç', 'ñ' },
|
||||||
{ 'v', 'V', '©', 'Ï' }, { 'b', 'B', '\0', 'ï' }, { 'n', 'N', '\0', 'Õ' }, { 'm', 'M', 'µ', 'õ' }, {
|
{ 'v', 'V', '©', 'Ï' }, { 'b', 'B', '\0', 'ï' }, { 'n', 'N', '\0', 'Õ' }, { 'm', 'M', 'µ', 'õ' }, {
|
||||||
',', ';', '\0', 'ÿ' }, { '.', ':', '\0', '\0' }, { '-', '_', '\0', '\0' } } };
|
',', ';', '\0', 'ÿ' }, { '.', ':', '\0', '\0' }, { '-', '_', '\0', '\0' } } };
|
||||||
memcpy(keys, thekeys, sizeof(thekeys));
|
memcpy(keys, thekeys, sizeof(thekeys));
|
||||||
}
|
}
|
||||||
//AZERTY//
|
//AZERTY//
|
||||||
if (mode == 3)
|
if (mode == 3)
|
||||||
{
|
{
|
||||||
Key thekeys[4][11] = { { { '1', '&', '²', 'À' }, { '2', '~', '³', 'é' }, { '3', '"', '#', 'È' }, { '4', '`',
|
Key thekeys[4][11] = { { { '1', '&', '²', 'À' }, { '2', '~', '³', 'é' }, { '3', '"', '#', 'È' }, { '4', '`',
|
||||||
'«', 'ù' }, { '5', '(', '[', 'Ì' }, { '6', '-', '|', 'ì' }, { '7', 'µ', '»', 'è' }, { '8', '_', '\'',
|
'«', 'ù' }, { '5', '(', '[', 'Ì' }, { '6', '-', '|', 'ì' }, { '7', 'µ', '»', 'è' }, { '8', '_', '\'',
|
||||||
'ò' }, { '9', '+', '^', 'ç' }, { '0', '=', '@', 'à' }, { '°', ')', ']', 'Ý' } }, {
|
'ò' }, { '9', '+', '^', 'ç' }, { '0', '=', '@', 'à' }, { '°', ')', ']', 'Ý' } }, {
|
||||||
{ 'a', 'A', 'Æ', 'Á' }, { 'z', 'Z', 'Œ', 'á' }, { 'e', 'E', '€', 'É' }, { 'r', 'R', '®', 'ë' }, { 't',
|
{ 'a', 'A', 'Æ', 'Á' }, { 'z', 'Z', 'Œ', 'á' }, { 'e', 'E', '€', 'É' }, { 'r', 'R', '®', 'ë' }, { 't',
|
||||||
'T', '†', 'Í' }, { 'y', 'Y', 'ÿ', 'í' }, { 'u', 'U', 'Õ', 'Ó' }, { 'i', 'I', 'õ', 'Ò' }, { 'o',
|
'T', '†', 'Í' }, { 'y', 'Y', 'ÿ', 'í' }, { 'u', 'U', 'Õ', 'Ó' }, { 'i', 'I', 'õ', 'Ò' }, { 'o',
|
||||||
'O', 'Ø', 'Ú' }, { 'p', 'P', 'ø', 'ú' }, { '$', '£', '¤', 'ý' } }, { { 'q', 'Q', 'æ', 'Â' }, {
|
'O', 'Ø', 'Ú' }, { 'p', 'P', 'ø', 'ú' }, { '$', '£', '¤', 'ý' } }, { { 'q', 'Q', 'æ', 'Â' }, {
|
||||||
's', 'S', 'œ', 'â' }, { 'd', 'D', '\0', 'Ê' }, { 'f', 'F', 'ß', 'ê' }, { 'g', 'G', '\0', 'Î' }, { 'h',
|
's', 'S', 'œ', 'â' }, { 'd', 'D', '\0', 'Ê' }, { 'f', 'F', 'ß', 'ê' }, { 'g', 'G', '\0', 'Î' }, { 'h',
|
||||||
'H', '\0', 'î' }, { 'j', 'J', '\0', 'Ô' }, { 'k', 'K', '\0', 'ô' }, { 'l', 'L', '\0', 'Û' }, { 'm',
|
'H', '\0', 'î' }, { 'j', 'J', '\0', 'Ô' }, { 'k', 'K', '\0', 'ô' }, { 'l', 'L', '\0', 'Û' }, { 'm',
|
||||||
'M', '\0', 'û' }, { '*', '%', '¬', 'Ù' } }, { { '<', '>', '\0', 'Ã' }, { 'w', 'W', '\0', 'Ä' }, { 'x',
|
'M', '\0', 'û' }, { '*', '%', '¬', 'Ù' } }, { { '<', '>', '\0', 'Ã' }, { 'w', 'W', '\0', 'Ä' }, { 'x',
|
||||||
'X', '\0', 'Ë' }, { 'c', 'C', '©', 'Ç' }, { 'v', 'V', '“', 'Ï' }, { 'b', 'B', '”', 'ï' }, { 'n', 'N',
|
'X', '\0', 'Ë' }, { 'c', 'C', '©', 'Ç' }, { 'v', 'V', '“', 'Ï' }, { 'b', 'B', '”', 'ï' }, { 'n', 'N',
|
||||||
'\0', 'Ñ' }, { '?', ',', '?', 'ñ' }, { '.', ';', '.', 'ó' }, { '/', ':', '/', 'ö' }, { '§', '!', '!',
|
'\0', 'Ñ' }, { '?', ',', '?', 'ñ' }, { '.', ';', '.', 'ó' }, { '/', ':', '/', 'ö' }, { '§', '!', '!',
|
||||||
'Ö' } } };
|
'Ö' } } };
|
||||||
memcpy(keys, thekeys, sizeof(thekeys));
|
memcpy(keys, thekeys, sizeof(thekeys));
|
||||||
}
|
}
|
||||||
//QWERTY 2//
|
//QWERTY 2//
|
||||||
if (mode == 4)
|
if (mode == 4)
|
||||||
{
|
{
|
||||||
Key thekeys[4][11] = { { { '1', '!', '|', 'Á' }, { '2', '"', '@', 'á' }, { '3', '·', '#', 'À' }, { '4', '$',
|
Key thekeys[4][11] = { { { '1', '!', '|', 'Á' }, { '2', '"', '@', 'á' }, { '3', '·', '#', 'À' }, { '4', '$',
|
||||||
'£', 'à' }, { '5', '%', '~', 'É' }, { '6', '&', '¬', 'é' }, { '7', '/', '\'', 'È' }, { '8', '(', '[',
|
'£', 'à' }, { '5', '%', '~', 'É' }, { '6', '&', '¬', 'é' }, { '7', '/', '\'', 'È' }, { '8', '(', '[',
|
||||||
'è' }, { '9', ')', ']', 'Í' }, { '0', '=', '¤', 'í' }, { '¡', '?', '¿', 'Ï' } }, { { 'q', 'Q', '\0',
|
'è' }, { '9', ')', ']', 'Í' }, { '0', '=', '¤', 'í' }, { '¡', '?', '¿', 'Ï' } }, { { 'q', 'Q', '\0',
|
||||||
'ï' }, { 'w', 'W', '\0', 'Ó' }, { 'e', 'E', '€', 'ó' }, { 'r', 'R', '®', 'Ò' }, { 't', 'T', '†', 'ò' },
|
'ï' }, { 'w', 'W', '\0', 'Ó' }, { 'e', 'E', '€', 'ó' }, { 'r', 'R', '®', 'Ò' }, { 't', 'T', '†', 'ò' },
|
||||||
{ 'y', 'Y', 'ÿ', 'Ú' }, { 'u', 'U', '“', 'ú' }, { 'i', 'I', '”', 'Ü' }, { 'o', 'O', 'Ø', 'ü' }, { 'p',
|
{ 'y', 'Y', 'ÿ', 'Ú' }, { 'u', 'U', '“', 'ú' }, { 'i', 'I', '”', 'Ü' }, { 'o', 'O', 'Ø', 'ü' }, { 'p',
|
||||||
'P', 'ø', 'Ù' }, { '+', '*', '\0', 'ù' } }, { { 'a', 'A', '^', 'Ã' }, { 's', 'S', '²', 'ã' }, {
|
'P', 'ø', 'Ù' }, { '+', '*', '\0', 'ù' } }, { { 'a', 'A', '^', 'Ã' }, { 's', 'S', '²', 'ã' }, {
|
||||||
'd', 'D', '³', 'Õ' }, { 'f', 'F', '«', 'õ' }, { 'g', 'G', '»', 'Ñ' }, { 'h', 'H', '§', 'ñ' }, { 'j',
|
'd', 'D', '³', 'Õ' }, { 'f', 'F', '«', 'õ' }, { 'g', 'G', '»', 'Ñ' }, { 'h', 'H', '§', 'ñ' }, { 'j',
|
||||||
'J', 'µ', 'Ç' }, { 'k', 'K', '¤', 'ç' }, { 'l', 'L', '„', '\0' }, { 'ñ', 'Ñ', '+', '\0' }, { 'ç', 'Ç',
|
'J', 'µ', 'Ç' }, { 'k', 'K', '¤', 'ç' }, { 'l', 'L', '„', '\0' }, { 'ñ', 'Ñ', '+', '\0' }, { 'ç', 'Ç',
|
||||||
'°', '\0' } }, { { '<', '>', '\0', 'Ä' }, { 'z', 'Z', '\0', 'ä' }, { 'x', 'X', '\0', 'Â' }, { 'c', 'C',
|
'°', '\0' } }, { { '<', '>', '\0', 'Ä' }, { 'z', 'Z', '\0', 'ä' }, { 'x', 'X', '\0', 'Â' }, { 'c', 'C',
|
||||||
'©', 'â' }, { 'v', 'V', '\0', 'å' }, { 'b', 'B', 'ß', 'Ë' }, { 'n', 'N', '\0', 'ë' }, { 'm', 'M', '\0',
|
'©', 'â' }, { 'v', 'V', '\0', 'å' }, { 'b', 'B', 'ß', 'Ë' }, { 'n', 'N', '\0', 'ë' }, { 'm', 'M', '\0',
|
||||||
'Ê' }, { ',', ';', '\0', 'ê' }, { '.', ':', '\0', '\0' }, { '-', '_', '\0', '\0' } } };
|
'Ê' }, { ',', ';', '\0', 'ê' }, { '.', ':', '\0', '\0' }, { '-', '_', '\0', '\0' } } };
|
||||||
memcpy(keys, thekeys, sizeof(thekeys));
|
memcpy(keys, thekeys, sizeof(thekeys));
|
||||||
}
|
}
|
||||||
|
|
||||||
keyTextbox = Resources::GetImageData("keyboard_textbox.png");
|
keyTextbox = Resources::GetImageData("keyboard_textbox.png");
|
||||||
keyTextboxImg = new GuiImage(keyTextbox);
|
keyTextboxImg = new GuiImage(keyTextbox);
|
||||||
keyTextboxImg->SetAlignment(ALIGN_CENTRE, ALIGN_TOP);
|
keyTextboxImg->SetAlignment(ALIGN_CENTRE, ALIGN_TOP);
|
||||||
keyTextboxImg->SetPosition(0, 40);//(0,0);
|
keyTextboxImg->SetPosition(0, 40);//(0,0);
|
||||||
this->Append(keyTextboxImg);
|
this->Append(keyTextboxImg);
|
||||||
|
|
||||||
kbText = new GuiText(kbtextstr, 20, ( GXColor )
|
kbText = new GuiText(kbtextstr, 20, ( GXColor )
|
||||||
{ 0, 0, 0, 0xff});
|
{ 0, 0, 0, 0xff});
|
||||||
kbText->SetAlignment(ALIGN_CENTRE, ALIGN_TOP);
|
kbText->SetAlignment(ALIGN_CENTRE, ALIGN_TOP);
|
||||||
kbText->SetPosition(0, 53);//(0, 13);
|
kbText->SetPosition(0, 53);//(0, 13);
|
||||||
this->Append(kbText);
|
this->Append(kbText);
|
||||||
|
|
||||||
key = Resources::GetImageData("keyboard_key.png");
|
key = Resources::GetImageData("keyboard_key.png");
|
||||||
keyOver = Resources::GetImageData("keyboard_key_over.png");
|
keyOver = Resources::GetImageData("keyboard_key_over.png");
|
||||||
keyMedium = Resources::GetImageData("keyboard_mediumkey_over.png");
|
keyMedium = Resources::GetImageData("keyboard_mediumkey_over.png");
|
||||||
keyLarge = Resources::GetImageData("keyboard_largekey_over.png");
|
keyLarge = Resources::GetImageData("keyboard_largekey_over.png");
|
||||||
|
|
||||||
trigA = new GuiTrigger;
|
trigA = new GuiTrigger;
|
||||||
trigA->SetSimpleTrigger(-1, WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A, PAD_BUTTON_A);
|
trigA->SetSimpleTrigger(-1, WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A, PAD_BUTTON_A);
|
||||||
trigB = new GuiTrigger;
|
trigB = new GuiTrigger;
|
||||||
trigB->SetButtonOnlyTrigger(-1, WPAD_BUTTON_B | WPAD_CLASSIC_BUTTON_B, PAD_BUTTON_B);
|
trigB->SetButtonOnlyTrigger(-1, WPAD_BUTTON_B | WPAD_CLASSIC_BUTTON_B, PAD_BUTTON_B);
|
||||||
|
|
||||||
int eurocheck = 0;
|
int eurocheck = 0;
|
||||||
if (mode > 1)
|
if (mode > 1)
|
||||||
{
|
{
|
||||||
eurocheck = -20;
|
eurocheck = -20;
|
||||||
}
|
}
|
||||||
|
|
||||||
keyBackImg = new GuiImage(keyMedium);
|
keyBackImg = new GuiImage(keyMedium);
|
||||||
keyBackOverImg = new GuiImage(keyMedium);
|
keyBackOverImg = new GuiImage(keyMedium);
|
||||||
if (mode == 3)
|
if (mode == 3)
|
||||||
{
|
{
|
||||||
keyBackText = new GuiText("Retour", 20, ( GXColor )
|
keyBackText = new GuiText("Retour", 20, ( GXColor )
|
||||||
{ 0, 0, 0, 0xff});
|
{ 0, 0, 0, 0xff});
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
keyBackText = new GuiText("Back", 20, ( GXColor )
|
keyBackText = new GuiText("Back", 20, ( GXColor )
|
||||||
{ 0, 0, 0, 0xff});
|
{ 0, 0, 0, 0xff});
|
||||||
}
|
}
|
||||||
//keyBack = new GuiButton(keyMedium->GetWidth(), keyMedium->GetHeight());
|
//keyBack = new GuiButton(keyMedium->GetWidth(), keyMedium->GetHeight());
|
||||||
keyBack = new GuiButton(keyBackImg, keyBackOverImg, 0, 3, 11 * 42 + 40 + eurocheck, 0 * 42 + 120, trigA,
|
keyBack = new GuiButton(keyBackImg, keyBackOverImg, 0, 3, 11 * 42 + 40 + eurocheck, 0 * 42 + 120, trigA,
|
||||||
btnSoundOver, btnSoundClick, 1);
|
btnSoundOver, btnSoundClick, 1);
|
||||||
//keyBack->SetImage(keyBackImg);
|
//keyBack->SetImage(keyBackImg);
|
||||||
//keyBack->SetImageOver(keyBackOverImg);
|
//keyBack->SetImageOver(keyBackOverImg);
|
||||||
keyBack->SetLabel(keyBackText);
|
keyBack->SetLabel(keyBackText);
|
||||||
//keyBack->SetSoundOver(btnSoundOver);
|
//keyBack->SetSoundOver(btnSoundOver);
|
||||||
//keyBack->SetSoundClick(btnSoundClick);
|
//keyBack->SetSoundClick(btnSoundClick);
|
||||||
//keyBack->SetTrigger(trigA);
|
//keyBack->SetTrigger(trigA);
|
||||||
keyBack->SetTrigger(trigB);
|
keyBack->SetTrigger(trigB);
|
||||||
if (mode > 1)
|
if (mode > 1)
|
||||||
{
|
{
|
||||||
keyBack->SetPosition(11 * 42 + 40 + eurocheck, 0 * 42 + 120);
|
keyBack->SetPosition(11 * 42 + 40 + eurocheck, 0 * 42 + 120);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
keyBack->SetPosition(10 * 42 + 40 + eurocheck, 0 * 42 + 120);
|
keyBack->SetPosition(10 * 42 + 40 + eurocheck, 0 * 42 + 120);
|
||||||
}//(10*42+40, 0*42+80);
|
}//(10*42+40, 0*42+80);
|
||||||
//keyBack->SetEffectGrow();
|
//keyBack->SetEffectGrow();
|
||||||
this->Append(keyBack);
|
this->Append(keyBack);
|
||||||
|
|
||||||
keyClearImg = new GuiImage(keyMedium);
|
keyClearImg = new GuiImage(keyMedium);
|
||||||
keyClearOverImg = new GuiImage(keyMedium);
|
keyClearOverImg = new GuiImage(keyMedium);
|
||||||
if (mode == 3)
|
if (mode == 3)
|
||||||
{
|
{
|
||||||
keyClearText = new GuiText("Effacer", 20, ( GXColor )
|
keyClearText = new GuiText("Effacer", 20, ( GXColor )
|
||||||
{ 0, 0, 0, 0xff});
|
{ 0, 0, 0, 0xff});
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
keyClearText = new GuiText("Clear", 20, ( GXColor )
|
keyClearText = new GuiText("Clear", 20, ( GXColor )
|
||||||
{ 0, 0, 0, 0xff});
|
{ 0, 0, 0, 0xff});
|
||||||
}
|
}
|
||||||
keyClear = new GuiButton(keyClearImg, keyClearOverImg, 0, 3, (10 * 42 + 40) + eurocheck, 4 * 42 + 120, trigA,
|
keyClear = new GuiButton(keyClearImg, keyClearOverImg, 0, 3, (10 * 42 + 40) + eurocheck, 4 * 42 + 120, trigA,
|
||||||
btnSoundOver, btnSoundClick, 1);
|
btnSoundOver, btnSoundClick, 1);
|
||||||
//keyClear = new GuiButton(keyMedium->GetWidth(), keyMedium->GetHeight());
|
//keyClear = new GuiButton(keyMedium->GetWidth(), keyMedium->GetHeight());
|
||||||
//keyClear->SetImage(keyClearImg);
|
//keyClear->SetImage(keyClearImg);
|
||||||
//keyClear->SetImageOver(keyClearOverImg);
|
//keyClear->SetImageOver(keyClearOverImg);
|
||||||
keyClear->SetLabel(keyClearText);
|
keyClear->SetLabel(keyClearText);
|
||||||
//keyClear->SetSoundOver(btnSoundOver);
|
//keyClear->SetSoundOver(btnSoundOver);
|
||||||
//keyClear->SetSoundClick(btnSoundClick);
|
//keyClear->SetSoundClick(btnSoundClick);
|
||||||
//keyClear->SetTrigger(trigA);
|
//keyClear->SetTrigger(trigA);
|
||||||
//keyClear->SetPosition((10*42+40)+eurocheck, 4*42+120);//(10*42+40, 0*42+80);
|
//keyClear->SetPosition((10*42+40)+eurocheck, 4*42+120);//(10*42+40, 0*42+80);
|
||||||
//keyClear->SetEffectGrow();
|
//keyClear->SetEffectGrow();
|
||||||
this->Append(keyClear);
|
this->Append(keyClear);
|
||||||
|
|
||||||
keyAltImg = new GuiImage(keyMedium);
|
keyAltImg = new GuiImage(keyMedium);
|
||||||
keyAltOverImg = new GuiImage(keyMedium);
|
keyAltOverImg = new GuiImage(keyMedium);
|
||||||
keyAltText = new GuiText("Alt Gr", 20, ( GXColor )
|
keyAltText = new GuiText("Alt Gr", 20, ( GXColor )
|
||||||
{ 0, 0, 0, 0xff});
|
{ 0, 0, 0, 0xff});
|
||||||
keyAlt = new GuiButton(keyAltImg, keyAltOverImg, 0, 3, 84 + eurocheck, 4 * 42 + 120, trigA, btnSoundOver,
|
keyAlt = new GuiButton(keyAltImg, keyAltOverImg, 0, 3, 84 + eurocheck, 4 * 42 + 120, trigA, btnSoundOver,
|
||||||
btnSoundClick, 1);
|
btnSoundClick, 1);
|
||||||
//keyAlt = new GuiButton(keyMedium->GetWidth(), keyMedium->GetHeight());
|
//keyAlt = new GuiButton(keyMedium->GetWidth(), keyMedium->GetHeight());
|
||||||
//keyAlt->SetImage(keyAltImg);
|
//keyAlt->SetImage(keyAltImg);
|
||||||
//keyAlt->SetImageOver(keyAltOverImg);
|
//keyAlt->SetImageOver(keyAltOverImg);
|
||||||
keyAlt->SetLabel(keyAltText);
|
keyAlt->SetLabel(keyAltText);
|
||||||
//keyAlt->SetSoundOver(btnSoundOver);
|
//keyAlt->SetSoundOver(btnSoundOver);
|
||||||
//keyAlt->SetSoundClick(btnSoundClick);
|
//keyAlt->SetSoundClick(btnSoundClick);
|
||||||
//keyAlt->SetTrigger(trigA);
|
//keyAlt->SetTrigger(trigA);
|
||||||
//keyAlt->SetPosition(84+eurocheck, 4*42+120);//(10*42+40, 4*42+120);
|
//keyAlt->SetPosition(84+eurocheck, 4*42+120);//(10*42+40, 4*42+120);
|
||||||
//keyAlt->SetEffectGrow();
|
//keyAlt->SetEffectGrow();
|
||||||
if (mode > 1)
|
if (mode > 1)
|
||||||
{
|
{
|
||||||
this->Append(keyAlt);
|
this->Append(keyAlt);
|
||||||
}
|
}
|
||||||
|
|
||||||
keyAlt2Img = new GuiImage(keyMedium);
|
keyAlt2Img = new GuiImage(keyMedium);
|
||||||
keyAlt2OverImg = new GuiImage(keyMedium);
|
keyAlt2OverImg = new GuiImage(keyMedium);
|
||||||
keyAlt2Text = new GuiText("Accent", 20, ( GXColor )
|
keyAlt2Text = new GuiText("Accent", 20, ( GXColor )
|
||||||
{ 0, 0, 0, 0xff});
|
{ 0, 0, 0, 0xff});
|
||||||
keyAlt2 = new GuiButton(keyAlt2Img, keyAlt2OverImg, 0, 3, (8 * 42 + 40) + eurocheck, 4 * 42 + 120, trigA,
|
keyAlt2 = new GuiButton(keyAlt2Img, keyAlt2OverImg, 0, 3, (8 * 42 + 40) + eurocheck, 4 * 42 + 120, trigA,
|
||||||
btnSoundOver, btnSoundClick, 1);
|
btnSoundOver, btnSoundClick, 1);
|
||||||
//keyAlt2 = new GuiButton(keyMedium->GetWidth(), keyMedium->GetHeight());
|
//keyAlt2 = new GuiButton(keyMedium->GetWidth(), keyMedium->GetHeight());
|
||||||
//keyAlt2->SetImage(keyAlt2Img);
|
//keyAlt2->SetImage(keyAlt2Img);
|
||||||
//keyAlt2->SetImageOver(keyAlt2OverImg);
|
//keyAlt2->SetImageOver(keyAlt2OverImg);
|
||||||
keyAlt2->SetLabel(keyAlt2Text);
|
keyAlt2->SetLabel(keyAlt2Text);
|
||||||
//keyAlt2->SetSoundOver(btnSoundOver);
|
//keyAlt2->SetSoundOver(btnSoundOver);
|
||||||
//keyAlt2->SetSoundClick(btnSoundClick);
|
//keyAlt2->SetSoundClick(btnSoundClick);
|
||||||
//keyAlt2->SetTrigger(trigA);
|
//keyAlt2->SetTrigger(trigA);
|
||||||
//keyAlt2->SetPosition((8*42+40)+eurocheck, 4*42+120);//(10*42+40, 4*42+120);
|
//keyAlt2->SetPosition((8*42+40)+eurocheck, 4*42+120);//(10*42+40, 4*42+120);
|
||||||
//keyAlt2->SetEffectGrow();
|
//keyAlt2->SetEffectGrow();
|
||||||
if (mode > 1)
|
if (mode > 1)
|
||||||
{
|
{
|
||||||
this->Append(keyAlt2);
|
this->Append(keyAlt2);
|
||||||
}
|
}
|
||||||
|
|
||||||
keyCapsImg = new GuiImage(keyMedium);
|
keyCapsImg = new GuiImage(keyMedium);
|
||||||
keyCapsOverImg = new GuiImage(keyMedium);
|
keyCapsOverImg = new GuiImage(keyMedium);
|
||||||
keyCapsText = new GuiText("Caps", 20, ( GXColor )
|
keyCapsText = new GuiText("Caps", 20, ( GXColor )
|
||||||
{ 0, 0, 0, 0xff});
|
{ 0, 0, 0, 0xff});
|
||||||
keyCaps = new GuiButton(keyCapsImg, keyCapsOverImg, 0, 3, 0 + eurocheck, 2 * 42 + 120, trigA, btnSoundOver,
|
keyCaps = new GuiButton(keyCapsImg, keyCapsOverImg, 0, 3, 0 + eurocheck, 2 * 42 + 120, trigA, btnSoundOver,
|
||||||
btnSoundClick, 1);
|
btnSoundClick, 1);
|
||||||
//keyCaps = new GuiButton(keyMedium->GetWidth(), keyMedium->GetHeight());
|
//keyCaps = new GuiButton(keyMedium->GetWidth(), keyMedium->GetHeight());
|
||||||
//keyCaps->SetImage(keyCapsImg);
|
//keyCaps->SetImage(keyCapsImg);
|
||||||
//keyCaps->SetImageOver(keyCapsOverImg);
|
//keyCaps->SetImageOver(keyCapsOverImg);
|
||||||
keyCaps->SetLabel(keyCapsText);
|
keyCaps->SetLabel(keyCapsText);
|
||||||
//keyCaps->SetSoundOver(btnSoundOver);
|
//keyCaps->SetSoundOver(btnSoundOver);
|
||||||
//keyCaps->SetSoundClick(btnSoundClick);
|
//keyCaps->SetSoundClick(btnSoundClick);
|
||||||
//keyCaps->SetTrigger(trigA);
|
//keyCaps->SetTrigger(trigA);
|
||||||
//keyCaps->SetPosition(0+eurocheck, 2*42+120);//(0, 2*42+80);
|
//keyCaps->SetPosition(0+eurocheck, 2*42+120);//(0, 2*42+80);
|
||||||
//keyCaps->SetEffectGrow();
|
//keyCaps->SetEffectGrow();
|
||||||
this->Append(keyCaps);
|
this->Append(keyCaps);
|
||||||
|
|
||||||
keyShiftImg = new GuiImage(keyMedium);
|
keyShiftImg = new GuiImage(keyMedium);
|
||||||
keyShiftOverImg = new GuiImage(keyMedium);
|
keyShiftOverImg = new GuiImage(keyMedium);
|
||||||
keyShiftText = new GuiText("Shift", 20, ( GXColor )
|
keyShiftText = new GuiText("Shift", 20, ( GXColor )
|
||||||
{ 0, 0, 0, 0xff});
|
{ 0, 0, 0, 0xff});
|
||||||
keyShift = new GuiButton(keyShiftImg, keyShiftOverImg, 0, 3, 21 + eurocheck, 3 * 42 + 120, trigA, btnSoundOver,
|
keyShift = new GuiButton(keyShiftImg, keyShiftOverImg, 0, 3, 21 + eurocheck, 3 * 42 + 120, trigA, btnSoundOver,
|
||||||
btnSoundClick, 1);
|
btnSoundClick, 1);
|
||||||
//keyShift = new GuiButton(keyMedium->GetWidth(), keyMedium->GetHeight());
|
//keyShift = new GuiButton(keyMedium->GetWidth(), keyMedium->GetHeight());
|
||||||
//keyShift->SetImage(keyShiftImg);
|
//keyShift->SetImage(keyShiftImg);
|
||||||
//keyShift->SetImageOver(keyShiftOverImg);
|
//keyShift->SetImageOver(keyShiftOverImg);
|
||||||
keyShift->SetLabel(keyShiftText);
|
keyShift->SetLabel(keyShiftText);
|
||||||
//keyShift->SetSoundOver(btnSoundOver);
|
//keyShift->SetSoundOver(btnSoundOver);
|
||||||
//keyShift->SetSoundClick(btnSoundClick);
|
//keyShift->SetSoundClick(btnSoundClick);
|
||||||
//keyShift->SetTrigger(trigA);
|
//keyShift->SetTrigger(trigA);
|
||||||
//keyShift->SetPosition(21+eurocheck, 3*42+120);//(21, 3*42+80);
|
//keyShift->SetPosition(21+eurocheck, 3*42+120);//(21, 3*42+80);
|
||||||
//keyShift->SetEffectGrow();
|
//keyShift->SetEffectGrow();
|
||||||
this->Append(keyShift);
|
this->Append(keyShift);
|
||||||
|
|
||||||
keySpaceImg = new GuiImage(keyLarge);
|
keySpaceImg = new GuiImage(keyLarge);
|
||||||
keySpaceOverImg = new GuiImage(keyLarge);
|
keySpaceOverImg = new GuiImage(keyLarge);
|
||||||
keySpace = new GuiButton(keySpaceImg, keySpaceOverImg, 2, 3, 0 + eurocheck, 4 * 42 + 120, trigA, btnSoundOver,
|
keySpace = new GuiButton(keySpaceImg, keySpaceOverImg, 2, 3, 0 + eurocheck, 4 * 42 + 120, trigA, btnSoundOver,
|
||||||
btnSoundClick, 1);
|
btnSoundClick, 1);
|
||||||
//keySpace = new GuiButton(keyLarge->GetWidth(), keyLarge->GetHeight());
|
//keySpace = new GuiButton(keyLarge->GetWidth(), keyLarge->GetHeight());
|
||||||
//keySpace->SetImage(keySpaceImg);
|
//keySpace->SetImage(keySpaceImg);
|
||||||
//keySpace->SetImageOver(keySpaceOverImg);
|
//keySpace->SetImageOver(keySpaceOverImg);
|
||||||
//keySpace->SetSoundOver(btnSoundOver);
|
//keySpace->SetSoundOver(btnSoundOver);
|
||||||
//keySpace->SetSoundClick(btnSoundClick);
|
//keySpace->SetSoundClick(btnSoundClick);
|
||||||
//keySpace->SetTrigger(trigA);
|
//keySpace->SetTrigger(trigA);
|
||||||
//keySpace->SetPosition(0+eurocheck, 4*42+120);//(0, 4*42+80);
|
//keySpace->SetPosition(0+eurocheck, 4*42+120);//(0, 4*42+80);
|
||||||
//keySpace->SetAlignment(ALIGN_CENTRE, ALIGN_TOP);
|
//keySpace->SetAlignment(ALIGN_CENTRE, ALIGN_TOP);
|
||||||
//keySpace->SetEffectGrow();
|
//keySpace->SetEffectGrow();
|
||||||
this->Append(keySpace);
|
this->Append(keySpace);
|
||||||
|
|
||||||
char txt[2] = { 0, 0 };
|
char txt[2] = { 0, 0 };
|
||||||
for (int i = 0; i < 4; i++)
|
for (int i = 0; i < 4; i++)
|
||||||
{
|
{
|
||||||
for (int j = 0; j < 11; j++)
|
for (int j = 0; j < 11; j++)
|
||||||
{
|
{
|
||||||
if (keys[i][j].ch != '\0')
|
if (keys[i][j].ch != '\0')
|
||||||
{
|
{
|
||||||
keyImg[i][j] = new GuiImage(key);
|
keyImg[i][j] = new GuiImage(key);
|
||||||
keyImgOver[i][j] = new GuiImage(keyOver);
|
keyImgOver[i][j] = new GuiImage(keyOver);
|
||||||
txt[0] = keys[i][j].ch;
|
txt[0] = keys[i][j].ch;
|
||||||
keyTxt[i][j] = new GuiText(txt, 20, ( GXColor )
|
keyTxt[i][j] = new GuiText(txt, 20, ( GXColor )
|
||||||
{ 0, 0, 0, 0xff});
|
{ 0, 0, 0, 0xff});
|
||||||
keyTxt[i][j]->SetAlignment(ALIGN_CENTRE, ALIGN_BOTTOM);
|
keyTxt[i][j]->SetAlignment(ALIGN_CENTRE, ALIGN_BOTTOM);
|
||||||
keyTxt[i][j]->SetPosition(0, -10);
|
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,
|
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);
|
i * 42 + 120, trigA, btnSoundOver, btnSoundClick, 1);
|
||||||
//keyBtn[i][j] = new GuiButton(key->GetWidth(), key->GetHeight());
|
//keyBtn[i][j] = new GuiButton(key->GetWidth(), key->GetHeight());
|
||||||
//keyBtn[i][j]->SetImage(keyImg[i][j]);
|
//keyBtn[i][j]->SetImage(keyImg[i][j]);
|
||||||
//keyBtn[i][j]->SetImageOver(keyImgOver[i][j]);
|
//keyBtn[i][j]->SetImageOver(keyImgOver[i][j]);
|
||||||
//keyBtn[i][j]->SetSoundOver(btnSoundOver);
|
//keyBtn[i][j]->SetSoundOver(btnSoundOver);
|
||||||
//keyBtn[i][j]->SetSoundClick(btnSoundClick);
|
//keyBtn[i][j]->SetSoundClick(btnSoundClick);
|
||||||
//keyBtn[i][j]->SetTrigger(trigA);
|
//keyBtn[i][j]->SetTrigger(trigA);
|
||||||
keyBtn[i][j]->SetLabel(keyTxt[i][j]);
|
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]->SetPosition((j*42+21*i+40)+eurocheck, i*42+120);//SetPosition(j*42+21*i+40, i*42+80);
|
||||||
//keyBtn[i][j]->SetEffectGrow();
|
//keyBtn[i][j]->SetEffectGrow();
|
||||||
this->Append(keyBtn[i][j]);
|
this->Append(keyBtn[i][j]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -419,190 +419,190 @@ GuiKeyboard::GuiKeyboard(char * t, u32 max, int min, int lang)
|
||||||
*/
|
*/
|
||||||
GuiKeyboard::~GuiKeyboard()
|
GuiKeyboard::~GuiKeyboard()
|
||||||
{
|
{
|
||||||
delete kbText;
|
delete kbText;
|
||||||
delete keyTextbox;
|
delete keyTextbox;
|
||||||
delete keyTextboxImg;
|
delete keyTextboxImg;
|
||||||
delete keyCapsText;
|
delete keyCapsText;
|
||||||
delete keyCapsImg;
|
delete keyCapsImg;
|
||||||
delete keyCapsOverImg;
|
delete keyCapsOverImg;
|
||||||
delete keyCaps;
|
delete keyCaps;
|
||||||
delete keyShiftText;
|
delete keyShiftText;
|
||||||
delete keyShiftImg;
|
delete keyShiftImg;
|
||||||
delete keyShiftOverImg;
|
delete keyShiftOverImg;
|
||||||
delete keyShift;
|
delete keyShift;
|
||||||
if (keyAlt)
|
if (keyAlt)
|
||||||
{
|
{
|
||||||
delete keyAlt;
|
delete keyAlt;
|
||||||
}
|
}
|
||||||
if (keyAlt2)
|
if (keyAlt2)
|
||||||
{
|
{
|
||||||
delete keyAlt2;
|
delete keyAlt2;
|
||||||
}
|
}
|
||||||
delete keyBackText;
|
delete keyBackText;
|
||||||
delete keyBackImg;
|
delete keyBackImg;
|
||||||
delete keyBackOverImg;
|
delete keyBackOverImg;
|
||||||
delete keyBack;
|
delete keyBack;
|
||||||
delete keySpaceImg;
|
delete keySpaceImg;
|
||||||
delete keySpaceOverImg;
|
delete keySpaceOverImg;
|
||||||
delete keySpace;
|
delete keySpace;
|
||||||
delete key;
|
delete key;
|
||||||
delete keyOver;
|
delete keyOver;
|
||||||
delete keyMedium;
|
delete keyMedium;
|
||||||
delete keyLarge;
|
delete keyLarge;
|
||||||
delete trigA;
|
delete trigA;
|
||||||
delete trigB;
|
delete trigB;
|
||||||
|
|
||||||
for (int i = 0; i < 4; i++)
|
for (int i = 0; i < 4; i++)
|
||||||
{
|
{
|
||||||
for (int j = 0; j < 11; j++)
|
for (int j = 0; j < 11; j++)
|
||||||
{
|
{
|
||||||
if (keys[i][j].ch != '\0')
|
if (keys[i][j].ch != '\0')
|
||||||
{
|
{
|
||||||
delete keyImg[i][j];
|
delete keyImg[i][j];
|
||||||
delete keyImgOver[i][j];
|
delete keyImgOver[i][j];
|
||||||
delete keyTxt[i][j];
|
delete keyTxt[i][j];
|
||||||
delete keyBtn[i][j];
|
delete keyBtn[i][j];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuiKeyboard::Update(GuiTrigger * t)
|
void GuiKeyboard::Update(GuiTrigger * t)
|
||||||
{
|
{
|
||||||
LOCK( this );
|
LOCK( this );
|
||||||
if (_elements.size() == 0 || (state == STATE_DISABLED && parentElement)) return;
|
if (_elements.size() == 0 || (state == STATE_DISABLED && parentElement)) return;
|
||||||
|
|
||||||
for (u8 i = 0; i < _elements.size(); i++)
|
for (u8 i = 0; i < _elements.size(); i++)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
_elements.at(i)->Update(t);
|
_elements.at(i)->Update(t);
|
||||||
}
|
}
|
||||||
catch (const std::exception& e)
|
catch (const std::exception& e)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool changedShiftKey = false;
|
bool changedShiftKey = false;
|
||||||
|
|
||||||
if (keySpace->GetState() == STATE_CLICKED)
|
if (keySpace->GetState() == STATE_CLICKED)
|
||||||
{
|
{
|
||||||
if (strlen(kbtextstr) < kbtextmaxlen - 1) // -1 --> kbtextmaxlen means with terminating '\0'
|
if (strlen(kbtextstr) < kbtextmaxlen - 1) // -1 --> kbtextmaxlen means with terminating '\0'
|
||||||
{
|
{
|
||||||
kbtextstr[strlen(kbtextstr)] = ' ';
|
kbtextstr[strlen(kbtextstr)] = ' ';
|
||||||
kbText->SetText(kbtextstr);
|
kbText->SetText(kbtextstr);
|
||||||
}
|
}
|
||||||
keySpace->SetState(STATE_SELECTED, t->chan);
|
keySpace->SetState(STATE_SELECTED, t->chan);
|
||||||
}
|
}
|
||||||
else if (keyBack->GetState() == STATE_CLICKED)
|
else if (keyBack->GetState() == STATE_CLICKED)
|
||||||
{
|
{
|
||||||
if (strlen(kbtextstr) > (m))
|
if (strlen(kbtextstr) > (m))
|
||||||
{
|
{
|
||||||
kbtextstr[strlen(kbtextstr) - 1] = 0;
|
kbtextstr[strlen(kbtextstr) - 1] = 0;
|
||||||
kbText->SetText(kbtextstr);
|
kbText->SetText(kbtextstr);
|
||||||
}
|
}
|
||||||
keyBack->SetState(STATE_SELECTED, t->chan);
|
keyBack->SetState(STATE_SELECTED, t->chan);
|
||||||
}
|
}
|
||||||
else if (keyClear->GetState() == STATE_CLICKED)
|
else if (keyClear->GetState() == STATE_CLICKED)
|
||||||
{
|
{
|
||||||
while (strlen(kbtextstr) > (m))
|
while (strlen(kbtextstr) > (m))
|
||||||
{
|
{
|
||||||
kbtextstr[strlen(kbtextstr) - 1] = 0;
|
kbtextstr[strlen(kbtextstr) - 1] = 0;
|
||||||
kbText->SetText(kbtextstr);
|
kbText->SetText(kbtextstr);
|
||||||
}
|
}
|
||||||
keyClear->SetState(STATE_SELECTED, t->chan);
|
keyClear->SetState(STATE_SELECTED, t->chan);
|
||||||
}
|
}
|
||||||
else if (keyShift->GetState() == STATE_CLICKED)
|
else if (keyShift->GetState() == STATE_CLICKED)
|
||||||
{
|
{
|
||||||
changedShiftKey = true;
|
changedShiftKey = true;
|
||||||
shift ^= 1;
|
shift ^= 1;
|
||||||
if (alt) alt ^= 1;
|
if (alt) alt ^= 1;
|
||||||
if (alt2) alt2 ^= 1;
|
if (alt2) alt2 ^= 1;
|
||||||
keyShift->SetState(STATE_SELECTED, t->chan);
|
keyShift->SetState(STATE_SELECTED, t->chan);
|
||||||
}
|
}
|
||||||
else if (keyAlt->GetState() == STATE_CLICKED)
|
else if (keyAlt->GetState() == STATE_CLICKED)
|
||||||
{
|
{
|
||||||
changedShiftKey = true;
|
changedShiftKey = true;
|
||||||
alt ^= 1;
|
alt ^= 1;
|
||||||
if (shift) shift ^= 1;
|
if (shift) shift ^= 1;
|
||||||
if (alt2) alt2 ^= 1;
|
if (alt2) alt2 ^= 1;
|
||||||
keyAlt->SetState(STATE_SELECTED, t->chan);
|
keyAlt->SetState(STATE_SELECTED, t->chan);
|
||||||
}
|
}
|
||||||
else if (keyAlt2->GetState() == STATE_CLICKED)
|
else if (keyAlt2->GetState() == STATE_CLICKED)
|
||||||
{
|
{
|
||||||
changedShiftKey = true;
|
changedShiftKey = true;
|
||||||
alt2 ^= 1;
|
alt2 ^= 1;
|
||||||
if (shift) shift ^= 1;
|
if (shift) shift ^= 1;
|
||||||
if (alt) alt ^= 1;
|
if (alt) alt ^= 1;
|
||||||
keyAlt2->SetState(STATE_SELECTED, t->chan);
|
keyAlt2->SetState(STATE_SELECTED, t->chan);
|
||||||
}
|
}
|
||||||
else if (keyCaps->GetState() == STATE_CLICKED)
|
else if (keyCaps->GetState() == STATE_CLICKED)
|
||||||
{
|
{
|
||||||
changedShiftKey = true;
|
changedShiftKey = true;
|
||||||
caps ^= 1;
|
caps ^= 1;
|
||||||
keyCaps->SetState(STATE_SELECTED, t->chan);
|
keyCaps->SetState(STATE_SELECTED, t->chan);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool update = false;
|
bool update = false;
|
||||||
|
|
||||||
char txt[2] = { 0, 0 };
|
char txt[2] = { 0, 0 };
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
update = false;
|
update = false;
|
||||||
for (int i = 0; i < 4; i++)
|
for (int i = 0; i < 4; i++)
|
||||||
{
|
{
|
||||||
for (int j = 0; j < 11; j++)
|
for (int j = 0; j < 11; j++)
|
||||||
{
|
{
|
||||||
if (keys[i][j].ch != '\0')
|
if (keys[i][j].ch != '\0')
|
||||||
{
|
{
|
||||||
if (shift || caps)
|
if (shift || caps)
|
||||||
txt[0] = keys[i][j].chShift;
|
txt[0] = keys[i][j].chShift;
|
||||||
else if (alt)
|
else if (alt)
|
||||||
txt[0] = keys[i][j].chalt;
|
txt[0] = keys[i][j].chalt;
|
||||||
else if (alt2)
|
else if (alt2)
|
||||||
txt[0] = keys[i][j].chalt2;
|
txt[0] = keys[i][j].chalt2;
|
||||||
else txt[0] = keys[i][j].ch;
|
else txt[0] = keys[i][j].ch;
|
||||||
|
|
||||||
if (changedShiftKey) // change text only if needed
|
if (changedShiftKey) // change text only if needed
|
||||||
keyTxt[i][j]->SetText(txt);
|
keyTxt[i][j]->SetText(txt);
|
||||||
|
|
||||||
if (keyBtn[i][j]->GetState() == STATE_CLICKED)
|
if (keyBtn[i][j]->GetState() == STATE_CLICKED)
|
||||||
{
|
{
|
||||||
if (strlen(kbtextstr) < kbtextmaxlen - 1) // -1 --> kbtextmaxlen means with term. '\0'
|
if (strlen(kbtextstr) < kbtextmaxlen - 1) // -1 --> kbtextmaxlen means with term. '\0'
|
||||||
{
|
{
|
||||||
kbtextstr[strlen(kbtextstr)] = txt[0];
|
kbtextstr[strlen(kbtextstr)] = txt[0];
|
||||||
kbText->SetText(kbtextstr);
|
kbText->SetText(kbtextstr);
|
||||||
}
|
}
|
||||||
keyBtn[i][j]->SetState(STATE_SELECTED, t->chan);
|
keyBtn[i][j]->SetState(STATE_SELECTED, t->chan);
|
||||||
|
|
||||||
if (shift || alt || alt2)
|
if (shift || alt || alt2)
|
||||||
{
|
{
|
||||||
if (shift) shift ^= 1;
|
if (shift) shift ^= 1;
|
||||||
if (alt) alt ^= 1;
|
if (alt) alt ^= 1;
|
||||||
if (alt2) alt2 ^= 1;
|
if (alt2) alt2 ^= 1;
|
||||||
update = true;
|
update = true;
|
||||||
changedShiftKey = true;
|
changedShiftKey = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} while (update);
|
} 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
|
if (focus) // only send actions to this window if it's in focus
|
||||||
{
|
{
|
||||||
// pad/joystick navigation
|
// pad/joystick navigation
|
||||||
if (t->Right())
|
if (t->Right())
|
||||||
this->MoveSelectionHor(1);
|
this->MoveSelectionHor(1);
|
||||||
else if (t->Left())
|
else if (t->Left())
|
||||||
this->MoveSelectionHor(-1);
|
this->MoveSelectionHor(-1);
|
||||||
else if (t->Down())
|
else if (t->Down())
|
||||||
this->MoveSelectionVert(1);
|
this->MoveSelectionVert(1);
|
||||||
else if (t->Up()) this->MoveSelectionVert(-1);
|
else if (t->Up()) this->MoveSelectionVert(-1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,80 +19,80 @@
|
||||||
|
|
||||||
GuiNumpad::GuiNumpad(char * t, u32 max)
|
GuiNumpad::GuiNumpad(char * t, u32 max)
|
||||||
{
|
{
|
||||||
width = 400;
|
width = 400;
|
||||||
height = 370;
|
height = 370;
|
||||||
selectable = true;
|
selectable = true;
|
||||||
focus = 0; // allow focus
|
focus = 0; // allow focus
|
||||||
alignmentHor = ALIGN_CENTRE;
|
alignmentHor = ALIGN_CENTRE;
|
||||||
alignmentVert = ALIGN_MIDDLE;
|
alignmentVert = ALIGN_MIDDLE;
|
||||||
kbtextmaxlen = max > sizeof(kbtextstr) ? sizeof(kbtextstr) : max; // limit max up to sizeof(kbtextstr)
|
kbtextmaxlen = max > sizeof(kbtextstr) ? sizeof(kbtextstr) : max; // limit max up to sizeof(kbtextstr)
|
||||||
// strlcpy(kbtextstr, t, kbtextmaxlen);
|
// strlcpy(kbtextstr, t, kbtextmaxlen);
|
||||||
strncpy(kbtextstr, t, kbtextmaxlen); // strncpy is needed to fill the rest with \0
|
strncpy(kbtextstr, t, kbtextmaxlen); // strncpy is needed to fill the rest with \0
|
||||||
kbtextstr[sizeof(kbtextstr) - 1] = 0; // terminate with \0
|
kbtextstr[sizeof(kbtextstr) - 1] = 0; // terminate with \0
|
||||||
|
|
||||||
char thekeys[11] = { '1', '2', '3', '4', '5', '6', '7', '8', '9', '\0', '0' };
|
char thekeys[11] = { '1', '2', '3', '4', '5', '6', '7', '8', '9', '\0', '0' };
|
||||||
memcpy(keys, thekeys, sizeof(thekeys));
|
memcpy(keys, thekeys, sizeof(thekeys));
|
||||||
|
|
||||||
keyTextbox = new GuiImageData("keyboard_textbox.png");
|
keyTextbox = new GuiImageData("keyboard_textbox.png");
|
||||||
keyTextboxImg = new GuiImage(keyTextbox);
|
keyTextboxImg = new GuiImage(keyTextbox);
|
||||||
keyTextboxImg->SetAlignment(ALIGN_CENTRE, ALIGN_TOP);
|
keyTextboxImg->SetAlignment(ALIGN_CENTRE, ALIGN_TOP);
|
||||||
keyTextboxImg->SetPosition(0, 40);//(0,0);
|
keyTextboxImg->SetPosition(0, 40);//(0,0);
|
||||||
this->Append(keyTextboxImg);
|
this->Append(keyTextboxImg);
|
||||||
|
|
||||||
kbText = new GuiText(kbtextstr, 20, ( GXColor )
|
kbText = new GuiText(kbtextstr, 20, ( GXColor )
|
||||||
{ 0, 0, 0, 0xff});
|
{ 0, 0, 0, 0xff});
|
||||||
kbText->SetAlignment(ALIGN_CENTRE, ALIGN_TOP);
|
kbText->SetAlignment(ALIGN_CENTRE, ALIGN_TOP);
|
||||||
kbText->SetPosition(0, 53);//(0, 13);
|
kbText->SetPosition(0, 53);//(0, 13);
|
||||||
kbText->SetPassChar('*');
|
kbText->SetPassChar('*');
|
||||||
this->Append(kbText);
|
this->Append(kbText);
|
||||||
|
|
||||||
keyMedium = new GuiImageData("keyboard_mediumkey_over.png");
|
keyMedium = new GuiImageData("keyboard_mediumkey_over.png");
|
||||||
|
|
||||||
trigA = new GuiTrigger;
|
trigA = new GuiTrigger;
|
||||||
trigA->SetSimpleTrigger(-1, WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A, PAD_BUTTON_A);
|
trigA->SetSimpleTrigger(-1, WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A, PAD_BUTTON_A);
|
||||||
trigB = new GuiTrigger;
|
trigB = new GuiTrigger;
|
||||||
trigB->SetButtonOnlyTrigger(-1, WPAD_BUTTON_B | WPAD_CLASSIC_BUTTON_B, PAD_BUTTON_B);
|
trigB->SetButtonOnlyTrigger(-1, WPAD_BUTTON_B | WPAD_CLASSIC_BUTTON_B, PAD_BUTTON_B);
|
||||||
|
|
||||||
keyBackImg = new GuiImage(keyMedium);
|
keyBackImg = new GuiImage(keyMedium);
|
||||||
keyBackOverImg = new GuiImage(keyMedium);
|
keyBackOverImg = new GuiImage(keyMedium);
|
||||||
keyBackText = new GuiText("Back", 20, ( GXColor )
|
keyBackText = new GuiText("Back", 20, ( GXColor )
|
||||||
{ 0, 0, 0, 0xff});
|
{ 0, 0, 0, 0xff});
|
||||||
|
|
||||||
keyBack = new GuiButton(keyBackImg, keyBackOverImg, ALIGN_CENTRE, ALIGN_MIDDLE, 90, 80, trigA, btnSoundOver, btnSoundClick, 1);
|
keyBack = new GuiButton(keyBackImg, keyBackOverImg, ALIGN_CENTRE, ALIGN_MIDDLE, 90, 80, trigA, btnSoundOver, btnSoundClick, 1);
|
||||||
keyBack->SetLabel(keyBackText);
|
keyBack->SetLabel(keyBackText);
|
||||||
keyBack->SetTrigger(trigB);
|
keyBack->SetTrigger(trigB);
|
||||||
this->Append(keyBack);
|
this->Append(keyBack);
|
||||||
|
|
||||||
keyClearImg = new GuiImage(keyMedium);
|
keyClearImg = new GuiImage(keyMedium);
|
||||||
keyClearOverImg = new GuiImage(keyMedium);
|
keyClearOverImg = new GuiImage(keyMedium);
|
||||||
keyClearText = new GuiText("Clear", 20, ( GXColor )
|
keyClearText = new GuiText("Clear", 20, ( GXColor )
|
||||||
{ 0, 0, 0, 0xff});
|
{ 0, 0, 0, 0xff});
|
||||||
keyClear = new GuiButton(keyClearImg, keyClearOverImg, ALIGN_CENTRE, ALIGN_MIDDLE, -90, 80, trigA, btnSoundOver, btnSoundClick, 1);
|
keyClear = new GuiButton(keyClearImg, keyClearOverImg, ALIGN_CENTRE, ALIGN_MIDDLE, -90, 80, trigA, btnSoundOver, btnSoundClick, 1);
|
||||||
keyClear->SetLabel(keyClearText);
|
keyClear->SetLabel(keyClearText);
|
||||||
this->Append(keyClear);
|
this->Append(keyClear);
|
||||||
|
|
||||||
char txt[2] = { 0, 0 };
|
char txt[2] = { 0, 0 };
|
||||||
for (int i = 0; i < 11; i++)
|
for (int i = 0; i < 11; i++)
|
||||||
{
|
{
|
||||||
if (keys[i] != '\0')
|
if (keys[i] != '\0')
|
||||||
{
|
{
|
||||||
int col = i % 3;
|
int col = i % 3;
|
||||||
int row = i / 3;
|
int row = i / 3;
|
||||||
|
|
||||||
keyImg[i] = new GuiImage(keyMedium);
|
keyImg[i] = new GuiImage(keyMedium);
|
||||||
keyImgOver[i] = new GuiImage(keyMedium);
|
keyImgOver[i] = new GuiImage(keyMedium);
|
||||||
txt[0] = keys[i];
|
txt[0] = keys[i];
|
||||||
keyTxt[i] = new GuiText(txt, 20, ( GXColor )
|
keyTxt[i] = new GuiText(txt, 20, ( GXColor )
|
||||||
{ 0, 0, 0, 0xff});
|
{ 0, 0, 0, 0xff});
|
||||||
keyTxt[i]->SetAlignment(ALIGN_CENTRE, ALIGN_BOTTOM);
|
keyTxt[i]->SetAlignment(ALIGN_CENTRE, ALIGN_BOTTOM);
|
||||||
keyTxt[i]->SetPosition(0, -10);
|
keyTxt[i]->SetPosition(0, -10);
|
||||||
keyBtn[i] = new GuiButton(keyImg[i], keyImgOver[i], ALIGN_CENTRE, ALIGN_MIDDLE, -90 + 90 * col, -70 + 50
|
keyBtn[i] = new GuiButton(keyImg[i], keyImgOver[i], ALIGN_CENTRE, ALIGN_MIDDLE, -90 + 90 * col, -70 + 50
|
||||||
* row, trigA, btnSoundOver, btnSoundClick, 1);
|
* row, trigA, btnSoundOver, btnSoundClick, 1);
|
||||||
keyBtn[i]->SetLabel(keyTxt[i]);
|
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()
|
GuiNumpad::~GuiNumpad()
|
||||||
{
|
{
|
||||||
delete kbText;
|
delete kbText;
|
||||||
delete keyTextbox;
|
delete keyTextbox;
|
||||||
delete keyTextboxImg;
|
delete keyTextboxImg;
|
||||||
delete keyBackText;
|
delete keyBackText;
|
||||||
delete keyBackImg;
|
delete keyBackImg;
|
||||||
delete keyBackOverImg;
|
delete keyBackOverImg;
|
||||||
delete keyBack;
|
delete keyBack;
|
||||||
delete keyClear;
|
delete keyClear;
|
||||||
delete keyClearImg;
|
delete keyClearImg;
|
||||||
delete keyClearOverImg;
|
delete keyClearOverImg;
|
||||||
delete keyClearText;
|
delete keyClearText;
|
||||||
delete keyMedium;
|
delete keyMedium;
|
||||||
delete trigA;
|
delete trigA;
|
||||||
delete trigB;
|
delete trigB;
|
||||||
|
|
||||||
for (int i = 0; i < 11; i++)
|
for (int i = 0; i < 11; i++)
|
||||||
{
|
{
|
||||||
if (keys[i] != '\0')
|
if (keys[i] != '\0')
|
||||||
{
|
{
|
||||||
delete keyImg[i];
|
delete keyImg[i];
|
||||||
delete keyImgOver[i];
|
delete keyImgOver[i];
|
||||||
delete keyTxt[i];
|
delete keyTxt[i];
|
||||||
delete keyBtn[i];
|
delete keyBtn[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuiNumpad::Update(GuiTrigger * t)
|
void GuiNumpad::Update(GuiTrigger * t)
|
||||||
{
|
{
|
||||||
LOCK( this );
|
LOCK( this );
|
||||||
if (_elements.size() == 0 || (state == STATE_DISABLED && parentElement)) return;
|
if (_elements.size() == 0 || (state == STATE_DISABLED && parentElement)) return;
|
||||||
|
|
||||||
for (u8 i = 0; i < _elements.size(); i++)
|
for (u8 i = 0; i < _elements.size(); i++)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
_elements.at(i)->Update(t);
|
_elements.at(i)->Update(t);
|
||||||
}
|
}
|
||||||
catch (const std::exception& e)
|
catch (const std::exception& e)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (keyBack->GetState() == STATE_CLICKED)
|
if (keyBack->GetState() == STATE_CLICKED)
|
||||||
{
|
{
|
||||||
if (strlen(kbtextstr) > 0)
|
if (strlen(kbtextstr) > 0)
|
||||||
{
|
{
|
||||||
kbtextstr[strlen(kbtextstr) - 1] = 0;
|
kbtextstr[strlen(kbtextstr) - 1] = 0;
|
||||||
kbText->SetText(kbtextstr);
|
kbText->SetText(kbtextstr);
|
||||||
}
|
}
|
||||||
keyBack->SetState(STATE_SELECTED, t->chan);
|
keyBack->SetState(STATE_SELECTED, t->chan);
|
||||||
}
|
}
|
||||||
else if (keyClear->GetState() == STATE_CLICKED)
|
else if (keyClear->GetState() == STATE_CLICKED)
|
||||||
{
|
{
|
||||||
memset(kbtextstr, 0, sizeof(kbtextstr));
|
memset(kbtextstr, 0, sizeof(kbtextstr));
|
||||||
kbText->SetText(kbtextstr);
|
kbText->SetText(kbtextstr);
|
||||||
keyClear->SetState(STATE_SELECTED, t->chan);
|
keyClear->SetState(STATE_SELECTED, t->chan);
|
||||||
}
|
}
|
||||||
|
|
||||||
char txt[2] = { 0, 0 };
|
char txt[2] = { 0, 0 };
|
||||||
for (int i = 0; i < 11; i++)
|
for (int i = 0; i < 11; i++)
|
||||||
{
|
{
|
||||||
if (keys[i] != '\0')
|
if (keys[i] != '\0')
|
||||||
{
|
{
|
||||||
if (keyBtn[i]->GetState() == STATE_CLICKED)
|
if (keyBtn[i]->GetState() == STATE_CLICKED)
|
||||||
{
|
{
|
||||||
txt[0] = keys[i];
|
txt[0] = keys[i];
|
||||||
if (strlen(kbtextstr) < kbtextmaxlen - 1) // -1 --> kbtextmaxlen means with term. '\0'
|
if (strlen(kbtextstr) < kbtextmaxlen - 1) // -1 --> kbtextmaxlen means with term. '\0'
|
||||||
{
|
{
|
||||||
kbtextstr[strlen(kbtextstr)] = txt[0];
|
kbtextstr[strlen(kbtextstr)] = txt[0];
|
||||||
kbText->SetText(kbtextstr);
|
kbText->SetText(kbtextstr);
|
||||||
}
|
}
|
||||||
keyBtn[i]->SetState(STATE_SELECTED, t->chan);
|
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
|
if (focus) // only send actions to this window if it's in focus
|
||||||
{
|
{
|
||||||
// pad/joystick navigation
|
// pad/joystick navigation
|
||||||
if (t->Right())
|
if (t->Right())
|
||||||
this->MoveSelectionHor(1);
|
this->MoveSelectionHor(1);
|
||||||
else if (t->Left())
|
else if (t->Left())
|
||||||
this->MoveSelectionHor(-1);
|
this->MoveSelectionHor(-1);
|
||||||
else if (t->Down())
|
else if (t->Down())
|
||||||
this->MoveSelectionVert(1);
|
this->MoveSelectionVert(1);
|
||||||
else if (t->Up()) this->MoveSelectionVert(-1);
|
else if (t->Up()) this->MoveSelectionVert(-1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,67 +18,67 @@
|
||||||
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#define GAMESELECTSIZE 30
|
#define GAMESELECTSIZE 30
|
||||||
|
|
||||||
/**
|
/**
|
||||||
GuiOptionBrowser * Constructor for the GuiOptionBrowser class.
|
GuiOptionBrowser * Constructor for the GuiOptionBrowser class.
|
||||||
*/
|
*/
|
||||||
GuiOptionBrowser::GuiOptionBrowser(int w, int h, OptionList * l, const char * custombg)
|
GuiOptionBrowser::GuiOptionBrowser(int w, int h, OptionList * l, const char * custombg)
|
||||||
: scrollBar(h-10)
|
: scrollBar(h-10)
|
||||||
{
|
{
|
||||||
width = w;
|
width = w;
|
||||||
height = h;
|
height = h;
|
||||||
options = l;
|
options = l;
|
||||||
selectable = true;
|
selectable = true;
|
||||||
selectedItem = 0;
|
selectedItem = 0;
|
||||||
focus = 1; // allow focus
|
focus = 1; // allow focus
|
||||||
coL2 = 50;
|
coL2 = 50;
|
||||||
scrollbaron = false;
|
scrollbaron = false;
|
||||||
listChanged = true;
|
listChanged = true;
|
||||||
listOffset = 0;
|
listOffset = 0;
|
||||||
|
|
||||||
trigA = new GuiTrigger;
|
trigA = new GuiTrigger;
|
||||||
trigA->SetSimpleTrigger(-1, WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A, PAD_BUTTON_A);
|
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 = new GuiImage(bgOptions);
|
||||||
bgOptionsImg->SetParent(this);
|
bgOptionsImg->SetParent(this);
|
||||||
bgOptionsImg->SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE);
|
bgOptionsImg->SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE);
|
||||||
|
|
||||||
bgOptionsEntry = Resources::GetImageData("bg_options_entry.png");
|
bgOptionsEntry = Resources::GetImageData("bg_options_entry.png");
|
||||||
|
|
||||||
scrollBar.SetParent(this);
|
scrollBar.SetParent(this);
|
||||||
scrollBar.SetAlignment(thAlign("right - options browser scrollbar align hor"), thAlign("top - options browser scrollbar align ver"));
|
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.SetPosition(thInt("0 - options browser scrollbar pos x"), thInt("5 - options browser scrollbar pos y"));
|
||||||
scrollBar.listChanged.connect(this, &GuiOptionBrowser::onListChange);
|
scrollBar.listChanged.connect(this, &GuiOptionBrowser::onListChange);
|
||||||
|
|
||||||
for (int i = 0; i < PAGESIZE; i++)
|
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] = 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]->SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE);
|
||||||
optionTxt[i]->SetPosition(24, 0);
|
optionTxt[i]->SetPosition(24, 0);
|
||||||
optionTxt[i]->SetMaxWidth(bgOptionsImg->GetWidth()-scrollBar.GetWidth()-40, DOTTED);
|
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] = 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]->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] = 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]->SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE);
|
||||||
|
|
||||||
optionBtn[i] = new GuiButton(width - scrollBar.GetWidth(), GAMESELECTSIZE);
|
optionBtn[i] = new GuiButton(width - scrollBar.GetWidth(), GAMESELECTSIZE);
|
||||||
optionBtn[i]->SetParent(this);
|
optionBtn[i]->SetParent(this);
|
||||||
optionBtn[i]->SetLabel(optionTxt[i], 0);
|
optionBtn[i]->SetLabel(optionTxt[i], 0);
|
||||||
optionBtn[i]->SetLabel(optionVal[i], 1);
|
optionBtn[i]->SetLabel(optionVal[i], 1);
|
||||||
optionBtn[i]->SetLabelOver(optionValOver[i], 1);
|
optionBtn[i]->SetLabelOver(optionValOver[i], 1);
|
||||||
optionBtn[i]->SetImageOver(optionBg[i]);
|
optionBtn[i]->SetImageOver(optionBg[i]);
|
||||||
optionBtn[i]->SetPosition(10, GAMESELECTSIZE * i + 4);
|
optionBtn[i]->SetPosition(10, GAMESELECTSIZE * i + 4);
|
||||||
optionBtn[i]->SetRumble(false);
|
optionBtn[i]->SetRumble(false);
|
||||||
optionBtn[i]->SetTrigger(trigA);
|
optionBtn[i]->SetTrigger(trigA);
|
||||||
optionBtn[i]->SetSoundClick(btnSoundClick);
|
optionBtn[i]->SetSoundClick(btnSoundClick);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -86,91 +86,91 @@ GuiOptionBrowser::GuiOptionBrowser(int w, int h, OptionList * l, const char * cu
|
||||||
*/
|
*/
|
||||||
GuiOptionBrowser::~GuiOptionBrowser()
|
GuiOptionBrowser::~GuiOptionBrowser()
|
||||||
{
|
{
|
||||||
delete bgOptionsImg;
|
delete bgOptionsImg;
|
||||||
delete bgOptions;
|
delete bgOptions;
|
||||||
delete bgOptionsEntry;
|
delete bgOptionsEntry;
|
||||||
|
|
||||||
delete trigA;
|
delete trigA;
|
||||||
|
|
||||||
for (int i = 0; i < PAGESIZE; i++)
|
for (int i = 0; i < PAGESIZE; i++)
|
||||||
{
|
{
|
||||||
delete optionTxt[i];
|
delete optionTxt[i];
|
||||||
delete optionVal[i];
|
delete optionVal[i];
|
||||||
delete optionValOver[i];
|
delete optionValOver[i];
|
||||||
delete optionBg[i];
|
delete optionBg[i];
|
||||||
delete optionBtn[i];
|
delete optionBtn[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuiOptionBrowser::SetFocus(int f)
|
void GuiOptionBrowser::SetFocus(int f)
|
||||||
{
|
{
|
||||||
focus = f;
|
focus = f;
|
||||||
|
|
||||||
for (int i = 0; i < PAGESIZE; i++)
|
for (int i = 0; i < PAGESIZE; i++)
|
||||||
optionBtn[i]->ResetState();
|
optionBtn[i]->ResetState();
|
||||||
|
|
||||||
if (f == 1) optionBtn[selectedItem]->SetState(STATE_SELECTED);
|
if (f == 1) optionBtn[selectedItem]->SetState(STATE_SELECTED);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuiOptionBrowser::ResetState()
|
void GuiOptionBrowser::ResetState()
|
||||||
{
|
{
|
||||||
if (state != STATE_DISABLED)
|
if (state != STATE_DISABLED)
|
||||||
{
|
{
|
||||||
state = STATE_DEFAULT;
|
state = STATE_DEFAULT;
|
||||||
stateChan = -1;
|
stateChan = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < PAGESIZE; i++)
|
for (int i = 0; i < PAGESIZE; i++)
|
||||||
{
|
{
|
||||||
optionBtn[i]->ResetState();
|
optionBtn[i]->ResetState();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int GuiOptionBrowser::GetClickedOption()
|
int GuiOptionBrowser::GetClickedOption()
|
||||||
{
|
{
|
||||||
for (int i = 0; i < PAGESIZE; i++)
|
for (int i = 0; i < PAGESIZE; i++)
|
||||||
{
|
{
|
||||||
if (optionBtn[i]->GetState() == STATE_CLICKED)
|
if (optionBtn[i]->GetState() == STATE_CLICKED)
|
||||||
{
|
{
|
||||||
optionBtn[i]->SetState(STATE_SELECTED);
|
optionBtn[i]->SetState(STATE_SELECTED);
|
||||||
return optionIndex[i];
|
return optionIndex[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int GuiOptionBrowser::GetSelectedOption()
|
int GuiOptionBrowser::GetSelectedOption()
|
||||||
{
|
{
|
||||||
for (int i = 0; i < PAGESIZE; i++)
|
for (int i = 0; i < PAGESIZE; i++)
|
||||||
{
|
{
|
||||||
if (optionBtn[i]->GetState() == STATE_SELECTED)
|
if (optionBtn[i]->GetState() == STATE_SELECTED)
|
||||||
{
|
{
|
||||||
return optionIndex[i];
|
return optionIndex[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuiOptionBrowser::SetClickable(bool enable)
|
void GuiOptionBrowser::SetClickable(bool enable)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < PAGESIZE; i++)
|
for (int i = 0; i < PAGESIZE; i++)
|
||||||
{
|
{
|
||||||
optionBtn[i]->SetClickable(enable);
|
optionBtn[i]->SetClickable(enable);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuiOptionBrowser::SetOffset(int optionnumber)
|
void GuiOptionBrowser::SetOffset(int optionnumber)
|
||||||
{
|
{
|
||||||
listOffset = optionnumber;
|
listOffset = optionnumber;
|
||||||
selectedItem = optionnumber;
|
selectedItem = optionnumber;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuiOptionBrowser::onListChange(int SelItem, int SelInd)
|
void GuiOptionBrowser::onListChange(int SelItem, int SelInd)
|
||||||
{
|
{
|
||||||
selectedItem = SelItem;
|
selectedItem = SelItem;
|
||||||
listOffset = SelInd;
|
listOffset = SelInd;
|
||||||
UpdateListEntries();
|
UpdateListEntries();
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
|
@ -181,14 +181,14 @@ void GuiOptionBrowser::onListChange(int SelItem, int SelInd)
|
||||||
|
|
||||||
int GuiOptionBrowser::FindMenuItem(int currentItem, int direction)
|
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)
|
if (strlen(options->GetName(nextItem)) > 0)
|
||||||
return nextItem;
|
return nextItem;
|
||||||
|
|
||||||
return FindMenuItem(nextItem, direction);
|
return FindMenuItem(nextItem, direction);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -196,129 +196,129 @@ int GuiOptionBrowser::FindMenuItem(int currentItem, int direction)
|
||||||
*/
|
*/
|
||||||
void GuiOptionBrowser::Draw()
|
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++)
|
for (int i = 0; i < PAGESIZE; i++)
|
||||||
{
|
{
|
||||||
if (next >= 0)
|
if (next >= 0)
|
||||||
{
|
{
|
||||||
optionBtn[i]->Draw();
|
optionBtn[i]->Draw();
|
||||||
next = this->FindMenuItem(next, 1);
|
next = this->FindMenuItem(next, 1);
|
||||||
}
|
}
|
||||||
else break;
|
else break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (scrollbaron)
|
if (scrollbaron)
|
||||||
scrollBar.Draw();
|
scrollBar.Draw();
|
||||||
|
|
||||||
this->UpdateEffects();
|
this->UpdateEffects();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuiOptionBrowser::UpdateListEntries()
|
void GuiOptionBrowser::UpdateListEntries()
|
||||||
{
|
{
|
||||||
LOCK(this);
|
LOCK(this);
|
||||||
scrollbaron = options->GetLength() > PAGESIZE;
|
scrollbaron = options->GetLength() > PAGESIZE;
|
||||||
if (listOffset < 0) listOffset = this->FindMenuItem(-1, 1);
|
if (listOffset < 0) listOffset = this->FindMenuItem(-1, 1);
|
||||||
int next = listOffset;
|
int next = listOffset;
|
||||||
|
|
||||||
int maxNameWidth = 0;
|
int maxNameWidth = 0;
|
||||||
for (int i = 0; i < PAGESIZE; i++)
|
for (int i = 0; i < PAGESIZE; i++)
|
||||||
{
|
{
|
||||||
if (next >= 0)
|
if (next >= 0)
|
||||||
{
|
{
|
||||||
if (optionBtn[i]->GetState() == STATE_DISABLED)
|
if (optionBtn[i]->GetState() == STATE_DISABLED)
|
||||||
{
|
{
|
||||||
optionBtn[i]->SetVisible(true);
|
optionBtn[i]->SetVisible(true);
|
||||||
optionBtn[i]->SetState(STATE_DEFAULT);
|
optionBtn[i]->SetState(STATE_DEFAULT);
|
||||||
}
|
}
|
||||||
|
|
||||||
optionTxt[i]->SetText(options->GetName(next));
|
optionTxt[i]->SetText(options->GetName(next));
|
||||||
if (maxNameWidth < optionTxt[i]->GetTextWidth()) maxNameWidth = optionTxt[i]->GetTextWidth();
|
if (maxNameWidth < optionTxt[i]->GetTextWidth()) maxNameWidth = optionTxt[i]->GetTextWidth();
|
||||||
optionVal[i]->SetText(options->GetValue(next));
|
optionVal[i]->SetText(options->GetValue(next));
|
||||||
optionValOver[i]->SetText(options->GetValue(next));
|
optionValOver[i]->SetText(options->GetValue(next));
|
||||||
|
|
||||||
optionIndex[i] = next;
|
optionIndex[i] = next;
|
||||||
next = this->FindMenuItem(next, 1);
|
next = this->FindMenuItem(next, 1);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
optionBtn[i]->SetVisible(false);
|
optionBtn[i]->SetVisible(false);
|
||||||
optionBtn[i]->SetState(STATE_DISABLED);
|
optionBtn[i]->SetState(STATE_DISABLED);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (coL2 < (24 + maxNameWidth + 16))
|
if (coL2 < (24 + maxNameWidth + 16))
|
||||||
coL2 = 24 + maxNameWidth + 16;
|
coL2 = 24 + maxNameWidth + 16;
|
||||||
|
|
||||||
for (int i = 0; i < PAGESIZE; i++)
|
for (int i = 0; i < PAGESIZE; i++)
|
||||||
{
|
{
|
||||||
if (optionBtn[i]->GetState() != STATE_DISABLED)
|
if (optionBtn[i]->GetState() != STATE_DISABLED)
|
||||||
{
|
{
|
||||||
optionVal[i]->SetPosition(coL2, 0);
|
optionVal[i]->SetPosition(coL2, 0);
|
||||||
optionVal[i]->SetMaxWidth(bgOptionsImg->GetWidth() - (coL2 + scrollBar.GetWidth()+10), DOTTED);
|
optionVal[i]->SetMaxWidth(bgOptionsImg->GetWidth() - (coL2 + scrollBar.GetWidth()+10), DOTTED);
|
||||||
|
|
||||||
optionValOver[i]->SetPosition(coL2, 0);
|
optionValOver[i]->SetPosition(coL2, 0);
|
||||||
optionValOver[i]->SetMaxWidth(bgOptionsImg->GetWidth() - (coL2 + scrollBar.GetWidth()+10), SCROLL_HORIZONTAL);
|
optionValOver[i]->SetMaxWidth(bgOptionsImg->GetWidth() - (coL2 + scrollBar.GetWidth()+10), SCROLL_HORIZONTAL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuiOptionBrowser::Update(GuiTrigger * t)
|
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 |
|
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)) ||
|
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)))
|
(t->pad.btns_d & (PAD_BUTTON_UP | PAD_BUTTON_DOWN)))
|
||||||
pressedChan = t->chan;
|
pressedChan = t->chan;
|
||||||
|
|
||||||
if (scrollbaron)
|
if (scrollbaron)
|
||||||
// update the location of the scroll box based on the position in the option list
|
// update the location of the scroll box based on the position in the option list
|
||||||
scrollBar.Update(t);
|
scrollBar.Update(t);
|
||||||
|
|
||||||
int next = listOffset;
|
int next = listOffset;
|
||||||
|
|
||||||
if(pressedChan == -1 || (!t->wpad.btns_h && !t->pad.btns_h))
|
if(pressedChan == -1 || (!t->wpad.btns_h && !t->pad.btns_h))
|
||||||
{
|
{
|
||||||
for(int i = 0; i < PAGESIZE; i++)
|
for(int i = 0; i < PAGESIZE; i++)
|
||||||
{
|
{
|
||||||
if (next >= 0) next = this->FindMenuItem(next, 1);
|
if (next >= 0) next = this->FindMenuItem(next, 1);
|
||||||
|
|
||||||
if (i != selectedItem && optionBtn[i]->GetState() == STATE_SELECTED)
|
if (i != selectedItem && optionBtn[i]->GetState() == STATE_SELECTED)
|
||||||
{
|
{
|
||||||
optionBtn[i]->ResetState();
|
optionBtn[i]->ResetState();
|
||||||
}
|
}
|
||||||
else if (i == selectedItem && optionBtn[i]->GetState() == STATE_DEFAULT)
|
else if (i == selectedItem && optionBtn[i]->GetState() == STATE_DEFAULT)
|
||||||
{
|
{
|
||||||
optionBtn[selectedItem]->SetState(STATE_SELECTED);
|
optionBtn[selectedItem]->SetState(STATE_SELECTED);
|
||||||
}
|
}
|
||||||
|
|
||||||
optionBtn[i]->Update(t);
|
optionBtn[i]->Update(t);
|
||||||
|
|
||||||
if (optionBtn[i]->GetState() == STATE_SELECTED)
|
if (optionBtn[i]->GetState() == STATE_SELECTED)
|
||||||
selectedItem = i;
|
selectedItem = i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(pressedChan == t->chan && !t->wpad.btns_d && !t->wpad.btns_h)
|
if(pressedChan == t->chan && !t->wpad.btns_d && !t->wpad.btns_h)
|
||||||
pressedChan = -1;
|
pressedChan = -1;
|
||||||
|
|
||||||
scrollBar.SetPageSize(PAGESIZE);
|
scrollBar.SetPageSize(PAGESIZE);
|
||||||
scrollBar.SetSelectedItem(selectedItem);
|
scrollBar.SetSelectedItem(selectedItem);
|
||||||
scrollBar.SetSelectedIndex(listOffset);
|
scrollBar.SetSelectedIndex(listOffset);
|
||||||
scrollBar.SetEntrieCount(options->GetLength());
|
scrollBar.SetEntrieCount(options->GetLength());
|
||||||
|
|
||||||
if (options->IsChanged())
|
if (options->IsChanged())
|
||||||
{
|
{
|
||||||
UpdateListEntries();
|
UpdateListEntries();
|
||||||
listChanged = false;
|
listChanged = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (updateCB) updateCB(this);
|
if (updateCB) updateCB(this);
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,42 +8,42 @@
|
||||||
//!Display a list of menu options
|
//!Display a list of menu options
|
||||||
class GuiOptionBrowser: public GuiElement, public sigslot::has_slots<>
|
class GuiOptionBrowser: public GuiElement, public sigslot::has_slots<>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
GuiOptionBrowser(int w, int h, OptionList * l, const char * background);
|
GuiOptionBrowser(int w, int h, OptionList * l, const char * background);
|
||||||
virtual ~GuiOptionBrowser();
|
virtual ~GuiOptionBrowser();
|
||||||
int FindMenuItem(int c, int d);
|
int FindMenuItem(int c, int d);
|
||||||
int GetClickedOption();
|
int GetClickedOption();
|
||||||
int GetSelectedOption();
|
int GetSelectedOption();
|
||||||
void SetClickable(bool enable);
|
void SetClickable(bool enable);
|
||||||
void SetOffset(int optionnumber);
|
void SetOffset(int optionnumber);
|
||||||
void ResetState();
|
void ResetState();
|
||||||
void SetFocus(int f);
|
void SetFocus(int f);
|
||||||
void Draw();
|
void Draw();
|
||||||
void Update(GuiTrigger * t);
|
void Update(GuiTrigger * t);
|
||||||
protected:
|
protected:
|
||||||
void onListChange(int SelItem, int SelInd);
|
void onListChange(int SelItem, int SelInd);
|
||||||
void UpdateListEntries();
|
void UpdateListEntries();
|
||||||
int selectedItem;
|
int selectedItem;
|
||||||
int listOffset;
|
int listOffset;
|
||||||
int coL2;
|
int coL2;
|
||||||
bool scrollbaron;
|
bool scrollbaron;
|
||||||
bool listChanged;
|
bool listChanged;
|
||||||
|
|
||||||
OptionList * options;
|
OptionList * options;
|
||||||
int optionIndex[PAGESIZE];
|
int optionIndex[PAGESIZE];
|
||||||
GuiButton * optionBtn[PAGESIZE];
|
GuiButton * optionBtn[PAGESIZE];
|
||||||
GuiText * optionTxt[PAGESIZE];
|
GuiText * optionTxt[PAGESIZE];
|
||||||
GuiText * optionVal[PAGESIZE];
|
GuiText * optionVal[PAGESIZE];
|
||||||
GuiText * optionValOver[PAGESIZE];
|
GuiText * optionValOver[PAGESIZE];
|
||||||
GuiImage * optionBg[PAGESIZE];
|
GuiImage * optionBg[PAGESIZE];
|
||||||
|
|
||||||
GuiImage * bgOptionsImg;
|
GuiImage * bgOptionsImg;
|
||||||
|
|
||||||
GuiImageData * bgOptions;
|
GuiImageData * bgOptions;
|
||||||
GuiImageData * bgOptionsEntry;
|
GuiImageData * bgOptionsEntry;
|
||||||
|
|
||||||
GuiTrigger * trigA;
|
GuiTrigger * trigA;
|
||||||
GuiScrollbar scrollBar;
|
GuiScrollbar scrollBar;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -28,23 +28,23 @@
|
||||||
|
|
||||||
GuiScrollbar::GuiScrollbar(int h, u8 m)
|
GuiScrollbar::GuiScrollbar(int h, u8 m)
|
||||||
{
|
{
|
||||||
SelItem = 0;
|
SelItem = 0;
|
||||||
SelInd = 0;
|
SelInd = 0;
|
||||||
RowSize = 0;
|
RowSize = 0;
|
||||||
PageSize = 0;
|
PageSize = 0;
|
||||||
EntrieCount = 0;
|
EntrieCount = 0;
|
||||||
ScrollSpeed = 15;
|
ScrollSpeed = 15;
|
||||||
ButtonScroll = 0;
|
ButtonScroll = 0;
|
||||||
ButtonScrollSpeed = 20;
|
ButtonScrollSpeed = 20;
|
||||||
ScrollState = 0;
|
ScrollState = 0;
|
||||||
pressedChan = -1;
|
pressedChan = -1;
|
||||||
AllowDPad = true;
|
AllowDPad = true;
|
||||||
Mode = m;
|
Mode = m;
|
||||||
listChanged.connect(this, &GuiScrollbar::setScrollboxPosition);
|
listChanged.connect(this, &GuiScrollbar::setScrollboxPosition);
|
||||||
|
|
||||||
scrollbarTop = Resources::GetImageData("scrollBarTop.png");
|
scrollbarTop = Resources::GetImageData("scrollBarTop.png");
|
||||||
scrollbarBottom = Resources::GetImageData("scrollBarBottom.png");
|
scrollbarBottom = Resources::GetImageData("scrollBarBottom.png");
|
||||||
scrollbarTile = Resources::GetImageData("scrollBarTile.png");
|
scrollbarTile = Resources::GetImageData("scrollBarTile.png");
|
||||||
arrowDown = Resources::GetImageData("scrollbar_arrowdown.png");
|
arrowDown = Resources::GetImageData("scrollbar_arrowdown.png");
|
||||||
arrowDownOver = Resources::GetImageData("scrollbar_arrowdown.png");
|
arrowDownOver = Resources::GetImageData("scrollbar_arrowdown.png");
|
||||||
arrowUp = Resources::GetImageData("scrollbar_arrowup.png");
|
arrowUp = Resources::GetImageData("scrollbar_arrowup.png");
|
||||||
|
@ -53,20 +53,20 @@ GuiScrollbar::GuiScrollbar(int h, u8 m)
|
||||||
scrollbarBoxOver = Resources::GetImageData("scrollbar_box.png");
|
scrollbarBoxOver = Resources::GetImageData("scrollbar_box.png");
|
||||||
oneButtonScrollImgData = Resources::GetImageData("oneButtonScroll.png");
|
oneButtonScrollImgData = Resources::GetImageData("oneButtonScroll.png");
|
||||||
|
|
||||||
height = h;
|
height = h;
|
||||||
width = MAX(scrollbarBox->GetWidth(), scrollbarTile->GetWidth());
|
width = MAX(scrollbarBox->GetWidth(), scrollbarTile->GetWidth());
|
||||||
|
|
||||||
MinHeight = arrowUp->GetHeight();
|
MinHeight = arrowUp->GetHeight();
|
||||||
MaxHeight = height-scrollbarBox->GetHeight()-arrowDown->GetHeight();
|
MaxHeight = height-scrollbarBox->GetHeight()-arrowDown->GetHeight();
|
||||||
|
|
||||||
trigHeldA = new GuiTrigger;
|
trigHeldA = new GuiTrigger;
|
||||||
trigHeldA->SetHeldTrigger(-1, WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A, PAD_BUTTON_A);
|
trigHeldA->SetHeldTrigger(-1, WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A, PAD_BUTTON_A);
|
||||||
|
|
||||||
int Tiles = (height-scrollbarTop->GetHeight()-scrollbarBottom->GetHeight())/4;
|
int Tiles = (height-scrollbarTop->GetHeight()-scrollbarBottom->GetHeight())/4;
|
||||||
int PositionY = 0;
|
int PositionY = 0;
|
||||||
ButtonPositionX = 0;
|
ButtonPositionX = 0;
|
||||||
|
|
||||||
oneButtonScrollImg = new GuiImage(oneButtonScrollImgData);
|
oneButtonScrollImg = new GuiImage(oneButtonScrollImgData);
|
||||||
|
|
||||||
scrollbarTopImg = new GuiImage(scrollbarTop);
|
scrollbarTopImg = new GuiImage(scrollbarTop);
|
||||||
scrollbarTopImg->SetParent(this);
|
scrollbarTopImg->SetParent(this);
|
||||||
|
@ -103,7 +103,7 @@ GuiScrollbar::GuiScrollbar(int h, u8 m)
|
||||||
arrowUpBtn->SetTrigger(trigHeldA);
|
arrowUpBtn->SetTrigger(trigHeldA);
|
||||||
arrowUpBtn->SetSoundOver(btnSoundOver);
|
arrowUpBtn->SetSoundOver(btnSoundOver);
|
||||||
arrowUpBtn->SetSoundClick(btnSoundClick);
|
arrowUpBtn->SetSoundClick(btnSoundClick);
|
||||||
arrowUpBtn->Held.connect(this, &GuiScrollbar::OnUpButtonHold);
|
arrowUpBtn->Held.connect(this, &GuiScrollbar::OnUpButtonHold);
|
||||||
|
|
||||||
arrowDownBtn = new GuiButton(arrowDownImg->GetWidth(), arrowDownImg->GetHeight());
|
arrowDownBtn = new GuiButton(arrowDownImg->GetWidth(), arrowDownImg->GetHeight());
|
||||||
arrowDownBtn->SetParent(this);
|
arrowDownBtn->SetParent(this);
|
||||||
|
@ -115,7 +115,7 @@ GuiScrollbar::GuiScrollbar(int h, u8 m)
|
||||||
arrowDownBtn->SetTrigger(trigHeldA);
|
arrowDownBtn->SetTrigger(trigHeldA);
|
||||||
arrowDownBtn->SetSoundOver(btnSoundOver);
|
arrowDownBtn->SetSoundOver(btnSoundOver);
|
||||||
arrowDownBtn->SetSoundClick(btnSoundClick);
|
arrowDownBtn->SetSoundClick(btnSoundClick);
|
||||||
arrowDownBtn->Held.connect(this, &GuiScrollbar::OnDownButtonHold);
|
arrowDownBtn->Held.connect(this, &GuiScrollbar::OnDownButtonHold);
|
||||||
|
|
||||||
scrollbarBoxBtn = new GuiButton(scrollbarBoxImg->GetWidth(), scrollbarBoxImg->GetHeight());
|
scrollbarBoxBtn = new GuiButton(scrollbarBoxImg->GetWidth(), scrollbarBoxImg->GetHeight());
|
||||||
scrollbarBoxBtn->SetParent(this);
|
scrollbarBoxBtn->SetParent(this);
|
||||||
|
@ -127,7 +127,7 @@ GuiScrollbar::GuiScrollbar(int h, u8 m)
|
||||||
scrollbarBoxBtn->SetMaxY(MaxHeight);
|
scrollbarBoxBtn->SetMaxY(MaxHeight);
|
||||||
scrollbarBoxBtn->SetHoldable(true);
|
scrollbarBoxBtn->SetHoldable(true);
|
||||||
scrollbarBoxBtn->SetTrigger(trigHeldA);
|
scrollbarBoxBtn->SetTrigger(trigHeldA);
|
||||||
scrollbarBoxBtn->Held.connect(this, &GuiScrollbar::OnBoxButtonHold);
|
scrollbarBoxBtn->Held.connect(this, &GuiScrollbar::OnBoxButtonHold);
|
||||||
}
|
}
|
||||||
|
|
||||||
GuiScrollbar::~GuiScrollbar()
|
GuiScrollbar::~GuiScrollbar()
|
||||||
|
@ -163,22 +163,22 @@ GuiScrollbar::~GuiScrollbar()
|
||||||
|
|
||||||
void GuiScrollbar::ScrollOneUp()
|
void GuiScrollbar::ScrollOneUp()
|
||||||
{
|
{
|
||||||
if(Mode == ICONMODE)
|
if(Mode == ICONMODE)
|
||||||
{
|
{
|
||||||
if(SelInd+SelItem-RowSize >= 0)
|
if(SelInd+SelItem-RowSize >= 0)
|
||||||
{
|
{
|
||||||
SelItem = SelItem-RowSize;
|
SelItem = SelItem-RowSize;
|
||||||
if(SelItem < 0)
|
if(SelItem < 0)
|
||||||
{
|
{
|
||||||
// move list up by 1
|
// move list up by 1
|
||||||
SelInd = SelInd-RowSize;
|
SelInd = SelInd-RowSize;
|
||||||
SelItem = SelItem+RowSize;
|
SelItem = SelItem+RowSize;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(Mode == LISTMODE)
|
else if(Mode == LISTMODE)
|
||||||
{
|
{
|
||||||
if(SelItem == 0 && SelInd > 0)
|
if(SelItem == 0 && SelInd > 0)
|
||||||
{
|
{
|
||||||
// move list up by 1
|
// move list up by 1
|
||||||
--SelInd;
|
--SelInd;
|
||||||
|
@ -187,32 +187,32 @@ void GuiScrollbar::ScrollOneUp()
|
||||||
{
|
{
|
||||||
--SelItem;
|
--SelItem;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuiScrollbar::ScrollOneDown()
|
void GuiScrollbar::ScrollOneDown()
|
||||||
{
|
{
|
||||||
if(Mode == ICONMODE)
|
if(Mode == ICONMODE)
|
||||||
{
|
{
|
||||||
int i = RowSize;
|
int i = RowSize;
|
||||||
while(SelInd+SelItem+RowSize >= EntrieCount && i > 0 && SelItem > 0 && RowSize < EntrieCount)
|
while(SelInd+SelItem+RowSize >= EntrieCount && i > 0 && SelItem > 0 && RowSize < EntrieCount)
|
||||||
{
|
{
|
||||||
--i;
|
--i;
|
||||||
--SelItem;
|
--SelItem;
|
||||||
}
|
}
|
||||||
if(SelInd+SelItem+RowSize < EntrieCount)
|
if(SelInd+SelItem+RowSize < EntrieCount)
|
||||||
{
|
{
|
||||||
SelItem = SelItem+RowSize;
|
SelItem = SelItem+RowSize;
|
||||||
if(SelItem >= PageSize)
|
if(SelItem >= PageSize)
|
||||||
{
|
{
|
||||||
// move list down by 1
|
// move list down by 1
|
||||||
SelInd += RowSize;
|
SelInd += RowSize;
|
||||||
SelItem = SelItem-RowSize;
|
SelItem = SelItem-RowSize;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(Mode == LISTMODE)
|
else if(Mode == LISTMODE)
|
||||||
{
|
{
|
||||||
if(SelInd+SelItem + 1 < EntrieCount)
|
if(SelInd+SelItem + 1 < EntrieCount)
|
||||||
{
|
{
|
||||||
if(SelItem == PageSize-1)
|
if(SelItem == PageSize-1)
|
||||||
|
@ -225,232 +225,232 @@ void GuiScrollbar::ScrollOneDown()
|
||||||
SelItem++;
|
SelItem++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuiScrollbar::OnUpButtonHold(GuiButton *sender, int pointer, const POINT &p)
|
void GuiScrollbar::OnUpButtonHold(GuiButton *sender, int pointer, const POINT &p)
|
||||||
{
|
{
|
||||||
if(ScrollState < ScrollSpeed)
|
if(ScrollState < ScrollSpeed)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
ScrollOneUp();
|
ScrollOneUp();
|
||||||
|
|
||||||
ScrollState = 0;
|
ScrollState = 0;
|
||||||
listChanged(SelItem, SelInd);
|
listChanged(SelItem, SelInd);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuiScrollbar::OnDownButtonHold(GuiButton *sender, int pointer, const POINT &p)
|
void GuiScrollbar::OnDownButtonHold(GuiButton *sender, int pointer, const POINT &p)
|
||||||
{
|
{
|
||||||
if(ScrollState < ScrollSpeed)
|
if(ScrollState < ScrollSpeed)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
ScrollOneDown();
|
ScrollOneDown();
|
||||||
|
|
||||||
ScrollState = 0;
|
ScrollState = 0;
|
||||||
listChanged(SelItem, SelInd);
|
listChanged(SelItem, SelInd);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuiScrollbar::OnBoxButtonHold(GuiButton *sender, int pointer, const POINT &p)
|
void GuiScrollbar::OnBoxButtonHold(GuiButton *sender, int pointer, const POINT &p)
|
||||||
{
|
{
|
||||||
if(ScrollState < ScrollSpeed)
|
if(ScrollState < ScrollSpeed)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if(!userInput[pointer].wpad.ir.valid)
|
if(!userInput[pointer].wpad.ir.valid)
|
||||||
return;
|
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)
|
if(Mode == ICONMODE)
|
||||||
{
|
{
|
||||||
int rows = (int) floor(((float) (newSelected-SelInd-SelItem)) / ((float) RowSize));
|
int rows = (int) floor(((float) (newSelected-SelInd-SelItem)) / ((float) RowSize));
|
||||||
|
|
||||||
while(SelInd+rows*RowSize >= EntrieCount-PageSize+RowSize)
|
while(SelInd+rows*RowSize >= EntrieCount-PageSize+RowSize)
|
||||||
rows--;
|
rows--;
|
||||||
|
|
||||||
int pageIndex = LIMIT(SelInd+rows*RowSize, 0, EntrieCount-1-RowSize);
|
int pageIndex = LIMIT(SelInd+rows*RowSize, 0, EntrieCount-1-RowSize);
|
||||||
|
|
||||||
if(newSelected <= 0)
|
if(newSelected <= 0)
|
||||||
SelItem = 0;
|
SelItem = 0;
|
||||||
else if(newSelected >= EntrieCount-1)
|
else if(newSelected >= EntrieCount-1)
|
||||||
SelItem = EntrieCount-1-pageIndex;
|
SelItem = EntrieCount-1-pageIndex;
|
||||||
|
|
||||||
SelInd = pageIndex;
|
SelInd = pageIndex;
|
||||||
}
|
}
|
||||||
else if(Mode == LISTMODE)
|
else if(Mode == LISTMODE)
|
||||||
{
|
{
|
||||||
int diff = newSelected-SelInd-SelItem;
|
int diff = newSelected-SelInd-SelItem;
|
||||||
|
|
||||||
if(newSelected <= 0)
|
if(newSelected <= 0)
|
||||||
{
|
{
|
||||||
SelItem = 0;
|
SelItem = 0;
|
||||||
SelInd = 0;
|
SelInd = 0;
|
||||||
}
|
}
|
||||||
else if(newSelected >= EntrieCount-1)
|
else if(newSelected >= EntrieCount-1)
|
||||||
{
|
{
|
||||||
SelItem = (PageSize-1 < EntrieCount-1) ? PageSize-1 : EntrieCount-1;
|
SelItem = (PageSize-1 < EntrieCount-1) ? PageSize-1 : EntrieCount-1;
|
||||||
SelInd = EntrieCount-PageSize;
|
SelInd = EntrieCount-PageSize;
|
||||||
}
|
}
|
||||||
else if(newSelected < PageSize && SelInd == 0 && diff < 0)
|
else if(newSelected < PageSize && SelInd == 0 && diff < 0)
|
||||||
{
|
{
|
||||||
SelItem = MAX(SelItem+diff, 0);
|
SelItem = MAX(SelItem+diff, 0);
|
||||||
}
|
}
|
||||||
else if(EntrieCount-newSelected < PageSize && SelInd == EntrieCount-PageSize && diff > 0)
|
else if(EntrieCount-newSelected < PageSize && SelInd == EntrieCount-PageSize && diff > 0)
|
||||||
{
|
{
|
||||||
SelItem = MIN(SelItem+diff, PageSize-1);
|
SelItem = MIN(SelItem+diff, PageSize-1);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
SelInd = LIMIT(SelInd+diff, 0, ((EntrieCount-PageSize < 0) ? 0 : EntrieCount-PageSize));
|
SelInd = LIMIT(SelInd+diff, 0, ((EntrieCount-PageSize < 0) ? 0 : EntrieCount-PageSize));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ScrollState = 0;
|
ScrollState = 0;
|
||||||
listChanged(SelItem, SelInd);
|
listChanged(SelItem, SelInd);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuiScrollbar::SetPageSize(int size)
|
void GuiScrollbar::SetPageSize(int size)
|
||||||
{
|
{
|
||||||
if(PageSize == size)
|
if(PageSize == size)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
PageSize = size;
|
PageSize = size;
|
||||||
listChanged(SelItem, SelInd);
|
listChanged(SelItem, SelInd);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuiScrollbar::SetRowSize(int size)
|
void GuiScrollbar::SetRowSize(int size)
|
||||||
{
|
{
|
||||||
if(RowSize == size)
|
if(RowSize == size)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
RowSize = size;
|
RowSize = size;
|
||||||
listChanged(SelItem, SelInd);
|
listChanged(SelItem, SelInd);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuiScrollbar::SetSelectedItem(int pos)
|
void GuiScrollbar::SetSelectedItem(int pos)
|
||||||
{
|
{
|
||||||
if(SelItem == pos)
|
if(SelItem == pos)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
SelItem = pos;
|
SelItem = pos;
|
||||||
listChanged(SelItem, SelInd);
|
listChanged(SelItem, SelInd);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuiScrollbar::SetSelectedIndex(int pos)
|
void GuiScrollbar::SetSelectedIndex(int pos)
|
||||||
{
|
{
|
||||||
if(SelInd == pos)
|
if(SelInd == pos)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
SelInd = pos;
|
SelInd = pos;
|
||||||
listChanged(SelItem, SelInd);
|
listChanged(SelItem, SelInd);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuiScrollbar::SetEntrieCount(int cnt)
|
void GuiScrollbar::SetEntrieCount(int cnt)
|
||||||
{
|
{
|
||||||
if(EntrieCount == cnt)
|
if(EntrieCount == cnt)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
EntrieCount = cnt;
|
EntrieCount = cnt;
|
||||||
listChanged(SelItem, SelInd);
|
listChanged(SelItem, SelInd);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuiScrollbar::setScrollboxPosition(int SelItem, int SelInd)
|
void GuiScrollbar::setScrollboxPosition(int SelItem, int SelInd)
|
||||||
{
|
{
|
||||||
if(Mode == ICONMODE)
|
if(Mode == ICONMODE)
|
||||||
{
|
{
|
||||||
u8 row = (u8) floor((float) SelItem / (float) RowSize);
|
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)
|
if(position < MinHeight)
|
||||||
position = MinHeight;
|
position = MinHeight;
|
||||||
else if(position > MaxHeight || ((SelInd+PageSize >= (EntrieCount-1)) && row > 1))
|
else if(position > MaxHeight || ((SelInd+PageSize >= (EntrieCount-1)) && row > 1))
|
||||||
position = MaxHeight;
|
position = MaxHeight;
|
||||||
|
|
||||||
scrollbarBoxBtn->SetPosition(ButtonPositionX, position);
|
scrollbarBoxBtn->SetPosition(ButtonPositionX, position);
|
||||||
}
|
}
|
||||||
else if(Mode == LISTMODE)
|
else if(Mode == LISTMODE)
|
||||||
{
|
{
|
||||||
int position = MinHeight+(MaxHeight-MinHeight)*(SelInd+SelItem)/(EntrieCount-1);
|
int position = MinHeight+(MaxHeight-MinHeight)*(SelInd+SelItem)/(EntrieCount-1);
|
||||||
|
|
||||||
if(position < MinHeight)
|
if(position < MinHeight)
|
||||||
position = MinHeight;
|
position = MinHeight;
|
||||||
else if(position > MaxHeight || (SelInd+SelItem >= EntrieCount-1))
|
else if(position > MaxHeight || (SelInd+SelItem >= EntrieCount-1))
|
||||||
position = MaxHeight;
|
position = MaxHeight;
|
||||||
|
|
||||||
scrollbarBoxBtn->SetPosition(ButtonPositionX, position);
|
scrollbarBoxBtn->SetPosition(ButtonPositionX, position);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuiScrollbar::CheckDPadControls(GuiTrigger *t)
|
void GuiScrollbar::CheckDPadControls(GuiTrigger *t)
|
||||||
{
|
{
|
||||||
if(t->Up())
|
if(t->Up())
|
||||||
{
|
{
|
||||||
ScrollOneUp();
|
ScrollOneUp();
|
||||||
listChanged(SelItem, SelInd);
|
listChanged(SelItem, SelInd);
|
||||||
}
|
}
|
||||||
else if(t->Down())
|
else if(t->Down())
|
||||||
{
|
{
|
||||||
ScrollOneDown();
|
ScrollOneDown();
|
||||||
listChanged(SelItem, SelInd);
|
listChanged(SelItem, SelInd);
|
||||||
}
|
}
|
||||||
|
|
||||||
else if(t->Left() && Mode == LISTMODE)
|
else if(t->Left() && Mode == LISTMODE)
|
||||||
{
|
{
|
||||||
SelInd -= PageSize;
|
SelInd -= PageSize;
|
||||||
if(SelInd < 0)
|
if(SelInd < 0)
|
||||||
{
|
{
|
||||||
SelInd = 0;
|
SelInd = 0;
|
||||||
SelItem = 0;
|
SelItem = 0;
|
||||||
}
|
}
|
||||||
listChanged(SelItem, SelInd);
|
listChanged(SelItem, SelInd);
|
||||||
}
|
}
|
||||||
else if(t->Right() && Mode == LISTMODE)
|
else if(t->Right() && Mode == LISTMODE)
|
||||||
{
|
{
|
||||||
SelInd += PageSize;
|
SelInd += PageSize;
|
||||||
if(SelInd+PageSize >= EntrieCount)
|
if(SelInd+PageSize >= EntrieCount)
|
||||||
{
|
{
|
||||||
SelInd = EntrieCount-PageSize;
|
SelInd = EntrieCount-PageSize;
|
||||||
SelItem = PageSize-1;
|
SelItem = PageSize-1;
|
||||||
}
|
}
|
||||||
listChanged(SelItem, SelInd);
|
listChanged(SelItem, SelInd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuiScrollbar::ScrollByButton(GuiTrigger *t)
|
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)
|
if(!t->wpad.ir.valid || ScrollState < ButtonScrollSpeed-ButtonScrollSpeed*fabs(pressedPosition-t->wpad.ir.y)/250.f)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if(pressedChan == -1 && (t->wpad.btns_d & ButtonScroll) &&
|
if(pressedChan == -1 && (t->wpad.btns_d & ButtonScroll) &&
|
||||||
parentElement && parentElement->IsInside(t->wpad.ir.x, t->wpad.ir.y))
|
parentElement && parentElement->IsInside(t->wpad.ir.x, t->wpad.ir.y))
|
||||||
{
|
{
|
||||||
pressedPosition = t->wpad.ir.y;
|
pressedPosition = t->wpad.ir.y;
|
||||||
pressedChan = t->chan;
|
pressedChan = t->chan;
|
||||||
oneButtonScrollImg->SetPosition(t->wpad.ir.x-oneButtonScrollImg->GetWidth()/2, t->wpad.ir.y-oneButtonScrollImg->GetHeight()/2);
|
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(pressedChan == t->chan && (t->wpad.btns_h & ButtonScroll))
|
||||||
{
|
{
|
||||||
if(pressedPosition-oneButtonScrollImg->GetHeight()/2 > t->wpad.ir.y)
|
if(pressedPosition-oneButtonScrollImg->GetHeight()/2 > t->wpad.ir.y)
|
||||||
ScrollOneUp();
|
ScrollOneUp();
|
||||||
else if(pressedPosition+oneButtonScrollImg->GetHeight()/2 < t->wpad.ir.y)
|
else if(pressedPosition+oneButtonScrollImg->GetHeight()/2 < t->wpad.ir.y)
|
||||||
ScrollOneDown();
|
ScrollOneDown();
|
||||||
|
|
||||||
ScrollState = 0;
|
ScrollState = 0;
|
||||||
listChanged(SelItem, SelInd);
|
listChanged(SelItem, SelInd);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(pressedChan == t->chan && !t->wpad.btns_d && !t->wpad.btns_h)
|
if(pressedChan == t->chan && !t->wpad.btns_d && !t->wpad.btns_h)
|
||||||
{
|
{
|
||||||
pressedChan = -1;
|
pressedChan = -1;
|
||||||
pressedPosition = -1;
|
pressedPosition = -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuiScrollbar::Draw()
|
void GuiScrollbar::Draw()
|
||||||
|
@ -462,7 +462,7 @@ void GuiScrollbar::Draw()
|
||||||
arrowDownBtn->Draw();
|
arrowDownBtn->Draw();
|
||||||
scrollbarBoxBtn->Draw();
|
scrollbarBoxBtn->Draw();
|
||||||
if(pressedChan >= 0 && userInput[pressedChan].wpad.ir.valid)
|
if(pressedChan >= 0 && userInput[pressedChan].wpad.ir.valid)
|
||||||
oneButtonScrollImg->Draw();
|
oneButtonScrollImg->Draw();
|
||||||
|
|
||||||
UpdateEffects();
|
UpdateEffects();
|
||||||
}
|
}
|
||||||
|
@ -472,10 +472,10 @@ void GuiScrollbar::Update(GuiTrigger * t)
|
||||||
arrowUpBtn->Update(t);
|
arrowUpBtn->Update(t);
|
||||||
arrowDownBtn->Update(t);
|
arrowDownBtn->Update(t);
|
||||||
scrollbarBoxBtn->Update(t);
|
scrollbarBoxBtn->Update(t);
|
||||||
if(AllowDPad)
|
if(AllowDPad)
|
||||||
CheckDPadControls(t);
|
CheckDPadControls(t);
|
||||||
if(ButtonScroll)
|
if(ButtonScroll)
|
||||||
ScrollByButton(t);
|
ScrollByButton(t);
|
||||||
|
|
||||||
++ScrollState;
|
++ScrollState;
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,57 +28,57 @@
|
||||||
|
|
||||||
class GuiScrollbar : public GuiElement, public sigslot::has_slots<>
|
class GuiScrollbar : public GuiElement, public sigslot::has_slots<>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
GuiScrollbar(int height, u8 mode = LISTMODE);
|
GuiScrollbar(int height, u8 mode = LISTMODE);
|
||||||
virtual ~GuiScrollbar();
|
virtual ~GuiScrollbar();
|
||||||
void SetDPadControl(bool a) { AllowDPad = a; }
|
void SetDPadControl(bool a) { AllowDPad = a; }
|
||||||
void SetButtonScroll(u32 button) { ButtonScroll = button; }
|
void SetButtonScroll(u32 button) { ButtonScroll = button; }
|
||||||
void ScrollOneUp();
|
void ScrollOneUp();
|
||||||
void ScrollOneDown();
|
void ScrollOneDown();
|
||||||
int GetSelectedItem() { return SelItem; };
|
int GetSelectedItem() { return SelItem; };
|
||||||
int GetSelectedIndex() { return SelInd; };
|
int GetSelectedIndex() { return SelInd; };
|
||||||
void SetScrollSpeed(u16 speed) { ScrollSpeed = speed; };
|
void SetScrollSpeed(u16 speed) { ScrollSpeed = speed; };
|
||||||
void SetButtonScrollSpeed(u16 speed) { ButtonScrollSpeed = speed; };
|
void SetButtonScrollSpeed(u16 speed) { ButtonScrollSpeed = speed; };
|
||||||
void Draw();
|
void Draw();
|
||||||
void Update(GuiTrigger * t);
|
void Update(GuiTrigger * t);
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
ICONMODE = 0,
|
ICONMODE = 0,
|
||||||
LISTMODE,
|
LISTMODE,
|
||||||
};
|
};
|
||||||
//! Signals
|
//! Signals
|
||||||
sigslot::signal2<int, int> listChanged;
|
sigslot::signal2<int, int> listChanged;
|
||||||
//! Slots
|
//! Slots
|
||||||
void SetPageSize(int size);
|
void SetPageSize(int size);
|
||||||
void SetRowSize(int size);
|
void SetRowSize(int size);
|
||||||
void SetSelectedItem(int pos);
|
void SetSelectedItem(int pos);
|
||||||
void SetSelectedIndex(int pos);
|
void SetSelectedIndex(int pos);
|
||||||
void SetEntrieCount(int cnt);
|
void SetEntrieCount(int cnt);
|
||||||
protected:
|
protected:
|
||||||
void setScrollboxPosition(int SelItem, int SelInd);
|
void setScrollboxPosition(int SelItem, int SelInd);
|
||||||
void OnUpButtonHold(GuiButton *sender, int pointer, const POINT &p);
|
void OnUpButtonHold(GuiButton *sender, int pointer, const POINT &p);
|
||||||
void OnDownButtonHold(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 OnBoxButtonHold(GuiButton *sender, int pointer, const POINT &p);
|
||||||
void CheckDPadControls(GuiTrigger *t);
|
void CheckDPadControls(GuiTrigger *t);
|
||||||
void ScrollByButton(GuiTrigger *t);
|
void ScrollByButton(GuiTrigger *t);
|
||||||
|
|
||||||
u8 Mode;
|
u8 Mode;
|
||||||
u32 ScrollState;
|
u32 ScrollState;
|
||||||
u16 ScrollSpeed;
|
u16 ScrollSpeed;
|
||||||
u16 ButtonScrollSpeed;
|
u16 ButtonScrollSpeed;
|
||||||
u32 ButtonScroll;
|
u32 ButtonScroll;
|
||||||
bool AllowDPad;
|
bool AllowDPad;
|
||||||
|
|
||||||
int MinHeight;
|
int MinHeight;
|
||||||
int MaxHeight;
|
int MaxHeight;
|
||||||
int SelItem;
|
int SelItem;
|
||||||
int SelInd;
|
int SelInd;
|
||||||
int RowSize;
|
int RowSize;
|
||||||
int PageSize;
|
int PageSize;
|
||||||
int EntrieCount;
|
int EntrieCount;
|
||||||
int ButtonPositionX;
|
int ButtonPositionX;
|
||||||
int pressedChan;
|
int pressedChan;
|
||||||
bool listchanged;
|
bool listchanged;
|
||||||
|
|
||||||
GuiButton * arrowUpBtn;
|
GuiButton * arrowUpBtn;
|
||||||
GuiButton * arrowDownBtn;
|
GuiButton * arrowDownBtn;
|
||||||
|
|
|
@ -11,157 +11,157 @@ extern GuiWindow * mainWindow;
|
||||||
|
|
||||||
class cSearchButton
|
class cSearchButton
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
cSearchButton(wchar_t *Char, GuiImageData *keyImageData, GuiImageData *keyOverImageData, int x, int y,
|
cSearchButton(wchar_t *Char, GuiImageData *keyImageData, GuiImageData *keyOverImageData, int x, int y,
|
||||||
GuiTrigger* trig, GuiSound* sndOver, GuiSound* sndClick) :
|
GuiTrigger* trig, GuiSound* sndOver, GuiSound* sndClick) :
|
||||||
wchar(*Char), image(keyImageData), imageOver(keyOverImageData), text((char *) NULL, 20, ( GXColor )
|
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)
|
{ 0, 0, 0, 0xff}), button(&image, &imageOver, ALIGN_LEFT, ALIGN_TOP, x, y, trig, sndOver, sndClick, 1)
|
||||||
{
|
{
|
||||||
text.SetText(Char);
|
text.SetText(Char);
|
||||||
button.SetLabel(&text);
|
button.SetLabel(&text);
|
||||||
}
|
}
|
||||||
wchar_t wchar;
|
wchar_t wchar;
|
||||||
GuiImage image;
|
GuiImage image;
|
||||||
GuiImage imageOver;
|
GuiImage imageOver;
|
||||||
GuiText text;
|
GuiText text;
|
||||||
GuiButton button;
|
GuiButton button;
|
||||||
private:
|
private:
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
GuiSearchBar::GuiSearchBar(const wchar_t *SearchChars) :
|
GuiSearchBar::GuiSearchBar(const wchar_t *SearchChars) :
|
||||||
inSide(0), text((char *) NULL, 22, ( GXColor )
|
inSide(0), text((char *) NULL, 22, ( GXColor )
|
||||||
{ 0, 0, 0, 255}), buttons(0),
|
{ 0, 0, 0, 255}), buttons(0),
|
||||||
keyImageData(Resources::GetFile("keyboard_key.png"), Resources::GetFileSize("keyboard_key.png")),
|
keyImageData(Resources::GetFile("keyboard_key.png"), Resources::GetFileSize("keyboard_key.png")),
|
||||||
keyOverImageData(Resources::GetFile("keyboard_key_over.png"), Resources::GetFileSize("keyboard_key_over.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);
|
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);
|
trigB.SetButtonOnlyTrigger(-1, WPAD_BUTTON_B | WPAD_CLASSIC_BUTTON_B, PAD_BUTTON_B);
|
||||||
SetAlignment(ALIGN_CENTRE, ALIGN_MIDDLE);
|
SetAlignment(ALIGN_CENTRE, ALIGN_MIDDLE);
|
||||||
|
|
||||||
cnt = wcslen(SearchChars);
|
cnt = wcslen(SearchChars);
|
||||||
buttons = new cSearchButton*[cnt];
|
buttons = new cSearchButton*[cnt];
|
||||||
|
|
||||||
wchar_t charstr[2] = { 0, 0 };
|
wchar_t charstr[2] = { 0, 0 };
|
||||||
int lines = (cnt + 9) / 10;
|
int lines = (cnt + 9) / 10;
|
||||||
int buttonsPerLine = (cnt + lines - 1) / lines;
|
int buttonsPerLine = (cnt + lines - 1) / lines;
|
||||||
width = 10 + buttonsPerLine * 42 + 10;
|
width = 10 + buttonsPerLine * 42 + 10;
|
||||||
int x_start = 10, x = 0, y_start = 10 + 42, y = 0;
|
int x_start = 10, x = 0, y_start = 10 + 42, y = 0;
|
||||||
if (width < 200)
|
if (width < 200)
|
||||||
{
|
{
|
||||||
x_start += (200 - width) >> 1;
|
x_start += (200 - width) >> 1;
|
||||||
width = 200;
|
width = 200;
|
||||||
}
|
}
|
||||||
for (int i = 0; i < cnt; i++, x++)
|
for (int i = 0; i < cnt; i++, x++)
|
||||||
{
|
{
|
||||||
if (x >= buttonsPerLine) x = 0;
|
if (x >= buttonsPerLine) x = 0;
|
||||||
if (x == 0) y++;
|
if (x == 0) y++;
|
||||||
charstr[0] = SearchChars[i];
|
charstr[0] = SearchChars[i];
|
||||||
buttons[i] = new cSearchButton(charstr, &keyImageData, &keyOverImageData, x_start + x * 42, y_start - 42 + y
|
buttons[i] = new cSearchButton(charstr, &keyImageData, &keyOverImageData, x_start + x * 42, y_start - 42 + y
|
||||||
* 42, &trig, btnSoundOver, btnSoundClick);
|
* 42, &trig, btnSoundOver, btnSoundClick);
|
||||||
this->Append(&(buttons[i]->button));
|
this->Append(&(buttons[i]->button));
|
||||||
}
|
}
|
||||||
height = 10 + 42 + y * 42 + 10;
|
height = 10 + 42 + y * 42 + 10;
|
||||||
|
|
||||||
text.SetText(gameList.GetCurrentFilter());
|
text.SetText(gameList.GetCurrentFilter());
|
||||||
text.SetPosition(10, 15);
|
text.SetPosition(10, 15);
|
||||||
text.SetAlignment(ALIGN_LEFT, ALIGN_TOP);
|
text.SetAlignment(ALIGN_LEFT, ALIGN_TOP);
|
||||||
text.SetWidescreen(Settings.widescreen);
|
text.SetWidescreen(Settings.widescreen);
|
||||||
text.SetMaxWidth(width - (10 + 2 * 42 + 10), SCROLL_HORIZONTAL);
|
text.SetMaxWidth(width - (10 + 2 * 42 + 10), SCROLL_HORIZONTAL);
|
||||||
this->Append(&text);
|
this->Append(&text);
|
||||||
|
|
||||||
imgBacspaceBtn = Resources::GetImageData("keyboard_backspace_over.png");
|
imgBacspaceBtn = Resources::GetImageData("keyboard_backspace_over.png");
|
||||||
BacspaceBtnImg_Over = new GuiImage(imgBacspaceBtn);
|
BacspaceBtnImg_Over = new GuiImage(imgBacspaceBtn);
|
||||||
BacspaceBtnImg = new GuiImage(BacspaceBtnImg_Over);
|
BacspaceBtnImg = new GuiImage(BacspaceBtnImg_Over);
|
||||||
BacspaceBtnImg->SetGrayscale();
|
BacspaceBtnImg->SetGrayscale();
|
||||||
BacspaceBtn = new GuiButton(BacspaceBtnImg, BacspaceBtnImg_Over, ALIGN_RIGHT, ALIGN_TOP, -52, 10, &trig, btnSoundOver, btnSoundClick, 1);
|
BacspaceBtn = new GuiButton(BacspaceBtnImg, BacspaceBtnImg_Over, ALIGN_RIGHT, ALIGN_TOP, -52, 10, &trig, btnSoundOver, btnSoundClick, 1);
|
||||||
this->Append(BacspaceBtn);
|
this->Append(BacspaceBtn);
|
||||||
|
|
||||||
imgClearBtn = Resources::GetImageData("keyboard_clear_over.png");
|
imgClearBtn = Resources::GetImageData("keyboard_clear_over.png");
|
||||||
ClearBtnImg_Over = new GuiImage(imgClearBtn);
|
ClearBtnImg_Over = new GuiImage(imgClearBtn);
|
||||||
ClearBtnImg = new GuiImage(ClearBtnImg_Over);
|
ClearBtnImg = new GuiImage(ClearBtnImg_Over);
|
||||||
ClearBtnImg->SetGrayscale();
|
ClearBtnImg->SetGrayscale();
|
||||||
ClearBtn = new GuiButton(ClearBtnImg, ClearBtnImg_Over, ALIGN_RIGHT, ALIGN_TOP, -10, 10, &trig, btnSoundOver, btnSoundClick, 1);
|
ClearBtn = new GuiButton(ClearBtnImg, ClearBtnImg_Over, ALIGN_RIGHT, ALIGN_TOP, -10, 10, &trig, btnSoundOver, btnSoundClick, 1);
|
||||||
this->Append(ClearBtn);
|
this->Append(ClearBtn);
|
||||||
|
|
||||||
CloseBtn = new GuiButton(0, 0);
|
CloseBtn = new GuiButton(0, 0);
|
||||||
CloseBtn->SetTrigger(&trigB);
|
CloseBtn->SetTrigger(&trigB);
|
||||||
this->Append(CloseBtn);
|
this->Append(CloseBtn);
|
||||||
|
|
||||||
// SetPosition(100,100);
|
// SetPosition(100,100);
|
||||||
|
|
||||||
}
|
}
|
||||||
GuiSearchBar::~GuiSearchBar()
|
GuiSearchBar::~GuiSearchBar()
|
||||||
{
|
{
|
||||||
if (buttons)
|
if (buttons)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < cnt; i++)
|
for (int i = 0; i < cnt; i++)
|
||||||
delete buttons[i];
|
delete buttons[i];
|
||||||
delete[] buttons;
|
delete[] buttons;
|
||||||
}
|
}
|
||||||
delete ClearBtn;
|
delete ClearBtn;
|
||||||
delete ClearBtnImg;
|
delete ClearBtnImg;
|
||||||
delete ClearBtnImg_Over;
|
delete ClearBtnImg_Over;
|
||||||
delete imgClearBtn;
|
delete imgClearBtn;
|
||||||
|
|
||||||
delete CloseBtn;
|
delete CloseBtn;
|
||||||
|
|
||||||
delete BacspaceBtn;
|
delete BacspaceBtn;
|
||||||
delete BacspaceBtnImg;
|
delete BacspaceBtnImg;
|
||||||
delete BacspaceBtnImg_Over;
|
delete BacspaceBtnImg_Over;
|
||||||
delete imgBacspaceBtn;
|
delete imgBacspaceBtn;
|
||||||
if (inSide) mainWindow->SetState(STATE_DEFAULT);
|
if (inSide) mainWindow->SetState(STATE_DEFAULT);
|
||||||
}
|
}
|
||||||
void GuiSearchBar::Draw()
|
void GuiSearchBar::Draw()
|
||||||
{
|
{
|
||||||
Menu_DrawRectangle(this->GetLeft(), this->GetTop(), width, height, ( GXColor )
|
Menu_DrawRectangle(this->GetLeft(), this->GetTop(), width, height, ( GXColor )
|
||||||
{ 0, 0, 0, 0xa0}, 1);
|
{ 0, 0, 0, 0xa0}, 1);
|
||||||
Menu_DrawRectangle(this->GetLeft() + 10, this->GetTop() + 15, width - (10 + 2 * 42 + 10), 22, ( GXColor )
|
Menu_DrawRectangle(this->GetLeft() + 10, this->GetTop() + 15, width - (10 + 2 * 42 + 10), 22, ( GXColor )
|
||||||
{ 255, 255, 255, 255}, 1);
|
{ 255, 255, 255, 255}, 1);
|
||||||
GuiWindow::Draw();
|
GuiWindow::Draw();
|
||||||
}
|
}
|
||||||
void GuiSearchBar::Update(GuiTrigger * t)
|
void GuiSearchBar::Update(GuiTrigger * t)
|
||||||
{
|
{
|
||||||
LOCK( this );
|
LOCK( this );
|
||||||
if (_elements.size() == 0 || (state == STATE_DISABLED && parentElement)) return;
|
if (_elements.size() == 0 || (state == STATE_DISABLED && parentElement)) return;
|
||||||
// cursor
|
// cursor
|
||||||
if (t->wpad.ir.valid && state != STATE_DISABLED)
|
if (t->wpad.ir.valid && state != STATE_DISABLED)
|
||||||
{
|
{
|
||||||
if (this->IsInside(t->wpad.ir.x, t->wpad.ir.y))
|
if (this->IsInside(t->wpad.ir.x, t->wpad.ir.y))
|
||||||
{
|
{
|
||||||
if (inSide == 0)
|
if (inSide == 0)
|
||||||
{
|
{
|
||||||
mainWindow->SetState(STATE_DISABLED);
|
mainWindow->SetState(STATE_DISABLED);
|
||||||
this->SetState(STATE_DEFAULT);
|
this->SetState(STATE_DEFAULT);
|
||||||
}
|
}
|
||||||
inSide |= 1 << t->chan;
|
inSide |= 1 << t->chan;
|
||||||
}
|
}
|
||||||
else if (inSide)
|
else if (inSide)
|
||||||
{
|
{
|
||||||
inSide &= ~(1 << t->chan);
|
inSide &= ~(1 << t->chan);
|
||||||
if (inSide == 0) mainWindow->SetState(STATE_DEFAULT);
|
if (inSide == 0) mainWindow->SetState(STATE_DEFAULT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
GuiWindow::Update(t);
|
GuiWindow::Update(t);
|
||||||
}
|
}
|
||||||
wchar_t GuiSearchBar::GetClicked()
|
wchar_t GuiSearchBar::GetClicked()
|
||||||
{
|
{
|
||||||
if (buttons)
|
if (buttons)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < cnt; i++)
|
for (int i = 0; i < cnt; i++)
|
||||||
{
|
{
|
||||||
if (buttons[i]->button.GetState() == STATE_CLICKED)
|
if (buttons[i]->button.GetState() == STATE_CLICKED)
|
||||||
{
|
{
|
||||||
buttons[i]->button.ResetState();
|
buttons[i]->button.ResetState();
|
||||||
return buttons[i]->wchar;
|
return buttons[i]->wchar;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (BacspaceBtn->GetState() == STATE_CLICKED) return 8;
|
if (BacspaceBtn->GetState() == STATE_CLICKED) return 8;
|
||||||
else if (ClearBtn->GetState() == STATE_CLICKED) return 7;
|
else if (ClearBtn->GetState() == STATE_CLICKED) return 7;
|
||||||
else if (CloseBtn->GetState() == STATE_CLICKED) return 27;
|
else if (CloseBtn->GetState() == STATE_CLICKED) return 27;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -6,35 +6,35 @@ class cSearchButton;
|
||||||
|
|
||||||
class GuiSearchBar: public GuiWindow
|
class GuiSearchBar: public GuiWindow
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
GuiSearchBar(const wchar_t *SearchChars);
|
GuiSearchBar(const wchar_t *SearchChars);
|
||||||
virtual ~GuiSearchBar();
|
virtual ~GuiSearchBar();
|
||||||
void Draw();
|
void Draw();
|
||||||
void Update(GuiTrigger * t);
|
void Update(GuiTrigger * t);
|
||||||
wchar_t GetClicked();
|
wchar_t GetClicked();
|
||||||
private:
|
private:
|
||||||
u16 inSide;
|
u16 inSide;
|
||||||
|
|
||||||
GuiText text;
|
GuiText text;
|
||||||
|
|
||||||
GuiImageData* imgBacspaceBtn;
|
GuiImageData* imgBacspaceBtn;
|
||||||
GuiImage* BacspaceBtnImg;
|
GuiImage* BacspaceBtnImg;
|
||||||
GuiImage* BacspaceBtnImg_Over;
|
GuiImage* BacspaceBtnImg_Over;
|
||||||
GuiButton* BacspaceBtn;
|
GuiButton* BacspaceBtn;
|
||||||
|
|
||||||
GuiImageData* imgClearBtn;
|
GuiImageData* imgClearBtn;
|
||||||
GuiImage* ClearBtnImg;
|
GuiImage* ClearBtnImg;
|
||||||
GuiImage* ClearBtnImg_Over;
|
GuiImage* ClearBtnImg_Over;
|
||||||
GuiButton* ClearBtn;
|
GuiButton* ClearBtn;
|
||||||
|
|
||||||
GuiButton* CloseBtn;
|
GuiButton* CloseBtn;
|
||||||
|
|
||||||
cSearchButton **buttons;
|
cSearchButton **buttons;
|
||||||
int cnt;
|
int cnt;
|
||||||
GuiImageData keyImageData;
|
GuiImageData keyImageData;
|
||||||
GuiImageData keyOverImageData;
|
GuiImageData keyOverImageData;
|
||||||
GuiTrigger trig;
|
GuiTrigger trig;
|
||||||
GuiTrigger trigB;
|
GuiTrigger trigB;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,7 @@ static int presetAlignmentVert = 0;
|
||||||
static u16 presetStyle = 0;
|
static u16 presetStyle = 0;
|
||||||
static GXColor presetColor = (GXColor) {255, 255, 255, 255};
|
static GXColor presetColor = (GXColor) {255, 255, 255, 255};
|
||||||
|
|
||||||
#define TEXT_SCROLL_DELAY 5
|
#define TEXT_SCROLL_DELAY 5
|
||||||
#define TEXT_SCROLL_INITIAL_DELAY 8
|
#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)
|
GuiText::GuiText(const char * t, int s, GXColor c)
|
||||||
{
|
{
|
||||||
text = NULL;
|
text = NULL;
|
||||||
size = (int) (s * Settings.FontScaleFactor);
|
size = (int) (s * Settings.FontScaleFactor);
|
||||||
currentSize = size;
|
currentSize = size;
|
||||||
color = c;
|
color = c;
|
||||||
alpha = c.a;
|
alpha = c.a;
|
||||||
style = FTGX_JUSTIFY_CENTER | FTGX_ALIGN_MIDDLE;
|
style = FTGX_JUSTIFY_CENTER | FTGX_ALIGN_MIDDLE;
|
||||||
maxWidth = 0;
|
maxWidth = 0;
|
||||||
wrapMode = 0;
|
wrapMode = 0;
|
||||||
passChar = 0;
|
passChar = 0;
|
||||||
font = NULL;
|
font = NULL;
|
||||||
linestodraw = MAX_LINES_TO_DRAW;
|
linestodraw = MAX_LINES_TO_DRAW;
|
||||||
textScrollPos = 0;
|
textScrollPos = 0;
|
||||||
textScrollInitialDelay = TEXT_SCROLL_INITIAL_DELAY;
|
textScrollInitialDelay = TEXT_SCROLL_INITIAL_DELAY;
|
||||||
textScrollDelay = TEXT_SCROLL_DELAY;
|
textScrollDelay = TEXT_SCROLL_DELAY;
|
||||||
|
|
||||||
alignmentHor = ALIGN_CENTRE;
|
alignmentHor = ALIGN_CENTRE;
|
||||||
alignmentVert = ALIGN_MIDDLE;
|
alignmentVert = ALIGN_MIDDLE;
|
||||||
|
|
||||||
if (t)
|
if (t)
|
||||||
{
|
{
|
||||||
text = charToWideChar(t);
|
text = charToWideChar(t);
|
||||||
if (!text) return;
|
if (!text) return;
|
||||||
|
|
||||||
textWidth = fontSystem->getWidth(text, currentSize);
|
textWidth = fontSystem->getWidth(text, currentSize);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
GuiText::GuiText(const wchar_t * t, int s, GXColor c)
|
GuiText::GuiText(const wchar_t * t, int s, GXColor c)
|
||||||
{
|
{
|
||||||
text = NULL;
|
text = NULL;
|
||||||
size = (int) (s * Settings.FontScaleFactor);
|
size = (int) (s * Settings.FontScaleFactor);
|
||||||
currentSize = size;
|
currentSize = size;
|
||||||
color = c;
|
color = c;
|
||||||
alpha = c.a;
|
alpha = c.a;
|
||||||
style = FTGX_JUSTIFY_CENTER | FTGX_ALIGN_MIDDLE;
|
style = FTGX_JUSTIFY_CENTER | FTGX_ALIGN_MIDDLE;
|
||||||
maxWidth = 0;
|
maxWidth = 0;
|
||||||
wrapMode = 0;
|
wrapMode = 0;
|
||||||
passChar = 0;
|
passChar = 0;
|
||||||
font = NULL;
|
font = NULL;
|
||||||
linestodraw = MAX_LINES_TO_DRAW;
|
linestodraw = MAX_LINES_TO_DRAW;
|
||||||
textScrollPos = 0;
|
textScrollPos = 0;
|
||||||
textScrollInitialDelay = TEXT_SCROLL_INITIAL_DELAY;
|
textScrollInitialDelay = TEXT_SCROLL_INITIAL_DELAY;
|
||||||
textScrollDelay = TEXT_SCROLL_DELAY;
|
textScrollDelay = TEXT_SCROLL_DELAY;
|
||||||
|
|
||||||
alignmentHor = ALIGN_CENTRE;
|
alignmentHor = ALIGN_CENTRE;
|
||||||
alignmentVert = ALIGN_MIDDLE;
|
alignmentVert = ALIGN_MIDDLE;
|
||||||
|
|
||||||
if (t)
|
if (t)
|
||||||
{
|
{
|
||||||
text = new (std::nothrow) wchar_t[wcslen(t) + 1];
|
text = new (std::nothrow) wchar_t[wcslen(t) + 1];
|
||||||
if (!text) return;
|
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)
|
GuiText::GuiText(const char * t)
|
||||||
{
|
{
|
||||||
text = NULL;
|
text = NULL;
|
||||||
size = (int) (presetSize * Settings.FontScaleFactor);
|
size = (int) (presetSize * Settings.FontScaleFactor);
|
||||||
currentSize = size;
|
currentSize = size;
|
||||||
color = presetColor;
|
color = presetColor;
|
||||||
alpha = presetColor.a;
|
alpha = presetColor.a;
|
||||||
style = presetStyle;
|
style = presetStyle;
|
||||||
maxWidth = presetMaxWidth;
|
maxWidth = presetMaxWidth;
|
||||||
wrapMode = 0;
|
wrapMode = 0;
|
||||||
passChar = 0;
|
passChar = 0;
|
||||||
font = NULL;
|
font = NULL;
|
||||||
linestodraw = MAX_LINES_TO_DRAW;
|
linestodraw = MAX_LINES_TO_DRAW;
|
||||||
textScrollPos = 0;
|
textScrollPos = 0;
|
||||||
textScrollInitialDelay = TEXT_SCROLL_INITIAL_DELAY;
|
textScrollInitialDelay = TEXT_SCROLL_INITIAL_DELAY;
|
||||||
textScrollDelay = TEXT_SCROLL_DELAY;
|
textScrollDelay = TEXT_SCROLL_DELAY;
|
||||||
|
|
||||||
alignmentHor = presetAlignmentHor;
|
alignmentHor = presetAlignmentHor;
|
||||||
alignmentVert = presetAlignmentVert;
|
alignmentVert = presetAlignmentVert;
|
||||||
|
|
||||||
if (t)
|
if (t)
|
||||||
{
|
{
|
||||||
text = charToWideChar(t);
|
text = charToWideChar(t);
|
||||||
if (!text) return;
|
if (!text) return;
|
||||||
|
|
||||||
textWidth = fontSystem->getWidth(text, currentSize);
|
textWidth = fontSystem->getWidth(text, currentSize);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -126,222 +126,222 @@ GuiText::GuiText(const char * t)
|
||||||
*/
|
*/
|
||||||
GuiText::~GuiText()
|
GuiText::~GuiText()
|
||||||
{
|
{
|
||||||
if (text) delete[] text;
|
if (text) delete[] text;
|
||||||
text = NULL;
|
text = NULL;
|
||||||
|
|
||||||
if (font)
|
if (font)
|
||||||
{
|
{
|
||||||
delete font;
|
delete font;
|
||||||
font = NULL;
|
font = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
ClearDynamicText();
|
ClearDynamicText();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuiText::SetText(const char * t)
|
void GuiText::SetText(const char * t)
|
||||||
{
|
{
|
||||||
LOCK( this );
|
LOCK( this );
|
||||||
|
|
||||||
if (text) delete[] text;
|
if (text) delete[] text;
|
||||||
text = NULL;
|
text = NULL;
|
||||||
|
|
||||||
ClearDynamicText();
|
ClearDynamicText();
|
||||||
|
|
||||||
textScrollPos = 0;
|
textScrollPos = 0;
|
||||||
textScrollInitialDelay = TEXT_SCROLL_INITIAL_DELAY;
|
textScrollInitialDelay = TEXT_SCROLL_INITIAL_DELAY;
|
||||||
|
|
||||||
if (t)
|
if (t)
|
||||||
{
|
{
|
||||||
text = charToWideChar(t);
|
text = charToWideChar(t);
|
||||||
if (!text) return;
|
if (!text) return;
|
||||||
|
|
||||||
if (passChar != 0)
|
if (passChar != 0)
|
||||||
{
|
{
|
||||||
for (u8 i = 0; i < wcslen(text); i++)
|
for (u8 i = 0; i < wcslen(text); i++)
|
||||||
text[i] = passChar;
|
text[i] = passChar;
|
||||||
}
|
}
|
||||||
|
|
||||||
textWidth = fontSystem->getWidth(text, currentSize);
|
textWidth = fontSystem->getWidth(text, currentSize);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuiText::SetTextf(const char *format, ...)
|
void GuiText::SetTextf(const char *format, ...)
|
||||||
{
|
{
|
||||||
if (!format) SetText((char *) NULL);
|
if (!format) SetText((char *) NULL);
|
||||||
|
|
||||||
char *tmp = 0;
|
char *tmp = 0;
|
||||||
va_list va;
|
va_list va;
|
||||||
va_start( va, format );
|
va_start( va, format );
|
||||||
if ((vasprintf(&tmp, format, va) >= 0) && tmp)
|
if ((vasprintf(&tmp, format, va) >= 0) && tmp)
|
||||||
{
|
{
|
||||||
SetText(tmp);
|
SetText(tmp);
|
||||||
}
|
}
|
||||||
va_end( va );
|
va_end( va );
|
||||||
|
|
||||||
if (tmp) free(tmp);
|
if (tmp) free(tmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuiText::SetText(const wchar_t * t)
|
void GuiText::SetText(const wchar_t * t)
|
||||||
{
|
{
|
||||||
LOCK( this );
|
LOCK( this );
|
||||||
|
|
||||||
if (text)
|
if (text)
|
||||||
delete [] text;
|
delete [] text;
|
||||||
text = NULL;
|
text = NULL;
|
||||||
|
|
||||||
ClearDynamicText();
|
ClearDynamicText();
|
||||||
|
|
||||||
textScrollPos = 0;
|
textScrollPos = 0;
|
||||||
textScrollInitialDelay = TEXT_SCROLL_INITIAL_DELAY;
|
textScrollInitialDelay = TEXT_SCROLL_INITIAL_DELAY;
|
||||||
|
|
||||||
if (t)
|
if (t)
|
||||||
{
|
{
|
||||||
text = new (std::nothrow) wchar_t[wcslen(t) + 1];
|
text = new (std::nothrow) wchar_t[wcslen(t) + 1];
|
||||||
if (!text) return;
|
if (!text) return;
|
||||||
|
|
||||||
wcscpy(text, t);
|
wcscpy(text, t);
|
||||||
|
|
||||||
if (passChar != 0)
|
if (passChar != 0)
|
||||||
{
|
{
|
||||||
for (u8 i = 0; i < wcslen(text); i++)
|
for (u8 i = 0; i < wcslen(text); i++)
|
||||||
text[i] = passChar;
|
text[i] = passChar;
|
||||||
}
|
}
|
||||||
|
|
||||||
textWidth = fontSystem->getWidth(text, currentSize);
|
textWidth = fontSystem->getWidth(text, currentSize);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuiText::ClearDynamicText()
|
void GuiText::ClearDynamicText()
|
||||||
{
|
{
|
||||||
for (u32 i = 0; i < textDyn.size(); i++)
|
for (u32 i = 0; i < textDyn.size(); i++)
|
||||||
{
|
{
|
||||||
if (textDyn[i])
|
if (textDyn[i])
|
||||||
delete [] textDyn[i];
|
delete [] textDyn[i];
|
||||||
}
|
}
|
||||||
textDyn.clear();
|
textDyn.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuiText::SetPresets(int sz, GXColor c, int w, u16 s, int h, int v)
|
void GuiText::SetPresets(int sz, GXColor c, int w, u16 s, int h, int v)
|
||||||
{
|
{
|
||||||
presetSize = sz;
|
presetSize = sz;
|
||||||
presetColor = c;
|
presetColor = c;
|
||||||
presetStyle = s;
|
presetStyle = s;
|
||||||
presetMaxWidth = w;
|
presetMaxWidth = w;
|
||||||
presetAlignmentHor = h;
|
presetAlignmentHor = h;
|
||||||
presetAlignmentVert = v;
|
presetAlignmentVert = v;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuiText::SetFontSize(int s)
|
void GuiText::SetFontSize(int s)
|
||||||
{
|
{
|
||||||
LOCK( this );
|
LOCK( this );
|
||||||
|
|
||||||
size = s;
|
size = s;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuiText::SetMaxWidth(int width, int w)
|
void GuiText::SetMaxWidth(int width, int w)
|
||||||
{
|
{
|
||||||
LOCK( this );
|
LOCK( this );
|
||||||
|
|
||||||
maxWidth = width;
|
maxWidth = width;
|
||||||
wrapMode = w;
|
wrapMode = w;
|
||||||
|
|
||||||
if (w == SCROLL_HORIZONTAL)
|
if (w == SCROLL_HORIZONTAL)
|
||||||
{
|
{
|
||||||
textScrollPos = 0;
|
textScrollPos = 0;
|
||||||
textScrollInitialDelay = TEXT_SCROLL_INITIAL_DELAY;
|
textScrollInitialDelay = TEXT_SCROLL_INITIAL_DELAY;
|
||||||
textScrollDelay = TEXT_SCROLL_DELAY;
|
textScrollDelay = TEXT_SCROLL_DELAY;
|
||||||
}
|
}
|
||||||
|
|
||||||
ClearDynamicText();
|
ClearDynamicText();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuiText::SetPassChar(wchar_t p)
|
void GuiText::SetPassChar(wchar_t p)
|
||||||
{
|
{
|
||||||
LOCK( this );
|
LOCK( this );
|
||||||
passChar = p;
|
passChar = p;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuiText::SetColor(GXColor c)
|
void GuiText::SetColor(GXColor c)
|
||||||
{
|
{
|
||||||
LOCK( this );
|
LOCK( this );
|
||||||
color = c;
|
color = c;
|
||||||
alpha = c.a;
|
alpha = c.a;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuiText::SetStyle(u16 s)
|
void GuiText::SetStyle(u16 s)
|
||||||
{
|
{
|
||||||
LOCK( this );
|
LOCK( this );
|
||||||
style = s;
|
style = s;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuiText::SetAlignment(int hor, int vert)
|
void GuiText::SetAlignment(int hor, int vert)
|
||||||
{
|
{
|
||||||
LOCK( this );
|
LOCK( this );
|
||||||
style = 0;
|
style = 0;
|
||||||
|
|
||||||
switch (hor)
|
switch (hor)
|
||||||
{
|
{
|
||||||
case ALIGN_LEFT:
|
case ALIGN_LEFT:
|
||||||
style |= FTGX_JUSTIFY_LEFT;
|
style |= FTGX_JUSTIFY_LEFT;
|
||||||
break;
|
break;
|
||||||
case ALIGN_RIGHT:
|
case ALIGN_RIGHT:
|
||||||
style |= FTGX_JUSTIFY_RIGHT;
|
style |= FTGX_JUSTIFY_RIGHT;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
style |= FTGX_JUSTIFY_CENTER;
|
style |= FTGX_JUSTIFY_CENTER;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
switch (vert)
|
switch (vert)
|
||||||
{
|
{
|
||||||
case ALIGN_TOP:
|
case ALIGN_TOP:
|
||||||
style |= FTGX_ALIGN_TOP;
|
style |= FTGX_ALIGN_TOP;
|
||||||
break;
|
break;
|
||||||
case ALIGN_BOTTOM:
|
case ALIGN_BOTTOM:
|
||||||
style |= FTGX_ALIGN_BOTTOM;
|
style |= FTGX_ALIGN_BOTTOM;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
style |= FTGX_ALIGN_MIDDLE;
|
style |= FTGX_ALIGN_MIDDLE;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
alignmentHor = hor;
|
alignmentHor = hor;
|
||||||
alignmentVert = vert;
|
alignmentVert = vert;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuiText::SetLinesToDraw(int l)
|
void GuiText::SetLinesToDraw(int l)
|
||||||
{
|
{
|
||||||
linestodraw = l;
|
linestodraw = l;
|
||||||
}
|
}
|
||||||
|
|
||||||
int GuiText::GetTextWidth()
|
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)
|
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()
|
int GuiText::GetTextMaxWidth()
|
||||||
{
|
{
|
||||||
return maxWidth;
|
return maxWidth;
|
||||||
}
|
}
|
||||||
|
|
||||||
const wchar_t * GuiText::GetDynText(int ind)
|
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()
|
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)
|
bool GuiText::SetFont(const u8 *fontbuffer, const u32 filesize)
|
||||||
{
|
{
|
||||||
if (!fontbuffer || !filesize) return false;
|
if (!fontbuffer || !filesize) return false;
|
||||||
LOCK( this );
|
LOCK( this );
|
||||||
if (font)
|
if (font)
|
||||||
{
|
{
|
||||||
delete font;
|
delete font;
|
||||||
font = NULL;
|
font = NULL;
|
||||||
}
|
}
|
||||||
font = new FreeTypeGX(fontbuffer, filesize);
|
font = new FreeTypeGX(fontbuffer, filesize);
|
||||||
textWidth = font->getWidth(text, currentSize);
|
textWidth = font->getWidth(text, currentSize);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuiText::MakeDottedText()
|
void GuiText::MakeDottedText()
|
||||||
{
|
{
|
||||||
int pos = textDyn.size();
|
int pos = textDyn.size();
|
||||||
textDyn.resize(pos + 1);
|
textDyn.resize(pos + 1);
|
||||||
|
|
||||||
int i = 0, currentWidth = 0;
|
int i = 0, currentWidth = 0;
|
||||||
textDyn[pos] = new wchar_t[maxWidth];
|
textDyn[pos] = new wchar_t[maxWidth];
|
||||||
|
|
||||||
while (text[i])
|
while (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);
|
||||||
if (currentWidth >= maxWidth && i > 2)
|
if (currentWidth >= maxWidth && i > 2)
|
||||||
{
|
{
|
||||||
textDyn[pos][i - 2] = '.';
|
textDyn[pos][i - 2] = '.';
|
||||||
textDyn[pos][i - 1] = '.';
|
textDyn[pos][i - 1] = '.';
|
||||||
textDyn[pos][i] = '.';
|
textDyn[pos][i] = '.';
|
||||||
i++;
|
i++;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
textDyn[pos][i] = text[i];
|
textDyn[pos][i] = text[i];
|
||||||
|
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
textDyn[pos][i] = 0;
|
textDyn[pos][i] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuiText::ScrollText()
|
void GuiText::ScrollText()
|
||||||
{
|
{
|
||||||
if (textDyn.size() == 0)
|
if (textDyn.size() == 0)
|
||||||
{
|
{
|
||||||
int pos = textDyn.size();
|
int pos = textDyn.size();
|
||||||
int i = 0, currentWidth = 0;
|
int i = 0, currentWidth = 0;
|
||||||
textDyn.resize(pos + 1);
|
textDyn.resize(pos + 1);
|
||||||
|
|
||||||
textDyn[pos] = new wchar_t[maxWidth];
|
textDyn[pos] = new wchar_t[maxWidth];
|
||||||
|
|
||||||
while (text[i] && currentWidth < maxWidth)
|
while (text[i] && currentWidth < maxWidth)
|
||||||
{
|
{
|
||||||
textDyn[pos][i] = text[i];
|
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;
|
++i;
|
||||||
}
|
}
|
||||||
textDyn[pos][i] = 0;
|
textDyn[pos][i] = 0;
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (frameCount % textScrollDelay != 0)
|
if (frameCount % textScrollDelay != 0)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (textScrollInitialDelay)
|
if (textScrollInitialDelay)
|
||||||
{
|
{
|
||||||
--textScrollInitialDelay;
|
--textScrollInitialDelay;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int stringlen = wcslen(text);
|
int stringlen = wcslen(text);
|
||||||
|
|
||||||
++textScrollPos;
|
++textScrollPos;
|
||||||
if (textScrollPos > stringlen)
|
if (textScrollPos > stringlen)
|
||||||
{
|
{
|
||||||
textScrollPos = 0;
|
textScrollPos = 0;
|
||||||
textScrollInitialDelay = TEXT_SCROLL_INITIAL_DELAY;
|
textScrollInitialDelay = TEXT_SCROLL_INITIAL_DELAY;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ch = textScrollPos;
|
int ch = textScrollPos;
|
||||||
int pos = textDyn.size() - 1;
|
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)
|
while (currentWidth < maxWidth)
|
||||||
{
|
{
|
||||||
if (ch > stringlen - 1)
|
if (ch > stringlen - 1)
|
||||||
{
|
{
|
||||||
textDyn[pos][i++] = ' ';
|
textDyn[pos][i++] = ' ';
|
||||||
currentWidth += (font ? font : fontSystem)->getCharWidth(L' ', currentSize, ch > 0 ? text[ch - 1] : 0);
|
currentWidth += (font ? font : fontSystem)->getCharWidth(L' ', currentSize, ch > 0 ? text[ch - 1] : 0);
|
||||||
textDyn[pos][i++] = ' ';
|
textDyn[pos][i++] = ' ';
|
||||||
currentWidth += (font ? font : fontSystem)->getCharWidth(L' ', currentSize, L' ');
|
currentWidth += (font ? font : fontSystem)->getCharWidth(L' ', currentSize, L' ');
|
||||||
textDyn[pos][i++] = ' ';
|
textDyn[pos][i++] = ' ';
|
||||||
currentWidth += (font ? font : fontSystem)->getCharWidth(L' ', currentSize, L' ');
|
currentWidth += (font ? font : fontSystem)->getCharWidth(L' ', currentSize, L' ');
|
||||||
ch = 0;
|
ch = 0;
|
||||||
|
|
||||||
if(currentWidth >= maxWidth)
|
if(currentWidth >= maxWidth)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
textDyn[pos][i] = text[ch];
|
textDyn[pos][i] = text[ch];
|
||||||
currentWidth += (font ? font : fontSystem)->getCharWidth(text[ch], currentSize, ch > 0 ? text[ch - 1] : 0);
|
currentWidth += (font ? font : fontSystem)->getCharWidth(text[ch], currentSize, ch > 0 ? text[ch - 1] : 0);
|
||||||
++ch;
|
++ch;
|
||||||
++i;
|
++i;
|
||||||
}
|
}
|
||||||
textDyn[pos][i] = 0;
|
textDyn[pos][i] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuiText::WrapText()
|
void GuiText::WrapText()
|
||||||
{
|
{
|
||||||
if (textDyn.size() > 0) return;
|
if (textDyn.size() > 0) return;
|
||||||
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
int ch = 0;
|
int ch = 0;
|
||||||
int linenum = 0;
|
int linenum = 0;
|
||||||
int lastSpace = -1;
|
int lastSpace = -1;
|
||||||
int lastSpaceIndex = -1;
|
int lastSpaceIndex = -1;
|
||||||
int currentWidth = 0;
|
int currentWidth = 0;
|
||||||
|
|
||||||
while (text[ch] && linenum < linestodraw)
|
while (text[ch] && linenum < linestodraw)
|
||||||
{
|
{
|
||||||
if (linenum >= (int) textDyn.size())
|
if (linenum >= (int) textDyn.size())
|
||||||
{
|
{
|
||||||
textDyn.resize(linenum + 1);
|
textDyn.resize(linenum + 1);
|
||||||
textDyn[linenum] = new wchar_t[maxWidth];
|
textDyn[linenum] = new wchar_t[maxWidth];
|
||||||
}
|
}
|
||||||
|
|
||||||
textDyn[linenum][i] = text[ch];
|
textDyn[linenum][i] = text[ch];
|
||||||
textDyn[linenum][i + 1] = 0;
|
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 (currentWidth >= maxWidth)
|
||||||
{
|
{
|
||||||
if (lastSpace >= 0)
|
if (lastSpace >= 0)
|
||||||
{
|
{
|
||||||
textDyn[linenum][lastSpaceIndex] = 0; // discard space, and everything after
|
textDyn[linenum][lastSpaceIndex] = 0; // discard space, and everything after
|
||||||
ch = lastSpace; // go backwards to the last space
|
ch = lastSpace; // go backwards to the last space
|
||||||
lastSpace = -1; // we have used this space
|
lastSpace = -1; // we have used this space
|
||||||
lastSpaceIndex = -1;
|
lastSpaceIndex = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (linenum + 1 == linestodraw && text[ch + 1] != 0x0000)
|
if (linenum + 1 == linestodraw && text[ch + 1] != 0x0000)
|
||||||
{
|
{
|
||||||
textDyn[linenum][i - 2] = '.';
|
textDyn[linenum][i - 2] = '.';
|
||||||
textDyn[linenum][i - 1] = '.';
|
textDyn[linenum][i - 1] = '.';
|
||||||
textDyn[linenum][i] = '.';
|
textDyn[linenum][i] = '.';
|
||||||
textDyn[linenum][i + 1] = 0;
|
textDyn[linenum][i + 1] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
currentWidth = 0;
|
currentWidth = 0;
|
||||||
++linenum;
|
++linenum;
|
||||||
i = -1;
|
i = -1;
|
||||||
}
|
}
|
||||||
if (text[ch] == ' ' && i >= 0)
|
if (text[ch] == ' ' && i >= 0)
|
||||||
{
|
{
|
||||||
lastSpace = ch;
|
lastSpace = ch;
|
||||||
lastSpaceIndex = i;
|
lastSpaceIndex = i;
|
||||||
}
|
}
|
||||||
++ch;
|
++ch;
|
||||||
++i;
|
++i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -524,57 +524,57 @@ void GuiText::WrapText()
|
||||||
*/
|
*/
|
||||||
void GuiText::Draw()
|
void GuiText::Draw()
|
||||||
{
|
{
|
||||||
if (!text) return;
|
if (!text) return;
|
||||||
|
|
||||||
if (!IsVisible()) return;
|
if (!IsVisible()) return;
|
||||||
|
|
||||||
GXColor c = color;
|
GXColor c = color;
|
||||||
c.a = GetAlpha();
|
c.a = GetAlpha();
|
||||||
|
|
||||||
int newSize = (int) (size * GetScale());
|
int newSize = (int) (size * GetScale());
|
||||||
|
|
||||||
if (newSize != currentSize)
|
if (newSize != currentSize)
|
||||||
{
|
{
|
||||||
currentSize = LIMIT(newSize, 1, 100);
|
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 (maxWidth > 0 && maxWidth <= textWidth)
|
||||||
{
|
{
|
||||||
if (wrapMode == DOTTED) // text dotted
|
if (wrapMode == DOTTED) // text dotted
|
||||||
{
|
{
|
||||||
if (textDyn.size() == 0)
|
if (textDyn.size() == 0)
|
||||||
MakeDottedText();
|
MakeDottedText();
|
||||||
|
|
||||||
if (textDyn.size() > 0)
|
if (textDyn.size() > 0)
|
||||||
(font ? font : fontSystem)->drawText(this->GetLeft(), this->GetTop(), 0, textDyn[textDyn.size() - 1], currentSize, c, style);
|
(font ? font : fontSystem)->drawText(this->GetLeft(), this->GetTop(), 0, textDyn[textDyn.size() - 1], currentSize, c, style);
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (wrapMode == SCROLL_HORIZONTAL)
|
else if (wrapMode == SCROLL_HORIZONTAL)
|
||||||
{
|
{
|
||||||
ScrollText();
|
ScrollText();
|
||||||
|
|
||||||
if (textDyn.size() > 0)
|
if (textDyn.size() > 0)
|
||||||
(font ? font : fontSystem)->drawText(this->GetLeft(), this->GetTop(), 0, textDyn[textDyn.size() - 1], currentSize, c, style);
|
(font ? font : fontSystem)->drawText(this->GetLeft(), this->GetTop(), 0, textDyn[textDyn.size() - 1], currentSize, c, style);
|
||||||
}
|
}
|
||||||
else if (wrapMode == WRAP)
|
else if (wrapMode == WRAP)
|
||||||
{
|
{
|
||||||
int lineheight = currentSize + 6;
|
int lineheight = currentSize + 6;
|
||||||
int voffset = 0;
|
int voffset = 0;
|
||||||
if (alignmentVert == ALIGN_MIDDLE) voffset = -(lineheight * textDyn.size()) / 2 + lineheight / 2;
|
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++)
|
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);
|
(font ? font : fontSystem)->drawText(this->GetLeft(), this->GetTop() + voffset + i * lineheight, 0, textDyn[i], currentSize, c, style);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
(font ? font : fontSystem)->drawText(this->GetLeft(), this->GetTop(), 0, text, currentSize, c, style, textWidth);
|
(font ? font : fontSystem)->drawText(this->GetLeft(), this->GetTop(), 0, text, currentSize, c, style, textWidth);
|
||||||
}
|
}
|
||||||
this->UpdateEffects();
|
this->UpdateEffects();
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,22 +15,22 @@
|
||||||
*/
|
*/
|
||||||
GuiTooltip::GuiTooltip(const char *t, int Alpha/*=255*/)
|
GuiTooltip::GuiTooltip(const char *t, int Alpha/*=255*/)
|
||||||
{
|
{
|
||||||
tooltipLeft = Resources::GetImageData("tooltip_left.png");
|
tooltipLeft = Resources::GetImageData("tooltip_left.png");
|
||||||
tooltipTile = Resources::GetImageData("tooltip_tile.png");
|
tooltipTile = Resources::GetImageData("tooltip_tile.png");
|
||||||
tooltipRight = Resources::GetImageData("tooltip_right.png");
|
tooltipRight = Resources::GetImageData("tooltip_right.png");
|
||||||
leftImage = new GuiImage(tooltipLeft);
|
leftImage = new GuiImage(tooltipLeft);
|
||||||
tileImage = new GuiImage(tooltipTile);
|
tileImage = new GuiImage(tooltipTile);
|
||||||
rightImage = new GuiImage(tooltipRight);
|
rightImage = new GuiImage(tooltipRight);
|
||||||
text = NULL;
|
text = NULL;
|
||||||
height = leftImage->GetHeight();
|
height = leftImage->GetHeight();
|
||||||
leftImage->SetParent(this);
|
leftImage->SetParent(this);
|
||||||
tileImage->SetParent(this);
|
tileImage->SetParent(this);
|
||||||
rightImage->SetParent(this);
|
rightImage->SetParent(this);
|
||||||
leftImage->SetParentAngle(false);
|
leftImage->SetParentAngle(false);
|
||||||
tileImage->SetParentAngle(false);
|
tileImage->SetParentAngle(false);
|
||||||
rightImage->SetParentAngle(false);
|
rightImage->SetParentAngle(false);
|
||||||
SetText(t);
|
SetText(t);
|
||||||
SetAlpha(Alpha);
|
SetAlpha(Alpha);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -38,21 +38,21 @@ GuiTooltip::GuiTooltip(const char *t, int Alpha/*=255*/)
|
||||||
*/
|
*/
|
||||||
GuiTooltip::~GuiTooltip()
|
GuiTooltip::~GuiTooltip()
|
||||||
{
|
{
|
||||||
if (text) delete text;
|
if (text) delete text;
|
||||||
|
|
||||||
delete tooltipLeft;
|
delete tooltipLeft;
|
||||||
delete tooltipTile;
|
delete tooltipTile;
|
||||||
delete tooltipRight;
|
delete tooltipRight;
|
||||||
delete leftImage;
|
delete leftImage;
|
||||||
delete tileImage;
|
delete tileImage;
|
||||||
delete rightImage;
|
delete rightImage;
|
||||||
}
|
}
|
||||||
|
|
||||||
float GuiTooltip::GetScale()
|
float GuiTooltip::GetScale()
|
||||||
{
|
{
|
||||||
float s = scale * scaleDyn;
|
float s = scale * scaleDyn;
|
||||||
|
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* !Sets the text of the GuiTooltip element
|
/* !Sets the text of the GuiTooltip element
|
||||||
|
@ -60,24 +60,24 @@ float GuiTooltip::GetScale()
|
||||||
*/
|
*/
|
||||||
void GuiTooltip::SetText(const char * t)
|
void GuiTooltip::SetText(const char * t)
|
||||||
{
|
{
|
||||||
LOCK( this );
|
LOCK( this );
|
||||||
if (text)
|
if (text)
|
||||||
{
|
{
|
||||||
delete text;
|
delete text;
|
||||||
text = NULL;
|
text = NULL;
|
||||||
}
|
}
|
||||||
int tile_cnt = 0;
|
int tile_cnt = 0;
|
||||||
if (t && (text = new GuiText(t, 22, ( GXColor )
|
if (t && (text = new GuiText(t, 22, ( GXColor )
|
||||||
{ 0, 0, 0, 255})))
|
{ 0, 0, 0, 255})))
|
||||||
{
|
{
|
||||||
text->SetParent(this);
|
text->SetParent(this);
|
||||||
tile_cnt = (text->GetTextWidth() - 12) / tileImage->GetWidth();
|
tile_cnt = (text->GetTextWidth() - 12) / tileImage->GetWidth();
|
||||||
if (tile_cnt < 0) tile_cnt = 0;
|
if (tile_cnt < 0) tile_cnt = 0;
|
||||||
}
|
}
|
||||||
tileImage->SetPosition(leftImage->GetWidth(), 0);
|
tileImage->SetPosition(leftImage->GetWidth(), 0);
|
||||||
tileImage->SetTileHorizontal(tile_cnt);
|
tileImage->SetTileHorizontal(tile_cnt);
|
||||||
rightImage->SetPosition(leftImage->GetWidth() + tile_cnt * tileImage->GetWidth(), 0);
|
rightImage->SetPosition(leftImage->GetWidth() + tile_cnt * tileImage->GetWidth(), 0);
|
||||||
width = leftImage->GetWidth() + tile_cnt * tileImage->GetWidth() + rightImage->GetWidth();
|
width = leftImage->GetWidth() + tile_cnt * tileImage->GetWidth() + rightImage->GetWidth();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuiTooltip::SetWidescreen(bool )
|
void GuiTooltip::SetWidescreen(bool )
|
||||||
|
@ -88,13 +88,13 @@ void GuiTooltip::SetWidescreen(bool )
|
||||||
*/
|
*/
|
||||||
void GuiTooltip::Draw()
|
void GuiTooltip::Draw()
|
||||||
{
|
{
|
||||||
LOCK( this );
|
LOCK( this );
|
||||||
if (!this->IsVisible()) return;
|
if (!this->IsVisible()) return;
|
||||||
|
|
||||||
leftImage->Draw();
|
leftImage->Draw();
|
||||||
tileImage->Draw();
|
tileImage->Draw();
|
||||||
rightImage->Draw();
|
rightImage->Draw();
|
||||||
if (text) text->Draw();
|
if (text) text->Draw();
|
||||||
|
|
||||||
this->UpdateEffects();
|
this->UpdateEffects();
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,9 +17,9 @@ static int scrollDelay = 0;
|
||||||
*/
|
*/
|
||||||
GuiTrigger::GuiTrigger()
|
GuiTrigger::GuiTrigger()
|
||||||
{
|
{
|
||||||
chan = -1;
|
chan = -1;
|
||||||
memset(&wpad, 0, sizeof(WPADData));
|
memset(&wpad, 0, sizeof(WPADData));
|
||||||
memset(&pad, 0, sizeof(PADData));
|
memset(&pad, 0, sizeof(PADData));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -36,10 +36,10 @@ GuiTrigger::~GuiTrigger()
|
||||||
*/
|
*/
|
||||||
void GuiTrigger::SetSimpleTrigger(s32 ch, u32 wiibtns, u16 gcbtns)
|
void GuiTrigger::SetSimpleTrigger(s32 ch, u32 wiibtns, u16 gcbtns)
|
||||||
{
|
{
|
||||||
type = TRIGGER_SIMPLE;
|
type = TRIGGER_SIMPLE;
|
||||||
chan = ch;
|
chan = ch;
|
||||||
wpad.btns_d = wiibtns;
|
wpad.btns_d = wiibtns;
|
||||||
pad.btns_d = gcbtns;
|
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)
|
void GuiTrigger::SetHeldTrigger(s32 ch, u32 wiibtns, u16 gcbtns)
|
||||||
{
|
{
|
||||||
type = TRIGGER_HELD;
|
type = TRIGGER_HELD;
|
||||||
chan = ch;
|
chan = ch;
|
||||||
wpad.btns_h = wiibtns;
|
wpad.btns_h = wiibtns;
|
||||||
pad.btns_h = gcbtns;
|
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)
|
void GuiTrigger::SetButtonOnlyTrigger(s32 ch, u32 wiibtns, u16 gcbtns)
|
||||||
{
|
{
|
||||||
type = TRIGGER_BUTTON_ONLY;
|
type = TRIGGER_BUTTON_ONLY;
|
||||||
chan = ch;
|
chan = ch;
|
||||||
wpad.btns_d = wiibtns;
|
wpad.btns_d = wiibtns;
|
||||||
pad.btns_d = gcbtns;
|
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)
|
void GuiTrigger::SetButtonOnlyInFocusTrigger(s32 ch, u32 wiibtns, u16 gcbtns)
|
||||||
{
|
{
|
||||||
type = TRIGGER_BUTTON_ONLY_IN_FOCUS;
|
type = TRIGGER_BUTTON_ONLY_IN_FOCUS;
|
||||||
chan = ch;
|
chan = ch;
|
||||||
wpad.btns_d = wiibtns;
|
wpad.btns_d = wiibtns;
|
||||||
pad.btns_d = gcbtns;
|
pad.btns_d = gcbtns;
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
|
@ -90,158 +90,158 @@ s8 GuiTrigger::WPAD_Stick(u8 right, int axis)
|
||||||
{
|
{
|
||||||
#ifdef HW_RVL
|
#ifdef HW_RVL
|
||||||
|
|
||||||
float mag = 0.0;
|
float mag = 0.0;
|
||||||
float ang = 0.0;
|
float ang = 0.0;
|
||||||
|
|
||||||
switch ( wpad.exp.type )
|
switch ( wpad.exp.type )
|
||||||
{
|
{
|
||||||
case WPAD_EXP_NUNCHUK:
|
case WPAD_EXP_NUNCHUK:
|
||||||
case WPAD_EXP_GUITARHERO3:
|
case WPAD_EXP_GUITARHERO3:
|
||||||
if ( right == 0 )
|
if ( right == 0 )
|
||||||
{
|
{
|
||||||
mag = wpad.exp.nunchuk.js.mag;
|
mag = wpad.exp.nunchuk.js.mag;
|
||||||
ang = wpad.exp.nunchuk.js.ang;
|
ang = wpad.exp.nunchuk.js.ang;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case WPAD_EXP_CLASSIC:
|
case WPAD_EXP_CLASSIC:
|
||||||
if ( right == 0 )
|
if ( right == 0 )
|
||||||
{
|
{
|
||||||
mag = wpad.exp.classic.ljs.mag;
|
mag = wpad.exp.classic.ljs.mag;
|
||||||
ang = wpad.exp.classic.ljs.ang;
|
ang = wpad.exp.classic.ljs.ang;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
mag = wpad.exp.classic.rjs.mag;
|
mag = wpad.exp.classic.rjs.mag;
|
||||||
ang = wpad.exp.classic.rjs.ang;
|
ang = wpad.exp.classic.rjs.ang;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* calculate x/y value (angle need to be converted into radian) */
|
/* calculate x/y value (angle need to be converted into radian) */
|
||||||
if ( mag > 1.0 ) mag = 1.0;
|
if ( mag > 1.0 ) mag = 1.0;
|
||||||
else if ( mag < -1.0 ) mag = -1.0;
|
else if ( mag < -1.0 ) mag = -1.0;
|
||||||
double val;
|
double val;
|
||||||
|
|
||||||
if ( axis == 0 ) // x-axis
|
if ( axis == 0 ) // x-axis
|
||||||
val = mag * sin( ( PI * ang ) / 180.0f );
|
val = mag * sin( ( PI * ang ) / 180.0f );
|
||||||
else // y-axis
|
else // y-axis
|
||||||
val = mag * cos( ( PI * ang ) / 180.0f );
|
val = mag * cos( ( PI * ang ) / 180.0f );
|
||||||
|
|
||||||
return ( s8 )( val * 128.0f );
|
return ( s8 )( val * 128.0f );
|
||||||
|
|
||||||
#else
|
#else
|
||||||
return 0;
|
return 0;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GuiTrigger::Left()
|
bool GuiTrigger::Left()
|
||||||
{
|
{
|
||||||
u32 wiibtn = WPAD_BUTTON_LEFT;
|
u32 wiibtn = WPAD_BUTTON_LEFT;
|
||||||
if(wpad.exp.type == WPAD_EXP_CLASSIC)
|
if(wpad.exp.type == WPAD_EXP_CLASSIC)
|
||||||
wiibtn = WPAD_CLASSIC_BUTTON_LEFT;
|
wiibtn = WPAD_CLASSIC_BUTTON_LEFT;
|
||||||
|
|
||||||
if (((wpad.btns_d | wpad.btns_h) & wiibtn) || ((pad.btns_d | pad.btns_h)
|
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)
|
& PAD_BUTTON_LEFT) || pad.stickX < -PADCAL || WPAD_Stick(0, 0) < -PADCAL)
|
||||||
{
|
{
|
||||||
if ((wpad.btns_d & wiibtn) || (pad.btns_d & PAD_BUTTON_LEFT))
|
if ((wpad.btns_d & wiibtn) || (pad.btns_d & PAD_BUTTON_LEFT))
|
||||||
{
|
{
|
||||||
scrollDelay = SCROLL_INITIAL_DELAY; // reset scroll delay.
|
scrollDelay = SCROLL_INITIAL_DELAY; // reset scroll delay.
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else if (scrollDelay == 0)
|
else if (scrollDelay == 0)
|
||||||
{
|
{
|
||||||
scrollDelay = SCROLL_LOOP_DELAY;
|
scrollDelay = SCROLL_LOOP_DELAY;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (scrollDelay > 0) scrollDelay--;
|
if (scrollDelay > 0) scrollDelay--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GuiTrigger::Right()
|
bool GuiTrigger::Right()
|
||||||
{
|
{
|
||||||
u32 wiibtn = WPAD_BUTTON_RIGHT;
|
u32 wiibtn = WPAD_BUTTON_RIGHT;
|
||||||
if(wpad.exp.type == WPAD_EXP_CLASSIC)
|
if(wpad.exp.type == WPAD_EXP_CLASSIC)
|
||||||
wiibtn = WPAD_CLASSIC_BUTTON_RIGHT;
|
wiibtn = WPAD_CLASSIC_BUTTON_RIGHT;
|
||||||
|
|
||||||
if (((wpad.btns_d | wpad.btns_h) & wiibtn) || ((pad.btns_d | pad.btns_h)
|
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)
|
& PAD_BUTTON_RIGHT) || pad.stickX > PADCAL || WPAD_Stick(0, 0) > PADCAL)
|
||||||
{
|
{
|
||||||
if ((wpad.btns_d & wiibtn) || (pad.btns_d & PAD_BUTTON_RIGHT))
|
if ((wpad.btns_d & wiibtn) || (pad.btns_d & PAD_BUTTON_RIGHT))
|
||||||
{
|
{
|
||||||
scrollDelay = SCROLL_INITIAL_DELAY; // reset scroll delay.
|
scrollDelay = SCROLL_INITIAL_DELAY; // reset scroll delay.
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else if (scrollDelay == 0)
|
else if (scrollDelay == 0)
|
||||||
{
|
{
|
||||||
scrollDelay = SCROLL_LOOP_DELAY;
|
scrollDelay = SCROLL_LOOP_DELAY;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (scrollDelay > 0) scrollDelay--;
|
if (scrollDelay > 0) scrollDelay--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GuiTrigger::Up()
|
bool GuiTrigger::Up()
|
||||||
{
|
{
|
||||||
u32 wiibtn = WPAD_BUTTON_UP;
|
u32 wiibtn = WPAD_BUTTON_UP;
|
||||||
if(wpad.exp.type == WPAD_EXP_CLASSIC)
|
if(wpad.exp.type == WPAD_EXP_CLASSIC)
|
||||||
wiibtn = WPAD_CLASSIC_BUTTON_UP;
|
wiibtn = WPAD_CLASSIC_BUTTON_UP;
|
||||||
|
|
||||||
if (((wpad.btns_d | wpad.btns_h) & wiibtn) || ((pad.btns_d | pad.btns_h) & PAD_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)
|
|| pad.stickY > PADCAL || WPAD_Stick(0, 1) > PADCAL)
|
||||||
{
|
{
|
||||||
if ((wpad.btns_d & wiibtn) || (pad.btns_d & PAD_BUTTON_UP))
|
if ((wpad.btns_d & wiibtn) || (pad.btns_d & PAD_BUTTON_UP))
|
||||||
{
|
{
|
||||||
scrollDelay = SCROLL_INITIAL_DELAY; // reset scroll delay.
|
scrollDelay = SCROLL_INITIAL_DELAY; // reset scroll delay.
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else if (scrollDelay == 0)
|
else if (scrollDelay == 0)
|
||||||
{
|
{
|
||||||
scrollDelay = SCROLL_LOOP_DELAY;
|
scrollDelay = SCROLL_LOOP_DELAY;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (scrollDelay > 0) scrollDelay--;
|
if (scrollDelay > 0) scrollDelay--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GuiTrigger::Down()
|
bool GuiTrigger::Down()
|
||||||
{
|
{
|
||||||
u32 wiibtn = WPAD_BUTTON_DOWN;
|
u32 wiibtn = WPAD_BUTTON_DOWN;
|
||||||
if(wpad.exp.type == WPAD_EXP_CLASSIC)
|
if(wpad.exp.type == WPAD_EXP_CLASSIC)
|
||||||
wiibtn = WPAD_CLASSIC_BUTTON_DOWN;
|
wiibtn = WPAD_CLASSIC_BUTTON_DOWN;
|
||||||
|
|
||||||
if (((wpad.btns_d | wpad.btns_h) & wiibtn) || ((pad.btns_d | pad.btns_h)
|
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)
|
& PAD_BUTTON_DOWN) || pad.stickY < -PADCAL || WPAD_Stick(0, 1) < -PADCAL)
|
||||||
{
|
{
|
||||||
if ((wpad.btns_d & wiibtn) || (pad.btns_d & PAD_BUTTON_DOWN))
|
if ((wpad.btns_d & wiibtn) || (pad.btns_d & PAD_BUTTON_DOWN))
|
||||||
{
|
{
|
||||||
scrollDelay = SCROLL_INITIAL_DELAY; // reset scroll delay.
|
scrollDelay = SCROLL_INITIAL_DELAY; // reset scroll delay.
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else if (scrollDelay == 0)
|
else if (scrollDelay == 0)
|
||||||
{
|
{
|
||||||
scrollDelay = SCROLL_LOOP_DELAY;
|
scrollDelay = SCROLL_LOOP_DELAY;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (scrollDelay > 0) scrollDelay--;
|
if (scrollDelay > 0) scrollDelay--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,20 +12,20 @@
|
||||||
|
|
||||||
GuiWindow::GuiWindow()
|
GuiWindow::GuiWindow()
|
||||||
{
|
{
|
||||||
width = 0;
|
width = 0;
|
||||||
height = 0;
|
height = 0;
|
||||||
forceDim = false;
|
forceDim = false;
|
||||||
allowDim = true;
|
allowDim = true;
|
||||||
focus = 0; // allow focus
|
focus = 0; // allow focus
|
||||||
}
|
}
|
||||||
|
|
||||||
GuiWindow::GuiWindow(int w, int h)
|
GuiWindow::GuiWindow(int w, int h)
|
||||||
{
|
{
|
||||||
width = w;
|
width = w;
|
||||||
height = h;
|
height = h;
|
||||||
forceDim = false;
|
forceDim = false;
|
||||||
allowDim = true;
|
allowDim = true;
|
||||||
focus = 0; // allow focus
|
focus = 0; // allow focus
|
||||||
}
|
}
|
||||||
|
|
||||||
GuiWindow::~GuiWindow()
|
GuiWindow::~GuiWindow()
|
||||||
|
@ -34,419 +34,419 @@ GuiWindow::~GuiWindow()
|
||||||
|
|
||||||
void GuiWindow::Append(GuiElement* e)
|
void GuiWindow::Append(GuiElement* e)
|
||||||
{
|
{
|
||||||
LOCK( this );
|
LOCK( this );
|
||||||
if (e == NULL) return;
|
if (e == NULL) return;
|
||||||
|
|
||||||
Remove(e);
|
Remove(e);
|
||||||
_elements.push_back(e);
|
_elements.push_back(e);
|
||||||
e->SetParent(this);
|
e->SetParent(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuiWindow::Insert(GuiElement* e, u32 index)
|
void GuiWindow::Insert(GuiElement* e, u32 index)
|
||||||
{
|
{
|
||||||
LOCK( this );
|
LOCK( this );
|
||||||
if (e == NULL || index > (_elements.size() - 1)) return;
|
if (e == NULL || index > (_elements.size() - 1)) return;
|
||||||
|
|
||||||
Remove(e);
|
Remove(e);
|
||||||
_elements.insert(_elements.begin() + index, e);
|
_elements.insert(_elements.begin() + index, e);
|
||||||
e->SetParent(this);
|
e->SetParent(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuiWindow::Remove(GuiElement* e)
|
void GuiWindow::Remove(GuiElement* e)
|
||||||
{
|
{
|
||||||
LOCK( this );
|
LOCK( this );
|
||||||
if (e == NULL) return;
|
if (e == NULL) return;
|
||||||
|
|
||||||
for (u8 i = 0; i < _elements.size(); i++)
|
for (u8 i = 0; i < _elements.size(); i++)
|
||||||
{
|
{
|
||||||
if (e == _elements.at(i))
|
if (e == _elements.at(i))
|
||||||
{
|
{
|
||||||
_elements.erase(_elements.begin() + i);
|
_elements.erase(_elements.begin() + i);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuiWindow::RemoveAll()
|
void GuiWindow::RemoveAll()
|
||||||
{
|
{
|
||||||
LOCK( this );
|
LOCK( this );
|
||||||
_elements.clear();
|
_elements.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
GuiElement* GuiWindow::GetGuiElementAt(u32 index) const
|
GuiElement* GuiWindow::GetGuiElementAt(u32 index) const
|
||||||
{
|
{
|
||||||
if (index >= _elements.size()) return NULL;
|
if (index >= _elements.size()) return NULL;
|
||||||
return _elements.at(index);
|
return _elements.at(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
u32 GuiWindow::GetSize()
|
u32 GuiWindow::GetSize()
|
||||||
{
|
{
|
||||||
return _elements.size();
|
return _elements.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuiWindow::Draw()
|
void GuiWindow::Draw()
|
||||||
{
|
{
|
||||||
LOCK( this );
|
LOCK( this );
|
||||||
if (_elements.size() == 0 || !this->IsVisible()) return;
|
if (_elements.size() == 0 || !this->IsVisible()) return;
|
||||||
|
|
||||||
for (u8 i = 0; i < _elements.size(); i++)
|
for (u8 i = 0; i < _elements.size(); i++)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
_elements.at(i)->Draw();
|
_elements.at(i)->Draw();
|
||||||
}
|
}
|
||||||
catch (const std::exception& e)
|
catch (const std::exception& e)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this->UpdateEffects();
|
this->UpdateEffects();
|
||||||
|
|
||||||
if ((parentElement && state == STATE_DISABLED && allowDim) || forceDim)
|
if ((parentElement && state == STATE_DISABLED && allowDim) || forceDim)
|
||||||
Menu_DrawRectangle(0, 0, screenwidth, screenheight, (GXColor) {0, 0, 0, 0x70}, 1);
|
Menu_DrawRectangle(0, 0, screenwidth, screenheight, (GXColor) {0, 0, 0, 0x70}, 1);
|
||||||
}
|
}
|
||||||
void GuiWindow::DrawTooltip()
|
void GuiWindow::DrawTooltip()
|
||||||
{
|
{
|
||||||
LOCK( this );
|
LOCK( this );
|
||||||
if (_elements.size() == 0 || !this->IsVisible()) return;
|
if (_elements.size() == 0 || !this->IsVisible()) return;
|
||||||
|
|
||||||
for (u8 i = 0; i < _elements.size(); i++)
|
for (u8 i = 0; i < _elements.size(); i++)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
_elements.at(i)->DrawTooltip();
|
_elements.at(i)->DrawTooltip();
|
||||||
}
|
}
|
||||||
catch (const std::exception& e)
|
catch (const std::exception& e)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void GuiWindow::ResetState()
|
void GuiWindow::ResetState()
|
||||||
{
|
{
|
||||||
LOCK( this );
|
LOCK( this );
|
||||||
if (state != STATE_DISABLED) state = STATE_DEFAULT;
|
if (state != STATE_DISABLED) state = STATE_DEFAULT;
|
||||||
|
|
||||||
for (u8 i = 0; i < _elements.size(); i++)
|
for (u8 i = 0; i < _elements.size(); i++)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
_elements.at(i)->ResetState();
|
_elements.at(i)->ResetState();
|
||||||
}
|
}
|
||||||
catch (const std::exception& e)
|
catch (const std::exception& e)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuiWindow::SetState(int s)
|
void GuiWindow::SetState(int s)
|
||||||
{
|
{
|
||||||
LOCK( this );
|
LOCK( this );
|
||||||
state = s;
|
state = s;
|
||||||
|
|
||||||
for (u8 i = 0; i < _elements.size(); i++)
|
for (u8 i = 0; i < _elements.size(); i++)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
_elements.at(i)->SetState(s);
|
_elements.at(i)->SetState(s);
|
||||||
}
|
}
|
||||||
catch (const std::exception& e)
|
catch (const std::exception& e)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuiWindow::SetVisible(bool v)
|
void GuiWindow::SetVisible(bool v)
|
||||||
{
|
{
|
||||||
LOCK( this );
|
LOCK( this );
|
||||||
visible = v;
|
visible = v;
|
||||||
|
|
||||||
for (u8 i = 0; i < _elements.size(); i++)
|
for (u8 i = 0; i < _elements.size(); i++)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
_elements.at(i)->SetVisible(v);
|
_elements.at(i)->SetVisible(v);
|
||||||
}
|
}
|
||||||
catch (const std::exception& e)
|
catch (const std::exception& e)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuiWindow::SetFocus(int f)
|
void GuiWindow::SetFocus(int f)
|
||||||
{
|
{
|
||||||
LOCK( this );
|
LOCK( this );
|
||||||
focus = f;
|
focus = f;
|
||||||
|
|
||||||
if (f == 1)
|
if (f == 1)
|
||||||
this->MoveSelectionVert(1);
|
this->MoveSelectionVert(1);
|
||||||
else this->ResetState();
|
else this->ResetState();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuiWindow::ChangeFocus(GuiElement* e)
|
void GuiWindow::ChangeFocus(GuiElement* e)
|
||||||
{
|
{
|
||||||
LOCK( this );
|
LOCK( this );
|
||||||
if (parentElement) return; // this is only intended for the main window
|
if (parentElement) return; // this is only intended for the main window
|
||||||
|
|
||||||
for (u8 i = 0; i < _elements.size(); i++)
|
for (u8 i = 0; i < _elements.size(); i++)
|
||||||
{
|
{
|
||||||
if (e == _elements.at(i))
|
if (e == _elements.at(i))
|
||||||
_elements.at(i)->SetFocus(1);
|
_elements.at(i)->SetFocus(1);
|
||||||
else if (_elements.at(i)->IsFocused() == 1) _elements.at(i)->SetFocus(0);
|
else if (_elements.at(i)->IsFocused() == 1) _elements.at(i)->SetFocus(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuiWindow::ToggleFocus(GuiTrigger * t)
|
void GuiWindow::ToggleFocus(GuiTrigger * t)
|
||||||
{
|
{
|
||||||
LOCK( this );
|
LOCK( this );
|
||||||
if (parentElement) return; // this is only intended for the main window
|
if (parentElement) return; // this is only intended for the main window
|
||||||
|
|
||||||
int found = -1;
|
int found = -1;
|
||||||
int newfocus = -1;
|
int newfocus = -1;
|
||||||
u8 i;
|
u8 i;
|
||||||
|
|
||||||
// look for currently in focus element
|
// look for currently in focus element
|
||||||
for (i = 0; i < _elements.size(); i++)
|
for (i = 0; i < _elements.size(); i++)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (_elements.at(i)->IsFocused() == 1)
|
if (_elements.at(i)->IsFocused() == 1)
|
||||||
{
|
{
|
||||||
found = i;
|
found = i;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (const std::exception& e)
|
catch (const std::exception& e)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// element with focus not found, try to give focus
|
// element with focus not found, try to give focus
|
||||||
if (found == -1)
|
if (found == -1)
|
||||||
{
|
{
|
||||||
for (i = 0; i < _elements.size(); i++)
|
for (i = 0; i < _elements.size(); i++)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (_elements.at(i)->IsFocused() == 0 && _elements.at(i)->GetState() != STATE_DISABLED) // focus is possible (but not set)
|
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(i)->SetFocus(1); // give this element focus
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (const std::exception& e)
|
catch (const std::exception& e)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// change focus
|
// 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))
|
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++)
|
for (i = found; i < _elements.size(); i++)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (_elements.at(i)->IsFocused() == 0 && _elements.at(i)->GetState() != STATE_DISABLED) // focus is possible (but not set)
|
if (_elements.at(i)->IsFocused() == 0 && _elements.at(i)->GetState() != STATE_DISABLED) // focus is possible (but not set)
|
||||||
{
|
{
|
||||||
newfocus = i;
|
newfocus = i;
|
||||||
_elements.at(i)->SetFocus(1); // give this element focus
|
_elements.at(i)->SetFocus(1); // give this element focus
|
||||||
_elements.at(found)->SetFocus(0); // disable focus on other element
|
_elements.at(found)->SetFocus(0); // disable focus on other element
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (const std::exception& e)
|
catch (const std::exception& e)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (newfocus == -1)
|
if (newfocus == -1)
|
||||||
{
|
{
|
||||||
for (i = 0; i < found; i++)
|
for (i = 0; i < found; i++)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (_elements.at(i)->IsFocused() == 0 && _elements.at(i)->GetState() != STATE_DISABLED) // focus is possible (but not set)
|
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(i)->SetFocus(1); // give this element focus
|
||||||
_elements.at(found)->SetFocus(0); // disable focus on other element
|
_elements.at(found)->SetFocus(0); // disable focus on other element
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (const std::exception& e)
|
catch (const std::exception& e)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int GuiWindow::GetSelected()
|
int GuiWindow::GetSelected()
|
||||||
{
|
{
|
||||||
// find selected element
|
// find selected element
|
||||||
int found = -1;
|
int found = -1;
|
||||||
for (u8 i = 0; i < _elements.size(); i++)
|
for (u8 i = 0; i < _elements.size(); i++)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (_elements.at(i)->GetState() == STATE_SELECTED)
|
if (_elements.at(i)->GetState() == STATE_SELECTED)
|
||||||
{
|
{
|
||||||
found = i;
|
found = i;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (const std::exception& e)
|
catch (const std::exception& e)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return found;
|
return found;
|
||||||
}
|
}
|
||||||
|
|
||||||
// set element to left/right as selected
|
// set element to left/right as selected
|
||||||
// there's probably a more clever way to do this, but this way works
|
// there's probably a more clever way to do this, but this way works
|
||||||
void GuiWindow::MoveSelectionHor(int dir)
|
void GuiWindow::MoveSelectionHor(int dir)
|
||||||
{
|
{
|
||||||
LOCK( this );
|
LOCK( this );
|
||||||
int found = -1;
|
int found = -1;
|
||||||
u16 left = 0;
|
u16 left = 0;
|
||||||
u16 top = 0;
|
u16 top = 0;
|
||||||
u8 i = 0;
|
u8 i = 0;
|
||||||
|
|
||||||
int selected = this->GetSelected();
|
int selected = this->GetSelected();
|
||||||
|
|
||||||
if (selected >= 0)
|
if (selected >= 0)
|
||||||
{
|
{
|
||||||
left = _elements.at(selected)->GetLeft();
|
left = _elements.at(selected)->GetLeft();
|
||||||
top = _elements.at(selected)->GetTop();
|
top = _elements.at(selected)->GetTop();
|
||||||
}
|
}
|
||||||
|
|
||||||
// look for a button on the same row, to the left/right
|
// look for a button on the same row, to the left/right
|
||||||
for (i = 0; i < _elements.size(); i++)
|
for (i = 0; i < _elements.size(); i++)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (_elements.at(i)->IsSelectable())
|
if (_elements.at(i)->IsSelectable())
|
||||||
{
|
{
|
||||||
if (_elements.at(i)->GetLeft() * dir > left * dir && _elements.at(i)->GetTop() == top)
|
if (_elements.at(i)->GetLeft() * dir > left * dir && _elements.at(i)->GetTop() == top)
|
||||||
{
|
{
|
||||||
if (found == -1)
|
if (found == -1)
|
||||||
found = i;
|
found = i;
|
||||||
else if (_elements.at(i)->GetLeft() * dir < _elements.at(found)->GetLeft() * dir) found = i; // this is a better match
|
else if (_elements.at(i)->GetLeft() * dir < _elements.at(found)->GetLeft() * dir) found = i; // this is a better match
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (const std::exception& e)
|
catch (const std::exception& e)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (found >= 0) goto matchfound;
|
if (found >= 0) goto matchfound;
|
||||||
|
|
||||||
// match still not found, let's try the first button in the next row
|
// match still not found, let's try the first button in the next row
|
||||||
for (i = 0; i < _elements.size(); i++)
|
for (i = 0; i < _elements.size(); i++)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (_elements.at(i)->IsSelectable())
|
if (_elements.at(i)->IsSelectable())
|
||||||
{
|
{
|
||||||
if (_elements.at(i)->GetTop() * dir > top * dir)
|
if (_elements.at(i)->GetTop() * dir > top * dir)
|
||||||
{
|
{
|
||||||
if (found == -1)
|
if (found == -1)
|
||||||
found = i;
|
found = i;
|
||||||
else if (_elements.at(i)->GetTop() * dir < _elements.at(found)->GetTop() * dir)
|
else if (_elements.at(i)->GetTop() * dir < _elements.at(found)->GetTop() * dir)
|
||||||
found = i; // this is a better match
|
found = i; // this is a better match
|
||||||
else if (_elements.at(i)->GetTop() * dir == _elements.at(found)->GetTop() * dir
|
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
|
&& _elements.at(i)->GetLeft() * dir < _elements.at(found)->GetLeft() * dir) found = i; // this is a better match
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (const std::exception& e)
|
catch (const std::exception& e)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// match found
|
// match found
|
||||||
matchfound: if (found >= 0)
|
matchfound: if (found >= 0)
|
||||||
{
|
{
|
||||||
_elements.at(found)->SetState(STATE_SELECTED);
|
_elements.at(found)->SetState(STATE_SELECTED);
|
||||||
if (selected >= 0) _elements.at(selected)->ResetState();
|
if (selected >= 0) _elements.at(selected)->ResetState();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuiWindow::MoveSelectionVert(int dir)
|
void GuiWindow::MoveSelectionVert(int dir)
|
||||||
{
|
{
|
||||||
LOCK( this );
|
LOCK( this );
|
||||||
int found = -1;
|
int found = -1;
|
||||||
u16 left = 0;
|
u16 left = 0;
|
||||||
u16 top = 0;
|
u16 top = 0;
|
||||||
u8 i = 0;
|
u8 i = 0;
|
||||||
|
|
||||||
int selected = this->GetSelected();
|
int selected = this->GetSelected();
|
||||||
|
|
||||||
if (selected >= 0)
|
if (selected >= 0)
|
||||||
{
|
{
|
||||||
left = _elements.at(selected)->GetLeft();
|
left = _elements.at(selected)->GetLeft();
|
||||||
top = _elements.at(selected)->GetTop();
|
top = _elements.at(selected)->GetTop();
|
||||||
}
|
}
|
||||||
|
|
||||||
// look for a button above/below, with the least horizontal difference
|
// look for a button above/below, with the least horizontal difference
|
||||||
for (i = 0; i < _elements.size(); i++)
|
for (i = 0; i < _elements.size(); i++)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (_elements.at(i)->IsSelectable())
|
if (_elements.at(i)->IsSelectable())
|
||||||
{
|
{
|
||||||
if (_elements.at(i)->GetTop() * dir > top * dir)
|
if (_elements.at(i)->GetTop() * dir > top * dir)
|
||||||
{
|
{
|
||||||
if (found == -1)
|
if (found == -1)
|
||||||
found = i;
|
found = i;
|
||||||
else if (_elements.at(i)->GetTop() * dir < _elements.at(found)->GetTop() * dir)
|
else if (_elements.at(i)->GetTop() * dir < _elements.at(found)->GetTop() * dir)
|
||||||
found = i; // this is a better match
|
found = i; // this is a better match
|
||||||
else if (_elements.at(i)->GetTop() * dir == _elements.at(found)->GetTop() * dir && abs(
|
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;
|
_elements.at(i)->GetLeft() - left) < abs(_elements.at(found)->GetLeft() - left)) found = i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (const std::exception& e)
|
catch (const std::exception& e)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (found >= 0) goto matchfound;
|
if (found >= 0) goto matchfound;
|
||||||
|
|
||||||
// match found
|
// match found
|
||||||
matchfound: if (found >= 0)
|
matchfound: if (found >= 0)
|
||||||
{
|
{
|
||||||
_elements.at(found)->SetState(STATE_SELECTED);
|
_elements.at(found)->SetState(STATE_SELECTED);
|
||||||
if (selected >= 0) _elements.at(selected)->ResetState();
|
if (selected >= 0) _elements.at(selected)->ResetState();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuiWindow::Update(GuiTrigger * t)
|
void GuiWindow::Update(GuiTrigger * t)
|
||||||
{
|
{
|
||||||
LOCK( this );
|
LOCK( this );
|
||||||
if (_elements.size() == 0 || (state == STATE_DISABLED && parentElement)) return;
|
if (_elements.size() == 0 || (state == STATE_DISABLED && parentElement)) return;
|
||||||
|
|
||||||
for (u8 i = 0; i < _elements.size(); i++)
|
for (u8 i = 0; i < _elements.size(); i++)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
_elements.at(i)->Update(t);
|
_elements.at(i)->Update(t);
|
||||||
}
|
}
|
||||||
catch (const std::exception& e)
|
catch (const std::exception& e)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this->ToggleFocus(t);
|
this->ToggleFocus(t);
|
||||||
|
|
||||||
if (focus) // only send actions to this window if it's in focus
|
if (focus) // only send actions to this window if it's in focus
|
||||||
{
|
{
|
||||||
// pad/joystick navigation
|
// pad/joystick navigation
|
||||||
if (t->Right())
|
if (t->Right())
|
||||||
this->MoveSelectionHor(1);
|
this->MoveSelectionHor(1);
|
||||||
else if (t->Left())
|
else if (t->Left())
|
||||||
this->MoveSelectionHor(-1);
|
this->MoveSelectionHor(-1);
|
||||||
else if (t->Down())
|
else if (t->Down())
|
||||||
this->MoveSelectionVert(1);
|
this->MoveSelectionVert(1);
|
||||||
else if (t->Up()) 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.
|
// 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
|
// 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
|
// QUICK DOCUMENTATION
|
||||||
//
|
//
|
||||||
|
@ -288,8 +288,8 @@ namespace sigslot {
|
||||||
public:
|
public:
|
||||||
multi_threaded_global()
|
multi_threaded_global()
|
||||||
{
|
{
|
||||||
if(g_mutex == LWP_MUTEX_NULL)
|
if(g_mutex == LWP_MUTEX_NULL)
|
||||||
LWP_MutexInit(&g_mutex, NULL);
|
LWP_MutexInit(&g_mutex, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
multi_threaded_global(const multi_threaded_global&)
|
multi_threaded_global(const multi_threaded_global&)
|
||||||
|
@ -318,12 +318,12 @@ namespace sigslot {
|
||||||
public:
|
public:
|
||||||
multi_threaded_local()
|
multi_threaded_local()
|
||||||
{
|
{
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
multi_threaded_local(const multi_threaded_local&)
|
multi_threaded_local(const multi_threaded_local&)
|
||||||
{
|
{
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual ~multi_threaded_local()
|
virtual ~multi_threaded_local()
|
||||||
|
@ -796,8 +796,8 @@ namespace sigslot {
|
||||||
public:
|
public:
|
||||||
typedef typename std::list<_connection_base2<arg1_type, arg2_type, mt_policy> *>
|
typedef typename std::list<_connection_base2<arg1_type, arg2_type, mt_policy> *>
|
||||||
connections_list;
|
connections_list;
|
||||||
typedef typename connections_list::const_iterator const_iterator;
|
typedef typename connections_list::const_iterator const_iterator;
|
||||||
typedef typename connections_list::iterator iterator;
|
typedef typename connections_list::iterator iterator;
|
||||||
|
|
||||||
_signal_base2()
|
_signal_base2()
|
||||||
{
|
{
|
||||||
|
@ -917,8 +917,8 @@ namespace sigslot {
|
||||||
typedef std::list<_connection_base3<arg1_type, arg2_type, arg3_type, mt_policy> *>
|
typedef std::list<_connection_base3<arg1_type, arg2_type, arg3_type, mt_policy> *>
|
||||||
connections_list;
|
connections_list;
|
||||||
|
|
||||||
typedef typename connections_list::const_iterator const_iterator;
|
typedef typename connections_list::const_iterator const_iterator;
|
||||||
typedef typename connections_list::iterator iterator;
|
typedef typename connections_list::iterator iterator;
|
||||||
_signal_base3()
|
_signal_base3()
|
||||||
{
|
{
|
||||||
;
|
;
|
||||||
|
@ -1036,8 +1036,8 @@ namespace sigslot {
|
||||||
public:
|
public:
|
||||||
typedef std::list<_connection_base4<arg1_type, arg2_type, arg3_type,
|
typedef std::list<_connection_base4<arg1_type, arg2_type, arg3_type,
|
||||||
arg4_type, mt_policy> *> connections_list;
|
arg4_type, mt_policy> *> connections_list;
|
||||||
typedef typename connections_list::const_iterator const_iterator;
|
typedef typename connections_list::const_iterator const_iterator;
|
||||||
typedef typename connections_list::iterator iterator;
|
typedef typename connections_list::iterator iterator;
|
||||||
|
|
||||||
_signal_base4()
|
_signal_base4()
|
||||||
{
|
{
|
||||||
|
@ -1157,8 +1157,8 @@ namespace sigslot {
|
||||||
public:
|
public:
|
||||||
typedef std::list<_connection_base5<arg1_type, arg2_type, arg3_type,
|
typedef std::list<_connection_base5<arg1_type, arg2_type, arg3_type,
|
||||||
arg4_type, arg5_type, mt_policy> *> connections_list;
|
arg4_type, arg5_type, mt_policy> *> connections_list;
|
||||||
typedef typename connections_list::const_iterator const_iterator;
|
typedef typename connections_list::const_iterator const_iterator;
|
||||||
typedef typename connections_list::iterator iterator;
|
typedef typename connections_list::iterator iterator;
|
||||||
|
|
||||||
_signal_base5()
|
_signal_base5()
|
||||||
{
|
{
|
||||||
|
@ -1279,8 +1279,8 @@ namespace sigslot {
|
||||||
public:
|
public:
|
||||||
typedef std::list<_connection_base6<arg1_type, arg2_type, arg3_type,
|
typedef std::list<_connection_base6<arg1_type, arg2_type, arg3_type,
|
||||||
arg4_type, arg5_type, arg6_type, mt_policy> *> connections_list;
|
arg4_type, arg5_type, arg6_type, mt_policy> *> connections_list;
|
||||||
typedef typename connections_list::const_iterator const_iterator;
|
typedef typename connections_list::const_iterator const_iterator;
|
||||||
typedef typename connections_list::iterator iterator;
|
typedef typename connections_list::iterator iterator;
|
||||||
|
|
||||||
_signal_base6()
|
_signal_base6()
|
||||||
{
|
{
|
||||||
|
@ -1401,8 +1401,8 @@ namespace sigslot {
|
||||||
public:
|
public:
|
||||||
typedef std::list<_connection_base7<arg1_type, arg2_type, arg3_type,
|
typedef std::list<_connection_base7<arg1_type, arg2_type, arg3_type,
|
||||||
arg4_type, arg5_type, arg6_type, arg7_type, mt_policy> *> connections_list;
|
arg4_type, arg5_type, arg6_type, arg7_type, mt_policy> *> connections_list;
|
||||||
typedef typename connections_list::const_iterator const_iterator;
|
typedef typename connections_list::const_iterator const_iterator;
|
||||||
typedef typename connections_list::iterator iterator;
|
typedef typename connections_list::iterator iterator;
|
||||||
|
|
||||||
_signal_base7()
|
_signal_base7()
|
||||||
{
|
{
|
||||||
|
@ -1524,8 +1524,8 @@ namespace sigslot {
|
||||||
typedef std::list<_connection_base8<arg1_type, arg2_type, arg3_type,
|
typedef std::list<_connection_base8<arg1_type, arg2_type, arg3_type,
|
||||||
arg4_type, arg5_type, arg6_type, arg7_type, arg8_type, mt_policy> *>
|
arg4_type, arg5_type, arg6_type, arg7_type, arg8_type, mt_policy> *>
|
||||||
connections_list;
|
connections_list;
|
||||||
typedef typename connections_list::const_iterator const_iterator;
|
typedef typename connections_list::const_iterator const_iterator;
|
||||||
typedef typename connections_list::iterator iterator;
|
typedef typename connections_list::iterator iterator;
|
||||||
|
|
||||||
_signal_base8()
|
_signal_base8()
|
||||||
{
|
{
|
||||||
|
@ -1797,10 +1797,10 @@ namespace sigslot {
|
||||||
m_pmemfun = pmemfun;
|
m_pmemfun = pmemfun;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual ~_connection3()
|
virtual ~_connection3()
|
||||||
{
|
{
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
virtual _connection_base3<arg1_type, arg2_type, arg3_type, mt_policy>* clone()
|
virtual _connection_base3<arg1_type, arg2_type, arg3_type, mt_policy>* clone()
|
||||||
|
@ -1847,10 +1847,10 @@ namespace sigslot {
|
||||||
m_pmemfun = pmemfun;
|
m_pmemfun = pmemfun;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual ~_connection4()
|
virtual ~_connection4()
|
||||||
{
|
{
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual _connection_base4<arg1_type, arg2_type, arg3_type, arg4_type, mt_policy>* clone()
|
virtual _connection_base4<arg1_type, arg2_type, arg3_type, arg4_type, mt_policy>* clone()
|
||||||
{
|
{
|
||||||
|
@ -1898,10 +1898,10 @@ namespace sigslot {
|
||||||
m_pmemfun = pmemfun;
|
m_pmemfun = pmemfun;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual ~_connection5()
|
virtual ~_connection5()
|
||||||
{
|
{
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual _connection_base5<arg1_type, arg2_type, arg3_type, arg4_type,
|
virtual _connection_base5<arg1_type, arg2_type, arg3_type, arg4_type,
|
||||||
arg5_type, mt_policy>* clone()
|
arg5_type, mt_policy>* clone()
|
||||||
|
@ -1953,10 +1953,10 @@ namespace sigslot {
|
||||||
m_pmemfun = pmemfun;
|
m_pmemfun = pmemfun;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual ~_connection6()
|
virtual ~_connection6()
|
||||||
{
|
{
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual _connection_base6<arg1_type, arg2_type, arg3_type, arg4_type,
|
virtual _connection_base6<arg1_type, arg2_type, arg3_type, arg4_type,
|
||||||
arg5_type, arg6_type, mt_policy>* clone()
|
arg5_type, arg6_type, mt_policy>* clone()
|
||||||
|
@ -2008,10 +2008,10 @@ namespace sigslot {
|
||||||
m_pmemfun = pmemfun;
|
m_pmemfun = pmemfun;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual ~_connection7()
|
virtual ~_connection7()
|
||||||
{
|
{
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual _connection_base7<arg1_type, arg2_type, arg3_type, arg4_type,
|
virtual _connection_base7<arg1_type, arg2_type, arg3_type, arg4_type,
|
||||||
arg5_type, arg6_type, arg7_type, mt_policy>* clone()
|
arg5_type, arg6_type, arg7_type, mt_policy>* clone()
|
||||||
|
@ -2065,10 +2065,10 @@ namespace sigslot {
|
||||||
m_pmemfun = pmemfun;
|
m_pmemfun = pmemfun;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual ~_connection8()
|
virtual ~_connection8()
|
||||||
{
|
{
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual _connection_base8<arg1_type, arg2_type, arg3_type, arg4_type,
|
virtual _connection_base8<arg1_type, arg2_type, arg3_type, arg4_type,
|
||||||
arg5_type, arg6_type, arg7_type, arg8_type, mt_policy>* clone()
|
arg5_type, arg6_type, arg7_type, arg8_type, mt_policy>* clone()
|
||||||
|
@ -2105,7 +2105,7 @@ namespace sigslot {
|
||||||
class signal0 : public _signal_base0<mt_policy>
|
class signal0 : public _signal_base0<mt_policy>
|
||||||
{
|
{
|
||||||
public:
|
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()
|
signal0()
|
||||||
{
|
{
|
||||||
;
|
;
|
||||||
|
@ -2171,7 +2171,7 @@ namespace sigslot {
|
||||||
class signal1 : public _signal_base1<arg1_type, mt_policy>
|
class signal1 : public _signal_base1<arg1_type, mt_policy>
|
||||||
{
|
{
|
||||||
public:
|
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()
|
signal1()
|
||||||
{
|
{
|
||||||
;
|
;
|
||||||
|
@ -2237,7 +2237,7 @@ namespace sigslot {
|
||||||
class signal2 : public _signal_base2<arg1_type, arg2_type, mt_policy>
|
class signal2 : public _signal_base2<arg1_type, arg2_type, mt_policy>
|
||||||
{
|
{
|
||||||
public:
|
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()
|
signal2()
|
||||||
{
|
{
|
||||||
;
|
;
|
||||||
|
@ -2304,7 +2304,7 @@ namespace sigslot {
|
||||||
class signal3 : public _signal_base3<arg1_type, arg2_type, arg3_type, mt_policy>
|
class signal3 : public _signal_base3<arg1_type, arg2_type, arg3_type, mt_policy>
|
||||||
{
|
{
|
||||||
public:
|
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()
|
signal3()
|
||||||
{
|
{
|
||||||
;
|
;
|
||||||
|
@ -2373,7 +2373,7 @@ namespace sigslot {
|
||||||
arg4_type, mt_policy>
|
arg4_type, mt_policy>
|
||||||
{
|
{
|
||||||
public:
|
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()
|
signal4()
|
||||||
{
|
{
|
||||||
;
|
;
|
||||||
|
@ -2443,7 +2443,7 @@ namespace sigslot {
|
||||||
arg4_type, arg5_type, mt_policy>
|
arg4_type, arg5_type, mt_policy>
|
||||||
{
|
{
|
||||||
public:
|
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()
|
signal5()
|
||||||
{
|
{
|
||||||
;
|
;
|
||||||
|
@ -2518,7 +2518,7 @@ namespace sigslot {
|
||||||
arg4_type, arg5_type, arg6_type, mt_policy>
|
arg4_type, arg5_type, arg6_type, mt_policy>
|
||||||
{
|
{
|
||||||
public:
|
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;
|
arg4_type, arg5_type, arg6_type, mt_policy>::connections_list::const_iterator const_iterator;
|
||||||
signal6()
|
signal6()
|
||||||
{
|
{
|
||||||
|
@ -2594,7 +2594,7 @@ namespace sigslot {
|
||||||
arg4_type, arg5_type, arg6_type, arg7_type, mt_policy>
|
arg4_type, arg5_type, arg6_type, arg7_type, mt_policy>
|
||||||
{
|
{
|
||||||
public:
|
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;
|
arg4_type, arg5_type, arg6_type, arg7_type, mt_policy>::connections_list::const_iterator const_iterator;
|
||||||
signal7()
|
signal7()
|
||||||
{
|
{
|
||||||
|
@ -2671,7 +2671,7 @@ namespace sigslot {
|
||||||
arg4_type, arg5_type, arg6_type, arg7_type, arg8_type, mt_policy>
|
arg4_type, arg5_type, arg6_type, arg7_type, arg8_type, mt_policy>
|
||||||
{
|
{
|
||||||
public:
|
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;
|
arg4_type, arg5_type, arg6_type, arg7_type, arg8_type, mt_policy>::connections_list::const_iterator const_iterator;
|
||||||
signal8()
|
signal8()
|
||||||
{
|
{
|
||||||
|
|
|
@ -68,14 +68,14 @@ bool I4ToGD(const u8 * buffer, u32 width, u32 height, gdImagePtr * im)
|
||||||
u32 iv;
|
u32 iv;
|
||||||
|
|
||||||
if(!buffer)
|
if(!buffer)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
*im = gdImageCreateTrueColor(width, height);
|
*im = gdImageCreateTrueColor(width, height);
|
||||||
if(*im == 0)
|
if(*im == 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
gdImageAlphaBlending(*im, 0);
|
gdImageAlphaBlending(*im, 0);
|
||||||
gdImageSaveAlpha(*im, 1);
|
gdImageSaveAlpha(*im, 1);
|
||||||
|
|
||||||
for(iv = 0, y1 = 0; y1 < height; y1 += 8)
|
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;
|
u32 iv;
|
||||||
|
|
||||||
if(!buffer)
|
if(!buffer)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
*im = gdImageCreateTrueColor(width, height);
|
*im = gdImageCreateTrueColor(width, height);
|
||||||
if(*im == 0)
|
if(*im == 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
gdImageAlphaBlending(*im, 0);
|
gdImageAlphaBlending(*im, 0);
|
||||||
gdImageSaveAlpha(*im, 1);
|
gdImageSaveAlpha(*im, 1);
|
||||||
|
|
||||||
for(iv = 0, y1 = 0; y1 < height; y1 += 4)
|
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 g = ((oldpixel & 0xF) * 255) / 15;
|
||||||
u8 b = ((oldpixel & 0xF) * 255) / 15;
|
u8 b = ((oldpixel & 0xF) * 255) / 15;
|
||||||
u8 a = ((oldpixel >> 4) * 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));
|
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;
|
u32 iv;
|
||||||
|
|
||||||
if(!buffer)
|
if(!buffer)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
*im = gdImageCreateTrueColor(width, height);
|
*im = gdImageCreateTrueColor(width, height);
|
||||||
if(*im == 0)
|
if(*im == 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
gdImageAlphaBlending(*im, 0);
|
gdImageAlphaBlending(*im, 0);
|
||||||
gdImageSaveAlpha(*im, 1);
|
gdImageSaveAlpha(*im, 1);
|
||||||
|
|
||||||
for(iv = 0, y1 = 0; y1 < height; y1 += 4)
|
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;
|
u32 iv;
|
||||||
|
|
||||||
if(!buffer)
|
if(!buffer)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
*im = gdImageCreateTrueColor(width, height);
|
*im = gdImageCreateTrueColor(width, height);
|
||||||
if(*im == 0)
|
if(*im == 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
gdImageAlphaBlending(*im, 0);
|
gdImageAlphaBlending(*im, 0);
|
||||||
gdImageSaveAlpha(*im, 1);
|
gdImageSaveAlpha(*im, 1);
|
||||||
|
|
||||||
for(iv = 0, y1 = 0; y1 < height; y1 += 4)
|
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 g = oldpixel >> 8;
|
||||||
u8 b = oldpixel >> 8;
|
u8 b = oldpixel >> 8;
|
||||||
u8 a = oldpixel & 0xFF;
|
u8 a = oldpixel & 0xFF;
|
||||||
a = 127-127*a/255;
|
a = 127-127*a/255;
|
||||||
|
|
||||||
gdImageSetPixel(*im, x+1, y, gdTrueColorAlpha(r, g, b, a));
|
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)
|
bool CMPToGD(const u8* buffer, u32 width, u32 height, gdImagePtr * im)
|
||||||
{
|
{
|
||||||
u32 x, y;
|
u32 x, y;
|
||||||
u8 r, g, b, a;
|
u8 r, g, b, a;
|
||||||
u16 raw;
|
u16 raw;
|
||||||
u16 c[4];
|
u16 c[4];
|
||||||
int x0, x1, x2, y0, y1, y2, off;
|
int x0, x1, x2, y0, y1, y2, off;
|
||||||
int ww = (-(-(width) & -(8)));
|
int ww = (-(-(width) & -(8)));
|
||||||
int ix;
|
int ix;
|
||||||
u32 px;
|
u32 px;
|
||||||
|
|
||||||
if(!buffer)
|
if(!buffer)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
*im = gdImageCreateTrueColor(width, height);
|
*im = gdImageCreateTrueColor(width, height);
|
||||||
if(*im == 0)
|
if(*im == 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
gdImageAlphaBlending(*im, 0);
|
gdImageAlphaBlending(*im, 0);
|
||||||
gdImageSaveAlpha(*im, 1);
|
gdImageSaveAlpha(*im, 1);
|
||||||
|
|
||||||
for (y = 0; y < height; y++)
|
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;
|
b = (raw << 3) & 0xf8;
|
||||||
a = gdAlphaOpaque;
|
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;
|
u32 iv;
|
||||||
|
|
||||||
if(!buffer)
|
if(!buffer)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
*im = gdImageCreateTrueColor(width, height);
|
*im = gdImageCreateTrueColor(width, height);
|
||||||
if(*im == 0)
|
if(*im == 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
gdImageAlphaBlending(*im, 0);
|
gdImageAlphaBlending(*im, 0);
|
||||||
gdImageSaveAlpha(*im, 1);
|
gdImageSaveAlpha(*im, 1);
|
||||||
|
|
||||||
for(iv = 0, y1 = 0; y1 < height; y1 += 4)
|
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 b = ((pixel >> 0) & 0x1F) << 3;
|
||||||
u8 a = gdAlphaOpaque;
|
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;
|
u32 iv;
|
||||||
|
|
||||||
if(!buffer)
|
if(!buffer)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
*im = gdImageCreateTrueColor(width, height);
|
*im = gdImageCreateTrueColor(width, height);
|
||||||
if(*im == 0)
|
if(*im == 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
gdImageAlphaBlending(*im, 0);
|
gdImageAlphaBlending(*im, 0);
|
||||||
gdImageSaveAlpha(*im, 1);
|
gdImageSaveAlpha(*im, 1);
|
||||||
|
|
||||||
for(iv = 0, y1 = 0; y1 < height; y1 += 4)
|
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 b = (((pixel >> 0) & 0x1F) * 255) / 31;
|
||||||
u8 a = gdAlphaOpaque;
|
u8 a = gdAlphaOpaque;
|
||||||
|
|
||||||
gdImageSetPixel(*im, x, y, gdTrueColorAlpha(r, g, b, a));
|
gdImageSetPixel(*im, x, y, gdTrueColorAlpha(r, g, b, a));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -384,9 +384,9 @@ bool RGB565A3ToGD(const u8* buffer, u32 width, u32 height, gdImagePtr * im)
|
||||||
u8 g = (((pixel >> 8) & 0xF) * 255) / 15;
|
u8 g = (((pixel >> 8) & 0xF) * 255) / 15;
|
||||||
u8 b = (((pixel >> 4) & 0xF) * 255) / 15;
|
u8 b = (((pixel >> 4) & 0xF) * 255) / 15;
|
||||||
u8 a = (((pixel >> 0) & 0x7) * 64) / 7;
|
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;
|
u8 r, g, b, a;
|
||||||
|
|
||||||
if(!buffer)
|
if(!buffer)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
*im = gdImageCreateTrueColor(width, height);
|
*im = gdImageCreateTrueColor(width, height);
|
||||||
if(*im == 0)
|
if(*im == 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
gdImageAlphaBlending(*im, 0);
|
gdImageAlphaBlending(*im, 0);
|
||||||
gdImageSaveAlpha(*im, 1);
|
gdImageSaveAlpha(*im, 1);
|
||||||
|
|
||||||
for(y = 0; y < height; y++)
|
for(y = 0; y < height; y++)
|
||||||
{
|
{
|
||||||
for(x = 0; x < width; x++)
|
for(x = 0; x < width; x++)
|
||||||
{
|
{
|
||||||
offset = coordsRGBA8(x, y, width);
|
offset = coordsRGBA8(x, y, width);
|
||||||
a = *(buffer+offset);
|
a = *(buffer+offset);
|
||||||
r = *(buffer+offset+1);
|
r = *(buffer+offset+1);
|
||||||
g = *(buffer+offset+32);
|
g = *(buffer+offset+32);
|
||||||
b = *(buffer+offset+33);
|
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)
|
bool YCbYCrToGD(const u8* buffer, u32 width, u32 height, gdImagePtr * im)
|
||||||
{
|
{
|
||||||
u32 x, y, x1, YCbYCr;
|
u32 x, y, x1, YCbYCr;
|
||||||
int r, g, b;
|
int r, g, b;
|
||||||
u8 r1, g1, b1;
|
u8 r1, g1, b1;
|
||||||
|
|
||||||
if(!buffer)
|
if(!buffer)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
*im = gdImageCreateTrueColor(width, height);
|
*im = gdImageCreateTrueColor(width, height);
|
||||||
if(*im == 0)
|
if(*im == 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
gdImageAlphaBlending(*im, 0);
|
gdImageAlphaBlending(*im, 0);
|
||||||
gdImageSaveAlpha(*im, 1);
|
gdImageSaveAlpha(*im, 1);
|
||||||
|
|
||||||
for(y = 0; y < height; y++)
|
for(y = 0; y < height; y++)
|
||||||
{
|
{
|
||||||
for (x = 0, x1 = 0; x < (width / 2); x++, x1++)
|
for (x = 0, x1 = 0; x < (width / 2); x++, x1++)
|
||||||
{
|
{
|
||||||
YCbYCr = ((u32 *) buffer)[y*width/2+x];
|
YCbYCr = ((u32 *) buffer)[y*width/2+x];
|
||||||
|
|
||||||
u8 * val = (u8 *) &YCbYCr;
|
u8 * val = (u8 *) &YCbYCr;
|
||||||
|
|
||||||
r = (int) (1.371f * (val[3] - 128));
|
r = (int) (1.371f * (val[3] - 128));
|
||||||
g = (int) (- 0.698f * (val[3] - 128) - 0.336f * (val[1] - 128));
|
g = (int) (- 0.698f * (val[3] - 128) - 0.336f * (val[1] - 128));
|
||||||
b = (int) (1.732f * (val[1] - 128));
|
b = (int) (1.732f * (val[1] - 128));
|
||||||
|
|
||||||
r1 = cut_bounds(val[0] + r, 0, 255);
|
r1 = cut_bounds(val[0] + r, 0, 255);
|
||||||
g1 = cut_bounds(val[0] + g, 0, 255);
|
g1 = cut_bounds(val[0] + g, 0, 255);
|
||||||
b1 = cut_bounds(val[0] + b, 0, 255);
|
b1 = cut_bounds(val[0] + b, 0, 255);
|
||||||
|
|
||||||
gdImageSetPixel(*im, x1, y, gdTrueColorAlpha(r1, g1, b1, gdAlphaOpaque));
|
gdImageSetPixel(*im, x1, y, gdTrueColorAlpha(r1, g1, b1, gdAlphaOpaque));
|
||||||
x1++;
|
x1++;
|
||||||
|
|
||||||
r1 = cut_bounds(val[2] + r, 0, 255);
|
r1 = cut_bounds(val[2] + r, 0, 255);
|
||||||
g1 = cut_bounds(val[2] + g, 0, 255);
|
g1 = cut_bounds(val[2] + g, 0, 255);
|
||||||
b1 = cut_bounds(val[2] + b, 0, 255);
|
b1 = cut_bounds(val[2] + b, 0, 255);
|
||||||
gdImageSetPixel(*im, x1, y, gdTrueColorAlpha(r1, g1, b1, gdAlphaOpaque));
|
gdImageSetPixel(*im, x1, y, gdTrueColorAlpha(r1, g1, b1, gdAlphaOpaque));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
u8 * GDImageToRGBA8(gdImagePtr * gdImg, int * w, int * h)
|
u8 * GDImageToRGBA8(gdImagePtr * gdImg, int * w, int * h)
|
||||||
{
|
{
|
||||||
int width = gdImageSX(*gdImg);
|
int width = gdImageSX(*gdImg);
|
||||||
int height = gdImageSY(*gdImg);
|
int height = gdImageSY(*gdImg);
|
||||||
float scale = 1.0f;
|
float scale = 1.0f;
|
||||||
int retries = 100; //shouldn't need that long but to be sure
|
int retries = 100; //shouldn't need that long but to be sure
|
||||||
|
|
||||||
gdImageAlphaBlending(*gdImg, 0);
|
gdImageAlphaBlending(*gdImg, 0);
|
||||||
gdImageSaveAlpha(*gdImg, 1);
|
gdImageSaveAlpha(*gdImg, 1);
|
||||||
|
|
||||||
while(width*scale > MAXWIDTH || height*scale > MAXHEIGHT)
|
while(width*scale > MAXWIDTH || height*scale > MAXHEIGHT)
|
||||||
{
|
{
|
||||||
if(width*scale > MAXWIDTH)
|
if(width*scale > MAXWIDTH)
|
||||||
scale = MAXWIDTH/width;
|
scale = MAXWIDTH/width;
|
||||||
if(height*scale > MAXHEIGHT)
|
if(height*scale > MAXHEIGHT)
|
||||||
scale = MAXHEIGHT/height;
|
scale = MAXHEIGHT/height;
|
||||||
|
|
||||||
retries--;
|
retries--;
|
||||||
|
|
||||||
if(!retries)
|
if(!retries)
|
||||||
{
|
{
|
||||||
while(width*scale > MAXWIDTH || height*scale > MAXHEIGHT)
|
while(width*scale > MAXWIDTH || height*scale > MAXHEIGHT)
|
||||||
scale -= 0.02;
|
scale -= 0.02;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
width = ALIGN((int) (width * scale));
|
width = ALIGN((int) (width * scale));
|
||||||
height = ALIGN((int) (height * scale));
|
height = ALIGN((int) (height * scale));
|
||||||
|
|
||||||
if(width != gdImageSX(*gdImg) || height != gdImageSY(*gdImg))
|
if(width != gdImageSX(*gdImg) || height != gdImageSY(*gdImg))
|
||||||
{
|
{
|
||||||
gdImagePtr dst = gdImageCreateTrueColor(width, height);
|
gdImagePtr dst = gdImageCreateTrueColor(width, height);
|
||||||
gdImageAlphaBlending(dst, 0);
|
gdImageAlphaBlending(dst, 0);
|
||||||
gdImageSaveAlpha(dst, 1);
|
gdImageSaveAlpha(dst, 1);
|
||||||
gdImageCopyResized(dst, *gdImg, 0, 0, 0, 0, width, height, gdImageSX(*gdImg), gdImageSY(*gdImg));
|
gdImageCopyResized(dst, *gdImg, 0, 0, 0, 0, width, height, gdImageSX(*gdImg), gdImageSY(*gdImg));
|
||||||
|
|
||||||
gdImageDestroy(*gdImg);
|
gdImageDestroy(*gdImg);
|
||||||
*gdImg = dst;
|
*gdImg = dst;
|
||||||
|
|
||||||
width = gdImageSX(*gdImg);
|
width = gdImageSX(*gdImg);
|
||||||
height = gdImageSY(*gdImg);
|
height = gdImageSY(*gdImg);
|
||||||
}
|
}
|
||||||
|
|
||||||
int len = datasizeRGBA8(width, height);
|
int len = datasizeRGBA8(width, height);
|
||||||
|
|
||||||
u8 * data = (u8 *) memalign(32, len);
|
u8 * data = (u8 *) memalign(32, len);
|
||||||
if(!data)
|
if(!data)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
u8 a;
|
u8 a;
|
||||||
int x, y;
|
int x, y;
|
||||||
u32 pixel, offset;
|
u32 pixel, offset;
|
||||||
|
|
||||||
for(y = 0; y < height; ++y)
|
for(y = 0; y < height; ++y)
|
||||||
{
|
{
|
||||||
for(x = 0; x < width; ++x)
|
for(x = 0; x < width; ++x)
|
||||||
{
|
{
|
||||||
pixel = gdImageGetPixel(*gdImg, x, y);
|
pixel = gdImageGetPixel(*gdImg, x, y);
|
||||||
|
|
||||||
a = 254 - 2*((u8)gdImageAlpha(*gdImg, pixel));
|
a = 254 - 2*((u8)gdImageAlpha(*gdImg, pixel));
|
||||||
if(a == 254) a++;
|
if(a == 254) a++;
|
||||||
|
|
||||||
offset = coordsRGBA8(x, y, width);
|
offset = coordsRGBA8(x, y, width);
|
||||||
data[offset] = a;
|
data[offset] = a;
|
||||||
data[offset+1] = (u8)gdImageRed(*gdImg, pixel);
|
data[offset+1] = (u8)gdImageRed(*gdImg, pixel);
|
||||||
data[offset+32] = (u8)gdImageGreen(*gdImg, pixel);
|
data[offset+32] = (u8)gdImageGreen(*gdImg, pixel);
|
||||||
data[offset+33] = (u8)gdImageBlue(*gdImg, pixel);
|
data[offset+33] = (u8)gdImageBlue(*gdImg, pixel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
DCFlushRange(data, len);
|
DCFlushRange(data, len);
|
||||||
|
|
||||||
if(w)
|
if(w)
|
||||||
*w = width;
|
*w = width;
|
||||||
if(h)
|
if(h)
|
||||||
*h = height;
|
*h = height;
|
||||||
|
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
u8 * FlipRGBAImage(const u8 *src, u32 width, u32 height)
|
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);
|
u8 * data = memalign(32, len);
|
||||||
if(!data)
|
if(!data)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
for (y = 0; y < height; y++)
|
for (y = 0; y < height; y++)
|
||||||
{
|
{
|
||||||
for (x = 0; x < width; x++)
|
for (x = 0; x < width; x++)
|
||||||
{
|
{
|
||||||
u32 offset = coordsRGBA8(x, y, width);
|
u32 offset = coordsRGBA8(x, y, width);
|
||||||
u8 a = src[offset];
|
u8 a = src[offset];
|
||||||
u8 r = src[offset+1];
|
u8 r = src[offset+1];
|
||||||
u8 g = src[offset+32];
|
u8 g = src[offset+32];
|
||||||
u8 b = src[offset+33];
|
u8 b = src[offset+33];
|
||||||
|
|
||||||
u32 offset2 = coordsRGBA8((width-x-1), (height-y-1), width);
|
u32 offset2 = coordsRGBA8((width-x-1), (height-y-1), width);
|
||||||
data[offset2] = a;
|
data[offset2] = a;
|
||||||
data[offset2+1] = r;
|
data[offset2+1] = r;
|
||||||
data[offset2+32] = g;
|
data[offset2+32] = g;
|
||||||
data[offset2+33] = b;
|
data[offset2+33] = b;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
DCFlushRange(data, len);
|
DCFlushRange(data, len);
|
||||||
|
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
u8 * RGB8ToRGBA8(const u8 *src, u32 width, u32 height)
|
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);
|
u8 * dst = (u8 *) memalign(32, len);
|
||||||
if(!dst)
|
if(!dst)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
for (y = 0; y < height; ++y)
|
for (y = 0; y < height; ++y)
|
||||||
{
|
{
|
||||||
for (x = 0; x < width; ++x)
|
for (x = 0; x < width; ++x)
|
||||||
{
|
{
|
||||||
offset = coordsRGBA8(x, y, width);
|
offset = coordsRGBA8(x, y, width);
|
||||||
dst[offset] = 0xFF;
|
dst[offset] = 0xFF;
|
||||||
dst[offset+1] = src[(y*width+x)*3];
|
dst[offset+1] = src[(y*width+x)*3];
|
||||||
dst[offset+32] = src[(y*width+x)*3+1];
|
dst[offset+32] = src[(y*width+x)*3+1];
|
||||||
dst[offset+33] = src[(y*width+x)*3+2];
|
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)
|
TplImage::TplImage(const char * filepath)
|
||||||
{
|
{
|
||||||
TPLBuffer = NULL;
|
TPLBuffer = NULL;
|
||||||
TPLSize = 0;
|
TPLSize = 0;
|
||||||
|
|
||||||
u8 * buffer = NULL;
|
u8 * buffer = NULL;
|
||||||
u64 filesize = 0;
|
u64 filesize = 0;
|
||||||
LoadFileToMem(filepath, &buffer, &filesize);
|
LoadFileToMem(filepath, &buffer, &filesize);
|
||||||
|
|
||||||
if(buffer)
|
if(buffer)
|
||||||
{
|
{
|
||||||
LoadImage(buffer, filesize);
|
LoadImage(buffer, filesize);
|
||||||
free(buffer);
|
free(buffer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TplImage::TplImage(const u8 * imgBuffer, u32 imgSize)
|
TplImage::TplImage(const u8 * imgBuffer, u32 imgSize)
|
||||||
{
|
{
|
||||||
TPLBuffer = NULL;
|
TPLBuffer = NULL;
|
||||||
TPLSize = 0;
|
TPLSize = 0;
|
||||||
|
|
||||||
if(imgBuffer)
|
if(imgBuffer)
|
||||||
{
|
{
|
||||||
LoadImage(imgBuffer, imgSize);
|
LoadImage(imgBuffer, imgSize);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TplImage::~TplImage()
|
TplImage::~TplImage()
|
||||||
{
|
{
|
||||||
if(TPLBuffer)
|
if(TPLBuffer)
|
||||||
free(TPLBuffer);
|
free(TPLBuffer);
|
||||||
|
|
||||||
Texture.clear();
|
Texture.clear();
|
||||||
TextureHeader.clear();
|
TextureHeader.clear();
|
||||||
TplTextureBuffer.clear();
|
TplTextureBuffer.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TplImage::LoadImage(const u8 * imgBuffer, u32 imgSize)
|
bool TplImage::LoadImage(const u8 * imgBuffer, u32 imgSize)
|
||||||
{
|
{
|
||||||
if(TPLBuffer)
|
if(TPLBuffer)
|
||||||
free(TPLBuffer);
|
free(TPLBuffer);
|
||||||
|
|
||||||
TPLBuffer = NULL;
|
TPLBuffer = NULL;
|
||||||
TPLSize = 0;
|
TPLSize = 0;
|
||||||
|
|
||||||
if(!imgBuffer)
|
if(!imgBuffer)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
TPLBuffer = (u8 *) malloc(imgSize);
|
TPLBuffer = (u8 *) malloc(imgSize);
|
||||||
if(!TPLBuffer)
|
if(!TPLBuffer)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
TPLSize = imgSize;
|
TPLSize = imgSize;
|
||||||
|
|
||||||
memcpy(TPLBuffer, imgBuffer, imgSize);
|
memcpy(TPLBuffer, imgBuffer, imgSize);
|
||||||
|
|
||||||
return ParseTplFile();
|
return ParseTplFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TplImage::ParseTplFile()
|
bool TplImage::ParseTplFile()
|
||||||
{
|
{
|
||||||
if(!TPLBuffer)
|
if(!TPLBuffer)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
TPLHeader = (const TPL_Header *) TPLBuffer;
|
TPLHeader = (const TPL_Header *) TPLBuffer;
|
||||||
|
|
||||||
if(TPLHeader->magic != 0x0020AF30)
|
if(TPLHeader->magic != 0x0020AF30)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if(TPLHeader->head_size != 12)
|
if(TPLHeader->head_size != 12)
|
||||||
return false;
|
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++)
|
for(u32 i = 0; i < TPLHeader->num_textures; i++)
|
||||||
{
|
{
|
||||||
Texture.resize(i+1);
|
Texture.resize(i+1);
|
||||||
TextureHeader.resize(i+1);
|
TextureHeader.resize(i+1);
|
||||||
TplTextureBuffer.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)
|
int TplImage::GetWidth(int pos)
|
||||||
{
|
{
|
||||||
if(pos < 0 || pos >= (int) Texture.size())
|
if(pos < 0 || pos >= (int) Texture.size())
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return TextureHeader[pos]->width;
|
return TextureHeader[pos]->width;
|
||||||
}
|
}
|
||||||
|
|
||||||
int TplImage::GetHeight(int pos)
|
int TplImage::GetHeight(int pos)
|
||||||
{
|
{
|
||||||
if(pos < 0 || pos >= (int) TextureHeader.size())
|
if(pos < 0 || pos >= (int) TextureHeader.size())
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return TextureHeader[pos]->height;
|
return TextureHeader[pos]->height;
|
||||||
}
|
}
|
||||||
|
|
||||||
u32 TplImage::GetFormat(int pos)
|
u32 TplImage::GetFormat(int pos)
|
||||||
{
|
{
|
||||||
if(pos < 0 || pos >= (int) TextureHeader.size())
|
if(pos < 0 || pos >= (int) TextureHeader.size())
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return TextureHeader[pos]->format;
|
return TextureHeader[pos]->format;
|
||||||
}
|
}
|
||||||
|
|
||||||
const u8 * TplImage::GetTextureBuffer(int pos)
|
const u8 * TplImage::GetTextureBuffer(int pos)
|
||||||
{
|
{
|
||||||
if(pos < 0 || pos >= (int) TplTextureBuffer.size())
|
if(pos < 0 || pos >= (int) TplTextureBuffer.size())
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return TplTextureBuffer[pos];
|
return TplTextureBuffer[pos];
|
||||||
}
|
}
|
||||||
|
|
||||||
int TplImage::GetTextureSize(int pos)
|
int TplImage::GetTextureSize(int pos)
|
||||||
{
|
{
|
||||||
int width = GetWidth(pos);
|
int width = GetWidth(pos);
|
||||||
int height = GetHeight(pos);
|
int height = GetHeight(pos);
|
||||||
int len = 0;
|
int len = 0;
|
||||||
|
|
||||||
switch(GetFormat(pos))
|
switch(GetFormat(pos))
|
||||||
{
|
{
|
||||||
case GX_TF_I4:
|
case GX_TF_I4:
|
||||||
case GX_TF_CI4:
|
case GX_TF_CI4:
|
||||||
case GX_TF_CMPR:
|
case GX_TF_CMPR:
|
||||||
len = ((width+7)>>3)*((height+7)>>3)*32;
|
len = ((width+7)>>3)*((height+7)>>3)*32;
|
||||||
break;
|
break;
|
||||||
case GX_TF_I8:
|
case GX_TF_I8:
|
||||||
case GX_TF_IA4:
|
case GX_TF_IA4:
|
||||||
case GX_TF_CI8:
|
case GX_TF_CI8:
|
||||||
len = ((width+7)>>3)*((height+7)>>2)*32;
|
len = ((width+7)>>3)*((height+7)>>2)*32;
|
||||||
break;
|
break;
|
||||||
case GX_TF_IA8:
|
case GX_TF_IA8:
|
||||||
case GX_TF_CI14:
|
case GX_TF_CI14:
|
||||||
case GX_TF_RGB565:
|
case GX_TF_RGB565:
|
||||||
case GX_TF_RGB5A3:
|
case GX_TF_RGB5A3:
|
||||||
len = ((width+3)>>2)*((height+3)>>2)*32;
|
len = ((width+3)>>2)*((height+3)>>2)*32;
|
||||||
break;
|
break;
|
||||||
case GX_TF_RGBA8:
|
case GX_TF_RGBA8:
|
||||||
len = ((width+3)>>2)*((height+3)>>2)*32*2;
|
len = ((width+3)>>2)*((height+3)>>2)*32*2;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
len = ((width+3)>>2)*((height+3)>>2)*32*2;
|
len = ((width+3)>>2)*((height+3)>>2)*32*2;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
gdImagePtr TplImage::ConvertToGD(int pos)
|
gdImagePtr TplImage::ConvertToGD(int pos)
|
||||||
{
|
{
|
||||||
if(pos < 0 || pos >= (int) Texture.size())
|
if(pos < 0 || pos >= (int) Texture.size())
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
gdImagePtr gdImg = 0;
|
gdImagePtr gdImg = 0;
|
||||||
|
|
||||||
switch(TextureHeader[pos]->format)
|
switch(TextureHeader[pos]->format)
|
||||||
{
|
{
|
||||||
case GX_TF_RGB565:
|
case GX_TF_RGB565:
|
||||||
RGB565ToGD(TplTextureBuffer[pos], TextureHeader[pos]->width, TextureHeader[pos]->height, &gdImg);
|
RGB565ToGD(TplTextureBuffer[pos], TextureHeader[pos]->width, TextureHeader[pos]->height, &gdImg);
|
||||||
break;
|
break;
|
||||||
case GX_TF_RGB5A3:
|
case GX_TF_RGB5A3:
|
||||||
RGB565A3ToGD(TplTextureBuffer[pos], TextureHeader[pos]->width, TextureHeader[pos]->height, &gdImg);
|
RGB565A3ToGD(TplTextureBuffer[pos], TextureHeader[pos]->width, TextureHeader[pos]->height, &gdImg);
|
||||||
break;
|
break;
|
||||||
case GX_TF_RGBA8:
|
case GX_TF_RGBA8:
|
||||||
RGBA8ToGD(TplTextureBuffer[pos], TextureHeader[pos]->width, TextureHeader[pos]->height, &gdImg);
|
RGBA8ToGD(TplTextureBuffer[pos], TextureHeader[pos]->width, TextureHeader[pos]->height, &gdImg);
|
||||||
break;
|
break;
|
||||||
case GX_TF_I4:
|
case GX_TF_I4:
|
||||||
I4ToGD(TplTextureBuffer[pos], TextureHeader[pos]->width, TextureHeader[pos]->height, &gdImg);
|
I4ToGD(TplTextureBuffer[pos], TextureHeader[pos]->width, TextureHeader[pos]->height, &gdImg);
|
||||||
break;
|
break;
|
||||||
case GX_TF_I8:
|
case GX_TF_I8:
|
||||||
I8ToGD(TplTextureBuffer[pos], TextureHeader[pos]->width, TextureHeader[pos]->height, &gdImg);
|
I8ToGD(TplTextureBuffer[pos], TextureHeader[pos]->width, TextureHeader[pos]->height, &gdImg);
|
||||||
break;
|
break;
|
||||||
case GX_TF_IA4:
|
case GX_TF_IA4:
|
||||||
IA4ToGD(TplTextureBuffer[pos], TextureHeader[pos]->width, TextureHeader[pos]->height, &gdImg);
|
IA4ToGD(TplTextureBuffer[pos], TextureHeader[pos]->width, TextureHeader[pos]->height, &gdImg);
|
||||||
break;
|
break;
|
||||||
case GX_TF_IA8:
|
case GX_TF_IA8:
|
||||||
IA8ToGD(TplTextureBuffer[pos], TextureHeader[pos]->width, TextureHeader[pos]->height, &gdImg);
|
IA8ToGD(TplTextureBuffer[pos], TextureHeader[pos]->width, TextureHeader[pos]->height, &gdImg);
|
||||||
break;
|
break;
|
||||||
case GX_TF_CMPR:
|
case GX_TF_CMPR:
|
||||||
CMPToGD(TplTextureBuffer[pos], TextureHeader[pos]->width, TextureHeader[pos]->height, &gdImg);
|
CMPToGD(TplTextureBuffer[pos], TextureHeader[pos]->width, TextureHeader[pos]->height, &gdImg);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
gdImg = 0;
|
gdImg = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return gdImg;
|
return gdImg;
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,15 +34,15 @@
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
u32 magic;
|
u32 magic;
|
||||||
u32 num_textures;
|
u32 num_textures;
|
||||||
u32 head_size;
|
u32 head_size;
|
||||||
} TPL_Header;
|
} TPL_Header;
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
u32 text_header_offset;
|
u32 text_header_offset;
|
||||||
u32 text_palette_offset;
|
u32 text_palette_offset;
|
||||||
} TPL_Texture;
|
} TPL_Texture;
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
|
@ -73,26 +73,26 @@ typedef struct
|
||||||
|
|
||||||
class TplImage
|
class TplImage
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
TplImage(const char * filepath);
|
TplImage(const char * filepath);
|
||||||
TplImage(const u8 * imgBuffer, u32 imgSize);
|
TplImage(const u8 * imgBuffer, u32 imgSize);
|
||||||
~TplImage();
|
~TplImage();
|
||||||
bool LoadImage(const u8 * imgBuffer, u32 imgSize);
|
bool LoadImage(const u8 * imgBuffer, u32 imgSize);
|
||||||
int GetWidth(int Texture);
|
int GetWidth(int Texture);
|
||||||
int GetHeight(int Texture);
|
int GetHeight(int Texture);
|
||||||
u32 GetFormat(int Texture);
|
u32 GetFormat(int Texture);
|
||||||
const u8 * GetTextureBuffer(int Texture);
|
const u8 * GetTextureBuffer(int Texture);
|
||||||
int GetTextureSize(int Texture);
|
int GetTextureSize(int Texture);
|
||||||
gdImagePtr ConvertToGD(int Texture);
|
gdImagePtr ConvertToGD(int Texture);
|
||||||
private:
|
private:
|
||||||
bool ParseTplFile();
|
bool ParseTplFile();
|
||||||
|
|
||||||
u8 * TPLBuffer;
|
u8 * TPLBuffer;
|
||||||
u32 TPLSize;
|
u32 TPLSize;
|
||||||
const TPL_Header * TPLHeader;
|
const TPL_Header * TPLHeader;
|
||||||
std::vector<const TPL_Texture *> Texture;
|
std::vector<const TPL_Texture *> Texture;
|
||||||
std::vector<const TPL_Texture_Header *> TextureHeader;
|
std::vector<const TPL_Texture_Header *> TextureHeader;
|
||||||
std::vector<const u8 *> TplTextureBuffer;
|
std::vector<const u8 *> TplTextureBuffer;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -51,64 +51,64 @@ typedef struct
|
||||||
# define HUGE_VAL HUGE
|
# define HUGE_VAL HUGE
|
||||||
#endif
|
#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)
|
static double ConvertFromIeeeExtended(const unsigned char* bytes)
|
||||||
{
|
{
|
||||||
double f;
|
double f;
|
||||||
int expon;
|
int expon;
|
||||||
unsigned long hiMant, loMant;
|
unsigned long hiMant, loMant;
|
||||||
|
|
||||||
expon = ((bytes[0] & 0x7F) << 8) | (bytes[1] & 0xFF);
|
expon = ((bytes[0] & 0x7F) << 8) | (bytes[1] & 0xFF);
|
||||||
hiMant = ((unsigned long)(bytes[2] & 0xFF) << 24)
|
hiMant = ((unsigned long)(bytes[2] & 0xFF) << 24)
|
||||||
| ((unsigned long)(bytes[3] & 0xFF) << 16)
|
| ((unsigned long)(bytes[3] & 0xFF) << 16)
|
||||||
| ((unsigned long)(bytes[4] & 0xFF) << 8)
|
| ((unsigned long)(bytes[4] & 0xFF) << 8)
|
||||||
| ((unsigned long)(bytes[5] & 0xFF));
|
| ((unsigned long)(bytes[5] & 0xFF));
|
||||||
loMant = ((unsigned long)(bytes[6] & 0xFF) << 24)
|
loMant = ((unsigned long)(bytes[6] & 0xFF) << 24)
|
||||||
| ((unsigned long)(bytes[7] & 0xFF) << 16)
|
| ((unsigned long)(bytes[7] & 0xFF) << 16)
|
||||||
| ((unsigned long)(bytes[8] & 0xFF) << 8)
|
| ((unsigned long)(bytes[8] & 0xFF) << 8)
|
||||||
| ((unsigned long)(bytes[9] & 0xFF));
|
| ((unsigned long)(bytes[9] & 0xFF));
|
||||||
|
|
||||||
if (expon == 0 && hiMant == 0 && loMant == 0) {
|
if (expon == 0 && hiMant == 0 && loMant == 0) {
|
||||||
f = 0;
|
f = 0;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (expon == 0x7FFF) {
|
if (expon == 0x7FFF) {
|
||||||
f = HUGE_VAL;
|
f = HUGE_VAL;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
expon -= 16383;
|
expon -= 16383;
|
||||||
f = ldexp(UnsignedToFloat(hiMant), expon-=31);
|
f = ldexp(UnsignedToFloat(hiMant), expon-=31);
|
||||||
f += ldexp(UnsignedToFloat(loMant), expon-=32);
|
f += ldexp(UnsignedToFloat(loMant), expon-=32);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bytes[0] & 0x80)
|
if (bytes[0] & 0x80)
|
||||||
return -f;
|
return -f;
|
||||||
else
|
else
|
||||||
return f;
|
return f;
|
||||||
}
|
}
|
||||||
|
|
||||||
AifDecoder::AifDecoder(const char * filepath)
|
AifDecoder::AifDecoder(const char * filepath)
|
||||||
: SoundDecoder(filepath)
|
: SoundDecoder(filepath)
|
||||||
{
|
{
|
||||||
SoundType = SOUND_AIF;
|
SoundType = SOUND_AIF;
|
||||||
|
|
||||||
if(!file_fd)
|
if(!file_fd)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
OpenFile();
|
OpenFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
AifDecoder::AifDecoder(const u8 * snd, int len)
|
AifDecoder::AifDecoder(const u8 * snd, int len)
|
||||||
: SoundDecoder(snd, len)
|
: SoundDecoder(snd, len)
|
||||||
{
|
{
|
||||||
SoundType = SOUND_AIF;
|
SoundType = SOUND_AIF;
|
||||||
|
|
||||||
if(!file_fd)
|
if(!file_fd)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
OpenFile();
|
OpenFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
AifDecoder::~AifDecoder()
|
AifDecoder::~AifDecoder()
|
||||||
|
@ -117,8 +117,8 @@ AifDecoder::~AifDecoder()
|
||||||
|
|
||||||
void AifDecoder::OpenFile()
|
void AifDecoder::OpenFile()
|
||||||
{
|
{
|
||||||
SWaveHdr Header;
|
SWaveHdr Header;
|
||||||
file_fd->read((u8 *) &Header, sizeof(SWaveHdr));
|
file_fd->read((u8 *) &Header, sizeof(SWaveHdr));
|
||||||
|
|
||||||
if (Header.magicRIFF != 'FORM')
|
if (Header.magicRIFF != 'FORM')
|
||||||
{
|
{
|
||||||
|
@ -134,20 +134,20 @@ void AifDecoder::OpenFile()
|
||||||
SWaveChunk WaveChunk;
|
SWaveChunk WaveChunk;
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
int ret = file_fd->read((u8 *) &WaveChunk, sizeof(SWaveChunk));
|
int ret = file_fd->read((u8 *) &WaveChunk, sizeof(SWaveChunk));
|
||||||
if(ret <= 0)
|
if(ret <= 0)
|
||||||
{
|
{
|
||||||
CloseFile();
|
CloseFile();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
while(WaveChunk.magicDATA != 'COMM');
|
while(WaveChunk.magicDATA != 'COMM');
|
||||||
|
|
||||||
DataOffset = file_fd->tell()+WaveChunk.size;
|
DataOffset = file_fd->tell()+WaveChunk.size;
|
||||||
|
|
||||||
SAIFFCommChunk CommHdr;
|
SAIFFCommChunk CommHdr;
|
||||||
file_fd->seek(file_fd->tell()-sizeof(SWaveChunk), SEEK_SET);
|
file_fd->seek(file_fd->tell()-sizeof(SWaveChunk), SEEK_SET);
|
||||||
file_fd->read((u8 *) &CommHdr, sizeof(SAIFFCommChunk));
|
file_fd->read((u8 *) &CommHdr, sizeof(SAIFFCommChunk));
|
||||||
|
|
||||||
if(CommHdr.fccCOMM != 'COMM')
|
if(CommHdr.fccCOMM != 'COMM')
|
||||||
{
|
{
|
||||||
|
@ -155,12 +155,12 @@ void AifDecoder::OpenFile()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
file_fd->seek(DataOffset, SEEK_SET);
|
file_fd->seek(DataOffset, SEEK_SET);
|
||||||
|
|
||||||
SAIFFSSndChunk SSndChunk;
|
SAIFFSSndChunk SSndChunk;
|
||||||
file_fd->read((u8 *) &SSndChunk, sizeof(SAIFFSSndChunk));
|
file_fd->read((u8 *) &SSndChunk, sizeof(SAIFFSSndChunk));
|
||||||
|
|
||||||
if(SSndChunk.fccSSND != 'SSND')
|
if(SSndChunk.fccSSND != 'SSND')
|
||||||
{
|
{
|
||||||
CloseFile();
|
CloseFile();
|
||||||
return;
|
return;
|
||||||
|
@ -169,7 +169,7 @@ void AifDecoder::OpenFile()
|
||||||
DataOffset += sizeof(SAIFFSSndChunk);
|
DataOffset += sizeof(SAIFFSSndChunk);
|
||||||
DataSize = SSndChunk.size-8;
|
DataSize = SSndChunk.size-8;
|
||||||
SampleRate = (u32) ConvertFromIeeeExtended(CommHdr.freq);
|
SampleRate = (u32) ConvertFromIeeeExtended(CommHdr.freq);
|
||||||
Format = VOICE_STEREO_16BIT;
|
Format = VOICE_STEREO_16BIT;
|
||||||
|
|
||||||
if(CommHdr.channels == 1 && CommHdr.bps == 8)
|
if(CommHdr.channels == 1 && CommHdr.bps == 8)
|
||||||
Format = VOICE_MONO_8BIT;
|
Format = VOICE_MONO_8BIT;
|
||||||
|
@ -180,35 +180,35 @@ void AifDecoder::OpenFile()
|
||||||
else if (CommHdr.channels == 2 && CommHdr.bps == 16)
|
else if (CommHdr.channels == 2 && CommHdr.bps == 16)
|
||||||
Format = VOICE_STEREO_16BIT;
|
Format = VOICE_STEREO_16BIT;
|
||||||
|
|
||||||
Decode();
|
Decode();
|
||||||
}
|
}
|
||||||
|
|
||||||
void AifDecoder::CloseFile()
|
void AifDecoder::CloseFile()
|
||||||
{
|
{
|
||||||
if(file_fd)
|
if(file_fd)
|
||||||
delete file_fd;
|
delete file_fd;
|
||||||
|
|
||||||
file_fd = NULL;
|
file_fd = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
int AifDecoder::Read(u8 * buffer, int buffer_size, int pos)
|
int AifDecoder::Read(u8 * buffer, int buffer_size, int pos)
|
||||||
{
|
{
|
||||||
if(!file_fd)
|
if(!file_fd)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if(CurPos >= (int) DataSize)
|
if(CurPos >= (int) DataSize)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
file_fd->seek(DataOffset+CurPos, SEEK_SET);
|
file_fd->seek(DataOffset+CurPos, SEEK_SET);
|
||||||
|
|
||||||
if(buffer_size > (int) DataSize-CurPos)
|
if(buffer_size > (int) DataSize-CurPos)
|
||||||
buffer_size = DataSize-CurPos;
|
buffer_size = DataSize-CurPos;
|
||||||
|
|
||||||
int read = file_fd->read(buffer, buffer_size);
|
int read = file_fd->read(buffer, buffer_size);
|
||||||
if(read > 0)
|
if(read > 0)
|
||||||
{
|
{
|
||||||
CurPos += read;
|
CurPos += read;
|
||||||
}
|
}
|
||||||
|
|
||||||
return read;
|
return read;
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,20 +31,20 @@
|
||||||
|
|
||||||
class AifDecoder : public SoundDecoder
|
class AifDecoder : public SoundDecoder
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
AifDecoder(const char * filepath);
|
AifDecoder(const char * filepath);
|
||||||
AifDecoder(const u8 * snd, int len);
|
AifDecoder(const u8 * snd, int len);
|
||||||
virtual ~AifDecoder();
|
virtual ~AifDecoder();
|
||||||
int GetFormat() { return Format; };
|
int GetFormat() { return Format; };
|
||||||
int GetSampleRate() { return SampleRate; };
|
int GetSampleRate() { return SampleRate; };
|
||||||
int Read(u8 * buffer, int buffer_size, int pos);
|
int Read(u8 * buffer, int buffer_size, int pos);
|
||||||
protected:
|
protected:
|
||||||
void OpenFile();
|
void OpenFile();
|
||||||
void CloseFile();
|
void CloseFile();
|
||||||
u32 DataOffset;
|
u32 DataOffset;
|
||||||
u32 DataSize;
|
u32 DataSize;
|
||||||
u32 SampleRate;
|
u32 SampleRate;
|
||||||
u8 Format;
|
u8 Format;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -32,112 +32,112 @@
|
||||||
SoundBlock DecodefromBNS(const u8 *buffer, u32 size);
|
SoundBlock DecodefromBNS(const u8 *buffer, u32 size);
|
||||||
|
|
||||||
BNSDecoder::BNSDecoder(const char * filepath)
|
BNSDecoder::BNSDecoder(const char * filepath)
|
||||||
: SoundDecoder(filepath)
|
: SoundDecoder(filepath)
|
||||||
{
|
{
|
||||||
SoundType = SOUND_BNS;
|
SoundType = SOUND_BNS;
|
||||||
memset(&SoundData, 0, sizeof(SoundBlock));
|
memset(&SoundData, 0, sizeof(SoundBlock));
|
||||||
|
|
||||||
if(!file_fd)
|
if(!file_fd)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
OpenFile();
|
OpenFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
BNSDecoder::BNSDecoder(const u8 * snd, int len)
|
BNSDecoder::BNSDecoder(const u8 * snd, int len)
|
||||||
: SoundDecoder(snd, len)
|
: SoundDecoder(snd, len)
|
||||||
{
|
{
|
||||||
SoundType = SOUND_BNS;
|
SoundType = SOUND_BNS;
|
||||||
memset(&SoundData, 0, sizeof(SoundBlock));
|
memset(&SoundData, 0, sizeof(SoundBlock));
|
||||||
|
|
||||||
if(!file_fd)
|
if(!file_fd)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
OpenFile();
|
OpenFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
BNSDecoder::~BNSDecoder()
|
BNSDecoder::~BNSDecoder()
|
||||||
{
|
{
|
||||||
ExitRequested = true;
|
ExitRequested = true;
|
||||||
while(Decoding)
|
while(Decoding)
|
||||||
usleep(100);
|
usleep(100);
|
||||||
|
|
||||||
if(SoundData.buffer != NULL)
|
if(SoundData.buffer != NULL)
|
||||||
free(SoundData.buffer);
|
free(SoundData.buffer);
|
||||||
|
|
||||||
SoundData.buffer = NULL;
|
SoundData.buffer = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BNSDecoder::OpenFile()
|
void BNSDecoder::OpenFile()
|
||||||
{
|
{
|
||||||
u8 * tempbuff = new (std::nothrow) u8[file_fd->size()];
|
u8 * tempbuff = new (std::nothrow) u8[file_fd->size()];
|
||||||
if(!tempbuff)
|
if(!tempbuff)
|
||||||
{
|
{
|
||||||
CloseFile();
|
CloseFile();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int done = 0;
|
int done = 0;
|
||||||
|
|
||||||
while(done < file_fd->size())
|
while(done < file_fd->size())
|
||||||
{
|
{
|
||||||
int read = file_fd->read(tempbuff, file_fd->size());
|
int read = file_fd->read(tempbuff, file_fd->size());
|
||||||
if(read > 0)
|
if(read > 0)
|
||||||
done += read;
|
done += read;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
CloseFile();
|
CloseFile();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SoundData = DecodefromBNS(tempbuff, done);
|
SoundData = DecodefromBNS(tempbuff, done);
|
||||||
if(SoundData.buffer == NULL)
|
if(SoundData.buffer == NULL)
|
||||||
{
|
{
|
||||||
CloseFile();
|
CloseFile();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
delete [] tempbuff;
|
delete [] tempbuff;
|
||||||
tempbuff = NULL;
|
tempbuff = NULL;
|
||||||
|
|
||||||
Decode();
|
Decode();
|
||||||
}
|
}
|
||||||
|
|
||||||
void BNSDecoder::CloseFile()
|
void BNSDecoder::CloseFile()
|
||||||
{
|
{
|
||||||
if(file_fd)
|
if(file_fd)
|
||||||
delete file_fd;
|
delete file_fd;
|
||||||
|
|
||||||
file_fd = NULL;
|
file_fd = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
int BNSDecoder::Read(u8 * buffer, int buffer_size, int pos)
|
int BNSDecoder::Read(u8 * buffer, int buffer_size, int pos)
|
||||||
{
|
{
|
||||||
if(!SoundData.buffer)
|
if(!SoundData.buffer)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if(SoundData.loopFlag)
|
if(SoundData.loopFlag)
|
||||||
{
|
{
|
||||||
int factor = SoundData.format == VOICE_STEREO_16BIT ? 4 : 2;
|
int factor = SoundData.format == VOICE_STEREO_16BIT ? 4 : 2;
|
||||||
if(CurPos >= (int) SoundData.loopEnd*factor)
|
if(CurPos >= (int) SoundData.loopEnd*factor)
|
||||||
CurPos = SoundData.loopStart*factor;
|
CurPos = SoundData.loopStart*factor;
|
||||||
|
|
||||||
if(buffer_size > (int) SoundData.loopEnd*factor-CurPos)
|
if(buffer_size > (int) SoundData.loopEnd*factor-CurPos)
|
||||||
buffer_size = SoundData.loopEnd*factor-CurPos;
|
buffer_size = SoundData.loopEnd*factor-CurPos;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if(CurPos >= (int) SoundData.size)
|
if(CurPos >= (int) SoundData.size)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if(buffer_size > (int) SoundData.size-CurPos)
|
if(buffer_size > (int) SoundData.size-CurPos)
|
||||||
buffer_size = SoundData.size-CurPos;
|
buffer_size = SoundData.size-CurPos;
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(buffer, SoundData.buffer+CurPos, buffer_size);
|
memcpy(buffer, SoundData.buffer+CurPos, buffer_size);
|
||||||
CurPos += buffer_size;
|
CurPos += buffer_size;
|
||||||
|
|
||||||
return buffer_size;
|
return buffer_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct BNSHeader
|
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 DecodefromBNS(const u8 *buffer, u32 size)
|
||||||
{
|
{
|
||||||
SoundBlock OutBlock;
|
SoundBlock OutBlock;
|
||||||
memset(&OutBlock, 0, sizeof(SoundBlock));
|
memset(&OutBlock, 0, sizeof(SoundBlock));
|
||||||
|
|
||||||
const BNSHeader &hdr = *(BNSHeader *)buffer;
|
const BNSHeader &hdr = *(BNSHeader *)buffer;
|
||||||
if (size < sizeof hdr)
|
if (size < sizeof hdr)
|
||||||
|
|
|
@ -41,17 +41,17 @@ typedef struct _SoundBlock
|
||||||
|
|
||||||
class BNSDecoder : public SoundDecoder
|
class BNSDecoder : public SoundDecoder
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
BNSDecoder(const char * filepath);
|
BNSDecoder(const char * filepath);
|
||||||
BNSDecoder(const u8 * snd, int len);
|
BNSDecoder(const u8 * snd, int len);
|
||||||
virtual ~BNSDecoder();
|
virtual ~BNSDecoder();
|
||||||
int GetFormat() { return SoundData.format; };
|
int GetFormat() { return SoundData.format; };
|
||||||
int GetSampleRate() { return SoundData.frequency; };
|
int GetSampleRate() { return SoundData.frequency; };
|
||||||
int Read(u8 * buffer, int buffer_size, int pos);
|
int Read(u8 * buffer, int buffer_size, int pos);
|
||||||
protected:
|
protected:
|
||||||
void OpenFile();
|
void OpenFile();
|
||||||
void CloseFile();
|
void CloseFile();
|
||||||
SoundBlock SoundData;
|
SoundBlock SoundData;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -30,115 +30,115 @@
|
||||||
|
|
||||||
BufferCircle::BufferCircle()
|
BufferCircle::BufferCircle()
|
||||||
{
|
{
|
||||||
which = 0;
|
which = 0;
|
||||||
BufferBlockSize = 0;
|
BufferBlockSize = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
BufferCircle::~BufferCircle()
|
BufferCircle::~BufferCircle()
|
||||||
{
|
{
|
||||||
FreeBuffer();
|
FreeBuffer();
|
||||||
SoundBuffer.clear();
|
SoundBuffer.clear();
|
||||||
BufferSize.clear();
|
BufferSize.clear();
|
||||||
BufferReady.clear();
|
BufferReady.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void BufferCircle::SetBufferBlockSize(int size)
|
void BufferCircle::SetBufferBlockSize(int size)
|
||||||
{
|
{
|
||||||
if(size < 0)
|
if(size < 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
BufferBlockSize = size;
|
BufferBlockSize = size;
|
||||||
|
|
||||||
for(int i = 0; i < Size(); i++)
|
for(int i = 0; i < Size(); i++)
|
||||||
{
|
{
|
||||||
if(SoundBuffer[i] != NULL)
|
if(SoundBuffer[i] != NULL)
|
||||||
free(SoundBuffer[i]);
|
free(SoundBuffer[i]);
|
||||||
|
|
||||||
SoundBuffer[i] = (u8 *) memalign(32, ALIGN32(BufferBlockSize));
|
SoundBuffer[i] = (u8 *) memalign(32, ALIGN32(BufferBlockSize));
|
||||||
BufferSize[i] = 0;
|
BufferSize[i] = 0;
|
||||||
BufferReady[i] = false;
|
BufferReady[i] = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void BufferCircle::Resize(int size)
|
void BufferCircle::Resize(int size)
|
||||||
{
|
{
|
||||||
while(size < Size())
|
while(size < Size())
|
||||||
RemoveBuffer(Size()-1);
|
RemoveBuffer(Size()-1);
|
||||||
|
|
||||||
int oldSize = Size();
|
int oldSize = Size();
|
||||||
|
|
||||||
SoundBuffer.resize(size);
|
SoundBuffer.resize(size);
|
||||||
BufferSize.resize(size);
|
BufferSize.resize(size);
|
||||||
BufferReady.resize(size);
|
BufferReady.resize(size);
|
||||||
|
|
||||||
for(int i = oldSize; i < Size(); i++)
|
for(int i = oldSize; i < Size(); i++)
|
||||||
{
|
{
|
||||||
if(BufferBlockSize > 0)
|
if(BufferBlockSize > 0)
|
||||||
SoundBuffer[i] = (u8 *) memalign(32, ALIGN32(BufferBlockSize));
|
SoundBuffer[i] = (u8 *) memalign(32, ALIGN32(BufferBlockSize));
|
||||||
else
|
else
|
||||||
SoundBuffer[i] = NULL;
|
SoundBuffer[i] = NULL;
|
||||||
BufferSize[i] = 0;
|
BufferSize[i] = 0;
|
||||||
BufferReady[i] = false;
|
BufferReady[i] = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void BufferCircle::RemoveBuffer(int pos)
|
void BufferCircle::RemoveBuffer(int pos)
|
||||||
{
|
{
|
||||||
if(!Valid(pos))
|
if(!Valid(pos))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if(SoundBuffer[pos] != NULL)
|
if(SoundBuffer[pos] != NULL)
|
||||||
free(SoundBuffer[pos]);
|
free(SoundBuffer[pos]);
|
||||||
|
|
||||||
SoundBuffer.erase(SoundBuffer.begin()+pos);
|
SoundBuffer.erase(SoundBuffer.begin()+pos);
|
||||||
BufferSize.erase(BufferSize.begin()+pos);
|
BufferSize.erase(BufferSize.begin()+pos);
|
||||||
BufferReady.erase(BufferReady.begin()+pos);
|
BufferReady.erase(BufferReady.begin()+pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BufferCircle::ClearBuffer()
|
void BufferCircle::ClearBuffer()
|
||||||
{
|
{
|
||||||
for(int i = 0; i < Size(); i++)
|
for(int i = 0; i < Size(); i++)
|
||||||
{
|
{
|
||||||
BufferSize[i] = 0;
|
BufferSize[i] = 0;
|
||||||
BufferReady[i] = false;
|
BufferReady[i] = false;
|
||||||
}
|
}
|
||||||
which = 0;
|
which = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BufferCircle::FreeBuffer()
|
void BufferCircle::FreeBuffer()
|
||||||
{
|
{
|
||||||
for(int i = 0; i < Size(); i++)
|
for(int i = 0; i < Size(); i++)
|
||||||
{
|
{
|
||||||
if(SoundBuffer[i] != NULL)
|
if(SoundBuffer[i] != NULL)
|
||||||
free(SoundBuffer[i]);
|
free(SoundBuffer[i]);
|
||||||
|
|
||||||
SoundBuffer[i] = NULL;
|
SoundBuffer[i] = NULL;
|
||||||
BufferSize[i] = 0;
|
BufferSize[i] = 0;
|
||||||
BufferReady[i] = false;
|
BufferReady[i] = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void BufferCircle::LoadNext()
|
void BufferCircle::LoadNext()
|
||||||
{
|
{
|
||||||
int pos = (which+Size()-1) % Size();
|
int pos = (which+Size()-1) % Size();
|
||||||
BufferReady[pos] = false;
|
BufferReady[pos] = false;
|
||||||
BufferSize[pos] = 0;
|
BufferSize[pos] = 0;
|
||||||
|
|
||||||
which = (which+1) % Size();
|
which = (which+1) % Size();
|
||||||
}
|
}
|
||||||
|
|
||||||
void BufferCircle::SetBufferReady(int pos, bool state)
|
void BufferCircle::SetBufferReady(int pos, bool state)
|
||||||
{
|
{
|
||||||
if(!Valid(pos))
|
if(!Valid(pos))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
BufferReady[pos] = state;
|
BufferReady[pos] = state;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BufferCircle::SetBufferSize(int pos, int size)
|
void BufferCircle::SetBufferSize(int pos, int size)
|
||||||
{
|
{
|
||||||
if(!Valid(pos))
|
if(!Valid(pos))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
BufferSize[pos] = size;
|
BufferSize[pos] = size;
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,62 +31,62 @@
|
||||||
|
|
||||||
class BufferCircle
|
class BufferCircle
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
//!> Constructor
|
//!> Constructor
|
||||||
BufferCircle();
|
BufferCircle();
|
||||||
//!> Destructor
|
//!> Destructor
|
||||||
~BufferCircle();
|
~BufferCircle();
|
||||||
//!> Set circle size
|
//!> Set circle size
|
||||||
void Resize(int size);
|
void Resize(int size);
|
||||||
//!> Get the circle size
|
//!> Get the circle size
|
||||||
int Size() { return SoundBuffer.size(); };
|
int Size() { return SoundBuffer.size(); };
|
||||||
//!> Set/resize the buffer size
|
//!> Set/resize the buffer size
|
||||||
void SetBufferBlockSize(int size);
|
void SetBufferBlockSize(int size);
|
||||||
//!> Remove a buffer
|
//!> Remove a buffer
|
||||||
void RemoveBuffer(int pos);
|
void RemoveBuffer(int pos);
|
||||||
//!> Set all buffers clear
|
//!> Set all buffers clear
|
||||||
void ClearBuffer();
|
void ClearBuffer();
|
||||||
//!> Free all buffers
|
//!> Free all buffers
|
||||||
void FreeBuffer();
|
void FreeBuffer();
|
||||||
//!> Switch to next buffer
|
//!> Switch to next buffer
|
||||||
void LoadNext();
|
void LoadNext();
|
||||||
//!> Get the current buffer
|
//!> Get the current buffer
|
||||||
u8 * GetBuffer() { if(!Valid(which)) return 0; return SoundBuffer[which]; };
|
u8 * GetBuffer() { if(!Valid(which)) return 0; return SoundBuffer[which]; };
|
||||||
//!> Get a buffer at a position
|
//!> Get a buffer at a position
|
||||||
u8 * GetBuffer(int pos) { if(!Valid(pos)) return NULL; else return SoundBuffer[pos]; };
|
u8 * GetBuffer(int pos) { if(!Valid(pos)) return NULL; else return SoundBuffer[pos]; };
|
||||||
//!> Get next buffer
|
//!> Get next buffer
|
||||||
u8 * GetNextBuffer() { if(Size() <= 0) return 0; else return SoundBuffer[(which+1) % Size()]; };
|
u8 * GetNextBuffer() { if(Size() <= 0) return 0; else return SoundBuffer[(which+1) % Size()]; };
|
||||||
//!> Get previous buffer
|
//!> Get previous buffer
|
||||||
u8 * GetLastBuffer() { if(Size() <= 0) return 0; else return SoundBuffer[(which+Size()-1) % Size()]; };
|
u8 * GetLastBuffer() { if(Size() <= 0) return 0; else return SoundBuffer[(which+Size()-1) % Size()]; };
|
||||||
//!> Get current buffer size
|
//!> Get current buffer size
|
||||||
u32 GetBufferSize() { if(!Valid(which)) return 0; else return BufferSize[which]; };
|
u32 GetBufferSize() { if(!Valid(which)) return 0; else return BufferSize[which]; };
|
||||||
//!> Get buffer size at position
|
//!> Get buffer size at position
|
||||||
u32 GetBufferSize(int pos) { if(!Valid(pos)) return 0; else return BufferSize[pos]; };
|
u32 GetBufferSize(int pos) { if(!Valid(pos)) return 0; else return BufferSize[pos]; };
|
||||||
//!> Get previous buffer size
|
//!> Get previous buffer size
|
||||||
u32 GetLastBufferSize() { if(Size() <= 0) return 0; else return BufferSize[(which+Size()-1) % Size()]; };
|
u32 GetLastBufferSize() { if(Size() <= 0) return 0; else return BufferSize[(which+Size()-1) % Size()]; };
|
||||||
//!> Is current buffer ready
|
//!> Is current buffer ready
|
||||||
bool IsBufferReady() { if(!Valid(which)) return false; else return BufferReady[which]; };
|
bool IsBufferReady() { if(!Valid(which)) return false; else return BufferReady[which]; };
|
||||||
//!> Is a buffer at a position ready
|
//!> Is a buffer at a position ready
|
||||||
bool IsBufferReady(int pos) { if(!Valid(pos)) return false; else return BufferReady[pos]; };
|
bool IsBufferReady(int pos) { if(!Valid(pos)) return false; else return BufferReady[pos]; };
|
||||||
//!> Is next buffer ready
|
//!> Is next buffer ready
|
||||||
bool IsNextBufferReady() { if(Size() <= 0) return false; else return BufferReady[(which+1) % Size()]; };
|
bool IsNextBufferReady() { if(Size() <= 0) return false; else return BufferReady[(which+1) % Size()]; };
|
||||||
//!> Is last buffer ready
|
//!> Is last buffer ready
|
||||||
bool IsLastBufferReady() { if(Size() <= 0) return false; else return BufferReady[(which+Size()-1) % Size()]; };
|
bool IsLastBufferReady() { if(Size() <= 0) return false; else return BufferReady[(which+Size()-1) % Size()]; };
|
||||||
//!> Set a buffer at a position to a ready state
|
//!> Set a buffer at a position to a ready state
|
||||||
void SetBufferReady(int pos, bool st);
|
void SetBufferReady(int pos, bool st);
|
||||||
//!> Set the buffersize at a position
|
//!> Set the buffersize at a position
|
||||||
void SetBufferSize(int pos, int size);
|
void SetBufferSize(int pos, int size);
|
||||||
//!> Get the current position in the circle
|
//!> Get the current position in the circle
|
||||||
u16 Which() { return which; };
|
u16 Which() { return which; };
|
||||||
protected:
|
protected:
|
||||||
//!> Check if the position is a valid position in the vector
|
//!> Check if the position is a valid position in the vector
|
||||||
bool Valid(int pos) { return !(pos < 0 || pos >= Size()); };
|
bool Valid(int pos) { return !(pos < 0 || pos >= Size()); };
|
||||||
|
|
||||||
u16 which;
|
u16 which;
|
||||||
u32 BufferBlockSize;
|
u32 BufferBlockSize;
|
||||||
std::vector<u8 *> SoundBuffer;
|
std::vector<u8 *> SoundBuffer;
|
||||||
std::vector<u32> BufferSize;
|
std::vector<u32> BufferSize;
|
||||||
std::vector<bool> BufferReady;
|
std::vector<bool> BufferReady;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -32,96 +32,96 @@
|
||||||
#include "Mp3Decoder.hpp"
|
#include "Mp3Decoder.hpp"
|
||||||
|
|
||||||
Mp3Decoder::Mp3Decoder(const char * filepath)
|
Mp3Decoder::Mp3Decoder(const char * filepath)
|
||||||
: SoundDecoder(filepath)
|
: SoundDecoder(filepath)
|
||||||
{
|
{
|
||||||
SoundType = SOUND_MP3;
|
SoundType = SOUND_MP3;
|
||||||
ReadBuffer = NULL;
|
ReadBuffer = NULL;
|
||||||
mad_timer_reset(&Timer);
|
mad_timer_reset(&Timer);
|
||||||
mad_stream_init(&Stream);
|
mad_stream_init(&Stream);
|
||||||
mad_frame_init(&Frame);
|
mad_frame_init(&Frame);
|
||||||
mad_synth_init(&Synth);
|
mad_synth_init(&Synth);
|
||||||
|
|
||||||
if(!file_fd)
|
if(!file_fd)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
OpenFile();
|
OpenFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
Mp3Decoder::Mp3Decoder(const u8 * snd, int len)
|
Mp3Decoder::Mp3Decoder(const u8 * snd, int len)
|
||||||
: SoundDecoder(snd, len)
|
: SoundDecoder(snd, len)
|
||||||
{
|
{
|
||||||
SoundType = SOUND_MP3;
|
SoundType = SOUND_MP3;
|
||||||
ReadBuffer = NULL;
|
ReadBuffer = NULL;
|
||||||
mad_timer_reset(&Timer);
|
mad_timer_reset(&Timer);
|
||||||
mad_stream_init(&Stream);
|
mad_stream_init(&Stream);
|
||||||
mad_frame_init(&Frame);
|
mad_frame_init(&Frame);
|
||||||
mad_synth_init(&Synth);
|
mad_synth_init(&Synth);
|
||||||
|
|
||||||
if(!file_fd)
|
if(!file_fd)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
OpenFile();
|
OpenFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
Mp3Decoder::~Mp3Decoder()
|
Mp3Decoder::~Mp3Decoder()
|
||||||
{
|
{
|
||||||
ExitRequested = true;
|
ExitRequested = true;
|
||||||
while(Decoding)
|
while(Decoding)
|
||||||
usleep(100);
|
usleep(100);
|
||||||
|
|
||||||
mad_synth_finish(&Synth);
|
mad_synth_finish(&Synth);
|
||||||
mad_frame_finish(&Frame);
|
mad_frame_finish(&Frame);
|
||||||
mad_stream_finish(&Stream);
|
mad_stream_finish(&Stream);
|
||||||
|
|
||||||
if(ReadBuffer)
|
if(ReadBuffer)
|
||||||
free(ReadBuffer);
|
free(ReadBuffer);
|
||||||
ReadBuffer = NULL;
|
ReadBuffer = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Mp3Decoder::OpenFile()
|
void Mp3Decoder::OpenFile()
|
||||||
{
|
{
|
||||||
GuardPtr = NULL;
|
GuardPtr = NULL;
|
||||||
ReadBuffer = (u8 *) memalign(32, SoundBlockSize*SoundBlocks);
|
ReadBuffer = (u8 *) memalign(32, SoundBlockSize*SoundBlocks);
|
||||||
if(!ReadBuffer)
|
if(!ReadBuffer)
|
||||||
{
|
{
|
||||||
if(file_fd)
|
if(file_fd)
|
||||||
delete file_fd;
|
delete file_fd;
|
||||||
file_fd = NULL;
|
file_fd = NULL;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
u8 dummybuff[4096];
|
u8 dummybuff[4096];
|
||||||
int ret = Read(dummybuff, 4096, 0);
|
int ret = Read(dummybuff, 4096, 0);
|
||||||
if(ret <= 0)
|
if(ret <= 0)
|
||||||
{
|
{
|
||||||
if(file_fd)
|
if(file_fd)
|
||||||
delete file_fd;
|
delete file_fd;
|
||||||
file_fd = NULL;
|
file_fd = NULL;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
SampleRate = (u32) Frame.header.samplerate;
|
SampleRate = (u32) Frame.header.samplerate;
|
||||||
Format = ((MAD_NCHANNELS(&Frame.header) == 2) ? VOICE_STEREO_16BIT : VOICE_MONO_16BIT);
|
Format = ((MAD_NCHANNELS(&Frame.header) == 2) ? VOICE_STEREO_16BIT : VOICE_MONO_16BIT);
|
||||||
Rewind();
|
Rewind();
|
||||||
Decode();
|
Decode();
|
||||||
}
|
}
|
||||||
|
|
||||||
int Mp3Decoder::Rewind()
|
int Mp3Decoder::Rewind()
|
||||||
{
|
{
|
||||||
mad_synth_finish(&Synth);
|
mad_synth_finish(&Synth);
|
||||||
mad_frame_finish(&Frame);
|
mad_frame_finish(&Frame);
|
||||||
mad_stream_finish(&Stream);
|
mad_stream_finish(&Stream);
|
||||||
mad_timer_reset(&Timer);
|
mad_timer_reset(&Timer);
|
||||||
mad_stream_init(&Stream);
|
mad_stream_init(&Stream);
|
||||||
mad_frame_init(&Frame);
|
mad_frame_init(&Frame);
|
||||||
mad_synth_init(&Synth);
|
mad_synth_init(&Synth);
|
||||||
SynthPos = 0;
|
SynthPos = 0;
|
||||||
GuardPtr = NULL;
|
GuardPtr = NULL;
|
||||||
|
|
||||||
if(!file_fd)
|
if(!file_fd)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
return SoundDecoder::Rewind();
|
return SoundDecoder::Rewind();
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline s16 FixedToShort(mad_fixed_t Fixed)
|
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)
|
int Mp3Decoder::Read(u8 * buffer, int buffer_size, int pos)
|
||||||
{
|
{
|
||||||
if(!file_fd)
|
if(!file_fd)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if(Format == VOICE_STEREO_16BIT)
|
if(Format == VOICE_STEREO_16BIT)
|
||||||
buffer_size &= ~0x0003;
|
buffer_size &= ~0x0003;
|
||||||
else
|
else
|
||||||
buffer_size &= ~0x0001;
|
buffer_size &= ~0x0001;
|
||||||
|
|
||||||
u8 * write_pos = buffer;
|
u8 * write_pos = buffer;
|
||||||
u8 * write_end = buffer+buffer_size;
|
u8 * write_end = buffer+buffer_size;
|
||||||
|
|
||||||
while(1)
|
while(1)
|
||||||
{
|
{
|
||||||
while(SynthPos < Synth.pcm.length)
|
while(SynthPos < Synth.pcm.length)
|
||||||
{
|
{
|
||||||
if(write_pos >= write_end)
|
if(write_pos >= write_end)
|
||||||
return write_pos-buffer;
|
return write_pos-buffer;
|
||||||
|
|
||||||
*((s16 *) write_pos) = FixedToShort(Synth.pcm.samples[0][SynthPos]);
|
*((s16 *) write_pos) = FixedToShort(Synth.pcm.samples[0][SynthPos]);
|
||||||
write_pos += 2;
|
write_pos += 2;
|
||||||
|
|
||||||
if(MAD_NCHANNELS(&Frame.header) == 2)
|
if(MAD_NCHANNELS(&Frame.header) == 2)
|
||||||
{
|
{
|
||||||
*((s16 *) write_pos) = FixedToShort(Synth.pcm.samples[1][SynthPos]);
|
*((s16 *) write_pos) = FixedToShort(Synth.pcm.samples[1][SynthPos]);
|
||||||
write_pos += 2;
|
write_pos += 2;
|
||||||
}
|
}
|
||||||
SynthPos++;
|
SynthPos++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(Stream.buffer == NULL || Stream.error == MAD_ERROR_BUFLEN)
|
if(Stream.buffer == NULL || Stream.error == MAD_ERROR_BUFLEN)
|
||||||
{
|
{
|
||||||
u8 * ReadStart = ReadBuffer;
|
u8 * ReadStart = ReadBuffer;
|
||||||
int ReadSize = SoundBlockSize*SoundBlocks;
|
int ReadSize = SoundBlockSize*SoundBlocks;
|
||||||
int Remaining = 0;
|
int Remaining = 0;
|
||||||
|
@ -182,14 +182,14 @@ int Mp3Decoder::Read(u8 * buffer, int buffer_size, int pos)
|
||||||
}
|
}
|
||||||
|
|
||||||
ReadSize = file_fd->read(ReadStart, ReadSize);
|
ReadSize = file_fd->read(ReadStart, ReadSize);
|
||||||
if(ReadSize <= 0)
|
if(ReadSize <= 0)
|
||||||
{
|
{
|
||||||
GuardPtr = ReadStart;
|
GuardPtr = ReadStart;
|
||||||
memset(GuardPtr, 0, MAD_BUFFER_GUARD);
|
memset(GuardPtr, 0, MAD_BUFFER_GUARD);
|
||||||
ReadSize = MAD_BUFFER_GUARD;
|
ReadSize = MAD_BUFFER_GUARD;
|
||||||
}
|
}
|
||||||
|
|
||||||
CurPos += ReadSize;
|
CurPos += ReadSize;
|
||||||
mad_stream_buffer(&Stream, ReadBuffer, Remaining+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(MAD_RECOVERABLE(Stream.error))
|
||||||
{
|
{
|
||||||
if(Stream.error != MAD_ERROR_LOSTSYNC || !GuardPtr)
|
if(Stream.error != MAD_ERROR_LOSTSYNC || !GuardPtr)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if(Stream.error != MAD_ERROR_BUFLEN)
|
if(Stream.error != MAD_ERROR_BUFLEN)
|
||||||
return -1;
|
return -1;
|
||||||
else if(Stream.error == MAD_ERROR_BUFLEN && GuardPtr)
|
else if(Stream.error == MAD_ERROR_BUFLEN && GuardPtr)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mad_timer_add(&Timer,Frame.header.duration);
|
mad_timer_add(&Timer,Frame.header.duration);
|
||||||
mad_synth_frame(&Synth,&Frame);
|
mad_synth_frame(&Synth,&Frame);
|
||||||
SynthPos = 0;
|
SynthPos = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,23 +29,23 @@
|
||||||
|
|
||||||
class Mp3Decoder : public SoundDecoder
|
class Mp3Decoder : public SoundDecoder
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Mp3Decoder(const char * filepath);
|
Mp3Decoder(const char * filepath);
|
||||||
Mp3Decoder(const u8 * sound, int len);
|
Mp3Decoder(const u8 * sound, int len);
|
||||||
virtual ~Mp3Decoder();
|
virtual ~Mp3Decoder();
|
||||||
int GetFormat() { return Format; };
|
int GetFormat() { return Format; };
|
||||||
int GetSampleRate() { return SampleRate; };
|
int GetSampleRate() { return SampleRate; };
|
||||||
int Rewind();
|
int Rewind();
|
||||||
int Read(u8 * buffer, int buffer_size, int pos);
|
int Read(u8 * buffer, int buffer_size, int pos);
|
||||||
protected:
|
protected:
|
||||||
void OpenFile();
|
void OpenFile();
|
||||||
struct mad_stream Stream;
|
struct mad_stream Stream;
|
||||||
struct mad_frame Frame;
|
struct mad_frame Frame;
|
||||||
struct mad_synth Synth;
|
struct mad_synth Synth;
|
||||||
mad_timer_t Timer;
|
mad_timer_t Timer;
|
||||||
u8 * GuardPtr;
|
u8 * GuardPtr;
|
||||||
u8 * ReadBuffer;
|
u8 * ReadBuffer;
|
||||||
u8 Format;
|
u8 Format;
|
||||||
u32 SampleRate;
|
u32 SampleRate;
|
||||||
u32 SynthPos;
|
u32 SynthPos;
|
||||||
};
|
};
|
||||||
|
|
|
@ -29,7 +29,7 @@
|
||||||
|
|
||||||
extern "C" int ogg_read(void * punt, int bytes, int blocks, int *f)
|
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)
|
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)
|
extern "C" int ogg_close(int *f)
|
||||||
{
|
{
|
||||||
((CFile *) f)->close();
|
((CFile *) f)->close();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,95 +50,95 @@ extern "C" long ogg_tell(int *f)
|
||||||
|
|
||||||
static ov_callbacks callbacks = {
|
static ov_callbacks callbacks = {
|
||||||
(size_t (*)(void *, size_t, size_t, void *)) ogg_read,
|
(size_t (*)(void *, size_t, size_t, void *)) ogg_read,
|
||||||
(int (*)(void *, ogg_int64_t, int)) ogg_seek,
|
(int (*)(void *, ogg_int64_t, int)) ogg_seek,
|
||||||
(int (*)(void *)) ogg_close,
|
(int (*)(void *)) ogg_close,
|
||||||
(long (*)(void *)) ogg_tell
|
(long (*)(void *)) ogg_tell
|
||||||
};
|
};
|
||||||
|
|
||||||
OggDecoder::OggDecoder(const char * filepath)
|
OggDecoder::OggDecoder(const char * filepath)
|
||||||
: SoundDecoder(filepath)
|
: SoundDecoder(filepath)
|
||||||
{
|
{
|
||||||
SoundType = SOUND_OGG;
|
SoundType = SOUND_OGG;
|
||||||
|
|
||||||
if(!file_fd)
|
if(!file_fd)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
OpenFile();
|
OpenFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
OggDecoder::OggDecoder(const u8 * snd, int len)
|
OggDecoder::OggDecoder(const u8 * snd, int len)
|
||||||
: SoundDecoder(snd, len)
|
: SoundDecoder(snd, len)
|
||||||
{
|
{
|
||||||
SoundType = SOUND_OGG;
|
SoundType = SOUND_OGG;
|
||||||
|
|
||||||
if(!file_fd)
|
if(!file_fd)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
OpenFile();
|
OpenFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
OggDecoder::~OggDecoder()
|
OggDecoder::~OggDecoder()
|
||||||
{
|
{
|
||||||
ExitRequested = true;
|
ExitRequested = true;
|
||||||
while(Decoding)
|
while(Decoding)
|
||||||
usleep(100);
|
usleep(100);
|
||||||
|
|
||||||
if(file_fd)
|
if(file_fd)
|
||||||
ov_clear(&ogg_file);
|
ov_clear(&ogg_file);
|
||||||
}
|
}
|
||||||
|
|
||||||
void OggDecoder::OpenFile()
|
void OggDecoder::OpenFile()
|
||||||
{
|
{
|
||||||
if (ov_open_callbacks(file_fd, &ogg_file, NULL, 0, callbacks) < 0)
|
if (ov_open_callbacks(file_fd, &ogg_file, NULL, 0, callbacks) < 0)
|
||||||
{
|
{
|
||||||
delete file_fd;
|
delete file_fd;
|
||||||
file_fd = NULL;
|
file_fd = NULL;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ogg_info = ov_info(&ogg_file, -1);
|
ogg_info = ov_info(&ogg_file, -1);
|
||||||
Decode();
|
Decode();
|
||||||
}
|
}
|
||||||
|
|
||||||
int OggDecoder::GetFormat()
|
int OggDecoder::GetFormat()
|
||||||
{
|
{
|
||||||
if(!file_fd)
|
if(!file_fd)
|
||||||
return VOICE_STEREO_16BIT;
|
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()
|
int OggDecoder::GetSampleRate()
|
||||||
{
|
{
|
||||||
if(!file_fd)
|
if(!file_fd)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
return (int) ogg_info->rate;
|
return (int) ogg_info->rate;
|
||||||
}
|
}
|
||||||
|
|
||||||
int OggDecoder::Rewind()
|
int OggDecoder::Rewind()
|
||||||
{
|
{
|
||||||
if(!file_fd)
|
if(!file_fd)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
int ret = ov_time_seek(&ogg_file, 0);
|
int ret = ov_time_seek(&ogg_file, 0);
|
||||||
CurPos = 0;
|
CurPos = 0;
|
||||||
EndOfFile = false;
|
EndOfFile = false;
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int OggDecoder::Read(u8 * buffer, int buffer_size, int pos)
|
int OggDecoder::Read(u8 * buffer, int buffer_size, int pos)
|
||||||
{
|
{
|
||||||
if(!file_fd)
|
if(!file_fd)
|
||||||
return -1;
|
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)
|
if(read > 0)
|
||||||
CurPos += read;
|
CurPos += read;
|
||||||
|
|
||||||
return read;
|
return read;
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,16 +30,16 @@
|
||||||
|
|
||||||
class OggDecoder : public SoundDecoder
|
class OggDecoder : public SoundDecoder
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
OggDecoder(const char * filepath);
|
OggDecoder(const char * filepath);
|
||||||
OggDecoder(const u8 * snd, int len);
|
OggDecoder(const u8 * snd, int len);
|
||||||
virtual ~OggDecoder();
|
virtual ~OggDecoder();
|
||||||
int GetFormat();
|
int GetFormat();
|
||||||
int GetSampleRate();
|
int GetSampleRate();
|
||||||
int Rewind();
|
int Rewind();
|
||||||
int Read(u8 * buffer, int buffer_size, int pos);
|
int Read(u8 * buffer, int buffer_size, int pos);
|
||||||
protected:
|
protected:
|
||||||
void OpenFile();
|
void OpenFile();
|
||||||
OggVorbis_File ogg_file;
|
OggVorbis_File ogg_file;
|
||||||
vorbis_info *ogg_info;
|
vorbis_info *ogg_info;
|
||||||
};
|
};
|
||||||
|
|
|
@ -34,123 +34,123 @@
|
||||||
|
|
||||||
SoundDecoder::SoundDecoder()
|
SoundDecoder::SoundDecoder()
|
||||||
{
|
{
|
||||||
file_fd = NULL;
|
file_fd = NULL;
|
||||||
Init();
|
Init();
|
||||||
}
|
}
|
||||||
|
|
||||||
SoundDecoder::SoundDecoder(const char * filepath)
|
SoundDecoder::SoundDecoder(const char * filepath)
|
||||||
{
|
{
|
||||||
file_fd = new CFile(filepath, "rb");
|
file_fd = new CFile(filepath, "rb");
|
||||||
Init();
|
Init();
|
||||||
}
|
}
|
||||||
|
|
||||||
SoundDecoder::SoundDecoder(const u8 * buffer, int size)
|
SoundDecoder::SoundDecoder(const u8 * buffer, int size)
|
||||||
{
|
{
|
||||||
file_fd = new CFile(buffer, size);
|
file_fd = new CFile(buffer, size);
|
||||||
Init();
|
Init();
|
||||||
}
|
}
|
||||||
|
|
||||||
SoundDecoder::~SoundDecoder()
|
SoundDecoder::~SoundDecoder()
|
||||||
{
|
{
|
||||||
ExitRequested = true;
|
ExitRequested = true;
|
||||||
while(Decoding)
|
while(Decoding)
|
||||||
usleep(100);
|
usleep(100);
|
||||||
|
|
||||||
if(file_fd)
|
if(file_fd)
|
||||||
delete file_fd;
|
delete file_fd;
|
||||||
file_fd = NULL;
|
file_fd = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SoundDecoder::Init()
|
void SoundDecoder::Init()
|
||||||
{
|
{
|
||||||
SoundType = SOUND_RAW;
|
SoundType = SOUND_RAW;
|
||||||
SoundBlocks = 8;
|
SoundBlocks = 8;
|
||||||
SoundBlockSize = 8192;
|
SoundBlockSize = 8192;
|
||||||
CurPos = 0;
|
CurPos = 0;
|
||||||
Loop = false;
|
Loop = false;
|
||||||
EndOfFile = false;
|
EndOfFile = false;
|
||||||
Decoding = false;
|
Decoding = false;
|
||||||
ExitRequested = false;
|
ExitRequested = false;
|
||||||
SoundBuffer.SetBufferBlockSize(SoundBlockSize);
|
SoundBuffer.SetBufferBlockSize(SoundBlockSize);
|
||||||
SoundBuffer.Resize(SoundBlocks);
|
SoundBuffer.Resize(SoundBlocks);
|
||||||
}
|
}
|
||||||
|
|
||||||
int SoundDecoder::Rewind()
|
int SoundDecoder::Rewind()
|
||||||
{
|
{
|
||||||
CurPos = 0;
|
CurPos = 0;
|
||||||
EndOfFile = false;
|
EndOfFile = false;
|
||||||
file_fd->rewind();
|
file_fd->rewind();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int SoundDecoder::Read(u8 * buffer, int buffer_size, int pos)
|
int SoundDecoder::Read(u8 * buffer, int buffer_size, int pos)
|
||||||
{
|
{
|
||||||
int ret = file_fd->read(buffer, buffer_size);
|
int ret = file_fd->read(buffer, buffer_size);
|
||||||
CurPos += ret;
|
CurPos += ret;
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SoundDecoder::Decode()
|
void SoundDecoder::Decode()
|
||||||
{
|
{
|
||||||
if(!file_fd || ExitRequested || EndOfFile)
|
if(!file_fd || ExitRequested || EndOfFile)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
u16 newWhich = SoundBuffer.Which();
|
u16 newWhich = SoundBuffer.Which();
|
||||||
u16 i = 0;
|
u16 i = 0;
|
||||||
for (i = 0; i < SoundBuffer.Size()-2; i++)
|
for (i = 0; i < SoundBuffer.Size()-2; i++)
|
||||||
{
|
{
|
||||||
if(!SoundBuffer.IsBufferReady(newWhich))
|
if(!SoundBuffer.IsBufferReady(newWhich))
|
||||||
break;
|
break;
|
||||||
|
|
||||||
newWhich = (newWhich+1) % SoundBuffer.Size();
|
newWhich = (newWhich+1) % SoundBuffer.Size();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(i == SoundBuffer.Size()-2)
|
if(i == SoundBuffer.Size()-2)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Decoding = true;
|
Decoding = true;
|
||||||
|
|
||||||
int done = 0;
|
int done = 0;
|
||||||
u8 * write_buf = SoundBuffer.GetBuffer(newWhich);
|
u8 * write_buf = SoundBuffer.GetBuffer(newWhich);
|
||||||
if(!write_buf)
|
if(!write_buf)
|
||||||
{
|
{
|
||||||
ExitRequested = true;
|
ExitRequested = true;
|
||||||
Decoding = false;
|
Decoding = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
while(done < SoundBlockSize)
|
while(done < SoundBlockSize)
|
||||||
{
|
{
|
||||||
int ret = Read(&write_buf[done], SoundBlockSize-done, Tell());
|
int ret = Read(&write_buf[done], SoundBlockSize-done, Tell());
|
||||||
|
|
||||||
if(ret <= 0)
|
if(ret <= 0)
|
||||||
{
|
{
|
||||||
if(Loop)
|
if(Loop)
|
||||||
{
|
{
|
||||||
Rewind();
|
Rewind();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
EndOfFile = true;
|
EndOfFile = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
done += ret;
|
done += ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(done > 0)
|
if(done > 0)
|
||||||
{
|
{
|
||||||
SoundBuffer.SetBufferSize(newWhich, done);
|
SoundBuffer.SetBufferSize(newWhich, done);
|
||||||
SoundBuffer.SetBufferReady(newWhich, true);
|
SoundBuffer.SetBufferReady(newWhich, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!SoundBuffer.IsBufferReady((newWhich+1) % SoundBuffer.Size()))
|
if(!SoundBuffer.IsBufferReady((newWhich+1) % SoundBuffer.Size()))
|
||||||
Decode();
|
Decode();
|
||||||
|
|
||||||
Decoding = false;
|
Decoding = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -45,45 +45,45 @@ enum
|
||||||
|
|
||||||
class SoundDecoder
|
class SoundDecoder
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
SoundDecoder();
|
SoundDecoder();
|
||||||
SoundDecoder(const char * filepath);
|
SoundDecoder(const char * filepath);
|
||||||
SoundDecoder(const u8 * buffer, int size);
|
SoundDecoder(const u8 * buffer, int size);
|
||||||
virtual ~SoundDecoder();
|
virtual ~SoundDecoder();
|
||||||
virtual int Read(u8 * buffer, int buffer_size, int pos);
|
virtual int Read(u8 * buffer, int buffer_size, int pos);
|
||||||
virtual int Tell() { return CurPos; };
|
virtual int Tell() { return CurPos; };
|
||||||
virtual int Seek(int pos) { CurPos = pos; return file_fd->seek(CurPos, SEEK_SET); };
|
virtual int Seek(int pos) { CurPos = pos; return file_fd->seek(CurPos, SEEK_SET); };
|
||||||
virtual int Rewind();
|
virtual int Rewind();
|
||||||
virtual int GetFormat() { return VOICE_STEREO_16BIT; };
|
virtual int GetFormat() { return VOICE_STEREO_16BIT; };
|
||||||
virtual int GetSampleRate() { return 48000; };
|
virtual int GetSampleRate() { return 48000; };
|
||||||
virtual void Decode();
|
virtual void Decode();
|
||||||
virtual u32 GetBufferSize() { return SoundBuffer.GetBufferSize(); };
|
virtual u32 GetBufferSize() { return SoundBuffer.GetBufferSize(); };
|
||||||
virtual u8 * GetBuffer() { return SoundBuffer.GetBuffer(); };
|
virtual u8 * GetBuffer() { return SoundBuffer.GetBuffer(); };
|
||||||
virtual u8 * GetNextBuffer() { return SoundBuffer.GetNextBuffer(); };
|
virtual u8 * GetNextBuffer() { return SoundBuffer.GetNextBuffer(); };
|
||||||
virtual u8 * GetLastBuffer() { return SoundBuffer.GetLastBuffer(); };
|
virtual u8 * GetLastBuffer() { return SoundBuffer.GetLastBuffer(); };
|
||||||
virtual void LoadNext() { SoundBuffer.LoadNext(); };
|
virtual void LoadNext() { SoundBuffer.LoadNext(); };
|
||||||
virtual bool IsBufferReady() { return SoundBuffer.IsBufferReady(); };
|
virtual bool IsBufferReady() { return SoundBuffer.IsBufferReady(); };
|
||||||
virtual bool IsNextBufferReady() { return SoundBuffer.IsNextBufferReady(); };
|
virtual bool IsNextBufferReady() { return SoundBuffer.IsNextBufferReady(); };
|
||||||
virtual bool IsLastBufferReady() { return SoundBuffer.IsLastBufferReady(); };
|
virtual bool IsLastBufferReady() { return SoundBuffer.IsLastBufferReady(); };
|
||||||
virtual bool IsEOF() { return EndOfFile; };
|
virtual bool IsEOF() { return EndOfFile; };
|
||||||
virtual void SetLoop(bool l) { Loop = l; };
|
virtual void SetLoop(bool l) { Loop = l; };
|
||||||
virtual u8 GetSoundType() { return SoundType; };
|
virtual u8 GetSoundType() { return SoundType; };
|
||||||
virtual void ClearBuffer() { SoundBuffer.ClearBuffer(); };
|
virtual void ClearBuffer() { SoundBuffer.ClearBuffer(); };
|
||||||
virtual bool IsStereo() { return (GetFormat() == VOICE_STEREO_16BIT || GetFormat() == VOICE_STEREO_8BIT); };
|
virtual bool IsStereo() { return (GetFormat() == VOICE_STEREO_16BIT || GetFormat() == VOICE_STEREO_8BIT); };
|
||||||
virtual bool Is16Bit() { return (GetFormat() == VOICE_STEREO_16BIT || GetFormat() == VOICE_MONO_16BIT); };
|
virtual bool Is16Bit() { return (GetFormat() == VOICE_STEREO_16BIT || GetFormat() == VOICE_MONO_16BIT); };
|
||||||
protected:
|
protected:
|
||||||
void Init();
|
void Init();
|
||||||
|
|
||||||
CFile * file_fd;
|
CFile * file_fd;
|
||||||
BufferCircle SoundBuffer;
|
BufferCircle SoundBuffer;
|
||||||
u8 SoundType;
|
u8 SoundType;
|
||||||
u16 SoundBlocks;
|
u16 SoundBlocks;
|
||||||
int SoundBlockSize;
|
int SoundBlockSize;
|
||||||
int CurPos;
|
int CurPos;
|
||||||
bool Loop;
|
bool Loop;
|
||||||
bool EndOfFile;
|
bool EndOfFile;
|
||||||
bool Decoding;
|
bool Decoding;
|
||||||
bool ExitRequested;
|
bool ExitRequested;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -36,14 +36,14 @@ SoundHandler * SoundHandler::instance = NULL;
|
||||||
|
|
||||||
SoundHandler::SoundHandler()
|
SoundHandler::SoundHandler()
|
||||||
{
|
{
|
||||||
Decoding = false;
|
Decoding = false;
|
||||||
ExitRequested = false;
|
ExitRequested = false;
|
||||||
for(u32 i = 0; i < MAX_DECODERS; ++i)
|
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)
|
if(!ThreadStack)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
LWP_CreateThread(&SoundThread, UpdateThread, this, ThreadStack, 32768, 80);
|
LWP_CreateThread(&SoundThread, UpdateThread, this, ThreadStack, 32768, 80);
|
||||||
}
|
}
|
||||||
|
@ -55,7 +55,7 @@ SoundHandler::~SoundHandler()
|
||||||
LWP_JoinThread(SoundThread, NULL);
|
LWP_JoinThread(SoundThread, NULL);
|
||||||
SoundThread = LWP_THREAD_NULL;
|
SoundThread = LWP_THREAD_NULL;
|
||||||
if(ThreadStack)
|
if(ThreadStack)
|
||||||
free(ThreadStack);
|
free(ThreadStack);
|
||||||
|
|
||||||
ClearDecoderList();
|
ClearDecoderList();
|
||||||
}
|
}
|
||||||
|
@ -71,168 +71,168 @@ SoundHandler * SoundHandler::Instance()
|
||||||
|
|
||||||
void SoundHandler::DestroyInstance()
|
void SoundHandler::DestroyInstance()
|
||||||
{
|
{
|
||||||
if(instance)
|
if(instance)
|
||||||
{
|
{
|
||||||
delete instance;
|
delete instance;
|
||||||
}
|
}
|
||||||
instance = NULL;
|
instance = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SoundHandler::AddDecoder(int voice, const char * filepath)
|
void SoundHandler::AddDecoder(int voice, const char * filepath)
|
||||||
{
|
{
|
||||||
if(voice < 0 || voice >= MAX_DECODERS)
|
if(voice < 0 || voice >= MAX_DECODERS)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if(DecoderList[voice] != NULL)
|
if(DecoderList[voice] != NULL)
|
||||||
RemoveDecoder(voice);
|
RemoveDecoder(voice);
|
||||||
|
|
||||||
DecoderList[voice] = GetSoundDecoder(filepath);
|
DecoderList[voice] = GetSoundDecoder(filepath);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SoundHandler::AddDecoder(int voice, const u8 * snd, int len)
|
void SoundHandler::AddDecoder(int voice, const u8 * snd, int len)
|
||||||
{
|
{
|
||||||
if(voice < 0 || voice >= MAX_DECODERS)
|
if(voice < 0 || voice >= MAX_DECODERS)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if(DecoderList[voice] != NULL)
|
if(DecoderList[voice] != NULL)
|
||||||
RemoveDecoder(voice);
|
RemoveDecoder(voice);
|
||||||
|
|
||||||
DecoderList[voice] = GetSoundDecoder(snd, len);
|
DecoderList[voice] = GetSoundDecoder(snd, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SoundHandler::RemoveDecoder(int voice)
|
void SoundHandler::RemoveDecoder(int voice)
|
||||||
{
|
{
|
||||||
if(voice < 0 || voice >= MAX_DECODERS)
|
if(voice < 0 || voice >= MAX_DECODERS)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if(DecoderList[voice] != NULL)
|
if(DecoderList[voice] != NULL)
|
||||||
delete DecoderList[voice];
|
delete DecoderList[voice];
|
||||||
|
|
||||||
DecoderList[voice] = NULL;
|
DecoderList[voice] = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SoundHandler::ClearDecoderList()
|
void SoundHandler::ClearDecoderList()
|
||||||
{
|
{
|
||||||
for(u32 i = 0; i < MAX_DECODERS; ++i)
|
for(u32 i = 0; i < MAX_DECODERS; ++i)
|
||||||
RemoveDecoder(i);
|
RemoveDecoder(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline bool CheckMP3Signature(const u8 * buffer)
|
static inline bool CheckMP3Signature(const u8 * buffer)
|
||||||
{
|
{
|
||||||
const char MP3_Magic[][3] =
|
const char MP3_Magic[][3] =
|
||||||
{
|
{
|
||||||
{'I', 'D', '3'}, //'ID3'
|
{'I', 'D', '3'}, //'ID3'
|
||||||
{0xff, 0xfe}, //'MPEG ADTS, layer III, v1.0 [protected]', 'mp3', 'audio/mpeg'),
|
{0xff, 0xfe}, //'MPEG ADTS, layer III, v1.0 [protected]', 'mp3', 'audio/mpeg'),
|
||||||
{0xff, 0xff}, //'MPEG ADTS, layer III, v1.0', '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, 0xfa}, //'MPEG ADTS, layer III, v1.0 [protected]', 'mp3', 'audio/mpeg'),
|
||||||
{0xff, 0xfb}, //'MPEG ADTS, layer III, v1.0', '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, 0xf2}, //'MPEG ADTS, layer III, v2.0 [protected]', 'mp3', 'audio/mpeg'),
|
||||||
{0xff, 0xf3}, //'MPEG ADTS, layer III, v2.0', '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, 0xf4}, //'MPEG ADTS, layer III, v2.0 [protected]', 'mp3', 'audio/mpeg'),
|
||||||
{0xff, 0xf5}, //'MPEG ADTS, layer III, v2.0', '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, 0xf6}, //'MPEG ADTS, layer III, v2.0 [protected]', 'mp3', 'audio/mpeg'),
|
||||||
{0xff, 0xf7}, //'MPEG ADTS, layer III, v2.0', '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, 0xe2}, //'MPEG ADTS, layer III, v2.5 [protected]', 'mp3', 'audio/mpeg'),
|
||||||
{0xff, 0xe3}, //'MPEG ADTS, layer III, v2.5', '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] &&
|
if(buffer[0] == MP3_Magic[0][0] && buffer[1] == MP3_Magic[0][1] &&
|
||||||
buffer[2] == MP3_Magic[0][2])
|
buffer[2] == MP3_Magic[0][2])
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
for(int i = 1; i < 13; i++)
|
for(int i = 1; i < 13; i++)
|
||||||
{
|
{
|
||||||
if(buffer[0] == MP3_Magic[i][0] && buffer[1] == MP3_Magic[i][1])
|
if(buffer[0] == MP3_Magic[i][0] && buffer[1] == MP3_Magic[i][1])
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
SoundDecoder * SoundHandler::GetSoundDecoder(const char * filepath)
|
SoundDecoder * SoundHandler::GetSoundDecoder(const char * filepath)
|
||||||
{
|
{
|
||||||
u32 magic;
|
u32 magic;
|
||||||
CFile f(filepath, "rb");
|
CFile f(filepath, "rb");
|
||||||
if(f.size() == 0)
|
if(f.size() == 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
f.read((u8 *) &magic, 1);
|
f.read((u8 *) &magic, 1);
|
||||||
}
|
}
|
||||||
while(((u8 *) &magic)[0] == 0 && f.tell() < f.size());
|
while(((u8 *) &magic)[0] == 0 && f.tell() < f.size());
|
||||||
|
|
||||||
if(f.tell() == f.size())
|
if(f.tell() == f.size())
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
f.seek(f.tell()-1, SEEK_SET);
|
f.seek(f.tell()-1, SEEK_SET);
|
||||||
f.read((u8 *) &magic, 4);
|
f.read((u8 *) &magic, 4);
|
||||||
f.close();
|
f.close();
|
||||||
|
|
||||||
if(magic == 'OggS')
|
if(magic == 'OggS')
|
||||||
{
|
{
|
||||||
return new OggDecoder(filepath);
|
return new OggDecoder(filepath);
|
||||||
}
|
}
|
||||||
else if(magic == 'RIFF')
|
else if(magic == 'RIFF')
|
||||||
{
|
{
|
||||||
return new WavDecoder(filepath);
|
return new WavDecoder(filepath);
|
||||||
}
|
}
|
||||||
else if(magic == 'BNS ')
|
else if(magic == 'BNS ')
|
||||||
{
|
{
|
||||||
return new BNSDecoder(filepath);
|
return new BNSDecoder(filepath);
|
||||||
}
|
}
|
||||||
else if(magic == 'FORM')
|
else if(magic == 'FORM')
|
||||||
{
|
{
|
||||||
return new AifDecoder(filepath);
|
return new AifDecoder(filepath);
|
||||||
}
|
}
|
||||||
else if(CheckMP3Signature((u8 *) &magic) == true)
|
else if(CheckMP3Signature((u8 *) &magic) == true)
|
||||||
{
|
{
|
||||||
return new Mp3Decoder(filepath);
|
return new Mp3Decoder(filepath);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new SoundDecoder(filepath);
|
return new SoundDecoder(filepath);
|
||||||
}
|
}
|
||||||
|
|
||||||
SoundDecoder * SoundHandler::GetSoundDecoder(const u8 * sound, int length)
|
SoundDecoder * SoundHandler::GetSoundDecoder(const u8 * sound, int length)
|
||||||
{
|
{
|
||||||
const u8 * check = sound;
|
const u8 * check = sound;
|
||||||
int counter = 0;
|
int counter = 0;
|
||||||
|
|
||||||
while(check[0] == 0 && counter < length)
|
while(check[0] == 0 && counter < length)
|
||||||
{
|
{
|
||||||
check++;
|
check++;
|
||||||
counter++;
|
counter++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(counter >= length)
|
if(counter >= length)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
u32 * magic = (u32 *) check;
|
u32 * magic = (u32 *) check;
|
||||||
|
|
||||||
if(magic[0] == 'OggS')
|
if(magic[0] == 'OggS')
|
||||||
{
|
{
|
||||||
return new OggDecoder(sound, length);
|
return new OggDecoder(sound, length);
|
||||||
}
|
}
|
||||||
else if(magic[0] == 'RIFF')
|
else if(magic[0] == 'RIFF')
|
||||||
{
|
{
|
||||||
return new WavDecoder(sound, length);
|
return new WavDecoder(sound, length);
|
||||||
}
|
}
|
||||||
else if(magic[0] == 'BNS ')
|
else if(magic[0] == 'BNS ')
|
||||||
{
|
{
|
||||||
return new BNSDecoder(sound, length);
|
return new BNSDecoder(sound, length);
|
||||||
}
|
}
|
||||||
else if(magic[0] == 'FORM')
|
else if(magic[0] == 'FORM')
|
||||||
{
|
{
|
||||||
return new AifDecoder(sound, length);
|
return new AifDecoder(sound, length);
|
||||||
}
|
}
|
||||||
else if(CheckMP3Signature(check) == true)
|
else if(CheckMP3Signature(check) == true)
|
||||||
{
|
{
|
||||||
return new Mp3Decoder(sound, length);
|
return new Mp3Decoder(sound, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new SoundDecoder(sound, length);
|
return new SoundDecoder(sound, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
void * SoundHandler::UpdateThread(void *arg)
|
void * SoundHandler::UpdateThread(void *arg)
|
||||||
|
@ -243,22 +243,22 @@ void * SoundHandler::UpdateThread(void *arg)
|
||||||
|
|
||||||
void SoundHandler::InternalSoundUpdates()
|
void SoundHandler::InternalSoundUpdates()
|
||||||
{
|
{
|
||||||
u16 i = 0;
|
u16 i = 0;
|
||||||
LWP_InitQueue(&ThreadQueue);
|
LWP_InitQueue(&ThreadQueue);
|
||||||
while (!ExitRequested)
|
while (!ExitRequested)
|
||||||
{
|
{
|
||||||
LWP_ThreadSleep(ThreadQueue);
|
LWP_ThreadSleep(ThreadQueue);
|
||||||
|
|
||||||
for(i = 0; i < MAX_DECODERS; ++i)
|
for(i = 0; i < MAX_DECODERS; ++i)
|
||||||
{
|
{
|
||||||
if(DecoderList[i] == NULL)
|
if(DecoderList[i] == NULL)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
Decoding = true;
|
Decoding = true;
|
||||||
DecoderList[i]->Decode();
|
DecoderList[i]->Decode();
|
||||||
}
|
}
|
||||||
Decoding = false;
|
Decoding = false;
|
||||||
}
|
}
|
||||||
LWP_CloseQueue(ThreadQueue);
|
LWP_CloseQueue(ThreadQueue);
|
||||||
ThreadQueue = LWP_TQUEUE_NULL;
|
ThreadQueue = LWP_TQUEUE_NULL;
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,11 +30,11 @@
|
||||||
#include <gccore.h>
|
#include <gccore.h>
|
||||||
#include "SoundDecoder.hpp"
|
#include "SoundDecoder.hpp"
|
||||||
|
|
||||||
#define MAX_DECODERS 16
|
#define MAX_DECODERS 16
|
||||||
|
|
||||||
class SoundHandler
|
class SoundHandler
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static SoundHandler * Instance();
|
static SoundHandler * Instance();
|
||||||
static void DestroyInstance();
|
static void DestroyInstance();
|
||||||
|
|
||||||
|
@ -43,8 +43,8 @@ class SoundHandler
|
||||||
void RemoveDecoder(int voice);
|
void RemoveDecoder(int voice);
|
||||||
void DestroyDecoder(SoundDecoder * decoder);
|
void DestroyDecoder(SoundDecoder * decoder);
|
||||||
|
|
||||||
SoundDecoder * Decoder(int i) { return ((i < 0 || i >= MAX_DECODERS) ? NULL : DecoderList[i]); };
|
SoundDecoder * Decoder(int i) { return ((i < 0 || i >= MAX_DECODERS) ? NULL : DecoderList[i]); };
|
||||||
void ThreadSignal() { LWP_ThreadSignal(ThreadQueue); };
|
void ThreadSignal() { LWP_ThreadSignal(ThreadQueue); };
|
||||||
bool IsDecoding() { return Decoding; };
|
bool IsDecoding() { return Decoding; };
|
||||||
protected:
|
protected:
|
||||||
SoundHandler();
|
SoundHandler();
|
||||||
|
@ -52,13 +52,13 @@ class SoundHandler
|
||||||
static void * UpdateThread(void *arg);
|
static void * UpdateThread(void *arg);
|
||||||
void InternalSoundUpdates();
|
void InternalSoundUpdates();
|
||||||
void ClearDecoderList();
|
void ClearDecoderList();
|
||||||
SoundDecoder * GetSoundDecoder(const char * filepath);
|
SoundDecoder * GetSoundDecoder(const char * filepath);
|
||||||
SoundDecoder * GetSoundDecoder(const u8 * sound, int length);
|
SoundDecoder * GetSoundDecoder(const u8 * sound, int length);
|
||||||
|
|
||||||
static SoundHandler * instance;
|
static SoundHandler * instance;
|
||||||
u8 * ThreadStack;
|
u8 * ThreadStack;
|
||||||
lwp_t SoundThread;
|
lwp_t SoundThread;
|
||||||
lwpq_t ThreadQueue;
|
lwpq_t ThreadQueue;
|
||||||
bool Decoding;
|
bool Decoding;
|
||||||
bool ExitRequested;
|
bool ExitRequested;
|
||||||
|
|
||||||
|
|
|
@ -28,29 +28,29 @@
|
||||||
#include "utils/uncompress.h"
|
#include "utils/uncompress.h"
|
||||||
|
|
||||||
WavDecoder::WavDecoder(const char * filepath)
|
WavDecoder::WavDecoder(const char * filepath)
|
||||||
: SoundDecoder(filepath)
|
: SoundDecoder(filepath)
|
||||||
{
|
{
|
||||||
SoundType = SOUND_WAV;
|
SoundType = SOUND_WAV;
|
||||||
SampleRate = 48000;
|
SampleRate = 48000;
|
||||||
Format = VOICE_STEREO_16BIT;
|
Format = VOICE_STEREO_16BIT;
|
||||||
|
|
||||||
if(!file_fd)
|
if(!file_fd)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
OpenFile();
|
OpenFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
WavDecoder::WavDecoder(const u8 * snd, int len)
|
WavDecoder::WavDecoder(const u8 * snd, int len)
|
||||||
: SoundDecoder(snd, len)
|
: SoundDecoder(snd, len)
|
||||||
{
|
{
|
||||||
SoundType = SOUND_WAV;
|
SoundType = SOUND_WAV;
|
||||||
SampleRate = 48000;
|
SampleRate = 48000;
|
||||||
Format = VOICE_STEREO_16BIT;
|
Format = VOICE_STEREO_16BIT;
|
||||||
|
|
||||||
if(!file_fd)
|
if(!file_fd)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
OpenFile();
|
OpenFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
WavDecoder::~WavDecoder()
|
WavDecoder::~WavDecoder()
|
||||||
|
@ -59,13 +59,13 @@ WavDecoder::~WavDecoder()
|
||||||
|
|
||||||
void WavDecoder::OpenFile()
|
void WavDecoder::OpenFile()
|
||||||
{
|
{
|
||||||
SWaveHdr Header;
|
SWaveHdr Header;
|
||||||
SWaveFmtChunk FmtChunk;
|
SWaveFmtChunk FmtChunk;
|
||||||
memset(&Header, 0, sizeof(SWaveHdr));
|
memset(&Header, 0, sizeof(SWaveHdr));
|
||||||
memset(&FmtChunk, 0, sizeof(SWaveFmtChunk));
|
memset(&FmtChunk, 0, sizeof(SWaveFmtChunk));
|
||||||
|
|
||||||
file_fd->read((u8 *) &Header, sizeof(SWaveHdr));
|
file_fd->read((u8 *) &Header, sizeof(SWaveHdr));
|
||||||
file_fd->read((u8 *) &FmtChunk, sizeof(SWaveFmtChunk));
|
file_fd->read((u8 *) &FmtChunk, sizeof(SWaveFmtChunk));
|
||||||
|
|
||||||
if (Header.magicRIFF != 'RIFF')
|
if (Header.magicRIFF != 'RIFF')
|
||||||
{
|
{
|
||||||
|
@ -83,27 +83,27 @@ void WavDecoder::OpenFile()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
DataOffset = sizeof(SWaveHdr)+le32(FmtChunk.size)+8;
|
DataOffset = sizeof(SWaveHdr)+le32(FmtChunk.size)+8;
|
||||||
file_fd->seek(DataOffset, SEEK_SET);
|
file_fd->seek(DataOffset, SEEK_SET);
|
||||||
SWaveChunk DataChunk;
|
SWaveChunk DataChunk;
|
||||||
file_fd->read((u8 *) &DataChunk, sizeof(SWaveChunk));
|
file_fd->read((u8 *) &DataChunk, sizeof(SWaveChunk));
|
||||||
|
|
||||||
if(DataChunk.magicDATA == 'fact')
|
if(DataChunk.magicDATA == 'fact')
|
||||||
{
|
{
|
||||||
DataOffset += 8+le32(DataChunk.size);
|
DataOffset += 8+le32(DataChunk.size);
|
||||||
file_fd->seek(DataOffset, SEEK_SET);
|
file_fd->seek(DataOffset, SEEK_SET);
|
||||||
file_fd->read((u8 *) &DataChunk, sizeof(SWaveChunk));
|
file_fd->read((u8 *) &DataChunk, sizeof(SWaveChunk));
|
||||||
}
|
}
|
||||||
if(DataChunk.magicDATA != 'data')
|
if(DataChunk.magicDATA != 'data')
|
||||||
{
|
{
|
||||||
CloseFile();
|
CloseFile();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
DataOffset += 8;
|
DataOffset += 8;
|
||||||
DataSize = le32(DataChunk.size);
|
DataSize = le32(DataChunk.size);
|
||||||
Is16Bit = (le16(FmtChunk.bps) == 16);
|
Is16Bit = (le16(FmtChunk.bps) == 16);
|
||||||
SampleRate = le32(FmtChunk.freq);
|
SampleRate = le32(FmtChunk.freq);
|
||||||
|
|
||||||
if (le16(FmtChunk.channels) == 1 && le16(FmtChunk.bps) == 8 && le16(FmtChunk.alignment) <= 1)
|
if (le16(FmtChunk.channels) == 1 && le16(FmtChunk.bps) == 8 && le16(FmtChunk.alignment) <= 1)
|
||||||
Format = VOICE_MONO_8BIT;
|
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)
|
else if (le16(FmtChunk.channels) == 2 && le16(FmtChunk.bps) == 16 && le16(FmtChunk.alignment) <= 4)
|
||||||
Format = VOICE_STEREO_16BIT;
|
Format = VOICE_STEREO_16BIT;
|
||||||
|
|
||||||
Decode();
|
Decode();
|
||||||
}
|
}
|
||||||
|
|
||||||
void WavDecoder::CloseFile()
|
void WavDecoder::CloseFile()
|
||||||
{
|
{
|
||||||
if(file_fd)
|
if(file_fd)
|
||||||
delete file_fd;
|
delete file_fd;
|
||||||
|
|
||||||
file_fd = NULL;
|
file_fd = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
int WavDecoder::Read(u8 * buffer, int buffer_size, int pos)
|
int WavDecoder::Read(u8 * buffer, int buffer_size, int pos)
|
||||||
{
|
{
|
||||||
if(!file_fd)
|
if(!file_fd)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if(CurPos >= (int) DataSize)
|
if(CurPos >= (int) DataSize)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
file_fd->seek(DataOffset+CurPos, SEEK_SET);
|
file_fd->seek(DataOffset+CurPos, SEEK_SET);
|
||||||
|
|
||||||
if(buffer_size > (int) DataSize-CurPos)
|
if(buffer_size > (int) DataSize-CurPos)
|
||||||
buffer_size = DataSize-CurPos;
|
buffer_size = DataSize-CurPos;
|
||||||
|
|
||||||
int read = file_fd->read(buffer, buffer_size);
|
int read = file_fd->read(buffer, buffer_size);
|
||||||
if(read > 0)
|
if(read > 0)
|
||||||
{
|
{
|
||||||
if (Is16Bit)
|
if (Is16Bit)
|
||||||
{
|
{
|
||||||
read &= ~0x0001;
|
read &= ~0x0001;
|
||||||
|
|
||||||
for (u32 i = 0; i < (u32) (read / sizeof (u16)); ++i)
|
for (u32 i = 0; i < (u32) (read / sizeof (u16)); ++i)
|
||||||
((u16 *) buffer)[i] = le16(((u16 *) buffer)[i]);
|
((u16 *) buffer)[i] = le16(((u16 *) buffer)[i]);
|
||||||
}
|
}
|
||||||
CurPos += read;
|
CurPos += read;
|
||||||
}
|
}
|
||||||
|
|
||||||
return read;
|
return read;
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,21 +55,21 @@ typedef struct
|
||||||
|
|
||||||
class WavDecoder : public SoundDecoder
|
class WavDecoder : public SoundDecoder
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
WavDecoder(const char * filepath);
|
WavDecoder(const char * filepath);
|
||||||
WavDecoder(const u8 * snd, int len);
|
WavDecoder(const u8 * snd, int len);
|
||||||
virtual ~WavDecoder();
|
virtual ~WavDecoder();
|
||||||
int GetFormat() { return Format; };
|
int GetFormat() { return Format; };
|
||||||
int GetSampleRate() { return SampleRate; };
|
int GetSampleRate() { return SampleRate; };
|
||||||
int Read(u8 * buffer, int buffer_size, int pos);
|
int Read(u8 * buffer, int buffer_size, int pos);
|
||||||
protected:
|
protected:
|
||||||
void OpenFile();
|
void OpenFile();
|
||||||
void CloseFile();
|
void CloseFile();
|
||||||
u32 DataOffset;
|
u32 DataOffset;
|
||||||
u32 DataSize;
|
u32 DataSize;
|
||||||
u32 SampleRate;
|
u32 SampleRate;
|
||||||
u8 Format;
|
u8 Format;
|
||||||
bool Is16Bit;
|
bool Is16Bit;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -10,209 +10,209 @@
|
||||||
#include "menu.h"
|
#include "menu.h"
|
||||||
|
|
||||||
GuiBGM::GuiBGM(const u8 *s, int l, int v) :
|
GuiBGM::GuiBGM(const u8 *s, int l, int v) :
|
||||||
GuiSound(s, l, v, false, 0)
|
GuiSound(s, l, v, false, 0)
|
||||||
{
|
{
|
||||||
currentPath = NULL;
|
currentPath = NULL;
|
||||||
currentPlaying = 0;
|
currentPlaying = 0;
|
||||||
voice = 0;
|
voice = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
GuiBGM::~GuiBGM()
|
GuiBGM::~GuiBGM()
|
||||||
{
|
{
|
||||||
if (currentPath) delete[] currentPath;
|
if (currentPath) delete[] currentPath;
|
||||||
|
|
||||||
ClearList();
|
ClearList();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GuiBGM::Load(const char *path)
|
bool GuiBGM::Load(const char *path)
|
||||||
{
|
{
|
||||||
if (!path)
|
if (!path)
|
||||||
{
|
{
|
||||||
LoadStandard();
|
LoadStandard();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (strcmp(path, "") == 0)
|
if (strcmp(path, "") == 0)
|
||||||
{
|
{
|
||||||
LoadStandard();
|
LoadStandard();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!GuiSound::Load(path))
|
if (!GuiSound::Load(path))
|
||||||
{
|
{
|
||||||
LoadStandard();
|
LoadStandard();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return ParsePath(path);
|
return ParsePath(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GuiBGM::LoadStandard()
|
bool GuiBGM::LoadStandard()
|
||||||
{
|
{
|
||||||
ClearList();
|
ClearList();
|
||||||
if (currentPath)
|
if (currentPath)
|
||||||
{
|
{
|
||||||
delete[] currentPath;
|
delete[] currentPath;
|
||||||
currentPath = NULL;
|
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)
|
bool GuiBGM::ParsePath(const char * folderpath)
|
||||||
{
|
{
|
||||||
ClearList();
|
ClearList();
|
||||||
|
|
||||||
if (currentPath) delete[] currentPath;
|
if (currentPath) delete[] currentPath;
|
||||||
|
|
||||||
currentPath = new char[strlen(folderpath) + 1];
|
currentPath = new char[strlen(folderpath) + 1];
|
||||||
sprintf(currentPath, "%s", folderpath);
|
sprintf(currentPath, "%s", folderpath);
|
||||||
|
|
||||||
char * isdirpath = strrchr(folderpath, '.');
|
char * isdirpath = strrchr(folderpath, '.');
|
||||||
if (isdirpath)
|
if (isdirpath)
|
||||||
{
|
{
|
||||||
char * pathptr = strrchr(currentPath, '/');
|
char * pathptr = strrchr(currentPath, '/');
|
||||||
if (pathptr)
|
if (pathptr)
|
||||||
{
|
{
|
||||||
pathptr++;
|
pathptr++;
|
||||||
pathptr[0] = 0;
|
pathptr[0] = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
char * LoadedFilename = strrchr(folderpath, '/') + 1;
|
char * LoadedFilename = strrchr(folderpath, '/') + 1;
|
||||||
|
|
||||||
char filename[1024];
|
char filename[1024];
|
||||||
struct dirent * dirent = NULL;
|
struct dirent * dirent = NULL;
|
||||||
|
|
||||||
DIR * dir = opendir(currentPath);
|
DIR * dir = opendir(currentPath);
|
||||||
if (dir == NULL)
|
if (dir == NULL)
|
||||||
{
|
{
|
||||||
LoadStandard();
|
LoadStandard();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
u32 counter = 0;
|
u32 counter = 0;
|
||||||
|
|
||||||
while ((dirent = readdir(dir)) != 0)
|
while ((dirent = readdir(dir)) != 0)
|
||||||
{
|
{
|
||||||
snprintf(filename, sizeof(filename), dirent->d_name);
|
snprintf(filename, sizeof(filename), dirent->d_name);
|
||||||
|
|
||||||
char * fileext = strrchr(filename, '.');
|
char * fileext = strrchr(filename, '.');
|
||||||
if (!fileext)
|
if (!fileext)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (strcasecmp(fileext, ".mp3") == 0 || strcasecmp(fileext, ".ogg") == 0 ||
|
if (strcasecmp(fileext, ".mp3") == 0 || strcasecmp(fileext, ".ogg") == 0 ||
|
||||||
strcasecmp(fileext, ".wav") == 0 || strcasecmp(fileext, ".aif") == 0)
|
strcasecmp(fileext, ".wav") == 0 || strcasecmp(fileext, ".aif") == 0)
|
||||||
{
|
{
|
||||||
AddEntrie(filename);
|
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)
|
void GuiBGM::AddEntrie(const char * filename)
|
||||||
{
|
{
|
||||||
if (!filename) return;
|
if (!filename) return;
|
||||||
|
|
||||||
char * NewEntrie = new char[strlen(filename) + 1];
|
char * NewEntrie = new char[strlen(filename) + 1];
|
||||||
sprintf(NewEntrie, "%s", filename);
|
sprintf(NewEntrie, "%s", filename);
|
||||||
|
|
||||||
PlayList.push_back(NewEntrie);
|
PlayList.push_back(NewEntrie);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuiBGM::ClearList()
|
void GuiBGM::ClearList()
|
||||||
{
|
{
|
||||||
for (u32 i = 0; i < PlayList.size(); i++)
|
for (u32 i = 0; i < PlayList.size(); i++)
|
||||||
{
|
{
|
||||||
if (PlayList.at(i) != NULL)
|
if (PlayList.at(i) != NULL)
|
||||||
{
|
{
|
||||||
delete[] PlayList.at(i);
|
delete[] PlayList.at(i);
|
||||||
PlayList.at(i) = NULL;
|
PlayList.at(i) = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
PlayList.clear();
|
PlayList.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GuiBGM::PlayNext()
|
bool GuiBGM::PlayNext()
|
||||||
{
|
{
|
||||||
if (!currentPath) return false;
|
if (!currentPath) return false;
|
||||||
|
|
||||||
currentPlaying++;
|
currentPlaying++;
|
||||||
if (currentPlaying >= (int) PlayList.size()) currentPlaying = 0;
|
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()
|
bool GuiBGM::PlayPrevious()
|
||||||
{
|
{
|
||||||
if (!currentPath) return false;
|
if (!currentPath) return false;
|
||||||
|
|
||||||
currentPlaying--;
|
currentPlaying--;
|
||||||
if (currentPlaying < 0) currentPlaying = PlayList.size() - 1;
|
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()
|
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
|
//just in case
|
||||||
if (currentPlaying < 0)
|
if (currentPlaying < 0)
|
||||||
currentPlaying = PlayList.size() - 1;
|
currentPlaying = PlayList.size() - 1;
|
||||||
else if (currentPlaying >= (int) PlayList.size()) currentPlaying = 0;
|
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()
|
void GuiBGM::UpdateState()
|
||||||
{
|
{
|
||||||
if (!IsPlaying())
|
if (!IsPlaying())
|
||||||
{
|
{
|
||||||
if (loop == DIR_LOOP)
|
if (loop == DIR_LOOP)
|
||||||
{
|
{
|
||||||
PlayNext();
|
PlayNext();
|
||||||
}
|
}
|
||||||
else if (loop == RANDOM_BGM)
|
else if (loop == RANDOM_BGM)
|
||||||
{
|
{
|
||||||
PlayRandom();
|
PlayRandom();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,28 +13,28 @@
|
||||||
|
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
ONCE = 0, LOOP, RANDOM_BGM, DIR_LOOP
|
ONCE = 0, LOOP, RANDOM_BGM, DIR_LOOP
|
||||||
};
|
};
|
||||||
|
|
||||||
class GuiBGM: public GuiSound
|
class GuiBGM: public GuiSound
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
GuiBGM(const u8 *s, int l, int v);
|
GuiBGM(const u8 *s, int l, int v);
|
||||||
virtual ~GuiBGM();
|
virtual ~GuiBGM();
|
||||||
bool Load(const char *path);
|
bool Load(const char *path);
|
||||||
bool LoadStandard();
|
bool LoadStandard();
|
||||||
bool ParsePath(const char * folderpath);
|
bool ParsePath(const char * folderpath);
|
||||||
bool PlayNext();
|
bool PlayNext();
|
||||||
bool PlayPrevious();
|
bool PlayPrevious();
|
||||||
bool PlayRandom();
|
bool PlayRandom();
|
||||||
void UpdateState();
|
void UpdateState();
|
||||||
protected:
|
protected:
|
||||||
void AddEntrie(const char * filename);
|
void AddEntrie(const char * filename);
|
||||||
void ClearList();
|
void ClearList();
|
||||||
|
|
||||||
int currentPlaying;
|
int currentPlaying;
|
||||||
char * currentPath;
|
char * currentPath;
|
||||||
std::vector<char *> PlayList;
|
std::vector<char *> PlayList;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -30,61 +30,61 @@
|
||||||
#include "SoundHandler.hpp"
|
#include "SoundHandler.hpp"
|
||||||
#include "WavDecoder.hpp"
|
#include "WavDecoder.hpp"
|
||||||
|
|
||||||
#define MAX_SND_VOICES 16
|
#define MAX_SND_VOICES 16
|
||||||
|
|
||||||
static bool VoiceUsed[MAX_SND_VOICES] =
|
static bool VoiceUsed[MAX_SND_VOICES] =
|
||||||
{
|
{
|
||||||
true, false, false, false, false, false,
|
true, false, false, false, false, false,
|
||||||
false, false, false, false, false, false,
|
false, false, false, false, false, false,
|
||||||
false, false, false, false
|
false, false, false, false
|
||||||
};
|
};
|
||||||
|
|
||||||
static inline int GetFirstUnusedVoice()
|
static inline int GetFirstUnusedVoice()
|
||||||
{
|
{
|
||||||
for(int i = 1; i < MAX_SND_VOICES; i++)
|
for(int i = 1; i < MAX_SND_VOICES; i++)
|
||||||
{
|
{
|
||||||
if(VoiceUsed[i] == false)
|
if(VoiceUsed[i] == false)
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" void SoundCallback(s32 voice)
|
extern "C" void SoundCallback(s32 voice)
|
||||||
{
|
{
|
||||||
SoundDecoder * decoder = SoundHandler::Instance()->Decoder(voice);
|
SoundDecoder * decoder = SoundHandler::Instance()->Decoder(voice);
|
||||||
if(!decoder)
|
if(!decoder)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if(decoder->IsBufferReady())
|
if(decoder->IsBufferReady())
|
||||||
{
|
{
|
||||||
if(ASND_AddVoice(voice, decoder->GetBuffer(), decoder->GetBufferSize()) == SND_OK)
|
if(ASND_AddVoice(voice, decoder->GetBuffer(), decoder->GetBufferSize()) == SND_OK)
|
||||||
{
|
{
|
||||||
decoder->LoadNext();
|
decoder->LoadNext();
|
||||||
SoundHandler::Instance()->ThreadSignal();
|
SoundHandler::Instance()->ThreadSignal();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(decoder->IsEOF())
|
else if(decoder->IsEOF())
|
||||||
{
|
{
|
||||||
ASND_StopVoice(voice);
|
ASND_StopVoice(voice);
|
||||||
//if(voice == 0)
|
//if(voice == 0)
|
||||||
//MusicPlayer::Instance()->SetPlaybackFinished(true); //see if next music must be played
|
//MusicPlayer::Instance()->SetPlaybackFinished(true); //see if next music must be played
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
SoundHandler::Instance()->ThreadSignal();
|
SoundHandler::Instance()->ThreadSignal();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
GuiSound::GuiSound(const char * filepath)
|
GuiSound::GuiSound(const char * filepath)
|
||||||
{
|
{
|
||||||
sound = NULL;
|
sound = NULL;
|
||||||
length = 0;
|
length = 0;
|
||||||
voice = GetFirstUnusedVoice();
|
voice = GetFirstUnusedVoice();
|
||||||
if(voice > 0)
|
if(voice > 0)
|
||||||
VoiceUsed[voice] = true;
|
VoiceUsed[voice] = true;
|
||||||
|
|
||||||
volume = 255;
|
volume = 255;
|
||||||
SoundEffectLength = 0;
|
SoundEffectLength = 0;
|
||||||
loop = 0;
|
loop = 0;
|
||||||
allocated = false;
|
allocated = false;
|
||||||
|
@ -93,17 +93,17 @@ GuiSound::GuiSound(const char * filepath)
|
||||||
|
|
||||||
GuiSound::GuiSound(const u8 * snd, s32 len, int vol, bool isallocated, int v)
|
GuiSound::GuiSound(const u8 * snd, s32 len, int vol, bool isallocated, int v)
|
||||||
{
|
{
|
||||||
sound = NULL;
|
sound = NULL;
|
||||||
length = 0;
|
length = 0;
|
||||||
if(v < 0)
|
if(v < 0)
|
||||||
voice = GetFirstUnusedVoice();
|
voice = GetFirstUnusedVoice();
|
||||||
else
|
else
|
||||||
voice = v;
|
voice = v;
|
||||||
|
|
||||||
if(voice > 0)
|
if(voice > 0)
|
||||||
VoiceUsed[voice] = true;
|
VoiceUsed[voice] = true;
|
||||||
|
|
||||||
volume = vol;
|
volume = vol;
|
||||||
SoundEffectLength = 0;
|
SoundEffectLength = 0;
|
||||||
loop = 0;
|
loop = 0;
|
||||||
allocated = false;
|
allocated = false;
|
||||||
|
@ -114,173 +114,173 @@ GuiSound::~GuiSound()
|
||||||
{
|
{
|
||||||
FreeMemory();
|
FreeMemory();
|
||||||
if(voice > 0)
|
if(voice > 0)
|
||||||
VoiceUsed[voice] = false;
|
VoiceUsed[voice] = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuiSound::FreeMemory()
|
void GuiSound::FreeMemory()
|
||||||
{
|
{
|
||||||
this->Stop();
|
this->Stop();
|
||||||
|
|
||||||
SoundHandler::Instance()->RemoveDecoder(voice);
|
SoundHandler::Instance()->RemoveDecoder(voice);
|
||||||
|
|
||||||
if(allocated && sound != NULL)
|
if(allocated && sound != NULL)
|
||||||
{
|
{
|
||||||
free(sound);
|
free(sound);
|
||||||
sound = NULL;
|
sound = NULL;
|
||||||
allocated = false;
|
allocated = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
SoundEffectLength = 0;
|
SoundEffectLength = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GuiSound::Load(const char * filepath)
|
bool GuiSound::Load(const char * filepath)
|
||||||
{
|
{
|
||||||
FreeMemory();
|
FreeMemory();
|
||||||
|
|
||||||
if(!filepath)
|
if(!filepath)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
u32 magic;
|
u32 magic;
|
||||||
FILE * f = fopen(filepath, "rb");
|
FILE * f = fopen(filepath, "rb");
|
||||||
if(!f)
|
if(!f)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
fread(&magic, 1, 4, f);
|
fread(&magic, 1, 4, f);
|
||||||
fclose(f);
|
fclose(f);
|
||||||
|
|
||||||
if(magic == 'IMD5')
|
if(magic == 'IMD5')
|
||||||
{
|
{
|
||||||
u8 * snd = NULL;
|
u8 * snd = NULL;
|
||||||
u64 filesize = 0;
|
u64 filesize = 0;
|
||||||
LoadFileToMem(filepath, &snd, &filesize);
|
LoadFileToMem(filepath, &snd, &filesize);
|
||||||
return Load(snd, filesize, true);
|
return Load(snd, filesize, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
SoundHandler::Instance()->AddDecoder(voice, filepath);
|
SoundHandler::Instance()->AddDecoder(voice, filepath);
|
||||||
|
|
||||||
SoundDecoder * decoder = SoundHandler::Instance()->Decoder(voice);
|
SoundDecoder * decoder = SoundHandler::Instance()->Decoder(voice);
|
||||||
if(!decoder)
|
if(!decoder)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if(!decoder->IsBufferReady())
|
if(!decoder->IsBufferReady())
|
||||||
{
|
{
|
||||||
SoundHandler::Instance()->RemoveDecoder(voice);
|
SoundHandler::Instance()->RemoveDecoder(voice);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
SetLoop(loop);
|
SetLoop(loop);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GuiSound::Load(const u8 * snd, s32 len, bool isallocated)
|
bool GuiSound::Load(const u8 * snd, s32 len, bool isallocated)
|
||||||
{
|
{
|
||||||
FreeMemory();
|
FreeMemory();
|
||||||
|
|
||||||
if(!snd)
|
if(!snd)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if(!isallocated && *((u32 *) snd) == 'RIFF')
|
if(!isallocated && *((u32 *) snd) == 'RIFF')
|
||||||
{
|
{
|
||||||
return LoadSoundEffect(snd, len);
|
return LoadSoundEffect(snd, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(*((u32 *) snd) == 'IMD5')
|
if(*((u32 *) snd) == 'IMD5')
|
||||||
{
|
{
|
||||||
UncompressSoundbin(snd, len, isallocated);
|
UncompressSoundbin(snd, len, isallocated);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
sound = (u8 *) snd;
|
sound = (u8 *) snd;
|
||||||
length = len;
|
length = len;
|
||||||
allocated = isallocated;
|
allocated = isallocated;
|
||||||
}
|
}
|
||||||
|
|
||||||
SoundHandler::Instance()->AddDecoder(voice, sound, length);
|
SoundHandler::Instance()->AddDecoder(voice, sound, length);
|
||||||
|
|
||||||
SoundDecoder * decoder = SoundHandler::Instance()->Decoder(voice);
|
SoundDecoder * decoder = SoundHandler::Instance()->Decoder(voice);
|
||||||
if(!decoder)
|
if(!decoder)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if(!decoder->IsBufferReady())
|
if(!decoder->IsBufferReady())
|
||||||
{
|
{
|
||||||
SoundHandler::Instance()->RemoveDecoder(voice);
|
SoundHandler::Instance()->RemoveDecoder(voice);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
SetLoop(loop);
|
SetLoop(loop);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GuiSound::LoadSoundEffect(const u8 * snd, s32 len)
|
bool GuiSound::LoadSoundEffect(const u8 * snd, s32 len)
|
||||||
{
|
{
|
||||||
WavDecoder decoder(snd, len);
|
WavDecoder decoder(snd, len);
|
||||||
decoder.Rewind();
|
decoder.Rewind();
|
||||||
|
|
||||||
u32 done = 0;
|
u32 done = 0;
|
||||||
sound = (u8 *) malloc(4096);
|
sound = (u8 *) malloc(4096);
|
||||||
memset(sound, 0, 4096);
|
memset(sound, 0, 4096);
|
||||||
|
|
||||||
while(1)
|
while(1)
|
||||||
{
|
{
|
||||||
u8 * tmpsnd = (u8 *) realloc(sound, done+4096);
|
u8 * tmpsnd = (u8 *) realloc(sound, done+4096);
|
||||||
if(!tmpsnd)
|
if(!tmpsnd)
|
||||||
{
|
{
|
||||||
free(sound);
|
free(sound);
|
||||||
sound = NULL;
|
sound = NULL;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
sound = tmpsnd;
|
sound = tmpsnd;
|
||||||
|
|
||||||
int read = decoder.Read(sound+done, 4096, done);
|
int read = decoder.Read(sound+done, 4096, done);
|
||||||
if(read <= 0)
|
if(read <= 0)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
done += read;
|
done += read;
|
||||||
}
|
}
|
||||||
|
|
||||||
sound = (u8 *) realloc(sound, done);
|
sound = (u8 *) realloc(sound, done);
|
||||||
SoundEffectLength = done;
|
SoundEffectLength = done;
|
||||||
allocated = true;
|
allocated = true;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuiSound::Play()
|
void GuiSound::Play()
|
||||||
{
|
{
|
||||||
if(SoundEffectLength > 0)
|
if(SoundEffectLength > 0)
|
||||||
{
|
{
|
||||||
ASND_StopVoice(voice);
|
ASND_StopVoice(voice);
|
||||||
ASND_SetVoice(voice, VOICE_STEREO_16BIT, 32000, 0, sound, SoundEffectLength, volume, volume, NULL);
|
ASND_SetVoice(voice, VOICE_STEREO_16BIT, 32000, 0, sound, SoundEffectLength, volume, volume, NULL);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(IsPlaying())
|
if(IsPlaying())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if(voice < 0 || voice >= 16)
|
if(voice < 0 || voice >= 16)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
SoundDecoder * decoder = SoundHandler::Instance()->Decoder(voice);
|
SoundDecoder * decoder = SoundHandler::Instance()->Decoder(voice);
|
||||||
if(!decoder)
|
if(!decoder)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if(decoder->IsEOF())
|
if(decoder->IsEOF())
|
||||||
{
|
{
|
||||||
ASND_StopVoice(voice);
|
ASND_StopVoice(voice);
|
||||||
decoder->ClearBuffer();
|
decoder->ClearBuffer();
|
||||||
decoder->Rewind();
|
decoder->Rewind();
|
||||||
decoder->Decode();
|
decoder->Decode();
|
||||||
}
|
}
|
||||||
|
|
||||||
u8 * curbuffer = decoder->GetBuffer();
|
u8 * curbuffer = decoder->GetBuffer();
|
||||||
int bufsize = decoder->GetBufferSize();
|
int bufsize = decoder->GetBufferSize();
|
||||||
decoder->LoadNext();
|
decoder->LoadNext();
|
||||||
SoundHandler::Instance()->ThreadSignal();
|
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()
|
void GuiSound::Stop()
|
||||||
|
@ -290,13 +290,13 @@ void GuiSound::Stop()
|
||||||
|
|
||||||
ASND_StopVoice(voice);
|
ASND_StopVoice(voice);
|
||||||
|
|
||||||
SoundDecoder * decoder = SoundHandler::Instance()->Decoder(voice);
|
SoundDecoder * decoder = SoundHandler::Instance()->Decoder(voice);
|
||||||
if(!decoder)
|
if(!decoder)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
decoder->ClearBuffer();
|
decoder->ClearBuffer();
|
||||||
Rewind();
|
Rewind();
|
||||||
SoundHandler::Instance()->ThreadSignal();
|
SoundHandler::Instance()->ThreadSignal();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuiSound::Pause()
|
void GuiSound::Pause()
|
||||||
|
@ -304,12 +304,12 @@ void GuiSound::Pause()
|
||||||
if(voice < 0 || voice >= 16)
|
if(voice < 0 || voice >= 16)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
ASND_StopVoice(voice);
|
ASND_StopVoice(voice);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuiSound::Resume()
|
void GuiSound::Resume()
|
||||||
{
|
{
|
||||||
Play();
|
Play();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GuiSound::IsPlaying()
|
bool GuiSound::IsPlaying()
|
||||||
|
@ -317,7 +317,7 @@ bool GuiSound::IsPlaying()
|
||||||
if(voice < 0 || voice >= 16)
|
if(voice < 0 || voice >= 16)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
int result = ASND_StatusVoice(voice);
|
int result = ASND_StatusVoice(voice);
|
||||||
|
|
||||||
if(result == SND_WORKING || result == SND_WAITING)
|
if(result == SND_WORKING || result == SND_WAITING)
|
||||||
return true;
|
return true;
|
||||||
|
@ -333,48 +333,48 @@ void GuiSound::SetVolume(int vol)
|
||||||
if(vol < 0)
|
if(vol < 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
volume = 255*(vol/100.0);
|
volume = 255*(vol/100.0);
|
||||||
ASND_ChangeVolumeVoice(voice, volume, volume);
|
ASND_ChangeVolumeVoice(voice, volume, volume);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuiSound::SetLoop(u8 l)
|
void GuiSound::SetLoop(u8 l)
|
||||||
{
|
{
|
||||||
loop = l;
|
loop = l;
|
||||||
|
|
||||||
SoundDecoder * decoder = SoundHandler::Instance()->Decoder(voice);
|
SoundDecoder * decoder = SoundHandler::Instance()->Decoder(voice);
|
||||||
if(!decoder)
|
if(!decoder)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
decoder->SetLoop(l == 1);
|
decoder->SetLoop(l == 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuiSound::Rewind()
|
void GuiSound::Rewind()
|
||||||
{
|
{
|
||||||
SoundDecoder * decoder = SoundHandler::Instance()->Decoder(voice);
|
SoundDecoder * decoder = SoundHandler::Instance()->Decoder(voice);
|
||||||
if(!decoder)
|
if(!decoder)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
decoder->Rewind();
|
decoder->Rewind();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuiSound::UncompressSoundbin(const u8 * snd, int len, bool isallocated)
|
void GuiSound::UncompressSoundbin(const u8 * snd, int len, bool isallocated)
|
||||||
{
|
{
|
||||||
const u8 * file = snd+32;
|
const u8 * file = snd+32;
|
||||||
if(*((u32 *) file) == 'LZ77')
|
if(*((u32 *) file) == 'LZ77')
|
||||||
{
|
{
|
||||||
u32 size = 0;
|
u32 size = 0;
|
||||||
sound = uncompressLZ77(file, len-32, &size);
|
sound = uncompressLZ77(file, len-32, &size);
|
||||||
length = size;
|
length = size;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
length = len-32;
|
length = len-32;
|
||||||
sound = (u8 *) malloc(length);
|
sound = (u8 *) malloc(length);
|
||||||
memcpy(sound, file, length);
|
memcpy(sound, file, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(isallocated)
|
if(isallocated)
|
||||||
free((u8 *) snd);
|
free((u8 *) snd);
|
||||||
|
|
||||||
allocated = true;
|
allocated = true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,7 +35,7 @@ class GuiSound
|
||||||
//!Constructor
|
//!Constructor
|
||||||
//!\param sound Pointer to the sound data
|
//!\param sound Pointer to the sound data
|
||||||
//!\param filesize Length of 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);
|
GuiSound(const u8 * sound, int filesize, int volume, bool allocated = false, int voice = -1);
|
||||||
//!Destructor
|
//!Destructor
|
||||||
virtual ~GuiSound();
|
virtual ~GuiSound();
|
||||||
|
@ -64,10 +64,10 @@ class GuiSound
|
||||||
//!\param l Loop (true to loop)
|
//!\param l Loop (true to loop)
|
||||||
virtual void SetLoop(u8 l);
|
virtual void SetLoop(u8 l);
|
||||||
//!Special sound case for sound.bin
|
//!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:
|
protected:
|
||||||
//!Stops sound and frees all memory/closes files
|
//!Stops sound and frees all memory/closes files
|
||||||
void FreeMemory();
|
void FreeMemory();
|
||||||
u8 * sound; //!< Pointer to the sound data
|
u8 * sound; //!< Pointer to the sound data
|
||||||
int length; //!< Length of sound data
|
int length; //!< Length of sound data
|
||||||
s32 voice; //!< Currently assigned ASND voice channel
|
s32 voice; //!< Currently assigned ASND voice channel
|
||||||
|
|
|
@ -23,84 +23,84 @@
|
||||||
|
|
||||||
StartUpProcess::StartUpProcess()
|
StartUpProcess::StartUpProcess()
|
||||||
{
|
{
|
||||||
//! Load default font for the next text outputs
|
//! Load default font for the next text outputs
|
||||||
Theme::LoadFont("");
|
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");
|
GXImageData = Resources::GetImageData("gxlogo.png");
|
||||||
GXImage = new GuiImage(GXImageData);
|
GXImage = new GuiImage(GXImageData);
|
||||||
GXImage->SetAlignment(ALIGN_CENTER, ALIGN_MIDDLE);
|
GXImage->SetAlignment(ALIGN_CENTER, ALIGN_MIDDLE);
|
||||||
GXImage->SetPosition(screenwidth/2, screenheight/2-50);
|
GXImage->SetPosition(screenwidth/2, screenheight/2-50);
|
||||||
|
|
||||||
titleTxt = new GuiText("Loading...", 24, (GXColor) {255, 255, 255, 255});
|
titleTxt = new GuiText("Loading...", 24, (GXColor) {255, 255, 255, 255});
|
||||||
titleTxt->SetAlignment(ALIGN_CENTER, ALIGN_MIDDLE);
|
titleTxt->SetAlignment(ALIGN_CENTER, ALIGN_MIDDLE);
|
||||||
titleTxt->SetPosition(screenwidth/2, screenheight/2+30);
|
titleTxt->SetPosition(screenwidth/2, screenheight/2+30);
|
||||||
|
|
||||||
messageTxt = new GuiText(" ", 22, (GXColor) {255, 255, 255, 255});
|
messageTxt = new GuiText(" ", 22, (GXColor) {255, 255, 255, 255});
|
||||||
messageTxt->SetAlignment(ALIGN_CENTER, ALIGN_MIDDLE);
|
messageTxt->SetAlignment(ALIGN_CENTER, ALIGN_MIDDLE);
|
||||||
messageTxt->SetPosition(screenwidth/2, screenheight/2+60);
|
messageTxt->SetPosition(screenwidth/2, screenheight/2+60);
|
||||||
}
|
}
|
||||||
|
|
||||||
StartUpProcess::~StartUpProcess()
|
StartUpProcess::~StartUpProcess()
|
||||||
{
|
{
|
||||||
delete background;
|
delete background;
|
||||||
delete GXImageData;
|
delete GXImageData;
|
||||||
delete GXImage;
|
delete GXImage;
|
||||||
delete titleTxt;
|
delete titleTxt;
|
||||||
delete messageTxt;
|
delete messageTxt;
|
||||||
}
|
}
|
||||||
|
|
||||||
int StartUpProcess::ParseArguments(int argc, char *argv[])
|
int StartUpProcess::ParseArguments(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
int quickBoot = -1;
|
int quickBoot = -1;
|
||||||
|
|
||||||
//! The arguments override
|
//! The arguments override
|
||||||
for(int i = 0; i < argc; ++i)
|
for(int i = 0; i < argc; ++i)
|
||||||
{
|
{
|
||||||
if(!argv[i]) continue;
|
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=");
|
char *ptr = strcasestr(argv[i], "-ios=");
|
||||||
if(ptr)
|
if(ptr)
|
||||||
Settings.cios = LIMIT(atoi(ptr+strlen("-ios=")), 200, 255);
|
Settings.cios = LIMIT(atoi(ptr+strlen("-ios=")), 200, 255);
|
||||||
|
|
||||||
ptr = strcasestr(argv[i], "-usbport=");
|
ptr = strcasestr(argv[i], "-usbport=");
|
||||||
if(ptr)
|
if(ptr)
|
||||||
{
|
{
|
||||||
Settings.USBPort = LIMIT(atoi(ptr+strlen("-usbport=")), 0, 2);
|
Settings.USBPort = LIMIT(atoi(ptr+strlen("-usbport=")), 0, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(strlen(argv[i]) == 6 && strchr(argv[i], '=') == 0 && strchr(argv[i], '-') == 0)
|
if(strlen(argv[i]) == 6 && strchr(argv[i], '=') == 0 && strchr(argv[i], '-') == 0)
|
||||||
quickBoot = i;
|
quickBoot = i;
|
||||||
}
|
}
|
||||||
|
|
||||||
return quickBoot;
|
return quickBoot;
|
||||||
}
|
}
|
||||||
|
|
||||||
void StartUpProcess::TextFade(int direction)
|
void StartUpProcess::TextFade(int direction)
|
||||||
{
|
{
|
||||||
if(direction > 0)
|
if(direction > 0)
|
||||||
{
|
{
|
||||||
for(int i = 0; i < 255; i += direction)
|
for(int i = 0; i < 255; i += direction)
|
||||||
{
|
{
|
||||||
messageTxt->SetAlpha(i);
|
messageTxt->SetAlpha(i);
|
||||||
Draw();
|
Draw();
|
||||||
}
|
}
|
||||||
messageTxt->SetAlpha(255);
|
messageTxt->SetAlpha(255);
|
||||||
Draw();
|
Draw();
|
||||||
}
|
}
|
||||||
else if(direction < 0)
|
else if(direction < 0)
|
||||||
{
|
{
|
||||||
for(int i = 255; i > 0; i += direction)
|
for(int i = 255; i > 0; i += direction)
|
||||||
{
|
{
|
||||||
messageTxt->SetAlpha(i);
|
messageTxt->SetAlpha(i);
|
||||||
Draw();
|
Draw();
|
||||||
}
|
}
|
||||||
messageTxt->SetAlpha(0);
|
messageTxt->SetAlpha(0);
|
||||||
Draw();
|
Draw();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void StartUpProcess::SetTextf(const char * format, ...)
|
void StartUpProcess::SetTextf(const char * format, ...)
|
||||||
|
@ -109,150 +109,150 @@ void StartUpProcess::SetTextf(const char * format, ...)
|
||||||
va_list va;
|
va_list va;
|
||||||
va_start(va, format);
|
va_start(va, format);
|
||||||
if((vasprintf(&tmp, format, va) >= 0) && tmp)
|
if((vasprintf(&tmp, format, va) >= 0) && tmp)
|
||||||
{
|
{
|
||||||
TextFade(-40);
|
TextFade(-40);
|
||||||
gprintf(tmp);
|
gprintf(tmp);
|
||||||
messageTxt->SetText(tmp);
|
messageTxt->SetText(tmp);
|
||||||
TextFade(40);
|
TextFade(40);
|
||||||
}
|
}
|
||||||
va_end(va);
|
va_end(va);
|
||||||
|
|
||||||
if(tmp)
|
if(tmp)
|
||||||
free(tmp);
|
free(tmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool StartUpProcess::USBSpinUp()
|
bool StartUpProcess::USBSpinUp()
|
||||||
{
|
{
|
||||||
bool started = false;
|
bool started = false;
|
||||||
const DISC_INTERFACE * handle = Settings.USBPort == 1 ? DeviceHandler::GetUSB1Interface() : DeviceHandler::GetUSB0Interface();
|
const DISC_INTERFACE * handle = Settings.USBPort == 1 ? DeviceHandler::GetUSB1Interface() : DeviceHandler::GetUSB0Interface();
|
||||||
Timer countDown;
|
Timer countDown;
|
||||||
// wait 10 sec for the USB to spin up...stupid slow ass HDD
|
// wait 10 sec for the USB to spin up...stupid slow ass HDD
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
started = (handle->startup() && handle->isInserted());
|
started = (handle->startup() && handle->isInserted());
|
||||||
if(started)
|
if(started)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
messageTxt->SetTextf("Waiting for HDD: %i sec left\n", 20-(int)countDown.elapsed());
|
messageTxt->SetTextf("Waiting for HDD: %i sec left\n", 20-(int)countDown.elapsed());
|
||||||
Draw();
|
Draw();
|
||||||
usleep(50000);
|
usleep(50000);
|
||||||
}
|
}
|
||||||
while(countDown.elapsed() < 20.f);
|
while(countDown.elapsed() < 20.f);
|
||||||
|
|
||||||
return started;
|
return started;
|
||||||
}
|
}
|
||||||
|
|
||||||
int StartUpProcess::Run(int argc, char *argv[])
|
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)
|
if(quickGameBoot != -1)
|
||||||
return QuickGameBoot(argv[quickGameBoot]);
|
return QuickGameBoot(argv[quickGameBoot]);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int StartUpProcess::Execute()
|
int StartUpProcess::Execute()
|
||||||
{
|
{
|
||||||
Settings.EntryIOS = IOS_GetVersion();
|
Settings.EntryIOS = IOS_GetVersion();
|
||||||
SetTextf("Start up\n");
|
SetTextf("Start up\n");
|
||||||
|
|
||||||
if(IosLoader::LoadAppCios() < 0)
|
if(IosLoader::LoadAppCios() < 0)
|
||||||
{
|
{
|
||||||
SetTextf("Failed loading any cIOS. USB Loader GX requires at least cIOS 222 or 245-250. Exiting...\n");
|
SetTextf("Failed loading any cIOS. USB Loader GX requires at least cIOS 222 or 245-250. Exiting...\n");
|
||||||
sleep(5);
|
sleep(5);
|
||||||
Sys_BackToLoader();
|
Sys_BackToLoader();
|
||||||
}
|
}
|
||||||
|
|
||||||
SetTextf("Initialize sd card\n");
|
SetTextf("Initialize sd card\n");
|
||||||
DeviceHandler::Instance()->MountSD();
|
DeviceHandler::Instance()->MountSD();
|
||||||
|
|
||||||
SetTextf("Initialize usb device\n");
|
SetTextf("Initialize usb device\n");
|
||||||
USBSpinUp();
|
USBSpinUp();
|
||||||
DeviceHandler::Instance()->MountAllUSB(false);
|
DeviceHandler::Instance()->MountAllUSB(false);
|
||||||
|
|
||||||
SetTextf("Loading config files");
|
SetTextf("Loading config files");
|
||||||
gprintf("\tLoading config...%s\n", Settings.Load() ? "done" : "failed");
|
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 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 settings...%s\n", GameSettings.Load(Settings.ConfigPath) ? "done" : "failed");
|
||||||
gprintf("\tLoading game statistics...%s\n", GameStatistics.Load(Settings.ConfigPath) ? "done" : "failed");
|
gprintf("\tLoading game statistics...%s\n", GameStatistics.Load(Settings.ConfigPath) ? "done" : "failed");
|
||||||
|
|
||||||
if(Settings.cios != IOS_GetVersion())
|
if(Settings.cios != IOS_GetVersion())
|
||||||
{
|
{
|
||||||
SetTextf("Loading cIOS %i\n", Settings.cios);
|
SetTextf("Loading cIOS %i\n", Settings.cios);
|
||||||
|
|
||||||
DeviceHandler::DestroyInstance();
|
DeviceHandler::DestroyInstance();
|
||||||
USBStorage2_Deinit();
|
USBStorage2_Deinit();
|
||||||
|
|
||||||
// Loading now the cios setup in the settings
|
// Loading now the cios setup in the settings
|
||||||
IosLoader::LoadAppCios();
|
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();
|
DeviceHandler::Instance()->MountSD();
|
||||||
USBSpinUp();
|
USBSpinUp();
|
||||||
DeviceHandler::Instance()->MountAllUSB(false);
|
DeviceHandler::Instance()->MountAllUSB(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!IosLoader::IsHermesIOS())
|
if(!IosLoader::IsHermesIOS())
|
||||||
{
|
{
|
||||||
Settings.USBPort = 0;
|
Settings.USBPort = 0;
|
||||||
}
|
}
|
||||||
else if(Settings.USBPort == 1 && USBStorage2_GetPort() != Settings.USBPort)
|
else if(Settings.USBPort == 1 && USBStorage2_GetPort() != Settings.USBPort)
|
||||||
{
|
{
|
||||||
SetTextf("Changing USB Port to %i\n", Settings.USBPort);
|
SetTextf("Changing USB Port to %i\n", Settings.USBPort);
|
||||||
DeviceHandler::Instance()->UnMountAllUSB();
|
DeviceHandler::Instance()->UnMountAllUSB();
|
||||||
DeviceHandler::Instance()->MountAllUSB();
|
DeviceHandler::Instance()->MountAllUSB();
|
||||||
}
|
}
|
||||||
else if(Settings.USBPort == 2)
|
else if(Settings.USBPort == 2)
|
||||||
{
|
{
|
||||||
SetTextf("Mounting USB Port to 1\n");
|
SetTextf("Mounting USB Port to 1\n");
|
||||||
DeviceHandler::Instance()->MountUSBPort1();
|
DeviceHandler::Instance()->MountUSBPort1();
|
||||||
}
|
}
|
||||||
|
|
||||||
gprintf("\tLoading game categories...%s\n", GameCategories.Load(Settings.ConfigPath) ? "done" : "failed");
|
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 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 theme...%s\n", Theme::Load(Settings.theme) ? "done" : "failed (using default)");
|
||||||
|
|
||||||
//! Init the rest of the System
|
//! Init the rest of the System
|
||||||
Sys_Init();
|
Sys_Init();
|
||||||
SetupPads();
|
SetupPads();
|
||||||
InitAudio();
|
InitAudio();
|
||||||
setlocale(LC_CTYPE, "C-UTF-8");
|
setlocale(LC_CTYPE, "C-UTF-8");
|
||||||
setlocale(LC_MESSAGES, "C-UTF-8");
|
setlocale(LC_MESSAGES, "C-UTF-8");
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void StartUpProcess::Draw()
|
void StartUpProcess::Draw()
|
||||||
{
|
{
|
||||||
background->Draw();
|
background->Draw();
|
||||||
GXImage->Draw();
|
GXImage->Draw();
|
||||||
titleTxt->Draw();
|
titleTxt->Draw();
|
||||||
messageTxt->Draw();
|
messageTxt->Draw();
|
||||||
Menu_Render();
|
Menu_Render();
|
||||||
}
|
}
|
||||||
|
|
||||||
int StartUpProcess::QuickGameBoot(const char * gameID)
|
int StartUpProcess::QuickGameBoot(const char * gameID)
|
||||||
{
|
{
|
||||||
MountGamePartition(false);
|
MountGamePartition(false);
|
||||||
|
|
||||||
struct discHdr *header = NULL;
|
struct discHdr *header = NULL;
|
||||||
for(int i = 0; i < gameList.size(); ++i)
|
for(int i = 0; i < gameList.size(); ++i)
|
||||||
{
|
{
|
||||||
if(strncasecmp((char *) gameList[i]->id, gameID, 6) == 0)
|
if(strncasecmp((char *) gameList[i]->id, gameID, 6) == 0)
|
||||||
header = gameList[i];
|
header = gameList[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!header)
|
if(!header)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
GameStatistics.SetPlayCount(header->id, GameStatistics.GetPlayCount(header->id)+1);
|
GameStatistics.SetPlayCount(header->id, GameStatistics.GetPlayCount(header->id)+1);
|
||||||
GameStatistics.Save();
|
GameStatistics.Save();
|
||||||
|
|
||||||
return GameBooter::BootGame(gameID);
|
return GameBooter::BootGame(gameID);
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,24 +5,24 @@
|
||||||
|
|
||||||
class StartUpProcess
|
class StartUpProcess
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static int Run(int argc, char *argv[]);
|
static int Run(int argc, char *argv[]);
|
||||||
private:
|
private:
|
||||||
StartUpProcess();
|
StartUpProcess();
|
||||||
~StartUpProcess();
|
~StartUpProcess();
|
||||||
int Execute();
|
int Execute();
|
||||||
bool USBSpinUp();
|
bool USBSpinUp();
|
||||||
void TextFade(int direction);
|
void TextFade(int direction);
|
||||||
void SetTextf(const char * format, ...);
|
void SetTextf(const char * format, ...);
|
||||||
void Draw();
|
void Draw();
|
||||||
static int ParseArguments(int argc, char *argv[]);
|
static int ParseArguments(int argc, char *argv[]);
|
||||||
static int QuickGameBoot(const char * gameID);
|
static int QuickGameBoot(const char * gameID);
|
||||||
|
|
||||||
GuiImageData * GXImageData;
|
GuiImageData * GXImageData;
|
||||||
GuiImage * background;
|
GuiImage * background;
|
||||||
GuiImage * GXImage;
|
GuiImage * GXImage;
|
||||||
GuiText * titleTxt;
|
GuiText * titleTxt;
|
||||||
GuiText * messageTxt;
|
GuiText * messageTxt;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -41,144 +41,144 @@
|
||||||
|
|
||||||
ZipFile::ZipFile(const char *filepath)
|
ZipFile::ZipFile(const char *filepath)
|
||||||
{
|
{
|
||||||
File = unzOpen(filepath);
|
File = unzOpen(filepath);
|
||||||
if (File) this->LoadList();
|
if (File) this->LoadList();
|
||||||
}
|
}
|
||||||
|
|
||||||
ZipFile::~ZipFile()
|
ZipFile::~ZipFile()
|
||||||
{
|
{
|
||||||
unzClose(File);
|
unzClose(File);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ZipFile::LoadList()
|
bool ZipFile::LoadList()
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ZipFile::FindFile(const char *file)
|
bool ZipFile::FindFile(const char *file)
|
||||||
{
|
{
|
||||||
if (!File) return false;
|
if (!File) return false;
|
||||||
|
|
||||||
char filename[MAXPATHLEN];
|
char filename[MAXPATHLEN];
|
||||||
|
|
||||||
int ret = unzGoToFirstFile(File);
|
int ret = unzGoToFirstFile(File);
|
||||||
if (ret != UNZ_OK) return false;
|
if (ret != UNZ_OK) return false;
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
if(unzGetCurrentFileInfo(File, &cur_file_info, filename, sizeof(filename), NULL, 0, NULL, 0) != UNZ_OK)
|
if(unzGetCurrentFileInfo(File, &cur_file_info, filename, sizeof(filename), NULL, 0, NULL, 0) != UNZ_OK)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
const char *realfilename = strrchr(filename, '/');
|
const char *realfilename = strrchr(filename, '/');
|
||||||
if(!realfilename || strlen(realfilename) == 0)
|
if(!realfilename || strlen(realfilename) == 0)
|
||||||
realfilename = filename;
|
realfilename = filename;
|
||||||
|
|
||||||
if(strcasecmp(realfilename, file) == 0)
|
if(strcasecmp(realfilename, file) == 0)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
while(unzGoToNextFile(File) == UNZ_OK);
|
while(unzGoToNextFile(File) == UNZ_OK);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ZipFile::FindFilePart(const char *partfilename, std::string &realname)
|
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);
|
int ret = unzGoToFirstFile(File);
|
||||||
if (ret != UNZ_OK) return false;
|
if (ret != UNZ_OK) return false;
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
if(unzGetCurrentFileInfo(File, &cur_file_info, filename, sizeof(filename), NULL, 0, NULL, 0) != UNZ_OK)
|
if(unzGetCurrentFileInfo(File, &cur_file_info, filename, sizeof(filename), NULL, 0, NULL, 0) != UNZ_OK)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if(strcasestr(filename, partfilename) != 0)
|
if(strcasestr(filename, partfilename) != 0)
|
||||||
{
|
{
|
||||||
realname = filename;
|
realname = filename;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
while(unzGoToNextFile(File) == UNZ_OK);
|
while(unzGoToNextFile(File) == UNZ_OK);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ZipFile::ExtractAll(const char *dest)
|
bool ZipFile::ExtractAll(const char *dest)
|
||||||
{
|
{
|
||||||
if (!File) return false;
|
if (!File) return false;
|
||||||
|
|
||||||
bool Stop = false;
|
bool Stop = false;
|
||||||
|
|
||||||
u32 blocksize = 1024 * 50;
|
u32 blocksize = 1024 * 50;
|
||||||
u8 *buffer = new u8[blocksize];
|
u8 *buffer = new u8[blocksize];
|
||||||
|
|
||||||
if (!buffer) return false;
|
if (!buffer) return false;
|
||||||
|
|
||||||
char writepath[MAXPATHLEN];
|
char writepath[MAXPATHLEN];
|
||||||
char filename[MAXPATHLEN];
|
char filename[MAXPATHLEN];
|
||||||
memset(filename, 0, sizeof(filename));
|
memset(filename, 0, sizeof(filename));
|
||||||
|
|
||||||
int ret = unzGoToFirstFile(File);
|
int ret = unzGoToFirstFile(File);
|
||||||
if (ret != UNZ_OK) Stop = true;
|
if (ret != UNZ_OK) Stop = true;
|
||||||
|
|
||||||
while (!Stop)
|
while (!Stop)
|
||||||
{
|
{
|
||||||
if (unzGetCurrentFileInfo(File, &cur_file_info, filename, sizeof(filename), NULL, 0, NULL, 0) != UNZ_OK) Stop
|
if (unzGetCurrentFileInfo(File, &cur_file_info, filename, sizeof(filename), NULL, 0, NULL, 0) != UNZ_OK) Stop
|
||||||
= true;
|
= true;
|
||||||
|
|
||||||
if (!Stop && filename[strlen(filename) - 1] != '/')
|
if (!Stop && filename[strlen(filename) - 1] != '/')
|
||||||
{
|
{
|
||||||
u32 uncompressed_size = cur_file_info.uncompressed_size;
|
u32 uncompressed_size = cur_file_info.uncompressed_size;
|
||||||
|
|
||||||
u32 done = 0;
|
u32 done = 0;
|
||||||
char *pointer = NULL;
|
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, '/');
|
pointer = strrchr(writepath, '/');
|
||||||
int position = pointer - writepath + 2;
|
int position = pointer - writepath + 2;
|
||||||
|
|
||||||
char temppath[strlen(writepath)];
|
char temppath[strlen(writepath)];
|
||||||
snprintf(temppath, position, "%s", writepath);
|
snprintf(temppath, position, "%s", writepath);
|
||||||
|
|
||||||
CreateSubfolder(temppath);
|
CreateSubfolder(temppath);
|
||||||
|
|
||||||
if (ret == UNZ_OK)
|
if (ret == UNZ_OK)
|
||||||
{
|
{
|
||||||
FILE *pfile = fopen(writepath, "wb");
|
FILE *pfile = fopen(writepath, "wb");
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
ShowProgress(tr( "Extracting files..." ), 0, pointer + 1, done, uncompressed_size, true);
|
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);
|
fclose(pfile);
|
||||||
unzCloseCurrentFile(File);
|
unzCloseCurrentFile(File);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (unzGoToNextFile(File) != UNZ_OK) Stop = true;
|
if (unzGoToNextFile(File) != UNZ_OK) Stop = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
delete[] buffer;
|
delete[] buffer;
|
||||||
buffer = NULL;
|
buffer = NULL;
|
||||||
|
|
||||||
ProgressStop();
|
ProgressStop();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,31 +33,31 @@
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
u64 offset; // ZipFile offset
|
u64 offset; // ZipFile offset
|
||||||
u64 length; // uncompressed file length in 64 bits for sizes higher than 4GB
|
u64 length; // uncompressed file length in 64 bits for sizes higher than 4GB
|
||||||
bool isdir; // 0 - file, 1 - directory
|
bool isdir; // 0 - file, 1 - directory
|
||||||
char filename[256]; // full filename
|
char filename[256]; // full filename
|
||||||
} FileStructure;
|
} FileStructure;
|
||||||
|
|
||||||
class ZipFile
|
class ZipFile
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
//!Constructor
|
//!Constructor
|
||||||
ZipFile(const char *filepath);
|
ZipFile(const char *filepath);
|
||||||
//!Destructor
|
//!Destructor
|
||||||
~ZipFile();
|
~ZipFile();
|
||||||
//!Extract all files from a zip file to a directory
|
//!Extract all files from a zip file to a directory
|
||||||
//!\param dest Destination path to where to extract
|
//!\param dest Destination path to where to extract
|
||||||
bool ExtractAll(const char *dest);
|
bool ExtractAll(const char *dest);
|
||||||
//!Find a file inside the zip and return if it is existent or not
|
//!Find a file inside the zip and return if it is existent or not
|
||||||
bool FindFile(const char *filename);
|
bool FindFile(const char *filename);
|
||||||
//!Only needed a part of a filename to find the real one
|
//!Only needed a part of a filename to find the real one
|
||||||
bool FindFilePart(const char *partfilename, std::string &realname);
|
bool FindFilePart(const char *partfilename, std::string &realname);
|
||||||
protected:
|
protected:
|
||||||
bool LoadList();
|
bool LoadList();
|
||||||
unzFile File;
|
unzFile File;
|
||||||
unz_file_info cur_file_info;
|
unz_file_info cur_file_info;
|
||||||
FileStructure *FileList;
|
FileStructure *FileList;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -17,9 +17,9 @@
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
void InitAudio()
|
void InitAudio()
|
||||||
{
|
{
|
||||||
AUDIO_Init(NULL);
|
AUDIO_Init(NULL);
|
||||||
ASND_Init();
|
ASND_Init();
|
||||||
ASND_Pause(0);
|
ASND_Pause(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
|
@ -30,6 +30,6 @@ void InitAudio()
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
void ShutdownAudio()
|
void ShutdownAudio()
|
||||||
{
|
{
|
||||||
ASND_Pause(1);
|
ASND_Pause(1);
|
||||||
ASND_End();
|
ASND_End();
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,114 +8,114 @@
|
||||||
BNRInstance * BNRInstance::instance = NULL;
|
BNRInstance * BNRInstance::instance = NULL;
|
||||||
|
|
||||||
OpeningBNR::OpeningBNR()
|
OpeningBNR::OpeningBNR()
|
||||||
: imetHdr(0)
|
: imetHdr(0)
|
||||||
{
|
{
|
||||||
memset(gameID, 0, sizeof(gameID));
|
memset(gameID, 0, sizeof(gameID));
|
||||||
}
|
}
|
||||||
|
|
||||||
OpeningBNR::~OpeningBNR()
|
OpeningBNR::~OpeningBNR()
|
||||||
{
|
{
|
||||||
if(imetHdr)
|
if(imetHdr)
|
||||||
free(imetHdr);
|
free(imetHdr);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool OpeningBNR::Load(const u8 * discid)
|
bool OpeningBNR::Load(const u8 * discid)
|
||||||
{
|
{
|
||||||
if(!discid)
|
if(!discid)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if(memcmp(gameID, discid, 6) == 0)
|
if(memcmp(gameID, discid, 6) == 0)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if(imetHdr)
|
if(imetHdr)
|
||||||
free(imetHdr);
|
free(imetHdr);
|
||||||
imetHdr = NULL;
|
imetHdr = NULL;
|
||||||
snprintf(gameID, sizeof(gameID), (const char *) discid);
|
snprintf(gameID, sizeof(gameID), (const char *) discid);
|
||||||
|
|
||||||
wbfs_disc_t *disc = WBFS_OpenDisc((u8 *) gameID);
|
wbfs_disc_t *disc = WBFS_OpenDisc((u8 *) gameID);
|
||||||
if (!disc)
|
if (!disc)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
wiidisc_t *wdisc = wd_open_disc((int(*)(void *, u32, u32, void *)) wbfs_disc_read, disc);
|
wiidisc_t *wdisc = wd_open_disc((int(*)(void *, u32, u32, void *)) wbfs_disc_read, disc);
|
||||||
if (!wdisc)
|
if (!wdisc)
|
||||||
{
|
{
|
||||||
WBFS_CloseDisc(disc);
|
WBFS_CloseDisc(disc);
|
||||||
return false;
|
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);
|
wd_close_disc(wdisc);
|
||||||
WBFS_CloseDisc(disc);
|
WBFS_CloseDisc(disc);
|
||||||
|
|
||||||
if(!imetHdr)
|
if(!imetHdr)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (imetHdr->fcc != 'IMET')
|
if (imetHdr->fcc != 'IMET')
|
||||||
{
|
{
|
||||||
free(imetHdr);
|
free(imetHdr);
|
||||||
imetHdr = NULL;
|
imetHdr = NULL;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
const u16 * OpeningBNR::GetIMETTitle(int lang)
|
const u16 * OpeningBNR::GetIMETTitle(int lang)
|
||||||
{
|
{
|
||||||
if(!imetHdr || lang < 0 || lang >= 10)
|
if(!imetHdr || lang < 0 || lang >= 10)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if(imetHdr->names[lang][0] == 0)
|
if(imetHdr->names[lang][0] == 0)
|
||||||
lang = CONF_LANG_ENGLISH;
|
lang = CONF_LANG_ENGLISH;
|
||||||
|
|
||||||
return imetHdr->names[lang];
|
return imetHdr->names[lang];
|
||||||
}
|
}
|
||||||
|
|
||||||
const u8 * OpeningBNR::GetBannerSound(u32 * size)
|
const u8 * OpeningBNR::GetBannerSound(u32 * size)
|
||||||
{
|
{
|
||||||
if(!imetHdr)
|
if(!imetHdr)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
const U8Header *bnrArcHdr = (U8Header *) (imetHdr + 1);
|
const U8Header *bnrArcHdr = (U8Header *) (imetHdr + 1);
|
||||||
const U8Entry *fst = (const U8Entry *) (((const u8 *) bnrArcHdr) + bnrArcHdr->rootNodeOffset);
|
const U8Entry *fst = (const U8Entry *) (((const u8 *) bnrArcHdr) + bnrArcHdr->rootNodeOffset);
|
||||||
|
|
||||||
u32 i;
|
u32 i;
|
||||||
for (i = 1; i < fst[0].numEntries; ++i)
|
for (i = 1; i < fst[0].numEntries; ++i)
|
||||||
if (fst[i].fileType == 0 && strcasecmp(u8Filename(fst, i), "sound.bin") == 0) break;
|
if (fst[i].fileType == 0 && strcasecmp(u8Filename(fst, i), "sound.bin") == 0) break;
|
||||||
|
|
||||||
if (i >= fst[0].numEntries)
|
if (i >= fst[0].numEntries)
|
||||||
{
|
{
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
const u8 *sound_bin = ((const u8 *) bnrArcHdr) + fst[i].fileOffset;
|
const u8 *sound_bin = ((const u8 *) bnrArcHdr) + fst[i].fileOffset;
|
||||||
if (((IMD5Header *) sound_bin)->fcc != 'IMD5')
|
if (((IMD5Header *) sound_bin)->fcc != 'IMD5')
|
||||||
{
|
{
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
const u8 *soundChunk = sound_bin + sizeof(IMD5Header);
|
const u8 *soundChunk = sound_bin + sizeof(IMD5Header);
|
||||||
u32 soundChunkSize = fst[i].fileLength - sizeof(IMD5Header);
|
u32 soundChunkSize = fst[i].fileLength - sizeof(IMD5Header);
|
||||||
|
|
||||||
if (*((u32*) soundChunk) == 'LZ77')
|
if (*((u32*) soundChunk) == 'LZ77')
|
||||||
{
|
{
|
||||||
u32 uncSize = 0;
|
u32 uncSize = 0;
|
||||||
u8 * uncompressed_data = uncompressLZ77(soundChunk, soundChunkSize, &uncSize);
|
u8 * uncompressed_data = uncompressLZ77(soundChunk, soundChunkSize, &uncSize);
|
||||||
if (!uncompressed_data)
|
if (!uncompressed_data)
|
||||||
{
|
{
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (size) *size = uncSize;
|
if (size) *size = uncSize;
|
||||||
|
|
||||||
return uncompressed_data;
|
return uncompressed_data;
|
||||||
}
|
}
|
||||||
|
|
||||||
u8 *out = (u8 *) malloc(soundChunkSize);
|
u8 *out = (u8 *) malloc(soundChunkSize);
|
||||||
if (out)
|
if (out)
|
||||||
{
|
{
|
||||||
memcpy(out, soundChunk, soundChunkSize);
|
memcpy(out, soundChunk, soundChunkSize);
|
||||||
if (size) *size = soundChunkSize;
|
if (size) *size = soundChunkSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,80 +5,80 @@
|
||||||
|
|
||||||
typedef struct _IMETHeader
|
typedef struct _IMETHeader
|
||||||
{
|
{
|
||||||
u8 zeroes[64];
|
u8 zeroes[64];
|
||||||
u32 fcc;
|
u32 fcc;
|
||||||
u8 unk[8];
|
u8 unk[8];
|
||||||
u32 iconSize;
|
u32 iconSize;
|
||||||
u32 bannerSize;
|
u32 bannerSize;
|
||||||
u32 soundSize;
|
u32 soundSize;
|
||||||
u32 flag1;
|
u32 flag1;
|
||||||
u16 names[10][42]; // 10 languages (thanks dkosmari for the info)
|
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)
|
u16 zeroes_2[7*42]; // padding for 7 more languages (thanks dkosmari for the info)
|
||||||
u8 crypto[16];
|
u8 crypto[16];
|
||||||
} __attribute__((packed)) IMETHeader;
|
} __attribute__((packed)) IMETHeader;
|
||||||
|
|
||||||
typedef struct _IMD5Header
|
typedef struct _IMD5Header
|
||||||
{
|
{
|
||||||
u32 fcc;
|
u32 fcc;
|
||||||
u32 filesize;
|
u32 filesize;
|
||||||
u8 zeroes[8];
|
u8 zeroes[8];
|
||||||
u8 crypto[16];
|
u8 crypto[16];
|
||||||
} __attribute__((packed)) IMD5Header;
|
} __attribute__((packed)) IMD5Header;
|
||||||
|
|
||||||
typedef struct _U8Header
|
typedef struct _U8Header
|
||||||
{
|
{
|
||||||
u32 fcc;
|
u32 fcc;
|
||||||
u32 rootNodeOffset;
|
u32 rootNodeOffset;
|
||||||
u32 headerSize;
|
u32 headerSize;
|
||||||
u32 dataOffset;
|
u32 dataOffset;
|
||||||
u8 zeroes[16];
|
u8 zeroes[16];
|
||||||
} __attribute__((packed)) U8Header;
|
} __attribute__((packed)) U8Header;
|
||||||
|
|
||||||
typedef struct _U8Entry
|
typedef struct _U8Entry
|
||||||
{
|
{
|
||||||
struct
|
struct
|
||||||
{
|
{
|
||||||
u32 fileType :8;
|
u32 fileType :8;
|
||||||
u32 nameOffset :24;
|
u32 nameOffset :24;
|
||||||
};
|
};
|
||||||
u32 fileOffset;
|
u32 fileOffset;
|
||||||
union
|
union
|
||||||
{
|
{
|
||||||
u32 fileLength;
|
u32 fileLength;
|
||||||
u32 numEntries;
|
u32 numEntries;
|
||||||
};
|
};
|
||||||
} __attribute__( ( packed ) ) U8Entry;
|
} __attribute__( ( packed ) ) U8Entry;
|
||||||
|
|
||||||
|
|
||||||
static inline const char * u8Filename(const U8Entry *fst, int i)
|
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
|
class OpeningBNR
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
OpeningBNR();
|
OpeningBNR();
|
||||||
~OpeningBNR();
|
~OpeningBNR();
|
||||||
bool Load(const u8 * gameID);
|
bool Load(const u8 * gameID);
|
||||||
const u16 * GetIMETTitle(int lang);
|
const u16 * GetIMETTitle(int lang);
|
||||||
const u16 * GetIMETTitle(const u8 * gameID, int lang) { Load(gameID); return GetIMETTitle(lang); };
|
const u16 * GetIMETTitle(const u8 * gameID, int lang) { Load(gameID); return GetIMETTitle(lang); };
|
||||||
const u8 * GetBannerSound(u32 * size);
|
const u8 * GetBannerSound(u32 * size);
|
||||||
const u8 * GetBannerSound(const u8 * gameID, u32 * size) { Load(gameID); return GetBannerSound(size); };
|
const u8 * GetBannerSound(const u8 * gameID, u32 * size) { Load(gameID); return GetBannerSound(size); };
|
||||||
private:
|
private:
|
||||||
IMETHeader *imetHdr;
|
IMETHeader *imetHdr;
|
||||||
char gameID[7];
|
char gameID[7];
|
||||||
};
|
};
|
||||||
|
|
||||||
class BNRInstance : public OpeningBNR
|
class BNRInstance : public OpeningBNR
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static BNRInstance * Instance() { if(!instance) instance = new BNRInstance; return instance; };
|
static BNRInstance * Instance() { if(!instance) instance = new BNRInstance; return instance; };
|
||||||
static void DestroyInstance() { delete instance; instance = NULL; };
|
static void DestroyInstance() { delete instance; instance = NULL; };
|
||||||
private:
|
private:
|
||||||
BNRInstance() { };
|
BNRInstance() { };
|
||||||
~BNRInstance() { };
|
~BNRInstance() { };
|
||||||
static BNRInstance * instance;
|
static BNRInstance * instance;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -16,151 +16,151 @@
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
int CheatMenu(const char * gameID)
|
int CheatMenu(const char * gameID)
|
||||||
{
|
{
|
||||||
int choice = 0;
|
int choice = 0;
|
||||||
bool exit = false;
|
bool exit = false;
|
||||||
int ret = 1;
|
int ret = 1;
|
||||||
|
|
||||||
GuiImageData btnOutline(Resources::GetFile("button_dialogue_box.png"), Resources::GetFileSize("button_dialogue_box.png"));
|
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"));
|
GuiImageData settingsbg(Resources::GetFile("settings_background.png"), Resources::GetFileSize("settings_background.png"));
|
||||||
GuiImage settingsbackground(&settingsbg);
|
GuiImage settingsbackground(&settingsbg);
|
||||||
|
|
||||||
GuiTrigger trigA;
|
GuiTrigger trigA;
|
||||||
trigA.SetSimpleTrigger(-1, WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A, PAD_BUTTON_A);
|
trigA.SetSimpleTrigger(-1, WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A, PAD_BUTTON_A);
|
||||||
GuiTrigger trigB;
|
GuiTrigger trigB;
|
||||||
trigB.SetButtonOnlyTrigger(-1, WPAD_BUTTON_B | WPAD_CLASSIC_BUTTON_B, PAD_BUTTON_B);
|
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"));
|
GuiText backBtnTxt(tr( "Back" ), 22, thColor("r=0 g=0 b=0 a=255 - prompt windows button text color"));
|
||||||
backBtnTxt.SetMaxWidth(btnOutline.GetWidth() - 30);
|
backBtnTxt.SetMaxWidth(btnOutline.GetWidth() - 30);
|
||||||
GuiImage backBtnImg(&btnOutline);
|
GuiImage backBtnImg(&btnOutline);
|
||||||
GuiButton backBtn(&backBtnImg, &backBtnImg, 2, 3, -140, 400, &trigA, NULL, btnSoundClick2, 1);
|
GuiButton backBtn(&backBtnImg, &backBtnImg, 2, 3, -140, 400, &trigA, NULL, btnSoundClick2, 1);
|
||||||
backBtn.SetLabel(&backBtnTxt);
|
backBtn.SetLabel(&backBtnTxt);
|
||||||
backBtn.SetTrigger(&trigB);
|
backBtn.SetTrigger(&trigB);
|
||||||
|
|
||||||
GuiText createBtnTxt(tr( "Create" ), 22, thColor("r=0 g=0 b=0 a=255 - prompt windows button text color"));
|
GuiText createBtnTxt(tr( "Create" ), 22, thColor("r=0 g=0 b=0 a=255 - prompt windows button text color"));
|
||||||
createBtnTxt.SetMaxWidth(btnOutline.GetWidth() - 30);
|
createBtnTxt.SetMaxWidth(btnOutline.GetWidth() - 30);
|
||||||
GuiImage createBtnImg(&btnOutline);
|
GuiImage createBtnImg(&btnOutline);
|
||||||
GuiButton createBtn(&createBtnImg, &createBtnImg, 2, 3, 160, 400, &trigA, NULL, btnSoundClick2, 1);
|
GuiButton createBtn(&createBtnImg, &createBtnImg, 2, 3, 160, 400, &trigA, NULL, btnSoundClick2, 1);
|
||||||
createBtn.SetLabel(&createBtnTxt);
|
createBtn.SetLabel(&createBtnTxt);
|
||||||
|
|
||||||
char txtfilename[55];
|
char txtfilename[55];
|
||||||
snprintf(txtfilename, sizeof(txtfilename), "%s%s.txt", Settings.TxtCheatcodespath, gameID);
|
snprintf(txtfilename, sizeof(txtfilename), "%s%s.txt", Settings.TxtCheatcodespath, gameID);
|
||||||
|
|
||||||
GCTCheats c;
|
GCTCheats c;
|
||||||
int check = c.openTxtfile(txtfilename);
|
int check = c.openTxtfile(txtfilename);
|
||||||
|
|
||||||
int download = 0;
|
int download = 0;
|
||||||
|
|
||||||
switch (check)
|
switch (check)
|
||||||
{
|
{
|
||||||
case -1:
|
case -1:
|
||||||
WindowPrompt(tr( "Error" ), tr( "Cheatfile is blank" ), tr( "OK" ));
|
WindowPrompt(tr( "Error" ), tr( "Cheatfile is blank" ), tr( "OK" ));
|
||||||
break;
|
break;
|
||||||
case 0:
|
case 0:
|
||||||
download = WindowPrompt(tr( "Error" ), tr( "No Cheatfile found" ), tr( "Download Now" ), tr( "Cancel" ));
|
download = WindowPrompt(tr( "Error" ), tr( "No Cheatfile found" ), tr( "Download Now" ), tr( "Cancel" ));
|
||||||
if (download == 1)
|
if (download == 1)
|
||||||
{
|
{
|
||||||
download = CodeDownload(gameID);
|
download = CodeDownload(gameID);
|
||||||
if (download < 0 || c.openTxtfile(txtfilename) != 1)
|
if (download < 0 || c.openTxtfile(txtfilename) != 1)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
int cntcheats = c.getCnt();
|
int cntcheats = c.getCnt();
|
||||||
OptionList cheatslst;
|
OptionList cheatslst;
|
||||||
GuiOptionBrowser chtBrowser(400, 280, &cheatslst, "bg_options_settings.png");
|
GuiOptionBrowser chtBrowser(400, 280, &cheatslst, "bg_options_settings.png");
|
||||||
chtBrowser.SetPosition(0, 90);
|
chtBrowser.SetPosition(0, 90);
|
||||||
chtBrowser.SetAlignment(ALIGN_CENTRE, ALIGN_TOP);
|
chtBrowser.SetAlignment(ALIGN_CENTRE, ALIGN_TOP);
|
||||||
chtBrowser.SetClickable(true);
|
chtBrowser.SetClickable(true);
|
||||||
|
|
||||||
GuiText titleTxt(c.getGameName().c_str(), 28, ( GXColor ) {0, 0, 0, 255});
|
GuiText titleTxt(c.getGameName().c_str(), 28, ( GXColor ) {0, 0, 0, 255});
|
||||||
titleTxt.SetAlignment(ALIGN_CENTRE, ALIGN_TOP);
|
titleTxt.SetAlignment(ALIGN_CENTRE, ALIGN_TOP);
|
||||||
titleTxt.SetMaxWidth(350, SCROLL_HORIZONTAL);
|
titleTxt.SetMaxWidth(350, SCROLL_HORIZONTAL);
|
||||||
titleTxt.SetPosition(12, 40);
|
titleTxt.SetPosition(12, 40);
|
||||||
|
|
||||||
for (int i = 0; i < cntcheats; i++)
|
for (int i = 0; i < cntcheats; i++)
|
||||||
{
|
{
|
||||||
cheatslst.SetValue(i, "%s", c.getCheatName(i).c_str());
|
cheatslst.SetValue(i, "%s", c.getCheatName(i).c_str());
|
||||||
cheatslst.SetName(i, "OFF");
|
cheatslst.SetName(i, "OFF");
|
||||||
}
|
}
|
||||||
|
|
||||||
HaltGui();
|
HaltGui();
|
||||||
GuiWindow w(screenwidth, screenheight);
|
GuiWindow w(screenwidth, screenheight);
|
||||||
w.Append(&settingsbackground);
|
w.Append(&settingsbackground);
|
||||||
w.Append(&titleTxt);
|
w.Append(&titleTxt);
|
||||||
w.Append(&backBtn);
|
w.Append(&backBtn);
|
||||||
w.Append(&createBtn);
|
w.Append(&createBtn);
|
||||||
w.Append(&chtBrowser);
|
w.Append(&chtBrowser);
|
||||||
mainWindow->SetState(STATE_DISABLED);
|
mainWindow->SetState(STATE_DISABLED);
|
||||||
mainWindow->ChangeFocus(&w);
|
mainWindow->ChangeFocus(&w);
|
||||||
mainWindow->Append(&w);
|
mainWindow->Append(&w);
|
||||||
ResumeGui();
|
ResumeGui();
|
||||||
|
|
||||||
while (!exit)
|
while (!exit)
|
||||||
{
|
{
|
||||||
VIDEO_WaitVSync();
|
VIDEO_WaitVSync();
|
||||||
|
|
||||||
ret = chtBrowser.GetClickedOption();
|
ret = chtBrowser.GetClickedOption();
|
||||||
if (ret != -1)
|
if (ret != -1)
|
||||||
{
|
{
|
||||||
const char *strCheck = cheatslst.GetName(ret);
|
const char *strCheck = cheatslst.GetName(ret);
|
||||||
if (strncmp(strCheck, "ON", 2) == 0)
|
if (strncmp(strCheck, "ON", 2) == 0)
|
||||||
{
|
{
|
||||||
cheatslst.SetName(ret, "%s", "OFF");
|
cheatslst.SetName(ret, "%s", "OFF");
|
||||||
}
|
}
|
||||||
else if (strncmp(strCheck, "OFF", 3) == 0)
|
else if (strncmp(strCheck, "OFF", 3) == 0)
|
||||||
{
|
{
|
||||||
cheatslst.SetName(ret, "%s", "ON");
|
cheatslst.SetName(ret, "%s", "ON");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (createBtn.GetState() == STATE_CLICKED)
|
if (createBtn.GetState() == STATE_CLICKED)
|
||||||
{
|
{
|
||||||
createBtn.ResetState();
|
createBtn.ResetState();
|
||||||
if (cntcheats > 0)
|
if (cntcheats > 0)
|
||||||
{
|
{
|
||||||
int selectednrs[30];
|
int selectednrs[30];
|
||||||
int x = 0;
|
int x = 0;
|
||||||
for (int i = 0; i < cntcheats; i++)
|
for (int i = 0; i < cntcheats; i++)
|
||||||
{
|
{
|
||||||
const char *strCheck = cheatslst.GetName(i);
|
const char *strCheck = cheatslst.GetName(i);
|
||||||
if (strncmp(strCheck, "ON", 2) == 0)
|
if (strncmp(strCheck, "ON", 2) == 0)
|
||||||
{
|
{
|
||||||
selectednrs[x] = i;
|
selectednrs[x] = i;
|
||||||
x++;
|
x++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (x == 0)
|
if (x == 0)
|
||||||
{
|
{
|
||||||
WindowPrompt(tr( "Error" ), tr( "No cheats were selected" ), tr( "OK" ));
|
WindowPrompt(tr( "Error" ), tr( "No cheats were selected" ), tr( "OK" ));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
CreateSubfolder(Settings.Cheatcodespath);
|
CreateSubfolder(Settings.Cheatcodespath);
|
||||||
string chtpath = Settings.Cheatcodespath;
|
string chtpath = Settings.Cheatcodespath;
|
||||||
string gctfname = chtpath + c.getGameID() + ".gct";
|
string gctfname = chtpath + c.getGameID() + ".gct";
|
||||||
c.createGCT(selectednrs, x, gctfname.c_str());
|
c.createGCT(selectednrs, x, gctfname.c_str());
|
||||||
WindowPrompt(tr( "GCT File created" ), NULL, tr( "OK" ));
|
WindowPrompt(tr( "GCT File created" ), NULL, tr( "OK" ));
|
||||||
exit = true;
|
exit = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else WindowPrompt(tr( "Error" ), tr( "Could not create GCT file" ), tr( "OK" ));
|
else WindowPrompt(tr( "Error" ), tr( "Could not create GCT file" ), tr( "OK" ));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (backBtn.GetState() == STATE_CLICKED)
|
if (backBtn.GetState() == STATE_CLICKED)
|
||||||
{
|
{
|
||||||
backBtn.ResetState();
|
backBtn.ResetState();
|
||||||
exit = true;
|
exit = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
HaltGui();
|
HaltGui();
|
||||||
mainWindow->SetState(STATE_DEFAULT);
|
mainWindow->SetState(STATE_DEFAULT);
|
||||||
mainWindow->Remove(&w);
|
mainWindow->Remove(&w);
|
||||||
ResumeGui();
|
ResumeGui();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return choice;
|
return choice;
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,267 +14,267 @@
|
||||||
|
|
||||||
GCTCheats::GCTCheats(void)
|
GCTCheats::GCTCheats(void)
|
||||||
{
|
{
|
||||||
iCntCheats = 0;
|
iCntCheats = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
GCTCheats::~GCTCheats(void)
|
GCTCheats::~GCTCheats(void)
|
||||||
{
|
{
|
||||||
|
|
||||||
string sGameID = "";
|
string sGameID = "";
|
||||||
string sGameTitle = "";
|
string sGameTitle = "";
|
||||||
/*string sCheatName[MAXCHEATS];
|
/*string sCheatName[MAXCHEATS];
|
||||||
string sCheats[MAXCHEATS];
|
string sCheats[MAXCHEATS];
|
||||||
string sCheatComment[MAXCHEATS];*/
|
string sCheatComment[MAXCHEATS];*/
|
||||||
}
|
}
|
||||||
|
|
||||||
int GCTCheats::getCnt()
|
int GCTCheats::getCnt()
|
||||||
{
|
{
|
||||||
return iCntCheats;
|
return iCntCheats;
|
||||||
}
|
}
|
||||||
|
|
||||||
string GCTCheats::getGameName(void)
|
string GCTCheats::getGameName(void)
|
||||||
{
|
{
|
||||||
return sGameTitle;
|
return sGameTitle;
|
||||||
}
|
}
|
||||||
|
|
||||||
string GCTCheats::getGameID(void)
|
string GCTCheats::getGameID(void)
|
||||||
{
|
{
|
||||||
return sGameID;
|
return sGameID;
|
||||||
}
|
}
|
||||||
|
|
||||||
string GCTCheats::getCheat(int nr)
|
string GCTCheats::getCheat(int nr)
|
||||||
{
|
{
|
||||||
if (nr <= (iCntCheats - 1))
|
if (nr <= (iCntCheats - 1))
|
||||||
{
|
{
|
||||||
return sCheats[nr];
|
return sCheats[nr];
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return ERRORRANGE;
|
return ERRORRANGE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
string GCTCheats::getCheatName(int nr)
|
string GCTCheats::getCheatName(int nr)
|
||||||
{
|
{
|
||||||
if (nr <= (iCntCheats - 1))
|
if (nr <= (iCntCheats - 1))
|
||||||
{
|
{
|
||||||
return sCheatName[nr];
|
return sCheatName[nr];
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return ERRORRANGE;
|
return ERRORRANGE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
string GCTCheats::getCheatComment(int nr)
|
string GCTCheats::getCheatComment(int nr)
|
||||||
{
|
{
|
||||||
if (nr <= (iCntCheats - 1))
|
if (nr <= (iCntCheats - 1))
|
||||||
{
|
{
|
||||||
return sCheatComment[nr];
|
return sCheatComment[nr];
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return ERRORRANGE;
|
return ERRORRANGE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int GCTCheats::createGCT(int nr, const char * filename)
|
int GCTCheats::createGCT(int nr, const char * filename)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (nr == 0) return 0;
|
if (nr == 0) return 0;
|
||||||
|
|
||||||
ofstream filestr;
|
ofstream filestr;
|
||||||
filestr.open(filename);
|
filestr.open(filename);
|
||||||
|
|
||||||
if (filestr.fail()) return 0;
|
if (filestr.fail()) return 0;
|
||||||
|
|
||||||
//Header and Footer
|
//Header and Footer
|
||||||
char header[] = { 0x00, 0xd0, 0xc0, 0xde, 0x00, 0xd0, 0xc0, 0xde };
|
char header[] = { 0x00, 0xd0, 0xc0, 0xde, 0x00, 0xd0, 0xc0, 0xde };
|
||||||
char footer[] = { 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
char footer[] = { 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
||||||
|
|
||||||
string buf = getCheat(nr);
|
string buf = getCheat(nr);
|
||||||
filestr.write(header, sizeof(header));
|
filestr.write(header, sizeof(header));
|
||||||
|
|
||||||
int x = 0;
|
int x = 0;
|
||||||
long int li;
|
long int li;
|
||||||
int len = buf.size();
|
int len = buf.size();
|
||||||
|
|
||||||
while (x < len)
|
while (x < len)
|
||||||
{
|
{
|
||||||
string temp = buf.substr(x, 2);
|
string temp = buf.substr(x, 2);
|
||||||
li = strtol(temp.c_str(), NULL, 16);
|
li = strtol(temp.c_str(), NULL, 16);
|
||||||
temp = li;
|
temp = li;
|
||||||
filestr.write(temp.c_str(), 1);
|
filestr.write(temp.c_str(), 1);
|
||||||
x += 2;
|
x += 2;
|
||||||
}
|
}
|
||||||
filestr.write(footer, sizeof(footer));
|
filestr.write(footer, sizeof(footer));
|
||||||
|
|
||||||
filestr.close();
|
filestr.close();
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int GCTCheats::createGCT(const char * chtbuffer, const char * filename)
|
int GCTCheats::createGCT(const char * chtbuffer, const char * filename)
|
||||||
{
|
{
|
||||||
|
|
||||||
ofstream filestr;
|
ofstream filestr;
|
||||||
filestr.open(filename);
|
filestr.open(filename);
|
||||||
|
|
||||||
if (filestr.fail()) return 0;
|
if (filestr.fail()) return 0;
|
||||||
|
|
||||||
//Header and Footer
|
//Header and Footer
|
||||||
char header[] = { 0x00, 0xd0, 0xc0, 0xde, 0x00, 0xd0, 0xc0, 0xde };
|
char header[] = { 0x00, 0xd0, 0xc0, 0xde, 0x00, 0xd0, 0xc0, 0xde };
|
||||||
char footer[] = { 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
char footer[] = { 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
||||||
|
|
||||||
string buf = chtbuffer;
|
string buf = chtbuffer;
|
||||||
filestr.write(header, sizeof(header));
|
filestr.write(header, sizeof(header));
|
||||||
|
|
||||||
int x = 0;
|
int x = 0;
|
||||||
long int li;
|
long int li;
|
||||||
int len = buf.size();
|
int len = buf.size();
|
||||||
|
|
||||||
while (x < len)
|
while (x < len)
|
||||||
{
|
{
|
||||||
string temp = buf.substr(x, 2);
|
string temp = buf.substr(x, 2);
|
||||||
li = strtol(temp.c_str(), NULL, 16);
|
li = strtol(temp.c_str(), NULL, 16);
|
||||||
temp = li;
|
temp = li;
|
||||||
filestr.write(temp.c_str(), 1);
|
filestr.write(temp.c_str(), 1);
|
||||||
x += 2;
|
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)
|
int GCTCheats::createGCT(int nr[], int cnt, const char * filename)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (cnt == 0) return 0;
|
if (cnt == 0) return 0;
|
||||||
|
|
||||||
ofstream filestr;
|
ofstream filestr;
|
||||||
filestr.open(filename);
|
filestr.open(filename);
|
||||||
|
|
||||||
if (filestr.fail()) return 0;
|
if (filestr.fail()) return 0;
|
||||||
|
|
||||||
//Header and Footer
|
//Header and Footer
|
||||||
char header[] = { 0x00, 0xd0, 0xc0, 0xde, 0x00, 0xd0, 0xc0, 0xde };
|
char header[] = { 0x00, 0xd0, 0xc0, 0xde, 0x00, 0xd0, 0xc0, 0xde };
|
||||||
char footer[] = { 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
char footer[] = { 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
||||||
|
|
||||||
filestr.write(header, sizeof(header));
|
filestr.write(header, sizeof(header));
|
||||||
|
|
||||||
int c = 0;
|
int c = 0;
|
||||||
while (c != cnt)
|
while (c != cnt)
|
||||||
{
|
{
|
||||||
int actnr = nr[c];
|
int actnr = nr[c];
|
||||||
string buf = getCheat(actnr);
|
string buf = getCheat(actnr);
|
||||||
long int li;
|
long int li;
|
||||||
int len = buf.size();
|
int len = buf.size();
|
||||||
int x = 0;
|
int x = 0;
|
||||||
|
|
||||||
while (x < len)
|
while (x < len)
|
||||||
{
|
{
|
||||||
string temp = buf.substr(x, 2);
|
string temp = buf.substr(x, 2);
|
||||||
li = strtol(temp.c_str(), NULL, 16);
|
li = strtol(temp.c_str(), NULL, 16);
|
||||||
temp = li;
|
temp = li;
|
||||||
filestr.write(temp.c_str(), 1);
|
filestr.write(temp.c_str(), 1);
|
||||||
x += 2;
|
x += 2;
|
||||||
}
|
}
|
||||||
c++;
|
c++;
|
||||||
}
|
}
|
||||||
|
|
||||||
filestr.write(footer, sizeof(footer));
|
filestr.write(footer, sizeof(footer));
|
||||||
filestr.close();
|
filestr.close();
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int GCTCheats::openTxtfile(const char * filename)
|
int GCTCheats::openTxtfile(const char * filename)
|
||||||
{
|
{
|
||||||
ifstream filestr;
|
ifstream filestr;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
string str;
|
string str;
|
||||||
filestr.open(filename);
|
filestr.open(filename);
|
||||||
|
|
||||||
if (filestr.fail()) return 0;
|
if (filestr.fail()) return 0;
|
||||||
|
|
||||||
filestr.seekg(0, ios_base::end);
|
filestr.seekg(0, ios_base::end);
|
||||||
int size = filestr.tellg();
|
int size = filestr.tellg();
|
||||||
if (size <= 0) return -1;
|
if (size <= 0) return -1;
|
||||||
filestr.seekg(0, ios_base::beg);
|
filestr.seekg(0, ios_base::beg);
|
||||||
|
|
||||||
getline(filestr, sGameID);
|
getline(filestr, sGameID);
|
||||||
if (sGameID[sGameID.length() - 1] == '\r') sGameID.erase(sGameID.length() - 1);
|
if (sGameID[sGameID.length() - 1] == '\r') sGameID.erase(sGameID.length() - 1);
|
||||||
|
|
||||||
getline(filestr, sGameTitle);
|
getline(filestr, sGameTitle);
|
||||||
if (sGameTitle[sGameTitle.length() - 1] == '\r') sGameTitle.erase(sGameTitle.length() - 1);
|
if (sGameTitle[sGameTitle.length() - 1] == '\r') sGameTitle.erase(sGameTitle.length() - 1);
|
||||||
|
|
||||||
getline(filestr, sCheatName[i]); // skip first line if file uses CRLF
|
getline(filestr, sCheatName[i]); // skip first line if file uses CRLF
|
||||||
if (!sGameTitle[sGameTitle.length() - 1] == '\r') filestr.seekg(0, ios_base::beg);
|
if (!sGameTitle[sGameTitle.length() - 1] == '\r') filestr.seekg(0, ios_base::beg);
|
||||||
|
|
||||||
while (!filestr.eof())
|
while (!filestr.eof())
|
||||||
{
|
{
|
||||||
getline(filestr, sCheatName[i]); // '\n' delimiter by default
|
getline(filestr, sCheatName[i]); // '\n' delimiter by default
|
||||||
if (sCheatName[i][sCheatName[i].length() - 1] == '\r') sCheatName[i].erase(sCheatName[i].length() - 1);
|
if (sCheatName[i][sCheatName[i].length() - 1] == '\r') sCheatName[i].erase(sCheatName[i].length() - 1);
|
||||||
|
|
||||||
string cheatdata;
|
string cheatdata;
|
||||||
bool emptyline = false;
|
bool emptyline = false;
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
getline(filestr, str);
|
getline(filestr, str);
|
||||||
if (str[str.length() - 1] == '\r') str.erase(str.length() - 1);
|
if (str[str.length() - 1] == '\r') str.erase(str.length() - 1);
|
||||||
|
|
||||||
if (str == "" || str[0] == '\r' || str[0] == '\n')
|
if (str == "" || str[0] == '\r' || str[0] == '\n')
|
||||||
{
|
{
|
||||||
emptyline = true;
|
emptyline = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (IsCode(str))
|
if (IsCode(str))
|
||||||
{
|
{
|
||||||
// remove any garbage (comment) after code
|
// remove any garbage (comment) after code
|
||||||
while (str.size() > 17)
|
while (str.size() > 17)
|
||||||
{
|
{
|
||||||
str.erase(str.length() - 1);
|
str.erase(str.length() - 1);
|
||||||
}
|
}
|
||||||
cheatdata.append(str);
|
cheatdata.append(str);
|
||||||
size_t found = cheatdata.find(' ');
|
size_t found = cheatdata.find(' ');
|
||||||
cheatdata.replace(found, 1, "");
|
cheatdata.replace(found, 1, "");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
//printf("%i",str.size());
|
//printf("%i",str.size());
|
||||||
sCheatComment[i] = str;
|
sCheatComment[i] = str;
|
||||||
}
|
}
|
||||||
if (filestr.eof()) break;
|
if (filestr.eof()) break;
|
||||||
|
|
||||||
} while (!emptyline);
|
} while (!emptyline);
|
||||||
|
|
||||||
sCheats[i] = cheatdata;
|
sCheats[i] = cheatdata;
|
||||||
i++;
|
i++;
|
||||||
if (i == MAXCHEATS) break;
|
if (i == MAXCHEATS) break;
|
||||||
}
|
}
|
||||||
iCntCheats = i;
|
iCntCheats = i;
|
||||||
filestr.close();
|
filestr.close();
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GCTCheats::IsCode(const std::string& str)
|
bool GCTCheats::IsCode(const std::string& str)
|
||||||
{
|
{
|
||||||
if (str[8] == ' ' && str.size() >= 17)
|
if (str[8] == ' ' && str.size() >= 17)
|
||||||
{
|
{
|
||||||
// accept strings longer than 17 in case there is a comment on the same line as the code
|
// accept strings longer than 17 in case there is a comment on the same line as the code
|
||||||
char part1[9];
|
char part1[9];
|
||||||
char part2[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],
|
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]);
|
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],
|
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]);
|
str[15], str[16]);
|
||||||
if ((strtok(part1, "0123456789ABCDEFabcdef") == NULL) && (strtok(part2, "0123456789ABCDEFabcdef") == NULL))
|
if ((strtok(part1, "0123456789ABCDEFabcdef") == NULL) && (strtok(part2, "0123456789ABCDEFabcdef") == NULL))
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,60 +16,60 @@ using namespace std;
|
||||||
//!Handles Ocarina TXT Cheatfiles
|
//!Handles Ocarina TXT Cheatfiles
|
||||||
class GCTCheats
|
class GCTCheats
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
string sGameID;
|
string sGameID;
|
||||||
string sGameTitle;
|
string sGameTitle;
|
||||||
string sCheatName[MAXCHEATS];
|
string sCheatName[MAXCHEATS];
|
||||||
string sCheats[MAXCHEATS];
|
string sCheats[MAXCHEATS];
|
||||||
string sCheatComment[MAXCHEATS];
|
string sCheatComment[MAXCHEATS];
|
||||||
int iCntCheats;
|
int iCntCheats;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
//!Constructor
|
//!Constructor
|
||||||
GCTCheats(void);
|
GCTCheats(void);
|
||||||
//!Destructor
|
//!Destructor
|
||||||
~GCTCheats(void);
|
~GCTCheats(void);
|
||||||
//!Open txt file with cheats
|
//!Open txt file with cheats
|
||||||
//!\param filename name of TXT file
|
//!\param filename name of TXT file
|
||||||
//!\return error code
|
//!\return error code
|
||||||
int openTxtfile(const char * filename);
|
int openTxtfile(const char * filename);
|
||||||
//!Creates GCT file for one cheat
|
//!Creates GCT file for one cheat
|
||||||
//!\param nr selected Cheat Numbers
|
//!\param nr selected Cheat Numbers
|
||||||
//!\param filename name of GCT file
|
//!\param filename name of GCT file
|
||||||
//!\return error code
|
//!\return error code
|
||||||
int createGCT(int nr, const char * filename);
|
int createGCT(int nr, const char * filename);
|
||||||
//!Creates GCT file from a buffer
|
//!Creates GCT file from a buffer
|
||||||
//!\param chtbuffer buffer that holds the cheat data
|
//!\param chtbuffer buffer that holds the cheat data
|
||||||
//!\param filename name of GCT file
|
//!\param filename name of GCT file
|
||||||
//!\return error code
|
//!\return error code
|
||||||
int createGCT(const char * chtbuffer, const char * filename);
|
int createGCT(const char * chtbuffer, const char * filename);
|
||||||
//!Creates GCT file
|
//!Creates GCT file
|
||||||
//!\param nr[] array of selected Cheat Numbers
|
//!\param nr[] array of selected Cheat Numbers
|
||||||
//!\param cnt size of array
|
//!\param cnt size of array
|
||||||
//!\param filename name of GCT file
|
//!\param filename name of GCT file
|
||||||
//!\return error code
|
//!\return error code
|
||||||
int createGCT(int nr[], int cnt, const char * filename);
|
int createGCT(int nr[], int cnt, const char * filename);
|
||||||
//!Gets Count cheats
|
//!Gets Count cheats
|
||||||
//!\return Count cheats
|
//!\return Count cheats
|
||||||
int getCnt();
|
int getCnt();
|
||||||
//!Gets Game Name
|
//!Gets Game Name
|
||||||
//!\return Game Name
|
//!\return Game Name
|
||||||
string getGameName(void);
|
string getGameName(void);
|
||||||
//!Gets GameID
|
//!Gets GameID
|
||||||
//!\return GameID
|
//!\return GameID
|
||||||
string getGameID(void);
|
string getGameID(void);
|
||||||
//!Gets cheat data
|
//!Gets cheat data
|
||||||
//!\return cheat data
|
//!\return cheat data
|
||||||
string getCheat(int nr);
|
string getCheat(int nr);
|
||||||
//!Gets Cheat Name
|
//!Gets Cheat Name
|
||||||
//!\return Cheat Name
|
//!\return Cheat Name
|
||||||
string getCheatName(int nr);
|
string getCheatName(int nr);
|
||||||
//!Gets Cheat Comment
|
//!Gets Cheat Comment
|
||||||
//!\return Cheat Comment
|
//!\return Cheat Comment
|
||||||
string getCheatComment(int nr);
|
string getCheatComment(int nr);
|
||||||
//!Check if string is a code
|
//!Check if string is a code
|
||||||
//!\return true/false
|
//!\return true/false
|
||||||
bool IsCode(const std::string& s);
|
bool IsCode(const std::string& s);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* _GCT_H */
|
#endif /* _GCT_H */
|
||||||
|
|
|
@ -13,78 +13,78 @@ static bool geckoinit = false;
|
||||||
void gprintf(const char *format, ...)
|
void gprintf(const char *format, ...)
|
||||||
{
|
{
|
||||||
if (!geckoinit)
|
if (!geckoinit)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
char * tmp = NULL;
|
char * tmp = NULL;
|
||||||
va_list va;
|
va_list va;
|
||||||
va_start(va, format);
|
va_start(va, format);
|
||||||
if((vasprintf(&tmp, format, va) >= 0) && tmp)
|
if((vasprintf(&tmp, format, va) >= 0) && tmp)
|
||||||
{
|
{
|
||||||
usb_sendbuffer(1, tmp, strlen(tmp));
|
usb_sendbuffer(1, tmp, strlen(tmp));
|
||||||
#ifdef DEBUG_TO_FILE
|
#ifdef DEBUG_TO_FILE
|
||||||
FILE *debugF = fopen("sd:/debug.txt", "a");
|
FILE *debugF = fopen("sd:/debug.txt", "a");
|
||||||
if(!debugF)
|
if(!debugF)
|
||||||
debugF = fopen("sd:/debug.txt", "w");
|
debugF = fopen("sd:/debug.txt", "w");
|
||||||
if(debugF)
|
if(debugF)
|
||||||
fprintf(debugF, tmp);
|
fprintf(debugF, tmp);
|
||||||
fclose(debugF);
|
fclose(debugF);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
va_end(va);
|
va_end(va);
|
||||||
|
|
||||||
if(tmp)
|
if(tmp)
|
||||||
free(tmp);
|
free(tmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool InitGecko()
|
bool InitGecko()
|
||||||
{
|
{
|
||||||
u32 geckoattached = usb_isgeckoalive(EXI_CHANNEL_1);
|
u32 geckoattached = usb_isgeckoalive(EXI_CHANNEL_1);
|
||||||
if (geckoattached)
|
if (geckoattached)
|
||||||
{
|
{
|
||||||
usb_flush(EXI_CHANNEL_1);
|
usb_flush(EXI_CHANNEL_1);
|
||||||
geckoinit = true;
|
geckoinit = true;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
char ascii(char s)
|
char ascii(char s)
|
||||||
{
|
{
|
||||||
if (s < 0x20) return '.';
|
if (s < 0x20) return '.';
|
||||||
if (s > 0x7E) return '.';
|
if (s > 0x7E) return '.';
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
void hexdump(void *d, int len)
|
void hexdump(void *d, int len)
|
||||||
{
|
{
|
||||||
u8 *data;
|
u8 *data;
|
||||||
int i, off;
|
int i, off;
|
||||||
data = (u8*) d;
|
data = (u8*) d;
|
||||||
|
|
||||||
gprintf("\n 0 1 2 3 4 5 6 7 8 9 A B C D E F 0123456789ABCDEF");
|
gprintf("\n 0 1 2 3 4 5 6 7 8 9 A B C D E F 0123456789ABCDEF");
|
||||||
gprintf("\n==== =============================================== ================\n");
|
gprintf("\n==== =============================================== ================\n");
|
||||||
|
|
||||||
for (off = 0; off < len; off += 16)
|
for (off = 0; off < len; off += 16)
|
||||||
{
|
{
|
||||||
gprintf("%04x ", off);
|
gprintf("%04x ", off);
|
||||||
for (i = 0; i < 16; i++)
|
for (i = 0; i < 16; i++)
|
||||||
if ((i + off) >= len)
|
if ((i + off) >= len)
|
||||||
gprintf(" ");
|
gprintf(" ");
|
||||||
else gprintf("%02x ", data[off + i]);
|
else gprintf("%02x ", data[off + i]);
|
||||||
|
|
||||||
gprintf(" ");
|
gprintf(" ");
|
||||||
for (i = 0; i < 16; i++)
|
for (i = 0; i < 16; i++)
|
||||||
if ((i + off) >= len)
|
if ((i + off) >= len)
|
||||||
gprintf(" ");
|
gprintf(" ");
|
||||||
else gprintf("%c", ascii(data[off + i]));
|
else gprintf("%c", ascii(data[off + i]));
|
||||||
gprintf("\n");
|
gprintf("\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static ssize_t __out_write(struct _reent *r, int fd, const char *ptr, size_t len)
|
static ssize_t __out_write(struct _reent *r, int fd, const char *ptr, size_t len)
|
||||||
{
|
{
|
||||||
gprintf(ptr);
|
gprintf(ptr);
|
||||||
|
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,17 +7,17 @@ extern "C"
|
||||||
{
|
{
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
char ascii(char s);
|
char ascii(char s);
|
||||||
|
|
||||||
#ifndef NO_DEBUG
|
#ifndef NO_DEBUG
|
||||||
//use this just like printf();
|
//use this just like printf();
|
||||||
void gprintf(const char *str, ...);
|
void gprintf(const char *str, ...);
|
||||||
bool InitGecko();
|
bool InitGecko();
|
||||||
void hexdump(void *d, int len);
|
void hexdump(void *d, int len);
|
||||||
void USBGeckoOutput();
|
void USBGeckoOutput();
|
||||||
#else
|
#else
|
||||||
#define gprintf(...)
|
#define gprintf(...)
|
||||||
#define InitGecko() false
|
#define InitGecko() false
|
||||||
#define hexdump( x, y )
|
#define hexdump( x, y )
|
||||||
#endif /* NO_DEBUG */
|
#endif /* NO_DEBUG */
|
||||||
|
|
||||||
|
|
|
@ -30,84 +30,84 @@ static std::vector<std::string> Arguments;
|
||||||
|
|
||||||
void AddBootArgument(const char * argv)
|
void AddBootArgument(const char * argv)
|
||||||
{
|
{
|
||||||
std::string arg(argv);
|
std::string arg(argv);
|
||||||
Arguments.push_back(arg);
|
Arguments.push_back(arg);
|
||||||
}
|
}
|
||||||
|
|
||||||
int CopyHomebrewMemory(u8 *temp, u32 pos, u32 len)
|
int CopyHomebrewMemory(u8 *temp, u32 pos, u32 len)
|
||||||
{
|
{
|
||||||
homebrewsize += len;
|
homebrewsize += len;
|
||||||
memcpy((homebrewbuffer) + pos, temp, len);
|
memcpy((homebrewbuffer) + pos, temp, len);
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void FreeHomebrewBuffer()
|
void FreeHomebrewBuffer()
|
||||||
{
|
{
|
||||||
homebrewbuffer = EXECUTE_ADDR;
|
homebrewbuffer = EXECUTE_ADDR;
|
||||||
homebrewsize = 0;
|
homebrewsize = 0;
|
||||||
|
|
||||||
Arguments.clear();
|
Arguments.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
static int SetupARGV(struct __argv * args)
|
static int SetupARGV(struct __argv * args)
|
||||||
{
|
{
|
||||||
if (!args) return -1;
|
if (!args) return -1;
|
||||||
|
|
||||||
bzero(args, sizeof(struct __argv));
|
bzero(args, sizeof(struct __argv));
|
||||||
args->argvMagic = ARGV_MAGIC;
|
args->argvMagic = ARGV_MAGIC;
|
||||||
|
|
||||||
u32 argc = 0;
|
u32 argc = 0;
|
||||||
u32 position = 0;
|
u32 position = 0;
|
||||||
u32 stringlength = 1;
|
u32 stringlength = 1;
|
||||||
|
|
||||||
/** Append Arguments **/
|
/** Append Arguments **/
|
||||||
for (u32 i = 0; i < Arguments.size(); i++)
|
for (u32 i = 0; i < Arguments.size(); i++)
|
||||||
{
|
{
|
||||||
stringlength += Arguments[i].size() + 1;
|
stringlength += Arguments[i].size() + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
args->length = stringlength;
|
args->length = stringlength;
|
||||||
//! Put the argument into mem2 too, to avoid overwriting it
|
//! 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 **/
|
/** Append Arguments **/
|
||||||
for (u32 i = 0; i < Arguments.size(); i++)
|
for (u32 i = 0; i < Arguments.size(); i++)
|
||||||
{
|
{
|
||||||
strcpy(&args->commandLine[position], Arguments[i].c_str());
|
strcpy(&args->commandLine[position], Arguments[i].c_str());
|
||||||
position += Arguments[i].size() + 1;
|
position += Arguments[i].size() + 1;
|
||||||
argc++;
|
argc++;
|
||||||
}
|
}
|
||||||
|
|
||||||
args->argc = argc;
|
args->argc = argc;
|
||||||
|
|
||||||
args->commandLine[args->length - 1] = '\0';
|
args->commandLine[args->length - 1] = '\0';
|
||||||
args->argv = &args->commandLine;
|
args->argv = &args->commandLine;
|
||||||
args->endARGV = args->argv + 1;
|
args->endARGV = args->argv + 1;
|
||||||
|
|
||||||
Arguments.clear();
|
Arguments.clear();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int RunAppbooter()
|
static int RunAppbooter()
|
||||||
{
|
{
|
||||||
if (homebrewsize == 0) return -1;
|
if (homebrewsize == 0) return -1;
|
||||||
|
|
||||||
ExitApp();
|
ExitApp();
|
||||||
|
|
||||||
if(Settings.EntryIOS != IOS_GetVersion())
|
if(Settings.EntryIOS != IOS_GetVersion())
|
||||||
IOS_ReloadIOS(Settings.EntryIOS);
|
IOS_ReloadIOS(Settings.EntryIOS);
|
||||||
|
|
||||||
struct __argv args;
|
struct __argv args;
|
||||||
SetupARGV(&args);
|
SetupARGV(&args);
|
||||||
|
|
||||||
u32 cpu_isr;
|
u32 cpu_isr;
|
||||||
|
|
||||||
memcpy(BOOTER_ADDR, app_booter_bin, app_booter_bin_size);
|
memcpy(BOOTER_ADDR, app_booter_bin, app_booter_bin_size);
|
||||||
DCFlushRange(BOOTER_ADDR, 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)
|
if (args.argvMagic == ARGV_MAGIC)
|
||||||
{
|
{
|
||||||
|
@ -115,66 +115,66 @@ static int RunAppbooter()
|
||||||
DCFlushRange(ARGS_ADDR, sizeof(args) + args.length);
|
DCFlushRange(ARGS_ADDR, sizeof(args) + args.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
u64 currentStub = getStubDest();
|
u64 currentStub = getStubDest();
|
||||||
loadStub();
|
loadStub();
|
||||||
|
|
||||||
if (Set_Stub_Split(0x00010001, "UNEO") < 0)
|
if (Set_Stub_Split(0x00010001, "UNEO") < 0)
|
||||||
{
|
{
|
||||||
if (Set_Stub_Split(0x00010001, "ULNR") < 0)
|
if (Set_Stub_Split(0x00010001, "ULNR") < 0)
|
||||||
{
|
{
|
||||||
if (!currentStub) currentStub = 0x100000002ULL;
|
if (!currentStub) currentStub = 0x100000002ULL;
|
||||||
|
|
||||||
Set_Stub(currentStub);
|
Set_Stub(currentStub);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SYS_ResetSystem(SYS_SHUTDOWN, 0, 0);
|
SYS_ResetSystem(SYS_SHUTDOWN, 0, 0);
|
||||||
_CPU_ISR_Disable( cpu_isr );
|
_CPU_ISR_Disable( cpu_isr );
|
||||||
__exception_closeall();
|
__exception_closeall();
|
||||||
entry();
|
entry();
|
||||||
_CPU_ISR_Restore( cpu_isr );
|
_CPU_ISR_Restore( cpu_isr );
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int BootHomebrew(const char * filepath)
|
int BootHomebrew(const char * filepath)
|
||||||
{
|
{
|
||||||
void *buffer = NULL;
|
void *buffer = NULL;
|
||||||
u32 filesize = 0;
|
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);
|
fseek(file, 0, SEEK_END);
|
||||||
filesize = ftell(file);
|
filesize = ftell(file);
|
||||||
rewind(file);
|
rewind(file);
|
||||||
|
|
||||||
buffer = malloc(filesize);
|
buffer = malloc(filesize);
|
||||||
|
|
||||||
if (fread(buffer, 1, filesize, file) != filesize)
|
if (fread(buffer, 1, filesize, file) != filesize)
|
||||||
{
|
{
|
||||||
fclose(file);
|
fclose(file);
|
||||||
free(buffer);
|
free(buffer);
|
||||||
DeviceHandler::DestroyInstance();
|
DeviceHandler::DestroyInstance();
|
||||||
Sys_BackToLoader();
|
Sys_BackToLoader();
|
||||||
}
|
}
|
||||||
|
|
||||||
fclose(file);
|
fclose(file);
|
||||||
|
|
||||||
CopyHomebrewMemory((u8*) buffer, 0, filesize);
|
CopyHomebrewMemory((u8*) buffer, 0, filesize);
|
||||||
|
|
||||||
if (buffer)
|
if (buffer)
|
||||||
{
|
{
|
||||||
free(buffer);
|
free(buffer);
|
||||||
buffer = NULL;
|
buffer = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
AddBootArgument(filepath);
|
AddBootArgument(filepath);
|
||||||
return RunAppbooter();
|
return RunAppbooter();
|
||||||
}
|
}
|
||||||
|
|
||||||
int BootHomebrewFromMem()
|
int BootHomebrewFromMem()
|
||||||
{
|
{
|
||||||
return RunAppbooter();
|
return RunAppbooter();
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,423 +42,423 @@ extern char wiiloadVersion[2];
|
||||||
extern int connection;
|
extern int connection;
|
||||||
|
|
||||||
HomebrewBrowser::HomebrewBrowser()
|
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())
|
if (IsNetworkInit())
|
||||||
ResumeNetworkWait();
|
ResumeNetworkWait();
|
||||||
|
|
||||||
wifiNotSet = true;
|
wifiNotSet = true;
|
||||||
wifiImgData = Resources::GetImageData("wifi_btn.png");
|
wifiImgData = Resources::GetImageData("wifi_btn.png");
|
||||||
wifiToolTip = new GuiTooltip(" ");
|
wifiToolTip = new GuiTooltip(" ");
|
||||||
wifiImg = new GuiImage(wifiImgData);
|
wifiImg = new GuiImage(wifiImgData);
|
||||||
wifiBtn = new GuiButton(wifiImgData->GetWidth(), wifiImgData->GetHeight());
|
wifiBtn = new GuiButton(wifiImgData->GetWidth(), wifiImgData->GetHeight());
|
||||||
wifiBtn->SetImage(wifiImg);
|
wifiBtn->SetImage(wifiImg);
|
||||||
wifiBtn->SetPosition(300, 400);
|
wifiBtn->SetPosition(300, 400);
|
||||||
wifiBtn->SetSoundOver(btnSoundOver);
|
wifiBtn->SetSoundOver(btnSoundOver);
|
||||||
wifiBtn->SetSoundClick(btnSoundClick);
|
wifiBtn->SetSoundClick(btnSoundClick);
|
||||||
wifiBtn->SetEffectGrow();
|
wifiBtn->SetEffectGrow();
|
||||||
wifiBtn->SetAlpha(80);
|
wifiBtn->SetAlpha(80);
|
||||||
wifiBtn->SetTrigger(trigA);
|
wifiBtn->SetTrigger(trigA);
|
||||||
Append(wifiBtn);
|
Append(wifiBtn);
|
||||||
|
|
||||||
channelImgData = Resources::GetImageData("channel_btn.png");
|
channelImgData = Resources::GetImageData("channel_btn.png");
|
||||||
channelBtnImg = new GuiImage(channelImgData);
|
channelBtnImg = new GuiImage(channelImgData);
|
||||||
channelBtnImg->SetWidescreen(Settings.widescreen);
|
channelBtnImg->SetWidescreen(Settings.widescreen);
|
||||||
channelBtn = new GuiButton(channelBtnImg->GetWidth(), channelBtnImg->GetHeight());
|
channelBtn = new GuiButton(channelBtnImg->GetWidth(), channelBtnImg->GetHeight());
|
||||||
channelBtn->SetPosition(240, 400);
|
channelBtn->SetPosition(240, 400);
|
||||||
channelBtn->SetImage(channelBtnImg);
|
channelBtn->SetImage(channelBtnImg);
|
||||||
channelBtn->SetSoundOver(btnSoundOver);
|
channelBtn->SetSoundOver(btnSoundOver);
|
||||||
channelBtn->SetSoundClick(btnSoundClick2);
|
channelBtn->SetSoundClick(btnSoundClick2);
|
||||||
channelBtn->SetEffectGrow();
|
channelBtn->SetEffectGrow();
|
||||||
channelBtn->SetTrigger(trigA);
|
channelBtn->SetTrigger(trigA);
|
||||||
if (Settings.godmode || !(Settings.ParentalBlocks & BLOCK_TITLE_LAUNCHER_MENU))
|
if (Settings.godmode || !(Settings.ParentalBlocks & BLOCK_TITLE_LAUNCHER_MENU))
|
||||||
Append(channelBtn);
|
Append(channelBtn);
|
||||||
|
|
||||||
MainButtonDesc.resize(HomebrewList->GetFilecount());
|
MainButtonDesc.resize(HomebrewList->GetFilecount());
|
||||||
MainButtonDescOver.resize(HomebrewList->GetFilecount());
|
MainButtonDescOver.resize(HomebrewList->GetFilecount());
|
||||||
|
|
||||||
for(u32 i = 0; i < 4; ++i)
|
for(u32 i = 0; i < 4; ++i)
|
||||||
{
|
{
|
||||||
IconImgData[i] = NULL;
|
IconImgData[i] = NULL;
|
||||||
IconImg[i] = NULL;
|
IconImg[i] = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
for(int i = 0; i < HomebrewList->GetFilecount(); ++i)
|
for(int i = 0; i < HomebrewList->GetFilecount(); ++i)
|
||||||
{
|
{
|
||||||
MainButtonDesc[i] = new GuiText((char *) NULL, 18, (GXColor) {0, 0, 0, 255});
|
MainButtonDesc[i] = new GuiText((char *) NULL, 18, (GXColor) {0, 0, 0, 255});
|
||||||
MainButtonDesc[i]->SetMaxWidth(MainButtonImgData->GetWidth() - 150, DOTTED);
|
MainButtonDesc[i]->SetMaxWidth(MainButtonImgData->GetWidth() - 150, DOTTED);
|
||||||
MainButtonDesc[i]->SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE);
|
MainButtonDesc[i]->SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE);
|
||||||
MainButtonDesc[i]->SetPosition(148, 15);
|
MainButtonDesc[i]->SetPosition(148, 15);
|
||||||
|
|
||||||
MainButtonDescOver[i] = new GuiText((char *) NULL, 18, (GXColor) {0, 0, 0, 255});
|
MainButtonDescOver[i] = new GuiText((char *) NULL, 18, (GXColor) {0, 0, 0, 255});
|
||||||
MainButtonDescOver[i]->SetMaxWidth(MainButtonImgData->GetWidth() - 150, SCROLL_HORIZONTAL);
|
MainButtonDescOver[i]->SetMaxWidth(MainButtonImgData->GetWidth() - 150, SCROLL_HORIZONTAL);
|
||||||
MainButtonDescOver[i]->SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE);
|
MainButtonDescOver[i]->SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE);
|
||||||
MainButtonDescOver[i]->SetPosition(148, 15);
|
MainButtonDescOver[i]->SetPosition(148, 15);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
HomebrewBrowser::~HomebrewBrowser()
|
HomebrewBrowser::~HomebrewBrowser()
|
||||||
{
|
{
|
||||||
HaltGui();
|
HaltGui();
|
||||||
delete HomebrewList;
|
delete HomebrewList;
|
||||||
|
|
||||||
Remove(wifiBtn);
|
Remove(wifiBtn);
|
||||||
delete wifiImgData;
|
delete wifiImgData;
|
||||||
delete wifiImg;
|
delete wifiImg;
|
||||||
delete wifiToolTip;
|
delete wifiToolTip;
|
||||||
delete wifiBtn;
|
delete wifiBtn;
|
||||||
|
|
||||||
Remove(channelBtn);
|
Remove(channelBtn);
|
||||||
delete channelImgData;
|
delete channelImgData;
|
||||||
delete channelBtnImg;
|
delete channelBtnImg;
|
||||||
delete channelBtn;
|
delete channelBtn;
|
||||||
|
|
||||||
for(u32 i = 0; i < MainButtonDesc.size(); ++i)
|
for(u32 i = 0; i < MainButtonDesc.size(); ++i)
|
||||||
{
|
{
|
||||||
delete MainButtonDesc[i];
|
delete MainButtonDesc[i];
|
||||||
delete MainButtonDescOver[i];
|
delete MainButtonDescOver[i];
|
||||||
MainButton[i]->SetLabel(NULL, 1);
|
MainButton[i]->SetLabel(NULL, 1);
|
||||||
MainButton[i]->SetLabelOver(NULL, 1);
|
MainButton[i]->SetLabelOver(NULL, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (IsNetworkInit())
|
if (IsNetworkInit())
|
||||||
HaltNetworkThread();
|
HaltNetworkThread();
|
||||||
}
|
}
|
||||||
|
|
||||||
int HomebrewBrowser::Execute()
|
int HomebrewBrowser::Execute()
|
||||||
{
|
{
|
||||||
HomebrewBrowser * Menu = new HomebrewBrowser();
|
HomebrewBrowser * Menu = new HomebrewBrowser();
|
||||||
mainWindow->Append(Menu);
|
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()
|
void HomebrewBrowser::AddMainButtons()
|
||||||
{
|
{
|
||||||
HaltGui();
|
HaltGui();
|
||||||
|
|
||||||
for(u32 i = 0; i < 4; ++i)
|
for(u32 i = 0; i < 4; ++i)
|
||||||
{
|
{
|
||||||
if(IconImgData[i])
|
if(IconImgData[i])
|
||||||
delete IconImgData[i];
|
delete IconImgData[i];
|
||||||
if(IconImg[i])
|
if(IconImg[i])
|
||||||
delete IconImg[i];
|
delete IconImg[i];
|
||||||
IconImgData[i] = NULL;
|
IconImgData[i] = NULL;
|
||||||
IconImg[i] = NULL;
|
IconImg[i] = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
for(u32 i = 0; i < MainButton.size(); ++i)
|
for(u32 i = 0; i < MainButton.size(); ++i)
|
||||||
MainButton[i]->SetIcon(NULL);
|
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)
|
for(int i = FirstItem, n = 0; i < (int) MainButton.size() && i < FirstItem+DISPLAY_BUTTONS; ++i, ++n)
|
||||||
{
|
{
|
||||||
std::string iconpath = HomebrewList->GetFilepath(i);
|
std::string iconpath = HomebrewList->GetFilepath(i);
|
||||||
size_t pos = iconpath.rfind('/');
|
size_t pos = iconpath.rfind('/');
|
||||||
if(pos != std::string::npos && pos < iconpath.size()-1)
|
if(pos != std::string::npos && pos < iconpath.size()-1)
|
||||||
iconpath.erase(pos+1);
|
iconpath.erase(pos+1);
|
||||||
iconpath += "icon.png";
|
iconpath += "icon.png";
|
||||||
|
|
||||||
IconImgData[n] = new GuiImageData(iconpath.c_str());
|
IconImgData[n] = new GuiImageData(iconpath.c_str());
|
||||||
IconImg[n] = new GuiImage(IconImgData[n]);
|
IconImg[n] = new GuiImage(IconImgData[n]);
|
||||||
IconImg[n]->SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE);
|
IconImg[n]->SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE);
|
||||||
IconImg[n]->SetPosition(12, 0);
|
IconImg[n]->SetPosition(12, 0);
|
||||||
IconImg[n]->SetScale(0.95);
|
IconImg[n]->SetScale(0.95);
|
||||||
MainButton[i]->SetIcon(IconImg[n]);
|
MainButton[i]->SetIcon(IconImg[n]);
|
||||||
}
|
}
|
||||||
|
|
||||||
FlyingButtonsMenu::AddMainButtons();
|
FlyingButtonsMenu::AddMainButtons();
|
||||||
}
|
}
|
||||||
|
|
||||||
void HomebrewBrowser::SetupMainButtons()
|
void HomebrewBrowser::SetupMainButtons()
|
||||||
{
|
{
|
||||||
HomebrewXML MetaXML;
|
HomebrewXML MetaXML;
|
||||||
|
|
||||||
for(int i = 0; i < HomebrewList->GetFilecount(); ++i)
|
for(int i = 0; i < HomebrewList->GetFilecount(); ++i)
|
||||||
{
|
{
|
||||||
const char * HomebrewName = NULL;
|
const char * HomebrewName = NULL;
|
||||||
std::string metapath = HomebrewList->GetFilepath(i);
|
std::string metapath = HomebrewList->GetFilepath(i);
|
||||||
size_t pos = metapath.rfind('/');
|
size_t pos = metapath.rfind('/');
|
||||||
if(pos != std::string::npos && pos < metapath.size()-1)
|
if(pos != std::string::npos && pos < metapath.size()-1)
|
||||||
metapath.erase(pos+1);
|
metapath.erase(pos+1);
|
||||||
metapath += "meta.xml";
|
metapath += "meta.xml";
|
||||||
|
|
||||||
if (MetaXML.LoadHomebrewXMLData(metapath.c_str()) > 0)
|
if (MetaXML.LoadHomebrewXMLData(metapath.c_str()) > 0)
|
||||||
{
|
{
|
||||||
HomebrewName = MetaXML.GetName();
|
HomebrewName = MetaXML.GetName();
|
||||||
MainButtonDesc[i]->SetText(MetaXML.GetShortDescription());
|
MainButtonDesc[i]->SetText(MetaXML.GetShortDescription());
|
||||||
MainButtonDescOver[i]->SetText(MetaXML.GetShortDescription());
|
MainButtonDescOver[i]->SetText(MetaXML.GetShortDescription());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
const char * shortpath = HomebrewList->GetFilepath(i);
|
const char * shortpath = HomebrewList->GetFilepath(i);
|
||||||
const char * ptr = shortpath;
|
const char * ptr = shortpath;
|
||||||
const char * ptr2 = NULL;
|
const char * ptr2 = NULL;
|
||||||
while(*ptr != '\0')
|
while(*ptr != '\0')
|
||||||
{
|
{
|
||||||
if(*ptr == '/')
|
if(*ptr == '/')
|
||||||
{
|
{
|
||||||
shortpath = ptr2;
|
shortpath = ptr2;
|
||||||
ptr2 = ptr;
|
ptr2 = ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
++ptr;
|
++ptr;
|
||||||
}
|
}
|
||||||
if(!shortpath && ptr2)
|
if(!shortpath && ptr2)
|
||||||
shortpath = ptr2;
|
shortpath = ptr2;
|
||||||
else if(!shortpath)
|
else if(!shortpath)
|
||||||
shortpath = HomebrewList->GetFilename(i);
|
shortpath = HomebrewList->GetFilename(i);
|
||||||
|
|
||||||
HomebrewName = shortpath;
|
HomebrewName = shortpath;
|
||||||
MainButtonDesc[i]->SetText(" ");
|
MainButtonDesc[i]->SetText(" ");
|
||||||
MainButtonDescOver[i]->SetText(" ");
|
MainButtonDescOver[i]->SetText(" ");
|
||||||
}
|
}
|
||||||
|
|
||||||
SetMainButton(i, HomebrewName, MainButtonImgData, MainButtonImgOverData);
|
SetMainButton(i, HomebrewName, MainButtonImgData, MainButtonImgOverData);
|
||||||
|
|
||||||
MainButtonTxt[i]->SetFontSize(18);
|
MainButtonTxt[i]->SetFontSize(18);
|
||||||
MainButtonTxt[i]->SetMaxWidth(MainButtonImgData->GetWidth() - 150, DOTTED);
|
MainButtonTxt[i]->SetMaxWidth(MainButtonImgData->GetWidth() - 150, DOTTED);
|
||||||
MainButtonTxt[i]->SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE);
|
MainButtonTxt[i]->SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE);
|
||||||
MainButtonTxt[i]->SetPosition(148, -12);
|
MainButtonTxt[i]->SetPosition(148, -12);
|
||||||
MainButton[i]->SetLabel(MainButtonDesc[i], 1);
|
MainButton[i]->SetLabel(MainButtonDesc[i], 1);
|
||||||
MainButton[i]->SetLabelOver(MainButtonDescOver[i], 1);
|
MainButton[i]->SetLabelOver(MainButtonDescOver[i], 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int HomebrewBrowser::MainLoop()
|
int HomebrewBrowser::MainLoop()
|
||||||
{
|
{
|
||||||
if (IsNetworkInit() && wifiNotSet)
|
if (IsNetworkInit() && wifiNotSet)
|
||||||
{
|
{
|
||||||
wifiToolTip->SetText(GetNetworkIP());
|
wifiToolTip->SetText(GetNetworkIP());
|
||||||
wifiBtn->SetAlpha(255);
|
wifiBtn->SetAlpha(255);
|
||||||
wifiBtn->SetToolTip(wifiToolTip, 0, -50, 0, 5);
|
wifiBtn->SetToolTip(wifiToolTip, 0, -50, 0, 5);
|
||||||
wifiNotSet = false;
|
wifiNotSet = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(wifiBtn->GetState() == STATE_CLICKED)
|
if(wifiBtn->GetState() == STATE_CLICKED)
|
||||||
{
|
{
|
||||||
ResumeNetworkWait();
|
ResumeNetworkWait();
|
||||||
wifiBtn->ResetState();
|
wifiBtn->ResetState();
|
||||||
}
|
}
|
||||||
else if(channelBtn->GetState() == STATE_CLICKED)
|
else if(channelBtn->GetState() == STATE_CLICKED)
|
||||||
{
|
{
|
||||||
SetState(STATE_DISABLED);
|
SetState(STATE_DISABLED);
|
||||||
TitleBrowser();
|
TitleBrowser();
|
||||||
SetState(STATE_DEFAULT);
|
SetState(STATE_DEFAULT);
|
||||||
channelBtn->ResetState();
|
channelBtn->ResetState();
|
||||||
}
|
}
|
||||||
else if (infilesize > 0)
|
else if (infilesize > 0)
|
||||||
{
|
{
|
||||||
int menu = ReceiveFile();
|
int menu = ReceiveFile();
|
||||||
if(menu != MENU_NONE)
|
if(menu != MENU_NONE)
|
||||||
return menu;
|
return menu;
|
||||||
CloseConnection();
|
CloseConnection();
|
||||||
ResumeNetworkWait();
|
ResumeNetworkWait();
|
||||||
}
|
}
|
||||||
|
|
||||||
return FlyingButtonsMenu::MainLoop();
|
return FlyingButtonsMenu::MainLoop();
|
||||||
}
|
}
|
||||||
|
|
||||||
//! Callback for MainButton clicked
|
//! Callback for MainButton clicked
|
||||||
void HomebrewBrowser::MainButtonClicked(int button)
|
void HomebrewBrowser::MainButtonClicked(int button)
|
||||||
{
|
{
|
||||||
HomebrewXML MetaXML;
|
HomebrewXML MetaXML;
|
||||||
std::string metapath = HomebrewList->GetFilepath(button);
|
std::string metapath = HomebrewList->GetFilepath(button);
|
||||||
size_t pos = metapath.rfind('/');
|
size_t pos = metapath.rfind('/');
|
||||||
if(pos != std::string::npos && pos < metapath.size()-1)
|
if(pos != std::string::npos && pos < metapath.size()-1)
|
||||||
metapath.erase(pos+1);
|
metapath.erase(pos+1);
|
||||||
metapath += "meta.xml";
|
metapath += "meta.xml";
|
||||||
MetaXML.LoadHomebrewXMLData(metapath.c_str());
|
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(),
|
HomebrewPrompt *HBCWindowPrompt = new HomebrewPrompt(HomebrewName.toUTF8().c_str(), MetaXML.GetCoder(), MetaXML.GetVersion(),
|
||||||
MetaXML.GetReleasedate(), MetaXML.GetLongDescription(), IconImgData[button % 4], filesize);
|
MetaXML.GetReleasedate(), MetaXML.GetLongDescription(), IconImgData[button % 4], filesize);
|
||||||
|
|
||||||
mainWindow->SetState(STATE_DISABLED);
|
mainWindow->SetState(STATE_DISABLED);
|
||||||
mainWindow->Append(HBCWindowPrompt);
|
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)
|
if (choice == 1)
|
||||||
{
|
{
|
||||||
u8 *buffer = NULL;
|
u8 *buffer = NULL;
|
||||||
u64 filesize = 0;
|
u64 filesize = 0;
|
||||||
LoadFileToMem(HomebrewList->GetFilepath(button), &buffer, &filesize);
|
LoadFileToMem(HomebrewList->GetFilepath(button), &buffer, &filesize);
|
||||||
if(!buffer)
|
if(!buffer)
|
||||||
{
|
{
|
||||||
WindowPrompt(tr("Error"), tr("Not enough memory."), tr("OK"));
|
WindowPrompt(tr("Error"), tr("Not enough memory."), tr("OK"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
FreeHomebrewBuffer();
|
FreeHomebrewBuffer();
|
||||||
CopyHomebrewMemory(buffer, 0, filesize);
|
CopyHomebrewMemory(buffer, 0, filesize);
|
||||||
|
|
||||||
AddBootArgument(HomebrewList->GetFilepath(button));
|
AddBootArgument(HomebrewList->GetFilepath(button));
|
||||||
|
|
||||||
for(u32 i = 0; i < MetaXML.GetArguments().size(); ++i)
|
for(u32 i = 0; i < MetaXML.GetArguments().size(); ++i)
|
||||||
{
|
{
|
||||||
AddBootArgument(MetaXML.GetArguments().at(i).c_str());
|
AddBootArgument(MetaXML.GetArguments().at(i).c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
BootHomebrewFromMem();
|
BootHomebrewFromMem();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int HomebrewBrowser::ReceiveFile()
|
int HomebrewBrowser::ReceiveFile()
|
||||||
{
|
{
|
||||||
char filesizetxt[50];
|
char filesizetxt[50];
|
||||||
char temp[50];
|
char temp[50];
|
||||||
u32 filesize = 0;
|
u32 filesize = 0;
|
||||||
|
|
||||||
if (infilesize < MB_SIZE)
|
if (infilesize < MB_SIZE)
|
||||||
snprintf(filesizetxt, sizeof(filesizetxt), tr( "Incoming file %0.2fKB" ), infilesize / KB_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);
|
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)
|
if (choice == 0)
|
||||||
return MENU_NONE;
|
return MENU_NONE;
|
||||||
|
|
||||||
u32 read = 0;
|
u32 read = 0;
|
||||||
int len = NETWORKBLOCKSIZE;
|
int len = NETWORKBLOCKSIZE;
|
||||||
filesize = infilesize;
|
filesize = infilesize;
|
||||||
u8 * buffer = (u8 *) malloc(infilesize);
|
u8 * buffer = (u8 *) malloc(infilesize);
|
||||||
if(!buffer)
|
if(!buffer)
|
||||||
{
|
{
|
||||||
WindowPrompt(tr( "Not enough memory." ), 0, tr( "OK" ));
|
WindowPrompt(tr( "Not enough memory." ), 0, tr( "OK" ));
|
||||||
return MENU_NONE;
|
return MENU_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
int error = 0;
|
int error = 0;
|
||||||
|
|
||||||
while (read < infilesize)
|
while (read < infilesize)
|
||||||
{
|
{
|
||||||
ShowProgress(tr( "Receiving file from:" ), GetIncommingIP(), NULL, read, infilesize, true);
|
ShowProgress(tr( "Receiving file from:" ), GetIncommingIP(), NULL, read, infilesize, true);
|
||||||
|
|
||||||
if (infilesize - read < (u32) len)
|
if (infilesize - read < (u32) len)
|
||||||
len = infilesize - read;
|
len = infilesize - read;
|
||||||
else len = NETWORKBLOCKSIZE;
|
else len = NETWORKBLOCKSIZE;
|
||||||
|
|
||||||
int result = network_read(connection, buffer+read, len);
|
int result = network_read(connection, buffer+read, len);
|
||||||
|
|
||||||
if (result < 0)
|
if (result < 0)
|
||||||
{
|
{
|
||||||
WindowPrompt(tr( "Error while transfering data." ), 0, tr( "OK" ));
|
WindowPrompt(tr( "Error while transfering data." ), 0, tr( "OK" ));
|
||||||
free(buffer);
|
free(buffer);
|
||||||
return MENU_NONE;
|
return MENU_NONE;
|
||||||
}
|
}
|
||||||
if (!result)
|
if (!result)
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
read += result;
|
read += result;
|
||||||
}
|
}
|
||||||
|
|
||||||
char filename[101];
|
char filename[101];
|
||||||
memset(filename, 0, sizeof(filename));
|
memset(filename, 0, sizeof(filename));
|
||||||
|
|
||||||
network_read(connection, (u8*) filename, 100);
|
network_read(connection, (u8*) filename, 100);
|
||||||
|
|
||||||
// Do we need to unzip this thing?
|
// Do we need to unzip this thing?
|
||||||
if (wiiloadVersion[0] > 0 || wiiloadVersion[1] > 4)
|
if (wiiloadVersion[0] > 0 || wiiloadVersion[1] > 4)
|
||||||
{
|
{
|
||||||
// We need to unzip...
|
// We need to unzip...
|
||||||
if (buffer[0] == 'P' && buffer[1] == 'K' && buffer[2] == 0x03 && buffer[3] == 0x04)
|
if (buffer[0] == 'P' && buffer[1] == 'K' && buffer[2] == 0x03 && buffer[3] == 0x04)
|
||||||
{
|
{
|
||||||
// It's a zip file, unzip to the apps directory
|
// It's a zip file, unzip to the apps directory
|
||||||
// Zip archive, ask for permission to install the zip
|
// Zip archive, ask for permission to install the zip
|
||||||
char zippath[255];
|
char zippath[255];
|
||||||
sprintf(zippath, "%s%s", Settings.homebrewapps_path, filename);
|
sprintf(zippath, "%s%s", Settings.homebrewapps_path, filename);
|
||||||
|
|
||||||
FILE *fp = fopen(zippath, "wb");
|
FILE *fp = fopen(zippath, "wb");
|
||||||
if (!fp)
|
if (!fp)
|
||||||
{
|
{
|
||||||
WindowPrompt(tr( "Error writing the data." ), 0, tr( "OK" ));
|
WindowPrompt(tr( "Error writing the data." ), 0, tr( "OK" ));
|
||||||
return MENU_NONE;
|
return MENU_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
fwrite(buffer, 1, infilesize, fp);
|
fwrite(buffer, 1, infilesize, fp);
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
|
|
||||||
free(buffer);
|
free(buffer);
|
||||||
buffer = NULL;
|
buffer = NULL;
|
||||||
|
|
||||||
// Now unzip the zip file...
|
// Now unzip the zip file...
|
||||||
unzFile uf = unzOpen(zippath);
|
unzFile uf = unzOpen(zippath);
|
||||||
if (uf == NULL)
|
if (uf == NULL)
|
||||||
{
|
{
|
||||||
WindowPrompt(tr( "Error while opening the zip." ), 0, tr( "OK" ));
|
WindowPrompt(tr( "Error while opening the zip." ), 0, tr( "OK" ));
|
||||||
return MENU_NONE;
|
return MENU_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
extractZip(uf, 0, 1, 0, Settings.homebrewapps_path);
|
extractZip(uf, 0, 1, 0, Settings.homebrewapps_path);
|
||||||
unzCloseCurrentFile(uf);
|
unzCloseCurrentFile(uf);
|
||||||
|
|
||||||
remove(zippath);
|
remove(zippath);
|
||||||
|
|
||||||
WindowPrompt(tr( "Success:" ),
|
WindowPrompt(tr( "Success:" ),
|
||||||
tr( "Uploaded ZIP file installed to homebrew directory." ), tr( "OK" ));
|
tr( "Uploaded ZIP file installed to homebrew directory." ), tr( "OK" ));
|
||||||
|
|
||||||
// Reload this menu here...
|
// Reload this menu here...
|
||||||
return MENU_HOMEBREWBROWSE;
|
return MENU_HOMEBREWBROWSE;
|
||||||
}
|
}
|
||||||
else if (uncfilesize != 0) // if uncfilesize == 0, it's not compressed
|
else if (uncfilesize != 0) // if uncfilesize == 0, it's not compressed
|
||||||
{
|
{
|
||||||
// It's compressed, uncompress
|
// It's compressed, uncompress
|
||||||
u8 *unc = (u8 *) malloc(uncfilesize);
|
u8 *unc = (u8 *) malloc(uncfilesize);
|
||||||
if(!unc)
|
if(!unc)
|
||||||
{
|
{
|
||||||
ProgressStop();
|
ProgressStop();
|
||||||
free(buffer);
|
free(buffer);
|
||||||
CloseConnection();
|
CloseConnection();
|
||||||
WindowPrompt(tr( "Not enough memory." ), 0, tr( "OK" ));
|
WindowPrompt(tr( "Not enough memory." ), 0, tr( "OK" ));
|
||||||
return MENU_NONE;
|
return MENU_NONE;
|
||||||
}
|
}
|
||||||
uLongf f = uncfilesize;
|
uLongf f = uncfilesize;
|
||||||
error = uncompress(unc, &f, buffer, infilesize) != Z_OK;
|
error = uncompress(unc, &f, buffer, infilesize) != Z_OK;
|
||||||
uncfilesize = f;
|
uncfilesize = f;
|
||||||
filesize = uncfilesize;
|
filesize = uncfilesize;
|
||||||
|
|
||||||
free(buffer);
|
free(buffer);
|
||||||
buffer = unc;
|
buffer = unc;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CopyHomebrewMemory(buffer, 0, filesize);
|
CopyHomebrewMemory(buffer, 0, filesize);
|
||||||
free(buffer);
|
free(buffer);
|
||||||
|
|
||||||
ProgressStop();
|
ProgressStop();
|
||||||
|
|
||||||
if (error || read != infilesize || (strcasestr(filename, ".dol") == 0 && strcasestr(filename, ".elf") == 0))
|
if (error || read != infilesize || (strcasestr(filename, ".dol") == 0 && strcasestr(filename, ".elf") == 0))
|
||||||
{
|
{
|
||||||
WindowPrompt(tr( "Error:" ), tr( "No data could be read." ), tr( "OK" ));
|
WindowPrompt(tr( "Error:" ), tr( "No data could be read." ), tr( "OK" ));
|
||||||
FreeHomebrewBuffer();
|
FreeHomebrewBuffer();
|
||||||
return MENU_NONE;
|
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