Skip to content

Commit

Permalink
win32: Get win32 working with variable font.
Browse files Browse the repository at this point in the history
  • Loading branch information
bearoso committed May 4, 2023
1 parent 8289c77 commit ebf2e99
Show file tree
Hide file tree
Showing 20 changed files with 225 additions and 289 deletions.
2 changes: 1 addition & 1 deletion external/imgui/snes9x_imgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -279,5 +279,5 @@ void S9xImGuiInit(S9xImGuiInitInfo *init_info)
builder.AddText("←↑→↓▶❚");
ranges.clear();
builder.BuildRanges(&ranges);
ImGui::GetIO().Fonts->AddFontFromMemoryCompressedTTF(imgui_noto_font_compressed_data, settings.font_size, nullptr, ranges.Data);
ImGui::GetIO().Fonts->AddFontFromMemoryCompressedTTF(imgui_noto_font_compressed_data, imgui_noto_font_compressed_size, settings.font_size, nullptr, ranges.Data);
}
149 changes: 109 additions & 40 deletions gfx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
#include "cheats.h"
#include "movie.h"
#include "screenshot.h"
#include "font.h"
#include "display.h"

extern struct SCheatData Cheat;
Expand All @@ -21,7 +20,6 @@ extern struct SLineMatrixData LineMatrixData[240];

void S9xComputeClipWindows (void);

static int font_width = 8, font_height = 9;
void (*S9xCustomDisplayString) (const char *, int, int, bool, int) = NULL;

static void SetupOBJ (void);
Expand Down Expand Up @@ -1733,76 +1731,147 @@ void S9xSetInfoString (const char *string)
}
}

void S9xDisplayChar (uint16 *s, uint8 c)
#include "var8x10font.h"
static const int font_width = 8;
static const int font_height = 10;

static inline int CharWidth(uint8 c)
{
return font_width - var8x10font_kern[c - 32][0] - var8x10font_kern[c - 32][1];
}

