Skip to content

Commit

Permalink
removed SDL2
Browse files Browse the repository at this point in the history
  • Loading branch information
lantus360 committed Nov 13, 2018
1 parent c1d2e48 commit e089ac9
Show file tree
Hide file tree
Showing 20 changed files with 8,960 additions and 197 deletions.
Binary file added build/InterUI14.nxfnt
Binary file not shown.
Binary file added build/InterUI18.nxfnt
Binary file not shown.
Binary file added build/InterUI20.nxfnt
Binary file not shown.
Binary file added build/InterUI24.nxfnt
Binary file not shown.
11 changes: 7 additions & 4 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ DEFS = -DALIGN_SHORTS -DALIGN_INTS -DLSB_FIRST -DINLINE="static __inline__" -DSW

CFLAGS = -Isrc -Isrc/includes -Isrc/$(MAMEOS) -I$(OBJ)/cpu/m68000 -Isrc/cpu/m68000 -I$(DEVKITPRO)/libnx/include -I$(DEVKITPRO)/portlibs/switch/include
CXXFLAGS = -Isrc -Isrc/includes -Isrc/$(MAMEOS) -I$(OBJ)/cpu/m68000 -Isrc/cpu/m68000 -I$(DEVKITPRO)/libnx/include -I$(DEVKITPRO)/portlibs/switch/include
CXXFLAGS += -DNDEBUG \
CXXFLAGS += -DNDEBUG `freetype-config --cflags`\
$(ARCH) -w -O3 -fomit-frame-pointer -fstrict-aliasing \
-Wall -Wno-sign-compare -Wunused \
-Wpointer-arith -Wcast-align -Waggregate-return \
Expand All @@ -164,7 +164,7 @@ CXXFLAGS += -DNDEBUG \
ifdef SYMBOLS
CFLAGS += -O0 -Wall -Werror -Wno-unused -g
else
CFLAGS += -DNDEBUG \
CFLAGS += -DNDEBUG `freetype-config --cflags` \
$(ARCH) -w -O3 -fomit-frame-pointer -fstrict-aliasing \
-Wall -Wno-sign-compare -Wunused \
-Wpointer-arith -Wbad-function-cast -Wcast-align -Waggregate-return \
Expand All @@ -191,7 +191,7 @@ MAPFLAGS =
endif

# platform .mak files will want to add to this
LIBS = -lfreetype -lSDL2_ttf -lSDL2_gfx -lSDL2_image -lpng -ljpeg `sdl2-config --libs` `freetype-config --libs` -lz -lglad -lEGL -lglapi -ldrm_nouveau -lnx -lm
LIBS = -lfreetype `freetype-config --libs` -lz -lglad -lEGL -lglapi -ldrm_nouveau -lnx -lm

OBJDIRS = obj $(OBJ) $(OBJ)/cpu $(OBJ)/sound $(OBJ)/$(MAMEOS) \
$(OBJ)/drivers $(OBJ)/machine $(OBJ)/vidhrdw $(OBJ)/sndhrdw
Expand Down Expand Up @@ -229,12 +229,15 @@ extra: $(TOOLS) $(TEXTS)
# combine the various definitions to one
CDEFS = $(DEFS) $(COREDEFS) $(CPUDEFS) $(SOUNDDEFS) $(ASMDEFS) $(DBGDEFS)

$(OBJ)/nx/gfx.o : src/nx/gfx.cpp
$(CXX) $(CDEFS) $(CXXFLAGS) -c src/nx/gfx.cpp -o $(OBJ)/nx/gfx.o

$(OBJ)/nx/nx_maintest.o: src/nx/nx_maintest.cpp
$(CXX) $(CDEFS) $(CXXFLAGS) -c src/nx/nx_maintest.cpp -o $(OBJ)/nx/nx_maintest.o

$(OBJ)/nx/nx_romlist.o : src/nx/nx_romlist.cpp
$(CXX) $(CDEFS) $(CXXFLAGS) -c src/nx/nx_romlist.cpp -o $(OBJ)/nx/nx_romlist.o

# primary target
$(EMULATOR): $(OBJS) $(COREOBJS) $(OSOBJS) $(DRVLIBS)
# always recompile the version string
Expand Down
Binary file modified romfs/Graphics/border.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added romfs/Graphics/mamelogo-nx.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed romfs/Graphics/mamelogo-nx.png
Binary file not shown.
186 changes: 50 additions & 136 deletions src/CustomUI.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,19 @@
using namespace std;

#include <switch.h>
#include <SDL2/SDL.h>
#include <SDL2/SDL2_gfxPrimitives.h>
#include <SDL2/SDL_image.h>
#include <SDL2/SDL_mixer.h>
#include <SDL2/SDL_ttf.h>
#include "nx_romlist.h"
#include "gfx.hpp"


extern "C" {
#include "osd_cpu.h"
#include "driver.h"
#include "mame.h"
#include "mame.h"


bool initEgl();
void deinitEgl();

}


Expand All @@ -39,8 +35,7 @@ const int GAMESEL_WindowMiddle = 8;

