From f5e8484dc8123b7e178d07474c4d989c23972f1e Mon Sep 17 00:00:00 2001 From: dborth Date: Tue, 13 Apr 2010 23:34:09 +0000 Subject: [PATCH] some spiffy new audio/video code! --- source/audio.cpp | 10 +++++-- source/gui/gui.h | 21 +++++++++++-- source/gui/gui_element.cpp | 61 +++++++++++++++++++++++++++++++++----- source/gui/gui_image.cpp | 11 +++---- source/menu.cpp | 6 ++-- source/vbasupport.cpp | 2 +- source/video.cpp | 60 ++++++++++++++++++++++++------------- source/video.h | 1 + 8 files changed, 130 insertions(+), 42 deletions(-) diff --git a/source/audio.cpp b/source/audio.cpp index 2810adc..c8c6f7e 100644 --- a/source/audio.cpp +++ b/source/audio.cpp @@ -62,11 +62,10 @@ static void AudioPlayer() { if (!ConfigRequested) { + whichab ^= 1; int len = MIXER_GetSamples(soundbuffer[whichab], 3200); DCFlushRange(soundbuffer[whichab],len); AUDIO_InitDMA((u32)soundbuffer[whichab],len); - AUDIO_StartDMA(); - whichab ^= 1; IsPlaying = 1; } else @@ -106,6 +105,13 @@ SwitchAudioMode(int mode) ASND_Pause(1); AUDIO_StopDMA(); AUDIO_RegisterDMACallback(AudioPlayer); + + memset(soundbuffer[0],0,3840); + memset(soundbuffer[1],0,3840); + DCFlushRange(soundbuffer[0],3840); + DCFlushRange(soundbuffer[1],3840); + AUDIO_InitDMA((u32)soundbuffer[whichab],3200); + AUDIO_StartDMA(); #endif } else // menu diff --git a/source/gui/gui.h b/source/gui/gui.h index e0c159b..61c5888 100644 --- a/source/gui/gui.h +++ b/source/gui/gui.h @@ -323,12 +323,28 @@ class GuiElement //!Considers alpha, alphaDyn, and the parent element's GetAlpha() value //!\return alpha int GetAlpha(); - //!Sets the element's scale + //!Sets the element's x and y scale //!\param s scale (1 is 100%) void SetScale(float s); + //!Sets the element's x scale + //!\param s scale (1 is 100%) + void SetScaleX(float s); + //!Sets the element's y scale + //!\param s scale (1 is 100%) + void SetScaleY(float s); + //!Sets the element's x and y scale, using the provided max width/height + //!\param w Maximum width + //!\param h Maximum height + void SetScale(int w, int h); //!Gets the element's current scale //!Considers scale, scaleDyn, and the parent element's GetScale() value float GetScale(); + //!Gets the element's current x scale + //!Considers scale, scaleDyn, and the parent element's GetScale() value + float GetScaleX(); + //!Gets the element's current y scale + //!Considers scale, scaleDyn, and the parent element's GetScale() value + float GetScaleY(); //!Set a new GuiTrigger for the element //!\param t Pointer to GuiTrigger void SetTrigger(GuiTrigger * t); @@ -420,7 +436,8 @@ class GuiElement int yoffsetDyn; //!< Element Y offset, dynamic (added to yoffset value for animation effects) int alpha; //!< Element alpha value (0-255) int alphaDyn; //!< Element alpha, dynamic (multiplied by alpha value for blending/fading effects) - f32 scale; //!< Element scale (1 = 100%) + f32 xscale; //!< Element X scale (1 = 100%) + f32 yscale; //!< Element Y scale (1 = 100%) f32 scaleDyn; //!< Element scale, dynamic (multiplied by alpha value for blending/fading effects) int effects; //!< Currently enabled effect(s). 0 when no effects are enabled int effectAmount; //!< Effect amount. Used by different effects for different purposes diff --git a/source/gui/gui_element.cpp b/source/gui/gui_element.cpp index 4378324..9efb1c1 100644 --- a/source/gui/gui_element.cpp +++ b/source/gui/gui_element.cpp @@ -24,7 +24,8 @@ GuiElement::GuiElement() width = 0; height = 0; alpha = 255; - scale = 1; + xscale = 1; + yscale = 1; state = STATE_DEFAULT; stateChan = -1; trigger[0] = NULL; @@ -92,12 +93,13 @@ int GuiElement::GetLeft() x = pLeft; break; case ALIGN_CENTRE: - x = pLeft + (pWidth>>1) - (width>>1); + x = pLeft + pWidth/2.0 - (width*xscale)/2.0; break; case ALIGN_RIGHT: - x = pLeft + pWidth - width; + x = pLeft + pWidth - width*xscale; break; } + x += (width*(xscale - 1))/2.0; // correct offset for scaled images return x + xoffset; } @@ -122,12 +124,13 @@ int GuiElement::GetTop() y = pTop; break; case ALIGN_MIDDLE: - y = pTop + (pHeight>>1) - (height>>1); + y = pTop + pHeight/2.0 - (height*yscale)/2.0; break; case ALIGN_BOTTOM: - y = pTop + pHeight - height; + y = pTop + pHeight - height*yscale; break; } + y += (height*(yscale - 1))/2.0; // correct offset for scaled images return y + yoffset; } @@ -218,12 +221,36 @@ int GuiElement::GetAlpha() void GuiElement::SetScale(float s) { - scale = s; + xscale = s; + yscale = s; +} + +void GuiElement::SetScaleX(float s) +{ + xscale = s; +} + +void GuiElement::SetScaleY(float s) +{ + yscale = s; +} + +void GuiElement::SetScale(int mw, int mh) +{ + xscale = 1.0f; + if(width > mw || height > mh) + { + if(width/(height*1.0) > mw/(mh*1.0)) + xscale = mw/(width*1.0); + else + xscale = mh/(height*1.0); + } + yscale = xscale; } float GuiElement::GetScale() { - float s = scale * scaleDyn; + float s = xscale * scaleDyn; if(parentElement) s *= parentElement->GetScale(); @@ -231,6 +258,26 @@ float GuiElement::GetScale() return s; } +float GuiElement::GetScaleX() +{ + float s = xscale * scaleDyn; + + if(parentElement) + s *= parentElement->GetScale(); + + return s; +} + +float GuiElement::GetScaleY() +{ + float s = yscale * scaleDyn; + + if(parentElement) + s *= parentElement->GetScaleY(); + + return s; +} + int GuiElement::GetState() { return state; diff --git a/source/gui/gui_image.cpp b/source/gui/gui_image.cpp index 692a591..acf1b00 100644 --- a/source/gui/gui_image.cpp +++ b/source/gui/gui_image.cpp @@ -226,7 +226,8 @@ void GuiImage::Draw() if(!image || !this->IsVisible() || tile == 0) return; - float currScale = this->GetScale(); + float currScaleX = this->GetScaleX(); + float currScaleY = this->GetScaleY(); int currLeft = this->GetLeft(); int thisTop = this->GetTop(); @@ -235,16 +236,12 @@ void GuiImage::Draw() int alpha = this->GetAlpha(); for(int i=0; iGetAlpha()); + Menu_DrawImg(currLeft, thisTop, width, height, image, imageangle, currScaleX, currScaleY, this->GetAlpha()); } if(stripe > 0) diff --git a/source/menu.cpp b/source/menu.cpp index 4e35005..3efcbc0 100644 --- a/source/menu.cpp +++ b/source/menu.cpp @@ -375,7 +375,7 @@ ProgressWindow(char *title, char *msg) } // wait to see if progress flag changes soon - progsleep = 400000; + progsleep = 800000; while(progsleep > 0) { @@ -4223,9 +4223,11 @@ MainMenu (int menu) if(gameScreenTex) { - gameScreenImg = new GuiImage(gameScreenTex, screenwidth, screenheight); + gameScreenImg = new GuiImage(gameScreenTex, vmode->fbWidth, vmode->efbHeight); gameScreenImg->SetAlpha(192); gameScreenImg->ColorStripe(30); + gameScreenImg->SetScaleX(screenwidth/(float)vmode->fbWidth); + gameScreenImg->SetScaleY(screenheight/(float)vmode->efbHeight); mainWindow->Append(gameScreenImg); bgImg->SetVisible(false); } diff --git a/source/vbasupport.cpp b/source/vbasupport.cpp index 8a14498..5c5ec50 100644 --- a/source/vbasupport.cpp +++ b/source/vbasupport.cpp @@ -364,7 +364,7 @@ bool SaveBatteryOrState(char * filepath, int action, bool silent) if (pngContext != NULL) { - imgSize = PNGU_EncodeFromGXTexture(pngContext, screenwidth, screenheight, gameScreenTex2, 0); + imgSize = PNGU_EncodeFromGXTexture(pngContext, vmode->fbWidth, vmode->efbHeight, gameScreenTex2, 0); PNGU_ReleaseImageContext(pngContext); } diff --git a/source/video.cpp b/source/video.cpp index ccb4fe3..6891949 100644 --- a/source/video.cpp +++ b/source/video.cpp @@ -29,7 +29,7 @@ u32 FrameTimer = 0; /*** External 2D Video ***/ /*** 2D Video Globals ***/ -static GXRModeObj *vmode = NULL; // Graphics Mode Object +GXRModeObj *vmode = NULL; // Graphics Mode Object unsigned int *xfb[2] = { NULL, NULL }; // Framebuffers int whichfb = 0; // Frame buffer toggle @@ -304,22 +304,6 @@ static GXRModeObj * FindVideoMode() break; } - // configure original modes (not implemented) - switch (mode->viTVMode >> 2) - { - case VI_PAL: - // 576 lines (PAL 50hz) - break; - - case VI_NTSC: - // 480 lines (NTSC 60hz) - break; - - default: - // 480 lines (PAL 60Hz) - break; - } - // check for progressive scan if (mode->viTVMode == VI_TVMODE_NTSC_PROG) progressive = true; @@ -327,11 +311,45 @@ static GXRModeObj * FindVideoMode() progressive = false; #ifdef HW_RVL - // widescreen fix - if(CONF_GetAspectRatio() == CONF_ASPECT_16_9) + bool pal = false; + + if (mode == &TVPal528IntDf) + pal = true; + + if (CONF_GetAspectRatio() == CONF_ASPECT_16_9) { - mode->viWidth = 678; - mode->viXOrigin = (VI_MAX_WIDTH_NTSC - 678) / 2; + mode->fbWidth = 640; + mode->efbHeight = 456; + mode->viWidth = 686; + + if (pal) + { + mode->xfbHeight = 542; + mode->viHeight = 542; + } + else + { + mode->xfbHeight = 456; + mode->viHeight = 456; + } + } + else + { + if (pal) + mode = &TVPal574IntDfScale; + + mode->viWidth = 672; + } + + if (pal) + { + mode->viXOrigin = (VI_MAX_WIDTH_PAL - mode->viWidth) / 2; + mode->viYOrigin = (VI_MAX_HEIGHT_PAL - mode->viHeight) / 2; + } + else + { + mode->viXOrigin = (VI_MAX_WIDTH_NTSC - mode->viWidth) / 2; + mode->viYOrigin = (VI_MAX_HEIGHT_NTSC - mode->viHeight) / 2; } #endif diff --git a/source/video.h b/source/video.h index e571261..f105d44 100644 --- a/source/video.h +++ b/source/video.h @@ -25,6 +25,7 @@ void Menu_Render(); void Menu_DrawImg(f32 xpos, f32 ypos, u16 width, u16 height, u8 data[], f32 degrees, f32 scaleX, f32 scaleY, u8 alphaF ); void Menu_DrawRectangle(f32 x, f32 y, f32 width, f32 height, GXColor color, u8 filled); +extern GXRModeObj *vmode; extern int screenheight; extern int screenwidth; extern s32 CursorX, CursorY;