libpng + pngs for easier graphics changes
4
Makefile
|
|
@ -38,7 +38,7 @@ INCLUDES := inc
|
|||
EXEFS_SRC := exefs_src
|
||||
APP_TITLE := JKSV
|
||||
APP_AUTHOR := JK_
|
||||
APP_VERSION := 06/27/2018
|
||||
APP_VERSION := 06/28/2018
|
||||
ROMFS := romfs
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
|
|
@ -56,7 +56,7 @@ CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions -std=gnu++11
|
|||
ASFLAGS := -g $(ARCH)
|
||||
LDFLAGS = -specs=$(DEVKITPRO)/libnx/switch.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map)
|
||||
|
||||
LIBS := `freetype-config --libs`
|
||||
LIBS := `freetype-config --libs` -lpng
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# list of directories containing libraries, this must be the top level containing
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ JKSV for Switch. Mostly to get used to libnx. Reuses a lot of code of JKSM for 3
|
|||
# Building:
|
||||
1. Requires [devkitPro](https://devkitpro.org/) devkitA64
|
||||
2. Requires switch-freetype
|
||||
3. libpng
|
||||
|
||||
# Credits and Thanks:
|
||||
* [shared-font](https://github.com/switchbrew/switch-portlibs-examples) example by yellows8
|
||||
|
|
|
|||
|
|
@ -37,11 +37,9 @@ namespace gfx
|
|||
{
|
||||
public:
|
||||
/*
|
||||
Loads binary data from path
|
||||
First 4 bytes are data size
|
||||
Next 2 are width
|
||||
Next 2 are height
|
||||
The rest is raw RGBA8 data
|
||||
Now uses libpng and png files
|
||||
Only accepts RGBA8 PNGs
|
||||
Others will have issues.
|
||||
*/
|
||||
void loadFromFile(const std::string& path);
|
||||
//Frees memory used by data
|
||||
|
|
|
|||
BIN
romfs/img/buttonA.png
Normal file
|
After Width: | Height: | Size: 1.1 KiB |
BIN
romfs/img/buttonB.png
Normal file
|
After Width: | Height: | Size: 1.2 KiB |
BIN
romfs/img/buttonX.png
Normal file
|
After Width: | Height: | Size: 1.2 KiB |
BIN
romfs/img/buttonY.png
Normal file
|
After Width: | Height: | Size: 1.1 KiB |
BIN
romfs/img/tbox/tboxCornerBotLeft_drk.png
Normal file
|
After Width: | Height: | Size: 240 B |
BIN
romfs/img/tbox/tboxCornerBotLeft_lght.png
Normal file
|
After Width: | Height: | Size: 235 B |
BIN
romfs/img/tbox/tboxCornerBotRight_drk.png
Normal file
|
After Width: | Height: | Size: 237 B |
BIN
romfs/img/tbox/tboxCornerBotRight_lght.png
Normal file
|
After Width: | Height: | Size: 237 B |
BIN
romfs/img/tbox/tboxCornerTopLeft_drk.png
Normal file
|
After Width: | Height: | Size: 237 B |
BIN
romfs/img/tbox/tboxCornerTopLeft_lght.png
Normal file
|
After Width: | Height: | Size: 230 B |
BIN
romfs/img/tbox/tboxCornerTopRight_drk.png
Normal file
|
After Width: | Height: | Size: 252 B |
BIN
romfs/img/tbox/tboxCornerTopRight_lght.png
Normal file
|
After Width: | Height: | Size: 245 B |
BIN
romfs/img/tbox/tboxHorEdgeBot_drk.png
Normal file
|
After Width: | Height: | Size: 181 B |
BIN
romfs/img/tbox/tboxHorEdgeBot_lght.png
Normal file
|
After Width: | Height: | Size: 181 B |
BIN
romfs/img/tbox/tboxHorEdgeTop_drk.png
Normal file
|
After Width: | Height: | Size: 180 B |
BIN
romfs/img/tbox/tboxHorEdgeTop_lght.png
Normal file
|
After Width: | Height: | Size: 182 B |
BIN
romfs/img/tbox/tboxVertEdgeLeft_drk.png
Normal file
|
After Width: | Height: | Size: 175 B |
BIN
romfs/img/tbox/tboxVertEdgeLeft_lght.png
Normal file
|
After Width: | Height: | Size: 175 B |
BIN
romfs/img/tbox/tboxVertEdgeRight_drk.png
Normal file
|
After Width: | Height: | Size: 176 B |
BIN
romfs/img/tbox/tboxVertEdgeRight_lght.png
Normal file
|
After Width: | Height: | Size: 177 B |
BIN
romfs/img/topbar_drk.png
Normal file
|
After Width: | Height: | Size: 251 B |
BIN
romfs/img/topbar_lght.png
Normal file
|
After Width: | Height: | Size: 195 B |
61
src/gfx.cpp
|
|
@ -3,6 +3,8 @@
|
|||
#include <fstream>
|
||||
#include <cstdio>
|
||||
#include <switch.h>
|
||||
#include <png.h>
|
||||
#include <malloc.h>
|
||||
|
||||
#include <ft2build.h>
|
||||
#include FT_FREETYPE_H
|
||||
|
|
@ -256,18 +258,59 @@ namespace gfx
|
|||
|
||||
void tex::loadFromFile(const std::string& path)
|
||||
{
|
||||
std::fstream dataIn(path, std::ios::in | std::ios::binary);
|
||||
if(dataIn.is_open())
|
||||
FILE *pngIn = fopen(path.c_str(), "rb");
|
||||
if(pngIn != NULL)
|
||||
{
|
||||
dataIn.read((char *)&sz, sizeof(uint32_t));
|
||||
dataIn.read((char *)&width, sizeof(uint16_t));
|
||||
dataIn.read((char *)&height, sizeof(uint16_t));
|
||||
png_structp png = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
|
||||
if(png == 0)
|
||||
return;
|
||||
|
||||
data = new uint32_t[sz / sizeof(uint32_t)];
|
||||
if(data != NULL)
|
||||
dataIn.read((char *)data, sz);
|
||||
png_infop pngInfo = png_create_info_struct(png);
|
||||
if(pngInfo == 0)
|
||||
return;
|
||||
|
||||
dataIn.close();
|
||||
int jmp = setjmp(png_jmpbuf(png));
|
||||
if(jmp)
|
||||
return;
|
||||
|
||||
png_init_io(png, pngIn);
|
||||
|
||||
png_read_info(png, pngInfo);
|
||||
|
||||
unsigned clrType = png_get_color_type(png, pngInfo);
|
||||
if(clrType != PNG_COLOR_TYPE_RGBA)
|
||||
return;
|
||||
|
||||
width = png_get_image_width(png, pngInfo);
|
||||
height = png_get_image_height(png, pngInfo);
|
||||
|
||||
data = new uint32_t[width * height];
|
||||
|
||||
png_bytep *rows = new png_bytep[sizeof(png_bytep) * height];
|
||||
for(unsigned i = 0; i < height; i++)
|
||||
rows[i] = new png_byte[png_get_rowbytes(png, pngInfo)];
|
||||
|
||||
png_read_image(png, rows);
|
||||
|
||||
for(unsigned y = 0, i = 0; y < height; y++)
|
||||
{
|
||||
png_bytep row = rows[y];
|
||||
for(unsigned x = 0; x < width; x++, i++)
|
||||
{
|
||||
png_bytep px = &(row[x * 4]);
|
||||
|
||||
data[i] = px[3] << 24 | px[2] << 16 | px[1] << 8 | px[0];
|
||||
}
|
||||
}
|
||||
|
||||
for(unsigned i = 0; i < height; i++)
|
||||
delete rows[i];
|
||||
|
||||
delete[] rows;
|
||||
|
||||
png_destroy_read_struct(&png, &pngInfo, NULL);
|
||||
|
||||
fclose(pngIn);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
52
src/ui.cpp
|
|
@ -52,7 +52,9 @@ static int advMenuCtrl = 0, advPrev = 0;
|
|||
|
||||
namespace ui
|
||||
{
|
||||
uint32_t clearClr = 0, mnuTxt = 0, txtClr = 0, rectLt = 0, rectSh = 0, tboxClr = 0;
|
||||
uint32_t clearClr = 0xFFFFFFFF, mnuTxt = 0xFF000000, txtClr = 0xFF000000, \
|
||||
rectLt = 0xFFC0C0C0, rectSh = 0, tboxClr = 0xFFC0C0C0;
|
||||
|
||||
void init()
|
||||
{
|
||||
ColorSetId gthm;
|
||||
|
|
@ -61,19 +63,19 @@ namespace ui
|
|||
switch(gthm)
|
||||
{
|
||||
case ColorSetId_Light:
|
||||
titleBar.loadFromFile("romfs:/img/topbar_lght.data");
|
||||
titleBar.loadFromFile("romfs:/img/topbar_lght.png");
|
||||
|
||||
//Dark corners
|
||||
cornerTopLeft.loadFromFile("romfs:/img/tbox/tBoxCornerTopLeft_drk.data");
|
||||
cornerTopRight.loadFromFile("romfs:/img/tbox/tBoxCornerTopRight_drk.data");
|
||||
cornerBottomLeft.loadFromFile("romfs:/img/tbox/tBoxCornerBotLeft_drk.data");
|
||||
cornerBottomRight.loadFromFile("romfs:/img/tbox/tBoxCornerBotRight_drk.data");
|
||||
cornerTopLeft.loadFromFile("romfs:/img/tbox/tboxCornerTopLeft_drk.png");
|
||||
cornerTopRight.loadFromFile("romfs:/img/tbox/tboxCornerTopRight_drk.png");
|
||||
cornerBottomLeft.loadFromFile("romfs:/img/tbox/tboxCornerBotLeft_drk.png");
|
||||
cornerBottomRight.loadFromFile("romfs:/img/tbox/tboxCornerBotRight_drk.png");
|
||||
|
||||
//Dark edges
|
||||
horEdgeTop.loadFromFile("romfs:/img/tbox/tboxHorEdgeTop_drk.data");
|
||||
horEdgeBot.loadFromFile("romfs:/img/tbox/tboxHorEdgeBot_drk.data");
|
||||
vertEdgeLeft.loadFromFile("romfs:/img/tbox/tboxVertEdgeLeft_drk.data");
|
||||
vertEdgeRight.loadFromFile("romfs:/img/tbox/tboxVertEdgeRight_drk.data");
|
||||
horEdgeTop.loadFromFile("romfs:/img/tbox/tboxHorEdgeTop_drk.png");
|
||||
horEdgeBot.loadFromFile("romfs:/img/tbox/tboxHorEdgeBot_drk.png");
|
||||
vertEdgeLeft.loadFromFile("romfs:/img/tbox/tboxVertEdgeLeft_drk.png");
|
||||
vertEdgeRight.loadFromFile("romfs:/img/tbox/tboxVertEdgeRight_drk.png");
|
||||
|
||||
clearClr = 0xFFEBEBEB;
|
||||
mnuTxt = 0xFF000000;
|
||||
|
|
@ -83,21 +85,21 @@ namespace ui
|
|||
tboxClr = 0xFF2D2D2D;
|
||||
break;
|
||||
|
||||
default:
|
||||
default:
|
||||
case ColorSetId_Dark:
|
||||
titleBar.loadFromFile("romfs:/img/topbar_drk.data");
|
||||
titleBar.loadFromFile("romfs:/img/topbar_drk.png");
|
||||
|
||||
//Light corners
|
||||
cornerTopLeft.loadFromFile("romfs:/img/tbox/tBoxCornerTopLeft_lght.data");
|
||||
cornerTopRight.loadFromFile("romfs:/img/tbox/tBoxCornerTopRight_lght.data");
|
||||
cornerBottomLeft.loadFromFile("romfs:/img/tbox/tBoxCornerBotLeft_lght.data");
|
||||
cornerBottomRight.loadFromFile("romfs:/img/tbox/tBoxCornerBotRight_lght.data");
|
||||
cornerTopLeft.loadFromFile("romfs:/img/tbox/tboxCornerTopLeft_lght.png");
|
||||
cornerTopRight.loadFromFile("romfs:/img/tbox/tboxCornerTopRight_lght.png");
|
||||
cornerBottomLeft.loadFromFile("romfs:/img/tbox/tboxCornerBotLeft_lght.png");
|
||||
cornerBottomRight.loadFromFile("romfs:/img/tbox/tboxCornerBotRight_lght.png");
|
||||
|
||||
//light edges
|
||||
horEdgeTop.loadFromFile("romfs:/img/tbox/tboxHorEdgeTop_lght.data");
|
||||
horEdgeBot.loadFromFile("romfs:/img/tbox/tboxHorEdgeBot_lght.data");
|
||||
vertEdgeLeft.loadFromFile("romfs:/img/tbox/tboxVertEdgeLeft_lght.data");
|
||||
vertEdgeRight.loadFromFile("romfs:/img/tbox/tboxVertEdgeRight_lght.data");
|
||||
horEdgeTop.loadFromFile("romfs:/img/tbox/tboxHorEdgeTop_lght.png");
|
||||
horEdgeBot.loadFromFile("romfs:/img/tbox/tboxHorEdgeBot_lght.png");
|
||||
vertEdgeLeft.loadFromFile("romfs:/img/tbox/tboxVertEdgeLeft_lght.png");
|
||||
vertEdgeRight.loadFromFile("romfs:/img/tbox/tboxVertEdgeRight_lght.png");
|
||||
|
||||
clearClr = 0xFF2D2D2D;
|
||||
mnuTxt = 0xFFFFFFFF;
|
||||
|
|
@ -108,10 +110,10 @@ namespace ui
|
|||
break;
|
||||
}
|
||||
|
||||
buttonA.loadFromFile("romfs:/img/buttonA.data");
|
||||
buttonB.loadFromFile("romfs:/img/buttonB.data");
|
||||
buttonX.loadFromFile("romfs:/img/buttonX.data");
|
||||
buttonY.loadFromFile("romfs:/img/buttonY.data");
|
||||
buttonA.loadFromFile("romfs:/img/buttonA.png");
|
||||
buttonB.loadFromFile("romfs:/img/buttonB.png");
|
||||
buttonX.loadFromFile("romfs:/img/buttonX.png");
|
||||
buttonY.loadFromFile("romfs:/img/buttonY.png");
|
||||
|
||||
copyMenu.addOpt("Copy From");
|
||||
copyMenu.addOpt("Delete");
|
||||
|
|
@ -600,7 +602,7 @@ namespace ui
|
|||
void drawUI()
|
||||
{
|
||||
gfx::clearBufferColor(clearClr);
|
||||
ui::drawTitleBar("JKSV - 06/27/2018");
|
||||
ui::drawTitleBar("JKSV - 06/28/2018");
|
||||
|
||||
switch(mstate)
|
||||
{
|
||||
|
|
|
|||