static bool bGLInited = false;
int MenuState;
SDL_Renderer *menu_render;
TTF_Font *menuFntLarge;



float fGameSelect;
Expand All @@ -67,18 +62,8 @@ namespace UI
int optRed,optGreen,optBlue,optAlpha;

char RomCountText[60];
static SDL_Window *sdl_wnd;
static SDL_Surface *sdl_surf;
static SDL_Renderer *sdl_render;
static TTF_Font *fntLarge;
static TTF_Font *fntMedium;
static TTF_Font *fntSmall;


static string Back;
static SDL_Color txtcolor;
static SDL_Surface *sdls_Back;
static SDL_Texture *sdlt_Back;

static string Back;
static int TitleX = 60;
static int TitleY = 235;
static int Opt1X = 55;
Expand All @@ -93,68 +78,12 @@ namespace UI
static int vol = 64;
static string curfilename = ":nofile:";
static string curfile = ":nofile:";


SDL_Surface *InitSurface(string Path)
{
SDL_Surface *srf = IMG_Load(Path.c_str());
if(srf)
{
Uint32 colorkey = SDL_MapRGB(srf->format, 0, 0, 0);
SDL_SetColorKey(srf, SDL_TRUE, colorkey);
}
return srf;
}

SDL_Texture *InitTexture(SDL_Surface *surf)
{
SDL_Texture *tex = SDL_CreateTextureFromSurface(sdl_render, surf);
return tex;
}

void DrawText(TTF_Font *font, int x, int y, SDL_Color colour, const char *text)
{
SDL_Surface *surface = TTF_RenderText_Blended_Wrapped(font, text, colour, 1280);
SDL_SetSurfaceAlphaMod(surface, 255);
SDL_Rect position = { x, y, surface->w, surface->h };
SDL_BlitSurface(surface, NULL, sdl_surf, &position);
SDL_FreeSurface(surface);
}

void DrawRect(int x, int y, int w, int h, SDL_Color colour)
{
SDL_Rect rect;
rect.x = x; rect.y = y; rect.w = w; rect.h = h;
SDL_SetRenderDrawColor(sdl_render, colour.r, colour.g, colour.b, colour.a);
SDL_RenderFillRect(sdl_render, &rect);
}

void DrawBackXY(SDL_Surface *surf, SDL_Texture *tex, int x, int y)
{
SDL_Rect position;
position.x = x;
position.y = y;
position.w = surf->w;
position.h = surf->h;
SDL_RenderCopy(sdl_render, tex, NULL, &position);
}

void DrawBack(SDL_Surface *surf, SDL_Texture *tex)
{
DrawBackXY(surf, tex, 0, 0);
}


void Exit()
{
TTF_Quit();
IMG_Quit();
SDL_DestroyRenderer(sdl_render);
SDL_FreeSurface(sdl_surf);
SDL_DestroyWindow(sdl_wnd);

SDL_Quit();
romfsExit();
exit(0);
Gfx::exit();
romfsExit();
exit(0);
}

void Draw()
Expand All @@ -163,9 +92,8 @@ namespace UI
int iTempGameSel;
int iGameidx;

SDL_RenderClear(sdl_render);
DrawBack(sdls_Back, sdlt_Back);

Gfx::drawBgImage();

int ox = Opt1X;
int oy = Opt1Y;
for(int i = 0; i < optionsvec.size(); i++)
Expand Down Expand Up @@ -207,22 +135,24 @@ namespace UI
dr = 0; dg = 0; db = -1;
}

DrawText(fntLarge, ox, oy, { 140, 255, 255, 255 }, optionsvec[i].c_str());
Gfx::drawText(ox,oy, optionsvec[i].c_str() , { selBlue, selGreen, selRed, 255 } , 20);

if(i == 0)
{
int fx = 450;
int fy = 235;



// draw game list entries

iGameSelect = fGameSelect;
iCursorPos = fCursorPos;
iTempGameSel = iGameSelect;

if (iNumGames == 0)
DrawText(fntLarge, fx, 202, txtcolor, "No Roms Found");
{
Gfx::drawText( fx, 202, "No Roms Found", { 255, 255, 255, 255 }, 20);

}
for (iGameidx=0; iGameidx<iMaxWindowList; iGameidx++)
{

Expand All @@ -231,14 +161,13 @@ namespace UI


if (iGameidx==iCursorPos){

DrawText(fntLarge, fx, fy + (28*iGameidx), { selRed, selGreen, selBlue, 255 }, currentName);


Gfx::drawText(fx,fy + (28*iGameidx) , currentName, { selRed, selGreen, selBlue, 255 }, 20);
currentGame = currentName;
}
else
{
DrawText(fntLarge, fx, fy + (28*iGameidx), txtcolor, currentName);
{
Gfx::drawText(fx,fy + (28*iGameidx) , currentName, { 255, 255, 255, 255 }, 20);
}

}
Expand All @@ -247,24 +176,30 @@ namespace UI
}
else if(i == 1)
{
//DrawText(fntLarge, 450, 400, txtcolor, "Rotate Vertical Games");
//DrawText(fntLarge, 450, 420, txtcolor, "Keep Aspect Ratio");

Gfx::drawText(450, 400,"No Options Yet", { 255, 255, 255, 255 }, 20);


}
else if(i == 2)
{
DrawText(fntLarge, 450, 400, txtcolor, "Release 2.2 Ported by MVG in 2018");
Gfx::drawText(450, 400,"Release 2.2 Ported by MVG in 2018", { 255, 255, 255, 255 }, 20);

}
else if(i == 3)
{

}
}
else DrawText(fntLarge, ox, oy, txtcolor, optionsvec[i].c_str());
else{

Gfx::drawText(ox,oy, optionsvec[i].c_str(), { 255, 255, 255, 255 }, 20);
}
oy += 50;
}
DrawText(fntLarge, TitleX, 672, txtcolor, RomCountText);
SDL_RenderPresent(sdl_render);