static int StringWidth(const char* str)
{
const uint16 black = BUILD_PIXEL(0, 0, 0);
int length = strlen(str);
int pixcount = 0;

int line = ((c - 32) >> 4) * font_height;
int offset = ((c - 32) & 15) * font_width;
if (length > 0)
pixcount++;

for (int h = 0; h < font_height; h++, line++, s += GFX.RealPPL - font_width)
for (int i = 0; i < length; i++)
{
for (int w = 0; w < font_width; w++, s++)
{
char p = font[line][offset + w];
pixcount += (CharWidth(str[i]) - 1);
}

return pixcount;
}

static void VariableDisplayChar(int x, int y, uint8 c, bool monospace = false, int overlap = 0)
{
int cindex = c - 32;
int crow = cindex >> 4;
int ccol = cindex & 15;
int cwidth = font_width - (monospace ? 0 : (var8x10font_kern[cindex][0] + var8x10font_kern[cindex][1]));

int line = crow * font_height;
int offset = ccol * font_width + (monospace ? 0 : var8x10font_kern[cindex][0]);
int scale = IPPU.RenderedScreenWidth / SNES_WIDTH;

if (p == '#')
uint16* s = GFX.Screen + y * GFX.RealPPL + x * scale;

for (int h = 0; h < font_height; h++, line++, s += GFX.RealPPL - cwidth * scale)
{
for (int w = 0; w < cwidth; w++, s++)
{
if (var8x10font[line][offset + w] == '#')
*s = Settings.DisplayColor;
else
if (p == '.')
*s = black;
else if (var8x10font[line][offset + w] == '.')
*s = 0x0000;
// else if (!monospace && w >= overlap)
// *s = (*s & 0xf7de) >> 1;
// *s = (*s & 0xe79c) >> 2;

if (scale > 1)
{
s[1] = s[0];
s++;
}
}
}
}

static void DisplayStringFromBottom (const char *string, int linesFromBottom, int pixelsFromLeft, bool allowWrap)
static void S9xVariableDisplayString(const char* string, int linesFromBottom,
int pixelsFromLeft, bool allowWrap, int type)
{
if (S9xCustomDisplayString)
bool monospace = true;
if (type == S9X_NO_INFO)
{
S9xCustomDisplayString (string, linesFromBottom, pixelsFromLeft, allowWrap, S9X_NO_INFO);
return;
if (linesFromBottom <= 0)
linesFromBottom = 1;

if (linesFromBottom >= 5 && !Settings.DisplayPressedKeys)
{
if (!Settings.DisplayPressedKeys)
linesFromBottom -= 3;
else
linesFromBottom -= 1;
}

if (pixelsFromLeft > 128)
pixelsFromLeft = SNES_WIDTH - StringWidth(string);

monospace = false;
}

if (linesFromBottom <= 0)
linesFromBottom = 1;
int dst_x = pixelsFromLeft;
int dst_y = IPPU.RenderedScreenHeight - (font_height)*linesFromBottom;
int len = strlen(string);

uint16 *dst = GFX.Screen + (IPPU.RenderedScreenHeight - font_height * linesFromBottom) * GFX.RealPPL + pixelsFromLeft;
if (IPPU.RenderedScreenHeight % 224 && !Settings.ShowOverscan)
dst_y -= 8;
else if (Settings.ShowOverscan)
dst_y += 8;

int len = strlen(string);
int max_chars = IPPU.RenderedScreenWidth / (font_width - 1);
int char_count = 0;
int overlap = 0;

for (int i = 0 ; i < len ; i++, char_count++)
for (int i = 0; i < len; i++)
{
if (char_count >= max_chars || (uint8) string[i] < 32)
int cindex = string[i] - 32;
int char_width = font_width - (monospace ? 1 : (var8x10font_kern[cindex][0] + var8x10font_kern[cindex][1]));

if (dst_x + char_width > SNES_WIDTH || (uint8)string[i] < 32)
{
if (!allowWrap)
break;

dst += font_height * GFX.RealPPL - (font_width - 1) * max_chars;
if (dst >= GFX.Screen + IPPU.RenderedScreenHeight * GFX.RealPPL)
break;
linesFromBottom--;
dst_y = IPPU.RenderedScreenHeight - font_height * linesFromBottom;
dst_x = pixelsFromLeft;

char_count -= max_chars;
if (dst_y >= IPPU.RenderedScreenHeight)
break;
}

if ((uint8) string[i] < 32)
if ((uint8)string[i] < 32)
continue;

S9xDisplayChar(dst, string[i]);
dst += font_width - 1;
VariableDisplayChar(dst_x, dst_y, string[i], monospace, overlap);

dst_x += char_width - 1;
overlap = 1;
}
}

static void S9xDisplayStringType (const char *string, int linesFromBottom, int pixelsFromLeft, bool allowWrap, int type)
static void DisplayStringFromBottom(const char* string, int linesFromBottom, int pixelsFromLeft, bool allowWrap)
{
if (S9xCustomDisplayString)
{
S9xCustomDisplayString (string, linesFromBottom, pixelsFromLeft, allowWrap, type);
return;
}
if (S9xCustomDisplayString)
{
S9xCustomDisplayString(string, linesFromBottom, pixelsFromLeft, allowWrap, S9X_NO_INFO);
return;
}

S9xVariableDisplayString(string, linesFromBottom, pixelsFromLeft, allowWrap, S9X_NO_INFO);
}

static void S9xDisplayStringType(const char* string, int linesFromBottom, int pixelsFromLeft, bool allowWrap, int type)
{
if (S9xCustomDisplayString)
{
S9xCustomDisplayString(string, linesFromBottom, pixelsFromLeft, allowWrap, type);
return;
}

S9xDisplayString (string, linesFromBottom, pixelsFromLeft, allowWrap);
S9xVariableDisplayString(string, linesFromBottom, pixelsFromLeft, allowWrap, type);
}

static void DisplayTime (void)
Expand Down
11 changes: 1 addition & 10 deletions port.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,20 +123,11 @@ typedef size_t pint;

#include "fscompat.h"

#ifndef __WIN32__
#define S9xDisplayString DisplayStringFromBottom
#else // __WIN32__
#ifdef __WIN32__
#define snprintf _snprintf
#define strcasecmp stricmp
#define strncasecmp strnicmp
#ifndef __LIBRETRO__
void WinDisplayStringFromBottom(const char *string, int linesFromBottom, int pixelsFromLeft, bool allowWrap);
#define S9xDisplayString WinDisplayStringFromBottom
void SetInfoDlgColor(unsigned char, unsigned char, unsigned char);
#define SET_UI_COLOR(r,g,b) SetInfoDlgColor(r,g,b)
#else // __LIBRETRO__
#define S9xDisplayString DisplayStringFromBottom
#endif // __LIBRETRO__
#endif // __WIN32__

#if defined(__DJGPP) || defined(__WIN32__)
Expand Down
1 change: 1 addition & 0 deletions snes9x.h
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ struct SSettings
uint32 InitialInfoStringTimeout;
uint16 DisplayColor;
bool8 BilinearFilter;
bool ShowOverscan;

bool8 Multi;
char CartAName[PATH_MAX + 1];
Expand Down
File renamed without changes.
4 changes: 0 additions & 4 deletions win32/CDirect3D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -290,10 +290,6 @@ void CDirect3D::Render(SSurface Src)
Dst.Pitch = lr.Pitch;

RenderMethod (Src, Dst, &dstRect);
if(!Settings.AutoDisplayMessages) {
WinSetCustomDisplaySurface((void *)Dst.Surface, Dst.Pitch/2, dstRect.right-dstRect.left, dstRect.bottom-dstRect.top, GetFilterScale(CurrentScale));
S9xDisplayMessages ((uint16*)Dst.Surface, Dst.Pitch/2, dstRect.right-dstRect.left, dstRect.bottom-dstRect.top, GetFilterScale(CurrentScale));
}

drawSurface->UnlockRect(0);
}
Expand Down
7 changes: 1 addition & 6 deletions win32/CDirectDraw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -435,11 +435,6 @@ void CDirectDraw::Render(SSurface Src)
RenderMethod (Src, Dst, &srcRect);
}

