Skip to content

Commit

Permalink
Save and load HUD layout, prefer raster font on low resolution, select
Browse files Browse the repository at this point in the history
vector font size close to raster one, make OSDCLASS::scale floating point
  • Loading branch information
thesourcehim committed Feb 2, 2024
1 parent ddd8004 commit 17509e0
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 15 deletions.
14 changes: 7 additions & 7 deletions desmume/src/frontend/modules/osd/agg/agg_osd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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) {

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion desmume/src/frontend/modules/osd/agg/agg_osd.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 19 additions & 0 deletions desmume/src/frontend/posix/gtk/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,25 @@ void value<string>::save() {
g_key_file_set_string(this->mKeyFile, this->mSection.c_str(), this->mKey.c_str(), this->mData.c_str());
}

/* class value<vector<int> > */

template<>
void value<vector<int> >::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<vector<int> >::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()
Expand Down
1 change: 1 addition & 0 deletions desmume/src/frontend/posix/gtk/config_opts.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>, std::vector<int>(), HudDisplay, Layout)

/* Config */
OPT(fpslimiter, bool, true, Config, FpsLimiter)
Expand Down
68 changes: 61 additions & 7 deletions desmume/src/frontend/posix/gtk/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -2124,15 +2126,16 @@ 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;
#endif
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);
Expand Down Expand Up @@ -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);
Expand All @@ -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<int> 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<int> 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 {
Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 17509e0

Please sign in to comment.