From f2bea21a4b7dfdf214ddffd80e9d93a0be671d79 Mon Sep 17 00:00:00 2001 From: thesource Date: Thu, 1 Feb 2024 13:19:59 +0300 Subject: [PATCH 1/8] gtk: make OSD scalable --- .../src/frontend/modules/osd/agg/agg2d.inl | 15 +- .../src/frontend/modules/osd/agg/agg_osd.cpp | 241 ++++++++++++------ .../src/frontend/modules/osd/agg/agg_osd.h | 9 +- .../src/frontend/modules/osd/agg/aggdraw.cpp | 29 ++- .../src/frontend/modules/osd/agg/aggdraw.h | 62 ++++- desmume/src/frontend/posix/gtk/main.cpp | 94 ++++++- desmume/src/frontend/posix/gtk/meson.build | 3 +- desmume/src/frontend/posix/meson.build | 6 + 8 files changed, 350 insertions(+), 109 deletions(-) diff --git a/desmume/src/frontend/modules/osd/agg/agg2d.inl b/desmume/src/frontend/modules/osd/agg/agg2d.inl index 756d193b9..2f4ee6a5d 100644 --- a/desmume/src/frontend/modules/osd/agg/agg2d.inl +++ b/desmume/src/frontend/modules/osd/agg/agg2d.inl @@ -1370,6 +1370,17 @@ AGG2D_TEMPLATE void TAGG2D::text(double x, double y, const wchar_t* str, unsigne } } + +AGG2D_TEMPLATE double TAGG2D::textWidth(const char* str) +{ + return textWidth(str, (unsigned int)strlen(str)); +} + +AGG2D_TEMPLATE void TAGG2D::text(double x, double y, const char* str, bool roundOff, double dx, double dy) +{ + text(x, y, str, (unsigned int)strlen(str), roundOff, dx, dy); +} + #endif //------------------------------------------------------------------------ @@ -1945,11 +1956,11 @@ AGG2D_TEMPLATE void TAGG2D::render(FontRasterizer& ras, FontScanline& sl) { if(m_blendMode == BlendAlpha) { - Agg2DRenderer::render(*this, m_renBase, m_renSolid, ras, sl); + Agg2DRenderer::render(*this, m_renBase, m_renSolid, ras, sl); } else { - Agg2DRenderer::render(*this, m_renBaseComp, m_renSolidComp, ras, sl); + Agg2DRenderer::render(*this, m_renBaseComp, m_renSolidComp, ras, sl); } } diff --git a/desmume/src/frontend/modules/osd/agg/agg_osd.cpp b/desmume/src/frontend/modules/osd/agg/agg_osd.cpp index 06332ddab..ecaba59d1 100644 --- a/desmume/src/frontend/modules/osd/agg/agg_osd.cpp +++ b/desmume/src/frontend/modules/osd/agg/agg_osd.cpp @@ -50,13 +50,23 @@ static s64 hudTimer; static void SetHudDummy (HudCoordinates *hud) { - hud->x=666; - hud->y=666; + hud->x=-666; + hud->y=-666; } static bool IsHudDummy (HudCoordinates *hud) { - return (hud->x == 666 && hud->y == 666); + return (hud->x == -666 && hud->y == -666); +} + +static int ScreenWidth() +{ + return 256*osd->scale; +} + +static int ScreenHeight() +{ + return 192*osd->scale; } template @@ -64,21 +74,47 @@ static T calcY(T y) // alters a GUI element y coordinate as necessary to obey sw { if(osd->singleScreen) { - if(y >= 192) - y -= 192; + if(y >= ScreenHeight()) + y -= ScreenHeight(); if(osd->swapScreens) - y += 192; + y += ScreenHeight(); } else if(osd->swapScreens) { - if(y >= 192) - y -= 192; + if(y >= ScreenHeight()) + y -= ScreenHeight(); else - y += 192; + y += ScreenHeight(); } return y; } +static void RenderTextAutoVector(double x, double y, const std::string& str, bool shadow = true, int shadowOffset = 1) +{ +#ifdef AGG2D_USE_VECTORFONTS + bool render_vect = false; + if(osd) + if(osd->useVectorFonts) + render_vect = true; + if(render_vect) + { + if(shadow) + aggDraw.hud->renderVectorFontTextDropshadowed(x, y, str, shadowOffset); + else + aggDraw.hud->renderVectorFontText(x, y, str); + } + else + { +#endif + if(shadow) + aggDraw.hud->renderTextDropshadowed(x, y, str); + else + aggDraw.hud->renderText(x, y, str); +#ifdef AGG2D_USE_VECTORFONTS + } +#endif +} + void EditHud(s32 x, s32 y, HudStruct *hudstruct) { u32 i = 0; @@ -108,8 +144,10 @@ void EditHud(s32 x, s32 y, HudStruct *hudstruct) { //sanity checks if(hud.x < 0) hud.x = 0; if(hud.y < 0) hud.y = 0; - if(hud.x > 245)hud.x = 245; //margins - if(hud.y > 384-16)hud.y = 384-16; + if(hud.x > ScreenWidth()-11*osd->scale) + hud.x = ScreenWidth()-11*osd->scale; //margins + if(hud.y > ScreenHeight()*2-16*osd->scale) + hud.y = ScreenHeight()*2-16*osd->scale; if(hud.clicked) { @@ -136,45 +174,47 @@ void HudClickRelease(HudStruct *hudstruct) { void HudStruct::reset() { + int sc=(osd ? osd->scale : 1); + FpsDisplay.x=0; - FpsDisplay.y=5; - FpsDisplay.xsize=166; - FpsDisplay.ysize=10; + FpsDisplay.y=5*sc; + FpsDisplay.xsize=166*sc; + FpsDisplay.ysize=10*sc; FrameCounter.x=0; - FrameCounter.y=25; - FrameCounter.xsize=60; - FrameCounter.ysize=10; + FrameCounter.y=25*sc; + FrameCounter.xsize=60*sc; + FrameCounter.ysize=10*sc; InputDisplay.x=0; - InputDisplay.y=45; - InputDisplay.xsize=220; - InputDisplay.ysize=10; + InputDisplay.y=45*sc; + InputDisplay.xsize=220*sc; + InputDisplay.ysize=10*sc; - GraphicalInputDisplay.x=8; - GraphicalInputDisplay.y=328; - GraphicalInputDisplay.xsize=102; - GraphicalInputDisplay.ysize=50; + GraphicalInputDisplay.x=8*sc; + GraphicalInputDisplay.y=328*sc; + GraphicalInputDisplay.xsize=102*sc; + GraphicalInputDisplay.ysize=50*sc; LagFrameCounter.x=0; - LagFrameCounter.y=65; - LagFrameCounter.xsize=30; - LagFrameCounter.ysize=10; + LagFrameCounter.y=65*sc; + LagFrameCounter.xsize=30*sc; + LagFrameCounter.ysize=10*sc; Microphone.x=0; - Microphone.y=85; - Microphone.xsize=20; - Microphone.ysize=10; + Microphone.y=85*sc; + Microphone.xsize=20*sc; + Microphone.ysize=10*sc; RTCDisplay.x=0; - RTCDisplay.y=105; - RTCDisplay.xsize=220; - RTCDisplay.ysize=10; + RTCDisplay.y=105*sc; + RTCDisplay.xsize=220*sc; + RTCDisplay.ysize=10*sc; - SavestateSlots.x = 8; - SavestateSlots.y = 160; - SavestateSlots.xsize = 240; - SavestateSlots.ysize = 24; + SavestateSlots.x = 8*sc; + SavestateSlots.y = 160*sc; + SavestateSlots.xsize = 240*sc; + SavestateSlots.ysize = 24*sc; #ifdef _MSC_VER #define AGG_OSD_SETTING(which,comp) which.comp = GetPrivateProfileInt("HudEdit", #which "." #comp, which.comp, IniName); @@ -186,6 +226,51 @@ void HudStruct::reset() clicked = false; } +void HudStruct::rescale(double oldScale, double newScale) +{ + double sc=newScale/oldScale; + + FpsDisplay.x*=sc; + FpsDisplay.y*=sc; + FpsDisplay.xsize*=sc; + FpsDisplay.ysize*=sc; + + FrameCounter.x*=sc; + FrameCounter.y*=sc; + FrameCounter.xsize*=sc; + FrameCounter.ysize*=sc; + + InputDisplay.x*=sc; + InputDisplay.y*=sc; + InputDisplay.xsize*=sc; + InputDisplay.ysize*=sc; + + GraphicalInputDisplay.x*=sc; + GraphicalInputDisplay.y*=sc; + GraphicalInputDisplay.xsize*=sc; + GraphicalInputDisplay.ysize*=sc; + + LagFrameCounter.x*=sc; + LagFrameCounter.y*=sc; + LagFrameCounter.xsize*=sc; + LagFrameCounter.ysize*=sc; + + Microphone.x*=sc; + Microphone.y*=sc; + Microphone.xsize*=sc; + Microphone.ysize*=sc; + + RTCDisplay.x*=sc; + RTCDisplay.y*=sc; + RTCDisplay.xsize*=sc; + RTCDisplay.ysize*=sc; + + SavestateSlots.x*=sc; + SavestateSlots.y*=sc; + SavestateSlots.xsize*=sc; + SavestateSlots.ysize*=sc; +} + static void joyFill(int n) { bool pressedForGame = NDS_getFinalUserInput().buttons.array[n]; @@ -235,8 +320,8 @@ static void drawPad(double x, double y, double ratio) { // aligning to odd half-pixel boundaries prevents agg2d from blurring thin straight lines x = floor(x) + 0.5; y = floor(calcY(y)) + 0.5; - double xc = 41 - 0.5; - double yc = 20 - 0.5; + double xc = 41*osd->scale - 0.5; + double yc = 20*osd->scale - 0.5; aggDraw.hud->lineColor(128,128,128,255); @@ -252,12 +337,12 @@ static void drawPad(double x, double y, double ratio) { aggDraw.hud->roundedRect (screenLeft, screenTop, screenRight, screenBottom, 1); - joyEllipse(.89,.45,xc,yc,x,y,ratio,1,6);//B - joyEllipse(.89,.22,xc,yc,x,y,ratio,1,3);//X - joyEllipse(.83,.34,xc,yc,x,y,ratio,1,4);//Y - joyEllipse(.95,.34,xc,yc,x,y,ratio,1,5);//A - joyEllipse(.82,.716,xc,yc,x,y,ratio,.5,7);//Start - joyEllipse(.82,.842,xc,yc,x,y,ratio,.5,8);//Select + joyEllipse(.89,.45,xc,yc,x,y,ratio,osd->scale,6);//B + joyEllipse(.89,.22,xc,yc,x,y,ratio,osd->scale,3);//X + joyEllipse(.83,.34,xc,yc,x,y,ratio,osd->scale,4);//Y + joyEllipse(.95,.34,xc,yc,x,y,ratio,osd->scale,5);//A + joyEllipse(.82,.716,xc,yc,x,y,ratio,osd->scale * .5,7);//Start + joyEllipse(.82,.842,xc,yc,x,y,ratio,osd->scale * .5,8);//Select double dpadPoints [][2] = { @@ -311,29 +396,29 @@ static void drawPad(double x, double y, double ratio) { // touch pad { BOOL gameTouchOn = nds.isTouch; - double gameTouchX = screenLeft+1 + (nds.scr_touchX * 0.0625) * (screenRight - screenLeft - 2) / 256.0; - double gameTouchY = screenTop+1 + (nds.scr_touchY * 0.0625) * (screenBottom - screenTop - 2) / 192.0; + double gameTouchX = screenLeft+1 + (nds.scr_touchX * osd->scale * 0.0625) * (screenRight - screenLeft - 2) / (double)ScreenWidth(); + double gameTouchY = screenTop+1 + (nds.scr_touchY * osd->scale * 0.0625) * (screenBottom - screenTop - 2) / (double)ScreenHeight(); bool physicalTouchOn = NDS_getRawUserInput().touch.isTouch; - double physicalTouchX = screenLeft+1 + (NDS_getRawUserInput().touch.touchX * 0.0625) * (screenRight - screenLeft - 2) / 256.0; - double physicalTouchY = screenTop+1 + (NDS_getRawUserInput().touch.touchY * 0.0625) * (screenBottom - screenTop - 2) / 192.0; + double physicalTouchX = screenLeft+1 + (NDS_getRawUserInput().touch.touchX * osd->scale * 0.0625) * (screenRight - screenLeft - 2) / (double)ScreenWidth(); + double physicalTouchY = screenTop+1 + (NDS_getRawUserInput().touch.touchY * osd->scale * 0.0625) * (screenBottom - screenTop - 2) / (double)ScreenHeight(); if(gameTouchOn && physicalTouchOn && gameTouchX == physicalTouchX && gameTouchY == physicalTouchY) { aggDraw.hud->fillColor(0,0,0,255); - aggDraw.hud->ellipse(gameTouchX, gameTouchY, ratio*0.37, ratio*0.37); + aggDraw.hud->ellipse(gameTouchX, gameTouchY, osd->scale*ratio*0.37, osd->scale*ratio*0.37); } else { if(physicalTouchOn) { aggDraw.hud->fillColor(0,0,0,128); - aggDraw.hud->ellipse(physicalTouchX, physicalTouchY, ratio*0.5, ratio*0.5); + aggDraw.hud->ellipse(physicalTouchX, physicalTouchY, osd->scale*ratio*0.5, osd->scale*ratio*0.5); aggDraw.hud->fillColor(0,255,0,255); - aggDraw.hud->ellipse(physicalTouchX, physicalTouchY, ratio*0.37, ratio*0.37); + aggDraw.hud->ellipse(physicalTouchX, physicalTouchY, osd->scale*ratio*0.37, osd->scale*ratio*0.37); } if(gameTouchOn) { aggDraw.hud->fillColor(255,0,0,255); - aggDraw.hud->ellipse(gameTouchX, gameTouchY, ratio*0.37, ratio*0.37); + aggDraw.hud->ellipse(gameTouchX, gameTouchY, osd->scale*ratio*0.37, osd->scale*ratio*0.37); } } } @@ -379,8 +464,8 @@ static void TextualInputDisplay() { // cast from char to std::string is a bit awkward std::string str(buttonChars+i, 2); str[1] = '\0'; - - aggDraw.hud->renderTextDropshadowed(x, calcY(Hud.InputDisplay.y), str); + + RenderTextAutoVector(x, calcY(Hud.InputDisplay.y), str, true, osd ? osd->scale : 1); } // touch pad @@ -396,7 +481,7 @@ static void TextualInputDisplay() { { sprintf(str, "%d,%d", gameTouchX, gameTouchY); aggDraw.hud->lineColor(255,255,255,255); - aggDraw.hud->renderTextDropshadowed(x, calcY(Hud.InputDisplay.y), str); + RenderTextAutoVector(x, calcY(Hud.InputDisplay.y), str, true, osd ? osd->scale : 1); } else { @@ -404,13 +489,13 @@ static void TextualInputDisplay() { { sprintf(str, "%d,%d", gameTouchX, gameTouchY); aggDraw.hud->lineColor(255,48,48,255); - aggDraw.hud->renderTextDropshadowed(x, calcY(Hud.InputDisplay.y)-(physicalTouchOn?8:0), str); + RenderTextAutoVector(x, calcY(Hud.InputDisplay.y)-(physicalTouchOn?8:0), str, true, osd ? osd->scale : 1); } if(physicalTouchOn) { sprintf(str, "%d,%d", physicalTouchX, physicalTouchY); aggDraw.hud->lineColor(0,192,0,255); - aggDraw.hud->renderTextDropshadowed(x, calcY(Hud.InputDisplay.y)+(gameTouchOn?8:0), str); + RenderTextAutoVector(x, calcY(Hud.InputDisplay.y)+(gameTouchOn?8:0), str, true, osd ? osd->scale : 1); } } } @@ -418,10 +503,10 @@ static void TextualInputDisplay() { static void OSD_HandleTouchDisplay() { // note: calcY should not be used in this function. - aggDraw.hud->lineWidth(1.0); + aggDraw.hud->lineWidth(osd->scale); - temptouch.X = NDS_getRawUserInput().touch.touchX >> 4; - temptouch.Y = NDS_getRawUserInput().touch.touchY >> 4; + temptouch.X = NDS_getRawUserInput().touch.touchX >> 4 * osd->scale; + temptouch.Y = NDS_getRawUserInput().touch.touchY >> 4 * osd->scale; if(touchshadow) { @@ -432,27 +517,27 @@ static void OSD_HandleTouchDisplay() { temptouch = touch[i]; if(temptouch.X != 0 || temptouch.Y != 0) { aggDraw.hud->lineColor(0, 255, 0, touchalpha[i]); - aggDraw.hud->line(temptouch.X - 256, temptouch.Y + 192, temptouch.X + 256, temptouch.Y + 192); //horiz - aggDraw.hud->line(temptouch.X, temptouch.Y - 256, temptouch.X, temptouch.Y + 384); //vert + aggDraw.hud->line(temptouch.X - ScreenWidth(), temptouch.Y + ScreenHeight(), temptouch.X + ScreenWidth(), temptouch.Y + ScreenHeight()); //horiz + aggDraw.hud->line(temptouch.X, temptouch.Y - ScreenWidth(), temptouch.X, temptouch.Y + ScreenHeight()*2); //vert aggDraw.hud->fillColor(0, 0, 0, touchalpha[i]); - aggDraw.hud->rectangle(temptouch.X-1, temptouch.Y + 192-1, temptouch.X+1, temptouch.Y + 192+1); + aggDraw.hud->rectangle(temptouch.X-1, temptouch.Y + ScreenHeight()-1, temptouch.X+1, temptouch.Y + ScreenHeight()+1); } } } else if(NDS_getRawUserInput().touch.isTouch) { aggDraw.hud->lineColor(0, 255, 0, 128); - aggDraw.hud->line(temptouch.X - 256, temptouch.Y + 192, temptouch.X + 256, temptouch.Y + 192); //horiz - aggDraw.hud->line(temptouch.X, temptouch.Y - 256, temptouch.X, temptouch.Y + 384); //vert + aggDraw.hud->line(temptouch.X - ScreenWidth(), temptouch.Y + ScreenHeight(), temptouch.X + ScreenWidth(), temptouch.Y + ScreenHeight()); //horiz + aggDraw.hud->line(temptouch.X, temptouch.Y - ScreenWidth(), temptouch.X, temptouch.Y + ScreenHeight()*2); //vert } if(nds.isTouch) { - temptouch.X = nds.scr_touchX / 16; - temptouch.Y = nds.scr_touchY / 16; + temptouch.X = nds.scr_touchX / 16 * osd->scale; + temptouch.Y = nds.scr_touchY / 16 * osd->scale; aggDraw.hud->lineColor(255, 0, 0, 128); - aggDraw.hud->line(temptouch.X - 256, temptouch.Y + 192, temptouch.X + 256, temptouch.Y + 192); //horiz - aggDraw.hud->line(temptouch.X, temptouch.Y - 256, temptouch.X, temptouch.Y + 384); //vert + aggDraw.hud->line(temptouch.X - ScreenWidth(), temptouch.Y + ScreenHeight(), temptouch.X + ScreenWidth(), temptouch.Y + ScreenHeight()); //horiz + aggDraw.hud->line(temptouch.X, temptouch.Y - ScreenWidth(), temptouch.X, temptouch.Y + ScreenHeight()*2); //vert } } @@ -493,7 +578,7 @@ static void DrawStateSlots(){ aggDraw.hud->rectangle(xloc + xpos , yloc - yheight, xloc + 22 + xpos , yloc + 20 + yheight); snprintf(number, 10, "%d", i); - aggDraw.hud->renderText(xloc + 1 + xpos + 4, yloc+4, std::string(number)); + RenderTextAutoVector(xloc + 1 + xpos + 4, yloc+4, std::string(number), true, osd ? osd->scale : 1); i++; } } @@ -511,10 +596,10 @@ static void DrawEditableElementIndicators() HudCoordinates &hud = Hud.hud(i); aggDraw.hud->fillColor(0,0,0,0); aggDraw.hud->lineColor(0,0,0,64); - aggDraw.hud->lineWidth(2.0); + aggDraw.hud->lineWidth(2.0*osd->scale); aggDraw.hud->rectangle(hud.x,calcY(hud.y),hud.x+hud.xsize+1.0,calcY(hud.y)+hud.ysize+1.0); aggDraw.hud->lineColor(255,hud.clicked?127:255,0,255); - aggDraw.hud->lineWidth(1.0); + aggDraw.hud->lineWidth(osd->scale); aggDraw.hud->rectangle(hud.x-0.5,calcY(hud.y)-0.5,hud.x+hud.xsize+0.5,calcY(hud.y)+hud.ysize+0.5); i++; } @@ -624,9 +709,11 @@ OSDCLASS::OSDCLASS(u8 core) singleScreen = false; swapScreens = false; - + scale=1; needUpdate = false; - +#ifdef AGG2D_USE_VECTORFONTS + useVectorFonts = false; +#endif if (core==0) strcpy(name,"Core A"); else @@ -707,7 +794,7 @@ void OSDCLASS::update() for (int i=0; i < lastLineText; i++) { aggDraw.hud->lineColor(lineColor[i]); - aggDraw.hud->renderTextDropshadowed(lineText_x,lineText_y+(i*16),lineText[i]); + RenderTextAutoVector(lineText_x, lineText_y+(i*16), lineText[i], true, osd ? osd->scale : 1); } } else @@ -789,7 +876,7 @@ void OSDCLASS::addFixed(u16 x, u16 y, const char *fmt, ...) va_end(list); aggDraw.hud->lineColor(255,255,255); - aggDraw.hud->renderTextDropshadowed(x,calcY(y),msg); + RenderTextAutoVector(x, calcY(y), msg, true, osd ? osd->scale : 1); needUpdate = true; } diff --git a/desmume/src/frontend/modules/osd/agg/agg_osd.h b/desmume/src/frontend/modules/osd/agg/agg_osd.h index e62fcbd95..f7a306f32 100644 --- a/desmume/src/frontend/modules/osd/agg/agg_osd.h +++ b/desmume/src/frontend/modules/osd/agg/agg_osd.h @@ -73,6 +73,7 @@ struct HudStruct HudCoordinates &hud(int i) { return ((HudCoordinates*)this)[i]; } void reset(); + void rescale(double oldScale, double newScale); int fps, fps3d, cpuload[2], cpuloopIterationCount; char rtcString[25]; @@ -92,7 +93,7 @@ class OSDCLASS private: u64 offset; u8 mode; - + u16 rotAngle; u16 lineText_x; @@ -111,6 +112,10 @@ class OSDCLASS char name[7]; // for debuging bool singleScreen; bool swapScreens; + int scale; +#ifdef AGG2D_USE_VECTORFONTS + bool useVectorFonts; +#endif OSDCLASS(u8 core); ~OSDCLASS(); @@ -125,7 +130,7 @@ class OSDCLASS void addLine(const char* fmt, va_list args); void addFixed(u16 x, u16 y, const char *fmt, ...); void border(bool enabled); - + void SaveHudEditor(); }; diff --git a/desmume/src/frontend/modules/osd/agg/aggdraw.cpp b/desmume/src/frontend/modules/osd/agg/aggdraw.cpp index 4ec5e0403..d8aa1008f 100644 --- a/desmume/src/frontend/modules/osd/agg/aggdraw.cpp +++ b/desmume/src/frontend/modules/osd/agg/aggdraw.cpp @@ -119,16 +119,16 @@ static void Agg_init_fonts() AggDraw_Desmume aggDraw; #if defined(WIN32) || defined(HOST_LINUX) -T_AGG_RGBA agg_targetScreen(0, 256, 384, 1024); +T_AGG_RGBA agg_targetScreen(0, GPU_FRAMEBUFFER_NATIVE_WIDTH, GPU_FRAMEBUFFER_NATIVE_HEIGHT*2, 1024); #else -T_AGG_RGB555 agg_targetScreen(0, 256, 384, 1512); +T_AGG_RGB555 agg_targetScreen(0, GPU_FRAMEBUFFER_NATIVE_WIDTH, GPU_FRAMEBUFFER_NATIVE_HEIGHT*2, 512); #endif -static u32 luaBuffer[256*192*2]; -T_AGG_RGBA agg_targetLua((u8*)luaBuffer, 256, 384, 1024); +static std::vector luaBuffer(GPU_FRAMEBUFFER_NATIVE_WIDTH*GPU_FRAMEBUFFER_NATIVE_HEIGHT*2); +T_AGG_RGBA agg_targetLua((u8*)luaBuffer.data(), GPU_FRAMEBUFFER_NATIVE_WIDTH, GPU_FRAMEBUFFER_NATIVE_HEIGHT*2, 1024); -static u32 hudBuffer[256*192*2]; -T_AGG_RGBA agg_targetHud((u8*)hudBuffer, 256, 384, 1024); +static std::vector hudBuffer(GPU_FRAMEBUFFER_NATIVE_WIDTH*GPU_FRAMEBUFFER_NATIVE_HEIGHT*2); +T_AGG_RGBA agg_targetHud((u8*)hudBuffer.data(), GPU_FRAMEBUFFER_NATIVE_WIDTH, GPU_FRAMEBUFFER_NATIVE_HEIGHT*2, 1024); static AggDrawTarget* targets[] = { &agg_targetScreen, @@ -162,6 +162,23 @@ void AggDraw_Desmume::setTarget(AggTarget newTarget) target = targets[newTarget]; } +void Agg_setCustomSize(int w, int h) +{ + hudBuffer.resize(w*h); + luaBuffer.resize(w*h); + if(aggDraw.screen) + { +#if defined(WIN32) || defined(HOST_LINUX) + aggDraw.screen->setDrawTargetDims(0, w, h, w*4); +#else + aggDraw.screen->setDrawTargetDims(0, w, h, w*2); +#endif + } + if(aggDraw.hud) + aggDraw.hud->setDrawTargetDims((u8*)hudBuffer.data(), w, h, w*4); + if(aggDraw.lua) + aggDraw.lua->setDrawTargetDims((u8*)luaBuffer.data(), w, h, w*4); +} ////temporary, just for testing the lib diff --git a/desmume/src/frontend/modules/osd/agg/aggdraw.h b/desmume/src/frontend/modules/osd/agg/aggdraw.h index 2cc385622..a3813c670 100644 --- a/desmume/src/frontend/modules/osd/agg/aggdraw.h +++ b/desmume/src/frontend/modules/osd/agg/aggdraw.h @@ -19,7 +19,7 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. +THE SOFTWARE. */ @@ -43,18 +43,18 @@ THE SOFTWARE. #include "agg_pixfmt_rgb.h" #include "agg_pixfmt_rgba.h" -#include "agg_pixfmt_rgb_packed.h" +#include "agg_pixfmt_rgb_packed.h" #include "agg2d.h" typedef agg::rgba8 AggColor; -namespace agg -{ - //NOTE - these blenders are necessary to change the rgb order from the defaults, which are incorrect for us - - //this custom blender does more correct blending math than the default - //which is necessary or else drawing transparent pixels on (31,31,31) will yield (30,30,30) +namespace agg +{ + //NOTE - these blenders are necessary to change the rgb order from the defaults, which are incorrect for us + + //this custom blender does more correct blending math than the default + //which is necessary or else drawing transparent pixels on (31,31,31) will yield (30,30,30) struct my_blender_rgb555_pre { typedef rgba8 color_type; @@ -242,6 +242,8 @@ class AggDrawTarget bool empty; virtual void clear() = 0; + + virtual void setDrawTargetDims(agg::int8u* buf, int width, int height, int stride) = 0; virtual agg::rendering_buffer & buf() = 0; @@ -408,6 +410,9 @@ class AggDrawTarget virtual Agg2DBase::ImageResample imageResample() = 0; static const agg::int8u* lookupFont(const std::string& name); virtual void setFont(const std::string& name) = 0; +#ifdef AGG2D_USE_VECTORFONTS + virtual void setVectorFont(const std::string& fileName, int size, bool bold) = 0; +#endif virtual void renderText(double dstX, double dstY, const std::string& str) = 0; virtual void renderTextDropshadowed(double dstX, double dstY, const std::string& str) { @@ -427,6 +432,29 @@ class AggDrawTarget lineColor(lineColorOld); renderText(dstX,dstY,str); } +#ifdef AGG2D_USE_VECTORFONTS + virtual void renderVectorFontText(double dstX, double dstY, const std::string& str) = 0; + virtual void renderVectorFontTextDropshadowed(double dstX, double dstY, const std::string& str, int shadowOffset = 1) + { + AggColor lineColorOld = lineColor(); + if(lineColorOld.r+lineColorOld.g+lineColorOld.b<192) + lineColor(255-lineColorOld.r,255-lineColorOld.g,255-lineColorOld.b); + else + lineColor(0,0,0); + fillColor(lineColor()); + renderVectorFontText(dstX-shadowOffset,dstY-shadowOffset,str); + renderVectorFontText(dstX,dstY-shadowOffset,str); + renderVectorFontText(dstX+shadowOffset,dstY-shadowOffset,str); + renderVectorFontText(dstX-shadowOffset,dstY,str); + renderVectorFontText(dstX+shadowOffset,dstY,str); + renderVectorFontText(dstX-shadowOffset,dstY+shadowOffset,str); + renderVectorFontText(dstX,dstY+shadowOffset,str); + renderVectorFontText(dstX+shadowOffset,dstY+shadowOffset,str); + lineColor(lineColorOld); + fillColor(lineColor()); + renderVectorFontText(dstX,dstY,str); + } +#endif // Auxiliary @@ -458,6 +486,13 @@ class AggDrawTargetImplementation : public AggDrawTarget, public Agg2D #include #include +#include #include "types.h" #include "firmware.h" @@ -127,6 +128,15 @@ enum { SUB_OBJ }; +#ifdef AGG2D_USE_VECTORFONTS +#define VECTOR_FONT_BASE_SIZE 6 +#endif + +static FcConfig* fontConfig; +static std::string vectorFontFile; + +static std::string FindFontFile(const char* fontName, bool bold); + gboolean EmuLoop(gpointer data); static AVOutX264 avout_x264; @@ -1449,7 +1459,7 @@ static void RedrawScreen() { GPU->GetDisplayInfo().isCustomSizeRequested ? (u16*)(GPU->GetDisplayInfo().masterCustomBuffer) : GPU->GetDisplayInfo().masterNativeBuffer16, (uint32_t *)video->GetSrcBufferPtr(), real_framebuffer_width * real_framebuffer_height * 2); #ifdef HAVE_LIBAGG - aggDraw.hud->attach((u8*)video->GetSrcBufferPtr(), real_framebuffer_width, real_framebuffer_height * 2, 1024 * gpu_scale_factor); + aggDraw.hud->setDrawTargetDims((u8*)video->GetSrcBufferPtr(), real_framebuffer_width, real_framebuffer_height * 2, real_framebuffer_width * 4); osd->update(); DrawHUD(); osd->clear(); @@ -1471,33 +1481,33 @@ static gboolean rotoscaled_hudedit(gint x, gint y, gboolean start) devX = x; devY = y; cairo_matrix_transform_point(&nds_screen.topscreen_matrix, &devX, &devY); - topX = devX; - topY = devY; + topX = devX * gpu_scale_factor; + topY = devY * gpu_scale_factor; } if (nds_screen.orientation != ORIENT_SINGLE || nds_screen.swap) { devX = x; devY = y; cairo_matrix_transform_point(&nds_screen.touch_matrix, &devX, &devY); - botX = devX; - botY = devY; + botX = devX * gpu_scale_factor; + botY = devY * gpu_scale_factor; } - if (topX >= 0 && topY >= 0 && topX < 256 && topY < 192) { + if (topX >= 0 && topY >= 0 && topX < real_framebuffer_width && topY < real_framebuffer_height) { X = topX; - Y = topY + (nds_screen.swap ? 192 : 0); + Y = topY + (nds_screen.swap ? real_framebuffer_height : 0); startScreen = 0; - } else if (botX >= 0 && botY >= 0 && botX < 256 && botY < 192) { + } else if (botX >= 0 && botY >= 0 && botX < real_framebuffer_width && botY < real_framebuffer_height) { X = botX; - Y = botY + (nds_screen.swap ? 0 : 192); + Y = botY + (nds_screen.swap ? 0 : real_framebuffer_height); startScreen = 1; } else if (!start) { if (startScreen == 0) { - X = CLAMP(topX, 0, 255); - Y = CLAMP(topY, 0, 191) + (nds_screen.swap ? 192 : 0); + X = CLAMP(topX, 0, real_framebuffer_width-1); + Y = CLAMP(topY, 0, real_framebuffer_height-1) + (nds_screen.swap ? real_framebuffer_height : 0); } else { - X = CLAMP(botX, 0, 255); - Y = CLAMP(botY, 0, 191) + (nds_screen.swap ? 0 : 192); + X = CLAMP(botX, 0, real_framebuffer_width-1); + Y = CLAMP(botY, 0, real_framebuffer_height-1) + (nds_screen.swap ? 0 : real_framebuffer_height); } } else { LOG("TopX=%d, TopY=%d, BotX=%d, BotY=%d\n", topX, topY, botX, botY); @@ -2098,6 +2108,7 @@ static void GraphicsSettingsDialog(GSimpleAction *action, GVariant *parameter, g default: break; } + double old_scale_factor = gpu_scale_factor; gpu_scale_factor = gtk_spin_button_get_value(wGPUScale); if(gpu_scale_factor < GPU_SCALE_FACTOR_MIN) gpu_scale_factor = GPU_SCALE_FACTOR_MIN; @@ -2109,6 +2120,20 @@ static void GraphicsSettingsDialog(GSimpleAction *action, GVariant *parameter, g real_framebuffer_height = GPU_FRAMEBUFFER_NATIVE_HEIGHT * gpu_scale_factor; GPU->SetCustomFramebufferSize(real_framebuffer_width, real_framebuffer_height); video->SetSourceSize(real_framebuffer_width, real_framebuffer_height * 2); +#ifdef HAVE_LIBAGG +#ifdef AGG2D_USE_VECTORFONTS + if(vectorFontFile.size() > 0) + { + aggDraw.hud->setVectorFont(vectorFontFile, VECTOR_FONT_BASE_SIZE * gpu_scale_factor, true); + osd->useVectorFonts=true; + } + else + osd->useVectorFonts=false; +#endif + Agg_setCustomSize(real_framebuffer_width, real_framebuffer_height*2); + osd->scale=gpu_scale_factor; + Hud.rescale(old_scale_factor, gpu_scale_factor); +#endif CommonSettings.GFX3D_Renderer_TextureDeposterize = config.textureDeposterize = gtk_toggle_button_get_active(wPosterize); CommonSettings.GFX3D_Renderer_TextureSmoothing = config.textureSmoothing = gtk_toggle_button_get_active(wSmoothing); CommonSettings.GFX3D_Renderer_TextureScalingFactor = config.textureUpscale = scale; @@ -3067,6 +3092,20 @@ common_gtk_main(GApplication *app, gpointer user_data) g_printerr("Using %d threads for video filter.\n", CommonSettings.num_cores); GPU->SetCustomFramebufferSize(real_framebuffer_width, real_framebuffer_height); video = new VideoFilter(real_framebuffer_width, real_framebuffer_height * 2, VideoFilterTypeID_None, CommonSettings.num_cores); +#ifdef HAVE_LIBAGG +#ifdef AGG2D_USE_VECTORFONTS + if(vectorFontFile.size() > 0) + { + aggDraw.hud->setVectorFont(vectorFontFile, VECTOR_FONT_BASE_SIZE * gpu_scale_factor, true); + osd->useVectorFonts=true; + } + else + osd->useVectorFonts=false; +#endif + Agg_setCustomSize(real_framebuffer_width, real_framebuffer_height*2); + osd->scale=gpu_scale_factor; + Hud.reset(); +#endif /* Fetch the main elements from the window */ GtkBuilder *builder = gtk_builder_new_from_resource("/org/desmume/DeSmuME/main.ui"); @@ -3644,9 +3683,38 @@ handle_open(GApplication *application, common_gtk_main(application, user_data); } +static std::string FindFontFile(const char* fontName, bool bold) +{ + std::string fontFile; + FcPattern* pat = FcNameParse((const FcChar8*)fontName); + if(bold) + FcPatternAddInteger(pat, FC_WEIGHT, FC_WEIGHT_BOLD); + FcConfigSubstitute(fontConfig, pat, FcMatchPattern); + FcDefaultSubstitute(pat); + + // find the font + FcResult res; + FcPattern* font = FcFontMatch(fontConfig, pat, &res); + if (font) + { + FcChar8* file = NULL; + if (FcPatternGetString(font, FC_FILE, 0, &file) == FcResultMatch) + { + // save the file to another std::string + fontFile = (char*)file; + } + FcPatternDestroy(font); + } + FcPatternDestroy(pat); + return fontFile; +} + int main (int argc, char *argv[]) { configured_features my_config; + + fontConfig = FcInitLoadConfigAndFonts(); + vectorFontFile = FindFontFile("mono", true); // The global menu screws up the window size... unsetenv("UBUNTU_MENUPROXY"); diff --git a/desmume/src/frontend/posix/gtk/meson.build b/desmume/src/frontend/posix/gtk/meson.build index 99d6fd1dc..d124e3000 100644 --- a/desmume/src/frontend/posix/gtk/meson.build +++ b/desmume/src/frontend/posix/gtk/meson.build @@ -1,7 +1,8 @@ dep_gtk3 = dependency('gtk+-3.0', version: '>=3.24') dep_x11 = dependency('x11') +dep_fontconfig = dependency('fontconfig') -gtk_dependencies = dependencies + [dep_gtk3, dep_x11] +gtk_dependencies = dependencies + [dep_gtk3, dep_x11, dep_fontconfig] gnome = import('gnome') diff --git a/desmume/src/frontend/posix/meson.build b/desmume/src/frontend/posix/meson.build index 89e0e4bef..e9df3f5ee 100644 --- a/desmume/src/frontend/posix/meson.build +++ b/desmume/src/frontend/posix/meson.build @@ -10,6 +10,8 @@ project('desmume', license: 'GPL2+', ) +add_global_arguments('-DHOST_LINUX', language: ['c', 'cpp']) + dep_glib2 = dependency('glib-2.0') dep_sdl = dependency('sdl2') dep_pcap = dependency('pcap') @@ -203,6 +205,10 @@ endif if dep_agg.found() dependencies += dep_agg add_global_arguments('-DHAVE_LIBAGG', language: ['c', 'cpp']) + if get_option('frontend-gtk') + add_global_arguments('-DAGG2D_USE_VECTORFONTS', language: ['c', 'cpp']) + add_global_link_arguments('-laggfontfreetype', language: ['c', 'cpp']) + endif libdesmume_src += [ '../modules/osd/agg/aggdraw.cpp', '../modules/osd/agg/agg_osd.cpp', From ddd800493cc7462750559415e0e6250f7eab7393 Mon Sep 17 00:00:00 2001 From: thesource Date: Thu, 1 Feb 2024 18:18:03 +0300 Subject: [PATCH 2/8] Scale save slot indicator (oops), make text outlines look smoother, use larger font when not scaling --- desmume/src/frontend/modules/osd/agg/agg_osd.cpp | 14 +++++++------- desmume/src/frontend/modules/osd/agg/aggdraw.h | 3 ++- desmume/src/frontend/posix/gtk/main.cpp | 4 ++-- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/desmume/src/frontend/modules/osd/agg/agg_osd.cpp b/desmume/src/frontend/modules/osd/agg/agg_osd.cpp index ecaba59d1..b1ac1ba73 100644 --- a/desmume/src/frontend/modules/osd/agg/agg_osd.cpp +++ b/desmume/src/frontend/modules/osd/agg/agg_osd.cpp @@ -561,24 +561,24 @@ static void DrawStateSlots(){ if(alpha!=0) { - aggDraw.hud->lineWidth(1.0); + aggDraw.hud->lineWidth(osd->scale); aggDraw.hud->lineColor(0, 0, 0, alpha); aggDraw.hud->fillColor(255, 255, 255, alpha); - for ( int i = 0, xpos=0; i < 10; xpos=xpos+24) { + for ( int i = 0, xpos=0; i < 10; xpos=xpos+24*osd->scale) { int yheight=0; - aggDraw.hud->fillLinearGradient(xloc + xpos, yloc - yheight, xloc + 22 + xpos, yloc + 20 + yheight+20, agg::rgba8(100,200,255,alpha), agg::rgba8(255,255,255,0)); + aggDraw.hud->fillLinearGradient(xloc + xpos, yloc - yheight, xloc + 22*osd->scale + xpos, yloc + 20*osd->scale + yheight+20*osd->scale, agg::rgba8(100,200,255,alpha), agg::rgba8(255,255,255,0)); if(lastSaveState == i) { - yheight = 5; - aggDraw.hud->fillLinearGradient(xloc + xpos, yloc - yheight, 22 + xloc + xpos, yloc + 20 + yheight+20, agg::rgba8(100,255,255,alpha), agg::rgba8(255,255,255,0)); + yheight = 5*osd->scale; + aggDraw.hud->fillLinearGradient(xloc + xpos, yloc - yheight, 22*osd->scale + xloc + xpos, yloc + 20*osd->scale + yheight+20*osd->scale, agg::rgba8(100,255,255,alpha), agg::rgba8(255,255,255,0)); } - aggDraw.hud->rectangle(xloc + xpos , yloc - yheight, xloc + 22 + xpos , yloc + 20 + yheight); + aggDraw.hud->rectangle(xloc + xpos , yloc - yheight, xloc + 22*osd->scale + xpos , yloc + 20*osd->scale + yheight); snprintf(number, 10, "%d", i); - RenderTextAutoVector(xloc + 1 + xpos + 4, yloc+4, std::string(number), true, osd ? osd->scale : 1); + RenderTextAutoVector(xloc + osd->scale + xpos + 4*osd->scale, yloc+4*osd->scale, std::string(number), true, osd->scale); i++; } } diff --git a/desmume/src/frontend/modules/osd/agg/aggdraw.h b/desmume/src/frontend/modules/osd/agg/aggdraw.h index a3813c670..557b17e5b 100644 --- a/desmume/src/frontend/modules/osd/agg/aggdraw.h +++ b/desmume/src/frontend/modules/osd/agg/aggdraw.h @@ -434,8 +434,9 @@ class AggDrawTarget } #ifdef AGG2D_USE_VECTORFONTS virtual void renderVectorFontText(double dstX, double dstY, const std::string& str) = 0; - virtual void renderVectorFontTextDropshadowed(double dstX, double dstY, const std::string& str, int shadowOffset = 1) + virtual void renderVectorFontTextDropshadowed(double dstX, double dstY, const std::string& str, double shadowOffset = 1.0) { + shadowOffset*=0.5; AggColor lineColorOld = lineColor(); if(lineColorOld.r+lineColorOld.g+lineColorOld.b<192) lineColor(255-lineColorOld.r,255-lineColorOld.g,255-lineColorOld.b); diff --git a/desmume/src/frontend/posix/gtk/main.cpp b/desmume/src/frontend/posix/gtk/main.cpp index 87f1c1ff2..4ad159a68 100644 --- a/desmume/src/frontend/posix/gtk/main.cpp +++ b/desmume/src/frontend/posix/gtk/main.cpp @@ -2124,7 +2124,7 @@ static void GraphicsSettingsDialog(GSimpleAction *action, GVariant *parameter, g #ifdef AGG2D_USE_VECTORFONTS if(vectorFontFile.size() > 0) { - aggDraw.hud->setVectorFont(vectorFontFile, VECTOR_FONT_BASE_SIZE * gpu_scale_factor, true); + aggDraw.hud->setVectorFont(vectorFontFile, std::max(10.0f, VECTOR_FONT_BASE_SIZE * gpu_scale_factor), true); osd->useVectorFonts=true; } else @@ -3096,7 +3096,7 @@ common_gtk_main(GApplication *app, gpointer user_data) #ifdef AGG2D_USE_VECTORFONTS if(vectorFontFile.size() > 0) { - aggDraw.hud->setVectorFont(vectorFontFile, VECTOR_FONT_BASE_SIZE * gpu_scale_factor, true); + aggDraw.hud->setVectorFont(vectorFontFile, std::max(10.0f, VECTOR_FONT_BASE_SIZE * gpu_scale_factor), true); osd->useVectorFonts=true; } else From 17509e0e36d25b2feb630d1001603b3647e37e20 Mon Sep 17 00:00:00 2001 From: thesource Date: Fri, 2 Feb 2024 18:49:10 +0300 Subject: [PATCH 3/8] Save and load HUD layout, prefer raster font on low resolution, select vector font size close to raster one, make OSDCLASS::scale floating point --- .../src/frontend/modules/osd/agg/agg_osd.cpp | 14 ++-- .../src/frontend/modules/osd/agg/agg_osd.h | 2 +- desmume/src/frontend/posix/gtk/config.cpp | 19 ++++++ desmume/src/frontend/posix/gtk/config_opts.h | 1 + desmume/src/frontend/posix/gtk/main.cpp | 68 +++++++++++++++++-- 5 files changed, 89 insertions(+), 15 deletions(-) diff --git a/desmume/src/frontend/modules/osd/agg/agg_osd.cpp b/desmume/src/frontend/modules/osd/agg/agg_osd.cpp index b1ac1ba73..5534ad0ab 100644 --- a/desmume/src/frontend/modules/osd/agg/agg_osd.cpp +++ b/desmume/src/frontend/modules/osd/agg/agg_osd.cpp @@ -89,7 +89,7 @@ static T calcY(T y) // alters a GUI element y coordinate as necessary to obey sw return y; } -static void RenderTextAutoVector(double x, double y, const std::string& str, bool shadow = true, int shadowOffset = 1) +static void RenderTextAutoVector(double x, double y, const std::string& str, bool shadow = true, double shadowOffset = 1.0) { #ifdef AGG2D_USE_VECTORFONTS bool render_vect = false; @@ -174,7 +174,7 @@ void HudClickRelease(HudStruct *hudstruct) { void HudStruct::reset() { - int sc=(osd ? osd->scale : 1); + double sc=(osd ? osd->scale : 1.0); FpsDisplay.x=0; FpsDisplay.y=5*sc; @@ -505,8 +505,8 @@ static void OSD_HandleTouchDisplay() { // note: calcY should not be used in this function. aggDraw.hud->lineWidth(osd->scale); - temptouch.X = NDS_getRawUserInput().touch.touchX >> 4 * osd->scale; - temptouch.Y = NDS_getRawUserInput().touch.touchY >> 4 * osd->scale; + temptouch.X = (NDS_getRawUserInput().touch.touchX >> 4) * osd->scale; + temptouch.Y = (NDS_getRawUserInput().touch.touchY >> 4) * osd->scale; if(touchshadow) { @@ -709,7 +709,7 @@ OSDCLASS::OSDCLASS(u8 core) singleScreen = false; swapScreens = false; - scale=1; + scale = 1.0; needUpdate = false; #ifdef AGG2D_USE_VECTORFONTS useVectorFonts = false; @@ -794,7 +794,7 @@ void OSDCLASS::update() for (int i=0; i < lastLineText; i++) { aggDraw.hud->lineColor(lineColor[i]); - RenderTextAutoVector(lineText_x, lineText_y+(i*16), lineText[i], true, osd ? osd->scale : 1); + RenderTextAutoVector(lineText_x, lineText_y+(i*16), lineText[i], true, osd->scale); } } else @@ -876,7 +876,7 @@ void OSDCLASS::addFixed(u16 x, u16 y, const char *fmt, ...) va_end(list); aggDraw.hud->lineColor(255,255,255); - RenderTextAutoVector(x, calcY(y), msg, true, osd ? osd->scale : 1); + RenderTextAutoVector(x, calcY(y), msg, true, osd->scale); needUpdate = true; } diff --git a/desmume/src/frontend/modules/osd/agg/agg_osd.h b/desmume/src/frontend/modules/osd/agg/agg_osd.h index f7a306f32..4077a1eb2 100644 --- a/desmume/src/frontend/modules/osd/agg/agg_osd.h +++ b/desmume/src/frontend/modules/osd/agg/agg_osd.h @@ -112,7 +112,7 @@ class OSDCLASS char name[7]; // for debuging bool singleScreen; bool swapScreens; - int scale; + double scale; #ifdef AGG2D_USE_VECTORFONTS bool useVectorFonts; #endif diff --git a/desmume/src/frontend/posix/gtk/config.cpp b/desmume/src/frontend/posix/gtk/config.cpp index a0e593a5b..17a897563 100644 --- a/desmume/src/frontend/posix/gtk/config.cpp +++ b/desmume/src/frontend/posix/gtk/config.cpp @@ -97,6 +97,25 @@ void value::save() { g_key_file_set_string(this->mKeyFile, this->mSection.c_str(), this->mKey.c_str(), this->mData.c_str()); } +/* class value > */ + +template<> +void value >::load() { + gsize l; + int* val = g_key_file_get_integer_list(this->mKeyFile, this->mSection.c_str(), this->mKey.c_str(), &l, NULL); + if(val) + { + this->mData.resize(l); + std::copy(val, val+l, this->mData.begin()); + g_free(val); + } +} + +template<> +void value >::save() { + g_key_file_set_integer_list(this->mKeyFile, this->mSection.c_str(), this->mKey.c_str(), this->mData.data(), this->mData.size()); +} + /* class Config */ Config::Config() diff --git a/desmume/src/frontend/posix/gtk/config_opts.h b/desmume/src/frontend/posix/gtk/config_opts.h index 7481ab634..72f0f5249 100644 --- a/desmume/src/frontend/posix/gtk/config_opts.h +++ b/desmume/src/frontend/posix/gtk/config_opts.h @@ -49,6 +49,7 @@ OPT(hud_input, bool, false, HudDisplay, Input) OPT(hud_graphicalInput, bool, false, HudDisplay, GraphicalInput) OPT(hud_rtc, bool, false, HudDisplay, RTC) OPT(hud_mic, bool, false, HudDisplay, Mic) +OPT(hud_layout, std::vector, std::vector(), HudDisplay, Layout) /* Config */ OPT(fpslimiter, bool, true, Config, FpsLimiter) diff --git a/desmume/src/frontend/posix/gtk/main.cpp b/desmume/src/frontend/posix/gtk/main.cpp index 4ad159a68..b25c0cc7c 100644 --- a/desmume/src/frontend/posix/gtk/main.cpp +++ b/desmume/src/frontend/posix/gtk/main.cpp @@ -129,7 +129,7 @@ enum { }; #ifdef AGG2D_USE_VECTORFONTS -#define VECTOR_FONT_BASE_SIZE 6 +#define VECTOR_FONT_BASE_SIZE 16 #endif static FcConfig* fontConfig; @@ -200,6 +200,8 @@ static void HudLagCounter(GSimpleAction *action, GVariant *parameter, gpointer u static void HudRtc(GSimpleAction *action, GVariant *parameter, gpointer user_data); static void HudMic(GSimpleAction *action, GVariant *parameter, gpointer user_data); static void HudEditor(GSimpleAction *action, GVariant *parameter, gpointer user_data); +static void HudSaveLayout(); +static void HudLoadLayout(); #endif #ifdef DESMUME_GTK_FIRMWARE_BROKEN static void SelectFirmwareFile(GSimpleAction *action, GVariant *parameter, gpointer user_data); @@ -2124,8 +2126,8 @@ static void GraphicsSettingsDialog(GSimpleAction *action, GVariant *parameter, g #ifdef AGG2D_USE_VECTORFONTS if(vectorFontFile.size() > 0) { - aggDraw.hud->setVectorFont(vectorFontFile, std::max(10.0f, VECTOR_FONT_BASE_SIZE * gpu_scale_factor), true); - osd->useVectorFonts=true; + aggDraw.hud->setVectorFont(vectorFontFile, VECTOR_FONT_BASE_SIZE * gpu_scale_factor, true); + osd->useVectorFonts=(gpu_scale_factor >= 1.1); } else osd->useVectorFonts=false; @@ -2133,6 +2135,7 @@ static void GraphicsSettingsDialog(GSimpleAction *action, GVariant *parameter, g Agg_setCustomSize(real_framebuffer_width, real_framebuffer_height*2); osd->scale=gpu_scale_factor; Hud.rescale(old_scale_factor, gpu_scale_factor); + HudSaveLayout(); #endif CommonSettings.GFX3D_Renderer_TextureDeposterize = config.textureDeposterize = gtk_toggle_button_get_active(wPosterize); CommonSettings.GFX3D_Renderer_TextureSmoothing = config.textureSmoothing = gtk_toggle_button_get_active(wSmoothing); @@ -2798,6 +2801,8 @@ static void ToggleHudDisplay(hud_display_enum hudId, gboolean active) break; case HUD_DISPLAY_EDITOR: HudEditorMode = active; + if(!active) + HudSaveLayout(); break; default: g_printerr("Unknown HUD toggle %u!", hudId); @@ -2824,6 +2829,54 @@ HudMacro(HudRtc, HUD_DISPLAY_RTC) HudMacro(HudMic, HUD_DISPLAY_MIC) HudMacro(HudEditor, HUD_DISPLAY_EDITOR) +static void HudSaveCoordsToVector(HudCoordinates* pCoords, int* pDest) +{ + pDest[0]=pCoords->x; + pDest[1]=pCoords->y; + pDest[2]=pCoords->xsize; + pDest[3]=pCoords->ysize; +} + +static void HudLoadCoordsFromVector(HudCoordinates* pCoords, int* pSrc) +{ + pCoords->x=pSrc[0]; + pCoords->y=pSrc[1]; + pCoords->xsize=pSrc[2]; + pCoords->ysize=pSrc[3]; +} + +static void HudSaveLayout() +{ + std::vector vec(8*4); //8 HudCoordinates + HudSaveCoordsToVector(&Hud.SavestateSlots, vec.data()); + HudSaveCoordsToVector(&Hud.FpsDisplay, vec.data()+4); + HudSaveCoordsToVector(&Hud.FrameCounter, vec.data()+8); + HudSaveCoordsToVector(&Hud.InputDisplay, vec.data()+12); + HudSaveCoordsToVector(&Hud.GraphicalInputDisplay, vec.data()+16); + HudSaveCoordsToVector(&Hud.LagFrameCounter, vec.data()+20); + HudSaveCoordsToVector(&Hud.Microphone, vec.data()+24); + HudSaveCoordsToVector(&Hud.RTCDisplay, vec.data()+28); + config.hud_layout=vec; +} + +static void HudLoadLayout() +{ + std::vector vec=config.hud_layout; + if(vec.size()==8*4) + { + HudLoadCoordsFromVector(&Hud.SavestateSlots, vec.data()); + HudLoadCoordsFromVector(&Hud.FpsDisplay, vec.data()+4); + HudLoadCoordsFromVector(&Hud.FrameCounter, vec.data()+8); + HudLoadCoordsFromVector(&Hud.InputDisplay, vec.data()+12); + HudLoadCoordsFromVector(&Hud.GraphicalInputDisplay, vec.data()+16); + HudLoadCoordsFromVector(&Hud.LagFrameCounter, vec.data()+20); + HudLoadCoordsFromVector(&Hud.Microphone, vec.data()+24); + HudLoadCoordsFromVector(&Hud.RTCDisplay, vec.data()+28); + } + else + Hud.reset(); +} + static void desmume_gtk_menu_view_hud(GtkApplication *app) { const struct { @@ -3096,15 +3149,15 @@ common_gtk_main(GApplication *app, gpointer user_data) #ifdef AGG2D_USE_VECTORFONTS if(vectorFontFile.size() > 0) { - aggDraw.hud->setVectorFont(vectorFontFile, std::max(10.0f, VECTOR_FONT_BASE_SIZE * gpu_scale_factor), true); - osd->useVectorFonts=true; + aggDraw.hud->setVectorFont(vectorFontFile, VECTOR_FONT_BASE_SIZE * gpu_scale_factor, true); + osd->useVectorFonts=(gpu_scale_factor >= 1.1); } else osd->useVectorFonts=false; #endif Agg_setCustomSize(real_framebuffer_width, real_framebuffer_height*2); osd->scale=gpu_scale_factor; - Hud.reset(); + HudLoadLayout(); #endif /* Fetch the main elements from the window */ @@ -3640,7 +3693,8 @@ common_gtk_main(GApplication *app, gpointer user_data) static void Teardown() { delete video; - + + HudSaveLayout(); config.save(); avout_x264.end(); avout_flac.end(); From 7252e1cc9dba05da7747204b035d1afa99516612 Mon Sep 17 00:00:00 2001 From: thesource Date: Fri, 2 Feb 2024 18:59:24 +0300 Subject: [PATCH 4/8] Build fix --- desmume/src/frontend/posix/gtk/main.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/desmume/src/frontend/posix/gtk/main.cpp b/desmume/src/frontend/posix/gtk/main.cpp index b25c0cc7c..4abd9d8ec 100644 --- a/desmume/src/frontend/posix/gtk/main.cpp +++ b/desmume/src/frontend/posix/gtk/main.cpp @@ -3693,8 +3693,9 @@ common_gtk_main(GApplication *app, gpointer user_data) static void Teardown() { delete video; - +#ifdef HAVE_LIBAGG HudSaveLayout(); +#endif config.save(); avout_x264.end(); avout_flac.end(); From 25a5d683acb0afbca653a252f74b7d6e9ee0fe6a Mon Sep 17 00:00:00 2001 From: thesource Date: Sat, 3 Feb 2024 19:28:24 +0300 Subject: [PATCH 5/8] Add reset HUD layout action, only require fontconfig if libagg is found. --- desmume/src/frontend/posix/gtk/main.cpp | 21 +++++++++++++++++++-- desmume/src/frontend/posix/gtk/menu.ui | 4 ++++ desmume/src/frontend/posix/gtk/meson.build | 8 ++++++-- 3 files changed, 29 insertions(+), 4 deletions(-) diff --git a/desmume/src/frontend/posix/gtk/main.cpp b/desmume/src/frontend/posix/gtk/main.cpp index 4abd9d8ec..ea725b133 100644 --- a/desmume/src/frontend/posix/gtk/main.cpp +++ b/desmume/src/frontend/posix/gtk/main.cpp @@ -31,7 +31,9 @@ #include #include #include +#ifdef HAVE_LIBAGG #include +#endif #include "types.h" #include "firmware.h" @@ -128,6 +130,7 @@ enum { SUB_OBJ }; +#ifdef HAVE_LIBAGG #ifdef AGG2D_USE_VECTORFONTS #define VECTOR_FONT_BASE_SIZE 16 #endif @@ -136,6 +139,7 @@ static FcConfig* fontConfig; static std::string vectorFontFile; static std::string FindFontFile(const char* fontName, bool bold); +#endif gboolean EmuLoop(gpointer data); @@ -200,6 +204,7 @@ static void HudLagCounter(GSimpleAction *action, GVariant *parameter, gpointer u static void HudRtc(GSimpleAction *action, GVariant *parameter, gpointer user_data); static void HudMic(GSimpleAction *action, GVariant *parameter, gpointer user_data); static void HudEditor(GSimpleAction *action, GVariant *parameter, gpointer user_data); +static void HudResetLayout(GSimpleAction *action, GVariant *parameter, gpointer user_data); static void HudSaveLayout(); static void HudLoadLayout(); #endif @@ -259,6 +264,7 @@ static const GActionEntry app_entries[] = { { "hud_rtc", HudRtc, NULL, "false" }, { "hud_mic", HudMic, NULL, "false" }, { "hud_editor", HudEditor, NULL, "false" }, + { "hud_reset_layout", HudResetLayout}, #endif // Config @@ -2829,6 +2835,12 @@ HudMacro(HudRtc, HUD_DISPLAY_RTC) HudMacro(HudMic, HUD_DISPLAY_MIC) HudMacro(HudEditor, HUD_DISPLAY_EDITOR) +static void HudResetLayout(GSimpleAction *action, GVariant *parameter, gpointer user_data) +{ + Hud.reset(); + HudSaveLayout(); +} + static void HudSaveCoordsToVector(HudCoordinates* pCoords, int* pDest) { pDest[0]=pCoords->x; @@ -3738,6 +3750,8 @@ handle_open(GApplication *application, common_gtk_main(application, user_data); } +#ifdef HAVE_LIBAGG + static std::string FindFontFile(const char* fontName, bool bold) { std::string fontFile; @@ -3764,13 +3778,16 @@ static std::string FindFontFile(const char* fontName, bool bold) return fontFile; } +#endif + int main (int argc, char *argv[]) { configured_features my_config; - + +#ifdef HAVE_LIBAGG fontConfig = FcInitLoadConfigAndFonts(); vectorFontFile = FindFontFile("mono", true); - +#endif // The global menu screws up the window size... unsetenv("UBUNTU_MENUPROXY"); diff --git a/desmume/src/frontend/posix/gtk/menu.ui b/desmume/src/frontend/posix/gtk/menu.ui index db28d2ae7..807efa898 100644 --- a/desmume/src/frontend/posix/gtk/menu.ui +++ b/desmume/src/frontend/posix/gtk/menu.ui @@ -834,6 +834,10 @@ _Editor mode app.hud_editor + + Reset layout + app.hud_reset_layout + diff --git a/desmume/src/frontend/posix/gtk/meson.build b/desmume/src/frontend/posix/gtk/meson.build index d124e3000..c38607ea5 100644 --- a/desmume/src/frontend/posix/gtk/meson.build +++ b/desmume/src/frontend/posix/gtk/meson.build @@ -1,8 +1,12 @@ dep_gtk3 = dependency('gtk+-3.0', version: '>=3.24') dep_x11 = dependency('x11') -dep_fontconfig = dependency('fontconfig') -gtk_dependencies = dependencies + [dep_gtk3, dep_x11, dep_fontconfig] +gtk_dependencies = dependencies + [dep_gtk3, dep_x11] + +if dep_agg.found() + dep_fontconfig = dependency('fontconfig') + gtk_dependencies = gtk_dependencies + [dep_fontconfig] +endif gnome = import('gnome') From 30979d186c59b5cd0360c352cb063f2628e4cdb5 Mon Sep 17 00:00:00 2001 From: thesource Date: Mon, 5 Feb 2024 19:54:28 +0300 Subject: [PATCH 6/8] Try another font in case we could not locate monospace --- desmume/src/frontend/posix/gtk/main.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/desmume/src/frontend/posix/gtk/main.cpp b/desmume/src/frontend/posix/gtk/main.cpp index ea725b133..8d6ab323a 100644 --- a/desmume/src/frontend/posix/gtk/main.cpp +++ b/desmume/src/frontend/posix/gtk/main.cpp @@ -3787,6 +3787,8 @@ int main (int argc, char *argv[]) #ifdef HAVE_LIBAGG fontConfig = FcInitLoadConfigAndFonts(); vectorFontFile = FindFontFile("mono", true); + if(!vectorFontFile.size()) + vectorFontFile = FindFontFile("sans", true); #endif // The global menu screws up the window size... unsetenv("UBUNTU_MENUPROXY"); From 21cceaffe31f6d5f984301482d7f2ea616eb299d Mon Sep 17 00:00:00 2001 From: thesource Date: Tue, 13 Feb 2024 18:34:33 +0300 Subject: [PATCH 7/8] Detect screen bytes per pixel instead of hardcoding it, define AGG2D_USE_VECTORFONTS if fontconfig is found. --- desmume/src/frontend/modules/osd/agg/aggdraw.cpp | 13 ++----------- desmume/src/frontend/modules/osd/agg/aggdraw.h | 1 + desmume/src/frontend/posix/gtk/main.cpp | 11 ++++++----- desmume/src/frontend/posix/gtk/meson.build | 5 ----- desmume/src/frontend/posix/meson.build | 6 +++--- 5 files changed, 12 insertions(+), 24 deletions(-) diff --git a/desmume/src/frontend/modules/osd/agg/aggdraw.cpp b/desmume/src/frontend/modules/osd/agg/aggdraw.cpp index d8aa1008f..7da6b1c84 100644 --- a/desmume/src/frontend/modules/osd/agg/aggdraw.cpp +++ b/desmume/src/frontend/modules/osd/agg/aggdraw.cpp @@ -118,11 +118,7 @@ static void Agg_init_fonts() AggDraw_Desmume aggDraw; -#if defined(WIN32) || defined(HOST_LINUX) T_AGG_RGBA agg_targetScreen(0, GPU_FRAMEBUFFER_NATIVE_WIDTH, GPU_FRAMEBUFFER_NATIVE_HEIGHT*2, 1024); -#else -T_AGG_RGB555 agg_targetScreen(0, GPU_FRAMEBUFFER_NATIVE_WIDTH, GPU_FRAMEBUFFER_NATIVE_HEIGHT*2, 512); -#endif static std::vector luaBuffer(GPU_FRAMEBUFFER_NATIVE_WIDTH*GPU_FRAMEBUFFER_NATIVE_HEIGHT*2); T_AGG_RGBA agg_targetLua((u8*)luaBuffer.data(), GPU_FRAMEBUFFER_NATIVE_WIDTH, GPU_FRAMEBUFFER_NATIVE_HEIGHT*2, 1024); @@ -139,6 +135,7 @@ static AggDrawTarget* targets[] = { void Agg_init() { Agg_init_fonts(); + aggDraw.screenBytesPerPixel = 4; aggDraw.screen = targets[0]; aggDraw.hud = targets[1]; aggDraw.lua = targets[2]; @@ -167,13 +164,7 @@ void Agg_setCustomSize(int w, int h) hudBuffer.resize(w*h); luaBuffer.resize(w*h); if(aggDraw.screen) - { -#if defined(WIN32) || defined(HOST_LINUX) - aggDraw.screen->setDrawTargetDims(0, w, h, w*4); -#else - aggDraw.screen->setDrawTargetDims(0, w, h, w*2); -#endif - } + aggDraw.screen->setDrawTargetDims(0, w, h, w*aggDraw.screenBytesPerPixel); if(aggDraw.hud) aggDraw.hud->setDrawTargetDims((u8*)hudBuffer.data(), w, h, w*4); if(aggDraw.lua) diff --git a/desmume/src/frontend/modules/osd/agg/aggdraw.h b/desmume/src/frontend/modules/osd/agg/aggdraw.h index 557b17e5b..7f35428df 100644 --- a/desmume/src/frontend/modules/osd/agg/aggdraw.h +++ b/desmume/src/frontend/modules/osd/agg/aggdraw.h @@ -709,6 +709,7 @@ class AggDraw_Desmume : public AggDraw //void composite(void* dest); AggDrawTarget *screen, *hud, *lua; + int screenBytesPerPixel; }; extern AggDraw_Desmume aggDraw; diff --git a/desmume/src/frontend/posix/gtk/main.cpp b/desmume/src/frontend/posix/gtk/main.cpp index 8d6ab323a..b179a4a8c 100644 --- a/desmume/src/frontend/posix/gtk/main.cpp +++ b/desmume/src/frontend/posix/gtk/main.cpp @@ -31,7 +31,7 @@ #include #include #include -#ifdef HAVE_LIBAGG +#ifdef AGG2D_USE_VECTORFONTS #include #endif @@ -130,10 +130,8 @@ enum { SUB_OBJ }; -#ifdef HAVE_LIBAGG #ifdef AGG2D_USE_VECTORFONTS #define VECTOR_FONT_BASE_SIZE 16 -#endif static FcConfig* fontConfig; static std::string vectorFontFile; @@ -3167,6 +3165,9 @@ common_gtk_main(GApplication *app, gpointer user_data) else osd->useVectorFonts=false; #endif + SDL_DisplayMode cur_mode; + if(!SDL_GetCurrentDisplayMode(0, &cur_mode)) + aggDraw.screenBytesPerPixel = SDL_BYTESPERPIXEL(cur_mode.format); Agg_setCustomSize(real_framebuffer_width, real_framebuffer_height*2); osd->scale=gpu_scale_factor; HudLoadLayout(); @@ -3750,7 +3751,7 @@ handle_open(GApplication *application, common_gtk_main(application, user_data); } -#ifdef HAVE_LIBAGG +#ifdef AGG2D_USE_VECTORFONTS static std::string FindFontFile(const char* fontName, bool bold) { @@ -3784,7 +3785,7 @@ int main (int argc, char *argv[]) { configured_features my_config; -#ifdef HAVE_LIBAGG +#ifdef AGG2D_USE_VECTORFONTS fontConfig = FcInitLoadConfigAndFonts(); vectorFontFile = FindFontFile("mono", true); if(!vectorFontFile.size()) diff --git a/desmume/src/frontend/posix/gtk/meson.build b/desmume/src/frontend/posix/gtk/meson.build index c38607ea5..99d6fd1dc 100644 --- a/desmume/src/frontend/posix/gtk/meson.build +++ b/desmume/src/frontend/posix/gtk/meson.build @@ -3,11 +3,6 @@ dep_x11 = dependency('x11') gtk_dependencies = dependencies + [dep_gtk3, dep_x11] -if dep_agg.found() - dep_fontconfig = dependency('fontconfig') - gtk_dependencies = gtk_dependencies + [dep_fontconfig] -endif - gnome = import('gnome') gresource = gnome.compile_resources( diff --git a/desmume/src/frontend/posix/meson.build b/desmume/src/frontend/posix/meson.build index e9df3f5ee..13bf45a25 100644 --- a/desmume/src/frontend/posix/meson.build +++ b/desmume/src/frontend/posix/meson.build @@ -10,8 +10,6 @@ project('desmume', license: 'GPL2+', ) -add_global_arguments('-DHOST_LINUX', language: ['c', 'cpp']) - dep_glib2 = dependency('glib-2.0') dep_sdl = dependency('sdl2') dep_pcap = dependency('pcap') @@ -22,6 +20,7 @@ dep_openal = dependency('openal', required: get_option('openal')) dep_alsa = dependency('alsa', required: false) dep_soundtouch = dependency('soundtouch', required: false) dep_agg = dependency('libagg', required: false) +dep_fontconfig = dependency('fontconfig', required: false) # XXX: something wrong with this one. #dep_lua = dependency('lua-5.1', required: false) @@ -205,7 +204,8 @@ endif if dep_agg.found() dependencies += dep_agg add_global_arguments('-DHAVE_LIBAGG', language: ['c', 'cpp']) - if get_option('frontend-gtk') + if dep_fontconfig.found() + dependencies += dep_fontconfig add_global_arguments('-DAGG2D_USE_VECTORFONTS', language: ['c', 'cpp']) add_global_link_arguments('-laggfontfreetype', language: ['c', 'cpp']) endif From 7529f6bc9f15fe47c5e1402b34f610a32b135091 Mon Sep 17 00:00:00 2001 From: thesource Date: Wed, 14 Feb 2024 10:33:08 +0300 Subject: [PATCH 8/8] Different pixel formats are handled by different draw target implementations --- .../src/frontend/modules/osd/agg/aggdraw.cpp | 29 ++++++++++++++----- .../src/frontend/modules/osd/agg/aggdraw.h | 1 + desmume/src/frontend/posix/gtk/main.cpp | 7 +++-- 3 files changed, 27 insertions(+), 10 deletions(-) diff --git a/desmume/src/frontend/modules/osd/agg/aggdraw.cpp b/desmume/src/frontend/modules/osd/agg/aggdraw.cpp index 7da6b1c84..50758c8f1 100644 --- a/desmume/src/frontend/modules/osd/agg/aggdraw.cpp +++ b/desmume/src/frontend/modules/osd/agg/aggdraw.cpp @@ -118,16 +118,17 @@ static void Agg_init_fonts() AggDraw_Desmume aggDraw; -T_AGG_RGBA agg_targetScreen(0, GPU_FRAMEBUFFER_NATIVE_WIDTH, GPU_FRAMEBUFFER_NATIVE_HEIGHT*2, 1024); +T_AGG_RGBA agg_targetScreen_32bit(0, GPU_FRAMEBUFFER_NATIVE_WIDTH, GPU_FRAMEBUFFER_NATIVE_HEIGHT*2, GPU_FRAMEBUFFER_NATIVE_WIDTH*4); +T_AGG_RGB555 agg_targetScreen_16bit(0, GPU_FRAMEBUFFER_NATIVE_WIDTH, GPU_FRAMEBUFFER_NATIVE_HEIGHT*2, GPU_FRAMEBUFFER_NATIVE_WIDTH*2); static std::vector luaBuffer(GPU_FRAMEBUFFER_NATIVE_WIDTH*GPU_FRAMEBUFFER_NATIVE_HEIGHT*2); -T_AGG_RGBA agg_targetLua((u8*)luaBuffer.data(), GPU_FRAMEBUFFER_NATIVE_WIDTH, GPU_FRAMEBUFFER_NATIVE_HEIGHT*2, 1024); +T_AGG_RGBA agg_targetLua((u8*)luaBuffer.data(), GPU_FRAMEBUFFER_NATIVE_WIDTH, GPU_FRAMEBUFFER_NATIVE_HEIGHT*2, GPU_FRAMEBUFFER_NATIVE_WIDTH*4); static std::vector hudBuffer(GPU_FRAMEBUFFER_NATIVE_WIDTH*GPU_FRAMEBUFFER_NATIVE_HEIGHT*2); -T_AGG_RGBA agg_targetHud((u8*)hudBuffer.data(), GPU_FRAMEBUFFER_NATIVE_WIDTH, GPU_FRAMEBUFFER_NATIVE_HEIGHT*2, 1024); +T_AGG_RGBA agg_targetHud((u8*)hudBuffer.data(), GPU_FRAMEBUFFER_NATIVE_WIDTH, GPU_FRAMEBUFFER_NATIVE_HEIGHT*2, GPU_FRAMEBUFFER_NATIVE_WIDTH*4); static AggDrawTarget* targets[] = { - &agg_targetScreen, + &agg_targetScreen_32bit, &agg_targetHud, &agg_targetLua, }; @@ -135,7 +136,16 @@ static AggDrawTarget* targets[] = { void Agg_init() { Agg_init_fonts(); - aggDraw.screenBytesPerPixel = 4; + switch(aggDraw.screenBytesPerPixel) + { + case 2: + targets[0]=&agg_targetScreen_16bit; + break; + case 4: + targets[0]=&agg_targetScreen_32bit; + break; + } + aggDraw.screen = targets[0]; aggDraw.hud = targets[1]; aggDraw.lua = targets[2]; @@ -146,14 +156,19 @@ void Agg_init() //and the more clever compositing isnt supported in non-windows #ifdef WIN32 if(CommonSettings.single_core()) - aggDraw.hud = &agg_targetScreen; + aggDraw.hud = aggDraw.screen; #else - aggDraw.hud = &agg_targetScreen; + aggDraw.hud = aggDraw.screen; #endif aggDraw.hud->setFont("verdana18_bold"); } +AggDraw_Desmume::AggDraw_Desmume() +{ + screenBytesPerPixel = 4; +} + void AggDraw_Desmume::setTarget(AggTarget newTarget) { target = targets[newTarget]; diff --git a/desmume/src/frontend/modules/osd/agg/aggdraw.h b/desmume/src/frontend/modules/osd/agg/aggdraw.h index 7f35428df..692334fcf 100644 --- a/desmume/src/frontend/modules/osd/agg/aggdraw.h +++ b/desmume/src/frontend/modules/osd/agg/aggdraw.h @@ -705,6 +705,7 @@ enum AggTarget class AggDraw_Desmume : public AggDraw { public: + AggDraw_Desmume(); void setTarget(AggTarget newTarget); //void composite(void* dest); diff --git a/desmume/src/frontend/posix/gtk/main.cpp b/desmume/src/frontend/posix/gtk/main.cpp index b179a4a8c..f3e4c96d6 100644 --- a/desmume/src/frontend/posix/gtk/main.cpp +++ b/desmume/src/frontend/posix/gtk/main.cpp @@ -3086,6 +3086,10 @@ common_gtk_main(GApplication *app, gpointer user_data) /* Init the hud / osd stuff */ #ifdef HAVE_LIBAGG + SDL_DisplayMode cur_mode; + if(!SDL_GetCurrentDisplayMode(0, &cur_mode)) + aggDraw.screenBytesPerPixel = SDL_BYTESPERPIXEL(cur_mode.format); + Desmume_InitOnce(); Hud.reset(); osd = new OSDCLASS(-1); @@ -3165,9 +3169,6 @@ common_gtk_main(GApplication *app, gpointer user_data) else osd->useVectorFonts=false; #endif - SDL_DisplayMode cur_mode; - if(!SDL_GetCurrentDisplayMode(0, &cur_mode)) - aggDraw.screenBytesPerPixel = SDL_BYTESPERPIXEL(cur_mode.format); Agg_setCustomSize(real_framebuffer_width, real_framebuffer_height*2); osd->scale=gpu_scale_factor; HudLoadLayout();