if(!Settings.AutoDisplayMessages) {
WinSetCustomDisplaySurface((void *)Dst.Surface, (Dst.Pitch*8/GUI.ScreenDepth), srcRect.right-srcRect.left, srcRect.bottom-srcRect.top, GetFilterScale(CurrentScale));
S9xDisplayMessages ((uint16*)Dst.Surface, Dst.Pitch/2, srcRect.right-srcRect.left, srcRect.bottom-srcRect.top, GetFilterScale(CurrentScale));
}

RECT lastRect = SizeHistory [GUI.FlipCounter % GUI.NumFlipFrames];
POINT p;

Expand All @@ -456,7 +451,7 @@ void CDirectDraw::Render(SSurface Src)
int height = dstRect.bottom - dstRect.top;

int oldWidth = GUI.AspectWidth;
int oldHeight = GUI.HeightExtend ? SNES_HEIGHT_EXTENDED : SNES_HEIGHT;
int oldHeight = Settings.ShowOverscan ? SNES_HEIGHT_EXTENDED : SNES_HEIGHT;
int newWidth, newHeight;

if(oldWidth * height > oldHeight * width)
Expand Down
4 changes: 0 additions & 4 deletions win32/COpenGL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -297,10 +297,6 @@ void COpenGL::Render(SSurface Src)
Dst.Pitch = outTextureWidth * 2;

RenderMethod (Src, Dst, &dstRect);
if(!Settings.AutoDisplayMessages) {
WinSetCustomDisplaySurface((void *)Dst.Surface, Dst.Pitch/2, dstRect.right-dstRect.left, dstRect.bottom-dstRect.top, GetFilterScale(CurrentScale));
S9xDisplayMessages ((uint16*)Dst.Surface, Dst.Pitch/2, dstRect.right-dstRect.left, dstRect.bottom-dstRect.top, GetFilterScale(CurrentScale));
}

if(pboFunctionsLoaded)
glUnmapBuffer(GL_PIXEL_UNPACK_BUFFER);
Expand Down
5 changes: 0 additions & 5 deletions win32/CVulkan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,6 @@ void CVulkan::Render(SSurface Src)

RenderMethod(Src, Dst, &dstRect);