Gfx::drawText(TitleX,672, RomCountText, { 255, 255, 255, 255 }, 20);

}

void Loop()
Expand Down Expand Up @@ -489,9 +424,7 @@ namespace UI
Draw();

}




if(k & KEY_LSTICK_UP)
{
if(selected > 0) selected -= 1;
Expand Down Expand Up @@ -523,9 +456,9 @@ namespace UI
//{
// case 0:
int gameIndex = mapRoms[currentGame];
SDL_SetRenderDrawColor(sdl_render, 0, 0, 0, 255);
SDL_RenderClear(sdl_render);
Gfx::clear({ 0, 0, 0, 0 });

options.ui_orientation = drivers[gameIndex]->flags & ORIENTATION_MASK;

if( options.ui_orientation & ORIENTATION_SWAP_XY )
Expand All @@ -536,26 +469,16 @@ namespace UI
options.ui_orientation ^= ROT180;
}

run_game(gameIndex);

SDL_SetRenderDrawColor(sdl_render, 255, 255, 255, 255);
SDL_RenderClear(sdl_render);
//break;
//case 1:



//break;

//}

run_game(gameIndex);

Draw();
}
else if(k & KEY_B)
{
Draw();
}
else if(k & KEY_PLUS || k & KEY_MINUS) Exit();

}


Expand All @@ -571,29 +494,20 @@ namespace UI
iCursorPos = 0;

romfsInit();

initEgl();

Gfx::init();

ColorSetId id;
setsysInitialize();
setsysGetColorSetId(&id);
Back = "romfs:/Graphics/mamelogo-nx.png";
txtcolor = { 255, 255, 255, 255 };

setsysExit();
SDL_Init(SDL_INIT_EVERYTHING);
SDL_CreateWindowAndRenderer(1280, 720, 0, &sdl_wnd, &sdl_render);
sdl_surf = SDL_GetWindowSurface(sdl_wnd);
SDL_SetRenderDrawBlendMode(sdl_render, SDL_BLENDMODE_BLEND);
SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "2");
IMG_Init(IMG_INIT_PNG | IMG_INIT_JPG);
TTF_Init();
SDL_SetRenderDrawColor(sdl_render, 255, 255, 255, 255);

fntLarge = TTF_OpenFont("romfs:/Fonts/NintendoStandard.ttf", 25);
fntMedium = TTF_OpenFont("romfs:/Fonts/NintendoStandard.ttf", 20);
fntSmall = TTF_OpenFont("romfs:/Fonts/NintendoStandard.ttf", 10);

menuFntLarge = fntLarge;
//Gfx::drawBgImage();
Gfx::flush();

sdls_Back = InitSurface(Back);
sdlt_Back = InitTexture(sdls_Back);
optionsvec.push_back("Playable ROM(s)");
optionsvec.push_back("Options");
optionsvec.push_back("About mame-nx");
Expand Down Expand Up @@ -621,7 +535,7 @@ namespace UI
selBlue = 0;
selAlpha = 255;

menu_render = sdl_render;

Draw();
}
Expand Down
3 changes: 3 additions & 0 deletions src/nx/InterUI14_nxfnt.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
extern const u8 InterUI14_nxfnt_end[];
extern const u8 InterUI14_nxfnt[];
extern const u32 InterUI14_nxfnt_size;
3 changes: 3 additions & 0 deletions src/nx/InterUI18_nxfnt.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
extern const u8 InterUI18_nxfnt_end[];
extern const u8 InterUI18_nxfnt[];
extern const u32 InterUI18_nxfnt_size;
3 changes: 3 additions & 0 deletions src/nx/InterUI20_nxfnt.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
extern const u8 InterUI20_nxfnt_end[];
extern const u8 InterUI20_nxfnt[];
extern const u32 InterUI20_nxfnt_size;
3 changes: 3 additions & 0 deletions src/nx/InterUI24_nxfnt.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
extern const u8 InterUI24_nxfnt_end[];
extern const u8 InterUI24_nxfnt[];
extern const u32 InterUI24_nxfnt_size;
Loading

0 comments on commit e089ac9

Please sign in to comment.