if (!Settings.AutoDisplayMessages) {
WinSetCustomDisplaySurface((void*)Dst.Surface, Dst.Pitch / 2, dstRect.right - dstRect.left, dstRect.bottom - dstRect.top, GetFilterScale(GUI.Scale));
S9xDisplayMessages((uint16*)Dst.Surface, Dst.Pitch / 2, dstRect.right - dstRect.left, dstRect.bottom - dstRect.top, GetFilterScale(GUI.Scale));
}

RECT windowSize, displayRect;
GetClientRect(hWnd, &windowSize);
//Get maximum rect respecting AR setting
Expand Down
2 changes: 1 addition & 1 deletion win32/render.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ inline static bool GetFilterBlendSupport(RenderFilter filterID)

void AdjustHeightExtend(unsigned int &height)
{
if(GUI.HeightExtend)
if(Settings.ShowOverscan)
{
if(height == SNES_HEIGHT)
height = SNES_HEIGHT_EXTENDED;
Expand Down
4 changes: 3 additions & 1 deletion win32/rsrc/resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,8 @@
#define IDC_NO_SPRITE_LIMIT 3037
#define IDC_SET_DEFAULTS 3038
#define IDC_BUTTON_SLOT_1 3039
#define IDC_OSD_SCALE 3041
#define IDC_SPIN_OSD_SIZE 3042
#define IDC_STATIC_SLOT_1 3059
#define ID_FILE_EXIT 40001
#define ID_WINDOW_HIDEMENUBAR 40004
Expand Down Expand Up @@ -561,7 +563,7 @@
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 169
#define _APS_NEXT_COMMAND_VALUE 40189
#define _APS_NEXT_CONTROL_VALUE 3040
#define _APS_NEXT_CONTROL_VALUE 3044
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif
7 changes: 4 additions & 3 deletions win32/rsrc/snes9x.rc
Original file line number Diff line number Diff line change
Expand Up @@ -222,17 +222,18 @@ BEGIN
CONTROL "Transparency Effects",IDC_TRANS,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,186,131,150,8
CONTROL "Blend Hi-Res Images",IDC_HIRESBLEND,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,186,143,150,8
CONTROL "Extend Height of SNES Image",IDC_HEIGHT_EXTEND,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,186,155,150,8
CONTROL "Display messages before applying filters",IDC_MESSAGES_IN_IMAGE,
CONTROL "Display messages inside SNES image",IDC_MESSAGES_IN_IMAGE,
"Button",BS_AUTOCHECKBOX | WS_TABSTOP,186,167,150,8
CONTROL "Scale messages with EPX if possible",IDC_MESSAGES_SCALE,
"Button",BS_AUTOCHECKBOX | WS_TABSTOP,186,179,150,8
GROUPBOX "Frame Skipping:",IDC_STATIC,6,145,168,48,0,WS_EX_TRANSPARENT
GROUPBOX "SNES Image",IDC_STATIC,180,118,162,75,0,WS_EX_TRANSPARENT
GROUPBOX "Output Image Processing",IDC_STATIC,180,6,162,61,0,WS_EX_TRANSPARENT
GROUPBOX "Fullscreen Display Settings",IDC_STATIC,180,73,162,42,0,WS_EX_TRANSPARENT
LTEXT "Hi Res:",IDC_HIRESLABEL,186,36,31,8
GROUPBOX "General",IDC_STATIC,6,6,168,138,0,WS_EX_TRANSPARENT
LTEXT "Output Method",IDC_STATIC,12,18,51,12
LTEXT "On-screen Display Size:",IDC_STATIC,186,179,79,8
EDITTEXT IDC_OSD_SCALE,296,176,40,14,ES_AUTOHSCROLL | ES_NUMBER
CONTROL "",IDC_SPIN_OSD_SIZE,"msctls_updown32",UDS_SETBUDDYINT | UDS_ALIGNRIGHT | UDS_AUTOBUDDY | UDS_ARROWKEYS,320,177,9,12
END

IDD_CHEATER DIALOGEX 0, 0, 378, 189
Expand Down
Loading

0 comments on commit ebf2e99

Please sign in to comment.